diff --git a/assets/index.es-e6325295.js b/assets/index.es-9e632253.js similarity index 99% rename from assets/index.es-e6325295.js rename to assets/index.es-9e632253.js index 619e000..d49c441 100644 --- a/assets/index.es-e6325295.js +++ b/assets/index.es-9e632253.js @@ -1,4 +1,4 @@ -import{c as Je,g as Do}from"./main-262930e7.js";import{_ as Ha}from"./jspdf.es.min-282c0c72.js";var ct=function(a){return a&&a.Math===Math&&a},U=ct(typeof globalThis=="object"&&globalThis)||ct(typeof window=="object"&&window)||ct(typeof self=="object"&&self)||ct(typeof Je=="object"&&Je)||ct(typeof Je=="object"&&Je)||function(){return this}()||Function("return this")(),ut={},L=function(a){try{return!!a()}catch{return!0}},Rl=L,ce=!Rl(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!==7}),Il=L,br=!Il(function(){var a=(function(){}).bind();return typeof a!="function"||a.hasOwnProperty("prototype")}),Nl=br,Ht=Function.prototype.call,Y=Nl?Ht.bind(Ht):function(){return Ht.apply(Ht,arguments)},Vo={},Lo={}.propertyIsEnumerable,ko=Object.getOwnPropertyDescriptor,Ml=ko&&!Lo.call({1:2},1);Vo.f=Ml?function(e){var t=ko(this,e);return!!t&&t.enumerable}:Lo;var xr=function(a,e){return{enumerable:!(a&1),configurable:!(a&2),writable:!(a&4),value:e}},Bo=br,Fo=Function.prototype,Ya=Fo.call,_l=Bo&&Fo.bind.bind(Ya,Ya),k=Bo?_l:function(a){return function(){return Ya.apply(a,arguments)}},jo=k,Dl=jo({}.toString),Vl=jo("".slice),Fe=function(a){return Vl(Dl(a),8,-1)},Ll=k,kl=L,Bl=Fe,Jr=Object,Fl=Ll("".split),Uo=kl(function(){return!Jr("z").propertyIsEnumerable(0)})?function(a){return Bl(a)==="String"?Fl(a,""):Jr(a)}:Jr,je=function(a){return a==null},jl=je,Ul=TypeError,ge=function(a){if(jl(a))throw new Ul("Can't call method on "+a);return a},zl=Uo,Gl=ge,At=function(a){return zl(Gl(a))},Xa=typeof document=="object"&&document.all,Hl=typeof Xa>"u"&&Xa!==void 0,zo={all:Xa,IS_HTMLDDA:Hl},Go=zo,Yl=Go.all,D=Go.IS_HTMLDDA?function(a){return typeof a=="function"||a===Yl}:function(a){return typeof a=="function"},yn=D,Ho=zo,Xl=Ho.all,Te=Ho.IS_HTMLDDA?function(a){return typeof a=="object"?a!==null:yn(a)||a===Xl}:function(a){return typeof a=="object"?a!==null:yn(a)},ea=U,Wl=D,ql=function(a){return Wl(a)?a:void 0},Ue=function(a,e){return arguments.length<2?ql(ea[a]):ea[a]&&ea[a][e]},Ql=k,Tr=Ql({}.isPrototypeOf),Sr=typeof navigator<"u"&&String(navigator.userAgent)||"",Yo=U,ta=Sr,mn=Yo.process,bn=Yo.Deno,xn=mn&&mn.versions||bn&&bn.version,Tn=xn&&xn.v8,ue,cr;Tn&&(ue=Tn.split("."),cr=ue[0]>0&&ue[0]<4?1:+(ue[0]+ue[1]));!cr&&ta&&(ue=ta.match(/Edge\/(\d+)/),(!ue||ue[1]>=74)&&(ue=ta.match(/Chrome\/(\d+)/),ue&&(cr=+ue[1])));var Oi=cr,Sn=Oi,Kl=L,Zl=U,Jl=Zl.String,Xo=!!Object.getOwnPropertySymbols&&!Kl(function(){var a=Symbol("symbol detection");return!Jl(a)||!(Object(a)instanceof Symbol)||!Symbol.sham&&Sn&&Sn<41}),eh=Xo,Wo=eh&&!Symbol.sham&&typeof Symbol.iterator=="symbol",th=Ue,rh=D,ah=Tr,ih=Wo,nh=Object,qo=ih?function(a){return typeof a=="symbol"}:function(a){var e=th("Symbol");return rh(e)&&ah(e.prototype,nh(a))},sh=String,Or=function(a){try{return sh(a)}catch{return"Object"}},oh=D,uh=Or,lh=TypeError,Se=function(a){if(oh(a))return a;throw new lh(uh(a)+" is not a function")},hh=Se,vh=je,lt=function(a,e){var t=a[e];return vh(t)?void 0:hh(t)},ra=Y,aa=D,ia=Te,fh=TypeError,ch=function(a,e){var t,r;if(e==="string"&&aa(t=a.toString)&&!ia(r=ra(t,a))||aa(t=a.valueOf)&&!ia(r=ra(t,a))||e!=="string"&&aa(t=a.toString)&&!ia(r=ra(t,a)))return r;throw new fh("Can't convert object to primitive value")},Qo={exports:{}},On=U,gh=Object.defineProperty,Ei=function(a,e){try{gh(On,a,{value:e,configurable:!0,writable:!0})}catch{On[a]=e}return e},dh=U,ph=Ei,En="__core-js_shared__",yh=dh[En]||ph(En,{}),$i=yh,$n=$i;(Qo.exports=function(a,e){return $n[a]||($n[a]=e!==void 0?e:{})})("versions",[]).push({version:"3.34.0",mode:"global",copyright:"© 2014-2023 Denis Pushkarev (zloirock.ru)",license:"https://github.com/zloirock/core-js/blob/v3.34.0/LICENSE",source:"https://github.com/zloirock/core-js"});var wi=Qo.exports,mh=ge,bh=Object,Er=function(a){return bh(mh(a))},xh=k,Th=Er,Sh=xh({}.hasOwnProperty),le=Object.hasOwn||function(e,t){return Sh(Th(e),t)},Oh=k,Eh=0,$h=Math.random(),wh=Oh(1 .toString),Ko=function(a){return"Symbol("+(a===void 0?"":a)+")_"+wh(++Eh+$h,36)},Ch=U,Ah=wi,wn=le,Ph=Ko,Rh=Xo,Ih=Wo,et=Ch.Symbol,na=Ah("wks"),Nh=Ih?et.for||et:et&&et.withoutSetter||Ph,G=function(a){return wn(na,a)||(na[a]=Rh&&wn(et,a)?et[a]:Nh("Symbol."+a)),na[a]},Mh=Y,Cn=Te,An=qo,_h=lt,Dh=ch,Vh=G,Lh=TypeError,kh=Vh("toPrimitive"),Bh=function(a,e){if(!Cn(a)||An(a))return a;var t=_h(a,kh),r;if(t){if(e===void 0&&(e="default"),r=Mh(t,a,e),!Cn(r)||An(r))return r;throw new Lh("Can't convert object to primitive value")}return e===void 0&&(e="number"),Dh(a,e)},Fh=Bh,jh=qo,Ci=function(a){var e=Fh(a,"string");return jh(e)?e:e+""},Uh=U,Pn=Te,Wa=Uh.document,zh=Pn(Wa)&&Pn(Wa.createElement),$r=function(a){return zh?Wa.createElement(a):{}},Gh=ce,Hh=L,Yh=$r,Zo=!Gh&&!Hh(function(){return Object.defineProperty(Yh("div"),"a",{get:function(){return 7}}).a!==7}),Xh=ce,Wh=Y,qh=Vo,Qh=xr,Kh=At,Zh=Ci,Jh=le,ev=Zo,Rn=Object.getOwnPropertyDescriptor;ut.f=Xh?Rn:function(e,t){if(e=Kh(e),t=Zh(t),ev)try{return Rn(e,t)}catch{}if(Jh(e,t))return Qh(!Wh(qh.f,e,t),e[t])};var de={},tv=ce,rv=L,Jo=tv&&rv(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!==42}),av=Te,iv=String,nv=TypeError,K=function(a){if(av(a))return a;throw new nv(iv(a)+" is not an object")},sv=ce,ov=Zo,uv=Jo,Yt=K,In=Ci,lv=TypeError,sa=Object.defineProperty,hv=Object.getOwnPropertyDescriptor,oa="enumerable",ua="configurable",la="writable";de.f=sv?uv?function(e,t,r){if(Yt(e),t=In(t),Yt(r),typeof e=="function"&&t==="prototype"&&"value"in r&&la in r&&!r[la]){var i=hv(e,t);i&&i[la]&&(e[t]=r.value,r={configurable:ua in r?r[ua]:i[ua],enumerable:oa in r?r[oa]:i[oa],writable:!1})}return sa(e,t,r)}:sa:function(e,t,r){if(Yt(e),t=In(t),Yt(r),ov)try{return sa(e,t,r)}catch{}if("get"in r||"set"in r)throw new lv("Accessors not supported");return"value"in r&&(e[t]=r.value),e};var vv=ce,fv=de,cv=xr,Pt=vv?function(a,e,t){return fv.f(a,e,cv(1,t))}:function(a,e,t){return a[e]=t,a},eu={exports:{}},qa=ce,gv=le,tu=Function.prototype,dv=qa&&Object.getOwnPropertyDescriptor,Ai=gv(tu,"name"),pv=Ai&&(function(){}).name==="something",yv=Ai&&(!qa||qa&&dv(tu,"name").configurable),wr={EXISTS:Ai,PROPER:pv,CONFIGURABLE:yv},mv=k,bv=D,Qa=$i,xv=mv(Function.toString);bv(Qa.inspectSource)||(Qa.inspectSource=function(a){return xv(a)});var Pi=Qa.inspectSource,Tv=U,Sv=D,Nn=Tv.WeakMap,Ov=Sv(Nn)&&/native code/.test(String(Nn)),Ev=wi,$v=Ko,Mn=Ev("keys"),Ri=function(a){return Mn[a]||(Mn[a]=$v(a))},Ii={},wv=Ov,ru=U,Cv=Te,Av=Pt,ha=le,va=$i,Pv=Ri,Rv=Ii,_n="Object already initialized",Ka=ru.TypeError,Iv=ru.WeakMap,gr,$t,dr,Nv=function(a){return dr(a)?$t(a):gr(a,{})},Mv=function(a){return function(e){var t;if(!Cv(e)||(t=$t(e)).type!==a)throw new Ka("Incompatible receiver, "+a+" required");return t}};if(wv||va.state){var fe=va.state||(va.state=new Iv);fe.get=fe.get,fe.has=fe.has,fe.set=fe.set,gr=function(a,e){if(fe.has(a))throw new Ka(_n);return e.facade=a,fe.set(a,e),e},$t=function(a){return fe.get(a)||{}},dr=function(a){return fe.has(a)}}else{var Xe=Pv("state");Rv[Xe]=!0,gr=function(a,e){if(ha(a,Xe))throw new Ka(_n);return e.facade=a,Av(a,Xe,e),e},$t=function(a){return ha(a,Xe)?a[Xe]:{}},dr=function(a){return ha(a,Xe)}}var Cr={set:gr,get:$t,has:dr,enforce:Nv,getterFor:Mv},Ni=k,_v=L,Dv=D,Xt=le,Za=ce,Vv=wr.CONFIGURABLE,Lv=Pi,au=Cr,kv=au.enforce,Bv=au.get,Dn=String,or=Object.defineProperty,Fv=Ni("".slice),jv=Ni("".replace),Uv=Ni([].join),zv=Za&&!_v(function(){return or(function(){},"length",{value:8}).length!==8}),Gv=String(String).split("String"),Hv=eu.exports=function(a,e,t){Fv(Dn(e),0,7)==="Symbol("&&(e="["+jv(Dn(e),/^Symbol\(([^)]*)\)/,"$1")+"]"),t&&t.getter&&(e="get "+e),t&&t.setter&&(e="set "+e),(!Xt(a,"name")||Vv&&a.name!==e)&&(Za?or(a,"name",{value:e,configurable:!0}):a.name=e),zv&&t&&Xt(t,"arity")&&a.length!==t.arity&&or(a,"length",{value:t.arity});try{t&&Xt(t,"constructor")&&t.constructor?Za&&or(a,"prototype",{writable:!1}):a.prototype&&(a.prototype=void 0)}catch{}var r=kv(a);return Xt(r,"source")||(r.source=Uv(Gv,typeof e=="string"?e:"")),a};Function.prototype.toString=Hv(function(){return Dv(this)&&Bv(this).source||Lv(this)},"toString");var iu=eu.exports,Yv=D,Xv=de,Wv=iu,qv=Ei,ze=function(a,e,t,r){r||(r={});var i=r.enumerable,n=r.name!==void 0?r.name:e;if(Yv(t)&&Wv(t,n,r),r.global)i?a[e]=t:qv(e,t);else{try{r.unsafe?a[e]&&(i=!0):delete a[e]}catch{}i?a[e]=t:Xv.f(a,e,{value:t,enumerable:!1,configurable:!r.nonConfigurable,writable:!r.nonWritable})}return a},nu={},Qv=Math.ceil,Kv=Math.floor,Zv=Math.trunc||function(e){var t=+e;return(t>0?Kv:Qv)(t)},Jv=Zv,Ar=function(a){var e=+a;return e!==e||e===0?0:Jv(e)},ef=Ar,tf=Math.max,rf=Math.min,su=function(a,e){var t=ef(a);return t<0?tf(t+e,0):rf(t,e)},af=Ar,nf=Math.min,ht=function(a){return a>0?nf(af(a),9007199254740991):0},sf=ht,Pr=function(a){return sf(a.length)},of=At,uf=su,lf=Pr,Vn=function(a){return function(e,t,r){var i=of(e),n=lf(i),o=uf(r,n),s;if(a&&t!==t){for(;n>o;)if(s=i[o++],s!==s)return!0}else for(;n>o;o++)if((a||o in i)&&i[o]===t)return a||o||0;return!a&&-1}},ou={includes:Vn(!0),indexOf:Vn(!1)},hf=k,fa=le,vf=At,ff=ou.indexOf,cf=Ii,Ln=hf([].push),uu=function(a,e){var t=vf(a),r=0,i=[],n;for(n in t)!fa(cf,n)&&fa(t,n)&&Ln(i,n);for(;e.length>r;)fa(t,n=e[r++])&&(~ff(i,n)||Ln(i,n));return i},Mi=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"],gf=uu,df=Mi,pf=df.concat("length","prototype");nu.f=Object.getOwnPropertyNames||function(e){return gf(e,pf)};var lu={};lu.f=Object.getOwnPropertySymbols;var yf=Ue,mf=k,bf=nu,xf=lu,Tf=K,Sf=mf([].concat),Of=yf("Reflect","ownKeys")||function(e){var t=bf.f(Tf(e)),r=xf.f;return r?Sf(t,r(e)):t},kn=le,Ef=Of,$f=ut,wf=de,Cf=function(a,e,t){for(var r=Ef(e),i=wf.f,n=$f.f,o=0;of;f++)if(v=y(a[f]),v&&gs(ps,v))return v;return new hr(!1)}l=$d(a,h)}for(d=n?a.next:l.next;!(g=xd(d,l)).done;){try{v=y(g.value)}catch(x){ds(l,"throw",x)}if(typeof v=="object"&&v&&gs(ps,v))return v}return new hr(!1)},Ad=G,ju=Ad("iterator"),Uu=!1;try{var Pd=0,ys={next:function(){return{done:!!Pd++}},return:function(){Uu=!0}};ys[ju]=function(){return this},Array.from(ys,function(){throw 2})}catch{}var Rd=function(a,e){try{if(!e&&!Uu)return!1}catch{return!1}var t=!1;try{var r={};r[ju]=function(){return{next:function(){return{done:t=!0}}}},a(r)}catch{}return t},Id=Ir,Nd=Rd,Md=Mt.CONSTRUCTOR,zu=Md||!Nd(function(a){Id.all(a).then(void 0,function(){})}),_d=ee,Dd=Y,Vd=Se,Ld=vt,kd=Bi,Bd=Fu,Fd=zu;_d({target:"Promise",stat:!0,forced:Fd},{all:function(e){var t=this,r=Ld.f(t),i=r.resolve,n=r.reject,o=kd(function(){var s=Vd(t.resolve),u=[],l=0,h=1;Bd(e,function(f){var c=l++,v=!1;h++,Dd(s,t,f).then(function(d){v||(v=!0,u[c]=d,--h||i(u))},n)}),--h||i(u)});return o.error&&n(o.value),r.promise}});var jd=ee,Ud=Mt.CONSTRUCTOR,si=Ir,zd=Ue,Gd=D,Hd=ze,ms=si&&si.prototype;jd({target:"Promise",proto:!0,forced:Ud,real:!0},{catch:function(a){return this.then(void 0,a)}});if(Gd(si)){var bs=zd("Promise").prototype.catch;ms.catch!==bs&&Hd(ms,"catch",bs,{unsafe:!0})}var Yd=ee,Xd=Y,Wd=Se,qd=vt,Qd=Bi,Kd=Fu,Zd=zu;Yd({target:"Promise",stat:!0,forced:Zd},{race:function(e){var t=this,r=qd.f(t),i=r.reject,n=Qd(function(){var o=Wd(t.resolve);Kd(e,function(s){Xd(o,t,s).then(r.resolve,i)})});return n.error&&i(n.value),r.promise}});var Jd=ee,ep=Y,tp=vt,rp=Mt.CONSTRUCTOR;Jd({target:"Promise",stat:!0,forced:rp},{reject:function(e){var t=tp.f(this);return ep(t.reject,void 0,e),t.promise}});var ap=K,ip=Te,np=vt,sp=function(a,e){if(ap(a),ip(e)&&e.constructor===a)return e;var t=np.f(a),r=t.resolve;return r(e),t.promise},op=ee,up=Ue,lp=Mt.CONSTRUCTOR,hp=sp;up("Promise");op({target:"Promise",stat:!0,forced:lp},{resolve:function(e){return hp(this,e)}});function xs(a,e,t,r,i,n,o){try{var s=a[n](o),u=s.value}catch(l){t(l);return}s.done?e(u):Promise.resolve(u).then(r,i)}function xe(a){return function(){var e=this,t=arguments;return new Promise(function(r,i){var n=a.apply(e,t);function o(u){xs(n,r,i,o,s,"next",u)}function s(u){xs(n,r,i,o,s,"throw",u)}o(void 0)})}}var vp=_i,fp=String,pe=function(a){if(vp(a)==="Symbol")throw new TypeError("Cannot convert a Symbol value to a string");return fp(a)},cp=K,Gu=function(){var a=cp(this),e="";return a.hasIndices&&(e+="d"),a.global&&(e+="g"),a.ignoreCase&&(e+="i"),a.multiline&&(e+="m"),a.dotAll&&(e+="s"),a.unicode&&(e+="u"),a.unicodeSets&&(e+="v"),a.sticky&&(e+="y"),e},Gi=L,gp=U,Hi=gp.RegExp,Yi=Gi(function(){var a=Hi("a","y");return a.lastIndex=2,a.exec("abcd")!==null}),dp=Yi||Gi(function(){return!Hi("a","y").sticky}),pp=Yi||Gi(function(){var a=Hi("^r","gy");return a.lastIndex=2,a.exec("str")!==null}),Hu={BROKEN_CARET:pp,MISSED_STICKY:dp,UNSUPPORTED_Y:Yi},Yu={},yp=uu,mp=Mi,bp=Object.keys||function(e){return yp(e,mp)},xp=ce,Tp=Jo,Sp=de,Op=K,Ep=At,$p=bp;Yu.f=xp&&!Tp?Object.defineProperties:function(e,t){Op(e);for(var r=Ep(t),i=$p(t),n=i.length,o=0,s;n>o;)Sp.f(e,s=i[o++],r[s]);return e};var wp=K,Cp=Yu,Ts=Mi,Ap=Ii,Pp=bu,Rp=$r,Ip=Ri,Ss=">",Os="<",oi="prototype",ui="script",Xu=Ip("IE_PROTO"),$a=function(){},Wu=function(a){return Os+ui+Ss+a+Os+"/"+ui+Ss},Es=function(a){a.write(Wu("")),a.close();var e=a.parentWindow.Object;return a=null,e},Np=function(){var a=Rp("iframe"),e="java"+ui+":",t;return a.style.display="none",Pp.appendChild(a),a.src=String(e),t=a.contentWindow.document,t.open(),t.write(Wu("document.F=Object")),t.close(),t.F},er,vr=function(){try{er=new ActiveXObject("htmlfile")}catch{}vr=typeof document<"u"?document.domain&&er?Es(er):Np():Es(er);for(var a=Ts.length;a--;)delete vr[oi][Ts[a]];return vr()};Ap[Xu]=!0;var Xi=Object.create||function(e,t){var r;return e!==null?($a[oi]=wp(e),r=new $a,$a[oi]=null,r[Xu]=e):r=vr(),t===void 0?r:Cp.f(r,t)},Mp=L,_p=U,Dp=_p.RegExp,Vp=Mp(function(){var a=Dp(".","s");return!(a.dotAll&&a.test(` +import{c as Je,g as Do}from"./main-ab68e62d.js";import{_ as Ha}from"./jspdf.es.min-9eaca9d8.js";var ct=function(a){return a&&a.Math===Math&&a},U=ct(typeof globalThis=="object"&&globalThis)||ct(typeof window=="object"&&window)||ct(typeof self=="object"&&self)||ct(typeof Je=="object"&&Je)||ct(typeof Je=="object"&&Je)||function(){return this}()||Function("return this")(),ut={},L=function(a){try{return!!a()}catch{return!0}},Rl=L,ce=!Rl(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!==7}),Il=L,br=!Il(function(){var a=(function(){}).bind();return typeof a!="function"||a.hasOwnProperty("prototype")}),Nl=br,Ht=Function.prototype.call,Y=Nl?Ht.bind(Ht):function(){return Ht.apply(Ht,arguments)},Vo={},Lo={}.propertyIsEnumerable,ko=Object.getOwnPropertyDescriptor,Ml=ko&&!Lo.call({1:2},1);Vo.f=Ml?function(e){var t=ko(this,e);return!!t&&t.enumerable}:Lo;var xr=function(a,e){return{enumerable:!(a&1),configurable:!(a&2),writable:!(a&4),value:e}},Bo=br,Fo=Function.prototype,Ya=Fo.call,_l=Bo&&Fo.bind.bind(Ya,Ya),k=Bo?_l:function(a){return function(){return Ya.apply(a,arguments)}},jo=k,Dl=jo({}.toString),Vl=jo("".slice),Fe=function(a){return Vl(Dl(a),8,-1)},Ll=k,kl=L,Bl=Fe,Jr=Object,Fl=Ll("".split),Uo=kl(function(){return!Jr("z").propertyIsEnumerable(0)})?function(a){return Bl(a)==="String"?Fl(a,""):Jr(a)}:Jr,je=function(a){return a==null},jl=je,Ul=TypeError,ge=function(a){if(jl(a))throw new Ul("Can't call method on "+a);return a},zl=Uo,Gl=ge,At=function(a){return zl(Gl(a))},Xa=typeof document=="object"&&document.all,Hl=typeof Xa>"u"&&Xa!==void 0,zo={all:Xa,IS_HTMLDDA:Hl},Go=zo,Yl=Go.all,D=Go.IS_HTMLDDA?function(a){return typeof a=="function"||a===Yl}:function(a){return typeof a=="function"},yn=D,Ho=zo,Xl=Ho.all,Te=Ho.IS_HTMLDDA?function(a){return typeof a=="object"?a!==null:yn(a)||a===Xl}:function(a){return typeof a=="object"?a!==null:yn(a)},ea=U,Wl=D,ql=function(a){return Wl(a)?a:void 0},Ue=function(a,e){return arguments.length<2?ql(ea[a]):ea[a]&&ea[a][e]},Ql=k,Tr=Ql({}.isPrototypeOf),Sr=typeof navigator<"u"&&String(navigator.userAgent)||"",Yo=U,ta=Sr,mn=Yo.process,bn=Yo.Deno,xn=mn&&mn.versions||bn&&bn.version,Tn=xn&&xn.v8,ue,cr;Tn&&(ue=Tn.split("."),cr=ue[0]>0&&ue[0]<4?1:+(ue[0]+ue[1]));!cr&&ta&&(ue=ta.match(/Edge\/(\d+)/),(!ue||ue[1]>=74)&&(ue=ta.match(/Chrome\/(\d+)/),ue&&(cr=+ue[1])));var Oi=cr,Sn=Oi,Kl=L,Zl=U,Jl=Zl.String,Xo=!!Object.getOwnPropertySymbols&&!Kl(function(){var a=Symbol("symbol detection");return!Jl(a)||!(Object(a)instanceof Symbol)||!Symbol.sham&&Sn&&Sn<41}),eh=Xo,Wo=eh&&!Symbol.sham&&typeof Symbol.iterator=="symbol",th=Ue,rh=D,ah=Tr,ih=Wo,nh=Object,qo=ih?function(a){return typeof a=="symbol"}:function(a){var e=th("Symbol");return rh(e)&&ah(e.prototype,nh(a))},sh=String,Or=function(a){try{return sh(a)}catch{return"Object"}},oh=D,uh=Or,lh=TypeError,Se=function(a){if(oh(a))return a;throw new lh(uh(a)+" is not a function")},hh=Se,vh=je,lt=function(a,e){var t=a[e];return vh(t)?void 0:hh(t)},ra=Y,aa=D,ia=Te,fh=TypeError,ch=function(a,e){var t,r;if(e==="string"&&aa(t=a.toString)&&!ia(r=ra(t,a))||aa(t=a.valueOf)&&!ia(r=ra(t,a))||e!=="string"&&aa(t=a.toString)&&!ia(r=ra(t,a)))return r;throw new fh("Can't convert object to primitive value")},Qo={exports:{}},On=U,gh=Object.defineProperty,Ei=function(a,e){try{gh(On,a,{value:e,configurable:!0,writable:!0})}catch{On[a]=e}return e},dh=U,ph=Ei,En="__core-js_shared__",yh=dh[En]||ph(En,{}),$i=yh,$n=$i;(Qo.exports=function(a,e){return $n[a]||($n[a]=e!==void 0?e:{})})("versions",[]).push({version:"3.34.0",mode:"global",copyright:"© 2014-2023 Denis Pushkarev (zloirock.ru)",license:"https://github.com/zloirock/core-js/blob/v3.34.0/LICENSE",source:"https://github.com/zloirock/core-js"});var wi=Qo.exports,mh=ge,bh=Object,Er=function(a){return bh(mh(a))},xh=k,Th=Er,Sh=xh({}.hasOwnProperty),le=Object.hasOwn||function(e,t){return Sh(Th(e),t)},Oh=k,Eh=0,$h=Math.random(),wh=Oh(1 .toString),Ko=function(a){return"Symbol("+(a===void 0?"":a)+")_"+wh(++Eh+$h,36)},Ch=U,Ah=wi,wn=le,Ph=Ko,Rh=Xo,Ih=Wo,et=Ch.Symbol,na=Ah("wks"),Nh=Ih?et.for||et:et&&et.withoutSetter||Ph,G=function(a){return wn(na,a)||(na[a]=Rh&&wn(et,a)?et[a]:Nh("Symbol."+a)),na[a]},Mh=Y,Cn=Te,An=qo,_h=lt,Dh=ch,Vh=G,Lh=TypeError,kh=Vh("toPrimitive"),Bh=function(a,e){if(!Cn(a)||An(a))return a;var t=_h(a,kh),r;if(t){if(e===void 0&&(e="default"),r=Mh(t,a,e),!Cn(r)||An(r))return r;throw new Lh("Can't convert object to primitive value")}return e===void 0&&(e="number"),Dh(a,e)},Fh=Bh,jh=qo,Ci=function(a){var e=Fh(a,"string");return jh(e)?e:e+""},Uh=U,Pn=Te,Wa=Uh.document,zh=Pn(Wa)&&Pn(Wa.createElement),$r=function(a){return zh?Wa.createElement(a):{}},Gh=ce,Hh=L,Yh=$r,Zo=!Gh&&!Hh(function(){return Object.defineProperty(Yh("div"),"a",{get:function(){return 7}}).a!==7}),Xh=ce,Wh=Y,qh=Vo,Qh=xr,Kh=At,Zh=Ci,Jh=le,ev=Zo,Rn=Object.getOwnPropertyDescriptor;ut.f=Xh?Rn:function(e,t){if(e=Kh(e),t=Zh(t),ev)try{return Rn(e,t)}catch{}if(Jh(e,t))return Qh(!Wh(qh.f,e,t),e[t])};var de={},tv=ce,rv=L,Jo=tv&&rv(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!==42}),av=Te,iv=String,nv=TypeError,K=function(a){if(av(a))return a;throw new nv(iv(a)+" is not an object")},sv=ce,ov=Zo,uv=Jo,Yt=K,In=Ci,lv=TypeError,sa=Object.defineProperty,hv=Object.getOwnPropertyDescriptor,oa="enumerable",ua="configurable",la="writable";de.f=sv?uv?function(e,t,r){if(Yt(e),t=In(t),Yt(r),typeof e=="function"&&t==="prototype"&&"value"in r&&la in r&&!r[la]){var i=hv(e,t);i&&i[la]&&(e[t]=r.value,r={configurable:ua in r?r[ua]:i[ua],enumerable:oa in r?r[oa]:i[oa],writable:!1})}return sa(e,t,r)}:sa:function(e,t,r){if(Yt(e),t=In(t),Yt(r),ov)try{return sa(e,t,r)}catch{}if("get"in r||"set"in r)throw new lv("Accessors not supported");return"value"in r&&(e[t]=r.value),e};var vv=ce,fv=de,cv=xr,Pt=vv?function(a,e,t){return fv.f(a,e,cv(1,t))}:function(a,e,t){return a[e]=t,a},eu={exports:{}},qa=ce,gv=le,tu=Function.prototype,dv=qa&&Object.getOwnPropertyDescriptor,Ai=gv(tu,"name"),pv=Ai&&(function(){}).name==="something",yv=Ai&&(!qa||qa&&dv(tu,"name").configurable),wr={EXISTS:Ai,PROPER:pv,CONFIGURABLE:yv},mv=k,bv=D,Qa=$i,xv=mv(Function.toString);bv(Qa.inspectSource)||(Qa.inspectSource=function(a){return xv(a)});var Pi=Qa.inspectSource,Tv=U,Sv=D,Nn=Tv.WeakMap,Ov=Sv(Nn)&&/native code/.test(String(Nn)),Ev=wi,$v=Ko,Mn=Ev("keys"),Ri=function(a){return Mn[a]||(Mn[a]=$v(a))},Ii={},wv=Ov,ru=U,Cv=Te,Av=Pt,ha=le,va=$i,Pv=Ri,Rv=Ii,_n="Object already initialized",Ka=ru.TypeError,Iv=ru.WeakMap,gr,$t,dr,Nv=function(a){return dr(a)?$t(a):gr(a,{})},Mv=function(a){return function(e){var t;if(!Cv(e)||(t=$t(e)).type!==a)throw new Ka("Incompatible receiver, "+a+" required");return t}};if(wv||va.state){var fe=va.state||(va.state=new Iv);fe.get=fe.get,fe.has=fe.has,fe.set=fe.set,gr=function(a,e){if(fe.has(a))throw new Ka(_n);return e.facade=a,fe.set(a,e),e},$t=function(a){return fe.get(a)||{}},dr=function(a){return fe.has(a)}}else{var Xe=Pv("state");Rv[Xe]=!0,gr=function(a,e){if(ha(a,Xe))throw new Ka(_n);return e.facade=a,Av(a,Xe,e),e},$t=function(a){return ha(a,Xe)?a[Xe]:{}},dr=function(a){return ha(a,Xe)}}var Cr={set:gr,get:$t,has:dr,enforce:Nv,getterFor:Mv},Ni=k,_v=L,Dv=D,Xt=le,Za=ce,Vv=wr.CONFIGURABLE,Lv=Pi,au=Cr,kv=au.enforce,Bv=au.get,Dn=String,or=Object.defineProperty,Fv=Ni("".slice),jv=Ni("".replace),Uv=Ni([].join),zv=Za&&!_v(function(){return or(function(){},"length",{value:8}).length!==8}),Gv=String(String).split("String"),Hv=eu.exports=function(a,e,t){Fv(Dn(e),0,7)==="Symbol("&&(e="["+jv(Dn(e),/^Symbol\(([^)]*)\)/,"$1")+"]"),t&&t.getter&&(e="get "+e),t&&t.setter&&(e="set "+e),(!Xt(a,"name")||Vv&&a.name!==e)&&(Za?or(a,"name",{value:e,configurable:!0}):a.name=e),zv&&t&&Xt(t,"arity")&&a.length!==t.arity&&or(a,"length",{value:t.arity});try{t&&Xt(t,"constructor")&&t.constructor?Za&&or(a,"prototype",{writable:!1}):a.prototype&&(a.prototype=void 0)}catch{}var r=kv(a);return Xt(r,"source")||(r.source=Uv(Gv,typeof e=="string"?e:"")),a};Function.prototype.toString=Hv(function(){return Dv(this)&&Bv(this).source||Lv(this)},"toString");var iu=eu.exports,Yv=D,Xv=de,Wv=iu,qv=Ei,ze=function(a,e,t,r){r||(r={});var i=r.enumerable,n=r.name!==void 0?r.name:e;if(Yv(t)&&Wv(t,n,r),r.global)i?a[e]=t:qv(e,t);else{try{r.unsafe?a[e]&&(i=!0):delete a[e]}catch{}i?a[e]=t:Xv.f(a,e,{value:t,enumerable:!1,configurable:!r.nonConfigurable,writable:!r.nonWritable})}return a},nu={},Qv=Math.ceil,Kv=Math.floor,Zv=Math.trunc||function(e){var t=+e;return(t>0?Kv:Qv)(t)},Jv=Zv,Ar=function(a){var e=+a;return e!==e||e===0?0:Jv(e)},ef=Ar,tf=Math.max,rf=Math.min,su=function(a,e){var t=ef(a);return t<0?tf(t+e,0):rf(t,e)},af=Ar,nf=Math.min,ht=function(a){return a>0?nf(af(a),9007199254740991):0},sf=ht,Pr=function(a){return sf(a.length)},of=At,uf=su,lf=Pr,Vn=function(a){return function(e,t,r){var i=of(e),n=lf(i),o=uf(r,n),s;if(a&&t!==t){for(;n>o;)if(s=i[o++],s!==s)return!0}else for(;n>o;o++)if((a||o in i)&&i[o]===t)return a||o||0;return!a&&-1}},ou={includes:Vn(!0),indexOf:Vn(!1)},hf=k,fa=le,vf=At,ff=ou.indexOf,cf=Ii,Ln=hf([].push),uu=function(a,e){var t=vf(a),r=0,i=[],n;for(n in t)!fa(cf,n)&&fa(t,n)&&Ln(i,n);for(;e.length>r;)fa(t,n=e[r++])&&(~ff(i,n)||Ln(i,n));return i},Mi=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"],gf=uu,df=Mi,pf=df.concat("length","prototype");nu.f=Object.getOwnPropertyNames||function(e){return gf(e,pf)};var lu={};lu.f=Object.getOwnPropertySymbols;var yf=Ue,mf=k,bf=nu,xf=lu,Tf=K,Sf=mf([].concat),Of=yf("Reflect","ownKeys")||function(e){var t=bf.f(Tf(e)),r=xf.f;return r?Sf(t,r(e)):t},kn=le,Ef=Of,$f=ut,wf=de,Cf=function(a,e,t){for(var r=Ef(e),i=wf.f,n=$f.f,o=0;of;f++)if(v=y(a[f]),v&&gs(ps,v))return v;return new hr(!1)}l=$d(a,h)}for(d=n?a.next:l.next;!(g=xd(d,l)).done;){try{v=y(g.value)}catch(x){ds(l,"throw",x)}if(typeof v=="object"&&v&&gs(ps,v))return v}return new hr(!1)},Ad=G,ju=Ad("iterator"),Uu=!1;try{var Pd=0,ys={next:function(){return{done:!!Pd++}},return:function(){Uu=!0}};ys[ju]=function(){return this},Array.from(ys,function(){throw 2})}catch{}var Rd=function(a,e){try{if(!e&&!Uu)return!1}catch{return!1}var t=!1;try{var r={};r[ju]=function(){return{next:function(){return{done:t=!0}}}},a(r)}catch{}return t},Id=Ir,Nd=Rd,Md=Mt.CONSTRUCTOR,zu=Md||!Nd(function(a){Id.all(a).then(void 0,function(){})}),_d=ee,Dd=Y,Vd=Se,Ld=vt,kd=Bi,Bd=Fu,Fd=zu;_d({target:"Promise",stat:!0,forced:Fd},{all:function(e){var t=this,r=Ld.f(t),i=r.resolve,n=r.reject,o=kd(function(){var s=Vd(t.resolve),u=[],l=0,h=1;Bd(e,function(f){var c=l++,v=!1;h++,Dd(s,t,f).then(function(d){v||(v=!0,u[c]=d,--h||i(u))},n)}),--h||i(u)});return o.error&&n(o.value),r.promise}});var jd=ee,Ud=Mt.CONSTRUCTOR,si=Ir,zd=Ue,Gd=D,Hd=ze,ms=si&&si.prototype;jd({target:"Promise",proto:!0,forced:Ud,real:!0},{catch:function(a){return this.then(void 0,a)}});if(Gd(si)){var bs=zd("Promise").prototype.catch;ms.catch!==bs&&Hd(ms,"catch",bs,{unsafe:!0})}var Yd=ee,Xd=Y,Wd=Se,qd=vt,Qd=Bi,Kd=Fu,Zd=zu;Yd({target:"Promise",stat:!0,forced:Zd},{race:function(e){var t=this,r=qd.f(t),i=r.reject,n=Qd(function(){var o=Wd(t.resolve);Kd(e,function(s){Xd(o,t,s).then(r.resolve,i)})});return n.error&&i(n.value),r.promise}});var Jd=ee,ep=Y,tp=vt,rp=Mt.CONSTRUCTOR;Jd({target:"Promise",stat:!0,forced:rp},{reject:function(e){var t=tp.f(this);return ep(t.reject,void 0,e),t.promise}});var ap=K,ip=Te,np=vt,sp=function(a,e){if(ap(a),ip(e)&&e.constructor===a)return e;var t=np.f(a),r=t.resolve;return r(e),t.promise},op=ee,up=Ue,lp=Mt.CONSTRUCTOR,hp=sp;up("Promise");op({target:"Promise",stat:!0,forced:lp},{resolve:function(e){return hp(this,e)}});function xs(a,e,t,r,i,n,o){try{var s=a[n](o),u=s.value}catch(l){t(l);return}s.done?e(u):Promise.resolve(u).then(r,i)}function xe(a){return function(){var e=this,t=arguments;return new Promise(function(r,i){var n=a.apply(e,t);function o(u){xs(n,r,i,o,s,"next",u)}function s(u){xs(n,r,i,o,s,"throw",u)}o(void 0)})}}var vp=_i,fp=String,pe=function(a){if(vp(a)==="Symbol")throw new TypeError("Cannot convert a Symbol value to a string");return fp(a)},cp=K,Gu=function(){var a=cp(this),e="";return a.hasIndices&&(e+="d"),a.global&&(e+="g"),a.ignoreCase&&(e+="i"),a.multiline&&(e+="m"),a.dotAll&&(e+="s"),a.unicode&&(e+="u"),a.unicodeSets&&(e+="v"),a.sticky&&(e+="y"),e},Gi=L,gp=U,Hi=gp.RegExp,Yi=Gi(function(){var a=Hi("a","y");return a.lastIndex=2,a.exec("abcd")!==null}),dp=Yi||Gi(function(){return!Hi("a","y").sticky}),pp=Yi||Gi(function(){var a=Hi("^r","gy");return a.lastIndex=2,a.exec("str")!==null}),Hu={BROKEN_CARET:pp,MISSED_STICKY:dp,UNSUPPORTED_Y:Yi},Yu={},yp=uu,mp=Mi,bp=Object.keys||function(e){return yp(e,mp)},xp=ce,Tp=Jo,Sp=de,Op=K,Ep=At,$p=bp;Yu.f=xp&&!Tp?Object.defineProperties:function(e,t){Op(e);for(var r=Ep(t),i=$p(t),n=i.length,o=0,s;n>o;)Sp.f(e,s=i[o++],r[s]);return e};var wp=K,Cp=Yu,Ts=Mi,Ap=Ii,Pp=bu,Rp=$r,Ip=Ri,Ss=">",Os="<",oi="prototype",ui="script",Xu=Ip("IE_PROTO"),$a=function(){},Wu=function(a){return Os+ui+Ss+a+Os+"/"+ui+Ss},Es=function(a){a.write(Wu("")),a.close();var e=a.parentWindow.Object;return a=null,e},Np=function(){var a=Rp("iframe"),e="java"+ui+":",t;return a.style.display="none",Pp.appendChild(a),a.src=String(e),t=a.contentWindow.document,t.open(),t.write(Wu("document.F=Object")),t.close(),t.F},er,vr=function(){try{er=new ActiveXObject("htmlfile")}catch{}vr=typeof document<"u"?document.domain&&er?Es(er):Np():Es(er);for(var a=Ts.length;a--;)delete vr[oi][Ts[a]];return vr()};Ap[Xu]=!0;var Xi=Object.create||function(e,t){var r;return e!==null?($a[oi]=wp(e),r=new $a,$a[oi]=null,r[Xu]=e):r=vr(),t===void 0?r:Cp.f(r,t)},Mp=L,_p=U,Dp=_p.RegExp,Vp=Mp(function(){var a=Dp(".","s");return!(a.dotAll&&a.test(` `)&&a.flags==="s")}),Lp=L,kp=U,Bp=kp.RegExp,Fp=Lp(function(){var a=Bp("(?b)","g");return a.exec("b").groups.a!=="b"||"b".replace(a,"$c")!=="bc"}),rt=Y,Mr=k,jp=pe,Up=Gu,zp=Hu,Gp=wi,Hp=Xi,Yp=Cr.get,Xp=Vp,Wp=Fp,qp=Gp("native-string-replace",String.prototype.replace),mr=RegExp.prototype.exec,li=mr,Qp=Mr("".charAt),Kp=Mr("".indexOf),Zp=Mr("".replace),wa=Mr("".slice),hi=function(){var a=/a/,e=/b*/g;return rt(mr,a,"a"),rt(mr,e,"a"),a.lastIndex!==0||e.lastIndex!==0}(),qu=zp.BROKEN_CARET,vi=/()??/.exec("")[1]!==void 0,Jp=hi||vi||qu||Xp||Wp;Jp&&(li=function(e){var t=this,r=Yp(t),i=jp(e),n=r.raw,o,s,u,l,h,f,c;if(n)return n.lastIndex=t.lastIndex,o=rt(li,n,i),t.lastIndex=n.lastIndex,o;var v=r.groups,d=qu&&t.sticky,g=rt(Up,t),p=t.source,y=0,x=i;if(d&&(g=Zp(g,"y",""),Kp(g,"g")===-1&&(g+="g"),x=wa(i,t.lastIndex),t.lastIndex>0&&(!t.multiline||t.multiline&&Qp(i,t.lastIndex-1)!==` `)&&(p="(?: "+p+")",x=" "+x,y++),s=new RegExp("^(?:"+p+")",g)),vi&&(s=new RegExp("^"+p+"$(?!\\s)",g)),hi&&(u=t.lastIndex),l=rt(mr,d?s:t,x),d?l?(l.input=wa(l.input,y),l[0]=wa(l[0],y),l.index=t.lastIndex,t.lastIndex+=l[0].length):t.lastIndex=0:hi&&l&&(t.lastIndex=t.global?l.index+l[0].length:u),vi&&l&&l.length>1&&rt(qp,l[0],s,function(){for(h=1;h=n?a?"":void 0:(o=Ps(r,i),o<55296||o>56319||i+1===n||(s=Ps(r,i+1))<56320||s>57343?a?oy(r,i):o:a?uy(r,i,i+2):(o-55296<<10)+(s-56320)+65536)}},ly={codeAt:Rs(!1),charAt:Rs(!0)},hy=ly.charAt,Qi=function(a,e,t){return e+(t?hy(a,e).length:1)},Is=Y,vy=K,fy=D,cy=Fe,gy=_r,dy=TypeError,Ki=function(a,e){var t=a.exec;if(fy(t)){var r=Is(t,a,e);return r!==null&&vy(r),r}if(cy(a)==="RegExp")return Is(gy,a,e);throw new dy("RegExp#exec called on incompatible receiver")},py=Y,yy=Wi,my=K,by=je,xy=ht,Aa=pe,Ty=ge,Sy=lt,Oy=Qi,Ns=Ki;yy("match",function(a,e,t){return[function(i){var n=Ty(this),o=by(i)?void 0:Sy(i,a);return o?py(o,i,n):new RegExp(i)[a](Aa(n))},function(r){var i=my(this),n=Aa(r),o=t(e,i,n);if(o.done)return o.value;if(!i.global)return Ns(i,n);var s=i.unicode;i.lastIndex=0;for(var u=[],l=0,h;(h=Ns(i,n))!==null;){var f=Aa(h[0]);u[l]=f,f===""&&(i.lastIndex=Oy(n,xy(i.lastIndex),s)),l++}return l===0?null:u}]});var Zi=k,Ey=Er,$y=Math.floor,Pa=Zi("".charAt),wy=Zi("".replace),Ra=Zi("".slice),Cy=/\$([$&'`]|\d{1,2}|<[^>]*>)/g,Ay=/\$([$&'`]|\d{1,2})/g,Py=function(a,e,t,r,i,n){var o=t+a.length,s=r.length,u=Ay;return i!==void 0&&(i=Ey(i),u=Cy),wy(n,u,function(l,h){var f;switch(Pa(h,0)){case"$":return"$";case"&":return a;case"`":return Ra(e,0,t);case"'":return Ra(e,o);case"<":f=i[Ra(h,1,-1)];break;default:var c=+h;if(c===0)return l;if(c>s){var v=$y(c/10);return v===0?l:v<=s?r[v-1]===void 0?Pa(h,1):r[v-1]+Pa(h,1):l}f=r[c-1]}return f===void 0?"":f})},Ry=Vi,Ms=Y,Dr=k,Iy=Wi,Ny=L,My=K,_y=D,Dy=je,Vy=Ar,Ly=ht,qe=pe,ky=ge,By=Qi,Fy=lt,jy=Py,Uy=Ki,zy=G,fi=zy("replace"),Gy=Math.max,Hy=Math.min,Yy=Dr([].concat),Ia=Dr([].push),_s=Dr("".indexOf),Ds=Dr("".slice),Xy=function(a){return a===void 0?a:String(a)},Wy=function(){return"a".replace(/./,"$0")==="$0"}(),Vs=function(){return/./[fi]?/./[fi]("a","$0")==="":!1}(),qy=!Ny(function(){var a=/./;return a.exec=function(){var e=[];return e.groups={a:"7"},e},"".replace(a,"$")!=="7"});Iy("replace",function(a,e,t){var r=Vs?"$":"$0";return[function(n,o){var s=ky(this),u=Dy(n)?void 0:Fy(n,fi);return u?Ms(u,n,s,o):Ms(e,qe(s),n,o)},function(i,n){var o=My(this),s=qe(i);if(typeof n=="string"&&_s(n,r)===-1&&_s(n,"$<")===-1){var u=t(e,o,s,n);if(u.done)return u.value}var l=_y(n);l||(n=qe(n));var h=o.global,f;h&&(f=o.unicode,o.lastIndex=0);for(var c=[],v;v=Uy(o,s),!(v===null||(Ia(c,v),!h));){var d=qe(v[0]);d===""&&(o.lastIndex=By(s,Ly(o.lastIndex),f))}for(var g="",p=0,y=0;y=p&&(g+=Ds(s,p,b)+$,p=b+x.length)}return g+Ds(s,p)}]},!qy||!Wy||Vs);var Qy=Te,Ky=Fe,Zy=G,Jy=Zy("match"),Ku=function(a){var e;return Qy(a)&&((e=a[Jy])!==void 0?!!e:Ky(a)==="RegExp")},em=Ku,tm=TypeError,Ji=function(a){if(em(a))throw new tm("The method doesn't accept regular expressions");return a},rm=G,am=rm("match"),en=function(a){var e=/./;try{"/./"[a](e)}catch{try{return e[am]=!1,"/./"[a](e)}catch{}}return!1},im=ee,Zu=Nt,nm=ut.f,sm=ht,Ls=pe,om=Ji,um=ge,lm=en,ks=Zu("".startsWith),hm=Zu("".slice),vm=Math.min,Ju=lm("startsWith"),fm=!Ju&&!!function(){var a=nm(String.prototype,"startsWith");return a&&!a.writable}();im({target:"String",proto:!0,forced:!fm&&!Ju},{startsWith:function(e){var t=Ls(um(this));om(e);var r=sm(vm(arguments.length>1?arguments[1]:void 0,t.length)),i=Ls(e);return ks?ks(t,i,r):hm(t,r,r+i.length)===i}});var cm=G,gm=Xi,dm=de.f,ci=cm("unscopables"),gi=Array.prototype;gi[ci]===void 0&&dm(gi,ci,{configurable:!0,value:gm(null)});var pm=function(a){gi[ci][a]=!0},ym=L,mm=!ym(function(){function a(){}return a.prototype.constructor=null,Object.getPrototypeOf(new a)!==a.prototype}),bm=le,xm=D,Tm=Er,Sm=Ri,Om=mm,Bs=Sm("IE_PROTO"),di=Object,Em=di.prototype,el=Om?di.getPrototypeOf:function(a){var e=Tm(a);if(bm(e,Bs))return e[Bs];var t=e.constructor;return xm(t)&&e instanceof t?t.prototype:e instanceof di?Em:null},$m=L,wm=D,Cm=Te,Fs=el,Am=ze,Pm=G,pi=Pm("iterator"),tl=!1,ke,Na,Ma;[].keys&&(Ma=[].keys(),"next"in Ma?(Na=Fs(Fs(Ma)),Na!==Object.prototype&&(ke=Na)):tl=!0);var Rm=!Cm(ke)||$m(function(){var a={};return ke[pi].call(a)!==a});Rm&&(ke={});wm(ke[pi])||Am(ke,pi,function(){return this});var rl={IteratorPrototype:ke,BUGGY_SAFARI_ITERATORS:tl},Im=rl.IteratorPrototype,Nm=Xi,Mm=xr,_m=Rr,Dm=_t,Vm=function(){return this},Lm=function(a,e,t,r){var i=e+" Iterator";return a.prototype=Nm(Im,{next:Mm(+!r,t)}),_m(a,i,!1),Dm[i]=Vm,a},km=ee,Bm=Y,al=wr,Fm=D,jm=Lm,js=el,Us=vu,Um=Rr,zm=Pt,_a=ze,Gm=G,Hm=_t,il=rl,Ym=al.PROPER,Xm=al.CONFIGURABLE,zs=il.IteratorPrototype,tr=il.BUGGY_SAFARI_ITERATORS,dt=Gm("iterator"),Gs="keys",pt="values",Hs="entries",Wm=function(){return this},qm=function(a,e,t,r,i,n,o){jm(t,e,r);var s=function(y){if(y===i&&c)return c;if(!tr&&y&&y in h)return h[y];switch(y){case Gs:return function(){return new t(this,y)};case pt:return function(){return new t(this,y)};case Hs:return function(){return new t(this,y)}}return function(){return new t(this)}},u=e+" Iterator",l=!1,h=a.prototype,f=h[dt]||h["@@iterator"]||i&&h[i],c=!tr&&f||s(i),v=e==="Array"&&h.entries||f,d,g,p;if(v&&(d=js(v.call(new a)),d!==Object.prototype&&d.next&&(js(d)!==zs&&(Us?Us(d,zs):Fm(d[dt])||_a(d,dt,Wm)),Um(d,u,!0))),Ym&&i===pt&&f&&f.name!==pt&&(Xm?zm(h,"name",pt):(l=!0,c=function(){return Bm(f,this)})),i)if(g={values:s(pt),keys:n?c:s(Gs),entries:s(Hs)},o)for(p in g)(tr||l||!(p in h))&&_a(h,p,g[p]);else km({target:e,proto:!0,forced:tr||l},g);return h[dt]!==c&&_a(h,dt,c,{name:i}),Hm[e]=c,g},Qm=function(a,e){return{value:a,done:e}},Km=At,tn=pm,Ys=_t,nl=Cr,Zm=de.f,Jm=qm,rr=Qm,e0=ce,sl="Array Iterator",t0=nl.set,r0=nl.getterFor(sl),a0=Jm(Array,"Array",function(a,e){t0(this,{type:sl,target:Km(a),index:0,kind:e})},function(){var a=r0(this),e=a.target,t=a.index++;if(!e||t>=e.length)return a.target=void 0,rr(void 0,!0);switch(a.kind){case"keys":return rr(t,!1);case"values":return rr(e[t],!1)}return rr([t,e[t]],!1)},"values"),Xs=Ys.Arguments=Ys.Array;tn("keys");tn("values");tn("entries");if(e0&&Xs.name!=="values")try{Zm(Xs,"name",{value:"values"})}catch{}var i0={CSSRuleList:0,CSSStyleDeclaration:0,CSSValueList:0,ClientRectList:0,DOMRectList:0,DOMStringList:0,DOMTokenList:1,DataTransferItemList:0,FileList:0,HTMLAllCollection:0,HTMLCollection:0,HTMLFormElement:0,HTMLSelectElement:0,MediaList:0,MimeTypeArray:0,NamedNodeMap:0,NodeList:1,PaintRequestList:0,Plugin:0,PluginArray:0,SVGLengthList:0,SVGNumberList:0,SVGPathSegList:0,SVGPointList:0,SVGStringList:0,SVGTransformList:0,SourceBufferList:0,StyleSheetList:0,TextTrackCueList:0,TextTrackList:0,TouchList:0},n0=$r,Da=n0("span").classList,Ws=Da&&Da.constructor&&Da.constructor.prototype,s0=Ws===Object.prototype?void 0:Ws,qs=U,ol=i0,o0=s0,xt=a0,Qs=Pt,u0=Rr,l0=G,Va=l0("iterator"),La=xt.values,ul=function(a,e){if(a){if(a[Va]!==La)try{Qs(a,Va,La)}catch{a[Va]=La}if(u0(a,e,!0),ol[e]){for(var t in xt)if(a[t]!==xt[t])try{Qs(a,t,xt[t])}catch{a[t]=xt[t]}}}};for(var ka in ol)ul(qs[ka]&&qs[ka].prototype,ka);ul(o0,"DOMTokenList");function h0(a,e){if(Ha(a)!=="object"||a===null)return a;var t=a[Symbol.toPrimitive];if(t!==void 0){var r=t.call(a,e||"default");if(Ha(r)!=="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(e==="string"?String:Number)(a)}function v0(a){var e=h0(a,"string");return Ha(e)==="symbol"?e:String(e)}function rn(a,e,t){return e=v0(e),e in a?Object.defineProperty(a,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):a[e]=t,a}var f0=Se,c0=Er,g0=Uo,d0=Pr,p0=TypeError,Ks=function(a){return function(e,t,r,i){var n=c0(e),o=g0(n),s=d0(n);f0(t);var u=a?s-1:0,l=a?-1:1;if(r<2)for(;;){if(u in o){i=o[u],u+=l;break}if(u+=l,a?u<0:s<=u)throw new p0("Reduce of empty array with no initial value")}for(;a?u>=0:s>u;u+=l)u in o&&(i=t(i,o[u],u,n));return i}},y0={left:Ks(!1),right:Ks(!0)},m0=L,ll=function(a,e){var t=[][a];return!!t&&m0(function(){t.call(null,e||function(){return 1},1)})},b0=ee,x0=y0.left,T0=ll,Zs=Oi,S0=It,O0=!S0&&Zs>79&&Zs<83,E0=O0||!T0("reduce");b0({target:"Array",proto:!0,forced:E0},{reduce:function(e){var t=arguments.length;return x0(this,e,t,t>1?arguments[1]:void 0)}});var $0=ee,hl=Nt,w0=ut.f,C0=ht,Js=pe,A0=Ji,P0=ge,R0=en,eo=hl("".endsWith),I0=hl("".slice),N0=Math.min,vl=R0("endsWith"),M0=!vl&&!!function(){var a=w0(String.prototype,"endsWith");return a&&!a.writable}();$0({target:"String",proto:!0,forced:!M0&&!vl},{endsWith:function(e){var t=Js(P0(this));A0(e);var r=arguments.length>1?arguments[1]:void 0,i=t.length,n=r===void 0?i:N0(C0(r),i),o=Js(e);return eo?eo(t,o,n):I0(t,n-o.length,n)===o}});var _0=Ci,D0=de,V0=xr,L0=function(a,e,t){var r=_0(e);r in a?D0.f(a,r,V0(0,t)):a[r]=t},to=su,k0=Pr,B0=L0,F0=Array,j0=Math.max,U0=function(a,e,t){for(var r=k0(a),i=to(e,r),n=to(t===void 0?r:t,r),o=F0(j0(n-i,0)),s=0;i1||"".split(/.?/).length?r=function(i,n){var o=Ba(ro(this)),s=n===void 0?no:n>>>0;if(s===0)return[];if(i===void 0)return[o];if(!X0(i))return yt(e,o,i,s);for(var u=[],l=(i.ignoreCase?"i":"")+(i.multiline?"m":"")+(i.unicode?"u":"")+(i.sticky?"y":""),h=0,f=new RegExp(i.source,l+"g"),c,v,d;(c=yt(Z0,f,o))&&(v=f.lastIndex,!(v>h&&(Ke(u,mt(o,h,c.index)),c.length>1&&c.index=s)));)f.lastIndex===c.index&&f.lastIndex++;return h===o.length?(d||!rb(f,""))&&Ke(u,""):Ke(u,mt(o,h)),u.length>s?ao(u,0,s):u}:"0".split(void 0,0).length?r=function(i,n){return i===void 0&&n===0?[]:yt(e,this,i,n)}:r=e,[function(n,o){var s=ro(this),u=Y0(n)?void 0:K0(n,a);return u?yt(u,n,s,o):yt(r,Ba(s),n,o)},function(i,n){var o=H0(this),s=Ba(i),u=t(r,o,s,n,r!==e);if(u.done)return u.value;var l=W0(o,RegExp),h=o.unicode,f=(o.ignoreCase?"i":"")+(o.multiline?"m":"")+(o.unicode?"u":"")+(Qe?"g":"y"),c=new l(Qe?"^(?:"+o.source+")":o,f),v=n===void 0?no:n>>>0;if(v===0)return[];if(s.length===0)return io(c,s)===null?[s]:[];for(var d=0,g=0,p=[];g"u"?Je:window,ar=["moz","webkit"],it="AnimationFrame",ot=be["request"+it],Ct=be["cancel"+it]||be["cancelRequest"+it];for(var bt=0;!ot&&bt3&&(this.alpha=s[3]),this.ok=!0}}this.r=this.r<0||isNaN(this.r)?0:this.r>255?255:this.r,this.g=this.g<0||isNaN(this.g)?0:this.g>255?255:this.g,this.b=this.b<0||isNaN(this.b)?0:this.b>255?255:this.b,this.alpha=this.alpha<0?0:this.alpha>1||isNaN(this.alpha)?1:this.alpha,this.toRGB=function(){return"rgb("+this.r+", "+this.g+", "+this.b+")"},this.toRGBA=function(){return"rgba("+this.r+", "+this.g+", "+this.b+", "+this.alpha+")"},this.toHex=function(){var u=this.r.toString(16),l=this.g.toString(16),h=this.b.toString(16);return u.length==1&&(u="0"+u),l.length==1&&(l="0"+l),h.length==1&&(h="0"+h),"#"+u+l+h},this.getHelpXML=function(){for(var u=new Array,l=0;l "+g.toRGB()+" -> "+g.toHex());d.appendChild(p),d.appendChild(y),v.appendChild(d)}catch{}return v}};const mi=Do(xb);var Tb=ee,Sb=Nt,Ob=ou.indexOf,Eb=ll,bi=Sb([].indexOf),gl=!!bi&&1/bi([1],1,-0)<0,$b=gl||!Eb("indexOf");Tb({target:"Array",proto:!0,forced:$b},{indexOf:function(e){var t=arguments.length>1?arguments[1]:void 0;return gl?bi(this,e,t)||0:Ob(this,e,t)}});var wb=ee,Cb=k,Ab=Ji,Pb=ge,ho=pe,Rb=en,Ib=Cb("".indexOf);wb({target:"String",proto:!0,forced:!Rb("includes")},{includes:function(e){return!!~Ib(ho(Pb(this)),ho(Ab(e)),arguments.length>1?arguments[1]:void 0)}});var Nb=Fe,Mb=Array.isArray||function(e){return Nb(e)==="Array"},_b=ee,Db=k,Vb=Mb,Lb=Db([].reverse),vo=[1,2];_b({target:"Array",proto:!0,forced:String(vo)===String(vo.reverse())},{reverse:function(){return Vb(this)&&(this.length=this.length),Lb(this)}});/*! ***************************************************************************** diff --git a/assets/jspdf.es.min-282c0c72.js b/assets/jspdf.es.min-9eaca9d8.js similarity index 99% rename from assets/jspdf.es.min-282c0c72.js rename to assets/jspdf.es.min-9eaca9d8.js index 5bf1be0..91cfc29 100644 --- a/assets/jspdf.es.min-282c0c72.js +++ b/assets/jspdf.es.min-9eaca9d8.js @@ -1,4 +1,4 @@ -import{_ as ls}from"./main-262930e7.js";function fe(i){"@babel/helpers - typeof";return fe=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(e){return typeof e}:function(e){return e&&typeof Symbol=="function"&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},fe(i)}var Qe=Uint8Array,tn=Uint16Array,ha=Uint32Array,so=new Qe([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),co=new Qe([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),hs=new Qe([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),xc=function(i,e){for(var n=new tn(31),a=0;a<31;++a)n[a]=e+=1<>>1|(ye&21845)<<1;Pr=(Pr&52428)>>>2|(Pr&13107)<<2,Pr=(Pr&61680)>>>4|(Pr&3855)<<4,ds[ye]=((Pr&65280)>>>8|(Pr&255)<<8)>>>1}var Kn=function(i,e,n){for(var a=i.length,c=0,o=new tn(e);c>>f]=g}else for(h=new tn(a),c=0;c>>15-i[c];return h},jr=new Qe(288);for(var ye=0;ye<144;++ye)jr[ye]=8;for(var ye=144;ye<256;++ye)jr[ye]=9;for(var ye=256;ye<280;++ye)jr[ye]=7;for(var ye=280;ye<288;++ye)jr[ye]=8;var fa=new Qe(32);for(var ye=0;ye<32;++ye)fa[ye]=5;var Su=Kn(jr,9,0),_u=Kn(jr,9,1),Pu=Kn(fa,5,0),ku=Kn(fa,5,1),es=function(i){for(var e=i[0],n=1;ne&&(e=i[n]);return e},Mn=function(i,e,n){var a=e/8>>0;return(i[a]|i[a+1]<<8)>>>(e&7)&n},ns=function(i,e){var n=e/8>>0;return(i[n]|i[n+1]<<8|i[n+2]<<16)>>>(e&7)},Ns=function(i){return(i/8>>0)+(i&7&&1)},kc=function(i,e,n){(e==null||e<0)&&(e=0),(n==null||n>i.length)&&(n=i.length);var a=new(i instanceof tn?tn:i instanceof ha?ha:Qe)(n-e);return a.set(i.subarray(e,n)),a},Fu=function(i,e,n){var a=i.length,c=!e||n,o=!n||n.i;n||(n={}),e||(e=new Qe(a*3));var l=function(Y){var Q=e.length;if(Y>Q){var et=new Qe(Math.max(Q*2,Y));et.set(e),e=et}},h=n.f||0,f=n.p||0,g=n.b||0,b=n.l,A=n.d,S=n.m,p=n.n,O=a*8;do{if(!b){n.f=h=Mn(i,f,1);var I=Mn(i,f+1,3);if(f+=3,I)if(I==1)b=_u,A=ku,S=9,p=5;else if(I==2){var X=Mn(i,f,31)+257,ot=Mn(i,f+10,15)+4,ut=X+Mn(i,f+5,31)+1;f+=14;for(var wt=new Qe(ut),tt=new Qe(19),R=0;RO)break;for(var F=Kn(tt,gt,1),R=0;R>>4;if(q<16)wt[R++]=q;else{var z=0,D=0;for(q==16?(D=3+Mn(i,f,3),f+=2,z=wt[R-1]):q==17?(D=3+Mn(i,f,7),f+=3):q==18&&(D=11+Mn(i,f,127),f+=7);D--;)wt[R++]=z}}var at=wt.subarray(0,X),nt=wt.subarray(X);S=es(at),p=es(nt),b=Kn(at,S,1),A=Kn(nt,p,1)}else throw"invalid block type";else{var q=Ns(f)+4,_=i[q-4]|i[q-3]<<8,B=q+_;if(B>a){if(o)throw"unexpected EOF";break}c&&l(g+_),e.set(i.subarray(q,B),g),n.b=g+=_,n.p=f=B*8;continue}if(f>O)throw"unexpected EOF"}c&&l(g+131072);for(var lt=(1<>>4;if(f+=z&15,f>O)throw"unexpected EOF";if(!z)throw"invalid length/literal";if(ht<256)e[g++]=ht;else if(ht==256){b=null;break}else{var kt=ht-254;if(ht>264){var R=ht-257,L=so[R];kt=Mn(i,f,(1<>>4;if(!j)throw"invalid distance";f+=j&15;var nt=xu[M];if(M>3){var L=co[M];nt+=ns(i,f)&(1<O)throw"unexpected EOF";c&&l(g+131072);for(var W=g+kt;g>0;i[a]|=n,i[a+1]|=n>>>8},ia=function(i,e,n){n<<=e&7;var a=e/8>>0;i[a]|=n,i[a+1]|=n>>>8,i[a+2]|=n>>>16},rs=function(i,e){for(var n=[],a=0;aS&&(S=o[a].s);var p=new tn(S+1),O=ps(n[b-1],p,0);if(O>e){var a=0,I=0,q=O-e,_=1<e)I+=_-(1<>>=q;I>0;){var X=o[a].s;p[X]=0&&I;--a){var ot=o[a].s;p[ot]==e&&(--p[ot],++I)}O=e}return[new Qe(p),O]},ps=function(i,e,n){return i.s==-1?Math.max(ps(i.l,e,n+1),ps(i.r,e,n+1)):e[i.s]=n},ac=function(i){for(var e=i.length;e&&!i[--e];);for(var n=new tn(++e),a=0,c=i[0],o=1,l=function(f){n[a++]=f},h=1;h<=e;++h)if(i[h]==c&&h!=e)++o;else{if(!c&&o>2){for(;o>138;o-=138)l(32754);o>2&&(l(o>10?o-11<<5|28690:o-3<<5|12305),o=0)}else if(o>3){for(l(c),--o;o>6;o-=6)l(8304);o>2&&(l(o-3<<5|8208),o=0)}for(;o--;)l(c);o=1,c=i[h]}return[n.subarray(0,a),e]},aa=function(i,e){for(var n=0,a=0;a>>8,i[c+2]=i[c]^255,i[c+3]=i[c+1]^255;for(var o=0;o4&&!dt[hs[P-1]];--P);var z=g+5<<3,D=aa(c,jr)+aa(o,fa)+l,at=aa(c,S)+aa(o,I)+l+14+3*P+aa(tt,dt)+(2*tt[16]+3*tt[17]+7*tt[18]);if(z<=D&&z<=at)return ao(e,b,i.subarray(f,f+g));var nt,lt,$,ft;if(lr(e,b,1+(at15&&(lr(e,b,j[R]>>>5&127),b+=j[R]>>>12)}}else nt=Su,lt=jr,$=Pu,ft=fa;for(var R=0;R255){var M=a[R]>>>18&31;ia(e,b,nt[M+257]),b+=lt[M+257],M>7&&(lr(e,b,a[R]>>>23&31),b+=so[M]);var W=a[R]&31;ia(e,b,$[W]),b+=ft[W],W>3&&(ia(e,b,a[R]>>>5&8191),b+=co[W])}else ia(e,b,nt[a[R]]),b+=lt[a[R]];return ia(e,b,nt[256]),b+lt[256]},Iu=new ha([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]),Cu=new Qe(0),ju=function(i,e,n,a,c,o){var l=i.length,h=new Qe(a+l+5*(1+Math.floor(l/7e3))+c),f=h.subarray(a,h.length-c),g=0;if(!e||l<8)for(var b=0;b<=l;b+=65535){var A=b+65535;A>>13,O=S&8191,I=(1<7e3||dt>24576)&&nt>423){g=oc(i,f,0,ut,wt,tt,gt,dt,P,b-P,g),dt=R=gt=0,P=b;for(var lt=0;lt<286;++lt)wt[lt]=0;for(var lt=0;lt<30;++lt)tt[lt]=0}var $=2,ft=0,ht=O,kt=D-at&32767;if(nt>2&&z==ot(b-kt))for(var L=Math.min(p,nt)-1,j=Math.min(32767,b),M=Math.min(258,nt);kt<=j&&--ht&&D!=at;){if(i[b+$]==i[b+$-kt]){for(var W=0;W$){if($=W,ft=kt,W>L)break;for(var Y=Math.min(kt,W-2),Q=0,lt=0;ltQ&&(Q=At,at=et)}}}D=at,at=q[D],kt+=D-at+32768&32767}if(ft){ut[dt++]=268435456|fs[$]<<18|ic[ft];var Nt=fs[$]&31,Ct=ic[ft]&31;gt+=so[Nt]+co[Ct],++wt[257+Nt],++tt[Ct],F=b+$,++R}else ut[dt++]=i[b],++wt[i[b]]}}g=oc(i,f,o,ut,wt,tt,gt,dt,P,b-P,g),o||(g=ao(f,g,Cu))}return kc(h,0,a+Ns(g)+c)},Ou=function(){var i=1,e=0;return{p:function(n){for(var a=i,c=e,o=n.length,l=0;l!=o;){for(var h=Math.min(l+5552,o);l>>8<<16|(e&255)<<8|e>>>8)+((i&255)<<23)*2}}},Bu=function(i,e,n,a,c){return ju(i,e.level==null?6:e.level,e.mem==null?Math.ceil(Math.max(8,Math.min(13,Math.log(i.length)))*1.5):12+e.mem,n,a,!c)},Mu=function(i,e,n){for(;n;++e)i[e]=n,n>>>=8},Eu=function(i,e){var n=e.level,a=n==0?0:n<6?1:n==9?3:2;i[0]=120,i[1]=a<<6|(a?32-2*a:1)},qu=function(i){if((i[0]&15)!=8||i[0]>>>4>7||(i[0]<<8|i[1])%31)throw"invalid zlib data";if(i[1]&32)throw"invalid zlib data: preset dictionaries not supported"};function gs(i,e){e===void 0&&(e={});var n=Ou();n.p(i);var a=Bu(i,e,2,4);return Eu(a,e),Mu(a,a.length-4,n.d()),a}function Du(i,e){return Fu((qu(i),i.subarray(2,-4)),e)}var Ht=function(){return typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:this}();function is(){Ht.console&&typeof Ht.console.log=="function"&&Ht.console.log.apply(Ht.console,arguments)}var ve={log:is,warn:function(i){Ht.console&&(typeof Ht.console.warn=="function"?Ht.console.warn.apply(Ht.console,arguments):is.call(null,arguments))},error:function(i){Ht.console&&(typeof Ht.console.error=="function"?Ht.console.error.apply(Ht.console,arguments):is(i))}};function as(i,e,n){var a=new XMLHttpRequest;a.open("GET",i),a.responseType="blob",a.onload=function(){Wr(a.response,e,n)},a.onerror=function(){ve.error("could not download file")},a.send()}function sc(i){var e=new XMLHttpRequest;e.open("HEAD",i,!1);try{e.send()}catch{}return e.status>=200&&e.status<=299}function eo(i){try{i.dispatchEvent(new MouseEvent("click"))}catch{var e=document.createEvent("MouseEvents");e.initMouseEvent("click",!0,!0,window,0,0,0,80,20,!1,!1,!1,!1,0,null),i.dispatchEvent(e)}}var oa,ms,Wr=Ht.saveAs||((typeof window>"u"?"undefined":fe(window))!=="object"||window!==Ht?function(){}:typeof HTMLAnchorElement<"u"&&"download"in HTMLAnchorElement.prototype?function(i,e,n){var a=Ht.URL||Ht.webkitURL,c=document.createElement("a");e=e||i.name||"download",c.download=e,c.rel="noopener",typeof i=="string"?(c.href=i,c.origin!==location.origin?sc(c.href)?as(i,e,n):eo(c,c.target="_blank"):eo(c)):(c.href=a.createObjectURL(i),setTimeout(function(){a.revokeObjectURL(c.href)},4e4),setTimeout(function(){eo(c)},0))}:"msSaveOrOpenBlob"in navigator?function(i,e,n){if(e=e||i.name||"download",typeof i=="string")if(sc(i))as(i,e,n);else{var a=document.createElement("a");a.href=i,a.target="_blank",setTimeout(function(){eo(a)})}else navigator.msSaveOrOpenBlob(function(c,o){return o===void 0?o={autoBom:!1}:fe(o)!=="object"&&(ve.warn("Deprecated: Expected third argument to be a object"),o={autoBom:!o}),o.autoBom&&/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(c.type)?new Blob([String.fromCharCode(65279),c],{type:c.type}):c}(i,n),e)}:function(i,e,n,a){if((a=a||open("","_blank"))&&(a.document.title=a.document.body.innerText="downloading..."),typeof i=="string")return as(i,e,n);var c=i.type==="application/octet-stream",o=/constructor/i.test(Ht.HTMLElement)||Ht.safari,l=/CriOS\/[\d]+/.test(navigator.userAgent);if((l||c&&o)&&(typeof FileReader>"u"?"undefined":fe(FileReader))==="object"){var h=new FileReader;h.onloadend=function(){var b=h.result;b=l?b:b.replace(/^data:[^;]*;/,"data:attachment/file;"),a?a.location.href=b:location=b,a=null},h.readAsDataURL(i)}else{var f=Ht.URL||Ht.webkitURL,g=f.createObjectURL(i);a?a.location=g:location.href=g,a=null,setTimeout(function(){f.revokeObjectURL(g)},4e4)}});/** +import{_ as ls}from"./main-ab68e62d.js";function fe(i){"@babel/helpers - typeof";return fe=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(e){return typeof e}:function(e){return e&&typeof Symbol=="function"&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},fe(i)}var Qe=Uint8Array,tn=Uint16Array,ha=Uint32Array,so=new Qe([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),co=new Qe([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),hs=new Qe([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),xc=function(i,e){for(var n=new tn(31),a=0;a<31;++a)n[a]=e+=1<>>1|(ye&21845)<<1;Pr=(Pr&52428)>>>2|(Pr&13107)<<2,Pr=(Pr&61680)>>>4|(Pr&3855)<<4,ds[ye]=((Pr&65280)>>>8|(Pr&255)<<8)>>>1}var Kn=function(i,e,n){for(var a=i.length,c=0,o=new tn(e);c>>f]=g}else for(h=new tn(a),c=0;c>>15-i[c];return h},jr=new Qe(288);for(var ye=0;ye<144;++ye)jr[ye]=8;for(var ye=144;ye<256;++ye)jr[ye]=9;for(var ye=256;ye<280;++ye)jr[ye]=7;for(var ye=280;ye<288;++ye)jr[ye]=8;var fa=new Qe(32);for(var ye=0;ye<32;++ye)fa[ye]=5;var Su=Kn(jr,9,0),_u=Kn(jr,9,1),Pu=Kn(fa,5,0),ku=Kn(fa,5,1),es=function(i){for(var e=i[0],n=1;ne&&(e=i[n]);return e},Mn=function(i,e,n){var a=e/8>>0;return(i[a]|i[a+1]<<8)>>>(e&7)&n},ns=function(i,e){var n=e/8>>0;return(i[n]|i[n+1]<<8|i[n+2]<<16)>>>(e&7)},Ns=function(i){return(i/8>>0)+(i&7&&1)},kc=function(i,e,n){(e==null||e<0)&&(e=0),(n==null||n>i.length)&&(n=i.length);var a=new(i instanceof tn?tn:i instanceof ha?ha:Qe)(n-e);return a.set(i.subarray(e,n)),a},Fu=function(i,e,n){var a=i.length,c=!e||n,o=!n||n.i;n||(n={}),e||(e=new Qe(a*3));var l=function(Y){var Q=e.length;if(Y>Q){var et=new Qe(Math.max(Q*2,Y));et.set(e),e=et}},h=n.f||0,f=n.p||0,g=n.b||0,b=n.l,A=n.d,S=n.m,p=n.n,O=a*8;do{if(!b){n.f=h=Mn(i,f,1);var I=Mn(i,f+1,3);if(f+=3,I)if(I==1)b=_u,A=ku,S=9,p=5;else if(I==2){var X=Mn(i,f,31)+257,ot=Mn(i,f+10,15)+4,ut=X+Mn(i,f+5,31)+1;f+=14;for(var wt=new Qe(ut),tt=new Qe(19),R=0;RO)break;for(var F=Kn(tt,gt,1),R=0;R>>4;if(q<16)wt[R++]=q;else{var z=0,D=0;for(q==16?(D=3+Mn(i,f,3),f+=2,z=wt[R-1]):q==17?(D=3+Mn(i,f,7),f+=3):q==18&&(D=11+Mn(i,f,127),f+=7);D--;)wt[R++]=z}}var at=wt.subarray(0,X),nt=wt.subarray(X);S=es(at),p=es(nt),b=Kn(at,S,1),A=Kn(nt,p,1)}else throw"invalid block type";else{var q=Ns(f)+4,_=i[q-4]|i[q-3]<<8,B=q+_;if(B>a){if(o)throw"unexpected EOF";break}c&&l(g+_),e.set(i.subarray(q,B),g),n.b=g+=_,n.p=f=B*8;continue}if(f>O)throw"unexpected EOF"}c&&l(g+131072);for(var lt=(1<>>4;if(f+=z&15,f>O)throw"unexpected EOF";if(!z)throw"invalid length/literal";if(ht<256)e[g++]=ht;else if(ht==256){b=null;break}else{var kt=ht-254;if(ht>264){var R=ht-257,L=so[R];kt=Mn(i,f,(1<>>4;if(!j)throw"invalid distance";f+=j&15;var nt=xu[M];if(M>3){var L=co[M];nt+=ns(i,f)&(1<O)throw"unexpected EOF";c&&l(g+131072);for(var W=g+kt;g>0;i[a]|=n,i[a+1]|=n>>>8},ia=function(i,e,n){n<<=e&7;var a=e/8>>0;i[a]|=n,i[a+1]|=n>>>8,i[a+2]|=n>>>16},rs=function(i,e){for(var n=[],a=0;aS&&(S=o[a].s);var p=new tn(S+1),O=ps(n[b-1],p,0);if(O>e){var a=0,I=0,q=O-e,_=1<e)I+=_-(1<>>=q;I>0;){var X=o[a].s;p[X]=0&&I;--a){var ot=o[a].s;p[ot]==e&&(--p[ot],++I)}O=e}return[new Qe(p),O]},ps=function(i,e,n){return i.s==-1?Math.max(ps(i.l,e,n+1),ps(i.r,e,n+1)):e[i.s]=n},ac=function(i){for(var e=i.length;e&&!i[--e];);for(var n=new tn(++e),a=0,c=i[0],o=1,l=function(f){n[a++]=f},h=1;h<=e;++h)if(i[h]==c&&h!=e)++o;else{if(!c&&o>2){for(;o>138;o-=138)l(32754);o>2&&(l(o>10?o-11<<5|28690:o-3<<5|12305),o=0)}else if(o>3){for(l(c),--o;o>6;o-=6)l(8304);o>2&&(l(o-3<<5|8208),o=0)}for(;o--;)l(c);o=1,c=i[h]}return[n.subarray(0,a),e]},aa=function(i,e){for(var n=0,a=0;a>>8,i[c+2]=i[c]^255,i[c+3]=i[c+1]^255;for(var o=0;o4&&!dt[hs[P-1]];--P);var z=g+5<<3,D=aa(c,jr)+aa(o,fa)+l,at=aa(c,S)+aa(o,I)+l+14+3*P+aa(tt,dt)+(2*tt[16]+3*tt[17]+7*tt[18]);if(z<=D&&z<=at)return ao(e,b,i.subarray(f,f+g));var nt,lt,$,ft;if(lr(e,b,1+(at15&&(lr(e,b,j[R]>>>5&127),b+=j[R]>>>12)}}else nt=Su,lt=jr,$=Pu,ft=fa;for(var R=0;R255){var M=a[R]>>>18&31;ia(e,b,nt[M+257]),b+=lt[M+257],M>7&&(lr(e,b,a[R]>>>23&31),b+=so[M]);var W=a[R]&31;ia(e,b,$[W]),b+=ft[W],W>3&&(ia(e,b,a[R]>>>5&8191),b+=co[W])}else ia(e,b,nt[a[R]]),b+=lt[a[R]];return ia(e,b,nt[256]),b+lt[256]},Iu=new ha([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]),Cu=new Qe(0),ju=function(i,e,n,a,c,o){var l=i.length,h=new Qe(a+l+5*(1+Math.floor(l/7e3))+c),f=h.subarray(a,h.length-c),g=0;if(!e||l<8)for(var b=0;b<=l;b+=65535){var A=b+65535;A>>13,O=S&8191,I=(1<7e3||dt>24576)&&nt>423){g=oc(i,f,0,ut,wt,tt,gt,dt,P,b-P,g),dt=R=gt=0,P=b;for(var lt=0;lt<286;++lt)wt[lt]=0;for(var lt=0;lt<30;++lt)tt[lt]=0}var $=2,ft=0,ht=O,kt=D-at&32767;if(nt>2&&z==ot(b-kt))for(var L=Math.min(p,nt)-1,j=Math.min(32767,b),M=Math.min(258,nt);kt<=j&&--ht&&D!=at;){if(i[b+$]==i[b+$-kt]){for(var W=0;W$){if($=W,ft=kt,W>L)break;for(var Y=Math.min(kt,W-2),Q=0,lt=0;ltQ&&(Q=At,at=et)}}}D=at,at=q[D],kt+=D-at+32768&32767}if(ft){ut[dt++]=268435456|fs[$]<<18|ic[ft];var Nt=fs[$]&31,Ct=ic[ft]&31;gt+=so[Nt]+co[Ct],++wt[257+Nt],++tt[Ct],F=b+$,++R}else ut[dt++]=i[b],++wt[i[b]]}}g=oc(i,f,o,ut,wt,tt,gt,dt,P,b-P,g),o||(g=ao(f,g,Cu))}return kc(h,0,a+Ns(g)+c)},Ou=function(){var i=1,e=0;return{p:function(n){for(var a=i,c=e,o=n.length,l=0;l!=o;){for(var h=Math.min(l+5552,o);l>>8<<16|(e&255)<<8|e>>>8)+((i&255)<<23)*2}}},Bu=function(i,e,n,a,c){return ju(i,e.level==null?6:e.level,e.mem==null?Math.ceil(Math.max(8,Math.min(13,Math.log(i.length)))*1.5):12+e.mem,n,a,!c)},Mu=function(i,e,n){for(;n;++e)i[e]=n,n>>>=8},Eu=function(i,e){var n=e.level,a=n==0?0:n<6?1:n==9?3:2;i[0]=120,i[1]=a<<6|(a?32-2*a:1)},qu=function(i){if((i[0]&15)!=8||i[0]>>>4>7||(i[0]<<8|i[1])%31)throw"invalid zlib data";if(i[1]&32)throw"invalid zlib data: preset dictionaries not supported"};function gs(i,e){e===void 0&&(e={});var n=Ou();n.p(i);var a=Bu(i,e,2,4);return Eu(a,e),Mu(a,a.length-4,n.d()),a}function Du(i,e){return Fu((qu(i),i.subarray(2,-4)),e)}var Ht=function(){return typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:this}();function is(){Ht.console&&typeof Ht.console.log=="function"&&Ht.console.log.apply(Ht.console,arguments)}var ve={log:is,warn:function(i){Ht.console&&(typeof Ht.console.warn=="function"?Ht.console.warn.apply(Ht.console,arguments):is.call(null,arguments))},error:function(i){Ht.console&&(typeof Ht.console.error=="function"?Ht.console.error.apply(Ht.console,arguments):is(i))}};function as(i,e,n){var a=new XMLHttpRequest;a.open("GET",i),a.responseType="blob",a.onload=function(){Wr(a.response,e,n)},a.onerror=function(){ve.error("could not download file")},a.send()}function sc(i){var e=new XMLHttpRequest;e.open("HEAD",i,!1);try{e.send()}catch{}return e.status>=200&&e.status<=299}function eo(i){try{i.dispatchEvent(new MouseEvent("click"))}catch{var e=document.createEvent("MouseEvents");e.initMouseEvent("click",!0,!0,window,0,0,0,80,20,!1,!1,!1,!1,0,null),i.dispatchEvent(e)}}var oa,ms,Wr=Ht.saveAs||((typeof window>"u"?"undefined":fe(window))!=="object"||window!==Ht?function(){}:typeof HTMLAnchorElement<"u"&&"download"in HTMLAnchorElement.prototype?function(i,e,n){var a=Ht.URL||Ht.webkitURL,c=document.createElement("a");e=e||i.name||"download",c.download=e,c.rel="noopener",typeof i=="string"?(c.href=i,c.origin!==location.origin?sc(c.href)?as(i,e,n):eo(c,c.target="_blank"):eo(c)):(c.href=a.createObjectURL(i),setTimeout(function(){a.revokeObjectURL(c.href)},4e4),setTimeout(function(){eo(c)},0))}:"msSaveOrOpenBlob"in navigator?function(i,e,n){if(e=e||i.name||"download",typeof i=="string")if(sc(i))as(i,e,n);else{var a=document.createElement("a");a.href=i,a.target="_blank",setTimeout(function(){eo(a)})}else navigator.msSaveOrOpenBlob(function(c,o){return o===void 0?o={autoBom:!1}:fe(o)!=="object"&&(ve.warn("Deprecated: Expected third argument to be a object"),o={autoBom:!o}),o.autoBom&&/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(c.type)?new Blob([String.fromCharCode(65279),c],{type:c.type}):c}(i,n),e)}:function(i,e,n,a){if((a=a||open("","_blank"))&&(a.document.title=a.document.body.innerText="downloading..."),typeof i=="string")return as(i,e,n);var c=i.type==="application/octet-stream",o=/constructor/i.test(Ht.HTMLElement)||Ht.safari,l=/CriOS\/[\d]+/.test(navigator.userAgent);if((l||c&&o)&&(typeof FileReader>"u"?"undefined":fe(FileReader))==="object"){var h=new FileReader;h.onloadend=function(){var b=h.result;b=l?b:b.replace(/^data:[^;]*;/,"data:attachment/file;"),a?a.location.href=b:location=b,a=null},h.readAsDataURL(i)}else{var f=Ht.URL||Ht.webkitURL,g=f.createObjectURL(i);a?a.location=g:location.href=g,a=null,setTimeout(function(){f.revokeObjectURL(g)},4e4)}});/** * A class to parse color values * @author Stoyan Stefanov * {@link http://www.phpied.com/rgb-color-parser-in-javascript/} @@ -163,7 +163,7 @@ endobj\r * http://opensource.org/licenses/mit-license */function En(i,e){if(this.pos=0,this.buffer=i,this.datav=new DataView(i.buffer),this.is_with_alpha=!!e,this.bottom_up=!0,this.flag=String.fromCharCode(this.buffer[0])+String.fromCharCode(this.buffer[1]),this.pos+=2,["BM","BA","CI","CP","IC","PT"].indexOf(this.flag)===-1)throw new Error("Invalid BMP File");this.parseHeader(),this.parseBGR()}function Nc(i){function e(R){if(!R)throw Error("assert :P")}function n(R,gt,dt){for(var F=0;4>F;F++)if(R[gt+F]!=dt.charCodeAt(F))return!0;return!1}function a(R,gt,dt,F,P){for(var z=0;zz+1?[]:new gt),!(D.length>>0;t&u;)u>>>=1;return u?(t&u-1)+u:t}function dt(t,r,u,d,m){e(!(d%u));do t[r+(d-=u)]=m;while(0=m),512>=m)var w=o(512);else if((w=o(m))==null)return 0;return function(y,N,x,k,U,K){var Z,G,vt=N,it=1<Z;++Z){if(H[Z]>1<(Rt-=H[Z]))return 0;for(;0=Z;++Z,U<<=1){if(St+=Rt<<=1,0>(Rt-=H[Z]))return 0;for(;0bt&&!(0>=(pt-=H[bt]));)++bt,pt<<=1;it+=_t=1<<(pt=bt-x),y[N+(bt=Ot&mt)].g=pt+x,y[N+bt].value=vt-N-bt}k.g=Z-x,k.value=K[G++],dt(y,vt+(Ot>>x),U,_t,k),Ot=gt(Ot,Z)}}return St!=2*V[15]-1?0:it}(t,r,u,d,m,w)}function P(){this.value=this.g=0}function z(){this.value=this.g=0}function D(){this.G=l(5,P),this.H=o(5),this.jc=this.Qb=this.qb=this.nd=0,this.pd=l(rn,z)}function at(t,r,u,d){e(t!=null),e(r!=null),e(2147483648>d),t.Ca=254,t.I=0,t.b=-8,t.Ka=0,t.oa=r,t.pa=u,t.Jd=r,t.Yc=u+d,t.Zc=4<=d?u+d-4+1:u,Q(t)}function nt(t,r){for(var u=0;0d),t.Sb=d,t.Ra=0,t.u=0,t.h=0,4>>=8,t.Ra+=t.oa[t.pa+t.bb]<>>0,++t.bb,t.u-=8;M(t)&&(t.h=1,t.u=0)}function ht(t,r){if(e(0<=r),!t.h&&r<=gi){var u=j(t)&pi[r];return t.u+=r,ft(t),u}return t.h=1,t.u=0}function kt(){this.b=this.Ca=this.I=0,this.oa=[],this.pa=0,this.Jd=[],this.Yc=0,this.Zc=[],this.Ka=0}function L(){this.Ra=0,this.oa=[],this.h=this.u=this.bb=this.Sb=this.pa=0}function j(t){return t.Ra>>>(t.u&mi-1)>>>0}function M(t){return e(t.bb<=t.Sb),t.h||t.bb==t.Sb&&t.u>mi}function W(t,r){t.u=r,t.h=M(t)}function Y(t){t.u>=Yi&&(e(t.u>=Yi),ft(t))}function Q(t){e(t!=null&&t.oa!=null),t.pa>>0,t.b+=8):(e(t!=null&&t.oa!=null),t.pat.b&&Q(t);var d=t.b,m=u*r>>>8,w=(t.I>>>d>m)+0;for(w?(u-=m,t.I-=m+1<>>0):u=m+1,d=u,m=0;256<=d;)m+=8,d>>=8;return d=7^m+an[d],t.b-=d,t.Ca=(u<>24&255,t[r+1]=u>>16&255,t[r+2]=u>>8&255,t[r+3]=u>>0&255}function Nt(t,r){return t[r+0]<<0|t[r+1]<<8}function Ct(t,r){return Nt(t,r)|t[r+2]<<16}function Bt(t,r){return Nt(t,r)|Nt(t,r+2)<<16}function Ut(t,r){var u=1<=m||0>=w?0:(u[0]=m,d[0]=w,1)}function Et(t,r){return t+(1<>>r}function Lt(t,r){return((4278255360&t)+(4278255360&r)>>>0&4278255360)+((16711935&t)+(16711935&r)>>>0&16711935)>>>0}function xt(t,r){R[r]=function(u,d,m,w,y,N,x){var k;for(k=0;k>>1)+(t&r)>>>0}function qt(t){return 0<=t&&256>t?t:0>t?0:255>1))}function $t(t,r,u){return Math.abs(r-u)-Math.abs(t-u)}function te(t,r,u,d,m,w,y){for(d=w[y-1],u=0;u>8&255,x=16711935&(x=(x=16711935&y)+((N<<16)+N));d[m+w]=(4278255360&y)+x>>>0}}function de(t,r){r.jd=t>>0&255,r.hd=t>>8&255,r.ud=t>>16&255}function Wt(t,r,u,d,m,w){var y;for(y=0;y>>8,k=N,U=255&(U=(U=N>>>16)+((t.jd<<24>>24)*(x<<24>>24)>>>5));k=255&(k=(k=k+((t.hd<<24>>24)*(x<<24>>24)>>>5))+((t.ud<<24>>24)*(U<<24>>24)>>>5)),m[w+y]=(4278255360&N)+(U<<16)+k}}function ee(t,r,u,d,m){R[r]=function(w,y,N,x,k,U,K,Z,G){for(x=K;x>w.b,G=w.Ea,vt=w.K[0],it=w.w;if(8>Z)for(w=(1<>=Z}else R["VP8LMapColor"+u](x,k,vt,it,U,K,y,N,G)}}function It(t,r,u,d,m){for(u=r+u;r>16&255,d[m++]=w>>8&255,d[m++]=w>>0&255}}function Ve(t,r,u,d,m){for(u=r+u;r>16&255,d[m++]=w>>8&255,d[m++]=w>>0&255,d[m++]=w>>24&255}}function oe(t,r,u,d,m){for(u=r+u;r>16&240|y>>12&15,y=y>>0&240|y>>28&15;d[m++]=w,d[m++]=y}}function yn(t,r,u,d,m){for(u=r+u;r>16&248|y>>13&7,y=y>>5&224|y>>3&31;d[m++]=w,d[m++]=y}}function ge(t,r,u,d,m){for(u=r+u;r>0&255,d[m++]=w>>8&255,d[m++]=w>>16&255}}function Le(t,r,u,d,m,w){if(w==0)for(u=r+u;r>24|w[1]>>8&65280|w[2]<<8&16711680|w[3]<<24)>>>0),m+=32;else a(d,m,t,r,u)}function Rn(t,r){R[r][0]=R[t+"0"],R[r][1]=R[t+"1"],R[r][2]=R[t+"2"],R[r][3]=R[t+"3"],R[r][4]=R[t+"4"],R[r][5]=R[t+"5"],R[r][6]=R[t+"6"],R[r][7]=R[t+"7"],R[r][8]=R[t+"8"],R[r][9]=R[t+"9"],R[r][10]=R[t+"10"],R[r][11]=R[t+"11"],R[r][12]=R[t+"12"],R[r][13]=R[t+"13"],R[r][14]=R[t+"0"],R[r][15]=R[t+"0"]}function ce(t){return t==To||t==zo||t==za||t==Uo}function Br(){this.eb=[],this.size=this.A=this.fb=0}function Ae(){this.y=[],this.f=[],this.ea=[],this.F=[],this.Tc=this.Ed=this.Cd=this.Fd=this.lb=this.Db=this.Ab=this.fa=this.J=this.W=this.N=this.O=0}function Ln(){this.Rd=this.height=this.width=this.S=0,this.f={},this.f.RGBA=new Br,this.f.kb=new Ae,this.sd=null}function $n(){this.width=[0],this.height=[0],this.Pd=[0],this.Qd=[0],this.format=[0]}function xe(){this.Id=this.fd=this.Md=this.hb=this.ib=this.da=this.bd=this.cd=this.j=this.v=this.Da=this.Sd=this.ob=0}function Yt(t){return alert("todo:WebPSamplerProcessPlane"),t.T}function ue(t,r){var u=t.T,d=r.ba.f.RGBA,m=d.eb,w=d.fb+t.ka*d.A,y=bn[r.ba.S],N=t.y,x=t.O,k=t.f,U=t.N,K=t.ea,Z=t.W,G=r.cc,vt=r.dc,it=r.Mc,H=r.Nc,V=t.ka,pt=t.ka+t.T,bt=t.U,mt=bt+1>>1;for(V==0?y(N,x,null,null,k,U,K,Z,k,U,K,Z,m,w,null,null,bt):(y(r.ec,r.fc,N,x,G,vt,it,H,k,U,K,Z,m,w-d.A,m,w,bt),++u);V+2u,m=u==Da||u==Ra||u==Ta||u==Ro||u==12||ce(u);if(r.memory=null,r.Ib=null,r.Jb=null,r.Nd=null,!Vi(r.Oa,t,m?11:12))return 0;if(m&&ce(u)&&yt(),t.da)alert("todo:use_scaling");else{if(d){if(r.Ib=Yt,t.Kb){if(u=t.U+1>>1,r.memory=o(t.U+2*u),r.memory==null)return 0;r.ec=r.memory,r.fc=0,r.cc=r.ec,r.dc=r.fc+t.U,r.Mc=r.cc,r.Nc=r.dc+u,r.Ib=ue,yt()}}else alert("todo:EmitYUV");m&&(r.Jb=Mr,d&&J())}if(d&&!Ts){for(t=0;256>t;++t)au[t]=89858*(t-128)+Ha>>Ua,cu[t]=-22014*(t-128)+Ha,su[t]=-45773*(t-128),ou[t]=113618*(t-128)+Ha>>Ua;for(t=Qi;t>Ua,uu[t-Qi]=ln(r,255),lu[t-Qi]=ln(r+8>>4,15);Ts=1}return 1}function Tn(t){var r=t.ma,u=t.U,d=t.T;return e(!(1&t.ka)),0>=u||0>=d?0:(u=r.Ib(t,r),r.Jb!=null&&r.Jb(t,r,u),r.Dc+=u,1)}function zn(t){t.ma.memory=null}function zt(t,r,u,d){return ht(t,8)!=47?0:(r[0]=ht(t,14)+1,u[0]=ht(t,14)+1,d[0]=ht(t,1),ht(t,3)!=0?0:!t.h)}function Nn(t,r){if(4>t)return t+1;var u=t-2>>1;return(2+(1&t)<>4)*t+(8-(15&u)))?u:1;var u}function en(t,r,u){var d=j(u),m=t[r+=255&d].g-8;return 0>>0,e(8>=u.g),t.g}function Oe(t,r,u){var d=t.xc;return e((r=d==0?0:t.vc[t.md*(u>>d)+(r>>d)])>_t.b)*St;itbt&&(ne=bt),(0,gr[se[le++]>>8&15])(Z,G+ +ae,V,pt+ae-bt,ne-ae,V,pt+ae),ae=ne}G+=bt,pt+=bt,++it&Ot||(_t+=St)}K!=k.nc&&a(x,N-vt,x,N+(K-U-1)*vt,vt);break;case 1:for(vt=Z,H=G,bt=(Z=k.Ea)-(pt=Z&~(V=(G=1<>k.b)*it;U=m),0w.o&&(d=w.o),u=d?u=0:(m[0]+=4*w.v,w.ka=u-w.j,w.U=w.va-w.v,w.T=d-u,u=1),u){if(N=N[0],11>(u=t.ca).S){var U=u.f.RGBA,K=(d=u.S,m=w.U,w=w.T,k=U.eb,U.A),Z=w;for(U=U.fb+t.Ma*U.A;0d){var m=t.l.width,w=u.ca,y=u.tb+m*d,N=t.V,x=t.Ba+t.c*d,k=t.gc;e(t.ab==1),e(k[0].hc==3),Eo(k[0],d,r,N,x,w,y),An(u,d,r,w,y,m)}t.C=t.Ma=r}function Sn(t,r,u,d,m,w,y){var N=t.$/d,x=t.$%d,k=t.m,U=t.s,K=u+t.$,Z=K;m=u+d*m;var G=u+d*w,vt=280+U.ua,it=t.Pb?N:16777216,H=0=it){var Ot=K-u;e((it=t).Pb),it.wd=it.m,it.xd=Ot,0Rt.g?(W(mt,mt.u+Rt.g),Ot[St]=Rt.value,mt=0):(W(mt,mt.u+Rt.g-256),e(256<=Rt.value),mt=Rt.value),mt==0&&(bt=!0)}else mt=en(pt.G[0],pt.H[0],k);if(k.h)break;if(bt||256>mt){if(!bt)if(pt.nd)r[K]=(pt.qb|mt<<8)>>>0;else{if(Y(k),bt=en(pt.G[1],pt.H[1],k),Y(k),Ot=en(pt.G[2],pt.H[2],k),St=en(pt.G[3],pt.H[3],k),k.h)break;r[K]=(St<<24|bt<<16|mt<<8|Ot)>>>0}if(bt=!1,++K,++x>=d&&(x=0,++N,y!=null&&N<=w&&!(N%16)&&y(t,N),H!=null))for(;Z>>H.Mb]=mt}else if(280>mt){if(mt=Nn(mt-256,k),Ot=en(pt.G[4],pt.H[4],k),Y(k),Ot=Un(d,Ot=Nn(Ot,k)),k.h)break;if(K-u=d;)x-=d,++N,y!=null&&N<=w&&!(N%16)&&y(t,N);if(e(K<=m),x&V&&(pt=Oe(U,x,N)),H!=null)for(;Z>>H.Mb]=mt}else{if(!(mt>>H.Mb]=mt;mt=K,e(!(bt>>>(Ot=H).Xa)),r[mt]=Ot.X[bt],bt=!0}bt||e(k.h==M(k))}if(t.Pb&&k.h&&Kw?w:N),t.a=0,t.$=K-u}return 1}return t.a=3,0}function Hn(t){e(t!=null),t.vc=null,t.yc=null,t.Ya=null;var r=t.Wa;r!=null&&(r.X=null),t.vb=null,e(t!=null)}function pn(){var t=new Bo;return t==null?null:(t.a=0,t.xb=Bs,Rn("Predictor","VP8LPredictors"),Rn("Predictor","VP8LPredictors_C"),Rn("PredictorAdd","VP8LPredictorsAdd"),Rn("PredictorAdd","VP8LPredictorsAdd_C"),Ba=ie,gn=Wt,In=It,mr=Ve,Gn=oe,rr=yn,vi=ge,R.VP8LMapColor32b=Xi,R.VP8LMapColor8b=qo,t)}function Wn(t,r,u,d,m){var w=1,y=[t],N=[r],x=d.m,k=d.s,U=null,K=0;t:for(;;){if(u)for(;w&&ht(x,1);){var Z=y,G=N,vt=d,it=1,H=vt.m,V=vt.gc[vt.ab],pt=ht(H,2);if(vt.Oc&1<=vt.ab),pt){case 0:case 1:V.b=ht(H,3)+2,it=Wn(Et(V.Ea,V.b),Et(V.nc,V.b),0,vt,V.K),V.K=V.K[0];break;case 3:var bt,mt=ht(H,8)+1,Ot=16>_t.b),le=o(se);if(le==null)bt=0;else{var ae=_t.K[0],ne=_t.w;for(le[0]=_t.K[0][0],St=1;St<1*Rt;++St)le[St]=Lt(ae[ne+St],le[St-1]);for(;St<4*se;++St)le[St]=0;_t.K[0]=null,_t.K[0]=le,bt=1}}it=bt;break;case 2:break;default:e(0)}w=it}}if(y=y[0],N=N[0],w&&ht(x,1)&&!(w=1<=(K=ht(x,4))&&11>=K)){d.a=3;break t}var me;if(me=w)e:{var pe,Zt,Me,on=d,Ee=y,sn=N,he=K,fn=u,dn=on.m,ze=on.s,We=[null],$e=1,wn=0,Yn=Gc[he];n:for(;;){if(fn&&ht(dn,1)){var Ue=ht(dn,3)+2,cr=Et(Ee,Ue),Hr=Et(sn,Ue),Li=cr*Hr;if(!Wn(cr,Hr,0,on,We))break n;for(We=We[0],ze.xc=Ue,pe=0;pe>8&65535;We[pe]=Nr,Nr>=$e&&($e=Nr+1)}}if(dn.h)break n;for(Zt=0;5>Zt;++Zt){var _e=js[Zt];!Zt&&0=Hs),Va=Ws;var ta=o(wn);if(Va==null||ta==null||Go==null){on.a=1;break n}var Ga=Go;for(pe=Me=0;pe<$e;++pe){var Bn=Va[pe],Ni=Bn.G,Ai=Bn.H,Vs=0,Ya=1,Gs=0;for(Zt=0;5>Zt;++Zt){_e=js[Zt],Ni[Zt]=Ga,Ai[Zt]=Me,!Zt&&0$a)break r}else Xo=$a;for(na=0;na<$a&&Xo--;){Y(xr);var tc=Qs[0+(127&j(xr))];W(xr,xr.u+tc.g);var xi=tc.value;if(16>xi)Zs[na++]=xi,xi!=0&&($s=xi);else{var yu=xi==16,ec=xi-16,Lu=Uc[ec],nc=ht(xr,zc[ec])+Lu;if(na+nc>$a)break r;for(var Nu=yu?$s:0;0=Zt){var ra,Zo=ta[0];for(ra=1;ra<_e;++ra)ta[ra]>Zo&&(Zo=ta[ra]);Gs+=Zo}}if(Bn.nd=Ya,Bn.Qb=0,Ya&&(Bn.qb=(Ni[3][Ai[3]+0].value<<24|Ni[1][Ai[1]+0].value<<16|Ni[2][Ai[2]+0].value)>>>0,Vs==0&&256>Ni[0][Ai[0]+0].value&&(Bn.Qb=1,Bn.qb+=Ni[0][Ai[0]+0].value<<8)),Bn.jc=!Bn.Qb&&6>Gs,Bn.jc){var Qa,ur=Bn;for(Qa=0;Qa>=qe(to,8,_r),Sr>>=qe(ur.G[1][ur.H[1]+Sr],16,_r),Sr>>=qe(ur.G[2][ur.H[2]+Sr],0,_r),qe(ur.G[3][ur.H[3]+Sr],24,_r))}}}ze.vc=We,ze.Wb=$e,ze.Ya=Va,ze.yc=Go,me=1;break e}me=0}if(!(w=me)){d.a=3;break t}if(0d+1?[]:0),!(m.lengthm)return ke(t,7,"Truncated header.");var w=u[d+0]|u[d+1]<<8|u[d+2]<<16,y=t.Od;if(y.Rb=!(1&w),y.td=w>>1&7,y.yd=w>>4&1,y.ub=w>>5,3m)return ke(t,7,"cannot parse picture header");if(!va(u,d,m))return ke(t,3,"Bad code word");N.c=16383&(u[d+4]<<8|u[d+3]),N.Td=u[d+4]>>6,N.i=16383&(u[d+6]<<8|u[d+5]),N.Ud=u[d+6]>>6,d+=7,m-=7,t.za=N.c+15>>4,t.Ub=N.i+15>>4,r.width=N.c,r.height=N.i,r.Da=0,r.j=0,r.v=0,r.va=r.width,r.o=r.height,r.da=0,r.ib=r.width,r.hb=r.height,r.U=r.width,r.T=r.height,c((w=t.Pa).jb,0,255,w.jb.length),e((w=t.Qa)!=null),w.Cb=0,w.Bb=0,w.Fb=1,c(w.Zb,0,0,w.Zb.length),c(w.Lb,0,0,w.Lb)}if(y.ub>m)return ke(t,7,"bad partition length");at(w=t.m,u,d,y.ub),d+=y.ub,m-=y.ub,y.Rb&&(N.Ld=et(w),N.Kd=et(w)),N=t.Qa;var x,k=t.Pa;if(e(w!=null),e(N!=null),N.Cb=et(w),N.Cb){if(N.Bb=et(w),et(w)){for(N.Fb=et(w),x=0;4>x;++x)N.Zb[x]=et(w)?lt(w,7):0;for(x=0;4>x;++x)N.Lb[x]=et(w)?lt(w,6):0}if(N.Bb)for(x=0;3>x;++x)k.jb[x]=et(w)?nt(w,8):255}else N.Bb=0;if(w.Ka)return ke(t,3,"cannot parse segment header");if((N=t.ed).zd=et(w),N.Tb=nt(w,6),N.wb=nt(w,3),N.Pc=et(w),N.Pc&&et(w)){for(k=0;4>k;++k)et(w)&&(N.vd[k]=lt(w,6));for(k=0;4>k;++k)et(w)&&(N.od[k]=lt(w,6))}if(t.L=N.Tb==0?0:N.zd?1:2,w.Ka)return ke(t,3,"cannot parse filter header");var U=m;if(m=x=d,d=x+U,N=U,t.Xb=(1<N&&(K=N),at(t.Jc[+U],u,x,K),x+=K,N-=K,m+=3}at(t.Jc[+k],u,x,N),u=xK;++K){if(U.Cb){var Z=U.Zb[K];U.Fb||(Z+=u)}else{if(0>16,8>G.Eb[1]&&(G.Eb[1]=8),G.Qc[0]=Ho[ln(Z+k,117)],G.Qc[1]=Wo[ln(Z+x,127)],G.lc=Z+x}if(!y.Rb)return ke(t,4,"Not a key frame.");for(et(w),y=t.Pa,u=0;4>u;++u){for(m=0;8>m;++m)for(d=0;3>d;++d)for(N=0;11>N;++N)k=rt(w,$c[u][m][d][N])?nt(w,8):Kc[u][m][d][N],y.Wc[u][m].Yb[d][N]=k;for(m=0;17>m;++m)y.Xc[u][m]=y.Wc[u][Qc[m]]}return t.kc=et(w),t.kc&&(t.Bd=nt(w,8)),t.cb=1}function wa(t,r,u,d,m,w,y){var N=r[m].Yb[u];for(u=0;16>m;++m){if(!rt(t,N[u+0]))return m;for(;!rt(t,N[u+1]);)if(N=r[++m].Yb[0],u=0,m==16)return 16;var x=r[m+1].Yb;if(rt(t,N[u+2])){var k=t,U=0;if(rt(k,(Z=N)[(K=u)+3]))if(rt(k,Z[K+6])){for(N=0,K=2*(U=rt(k,Z[K+8]))+(Z=rt(k,Z[K+9+U])),U=0,Z=Jc[K];Z[N];++N)U+=U+rt(k,Z[N]);U+=3+(8<(k=t).b&&Q(k);var K,Z=k.b,G=(K=k.Ca>>1)-(k.I>>Z)>>31;--k.b,k.Ca+=G,k.Ca|=1,k.I-=(K+1&G)<>4,t.zb=r.j-u>>4,0>t.yb&&(t.yb=0),0>t.zb&&(t.zb=0)),t.Va=r.o+15+u>>4,t.Hb=r.va+15+u>>4,t.Hb>t.za&&(t.Hb=t.za),t.Va>t.Ub&&(t.Va=t.Ub),0u;++u){var m;if(t.Qa.Cb){var w=t.Qa.Lb[u];t.Qa.Fb||(w+=d.Tb)}else w=d.Tb;for(m=0;1>=m;++m){var y=t.gd[u][m],N=w;if(d.Pc&&(N+=d.vd[0],m&&(N+=d.od[0])),0<(N=0>N?0:63>2:x>>1)>9-d.wb&&(x=9-d.wb),1>x&&(x=1),y.dd=x,y.tc=2*N+x,y.ld=40<=N?2:15<=N?1:0}else y.tc=0;y.La=m}}}u=0}else ke(t,6,"Frame setup failed"),u=t.a;if(u=u==0){if(u){t.$c=0,0t.Vb){if(t.Vb=0,t.Ec=o(y),t.Fc=0,t.Ec==null){u=ke(t,1,"no memory during frame initialization.");break t}t.Vb=y}y=t.Ec,N=t.Fc,t.Ac=y,t.Bc=N,N+=d,t.Gd=l(k,ma),t.Hd=0,t.rb=l(U+1,ga),t.sb=1,t.wa=K?l(K,ni):null,t.Y=0,t.D.Nb=0,t.D.wa=t.wa,t.D.Y=t.Y,0=u;++u)Ss[255+u]=0>u?-u:u;for(u=-1020;1020>=u;++u)_s[1020+u]=-128>u?-128:127=u;++u)Ps[112+u]=-16>u?-16:15=u;++u)ks[255+u]=0>u?0:255mt;++mt){var ae,ne=Rt[0+mt];for(ae=0;4>ae;++ae){ne=Zc[Ot[St+ae]][ne];for(var me=Os[rt(bt,ne[0])];0>3;for(me=0;256>me;me+=16)mt[se+me]=sn}Me=1,on=St[0]}var he=15&bt.la,fn=15&le.la;for(me=0;4>me;++me){var dn=1&fn;for(sn=Zt=0;4>sn;++sn)he=he>>1|(dn=(Ee=$i(Ot,on,Ee=dn+(1&he),_t.Sc,Me,mt,se))>Me)<<7,Zt=Zt<<2|(3>=4,fn=fn>>1|dn<<7,ae=(ae<<8|Zt)>>>0}for(on=he,Me=fn>>4,pe=0;4>pe;pe+=2){for(Zt=0,he=bt.la>>4+pe,fn=le.la>>4+pe,me=0;2>me;++me){for(dn=1&fn,sn=0;2>sn;++sn)Ee=dn+(1&he),he=he>>1|(dn=0<(Ee=$i(Ot,St[2],Ee,_t.Qc,0,mt,se)))<<3,Zt=Zt<<2|(3>=2,fn=fn>>1|dn<<5}ne|=Zt<<4*pe,on|=he<<4<=H.zb&&H.M<=H.Va,H.Aa==0)t:{if(it.M=H.M,it.uc=bt,Wi(H,it),pt=1,it=(Zt=H.D).Nb,bt=(ne=Wa[H.L])*H.R,Ot=ne/2*H.B,me=16*it*H.R,sn=8*it*H.B,St=H.sa,Rt=H.ta-bt+me,_t=H.qa,mt=H.ra-Ot+sn,se=H.Ha,le=H.Ia-Ot+sn,fn=(he=Zt.M)==0,ae=he>=H.Va-1,H.Aa==2&&Wi(H,Zt),Zt.uc)for(dn=(Ee=H).D.M,e(Ee.D.uc),Zt=Ee.yb;ZtV.o&&(he=V.o),V.F=null,V.J=null,H.Fa!=null&&0>1),V.W+=H.B*(ne>>1),V.F!=null&&(V.J+=V.width*ne)),Zt>1,V.W+=V.v>>1,V.F!=null&&(V.J+=V.v),V.ka=Zt-V.j,V.U=V.va-V.v,V.T=he-Zt,pt=V.put(V))}it+1!=H.Ic||ae||(a(H.sa,H.ta-bt,St,Rt+16*H.R,bt),a(H.qa,H.ra-Ot,_t,mt+8*H.B,Ot),a(H.Ha,H.Ia-Ot,se,le+8*H.B,Ot))}if(!pt)return ke(G,6,"Output aborted.")}return 1}(t,r)),r.bc!=null&&r.bc(r),u&=1}return u?(t.cb=0,u):0}function _n(t,r,u,d,m){m=t[r+u+32*d]+(m>>3),t[r+u+32*d]=-256&m?0>m?0:255:m}function ii(t,r,u,d,m,w){_n(t,r,0,u,d+m),_n(t,r,1,u,d+w),_n(t,r,2,u,d-w),_n(t,r,3,u,d-m)}function nn(t){return(20091*t>>16)+t}function Ci(t,r,u,d){var m,w=0,y=o(16);for(m=0;4>m;++m){var N=t[r+0]+t[r+8],x=t[r+0]-t[r+8],k=(35468*t[r+4]>>16)-nn(t[r+12]),U=nn(t[r+4])+(35468*t[r+12]>>16);y[w+0]=N+U,y[w+1]=x+k,y[w+2]=x-k,y[w+3]=N-U,w+=4,r++}for(m=w=0;4>m;++m)N=(t=y[w+0]+4)+y[w+8],x=t-y[w+8],k=(35468*y[w+4]>>16)-nn(y[w+12]),_n(u,d,0,0,N+(U=nn(y[w+4])+(35468*y[w+12]>>16))),_n(u,d,1,0,x+k),_n(u,d,2,0,x-k),_n(u,d,3,0,N-U),w++,d+=32}function ya(t,r,u,d){var m=t[r+0]+4,w=35468*t[r+4]>>16,y=nn(t[r+4]),N=35468*t[r+1]>>16;ii(u,d,0,m+y,t=nn(t[r+1]),N),ii(u,d,1,m+w,t,N),ii(u,d,2,m-w,t,N),ii(u,d,3,m-y,t,N)}function bo(t,r,u,d,m){Ci(t,r,u,d),m&&Ci(t,r+16,u,d+4)}function La(t,r,u,d){bi(t,r+0,u,d,1),bi(t,r+32,u,d+128,1)}function wo(t,r,u,d){var m;for(t=t[r+0]+4,m=0;4>m;++m)for(r=0;4>r;++r)_n(u,d,r,m,t)}function Na(t,r,u,d){t[r+0]&&jn(t,r+0,u,d),t[r+16]&&jn(t,r+16,u,d+4),t[r+32]&&jn(t,r+32,u,d+128),t[r+48]&&jn(t,r+48,u,d+128+4)}function yo(t,r,u,d){var m,w=o(16);for(m=0;4>m;++m){var y=t[r+0+m]+t[r+12+m],N=t[r+4+m]+t[r+8+m],x=t[r+4+m]-t[r+8+m],k=t[r+0+m]-t[r+12+m];w[0+m]=y+N,w[8+m]=y-N,w[4+m]=k+x,w[12+m]=k-x}for(m=0;4>m;++m)y=(t=w[0+4*m]+3)+w[3+4*m],N=w[1+4*m]+w[2+4*m],x=w[1+4*m]-w[2+4*m],k=t-w[3+4*m],u[d+0]=y+N>>3,u[d+16]=k+x>>3,u[d+32]=y-N>>3,u[d+48]=k-x>>3,d+=64}function ji(t,r,u){var d,m=r-32,w=hn,y=255-t[m-1];for(d=0;du;++u)a(t,r+32*u,t,r-32,16)}function ai(t,r){var u;for(u=16;0d;++d)c(r,u+32*d,t,16)}function Aa(t,r){var u,d=16;for(u=0;16>u;++u)d+=t[r-1+32*u]+t[r+u-32];oi(d>>5,t,r)}function Ge(t,r){var u,d=8;for(u=0;16>u;++u)d+=t[r-1+32*u];oi(d>>4,t,r)}function xo(t,r){var u,d=8;for(u=0;16>u;++u)d+=t[r+u-32];oi(d>>4,t,r)}function xa(t,r){oi(128,t,r)}function Vt(t,r,u){return t+2*r+u+2>>2}function So(t,r){var u,d=r-32;for(d=new Uint8Array([Vt(t[d-1],t[d+0],t[d+1]),Vt(t[d+0],t[d+1],t[d+2]),Vt(t[d+1],t[d+2],t[d+3]),Vt(t[d+2],t[d+3],t[d+4])]),u=0;4>u;++u)a(t,r+32*u,d,0,d.length)}function _o(t,r){var u=t[r-1],d=t[r-1+32],m=t[r-1+64],w=t[r-1+96];At(t,r+0,16843009*Vt(t[r-1-32],u,d)),At(t,r+32,16843009*Vt(u,d,m)),At(t,r+64,16843009*Vt(d,m,w)),At(t,r+96,16843009*Vt(m,w,w))}function Vn(t,r){var u,d=4;for(u=0;4>u;++u)d+=t[r+u-32]+t[r-1+32*u];for(d>>=3,u=0;4>u;++u)c(t,r+32*u,d,4)}function Sa(t,r){var u=t[r-1+0],d=t[r-1+32],m=t[r-1+64],w=t[r-1-32],y=t[r+0-32],N=t[r+1-32],x=t[r+2-32],k=t[r+3-32];t[r+0+96]=Vt(d,m,t[r-1+96]),t[r+1+96]=t[r+0+64]=Vt(u,d,m),t[r+2+96]=t[r+1+64]=t[r+0+32]=Vt(w,u,d),t[r+3+96]=t[r+2+64]=t[r+1+32]=t[r+0+0]=Vt(y,w,u),t[r+3+64]=t[r+2+32]=t[r+1+0]=Vt(N,y,w),t[r+3+32]=t[r+2+0]=Vt(x,N,y),t[r+3+0]=Vt(k,x,N)}function _a(t,r){var u=t[r+1-32],d=t[r+2-32],m=t[r+3-32],w=t[r+4-32],y=t[r+5-32],N=t[r+6-32],x=t[r+7-32];t[r+0+0]=Vt(t[r+0-32],u,d),t[r+1+0]=t[r+0+32]=Vt(u,d,m),t[r+2+0]=t[r+1+32]=t[r+0+64]=Vt(d,m,w),t[r+3+0]=t[r+2+32]=t[r+1+64]=t[r+0+96]=Vt(m,w,y),t[r+3+32]=t[r+2+64]=t[r+1+96]=Vt(w,y,N),t[r+3+64]=t[r+2+96]=Vt(y,N,x),t[r+3+96]=Vt(N,x,x)}function si(t,r){var u=t[r-1+0],d=t[r-1+32],m=t[r-1+64],w=t[r-1-32],y=t[r+0-32],N=t[r+1-32],x=t[r+2-32],k=t[r+3-32];t[r+0+0]=t[r+1+64]=w+y+1>>1,t[r+1+0]=t[r+2+64]=y+N+1>>1,t[r+2+0]=t[r+3+64]=N+x+1>>1,t[r+3+0]=x+k+1>>1,t[r+0+96]=Vt(m,d,u),t[r+0+64]=Vt(d,u,w),t[r+0+32]=t[r+1+96]=Vt(u,w,y),t[r+1+32]=t[r+2+96]=Vt(w,y,N),t[r+2+32]=t[r+3+96]=Vt(y,N,x),t[r+3+32]=Vt(N,x,k)}function Oi(t,r){var u=t[r+0-32],d=t[r+1-32],m=t[r+2-32],w=t[r+3-32],y=t[r+4-32],N=t[r+5-32],x=t[r+6-32],k=t[r+7-32];t[r+0+0]=u+d+1>>1,t[r+1+0]=t[r+0+64]=d+m+1>>1,t[r+2+0]=t[r+1+64]=m+w+1>>1,t[r+3+0]=t[r+2+64]=w+y+1>>1,t[r+0+32]=Vt(u,d,m),t[r+1+32]=t[r+0+96]=Vt(d,m,w),t[r+2+32]=t[r+1+96]=Vt(m,w,y),t[r+3+32]=t[r+2+96]=Vt(w,y,N),t[r+3+64]=Vt(y,N,x),t[r+3+96]=Vt(N,x,k)}function Po(t,r){var u=t[r-1+0],d=t[r-1+32],m=t[r-1+64],w=t[r-1+96];t[r+0+0]=u+d+1>>1,t[r+2+0]=t[r+0+32]=d+m+1>>1,t[r+2+32]=t[r+0+64]=m+w+1>>1,t[r+1+0]=Vt(u,d,m),t[r+3+0]=t[r+1+32]=Vt(d,m,w),t[r+3+32]=t[r+1+64]=Vt(m,w,w),t[r+3+64]=t[r+2+64]=t[r+0+96]=t[r+1+96]=t[r+2+96]=t[r+3+96]=w}function ko(t,r){var u=t[r-1+0],d=t[r-1+32],m=t[r-1+64],w=t[r-1+96],y=t[r-1-32],N=t[r+0-32],x=t[r+1-32],k=t[r+2-32];t[r+0+0]=t[r+2+32]=u+y+1>>1,t[r+0+32]=t[r+2+64]=d+u+1>>1,t[r+0+64]=t[r+2+96]=m+d+1>>1,t[r+0+96]=w+m+1>>1,t[r+3+0]=Vt(N,x,k),t[r+2+0]=Vt(y,N,x),t[r+1+0]=t[r+3+32]=Vt(u,y,N),t[r+1+32]=t[r+3+64]=Vt(d,u,y),t[r+1+64]=t[r+3+96]=Vt(m,d,u),t[r+1+96]=Vt(w,m,d)}function Fo(t,r){var u;for(u=0;8>u;++u)a(t,r+32*u,t,r-32,8)}function Bi(t,r){var u;for(u=0;8>u;++u)c(t,r,t[r-1],8),r+=32}function qr(t,r,u){var d;for(d=0;8>d;++d)c(r,u+32*d,t,8)}function hr(t,r){var u,d=8;for(u=0;8>u;++u)d+=t[r+u-32]+t[r-1+32*u];qr(d>>4,t,r)}function Io(t,r){var u,d=4;for(u=0;8>u;++u)d+=t[r+u-32];qr(d>>3,t,r)}function Dr(t,r){var u,d=4;for(u=0;8>u;++u)d+=t[r-1+32*u];qr(d>>3,t,r)}function Mi(t,r){qr(128,t,r)}function ci(t,r,u){var d=t[r-u],m=t[r+0],w=3*(m-d)+Do[1020+t[r-2*u]-t[r+u]],y=Ea[112+(w+4>>3)];t[r-u]=hn[255+d+Ea[112+(w+3>>3)]],t[r+0]=hn[255+m-y]}function Pa(t,r,u,d){var m=t[r+0],w=t[r+u];return vn[255+t[r-2*u]-t[r-u]]>d||vn[255+w-m]>d}function ka(t,r,u,d){return 4*vn[255+t[r-u]-t[r+0]]+vn[255+t[r-2*u]-t[r+u]]<=d}function Fa(t,r,u,d,m){var w=t[r-3*u],y=t[r-2*u],N=t[r-u],x=t[r+0],k=t[r+u],U=t[r+2*u],K=t[r+3*u];return 4*vn[255+N-x]+vn[255+y-k]>d?0:vn[255+t[r-4*u]-w]<=m&&vn[255+w-y]<=m&&vn[255+y-N]<=m&&vn[255+K-U]<=m&&vn[255+U-k]<=m&&vn[255+k-x]<=m}function Ia(t,r,u,d){var m=2*d+1;for(d=0;16>d;++d)ka(t,r+d,u,m)&&ci(t,r+d,u)}function er(t,r,u,d){var m=2*d+1;for(d=0;16>d;++d)ka(t,r+d*u,1,m)&&ci(t,r+d*u,1)}function fr(t,r,u,d){var m;for(m=3;0>7,V=18*pt+63>>7,pt=9*pt+63>>7;x[k-3*U]=hn[255+x[k-3*U]+pt],x[k-2*U]=hn[255+K+V],x[k-U]=hn[255+Z+H],x[k+0]=hn[255+G-H],x[k+U]=hn[255+vt-V],x[k+2*U]=hn[255+it-pt]}r+=d}}function Pn(t,r,u,d,m,w,y,N){for(w=2*w+1;0>3)],it=Ea[112+(it+3>>3)],H=vt+1>>1;x[k-2*U]=hn[255+x[k-2*U]+H],x[k-U]=hn[255+K+it],x[k+0]=hn[255+Z-vt],x[k+U]=hn[255+G-H]}r+=d}}function Ei(t,r,u,d,m,w){dr(t,r,u,1,16,d,m,w)}function Rr(t,r,u,d,m,w){dr(t,r,1,u,16,d,m,w)}function jo(t,r,u,d,m,w){var y;for(y=3;0k?0:255:k)&255,k=x,m[w+N]=U}}function Ui(t,r,u,d){var m=r.width,w=r.o;if(e(t!=null&&r!=null),0>u||0>=d||u+d>w)return null;if(!t.Cc){if(t.ga==null){var y;if(t.ga=new hi,(y=t.ga==null)||(y=r.width*r.o,e(t.Gb.length==0),t.Gb=o(y),t.Uc=0,t.Gb==null?y=0:(t.mb=t.Gb,t.nb=t.Uc,t.rc=null,y=1),y=!y),!y){y=t.ga;var N=t.Fa,x=t.P,k=t.qc,U=t.mb,K=t.nb,Z=x+1,G=k-1,vt=y.l;if(e(N!=null&&U!=null&&r!=null),Lr[0]=null,Lr[1]=Tr,Lr[2]=zi,Lr[3]=pr,y.ca=U,y.tb=K,y.c=r.width,y.i=r.height,e(0=k)r=0;else if(y.$a=N[x+0]>>0&3,y.Z=N[x+0]>>2&3,y.Lc=N[x+0]>>4&3,x=N[x+0]>>6&3,0>y.$a||1=y.c*y.i;y=!r}if(y)return null;t.ga.Lc!=1?t.Ga=0:d=w-u}e(t.ga!=null),e(u+d<=w);t:{if(r=(N=t.ga).c,w=N.l.o,N.$a==0){if(Z=t.rc,G=t.Vc,vt=t.Fa,x=t.P+1+u*r,k=t.mb,U=t.nb+u*r,e(x<=t.P+t.qc),N.Z!=0)for(e(Lr[N.Z]!=null),y=0;y=r)r=1;else if(N.ic||J(),N.ic){N=y.V,Z=y.Ba,G=y.c;var it=y.i,H=(vt=1,x=y.$/G,k=y.$%G,U=y.m,K=y.s,y.$),V=G*it,pt=G*r,bt=K.wc,mt=H(it=en(mt.G[0],mt.H[0],U)))N[Z+H]=it,++H,++k>=G&&(k=0,++x<=r&&!(x%16)&&xn(y,x));else{if(!(280>it)){vt=0;break e}it=Nn(it-256,U);var Ot,St=en(mt.G[4],mt.H[4],U);if(Y(U),!(H>=(St=Un(G,St=Nn(St,U)))&&V-H>=it)){vt=0;break e}for(Ot=0;Ot=G;)k-=G,++x<=r&&!(x%16)&&xn(y,x);Hr?r:x);break e}!vt||U.h&&H=w&&(t.Cc=1),d=1}if(!d)return null;if(t.Cc&&((d=t.ga)!=null&&(d.mc=null),t.ga=null,0>23,N[x+4*y+1]=N[x+4*y+1]*K>>23,N[x+4*y+2]=N[x+4*y+2]*K>>23)}r+=w}}function v(t,r,u,d,m){for(;0>4)*x>>16;t[r+2*w+0]=(240&y|y>>4)*x>>16&240|(15&y|y<<4)*x>>16>>4&15,t[r+2*w+1]=240&k|N}r+=m}}function C(t,r,u,d,m,w,y,N){var x,k,U=255;for(k=0;k>8}function J(){wr=s,yi=v,Ma=C,xs=T}function st(t,r,u){R[t]=function(d,m,w,y,N,x,k,U,K,Z,G,vt,it,H,V,pt,bt){var mt,Ot=bt-1>>1,St=N[x+0]|k[U+0]<<16,Rt=K[Z+0]|G[vt+0]<<16;e(d!=null);var _t=3*St+Rt+131074>>2;for(r(d[m+0],255&_t,_t>>16,it,H),w!=null&&(_t=3*Rt+St+131074>>2,r(w[y+0],255&_t,_t>>16,V,pt)),mt=1;mt<=Ot;++mt){var se=N[x+mt]|k[U+mt]<<16,le=K[Z+mt]|G[vt+mt]<<16,ae=St+se+Rt+le+524296,ne=ae+2*(se+Rt)>>3;_t=ne+St>>1,St=(ae=ae+2*(St+le)>>3)+se>>1,r(d[m+2*mt-1],255&_t,_t>>16,it,H+(2*mt-1)*u),r(d[m+2*mt-0],255&St,St>>16,it,H+(2*mt-0)*u),w!=null&&(_t=ae+Rt>>1,St=ne+le>>1,r(w[y+2*mt-1],255&_t,_t>>16,V,pt+(2*mt-1)*u),r(w[y+2*mt+0],255&St,St>>16,V,pt+(2*mt+0)*u)),St=se,Rt=le}1&bt||(_t=3*St+Rt+131074>>2,r(d[m+bt-1],255&_t,_t>>16,it,H+(bt-1)*u),w!=null&&(_t=3*Rt+St+131074>>2,r(w[y+bt-1],255&_t,_t>>16,V,pt+(bt-1)*u)))}}function yt(){bn[qa]=eu,bn[Da]=Ms,bn[Is]=nu,bn[Ra]=Es,bn[Ta]=qs,bn[Ro]=Ds,bn[Cs]=ru,bn[To]=Ms,bn[zo]=Es,bn[za]=qs,bn[Uo]=Ds}function jt(t){return t&~iu?0>t?0:255:t>>Rs}function Dt(t,r){return jt((19077*t>>8)+(26149*r>>8)-14234)}function Kt(t,r,u){return jt((19077*t>>8)-(6419*r>>8)-(13320*u>>8)+8708)}function Qt(t,r){return jt((19077*t>>8)+(33050*r>>8)-17685)}function re(t,r,u,d,m){d[m+0]=Dt(t,u),d[m+1]=Kt(t,r,u),d[m+2]=Qt(t,r)}function Ne(t,r,u,d,m){d[m+0]=Qt(t,r),d[m+1]=Kt(t,r,u),d[m+2]=Dt(t,u)}function Se(t,r,u,d,m){var w=Kt(t,r,u);r=w<<3&224|Qt(t,r)>>3,d[m+0]=248&Dt(t,u)|w>>5,d[m+1]=r}function Be(t,r,u,d,m){var w=240&Qt(t,r)|15;d[m+0]=240&Dt(t,u)|Kt(t,r,u)>>4,d[m+1]=w}function Ye(t,r,u,d,m){d[m+0]=255,re(t,r,u,d,m+1)}function Te(t,r,u,d,m){Ne(t,r,u,d,m),d[m+3]=255}function kn(t,r,u,d,m){re(t,r,u,d,m),d[m+3]=255}function ln(t,r){return 0>t?0:t>r?r:t}function nr(t,r,u){R[t]=function(d,m,w,y,N,x,k,U,K){for(var Z=U+(-2&K)*u;U!=Z;)r(d[m+0],w[y+0],N[x+0],k,U),r(d[m+1],w[y+0],N[x+0],k,U+u),m+=2,++y,++x,U+=2*u;1&K&&r(d[m+0],w[y+0],N[x+0],k,U)}}function Oa(t,r,u){return u==0?t==0?r==0?6:5:r==0?4:0:u}function Hi(t,r,u,d,m){switch(t>>>30){case 3:bi(r,u,d,m,0);break;case 2:Ki(r,u,d,m);break;case 1:jn(r,u,d,m)}}function Wi(t,r){var u,d,m=r.M,w=r.Nb,y=t.oc,N=t.pc+40,x=t.oc,k=t.pc+584,U=t.oc,K=t.pc+600;for(u=0;16>u;++u)y[N+32*u-1]=129;for(u=0;8>u;++u)x[k+32*u-1]=129,U[K+32*u-1]=129;for(0u;++u)a(y,N+32*u-4,y,N+32*u+12,4);for(u=-1;8>u;++u)a(x,k+32*u-4,x,k+32*u+4,4),a(U,K+32*u-4,U,K+32*u+4,4)}var G=t.Gd,vt=t.Hd+d,it=Z.ad,H=Z.Hc;if(0=t.za-1?c(V,pt,G[vt].y[15],4):a(V,pt,G[vt+1].y,0,4)),u=0;4>u;u++)V[pt+128+u]=V[pt+256+u]=V[pt+384+u]=V[pt+0+u];for(u=0;16>u;++u,H<<=2)V=y,pt=N+zs[u],On[Z.Ob[u]](V,pt),Hi(H,it,16*+u,V,pt)}else if(V=Oa(d,m,Z.Ob[0]),yr[V](y,N),H!=0)for(u=0;16>u;++u,H<<=2)Hi(H,it,16*+u,y,N+zs[u]);for(u=Z.Gc,V=Oa(d,m,Z.Dd),sr[V](x,k),sr[V](U,K),H=it,V=x,pt=k,255&(Z=u>>0)&&(170&Z?vr(H,256,V,pt):ir(H,256,V,pt)),Z=U,H=K,255&(u>>=8)&&(170&u?vr(it,320,Z,H):ir(it,320,Z,H)),mu;++u)a(G,vt+u*t.R,y,N+32*u,16);for(u=0;8>u;++u)a(it,Z+u*t.B,x,k+32*u,8),a(H,V+u*t.B,U,K+32*u,8)}}function fi(t,r,u,d,m,w,y,N,x){var k=[0],U=[0],K=0,Z=x!=null?x.kd:0,G=x??new Ri;if(t==null||12>u)return 7;G.data=t,G.w=r,G.ha=u,r=[r],u=[u],G.gb=[G.gb];t:{var vt=r,it=u,H=G.gb;if(e(t!=null),e(it!=null),e(H!=null),H[0]=0,12<=it[0]&&!n(t,vt[0],"RIFF")){if(n(t,vt[0]+8,"WEBP")){H=3;break t}var V=Bt(t,vt[0]+4);if(12>V||4294967286it[0]-8){H=7;break t}H[0]=V,vt[0]+=12,it[0]-=12}H=0}if(H!=0)return H;for(V=0H[0])H=7;else{if(!n(pt,it[0],"VP8X")){if(Bt(pt,it[0]+4)!=10){H=3;break t}if(18>H[0]){H=7;break t}var St=Bt(pt,it[0]+8),Rt=1+Ct(pt,it[0]+12);if(2147483648<=Rt*(pt=1+Ct(pt,it[0]+15))){H=3;break t}Ot!=null&&(Ot[0]=St),bt!=null&&(bt[0]=Rt),mt!=null&&(mt[0]=pt),it[0]+=18,H[0]-=18,_t[0]=1}H=0}}if(K=K[0],vt=vt[0],H!=0)return H;if(it=!!(2&vt),!V&&K)return 3;if(w!=null&&(w[0]=!!(16&vt)),y!=null&&(y[0]=it),N!=null&&(N[0]=0),y=k[0],vt=U[0],K&&it&&x==null){H=0;break}if(4>u){H=7;break}if(V&&K||!V&&!K&&!n(t,r[0],"ALPH")){u=[u],G.na=[G.na],G.P=[G.P],G.Sa=[G.Sa];t:{St=t,H=r,V=u;var _t=G.gb;bt=G.na,mt=G.P,Ot=G.Sa,Rt=22,e(St!=null),e(V!=null),pt=H[0];var se=V[0];for(e(bt!=null),e(Ot!=null),bt[0]=null,mt[0]=null,Ot[0]=0;;){if(H[0]=pt,V[0]=se,8>se){H=7;break t}var le=Bt(St,pt+4);if(4294967286_t){H=3;break t}if(!n(St,pt,"VP8 ")||!n(St,pt,"VP8L")){H=0;break t}if(se[0]V[0])H=7;else{if(pt||Rt){if(_t=Bt(_t,St+4),12<=bt&&_t>bt-12){H=3;break t}if(Z&&_t>V[0]-8){H=7;break t}mt[0]=_t,H[0]+=8,V[0]-=8,Ot[0]=Rt}else Ot[0]=5<=V[0]&&_t[St+0]==47&&!(_t[St+4]>>5),mt[0]=V[0];H=0}if(u=u[0],G.Ja=G.Ja[0],G.xa=G.xa[0],r=r[0],H!=0)break;if(4294967286u){H=7;break}N=y,Z=vt,it=w,t==null||5>u?t=0:5<=u&&t[r+0]==47&&!(t[r+4]>>5)?(V=[0],_t=[0],bt=[0],$(mt=new L,t,r,u),zt(mt,V,_t,bt)?(N!=null&&(N[0]=V[0]),Z!=null&&(Z[0]=_t[0]),it!=null&&(it[0]=bt[0]),t=1):t=0):t=0}else{if(10>u){H=7;break}N=vt,t==null||10>u||!va(t,r+3,u-3)?t=0:(Z=t[r+0]|t[r+1]<<8|t[r+2]<<16,it=16383&(t[r+7]<<8|t[r+6]),t=16383&(t[r+9]<<8|t[r+8]),1&Z||3<(Z>>1&7)||!(Z>>4&1)||Z>>5>=G.Ja||!it||!t?t=0:(y&&(y[0]=it),N&&(N[0]=t),t=1))}if(!t||(y=y[0],vt=vt[0],K&&(k[0]!=y||U[0]!=vt)))return 3;x!=null&&(x[0]=G,x.offset=r-x.w,e(4294967286>r-x.w),e(x.offset==x.ha-u));break}return H==0||H==7&&K&&x==null?(w!=null&&(w[0]|=G.na!=null&&0u||(w&=-2,y&=-2),0>w||0>y||0>=N||0>=x||w+N>d||y+x>m))return 0;if(r.v=w,r.j=y,r.va=w+N,r.o=y+x,r.U=N,r.T=x,r.da=t!=null&&0t.S){var r=t.f.RGBA;r.fb+=(t.height-1)*r.A,r.A=-r.A}else r=t.f.kb,t=t.height,r.O+=(t-1)*r.fa,r.fa=-r.fa,r.N+=(t-1>>1)*r.Ab,r.Ab=-r.Ab,r.W+=(t-1>>1)*r.Db,r.Db=-r.Db,r.F!=null&&(r.J+=(t-1)*r.lb,r.lb=-r.lb);return 0}function di(t,r,u,d){if(d==null||0>=t||0>=r)return 2;if(u!=null){if(u.Da){var m=u.cd,w=u.bd,y=-2&u.v,N=-2&u.j;if(0>y||0>N||0>=m||0>=w||y+m>t||N+w>r)return 2;t=m,r=w}if(u.da){if(!Xt(t,r,m=[u.ib],w=[u.hb]))return 2;t=m[0],r=w[0]}}d.width=t,d.height=r;t:{var x=d.width,k=d.height;if(t=d.S,0>=x||0>=k||!(t>=qa&&13>t))t=2;else{if(0>=d.Rd&&d.sd==null){y=w=m=r=0;var U=(N=x*Us[t])*k;if(11>t||(w=(k+1)/2*(r=(x+1)/2),t==12&&(y=(m=x)*k)),(k=o(U+2*w+y))==null){t=1;break t}d.sd=k,11>t?((x=d.f.RGBA).eb=k,x.fb=0,x.A=N,x.size=U):((x=d.f.kb).y=k,x.O=0,x.fa=N,x.Fd=U,x.f=k,x.N=0+U,x.Ab=r,x.Cd=w,x.ea=k,x.W=0+U+w,x.Db=r,x.Ed=w,t==12&&(x.F=k,x.J=0+U+2*w),x.Tc=y,x.lb=m)}if(r=1,m=d.S,w=d.width,y=d.height,m>=qa&&13>m)if(11>m)t=d.f.RGBA,r&=(N=Math.abs(t.A))*(y-1)+w<=t.size,r&=N>=w*Us[m],r&=t.eb!=null;else{t=d.f.kb,N=(w+1)/2,U=(y+1)/2,x=Math.abs(t.fa),k=Math.abs(t.Ab);var K=Math.abs(t.Db),Z=Math.abs(t.lb),G=Z*(y-1)+w;r&=x*(y-1)+w<=t.Fd,r&=k*(U-1)+N<=t.Cd,r=(r&=K*(U-1)+N<=t.Ed)&x>=w&k>=N&K>=N,r&=t.y!=null,r&=t.f!=null,r&=t.ea!=null,m==12&&(r&=Z>=w,r&=G<=t.Tc,r&=t.F!=null)}else r=0;t=r?0:2}}return t!=0||u!=null&&u.fd&&(t=Gi(d)),t}var rn=64,pi=[0,1,3,7,15,31,63,127,255,511,1023,2047,4095,8191,16383,32767,65535,131071,262143,524287,1048575,2097151,4194303,8388607,16777215],gi=24,mi=32,Yi=8,an=[0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7];xt("Predictor0","PredictorAdd0"),R.Predictor0=function(){return 4278190080},R.Predictor1=function(t){return t},R.Predictor2=function(t,r,u){return r[u+0]},R.Predictor3=function(t,r,u){return r[u+1]},R.Predictor4=function(t,r,u){return r[u-1]},R.Predictor5=function(t,r,u){return Pt(Pt(t,r[u+1]),r[u+0])},R.Predictor6=function(t,r,u){return Pt(t,r[u-1])},R.Predictor7=function(t,r,u){return Pt(t,r[u+0])},R.Predictor8=function(t,r,u){return Pt(r[u-1],r[u+0])},R.Predictor9=function(t,r,u){return Pt(r[u+0],r[u+1])},R.Predictor10=function(t,r,u){return Pt(Pt(t,r[u-1]),Pt(r[u+0],r[u+1]))},R.Predictor11=function(t,r,u){var d=r[u+0];return 0>=$t(d>>24&255,t>>24&255,(r=r[u-1])>>24&255)+$t(d>>16&255,t>>16&255,r>>16&255)+$t(d>>8&255,t>>8&255,r>>8&255)+$t(255&d,255&t,255&r)?d:t},R.Predictor12=function(t,r,u){var d=r[u+0];return(qt((t>>24&255)+(d>>24&255)-((r=r[u-1])>>24&255))<<24|qt((t>>16&255)+(d>>16&255)-(r>>16&255))<<16|qt((t>>8&255)+(d>>8&255)-(r>>8&255))<<8|qt((255&t)+(255&d)-(255&r)))>>>0},R.Predictor13=function(t,r,u){var d=r[u-1];return(Gt((t=Pt(t,r[u+0]))>>24&255,d>>24&255)<<24|Gt(t>>16&255,d>>16&255)<<16|Gt(t>>8&255,d>>8&255)<<8|Gt(t>>0&255,d>>0&255))>>>0};var Mo=R.PredictorAdd0;R.PredictorAdd1=te,xt("Predictor2","PredictorAdd2"),xt("Predictor3","PredictorAdd3"),xt("Predictor4","PredictorAdd4"),xt("Predictor5","PredictorAdd5"),xt("Predictor6","PredictorAdd6"),xt("Predictor7","PredictorAdd7"),xt("Predictor8","PredictorAdd8"),xt("Predictor9","PredictorAdd9"),xt("Predictor10","PredictorAdd10"),xt("Predictor11","PredictorAdd11"),xt("Predictor12","PredictorAdd12"),xt("Predictor13","PredictorAdd13");var Ji=R.PredictorAdd2;ee("ColorIndexInverseTransform","MapARGB","32b",function(t){return t>>8&255},function(t){return t}),ee("VP8LColorIndexInverseTransformAlpha","MapAlpha","8b",function(t){return t},function(t){return t>>8&255});var Ba,Fn=R.ColorIndexInverseTransform,Xi=R.MapARGB,Eo=R.VP8LColorIndexInverseTransformAlpha,qo=R.MapAlpha,gr=R.VP8LPredictorsAdd=[];gr.length=16,(R.VP8LPredictors=[]).length=16,(R.VP8LPredictorsAdd_C=[]).length=16,(R.VP8LPredictors_C=[]).length=16;var gn,In,mr,Gn,rr,vi,Cn,bi,Ki,vr,jn,ir,zr,wi,Ur,br,Zi,mn,ar,be,we,Fe,De,or,wr,yi,Ma,xs,Ss=o(511),_s=o(2041),Ps=o(225),ks=o(767),Fs=0,Do=_s,Ea=Ps,hn=ks,vn=Ss,qa=0,Da=1,Is=2,Ra=3,Ta=4,Ro=5,Cs=6,To=7,zo=8,za=9,Uo=10,zc=[2,3,7],Uc=[3,3,11],js=[280,256,256,256,40],Hc=[0,1,1,1,0],Wc=[17,18,0,1,2,3,4,5,16,6,7,8,9,10,11,12,13,14,15],Vc=[24,7,23,25,40,6,39,41,22,26,38,42,56,5,55,57,21,27,54,58,37,43,72,4,71,73,20,28,53,59,70,74,36,44,88,69,75,52,60,3,87,89,19,29,86,90,35,45,68,76,85,91,51,61,104,2,103,105,18,30,102,106,34,46,84,92,67,77,101,107,50,62,120,1,119,121,83,93,17,31,100,108,66,78,118,122,33,47,117,123,49,63,99,109,82,94,0,116,124,65,79,16,32,98,110,48,115,125,81,95,64,114,126,97,111,80,113,127,96,112],Gc=[2954,2956,2958,2962,2970,2986,3018,3082,3212,3468,3980,5004],Yc=8,Ho=[4,5,6,7,8,9,10,10,11,12,13,14,15,16,17,17,18,19,20,20,21,21,22,22,23,23,24,25,25,26,27,28,29,30,31,32,33,34,35,36,37,37,38,39,40,41,42,43,44,45,46,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,76,77,78,79,80,81,82,83,84,85,86,87,88,89,91,93,95,96,98,100,101,102,104,106,108,110,112,114,116,118,122,124,126,128,130,132,134,136,138,140,143,145,148,151,154,157],Wo=[4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,60,62,64,66,68,70,72,74,76,78,80,82,84,86,88,90,92,94,96,98,100,102,104,106,108,110,112,114,116,119,122,125,128,131,134,137,140,143,146,149,152,155,158,161,164,167,170,173,177,181,185,189,193,197,201,205,209,213,217,221,225,229,234,239,245,249,254,259,264,269,274,279,284],$i=null,Jc=[[173,148,140,0],[176,155,140,135,0],[180,157,141,134,130,0],[254,254,243,230,196,177,153,140,133,130,129,0]],Xc=[0,1,4,8,5,2,3,6,9,12,13,10,7,11,14,15],Os=[-0,1,-1,2,-2,3,4,6,-3,5,-4,-5,-6,7,-7,8,-8,-9],Kc=[[[[128,128,128,128,128,128,128,128,128,128,128],[128,128,128,128,128,128,128,128,128,128,128],[128,128,128,128,128,128,128,128,128,128,128]],[[253,136,254,255,228,219,128,128,128,128,128],[189,129,242,255,227,213,255,219,128,128,128],[106,126,227,252,214,209,255,255,128,128,128]],[[1,98,248,255,236,226,255,255,128,128,128],[181,133,238,254,221,234,255,154,128,128,128],[78,134,202,247,198,180,255,219,128,128,128]],[[1,185,249,255,243,255,128,128,128,128,128],[184,150,247,255,236,224,128,128,128,128,128],[77,110,216,255,236,230,128,128,128,128,128]],[[1,101,251,255,241,255,128,128,128,128,128],[170,139,241,252,236,209,255,255,128,128,128],[37,116,196,243,228,255,255,255,128,128,128]],[[1,204,254,255,245,255,128,128,128,128,128],[207,160,250,255,238,128,128,128,128,128,128],[102,103,231,255,211,171,128,128,128,128,128]],[[1,152,252,255,240,255,128,128,128,128,128],[177,135,243,255,234,225,128,128,128,128,128],[80,129,211,255,194,224,128,128,128,128,128]],[[1,1,255,128,128,128,128,128,128,128,128],[246,1,255,128,128,128,128,128,128,128,128],[255,128,128,128,128,128,128,128,128,128,128]]],[[[198,35,237,223,193,187,162,160,145,155,62],[131,45,198,221,172,176,220,157,252,221,1],[68,47,146,208,149,167,221,162,255,223,128]],[[1,149,241,255,221,224,255,255,128,128,128],[184,141,234,253,222,220,255,199,128,128,128],[81,99,181,242,176,190,249,202,255,255,128]],[[1,129,232,253,214,197,242,196,255,255,128],[99,121,210,250,201,198,255,202,128,128,128],[23,91,163,242,170,187,247,210,255,255,128]],[[1,200,246,255,234,255,128,128,128,128,128],[109,178,241,255,231,245,255,255,128,128,128],[44,130,201,253,205,192,255,255,128,128,128]],[[1,132,239,251,219,209,255,165,128,128,128],[94,136,225,251,218,190,255,255,128,128,128],[22,100,174,245,186,161,255,199,128,128,128]],[[1,182,249,255,232,235,128,128,128,128,128],[124,143,241,255,227,234,128,128,128,128,128],[35,77,181,251,193,211,255,205,128,128,128]],[[1,157,247,255,236,231,255,255,128,128,128],[121,141,235,255,225,227,255,255,128,128,128],[45,99,188,251,195,217,255,224,128,128,128]],[[1,1,251,255,213,255,128,128,128,128,128],[203,1,248,255,255,128,128,128,128,128,128],[137,1,177,255,224,255,128,128,128,128,128]]],[[[253,9,248,251,207,208,255,192,128,128,128],[175,13,224,243,193,185,249,198,255,255,128],[73,17,171,221,161,179,236,167,255,234,128]],[[1,95,247,253,212,183,255,255,128,128,128],[239,90,244,250,211,209,255,255,128,128,128],[155,77,195,248,188,195,255,255,128,128,128]],[[1,24,239,251,218,219,255,205,128,128,128],[201,51,219,255,196,186,128,128,128,128,128],[69,46,190,239,201,218,255,228,128,128,128]],[[1,191,251,255,255,128,128,128,128,128,128],[223,165,249,255,213,255,128,128,128,128,128],[141,124,248,255,255,128,128,128,128,128,128]],[[1,16,248,255,255,128,128,128,128,128,128],[190,36,230,255,236,255,128,128,128,128,128],[149,1,255,128,128,128,128,128,128,128,128]],[[1,226,255,128,128,128,128,128,128,128,128],[247,192,255,128,128,128,128,128,128,128,128],[240,128,255,128,128,128,128,128,128,128,128]],[[1,134,252,255,255,128,128,128,128,128,128],[213,62,250,255,255,128,128,128,128,128,128],[55,93,255,128,128,128,128,128,128,128,128]],[[128,128,128,128,128,128,128,128,128,128,128],[128,128,128,128,128,128,128,128,128,128,128],[128,128,128,128,128,128,128,128,128,128,128]]],[[[202,24,213,235,186,191,220,160,240,175,255],[126,38,182,232,169,184,228,174,255,187,128],[61,46,138,219,151,178,240,170,255,216,128]],[[1,112,230,250,199,191,247,159,255,255,128],[166,109,228,252,211,215,255,174,128,128,128],[39,77,162,232,172,180,245,178,255,255,128]],[[1,52,220,246,198,199,249,220,255,255,128],[124,74,191,243,183,193,250,221,255,255,128],[24,71,130,219,154,170,243,182,255,255,128]],[[1,182,225,249,219,240,255,224,128,128,128],[149,150,226,252,216,205,255,171,128,128,128],[28,108,170,242,183,194,254,223,255,255,128]],[[1,81,230,252,204,203,255,192,128,128,128],[123,102,209,247,188,196,255,233,128,128,128],[20,95,153,243,164,173,255,203,128,128,128]],[[1,222,248,255,216,213,128,128,128,128,128],[168,175,246,252,235,205,255,255,128,128,128],[47,116,215,255,211,212,255,255,128,128,128]],[[1,121,236,253,212,214,255,255,128,128,128],[141,84,213,252,201,202,255,219,128,128,128],[42,80,160,240,162,185,255,205,128,128,128]],[[1,1,255,128,128,128,128,128,128,128,128],[244,1,255,128,128,128,128,128,128,128,128],[238,1,255,128,128,128,128,128,128,128,128]]]],Zc=[[[231,120,48,89,115,113,120,152,112],[152,179,64,126,170,118,46,70,95],[175,69,143,80,85,82,72,155,103],[56,58,10,171,218,189,17,13,152],[114,26,17,163,44,195,21,10,173],[121,24,80,195,26,62,44,64,85],[144,71,10,38,171,213,144,34,26],[170,46,55,19,136,160,33,206,71],[63,20,8,114,114,208,12,9,226],[81,40,11,96,182,84,29,16,36]],[[134,183,89,137,98,101,106,165,148],[72,187,100,130,157,111,32,75,80],[66,102,167,99,74,62,40,234,128],[41,53,9,178,241,141,26,8,107],[74,43,26,146,73,166,49,23,157],[65,38,105,160,51,52,31,115,128],[104,79,12,27,217,255,87,17,7],[87,68,71,44,114,51,15,186,23],[47,41,14,110,182,183,21,17,194],[66,45,25,102,197,189,23,18,22]],[[88,88,147,150,42,46,45,196,205],[43,97,183,117,85,38,35,179,61],[39,53,200,87,26,21,43,232,171],[56,34,51,104,114,102,29,93,77],[39,28,85,171,58,165,90,98,64],[34,22,116,206,23,34,43,166,73],[107,54,32,26,51,1,81,43,31],[68,25,106,22,64,171,36,225,114],[34,19,21,102,132,188,16,76,124],[62,18,78,95,85,57,50,48,51]],[[193,101,35,159,215,111,89,46,111],[60,148,31,172,219,228,21,18,111],[112,113,77,85,179,255,38,120,114],[40,42,1,196,245,209,10,25,109],[88,43,29,140,166,213,37,43,154],[61,63,30,155,67,45,68,1,209],[100,80,8,43,154,1,51,26,71],[142,78,78,16,255,128,34,197,171],[41,40,5,102,211,183,4,1,221],[51,50,17,168,209,192,23,25,82]],[[138,31,36,171,27,166,38,44,229],[67,87,58,169,82,115,26,59,179],[63,59,90,180,59,166,93,73,154],[40,40,21,116,143,209,34,39,175],[47,15,16,183,34,223,49,45,183],[46,17,33,183,6,98,15,32,183],[57,46,22,24,128,1,54,17,37],[65,32,73,115,28,128,23,128,205],[40,3,9,115,51,192,18,6,223],[87,37,9,115,59,77,64,21,47]],[[104,55,44,218,9,54,53,130,226],[64,90,70,205,40,41,23,26,57],[54,57,112,184,5,41,38,166,213],[30,34,26,133,152,116,10,32,134],[39,19,53,221,26,114,32,73,255],[31,9,65,234,2,15,1,118,73],[75,32,12,51,192,255,160,43,51],[88,31,35,67,102,85,55,186,85],[56,21,23,111,59,205,45,37,192],[55,38,70,124,73,102,1,34,98]],[[125,98,42,88,104,85,117,175,82],[95,84,53,89,128,100,113,101,45],[75,79,123,47,51,128,81,171,1],[57,17,5,71,102,57,53,41,49],[38,33,13,121,57,73,26,1,85],[41,10,67,138,77,110,90,47,114],[115,21,2,10,102,255,166,23,6],[101,29,16,10,85,128,101,196,26],[57,18,10,102,102,213,34,20,43],[117,20,15,36,163,128,68,1,26]],[[102,61,71,37,34,53,31,243,192],[69,60,71,38,73,119,28,222,37],[68,45,128,34,1,47,11,245,171],[62,17,19,70,146,85,55,62,70],[37,43,37,154,100,163,85,160,1],[63,9,92,136,28,64,32,201,85],[75,15,9,9,64,255,184,119,16],[86,6,28,5,64,255,25,248,1],[56,8,17,132,137,255,55,116,128],[58,15,20,82,135,57,26,121,40]],[[164,50,31,137,154,133,25,35,218],[51,103,44,131,131,123,31,6,158],[86,40,64,135,148,224,45,183,128],[22,26,17,131,240,154,14,1,209],[45,16,21,91,64,222,7,1,197],[56,21,39,155,60,138,23,102,213],[83,12,13,54,192,255,68,47,28],[85,26,85,85,128,128,32,146,171],[18,11,7,63,144,171,4,4,246],[35,27,10,146,174,171,12,26,128]],[[190,80,35,99,180,80,126,54,45],[85,126,47,87,176,51,41,20,32],[101,75,128,139,118,146,116,128,85],[56,41,15,176,236,85,37,9,62],[71,30,17,119,118,255,17,18,138],[101,38,60,138,55,70,43,26,142],[146,36,19,30,171,255,97,27,20],[138,45,61,62,219,1,81,188,64],[32,41,20,117,151,142,20,21,163],[112,19,12,61,195,128,48,4,24]]],$c=[[[[255,255,255,255,255,255,255,255,255,255,255],[255,255,255,255,255,255,255,255,255,255,255],[255,255,255,255,255,255,255,255,255,255,255]],[[176,246,255,255,255,255,255,255,255,255,255],[223,241,252,255,255,255,255,255,255,255,255],[249,253,253,255,255,255,255,255,255,255,255]],[[255,244,252,255,255,255,255,255,255,255,255],[234,254,254,255,255,255,255,255,255,255,255],[253,255,255,255,255,255,255,255,255,255,255]],[[255,246,254,255,255,255,255,255,255,255,255],[239,253,254,255,255,255,255,255,255,255,255],[254,255,254,255,255,255,255,255,255,255,255]],[[255,248,254,255,255,255,255,255,255,255,255],[251,255,254,255,255,255,255,255,255,255,255],[255,255,255,255,255,255,255,255,255,255,255]],[[255,253,254,255,255,255,255,255,255,255,255],[251,254,254,255,255,255,255,255,255,255,255],[254,255,254,255,255,255,255,255,255,255,255]],[[255,254,253,255,254,255,255,255,255,255,255],[250,255,254,255,254,255,255,255,255,255,255],[254,255,255,255,255,255,255,255,255,255,255]],[[255,255,255,255,255,255,255,255,255,255,255],[255,255,255,255,255,255,255,255,255,255,255],[255,255,255,255,255,255,255,255,255,255,255]]],[[[217,255,255,255,255,255,255,255,255,255,255],[225,252,241,253,255,255,254,255,255,255,255],[234,250,241,250,253,255,253,254,255,255,255]],[[255,254,255,255,255,255,255,255,255,255,255],[223,254,254,255,255,255,255,255,255,255,255],[238,253,254,254,255,255,255,255,255,255,255]],[[255,248,254,255,255,255,255,255,255,255,255],[249,254,255,255,255,255,255,255,255,255,255],[255,255,255,255,255,255,255,255,255,255,255]],[[255,253,255,255,255,255,255,255,255,255,255],[247,254,255,255,255,255,255,255,255,255,255],[255,255,255,255,255,255,255,255,255,255,255]],[[255,253,254,255,255,255,255,255,255,255,255],[252,255,255,255,255,255,255,255,255,255,255],[255,255,255,255,255,255,255,255,255,255,255]],[[255,254,254,255,255,255,255,255,255,255,255],[253,255,255,255,255,255,255,255,255,255,255],[255,255,255,255,255,255,255,255,255,255,255]],[[255,254,253,255,255,255,255,255,255,255,255],[250,255,255,255,255,255,255,255,255,255,255],[254,255,255,255,255,255,255,255,255,255,255]],[[255,255,255,255,255,255,255,255,255,255,255],[255,255,255,255,255,255,255,255,255,255,255],[255,255,255,255,255,255,255,255,255,255,255]]],[[[186,251,250,255,255,255,255,255,255,255,255],[234,251,244,254,255,255,255,255,255,255,255],[251,251,243,253,254,255,254,255,255,255,255]],[[255,253,254,255,255,255,255,255,255,255,255],[236,253,254,255,255,255,255,255,255,255,255],[251,253,253,254,254,255,255,255,255,255,255]],[[255,254,254,255,255,255,255,255,255,255,255],[254,254,254,255,255,255,255,255,255,255,255],[255,255,255,255,255,255,255,255,255,255,255]],[[255,254,255,255,255,255,255,255,255,255,255],[254,254,255,255,255,255,255,255,255,255,255],[254,255,255,255,255,255,255,255,255,255,255]],[[255,255,255,255,255,255,255,255,255,255,255],[254,255,255,255,255,255,255,255,255,255,255],[255,255,255,255,255,255,255,255,255,255,255]],[[255,255,255,255,255,255,255,255,255,255,255],[255,255,255,255,255,255,255,255,255,255,255],[255,255,255,255,255,255,255,255,255,255,255]],[[255,255,255,255,255,255,255,255,255,255,255],[255,255,255,255,255,255,255,255,255,255,255],[255,255,255,255,255,255,255,255,255,255,255]],[[255,255,255,255,255,255,255,255,255,255,255],[255,255,255,255,255,255,255,255,255,255,255],[255,255,255,255,255,255,255,255,255,255,255]]],[[[248,255,255,255,255,255,255,255,255,255,255],[250,254,252,254,255,255,255,255,255,255,255],[248,254,249,253,255,255,255,255,255,255,255]],[[255,253,253,255,255,255,255,255,255,255,255],[246,253,253,255,255,255,255,255,255,255,255],[252,254,251,254,254,255,255,255,255,255,255]],[[255,254,252,255,255,255,255,255,255,255,255],[248,254,253,255,255,255,255,255,255,255,255],[253,255,254,254,255,255,255,255,255,255,255]],[[255,251,254,255,255,255,255,255,255,255,255],[245,251,254,255,255,255,255,255,255,255,255],[253,253,254,255,255,255,255,255,255,255,255]],[[255,251,253,255,255,255,255,255,255,255,255],[252,253,254,255,255,255,255,255,255,255,255],[255,254,255,255,255,255,255,255,255,255,255]],[[255,252,255,255,255,255,255,255,255,255,255],[249,255,254,255,255,255,255,255,255,255,255],[255,255,254,255,255,255,255,255,255,255,255]],[[255,255,253,255,255,255,255,255,255,255,255],[250,255,255,255,255,255,255,255,255,255,255],[255,255,255,255,255,255,255,255,255,255,255]],[[255,255,255,255,255,255,255,255,255,255,255],[254,255,255,255,255,255,255,255,255,255,255],[255,255,255,255,255,255,255,255,255,255,255]]]],Qc=[0,1,2,3,6,4,5,6,6,6,6,6,6,6,6,7,0],yr=[],On=[],sr=[],tu=1,Bs=2,Lr=[],bn=[];st("UpsampleRgbLinePair",re,3),st("UpsampleBgrLinePair",Ne,3),st("UpsampleRgbaLinePair",kn,4),st("UpsampleBgraLinePair",Te,4),st("UpsampleArgbLinePair",Ye,4),st("UpsampleRgba4444LinePair",Be,2),st("UpsampleRgb565LinePair",Se,2);var eu=R.UpsampleRgbLinePair,nu=R.UpsampleBgrLinePair,Ms=R.UpsampleRgbaLinePair,Es=R.UpsampleBgraLinePair,qs=R.UpsampleArgbLinePair,Ds=R.UpsampleRgba4444LinePair,ru=R.UpsampleRgb565LinePair,Ua=16,Ha=1<d.ca.S||(alert("todo:WebPInitConvertARGBToYUV"),d.ca.f.kb.F!=null&&J()),d.Pb&&0(x=u.Md)?0:100k;++k)12>(K=m.pb[k]).lc&&(K.ia=x*hu[0>K.lc?0:K.lc]>>3),U|=K.ia;U&&(alert("todo:VP8InitRandom"),m.ia=1)}m.Ga=u.Id,100m.Ga&&(m.Ga=0)}vo(t,d)||(r=t.a)}}else r=t.a}r==0&&y.Oa!=null&&y.Oa.fd&&(r=Gi(y.ba))}y=r}w=y!=0?null:11>w?N.f.RGBA.eb:N.f.kb.y}else w=null;return w};var Us=[3,4,3,4,4,2,2,4,4,4,2,1,1]};function g(R,gt){for(var dt="",F=0;F<4;F++)dt+=String.fromCharCode(R[gt++]);return dt}function b(R,gt){return(R[gt+0]<<0|R[gt+1]<<8|R[gt+2]<<16)>>>0}function A(R,gt){return(R[gt+0]<<0|R[gt+1]<<8|R[gt+2]<<16|R[gt+3]<<24)>>>0}new f;var S=[0],p=[0],O=[],I=new f,q=i,_=function(R,gt){var dt={},F=0,P=!1,z=0,D=0;if(dt.frames=[],!function(j,M,W,Y){for(var Q=0;Q>1&1}lt!="ANMF"&&(gt+=ft)}return dt}}(q,0);_.response=q,_.rgbaoutput=!0,_.dataurl=!1;var B=_.header?_.header:null,X=_.frames?_.frames:null;if(B){B.loop_counter=B.loop_count,S=[B.canvas_height],p=[B.canvas_width];for(var ot=0;ot>>1)&255;return _},f=function(S,p,O){var I,q,_,B,X=[],ot=S.length;X[0]=4;for(var ut=0;ut>>lt&255,lt+=B.bits;gt[z]=P>>>lt&255}}if(B.bits===16){R=(tt=new Uint32Array(B.decodePixels().buffer)).length,dt=new Uint8Array(R*(32/B.pixelBitlength)*B.colors),gt=new Uint8Array(R*(32/B.pixelBitlength)),F=B.colors>1,z=0,D=0;for(var ft=0;z>>0&255,F&&(dt[D++]=P>>>16&255,P=tt[z++],dt[D++]=P>>>0&255),gt[ft++]=P>>>16&255;_=8}I!==i.image_compression.NONE&&e()?(S=n(dt,B.width*B.colors,B.colors,I),wt=n(gt,B.width,1,I)):(S=dt,wt=gt,at=void 0)}if(B.colorType===3&&(q=this.color_spaces.INDEXED,ut=B.palette,B.transparency.indexed)){var ht=B.transparency.indexed,kt=0;for(z=0,R=ht.length;z=0;i--){for(var a=this.bottom_up?i:this.height-1-i,c=0;c>7-h&1];this.data[l+4*h]=f.blue,this.data[l+4*h+1]=f.green,this.data[l+4*h+2]=f.red,this.data[l+4*h+3]=255}n!==0&&(this.pos+=4-n)}},En.prototype.bit4=function(){for(var i=Math.ceil(this.width/2),e=i%4,n=this.height-1;n>=0;n--){for(var a=this.bottom_up?n:this.height-1-n,c=0;c>4,f=15&o,g=this.palette[h];if(this.data[l]=g.blue,this.data[l+1]=g.green,this.data[l+2]=g.red,this.data[l+3]=255,2*c+1>=this.width)break;g=this.palette[f],this.data[l+4]=g.blue,this.data[l+4+1]=g.green,this.data[l+4+2]=g.red,this.data[l+4+3]=255}e!==0&&(this.pos+=4-e)}},En.prototype.bit8=function(){for(var i=this.width%4,e=this.height-1;e>=0;e--){for(var n=this.bottom_up?e:this.height-1-e,a=0;a=0;n--){for(var a=this.bottom_up?n:this.height-1-n,c=0;c>5&e)/e*255|0,f=(o>>10&e)/e*255|0,g=o>>15?255:0,b=a*this.width*4+4*c;this.data[b]=f,this.data[b+1]=h,this.data[b+2]=l,this.data[b+3]=g}this.pos+=i}},En.prototype.bit16=function(){for(var i=this.width%3,e=parseInt("11111",2),n=parseInt("111111",2),a=this.height-1;a>=0;a--){for(var c=this.bottom_up?a:this.height-1-a,o=0;o>5&n)/n*255|0,g=(l>>11)/e*255|0,b=c*this.width*4+4*o;this.data[b]=g,this.data[b+1]=f,this.data[b+2]=h,this.data[b+3]=255}this.pos+=i}},En.prototype.bit24=function(){for(var i=this.height-1;i>=0;i--){for(var e=this.bottom_up?i:this.height-1-i,n=0;n=0;i--)for(var e=this.bottom_up?i:this.height-1-i,n=0;na&&(c.push(i.slice(f,o)),h=0,f=o),h+=e[o],o++;return f!==o&&c.push(i.slice(f,o)),c},yc=function(i,e,n){n||(n={});var a,c,o,l,h,f,g,b=[],A=[b],S=n.textIndent||0,p=0,O=0,I=i.split(" "),q=io.apply(this,[" ",n])[0];if(f=n.lineIndent===-1?I[0].length+2:n.lineIndent||0){var _=Array(f).join(" "),B=[];I.map(function(ot){(ot=ot.split(/\s*\n/)).length>1?B=B.concat(ot.map(function(ut,wt){return(wt&&ut.length?` `:"")+ut})):B.push(ot[0])}),I=B,f=bc.apply(this,[_,n])}for(o=0,l=I.length;oe||X){if(O>e){for(h=wc.apply(this,[a,c,e-(S+p),e]),b.push(h.shift()),b=[h.pop()];h.length;)A.push([h.shift()]);O=c.slice(a.length-(b[0]?b[0].length:0)).reduce(function(ot,ut){return ot+ut},0)}else b=[a];A.push(b),S=O+f,p=q}else b.push(a),S+=p+O,p=q}return g=f?function(ot,ut){return(ut?_:"")+ot.join(" ")}:function(ot){return ot.join(" ")},A.map(g)},_i.splitTextToSize=function(i,e,n){var a,c=(n=n||{}).fontSize||this.internal.getFontSize(),o=(function(b){if(b.widths&&b.kerning)return{widths:b.widths,kerning:b.kerning};var A=this.internal.getFont(b.fontName,b.fontStyle);return A.metadata.Unicode?{widths:A.metadata.Unicode.widths||{0:1},kerning:A.metadata.Unicode.kerning||{}}:{font:A.metadata,fontSize:this.internal.getFontSize(),charSpace:this.internal.getCharSpace()}}).call(this,n);a=Array.isArray(i)?i:String(i).split(/\r?\n/);var l=1*this.internal.scaleFactor*e/c;o.textIndent=n.textIndent?1*n.textIndent*this.internal.scaleFactor/c:0,o.lineIndent=n.lineIndent;var h,f,g=[];for(h=0,f=a.length;himport("./index.es-e6325295.js"),["assets/index.es-e6325295.js","assets/main-262930e7.js"])).catch(function(n){return Promise.reject(new Error("Could not load canvg: "+n))}).then(function(n){return n.default?n.default:n})}Tt.API.addSvgAsImage=function(n,a,c,o,l,h,f,g){if(isNaN(a)||isNaN(c))throw ve.error("jsPDF.addSvgAsImage: Invalid coordinates",arguments),new Error("Invalid coordinates passed to jsPDF.addSvgAsImage");if(isNaN(o)||isNaN(l))throw ve.error("jsPDF.addSvgAsImage: Invalid measurements",arguments),new Error("Invalid measurements (width and/or height) passed to jsPDF.addSvgAsImage");var b=document.createElement("canvas");b.width=o,b.height=l;var A=b.getContext("2d");A.fillStyle="#fff",A.fillRect(0,0,b.width,b.height);var S={ignoreMouse:!0,ignoreAnimation:!0,ignoreDimensions:!0},p=this;return e().then(function(O){return O.fromString(A,n,S)},function(){return Promise.reject(new Error("Could not load canvg."))}).then(function(O){return O.render(S)}).then(function(){p.addImage(b.toDataURL("image/jpeg",1),a,c,o,l,f,g)})}}(),Tt.API.putTotalPages=function(i){var e,n=0;parseInt(this.internal.getFont().id.substr(1),10)<15?(e=new RegExp(i,"g"),n=this.internal.getNumberOfPages()):(e=new RegExp(this.pdfEscape16(i,this.internal.getFont()),"g"),n=this.pdfEscape16(this.internal.getNumberOfPages()+"",this.internal.getFont()));for(var a=1;a<=this.internal.getNumberOfPages();a++)for(var c=0;c1){for(b=0;be||X){if(O>e){for(h=wc.apply(this,[a,c,e-(S+p),e]),b.push(h.shift()),b=[h.pop()];h.length;)A.push([h.shift()]);O=c.slice(a.length-(b[0]?b[0].length:0)).reduce(function(ot,ut){return ot+ut},0)}else b=[a];A.push(b),S=O+f,p=q}else b.push(a),S+=p+O,p=q}return g=f?function(ot,ut){return(ut?_:"")+ot.join(" ")}:function(ot){return ot.join(" ")},A.map(g)},_i.splitTextToSize=function(i,e,n){var a,c=(n=n||{}).fontSize||this.internal.getFontSize(),o=(function(b){if(b.widths&&b.kerning)return{widths:b.widths,kerning:b.kerning};var A=this.internal.getFont(b.fontName,b.fontStyle);return A.metadata.Unicode?{widths:A.metadata.Unicode.widths||{0:1},kerning:A.metadata.Unicode.kerning||{}}:{font:A.metadata,fontSize:this.internal.getFontSize(),charSpace:this.internal.getCharSpace()}}).call(this,n);a=Array.isArray(i)?i:String(i).split(/\r?\n/);var l=1*this.internal.scaleFactor*e/c;o.textIndent=n.textIndent?1*n.textIndent*this.internal.scaleFactor/c:0,o.lineIndent=n.lineIndent;var h,f,g=[];for(h=0,f=a.length;himport("./index.es-9e632253.js"),["assets/index.es-9e632253.js","assets/main-ab68e62d.js"])).catch(function(n){return Promise.reject(new Error("Could not load canvg: "+n))}).then(function(n){return n.default?n.default:n})}Tt.API.addSvgAsImage=function(n,a,c,o,l,h,f,g){if(isNaN(a)||isNaN(c))throw ve.error("jsPDF.addSvgAsImage: Invalid coordinates",arguments),new Error("Invalid coordinates passed to jsPDF.addSvgAsImage");if(isNaN(o)||isNaN(l))throw ve.error("jsPDF.addSvgAsImage: Invalid measurements",arguments),new Error("Invalid measurements (width and/or height) passed to jsPDF.addSvgAsImage");var b=document.createElement("canvas");b.width=o,b.height=l;var A=b.getContext("2d");A.fillStyle="#fff",A.fillRect(0,0,b.width,b.height);var S={ignoreMouse:!0,ignoreAnimation:!0,ignoreDimensions:!0},p=this;return e().then(function(O){return O.fromString(A,n,S)},function(){return Promise.reject(new Error("Could not load canvg."))}).then(function(O){return O.render(S)}).then(function(){p.addImage(b.toDataURL("image/jpeg",1),a,c,o,l,f,g)})}}(),Tt.API.putTotalPages=function(i){var e,n=0;parseInt(this.internal.getFont().id.substr(1),10)<15?(e=new RegExp(i,"g"),n=this.internal.getNumberOfPages()):(e=new RegExp(this.pdfEscape16(i,this.internal.getFont()),"g"),n=this.pdfEscape16(this.internal.getNumberOfPages()+"",this.internal.getFont()));for(var a=1;a<=this.internal.getNumberOfPages();a++)for(var c=0;c1){for(b=0;be in g?xke(g,e,{enumerable:!0,configurable:!0,writable:!0,value:I}):g[e]=I;var Tu=(g,e,I)=>(Dke(g,typeof e!="symbol"?e+"":e,I),I);function Fke(g,e){for(var I=0;Ii[n]})}}}return Object.freeze(Object.defineProperty(g,Symbol.toStringTag,{value:"Module"}))}(function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const n of document.querySelectorAll('link[rel="modulepreload"]'))i(n);new MutationObserver(n=>{for(const C of n)if(C.type==="childList")for(const r of C.addedNodes)r.tagName==="LINK"&&r.rel==="modulepreload"&&i(r)}).observe(document,{childList:!0,subtree:!0});function I(n){const C={};return n.integrity&&(C.integrity=n.integrity),n.referrerPolicy&&(C.referrerPolicy=n.referrerPolicy),n.crossOrigin==="use-credentials"?C.credentials="include":n.crossOrigin==="anonymous"?C.credentials="omit":C.credentials="same-origin",C}function i(n){if(n.ep)return;n.ep=!0;const C=I(n);fetch(n.href,C)}})();var ZI=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function jh(g){return g&&g.__esModule&&Object.prototype.hasOwnProperty.call(g,"default")?g.default:g}function TL(g){if(g.__esModule)return g;var e=g.default;if(typeof e=="function"){var I=function i(){return this instanceof i?Reflect.construct(e,arguments,this.constructor):e.apply(this,arguments)};I.prototype=e.prototype}else I={};return Object.defineProperty(I,"__esModule",{value:!0}),Object.keys(g).forEach(function(i){var n=Object.getOwnPropertyDescriptor(g,i);Object.defineProperty(I,i,n.get?n:{enumerable:!0,get:function(){return g[i]}})}),I}var Sue={exports:{}},hT={},wue={exports:{}},Bg={};/** +var VNe=Object.defineProperty;var RNe=(e,g,I)=>g in e?VNe(e,g,{enumerable:!0,configurable:!0,writable:!0,value:I}):e[g]=I;var lu=(e,g,I)=>(RNe(e,typeof g!="symbol"?g+"":g,I),I);function WNe(e,g){for(var I=0;Ii[n]})}}}return Object.freeze(Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}))}(function(){const g=document.createElement("link").relList;if(g&&g.supports&&g.supports("modulepreload"))return;for(const n of document.querySelectorAll('link[rel="modulepreload"]'))i(n);new MutationObserver(n=>{for(const C of n)if(C.type==="childList")for(const r of C.addedNodes)r.tagName==="LINK"&&r.rel==="modulepreload"&&i(r)}).observe(document,{childList:!0,subtree:!0});function I(n){const C={};return n.integrity&&(C.integrity=n.integrity),n.referrerPolicy&&(C.referrerPolicy=n.referrerPolicy),n.crossOrigin==="use-credentials"?C.credentials="include":n.crossOrigin==="anonymous"?C.credentials="omit":C.credentials="same-origin",C}function i(n){if(n.ep)return;n.ep=!0;const C=I(n);fetch(n.href,C)}})();var bI=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Fc(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function $O(e){if(e.__esModule)return e;var g=e.default;if(typeof g=="function"){var I=function i(){return this instanceof i?Reflect.construct(g,arguments,this.constructor):g.apply(this,arguments)};I.prototype=g.prototype}else I={};return Object.defineProperty(I,"__esModule",{value:!0}),Object.keys(e).forEach(function(i){var n=Object.getOwnPropertyDescriptor(e,i);Object.defineProperty(I,i,n.get?n:{enumerable:!0,get:function(){return e[i]}})}),I}var Ece={exports:{}},SH={},Mce={exports:{}},mg={};/** * @license React * react.production.min.js * @@ -6,7 +6,7 @@ var xke=Object.defineProperty;var Dke=(g,e,I)=>e in g?xke(g,e,{enumerable:!0,con * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - */var wS=Symbol.for("react.element"),Eke=Symbol.for("react.portal"),Mke=Symbol.for("react.fragment"),zke=Symbol.for("react.strict_mode"),Pke=Symbol.for("react.profiler"),Jke=Symbol.for("react.provider"),Oke=Symbol.for("react.context"),Lke=Symbol.for("react.forward_ref"),_ke=Symbol.for("react.suspense"),Uke=Symbol.for("react.memo"),Qke=Symbol.for("react.lazy"),J8=Symbol.iterator;function jke(g){return g===null||typeof g!="object"?null:(g=J8&&g[J8]||g["@@iterator"],typeof g=="function"?g:null)}var Vue={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},Rue=Object.assign,Wue={};function W0(g,e,I){this.props=g,this.context=e,this.refs=Wue,this.updater=I||Vue}W0.prototype.isReactComponent={};W0.prototype.setState=function(g,e){if(typeof g!="object"&&typeof g!="function"&&g!=null)throw Error("setState(...): takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,g,e,"setState")};W0.prototype.forceUpdate=function(g){this.updater.enqueueForceUpdate(this,g,"forceUpdate")};function Xue(){}Xue.prototype=W0.prototype;function NL(g,e,I){this.props=g,this.context=e,this.refs=Wue,this.updater=I||Vue}var kL=NL.prototype=new Xue;kL.constructor=NL;Rue(kL,W0.prototype);kL.isPureReactComponent=!0;var O8=Array.isArray,Hue=Object.prototype.hasOwnProperty,YL={current:null},Tue={key:!0,ref:!0,__self:!0,__source:!0};function Nue(g,e,I){var i,n={},C=null,r=null;if(e!=null)for(i in e.ref!==void 0&&(r=e.ref),e.key!==void 0&&(C=""+e.key),e)Hue.call(e,i)&&!Tue.hasOwnProperty(i)&&(n[i]=e[i]);var o=arguments.length-2;if(o===1)n.children=I;else if(1e in g?xke(g,e,{enumerable:!0,con * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - */var gYe=Ie,IYe=Symbol.for("react.element"),iYe=Symbol.for("react.fragment"),nYe=Object.prototype.hasOwnProperty,CYe=gYe.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,rYe={key:!0,ref:!0,__self:!0,__source:!0};function kue(g,e,I){var i,n={},C=null,r=null;I!==void 0&&(C=""+I),e.key!==void 0&&(C=""+e.key),e.ref!==void 0&&(r=e.ref);for(i in e)nYe.call(e,i)&&!rYe.hasOwnProperty(i)&&(n[i]=e[i]);if(g&&g.defaultProps)for(i in e=g.defaultProps,e)n[i]===void 0&&(n[i]=e[i]);return{$$typeof:IYe,type:g,key:C,ref:r,props:n,_owner:CYe.current}}hT.Fragment=iYe;hT.jsx=kue;hT.jsxs=kue;Sue.exports=hT;var tt=Sue.exports,CE={},Yue={exports:{}},Gr={},Kue={exports:{}},xue={};/** + */var ONe=Ie,_Ne=Symbol.for("react.element"),LNe=Symbol.for("react.fragment"),UNe=Object.prototype.hasOwnProperty,QNe=ONe.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,jNe={key:!0,ref:!0,__self:!0,__source:!0};function Qce(e,g,I){var i,n={},C=null,r=null;I!==void 0&&(C=""+I),g.key!==void 0&&(C=""+g.key),g.ref!==void 0&&(r=g.ref);for(i in g)UNe.call(g,i)&&!jNe.hasOwnProperty(i)&&(n[i]=g[i]);if(e&&e.defaultProps)for(i in g=e.defaultProps,g)n[i]===void 0&&(n[i]=g[i]);return{$$typeof:_Ne,type:e,key:C,ref:r,props:n,_owner:QNe.current}}SH.Fragment=LNe;SH.jsx=Qce;SH.jsxs=Qce;Ece.exports=SH;var tt=Ece.exports,hF={},jce={exports:{}},dr={},$ce={exports:{}},qce={};/** * @license React * scheduler.production.min.js * @@ -22,7 +22,7 @@ var xke=Object.defineProperty;var Dke=(g,e,I)=>e in g?xke(g,e,{enumerable:!0,con * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - */(function(g){function e(F,_){var J=F.length;F.push(_);e:for(;0>>1,q=F[te];if(0>>1;te<$;){var j=2*(te+1)-1,ee=F[j],Q=j+1,ne=F[Q];if(0>n(ee,J))Qn(ne,ee)?(F[te]=ne,F[Q]=J,te=Q):(F[te]=ee,F[j]=J,te=j);else if(Qn(ne,J))F[te]=ne,F[Q]=J,te=Q;else break e}}return _}function n(F,_){var J=F.sortIndex-_.sortIndex;return J!==0?J:F.id-_.id}if(typeof performance=="object"&&typeof performance.now=="function"){var C=performance;g.unstable_now=function(){return C.now()}}else{var r=Date,o=r.now();g.unstable_now=function(){return r.now()-o}}var A=[],s=[],a=1,l=null,c=3,u=!1,d=!1,h=!1,m=typeof setTimeout=="function"?setTimeout:null,f=typeof clearTimeout=="function"?clearTimeout:null,b=typeof setImmediate<"u"?setImmediate:null;typeof navigator<"u"&&navigator.scheduling!==void 0&&navigator.scheduling.isInputPending!==void 0&&navigator.scheduling.isInputPending.bind(navigator.scheduling);function p(F){for(var _=I(s);_!==null;){if(_.callback===null)i(s);else if(_.startTime<=F)i(s),_.sortIndex=_.expirationTime,e(A,_);else break;_=I(s)}}function y(F){if(h=!1,p(F),!d)if(I(A)!==null)d=!0,D(Z);else{var _=I(s);_!==null&&Y(y,_.startTime-F)}}function Z(F,_){d=!1,h&&(h=!1,f(B),B=-1),u=!0;var J=c;try{for(p(_),l=I(A);l!==null&&(!(l.expirationTime>_)||F&&!S());){var te=l.callback;if(typeof te=="function"){l.callback=null,c=l.priorityLevel;var q=te(l.expirationTime<=_);_=g.unstable_now(),typeof q=="function"?l.callback=q:l===I(A)&&i(A),p(_)}else i(A);l=I(A)}if(l!==null)var $=!0;else{var j=I(s);j!==null&&Y(y,j.startTime-_),$=!1}return $}finally{l=null,c=J,u=!1}}var v=!1,G=null,B=-1,w=5,R=-1;function S(){return!(g.unstable_now()-RF||125te?(F.sortIndex=J,e(s,F),I(A)===null&&F===I(s)&&(h?(f(B),B=-1):h=!0,Y(y,J-te))):(F.sortIndex=q,e(A,F),d||u||(d=!0,D(Z))),F},g.unstable_shouldYield=S,g.unstable_wrapCallback=function(F){var _=c;return function(){var J=c;c=_;try{return F.apply(this,arguments)}finally{c=J}}}})(xue);Kue.exports=xue;var oYe=Kue.exports;/** + */(function(e){function g(E,O){var J=E.length;E.push(O);e:for(;0>>1,q=E[ee];if(0>>1;ee<$;){var j=2*(ee+1)-1,te=E[j],U=j+1,ie=E[U];if(0>n(te,J))Un(ie,te)?(E[ee]=ie,E[U]=J,ee=U):(E[ee]=te,E[j]=J,ee=j);else if(Un(ie,J))E[ee]=ie,E[U]=J,ee=U;else break e}}return O}function n(E,O){var J=E.sortIndex-O.sortIndex;return J!==0?J:E.id-O.id}if(typeof performance=="object"&&typeof performance.now=="function"){var C=performance;e.unstable_now=function(){return C.now()}}else{var r=Date,o=r.now();e.unstable_now=function(){return r.now()-o}}var A=[],s=[],a=1,l=null,c=3,u=!1,d=!1,h=!1,m=typeof setTimeout=="function"?setTimeout:null,f=typeof clearTimeout=="function"?clearTimeout:null,b=typeof setImmediate<"u"?setImmediate:null;typeof navigator<"u"&&navigator.scheduling!==void 0&&navigator.scheduling.isInputPending!==void 0&&navigator.scheduling.isInputPending.bind(navigator.scheduling);function p(E){for(var O=I(s);O!==null;){if(O.callback===null)i(s);else if(O.startTime<=E)i(s),O.sortIndex=O.expirationTime,g(A,O);else break;O=I(s)}}function y(E){if(h=!1,p(E),!d)if(I(A)!==null)d=!0,Y(Z);else{var O=I(s);O!==null&&D(y,O.startTime-E)}}function Z(E,O){d=!1,h&&(h=!1,f(v),v=-1),u=!0;var J=c;try{for(p(O),l=I(A);l!==null&&(!(l.expirationTime>O)||E&&!S());){var ee=l.callback;if(typeof ee=="function"){l.callback=null,c=l.priorityLevel;var q=ee(l.expirationTime<=O);O=e.unstable_now(),typeof q=="function"?l.callback=q:l===I(A)&&i(A),p(O)}else i(A);l=I(A)}if(l!==null)var $=!0;else{var j=I(s);j!==null&&D(y,j.startTime-O),$=!1}return $}finally{l=null,c=J,u=!1}}var B=!1,G=null,v=-1,w=5,V=-1;function S(){return!(e.unstable_now()-VE||125ee?(E.sortIndex=J,g(s,E),I(A)===null&&E===I(s)&&(h?(f(v),v=-1):h=!0,D(y,J-ee))):(E.sortIndex=q,g(A,E),d||u||(d=!0,Y(Z))),E},e.unstable_shouldYield=S,e.unstable_wrapCallback=function(E){var O=c;return function(){var J=c;c=O;try{return E.apply(this,arguments)}finally{c=J}}}})(qce);$ce.exports=qce;var $Ne=$ce.exports;/** * @license React * react-dom.production.min.js * @@ -30,99 +30,190 @@ var xke=Object.defineProperty;var Dke=(g,e,I)=>e in g?xke(g,e,{enumerable:!0,con * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - */var Due=Ie,br=oYe;function at(g){for(var e="https://reactjs.org/docs/error-decoder.html?invariant="+g,I=1;I"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),rE=Object.prototype.hasOwnProperty,AYe=/^[:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD][:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\-.0-9\u00B7\u0300-\u036F\u203F-\u2040]*$/,_8={},U8={};function aYe(g){return rE.call(U8,g)?!0:rE.call(_8,g)?!1:AYe.test(g)?U8[g]=!0:(_8[g]=!0,!1)}function sYe(g,e,I,i){if(I!==null&&I.type===0)return!1;switch(typeof e){case"function":case"symbol":return!0;case"boolean":return i?!1:I!==null?!I.acceptsBooleans:(g=g.toLowerCase().slice(0,5),g!=="data-"&&g!=="aria-");default:return!1}}function lYe(g,e,I,i){if(e===null||typeof e>"u"||sYe(g,e,I,i))return!0;if(i)return!1;if(I!==null)switch(I.type){case 3:return!e;case 4:return e===!1;case 5:return isNaN(e);case 6:return isNaN(e)||1>e}return!1}function cC(g,e,I,i,n,C,r){this.acceptsBooleans=e===2||e===3||e===4,this.attributeName=i,this.attributeNamespace=n,this.mustUseProperty=I,this.propertyName=g,this.type=e,this.sanitizeURL=C,this.removeEmptyString=r}var ln={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(g){ln[g]=new cC(g,0,!1,g,null,!1,!1)});[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(g){var e=g[0];ln[e]=new cC(e,1,!1,g[1],null,!1,!1)});["contentEditable","draggable","spellCheck","value"].forEach(function(g){ln[g]=new cC(g,2,!1,g.toLowerCase(),null,!1,!1)});["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(g){ln[g]=new cC(g,2,!1,g,null,!1,!1)});"allowFullScreen async autoFocus autoPlay controls default defer disabled disablePictureInPicture disableRemotePlayback formNoValidate hidden loop noModule noValidate open playsInline readOnly required reversed scoped seamless itemScope".split(" ").forEach(function(g){ln[g]=new cC(g,3,!1,g.toLowerCase(),null,!1,!1)});["checked","multiple","muted","selected"].forEach(function(g){ln[g]=new cC(g,3,!0,g,null,!1,!1)});["capture","download"].forEach(function(g){ln[g]=new cC(g,4,!1,g,null,!1,!1)});["cols","rows","size","span"].forEach(function(g){ln[g]=new cC(g,6,!1,g,null,!1,!1)});["rowSpan","start"].forEach(function(g){ln[g]=new cC(g,5,!1,g.toLowerCase(),null,!1,!1)});var xL=/[\-:]([a-z])/g;function DL(g){return g[1].toUpperCase()}"accent-height alignment-baseline arabic-form baseline-shift cap-height clip-path clip-rule color-interpolation color-interpolation-filters color-profile color-rendering dominant-baseline enable-background fill-opacity fill-rule flood-color flood-opacity font-family font-size font-size-adjust font-stretch font-style font-variant font-weight glyph-name glyph-orientation-horizontal glyph-orientation-vertical horiz-adv-x horiz-origin-x image-rendering letter-spacing lighting-color marker-end marker-mid marker-start overline-position overline-thickness paint-order panose-1 pointer-events rendering-intent shape-rendering stop-color stop-opacity strikethrough-position strikethrough-thickness stroke-dasharray stroke-dashoffset stroke-linecap stroke-linejoin stroke-miterlimit stroke-opacity stroke-width text-anchor text-decoration text-rendering underline-position underline-thickness unicode-bidi unicode-range units-per-em v-alphabetic v-hanging v-ideographic v-mathematical vector-effect vert-adv-y vert-origin-x vert-origin-y word-spacing writing-mode xmlns:xlink x-height".split(" ").forEach(function(g){var e=g.replace(xL,DL);ln[e]=new cC(e,1,!1,g,null,!1,!1)});"xlink:actuate xlink:arcrole xlink:role xlink:show xlink:title xlink:type".split(" ").forEach(function(g){var e=g.replace(xL,DL);ln[e]=new cC(e,1,!1,g,"http://www.w3.org/1999/xlink",!1,!1)});["xml:base","xml:lang","xml:space"].forEach(function(g){var e=g.replace(xL,DL);ln[e]=new cC(e,1,!1,g,"http://www.w3.org/XML/1998/namespace",!1,!1)});["tabIndex","crossOrigin"].forEach(function(g){ln[g]=new cC(g,1,!1,g.toLowerCase(),null,!1,!1)});ln.xlinkHref=new cC("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1);["src","href","action","formAction"].forEach(function(g){ln[g]=new cC(g,1,!1,g.toLowerCase(),null,!0,!0)});function FL(g,e,I,i){var n=ln.hasOwnProperty(e)?ln[e]:null;(n!==null?n.type!==0:i||!(2"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),mF=Object.prototype.hasOwnProperty,qNe=/^[:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD][:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\-.0-9\u00B7\u0300-\u036F\u203F-\u2040]*$/,d8={},h8={};function eke(e){return mF.call(h8,e)?!0:mF.call(d8,e)?!1:qNe.test(e)?h8[e]=!0:(d8[e]=!0,!1)}function tke(e,g,I,i){if(I!==null&&I.type===0)return!1;switch(typeof g){case"function":case"symbol":return!0;case"boolean":return i?!1:I!==null?!I.acceptsBooleans:(e=e.toLowerCase().slice(0,5),e!=="data-"&&e!=="aria-");default:return!1}}function gke(e,g,I,i){if(g===null||typeof g>"u"||tke(e,g,I,i))return!0;if(i)return!1;if(I!==null)switch(I.type){case 3:return!g;case 4:return g===!1;case 5:return isNaN(g);case 6:return isNaN(g)||1>g}return!1}function aC(e,g,I,i,n,C,r){this.acceptsBooleans=g===2||g===3||g===4,this.attributeName=i,this.attributeNamespace=n,this.mustUseProperty=I,this.propertyName=e,this.type=g,this.sanitizeURL=C,this.removeEmptyString=r}var sn={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(e){sn[e]=new aC(e,0,!1,e,null,!1,!1)});[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(e){var g=e[0];sn[g]=new aC(g,1,!1,e[1],null,!1,!1)});["contentEditable","draggable","spellCheck","value"].forEach(function(e){sn[e]=new aC(e,2,!1,e.toLowerCase(),null,!1,!1)});["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(e){sn[e]=new aC(e,2,!1,e,null,!1,!1)});"allowFullScreen async autoFocus autoPlay controls default defer disabled disablePictureInPicture disableRemotePlayback formNoValidate hidden loop noModule noValidate open playsInline readOnly required reversed scoped seamless itemScope".split(" ").forEach(function(e){sn[e]=new aC(e,3,!1,e.toLowerCase(),null,!1,!1)});["checked","multiple","muted","selected"].forEach(function(e){sn[e]=new aC(e,3,!0,e,null,!1,!1)});["capture","download"].forEach(function(e){sn[e]=new aC(e,4,!1,e,null,!1,!1)});["cols","rows","size","span"].forEach(function(e){sn[e]=new aC(e,6,!1,e,null,!1,!1)});["rowSpan","start"].forEach(function(e){sn[e]=new aC(e,5,!1,e.toLowerCase(),null,!1,!1)});var I_=/[\-:]([a-z])/g;function i_(e){return e[1].toUpperCase()}"accent-height alignment-baseline arabic-form baseline-shift cap-height clip-path clip-rule color-interpolation color-interpolation-filters color-profile color-rendering dominant-baseline enable-background fill-opacity fill-rule flood-color flood-opacity font-family font-size font-size-adjust font-stretch font-style font-variant font-weight glyph-name glyph-orientation-horizontal glyph-orientation-vertical horiz-adv-x horiz-origin-x image-rendering letter-spacing lighting-color marker-end marker-mid marker-start overline-position overline-thickness paint-order panose-1 pointer-events rendering-intent shape-rendering stop-color stop-opacity strikethrough-position strikethrough-thickness stroke-dasharray stroke-dashoffset stroke-linecap stroke-linejoin stroke-miterlimit stroke-opacity stroke-width text-anchor text-decoration text-rendering underline-position underline-thickness unicode-bidi unicode-range units-per-em v-alphabetic v-hanging v-ideographic v-mathematical vector-effect vert-adv-y vert-origin-x vert-origin-y word-spacing writing-mode xmlns:xlink x-height".split(" ").forEach(function(e){var g=e.replace(I_,i_);sn[g]=new aC(g,1,!1,e,null,!1,!1)});"xlink:actuate xlink:arcrole xlink:role xlink:show xlink:title xlink:type".split(" ").forEach(function(e){var g=e.replace(I_,i_);sn[g]=new aC(g,1,!1,e,"http://www.w3.org/1999/xlink",!1,!1)});["xml:base","xml:lang","xml:space"].forEach(function(e){var g=e.replace(I_,i_);sn[g]=new aC(g,1,!1,e,"http://www.w3.org/XML/1998/namespace",!1,!1)});["tabIndex","crossOrigin"].forEach(function(e){sn[e]=new aC(e,1,!1,e.toLowerCase(),null,!1,!1)});sn.xlinkHref=new aC("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1);["src","href","action","formAction"].forEach(function(e){sn[e]=new aC(e,1,!1,e.toLowerCase(),null,!0,!0)});function n_(e,g,I,i){var n=sn.hasOwnProperty(g)?sn[g]:null;(n!==null?n.type!==0:i||!(2o||n[r]!==C[o]){var A=` -`+n[r].replace(" at new "," at ");return g.displayName&&A.includes("")&&(A=A.replace("",g.displayName)),A}while(1<=r&&0<=o);break}}}finally{iK=!1,Error.prepareStackTrace=I}return(g=g?g.displayName||g.name:"")?XZ(g):""}function cYe(g){switch(g.tag){case 5:return XZ(g.type);case 16:return XZ("Lazy");case 13:return XZ("Suspense");case 19:return XZ("SuspenseList");case 0:case 2:case 15:return g=nK(g.type,!1),g;case 11:return g=nK(g.type.render,!1),g;case 1:return g=nK(g.type,!0),g;default:return""}}function sE(g){if(g==null)return null;if(typeof g=="function")return g.displayName||g.name||null;if(typeof g=="string")return g;switch(g){case ip:return"Fragment";case Ip:return"Portal";case oE:return"Profiler";case EL:return"StrictMode";case AE:return"Suspense";case aE:return"SuspenseList"}if(typeof g=="object")switch(g.$$typeof){case Mue:return(g.displayName||"Context")+".Consumer";case Eue:return(g._context.displayName||"Context")+".Provider";case ML:var e=g.render;return g=g.displayName,g||(g=e.displayName||e.name||"",g=g!==""?"ForwardRef("+g+")":"ForwardRef"),g;case zL:return e=g.displayName||null,e!==null?e:sE(g.type)||"Memo";case Ql:e=g._payload,g=g._init;try{return sE(g(e))}catch{}}return null}function uYe(g){var e=g.type;switch(g.tag){case 24:return"Cache";case 9:return(e.displayName||"Context")+".Consumer";case 10:return(e._context.displayName||"Context")+".Provider";case 18:return"DehydratedFragment";case 11:return g=e.render,g=g.displayName||g.name||"",e.displayName||(g!==""?"ForwardRef("+g+")":"ForwardRef");case 7:return"Fragment";case 5:return e;case 4:return"Portal";case 3:return"Root";case 6:return"Text";case 16:return sE(e);case 8:return e===EL?"StrictMode":"Mode";case 22:return"Offscreen";case 12:return"Profiler";case 21:return"Scope";case 13:return"Suspense";case 19:return"SuspenseList";case 25:return"TracingMarker";case 1:case 0:case 17:case 2:case 14:case 15:if(typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e}return null}function eu(g){switch(typeof g){case"boolean":case"number":case"string":case"undefined":return g;case"object":return g;default:return""}}function Pue(g){var e=g.type;return(g=g.nodeName)&&g.toLowerCase()==="input"&&(e==="checkbox"||e==="radio")}function dYe(g){var e=Pue(g)?"checked":"value",I=Object.getOwnPropertyDescriptor(g.constructor.prototype,e),i=""+g[e];if(!g.hasOwnProperty(e)&&typeof I<"u"&&typeof I.get=="function"&&typeof I.set=="function"){var n=I.get,C=I.set;return Object.defineProperty(g,e,{configurable:!0,get:function(){return n.call(this)},set:function(r){i=""+r,C.call(this,r)}}),Object.defineProperty(g,e,{enumerable:I.enumerable}),{getValue:function(){return i},setValue:function(r){i=""+r},stopTracking:function(){g._valueTracker=null,delete g[e]}}}}function aV(g){g._valueTracker||(g._valueTracker=dYe(g))}function Jue(g){if(!g)return!1;var e=g._valueTracker;if(!e)return!0;var I=e.getValue(),i="";return g&&(i=Pue(g)?g.checked?"true":"false":g.value),g=i,g!==I?(e.setValue(g),!0):!1}function nX(g){if(g=g||(typeof document<"u"?document:void 0),typeof g>"u")return null;try{return g.activeElement||g.body}catch{return g.body}}function lE(g,e){var I=e.checked;return MI({},e,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:I??g._wrapperState.initialChecked})}function j8(g,e){var I=e.defaultValue==null?"":e.defaultValue,i=e.checked!=null?e.checked:e.defaultChecked;I=eu(e.value!=null?e.value:I),g._wrapperState={initialChecked:i,initialValue:I,controlled:e.type==="checkbox"||e.type==="radio"?e.checked!=null:e.value!=null}}function Oue(g,e){e=e.checked,e!=null&&FL(g,"checked",e,!1)}function cE(g,e){Oue(g,e);var I=eu(e.value),i=e.type;if(I!=null)i==="number"?(I===0&&g.value===""||g.value!=I)&&(g.value=""+I):g.value!==""+I&&(g.value=""+I);else if(i==="submit"||i==="reset"){g.removeAttribute("value");return}e.hasOwnProperty("value")?uE(g,e.type,I):e.hasOwnProperty("defaultValue")&&uE(g,e.type,eu(e.defaultValue)),e.checked==null&&e.defaultChecked!=null&&(g.defaultChecked=!!e.defaultChecked)}function $8(g,e,I){if(e.hasOwnProperty("value")||e.hasOwnProperty("defaultValue")){var i=e.type;if(!(i!=="submit"&&i!=="reset"||e.value!==void 0&&e.value!==null))return;e=""+g._wrapperState.initialValue,I||e===g.value||(g.value=e),g.defaultValue=e}I=g.name,I!==""&&(g.name=""),g.defaultChecked=!!g._wrapperState.initialChecked,I!==""&&(g.name=I)}function uE(g,e,I){(e!=="number"||nX(g.ownerDocument)!==g)&&(I==null?g.defaultValue=""+g._wrapperState.initialValue:g.defaultValue!==""+I&&(g.defaultValue=""+I))}var HZ=Array.isArray;function Rp(g,e,I,i){if(g=g.options,e){e={};for(var n=0;n"+e.valueOf().toString()+"",e=sV.firstChild;g.firstChild;)g.removeChild(g.firstChild);for(;e.firstChild;)g.appendChild(e.firstChild)}});function LB(g,e){if(e){var I=g.firstChild;if(I&&I===g.lastChild&&I.nodeType===3){I.nodeValue=e;return}}g.textContent=e}var YG={animationIterationCount:!0,aspectRatio:!0,borderImageOutset:!0,borderImageSlice:!0,borderImageWidth:!0,boxFlex:!0,boxFlexGroup:!0,boxOrdinalGroup:!0,columnCount:!0,columns:!0,flex:!0,flexGrow:!0,flexPositive:!0,flexShrink:!0,flexNegative:!0,flexOrder:!0,gridArea:!0,gridRow:!0,gridRowEnd:!0,gridRowSpan:!0,gridRowStart:!0,gridColumn:!0,gridColumnEnd:!0,gridColumnSpan:!0,gridColumnStart:!0,fontWeight:!0,lineClamp:!0,lineHeight:!0,opacity:!0,order:!0,orphans:!0,tabSize:!0,widows:!0,zIndex:!0,zoom:!0,fillOpacity:!0,floodOpacity:!0,stopOpacity:!0,strokeDasharray:!0,strokeDashoffset:!0,strokeMiterlimit:!0,strokeOpacity:!0,strokeWidth:!0},hYe=["Webkit","ms","Moz","O"];Object.keys(YG).forEach(function(g){hYe.forEach(function(e){e=e+g.charAt(0).toUpperCase()+g.substring(1),YG[e]=YG[g]})});function Que(g,e,I){return e==null||typeof e=="boolean"||e===""?"":I||typeof e!="number"||e===0||YG.hasOwnProperty(g)&&YG[g]?(""+e).trim():e+"px"}function jue(g,e){g=g.style;for(var I in e)if(e.hasOwnProperty(I)){var i=I.indexOf("--")===0,n=Que(I,e[I],i);I==="float"&&(I="cssFloat"),i?g.setProperty(I,n):g[I]=n}}var mYe=MI({menuitem:!0},{area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,keygen:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0});function mE(g,e){if(e){if(mYe[g]&&(e.children!=null||e.dangerouslySetInnerHTML!=null))throw Error(at(137,g));if(e.dangerouslySetInnerHTML!=null){if(e.children!=null)throw Error(at(60));if(typeof e.dangerouslySetInnerHTML!="object"||!("__html"in e.dangerouslySetInnerHTML))throw Error(at(61))}if(e.style!=null&&typeof e.style!="object")throw Error(at(62))}}function fE(g,e){if(g.indexOf("-")===-1)return typeof e.is=="string";switch(g){case"annotation-xml":case"color-profile":case"font-face":case"font-face-src":case"font-face-uri":case"font-face-format":case"font-face-name":case"missing-glyph":return!1;default:return!0}}var pE=null;function PL(g){return g=g.target||g.srcElement||window,g.correspondingUseElement&&(g=g.correspondingUseElement),g.nodeType===3?g.parentNode:g}var bE=null,Wp=null,Xp=null;function t6(g){if(g=WS(g)){if(typeof bE!="function")throw Error(at(280));var e=g.stateNode;e&&(e=yT(e),bE(g.stateNode,g.type,e))}}function $ue(g){Wp?Xp?Xp.push(g):Xp=[g]:Wp=g}function que(){if(Wp){var g=Wp,e=Xp;if(Xp=Wp=null,t6(g),e)for(g=0;g>>=0,g===0?32:31-(VYe(g)/RYe|0)|0}var lV=64,cV=4194304;function TZ(g){switch(g&-g){case 1:return 1;case 2:return 2;case 4:return 4;case 8:return 8;case 16:return 16;case 32:return 32;case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:return g&4194240;case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:return g&130023424;case 134217728:return 134217728;case 268435456:return 268435456;case 536870912:return 536870912;case 1073741824:return 1073741824;default:return g}}function AX(g,e){var I=g.pendingLanes;if(I===0)return 0;var i=0,n=g.suspendedLanes,C=g.pingedLanes,r=I&268435455;if(r!==0){var o=r&~n;o!==0?i=TZ(o):(C&=r,C!==0&&(i=TZ(C)))}else r=I&~n,r!==0?i=TZ(r):C!==0&&(i=TZ(C));if(i===0)return 0;if(e!==0&&e!==i&&!(e&n)&&(n=i&-i,C=e&-e,n>=C||n===16&&(C&4194240)!==0))return e;if(i&4&&(i|=I&16),e=g.entangledLanes,e!==0)for(g=g.entanglements,e&=i;0I;I++)e.push(g);return e}function VS(g,e,I){g.pendingLanes|=e,e!==536870912&&(g.suspendedLanes=0,g.pingedLanes=0),g=g.eventTimes,e=31-iA(e),g[e]=I}function TYe(g,e){var I=g.pendingLanes&~e;g.pendingLanes=e,g.suspendedLanes=0,g.pingedLanes=0,g.expiredLanes&=e,g.mutableReadLanes&=e,g.entangledLanes&=e,e=g.entanglements;var i=g.eventTimes;for(g=g.expirationTimes;0=xG),a6=String.fromCharCode(32),s6=!1;function pde(g,e){switch(g){case"keyup":return rKe.indexOf(e.keyCode)!==-1;case"keydown":return e.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function bde(g){return g=g.detail,typeof g=="object"&&"data"in g?g.data:null}var np=!1;function AKe(g,e){switch(g){case"compositionend":return bde(e);case"keypress":return e.which!==32?null:(s6=!0,a6);case"textInput":return g=e.data,g===a6&&s6?null:g;default:return null}}function aKe(g,e){if(np)return g==="compositionend"||!$L&&pde(g,e)?(g=mde(),G1=UL=yc=null,np=!1,g):null;switch(g){case"paste":return null;case"keypress":if(!(e.ctrlKey||e.altKey||e.metaKey)||e.ctrlKey&&e.altKey){if(e.char&&1=e)return{node:I,offset:e-g};g=i}e:{for(;I;){if(I.nextSibling){I=I.nextSibling;break e}I=I.parentNode}I=void 0}I=d6(I)}}function Bde(g,e){return g&&e?g===e?!0:g&&g.nodeType===3?!1:e&&e.nodeType===3?Bde(g,e.parentNode):"contains"in g?g.contains(e):g.compareDocumentPosition?!!(g.compareDocumentPosition(e)&16):!1:!1}function vde(){for(var g=window,e=nX();e instanceof g.HTMLIFrameElement;){try{var I=typeof e.contentWindow.location.href=="string"}catch{I=!1}if(I)g=e.contentWindow;else break;e=nX(g.document)}return e}function qL(g){var e=g&&g.nodeName&&g.nodeName.toLowerCase();return e&&(e==="input"&&(g.type==="text"||g.type==="search"||g.type==="tel"||g.type==="url"||g.type==="password")||e==="textarea"||g.contentEditable==="true")}function pKe(g){var e=vde(),I=g.focusedElem,i=g.selectionRange;if(e!==I&&I&&I.ownerDocument&&Bde(I.ownerDocument.documentElement,I)){if(i!==null&&qL(I)){if(e=i.start,g=i.end,g===void 0&&(g=e),"selectionStart"in I)I.selectionStart=e,I.selectionEnd=Math.min(g,I.value.length);else if(g=(e=I.ownerDocument||document)&&e.defaultView||window,g.getSelection){g=g.getSelection();var n=I.textContent.length,C=Math.min(i.start,n);i=i.end===void 0?C:Math.min(i.end,n),!g.extend&&C>i&&(n=i,i=C,C=n),n=h6(I,C);var r=h6(I,i);n&&r&&(g.rangeCount!==1||g.anchorNode!==n.node||g.anchorOffset!==n.offset||g.focusNode!==r.node||g.focusOffset!==r.offset)&&(e=e.createRange(),e.setStart(n.node,n.offset),g.removeAllRanges(),C>i?(g.addRange(e),g.extend(r.node,r.offset)):(e.setEnd(r.node,r.offset),g.addRange(e)))}}for(e=[],g=I;g=g.parentNode;)g.nodeType===1&&e.push({element:g,left:g.scrollLeft,top:g.scrollTop});for(typeof I.focus=="function"&&I.focus(),I=0;I=document.documentMode,Cp=null,SE=null,FG=null,wE=!1;function m6(g,e,I){var i=I.window===I?I.document:I.nodeType===9?I:I.ownerDocument;wE||Cp==null||Cp!==nX(i)||(i=Cp,"selectionStart"in i&&qL(i)?i={start:i.selectionStart,end:i.selectionEnd}:(i=(i.ownerDocument&&i.ownerDocument.defaultView||window).getSelection(),i={anchorNode:i.anchorNode,anchorOffset:i.anchorOffset,focusNode:i.focusNode,focusOffset:i.focusOffset}),FG&&qB(FG,i)||(FG=i,i=lX(SE,"onSelect"),0Ap||(g.current=TE[Ap],TE[Ap]=null,Ap--)}function aI(g,e){Ap++,TE[Ap]=g.current,g.current=e}var tu={},Tn=Au(tu),NC=Au(!1),jd=tu;function db(g,e){var I=g.type.contextTypes;if(!I)return tu;var i=g.stateNode;if(i&&i.__reactInternalMemoizedUnmaskedChildContext===e)return i.__reactInternalMemoizedMaskedChildContext;var n={},C;for(C in I)n[C]=e[C];return i&&(g=g.stateNode,g.__reactInternalMemoizedUnmaskedChildContext=e,g.__reactInternalMemoizedMaskedChildContext=n),n}function kC(g){return g=g.childContextTypes,g!=null}function uX(){GI(NC),GI(Tn)}function B6(g,e,I){if(Tn.current!==tu)throw Error(at(168));aI(Tn,e),aI(NC,I)}function Nde(g,e,I){var i=g.stateNode;if(e=e.childContextTypes,typeof i.getChildContext!="function")return I;i=i.getChildContext();for(var n in i)if(!(n in e))throw Error(at(108,uYe(g)||"Unknown",n));return MI({},I,i)}function dX(g){return g=(g=g.stateNode)&&g.__reactInternalMemoizedMergedChildContext||tu,jd=Tn.current,aI(Tn,g),aI(NC,NC.current),!0}function v6(g,e,I){var i=g.stateNode;if(!i)throw Error(at(169));I?(g=Nde(g,e,jd),i.__reactInternalMemoizedMergedChildContext=g,GI(NC),GI(Tn),aI(Tn,g)):GI(NC),aI(NC,I)}var ns=null,ZT=!1,pK=!1;function kde(g){ns===null?ns=[g]:ns.push(g)}function XKe(g){ZT=!0,kde(g)}function au(){if(!pK&&ns!==null){pK=!0;var g=0,e=_g;try{var I=ns;for(_g=1;g>=r,n-=r,hs=1<<32-iA(e)+n|I<B?(w=G,G=null):w=G.sibling;var R=c(f,G,p[B],y);if(R===null){G===null&&(G=w);break}g&&G&&R.alternate===null&&e(f,G),b=C(R,b,B),v===null?Z=R:v.sibling=R,v=R,G=w}if(B===p.length)return I(f,G),XI&&Uu(f,B),Z;if(G===null){for(;BB?(w=G,G=null):w=G.sibling;var S=c(f,G,R.value,y);if(S===null){G===null&&(G=w);break}g&&G&&S.alternate===null&&e(f,G),b=C(S,b,B),v===null?Z=S:v.sibling=S,v=S,G=w}if(R.done)return I(f,G),XI&&Uu(f,B),Z;if(G===null){for(;!R.done;B++,R=p.next())R=l(f,R.value,y),R!==null&&(b=C(R,b,B),v===null?Z=R:v.sibling=R,v=R);return XI&&Uu(f,B),Z}for(G=i(f,G);!R.done;B++,R=p.next())R=u(G,f,B,R.value,y),R!==null&&(g&&R.alternate!==null&&G.delete(R.key===null?B:R.key),b=C(R,b,B),v===null?Z=R:v.sibling=R,v=R);return g&&G.forEach(function(X){return e(f,X)}),XI&&Uu(f,B),Z}function m(f,b,p,y){if(typeof p=="object"&&p!==null&&p.type===ip&&p.key===null&&(p=p.props.children),typeof p=="object"&&p!==null){switch(p.$$typeof){case AV:e:{for(var Z=p.key,v=b;v!==null;){if(v.key===Z){if(Z=p.type,Z===ip){if(v.tag===7){I(f,v.sibling),b=n(v,p.props.children),b.return=f,f=b;break e}}else if(v.elementType===Z||typeof Z=="object"&&Z!==null&&Z.$$typeof===Ql&&H6(Z)===v.type){I(f,v.sibling),b=n(v,p.props),b.ref=Hy(f,v,p),b.return=f,f=b;break e}I(f,v);break}else e(f,v);v=v.sibling}p.type===ip?(b=Wd(p.props.children,f.mode,y,p.key),b.return=f,f=b):(y=X1(p.type,p.key,p.props,null,f.mode,y),y.ref=Hy(f,b,p),y.return=f,f=y)}return r(f);case Ip:e:{for(v=p.key;b!==null;){if(b.key===v)if(b.tag===4&&b.stateNode.containerInfo===p.containerInfo&&b.stateNode.implementation===p.implementation){I(f,b.sibling),b=n(b,p.children||[]),b.return=f,f=b;break e}else{I(f,b);break}else e(f,b);b=b.sibling}b=wK(p,f.mode,y),b.return=f,f=b}return r(f);case Ql:return v=p._init,m(f,b,v(p._payload),y)}if(HZ(p))return d(f,b,p,y);if(wy(p))return h(f,b,p,y);bV(f,p)}return typeof p=="string"&&p!==""||typeof p=="number"?(p=""+p,b!==null&&b.tag===6?(I(f,b.sibling),b=n(b,p),b.return=f,f=b):(I(f,b),b=SK(p,f.mode,y),b.return=f,f=b),r(f)):I(f,b)}return m}var mb=zde(!0),Pde=zde(!1),XS={},ua=Au(XS),Iv=Au(XS),iv=Au(XS);function dd(g){if(g===XS)throw Error(at(174));return g}function o_(g,e){switch(aI(iv,e),aI(Iv,g),aI(ua,XS),g=e.nodeType,g){case 9:case 11:e=(e=e.documentElement)?e.namespaceURI:hE(null,"");break;default:g=g===8?e.parentNode:e,e=g.namespaceURI||null,g=g.tagName,e=hE(e,g)}GI(ua),aI(ua,e)}function fb(){GI(ua),GI(Iv),GI(iv)}function Jde(g){dd(iv.current);var e=dd(ua.current),I=hE(e,g.type);e!==I&&(aI(Iv,g),aI(ua,I))}function A_(g){Iv.current===g&&(GI(ua),GI(Iv))}var xI=Au(0);function yX(g){for(var e=g;e!==null;){if(e.tag===13){var I=e.memoizedState;if(I!==null&&(I=I.dehydrated,I===null||I.data==="$?"||I.data==="$!"))return e}else if(e.tag===19&&e.memoizedProps.revealOrder!==void 0){if(e.flags&128)return e}else if(e.child!==null){e.child.return=e,e=e.child;continue}if(e===g)break;for(;e.sibling===null;){if(e.return===null||e.return===g)return null;e=e.return}e.sibling.return=e.return,e=e.sibling}return null}var bK=[];function a_(){for(var g=0;gI?I:4,g(!0);var i=yK.transition;yK.transition={};try{g(!1),e()}finally{_g=I,yK.transition=i}}function rhe(){return ro().memoizedState}function kKe(g,e,I){var i=Ec(g);if(I={lane:i,action:I,hasEagerState:!1,eagerState:null,next:null},ohe(g))Ahe(e,I);else if(I=Dde(g,e,I,i),I!==null){var n=CC();nA(I,g,i,n),ahe(I,e,i)}}function YKe(g,e,I){var i=Ec(g),n={lane:i,action:I,hasEagerState:!1,eagerState:null,next:null};if(ohe(g))Ahe(e,n);else{var C=g.alternate;if(g.lanes===0&&(C===null||C.lanes===0)&&(C=e.lastRenderedReducer,C!==null))try{var r=e.lastRenderedState,o=C(r,I);if(n.hasEagerState=!0,n.eagerState=o,cA(o,r)){var A=e.interleaved;A===null?(n.next=n,C_(e)):(n.next=A.next,A.next=n),e.interleaved=n;return}}catch{}finally{}I=Dde(g,e,n,i),I!==null&&(n=CC(),nA(I,g,i,n),ahe(I,e,i))}}function ohe(g){var e=g.alternate;return g===EI||e!==null&&e===EI}function Ahe(g,e){EG=ZX=!0;var I=g.pending;I===null?e.next=e:(e.next=I.next,I.next=e),g.pending=e}function ahe(g,e,I){if(I&4194240){var i=e.lanes;i&=g.pendingLanes,I|=i,e.lanes=I,OL(g,I)}}var GX={readContext:Co,useCallback:mn,useContext:mn,useEffect:mn,useImperativeHandle:mn,useInsertionEffect:mn,useLayoutEffect:mn,useMemo:mn,useReducer:mn,useRef:mn,useState:mn,useDebugValue:mn,useDeferredValue:mn,useTransition:mn,useMutableSource:mn,useSyncExternalStore:mn,useId:mn,unstable_isNewReconciler:!1},KKe={readContext:Co,useCallback:function(g,e){return DA().memoizedState=[g,e===void 0?null:e],g},useContext:Co,useEffect:N6,useImperativeHandle:function(g,e,I){return I=I!=null?I.concat([g]):null,w1(4194308,4,ghe.bind(null,e,g),I)},useLayoutEffect:function(g,e){return w1(4194308,4,g,e)},useInsertionEffect:function(g,e){return w1(4,2,g,e)},useMemo:function(g,e){var I=DA();return e=e===void 0?null:e,g=g(),I.memoizedState=[g,e],g},useReducer:function(g,e,I){var i=DA();return e=I!==void 0?I(e):e,i.memoizedState=i.baseState=e,g={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:g,lastRenderedState:e},i.queue=g,g=g.dispatch=kKe.bind(null,EI,g),[i.memoizedState,g]},useRef:function(g){var e=DA();return g={current:g},e.memoizedState=g},useState:T6,useDebugValue:d_,useDeferredValue:function(g){return DA().memoizedState=g},useTransition:function(){var g=T6(!1),e=g[0];return g=NKe.bind(null,g[1]),DA().memoizedState=g,[e,g]},useMutableSource:function(){},useSyncExternalStore:function(g,e,I){var i=EI,n=DA();if(XI){if(I===void 0)throw Error(at(407));I=I()}else{if(I=e(),Oi===null)throw Error(at(349));qd&30||_de(i,e,I)}n.memoizedState=I;var C={value:I,getSnapshot:e};return n.queue=C,N6(Qde.bind(null,i,C,g),[g]),i.flags|=2048,rv(9,Ude.bind(null,i,C,I,e),void 0,null),I},useId:function(){var g=DA(),e=Oi.identifierPrefix;if(XI){var I=ms,i=hs;I=(i&~(1<<32-iA(i)-1)).toString(32)+I,e=":"+e+"R"+I,I=nv++,0")&&(A=A.replace("",e.displayName)),A}while(1<=r&&0<=o);break}}}finally{lY=!1,Error.prepareStackTrace=I}return(e=e?e.displayName||e.name:"")?uZ(e):""}function Ike(e){switch(e.tag){case 5:return uZ(e.type);case 16:return uZ("Lazy");case 13:return uZ("Suspense");case 19:return uZ("SuspenseList");case 0:case 2:case 15:return e=cY(e.type,!1),e;case 11:return e=cY(e.type.render,!1),e;case 1:return e=cY(e.type,!0),e;default:return""}}function yF(e){if(e==null)return null;if(typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case kf:return"Fragment";case Nf:return"Portal";case fF:return"Profiler";case C_:return"StrictMode";case pF:return"Suspense";case bF:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case Iue:return(e.displayName||"Context")+".Consumer";case gue:return(e._context.displayName||"Context")+".Provider";case r_:var g=e.render;return e=e.displayName,e||(e=g.displayName||g.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case o_:return g=e.displayName||null,g!==null?g:yF(e.type)||"Memo";case Tl:g=e._payload,e=e._init;try{return yF(e(g))}catch{}}return null}function ike(e){var g=e.type;switch(e.tag){case 24:return"Cache";case 9:return(g.displayName||"Context")+".Consumer";case 10:return(g._context.displayName||"Context")+".Provider";case 18:return"DehydratedFragment";case 11:return e=g.render,e=e.displayName||e.name||"",g.displayName||(e!==""?"ForwardRef("+e+")":"ForwardRef");case 7:return"Fragment";case 5:return g;case 4:return"Portal";case 3:return"Root";case 6:return"Text";case 16:return yF(g);case 8:return g===C_?"StrictMode":"Mode";case 22:return"Offscreen";case 12:return"Profiler";case 21:return"Scope";case 13:return"Suspense";case 19:return"SuspenseList";case 25:return"TracingMarker";case 1:case 0:case 17:case 2:case 14:case 15:if(typeof g=="function")return g.displayName||g.name||null;if(typeof g=="string")return g}return null}function Tc(e){switch(typeof e){case"boolean":case"number":case"string":case"undefined":return e;case"object":return e;default:return""}}function nue(e){var g=e.type;return(e=e.nodeName)&&e.toLowerCase()==="input"&&(g==="checkbox"||g==="radio")}function nke(e){var g=nue(e)?"checked":"value",I=Object.getOwnPropertyDescriptor(e.constructor.prototype,g),i=""+e[g];if(!e.hasOwnProperty(g)&&typeof I<"u"&&typeof I.get=="function"&&typeof I.set=="function"){var n=I.get,C=I.set;return Object.defineProperty(e,g,{configurable:!0,get:function(){return n.call(this)},set:function(r){i=""+r,C.call(this,r)}}),Object.defineProperty(e,g,{enumerable:I.enumerable}),{getValue:function(){return i},setValue:function(r){i=""+r},stopTracking:function(){e._valueTracker=null,delete e[g]}}}}function Xw(e){e._valueTracker||(e._valueTracker=nke(e))}function Cue(e){if(!e)return!1;var g=e._valueTracker;if(!g)return!0;var I=g.getValue(),i="";return e&&(i=nue(e)?e.checked?"true":"false":e.value),e=i,e!==I?(g.setValue(e),!0):!1}function vW(e){if(e=e||(typeof document<"u"?document:void 0),typeof e>"u")return null;try{return e.activeElement||e.body}catch{return e.body}}function ZF(e,g){var I=g.checked;return EI({},g,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:I??e._wrapperState.initialChecked})}function f8(e,g){var I=g.defaultValue==null?"":g.defaultValue,i=g.checked!=null?g.checked:g.defaultChecked;I=Tc(g.value!=null?g.value:I),e._wrapperState={initialChecked:i,initialValue:I,controlled:g.type==="checkbox"||g.type==="radio"?g.checked!=null:g.value!=null}}function rue(e,g){g=g.checked,g!=null&&n_(e,"checked",g,!1)}function GF(e,g){rue(e,g);var I=Tc(g.value),i=g.type;if(I!=null)i==="number"?(I===0&&e.value===""||e.value!=I)&&(e.value=""+I):e.value!==""+I&&(e.value=""+I);else if(i==="submit"||i==="reset"){e.removeAttribute("value");return}g.hasOwnProperty("value")?vF(e,g.type,I):g.hasOwnProperty("defaultValue")&&vF(e,g.type,Tc(g.defaultValue)),g.checked==null&&g.defaultChecked!=null&&(e.defaultChecked=!!g.defaultChecked)}function p8(e,g,I){if(g.hasOwnProperty("value")||g.hasOwnProperty("defaultValue")){var i=g.type;if(!(i!=="submit"&&i!=="reset"||g.value!==void 0&&g.value!==null))return;g=""+e._wrapperState.initialValue,I||g===e.value||(e.value=g),e.defaultValue=g}I=e.name,I!==""&&(e.name=""),e.defaultChecked=!!e._wrapperState.initialChecked,I!==""&&(e.name=I)}function vF(e,g,I){(g!=="number"||vW(e.ownerDocument)!==e)&&(I==null?e.defaultValue=""+e._wrapperState.initialValue:e.defaultValue!==""+I&&(e.defaultValue=""+I))}var dZ=Array.isArray;function Cp(e,g,I,i){if(e=e.options,g){g={};for(var n=0;n"+g.valueOf().toString()+"",g=Hw.firstChild;e.firstChild;)e.removeChild(e.firstChild);for(;g.firstChild;)e.appendChild(g.firstChild)}});function yv(e,g){if(g){var I=e.firstChild;if(I&&I===e.lastChild&&I.nodeType===3){I.nodeValue=g;return}}e.textContent=g}var aG={animationIterationCount:!0,aspectRatio:!0,borderImageOutset:!0,borderImageSlice:!0,borderImageWidth:!0,boxFlex:!0,boxFlexGroup:!0,boxOrdinalGroup:!0,columnCount:!0,columns:!0,flex:!0,flexGrow:!0,flexPositive:!0,flexShrink:!0,flexNegative:!0,flexOrder:!0,gridArea:!0,gridRow:!0,gridRowEnd:!0,gridRowSpan:!0,gridRowStart:!0,gridColumn:!0,gridColumnEnd:!0,gridColumnSpan:!0,gridColumnStart:!0,fontWeight:!0,lineClamp:!0,lineHeight:!0,opacity:!0,order:!0,orphans:!0,tabSize:!0,widows:!0,zIndex:!0,zoom:!0,fillOpacity:!0,floodOpacity:!0,stopOpacity:!0,strokeDasharray:!0,strokeDashoffset:!0,strokeMiterlimit:!0,strokeOpacity:!0,strokeWidth:!0},Cke=["Webkit","ms","Moz","O"];Object.keys(aG).forEach(function(e){Cke.forEach(function(g){g=g+e.charAt(0).toUpperCase()+e.substring(1),aG[g]=aG[e]})});function sue(e,g,I){return g==null||typeof g=="boolean"||g===""?"":I||typeof g!="number"||g===0||aG.hasOwnProperty(e)&&aG[e]?(""+g).trim():g+"px"}function lue(e,g){e=e.style;for(var I in g)if(g.hasOwnProperty(I)){var i=I.indexOf("--")===0,n=sue(I,g[I],i);I==="float"&&(I="cssFloat"),i?e.setProperty(I,n):e[I]=n}}var rke=EI({menuitem:!0},{area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,keygen:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0});function wF(e,g){if(g){if(rke[e]&&(g.children!=null||g.dangerouslySetInnerHTML!=null))throw Error(at(137,e));if(g.dangerouslySetInnerHTML!=null){if(g.children!=null)throw Error(at(60));if(typeof g.dangerouslySetInnerHTML!="object"||!("__html"in g.dangerouslySetInnerHTML))throw Error(at(61))}if(g.style!=null&&typeof g.style!="object")throw Error(at(62))}}function VF(e,g){if(e.indexOf("-")===-1)return typeof g.is=="string";switch(e){case"annotation-xml":case"color-profile":case"font-face":case"font-face-src":case"font-face-uri":case"font-face-format":case"font-face-name":case"missing-glyph":return!1;default:return!0}}var RF=null;function A_(e){return e=e.target||e.srcElement||window,e.correspondingUseElement&&(e=e.correspondingUseElement),e.nodeType===3?e.parentNode:e}var WF=null,rp=null,op=null;function Z8(e){if(e=iS(e)){if(typeof WF!="function")throw Error(at(280));var g=e.stateNode;g&&(g=XH(g),WF(e.stateNode,e.type,g))}}function cue(e){rp?op?op.push(e):op=[e]:rp=e}function uue(){if(rp){var e=rp,g=op;if(op=rp=null,Z8(e),g)for(e=0;e>>=0,e===0?32:31-(fke(e)/pke|0)|0}var Tw=64,Nw=4194304;function hZ(e){switch(e&-e){case 1:return 1;case 2:return 2;case 4:return 4;case 8:return 8;case 16:return 16;case 32:return 32;case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:return e&4194240;case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:return e&130023424;case 134217728:return 134217728;case 268435456:return 268435456;case 536870912:return 536870912;case 1073741824:return 1073741824;default:return e}}function VW(e,g){var I=e.pendingLanes;if(I===0)return 0;var i=0,n=e.suspendedLanes,C=e.pingedLanes,r=I&268435455;if(r!==0){var o=r&~n;o!==0?i=hZ(o):(C&=r,C!==0&&(i=hZ(C)))}else r=I&~n,r!==0?i=hZ(r):C!==0&&(i=hZ(C));if(i===0)return 0;if(g!==0&&g!==i&&!(g&n)&&(n=i&-i,C=g&-g,n>=C||n===16&&(C&4194240)!==0))return g;if(i&4&&(i|=I&16),g=e.entangledLanes,g!==0)for(e=e.entanglements,g&=i;0I;I++)g.push(e);return g}function gS(e,g,I){e.pendingLanes|=g,g!==536870912&&(e.suspendedLanes=0,e.pingedLanes=0),e=e.eventTimes,g=31-Qo(g),e[g]=I}function Gke(e,g){var I=e.pendingLanes&~g;e.pendingLanes=g,e.suspendedLanes=0,e.pingedLanes=0,e.expiredLanes&=g,e.mutableReadLanes&=g,e.entangledLanes&=g,g=e.entanglements;var i=e.eventTimes;for(e=e.expirationTimes;0=lG),X8=String.fromCharCode(32),H8=!1;function Nue(e,g){switch(e){case"keyup":return jke.indexOf(g.keyCode)!==-1;case"keydown":return g.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function kue(e){return e=e.detail,typeof e=="object"&&"data"in e?e.data:null}var Yf=!1;function qke(e,g){switch(e){case"compositionend":return kue(g);case"keypress":return g.which!==32?null:(H8=!0,X8);case"textInput":return e=g.data,e===X8&&H8?null:e;default:return null}}function eYe(e,g){if(Yf)return e==="compositionend"||!m_&&Nue(e,g)?(e=Hue(),LR=u_=ec=null,Yf=!1,e):null;switch(e){case"paste":return null;case"keypress":if(!(g.ctrlKey||g.altKey||g.metaKey)||g.ctrlKey&&g.altKey){if(g.char&&1=g)return{node:I,offset:g-e};e=i}e:{for(;I;){if(I.nextSibling){I=I.nextSibling;break e}I=I.parentNode}I=void 0}I=Y8(I)}}function xue(e,g){return e&&g?e===g?!0:e&&e.nodeType===3?!1:g&&g.nodeType===3?xue(e,g.parentNode):"contains"in e?e.contains(g):e.compareDocumentPosition?!!(e.compareDocumentPosition(g)&16):!1:!1}function Fue(){for(var e=window,g=vW();g instanceof e.HTMLIFrameElement;){try{var I=typeof g.contentWindow.location.href=="string"}catch{I=!1}if(I)e=g.contentWindow;else break;g=vW(e.document)}return g}function f_(e){var g=e&&e.nodeName&&e.nodeName.toLowerCase();return g&&(g==="input"&&(e.type==="text"||e.type==="search"||e.type==="tel"||e.type==="url"||e.type==="password")||g==="textarea"||e.contentEditable==="true")}function AYe(e){var g=Fue(),I=e.focusedElem,i=e.selectionRange;if(g!==I&&I&&I.ownerDocument&&xue(I.ownerDocument.documentElement,I)){if(i!==null&&f_(I)){if(g=i.start,e=i.end,e===void 0&&(e=g),"selectionStart"in I)I.selectionStart=g,I.selectionEnd=Math.min(e,I.value.length);else if(e=(g=I.ownerDocument||document)&&g.defaultView||window,e.getSelection){e=e.getSelection();var n=I.textContent.length,C=Math.min(i.start,n);i=i.end===void 0?C:Math.min(i.end,n),!e.extend&&C>i&&(n=i,i=C,C=n),n=K8(I,C);var r=K8(I,i);n&&r&&(e.rangeCount!==1||e.anchorNode!==n.node||e.anchorOffset!==n.offset||e.focusNode!==r.node||e.focusOffset!==r.offset)&&(g=g.createRange(),g.setStart(n.node,n.offset),e.removeAllRanges(),C>i?(e.addRange(g),e.extend(r.node,r.offset)):(g.setEnd(r.node,r.offset),e.addRange(g)))}}for(g=[],e=I;e=e.parentNode;)e.nodeType===1&&g.push({element:e,left:e.scrollLeft,top:e.scrollTop});for(typeof I.focus=="function"&&I.focus(),I=0;I=document.documentMode,Kf=null,YF=null,uG=null,KF=!1;function D8(e,g,I){var i=I.window===I?I.document:I.nodeType===9?I:I.ownerDocument;KF||Kf==null||Kf!==vW(i)||(i=Kf,"selectionStart"in i&&f_(i)?i={start:i.selectionStart,end:i.selectionEnd}:(i=(i.ownerDocument&&i.ownerDocument.defaultView||window).getSelection(),i={anchorNode:i.anchorNode,anchorOffset:i.anchorOffset,focusNode:i.focusNode,focusOffset:i.focusOffset}),uG&&wv(uG,i)||(uG=i,i=XW(YF,"onSelect"),0Ff||(e.current=zF[Ff],zF[Ff]=null,Ff--)}function CI(e,g){Ff++,zF[Ff]=e.current,e.current=g}var Nc={},Xn=Mc(Nc),HC=Mc(!1),Hd=Nc;function Op(e,g){var I=e.type.contextTypes;if(!I)return Nc;var i=e.stateNode;if(i&&i.__reactInternalMemoizedUnmaskedChildContext===g)return i.__reactInternalMemoizedMaskedChildContext;var n={},C;for(C in I)n[C]=g[C];return i&&(e=e.stateNode,e.__reactInternalMemoizedUnmaskedChildContext=g,e.__reactInternalMemoizedMaskedChildContext=n),n}function TC(e){return e=e.childContextTypes,e!=null}function TW(){yI(HC),yI(Xn)}function J8(e,g,I){if(Xn.current!==Nc)throw Error(at(168));CI(Xn,g),CI(HC,I)}function Uue(e,g,I){var i=e.stateNode;if(g=g.childContextTypes,typeof i.getChildContext!="function")return I;i=i.getChildContext();for(var n in i)if(!(n in g))throw Error(at(108,ike(e)||"Unknown",n));return EI({},I,i)}function NW(e){return e=(e=e.stateNode)&&e.__reactInternalMemoizedMergedChildContext||Nc,Hd=Xn.current,CI(Xn,e),CI(HC,HC.current),!0}function O8(e,g,I){var i=e.stateNode;if(!i)throw Error(at(169));I?(e=Uue(e,g,Hd),i.__reactInternalMemoizedMergedChildContext=e,yI(HC),yI(Xn),CI(Xn,e)):yI(HC),CI(HC,I)}var La=null,HH=!1,wY=!1;function Que(e){La===null?La=[e]:La.push(e)}function yYe(e){HH=!0,Que(e)}function zc(){if(!wY&&La!==null){wY=!0;var e=0,g=zg;try{var I=La;for(zg=1;e>=r,n-=r,ns=1<<32-Qo(g)+n|I<v?(w=G,G=null):w=G.sibling;var V=c(f,G,p[v],y);if(V===null){G===null&&(G=w);break}e&&G&&V.alternate===null&&g(f,G),b=C(V,b,v),B===null?Z=V:B.sibling=V,B=V,G=w}if(v===p.length)return I(f,G),RI&&Wu(f,v),Z;if(G===null){for(;vv?(w=G,G=null):w=G.sibling;var S=c(f,G,V.value,y);if(S===null){G===null&&(G=w);break}e&&G&&S.alternate===null&&g(f,G),b=C(S,b,v),B===null?Z=S:B.sibling=S,B=S,G=w}if(V.done)return I(f,G),RI&&Wu(f,v),Z;if(G===null){for(;!V.done;v++,V=p.next())V=l(f,V.value,y),V!==null&&(b=C(V,b,v),B===null?Z=V:B.sibling=V,B=V);return RI&&Wu(f,v),Z}for(G=i(f,G);!V.done;v++,V=p.next())V=u(G,f,v,V.value,y),V!==null&&(e&&V.alternate!==null&&G.delete(V.key===null?v:V.key),b=C(V,b,v),B===null?Z=V:B.sibling=V,B=V);return e&&G.forEach(function(X){return g(f,X)}),RI&&Wu(f,v),Z}function m(f,b,p,y){if(typeof p=="object"&&p!==null&&p.type===kf&&p.key===null&&(p=p.props.children),typeof p=="object"&&p!==null){switch(p.$$typeof){case Ww:e:{for(var Z=p.key,B=b;B!==null;){if(B.key===Z){if(Z=p.type,Z===kf){if(B.tag===7){I(f,B.sibling),b=n(B,p.props.children),b.return=f,f=b;break e}}else if(B.elementType===Z||typeof Z=="object"&&Z!==null&&Z.$$typeof===Tl&&q8(Z)===B.type){I(f,B.sibling),b=n(B,p.props),b.ref=cy(f,B,p),b.return=f,f=b;break e}I(f,B);break}else g(f,B);B=B.sibling}p.type===kf?(b=cd(p.props.children,f.mode,y,p.key),b.return=f,f=b):(y=g1(p.type,p.key,p.props,null,f.mode,y),y.ref=cy(f,b,p),y.return=f,f=y)}return r(f);case Nf:e:{for(B=p.key;b!==null;){if(b.key===B)if(b.tag===4&&b.stateNode.containerInfo===p.containerInfo&&b.stateNode.implementation===p.implementation){I(f,b.sibling),b=n(b,p.children||[]),b.return=f,f=b;break e}else{I(f,b);break}else g(f,b);b=b.sibling}b=kY(p,f.mode,y),b.return=f,f=b}return r(f);case Tl:return B=p._init,m(f,b,B(p._payload),y)}if(dZ(p))return d(f,b,p,y);if(oy(p))return h(f,b,p,y);Ew(f,p)}return typeof p=="string"&&p!==""||typeof p=="number"?(p=""+p,b!==null&&b.tag===6?(I(f,b.sibling),b=n(b,p),b.return=f,f=b):(I(f,b),b=NY(p,f.mode,y),b.return=f,f=b),r(f)):I(f,b)}return m}var Lp=ide(!0),nde=ide(!1),nS={},ga=Mc(nS),Xv=Mc(nS),Hv=Mc(nS);function Qu(e){if(e===nS)throw Error(at(174));return e}function w_(e,g){switch(CI(Hv,g),CI(Xv,e),CI(ga,nS),e=g.nodeType,e){case 9:case 11:g=(g=g.documentElement)?g.namespaceURI:SF(null,"");break;default:e=e===8?g.parentNode:g,g=e.namespaceURI||null,e=e.tagName,g=SF(g,e)}yI(ga),CI(ga,g)}function Up(){yI(ga),yI(Xv),yI(Hv)}function Cde(e){Qu(Hv.current);var g=Qu(ga.current),I=SF(g,e.type);g!==I&&(CI(Xv,e),CI(ga,I))}function V_(e){Xv.current===e&&(yI(ga),yI(Xv))}var kI=Mc(0);function FW(e){for(var g=e;g!==null;){if(g.tag===13){var I=g.memoizedState;if(I!==null&&(I=I.dehydrated,I===null||I.data==="$?"||I.data==="$!"))return g}else if(g.tag===19&&g.memoizedProps.revealOrder!==void 0){if(g.flags&128)return g}else if(g.child!==null){g.child.return=g,g=g.child;continue}if(g===e)break;for(;g.sibling===null;){if(g.return===null||g.return===e)return null;g=g.return}g.sibling.return=g.return,g=g.sibling}return null}var VY=[];function R_(){for(var e=0;eI?I:4,e(!0);var i=RY.transition;RY.transition={};try{e(!1),g()}finally{zg=I,RY.transition=i}}function Zde(){return qr().memoizedState}function BYe(e,g,I){var i=bc(e);if(I={lane:i,action:I,hasEagerState:!1,eagerState:null,next:null},Gde(e))vde(g,I);else if(I=ede(e,g,I,i),I!==null){var n=gC();jo(I,e,i,n),Bde(I,g,i)}}function SYe(e,g,I){var i=bc(e),n={lane:i,action:I,hasEagerState:!1,eagerState:null,next:null};if(Gde(e))vde(g,n);else{var C=e.alternate;if(e.lanes===0&&(C===null||C.lanes===0)&&(C=g.lastRenderedReducer,C!==null))try{var r=g.lastRenderedState,o=C(r,I);if(n.hasEagerState=!0,n.eagerState=o,nA(o,r)){var A=g.interleaved;A===null?(n.next=n,B_(g)):(n.next=A.next,A.next=n),g.interleaved=n;return}}catch{}finally{}I=ede(e,g,n,i),I!==null&&(n=gC(),jo(I,e,i,n),Bde(I,g,i))}}function Gde(e){var g=e.alternate;return e===xI||g!==null&&g===xI}function vde(e,g){dG=EW=!0;var I=e.pending;I===null?g.next=g:(g.next=I.next,I.next=g),e.pending=g}function Bde(e,g,I){if(I&4194240){var i=g.lanes;i&=e.pendingLanes,I|=i,g.lanes=I,s_(e,I)}}var MW={readContext:$r,useCallback:hn,useContext:hn,useEffect:hn,useImperativeHandle:hn,useInsertionEffect:hn,useLayoutEffect:hn,useMemo:hn,useReducer:hn,useRef:hn,useState:hn,useDebugValue:hn,useDeferredValue:hn,useTransition:hn,useMutableSource:hn,useSyncExternalStore:hn,useId:hn,unstable_isNewReconciler:!1},wYe={readContext:$r,useCallback:function(e,g){return RA().memoizedState=[e,g===void 0?null:g],e},useContext:$r,useEffect:t6,useImperativeHandle:function(e,g,I){return I=I!=null?I.concat([e]):null,$R(4194308,4,mde.bind(null,g,e),I)},useLayoutEffect:function(e,g){return $R(4194308,4,e,g)},useInsertionEffect:function(e,g){return $R(4,2,e,g)},useMemo:function(e,g){var I=RA();return g=g===void 0?null:g,e=e(),I.memoizedState=[e,g],e},useReducer:function(e,g,I){var i=RA();return g=I!==void 0?I(g):g,i.memoizedState=i.baseState=g,e={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:e,lastRenderedState:g},i.queue=e,e=e.dispatch=BYe.bind(null,xI,e),[i.memoizedState,e]},useRef:function(e){var g=RA();return e={current:e},g.memoizedState=e},useState:e6,useDebugValue:N_,useDeferredValue:function(e){return RA().memoizedState=e},useTransition:function(){var e=e6(!1),g=e[0];return e=vYe.bind(null,e[1]),RA().memoizedState=e,[g,e]},useMutableSource:function(){},useSyncExternalStore:function(e,g,I){var i=xI,n=RA();if(RI){if(I===void 0)throw Error(at(407));I=I()}else{if(I=g(),Ji===null)throw Error(at(349));Nd&30||Ade(i,g,I)}n.memoizedState=I;var C={value:I,getSnapshot:g};return n.queue=C,t6(sde.bind(null,i,C,e),[e]),i.flags|=2048,kv(9,ade.bind(null,i,C,I,g),void 0,null),I},useId:function(){var e=RA(),g=Ji.identifierPrefix;if(RI){var I=Cs,i=ns;I=(i&~(1<<32-Qo(i)-1)).toString(32)+I,g=":"+g+"R"+I,I=Tv++,0<\/script>",g=g.removeChild(g.firstChild)):typeof i.is=="string"?g=r.createElement(I,{is:i.is}):(g=r.createElement(I),I==="select"&&(r=g,i.multiple?r.multiple=!0:i.size&&(r.size=i.size))):g=r.createElementNS(g,I),g[JA]=e,g[gv]=i,phe(g,e,!1,!1),e.stateNode=g;e:{switch(r=fE(I,i),I){case"dialog":hI("cancel",g),hI("close",g),n=i;break;case"iframe":case"object":case"embed":hI("load",g),n=i;break;case"video":case"audio":for(n=0;nbb&&(e.flags|=128,i=!0,Ty(C,!1),e.lanes=4194304)}else{if(!i)if(g=yX(r),g!==null){if(e.flags|=128,i=!0,I=g.updateQueue,I!==null&&(e.updateQueue=I,e.flags|=4),Ty(C,!0),C.tail===null&&C.tailMode==="hidden"&&!r.alternate&&!XI)return fn(e),null}else 2*oi()-C.renderingStartTime>bb&&I!==1073741824&&(e.flags|=128,i=!0,Ty(C,!1),e.lanes=4194304);C.isBackwards?(r.sibling=e.child,e.child=r):(I=C.last,I!==null?I.sibling=r:e.child=r,C.last=r)}return C.tail!==null?(e=C.tail,C.rendering=e,C.tail=e.sibling,C.renderingStartTime=oi(),e.sibling=null,I=xI.current,aI(xI,i?I&1|2:I&1),e):(fn(e),null);case 22:case 23:return y_(),i=e.memoizedState!==null,g!==null&&g.memoizedState!==null!==i&&(e.flags|=8192),i&&e.mode&1?QC&1073741824&&(fn(e),e.subtreeFlags&6&&(e.flags|=8192)):fn(e),null;case 24:return null;case 25:return null}throw Error(at(156,e.tag))}function JKe(g,e){switch(t_(e),e.tag){case 1:return kC(e.type)&&uX(),g=e.flags,g&65536?(e.flags=g&-65537|128,e):null;case 3:return fb(),GI(NC),GI(Tn),a_(),g=e.flags,g&65536&&!(g&128)?(e.flags=g&-65537|128,e):null;case 5:return A_(e),null;case 13:if(GI(xI),g=e.memoizedState,g!==null&&g.dehydrated!==null){if(e.alternate===null)throw Error(at(340));hb()}return g=e.flags,g&65536?(e.flags=g&-65537|128,e):null;case 19:return GI(xI),null;case 4:return fb(),null;case 10:return n_(e.type._context),null;case 22:case 23:return y_(),null;case 24:return null;default:return null}}var ZV=!1,Wn=!1,OKe=typeof WeakSet=="function"?WeakSet:Set,Wt=null;function cp(g,e){var I=g.ref;if(I!==null)if(typeof I=="function")try{I(null)}catch(i){_I(g,e,i)}else I.current=null}function JE(g,e,I){try{I()}catch(i){_I(g,e,i)}}var z6=!1;function LKe(g,e){if(VE=aX,g=vde(),qL(g)){if("selectionStart"in g)var I={start:g.selectionStart,end:g.selectionEnd};else e:{I=(I=g.ownerDocument)&&I.defaultView||window;var i=I.getSelection&&I.getSelection();if(i&&i.rangeCount!==0){I=i.anchorNode;var n=i.anchorOffset,C=i.focusNode;i=i.focusOffset;try{I.nodeType,C.nodeType}catch{I=null;break e}var r=0,o=-1,A=-1,s=0,a=0,l=g,c=null;t:for(;;){for(var u;l!==I||n!==0&&l.nodeType!==3||(o=r+n),l!==C||i!==0&&l.nodeType!==3||(A=r+i),l.nodeType===3&&(r+=l.nodeValue.length),(u=l.firstChild)!==null;)c=l,l=u;for(;;){if(l===g)break t;if(c===I&&++s===n&&(o=r),c===C&&++a===i&&(A=r),(u=l.nextSibling)!==null)break;l=c,c=l.parentNode}l=u}I=o===-1||A===-1?null:{start:o,end:A}}else I=null}I=I||{start:0,end:0}}else I=null;for(RE={focusedElem:g,selectionRange:I},aX=!1,Wt=e;Wt!==null;)if(e=Wt,g=e.child,(e.subtreeFlags&1028)!==0&&g!==null)g.return=e,Wt=g;else for(;Wt!==null;){e=Wt;try{var d=e.alternate;if(e.flags&1024)switch(e.tag){case 0:case 11:case 15:break;case 1:if(d!==null){var h=d.memoizedProps,m=d.memoizedState,f=e.stateNode,b=f.getSnapshotBeforeUpdate(e.elementType===e.type?h:Eo(e.type,h),m);f.__reactInternalSnapshotBeforeUpdate=b}break;case 3:var p=e.stateNode.containerInfo;p.nodeType===1?p.textContent="":p.nodeType===9&&p.documentElement&&p.removeChild(p.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(at(163))}}catch(y){_I(e,e.return,y)}if(g=e.sibling,g!==null){g.return=e.return,Wt=g;break}Wt=e.return}return d=z6,z6=!1,d}function MG(g,e,I){var i=e.updateQueue;if(i=i!==null?i.lastEffect:null,i!==null){var n=i=i.next;do{if((n.tag&g)===g){var C=n.destroy;n.destroy=void 0,C!==void 0&&JE(e,I,C)}n=n.next}while(n!==i)}}function vT(g,e){if(e=e.updateQueue,e=e!==null?e.lastEffect:null,e!==null){var I=e=e.next;do{if((I.tag&g)===g){var i=I.create;I.destroy=i()}I=I.next}while(I!==e)}}function OE(g){var e=g.ref;if(e!==null){var I=g.stateNode;switch(g.tag){case 5:g=I;break;default:g=I}typeof e=="function"?e(g):e.current=g}}function Zhe(g){var e=g.alternate;e!==null&&(g.alternate=null,Zhe(e)),g.child=null,g.deletions=null,g.sibling=null,g.tag===5&&(e=g.stateNode,e!==null&&(delete e[JA],delete e[gv],delete e[HE],delete e[RKe],delete e[WKe])),g.stateNode=null,g.return=null,g.dependencies=null,g.memoizedProps=null,g.memoizedState=null,g.pendingProps=null,g.stateNode=null,g.updateQueue=null}function Ghe(g){return g.tag===5||g.tag===3||g.tag===4}function P6(g){e:for(;;){for(;g.sibling===null;){if(g.return===null||Ghe(g.return))return null;g=g.return}for(g.sibling.return=g.return,g=g.sibling;g.tag!==5&&g.tag!==6&&g.tag!==18;){if(g.flags&2||g.child===null||g.tag===4)continue e;g.child.return=g,g=g.child}if(!(g.flags&2))return g.stateNode}}function LE(g,e,I){var i=g.tag;if(i===5||i===6)g=g.stateNode,e?I.nodeType===8?I.parentNode.insertBefore(g,e):I.insertBefore(g,e):(I.nodeType===8?(e=I.parentNode,e.insertBefore(g,I)):(e=I,e.appendChild(g)),I=I._reactRootContainer,I!=null||e.onclick!==null||(e.onclick=cX));else if(i!==4&&(g=g.child,g!==null))for(LE(g,e,I),g=g.sibling;g!==null;)LE(g,e,I),g=g.sibling}function _E(g,e,I){var i=g.tag;if(i===5||i===6)g=g.stateNode,e?I.insertBefore(g,e):I.appendChild(g);else if(i!==4&&(g=g.child,g!==null))for(_E(g,e,I),g=g.sibling;g!==null;)_E(g,e,I),g=g.sibling}var In=null,zo=!1;function vl(g,e,I){for(I=I.child;I!==null;)Bhe(g,e,I),I=I.sibling}function Bhe(g,e,I){if(ca&&typeof ca.onCommitFiberUnmount=="function")try{ca.onCommitFiberUnmount(mT,I)}catch{}switch(I.tag){case 5:Wn||cp(I,e);case 6:var i=In,n=zo;In=null,vl(g,e,I),In=i,zo=n,In!==null&&(zo?(g=In,I=I.stateNode,g.nodeType===8?g.parentNode.removeChild(I):g.removeChild(I)):In.removeChild(I.stateNode));break;case 18:In!==null&&(zo?(g=In,I=I.stateNode,g.nodeType===8?fK(g.parentNode,I):g.nodeType===1&&fK(g,I),jB(g)):fK(In,I.stateNode));break;case 4:i=In,n=zo,In=I.stateNode.containerInfo,zo=!0,vl(g,e,I),In=i,zo=n;break;case 0:case 11:case 14:case 15:if(!Wn&&(i=I.updateQueue,i!==null&&(i=i.lastEffect,i!==null))){n=i=i.next;do{var C=n,r=C.destroy;C=C.tag,r!==void 0&&(C&2||C&4)&&JE(I,e,r),n=n.next}while(n!==i)}vl(g,e,I);break;case 1:if(!Wn&&(cp(I,e),i=I.stateNode,typeof i.componentWillUnmount=="function"))try{i.props=I.memoizedProps,i.state=I.memoizedState,i.componentWillUnmount()}catch(o){_I(I,e,o)}vl(g,e,I);break;case 21:vl(g,e,I);break;case 22:I.mode&1?(Wn=(i=Wn)||I.memoizedState!==null,vl(g,e,I),Wn=i):vl(g,e,I);break;default:vl(g,e,I)}}function J6(g){var e=g.updateQueue;if(e!==null){g.updateQueue=null;var I=g.stateNode;I===null&&(I=g.stateNode=new OKe),e.forEach(function(i){var n=g5e.bind(null,g,i);I.has(i)||(I.add(i),i.then(n,n))})}}function po(g,e){var I=e.deletions;if(I!==null)for(var i=0;in&&(n=r),i&=~C}if(i=n,i=oi()-i,i=(120>i?120:480>i?480:1080>i?1080:1920>i?1920:3e3>i?3e3:4320>i?4320:1960*UKe(i/1960))-i,10g?16:g,Zc===null)var i=!1;else{if(g=Zc,Zc=null,SX=0,kg&6)throw Error(at(331));var n=kg;for(kg|=4,Wt=g.current;Wt!==null;){var C=Wt,r=C.child;if(Wt.flags&16){var o=C.deletions;if(o!==null){for(var A=0;Aoi()-p_?Rd(g,0):f_|=I),YC(g,e)}function Hhe(g,e){e===0&&(g.mode&1?(e=cV,cV<<=1,!(cV&130023424)&&(cV=4194304)):e=1);var I=CC();g=xs(g,e),g!==null&&(VS(g,e,I),YC(g,I))}function t5e(g){var e=g.memoizedState,I=0;e!==null&&(I=e.retryLane),Hhe(g,I)}function g5e(g,e){var I=0;switch(g.tag){case 13:var i=g.stateNode,n=g.memoizedState;n!==null&&(I=n.retryLane);break;case 19:i=g.stateNode;break;default:throw Error(at(314))}i!==null&&i.delete(e),Hhe(g,I)}var The;The=function(g,e,I){if(g!==null)if(g.memoizedProps!==e.pendingProps||NC.current)HC=!0;else{if(!(g.lanes&I)&&!(e.flags&128))return HC=!1,zKe(g,e,I);HC=!!(g.flags&131072)}else HC=!1,XI&&e.flags&1048576&&Yde(e,mX,e.index);switch(e.lanes=0,e.tag){case 2:var i=e.type;V1(g,e),g=e.pendingProps;var n=db(e,Tn.current);Tp(e,I),n=l_(null,e,i,g,n,I);var C=c_();return e.flags|=1,typeof n=="object"&&n!==null&&typeof n.render=="function"&&n.$$typeof===void 0?(e.tag=1,e.memoizedState=null,e.updateQueue=null,kC(i)?(C=!0,dX(e)):C=!1,e.memoizedState=n.state!==null&&n.state!==void 0?n.state:null,r_(e),n.updater=GT,e.stateNode=n,n._reactInternals=e,xE(e,i,g,I),e=EE(null,e,i,!0,C,I)):(e.tag=0,XI&&C&&e_(e),Jn(null,e,n,I),e=e.child),e;case 16:i=e.elementType;e:{switch(V1(g,e),g=e.pendingProps,n=i._init,i=n(i._payload),e.type=i,n=e.tag=i5e(i),g=Eo(i,g),n){case 0:e=FE(null,e,i,g,I);break e;case 1:e=F6(null,e,i,g,I);break e;case 11:e=x6(null,e,i,g,I);break e;case 14:e=D6(null,e,i,Eo(i.type,g),I);break e}throw Error(at(306,i,""))}return e;case 0:return i=e.type,n=e.pendingProps,n=e.elementType===i?n:Eo(i,n),FE(g,e,i,n,I);case 1:return i=e.type,n=e.pendingProps,n=e.elementType===i?n:Eo(i,n),F6(g,e,i,n,I);case 3:e:{if(hhe(e),g===null)throw Error(at(387));i=e.pendingProps,C=e.memoizedState,n=C.element,Fde(g,e),bX(e,i,null,I);var r=e.memoizedState;if(i=r.element,C.isDehydrated)if(C={element:i,isDehydrated:!1,cache:r.cache,pendingSuspenseBoundaries:r.pendingSuspenseBoundaries,transitions:r.transitions},e.updateQueue.baseState=C,e.memoizedState=C,e.flags&256){n=pb(Error(at(423)),e),e=E6(g,e,i,I,n);break e}else if(i!==n){n=pb(Error(at(424)),e),e=E6(g,e,i,I,n);break e}else for(ar=xc(e.stateNode.containerInfo.firstChild),ur=e,XI=!0,Jo=null,I=Pde(e,null,i,I),e.child=I;I;)I.flags=I.flags&-3|4096,I=I.sibling;else{if(hb(),i===n){e=Ds(g,e,I);break e}Jn(g,e,i,I)}e=e.child}return e;case 5:return Jde(e),g===null&&kE(e),i=e.type,n=e.pendingProps,C=g!==null?g.memoizedProps:null,r=n.children,WE(i,n)?r=null:C!==null&&WE(i,C)&&(e.flags|=32),dhe(g,e),Jn(g,e,r,I),e.child;case 6:return g===null&&kE(e),null;case 13:return mhe(g,e,I);case 4:return o_(e,e.stateNode.containerInfo),i=e.pendingProps,g===null?e.child=mb(e,null,i,I):Jn(g,e,i,I),e.child;case 11:return i=e.type,n=e.pendingProps,n=e.elementType===i?n:Eo(i,n),x6(g,e,i,n,I);case 7:return Jn(g,e,e.pendingProps,I),e.child;case 8:return Jn(g,e,e.pendingProps.children,I),e.child;case 12:return Jn(g,e,e.pendingProps.children,I),e.child;case 10:e:{if(i=e.type._context,n=e.pendingProps,C=e.memoizedProps,r=n.value,aI(fX,i._currentValue),i._currentValue=r,C!==null)if(cA(C.value,r)){if(C.children===n.children&&!NC.current){e=Ds(g,e,I);break e}}else for(C=e.child,C!==null&&(C.return=e);C!==null;){var o=C.dependencies;if(o!==null){r=C.child;for(var A=o.firstContext;A!==null;){if(A.context===i){if(C.tag===1){A=Xs(-1,I&-I),A.tag=2;var s=C.updateQueue;if(s!==null){s=s.shared;var a=s.pending;a===null?A.next=A:(A.next=a.next,a.next=A),s.pending=A}}C.lanes|=I,A=C.alternate,A!==null&&(A.lanes|=I),YE(C.return,I,e),o.lanes|=I;break}A=A.next}}else if(C.tag===10)r=C.type===e.type?null:C.child;else if(C.tag===18){if(r=C.return,r===null)throw Error(at(341));r.lanes|=I,o=r.alternate,o!==null&&(o.lanes|=I),YE(r,I,e),r=C.sibling}else r=C.child;if(r!==null)r.return=C;else for(r=C;r!==null;){if(r===e){r=null;break}if(C=r.sibling,C!==null){C.return=r.return,r=C;break}r=r.return}C=r}Jn(g,e,n.children,I),e=e.child}return e;case 9:return n=e.type,i=e.pendingProps.children,Tp(e,I),n=Co(n),i=i(n),e.flags|=1,Jn(g,e,i,I),e.child;case 14:return i=e.type,n=Eo(i,e.pendingProps),n=Eo(i.type,n),D6(g,e,i,n,I);case 15:return che(g,e,e.type,e.pendingProps,I);case 17:return i=e.type,n=e.pendingProps,n=e.elementType===i?n:Eo(i,n),V1(g,e),e.tag=1,kC(i)?(g=!0,dX(e)):g=!1,Tp(e,I),Mde(e,i,n),xE(e,i,n,I),EE(null,e,i,!0,g,I);case 19:return fhe(g,e,I);case 22:return uhe(g,e,I)}throw Error(at(156,e.tag))};function Nhe(g,e){return Cde(g,e)}function I5e(g,e,I,i){this.tag=g,this.key=I,this.sibling=this.child=this.return=this.stateNode=this.type=this.elementType=null,this.index=0,this.ref=null,this.pendingProps=e,this.dependencies=this.memoizedState=this.updateQueue=this.memoizedProps=null,this.mode=i,this.subtreeFlags=this.flags=0,this.deletions=null,this.childLanes=this.lanes=0,this.alternate=null}function Ur(g,e,I,i){return new I5e(g,e,I,i)}function G_(g){return g=g.prototype,!(!g||!g.isReactComponent)}function i5e(g){if(typeof g=="function")return G_(g)?1:0;if(g!=null){if(g=g.$$typeof,g===ML)return 11;if(g===zL)return 14}return 2}function Mc(g,e){var I=g.alternate;return I===null?(I=Ur(g.tag,e,g.key,g.mode),I.elementType=g.elementType,I.type=g.type,I.stateNode=g.stateNode,I.alternate=g,g.alternate=I):(I.pendingProps=e,I.type=g.type,I.flags=0,I.subtreeFlags=0,I.deletions=null),I.flags=g.flags&14680064,I.childLanes=g.childLanes,I.lanes=g.lanes,I.child=g.child,I.memoizedProps=g.memoizedProps,I.memoizedState=g.memoizedState,I.updateQueue=g.updateQueue,e=g.dependencies,I.dependencies=e===null?null:{lanes:e.lanes,firstContext:e.firstContext},I.sibling=g.sibling,I.index=g.index,I.ref=g.ref,I}function X1(g,e,I,i,n,C){var r=2;if(i=g,typeof g=="function")G_(g)&&(r=1);else if(typeof g=="string")r=5;else e:switch(g){case ip:return Wd(I.children,n,C,e);case EL:r=8,n|=8;break;case oE:return g=Ur(12,I,e,n|2),g.elementType=oE,g.lanes=C,g;case AE:return g=Ur(13,I,e,n),g.elementType=AE,g.lanes=C,g;case aE:return g=Ur(19,I,e,n),g.elementType=aE,g.lanes=C,g;case zue:return wT(I,n,C,e);default:if(typeof g=="object"&&g!==null)switch(g.$$typeof){case Eue:r=10;break e;case Mue:r=9;break e;case ML:r=11;break e;case zL:r=14;break e;case Ql:r=16,i=null;break e}throw Error(at(130,g==null?g:typeof g,""))}return e=Ur(r,I,e,n),e.elementType=g,e.type=i,e.lanes=C,e}function Wd(g,e,I,i){return g=Ur(7,g,i,e),g.lanes=I,g}function wT(g,e,I,i){return g=Ur(22,g,i,e),g.elementType=zue,g.lanes=I,g.stateNode={isHidden:!1},g}function SK(g,e,I){return g=Ur(6,g,null,e),g.lanes=I,g}function wK(g,e,I){return e=Ur(4,g.children!==null?g.children:[],g.key,e),e.lanes=I,e.stateNode={containerInfo:g.containerInfo,pendingChildren:null,implementation:g.implementation},e}function n5e(g,e,I,i,n){this.tag=e,this.containerInfo=g,this.finishedWork=this.pingCache=this.current=this.pendingChildren=null,this.timeoutHandle=-1,this.callbackNode=this.pendingContext=this.context=null,this.callbackPriority=0,this.eventTimes=rK(0),this.expirationTimes=rK(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=rK(0),this.identifierPrefix=i,this.onRecoverableError=n,this.mutableSourceEagerHydrationData=null}function B_(g,e,I,i,n,C,r,o,A){return g=new n5e(g,e,I,o,A),e===1?(e=1,C===!0&&(e|=8)):e=0,C=Ur(3,null,null,e),g.current=C,C.stateNode=g,C.memoizedState={element:i,isDehydrated:I,cache:null,transitions:null,pendingSuspenseBoundaries:null},r_(C),g}function C5e(g,e,I){var i=3"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(xhe)}catch(g){console.error(g)}}xhe(),Yue.exports=Gr;var Fs=Yue.exports;const QI=jh(Fs);var q6=Fs;CE.createRoot=q6.createRoot,CE.hydrateRoot=q6.hydrateRoot;const s5e="modulepreload",l5e=function(g){return"/alt-gosling/"+g},eq={},c5e=function(e,I,i){if(!I||I.length===0)return e();const n=document.getElementsByTagName("link");return Promise.all(I.map(C=>{if(C=l5e(C),C in eq)return;eq[C]=!0;const r=C.endsWith(".css"),o=r?'[rel="stylesheet"]':"";if(!!i)for(let a=n.length-1;a>=0;a--){const l=n[a];if(l.href===C&&(!r||l.rel==="stylesheet"))return}else if(document.querySelector(`link[href="${C}"]${o}`))return;const s=document.createElement("link");if(s.rel=r?"stylesheet":s5e,r||(s.as="script",s.crossOrigin=""),s.href=C,document.head.appendChild(s),r)return new Promise((a,l)=>{s.addEventListener("load",a),s.addEventListener("error",()=>l(new Error(`Unable to preload CSS for ${C}`)))})})).then(()=>e()).catch(C=>{const r=new Event("vite:preloadError",{cancelable:!0});if(r.payload=C,window.dispatchEvent(r),!r.defaultPrevented)throw C})};var su=(g=>(g[g.WEBGL_LEGACY=0]="WEBGL_LEGACY",g[g.WEBGL=1]="WEBGL",g[g.WEBGL2=2]="WEBGL2",g))(su||{}),V_=(g=>(g[g.UNKNOWN=0]="UNKNOWN",g[g.WEBGL=1]="WEBGL",g[g.CANVAS=2]="CANVAS",g))(V_||{}),RX=(g=>(g[g.COLOR=16384]="COLOR",g[g.DEPTH=256]="DEPTH",g[g.STENCIL=1024]="STENCIL",g))(RX||{}),$t=(g=>(g[g.NORMAL=0]="NORMAL",g[g.ADD=1]="ADD",g[g.MULTIPLY=2]="MULTIPLY",g[g.SCREEN=3]="SCREEN",g[g.OVERLAY=4]="OVERLAY",g[g.DARKEN=5]="DARKEN",g[g.LIGHTEN=6]="LIGHTEN",g[g.COLOR_DODGE=7]="COLOR_DODGE",g[g.COLOR_BURN=8]="COLOR_BURN",g[g.HARD_LIGHT=9]="HARD_LIGHT",g[g.SOFT_LIGHT=10]="SOFT_LIGHT",g[g.DIFFERENCE=11]="DIFFERENCE",g[g.EXCLUSION=12]="EXCLUSION",g[g.HUE=13]="HUE",g[g.SATURATION=14]="SATURATION",g[g.COLOR=15]="COLOR",g[g.LUMINOSITY=16]="LUMINOSITY",g[g.NORMAL_NPM=17]="NORMAL_NPM",g[g.ADD_NPM=18]="ADD_NPM",g[g.SCREEN_NPM=19]="SCREEN_NPM",g[g.NONE=20]="NONE",g[g.SRC_OVER=0]="SRC_OVER",g[g.SRC_IN=21]="SRC_IN",g[g.SRC_OUT=22]="SRC_OUT",g[g.SRC_ATOP=23]="SRC_ATOP",g[g.DST_OVER=24]="DST_OVER",g[g.DST_IN=25]="DST_IN",g[g.DST_OUT=26]="DST_OUT",g[g.DST_ATOP=27]="DST_ATOP",g[g.ERASE=26]="ERASE",g[g.SUBTRACT=28]="SUBTRACT",g[g.XOR=29]="XOR",g))($t||{}),qo=(g=>(g[g.POINTS=0]="POINTS",g[g.LINES=1]="LINES",g[g.LINE_LOOP=2]="LINE_LOOP",g[g.LINE_STRIP=3]="LINE_STRIP",g[g.TRIANGLES=4]="TRIANGLES",g[g.TRIANGLE_STRIP=5]="TRIANGLE_STRIP",g[g.TRIANGLE_FAN=6]="TRIANGLE_FAN",g))(qo||{}),st=(g=>(g[g.RGBA=6408]="RGBA",g[g.RGB=6407]="RGB",g[g.RG=33319]="RG",g[g.RED=6403]="RED",g[g.RGBA_INTEGER=36249]="RGBA_INTEGER",g[g.RGB_INTEGER=36248]="RGB_INTEGER",g[g.RG_INTEGER=33320]="RG_INTEGER",g[g.RED_INTEGER=36244]="RED_INTEGER",g[g.ALPHA=6406]="ALPHA",g[g.LUMINANCE=6409]="LUMINANCE",g[g.LUMINANCE_ALPHA=6410]="LUMINANCE_ALPHA",g[g.DEPTH_COMPONENT=6402]="DEPTH_COMPONENT",g[g.DEPTH_STENCIL=34041]="DEPTH_STENCIL",g))(st||{}),Xd=(g=>(g[g.TEXTURE_2D=3553]="TEXTURE_2D",g[g.TEXTURE_CUBE_MAP=34067]="TEXTURE_CUBE_MAP",g[g.TEXTURE_2D_ARRAY=35866]="TEXTURE_2D_ARRAY",g[g.TEXTURE_CUBE_MAP_POSITIVE_X=34069]="TEXTURE_CUBE_MAP_POSITIVE_X",g[g.TEXTURE_CUBE_MAP_NEGATIVE_X=34070]="TEXTURE_CUBE_MAP_NEGATIVE_X",g[g.TEXTURE_CUBE_MAP_POSITIVE_Y=34071]="TEXTURE_CUBE_MAP_POSITIVE_Y",g[g.TEXTURE_CUBE_MAP_NEGATIVE_Y=34072]="TEXTURE_CUBE_MAP_NEGATIVE_Y",g[g.TEXTURE_CUBE_MAP_POSITIVE_Z=34073]="TEXTURE_CUBE_MAP_POSITIVE_Z",g[g.TEXTURE_CUBE_MAP_NEGATIVE_Z=34074]="TEXTURE_CUBE_MAP_NEGATIVE_Z",g))(Xd||{}),Mt=(g=>(g[g.UNSIGNED_BYTE=5121]="UNSIGNED_BYTE",g[g.UNSIGNED_SHORT=5123]="UNSIGNED_SHORT",g[g.UNSIGNED_SHORT_5_6_5=33635]="UNSIGNED_SHORT_5_6_5",g[g.UNSIGNED_SHORT_4_4_4_4=32819]="UNSIGNED_SHORT_4_4_4_4",g[g.UNSIGNED_SHORT_5_5_5_1=32820]="UNSIGNED_SHORT_5_5_5_1",g[g.UNSIGNED_INT=5125]="UNSIGNED_INT",g[g.UNSIGNED_INT_10F_11F_11F_REV=35899]="UNSIGNED_INT_10F_11F_11F_REV",g[g.UNSIGNED_INT_2_10_10_10_REV=33640]="UNSIGNED_INT_2_10_10_10_REV",g[g.UNSIGNED_INT_24_8=34042]="UNSIGNED_INT_24_8",g[g.UNSIGNED_INT_5_9_9_9_REV=35902]="UNSIGNED_INT_5_9_9_9_REV",g[g.BYTE=5120]="BYTE",g[g.SHORT=5122]="SHORT",g[g.INT=5124]="INT",g[g.FLOAT=5126]="FLOAT",g[g.FLOAT_32_UNSIGNED_INT_24_8_REV=36269]="FLOAT_32_UNSIGNED_INT_24_8_REV",g[g.HALF_FLOAT=36193]="HALF_FLOAT",g))(Mt||{}),Zt=(g=>(g[g.FLOAT=0]="FLOAT",g[g.INT=1]="INT",g[g.UINT=2]="UINT",g))(Zt||{}),Ca=(g=>(g[g.NEAREST=0]="NEAREST",g[g.LINEAR=1]="LINEAR",g))(Ca||{}),da=(g=>(g[g.CLAMP=33071]="CLAMP",g[g.REPEAT=10497]="REPEAT",g[g.MIRRORED_REPEAT=33648]="MIRRORED_REPEAT",g))(da||{}),uA=(g=>(g[g.OFF=0]="OFF",g[g.POW2=1]="POW2",g[g.ON=2]="ON",g[g.ON_MANUAL=3]="ON_MANUAL",g))(uA||{}),tC=(g=>(g[g.NPM=0]="NPM",g[g.UNPACK=1]="UNPACK",g[g.PMA=2]="PMA",g[g.NO_PREMULTIPLIED_ALPHA=0]="NO_PREMULTIPLIED_ALPHA",g[g.PREMULTIPLY_ON_UPLOAD=1]="PREMULTIPLY_ON_UPLOAD",g[g.PREMULTIPLIED_ALPHA=2]="PREMULTIPLIED_ALPHA",g))(tC||{}),Oo=(g=>(g[g.NO=0]="NO",g[g.YES=1]="YES",g[g.AUTO=2]="AUTO",g[g.BLEND=0]="BLEND",g[g.CLEAR=1]="CLEAR",g[g.BLIT=2]="BLIT",g))(Oo||{}),HT=(g=>(g[g.AUTO=0]="AUTO",g[g.MANUAL=1]="MANUAL",g))(HT||{}),sr=(g=>(g.LOW="lowp",g.MEDIUM="mediump",g.HIGH="highp",g))(sr||{}),ai=(g=>(g[g.NONE=0]="NONE",g[g.SCISSOR=1]="SCISSOR",g[g.STENCIL=2]="STENCIL",g[g.SPRITE=3]="SPRITE",g[g.COLOR=4]="COLOR",g))(ai||{}),Dhe=(g=>(g[g.RED=1]="RED",g[g.GREEN=2]="GREEN",g[g.BLUE=4]="BLUE",g[g.ALPHA=8]="ALPHA",g))(Dhe||{}),Ci=(g=>(g[g.NONE=0]="NONE",g[g.LOW=2]="LOW",g[g.MEDIUM=4]="MEDIUM",g[g.HIGH=8]="HIGH",g))(Ci||{}),CA=(g=>(g[g.ELEMENT_ARRAY_BUFFER=34963]="ELEMENT_ARRAY_BUFFER",g[g.ARRAY_BUFFER=34962]="ARRAY_BUFFER",g[g.UNIFORM_BUFFER=35345]="UNIFORM_BUFFER",g))(CA||{});const Fhe={createCanvas:(g,e)=>{const I=document.createElement("canvas");return I.width=g,I.height=e,I},getCanvasRenderingContext2D:()=>CanvasRenderingContext2D,getWebGLRenderingContext:()=>WebGLRenderingContext,getNavigator:()=>navigator,getBaseUrl:()=>document.baseURI??window.location.href,getFontFaceSet:()=>document.fonts,fetch:(g,e)=>fetch(g,e),parseXML:g=>new DOMParser().parseFromString(g,"text/xml")},Gt={ADAPTER:Fhe,RESOLUTION:1,CREATE_IMAGE_BITMAP:!1,ROUND_PIXELS:!1};var VK=/iPhone/i,tq=/iPod/i,gq=/iPad/i,Iq=/\biOS-universal(?:.+)Mac\b/i,RK=/\bAndroid(?:.+)Mobile\b/i,iq=/Android/i,Ym=/(?:SD4930UR|\bSilk(?:.+)Mobile\b)/i,vV=/Silk/i,Ea=/Windows Phone/i,nq=/\bWindows(?:.+)ARM\b/i,Cq=/BlackBerry/i,rq=/BB10/i,oq=/Opera Mini/i,Aq=/\b(CriOS|Chrome)(?:.+)Mobile/i,aq=/Mobile(?:.+)Firefox\b/i,sq=function(g){return typeof g<"u"&&g.platform==="MacIntel"&&typeof g.maxTouchPoints=="number"&&g.maxTouchPoints>1&&typeof MSStream>"u"};function u5e(g){return function(e){return e.test(g)}}function lq(g){var e={userAgent:"",platform:"",maxTouchPoints:0};!g&&typeof navigator<"u"?e={userAgent:navigator.userAgent,platform:navigator.platform,maxTouchPoints:navigator.maxTouchPoints||0}:typeof g=="string"?e.userAgent=g:g&&g.userAgent&&(e={userAgent:g.userAgent,platform:g.platform,maxTouchPoints:g.maxTouchPoints||0});var I=e.userAgent,i=I.split("[FBAN");typeof i[1]<"u"&&(I=i[0]),i=I.split("Twitter"),typeof i[1]<"u"&&(I=i[0]);var n=u5e(I),C={apple:{phone:n(VK)&&!n(Ea),ipod:n(tq),tablet:!n(VK)&&(n(gq)||sq(e))&&!n(Ea),universal:n(Iq),device:(n(VK)||n(tq)||n(gq)||n(Iq)||sq(e))&&!n(Ea)},amazon:{phone:n(Ym),tablet:!n(Ym)&&n(vV),device:n(Ym)||n(vV)},android:{phone:!n(Ea)&&n(Ym)||!n(Ea)&&n(RK),tablet:!n(Ea)&&!n(Ym)&&!n(RK)&&(n(vV)||n(iq)),device:!n(Ea)&&(n(Ym)||n(vV)||n(RK)||n(iq))||n(/\bokhttp\b/i)},windows:{phone:n(Ea),tablet:n(nq),device:n(Ea)||n(nq)},other:{blackberry:n(Cq),blackberry10:n(rq),opera:n(oq),firefox:n(aq),chrome:n(Aq),device:n(Cq)||n(rq)||n(oq)||n(aq)||n(Aq)},any:!1,phone:!1,tablet:!1};return C.any=C.apple.device||C.android.device||C.windows.device||C.other.device,C.phone=C.apple.phone||C.android.phone||C.windows.phone,C.tablet=C.apple.tablet||C.android.tablet||C.windows.tablet,C}const d5e=lq.default??lq,eA=d5e(globalThis.navigator);Gt.RETINA_PREFIX=/@([0-9\.]+)x/;Gt.FAIL_IF_MAJOR_PERFORMANCE_CAVEAT=!1;var Ehe={exports:{}};(function(g){var e=Object.prototype.hasOwnProperty,I="~";function i(){}Object.create&&(i.prototype=Object.create(null),new i().__proto__||(I=!1));function n(A,s,a){this.fn=A,this.context=s,this.once=a||!1}function C(A,s,a,l,c){if(typeof a!="function")throw new TypeError("The listener must be a function");var u=new n(a,l||A,c),d=I?I+s:s;return A._events[d]?A._events[d].fn?A._events[d]=[A._events[d],u]:A._events[d].push(u):(A._events[d]=u,A._eventsCount++),A}function r(A,s){--A._eventsCount===0?A._events=new i:delete A._events[s]}function o(){this._events=new i,this._eventsCount=0}o.prototype.eventNames=function(){var s=[],a,l;if(this._eventsCount===0)return s;for(l in a=this._events)e.call(a,l)&&s.push(I?l.slice(1):l);return Object.getOwnPropertySymbols?s.concat(Object.getOwnPropertySymbols(a)):s},o.prototype.listeners=function(s){var a=I?I+s:s,l=this._events[a];if(!l)return[];if(l.fn)return[l.fn];for(var c=0,u=l.length,d=new Array(u);c80*I){o=s=g[0],A=a=g[1];for(var d=I;ds&&(s=l),c>a&&(a=c);u=Math.max(s-o,a-A),u=u!==0?32767/u:0}return Av(C,r,I,o,A,u,0),r}function Mhe(g,e,I,i,n){var C,r;if(n===tM(g,e,I,i)>0)for(C=e;C=e;C-=i)r=cq(C,g[C],g[C+1],r);return r&&NT(r,r.next)&&(sv(r),r=r.next),r}function gh(g,e){if(!g)return g;e||(e=g);var I=g,i;do if(i=!1,!I.steiner&&(NT(I,I.next)||DI(I.prev,I,I.next)===0)){if(sv(I),I=e=I.prev,I===I.next)break;i=!0}else I=I.next;while(i||I!==e);return e}function Av(g,e,I,i,n,C,r){if(g){!r&&C&&S5e(g,i,n,C);for(var o=g,A,s;g.prev!==g.next;){if(A=g.prev,s=g.next,C?f5e(g,i,n,C):m5e(g)){e.push(A.i/I|0),e.push(g.i/I|0),e.push(s.i/I|0),sv(g),g=s.next,o=s.next;continue}if(g=s,g===o){r?r===1?(g=p5e(gh(g),e,I),Av(g,e,I,i,n,C,2)):r===2&&b5e(g,e,I,i,n,C):Av(gh(g),e,I,i,n,C,1);break}}}}function m5e(g){var e=g.prev,I=g,i=g.next;if(DI(e,I,i)>=0)return!1;for(var n=e.x,C=I.x,r=i.x,o=e.y,A=I.y,s=i.y,a=nC?n>r?n:r:C>r?C:r,u=o>A?o>s?o:s:A>s?A:s,d=i.next;d!==e;){if(d.x>=a&&d.x<=c&&d.y>=l&&d.y<=u&&dp(n,o,C,A,r,s,d.x,d.y)&&DI(d.prev,d,d.next)>=0)return!1;d=d.next}return!0}function f5e(g,e,I,i){var n=g.prev,C=g,r=g.next;if(DI(n,C,r)>=0)return!1;for(var o=n.x,A=C.x,s=r.x,a=n.y,l=C.y,c=r.y,u=oA?o>s?o:s:A>s?A:s,m=a>l?a>c?a:c:l>c?l:c,f=qE(u,d,e,I,i),b=qE(h,m,e,I,i),p=g.prevZ,y=g.nextZ;p&&p.z>=f&&y&&y.z<=b;){if(p.x>=u&&p.x<=h&&p.y>=d&&p.y<=m&&p!==n&&p!==r&&dp(o,a,A,l,s,c,p.x,p.y)&&DI(p.prev,p,p.next)>=0||(p=p.prevZ,y.x>=u&&y.x<=h&&y.y>=d&&y.y<=m&&y!==n&&y!==r&&dp(o,a,A,l,s,c,y.x,y.y)&&DI(y.prev,y,y.next)>=0))return!1;y=y.nextZ}for(;p&&p.z>=f;){if(p.x>=u&&p.x<=h&&p.y>=d&&p.y<=m&&p!==n&&p!==r&&dp(o,a,A,l,s,c,p.x,p.y)&&DI(p.prev,p,p.next)>=0)return!1;p=p.prevZ}for(;y&&y.z<=b;){if(y.x>=u&&y.x<=h&&y.y>=d&&y.y<=m&&y!==n&&y!==r&&dp(o,a,A,l,s,c,y.x,y.y)&&DI(y.prev,y,y.next)>=0)return!1;y=y.nextZ}return!0}function p5e(g,e,I){var i=g;do{var n=i.prev,C=i.next.next;!NT(n,C)&&zhe(n,i,i.next,C)&&av(n,C)&&av(C,n)&&(e.push(n.i/I|0),e.push(i.i/I|0),e.push(C.i/I|0),sv(i),sv(i.next),i=g=C),i=i.next}while(i!==g);return gh(i)}function b5e(g,e,I,i,n,C){var r=g;do{for(var o=r.next.next;o!==r.prev;){if(r.i!==o.i&&R5e(r,o)){var A=Phe(r,o);r=gh(r,r.next),A=gh(A,A.next),Av(r,e,I,i,n,C,0),Av(A,e,I,i,n,C,0);return}o=o.next}r=r.next}while(r!==g)}function y5e(g,e,I,i){var n=[],C,r,o,A,s;for(C=0,r=e.length;C=I.next.y&&I.next.y!==I.y){var o=I.x+(n-I.y)*(I.next.x-I.x)/(I.next.y-I.y);if(o<=i&&o>C&&(C=o,r=I.x=I.x&&I.x>=s&&i!==I.x&&dp(nr.x||I.x===r.x&&v5e(r,I)))&&(r=I,l=c)),I=I.next;while(I!==A);return r}function v5e(g,e){return DI(g.prev,g,e.prev)<0&&DI(e.next,g,g.next)<0}function S5e(g,e,I,i){var n=g;do n.z===0&&(n.z=qE(n.x,n.y,e,I,i)),n.prevZ=n.prev,n.nextZ=n.next,n=n.next;while(n!==g);n.prevZ.nextZ=null,n.prevZ=null,w5e(n)}function w5e(g){var e,I,i,n,C,r,o,A,s=1;do{for(I=g,g=null,C=null,r=0;I;){for(r++,i=I,o=0,e=0;e0||A>0&&i;)o!==0&&(A===0||!i||I.z<=i.z)?(n=I,I=I.nextZ,o--):(n=i,i=i.nextZ,A--),C?C.nextZ=n:g=n,n.prevZ=C,C=n;I=i}C.nextZ=null,s*=2}while(r>1);return g}function qE(g,e,I,i,n){return g=(g-I)*n|0,e=(e-i)*n|0,g=(g|g<<8)&16711935,g=(g|g<<4)&252645135,g=(g|g<<2)&858993459,g=(g|g<<1)&1431655765,e=(e|e<<8)&16711935,e=(e|e<<4)&252645135,e=(e|e<<2)&858993459,e=(e|e<<1)&1431655765,g|e<<1}function V5e(g){var e=g,I=g;do(e.x=(g-r)*(C-o)&&(g-r)*(i-o)>=(I-r)*(e-o)&&(I-r)*(C-o)>=(n-r)*(i-o)}function R5e(g,e){return g.next.i!==e.i&&g.prev.i!==e.i&&!W5e(g,e)&&(av(g,e)&&av(e,g)&&X5e(g,e)&&(DI(g.prev,g,e.prev)||DI(g,e.prev,e))||NT(g,e)&&DI(g.prev,g,g.next)>0&&DI(e.prev,e,e.next)>0)}function DI(g,e,I){return(e.y-g.y)*(I.x-e.x)-(e.x-g.x)*(I.y-e.y)}function NT(g,e){return g.x===e.x&&g.y===e.y}function zhe(g,e,I,i){var n=wV(DI(g,e,I)),C=wV(DI(g,e,i)),r=wV(DI(I,i,g)),o=wV(DI(I,i,e));return!!(n!==C&&r!==o||n===0&&SV(g,I,e)||C===0&&SV(g,i,e)||r===0&&SV(I,g,i)||o===0&&SV(I,e,i))}function SV(g,e,I){return e.x<=Math.max(g.x,I.x)&&e.x>=Math.min(g.x,I.x)&&e.y<=Math.max(g.y,I.y)&&e.y>=Math.min(g.y,I.y)}function wV(g){return g>0?1:g<0?-1:0}function W5e(g,e){var I=g;do{if(I.i!==g.i&&I.next.i!==g.i&&I.i!==e.i&&I.next.i!==e.i&&zhe(I,I.next,g,e))return!0;I=I.next}while(I!==g);return!1}function av(g,e){return DI(g.prev,g,g.next)<0?DI(g,e,g.next)>=0&&DI(g,g.prev,e)>=0:DI(g,e,g.prev)<0||DI(g,g.next,e)<0}function X5e(g,e){var I=g,i=!1,n=(g.x+e.x)/2,C=(g.y+e.y)/2;do I.y>C!=I.next.y>C&&I.next.y!==I.y&&n<(I.next.x-I.x)*(C-I.y)/(I.next.y-I.y)+I.x&&(i=!i),I=I.next;while(I!==g);return i}function Phe(g,e){var I=new eM(g.i,g.x,g.y),i=new eM(e.i,e.x,e.y),n=g.next,C=e.prev;return g.next=e,e.prev=g,I.next=n,n.prev=I,i.next=I,I.prev=i,C.next=i,i.prev=C,i}function cq(g,e,I,i){var n=new eM(g,e,I);return i?(n.next=i.next,n.prev=i,i.next.prev=n,i.next=n):(n.prev=n,n.next=n),n}function sv(g){g.next.prev=g.prev,g.prev.next=g.next,g.prevZ&&(g.prevZ.nextZ=g.nextZ),g.nextZ&&(g.nextZ.prevZ=g.prevZ)}function eM(g,e,I){this.i=g,this.x=e,this.y=I,this.prev=null,this.next=null,this.z=0,this.prevZ=null,this.nextZ=null,this.steiner=!1}TT.deviation=function(g,e,I,i){var n=e&&e.length,C=n?e[0]*I:g.length,r=Math.abs(tM(g,0,C,I));if(n)for(var o=0,A=e.length;o0&&(i+=g[n-1].length,I.holes.push(i))}return I};var H5e=R_.exports;const Jhe=jh(H5e);var WX={exports:{}};/*! https://mths.be/punycode v1.4.1 by @mathias */WX.exports;(function(g,e){(function(I){var i=e&&!e.nodeType&&e,n=g&&!g.nodeType&&g,C=typeof ZI=="object"&&ZI;(C.global===C||C.window===C||C.self===C)&&(I=C);var r,o=2147483647,A=36,s=1,a=26,l=38,c=700,u=72,d=128,h="-",m=/^xn--/,f=/[^\x20-\x7E]/,b=/[\x2E\u3002\uFF0E\uFF61]/g,p={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},y=A-s,Z=Math.floor,v=String.fromCharCode,G;function B(J){throw new RangeError(p[J])}function w(J,te){for(var q=J.length,$=[];q--;)$[q]=te(J[q]);return $}function R(J,te){var q=J.split("@"),$="";q.length>1&&($=q[0]+"@",J=q[1]),J=J.replace(b,".");var j=J.split("."),ee=w(j,te).join(".");return $+ee}function S(J){for(var te=[],q=0,$=J.length,j,ee;q<$;)j=J.charCodeAt(q++),j>=55296&&j<=56319&&q<$?(ee=J.charCodeAt(q++),(ee&64512)==56320?te.push(((j&1023)<<10)+(ee&1023)+65536):(te.push(j),q--)):te.push(j);return te}function X(J){return w(J,function(te){var q="";return te>65535&&(te-=65536,q+=v(te>>>10&1023|55296),te=56320|te&1023),q+=v(te),q}).join("")}function W(J){return J-48<10?J-22:J-65<26?J-65:J-97<26?J-97:A}function V(J,te){return J+22+75*(J<26)-((te!=0)<<5)}function H(J,te,q){var $=0;for(J=q?Z(J/c):J>>1,J+=Z(J/te);J>y*a>>1;$+=A)J=Z(J/y);return Z($+(y+1)*J/(J+l))}function D(J){var te=[],q=J.length,$,j=0,ee=d,Q=u,ne,fe,Ce,Ze,Ge,ve,ke,Xe,Oe;for(ne=J.lastIndexOf(h),ne<0&&(ne=0),fe=0;fe=128&&B("not-basic"),te.push(J.charCodeAt(fe));for(Ce=ne>0?ne+1:0;Ce=q&&B("invalid-input"),ke=W(J.charCodeAt(Ce++)),(ke>=A||ke>Z((o-j)/Ge))&&B("overflow"),j+=ke*Ge,Xe=ve<=Q?s:ve>=Q+a?a:ve-Q,!(keZ(o/Oe)&&B("overflow"),Ge*=Oe;$=te.length+1,Q=H(j-Ze,$,Ze==0),Z(j/$)>o-ee&&B("overflow"),ee+=Z(j/$),j%=$,te.splice(j++,0,ee)}return X(te)}function Y(J){var te,q,$,j,ee,Q,ne,fe,Ce,Ze,Ge,ve=[],ke,Xe,Oe,ze;for(J=S(J),ke=J.length,te=d,q=0,ee=u,Q=0;Q=te&&GeZ((o-q)/Xe)&&B("overflow"),q+=(ne-te)*Xe,te=ne,Q=0;Qo&&B("overflow"),Ge==te){for(fe=q,Ce=A;Ze=Ce<=ee?s:Ce>=ee+a?a:Ce-ee,!(fe"u"||!xi?yg:xi(Uint8Array),Td={"%AggregateError%":typeof AggregateError>"u"?yg:AggregateError,"%Array%":Array,"%ArrayBuffer%":typeof ArrayBuffer>"u"?yg:ArrayBuffer,"%ArrayIteratorPrototype%":Km&&xi?xi([][Symbol.iterator]()):yg,"%AsyncFromSyncIteratorPrototype%":yg,"%AsyncFunction%":Bf,"%AsyncGenerator%":Bf,"%AsyncGeneratorFunction%":Bf,"%AsyncIteratorPrototype%":Bf,"%Atomics%":typeof Atomics>"u"?yg:Atomics,"%BigInt%":typeof BigInt>"u"?yg:BigInt,"%BigInt64Array%":typeof BigInt64Array>"u"?yg:BigInt64Array,"%BigUint64Array%":typeof BigUint64Array>"u"?yg:BigUint64Array,"%Boolean%":Boolean,"%DataView%":typeof DataView>"u"?yg:DataView,"%Date%":Date,"%decodeURI%":decodeURI,"%decodeURIComponent%":decodeURIComponent,"%encodeURI%":encodeURI,"%encodeURIComponent%":encodeURIComponent,"%Error%":Error,"%eval%":eval,"%EvalError%":EvalError,"%Float32Array%":typeof Float32Array>"u"?yg:Float32Array,"%Float64Array%":typeof Float64Array>"u"?yg:Float64Array,"%FinalizationRegistry%":typeof FinalizationRegistry>"u"?yg:FinalizationRegistry,"%Function%":Ohe,"%GeneratorFunction%":Bf,"%Int8Array%":typeof Int8Array>"u"?yg:Int8Array,"%Int16Array%":typeof Int16Array>"u"?yg:Int16Array,"%Int32Array%":typeof Int32Array>"u"?yg:Int32Array,"%isFinite%":isFinite,"%isNaN%":isNaN,"%IteratorPrototype%":Km&&xi?xi(xi([][Symbol.iterator]())):yg,"%JSON%":typeof JSON=="object"?JSON:yg,"%Map%":typeof Map>"u"?yg:Map,"%MapIteratorPrototype%":typeof Map>"u"||!Km||!xi?yg:xi(new Map()[Symbol.iterator]()),"%Math%":Math,"%Number%":Number,"%Object%":Object,"%parseFloat%":parseFloat,"%parseInt%":parseInt,"%Promise%":typeof Promise>"u"?yg:Promise,"%Proxy%":typeof Proxy>"u"?yg:Proxy,"%RangeError%":RangeError,"%ReferenceError%":ReferenceError,"%Reflect%":typeof Reflect>"u"?yg:Reflect,"%RegExp%":RegExp,"%Set%":typeof Set>"u"?yg:Set,"%SetIteratorPrototype%":typeof Set>"u"||!Km||!xi?yg:xi(new Set()[Symbol.iterator]()),"%SharedArrayBuffer%":typeof SharedArrayBuffer>"u"?yg:SharedArrayBuffer,"%String%":String,"%StringIteratorPrototype%":Km&&xi?xi(""[Symbol.iterator]()):yg,"%Symbol%":Km?Symbol:yg,"%SyntaxError%":yb,"%ThrowTypeError%":j5e,"%TypedArray%":q5e,"%TypeError%":kp,"%Uint8Array%":typeof Uint8Array>"u"?yg:Uint8Array,"%Uint8ClampedArray%":typeof Uint8ClampedArray>"u"?yg:Uint8ClampedArray,"%Uint16Array%":typeof Uint16Array>"u"?yg:Uint16Array,"%Uint32Array%":typeof Uint32Array>"u"?yg:Uint32Array,"%URIError%":URIError,"%WeakMap%":typeof WeakMap>"u"?yg:WeakMap,"%WeakRef%":typeof WeakRef>"u"?yg:WeakRef,"%WeakSet%":typeof WeakSet>"u"?yg:WeakSet};if(xi)try{null.error}catch(g){var exe=xi(xi(g));Td["%Error.prototype%"]=exe}var txe=function g(e){var I;if(e==="%AsyncFunction%")I=WK("async function () {}");else if(e==="%GeneratorFunction%")I=WK("function* () {}");else if(e==="%AsyncGeneratorFunction%")I=WK("async function* () {}");else if(e==="%AsyncGenerator%"){var i=g("%AsyncGeneratorFunction%");i&&(I=i.prototype)}else if(e==="%AsyncIteratorPrototype%"){var n=g("%AsyncGenerator%");n&&xi&&(I=xi(n.prototype))}return Td[e]=I,I},mq={"%ArrayBufferPrototype%":["ArrayBuffer","prototype"],"%ArrayPrototype%":["Array","prototype"],"%ArrayProto_entries%":["Array","prototype","entries"],"%ArrayProto_forEach%":["Array","prototype","forEach"],"%ArrayProto_keys%":["Array","prototype","keys"],"%ArrayProto_values%":["Array","prototype","values"],"%AsyncFunctionPrototype%":["AsyncFunction","prototype"],"%AsyncGenerator%":["AsyncGeneratorFunction","prototype"],"%AsyncGeneratorPrototype%":["AsyncGeneratorFunction","prototype","prototype"],"%BooleanPrototype%":["Boolean","prototype"],"%DataViewPrototype%":["DataView","prototype"],"%DatePrototype%":["Date","prototype"],"%ErrorPrototype%":["Error","prototype"],"%EvalErrorPrototype%":["EvalError","prototype"],"%Float32ArrayPrototype%":["Float32Array","prototype"],"%Float64ArrayPrototype%":["Float64Array","prototype"],"%FunctionPrototype%":["Function","prototype"],"%Generator%":["GeneratorFunction","prototype"],"%GeneratorPrototype%":["GeneratorFunction","prototype","prototype"],"%Int8ArrayPrototype%":["Int8Array","prototype"],"%Int16ArrayPrototype%":["Int16Array","prototype"],"%Int32ArrayPrototype%":["Int32Array","prototype"],"%JSONParse%":["JSON","parse"],"%JSONStringify%":["JSON","stringify"],"%MapPrototype%":["Map","prototype"],"%NumberPrototype%":["Number","prototype"],"%ObjectPrototype%":["Object","prototype"],"%ObjProto_toString%":["Object","prototype","toString"],"%ObjProto_valueOf%":["Object","prototype","valueOf"],"%PromisePrototype%":["Promise","prototype"],"%PromiseProto_then%":["Promise","prototype","then"],"%Promise_all%":["Promise","all"],"%Promise_reject%":["Promise","reject"],"%Promise_resolve%":["Promise","resolve"],"%RangeErrorPrototype%":["RangeError","prototype"],"%ReferenceErrorPrototype%":["ReferenceError","prototype"],"%RegExpPrototype%":["RegExp","prototype"],"%SetPrototype%":["Set","prototype"],"%SharedArrayBufferPrototype%":["SharedArrayBuffer","prototype"],"%StringPrototype%":["String","prototype"],"%SymbolPrototype%":["Symbol","prototype"],"%SyntaxErrorPrototype%":["SyntaxError","prototype"],"%TypedArrayPrototype%":["TypedArray","prototype"],"%TypeErrorPrototype%":["TypeError","prototype"],"%Uint8ArrayPrototype%":["Uint8Array","prototype"],"%Uint8ClampedArrayPrototype%":["Uint8ClampedArray","prototype"],"%Uint16ArrayPrototype%":["Uint16Array","prototype"],"%Uint32ArrayPrototype%":["Uint32Array","prototype"],"%URIErrorPrototype%":["URIError","prototype"],"%WeakMapPrototype%":["WeakMap","prototype"],"%WeakSetPrototype%":["WeakSet","prototype"]},HS=W_,XX=Q5e,gxe=HS.call(Function.call,Array.prototype.concat),Ixe=HS.call(Function.apply,Array.prototype.splice),fq=HS.call(Function.call,String.prototype.replace),HX=HS.call(Function.call,String.prototype.slice),ixe=HS.call(Function.call,RegExp.prototype.exec),nxe=/[^%.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|%$))/g,Cxe=/\\(\\)?/g,rxe=function(e){var I=HX(e,0,1),i=HX(e,-1);if(I==="%"&&i!=="%")throw new yb("invalid intrinsic syntax, expected closing `%`");if(i==="%"&&I!=="%")throw new yb("invalid intrinsic syntax, expected opening `%`");var n=[];return fq(e,nxe,function(C,r,o,A){n[n.length]=o?fq(A,Cxe,"$1"):r||C}),n},oxe=function(e,I){var i=e,n;if(XX(mq,i)&&(n=mq[i],i="%"+n[0]+"%"),XX(Td,i)){var C=Td[i];if(C===Bf&&(C=txe(i)),typeof C>"u"&&!I)throw new kp("intrinsic "+e+" exists, but is not available. Please file an issue!");return{alias:n,name:i,value:C}}throw new yb("intrinsic "+e+" does not exist!")},em=function(e,I){if(typeof e!="string"||e.length===0)throw new kp("intrinsic name must be a non-empty string");if(arguments.length>1&&typeof I!="boolean")throw new kp('"allowMissing" argument must be a boolean');if(ixe(/^%?[^%]*%?$/,e)===null)throw new yb("`%` may not be present anywhere but at the beginning and end of the intrinsic name");var i=rxe(e),n=i.length>0?i[0]:"",C=oxe("%"+n+"%",I),r=C.name,o=C.value,A=!1,s=C.alias;s&&(n=s[0],Ixe(i,gxe([0,1],s)));for(var a=1,l=!0;a=i.length){var h=Hd(o,c);l=!!h,l&&"get"in h&&!("originalValue"in h.get)?o=h.get:o=o[c]}else l=XX(o,c),o=o[c];l&&!A&&(Td[r]=o)}}return o},Lhe={exports:{}},Axe=em,gM=Axe("%Object.defineProperty%",!0),IM=function(){if(gM)try{return gM({},"a",{value:1}),!0}catch{return!1}return!1};IM.hasArrayLengthDefineBug=function(){if(!IM())return null;try{return gM([],"length",{value:1}).length!==1}catch{return!0}};var _he=IM,axe=em,H1=axe("%Object.getOwnPropertyDescriptor%",!0);if(H1)try{H1([],"length")}catch{H1=null}var Uhe=H1,sxe=_he(),X_=em,JG=sxe&&X_("%Object.defineProperty%",!0);if(JG)try{JG({},"a",{value:1})}catch{JG=!1}var lxe=X_("%SyntaxError%"),xm=X_("%TypeError%"),pq=Uhe,cxe=function(e,I,i){if(!e||typeof e!="object"&&typeof e!="function")throw new xm("`obj` must be an object or a function`");if(typeof I!="string"&&typeof I!="symbol")throw new xm("`property` must be a string or a symbol`");if(arguments.length>3&&typeof arguments[3]!="boolean"&&arguments[3]!==null)throw new xm("`nonEnumerable`, if provided, must be a boolean or null");if(arguments.length>4&&typeof arguments[4]!="boolean"&&arguments[4]!==null)throw new xm("`nonWritable`, if provided, must be a boolean or null");if(arguments.length>5&&typeof arguments[5]!="boolean"&&arguments[5]!==null)throw new xm("`nonConfigurable`, if provided, must be a boolean or null");if(arguments.length>6&&typeof arguments[6]!="boolean")throw new xm("`loose`, if provided, must be a boolean");var n=arguments.length>3?arguments[3]:null,C=arguments.length>4?arguments[4]:null,r=arguments.length>5?arguments[5]:null,o=arguments.length>6?arguments[6]:!1,A=!!pq&&pq(e,I);if(JG)JG(e,I,{configurable:r===null&&A?A.configurable:!r,enumerable:n===null&&A?A.enumerable:!n,value:i,writable:C===null&&A?A.writable:!C});else if(o||!n&&!C&&!r)e[I]=i;else throw new lxe("This environment does not support defining a property as non-configurable, non-writable, or non-enumerable.")},Qhe=em,bq=cxe,uxe=_he(),yq=Uhe,Zq=Qhe("%TypeError%"),dxe=Qhe("%Math.floor%"),hxe=function(e,I){if(typeof e!="function")throw new Zq("`fn` is not a function");if(typeof I!="number"||I<0||I>4294967295||dxe(I)!==I)throw new Zq("`length` must be a positive 32-bit integer");var i=arguments.length>2&&!!arguments[2],n=!0,C=!0;if("length"in e&&yq){var r=yq(e,"length");r&&!r.configurable&&(n=!1),r&&!r.writable&&(C=!1)}return(n||C||!i)&&(uxe?bq(e,"length",I,!0,!0):bq(e,"length",I)),e};(function(g){var e=W_,I=em,i=hxe,n=I("%TypeError%"),C=I("%Function.prototype.apply%"),r=I("%Function.prototype.call%"),o=I("%Reflect.apply%",!0)||e.call(r,C),A=I("%Object.defineProperty%",!0),s=I("%Math.max%");if(A)try{A({},"a",{value:1})}catch{A=null}g.exports=function(c){if(typeof c!="function")throw new n("a function is required");var u=o(e,r,arguments);return i(u,1+s(0,c.length-(arguments.length-1)),!0)};var a=function(){return o(e,C,arguments)};A?A(g.exports,"apply",{value:a}):g.exports.apply=a})(Lhe);var mxe=Lhe.exports,jhe=em,$he=mxe,fxe=$he(jhe("String.prototype.indexOf")),pxe=function(e,I){var i=jhe(e,!!I);return typeof i=="function"&&fxe(e,".prototype.")>-1?$he(i):i};const qhe={},bxe=Object.freeze(Object.defineProperty({__proto__:null,default:qhe},Symbol.toStringTag,{value:"Module"})),yxe=TL(bxe);var H_=typeof Map=="function"&&Map.prototype,HK=Object.getOwnPropertyDescriptor&&H_?Object.getOwnPropertyDescriptor(Map.prototype,"size"):null,TX=H_&&HK&&typeof HK.get=="function"?HK.get:null,Gq=H_&&Map.prototype.forEach,T_=typeof Set=="function"&&Set.prototype,TK=Object.getOwnPropertyDescriptor&&T_?Object.getOwnPropertyDescriptor(Set.prototype,"size"):null,NX=T_&&TK&&typeof TK.get=="function"?TK.get:null,Bq=T_&&Set.prototype.forEach,Zxe=typeof WeakMap=="function"&&WeakMap.prototype,OG=Zxe?WeakMap.prototype.has:null,Gxe=typeof WeakSet=="function"&&WeakSet.prototype,LG=Gxe?WeakSet.prototype.has:null,Bxe=typeof WeakRef=="function"&&WeakRef.prototype,vq=Bxe?WeakRef.prototype.deref:null,vxe=Boolean.prototype.valueOf,Sxe=Object.prototype.toString,wxe=Function.prototype.toString,Vxe=String.prototype.match,N_=String.prototype.slice,Gc=String.prototype.replace,Rxe=String.prototype.toUpperCase,Sq=String.prototype.toLowerCase,eme=RegExp.prototype.test,wq=Array.prototype.concat,EA=Array.prototype.join,Wxe=Array.prototype.slice,Vq=Math.floor,iM=typeof BigInt=="function"?BigInt.prototype.valueOf:null,NK=Object.getOwnPropertySymbols,nM=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Symbol.prototype.toString:null,Zb=typeof Symbol=="function"&&typeof Symbol.iterator=="object",Nn=typeof Symbol=="function"&&Symbol.toStringTag&&(typeof Symbol.toStringTag===Zb||"symbol")?Symbol.toStringTag:null,tme=Object.prototype.propertyIsEnumerable,Rq=(typeof Reflect=="function"?Reflect.getPrototypeOf:Object.getPrototypeOf)||([].__proto__===Array.prototype?function(g){return g.__proto__}:null);function Wq(g,e){if(g===1/0||g===-1/0||g!==g||g&&g>-1e3&&g<1e3||eme.call(/e/,e))return e;var I=/[0-9](?=(?:[0-9]{3})+(?![0-9]))/g;if(typeof g=="number"){var i=g<0?-Vq(-g):Vq(g);if(i!==g){var n=String(i),C=N_.call(e,n.length+1);return Gc.call(n,I,"$&_")+"."+Gc.call(Gc.call(C,/([0-9]{3})/g,"$&_"),/_$/,"")}}return Gc.call(e,I,"$&_")}var CM=yxe,Xq=CM.custom,Hq=Ime(Xq)?Xq:null,Xxe=function g(e,I,i,n){var C=I||{};if($l(C,"quoteStyle")&&C.quoteStyle!=="single"&&C.quoteStyle!=="double")throw new TypeError('option "quoteStyle" must be "single" or "double"');if($l(C,"maxStringLength")&&(typeof C.maxStringLength=="number"?C.maxStringLength<0&&C.maxStringLength!==1/0:C.maxStringLength!==null))throw new TypeError('option "maxStringLength", if provided, must be a positive integer, Infinity, or `null`');var r=$l(C,"customInspect")?C.customInspect:!0;if(typeof r!="boolean"&&r!=="symbol")throw new TypeError("option \"customInspect\", if provided, must be `true`, `false`, or `'symbol'`");if($l(C,"indent")&&C.indent!==null&&C.indent!==" "&&!(parseInt(C.indent,10)===C.indent&&C.indent>0))throw new TypeError('option "indent" must be "\\t", an integer > 0, or `null`');if($l(C,"numericSeparator")&&typeof C.numericSeparator!="boolean")throw new TypeError('option "numericSeparator", if provided, must be `true` or `false`');var o=C.numericSeparator;if(typeof e>"u")return"undefined";if(e===null)return"null";if(typeof e=="boolean")return e?"true":"false";if(typeof e=="string")return nme(e,C);if(typeof e=="number"){if(e===0)return 1/0/e>0?"0":"-0";var A=String(e);return o?Wq(e,A):A}if(typeof e=="bigint"){var s=String(e)+"n";return o?Wq(e,s):s}var a=typeof C.depth>"u"?5:C.depth;if(typeof i>"u"&&(i=0),i>=a&&a>0&&typeof e=="object")return rM(e)?"[Array]":"[Object]";var l=Uxe(C,i);if(typeof n>"u")n=[];else if(ime(n,e)>=0)return"[Circular]";function c(W,V,H){if(V&&(n=Wxe.call(n),n.push(V)),H){var D={depth:C.depth};return $l(C,"quoteStyle")&&(D.quoteStyle=C.quoteStyle),g(W,D,i+1,n)}return g(W,C,i+1,n)}if(typeof e=="function"&&!Tq(e)){var u=Fxe(e),d=VV(e,c);return"[Function"+(u?": "+u:" (anonymous)")+"]"+(d.length>0?" { "+EA.call(d,", ")+" }":"")}if(Ime(e)){var h=Zb?Gc.call(String(e),/^(Symbol\(.*\))_[^)]*$/,"$1"):nM.call(e);return typeof e=="object"&&!Zb?ky(h):h}if(Oxe(e)){for(var m="<"+Sq.call(String(e.nodeName)),f=e.attributes||[],b=0;b",m}if(rM(e)){if(e.length===0)return"[]";var p=VV(e,c);return l&&!_xe(p)?"["+oM(p,l)+"]":"[ "+EA.call(p,", ")+" ]"}if(Nxe(e)){var y=VV(e,c);return!("cause"in Error.prototype)&&"cause"in e&&!tme.call(e,"cause")?"{ ["+String(e)+"] "+EA.call(wq.call("[cause]: "+c(e.cause),y),", ")+" }":y.length===0?"["+String(e)+"]":"{ ["+String(e)+"] "+EA.call(y,", ")+" }"}if(typeof e=="object"&&r){if(Hq&&typeof e[Hq]=="function"&&CM)return CM(e,{depth:a-i});if(r!=="symbol"&&typeof e.inspect=="function")return e.inspect()}if(Exe(e)){var Z=[];return Gq&&Gq.call(e,function(W,V){Z.push(c(V,e,!0)+" => "+c(W,e))}),Nq("Map",TX.call(e),Z,l)}if(Pxe(e)){var v=[];return Bq&&Bq.call(e,function(W){v.push(c(W,e))}),Nq("Set",NX.call(e),v,l)}if(Mxe(e))return kK("WeakMap");if(Jxe(e))return kK("WeakSet");if(zxe(e))return kK("WeakRef");if(Yxe(e))return ky(c(Number(e)));if(xxe(e))return ky(c(iM.call(e)));if(Kxe(e))return ky(vxe.call(e));if(kxe(e))return ky(c(String(e)));if(typeof window<"u"&&e===window)return"{ [object Window] }";if(e===ZI)return"{ [object globalThis] }";if(!Txe(e)&&!Tq(e)){var G=VV(e,c),B=Rq?Rq(e)===Object.prototype:e instanceof Object||e.constructor===Object,w=e instanceof Object?"":"null prototype",R=!B&&Nn&&Object(e)===e&&Nn in e?N_.call(lu(e),8,-1):w?"Object":"",S=B||typeof e.constructor!="function"?"":e.constructor.name?e.constructor.name+" ":"",X=S+(R||w?"["+EA.call(wq.call([],R||[],w||[]),": ")+"] ":"");return G.length===0?X+"{}":l?X+"{"+oM(G,l)+"}":X+"{ "+EA.call(G,", ")+" }"}return String(e)};function gme(g,e,I){var i=(I.quoteStyle||e)==="double"?'"':"'";return i+g+i}function Hxe(g){return Gc.call(String(g),/"/g,""")}function rM(g){return lu(g)==="[object Array]"&&(!Nn||!(typeof g=="object"&&Nn in g))}function Txe(g){return lu(g)==="[object Date]"&&(!Nn||!(typeof g=="object"&&Nn in g))}function Tq(g){return lu(g)==="[object RegExp]"&&(!Nn||!(typeof g=="object"&&Nn in g))}function Nxe(g){return lu(g)==="[object Error]"&&(!Nn||!(typeof g=="object"&&Nn in g))}function kxe(g){return lu(g)==="[object String]"&&(!Nn||!(typeof g=="object"&&Nn in g))}function Yxe(g){return lu(g)==="[object Number]"&&(!Nn||!(typeof g=="object"&&Nn in g))}function Kxe(g){return lu(g)==="[object Boolean]"&&(!Nn||!(typeof g=="object"&&Nn in g))}function Ime(g){if(Zb)return g&&typeof g=="object"&&g instanceof Symbol;if(typeof g=="symbol")return!0;if(!g||typeof g!="object"||!nM)return!1;try{return nM.call(g),!0}catch{}return!1}function xxe(g){if(!g||typeof g!="object"||!iM)return!1;try{return iM.call(g),!0}catch{}return!1}var Dxe=Object.prototype.hasOwnProperty||function(g){return g in this};function $l(g,e){return Dxe.call(g,e)}function lu(g){return Sxe.call(g)}function Fxe(g){if(g.name)return g.name;var e=Vxe.call(wxe.call(g),/^function\s*([\w$]+)/);return e?e[1]:null}function ime(g,e){if(g.indexOf)return g.indexOf(e);for(var I=0,i=g.length;Ie.maxStringLength){var I=g.length-e.maxStringLength,i="... "+I+" more character"+(I>1?"s":"");return nme(N_.call(g,0,e.maxStringLength),e)+i}var n=Gc.call(Gc.call(g,/(['\\])/g,"\\$1"),/[\x00-\x1f]/g,Lxe);return gme(n,"single",e)}function Lxe(g){var e=g.charCodeAt(0),I={8:"b",9:"t",10:"n",12:"f",13:"r"}[e];return I?"\\"+I:"\\x"+(e<16?"0":"")+Rxe.call(e.toString(16))}function ky(g){return"Object("+g+")"}function kK(g){return g+" { ? }"}function Nq(g,e,I,i){var n=i?oM(I,i):EA.call(I,", ");return g+" ("+e+") {"+n+"}"}function _xe(g){for(var e=0;e=0)return!1;return!0}function Uxe(g,e){var I;if(g.indent===" ")I=" ";else if(typeof g.indent=="number"&&g.indent>0)I=EA.call(Array(g.indent+1)," ");else return null;return{base:I,prev:EA.call(Array(e+1),I)}}function oM(g,e){if(g.length===0)return"";var I=` -`+e.prev+e.base;return I+EA.call(g,","+I)+` -`+e.prev}function VV(g,e){var I=rM(g),i=[];if(I){i.length=g.length;for(var n=0;n1;){var I=e.pop(),i=I.obj[I.prop];if(ad(i)){for(var n=[],C=0;C=48&&s<=57||s>=65&&s<=90||s>=97&&s<=122||C===aDe.RFC1738&&(s===40||s===41)){o+=r.charAt(A);continue}if(s<128){o=o+wA[s];continue}if(s<2048){o=o+(wA[192|s>>6]+wA[128|s&63]);continue}if(s<55296||s>=57344){o=o+(wA[224|s>>12]+wA[128|s>>6&63]+wA[128|s&63]);continue}A+=1,s=65536+((s&1023)<<10|r.charCodeAt(A)&1023),o+=wA[240|s>>18]+wA[128|s>>12&63]+wA[128|s>>6&63]+wA[128|s&63]}return o},hDe=function(e){for(var I=[{obj:{o:e},prop:"o"}],i=[],n=0;n"u"&&(p=0)}if(typeof A=="function"?f=A(I,f):f instanceof Date?f=l(f):i==="comma"&&Cs(f)&&(f=T1.maybeMap(f,function(D){return D instanceof Date?l(D):D})),f===null){if(C)return o&&!d?o(I,Rn.encoder,h,"key",c):I;f=""}if(BDe(f)||T1.isBuffer(f)){if(o){var v=d?I:o(I,Rn.encoder,h,"key",c);return[u(v)+"="+u(o(f,Rn.encoder,h,"value",c))]}return[u(I)+"="+u(String(f))]}var G=[];if(typeof f>"u")return G;var B;if(i==="comma"&&Cs(f))d&&o&&(f=T1.maybeMap(f,o)),B=[{value:f.length>0?f.join(",")||null:void 0}];else if(Cs(A))B=A;else{var w=Object.keys(f);B=s?w.sort(s):w}for(var R=n&&Cs(f)&&f.length===1?I+"[]":I,S=0;S"u"?Rn.allowDots:!!e.allowDots,charset:I,charsetSentinel:typeof e.charsetSentinel=="boolean"?e.charsetSentinel:Rn.charsetSentinel,delimiter:typeof e.delimiter>"u"?Rn.delimiter:e.delimiter,encode:typeof e.encode=="boolean"?e.encode:Rn.encode,encoder:typeof e.encoder=="function"?e.encoder:Rn.encoder,encodeValuesOnly:typeof e.encodeValuesOnly=="boolean"?e.encodeValuesOnly:Rn.encodeValuesOnly,filter:C,format:i,formatter:n,serializeDate:typeof e.serializeDate=="function"?e.serializeDate:Rn.serializeDate,skipNulls:typeof e.skipNulls=="boolean"?e.skipNulls:Rn.skipNulls,sort:typeof e.sort=="function"?e.sort:null,strictNullHandling:typeof e.strictNullHandling=="boolean"?e.strictNullHandling:Rn.strictNullHandling}},wDe=function(g,e){var I=g,i=SDe(e),n,C;typeof i.filter=="function"?(C=i.filter,I=C("",I)):Cs(i.filter)&&(C=i.filter,n=C);var r=[];if(typeof I!="object"||I===null)return"";var o;e&&e.arrayFormat in kq?o=e.arrayFormat:e&&"indices"in e?o=e.indices?"indices":"repeat":o="indices";var A=kq[o];if(e&&"commaRoundTrip"in e&&typeof e.commaRoundTrip!="boolean")throw new TypeError("`commaRoundTrip` must be a boolean, or absent");var s=A==="comma"&&e&&e.commaRoundTrip;n||(n=Object.keys(I)),i.sort&&n.sort(i.sort);for(var a=ome(),l=0;l0?d+u:""},Gb=rme,AM=Object.prototype.hasOwnProperty,VDe=Array.isArray,Ki={allowDots:!1,allowPrototypes:!1,allowSparse:!1,arrayLimit:20,charset:"utf-8",charsetSentinel:!1,comma:!1,decoder:Gb.decode,delimiter:"&",depth:5,ignoreQueryPrefix:!1,interpretNumericEntities:!1,parameterLimit:1e3,parseArrays:!0,plainObjects:!1,strictNullHandling:!1},RDe=function(g){return g.replace(/&#(\d+);/g,function(e,I){return String.fromCharCode(parseInt(I,10))})},ame=function(g,e){return g&&typeof g=="string"&&e.comma&&g.indexOf(",")>-1?g.split(","):g},WDe="utf8=%26%2310003%3B",XDe="utf8=%E2%9C%93",HDe=function(e,I){var i={__proto__:null},n=I.ignoreQueryPrefix?e.replace(/^\?/,""):e,C=I.parameterLimit===1/0?void 0:I.parameterLimit,r=n.split(I.delimiter,C),o=-1,A,s=I.charset;if(I.charsetSentinel)for(A=0;A-1&&(d=VDe(d)?[d]:d),AM.call(i,u)?i[u]=Gb.combine(i[u],d):i[u]=d}return i},TDe=function(g,e,I,i){for(var n=i?e:ame(e,I),C=g.length-1;C>=0;--C){var r,o=g[C];if(o==="[]"&&I.parseArrays)r=[].concat(n);else{r=I.plainObjects?Object.create(null):{};var A=o.charAt(0)==="["&&o.charAt(o.length-1)==="]"?o.slice(1,-1):o,s=parseInt(A,10);!I.parseArrays&&A===""?r={0:n}:!isNaN(s)&&o!==A&&String(s)===A&&s>=0&&I.parseArrays&&s<=I.arrayLimit?(r=[],r[s]=n):A!=="__proto__"&&(r[A]=n)}n=r}return n},NDe=function(e,I,i,n){if(e){var C=i.allowDots?e.replace(/\.([^.[]+)/g,"[$1]"):e,r=/(\[[^[\]]*])/,o=/(\[[^[\]]*])/g,A=i.depth>0&&r.exec(C),s=A?C.slice(0,A.index):C,a=[];if(s){if(!i.plainObjects&&AM.call(Object.prototype,s)&&!i.allowPrototypes)return;a.push(s)}for(var l=0;i.depth>0&&(A=o.exec(C))!==null&&l"u"?Ki.charset:e.charset;return{allowDots:typeof e.allowDots>"u"?Ki.allowDots:!!e.allowDots,allowPrototypes:typeof e.allowPrototypes=="boolean"?e.allowPrototypes:Ki.allowPrototypes,allowSparse:typeof e.allowSparse=="boolean"?e.allowSparse:Ki.allowSparse,arrayLimit:typeof e.arrayLimit=="number"?e.arrayLimit:Ki.arrayLimit,charset:I,charsetSentinel:typeof e.charsetSentinel=="boolean"?e.charsetSentinel:Ki.charsetSentinel,comma:typeof e.comma=="boolean"?e.comma:Ki.comma,decoder:typeof e.decoder=="function"?e.decoder:Ki.decoder,delimiter:typeof e.delimiter=="string"||Gb.isRegExp(e.delimiter)?e.delimiter:Ki.delimiter,depth:typeof e.depth=="number"||e.depth===!1?+e.depth:Ki.depth,ignoreQueryPrefix:e.ignoreQueryPrefix===!0,interpretNumericEntities:typeof e.interpretNumericEntities=="boolean"?e.interpretNumericEntities:Ki.interpretNumericEntities,parameterLimit:typeof e.parameterLimit=="number"?e.parameterLimit:Ki.parameterLimit,parseArrays:e.parseArrays!==!1,plainObjects:typeof e.plainObjects=="boolean"?e.plainObjects:Ki.plainObjects,strictNullHandling:typeof e.strictNullHandling=="boolean"?e.strictNullHandling:Ki.strictNullHandling}},YDe=function(g,e){var I=kDe(e);if(g===""||g===null||typeof g>"u")return I.plainObjects?Object.create(null):{};for(var i=typeof g=="string"?HDe(g,I):g,n=I.plainObjects?Object.create(null):{},C=Object.keys(i),r=0;r",'"',"`"," ","\r",` -`," "],ODe=["{","}","|","\\","^","`"].concat(JDe),aM=["'"].concat(ODe),Kq=["%","/","?",";","#"].concat(aM),xq=["/","?","#"],LDe=255,Dq=/^[+a-z0-9A-Z_-]{0,63}$/,_De=/^([+a-z0-9A-Z_-]{0,63})(.*)$/,UDe={javascript:!0,"javascript:":!0},sM={javascript:!0,"javascript:":!0},Yp={http:!0,https:!0,ftp:!0,gopher:!0,file:!0,"http:":!0,"https:":!0,"ftp:":!0,"gopher:":!0,"file:":!0},lM=FDe;function kT(g,e,I){if(g&&typeof g=="object"&&g instanceof rA)return g;var i=new rA;return i.parse(g,e,I),i}rA.prototype.parse=function(g,e,I){if(typeof g!="string")throw new TypeError("Parameter 'url' must be a string, not "+typeof g);var i=g.indexOf("?"),n=i!==-1&&i127?Z+="x":Z+=y[v];if(!Z.match(Dq)){var B=b.slice(0,u),w=b.slice(u+1),R=y.match(_De);R&&(B.push(R[1]),w.unshift(R[2])),w.length&&(o="/"+w.join(".")+o),this.hostname=B.join(".");break}}}this.hostname.length>LDe?this.hostname="":this.hostname=this.hostname.toLowerCase(),f||(this.hostname=EDe.toASCII(this.hostname));var S=this.port?":"+this.port:"",X=this.hostname||"";this.host=X+S,this.href+=this.host,f&&(this.hostname=this.hostname.substr(1,this.hostname.length-2),o[0]!=="/"&&(o="/"+o))}if(!UDe[a])for(var u=0,p=aM.length;u0?I.host.split("@"):!1;Z&&(I.auth=Z.shift(),I.hostname=Z.shift(),I.host=I.hostname)}return I.search=g.search,I.query=g.query,(I.pathname!==null||I.search!==null)&&(I.path=(I.pathname?I.pathname:"")+(I.search?I.search:"")),I.href=I.format(),I}if(!b.length)return I.pathname=null,I.search?I.path="/"+I.search:I.path=null,I.href=I.format(),I;for(var v=b.slice(-1)[0],G=(I.host||g.host||b.length>1)&&(v==="."||v==="..")||v==="",B=0,w=b.length;w>=0;w--)v=b[w],v==="."?b.splice(w,1):v===".."?(b.splice(w,1),B++):B&&(b.splice(w,1),B--);if(!m&&!f)for(;B--;B)b.unshift("..");m&&b[0]!==""&&(!b[0]||b[0].charAt(0)!=="/")&&b.unshift(""),G&&b.join("/").substr(-1)!=="/"&&b.push("");var R=b[0]===""||b[0]&&b[0].charAt(0)==="/";if(y){I.hostname=R?"":b.length?b.shift():"",I.host=I.hostname;var Z=I.host&&I.host.indexOf("@")>0?I.host.split("@"):!1;Z&&(I.auth=Z.shift(),I.hostname=Z.shift(),I.host=I.hostname)}return m=m||I.host&&b.length,m&&!R&&b.unshift(""),b.length>0?I.pathname=b.join("/"):(I.pathname=null,I.path=null),(I.pathname!==null||I.search!==null)&&(I.path=(I.pathname?I.pathname:"")+(I.search?I.search:"")),I.auth=g.auth||I.auth,I.slashes=I.slashes||g.slashes,I.href=I.format(),I};rA.prototype.parseHost=function(){var g=this.host,e=zDe.exec(g);e&&(e=e[0],e!==":"&&(this.port=e.substr(1)),g=g.substr(0,g.length-e.length)),g&&(this.hostname=g)};var $De=kT,qDe=jDe,eFe=QDe;const Fq={};function tg(g,e,I=3){if(Fq[e])return;let i=new Error().stack;typeof i>"u"?console.warn("PixiJS Deprecation Warning: ",`${e} -Deprecated since v${g}`):(i=i.split(` -`).splice(I).join(` -`),console.groupCollapsed?(console.groupCollapsed("%cPixiJS Deprecation Warning: %c%s","color:#614108;background:#fffbe6","font-weight:normal;color:#614108;background:#fffbe6",`${e} -Deprecated since v${g}`),console.warn(i),console.groupEnd()):(console.warn("PixiJS Deprecation Warning: ",`${e} -Deprecated since v${g}`),console.warn(i))),Fq[e]=!0}const tFe={get parse(){return tg("7.3.0","utils.url.parse is deprecated, use native URL API instead."),$De},get format(){return tg("7.3.0","utils.url.format is deprecated, use native URL API instead."),eFe},get resolve(){return tg("7.3.0","utils.url.resolve is deprecated, use native URL API instead."),qDe}};function bo(g){if(typeof g!="string")throw new TypeError(`Path must be a string. Received ${JSON.stringify(g)}`)}function Yy(g){return g.split("?")[0].split("#")[0]}function gFe(g){return g.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function IFe(g,e,I){return g.replace(new RegExp(gFe(e),"g"),I)}function iFe(g,e){let I="",i=0,n=-1,C=0,r=-1;for(let o=0;o<=g.length;++o){if(o2){const A=I.lastIndexOf("/");if(A!==I.length-1){A===-1?(I="",i=0):(I=I.slice(0,A),i=I.length-1-I.lastIndexOf("/")),n=o,C=0;continue}}else if(I.length===2||I.length===1){I="",i=0,n=o,C=0;continue}}e&&(I.length>0?I+="/..":I="..",i=2)}else I.length>0?I+=`/${g.slice(n+1,o)}`:I=g.slice(n+1,o),i=o-n-1;n=o,C=0}else r===46&&C!==-1?++C:C=-1}return I}const fi={toPosix(g){return IFe(g,"\\","/")},isUrl(g){return/^https?:/.test(this.toPosix(g))},isDataUrl(g){return/^data:([a-z]+\/[a-z0-9-+.]+(;[a-z0-9-.!#$%*+.{}|~`]+=[a-z0-9-.!#$%*+.{}()_|~`]+)*)?(;base64)?,([a-z0-9!$&',()*+;=\-._~:@\/?%\s<>]*?)$/i.test(g)},isBlobUrl(g){return g.startsWith("blob:")},hasProtocol(g){return/^[^/:]+:/.test(this.toPosix(g))},getProtocol(g){bo(g),g=this.toPosix(g);const e=/^file:\/\/\//.exec(g);if(e)return e[0];const I=/^[^/:]+:\/{0,2}/.exec(g);return I?I[0]:""},toAbsolute(g,e,I){if(bo(g),this.isDataUrl(g)||this.isBlobUrl(g))return g;const i=Yy(this.toPosix(e??Gt.ADAPTER.getBaseUrl())),n=Yy(this.toPosix(I??this.rootname(i)));return g=this.toPosix(g),g.startsWith("/")?fi.join(n,g.slice(1)):this.isAbsolute(g)?g:this.join(i,g)},normalize(g){if(bo(g),g.length===0)return".";if(this.isDataUrl(g)||this.isBlobUrl(g))return g;g=this.toPosix(g);let e="";const I=g.startsWith("/");this.hasProtocol(g)&&(e=this.rootname(g),g=g.slice(e.length));const i=g.endsWith("/");return g=iFe(g,!1),g.length>0&&i&&(g+="/"),I?`/${g}`:e+g},isAbsolute(g){return bo(g),g=this.toPosix(g),this.hasProtocol(g)?!0:g.startsWith("/")},join(...g){if(g.length===0)return".";let e;for(let I=0;I0)if(e===void 0)e=i;else{const n=g[I-1]??"";this.extname(n)?e+=`/../${i}`:e+=`/${i}`}}return e===void 0?".":this.normalize(e)},dirname(g){if(bo(g),g.length===0)return".";g=this.toPosix(g);let e=g.charCodeAt(0);const I=e===47;let i=-1,n=!0;const C=this.getProtocol(g),r=g;g=g.slice(C.length);for(let o=g.length-1;o>=1;--o)if(e=g.charCodeAt(o),e===47){if(!n){i=o;break}}else n=!1;return i===-1?I?"/":this.isUrl(r)?C+g:C:I&&i===1?"//":C+g.slice(0,i)},rootname(g){bo(g),g=this.toPosix(g);let e="";if(g.startsWith("/")?e="/":e=this.getProtocol(g),this.isUrl(g)){const I=g.indexOf("/",e.length);I!==-1?e=g.slice(0,I):e=g,e.endsWith("/")||(e+="/")}return e},basename(g,e){bo(g),e&&bo(e),g=Yy(this.toPosix(g));let I=0,i=-1,n=!0,C;if(e!==void 0&&e.length>0&&e.length<=g.length){if(e.length===g.length&&e===g)return"";let r=e.length-1,o=-1;for(C=g.length-1;C>=0;--C){const A=g.charCodeAt(C);if(A===47){if(!n){I=C+1;break}}else o===-1&&(n=!1,o=C+1),r>=0&&(A===e.charCodeAt(r)?--r===-1&&(i=C):(r=-1,i=o))}return I===i?i=o:i===-1&&(i=g.length),g.slice(I,i)}for(C=g.length-1;C>=0;--C)if(g.charCodeAt(C)===47){if(!n){I=C+1;break}}else i===-1&&(n=!1,i=C+1);return i===-1?"":g.slice(I,i)},extname(g){bo(g),g=Yy(this.toPosix(g));let e=-1,I=0,i=-1,n=!0,C=0;for(let r=g.length-1;r>=0;--r){const o=g.charCodeAt(r);if(o===47){if(!n){I=r+1;break}continue}i===-1&&(n=!1,i=r+1),o===46?e===-1?e=r:C!==1&&(C=1):e!==-1&&(C=-1)}return e===-1||i===-1||C===0||C===1&&e===i-1&&e===I+1?"":g.slice(e,i)},parse(g){bo(g);const e={root:"",dir:"",base:"",ext:"",name:""};if(g.length===0)return e;g=Yy(this.toPosix(g));let I=g.charCodeAt(0);const i=this.isAbsolute(g);let n;e.root=this.rootname(g),i||this.hasProtocol(g)?n=1:n=0;let C=-1,r=0,o=-1,A=!0,s=g.length-1,a=0;for(;s>=n;--s){if(I=g.charCodeAt(s),I===47){if(!A){r=s+1;break}continue}o===-1&&(A=!1,o=s+1),I===46?C===-1?C=s:a!==1&&(a=1):C!==-1&&(a=-1)}return C===-1||o===-1||a===0||a===1&&C===o-1&&C===r+1?o!==-1&&(r===0&&i?e.base=e.name=g.slice(1,o):e.base=e.name=g.slice(r,o)):(r===0&&i?(e.name=g.slice(1,C),e.base=g.slice(1,o)):(e.name=g.slice(r,C),e.base=g.slice(r,o)),e.ext=g.slice(C,o)),e.dir=this.dirname(g),e},sep:"/",delimiter:":"};let DK;async function sme(){return DK??(DK=(async()=>{var C;const g=document.createElement("canvas").getContext("webgl");if(!g)return tC.UNPACK;const e=await new Promise(r=>{const o=document.createElement("video");o.onloadeddata=()=>r(o),o.onerror=()=>r(null),o.autoplay=!1,o.crossOrigin="anonymous",o.preload="auto",o.src="data:video/webm;base64,GkXfo59ChoEBQveBAULygQRC84EIQoKEd2VibUKHgQJChYECGFOAZwEAAAAAAAHTEU2bdLpNu4tTq4QVSalmU6yBoU27i1OrhBZUrmtTrIHGTbuMU6uEElTDZ1OsggEXTbuMU6uEHFO7a1OsggG97AEAAAAAAABZAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAVSalmoCrXsYMPQkBNgIRMYXZmV0GETGF2ZkSJiEBEAAAAAAAAFlSua8yuAQAAAAAAAEPXgQFzxYgAAAAAAAAAAZyBACK1nIN1bmSIgQCGhVZfVlA5g4EBI+ODhAJiWgDglLCBArqBApqBAlPAgQFVsIRVuYEBElTDZ9Vzc9JjwItjxYgAAAAAAAAAAWfInEWjh0VOQ09ERVJEh49MYXZjIGxpYnZweC12cDlnyKJFo4hEVVJBVElPTkSHlDAwOjAwOjAwLjA0MDAwMDAwMAAAH0O2dcfngQCgwqGggQAAAIJJg0IAABAAFgA4JBwYSgAAICAAEb///4r+AAB1oZ2mm+6BAaWWgkmDQgAAEAAWADgkHBhKAAAgIABIQBxTu2uRu4+zgQC3iveBAfGCAXHwgQM=",o.load()});if(!e)return tC.UNPACK;const I=g.createTexture();g.bindTexture(g.TEXTURE_2D,I);const i=g.createFramebuffer();g.bindFramebuffer(g.FRAMEBUFFER,i),g.framebufferTexture2D(g.FRAMEBUFFER,g.COLOR_ATTACHMENT0,g.TEXTURE_2D,I,0),g.pixelStorei(g.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),g.pixelStorei(g.UNPACK_COLORSPACE_CONVERSION_WEBGL,g.NONE),g.texImage2D(g.TEXTURE_2D,0,g.RGBA,g.RGBA,g.UNSIGNED_BYTE,e);const n=new Uint8Array(4);return g.readPixels(0,0,1,1,g.RGBA,g.UNSIGNED_BYTE,n),g.deleteFramebuffer(i),g.deleteTexture(I),(C=g.getExtension("WEBGL_lose_context"))==null||C.loseContext(),n[0]<=n[3]?tC.PMA:tC.UNPACK})()),DK}function nFe(){tg("7.0.0","skipHello is deprecated, please use settings.RENDER_OPTIONS.hello")}function CFe(){tg("7.0.0",`sayHello is deprecated, please use Renderer's "hello" option`)}let FK;function lme(){return typeof FK>"u"&&(FK=function(){var e;const g={stencil:!0,failIfMajorPerformanceCaveat:Gt.FAIL_IF_MAJOR_PERFORMANCE_CAVEAT};try{if(!Gt.ADAPTER.getWebGLRenderingContext())return!1;const I=Gt.ADAPTER.createCanvas();let i=I.getContext("webgl",g)||I.getContext("experimental-webgl",g);const n=!!((e=i==null?void 0:i.getContextAttributes())!=null&&e.stencil);if(i){const C=i.getExtension("WEBGL_lose_context");C&&C.loseContext()}return i=null,n}catch{return!1}}()),FK}var rFe={grad:.9,turn:360,rad:360/(2*Math.PI)},Ma=function(g){return typeof g=="string"?g.length>0:typeof g=="number"},Mi=function(g,e,I){return e===void 0&&(e=0),I===void 0&&(I=Math.pow(10,e)),Math.round(I*g)/I+0},Qr=function(g,e,I){return e===void 0&&(e=0),I===void 0&&(I=1),g>I?I:g>e?g:e},cme=function(g){return(g=isFinite(g)?g%360:0)>0?g:g+360},Eq=function(g){return{r:Qr(g.r,0,255),g:Qr(g.g,0,255),b:Qr(g.b,0,255),a:Qr(g.a)}},EK=function(g){return{r:Mi(g.r),g:Mi(g.g),b:Mi(g.b),a:Mi(g.a,3)}},oFe=/^#([0-9a-f]{3,8})$/i,XV=function(g){var e=g.toString(16);return e.length<2?"0"+e:e},ume=function(g){var e=g.r,I=g.g,i=g.b,n=g.a,C=Math.max(e,I,i),r=C-Math.min(e,I,i),o=r?C===e?(I-i)/r:C===I?2+(i-e)/r:4+(e-I)/r:0;return{h:60*(o<0?o+6:o),s:C?r/C*100:0,v:C/255*100,a:n}},dme=function(g){var e=g.h,I=g.s,i=g.v,n=g.a;e=e/360*6,I/=100,i/=100;var C=Math.floor(e),r=i*(1-I),o=i*(1-(e-C)*I),A=i*(1-(1-e+C)*I),s=C%6;return{r:255*[i,o,r,r,A,i][s],g:255*[A,i,i,o,r,r][s],b:255*[r,r,A,i,i,o][s],a:n}},Mq=function(g){return{h:cme(g.h),s:Qr(g.s,0,100),l:Qr(g.l,0,100),a:Qr(g.a)}},zq=function(g){return{h:Mi(g.h),s:Mi(g.s),l:Mi(g.l),a:Mi(g.a,3)}},Pq=function(g){return dme((I=(e=g).s,{h:e.h,s:(I*=((i=e.l)<50?i:100-i)/100)>0?2*I/(i+I)*100:0,v:i+I,a:e.a}));var e,I,i},UG=function(g){return{h:(e=ume(g)).h,s:(n=(200-(I=e.s))*(i=e.v)/100)>0&&n<200?I*i/100/(n<=100?n:200-n)*100:0,l:n/2,a:e.a};var e,I,i,n},AFe=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,aFe=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,sFe=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,lFe=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,cM={string:[[function(g){var e=oFe.exec(g);return e?(g=e[1]).length<=4?{r:parseInt(g[0]+g[0],16),g:parseInt(g[1]+g[1],16),b:parseInt(g[2]+g[2],16),a:g.length===4?Mi(parseInt(g[3]+g[3],16)/255,2):1}:g.length===6||g.length===8?{r:parseInt(g.substr(0,2),16),g:parseInt(g.substr(2,2),16),b:parseInt(g.substr(4,2),16),a:g.length===8?Mi(parseInt(g.substr(6,2),16)/255,2):1}:null:null},"hex"],[function(g){var e=sFe.exec(g)||lFe.exec(g);return e?e[2]!==e[4]||e[4]!==e[6]?null:Eq({r:Number(e[1])/(e[2]?100/255:1),g:Number(e[3])/(e[4]?100/255:1),b:Number(e[5])/(e[6]?100/255:1),a:e[7]===void 0?1:Number(e[7])/(e[8]?100:1)}):null},"rgb"],[function(g){var e=AFe.exec(g)||aFe.exec(g);if(!e)return null;var I,i,n=Mq({h:(I=e[1],i=e[2],i===void 0&&(i="deg"),Number(I)*(rFe[i]||1)),s:Number(e[3]),l:Number(e[4]),a:e[5]===void 0?1:Number(e[5])/(e[6]?100:1)});return Pq(n)},"hsl"]],object:[[function(g){var e=g.r,I=g.g,i=g.b,n=g.a,C=n===void 0?1:n;return Ma(e)&&Ma(I)&&Ma(i)?Eq({r:Number(e),g:Number(I),b:Number(i),a:Number(C)}):null},"rgb"],[function(g){var e=g.h,I=g.s,i=g.l,n=g.a,C=n===void 0?1:n;if(!Ma(e)||!Ma(I)||!Ma(i))return null;var r=Mq({h:Number(e),s:Number(I),l:Number(i),a:Number(C)});return Pq(r)},"hsl"],[function(g){var e=g.h,I=g.s,i=g.v,n=g.a,C=n===void 0?1:n;if(!Ma(e)||!Ma(I)||!Ma(i))return null;var r=function(o){return{h:cme(o.h),s:Qr(o.s,0,100),v:Qr(o.v,0,100),a:Qr(o.a)}}({h:Number(e),s:Number(I),v:Number(i),a:Number(C)});return dme(r)},"hsv"]]},Jq=function(g,e){for(var I=0;I=.5},g.prototype.toHex=function(){return e=EK(this.rgba),I=e.r,i=e.g,n=e.b,r=(C=e.a)<1?XV(Mi(255*C)):"","#"+XV(I)+XV(i)+XV(n)+r;var e,I,i,n,C,r},g.prototype.toRgb=function(){return EK(this.rgba)},g.prototype.toRgbString=function(){return e=EK(this.rgba),I=e.r,i=e.g,n=e.b,(C=e.a)<1?"rgba("+I+", "+i+", "+n+", "+C+")":"rgb("+I+", "+i+", "+n+")";var e,I,i,n,C},g.prototype.toHsl=function(){return zq(UG(this.rgba))},g.prototype.toHslString=function(){return e=zq(UG(this.rgba)),I=e.h,i=e.s,n=e.l,(C=e.a)<1?"hsla("+I+", "+i+"%, "+n+"%, "+C+")":"hsl("+I+", "+i+"%, "+n+"%)";var e,I,i,n,C},g.prototype.toHsv=function(){return e=ume(this.rgba),{h:Mi(e.h),s:Mi(e.s),v:Mi(e.v),a:Mi(e.a,3)};var e},g.prototype.invert=function(){return YA({r:255-(e=this.rgba).r,g:255-e.g,b:255-e.b,a:e.a});var e},g.prototype.saturate=function(e){return e===void 0&&(e=.1),YA(MK(this.rgba,e))},g.prototype.desaturate=function(e){return e===void 0&&(e=.1),YA(MK(this.rgba,-e))},g.prototype.grayscale=function(){return YA(MK(this.rgba,-1))},g.prototype.lighten=function(e){return e===void 0&&(e=.1),YA(Oq(this.rgba,e))},g.prototype.darken=function(e){return e===void 0&&(e=.1),YA(Oq(this.rgba,-e))},g.prototype.rotate=function(e){return e===void 0&&(e=15),this.hue(this.hue()+e)},g.prototype.alpha=function(e){return typeof e=="number"?YA({r:(I=this.rgba).r,g:I.g,b:I.b,a:e}):Mi(this.rgba.a,3);var I},g.prototype.hue=function(e){var I=UG(this.rgba);return typeof e=="number"?YA({h:e,s:I.s,l:I.l,a:I.a}):Mi(I.h)},g.prototype.isEqual=function(e){return this.toHex()===YA(e).toHex()},g}(),YA=function(g){return g instanceof uM?g:new uM(g)},Lq=[],uFe=function(g){g.forEach(function(e){Lq.indexOf(e)<0&&(e(uM,cM),Lq.push(e))})};function dFe(g,e){var I={white:"#ffffff",bisque:"#ffe4c4",blue:"#0000ff",cadetblue:"#5f9ea0",chartreuse:"#7fff00",chocolate:"#d2691e",coral:"#ff7f50",antiquewhite:"#faebd7",aqua:"#00ffff",azure:"#f0ffff",whitesmoke:"#f5f5f5",papayawhip:"#ffefd5",plum:"#dda0dd",blanchedalmond:"#ffebcd",black:"#000000",gold:"#ffd700",goldenrod:"#daa520",gainsboro:"#dcdcdc",cornsilk:"#fff8dc",cornflowerblue:"#6495ed",burlywood:"#deb887",aquamarine:"#7fffd4",beige:"#f5f5dc",crimson:"#dc143c",cyan:"#00ffff",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkkhaki:"#bdb76b",darkgray:"#a9a9a9",darkgreen:"#006400",darkgrey:"#a9a9a9",peachpuff:"#ffdab9",darkmagenta:"#8b008b",darkred:"#8b0000",darkorchid:"#9932cc",darkorange:"#ff8c00",darkslateblue:"#483d8b",gray:"#808080",darkslategray:"#2f4f4f",darkslategrey:"#2f4f4f",deeppink:"#ff1493",deepskyblue:"#00bfff",wheat:"#f5deb3",firebrick:"#b22222",floralwhite:"#fffaf0",ghostwhite:"#f8f8ff",darkviolet:"#9400d3",magenta:"#ff00ff",green:"#008000",dodgerblue:"#1e90ff",grey:"#808080",honeydew:"#f0fff0",hotpink:"#ff69b4",blueviolet:"#8a2be2",forestgreen:"#228b22",lawngreen:"#7cfc00",indianred:"#cd5c5c",indigo:"#4b0082",fuchsia:"#ff00ff",brown:"#a52a2a",maroon:"#800000",mediumblue:"#0000cd",lightcoral:"#f08080",darkturquoise:"#00ced1",lightcyan:"#e0ffff",ivory:"#fffff0",lightyellow:"#ffffe0",lightsalmon:"#ffa07a",lightseagreen:"#20b2aa",linen:"#faf0e6",mediumaquamarine:"#66cdaa",lemonchiffon:"#fffacd",lime:"#00ff00",khaki:"#f0e68c",mediumseagreen:"#3cb371",limegreen:"#32cd32",mediumspringgreen:"#00fa9a",lightskyblue:"#87cefa",lightblue:"#add8e6",midnightblue:"#191970",lightpink:"#ffb6c1",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",mintcream:"#f5fffa",lightslategray:"#778899",lightslategrey:"#778899",navajowhite:"#ffdead",navy:"#000080",mediumvioletred:"#c71585",powderblue:"#b0e0e6",palegoldenrod:"#eee8aa",oldlace:"#fdf5e6",paleturquoise:"#afeeee",mediumturquoise:"#48d1cc",mediumorchid:"#ba55d3",rebeccapurple:"#663399",lightsteelblue:"#b0c4de",mediumslateblue:"#7b68ee",thistle:"#d8bfd8",tan:"#d2b48c",orchid:"#da70d6",mediumpurple:"#9370db",purple:"#800080",pink:"#ffc0cb",skyblue:"#87ceeb",springgreen:"#00ff7f",palegreen:"#98fb98",red:"#ff0000",yellow:"#ffff00",slateblue:"#6a5acd",lavenderblush:"#fff0f5",peru:"#cd853f",palevioletred:"#db7093",violet:"#ee82ee",teal:"#008080",slategray:"#708090",slategrey:"#708090",aliceblue:"#f0f8ff",darkseagreen:"#8fbc8f",darkolivegreen:"#556b2f",greenyellow:"#adff2f",seagreen:"#2e8b57",seashell:"#fff5ee",tomato:"#ff6347",silver:"#c0c0c0",sienna:"#a0522d",lavender:"#e6e6fa",lightgreen:"#90ee90",orange:"#ffa500",orangered:"#ff4500",steelblue:"#4682b4",royalblue:"#4169e1",turquoise:"#40e0d0",yellowgreen:"#9acd32",salmon:"#fa8072",saddlebrown:"#8b4513",sandybrown:"#f4a460",rosybrown:"#bc8f8f",darksalmon:"#e9967a",lightgoldenrodyellow:"#fafad2",snow:"#fffafa",lightgrey:"#d3d3d3",lightgray:"#d3d3d3",dimgray:"#696969",dimgrey:"#696969",olivedrab:"#6b8e23",olive:"#808000"},i={};for(var n in I)i[I[n]]=n;var C={};g.prototype.toName=function(r){if(!(this.rgba.a||this.rgba.r||this.rgba.g||this.rgba.b))return"transparent";var o,A,s=i[this.toHex()];if(s)return s;if(r!=null&&r.closest){var a=this.toRgb(),l=1/0,c="black";if(!C.length)for(var u in I)C[u]=new g(I[u]).toRgb();for(var d in I){var h=(o=a,A=C[d],Math.pow(o.r-A.r,2)+Math.pow(o.g-A.g,2)+Math.pow(o.b-A.b,2));hn===I[C]);if(e!==null&&I!==null){const n=Object.keys(e),C=Object.keys(I);return n.length!==C.length?!1:n.every(r=>e[r]===I[r])}return e===I}toRgba(){const[e,I,i,n]=this._components;return{r:e,g:I,b:i,a:n}}toRgb(){const[e,I,i]=this._components;return{r:e,g:I,b:i}}toRgbaString(){const[e,I,i]=this.toUint8RgbArray();return`rgba(${e},${I},${i},${this.alpha})`}toUint8RgbArray(e){const[I,i,n]=this._components;return e=e??[],e[0]=Math.round(I*255),e[1]=Math.round(i*255),e[2]=Math.round(n*255),e}toRgbArray(e){e=e??[];const[I,i,n]=this._components;return e[0]=I,e[1]=i,e[2]=n,e}toNumber(){return this._int}toLittleEndianNumber(){const e=this._int;return(e>>16)+(e&65280)+((e&255)<<16)}multiply(e){const[I,i,n,C]=N1.temp.setValue(e)._components;return this._components[0]*=I,this._components[1]*=i,this._components[2]*=n,this._components[3]*=C,this.refreshInt(),this._value=null,this}premultiply(e,I=!0){return I&&(this._components[0]*=e,this._components[1]*=e,this._components[2]*=e),this._components[3]=e,this.refreshInt(),this._value=null,this}toPremultiplied(e,I=!0){if(e===1)return(255<<24)+this._int;if(e===0)return I?0:this._int;let i=this._int>>16&255,n=this._int>>8&255,C=this._int&255;return I&&(i=i*e+.5|0,n=n*e+.5|0,C=C*e+.5|0),(e*255<<24)+(i<<16)+(n<<8)+C}toHex(){const e=this._int.toString(16);return`#${"000000".substring(0,6-e.length)+e}`}toHexa(){const e=Math.round(this._components[3]*255).toString(16);return this.toHex()+"00".substring(0,2-e.length)+e}setAlpha(e){return this._components[3]=this._clamp(e),this}round(e){const[I,i,n]=this._components;return this._components[0]=Math.round(I*e)/e,this._components[1]=Math.round(i*e)/e,this._components[2]=Math.round(n*e)/e,this.refreshInt(),this._value=null,this}toArray(e){e=e??[];const[I,i,n,C]=this._components;return e[0]=I,e[1]=i,e[2]=n,e[3]=C,e}normalize(e){let I,i,n,C;if((typeof e=="number"||e instanceof Number)&&e>=0&&e<=16777215){const r=e;I=(r>>16&255)/255,i=(r>>8&255)/255,n=(r&255)/255,C=1}else if((Array.isArray(e)||e instanceof Float32Array)&&e.length>=3&&e.length<=4)e=this._clamp(e),[I,i,n,C=1]=e;else if((e instanceof Uint8Array||e instanceof Uint8ClampedArray)&&e.length>=3&&e.length<=4)e=this._clamp(e,0,255),[I,i,n,C=255]=e,I/=255,i/=255,n/=255,C/=255;else if(typeof e=="string"||typeof e=="object"){if(typeof e=="string"){const o=N1.HEX_PATTERN.exec(e);o&&(e=`#${o[2]}`)}const r=YA(e);r.isValid()&&({r:I,g:i,b:n,a:C}=r.rgba,I/=255,i/=255,n/=255)}if(I!==void 0)this._components[0]=I,this._components[1]=i,this._components[2]=n,this._components[3]=C,this.refreshInt();else throw new Error(`Unable to convert color ${e}`)}refreshInt(){this._clamp(this._components);const[e,I,i]=this._components;this._int=(e*255<<16)+(I*255<<8)+(i*255|0)}_clamp(e,I=0,i=1){return typeof e=="number"?Math.min(Math.max(e,I),i):(e.forEach((n,C)=>{e[C]=Math.min(Math.max(n,I),i)}),e)}};vf.shared=new vf,vf.temp=new vf,vf.HEX_PATTERN=/^(#|0x)?(([a-f0-9]{3}){1,2}([a-f0-9]{2})?)$/i;let xg=vf;function hFe(g,e=[]){return tg("7.2.0","utils.hex2rgb is deprecated, use Color#toRgbArray instead"),xg.shared.setValue(g).toRgbArray(e)}function hme(g){return tg("7.2.0","utils.hex2string is deprecated, use Color#toHex instead"),xg.shared.setValue(g).toHex()}function mFe(g){return tg("7.2.0","utils.string2hex is deprecated, use Color#toNumber instead"),xg.shared.setValue(g).toNumber()}function x_(g){return tg("7.2.0","utils.rgb2hex is deprecated, use Color#toNumber instead"),xg.shared.setValue(g).toNumber()}function fFe(){const g=[],e=[];for(let i=0;i<32;i++)g[i]=i,e[i]=i;g[$t.NORMAL_NPM]=$t.NORMAL,g[$t.ADD_NPM]=$t.ADD,g[$t.SCREEN_NPM]=$t.SCREEN,e[$t.NORMAL]=$t.NORMAL_NPM,e[$t.ADD]=$t.ADD_NPM,e[$t.SCREEN]=$t.SCREEN_NPM;const I=[];return I.push(e),I.push(g),I}const D_=fFe();function F_(g,e){return D_[e?1:0][g]}function pFe(g,e,I,i=!0){return tg("7.2.0","utils.premultiplyRgba has moved to Color.premultiply"),xg.shared.setValue(g).premultiply(e,i).toArray(I??new Float32Array(4))}function bFe(g,e){return tg("7.2.0","utils.premultiplyTint has moved to Color.toPremultiplied"),xg.shared.setValue(g).toPremultiplied(e)}function yFe(g,e,I,i=!0){return tg("7.2.0","utils.premultiplyTintToRgba has moved to Color.premultiply"),xg.shared.setValue(g).premultiply(e,i).toArray(I??new Float32Array(4))}const mme=/^\s*data:(?:([\w-]+)\/([\w+.-]+))?(?:;charset=([\w-]+))?(?:;(base64))?,(.*)/i;function fme(g,e=null){const I=g*6;if(e=e||new Uint16Array(I),e.length!==I)throw new Error(`Out buffer length is incorrect, got ${e.length} and expected ${I}`);for(let i=0,n=0;i>>1,g|=g>>>2,g|=g>>>4,g|=g>>>8,g|=g>>>16,g+1}function dM(g){return!(g&g-1)&&!!g}function hM(g){let e=(g>65535?1:0)<<4;g>>>=e;let I=(g>255?1:0)<<3;return g>>>=I,e|=I,I=(g>15?1:0)<<2,g>>>=I,e|=I,I=(g>3?1:0)<<1,g>>>=I,e|=I,e|g>>1}function Nd(g,e,I){const i=g.length;let n;if(e>=i||I===0)return;I=e+I>i?i-e:I;const C=i-I;for(n=e;n(g.Renderer="renderer",g.Application="application",g.RendererSystem="renderer-webgl-system",g.RendererPlugin="renderer-webgl-plugin",g.CanvasRendererSystem="renderer-canvas-system",g.CanvasRendererPlugin="renderer-canvas-plugin",g.Asset="asset",g.LoadParser="load-parser",g.ResolveParser="resolve-parser",g.CacheParser="cache-parser",g.DetectionParser="detection-parser",g))(pt||{});const bM=g=>{if(typeof g=="function"||typeof g=="object"&&g.extension){if(!g.extension)throw new Error("Extension class must have an extension object");g={...typeof g.extension!="object"?{type:g.extension}:g.extension,ref:g}}if(typeof g=="object")g={...g};else throw new Error("Invalid extension type");return typeof g.type=="string"&&(g.type=[g.type]),g},Qq=(g,e)=>bM(g).priority??e,kt={_addHandlers:{},_removeHandlers:{},_queue:{},remove(...g){return g.map(bM).forEach(e=>{e.type.forEach(I=>{var i,n;return(n=(i=this._removeHandlers)[I])==null?void 0:n.call(i,e)})}),this},add(...g){return g.map(bM).forEach(e=>{e.type.forEach(I=>{const i=this._addHandlers,n=this._queue;i[I]?i[I](e):(n[I]=n[I]||[],n[I].push(e))})}),this},handle(g,e,I){const i=this._addHandlers,n=this._removeHandlers;if(i[g]||n[g])throw new Error(`Extension type ${g} already has a handler`);i[g]=e,n[g]=I;const C=this._queue;return C[g]&&(C[g].forEach(r=>e(r)),delete C[g]),this},handleByMap(g,e){return this.handle(g,I=>{e[I.name]=I.ref},I=>{delete e[I.name]})},handleByList(g,e,I=-1){return this.handle(g,i=>{e.includes(i.ref)||(e.push(i.ref),e.sort((n,C)=>Qq(C,I)-Qq(n,I)))},i=>{const n=e.indexOf(i.ref);n!==-1&&e.splice(n,1)})}};class kX{constructor(e){typeof e=="number"?this.rawBinaryData=new ArrayBuffer(e):e instanceof Uint8Array?this.rawBinaryData=e.buffer:this.rawBinaryData=e,this.uint32View=new Uint32Array(this.rawBinaryData),this.float32View=new Float32Array(this.rawBinaryData)}get int8View(){return this._int8View||(this._int8View=new Int8Array(this.rawBinaryData)),this._int8View}get uint8View(){return this._uint8View||(this._uint8View=new Uint8Array(this.rawBinaryData)),this._uint8View}get int16View(){return this._int16View||(this._int16View=new Int16Array(this.rawBinaryData)),this._int16View}get uint16View(){return this._uint16View||(this._uint16View=new Uint16Array(this.rawBinaryData)),this._uint16View}get int32View(){return this._int32View||(this._int32View=new Int32Array(this.rawBinaryData)),this._int32View}view(e){return this[`${e}View`]}destroy(){this.rawBinaryData=null,this._int8View=null,this._uint8View=null,this._int16View=null,this._uint16View=null,this._int32View=null,this.uint32View=null,this.float32View=null}static sizeOf(e){switch(e){case"int8":case"uint8":return 1;case"int16":case"uint16":return 2;case"int32":case"uint32":case"float32":return 4;default:throw new Error(`${e} isn't a valid view type`)}}}const RFe=["precision mediump float;","void main(void){","float test = 0.1;","%forloop%","gl_FragColor = vec4(0.0);","}"].join(` -`);function WFe(g){let e="";for(let I=0;I0&&(e+=` -else `),I=0;--i){const n=YX[i];if(n.test&&n.test(g,I))return new n(g,e)}throw new Error("Unrecognized source type to auto-detect Resource")}class dr{constructor(e){this.items=[],this._name=e,this._aliasCount=0}emit(e,I,i,n,C,r,o,A){if(arguments.length>8)throw new Error("max arguments reached");const{name:s,items:a}=this;this._aliasCount++;for(let l=0,c=a.length;l0&&this.items.length>1&&(this._aliasCount=0,this.items=this.items.slice(0))}add(e){return e[this._name]&&(this.ensureNonAliasedItems(),this.remove(e),this.items.push(e)),this}remove(e){const I=this.items.indexOf(e);return I!==-1&&(this.ensureNonAliasedItems(),this.items.splice(I,1)),this}contains(e){return this.items.includes(e)}removeAll(){return this.ensureNonAliasedItems(),this.items.length=0,this}destroy(){this.removeAll(),this.items=null,this._name=null}get empty(){return this.items.length===0}get name(){return this._name}}Object.defineProperties(dr.prototype,{dispatch:{value:dr.prototype.emit},run:{value:dr.prototype.emit}});class Bb{constructor(e=0,I=0){this._width=e,this._height=I,this.destroyed=!1,this.internal=!1,this.onResize=new dr("setRealSize"),this.onUpdate=new dr("update"),this.onError=new dr("onError")}bind(e){this.onResize.add(e),this.onUpdate.add(e),this.onError.add(e),(this._width||this._height)&&this.onResize.emit(this._width,this._height)}unbind(e){this.onResize.remove(e),this.onUpdate.remove(e),this.onError.remove(e)}resize(e,I){(e!==this._width||I!==this._height)&&(this._width=e,this._height=I,this.onResize.emit(e,I))}get valid(){return!!this._width&&!!this._height}update(){this.destroyed||this.onUpdate.emit()}load(){return Promise.resolve(this)}get width(){return this._width}get height(){return this._height}style(e,I,i){return!1}dispose(){}destroy(){this.destroyed||(this.destroyed=!0,this.dispose(),this.onError.removeAll(),this.onError=null,this.onResize.removeAll(),this.onResize=null,this.onUpdate.removeAll(),this.onUpdate=null)}static test(e,I){return!1}}class TS extends Bb{constructor(e,I){const{width:i,height:n}=I||{};if(!i||!n)throw new Error("BufferResource width or height invalid");super(i,n),this.data=e,this.unpackAlignment=I.unpackAlignment??4}upload(e,I,i){const n=e.gl;n.pixelStorei(n.UNPACK_ALIGNMENT,this.unpackAlignment),n.pixelStorei(n.UNPACK_PREMULTIPLY_ALPHA_WEBGL,I.alphaMode===tC.UNPACK);const C=I.realWidth,r=I.realHeight;return i.width===C&&i.height===r?n.texSubImage2D(I.target,0,0,0,C,r,I.format,i.type,this.data):(i.width=C,i.height=r,n.texImage2D(I.target,0,i.internalFormat,C,r,0,I.format,i.type,this.data)),!0}dispose(){this.data=null}static test(e){return e===null||e instanceof Int8Array||e instanceof Uint8Array||e instanceof Uint8ClampedArray||e instanceof Int16Array||e instanceof Uint16Array||e instanceof Int32Array||e instanceof Uint32Array||e instanceof Float32Array}}const XFe={scaleMode:Ca.NEAREST,alphaMode:tC.NPM},yM=class Sf extends T0{constructor(e=null,I=null){super(),I=Object.assign({},Sf.defaultOptions,I);const{alphaMode:i,mipmap:n,anisotropicLevel:C,scaleMode:r,width:o,height:A,wrapMode:s,format:a,type:l,target:c,resolution:u,resourceOptions:d}=I;e&&!(e instanceof Bb)&&(e=E_(e,d),e.internal=!0),this.resolution=u||Gt.RESOLUTION,this.width=Math.round((o||0)*this.resolution)/this.resolution,this.height=Math.round((A||0)*this.resolution)/this.resolution,this._mipmap=n,this.anisotropicLevel=C,this._wrapMode=s,this._scaleMode=r,this.format=a,this.type=l,this.target=c,this.alphaMode=i,this.uid=gu(),this.touched=0,this.isPowerOfTwo=!1,this._refreshPOT(),this._glTextures={},this.dirtyId=0,this.dirtyStyleId=0,this.cacheId=null,this.valid=o>0&&A>0,this.textureCacheIds=[],this.destroyed=!1,this.resource=null,this._batchEnabled=0,this._batchLocation=0,this.parentTextureArray=null,this.setResource(e)}get realWidth(){return Math.round(this.width*this.resolution)}get realHeight(){return Math.round(this.height*this.resolution)}get mipmap(){return this._mipmap}set mipmap(e){this._mipmap!==e&&(this._mipmap=e,this.dirtyStyleId++)}get scaleMode(){return this._scaleMode}set scaleMode(e){this._scaleMode!==e&&(this._scaleMode=e,this.dirtyStyleId++)}get wrapMode(){return this._wrapMode}set wrapMode(e){this._wrapMode!==e&&(this._wrapMode=e,this.dirtyStyleId++)}setStyle(e,I){let i;return e!==void 0&&e!==this.scaleMode&&(this.scaleMode=e,i=!0),I!==void 0&&I!==this.mipmap&&(this.mipmap=I,i=!0),i&&this.dirtyStyleId++,this}setSize(e,I,i){return i=i||this.resolution,this.setRealSize(e*i,I*i,i)}setRealSize(e,I,i){return this.resolution=i||this.resolution,this.width=Math.round(e)/this.resolution,this.height=Math.round(I)/this.resolution,this._refreshPOT(),this.update(),this}_refreshPOT(){this.isPowerOfTwo=dM(this.realWidth)&&dM(this.realHeight)}setResolution(e){const I=this.resolution;return I===e?this:(this.resolution=e,this.valid&&(this.width=Math.round(this.width*I)/e,this.height=Math.round(this.height*I)/e,this.emit("update",this)),this._refreshPOT(),this)}setResource(e){if(this.resource===e)return this;if(this.resource)throw new Error("Resource can be set only once");return e.bind(this),this.resource=e,this}update(){this.valid?(this.dirtyId++,this.dirtyStyleId++,this.emit("update",this)):this.width>0&&this.height>0&&(this.valid=!0,this.emit("loaded",this),this.emit("update",this))}onError(e){this.emit("error",this,e)}destroy(){this.resource&&(this.resource.unbind(this),this.resource.internal&&this.resource.destroy(),this.resource=null),this.cacheId&&(delete jC[this.cacheId],delete On[this.cacheId],this.cacheId=null),this.valid=!1,this.dispose(),Sf.removeFromCache(this),this.textureCacheIds=null,this.destroyed=!0,this.emit("destroyed",this),this.removeAllListeners()}dispose(){this.emit("dispose",this)}castToBaseTexture(){return this}static from(e,I,i=Gt.STRICT_TEXTURE_CACHE){const n=typeof e=="string";let C=null;if(n)C=e;else{if(!e._pixiId){const o=(I==null?void 0:I.pixiIdPrefix)||"pixiid";e._pixiId=`${o}_${gu()}`}C=e._pixiId}let r=jC[C];if(n&&i&&!r)throw new Error(`The cacheId "${C}" does not exist in BaseTextureCache.`);return r||(r=new Sf(e,I),r.cacheId=C,Sf.addToCache(r,C)),r}static fromBuffer(e,I,i,n){e=e||new Float32Array(I*i*4);const C=new TS(e,{width:I,height:i,...n==null?void 0:n.resourceOptions});let r,o;return e instanceof Float32Array?(r=st.RGBA,o=Mt.FLOAT):e instanceof Int32Array?(r=st.RGBA_INTEGER,o=Mt.INT):e instanceof Uint32Array?(r=st.RGBA_INTEGER,o=Mt.UNSIGNED_INT):e instanceof Int16Array?(r=st.RGBA_INTEGER,o=Mt.SHORT):e instanceof Uint16Array?(r=st.RGBA_INTEGER,o=Mt.UNSIGNED_SHORT):e instanceof Int8Array?(r=st.RGBA,o=Mt.BYTE):(r=st.RGBA,o=Mt.UNSIGNED_BYTE),C.internal=!0,new Sf(C,Object.assign({},XFe,{type:o,format:r},n))}static addToCache(e,I){I&&(e.textureCacheIds.includes(I)||e.textureCacheIds.push(I),jC[I]&&jC[I]!==e&&console.warn(`BaseTexture added to the cache with an id [${I}] that already had an entry`),jC[I]=e)}static removeFromCache(e){if(typeof e=="string"){const I=jC[e];if(I){const i=I.textureCacheIds.indexOf(e);return i>-1&&I.textureCacheIds.splice(i,1),delete jC[e],I}}else if(e!=null&&e.textureCacheIds){for(let I=0;I1){for(let l=0;l(g[g.POLY=0]="POLY",g[g.RECT=1]="RECT",g[g.CIRC=2]="CIRC",g[g.ELIP=3]="ELIP",g[g.RREC=4]="RREC",g))(Pi||{});class Gg{constructor(e=0,I=0){this.x=0,this.y=0,this.x=e,this.y=I}clone(){return new Gg(this.x,this.y)}copyFrom(e){return this.set(e.x,e.y),this}copyTo(e){return e.set(this.x,this.y),e}equals(e){return e.x===this.x&&e.y===this.y}set(e=0,I=e){return this.x=e,this.y=I,this}}Gg.prototype.toString=function(){return`[@pixi/math:Point x=${this.x} y=${this.y}]`};const HV=[new Gg,new Gg,new Gg,new Gg];class rg{constructor(e=0,I=0,i=0,n=0){this.x=Number(e),this.y=Number(I),this.width=Number(i),this.height=Number(n),this.type=Pi.RECT}get left(){return this.x}get right(){return this.x+this.width}get top(){return this.y}get bottom(){return this.y+this.height}static get EMPTY(){return new rg(0,0,0,0)}clone(){return new rg(this.x,this.y,this.width,this.height)}copyFrom(e){return this.x=e.x,this.y=e.y,this.width=e.width,this.height=e.height,this}copyTo(e){return e.x=this.x,e.y=this.y,e.width=this.width,e.height=this.height,e}contains(e,I){return this.width<=0||this.height<=0?!1:e>=this.x&&e=this.y&&Ie.right?e.right:this.right)<=B)return!1;const w=this.ye.bottom?e.bottom:this.bottom)>w}const i=this.left,n=this.right,C=this.top,r=this.bottom;if(n<=i||r<=C)return!1;const o=HV[0].set(e.left,e.top),A=HV[1].set(e.left,e.bottom),s=HV[2].set(e.right,e.top),a=HV[3].set(e.right,e.bottom);if(s.x<=o.x||A.y<=o.y)return!1;const l=Math.sign(I.a*I.d-I.b*I.c);if(l===0||(I.apply(o,o),I.apply(A,A),I.apply(s,s),I.apply(a,a),Math.max(o.x,A.x,s.x,a.x)<=i||Math.min(o.x,A.x,s.x,a.x)>=n||Math.max(o.y,A.y,s.y,a.y)<=C||Math.min(o.y,A.y,s.y,a.y)>=r))return!1;const c=l*(A.y-o.y),u=l*(o.x-A.x),d=c*i+u*C,h=c*n+u*C,m=c*i+u*r,f=c*n+u*r;if(Math.max(d,h,m,f)<=c*o.x+u*o.y||Math.min(d,h,m,f)>=c*a.x+u*a.y)return!1;const b=l*(o.y-s.y),p=l*(s.x-o.x),y=b*i+p*C,Z=b*n+p*C,v=b*i+p*r,G=b*n+p*r;return!(Math.max(y,Z,v,G)<=b*o.x+p*o.y||Math.min(y,Z,v,G)>=b*a.x+p*a.y)}pad(e=0,I=e){return this.x-=e,this.y-=I,this.width+=e*2,this.height+=I*2,this}fit(e){const I=Math.max(this.x,e.x),i=Math.min(this.x+this.width,e.x+e.width),n=Math.max(this.y,e.y),C=Math.min(this.y+this.height,e.y+e.height);return this.x=I,this.width=Math.max(i-I,0),this.y=n,this.height=Math.max(C-n,0),this}ceil(e=1,I=.001){const i=Math.ceil((this.x+this.width-I)*e)/e,n=Math.ceil((this.y+this.height-I)*e)/e;return this.x=Math.floor((this.x+I)*e)/e,this.y=Math.floor((this.y+I)*e)/e,this.width=i-this.x,this.height=n-this.y,this}enlarge(e){const I=Math.min(this.x,e.x),i=Math.max(this.x+this.width,e.x+e.width),n=Math.min(this.y,e.y),C=Math.max(this.y+this.height,e.y+e.height);return this.x=I,this.width=i-I,this.y=n,this.height=C-n,this}}rg.prototype.toString=function(){return`[@pixi/math:Rectangle x=${this.x} y=${this.y} width=${this.width} height=${this.height}]`};let z_=class Vme{constructor(e=0,I=0,i=0){this.x=e,this.y=I,this.radius=i,this.type=Pi.CIRC}clone(){return new Vme(this.x,this.y,this.radius)}contains(e,I){if(this.radius<=0)return!1;const i=this.radius*this.radius;let n=this.x-e,C=this.y-I;return n*=n,C*=C,n+C<=i}getBounds(){return new rg(this.x-this.radius,this.y-this.radius,this.radius*2,this.radius*2)}};z_.prototype.toString=function(){return`[@pixi/math:Circle x=${this.x} y=${this.y} radius=${this.radius}]`};class NS{constructor(e=0,I=0,i=0,n=0){this.x=e,this.y=I,this.width=i,this.height=n,this.type=Pi.ELIP}clone(){return new NS(this.x,this.y,this.width,this.height)}contains(e,I){if(this.width<=0||this.height<=0)return!1;let i=(e-this.x)/this.width,n=(I-this.y)/this.height;return i*=i,n*=n,i+n<=1}getBounds(){return new rg(this.x-this.width,this.y-this.height,this.width,this.height)}}NS.prototype.toString=function(){return`[@pixi/math:Ellipse x=${this.x} y=${this.y} width=${this.width} height=${this.height}]`};class zc{constructor(...e){let I=Array.isArray(e[0])?e[0]:e;if(typeof I[0]!="number"){const i=[];for(let n=0,C=I.length;nI!=a>I&&e<(s-o)*((I-A)/(a-A))+o&&(i=!i)}return i}}zc.prototype.toString=function(){return`[@pixi/math:PolygoncloseStroke=${this.closeStroke}points=${this.points.reduce((g,e)=>`${g}, ${e}`,"")}]`};class kS{constructor(e=0,I=0,i=0,n=0,C=20){this.x=e,this.y=I,this.width=i,this.height=n,this.radius=C,this.type=Pi.RREC}clone(){return new kS(this.x,this.y,this.width,this.height,this.radius)}contains(e,I){if(this.width<=0||this.height<=0)return!1;if(e>=this.x&&e<=this.x+this.width&&I>=this.y&&I<=this.y+this.height){const i=Math.max(0,Math.min(this.radius,Math.min(this.width,this.height)/2));if(I>=this.y+i&&I<=this.y+this.height-i||e>=this.x+i&&e<=this.x+this.width-i)return!0;let n=e-(this.x+i),C=I-(this.y+i);const r=i*i;if(n*n+C*C<=r||(n=e-(this.x+this.width-i),n*n+C*C<=r)||(C=I-(this.y+this.height-i),n*n+C*C<=r)||(n=e-(this.x+i),n*n+C*C<=r))return!0}return!1}}kS.prototype.toString=function(){return`[@pixi/math:RoundedRectangle x=${this.x} y=${this.y}width=${this.width} height=${this.height} radius=${this.radius}]`};class sI{constructor(e=1,I=0,i=0,n=1,C=0,r=0){this.array=null,this.a=e,this.b=I,this.c=i,this.d=n,this.tx=C,this.ty=r}fromArray(e){this.a=e[0],this.b=e[1],this.c=e[3],this.d=e[4],this.tx=e[2],this.ty=e[5]}set(e,I,i,n,C,r){return this.a=e,this.b=I,this.c=i,this.d=n,this.tx=C,this.ty=r,this}toArray(e,I){this.array||(this.array=new Float32Array(9));const i=I||this.array;return e?(i[0]=this.a,i[1]=this.b,i[2]=0,i[3]=this.c,i[4]=this.d,i[5]=0,i[6]=this.tx,i[7]=this.ty,i[8]=1):(i[0]=this.a,i[1]=this.c,i[2]=this.tx,i[3]=this.b,i[4]=this.d,i[5]=this.ty,i[6]=0,i[7]=0,i[8]=1),i}apply(e,I){I=I||new Gg;const i=e.x,n=e.y;return I.x=this.a*i+this.c*n+this.tx,I.y=this.b*i+this.d*n+this.ty,I}applyInverse(e,I){I=I||new Gg;const i=1/(this.a*this.d+this.c*-this.b),n=e.x,C=e.y;return I.x=this.d*i*n+-this.c*i*C+(this.ty*this.c-this.tx*this.d)*i,I.y=this.a*i*C+-this.b*i*n+(-this.ty*this.a+this.tx*this.b)*i,I}translate(e,I){return this.tx+=e,this.ty+=I,this}scale(e,I){return this.a*=e,this.d*=I,this.c*=e,this.b*=I,this.tx*=e,this.ty*=I,this}rotate(e){const I=Math.cos(e),i=Math.sin(e),n=this.a,C=this.c,r=this.tx;return this.a=n*I-this.b*i,this.b=n*i+this.b*I,this.c=C*I-this.d*i,this.d=C*i+this.d*I,this.tx=r*I-this.ty*i,this.ty=r*i+this.ty*I,this}append(e){const I=this.a,i=this.b,n=this.c,C=this.d;return this.a=e.a*I+e.b*n,this.b=e.a*i+e.b*C,this.c=e.c*I+e.d*n,this.d=e.c*i+e.d*C,this.tx=e.tx*I+e.ty*n+this.tx,this.ty=e.tx*i+e.ty*C+this.ty,this}setTransform(e,I,i,n,C,r,o,A,s){return this.a=Math.cos(o+s)*C,this.b=Math.sin(o+s)*C,this.c=-Math.sin(o-A)*r,this.d=Math.cos(o-A)*r,this.tx=e-(i*this.a+n*this.c),this.ty=I-(i*this.b+n*this.d),this}prepend(e){const I=this.tx;if(e.a!==1||e.b!==0||e.c!==0||e.d!==1){const i=this.a,n=this.c;this.a=i*e.a+this.b*e.c,this.b=i*e.b+this.b*e.d,this.c=n*e.a+this.d*e.c,this.d=n*e.b+this.d*e.d}return this.tx=I*e.a+this.ty*e.c+e.tx,this.ty=I*e.b+this.ty*e.d+e.ty,this}decompose(e){const I=this.a,i=this.b,n=this.c,C=this.d,r=e.pivot,o=-Math.atan2(-n,C),A=Math.atan2(i,I),s=Math.abs(o+A);return s<1e-5||Math.abs(uv-s)<1e-5?(e.rotation=A,e.skew.x=e.skew.y=0):(e.rotation=0,e.skew.x=o,e.skew.y=A),e.scale.x=Math.sqrt(I*I+i*i),e.scale.y=Math.sqrt(n*n+C*C),e.position.x=this.tx+(r.x*I+r.y*n),e.position.y=this.ty+(r.x*i+r.y*C),e}invert(){const e=this.a,I=this.b,i=this.c,n=this.d,C=this.tx,r=e*n-I*i;return this.a=n/r,this.b=-I/r,this.c=-i/r,this.d=e/r,this.tx=(i*this.ty-n*C)/r,this.ty=-(e*this.ty-I*C)/r,this}identity(){return this.a=1,this.b=0,this.c=0,this.d=1,this.tx=0,this.ty=0,this}clone(){const e=new sI;return e.a=this.a,e.b=this.b,e.c=this.c,e.d=this.d,e.tx=this.tx,e.ty=this.ty,e}copyTo(e){return e.a=this.a,e.b=this.b,e.c=this.c,e.d=this.d,e.tx=this.tx,e.ty=this.ty,e}copyFrom(e){return this.a=e.a,this.b=e.b,this.c=e.c,this.d=e.d,this.tx=e.tx,this.ty=e.ty,this}static get IDENTITY(){return new sI}static get TEMP_MATRIX(){return new sI}}sI.prototype.toString=function(){return`[@pixi/math:Matrix a=${this.a} b=${this.b} c=${this.c} d=${this.d} tx=${this.tx} ty=${this.ty}]`};const ju=[1,1,0,-1,-1,-1,0,1,1,1,0,-1,-1,-1,0,1],$u=[0,1,1,1,0,-1,-1,-1,0,1,1,1,0,-1,-1,-1],qu=[0,-1,-1,-1,0,1,1,1,0,1,1,1,0,-1,-1,-1],ed=[1,1,0,-1,-1,-1,0,1,-1,-1,0,1,1,1,0,-1],ZM=[],Rme=[],TV=Math.sign;function KFe(){for(let g=0;g<16;g++){const e=[];ZM.push(e);for(let I=0;I<16;I++){const i=TV(ju[g]*ju[I]+qu[g]*$u[I]),n=TV($u[g]*ju[I]+ed[g]*$u[I]),C=TV(ju[g]*qu[I]+qu[g]*ed[I]),r=TV($u[g]*qu[I]+ed[g]*ed[I]);for(let o=0;o<16;o++)if(ju[o]===i&&$u[o]===n&&qu[o]===C&&ed[o]===r){e.push(o);break}}}for(let g=0;g<16;g++){const e=new sI;e.set(ju[g],$u[g],qu[g],ed[g],0,0),Rme.push(e)}}KFe();const VI={E:0,SE:1,S:2,SW:3,W:4,NW:5,N:6,NE:7,MIRROR_VERTICAL:8,MAIN_DIAGONAL:10,MIRROR_HORIZONTAL:12,REVERSE_DIAGONAL:14,uX:g=>ju[g],uY:g=>$u[g],vX:g=>qu[g],vY:g=>ed[g],inv:g=>g&8?g&15:-g&7,add:(g,e)=>ZM[g][e],sub:(g,e)=>ZM[g][VI.inv(e)],rotate180:g=>g^4,isVertical:g=>(g&3)===2,byDirection:(g,e)=>Math.abs(g)*2<=Math.abs(e)?e>=0?VI.S:VI.N:Math.abs(e)*2<=Math.abs(g)?g>0?VI.E:VI.W:e>0?g>0?VI.SE:VI.SW:g>0?VI.NE:VI.NW,matrixAppendRotationInv:(g,e,I=0,i=0)=>{const n=Rme[VI.inv(e)];n.tx=I,n.ty=i,g.append(n)}};class ra{constructor(e,I,i=0,n=0){this._x=i,this._y=n,this.cb=e,this.scope=I}clone(e=this.cb,I=this.scope){return new ra(e,I,this._x,this._y)}set(e=0,I=e){return(this._x!==e||this._y!==I)&&(this._x=e,this._y=I,this.cb.call(this.scope)),this}copyFrom(e){return(this._x!==e.x||this._y!==e.y)&&(this._x=e.x,this._y=e.y,this.cb.call(this.scope)),this}copyTo(e){return e.set(this._x,this._y),e}equals(e){return e.x===this._x&&e.y===this._y}get x(){return this._x}set x(e){this._x!==e&&(this._x=e,this.cb.call(this.scope))}get y(){return this._y}set y(e){this._y!==e&&(this._y=e,this.cb.call(this.scope))}}ra.prototype.toString=function(){return`[@pixi/math:ObservablePoint x=${this.x} y=${this.y} scope=${this.scope}]`};const GM=class{constructor(){this.worldTransform=new sI,this.localTransform=new sI,this.position=new ra(this.onChange,this,0,0),this.scale=new ra(this.onChange,this,1,1),this.pivot=new ra(this.onChange,this,0,0),this.skew=new ra(this.updateSkew,this,0,0),this._rotation=0,this._cx=1,this._sx=0,this._cy=0,this._sy=1,this._localID=0,this._currentLocalID=0,this._worldID=0,this._parentID=0}onChange(){this._localID++}updateSkew(){this._cx=Math.cos(this._rotation+this.skew.y),this._sx=Math.sin(this._rotation+this.skew.y),this._cy=-Math.sin(this._rotation-this.skew.x),this._sy=Math.cos(this._rotation-this.skew.x),this._localID++}updateLocalTransform(){const g=this.localTransform;this._localID!==this._currentLocalID&&(g.a=this._cx*this.scale.x,g.b=this._sx*this.scale.x,g.c=this._cy*this.scale.y,g.d=this._sy*this.scale.y,g.tx=this.position.x-(this.pivot.x*g.a+this.pivot.y*g.c),g.ty=this.position.y-(this.pivot.x*g.b+this.pivot.y*g.d),this._currentLocalID=this._localID,this._parentID=-1)}updateTransform(g){const e=this.localTransform;if(this._localID!==this._currentLocalID&&(e.a=this._cx*this.scale.x,e.b=this._sx*this.scale.x,e.c=this._cy*this.scale.y,e.d=this._sy*this.scale.y,e.tx=this.position.x-(this.pivot.x*e.a+this.pivot.y*e.c),e.ty=this.position.y-(this.pivot.x*e.b+this.pivot.y*e.d),this._currentLocalID=this._localID,this._parentID=-1),this._parentID!==g._worldID){const I=g.worldTransform,i=this.worldTransform;i.a=e.a*I.a+e.b*I.c,i.b=e.a*I.b+e.b*I.d,i.c=e.c*I.a+e.d*I.c,i.d=e.c*I.b+e.d*I.d,i.tx=e.tx*I.a+e.ty*I.c+I.tx,i.ty=e.tx*I.b+e.ty*I.d+I.ty,this._parentID=g._worldID,this._worldID++}}setFromMatrix(g){g.decompose(this),this._localID++}get rotation(){return this._rotation}set rotation(g){this._rotation!==g&&(this._rotation=g,this.updateSkew())}};GM.IDENTITY=new GM;let YS=GM;YS.prototype.toString=function(){return`[@pixi/math:Transform position=(${this.position.x}, ${this.position.y}) rotation=${this.rotation} scale=(${this.scale.x}, ${this.scale.y}) skew=(${this.skew.x}, ${this.skew.y}) ]`};var xFe=`varying vec2 vTextureCoord; - -uniform sampler2D uSampler; - -void main(void){ - gl_FragColor *= texture2D(uSampler, vTextureCoord); -}`,DFe=`attribute vec2 aVertexPosition; -attribute vec2 aTextureCoord; - -uniform mat3 projectionMatrix; - -varying vec2 vTextureCoord; +`+C.stack}return{value:e,source:g,stack:n,digest:null}}function HY(e,g,I){return{value:e,source:null,stack:I??null,digest:g??null}}function UF(e,g){try{console.error(g.value)}catch(I){setTimeout(function(){throw I})}}var WYe=typeof WeakMap=="function"?WeakMap:Map;function Sde(e,g,I){I=ps(-1,I),I.tag=3,I.payload={element:null};var i=g.value;return I.callback=function(){PW||(PW=!0,nE=i),UF(e,g)},I}function wde(e,g,I){I=ps(-1,I),I.tag=3;var i=e.type.getDerivedStateFromError;if(typeof i=="function"){var n=g.value;I.payload=function(){return i(n)},I.callback=function(){UF(e,g)}}var C=e.stateNode;return C!==null&&typeof C.componentDidCatch=="function"&&(I.callback=function(){UF(e,g),typeof i!="function"&&(pc===null?pc=new Set([this]):pc.add(this));var r=g.stack;this.componentDidCatch(g.value,{componentStack:r!==null?r:""})}),I}function g6(e,g,I){var i=e.pingCache;if(i===null){i=e.pingCache=new WYe;var n=new Set;i.set(g,n)}else n=i.get(g),n===void 0&&(n=new Set,i.set(g,n));n.has(I)||(n.add(I),e=PYe.bind(null,e,g,I),g.then(e,e))}function I6(e){do{var g;if((g=e.tag===13)&&(g=e.memoizedState,g=g!==null?g.dehydrated!==null:!0),g)return e;e=e.return}while(e!==null);return null}function i6(e,g,I,i,n){return e.mode&1?(e.flags|=65536,e.lanes=n,e):(e===g?e.flags|=65536:(e.flags|=128,I.flags|=131072,I.flags&=-52805,I.tag===1&&(I.alternate===null?I.tag=17:(g=ps(-1,1),g.tag=2,fc(I,g,1))),I.lanes|=1),e)}var XYe=Ms.ReactCurrentOwner,RC=!1;function zn(e,g,I,i){g.child=e===null?nde(g,null,I,i):Lp(g,e.child,I,i)}function n6(e,g,I,i,n){I=I.render;var C=g.ref;return ap(g,n),i=X_(e,g,I,i,C,n),I=H_(),e!==null&&!RC?(g.updateQueue=e.updateQueue,g.flags&=-2053,e.lanes&=~n,Vs(e,g,n)):(RI&&I&&p_(g),g.flags|=1,zn(e,g,i,n),g.child)}function C6(e,g,I,i,n){if(e===null){var C=I.type;return typeof C=="function"&&!M_(C)&&C.defaultProps===void 0&&I.compare===null&&I.defaultProps===void 0?(g.tag=15,g.type=C,Vde(e,g,C,i,n)):(e=g1(I.type,null,i,g,g.mode,n),e.ref=g.ref,e.return=g,g.child=e)}if(C=e.child,!(e.lanes&n)){var r=C.memoizedProps;if(I=I.compare,I=I!==null?I:wv,I(r,i)&&e.ref===g.ref)return Vs(e,g,n)}return g.flags|=1,e=yc(C,i),e.ref=g.ref,e.return=g,g.child=e}function Vde(e,g,I,i,n){if(e!==null){var C=e.memoizedProps;if(wv(C,i)&&e.ref===g.ref)if(RC=!1,g.pendingProps=i=C,(e.lanes&n)!==0)e.flags&131072&&(RC=!0);else return g.lanes=e.lanes,Vs(e,g,n)}return QF(e,g,I,i,n)}function Rde(e,g,I){var i=g.pendingProps,n=i.children,C=e!==null?e.memoizedState:null;if(i.mode==="hidden")if(!(g.mode&1))g.memoizedState={baseLanes:0,cachePool:null,transitions:null},CI(Jf,_C),_C|=I;else{if(!(I&1073741824))return e=C!==null?C.baseLanes|I:I,g.lanes=g.childLanes=1073741824,g.memoizedState={baseLanes:e,cachePool:null,transitions:null},g.updateQueue=null,CI(Jf,_C),_C|=e,null;g.memoizedState={baseLanes:0,cachePool:null,transitions:null},i=C!==null?C.baseLanes:I,CI(Jf,_C),_C|=i}else C!==null?(i=C.baseLanes|I,g.memoizedState=null):i=I,CI(Jf,_C),_C|=i;return zn(e,g,n,I),g.child}function Wde(e,g){var I=g.ref;(e===null&&I!==null||e!==null&&e.ref!==I)&&(g.flags|=512,g.flags|=2097152)}function QF(e,g,I,i,n){var C=TC(I)?Hd:Xn.current;return C=Op(g,C),ap(g,n),I=X_(e,g,I,i,C,n),i=H_(),e!==null&&!RC?(g.updateQueue=e.updateQueue,g.flags&=-2053,e.lanes&=~n,Vs(e,g,n)):(RI&&i&&p_(g),g.flags|=1,zn(e,g,I,n),g.child)}function r6(e,g,I,i,n){if(TC(I)){var C=!0;NW(g)}else C=!1;if(ap(g,n),g.stateNode===null)qR(e,g),Ide(g,I,i),LF(g,I,i,n),i=!0;else if(e===null){var r=g.stateNode,o=g.memoizedProps;r.props=o;var A=r.context,s=I.contextType;typeof s=="object"&&s!==null?s=$r(s):(s=TC(I)?Hd:Xn.current,s=Op(g,s));var a=I.getDerivedStateFromProps,l=typeof a=="function"||typeof r.getSnapshotBeforeUpdate=="function";l||typeof r.UNSAFE_componentWillReceiveProps!="function"&&typeof r.componentWillReceiveProps!="function"||(o!==i||A!==s)&&$8(g,r,i,s),Nl=!1;var c=g.memoizedState;r.state=c,xW(g,i,r,n),A=g.memoizedState,o!==i||c!==A||HC.current||Nl?(typeof a=="function"&&(_F(g,I,a,i),A=g.memoizedState),(o=Nl||j8(g,I,o,i,c,A,s))?(l||typeof r.UNSAFE_componentWillMount!="function"&&typeof r.componentWillMount!="function"||(typeof r.componentWillMount=="function"&&r.componentWillMount(),typeof r.UNSAFE_componentWillMount=="function"&&r.UNSAFE_componentWillMount()),typeof r.componentDidMount=="function"&&(g.flags|=4194308)):(typeof r.componentDidMount=="function"&&(g.flags|=4194308),g.memoizedProps=i,g.memoizedState=A),r.props=i,r.state=A,r.context=s,i=o):(typeof r.componentDidMount=="function"&&(g.flags|=4194308),i=!1)}else{r=g.stateNode,tde(e,g),o=g.memoizedProps,s=g.type===g.elementType?o:ko(g.type,o),r.props=s,l=g.pendingProps,c=r.context,A=I.contextType,typeof A=="object"&&A!==null?A=$r(A):(A=TC(I)?Hd:Xn.current,A=Op(g,A));var u=I.getDerivedStateFromProps;(a=typeof u=="function"||typeof r.getSnapshotBeforeUpdate=="function")||typeof r.UNSAFE_componentWillReceiveProps!="function"&&typeof r.componentWillReceiveProps!="function"||(o!==l||c!==A)&&$8(g,r,i,A),Nl=!1,c=g.memoizedState,r.state=c,xW(g,i,r,n);var d=g.memoizedState;o!==l||c!==d||HC.current||Nl?(typeof u=="function"&&(_F(g,I,u,i),d=g.memoizedState),(s=Nl||j8(g,I,s,i,c,d,A)||!1)?(a||typeof r.UNSAFE_componentWillUpdate!="function"&&typeof r.componentWillUpdate!="function"||(typeof r.componentWillUpdate=="function"&&r.componentWillUpdate(i,d,A),typeof r.UNSAFE_componentWillUpdate=="function"&&r.UNSAFE_componentWillUpdate(i,d,A)),typeof r.componentDidUpdate=="function"&&(g.flags|=4),typeof r.getSnapshotBeforeUpdate=="function"&&(g.flags|=1024)):(typeof r.componentDidUpdate!="function"||o===e.memoizedProps&&c===e.memoizedState||(g.flags|=4),typeof r.getSnapshotBeforeUpdate!="function"||o===e.memoizedProps&&c===e.memoizedState||(g.flags|=1024),g.memoizedProps=i,g.memoizedState=d),r.props=i,r.state=d,r.context=A,i=s):(typeof r.componentDidUpdate!="function"||o===e.memoizedProps&&c===e.memoizedState||(g.flags|=4),typeof r.getSnapshotBeforeUpdate!="function"||o===e.memoizedProps&&c===e.memoizedState||(g.flags|=1024),i=!1)}return jF(e,g,I,i,C,n)}function jF(e,g,I,i,n,C){Wde(e,g);var r=(g.flags&128)!==0;if(!i&&!r)return n&&O8(g,I,!1),Vs(e,g,C);i=g.stateNode,XYe.current=g;var o=r&&typeof I.getDerivedStateFromError!="function"?null:i.render();return g.flags|=1,e!==null&&r?(g.child=Lp(g,e.child,null,C),g.child=Lp(g,null,o,C)):zn(e,g,o,C),g.memoizedState=i.state,n&&O8(g,I,!0),g.child}function Xde(e){var g=e.stateNode;g.pendingContext?J8(e,g.pendingContext,g.pendingContext!==g.context):g.context&&J8(e,g.context,!1),w_(e,g.containerInfo)}function o6(e,g,I,i,n){return _p(),y_(n),g.flags|=256,zn(e,g,I,i),g.child}var $F={dehydrated:null,treeContext:null,retryLane:0};function qF(e){return{baseLanes:e,cachePool:null,transitions:null}}function Hde(e,g,I){var i=g.pendingProps,n=kI.current,C=!1,r=(g.flags&128)!==0,o;if((o=r)||(o=e!==null&&e.memoizedState===null?!1:(n&2)!==0),o?(C=!0,g.flags&=-129):(e===null||e.memoizedState!==null)&&(n|=1),CI(kI,n&1),e===null)return JF(g),e=g.memoizedState,e!==null&&(e=e.dehydrated,e!==null)?(g.mode&1?e.data==="$!"?g.lanes=8:g.lanes=1073741824:g.lanes=1,null):(r=i.children,e=i.fallback,C?(i=g.mode,C=g.child,r={mode:"hidden",children:r},!(i&1)&&C!==null?(C.childLanes=0,C.pendingProps=r):C=KH(r,i,0,null),e=cd(e,i,I,null),C.return=g,e.return=g,C.sibling=e,g.child=C,g.child.memoizedState=qF(I),g.memoizedState=$F,e):k_(g,r));if(n=e.memoizedState,n!==null&&(o=n.dehydrated,o!==null))return HYe(e,g,r,i,o,n,I);if(C){C=i.fallback,r=g.mode,n=e.child,o=n.sibling;var A={mode:"hidden",children:i.children};return!(r&1)&&g.child!==n?(i=g.child,i.childLanes=0,i.pendingProps=A,g.deletions=null):(i=yc(n,A),i.subtreeFlags=n.subtreeFlags&14680064),o!==null?C=yc(o,C):(C=cd(C,r,I,null),C.flags|=2),C.return=g,i.return=g,i.sibling=C,g.child=i,i=C,C=g.child,r=e.child.memoizedState,r=r===null?qF(I):{baseLanes:r.baseLanes|I,cachePool:null,transitions:r.transitions},C.memoizedState=r,C.childLanes=e.childLanes&~I,g.memoizedState=$F,i}return C=e.child,e=C.sibling,i=yc(C,{mode:"visible",children:i.children}),!(g.mode&1)&&(i.lanes=I),i.return=g,i.sibling=null,e!==null&&(I=g.deletions,I===null?(g.deletions=[e],g.flags|=16):I.push(e)),g.child=i,g.memoizedState=null,i}function k_(e,g){return g=KH({mode:"visible",children:g},e.mode,0,null),g.return=e,e.child=g}function Mw(e,g,I,i){return i!==null&&y_(i),Lp(g,e.child,null,I),e=k_(g,g.pendingProps.children),e.flags|=2,g.memoizedState=null,e}function HYe(e,g,I,i,n,C,r){if(I)return g.flags&256?(g.flags&=-257,i=HY(Error(at(422))),Mw(e,g,r,i)):g.memoizedState!==null?(g.child=e.child,g.flags|=128,null):(C=i.fallback,n=g.mode,i=KH({mode:"visible",children:i.children},n,0,null),C=cd(C,n,r,null),C.flags|=2,i.return=g,C.return=g,i.sibling=C,g.child=i,g.mode&1&&Lp(g,e.child,null,r),g.child.memoizedState=qF(r),g.memoizedState=$F,C);if(!(g.mode&1))return Mw(e,g,r,null);if(n.data==="$!"){if(i=n.nextSibling&&n.nextSibling.dataset,i)var o=i.dgst;return i=o,C=Error(at(419)),i=HY(C,i,void 0),Mw(e,g,r,i)}if(o=(r&e.childLanes)!==0,RC||o){if(i=Ji,i!==null){switch(r&-r){case 4:n=2;break;case 16:n=8;break;case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:n=32;break;case 536870912:n=268435456;break;default:n=0}n=n&(i.suspendedLanes|r)?0:n,n!==0&&n!==C.retryLane&&(C.retryLane=n,ws(e,n),jo(i,e,n,-1))}return E_(),i=HY(Error(at(421))),Mw(e,g,r,i)}return n.data==="$?"?(g.flags|=128,g.child=e.child,g=JYe.bind(null,e),n._reactRetry=g,null):(e=C.treeContext,nr=mc(n.nextSibling),or=g,RI=!0,xo=null,e!==null&&(Tr[Nr++]=ns,Tr[Nr++]=Cs,Tr[Nr++]=Td,ns=e.id,Cs=e.overflow,Td=g),g=k_(g,i.children),g.flags|=4096,g)}function A6(e,g,I){e.lanes|=g;var i=e.alternate;i!==null&&(i.lanes|=g),OF(e.return,g,I)}function TY(e,g,I,i,n){var C=e.memoizedState;C===null?e.memoizedState={isBackwards:g,rendering:null,renderingStartTime:0,last:i,tail:I,tailMode:n}:(C.isBackwards=g,C.rendering=null,C.renderingStartTime=0,C.last=i,C.tail=I,C.tailMode=n)}function Tde(e,g,I){var i=g.pendingProps,n=i.revealOrder,C=i.tail;if(zn(e,g,i.children,I),i=kI.current,i&2)i=i&1|2,g.flags|=128;else{if(e!==null&&e.flags&128)e:for(e=g.child;e!==null;){if(e.tag===13)e.memoizedState!==null&&A6(e,I,g);else if(e.tag===19)A6(e,I,g);else if(e.child!==null){e.child.return=e,e=e.child;continue}if(e===g)break e;for(;e.sibling===null;){if(e.return===null||e.return===g)break e;e=e.return}e.sibling.return=e.return,e=e.sibling}i&=1}if(CI(kI,i),!(g.mode&1))g.memoizedState=null;else switch(n){case"forwards":for(I=g.child,n=null;I!==null;)e=I.alternate,e!==null&&FW(e)===null&&(n=I),I=I.sibling;I=n,I===null?(n=g.child,g.child=null):(n=I.sibling,I.sibling=null),TY(g,!1,n,I,C);break;case"backwards":for(I=null,n=g.child,g.child=null;n!==null;){if(e=n.alternate,e!==null&&FW(e)===null){g.child=n;break}e=n.sibling,n.sibling=I,I=n,n=e}TY(g,!0,I,null,C);break;case"together":TY(g,!1,null,null,void 0);break;default:g.memoizedState=null}return g.child}function qR(e,g){!(g.mode&1)&&e!==null&&(e.alternate=null,g.alternate=null,g.flags|=2)}function Vs(e,g,I){if(e!==null&&(g.dependencies=e.dependencies),kd|=g.lanes,!(I&g.childLanes))return null;if(e!==null&&g.child!==e.child)throw Error(at(153));if(g.child!==null){for(e=g.child,I=yc(e,e.pendingProps),g.child=I,I.return=g;e.sibling!==null;)e=e.sibling,I=I.sibling=yc(e,e.pendingProps),I.return=g;I.sibling=null}return g.child}function TYe(e,g,I){switch(g.tag){case 3:Xde(g),_p();break;case 5:Cde(g);break;case 1:TC(g.type)&&NW(g);break;case 4:w_(g,g.stateNode.containerInfo);break;case 10:var i=g.type._context,n=g.memoizedProps.value;CI(KW,i._currentValue),i._currentValue=n;break;case 13:if(i=g.memoizedState,i!==null)return i.dehydrated!==null?(CI(kI,kI.current&1),g.flags|=128,null):I&g.child.childLanes?Hde(e,g,I):(CI(kI,kI.current&1),e=Vs(e,g,I),e!==null?e.sibling:null);CI(kI,kI.current&1);break;case 19:if(i=(I&g.childLanes)!==0,e.flags&128){if(i)return Tde(e,g,I);g.flags|=128}if(n=g.memoizedState,n!==null&&(n.rendering=null,n.tail=null,n.lastEffect=null),CI(kI,kI.current),i)break;return null;case 22:case 23:return g.lanes=0,Rde(e,g,I)}return Vs(e,g,I)}var Nde,eE,kde,Yde;Nde=function(e,g){for(var I=g.child;I!==null;){if(I.tag===5||I.tag===6)e.appendChild(I.stateNode);else if(I.tag!==4&&I.child!==null){I.child.return=I,I=I.child;continue}if(I===g)break;for(;I.sibling===null;){if(I.return===null||I.return===g)return;I=I.return}I.sibling.return=I.return,I=I.sibling}};eE=function(){};kde=function(e,g,I,i){var n=e.memoizedProps;if(n!==i){e=g.stateNode,Qu(ga.current);var C=null;switch(I){case"input":n=ZF(e,n),i=ZF(e,i),C=[];break;case"select":n=EI({},n,{value:void 0}),i=EI({},i,{value:void 0}),C=[];break;case"textarea":n=BF(e,n),i=BF(e,i),C=[];break;default:typeof n.onClick!="function"&&typeof i.onClick=="function"&&(e.onclick=HW)}wF(I,i);var r;I=null;for(s in n)if(!i.hasOwnProperty(s)&&n.hasOwnProperty(s)&&n[s]!=null)if(s==="style"){var o=n[s];for(r in o)o.hasOwnProperty(r)&&(I||(I={}),I[r]="")}else s!=="dangerouslySetInnerHTML"&&s!=="children"&&s!=="suppressContentEditableWarning"&&s!=="suppressHydrationWarning"&&s!=="autoFocus"&&(bv.hasOwnProperty(s)?C||(C=[]):(C=C||[]).push(s,null));for(s in i){var A=i[s];if(o=n!=null?n[s]:void 0,i.hasOwnProperty(s)&&A!==o&&(A!=null||o!=null))if(s==="style")if(o){for(r in o)!o.hasOwnProperty(r)||A&&A.hasOwnProperty(r)||(I||(I={}),I[r]="");for(r in A)A.hasOwnProperty(r)&&o[r]!==A[r]&&(I||(I={}),I[r]=A[r])}else I||(C||(C=[]),C.push(s,I)),I=A;else s==="dangerouslySetInnerHTML"?(A=A?A.__html:void 0,o=o?o.__html:void 0,A!=null&&o!==A&&(C=C||[]).push(s,A)):s==="children"?typeof A!="string"&&typeof A!="number"||(C=C||[]).push(s,""+A):s!=="suppressContentEditableWarning"&&s!=="suppressHydrationWarning"&&(bv.hasOwnProperty(s)?(A!=null&&s==="onScroll"&&cI("scroll",e),C||o===A||(C=[])):(C=C||[]).push(s,A))}I&&(C=C||[]).push("style",I);var s=C;(g.updateQueue=s)&&(g.flags|=4)}};Yde=function(e,g,I,i){I!==i&&(g.flags|=4)};function uy(e,g){if(!RI)switch(e.tailMode){case"hidden":g=e.tail;for(var I=null;g!==null;)g.alternate!==null&&(I=g),g=g.sibling;I===null?e.tail=null:I.sibling=null;break;case"collapsed":I=e.tail;for(var i=null;I!==null;)I.alternate!==null&&(i=I),I=I.sibling;i===null?g||e.tail===null?e.tail=null:e.tail.sibling=null:i.sibling=null}}function mn(e){var g=e.alternate!==null&&e.alternate.child===e.child,I=0,i=0;if(g)for(var n=e.child;n!==null;)I|=n.lanes|n.childLanes,i|=n.subtreeFlags&14680064,i|=n.flags&14680064,n.return=e,n=n.sibling;else for(n=e.child;n!==null;)I|=n.lanes|n.childLanes,i|=n.subtreeFlags,i|=n.flags,n.return=e,n=n.sibling;return e.subtreeFlags|=i,e.childLanes=I,g}function NYe(e,g,I){var i=g.pendingProps;switch(b_(g),g.tag){case 2:case 16:case 15:case 0:case 11:case 7:case 8:case 12:case 9:case 14:return mn(g),null;case 1:return TC(g.type)&&TW(),mn(g),null;case 3:return i=g.stateNode,Up(),yI(HC),yI(Xn),R_(),i.pendingContext&&(i.context=i.pendingContext,i.pendingContext=null),(e===null||e.child===null)&&(Fw(g)?g.flags|=4:e===null||e.memoizedState.isDehydrated&&!(g.flags&256)||(g.flags|=1024,xo!==null&&(oE(xo),xo=null))),eE(e,g),mn(g),null;case 5:V_(g);var n=Qu(Hv.current);if(I=g.type,e!==null&&g.stateNode!=null)kde(e,g,I,i,n),e.ref!==g.ref&&(g.flags|=512,g.flags|=2097152);else{if(!i){if(g.stateNode===null)throw Error(at(166));return mn(g),null}if(e=Qu(ga.current),Fw(g)){i=g.stateNode,I=g.type;var C=g.memoizedProps;switch(i[kA]=g,i[Wv]=C,e=(g.mode&1)!==0,I){case"dialog":cI("cancel",i),cI("close",i);break;case"iframe":case"object":case"embed":cI("load",i);break;case"video":case"audio":for(n=0;n<\/script>",e=e.removeChild(e.firstChild)):typeof i.is=="string"?e=r.createElement(I,{is:i.is}):(e=r.createElement(I),I==="select"&&(r=e,i.multiple?r.multiple=!0:i.size&&(r.size=i.size))):e=r.createElementNS(e,I),e[kA]=g,e[Wv]=i,Nde(e,g,!1,!1),g.stateNode=e;e:{switch(r=VF(I,i),I){case"dialog":cI("cancel",e),cI("close",e),n=i;break;case"iframe":case"object":case"embed":cI("load",e),n=i;break;case"video":case"audio":for(n=0;njp&&(g.flags|=128,i=!0,uy(C,!1),g.lanes=4194304)}else{if(!i)if(e=FW(r),e!==null){if(g.flags|=128,i=!0,I=e.updateQueue,I!==null&&(g.updateQueue=I,g.flags|=4),uy(C,!0),C.tail===null&&C.tailMode==="hidden"&&!r.alternate&&!RI)return mn(g),null}else 2*oi()-C.renderingStartTime>jp&&I!==1073741824&&(g.flags|=128,i=!0,uy(C,!1),g.lanes=4194304);C.isBackwards?(r.sibling=g.child,g.child=r):(I=C.last,I!==null?I.sibling=r:g.child=r,C.last=r)}return C.tail!==null?(g=C.tail,C.rendering=g,C.tail=g.sibling,C.renderingStartTime=oi(),g.sibling=null,I=kI.current,CI(kI,i?I&1|2:I&1),g):(mn(g),null);case 22:case 23:return F_(),i=g.memoizedState!==null,e!==null&&e.memoizedState!==null!==i&&(g.flags|=8192),i&&g.mode&1?_C&1073741824&&(mn(g),g.subtreeFlags&6&&(g.flags|=8192)):mn(g),null;case 24:return null;case 25:return null}throw Error(at(156,g.tag))}function kYe(e,g){switch(b_(g),g.tag){case 1:return TC(g.type)&&TW(),e=g.flags,e&65536?(g.flags=e&-65537|128,g):null;case 3:return Up(),yI(HC),yI(Xn),R_(),e=g.flags,e&65536&&!(e&128)?(g.flags=e&-65537|128,g):null;case 5:return V_(g),null;case 13:if(yI(kI),e=g.memoizedState,e!==null&&e.dehydrated!==null){if(g.alternate===null)throw Error(at(340));_p()}return e=g.flags,e&65536?(g.flags=e&-65537|128,g):null;case 19:return yI(kI),null;case 4:return Up(),null;case 10:return v_(g.type._context),null;case 22:case 23:return F_(),null;case 24:return null;default:return null}}var zw=!1,Rn=!1,YYe=typeof WeakSet=="function"?WeakSet:Set,wt=null;function Pf(e,g){var I=e.ref;if(I!==null)if(typeof I=="function")try{I(null)}catch(i){_I(e,g,i)}else I.current=null}function tE(e,g,I){try{I()}catch(i){_I(e,g,i)}}var a6=!1;function KYe(e,g){if(DF=RW,e=Fue(),f_(e)){if("selectionStart"in e)var I={start:e.selectionStart,end:e.selectionEnd};else e:{I=(I=e.ownerDocument)&&I.defaultView||window;var i=I.getSelection&&I.getSelection();if(i&&i.rangeCount!==0){I=i.anchorNode;var n=i.anchorOffset,C=i.focusNode;i=i.focusOffset;try{I.nodeType,C.nodeType}catch{I=null;break e}var r=0,o=-1,A=-1,s=0,a=0,l=e,c=null;t:for(;;){for(var u;l!==I||n!==0&&l.nodeType!==3||(o=r+n),l!==C||i!==0&&l.nodeType!==3||(A=r+i),l.nodeType===3&&(r+=l.nodeValue.length),(u=l.firstChild)!==null;)c=l,l=u;for(;;){if(l===e)break t;if(c===I&&++s===n&&(o=r),c===C&&++a===i&&(A=r),(u=l.nextSibling)!==null)break;l=c,c=l.parentNode}l=u}I=o===-1||A===-1?null:{start:o,end:A}}else I=null}I=I||{start:0,end:0}}else I=null;for(xF={focusedElem:e,selectionRange:I},RW=!1,wt=g;wt!==null;)if(g=wt,e=g.child,(g.subtreeFlags&1028)!==0&&e!==null)e.return=g,wt=e;else for(;wt!==null;){g=wt;try{var d=g.alternate;if(g.flags&1024)switch(g.tag){case 0:case 11:case 15:break;case 1:if(d!==null){var h=d.memoizedProps,m=d.memoizedState,f=g.stateNode,b=f.getSnapshotBeforeUpdate(g.elementType===g.type?h:ko(g.type,h),m);f.__reactInternalSnapshotBeforeUpdate=b}break;case 3:var p=g.stateNode.containerInfo;p.nodeType===1?p.textContent="":p.nodeType===9&&p.documentElement&&p.removeChild(p.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(at(163))}}catch(y){_I(g,g.return,y)}if(e=g.sibling,e!==null){e.return=g.return,wt=e;break}wt=g.return}return d=a6,a6=!1,d}function hG(e,g,I){var i=g.updateQueue;if(i=i!==null?i.lastEffect:null,i!==null){var n=i=i.next;do{if((n.tag&e)===e){var C=n.destroy;n.destroy=void 0,C!==void 0&&tE(g,I,C)}n=n.next}while(n!==i)}}function kH(e,g){if(g=g.updateQueue,g=g!==null?g.lastEffect:null,g!==null){var I=g=g.next;do{if((I.tag&e)===e){var i=I.create;I.destroy=i()}I=I.next}while(I!==g)}}function gE(e){var g=e.ref;if(g!==null){var I=e.stateNode;switch(e.tag){case 5:e=I;break;default:e=I}typeof g=="function"?g(e):g.current=e}}function Kde(e){var g=e.alternate;g!==null&&(e.alternate=null,Kde(g)),e.child=null,e.deletions=null,e.sibling=null,e.tag===5&&(g=e.stateNode,g!==null&&(delete g[kA],delete g[Wv],delete g[MF],delete g[pYe],delete g[bYe])),e.stateNode=null,e.return=null,e.dependencies=null,e.memoizedProps=null,e.memoizedState=null,e.pendingProps=null,e.stateNode=null,e.updateQueue=null}function Dde(e){return e.tag===5||e.tag===3||e.tag===4}function s6(e){e:for(;;){for(;e.sibling===null;){if(e.return===null||Dde(e.return))return null;e=e.return}for(e.sibling.return=e.return,e=e.sibling;e.tag!==5&&e.tag!==6&&e.tag!==18;){if(e.flags&2||e.child===null||e.tag===4)continue e;e.child.return=e,e=e.child}if(!(e.flags&2))return e.stateNode}}function IE(e,g,I){var i=e.tag;if(i===5||i===6)e=e.stateNode,g?I.nodeType===8?I.parentNode.insertBefore(e,g):I.insertBefore(e,g):(I.nodeType===8?(g=I.parentNode,g.insertBefore(e,I)):(g=I,g.appendChild(e)),I=I._reactRootContainer,I!=null||g.onclick!==null||(g.onclick=HW));else if(i!==4&&(e=e.child,e!==null))for(IE(e,g,I),e=e.sibling;e!==null;)IE(e,g,I),e=e.sibling}function iE(e,g,I){var i=e.tag;if(i===5||i===6)e=e.stateNode,g?I.insertBefore(e,g):I.appendChild(e);else if(i!==4&&(e=e.child,e!==null))for(iE(e,g,I),e=e.sibling;e!==null;)iE(e,g,I),e=e.sibling}var gn=null,Ko=!1;function ol(e,g,I){for(I=I.child;I!==null;)xde(e,g,I),I=I.sibling}function xde(e,g,I){if(ta&&typeof ta.onCommitFiberUnmount=="function")try{ta.onCommitFiberUnmount(wH,I)}catch{}switch(I.tag){case 5:Rn||Pf(I,g);case 6:var i=gn,n=Ko;gn=null,ol(e,g,I),gn=i,Ko=n,gn!==null&&(Ko?(e=gn,I=I.stateNode,e.nodeType===8?e.parentNode.removeChild(I):e.removeChild(I)):gn.removeChild(I.stateNode));break;case 18:gn!==null&&(Ko?(e=gn,I=I.stateNode,e.nodeType===8?SY(e.parentNode,I):e.nodeType===1&&SY(e,I),Bv(e)):SY(gn,I.stateNode));break;case 4:i=gn,n=Ko,gn=I.stateNode.containerInfo,Ko=!0,ol(e,g,I),gn=i,Ko=n;break;case 0:case 11:case 14:case 15:if(!Rn&&(i=I.updateQueue,i!==null&&(i=i.lastEffect,i!==null))){n=i=i.next;do{var C=n,r=C.destroy;C=C.tag,r!==void 0&&(C&2||C&4)&&tE(I,g,r),n=n.next}while(n!==i)}ol(e,g,I);break;case 1:if(!Rn&&(Pf(I,g),i=I.stateNode,typeof i.componentWillUnmount=="function"))try{i.props=I.memoizedProps,i.state=I.memoizedState,i.componentWillUnmount()}catch(o){_I(I,g,o)}ol(e,g,I);break;case 21:ol(e,g,I);break;case 22:I.mode&1?(Rn=(i=Rn)||I.memoizedState!==null,ol(e,g,I),Rn=i):ol(e,g,I);break;default:ol(e,g,I)}}function l6(e){var g=e.updateQueue;if(g!==null){e.updateQueue=null;var I=e.stateNode;I===null&&(I=e.stateNode=new YYe),g.forEach(function(i){var n=OYe.bind(null,e,i);I.has(i)||(I.add(i),i.then(n,n))})}}function so(e,g){var I=g.deletions;if(I!==null)for(var i=0;in&&(n=r),i&=~C}if(i=n,i=oi()-i,i=(120>i?120:480>i?480:1080>i?1080:1920>i?1920:3e3>i?3e3:4320>i?4320:1960*xYe(i/1960))-i,10e?16:e,tc===null)var i=!1;else{if(e=tc,tc=null,JW=0,Wg&6)throw Error(at(331));var n=Wg;for(Wg|=4,wt=e.current;wt!==null;){var C=wt,r=C.child;if(wt.flags&16){var o=C.deletions;if(o!==null){for(var A=0;Aoi()-D_?ld(e,0):K_|=I),NC(e,g)}function _de(e,g){g===0&&(e.mode&1?(g=Nw,Nw<<=1,!(Nw&130023424)&&(Nw=4194304)):g=1);var I=gC();e=ws(e,g),e!==null&&(gS(e,g,I),NC(e,I))}function JYe(e){var g=e.memoizedState,I=0;g!==null&&(I=g.retryLane),_de(e,I)}function OYe(e,g){var I=0;switch(e.tag){case 13:var i=e.stateNode,n=e.memoizedState;n!==null&&(I=n.retryLane);break;case 19:i=e.stateNode;break;default:throw Error(at(314))}i!==null&&i.delete(g),_de(e,I)}var Lde;Lde=function(e,g,I){if(e!==null)if(e.memoizedProps!==g.pendingProps||HC.current)RC=!0;else{if(!(e.lanes&I)&&!(g.flags&128))return RC=!1,TYe(e,g,I);RC=!!(e.flags&131072)}else RC=!1,RI&&g.flags&1048576&&jue(g,YW,g.index);switch(g.lanes=0,g.tag){case 2:var i=g.type;qR(e,g),e=g.pendingProps;var n=Op(g,Xn.current);ap(g,I),n=X_(null,g,i,e,n,I);var C=H_();return g.flags|=1,typeof n=="object"&&n!==null&&typeof n.render=="function"&&n.$$typeof===void 0?(g.tag=1,g.memoizedState=null,g.updateQueue=null,TC(i)?(C=!0,NW(g)):C=!1,g.memoizedState=n.state!==null&&n.state!==void 0?n.state:null,S_(g),n.updater=TH,g.stateNode=n,n._reactInternals=g,LF(g,i,e,I),g=jF(null,g,i,!0,C,I)):(g.tag=0,RI&&C&&p_(g),zn(null,g,n,I),g=g.child),g;case 16:i=g.elementType;e:{switch(qR(e,g),e=g.pendingProps,n=i._init,i=n(i._payload),g.type=i,n=g.tag=LYe(i),e=ko(i,e),n){case 0:g=QF(null,g,i,e,I);break e;case 1:g=r6(null,g,i,e,I);break e;case 11:g=n6(null,g,i,e,I);break e;case 14:g=C6(null,g,i,ko(i.type,e),I);break e}throw Error(at(306,i,""))}return g;case 0:return i=g.type,n=g.pendingProps,n=g.elementType===i?n:ko(i,n),QF(e,g,i,n,I);case 1:return i=g.type,n=g.pendingProps,n=g.elementType===i?n:ko(i,n),r6(e,g,i,n,I);case 3:e:{if(Xde(g),e===null)throw Error(at(387));i=g.pendingProps,C=g.memoizedState,n=C.element,tde(e,g),xW(g,i,null,I);var r=g.memoizedState;if(i=r.element,C.isDehydrated)if(C={element:i,isDehydrated:!1,cache:r.cache,pendingSuspenseBoundaries:r.pendingSuspenseBoundaries,transitions:r.transitions},g.updateQueue.baseState=C,g.memoizedState=C,g.flags&256){n=Qp(Error(at(423)),g),g=o6(e,g,i,I,n);break e}else if(i!==n){n=Qp(Error(at(424)),g),g=o6(e,g,i,I,n);break e}else for(nr=mc(g.stateNode.containerInfo.firstChild),or=g,RI=!0,xo=null,I=nde(g,null,i,I),g.child=I;I;)I.flags=I.flags&-3|4096,I=I.sibling;else{if(_p(),i===n){g=Vs(e,g,I);break e}zn(e,g,i,I)}g=g.child}return g;case 5:return Cde(g),e===null&&JF(g),i=g.type,n=g.pendingProps,C=e!==null?e.memoizedProps:null,r=n.children,FF(i,n)?r=null:C!==null&&FF(i,C)&&(g.flags|=32),Wde(e,g),zn(e,g,r,I),g.child;case 6:return e===null&&JF(g),null;case 13:return Hde(e,g,I);case 4:return w_(g,g.stateNode.containerInfo),i=g.pendingProps,e===null?g.child=Lp(g,null,i,I):zn(e,g,i,I),g.child;case 11:return i=g.type,n=g.pendingProps,n=g.elementType===i?n:ko(i,n),n6(e,g,i,n,I);case 7:return zn(e,g,g.pendingProps,I),g.child;case 8:return zn(e,g,g.pendingProps.children,I),g.child;case 12:return zn(e,g,g.pendingProps.children,I),g.child;case 10:e:{if(i=g.type._context,n=g.pendingProps,C=g.memoizedProps,r=n.value,CI(KW,i._currentValue),i._currentValue=r,C!==null)if(nA(C.value,r)){if(C.children===n.children&&!HC.current){g=Vs(e,g,I);break e}}else for(C=g.child,C!==null&&(C.return=g);C!==null;){var o=C.dependencies;if(o!==null){r=C.child;for(var A=o.firstContext;A!==null;){if(A.context===i){if(C.tag===1){A=ps(-1,I&-I),A.tag=2;var s=C.updateQueue;if(s!==null){s=s.shared;var a=s.pending;a===null?A.next=A:(A.next=a.next,a.next=A),s.pending=A}}C.lanes|=I,A=C.alternate,A!==null&&(A.lanes|=I),OF(C.return,I,g),o.lanes|=I;break}A=A.next}}else if(C.tag===10)r=C.type===g.type?null:C.child;else if(C.tag===18){if(r=C.return,r===null)throw Error(at(341));r.lanes|=I,o=r.alternate,o!==null&&(o.lanes|=I),OF(r,I,g),r=C.sibling}else r=C.child;if(r!==null)r.return=C;else for(r=C;r!==null;){if(r===g){r=null;break}if(C=r.sibling,C!==null){C.return=r.return,r=C;break}r=r.return}C=r}zn(e,g,n.children,I),g=g.child}return g;case 9:return n=g.type,i=g.pendingProps.children,ap(g,I),n=$r(n),i=i(n),g.flags|=1,zn(e,g,i,I),g.child;case 14:return i=g.type,n=ko(i,g.pendingProps),n=ko(i.type,n),C6(e,g,i,n,I);case 15:return Vde(e,g,g.type,g.pendingProps,I);case 17:return i=g.type,n=g.pendingProps,n=g.elementType===i?n:ko(i,n),qR(e,g),g.tag=1,TC(i)?(e=!0,NW(g)):e=!1,ap(g,I),Ide(g,i,n),LF(g,i,n,I),jF(null,g,i,!0,e,I);case 19:return Tde(e,g,I);case 22:return Rde(e,g,I)}throw Error(at(156,g.tag))};function Ude(e,g){return yue(e,g)}function _Ye(e,g,I,i){this.tag=e,this.key=I,this.sibling=this.child=this.return=this.stateNode=this.type=this.elementType=null,this.index=0,this.ref=null,this.pendingProps=g,this.dependencies=this.memoizedState=this.updateQueue=this.memoizedProps=null,this.mode=i,this.subtreeFlags=this.flags=0,this.deletions=null,this.childLanes=this.lanes=0,this.alternate=null}function Er(e,g,I,i){return new _Ye(e,g,I,i)}function M_(e){return e=e.prototype,!(!e||!e.isReactComponent)}function LYe(e){if(typeof e=="function")return M_(e)?1:0;if(e!=null){if(e=e.$$typeof,e===r_)return 11;if(e===o_)return 14}return 2}function yc(e,g){var I=e.alternate;return I===null?(I=Er(e.tag,g,e.key,e.mode),I.elementType=e.elementType,I.type=e.type,I.stateNode=e.stateNode,I.alternate=e,e.alternate=I):(I.pendingProps=g,I.type=e.type,I.flags=0,I.subtreeFlags=0,I.deletions=null),I.flags=e.flags&14680064,I.childLanes=e.childLanes,I.lanes=e.lanes,I.child=e.child,I.memoizedProps=e.memoizedProps,I.memoizedState=e.memoizedState,I.updateQueue=e.updateQueue,g=e.dependencies,I.dependencies=g===null?null:{lanes:g.lanes,firstContext:g.firstContext},I.sibling=e.sibling,I.index=e.index,I.ref=e.ref,I}function g1(e,g,I,i,n,C){var r=2;if(i=e,typeof e=="function")M_(e)&&(r=1);else if(typeof e=="string")r=5;else e:switch(e){case kf:return cd(I.children,n,C,g);case C_:r=8,n|=8;break;case fF:return e=Er(12,I,g,n|2),e.elementType=fF,e.lanes=C,e;case pF:return e=Er(13,I,g,n),e.elementType=pF,e.lanes=C,e;case bF:return e=Er(19,I,g,n),e.elementType=bF,e.lanes=C,e;case iue:return KH(I,n,C,g);default:if(typeof e=="object"&&e!==null)switch(e.$$typeof){case gue:r=10;break e;case Iue:r=9;break e;case r_:r=11;break e;case o_:r=14;break e;case Tl:r=16,i=null;break e}throw Error(at(130,e==null?e:typeof e,""))}return g=Er(r,I,g,n),g.elementType=e,g.type=i,g.lanes=C,g}function cd(e,g,I,i){return e=Er(7,e,i,g),e.lanes=I,e}function KH(e,g,I,i){return e=Er(22,e,i,g),e.elementType=iue,e.lanes=I,e.stateNode={isHidden:!1},e}function NY(e,g,I){return e=Er(6,e,null,g),e.lanes=I,e}function kY(e,g,I){return g=Er(4,e.children!==null?e.children:[],e.key,g),g.lanes=I,g.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},g}function UYe(e,g,I,i,n){this.tag=g,this.containerInfo=e,this.finishedWork=this.pingCache=this.current=this.pendingChildren=null,this.timeoutHandle=-1,this.callbackNode=this.pendingContext=this.context=null,this.callbackPriority=0,this.eventTimes=dY(0),this.expirationTimes=dY(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=dY(0),this.identifierPrefix=i,this.onRecoverableError=n,this.mutableSourceEagerHydrationData=null}function z_(e,g,I,i,n,C,r,o,A){return e=new UYe(e,g,I,o,A),g===1?(g=1,C===!0&&(g|=8)):g=0,C=Er(3,null,null,g),e.current=C,C.stateNode=e,C.memoizedState={element:i,isDehydrated:I,cache:null,transitions:null,pendingSuspenseBoundaries:null},S_(C),e}function QYe(e,g,I){var i=3"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(qde)}catch(e){console.error(e)}}qde(),jce.exports=dr;var Rs=jce.exports;const UI=Fc(Rs);var b6=Rs;hF.createRoot=b6.createRoot,hF.hydrateRoot=b6.hydrateRoot;const tKe="modulepreload",gKe=function(e){return"/alt-gosling/"+e},y6={},IKe=function(g,I,i){if(!I||I.length===0)return g();const n=document.getElementsByTagName("link");return Promise.all(I.map(C=>{if(C=gKe(C),C in y6)return;y6[C]=!0;const r=C.endsWith(".css"),o=r?'[rel="stylesheet"]':"";if(!!i)for(let a=n.length-1;a>=0;a--){const l=n[a];if(l.href===C&&(!r||l.rel==="stylesheet"))return}else if(document.querySelector(`link[href="${C}"]${o}`))return;const s=document.createElement("link");if(s.rel=r?"stylesheet":tKe,r||(s.as="script",s.crossOrigin=""),s.href=C,document.head.appendChild(s),r)return new Promise((a,l)=>{s.addEventListener("load",a),s.addEventListener("error",()=>l(new Error(`Unable to preload CSS for ${C}`)))})})).then(()=>g()).catch(C=>{const r=new Event("vite:preloadError",{cancelable:!0});if(r.payload=C,window.dispatchEvent(r),!r.defaultPrevented)throw C})};function iKe(e){var g=this.constructor;return this.then(function(I){return g.resolve(e()).then(function(){return I})},function(I){return g.resolve(e()).then(function(){return g.reject(I)})})}function nKe(e){var g=this;return new g(function(I,i){if(!(e&&typeof e.length<"u"))return i(new TypeError(typeof e+" "+e+" is not iterable(cannot read property Symbol(Symbol.iterator))"));var n=Array.prototype.slice.call(e);if(n.length===0)return I([]);var C=n.length;function r(A,s){if(s&&(typeof s=="object"||typeof s=="function")){var a=s.then;if(typeof a=="function"){a.call(s,function(l){r(A,l)},function(l){n[A]={status:"rejected",reason:l},--C===0&&I(n)});return}}n[A]={status:"fulfilled",value:s},--C===0&&I(n)}for(var o=0;o"u"&&(typeof self<"u"?self.globalThis=self:typeof global<"u"&&(global.globalThis=global));globalThis.Promise||(globalThis.Promise=FI);Object.assign||(Object.assign=hKe);var mKe=16;Date.now&&Date.prototype.getTime||(Date.now=function(){return new Date().getTime()});if(!(globalThis.performance&&globalThis.performance.now)){var fKe=Date.now();globalThis.performance||(globalThis.performance={}),globalThis.performance.now=function(){return Date.now()-fKe}}var YY=Date.now(),G6=["ms","moz","webkit","o"];for(var KY=0;KY0?1:-1});Number.isInteger||(Number.isInteger=function(g){return typeof g=="number"&&isFinite(g)&&Math.floor(g)===g});globalThis.ArrayBuffer||(globalThis.ArrayBuffer=Array);globalThis.Float32Array||(globalThis.Float32Array=Array);globalThis.Uint32Array||(globalThis.Uint32Array=Array);globalThis.Uint16Array||(globalThis.Uint16Array=Array);globalThis.Uint8Array||(globalThis.Uint8Array=Array);globalThis.Int32Array||(globalThis.Int32Array=Array);/*! + * @pixi/constants - v6.5.10 + * Compiled Thu, 06 Jul 2023 15:25:11 UTC + * + * @pixi/constants is licensed under the MIT License. + * http://www.opensource.org/licenses/mit-license + */var aa;(function(e){e[e.WEBGL_LEGACY=0]="WEBGL_LEGACY",e[e.WEBGL=1]="WEBGL",e[e.WEBGL2=2]="WEBGL2"})(aa||(aa={}));var $p;(function(e){e[e.UNKNOWN=0]="UNKNOWN",e[e.WEBGL=1]="WEBGL",e[e.CANVAS=2]="CANVAS"})($p||($p={}));var Dv;(function(e){e[e.COLOR=16384]="COLOR",e[e.DEPTH=256]="DEPTH",e[e.STENCIL=1024]="STENCIL"})(Dv||(Dv={}));var Jt;(function(e){e[e.NORMAL=0]="NORMAL",e[e.ADD=1]="ADD",e[e.MULTIPLY=2]="MULTIPLY",e[e.SCREEN=3]="SCREEN",e[e.OVERLAY=4]="OVERLAY",e[e.DARKEN=5]="DARKEN",e[e.LIGHTEN=6]="LIGHTEN",e[e.COLOR_DODGE=7]="COLOR_DODGE",e[e.COLOR_BURN=8]="COLOR_BURN",e[e.HARD_LIGHT=9]="HARD_LIGHT",e[e.SOFT_LIGHT=10]="SOFT_LIGHT",e[e.DIFFERENCE=11]="DIFFERENCE",e[e.EXCLUSION=12]="EXCLUSION",e[e.HUE=13]="HUE",e[e.SATURATION=14]="SATURATION",e[e.COLOR=15]="COLOR",e[e.LUMINOSITY=16]="LUMINOSITY",e[e.NORMAL_NPM=17]="NORMAL_NPM",e[e.ADD_NPM=18]="ADD_NPM",e[e.SCREEN_NPM=19]="SCREEN_NPM",e[e.NONE=20]="NONE",e[e.SRC_OVER=0]="SRC_OVER",e[e.SRC_IN=21]="SRC_IN",e[e.SRC_OUT=22]="SRC_OUT",e[e.SRC_ATOP=23]="SRC_ATOP",e[e.DST_OVER=24]="DST_OVER",e[e.DST_IN=25]="DST_IN",e[e.DST_OUT=26]="DST_OUT",e[e.DST_ATOP=27]="DST_ATOP",e[e.ERASE=26]="ERASE",e[e.SUBTRACT=28]="SUBTRACT",e[e.XOR=29]="XOR"})(Jt||(Jt={}));var Mr;(function(e){e[e.POINTS=0]="POINTS",e[e.LINES=1]="LINES",e[e.LINE_LOOP=2]="LINE_LOOP",e[e.LINE_STRIP=3]="LINE_STRIP",e[e.TRIANGLES=4]="TRIANGLES",e[e.TRIANGLE_STRIP=5]="TRIANGLE_STRIP",e[e.TRIANGLE_FAN=6]="TRIANGLE_FAN"})(Mr||(Mr={}));var ht;(function(e){e[e.RGBA=6408]="RGBA",e[e.RGB=6407]="RGB",e[e.RG=33319]="RG",e[e.RED=6403]="RED",e[e.RGBA_INTEGER=36249]="RGBA_INTEGER",e[e.RGB_INTEGER=36248]="RGB_INTEGER",e[e.RG_INTEGER=33320]="RG_INTEGER",e[e.RED_INTEGER=36244]="RED_INTEGER",e[e.ALPHA=6406]="ALPHA",e[e.LUMINANCE=6409]="LUMINANCE",e[e.LUMINANCE_ALPHA=6410]="LUMINANCE_ALPHA",e[e.DEPTH_COMPONENT=6402]="DEPTH_COMPONENT",e[e.DEPTH_STENCIL=34041]="DEPTH_STENCIL"})(ht||(ht={}));var Zc;(function(e){e[e.TEXTURE_2D=3553]="TEXTURE_2D",e[e.TEXTURE_CUBE_MAP=34067]="TEXTURE_CUBE_MAP",e[e.TEXTURE_2D_ARRAY=35866]="TEXTURE_2D_ARRAY",e[e.TEXTURE_CUBE_MAP_POSITIVE_X=34069]="TEXTURE_CUBE_MAP_POSITIVE_X",e[e.TEXTURE_CUBE_MAP_NEGATIVE_X=34070]="TEXTURE_CUBE_MAP_NEGATIVE_X",e[e.TEXTURE_CUBE_MAP_POSITIVE_Y=34071]="TEXTURE_CUBE_MAP_POSITIVE_Y",e[e.TEXTURE_CUBE_MAP_NEGATIVE_Y=34072]="TEXTURE_CUBE_MAP_NEGATIVE_Y",e[e.TEXTURE_CUBE_MAP_POSITIVE_Z=34073]="TEXTURE_CUBE_MAP_POSITIVE_Z",e[e.TEXTURE_CUBE_MAP_NEGATIVE_Z=34074]="TEXTURE_CUBE_MAP_NEGATIVE_Z"})(Zc||(Zc={}));var Et;(function(e){e[e.UNSIGNED_BYTE=5121]="UNSIGNED_BYTE",e[e.UNSIGNED_SHORT=5123]="UNSIGNED_SHORT",e[e.UNSIGNED_SHORT_5_6_5=33635]="UNSIGNED_SHORT_5_6_5",e[e.UNSIGNED_SHORT_4_4_4_4=32819]="UNSIGNED_SHORT_4_4_4_4",e[e.UNSIGNED_SHORT_5_5_5_1=32820]="UNSIGNED_SHORT_5_5_5_1",e[e.UNSIGNED_INT=5125]="UNSIGNED_INT",e[e.UNSIGNED_INT_10F_11F_11F_REV=35899]="UNSIGNED_INT_10F_11F_11F_REV",e[e.UNSIGNED_INT_2_10_10_10_REV=33640]="UNSIGNED_INT_2_10_10_10_REV",e[e.UNSIGNED_INT_24_8=34042]="UNSIGNED_INT_24_8",e[e.UNSIGNED_INT_5_9_9_9_REV=35902]="UNSIGNED_INT_5_9_9_9_REV",e[e.BYTE=5120]="BYTE",e[e.SHORT=5122]="SHORT",e[e.INT=5124]="INT",e[e.FLOAT=5126]="FLOAT",e[e.FLOAT_32_UNSIGNED_INT_24_8_REV=36269]="FLOAT_32_UNSIGNED_INT_24_8_REV",e[e.HALF_FLOAT=36193]="HALF_FLOAT"})(Et||(Et={}));var xv;(function(e){e[e.FLOAT=0]="FLOAT",e[e.INT=1]="INT",e[e.UINT=2]="UINT"})(xv||(xv={}));var Oo;(function(e){e[e.NEAREST=0]="NEAREST",e[e.LINEAR=1]="LINEAR"})(Oo||(Oo={}));var $o;(function(e){e[e.CLAMP=33071]="CLAMP",e[e.REPEAT=10497]="REPEAT",e[e.MIRRORED_REPEAT=33648]="MIRRORED_REPEAT"})($o||($o={}));var eo;(function(e){e[e.OFF=0]="OFF",e[e.POW2=1]="POW2",e[e.ON=2]="ON",e[e.ON_MANUAL=3]="ON_MANUAL"})(eo||(eo={}));var to;(function(e){e[e.NPM=0]="NPM",e[e.UNPACK=1]="UNPACK",e[e.PMA=2]="PMA",e[e.NO_PREMULTIPLIED_ALPHA=0]="NO_PREMULTIPLIED_ALPHA",e[e.PREMULTIPLY_ON_UPLOAD=1]="PREMULTIPLY_ON_UPLOAD",e[e.PREMULTIPLY_ALPHA=2]="PREMULTIPLY_ALPHA",e[e.PREMULTIPLIED_ALPHA=2]="PREMULTIPLIED_ALPHA"})(to||(to={}));var kr;(function(e){e[e.NO=0]="NO",e[e.YES=1]="YES",e[e.AUTO=2]="AUTO",e[e.BLEND=0]="BLEND",e[e.CLEAR=1]="CLEAR",e[e.BLIT=2]="BLIT"})(kr||(kr={}));var Fv;(function(e){e[e.AUTO=0]="AUTO",e[e.MANUAL=1]="MANUAL"})(Fv||(Fv={}));var WC;(function(e){e.LOW="lowp",e.MEDIUM="mediump",e.HIGH="highp"})(WC||(WC={}));var ii;(function(e){e[e.NONE=0]="NONE",e[e.SCISSOR=1]="SCISSOR",e[e.STENCIL=2]="STENCIL",e[e.SPRITE=3]="SPRITE",e[e.COLOR=4]="COLOR"})(ii||(ii={}));var sE;(function(e){e[e.RED=1]="RED",e[e.GREEN=2]="GREEN",e[e.BLUE=4]="BLUE",e[e.ALPHA=8]="ALPHA"})(sE||(sE={}));var mI;(function(e){e[e.NONE=0]="NONE",e[e.LOW=2]="LOW",e[e.MEDIUM=4]="MEDIUM",e[e.HIGH=8]="HIGH"})(mI||(mI={}));var qo;(function(e){e[e.ELEMENT_ARRAY_BUFFER=34963]="ELEMENT_ARRAY_BUFFER",e[e.ARRAY_BUFFER=34962]="ARRAY_BUFFER",e[e.UNIFORM_BUFFER=35345]="UNIFORM_BUFFER"})(qo||(qo={}));/*! + * @pixi/settings - v6.5.10 + * Compiled Thu, 06 Jul 2023 15:25:11 UTC + * + * @pixi/settings is licensed under the MIT License. + * http://www.opensource.org/licenses/mit-license + */var ihe={createCanvas:function(e,g){var I=document.createElement("canvas");return I.width=e,I.height=g,I},getWebGLRenderingContext:function(){return WebGLRenderingContext},getNavigator:function(){return navigator},getBaseUrl:function(){var e;return(e=document.baseURI)!==null&&e!==void 0?e:window.location.href},fetch:function(e,g){return fetch(e,g)}},xY=/iPhone/i,v6=/iPod/i,B6=/iPad/i,S6=/\biOS-universal(?:.+)Mac\b/i,FY=/\bAndroid(?:.+)Mobile\b/i,w6=/Android/i,pm=/(?:SD4930UR|\bSilk(?:.+)Mobile\b)/i,Ow=/Silk/i,Xa=/Windows Phone/i,V6=/\bWindows(?:.+)ARM\b/i,R6=/BlackBerry/i,W6=/BB10/i,X6=/Opera Mini/i,H6=/\b(CriOS|Chrome)(?:.+)Mobile/i,T6=/Mobile(?:.+)Firefox\b/i,N6=function(e){return typeof e<"u"&&e.platform==="MacIntel"&&typeof e.maxTouchPoints=="number"&&e.maxTouchPoints>1&&typeof MSStream>"u"};function pKe(e){return function(g){return g.test(e)}}function bKe(e){var g={userAgent:"",platform:"",maxTouchPoints:0};!e&&typeof navigator<"u"?g={userAgent:navigator.userAgent,platform:navigator.platform,maxTouchPoints:navigator.maxTouchPoints||0}:typeof e=="string"?g.userAgent=e:e&&e.userAgent&&(g={userAgent:e.userAgent,platform:e.platform,maxTouchPoints:e.maxTouchPoints||0});var I=g.userAgent,i=I.split("[FBAN");typeof i[1]<"u"&&(I=i[0]),i=I.split("Twitter"),typeof i[1]<"u"&&(I=i[0]);var n=pKe(I),C={apple:{phone:n(xY)&&!n(Xa),ipod:n(v6),tablet:!n(xY)&&(n(B6)||N6(g))&&!n(Xa),universal:n(S6),device:(n(xY)||n(v6)||n(B6)||n(S6)||N6(g))&&!n(Xa)},amazon:{phone:n(pm),tablet:!n(pm)&&n(Ow),device:n(pm)||n(Ow)},android:{phone:!n(Xa)&&n(pm)||!n(Xa)&&n(FY),tablet:!n(Xa)&&!n(pm)&&!n(FY)&&(n(Ow)||n(w6)),device:!n(Xa)&&(n(pm)||n(Ow)||n(FY)||n(w6))||n(/\bokhttp\b/i)},windows:{phone:n(Xa),tablet:n(V6),device:n(Xa)||n(V6)},other:{blackberry:n(R6),blackberry10:n(W6),opera:n(X6),firefox:n(T6),chrome:n(H6),device:n(R6)||n(W6)||n(X6)||n(T6)||n(H6)},any:!1,phone:!1,tablet:!1};return C.any=C.apple.device||C.android.device||C.windows.device||C.other.device,C.phone=C.apple.phone||C.android.phone||C.windows.phone,C.tablet=C.apple.tablet||C.android.tablet||C.windows.tablet,C}var zr=bKe(globalThis.navigator);function yKe(){return!zr.apple.device}function ZKe(e){var g=!0;if(zr.tablet||zr.phone){if(zr.apple.device){var I=navigator.userAgent.match(/OS (\d+)_(\d+)?/);if(I){var i=parseInt(I[1],10);i<11&&(g=!1)}}if(zr.android.device){var I=navigator.userAgent.match(/Android\s([0-9.]*)/);if(I){var i=parseInt(I[1],10);i<7&&(g=!1)}}}return g?e:4}var yt={ADAPTER:ihe,MIPMAP_TEXTURES:eo.POW2,ANISOTROPIC_LEVEL:0,RESOLUTION:1,FILTER_RESOLUTION:1,FILTER_MULTISAMPLE:mI.NONE,SPRITE_MAX_TEXTURES:ZKe(32),SPRITE_BATCH_SIZE:4096,RENDER_OPTIONS:{view:null,width:800,height:600,autoDensity:!1,backgroundColor:0,backgroundAlpha:1,useContextAlpha:!0,clearBeforeRender:!0,antialias:!1,preserveDrawingBuffer:!1},GC_MODE:Fv.AUTO,GC_MAX_IDLE:60*60,GC_MAX_CHECK_COUNT:60*10,WRAP_MODE:$o.CLAMP,SCALE_MODE:Oo.LINEAR,PRECISION_VERTEX:WC.HIGH,PRECISION_FRAGMENT:zr.apple.device?WC.HIGH:WC.MEDIUM,CAN_UPLOAD_SAME_BUFFER:yKe(),CREATE_IMAGE_BITMAP:!1,ROUND_PIXELS:!1},nhe={exports:{}};(function(e){var g=Object.prototype.hasOwnProperty,I="~";function i(){}Object.create&&(i.prototype=Object.create(null),new i().__proto__||(I=!1));function n(A,s,a){this.fn=A,this.context=s,this.once=a||!1}function C(A,s,a,l,c){if(typeof a!="function")throw new TypeError("The listener must be a function");var u=new n(a,l||A,c),d=I?I+s:s;return A._events[d]?A._events[d].fn?A._events[d]=[A._events[d],u]:A._events[d].push(u):(A._events[d]=u,A._eventsCount++),A}function r(A,s){--A._eventsCount===0?A._events=new i:delete A._events[s]}function o(){this._events=new i,this._eventsCount=0}o.prototype.eventNames=function(){var s=[],a,l;if(this._eventsCount===0)return s;for(l in a=this._events)g.call(a,l)&&s.push(I?l.slice(1):l);return Object.getOwnPropertySymbols?s.concat(Object.getOwnPropertySymbols(a)):s},o.prototype.listeners=function(s){var a=I?I+s:s,l=this._events[a];if(!l)return[];if(l.fn)return[l.fn];for(var c=0,u=l.length,d=new Array(u);c80*I){o=s=e[0],A=a=e[1];for(var d=I;ds&&(s=l),c>a&&(a=c);u=Math.max(s-o,a-A),u=u!==0?32767/u:0}return Ev(C,r,I,o,A,u,0),r}function Che(e,g,I,i,n){var C,r;if(n===uE(e,g,I,i)>0)for(C=g;C=g;C-=i)r=k6(C,e[C],e[C+1],r);return r&&zH(r,r.next)&&(zv(r),r=r.next),r}function Kd(e,g){if(!e)return e;g||(g=e);var I=e,i;do if(i=!1,!I.steiner&&(zH(I,I.next)||YI(I.prev,I,I.next)===0)){if(zv(I),I=g=I.prev,I===I.next)break;i=!0}else I=I.next;while(i||I!==g);return g}function Ev(e,g,I,i,n,C,r){if(e){!r&&C&&TKe(e,i,n,C);for(var o=e,A,s;e.prev!==e.next;){if(A=e.prev,s=e.next,C?BKe(e,i,n,C):vKe(e)){g.push(A.i/I|0),g.push(e.i/I|0),g.push(s.i/I|0),zv(e),e=s.next,o=s.next;continue}if(e=s,e===o){r?r===1?(e=SKe(Kd(e),g,I),Ev(e,g,I,i,n,C,2)):r===2&&wKe(e,g,I,i,n,C):Ev(Kd(e),g,I,i,n,C,1);break}}}}function vKe(e){var g=e.prev,I=e,i=e.next;if(YI(g,I,i)>=0)return!1;for(var n=g.x,C=I.x,r=i.x,o=g.y,A=I.y,s=i.y,a=nC?n>r?n:r:C>r?C:r,u=o>A?o>s?o:s:A>s?A:s,d=i.next;d!==g;){if(d.x>=a&&d.x<=c&&d.y>=l&&d.y<=u&&Of(n,o,C,A,r,s,d.x,d.y)&&YI(d.prev,d,d.next)>=0)return!1;d=d.next}return!0}function BKe(e,g,I,i){var n=e.prev,C=e,r=e.next;if(YI(n,C,r)>=0)return!1;for(var o=n.x,A=C.x,s=r.x,a=n.y,l=C.y,c=r.y,u=oA?o>s?o:s:A>s?A:s,m=a>l?a>c?a:c:l>c?l:c,f=lE(u,d,g,I,i),b=lE(h,m,g,I,i),p=e.prevZ,y=e.nextZ;p&&p.z>=f&&y&&y.z<=b;){if(p.x>=u&&p.x<=h&&p.y>=d&&p.y<=m&&p!==n&&p!==r&&Of(o,a,A,l,s,c,p.x,p.y)&&YI(p.prev,p,p.next)>=0||(p=p.prevZ,y.x>=u&&y.x<=h&&y.y>=d&&y.y<=m&&y!==n&&y!==r&&Of(o,a,A,l,s,c,y.x,y.y)&&YI(y.prev,y,y.next)>=0))return!1;y=y.nextZ}for(;p&&p.z>=f;){if(p.x>=u&&p.x<=h&&p.y>=d&&p.y<=m&&p!==n&&p!==r&&Of(o,a,A,l,s,c,p.x,p.y)&&YI(p.prev,p,p.next)>=0)return!1;p=p.prevZ}for(;y&&y.z<=b;){if(y.x>=u&&y.x<=h&&y.y>=d&&y.y<=m&&y!==n&&y!==r&&Of(o,a,A,l,s,c,y.x,y.y)&&YI(y.prev,y,y.next)>=0)return!1;y=y.nextZ}return!0}function SKe(e,g,I){var i=e;do{var n=i.prev,C=i.next.next;!zH(n,C)&&rhe(n,i,i.next,C)&&Mv(n,C)&&Mv(C,n)&&(g.push(n.i/I|0),g.push(i.i/I|0),g.push(C.i/I|0),zv(i),zv(i.next),i=e=C),i=i.next}while(i!==e);return Kd(i)}function wKe(e,g,I,i,n,C){var r=e;do{for(var o=r.next.next;o!==r.prev;){if(r.i!==o.i&&YKe(r,o)){var A=ohe(r,o);r=Kd(r,r.next),A=Kd(A,A.next),Ev(r,g,I,i,n,C,0),Ev(A,g,I,i,n,C,0);return}o=o.next}r=r.next}while(r!==e)}function VKe(e,g,I,i){var n=[],C,r,o,A,s;for(C=0,r=g.length;C=I.next.y&&I.next.y!==I.y){var o=I.x+(n-I.y)*(I.next.x-I.x)/(I.next.y-I.y);if(o<=i&&o>C&&(C=o,r=I.x=I.x&&I.x>=s&&i!==I.x&&Of(nr.x||I.x===r.x&&HKe(r,I)))&&(r=I,l=c)),I=I.next;while(I!==A);return r}function HKe(e,g){return YI(e.prev,e,g.prev)<0&&YI(g.next,e,e.next)<0}function TKe(e,g,I,i){var n=e;do n.z===0&&(n.z=lE(n.x,n.y,g,I,i)),n.prevZ=n.prev,n.nextZ=n.next,n=n.next;while(n!==e);n.prevZ.nextZ=null,n.prevZ=null,NKe(n)}function NKe(e){var g,I,i,n,C,r,o,A,s=1;do{for(I=e,e=null,C=null,r=0;I;){for(r++,i=I,o=0,g=0;g0||A>0&&i;)o!==0&&(A===0||!i||I.z<=i.z)?(n=I,I=I.nextZ,o--):(n=i,i=i.nextZ,A--),C?C.nextZ=n:e=n,n.prevZ=C,C=n;I=i}C.nextZ=null,s*=2}while(r>1);return e}function lE(e,g,I,i,n){return e=(e-I)*n|0,g=(g-i)*n|0,e=(e|e<<8)&16711935,e=(e|e<<4)&252645135,e=(e|e<<2)&858993459,e=(e|e<<1)&1431655765,g=(g|g<<8)&16711935,g=(g|g<<4)&252645135,g=(g|g<<2)&858993459,g=(g|g<<1)&1431655765,e|g<<1}function kKe(e){var g=e,I=e;do(g.x=(e-r)*(C-o)&&(e-r)*(i-o)>=(I-r)*(g-o)&&(I-r)*(C-o)>=(n-r)*(i-o)}function YKe(e,g){return e.next.i!==g.i&&e.prev.i!==g.i&&!KKe(e,g)&&(Mv(e,g)&&Mv(g,e)&&DKe(e,g)&&(YI(e.prev,e,g.prev)||YI(e,g.prev,g))||zH(e,g)&&YI(e.prev,e,e.next)>0&&YI(g.prev,g,g.next)>0)}function YI(e,g,I){return(g.y-e.y)*(I.x-g.x)-(g.x-e.x)*(I.y-g.y)}function zH(e,g){return e.x===g.x&&e.y===g.y}function rhe(e,g,I,i){var n=Lw(YI(e,g,I)),C=Lw(YI(e,g,i)),r=Lw(YI(I,i,e)),o=Lw(YI(I,i,g));return!!(n!==C&&r!==o||n===0&&_w(e,I,g)||C===0&&_w(e,i,g)||r===0&&_w(I,e,i)||o===0&&_w(I,g,i))}function _w(e,g,I){return g.x<=Math.max(e.x,I.x)&&g.x>=Math.min(e.x,I.x)&&g.y<=Math.max(e.y,I.y)&&g.y>=Math.min(e.y,I.y)}function Lw(e){return e>0?1:e<0?-1:0}function KKe(e,g){var I=e;do{if(I.i!==e.i&&I.next.i!==e.i&&I.i!==g.i&&I.next.i!==g.i&&rhe(I,I.next,e,g))return!0;I=I.next}while(I!==e);return!1}function Mv(e,g){return YI(e.prev,e,e.next)<0?YI(e,g,e.next)>=0&&YI(e,e.prev,g)>=0:YI(e,g,e.prev)<0||YI(e,e.next,g)<0}function DKe(e,g){var I=e,i=!1,n=(e.x+g.x)/2,C=(e.y+g.y)/2;do I.y>C!=I.next.y>C&&I.next.y!==I.y&&n<(I.next.x-I.x)*(C-I.y)/(I.next.y-I.y)+I.x&&(i=!i),I=I.next;while(I!==e);return i}function ohe(e,g){var I=new cE(e.i,e.x,e.y),i=new cE(g.i,g.x,g.y),n=e.next,C=g.prev;return e.next=g,g.prev=e,I.next=n,n.prev=I,i.next=I,I.prev=i,C.next=i,i.prev=C,i}function k6(e,g,I,i){var n=new cE(e,g,I);return i?(n.next=i.next,n.prev=i,i.next.prev=n,i.next=n):(n.prev=n,n.next=n),n}function zv(e){e.next.prev=e.prev,e.prev.next=e.next,e.prevZ&&(e.prevZ.nextZ=e.nextZ),e.nextZ&&(e.nextZ.prevZ=e.prevZ)}function cE(e,g,I){this.i=e,this.x=g,this.y=I,this.prev=null,this.next=null,this.z=0,this.prevZ=null,this.nextZ=null,this.steiner=!1}MH.deviation=function(e,g,I,i){var n=g&&g.length,C=n?g[0]*I:e.length,r=Math.abs(uE(e,0,C,I));if(n)for(var o=0,A=g.length;o0&&(i+=e[n-1].length,I.holes.push(i))}return I};var xKe=__.exports;const L_=Fc(xKe);var LW={exports:{}};/*! https://mths.be/punycode v1.4.1 by @mathias */LW.exports;(function(e,g){(function(I){var i=g&&!g.nodeType&&g,n=e&&!e.nodeType&&e,C=typeof bI=="object"&&bI;(C.global===C||C.window===C||C.self===C)&&(I=C);var r,o=2147483647,A=36,s=1,a=26,l=38,c=700,u=72,d=128,h="-",m=/^xn--/,f=/[^\x20-\x7E]/,b=/[\x2E\u3002\uFF0E\uFF61]/g,p={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},y=A-s,Z=Math.floor,B=String.fromCharCode,G;function v(J){throw new RangeError(p[J])}function w(J,ee){for(var q=J.length,$=[];q--;)$[q]=ee(J[q]);return $}function V(J,ee){var q=J.split("@"),$="";q.length>1&&($=q[0]+"@",J=q[1]),J=J.replace(b,".");var j=J.split("."),te=w(j,ee).join(".");return $+te}function S(J){for(var ee=[],q=0,$=J.length,j,te;q<$;)j=J.charCodeAt(q++),j>=55296&&j<=56319&&q<$?(te=J.charCodeAt(q++),(te&64512)==56320?ee.push(((j&1023)<<10)+(te&1023)+65536):(ee.push(j),q--)):ee.push(j);return ee}function X(J){return w(J,function(ee){var q="";return ee>65535&&(ee-=65536,q+=B(ee>>>10&1023|55296),ee=56320|ee&1023),q+=B(ee),q}).join("")}function W(J){return J-48<10?J-22:J-65<26?J-65:J-97<26?J-97:A}function R(J,ee){return J+22+75*(J<26)-((ee!=0)<<5)}function H(J,ee,q){var $=0;for(J=q?Z(J/c):J>>1,J+=Z(J/ee);J>y*a>>1;$+=A)J=Z(J/y);return Z($+(y+1)*J/(J+l))}function Y(J){var ee=[],q=J.length,$,j=0,te=d,U=u,ie,me,Ce,Ze,Ge,Be,Ne,Se,Pe;for(ie=J.lastIndexOf(h),ie<0&&(ie=0),me=0;me=128&&v("not-basic"),ee.push(J.charCodeAt(me));for(Ce=ie>0?ie+1:0;Ce=q&&v("invalid-input"),Ne=W(J.charCodeAt(Ce++)),(Ne>=A||Ne>Z((o-j)/Ge))&&v("overflow"),j+=Ne*Ge,Se=Be<=U?s:Be>=U+a?a:Be-U,!(NeZ(o/Pe)&&v("overflow"),Ge*=Pe;$=ee.length+1,U=H(j-Ze,$,Ze==0),Z(j/$)>o-te&&v("overflow"),te+=Z(j/$),j%=$,ee.splice(j++,0,te)}return X(ee)}function D(J){var ee,q,$,j,te,U,ie,me,Ce,Ze,Ge,Be=[],Ne,Se,Pe,ze;for(J=S(J),Ne=J.length,ee=d,q=0,te=u,U=0;U=ee&&GeZ((o-q)/Se)&&v("overflow"),q+=(ie-ee)*Se,ee=ie,U=0;Uo&&v("overflow"),Ge==ee){for(me=q,Ce=A;Ze=Ce<=te?s:Ce>=te+a?a:Ce-te,!(me"u"||!Di?dg:Di(Uint8Array),dd={"%AggregateError%":typeof AggregateError>"u"?dg:AggregateError,"%Array%":Array,"%ArrayBuffer%":typeof ArrayBuffer>"u"?dg:ArrayBuffer,"%ArrayIteratorPrototype%":bm&&Di?Di([][Symbol.iterator]()):dg,"%AsyncFromSyncIteratorPrototype%":dg,"%AsyncFunction%":rf,"%AsyncGenerator%":rf,"%AsyncGeneratorFunction%":rf,"%AsyncIteratorPrototype%":rf,"%Atomics%":typeof Atomics>"u"?dg:Atomics,"%BigInt%":typeof BigInt>"u"?dg:BigInt,"%BigInt64Array%":typeof BigInt64Array>"u"?dg:BigInt64Array,"%BigUint64Array%":typeof BigUint64Array>"u"?dg:BigUint64Array,"%Boolean%":Boolean,"%DataView%":typeof DataView>"u"?dg:DataView,"%Date%":Date,"%decodeURI%":decodeURI,"%decodeURIComponent%":decodeURIComponent,"%encodeURI%":encodeURI,"%encodeURIComponent%":encodeURIComponent,"%Error%":Error,"%eval%":eval,"%EvalError%":EvalError,"%Float32Array%":typeof Float32Array>"u"?dg:Float32Array,"%Float64Array%":typeof Float64Array>"u"?dg:Float64Array,"%FinalizationRegistry%":typeof FinalizationRegistry>"u"?dg:FinalizationRegistry,"%Function%":Ahe,"%GeneratorFunction%":rf,"%Int8Array%":typeof Int8Array>"u"?dg:Int8Array,"%Int16Array%":typeof Int16Array>"u"?dg:Int16Array,"%Int32Array%":typeof Int32Array>"u"?dg:Int32Array,"%isFinite%":isFinite,"%isNaN%":isNaN,"%IteratorPrototype%":bm&&Di?Di(Di([][Symbol.iterator]())):dg,"%JSON%":typeof JSON=="object"?JSON:dg,"%Map%":typeof Map>"u"?dg:Map,"%MapIteratorPrototype%":typeof Map>"u"||!bm||!Di?dg:Di(new Map()[Symbol.iterator]()),"%Math%":Math,"%Number%":Number,"%Object%":Object,"%parseFloat%":parseFloat,"%parseInt%":parseInt,"%Promise%":typeof Promise>"u"?dg:Promise,"%Proxy%":typeof Proxy>"u"?dg:Proxy,"%RangeError%":RangeError,"%ReferenceError%":ReferenceError,"%Reflect%":typeof Reflect>"u"?dg:Reflect,"%RegExp%":RegExp,"%Set%":typeof Set>"u"?dg:Set,"%SetIteratorPrototype%":typeof Set>"u"||!bm||!Di?dg:Di(new Set()[Symbol.iterator]()),"%SharedArrayBuffer%":typeof SharedArrayBuffer>"u"?dg:SharedArrayBuffer,"%String%":String,"%StringIteratorPrototype%":bm&&Di?Di(""[Symbol.iterator]()):dg,"%Symbol%":bm?Symbol:dg,"%SyntaxError%":qp,"%ThrowTypeError%":i5e,"%TypedArray%":C5e,"%TypeError%":lp,"%Uint8Array%":typeof Uint8Array>"u"?dg:Uint8Array,"%Uint8ClampedArray%":typeof Uint8ClampedArray>"u"?dg:Uint8ClampedArray,"%Uint16Array%":typeof Uint16Array>"u"?dg:Uint16Array,"%Uint32Array%":typeof Uint32Array>"u"?dg:Uint32Array,"%URIError%":URIError,"%WeakMap%":typeof WeakMap>"u"?dg:WeakMap,"%WeakRef%":typeof WeakRef>"u"?dg:WeakRef,"%WeakSet%":typeof WeakSet>"u"?dg:WeakSet};if(Di)try{null.error}catch(e){var r5e=Di(Di(e));dd["%Error.prototype%"]=r5e}var o5e=function e(g){var I;if(g==="%AsyncFunction%")I=EY("async function () {}");else if(g==="%GeneratorFunction%")I=EY("function* () {}");else if(g==="%AsyncGeneratorFunction%")I=EY("async function* () {}");else if(g==="%AsyncGenerator%"){var i=e("%AsyncGeneratorFunction%");i&&(I=i.prototype)}else if(g==="%AsyncIteratorPrototype%"){var n=e("%AsyncGenerator%");n&&Di&&(I=Di(n.prototype))}return dd[g]=I,I},x6={"%ArrayBufferPrototype%":["ArrayBuffer","prototype"],"%ArrayPrototype%":["Array","prototype"],"%ArrayProto_entries%":["Array","prototype","entries"],"%ArrayProto_forEach%":["Array","prototype","forEach"],"%ArrayProto_keys%":["Array","prototype","keys"],"%ArrayProto_values%":["Array","prototype","values"],"%AsyncFunctionPrototype%":["AsyncFunction","prototype"],"%AsyncGenerator%":["AsyncGeneratorFunction","prototype"],"%AsyncGeneratorPrototype%":["AsyncGeneratorFunction","prototype","prototype"],"%BooleanPrototype%":["Boolean","prototype"],"%DataViewPrototype%":["DataView","prototype"],"%DatePrototype%":["Date","prototype"],"%ErrorPrototype%":["Error","prototype"],"%EvalErrorPrototype%":["EvalError","prototype"],"%Float32ArrayPrototype%":["Float32Array","prototype"],"%Float64ArrayPrototype%":["Float64Array","prototype"],"%FunctionPrototype%":["Function","prototype"],"%Generator%":["GeneratorFunction","prototype"],"%GeneratorPrototype%":["GeneratorFunction","prototype","prototype"],"%Int8ArrayPrototype%":["Int8Array","prototype"],"%Int16ArrayPrototype%":["Int16Array","prototype"],"%Int32ArrayPrototype%":["Int32Array","prototype"],"%JSONParse%":["JSON","parse"],"%JSONStringify%":["JSON","stringify"],"%MapPrototype%":["Map","prototype"],"%NumberPrototype%":["Number","prototype"],"%ObjectPrototype%":["Object","prototype"],"%ObjProto_toString%":["Object","prototype","toString"],"%ObjProto_valueOf%":["Object","prototype","valueOf"],"%PromisePrototype%":["Promise","prototype"],"%PromiseProto_then%":["Promise","prototype","then"],"%Promise_all%":["Promise","all"],"%Promise_reject%":["Promise","reject"],"%Promise_resolve%":["Promise","resolve"],"%RangeErrorPrototype%":["RangeError","prototype"],"%ReferenceErrorPrototype%":["ReferenceError","prototype"],"%RegExpPrototype%":["RegExp","prototype"],"%SetPrototype%":["Set","prototype"],"%SharedArrayBufferPrototype%":["SharedArrayBuffer","prototype"],"%StringPrototype%":["String","prototype"],"%SymbolPrototype%":["Symbol","prototype"],"%SyntaxErrorPrototype%":["SyntaxError","prototype"],"%TypedArrayPrototype%":["TypedArray","prototype"],"%TypeErrorPrototype%":["TypeError","prototype"],"%Uint8ArrayPrototype%":["Uint8Array","prototype"],"%Uint8ClampedArrayPrototype%":["Uint8ClampedArray","prototype"],"%Uint16ArrayPrototype%":["Uint16Array","prototype"],"%Uint32ArrayPrototype%":["Uint32Array","prototype"],"%URIErrorPrototype%":["URIError","prototype"],"%WeakMapPrototype%":["WeakMap","prototype"],"%WeakSetPrototype%":["WeakSet","prototype"]},CS=U_,UW=I5e,A5e=CS.call(Function.call,Array.prototype.concat),a5e=CS.call(Function.apply,Array.prototype.splice),F6=CS.call(Function.call,String.prototype.replace),QW=CS.call(Function.call,String.prototype.slice),s5e=CS.call(Function.call,RegExp.prototype.exec),l5e=/[^%.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|%$))/g,c5e=/\\(\\)?/g,u5e=function(g){var I=QW(g,0,1),i=QW(g,-1);if(I==="%"&&i!=="%")throw new qp("invalid intrinsic syntax, expected closing `%`");if(i==="%"&&I!=="%")throw new qp("invalid intrinsic syntax, expected opening `%`");var n=[];return F6(g,l5e,function(C,r,o,A){n[n.length]=o?F6(A,c5e,"$1"):r||C}),n},d5e=function(g,I){var i=g,n;if(UW(x6,i)&&(n=x6[i],i="%"+n[0]+"%"),UW(dd,i)){var C=dd[i];if(C===rf&&(C=o5e(i)),typeof C>"u"&&!I)throw new lp("intrinsic "+g+" exists, but is not available. Please file an issue!");return{alias:n,name:i,value:C}}throw new qp("intrinsic "+g+" does not exist!")},Kh=function(g,I){if(typeof g!="string"||g.length===0)throw new lp("intrinsic name must be a non-empty string");if(arguments.length>1&&typeof I!="boolean")throw new lp('"allowMissing" argument must be a boolean');if(s5e(/^%?[^%]*%?$/,g)===null)throw new qp("`%` may not be present anywhere but at the beginning and end of the intrinsic name");var i=u5e(g),n=i.length>0?i[0]:"",C=d5e("%"+n+"%",I),r=C.name,o=C.value,A=!1,s=C.alias;s&&(n=s[0],a5e(i,A5e([0,1],s)));for(var a=1,l=!0;a=i.length){var h=ud(o,c);l=!!h,l&&"get"in h&&!("originalValue"in h.get)?o=h.get:o=o[c]}else l=UW(o,c),o=o[c];l&&!A&&(dd[r]=o)}}return o},ahe={exports:{}},h5e=Kh,dE=h5e("%Object.defineProperty%",!0),hE=function(){if(dE)try{return dE({},"a",{value:1}),!0}catch{return!1}return!1};hE.hasArrayLengthDefineBug=function(){if(!hE())return null;try{return dE([],"length",{value:1}).length!==1}catch{return!0}};var she=hE,m5e=Kh,I1=m5e("%Object.getOwnPropertyDescriptor%",!0);if(I1)try{I1([],"length")}catch{I1=null}var lhe=I1,f5e=she(),Q_=Kh,pG=f5e&&Q_("%Object.defineProperty%",!0);if(pG)try{pG({},"a",{value:1})}catch{pG=!1}var p5e=Q_("%SyntaxError%"),ym=Q_("%TypeError%"),E6=lhe,b5e=function(g,I,i){if(!g||typeof g!="object"&&typeof g!="function")throw new ym("`obj` must be an object or a function`");if(typeof I!="string"&&typeof I!="symbol")throw new ym("`property` must be a string or a symbol`");if(arguments.length>3&&typeof arguments[3]!="boolean"&&arguments[3]!==null)throw new ym("`nonEnumerable`, if provided, must be a boolean or null");if(arguments.length>4&&typeof arguments[4]!="boolean"&&arguments[4]!==null)throw new ym("`nonWritable`, if provided, must be a boolean or null");if(arguments.length>5&&typeof arguments[5]!="boolean"&&arguments[5]!==null)throw new ym("`nonConfigurable`, if provided, must be a boolean or null");if(arguments.length>6&&typeof arguments[6]!="boolean")throw new ym("`loose`, if provided, must be a boolean");var n=arguments.length>3?arguments[3]:null,C=arguments.length>4?arguments[4]:null,r=arguments.length>5?arguments[5]:null,o=arguments.length>6?arguments[6]:!1,A=!!E6&&E6(g,I);if(pG)pG(g,I,{configurable:r===null&&A?A.configurable:!r,enumerable:n===null&&A?A.enumerable:!n,value:i,writable:C===null&&A?A.writable:!C});else if(o||!n&&!C&&!r)g[I]=i;else throw new p5e("This environment does not support defining a property as non-configurable, non-writable, or non-enumerable.")},che=Kh,M6=b5e,y5e=she(),z6=lhe,P6=che("%TypeError%"),Z5e=che("%Math.floor%"),G5e=function(g,I){if(typeof g!="function")throw new P6("`fn` is not a function");if(typeof I!="number"||I<0||I>4294967295||Z5e(I)!==I)throw new P6("`length` must be a positive 32-bit integer");var i=arguments.length>2&&!!arguments[2],n=!0,C=!0;if("length"in g&&z6){var r=z6(g,"length");r&&!r.configurable&&(n=!1),r&&!r.writable&&(C=!1)}return(n||C||!i)&&(y5e?M6(g,"length",I,!0,!0):M6(g,"length",I)),g};(function(e){var g=U_,I=Kh,i=G5e,n=I("%TypeError%"),C=I("%Function.prototype.apply%"),r=I("%Function.prototype.call%"),o=I("%Reflect.apply%",!0)||g.call(r,C),A=I("%Object.defineProperty%",!0),s=I("%Math.max%");if(A)try{A({},"a",{value:1})}catch{A=null}e.exports=function(c){if(typeof c!="function")throw new n("a function is required");var u=o(g,r,arguments);return i(u,1+s(0,c.length-(arguments.length-1)),!0)};var a=function(){return o(g,C,arguments)};A?A(e.exports,"apply",{value:a}):e.exports.apply=a})(ahe);var v5e=ahe.exports,uhe=Kh,dhe=v5e,B5e=dhe(uhe("String.prototype.indexOf")),S5e=function(g,I){var i=uhe(g,!!I);return typeof i=="function"&&B5e(g,".prototype.")>-1?dhe(i):i};const hhe={},w5e=Object.freeze(Object.defineProperty({__proto__:null,default:hhe},Symbol.toStringTag,{value:"Module"})),V5e=$O(w5e);var j_=typeof Map=="function"&&Map.prototype,zY=Object.getOwnPropertyDescriptor&&j_?Object.getOwnPropertyDescriptor(Map.prototype,"size"):null,jW=j_&&zY&&typeof zY.get=="function"?zY.get:null,J6=j_&&Map.prototype.forEach,$_=typeof Set=="function"&&Set.prototype,PY=Object.getOwnPropertyDescriptor&&$_?Object.getOwnPropertyDescriptor(Set.prototype,"size"):null,$W=$_&&PY&&typeof PY.get=="function"?PY.get:null,O6=$_&&Set.prototype.forEach,R5e=typeof WeakMap=="function"&&WeakMap.prototype,bG=R5e?WeakMap.prototype.has:null,W5e=typeof WeakSet=="function"&&WeakSet.prototype,yG=W5e?WeakSet.prototype.has:null,X5e=typeof WeakRef=="function"&&WeakRef.prototype,_6=X5e?WeakRef.prototype.deref:null,H5e=Boolean.prototype.valueOf,T5e=Object.prototype.toString,N5e=Function.prototype.toString,k5e=String.prototype.match,q_=String.prototype.slice,gc=String.prototype.replace,Y5e=String.prototype.toUpperCase,L6=String.prototype.toLowerCase,mhe=RegExp.prototype.test,U6=Array.prototype.concat,XA=Array.prototype.join,K5e=Array.prototype.slice,Q6=Math.floor,mE=typeof BigInt=="function"?BigInt.prototype.valueOf:null,JY=Object.getOwnPropertySymbols,fE=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Symbol.prototype.toString:null,eb=typeof Symbol=="function"&&typeof Symbol.iterator=="object",Hn=typeof Symbol=="function"&&Symbol.toStringTag&&(typeof Symbol.toStringTag===eb||"symbol")?Symbol.toStringTag:null,fhe=Object.prototype.propertyIsEnumerable,j6=(typeof Reflect=="function"?Reflect.getPrototypeOf:Object.getPrototypeOf)||([].__proto__===Array.prototype?function(e){return e.__proto__}:null);function $6(e,g){if(e===1/0||e===-1/0||e!==e||e&&e>-1e3&&e<1e3||mhe.call(/e/,g))return g;var I=/[0-9](?=(?:[0-9]{3})+(?![0-9]))/g;if(typeof e=="number"){var i=e<0?-Q6(-e):Q6(e);if(i!==e){var n=String(i),C=q_.call(g,n.length+1);return gc.call(n,I,"$&_")+"."+gc.call(gc.call(C,/([0-9]{3})/g,"$&_"),/_$/,"")}}return gc.call(g,I,"$&_")}var pE=V5e,q6=pE.custom,eq=bhe(q6)?q6:null,D5e=function e(g,I,i,n){var C=I||{};if(kl(C,"quoteStyle")&&C.quoteStyle!=="single"&&C.quoteStyle!=="double")throw new TypeError('option "quoteStyle" must be "single" or "double"');if(kl(C,"maxStringLength")&&(typeof C.maxStringLength=="number"?C.maxStringLength<0&&C.maxStringLength!==1/0:C.maxStringLength!==null))throw new TypeError('option "maxStringLength", if provided, must be a positive integer, Infinity, or `null`');var r=kl(C,"customInspect")?C.customInspect:!0;if(typeof r!="boolean"&&r!=="symbol")throw new TypeError("option \"customInspect\", if provided, must be `true`, `false`, or `'symbol'`");if(kl(C,"indent")&&C.indent!==null&&C.indent!==" "&&!(parseInt(C.indent,10)===C.indent&&C.indent>0))throw new TypeError('option "indent" must be "\\t", an integer > 0, or `null`');if(kl(C,"numericSeparator")&&typeof C.numericSeparator!="boolean")throw new TypeError('option "numericSeparator", if provided, must be `true` or `false`');var o=C.numericSeparator;if(typeof g>"u")return"undefined";if(g===null)return"null";if(typeof g=="boolean")return g?"true":"false";if(typeof g=="string")return Zhe(g,C);if(typeof g=="number"){if(g===0)return 1/0/g>0?"0":"-0";var A=String(g);return o?$6(g,A):A}if(typeof g=="bigint"){var s=String(g)+"n";return o?$6(g,s):s}var a=typeof C.depth>"u"?5:C.depth;if(typeof i>"u"&&(i=0),i>=a&&a>0&&typeof g=="object")return bE(g)?"[Array]":"[Object]";var l=gDe(C,i);if(typeof n>"u")n=[];else if(yhe(n,g)>=0)return"[Circular]";function c(W,R,H){if(R&&(n=K5e.call(n),n.push(R)),H){var Y={depth:C.depth};return kl(C,"quoteStyle")&&(Y.quoteStyle=C.quoteStyle),e(W,Y,i+1,n)}return e(W,C,i+1,n)}if(typeof g=="function"&&!tq(g)){var u=_5e(g),d=Uw(g,c);return"[Function"+(u?": "+u:" (anonymous)")+"]"+(d.length>0?" { "+XA.call(d,", ")+" }":"")}if(bhe(g)){var h=eb?gc.call(String(g),/^(Symbol\(.*\))_[^)]*$/,"$1"):fE.call(g);return typeof g=="object"&&!eb?hy(h):h}if(q5e(g)){for(var m="<"+L6.call(String(g.nodeName)),f=g.attributes||[],b=0;b",m}if(bE(g)){if(g.length===0)return"[]";var p=Uw(g,c);return l&&!tDe(p)?"["+yE(p,l)+"]":"[ "+XA.call(p,", ")+" ]"}if(E5e(g)){var y=Uw(g,c);return!("cause"in Error.prototype)&&"cause"in g&&!fhe.call(g,"cause")?"{ ["+String(g)+"] "+XA.call(U6.call("[cause]: "+c(g.cause),y),", ")+" }":y.length===0?"["+String(g)+"]":"{ ["+String(g)+"] "+XA.call(y,", ")+" }"}if(typeof g=="object"&&r){if(eq&&typeof g[eq]=="function"&&pE)return pE(g,{depth:a-i});if(r!=="symbol"&&typeof g.inspect=="function")return g.inspect()}if(L5e(g)){var Z=[];return J6&&J6.call(g,function(W,R){Z.push(c(R,g,!0)+" => "+c(W,g))}),gq("Map",jW.call(g),Z,l)}if(j5e(g)){var B=[];return O6&&O6.call(g,function(W){B.push(c(W,g))}),gq("Set",$W.call(g),B,l)}if(U5e(g))return OY("WeakMap");if($5e(g))return OY("WeakSet");if(Q5e(g))return OY("WeakRef");if(z5e(g))return hy(c(Number(g)));if(J5e(g))return hy(c(mE.call(g)));if(P5e(g))return hy(H5e.call(g));if(M5e(g))return hy(c(String(g)));if(typeof window<"u"&&g===window)return"{ [object Window] }";if(g===bI)return"{ [object globalThis] }";if(!F5e(g)&&!tq(g)){var G=Uw(g,c),v=j6?j6(g)===Object.prototype:g instanceof Object||g.constructor===Object,w=g instanceof Object?"":"null prototype",V=!v&&Hn&&Object(g)===g&&Hn in g?q_.call(Pc(g),8,-1):w?"Object":"",S=v||typeof g.constructor!="function"?"":g.constructor.name?g.constructor.name+" ":"",X=S+(V||w?"["+XA.call(U6.call([],V||[],w||[]),": ")+"] ":"");return G.length===0?X+"{}":l?X+"{"+yE(G,l)+"}":X+"{ "+XA.call(G,", ")+" }"}return String(g)};function phe(e,g,I){var i=(I.quoteStyle||g)==="double"?'"':"'";return i+e+i}function x5e(e){return gc.call(String(e),/"/g,""")}function bE(e){return Pc(e)==="[object Array]"&&(!Hn||!(typeof e=="object"&&Hn in e))}function F5e(e){return Pc(e)==="[object Date]"&&(!Hn||!(typeof e=="object"&&Hn in e))}function tq(e){return Pc(e)==="[object RegExp]"&&(!Hn||!(typeof e=="object"&&Hn in e))}function E5e(e){return Pc(e)==="[object Error]"&&(!Hn||!(typeof e=="object"&&Hn in e))}function M5e(e){return Pc(e)==="[object String]"&&(!Hn||!(typeof e=="object"&&Hn in e))}function z5e(e){return Pc(e)==="[object Number]"&&(!Hn||!(typeof e=="object"&&Hn in e))}function P5e(e){return Pc(e)==="[object Boolean]"&&(!Hn||!(typeof e=="object"&&Hn in e))}function bhe(e){if(eb)return e&&typeof e=="object"&&e instanceof Symbol;if(typeof e=="symbol")return!0;if(!e||typeof e!="object"||!fE)return!1;try{return fE.call(e),!0}catch{}return!1}function J5e(e){if(!e||typeof e!="object"||!mE)return!1;try{return mE.call(e),!0}catch{}return!1}var O5e=Object.prototype.hasOwnProperty||function(e){return e in this};function kl(e,g){return O5e.call(e,g)}function Pc(e){return T5e.call(e)}function _5e(e){if(e.name)return e.name;var g=k5e.call(N5e.call(e),/^function\s*([\w$]+)/);return g?g[1]:null}function yhe(e,g){if(e.indexOf)return e.indexOf(g);for(var I=0,i=e.length;Ig.maxStringLength){var I=e.length-g.maxStringLength,i="... "+I+" more character"+(I>1?"s":"");return Zhe(q_.call(e,0,g.maxStringLength),g)+i}var n=gc.call(gc.call(e,/(['\\])/g,"\\$1"),/[\x00-\x1f]/g,eDe);return phe(n,"single",g)}function eDe(e){var g=e.charCodeAt(0),I={8:"b",9:"t",10:"n",12:"f",13:"r"}[g];return I?"\\"+I:"\\x"+(g<16?"0":"")+Y5e.call(g.toString(16))}function hy(e){return"Object("+e+")"}function OY(e){return e+" { ? }"}function gq(e,g,I,i){var n=i?yE(I,i):XA.call(I,", ");return e+" ("+g+") {"+n+"}"}function tDe(e){for(var g=0;g=0)return!1;return!0}function gDe(e,g){var I;if(e.indent===" ")I=" ";else if(typeof e.indent=="number"&&e.indent>0)I=XA.call(Array(e.indent+1)," ");else return null;return{base:I,prev:XA.call(Array(g+1),I)}}function yE(e,g){if(e.length===0)return"";var I=` +`+g.prev+g.base;return I+XA.call(e,","+I)+` +`+g.prev}function Uw(e,g){var I=bE(e),i=[];if(I){i.length=e.length;for(var n=0;n1;){var I=g.pop(),i=I.obj[I.prop];if(Ju(i)){for(var n=[],C=0;C=48&&s<=57||s>=65&&s<=90||s>=97&&s<=122||C===mDe.RFC1738&&(s===40||s===41)){o+=r.charAt(A);continue}if(s<128){o=o+bA[s];continue}if(s<2048){o=o+(bA[192|s>>6]+bA[128|s&63]);continue}if(s<55296||s>=57344){o=o+(bA[224|s>>12]+bA[128|s>>6&63]+bA[128|s&63]);continue}A+=1,s=65536+((s&1023)<<10|r.charCodeAt(A)&1023),o+=bA[240|s>>18]+bA[128|s>>12&63]+bA[128|s>>6&63]+bA[128|s&63]}return o},GDe=function(g){for(var I=[{obj:{o:g},prop:"o"}],i=[],n=0;n"u"&&(p=0)}if(typeof A=="function"?f=A(I,f):f instanceof Date?f=l(f):i==="comma"&&Ua(f)&&(f=i1.maybeMap(f,function(Y){return Y instanceof Date?l(Y):Y})),f===null){if(C)return o&&!d?o(I,Vn.encoder,h,"key",c):I;f=""}if(XDe(f)||i1.isBuffer(f)){if(o){var B=d?I:o(I,Vn.encoder,h,"key",c);return[u(B)+"="+u(o(f,Vn.encoder,h,"value",c))]}return[u(I)+"="+u(String(f))]}var G=[];if(typeof f>"u")return G;var v;if(i==="comma"&&Ua(f))d&&o&&(f=i1.maybeMap(f,o)),v=[{value:f.length>0?f.join(",")||null:void 0}];else if(Ua(A))v=A;else{var w=Object.keys(f);v=s?w.sort(s):w}for(var V=n&&Ua(f)&&f.length===1?I+"[]":I,S=0;S"u"?Vn.allowDots:!!g.allowDots,charset:I,charsetSentinel:typeof g.charsetSentinel=="boolean"?g.charsetSentinel:Vn.charsetSentinel,delimiter:typeof g.delimiter>"u"?Vn.delimiter:g.delimiter,encode:typeof g.encode=="boolean"?g.encode:Vn.encode,encoder:typeof g.encoder=="function"?g.encoder:Vn.encoder,encodeValuesOnly:typeof g.encodeValuesOnly=="boolean"?g.encodeValuesOnly:Vn.encodeValuesOnly,filter:C,format:i,formatter:n,serializeDate:typeof g.serializeDate=="function"?g.serializeDate:Vn.serializeDate,skipNulls:typeof g.skipNulls=="boolean"?g.skipNulls:Vn.skipNulls,sort:typeof g.sort=="function"?g.sort:null,strictNullHandling:typeof g.strictNullHandling=="boolean"?g.strictNullHandling:Vn.strictNullHandling}},NDe=function(e,g){var I=e,i=TDe(g),n,C;typeof i.filter=="function"?(C=i.filter,I=C("",I)):Ua(i.filter)&&(C=i.filter,n=C);var r=[];if(typeof I!="object"||I===null)return"";var o;g&&g.arrayFormat in Iq?o=g.arrayFormat:g&&"indices"in g?o=g.indices?"indices":"repeat":o="indices";var A=Iq[o];if(g&&"commaRoundTrip"in g&&typeof g.commaRoundTrip!="boolean")throw new TypeError("`commaRoundTrip` must be a boolean, or absent");var s=A==="comma"&&g&&g.commaRoundTrip;n||(n=Object.keys(I)),i.sort&&n.sort(i.sort);for(var a=Bhe(),l=0;l0?d+u:""},tb=vhe,ZE=Object.prototype.hasOwnProperty,kDe=Array.isArray,Ki={allowDots:!1,allowPrototypes:!1,allowSparse:!1,arrayLimit:20,charset:"utf-8",charsetSentinel:!1,comma:!1,decoder:tb.decode,delimiter:"&",depth:5,ignoreQueryPrefix:!1,interpretNumericEntities:!1,parameterLimit:1e3,parseArrays:!0,plainObjects:!1,strictNullHandling:!1},YDe=function(e){return e.replace(/&#(\d+);/g,function(g,I){return String.fromCharCode(parseInt(I,10))})},whe=function(e,g){return e&&typeof e=="string"&&g.comma&&e.indexOf(",")>-1?e.split(","):e},KDe="utf8=%26%2310003%3B",DDe="utf8=%E2%9C%93",xDe=function(g,I){var i={__proto__:null},n=I.ignoreQueryPrefix?g.replace(/^\?/,""):g,C=I.parameterLimit===1/0?void 0:I.parameterLimit,r=n.split(I.delimiter,C),o=-1,A,s=I.charset;if(I.charsetSentinel)for(A=0;A-1&&(d=kDe(d)?[d]:d),ZE.call(i,u)?i[u]=tb.combine(i[u],d):i[u]=d}return i},FDe=function(e,g,I,i){for(var n=i?g:whe(g,I),C=e.length-1;C>=0;--C){var r,o=e[C];if(o==="[]"&&I.parseArrays)r=[].concat(n);else{r=I.plainObjects?Object.create(null):{};var A=o.charAt(0)==="["&&o.charAt(o.length-1)==="]"?o.slice(1,-1):o,s=parseInt(A,10);!I.parseArrays&&A===""?r={0:n}:!isNaN(s)&&o!==A&&String(s)===A&&s>=0&&I.parseArrays&&s<=I.arrayLimit?(r=[],r[s]=n):A!=="__proto__"&&(r[A]=n)}n=r}return n},EDe=function(g,I,i,n){if(g){var C=i.allowDots?g.replace(/\.([^.[]+)/g,"[$1]"):g,r=/(\[[^[\]]*])/,o=/(\[[^[\]]*])/g,A=i.depth>0&&r.exec(C),s=A?C.slice(0,A.index):C,a=[];if(s){if(!i.plainObjects&&ZE.call(Object.prototype,s)&&!i.allowPrototypes)return;a.push(s)}for(var l=0;i.depth>0&&(A=o.exec(C))!==null&&l"u"?Ki.charset:g.charset;return{allowDots:typeof g.allowDots>"u"?Ki.allowDots:!!g.allowDots,allowPrototypes:typeof g.allowPrototypes=="boolean"?g.allowPrototypes:Ki.allowPrototypes,allowSparse:typeof g.allowSparse=="boolean"?g.allowSparse:Ki.allowSparse,arrayLimit:typeof g.arrayLimit=="number"?g.arrayLimit:Ki.arrayLimit,charset:I,charsetSentinel:typeof g.charsetSentinel=="boolean"?g.charsetSentinel:Ki.charsetSentinel,comma:typeof g.comma=="boolean"?g.comma:Ki.comma,decoder:typeof g.decoder=="function"?g.decoder:Ki.decoder,delimiter:typeof g.delimiter=="string"||tb.isRegExp(g.delimiter)?g.delimiter:Ki.delimiter,depth:typeof g.depth=="number"||g.depth===!1?+g.depth:Ki.depth,ignoreQueryPrefix:g.ignoreQueryPrefix===!0,interpretNumericEntities:typeof g.interpretNumericEntities=="boolean"?g.interpretNumericEntities:Ki.interpretNumericEntities,parameterLimit:typeof g.parameterLimit=="number"?g.parameterLimit:Ki.parameterLimit,parseArrays:g.parseArrays!==!1,plainObjects:typeof g.plainObjects=="boolean"?g.plainObjects:Ki.plainObjects,strictNullHandling:typeof g.strictNullHandling=="boolean"?g.strictNullHandling:Ki.strictNullHandling}},zDe=function(e,g){var I=MDe(g);if(e===""||e===null||typeof e>"u")return I.plainObjects?Object.create(null):{};for(var i=typeof e=="string"?xDe(e,I):e,n=I.plainObjects?Object.create(null):{},C=Object.keys(i),r=0;r",'"',"`"," ","\r",` +`," "],qDe=["{","}","|","\\","^","`"].concat($De),GE=["'"].concat(qDe),nq=["%","/","?",";","#"].concat(GE),Cq=["/","?","#"],exe=255,rq=/^[+a-z0-9A-Z_-]{0,63}$/,txe=/^([+a-z0-9A-Z_-]{0,63})(.*)$/,gxe={javascript:!0,"javascript:":!0},vE={javascript:!0,"javascript:":!0},cp={http:!0,https:!0,ftp:!0,gopher:!0,file:!0,"http:":!0,"https:":!0,"ftp:":!0,"gopher:":!0,"file:":!0},BE=_De;function PH(e,g,I){if(e&&typeof e=="object"&&e instanceof eA)return e;var i=new eA;return i.parse(e,g,I),i}eA.prototype.parse=function(e,g,I){if(typeof e!="string")throw new TypeError("Parameter 'url' must be a string, not "+typeof e);var i=e.indexOf("?"),n=i!==-1&&i127?Z+="x":Z+=y[B];if(!Z.match(rq)){var v=b.slice(0,u),w=b.slice(u+1),V=y.match(txe);V&&(v.push(V[1]),w.unshift(V[2])),w.length&&(o="/"+w.join(".")+o),this.hostname=v.join(".");break}}}this.hostname.length>exe?this.hostname="":this.hostname=this.hostname.toLowerCase(),f||(this.hostname=LDe.toASCII(this.hostname));var S=this.port?":"+this.port:"",X=this.hostname||"";this.host=X+S,this.href+=this.host,f&&(this.hostname=this.hostname.substr(1,this.hostname.length-2),o[0]!=="/"&&(o="/"+o))}if(!gxe[a])for(var u=0,p=GE.length;u0?I.host.split("@"):!1;Z&&(I.auth=Z.shift(),I.hostname=Z.shift(),I.host=I.hostname)}return I.search=e.search,I.query=e.query,(I.pathname!==null||I.search!==null)&&(I.path=(I.pathname?I.pathname:"")+(I.search?I.search:"")),I.href=I.format(),I}if(!b.length)return I.pathname=null,I.search?I.path="/"+I.search:I.path=null,I.href=I.format(),I;for(var B=b.slice(-1)[0],G=(I.host||e.host||b.length>1)&&(B==="."||B==="..")||B==="",v=0,w=b.length;w>=0;w--)B=b[w],B==="."?b.splice(w,1):B===".."?(b.splice(w,1),v++):v&&(b.splice(w,1),v--);if(!m&&!f)for(;v--;v)b.unshift("..");m&&b[0]!==""&&(!b[0]||b[0].charAt(0)!=="/")&&b.unshift(""),G&&b.join("/").substr(-1)!=="/"&&b.push("");var V=b[0]===""||b[0]&&b[0].charAt(0)==="/";if(y){I.hostname=V?"":b.length?b.shift():"",I.host=I.hostname;var Z=I.host&&I.host.indexOf("@")>0?I.host.split("@"):!1;Z&&(I.auth=Z.shift(),I.hostname=Z.shift(),I.host=I.hostname)}return m=m||I.host&&b.length,m&&!V&&b.unshift(""),b.length>0?I.pathname=b.join("/"):(I.pathname=null,I.path=null),(I.pathname!==null||I.search!==null)&&(I.path=(I.pathname?I.pathname:"")+(I.search?I.search:"")),I.auth=e.auth||I.auth,I.slashes=I.slashes||e.slashes,I.href=I.format(),I};eA.prototype.parseHost=function(){var e=this.host,g=QDe.exec(e);g&&(g=g[0],g!==":"&&(this.port=g.substr(1)),e=e.substr(0,e.length-g.length)),e&&(this.hostname=e)};var nxe=PH,Cxe=ixe,rxe=Ixe;/*! + * @pixi/utils - v6.5.10 + * Compiled Thu, 06 Jul 2023 15:25:11 UTC + * + * @pixi/utils is licensed under the MIT License. + * http://www.opensource.org/licenses/mit-license + */var ju={parse:nxe,format:rxe,resolve:Cxe};function lo(e){if(typeof e!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(e))}function oq(e){var g=e.split("?")[0];return g.split("#")[0]}function oxe(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Axe(e,g,I){return e.replace(new RegExp(oxe(g),"g"),I)}function axe(e,g){for(var I="",i=0,n=-1,C=0,r,o=0;o<=e.length;++o){if(o2){var A=I.lastIndexOf("/");if(A!==I.length-1){A===-1?(I="",i=0):(I=I.slice(0,A),i=I.length-1-I.lastIndexOf("/")),n=o,C=0;continue}}else if(I.length===2||I.length===1){I="",i=0,n=o,C=0;continue}}g&&(I.length>0?I+="/..":I="..",i=2)}else I.length>0?I+="/"+e.slice(n+1,o):I=e.slice(n+1,o),i=o-n-1;n=o,C=0}else r===46&&C!==-1?++C:C=-1}return I}var Vhe={toPosix:function(e){return Axe(e,"\\","/")},isUrl:function(e){return/^https?:/.test(this.toPosix(e))},isDataUrl:function(e){return/^data:([a-z]+\/[a-z0-9-+.]+(;[a-z0-9-.!#$%*+.{}|~`]+=[a-z0-9-.!#$%*+.{}()_|~`]+)*)?(;base64)?,([a-z0-9!$&',()*+;=\-._~:@\/?%\s<>]*?)$/i.test(e)},hasProtocol:function(e){return/^[^/:]+:\//.test(this.toPosix(e))},getProtocol:function(e){lo(e),e=this.toPosix(e);var g="",I=/^file:\/\/\//.exec(e),i=/^[^/:]+:\/\//.exec(e),n=/^[^/:]+:\//.exec(e);if(I||i||n){var C=(I==null?void 0:I[0])||(i==null?void 0:i[0])||(n==null?void 0:n[0]);g=C,e=e.slice(C.length)}return g},toAbsolute:function(e,g,I){if(this.isDataUrl(e))return e;var i=oq(this.toPosix(g??yt.ADAPTER.getBaseUrl())),n=oq(this.toPosix(I??this.rootname(i)));if(lo(e),e=this.toPosix(e),e.startsWith("/"))return Vhe.join(n,e.slice(1));var C=this.isAbsolute(e)?e:this.join(i,e);return C},normalize:function(e){if(e=this.toPosix(e),lo(e),e.length===0)return".";var g="",I=e.startsWith("/");this.hasProtocol(e)&&(g=this.rootname(e),e=e.slice(g.length));var i=e.endsWith("/");return e=axe(e,!1),e.length>0&&i&&(e+="/"),I?"/"+e:g+e},isAbsolute:function(e){return lo(e),e=this.toPosix(e),this.hasProtocol(e)?!0:e.startsWith("/")},join:function(){for(var e=arguments,g,I=[],i=0;i0)if(n===void 0)n=r;else{var o=(g=I[C-1])!==null&&g!==void 0?g:"";this.extname(o)?n+="/../"+r:n+="/"+r}}return n===void 0?".":this.normalize(n)},dirname:function(e){if(lo(e),e.length===0)return".";e=this.toPosix(e);var g=e.charCodeAt(0),I=g===47,i=-1,n=!0,C=this.getProtocol(e),r=e;e=e.slice(C.length);for(var o=e.length-1;o>=1;--o)if(g=e.charCodeAt(o),g===47){if(!n){i=o;break}}else n=!1;return i===-1?I?"/":this.isUrl(r)?C+e:C:I&&i===1?"//":C+e.slice(0,i)},rootname:function(e){lo(e),e=this.toPosix(e);var g="";if(e.startsWith("/")?g="/":g=this.getProtocol(e),this.isUrl(e)){var I=e.indexOf("/",g.length);I!==-1?g=e.slice(0,I):g=e,g.endsWith("/")||(g+="/")}return g},basename:function(e,g){lo(e),g&&lo(g),e=this.toPosix(e);var I=0,i=-1,n=!0,C;if(g!==void 0&&g.length>0&&g.length<=e.length){if(g.length===e.length&&g===e)return"";var r=g.length-1,o=-1;for(C=e.length-1;C>=0;--C){var A=e.charCodeAt(C);if(A===47){if(!n){I=C+1;break}}else o===-1&&(n=!1,o=C+1),r>=0&&(A===g.charCodeAt(r)?--r===-1&&(i=C):(r=-1,i=o))}return I===i?i=o:i===-1&&(i=e.length),e.slice(I,i)}for(C=e.length-1;C>=0;--C)if(e.charCodeAt(C)===47){if(!n){I=C+1;break}}else i===-1&&(n=!1,i=C+1);return i===-1?"":e.slice(I,i)},extname:function(e){lo(e),e=this.toPosix(e);for(var g=-1,I=0,i=-1,n=!0,C=0,r=e.length-1;r>=0;--r){var o=e.charCodeAt(r);if(o===47){if(!n){I=r+1;break}continue}i===-1&&(n=!1,i=r+1),o===46?g===-1?g=r:C!==1&&(C=1):g!==-1&&(C=-1)}return g===-1||i===-1||C===0||C===1&&g===i-1&&g===I+1?"":e.slice(g,i)},parse:function(e){lo(e);var g={root:"",dir:"",base:"",ext:"",name:""};if(e.length===0)return g;e=this.toPosix(e);var I=e.charCodeAt(0),i=this.isAbsolute(e),n;g.root=this.rootname(e),i||this.hasProtocol(e)?n=1:n=0;for(var C=-1,r=0,o=-1,A=!0,s=e.length-1,a=0;s>=n;--s){if(I=e.charCodeAt(s),I===47){if(!A){r=s+1;break}continue}o===-1&&(A=!1,o=s+1),I===46?C===-1?C=s:a!==1&&(a=1):C!==-1&&(a=-1)}return C===-1||o===-1||a===0||a===1&&C===o-1&&C===r+1?o!==-1&&(r===0&&i?g.base=g.name=e.slice(1,o):g.base=g.name=e.slice(r,o)):(r===0&&i?(g.name=e.slice(1,C),g.base=e.slice(1,o)):(g.name=e.slice(r,C),g.base=e.slice(r,o)),g.ext=e.slice(C,o)),g.dir=this.dirname(e),g},sep:"/",delimiter:":"};yt.RETINA_PREFIX=/@([0-9\.]+)x/;yt.FAIL_IF_MAJOR_PERFORMANCE_CAVEAT=!1;var SE=!1,Aq="6.5.10";function sxe(){SE=!0}function Rhe(e){var g;if(!SE){if(yt.ADAPTER.getNavigator().userAgent.toLowerCase().indexOf("chrome")>-1){var I=[` + %c %c %c PixiJS `+Aq+" - ✰ "+e+` ✰ %c %c http://www.pixijs.com/ %c %c ♥%c♥%c♥ -void main(void){ - gl_Position = vec4((projectionMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0); - vTextureCoord = aTextureCoord; -} -`;function $q(g,e,I){const i=g.createShader(e);return g.shaderSource(i,I),g.compileShader(i),i}function QK(g){const e=new Array(g);for(let I=0;Ig.type==="float"&&g.size===1&&!g.isArray,code:g=>` - if(uv["${g}"] !== ud["${g}"].value) +`,"background: #ff66a5; padding:5px 0;","background: #ff66a5; padding:5px 0;","color: #ff66a5; background: #030307; padding:5px 0;","background: #ff66a5; padding:5px 0;","background: #ffc3dc; padding:5px 0;","background: #ff66a5; padding:5px 0;","color: #ff2424; background: #fff; padding:5px 0;","color: #ff2424; background: #fff; padding:5px 0;","color: #ff2424; background: #fff; padding:5px 0;"];(g=globalThis.console).log.apply(g,I)}else globalThis.console&&globalThis.console.log("PixiJS "+Aq+" - "+e+" - http://www.pixijs.com/");SE=!0}}var QY;function Whe(){return typeof QY>"u"&&(QY=function(){var g={stencil:!0,failIfMajorPerformanceCaveat:yt.FAIL_IF_MAJOR_PERFORMANCE_CAVEAT};try{if(!yt.ADAPTER.getWebGLRenderingContext())return!1;var I=yt.ADAPTER.createCanvas(),i=I.getContext("webgl",g)||I.getContext("experimental-webgl",g),n=!!(i&&i.getContextAttributes().stencil);if(i){var C=i.getExtension("WEBGL_lose_context");C&&C.loseContext()}return i=null,n}catch{return!1}}()),QY}var lxe="#f0f8ff",cxe="#faebd7",uxe="#00ffff",dxe="#7fffd4",hxe="#f0ffff",mxe="#f5f5dc",fxe="#ffe4c4",pxe="#000000",bxe="#ffebcd",yxe="#0000ff",Zxe="#8a2be2",Gxe="#a52a2a",vxe="#deb887",Bxe="#5f9ea0",Sxe="#7fff00",wxe="#d2691e",Vxe="#ff7f50",Rxe="#6495ed",Wxe="#fff8dc",Xxe="#dc143c",Hxe="#00ffff",Txe="#00008b",Nxe="#008b8b",kxe="#b8860b",Yxe="#a9a9a9",Kxe="#006400",Dxe="#a9a9a9",xxe="#bdb76b",Fxe="#8b008b",Exe="#556b2f",Mxe="#ff8c00",zxe="#9932cc",Pxe="#8b0000",Jxe="#e9967a",Oxe="#8fbc8f",_xe="#483d8b",Lxe="#2f4f4f",Uxe="#2f4f4f",Qxe="#00ced1",jxe="#9400d3",$xe="#ff1493",qxe="#00bfff",eFe="#696969",tFe="#696969",gFe="#1e90ff",IFe="#b22222",iFe="#fffaf0",nFe="#228b22",CFe="#ff00ff",rFe="#dcdcdc",oFe="#f8f8ff",AFe="#daa520",aFe="#ffd700",sFe="#808080",lFe="#008000",cFe="#adff2f",uFe="#808080",dFe="#f0fff0",hFe="#ff69b4",mFe="#cd5c5c",fFe="#4b0082",pFe="#fffff0",bFe="#f0e68c",yFe="#fff0f5",ZFe="#e6e6fa",GFe="#7cfc00",vFe="#fffacd",BFe="#add8e6",SFe="#f08080",wFe="#e0ffff",VFe="#fafad2",RFe="#d3d3d3",WFe="#90ee90",XFe="#d3d3d3",HFe="#ffb6c1",TFe="#ffa07a",NFe="#20b2aa",kFe="#87cefa",YFe="#778899",KFe="#778899",DFe="#b0c4de",xFe="#ffffe0",FFe="#00ff00",EFe="#32cd32",MFe="#faf0e6",zFe="#ff00ff",PFe="#800000",JFe="#66cdaa",OFe="#0000cd",_Fe="#ba55d3",LFe="#9370db",UFe="#3cb371",QFe="#7b68ee",jFe="#00fa9a",$Fe="#48d1cc",qFe="#c71585",eEe="#191970",tEe="#f5fffa",gEe="#ffe4e1",IEe="#ffe4b5",iEe="#ffdead",nEe="#000080",CEe="#fdf5e6",rEe="#808000",oEe="#6b8e23",AEe="#ffa500",aEe="#ff4500",sEe="#da70d6",lEe="#eee8aa",cEe="#98fb98",uEe="#afeeee",dEe="#db7093",hEe="#ffefd5",mEe="#ffdab9",fEe="#cd853f",pEe="#ffc0cb",bEe="#dda0dd",yEe="#b0e0e6",ZEe="#800080",GEe="#663399",vEe="#ff0000",BEe="#bc8f8f",SEe="#4169e1",wEe="#8b4513",VEe="#fa8072",REe="#f4a460",WEe="#2e8b57",XEe="#fff5ee",HEe="#a0522d",TEe="#c0c0c0",NEe="#87ceeb",kEe="#6a5acd",YEe="#708090",KEe="#708090",DEe="#fffafa",xEe="#00ff7f",FEe="#4682b4",EEe="#d2b48c",MEe="#008080",zEe="#d8bfd8",PEe="#ff6347",JEe="#40e0d0",OEe="#ee82ee",_Ee="#f5deb3",LEe="#ffffff",UEe="#f5f5f5",QEe="#ffff00",jEe="#9acd32",$Ee={aliceblue:lxe,antiquewhite:cxe,aqua:uxe,aquamarine:dxe,azure:hxe,beige:mxe,bisque:fxe,black:pxe,blanchedalmond:bxe,blue:yxe,blueviolet:Zxe,brown:Gxe,burlywood:vxe,cadetblue:Bxe,chartreuse:Sxe,chocolate:wxe,coral:Vxe,cornflowerblue:Rxe,cornsilk:Wxe,crimson:Xxe,cyan:Hxe,darkblue:Txe,darkcyan:Nxe,darkgoldenrod:kxe,darkgray:Yxe,darkgreen:Kxe,darkgrey:Dxe,darkkhaki:xxe,darkmagenta:Fxe,darkolivegreen:Exe,darkorange:Mxe,darkorchid:zxe,darkred:Pxe,darksalmon:Jxe,darkseagreen:Oxe,darkslateblue:_xe,darkslategray:Lxe,darkslategrey:Uxe,darkturquoise:Qxe,darkviolet:jxe,deeppink:$xe,deepskyblue:qxe,dimgray:eFe,dimgrey:tFe,dodgerblue:gFe,firebrick:IFe,floralwhite:iFe,forestgreen:nFe,fuchsia:CFe,gainsboro:rFe,ghostwhite:oFe,goldenrod:AFe,gold:aFe,gray:sFe,green:lFe,greenyellow:cFe,grey:uFe,honeydew:dFe,hotpink:hFe,indianred:mFe,indigo:fFe,ivory:pFe,khaki:bFe,lavenderblush:yFe,lavender:ZFe,lawngreen:GFe,lemonchiffon:vFe,lightblue:BFe,lightcoral:SFe,lightcyan:wFe,lightgoldenrodyellow:VFe,lightgray:RFe,lightgreen:WFe,lightgrey:XFe,lightpink:HFe,lightsalmon:TFe,lightseagreen:NFe,lightskyblue:kFe,lightslategray:YFe,lightslategrey:KFe,lightsteelblue:DFe,lightyellow:xFe,lime:FFe,limegreen:EFe,linen:MFe,magenta:zFe,maroon:PFe,mediumaquamarine:JFe,mediumblue:OFe,mediumorchid:_Fe,mediumpurple:LFe,mediumseagreen:UFe,mediumslateblue:QFe,mediumspringgreen:jFe,mediumturquoise:$Fe,mediumvioletred:qFe,midnightblue:eEe,mintcream:tEe,mistyrose:gEe,moccasin:IEe,navajowhite:iEe,navy:nEe,oldlace:CEe,olive:rEe,olivedrab:oEe,orange:AEe,orangered:aEe,orchid:sEe,palegoldenrod:lEe,palegreen:cEe,paleturquoise:uEe,palevioletred:dEe,papayawhip:hEe,peachpuff:mEe,peru:fEe,pink:pEe,plum:bEe,powderblue:yEe,purple:ZEe,rebeccapurple:GEe,red:vEe,rosybrown:BEe,royalblue:SEe,saddlebrown:wEe,salmon:VEe,sandybrown:REe,seagreen:WEe,seashell:XEe,sienna:HEe,silver:TEe,skyblue:NEe,slateblue:kEe,slategray:YEe,slategrey:KEe,snow:DEe,springgreen:xEe,steelblue:FEe,tan:EEe,teal:MEe,thistle:zEe,tomato:PEe,turquoise:JEe,violet:OEe,wheat:_Ee,white:LEe,whitesmoke:UEe,yellow:QEe,yellowgreen:jEe};function Dd(e,g){return g===void 0&&(g=[]),g[0]=(e>>16&255)/255,g[1]=(e>>8&255)/255,g[2]=(e&255)/255,g}function IL(e){var g=e.toString(16);return g="000000".substring(0,6-g.length)+g,"#"+g}function iL(e){return typeof e=="string"&&(e=$Ee[e.toLowerCase()]||e,e[0]==="#"&&(e=e.slice(1))),parseInt(e,16)}function Xhe(e){return(e[0]*255<<16)+(e[1]*255<<8)+(e[2]*255|0)}function qEe(){for(var e=[],g=[],I=0;I<32;I++)e[I]=I,g[I]=I;e[Jt.NORMAL_NPM]=Jt.NORMAL,e[Jt.ADD_NPM]=Jt.ADD,e[Jt.SCREEN_NPM]=Jt.SCREEN,g[Jt.NORMAL]=Jt.NORMAL_NPM,g[Jt.ADD]=Jt.ADD_NPM,g[Jt.SCREEN]=Jt.SCREEN_NPM;var i=[];return i.push(g),i.push(e),i}var nL=qEe();function CL(e,g){return nL[g?1:0][e]}function Hhe(e,g,I,i){return I=I||new Float32Array(4),i||i===void 0?(I[0]=e[0]*g,I[1]=e[1]*g,I[2]=e[2]*g):(I[0]=e[0],I[1]=e[1],I[2]=e[2]),I[3]=g,I}function JH(e,g){if(g===1)return(g*255<<24)+e;if(g===0)return 0;var I=e>>16&255,i=e>>8&255,n=e&255;return I=I*g+.5|0,i=i*g+.5|0,n=n*g+.5|0,(g*255<<24)+(I<<16)+(i<<8)+n}function rL(e,g,I,i){return I=I||new Float32Array(4),I[0]=(e>>16&255)/255,I[1]=(e>>8&255)/255,I[2]=(e&255)/255,(i||i===void 0)&&(I[0]*=g,I[1]*=g,I[2]*=g),I[3]=g,I}function The(e,g){g===void 0&&(g=null);var I=e*6;if(g=g||new Uint16Array(I),g.length!==I)throw new Error("Out buffer length is incorrect, got "+g.length+" and expected "+I);for(var i=0,n=0;i>>1,e|=e>>>2,e|=e>>>4,e|=e>>>8,e|=e>>>16,e+1}function wE(e){return!(e&e-1)&&!!e}function VE(e){var g=(e>65535?1:0)<<4;e>>>=g;var I=(e>255?1:0)<<3;return e>>>=I,g|=I,I=(e>15?1:0)<<2,e>>>=I,g|=I,I=(e>3?1:0)<<1,e>>>=I,g|=I,g|e>>1}function hd(e,g,I){var i=e.length,n;if(!(g>=i||I===0)){I=g+I>i?i-g:I;var C=i-I;for(n=g;n"u"?console.warn("PixiJS Deprecation Warning: ",g+` +Deprecated since v`+e):(i=i.split(` +`).splice(I).join(` +`),console.groupCollapsed?(console.groupCollapsed("%cPixiJS Deprecation Warning: %c%s","color:#614108;background:#fffbe6","font-weight:normal;color:#614108;background:#fffbe6",g+` +Deprecated since v`+e),console.warn(i),console.groupEnd()):(console.warn("PixiJS Deprecation Warning: ",g+` +Deprecated since v`+e),console.warn(i))),aq[g]=!0}}var RE={},ZC=Object.create(null),Wr=Object.create(null);function IMe(){var e;for(e in ZC)ZC[e].destroy();for(e in Wr)Wr[e].destroy()}function iMe(){var e;for(e in ZC)delete ZC[e];for(e in Wr)delete Wr[e]}var WE=function(){function e(g,I,i){this.canvas=yt.ADAPTER.createCanvas(),this.context=this.canvas.getContext("2d"),this.resolution=i||yt.RESOLUTION,this.resize(g,I)}return e.prototype.clear=function(){this.context.setTransform(1,0,0,1,0,0),this.context.clearRect(0,0,this.canvas.width,this.canvas.height)},e.prototype.resize=function(g,I){this.canvas.width=Math.round(g*this.resolution),this.canvas.height=Math.round(I*this.resolution)},e.prototype.destroy=function(){this.context=null,this.canvas=null},Object.defineProperty(e.prototype,"width",{get:function(){return this.canvas.width},set:function(g){this.canvas.width=Math.round(g)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"height",{get:function(){return this.canvas.height},set:function(g){this.canvas.height=Math.round(g)},enumerable:!1,configurable:!0}),e}();function Nhe(e){var g=e.width,I=e.height,i=e.getContext("2d",{willReadFrequently:!0}),n=i.getImageData(0,0,g,I),C=n.data,r=C.length,o={top:null,left:null,right:null,bottom:null},A=null,s,a,l;for(s=0;s=this.x&&g=this.y&&Ig.right?g.right:this.right;if(n<=i)return!1;var C=this.yg.bottom?g.bottom:this.bottom;return r>C}var o=this.left,A=this.right,s=this.top,a=this.bottom;if(A<=o||a<=s)return!1;var l=qw[0].set(g.left,g.top),c=qw[1].set(g.left,g.bottom),u=qw[2].set(g.right,g.top),d=qw[3].set(g.right,g.bottom);if(u.x<=l.x||c.y<=l.y)return!1;var h=Math.sign(I.a*I.d-I.b*I.c);if(h===0||(I.apply(l,l),I.apply(c,c),I.apply(u,u),I.apply(d,d),Math.max(l.x,c.x,u.x,d.x)<=o||Math.min(l.x,c.x,u.x,d.x)>=A||Math.max(l.y,c.y,u.y,d.y)<=s||Math.min(l.y,c.y,u.y,d.y)>=a))return!1;var m=h*(c.y-l.y),f=h*(l.x-c.x),b=m*o+f*s,p=m*A+f*s,y=m*o+f*a,Z=m*A+f*a;if(Math.max(b,p,y,Z)<=m*l.x+f*l.y||Math.min(b,p,y,Z)>=m*d.x+f*d.y)return!1;var B=h*(l.y-u.y),G=h*(u.x-l.x),v=B*o+G*s,w=B*A+G*s,V=B*o+G*a,S=B*A+G*a;return!(Math.max(v,w,V,S)<=B*l.x+G*l.y||Math.min(v,w,V,S)>=B*d.x+G*d.y)},e.prototype.pad=function(g,I){return g===void 0&&(g=0),I===void 0&&(I=g),this.x-=g,this.y-=I,this.width+=g*2,this.height+=I*2,this},e.prototype.fit=function(g){var I=Math.max(this.x,g.x),i=Math.min(this.x+this.width,g.x+g.width),n=Math.max(this.y,g.y),C=Math.min(this.y+this.height,g.y+g.height);return this.x=I,this.width=Math.max(i-I,0),this.y=n,this.height=Math.max(C-n,0),this},e.prototype.ceil=function(g,I){g===void 0&&(g=1),I===void 0&&(I=.001);var i=Math.ceil((this.x+this.width-I)*g)/g,n=Math.ceil((this.y+this.height-I)*g)/g;return this.x=Math.floor((this.x+I)*g)/g,this.y=Math.floor((this.y+I)*g)/g,this.width=i-this.x,this.height=n-this.y,this},e.prototype.enlarge=function(g){var I=Math.min(this.x,g.x),i=Math.max(this.x+this.width,g.x+g.width),n=Math.min(this.y,g.y),C=Math.max(this.y+this.height,g.y+g.height);return this.x=I,this.width=i-I,this.y=n,this.height=C-n,this},e.prototype.toString=function(){return"[@pixi/math:Rectangle x="+this.x+" y="+this.y+" width="+this.width+" height="+this.height+"]"},e}(),xhe=function(){function e(g,I,i){g===void 0&&(g=0),I===void 0&&(I=0),i===void 0&&(i=0),this.x=g,this.y=I,this.radius=i,this.type=Si.CIRC}return e.prototype.clone=function(){return new e(this.x,this.y,this.radius)},e.prototype.contains=function(g,I){if(this.radius<=0)return!1;var i=this.radius*this.radius,n=this.x-g,C=this.y-I;return n*=n,C*=C,n+C<=i},e.prototype.getBounds=function(){return new vg(this.x-this.radius,this.y-this.radius,this.radius*2,this.radius*2)},e.prototype.toString=function(){return"[@pixi/math:Circle x="+this.x+" y="+this.y+" radius="+this.radius+"]"},e}(),Fhe=function(){function e(g,I,i,n){g===void 0&&(g=0),I===void 0&&(I=0),i===void 0&&(i=0),n===void 0&&(n=0),this.x=g,this.y=I,this.width=i,this.height=n,this.type=Si.ELIP}return e.prototype.clone=function(){return new e(this.x,this.y,this.width,this.height)},e.prototype.contains=function(g,I){if(this.width<=0||this.height<=0)return!1;var i=(g-this.x)/this.width,n=(I-this.y)/this.height;return i*=i,n*=n,i+n<=1},e.prototype.getBounds=function(){return new vg(this.x-this.width,this.y-this.height,this.width,this.height)},e.prototype.toString=function(){return"[@pixi/math:Ellipse x="+this.x+" y="+this.y+" width="+this.width+" height="+this.height+"]"},e}(),GG=function(){function e(){for(var g=arguments,I=[],i=0;iI!=a>I&&g<(s-o)*((I-A)/(a-A))+o;l&&(i=!i)}return i},e.prototype.toString=function(){return"[@pixi/math:Polygon"+("closeStroke="+this.closeStroke)+("points="+this.points.reduce(function(g,I){return g+", "+I},"")+"]")},e}(),Ehe=function(){function e(g,I,i,n,C){g===void 0&&(g=0),I===void 0&&(I=0),i===void 0&&(i=0),n===void 0&&(n=0),C===void 0&&(C=20),this.x=g,this.y=I,this.width=i,this.height=n,this.radius=C,this.type=Si.RREC}return e.prototype.clone=function(){return new e(this.x,this.y,this.width,this.height,this.radius)},e.prototype.contains=function(g,I){if(this.width<=0||this.height<=0)return!1;if(g>=this.x&&g<=this.x+this.width&&I>=this.y&&I<=this.y+this.height){var i=Math.max(0,Math.min(this.radius,Math.min(this.width,this.height)/2));if(I>=this.y+i&&I<=this.y+this.height-i||g>=this.x+i&&g<=this.x+this.width-i)return!0;var n=g-(this.x+i),C=I-(this.y+i),r=i*i;if(n*n+C*C<=r||(n=g-(this.x+this.width-i),n*n+C*C<=r)||(C=I-(this.y+this.height-i),n*n+C*C<=r)||(n=g-(this.x+i),n*n+C*C<=r))return!0}return!1},e.prototype.toString=function(){return"[@pixi/math:RoundedRectangle x="+this.x+" y="+this.y+("width="+this.width+" height="+this.height+" radius="+this.radius+"]")},e}(),qu=function(){function e(g,I,i,n){i===void 0&&(i=0),n===void 0&&(n=0),this._x=i,this._y=n,this.cb=g,this.scope=I}return e.prototype.clone=function(g,I){return g===void 0&&(g=this.cb),I===void 0&&(I=this.scope),new e(g,I,this._x,this._y)},e.prototype.set=function(g,I){return g===void 0&&(g=0),I===void 0&&(I=g),(this._x!==g||this._y!==I)&&(this._x=g,this._y=I,this.cb.call(this.scope)),this},e.prototype.copyFrom=function(g){return(this._x!==g.x||this._y!==g.y)&&(this._x=g.x,this._y=g.y,this.cb.call(this.scope)),this},e.prototype.copyTo=function(g){return g.set(this._x,this._y),g},e.prototype.equals=function(g){return g.x===this._x&&g.y===this._y},e.prototype.toString=function(){return"[@pixi/math:ObservablePoint x=0 y=0 scope="+this.scope+"]"},Object.defineProperty(e.prototype,"x",{get:function(){return this._x},set:function(g){this._x!==g&&(this._x=g,this.cb.call(this.scope))},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"y",{get:function(){return this._y},set:function(g){this._y!==g&&(this._y=g,this.cb.call(this.scope))},enumerable:!1,configurable:!0}),e}(),fi=function(){function e(g,I,i,n,C,r){g===void 0&&(g=1),I===void 0&&(I=0),i===void 0&&(i=0),n===void 0&&(n=1),C===void 0&&(C=0),r===void 0&&(r=0),this.array=null,this.a=g,this.b=I,this.c=i,this.d=n,this.tx=C,this.ty=r}return e.prototype.fromArray=function(g){this.a=g[0],this.b=g[1],this.c=g[3],this.d=g[4],this.tx=g[2],this.ty=g[5]},e.prototype.set=function(g,I,i,n,C,r){return this.a=g,this.b=I,this.c=i,this.d=n,this.tx=C,this.ty=r,this},e.prototype.toArray=function(g,I){this.array||(this.array=new Float32Array(9));var i=I||this.array;return g?(i[0]=this.a,i[1]=this.b,i[2]=0,i[3]=this.c,i[4]=this.d,i[5]=0,i[6]=this.tx,i[7]=this.ty,i[8]=1):(i[0]=this.a,i[1]=this.c,i[2]=this.tx,i[3]=this.b,i[4]=this.d,i[5]=this.ty,i[6]=0,i[7]=0,i[8]=1),i},e.prototype.apply=function(g,I){I=I||new rI;var i=g.x,n=g.y;return I.x=this.a*i+this.c*n+this.tx,I.y=this.b*i+this.d*n+this.ty,I},e.prototype.applyInverse=function(g,I){I=I||new rI;var i=1/(this.a*this.d+this.c*-this.b),n=g.x,C=g.y;return I.x=this.d*i*n+-this.c*i*C+(this.ty*this.c-this.tx*this.d)*i,I.y=this.a*i*C+-this.b*i*n+(-this.ty*this.a+this.tx*this.b)*i,I},e.prototype.translate=function(g,I){return this.tx+=g,this.ty+=I,this},e.prototype.scale=function(g,I){return this.a*=g,this.d*=I,this.c*=g,this.b*=I,this.tx*=g,this.ty*=I,this},e.prototype.rotate=function(g){var I=Math.cos(g),i=Math.sin(g),n=this.a,C=this.c,r=this.tx;return this.a=n*I-this.b*i,this.b=n*i+this.b*I,this.c=C*I-this.d*i,this.d=C*i+this.d*I,this.tx=r*I-this.ty*i,this.ty=r*i+this.ty*I,this},e.prototype.append=function(g){var I=this.a,i=this.b,n=this.c,C=this.d;return this.a=g.a*I+g.b*n,this.b=g.a*i+g.b*C,this.c=g.c*I+g.d*n,this.d=g.c*i+g.d*C,this.tx=g.tx*I+g.ty*n+this.tx,this.ty=g.tx*i+g.ty*C+this.ty,this},e.prototype.setTransform=function(g,I,i,n,C,r,o,A,s){return this.a=Math.cos(o+s)*C,this.b=Math.sin(o+s)*C,this.c=-Math.sin(o-A)*r,this.d=Math.cos(o-A)*r,this.tx=g-(i*this.a+n*this.c),this.ty=I-(i*this.b+n*this.d),this},e.prototype.prepend=function(g){var I=this.tx;if(g.a!==1||g.b!==0||g.c!==0||g.d!==1){var i=this.a,n=this.c;this.a=i*g.a+this.b*g.c,this.b=i*g.b+this.b*g.d,this.c=n*g.a+this.d*g.c,this.d=n*g.b+this.d*g.d}return this.tx=I*g.a+this.ty*g.c+g.tx,this.ty=I*g.b+this.ty*g.d+g.ty,this},e.prototype.decompose=function(g){var I=this.a,i=this.b,n=this.c,C=this.d,r=g.pivot,o=-Math.atan2(-n,C),A=Math.atan2(i,I),s=Math.abs(o+A);return s<1e-5||Math.abs(Ov-s)<1e-5?(g.rotation=A,g.skew.x=g.skew.y=0):(g.rotation=0,g.skew.x=o,g.skew.y=A),g.scale.x=Math.sqrt(I*I+i*i),g.scale.y=Math.sqrt(n*n+C*C),g.position.x=this.tx+(r.x*I+r.y*n),g.position.y=this.ty+(r.x*i+r.y*C),g},e.prototype.invert=function(){var g=this.a,I=this.b,i=this.c,n=this.d,C=this.tx,r=g*n-I*i;return this.a=n/r,this.b=-I/r,this.c=-i/r,this.d=g/r,this.tx=(i*this.ty-n*C)/r,this.ty=-(g*this.ty-I*C)/r,this},e.prototype.identity=function(){return this.a=1,this.b=0,this.c=0,this.d=1,this.tx=0,this.ty=0,this},e.prototype.clone=function(){var g=new e;return g.a=this.a,g.b=this.b,g.c=this.c,g.d=this.d,g.tx=this.tx,g.ty=this.ty,g},e.prototype.copyTo=function(g){return g.a=this.a,g.b=this.b,g.c=this.c,g.d=this.d,g.tx=this.tx,g.ty=this.ty,g},e.prototype.copyFrom=function(g){return this.a=g.a,this.b=g.b,this.c=g.c,this.d=g.d,this.tx=g.tx,this.ty=g.ty,this},e.prototype.toString=function(){return"[@pixi/math:Matrix a="+this.a+" b="+this.b+" c="+this.c+" d="+this.d+" tx="+this.tx+" ty="+this.ty+"]"},Object.defineProperty(e,"IDENTITY",{get:function(){return new e},enumerable:!1,configurable:!0}),Object.defineProperty(e,"TEMP_MATRIX",{get:function(){return new e},enumerable:!1,configurable:!0}),e}(),Hu=[1,1,0,-1,-1,-1,0,1,1,1,0,-1,-1,-1,0,1],Tu=[0,1,1,1,0,-1,-1,-1,0,1,1,1,0,-1,-1,-1],Nu=[0,-1,-1,-1,0,1,1,1,0,1,1,1,0,-1,-1,-1],ku=[1,1,0,-1,-1,-1,0,1,-1,-1,0,1,1,1,0,-1],XE=[],Mhe=[],eV=Math.sign;function rMe(){for(var e=0;e<16;e++){var g=[];XE.push(g);for(var I=0;I<16;I++)for(var i=eV(Hu[e]*Hu[I]+Nu[e]*Tu[I]),n=eV(Tu[e]*Hu[I]+ku[e]*Tu[I]),C=eV(Hu[e]*Nu[I]+Nu[e]*ku[I]),r=eV(Tu[e]*Nu[I]+ku[e]*ku[I]),o=0;o<16;o++)if(Hu[o]===i&&Tu[o]===n&&Nu[o]===C&&ku[o]===r){g.push(o);break}}for(var e=0;e<16;e++){var A=new fi;A.set(Hu[e],Tu[e],Nu[e],ku[e],0,0),Mhe.push(A)}}rMe();var SI={E:0,SE:1,S:2,SW:3,W:4,NW:5,N:6,NE:7,MIRROR_VERTICAL:8,MAIN_DIAGONAL:10,MIRROR_HORIZONTAL:12,REVERSE_DIAGONAL:14,uX:function(e){return Hu[e]},uY:function(e){return Tu[e]},vX:function(e){return Nu[e]},vY:function(e){return ku[e]},inv:function(e){return e&8?e&15:-e&7},add:function(e,g){return XE[e][g]},sub:function(e,g){return XE[e][SI.inv(g)]},rotate180:function(e){return e^4},isVertical:function(e){return(e&3)===2},byDirection:function(e,g){return Math.abs(e)*2<=Math.abs(g)?g>=0?SI.S:SI.N:Math.abs(g)*2<=Math.abs(e)?e>0?SI.E:SI.W:g>0?e>0?SI.SE:SI.SW:e>0?SI.NE:SI.NW},matrixAppendRotationInv:function(e,g,I,i){I===void 0&&(I=0),i===void 0&&(i=0);var n=Mhe[SI.inv(g)];n.tx=I,n.ty=i,e.append(n)}},oL=function(){function e(){this.worldTransform=new fi,this.localTransform=new fi,this.position=new qu(this.onChange,this,0,0),this.scale=new qu(this.onChange,this,1,1),this.pivot=new qu(this.onChange,this,0,0),this.skew=new qu(this.updateSkew,this,0,0),this._rotation=0,this._cx=1,this._sx=0,this._cy=0,this._sy=1,this._localID=0,this._currentLocalID=0,this._worldID=0,this._parentID=0}return e.prototype.onChange=function(){this._localID++},e.prototype.updateSkew=function(){this._cx=Math.cos(this._rotation+this.skew.y),this._sx=Math.sin(this._rotation+this.skew.y),this._cy=-Math.sin(this._rotation-this.skew.x),this._sy=Math.cos(this._rotation-this.skew.x),this._localID++},e.prototype.toString=function(){return"[@pixi/math:Transform "+("position=("+this.position.x+", "+this.position.y+") ")+("rotation="+this.rotation+" ")+("scale=("+this.scale.x+", "+this.scale.y+") ")+("skew=("+this.skew.x+", "+this.skew.y+") ")+"]"},e.prototype.updateLocalTransform=function(){var g=this.localTransform;this._localID!==this._currentLocalID&&(g.a=this._cx*this.scale.x,g.b=this._sx*this.scale.x,g.c=this._cy*this.scale.y,g.d=this._sy*this.scale.y,g.tx=this.position.x-(this.pivot.x*g.a+this.pivot.y*g.c),g.ty=this.position.y-(this.pivot.x*g.b+this.pivot.y*g.d),this._currentLocalID=this._localID,this._parentID=-1)},e.prototype.updateTransform=function(g){var I=this.localTransform;if(this._localID!==this._currentLocalID&&(I.a=this._cx*this.scale.x,I.b=this._sx*this.scale.x,I.c=this._cy*this.scale.y,I.d=this._sy*this.scale.y,I.tx=this.position.x-(this.pivot.x*I.a+this.pivot.y*I.c),I.ty=this.position.y-(this.pivot.x*I.b+this.pivot.y*I.d),this._currentLocalID=this._localID,this._parentID=-1),this._parentID!==g._worldID){var i=g.worldTransform,n=this.worldTransform;n.a=I.a*i.a+I.b*i.c,n.b=I.a*i.b+I.b*i.d,n.c=I.c*i.a+I.d*i.c,n.d=I.c*i.b+I.d*i.d,n.tx=I.tx*i.a+I.ty*i.c+i.tx,n.ty=I.tx*i.b+I.ty*i.d+i.ty,this._parentID=g._worldID,this._worldID++}},e.prototype.setFromMatrix=function(g){g.decompose(this),this._localID++},Object.defineProperty(e.prototype,"rotation",{get:function(){return this._rotation},set:function(g){this._rotation!==g&&(this._rotation=g,this.updateSkew())},enumerable:!1,configurable:!0}),e.IDENTITY=new e,e}();/*! + * @pixi/display - v6.5.10 + * Compiled Thu, 06 Jul 2023 15:25:11 UTC + * + * @pixi/display is licensed under the MIT License. + * http://www.opensource.org/licenses/mit-license + */yt.SORTABLE_CHILDREN=!1;var _v=function(){function e(){this.minX=1/0,this.minY=1/0,this.maxX=-1/0,this.maxY=-1/0,this.rect=null,this.updateID=-1}return e.prototype.isEmpty=function(){return this.minX>this.maxX||this.minY>this.maxY},e.prototype.clear=function(){this.minX=1/0,this.minY=1/0,this.maxX=-1/0,this.maxY=-1/0},e.prototype.getRectangle=function(g){return this.minX>this.maxX||this.minY>this.maxY?vg.EMPTY:(g=g||new vg(0,0,1,1),g.x=this.minX,g.y=this.minY,g.width=this.maxX-this.minX,g.height=this.maxY-this.minY,g)},e.prototype.addPoint=function(g){this.minX=Math.min(this.minX,g.x),this.maxX=Math.max(this.maxX,g.x),this.minY=Math.min(this.minY,g.y),this.maxY=Math.max(this.maxY,g.y)},e.prototype.addPointMatrix=function(g,I){var i=g.a,n=g.b,C=g.c,r=g.d,o=g.tx,A=g.ty,s=i*I.x+C*I.y+o,a=n*I.x+r*I.y+A;this.minX=Math.min(this.minX,s),this.maxX=Math.max(this.maxX,s),this.minY=Math.min(this.minY,a),this.maxY=Math.max(this.maxY,a)},e.prototype.addQuad=function(g){var I=this.minX,i=this.minY,n=this.maxX,C=this.maxY,r=g[0],o=g[1];I=rn?r:n,C=o>C?o:C,r=g[2],o=g[3],I=rn?r:n,C=o>C?o:C,r=g[4],o=g[5],I=rn?r:n,C=o>C?o:C,r=g[6],o=g[7],I=rn?r:n,C=o>C?o:C,this.minX=I,this.minY=i,this.maxX=n,this.maxY=C},e.prototype.addFrame=function(g,I,i,n,C){this.addFrameMatrix(g.worldTransform,I,i,n,C)},e.prototype.addFrameMatrix=function(g,I,i,n,C){var r=g.a,o=g.b,A=g.c,s=g.d,a=g.tx,l=g.ty,c=this.minX,u=this.minY,d=this.maxX,h=this.maxY,m=r*I+A*i+a,f=o*I+s*i+l;c=md?m:d,h=f>h?f:h,m=r*n+A*i+a,f=o*n+s*i+l,c=md?m:d,h=f>h?f:h,m=r*I+A*C+a,f=o*I+s*C+l,c=md?m:d,h=f>h?f:h,m=r*n+A*C+a,f=o*n+s*C+l,c=md?m:d,h=f>h?f:h,this.minX=c,this.minY=u,this.maxX=d,this.maxY=h},e.prototype.addVertexData=function(g,I,i){for(var n=this.minX,C=this.minY,r=this.maxX,o=this.maxY,A=I;Ar?s:r,o=a>o?a:o}this.minX=n,this.minY=C,this.maxX=r,this.maxY=o},e.prototype.addVertices=function(g,I,i,n){this.addVerticesMatrix(g.worldTransform,I,i,n)},e.prototype.addVerticesMatrix=function(g,I,i,n,C,r){C===void 0&&(C=0),r===void 0&&(r=C);for(var o=g.a,A=g.b,s=g.c,a=g.d,l=g.tx,c=g.ty,u=this.minX,d=this.minY,h=this.maxX,m=this.maxY,f=i;fn?g.maxX:n,this.maxY=g.maxY>C?g.maxY:C},e.prototype.addBoundsMask=function(g,I){var i=g.minX>I.minX?g.minX:I.minX,n=g.minY>I.minY?g.minY:I.minY,C=g.maxXs?C:s,this.maxY=r>a?r:a}},e.prototype.addBoundsMatrix=function(g,I){this.addFrameMatrix(I,g.minX,g.minY,g.maxX,g.maxY)},e.prototype.addBoundsArea=function(g,I){var i=g.minX>I.x?g.minX:I.x,n=g.minY>I.y?g.minY:I.y,C=g.maxXs?C:s,this.maxY=r>a?r:a}},e.prototype.pad=function(g,I){g===void 0&&(g=0),I===void 0&&(I=g),this.isEmpty()||(this.minX-=g,this.maxX+=g,this.minY-=I,this.maxY+=I)},e.prototype.addFramePad=function(g,I,i,n,C,r){g-=C,I-=r,i+=C,n+=r,this.minX=this.minXi?this.maxX:i,this.minY=this.minYn?this.maxY:n},e}();/*! ***************************************************************************** +Copyright (c) Microsoft Corporation. + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +PERFORMANCE OF THIS SOFTWARE. +***************************************************************************** */var HE=function(e,g){return HE=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(I,i){I.__proto__=i}||function(I,i){for(var n in i)i.hasOwnProperty(n)&&(I[n]=i[n])},HE(e,g)};function AL(e,g){HE(e,g);function I(){this.constructor=e}e.prototype=g===null?Object.create(g):(I.prototype=g.prototype,new I)}var jI=function(e){AL(g,e);function g(){var I=e.call(this)||this;return I.tempDisplayObjectParent=null,I.transform=new oL,I.alpha=1,I.visible=!0,I.renderable=!0,I.cullable=!1,I.cullArea=null,I.parent=null,I.worldAlpha=1,I._lastSortedIndex=0,I._zIndex=0,I.filterArea=null,I.filters=null,I._enabledFilters=null,I._bounds=new _v,I._localBounds=null,I._boundsID=0,I._boundsRect=null,I._localBoundsRect=null,I._mask=null,I._maskRefCount=0,I._destroyed=!1,I.isSprite=!1,I.isMask=!1,I}return g.mixin=function(I){for(var i=Object.keys(I),n=0;n1)for(var C=0;Cthis.children.length)throw new Error(I+"addChildAt: The index "+i+" supplied is out of bounds "+this.children.length);return I.parent&&I.parent.removeChild(I),I.parent=this,this.sortDirty=!0,I.transform._parentID=-1,this.children.splice(i,0,I),this._boundsID++,this.onChildrenChange(i),I.emit("added",this),this.emit("childAdded",I,this,i),I},g.prototype.swapChildren=function(I,i){if(I!==i){var n=this.getChildIndex(I),C=this.getChildIndex(i);this.children[n]=i,this.children[C]=I,this.onChildrenChange(n=this.children.length)throw new Error("The index "+i+" supplied is out of bounds "+this.children.length);var n=this.getChildIndex(I);hd(this.children,n,1),this.children.splice(i,0,I),this.onChildrenChange(i)},g.prototype.getChildAt=function(I){if(I<0||I>=this.children.length)throw new Error("getChildAt: Index ("+I+") does not exist.");return this.children[I]},g.prototype.removeChild=function(){for(var I=arguments,i=[],n=0;n1)for(var C=0;C0&&r<=C){o=this.children.splice(n,r);for(var A=0;A1&&this.children.sort(oMe),this.sortDirty=!1},g.prototype.updateTransform=function(){this.sortableChildren&&this.sortDirty&&this.sortChildren(),this._boundsID++,this.transform.updateTransform(this.parent.transform),this.worldAlpha=this.alpha*this.parent.worldAlpha;for(var I=0,i=this.children.length;I0&&i.height>0){var n,C;if(this.cullArea?(n=this.cullArea,C=this.worldTransform):this._render!==g.prototype._render&&(n=this.getBounds(!0)),n&&i.intersects(n,C))this._render(I);else if(this.cullArea)return;for(var r=0,o=this.children.length;r8)throw new Error("max arguments reached");var s=this,a=s.name,l=s.items;this._aliasCount++;for(var c=0,u=l.length;c0&&this.items.length>1&&(this._aliasCount=0,this.items=this.items.slice(0))},e.prototype.add=function(g){return g[this._name]&&(this.ensureNonAliasedItems(),this.remove(g),this.items.push(g)),this},e.prototype.remove=function(g){var I=this.items.indexOf(g);return I!==-1&&(this.ensureNonAliasedItems(),this.items.splice(I,1)),this},e.prototype.contains=function(g){return this.items.indexOf(g)!==-1},e.prototype.removeAll=function(){return this.ensureNonAliasedItems(),this.items.length=0,this},e.prototype.destroy=function(){this.removeAll(),this.items=null,this._name=null},Object.defineProperty(e.prototype,"empty",{get:function(){return this.items.length===0},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"name",{get:function(){return this._name},enumerable:!1,configurable:!0}),e}();Object.defineProperties(zi.prototype,{dispatch:{value:zi.prototype.emit},run:{value:zi.prototype.emit}});/*! + * @pixi/ticker - v6.5.10 + * Compiled Thu, 06 Jul 2023 15:25:11 UTC + * + * @pixi/ticker is licensed under the MIT License. + * http://www.opensource.org/licenses/mit-license + */yt.TARGET_FPMS=.06;var sa;(function(e){e[e.INTERACTION=50]="INTERACTION",e[e.HIGH=25]="HIGH",e[e.NORMAL=0]="NORMAL",e[e.LOW=-25]="LOW",e[e.UTILITY=-50]="UTILITY"})(sa||(sa={}));var jY=function(){function e(g,I,i,n){I===void 0&&(I=null),i===void 0&&(i=0),n===void 0&&(n=!1),this.next=null,this.previous=null,this._destroyed=!1,this.fn=g,this.context=I,this.priority=i,this.once=n}return e.prototype.match=function(g,I){return I===void 0&&(I=null),this.fn===g&&this.context===I},e.prototype.emit=function(g){this.fn&&(this.context?this.fn.call(this.context,g):this.fn(g));var I=this.next;return this.once&&this.destroy(!0),this._destroyed&&(this.next=null),I},e.prototype.connect=function(g){this.previous=g,g.next&&(g.next.previous=this),this.next=g.next,g.next=this},e.prototype.destroy=function(g){g===void 0&&(g=!1),this._destroyed=!0,this.fn=null,this.context=null,this.previous&&(this.previous.next=this.next),this.next&&(this.next.previous=this.previous);var I=this.next;return this.next=g?null:I,this.previous=null,I},e}(),Pi=function(){function e(){var g=this;this.autoStart=!1,this.deltaTime=1,this.lastTime=-1,this.speed=1,this.started=!1,this._requestId=null,this._maxElapsedMS=100,this._minElapsedMS=0,this._protected=!1,this._lastFrame=-1,this._head=new jY(null,null,1/0),this.deltaMS=1/yt.TARGET_FPMS,this.elapsedMS=1/yt.TARGET_FPMS,this._tick=function(I){g._requestId=null,g.started&&(g.update(I),g.started&&g._requestId===null&&g._head.next&&(g._requestId=requestAnimationFrame(g._tick)))}}return e.prototype._requestIfNeeded=function(){this._requestId===null&&this._head.next&&(this.lastTime=performance.now(),this._lastFrame=this.lastTime,this._requestId=requestAnimationFrame(this._tick))},e.prototype._cancelIfNeeded=function(){this._requestId!==null&&(cancelAnimationFrame(this._requestId),this._requestId=null)},e.prototype._startIfPossible=function(){this.started?this._requestIfNeeded():this.autoStart&&this.start()},e.prototype.add=function(g,I,i){return i===void 0&&(i=sa.NORMAL),this._addListener(new jY(g,I,i))},e.prototype.addOnce=function(g,I,i){return i===void 0&&(i=sa.NORMAL),this._addListener(new jY(g,I,i,!0))},e.prototype._addListener=function(g){var I=this._head.next,i=this._head;if(!I)g.connect(i);else{for(;I;){if(g.priority>I.priority){g.connect(i);break}i=I,I=I.next}g.previous||g.connect(i)}return this._startIfPossible(),this},e.prototype.remove=function(g,I){for(var i=this._head.next;i;)i.match(g,I)?i=i.destroy():i=i.next;return this._head.next||this._cancelIfNeeded(),this},Object.defineProperty(e.prototype,"count",{get:function(){if(!this._head)return 0;for(var g=0,I=this._head;I=I.next;)g++;return g},enumerable:!1,configurable:!0}),e.prototype.start=function(){this.started||(this.started=!0,this._requestIfNeeded())},e.prototype.stop=function(){this.started&&(this.started=!1,this._cancelIfNeeded())},e.prototype.destroy=function(){if(!this._protected){this.stop();for(var g=this._head.next;g;)g=g.destroy(!0);this._head.destroy(),this._head=null}},e.prototype.update=function(g){g===void 0&&(g=performance.now());var I;if(g>this.lastTime){if(I=this.elapsedMS=g-this.lastTime,I>this._maxElapsedMS&&(I=this._maxElapsedMS),I*=this.speed,this._minElapsedMS){var i=g-this._lastFrame|0;if(i=0;--n){var C=Lv[n];if(C.test&&C.test(e,I))return new C(e,g)}throw new Error("Unrecognized source type to auto-detect Resource")}/*! ***************************************************************************** +Copyright (c) Microsoft Corporation. + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +PERFORMANCE OF THIS SOFTWARE. +***************************************************************************** */var TE=function(e,g){return TE=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(I,i){I.__proto__=i}||function(I,i){for(var n in i)i.hasOwnProperty(n)&&(I[n]=i[n])},TE(e,g)};function oI(e,g){TE(e,g);function I(){this.constructor=e}e.prototype=g===null?Object.create(g):(I.prototype=g.prototype,new I)}var NE=function(){return NE=Object.assign||function(g){for(var I=arguments,i,n=1,C=arguments.length;n0&&a>0,n.textureCacheIds=[],n.destroyed=!1,n.resource=null,n._batchEnabled=0,n._batchLocation=0,n.parentTextureArray=null,n.setResource(I),n}return Object.defineProperty(g.prototype,"realWidth",{get:function(){return Math.round(this.width*this.resolution)},enumerable:!1,configurable:!0}),Object.defineProperty(g.prototype,"realHeight",{get:function(){return Math.round(this.height*this.resolution)},enumerable:!1,configurable:!0}),Object.defineProperty(g.prototype,"mipmap",{get:function(){return this._mipmap},set:function(I){this._mipmap!==I&&(this._mipmap=I,this.dirtyStyleId++)},enumerable:!1,configurable:!0}),Object.defineProperty(g.prototype,"scaleMode",{get:function(){return this._scaleMode},set:function(I){this._scaleMode!==I&&(this._scaleMode=I,this.dirtyStyleId++)},enumerable:!1,configurable:!0}),Object.defineProperty(g.prototype,"wrapMode",{get:function(){return this._wrapMode},set:function(I){this._wrapMode!==I&&(this._wrapMode=I,this.dirtyStyleId++)},enumerable:!1,configurable:!0}),g.prototype.setStyle=function(I,i){var n;return I!==void 0&&I!==this.scaleMode&&(this.scaleMode=I,n=!0),i!==void 0&&i!==this.mipmap&&(this.mipmap=i,n=!0),n&&this.dirtyStyleId++,this},g.prototype.setSize=function(I,i,n){return n=n||this.resolution,this.setRealSize(I*n,i*n,n)},g.prototype.setRealSize=function(I,i,n){return this.resolution=n||this.resolution,this.width=Math.round(I)/this.resolution,this.height=Math.round(i)/this.resolution,this._refreshPOT(),this.update(),this},g.prototype._refreshPOT=function(){this.isPowerOfTwo=wE(this.realWidth)&&wE(this.realHeight)},g.prototype.setResolution=function(I){var i=this.resolution;return i===I?this:(this.resolution=I,this.valid&&(this.width=Math.round(this.width*i)/I,this.height=Math.round(this.height*i)/I,this.emit("update",this)),this._refreshPOT(),this)},g.prototype.setResource=function(I){if(this.resource===I)return this;if(this.resource)throw new Error("Resource can be set only once");return I.bind(this),this.resource=I,this},g.prototype.update=function(){this.valid?(this.dirtyId++,this.dirtyStyleId++,this.emit("update",this)):this.width>0&&this.height>0&&(this.valid=!0,this.emit("loaded",this),this.emit("update",this))},g.prototype.onError=function(I){this.emit("error",this,I)},g.prototype.destroy=function(){this.resource&&(this.resource.unbind(this),this.resource.internal&&this.resource.destroy(),this.resource=null),this.cacheId&&(delete Wr[this.cacheId],delete ZC[this.cacheId],this.cacheId=null),this.dispose(),g.removeFromCache(this),this.textureCacheIds=null,this.destroyed=!0},g.prototype.dispose=function(){this.emit("dispose",this)},g.prototype.castToBaseTexture=function(){return this},g.from=function(I,i,n){n===void 0&&(n=yt.STRICT_TEXTURE_CACHE);var C=typeof I=="string",r=null;if(C)r=I;else{if(!I._pixiId){var o=i&&i.pixiIdPrefix||"pixiid";I._pixiId=o+"_"+kc()}r=I._pixiId}var A=Wr[r];if(C&&n&&!A)throw new Error('The cacheId "'+r+'" does not exist in BaseTextureCache.');return A||(A=new g(I,i),A.cacheId=r,g.addToCache(A,r)),A},g.fromBuffer=function(I,i,n,C){I=I||new Float32Array(i*n*4);var r=new Dh(I,{width:i,height:n}),o=I instanceof Float32Array?Et.FLOAT:Et.UNSIGNED_BYTE;return new g(r,Object.assign({},aMe,C||{width:i,height:n,type:o}))},g.addToCache=function(I,i){i&&(I.textureCacheIds.indexOf(i)===-1&&I.textureCacheIds.push(i),Wr[i]&&console.warn("BaseTexture added to the cache with an id ["+i+"] that already had an entry"),Wr[i]=I)},g.removeFromCache=function(I){if(typeof I=="string"){var i=Wr[I];if(i){var n=i.textureCacheIds.indexOf(I);return n>-1&&i.textureCacheIds.splice(n,1),delete Wr[I],i}}else if(I&&I.textureCacheIds){for(var C=0;C0)if(I.resource)this.addResourceAt(I.resource,i);else throw new Error("CubeResource does not support copying of renderTexture.");else I.target=Zc.TEXTURE_CUBE_MAP_POSITIVE_X+i,I.parentTextureArray=this.baseTexture,this.items[i]=I;return I.valid&&!this.valid&&this.resize(I.realWidth,I.realHeight),this.items[i]=I,this},g.prototype.upload=function(I,i,n){for(var C=this.itemDirtyIds,r=0;r)?\s*()]*-->)?\s*\]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i,g}(la),dL=function(e){oI(g,e);function g(I,i){var n=this;if(i=i||{},!(I instanceof HTMLVideoElement)){var C=document.createElement("video");C.setAttribute("preload","auto"),C.setAttribute("webkit-playsinline",""),C.setAttribute("playsinline",""),typeof I=="string"&&(I=[I]);var r=I[0].src||I[0];la.crossOrigin(C,r,i.crossorigin);for(var o=0;o2},g.prototype._onPlayStart=function(){this.valid||this._onCanPlay(),this.autoUpdate&&!this._isConnectedToTicker&&(Pi.shared.add(this.update,this),this._isConnectedToTicker=!0)},g.prototype._onPlayStop=function(){this._isConnectedToTicker&&(Pi.shared.remove(this.update,this),this._isConnectedToTicker=!1)},g.prototype._onCanPlay=function(){var I=this.source;I.removeEventListener("canplay",this._onCanPlay),I.removeEventListener("canplaythrough",this._onCanPlay);var i=this.valid;this.resize(I.videoWidth,I.videoHeight),!i&&this._resolve&&(this._resolve(this),this._resolve=null),this._isSourcePlaying()?this._onPlayStart():this.autoPlay&&I.play()},g.prototype.dispose=function(){this._isConnectedToTicker&&(Pi.shared.remove(this.update,this),this._isConnectedToTicker=!1);var I=this.source;I&&(I.removeEventListener("error",this._onError,!0),I.pause(),I.src="",I.load()),e.prototype.dispose.call(this)},Object.defineProperty(g.prototype,"autoUpdate",{get:function(){return this._autoUpdate},set:function(I){I!==this._autoUpdate&&(this._autoUpdate=I,!this._autoUpdate&&this._isConnectedToTicker?(Pi.shared.remove(this.update,this),this._isConnectedToTicker=!1):this._autoUpdate&&!this._isConnectedToTicker&&this._isSourcePlaying()&&(Pi.shared.add(this.update,this),this._isConnectedToTicker=!0))},enumerable:!1,configurable:!0}),Object.defineProperty(g.prototype,"updateFPS",{get:function(){return this._updateFPS},set:function(I){I!==this._updateFPS&&(this._updateFPS=I)},enumerable:!1,configurable:!0}),g.test=function(I,i){return globalThis.HTMLVideoElement&&I instanceof HTMLVideoElement||g.TYPES.indexOf(i)>-1},g.TYPES=["mp4","m4v","webm","ogg","ogv","h264","avi","mov"],g.MIME_TYPES={ogv:"video/ogg",mov:"video/quicktime",m4v:"video/mp4"},g}(la),hL=function(e){oI(g,e);function g(I){return e.call(this,I)||this}return g.test=function(I){return!!globalThis.createImageBitmap&&typeof ImageBitmap<"u"&&I instanceof ImageBitmap},g}(la);Lv.push(UH,hL,lL,dL,uL,Dh,cL,sL);var Phe={__proto__:null,Resource:xd,BaseImageResource:la,INSTALLED:Lv,autoDetectResource:_H,AbstractMultiResource:LH,ArrayResource:sL,BufferResource:Dh,CanvasResource:lL,CubeResource:cL,ImageResource:UH,SVGResource:uL,VideoResource:dL,ImageBitmapResource:hL},sMe=function(e){oI(g,e);function g(){return e!==null&&e.apply(this,arguments)||this}return g.prototype.upload=function(I,i,n){var C=I.gl;C.pixelStorei(C.UNPACK_PREMULTIPLY_ALPHA_WEBGL,i.alphaMode===to.UNPACK);var r=i.realWidth,o=i.realHeight;return n.width===r&&n.height===o?C.texSubImage2D(i.target,0,0,0,r,o,i.format,n.type,this.data):(n.width=r,n.height=o,C.texImage2D(i.target,0,n.internalFormat,r,o,0,i.format,n.type,this.data)),!0},g}(Dh),qW=function(){function e(g,I){this.width=Math.round(g||100),this.height=Math.round(I||100),this.stencil=!1,this.depth=!1,this.dirtyId=0,this.dirtyFormat=0,this.dirtySize=0,this.depthTexture=null,this.colorTextures=[],this.glFramebuffers={},this.disposeRunner=new zi("disposeFramebuffer"),this.multisample=mI.NONE}return Object.defineProperty(e.prototype,"colorTexture",{get:function(){return this.colorTextures[0]},enumerable:!1,configurable:!0}),e.prototype.addColorTexture=function(g,I){return g===void 0&&(g=0),this.colorTextures[g]=I||new yg(null,{scaleMode:Oo.NEAREST,resolution:1,mipmap:eo.OFF,width:this.width,height:this.height}),this.dirtyId++,this.dirtyFormat++,this},e.prototype.addDepthTexture=function(g){return this.depthTexture=g||new yg(new sMe(null,{width:this.width,height:this.height}),{scaleMode:Oo.NEAREST,resolution:1,width:this.width,height:this.height,mipmap:eo.OFF,format:ht.DEPTH_COMPONENT,type:Et.UNSIGNED_SHORT}),this.dirtyId++,this.dirtyFormat++,this},e.prototype.enableDepth=function(){return this.depth=!0,this.dirtyId++,this.dirtyFormat++,this},e.prototype.enableStencil=function(){return this.stencil=!0,this.dirtyId++,this.dirtyFormat++,this},e.prototype.resize=function(g,I){if(g=Math.round(g),I=Math.round(I),!(g===this.width&&I===this.height)){this.width=g,this.height=I,this.dirtyId++,this.dirtySize++;for(var i=0;i-1&&i.textureCacheIds.splice(n,1),delete ZC[I],i}}else if(I&&I.textureCacheIds){for(var C=0;Cthis.baseTexture.width,A=n+r>this.baseTexture.height;if(o||A){var s=o&&A?"and":"or",a="X: "+i+" + "+C+" = "+(i+C)+" > "+this.baseTexture.width,l="Y: "+n+" + "+r+" = "+(n+r)+" > "+this.baseTexture.height;throw new Error("Texture Error: frame does not fit inside the base Texture dimensions: "+(a+" "+s+" "+l))}this.valid=C&&r&&this.baseTexture.valid,!this.trim&&!this.rotate&&(this.orig=I),this.valid&&this.updateUvs()},enumerable:!1,configurable:!0}),Object.defineProperty(g.prototype,"rotate",{get:function(){return this._rotate},set:function(I){this._rotate=I,this.valid&&this.updateUvs()},enumerable:!1,configurable:!0}),Object.defineProperty(g.prototype,"width",{get:function(){return this.orig.width},enumerable:!1,configurable:!0}),Object.defineProperty(g.prototype,"height",{get:function(){return this.orig.height},enumerable:!1,configurable:!0}),g.prototype.castToBaseTexture=function(){return this.baseTexture},Object.defineProperty(g,"EMPTY",{get:function(){return g._EMPTY||(g._EMPTY=new g(new yg),tV(g._EMPTY),tV(g._EMPTY.baseTexture)),g._EMPTY},enumerable:!1,configurable:!0}),Object.defineProperty(g,"WHITE",{get:function(){if(!g._WHITE){var I=yt.ADAPTER.createCanvas(16,16),i=I.getContext("2d");I.width=16,I.height=16,i.fillStyle="white",i.fillRect(0,0,16,16),g._WHITE=new g(yg.from(I)),tV(g._WHITE),tV(g._WHITE.baseTexture)}return g._WHITE},enumerable:!1,configurable:!0}),g}(l0),Ws=function(e){oI(g,e);function g(I,i){var n=e.call(this,I,i)||this;return n.valid=!0,n.filterFrame=null,n.filterPoolKey=null,n.updateUvs(),n}return Object.defineProperty(g.prototype,"framebuffer",{get:function(){return this.baseTexture.framebuffer},enumerable:!1,configurable:!0}),Object.defineProperty(g.prototype,"multisample",{get:function(){return this.framebuffer.multisample},set:function(I){this.framebuffer.multisample=I},enumerable:!1,configurable:!0}),g.prototype.resize=function(I,i,n){n===void 0&&(n=!0);var C=this.baseTexture.resolution,r=Math.round(I*C)/C,o=Math.round(i*C)/C;this.valid=r>0&&o>0,this._frame.width=this.orig.width=r,this._frame.height=this.orig.height=o,n&&this.baseTexture.resize(r,o),this.updateUvs()},g.prototype.setResolution=function(I){var i=this.baseTexture;i.resolution!==I&&(i.setResolution(I),this.resize(i.width,i.height,!1))},g.create=function(I){for(var i=arguments,n=[],C=1;C>>0,n>1&&(C+=n*4294967296)):C=n>1?-n:-1,this.texturePool[C]||(this.texturePool[C]=[]);var r=this.texturePool[C].pop();return r||(r=this.createTexture(g,I,n)),r.filterPoolKey=C,r.setResolution(i),r},e.prototype.getFilterTexture=function(g,I,i){var n=this.getOptimalTexture(g.width,g.height,I||g.resolution,i||mI.NONE);return n.filterFrame=g.filterFrame,n},e.prototype.returnTexture=function(g){var I=g.filterPoolKey;g.filterFrame=null,this.texturePool[I].push(g)},e.prototype.returnFilterTexture=function(g){this.returnTexture(g)},e.prototype.clear=function(g){if(g=g!==!1,g)for(var I in this.texturePool){var i=this.texturePool[I];if(i)for(var n=0;n0&&g.height>0;for(var I in this.texturePool)if(Number(I)<0){var i=this.texturePool[I];if(i)for(var n=0;n1){for(var a=0;a1&&(l=this.getOptimalFilterTexture(a.width,a.height,I.resolution),l.filterFrame=a.filterFrame),i[c].apply(this,a,l,kr.CLEAR,I);var u=a;a=l,l=u}i[c].apply(this,a,s.renderTexture,kr.BLEND,I),c>1&&I.multisample>1&&this.returnFilterTexture(I.renderTexture),this.returnFilterTexture(a),this.returnFilterTexture(l)}I.clear(),this.statePool.push(I)},e.prototype.bindAndClear=function(g,I){I===void 0&&(I=kr.CLEAR);var i=this.renderer,n=i.renderTexture,C=i.state;if(g===this.defaultFilterStack[this.defaultFilterStack.length-1].renderTexture?this.renderer.projection.transform=this.activeState.transform:this.renderer.projection.transform=null,g&&g.filterFrame){var r=this.tempRect;r.x=0,r.y=0,r.width=g.filterFrame.width,r.height=g.filterFrame.height,n.bind(g,g.filterFrame,r)}else g!==this.defaultFilterStack[this.defaultFilterStack.length-1].renderTexture?n.bind(g):this.renderer.renderTexture.bind(g,this.activeState.bindingSourceFrame,this.activeState.bindingDestinationFrame);var o=C.stateId&1||this.forceClear;(I===kr.CLEAR||I===kr.BLIT&&o)&&this.renderer.framebuffer.clear(0,0,0,0)},e.prototype.applyFilter=function(g,I,i,n){var C=this.renderer;C.state.set(g.state),this.bindAndClear(i,n),g.uniforms.uSampler=I,g.uniforms.filterGlobals=this.globalUniforms,C.shader.bind(g),g.legacy=!!g.program.attributeData.aTextureCoord,g.legacy?(this.quadUv.map(I._frame,I.filterFrame),C.geometry.bind(this.quadUv),C.geometry.draw(Mr.TRIANGLES)):(C.geometry.bind(this.quad),C.geometry.draw(Mr.TRIANGLE_STRIP))},e.prototype.calculateSpriteMatrix=function(g,I){var i=this.activeState,n=i.sourceFrame,C=i.destinationFrame,r=I._texture.orig,o=g.set(C.width,0,0,C.height,n.x,n.y),A=I.worldTransform.copyTo(fi.TEMP_MATRIX);return A.invert(),o.prepend(A),o.scale(1/r.width,1/r.height),o.translate(I.anchor.x,I.anchor.y),o},e.prototype.destroy=function(){this.renderer=null,this.texturePool.clear(!1)},e.prototype.getOptimalFilterTexture=function(g,I,i,n){return i===void 0&&(i=1),n===void 0&&(n=mI.NONE),this.texturePool.getOptimalTexture(g,I,i,n)},e.prototype.getFilterTexture=function(g,I,i){if(typeof g=="number"){var n=g;g=I,I=n}g=g||this.activeState.renderTexture;var C=this.texturePool.getOptimalTexture(g.width,g.height,I||g.resolution,i||mI.NONE);return C.filterFrame=g.filterFrame,C},e.prototype.returnFilterTexture=function(g){this.texturePool.returnTexture(g)},e.prototype.emptyPool=function(){this.texturePool.clear(!0)},e.prototype.resize=function(){this.texturePool.setScreenSize(this.renderer.view)},e.prototype.transformAABB=function(g,I){var i=gV[0],n=gV[1],C=gV[2],r=gV[3];i.set(I.left,I.top),n.set(I.left,I.bottom),C.set(I.right,I.top),r.set(I.right,I.bottom),g.apply(i,i),g.apply(n,n),g.apply(C,C),g.apply(r,r);var o=Math.min(i.x,n.x,C.x,r.x),A=Math.min(i.y,n.y,C.y,r.y),s=Math.max(i.x,n.x,C.x,r.x),a=Math.max(i.y,n.y,C.y,r.y);I.x=o,I.y=A,I.width=s-o,I.height=a-A},e.prototype.roundFrame=function(g,I,i,n,C){if(!(g.width<=0||g.height<=0||i.width<=0||i.height<=0)){if(C){var r=C.a,o=C.b,A=C.c,s=C.d;if((Math.abs(o)>1e-4||Math.abs(A)>1e-4)&&(Math.abs(r)>1e-4||Math.abs(s)>1e-4))return}C=C?$Y.copyFrom(C):$Y.identity(),C.translate(-i.x,-i.y).scale(n.width/i.width,n.height/i.height).translate(n.x,n.y),this.transformAABB(C,g),g.ceil(I),this.transformAABB(C.invert(),g)}},e}(),rS=function(){function e(g){this.renderer=g}return e.prototype.flush=function(){},e.prototype.destroy=function(){this.renderer=null},e.prototype.start=function(){},e.prototype.stop=function(){this.flush()},e.prototype.render=function(g){},e}(),yL=function(){function e(g){this.renderer=g,this.emptyRenderer=new rS(g),this.currentRenderer=this.emptyRenderer}return e.prototype.setObjectRenderer=function(g){this.currentRenderer!==g&&(this.currentRenderer.stop(),this.currentRenderer=g,this.currentRenderer.start())},e.prototype.flush=function(){this.setObjectRenderer(this.emptyRenderer)},e.prototype.reset=function(){this.setObjectRenderer(this.emptyRenderer)},e.prototype.copyBoundTextures=function(g,I){for(var i=this.renderer.texture.boundTextures,n=I-1;n>=0;--n)g[n]=i[n]||null,g[n]&&(g[n]._batchLocation=n)},e.prototype.boundArray=function(g,I,i,n){for(var C=g.elements,r=g.ids,o=g.count,A=0,s=0;s=0&&l=aa.WEBGL2&&(i=g.getContext("webgl2",I)),i)this.webGLVersion=2;else if(this.webGLVersion=1,i=g.getContext("webgl",I)||g.getContext("experimental-webgl",I),!i)throw new Error("This browser does not support WebGL. Try using the canvas renderer");return this.gl=i,this.getExtensions(),this.gl},e.prototype.getExtensions=function(){var g=this.gl,I={loseContext:g.getExtension("WEBGL_lose_context"),anisotropicFiltering:g.getExtension("EXT_texture_filter_anisotropic"),floatTextureLinear:g.getExtension("OES_texture_float_linear"),s3tc:g.getExtension("WEBGL_compressed_texture_s3tc"),s3tc_sRGB:g.getExtension("WEBGL_compressed_texture_s3tc_srgb"),etc:g.getExtension("WEBGL_compressed_texture_etc"),etc1:g.getExtension("WEBGL_compressed_texture_etc1"),pvrtc:g.getExtension("WEBGL_compressed_texture_pvrtc")||g.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc"),atc:g.getExtension("WEBGL_compressed_texture_atc"),astc:g.getExtension("WEBGL_compressed_texture_astc")};this.webGLVersion===1?Object.assign(this.extensions,I,{drawBuffers:g.getExtension("WEBGL_draw_buffers"),depthTexture:g.getExtension("WEBGL_depth_texture"),vertexArrayObject:g.getExtension("OES_vertex_array_object")||g.getExtension("MOZ_OES_vertex_array_object")||g.getExtension("WEBKIT_OES_vertex_array_object"),uint32ElementIndex:g.getExtension("OES_element_index_uint"),floatTexture:g.getExtension("OES_texture_float"),floatTextureLinear:g.getExtension("OES_texture_float_linear"),textureHalfFloat:g.getExtension("OES_texture_half_float"),textureHalfFloatLinear:g.getExtension("OES_texture_half_float_linear")}):this.webGLVersion===2&&Object.assign(this.extensions,I,{colorBufferFloat:g.getExtension("EXT_color_buffer_float")})},e.prototype.handleContextLost=function(g){var I=this;g.preventDefault(),setTimeout(function(){I.gl.isContextLost()&&I.extensions.loseContext&&I.extensions.loseContext.restoreContext()},0)},e.prototype.handleContextRestored=function(){this.renderer.runners.contextChange.emit(this.gl)},e.prototype.destroy=function(){var g=this.renderer.view;this.renderer=null,g.removeEventListener("webglcontextlost",this.handleContextLost),g.removeEventListener("webglcontextrestored",this.handleContextRestored),this.gl.useProgram(null),this.extensions.loseContext&&this.extensions.loseContext.loseContext()},e.prototype.postrender=function(){this.renderer.renderingToScreen&&this.gl.flush()},e.prototype.validateContext=function(g){var I=g.getContextAttributes(),i="WebGL2RenderingContext"in globalThis&&g instanceof globalThis.WebGL2RenderingContext;i&&(this.webGLVersion=2),I&&!I.stencil&&console.warn("Provided WebGL context does not have a stencil buffer, masks may not render correctly");var n=i||!!g.getExtension("OES_element_index_uint");this.supports.uint32Indices=n,n||console.warn("Provided WebGL context does not support 32 index buffer, complex graphics may not render correctly")},e}(),Lhe=function(){function e(g){this.framebuffer=g,this.stencil=null,this.dirtyId=-1,this.dirtyFormat=-1,this.dirtySize=-1,this.multisample=mI.NONE,this.msaaBuffer=null,this.blitFramebuffer=null,this.mipLevel=0}return e}(),fMe=new vg,GL=function(){function e(g){this.renderer=g,this.managedFramebuffers=[],this.unknownFramebuffer=new qW(10,10),this.msaaSamples=null}return e.prototype.contextChange=function(){this.disposeAll(!0);var g=this.gl=this.renderer.gl;if(this.CONTEXT_UID=this.renderer.CONTEXT_UID,this.current=this.unknownFramebuffer,this.viewport=new vg,this.hasMRT=!0,this.writeDepthTexture=!0,this.renderer.context.webGLVersion===1){var I=this.renderer.context.extensions.drawBuffers,i=this.renderer.context.extensions.depthTexture;yt.PREFER_ENV===aa.WEBGL_LEGACY&&(I=null,i=null),I?g.drawBuffers=function(n){return I.drawBuffersWEBGL(n)}:(this.hasMRT=!1,g.drawBuffers=function(){}),i||(this.writeDepthTexture=!1)}else this.msaaSamples=g.getInternalformatParameter(g.RENDERBUFFER,g.RGBA8,g.SAMPLES)},e.prototype.bind=function(g,I,i){i===void 0&&(i=0);var n=this.gl;if(g){var C=g.glFramebuffers[this.CONTEXT_UID]||this.initFramebuffer(g);this.current!==g&&(this.current=g,n.bindFramebuffer(n.FRAMEBUFFER,C.framebuffer)),C.mipLevel!==i&&(g.dirtyId++,g.dirtyFormat++,C.mipLevel=i),C.dirtyId!==g.dirtyId&&(C.dirtyId=g.dirtyId,C.dirtyFormat!==g.dirtyFormat?(C.dirtyFormat=g.dirtyFormat,C.dirtySize=g.dirtySize,this.updateFramebuffer(g,i)):C.dirtySize!==g.dirtySize&&(C.dirtySize=g.dirtySize,this.resizeFramebuffer(g)));for(var r=0;r>i,s=I.height>>i,a=A/I.width;this.setViewport(I.x*a,I.y*a,A,s)}else{var A=g.width>>i,s=g.height>>i;this.setViewport(0,0,A,s)}}else this.current&&(this.current=null,n.bindFramebuffer(n.FRAMEBUFFER,null)),I?this.setViewport(I.x,I.y,I.width,I.height):this.setViewport(0,0,this.renderer.width,this.renderer.height)},e.prototype.setViewport=function(g,I,i,n){var C=this.viewport;g=Math.round(g),I=Math.round(I),i=Math.round(i),n=Math.round(n),(C.width!==i||C.height!==n||C.x!==g||C.y!==I)&&(C.x=g,C.y=I,C.width=i,C.height=n,this.gl.viewport(g,I,i,n))},Object.defineProperty(e.prototype,"size",{get:function(){return this.current?{x:0,y:0,width:this.current.width,height:this.current.height}:{x:0,y:0,width:this.renderer.width,height:this.renderer.height}},enumerable:!1,configurable:!0}),e.prototype.clear=function(g,I,i,n,C){C===void 0&&(C=Dv.COLOR|Dv.DEPTH);var r=this.gl;r.clearColor(g,I,i,n),r.clear(C)},e.prototype.initFramebuffer=function(g){var I=this.gl,i=new Lhe(I.createFramebuffer());return i.multisample=this.detectSamples(g.multisample),g.glFramebuffers[this.CONTEXT_UID]=i,this.managedFramebuffers.push(g),g.disposeRunner.add(this),i},e.prototype.resizeFramebuffer=function(g){var I=this.gl,i=g.glFramebuffers[this.CONTEXT_UID];i.msaaBuffer&&(I.bindRenderbuffer(I.RENDERBUFFER,i.msaaBuffer),I.renderbufferStorageMultisample(I.RENDERBUFFER,i.multisample,I.RGBA8,g.width,g.height)),i.stencil&&(I.bindRenderbuffer(I.RENDERBUFFER,i.stencil),i.msaaBuffer?I.renderbufferStorageMultisample(I.RENDERBUFFER,i.multisample,I.DEPTH24_STENCIL8,g.width,g.height):I.renderbufferStorage(I.RENDERBUFFER,I.DEPTH_STENCIL,g.width,g.height));var n=g.colorTextures,C=n.length;I.drawBuffers||(C=Math.min(C,1));for(var r=0;r1&&this.canMultisampleFramebuffer(g)?(n.msaaBuffer=n.msaaBuffer||i.createRenderbuffer(),i.bindRenderbuffer(i.RENDERBUFFER,n.msaaBuffer),i.renderbufferStorageMultisample(i.RENDERBUFFER,n.multisample,i.RGBA8,g.width,g.height),i.framebufferRenderbuffer(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0,i.RENDERBUFFER,n.msaaBuffer)):n.msaaBuffer&&(i.deleteRenderbuffer(n.msaaBuffer),n.msaaBuffer=null,n.blitFramebuffer&&(n.blitFramebuffer.dispose(),n.blitFramebuffer=null));for(var o=[],A=0;A1&&i.drawBuffers(o),g.depthTexture){var l=this.writeDepthTexture;if(l){var c=g.depthTexture;this.renderer.texture.bind(c,0),i.framebufferTexture2D(i.FRAMEBUFFER,i.DEPTH_ATTACHMENT,i.TEXTURE_2D,c._glTextures[this.CONTEXT_UID].texture,I)}}(g.stencil||g.depth)&&!(g.depthTexture&&this.writeDepthTexture)?(n.stencil=n.stencil||i.createRenderbuffer(),i.bindRenderbuffer(i.RENDERBUFFER,n.stencil),n.msaaBuffer?i.renderbufferStorageMultisample(i.RENDERBUFFER,n.multisample,i.DEPTH24_STENCIL8,g.width,g.height):i.renderbufferStorage(i.RENDERBUFFER,i.DEPTH_STENCIL,g.width,g.height),i.framebufferRenderbuffer(i.FRAMEBUFFER,i.DEPTH_STENCIL_ATTACHMENT,i.RENDERBUFFER,n.stencil)):n.stencil&&(i.deleteRenderbuffer(n.stencil),n.stencil=null)},e.prototype.canMultisampleFramebuffer=function(g){return this.renderer.context.webGLVersion!==1&&g.colorTextures.length<=1&&!g.depthTexture},e.prototype.detectSamples=function(g){var I=this.msaaSamples,i=mI.NONE;if(g<=1||I===null)return i;for(var n=0;n=0&&this.managedFramebuffers.splice(C,1),g.disposeRunner.remove(this),I||(n.deleteFramebuffer(i.framebuffer),i.msaaBuffer&&n.deleteRenderbuffer(i.msaaBuffer),i.stencil&&n.deleteRenderbuffer(i.stencil)),i.blitFramebuffer&&i.blitFramebuffer.dispose()}},e.prototype.disposeAll=function(g){var I=this.managedFramebuffers;this.managedFramebuffers=[];for(var i=0;i=aa.WEBGL2&&(g=e.getContext("webgl2",{})),g||(g=e.getContext("webgl",{})||e.getContext("experimental-webgl",{}),g?g.getExtension("WEBGL_draw_buffers"):g=null),my=g}return my}var IV;function bMe(){if(!IV){IV=WC.MEDIUM;var e=$he();if(e&&e.getShaderPrecisionFormat){var g=e.getShaderPrecisionFormat(e.FRAGMENT_SHADER,e.HIGH_FLOAT);IV=g.precision?WC.HIGH:WC.MEDIUM}}return IV}function mq(e,g,I){if(e.substring(0,9)!=="precision"){var i=g;return g===WC.HIGH&&I!==WC.HIGH&&(i=WC.MEDIUM),"precision "+i+` float; +`+e}else if(I!==WC.HIGH&&e.substring(0,15)==="precision highp")return e.replace("precision highp","precision mediump");return e}var yMe={float:1,vec2:2,vec3:3,vec4:4,int:1,ivec2:2,ivec3:3,ivec4:4,uint:1,uvec2:2,uvec3:3,uvec4:4,bool:1,bvec2:2,bvec3:3,bvec4:4,mat2:4,mat3:9,mat4:16,sampler2D:1};function qhe(e){return yMe[e]}var iV=null,fq={FLOAT:"float",FLOAT_VEC2:"vec2",FLOAT_VEC3:"vec3",FLOAT_VEC4:"vec4",INT:"int",INT_VEC2:"ivec2",INT_VEC3:"ivec3",INT_VEC4:"ivec4",UNSIGNED_INT:"uint",UNSIGNED_INT_VEC2:"uvec2",UNSIGNED_INT_VEC3:"uvec3",UNSIGNED_INT_VEC4:"uvec4",BOOL:"bool",BOOL_VEC2:"bvec2",BOOL_VEC3:"bvec3",BOOL_VEC4:"bvec4",FLOAT_MAT2:"mat2",FLOAT_MAT3:"mat3",FLOAT_MAT4:"mat4",SAMPLER_2D:"sampler2D",INT_SAMPLER_2D:"sampler2D",UNSIGNED_INT_SAMPLER_2D:"sampler2D",SAMPLER_CUBE:"samplerCube",INT_SAMPLER_CUBE:"samplerCube",UNSIGNED_INT_SAMPLER_CUBE:"samplerCube",SAMPLER_2D_ARRAY:"sampler2DArray",INT_SAMPLER_2D_ARRAY:"sampler2DArray",UNSIGNED_INT_SAMPLER_2D_ARRAY:"sampler2DArray"};function eme(e,g){if(!iV){var I=Object.keys(fq);iV={};for(var i=0;i(g.type==="sampler2D"||g.type==="samplerCube"||g.type==="sampler2DArray")&&g.size===1&&!g.isArray&&(e==null||e.castToBaseTexture!==void 0),code:g=>`t = syncData.textureCount++; + `}},{test:function(e,g){return(e.type==="sampler2D"||e.type==="samplerCube"||e.type==="sampler2DArray")&&e.size===1&&!e.isArray&&(g==null||g.castToBaseTexture!==void 0)},code:function(e){return`t = syncData.textureCount++; - renderer.texture.bind(uv["${g}"], t); + renderer.texture.bind(uv["`+e+`"], t); - if(ud["${g}"].value !== t) + if(ud["`+e+`"].value !== t) { - ud["${g}"].value = t; - gl.uniform1i(ud["${g}"].location, t); + ud["`+e+`"].value = t; + gl.uniform1i(ud["`+e+`"].location, t); ; // eslint-disable-line max-len - }`},{test:(g,e)=>g.type==="mat3"&&g.size===1&&!g.isArray&&e.a!==void 0,code:g=>` - gl.uniformMatrix3fv(ud["${g}"].location, false, uv["${g}"].toArray(true)); - `,codeUbo:g=>` - var ${g}_matrix = uv.${g}.toArray(true); - - data[offset] = ${g}_matrix[0]; - data[offset+1] = ${g}_matrix[1]; - data[offset+2] = ${g}_matrix[2]; + }`}},{test:function(e,g){return e.type==="mat3"&&e.size===1&&!e.isArray&&g.a!==void 0},code:function(e){return` + gl.uniformMatrix3fv(ud["`+e+'"].location, false, uv["'+e+`"].toArray(true)); + `},codeUbo:function(e){return` + var `+e+"_matrix = uv."+e+`.toArray(true); + + data[offset] = `+e+`_matrix[0]; + data[offset+1] = `+e+`_matrix[1]; + data[offset+2] = `+e+`_matrix[2]; - data[offset + 4] = ${g}_matrix[3]; - data[offset + 5] = ${g}_matrix[4]; - data[offset + 6] = ${g}_matrix[5]; + data[offset + 4] = `+e+`_matrix[3]; + data[offset + 5] = `+e+`_matrix[4]; + data[offset + 6] = `+e+`_matrix[5]; - data[offset + 8] = ${g}_matrix[6]; - data[offset + 9] = ${g}_matrix[7]; - data[offset + 10] = ${g}_matrix[8]; - `},{test:(g,e)=>g.type==="vec2"&&g.size===1&&!g.isArray&&e.x!==void 0,code:g=>` - cv = ud["${g}"].value; - v = uv["${g}"]; + data[offset + 8] = `+e+`_matrix[6]; + data[offset + 9] = `+e+`_matrix[7]; + data[offset + 10] = `+e+`_matrix[8]; + `}},{test:function(e,g){return e.type==="vec2"&&e.size===1&&!e.isArray&&g.x!==void 0},code:function(e){return` + cv = ud["`+e+`"].value; + v = uv["`+e+`"]; if(cv[0] !== v.x || cv[1] !== v.y) { cv[0] = v.x; cv[1] = v.y; - gl.uniform2f(ud["${g}"].location, v.x, v.y); - }`,codeUbo:g=>` - v = uv.${g}; + gl.uniform2f(ud["`+e+`"].location, v.x, v.y); + }`},codeUbo:function(e){return` + v = uv.`+e+`; data[offset] = v.x; data[offset+1] = v.y; - `},{test:g=>g.type==="vec2"&&g.size===1&&!g.isArray,code:g=>` - cv = ud["${g}"].value; - v = uv["${g}"]; + `}},{test:function(e){return e.type==="vec2"&&e.size===1&&!e.isArray},code:function(e){return` + cv = ud["`+e+`"].value; + v = uv["`+e+`"]; if(cv[0] !== v[0] || cv[1] !== v[1]) { cv[0] = v[0]; cv[1] = v[1]; - gl.uniform2f(ud["${g}"].location, v[0], v[1]); + gl.uniform2f(ud["`+e+`"].location, v[0], v[1]); } - `},{test:(g,e)=>g.type==="vec4"&&g.size===1&&!g.isArray&&e.width!==void 0,code:g=>` - cv = ud["${g}"].value; - v = uv["${g}"]; + `}},{test:function(e,g){return e.type==="vec4"&&e.size===1&&!e.isArray&&g.width!==void 0},code:function(e){return` + cv = ud["`+e+`"].value; + v = uv["`+e+`"]; if(cv[0] !== v.x || cv[1] !== v.y || cv[2] !== v.width || cv[3] !== v.height) { @@ -130,52 +221,17 @@ void main(void){ cv[1] = v.y; cv[2] = v.width; cv[3] = v.height; - gl.uniform4f(ud["${g}"].location, v.x, v.y, v.width, v.height) - }`,codeUbo:g=>` - v = uv.${g}; + gl.uniform4f(ud["`+e+`"].location, v.x, v.y, v.width, v.height) + }`},codeUbo:function(e){return` + v = uv.`+e+`; data[offset] = v.x; data[offset+1] = v.y; data[offset+2] = v.width; data[offset+3] = v.height; - `},{test:(g,e)=>g.type==="vec4"&&g.size===1&&!g.isArray&&e.red!==void 0,code:g=>` - cv = ud["${g}"].value; - v = uv["${g}"]; - - if(cv[0] !== v.red || cv[1] !== v.green || cv[2] !== v.blue || cv[3] !== v.alpha) - { - cv[0] = v.red; - cv[1] = v.green; - cv[2] = v.blue; - cv[3] = v.alpha; - gl.uniform4f(ud["${g}"].location, v.red, v.green, v.blue, v.alpha) - }`,codeUbo:g=>` - v = uv.${g}; - - data[offset] = v.red; - data[offset+1] = v.green; - data[offset+2] = v.blue; - data[offset+3] = v.alpha; - `},{test:(g,e)=>g.type==="vec3"&&g.size===1&&!g.isArray&&e.red!==void 0,code:g=>` - cv = ud["${g}"].value; - v = uv["${g}"]; - - if(cv[0] !== v.red || cv[1] !== v.green || cv[2] !== v.blue || cv[3] !== v.a) - { - cv[0] = v.red; - cv[1] = v.green; - cv[2] = v.blue; - - gl.uniform3f(ud["${g}"].location, v.red, v.green, v.blue) - }`,codeUbo:g=>` - v = uv.${g}; - - data[offset] = v.red; - data[offset+1] = v.green; - data[offset+2] = v.blue; - `},{test:g=>g.type==="vec4"&&g.size===1&&!g.isArray,code:g=>` - cv = ud["${g}"].value; - v = uv["${g}"]; + `}},{test:function(e){return e.type==="vec4"&&e.size===1&&!e.isArray},code:function(e){return` + cv = ud["`+e+`"].value; + v = uv["`+e+`"]; if(cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2] || cv[3] !== v[3]) { @@ -184,8 +240,8 @@ void main(void){ cv[2] = v[2]; cv[3] = v[3]; - gl.uniform4f(ud["${g}"].location, v[0], v[1], v[2], v[3]) - }`}],FFe={float:` + gl.uniform4f(ud["`+e+`"].location, v[0], v[1], v[2], v[3]) + }`}}],ZMe={float:` if (cv !== v) { cu.value = v; @@ -321,74 +377,50 @@ void main(void){ cu.value = v; gl.uniform1i(location, v); - }`},EFe={float:"gl.uniform1fv(location, v)",vec2:"gl.uniform2fv(location, v)",vec3:"gl.uniform3fv(location, v)",vec4:"gl.uniform4fv(location, v)",mat4:"gl.uniformMatrix4fv(location, false, v)",mat3:"gl.uniformMatrix3fv(location, false, v)",mat2:"gl.uniformMatrix2fv(location, false, v)",int:"gl.uniform1iv(location, v)",ivec2:"gl.uniform2iv(location, v)",ivec3:"gl.uniform3iv(location, v)",ivec4:"gl.uniform4iv(location, v)",uint:"gl.uniform1uiv(location, v)",uvec2:"gl.uniform2uiv(location, v)",uvec3:"gl.uniform3uiv(location, v)",uvec4:"gl.uniform4uiv(location, v)",bool:"gl.uniform1iv(location, v)",bvec2:"gl.uniform2iv(location, v)",bvec3:"gl.uniform3iv(location, v)",bvec4:"gl.uniform4iv(location, v)",sampler2D:"gl.uniform1iv(location, v)",samplerCube:"gl.uniform1iv(location, v)",sampler2DArray:"gl.uniform1iv(location, v)"};function MFe(g,e){var i;const I=[` + }`},GMe={float:"gl.uniform1fv(location, v)",vec2:"gl.uniform2fv(location, v)",vec3:"gl.uniform3fv(location, v)",vec4:"gl.uniform4fv(location, v)",mat4:"gl.uniformMatrix4fv(location, false, v)",mat3:"gl.uniformMatrix3fv(location, false, v)",mat2:"gl.uniformMatrix2fv(location, false, v)",int:"gl.uniform1iv(location, v)",ivec2:"gl.uniform2iv(location, v)",ivec3:"gl.uniform3iv(location, v)",ivec4:"gl.uniform4iv(location, v)",uint:"gl.uniform1uiv(location, v)",uvec2:"gl.uniform2uiv(location, v)",uvec3:"gl.uniform3uiv(location, v)",uvec4:"gl.uniform4uiv(location, v)",bool:"gl.uniform1iv(location, v)",bvec2:"gl.uniform2iv(location, v)",bvec3:"gl.uniform3iv(location, v)",bvec4:"gl.uniform4iv(location, v)",sampler2D:"gl.uniform1iv(location, v)",samplerCube:"gl.uniform1iv(location, v)",sampler2DArray:"gl.uniform1iv(location, v)"};function vMe(e,g){var I,i=[` var v = null; var cv = null; var cu = null; var t = 0; var gl = renderer.gl; - `];for(const n in g.uniforms){const C=e[n];if(!C){((i=g.uniforms[n])==null?void 0:i.group)===!0&&(g.uniforms[n].ubo?I.push(` - renderer.shader.syncUniformBufferGroup(uv.${n}, '${n}'); - `):I.push(` - renderer.shader.syncUniformGroup(uv.${n}, syncData); - `));continue}const r=g.uniforms[n];let o=!1;for(let A=0;A=su.WEBGL2&&(e=g.getContext("webgl2",{})),e||(e=g.getContext("webgl",{})||g.getContext("experimental-webgl",{}),e?e.getExtension("WEBGL_draw_buffers"):e=null),Dm=e}return Dm}let NV;function zFe(){if(!NV){NV=sr.MEDIUM;const g=Hme();if(g&&g.getShaderPrecisionFormat){const e=g.getShaderPrecisionFormat(g.FRAGMENT_SHADER,g.HIGH_FLOAT);e&&(NV=e.precision?sr.HIGH:sr.MEDIUM)}}return NV}function qq(g,e){const I=g.getShaderSource(e).split(` -`).map((s,a)=>`${a}: ${s}`),i=g.getShaderInfoLog(e),n=i.split(` -`),C={},r=n.map(s=>parseFloat(s.replace(/^ERROR\: 0\:([\d]+)\:.*$/,"$1"))).filter(s=>s&&!C[s]?(C[s]=!0,!0):!1),o=[""];r.forEach(s=>{I[s-1]=`%c${I[s-1]}%c`,o.push("background: #FF0000; color:#FFFFFF; font-size: 10px","font-size: 10px")});const A=I.join(` -`);o[0]=A,console.error(i),console.groupCollapsed("click to view full shader code"),console.warn(...o),console.groupEnd()}function PFe(g,e,I,i){g.getProgramParameter(e,g.LINK_STATUS)||(g.getShaderParameter(I,g.COMPILE_STATUS)||qq(g,I),g.getShaderParameter(i,g.COMPILE_STATUS)||qq(g,i),console.error("PixiJS Error: Could not initialize shader."),g.getProgramInfoLog(e)!==""&&console.warn("PixiJS Warning: gl.getProgramInfoLog()",g.getProgramInfoLog(e)))}const JFe={float:1,vec2:2,vec3:3,vec4:4,int:1,ivec2:2,ivec3:3,ivec4:4,uint:1,uvec2:2,uvec3:3,uvec4:4,bool:1,bvec2:2,bvec3:3,bvec4:4,mat2:4,mat3:9,mat4:16,sampler2D:1};function Tme(g){return JFe[g]}let kV=null;const eee={FLOAT:"float",FLOAT_VEC2:"vec2",FLOAT_VEC3:"vec3",FLOAT_VEC4:"vec4",INT:"int",INT_VEC2:"ivec2",INT_VEC3:"ivec3",INT_VEC4:"ivec4",UNSIGNED_INT:"uint",UNSIGNED_INT_VEC2:"uvec2",UNSIGNED_INT_VEC3:"uvec3",UNSIGNED_INT_VEC4:"uvec4",BOOL:"bool",BOOL_VEC2:"bvec2",BOOL_VEC3:"bvec3",BOOL_VEC4:"bvec4",FLOAT_MAT2:"mat2",FLOAT_MAT3:"mat3",FLOAT_MAT4:"mat4",SAMPLER_2D:"sampler2D",INT_SAMPLER_2D:"sampler2D",UNSIGNED_INT_SAMPLER_2D:"sampler2D",SAMPLER_CUBE:"samplerCube",INT_SAMPLER_CUBE:"samplerCube",UNSIGNED_INT_SAMPLER_CUBE:"samplerCube",SAMPLER_2D_ARRAY:"sampler2DArray",INT_SAMPLER_2D_ARRAY:"sampler2DArray",UNSIGNED_INT_SAMPLER_2D_ARRAY:"sampler2DArray"};function Nme(g,e){if(!kV){const I=Object.keys(eee);kV={};for(let i=0;i0&&(I+=` -else `),i0&&(g+=` +else `),Ithis.size&&this.flush(),this._vertexCount+=e.vertexData.length/2,this._indexCount+=e.indices.length,this._bufferedTextures[this._bufferSize]=e._texture.baseTexture,this._bufferedElements[this._bufferSize++]=e)}buildTexturesAndDrawCalls(){const{_bufferedTextures:e,maxTextures:I}=this,i=Ko._textureArrayPool,n=this.renderer.batch,C=this._tempBoundTextures,r=this.renderer.textureGC.count;let o=++ng._globalBatch,A=0,s=i[0],a=0;n.copyBoundTextures(C,I);for(let l=0;l=I&&(n.boundArray(s,C,o,I),this.buildDrawCalls(s,a,l),a=l,s=i[++A],++o),c._batchEnabled=o,c.touched=r,s.elements[s.count++]=c)}s.count>0&&(n.boundArray(s,C,o,I),this.buildDrawCalls(s,a,this._bufferSize),++A,++o);for(let l=0;l0);for(let h=0;h=0;--n)e[n]=i[n]||null,e[n]&&(e[n]._batchLocation=n)}boundArray(e,I,i,n){const{elements:C,ids:r,count:o}=e;let A=0;for(let s=0;s=0&&l=su.WEBGL2&&(i=e.getContext("webgl2",I)),i)this.webGLVersion=2;else if(this.webGLVersion=1,i=e.getContext("webgl",I)||e.getContext("experimental-webgl",I),!i)throw new Error("This browser does not support WebGL. Try using the canvas renderer");return this.gl=i,this.getExtensions(),this.gl}getExtensions(){const{gl:e}=this,I={loseContext:e.getExtension("WEBGL_lose_context"),anisotropicFiltering:e.getExtension("EXT_texture_filter_anisotropic"),floatTextureLinear:e.getExtension("OES_texture_float_linear"),s3tc:e.getExtension("WEBGL_compressed_texture_s3tc"),s3tc_sRGB:e.getExtension("WEBGL_compressed_texture_s3tc_srgb"),etc:e.getExtension("WEBGL_compressed_texture_etc"),etc1:e.getExtension("WEBGL_compressed_texture_etc1"),pvrtc:e.getExtension("WEBGL_compressed_texture_pvrtc")||e.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc"),atc:e.getExtension("WEBGL_compressed_texture_atc"),astc:e.getExtension("WEBGL_compressed_texture_astc")};this.webGLVersion===1?Object.assign(this.extensions,I,{drawBuffers:e.getExtension("WEBGL_draw_buffers"),depthTexture:e.getExtension("WEBGL_depth_texture"),vertexArrayObject:e.getExtension("OES_vertex_array_object")||e.getExtension("MOZ_OES_vertex_array_object")||e.getExtension("WEBKIT_OES_vertex_array_object"),uint32ElementIndex:e.getExtension("OES_element_index_uint"),floatTexture:e.getExtension("OES_texture_float"),floatTextureLinear:e.getExtension("OES_texture_float_linear"),textureHalfFloat:e.getExtension("OES_texture_half_float"),textureHalfFloatLinear:e.getExtension("OES_texture_half_float_linear")}):this.webGLVersion===2&&Object.assign(this.extensions,I,{colorBufferFloat:e.getExtension("EXT_color_buffer_float")})}handleContextLost(e){e.preventDefault(),setTimeout(()=>{this.gl.isContextLost()&&this.extensions.loseContext&&this.extensions.loseContext.restoreContext()},0)}handleContextRestored(){this.renderer.runners.contextChange.emit(this.gl)}destroy(){const e=this.renderer.view;this.renderer=null,e.removeEventListener!==void 0&&(e.removeEventListener("webglcontextlost",this.handleContextLost),e.removeEventListener("webglcontextrestored",this.handleContextRestored)),this.gl.useProgram(null),this.extensions.loseContext&&this.extensions.loseContext.loseContext()}postrender(){this.renderer.objectRenderer.renderingToScreen&&this.gl.flush()}validateContext(e){const I=e.getContextAttributes(),i="WebGL2RenderingContext"in globalThis&&e instanceof globalThis.WebGL2RenderingContext;i&&(this.webGLVersion=2),I&&!I.stencil&&console.warn("Provided WebGL context does not have a stencil buffer, masks may not render correctly");const n=i||!!e.getExtension("OES_element_index_uint");this.supports.uint32Indices=n,n||console.warn("Provided WebGL context does not support 32 index buffer, complex graphics may not render correctly")}}hv.defaultOptions={context:null,antialias:!1,premultipliedAlpha:!0,preserveDrawingBuffer:!1,powerPreference:"default"},hv.extension={type:pt.RendererSystem,name:"context"};kt.add(hv);class DX{constructor(e,I){if(this.width=Math.round(e),this.height=Math.round(I),!this.width||!this.height)throw new Error("Framebuffer width or height is zero");this.stencil=!1,this.depth=!1,this.dirtyId=0,this.dirtyFormat=0,this.dirtySize=0,this.depthTexture=null,this.colorTextures=[],this.glFramebuffers={},this.disposeRunner=new dr("disposeFramebuffer"),this.multisample=Ci.NONE}get colorTexture(){return this.colorTextures[0]}addColorTexture(e=0,I){return this.colorTextures[e]=I||new ng(null,{scaleMode:Ca.NEAREST,resolution:1,mipmap:uA.OFF,width:this.width,height:this.height}),this.dirtyId++,this.dirtyFormat++,this}addDepthTexture(e){return this.depthTexture=e||new ng(null,{scaleMode:Ca.NEAREST,resolution:1,width:this.width,height:this.height,mipmap:uA.OFF,format:st.DEPTH_COMPONENT,type:Mt.UNSIGNED_SHORT}),this.dirtyId++,this.dirtyFormat++,this}enableDepth(){return this.depth=!0,this.dirtyId++,this.dirtyFormat++,this}enableStencil(){return this.stencil=!0,this.dirtyId++,this.dirtyFormat++,this}resize(e,I){if(e=Math.round(e),I=Math.round(I),!e||!I)throw new Error("Framebuffer width and height must not be zero");if(!(e===this.width&&I===this.height)){this.width=e,this.height=I,this.dirtyId++,this.dirtySize++;for(let i=0;i{const n=this.source;this.url=n.src;const C=()=>{this.destroyed||(n.onload=null,n.onerror=null,this.update(),this._load=null,this.createBitmap?I(this.process()):I(this))};n.complete&&n.src?C():(n.onload=C,n.onerror=r=>{i(r),this.onError.emit(r)})}),this._load)}process(){const e=this.source;if(this._process!==null)return this._process;if(this.bitmap!==null||!globalThis.createImageBitmap)return Promise.resolve(this);const I=globalThis.createImageBitmap,i=!e.crossOrigin||e.crossOrigin==="anonymous";return this._process=fetch(e.src,{mode:i?"cors":"no-cors"}).then(n=>n.blob()).then(n=>I(n,0,0,e.width,e.height,{premultiplyAlpha:this.alphaMode===null||this.alphaMode===tC.UNPACK?"premultiply":"none"})).then(n=>this.destroyed?Promise.reject():(this.bitmap=n,this.update(),this._process=null,Promise.resolve(this))),this._process}upload(e,I,i){if(typeof this.alphaMode=="number"&&(I.alphaMode=this.alphaMode),!this.createBitmap)return super.upload(e,I,i);if(!this.bitmap&&(this.process(),!this.bitmap))return!1;if(super.upload(e,I,i,this.bitmap),!this.preserveBitmap){let n=!0;const C=I._glTextures;for(const r in C){const o=C[r];if(o!==i&&o.dirtyId!==I.dirtyId){n=!1;break}}n&&(this.bitmap.close&&this.bitmap.close(),this.bitmap=null)}return!0}dispose(){this.source.onload=null,this.source.onerror=null,super.dispose(),this.bitmap&&(this.bitmap.close(),this.bitmap=null),this._process=null,this._load=null}static test(e){return typeof HTMLImageElement<"u"&&(typeof e=="string"||e instanceof HTMLImageElement)}}class KT{constructor(){this.x0=0,this.y0=0,this.x1=1,this.y1=0,this.x2=1,this.y2=1,this.x3=0,this.y3=1,this.uvsFloat32=new Float32Array(8)}set(e,I,i){const n=I.width,C=I.height;if(i){const r=e.width/2/n,o=e.height/2/C,A=e.x/n+r,s=e.y/C+o;i=VI.add(i,VI.NW),this.x0=A+r*VI.uX(i),this.y0=s+o*VI.uY(i),i=VI.add(i,2),this.x1=A+r*VI.uX(i),this.y1=s+o*VI.uY(i),i=VI.add(i,2),this.x2=A+r*VI.uX(i),this.y2=s+o*VI.uY(i),i=VI.add(i,2),this.x3=A+r*VI.uX(i),this.y3=s+o*VI.uY(i)}else this.x0=e.x/n,this.y0=e.y/C,this.x1=(e.x+e.width)/n,this.y1=e.y/C,this.x2=(e.x+e.width)/n,this.y2=(e.y+e.height)/C,this.x3=e.x/n,this.y3=(e.y+e.height)/C;this.uvsFloat32[0]=this.x0,this.uvsFloat32[1]=this.y0,this.uvsFloat32[2]=this.x1,this.uvsFloat32[3]=this.y1,this.uvsFloat32[4]=this.x2,this.uvsFloat32[5]=this.y2,this.uvsFloat32[6]=this.x3,this.uvsFloat32[7]=this.y3}}KT.prototype.toString=function(){return`[@pixi/core:TextureUvs x0=${this.x0} y0=${this.y0} x1=${this.x1} y1=${this.y1} x2=${this.x2} y2=${this.y2} x3=${this.x3} y3=${this.y3}]`};const Iee=new KT;function KV(g){g.destroy=function(){},g.on=function(){},g.once=function(){},g.emit=function(){}}class Bt extends T0{constructor(e,I,i,n,C,r,o){if(super(),this.noFrame=!1,I||(this.noFrame=!0,I=new rg(0,0,1,1)),e instanceof Bt&&(e=e.baseTexture),this.baseTexture=e,this._frame=I,this.trim=n,this.valid=!1,this.destroyed=!1,this._uvs=Iee,this.uvMatrix=null,this.orig=i||I,this._rotate=Number(C||0),C===!0)this._rotate=2;else if(this._rotate%2!==0)throw new Error("attempt to use diamond-shaped UVs. If you are sure, set rotation manually");this.defaultAnchor=r?new Gg(r.x,r.y):new Gg(0,0),this.defaultBorders=o,this._updateID=0,this.textureCacheIds=[],e.valid?this.noFrame?e.valid&&this.onBaseTextureUpdated(e):this.frame=I:e.once("loaded",this.onBaseTextureUpdated,this),this.noFrame&&e.on("update",this.onBaseTextureUpdated,this)}update(){this.baseTexture.resource&&this.baseTexture.resource.update()}onBaseTextureUpdated(e){if(this.noFrame){if(!this.baseTexture.valid)return;this._frame.width=e.width,this._frame.height=e.height,this.valid=!0,this.updateUvs()}else this.frame=this._frame;this.emit("update",this)}destroy(e){if(this.baseTexture){if(e){const{resource:I}=this.baseTexture;I!=null&&I.url&&On[I.url]&&Bt.removeFromCache(I.url),this.baseTexture.destroy()}this.baseTexture.off("loaded",this.onBaseTextureUpdated,this),this.baseTexture.off("update",this.onBaseTextureUpdated,this),this.baseTexture=null}this._frame=null,this._uvs=null,this.trim=null,this.orig=null,this.valid=!1,Bt.removeFromCache(this),this.textureCacheIds=null,this.destroyed=!0,this.emit("destroyed",this),this.removeAllListeners()}clone(){var n;const e=this._frame.clone(),I=this._frame===this.orig?e:this.orig.clone(),i=new Bt(this.baseTexture,!this.noFrame&&e,I,(n=this.trim)==null?void 0:n.clone(),this.rotate,this.defaultAnchor,this.defaultBorders);return this.noFrame&&(i._frame=e),i}updateUvs(){this._uvs===Iee&&(this._uvs=new KT),this._uvs.set(this._frame,this.baseTexture,this.rotate),this._updateID++}static from(e,I={},i=Gt.STRICT_TEXTURE_CACHE){const n=typeof e=="string";let C=null;if(n)C=e;else if(e instanceof ng){if(!e.cacheId){const o=(I==null?void 0:I.pixiIdPrefix)||"pixiid";e.cacheId=`${o}-${gu()}`,ng.addToCache(e,e.cacheId)}C=e.cacheId}else{if(!e._pixiId){const o=(I==null?void 0:I.pixiIdPrefix)||"pixiid";e._pixiId=`${o}_${gu()}`}C=e._pixiId}let r=On[C];if(n&&i&&!r)throw new Error(`The cacheId "${C}" does not exist in TextureCache.`);return!r&&!(e instanceof ng)?(I.resolution||(I.resolution=Ga(e)),r=new Bt(new ng(e,I)),r.baseTexture.cacheId=C,ng.addToCache(r.baseTexture,C),Bt.addToCache(r,C)):!r&&e instanceof ng&&(r=new Bt(e),Bt.addToCache(r,C)),r}static fromURL(e,I){const i=Object.assign({autoLoad:!1},I==null?void 0:I.resourceOptions),n=Bt.from(e,Object.assign({resourceOptions:i},I),!1),C=n.baseTexture.resource;return n.baseTexture.valid?Promise.resolve(n):C.load().then(()=>Promise.resolve(n))}static fromBuffer(e,I,i,n){return new Bt(ng.fromBuffer(e,I,i,n))}static fromLoader(e,I,i,n){const C=new ng(e,Object.assign({scaleMode:ng.defaultOptions.scaleMode,resolution:Ga(I)},n)),{resource:r}=C;r instanceof O_&&(r.url=I);const o=new Bt(C);return i||(i=I),ng.addToCache(o.baseTexture,i),Bt.addToCache(o,i),i!==I&&(ng.addToCache(o.baseTexture,I),Bt.addToCache(o,I)),o.baseTexture.valid?Promise.resolve(o):new Promise(A=>{o.baseTexture.once("loaded",()=>A(o))})}static addToCache(e,I){I&&(e.textureCacheIds.includes(I)||e.textureCacheIds.push(I),On[I]&&On[I]!==e&&console.warn(`Texture added to the cache with an id [${I}] that already had an entry`),On[I]=e)}static removeFromCache(e){if(typeof e=="string"){const I=On[e];if(I){const i=I.textureCacheIds.indexOf(e);return i>-1&&I.textureCacheIds.splice(i,1),delete On[e],I}}else if(e!=null&&e.textureCacheIds){for(let I=0;Ithis.baseTexture.width,o=i+C>this.baseTexture.height;if(r||o){const A=r&&o?"and":"or",s=`X: ${I} + ${n} = ${I+n} > ${this.baseTexture.width}`,a=`Y: ${i} + ${C} = ${i+C} > ${this.baseTexture.height}`;throw new Error(`Texture Error: frame does not fit inside the base Texture dimensions: ${s} ${A} ${a}`)}this.valid=n&&C&&this.baseTexture.valid,!this.trim&&!this.rotate&&(this.orig=e),this.valid&&this.updateUvs()}get rotate(){return this._rotate}set rotate(e){this._rotate=e,this.valid&&this.updateUvs()}get width(){return this.orig.width}get height(){return this.orig.height}castToBaseTexture(){return this.baseTexture}static get EMPTY(){return Bt._EMPTY||(Bt._EMPTY=new Bt(new ng),KV(Bt._EMPTY),KV(Bt._EMPTY.baseTexture)),Bt._EMPTY}static get WHITE(){if(!Bt._WHITE){const e=Gt.ADAPTER.createCanvas(16,16),I=e.getContext("2d");e.width=16,e.height=16,I.fillStyle="white",I.fillRect(0,0,16,16),Bt._WHITE=new Bt(ng.from(e)),KV(Bt._WHITE),KV(Bt._WHITE.baseTexture)}return Bt._WHITE}}class il extends Bt{constructor(e,I){super(e,I),this.valid=!0,this.filterFrame=null,this.filterPoolKey=null,this.updateUvs()}get framebuffer(){return this.baseTexture.framebuffer}get multisample(){return this.framebuffer.multisample}set multisample(e){this.framebuffer.multisample=e}resize(e,I,i=!0){const n=this.baseTexture.resolution,C=Math.round(e*n)/n,r=Math.round(I*n)/n;this.valid=C>0&&r>0,this._frame.width=this.orig.width=C,this._frame.height=this.orig.height=r,i&&this.baseTexture.resize(C,r),this.updateUvs()}setResolution(e){const{baseTexture:I}=this;I.resolution!==e&&(I.setResolution(e),this.resize(I.width,I.height,!1))}static create(e){return new il(new J_(e))}}class L_{constructor(e){this.texturePool={},this.textureOptions=e||{},this.enableFullScreen=!1,this._pixelsWidth=0,this._pixelsHeight=0}createTexture(e,I,i=Ci.NONE){const n=new J_(Object.assign({width:e,height:I,resolution:1,multisample:i},this.textureOptions));return new il(n)}getOptimalTexture(e,I,i=1,n=Ci.NONE){let C;e=Math.max(Math.ceil(e*i-1e-6),1),I=Math.max(Math.ceil(I*i-1e-6),1),!this.enableFullScreen||e!==this._pixelsWidth||I!==this._pixelsHeight?(e=lv(e),I=lv(I),C=((e&65535)<<16|I&65535)>>>0,n>1&&(C+=n*4294967296)):C=n>1?-n:-1,this.texturePool[C]||(this.texturePool[C]=[]);let r=this.texturePool[C].pop();return r||(r=this.createTexture(e,I,n)),r.filterPoolKey=C,r.setResolution(i),r}getFilterTexture(e,I,i){const n=this.getOptimalTexture(e.width,e.height,I||e.resolution,i||Ci.NONE);return n.filterFrame=e.filterFrame,n}returnTexture(e){const I=e.filterPoolKey;e.filterFrame=null,this.texturePool[I].push(e)}returnFilterTexture(e){this.returnTexture(e)}clear(e){if(e=e!==!1,e)for(const I in this.texturePool){const i=this.texturePool[I];if(i)for(let n=0;n0&&e.height>0;for(const I in this.texturePool){if(!(Number(I)<0))continue;const i=this.texturePool[I];if(i)for(let n=0;n1&&(a=this.getOptimalFilterTexture(s.width,s.height,I.resolution),a.filterFrame=s.filterFrame),i[l].apply(this,s,a,Oo.CLEAR,I);const c=s;s=a,a=c}i[l].apply(this,s,A.renderTexture,Oo.BLEND,I),l>1&&I.multisample>1&&this.returnFilterTexture(I.renderTexture),this.returnFilterTexture(s),this.returnFilterTexture(a)}I.clear(),this.statePool.push(I)}bindAndClear(e,I=Oo.CLEAR){const{renderTexture:i,state:n}=this.renderer;if(e===this.defaultFilterStack[this.defaultFilterStack.length-1].renderTexture?this.renderer.projection.transform=this.activeState.transform:this.renderer.projection.transform=null,e==null?void 0:e.filterFrame){const r=this.tempRect;r.x=0,r.y=0,r.width=e.filterFrame.width,r.height=e.filterFrame.height,i.bind(e,e.filterFrame,r)}else e!==this.defaultFilterStack[this.defaultFilterStack.length-1].renderTexture?i.bind(e):this.renderer.renderTexture.bind(e,this.activeState.bindingSourceFrame,this.activeState.bindingDestinationFrame);const C=n.stateId&1||this.forceClear;(I===Oo.CLEAR||I===Oo.BLIT&&C)&&this.renderer.framebuffer.clear(0,0,0,0)}applyFilter(e,I,i,n){const C=this.renderer;C.state.set(e.state),this.bindAndClear(i,n),e.uniforms.uSampler=I,e.uniforms.filterGlobals=this.globalUniforms,C.shader.bind(e),e.legacy=!!e.program.attributeData.aTextureCoord,e.legacy?(this.quadUv.map(I._frame,I.filterFrame),C.geometry.bind(this.quadUv),C.geometry.draw(qo.TRIANGLES)):(C.geometry.bind(this.quad),C.geometry.draw(qo.TRIANGLE_STRIP))}calculateSpriteMatrix(e,I){const{sourceFrame:i,destinationFrame:n}=this.activeState,{orig:C}=I._texture,r=e.set(n.width,0,0,n.height,i.x,i.y),o=I.worldTransform.copyTo(sI.TEMP_MATRIX);return o.invert(),r.prepend(o),r.scale(1/C.width,1/C.height),r.translate(I.anchor.x,I.anchor.y),r}destroy(){this.renderer=null,this.texturePool.clear(!1)}getOptimalFilterTexture(e,I,i=1,n=Ci.NONE){return this.texturePool.getOptimalTexture(e,I,i,n)}getFilterTexture(e,I,i){if(typeof e=="number"){const C=e;e=I,I=C}e=e||this.activeState.renderTexture;const n=this.texturePool.getOptimalTexture(e.width,e.height,I||e.resolution,i||Ci.NONE);return n.filterFrame=e.filterFrame,n}returnFilterTexture(e){this.texturePool.returnTexture(e)}emptyPool(){this.texturePool.clear(!0)}resize(){this.texturePool.setScreenSize(this.renderer.view)}transformAABB(e,I){const i=xV[0],n=xV[1],C=xV[2],r=xV[3];i.set(I.left,I.top),n.set(I.left,I.bottom),C.set(I.right,I.top),r.set(I.right,I.bottom),e.apply(i,i),e.apply(n,n),e.apply(C,C),e.apply(r,r);const o=Math.min(i.x,n.x,C.x,r.x),A=Math.min(i.y,n.y,C.y,r.y),s=Math.max(i.x,n.x,C.x,r.x),a=Math.max(i.y,n.y,C.y,r.y);I.x=o,I.y=A,I.width=s-o,I.height=a-A}roundFrame(e,I,i,n,C){if(!(e.width<=0||e.height<=0||i.width<=0||i.height<=0)){if(C){const{a:r,b:o,c:A,d:s}=C;if((Math.abs(o)>1e-4||Math.abs(A)>1e-4)&&(Math.abs(r)>1e-4||Math.abs(s)>1e-4))return}C=C?jK.copyFrom(C):jK.identity(),C.translate(-i.x,-i.y).scale(n.width/i.width,n.height/i.height).translate(n.x,n.y),this.transformAABB(C,e),e.ceil(I),this.transformAABB(C.invert(),e)}}}U_.extension={type:pt.RendererSystem,name:"filter"};kt.add(U_);class Dme{constructor(e){this.framebuffer=e,this.stencil=null,this.dirtyId=-1,this.dirtyFormat=-1,this.dirtySize=-1,this.multisample=Ci.NONE,this.msaaBuffer=null,this.blitFramebuffer=null,this.mipLevel=0}}const eEe=new rg;class Q_{constructor(e){this.renderer=e,this.managedFramebuffers=[],this.unknownFramebuffer=new DX(10,10),this.msaaSamples=null}contextChange(){this.disposeAll(!0);const e=this.gl=this.renderer.gl;if(this.CONTEXT_UID=this.renderer.CONTEXT_UID,this.current=this.unknownFramebuffer,this.viewport=new rg,this.hasMRT=!0,this.writeDepthTexture=!0,this.renderer.context.webGLVersion===1){let I=this.renderer.context.extensions.drawBuffers,i=this.renderer.context.extensions.depthTexture;Gt.PREFER_ENV===su.WEBGL_LEGACY&&(I=null,i=null),I?e.drawBuffers=n=>I.drawBuffersWEBGL(n):(this.hasMRT=!1,e.drawBuffers=()=>{}),i||(this.writeDepthTexture=!1)}else this.msaaSamples=e.getInternalformatParameter(e.RENDERBUFFER,e.RGBA8,e.SAMPLES)}bind(e,I,i=0){const{gl:n}=this;if(e){const C=e.glFramebuffers[this.CONTEXT_UID]||this.initFramebuffer(e);this.current!==e&&(this.current=e,n.bindFramebuffer(n.FRAMEBUFFER,C.framebuffer)),C.mipLevel!==i&&(e.dirtyId++,e.dirtyFormat++,C.mipLevel=i),C.dirtyId!==e.dirtyId&&(C.dirtyId=e.dirtyId,C.dirtyFormat!==e.dirtyFormat?(C.dirtyFormat=e.dirtyFormat,C.dirtySize=e.dirtySize,this.updateFramebuffer(e,i)):C.dirtySize!==e.dirtySize&&(C.dirtySize=e.dirtySize,this.resizeFramebuffer(e)));for(let r=0;r>i,o=I.height>>i,A=r/I.width;this.setViewport(I.x*A,I.y*A,r,o)}else{const r=e.width>>i,o=e.height>>i;this.setViewport(0,0,r,o)}}else this.current&&(this.current=null,n.bindFramebuffer(n.FRAMEBUFFER,null)),I?this.setViewport(I.x,I.y,I.width,I.height):this.setViewport(0,0,this.renderer.width,this.renderer.height)}setViewport(e,I,i,n){const C=this.viewport;e=Math.round(e),I=Math.round(I),i=Math.round(i),n=Math.round(n),(C.width!==i||C.height!==n||C.x!==e||C.y!==I)&&(C.x=e,C.y=I,C.width=i,C.height=n,this.gl.viewport(e,I,i,n))}get size(){return this.current?{x:0,y:0,width:this.current.width,height:this.current.height}:{x:0,y:0,width:this.renderer.width,height:this.renderer.height}}clear(e,I,i,n,C=RX.COLOR|RX.DEPTH){const{gl:r}=this;r.clearColor(e,I,i,n),r.clear(C)}initFramebuffer(e){const{gl:I}=this,i=new Dme(I.createFramebuffer());return i.multisample=this.detectSamples(e.multisample),e.glFramebuffers[this.CONTEXT_UID]=i,this.managedFramebuffers.push(e),e.disposeRunner.add(this),i}resizeFramebuffer(e){const{gl:I}=this,i=e.glFramebuffers[this.CONTEXT_UID];if(i.stencil){I.bindRenderbuffer(I.RENDERBUFFER,i.stencil);let r;this.renderer.context.webGLVersion===1?r=I.DEPTH_STENCIL:e.depth&&e.stencil?r=I.DEPTH24_STENCIL8:e.depth?r=I.DEPTH_COMPONENT24:r=I.STENCIL_INDEX8,i.msaaBuffer?I.renderbufferStorageMultisample(I.RENDERBUFFER,i.multisample,r,e.width,e.height):I.renderbufferStorage(I.RENDERBUFFER,r,e.width,e.height)}const n=e.colorTextures;let C=n.length;I.drawBuffers||(C=Math.min(C,1));for(let r=0;r1&&this.canMultisampleFramebuffer(e)?n.msaaBuffer=n.msaaBuffer||i.createRenderbuffer():n.msaaBuffer&&(i.deleteRenderbuffer(n.msaaBuffer),n.msaaBuffer=null,n.blitFramebuffer&&(n.blitFramebuffer.dispose(),n.blitFramebuffer=null));const o=[];for(let A=0;A1&&i.drawBuffers(o),e.depthTexture&&this.writeDepthTexture){const A=e.depthTexture;this.renderer.texture.bind(A,0),i.framebufferTexture2D(i.FRAMEBUFFER,i.DEPTH_ATTACHMENT,i.TEXTURE_2D,A._glTextures[this.CONTEXT_UID].texture,I)}if((e.stencil||e.depth)&&!(e.depthTexture&&this.writeDepthTexture)){n.stencil=n.stencil||i.createRenderbuffer();let A,s;this.renderer.context.webGLVersion===1?(A=i.DEPTH_STENCIL_ATTACHMENT,s=i.DEPTH_STENCIL):e.depth&&e.stencil?(A=i.DEPTH_STENCIL_ATTACHMENT,s=i.DEPTH24_STENCIL8):e.depth?(A=i.DEPTH_ATTACHMENT,s=i.DEPTH_COMPONENT24):(A=i.STENCIL_ATTACHMENT,s=i.STENCIL_INDEX8),i.bindRenderbuffer(i.RENDERBUFFER,n.stencil),n.msaaBuffer?i.renderbufferStorageMultisample(i.RENDERBUFFER,n.multisample,s,e.width,e.height):i.renderbufferStorage(i.RENDERBUFFER,s,e.width,e.height),i.framebufferRenderbuffer(i.FRAMEBUFFER,A,i.RENDERBUFFER,n.stencil)}else n.stencil&&(i.deleteRenderbuffer(n.stencil),n.stencil=null)}canMultisampleFramebuffer(e){return this.renderer.context.webGLVersion!==1&&e.colorTextures.length<=1&&!e.depthTexture}detectSamples(e){const{msaaSamples:I}=this;let i=Ci.NONE;if(e<=1||I===null)return i;for(let n=0;n=0&&this.managedFramebuffers.splice(C,1),e.disposeRunner.remove(this),I||(n.deleteFramebuffer(i.framebuffer),i.msaaBuffer&&n.deleteRenderbuffer(i.msaaBuffer),i.stencil&&n.deleteRenderbuffer(i.stencil)),i.blitFramebuffer&&this.disposeFramebuffer(i.blitFramebuffer,I)}disposeAll(e){const I=this.managedFramebuffers;this.managedFramebuffers=[];for(let i=0;ii.createVertexArrayOES(),e.bindVertexArray=n=>i.bindVertexArrayOES(n),e.deleteVertexArray=n=>i.deleteVertexArrayOES(n)):(this.hasVao=!1,e.createVertexArray=()=>null,e.bindVertexArray=()=>null,e.deleteVertexArray=()=>null)}if(I.webGLVersion!==2){const i=e.getExtension("ANGLE_instanced_arrays");i?(e.vertexAttribDivisor=(n,C)=>i.vertexAttribDivisorANGLE(n,C),e.drawElementsInstanced=(n,C,r,o,A)=>i.drawElementsInstancedANGLE(n,C,r,o,A),e.drawArraysInstanced=(n,C,r,o)=>i.drawArraysInstancedANGLE(n,C,r,o)):this.hasInstance=!1}this.canUseUInt32ElementIndex=I.webGLVersion===2||!!I.extensions.uint32ElementIndex}bind(e,I){I=I||this.renderer.shader.shader;const{gl:i}=this;let n=e.glVertexArrayObjects[this.CONTEXT_UID],C=!1;n||(this.managedGeometries[e.id]=e,e.disposeRunner.add(this),e.glVertexArrayObjects[this.CONTEXT_UID]=n={},C=!0);const r=n[I.program.id]||this.initGeometryVao(e,I,C);this._activeGeometry=e,this._activeVao!==r&&(this._activeVao=r,this.hasVao?i.bindVertexArray(r):this.activateVao(e,I.program)),this.updateBuffers()}reset(){this.unbind()}updateBuffers(){const e=this._activeGeometry,I=this.renderer.buffer;for(let i=0;i"u"?.5:I,this.isSimple=!1}get texture(){return this._texture}set texture(e){this._texture=e,this._textureID=-1}multiplyUvs(e,I){I===void 0&&(I=e);const i=this.mapCoord;for(let n=0;n0?this.maskStack[this.maskStack.length-1]._colorMask:15;i!==I&&this.renderer.gl.colorMask((i&1)!==0,(i&2)!==0,(i&4)!==0,(i&8)!==0)}destroy(){this.renderer=null}}$_.extension={type:pt.RendererSystem,name:"mask"};kt.add($_);class Mme{constructor(e){this.renderer=e,this.maskStack=[],this.glConst=0}getStackLength(){return this.maskStack.length}setMaskStack(e){const{gl:I}=this.renderer,i=this.getStackLength();this.maskStack=e;const n=this.getStackLength();n!==i&&(n===0?I.disable(this.glConst):(I.enable(this.glConst),this._useCurrent()))}_useCurrent(){}destroy(){this.renderer=null,this.maskStack=null}}const nee=new sI,Cee=[],zme=class k1 extends Mme{constructor(e){super(e),this.glConst=Gt.ADAPTER.getWebGLRenderingContext().SCISSOR_TEST}getStackLength(){const e=this.maskStack[this.maskStack.length-1];return e?e._scissorCounter:0}calcScissorRect(e){if(e._scissorRectLocal)return;const I=e._scissorRect,{maskObject:i}=e,{renderer:n}=this,C=n.renderTexture,r=i.getBounds(!0,Cee.pop()??new rg);this.roundFrameToPixels(r,C.current?C.current.resolution:n.resolution,C.sourceFrame,C.destinationFrame,n.projection.transform),I&&r.fit(I),e._scissorRectLocal=r}static isMatrixRotated(e){if(!e)return!1;const{a:I,b:i,c:n,d:C}=e;return(Math.abs(i)>1e-4||Math.abs(n)>1e-4)&&(Math.abs(I)>1e-4||Math.abs(C)>1e-4)}testScissor(e){const{maskObject:I}=e;if(!I.isFastRect||!I.isFastRect()||k1.isMatrixRotated(I.worldTransform)||k1.isMatrixRotated(this.renderer.projection.transform))return!1;this.calcScissorRect(e);const i=e._scissorRectLocal;return i.width>0&&i.height>0}roundFrameToPixels(e,I,i,n,C){k1.isMatrixRotated(C)||(C=C?nee.copyFrom(C):nee.identity(),C.translate(-i.x,-i.y).scale(n.width/i.width,n.height/i.height).translate(n.x,n.y),this.renderer.filter.transformAABB(C,e),e.fit(n),e.x=Math.round(e.x*I),e.y=Math.round(e.y*I),e.width=Math.round(e.width*I),e.height=Math.round(e.height*I))}push(e){e._scissorRectLocal||this.calcScissorRect(e);const{gl:I}=this.renderer;e._scissorRect||I.enable(I.SCISSOR_TEST),e._scissorCounter++,e._scissorRect=e._scissorRectLocal,this._useCurrent()}pop(e){const{gl:I}=this.renderer;e&&Cee.push(e._scissorRectLocal),this.getStackLength()>0?this._useCurrent():I.disable(I.SCISSOR_TEST)}_useCurrent(){const e=this.maskStack[this.maskStack.length-1]._scissorRect;let I;this.renderer.renderTexture.current?I=e.y:I=this.renderer.height-e.height-e.y,this.renderer.gl.scissor(e.x,I,e.width,e.height)}};zme.extension={type:pt.RendererSystem,name:"scissor"};let Pme=zme;kt.add(Pme);class q_ extends Mme{constructor(e){super(e),this.glConst=Gt.ADAPTER.getWebGLRenderingContext().STENCIL_TEST}getStackLength(){const e=this.maskStack[this.maskStack.length-1];return e?e._stencilCounter:0}push(e){const I=e.maskObject,{gl:i}=this.renderer,n=e._stencilCounter;n===0&&(this.renderer.framebuffer.forceStencil(),i.clearStencil(0),i.clear(i.STENCIL_BUFFER_BIT),i.enable(i.STENCIL_TEST)),e._stencilCounter++;const C=e._colorMask;C!==0&&(e._colorMask=0,i.colorMask(!1,!1,!1,!1)),i.stencilFunc(i.EQUAL,n,4294967295),i.stencilOp(i.KEEP,i.KEEP,i.INCR),I.renderable=!0,I.render(this.renderer),this.renderer.batch.flush(),I.renderable=!1,C!==0&&(e._colorMask=C,i.colorMask((C&1)!==0,(C&2)!==0,(C&4)!==0,(C&8)!==0)),this._useCurrent()}pop(e){const I=this.renderer.gl;if(this.getStackLength()===0)I.disable(I.STENCIL_TEST);else{const i=this.maskStack.length!==0?this.maskStack[this.maskStack.length-1]:null,n=i?i._colorMask:15;n!==0&&(i._colorMask=0,I.colorMask(!1,!1,!1,!1)),I.stencilOp(I.KEEP,I.KEEP,I.DECR),e.renderable=!0,e.render(this.renderer),this.renderer.batch.flush(),e.renderable=!1,n!==0&&(i._colorMask=n,I.colorMask((n&1)!==0,(n&2)!==0,(n&4)!==0,(n&8)!==0)),this._useCurrent()}}_useCurrent(){const e=this.renderer.gl;e.stencilFunc(e.EQUAL,this.getStackLength(),4294967295),e.stencilOp(e.KEEP,e.KEEP,e.KEEP)}}q_.extension={type:pt.RendererSystem,name:"stencil"};kt.add(q_);class eU{constructor(e){this.renderer=e,this.plugins={},Object.defineProperties(this.plugins,{extract:{enumerable:!1,get(){return tg("7.0.0","renderer.plugins.extract has moved to renderer.extract"),e.extract}},prepare:{enumerable:!1,get(){return tg("7.0.0","renderer.plugins.prepare has moved to renderer.prepare"),e.prepare}},interaction:{enumerable:!1,get(){return tg("7.0.0","renderer.plugins.interaction has been deprecated, use renderer.events"),e.events}}})}init(){const e=this.rendererPlugins;for(const I in e)this.plugins[I]=new e[I](this.renderer)}destroy(){for(const e in this.plugins)this.plugins[e].destroy(),this.plugins[e]=null}}eU.extension={type:[pt.RendererSystem,pt.CanvasRendererSystem],name:"_plugin"};kt.add(eU);class tU{constructor(e){this.renderer=e,this.destinationFrame=null,this.sourceFrame=null,this.defaultFrame=null,this.projectionMatrix=new sI,this.transform=null}update(e,I,i,n){this.destinationFrame=e||this.destinationFrame||this.defaultFrame,this.sourceFrame=I||this.sourceFrame||e,this.calculateProjection(this.destinationFrame,this.sourceFrame,i,n),this.transform&&this.projectionMatrix.append(this.transform);const C=this.renderer;C.globalUniforms.uniforms.projectionMatrix=this.projectionMatrix,C.globalUniforms.update(),C.shader.shader&&C.shader.syncUniformGroup(C.shader.shader.uniforms.globals)}calculateProjection(e,I,i,n){const C=this.projectionMatrix,r=n?-1:1;C.identity(),C.a=1/I.width*2,C.d=r*(1/I.height*2),C.tx=-1-I.x*C.a,C.ty=-r-I.y*C.d}setTransform(e){}destroy(){this.renderer=null}}tU.extension={type:pt.RendererSystem,name:"projection"};kt.add(tU);const IEe=new YS,ree=new rg;class gU{constructor(e){this.renderer=e,this._tempMatrix=new sI}generateTexture(e,I){const{region:i,...n}=I||{},C=(i==null?void 0:i.copyTo(ree))||e.getLocalBounds(ree,!0),r=n.resolution||this.renderer.resolution;C.width=Math.max(C.width,1/r),C.height=Math.max(C.height,1/r),n.width=C.width,n.height=C.height,n.resolution=r,n.multisample??(n.multisample=this.renderer.multisample);const o=il.create(n);this._tempMatrix.tx=-C.x,this._tempMatrix.ty=-C.y;const A=e.transform;return e.transform=IEe,this.renderer.render(e,{renderTexture:o,transform:this._tempMatrix,skipUpdateTransform:!!e.parent,blit:!0}),e.transform=A,o}destroy(){}}gU.extension={type:[pt.RendererSystem,pt.CanvasRendererSystem],name:"textureGenerator"};kt.add(gU);const Nu=new rg,xy=new rg;class IU{constructor(e){this.renderer=e,this.defaultMaskStack=[],this.current=null,this.sourceFrame=new rg,this.destinationFrame=new rg,this.viewportFrame=new rg}contextChange(){var I;const e=(I=this.renderer)==null?void 0:I.gl.getContextAttributes();this._rendererPremultipliedAlpha=!!(e&&e.alpha&&e.premultipliedAlpha)}bind(e=null,I,i){const n=this.renderer;this.current=e;let C,r,o;e?(C=e.baseTexture,o=C.resolution,I||(Nu.width=e.frame.width,Nu.height=e.frame.height,I=Nu),i||(xy.x=e.frame.x,xy.y=e.frame.y,xy.width=I.width,xy.height=I.height,i=xy),r=C.framebuffer):(o=n.resolution,I||(Nu.width=n._view.screen.width,Nu.height=n._view.screen.height,I=Nu),i||(i=Nu,i.width=I.width,i.height=I.height));const A=this.viewportFrame;A.x=i.x*o,A.y=i.y*o,A.width=i.width*o,A.height=i.height*o,e||(A.y=n.view.height-(A.y+A.height)),A.ceil(),this.renderer.framebuffer.bind(r,A),this.renderer.projection.update(i,I,o,!r),e?this.renderer.mask.setMaskStack(C.maskStack):this.renderer.mask.setMaskStack(this.defaultMaskStack),this.sourceFrame.copyFrom(I),this.destinationFrame.copyFrom(i)}clear(e,I){const i=this.current?this.current.baseTexture.clear:this.renderer.background.backgroundColor,n=xg.shared.setValue(e||i);(this.current&&this.current.baseTexture.alphaMode>0||!this.current&&this._rendererPremultipliedAlpha)&&n.premultiply(n.alpha);const C=this.destinationFrame,r=this.current?this.current.baseTexture:this.renderer._view.screen,o=C.width!==r.width||C.height!==r.height;if(o){let{x:A,y:s,width:a,height:l}=this.viewportFrame;A=Math.round(A),s=Math.round(s),a=Math.round(a),l=Math.round(l),this.renderer.gl.enable(this.renderer.gl.SCISSOR_TEST),this.renderer.gl.scissor(A,s,a,l)}this.renderer.framebuffer.clear(n.red,n.green,n.blue,n.alpha,I),o&&this.renderer.scissor.pop()}resize(){this.bind(null)}reset(){this.bind(null)}destroy(){this.renderer=null}}IU.extension={type:pt.RendererSystem,name:"renderTexture"};kt.add(IU);class iEe{}class Jme{constructor(e,I){this.program=e,this.uniformData=I,this.uniformGroups={},this.uniformDirtyGroups={},this.uniformBufferBindings={}}destroy(){this.uniformData=null,this.uniformGroups=null,this.uniformDirtyGroups=null,this.uniformBufferBindings=null,this.program=null}}function nEe(g,e){const I={},i=e.getProgramParameter(g,e.ACTIVE_ATTRIBUTES);for(let n=0;ns>a?1:-1);for(let s=0;s"u"?.5:I,this.isSimple=!1}return Object.defineProperty(e.prototype,"texture",{get:function(){return this._texture},set:function(g){this._texture=g,this._textureID=-1},enumerable:!1,configurable:!0}),e.prototype.multiplyUvs=function(g,I){I===void 0&&(I=g);for(var i=this.mapCoord,n=0;n0?this.maskStack[this.maskStack.length-1]._colorMask:15;i!==I&&this.renderer.gl.colorMask((i&1)!==0,(i&2)!==0,(i&4)!==0,(i&8)!==0)},e.prototype.destroy=function(){this.renderer=null},e}(),Ime=function(){function e(g){this.renderer=g,this.maskStack=[],this.glConst=0}return e.prototype.getStackLength=function(){return this.maskStack.length},e.prototype.setMaskStack=function(g){var I=this.renderer.gl,i=this.getStackLength();this.maskStack=g;var n=this.getStackLength();n!==i&&(n===0?I.disable(this.glConst):(I.enable(this.glConst),this._useCurrent()))},e.prototype._useCurrent=function(){},e.prototype.destroy=function(){this.renderer=null,this.maskStack=null},e}(),bq=new fi,yq=[],SL=function(e){oI(g,e);function g(I){var i=e.call(this,I)||this;return i.glConst=yt.ADAPTER.getWebGLRenderingContext().SCISSOR_TEST,i}return g.prototype.getStackLength=function(){var I=this.maskStack[this.maskStack.length-1];return I?I._scissorCounter:0},g.prototype.calcScissorRect=function(I){var i;if(!I._scissorRectLocal){var n=I._scissorRect,C=I.maskObject,r=this.renderer,o=r.renderTexture,A=C.getBounds(!0,(i=yq.pop())!==null&&i!==void 0?i:new vg);this.roundFrameToPixels(A,o.current?o.current.resolution:r.resolution,o.sourceFrame,o.destinationFrame,r.projection.transform),n&&A.fit(n),I._scissorRectLocal=A}},g.isMatrixRotated=function(I){if(!I)return!1;var i=I.a,n=I.b,C=I.c,r=I.d;return(Math.abs(n)>1e-4||Math.abs(C)>1e-4)&&(Math.abs(i)>1e-4||Math.abs(r)>1e-4)},g.prototype.testScissor=function(I){var i=I.maskObject;if(!i.isFastRect||!i.isFastRect()||g.isMatrixRotated(i.worldTransform)||g.isMatrixRotated(this.renderer.projection.transform))return!1;this.calcScissorRect(I);var n=I._scissorRectLocal;return n.width>0&&n.height>0},g.prototype.roundFrameToPixels=function(I,i,n,C,r){g.isMatrixRotated(r)||(r=r?bq.copyFrom(r):bq.identity(),r.translate(-n.x,-n.y).scale(C.width/n.width,C.height/n.height).translate(C.x,C.y),this.renderer.filter.transformAABB(r,I),I.fit(C),I.x=Math.round(I.x*i),I.y=Math.round(I.y*i),I.width=Math.round(I.width*i),I.height=Math.round(I.height*i))},g.prototype.push=function(I){I._scissorRectLocal||this.calcScissorRect(I);var i=this.renderer.gl;I._scissorRect||i.enable(i.SCISSOR_TEST),I._scissorCounter++,I._scissorRect=I._scissorRectLocal,this._useCurrent()},g.prototype.pop=function(I){var i=this.renderer.gl;I&&yq.push(I._scissorRectLocal),this.getStackLength()>0?this._useCurrent():i.disable(i.SCISSOR_TEST)},g.prototype._useCurrent=function(){var I=this.maskStack[this.maskStack.length-1]._scissorRect,i;this.renderer.renderTexture.current?i=I.y:i=this.renderer.height-I.height-I.y,this.renderer.gl.scissor(I.x,i,I.width,I.height)},g}(Ime),wL=function(e){oI(g,e);function g(I){var i=e.call(this,I)||this;return i.glConst=yt.ADAPTER.getWebGLRenderingContext().STENCIL_TEST,i}return g.prototype.getStackLength=function(){var I=this.maskStack[this.maskStack.length-1];return I?I._stencilCounter:0},g.prototype.push=function(I){var i=I.maskObject,n=this.renderer.gl,C=I._stencilCounter;C===0&&(this.renderer.framebuffer.forceStencil(),n.clearStencil(0),n.clear(n.STENCIL_BUFFER_BIT),n.enable(n.STENCIL_TEST)),I._stencilCounter++;var r=I._colorMask;r!==0&&(I._colorMask=0,n.colorMask(!1,!1,!1,!1)),n.stencilFunc(n.EQUAL,C,4294967295),n.stencilOp(n.KEEP,n.KEEP,n.INCR),i.renderable=!0,i.render(this.renderer),this.renderer.batch.flush(),i.renderable=!1,r!==0&&(I._colorMask=r,n.colorMask((r&1)!==0,(r&2)!==0,(r&4)!==0,(r&8)!==0)),this._useCurrent()},g.prototype.pop=function(I){var i=this.renderer.gl;if(this.getStackLength()===0)i.disable(i.STENCIL_TEST);else{var n=this.maskStack.length!==0?this.maskStack[this.maskStack.length-1]:null,C=n?n._colorMask:15;C!==0&&(n._colorMask=0,i.colorMask(!1,!1,!1,!1)),i.stencilOp(i.KEEP,i.KEEP,i.DECR),I.renderable=!0,I.render(this.renderer),this.renderer.batch.flush(),I.renderable=!1,C!==0&&(n._colorMask=C,i.colorMask((C&1)!==0,(C&2)!==0,(C&4)!==0,(C&8)!==0)),this._useCurrent()}},g.prototype._useCurrent=function(){var I=this.renderer.gl;I.stencilFunc(I.EQUAL,this.getStackLength(),4294967295),I.stencilOp(I.KEEP,I.KEEP,I.KEEP)},g}(Ime),VL=function(){function e(g){this.renderer=g,this.destinationFrame=null,this.sourceFrame=null,this.defaultFrame=null,this.projectionMatrix=new fi,this.transform=null}return e.prototype.update=function(g,I,i,n){this.destinationFrame=g||this.destinationFrame||this.defaultFrame,this.sourceFrame=I||this.sourceFrame||g,this.calculateProjection(this.destinationFrame,this.sourceFrame,i,n),this.transform&&this.projectionMatrix.append(this.transform);var C=this.renderer;C.globalUniforms.uniforms.projectionMatrix=this.projectionMatrix,C.globalUniforms.update(),C.shader.shader&&C.shader.syncUniformGroup(C.shader.shader.uniforms.globals)},e.prototype.calculateProjection=function(g,I,i,n){var C=this.projectionMatrix,r=n?-1:1;C.identity(),C.a=1/I.width*2,C.d=r*(1/I.height*2),C.tx=-1-I.x*C.a,C.ty=-r-I.y*C.d},e.prototype.setTransform=function(g){},e.prototype.destroy=function(){this.renderer=null},e}(),cu=new vg,py=new vg,RL=function(){function e(g){this.renderer=g,this.clearColor=g._backgroundColorRgba,this.defaultMaskStack=[],this.current=null,this.sourceFrame=new vg,this.destinationFrame=new vg,this.viewportFrame=new vg}return e.prototype.bind=function(g,I,i){g===void 0&&(g=null);var n=this.renderer;this.current=g;var C,r,o;g?(C=g.baseTexture,o=C.resolution,I||(cu.width=g.frame.width,cu.height=g.frame.height,I=cu),i||(py.x=g.frame.x,py.y=g.frame.y,py.width=I.width,py.height=I.height,i=py),r=C.framebuffer):(o=n.resolution,I||(cu.width=n.screen.width,cu.height=n.screen.height,I=cu),i||(i=cu,i.width=I.width,i.height=I.height));var A=this.viewportFrame;A.x=i.x*o,A.y=i.y*o,A.width=i.width*o,A.height=i.height*o,g||(A.y=n.view.height-(A.y+A.height)),A.ceil(),this.renderer.framebuffer.bind(r,A),this.renderer.projection.update(i,I,o,!r),g?this.renderer.mask.setMaskStack(C.maskStack):this.renderer.mask.setMaskStack(this.defaultMaskStack),this.sourceFrame.copyFrom(I),this.destinationFrame.copyFrom(i)},e.prototype.clear=function(g,I){this.current?g=g||this.current.baseTexture.clearColor:g=g||this.clearColor;var i=this.destinationFrame,n=this.current?this.current.baseTexture:this.renderer.screen,C=i.width!==n.width||i.height!==n.height;if(C){var r=this.viewportFrame,o=r.x,A=r.y,s=r.width,a=r.height;o=Math.round(o),A=Math.round(A),s=Math.round(s),a=Math.round(a),this.renderer.gl.enable(this.renderer.gl.SCISSOR_TEST),this.renderer.gl.scissor(o,A,s,a)}this.renderer.framebuffer.clear(g[0],g[1],g[2],g[3],I),C&&this.renderer.scissor.pop()},e.prototype.resize=function(){this.bind(null)},e.prototype.reset=function(){this.bind(null)},e.prototype.destroy=function(){this.renderer=null},e}();function kMe(e,g,I,i,n){I.buffer.update(n)}var YMe={float:` data[offset] = v; `,vec2:` data[offset] = v[0]; @@ -493,7 +525,7 @@ void main(void) { data[offset + i] = v[i]; } - `},Lme={float:4,vec2:8,vec3:12,vec4:16,int:4,ivec2:8,ivec3:12,ivec4:16,uint:4,uvec2:8,uvec3:12,uvec4:16,bool:4,bvec2:8,bvec3:12,bvec4:16,mat2:16*2,mat3:16*3,mat4:16*4};function _me(g){const e=g.map(C=>({data:C,offset:0,dataLen:0,dirty:0}));let I=0,i=0,n=0;for(let C=0;C1&&(I=Math.max(I,16)*r.data.size),r.dataLen=I,i%I!==0&&i<16){const o=i%I%16;i+=o,n+=o}i+I>16?(n=Math.ceil(n/16)*16,r.offset=n,n+=I,i=I):(r.offset=n,i+=I,n+=I)}return n=Math.ceil(n/16)*16,{uboElements:e,size:n}}function Ume(g,e){const I=[];for(const i in g)e[i]&&I.push(e[i]);return I.sort((i,n)=>i.index-n.index),I}function Qme(g,e){if(!g.autoManage)return{size:0,syncFunc:rEe};const I=Ume(g.uniforms,e),{uboElements:i,size:n}=_me(I),C=[` + `},ime={float:4,vec2:8,vec3:12,vec4:16,int:4,ivec2:8,ivec3:12,ivec4:16,uint:4,uvec2:8,uvec3:12,uvec4:16,bool:4,bvec2:8,bvec3:12,bvec4:16,mat2:16*2,mat3:16*3,mat4:16*4};function nme(e){for(var g=e.map(function(A){return{data:A,offset:0,dataLen:0,dirty:0}}),I=0,i=0,n=0,C=0;C1&&(I=Math.max(I,16)*r.data.size),r.dataLen=I,i%I!==0&&i<16){var o=i%I%16;i+=o,n+=o}i+I>16?(n=Math.ceil(n/16)*16,r.offset=n,n+=I,i=I):(r.offset=n,i+=I,n+=I)}return n=Math.ceil(n/16)*16,{uboElements:g,size:n}}function Cme(e,g){var I=[];for(var i in e)g[i]&&I.push(g[i]);return I.sort(function(n,C){return n.index-C.index}),I}function rme(e,g){if(!e.autoManage)return{size:0,syncFunc:kMe};for(var I=Cme(e.uniforms,g),i=nme(I),n=i.uboElements,C=i.size,r=[` var v = null; var v2 = null; var cv = null; @@ -501,31 +533,31 @@ void main(void) var gl = renderer.gl var index = 0; var data = buffer.data; - `];for(let r=0;r1){const l=Tme(o.data.type),c=Math.max(Lme[o.data.type]/16,1),u=l/c,d=(4-u%4)%4;C.push(` - cv = ud.${s}.value; - v = uv.${s}; - offset = ${o.offset/4}; + `],o=0;o1){var d=qhe(A.data.type),h=Math.max(ime[A.data.type]/16,1),m=d/h,f=(4-m%4)%4;r.push(` + cv = ud.`+a+`.value; + v = uv.`+a+`; + offset = `+A.offset/4+`; t = 0; - for(var i=0; i < ${o.data.size*c}; i++) + for(var i=0; i < `+A.data.size*h+`; i++) { - for(var j = 0; j < ${u}; j++) + for(var j = 0; j < `+m+`; j++) { data[offset++] = v[t++]; } - offset += ${d}; + offset += `+f+`; } - `)}else{const l=oEe[o.data.type];C.push(` - cv = ud.${s}.value; - v = uv.${s}; - offset = ${o.offset/4}; - ${l}; - `)}}return C.push(` + `)}else{var b=YMe[A.data.type];r.push(` + cv = ud.`+a+`.value; + v = uv.`+a+`; + offset = `+A.offset/4+`; + `+b+`; + `)}}return r.push(` renderer.buffer.update(buffer); - `),{size:n,syncFunc:new Function("ud","uv","renderer","syncData","buffer",C.join(` -`))}}let AEe=0;const DV={textureCount:0,uboCount:0};class iU{constructor(e){this.destroyed=!1,this.renderer=e,this.systemCheck(),this.gl=null,this.shader=null,this.program=null,this.cache={},this._uboCache={},this.id=AEe++}systemCheck(){if(!kme())throw new Error("Current environment does not allow unsafe-eval, please use @pixi/unsafe-eval module to enable support.")}contextChange(e){this.gl=e,this.reset()}bind(e,I){e.disposeRunner.add(this),e.uniforms.globals=this.renderer.globalUniforms;const i=e.program,n=i.glPrograms[this.renderer.CONTEXT_UID]||this.generateProgram(e);return this.shader=e,this.program!==i&&(this.program=i,this.gl.useProgram(n.program)),I||(DV.textureCount=0,DV.uboCount=0,this.syncUniformGroup(e.uniformGroup,DV)),n}setUniforms(e){const I=this.shader.program,i=I.glPrograms[this.renderer.CONTEXT_UID];I.syncUniforms(i.uniformData,e,this.renderer)}syncUniformGroup(e,I){const i=this.getGlProgram();(!e.static||e.dirtyId!==i.uniformDirtyGroups[e.id])&&(i.uniformDirtyGroups[e.id]=e.dirtyId,this.syncUniforms(e,i,I))}syncUniforms(e,I,i){(e.syncUniforms[this.shader.program.id]||this.createSyncGroups(e))(I.uniformData,e.uniforms,this.renderer,i)}createSyncGroups(e){const I=this.getSignature(e,this.shader.program.uniformData,"u");return this.cache[I]||(this.cache[I]=MFe(e,this.shader.program.uniformData)),e.syncUniforms[this.shader.program.id]=this.cache[I],e.syncUniforms[this.shader.program.id]}syncUniformBufferGroup(e,I){const i=this.getGlProgram();if(!e.static||e.dirtyId!==0||!i.uniformGroups[e.id]){e.dirtyId=0;const n=i.uniformGroups[e.id]||this.createSyncBufferGroup(e,i,I);e.buffer.update(),n(i.uniformData,e.uniforms,this.renderer,DV,e.buffer)}this.renderer.buffer.bindBufferBase(e.buffer,i.uniformBufferBindings[I])}createSyncBufferGroup(e,I,i){const{gl:n}=this.renderer;this.renderer.buffer.bind(e.buffer);const C=this.gl.getUniformBlockIndex(I.program,i);I.uniformBufferBindings[i]=this.shader.uniformBindCount,n.uniformBlockBinding(I.program,C,this.shader.uniformBindCount),this.shader.uniformBindCount++;const r=this.getSignature(e,this.shader.program.uniformData,"ubo");let o=this._uboCache[r];if(o||(o=this._uboCache[r]=Qme(e,this.shader.program.uniformData)),e.autoManage){const A=new Float32Array(o.size/4);e.buffer.update(A)}return I.uniformGroups[e.id]=o.syncFunc,I.uniformGroups[e.id]}getSignature(e,I,i){const n=e.uniforms,C=[`${i}-`];for(const r in n)C.push(r),I[r]&&C.push(I[r].type);return C.join("-")}getGlProgram(){return this.shader?this.shader.program.glPrograms[this.renderer.CONTEXT_UID]:null}generateProgram(e){const I=this.gl,i=e.program,n=Ome(I,i);return i.glPrograms[this.renderer.CONTEXT_UID]=n,n}reset(){this.program=null,this.shader=null}disposeShader(e){this.shader===e&&(this.shader=null)}destroy(){this.renderer=null,this.destroyed=!0}}iU.extension={type:pt.RendererSystem,name:"shader"};kt.add(iU);class mv{constructor(e){this.renderer=e}run(e){const{renderer:I}=this;I.runners.init.emit(I.options),e.hello&&console.log(`PixiJS 7.3.2 - ${I.rendererLogId} - https://pixijs.com`),I.resize(I.screen.width,I.screen.height)}destroy(){}}mv.defaultOptions={hello:!1},mv.extension={type:[pt.RendererSystem,pt.CanvasRendererSystem],name:"startup"};kt.add(mv);function aEe(g,e=[]){return e[$t.NORMAL]=[g.ONE,g.ONE_MINUS_SRC_ALPHA],e[$t.ADD]=[g.ONE,g.ONE],e[$t.MULT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g.ONE_MINUS_DST_ALPHA,g.ONE],e[$t.DST_IN]=[g.ZERO,g.SRC_ALPHA],e[$t.DST_OUT]=[g.ZERO,g.ONE_MINUS_SRC_ALPHA],e[$t.DST_ATOP]=[g.ONE_MINUS_DST_ALPHA,g.SRC_ALPHA],e[$t.XOR]=[g.ONE_MINUS_DST_ALPHA,g.ONE_MINUS_SRC_ALPHA],e[$t.SUBTRACT]=[g.ONE,g.ONE,g.ONE,g.ONE,g.FUNC_REVERSE_SUBTRACT,g.FUNC_ADD],e}const sEe=0,lEe=1,cEe=2,uEe=3,dEe=4,hEe=5,jme=class SM{constructor(){this.gl=null,this.stateId=0,this.polygonOffset=0,this.blendMode=$t.NONE,this._blendEq=!1,this.map=[],this.map[sEe]=this.setBlend,this.map[lEe]=this.setOffset,this.map[cEe]=this.setCullFace,this.map[uEe]=this.setDepthTest,this.map[dEe]=this.setFrontFace,this.map[hEe]=this.setDepthMask,this.checks=[],this.defaultState=new Il,this.defaultState.blend=!0}contextChange(e){this.gl=e,this.blendModes=aEe(e),this.set(this.defaultState),this.reset()}set(e){if(e=e||this.defaultState,this.stateId!==e.data){let I=this.stateId^e.data,i=0;for(;I;)I&1&&this.map[i].call(this,!!(e.data&1<>1,i++;this.stateId=e.data}for(let I=0;Ie.systems[n]),i=[...I,...Object.keys(e.systems).filter(n=>!I.includes(n))];for(const n of i)this.addSystem(e.systems[n],n)}addRunners(...e){e.forEach(I=>{this.runners[I]=new dr(I)})}addSystem(e,I){const i=new e(this);if(this[I])throw new Error(`Whoops! The name "${I}" is already in use`);this[I]=i,this._systemsHash[I]=i;for(const n in this.runners)this.runners[n].add(i);return this}emitWithCustomOptions(e,I){const i=Object.keys(this._systemsHash);e.items.forEach(n=>{const C=i.find(r=>this._systemsHash[r]===n);n[e.name](I[C])})}destroy(){Object.values(this.runners).forEach(e=>{e.destroy()}),this._systemsHash={}}}const KZ=class Y1{constructor(e){this.renderer=e,this.count=0,this.checkCount=0,this.maxIdle=Y1.defaultMaxIdle,this.checkCountMax=Y1.defaultCheckCountMax,this.mode=Y1.defaultMode}postrender(){this.renderer.objectRenderer.renderingToScreen&&(this.count++,this.mode!==HT.MANUAL&&(this.checkCount++,this.checkCount>this.checkCountMax&&(this.checkCount=0,this.run())))}run(){const e=this.renderer.texture,I=e.managedTextures;let i=!1;for(let n=0;nthis.maxIdle&&(e.destroyTexture(C,!0),I[n]=null,i=!0)}if(i){let n=0;for(let C=0;C=0;n--)this.unload(e.children[n])}destroy(){this.renderer=null}};KZ.defaultMode=HT.AUTO,KZ.defaultMaxIdle=60*60,KZ.defaultCheckCountMax=60*10,KZ.extension={type:pt.RendererSystem,name:"textureGC"};let ec=KZ;kt.add(ec);class K1{constructor(e){this.texture=e,this.width=-1,this.height=-1,this.dirtyId=-1,this.dirtyStyleId=-1,this.mipmap=!1,this.wrapMode=33071,this.type=Mt.UNSIGNED_BYTE,this.internalFormat=st.RGBA,this.samplerType=0}}function mEe(g){let e;return"WebGL2RenderingContext"in globalThis&&g instanceof globalThis.WebGL2RenderingContext?e={[g.RGB]:Zt.FLOAT,[g.RGBA]:Zt.FLOAT,[g.ALPHA]:Zt.FLOAT,[g.LUMINANCE]:Zt.FLOAT,[g.LUMINANCE_ALPHA]:Zt.FLOAT,[g.R8]:Zt.FLOAT,[g.R8_SNORM]:Zt.FLOAT,[g.RG8]:Zt.FLOAT,[g.RG8_SNORM]:Zt.FLOAT,[g.RGB8]:Zt.FLOAT,[g.RGB8_SNORM]:Zt.FLOAT,[g.RGB565]:Zt.FLOAT,[g.RGBA4]:Zt.FLOAT,[g.RGB5_A1]:Zt.FLOAT,[g.RGBA8]:Zt.FLOAT,[g.RGBA8_SNORM]:Zt.FLOAT,[g.RGB10_A2]:Zt.FLOAT,[g.RGB10_A2UI]:Zt.FLOAT,[g.SRGB8]:Zt.FLOAT,[g.SRGB8_ALPHA8]:Zt.FLOAT,[g.R16F]:Zt.FLOAT,[g.RG16F]:Zt.FLOAT,[g.RGB16F]:Zt.FLOAT,[g.RGBA16F]:Zt.FLOAT,[g.R32F]:Zt.FLOAT,[g.RG32F]:Zt.FLOAT,[g.RGB32F]:Zt.FLOAT,[g.RGBA32F]:Zt.FLOAT,[g.R11F_G11F_B10F]:Zt.FLOAT,[g.RGB9_E5]:Zt.FLOAT,[g.R8I]:Zt.INT,[g.R8UI]:Zt.UINT,[g.R16I]:Zt.INT,[g.R16UI]:Zt.UINT,[g.R32I]:Zt.INT,[g.R32UI]:Zt.UINT,[g.RG8I]:Zt.INT,[g.RG8UI]:Zt.UINT,[g.RG16I]:Zt.INT,[g.RG16UI]:Zt.UINT,[g.RG32I]:Zt.INT,[g.RG32UI]:Zt.UINT,[g.RGB8I]:Zt.INT,[g.RGB8UI]:Zt.UINT,[g.RGB16I]:Zt.INT,[g.RGB16UI]:Zt.UINT,[g.RGB32I]:Zt.INT,[g.RGB32UI]:Zt.UINT,[g.RGBA8I]:Zt.INT,[g.RGBA8UI]:Zt.UINT,[g.RGBA16I]:Zt.INT,[g.RGBA16UI]:Zt.UINT,[g.RGBA32I]:Zt.INT,[g.RGBA32UI]:Zt.UINT,[g.DEPTH_COMPONENT16]:Zt.FLOAT,[g.DEPTH_COMPONENT24]:Zt.FLOAT,[g.DEPTH_COMPONENT32F]:Zt.FLOAT,[g.DEPTH_STENCIL]:Zt.FLOAT,[g.DEPTH24_STENCIL8]:Zt.FLOAT,[g.DEPTH32F_STENCIL8]:Zt.FLOAT}:e={[g.RGB]:Zt.FLOAT,[g.RGBA]:Zt.FLOAT,[g.ALPHA]:Zt.FLOAT,[g.LUMINANCE]:Zt.FLOAT,[g.LUMINANCE_ALPHA]:Zt.FLOAT,[g.DEPTH_STENCIL]:Zt.FLOAT},e}function fEe(g){let e;return"WebGL2RenderingContext"in globalThis&&g instanceof globalThis.WebGL2RenderingContext?e={[Mt.UNSIGNED_BYTE]:{[st.RGBA]:g.RGBA8,[st.RGB]:g.RGB8,[st.RG]:g.RG8,[st.RED]:g.R8,[st.RGBA_INTEGER]:g.RGBA8UI,[st.RGB_INTEGER]:g.RGB8UI,[st.RG_INTEGER]:g.RG8UI,[st.RED_INTEGER]:g.R8UI,[st.ALPHA]:g.ALPHA,[st.LUMINANCE]:g.LUMINANCE,[st.LUMINANCE_ALPHA]:g.LUMINANCE_ALPHA},[Mt.BYTE]:{[st.RGBA]:g.RGBA8_SNORM,[st.RGB]:g.RGB8_SNORM,[st.RG]:g.RG8_SNORM,[st.RED]:g.R8_SNORM,[st.RGBA_INTEGER]:g.RGBA8I,[st.RGB_INTEGER]:g.RGB8I,[st.RG_INTEGER]:g.RG8I,[st.RED_INTEGER]:g.R8I},[Mt.UNSIGNED_SHORT]:{[st.RGBA_INTEGER]:g.RGBA16UI,[st.RGB_INTEGER]:g.RGB16UI,[st.RG_INTEGER]:g.RG16UI,[st.RED_INTEGER]:g.R16UI,[st.DEPTH_COMPONENT]:g.DEPTH_COMPONENT16},[Mt.SHORT]:{[st.RGBA_INTEGER]:g.RGBA16I,[st.RGB_INTEGER]:g.RGB16I,[st.RG_INTEGER]:g.RG16I,[st.RED_INTEGER]:g.R16I},[Mt.UNSIGNED_INT]:{[st.RGBA_INTEGER]:g.RGBA32UI,[st.RGB_INTEGER]:g.RGB32UI,[st.RG_INTEGER]:g.RG32UI,[st.RED_INTEGER]:g.R32UI,[st.DEPTH_COMPONENT]:g.DEPTH_COMPONENT24},[Mt.INT]:{[st.RGBA_INTEGER]:g.RGBA32I,[st.RGB_INTEGER]:g.RGB32I,[st.RG_INTEGER]:g.RG32I,[st.RED_INTEGER]:g.R32I},[Mt.FLOAT]:{[st.RGBA]:g.RGBA32F,[st.RGB]:g.RGB32F,[st.RG]:g.RG32F,[st.RED]:g.R32F,[st.DEPTH_COMPONENT]:g.DEPTH_COMPONENT32F},[Mt.HALF_FLOAT]:{[st.RGBA]:g.RGBA16F,[st.RGB]:g.RGB16F,[st.RG]:g.RG16F,[st.RED]:g.R16F},[Mt.UNSIGNED_SHORT_5_6_5]:{[st.RGB]:g.RGB565},[Mt.UNSIGNED_SHORT_4_4_4_4]:{[st.RGBA]:g.RGBA4},[Mt.UNSIGNED_SHORT_5_5_5_1]:{[st.RGBA]:g.RGB5_A1},[Mt.UNSIGNED_INT_2_10_10_10_REV]:{[st.RGBA]:g.RGB10_A2,[st.RGBA_INTEGER]:g.RGB10_A2UI},[Mt.UNSIGNED_INT_10F_11F_11F_REV]:{[st.RGB]:g.R11F_G11F_B10F},[Mt.UNSIGNED_INT_5_9_9_9_REV]:{[st.RGB]:g.RGB9_E5},[Mt.UNSIGNED_INT_24_8]:{[st.DEPTH_STENCIL]:g.DEPTH24_STENCIL8},[Mt.FLOAT_32_UNSIGNED_INT_24_8_REV]:{[st.DEPTH_STENCIL]:g.DEPTH32F_STENCIL8}}:e={[Mt.UNSIGNED_BYTE]:{[st.RGBA]:g.RGBA,[st.RGB]:g.RGB,[st.ALPHA]:g.ALPHA,[st.LUMINANCE]:g.LUMINANCE,[st.LUMINANCE_ALPHA]:g.LUMINANCE_ALPHA},[Mt.UNSIGNED_SHORT_5_6_5]:{[st.RGB]:g.RGB},[Mt.UNSIGNED_SHORT_4_4_4_4]:{[st.RGBA]:g.RGBA},[Mt.UNSIGNED_SHORT_5_5_5_1]:{[st.RGBA]:g.RGBA}},e}class nU{constructor(e){this.renderer=e,this.boundTextures=[],this.currentLocation=-1,this.managedTextures=[],this._unknownBoundTextures=!1,this.unknownTexture=new ng,this.hasIntegerTextures=!1}contextChange(){const e=this.gl=this.renderer.gl;this.CONTEXT_UID=this.renderer.CONTEXT_UID,this.webGLVersion=this.renderer.context.webGLVersion,this.internalFormats=fEe(e),this.samplerTypes=mEe(e);const I=e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS);this.boundTextures.length=I;for(let n=0;n=0;--C){const r=I[C];r&&r._glTextures[n].samplerType!==Zt.FLOAT&&this.renderer.texture.unbind(r)}}initTexture(e){const I=new K1(this.gl.createTexture());return I.dirtyId=-1,e._glTextures[this.CONTEXT_UID]=I,this.managedTextures.push(e),e.on("dispose",this.destroyTexture,this),I}initTextureType(e,I){var i;I.internalFormat=((i=this.internalFormats[e.type])==null?void 0:i[e.format])??e.format,I.samplerType=this.samplerTypes[I.internalFormat]??Zt.FLOAT,this.webGLVersion===2&&e.type===Mt.HALF_FLOAT?I.type=this.gl.HALF_FLOAT:I.type=e.type}updateTexture(e){var n;const I=e._glTextures[this.CONTEXT_UID];if(!I)return;const i=this.renderer;if(this.initTextureType(e,I),(n=e.resource)==null?void 0:n.upload(i,e,I))I.samplerType!==Zt.FLOAT&&(this.hasIntegerTextures=!0);else{const C=e.realWidth,r=e.realHeight,o=i.gl;(I.width!==C||I.height!==r||I.dirtyId<0)&&(I.width=C,I.height=r,o.texImage2D(e.target,0,I.internalFormat,C,r,0,e.format,I.type,null))}e.dirtyStyleId!==I.dirtyStyleId&&this.updateTextureStyle(e),I.dirtyId=e.dirtyId}destroyTexture(e,I){const{gl:i}=this;if(e=e.castToBaseTexture(),e._glTextures[this.CONTEXT_UID]&&(this.unbind(e),i.deleteTexture(e._glTextures[this.CONTEXT_UID].texture),e.off("dispose",this.destroyTexture,this),delete e._glTextures[this.CONTEXT_UID],!I)){const n=this.managedTextures.indexOf(e);n!==-1&&Nd(this.managedTextures,n,1)}}updateTextureStyle(e){var i;const I=e._glTextures[this.CONTEXT_UID];I&&((e.mipmap===uA.POW2||this.webGLVersion!==2)&&!e.isPowerOfTwo?I.mipmap=!1:I.mipmap=e.mipmap>=1,this.webGLVersion!==2&&!e.isPowerOfTwo?I.wrapMode=da.CLAMP:I.wrapMode=e.wrapMode,(i=e.resource)!=null&&i.style(this.renderer,e,I)||this.setStyle(e,I),I.dirtyStyleId=e.dirtyStyleId)}setStyle(e,I){const i=this.gl;if(I.mipmap&&e.mipmap!==uA.ON_MANUAL&&i.generateMipmap(e.target),i.texParameteri(e.target,i.TEXTURE_WRAP_S,I.wrapMode),i.texParameteri(e.target,i.TEXTURE_WRAP_T,I.wrapMode),I.mipmap){i.texParameteri(e.target,i.TEXTURE_MIN_FILTER,e.scaleMode===Ca.LINEAR?i.LINEAR_MIPMAP_LINEAR:i.NEAREST_MIPMAP_NEAREST);const n=this.renderer.context.extensions.anisotropicFiltering;if(n&&e.anisotropicLevel>0&&e.scaleMode===Ca.LINEAR){const C=Math.min(e.anisotropicLevel,i.getParameter(n.MAX_TEXTURE_MAX_ANISOTROPY_EXT));i.texParameterf(e.target,n.TEXTURE_MAX_ANISOTROPY_EXT,C)}}else i.texParameteri(e.target,i.TEXTURE_MIN_FILTER,e.scaleMode===Ca.LINEAR?i.LINEAR:i.NEAREST);i.texParameteri(e.target,i.TEXTURE_MAG_FILTER,e.scaleMode===Ca.LINEAR?i.LINEAR:i.NEAREST)}destroy(){this.renderer=null}}nU.extension={type:pt.RendererSystem,name:"texture"};kt.add(nU);class CU{constructor(e){this.renderer=e}contextChange(){this.gl=this.renderer.gl,this.CONTEXT_UID=this.renderer.CONTEXT_UID}bind(e){const{gl:I,CONTEXT_UID:i}=this,n=e._glTransformFeedbacks[i]||this.createGLTransformFeedback(e);I.bindTransformFeedback(I.TRANSFORM_FEEDBACK,n)}unbind(){const{gl:e}=this;e.bindTransformFeedback(e.TRANSFORM_FEEDBACK,null)}beginTransformFeedback(e,I){const{gl:i,renderer:n}=this;I&&n.shader.bind(I),i.beginTransformFeedback(e)}endTransformFeedback(){const{gl:e}=this;e.endTransformFeedback()}createGLTransformFeedback(e){const{gl:I,renderer:i,CONTEXT_UID:n}=this,C=I.createTransformFeedback();e._glTransformFeedbacks[n]=C,I.bindTransformFeedback(I.TRANSFORM_FEEDBACK,C);for(let r=0;r(g[g.INTERACTION=50]="INTERACTION",g[g.HIGH=25]="HIGH",g[g.NORMAL=0]="NORMAL",g[g.LOW=-25]="LOW",g[g.UTILITY=-50]="UTILITY",g))(zs||{});class qK{constructor(e,I=null,i=0,n=!1){this.next=null,this.previous=null,this._destroyed=!1,this.fn=e,this.context=I,this.priority=i,this.once=n}match(e,I=null){return this.fn===e&&this.context===I}emit(e){this.fn&&(this.context?this.fn.call(this.context,e):this.fn(e));const I=this.next;return this.once&&this.destroy(!0),this._destroyed&&(this.next=null),I}connect(e){this.previous=e,e.next&&(e.next.previous=this),this.next=e.next,e.next=this}destroy(e=!1){this._destroyed=!0,this.fn=null,this.context=null,this.previous&&(this.previous.next=this.next),this.next&&(this.next.previous=this.previous);const I=this.next;return this.next=e?null:I,this.previous=null,I}}const efe=class LC{constructor(){this.autoStart=!1,this.deltaTime=1,this.lastTime=-1,this.speed=1,this.started=!1,this._requestId=null,this._maxElapsedMS=100,this._minElapsedMS=0,this._protected=!1,this._lastFrame=-1,this._head=new qK(null,null,1/0),this.deltaMS=1/LC.targetFPMS,this.elapsedMS=1/LC.targetFPMS,this._tick=e=>{this._requestId=null,this.started&&(this.update(e),this.started&&this._requestId===null&&this._head.next&&(this._requestId=requestAnimationFrame(this._tick)))}}_requestIfNeeded(){this._requestId===null&&this._head.next&&(this.lastTime=performance.now(),this._lastFrame=this.lastTime,this._requestId=requestAnimationFrame(this._tick))}_cancelIfNeeded(){this._requestId!==null&&(cancelAnimationFrame(this._requestId),this._requestId=null)}_startIfPossible(){this.started?this._requestIfNeeded():this.autoStart&&this.start()}add(e,I,i=zs.NORMAL){return this._addListener(new qK(e,I,i))}addOnce(e,I,i=zs.NORMAL){return this._addListener(new qK(e,I,i,!0))}_addListener(e){let I=this._head.next,i=this._head;if(!I)e.connect(i);else{for(;I;){if(e.priority>I.priority){e.connect(i);break}i=I,I=I.next}e.previous||e.connect(i)}return this._startIfPossible(),this}remove(e,I){let i=this._head.next;for(;i;)i.match(e,I)?i=i.destroy():i=i.next;return this._head.next||this._cancelIfNeeded(),this}get count(){if(!this._head)return 0;let e=0,I=this._head;for(;I=I.next;)e++;return e}start(){this.started||(this.started=!0,this._requestIfNeeded())}stop(){this.started&&(this.started=!1,this._cancelIfNeeded())}destroy(){if(!this._protected){this.stop();let e=this._head.next;for(;e;)e=e.destroy(!0);this._head.destroy(),this._head=null}}update(e=performance.now()){let I;if(e>this.lastTime){if(I=this.elapsedMS=e-this.lastTime,I>this._maxElapsedMS&&(I=this._maxElapsedMS),I*=this.speed,this._minElapsedMS){const C=e-this._lastFrame|0;if(C{this._ticker.stop()},this.start=()=>{this._ticker.start()},this._ticker=null,this.ticker=e.sharedTicker?Ji.shared:new Ji,e.autoStart&&this.start()}static destroy(){if(this._ticker){const e=this._ticker;this.ticker=null,e.destroy()}}}rU.extension=pt.Application;kt.add(rU);const tfe=[];kt.handleByList(pt.Renderer,tfe);function gfe(g){for(const e of tfe)if(e.test(g))return new e(g);throw new Error("Unable to auto-detect a suitable renderer.")}var pEe=`attribute vec2 aVertexPosition; + `),{size:C,syncFunc:new Function("ud","uv","renderer","syncData","buffer",r.join(` +`))}}var KMe=function(){function e(){}return e}(),ome=function(){function e(g,I){this.program=g,this.uniformData=I,this.uniformGroups={},this.uniformDirtyGroups={},this.uniformBufferBindings={}}return e.prototype.destroy=function(){this.uniformData=null,this.uniformGroups=null,this.uniformDirtyGroups=null,this.uniformBufferBindings=null,this.program=null},e}();function DMe(e,g){for(var I={},i=g.getProgramParameter(e,g.ACTIVE_ATTRIBUTES),n=0;nl?1:-1});for(var r=0;r>1,i++;this.stateId=g.data}for(var i=0;ithis.checkCountMax&&(this.checkCount=0,this.run())))},e.prototype.run=function(){for(var g=this.renderer.texture,I=g.managedTextures,i=!1,n=0;nthis.maxIdle&&(g.destroyTexture(C,!0),I[n]=null,i=!0)}if(i){for(var r=0,n=0;n=0;n--)this.unload(g.children[n])},e.prototype.destroy=function(){this.renderer=null},e}();function LMe(e){var g,I,i,n,C,r,o,A,s,a,l,c,u,d,h,m,f,b,p,y,Z,B,G;return"WebGL2RenderingContext"in globalThis&&e instanceof globalThis.WebGL2RenderingContext?G=(g={},g[Et.UNSIGNED_BYTE]=(I={},I[ht.RGBA]=e.RGBA8,I[ht.RGB]=e.RGB8,I[ht.RG]=e.RG8,I[ht.RED]=e.R8,I[ht.RGBA_INTEGER]=e.RGBA8UI,I[ht.RGB_INTEGER]=e.RGB8UI,I[ht.RG_INTEGER]=e.RG8UI,I[ht.RED_INTEGER]=e.R8UI,I[ht.ALPHA]=e.ALPHA,I[ht.LUMINANCE]=e.LUMINANCE,I[ht.LUMINANCE_ALPHA]=e.LUMINANCE_ALPHA,I),g[Et.BYTE]=(i={},i[ht.RGBA]=e.RGBA8_SNORM,i[ht.RGB]=e.RGB8_SNORM,i[ht.RG]=e.RG8_SNORM,i[ht.RED]=e.R8_SNORM,i[ht.RGBA_INTEGER]=e.RGBA8I,i[ht.RGB_INTEGER]=e.RGB8I,i[ht.RG_INTEGER]=e.RG8I,i[ht.RED_INTEGER]=e.R8I,i),g[Et.UNSIGNED_SHORT]=(n={},n[ht.RGBA_INTEGER]=e.RGBA16UI,n[ht.RGB_INTEGER]=e.RGB16UI,n[ht.RG_INTEGER]=e.RG16UI,n[ht.RED_INTEGER]=e.R16UI,n[ht.DEPTH_COMPONENT]=e.DEPTH_COMPONENT16,n),g[Et.SHORT]=(C={},C[ht.RGBA_INTEGER]=e.RGBA16I,C[ht.RGB_INTEGER]=e.RGB16I,C[ht.RG_INTEGER]=e.RG16I,C[ht.RED_INTEGER]=e.R16I,C),g[Et.UNSIGNED_INT]=(r={},r[ht.RGBA_INTEGER]=e.RGBA32UI,r[ht.RGB_INTEGER]=e.RGB32UI,r[ht.RG_INTEGER]=e.RG32UI,r[ht.RED_INTEGER]=e.R32UI,r[ht.DEPTH_COMPONENT]=e.DEPTH_COMPONENT24,r),g[Et.INT]=(o={},o[ht.RGBA_INTEGER]=e.RGBA32I,o[ht.RGB_INTEGER]=e.RGB32I,o[ht.RG_INTEGER]=e.RG32I,o[ht.RED_INTEGER]=e.R32I,o),g[Et.FLOAT]=(A={},A[ht.RGBA]=e.RGBA32F,A[ht.RGB]=e.RGB32F,A[ht.RG]=e.RG32F,A[ht.RED]=e.R32F,A[ht.DEPTH_COMPONENT]=e.DEPTH_COMPONENT32F,A),g[Et.HALF_FLOAT]=(s={},s[ht.RGBA]=e.RGBA16F,s[ht.RGB]=e.RGB16F,s[ht.RG]=e.RG16F,s[ht.RED]=e.R16F,s),g[Et.UNSIGNED_SHORT_5_6_5]=(a={},a[ht.RGB]=e.RGB565,a),g[Et.UNSIGNED_SHORT_4_4_4_4]=(l={},l[ht.RGBA]=e.RGBA4,l),g[Et.UNSIGNED_SHORT_5_5_5_1]=(c={},c[ht.RGBA]=e.RGB5_A1,c),g[Et.UNSIGNED_INT_2_10_10_10_REV]=(u={},u[ht.RGBA]=e.RGB10_A2,u[ht.RGBA_INTEGER]=e.RGB10_A2UI,u),g[Et.UNSIGNED_INT_10F_11F_11F_REV]=(d={},d[ht.RGB]=e.R11F_G11F_B10F,d),g[Et.UNSIGNED_INT_5_9_9_9_REV]=(h={},h[ht.RGB]=e.RGB9_E5,h),g[Et.UNSIGNED_INT_24_8]=(m={},m[ht.DEPTH_STENCIL]=e.DEPTH24_STENCIL8,m),g[Et.FLOAT_32_UNSIGNED_INT_24_8_REV]=(f={},f[ht.DEPTH_STENCIL]=e.DEPTH32F_STENCIL8,f),g):G=(b={},b[Et.UNSIGNED_BYTE]=(p={},p[ht.RGBA]=e.RGBA,p[ht.RGB]=e.RGB,p[ht.ALPHA]=e.ALPHA,p[ht.LUMINANCE]=e.LUMINANCE,p[ht.LUMINANCE_ALPHA]=e.LUMINANCE_ALPHA,p),b[Et.UNSIGNED_SHORT_5_6_5]=(y={},y[ht.RGB]=e.RGB,y),b[Et.UNSIGNED_SHORT_4_4_4_4]=(Z={},Z[ht.RGBA]=e.RGBA,Z),b[Et.UNSIGNED_SHORT_5_5_5_1]=(B={},B[ht.RGBA]=e.RGBA,B),b),G}var n1=function(){function e(g){this.texture=g,this.width=-1,this.height=-1,this.dirtyId=-1,this.dirtyStyleId=-1,this.mipmap=!1,this.wrapMode=33071,this.type=Et.UNSIGNED_BYTE,this.internalFormat=ht.RGBA,this.samplerType=0}return e}(),TL=function(){function e(g){this.renderer=g,this.boundTextures=[],this.currentLocation=-1,this.managedTextures=[],this._unknownBoundTextures=!1,this.unknownTexture=new yg,this.hasIntegerTextures=!1}return e.prototype.contextChange=function(){var g=this.gl=this.renderer.gl;this.CONTEXT_UID=this.renderer.CONTEXT_UID,this.webGLVersion=this.renderer.context.webGLVersion,this.internalFormats=LMe(g);var I=g.getParameter(g.MAX_TEXTURE_IMAGE_UNITS);this.boundTextures.length=I;for(var i=0;i=0;--r){var o=i[r];if(o){var A=o._glTextures[C];A.samplerType!==xv.FLOAT&&this.renderer.texture.unbind(o)}}},e.prototype.initTexture=function(g){var I=new n1(this.gl.createTexture());return I.dirtyId=-1,g._glTextures[this.CONTEXT_UID]=I,this.managedTextures.push(g),g.on("dispose",this.destroyTexture,this),I},e.prototype.initTextureType=function(g,I){var i,n;I.internalFormat=(n=(i=this.internalFormats[g.type])===null||i===void 0?void 0:i[g.format])!==null&&n!==void 0?n:g.format,this.webGLVersion===2&&g.type===Et.HALF_FLOAT?I.type=this.gl.HALF_FLOAT:I.type=g.type},e.prototype.updateTexture=function(g){var I=g._glTextures[this.CONTEXT_UID];if(I){var i=this.renderer;if(this.initTextureType(g,I),g.resource&&g.resource.upload(i,g,I))I.samplerType!==xv.FLOAT&&(this.hasIntegerTextures=!0);else{var n=g.realWidth,C=g.realHeight,r=i.gl;(I.width!==n||I.height!==C||I.dirtyId<0)&&(I.width=n,I.height=C,r.texImage2D(g.target,0,I.internalFormat,n,C,0,g.format,I.type,null))}g.dirtyStyleId!==I.dirtyStyleId&&this.updateTextureStyle(g),I.dirtyId=g.dirtyId}},e.prototype.destroyTexture=function(g,I){var i=this.gl;if(g=g.castToBaseTexture(),g._glTextures[this.CONTEXT_UID]&&(this.unbind(g),i.deleteTexture(g._glTextures[this.CONTEXT_UID].texture),g.off("dispose",this.destroyTexture,this),delete g._glTextures[this.CONTEXT_UID],!I)){var n=this.managedTextures.indexOf(g);n!==-1&&hd(this.managedTextures,n,1)}},e.prototype.updateTextureStyle=function(g){var I=g._glTextures[this.CONTEXT_UID];I&&((g.mipmap===eo.POW2||this.webGLVersion!==2)&&!g.isPowerOfTwo?I.mipmap=!1:I.mipmap=g.mipmap>=1,this.webGLVersion!==2&&!g.isPowerOfTwo?I.wrapMode=$o.CLAMP:I.wrapMode=g.wrapMode,g.resource&&g.resource.style(this.renderer,g,I)||this.setStyle(g,I),I.dirtyStyleId=g.dirtyStyleId)},e.prototype.setStyle=function(g,I){var i=this.gl;if(I.mipmap&&g.mipmap!==eo.ON_MANUAL&&i.generateMipmap(g.target),i.texParameteri(g.target,i.TEXTURE_WRAP_S,I.wrapMode),i.texParameteri(g.target,i.TEXTURE_WRAP_T,I.wrapMode),I.mipmap){i.texParameteri(g.target,i.TEXTURE_MIN_FILTER,g.scaleMode===Oo.LINEAR?i.LINEAR_MIPMAP_LINEAR:i.NEAREST_MIPMAP_NEAREST);var n=this.renderer.context.extensions.anisotropicFiltering;if(n&&g.anisotropicLevel>0&&g.scaleMode===Oo.LINEAR){var C=Math.min(g.anisotropicLevel,i.getParameter(n.MAX_TEXTURE_MAX_ANISOTROPY_EXT));i.texParameterf(g.target,n.TEXTURE_MAX_ANISOTROPY_EXT,C)}}else i.texParameteri(g.target,i.TEXTURE_MIN_FILTER,g.scaleMode===Oo.LINEAR?i.LINEAR:i.NEAREST);i.texParameteri(g.target,i.TEXTURE_MAG_FILTER,g.scaleMode===Oo.LINEAR?i.LINEAR:i.NEAREST)},e.prototype.destroy=function(){this.renderer=null},e}(),ame={__proto__:null,FilterSystem:bL,BatchSystem:yL,ContextSystem:ZL,FramebufferSystem:GL,GeometrySystem:vL,MaskSystem:BL,ScissorSystem:SL,StencilSystem:wL,ProjectionSystem:VL,RenderTextureSystem:RL,ShaderSystem:WL,StateSystem:XL,TextureGCSystem:HL,TextureSystem:TL},rK=new fi,sme=function(e){oI(g,e);function g(I,i){I===void 0&&(I=$p.UNKNOWN);var n=e.call(this)||this;return i=Object.assign({},yt.RENDER_OPTIONS,i),n.options=i,n.type=I,n.screen=new vg(0,0,i.width,i.height),n.view=i.view||yt.ADAPTER.createCanvas(),n.resolution=i.resolution||yt.RESOLUTION,n.useContextAlpha=i.useContextAlpha,n.autoDensity=!!i.autoDensity,n.preserveDrawingBuffer=i.preserveDrawingBuffer,n.clearBeforeRender=i.clearBeforeRender,n._backgroundColor=0,n._backgroundColorRgba=[0,0,0,1],n._backgroundColorString="#000000",n.backgroundColor=i.backgroundColor||n._backgroundColor,n.backgroundAlpha=i.backgroundAlpha,i.transparent!==void 0&&(IC("6.0.0","Option transparent is deprecated, please use backgroundAlpha instead."),n.useContextAlpha=i.transparent,n.backgroundAlpha=i.transparent?0:1),n._lastObjectRendered=null,n.plugins={},n}return g.prototype.initPlugins=function(I){for(var i in I)this.plugins[i]=new I[i](this)},Object.defineProperty(g.prototype,"width",{get:function(){return this.view.width},enumerable:!1,configurable:!0}),Object.defineProperty(g.prototype,"height",{get:function(){return this.view.height},enumerable:!1,configurable:!0}),g.prototype.resize=function(I,i){this.view.width=Math.round(I*this.resolution),this.view.height=Math.round(i*this.resolution);var n=this.view.width/this.resolution,C=this.view.height/this.resolution;this.screen.width=n,this.screen.height=C,this.autoDensity&&(this.view.style.width=n+"px",this.view.style.height=C+"px"),this.emit("resize",n,C)},g.prototype.generateTexture=function(I,i,n,C){i===void 0&&(i={}),typeof i=="number"&&(IC("6.1.0","generateTexture options (scaleMode, resolution, region) are now object options."),i={scaleMode:i,resolution:n,region:C});var r=i.region,o=AMe(i,["region"]);C=r||I.getLocalBounds(null,!0),C.width===0&&(C.width=1),C.height===0&&(C.height=1);var A=Ws.create(NE({width:C.width,height:C.height},o));return rK.tx=-C.x,rK.ty=-C.y,this.render(I,{renderTexture:A,clear:!1,transform:rK,skipUpdateTransform:!!I.parent}),A},g.prototype.destroy=function(I){for(var i in this.plugins)this.plugins[i].destroy(),this.plugins[i]=null;I&&this.view.parentNode&&this.view.parentNode.removeChild(this.view);var n=this;n.plugins=null,n.type=$p.UNKNOWN,n.view=null,n.screen=null,n._tempDisplayObjectParent=null,n.options=null,this._backgroundColorRgba=null,this._backgroundColorString=null,this._lastObjectRendered=null},Object.defineProperty(g.prototype,"backgroundColor",{get:function(){return this._backgroundColor},set:function(I){this._backgroundColor=I,this._backgroundColorString=IL(I),Dd(I,this._backgroundColorRgba)},enumerable:!1,configurable:!0}),Object.defineProperty(g.prototype,"backgroundAlpha",{get:function(){return this._backgroundColorRgba[3]},set:function(I){this._backgroundColorRgba[3]=I},enumerable:!1,configurable:!0}),g}(l0),UMe=function(){function e(g){this.buffer=g||null,this.updateID=-1,this.byteLength=-1,this.refCount=0}return e}(),QMe=function(){function e(g){this.renderer=g,this.managedBuffers={},this.boundBufferBases={}}return e.prototype.destroy=function(){this.renderer=null},e.prototype.contextChange=function(){this.disposeAll(!0),this.gl=this.renderer.gl,this.CONTEXT_UID=this.renderer.CONTEXT_UID},e.prototype.bind=function(g){var I=this,i=I.gl,n=I.CONTEXT_UID,C=g._glBuffers[n]||this.createGLBuffer(g);i.bindBuffer(g.type,C.buffer)},e.prototype.bindBufferBase=function(g,I){var i=this,n=i.gl,C=i.CONTEXT_UID;if(this.boundBufferBases[I]!==g){var r=g._glBuffers[C]||this.createGLBuffer(g);this.boundBufferBases[I]=g,n.bindBufferBase(n.UNIFORM_BUFFER,I,r.buffer)}},e.prototype.bindBufferRange=function(g,I,i){var n=this,C=n.gl,r=n.CONTEXT_UID;i=i||0;var o=g._glBuffers[r]||this.createGLBuffer(g);C.bindBufferRange(C.UNIFORM_BUFFER,I||0,o.buffer,i*256,256)},e.prototype.update=function(g){var I=this,i=I.gl,n=I.CONTEXT_UID,C=g._glBuffers[n];if(g._updateID!==C.updateID)if(C.updateID=g._updateID,i.bindBuffer(g.type,C.buffer),C.byteLength>=g.data.byteLength)i.bufferSubData(g.type,0,g.data);else{var r=g.static?i.STATIC_DRAW:i.DYNAMIC_DRAW;C.byteLength=g.data.byteLength,i.bufferData(g.type,g.data,r)}},e.prototype.dispose=function(g,I){if(this.managedBuffers[g.id]){delete this.managedBuffers[g.id];var i=g._glBuffers[this.CONTEXT_UID],n=this.gl;g.disposeRunner.remove(this),i&&(I||n.deleteBuffer(i.buffer),delete g._glBuffers[this.CONTEXT_UID])}},e.prototype.disposeAll=function(g){for(var I=Object.keys(this.managedBuffers),i=0;i=mI.HIGH?this.multisample=mI.HIGH:i>=mI.MEDIUM?this.multisample=mI.MEDIUM:i>=mI.LOW?this.multisample=mI.LOW:this.multisample=mI.NONE},g.prototype.addSystem=function(I,i){var n=new I(this);if(this[i])throw new Error('Whoops! The name "'+i+'" is already in use');this[i]=n;for(var C in this.runners)this.runners[C].add(n);return this},g.prototype.render=function(I,i){var n,C,r,o;if(i&&(i instanceof Ws?(IC("6.0.0","Renderer#render arguments changed, use options instead."),n=i,C=arguments[2],r=arguments[3],o=arguments[4]):(n=i.renderTexture,C=i.clear,r=i.transform,o=i.skipUpdateTransform)),this.renderingToScreen=!n,this.runners.prerender.emit(),this.emit("prerender"),this.projection.transform=r,!this.context.isLost){if(n||(this._lastObjectRendered=I),!o){var A=I.enableTempParent();I.updateTransform(),I.disableTempParent(A)}this.renderTexture.bind(n),this.batch.currentRenderer.start(),(C!==void 0?C:this.clearBeforeRender)&&this.renderTexture.clear(),I.render(this),this.batch.currentRenderer.flush(),n&&n.baseTexture.update(),this.runners.postrender.emit(),this.projection.transform=null,this.emit("postrender")}},g.prototype.generateTexture=function(I,i,n,C){i===void 0&&(i={});var r=e.prototype.generateTexture.call(this,I,i,n,C);return this.framebuffer.blit(),r},g.prototype.resize=function(I,i){e.prototype.resize.call(this,I,i),this.runners.resize.emit(this.screen.height,this.screen.width)},g.prototype.reset=function(){return this.runners.reset.emit(),this},g.prototype.clear=function(){this.renderTexture.bind(),this.renderTexture.clear()},g.prototype.destroy=function(I){this.runners.destroy.emit();for(var i in this.runners)this.runners[i].destroy();e.prototype.destroy.call(this,I),this.gl=null},Object.defineProperty(g.prototype,"extract",{get:function(){return IC("6.0.0","Renderer#extract has been deprecated, please use Renderer#plugins.extract instead."),this.plugins.extract},enumerable:!1,configurable:!0}),g.registerPlugin=function(I,i){IC("6.5.0","Renderer.registerPlugin() has been deprecated, please use extensions.add() instead."),ba.add({name:I,type:Pg.RendererPlugin,ref:i})},g.__plugins={},g}(sme);ba.handleByMap(Pg.RendererPlugin,NL.__plugins);function lme(e){return NL.create(e)}var jMe=`attribute vec2 aVertexPosition; attribute vec2 aTextureCoord; uniform mat3 projectionMatrix; @@ -536,7 +568,7 @@ void main(void) { gl_Position = vec4((projectionMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0); vTextureCoord = aTextureCoord; -}`,bEe=`attribute vec2 aVertexPosition; +}`,$Me=`attribute vec2 aVertexPosition; uniform mat3 projectionMatrix; @@ -562,404 +594,389 @@ void main(void) gl_Position = filterVertexPosition(); vTextureCoord = filterTextureCoord(); } -`;const Ife=pEe,oU=bEe;class AU{constructor(e){this.renderer=e}contextChange(e){let I;if(this.renderer.context.webGLVersion===1){const i=e.getParameter(e.FRAMEBUFFER_BINDING);e.bindFramebuffer(e.FRAMEBUFFER,null),I=e.getParameter(e.SAMPLES),e.bindFramebuffer(e.FRAMEBUFFER,i)}else{const i=e.getParameter(e.DRAW_FRAMEBUFFER_BINDING);e.bindFramebuffer(e.DRAW_FRAMEBUFFER,null),I=e.getParameter(e.SAMPLES),e.bindFramebuffer(e.DRAW_FRAMEBUFFER,i)}I>=Ci.HIGH?this.multisample=Ci.HIGH:I>=Ci.MEDIUM?this.multisample=Ci.MEDIUM:I>=Ci.LOW?this.multisample=Ci.LOW:this.multisample=Ci.NONE}destroy(){}}AU.extension={type:pt.RendererSystem,name:"_multisample"};kt.add(AU);class yEe{constructor(e){this.buffer=e||null,this.updateID=-1,this.byteLength=-1,this.refCount=0}}class aU{constructor(e){this.renderer=e,this.managedBuffers={},this.boundBufferBases={}}destroy(){this.renderer=null}contextChange(){this.disposeAll(!0),this.gl=this.renderer.gl,this.CONTEXT_UID=this.renderer.CONTEXT_UID}bind(e){const{gl:I,CONTEXT_UID:i}=this,n=e._glBuffers[i]||this.createGLBuffer(e);I.bindBuffer(e.type,n.buffer)}unbind(e){const{gl:I}=this;I.bindBuffer(e,null)}bindBufferBase(e,I){const{gl:i,CONTEXT_UID:n}=this;if(this.boundBufferBases[I]!==e){const C=e._glBuffers[n]||this.createGLBuffer(e);this.boundBufferBases[I]=e,i.bindBufferBase(i.UNIFORM_BUFFER,I,C.buffer)}}bindBufferRange(e,I,i){const{gl:n,CONTEXT_UID:C}=this;i=i||0;const r=e._glBuffers[C]||this.createGLBuffer(e);n.bindBufferRange(n.UNIFORM_BUFFER,I||0,r.buffer,i*256,256)}update(e){const{gl:I,CONTEXT_UID:i}=this,n=e._glBuffers[i]||this.createGLBuffer(e);if(e._updateID!==n.updateID)if(n.updateID=e._updateID,I.bindBuffer(e.type,n.buffer),n.byteLength>=e.data.byteLength)I.bufferSubData(e.type,0,e.data);else{const C=e.static?I.STATIC_DRAW:I.DYNAMIC_DRAW;n.byteLength=e.data.byteLength,I.bufferData(e.type,e.data,C)}}dispose(e,I){if(!this.managedBuffers[e.id])return;delete this.managedBuffers[e.id];const i=e._glBuffers[this.CONTEXT_UID],n=this.gl;e.disposeRunner.remove(this),i&&(I||n.deleteBuffer(i.buffer),delete e._glBuffers[this.CONTEXT_UID])}disposeAll(e){const I=Object.keys(this.managedBuffers);for(let i=0;iI.resource).filter(I=>I).map(I=>I.load());return this._load=Promise.all(e).then(()=>{const{realWidth:I,realHeight:i}=this.items[0];return this.resize(I,i),this.update(),Promise.resolve(this)}),this._load}}class ife extends lU{constructor(e,I){const{width:i,height:n}=I||{};let C,r;Array.isArray(e)?(C=e,r=e.length):r=e,super(r,{width:i,height:n}),C&&this.initFromArray(C,I)}addBaseTextureAt(e,I){if(e.resource)this.addResourceAt(e.resource,I);else throw new Error("ArrayResource does not support RenderTexture");return this}bind(e){super.bind(e),e.target=Xd.TEXTURE_2D_ARRAY}upload(e,I,i){const{length:n,itemDirtyIds:C,items:r}=this,{gl:o}=e;i.dirtyId<0&&o.texImage3D(o.TEXTURE_2D_ARRAY,0,i.internalFormat,this._width,this._height,n,0,I.format,i.type,null);for(let A=0;A0)if(e.resource)this.addResourceAt(e.resource,I);else throw new Error("CubeResource does not support copying of renderTexture.");else e.target=Xd.TEXTURE_CUBE_MAP_POSITIVE_X+I,e.parentTextureArray=this.baseTexture,this.items[I]=e;return e.valid&&!this.valid&&this.resize(e.realWidth,e.realHeight),this.items[I]=e,this}upload(e,I,i){const n=this.itemDirtyIds;for(let C=0;C{if(this.url===null){e(this);return}try{const i=await Gt.ADAPTER.fetch(this.url,{mode:this.crossOrigin?"cors":"no-cors"});if(this.destroyed)return;const n=await i.blob();if(this.destroyed)return;const C=await createImageBitmap(n,{premultiplyAlpha:this.alphaMode===null||this.alphaMode===tC.UNPACK?"premultiply":"none"});if(this.destroyed){C.close();return}this.source=C,this.update(),e(this)}catch(i){if(this.destroyed)return;I(i),this.onError.emit(i)}}),this._load)}upload(e,I,i){return this.source instanceof ImageBitmap?(typeof this.alphaMode=="number"&&(I.alphaMode=this.alphaMode),super.upload(e,I,i)):(this.load(),!1)}dispose(){this.ownsImageBitmap&&this.source instanceof ImageBitmap&&this.source.close(),super.dispose(),this._load=null}static test(e){return!!globalThis.createImageBitmap&&typeof ImageBitmap<"u"&&(typeof e=="string"||e instanceof ImageBitmap)}static get EMPTY(){return hd._EMPTY=hd._EMPTY??Gt.ADAPTER.createCanvas(0,0),hd._EMPTY}}const VM=class D1 extends Ms{constructor(e,I){I=I||{},super(Gt.ADAPTER.createCanvas()),this._width=0,this._height=0,this.svg=e,this.scale=I.scale||1,this._overrideWidth=I.width,this._overrideHeight=I.height,this._resolve=null,this._crossorigin=I.crossorigin,this._load=null,I.autoLoad!==!1&&this.load()}load(){return this._load?this._load:(this._load=new Promise(e=>{if(this._resolve=()=>{this.update(),e(this)},D1.SVG_XML.test(this.svg.trim())){if(!btoa)throw new Error("Your browser doesn't support base64 conversions.");this.svg=`data:image/svg+xml;base64,${btoa(unescape(encodeURIComponent(this.svg)))}`}this._loadSvg()}),this._load)}_loadSvg(){const e=new Image;Ms.crossOrigin(e,this.svg,this._crossorigin),e.src=this.svg,e.onerror=I=>{this._resolve&&(e.onerror=null,this.onError.emit(I))},e.onload=()=>{if(!this._resolve)return;const I=e.width,i=e.height;if(!I||!i)throw new Error("The SVG image must have width and height defined (in pixels), canvas API needs them.");let n=I*this.scale,C=i*this.scale;(this._overrideWidth||this._overrideHeight)&&(n=this._overrideWidth||this._overrideHeight/i*I,C=this._overrideHeight||this._overrideWidth/I*i),n=Math.round(n),C=Math.round(C);const r=this.source;r.width=n,r.height=C,r._pixiId=`canvas_${gu()}`,r.getContext("2d").drawImage(e,0,0,I,i,0,0,n,C),this._resolve(),this._resolve=null}}static getSize(e){const I=D1.SVG_SIZE.exec(e),i={};return I&&(i[I[1]]=Math.round(parseFloat(I[3])),i[I[5]]=Math.round(parseFloat(I[7]))),i}dispose(){super.dispose(),this._resolve=null,this._crossorigin=null}static test(e,I){return I==="svg"||typeof e=="string"&&e.startsWith("data:image/svg+xml")||typeof e=="string"&&D1.SVG_XML.test(e)}};VM.SVG_XML=/^(<\?xml[^?]+\?>)?\s*()]*-->)?\s*\]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i;let FX=VM;const RM=class WM extends Ms{constructor(e,I){if(I=I||{},!(e instanceof HTMLVideoElement)){const i=document.createElement("video");I.autoLoad!==!1&&i.setAttribute("preload","auto"),I.playsinline!==!1&&(i.setAttribute("webkit-playsinline",""),i.setAttribute("playsinline","")),I.muted===!0&&(i.setAttribute("muted",""),i.muted=!0),I.loop===!0&&i.setAttribute("loop",""),I.autoPlay!==!1&&i.setAttribute("autoplay",""),typeof e=="string"&&(e=[e]);const n=e[0].src||e[0];Ms.crossOrigin(i,n,I.crossorigin);for(let C=0;C{this.valid?I(this):(this._resolve=I,this._reject=i,e.load())}),this._load}_onError(e){this.source.removeEventListener("error",this._onError,!0),this.onError.emit(e),this._reject&&(this._reject(e),this._reject=null,this._resolve=null)}_isSourcePlaying(){const e=this.source;return!e.paused&&!e.ended}_isSourceReady(){return this.source.readyState>2}_onPlayStart(){this.valid||this._onCanPlay(),this._configureAutoUpdate()}_onPlayStop(){this._configureAutoUpdate()}_onSeeked(){this._autoUpdate&&!this._isSourcePlaying()&&(this._msToNextUpdate=0,this.update(),this._msToNextUpdate=0)}_onCanPlay(){const e=this.source;e.removeEventListener("canplay",this._onCanPlay),e.removeEventListener("canplaythrough",this._onCanPlay);const I=this.valid;this._msToNextUpdate=0,this.update(),this._msToNextUpdate=0,!I&&this._resolve&&(this._resolve(this),this._resolve=null,this._reject=null),this._isSourcePlaying()?this._onPlayStart():this.autoPlay&&e.play()}dispose(){this._configureAutoUpdate();const e=this.source;e&&(e.removeEventListener("play",this._onPlayStart),e.removeEventListener("pause",this._onPlayStop),e.removeEventListener("seeked",this._onSeeked),e.removeEventListener("canplay",this._onCanPlay),e.removeEventListener("canplaythrough",this._onCanPlay),e.removeEventListener("error",this._onError,!0),e.pause(),e.src="",e.load()),super.dispose()}get autoUpdate(){return this._autoUpdate}set autoUpdate(e){e!==this._autoUpdate&&(this._autoUpdate=e,this._configureAutoUpdate())}get updateFPS(){return this._updateFPS}set updateFPS(e){e!==this._updateFPS&&(this._updateFPS=e,this._configureAutoUpdate())}_configureAutoUpdate(){this._autoUpdate&&this._isSourcePlaying()?!this._updateFPS&&this.source.requestVideoFrameCallback?(this._isConnectedToTicker&&(Ji.shared.remove(this.update,this),this._isConnectedToTicker=!1,this._msToNextUpdate=0),this._videoFrameRequestCallbackHandle===null&&(this._videoFrameRequestCallbackHandle=this.source.requestVideoFrameCallback(this._videoFrameRequestCallback))):(this._videoFrameRequestCallbackHandle!==null&&(this.source.cancelVideoFrameCallback(this._videoFrameRequestCallbackHandle),this._videoFrameRequestCallbackHandle=null),this._isConnectedToTicker||(Ji.shared.add(this.update,this),this._isConnectedToTicker=!0,this._msToNextUpdate=0)):(this._videoFrameRequestCallbackHandle!==null&&(this.source.cancelVideoFrameCallback(this._videoFrameRequestCallbackHandle),this._videoFrameRequestCallbackHandle=null),this._isConnectedToTicker&&(Ji.shared.remove(this.update,this),this._isConnectedToTicker=!1,this._msToNextUpdate=0))}static test(e,I){return globalThis.HTMLVideoElement&&e instanceof HTMLVideoElement||WM.TYPES.includes(I)}};RM.TYPES=["mp4","m4v","webm","ogg","ogv","h264","avi","mov"],RM.MIME_TYPES={ogv:"video/ogg",mov:"video/quicktime",m4v:"video/mp4"};let cU=RM;YX.push(hd,O_,nfe,cU,FX,TS,rfe,ife);class ZEe{constructor(){this._glTransformFeedbacks={},this.buffers=[],this.disposeRunner=new dr("disposeTransformFeedback")}bindBuffer(e,I){this.buffers[e]=I}destroy(){this.disposeRunner.emit(this,!1)}}const ofe="7.3.2";class pv{constructor(){this.minX=1/0,this.minY=1/0,this.maxX=-1/0,this.maxY=-1/0,this.rect=null,this.updateID=-1}isEmpty(){return this.minX>this.maxX||this.minY>this.maxY}clear(){this.minX=1/0,this.minY=1/0,this.maxX=-1/0,this.maxY=-1/0}getRectangle(e){return this.minX>this.maxX||this.minY>this.maxY?rg.EMPTY:(e=e||new rg(0,0,1,1),e.x=this.minX,e.y=this.minY,e.width=this.maxX-this.minX,e.height=this.maxY-this.minY,e)}addPoint(e){this.minX=Math.min(this.minX,e.x),this.maxX=Math.max(this.maxX,e.x),this.minY=Math.min(this.minY,e.y),this.maxY=Math.max(this.maxY,e.y)}addPointMatrix(e,I){const{a:i,b:n,c:C,d:r,tx:o,ty:A}=e,s=i*I.x+C*I.y+o,a=n*I.x+r*I.y+A;this.minX=Math.min(this.minX,s),this.maxX=Math.max(this.maxX,s),this.minY=Math.min(this.minY,a),this.maxY=Math.max(this.maxY,a)}addQuad(e){let I=this.minX,i=this.minY,n=this.maxX,C=this.maxY,r=e[0],o=e[1];I=rn?r:n,C=o>C?o:C,r=e[2],o=e[3],I=rn?r:n,C=o>C?o:C,r=e[4],o=e[5],I=rn?r:n,C=o>C?o:C,r=e[6],o=e[7],I=rn?r:n,C=o>C?o:C,this.minX=I,this.minY=i,this.maxX=n,this.maxY=C}addFrame(e,I,i,n,C){this.addFrameMatrix(e.worldTransform,I,i,n,C)}addFrameMatrix(e,I,i,n,C){const r=e.a,o=e.b,A=e.c,s=e.d,a=e.tx,l=e.ty;let c=this.minX,u=this.minY,d=this.maxX,h=this.maxY,m=r*I+A*i+a,f=o*I+s*i+l;c=md?m:d,h=f>h?f:h,m=r*n+A*i+a,f=o*n+s*i+l,c=md?m:d,h=f>h?f:h,m=r*I+A*C+a,f=o*I+s*C+l,c=md?m:d,h=f>h?f:h,m=r*n+A*C+a,f=o*n+s*C+l,c=md?m:d,h=f>h?f:h,this.minX=c,this.minY=u,this.maxX=d,this.maxY=h}addVertexData(e,I,i){let n=this.minX,C=this.minY,r=this.maxX,o=this.maxY;for(let A=I;Ar?s:r,o=a>o?a:o}this.minX=n,this.minY=C,this.maxX=r,this.maxY=o}addVertices(e,I,i,n){this.addVerticesMatrix(e.worldTransform,I,i,n)}addVerticesMatrix(e,I,i,n,C=0,r=C){const o=e.a,A=e.b,s=e.c,a=e.d,l=e.tx,c=e.ty;let u=this.minX,d=this.minY,h=this.maxX,m=this.maxY;for(let f=i;fn?e.maxX:n,this.maxY=e.maxY>C?e.maxY:C}addBoundsMask(e,I){const i=e.minX>I.minX?e.minX:I.minX,n=e.minY>I.minY?e.minY:I.minY,C=e.maxXs?C:s,this.maxY=r>a?r:a}}addBoundsMatrix(e,I){this.addFrameMatrix(I,e.minX,e.minY,e.maxX,e.maxY)}addBoundsArea(e,I){const i=e.minX>I.x?e.minX:I.x,n=e.minY>I.y?e.minY:I.y,C=e.maxXs?C:s,this.maxY=r>a?r:a}}pad(e=0,I=e){this.isEmpty()||(this.minX-=e,this.maxX+=e,this.minY-=I,this.maxY+=I)}addFramePad(e,I,i,n,C,r){e-=C,I-=r,i+=C,n+=r,this.minX=this.minXi?this.maxX:i,this.minY=this.minYn?this.maxY:n}}class HI extends T0{constructor(){super(),this.tempDisplayObjectParent=null,this.transform=new YS,this.alpha=1,this.visible=!0,this.renderable=!0,this.cullable=!1,this.cullArea=null,this.parent=null,this.worldAlpha=1,this._lastSortedIndex=0,this._zIndex=0,this.filterArea=null,this.filters=null,this._enabledFilters=null,this._bounds=new pv,this._localBounds=null,this._boundsID=0,this._boundsRect=null,this._localBoundsRect=null,this._mask=null,this._maskRefCount=0,this._destroyed=!1,this.isSprite=!1,this.isMask=!1}static mixin(e){const I=Object.keys(e);for(let i=0;i1)for(let I=0;Ithis.children.length)throw new Error(`${e}addChildAt: The index ${I} supplied is out of bounds ${this.children.length}`);return e.parent&&e.parent.removeChild(e),e.parent=this,this.sortDirty=!0,e.transform._parentID=-1,this.children.splice(I,0,e),this._boundsID++,this.onChildrenChange(I),e.emit("added",this),this.emit("childAdded",e,this,I),e}swapChildren(e,I){if(e===I)return;const i=this.getChildIndex(e),n=this.getChildIndex(I);this.children[i]=I,this.children[n]=e,this.onChildrenChange(i=this.children.length)throw new Error(`The index ${I} supplied is out of bounds ${this.children.length}`);const i=this.getChildIndex(e);Nd(this.children,i,1),this.children.splice(I,0,e),this.onChildrenChange(I)}getChildAt(e){if(e<0||e>=this.children.length)throw new Error(`getChildAt: Index (${e}) does not exist.`);return this.children[e]}removeChild(...e){if(e.length>1)for(let I=0;I0&&C<=n){r=this.children.splice(i,C);for(let o=0;o1&&this.children.sort(BEe),this.sortDirty=!1}updateTransform(){this.sortableChildren&&this.sortDirty&&this.sortChildren(),this._boundsID++,this.transform.updateTransform(this.parent.transform),this.worldAlpha=this.alpha*this.parent.worldAlpha;for(let e=0,I=this.children.length;e0&&I.height>0))return;let i,n;this.cullArea?(i=this.cullArea,n=this.worldTransform):this._render!==XM.prototype._render&&(i=this.getBounds(!0));const C=e.projection.transform;if(C&&(n?(n=GEe.copyFrom(n),n.prepend(C)):n=C),i&&I.intersects(i,n))this._render(e);else if(this.cullArea)return;for(let r=0,o=this.children.length;r=n&&Dy.x=C&&Dy.y=I&&(r=g-o-1),A=A.replace("%value%",e[r].toString()),n+=A,n+=` -`}return i=i.replace("%blur%",n),i=i.replace("%size%",g.toString()),i}const XEe=` - attribute vec2 aVertexPosition; - - uniform mat3 projectionMatrix; - - uniform float strength; - - varying vec2 vBlurTexCoords[%size%]; +`,cme=jMe,kL=$Me,qMe=function(){function e(g){IC("6.1.0","System class is deprecated, implemement ISystem interface instead."),this.renderer=g}return e.prototype.destroy=function(){this.renderer=null},e}(),eX=function(){function e(){this.texArray=null,this.blend=0,this.type=Mr.TRIANGLES,this.start=0,this.size=0,this.data=null}return e}(),tX=function(){function e(){this.elements=[],this.ids=[],this.count=0}return e.prototype.clear=function(){for(var g=0;gthis.size&&this.flush(),this._vertexCount+=I.vertexData.length/2,this._indexCount+=I.indices.length,this._bufferedTextures[this._bufferSize]=I._texture.baseTexture,this._bufferedElements[this._bufferSize++]=I)},g.prototype.buildTexturesAndDrawCalls=function(){var I=this,i=I._bufferedTextures,n=I.MAX_TEXTURES,C=g._textureArrayPool,r=this.renderer.batch,o=this._tempBoundTextures,A=this.renderer.textureGC.count,s=++yg._globalBatch,a=0,l=C[0],c=0;r.copyBoundTextures(o,n);for(var u=0;u=n&&(r.boundArray(l,o,s,n),this.buildDrawCalls(l,c,u),c=u,l=C[++a],++s),d._batchEnabled=s,d.touched=A,l.elements[l.count++]=d)}l.count>0&&(r.boundArray(l,o,s,n),this.buildDrawCalls(l,c,this._bufferSize),++a,++s);for(var u=0;u0&&(I+=` +else `),i title : "+g.title+"
tabIndex: "+g.tabIndex},e.prototype.capHitArea=function(g){g.x<0&&(g.width+=g.x,g.x=0),g.y<0&&(g.height+=g.y,g.y=0);var I=this.renderer,i=I.width,n=I.height;g.x+g.width>i&&(g.width=i-g.x),g.y+g.height>n&&(g.height=n-g.y)},e.prototype.addChild=function(g){var I=this.pool.pop();I||(I=document.createElement("button"),I.style.width=rV+"px",I.style.height=rV+"px",I.style.backgroundColor=this.debug?"rgba(255,255,255,0.5)":"transparent",I.style.position="absolute",I.style.zIndex=vq.toString(),I.style.borderStyle="none",navigator.userAgent.toLowerCase().indexOf("chrome")>-1?I.setAttribute("aria-live","off"):I.setAttribute("aria-live","polite"),navigator.userAgent.match(/rv:.*Gecko\//)?I.setAttribute("aria-relevant","additions"):I.setAttribute("aria-relevant","text"),I.addEventListener("click",this._onClick.bind(this)),I.addEventListener("focus",this._onFocus.bind(this)),I.addEventListener("focusout",this._onFocusOut.bind(this))),I.style.pointerEvents=g.accessiblePointerEvents,I.type=g.accessibleType,g.accessibleTitle&&g.accessibleTitle!==null?I.title=g.accessibleTitle:(!g.accessibleHint||g.accessibleHint===null)&&(I.title="displayObject "+g.tabIndex),g.accessibleHint&&g.accessibleHint!==null&&I.setAttribute("aria-label",g.accessibleHint),this.debug&&this.updateDebugHTML(I),g._accessibleActive=!0,g._accessibleDiv=I,I.displayObject=g,this.children.push(g),this.div.appendChild(g._accessibleDiv),g._accessibleDiv.tabIndex=g.tabIndex},e.prototype._onClick=function(g){var I=this.renderer.plugins.interaction,i=g.target.displayObject,n=I.eventData;I.dispatchEvent(i,"click",n),I.dispatchEvent(i,"pointertap",n),I.dispatchEvent(i,"tap",n)},e.prototype._onFocus=function(g){g.target.getAttribute("aria-live")||g.target.setAttribute("aria-live","assertive");var I=this.renderer.plugins.interaction,i=g.target.displayObject,n=I.eventData;I.dispatchEvent(i,"mouseover",n)},e.prototype._onFocusOut=function(g){g.target.getAttribute("aria-live")||g.target.setAttribute("aria-live","polite");var I=this.renderer.plugins.interaction,i=g.target.displayObject,n=I.eventData;I.dispatchEvent(i,"mouseout",n)},e.prototype._onKeyDown=function(g){g.keyCode===g3e&&this.activate()},e.prototype._onMouseMove=function(g){g.movementX===0&&g.movementY===0||this.deactivate()},e.prototype.destroy=function(){this.destroyTouchHook(),this.div=null,globalThis.document.removeEventListener("mousemove",this._onMouseMove,!0),globalThis.removeEventListener("keydown",this._onKeyDown),this.pool=null,this.children=null,this.renderer=null},e.extension={name:"accessibility",type:[Pg.RendererPlugin,Pg.CanvasRendererPlugin]},e}();/*! + * @pixi/interaction - v6.5.10 + * Compiled Thu, 06 Jul 2023 15:25:11 UTC + * + * @pixi/interaction is licensed under the MIT License. + * http://www.opensource.org/licenses/mit-license + */var YE=function(){function e(){this.pressure=0,this.rotationAngle=0,this.twist=0,this.tangentialPressure=0,this.global=new rI,this.target=null,this.originalEvent=null,this.identifier=null,this.isPrimary=!1,this.button=0,this.buttons=0,this.width=0,this.height=0,this.tiltX=0,this.tiltY=0,this.pointerType=null,this.pressure=0,this.rotationAngle=0,this.twist=0,this.tangentialPressure=0}return Object.defineProperty(e.prototype,"pointerId",{get:function(){return this.identifier},enumerable:!1,configurable:!0}),e.prototype.getLocalPosition=function(g,I,i){return g.worldTransform.applyInverse(i||this.global,I)},e.prototype.copyEvent=function(g){"isPrimary"in g&&g.isPrimary&&(this.isPrimary=!0),this.button="button"in g&&g.button;var I="buttons"in g&&g.buttons;this.buttons=Number.isInteger(I)?I:"which"in g&&g.which,this.width="width"in g&&g.width,this.height="height"in g&&g.height,this.tiltX="tiltX"in g&&g.tiltX,this.tiltY="tiltY"in g&&g.tiltY,this.pointerType="pointerType"in g&&g.pointerType,this.pressure="pressure"in g&&g.pressure,this.rotationAngle="rotationAngle"in g&&g.rotationAngle,this.twist="twist"in g&&g.twist||0,this.tangentialPressure="tangentialPressure"in g&&g.tangentialPressure||0},e.prototype.reset=function(){this.isPrimary=!1},e}();/*! ***************************************************************************** +Copyright (c) Microsoft Corporation. + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +PERFORMANCE OF THIS SOFTWARE. +***************************************************************************** */var KE=function(e,g){return KE=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(I,i){I.__proto__=i}||function(I,i){for(var n in i)i.hasOwnProperty(n)&&(I[n]=i[n])},KE(e,g)};function o3e(e,g){KE(e,g);function I(){this.constructor=e}e.prototype=g===null?Object.create(g):(I.prototype=g.prototype,new I)}var Zme=function(){function e(){this.stopped=!1,this.stopsPropagatingAt=null,this.stopPropagationHint=!1,this.target=null,this.currentTarget=null,this.type=null,this.data=null}return e.prototype.stopPropagation=function(){this.stopped=!0,this.stopPropagationHint=!0,this.stopsPropagatingAt=this.currentTarget},e.prototype.reset=function(){this.stopped=!1,this.stopsPropagatingAt=null,this.stopPropagationHint=!1,this.currentTarget=null,this.target=null},e}(),C1=function(){function e(g){this._pointerId=g,this._flags=e.FLAGS.NONE}return e.prototype._doSet=function(g,I){I?this._flags=this._flags|g:this._flags=this._flags&~g},Object.defineProperty(e.prototype,"pointerId",{get:function(){return this._pointerId},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"flags",{get:function(){return this._flags},set:function(g){this._flags=g},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"none",{get:function(){return this._flags===e.FLAGS.NONE},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"over",{get:function(){return(this._flags&e.FLAGS.OVER)!==0},set:function(g){this._doSet(e.FLAGS.OVER,g)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"rightDown",{get:function(){return(this._flags&e.FLAGS.RIGHT_DOWN)!==0},set:function(g){this._doSet(e.FLAGS.RIGHT_DOWN,g)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"leftDown",{get:function(){return(this._flags&e.FLAGS.LEFT_DOWN)!==0},set:function(g){this._doSet(e.FLAGS.LEFT_DOWN,g)},enumerable:!1,configurable:!0}),e.FLAGS=Object.freeze({NONE:0,OVER:1,LEFT_DOWN:2,RIGHT_DOWN:4}),e}(),A3e=function(){function e(){this._tempPoint=new rI}return e.prototype.recursiveFindHit=function(g,I,i,n,C){var r;if(!I||!I.visible)return!1;var o=g.data.global;C=I.interactive||C;var A=!1,s=C,a=!0;if(I.hitArea)n&&(I.worldTransform.applyInverse(o,this._tempPoint),I.hitArea.contains(this._tempPoint.x,this._tempPoint.y)?A=!0:(n=!1,a=!1)),s=!1;else if(I._mask&&n){var l=I._mask.isMaskData?I._mask.maskObject:I._mask;l&&!(!((r=l.containsPoint)===null||r===void 0)&&r.call(l,o))&&(n=!1)}if(a&&I.interactiveChildren&&I.children)for(var c=I.children,u=c.length-1;u>=0;u--){var d=c[u],h=this.recursiveFindHit(g,d,i,n,s);if(h){if(!d.parent)continue;s=!1,h&&(g.target&&(n=!1),A=!0)}}return C&&(n&&!g.target&&!I.hitArea&&I.containsPoint&&I.containsPoint(o)&&(A=!0),I.interactive&&(A&&!g.target&&(g.target=I),i&&i(g,I,!!A))),A},e.prototype.findHit=function(g,I,i,n){this.recursiveFindHit(g,I,i,n,!1)},e}(),Gme={interactive:!1,interactiveChildren:!0,hitArea:null,get buttonMode(){return this.cursor==="pointer"},set buttonMode(e){e?this.cursor="pointer":this.cursor==="pointer"&&(this.cursor=null)},cursor:null,get trackedPointers(){return this._trackedPointers===void 0&&(this._trackedPointers={}),this._trackedPointers},_trackedPointers:void 0};jI.mixin(Gme);var oV=1,AV={target:null,data:{global:null}},vme=function(e){o3e(g,e);function g(I,i){var n=e.call(this)||this;return i=i||{},n.renderer=I,n.autoPreventDefault=i.autoPreventDefault!==void 0?i.autoPreventDefault:!0,n.interactionFrequency=i.interactionFrequency||10,n.mouse=new YE,n.mouse.identifier=oV,n.mouse.global.set(-999999),n.activeInteractionData={},n.activeInteractionData[oV]=n.mouse,n.interactionDataPool=[],n.eventData=new Zme,n.interactionDOMElement=null,n.moveWhenInside=!1,n.eventsAdded=!1,n.tickerAdded=!1,n.mouseOverRenderer=!("PointerEvent"in globalThis),n.supportsTouchEvents="ontouchstart"in globalThis,n.supportsPointerEvents=!!globalThis.PointerEvent,n.onPointerUp=n.onPointerUp.bind(n),n.processPointerUp=n.processPointerUp.bind(n),n.onPointerCancel=n.onPointerCancel.bind(n),n.processPointerCancel=n.processPointerCancel.bind(n),n.onPointerDown=n.onPointerDown.bind(n),n.processPointerDown=n.processPointerDown.bind(n),n.onPointerMove=n.onPointerMove.bind(n),n.processPointerMove=n.processPointerMove.bind(n),n.onPointerOut=n.onPointerOut.bind(n),n.processPointerOverOut=n.processPointerOverOut.bind(n),n.onPointerOver=n.onPointerOver.bind(n),n.cursorStyles={default:"inherit",pointer:"pointer"},n.currentCursorMode=null,n.cursor=null,n.resolution=1,n.delayedEvents=[],n.search=new A3e,n._tempDisplayObject=new aL,n._eventListenerOptions={capture:!0,passive:!1},n._useSystemTicker=i.useSystemTicker!==void 0?i.useSystemTicker:!0,n.setTargetElement(n.renderer.view,n.renderer.resolution),n}return Object.defineProperty(g.prototype,"useSystemTicker",{get:function(){return this._useSystemTicker},set:function(I){this._useSystemTicker=I,I?this.addTickerListener():this.removeTickerListener()},enumerable:!1,configurable:!0}),Object.defineProperty(g.prototype,"lastObjectRendered",{get:function(){return this.renderer._lastObjectRendered||this._tempDisplayObject},enumerable:!1,configurable:!0}),g.prototype.hitTest=function(I,i){return AV.target=null,AV.data.global=I,i||(i=this.lastObjectRendered),this.processInteractive(AV,i,null,!0),AV.target},g.prototype.setTargetElement=function(I,i){i===void 0&&(i=1),this.removeTickerListener(),this.removeEvents(),this.interactionDOMElement=I,this.resolution=i,this.addEvents(),this.addTickerListener()},g.prototype.addTickerListener=function(){this.tickerAdded||!this.interactionDOMElement||!this._useSystemTicker||(Pi.system.add(this.tickerUpdate,this,sa.INTERACTION),this.tickerAdded=!0)},g.prototype.removeTickerListener=function(){this.tickerAdded&&(Pi.system.remove(this.tickerUpdate,this),this.tickerAdded=!1)},g.prototype.addEvents=function(){if(!(this.eventsAdded||!this.interactionDOMElement)){var I=this.interactionDOMElement.style;globalThis.navigator.msPointerEnabled?(I.msContentZooming="none",I.msTouchAction="none"):this.supportsPointerEvents&&(I.touchAction="none"),this.supportsPointerEvents?(globalThis.document.addEventListener("pointermove",this.onPointerMove,this._eventListenerOptions),this.interactionDOMElement.addEventListener("pointerdown",this.onPointerDown,this._eventListenerOptions),this.interactionDOMElement.addEventListener("pointerleave",this.onPointerOut,this._eventListenerOptions),this.interactionDOMElement.addEventListener("pointerover",this.onPointerOver,this._eventListenerOptions),globalThis.addEventListener("pointercancel",this.onPointerCancel,this._eventListenerOptions),globalThis.addEventListener("pointerup",this.onPointerUp,this._eventListenerOptions)):(globalThis.document.addEventListener("mousemove",this.onPointerMove,this._eventListenerOptions),this.interactionDOMElement.addEventListener("mousedown",this.onPointerDown,this._eventListenerOptions),this.interactionDOMElement.addEventListener("mouseout",this.onPointerOut,this._eventListenerOptions),this.interactionDOMElement.addEventListener("mouseover",this.onPointerOver,this._eventListenerOptions),globalThis.addEventListener("mouseup",this.onPointerUp,this._eventListenerOptions)),this.supportsTouchEvents&&(this.interactionDOMElement.addEventListener("touchstart",this.onPointerDown,this._eventListenerOptions),this.interactionDOMElement.addEventListener("touchcancel",this.onPointerCancel,this._eventListenerOptions),this.interactionDOMElement.addEventListener("touchend",this.onPointerUp,this._eventListenerOptions),this.interactionDOMElement.addEventListener("touchmove",this.onPointerMove,this._eventListenerOptions)),this.eventsAdded=!0}},g.prototype.removeEvents=function(){if(!(!this.eventsAdded||!this.interactionDOMElement)){var I=this.interactionDOMElement.style;globalThis.navigator.msPointerEnabled?(I.msContentZooming="",I.msTouchAction=""):this.supportsPointerEvents&&(I.touchAction=""),this.supportsPointerEvents?(globalThis.document.removeEventListener("pointermove",this.onPointerMove,this._eventListenerOptions),this.interactionDOMElement.removeEventListener("pointerdown",this.onPointerDown,this._eventListenerOptions),this.interactionDOMElement.removeEventListener("pointerleave",this.onPointerOut,this._eventListenerOptions),this.interactionDOMElement.removeEventListener("pointerover",this.onPointerOver,this._eventListenerOptions),globalThis.removeEventListener("pointercancel",this.onPointerCancel,this._eventListenerOptions),globalThis.removeEventListener("pointerup",this.onPointerUp,this._eventListenerOptions)):(globalThis.document.removeEventListener("mousemove",this.onPointerMove,this._eventListenerOptions),this.interactionDOMElement.removeEventListener("mousedown",this.onPointerDown,this._eventListenerOptions),this.interactionDOMElement.removeEventListener("mouseout",this.onPointerOut,this._eventListenerOptions),this.interactionDOMElement.removeEventListener("mouseover",this.onPointerOver,this._eventListenerOptions),globalThis.removeEventListener("mouseup",this.onPointerUp,this._eventListenerOptions)),this.supportsTouchEvents&&(this.interactionDOMElement.removeEventListener("touchstart",this.onPointerDown,this._eventListenerOptions),this.interactionDOMElement.removeEventListener("touchcancel",this.onPointerCancel,this._eventListenerOptions),this.interactionDOMElement.removeEventListener("touchend",this.onPointerUp,this._eventListenerOptions),this.interactionDOMElement.removeEventListener("touchmove",this.onPointerMove,this._eventListenerOptions)),this.interactionDOMElement=null,this.eventsAdded=!1}},g.prototype.tickerUpdate=function(I){this._deltaTime+=I,!(this._deltaTime0&&(o=I.composedPath()[0]);for(var A=o!==this.interactionDOMElement?"outside":"",s=0;s"u"&&(r.button=I.touches.length?1:0),typeof r.buttons>"u"&&(r.buttons=I.touches.length?1:0),typeof r.isPrimary>"u"&&(r.isPrimary=I.touches.length===1&&I.type==="touchstart"),typeof r.width>"u"&&(r.width=r.radiusX||1),typeof r.height>"u"&&(r.height=r.radiusY||1),typeof r.tiltX>"u"&&(r.tiltX=0),typeof r.tiltY>"u"&&(r.tiltY=0),typeof r.pointerType>"u"&&(r.pointerType="touch"),typeof r.pointerId>"u"&&(r.pointerId=r.identifier||0),typeof r.pressure>"u"&&(r.pressure=r.force||.5),typeof r.twist>"u"&&(r.twist=0),typeof r.tangentialPressure>"u"&&(r.tangentialPressure=0),typeof r.layerX>"u"&&(r.layerX=r.offsetX=r.clientX),typeof r.layerY>"u"&&(r.layerY=r.offsetY=r.clientY),r.isNormalized=!0,i.push(r)}else if(!globalThis.MouseEvent||I instanceof MouseEvent&&(!this.supportsPointerEvents||!(I instanceof globalThis.PointerEvent))){var o=I;typeof o.isPrimary>"u"&&(o.isPrimary=!0),typeof o.width>"u"&&(o.width=1),typeof o.height>"u"&&(o.height=1),typeof o.tiltX>"u"&&(o.tiltX=0),typeof o.tiltY>"u"&&(o.tiltY=0),typeof o.pointerType>"u"&&(o.pointerType="mouse"),typeof o.pointerId>"u"&&(o.pointerId=oV),typeof o.pressure>"u"&&(o.pressure=.5),typeof o.twist>"u"&&(o.twist=0),typeof o.tangentialPressure>"u"&&(o.tangentialPressure=0),o.isNormalized=!0,i.push(o)}else i.push(I);return i},g.prototype.destroy=function(){this.removeEvents(),this.removeTickerListener(),this.removeAllListeners(),this.renderer=null,this.mouse=null,this.eventData=null,this.interactionDOMElement=null,this.onPointerDown=null,this.processPointerDown=null,this.onPointerUp=null,this.processPointerUp=null,this.onPointerCancel=null,this.processPointerCancel=null,this.onPointerMove=null,this.processPointerMove=null,this.onPointerOut=null,this.processPointerOverOut=null,this.onPointerOver=null,this.search=null},g.extension={name:"interaction",type:[Pg.RendererPlugin,Pg.CanvasRendererPlugin]},g}(l0);/*! + * @pixi/extract - v6.5.10 + * Compiled Thu, 06 Jul 2023 15:25:11 UTC + * + * @pixi/extract is licensed under the MIT License. + * http://www.opensource.org/licenses/mit-license + */var a3e=new vg,s3e=4,Bme=function(){function e(g){this.renderer=g}return e.prototype.image=function(g,I,i){var n=new Image;return n.src=this.base64(g,I,i),n},e.prototype.base64=function(g,I,i){return this.canvas(g).toDataURL(I,i)},e.prototype.canvas=function(g,I){var i=this._rawPixels(g,I),n=i.pixels,C=i.width,r=i.height,o=i.flipY,A=new WE(C,r,1),s=A.context.getImageData(0,0,C,r);if(e.arrayPostDivide(n,s.data),A.context.putImageData(s,0,0),o){var a=new WE(A.width,A.height,1);a.context.scale(1,-1),a.context.drawImage(A.canvas,0,-r),A.destroy(),A=a}return A.canvas},e.prototype.pixels=function(g,I){var i=this._rawPixels(g,I).pixels;return e.arrayPostDivide(i,i),i},e.prototype._rawPixels=function(g,I){var i=this.renderer,n,C=!1,r,o=!1;if(g)if(g instanceof Ws)r=g;else{var A=i.context.webGLVersion>=2?i.multisample:mI.NONE;if(r=this.renderer.generateTexture(g,{multisample:A}),A!==mI.NONE){var s=Ws.create({width:r.width,height:r.height});i.framebuffer.bind(r.framebuffer),i.framebuffer.blit(s.framebuffer),i.framebuffer.bind(null),r.destroy(!0),r=s}o=!0}r?(n=r.baseTexture.resolution,I=I??r.frame,C=!1,i.renderTexture.bind(r)):(n=i.resolution,I||(I=a3e,I.width=i.width,I.height=i.height),C=!0,i.renderTexture.bind(null));var a=Math.round(I.width*n),l=Math.round(I.height*n),c=new Uint8Array(s3e*a*l),u=i.gl;return u.readPixels(Math.round(I.x*n),Math.round(I.y*n),a,l,u.RGBA,u.UNSIGNED_BYTE,c),o&&r.destroy(!0),{pixels:c,width:a,height:l,flipY:C}},e.prototype.destroy=function(){this.renderer=null},e.arrayPostDivide=function(g,I){for(var i=0;i"u"&&(oK=!!(globalThis.XDomainRequest&&!("withCredentials"in new XMLHttpRequest))),oK&&this.crossOrigin?this._loadXdr():this._loadXhr();break}}},e.prototype._hasFlag=function(g){return(this._flags&g)!==0},e.prototype._setFlag=function(g,I){this._flags=I?this._flags|g:this._flags&~g},e.prototype._clearEvents=function(){clearTimeout(this._elementTimer),this.data&&this.data.removeEventListener&&(this.data.removeEventListener("error",this._boundOnError,!1),this.data.removeEventListener("load",this._boundComplete,!1),this.data.removeEventListener("progress",this._boundOnProgress,!1),this.data.removeEventListener("canplaythrough",this._boundComplete,!1)),this.xhr&&(this.xhr.removeEventListener?(this.xhr.removeEventListener("error",this._boundXhrOnError,!1),this.xhr.removeEventListener("timeout",this._boundXhrOnTimeout,!1),this.xhr.removeEventListener("abort",this._boundXhrOnAbort,!1),this.xhr.removeEventListener("progress",this._boundOnProgress,!1),this.xhr.removeEventListener("load",this._boundXhrOnLoad,!1)):(this.xhr.onerror=null,this.xhr.ontimeout=null,this.xhr.onprogress=null,this.xhr.onload=null))},e.prototype._finish=function(){if(this.isComplete)throw new Error("Complete called again for an already completed resource.");this._setFlag(e.STATUS_FLAGS.COMPLETE,!0),this._setFlag(e.STATUS_FLAGS.LOADING,!1),this.onComplete.dispatch(this)},e.prototype._loadElement=function(g){this.metadata.loadElement?this.data=this.metadata.loadElement:g==="image"&&typeof globalThis.Image<"u"?this.data=new Image:this.data=document.createElement(g),this.crossOrigin&&(this.data.crossOrigin=this.crossOrigin),this.metadata.skipSource||(this.data.src=this.url),this.data.addEventListener("error",this._boundOnError,!1),this.data.addEventListener("load",this._boundComplete,!1),this.data.addEventListener("progress",this._boundOnProgress,!1),this.timeout&&(this._elementTimer=setTimeout(this._boundOnTimeout,this.timeout))},e.prototype._loadSourceElement=function(g){if(this.metadata.loadElement?this.data=this.metadata.loadElement:g==="audio"&&typeof globalThis.Audio<"u"?this.data=new Audio:this.data=document.createElement(g),this.data===null){this.abort("Unsupported element: "+g);return}if(this.crossOrigin&&(this.data.crossOrigin=this.crossOrigin),!this.metadata.skipSource)if(navigator.isCocoonJS)this.data.src=Array.isArray(this.url)?this.url[0]:this.url;else if(Array.isArray(this.url))for(var I=this.metadata.mimeType,i=0;i"u"?wq:g.status;(g.responseType===""||g.responseType==="text"||typeof g.responseType>"u")&&(I=g.responseText),i===l3e&&(I.length>0||g.responseType===e.XHR_RESPONSE_TYPE.BUFFER)?i=wq:i===u3e&&(i=c3e);var n=i/100|0;if(n===d3e)if(this.xhrType===e.XHR_RESPONSE_TYPE.TEXT)this.data=I,this.type=e.TYPE.TEXT;else if(this.xhrType===e.XHR_RESPONSE_TYPE.JSON)try{this.data=JSON.parse(I),this.type=e.TYPE.JSON}catch(o){this.abort("Error trying to parse loaded json: "+o);return}else if(this.xhrType===e.XHR_RESPONSE_TYPE.DOCUMENT)try{if(globalThis.DOMParser){var C=new DOMParser;this.data=C.parseFromString(I,"text/xml")}else{var r=document.createElement("div");r.innerHTML=I,this.data=r}this.type=e.TYPE.XML}catch(o){this.abort("Error trying to parse loaded xml: "+o);return}else this.data=g.response||I;else{this.abort("["+g.status+"] "+g.statusText+": "+g.responseURL);return}this.complete()},e.prototype._determineCrossOrigin=function(g,I){if(g.indexOf("data:")===0)return"";if(globalThis.origin!==globalThis.location.origin)return"anonymous";I=I||globalThis.location,sV||(sV=document.createElement("a")),sV.href=g;var i=Sme(sV.href,{strictMode:!0}),n=!i.port&&I.port===""||i.port===I.port,C=i.protocol?i.protocol+":":"";return i.host!==I.hostname||!n||C!==I.protocol?"anonymous":""},e.prototype._determineXhrType=function(){return e._xhrTypeMap[this.extension]||e.XHR_RESPONSE_TYPE.TEXT},e.prototype._determineLoadType=function(){return e._loadTypeMap[this.extension]||e.LOAD_TYPE.XHR},e.prototype._getExtension=function(g){g===void 0&&(g=this.url);var I="";if(this.isDataUrl){var i=g.indexOf("/");I=g.substring(i+1,g.indexOf(";",i))}else{var n=g.indexOf("?"),C=g.indexOf("#"),r=Math.min(n>-1?n:g.length,C>-1?C:g.length);g=g.substring(0,r),I=g.substring(g.lastIndexOf(".")+1)}return I.toLowerCase()},e.prototype._getMimeFromXhrType=function(g){switch(g){case e.XHR_RESPONSE_TYPE.BUFFER:return"application/octet-binary";case e.XHR_RESPONSE_TYPE.BLOB:return"application/blob";case e.XHR_RESPONSE_TYPE.DOCUMENT:return"application/xml";case e.XHR_RESPONSE_TYPE.JSON:return"application/json";case e.XHR_RESPONSE_TYPE.DEFAULT:case e.XHR_RESPONSE_TYPE.TEXT:default:return"text/plain"}},e}();(function(e){(function(g){g[g.NONE=0]="NONE",g[g.DATA_URL=1]="DATA_URL",g[g.COMPLETE=2]="COMPLETE",g[g.LOADING=4]="LOADING"})(e.STATUS_FLAGS||(e.STATUS_FLAGS={})),function(g){g[g.UNKNOWN=0]="UNKNOWN",g[g.JSON=1]="JSON",g[g.XML=2]="XML",g[g.IMAGE=3]="IMAGE",g[g.AUDIO=4]="AUDIO",g[g.VIDEO=5]="VIDEO",g[g.TEXT=6]="TEXT"}(e.TYPE||(e.TYPE={})),function(g){g[g.XHR=1]="XHR",g[g.IMAGE=2]="IMAGE",g[g.AUDIO=3]="AUDIO",g[g.VIDEO=4]="VIDEO"}(e.LOAD_TYPE||(e.LOAD_TYPE={})),function(g){g.DEFAULT="text",g.BUFFER="arraybuffer",g.BLOB="blob",g.DOCUMENT="document",g.JSON="json",g.TEXT="text"}(e.XHR_RESPONSE_TYPE||(e.XHR_RESPONSE_TYPE={})),e._loadTypeMap={gif:e.LOAD_TYPE.IMAGE,png:e.LOAD_TYPE.IMAGE,bmp:e.LOAD_TYPE.IMAGE,jpg:e.LOAD_TYPE.IMAGE,jpeg:e.LOAD_TYPE.IMAGE,tif:e.LOAD_TYPE.IMAGE,tiff:e.LOAD_TYPE.IMAGE,webp:e.LOAD_TYPE.IMAGE,tga:e.LOAD_TYPE.IMAGE,avif:e.LOAD_TYPE.IMAGE,svg:e.LOAD_TYPE.IMAGE,"svg+xml":e.LOAD_TYPE.IMAGE,mp3:e.LOAD_TYPE.AUDIO,ogg:e.LOAD_TYPE.AUDIO,wav:e.LOAD_TYPE.AUDIO,mp4:e.LOAD_TYPE.VIDEO,webm:e.LOAD_TYPE.VIDEO},e._xhrTypeMap={xhtml:e.XHR_RESPONSE_TYPE.DOCUMENT,html:e.XHR_RESPONSE_TYPE.DOCUMENT,htm:e.XHR_RESPONSE_TYPE.DOCUMENT,xml:e.XHR_RESPONSE_TYPE.DOCUMENT,tmx:e.XHR_RESPONSE_TYPE.DOCUMENT,svg:e.XHR_RESPONSE_TYPE.DOCUMENT,tsx:e.XHR_RESPONSE_TYPE.DOCUMENT,gif:e.XHR_RESPONSE_TYPE.BLOB,png:e.XHR_RESPONSE_TYPE.BLOB,bmp:e.XHR_RESPONSE_TYPE.BLOB,jpg:e.XHR_RESPONSE_TYPE.BLOB,jpeg:e.XHR_RESPONSE_TYPE.BLOB,tif:e.XHR_RESPONSE_TYPE.BLOB,tiff:e.XHR_RESPONSE_TYPE.BLOB,webp:e.XHR_RESPONSE_TYPE.BLOB,tga:e.XHR_RESPONSE_TYPE.BLOB,avif:e.XHR_RESPONSE_TYPE.BLOB,json:e.XHR_RESPONSE_TYPE.JSON,text:e.XHR_RESPONSE_TYPE.TEXT,txt:e.XHR_RESPONSE_TYPE.TEXT,ttf:e.XHR_RESPONSE_TYPE.BUFFER,otf:e.XHR_RESPONSE_TYPE.BUFFER},e.EMPTY_GIF="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=="})(KI||(KI={}));function uu(){}function h3e(e){return function(){for(var I=arguments,i=[],n=0;n>2,n[1]=(i[0]&3)<<4|i[1]>>4,n[2]=(i[1]&15)<<2|i[2]>>6,n[3]=i[2]&63;var r=I-(e.length-1);switch(r){case 2:n[3]=64,n[2]=64;break;case 1:n[3]=64;break}for(var C=0;C0&&C[C.length-1])&&(s[0]===6||s[0]===2)){I=0;continue}if(s[0]===3&&(!C||s[1]>C[0]&&s[1]=33776&&I<=33779)return"s3tc";if(I>=37488&&I<=37497)return"etc";if(I>=35840&&I<=35843)return"pvrtc";if(I>=36196)return"etc1";if(I>=35986&&I<=34798)return"atc";throw new Error("Invalid (compressed) texture format given!")},g._createLevelBuffers=function(I,i,n,C,r,o,A){for(var s=new Array(n),a=I.byteOffset,l=o,c=A,u=l+C-1&~(C-1),d=c+r-1&~(r-1),h=u*d*Qv[i],m=0;m1?l:u,levelHeight:n>1?c:d,levelBuffer:new Uint8Array(I.buffer,a,h)},a+=h,l=l>>1||1,c=c>>1||1,u=l+C-1&~(C-1),d=c+r-1&~(r-1),h=u*d*Qv[i];return s},g}(Wme),Xme=function(){function e(){}return e.use=function(g,I){var i=g.data,n=this;if(g.type===KI.TYPE.JSON&&i&&i.cacheID&&i.textures){for(var C=i.textures,r=void 0,o=void 0,A=0,s=C.length;A>>1,V=V>>>1}for(var H=B,S=0;S1||C!==0?w:S,levelHeight:u>1||C!==0?V:X,levelBuffer:new Uint8Array(g,Y,v)},Y+=v}W+=H+4,W=W%4!==0?W+4-W%4:W,w=w>>1||1,V=V>>1||1,S=w+h-1&~(h-1),X=V+m-1&~(m-1),v=S*X*Z}return C!==0?{uncompressed:p.map(function(O){var J=O[0].levelBuffer,ee=!1;return C===Et.FLOAT?J=new Float32Array(O[0].levelBuffer.buffer,O[0].levelBuffer.byteOffset,O[0].levelBuffer.byteLength/4):C===Et.UNSIGNED_INT?(ee=!0,J=new Uint32Array(O[0].levelBuffer.buffer,O[0].levelBuffer.byteOffset,O[0].levelBuffer.byteLength/4)):C===Et.INT&&(ee=!0,J=new Int32Array(O[0].levelBuffer.buffer,O[0].levelBuffer.byteOffset,O[0].levelBuffer.byteLength/4)),{resource:new Dh(J,{width:O[0].levelWidth,height:O[0].levelHeight}),type:C,format:ee?z3e(r):r}}),kvData:B}:{compressed:p.map(function(O){return new IX(null,{format:o,width:A,height:s,levels:u,levelBuffers:O})}),kvData:B}}function M3e(e,g){for(var I=0;Ig-n){console.error("KTXLoader: keyAndValueByteSize out of bounds");break}for(var A=0;Ao&&(n=o),r._properties=[!1,!0,!1,!1,!1],r._maxSize=I,r._batchSize=n,r._buffers=null,r._bufferUpdateIDs=[],r._updateID=0,r.interactiveChildren=!1,r.blendMode=Jt.NORMAL,r.autoResize=C,r.roundPixels=!0,r.baseTexture=null,r.setProperties(i),r._tint=0,r.tintRgb=new Float32Array(4),r.tint=16777215,r}return g.prototype.setProperties=function(I){I&&(this._properties[0]="vertices"in I||"scale"in I?!!I.vertices||!!I.scale:this._properties[0],this._properties[1]="position"in I?!!I.position:this._properties[1],this._properties[2]="rotation"in I?!!I.rotation:this._properties[2],this._properties[3]="uvs"in I?!!I.uvs:this._properties[3],this._properties[4]="tint"in I||"alpha"in I?!!I.tint||!!I.alpha:this._properties[4])},g.prototype.updateTransform=function(){this.displayObjectUpdateTransform()},Object.defineProperty(g.prototype,"tint",{get:function(){return this._tint},set:function(I){this._tint=I,Dd(I,this.tintRgb)},enumerable:!1,configurable:!0}),g.prototype.render=function(I){var i=this;!this.visible||this.worldAlpha<=0||!this.children.length||!this.renderable||(this.baseTexture||(this.baseTexture=this.children[0]._texture.baseTexture,this.baseTexture.valid||this.baseTexture.once("update",function(){return i.onChildrenChange(0)})),I.batch.setObjectRenderer(I.plugins.particle),I.plugins.particle.render(this))},g.prototype.onChildrenChange=function(I){for(var i=Math.floor(I/this._batchSize);this._bufferUpdateIDs.length 0.0) { - c.rgb /= c.a; - } +attribute vec2 aPositionCoord; +attribute float aRotation; - vec4 result; +uniform mat3 translationMatrix; +uniform vec4 uColor; - result.r = (m[0] * c.r); - result.r += (m[1] * c.g); - result.r += (m[2] * c.b); - result.r += (m[3] * c.a); - result.r += m[4]; +varying vec2 vTextureCoord; +varying vec4 vColor; - result.g = (m[5] * c.r); - result.g += (m[6] * c.g); - result.g += (m[7] * c.b); - result.g += (m[8] * c.a); - result.g += m[9]; +void main(void){ + float x = (aVertexPosition.x) * cos(aRotation) - (aVertexPosition.y) * sin(aRotation); + float y = (aVertexPosition.x) * sin(aRotation) + (aVertexPosition.y) * cos(aRotation); - result.b = (m[10] * c.r); - result.b += (m[11] * c.g); - result.b += (m[12] * c.b); - result.b += (m[13] * c.a); - result.b += m[14]; + vec2 v = vec2(x, y); + v = v + aPositionCoord; - result.a = (m[15] * c.r); - result.a += (m[16] * c.g); - result.a += (m[17] * c.b); - result.a += (m[18] * c.a); - result.a += m[19]; + gl_Position = vec4((translationMatrix * vec3(v, 1.0)).xy, 0.0, 1.0); - vec3 rgb = mix(c.rgb, result.rgb, uAlpha); + vTextureCoord = aTextureCoord; + vColor = aColor * uColor; +} +`,Fme=function(e){xme(g,e);function g(I){var i=e.call(this,I)||this;return i.shader=null,i.properties=null,i.tempMatrix=new fi,i.properties=[{attributeName:"aVertexPosition",size:2,uploadFunction:i.uploadVertices,offset:0},{attributeName:"aPositionCoord",size:2,uploadFunction:i.uploadPosition,offset:0},{attributeName:"aRotation",size:1,uploadFunction:i.uploadRotation,offset:0},{attributeName:"aTextureCoord",size:2,uploadFunction:i.uploadUvs,offset:0},{attributeName:"aColor",size:1,type:Et.UNSIGNED_BYTE,uploadFunction:i.uploadTint,offset:0}],i.shader=bs.from(_3e,O3e,{}),i.state=Jc.for2d(),i}return g.prototype.render=function(I){var i=I.children,n=I._maxSize,C=I._batchSize,r=this.renderer,o=i.length;if(o!==0){o>n&&!I.autoResize&&(o=n);var A=I._buffers;A||(A=I._buffers=this.generateBuffers(I));var s=i[0]._texture.baseTexture,a=s.alphaMode>0;this.state.blendMode=CL(I.blendMode,a),r.state.set(this.state);var l=r.gl,c=I.worldTransform.copyTo(this.tempMatrix);c.prepend(r.globalUniforms.uniforms.projectionMatrix),this.shader.uniforms.translationMatrix=c.toArray(!0),this.shader.uniforms.uColor=Hhe(I.tintRgb,I.worldAlpha,this.shader.uniforms.uColor,a),this.shader.uniforms.uSampler=s,this.renderer.shader.bind(this.shader);for(var u=!1,d=0,h=0;dC&&(m=C),h>=A.length&&A.push(this._generateOneMoreBuffer(I));var f=A[h];f.uploadDynamic(i,d,m);var b=I._bufferUpdateIDs[h]||0;u=u||f._updateID0,l=s.alpha,c=l<1&&a?JH(s._tintRGB,l):s._tintRGB+(l*255<<24);C[o]=c,C[o+r]=c,C[o+r*2]=c,C[o+r*3]=c,o+=r*4}},g.prototype.destroy=function(){e.prototype.destroy.call(this),this.shader&&(this.shader.destroy(),this.shader=null),this.tempMatrix=null},g.extension={name:"particle",type:Pg.RendererPlugin},g}(rS);/*! + * @pixi/graphics - v6.5.10 + * Compiled Thu, 06 Jul 2023 15:25:11 UTC + * + * @pixi/graphics is licensed under the MIT License. + * http://www.opensource.org/licenses/mit-license + */var YA;(function(e){e.MITER="miter",e.BEVEL="bevel",e.ROUND="round"})(YA||(YA={}));var rs;(function(e){e.BUTT="butt",e.ROUND="round",e.SQUARE="square"})(rs||(rs={}));var gb={adaptive:!0,maxLength:10,minSegments:8,maxSegments:2048,epsilon:1e-4,_segmentsCount:function(e,g){if(g===void 0&&(g=20),!this.adaptive||!e||isNaN(e))return g;var I=Math.ceil(e/this.maxLength);return Ithis.maxSegments&&(I=this.maxSegments),I}},xL=function(){function e(){this.color=16777215,this.alpha=1,this.texture=eg.WHITE,this.matrix=null,this.visible=!1,this.reset()}return e.prototype.clone=function(){var g=new e;return g.color=this.color,g.alpha=this.alpha,g.texture=this.texture,g.matrix=this.matrix,g.visible=this.visible,g},e.prototype.reset=function(){this.color=16777215,this.alpha=1,this.texture=eg.WHITE,this.matrix=null,this.visible=!1},e.prototype.destroy=function(){this.texture=null,this.matrix=null},e}();/*! ***************************************************************************** +Copyright (c) Microsoft Corporation. + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +PERFORMANCE OF THIS SOFTWARE. +***************************************************************************** */var zE=function(e,g){return zE=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(I,i){I.__proto__=i}||function(I,i){for(var n in i)i.hasOwnProperty(n)&&(I[n]=i[n])},zE(e,g)};function FL(e,g){zE(e,g);function I(){this.constructor=e}e.prototype=g===null?Object.create(g):(I.prototype=g.prototype,new I)}function Tq(e,g){var I,i;g===void 0&&(g=!1);var n=e.length;if(!(n<6)){for(var C=0,r=0,o=e[n-2],A=e[n-1];r0||g&&C<=0)for(var l=n/2,r=l+l%2;r=6){Tq(I,!1);for(var r=[],o=0;o=0&&o>=0&&n>=0&&C>=0)){g.length=0;return}var u=Math.ceil(2.3*Math.sqrt(r+o)),d=u*8+(n?4:0)+(C?4:0);if(g.length=d,d!==0){if(u===0){g.length=8,g[0]=g[6]=I+n,g[1]=g[3]=i+C,g[2]=g[4]=I-n,g[5]=g[7]=i-C;return}var h=0,m=u*4+(n?2:0)+2,f=m,b=d;{var p=n+r,y=C,Z=I+p,B=I-p,G=i+y;if(g[h++]=Z,g[h++]=G,g[--m]=G,g[--m]=B,C){var v=i-y;g[f++]=B,g[f++]=v,g[--b]=v,g[--b]=Z}}for(var w=1;wl&&(l+=Math.PI*2);var c=a,u=l-a,d=Math.abs(u),h=Math.sqrt(A*A+s*s),m=(15*d*Math.sqrt(h)/Math.PI>>0)+1,f=u/m;if(c+=f,o){r.push(e,g),r.push(I,i);for(var b=1,p=c;b=0&&(C.join===YA.ROUND?d+=du(Z,B,Z-w*H,B-V*H,Z-S*H,B-X*H,c,!1)+4:d+=2,c.push(Z-S*Y,B-X*Y),c.push(Z+S*H,B+X*H));continue}var te=(-w+p)*(-V+B)-(-w+Z)*(-V+y),U=(-S+G)*(-X+B)-(-S+Z)*(-X+v),ie=(E*U-J*te)/$,me=(ee*te-O*U)/$,Ce=(ie-Z)*(ie-Z)+(me-B)*(me-B),Ze=Z+(ie-Z)*H,Ge=B+(me-B)*H,Be=Z-(ie-Z)*Y,Ne=B-(me-B)*Y,Se=Math.min(E*E+O*O,J*J+ee*ee),Pe=j?H:Y,ze=Se+Pe*Pe*f,Fe=Ce<=ze;Fe?C.join===YA.BEVEL||Ce/f>b?(j?(c.push(Ze,Ge),c.push(Z+w*Y,B+V*Y),c.push(Ze,Ge),c.push(Z+S*Y,B+X*Y)):(c.push(Z-w*H,B-V*H),c.push(Be,Ne),c.push(Z-S*H,B-X*H),c.push(Be,Ne)),d+=2):C.join===YA.ROUND?j?(c.push(Ze,Ge),c.push(Z+w*Y,B+V*Y),d+=du(Z,B,Z+w*Y,B+V*Y,Z+S*Y,B+X*Y,c,!0)+4,c.push(Ze,Ge),c.push(Z+S*Y,B+X*Y)):(c.push(Z-w*H,B-V*H),c.push(Be,Ne),d+=du(Z,B,Z-w*H,B-V*H,Z-S*H,B-X*H,c,!1)+4,c.push(Z-S*H,B-X*H),c.push(Be,Ne)):(c.push(Ze,Ge),c.push(Be,Ne)):(c.push(Z-w*H,B-V*H),c.push(Z+w*Y,B+V*Y),C.join===YA.ROUND?j?d+=du(Z,B,Z+w*Y,B+V*Y,Z+S*Y,B+X*Y,c,!0)+2:d+=du(Z,B,Z-w*H,B-V*H,Z-S*H,B-X*H,c,!1)+2:C.join===YA.MITER&&Ce/f<=b&&(j?(c.push(Be,Ne),c.push(Be,Ne)):(c.push(Ze,Ge),c.push(Ze,Ge)),d+=2),c.push(Z-S*H,B-X*H),c.push(Z+S*Y,B+X*Y),d+=2)}p=i[(u-2)*2],y=i[(u-2)*2+1],Z=i[(u-1)*2],B=i[(u-1)*2+1],w=-(y-B),V=p-Z,W=Math.sqrt(w*w+V*V),w/=W,V/=W,w*=m,V*=m,c.push(Z-w*H,B-V*H),c.push(Z+w*Y,B+V*Y),A||(C.cap===rs.ROUND?d+=du(Z-w*(H-Y)*.5,B-V*(H-Y)*.5,Z-w*H,B-V*H,Z+w*Y,B+V*Y,c,!1)+2:C.cap===rs.SQUARE&&(d+=Nq(Z,B,w,V,H,Y,!1,c)));for(var Ue=g.indices,_e=gb.epsilon*gb.epsilon,D=h;Dc*s}},e.arc=function(g,I,i,n,C,r,o,A,s){for(var a=o-r,l=gb._segmentsCount(Math.abs(a)*C,Math.ceil(Math.abs(a)/Ov)*40),c=a/(l*2),u=c*2,d=Math.cos(c),h=Math.sin(c),m=l-1,f=m%1/m,b=0;b<=m;++b){var p=b+f*b,y=c+r+u*p,Z=Math.cos(y),B=-Math.sin(y);s.push((d*Z+h*B)*C+i,(d*-B+h*Z)*C+n)}},e}(),zme=function(){function e(){}return e.curveLength=function(g,I,i,n,C,r,o,A){for(var s=10,a=0,l=0,c=0,u=0,d=0,h=0,m=0,f=0,b=0,p=0,y=0,Z=g,B=I,G=1;G<=s;++G)l=G/s,c=l*l,u=c*l,d=1-l,h=d*d,m=h*d,f=m*g+3*h*l*i+3*d*c*C+u*o,b=m*I+3*h*l*n+3*d*c*r+u*A,p=Z-f,y=B-b,Z=f,B=b,a+=Math.sqrt(p*p+y*y);return a},e.curveTo=function(g,I,i,n,C,r,o){var A=o[o.length-2],s=o[o.length-1];o.length-=2;var a=gb._segmentsCount(e.curveLength(A,s,g,I,i,n,C,r)),l=0,c=0,u=0,d=0,h=0;o.push(A,s);for(var m=1,f=0;m<=a;++m)f=m/a,l=1-f,c=l*l,u=c*l,d=f*f,h=d*f,o.push(u*A+3*c*f*g+3*l*d*i+h*C,u*s+3*c*f*I+3*l*d*n+h*r)},e}(),Pme=function(){function e(){}return e.curveLength=function(g,I,i,n,C,r){var o=g-2*i+C,A=I-2*n+r,s=2*i-2*g,a=2*n-2*I,l=4*(o*o+A*A),c=4*(o*s+A*a),u=s*s+a*a,d=2*Math.sqrt(l+c+u),h=Math.sqrt(l),m=2*l*h,f=2*Math.sqrt(u),b=c/h;return(m*d+h*c*(d-f)+(4*u*l-c*c)*Math.log((2*h+b+d)/(b+f)))/(4*m)},e.curveTo=function(g,I,i,n,C){for(var r=C[C.length-2],o=C[C.length-1],A=gb._segmentsCount(e.curveLength(r,o,g,I,i,n)),s=0,a=0,l=1;l<=A;++l){var c=l/A;s=r+(g-r)*c,a=o+(I-o)*c,C.push(s+(g+(i-g)*c-s)*c,a+(I+(n-I)*c-a)*c)}},e}(),Jme=function(){function e(){this.reset()}return e.prototype.begin=function(g,I,i){this.reset(),this.style=g,this.start=I,this.attribStart=i},e.prototype.end=function(g,I){this.attribSize=I-this.attribStart,this.size=g-this.start},e.prototype.reset=function(){this.style=null,this.size=0,this.start=0,this.attribStart=0,this.attribSize=0},e}(),hu,r1=(hu={},hu[Si.POLY]=EL,hu[Si.CIRC]=jv,hu[Si.ELIP]=jv,hu[Si.RECT]=Eme,hu[Si.RREC]=Mme,hu),OE=[],fZ=[],_E=function(){function e(g,I,i,n){I===void 0&&(I=null),i===void 0&&(i=null),n===void 0&&(n=null),this.points=[],this.holes=[],this.shape=g,this.lineStyle=i,this.fillStyle=I,this.matrix=n,this.type=g.type}return e.prototype.clone=function(){return new e(this.shape,this.fillStyle,this.lineStyle,this.matrix)},e.prototype.destroy=function(){this.shape=null,this.holes.length=0,this.holes=null,this.points.length=0,this.points=null,this.lineStyle=null,this.fillStyle=null},e}(),Gm=new rI,Ome=function(e){FL(g,e);function g(){var I=e.call(this)||this;return I.closePointEps=1e-4,I.boundsPadding=0,I.uvsFloat32=null,I.indicesUint16=null,I.batchable=!1,I.points=[],I.colors=[],I.uvs=[],I.indices=[],I.textureIds=[],I.graphicsData=[],I.drawCalls=[],I.batchDirty=-1,I.batches=[],I.dirty=0,I.cacheDirty=-1,I.clearDirty=0,I.shapeIndex=0,I._bounds=new _v,I.boundsDirty=-1,I}return Object.defineProperty(g.prototype,"bounds",{get:function(){return this.updateBatches(),this.boundsDirty!==this.dirty&&(this.boundsDirty=this.dirty,this.calculateBounds()),this._bounds},enumerable:!1,configurable:!0}),g.prototype.invalidate=function(){this.boundsDirty=-1,this.dirty++,this.batchDirty++,this.shapeIndex=0,this.points.length=0,this.colors.length=0,this.uvs.length=0,this.indices.length=0,this.textureIds.length=0;for(var I=0;I0&&(this.invalidate(),this.clearDirty++,this.graphicsData.length=0),this},g.prototype.drawShape=function(I,i,n,C){i===void 0&&(i=null),n===void 0&&(n=null),C===void 0&&(C=null);var r=new _E(I,i,n,C);return this.graphicsData.push(r),this.dirty++,this},g.prototype.drawHole=function(I,i){if(i===void 0&&(i=null),!this.graphicsData.length)return null;var n=new _E(I,null,null,i),C=this.graphicsData[this.graphicsData.length-1];return n.lineStyle=C.lineStyle,C.holes.push(n),this.dirty++,this},g.prototype.destroy=function(){e.prototype.destroy.call(this);for(var I=0;I0&&(n=this.batches[this.batches.length-1],C=n.style);for(var r=this.shapeIndex;r65535;this.indicesUint16&&this.indices.length===this.indicesUint16.length&&p===this.indicesUint16.BYTES_PER_ELEMENT>2?this.indicesUint16.set(this.indices):this.indicesUint16=p?new Uint32Array(this.indices):new Uint16Array(this.indices),this.batchable=this.isBatchable(),this.batchable?this.packBatches():this.buildDrawCalls()}},g.prototype._compareStyles=function(I,i){return!(!I||!i||I.texture.baseTexture!==i.texture.baseTexture||I.color+I.alpha!==i.color+i.alpha||!!I.native!=!!i.native)},g.prototype.validateBatching=function(){if(this.dirty===this.cacheDirty||!this.graphicsData.length)return!1;for(var I=0,i=this.graphicsData.length;I65535*2)return!1;for(var I=this.batches,i=0;i0&&(r=fZ.pop(),r||(r=new eX,r.texArray=new tX),this.drawCalls.push(r)),r.start=c,r.size=0,r.texArray.count=0,r.type=l),m.touched=1,m._batchEnabled=I,m._batchLocation=o,m.wrapMode=$o.REPEAT,r.texArray.elements[r.texArray.count++]=m,o++)),r.size+=u.size,c+=u.size,s=m._batchLocation,this.addColors(n,h.color,h.alpha,u.attribSize,u.attribStart),this.addTextureIds(C,s,u.attribSize,u.attribStart)}yg._globalBatch=I,this.packAttributes()},g.prototype.packAttributes=function(){for(var I=this.points,i=this.uvs,n=this.colors,C=this.textureIds,r=new ArrayBuffer(I.length*3*4),o=new Float32Array(r),A=new Uint32Array(r),s=0,a=0;a>16)+(i&65280)+((i&255)<<16),A=JH(o,n);I.length=Math.max(I.length,r+C);for(var s=0;s0&&I.alpha>0;return i?(I.matrix&&(I.matrix=I.matrix.clone(),I.matrix.invert()),Object.assign(this._lineStyle,{visible:i},I)):this._lineStyle.reset(),this},g.prototype.startPoly=function(){if(this.currentPath){var I=this.currentPath.points,i=this.currentPath.points.length;i>2&&(this.drawShape(this.currentPath),this.currentPath=new GG,this.currentPath.closeStroke=!1,this.currentPath.points.push(I[i-2],I[i-1]))}else this.currentPath=new GG,this.currentPath.closeStroke=!1},g.prototype.finishPoly=function(){this.currentPath&&(this.currentPath.points.length>2?(this.drawShape(this.currentPath),this.currentPath=null):this.currentPath.points.length=0)},g.prototype.moveTo=function(I,i){return this.startPoly(),this.currentPath.points[0]=I,this.currentPath.points[1]=i,this},g.prototype.lineTo=function(I,i){this.currentPath||this.moveTo(0,0);var n=this.currentPath.points,C=n[n.length-2],r=n[n.length-1];return(C!==I||r!==i)&&n.push(I,i),this},g.prototype._initCurve=function(I,i){I===void 0&&(I=0),i===void 0&&(i=0),this.currentPath?this.currentPath.points.length===0&&(this.currentPath.points=[I,i]):this.moveTo(I,i)},g.prototype.quadraticCurveTo=function(I,i,n,C){this._initCurve();var r=this.currentPath.points;return r.length===0&&this.moveTo(0,0),Pme.curveTo(I,i,n,C,r),this},g.prototype.bezierCurveTo=function(I,i,n,C,r,o){return this._initCurve(),zme.curveTo(I,i,n,C,r,o,this.currentPath.points),this},g.prototype.arcTo=function(I,i,n,C,r){this._initCurve(I,i);var o=this.currentPath.points,A=JE.curveTo(I,i,n,C,r,o);if(A){var s=A.cx,a=A.cy,l=A.radius,c=A.startAngle,u=A.endAngle,d=A.anticlockwise;this.arc(s,a,l,c,u,d)}return this},g.prototype.arc=function(I,i,n,C,r,o){if(o===void 0&&(o=!1),C===r)return this;!o&&r<=C?r+=Ov:o&&C<=r&&(C+=Ov);var A=r-C;if(A===0)return this;var s=I+Math.cos(C)*n,a=i+Math.sin(C)*n,l=this._geometry.closePointEps,c=this.currentPath?this.currentPath.points:null;if(c){var u=Math.abs(c[c.length-2]-s),d=Math.abs(c[c.length-1]-a);u0;return i?(I.matrix&&(I.matrix=I.matrix.clone(),I.matrix.invert()),Object.assign(this._fillStyle,{visible:i},I)):this._fillStyle.reset(),this},g.prototype.endFill=function(){return this.finishPoly(),this._fillStyle.reset(),this},g.prototype.drawRect=function(I,i,n,C){return this.drawShape(new vg(I,i,n,C))},g.prototype.drawRoundedRect=function(I,i,n,C,r){return this.drawShape(new Ehe(I,i,n,C,r))},g.prototype.drawCircle=function(I,i,n){return this.drawShape(new xhe(I,i,n))},g.prototype.drawEllipse=function(I,i,n,C){return this.drawShape(new Fhe(I,i,n,C))},g.prototype.drawPolygon=function(){for(var I=arguments,i=[],n=0;n>16&255)/255*r,o.tint[1]=(C>>8&255)/255*r,o.tint[2]=(C&255)/255*r,o.tint[3]=r,I.shader.bind(i),I.geometry.bind(n,i),I.state.set(this.state);for(var s=0,a=A.length;s>16)+(s&65280)+((s&255)<<16)}}},g.prototype.calculateVertices=function(){var I=this.transform._worldID;if(this._transformID!==I){this._transformID=I;for(var i=this.transform.worldTransform,n=i.a,C=i.b,r=i.c,o=i.d,A=i.tx,s=i.ty,a=this._geometry.points,l=this.vertexData,c=0,u=0;u=C&&Zy.x=r&&Zy.y>16)+(I&65280)+((I&255)<<16)},enumerable:!1,configurable:!0}),Object.defineProperty(g.prototype,"texture",{get:function(){return this._texture},set:function(I){this._texture!==I&&(this._texture&&this._texture.off("update",this._onTextureUpdate,this),this._texture=I||eg.EMPTY,this._cachedTint=16777215,this._textureID=-1,this._textureTrimmedID=-1,I&&(I.baseTexture.valid?this._onTextureUpdate():I.once("update",this._onTextureUpdate,this)))},enumerable:!1,configurable:!0}),g}(CA);/*! + * @pixi/text - v6.5.10 + * Compiled Thu, 06 Jul 2023 15:25:11 UTC + * + * @pixi/text is licensed under the MIT License. + * http://www.opensource.org/licenses/mit-license + *//*! ***************************************************************************** +Copyright (c) Microsoft Corporation. + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +PERFORMANCE OF THIS SOFTWARE. +***************************************************************************** */var UE=function(e,g){return UE=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(I,i){I.__proto__=i}||function(I,i){for(var n in i)i.hasOwnProperty(n)&&(I[n]=i[n])},UE(e,g)};function eze(e,g){UE(e,g);function I(){this.constructor=e}e.prototype=g===null?Object.create(g):(I.prototype=g.prototype,new I)}var Ib;(function(e){e[e.LINEAR_VERTICAL=0]="LINEAR_VERTICAL",e[e.LINEAR_HORIZONTAL=1]="LINEAR_HORIZONTAL"})(Ib||(Ib={}));var uK={align:"left",breakWords:!1,dropShadow:!1,dropShadowAlpha:1,dropShadowAngle:Math.PI/6,dropShadowBlur:0,dropShadowColor:"black",dropShadowDistance:5,fill:"black",fillGradientType:Ib.LINEAR_VERTICAL,fillGradientStops:[],fontFamily:"Arial",fontSize:26,fontStyle:"normal",fontVariant:"normal",fontWeight:"normal",letterSpacing:0,lineHeight:0,lineJoin:"miter",miterLimit:10,padding:0,stroke:"black",strokeThickness:0,textBaseline:"alphabetic",trim:!1,whiteSpace:"pre",wordWrap:!1,wordWrapWidth:100,leading:0},tze=["serif","sans-serif","monospace","cursive","fantasy","system-ui"],Fd=function(){function e(g){this.styleID=0,this.reset(),hK(this,g,g)}return e.prototype.clone=function(){var g={};return hK(g,this,uK),new e(g)},e.prototype.reset=function(){hK(this,uK,uK)},Object.defineProperty(e.prototype,"align",{get:function(){return this._align},set:function(g){this._align!==g&&(this._align=g,this.styleID++)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"breakWords",{get:function(){return this._breakWords},set:function(g){this._breakWords!==g&&(this._breakWords=g,this.styleID++)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"dropShadow",{get:function(){return this._dropShadow},set:function(g){this._dropShadow!==g&&(this._dropShadow=g,this.styleID++)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"dropShadowAlpha",{get:function(){return this._dropShadowAlpha},set:function(g){this._dropShadowAlpha!==g&&(this._dropShadowAlpha=g,this.styleID++)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"dropShadowAngle",{get:function(){return this._dropShadowAngle},set:function(g){this._dropShadowAngle!==g&&(this._dropShadowAngle=g,this.styleID++)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"dropShadowBlur",{get:function(){return this._dropShadowBlur},set:function(g){this._dropShadowBlur!==g&&(this._dropShadowBlur=g,this.styleID++)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"dropShadowColor",{get:function(){return this._dropShadowColor},set:function(g){var I=dK(g);this._dropShadowColor!==I&&(this._dropShadowColor=I,this.styleID++)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"dropShadowDistance",{get:function(){return this._dropShadowDistance},set:function(g){this._dropShadowDistance!==g&&(this._dropShadowDistance=g,this.styleID++)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"fill",{get:function(){return this._fill},set:function(g){var I=dK(g);this._fill!==I&&(this._fill=I,this.styleID++)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"fillGradientType",{get:function(){return this._fillGradientType},set:function(g){this._fillGradientType!==g&&(this._fillGradientType=g,this.styleID++)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"fillGradientStops",{get:function(){return this._fillGradientStops},set:function(g){gze(this._fillGradientStops,g)||(this._fillGradientStops=g,this.styleID++)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"fontFamily",{get:function(){return this._fontFamily},set:function(g){this.fontFamily!==g&&(this._fontFamily=g,this.styleID++)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"fontSize",{get:function(){return this._fontSize},set:function(g){this._fontSize!==g&&(this._fontSize=g,this.styleID++)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"fontStyle",{get:function(){return this._fontStyle},set:function(g){this._fontStyle!==g&&(this._fontStyle=g,this.styleID++)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"fontVariant",{get:function(){return this._fontVariant},set:function(g){this._fontVariant!==g&&(this._fontVariant=g,this.styleID++)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"fontWeight",{get:function(){return this._fontWeight},set:function(g){this._fontWeight!==g&&(this._fontWeight=g,this.styleID++)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"letterSpacing",{get:function(){return this._letterSpacing},set:function(g){this._letterSpacing!==g&&(this._letterSpacing=g,this.styleID++)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"lineHeight",{get:function(){return this._lineHeight},set:function(g){this._lineHeight!==g&&(this._lineHeight=g,this.styleID++)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"leading",{get:function(){return this._leading},set:function(g){this._leading!==g&&(this._leading=g,this.styleID++)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"lineJoin",{get:function(){return this._lineJoin},set:function(g){this._lineJoin!==g&&(this._lineJoin=g,this.styleID++)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"miterLimit",{get:function(){return this._miterLimit},set:function(g){this._miterLimit!==g&&(this._miterLimit=g,this.styleID++)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"padding",{get:function(){return this._padding},set:function(g){this._padding!==g&&(this._padding=g,this.styleID++)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"stroke",{get:function(){return this._stroke},set:function(g){var I=dK(g);this._stroke!==I&&(this._stroke=I,this.styleID++)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"strokeThickness",{get:function(){return this._strokeThickness},set:function(g){this._strokeThickness!==g&&(this._strokeThickness=g,this.styleID++)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"textBaseline",{get:function(){return this._textBaseline},set:function(g){this._textBaseline!==g&&(this._textBaseline=g,this.styleID++)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"trim",{get:function(){return this._trim},set:function(g){this._trim!==g&&(this._trim=g,this.styleID++)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"whiteSpace",{get:function(){return this._whiteSpace},set:function(g){this._whiteSpace!==g&&(this._whiteSpace=g,this.styleID++)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"wordWrap",{get:function(){return this._wordWrap},set:function(g){this._wordWrap!==g&&(this._wordWrap=g,this.styleID++)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"wordWrapWidth",{get:function(){return this._wordWrapWidth},set:function(g){this._wordWrapWidth!==g&&(this._wordWrapWidth=g,this.styleID++)},enumerable:!1,configurable:!0}),e.prototype.toFontString=function(){var g=typeof this.fontSize=="number"?this.fontSize+"px":this.fontSize,I=this.fontFamily;Array.isArray(this.fontFamily)||(I=this.fontFamily.split(","));for(var i=I.length-1;i>=0;i--){var n=I[i].trim();!/([\"\'])[^\'\"]+\1/.test(n)&&tze.indexOf(n)<0&&(n='"'+n+'"'),I[i]=n}return this.fontStyle+" "+this.fontVariant+" "+this.fontWeight+" "+g+" "+I.join(",")},e}();function kq(e){return typeof e=="number"?IL(e):(typeof e=="string"&&e.indexOf("0x")===0&&(e=e.replace("0x","#")),e)}function dK(e){if(Array.isArray(e)){for(var g=0;gd)if(r!==""&&(o+=e.addLine(r),r="",C=0),e.canBreakWords(f,I.breakWords))for(var Z=e.wordWrapSplit(f),B=0;Bd&&(o+=e.addLine(r),u=!1,r="",C=0),r+=G,C+=S}else{r.length>0&&(o+=e.addLine(r),r="",C=0);var X=m===h.length-1;o+=e.addLine(f,!X),u=!1,r="",C=0}else y+C>d&&(u=!1,o+=e.addLine(r),r="",C=0),(r.length>0||!e.isBreakingSpace(f)||u)&&(r+=f,C+=y)}return o+=e.addLine(r,!1),o},e.addLine=function(g,I){return I===void 0&&(I=!0),g=e.trimRight(g),g=I?g+` +`:g,g},e.getFromCache=function(g,I,i,n){var C=i[g];if(typeof C!="number"){var r=g.length*I;C=n.measureText(g).width+r,i[g]=C}return C},e.collapseSpaces=function(g){return g==="normal"||g==="pre-line"},e.collapseNewlines=function(g){return g==="normal"},e.trimRight=function(g){if(typeof g!="string")return"";for(var I=g.length-1;I>=0;I--){var i=g[I];if(!e.isBreakingSpace(i))break;g=g.slice(0,-1)}return g},e.isNewline=function(g){return typeof g!="string"?!1:e._newlines.indexOf(g.charCodeAt(0))>=0},e.isBreakingSpace=function(g,I){return typeof g!="string"?!1:e._breakingSpaces.indexOf(g.charCodeAt(0))>=0},e.tokenize=function(g){var I=[],i="";if(typeof g!="string")return I;for(var n=0;no;--c){for(var h=0;h0&&m>f&&(b=(f+m)/2);var p=f+h,y=n.lineHeight*(d+1),Z=p;d+10},e}();function nze(e,g){var I=!1;if(e&&e._textures&&e._textures.length){for(var i=0;i=0;I--)this.add(g.children[I]);return this},e.prototype.destroy=function(){this.ticking&&Pi.system.remove(this.tick,this),this.ticking=!1,this.addHooks=null,this.uploadHooks=null,this.renderer=null,this.completes=null,this.queue=null,this.limiter=null,this.uploadHookHelper=null},e}();function Qme(e,g){return g instanceof yg?(g._glTextures[e.CONTEXT_UID]||e.texture.bind(g),!0):!1}function lze(e,g){if(!(g instanceof $v))return!1;var I=g.geometry;g.finishPoly(),I.updateBatches();for(var i=I.batches,n=0;n=C&&Gy.x=r&&Gy.y lumaMax)) - color = vec4(rgbA, texColor.a); - else - color = vec4(rgbB, texColor.a); - return color; + gl_FragColor = texSample * uColor; } +`,fze=`#version 300 es +#define SHADER_NAME Tiling-Sprite-300 -void main() { - - vec4 color; - - color = fxaa(uSampler, vFragCoord, inputSize.zw, v_rgbNW, v_rgbNE, v_rgbSW, v_rgbSE, v_rgbM); +precision lowp float; - gl_FragColor = color; -} -`,KEe=` -attribute vec2 aVertexPosition; +in vec2 aVertexPosition; +in vec2 aTextureCoord; uniform mat3 projectionMatrix; +uniform mat3 translationMatrix; +uniform mat3 uTransform; -varying vec2 v_rgbNW; -varying vec2 v_rgbNE; -varying vec2 v_rgbSW; -varying vec2 v_rgbSE; -varying vec2 v_rgbM; - -varying vec2 vFragCoord; - -uniform vec4 inputSize; -uniform vec4 outputFrame; +out vec2 vTextureCoord; -vec4 filterVertexPosition( void ) +void main(void) { - vec2 position = aVertexPosition * max(outputFrame.zw, vec2(0.)) + outputFrame.xy; - - return vec4((projectionMatrix * vec3(position, 1.0)).xy, 0.0, 1.0); -} + gl_Position = vec4((projectionMatrix * translationMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0); -void texcoords(vec2 fragCoord, vec2 inverseVP, - out vec2 v_rgbNW, out vec2 v_rgbNE, - out vec2 v_rgbSW, out vec2 v_rgbSE, - out vec2 v_rgbM) { - v_rgbNW = (fragCoord + vec2(-1.0, -1.0)) * inverseVP; - v_rgbNE = (fragCoord + vec2(1.0, -1.0)) * inverseVP; - v_rgbSW = (fragCoord + vec2(-1.0, 1.0)) * inverseVP; - v_rgbSE = (fragCoord + vec2(1.0, 1.0)) * inverseVP; - v_rgbM = vec2(fragCoord * inverseVP); + vTextureCoord = (uTransform * vec3(aTextureCoord, 1.0)).xy; } +`,pze=`#version 300 es +#define SHADER_NAME Tiling-Sprite-100 -void main(void) { - - gl_Position = filterVertexPosition(); - - vFragCoord = aVertexPosition * outputFrame.zw; +precision lowp float; - texcoords(vFragCoord, inputSize.zw, v_rgbNW, v_rgbNE, v_rgbSW, v_rgbSE, v_rgbM); -} -`;class dfe extends Hn{constructor(){super(KEe,YEe)}}var xEe=`precision highp float; +in vec2 vTextureCoord; -varying vec2 vTextureCoord; -varying vec4 vColor; +out vec4 fragmentColor; -uniform float uNoise; -uniform float uSeed; uniform sampler2D uSampler; +uniform vec4 uColor; +uniform mat3 uMapCoord; +uniform vec4 uClampFrame; +uniform vec2 uClampOffset; -float rand(vec2 co) -{ - return fract(sin(dot(co.xy, vec2(12.9898, 78.233))) * 43758.5453); -} - -void main() +void main(void) { - vec4 color = texture2D(uSampler, vTextureCoord); - float randomValue = rand(gl_FragCoord.xy * uSeed); - float diff = (randomValue - 0.5) * uNoise; - - // Un-premultiply alpha before applying the color matrix. See issue #3539. - if (color.a > 0.0) { - color.rgb /= color.a; - } - - color.r += diff; - color.g += diff; - color.b += diff; + vec2 coord = vTextureCoord + ceil(uClampOffset - vTextureCoord); + coord = (uMapCoord * vec3(coord, 1.0)).xy; + vec2 unclamped = coord; + coord = clamp(coord, uClampFrame.xy, uClampFrame.zw); - // Premultiply alpha again. - color.rgb *= color.a; + vec4 texSample = texture(uSampler, coord, unclamped == coord ? 0.0f : -32.0f);// lod-bias very negative to force lod 0 - gl_FragColor = color; + fragmentColor = texSample * uColor; } -`;class hfe extends Hn{constructor(e=.5,I=Math.random()){super(oU,xEe,{uNoise:0,uSeed:0}),this.noise=e,this.seed=I}get noise(){return this.uniforms.uNoise}set noise(e){this.uniforms.uNoise=e}get seed(){return this.uniforms.uSeed}set seed(e){this.uniforms.uSeed=e}}const HM={AlphaFilter:lfe,BlurFilter:cfe,BlurFilterPass:EX,ColorMatrixFilter:MX,DisplacementFilter:ufe,FXAAFilter:dfe,NoiseFilter:hfe};Object.entries(HM).forEach(([g,e])=>{Object.defineProperty(HM,g,{get(){return tg("7.1.0",`filters.${g} has moved to ${g}`),e}})});class DEe{constructor(){this.interactionFrequency=10,this._deltaTime=0,this._didMove=!1,this.tickerAdded=!1,this._pauseUpdate=!0}init(e){this.removeTickerListener(),this.events=e,this.interactionFrequency=10,this._deltaTime=0,this._didMove=!1,this.tickerAdded=!1,this._pauseUpdate=!0}get pauseUpdate(){return this._pauseUpdate}set pauseUpdate(e){this._pauseUpdate=e}addTickerListener(){this.tickerAdded||!this.domElement||(Ji.system.add(this.tickerUpdate,this,zs.INTERACTION),this.tickerAdded=!0)}removeTickerListener(){this.tickerAdded&&(Ji.system.remove(this.tickerUpdate,this),this.tickerAdded=!1)}pointerMoved(){this._didMove=!0}update(){if(!this.domElement||this._pauseUpdate)return;if(this._didMove){this._didMove=!1;return}const e=this.events.rootPointerEvent;this.events.supportsTouchEvents&&e.pointerType==="touch"||globalThis.document.dispatchEvent(new PointerEvent("pointermove",{clientX:e.clientX,clientY:e.clientY}))}tickerUpdate(e){this._deltaTime+=e,!(this._deltaTimei.priority-n.priority)}dispatchEvent(e,I){e.propagationStopped=!1,e.propagationImmediatelyStopped=!1,this.propagate(e,I),this.dispatch.emit(I||e.type,e)}mapEvent(e){if(!this.rootTarget)return;const I=this.mappingTable[e.type];if(I)for(let i=0,n=I.length;i=0;n--)if(e.currentTarget=i[n],this.notifyTarget(e,I),e.propagationStopped||e.propagationImmediatelyStopped)return}}all(e,I,i=this._allInteractiveElements){if(i.length===0)return;e.eventPhase=e.BUBBLING_PHASE;const n=Array.isArray(I)?I:[I];for(let C=i.length-1;C>=0;C--)n.forEach(r=>{e.currentTarget=i[C],this.notifyTarget(e,r)})}propagationPath(e){const I=[e];for(let i=0;i=0;l--){const c=a[l],u=this.hitTestMoveRecursive(c,this._isInteractive(I)?I:c.eventMode,i,n,C,r||C(e,i));if(u){if(u.length>0&&!u[u.length-1].parent)continue;const d=e.isInteractive();(u.length>0||d)&&(d&&this._allInteractiveElements.push(e),u.push(e)),this._hitElements.length===0&&(this._hitElements=u),o=!0}}}const A=this._isInteractive(I),s=e.isInteractive();return A&&s&&this._allInteractiveElements.push(e),r||this._hitElements.length>0?null:o?this._hitElements:A&&!C(e,i)&&n(e,i)?s?[e]:[]:null}hitTestRecursive(e,I,i,n,C){if(this._interactivePrune(e)||C(e,i))return null;if((e.eventMode==="dynamic"||I==="dynamic")&&(Ac.pauseUpdate=!1),e.interactiveChildren&&e.children){const A=e.children;for(let s=A.length-1;s>=0;s--){const a=A[s],l=this.hitTestRecursive(a,this._isInteractive(I)?I:a.eventMode,i,n,C);if(l){if(l.length>0&&!l[l.length-1].parent)continue;const c=e.isInteractive();return(l.length>0||c)&&l.push(e),l}}}const r=this._isInteractive(I),o=e.isInteractive();return r&&n(e,i)?o?[e]:[]:null}_isInteractive(e){return e==="static"||e==="dynamic"}_interactivePrune(e){return!!(!e||e.isMask||!e.visible||!e.renderable||e.eventMode==="none"||e.eventMode==="passive"&&!e.interactiveChildren||e.isMask)}hitPruneFn(e,I){var i;if(e.hitArea&&(e.worldTransform.applyInverse(I,e5),!e.hitArea.contains(e5.x,e5.y)))return!0;if(e._mask){const n=e._mask.isMaskData?e._mask.maskObject:e._mask;if(n&&!((i=n.containsPoint)!=null&&i.call(n,I)))return!0}return!1}hitTestFn(e,I){return e.eventMode==="passive"?!1:e.hitArea?!0:e.containsPoint?e.containsPoint(I):!1}notifyTarget(e,I){var C,r;I=I??e.type;const i=`on${I}`;(r=(C=e.currentTarget)[i])==null||r.call(C,e);const n=e.eventPhase===e.CAPTURING_PHASE||e.eventPhase===e.AT_TARGET?`${I}capture`:I;this.notifyListeners(e,n),e.eventPhase===e.AT_TARGET&&this.notifyListeners(e,I)}mapPointerDown(e){if(!(e instanceof Xr)){console.warn("EventBoundary cannot map a non-pointer event as a pointer event");return}const I=this.createPointerEvent(e);if(this.dispatchEvent(I,"pointerdown"),I.pointerType==="touch")this.dispatchEvent(I,"touchstart");else if(I.pointerType==="mouse"||I.pointerType==="pen"){const n=I.button===2;this.dispatchEvent(I,n?"rightdown":"mousedown")}const i=this.trackingData(e.pointerId);i.pressTargetsByButton[e.button]=I.composedPath(),this.freeEvent(I)}mapPointerMove(e){var A,s;if(!(e instanceof Xr)){console.warn("EventBoundary cannot map a non-pointer event as a pointer event");return}this._allInteractiveElements.length=0,this._hitElements.length=0,this._isPointerMoveEvent=!0;const I=this.createPointerEvent(e);this._isPointerMoveEvent=!1;const i=I.pointerType==="mouse"||I.pointerType==="pen",n=this.trackingData(e.pointerId),C=this.findMountedTarget(n.overTargets);if(((A=n.overTargets)==null?void 0:A.length)>0&&C!==I.target){const a=e.type==="mousemove"?"mouseout":"pointerout",l=this.createPointerEvent(e,a,C);if(this.dispatchEvent(l,"pointerout"),i&&this.dispatchEvent(l,"mouseout"),!I.composedPath().includes(C)){const c=this.createPointerEvent(e,"pointerleave",C);for(c.eventPhase=c.AT_TARGET;c.target&&!I.composedPath().includes(c.target);)c.currentTarget=c.target,this.notifyTarget(c),i&&this.notifyTarget(c,"mouseleave"),c.target=c.target.parent;this.freeEvent(c)}this.freeEvent(l)}if(C!==I.target){const a=e.type==="mousemove"?"mouseover":"pointerover",l=this.clonePointerEvent(I,a);this.dispatchEvent(l,"pointerover"),i&&this.dispatchEvent(l,"mouseover");let c=C==null?void 0:C.parent;for(;c&&c!==this.rootTarget.parent&&c!==I.target;)c=c.parent;if(!c||c===this.rootTarget.parent){const u=this.clonePointerEvent(I,"pointerenter");for(u.eventPhase=u.AT_TARGET;u.target&&u.target!==C&&u.target!==this.rootTarget.parent;)u.currentTarget=u.target,this.notifyTarget(u),i&&this.notifyTarget(u,"mouseenter"),u.target=u.target.parent;this.freeEvent(u)}this.freeEvent(l)}const r=[],o=this.enableGlobalMoveEvents??!0;this.moveOnAll?r.push("pointermove"):this.dispatchEvent(I,"pointermove"),o&&r.push("globalpointermove"),I.pointerType==="touch"&&(this.moveOnAll?r.splice(1,0,"touchmove"):this.dispatchEvent(I,"touchmove"),o&&r.push("globaltouchmove")),i&&(this.moveOnAll?r.splice(1,0,"mousemove"):this.dispatchEvent(I,"mousemove"),o&&r.push("globalmousemove"),this.cursor=(s=I.target)==null?void 0:s.cursor),r.length>0&&this.all(I,r),this._allInteractiveElements.length=0,this._hitElements.length=0,n.overTargets=I.composedPath(),this.freeEvent(I)}mapPointerOver(e){var r;if(!(e instanceof Xr)){console.warn("EventBoundary cannot map a non-pointer event as a pointer event");return}const I=this.trackingData(e.pointerId),i=this.createPointerEvent(e),n=i.pointerType==="mouse"||i.pointerType==="pen";this.dispatchEvent(i,"pointerover"),n&&this.dispatchEvent(i,"mouseover"),i.pointerType==="mouse"&&(this.cursor=(r=i.target)==null?void 0:r.cursor);const C=this.clonePointerEvent(i,"pointerenter");for(C.eventPhase=C.AT_TARGET;C.target&&C.target!==this.rootTarget.parent;)C.currentTarget=C.target,this.notifyTarget(C),n&&this.notifyTarget(C,"mouseenter"),C.target=C.target.parent;I.overTargets=i.composedPath(),this.freeEvent(i),this.freeEvent(C)}mapPointerOut(e){if(!(e instanceof Xr)){console.warn("EventBoundary cannot map a non-pointer event as a pointer event");return}const I=this.trackingData(e.pointerId);if(I.overTargets){const i=e.pointerType==="mouse"||e.pointerType==="pen",n=this.findMountedTarget(I.overTargets),C=this.createPointerEvent(e,"pointerout",n);this.dispatchEvent(C),i&&this.dispatchEvent(C,"mouseout");const r=this.createPointerEvent(e,"pointerleave",n);for(r.eventPhase=r.AT_TARGET;r.target&&r.target!==this.rootTarget.parent;)r.currentTarget=r.target,this.notifyTarget(r),i&&this.notifyTarget(r,"mouseleave"),r.target=r.target.parent;I.overTargets=null,this.freeEvent(C),this.freeEvent(r)}this.cursor=null}mapPointerUp(e){if(!(e instanceof Xr)){console.warn("EventBoundary cannot map a non-pointer event as a pointer event");return}const I=performance.now(),i=this.createPointerEvent(e);if(this.dispatchEvent(i,"pointerup"),i.pointerType==="touch")this.dispatchEvent(i,"touchend");else if(i.pointerType==="mouse"||i.pointerType==="pen"){const o=i.button===2;this.dispatchEvent(i,o?"rightup":"mouseup")}const n=this.trackingData(e.pointerId),C=this.findMountedTarget(n.pressTargetsByButton[e.button]);let r=C;if(C&&!i.composedPath().includes(C)){let o=C;for(;o&&!i.composedPath().includes(o);){if(i.currentTarget=o,this.notifyTarget(i,"pointerupoutside"),i.pointerType==="touch")this.notifyTarget(i,"touchendoutside");else if(i.pointerType==="mouse"||i.pointerType==="pen"){const A=i.button===2;this.notifyTarget(i,A?"rightupoutside":"mouseupoutside")}o=o.parent}delete n.pressTargetsByButton[e.button],r=o}if(r){const o=this.clonePointerEvent(i,"click");o.target=r,o.path=null,n.clicksByButton[e.button]||(n.clicksByButton[e.button]={clickCount:0,target:o.target,timeStamp:I});const A=n.clicksByButton[e.button];if(A.target===o.target&&I-A.timeStamp<200?++A.clickCount:A.clickCount=1,A.target=o.target,A.timeStamp=I,o.detail=A.clickCount,o.pointerType==="mouse"){const s=o.button===2;this.dispatchEvent(o,s?"rightclick":"click")}else o.pointerType==="touch"&&this.dispatchEvent(o,"tap");this.dispatchEvent(o,"pointertap"),this.freeEvent(o)}this.freeEvent(i)}mapPointerUpOutside(e){if(!(e instanceof Xr)){console.warn("EventBoundary cannot map a non-pointer event as a pointer event");return}const I=this.trackingData(e.pointerId),i=this.findMountedTarget(I.pressTargetsByButton[e.button]),n=this.createPointerEvent(e);if(i){let C=i;for(;C;)n.currentTarget=C,this.notifyTarget(n,"pointerupoutside"),n.pointerType==="touch"?this.notifyTarget(n,"touchendoutside"):(n.pointerType==="mouse"||n.pointerType==="pen")&&this.notifyTarget(n,n.button===2?"rightupoutside":"mouseupoutside"),C=C.parent;delete I.pressTargetsByButton[e.button]}this.freeEvent(n)}mapWheel(e){if(!(e instanceof Yd)){console.warn("EventBoundary cannot map a non-wheel event as a wheel event");return}const I=this.createWheelEvent(e);this.dispatchEvent(I),this.freeEvent(I)}findMountedTarget(e){if(!e)return null;let I=e[0];for(let i=1;i(i==="globalMove"&&(this.rootBoundary.enableGlobalMoveEvents=n),I[i]=n,!0)}),this.onPointerDown=this.onPointerDown.bind(this),this.onPointerMove=this.onPointerMove.bind(this),this.onPointerUp=this.onPointerUp.bind(this),this.onPointerOverOut=this.onPointerOverOut.bind(this),this.onWheel=this.onWheel.bind(this)}static get defaultEventMode(){return this._defaultEventMode}init(e){const{view:I,resolution:i}=this.renderer;this.setTargetElement(I),this.resolution=i,NM._defaultEventMode=e.eventMode??"auto",Object.assign(this.features,e.eventFeatures??{}),this.rootBoundary.enableGlobalMoveEvents=this.features.globalMove}resolutionChange(e){this.resolution=e}destroy(){this.setTargetElement(null),this.renderer=null}setCursor(e){e=e||"default";let I=!0;if(globalThis.OffscreenCanvas&&this.domElement instanceof OffscreenCanvas&&(I=!1),this.currentCursor===e)return;this.currentCursor=e;const i=this.cursorStyles[e];if(i)switch(typeof i){case"string":I&&(this.domElement.style.cursor=i);break;case"function":i(e);break;case"object":I&&Object.assign(this.domElement.style,i);break}else I&&typeof e=="string"&&!Object.prototype.hasOwnProperty.call(this.cursorStyles,e)&&(this.domElement.style.cursor=e)}get pointer(){return this.rootPointerEvent}onPointerDown(e){if(!this.features.click)return;this.rootBoundary.rootTarget=this.renderer.lastObjectRendered;const I=this.normalizeToPointerData(e);this.autoPreventDefault&&I[0].isNormalized&&(e.cancelable||!("cancelable"in e))&&e.preventDefault();for(let i=0,n=I.length;i0&&(I=e.composedPath()[0]);const i=I!==this.domElement?"outside":"",n=this.normalizeToPointerData(e);for(let C=0,r=n.length;C"u"&&(C.button=0),typeof C.buttons>"u"&&(C.buttons=1),typeof C.isPrimary>"u"&&(C.isPrimary=e.touches.length===1&&e.type==="touchstart"),typeof C.width>"u"&&(C.width=C.radiusX||1),typeof C.height>"u"&&(C.height=C.radiusY||1),typeof C.tiltX>"u"&&(C.tiltX=0),typeof C.tiltY>"u"&&(C.tiltY=0),typeof C.pointerType>"u"&&(C.pointerType="touch"),typeof C.pointerId>"u"&&(C.pointerId=C.identifier||0),typeof C.pressure>"u"&&(C.pressure=C.force||.5),typeof C.twist>"u"&&(C.twist=0),typeof C.tangentialPressure>"u"&&(C.tangentialPressure=0),typeof C.layerX>"u"&&(C.layerX=C.offsetX=C.clientX),typeof C.layerY>"u"&&(C.layerY=C.offsetY=C.clientY),C.isNormalized=!0,C.type=e.type,I.push(C)}else if(!globalThis.MouseEvent||e instanceof MouseEvent&&(!this.supportsPointerEvents||!(e instanceof globalThis.PointerEvent))){const i=e;typeof i.isPrimary>"u"&&(i.isPrimary=!0),typeof i.width>"u"&&(i.width=1),typeof i.height>"u"&&(i.height=1),typeof i.tiltX>"u"&&(i.tiltX=0),typeof i.tiltY>"u"&&(i.tiltY=0),typeof i.pointerType>"u"&&(i.pointerType="mouse"),typeof i.pointerId>"u"&&(i.pointerId=MEe),typeof i.pressure>"u"&&(i.pressure=.5),typeof i.twist>"u"&&(i.twist=0),typeof i.tangentialPressure>"u"&&(i.tangentialPressure=0),i.isNormalized=!0,I.push(i)}else I.push(e);return I}normalizeWheelEvent(e){const I=this.rootWheelEvent;return this.transferMouseData(I,e),I.deltaX=e.deltaX,I.deltaY=e.deltaY,I.deltaZ=e.deltaZ,I.deltaMode=e.deltaMode,this.mapPositionToPoint(I.screen,e.clientX,e.clientY),I.global.copyFrom(I.screen),I.offset.copyFrom(I.screen),I.nativeEvent=e,I.type=e.type,I}bootstrapEvent(e,I){return e.originalEvent=null,e.nativeEvent=I,e.pointerId=I.pointerId,e.width=I.width,e.height=I.height,e.isPrimary=I.isPrimary,e.pointerType=I.pointerType,e.pressure=I.pressure,e.tangentialPressure=I.tangentialPressure,e.tiltX=I.tiltX,e.tiltY=I.tiltY,e.twist=I.twist,this.transferMouseData(e,I),this.mapPositionToPoint(e.screen,I.clientX,I.clientY),e.global.copyFrom(e.screen),e.offset.copyFrom(e.screen),e.isTrusted=I.isTrusted,e.type==="pointerleave"&&(e.type="pointerout"),e.type.startsWith("mouse")&&(e.type=e.type.replace("mouse","pointer")),e.type.startsWith("touch")&&(e.type=zEe[e.type]||e.type),e}transferMouseData(e,I){e.isTrusted=I.isTrusted,e.srcElement=I.srcElement,e.timeStamp=performance.now(),e.type=I.type,e.altKey=I.altKey,e.button=I.button,e.buttons=I.buttons,e.client.x=I.clientX,e.client.y=I.clientY,e.ctrlKey=I.ctrlKey,e.metaKey=I.metaKey,e.movement.x=I.movementX,e.movement.y=I.movementY,e.page.x=I.pageX,e.page.y=I.pageY,e.relatedTarget=null,e.shiftKey=I.shiftKey}};TM.extension={name:"events",type:[pt.RendererSystem,pt.CanvasRendererSystem]},TM.defaultEventFeatures={move:!0,globalMove:!0,click:!0,wheel:!0};let zX=TM;kt.add(zX);function oee(g){return g==="dynamic"||g==="static"}const ffe={onclick:null,onmousedown:null,onmouseenter:null,onmouseleave:null,onmousemove:null,onglobalmousemove:null,onmouseout:null,onmouseover:null,onmouseup:null,onmouseupoutside:null,onpointercancel:null,onpointerdown:null,onpointerenter:null,onpointerleave:null,onpointermove:null,onglobalpointermove:null,onpointerout:null,onpointerover:null,onpointertap:null,onpointerup:null,onpointerupoutside:null,onrightclick:null,onrightdown:null,onrightup:null,onrightupoutside:null,ontap:null,ontouchcancel:null,ontouchend:null,ontouchendoutside:null,ontouchmove:null,onglobaltouchmove:null,ontouchstart:null,onwheel:null,_internalInteractive:void 0,get interactive(){return this._internalInteractive??oee(zX.defaultEventMode)},set interactive(g){tg("7.2.0","Setting interactive is deprecated, use eventMode = 'none'/'passive'/'auto'/'static'/'dynamic' instead."),this._internalInteractive=g,this.eventMode=g?"static":"auto"},_internalEventMode:void 0,get eventMode(){return this._internalEventMode??zX.defaultEventMode},set eventMode(g){this._internalInteractive=oee(g),this._internalEventMode=g},isInteractive(){return this.eventMode==="static"||this.eventMode==="dynamic"},interactiveChildren:!0,hitArea:null,addEventListener(g,e,I){const i=typeof I=="boolean"&&I||typeof I=="object"&&I.capture,n=typeof e=="function"?void 0:e;g=i?`${g}capture`:g,e=typeof e=="function"?e:e.handleEvent,this.on(g,e,n)},removeEventListener(g,e,I){const i=typeof I=="boolean"&&I||typeof I=="object"&&I.capture,n=typeof e=="function"?void 0:e;g=i?`${g}capture`:g,e=typeof e=="function"?e:e.handleEvent,this.off(g,e,n)},dispatchEvent(g){if(!(g instanceof k0))throw new Error("DisplayObject cannot propagate events outside of the Federated Events API");return g.defaultPrevented=!1,g.path=null,g.target=this,g.manager.dispatchEvent(g),!g.defaultPrevented}};HI.mixin(ffe);const pfe={accessible:!1,accessibleTitle:null,accessibleHint:null,tabIndex:0,_accessibleActive:!1,_accessibleDiv:null,accessibleType:"button",accessiblePointerEvents:"auto",accessibleChildren:!0,renderId:-1};HI.mixin(pfe);const PEe=9,FV=100,JEe=0,OEe=0,Aee=2,aee=1,LEe=-1e3,_Ee=-1e3,UEe=2;class uU{constructor(e){this.debug=!1,this._isActive=!1,this._isMobileAccessibility=!1,this.pool=[],this.renderId=0,this.children=[],this.androidUpdateCount=0,this.androidUpdateFrequency=500,this._hookDiv=null,(eA.tablet||eA.phone)&&this.createTouchHook();const I=document.createElement("div");I.style.width=`${FV}px`,I.style.height=`${FV}px`,I.style.position="absolute",I.style.top=`${JEe}px`,I.style.left=`${OEe}px`,I.style.zIndex=Aee.toString(),this.div=I,this.renderer=e,this._onKeyDown=this._onKeyDown.bind(this),this._onMouseMove=this._onMouseMove.bind(this),globalThis.addEventListener("keydown",this._onKeyDown,!1)}get isActive(){return this._isActive}get isMobileAccessibility(){return this._isMobileAccessibility}createTouchHook(){const e=document.createElement("button");e.style.width=`${aee}px`,e.style.height=`${aee}px`,e.style.position="absolute",e.style.top=`${LEe}px`,e.style.left=`${_Ee}px`,e.style.zIndex=UEe.toString(),e.style.backgroundColor="#FF0000",e.title="select to enable accessibility for this content",e.addEventListener("focus",()=>{this._isMobileAccessibility=!0,this.activate(),this.destroyTouchHook()}),document.body.appendChild(e),this._hookDiv=e}destroyTouchHook(){this._hookDiv&&(document.body.removeChild(this._hookDiv),this._hookDiv=null)}activate(){var e;this._isActive||(this._isActive=!0,globalThis.document.addEventListener("mousemove",this._onMouseMove,!0),globalThis.removeEventListener("keydown",this._onKeyDown,!1),this.renderer.on("postrender",this.update,this),(e=this.renderer.view.parentNode)==null||e.appendChild(this.div))}deactivate(){var e;!this._isActive||this._isMobileAccessibility||(this._isActive=!1,globalThis.document.removeEventListener("mousemove",this._onMouseMove,!0),globalThis.addEventListener("keydown",this._onKeyDown,!1),this.renderer.off("postrender",this.update),(e=this.div.parentNode)==null||e.removeChild(this.div))}updateAccessibleObjects(e){if(!e.visible||!e.accessibleChildren)return;e.accessible&&e.isInteractive()&&(e._accessibleActive||this.addChild(e),e.renderId=this.renderId);const I=e.children;if(I)for(let i=0;i title : ${e.title}
tabIndex: ${e.tabIndex}`}capHitArea(e){e.x<0&&(e.width+=e.x,e.x=0),e.y<0&&(e.height+=e.y,e.y=0);const{width:I,height:i}=this.renderer;e.x+e.width>I&&(e.width=I-e.x),e.y+e.height>i&&(e.height=i-e.y)}addChild(e){let I=this.pool.pop();I||(I=document.createElement("button"),I.style.width=`${FV}px`,I.style.height=`${FV}px`,I.style.backgroundColor=this.debug?"rgba(255,255,255,0.5)":"transparent",I.style.position="absolute",I.style.zIndex=Aee.toString(),I.style.borderStyle="none",navigator.userAgent.toLowerCase().includes("chrome")?I.setAttribute("aria-live","off"):I.setAttribute("aria-live","polite"),navigator.userAgent.match(/rv:.*Gecko\//)?I.setAttribute("aria-relevant","additions"):I.setAttribute("aria-relevant","text"),I.addEventListener("click",this._onClick.bind(this)),I.addEventListener("focus",this._onFocus.bind(this)),I.addEventListener("focusout",this._onFocusOut.bind(this))),I.style.pointerEvents=e.accessiblePointerEvents,I.type=e.accessibleType,e.accessibleTitle&&e.accessibleTitle!==null?I.title=e.accessibleTitle:(!e.accessibleHint||e.accessibleHint===null)&&(I.title=`displayObject ${e.tabIndex}`),e.accessibleHint&&e.accessibleHint!==null&&I.setAttribute("aria-label",e.accessibleHint),this.debug&&this.updateDebugHTML(I),e._accessibleActive=!0,e._accessibleDiv=I,I.displayObject=e,this.children.push(e),this.div.appendChild(e._accessibleDiv),e._accessibleDiv.tabIndex=e.tabIndex}_dispatchEvent(e,I){const{displayObject:i}=e.target,n=this.renderer.events.rootBoundary,C=Object.assign(new k0(n),{target:i});n.rootTarget=this.renderer.lastObjectRendered,I.forEach(r=>n.dispatchEvent(C,r))}_onClick(e){this._dispatchEvent(e,["click","pointertap","tap"])}_onFocus(e){e.target.getAttribute("aria-live")||e.target.setAttribute("aria-live","assertive"),this._dispatchEvent(e,["mouseover"])}_onFocusOut(e){e.target.getAttribute("aria-live")||e.target.setAttribute("aria-live","polite"),this._dispatchEvent(e,["mouseout"])}_onKeyDown(e){e.keyCode===PEe&&this.activate()}_onMouseMove(e){e.movementX===0&&e.movementY===0||this.deactivate()}destroy(){this.destroyTouchHook(),this.div=null,globalThis.document.removeEventListener("mousemove",this._onMouseMove,!0),globalThis.removeEventListener("keydown",this._onKeyDown),this.pool=null,this.children=null,this.renderer=null}}uU.extension={name:"accessibility",type:[pt.RendererPlugin,pt.CanvasRendererPlugin]};kt.add(uU);const bfe=class kM{constructor(e){this.stage=new yr,e=Object.assign({forceCanvas:!1},e),this.renderer=gfe(e),kM._plugins.forEach(I=>{I.init.call(this,e)})}render(){this.renderer.render(this.stage)}get view(){var e;return(e=this.renderer)==null?void 0:e.view}get screen(){var e;return(e=this.renderer)==null?void 0:e.screen}destroy(e,I){const i=kM._plugins.slice(0);i.reverse(),i.forEach(n=>{n.destroy.call(this)}),this.stage.destroy(I),this.stage=null,this.renderer.destroy(e),this.renderer=null}};bfe._plugins=[];let yfe=bfe;kt.handleByList(pt.Application,yfe._plugins);class dU{static init(e){Object.defineProperty(this,"resizeTo",{set(I){globalThis.removeEventListener("resize",this.queueResize),this._resizeTo=I,I&&(globalThis.addEventListener("resize",this.queueResize),this.resize())},get(){return this._resizeTo}}),this.queueResize=()=>{this._resizeTo&&(this.cancelResize(),this._resizeId=requestAnimationFrame(()=>this.resize()))},this.cancelResize=()=>{this._resizeId&&(cancelAnimationFrame(this._resizeId),this._resizeId=null)},this.resize=()=>{if(!this._resizeTo)return;this.cancelResize();let I,i;if(this._resizeTo===globalThis.window)I=globalThis.innerWidth,i=globalThis.innerHeight;else{const{clientWidth:n,clientHeight:C}=this._resizeTo;I=n,i=C}this.renderer.resize(I,i),this.render()},this._resizeId=null,this._resizeTo=null,this.resizeTo=e.resizeTo||null}static destroy(){globalThis.removeEventListener("resize",this.queueResize),this.cancelResize(),this.cancelResize=null,this.queueResize=null,this.resizeTo=null,this.resize=null}}dU.extension=pt.Application;kt.add(dU);const see={loader:pt.LoadParser,resolver:pt.ResolveParser,cache:pt.CacheParser,detection:pt.DetectionParser};kt.handle(pt.Asset,g=>{const e=g.ref;Object.entries(see).filter(([I])=>!!e[I]).forEach(([I,i])=>kt.add(Object.assign(e[I],{extension:e[I].extension??i})))},g=>{const e=g.ref;Object.keys(see).filter(I=>!!e[I]).forEach(I=>kt.remove(e[I]))});class QEe{constructor(e,I=!1){this._loader=e,this._assetList=[],this._isLoading=!1,this._maxConcurrent=1,this.verbose=I}add(e){e.forEach(I=>{this._assetList.push(I)}),this.verbose&&console.log("[BackgroundLoader] assets: ",this._assetList),this._isActive&&!this._isLoading&&this._next()}async _next(){if(this._assetList.length&&this._isActive){this._isLoading=!0;const e=[],I=Math.min(this._assetList.length,this._maxConcurrent);for(let i=0;i(Array.isArray(g)||(g=[g]),e?g.map(i=>typeof i=="string"||I?e(i):i):g),PX=(g,e)=>{const I=e.split("?")[1];return I&&(g+=`?${I}`),g};function Zfe(g,e,I,i,n){const C=e[I];for(let r=0;r{const r=C.substring(1,C.length-1).split(",");n.push(r)}),Zfe(g,n,0,I,i)}else i.push(g);return i}const yv=g=>!Array.isArray(g);class jEe{constructor(){this._parsers=[],this._cache=new Map,this._cacheMap=new Map}reset(){this._cacheMap.clear(),this._cache.clear()}has(e){return this._cache.has(e)}get(e){const I=this._cache.get(e);return I||console.warn(`[Assets] Asset id ${e} was not found in the Cache`),I}set(e,I){const i=Lr(e);let n;for(let o=0;o{n[o]=I}));const C=Object.keys(n),r={cacheKeys:C,keys:i};if(i.forEach(o=>{this._cacheMap.set(o,r)}),C.forEach(o=>{this._cache.has(o)&&this._cache.get(o)!==I&&console.warn("[Cache] already has key:",o),this._cache.set(o,n[o])}),I instanceof Bt){const o=I;i.forEach(A=>{o.baseTexture!==Bt.EMPTY.baseTexture&&ng.addToCache(o.baseTexture,A),Bt.addToCache(o,A)})}}remove(e){if(!this._cacheMap.has(e)){console.warn(`[Assets] Asset id ${e} was not found in the Cache`);return}const I=this._cacheMap.get(e);I.cacheKeys.forEach(i=>{this._cache.delete(i)}),I.keys.forEach(i=>{this._cacheMap.delete(i)})}get parsers(){return this._parsers}}const ac=new jEe;class $Ee{constructor(){this._parsers=[],this._parsersValidated=!1,this.parsers=new Proxy(this._parsers,{set:(e,I,i)=>(this._parsersValidated=!1,e[I]=i,!0)}),this.promiseCache={}}reset(){this._parsersValidated=!1,this.promiseCache={}}_getLoadPromiseAndParser(e,I){const i={promise:null,parser:null};return i.promise=(async()=>{var r,o;let n=null,C=null;if(I.loadParser&&(C=this._parserHash[I.loadParser],C||console.warn(`[Assets] specified load parser "${I.loadParser}" not found while loading ${e}`)),!C){for(let A=0;A({alias:[s],src:s})),o=r.length,A=r.map(async s=>{const a=fi.toAbsolute(s.src);if(!n[s.src])try{this.promiseCache[a]||(this.promiseCache[a]=this._getLoadPromiseAndParser(a,s)),n[s.src]=await this.promiseCache[a].promise,I&&I(++i/o)}catch(l){throw delete this.promiseCache[a],delete n[s.src],new Error(`[Loader.load] Failed to load ${a}. -${l}`)}});return await Promise.all(A),C?n[r[0].src]:n}async unload(e){const I=Lr(e,i=>({alias:[i],src:i})).map(async i=>{var r,o;const n=fi.toAbsolute(i.src),C=this.promiseCache[n];if(C){const A=await C.promise;delete this.promiseCache[n],(o=(r=C.parser)==null?void 0:r.unload)==null||o.call(r,A,i,this)}});await Promise.all(I)}_validateParsers(){this._parsersValidated=!0,this._parserHash=this._parsers.filter(e=>e.name).reduce((e,I)=>(e[I.name]&&console.warn(`[Assets] loadParser name conflict "${I.name}"`),{...e,[I.name]:I}),{})}}var so=(g=>(g[g.Low=0]="Low",g[g.Normal=1]="Normal",g[g.High=2]="High",g))(so||{});const qEe=".json",eMe="application/json",Bfe={extension:{type:pt.LoadParser,priority:so.Low},name:"loadJson",test(g){return tm(g,eMe)||Cl(g,qEe)},async load(g){return await(await Gt.ADAPTER.fetch(g)).json()}};kt.add(Bfe);const tMe=".txt",gMe="text/plain",vfe={name:"loadTxt",extension:{type:pt.LoadParser,priority:so.Low},test(g){return tm(g,gMe)||Cl(g,tMe)},async load(g){return await(await Gt.ADAPTER.fetch(g)).text()}};kt.add(vfe);const IMe=["normal","bold","100","200","300","400","500","600","700","800","900"],iMe=[".ttf",".otf",".woff",".woff2"],nMe=["font/ttf","font/otf","font/woff","font/woff2"],CMe=/^(--|-?[A-Z_])[0-9A-Z_-]*$/i;function Sfe(g){const e=fi.extname(g),I=fi.basename(g,e).replace(/(-|_)/g," ").toLowerCase().split(" ").map(C=>C.charAt(0).toUpperCase()+C.slice(1));let i=I.length>0;for(const C of I)if(!C.match(CMe)){i=!1;break}let n=I.join(" ");return i||(n=`"${n.replace(/[\\"]/g,"\\$&")}"`),n}const rMe=/^[0-9A-Za-z%:/?#\[\]@!\$&'()\*\+,;=\-._~]*$/;function oMe(g){return rMe.test(g)?g:encodeURI(g)}const wfe={extension:{type:pt.LoadParser,priority:so.Low},name:"loadWebFont",test(g){return tm(g,nMe)||Cl(g,iMe)},async load(g,e){var i,n,C;const I=Gt.ADAPTER.getFontFaceSet();if(I){const r=[],o=((i=e.data)==null?void 0:i.family)??Sfe(g),A=((C=(n=e.data)==null?void 0:n.weights)==null?void 0:C.filter(a=>IMe.includes(a)))??["normal"],s=e.data??{};for(let a=0;aGt.ADAPTER.getFontFaceSet().delete(e))}};kt.add(wfe);let lee=0,t5;const AMe="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+ip1sAAAAASUVORK5CYII=",aMe={id:"checkImageBitmap",code:` - async function checkImageBitmap() - { - try - { - if (typeof createImageBitmap !== 'function') return false; - - const response = await fetch('${AMe}'); - const imageBlob = await response.blob(); - const imageBitmap = await createImageBitmap(imageBlob); - - return imageBitmap.width === 1 && imageBitmap.height === 1; - } - catch (e) - { - return false; - } - } - checkImageBitmap().then((result) => { self.postMessage(result); }); - `},sMe={id:"loadImageBitmap",code:` - async function loadImageBitmap(url) - { - const response = await fetch(url); - - if (!response.ok) - { - throw new Error(\`[WorkerManager.loadImageBitmap] Failed to fetch \${url}: \` - + \`\${response.status} \${response.statusText}\`); - } - - const imageBlob = await response.blob(); - const imageBitmap = await createImageBitmap(imageBlob); - - return imageBitmap; - } - self.onmessage = async (event) => - { - try - { - const imageBitmap = await loadImageBitmap(event.data.data[0]); - - self.postMessage({ - data: imageBitmap, - uuid: event.data.uuid, - id: event.data.id, - }, [imageBitmap]); - } - catch(e) - { - self.postMessage({ - error: e, - uuid: event.data.uuid, - id: event.data.id, - }); - } - };`};let g5;class lMe{constructor(){this._initialized=!1,this._createdWorkers=0,this.workerPool=[],this.queue=[],this.resolveHash={}}isImageBitmapSupported(){return this._isImageBitmapSupported!==void 0?this._isImageBitmapSupported:(this._isImageBitmapSupported=new Promise(e=>{const I=URL.createObjectURL(new Blob([aMe.code],{type:"application/javascript"})),i=new Worker(I);i.addEventListener("message",n=>{i.terminate(),URL.revokeObjectURL(I),e(n.data)})}),this._isImageBitmapSupported)}loadImageBitmap(e){return this._run("loadImageBitmap",[e])}async _initWorkers(){this._initialized||(this._initialized=!0)}getWorker(){t5===void 0&&(t5=navigator.hardwareConcurrency||4);let e=this.workerPool.pop();return!e&&this._createdWorkers{this.complete(I.data),this.returnWorker(I.target),this.next()})),e}returnWorker(e){this.workerPool.push(e)}complete(e){e.error!==void 0?this.resolveHash[e.uuid].reject(e.error):this.resolveHash[e.uuid].resolve(e.data),this.resolveHash[e.uuid]=null}async _run(e,I){await this._initWorkers();const i=new Promise((n,C)=>{this.queue.push({id:e,arguments:I,resolve:n,reject:C})});return this.next(),i}next(){if(!this.queue.length)return;const e=this.getWorker();if(!e)return;const I=this.queue.pop(),i=I.id;this.resolveHash[lee]={resolve:I.resolve,reject:I.reject},e.postMessage({data:I.arguments,uuid:lee++,id:i})}}const cee=new lMe;function Y0(g,e,I){g.resource.internal=!0;const i=new Bt(g),n=()=>{delete e.promiseCache[I],ac.has(I)&&ac.remove(I)};return i.baseTexture.once("destroyed",()=>{I in e.promiseCache&&(console.warn("[Assets] A BaseTexture managed by Assets was destroyed instead of unloaded! Use Assets.unload() instead of destroying the BaseTexture."),n())}),i.once("destroyed",()=>{g.destroyed||(console.warn("[Assets] A Texture managed by Assets was destroyed instead of unloaded! Use Assets.unload() instead of destroying the Texture."),n())}),i}const cMe=[".jpeg",".jpg",".png",".webp",".avif"],uMe=["image/jpeg","image/png","image/webp","image/avif"];async function Vfe(g){const e=await Gt.ADAPTER.fetch(g);if(!e.ok)throw new Error(`[loadImageBitmap] Failed to fetch ${g}: ${e.status} ${e.statusText}`);const I=await e.blob();return await createImageBitmap(I)}const xS={name:"loadTextures",extension:{type:pt.LoadParser,priority:so.High},config:{preferWorkers:!0,preferCreateImageBitmap:!0,crossOrigin:"anonymous"},test(g){return tm(g,uMe)||Cl(g,cMe)},async load(g,e,I){var o;const i=globalThis.createImageBitmap&&this.config.preferCreateImageBitmap;let n;i?this.config.preferWorkers&&await cee.isImageBitmapSupported()?n=await cee.loadImageBitmap(g):n=await Vfe(g):n=await new Promise((A,s)=>{const a=new Image;a.crossOrigin=this.config.crossOrigin,a.src=g,a.complete?A(a):(a.onload=()=>A(a),a.onerror=l=>s(l))});const C={...e.data};C.resolution??(C.resolution=Ga(g)),i&&((o=C.resourceOptions)==null?void 0:o.ownsImageBitmap)===void 0&&(C.resourceOptions={...C.resourceOptions},C.resourceOptions.ownsImageBitmap=!0);const r=new ng(n,C);return r.resource.src=g,Y0(r,I,g)},unload(g){g.destroy(!0)}};kt.add(xS);const dMe=".svg",hMe="image/svg+xml",Rfe={extension:{type:pt.LoadParser,priority:so.High},name:"loadSVG",test(g){return tm(g,hMe)||Cl(g,dMe)},async testParse(g){return FX.test(g)},async parse(g,e,I){var C;const i=new FX(g,(C=e==null?void 0:e.data)==null?void 0:C.resourceOptions);await i.load();const n=new ng(i,{resolution:Ga(g),...e==null?void 0:e.data});return n.resource.src=e.src,Y0(n,I,e.src)},async load(g,e){return(await Gt.ADAPTER.fetch(g)).text()},unload:xS.unload};kt.add(Rfe);const mMe=[".mp4",".m4v",".webm",".ogv"],fMe=["video/mp4","video/webm","video/ogg"],Wfe={name:"loadVideo",extension:{type:pt.LoadParser,priority:so.High},config:{defaultAutoPlay:!0},test(g){return tm(g,fMe)||Cl(g,mMe)},async load(g,e,I){var r;let i;const n=await(await Gt.ADAPTER.fetch(g)).blob(),C=URL.createObjectURL(n);try{const o={autoPlay:this.config.defaultAutoPlay,...(r=e==null?void 0:e.data)==null?void 0:r.resourceOptions},A=new cU(C,o);await A.load();const s=new ng(A,{alphaMode:await sme(),resolution:Ga(g),...e==null?void 0:e.data});s.resource.src=g,i=Y0(s,I,g),i.baseTexture.once("destroyed",()=>{URL.revokeObjectURL(C)})}catch(o){throw URL.revokeObjectURL(C),o}return i},unload(g){g.destroy(!0)}};kt.add(Wfe);class pMe{constructor(){this._defaultBundleIdentifierOptions={connector:"-",createBundleAssetId:(e,I)=>`${e}${this._bundleIdConnector}${I}`,extractAssetIdFromBundle:(e,I)=>I.replace(`${e}${this._bundleIdConnector}`,"")},this._bundleIdConnector=this._defaultBundleIdentifierOptions.connector,this._createBundleAssetId=this._defaultBundleIdentifierOptions.createBundleAssetId,this._extractAssetIdFromBundle=this._defaultBundleIdentifierOptions.extractAssetIdFromBundle,this._assetMap={},this._preferredOrder=[],this._parsers=[],this._resolverHash={},this._bundles={}}setBundleIdentifier(e){if(this._bundleIdConnector=e.connector??this._bundleIdConnector,this._createBundleAssetId=e.createBundleAssetId??this._createBundleAssetId,this._extractAssetIdFromBundle=e.extractAssetIdFromBundle??this._extractAssetIdFromBundle,this._extractAssetIdFromBundle("foo",this._createBundleAssetId("foo","bar"))!=="bar")throw new Error("[Resolver] GenerateBundleAssetId are not working correctly")}prefer(...e){e.forEach(I=>{this._preferredOrder.push(I),I.priority||(I.priority=Object.keys(I.params))}),this._resolverHash={}}set basePath(e){this._basePath=e}get basePath(){return this._basePath}set rootPath(e){this._rootPath=e}get rootPath(){return this._rootPath}get parsers(){return this._parsers}reset(){this.setBundleIdentifier(this._defaultBundleIdentifierOptions),this._assetMap={},this._preferredOrder=[],this._resolverHash={},this._rootPath=null,this._basePath=null,this._manifest=null,this._bundles={},this._defaultSearchParams=null}setDefaultSearchParams(e){if(typeof e=="string")this._defaultSearchParams=e;else{const I=e;this._defaultSearchParams=Object.keys(I).map(i=>`${encodeURIComponent(i)}=${encodeURIComponent(I[i])}`).join("&")}}getAlias(e){const{alias:I,name:i,src:n,srcs:C}=e;return Lr(I||i||n||C,r=>typeof r=="string"?r:Array.isArray(r)?r.map(o=>(o==null?void 0:o.src)??(o==null?void 0:o.srcs)??o):r!=null&&r.src||r!=null&&r.srcs?r.src??r.srcs:r,!0)}addManifest(e){this._manifest&&console.warn("[Resolver] Manifest already exists, this will be overwritten"),this._manifest=e,e.bundles.forEach(I=>{this.addBundle(I.name,I.assets)})}addBundle(e,I){const i=[];Array.isArray(I)?I.forEach(n=>{const C=n.src??n.srcs,r=n.alias??n.name;let o;if(typeof r=="string"){const A=this._createBundleAssetId(e,r);i.push(A),o=[r,A]}else{const A=r.map(s=>this._createBundleAssetId(e,s));i.push(...A),o=[...r,...A]}this.add({...n,alias:o,src:C})}):Object.keys(I).forEach(n=>{const C=[n,this._createBundleAssetId(e,n)];if(typeof I[n]=="string")this.add({alias:C,src:I[n]});else if(Array.isArray(I[n]))this.add({alias:C,src:I[n]});else{const r=I[n],o=r.src??r.srcs;this.add({...r,alias:C,src:Array.isArray(o)?o:[o]})}i.push(...C)}),this._bundles[e]=i}add(e,I,i,n,C){const r=[];typeof e=="string"||Array.isArray(e)&&typeof e[0]=="string"?(tg("7.2.0",`Assets.add now uses an object instead of individual parameters. -Please use Assets.add({ alias, src, data, format, loadParser }) instead.`),r.push({alias:e,src:I,data:i,format:n,loadParser:C})):Array.isArray(e)?r.push(...e):r.push(e);let o;o=A=>{this.hasKey(A)&&console.warn(`[Resolver] already has key: ${A} overwriting`)},Lr(r).forEach(A=>{const{src:s,srcs:a}=A;let{data:l,format:c,loadParser:u}=A;const d=Lr(s||a).map(f=>typeof f=="string"?Gfe(f):Array.isArray(f)?f:[f]),h=this.getAlias(A);Array.isArray(h)?h.forEach(o):o(h);const m=[];d.forEach(f=>{f.forEach(b=>{let p={};if(typeof b!="object"){p.src=b;for(let y=0;y{this._assetMap[f]=m})})}resolveBundle(e){const I=yv(e);e=Lr(e);const i={};return e.forEach(n=>{const C=this._bundles[n];if(C){const r=this.resolve(C),o={};for(const A in r){const s=r[A];o[this._extractAssetIdFromBundle(n,A)]=s}i[n]=o}}),I?i[e[0]]:i}resolveUrl(e){const I=this.resolve(e);if(typeof e!="string"){const i={};for(const n in I)i[n]=I[n].src;return i}return I.src}resolve(e){const I=yv(e);e=Lr(e);const i={};return e.forEach(n=>{if(!this._resolverHash[n])if(this._assetMap[n]){let C=this._assetMap[n];const r=C[0],o=this._getPreferredOrder(C);o==null||o.priority.forEach(A=>{o.params[A].forEach(s=>{const a=C.filter(l=>l[A]?l[A]===s:!1);a.length&&(C=a)})}),this._resolverHash[n]=C[0]??r}else this._resolverHash[n]=this.buildResolvedAsset({alias:[n],src:n},{});i[n]=this._resolverHash[n]}),I?i[e[0]]:i}hasKey(e){return!!this._assetMap[e]}hasBundle(e){return!!this._bundles[e]}_getPreferredOrder(e){for(let I=0;IC.params.format.includes(i.format));if(n)return n}return this._preferredOrder[0]}_appendDefaultSearchParams(e){if(!this._defaultSearchParams)return e;const I=/\?/.test(e)?"&":"?";return`${e}${I}${this._defaultSearchParams}`}buildResolvedAsset(e,I){const{aliases:i,data:n,loadParser:C,format:r}=I;return(this._basePath||this._rootPath)&&(e.src=fi.toAbsolute(e.src,this._basePath,this._rootPath)),e.alias=i??e.alias??[e.src],e.src=this._appendDefaultSearchParams(e.src),e.data={...n||{},...e.data},e.loadParser=C??e.loadParser,e.format=r??fi.extname(e.src).slice(1),e.srcs=e.src,e.name=e.alias,e}}class Xfe{constructor(){this._detections=[],this._initialized=!1,this.resolver=new pMe,this.loader=new $Ee,this.cache=ac,this._backgroundLoader=new QEe(this.loader),this._backgroundLoader.active=!0,this.reset()}async init(e={}){var C,r;if(this._initialized){console.warn("[Assets]AssetManager already initialized, did you load before calling this Asset.init()?");return}if(this._initialized=!0,e.defaultSearchParams&&this.resolver.setDefaultSearchParams(e.defaultSearchParams),e.basePath&&(this.resolver.basePath=e.basePath),e.bundleIdentifier&&this.resolver.setBundleIdentifier(e.bundleIdentifier),e.manifest){let o=e.manifest;typeof o=="string"&&(o=await this.load(o)),this.resolver.addManifest(o)}const I=((C=e.texturePreference)==null?void 0:C.resolution)??1,i=typeof I=="number"?[I]:I,n=await this._detectFormats({preferredFormats:(r=e.texturePreference)==null?void 0:r.format,skipDetections:e.skipDetections,detections:this._detections});this.resolver.prefer({params:{format:n,resolution:i}}),e.preferences&&this.setPreferences(e.preferences)}add(e,I,i,n,C){this.resolver.add(e,I,i,n,C)}async load(e,I){this._initialized||await this.init();const i=yv(e),n=Lr(e).map(o=>{if(typeof o!="string"){const A=this.resolver.getAlias(o);return A.some(s=>!this.resolver.hasKey(s))&&this.add(o),Array.isArray(A)?A[0]:A}return this.resolver.hasKey(o)||this.add({alias:o,src:o}),o}),C=this.resolver.resolve(n),r=await this._mapLoadToResolve(C,I);return i?r[n[0]]:r}addBundle(e,I){this.resolver.addBundle(e,I)}async loadBundle(e,I){this._initialized||await this.init();let i=!1;typeof e=="string"&&(i=!0,e=[e]);const n=this.resolver.resolveBundle(e),C={},r=Object.keys(n);let o=0,A=0;const s=()=>{I==null||I(++o/A)},a=r.map(l=>{const c=n[l];return A+=Object.keys(c).length,this._mapLoadToResolve(c,s).then(u=>{C[l]=u})});return await Promise.all(a),i?C[e[0]]:C}async backgroundLoad(e){this._initialized||await this.init(),typeof e=="string"&&(e=[e]);const I=this.resolver.resolve(e);this._backgroundLoader.add(Object.values(I))}async backgroundLoadBundle(e){this._initialized||await this.init(),typeof e=="string"&&(e=[e]);const I=this.resolver.resolveBundle(e);Object.values(I).forEach(i=>{this._backgroundLoader.add(Object.values(i))})}reset(){this.resolver.reset(),this.loader.reset(),this.cache.reset(),this._initialized=!1}get(e){if(typeof e=="string")return ac.get(e);const I={};for(let i=0;i{const s=C[o.src],a=[o.src];o.alias&&a.push(...o.alias),r[n[A]]=s,ac.set(a,s)}),r}async unload(e){this._initialized||await this.init();const I=Lr(e).map(n=>typeof n!="string"?n.src:n),i=this.resolver.resolve(I);await this._unloadFromResolved(i)}async unloadBundle(e){this._initialized||await this.init(),e=Lr(e);const I=this.resolver.resolveBundle(e),i=Object.keys(I).map(n=>this._unloadFromResolved(I[n]));await Promise.all(i)}async _unloadFromResolved(e){const I=Object.values(e);I.forEach(i=>{ac.remove(i.src)}),await this.loader.unload(I)}async _detectFormats(e){let I=[];e.preferredFormats&&(I=Array.isArray(e.preferredFormats)?e.preferredFormats:[e.preferredFormats]);for(const i of e.detections)e.skipDetections||await i.test()?I=await i.add(I):e.skipDetections||(I=await i.remove(I));return I=I.filter((i,n)=>I.indexOf(i)===n),I}get detections(){return this._detections}get preferWorkers(){return xS.config.preferWorkers}set preferWorkers(e){tg("7.2.0","Assets.prefersWorkers is deprecated, use Assets.setPreferences({ preferWorkers: true }) instead."),this.setPreferences({preferWorkers:e})}setPreferences(e){this.loader.parsers.forEach(I=>{I.config&&Object.keys(I.config).filter(i=>i in e).forEach(i=>{I.config[i]=e[i]})})}}const DZ=new Xfe;kt.handleByList(pt.LoadParser,DZ.loader.parsers).handleByList(pt.ResolveParser,DZ.resolver.parsers).handleByList(pt.CacheParser,DZ.cache.parsers).handleByList(pt.DetectionParser,DZ.detections);const Hfe={extension:pt.CacheParser,test:g=>Array.isArray(g)&&g.every(e=>e instanceof Bt),getCacheableAssets:(g,e)=>{const I={};return g.forEach(i=>{e.forEach((n,C)=>{I[i+(C===0?"":C+1)]=n})}),I}};kt.add(Hfe);async function Tfe(g){if("Image"in globalThis)return new Promise(e=>{const I=new Image;I.onload=()=>{e(!0)},I.onerror=()=>{e(!1)},I.src=g});if("createImageBitmap"in globalThis&&"fetch"in globalThis){try{const e=await(await fetch(g)).blob();await createImageBitmap(e)}catch{return!1}return!0}return!1}const Nfe={extension:{type:pt.DetectionParser,priority:1},test:async()=>Tfe("data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAAB0AAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAIAAAACAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQ0MAAAAABNjb2xybmNseAACAAIAAYAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAACVtZGF0EgAKCBgANogQEAwgMg8f8D///8WfhwB8+ErK42A="),add:async g=>[...g,"avif"],remove:async g=>g.filter(e=>e!=="avif")};kt.add(Nfe);const kfe={extension:{type:pt.DetectionParser,priority:0},test:async()=>Tfe("data:image/webp;base64,UklGRh4AAABXRUJQVlA4TBEAAAAvAAAAAAfQ//73v/+BiOh/AAA="),add:async g=>[...g,"webp"],remove:async g=>g.filter(e=>e!=="webp")};kt.add(kfe);const uee=["png","jpg","jpeg"],Yfe={extension:{type:pt.DetectionParser,priority:-1},test:()=>Promise.resolve(!0),add:async g=>[...g,...uee],remove:async g=>g.filter(e=>!uee.includes(e))};kt.add(Yfe);const bMe="WorkerGlobalScope"in globalThis&&globalThis instanceof globalThis.WorkerGlobalScope;function hU(g){return bMe?!1:document.createElement("video").canPlayType(g)!==""}const Kfe={extension:{type:pt.DetectionParser,priority:0},test:async()=>hU("video/webm"),add:async g=>[...g,"webm"],remove:async g=>g.filter(e=>e!=="webm")};kt.add(Kfe);const xfe={extension:{type:pt.DetectionParser,priority:0},test:async()=>hU("video/mp4"),add:async g=>[...g,"mp4","m4v"],remove:async g=>g.filter(e=>e!=="mp4"&&e!=="m4v")};kt.add(xfe);const Dfe={extension:{type:pt.DetectionParser,priority:0},test:async()=>hU("video/ogg"),add:async g=>[...g,"ogv"],remove:async g=>g.filter(e=>e!=="ogv")};kt.add(Dfe);const Ffe={extension:pt.ResolveParser,test:xS.test,parse:g=>{var e;return{resolution:parseFloat(((e=Gt.RETINA_PREFIX.exec(g))==null?void 0:e[1])??"1"),format:fi.extname(g).slice(1),src:g}}};kt.add(Ffe);var vC=(g=>(g[g.COMPRESSED_RGB_S3TC_DXT1_EXT=33776]="COMPRESSED_RGB_S3TC_DXT1_EXT",g[g.COMPRESSED_RGBA_S3TC_DXT1_EXT=33777]="COMPRESSED_RGBA_S3TC_DXT1_EXT",g[g.COMPRESSED_RGBA_S3TC_DXT3_EXT=33778]="COMPRESSED_RGBA_S3TC_DXT3_EXT",g[g.COMPRESSED_RGBA_S3TC_DXT5_EXT=33779]="COMPRESSED_RGBA_S3TC_DXT5_EXT",g[g.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT=35917]="COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT",g[g.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT=35918]="COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT",g[g.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT=35919]="COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT",g[g.COMPRESSED_SRGB_S3TC_DXT1_EXT=35916]="COMPRESSED_SRGB_S3TC_DXT1_EXT",g[g.COMPRESSED_R11_EAC=37488]="COMPRESSED_R11_EAC",g[g.COMPRESSED_SIGNED_R11_EAC=37489]="COMPRESSED_SIGNED_R11_EAC",g[g.COMPRESSED_RG11_EAC=37490]="COMPRESSED_RG11_EAC",g[g.COMPRESSED_SIGNED_RG11_EAC=37491]="COMPRESSED_SIGNED_RG11_EAC",g[g.COMPRESSED_RGB8_ETC2=37492]="COMPRESSED_RGB8_ETC2",g[g.COMPRESSED_RGBA8_ETC2_EAC=37496]="COMPRESSED_RGBA8_ETC2_EAC",g[g.COMPRESSED_SRGB8_ETC2=37493]="COMPRESSED_SRGB8_ETC2",g[g.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC=37497]="COMPRESSED_SRGB8_ALPHA8_ETC2_EAC",g[g.COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2=37494]="COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2",g[g.COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2=37495]="COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2",g[g.COMPRESSED_RGB_PVRTC_4BPPV1_IMG=35840]="COMPRESSED_RGB_PVRTC_4BPPV1_IMG",g[g.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG=35842]="COMPRESSED_RGBA_PVRTC_4BPPV1_IMG",g[g.COMPRESSED_RGB_PVRTC_2BPPV1_IMG=35841]="COMPRESSED_RGB_PVRTC_2BPPV1_IMG",g[g.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG=35843]="COMPRESSED_RGBA_PVRTC_2BPPV1_IMG",g[g.COMPRESSED_RGB_ETC1_WEBGL=36196]="COMPRESSED_RGB_ETC1_WEBGL",g[g.COMPRESSED_RGB_ATC_WEBGL=35986]="COMPRESSED_RGB_ATC_WEBGL",g[g.COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL=35986]="COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL",g[g.COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL=34798]="COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL",g[g.COMPRESSED_RGBA_ASTC_4x4_KHR=37808]="COMPRESSED_RGBA_ASTC_4x4_KHR",g))(vC||{});const Zv={33776:.5,33777:.5,33778:1,33779:1,35916:.5,35917:.5,35918:1,35919:1,37488:.5,37489:.5,37490:1,37491:1,37492:.5,37496:1,37493:.5,37497:1,37494:.5,37495:.5,35840:.5,35842:.5,35841:.25,35843:.25,36196:.5,35986:.5,35986:1,34798:1,37808:1};let qa,Vf;function dee(){Vf={s3tc:qa.getExtension("WEBGL_compressed_texture_s3tc"),s3tc_sRGB:qa.getExtension("WEBGL_compressed_texture_s3tc_srgb"),etc:qa.getExtension("WEBGL_compressed_texture_etc"),etc1:qa.getExtension("WEBGL_compressed_texture_etc1"),pvrtc:qa.getExtension("WEBGL_compressed_texture_pvrtc")||qa.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc"),atc:qa.getExtension("WEBGL_compressed_texture_atc"),astc:qa.getExtension("WEBGL_compressed_texture_astc")}}const Efe={extension:{type:pt.DetectionParser,priority:2},test:async()=>{const g=Gt.ADAPTER.createCanvas().getContext("webgl");return g?(qa=g,!0):(console.warn("WebGL not available for compressed textures."),!1)},add:async g=>{Vf||dee();const e=[];for(const I in Vf)Vf[I]&&e.push(I);return[...e,...g]},remove:async g=>(Vf||dee(),g.filter(e=>!(e in Vf)))};kt.add(Efe);class Mfe extends TS{constructor(e,I={width:1,height:1,autoLoad:!0}){let i,n;typeof e=="string"?(i=e,n=new Uint8Array):(i=null,n=e),super(n,I),this.origin=i,this.buffer=n?new kX(n):null,this._load=null,this.loaded=!1,this.origin!==null&&I.autoLoad!==!1&&this.load(),this.origin===null&&this.buffer&&(this._load=Promise.resolve(this),this.loaded=!0,this.onBlobLoaded(this.buffer.rawBinaryData))}onBlobLoaded(e){}load(){return this._load?this._load:(this._load=fetch(this.origin).then(e=>e.blob()).then(e=>e.arrayBuffer()).then(e=>(this.data=new Uint32Array(e),this.buffer=new kX(e),this.loaded=!0,this.onBlobLoaded(e),this.update(),this)),this._load)}}class Pc extends Mfe{constructor(e,I){super(e,I),this.format=I.format,this.levels=I.levels||1,this._width=I.width,this._height=I.height,this._extension=Pc._formatToExtension(this.format),(I.levelBuffers||this.buffer)&&(this._levelBuffers=I.levelBuffers||Pc._createLevelBuffers(e instanceof Uint8Array?e:this.buffer.uint8View,this.format,this.levels,4,4,this.width,this.height))}upload(e,I,i){const n=e.gl;if(!e.context.extensions[this._extension])throw new Error(`${this._extension} textures are not supported on the current machine`);if(!this._levelBuffers)return!1;n.pixelStorei(n.UNPACK_ALIGNMENT,4);for(let C=0,r=this.levels;C=33776&&e<=33779)return"s3tc";if(e>=37488&&e<=37497)return"etc";if(e>=35840&&e<=35843)return"pvrtc";if(e>=36196)return"etc1";if(e>=35986&&e<=34798)return"atc";throw new Error("Invalid (compressed) texture format given!")}static _createLevelBuffers(e,I,i,n,C,r,o){const A=new Array(i);let s=e.byteOffset,a=r,l=o,c=a+n-1&~(n-1),u=l+C-1&~(C-1),d=c*u*Zv[I];for(let h=0;h1?a:c,levelHeight:i>1?l:u,levelBuffer:new Uint8Array(e.buffer,s,d)},s+=d,a=a>>1||1,l=l>>1||1,c=a+n-1&~(n-1),u=l+C-1&~(C-1),d=c*u*Zv[I];return A}}const I5=4,EV=124,yMe=32,hee=20,ZMe=542327876,MV={SIZE:1,FLAGS:2,HEIGHT:3,WIDTH:4,MIPMAP_COUNT:7,PIXEL_FORMAT:19},GMe={SIZE:0,FLAGS:1,FOURCC:2,RGB_BITCOUNT:3,R_BIT_MASK:4,G_BIT_MASK:5,B_BIT_MASK:6,A_BIT_MASK:7},zV={DXGI_FORMAT:0,RESOURCE_DIMENSION:1,MISC_FLAG:2,ARRAY_SIZE:3,MISC_FLAGS2:4},BMe=1,vMe=2,SMe=4,wMe=64,VMe=512,RMe=131072,WMe=827611204,XMe=861165636,HMe=894720068,TMe=808540228,NMe=4,kMe={[WMe]:vC.COMPRESSED_RGBA_S3TC_DXT1_EXT,[XMe]:vC.COMPRESSED_RGBA_S3TC_DXT3_EXT,[HMe]:vC.COMPRESSED_RGBA_S3TC_DXT5_EXT},YMe={70:vC.COMPRESSED_RGBA_S3TC_DXT1_EXT,71:vC.COMPRESSED_RGBA_S3TC_DXT1_EXT,73:vC.COMPRESSED_RGBA_S3TC_DXT3_EXT,74:vC.COMPRESSED_RGBA_S3TC_DXT3_EXT,76:vC.COMPRESSED_RGBA_S3TC_DXT5_EXT,77:vC.COMPRESSED_RGBA_S3TC_DXT5_EXT,72:vC.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT,75:vC.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT,78:vC.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT};function zfe(g){const e=new Uint32Array(g);if(e[0]!==ZMe)throw new Error("Invalid DDS file magic word");const I=new Uint32Array(g,0,EV/Uint32Array.BYTES_PER_ELEMENT),i=I[MV.HEIGHT],n=I[MV.WIDTH],C=I[MV.MIPMAP_COUNT],r=new Uint32Array(g,MV.PIXEL_FORMAT*Uint32Array.BYTES_PER_ELEMENT,yMe/Uint32Array.BYTES_PER_ELEMENT),o=r[BMe];if(o&SMe){const A=r[GMe.FOURCC];if(A!==TMe){const b=kMe[A],p=I5+EV,y=new Uint8Array(g,p);return[new Pc(y,{format:b,width:n,height:i,levels:C})]}const s=I5+EV,a=new Uint32Array(e.buffer,s,hee/Uint32Array.BYTES_PER_ELEMENT),l=a[zV.DXGI_FORMAT],c=a[zV.RESOURCE_DIMENSION],u=a[zV.MISC_FLAG],d=a[zV.ARRAY_SIZE],h=YMe[l];if(h===void 0)throw new Error(`DDSParser cannot parse texture data with DXGI format ${l}`);if(u===NMe)throw new Error("DDSParser does not support cubemap textures");if(c===6)throw new Error("DDSParser does not supported 3D texture data");const m=new Array,f=I5+EV+hee;if(d===1)m.push(new Uint8Array(g,f));else{const b=Zv[h];let p=0,y=n,Z=i;for(let G=0;G>>1,Z=Z>>>1}let v=f;for(let G=0;Gnew Pc(b,{format:h,width:n,height:i,levels:C}))}throw o&wMe?new Error("DDSParser does not support uncompressed texture data."):o&VMe?new Error("DDSParser does not supported YUV uncompressed texture data."):o&RMe?new Error("DDSParser does not support single-channel (lumninance) texture data!"):o&vMe?new Error("DDSParser does not support single-channel (alpha) texture data!"):new Error("DDSParser failed to load a texture file due to an unknown reason!")}const mee=[171,75,84,88,32,49,49,187,13,10,26,10],KMe=67305985,yo={FILE_IDENTIFIER:0,ENDIANNESS:12,GL_TYPE:16,GL_TYPE_SIZE:20,GL_FORMAT:24,GL_INTERNAL_FORMAT:28,GL_BASE_INTERNAL_FORMAT:32,PIXEL_WIDTH:36,PIXEL_HEIGHT:40,PIXEL_DEPTH:44,NUMBER_OF_ARRAY_ELEMENTS:48,NUMBER_OF_FACES:52,NUMBER_OF_MIPMAP_LEVELS:56,BYTES_OF_KEY_VALUE_DATA:60},YM=64,KM={[Mt.UNSIGNED_BYTE]:1,[Mt.UNSIGNED_SHORT]:2,[Mt.INT]:4,[Mt.UNSIGNED_INT]:4,[Mt.FLOAT]:4,[Mt.HALF_FLOAT]:8},Pfe={[st.RGBA]:4,[st.RGB]:3,[st.RG]:2,[st.RED]:1,[st.LUMINANCE]:1,[st.LUMINANCE_ALPHA]:2,[st.ALPHA]:1},Jfe={[Mt.UNSIGNED_SHORT_4_4_4_4]:2,[Mt.UNSIGNED_SHORT_5_5_5_1]:2,[Mt.UNSIGNED_SHORT_5_6_5]:2};function Ofe(g,e,I=!1){const i=new DataView(e);if(!xMe(g,i))return null;const n=i.getUint32(yo.ENDIANNESS,!0)===KMe,C=i.getUint32(yo.GL_TYPE,n),r=i.getUint32(yo.GL_FORMAT,n),o=i.getUint32(yo.GL_INTERNAL_FORMAT,n),A=i.getUint32(yo.PIXEL_WIDTH,n),s=i.getUint32(yo.PIXEL_HEIGHT,n)||1,a=i.getUint32(yo.PIXEL_DEPTH,n)||1,l=i.getUint32(yo.NUMBER_OF_ARRAY_ELEMENTS,n)||1,c=i.getUint32(yo.NUMBER_OF_FACES,n),u=i.getUint32(yo.NUMBER_OF_MIPMAP_LEVELS,n),d=i.getUint32(yo.BYTES_OF_KEY_VALUE_DATA,n);if(s===0||a!==1)throw new Error("Only 2D textures are supported");if(c!==1)throw new Error("CubeTextures are not supported by KTXLoader yet!");if(l!==1)throw new Error("WebGL does not support array textures");const h=4,m=4,f=A+3&-4,b=s+3&-4,p=new Array(l);let y=A*s;C===0&&(y=f*b);let Z;if(C!==0?KM[C]?Z=KM[C]*Pfe[r]:Z=Jfe[C]:Z=Zv[o],Z===void 0)throw new Error("Unable to resolve the pixel format stored in the *.ktx file!");const v=I?FMe(i,d,n):null;let G=y*Z,B=A,w=s,R=f,S=b,X=YM+d;for(let W=0;W1||C!==0?B:R,levelHeight:u>1||C!==0?w:S,levelBuffer:new Uint8Array(e,H,G)},H+=G}X+=V+4,X=X%4!==0?X+4-X%4:X,B=B>>1||1,w=w>>1||1,R=B+h-1&~(h-1),S=w+m-1&~(m-1),G=R*S*Z}return C!==0?{uncompressed:p.map(W=>{let V=W[0].levelBuffer,H=!1;return C===Mt.FLOAT?V=new Float32Array(W[0].levelBuffer.buffer,W[0].levelBuffer.byteOffset,W[0].levelBuffer.byteLength/4):C===Mt.UNSIGNED_INT?(H=!0,V=new Uint32Array(W[0].levelBuffer.buffer,W[0].levelBuffer.byteOffset,W[0].levelBuffer.byteLength/4)):C===Mt.INT&&(H=!0,V=new Int32Array(W[0].levelBuffer.buffer,W[0].levelBuffer.byteOffset,W[0].levelBuffer.byteLength/4)),{resource:new TS(V,{width:W[0].levelWidth,height:W[0].levelHeight}),type:C,format:H?DMe(r):r}}),kvData:v}:{compressed:p.map(W=>new Pc(null,{format:o,width:A,height:s,levels:u,levelBuffers:W})),kvData:v}}function xMe(g,e){for(let I=0;Ie-n){console.error("KTXLoader: keyAndValueByteSize out of bounds");break}let A=0;for(;A{const r=new ng(C,{mipmap:uA.OFF,alphaMode:tC.NO_PREMULTIPLIED_ALPHA,resolution:Ga(g),...e.data});return Y0(r,I,g)});return n.length===1?n[0]:n},unload(g){Array.isArray(g)?g.forEach(e=>e.destroy(!0)):g.destroy(!0)}};kt.add(Lfe);const _fe={extension:{type:pt.LoadParser,priority:so.High},name:"loadKTX",test(g){return Cl(g,".ktx")},async load(g,e,I){const i=await(await Gt.ADAPTER.fetch(g)).arrayBuffer(),{compressed:n,uncompressed:C,kvData:r}=Ofe(g,i),o=n??C,A={mipmap:uA.OFF,alphaMode:tC.NO_PREMULTIPLIED_ALPHA,resolution:Ga(g),...e.data},s=o.map(a=>{o===C&&Object.assign(A,{type:a.type,format:a.format});const l=a.resource??a,c=new ng(l,A);return c.ktxKeyValueData=r,Y0(c,I,g)});return s.length===1?s[0]:s},unload(g){Array.isArray(g)?g.forEach(e=>e.destroy(!0)):g.destroy(!0)}};kt.add(_fe);const Ufe={extension:pt.ResolveParser,test:g=>{const e=fi.extname(g).slice(1);return["basis","ktx","dds"].includes(e)},parse:g=>{var I,i;const e=fi.extname(g).slice(1);if(e==="ktx"){const n=[".s3tc.ktx",".s3tc_sRGB.ktx",".etc.ktx",".etc1.ktx",".pvrt.ktx",".atc.ktx",".astc.ktx"];if(n.some(C=>g.endsWith(C)))return{resolution:parseFloat(((I=Gt.RETINA_PREFIX.exec(g))==null?void 0:I[1])??"1"),format:n.find(C=>g.endsWith(C)),src:g}}return{resolution:parseFloat(((i=Gt.RETINA_PREFIX.exec(g))==null?void 0:i[1])??"1"),format:e,src:g}}};kt.add(Ufe);const PV=new rg,EMe=4,Qfe=class FZ{constructor(e){this.renderer=e,this._rendererPremultipliedAlpha=!1}contextChange(){var I;const e=(I=this.renderer)==null?void 0:I.gl.getContextAttributes();this._rendererPremultipliedAlpha=!!(e&&e.alpha&&e.premultipliedAlpha)}async image(e,I,i,n){const C=new Image;return C.src=await this.base64(e,I,i,n),C}async base64(e,I,i,n){const C=this.canvas(e,n);if(C.toBlob!==void 0)return new Promise((r,o)=>{C.toBlob(A=>{if(!A){o(new Error("ICanvas.toBlob failed!"));return}const s=new FileReader;s.onload=()=>r(s.result),s.onerror=o,s.readAsDataURL(A)},I,i)});if(C.toDataURL!==void 0)return C.toDataURL(I,i);if(C.convertToBlob!==void 0){const r=await C.convertToBlob({type:I,quality:i});return new Promise((o,A)=>{const s=new FileReader;s.onload=()=>o(s.result),s.onerror=A,s.readAsDataURL(r)})}throw new Error("Extract.base64() requires ICanvas.toDataURL, ICanvas.toBlob, or ICanvas.convertToBlob to be implemented")}canvas(e,I){const{pixels:i,width:n,height:C,flipY:r,premultipliedAlpha:o}=this._rawPixels(e,I);r&&FZ._flipY(i,n,C),o&&FZ._unpremultiplyAlpha(i);const A=new pme(n,C,1),s=new ImageData(new Uint8ClampedArray(i.buffer),n,C);return A.context.putImageData(s,0,0),A.canvas}pixels(e,I){const{pixels:i,width:n,height:C,flipY:r,premultipliedAlpha:o}=this._rawPixels(e,I);return r&&FZ._flipY(i,n,C),o&&FZ._unpremultiplyAlpha(i),i}_rawPixels(e,I){const i=this.renderer;if(!i)throw new Error("The Extract has already been destroyed");let n,C=!1,r=!1,o,A=!1;e&&(e instanceof il?o=e:(o=i.generateTexture(e,{region:I,resolution:i.resolution,multisample:i.multisample}),A=!0,I&&(PV.width=I.width,PV.height=I.height,I=PV)));const s=i.gl;if(o){if(n=o.baseTexture.resolution,I=I??o.frame,C=!1,r=o.baseTexture.alphaMode>0&&o.baseTexture.format===st.RGBA,!A){i.renderTexture.bind(o);const u=o.framebuffer.glFramebuffers[i.CONTEXT_UID];u.blitFramebuffer&&i.framebuffer.bind(u.blitFramebuffer)}}else n=i.resolution,I||(I=PV,I.width=i.width/n,I.height=i.height/n),C=!0,r=this._rendererPremultipliedAlpha,i.renderTexture.bind();const a=Math.max(Math.round(I.width*n),1),l=Math.max(Math.round(I.height*n),1),c=new Uint8Array(EMe*a*l);return s.readPixels(Math.round(I.x*n),Math.round(I.y*n),a,l,s.RGBA,s.UNSIGNED_BYTE,c),A&&(o==null||o.destroy(!0)),{pixels:c,width:a,height:l,flipY:C,premultipliedAlpha:r}}destroy(){this.renderer=null}static _flipY(e,I,i){const n=I<<2,C=i>>1,r=new Uint8Array(n);for(let o=0;o=0&&o>=0&&n>=0&&C>=0)){e.length=0;return}const A=Math.ceil(2.3*Math.sqrt(r+o)),s=A*8+(n?4:0)+(C?4:0);if(e.length=s,s===0)return;if(A===0){e.length=8,e[0]=e[6]=I+n,e[1]=e[3]=i+C,e[2]=e[4]=I-n,e[5]=e[7]=i-C;return}let a=0,l=A*4+(n?2:0)+2,c=l,u=s;{const d=n+r,h=C,m=I+d,f=I-d,b=i+h;if(e[a++]=m,e[a++]=b,e[--l]=b,e[--l]=f,C){const p=i-h;e[c++]=f,e[c++]=p,e[--u]=p,e[--u]=m}}for(let d=1;d0||e&&i<=0){const n=I/2;for(let C=n+n%2;C=6){fee(I,!1);const r=[];for(let s=0;s=0&&C>=0&&r.push(I,i,I+n,i,I+n,i+C,I,i+C)},triangulate(g,e){const I=g.points,i=e.points;if(I.length===0)return;const n=i.length/2;i.push(I[0],I[1],I[2],I[3],I[6],I[7],I[4],I[5]),e.indices.push(n,n+1,n+2,n+1,n+2,n+3)}},qfe={build(g){Gv.build(g)},triangulate(g,e){Gv.triangulate(g,e)}};var $C=(g=>(g.MITER="miter",g.BEVEL="bevel",g.ROUND="round",g))($C||{}),ps=(g=>(g.BUTT="butt",g.ROUND="round",g.SQUARE="square",g))(ps||{});const Iu={adaptive:!0,maxLength:10,minSegments:8,maxSegments:2048,epsilon:1e-4,_segmentsCount(g,e=20){if(!this.adaptive||!g||isNaN(g))return e;let I=Math.ceil(g/this.maxLength);return Ithis.maxSegments&&(I=this.maxSegments),I}},MMe=Iu;class xM{static curveTo(e,I,i,n,C,r){const o=r[r.length-2],A=r[r.length-1]-I,s=o-e,a=n-I,l=i-e,c=Math.abs(A*l-s*a);if(c<1e-8||C===0)return(r[r.length-2]!==e||r[r.length-1]!==I)&&r.push(e,I),null;const u=A*A+s*s,d=a*a+l*l,h=A*a+s*l,m=C*Math.sqrt(u)/c,f=C*Math.sqrt(d)/c,b=m*h/u,p=f*h/d,y=m*l+f*s,Z=m*a+f*A,v=s*(f+b),G=A*(f+b),B=l*(m+p),w=a*(m+p),R=Math.atan2(G-Z,v-y),S=Math.atan2(w-Z,B-y);return{cx:y+e,cy:Z+I,radius:C,startAngle:R,endAngle:S,anticlockwise:s*a>l*A}}static arc(e,I,i,n,C,r,o,A,s){const a=o-r,l=Iu._segmentsCount(Math.abs(a)*C,Math.ceil(Math.abs(a)/uv)*40),c=a/(l*2),u=c*2,d=Math.cos(c),h=Math.sin(c),m=l-1,f=m%1/m;for(let b=0;b<=m;++b){const p=b+f*b,y=c+r+u*p,Z=Math.cos(y),v=-Math.sin(y);s.push((d*Z+h*v)*C+i,(d*-v+h*Z)*C+n)}}}class epe{constructor(){this.reset()}begin(e,I,i){this.reset(),this.style=e,this.start=I,this.attribStart=i}end(e,I){this.attribSize=I-this.attribStart,this.size=e-this.start}reset(){this.style=null,this.size=0,this.start=0,this.attribStart=0,this.attribSize=0}}class FT{static curveLength(e,I,i,n,C,r,o,A){let s=0,a=0,l=0,c=0,u=0,d=0,h=0,m=0,f=0,b=0,p=0,y=e,Z=I;for(let v=1;v<=10;++v)a=v/10,l=a*a,c=l*a,u=1-a,d=u*u,h=d*u,m=h*e+3*d*a*i+3*u*l*C+c*o,f=h*I+3*d*a*n+3*u*l*r+c*A,b=y-m,p=Z-f,y=m,Z=f,s+=Math.sqrt(b*b+p*p);return s}static curveTo(e,I,i,n,C,r,o){const A=o[o.length-2],s=o[o.length-1];o.length-=2;const a=Iu._segmentsCount(FT.curveLength(A,s,e,I,i,n,C,r));let l=0,c=0,u=0,d=0,h=0;o.push(A,s);for(let m=1,f=0;m<=a;++m)f=m/a,l=1-f,c=l*l,u=c*l,d=f*f,h=d*f,o.push(u*A+3*c*f*e+3*l*d*i+h*C,u*s+3*c*f*I+3*l*d*n+h*r)}}function pee(g,e,I,i,n,C,r,o){const A=g-I*n,s=e-i*n,a=g+I*C,l=e+i*C;let c,u;r?(c=i,u=-I):(c=-i,u=I);const d=A+c,h=s+u,m=a+c,f=l+u;return o.push(d,h,m,f),2}function ku(g,e,I,i,n,C,r,o){const A=I-g,s=i-e;let a=Math.atan2(A,s),l=Math.atan2(n-g,C-e);o&&al&&(l+=Math.PI*2);let c=a;const u=l-a,d=Math.abs(u),h=Math.sqrt(A*A+s*s),m=(15*d*Math.sqrt(h)/Math.PI>>0)+1,f=u/m;if(c+=f,o){r.push(g,e,I,i);for(let b=1,p=c;b=0&&(C.join===$C.ROUND?c+=ku(p,y,p-G*W,y-B*W,p-w*W,y-R*W,a,!1)+4:c+=2,a.push(p-w*V,y-R*V,p+w*W,y+R*W));continue}const ee=(-G+f)*(-B+y)-(-G+p)*(-B+b),Q=(-w+Z)*(-R+y)-(-w+p)*(-R+v),ne=(F*Q-J*ee)/$,fe=(te*ee-_*Q)/$,Ce=(ne-p)*(ne-p)+(fe-y)*(fe-y),Ze=p+(ne-p)*W,Ge=y+(fe-y)*W,ve=p-(ne-p)*V,ke=y-(fe-y)*V,Xe=Math.min(F*F+_*_,J*J+te*te),Oe=j?W:V,ze=Xe+Oe*Oe*h,Me=Ce<=ze;let Ue=C.join;if(Ue===$C.MITER&&Ce/h>m&&(Ue=$C.BEVEL),Me)switch(Ue){case $C.MITER:{a.push(Ze,Ge,ve,ke);break}case $C.BEVEL:{j?a.push(Ze,Ge,p+G*V,y+B*V,Ze,Ge,p+w*V,y+R*V):a.push(p-G*W,y-B*W,ve,ke,p-w*W,y-R*W,ve,ke),c+=2;break}case $C.ROUND:{j?(a.push(Ze,Ge,p+G*V,y+B*V),c+=ku(p,y,p+G*V,y+B*V,p+w*V,y+R*V,a,!0)+4,a.push(Ze,Ge,p+w*V,y+R*V)):(a.push(p-G*W,y-B*W,ve,ke),c+=ku(p,y,p-G*W,y-B*W,p-w*W,y-R*W,a,!1)+4,a.push(p-w*W,y-R*W,ve,ke));break}}else{switch(a.push(p-G*W,y-B*W,p+G*V,y+B*V),Ue){case $C.MITER:{j?a.push(ve,ke,ve,ke):a.push(Ze,Ge,Ze,Ge),c+=2;break}case $C.ROUND:{j?c+=ku(p,y,p+G*V,y+B*V,p+w*V,y+R*V,a,!0)+2:c+=ku(p,y,p-G*W,y-B*W,p-w*W,y-R*W,a,!1)+2;break}}a.push(p-w*W,y-R*W,p+w*V,y+R*V),c+=2}}f=i[(l-2)*2],b=i[(l-2)*2+1],p=i[(l-1)*2],y=i[(l-1)*2+1],G=-(b-y),B=f-p,S=Math.sqrt(G*G+B*B),G/=S,B/=S,G*=d,B*=d,a.push(p-G*W,y-B*W,p+G*V,y+B*V),A||(C.cap===ps.ROUND?c+=ku(p-G*(W-V)*.5,y-B*(W-V)*.5,p-G*W,y-B*W,p+G*V,y+B*V,a,!1)+2:C.cap===ps.SQUARE&&(c+=pee(p,y,G,B,W,V,!1,a)));const H=e.indices,D=Iu.epsilon*Iu.epsilon;for(let Y=u;Y0&&(this.invalidate(),this.clearDirty++,this.graphicsData.length=0),this}drawShape(e,I=null,i=null,n=null){const C=new Bv(e,I,i,n);return this.graphicsData.push(C),this.dirty++,this}drawHole(e,I=null){if(!this.graphicsData.length)return null;const i=new Bv(e,null,null,I),n=this.graphicsData[this.graphicsData.length-1];return i.lineStyle=n.lineStyle,n.holes.push(i),this.dirty++,this}destroy(){super.destroy();for(let e=0;e0&&(i=this.batches[this.batches.length-1],n=i.style);for(let A=this.shapeIndex;A65535;this.indicesUint16&&this.indices.length===this.indicesUint16.length&&o===this.indicesUint16.BYTES_PER_ELEMENT>2?this.indicesUint16.set(this.indices):this.indicesUint16=o?new Uint32Array(this.indices):new Uint16Array(this.indices),this.batchable=this.isBatchable(),this.batchable?this.packBatches():this.buildDrawCalls()}_compareStyles(e,I){return!(!e||!I||e.texture.baseTexture!==I.texture.baseTexture||e.color+e.alpha!==I.color+I.alpha||!!e.native!=!!I.native)}validateBatching(){if(this.dirty===this.cacheDirty||!this.graphicsData.length)return!1;for(let e=0,I=this.graphicsData.length;e65535*2)return!1;const e=this.batches;for(let I=0;I0&&(n=EZ.pop(),n||(n=new KX,n.texArray=new xX),this.drawCalls.push(n)),n.start=a,n.size=0,n.texArray.count=0,n.type=s),h.touched=1,h._batchEnabled=e,h._batchLocation=C,h.wrapMode=da.REPEAT,n.texArray.elements[n.texArray.count++]=h,C++)),n.size+=c.size,a+=c.size,o=h._batchLocation,this.addColors(I,d.color,d.alpha,c.attribSize,c.attribStart),this.addTextureIds(i,o,c.attribSize,c.attribStart)}ng._globalBatch=e,this.packAttributes()}packAttributes(){const e=this.points,I=this.uvs,i=this.colors,n=this.textureIds,C=new ArrayBuffer(e.length*3*4),r=new Float32Array(C),o=new Uint32Array(C);let A=0;for(let s=0;s0&&e.alpha>0;return i?(e.matrix&&(e.matrix=e.matrix.clone(),e.matrix.invert()),Object.assign(this._lineStyle,{visible:i},e)):this._lineStyle.reset(),this}startPoly(){if(this.currentPath){const e=this.currentPath.points,I=this.currentPath.points.length;I>2&&(this.drawShape(this.currentPath),this.currentPath=new zc,this.currentPath.closeStroke=!1,this.currentPath.points.push(e[I-2],e[I-1]))}else this.currentPath=new zc,this.currentPath.closeStroke=!1}finishPoly(){this.currentPath&&(this.currentPath.points.length>2?(this.drawShape(this.currentPath),this.currentPath=null):this.currentPath.points.length=0)}moveTo(e,I){return this.startPoly(),this.currentPath.points[0]=e,this.currentPath.points[1]=I,this}lineTo(e,I){this.currentPath||this.moveTo(0,0);const i=this.currentPath.points,n=i[i.length-2],C=i[i.length-1];return(n!==e||C!==I)&&i.push(e,I),this}_initCurve(e=0,I=0){this.currentPath?this.currentPath.points.length===0&&(this.currentPath.points=[e,I]):this.moveTo(e,I)}quadraticCurveTo(e,I,i,n){this._initCurve();const C=this.currentPath.points;return C.length===0&&this.moveTo(0,0),ET.curveTo(e,I,i,n,C),this}bezierCurveTo(e,I,i,n,C,r){return this._initCurve(),FT.curveTo(e,I,i,n,C,r,this.currentPath.points),this}arcTo(e,I,i,n,C){this._initCurve(e,I);const r=this.currentPath.points,o=xM.curveTo(e,I,i,n,C,r);if(o){const{cx:A,cy:s,radius:a,startAngle:l,endAngle:c,anticlockwise:u}=o;this.arc(A,s,a,l,c,u)}return this}arc(e,I,i,n,C,r=!1){if(n===C)return this;if(!r&&C<=n?C+=uv:r&&n<=C&&(n+=uv),C-n===0)return this;const o=e+Math.cos(n)*i,A=I+Math.sin(n)*i,s=this._geometry.closePointEps;let a=this.currentPath?this.currentPath.points:null;if(a){const l=Math.abs(a[a.length-2]-o),c=Math.abs(a[a.length-1]-A);l0;return i?(e.matrix&&(e.matrix=e.matrix.clone(),e.matrix.invert()),Object.assign(this._fillStyle,{visible:i},e)):this._fillStyle.reset(),this}endFill(){return this.finishPoly(),this._fillStyle.reset(),this}drawRect(e,I,i,n){return this.drawShape(new rg(e,I,i,n))}drawRoundedRect(e,I,i,n,C){return this.drawShape(new kS(e,I,i,n,C))}drawCircle(e,I,i){return this.drawShape(new z_(e,I,i))}drawEllipse(e,I,i,n){return this.drawShape(new NS(e,I,i,n))}drawPolygon(...e){let I,i=!0;const n=e[0];n.points?(i=n.closeStroke,I=n.points):Array.isArray(e[0])?I=e[0]:I=e;const C=new zc(I);return C.closeStroke=i,this.drawShape(C),this}drawShape(e){return this._holeMode?this._geometry.drawHole(e,this._matrix):this._geometry.drawShape(e,this._fillStyle.clone(),this._lineStyle.clone(),this._matrix),this}clear(){return this._geometry.clear(),this._lineStyle.reset(),this._fillStyle.reset(),this._boundsID++,this._matrix=null,this._holeMode=!1,this.currentPath=null,this}isFastRect(){const e=this._geometry.graphicsData;return e.length===1&&e[0].shape.type===Pi.RECT&&!e[0].matrix&&!e[0].holes.length&&!(e[0].lineStyle.visible&&e[0].lineStyle.width)}_render(e){this.finishPoly();const I=this._geometry;I.updateBatches(),I.batchable?(this.batchDirty!==I.batchDirty&&this._populateBatches(),this._renderBatched(e)):(e.batch.flush(),this._renderDirect(e))}_populateBatches(){const e=this._geometry,I=this.blendMode,i=e.batches.length;this.batchTint=-1,this._transformID=-1,this.batchDirty=e.batchDirty,this.batches.length=i,this.vertexData=new Float32Array(e.points);for(let n=0;n1?bs.from(fze,pze,i):bs.from(Yq,mze,i)},g.prototype.render=function(I){var i=this.renderer,n=this.quad,C=n.vertices;C[0]=C[6]=I._width*-I.anchor.x,C[1]=C[3]=I._height*-I.anchor.y,C[2]=C[4]=I._width*(1-I.anchor.x),C[5]=C[7]=I._height*(1-I.anchor.y);var r=I.uvRespectAnchor?I.anchor.x:0,o=I.uvRespectAnchor?I.anchor.y:0;C=n.uvs,C[0]=C[6]=-r,C[1]=C[3]=-o,C[2]=C[4]=1-r,C[5]=C[7]=1-o,n.invalidate();var A=I._texture,s=A.baseTexture,a=s.alphaMode>0,l=I.tileTransform.localTransform,c=I.uvMatrix,u=s.isPowerOfTwo&&A.frame.width===s.width&&A.frame.height===s.height;u&&(s._glTextures[i.CONTEXT_UID]?u=s.wrapMode!==$o.CLAMP:s.wrapMode===$o.CLAMP&&(s.wrapMode=$o.REPEAT));var d=u?this.simpleShader:this.shader,h=A.width,m=A.height,f=I._width,b=I._height;mV.set(l.a*h/f,l.b*h/b,l.c*m/f,l.d*m/b,l.tx/f,l.ty/b),mV.invert(),u?mV.prepend(c.mapCoord):(d.uniforms.uMapCoord=c.mapCoord.toArray(!0),d.uniforms.uClampFrame=c.uClampFrame,d.uniforms.uClampOffset=c.uClampOffset),d.uniforms.uTransform=mV.toArray(!0),d.uniforms.uColor=rL(I.tint,I.worldAlpha,d.uniforms.uColor,a),d.uniforms.translationMatrix=I.transform.worldTransform.toArray(!0),d.uniforms.uSampler=A,i.shader.bind(d),i.geometry.bind(n),this.state.blendMode=CL(I.blendMode,a),i.state.set(this.state),i.geometry.draw(this.renderer.gl.TRIANGLES,6,0)},g.extension={name:"tilingSprite",type:Pg.RendererPlugin},g}(rS);/*! + * @pixi/mesh - v6.5.10 + * Compiled Thu, 06 Jul 2023 15:25:11 UTC + * + * @pixi/mesh is licensed under the MIT License. + * http://www.opensource.org/licenses/mit-license + *//*! ***************************************************************************** +Copyright (c) Microsoft Corporation. + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +PERFORMANCE OF THIS SOFTWARE. +***************************************************************************** */var $E=function(e,g){return $E=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(I,i){I.__proto__=i}||function(I,i){for(var n in i)i.hasOwnProperty(n)&&(I[n]=i[n])},$E(e,g)};function zL(e,g){$E(e,g);function I(){this.constructor=e}e.prototype=g===null?Object.create(g):(I.prototype=g.prototype,new I)}var gfe=function(){function e(g,I){this.uvBuffer=g,this.uvMatrix=I,this.data=null,this._bufferUpdateId=-1,this._textureUpdateId=-1,this._updateID=0}return e.prototype.update=function(g){if(!(!g&&this._bufferUpdateId===this.uvBuffer._updateID&&this._textureUpdateId===this.uvMatrix._updateID)){this._bufferUpdateId=this.uvBuffer._updateID,this._textureUpdateId=this.uvMatrix._updateID;var I=this.uvBuffer.data;(!this.data||this.data.length!==I.length)&&(this.data=new Float32Array(I.length)),this.uvMatrix.multiplyUvs(I,this.data),this._updateID++}},e}(),mK=new rI,Kq=new GG,ib=function(e){zL(g,e);function g(I,i,n,C){C===void 0&&(C=Mr.TRIANGLES);var r=e.call(this)||this;return r.geometry=I,r.shader=i,r.state=n||Jc.for2d(),r.drawMode=C,r.start=0,r.size=0,r.uvs=null,r.indices=null,r.vertexData=new Float32Array(1),r.vertexDirty=-1,r._transformID=-1,r._roundPixels=yt.ROUND_PIXELS,r.batchUvs=null,r}return Object.defineProperty(g.prototype,"geometry",{get:function(){return this._geometry},set:function(I){this._geometry!==I&&(this._geometry&&(this._geometry.refCount--,this._geometry.refCount===0&&this._geometry.dispose()),this._geometry=I,this._geometry&&this._geometry.refCount++,this.vertexDirty=-1)},enumerable:!1,configurable:!0}),Object.defineProperty(g.prototype,"uvBuffer",{get:function(){return this.geometry.buffers[1]},enumerable:!1,configurable:!0}),Object.defineProperty(g.prototype,"verticesBuffer",{get:function(){return this.geometry.buffers[0]},enumerable:!1,configurable:!0}),Object.defineProperty(g.prototype,"material",{get:function(){return this.shader},set:function(I){this.shader=I},enumerable:!1,configurable:!0}),Object.defineProperty(g.prototype,"blendMode",{get:function(){return this.state.blendMode},set:function(I){this.state.blendMode=I},enumerable:!1,configurable:!0}),Object.defineProperty(g.prototype,"roundPixels",{get:function(){return this._roundPixels},set:function(I){this._roundPixels!==I&&(this._transformID=-1),this._roundPixels=I},enumerable:!1,configurable:!0}),Object.defineProperty(g.prototype,"tint",{get:function(){return"tint"in this.shader?this.shader.tint:null},set:function(I){this.shader.tint=I},enumerable:!1,configurable:!0}),Object.defineProperty(g.prototype,"texture",{get:function(){return"texture"in this.shader?this.shader.texture:null},set:function(I){this.shader.texture=I},enumerable:!1,configurable:!0}),g.prototype._render=function(I){var i=this.geometry.buffers[0].data,n=this.shader;n.batchable&&this.drawMode===Mr.TRIANGLES&&i.length0){const d=A.x-e[c].x,h=A.y-e[c].y,m=Math.sqrt(d*d+h*h);A=e[c],o+=m/s}else o=c/(a-1);C[u]=o,C[u+1]=0,C[u+2]=o,C[u+3]=1}let l=0;for(let c=0;c0?this.textureScale*this._width/2:this._width/2;for(let s=0;s0?this.build():this.updateVertices()}}class Ape extends vb{constructor(e,I,i){const n=new rpe(e.width,e.height,I,i),C=new Sb(Bt.WHITE);super(n,C),this.texture=e,this.autoResize=!0}textureUpdated(){this._textureID=this.shader.texture._updateID;const e=this.geometry,{width:I,height:i}=this.shader.texture;this.autoResize&&(e.width!==I||e.height!==i)&&(e.width=this.shader.texture.width,e.height=this.shader.texture.height,e.build())}set texture(e){this.shader.texture!==e&&(this.shader.texture=e,this._textureID=-1,e.baseTexture.valid?this.textureUpdated():e.once("update",this.textureUpdated,this))}get texture(){return this.shader.texture}_render(e){this._textureID!==this.shader.texture._updateID&&this.textureUpdated(),super._render(e)}destroy(e){this.shader.texture.off("update",this.textureUpdated,this),super.destroy(e)}}const JV=10;class _Me extends Ape{constructor(e,I,i,n,C){var r,o,A,s;super(Bt.WHITE,4,4),this._origWidth=e.orig.width,this._origHeight=e.orig.height,this._width=this._origWidth,this._height=this._origHeight,this._leftWidth=I??((r=e.defaultBorders)==null?void 0:r.left)??JV,this._rightWidth=n??((o=e.defaultBorders)==null?void 0:o.right)??JV,this._topHeight=i??((A=e.defaultBorders)==null?void 0:A.top)??JV,this._bottomHeight=C??((s=e.defaultBorders)==null?void 0:s.bottom)??JV,this.texture=e}textureUpdated(){this._textureID=this.shader.texture._updateID,this._refresh()}get vertices(){return this.geometry.getBuffer("aVertexPosition").data}set vertices(e){this.geometry.getBuffer("aVertexPosition").data=e}updateHorizontalVertices(){const e=this.vertices,I=this._getMinScale();e[9]=e[11]=e[13]=e[15]=this._topHeight*I,e[17]=e[19]=e[21]=e[23]=this._height-this._bottomHeight*I,e[25]=e[27]=e[29]=e[31]=this._height}updateVerticalVertices(){const e=this.vertices,I=this._getMinScale();e[2]=e[10]=e[18]=e[26]=this._leftWidth*I,e[4]=e[12]=e[20]=e[28]=this._width-this._rightWidth*I,e[6]=e[14]=e[22]=e[30]=this._width}_getMinScale(){const e=this._leftWidth+this._rightWidth,I=this._width>e?1:this._width/e,i=this._topHeight+this._bottomHeight,n=this._height>i?1:this._height/i;return Math.min(I,n)}get width(){return this._width}set width(e){this._width=e,this._refresh()}get height(){return this._height}set height(e){this._height=e,this._refresh()}get leftWidth(){return this._leftWidth}set leftWidth(e){this._leftWidth=e,this._refresh()}get rightWidth(){return this._rightWidth}set rightWidth(e){this._rightWidth=e,this._refresh()}get topHeight(){return this._topHeight}set topHeight(e){this._topHeight=e,this._refresh()}get bottomHeight(){return this._bottomHeight}set bottomHeight(e){this._bottomHeight=e,this._refresh()}_refresh(){const e=this.texture,I=this.geometry.buffers[1].data;this._origWidth=e.orig.width,this._origHeight=e.orig.height;const i=1/this._origWidth,n=1/this._origHeight;I[0]=I[8]=I[16]=I[24]=0,I[1]=I[3]=I[5]=I[7]=0,I[6]=I[14]=I[22]=I[30]=1,I[25]=I[27]=I[29]=I[31]=1,I[2]=I[10]=I[18]=I[26]=i*this._leftWidth,I[4]=I[12]=I[20]=I[28]=1-i*this._rightWidth,I[9]=I[11]=I[13]=I[15]=n*this._topHeight,I[17]=I[19]=I[21]=I[23]=1-n*this._bottomHeight,this.updateHorizontalVertices(),this.updateVerticalVertices(),this.geometry.buffers[0].update(),this.geometry.buffers[1].update()}}class UMe extends vb{constructor(e=Bt.EMPTY,I,i,n,C){const r=new FS(I,i,n);r.getBuffer("aVertexPosition").static=!1;const o=new Sb(e);super(r,o,null,C),this.autoUpdate=!0}get vertices(){return this.geometry.getBuffer("aVertexPosition").data}set vertices(e){this.geometry.getBuffer("aVertexPosition").data=e}_render(e){this.autoUpdate&&this.geometry.getBuffer("aVertexPosition").update(),super._render(e)}}class QMe extends vb{constructor(e,I,i=0){const n=new ope(e.height,I,i),C=new Sb(e);i>0&&(e.baseTexture.wrapMode=da.REPEAT),super(n,C),this.autoUpdate=!0}_render(e){const I=this.geometry;(this.autoUpdate||I._width!==this.shader.texture.height)&&(I._width=this.shader.texture.height,I.update()),super._render(e)}}class jMe extends yr{constructor(e=1500,I,i=16384,n=!1){super();const C=16384;i>C&&(i=C),this._properties=[!1,!0,!1,!1,!1],this._maxSize=e,this._batchSize=i,this._buffers=null,this._bufferUpdateIDs=[],this._updateID=0,this.interactiveChildren=!1,this.blendMode=$t.NORMAL,this.autoResize=n,this.roundPixels=!0,this.baseTexture=null,this.setProperties(I),this._tintColor=new xg(0),this.tintRgb=new Float32Array(3),this.tint=16777215}setProperties(e){e&&(this._properties[0]="vertices"in e||"scale"in e?!!e.vertices||!!e.scale:this._properties[0],this._properties[1]="position"in e?!!e.position:this._properties[1],this._properties[2]="rotation"in e?!!e.rotation:this._properties[2],this._properties[3]="uvs"in e?!!e.uvs:this._properties[3],this._properties[4]="tint"in e||"alpha"in e?!!e.tint||!!e.alpha:this._properties[4])}updateTransform(){this.displayObjectUpdateTransform()}get tint(){return this._tintColor.value}set tint(e){this._tintColor.setValue(e),this._tintColor.toRgbArray(this.tintRgb)}render(e){!this.visible||this.worldAlpha<=0||!this.children.length||!this.renderable||(this.baseTexture||(this.baseTexture=this.children[0]._texture.baseTexture,this.baseTexture.valid||this.baseTexture.once("update",()=>this.onChildrenChange(0))),e.batch.setObjectRenderer(e.plugins.particle),e.plugins.particle.render(this))}onChildrenChange(e){const I=Math.floor(e/this._batchSize);for(;this._bufferUpdateIDs.length>16)+(I&65280)+((I&255)<<16),this._colorDirty=!0)},enumerable:!1,configurable:!0}),g.prototype.update=function(){if(this._colorDirty){this._colorDirty=!1;var I=this.texture.baseTexture;rL(this._tint,this._alpha,this.uniforms.uColor,I.alphaMode)}this.uvMatrix.update()&&(this.uniforms.uTextureMatrix=this.uvMatrix.mapCoord)},g}(bs),oS=function(e){zL(g,e);function g(I,i,n){var C=e.call(this)||this,r=new ci(I),o=new ci(i,!0),A=new ci(n,!0,!0);return C.addAttribute("aVertexPosition",r,2,!1,Et.FLOAT).addAttribute("aTextureCoord",o,2,!1,Et.FLOAT).addIndex(A),C._updateId=-1,C}return Object.defineProperty(g.prototype,"vertexDirtyId",{get:function(){return this.buffers[0]._updateID},enumerable:!1,configurable:!0}),g}(u0);/*! + * @pixi/text-bitmap - v6.5.10 + * Compiled Thu, 06 Jul 2023 15:25:11 UTC + * + * @pixi/text-bitmap is licensed under the MIT License. + * http://www.opensource.org/licenses/mit-license + *//*! ***************************************************************************** +Copyright (c) Microsoft Corporation. + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +PERFORMANCE OF THIS SOFTWARE. +***************************************************************************** */var qE=function(e,g){return qE=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(I,i){I.__proto__=i}||function(I,i){for(var n in i)i.hasOwnProperty(n)&&(I[n]=i[n])},qE(e,g)};function Zze(e,g){qE(e,g);function I(){this.constructor=e}e.prototype=g===null?Object.create(g):(I.prototype=g.prototype,new I)}var qv=function(){function e(){this.info=[],this.common=[],this.page=[],this.char=[],this.kerning=[],this.distanceField=[]}return e}(),Ife=function(){function e(){}return e.test=function(g){return typeof g=="string"&&g.indexOf("info face=")===0},e.parse=function(g){var I=g.match(/^[a-z]+\s+.+$/gm),i={info:[],common:[],page:[],char:[],chars:[],kerning:[],kernings:[],distanceField:[]};for(var n in I){var C=I[n].match(/^[a-z]+/gm)[0],r=I[n].match(/[a-zA-Z]+=([^\s"']+|"([^"]*)")/gm),o={};for(var A in r){var s=r[A].split("="),a=s[0],l=s[1].replace(/"/gm,""),c=parseFloat(l),u=isNaN(c)?l:c;o[a]=u}i[C].push(o)}var d=new qv;return i.info.forEach(function(h){return d.info.push({face:h.face,size:parseInt(h.size,10)})}),i.common.forEach(function(h){return d.common.push({lineHeight:parseInt(h.lineHeight,10)})}),i.page.forEach(function(h){return d.page.push({id:parseInt(h.id,10),file:h.file})}),i.char.forEach(function(h){return d.char.push({id:parseInt(h.id,10),page:parseInt(h.page,10),x:parseInt(h.x,10),y:parseInt(h.y,10),width:parseInt(h.width,10),height:parseInt(h.height,10),xoffset:parseInt(h.xoffset,10),yoffset:parseInt(h.yoffset,10),xadvance:parseInt(h.xadvance,10)})}),i.kerning.forEach(function(h){return d.kerning.push({first:parseInt(h.first,10),second:parseInt(h.second,10),amount:parseInt(h.amount,10)})}),i.distanceField.forEach(function(h){return d.distanceField.push({distanceRange:parseInt(h.distanceRange,10),fieldType:h.fieldType})}),d},e}(),iX=function(){function e(){}return e.test=function(g){return g instanceof XMLDocument&&g.getElementsByTagName("page").length&&g.getElementsByTagName("info")[0].getAttribute("face")!==null},e.parse=function(g){for(var I=new qv,i=g.getElementsByTagName("info"),n=g.getElementsByTagName("common"),C=g.getElementsByTagName("page"),r=g.getElementsByTagName("char"),o=g.getElementsByTagName("kerning"),A=g.getElementsByTagName("distanceField"),s=0;s")>-1){var I=new globalThis.DOMParser().parseFromString(g,"text/xml");return iX.test(I)}return!1},e.parse=function(g){var I=new globalThis.DOMParser().parseFromString(g,"text/xml");return iX.parse(I)},e}(),fK=[Ife,iX,ife];function PL(e){for(var g=0;g=s-w*o){if(h===0)throw new Error("[BitmapFont] textureHeight "+s+"px is too small "+("(fontFamily: '"+l.fontFamily+"', fontSize: "+l.fontSize+"px, char: '"+B+"')"));--Z,m=null,f=null,b=null,h=0,d=0,p=0;continue}if(p=Math.max(w+G.fontProperties.descent,p),V*o+d>=c){if(d===0)throw new Error("[BitmapFont] textureWidth "+A+"px is too small "+("(fontFamily: '"+l.fontFamily+"', fontSize: "+l.fontSize+"px, char: '"+B+"')"));--Z,h+=p*o,h=Math.ceil(h),d=0,p=0;continue}vze(m,f,G,d,h,o,l);var S=o1(G.text);u.char.push({id:S,page:y.length-1,x:d/o,y:h/o,width:V,height:w,xoffset:0,yoffset:0,xadvance:Math.ceil(v-(l.dropShadow?l.dropShadowDistance:0)-(l.stroke?l.strokeThickness:0))}),d+=(V+2*r)*o,d=Math.ceil(d)}if(!(i!=null&&i.skipKerning))for(var Z=0,X=a.length;Z 0.99) {\r + alpha = 1.0;\r + }\r +\r + // NPM Textures, NPM outputs\r + gl_FragColor = vec4(uColor.rgb, uColor.a * alpha);\r +\r +}\r +`,wze=`// Mesh material default fragment\r +attribute vec2 aVertexPosition;\r +attribute vec2 aTextureCoord;\r +\r +uniform mat3 projectionMatrix;\r +uniform mat3 translationMatrix;\r +uniform mat3 uTextureMatrix;\r +\r +varying vec2 vTextureCoord;\r +\r +void main(void)\r +{\r + gl_Position = vec4((projectionMatrix * translationMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);\r +\r + vTextureCoord = (uTextureMatrix * vec3(aTextureCoord, 1.0)).xy;\r +}\r +`,Dq=[],xq=[],Fq=[],Vze=function(e){Zze(g,e);function g(I,i){i===void 0&&(i={});var n=e.call(this)||this;n._tint=16777215;var C=Object.assign({},g.styleDefaults,i),r=C.align,o=C.tint,A=C.maxWidth,s=C.letterSpacing,a=C.fontName,l=C.fontSize;if(!Oa.available[a])throw new Error('Missing BitmapFont "'+a+'"');return n._activePagesMeshData=[],n._textWidth=0,n._textHeight=0,n._align=r,n._tint=o,n._font=void 0,n._fontName=a,n._fontSize=l,n.text=I,n._maxWidth=A,n._maxLineHeight=0,n._letterSpacing=s,n._anchor=new qu(function(){n.dirty=!0},n,0,0),n._roundPixels=yt.ROUND_PIXELS,n.dirty=!0,n._resolution=yt.RESOLUTION,n._autoResolution=!0,n._textureCache={},n}return g.prototype.updateText=function(){for(var I,i=Oa.available[this._fontName],n=this.fontSize,C=n/i.size,r=new rI,o=[],A=[],s=[],a=this._text.replace(/(?:\r\n|\r)/g,` +`)||" ",l=nfe(a),c=this._maxWidth*i.size/n,u=i.distanceFieldType==="none"?Dq:xq,d=null,h=0,m=0,f=0,b=-1,p=0,y=0,Z=0,B=0,G=0;G0&&r.x>c&&(++y,hd(o,1+b-y,1+G-b),G=b,b=-1,A.push(p),s.push(o.length>0?o[o.length-1].prevSpaces:0),m=Math.max(m,p),f++,r.x=0,r.y+=i.lineHeight,d=null,B=0)}}var X=l[l.length-1];X!=="\r"&&X!==` +`&&(/(?:\s)/.test(X)&&(h=p),A.push(h),m=Math.max(m,h),s.push(-1));for(var W=[],G=0;G<=f;G++){var R=0;this._align==="right"?R=m-A[G]:this._align==="center"?R=(m-A[G])/2:this._align==="justify"&&(R=s[G]<0?0:(m-A[G])/s[G]),W.push(R)}var H=o.length,Y={},D=[],E=this._activePagesMeshData;u.push.apply(u,E);for(var G=0;G6*ie)||ee.vertices.lengthi&&!e.autoResize&&(r=i);let o=e._buffers;o||(o=e._buffers=this.generateBuffers(e));const A=I[0]._texture.baseTexture,s=A.alphaMode>0;this.state.blendMode=F_(e.blendMode,s),C.state.set(this.state);const a=C.gl,l=e.worldTransform.copyTo(this.tempMatrix);l.prepend(C.globalUniforms.uniforms.projectionMatrix),this.shader.uniforms.translationMatrix=l.toArray(!0),this.shader.uniforms.uColor=xg.shared.setValue(e.tintRgb).premultiply(e.worldAlpha,s).toArray(this.shader.uniforms.uColor),this.shader.uniforms.uSampler=A,this.renderer.shader.bind(this.shader);let c=!1;for(let u=0,d=0;un&&(h=n),d>=o.length&&o.push(this._generateOneMoreBuffer(e));const m=o[d];m.uploadDynamic(I,u,h);const f=e._bufferUpdateIDs[d]||0;c=c||m._updateID0);n[r]=s,n[r+C]=s,n[r+C*2]=s,n[r+C*3]=s,r+=C*4}}destroy(){super.destroy(),this.shader&&(this.shader.destroy(),this.shader=null),this.tempMatrix=null}}pU.extension={name:"particle",type:pt.RendererPlugin};kt.add(pU);var ES=(g=>(g[g.LINEAR_VERTICAL=0]="LINEAR_VERTICAL",g[g.LINEAR_HORIZONTAL=1]="LINEAR_HORIZONTAL",g))(ES||{});const OV={willReadFrequently:!0},KA=class Kt{static get experimentalLetterSpacingSupported(){let e=Kt._experimentalLetterSpacingSupported;if(e!==void 0){const I=Gt.ADAPTER.getCanvasRenderingContext2D().prototype;e=Kt._experimentalLetterSpacingSupported="letterSpacing"in I||"textLetterSpacing"in I}return e}constructor(e,I,i,n,C,r,o,A,s){this.text=e,this.style=I,this.width=i,this.height=n,this.lines=C,this.lineWidths=r,this.lineHeight=o,this.maxLineWidth=A,this.fontProperties=s}static measureText(e,I,i,n=Kt._canvas){i=i??I.wordWrap;const C=I.toFontString(),r=Kt.measureFont(C);r.fontSize===0&&(r.fontSize=I.fontSize,r.ascent=I.fontSize);const o=n.getContext("2d",OV);o.font=C;const A=(i?Kt.wordWrap(e,I,n):e).split(/(?:\r\n|\r|\n)/),s=new Array(A.length);let a=0;for(let d=0;d0&&(n?C-=I:C+=(Kt.graphemeSegmenter(e).length-1)*I),C}static wordWrap(e,I,i=Kt._canvas){const n=i.getContext("2d",OV);let C=0,r="",o="";const A=Object.create(null),{letterSpacing:s,whiteSpace:a}=I,l=Kt.collapseSpaces(a),c=Kt.collapseNewlines(a);let u=!l;const d=I.wordWrapWidth+s,h=Kt.tokenize(e);for(let m=0;md)if(r!==""&&(o+=Kt.addLine(r),r="",C=0),Kt.canBreakWords(f,I.breakWords)){const p=Kt.wordWrapSplit(f);for(let y=0;yd&&(o+=Kt.addLine(r),u=!1,r="",C=0),r+=Z,C+=B}}else{r.length>0&&(o+=Kt.addLine(r),r="",C=0);const p=m===h.length-1;o+=Kt.addLine(f,!p),u=!1,r="",C=0}else b+C>d&&(u=!1,o+=Kt.addLine(r),r="",C=0),(r.length>0||!Kt.isBreakingSpace(f)||u)&&(r+=f,C+=b)}return o+=Kt.addLine(r,!1),o}static addLine(e,I=!0){return e=Kt.trimRight(e),e=I?`${e} -`:e,e}static getFromCache(e,I,i,n){let C=i[e];return typeof C!="number"&&(C=Kt._measureText(e,I,n)+I,i[e]=C),C}static collapseSpaces(e){return e==="normal"||e==="pre-line"}static collapseNewlines(e){return e==="normal"}static trimRight(e){if(typeof e!="string")return"";for(let I=e.length-1;I>=0;I--){const i=e[I];if(!Kt.isBreakingSpace(i))break;e=e.slice(0,-1)}return e}static isNewline(e){return typeof e!="string"?!1:Kt._newlines.includes(e.charCodeAt(0))}static isBreakingSpace(e,I){return typeof e!="string"?!1:Kt._breakingSpaces.includes(e.charCodeAt(0))}static tokenize(e){const I=[];let i="";if(typeof e!="string")return I;for(let n=0;no;--c){for(let h=0;h{if(typeof(Intl==null?void 0:Intl.Segmenter)=="function"){const g=new Intl.Segmenter;return e=>[...g.segment(e)].map(I=>I.segment)}return g=>[...g]})(),KA.experimentalLetterSpacing=!1,KA._fonts={},KA._newlines=[10,13],KA._breakingSpaces=[9,32,8192,8193,8194,8195,8196,8197,8198,8200,8201,8202,8287,12288];let rs=KA;const e3e=["serif","sans-serif","monospace","cursive","fantasy","system-ui"],ape=class MZ{constructor(e){this.styleID=0,this.reset(),r5(this,e,e)}clone(){const e={};return r5(e,this,MZ.defaultStyle),new MZ(e)}reset(){r5(this,MZ.defaultStyle,MZ.defaultStyle)}get align(){return this._align}set align(e){this._align!==e&&(this._align=e,this.styleID++)}get breakWords(){return this._breakWords}set breakWords(e){this._breakWords!==e&&(this._breakWords=e,this.styleID++)}get dropShadow(){return this._dropShadow}set dropShadow(e){this._dropShadow!==e&&(this._dropShadow=e,this.styleID++)}get dropShadowAlpha(){return this._dropShadowAlpha}set dropShadowAlpha(e){this._dropShadowAlpha!==e&&(this._dropShadowAlpha=e,this.styleID++)}get dropShadowAngle(){return this._dropShadowAngle}set dropShadowAngle(e){this._dropShadowAngle!==e&&(this._dropShadowAngle=e,this.styleID++)}get dropShadowBlur(){return this._dropShadowBlur}set dropShadowBlur(e){this._dropShadowBlur!==e&&(this._dropShadowBlur=e,this.styleID++)}get dropShadowColor(){return this._dropShadowColor}set dropShadowColor(e){const I=C5(e);this._dropShadowColor!==I&&(this._dropShadowColor=I,this.styleID++)}get dropShadowDistance(){return this._dropShadowDistance}set dropShadowDistance(e){this._dropShadowDistance!==e&&(this._dropShadowDistance=e,this.styleID++)}get fill(){return this._fill}set fill(e){const I=C5(e);this._fill!==I&&(this._fill=I,this.styleID++)}get fillGradientType(){return this._fillGradientType}set fillGradientType(e){this._fillGradientType!==e&&(this._fillGradientType=e,this.styleID++)}get fillGradientStops(){return this._fillGradientStops}set fillGradientStops(e){t3e(this._fillGradientStops,e)||(this._fillGradientStops=e,this.styleID++)}get fontFamily(){return this._fontFamily}set fontFamily(e){this.fontFamily!==e&&(this._fontFamily=e,this.styleID++)}get fontSize(){return this._fontSize}set fontSize(e){this._fontSize!==e&&(this._fontSize=e,this.styleID++)}get fontStyle(){return this._fontStyle}set fontStyle(e){this._fontStyle!==e&&(this._fontStyle=e,this.styleID++)}get fontVariant(){return this._fontVariant}set fontVariant(e){this._fontVariant!==e&&(this._fontVariant=e,this.styleID++)}get fontWeight(){return this._fontWeight}set fontWeight(e){this._fontWeight!==e&&(this._fontWeight=e,this.styleID++)}get letterSpacing(){return this._letterSpacing}set letterSpacing(e){this._letterSpacing!==e&&(this._letterSpacing=e,this.styleID++)}get lineHeight(){return this._lineHeight}set lineHeight(e){this._lineHeight!==e&&(this._lineHeight=e,this.styleID++)}get leading(){return this._leading}set leading(e){this._leading!==e&&(this._leading=e,this.styleID++)}get lineJoin(){return this._lineJoin}set lineJoin(e){this._lineJoin!==e&&(this._lineJoin=e,this.styleID++)}get miterLimit(){return this._miterLimit}set miterLimit(e){this._miterLimit!==e&&(this._miterLimit=e,this.styleID++)}get padding(){return this._padding}set padding(e){this._padding!==e&&(this._padding=e,this.styleID++)}get stroke(){return this._stroke}set stroke(e){const I=C5(e);this._stroke!==I&&(this._stroke=I,this.styleID++)}get strokeThickness(){return this._strokeThickness}set strokeThickness(e){this._strokeThickness!==e&&(this._strokeThickness=e,this.styleID++)}get textBaseline(){return this._textBaseline}set textBaseline(e){this._textBaseline!==e&&(this._textBaseline=e,this.styleID++)}get trim(){return this._trim}set trim(e){this._trim!==e&&(this._trim=e,this.styleID++)}get whiteSpace(){return this._whiteSpace}set whiteSpace(e){this._whiteSpace!==e&&(this._whiteSpace=e,this.styleID++)}get wordWrap(){return this._wordWrap}set wordWrap(e){this._wordWrap!==e&&(this._wordWrap=e,this.styleID++)}get wordWrapWidth(){return this._wordWrapWidth}set wordWrapWidth(e){this._wordWrapWidth!==e&&(this._wordWrapWidth=e,this.styleID++)}toFontString(){const e=typeof this.fontSize=="number"?`${this.fontSize}px`:this.fontSize;let I=this.fontFamily;Array.isArray(this.fontFamily)||(I=this.fontFamily.split(","));for(let i=I.length-1;i>=0;i--){let n=I[i].trim();!/([\"\'])[^\'\"]+\1/.test(n)&&!e3e.includes(n)&&(n=`"${n}"`),I[i]=n}return`${this.fontStyle} ${this.fontVariant} ${this.fontWeight} ${e} ${I.join(",")}`}};ape.defaultStyle={align:"left",breakWords:!1,dropShadow:!1,dropShadowAlpha:1,dropShadowAngle:Math.PI/6,dropShadowBlur:0,dropShadowColor:"black",dropShadowDistance:5,fill:"black",fillGradientType:ES.LINEAR_VERTICAL,fillGradientStops:[],fontFamily:"Arial",fontSize:26,fontStyle:"normal",fontVariant:"normal",fontWeight:"normal",leading:0,letterSpacing:0,lineHeight:0,lineJoin:"miter",miterLimit:10,padding:0,stroke:"black",strokeThickness:0,textBaseline:"alphabetic",trim:!1,whiteSpace:"pre",wordWrap:!1,wordWrapWidth:100};let Ps=ape;function C5(g){const e=xg.shared,I=i=>{const n=e.setValue(i);return n.alpha===1?n.toHex():n.toRgbaString()};return Array.isArray(g)?g.map(I):I(g)}function t3e(g,e){if(!Array.isArray(g)||!Array.isArray(e)||g.length!==e.length)return!1;for(let I=0;I0&&d>h&&(m=(h+d)/2);const f=h+c,b=i.lineHeight*(u+1);let p=f;u+10}}function I3e(g,e){var i;let I=!1;if((i=g==null?void 0:g._textures)!=null&&i.length){for(let n=0;n{this.queue&&this.prepareItems()},this.registerFindHook(o3e),this.registerFindHook(A3e),this.registerFindHook(I3e),this.registerFindHook(i3e),this.registerFindHook(n3e),this.registerUploadHook(C3e),this.registerUploadHook(r3e)}upload(e){return new Promise(I=>{e&&this.add(e),this.queue.length?(this.completes.push(I),this.ticking||(this.ticking=!0,Ji.system.addOnce(this.tick,this,zs.UTILITY))):I()})}tick(){setTimeout(this.delayedTick,0)}prepareItems(){for(this.limiter.beginFrame();this.queue.length&&this.limiter.allowedToUpload();){const e=this.queue[0];let I=!1;if(e&&!e._destroyed){for(let i=0,n=this.uploadHooks.length;i=0;I--)this.add(e.children[I]);return this}destroy(){this.ticking&&Ji.system.remove(this.tick,this),this.ticking=!1,this.addHooks=null,this.uploadHooks=null,this.renderer=null,this.completes=null,this.queue=null,this.limiter=null,this.uploadHookHelper=null}};cpe.uploadsPerFrame=4;let JX=cpe;Object.defineProperties(Gt,{UPLOADS_PER_FRAME:{get(){return JX.uploadsPerFrame},set(g){tg("7.1.0","settings.UPLOADS_PER_FRAME is deprecated, use prepare.BasePrepare.uploadsPerFrame"),JX.uploadsPerFrame=g}}});function dpe(g,e){return e instanceof ng?(e._glTextures[g.CONTEXT_UID]||g.texture.bind(e),!0):!1}function a3e(g,e){if(!(e instanceof fU))return!1;const{geometry:I}=e;e.finishPoly(),I.updateBatches();const{batches:i}=I;for(let n=0;n=this._durations[this.currentFrame];)n-=this._durations[this.currentFrame]*C,this._currentTime+=C;this._currentTime+=n/this._durations[this.currentFrame]}else this._currentTime+=I;this._currentTime<0&&!this.loop?(this.gotoAndStop(0),this.onComplete&&this.onComplete()):this._currentTime>=this._textures.length&&!this.loop?(this.gotoAndStop(this._textures.length-1),this.onComplete&&this.onComplete()):i!==this.currentFrame&&(this.loop&&this.onLoop&&(this.animationSpeed>0&&this.currentFramei)&&this.onLoop(),this.updateTexture())}updateTexture(){const e=this.currentFrame;this._previousFrame!==e&&(this._previousFrame=e,this._texture=this._textures[e],this._textureID=-1,this._textureTrimmedID=-1,this._cachedTint=16777215,this.uvs=this._texture._uvs.uvsFloat32,this.updateAnchor&&this._anchor.copyFrom(this._texture.defaultAnchor),this.onFrameChange&&this.onFrameChange(this.currentFrame))}destroy(e){this.stop(),super.destroy(e),this.onComplete=null,this.onFrameChange=null,this.onLoop=null}static fromFrames(e){const I=[];for(let i=0;ithis.totalFrames-1)throw new Error(`[AnimatedSprite]: Invalid frame index value ${e}, expected to be between 0 and totalFrames ${this.totalFrames}.`);const I=this.currentFrame;this._currentTime=e,I!==this.currentFrame&&this.updateTexture()}get playing(){return this._playing}get autoUpdate(){return this._autoUpdate}set autoUpdate(e){e!==this._autoUpdate&&(this._autoUpdate=e,!this._autoUpdate&&this._isConnectedToTicker?(Ji.shared.remove(this.update,this),this._isConnectedToTicker=!1):this._autoUpdate&&!this._isConnectedToTicker&&this._playing&&(Ji.shared.add(this.update,this),this._isConnectedToTicker=!0))}}const Fy=new Gg;class ZU extends nl{constructor(e,I=100,i=100){super(e),this.tileTransform=new YS,this._width=I,this._height=i,this.uvMatrix=this.texture.uvMatrix||new xT(e),this.pluginName="tilingSprite",this.uvRespectAnchor=!1}get clampMargin(){return this.uvMatrix.clampMargin}set clampMargin(e){this.uvMatrix.clampMargin=e,this.uvMatrix.update(!0)}get tileScale(){return this.tileTransform.scale}set tileScale(e){this.tileTransform.scale.copyFrom(e)}get tilePosition(){return this.tileTransform.position}set tilePosition(e){this.tileTransform.position.copyFrom(e)}_onTextureUpdate(){this.uvMatrix&&(this.uvMatrix.texture=this._texture),this._cachedTint=16777215}_render(e){const I=this._texture;!I||!I.valid||(this.tileTransform.updateLocalTransform(),this.uvMatrix.update(),e.batch.setObjectRenderer(e.plugins[this.pluginName]),e.plugins[this.pluginName].render(this))}_calculateBounds(){const e=this._width*-this._anchor._x,I=this._height*-this._anchor._y,i=this._width*(1-this._anchor._x),n=this._height*(1-this._anchor._y);this._bounds.addFrame(this.transform,e,I,i,n)}getLocalBounds(e){return this.children.length===0?(this._bounds.minX=this._width*-this._anchor._x,this._bounds.minY=this._height*-this._anchor._y,this._bounds.maxX=this._width*(1-this._anchor._x),this._bounds.maxY=this._height*(1-this._anchor._y),e||(this._localBoundsRect||(this._localBoundsRect=new rg),e=this._localBoundsRect),this._bounds.getRectangle(e)):super.getLocalBounds.call(this,e)}containsPoint(e){this.worldTransform.applyInverse(e,Fy);const I=this._width,i=this._height,n=-I*this.anchor._x;if(Fy.x>=n&&Fy.x=C&&Fy.y=I&&(r=e-o-1),A=A.replace("%value%",g[r].toString()),n+=A,n+=` +`}return i=i.replace("%blur%",n),i=i.replace("%size%",e.toString()),i}var gM=function(e){rfe(g,e);function g(I,i,n,C,r){i===void 0&&(i=8),n===void 0&&(n=4),C===void 0&&(C=yt.FILTER_RESOLUTION),r===void 0&&(r=5);var o=this,A=Tze(r,I),s=Yze(r);return o=e.call(this,A,s)||this,o.horizontal=I,o.resolution=C,o._quality=0,o.quality=n,o.blur=i,o}return g.prototype.apply=function(I,i,n,C){if(n?this.horizontal?this.uniforms.strength=1/n.width*(n.width/i.width):this.uniforms.strength=1/n.height*(n.height/i.height):this.horizontal?this.uniforms.strength=1/I.renderer.width*(I.renderer.width/i.width):this.uniforms.strength=1/I.renderer.height*(I.renderer.height/i.height),this.uniforms.strength*=this.strength,this.uniforms.strength/=this.passes,this.passes===1)I.applyFilter(this,i,n,C);else{var r=I.getFilterTexture(),o=I.renderer,A=i,s=r;this.state.blend=!1,I.applyFilter(this,A,s,kr.CLEAR);for(var a=1;a 0.0) { + c.rgb /= c.a; + } -precision lowp float; + vec4 result; -in vec2 aVertexPosition; -in vec2 aTextureCoord; + result.r = (m[0] * c.r); + result.r += (m[1] * c.g); + result.r += (m[2] * c.b); + result.r += (m[3] * c.a); + result.r += m[4]; -uniform mat3 projectionMatrix; -uniform mat3 translationMatrix; -uniform mat3 uTransform; + result.g = (m[5] * c.r); + result.g += (m[6] * c.g); + result.g += (m[7] * c.b); + result.g += (m[8] * c.a); + result.g += m[9]; -out vec2 vTextureCoord; + result.b = (m[10] * c.r); + result.b += (m[11] * c.g); + result.b += (m[12] * c.b); + result.b += (m[13] * c.a); + result.b += m[14]; -void main(void) -{ - gl_Position = vec4((projectionMatrix * translationMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0); + result.a = (m[15] * c.r); + result.a += (m[16] * c.g); + result.a += (m[17] * c.b); + result.a += (m[18] * c.a); + result.a += m[19]; - vTextureCoord = (uTransform * vec3(aTextureCoord, 1.0)).xy; -} -`,d3e=`#version 100 -#ifdef GL_EXT_shader_texture_lod - #extension GL_EXT_shader_texture_lod : enable -#endif -#define SHADER_NAME Tiling-Sprite-100 + vec3 rgb = mix(c.rgb, result.rgb, uAlpha); -precision lowp float; + // Premultiply alpha again. + rgb *= result.a; + gl_FragColor = vec4(rgb, result.a); +} +`,iM=function(e){Dze(g,e);function g(){var I=this,i={m:new Float32Array([1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0]),uAlpha:1};return I=e.call(this,kL,xze,i)||this,I.alpha=1,I}return g.prototype._loadMatrix=function(I,i){i===void 0&&(i=!1);var n=I;i&&(this._multiply(n,this.uniforms.m,I),n=this._colorMatrix(n)),this.uniforms.m=n},g.prototype._multiply=function(I,i,n){return I[0]=i[0]*n[0]+i[1]*n[5]+i[2]*n[10]+i[3]*n[15],I[1]=i[0]*n[1]+i[1]*n[6]+i[2]*n[11]+i[3]*n[16],I[2]=i[0]*n[2]+i[1]*n[7]+i[2]*n[12]+i[3]*n[17],I[3]=i[0]*n[3]+i[1]*n[8]+i[2]*n[13]+i[3]*n[18],I[4]=i[0]*n[4]+i[1]*n[9]+i[2]*n[14]+i[3]*n[19]+i[4],I[5]=i[5]*n[0]+i[6]*n[5]+i[7]*n[10]+i[8]*n[15],I[6]=i[5]*n[1]+i[6]*n[6]+i[7]*n[11]+i[8]*n[16],I[7]=i[5]*n[2]+i[6]*n[7]+i[7]*n[12]+i[8]*n[17],I[8]=i[5]*n[3]+i[6]*n[8]+i[7]*n[13]+i[8]*n[18],I[9]=i[5]*n[4]+i[6]*n[9]+i[7]*n[14]+i[8]*n[19]+i[9],I[10]=i[10]*n[0]+i[11]*n[5]+i[12]*n[10]+i[13]*n[15],I[11]=i[10]*n[1]+i[11]*n[6]+i[12]*n[11]+i[13]*n[16],I[12]=i[10]*n[2]+i[11]*n[7]+i[12]*n[12]+i[13]*n[17],I[13]=i[10]*n[3]+i[11]*n[8]+i[12]*n[13]+i[13]*n[18],I[14]=i[10]*n[4]+i[11]*n[9]+i[12]*n[14]+i[13]*n[19]+i[14],I[15]=i[15]*n[0]+i[16]*n[5]+i[17]*n[10]+i[18]*n[15],I[16]=i[15]*n[1]+i[16]*n[6]+i[17]*n[11]+i[18]*n[16],I[17]=i[15]*n[2]+i[16]*n[7]+i[17]*n[12]+i[18]*n[17],I[18]=i[15]*n[3]+i[16]*n[8]+i[17]*n[13]+i[18]*n[18],I[19]=i[15]*n[4]+i[16]*n[9]+i[17]*n[14]+i[18]*n[19]+i[19],I},g.prototype._colorMatrix=function(I){var i=new Float32Array(I);return i[4]/=255,i[9]/=255,i[14]/=255,i[19]/=255,i},g.prototype.brightness=function(I,i){var n=[I,0,0,0,0,0,I,0,0,0,0,0,I,0,0,0,0,0,1,0];this._loadMatrix(n,i)},g.prototype.tint=function(I,i){var n=I>>16&255,C=I>>8&255,r=I&255,o=[n/255,0,0,0,0,0,C/255,0,0,0,0,0,r/255,0,0,0,0,0,1,0];this._loadMatrix(o,i)},g.prototype.greyscale=function(I,i){var n=[I,I,I,0,0,I,I,I,0,0,I,I,I,0,0,0,0,0,1,0];this._loadMatrix(n,i)},g.prototype.blackAndWhite=function(I){var i=[.3,.6,.1,0,0,.3,.6,.1,0,0,.3,.6,.1,0,0,0,0,0,1,0];this._loadMatrix(i,I)},g.prototype.hue=function(I,i){I=(I||0)/180*Math.PI;var n=Math.cos(I),C=Math.sin(I),r=Math.sqrt,o=1/3,A=r(o),s=n+(1-n)*o,a=o*(1-n)-A*C,l=o*(1-n)+A*C,c=o*(1-n)+A*C,u=n+o*(1-n),d=o*(1-n)-A*C,h=o*(1-n)-A*C,m=o*(1-n)+A*C,f=n+o*(1-n),b=[s,a,l,0,0,c,u,d,0,0,h,m,f,0,0,0,0,0,1,0];this._loadMatrix(b,i)},g.prototype.contrast=function(I,i){var n=(I||0)+1,C=-.5*(n-1),r=[n,0,0,0,C,0,n,0,0,C,0,0,n,0,C,0,0,0,1,0];this._loadMatrix(r,i)},g.prototype.saturate=function(I,i){I===void 0&&(I=0);var n=I*2/3+1,C=(n-1)*-.5,r=[n,C,C,0,0,C,n,C,0,0,C,C,n,0,0,0,0,0,1,0];this._loadMatrix(r,i)},g.prototype.desaturate=function(){this.saturate(-1)},g.prototype.negative=function(I){var i=[-1,0,0,1,0,0,-1,0,1,0,0,0,-1,1,0,0,0,0,1,0];this._loadMatrix(i,I)},g.prototype.sepia=function(I){var i=[.393,.7689999,.18899999,0,0,.349,.6859999,.16799999,0,0,.272,.5339999,.13099999,0,0,0,0,0,1,0];this._loadMatrix(i,I)},g.prototype.technicolor=function(I){var i=[1.9125277891456083,-.8545344976951645,-.09155508482755585,0,11.793603434377337,-.3087833385928097,1.7658908555458428,-.10601743074722245,0,-70.35205161461398,-.231103377548616,-.7501899197440212,1.847597816108189,0,30.950940869491138,0,0,0,1,0];this._loadMatrix(i,I)},g.prototype.polaroid=function(I){var i=[1.438,-.062,-.062,0,0,-.122,1.378,-.122,0,0,-.016,-.016,1.483,0,0,0,0,0,1,0];this._loadMatrix(i,I)},g.prototype.toBGR=function(I){var i=[0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,1,0];this._loadMatrix(i,I)},g.prototype.kodachrome=function(I){var i=[1.1285582396593525,-.3967382283601348,-.03992559172921793,0,63.72958762196502,-.16404339962244616,1.0835251566291304,-.05498805115633132,0,24.732407896706203,-.16786010706155763,-.5603416277695248,1.6014850761964943,0,35.62982807460946,0,0,0,1,0];this._loadMatrix(i,I)},g.prototype.browni=function(I){var i=[.5997023498159715,.34553243048391263,-.2708298674538042,0,47.43192855600873,-.037703249837783157,.8609577587992641,.15059552388459913,0,-36.96841498319127,.24113635128153335,-.07441037908422492,.44972182064877153,0,-7.562075277591283,0,0,0,1,0];this._loadMatrix(i,I)},g.prototype.vintage=function(I){var i=[.6279345635605994,.3202183420819367,-.03965408211312453,0,9.651285835294123,.02578397704808868,.6441188644374771,.03259127616149294,0,7.462829176470591,.0466055556782719,-.0851232987247891,.5241648018700465,0,5.159190588235296,0,0,0,1,0];this._loadMatrix(i,I)},g.prototype.colorTone=function(I,i,n,C,r){I=I||.2,i=i||.15,n=n||16770432,C=C||3375104;var o=(n>>16&255)/255,A=(n>>8&255)/255,s=(n&255)/255,a=(C>>16&255)/255,l=(C>>8&255)/255,c=(C&255)/255,u=[.3,.59,.11,0,0,o,A,s,I,0,a,l,c,i,0,o-a,A-l,s-c,0,0];this._loadMatrix(u,r)},g.prototype.night=function(I,i){I=I||.1;var n=[I*-2,-I,0,0,0,-I,0,I,0,0,0,I,I*2,0,0,0,0,0,1,0];this._loadMatrix(n,i)},g.prototype.predator=function(I,i){var n=[11.224130630493164*I,-4.794486999511719*I,-2.8746118545532227*I,0*I,.40342438220977783*I,-3.6330697536468506*I,9.193157196044922*I,-2.951810836791992*I,0*I,-1.316135048866272*I,-3.2184197902679443*I,-4.2375030517578125*I,7.476448059082031*I,0*I,.8044459223747253*I,0,0,0,1,0];this._loadMatrix(n,i)},g.prototype.lsd=function(I){var i=[2,-.4,.5,0,0,-.5,2,-.4,0,0,-.4,-.5,3,0,0,0,0,0,1,0];this._loadMatrix(i,I)},g.prototype.reset=function(){var I=[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0];this._loadMatrix(I,!1)},Object.defineProperty(g.prototype,"matrix",{get:function(){return this.uniforms.m},set:function(I){this.uniforms.m=I},enumerable:!1,configurable:!0}),Object.defineProperty(g.prototype,"alpha",{get:function(){return this.uniforms.uAlpha},set:function(I){this.uniforms.uAlpha=I},enumerable:!1,configurable:!0}),g}(zs);iM.prototype.grayscale=iM.prototype.greyscale;/*! + * @pixi/filter-displacement - v6.5.10 + * Compiled Thu, 06 Jul 2023 15:25:11 UTC + * + * @pixi/filter-displacement is licensed under the MIT License. + * http://www.opensource.org/licenses/mit-license + *//*! ***************************************************************************** +Copyright (c) Microsoft Corporation. + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +PERFORMANCE OF THIS SOFTWARE. +***************************************************************************** */var nM=function(e,g){return nM=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(I,i){I.__proto__=i}||function(I,i){for(var n in i)i.hasOwnProperty(n)&&(I[n]=i[n])},nM(e,g)};function Fze(e,g){nM(e,g);function I(){this.constructor=e}e.prototype=g===null?Object.create(g):(I.prototype=g.prototype,new I)}var Eze=`varying vec2 vFilterCoord; varying vec2 vTextureCoord; +uniform vec2 scale; +uniform mat2 rotation; uniform sampler2D uSampler; -uniform vec4 uColor; -uniform mat3 uMapCoord; -uniform vec4 uClampFrame; -uniform vec2 uClampOffset; +uniform sampler2D mapSampler; + +uniform highp vec4 inputSize; +uniform vec4 inputClamp; void main(void) { - vec2 coord = vTextureCoord + ceil(uClampOffset - vTextureCoord); - coord = (uMapCoord * vec3(coord, 1.0)).xy; - vec2 unclamped = coord; - coord = clamp(coord, uClampFrame.xy, uClampFrame.zw); + vec4 map = texture2D(mapSampler, vFilterCoord); - #ifdef GL_EXT_shader_texture_lod - vec4 texSample = unclamped == coord - ? texture2D(uSampler, coord) - : texture2DLodEXT(uSampler, coord, 0); - #else - vec4 texSample = texture2D(uSampler, coord); - #endif + map -= 0.5; + map.xy = scale * inputSize.zw * (rotation * map.xy); - gl_FragColor = texSample * uColor; + gl_FragColor = texture2D(uSampler, clamp(vec2(vTextureCoord.x + map.x, vTextureCoord.y + map.y), inputClamp.xy, inputClamp.zw)); } -`,Zee=`#version 100 -#define SHADER_NAME Tiling-Sprite-100 +`,Mze=`attribute vec2 aVertexPosition; -precision lowp float; +uniform mat3 projectionMatrix; +uniform mat3 filterMatrix; + +varying vec2 vTextureCoord; +varying vec2 vFilterCoord; + +uniform vec4 inputSize; +uniform vec4 outputFrame; + +vec4 filterVertexPosition( void ) +{ + vec2 position = aVertexPosition * max(outputFrame.zw, vec2(0.)) + outputFrame.xy; + + return vec4((projectionMatrix * vec3(position, 1.0)).xy, 0.0, 1.0); +} +vec2 filterTextureCoord( void ) +{ + return aVertexPosition * (outputFrame.zw * inputSize.zw); +} + +void main(void) +{ + gl_Position = filterVertexPosition(); + vTextureCoord = filterTextureCoord(); + vFilterCoord = ( filterMatrix * vec3( vTextureCoord, 1.0) ).xy; +} +`,zze=function(e){Fze(g,e);function g(I,i){var n=this,C=new fi;return I.renderable=!1,n=e.call(this,Mze,Eze,{mapSampler:I._texture,filterMatrix:C,scale:{x:1,y:1},rotation:new Float32Array([1,0,0,1])})||this,n.maskSprite=I,n.maskMatrix=C,i==null&&(i=20),n.scale=new rI(i,i),n}return g.prototype.apply=function(I,i,n,C){this.uniforms.filterMatrix=I.calculateSpriteMatrix(this.maskMatrix,this.maskSprite),this.uniforms.scale.x=this.scale.x,this.uniforms.scale.y=this.scale.y;var r=this.maskSprite.worldTransform,o=Math.sqrt(r.a*r.a+r.b*r.b),A=Math.sqrt(r.c*r.c+r.d*r.d);o!==0&&A!==0&&(this.uniforms.rotation[0]=r.a/o,this.uniforms.rotation[1]=r.b/o,this.uniforms.rotation[2]=r.c/A,this.uniforms.rotation[3]=r.d/A),I.applyFilter(this,i,n,C)},Object.defineProperty(g.prototype,"map",{get:function(){return this.uniforms.mapSampler},set:function(I){this.uniforms.mapSampler=I},enumerable:!1,configurable:!0}),g}(zs);/*! + * @pixi/filter-fxaa - v6.5.10 + * Compiled Thu, 06 Jul 2023 15:25:11 UTC + * + * @pixi/filter-fxaa is licensed under the MIT License. + * http://www.opensource.org/licenses/mit-license + *//*! ***************************************************************************** +Copyright (c) Microsoft Corporation. + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +PERFORMANCE OF THIS SOFTWARE. +***************************************************************************** */var CM=function(e,g){return CM=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(I,i){I.__proto__=i}||function(I,i){for(var n in i)i.hasOwnProperty(n)&&(I[n]=i[n])},CM(e,g)};function Pze(e,g){CM(e,g);function I(){this.constructor=e}e.prototype=g===null?Object.create(g):(I.prototype=g.prototype,new I)}var Jze=` attribute vec2 aVertexPosition; -attribute vec2 aTextureCoord; uniform mat3 projectionMatrix; -uniform mat3 translationMatrix; -uniform mat3 uTransform; -varying vec2 vTextureCoord; +varying vec2 v_rgbNW; +varying vec2 v_rgbNE; +varying vec2 v_rgbSW; +varying vec2 v_rgbSE; +varying vec2 v_rgbM; -void main(void) +varying vec2 vFragCoord; + +uniform vec4 inputSize; +uniform vec4 outputFrame; + +vec4 filterVertexPosition( void ) { - gl_Position = vec4((projectionMatrix * translationMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0); + vec2 position = aVertexPosition * max(outputFrame.zw, vec2(0.)) + outputFrame.xy; - vTextureCoord = (uTransform * vec3(aTextureCoord, 1.0)).xy; + return vec4((projectionMatrix * vec3(position, 1.0)).xy, 0.0, 1.0); } -`,h3e=`#version 100 -#define SHADER_NAME Tiling-Sprite-Simple-100 -precision lowp float; +void texcoords(vec2 fragCoord, vec2 inverseVP, + out vec2 v_rgbNW, out vec2 v_rgbNE, + out vec2 v_rgbSW, out vec2 v_rgbSE, + out vec2 v_rgbM) { + v_rgbNW = (fragCoord + vec2(-1.0, -1.0)) * inverseVP; + v_rgbNE = (fragCoord + vec2(1.0, -1.0)) * inverseVP; + v_rgbSW = (fragCoord + vec2(-1.0, 1.0)) * inverseVP; + v_rgbSE = (fragCoord + vec2(1.0, 1.0)) * inverseVP; + v_rgbM = vec2(fragCoord * inverseVP); +} + +void main(void) { + + gl_Position = filterVertexPosition(); + + vFragCoord = aVertexPosition * outputFrame.zw; + + texcoords(vFragCoord, inputSize.zw, v_rgbNW, v_rgbNE, v_rgbSW, v_rgbSE, v_rgbM); +} +`,Oze=`varying vec2 v_rgbNW; +varying vec2 v_rgbNE; +varying vec2 v_rgbSW; +varying vec2 v_rgbSE; +varying vec2 v_rgbM; + +varying vec2 vFragCoord; +uniform sampler2D uSampler; +uniform highp vec4 inputSize; + + +/** + Basic FXAA implementation based on the code on geeks3d.com with the + modification that the texture2DLod stuff was removed since it's + unsupported by WebGL. + + -- + + From: + https://github.com/mitsuhiko/webgl-meincraft + + Copyright (c) 2011 by Armin Ronacher. + + Some rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + + * The names of the contributors may not be used to endorse or + promote products derived from this software without specific + prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef FXAA_REDUCE_MIN +#define FXAA_REDUCE_MIN (1.0/ 128.0) +#endif +#ifndef FXAA_REDUCE_MUL +#define FXAA_REDUCE_MUL (1.0 / 8.0) +#endif +#ifndef FXAA_SPAN_MAX +#define FXAA_SPAN_MAX 8.0 +#endif + +//optimized version for mobile, where dependent +//texture reads can be a bottleneck +vec4 fxaa(sampler2D tex, vec2 fragCoord, vec2 inverseVP, + vec2 v_rgbNW, vec2 v_rgbNE, + vec2 v_rgbSW, vec2 v_rgbSE, + vec2 v_rgbM) { + vec4 color; + vec3 rgbNW = texture2D(tex, v_rgbNW).xyz; + vec3 rgbNE = texture2D(tex, v_rgbNE).xyz; + vec3 rgbSW = texture2D(tex, v_rgbSW).xyz; + vec3 rgbSE = texture2D(tex, v_rgbSE).xyz; + vec4 texColor = texture2D(tex, v_rgbM); + vec3 rgbM = texColor.xyz; + vec3 luma = vec3(0.299, 0.587, 0.114); + float lumaNW = dot(rgbNW, luma); + float lumaNE = dot(rgbNE, luma); + float lumaSW = dot(rgbSW, luma); + float lumaSE = dot(rgbSE, luma); + float lumaM = dot(rgbM, luma); + float lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE))); + float lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE))); + + mediump vec2 dir; + dir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE)); + dir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE)); + + float dirReduce = max((lumaNW + lumaNE + lumaSW + lumaSE) * + (0.25 * FXAA_REDUCE_MUL), FXAA_REDUCE_MIN); + + float rcpDirMin = 1.0 / (min(abs(dir.x), abs(dir.y)) + dirReduce); + dir = min(vec2(FXAA_SPAN_MAX, FXAA_SPAN_MAX), + max(vec2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX), + dir * rcpDirMin)) * inverseVP; + + vec3 rgbA = 0.5 * ( + texture2D(tex, fragCoord * inverseVP + dir * (1.0 / 3.0 - 0.5)).xyz + + texture2D(tex, fragCoord * inverseVP + dir * (2.0 / 3.0 - 0.5)).xyz); + vec3 rgbB = rgbA * 0.5 + 0.25 * ( + texture2D(tex, fragCoord * inverseVP + dir * -0.5).xyz + + texture2D(tex, fragCoord * inverseVP + dir * 0.5).xyz); + + float lumaB = dot(rgbB, luma); + if ((lumaB < lumaMin) || (lumaB > lumaMax)) + color = vec4(rgbA, texColor.a); + else + color = vec4(rgbB, texColor.a); + return color; +} + +void main() { + + vec4 color; + + color = fxaa(uSampler, vFragCoord, inputSize.zw, v_rgbNW, v_rgbNE, v_rgbSW, v_rgbSE, v_rgbM); + + gl_FragColor = color; +} +`,_ze=function(e){Pze(g,e);function g(){return e.call(this,Jze,Oze)||this}return g}(zs);/*! + * @pixi/filter-noise - v6.5.10 + * Compiled Thu, 06 Jul 2023 15:25:11 UTC + * + * @pixi/filter-noise is licensed under the MIT License. + * http://www.opensource.org/licenses/mit-license + *//*! ***************************************************************************** +Copyright (c) Microsoft Corporation. + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +PERFORMANCE OF THIS SOFTWARE. +***************************************************************************** */var rM=function(e,g){return rM=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(I,i){I.__proto__=i}||function(I,i){for(var n in i)i.hasOwnProperty(n)&&(I[n]=i[n])},rM(e,g)};function Lze(e,g){rM(e,g);function I(){this.constructor=e}e.prototype=g===null?Object.create(g):(I.prototype=g.prototype,new I)}var Uze=`precision highp float; varying vec2 vTextureCoord; +varying vec4 vColor; +uniform float uNoise; +uniform float uSeed; uniform sampler2D uSampler; -uniform vec4 uColor; -void main(void) +float rand(vec2 co) { - vec4 texSample = texture2D(uSampler, vTextureCoord); - gl_FragColor = texSample * uColor; + return fract(sin(dot(co.xy, vec2(12.9898, 78.233))) * 43758.5453); } -`;const LV=new sI;class GU extends KS{constructor(e){super(e),e.runners.contextChange.add(this),this.quad=new __,this.state=Il.for2d()}contextChange(){const e=this.renderer,I={globals:e.globalUniforms};this.simpleShader=oA.from(Zee,h3e,I),this.shader=e.context.webGLVersion>1?oA.from(u3e,c3e,I):oA.from(Zee,d3e,I)}render(e){const I=this.renderer,i=this.quad;let n=i.vertices;n[0]=n[6]=e._width*-e.anchor.x,n[1]=n[3]=e._height*-e.anchor.y,n[2]=n[4]=e._width*(1-e.anchor.x),n[5]=n[7]=e._height*(1-e.anchor.y);const C=e.uvRespectAnchor?e.anchor.x:0,r=e.uvRespectAnchor?e.anchor.y:0;n=i.uvs,n[0]=n[6]=-C,n[1]=n[3]=-r,n[2]=n[4]=1-C,n[5]=n[7]=1-r,i.invalidate();const o=e._texture,A=o.baseTexture,s=A.alphaMode>0,a=e.tileTransform.localTransform,l=e.uvMatrix;let c=A.isPowerOfTwo&&o.frame.width===A.width&&o.frame.height===A.height;c&&(A._glTextures[I.CONTEXT_UID]?c=A.wrapMode!==da.CLAMP:A.wrapMode===da.CLAMP&&(A.wrapMode=da.REPEAT));const u=c?this.simpleShader:this.shader,d=o.width,h=o.height,m=e._width,f=e._height;LV.set(a.a*d/m,a.b*d/f,a.c*h/m,a.d*h/f,a.tx/m,a.ty/f),LV.invert(),c?LV.prepend(l.mapCoord):(u.uniforms.uMapCoord=l.mapCoord.toArray(!0),u.uniforms.uClampFrame=l.uClampFrame,u.uniforms.uClampOffset=l.uClampOffset),u.uniforms.uTransform=LV.toArray(!0),u.uniforms.uColor=xg.shared.setValue(e.tint).premultiply(e.worldAlpha,s).toArray(u.uniforms.uColor),u.uniforms.translationMatrix=e.transform.worldTransform.toArray(!0),u.uniforms.uSampler=o,I.shader.bind(u),I.geometry.bind(i),this.state.blendMode=F_(e.blendMode,s),I.state.set(this.state),I.geometry.draw(this.renderer.gl.TRIANGLES,6,0)}}GU.extension={name:"tilingSprite",type:pt.RendererPlugin};kt.add(GU);const hpe=class zZ{constructor(e,I,i=null){this.linkedSheets=[],this._texture=e instanceof Bt?e:null,this.baseTexture=e instanceof ng?e:this._texture.baseTexture,this.textures={},this.animations={},this.data=I;const n=this.baseTexture.resource;this.resolution=this._updateResolution(i||(n?n.url:null)),this._frames=this.data.frames,this._frameKeys=Object.keys(this._frames),this._batchIndex=0,this._callback=null}_updateResolution(e=null){const{scale:I}=this.data.meta;let i=Ga(e,null);return i===null&&(i=parseFloat(I??"1")),i!==1&&this.baseTexture.setResolution(i),i}parse(){return new Promise(e=>{this._callback=e,this._batchIndex=0,this._frameKeys.length<=zZ.BATCH_SIZE?(this._processFrames(0),this._processAnimations(),this._parseComplete()):this._nextBatch()})}_processFrames(e){let I=e;const i=zZ.BATCH_SIZE;for(;I-e{this._batchIndex*zZ.BATCH_SIZE{i[n]=e}),Object.keys(e.textures).forEach(n=>{i[n]=e.textures[n]}),!I){const n=fi.dirname(g[0]);e.linkedSheets.forEach((C,r)=>{const o=mpe([`${n}/${e.data.meta.related_multi_packs[r]}`],C,!0);Object.assign(i,o)})}return i}const fpe={extension:pt.Asset,cache:{test:g=>g instanceof zM,getCacheableAssets:(g,e)=>mpe(g,e,!1)},resolver:{test:g=>{const e=g.split("?")[0].split("."),I=e.pop(),i=e.pop();return I==="json"&&m3e.includes(i)},parse:g=>{var I;const e=g.split(".");return{resolution:parseFloat(((I=Gt.RETINA_PREFIX.exec(g))==null?void 0:I[1])??"1"),format:e[e.length-2],src:g}}},loader:{name:"spritesheetLoader",extension:{type:pt.LoadParser,priority:so.Normal},async testParse(g,e){return fi.extname(e.src).toLowerCase()===".json"&&!!g.frames},async parse(g,e,I){var A,s;let i=fi.dirname(e.src);i&&i.lastIndexOf("/")!==i.length-1&&(i+="/");let n=i+g.meta.image;n=PX(n,e.src);const C=(await I.load([n]))[n],r=new zM(C.baseTexture,g,e.src);await r.parse();const o=(A=g==null?void 0:g.meta)==null?void 0:A.related_multi_packs;if(Array.isArray(o)){const a=[];for(const c of o){if(typeof c!="string")continue;let u=i+c;(s=e.data)!=null&&s.ignoreMultiPack||(u=PX(u,e.src),a.push(I.load({src:u,data:{ignoreMultiPack:!0}})))}const l=await Promise.all(a);r.linkedSheets=l,l.forEach(c=>{c.linkedSheets=[r].concat(r.linkedSheets.filter(u=>u!==c))})}return r},unload(g){g.destroy(!0)}}};kt.add(fpe);class vv{constructor(){this.info=[],this.common=[],this.page=[],this.char=[],this.kerning=[],this.distanceField=[]}}class QG{static test(e){return typeof e=="string"&&e.startsWith("info face=")}static parse(e){const I=e.match(/^[a-z]+\s+.+$/gm),i={info:[],common:[],page:[],char:[],chars:[],kerning:[],kernings:[],distanceField:[]};for(const C in I){const r=I[C].match(/^[a-z]+/gm)[0],o=I[C].match(/[a-zA-Z]+=([^\s"']+|"([^"]*)")/gm),A={};for(const s in o){const a=o[s].split("="),l=a[0],c=a[1].replace(/"/gm,""),u=parseFloat(c),d=isNaN(u)?c:u;A[l]=d}i[r].push(A)}const n=new vv;return i.info.forEach(C=>n.info.push({face:C.face,size:parseInt(C.size,10)})),i.common.forEach(C=>n.common.push({lineHeight:parseInt(C.lineHeight,10)})),i.page.forEach(C=>n.page.push({id:parseInt(C.id,10),file:C.file})),i.char.forEach(C=>n.char.push({id:parseInt(C.id,10),page:parseInt(C.page,10),x:parseInt(C.x,10),y:parseInt(C.y,10),width:parseInt(C.width,10),height:parseInt(C.height,10),xoffset:parseInt(C.xoffset,10),yoffset:parseInt(C.yoffset,10),xadvance:parseInt(C.xadvance,10)})),i.kerning.forEach(C=>n.kerning.push({first:parseInt(C.first,10),second:parseInt(C.second,10),amount:parseInt(C.amount,10)})),i.distanceField.forEach(C=>n.distanceField.push({distanceRange:parseInt(C.distanceRange,10),fieldType:C.fieldType})),n}}class LX{static test(e){const I=e;return typeof e!="string"&&"getElementsByTagName"in e&&I.getElementsByTagName("page").length&&I.getElementsByTagName("info")[0].getAttribute("face")!==null}static parse(e){const I=new vv,i=e.getElementsByTagName("info"),n=e.getElementsByTagName("common"),C=e.getElementsByTagName("page"),r=e.getElementsByTagName("char"),o=e.getElementsByTagName("kerning"),A=e.getElementsByTagName("distanceField");for(let s=0;s")?LX.test(Gt.ADAPTER.parseXML(e)):!1}static parse(e){return LX.parse(Gt.ADAPTER.parseXML(e))}}const o5=[QG,LX,_X];function ppe(g){for(let e=0;e=A-R*r){if(h===0)throw new Error(`[BitmapFont] textureHeight ${A}px is too small (fontFamily: '${l.fontFamily}', fontSize: ${l.fontSize}px, char: '${G}')`);--v,m=null,f=null,b=null,h=0,d=0,p=0;continue}if(p=Math.max(R+B.fontProperties.descent,p),S*r+d>=c){if(d===0)throw new Error(`[BitmapFont] textureWidth ${o}px is too small (fontFamily: '${l.fontFamily}', fontSize: ${l.fontSize}px, char: '${G}')`);--v,h+=p*r,h=Math.ceil(h),d=0,p=0;continue}p3e(m,f,B,d,h,r,l);const X=M1(B.text);u.char.push({id:X,page:y.length-1,x:d/r,y:h/r,width:S,height:R,xoffset:0,yoffset:0,xadvance:w-(l.dropShadow?l.dropShadowDistance:0)-(l.stroke?l.strokeThickness:0)}),d+=(S+2*C)*r,d=Math.ceil(d)}if(!(i!=null&&i.skipKerning))for(let v=0,G=a.length;v 0.99) {\r - alpha = 1.0;\r - }\r -\r - // Gamma correction for coverage-like alpha\r - float luma = dot(uColor.rgb, vec3(0.299, 0.587, 0.114));\r - float gamma = mix(1.0, 1.0 / 2.2, luma);\r - float coverage = pow(uColor.a * alpha, gamma); \r -\r - // NPM Textures, NPM outputs\r - gl_FragColor = vec4(uColor.rgb, coverage);\r -}\r -`,Z3e=`// Mesh material default fragment\r -attribute vec2 aVertexPosition;\r -attribute vec2 aTextureCoord;\r -\r -uniform mat3 projectionMatrix;\r -uniform mat3 translationMatrix;\r -uniform mat3 uTextureMatrix;\r -\r -varying vec2 vTextureCoord;\r -\r -void main(void)\r -{\r - gl_Position = vec4((projectionMatrix * translationMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);\r -\r - vTextureCoord = (uTextureMatrix * vec3(aTextureCoord, 1.0)).xy;\r -}\r -`;const Gee=[],Bee=[],vee=[],ype=class Zpe extends yr{constructor(e,I={}){super();const{align:i,tint:n,maxWidth:C,letterSpacing:r,fontName:o,fontSize:A}=Object.assign({},Zpe.styleDefaults,I);if(!Is.available[o])throw new Error(`Missing BitmapFont "${o}"`);this._activePagesMeshData=[],this._textWidth=0,this._textHeight=0,this._align=i,this._tintColor=new xg(n),this._font=void 0,this._fontName=o,this._fontSize=A,this.text=e,this._maxWidth=C,this._maxLineHeight=0,this._letterSpacing=r,this._anchor=new ra(()=>{this.dirty=!0},this,0,0),this._roundPixels=Gt.ROUND_PIXELS,this.dirty=!0,this._resolution=Gt.RESOLUTION,this._autoResolution=!0,this._textureCache={}}updateText(){var S;const e=Is.available[this._fontName],I=this.fontSize,i=I/e.size,n=new Gg,C=[],r=[],o=[],A=this._text.replace(/(?:\r\n|\r)/g,` -`)||" ",s=bpe(A),a=this._maxWidth*e.size/I,l=e.distanceFieldType==="none"?Gee:Bee;let c=null,u=0,d=0,h=0,m=-1,f=0,b=0,p=0,y=0;for(let X=0;X0&&n.x>a&&(++b,Nd(C,1+m-b,1+X-m),X=m,m=-1,r.push(f),o.push(C.length>0?C[C.length-1].prevSpaces:0),d=Math.max(d,f),h++,n.x=0,n.y+=e.lineHeight,c=null,y=0)}const Z=s[s.length-1];Z!=="\r"&&Z!==` -`&&(/(?:\s)/.test(Z)&&(u=f),r.push(u),d=Math.max(d,u),o.push(-1));const v=[];for(let X=0;X<=h;X++){let W=0;this._align==="right"?W=d-r[X]:this._align==="center"?W=(d-r[X])/2:this._align==="justify"&&(W=o[X]<0?0:(d-r[X])/o[X]),v.push(W)}const G=C.length,B={},w=[],R=this._activePagesMeshData;l.push(...R);for(let X=0;X6*V)||W.vertices.lengthI[n.mesh.texture.baseTexture.uid]).forEach(n=>{n.mesh.texture=Bt.EMPTY});for(const n in I)I[n].destroy(),delete I[n];this._font=null,this._tintColor=null,this._textureCache=null,super.destroy(e)}};ype.styleDefaults={align:"left",tint:16777215,maxWidth:0,letterSpacing:0};let G3e=ype;const B3e=[".xml",".fnt"],Gpe={extension:{type:pt.LoadParser,priority:so.Normal},name:"loadBitmapFont",test(g){return B3e.includes(fi.extname(g).toLowerCase())},async testParse(g){return QG.test(g)||_X.test(g)},async parse(g,e,I){const i=QG.test(g)?QG.parse(g):_X.parse(g),{src:n}=e,{page:C}=i,r=[];for(let s=0;so[s]);return Is.install(i,A,!0)},async load(g,e){return(await Gt.ADAPTER.fetch(g)).text()},unload(g){g.destroy()}};kt.add(Gpe);const PM=class Rf extends Ps{constructor(){super(...arguments),this._fonts=[],this._overrides=[],this._stylesheet="",this.fontsDirty=!1}static from(e){return new Rf(Object.keys(Rf.defaultOptions).reduce((I,i)=>({...I,[i]:e[i]}),{}))}cleanFonts(){this._fonts.length>0&&(this._fonts.forEach(e=>{URL.revokeObjectURL(e.src),e.refs--,e.refs===0&&(e.fontFace&&document.fonts.delete(e.fontFace),delete Rf.availableFonts[e.originalUrl])}),this.fontFamily="Arial",this._fonts.length=0,this.styleID++,this.fontsDirty=!0)}loadFont(e,I={}){const{availableFonts:i}=Rf;if(i[e]){const n=i[e];return this._fonts.push(n),n.refs++,this.styleID++,this.fontsDirty=!0,Promise.resolve()}return Gt.ADAPTER.fetch(e).then(n=>n.blob()).then(async n=>new Promise((C,r)=>{const o=URL.createObjectURL(n),A=new FileReader;A.onload=()=>C([o,A.result]),A.onerror=r,A.readAsDataURL(n)})).then(async([n,C])=>{const r=Object.assign({family:fi.basename(e,fi.extname(e)),weight:"normal",style:"normal",display:"auto",src:n,dataSrc:C,refs:1,originalUrl:e,fontFace:null},I);i[e]=r,this._fonts.push(r),this.styleID++;const o=new FontFace(r.family,`url(${r.src})`,{weight:r.weight,style:r.style,display:r.display});r.fontFace=o,await o.load(),document.fonts.add(o),await document.fonts.ready,this.styleID++,this.fontsDirty=!0})}addOverride(...e){const I=e.filter(i=>!this._overrides.includes(i));I.length>0&&(this._overrides.push(...I),this.styleID++)}removeOverride(...e){const I=e.filter(i=>this._overrides.includes(i));I.length>0&&(this._overrides=this._overrides.filter(i=>!I.includes(i)),this.styleID++)}toCSS(e){return[`transform: scale(${e})`,"transform-origin: top left","display: inline-block",`color: ${this.normalizeColor(this.fill)}`,`font-size: ${this.fontSize}px`,`font-family: ${this.fontFamily}`,`font-weight: ${this.fontWeight}`,`font-style: ${this.fontStyle}`,`font-variant: ${this.fontVariant}`,`letter-spacing: ${this.letterSpacing}px`,`text-align: ${this.align}`,`padding: ${this.padding}px`,`white-space: ${this.whiteSpace}`,...this.lineHeight?[`line-height: ${this.lineHeight}px`]:[],...this.wordWrap?[`word-wrap: ${this.breakWords?"break-all":"break-word"}`,`max-width: ${this.wordWrapWidth}px`]:[],...this.strokeThickness?[`-webkit-text-stroke-width: ${this.strokeThickness}px`,`-webkit-text-stroke-color: ${this.normalizeColor(this.stroke)}`,`text-stroke-width: ${this.strokeThickness}px`,`text-stroke-color: ${this.normalizeColor(this.stroke)}`,"paint-order: stroke"]:[],...this.dropShadow?[this.dropShadowToCSS()]:[],...this._overrides].join(";")}toGlobalCSS(){return this._fonts.reduce((e,I)=>`${e} - @font-face { - font-family: "${I.family}"; - src: url('${I.dataSrc}'); - font-weight: ${I.weight}; - font-style: ${I.style}; - font-display: ${I.display}; - }`,this._stylesheet)}get stylesheet(){return this._stylesheet}set stylesheet(e){this._stylesheet!==e&&(this._stylesheet=e,this.styleID++)}normalizeColor(e){return Array.isArray(e)&&(e=x_(e)),typeof e=="number"?hme(e):e}dropShadowToCSS(){let e=this.normalizeColor(this.dropShadowColor);const I=this.dropShadowAlpha,i=Math.round(Math.cos(this.dropShadowAngle)*this.dropShadowDistance),n=Math.round(Math.sin(this.dropShadowAngle)*this.dropShadowDistance);e.startsWith("#")&&I<1&&(e+=(I*255|0).toString(16).padStart(2,"0"));const C=`${i}px ${n}px`;return this.dropShadowBlur>0?`text-shadow: ${C} ${this.dropShadowBlur}px ${e}`:`text-shadow: ${C} ${e}`}reset(){Object.assign(this,Rf.defaultOptions)}onBeforeDraw(){const{fontsDirty:e}=this;return this.fontsDirty=!1,this.isSafari&&this._fonts.length>0&&e?new Promise(I=>setTimeout(I,100)):Promise.resolve()}get isSafari(){const{userAgent:e}=Gt.ADAPTER.getNavigator();return/^((?!chrome|android).)*safari/i.test(e)}set fillGradientStops(e){console.warn("[HTMLTextStyle] fillGradientStops is not supported by HTMLText")}get fillGradientStops(){return super.fillGradientStops}set fillGradientType(e){console.warn("[HTMLTextStyle] fillGradientType is not supported by HTMLText")}get fillGradientType(){return super.fillGradientType}set miterLimit(e){console.warn("[HTMLTextStyle] miterLimit is not supported by HTMLText")}get miterLimit(){return super.miterLimit}set trim(e){console.warn("[HTMLTextStyle] trim is not supported by HTMLText")}get trim(){return super.trim}set textBaseline(e){console.warn("[HTMLTextStyle] textBaseline is not supported by HTMLText")}get textBaseline(){return super.textBaseline}set leading(e){console.warn("[HTMLTextStyle] leading is not supported by HTMLText")}get leading(){return super.leading}set lineJoin(e){console.warn("[HTMLTextStyle] lineJoin is not supported by HTMLText")}get lineJoin(){return super.lineJoin}};PM.availableFonts={},PM.defaultOptions={align:"left",breakWords:!1,dropShadow:!1,dropShadowAlpha:1,dropShadowAngle:Math.PI/6,dropShadowBlur:0,dropShadowColor:"black",dropShadowDistance:5,fill:"black",fontFamily:"Arial",fontSize:26,fontStyle:"normal",fontVariant:"normal",fontWeight:"normal",letterSpacing:0,lineHeight:0,padding:0,stroke:"black",strokeThickness:0,whiteSpace:"normal",wordWrap:!1,wordWrapWidth:100};let z1=PM;const PZ=class Wf extends nl{constructor(e="",I={}){super(Bt.EMPTY),this._text=null,this._style=null,this._autoResolution=!0,this.localStyleID=-1,this.dirty=!1,this._updateID=0,this.ownsStyle=!1;const i=new Image,n=Bt.from(i,{scaleMode:Gt.SCALE_MODE,resourceOptions:{autoLoad:!1}});n.orig=new rg,n.trim=new rg,this.texture=n;const C="http://www.w3.org/2000/svg",r="http://www.w3.org/1999/xhtml",o=document.createElementNS(C,"svg"),A=document.createElementNS(C,"foreignObject"),s=document.createElementNS(r,"div"),a=document.createElementNS(r,"style");A.setAttribute("width","10000"),A.setAttribute("height","10000"),A.style.overflow="hidden",o.appendChild(A),this.maxWidth=Wf.defaultMaxWidth,this.maxHeight=Wf.defaultMaxHeight,this._domElement=s,this._styleElement=a,this._svgRoot=o,this._foreignObject=A,this._foreignObject.appendChild(a),this._foreignObject.appendChild(s),this._image=i,this._loadImage=new Image,this._autoResolution=Wf.defaultAutoResolution,this._resolution=Wf.defaultResolution??Gt.RESOLUTION,this.text=e,this.style=I}measureText(e){var a,l;const{text:I,style:i,resolution:n}=Object.assign({text:this._text,style:this._style,resolution:this._resolution},e);Object.assign(this._domElement,{innerHTML:I,style:i.toCSS(n)}),this._styleElement.textContent=i.toGlobalCSS(),document.body.appendChild(this._svgRoot);const C=this._domElement.getBoundingClientRect();this._svgRoot.remove();const{width:r,height:o}=C;(r>this.maxWidth||o>this.maxHeight)&&console.warn("[HTMLText] Large expanse of text, increase HTMLText.maxWidth or HTMLText.maxHeight property.");const A=Math.min(this.maxWidth,Math.ceil(r)),s=Math.min(this.maxHeight,Math.ceil(o));return this._svgRoot.setAttribute("width",A.toString()),this._svgRoot.setAttribute("height",s.toString()),I!==this._text&&(this._domElement.innerHTML=this._text),i!==this._style&&(Object.assign(this._domElement,{style:(a=this._style)==null?void 0:a.toCSS(n)}),this._styleElement.textContent=(l=this._style)==null?void 0:l.toGlobalCSS()),{width:A+i.padding*2,height:s+i.padding*2}}async updateText(e=!0){const{style:I,_image:i,_loadImage:n}=this;if(this.localStyleID!==I.styleID&&(this.dirty=!0,this.localStyleID=I.styleID),!this.dirty&&e)return;const{width:C,height:r}=this.measureText();i.width=n.width=Math.ceil(Math.max(1,C)),i.height=n.height=Math.ceil(Math.max(1,r)),this._updateID++;const o=this._updateID;await new Promise(A=>{n.onload=async()=>{if(o/gi,"

").replace(/
/gi,"
").replace(/ /gi," ")}};PZ.defaultDestroyOptions={texture:!0,children:!1,baseTexture:!0},PZ.defaultMaxWidth=2024,PZ.defaultMaxHeight=2024,PZ.defaultAutoResolution=!0;let v3e=PZ;const Bpe=Object.freeze(Object.defineProperty({__proto__:null,ALPHA_MODES:tC,AbstractMultiResource:lU,AccessibilityManager:uU,AlphaFilter:lfe,AnimatedSprite:OX,Application:yfe,ArrayResource:ife,Assets:DZ,AssetsClass:Xfe,Attribute:cv,BLEND_MODES:$t,BUFFER_BITS:RX,BUFFER_TYPE:CA,BackgroundSystem:dv,BaseImageResource:Ms,BasePrepare:JX,BaseRenderTexture:J_,BaseTexture:ng,BatchDrawCall:KX,BatchGeometry:M_,BatchRenderer:ql,BatchShaderGenerator:Yme,BatchSystem:P_,BatchTextureArray:xX,BitmapFont:Is,BitmapFontData:vv,BitmapText:G3e,BlobResource:Mfe,BlurFilter:cfe,BlurFilterPass:EX,Bounds:pv,BrowserAdapter:Fhe,Buffer:ui,BufferResource:TS,BufferSystem:aU,CLEAR_MODES:Oo,COLOR_MASK_BITS:Dhe,Cache:ac,CanvasResource:nfe,Circle:z_,Color:xg,ColorMatrixFilter:MX,CompressedTextureResource:Pc,Container:yr,ContextSystem:hv,CountLimiter:lpe,CubeResource:rfe,DEG_TO_RAD:wme,DRAW_MODES:qo,DisplacementFilter:ufe,DisplayObject:HI,ENV:su,Ellipse:NS,EventBoundary:mfe,EventSystem:zX,ExtensionType:pt,Extract:jfe,FORMATS:st,FORMATS_TO_COMPONENTS:Pfe,FXAAFilter:dfe,FederatedDisplayObject:ffe,FederatedEvent:k0,FederatedMouseEvent:bv,FederatedPointerEvent:Xr,FederatedWheelEvent:Yd,FillStyle:DS,Filter:Hn,FilterState:xme,FilterSystem:U_,Framebuffer:DX,FramebufferSystem:Q_,GC_MODES:HT,GLFramebuffer:Dme,GLProgram:Jme,GLTexture:K1,GRAPHICS_CURVES:MMe,GenerateTextureSystem:gU,Geometry:Es,GeometrySystem:j_,Graphics:fU,GraphicsData:Bv,GraphicsGeometry:Ipe,HTMLText:v3e,HTMLTextStyle:z1,IGLUniformData:iEe,INSTALLED:YX,INTERNAL_FORMATS:vC,INTERNAL_FORMAT_TO_BYTES_PER_PIXEL:Zv,ImageBitmapResource:hd,ImageResource:O_,LINE_CAP:ps,LINE_JOIN:$C,LineStyle:MT,LoaderParserPriority:so,MASK_TYPES:ai,MIPMAP_MODES:uA,MSAA_QUALITY:Ci,MaskData:Eme,MaskSystem:$_,Matrix:sI,Mesh:vb,MeshBatchUvs:ipe,MeshGeometry:FS,MeshMaterial:Sb,MultisampleSystem:AU,NineSlicePlane:_Me,NoiseFilter:hfe,ObjectRenderer:KS,ObjectRendererSystem:sU,ObservablePoint:ra,PI_2:uv,PRECISION:sr,ParticleContainer:jMe,ParticleRenderer:pU,PlaneGeometry:rpe,PluginSystem:eU,Point:Gg,Polygon:zc,Prepare:yU,Program:oa,ProjectionSystem:tU,Quad:Kme,QuadUv:__,RAD_TO_DEG:Sme,RENDERER_TYPE:V_,Rectangle:rg,RenderTexture:il,RenderTexturePool:L_,RenderTextureSystem:IU,Renderer:DT,ResizePlugin:dU,Resource:Bb,RopeGeometry:ope,RoundedRectangle:kS,Runner:dr,SAMPLER_TYPES:Zt,SCALE_MODES:Ca,SHAPES:Pi,SVGResource:FX,ScissorSystem:Pme,Shader:oA,ShaderSystem:iU,SimpleMesh:UMe,SimplePlane:Ape,SimpleRope:QMe,Sprite:nl,SpriteMaskFilter:Fme,Spritesheet:zM,StartupSystem:mv,State:Il,StateSystem:$me,StencilSystem:q_,SystemManager:qme,TARGETS:Xd,TEXT_GRADIENT:ES,TYPES:Mt,TYPES_TO_BYTES_PER_COMPONENT:KM,TYPES_TO_BYTES_PER_PIXEL:Jfe,TemporaryDisplayObject:Afe,Text:bU,TextFormat:QG,TextMetrics:rs,TextStyle:Ps,Texture:Bt,TextureGCSystem:ec,TextureMatrix:xT,TextureSystem:nU,TextureUvs:KT,Ticker:Ji,TickerPlugin:rU,TilingSprite:ZU,TilingSpriteRenderer:GU,TimeLimiter:l3e,Transform:YS,TransformFeedback:ZEe,TransformFeedbackSystem:CU,UPDATE_PRIORITY:zs,UniformGroup:go,VERSION:ofe,VideoResource:cU,ViewSystem:fv,ViewableBuffer:kX,WRAP_MODES:da,XMLFormat:LX,XMLStringFormat:_X,accessibleTarget:pfe,autoDetectFormat:ppe,autoDetectRenderer:gfe,autoDetectResource:E_,cacheTextureArray:Hfe,checkDataUrl:tm,checkExtension:Cl,checkMaxIfStatementsInShader:Gme,convertToList:Lr,copySearchParams:PX,createStringVariations:Gfe,createTexture:Y0,createUBOElements:_me,curves:Iu,defaultFilterVertex:oU,defaultVertex:Ife,detectAvif:Nfe,detectCompressedTextures:Efe,detectDefaults:Yfe,detectMp4:xfe,detectOgv:Dfe,detectWebm:Kfe,detectWebp:kfe,extensions:kt,filters:HM,generateProgram:Ome,generateUniformBufferSync:Qme,getFontFamilyName:Sfe,getTestContext:Hme,getUBOData:Ume,graphicsUtils:JMe,groupD8:VI,isMobile:eA,isSingleItem:yv,loadBitmapFont:Gpe,loadDDS:Lfe,loadImageBitmap:Vfe,loadJson:Bfe,loadKTX:_fe,loadSVG:Rfe,loadTextures:xS,loadTxt:vfe,loadVideo:Wfe,loadWebFont:wfe,parseDDS:zfe,parseKTX:Ofe,resolveCompressedTextureUrl:Ufe,resolveTextureUrl:Ffe,settings:Gt,spritesheetAsset:fpe,uniformParsers:kd,unsafeEvalSupported:kme,utils:VFe},Symbol.toStringTag,{value:"Module"}));function zT(g,e,I){g.prototype=e.prototype=I,I.constructor=g}function BU(g,e){var I=Object.create(g.prototype);for(var i in e)I[i]=e[i];return I}function K0(){}var Ih=.7,wb=1/Ih,Kp="\\s*([+-]?\\d+)\\s*",Sv="\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)\\s*",ha="\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)%\\s*",S3e=/^#([0-9a-f]{3,8})$/,w3e=new RegExp("^rgb\\("+[Kp,Kp,Kp]+"\\)$"),V3e=new RegExp("^rgb\\("+[ha,ha,ha]+"\\)$"),R3e=new RegExp("^rgba\\("+[Kp,Kp,Kp,Sv]+"\\)$"),W3e=new RegExp("^rgba\\("+[ha,ha,ha,Sv]+"\\)$"),X3e=new RegExp("^hsl\\("+[Sv,ha,ha]+"\\)$"),H3e=new RegExp("^hsla\\("+[Sv,ha,ha,Sv]+"\\)$"),See={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074};zT(K0,ih,{copy:function(g){return Object.assign(new this.constructor,this,g)},displayable:function(){return this.rgb().displayable()},hex:wee,formatHex:wee,formatHsl:T3e,formatRgb:Vee,toString:Vee});function wee(){return this.rgb().formatHex()}function T3e(){return Spe(this).formatHsl()}function Vee(){return this.rgb().formatRgb()}function ih(g){var e,I;return g=(g+"").trim().toLowerCase(),(e=S3e.exec(g))?(I=e[1].length,e=parseInt(e[1],16),I===6?Ree(e):I===3?new gC(e>>8&15|e>>4&240,e>>4&15|e&240,(e&15)<<4|e&15,1):I===8?_V(e>>24&255,e>>16&255,e>>8&255,(e&255)/255):I===4?_V(e>>12&15|e>>8&240,e>>8&15|e>>4&240,e>>4&15|e&240,((e&15)<<4|e&15)/255):null):(e=w3e.exec(g))?new gC(e[1],e[2],e[3],1):(e=V3e.exec(g))?new gC(e[1]*255/100,e[2]*255/100,e[3]*255/100,1):(e=R3e.exec(g))?_V(e[1],e[2],e[3],e[4]):(e=W3e.exec(g))?_V(e[1]*255/100,e[2]*255/100,e[3]*255/100,e[4]):(e=X3e.exec(g))?Hee(e[1],e[2]/100,e[3]/100,1):(e=H3e.exec(g))?Hee(e[1],e[2]/100,e[3]/100,e[4]):See.hasOwnProperty(g)?Ree(See[g]):g==="transparent"?new gC(NaN,NaN,NaN,0):null}function Ree(g){return new gC(g>>16&255,g>>8&255,g&255,1)}function _V(g,e,I,i){return i<=0&&(g=e=I=NaN),new gC(g,e,I,i)}function vpe(g){return g instanceof K0||(g=ih(g)),g?(g=g.rgb(),new gC(g.r,g.g,g.b,g.opacity)):new gC}function UX(g,e,I,i){return arguments.length===1?vpe(g):new gC(g,e,I,i??1)}function gC(g,e,I,i){this.r=+g,this.g=+e,this.b=+I,this.opacity=+i}zT(gC,UX,BU(K0,{brighter:function(g){return g=g==null?wb:Math.pow(wb,g),new gC(this.r*g,this.g*g,this.b*g,this.opacity)},darker:function(g){return g=g==null?Ih:Math.pow(Ih,g),new gC(this.r*g,this.g*g,this.b*g,this.opacity)},rgb:function(){return this},displayable:function(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:Wee,formatHex:Wee,formatRgb:Xee,toString:Xee}));function Wee(){return"#"+A5(this.r)+A5(this.g)+A5(this.b)}function Xee(){var g=this.opacity;return g=isNaN(g)?1:Math.max(0,Math.min(1,g)),(g===1?"rgb(":"rgba(")+Math.max(0,Math.min(255,Math.round(this.r)||0))+", "+Math.max(0,Math.min(255,Math.round(this.g)||0))+", "+Math.max(0,Math.min(255,Math.round(this.b)||0))+(g===1?")":", "+g+")")}function A5(g){return g=Math.max(0,Math.min(255,Math.round(g)||0)),(g<16?"0":"")+g.toString(16)}function Hee(g,e,I,i){return i<=0?g=e=I=NaN:I<=0||I>=1?g=e=NaN:e<=0&&(g=NaN),new OA(g,e,I,i)}function Spe(g){if(g instanceof OA)return new OA(g.h,g.s,g.l,g.opacity);if(g instanceof K0||(g=ih(g)),!g)return new OA;if(g instanceof OA)return g;g=g.rgb();var e=g.r/255,I=g.g/255,i=g.b/255,n=Math.min(e,I,i),C=Math.max(e,I,i),r=NaN,o=C-n,A=(C+n)/2;return o?(e===C?r=(I-i)/o+(I0&&A<1?0:r,new OA(r,o,A,g.opacity)}function N3e(g,e,I,i){return arguments.length===1?Spe(g):new OA(g,e,I,i??1)}function OA(g,e,I,i){this.h=+g,this.s=+e,this.l=+I,this.opacity=+i}zT(OA,N3e,BU(K0,{brighter:function(g){return g=g==null?wb:Math.pow(wb,g),new OA(this.h,this.s,this.l*g,this.opacity)},darker:function(g){return g=g==null?Ih:Math.pow(Ih,g),new OA(this.h,this.s,this.l*g,this.opacity)},rgb:function(){var g=this.h%360+(this.h<0)*360,e=isNaN(g)||isNaN(this.s)?0:this.s,I=this.l,i=I+(I<.5?I:1-I)*e,n=2*I-i;return new gC(a5(g>=240?g-240:g+120,n,i),a5(g,n,i),a5(g<120?g+240:g-120,n,i),this.opacity)},displayable:function(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl:function(){var g=this.opacity;return g=isNaN(g)?1:Math.max(0,Math.min(1,g)),(g===1?"hsl(":"hsla(")+(this.h||0)+", "+(this.s||0)*100+"%, "+(this.l||0)*100+"%"+(g===1?")":", "+g+")")}}));function a5(g,e,I){return(g<60?e+(I-e)*g/60:g<180?I:g<240?e+(I-e)*(240-g)/60:e)*255}const k3e=Math.PI/180,Y3e=180/Math.PI;var wpe=-.14861,vU=1.78277,SU=-.29227,PT=-.90649,wv=1.97294,Tee=wv*PT,Nee=wv*vU,kee=vU*SU-PT*wpe;function K3e(g){if(g instanceof Kd)return new Kd(g.h,g.s,g.l,g.opacity);g instanceof gC||(g=vpe(g));var e=g.r/255,I=g.g/255,i=g.b/255,n=(kee*i+Tee*e-Nee*I)/(kee+Tee-Nee),C=i-n,r=(wv*(I-n)-SU*C)/PT,o=Math.sqrt(r*r+C*C)/(wv*n*(1-n)),A=o?Math.atan2(r,C)*Y3e-120:NaN;return new Kd(A<0?A+360:A,o,n,g.opacity)}function iu(g,e,I,i){return arguments.length===1?K3e(g):new Kd(g,e,I,i??1)}function Kd(g,e,I,i){this.h=+g,this.s=+e,this.l=+I,this.opacity=+i}zT(Kd,iu,BU(K0,{brighter:function(g){return g=g==null?wb:Math.pow(wb,g),new Kd(this.h,this.s,this.l*g,this.opacity)},darker:function(g){return g=g==null?Ih:Math.pow(Ih,g),new Kd(this.h,this.s,this.l*g,this.opacity)},rgb:function(){var g=isNaN(this.h)?0:(this.h+120)*k3e,e=+this.l,I=isNaN(this.s)?0:this.s*e*(1-e),i=Math.cos(g),n=Math.sin(g);return new gC(255*(e+I*(wpe*i+vU*n)),255*(e+I*(SU*i+PT*n)),255*(e+I*(wv*i)),this.opacity)}}));function Vpe(g,e){return ge?1:g>=e?0:NaN}function wU(g){let e=g,I=g;g.length===1&&(e=(r,o)=>g(r)-o,I=x3e(g));function i(r,o,A,s){for(A==null&&(A=0),s==null&&(s=r.length);A>>1;I(r[a],o)<0?A=a+1:s=a}return A}function n(r,o,A,s){for(A==null&&(A=0),s==null&&(s=r.length);A>>1;I(r[a],o)>0?s=a:A=a+1}return A}function C(r,o,A,s){A==null&&(A=0),s==null&&(s=r.length);const a=i(r,o,A,s-1);return a>A&&e(r[a-1],o)>-e(r[a],o)?a-1:a}return{left:i,center:C,right:n}}function x3e(g){return(e,I)=>Vpe(g(e),I)}function D3e(g){return g===null?NaN:+g}const F3e=wU(Vpe),E3e=F3e.right;wU(D3e).center;const M3e=E3e;let z3e=class extends Map{constructor(e,I=O3e){if(super(),Object.defineProperties(this,{_intern:{value:new Map},_key:{value:I}}),e!=null)for(const[i,n]of e)this.set(i,n)}get(e){return super.get(Yee(this,e))}has(e){return super.has(Yee(this,e))}set(e,I){return super.set(P3e(this,e),I)}delete(e){return super.delete(J3e(this,e))}};function Yee({_intern:g,_key:e},I){const i=e(I);return g.has(i)?g.get(i):I}function P3e({_intern:g,_key:e},I){const i=e(I);return g.has(i)?g.get(i):(g.set(i,I),I)}function J3e({_intern:g,_key:e},I){const i=e(I);return g.has(i)&&(I=g.get(I),g.delete(i)),I}function O3e(g){return g!==null&&typeof g=="object"?g.valueOf():g}function Kee(g){return g}function JT(g,...e){return L3e(g,Kee,Kee,e)}function L3e(g,e,I,i){return function n(C,r){if(r>=i.length)return I(C);const o=new z3e,A=i[r++];let s=-1;for(const a of C){const l=A(a,++s,C),c=o.get(l);c?c.push(a):o.set(l,[a])}for(const[a,l]of o)o.set(a,n(l,r));return e(o)}(g,0)}var JM=Math.sqrt(50),OM=Math.sqrt(10),LM=Math.sqrt(2);function _3e(g,e,I){var i,n=-1,C,r,o;if(e=+e,g=+g,I=+I,g===e&&I>0)return[g];if((i=e0){let A=Math.round(g/o),s=Math.round(e/o);for(A*oe&&--s,r=new Array(C=s-A+1);++ne&&--s,r=new Array(C=s-A+1);++n=0?(C>=JM?10:C>=OM?5:C>=LM?2:1)*Math.pow(10,n):-Math.pow(10,-n)/(C>=JM?10:C>=OM?5:C>=LM?2:1)}function U3e(g,e,I){var i=Math.abs(e-g)/Math.max(0,I),n=Math.pow(10,Math.floor(Math.log(i)/Math.LN10)),C=i/n;return C>=JM?n*=10:C>=OM?n*=5:C>=LM&&(n*=2),e=i)&&(I=i);else{let i=-1;for(let n of g)(n=e(n,++i,g))!=null&&(I=n)&&(I=n)}return I}function P1(g,e){let I;if(e===void 0)for(const i of g)i!=null&&(I>i||I===void 0&&i>=i)&&(I=i);else{let i=-1;for(let n of g)(n=e(n,++i,g))!=null&&(I>n||I===void 0&&n>=n)&&(I=n)}return I}function Q3e(g,e,I){g=+g,e=+e,I=(n=arguments.length)<2?(e=g,g=0,1):n<3?1:+I;for(var i=-1,n=Math.max(0,Math.ceil((e-g)/I))|0,C=new Array(n);++i1;){for(let o=0;o1;n--,C--){const r=[];for(let o=0,A;o"u")g=.5;else if(g===0||g===1)return g;const I=Hr(g,e)+Hr(1-g,e),i=I-1;return Ey(i/I)},projectionratio:function(g,e){if(e!==2&&e!==3)return!1;if(typeof g>"u")g=.5;else if(g===0||g===1)return g;const I=Hr(1-g,e),i=Hr(g,e)+I;return I/i},lli8:function(g,e,I,i,n,C,r,o){const A=(g*i-e*I)*(n-r)-(g-I)*(n*o-C*r),s=(g*i-e*I)*(C-o)-(e-i)*(n*o-C*r),a=(g-I)*(C-o)-(e-i)*(n-r);return a==0?!1:{x:A/a,y:s/a}},lli4:function(g,e,I,i){const n=g.x,C=g.y,r=e.x,o=e.y,A=I.x,s=I.y,a=i.x,l=i.y;return ht.lli8(n,C,r,o,A,s,a,l)},lli:function(g,e){return ht.lli4(g,g.c,e,e.c)},makeline:function(g,e){const I=g.x,i=g.y,n=e.x,C=e.y,r=(n-I)/3,o=(C-i)/3;return new ti(I,i,I+r,i+o,I+2*r,i+2*o,n,C)},findbbox:function(g){let e=s5,I=s5,i=l5,n=l5;return g.forEach(function(C){const r=C.bbox();e>r.x.min&&(e=r.x.min),I>r.y.min&&(I=r.y.min),i0&&(a.c1=A,a.c2=s,a.s1=g,a.s2=I,C.push(a))})}),C},makeshape:function(g,e,I){const i=e.points.length,n=g.points.length,C=ht.makeline(e.points[i-1],g.points[0]),r=ht.makeline(g.points[n-1],e.points[0]),o={startcap:C,forward:g,back:e,endcap:r,bbox:ht.findbbox([C,g,e,r])};return o.intersections=function(A){return ht.shapeintersections(o,o.bbox,A,A.bbox,I)},o},getminmax:function(g,e,I){if(!I)return{min:0,max:0};let i=s5,n=l5,C,r;I.indexOf(0)===-1&&(I=[0].concat(I)),I.indexOf(1)===-1&&I.push(1);for(let o=0,A=I.length;on&&(n=r[e]);return{min:i,mid:(i+n)/2,max:n,size:n-i}},align:function(g,e){const I=e.p1.x,i=e.p1.y,n=-My(e.p2.y-i,e.p2.x-I),C=function(r){return{x:(r.x-I)*za(n)-(r.y-i)*Em(n),y:(r.x-I)*Em(n)+(r.y-i)*za(n)}};return g.map(C)},roots:function(g,e){e=e||{p1:{x:0,y:0},p2:{x:1,y:0}};const I=g.length-1,i=ht.align(g,e),n=function(G){return 0<=G&&G<=1};if(I===2){const G=i[0].y,B=i[1].y,w=i[2].y,R=G-2*B+w;if(R!==0){const S=-Sl(B*B-G*w),X=-G+B,W=-(S+X)/R,V=-(-S+X)/R;return[W,V].filter(n)}else if(B!==w&&R===0)return[(2*B-w)/(2*B-2*w)].filter(n);return[]}const C=i[0].y,r=i[1].y,o=i[2].y,A=i[3].y;let s=-C+3*r-3*o+A,a=3*C-6*r+3*o,l=-3*C+3*r,c=C;if(ht.approximately(s,0)){if(ht.approximately(a,0))return ht.approximately(l,0)?[]:[-c/l].filter(n);const G=Sl(l*l-4*a*c),B=2*a;return[(G-l)/B,(-l-G)/B].filter(n)}a/=s,l/=s,c/=s;const u=(3*l-a*a)/3,d=u/3,h=(2*a*a*a-9*a*l+27*c)/27,m=h/2,f=m*m+d*d*d;let b,p,y,Z,v;if(f<0){const G=-u/3,B=G*G*G,w=Sl(B),R=-h/(2*w),S=R<-1?-1:R>1?1:R,X=j3e(S),W=zy(w),V=2*W;return y=V*za(X/3)-a/3,Z=V*za((X+UV)/3)-a/3,v=V*za((X+2*UV)/3)-a/3,[y,Z,v].filter(n)}else{if(f===0)return b=m<0?zy(-m):-zy(m),y=2*b-a/3,Z=-b-a/3,[y,Z].filter(n);{const G=Sl(f);return b=zy(-m+G),p=zy(m+G),[b-p-a/3].filter(n)}}},droots:function(g){if(g.length===3){const e=g[0],I=g[1],i=g[2],n=e-2*I+i;if(n!==0){const C=-Sl(I*I-e*i),r=-e+I,o=-(C+r)/n,A=-(-C+r)/n;return[o,A]}else if(I!==i&&n===0)return[(2*I-i)/(2*(I-i))];return[]}if(g.length===2){const e=g[0],I=g[1];return e!==I?[e/(e-I)]:[]}return[]},curvature:function(g,e,I,i,n){let C,r,o,A,s=0,a=0;const l=ht.compute(g,e),c=ht.compute(g,I),u=l.x*l.x+l.y*l.y;if(i?(C=Sl(Hr(l.y*c.z-c.y*l.z,2)+Hr(l.z*c.x-c.z*l.x,2)+Hr(l.x*c.y-c.x*l.y,2)),r=Hr(u+l.z*l.z,3/2)):(C=l.x*c.y-l.y*c.x,r=Hr(u,3/2)),C===0||r===0)return{k:0,r:0};if(s=C/r,a=r/C,!n){const d=ht.curvature(g-.001,e,I,i,!0).k,h=ht.curvature(g+.001,e,I,i,!0).k;A=(h-s+(s-d))/2,o=(Ey(h-s)+Ey(s-d))/2}return{k:s,r:a,dk:A,adk:o}},inflections:function(g){if(g.length<4)return[];const e=ht.align(g,{p1:g[0],p2:g.slice(-1)[0]}),I=e[2].x*e[1].y,i=e[3].x*e[1].y,n=e[1].x*e[2].y,C=e[3].x*e[2].y,r=18*(-3*I+2*i+3*n-C),o=18*(3*I-i-3*n),A=18*(n-I);if(ht.approximately(r,0)){if(!ht.approximately(o,0)){let c=-A/o;if(0<=c&&c<=1)return[c]}return[]}const s=o*o-4*r*A,a=Math.sqrt(s),l=2*r;return ht.approximately(l,0)?[]:[(a-o)/l,-(o+a)/l].filter(function(c){return 0<=c&&c<=1})},bboxoverlap:function(g,e){const I=["x","y"],i=I.length;for(let n=0,C,r,o,A;n=A)return!1;return!0},expandbox:function(g,e){e.x.ming.x.max&&(g.x.max=e.x.max),e.y.max>g.y.max&&(g.y.max=e.y.max),e.z&&e.z.max>g.z.max&&(g.z.max=e.z.max),g.x.mid=(g.x.min+g.x.max)/2,g.y.mid=(g.y.min+g.y.max)/2,g.z&&(g.z.mid=(g.z.min+g.z.max)/2),g.x.size=g.x.max-g.x.min,g.y.size=g.y.max-g.y.min,g.z&&(g.z.size=g.z.max-g.z.min)},pairiteration:function(g,e,I){const i=g.bbox(),n=e.bbox(),C=1e5,r=I||.5;if(i.x.size+i.y.sizev||v>G)&&(Z+=UV),Z>G&&(B=G,G=Z,Z=B)):G4){if(arguments.length!==1)throw new Error("Only new Bezier(point[]) is accepted for 4th and higher order curves");n=!0}}else if(C!==6&&C!==8&&C!==9&&C!==12&&arguments.length!==1)throw new Error("Only new Bezier(point[]) is accepted for 4th and higher order curves");const r=this._3d=!n&&(C===9||C===12)||e&&e[0]&&typeof e[0].z<"u",o=this.points=[];for(let c=0,u=r?3:2;cPy(c.y)>1e-4),this._lut=[],this._t1=0,this._t2=1,this.update()}static quadraticFromPoints(e,I,i,n){if(typeof n>"u"&&(n=.5),n===0)return new ti(I,I,i);if(n===1)return new ti(e,I,I);const C=ti.getABC(2,e,I,i,n);return new ti(e,C.A,i)}static cubicFromPoints(e,I,i,n,C){typeof n>"u"&&(n=.5);const r=ti.getABC(3,e,I,i,n);typeof C>"u"&&(C=ht.dist(I,r.C));const o=C*(1-n)/n,A=ht.dist(e,i),s=(i.x-e.x)/A,a=(i.y-e.y)/A,l=C*s,c=C*a,u=o*s,d=o*a,h={x:I.x-l,y:I.y-c},m={x:I.x+u,y:I.y+d},f=r.A,b={x:f.x+(h.x-f.x)/(1-n),y:f.y+(h.y-f.y)/(1-n)},p={x:f.x+(m.x-f.x)/n,y:f.y+(m.y-f.y)/n},y={x:e.x+(b.x-e.x)/n,y:e.y+(b.y-e.y)/n},Z={x:i.x+(p.x-i.x)/(1-n),y:i.y+(p.y-i.y)/(1-n)};return new ti(e,y,Z,i)}static getUtils(){return ht}getUtils(){return ti.getUtils()}static get PolyBezier(){return QX}valueOf(){return this.toString()}toString(){return ht.pointsToString(this.points)}toSVG(){if(this._3d)return!1;const e=this.points,I=e[0].x,i=e[0].y,n=["M",I,i,this.order===2?"Q":"C"];for(let C=1,r=e.length;C0}length(){return ht.length(this.derivative.bind(this))}static getABC(e=2,I,i,n,C=.5){const r=ht.projectionratio(C,e),o=1-r,A={x:r*I.x+o*n.x,y:r*I.y+o*n.y},s=ht.abcratio(C,e);return{A:{x:i.x+(i.x-A.x)/s,y:i.y+(i.y-A.y)/s},B:i,C:A,S:I,E:n}}getABC(e,I){I=I||this.get(e);let i=this.points[0],n=this.points[this.order];return ti.getABC(this.order,i,I,n,e)}getLUT(e){if(this.verify(),e=e||100,this._lut.length===e)return this._lut;this._lut=[],e--;for(let I=0,i,n;I1?1:l,c=this.compute(l),c.t=l,c.d=s,c}get(e){return this.compute(e)}point(e){return this.points[e]}compute(e){return this.ratios?ht.computeWithRatios(e,this.points,this.ratios,this._3d):ht.compute(e,this.points,this._3d,this.ratios)}raise(){const e=this.points,I=[e[0]],i=e.length;for(let n=1,C,r;n1;){i=[];for(let r=0,o,A=I.length-1;r=0&&r<=1}),I=I.concat(e[i].sort(ht.numberSort))}).bind(this)),e.values=I.sort(ht.numberSort).filter(function(i,n){return I.indexOf(i)===n}),e}bbox(){const e=this.extrema(),I={};return this.dims.forEach((function(i){I[i]=ht.getminmax(this,i,e[i])}).bind(this)),I}overlaps(e){const I=this.bbox(),i=e.bbox();return ht.bboxoverlap(I,i)}offset(e,I){if(typeof I<"u"){const i=this.get(e),n=this.normal(e),C={c:i,n,x:i.x+n.x*I,y:i.y+n.y*I};return this._3d&&(C.z=i.z+n.z*I),C}if(this._linear){const i=this.normal(0),n=this.points.map(function(C){const r={x:C.x+e*i.x,y:C.y+e*i.y};return C.z&&i.z&&(r.z=C.z+e*i.z),r});return[new ti(n)]}return this.reduce().map(function(i){return i._linear?i.offset(e)[0]:i.scale(e)})}simple(){if(this.order===3){const n=ht.angle(this.points[0],this.points[3],this.points[1]),C=ht.angle(this.points[0],this.points[3],this.points[2]);if(n>0&&C<0||n<0&&C>0)return!1}const e=this.normal(0),I=this.normal(1);let i=e.x*I.x+e.y*I.y;return this._3d&&(i+=e.z*I.z),Py(gze(i)){if(I===2&&l)return;const c=s[l*I],u=this.derivative(l),d={x:c.x+u.x,y:c.y+u.y};s[l+1]=ht.lli4(c,d,a,A[l+1])}),new ti(s))}outline(e,I,i,n){I=typeof I>"u"?e:I;const C=this.reduce(),r=C.length,o=[];let A=[],s,a=0,l=this.length();const c=typeof i<"u"&&typeof n<"u";function u(Z,v,G,B,w){return function(R){const S=B/G,X=(B+w)/G,W=v-Z;return ht.map(R,0,1,Z+S*W,Z+X*W)}}C.forEach(function(Z){const v=Z.length();c?(o.push(Z.scale(u(e,i,l,a,v))),A.push(Z.scale(u(-I,-n,l,a,v)))):(o.push(Z.scale(e)),A.push(Z.scale(-I))),a+=v}),A=A.map(function(Z){return s=Z.points,s[3]?Z.points=[s[3],s[2],s[1],s[0]]:Z.points=[s[2],s[1],s[0]],Z}).reverse();const d=o[0].points[0],h=o[r-1].points[o[r-1].points.length-1],m=A[r-1].points[A[r-1].points.length-1],f=A[0].points[0],b=ht.makeline(m,d),p=ht.makeline(h,f),y=[b].concat(o).concat([p]).concat(A);return y.length,new QX(y)}outlineshapes(e,I,i){I=I||e;const n=this.outline(e,I).curves,C=[];for(let r=1,o=n.length;r1,A.endcap.virtual=r{var o=this.get(r);return ht.between(o.x,I,n)&&ht.between(o.y,i,C)})}selfintersects(e){const I=this.reduce(),i=I.length-2,n=[];for(let C=0,r,o,A;C0&&(C=C.concat(o))}),C}arcs(e){return e=e||.5,this._iterate(e,[])}_error(e,I,i,n){const C=(n-i)/4,r=this.get(i+C),o=this.get(n-C),A=ht.dist(e,I),s=ht.dist(e,r),a=ht.dist(e,o);return Py(s-A)+Py(a-A)}_iterate(e,I){let i=0,n=1,C;do{C=0,n=1;let r=this.get(i),o,A,s,a,l=!1,c=!1,u,d=n,h=1;do if(c=l,a=s,d=(i+n)/2,o=this.get(d),A=this.get(n),s=ht.getccenter(r,o,A),s.interval={start:i,end:n},l=this._error(s,r,i,n)<=e,u=c&&!l,u||(h=n),l){if(n>=1){if(s.interval.end=h=1,a=s,n>1){let f={x:s.x+s.r*eze(s.e),y:s.y+s.r*tze(s.e)};s.e+=ht.angle({x:s.x,y:s.y},f,this.get(1))}break}n=n+(n-i)/2}else n=d;while(!u&&C++<100);if(C>=100)break;a=a||s,I.push(a),i=h}while(n<1);return I}}function VU(g,e){switch(arguments.length){case 0:break;case 1:this.range(g);break;default:this.range(e).domain(g);break}return this}function ize(g,e){switch(arguments.length){case 0:break;case 1:{typeof g=="function"?this.interpolator(g):this.range(g);break}default:{this.domain(g),typeof e=="function"?this.interpolator(e):this.range(e);break}}return this}const Eee=Symbol("implicit");function jX(){var g=new Map,e=[],I=[],i=Eee;function n(C){var r=C+"",o=g.get(r);if(!o){if(i!==Eee)return i;g.set(r,o=e.push(C))}return I[(o-1)%I.length]}return n.domain=function(C){if(!arguments.length)return e.slice();e=[],g=new Map;for(const r of C){const o=r+"";g.has(o)||g.set(o,e.push(r))}return n},n.range=function(C){return arguments.length?(I=Array.from(C),n):I.slice()},n.unknown=function(C){return arguments.length?(i=C,n):i},n.copy=function(){return jX(e,I).unknown(i)},VU.apply(n,arguments),n}function Xpe(){var g=jX().unknown(void 0),e=g.domain,I=g.range,i=0,n=1,C,r,o=!1,A=0,s=0,a=.5;delete g.unknown;function l(){var c=e().length,u=n=1?(I=1,e-1):Math.floor(I*e),n=g[i],C=g[i+1],r=i>0?g[i-1]:2*n-C,o=i()=>g;function Hpe(g,e){return function(I){return g+I*e}}function rze(g,e,I){return g=Math.pow(g,I),e=Math.pow(e,I)-g,I=1/I,function(i){return Math.pow(g+i*e,I)}}function oze(g,e){var I=e-g;return I?Hpe(g,I>180||I<-180?I-360*Math.round(I/360):I):OT(isNaN(g)?e:g)}function Aze(g){return(g=+g)==1?xp:function(e,I){return I-e?rze(e,I,g):OT(isNaN(e)?I:e)}}function xp(g,e){var I=e-g;return I?Hpe(g,I):OT(isNaN(g)?e:g)}const Mee=function g(e){var I=Aze(e);function i(n,C){var r=I((n=UX(n)).r,(C=UX(C)).r),o=I(n.g,C.g),A=I(n.b,C.b),s=xp(n.opacity,C.opacity);return function(a){return n.r=r(a),n.g=o(a),n.b=A(a),n.opacity=s(a),n+""}}return i.gamma=g,i}(1);function aze(g){return function(e){var I=e.length,i=new Array(I),n=new Array(I),C=new Array(I),r,o;for(r=0;rI&&(C=e.slice(I,C),o[r]?o[r]+=C:o[++r]=C),(i=i[0])===(n=n[0])?o[r]?o[r]+=n:o[++r]=n:(o[++r]=null,A.push({i:r,x:$X(i,n)})),I=c5.lastIndex;return Ie&&(I=g,g=e,e=I),function(i){return Math.max(g,Math.min(e,i))}}function Gze(g,e,I){var i=g[0],n=g[1],C=e[0],r=e[1];return n2?Bze:Gze,A=s=null,l}function l(c){return c==null||isNaN(c=+c)?C:(A||(A=o(g.map(i),e,I)))(i(r(c)))}return l.invert=function(c){return r(n((s||(s=o(e,g.map(i),$X)))(c)))},l.domain=function(c){return arguments.length?(g=Array.from(c,yze),a()):g.slice()},l.range=function(c){return arguments.length?(e=Array.from(c),a()):e.slice()},l.rangeRound=function(c){return e=Array.from(c),I=Tpe,a()},l.clamp=function(c){return arguments.length?(r=c?!0:Bc,a()):r!==Bc},l.interpolate=function(c){return arguments.length?(I=c,a()):I},l.unknown=function(c){return arguments.length?(C=c,l):C},function(c,u){return i=c,n=u,a()}}function wze(){return Sze()(Bc,Bc)}function Vze(g){return Math.abs(g=Math.round(g))>=1e21?g.toLocaleString("en").replace(/,/g,""):g.toString(10)}function qX(g,e){if((I=(g=e?g.toExponential(e-1):g.toExponential()).indexOf("e"))<0)return null;var I,i=g.slice(0,I);return[i.length>1?i[0]+i.slice(2):i,+g.slice(I+1)]}function Vb(g){return g=qX(Math.abs(g)),g?g[1]:NaN}function Rze(g,e){return function(I,i){for(var n=I.length,C=[],r=0,o=g[0],A=0;n>0&&o>0&&(A+o+1>i&&(o=Math.max(1,i-A)),C.push(I.substring(n-=o,n+o)),!((A+=o+1)>i));)o=g[r=(r+1)%g.length];return C.reverse().join(e)}}function Wze(g){return function(e){return e.replace(/[0-9]/g,function(I){return g[+I]})}}var Xze=/^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;function e9(g){if(!(e=Xze.exec(g)))throw new Error("invalid format: "+g);var e;return new RU({fill:e[1],align:e[2],sign:e[3],symbol:e[4],zero:e[5],width:e[6],comma:e[7],precision:e[8]&&e[8].slice(1),trim:e[9],type:e[10]})}e9.prototype=RU.prototype;function RU(g){this.fill=g.fill===void 0?" ":g.fill+"",this.align=g.align===void 0?">":g.align+"",this.sign=g.sign===void 0?"-":g.sign+"",this.symbol=g.symbol===void 0?"":g.symbol+"",this.zero=!!g.zero,this.width=g.width===void 0?void 0:+g.width,this.comma=!!g.comma,this.precision=g.precision===void 0?void 0:+g.precision,this.trim=!!g.trim,this.type=g.type===void 0?"":g.type+""}RU.prototype.toString=function(){return this.fill+this.align+this.sign+this.symbol+(this.zero?"0":"")+(this.width===void 0?"":Math.max(1,this.width|0))+(this.comma?",":"")+(this.precision===void 0?"":"."+Math.max(0,this.precision|0))+(this.trim?"~":"")+this.type};function Hze(g){e:for(var e=g.length,I=1,i=-1,n;I0&&(i=0);break}return i>0?g.slice(0,i)+g.slice(n+1):g}var Ype;function Tze(g,e){var I=qX(g,e);if(!I)return g+"";var i=I[0],n=I[1],C=n-(Ype=Math.max(-8,Math.min(8,Math.floor(n/3)))*3)+1,r=i.length;return C===r?i:C>r?i+new Array(C-r+1).join("0"):C>0?i.slice(0,C)+"."+i.slice(C):"0."+new Array(1-C).join("0")+qX(g,Math.max(0,e+C-1))[0]}function Pee(g,e){var I=qX(g,e);if(!I)return g+"";var i=I[0],n=I[1];return n<0?"0."+new Array(-n).join("0")+i:i.length>n+1?i.slice(0,n+1)+"."+i.slice(n+1):i+new Array(n-i.length+2).join("0")}const Jee={"%":(g,e)=>(g*100).toFixed(e),b:g=>Math.round(g).toString(2),c:g=>g+"",d:Vze,e:(g,e)=>g.toExponential(e),f:(g,e)=>g.toFixed(e),g:(g,e)=>g.toPrecision(e),o:g=>Math.round(g).toString(8),p:(g,e)=>Pee(g*100,e),r:Pee,s:Tze,X:g=>Math.round(g).toString(16).toUpperCase(),x:g=>Math.round(g).toString(16)};function Oee(g){return g}var Lee=Array.prototype.map,_ee=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"];function Nze(g){var e=g.grouping===void 0||g.thousands===void 0?Oee:Rze(Lee.call(g.grouping,Number),g.thousands+""),I=g.currency===void 0?"":g.currency[0]+"",i=g.currency===void 0?"":g.currency[1]+"",n=g.decimal===void 0?".":g.decimal+"",C=g.numerals===void 0?Oee:Wze(Lee.call(g.numerals,String)),r=g.percent===void 0?"%":g.percent+"",o=g.minus===void 0?"−":g.minus+"",A=g.nan===void 0?"NaN":g.nan+"";function s(l){l=e9(l);var c=l.fill,u=l.align,d=l.sign,h=l.symbol,m=l.zero,f=l.width,b=l.comma,p=l.precision,y=l.trim,Z=l.type;Z==="n"?(b=!0,Z="g"):Jee[Z]||(p===void 0&&(p=12),y=!0,Z="g"),(m||c==="0"&&u==="=")&&(m=!0,c="0",u="=");var v=h==="$"?I:h==="#"&&/[boxX]/.test(Z)?"0"+Z.toLowerCase():"",G=h==="$"?i:/[%p]/.test(Z)?r:"",B=Jee[Z],w=/[defgprs%]/.test(Z);p=p===void 0?6:/[gprs]/.test(Z)?Math.max(1,Math.min(21,p)):Math.max(0,Math.min(20,p));function R(S){var X=v,W=G,V,H,D;if(Z==="c")W=B(S)+W,S="";else{S=+S;var Y=S<0||1/S<0;if(S=isNaN(S)?A:B(Math.abs(S),p),y&&(S=Hze(S)),Y&&+S==0&&d!=="+"&&(Y=!1),X=(Y?d==="("?d:o:d==="-"||d==="("?"":d)+X,W=(Z==="s"?_ee[8+Ype/3]:"")+W+(Y&&d==="("?")":""),w){for(V=-1,H=S.length;++VD||D>57){W=(D===46?n+S.slice(V+1):S.slice(V))+W,S=S.slice(0,V);break}}}b&&!m&&(S=e(S,1/0));var F=X.length+S.length+W.length,_=F>1)+X+S+W+_.slice(F);break;default:S=_+X+S+W;break}return C(S)}return R.toString=function(){return l+""},R}function a(l,c){var u=s((l=e9(l),l.type="f",l)),d=Math.max(-8,Math.min(8,Math.floor(Vb(c)/3)))*3,h=Math.pow(10,-d),m=_ee[8+d/3];return function(f){return u(h*f)+m}}return{format:s,formatPrefix:a}}var QV,Kpe,xpe;kze({thousands:",",grouping:[3],currency:["$",""]});function kze(g){return QV=Nze(g),Kpe=QV.format,xpe=QV.formatPrefix,QV}function Yze(g){return Math.max(0,-Vb(Math.abs(g)))}function Kze(g,e){return Math.max(0,Math.max(-8,Math.min(8,Math.floor(Vb(e)/3)))*3-Vb(Math.abs(g)))}function xze(g,e){return g=Math.abs(g),e=Math.abs(e)-g,Math.max(0,Vb(e)-Vb(g))+1}function Dze(g,e,I,i){var n=U3e(g,e,I),C;switch(i=e9(i??",f"),i.type){case"s":{var r=Math.max(Math.abs(g),Math.abs(e));return i.precision==null&&!isNaN(C=Kze(n,r))&&(i.precision=C),xpe(i,r)}case"":case"e":case"g":case"p":case"r":{i.precision==null&&!isNaN(C=xze(n,Math.max(Math.abs(g),Math.abs(e))))&&(i.precision=C-(i.type==="e"));break}case"f":case"%":{i.precision==null&&!isNaN(C=Yze(n))&&(i.precision=C-(i.type==="%")*2);break}}return Kpe(i)}function Dpe(g){var e=g.domain;return g.ticks=function(I){var i=e();return _3e(i[0],i[i.length-1],I??10)},g.tickFormat=function(I,i){var n=e();return Dze(n[0],n[n.length-1],I??10,i)},g.nice=function(I){I==null&&(I=10);var i=e(),n=0,C=i.length-1,r=i[n],o=i[C],A,s,a=10;for(o0;){if(s=Rpe(r,o,I),s===A)return i[n]=r,i[C]=o,e(i);if(s>0)r=Math.floor(r/s)*s,o=Math.ceil(o/s)*s;else if(s<0)r=Math.ceil(r*s)/s,o=Math.floor(o*s)/s;else break;A=s}return g},g}function nh(){var g=wze();return g.copy=function(){return vze(g,nh())},VU.apply(g,arguments),Dpe(g)}function Fze(){var g=0,e=1,I,i,n,C,r=Bc,o=!1,A;function s(l){return l==null||isNaN(l=+l)?A:r(n===0?.5:(l=(C(l)-I)*n,o?Math.max(0,Math.min(1,l)):l))}s.domain=function(l){return arguments.length?([g,e]=l,I=C(g=+g),i=C(e=+e),n=I===i?0:1/(i-I),s):[g,e]},s.clamp=function(l){return arguments.length?(o=!!l,s):o},s.interpolator=function(l){return arguments.length?(r=l,s):r};function a(l){return function(c){var u,d;return arguments.length?([u,d]=c,r=l(u,d),s):[r(0),r(1)]}}return s.range=a(LT),s.rangeRound=a(Tpe),s.unknown=function(l){return arguments.length?(A=l,s):A},function(l){return C=l,I=l(g),i=l(e),n=I===i?0:1/(i-I),s}}function Eze(g,e){return e.domain(g.domain()).interpolator(g.interpolator()).clamp(g.clamp()).unknown(g.unknown())}function Fpe(){var g=Dpe(Fze()(Bc));return g.copy=function(){return Eze(g,Fpe())},ize.apply(g,arguments)}var Mze=typeof global=="object"&&global&&global.Object===Object&&global;const Epe=Mze;var zze=typeof self=="object"&&self&&self.Object===Object&&self,Pze=Epe||zze||Function("return this")();const Xa=Pze;var Jze=Xa.Symbol;const Ba=Jze;var Mpe=Object.prototype,Oze=Mpe.hasOwnProperty,Lze=Mpe.toString,Oy=Ba?Ba.toStringTag:void 0;function _ze(g){var e=Oze.call(g,Oy),I=g[Oy];try{g[Oy]=void 0;var i=!0}catch{}var n=Lze.call(g);return i&&(e?g[Oy]=I:delete g[Oy]),n}var Uze=Object.prototype,Qze=Uze.toString;function jze(g){return Qze.call(g)}var $ze="[object Null]",qze="[object Undefined]",Uee=Ba?Ba.toStringTag:void 0;function x0(g){return g==null?g===void 0?qze:$ze:Uee&&Uee in Object(g)?_ze(g):jze(g)}function nu(g){return g!=null&&typeof g=="object"}var ePe="[object Symbol]";function _T(g){return typeof g=="symbol"||nu(g)&&x0(g)==ePe}function zpe(g,e){for(var I=-1,i=g==null?0:g.length,n=Array(i);++I-1}var PPe=9007199254740991,JPe=/^(?:0|[1-9]\d*)$/;function WU(g,e){var I=typeof g;return e=e??PPe,!!e&&(I=="number"||I!="symbol"&&JPe.test(g))&&g>-1&&g%1==0&&g-1&&g%1==0&&g<=_Pe}function HU(g){return g!=null&&XU(g.length)&&!Jpe(g)}function UPe(g,e,I){if(!Js(I))return!1;var i=typeof e;return(i=="number"?HU(I)&&WU(e,I.length):i=="string"&&e in I)?UT(I[e],g):!1}var QPe=Object.prototype;function TU(g){var e=g&&g.constructor,I=typeof e=="function"&&e.prototype||QPe;return g===I}function jPe(g,e){for(var I=-1,i=Array(g);++I-1}function sOe(g,e){var I=this.__data__,i=jT(I,g);return i<0?(++this.size,I.push([g,e])):I[i][1]=e,this}function rl(g){var e=-1,I=g==null?0:g.length;for(this.clear();++e=e?g:e)),g}function WOe(){this.__data__=new rl,this.size=0}function XOe(g){var e=this.__data__,I=e.delete(g);return this.size=e.size,I}function HOe(g){return this.__data__.get(g)}function TOe(g){return this.__data__.has(g)}var NOe=200;function kOe(g,e){var I=this.__data__;if(I instanceof rl){var i=I.__data__;if(!Rv||i.lengtho))return!1;var s=C.get(g),a=C.get(e);if(s&&a)return s==e&&a==g;var l=-1,c=!0,u=I&Z_e?new Xv:void 0;for(C.set(g,e),C.set(e,g);++l=mUe){var s=e?null:hUe(g);if(s)return FU(s);r=!1,n=ube,A=new Xv}else A=e?[]:o;e:for(;++isze(g[g.length-1]);var bUe=new Array(3).concat("ef8a62f7f7f767a9cf","ca0020f4a58292c5de0571b0","ca0020f4a582f7f7f792c5de0571b0","b2182bef8a62fddbc7d1e5f067a9cf2166ac","b2182bef8a62fddbc7f7f7f7d1e5f067a9cf2166ac","b2182bd6604df4a582fddbc7d1e5f092c5de4393c32166ac","b2182bd6604df4a582fddbc7f7f7f7d1e5f092c5de4393c32166ac","67001fb2182bd6604df4a582fddbc7d1e5f092c5de4393c32166ac053061","67001fb2182bd6604df4a582fddbc7f7f7f7d1e5f092c5de4393c32166ac053061").map(Ha);const yUe=D0(bUe);var ZUe=new Array(3).concat("fc8d59ffffbf99d594","d7191cfdae61abdda42b83ba","d7191cfdae61ffffbfabdda42b83ba","d53e4ffc8d59fee08be6f59899d5943288bd","d53e4ffc8d59fee08bffffbfe6f59899d5943288bd","d53e4ff46d43fdae61fee08be6f598abdda466c2a53288bd","d53e4ff46d43fdae61fee08bffffbfe6f598abdda466c2a53288bd","9e0142d53e4ff46d43fdae61fee08be6f598abdda466c2a53288bd5e4fa2","9e0142d53e4ff46d43fdae61fee08bffffbfe6f598abdda466c2a53288bd5e4fa2").map(Ha);const GUe=D0(ZUe);var BUe=new Array(3).concat("e0ecf49ebcda8856a7","edf8fbb3cde38c96c688419d","edf8fbb3cde38c96c68856a7810f7c","edf8fbbfd3e69ebcda8c96c68856a7810f7c","edf8fbbfd3e69ebcda8c96c68c6bb188419d6e016b","f7fcfde0ecf4bfd3e69ebcda8c96c68c6bb188419d6e016b","f7fcfde0ecf4bfd3e69ebcda8c96c68c6bb188419d810f7c4d004b").map(Ha);const vUe=D0(BUe);var SUe=new Array(3).concat("fde0ddfa9fb5c51b8a","feebe2fbb4b9f768a1ae017e","feebe2fbb4b9f768a1c51b8a7a0177","feebe2fcc5c0fa9fb5f768a1c51b8a7a0177","feebe2fcc5c0fa9fb5f768a1dd3497ae017e7a0177","fff7f3fde0ddfcc5c0fa9fb5f768a1dd3497ae017e7a0177","fff7f3fde0ddfcc5c0fa9fb5f768a1dd3497ae017e7a017749006a").map(Ha);const wUe=D0(SUe);var VUe=new Array(3).concat("fff7bcfec44fd95f0e","ffffd4fed98efe9929cc4c02","ffffd4fed98efe9929d95f0e993404","ffffd4fee391fec44ffe9929d95f0e993404","ffffd4fee391fec44ffe9929ec7014cc4c028c2d04","ffffe5fff7bcfee391fec44ffe9929ec7014cc4c028c2d04","ffffe5fff7bcfee391fec44ffe9929ec7014cc4c02993404662506").map(Ha);const RUe=D0(VUe);var WUe=new Array(3).concat("f0f0f0bdbdbd636363","f7f7f7cccccc969696525252","f7f7f7cccccc969696636363252525","f7f7f7d9d9d9bdbdbd969696636363252525","f7f7f7d9d9d9bdbdbd969696737373525252252525","fffffff0f0f0d9d9d9bdbdbd969696737373525252252525","fffffff0f0f0d9d9d9bdbdbd969696737373525252252525000000").map(Ha);const XUe=D0(WUe);function HUe(g){return g=Math.max(0,Math.min(1,g)),"rgb("+Math.max(0,Math.min(255,Math.round(-4.54-g*(35.34-g*(2381.73-g*(6402.7-g*(7024.72-g*2710.57)))))))+", "+Math.max(0,Math.min(255,Math.round(32.49+g*(170.73+g*(52.82-g*(131.46-g*(176.58-g*67.37)))))))+", "+Math.max(0,Math.min(255,Math.round(81.24+g*(442.36-g*(2482.43-g*(6167.24-g*(6614.94-g*2475.67)))))))+")"}var TUe=kpe(iu(-100,.75,.35),iu(80,1.5,.8));kpe(iu(260,.75,.35),iu(80,1.5,.8));iu();function tN(g){var e=g.length;return function(I){return g[Math.max(0,Math.min(e-1,Math.floor(I*e)))]}}const bbe=tN(Ha("44015444025645045745055946075a46085c460a5d460b5e470d60470e6147106347116447136548146748166848176948186a481a6c481b6d481c6e481d6f481f70482071482173482374482475482576482677482878482979472a7a472c7a472d7b472e7c472f7d46307e46327e46337f463480453581453781453882443983443a83443b84433d84433e85423f854240864241864142874144874045884046883f47883f48893e49893e4a893e4c8a3d4d8a3d4e8a3c4f8a3c508b3b518b3b528b3a538b3a548c39558c39568c38588c38598c375a8c375b8d365c8d365d8d355e8d355f8d34608d34618d33628d33638d32648e32658e31668e31678e31688e30698e306a8e2f6b8e2f6c8e2e6d8e2e6e8e2e6f8e2d708e2d718e2c718e2c728e2c738e2b748e2b758e2a768e2a778e2a788e29798e297a8e297b8e287c8e287d8e277e8e277f8e27808e26818e26828e26828e25838e25848e25858e24868e24878e23888e23898e238a8d228b8d228c8d228d8d218e8d218f8d21908d21918c20928c20928c20938c1f948c1f958b1f968b1f978b1f988b1f998a1f9a8a1e9b8a1e9c891e9d891f9e891f9f881fa0881fa1881fa1871fa28720a38620a48621a58521a68522a78522a88423a98324aa8325ab8225ac8226ad8127ad8128ae8029af7f2ab07f2cb17e2db27d2eb37c2fb47c31b57b32b67a34b67935b77937b87838b9773aba763bbb753dbc743fbc7340bd7242be7144bf7046c06f48c16e4ac16d4cc26c4ec36b50c46a52c56954c56856c66758c7655ac8645cc8635ec96260ca6063cb5f65cb5e67cc5c69cd5b6ccd5a6ece5870cf5773d05675d05477d1537ad1517cd2507fd34e81d34d84d44b86d54989d5488bd6468ed64590d74393d74195d84098d83e9bd93c9dd93ba0da39a2da37a5db36a8db34aadc32addc30b0dd2fb2dd2db5de2bb8de29bade28bddf26c0df25c2df23c5e021c8e020cae11fcde11dd0e11cd2e21bd5e21ad8e219dae319dde318dfe318e2e418e5e419e7e419eae51aece51befe51cf1e51df4e61ef6e620f8e621fbe723fde725"));tN(Ha("00000401000501010601010802010902020b02020d03030f03031204041405041606051806051a07061c08071e0907200a08220b09240c09260d0a290e0b2b100b2d110c2f120d31130d34140e36150e38160f3b180f3d19103f1a10421c10441d11471e114920114b21114e22115024125325125527125829115a2a115c2c115f2d11612f116331116533106734106936106b38106c390f6e3b0f703d0f713f0f72400f74420f75440f764510774710784910784a10794c117a4e117b4f127b51127c52137c54137d56147d57157e59157e5a167e5c167f5d177f5f187f601880621980641a80651a80671b80681c816a1c816b1d816d1d816e1e81701f81721f817320817521817621817822817922827b23827c23827e24828025828125818326818426818627818827818928818b29818c29818e2a81902a81912b81932b80942c80962c80982d80992d809b2e7f9c2e7f9e2f7fa02f7fa1307ea3307ea5317ea6317da8327daa337dab337cad347cae347bb0357bb2357bb3367ab5367ab73779b83779ba3878bc3978bd3977bf3a77c03a76c23b75c43c75c53c74c73d73c83e73ca3e72cc3f71cd4071cf4070d0416fd2426fd3436ed5446dd6456cd8456cd9466bdb476adc4869de4968df4a68e04c67e24d66e34e65e44f64e55064e75263e85362e95462ea5661eb5760ec5860ed5a5fee5b5eef5d5ef05f5ef1605df2625df2645cf3655cf4675cf4695cf56b5cf66c5cf66e5cf7705cf7725cf8745cf8765cf9785df9795df97b5dfa7d5efa7f5efa815ffb835ffb8560fb8761fc8961fc8a62fc8c63fc8e64fc9065fd9266fd9467fd9668fd9869fd9a6afd9b6bfe9d6cfe9f6dfea16efea36ffea571fea772fea973feaa74feac76feae77feb078feb27afeb47bfeb67cfeb77efeb97ffebb81febd82febf84fec185fec287fec488fec68afec88cfeca8dfecc8ffecd90fecf92fed194fed395fed597fed799fed89afdda9cfddc9efddea0fde0a1fde2a3fde3a5fde5a7fde7a9fde9aafdebacfcecaefceeb0fcf0b2fcf2b4fcf4b6fcf6b8fcf7b9fcf9bbfcfbbdfcfdbf"));tN(Ha("00000401000501010601010802010a02020c02020e03021004031204031405041706041907051b08051d09061f0a07220b07240c08260d08290e092b10092d110a30120a32140b34150b37160b39180c3c190c3e1b0c411c0c431e0c451f0c48210c4a230c4c240c4f260c51280b53290b552b0b572d0b592f0a5b310a5c320a5e340a5f3609613809623909633b09643d09653e0966400a67420a68440a68450a69470b6a490b6a4a0c6b4c0c6b4d0d6c4f0d6c510e6c520e6d540f6d550f6d57106e59106e5a116e5c126e5d126e5f136e61136e62146e64156e65156e67166e69166e6a176e6c186e6d186e6f196e71196e721a6e741a6e751b6e771c6d781c6d7a1d6d7c1d6d7d1e6d7f1e6c801f6c82206c84206b85216b87216b88226a8a226a8c23698d23698f24699025689225689326679526679727669827669a28659b29649d29649f2a63a02a63a22b62a32c61a52c60a62d60a82e5fa92e5eab2f5ead305dae305cb0315bb1325ab3325ab43359b63458b73557b93556ba3655bc3754bd3853bf3952c03a51c13a50c33b4fc43c4ec63d4dc73e4cc83f4bca404acb4149cc4248ce4347cf4446d04545d24644d34743d44842d54a41d74b3fd84c3ed94d3dda4e3cdb503bdd513ade5238df5337e05536e15635e25734e35933e45a31e55c30e65d2fe75e2ee8602de9612bea632aeb6429eb6628ec6726ed6925ee6a24ef6c23ef6e21f06f20f1711ff1731df2741cf3761bf37819f47918f57b17f57d15f67e14f68013f78212f78410f8850ff8870ef8890cf98b0bf98c0af98e09fa9008fa9207fa9407fb9606fb9706fb9906fb9b06fb9d07fc9f07fca108fca309fca50afca60cfca80dfcaa0ffcac11fcae12fcb014fcb216fcb418fbb61afbb81dfbba1ffbbc21fbbe23fac026fac228fac42afac62df9c72ff9c932f9cb35f8cd37f8cf3af7d13df7d340f6d543f6d746f5d949f5db4cf4dd4ff4df53f4e156f3e35af3e55df2e661f2e865f2ea69f1ec6df1ed71f1ef75f1f179f2f27df2f482f3f586f3f68af4f88ef5f992f6fa96f8fb9af9fc9dfafda1fcffa4"));tN(Ha("0d088710078813078916078a19068c1b068d1d068e20068f2206902406912605912805922a05932c05942e05952f059631059733059735049837049938049a3a049a3c049b3e049c3f049c41049d43039e44039e46039f48039f4903a04b03a14c02a14e02a25002a25102a35302a35502a45601a45801a45901a55b01a55c01a65e01a66001a66100a76300a76400a76600a76700a86900a86a00a86c00a86e00a86f00a87100a87201a87401a87501a87701a87801a87a02a87b02a87d03a87e03a88004a88104a78305a78405a78606a68707a68808a68a09a58b0aa58d0ba58e0ca48f0da4910ea3920fa39410a29511a19613a19814a099159f9a169f9c179e9d189d9e199da01a9ca11b9ba21d9aa31e9aa51f99a62098a72197a82296aa2395ab2494ac2694ad2793ae2892b02991b12a90b22b8fb32c8eb42e8db52f8cb6308bb7318ab83289ba3388bb3488bc3587bd3786be3885bf3984c03a83c13b82c23c81c33d80c43e7fc5407ec6417dc7427cc8437bc9447aca457acb4679cc4778cc4977cd4a76ce4b75cf4c74d04d73d14e72d24f71d35171d45270d5536fd5546ed6556dd7566cd8576bd9586ada5a6ada5b69db5c68dc5d67dd5e66de5f65de6164df6263e06363e16462e26561e26660e3685fe4695ee56a5de56b5de66c5ce76e5be76f5ae87059e97158e97257ea7457eb7556eb7655ec7754ed7953ed7a52ee7b51ef7c51ef7e50f07f4ff0804ef1814df1834cf2844bf3854bf3874af48849f48948f58b47f58c46f68d45f68f44f79044f79143f79342f89441f89540f9973ff9983ef99a3efa9b3dfa9c3cfa9e3bfb9f3afba139fba238fca338fca537fca636fca835fca934fdab33fdac33fdae32fdaf31fdb130fdb22ffdb42ffdb52efeb72dfeb82cfeba2cfebb2bfebd2afebe2afec029fdc229fdc328fdc527fdc627fdc827fdca26fdcb26fccd25fcce25fcd025fcd225fbd324fbd524fbd724fad824fada24f9dc24f9dd25f8df25f8e125f7e225f7e425f6e626f6e826f5e926f5eb27f4ed27f3ee27f3f027f2f227f1f426f1f525f0f724f0f921"));var rh={},gN={};gN.byteLength=YUe;gN.toByteArray=xUe;gN.fromByteArray=EUe;var LA=[],kr=[],NUe=typeof Uint8Array<"u"?Uint8Array:Array,m5="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(var Mm=0,kUe=m5.length;Mm0)throw new Error("Invalid string. Length must be a multiple of 4");var I=g.indexOf("=");I===-1&&(I=e);var i=I===e?0:4-I%4;return[I,i]}function YUe(g){var e=ybe(g),I=e[0],i=e[1];return(I+i)*3/4-i}function KUe(g,e,I){return(e+I)*3/4-I}function xUe(g){var e,I=ybe(g),i=I[0],n=I[1],C=new NUe(KUe(g,i,n)),r=0,o=n>0?i-4:i,A;for(A=0;A>16&255,C[r++]=e>>8&255,C[r++]=e&255;return n===2&&(e=kr[g.charCodeAt(A)]<<2|kr[g.charCodeAt(A+1)]>>4,C[r++]=e&255),n===1&&(e=kr[g.charCodeAt(A)]<<10|kr[g.charCodeAt(A+1)]<<4|kr[g.charCodeAt(A+2)]>>2,C[r++]=e>>8&255,C[r++]=e&255),C}function DUe(g){return LA[g>>18&63]+LA[g>>12&63]+LA[g>>6&63]+LA[g&63]}function FUe(g,e,I){for(var i,n=[],C=e;Co?o:r+C));return i===1?(e=g[I-1],n.push(LA[e>>2]+LA[e<<4&63]+"==")):i===2&&(e=(g[I-2]<<8)+g[I-1],n.push(LA[e>>10]+LA[e>>4&63]+LA[e<<2&63]+"=")),n.join("")}var MU={};/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh */MU.read=function(g,e,I,i,n){var C,r,o=n*8-i-1,A=(1<>1,a=-7,l=I?n-1:0,c=I?-1:1,u=g[e+l];for(l+=c,C=u&(1<<-a)-1,u>>=-a,a+=o;a>0;C=C*256+g[e+l],l+=c,a-=8);for(r=C&(1<<-a)-1,C>>=-a,a+=i;a>0;r=r*256+g[e+l],l+=c,a-=8);if(C===0)C=1-s;else{if(C===A)return r?NaN:(u?-1:1)*(1/0);r=r+Math.pow(2,i),C=C-s}return(u?-1:1)*r*Math.pow(2,C-i)};MU.write=function(g,e,I,i,n,C){var r,o,A,s=C*8-n-1,a=(1<>1,c=n===23?Math.pow(2,-24)-Math.pow(2,-77):0,u=i?0:C-1,d=i?1:-1,h=e<0||e===0&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(o=isNaN(e)?1:0,r=a):(r=Math.floor(Math.log(e)/Math.LN2),e*(A=Math.pow(2,-r))<1&&(r--,A*=2),r+l>=1?e+=c/A:e+=c*Math.pow(2,1-l),e*A>=2&&(r++,A/=2),r+l>=a?(o=0,r=a):r+l>=1?(o=(e*A-1)*Math.pow(2,n),r=r+l):(o=e*Math.pow(2,l-1)*Math.pow(2,n),r=0));n>=8;g[I+u]=o&255,u+=d,o/=256,n-=8);for(r=r<0;g[I+u]=r&255,u+=d,r/=256,s-=8);g[I+u-d]|=h*128};/*! + +void main() +{ + vec4 color = texture2D(uSampler, vTextureCoord); + float randomValue = rand(gl_FragCoord.xy * uSeed); + float diff = (randomValue - 0.5) * uNoise; + + // Un-premultiply alpha before applying the color matrix. See issue #3539. + if (color.a > 0.0) { + color.rgb /= color.a; + } + + color.r += diff; + color.g += diff; + color.b += diff; + + // Premultiply alpha again. + color.rgb *= color.a; + + gl_FragColor = color; +} +`,Qze=function(e){Lze(g,e);function g(I,i){I===void 0&&(I=.5),i===void 0&&(i=Math.random());var n=e.call(this,kL,Uze,{uNoise:0,uSeed:0})||this;return n.noise=I,n.seed=i,n}return Object.defineProperty(g.prototype,"noise",{get:function(){return this.uniforms.uNoise},set:function(I){this.uniforms.uNoise=I},enumerable:!1,configurable:!0}),Object.defineProperty(g.prototype,"seed",{get:function(){return this.uniforms.uSeed},set:function(I){this.uniforms.uSeed=I},enumerable:!1,configurable:!0}),g}(zs);/*! + * @pixi/mixin-cache-as-bitmap - v6.5.10 + * Compiled Thu, 06 Jul 2023 15:25:11 UTC + * + * @pixi/mixin-cache-as-bitmap is licensed under the MIT License. + * http://www.opensource.org/licenses/mit-license + */var ofe=new fi;jI.prototype._cacheAsBitmap=!1;jI.prototype._cacheData=null;jI.prototype._cacheAsBitmapResolution=null;jI.prototype._cacheAsBitmapMultisample=mI.NONE;var jze=function(){function e(){this.textureCacheId=null,this.originalRender=null,this.originalRenderCanvas=null,this.originalCalculateBounds=null,this.originalGetLocalBounds=null,this.originalUpdateTransform=null,this.originalDestroy=null,this.originalMask=null,this.originalFilterArea=null,this.originalContainsPoint=null,this.sprite=null}return e}();Object.defineProperties(jI.prototype,{cacheAsBitmapResolution:{get:function(){return this._cacheAsBitmapResolution},set:function(e){e!==this._cacheAsBitmapResolution&&(this._cacheAsBitmapResolution=e,this.cacheAsBitmap&&(this.cacheAsBitmap=!1,this.cacheAsBitmap=!0))}},cacheAsBitmapMultisample:{get:function(){return this._cacheAsBitmapMultisample},set:function(e){e!==this._cacheAsBitmapMultisample&&(this._cacheAsBitmapMultisample=e,this.cacheAsBitmap&&(this.cacheAsBitmap=!1,this.cacheAsBitmap=!0))}},cacheAsBitmap:{get:function(){return this._cacheAsBitmap},set:function(e){if(this._cacheAsBitmap!==e){this._cacheAsBitmap=e;var g;e?(this._cacheData||(this._cacheData=new jze),g=this._cacheData,g.originalRender=this.render,g.originalRenderCanvas=this.renderCanvas,g.originalUpdateTransform=this.updateTransform,g.originalCalculateBounds=this.calculateBounds,g.originalGetLocalBounds=this.getLocalBounds,g.originalDestroy=this.destroy,g.originalContainsPoint=this.containsPoint,g.originalMask=this._mask,g.originalFilterArea=this.filterArea,this.render=this._renderCached,this.renderCanvas=this._renderCachedCanvas,this.destroy=this._cacheAsBitmapDestroy):(g=this._cacheData,g.sprite&&this._destroyCachedDisplayObject(),this.render=g.originalRender,this.renderCanvas=g.originalRenderCanvas,this.calculateBounds=g.originalCalculateBounds,this.getLocalBounds=g.originalGetLocalBounds,this.destroy=g.originalDestroy,this.updateTransform=g.originalUpdateTransform,this.containsPoint=g.originalContainsPoint,this._mask=g.originalMask,this.filterArea=g.originalFilterArea)}}}});jI.prototype._renderCached=function(g){!this.visible||this.worldAlpha<=0||!this.renderable||(this._initCachedDisplayObject(g),this._cacheData.sprite.transform._worldID=this.transform._worldID,this._cacheData.sprite.worldAlpha=this.worldAlpha,this._cacheData.sprite._render(g))};jI.prototype._initCachedDisplayObject=function(g){var I;if(!(this._cacheData&&this._cacheData.sprite)){var i=this.alpha;this.alpha=1,g.batch.flush();var n=this.getLocalBounds(null,!0).clone();if(this.filters&&this.filters.length){var C=this.filters[0].padding;n.pad(C)}n.ceil(yt.RESOLUTION);var r=g.renderTexture.current,o=g.renderTexture.sourceFrame.clone(),A=g.renderTexture.destinationFrame.clone(),s=g.projection.transform,a=Ws.create({width:n.width,height:n.height,resolution:this.cacheAsBitmapResolution||g.resolution,multisample:(I=this.cacheAsBitmapMultisample)!==null&&I!==void 0?I:g.multisample}),l="cacheAsBitmap_"+kc();this._cacheData.textureCacheId=l,yg.addToCache(a.baseTexture,l),eg.addToCache(a,l);var c=this.transform.localTransform.copyTo(ofe).invert().translate(-n.x,-n.y);this.render=this._cacheData.originalRender,g.render(this,{renderTexture:a,clear:!0,transform:c,skipUpdateTransform:!1}),g.framebuffer.blit(),g.projection.transform=s,g.renderTexture.bind(r,o,A),this.render=this._renderCached,this.updateTransform=this.displayObjectUpdateTransform,this.calculateBounds=this._calculateCachedBounds,this.getLocalBounds=this._getCachedLocalBounds,this._mask=null,this.filterArea=null,this.alpha=i;var u=new h0(a);u.transform.worldTransform=this.transform.worldTransform,u.anchor.x=-(n.x/n.width),u.anchor.y=-(n.y/n.height),u.alpha=i,u._bounds=this._bounds,this._cacheData.sprite=u,this.transform._parentID=-1,this.parent?this.updateTransform():(this.enableTempParent(),this.updateTransform(),this.disableTempParent(null)),this.containsPoint=u.containsPoint.bind(u)}};jI.prototype._renderCachedCanvas=function(g){!this.visible||this.worldAlpha<=0||!this.renderable||(this._initCachedDisplayObjectCanvas(g),this._cacheData.sprite.worldAlpha=this.worldAlpha,this._cacheData.sprite._renderCanvas(g))};jI.prototype._initCachedDisplayObjectCanvas=function(g){if(!(this._cacheData&&this._cacheData.sprite)){var I=this.getLocalBounds(null,!0),i=this.alpha;this.alpha=1;var n=g.context,C=g._projTransform;I.ceil(yt.RESOLUTION);var r=Ws.create({width:I.width,height:I.height}),o="cacheAsBitmap_"+kc();this._cacheData.textureCacheId=o,yg.addToCache(r.baseTexture,o),eg.addToCache(r,o);var A=ofe;this.transform.localTransform.copyTo(A),A.invert(),A.tx-=I.x,A.ty-=I.y,this.renderCanvas=this._cacheData.originalRenderCanvas,g.render(this,{renderTexture:r,clear:!0,transform:A,skipUpdateTransform:!1}),g.context=n,g._projTransform=C,this.renderCanvas=this._renderCachedCanvas,this.updateTransform=this.displayObjectUpdateTransform,this.calculateBounds=this._calculateCachedBounds,this.getLocalBounds=this._getCachedLocalBounds,this._mask=null,this.filterArea=null,this.alpha=i;var s=new h0(r);s.transform.worldTransform=this.transform.worldTransform,s.anchor.x=-(I.x/I.width),s.anchor.y=-(I.y/I.height),s.alpha=i,s._bounds=this._bounds,this._cacheData.sprite=s,this.transform._parentID=-1,this.parent?this.updateTransform():(this.parent=g._tempDisplayObjectParent,this.updateTransform(),this.parent=null),this.containsPoint=s.containsPoint.bind(s)}};jI.prototype._calculateCachedBounds=function(){this._bounds.clear(),this._cacheData.sprite.transform._worldID=this.transform._worldID,this._cacheData.sprite._calculateBounds(),this._bounds.updateID=this._boundsID};jI.prototype._getCachedLocalBounds=function(){return this._cacheData.sprite.getLocalBounds(null)};jI.prototype._destroyCachedDisplayObject=function(){this._cacheData.sprite._texture.destroy(!0),this._cacheData.sprite=null,yg.removeFromCache(this._cacheData.textureCacheId),eg.removeFromCache(this._cacheData.textureCacheId),this._cacheData.textureCacheId=null};jI.prototype._cacheAsBitmapDestroy=function(g){this.cacheAsBitmap=!1,this.destroy(g)};/*! + * @pixi/mixin-get-child-by-name - v6.5.10 + * Compiled Thu, 06 Jul 2023 15:25:11 UTC + * + * @pixi/mixin-get-child-by-name is licensed under the MIT License. + * http://www.opensource.org/licenses/mit-license + */jI.prototype.name=null;CA.prototype.getChildByName=function(g,I){for(var i=0,n=this.children.length;i0){var d=s.x-I[c].x,h=s.y-I[c].y,m=Math.sqrt(d*d+h*h);s=I[c],A+=m/a}else A=c/(l-1);r[u]=A,r[u+1]=0,r[u+2]=A,r[u+3]=1}for(var f=0,c=0;c0?this.textureScale*this._width/2:this._width/2;C/=c,r/=c,C*=u,r*=u,o[l]=a.x+C,o[l+1]=a.y+r,o[l+2]=a.x-C,o[l+3]=a.y-r,i=a}this.buffers[0].update()}},g.prototype.update=function(){this.textureScale>0?this.build():this.updateVertices()},g}(oS),$ze=function(e){m0(g,e);function g(I,i,n){n===void 0&&(n=0);var C=this,r=new lfe(I.height,i,n),o=new nb(I);return n>0&&(I.baseTexture.wrapMode=$o.REPEAT),C=e.call(this,r,o)||this,C.autoUpdate=!0,C}return g.prototype._render=function(I){var i=this.geometry;(this.autoUpdate||i._width!==this.shader.texture.height)&&(i._width=this.shader.texture.height,i.update()),e.prototype._render.call(this,I)},g}(ib),cfe=function(e){m0(g,e);function g(I,i,n){var C=this,r=new sfe(I.width,I.height,i,n),o=new nb(eg.WHITE);return C=e.call(this,r,o)||this,C.texture=I,C.autoResize=!0,C}return g.prototype.textureUpdated=function(){this._textureID=this.shader.texture._updateID;var I=this.geometry,i=this.shader.texture,n=i.width,C=i.height;this.autoResize&&(I.width!==n||I.height!==C)&&(I.width=this.shader.texture.width,I.height=this.shader.texture.height,I.build())},Object.defineProperty(g.prototype,"texture",{get:function(){return this.shader.texture},set:function(I){this.shader.texture!==I&&(this.shader.texture=I,this._textureID=-1,I.baseTexture.valid?this.textureUpdated():I.once("update",this.textureUpdated,this))},enumerable:!1,configurable:!0}),g.prototype._render=function(I){this._textureID!==this.shader.texture._updateID&&this.textureUpdated(),e.prototype._render.call(this,I)},g.prototype.destroy=function(I){this.shader.texture.off("update",this.textureUpdated,this),e.prototype.destroy.call(this,I)},g}(ib),qze=function(e){m0(g,e);function g(I,i,n,C,r){I===void 0&&(I=eg.EMPTY);var o=this,A=new oS(i,n,C);A.getBuffer("aVertexPosition").static=!1;var s=new nb(I);return o=e.call(this,A,s,null,r)||this,o.autoUpdate=!0,o}return Object.defineProperty(g.prototype,"vertices",{get:function(){return this.geometry.getBuffer("aVertexPosition").data},set:function(I){this.geometry.getBuffer("aVertexPosition").data=I},enumerable:!1,configurable:!0}),g.prototype._render=function(I){this.autoUpdate&&this.geometry.getBuffer("aVertexPosition").update(),e.prototype._render.call(this,I)},g}(ib),fV=10,ePe=function(e){m0(g,e);function g(I,i,n,C,r){i===void 0&&(i=fV),n===void 0&&(n=fV),C===void 0&&(C=fV),r===void 0&&(r=fV);var o=e.call(this,eg.WHITE,4,4)||this;return o._origWidth=I.orig.width,o._origHeight=I.orig.height,o._width=o._origWidth,o._height=o._origHeight,o._leftWidth=i,o._rightWidth=C,o._topHeight=n,o._bottomHeight=r,o.texture=I,o}return g.prototype.textureUpdated=function(){this._textureID=this.shader.texture._updateID,this._refresh()},Object.defineProperty(g.prototype,"vertices",{get:function(){return this.geometry.getBuffer("aVertexPosition").data},set:function(I){this.geometry.getBuffer("aVertexPosition").data=I},enumerable:!1,configurable:!0}),g.prototype.updateHorizontalVertices=function(){var I=this.vertices,i=this._getMinScale();I[9]=I[11]=I[13]=I[15]=this._topHeight*i,I[17]=I[19]=I[21]=I[23]=this._height-this._bottomHeight*i,I[25]=I[27]=I[29]=I[31]=this._height},g.prototype.updateVerticalVertices=function(){var I=this.vertices,i=this._getMinScale();I[2]=I[10]=I[18]=I[26]=this._leftWidth*i,I[4]=I[12]=I[20]=I[28]=this._width-this._rightWidth*i,I[6]=I[14]=I[22]=I[30]=this._width},g.prototype._getMinScale=function(){var I=this._leftWidth+this._rightWidth,i=this._width>I?1:this._width/I,n=this._topHeight+this._bottomHeight,C=this._height>n?1:this._height/n,r=Math.min(i,C);return r},Object.defineProperty(g.prototype,"width",{get:function(){return this._width},set:function(I){this._width=I,this._refresh()},enumerable:!1,configurable:!0}),Object.defineProperty(g.prototype,"height",{get:function(){return this._height},set:function(I){this._height=I,this._refresh()},enumerable:!1,configurable:!0}),Object.defineProperty(g.prototype,"leftWidth",{get:function(){return this._leftWidth},set:function(I){this._leftWidth=I,this._refresh()},enumerable:!1,configurable:!0}),Object.defineProperty(g.prototype,"rightWidth",{get:function(){return this._rightWidth},set:function(I){this._rightWidth=I,this._refresh()},enumerable:!1,configurable:!0}),Object.defineProperty(g.prototype,"topHeight",{get:function(){return this._topHeight},set:function(I){this._topHeight=I,this._refresh()},enumerable:!1,configurable:!0}),Object.defineProperty(g.prototype,"bottomHeight",{get:function(){return this._bottomHeight},set:function(I){this._bottomHeight=I,this._refresh()},enumerable:!1,configurable:!0}),g.prototype._refresh=function(){var I=this.texture,i=this.geometry.buffers[1].data;this._origWidth=I.orig.width,this._origHeight=I.orig.height;var n=1/this._origWidth,C=1/this._origHeight;i[0]=i[8]=i[16]=i[24]=0,i[1]=i[3]=i[5]=i[7]=0,i[6]=i[14]=i[22]=i[30]=1,i[25]=i[27]=i[29]=i[31]=1,i[2]=i[10]=i[18]=i[26]=n*this._leftWidth,i[4]=i[12]=i[20]=i[28]=1-n*this._rightWidth,i[9]=i[11]=i[13]=i[15]=C*this._topHeight,i[17]=i[19]=i[21]=i[23]=1-C*this._bottomHeight,this.updateHorizontalVertices(),this.updateVerticalVertices(),this.geometry.buffers[0].update(),this.geometry.buffers[1].update()},g}(cfe);/*! + * @pixi/sprite-animated - v6.5.10 + * Compiled Thu, 06 Jul 2023 15:25:11 UTC + * + * @pixi/sprite-animated is licensed under the MIT License. + * http://www.opensource.org/licenses/mit-license + *//*! ***************************************************************************** +Copyright (c) Microsoft Corporation. + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +PERFORMANCE OF THIS SOFTWARE. +***************************************************************************** */var AM=function(e,g){return AM=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(I,i){I.__proto__=i}||function(I,i){for(var n in i)i.hasOwnProperty(n)&&(I[n]=i[n])},AM(e,g)};function tPe(e,g){AM(e,g);function I(){this.constructor=e}e.prototype=g===null?Object.create(g):(I.prototype=g.prototype,new I)}var gPe=function(e){tPe(g,e);function g(I,i){i===void 0&&(i=!0);var n=e.call(this,I[0]instanceof eg?I[0]:I[0].texture)||this;return n._textures=null,n._durations=null,n._autoUpdate=i,n._isConnectedToTicker=!1,n.animationSpeed=1,n.loop=!0,n.updateAnchor=!1,n.onComplete=null,n.onFrameChange=null,n.onLoop=null,n._currentTime=0,n._playing=!1,n._previousFrame=null,n.textures=I,n}return g.prototype.stop=function(){this._playing&&(this._playing=!1,this._autoUpdate&&this._isConnectedToTicker&&(Pi.shared.remove(this.update,this),this._isConnectedToTicker=!1))},g.prototype.play=function(){this._playing||(this._playing=!0,this._autoUpdate&&!this._isConnectedToTicker&&(Pi.shared.add(this.update,this,sa.HIGH),this._isConnectedToTicker=!0))},g.prototype.gotoAndStop=function(I){this.stop();var i=this.currentFrame;this._currentTime=I,i!==this.currentFrame&&this.updateTexture()},g.prototype.gotoAndPlay=function(I){var i=this.currentFrame;this._currentTime=I,i!==this.currentFrame&&this.updateTexture(),this.play()},g.prototype.update=function(I){if(this._playing){var i=this.animationSpeed*I,n=this.currentFrame;if(this._durations!==null){var C=this._currentTime%1*this._durations[this.currentFrame];for(C+=i/60*1e3;C<0;)this._currentTime--,C+=this._durations[this.currentFrame];var r=Math.sign(this.animationSpeed*I);for(this._currentTime=Math.floor(this._currentTime);C>=this._durations[this.currentFrame];)C-=this._durations[this.currentFrame]*r,this._currentTime+=r;this._currentTime+=C/this._durations[this.currentFrame]}else this._currentTime+=i;this._currentTime<0&&!this.loop?(this.gotoAndStop(0),this.onComplete&&this.onComplete()):this._currentTime>=this._textures.length&&!this.loop?(this.gotoAndStop(this._textures.length-1),this.onComplete&&this.onComplete()):n!==this.currentFrame&&(this.loop&&this.onLoop&&(this.animationSpeed>0&&this.currentFramen&&this.onLoop()),this.updateTexture())}},g.prototype.updateTexture=function(){var I=this.currentFrame;this._previousFrame!==I&&(this._previousFrame=I,this._texture=this._textures[I],this._textureID=-1,this._textureTrimmedID=-1,this._cachedTint=16777215,this.uvs=this._texture._uvs.uvsFloat32,this.updateAnchor&&this._anchor.copyFrom(this._texture.defaultAnchor),this.onFrameChange&&this.onFrameChange(this.currentFrame))},g.prototype.destroy=function(I){this.stop(),e.prototype.destroy.call(this,I),this.onComplete=null,this.onFrameChange=null,this.onLoop=null},g.fromFrames=function(I){for(var i=[],n=0;n>8&15|g>>4&240,g>>4&15|g&240,(g&15)<<4|g&15,1):I===8?pV(g>>24&255,g>>16&255,g>>8&255,(g&255)/255):I===4?pV(g>>12&15|g>>8&240,g>>8&15|g>>4&240,g>>4&15|g&240,((g&15)<<4|g&15)/255):null):(g=nPe.exec(e))?new $n(g[1],g[2],g[3],1):(g=CPe.exec(e))?new $n(g[1]*255/100,g[2]*255/100,g[3]*255/100,1):(g=rPe.exec(e))?pV(g[1],g[2],g[3],g[4]):(g=oPe.exec(e))?pV(g[1]*255/100,g[2]*255/100,g[3]*255/100,g[4]):(g=APe.exec(e))?_q(g[1],g[2]/100,g[3]/100,1):(g=aPe.exec(e))?_q(g[1],g[2]/100,g[3]/100,g[4]):Eq.hasOwnProperty(e)?Pq(Eq[e]):e==="transparent"?new $n(NaN,NaN,NaN,0):null}function Pq(e){return new $n(e>>16&255,e>>8&255,e&255,1)}function pV(e,g,I,i){return i<=0&&(e=g=I=NaN),new $n(e,g,I,i)}function dfe(e){return e instanceof f0||(e=Md(e)),e?(e=e.rgb(),new $n(e.r,e.g,e.b,e.opacity)):new $n}function nX(e,g,I,i){return arguments.length===1?dfe(e):new $n(e,g,I,i??1)}function $n(e,g,I,i){this.r=+e,this.g=+g,this.b=+I,this.opacity=+i}jH($n,nX,JL(f0,{brighter:function(e){return e=e==null?Cb:Math.pow(Cb,e),new $n(this.r*e,this.g*e,this.b*e,this.opacity)},darker:function(e){return e=e==null?Ed:Math.pow(Ed,e),new $n(this.r*e,this.g*e,this.b*e,this.opacity)},rgb:function(){return this},displayable:function(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:Jq,formatHex:Jq,formatRgb:Oq,toString:Oq}));function Jq(){return"#"+pK(this.r)+pK(this.g)+pK(this.b)}function Oq(){var e=this.opacity;return e=isNaN(e)?1:Math.max(0,Math.min(1,e)),(e===1?"rgb(":"rgba(")+Math.max(0,Math.min(255,Math.round(this.r)||0))+", "+Math.max(0,Math.min(255,Math.round(this.g)||0))+", "+Math.max(0,Math.min(255,Math.round(this.b)||0))+(e===1?")":", "+e+")")}function pK(e){return e=Math.max(0,Math.min(255,Math.round(e)||0)),(e<16?"0":"")+e.toString(16)}function _q(e,g,I,i){return i<=0?e=g=I=NaN:I<=0||I>=1?e=g=NaN:g<=0&&(e=NaN),new KA(e,g,I,i)}function hfe(e){if(e instanceof KA)return new KA(e.h,e.s,e.l,e.opacity);if(e instanceof f0||(e=Md(e)),!e)return new KA;if(e instanceof KA)return e;e=e.rgb();var g=e.r/255,I=e.g/255,i=e.b/255,n=Math.min(g,I,i),C=Math.max(g,I,i),r=NaN,o=C-n,A=(C+n)/2;return o?(g===C?r=(I-i)/o+(I0&&A<1?0:r,new KA(r,o,A,e.opacity)}function lPe(e,g,I,i){return arguments.length===1?hfe(e):new KA(e,g,I,i??1)}function KA(e,g,I,i){this.h=+e,this.s=+g,this.l=+I,this.opacity=+i}jH(KA,lPe,JL(f0,{brighter:function(e){return e=e==null?Cb:Math.pow(Cb,e),new KA(this.h,this.s,this.l*e,this.opacity)},darker:function(e){return e=e==null?Ed:Math.pow(Ed,e),new KA(this.h,this.s,this.l*e,this.opacity)},rgb:function(){var e=this.h%360+(this.h<0)*360,g=isNaN(e)||isNaN(this.s)?0:this.s,I=this.l,i=I+(I<.5?I:1-I)*g,n=2*I-i;return new $n(bK(e>=240?e-240:e+120,n,i),bK(e,n,i),bK(e<120?e+240:e-120,n,i),this.opacity)},displayable:function(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl:function(){var e=this.opacity;return e=isNaN(e)?1:Math.max(0,Math.min(1,e)),(e===1?"hsl(":"hsla(")+(this.h||0)+", "+(this.s||0)*100+"%, "+(this.l||0)*100+"%"+(e===1?")":", "+e+")")}}));function bK(e,g,I){return(e<60?g+(I-g)*e/60:e<180?I:e<240?g+(I-g)*(240-e)/60:g)*255}const cPe=Math.PI/180,uPe=180/Math.PI;var mfe=-.14861,OL=1.78277,_L=-.29227,$H=-.90649,tB=1.97294,Lq=tB*$H,Uq=tB*OL,Qq=OL*_L-$H*mfe;function dPe(e){if(e instanceof fd)return new fd(e.h,e.s,e.l,e.opacity);e instanceof $n||(e=dfe(e));var g=e.r/255,I=e.g/255,i=e.b/255,n=(Qq*i+Lq*g-Uq*I)/(Qq+Lq-Uq),C=i-n,r=(tB*(I-n)-_L*C)/$H,o=Math.sqrt(r*r+C*C)/(tB*n*(1-n)),A=o?Math.atan2(r,C)*uPe-120:NaN;return new fd(A<0?A+360:A,o,n,e.opacity)}function Yc(e,g,I,i){return arguments.length===1?dPe(e):new fd(e,g,I,i??1)}function fd(e,g,I,i){this.h=+e,this.s=+g,this.l=+I,this.opacity=+i}jH(fd,Yc,JL(f0,{brighter:function(e){return e=e==null?Cb:Math.pow(Cb,e),new fd(this.h,this.s,this.l*e,this.opacity)},darker:function(e){return e=e==null?Ed:Math.pow(Ed,e),new fd(this.h,this.s,this.l*e,this.opacity)},rgb:function(){var e=isNaN(this.h)?0:(this.h+120)*cPe,g=+this.l,I=isNaN(this.s)?0:this.s*g*(1-g),i=Math.cos(e),n=Math.sin(e);return new $n(255*(g+I*(mfe*i+OL*n)),255*(g+I*(_L*i+$H*n)),255*(g+I*(tB*i)),this.opacity)}}));function ffe(e,g){return eg?1:e>=g?0:NaN}function LL(e){let g=e,I=e;e.length===1&&(g=(r,o)=>e(r)-o,I=hPe(e));function i(r,o,A,s){for(A==null&&(A=0),s==null&&(s=r.length);A>>1;I(r[a],o)<0?A=a+1:s=a}return A}function n(r,o,A,s){for(A==null&&(A=0),s==null&&(s=r.length);A>>1;I(r[a],o)>0?s=a:A=a+1}return A}function C(r,o,A,s){A==null&&(A=0),s==null&&(s=r.length);const a=i(r,o,A,s-1);return a>A&&g(r[a-1],o)>-g(r[a],o)?a-1:a}return{left:i,center:C,right:n}}function hPe(e){return(g,I)=>ffe(e(g),I)}function mPe(e){return e===null?NaN:+e}const fPe=LL(ffe),pPe=fPe.right;LL(mPe).center;const bPe=pPe;let yPe=class extends Map{constructor(g,I=vPe){if(super(),Object.defineProperties(this,{_intern:{value:new Map},_key:{value:I}}),g!=null)for(const[i,n]of g)this.set(i,n)}get(g){return super.get(jq(this,g))}has(g){return super.has(jq(this,g))}set(g,I){return super.set(ZPe(this,g),I)}delete(g){return super.delete(GPe(this,g))}};function jq({_intern:e,_key:g},I){const i=g(I);return e.has(i)?e.get(i):I}function ZPe({_intern:e,_key:g},I){const i=g(I);return e.has(i)?e.get(i):(e.set(i,I),I)}function GPe({_intern:e,_key:g},I){const i=g(I);return e.has(i)&&(I=e.get(I),e.delete(i)),I}function vPe(e){return e!==null&&typeof e=="object"?e.valueOf():e}function $q(e){return e}function qH(e,...g){return BPe(e,$q,$q,g)}function BPe(e,g,I,i){return function n(C,r){if(r>=i.length)return I(C);const o=new yPe,A=i[r++];let s=-1;for(const a of C){const l=A(a,++s,C),c=o.get(l);c?c.push(a):o.set(l,[a])}for(const[a,l]of o)o.set(a,n(l,r));return g(o)}(e,0)}var aM=Math.sqrt(50),sM=Math.sqrt(10),lM=Math.sqrt(2);function SPe(e,g,I){var i,n=-1,C,r,o;if(g=+g,e=+e,I=+I,e===g&&I>0)return[e];if((i=g0){let A=Math.round(e/o),s=Math.round(g/o);for(A*og&&--s,r=new Array(C=s-A+1);++ng&&--s,r=new Array(C=s-A+1);++n=0?(C>=aM?10:C>=sM?5:C>=lM?2:1)*Math.pow(10,n):-Math.pow(10,-n)/(C>=aM?10:C>=sM?5:C>=lM?2:1)}function wPe(e,g,I){var i=Math.abs(g-e)/Math.max(0,I),n=Math.pow(10,Math.floor(Math.log(i)/Math.LN10)),C=i/n;return C>=aM?n*=10:C>=sM?n*=5:C>=lM&&(n*=2),g=i)&&(I=i);else{let i=-1;for(let n of e)(n=g(n,++i,e))!=null&&(I=n)&&(I=n)}return I}function A1(e,g){let I;if(g===void 0)for(const i of e)i!=null&&(I>i||I===void 0&&i>=i)&&(I=i);else{let i=-1;for(let n of e)(n=g(n,++i,e))!=null&&(I>n||I===void 0&&n>=n)&&(I=n)}return I}function VPe(e,g,I){e=+e,g=+g,I=(n=arguments.length)<2?(g=e,e=0,1):n<3?1:+I;for(var i=-1,n=Math.max(0,Math.ceil((g-e)/I))|0,C=new Array(n);++i1;){for(let o=0;o1;n--,C--){const r=[];for(let o=0,A;o"u")e=.5;else if(e===0||e===1)return e;const I=Gr(e,g)+Gr(1-e,g),i=I-1;return vy(i/I)},projectionratio:function(e,g){if(g!==2&&g!==3)return!1;if(typeof e>"u")e=.5;else if(e===0||e===1)return e;const I=Gr(1-e,g),i=Gr(e,g)+I;return I/i},lli8:function(e,g,I,i,n,C,r,o){const A=(e*i-g*I)*(n-r)-(e-I)*(n*o-C*r),s=(e*i-g*I)*(C-o)-(g-i)*(n*o-C*r),a=(e-I)*(C-o)-(g-i)*(n-r);return a==0?!1:{x:A/a,y:s/a}},lli4:function(e,g,I,i){const n=e.x,C=e.y,r=g.x,o=g.y,A=I.x,s=I.y,a=i.x,l=i.y;return dt.lli8(n,C,r,o,A,s,a,l)},lli:function(e,g){return dt.lli4(e,e.c,g,g.c)},makeline:function(e,g){const I=e.x,i=e.y,n=g.x,C=g.y,r=(n-I)/3,o=(C-i)/3;return new ti(I,i,I+r,i+o,I+2*r,i+2*o,n,C)},findbbox:function(e){let g=yK,I=yK,i=ZK,n=ZK;return e.forEach(function(C){const r=C.bbox();g>r.x.min&&(g=r.x.min),I>r.y.min&&(I=r.y.min),i0&&(a.c1=A,a.c2=s,a.s1=e,a.s2=I,C.push(a))})}),C},makeshape:function(e,g,I){const i=g.points.length,n=e.points.length,C=dt.makeline(g.points[i-1],e.points[0]),r=dt.makeline(e.points[n-1],g.points[0]),o={startcap:C,forward:e,back:g,endcap:r,bbox:dt.findbbox([C,e,g,r])};return o.intersections=function(A){return dt.shapeintersections(o,o.bbox,A,A.bbox,I)},o},getminmax:function(e,g,I){if(!I)return{min:0,max:0};let i=yK,n=ZK,C,r;I.indexOf(0)===-1&&(I=[0].concat(I)),I.indexOf(1)===-1&&I.push(1);for(let o=0,A=I.length;on&&(n=r[g]);return{min:i,mid:(i+n)/2,max:n,size:n-i}},align:function(e,g){const I=g.p1.x,i=g.p1.y,n=-By(g.p2.y-i,g.p2.x-I),C=function(r){return{x:(r.x-I)*Ta(n)-(r.y-i)*vm(n),y:(r.x-I)*vm(n)+(r.y-i)*Ta(n)}};return e.map(C)},roots:function(e,g){g=g||{p1:{x:0,y:0},p2:{x:1,y:0}};const I=e.length-1,i=dt.align(e,g),n=function(G){return 0<=G&&G<=1};if(I===2){const G=i[0].y,v=i[1].y,w=i[2].y,V=G-2*v+w;if(V!==0){const S=-al(v*v-G*w),X=-G+v,W=-(S+X)/V,R=-(-S+X)/V;return[W,R].filter(n)}else if(v!==w&&V===0)return[(2*v-w)/(2*v-2*w)].filter(n);return[]}const C=i[0].y,r=i[1].y,o=i[2].y,A=i[3].y;let s=-C+3*r-3*o+A,a=3*C-6*r+3*o,l=-3*C+3*r,c=C;if(dt.approximately(s,0)){if(dt.approximately(a,0))return dt.approximately(l,0)?[]:[-c/l].filter(n);const G=al(l*l-4*a*c),v=2*a;return[(G-l)/v,(-l-G)/v].filter(n)}a/=s,l/=s,c/=s;const u=(3*l-a*a)/3,d=u/3,h=(2*a*a*a-9*a*l+27*c)/27,m=h/2,f=m*m+d*d*d;let b,p,y,Z,B;if(f<0){const G=-u/3,v=G*G*G,w=al(v),V=-h/(2*w),S=V<-1?-1:V>1?1:V,X=RPe(S),W=Sy(w),R=2*W;return y=R*Ta(X/3)-a/3,Z=R*Ta((X+bV)/3)-a/3,B=R*Ta((X+2*bV)/3)-a/3,[y,Z,B].filter(n)}else{if(f===0)return b=m<0?Sy(-m):-Sy(m),y=2*b-a/3,Z=-b-a/3,[y,Z].filter(n);{const G=al(f);return b=Sy(-m+G),p=Sy(m+G),[b-p-a/3].filter(n)}}},droots:function(e){if(e.length===3){const g=e[0],I=e[1],i=e[2],n=g-2*I+i;if(n!==0){const C=-al(I*I-g*i),r=-g+I,o=-(C+r)/n,A=-(-C+r)/n;return[o,A]}else if(I!==i&&n===0)return[(2*I-i)/(2*(I-i))];return[]}if(e.length===2){const g=e[0],I=e[1];return g!==I?[g/(g-I)]:[]}return[]},curvature:function(e,g,I,i,n){let C,r,o,A,s=0,a=0;const l=dt.compute(e,g),c=dt.compute(e,I),u=l.x*l.x+l.y*l.y;if(i?(C=al(Gr(l.y*c.z-c.y*l.z,2)+Gr(l.z*c.x-c.z*l.x,2)+Gr(l.x*c.y-c.x*l.y,2)),r=Gr(u+l.z*l.z,3/2)):(C=l.x*c.y-l.y*c.x,r=Gr(u,3/2)),C===0||r===0)return{k:0,r:0};if(s=C/r,a=r/C,!n){const d=dt.curvature(e-.001,g,I,i,!0).k,h=dt.curvature(e+.001,g,I,i,!0).k;A=(h-s+(s-d))/2,o=(vy(h-s)+vy(s-d))/2}return{k:s,r:a,dk:A,adk:o}},inflections:function(e){if(e.length<4)return[];const g=dt.align(e,{p1:e[0],p2:e.slice(-1)[0]}),I=g[2].x*g[1].y,i=g[3].x*g[1].y,n=g[1].x*g[2].y,C=g[3].x*g[2].y,r=18*(-3*I+2*i+3*n-C),o=18*(3*I-i-3*n),A=18*(n-I);if(dt.approximately(r,0)){if(!dt.approximately(o,0)){let c=-A/o;if(0<=c&&c<=1)return[c]}return[]}const s=o*o-4*r*A,a=Math.sqrt(s),l=2*r;return dt.approximately(l,0)?[]:[(a-o)/l,-(o+a)/l].filter(function(c){return 0<=c&&c<=1})},bboxoverlap:function(e,g){const I=["x","y"],i=I.length;for(let n=0,C,r,o,A;n=A)return!1;return!0},expandbox:function(e,g){g.x.mine.x.max&&(e.x.max=g.x.max),g.y.max>e.y.max&&(e.y.max=g.y.max),g.z&&g.z.max>e.z.max&&(e.z.max=g.z.max),e.x.mid=(e.x.min+e.x.max)/2,e.y.mid=(e.y.min+e.y.max)/2,e.z&&(e.z.mid=(e.z.min+e.z.max)/2),e.x.size=e.x.max-e.x.min,e.y.size=e.y.max-e.y.min,e.z&&(e.z.size=e.z.max-e.z.min)},pairiteration:function(e,g,I){const i=e.bbox(),n=g.bbox(),C=1e5,r=I||.5;if(i.x.size+i.y.sizeB||B>G)&&(Z+=bV),Z>G&&(v=G,G=Z,Z=v)):G4){if(arguments.length!==1)throw new Error("Only new Bezier(point[]) is accepted for 4th and higher order curves");n=!0}}else if(C!==6&&C!==8&&C!==9&&C!==12&&arguments.length!==1)throw new Error("Only new Bezier(point[]) is accepted for 4th and higher order curves");const r=this._3d=!n&&(C===9||C===12)||g&&g[0]&&typeof g[0].z<"u",o=this.points=[];for(let c=0,u=r?3:2;cwy(c.y)>1e-4),this._lut=[],this._t1=0,this._t2=1,this.update()}static quadraticFromPoints(g,I,i,n){if(typeof n>"u"&&(n=.5),n===0)return new ti(I,I,i);if(n===1)return new ti(g,I,I);const C=ti.getABC(2,g,I,i,n);return new ti(g,C.A,i)}static cubicFromPoints(g,I,i,n,C){typeof n>"u"&&(n=.5);const r=ti.getABC(3,g,I,i,n);typeof C>"u"&&(C=dt.dist(I,r.C));const o=C*(1-n)/n,A=dt.dist(g,i),s=(i.x-g.x)/A,a=(i.y-g.y)/A,l=C*s,c=C*a,u=o*s,d=o*a,h={x:I.x-l,y:I.y-c},m={x:I.x+u,y:I.y+d},f=r.A,b={x:f.x+(h.x-f.x)/(1-n),y:f.y+(h.y-f.y)/(1-n)},p={x:f.x+(m.x-f.x)/n,y:f.y+(m.y-f.y)/n},y={x:g.x+(b.x-g.x)/n,y:g.y+(b.y-g.y)/n},Z={x:i.x+(p.x-i.x)/(1-n),y:i.y+(p.y-i.y)/(1-n)};return new ti(g,y,Z,i)}static getUtils(){return dt}getUtils(){return ti.getUtils()}static get PolyBezier(){return CX}valueOf(){return this.toString()}toString(){return dt.pointsToString(this.points)}toSVG(){if(this._3d)return!1;const g=this.points,I=g[0].x,i=g[0].y,n=["M",I,i,this.order===2?"Q":"C"];for(let C=1,r=g.length;C0}length(){return dt.length(this.derivative.bind(this))}static getABC(g=2,I,i,n,C=.5){const r=dt.projectionratio(C,g),o=1-r,A={x:r*I.x+o*n.x,y:r*I.y+o*n.y},s=dt.abcratio(C,g);return{A:{x:i.x+(i.x-A.x)/s,y:i.y+(i.y-A.y)/s},B:i,C:A,S:I,E:n}}getABC(g,I){I=I||this.get(g);let i=this.points[0],n=this.points[this.order];return ti.getABC(this.order,i,I,n,g)}getLUT(g){if(this.verify(),g=g||100,this._lut.length===g)return this._lut;this._lut=[],g--;for(let I=0,i,n;I1?1:l,c=this.compute(l),c.t=l,c.d=s,c}get(g){return this.compute(g)}point(g){return this.points[g]}compute(g){return this.ratios?dt.computeWithRatios(g,this.points,this.ratios,this._3d):dt.compute(g,this.points,this._3d,this.ratios)}raise(){const g=this.points,I=[g[0]],i=g.length;for(let n=1,C,r;n1;){i=[];for(let r=0,o,A=I.length-1;r=0&&r<=1}),I=I.concat(g[i].sort(dt.numberSort))}).bind(this)),g.values=I.sort(dt.numberSort).filter(function(i,n){return I.indexOf(i)===n}),g}bbox(){const g=this.extrema(),I={};return this.dims.forEach((function(i){I[i]=dt.getminmax(this,i,g[i])}).bind(this)),I}overlaps(g){const I=this.bbox(),i=g.bbox();return dt.bboxoverlap(I,i)}offset(g,I){if(typeof I<"u"){const i=this.get(g),n=this.normal(g),C={c:i,n,x:i.x+n.x*I,y:i.y+n.y*I};return this._3d&&(C.z=i.z+n.z*I),C}if(this._linear){const i=this.normal(0),n=this.points.map(function(C){const r={x:C.x+g*i.x,y:C.y+g*i.y};return C.z&&i.z&&(r.z=C.z+g*i.z),r});return[new ti(n)]}return this.reduce().map(function(i){return i._linear?i.offset(g)[0]:i.scale(g)})}simple(){if(this.order===3){const n=dt.angle(this.points[0],this.points[3],this.points[1]),C=dt.angle(this.points[0],this.points[3],this.points[2]);if(n>0&&C<0||n<0&&C>0)return!1}const g=this.normal(0),I=this.normal(1);let i=g.x*I.x+g.y*I.y;return this._3d&&(i+=g.z*I.z),wy(NPe(i)){if(I===2&&l)return;const c=s[l*I],u=this.derivative(l),d={x:c.x+u.x,y:c.y+u.y};s[l+1]=dt.lli4(c,d,a,A[l+1])}),new ti(s))}outline(g,I,i,n){I=typeof I>"u"?g:I;const C=this.reduce(),r=C.length,o=[];let A=[],s,a=0,l=this.length();const c=typeof i<"u"&&typeof n<"u";function u(Z,B,G,v,w){return function(V){const S=v/G,X=(v+w)/G,W=B-Z;return dt.map(V,0,1,Z+S*W,Z+X*W)}}C.forEach(function(Z){const B=Z.length();c?(o.push(Z.scale(u(g,i,l,a,B))),A.push(Z.scale(u(-I,-n,l,a,B)))):(o.push(Z.scale(g)),A.push(Z.scale(-I))),a+=B}),A=A.map(function(Z){return s=Z.points,s[3]?Z.points=[s[3],s[2],s[1],s[0]]:Z.points=[s[2],s[1],s[0]],Z}).reverse();const d=o[0].points[0],h=o[r-1].points[o[r-1].points.length-1],m=A[r-1].points[A[r-1].points.length-1],f=A[0].points[0],b=dt.makeline(m,d),p=dt.makeline(h,f),y=[b].concat(o).concat([p]).concat(A);return y.length,new CX(y)}outlineshapes(g,I,i){I=I||g;const n=this.outline(g,I).curves,C=[];for(let r=1,o=n.length;r1,A.endcap.virtual=r{var o=this.get(r);return dt.between(o.x,I,n)&&dt.between(o.y,i,C)})}selfintersects(g){const I=this.reduce(),i=I.length-2,n=[];for(let C=0,r,o,A;C0&&(C=C.concat(o))}),C}arcs(g){return g=g||.5,this._iterate(g,[])}_error(g,I,i,n){const C=(n-i)/4,r=this.get(i+C),o=this.get(n-C),A=dt.dist(g,I),s=dt.dist(g,r),a=dt.dist(g,o);return wy(s-A)+wy(a-A)}_iterate(g,I){let i=0,n=1,C;do{C=0,n=1;let r=this.get(i),o,A,s,a,l=!1,c=!1,u,d=n,h=1;do if(c=l,a=s,d=(i+n)/2,o=this.get(d),A=this.get(n),s=dt.getccenter(r,o,A),s.interval={start:i,end:n},l=this._error(s,r,i,n)<=g,u=c&&!l,u||(h=n),l){if(n>=1){if(s.interval.end=h=1,a=s,n>1){let f={x:s.x+s.r*HPe(s.e),y:s.y+s.r*TPe(s.e)};s.e+=dt.angle({x:s.x,y:s.y},f,this.get(1))}break}n=n+(n-i)/2}else n=d;while(!u&&C++<100);if(C>=100)break;a=a||s,I.push(a),i=h}while(n<1);return I}}function UL(e,g){switch(arguments.length){case 0:break;case 1:this.range(e);break;default:this.range(g).domain(e);break}return this}function YPe(e,g){switch(arguments.length){case 0:break;case 1:{typeof e=="function"?this.interpolator(e):this.range(e);break}default:{this.domain(e),typeof g=="function"?this.interpolator(g):this.range(g);break}}return this}const gee=Symbol("implicit");function rX(){var e=new Map,g=[],I=[],i=gee;function n(C){var r=C+"",o=e.get(r);if(!o){if(i!==gee)return i;e.set(r,o=g.push(C))}return I[(o-1)%I.length]}return n.domain=function(C){if(!arguments.length)return g.slice();g=[],e=new Map;for(const r of C){const o=r+"";e.has(o)||e.set(o,g.push(r))}return n},n.range=function(C){return arguments.length?(I=Array.from(C),n):I.slice()},n.unknown=function(C){return arguments.length?(i=C,n):i},n.copy=function(){return rX(g,I).unknown(i)},UL.apply(n,arguments),n}function yfe(){var e=rX().unknown(void 0),g=e.domain,I=e.range,i=0,n=1,C,r,o=!1,A=0,s=0,a=.5;delete e.unknown;function l(){var c=g().length,u=n=1?(I=1,g-1):Math.floor(I*g),n=e[i],C=e[i+1],r=i>0?e[i-1]:2*n-C,o=i()=>e;function Zfe(e,g){return function(I){return e+I*g}}function xPe(e,g,I){return e=Math.pow(e,I),g=Math.pow(g,I)-e,I=1/I,function(i){return Math.pow(e+i*g,I)}}function FPe(e,g){var I=g-e;return I?Zfe(e,I>180||I<-180?I-360*Math.round(I/360):I):eT(isNaN(e)?g:e)}function EPe(e){return(e=+e)==1?dp:function(g,I){return I-g?xPe(g,I,e):eT(isNaN(g)?I:g)}}function dp(e,g){var I=g-e;return I?Zfe(e,I):eT(isNaN(e)?g:e)}const Iee=function e(g){var I=EPe(g);function i(n,C){var r=I((n=nX(n)).r,(C=nX(C)).r),o=I(n.g,C.g),A=I(n.b,C.b),s=dp(n.opacity,C.opacity);return function(a){return n.r=r(a),n.g=o(a),n.b=A(a),n.opacity=s(a),n+""}}return i.gamma=e,i}(1);function MPe(e){return function(g){var I=g.length,i=new Array(I),n=new Array(I),C=new Array(I),r,o;for(r=0;rI&&(C=g.slice(I,C),o[r]?o[r]+=C:o[++r]=C),(i=i[0])===(n=n[0])?o[r]?o[r]+=n:o[++r]=n:(o[++r]=null,A.push({i:r,x:oX(i,n)})),I=GK.lastIndex;return Ig&&(I=e,e=g,g=I),function(i){return Math.max(e,Math.min(g,i))}}function tJe(e,g,I){var i=e[0],n=e[1],C=g[0],r=g[1];return n2?gJe:tJe,A=s=null,l}function l(c){return c==null||isNaN(c=+c)?C:(A||(A=o(e.map(i),g,I)))(i(r(c)))}return l.invert=function(c){return r(n((s||(s=o(g,e.map(i),oX)))(c)))},l.domain=function(c){return arguments.length?(e=Array.from(c,qPe),a()):e.slice()},l.range=function(c){return arguments.length?(g=Array.from(c),a()):g.slice()},l.rangeRound=function(c){return g=Array.from(c),I=Gfe,a()},l.clamp=function(c){return arguments.length?(r=c?!0:Ic,a()):r!==Ic},l.interpolate=function(c){return arguments.length?(I=c,a()):I},l.unknown=function(c){return arguments.length?(C=c,l):C},function(c,u){return i=c,n=u,a()}}function nJe(){return iJe()(Ic,Ic)}function CJe(e){return Math.abs(e=Math.round(e))>=1e21?e.toLocaleString("en").replace(/,/g,""):e.toString(10)}function AX(e,g){if((I=(e=g?e.toExponential(g-1):e.toExponential()).indexOf("e"))<0)return null;var I,i=e.slice(0,I);return[i.length>1?i[0]+i.slice(2):i,+e.slice(I+1)]}function rb(e){return e=AX(Math.abs(e)),e?e[1]:NaN}function rJe(e,g){return function(I,i){for(var n=I.length,C=[],r=0,o=e[0],A=0;n>0&&o>0&&(A+o+1>i&&(o=Math.max(1,i-A)),C.push(I.substring(n-=o,n+o)),!((A+=o+1)>i));)o=e[r=(r+1)%e.length];return C.reverse().join(g)}}function oJe(e){return function(g){return g.replace(/[0-9]/g,function(I){return e[+I]})}}var AJe=/^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;function aX(e){if(!(g=AJe.exec(e)))throw new Error("invalid format: "+e);var g;return new QL({fill:g[1],align:g[2],sign:g[3],symbol:g[4],zero:g[5],width:g[6],comma:g[7],precision:g[8]&&g[8].slice(1),trim:g[9],type:g[10]})}aX.prototype=QL.prototype;function QL(e){this.fill=e.fill===void 0?" ":e.fill+"",this.align=e.align===void 0?">":e.align+"",this.sign=e.sign===void 0?"-":e.sign+"",this.symbol=e.symbol===void 0?"":e.symbol+"",this.zero=!!e.zero,this.width=e.width===void 0?void 0:+e.width,this.comma=!!e.comma,this.precision=e.precision===void 0?void 0:+e.precision,this.trim=!!e.trim,this.type=e.type===void 0?"":e.type+""}QL.prototype.toString=function(){return this.fill+this.align+this.sign+this.symbol+(this.zero?"0":"")+(this.width===void 0?"":Math.max(1,this.width|0))+(this.comma?",":"")+(this.precision===void 0?"":"."+Math.max(0,this.precision|0))+(this.trim?"~":"")+this.type};function aJe(e){e:for(var g=e.length,I=1,i=-1,n;I0&&(i=0);break}return i>0?e.slice(0,i)+e.slice(n+1):e}var Sfe;function sJe(e,g){var I=AX(e,g);if(!I)return e+"";var i=I[0],n=I[1],C=n-(Sfe=Math.max(-8,Math.min(8,Math.floor(n/3)))*3)+1,r=i.length;return C===r?i:C>r?i+new Array(C-r+1).join("0"):C>0?i.slice(0,C)+"."+i.slice(C):"0."+new Array(1-C).join("0")+AX(e,Math.max(0,g+C-1))[0]}function nee(e,g){var I=AX(e,g);if(!I)return e+"";var i=I[0],n=I[1];return n<0?"0."+new Array(-n).join("0")+i:i.length>n+1?i.slice(0,n+1)+"."+i.slice(n+1):i+new Array(n-i.length+2).join("0")}const Cee={"%":(e,g)=>(e*100).toFixed(g),b:e=>Math.round(e).toString(2),c:e=>e+"",d:CJe,e:(e,g)=>e.toExponential(g),f:(e,g)=>e.toFixed(g),g:(e,g)=>e.toPrecision(g),o:e=>Math.round(e).toString(8),p:(e,g)=>nee(e*100,g),r:nee,s:sJe,X:e=>Math.round(e).toString(16).toUpperCase(),x:e=>Math.round(e).toString(16)};function ree(e){return e}var oee=Array.prototype.map,Aee=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"];function lJe(e){var g=e.grouping===void 0||e.thousands===void 0?ree:rJe(oee.call(e.grouping,Number),e.thousands+""),I=e.currency===void 0?"":e.currency[0]+"",i=e.currency===void 0?"":e.currency[1]+"",n=e.decimal===void 0?".":e.decimal+"",C=e.numerals===void 0?ree:oJe(oee.call(e.numerals,String)),r=e.percent===void 0?"%":e.percent+"",o=e.minus===void 0?"−":e.minus+"",A=e.nan===void 0?"NaN":e.nan+"";function s(l){l=aX(l);var c=l.fill,u=l.align,d=l.sign,h=l.symbol,m=l.zero,f=l.width,b=l.comma,p=l.precision,y=l.trim,Z=l.type;Z==="n"?(b=!0,Z="g"):Cee[Z]||(p===void 0&&(p=12),y=!0,Z="g"),(m||c==="0"&&u==="=")&&(m=!0,c="0",u="=");var B=h==="$"?I:h==="#"&&/[boxX]/.test(Z)?"0"+Z.toLowerCase():"",G=h==="$"?i:/[%p]/.test(Z)?r:"",v=Cee[Z],w=/[defgprs%]/.test(Z);p=p===void 0?6:/[gprs]/.test(Z)?Math.max(1,Math.min(21,p)):Math.max(0,Math.min(20,p));function V(S){var X=B,W=G,R,H,Y;if(Z==="c")W=v(S)+W,S="";else{S=+S;var D=S<0||1/S<0;if(S=isNaN(S)?A:v(Math.abs(S),p),y&&(S=aJe(S)),D&&+S==0&&d!=="+"&&(D=!1),X=(D?d==="("?d:o:d==="-"||d==="("?"":d)+X,W=(Z==="s"?Aee[8+Sfe/3]:"")+W+(D&&d==="("?")":""),w){for(R=-1,H=S.length;++RY||Y>57){W=(Y===46?n+S.slice(R+1):S.slice(R))+W,S=S.slice(0,R);break}}}b&&!m&&(S=g(S,1/0));var E=X.length+S.length+W.length,O=E>1)+X+S+W+O.slice(E);break;default:S=O+X+S+W;break}return C(S)}return V.toString=function(){return l+""},V}function a(l,c){var u=s((l=aX(l),l.type="f",l)),d=Math.max(-8,Math.min(8,Math.floor(rb(c)/3)))*3,h=Math.pow(10,-d),m=Aee[8+d/3];return function(f){return u(h*f)+m}}return{format:s,formatPrefix:a}}var yV,wfe,Vfe;cJe({thousands:",",grouping:[3],currency:["$",""]});function cJe(e){return yV=lJe(e),wfe=yV.format,Vfe=yV.formatPrefix,yV}function uJe(e){return Math.max(0,-rb(Math.abs(e)))}function dJe(e,g){return Math.max(0,Math.max(-8,Math.min(8,Math.floor(rb(g)/3)))*3-rb(Math.abs(e)))}function hJe(e,g){return e=Math.abs(e),g=Math.abs(g)-e,Math.max(0,rb(g)-rb(e))+1}function mJe(e,g,I,i){var n=wPe(e,g,I),C;switch(i=aX(i??",f"),i.type){case"s":{var r=Math.max(Math.abs(e),Math.abs(g));return i.precision==null&&!isNaN(C=dJe(n,r))&&(i.precision=C),Vfe(i,r)}case"":case"e":case"g":case"p":case"r":{i.precision==null&&!isNaN(C=hJe(n,Math.max(Math.abs(e),Math.abs(g))))&&(i.precision=C-(i.type==="e"));break}case"f":case"%":{i.precision==null&&!isNaN(C=uJe(n))&&(i.precision=C-(i.type==="%")*2);break}}return wfe(i)}function Rfe(e){var g=e.domain;return e.ticks=function(I){var i=g();return SPe(i[0],i[i.length-1],I??10)},e.tickFormat=function(I,i){var n=g();return mJe(n[0],n[n.length-1],I??10,i)},e.nice=function(I){I==null&&(I=10);var i=g(),n=0,C=i.length-1,r=i[n],o=i[C],A,s,a=10;for(o0;){if(s=pfe(r,o,I),s===A)return i[n]=r,i[C]=o,g(i);if(s>0)r=Math.floor(r/s)*s,o=Math.ceil(o/s)*s;else if(s<0)r=Math.ceil(r*s)/s,o=Math.floor(o*s)/s;else break;A=s}return e},e}function zd(){var e=nJe();return e.copy=function(){return IJe(e,zd())},UL.apply(e,arguments),Rfe(e)}function fJe(){var e=0,g=1,I,i,n,C,r=Ic,o=!1,A;function s(l){return l==null||isNaN(l=+l)?A:r(n===0?.5:(l=(C(l)-I)*n,o?Math.max(0,Math.min(1,l)):l))}s.domain=function(l){return arguments.length?([e,g]=l,I=C(e=+e),i=C(g=+g),n=I===i?0:1/(i-I),s):[e,g]},s.clamp=function(l){return arguments.length?(o=!!l,s):o},s.interpolator=function(l){return arguments.length?(r=l,s):r};function a(l){return function(c){var u,d;return arguments.length?([u,d]=c,r=l(u,d),s):[r(0),r(1)]}}return s.range=a(tT),s.rangeRound=a(Gfe),s.unknown=function(l){return arguments.length?(A=l,s):A},function(l){return C=l,I=l(e),i=l(g),n=I===i?0:1/(i-I),s}}function pJe(e,g){return g.domain(e.domain()).interpolator(e.interpolator()).clamp(e.clamp()).unknown(e.unknown())}function Wfe(){var e=Rfe(fJe()(Ic));return e.copy=function(){return pJe(e,Wfe())},YPe.apply(e,arguments)}var bJe=typeof global=="object"&&global&&global.Object===Object&&global;const Xfe=bJe;var yJe=typeof self=="object"&&self&&self.Object===Object&&self,ZJe=Xfe||yJe||Function("return this")();const ya=ZJe;var GJe=ya.Symbol;const ca=GJe;var Hfe=Object.prototype,vJe=Hfe.hasOwnProperty,BJe=Hfe.toString,Ry=ca?ca.toStringTag:void 0;function SJe(e){var g=vJe.call(e,Ry),I=e[Ry];try{e[Ry]=void 0;var i=!0}catch{}var n=BJe.call(e);return i&&(g?e[Ry]=I:delete e[Ry]),n}var wJe=Object.prototype,VJe=wJe.toString;function RJe(e){return VJe.call(e)}var WJe="[object Null]",XJe="[object Undefined]",aee=ca?ca.toStringTag:void 0;function p0(e){return e==null?e===void 0?XJe:WJe:aee&&aee in Object(e)?SJe(e):RJe(e)}function Kc(e){return e!=null&&typeof e=="object"}var HJe="[object Symbol]";function gT(e){return typeof e=="symbol"||Kc(e)&&p0(e)==HJe}function Tfe(e,g){for(var I=-1,i=e==null?0:e.length,n=Array(i);++I-1}var ZOe=9007199254740991,GOe=/^(?:0|[1-9]\d*)$/;function jL(e,g){var I=typeof e;return g=g??ZOe,!!g&&(I=="number"||I!="symbol"&&GOe.test(e))&&e>-1&&e%1==0&&e-1&&e%1==0&&e<=SOe}function qL(e){return e!=null&&$L(e.length)&&!kfe(e)}function wOe(e,g,I){if(!Xs(I))return!1;var i=typeof g;return(i=="number"?qL(I)&&jL(g,I.length):i=="string"&&g in I)?IT(I[g],e):!1}var VOe=Object.prototype;function eU(e){var g=e&&e.constructor,I=typeof g=="function"&&g.prototype||VOe;return e===I}function ROe(e,g){for(var I=-1,i=Array(e);++I-1}function z_e(e,g){var I=this.__data__,i=nT(I,e);return i<0?(++this.size,I.push([e,g])):I[i][1]=g,this}function Ps(e){var g=-1,I=e==null?0:e.length;for(this.clear();++g=g?e:g)),e}function oLe(){this.__data__=new Ps,this.size=0}function ALe(e){var g=this.__data__,I=g.delete(e);return this.size=g.size,I}function aLe(e){return this.__data__.get(e)}function sLe(e){return this.__data__.has(e)}var lLe=200;function cLe(e,g){var I=this.__data__;if(I instanceof Ps){var i=I.__data__;if(!IB||i.lengtho))return!1;var s=C.get(e),a=C.get(g);if(s&&a)return s==g&&a==e;var l=-1,c=!0,u=I&e7e?new nB:void 0;for(C.set(e,g),C.set(g,e);++l=U7e){var s=g?null:L7e(e);if(s)return rU(s);r=!1,n=ipe,A=new nB}else A=g?[]:o;e:for(;++izPe(e[e.length-1]);var $7e=new Array(3).concat("ef8a62f7f7f767a9cf","ca0020f4a58292c5de0571b0","ca0020f4a582f7f7f792c5de0571b0","b2182bef8a62fddbc7d1e5f067a9cf2166ac","b2182bef8a62fddbc7f7f7f7d1e5f067a9cf2166ac","b2182bd6604df4a582fddbc7d1e5f092c5de4393c32166ac","b2182bd6604df4a582fddbc7f7f7f7d1e5f092c5de4393c32166ac","67001fb2182bd6604df4a582fddbc7d1e5f092c5de4393c32166ac053061","67001fb2182bd6604df4a582fddbc7f7f7f7d1e5f092c5de4393c32166ac053061").map(Za);const q7e=b0($7e);var eQe=new Array(3).concat("fc8d59ffffbf99d594","d7191cfdae61abdda42b83ba","d7191cfdae61ffffbfabdda42b83ba","d53e4ffc8d59fee08be6f59899d5943288bd","d53e4ffc8d59fee08bffffbfe6f59899d5943288bd","d53e4ff46d43fdae61fee08be6f598abdda466c2a53288bd","d53e4ff46d43fdae61fee08bffffbfe6f598abdda466c2a53288bd","9e0142d53e4ff46d43fdae61fee08be6f598abdda466c2a53288bd5e4fa2","9e0142d53e4ff46d43fdae61fee08bffffbfe6f598abdda466c2a53288bd5e4fa2").map(Za);const tQe=b0(eQe);var gQe=new Array(3).concat("e0ecf49ebcda8856a7","edf8fbb3cde38c96c688419d","edf8fbb3cde38c96c68856a7810f7c","edf8fbbfd3e69ebcda8c96c68856a7810f7c","edf8fbbfd3e69ebcda8c96c68c6bb188419d6e016b","f7fcfde0ecf4bfd3e69ebcda8c96c68c6bb188419d6e016b","f7fcfde0ecf4bfd3e69ebcda8c96c68c6bb188419d810f7c4d004b").map(Za);const IQe=b0(gQe);var iQe=new Array(3).concat("fde0ddfa9fb5c51b8a","feebe2fbb4b9f768a1ae017e","feebe2fbb4b9f768a1c51b8a7a0177","feebe2fcc5c0fa9fb5f768a1c51b8a7a0177","feebe2fcc5c0fa9fb5f768a1dd3497ae017e7a0177","fff7f3fde0ddfcc5c0fa9fb5f768a1dd3497ae017e7a0177","fff7f3fde0ddfcc5c0fa9fb5f768a1dd3497ae017e7a017749006a").map(Za);const nQe=b0(iQe);var CQe=new Array(3).concat("fff7bcfec44fd95f0e","ffffd4fed98efe9929cc4c02","ffffd4fed98efe9929d95f0e993404","ffffd4fee391fec44ffe9929d95f0e993404","ffffd4fee391fec44ffe9929ec7014cc4c028c2d04","ffffe5fff7bcfee391fec44ffe9929ec7014cc4c028c2d04","ffffe5fff7bcfee391fec44ffe9929ec7014cc4c02993404662506").map(Za);const rQe=b0(CQe);var oQe=new Array(3).concat("f0f0f0bdbdbd636363","f7f7f7cccccc969696525252","f7f7f7cccccc969696636363252525","f7f7f7d9d9d9bdbdbd969696636363252525","f7f7f7d9d9d9bdbdbd969696737373525252252525","fffffff0f0f0d9d9d9bdbdbd969696737373525252252525","fffffff0f0f0d9d9d9bdbdbd969696737373525252252525000000").map(Za);const AQe=b0(oQe);function aQe(e){return e=Math.max(0,Math.min(1,e)),"rgb("+Math.max(0,Math.min(255,Math.round(-4.54-e*(35.34-e*(2381.73-e*(6402.7-e*(7024.72-e*2710.57)))))))+", "+Math.max(0,Math.min(255,Math.round(32.49+e*(170.73+e*(52.82-e*(131.46-e*(176.58-e*67.37)))))))+", "+Math.max(0,Math.min(255,Math.round(81.24+e*(442.36-e*(2482.43-e*(6167.24-e*(6614.94-e*2475.67)))))))+")"}var sQe=Bfe(Yc(-100,.75,.35),Yc(80,1.5,.8));Bfe(Yc(260,.75,.35),Yc(80,1.5,.8));Yc();function AT(e){var g=e.length;return function(I){return e[Math.max(0,Math.min(g-1,Math.floor(I*g)))]}}const ape=AT(Za("44015444025645045745055946075a46085c460a5d460b5e470d60470e6147106347116447136548146748166848176948186a481a6c481b6d481c6e481d6f481f70482071482173482374482475482576482677482878482979472a7a472c7a472d7b472e7c472f7d46307e46327e46337f463480453581453781453882443983443a83443b84433d84433e85423f854240864241864142874144874045884046883f47883f48893e49893e4a893e4c8a3d4d8a3d4e8a3c4f8a3c508b3b518b3b528b3a538b3a548c39558c39568c38588c38598c375a8c375b8d365c8d365d8d355e8d355f8d34608d34618d33628d33638d32648e32658e31668e31678e31688e30698e306a8e2f6b8e2f6c8e2e6d8e2e6e8e2e6f8e2d708e2d718e2c718e2c728e2c738e2b748e2b758e2a768e2a778e2a788e29798e297a8e297b8e287c8e287d8e277e8e277f8e27808e26818e26828e26828e25838e25848e25858e24868e24878e23888e23898e238a8d228b8d228c8d228d8d218e8d218f8d21908d21918c20928c20928c20938c1f948c1f958b1f968b1f978b1f988b1f998a1f9a8a1e9b8a1e9c891e9d891f9e891f9f881fa0881fa1881fa1871fa28720a38620a48621a58521a68522a78522a88423a98324aa8325ab8225ac8226ad8127ad8128ae8029af7f2ab07f2cb17e2db27d2eb37c2fb47c31b57b32b67a34b67935b77937b87838b9773aba763bbb753dbc743fbc7340bd7242be7144bf7046c06f48c16e4ac16d4cc26c4ec36b50c46a52c56954c56856c66758c7655ac8645cc8635ec96260ca6063cb5f65cb5e67cc5c69cd5b6ccd5a6ece5870cf5773d05675d05477d1537ad1517cd2507fd34e81d34d84d44b86d54989d5488bd6468ed64590d74393d74195d84098d83e9bd93c9dd93ba0da39a2da37a5db36a8db34aadc32addc30b0dd2fb2dd2db5de2bb8de29bade28bddf26c0df25c2df23c5e021c8e020cae11fcde11dd0e11cd2e21bd5e21ad8e219dae319dde318dfe318e2e418e5e419e7e419eae51aece51befe51cf1e51df4e61ef6e620f8e621fbe723fde725"));AT(Za("00000401000501010601010802010902020b02020d03030f03031204041405041606051806051a07061c08071e0907200a08220b09240c09260d0a290e0b2b100b2d110c2f120d31130d34140e36150e38160f3b180f3d19103f1a10421c10441d11471e114920114b21114e22115024125325125527125829115a2a115c2c115f2d11612f116331116533106734106936106b38106c390f6e3b0f703d0f713f0f72400f74420f75440f764510774710784910784a10794c117a4e117b4f127b51127c52137c54137d56147d57157e59157e5a167e5c167f5d177f5f187f601880621980641a80651a80671b80681c816a1c816b1d816d1d816e1e81701f81721f817320817521817621817822817922827b23827c23827e24828025828125818326818426818627818827818928818b29818c29818e2a81902a81912b81932b80942c80962c80982d80992d809b2e7f9c2e7f9e2f7fa02f7fa1307ea3307ea5317ea6317da8327daa337dab337cad347cae347bb0357bb2357bb3367ab5367ab73779b83779ba3878bc3978bd3977bf3a77c03a76c23b75c43c75c53c74c73d73c83e73ca3e72cc3f71cd4071cf4070d0416fd2426fd3436ed5446dd6456cd8456cd9466bdb476adc4869de4968df4a68e04c67e24d66e34e65e44f64e55064e75263e85362e95462ea5661eb5760ec5860ed5a5fee5b5eef5d5ef05f5ef1605df2625df2645cf3655cf4675cf4695cf56b5cf66c5cf66e5cf7705cf7725cf8745cf8765cf9785df9795df97b5dfa7d5efa7f5efa815ffb835ffb8560fb8761fc8961fc8a62fc8c63fc8e64fc9065fd9266fd9467fd9668fd9869fd9a6afd9b6bfe9d6cfe9f6dfea16efea36ffea571fea772fea973feaa74feac76feae77feb078feb27afeb47bfeb67cfeb77efeb97ffebb81febd82febf84fec185fec287fec488fec68afec88cfeca8dfecc8ffecd90fecf92fed194fed395fed597fed799fed89afdda9cfddc9efddea0fde0a1fde2a3fde3a5fde5a7fde7a9fde9aafdebacfcecaefceeb0fcf0b2fcf2b4fcf4b6fcf6b8fcf7b9fcf9bbfcfbbdfcfdbf"));AT(Za("00000401000501010601010802010a02020c02020e03021004031204031405041706041907051b08051d09061f0a07220b07240c08260d08290e092b10092d110a30120a32140b34150b37160b39180c3c190c3e1b0c411c0c431e0c451f0c48210c4a230c4c240c4f260c51280b53290b552b0b572d0b592f0a5b310a5c320a5e340a5f3609613809623909633b09643d09653e0966400a67420a68440a68450a69470b6a490b6a4a0c6b4c0c6b4d0d6c4f0d6c510e6c520e6d540f6d550f6d57106e59106e5a116e5c126e5d126e5f136e61136e62146e64156e65156e67166e69166e6a176e6c186e6d186e6f196e71196e721a6e741a6e751b6e771c6d781c6d7a1d6d7c1d6d7d1e6d7f1e6c801f6c82206c84206b85216b87216b88226a8a226a8c23698d23698f24699025689225689326679526679727669827669a28659b29649d29649f2a63a02a63a22b62a32c61a52c60a62d60a82e5fa92e5eab2f5ead305dae305cb0315bb1325ab3325ab43359b63458b73557b93556ba3655bc3754bd3853bf3952c03a51c13a50c33b4fc43c4ec63d4dc73e4cc83f4bca404acb4149cc4248ce4347cf4446d04545d24644d34743d44842d54a41d74b3fd84c3ed94d3dda4e3cdb503bdd513ade5238df5337e05536e15635e25734e35933e45a31e55c30e65d2fe75e2ee8602de9612bea632aeb6429eb6628ec6726ed6925ee6a24ef6c23ef6e21f06f20f1711ff1731df2741cf3761bf37819f47918f57b17f57d15f67e14f68013f78212f78410f8850ff8870ef8890cf98b0bf98c0af98e09fa9008fa9207fa9407fb9606fb9706fb9906fb9b06fb9d07fc9f07fca108fca309fca50afca60cfca80dfcaa0ffcac11fcae12fcb014fcb216fcb418fbb61afbb81dfbba1ffbbc21fbbe23fac026fac228fac42afac62df9c72ff9c932f9cb35f8cd37f8cf3af7d13df7d340f6d543f6d746f5d949f5db4cf4dd4ff4df53f4e156f3e35af3e55df2e661f2e865f2ea69f1ec6df1ed71f1ef75f1f179f2f27df2f482f3f586f3f68af4f88ef5f992f6fa96f8fb9af9fc9dfafda1fcffa4"));AT(Za("0d088710078813078916078a19068c1b068d1d068e20068f2206902406912605912805922a05932c05942e05952f059631059733059735049837049938049a3a049a3c049b3e049c3f049c41049d43039e44039e46039f48039f4903a04b03a14c02a14e02a25002a25102a35302a35502a45601a45801a45901a55b01a55c01a65e01a66001a66100a76300a76400a76600a76700a86900a86a00a86c00a86e00a86f00a87100a87201a87401a87501a87701a87801a87a02a87b02a87d03a87e03a88004a88104a78305a78405a78606a68707a68808a68a09a58b0aa58d0ba58e0ca48f0da4910ea3920fa39410a29511a19613a19814a099159f9a169f9c179e9d189d9e199da01a9ca11b9ba21d9aa31e9aa51f99a62098a72197a82296aa2395ab2494ac2694ad2793ae2892b02991b12a90b22b8fb32c8eb42e8db52f8cb6308bb7318ab83289ba3388bb3488bc3587bd3786be3885bf3984c03a83c13b82c23c81c33d80c43e7fc5407ec6417dc7427cc8437bc9447aca457acb4679cc4778cc4977cd4a76ce4b75cf4c74d04d73d14e72d24f71d35171d45270d5536fd5546ed6556dd7566cd8576bd9586ada5a6ada5b69db5c68dc5d67dd5e66de5f65de6164df6263e06363e16462e26561e26660e3685fe4695ee56a5de56b5de66c5ce76e5be76f5ae87059e97158e97257ea7457eb7556eb7655ec7754ed7953ed7a52ee7b51ef7c51ef7e50f07f4ff0804ef1814df1834cf2844bf3854bf3874af48849f48948f58b47f58c46f68d45f68f44f79044f79143f79342f89441f89540f9973ff9983ef99a3efa9b3dfa9c3cfa9e3bfb9f3afba139fba238fca338fca537fca636fca835fca934fdab33fdac33fdae32fdaf31fdb130fdb22ffdb42ffdb52efeb72dfeb82cfeba2cfebb2bfebd2afebe2afec029fdc229fdc328fdc527fdc627fdc827fdca26fdcb26fccd25fcce25fcd025fcd225fbd324fbd524fbd724fad824fada24f9dc24f9dd25f8df25f8e125f7e225f7e425f6e626f6e826f5e926f5eb27f4ed27f3ee27f3f027f2f227f1f426f1f525f0f724f0f921"));var Jd={},aT={};aT.byteLength=uQe;aT.toByteArray=hQe;aT.fromByteArray=pQe;var DA=[],Sr=[],lQe=typeof Uint8Array<"u"?Uint8Array:Array,wK="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(var Bm=0,cQe=wK.length;Bm0)throw new Error("Invalid string. Length must be a multiple of 4");var I=e.indexOf("=");I===-1&&(I=g);var i=I===g?0:4-I%4;return[I,i]}function uQe(e){var g=spe(e),I=g[0],i=g[1];return(I+i)*3/4-i}function dQe(e,g,I){return(g+I)*3/4-I}function hQe(e){var g,I=spe(e),i=I[0],n=I[1],C=new lQe(dQe(e,i,n)),r=0,o=n>0?i-4:i,A;for(A=0;A>16&255,C[r++]=g>>8&255,C[r++]=g&255;return n===2&&(g=Sr[e.charCodeAt(A)]<<2|Sr[e.charCodeAt(A+1)]>>4,C[r++]=g&255),n===1&&(g=Sr[e.charCodeAt(A)]<<10|Sr[e.charCodeAt(A+1)]<<4|Sr[e.charCodeAt(A+2)]>>2,C[r++]=g>>8&255,C[r++]=g&255),C}function mQe(e){return DA[e>>18&63]+DA[e>>12&63]+DA[e>>6&63]+DA[e&63]}function fQe(e,g,I){for(var i,n=[],C=g;Co?o:r+C));return i===1?(g=e[I-1],n.push(DA[g>>2]+DA[g<<4&63]+"==")):i===2&&(g=(e[I-2]<<8)+e[I-1],n.push(DA[g>>10]+DA[g>>4&63]+DA[g<<2&63]+"=")),n.join("")}var AU={};/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh */AU.read=function(e,g,I,i,n){var C,r,o=n*8-i-1,A=(1<>1,a=-7,l=I?n-1:0,c=I?-1:1,u=e[g+l];for(l+=c,C=u&(1<<-a)-1,u>>=-a,a+=o;a>0;C=C*256+e[g+l],l+=c,a-=8);for(r=C&(1<<-a)-1,C>>=-a,a+=i;a>0;r=r*256+e[g+l],l+=c,a-=8);if(C===0)C=1-s;else{if(C===A)return r?NaN:(u?-1:1)*(1/0);r=r+Math.pow(2,i),C=C-s}return(u?-1:1)*r*Math.pow(2,C-i)};AU.write=function(e,g,I,i,n,C){var r,o,A,s=C*8-n-1,a=(1<>1,c=n===23?Math.pow(2,-24)-Math.pow(2,-77):0,u=i?0:C-1,d=i?1:-1,h=g<0||g===0&&1/g<0?1:0;for(g=Math.abs(g),isNaN(g)||g===1/0?(o=isNaN(g)?1:0,r=a):(r=Math.floor(Math.log(g)/Math.LN2),g*(A=Math.pow(2,-r))<1&&(r--,A*=2),r+l>=1?g+=c/A:g+=c*Math.pow(2,1-l),g*A>=2&&(r++,A/=2),r+l>=a?(o=0,r=a):r+l>=1?(o=(g*A-1)*Math.pow(2,n),r=r+l):(o=g*Math.pow(2,l-1)*Math.pow(2,n),r=0));n>=8;e[I+u]=o&255,u+=d,o/=256,n-=8);for(r=r<0;e[I+u]=r&255,u+=d,r/=256,s-=8);e[I+u-d]|=h*128};/*! * The buffer module from node.js, for the browser. * * @author Feross Aboukhadijeh * @license MIT - */(function(g){const e=gN,I=MU,i=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;g.Buffer=o,g.SlowBuffer=b,g.INSPECT_MAX_BYTES=50;const n=2147483647;g.kMaxLength=n,o.TYPED_ARRAY_SUPPORT=C(),!o.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function C(){try{const K=new Uint8Array(1),T={foo:function(){return 42}};return Object.setPrototypeOf(T,Uint8Array.prototype),Object.setPrototypeOf(K,T),K.foo()===42}catch{return!1}}Object.defineProperty(o.prototype,"parent",{enumerable:!0,get:function(){if(o.isBuffer(this))return this.buffer}}),Object.defineProperty(o.prototype,"offset",{enumerable:!0,get:function(){if(o.isBuffer(this))return this.byteOffset}});function r(K){if(K>n)throw new RangeError('The value "'+K+'" is invalid for option "size"');const T=new Uint8Array(K);return Object.setPrototypeOf(T,o.prototype),T}function o(K,T,k){if(typeof K=="number"){if(typeof T=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return l(K)}return A(K,T,k)}o.poolSize=8192;function A(K,T,k){if(typeof K=="string")return c(K,T);if(ArrayBuffer.isView(K))return d(K);if(K==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof K);if(rt(K,ArrayBuffer)||K&&rt(K.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(rt(K,SharedArrayBuffer)||K&&rt(K.buffer,SharedArrayBuffer)))return h(K,T,k);if(typeof K=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');const ge=K.valueOf&&K.valueOf();if(ge!=null&&ge!==K)return o.from(ge,T,k);const he=m(K);if(he)return he;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof K[Symbol.toPrimitive]=="function")return o.from(K[Symbol.toPrimitive]("string"),T,k);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof K)}o.from=function(K,T,k){return A(K,T,k)},Object.setPrototypeOf(o.prototype,Uint8Array.prototype),Object.setPrototypeOf(o,Uint8Array);function s(K){if(typeof K!="number")throw new TypeError('"size" argument must be of type number');if(K<0)throw new RangeError('The value "'+K+'" is invalid for option "size"')}function a(K,T,k){return s(K),K<=0?r(K):T!==void 0?typeof k=="string"?r(K).fill(T,k):r(K).fill(T):r(K)}o.alloc=function(K,T,k){return a(K,T,k)};function l(K){return s(K),r(K<0?0:f(K)|0)}o.allocUnsafe=function(K){return l(K)},o.allocUnsafeSlow=function(K){return l(K)};function c(K,T){if((typeof T!="string"||T==="")&&(T="utf8"),!o.isEncoding(T))throw new TypeError("Unknown encoding: "+T);const k=p(K,T)|0;let ge=r(k);const he=ge.write(K,T);return he!==k&&(ge=ge.slice(0,he)),ge}function u(K){const T=K.length<0?0:f(K.length)|0,k=r(T);for(let ge=0;ge=n)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+n.toString(16)+" bytes");return K|0}function b(K){return+K!=K&&(K=0),o.alloc(+K)}o.isBuffer=function(T){return T!=null&&T._isBuffer===!0&&T!==o.prototype},o.compare=function(T,k){if(rt(T,Uint8Array)&&(T=o.from(T,T.offset,T.byteLength)),rt(k,Uint8Array)&&(k=o.from(k,k.offset,k.byteLength)),!o.isBuffer(T)||!o.isBuffer(k))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(T===k)return 0;let ge=T.length,he=k.length;for(let we=0,xe=Math.min(ge,he);wehe.length?(o.isBuffer(xe)||(xe=o.from(xe)),xe.copy(he,we)):Uint8Array.prototype.set.call(he,xe,we);else if(o.isBuffer(xe))xe.copy(he,we);else throw new TypeError('"list" argument must be an Array of Buffers');we+=xe.length}return he};function p(K,T){if(o.isBuffer(K))return K.length;if(ArrayBuffer.isView(K)||rt(K,ArrayBuffer))return K.byteLength;if(typeof K!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof K);const k=K.length,ge=arguments.length>2&&arguments[2]===!0;if(!ge&&k===0)return 0;let he=!1;for(;;)switch(T){case"ascii":case"latin1":case"binary":return k;case"utf8":case"utf-8":return Me(K).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return k*2;case"hex":return k>>>1;case"base64":return At(K).length;default:if(he)return ge?-1:Me(K).length;T=(""+T).toLowerCase(),he=!0}}o.byteLength=p;function y(K,T,k){let ge=!1;if((T===void 0||T<0)&&(T=0),T>this.length||((k===void 0||k>this.length)&&(k=this.length),k<=0)||(k>>>=0,T>>>=0,k<=T))return"";for(K||(K="utf8");;)switch(K){case"hex":return _(this,T,k);case"utf8":case"utf-8":return V(this,T,k);case"ascii":return Y(this,T,k);case"latin1":case"binary":return F(this,T,k);case"base64":return W(this,T,k);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return J(this,T,k);default:if(ge)throw new TypeError("Unknown encoding: "+K);K=(K+"").toLowerCase(),ge=!0}}o.prototype._isBuffer=!0;function Z(K,T,k){const ge=K[T];K[T]=K[k],K[k]=ge}o.prototype.swap16=function(){const T=this.length;if(T%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let k=0;kk&&(T+=" ... "),""},i&&(o.prototype[i]=o.prototype.inspect),o.prototype.compare=function(T,k,ge,he,we){if(rt(T,Uint8Array)&&(T=o.from(T,T.offset,T.byteLength)),!o.isBuffer(T))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof T);if(k===void 0&&(k=0),ge===void 0&&(ge=T?T.length:0),he===void 0&&(he=0),we===void 0&&(we=this.length),k<0||ge>T.length||he<0||we>this.length)throw new RangeError("out of range index");if(he>=we&&k>=ge)return 0;if(he>=we)return-1;if(k>=ge)return 1;if(k>>>=0,ge>>>=0,he>>>=0,we>>>=0,this===T)return 0;let xe=we-he,qe=ge-k;const mt=Math.min(xe,qe),St=this.slice(he,we),ut=T.slice(k,ge);for(let Yt=0;Yt2147483647?k=2147483647:k<-2147483648&&(k=-2147483648),k=+k,Te(k)&&(k=he?0:K.length-1),k<0&&(k=K.length+k),k>=K.length){if(he)return-1;k=K.length-1}else if(k<0)if(he)k=0;else return-1;if(typeof T=="string"&&(T=o.from(T,ge)),o.isBuffer(T))return T.length===0?-1:G(K,T,k,ge,he);if(typeof T=="number")return T=T&255,typeof Uint8Array.prototype.indexOf=="function"?he?Uint8Array.prototype.indexOf.call(K,T,k):Uint8Array.prototype.lastIndexOf.call(K,T,k):G(K,[T],k,ge,he);throw new TypeError("val must be string, number or Buffer")}function G(K,T,k,ge,he){let we=1,xe=K.length,qe=T.length;if(ge!==void 0&&(ge=String(ge).toLowerCase(),ge==="ucs2"||ge==="ucs-2"||ge==="utf16le"||ge==="utf-16le")){if(K.length<2||T.length<2)return-1;we=2,xe/=2,qe/=2,k/=2}function mt(ut,Yt){return we===1?ut[Yt]:ut.readUInt16BE(Yt*we)}let St;if(he){let ut=-1;for(St=k;Stxe&&(k=xe-qe),St=k;St>=0;St--){let ut=!0;for(let Yt=0;Ythe&&(ge=he)):ge=he;const we=T.length;ge>we/2&&(ge=we/2);let xe;for(xe=0;xe>>0,isFinite(ge)?(ge=ge>>>0,he===void 0&&(he="utf8")):(he=ge,ge=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");const we=this.length-k;if((ge===void 0||ge>we)&&(ge=we),T.length>0&&(ge<0||k<0)||k>this.length)throw new RangeError("Attempt to write outside buffer bounds");he||(he="utf8");let xe=!1;for(;;)switch(he){case"hex":return B(this,T,k,ge);case"utf8":case"utf-8":return w(this,T,k,ge);case"ascii":case"latin1":case"binary":return R(this,T,k,ge);case"base64":return S(this,T,k,ge);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return X(this,T,k,ge);default:if(xe)throw new TypeError("Unknown encoding: "+he);he=(""+he).toLowerCase(),xe=!0}},o.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function W(K,T,k){return T===0&&k===K.length?e.fromByteArray(K):e.fromByteArray(K.slice(T,k))}function V(K,T,k){k=Math.min(K.length,k);const ge=[];let he=T;for(;he239?4:we>223?3:we>191?2:1;if(he+qe<=k){let mt,St,ut,Yt;switch(qe){case 1:we<128&&(xe=we);break;case 2:mt=K[he+1],(mt&192)===128&&(Yt=(we&31)<<6|mt&63,Yt>127&&(xe=Yt));break;case 3:mt=K[he+1],St=K[he+2],(mt&192)===128&&(St&192)===128&&(Yt=(we&15)<<12|(mt&63)<<6|St&63,Yt>2047&&(Yt<55296||Yt>57343)&&(xe=Yt));break;case 4:mt=K[he+1],St=K[he+2],ut=K[he+3],(mt&192)===128&&(St&192)===128&&(ut&192)===128&&(Yt=(we&15)<<18|(mt&63)<<12|(St&63)<<6|ut&63,Yt>65535&&Yt<1114112&&(xe=Yt))}}xe===null?(xe=65533,qe=1):xe>65535&&(xe-=65536,ge.push(xe>>>10&1023|55296),xe=56320|xe&1023),ge.push(xe),he+=qe}return D(ge)}const H=4096;function D(K){const T=K.length;if(T<=H)return String.fromCharCode.apply(String,K);let k="",ge=0;for(;gege)&&(k=ge);let he="";for(let we=T;wege&&(T=ge),k<0?(k+=ge,k<0&&(k=0)):k>ge&&(k=ge),kk)throw new RangeError("Trying to access beyond buffer length")}o.prototype.readUintLE=o.prototype.readUIntLE=function(T,k,ge){T=T>>>0,k=k>>>0,ge||te(T,k,this.length);let he=this[T],we=1,xe=0;for(;++xe>>0,k=k>>>0,ge||te(T,k,this.length);let he=this[T+--k],we=1;for(;k>0&&(we*=256);)he+=this[T+--k]*we;return he},o.prototype.readUint8=o.prototype.readUInt8=function(T,k){return T=T>>>0,k||te(T,1,this.length),this[T]},o.prototype.readUint16LE=o.prototype.readUInt16LE=function(T,k){return T=T>>>0,k||te(T,2,this.length),this[T]|this[T+1]<<8},o.prototype.readUint16BE=o.prototype.readUInt16BE=function(T,k){return T=T>>>0,k||te(T,2,this.length),this[T]<<8|this[T+1]},o.prototype.readUint32LE=o.prototype.readUInt32LE=function(T,k){return T=T>>>0,k||te(T,4,this.length),(this[T]|this[T+1]<<8|this[T+2]<<16)+this[T+3]*16777216},o.prototype.readUint32BE=o.prototype.readUInt32BE=function(T,k){return T=T>>>0,k||te(T,4,this.length),this[T]*16777216+(this[T+1]<<16|this[T+2]<<8|this[T+3])},o.prototype.readBigUInt64LE=ye(function(T){T=T>>>0,ke(T,"offset");const k=this[T],ge=this[T+7];(k===void 0||ge===void 0)&&Xe(T,this.length-8);const he=k+this[++T]*2**8+this[++T]*2**16+this[++T]*2**24,we=this[++T]+this[++T]*2**8+this[++T]*2**16+ge*2**24;return BigInt(he)+(BigInt(we)<>>0,ke(T,"offset");const k=this[T],ge=this[T+7];(k===void 0||ge===void 0)&&Xe(T,this.length-8);const he=k*2**24+this[++T]*2**16+this[++T]*2**8+this[++T],we=this[++T]*2**24+this[++T]*2**16+this[++T]*2**8+ge;return(BigInt(he)<>>0,k=k>>>0,ge||te(T,k,this.length);let he=this[T],we=1,xe=0;for(;++xe=we&&(he-=Math.pow(2,8*k)),he},o.prototype.readIntBE=function(T,k,ge){T=T>>>0,k=k>>>0,ge||te(T,k,this.length);let he=k,we=1,xe=this[T+--he];for(;he>0&&(we*=256);)xe+=this[T+--he]*we;return we*=128,xe>=we&&(xe-=Math.pow(2,8*k)),xe},o.prototype.readInt8=function(T,k){return T=T>>>0,k||te(T,1,this.length),this[T]&128?(255-this[T]+1)*-1:this[T]},o.prototype.readInt16LE=function(T,k){T=T>>>0,k||te(T,2,this.length);const ge=this[T]|this[T+1]<<8;return ge&32768?ge|4294901760:ge},o.prototype.readInt16BE=function(T,k){T=T>>>0,k||te(T,2,this.length);const ge=this[T+1]|this[T]<<8;return ge&32768?ge|4294901760:ge},o.prototype.readInt32LE=function(T,k){return T=T>>>0,k||te(T,4,this.length),this[T]|this[T+1]<<8|this[T+2]<<16|this[T+3]<<24},o.prototype.readInt32BE=function(T,k){return T=T>>>0,k||te(T,4,this.length),this[T]<<24|this[T+1]<<16|this[T+2]<<8|this[T+3]},o.prototype.readBigInt64LE=ye(function(T){T=T>>>0,ke(T,"offset");const k=this[T],ge=this[T+7];(k===void 0||ge===void 0)&&Xe(T,this.length-8);const he=this[T+4]+this[T+5]*2**8+this[T+6]*2**16+(ge<<24);return(BigInt(he)<>>0,ke(T,"offset");const k=this[T],ge=this[T+7];(k===void 0||ge===void 0)&&Xe(T,this.length-8);const he=(k<<24)+this[++T]*2**16+this[++T]*2**8+this[++T];return(BigInt(he)<>>0,k||te(T,4,this.length),I.read(this,T,!0,23,4)},o.prototype.readFloatBE=function(T,k){return T=T>>>0,k||te(T,4,this.length),I.read(this,T,!1,23,4)},o.prototype.readDoubleLE=function(T,k){return T=T>>>0,k||te(T,8,this.length),I.read(this,T,!0,52,8)},o.prototype.readDoubleBE=function(T,k){return T=T>>>0,k||te(T,8,this.length),I.read(this,T,!1,52,8)};function q(K,T,k,ge,he,we){if(!o.isBuffer(K))throw new TypeError('"buffer" argument must be a Buffer instance');if(T>he||TK.length)throw new RangeError("Index out of range")}o.prototype.writeUintLE=o.prototype.writeUIntLE=function(T,k,ge,he){if(T=+T,k=k>>>0,ge=ge>>>0,!he){const qe=Math.pow(2,8*ge)-1;q(this,T,k,ge,qe,0)}let we=1,xe=0;for(this[k]=T&255;++xe>>0,ge=ge>>>0,!he){const qe=Math.pow(2,8*ge)-1;q(this,T,k,ge,qe,0)}let we=ge-1,xe=1;for(this[k+we]=T&255;--we>=0&&(xe*=256);)this[k+we]=T/xe&255;return k+ge},o.prototype.writeUint8=o.prototype.writeUInt8=function(T,k,ge){return T=+T,k=k>>>0,ge||q(this,T,k,1,255,0),this[k]=T&255,k+1},o.prototype.writeUint16LE=o.prototype.writeUInt16LE=function(T,k,ge){return T=+T,k=k>>>0,ge||q(this,T,k,2,65535,0),this[k]=T&255,this[k+1]=T>>>8,k+2},o.prototype.writeUint16BE=o.prototype.writeUInt16BE=function(T,k,ge){return T=+T,k=k>>>0,ge||q(this,T,k,2,65535,0),this[k]=T>>>8,this[k+1]=T&255,k+2},o.prototype.writeUint32LE=o.prototype.writeUInt32LE=function(T,k,ge){return T=+T,k=k>>>0,ge||q(this,T,k,4,4294967295,0),this[k+3]=T>>>24,this[k+2]=T>>>16,this[k+1]=T>>>8,this[k]=T&255,k+4},o.prototype.writeUint32BE=o.prototype.writeUInt32BE=function(T,k,ge){return T=+T,k=k>>>0,ge||q(this,T,k,4,4294967295,0),this[k]=T>>>24,this[k+1]=T>>>16,this[k+2]=T>>>8,this[k+3]=T&255,k+4};function $(K,T,k,ge,he){ve(T,ge,he,K,k,7);let we=Number(T&BigInt(4294967295));K[k++]=we,we=we>>8,K[k++]=we,we=we>>8,K[k++]=we,we=we>>8,K[k++]=we;let xe=Number(T>>BigInt(32)&BigInt(4294967295));return K[k++]=xe,xe=xe>>8,K[k++]=xe,xe=xe>>8,K[k++]=xe,xe=xe>>8,K[k++]=xe,k}function j(K,T,k,ge,he){ve(T,ge,he,K,k,7);let we=Number(T&BigInt(4294967295));K[k+7]=we,we=we>>8,K[k+6]=we,we=we>>8,K[k+5]=we,we=we>>8,K[k+4]=we;let xe=Number(T>>BigInt(32)&BigInt(4294967295));return K[k+3]=xe,xe=xe>>8,K[k+2]=xe,xe=xe>>8,K[k+1]=xe,xe=xe>>8,K[k]=xe,k+8}o.prototype.writeBigUInt64LE=ye(function(T,k=0){return $(this,T,k,BigInt(0),BigInt("0xffffffffffffffff"))}),o.prototype.writeBigUInt64BE=ye(function(T,k=0){return j(this,T,k,BigInt(0),BigInt("0xffffffffffffffff"))}),o.prototype.writeIntLE=function(T,k,ge,he){if(T=+T,k=k>>>0,!he){const mt=Math.pow(2,8*ge-1);q(this,T,k,ge,mt-1,-mt)}let we=0,xe=1,qe=0;for(this[k]=T&255;++we>0)-qe&255;return k+ge},o.prototype.writeIntBE=function(T,k,ge,he){if(T=+T,k=k>>>0,!he){const mt=Math.pow(2,8*ge-1);q(this,T,k,ge,mt-1,-mt)}let we=ge-1,xe=1,qe=0;for(this[k+we]=T&255;--we>=0&&(xe*=256);)T<0&&qe===0&&this[k+we+1]!==0&&(qe=1),this[k+we]=(T/xe>>0)-qe&255;return k+ge},o.prototype.writeInt8=function(T,k,ge){return T=+T,k=k>>>0,ge||q(this,T,k,1,127,-128),T<0&&(T=255+T+1),this[k]=T&255,k+1},o.prototype.writeInt16LE=function(T,k,ge){return T=+T,k=k>>>0,ge||q(this,T,k,2,32767,-32768),this[k]=T&255,this[k+1]=T>>>8,k+2},o.prototype.writeInt16BE=function(T,k,ge){return T=+T,k=k>>>0,ge||q(this,T,k,2,32767,-32768),this[k]=T>>>8,this[k+1]=T&255,k+2},o.prototype.writeInt32LE=function(T,k,ge){return T=+T,k=k>>>0,ge||q(this,T,k,4,2147483647,-2147483648),this[k]=T&255,this[k+1]=T>>>8,this[k+2]=T>>>16,this[k+3]=T>>>24,k+4},o.prototype.writeInt32BE=function(T,k,ge){return T=+T,k=k>>>0,ge||q(this,T,k,4,2147483647,-2147483648),T<0&&(T=4294967295+T+1),this[k]=T>>>24,this[k+1]=T>>>16,this[k+2]=T>>>8,this[k+3]=T&255,k+4},o.prototype.writeBigInt64LE=ye(function(T,k=0){return $(this,T,k,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),o.prototype.writeBigInt64BE=ye(function(T,k=0){return j(this,T,k,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function ee(K,T,k,ge,he,we){if(k+ge>K.length)throw new RangeError("Index out of range");if(k<0)throw new RangeError("Index out of range")}function Q(K,T,k,ge,he){return T=+T,k=k>>>0,he||ee(K,T,k,4),I.write(K,T,k,ge,23,4),k+4}o.prototype.writeFloatLE=function(T,k,ge){return Q(this,T,k,!0,ge)},o.prototype.writeFloatBE=function(T,k,ge){return Q(this,T,k,!1,ge)};function ne(K,T,k,ge,he){return T=+T,k=k>>>0,he||ee(K,T,k,8),I.write(K,T,k,ge,52,8),k+8}o.prototype.writeDoubleLE=function(T,k,ge){return ne(this,T,k,!0,ge)},o.prototype.writeDoubleBE=function(T,k,ge){return ne(this,T,k,!1,ge)},o.prototype.copy=function(T,k,ge,he){if(!o.isBuffer(T))throw new TypeError("argument should be a Buffer");if(ge||(ge=0),!he&&he!==0&&(he=this.length),k>=T.length&&(k=T.length),k||(k=0),he>0&&he=this.length)throw new RangeError("Index out of range");if(he<0)throw new RangeError("sourceEnd out of bounds");he>this.length&&(he=this.length),T.length-k>>0,ge=ge===void 0?this.length:ge>>>0,T||(T=0);let we;if(typeof T=="number")for(we=k;we2**32?he=Ze(String(k)):typeof k=="bigint"&&(he=String(k),(k>BigInt(2)**BigInt(32)||k<-(BigInt(2)**BigInt(32)))&&(he=Ze(he)),he+="n"),ge+=` It must be ${T}. Received ${he}`,ge},RangeError);function Ze(K){let T="",k=K.length;const ge=K[0]==="-"?1:0;for(;k>=ge+4;k-=3)T=`_${K.slice(k-3,k)}${T}`;return`${K.slice(0,k)}${T}`}function Ge(K,T,k){ke(T,"offset"),(K[T]===void 0||K[T+k]===void 0)&&Xe(T,K.length-(k+1))}function ve(K,T,k,ge,he,we){if(K>k||K3?T===0||T===BigInt(0)?qe=`>= 0${xe} and < 2${xe} ** ${(we+1)*8}${xe}`:qe=`>= -(2${xe} ** ${(we+1)*8-1}${xe}) and < 2 ** ${(we+1)*8-1}${xe}`:qe=`>= ${T}${xe} and <= ${k}${xe}`,new fe.ERR_OUT_OF_RANGE("value",qe,K)}Ge(ge,he,we)}function ke(K,T){if(typeof K!="number")throw new fe.ERR_INVALID_ARG_TYPE(T,"number",K)}function Xe(K,T,k){throw Math.floor(K)!==K?(ke(K,k),new fe.ERR_OUT_OF_RANGE(k||"offset","an integer",K)):T<0?new fe.ERR_BUFFER_OUT_OF_BOUNDS:new fe.ERR_OUT_OF_RANGE(k||"offset",`>= ${k?1:0} and <= ${T}`,K)}const Oe=/[^+/0-9A-Za-z-_]/g;function ze(K){if(K=K.split("=")[0],K=K.trim().replace(Oe,""),K.length<2)return"";for(;K.length%4!==0;)K=K+"=";return K}function Me(K,T){T=T||1/0;let k;const ge=K.length;let he=null;const we=[];for(let xe=0;xe55295&&k<57344){if(!he){if(k>56319){(T-=3)>-1&&we.push(239,191,189);continue}else if(xe+1===ge){(T-=3)>-1&&we.push(239,191,189);continue}he=k;continue}if(k<56320){(T-=3)>-1&&we.push(239,191,189),he=k;continue}k=(he-55296<<10|k-56320)+65536}else he&&(T-=3)>-1&&we.push(239,191,189);if(he=null,k<128){if((T-=1)<0)break;we.push(k)}else if(k<2048){if((T-=2)<0)break;we.push(k>>6|192,k&63|128)}else if(k<65536){if((T-=3)<0)break;we.push(k>>12|224,k>>6&63|128,k&63|128)}else if(k<1114112){if((T-=4)<0)break;we.push(k>>18|240,k>>12&63|128,k>>6&63|128,k&63|128)}else throw new Error("Invalid code point")}return we}function Ue(K){const T=[];for(let k=0;k>8,he=k%256,we.push(he),we.push(ge);return we}function At(K){return e.toByteArray(ze(K))}function wt(K,T,k,ge){let he;for(he=0;he=T.length||he>=K.length);++he)T[he+k]=K[he];return he}function rt(K,T){return K instanceof T||K!=null&&K.constructor!=null&&K.constructor.name!=null&&K.constructor.name===T.name}function Te(K){return K!==K}const le=function(){const K="0123456789abcdef",T=new Array(256);for(let k=0;k<16;++k){const ge=k*16;for(let he=0;he<16;++he)T[ge+he]=K[k]+K[he]}return T}();function ye(K){return typeof BigInt>"u"?We:K}function We(){throw new Error("BigInt not supported")}})(rh);let Zbe=class{async getBufferFromResponse(e){if(typeof e.buffer=="function")return e.buffer();if(typeof e.arrayBuffer=="function"){const I=await e.arrayBuffer();return rh.Buffer.from(I)}else throw new TypeError("invalid HTTP response object, has no buffer method, and no arrayBuffer method")}constructor(e,I={}){this.baseOverrides={},this.url=e;const i=I.fetch||globalThis.fetch.bind(globalThis);if(!i)throw new TypeError("no fetch function supplied, and none found in global environment");I.overrides&&(this.baseOverrides=I.overrides),this.fetchImplementation=i}async fetch(e,I){let i;try{i=await this.fetchImplementation(e,I)}catch(n){if(`${n}`.includes("Failed to fetch"))console.warn(`generic-filehandle: refetching ${e} to attempt to work around chrome CORS header caching bug`),i=await this.fetchImplementation(e,{...I,cache:"reload"});else throw n}return i}async read(e,I=0,i,n=0,C={}){const{headers:r={},signal:o,overrides:A={}}=C;i<1/0?r.range=`bytes=${n}-${n+i}`:i===1/0&&n!==0&&(r.range=`bytes=${n}-`);const s={...this.baseOverrides,...A,headers:{...r,...A.headers,...this.baseOverrides.headers},method:"GET",redirect:"follow",mode:"cors",signal:o},a=await this.fetch(this.url,s);if(!a.ok)throw new Error(`HTTP ${a.status} ${a.statusText} ${this.url}`);if(a.status===200&&n===0||a.status===206){const l=await this.getBufferFromResponse(a),c=l.copy(e,I,0,Math.min(i,l.length)),u=a.headers.get("content-range"),d=/\/(\d+)$/.exec(u||"");return d&&d[1]&&(this._stat={size:parseInt(d[1],10)}),{bytesRead:c,buffer:e}}throw a.status===200?new Error("${this.url} fetch returned status 200, expected 206"):new Error(`HTTP ${a.status} fetching ${this.url}`)}async readFile(e={}){let I,i;typeof e=="string"?(I=e,i={}):(I=e.encoding,i=e,delete i.encoding);const{headers:n={},signal:C,overrides:r={}}=i,o={headers:n,method:"GET",redirect:"follow",mode:"cors",signal:C,...this.baseOverrides,...r},A=await this.fetch(this.url,o);if(!A)throw new Error("generic-filehandle failed to fetch");if(A.status!==200)throw Object.assign(new Error(`HTTP ${A.status} fetching ${this.url}`),{status:A.status});if(I==="utf8")return A.text();if(I)throw new Error(`unsupported encoding: ${I}`);return this.getBufferFromResponse(A)}async stat(){if(!this._stat){const e=rh.Buffer.allocUnsafe(10);if(await this.read(e,0,10,0),!this._stat)throw new Error(`unable to determine size of file at ${this.url}`)}return this._stat}async close(){}};var MUe=Object.defineProperty,zUe=(g,e,I)=>e in g?MUe(g,e,{enumerable:!0,configurable:!0,writable:!0,value:I}):g[e]=I,PUe=(g,e,I)=>(zUe(g,typeof e!="symbol"?e+"":e,I),I);const I9=6,JUe=130,OUe=600,vte=600,O1=10,Gbe=.3,LUe=0,_Ue="gray",ft=g=>{let e=ih(g);return e||(e=ih(_Ue)),x_([e.rgb().r/255,e.rgb().g/255,e.rgb().b/255])},$i=0;function qg(g,e,I,i,n){const C=Math.max(Math.min(e,g),0),r=n??$i,o=(i-I)/360*Math.PI*2-r*2;return-(I/360*Math.PI*2+C/e*o)-Math.PI/2-r}function Lt(g,e,I,i,n,C,r){return{x:i+I*Math.cos(qg(g,e,C,r)),y:n+I*Math.sin(qg(g,e,C,r))}}function vc(g,e,I,i){return I<=g?Math.atan((e-i)/(g-I)):Math.atan((e-i)/(g-I))-Math.PI}function UUe(g,e,I,i){return(Math.atan2(-(e-i),g-I)/Math.PI*180+270)%360}function QUe(g,e,I){var i,n,C,r,o;const A=I.spec();if(!A.width||!A.height){console.warn("Size of a track is not properly determined, so visual mark cannot be rendered");return}const s=I.data(),[a,l]=g.dimensions,c=I.getChannelScale("x").invert(a)-I.getChannelScale("x").invert(0),u=A.layout==="circular",d=(i=A.innerRadius)!=null?i:220,h=(n=A.outerRadius)!=null?n:300,m=(C=A.startAngle)!=null?C:0,f=(r=A.endAngle)!=null?r:360,b=h-d,p=a/2,y=l/2,Z=(o=I.getChannelDomainArray("row"))!=null?o:["___SINGLE_ROW___"],v=l/Z.length;Z.forEach(G=>{const B=I.encodedValue("row",G);s.filter(w=>!bI(w,A.row)||bI(w,A.row)===G).forEach(w=>{const R=I.encodedPIXIProperty("x-center",w),S=I.encodedPIXIProperty("y-center",w),X=I.encodedPIXIProperty("color",w),W=I.encodedPIXIProperty("p-size",w),V=I.encodedPIXIProperty("strokeWidth",w),H=I.encodedPIXIProperty("stroke",w),D=I.encodedPIXIProperty("opacity",w),Y=I.markVisibility(w,{width:W,zoomLevel:c}),F=Math.min(Y,D);if(!(W<=.1||F===0||R+W<0||R-W>a))if(e.lineStyle(V,ft(H),F,1),u){const _=h-(B+v-S)/l*b,J=Lt(R,a,_,p,y,m,f);e.beginFill(ft(X),F),e.drawCircle(J.x,J.y,W),I.getMouseEventModel().addPointBasedEvent(w,[J.x,J.y,W])}else e.beginFill(ft(X),F),e.drawCircle(R,B+v-S,W),I.getMouseEventModel().addPointBasedEvent(w,[R,B+v-S,W])})})}function jUe(g,e,I){const i=g.visualPropertyByChannel("xe",I),n=g.visualPropertyByChannel("x",I),C=g.visualPropertyByChannel("size",I);switch(e){case"x-center":return i?(i+n)/2:n;case"y-center":{const r=g.visualPropertyByChannel("ye",I),o=g.visualPropertyByChannel("y",I);return r?(r+o)/2:o}case"p-size":return i&&g.spec().stretch?(i-n)/2:C;default:return}}function $Ue(g,e,I,i){var n,C,r,o,A,s;const a=e.spec();if(!a.width||!a.height){console.warn("Size of a track is not properly determined, so visual mark cannot be rendered");return}const l=e.data(),c=a.layout==="circular",u=(n=a.innerRadius)!=null?n:220,d=(C=a.outerRadius)!=null?C:300,h=(r=a.startAngle)!=null?r:0,m=(o=a.endAngle)!=null?o:360,f=d-u,b=I/2,p=i/2,y=(A=e.getChannelDomainArray("row"))!=null?A:["___SINGLE_ROW___"],Z=i/y.length,v=(s=e.getChannelDomainArray("color"))!=null?s:["___SINGLE_COLOR___"];y.forEach(G=>{const B=e.encodedValue("row",G);v.forEach(w=>{l.filter(R=>(!bI(R,a.row)||bI(R,a.row)===G)&&(!bI(R,a.color)||bI(R,a.color)===w)).sort((R,S)=>bI(R,a.x)-bI(S,a.x)).forEach((R,S)=>{const X=e.encodedPIXIProperty("x",R),W=e.encodedPIXIProperty("y",R),V=e.encodedPIXIProperty("size",R),H=e.encodedPIXIProperty("color",R),D=e.encodedPIXIProperty("opacity",R);if(g.lineStyle(V,ft(H),D,.5),c){const Y=d-(B+Z-W)/i*f,F=Lt(X,I,Y,b,p,h,m);S===0?g.moveTo(F.x,F.y):g.lineTo(F.x,F.y),e.getMouseEventModel().addPointBasedEvent(R,[F.x,F.y,1])}else S===0?g.moveTo(X,B+Z-W):g.lineTo(X,B+Z-W),e.getMouseEventModel().addPointBasedEvent(R,[X,B+Z-W,1])})})})}function qUe(g,e,I){var i,n,C,r,o,A,s;const a=I.spec();if(!a.width||!a.height){console.warn("Size of a track is not properly determined, so visual mark cannot be rendered");return}const l=I.data(),[c,u]=g.dimensions,d=g.tilesetInfo.tile_size,h=I.getChannelScale("x").invert(c)-I.getChannelScale("x").invert(0),m=a.layout==="circular",f=(i=a.innerRadius)!=null?i:220,b=(n=a.outerRadius)!=null?n:300,p=(C=a.startAngle)!=null?C:0,y=(r=a.endAngle)!=null?r:360,Z=b-f,v=c/2,G=u/2,B=I.getChannelScale("x");let w;if(e.tileData.tilePos){const{tileX:D,tileWidth:Y}=g.getTilePosAndDimensions(e.tileData.zoomLevel,e.tileData.tilePos,d);w=B(D+Y/d)-B(D)}const R=(o=I.getChannelDomainArray("row"))!=null?o:["___SINGLE_ROW___"],S=u/R.length,X=!lt(a.row)||lt(a.row)&&typeof a.row.clip>"u"||a.row.clip,W=lt(a.y)?(A=a.y)==null?void 0:A.baseline:void 0,V=(s=I.encodedValue("y",W))!=null?s:0,H=e.graphics;if(IN(a)){const D=I.getGenomicChannel();if(!D||!D.field){console.warn("Genomic field is not provided in the specification");return}const Y=JT(l,_=>_[D.field]);[...Y.keys()].forEach(_=>{var J;let te=0;(J=Y.get(_))==null||J.forEach(q=>{const $=I.encodedPIXIProperty("color",q),j=I.encodedPIXIProperty("stroke",q),ee=I.encodedPIXIProperty("strokeWidth",q),Q=I.encodedPIXIProperty("opacity",q),ne=I.encodedPIXIProperty("y",q),fe=I.encodedPIXIProperty("width",q,{tileUnitWidth:w}),Ce=I.encodedPIXIProperty("x-start",q,{markWidth:fe}),Ze=Ce+fe,Ge=I.markVisibility(q,{width:fe,zoomLevel:h}),ve=Math.min(Ge,Q);if(ve===0||fe<=0||ne<=0)return;H.lineStyle(ee,ft(j),ve,0);let ke=[];if(m){const Xe=b-(S-te)/u*Z,Oe=b-(S-ne-te)/u*Z,ze=Lt(Ce,c,Oe,v,G,p,y),Me=qg(Ce,c,p,y),Ue=qg(Ce+fe,c,p,y);H.beginFill(ft($),$==="none"?0:ve),H.moveTo(ze.x,ze.y),H.arc(v,G,Oe,Me,Ue,!0),H.arc(v,G,Xe,Ue,Me,!1),ke=Array.from(H.currentPath.points),H.closePath()}else{H.beginFill(ft($),$==="none"?0:ve),H.drawRect(Ce,S-ne-te,fe,ne);const Xe=S-ne-te,Oe=Xe+ne;ke=[Ce,Xe,Ce,Oe,Ze,Oe,Ze,Xe]}I.getMouseEventModel().addPolygonBasedEvent(q,ke),te+=ne})})}else R.forEach(D=>{const Y=I.encodedValue("row",D);l.filter(F=>{const _=bI(F,a.row);return!_||_===D}).forEach(F=>{const _=I.encodedPIXIProperty("color",F),J=I.encodedPIXIProperty("stroke",F),te=I.encodedPIXIProperty("strokeWidth",F),q=I.encodedPIXIProperty("opacity");let $=I.encodedPIXIProperty("y",F),j=I.encodedPIXIProperty("ye",F);typeof j<"u"&&$>j&&([$,j]=[j,$]);const ee=I.encodedPIXIProperty("width",F,{tileUnitWidth:w}),Q=I.encodedPIXIProperty("x-start",F,{markWidth:ee}),ne=Q+ee;let fe;typeof j>"u"?(fe=Y+S-V-$,j=Y+S-V,(lt(a.y)&&a.y.flip||a.flipY)&&(j=fe,fe=Y)):(fe=Y+S-j,j=Y+S-$),X&&(fe=Math.max(Y,fe),fe=Math.min(fe,Y+S),j=Math.max(Y,j),j=Math.min(j,Y+S));const Ce=I.markVisibility(F,{width:ee,zoomLevel:h}),Ze=Math.min(Ce,q);if(Ze===0||ee===0||j-fe===0)return;H.lineStyle(te,ft(J),Ze,0);let Ge=[];if(m){const ve=b-fe/u*Z,ke=b-j/u*Z,Xe=Lt(Q,c,ke,v,G,p,y),Oe=qg(Q,c,p,y),ze=qg(Q+ee,c,p,y);H.beginFill(ft(_),_==="none"?0:Ze),H.moveTo(Xe.x,Xe.y),H.arc(v,G,ke,Oe,ze,!0),H.arc(v,G,ve,ze,Oe,!1),Ge=Array.from(H.currentPath.points),H.closePath()}else H.beginFill(ft(_),_==="none"?0:Ze),H.drawRect(Q,fe,ee,j-fe),Ge=[Q,fe,Q,j,ne,j,ne,fe];I.getMouseEventModel().addPolygonBasedEvent(F,Ge)})})}function e7e(g,e,I,i){const n=g.visualPropertyByChannel("x",I),C=g.visualPropertyByChannel("xe",I),r=g.visualPropertyByChannel("size",I);switch(e){case"width":return r??(C?C-n:i==null?void 0:i.tileUnitWidth);case"x-start":return i!=null&&i.markWidth?C?(n+C-(i==null?void 0:i.markWidth))/2:n-(i==null?void 0:i.markWidth)/2:void 0;default:return}}function t7e(g,e,I,i){var n,C,r,o,A,s;const a=i.spec(),l=i.data(),[c,u]=e.dimensions,d=a.layout==="circular",h=(n=a.innerRadius)!=null?n:220,m=(C=a.outerRadius)!=null?C:300,f=(r=a.startAngle)!=null?r:0,b=(o=a.endAngle)!=null?o:360,p=m-h,y=c/2,Z=u/2,v=e._xScale,G=(A=i.getChannelDomainArray("row"))!=null?A:["___SINGLE_ROW___"],B=u/G.length,w=(s=i.getChannelDomainArray("color"))!=null?s:["___SINGLE_COLOR___"],R=i.encodedPIXIProperty("opacity"),S=i.encodedPIXIProperty("strokeWidth"),X=i.encodedPIXIProperty("stroke"),W=I.graphics;if(IN(a)){const V=i.getGenomicChannel();if(!V||!V.field){console.warn("Genomic field is not provided in the specification");return}const H=JT(l,F=>F[V.field]),D=[...H.keys()];W.lineStyle(S,ft(X),R,1);const Y={};w.forEach(F=>{const _=[],J=[];D.forEach((q,$,j)=>{var ee,Q;(Q=(ee=H.get(q))==null?void 0:ee.filter(ne=>bI(ne,a.color)===F))==null||Q.forEach(ne=>{const fe=+q,Ce=v(fe),Ze=jG([i.encodedPIXIProperty("y",ne),0]);typeof Y[q]>"u"&&(Y[q]=0);const Ge=B-Ze-Y[q],ve=B-Y[q];if(d){if($===0){const Me=m-B/u*p,Ue=Lt(Ce,c,Me,y,Z,f,b);_.push([Ue.x,Ue.y]),J.push([Ue.x,Ue.y])}const ke=m-Ge/u*p,Xe=Lt(Ce,c,ke,y,Z,f,b);_.push([Xe.x,Xe.y]);const Oe=m-ve/u*p,ze=Lt(Ce,c,Oe,y,Z,f,b);if(J.push([ze.x,ze.y]),$===j.length-1){const Me=m-B/u*p,Ue=Lt(Ce,c,Me,y,Z,f,b);_.push([Ue.x,Ue.y]),J.push([Ue.x,Ue.y])}i.getMouseEventModel().addPointBasedEvent(ne,[ze.x,ze.y,1])}else $===0&&(_.push([Ce,B]),J.push([Ce,B])),_.push([Ce,Ge]),J.push([Ce,ve]),$===j.length-1&&(_.push([Ce,B]),J.push([Ce,B])),i.getMouseEventModel().addPointBasedEvent(ne,[Ce,Ge,1]);Y[q]+=Ze})});const te=i.encodedValue("color",F);W.beginFill(ft(te),R),W.drawPolygon([..._.reduce((q,$)=>q.concat($)),...J.reverse().reduce((q,$)=>q.concat($))]),W.endFill()})}else G.forEach(V=>{const H=i.encodedValue("row",V);W.lineStyle(S,ft(X),R,0),w.forEach(D=>{const Y=[],F=[],_=m-(H+B)/u*p;let J=0;l.filter(q=>(typeof bI(q,a.row)>"u"||bI(q,a.row)===V)&&(typeof bI(q,a.color)>"u"||bI(q,a.color)===D)).sort((q,$)=>i.encodedPIXIProperty("x",q)-i.encodedPIXIProperty("x",$)).forEach((q,$,j)=>{const ee=P1([jG([i.encodedPIXIProperty("y",q),0]),B]),Q=i.encodedPIXIProperty("x",q);if(d){const ne=Lt(Q,c,_,y,Z,f,b);Y.push([ne.x,ne.y]),$===0&&F.push(ne.x,ne.y);const fe=m-(H+B-ee)/u*p,Ce=Lt(Q,c,fe,y,Z,f,b);if(F.push(Ce.x,Ce.y),$===j.length-1){const Ze=m-(H+B)/u*p,Ge=Lt(Q,c,Ze,y,Z,f,b);F.push(Ge.x,Ge.y)}i.getMouseEventModel().addPointBasedEvent(q,[Ce.x,Ce.y,1])}else $===0&&(F.push(Q,H+B),J=Q),F.push(Q,H+B-ee),$===j.length-1&&(F.push(Q,H+B),F.push(J,H+B)),i.getMouseEventModel().addPointBasedEvent(q,[Q,H+B-ee,1])}),d&&Y.length!==0&&F.push(...Y.reverse().reduce((q,$)=>q.concat($)));const te=i.encodedValue("color",D);W.beginFill(ft(te),R),W.drawPolygon(F),W.endFill()})})}function g7e(g,e,I,i){var n,C,r,o,A,s;const a=i.spec(),l=i.data(),[c,u]=e.dimensions,d=a.layout==="circular",h=(n=a.innerRadius)!=null?n:220,m=(C=a.outerRadius)!=null?C:300,f=(r=a.startAngle)!=null?r:0,b=(o=a.endAngle)!=null?o:360,p=m-h,y=c/2,Z=u/2,v=e._xScale;let G;if(I.tileData.tilePos){const V=e.tilesetInfo.tile_size,{tileX:H,tileWidth:D}=e.getTilePosAndDimensions(I.tileData.zoomLevel,I.tileData.tilePos,V);G=v(H+D/V)-v(H)}const B=(A=i.getChannelDomainArray("row"))!=null?A:["___SINGLE_ROW___"],w=u/B.length,R=lt(a.row)&&a.row.padding?a.row.padding:0,S=(s=i.getChannelDomainArray("y"))!=null?s:["___SINGLE_Y_POSITION___"],X=w/S.length-R*2,W=I.graphics;l.forEach(V=>{var H;const D=i.encodedPIXIProperty("row",V)+R,Y=i.encodedPIXIProperty("x",V),F=i.encodedPIXIProperty("color",V),_=i.encodedPIXIProperty("stroke",V),J=i.encodedPIXIProperty("strokeWidth",V),te=i.encodedPIXIProperty("opacity",V),q=i.encodedPIXIProperty("width",V,{markWidth:G}),$=i.encodedPIXIProperty("height",V,{markHeight:X}),j=i.encodedPIXIProperty("y",V),ee=i.markVisibility(V,{width:q,zoomLevel:e._xScale.invert(c)-e._xScale.invert(0)}),Q=Math.min(ee,te);if(Q===0||$===0||q<=1e-4)return;const[ne,fe,Ce,Ze]=[Y,Y+q,D+w-j-$/2,D+w-j+$/2],Ge=(H=i.visualPropertyByChannel("size",V))!=null?H:void 0;W.lineStyle(J,ft(_),Q,.5);let ve=[];if(d){if(fe<0||c{const S=e.encodedValue("row",R);c.filter(X=>!bI(X,l.row)||bI(X,l.row)===R).forEach(X=>{var W,V,H;const D=e.encodedPIXIProperty("x",X),Y=e.encodedPIXIProperty("xe",X),F=(W=e.encodedPIXIProperty("size",X))!=null?W:Y===void 0?w:Y-D,_=e.encodedPIXIProperty("y",X),J=e.encodedPIXIProperty("strokeWidth",X),te=e.encodedPIXIProperty("stroke",X),q=e.encodedPIXIProperty("color",X),$=e.encodedPIXIProperty("opacity",X);let j=[];if(d){let ee=D||Y-F,Q=Y||D+F,ne=(ee+Q)/2;const fe=m-(S+G-_)/i*p,Ce=fe-w/2,Ze=fe+w/2;if(((V=l.style)==null?void 0:V.align)==="right"&&!Y&&(ee-=F,Q-=F,ne-=F),l.mark==="triangleLeft"){const ke=Lt(Q,I,Ce,y,Z,f,b),Xe=Lt(ee,I,fe,y,Z,f,b),Oe=Lt(Q,I,Ze,y,Z,f,b),ze=Lt(Q,I,Ce,y,Z,f,b);j=[ke.x,ke.y,Xe.x,Xe.y,Oe.x,Oe.y,ze.x,ze.y]}else if(l.mark==="triangleRight"){const ke=Lt(ee,I,Ce,y,Z,f,b),Xe=Lt(Q,I,fe,y,Z,f,b),Oe=Lt(ee,I,Ze,y,Z,f,b),ze=Lt(ee,I,Ce,y,Z,f,b);j=[ke.x,ke.y,Xe.x,Xe.y,Oe.x,Oe.y,ze.x,ze.y]}else if(l.mark==="triangleBottom"){ee=ne-F/2,Q=ne+F/2;const ke=Lt(ee,I,Ze,y,Z,f,b),Xe=Lt(Q,I,Ze,y,Z,f,b),Oe=Lt(ne,I,Ce,y,Z,f,b),ze=Lt(ee,I,Ze,y,Z,f,b);j=[ke.x,ke.y,Xe.x,Xe.y,Oe.x,Oe.y,ze.x,ze.y]}const Ge=e.markVisibility(X,{width:Q-ee,zoomLevel:u}),ve=Math.min(Ge,$);g.lineStyle(J,ft(te),Q-ee>2?ve:0,0),g.beginFill(ft(q),ve),g.drawPolygon(j),g.endFill()}else{let ee=D||Y-F,Q=Y||D+F,ne=ee+(Q-ee)/2;const fe=S+G-_,Ce=S+G-_-w/2,Ze=S+G-_+w/2;((H=l.style)==null?void 0:H.align)==="right"&&!Y&&(ee-=F,Q-=F,ne-=F),j={triangleLeft:[Q,Ce,ee,fe,Q,Ze,Q,Ce],triangleRight:[ee,Ce,Q,fe,ee,Ze,ee,Ce],triangleBottom:[ee,Ce,Q,Ce,ne,Ze,ee,Ce]}[l.mark];const Ge=e.markVisibility(X,{width:Q-ee,zoomLevel:u}),ve=Math.min(Ge,$);g.lineStyle(J,ft(te),Q-ee>2?ve:0,.5),g.beginFill(ft(q),ve),g.drawPolygon(j),g.endFill()}e.getMouseEventModel().addPolygonBasedEvent(X,j)})})}const VA={fontSize:"12px",fontFamily:"sans-serif",fontWeight:"normal",fill:"black",background:"white",lineJoin:"round",stroke:"#ffffff",strokeThickness:0};function n7e(g,e,I,i){var n,C,r,o,A,s,a,l,c,u;const d=i.spec(),h=i.data(),[m,f]=e.dimensions,b=d.layout==="circular",p=(n=d.innerRadius)!=null?n:220,y=(C=d.outerRadius)!=null?C:300,Z=(r=d.startAngle)!=null?r:0,v=(o=d.endAngle)!=null?o:360,G=y-p,B=m/2,w=f/2,R=(A=i.getChannelDomainArray("row"))!=null?A:["___SINGLE_ROW___"],S=f/R.length,X=(a=(s=d.style)==null?void 0:s.dx)!=null?a:0,W=(c=(l=d.style)==null?void 0:l.dy)!=null?c:0,V=(u=d.style)!=null&&u.textAnchor?d.style.textAnchor:"middle";if(IN(d)){if(b)return;const H=I.graphics,D=i.getGenomicChannel();if(!D||!D.field){console.warn("Genomic field is not provided in the specification");return}const Y=JT(h,_=>_[D.field]);[...Y.keys()].forEach(_=>{var J;let te=0;(J=Y.get(_))==null||J.forEach(q=>{var $,j,ee,Q,ne,fe,Ce,Ze;const Ge=i.encodedPIXIProperty("text",q),ve=i.encodedPIXIProperty("color",q),ke=i.encodedPIXIProperty("x",q)+X,Xe=i.encodedPIXIProperty("xe",q)+X,Oe=i.encodedPIXIProperty("x-center",q)+X,ze=i.encodedPIXIProperty("y",q)+W,Me=i.encodedPIXIProperty("size",q),Ue=i.encodedPIXIProperty("stroke",q),_e=i.encodedPIXIProperty("strokeWidth",q),At=i.encodedPIXIProperty("opacity",q);if(Oe<0||Oe>m||e.textsBeingUsed>1e3)return;const wt={...VA,fontSize:Me??(($=d.style)!=null&&$.textFontSize?`${(j=d.style)==null?void 0:j.textFontSize}px`:VA.fontSize),stroke:(Q=Ue??((ee=d.style)==null?void 0:ee.textStroke))!=null?Q:VA.stroke,strokeThickness:(fe=_e??((ne=d.style)==null?void 0:ne.textStrokeWidth))!=null?fe:VA.strokeThickness,fontWeight:(Ze=(Ce=d.style)==null?void 0:Ce.textFontWeight)!=null?Ze:VA.fontWeight},rt=new g.libraries.PIXI.TextStyle(wt);let Te;e.textGraphics.length>e.textsBeingUsed?(Te=e.textGraphics[e.textsBeingUsed],Te.style.fill=ve,Te.visible=!0,Te.text=Ge,Te.alpha=1):(Te=new g.libraries.PIXI.Text(Ge,{...wt,fill:ve}),e.textGraphics.push(Te));const le=g.libraries.PIXI.TextMetrics.measureText(Ge,rt);e.textsBeingUsed++;const ye=i.markVisibility(q,{...le,zoomLevel:e._xScale.invert(m)-e._xScale.invert(0)}),We=Math.min(ye,At);if(!Ge||We===0){e.textsBeingUsed--,Te.visible=!1;return}Te.alpha=We,Te.resolution=8,Te.updateText(),Te.texture.baseTexture.scaleMode=g.libraries.PIXI.SCALE_MODES.LINEAR;const K=new g.libraries.PIXI.Sprite(Te.texture);K.x=ke,K.y=S-ze-te,K.width=Xe-ke,K.height=ze,H.addChild(K),te+=ze})})}else R.forEach(H=>{const D=I.graphics,Y=i.encodedValue("row",H);h.filter(F=>!bI(F,d.row)||bI(F,d.row)===H).forEach(F=>{var _,J,te,q,$,j,ee,Q;const ne=i.encodedPIXIProperty("text",F),fe=i.encodedPIXIProperty("color",F),Ce=i.encodedPIXIProperty("x-center",F)+X,Ze=i.encodedPIXIProperty("y",F)+W,Ge=i.encodedPIXIProperty("size",F),ve=i.encodedPIXIProperty("stroke",F),ke=i.encodedPIXIProperty("strokeWidth",F),Xe=i.encodedPIXIProperty("opacity",F);if(Ce<0||Ce>m||e.textsBeingUsed>1e3)return;const Oe={...VA,fontSize:Ge??((_=d.style)!=null&&_.textFontSize?`${(J=d.style)==null?void 0:J.textFontSize}px`:VA.fontSize),stroke:(q=ve??((te=d.style)==null?void 0:te.textStroke))!=null?q:VA.stroke,strokeThickness:(j=ke??(($=d.style)==null?void 0:$.textStrokeWidth))!=null?j:VA.strokeThickness,fontWeight:(Q=(ee=d.style)==null?void 0:ee.textFontWeight)!=null?Q:VA.fontWeight},ze=new g.libraries.PIXI.TextStyle(Oe);let Me;e.textGraphics.length>e.textsBeingUsed?(Me=e.textGraphics[e.textsBeingUsed],Me.style.fill=fe,Me.visible=!0,Me.text=ne,Me.alpha=1):(Me=new g.libraries.PIXI.Text(ne,{...Oe,fill:fe}),e.textGraphics.push(Me));const Ue=g.libraries.PIXI.TextMetrics.measureText(ne,ze);e.textsBeingUsed++;const _e=i.markVisibility(F,{...Ue,zoomLevel:e._xScale.invert(m)-e._xScale.invert(0)}),At=Math.min(_e,Xe);if(!ne||At===0){e.textsBeingUsed--,Me.visible=!1;return}Me.alpha=At,Me.anchor.y=.5,Me.anchor.x=V==="middle"?.5:V==="start"?0:1;let wt=[];if(b){const rt=y-(Y+S-Ze)/f*G,Te=Lt(Ce,m,rt,B,w,Z,v);Me.x=Te.x,Me.y=Te.y,Me.resolution=4;const le=Ue.width/(2*rt*Math.PI)*m;let[ye,We]=[Ce-le/2,Ce+le/2];if(ye<0){const he=-ye;ye=0,We+=he}else if(We>m){const he=We-m;We=m,ye-=he}const K=[],T=[],k=[];for(let he=We;he>=ye;he-=le/10){const we=Lt(he,m,rt,B,w,Z,v);K.push(new g.libraries.PIXI.Point(we.x,we.y));const xe=Lt(he,m,rt+Ue.height/2,B,w,Z,v),qe=Lt(he,m,rt-Ue.height/2,B,w,Z,v);T.push(xe.x,xe.y),he===We&&k.push(xe.y,xe.x),k.push(qe.y,qe.x)}Me.updateText();const ge=new g.libraries.PIXI.SimpleRope(Me.texture,K);ge.alpha=At,D.addChild(ge),k.reverse(),wt=T.concat(k)}else{Me.position.x=Ce,Me.position.y=Y+S-Ze,D.addChild(Me);const{height:rt,width:Te}=Ue,le=Me.position.y-rt/2,ye=le+rt;let We=0,K=0;V==="start"?(We=Ce,K=Ce+Te):V==="middle"?(We=Ce-Te/2,K=Ce+Te/2):(We=Ce-Te,K=Ce),wt=[We,le,We,ye,K,ye,K,le]}i.getMouseEventModel().addPolygonBasedEvent(F,wt)})})}function C7e(g,e,I,i){var n,C,r,o,A,s,a,l;const c=i.spec(),u=i.data(),[d,h]=e.dimensions,m=c.layout==="circular",f=(n=c.innerRadius)!=null?n:220,b=(C=c.outerRadius)!=null?C:300,p=(r=c.startAngle)!=null?r:0,y=(o=c.endAngle)!=null?o:360,Z=b-f,v=d/2,G=h/2,B=(A=i.getChannelDomainArray("row"))!=null?A:["___SINGLE_ROW___"],w=h/B.length,R=(s=c.style)==null?void 0:s.dashed,S=(a=c.style)==null?void 0:a.linePattern,X=(l=c.style)==null?void 0:l.curve,W=I.graphics;B.forEach(V=>{const H=i.encodedValue("row",V);u.filter(D=>!bI(D,c.row)||bI(D,c.row)===V).forEach(D=>{const Y=i.encodedPIXIProperty("x",D),F=i.encodedPIXIProperty("xe",D),_=i.encodedPIXIProperty("y",D),J=i.encodedPIXIProperty("color",D),te=i.encodedPIXIProperty("strokeWidth",D),q=i.encodedPIXIProperty("opacity",D),$=i.markVisibility(D,{width:F-Y,zoomLevel:e._xScale.invert(d)-e._xScale.invert(0)}),j=Math.min($,q);if(W.lineStyle(te,ft(J),j,.5),!F&&(!c.y||!("field"in c.y))){if(m)return;if(R){const[ee,Q]=R;let ne=0;do W.moveTo(Y,ne),W.lineTo(Y,ne+ee),ne+=ee+Q;while(ne{const H=I.encodedValue("row",V);d.filter(D=>!bI(D,u.row)||bI(D,u.row)===V).forEach(D=>{var Y,F,_,J,te;let q=I.encodedPIXIProperty("x",D),$=I.encodedPIXIProperty("xe",D),j=I.encodedPIXIProperty("x1",D),ee=I.encodedPIXIProperty("x1e",D);const Q=I.encodedPIXIProperty("y",D),ne=I.encodedPIXIProperty("ye",D),fe=I.encodedPIXIProperty("stroke",D),Ce=I.encodedPIXIProperty("strokeWidth",D),Ze=I.encodedPIXIProperty("color",D),Ge=I.encodedPIXIProperty("opacity",D);typeof $<"u"&&([q,$]=[q,$].sort((ze,Me)=>ze-Me)),typeof j<"u"&&typeof ee<"u"&&([j,ee]=[j,ee].sort((ze,Me)=>ze-Me));const ve=typeof $<"u"&&typeof j<"u"&&typeof ee<"u"&&Math.abs(q-$)>.1&&Math.abs(j-ee)>.1;if(!ve&&$===void 0&&!IC(u)){if(j===void 0&&ee===void 0)return;$=j!==void 0?j:ee}!ve&&Math.abs(q-$)<=.1&&Math.abs(j-ee)<=.1&&(q=(q+$)/2,$=(j+ee)/2),g.lineStyle(Ce,ft(fe),Ge,.5);const ke=lt(u.y)&&u.y.flip||u.flipY,Xe=(Y=u.baselineY)!=null?Y:H+(ke?0:R);let Oe=[];if(ve){g.beginFill(ft(Ze==="none"?"white":Ze),Ze==="none"?0:Ge);let[ze,Me,Ue,_e]=[q,$,j,ee];if([ze,Me,Ue,_e]=[ze,Me,Ue,_e].sort((At,wt)=>At-wt),ze>h||_e<0||Math.abs(_e-ze)<.5)return;if(f){if(ze<0||_e>h)return;const At=p-H/m*v,wt=Lt(ze,h,At,G,B,y,Z),rt=Lt(Me,h,At,G,B,y,Z),Te=Lt(Ue,h,At,G,B,y,Z),le=Lt(_e,h,At,G,B,y,Z);g.moveTo(wt.x,wt.y),g.bezierCurveTo(G,B,G,B,le.x,le.y),g.arc(G,B,p,vc(le.x,le.y,G,B),vc(Te.x,Te.y,G,B),!1),g.bezierCurveTo(G,B,G,B,rt.x,rt.y),g.arc(G,B,p,vc(rt.x,rt.y,G,B),vc(wt.x,wt.y,G,B),!1),Oe=Array.from(g.currentPath.points),g.endFill()}else g.moveTo(ze,Xe),!((F=u.style)!=null&&F.linkStyle)||((_=u.style)==null?void 0:_.linkStyle)==="circular"?(g.arc((ze+_e)/2,Xe,(_e-ze)/2,-Math.PI,Math.PI,!1),g.arc((Me+Ue)/2,Xe,(Ue-Me)/2,Math.PI,-Math.PI,!0),Oe=Array.from(g.currentPath.points),g.closePath()):(g.lineTo(Ue,H+R),g.bezierCurveTo(Ue+(Me-Ue)/3,H+R-(Me-Ue)/2,Ue+(Me-Ue)/3*2,H+R-(Me-Ue)/2,Me,H+R),g.lineTo(_e,H+R),g.bezierCurveTo(ze+(_e-ze)/3*2,H+R-(_e-ze)/2,ze+(_e-ze)/3,H+R-(_e-ze)/2,ze,H+R),Oe=Array.from(g.currentPath.points),g.endFill());I.getMouseEventModel().addPolygonBasedEvent(D,Oe)}else{const ze=(q+$)/2;if(g.beginFill(ft("white"),0),f){if(q<0||$>h)return;if(((J=u.style)==null?void 0:J.linkStyle)==="straight"){const Me=p-H/m*v,Ue=Lt(q,h,Me,G,B,y,Z),_e=Lt($,h,Me,G,B,y,Z),At=Ue.x,wt=Ue.y,rt=_e.x,Te=_e.y;g.moveTo(At,wt),g.lineTo(rt,Te);const le=100;Oe=Array.from({length:le},(We,K)=>({x:(rt-At)/(le-1)*K+At,y:(Te-wt)/(le-1)*K+wt})).flatMap(We=>[We.x,We.y])}else{const Me=p-H/m*v,Ue=Lt(q,h,Me,G,B,y,Z),_e=Lt($,h,Me,G,B,y,Z),At=Ue.x,wt=Ue.y,rt=Ue.x,Te=Ue.y,le=h/2,ye=m/2,We=_e.x,K=_e.y;g.moveTo(At,wt);const T=new ti(At,wt,rt,Te,le,ye,We,K);T.getLUT(14).forEach(he=>g.lineTo(he.x,he.y)),Oe=T.getLUT(1e3).flatMap(he=>[he.x,he.y])}}else if(((te=u.style)==null?void 0:te.linkStyle)==="elliptical"){if(!(0<=q&&q<=h)&&!(0<=$&&$<=h))return;const Me=[],Ue=lt(u.y);for(let _e=0;_e<=X;_e++){const At=Math.PI*(_e/X),wt=($-q)/2*Math.cos(At)+(q+$)/2;let rt=Xe-Q*Math.sin(At)*(Ue?1:Math.min($-q+h*S,h)/h)*(ke?-1:1);if(typeof Q<"u"&&typeof ne<"u"){const Te=Math.abs(ne-Q),le=ne>Q;rt=Q-Te*Math.sin(At)*(le?-1:1)}if(_e===0)if(W){const Te=ke?Xe-m:Xe;g.moveTo(wt,Te),Me.push({x:wt,y:Te}),g.lineTo(wt,rt)}else g.moveTo(wt,rt);else g.lineTo(wt,rt);if(Me.push({x:wt,y:rt}),_e===X&&W){const Te=ke?Xe-m:Xe;g.lineTo(wt,Te),Me.push({x:wt,y:Te})}}Oe=Me.flatMap(_e=>[_e.x,_e.y])}else{if($<0||q>h)return;g.arc(ze,Xe,($-q)/2,-Math.PI,Math.PI),Oe=Array.from(g.currentPath.points),g.closePath()}I.getMouseEventModel().addLineBasedEvent(D,Oe)}})})}function o7e(g,e,I){return[...g.slice(0,e),I,...g.slice(e)]}function A7e(g){const e=[];for(let I=0;Itypeof e=="number")}function vbe(g){return Bbe(g,e=>typeof e=="string")}function a7e(g,e,I){l7e(g,e,I),s7e(g,e,I)}function s7e(g,e,I){var i,n,C,r;const o=e.spec();if(!lt(o.row)||o.row.grid!==!0)return;const[A,s]=g.position,[a,l]=g.dimensions,c=e.spec().layout==="circular",u=(i=o.innerRadius)!=null?i:220,d=(n=o.outerRadius)!=null?n:300,h=(C=o.startAngle)!=null?C:0,m=(r=o.endAngle)!=null?r:360,f=d-u,b=a/2,p=l/2,y=e.getChannelDomainArray("row");if(!y)return;const Z=l/y.length;if(c&&f<=20||!c&&Z<=20)return;const v=g.pBackground,G=I.axis.gridStrokeWidth;y.forEach(B=>{const w=e.encodedValue("row",B);if(c){const R=w+Z/2,S=d-R/l*f,X=S+G/2,W=S-G/2,V=Lt(0,a,W,b,p,h,m),H=qg(0,a,h,m),D=qg(a,a,h,m);v.lineStyle(G,ft("black"),0,.5),v.beginFill(ft(I.axis.gridColor),1),v.moveTo(A+V.x,s+V.y),v.arc(A+b,s+p,W,H,D,!0),v.arc(A+b,s+p,X,D,H,!1),v.closePath()}else{v.lineStyle(G,ft(I.axis.gridColor),1,.5);const R=s+w+Z/2;v.moveTo(A,R),v.lineTo(A+a,R)}})}function l7e(g,e,I){var i,n,C,r,o;const A=e.spec();if(!lt(A.y)||A.y.grid!==!0)return;const[s,a]=g.position,[l,c]=g.dimensions,u=s,d=s+l,h=e.spec().layout==="circular",m=(i=A.innerRadius)!=null?i:220,f=(n=A.outerRadius)!=null?n:300,b=(C=A.startAngle)!=null?C:0,p=(r=A.endAngle)!=null?r:360,y=f-m,Z=l/2,v=c/2,G=(o=e.getChannelDomainArray("row"))!=null?o:["___SINGLE_ROW___"],B=c/G.length;if(!vbe(G))return;const w=e.getChannelScale("y"),R=e.getChannelDomainArray("y");if(!w||!R||!zU(R)||h&&B/c*y<=20||!h&&B<=20)return;const S=g.pBackground,X=I.axis.gridStrokeWidth;G.forEach(W=>{const V=e.encodedValue("row",W),H=h?B/c*y:B,D=Math.max(Math.ceil(H/40),1);let Y=w.ticks(D).filter(F=>R[0]<=F&&F<=R[1]);Y.length===1&&(Y=w.ticks(D+1).filter(F=>R[0]<=F&&F<=R[1])),h?Y.forEach(F=>{const _=w(F),J=f-(V+B-_)/c*y,te=J+X/2,q=J-X/2,$=Lt(0,l,q,Z,v,b,p),j=qg(0,l,b,p),ee=qg(l,l,b,p);S.lineStyle(X,ft("black"),0,.5),S.beginFill(ft(I.axis.gridColor),1),S.moveTo(s+$.x,a+$.y),S.arc(s+Z,a+v,q,j,ee,!0),S.arc(s+Z,a+v,te,ee,j,!1),S.closePath()}):(S.lineStyle(X,ft(I.axis.gridColor),1,.5),Y.forEach(F=>{var _;const J=a+V+B-w(F);if(I.axis.gridStrokeType==="solid")S.moveTo(u,J),S.lineTo(d,J);else if(I.axis.gridStrokeType==="dashed"){const[te,q]=(_=I.axis.gridStrokeDash)!=null?_:[1,1];for(let $=u;$=R;D-=w/10){const Y=Lt(D,a,b-B.height/2,h,m,u,d);X.push(new g.libraries.PIXI.Point(Y.x,Y.y))}const W=qg(R,a,u,d),V=qg(S+p,a,u,d);f.lineStyle(1,ft("red"),0,.5),f.beginFill(ft(n.track.titleBackground),.5),f.moveTo(y.x,y.y),f.arc(h,m,b-B.height,W,V,!0),f.arc(h,m,b,V,W,!1),f.closePath(),v.updateText();const H=new g.libraries.PIXI.SimpleRope(v.texture,X);f.addChild(H)}function u7e(g,e,I){var i,n,C,r;const o=g.pBorder,[A,s]=g.position,[a,l]=g.dimensions;o.lineStyle((n=(i=e.spec().style)==null?void 0:i.outlineWidth)!=null?n:1,ft((r=(C=e.spec().style)==null?void 0:C.outline)!=null?r:I.track.outline),1,.5),o.beginFill(ft("white"),0),o.drawRect(A,s,a,l);const c=e.spec().x;o.lineStyle(1,ft(I.axis.baselineColor),1,.5),lt(c)&&c.axis==="top"?(o.moveTo(A,s),o.lineTo(A+a,s)):lt(c)&&c.axis==="bottom"&&(o.moveTo(A,s+l),o.lineTo(A+a,s+l))}function d7e(g,e,I,i,n){if(!e.gLegend)return;e.gLegend.selectAll(".brush").remove();const C=i.spec(),r={offsetRight:0};if(lt(C.color)&&C.color.legend)switch(C.color.type){case"nominal":h7e(g,e,I,i,n);break;case"quantitative":Ste(g,e,I,i,n,"color",r);break}if(lt(C.stroke)&&C.stroke.legend)switch(C.stroke.type){case"quantitative":Ste(g,e,I,i,n,"stroke",r);break}}function Ste(g,e,I,i,n,C,r){const o=i.spec(),A=o[C];if(!lt(A)||A.type!=="quantitative"||!A.legend)return;const[s,a]=e.position,[l,c]=e.dimensions,u=80,d=c-2>110?110:Math.max(c-2,40-2),h={top:10,left:55,width:20,height:d-20},m=s+l-u-1-r.offsetRight,f=a+1,b=i.getChannelScale(C),p=i.getChannelDomainArray(C);if(!b||!p)return;const y=e.pBorder;if(y.beginFill(ft(n.legend.background),n.legend.backgroundOpacity),y.lineStyle(1,ft(n.legend.backgroundStroke),n.legend.backgroundOpacity,0),y.drawRect(m,f,u,d),A.title){const H=A.title,D=Os({color:n.legend.labelColor,size:n.legend.labelFontSize,fontWeight:n.legend.labelFontWeight,fontFamily:n.legend.labelFontFamily}),Y=new g.libraries.PIXI.Text(H,{...D,fontWeight:"bold"});Y.anchor.x=0,Y.anchor.y=0,Y.position.x=m+10,Y.position.y=f+10;const F=new g.libraries.PIXI.TextStyle({...D,fontWeight:"bold"}),_=g.libraries.PIXI.TextMetrics.measureText(H,F);y.addChild(Y),h.top+=_.height+4,h.height-=_.height+4}const[Z,v]=p,G=v-Z,B=lt(A)&&A.scaleOffset?A.scaleOffset:[0,1];[...Array(h.height).keys()].forEach(H=>{let D;const Y=Array.from(B).sort();if(H/h.height>=Y[1])D=v;else if(H/h.height<=Y[0])D=Z;else{const F=nh().domain([h.height*Y[0],h.height*Y[1]]).range([0,h.height]);D=nh().domain([0,h.height]).range([Z,v])(F(H))}y.beginFill(ft(b(D)),1),y.lineStyle(1,ft(n.legend.backgroundStroke),0,.5),y.drawRect(m+h.left,f+h.top+h.height-H,h.width,1)});const w=4;e.colorBrushes=e.gLegend.append("g").attr("class",C).selectAll(".brush").data(B.map((H,D)=>({y:H,id:D}))).enter().append("rect").attr("class","brush").attr("pointer-events","all").attr("cursor","ns-resize").attr("transform",H=>`translate(${m+h.left}, ${f+h.top-w/2+h.height-h.height*H.y})`).attr("width",`${h.width}px`).attr("height",`${w}px`).attr("fill","lightgrey").attr("stroke","black").attr("stroke-width","0.5px").call(g.libraries.d3Drag.drag().on("start",H=>{e.startEvent=H.sourceEvent}).on("drag",(H,D)=>{if(A&&A.scaleOffset){const Y=H.sourceEvent,F=e.startEvent.clientY-Y.clientY,_=[A.scaleOffset[0],A.scaleOffset[1]];D.id===0?_[0]+=F/h.height:_[1]+=F/h.height,_[0]=Math.min(1,Math.max(0,_[0])),_[1]=Math.min(1,Math.max(0,_[1])),e.updateScaleOffsetFromOriginalSpec(o._renderingId,_,C),e.shareScaleOffsetAcrossTracksAndTiles(_,C),e.draw(),e.startEvent=H.sourceEvent}}));const R=Math.max(Math.ceil(h.height/30),2);let S=b.ticks(R).filter(H=>p[0]<=H&&H<=p[1]);S.length===1&&(S=b.ticks(R+1).filter(H=>p[0]<=H&&H<=p[1]));const X=1;y.lineStyle(X,ft(n.legend.tickColor),1,.5);const W=Os({color:n.legend.labelColor,size:n.legend.labelFontSize,fontWeight:n.legend.labelFontWeight,fontFamily:n.legend.labelFontFamily}),V=m+h.left;S.forEach(H=>{let D=f+h.top+h.height-(H-Z)/G*h.height;D===f+h.top?D+=X/2:D===f+h.top+h.height&&(D-=X/2),y.moveTo(V-3,D),y.lineTo(V,D);const Y=new g.libraries.PIXI.Text(H,W);Y.anchor.x=1,Y.anchor.y=.5,Y.position.x=V-6,Y.position.y=D,y.addChild(Y)}),r.offsetRight=l-m}function h7e(g,e,I,i,n){var C,r,o,A,s;const a=i.spec();if(!lt(a.color)||a.color.type!=="nominal"||!a.color.legend)return;const l=(C=i.getChannelDomainArray("color"))!=null?C:["___SINGLE_COLOR___"];if(l.length===0)return;const c=a.color.domain,u=a.color.range,d=e.displayedLegends,h=G=>typeof G=="string"?G:G.join();if(d.find(G=>h(G.domain)===h(c)&&h(G.range)===h(u)))return;d.push({domain:c,range:u});const m=e.pBorder,f=10,b=4;let p=b,y=0;const Z=[],v=Os({color:n.legend.labelColor,size:n.legend.labelFontSize,fontWeight:n.legend.labelFontWeight,fontFamily:n.legend.labelFontFamily});if((r=a.style)!=null&&r.inlineLegend)l.map(G=>G).reverse().forEach(G=>{if(y>e.dimensions[0])return;const B=i.encodedValue("color",G),w=new g.libraries.PIXI.Text(G,v);w.anchor.x=1,w.anchor.y=0,w.position.x=e.position[0]+e.dimensions[0]-y-f,w.position.y=e.position[1]+b,m.addChild(w);const R=new g.libraries.PIXI.TextStyle(v),S=g.libraries.PIXI.TextMetrics.measureText(G,R);p{if(p>e.dimensions[1])return;const B=i.encodedValue("color",G),w=new g.libraries.PIXI.Text(G,v);w.anchor.x=1,w.anchor.y=0,w.position.x=e.position[0]+e.dimensions[0]-f,w.position.y=e.position[1]+p,m.addChild(w);const R=new g.libraries.PIXI.TextStyle(v),S=g.libraries.PIXI.TextMetrics.measureText(G,R);y{m.lineStyle(1,ft("black"),0,0),m.beginFill(ft(G.color),1),m.drawCircle(G.x,G.y,4)})}function m7e(g,e,I,i,n){var C;const r=i.spec();if(!lt(r.row)||r.row.type!=="nominal"||!r.row.legend)return;const o=(C=i.getChannelDomainArray("row"))!=null?C:["___SINGLE_ROW___"];if(o.length===0)return;const A=e.pBorder,s=4,a=2,l=Os({color:n.legend.labelColor,size:n.legend.labelFontSize,fontWeight:n.legend.labelFontWeight,fontFamily:n.legend.labelFontFamily});o.forEach(c=>{const u=i.encodedValue("row",c),d=new g.libraries.PIXI.Text(c,l);d.anchor.x=0,d.anchor.y=0,d.position.x=e.position[0]+s,d.position.y=e.position[1]+u+a,A.addChild(d);const h=new g.libraries.PIXI.TextStyle(l),m=g.libraries.PIXI.TextMetrics.measureText(c,h);A.beginFill(ft(n.legend.background),n.legend.backgroundOpacity),A.lineStyle(1,ft(n.legend.backgroundStroke),0,0),A.drawRect(e.position[0]+1,e.position[1]+u+1,m.width+s*2,m.height+a*2)})}const t3=8,JZ=6;function f7e(g,e,I,i,n){var C;const r=i.spec(),o=r.layout==="circular",A=i.getChannelDomainArray("y"),s=i.getChannelRangeArray("y");if(o||!i.isShowYAxis()||!A||!s||!zU(A))return;const[a,l]=e.dimensions,[c,u]=e.position,d=(C=i.getChannelDomainArray("row"))!=null?C:["___SINGLE_ROW___"];if(!vbe(d))return;const h=l/d.length;if(h<=20)return;const m=i.spec().y,f=!(lt(m)&&"axis"in m&&m.axis==="right"),b=nh().domain(A).range(s),p=e.pBorder;d.forEach(y=>{const Z=i.encodedValue("row",y),v=f?c:c+a,G=u+Z;p.lineStyle(1,ft(n.axis.baselineColor),1,.5),p.moveTo(v,G),p.lineTo(v,G+h);const B=Math.max(Math.ceil(h/40),1);let w=b.ticks(B).filter(X=>A[0]<=X&&X<=A[1]);w.length===1&&(w=b.ticks(B+1).filter(X=>A[0]<=X&&X<=A[1])),p.lineStyle(1,ft(n.axis.tickColor),1,.5);let R=f?v+JZ:v-JZ;w.forEach(X=>{const W=b(X);p.moveTo(v,G+h-W),p.lineTo(R,G+h-W)}),R=f?v+t3:v-t3,p.moveTo(v,G),p.lineTo(R,G),p.moveTo(v,G+h),p.lineTo(R,G+h);const S=Os({color:n.axis.labelColor,size:n.axis.labelFontSize,fontFamily:n.axis.labelFontFamily,fontWeight:n.axis.labelFontWeight});w.forEach(X=>{const W=b(X);R=f?v+JZ*2:v-JZ*2;const V=new g.libraries.PIXI.Text(X,S);V.anchor.x=f?0:1,V.anchor.y=W===0?.9:.5,V.position.x=R,V.position.y=G+h-W,r.orientation==="vertical"&&(V.anchor.x=f?1:0,V.scale.x*=-1),p.addChild(V)})})}function p7e(g,e,I,i,n){var C,r,o,A,s;const a=i.spec(),l=a.layout==="circular",c=i.getChannelDomainArray("y"),u=i.getChannelRangeArray("y");if(!l||!i.isShowYAxis()||!c||!u||!zU(c))return;const[d,h]=e.dimensions,m=(C=a.innerRadius)!=null?C:220,f=(r=a.outerRadius)!=null?r:300,b=f-m,p=(o=a.startAngle)!=null?o:0,y=(A=a.endAngle)!=null?A:360,Z=d/2,v=h/2,G=(s=i.getChannelDomainArray("row"))!=null?s:["___SINGLE_ROW___"],B=h/G.length;if(B/h*b<=20)return;const w=i.spec().y,R=!(lt(w)&&"axis"in w&&w.axis==="right"),S=nh().domain(c).range(u),X=I.graphics;G.forEach(W=>{const V=i.encodedValue("row",W),H=f-(V+B)/h*b,D=f-V/h*b,Y=Lt(R?0:d,d,H,Z,v,p,y),F=Lt(R?0:d,d,D,Z,v,p,y);X.lineStyle(1,ft(n.axis.baselineColor),1,.5),X.moveTo(Y.x,Y.y),X.lineTo(F.x,F.y);const _=j=>JZ*d/2/Math.PI/j,J=j=>t3*d/2/Math.PI/j,te=B/h*b,q=Math.max(Math.ceil(te/40),1);let $=S.ticks(q).filter(j=>c[0]<=j&&j<=c[1]);$.length===1&&($=S.ticks(q+1).filter(j=>c[0]<=j&&j<=c[1])),X.lineStyle(1,ft(n.axis.tickColor),1,.5),$.forEach(j=>{const ee=S(j),Q=f-(V+B-ee)/h*b,ne=R?0:d-_(Q),fe=R?_(Q):d,Ce=Lt(ne,d,Q,Z,v,p,y),Ze=qg(ne,d,p,y),Ge=qg(fe,d,p,y);X.moveTo(Ce.x,Ce.y),X.arc(Z,v,Q,Ze,Ge,!0),X.arc(Z,v,Q,Ge,Ze,!1),X.closePath()});{const j=R?0:d-J(m),ee=R?J(m):d,Q=qg(j,d,p,y),ne=qg(ee,d,p,y);X.moveTo(Y.x,Y.y),X.arc(Z,v,m,Q,ne,!0),X.arc(Z,v,m,ne,Q,!1),X.closePath()}{const j=R?0:d-J(f),ee=R?J(f):d,Q=qg(j,d,p,y),ne=qg(ee,d,p,y);X.moveTo(F.x,F.y),X.arc(Z,v,f,Q,ne,!0),X.arc(Z,v,f,ne,Q,!1),X.closePath()}$.forEach(j=>{const ee=S(j),Q=f-(V+B-ee)/h*b,ne=Lt(_(Q)*2,d,Q,Z,v,p,y),fe=Os({color:n.axis.labelColor,size:n.axis.labelFontSize,fontFamily:n.axis.labelFontFamily,fontWeight:n.axis.labelFontWeight}),Ce=new g.libraries.PIXI.Text(j,fe);Ce.anchor.x=R?1:0,Ce.anchor.y=.5,Ce.position.x=ne.x,Ce.position.y=ne.y,Ce.resolution=4;const Ze=new g.libraries.PIXI.TextStyle(fe),ve=g.libraries.PIXI.TextMetrics.measureText(Ce.text,Ze).width/(2*Q*Math.PI)*d*360/(y-p),ke=R?_(Q)*2:d-_(Q)*2-ve,Xe=R?_(Q)*2+ve:d-_(Q)*2,Oe=[];for(let Me=Xe;Me>=ke;Me-=ve/10){const Ue=Lt(Me,d,Q,Z,v,p,y);Oe.push(new g.libraries.PIXI.Point(Ue.x,Ue.y))}Ce.updateText();const ze=new g.libraries.PIXI.SimpleRope(Ce.texture,Oe);X.addChild(ze)})})}function b7e(g,e,I){var i,n,C,r,o,A,s,a,l,c,u,d;const h=e.spec(),[m,f]=g.position,[b,p]=g.dimensions,y=(i=h.innerRadius)!=null?i:220,Z=(n=h.outerRadius)!=null?n:300,v=(C=h.startAngle)!=null?C:0,G=(r=h.endAngle)!=null?r:360,B=m+b/2,w=f+p/2,R=Lt(0,b,y,B,w,v,G),S=qg(0,b,v,G),X=qg(b,b,v,G),W=g.pBackground;h.layout==="circular"&&h.mark==="withinLink"||(W.lineStyle((o=h.style)!=null&&o.outlineWidth?((A=h.style)==null?void 0:A.outlineWidth)/2.5:0,ft((a=(s=h.style)==null?void 0:s.outline)!=null?a:"#DBDBDB"),1,1),W.beginFill(ft((c=(l=e.spec().style)==null?void 0:l.background)!=null?c:I.track.background),(d=(u=e.spec().style)==null?void 0:u.backgroundOpacity)!=null?d:!I.track.background||I.track.background==="transparent"?0:1),W.moveTo(R.x,R.y),W.arc(B,w,y,S,X,!0),W.arc(B,w,Z,X,S,!1),W.closePath()),lt(h.x)&&h.x.axis==="top"&&(W.lineStyle(.5,ft("black"),0,.5),W.beginFill(ft("white"),0),W.moveTo(R.x,R.y),W.arc(B,w,Z-.5,S,X,!0),W.arc(B,w,Z,X,S,!1),W.closePath()),W.lineStyle(.5,ft("black"),0,.5),W.beginFill(ft("white"),0),W.moveTo(B,w),W.arc(B,w,Z+3,S,X,!1),W.closePath(),W.lineStyle(1,ft("#DBDBDB"),0,0),W.beginFill(ft("white"),0),W.drawCircle(B,w,y-1)}function y7e(g,e,I){var i,n,C,r,o,A;const[s,a]=g.position,[l,c]=g.dimensions,u=g.pBackground;if((i=e.spec().style)!=null&&i.background||I.track.background&&I.track.background!=="transparent"){u.clear();const d=(C=(n=e.spec().style)==null?void 0:n.background)!=null?C:I.track.background,h=Bte((r=e.spec().style)==null?void 0:r.backgroundOpacity)?1:(o=e.spec().style)==null?void 0:o.backgroundOpacity;u.lineStyle(1,ft("white"),0,0),u.beginFill(ft(d),h),u.drawRect(s,a,l,c)}if(I.track.alternatingBackground&&I.track.alternatingBackground!=="transparent"){const d=e.spec();if(!lt(d.row)||d.row.type!=="nominal")return;const h=(A=e.getChannelDomainArray("row"))!=null?A:["___SINGLE_ROW___"];if(h.length===0)return;h.forEach((m,f)=>{var b,p,y,Z;if(f%2===0)return;const v=e.encodedValue("row",m),G=(p=(b=e.spec().style)==null?void 0:b.background)!=null?p:I.track.alternatingBackground,B=Bte((y=e.spec().style)==null?void 0:y.backgroundOpacity)?1:(Z=e.spec().style)==null?void 0:Z.backgroundOpacity;u.lineStyle(1,ft("white"),0,0),u.beginFill(ft(G),B),u.drawRect(g.position[0],g.position[1]+v,l,c/h.length)})}}function Z7e(g,e,I){var i,n,C,r,o;const A=I.spec();if(!A.width||!A.height){console.warn("Size of a track is not properly determined, so visual mark cannot be rendered");return}const s=I.data(),[a,l]=e.dimensions,c=A.layout==="circular",u=(i=A.innerRadius)!=null?i:220,d=(n=A.outerRadius)!=null?n:300,h=(C=A.startAngle)!=null?C:0,m=(r=A.endAngle)!=null?r:360,f=d-u,b=a/2,p=l/2,y=(o=I.getChannelDomainArray("row"))!=null?o:["___SINGLE_ROW___"],Z=l/y.length;y.forEach(v=>{const G=I.encodedValue("row",v);s.filter(B=>!bI(B,A.row)||bI(B,A.row)===v).forEach(B=>{var w,R;let S=I.encodedPIXIProperty("x",B),X=I.encodedPIXIProperty("xe",B),W=I.encodedPIXIProperty("x1",B),V=I.encodedPIXIProperty("x1e",B);const H=I.encodedPIXIProperty("y",B),D=I.encodedPIXIProperty("stroke",B),Y=I.encodedPIXIProperty("strokeWidth",B),F=I.encodedPIXIProperty("color",B),_=I.encodedPIXIProperty("opacity",B);typeof X<"u"&&([S,X]=[S,X].sort((te,q)=>te-q)),typeof W<"u"&&typeof V<"u"&&([W,V]=[W,V].sort((te,q)=>te-q));const J=typeof X<"u"&&typeof W<"u"&&typeof V<"u"&&Math.abs(S-X)>.1&&Math.abs(W-V)>.1;if(!J&&X===void 0&&!IC(A)){if(W===void 0&&V===void 0)return;X=W!==void 0?W:V}if(!J&&Math.abs(S-X)<=.1&&Math.abs(W-V)<=.1&&(S=(S+X)/2,X=(W+V)/2),g.lineStyle(Y,ft(D),_,.5),J){g.beginFill(ft(F==="none"?"white":F),F==="none"?0:_);let[te,q,$,j]=[S,X,W,V];if([te,q]=[te,q].sort((ee,Q)=>ee-Q),[$,j]=[$,j].sort((ee,Q)=>ee-Q),te>a||j<0||Math.abs(j-te)<.5)return;if(c){if(te<0||j>a)return;const ee=d-G/l*f,Q=Lt(te,a,ee,b,p,h,m),ne=Lt(q,a,ee,b,p,h,m),fe=Lt($,a,ee,b,p,h,m),Ce=Lt(j,a,ee,b,p,h,m);g.moveTo(Q.x,Q.y),g.bezierCurveTo(b,p,b,p,Ce.x,Ce.y),g.arc(b,p,d,vc(Ce.x,Ce.y,b,p),vc(fe.x,fe.y,b,p),!1),g.bezierCurveTo(b,p,b,p,ne.x,ne.y),g.arc(b,p,d,vc(ne.x,ne.y,b,p),vc(Q.x,Q.y,b,p),!1),g.endFill()}else g.moveTo(te,G),g.lineTo(q,G),g.lineTo(j,G+Z),g.lineTo($,G+Z),g.lineTo(te,G),g.closePath()}else{if(IC(A)){((w=A.style)==null?void 0:w.linkConnectionType)==="curve"?(g.moveTo(S,0),g.bezierCurveTo(S/5*4,(G+Z-H)/2,S/2,(G+Z-H)/5*4,0,G+Z-H)):((R=A.style)==null?void 0:R.linkConnectionType)==="straight"?(g.moveTo(S,0),g.lineTo(0,G+Z-H)):(g.moveTo(S,0),g.lineTo(S,G+Z-H),g.lineTo(0,G+Z-H));return}if(c){let te,q;for(let $=0;$<=1;$+=.02){const j=Ce=>Math.log(Ce/(1-Ce)),ee=Ce=>d-1/(1+Math.exp(j(Ce)))*f+3,Q=(Ce,Ze,Ge)=>((Ge-Ze)*Ce+Ze)/a,ne=b+ee($)*Math.cos(-Q($,S,X)*2*Math.PI-Math.PI/2),fe=p+ee($)*Math.sin(-Q($,S,X)*2*Math.PI-Math.PI/2);te&&q&&(g.lineStyle(Y,ft(D),_,.5),g.moveTo(te,q),g.lineTo(ne,fe)),te=ne,q=fe}return}g.moveTo(X,G+Z),g.lineTo(S,G)}})})}const xd=["x","xe","x1","x1e","y","ye","y1","y1e","color","size","row","stroke","strokeWidth","opacity","text"];function G7e(g,e,I,i){if(!g||!e||!I||i.spec().mark==="brush")return;if(["x","x1","x1e","xe"].forEach(r=>{i.setChannelScale(r,e._xScale)}),IC(i.spec())||k7e(i.spec())){const r=e._yScale.copy();r.range([r.range()[1],r.range()[0]]),["y","y1","y1e","ye"].forEach(o=>{i.setChannelScale(o,r)})}const[n,C]=e.dimensions;switch(i.spec().mark){case"point":QUe(e,I.graphics,i);break;case"bar":qUe(e,I,i);break;case"line":$Ue(I.graphics,i,n,C);break;case"area":t7e(g,e,I,i);break;case"rect":g7e(g,e,I,i);break;case"triangleLeft":case"triangleRight":case"triangleBottom":i7e(I.graphics,i,n,C);break;case"text":n7e(g,e,I,i);break;case"rule":C7e(g,e,I,i);break;case"betweenLink":Z7e(I.graphics,e,i);break;case"withinLink":r7e(I.graphics,e,i);break;default:console.warn("Unsupported mark type");break}}function B7e(g,e,I,i,n){if(!g||!e||!I||i.spec().mark==="brush")return;["x","x1","x1e","xe"].forEach(r=>{i.setChannelScale(r,e._xScale)}),i.spec().layout==="circular"?b7e(e,i,n):(y7e(e,i,n),u7e(e,i,n)),a7e(e,i,n)}function v7e(g,e,I,i,n){if(!g||!e||!I||i.spec().mark==="brush")return;["x","x1","x1e","xe"].forEach(r=>{i.setChannelScale(r,e._xScale)}),i.spec().layout==="circular"?(p7e(g,e,I,i,n),c7e(g,e,I,i,n)):(f7e(g,e,I,i,n),m7e(g,e,I,i,n)),d7e(g,e,I,i,n)}function F0(g){if(Vbe(g)||zS(g))return[];if(!si(g))return[g];if(g._overlay.length===0)return[{...g,superpose:void 0}];const e=JSON.parse(JSON.stringify(g));delete e._overlay;const I=[];g._overlay.forEach((C,r)=>{const o=Object.assign(JSON.parse(JSON.stringify(e)),C);o.title&&r!==0&&delete o.title,I.push(o)});let i;return I.forEach(C=>{lt(C.x)&&C.x.axis&&!i&&(i=C.x.axis)}),I.map(C=>({...C,x:{...C.x,axis:i}}))}function Sbe(g){return[].concat(...g.map(e=>{if(Vbe(e)||!si(e)||e._overlay.length<=1)return[e];if(e._overlay.filter(r=>r.data).length===0)return[e];if(wte([e.data,...e._overlay.map(r=>r.data)]))return[e];const I={...e,id:void 0,_overlay:void 0},i=[],n=JSON.parse(JSON.stringify(I));return n._overlay=[],e._overlay.forEach(r=>{if(n.data||(n.data=r.data),n.id||(n.id=r.id),!r.data||wte([n.data,r.data])){n._overlay.push(r);return}const o=Object.assign(JSON.parse(JSON.stringify(I)),r);i.push(o)}),(n._overlay.length>0?[n,...i]:i).map((r,o,A)=>{const s=o!==0,a=zr(r)&<(r.y)&&!r.y.axis&&s?{...r.y,axis:o===1?"right":"none"}:zr(r)?r.y:void 0;return r.title&&o!==A.length-1&&A.length!==1&&delete r.title,{...r,overlayOnPreviousTrack:s,y:a}})}))}function wte(g){if(g.length===0)return!1;const e=g.filter(n=>n);if(e.length!==g.length)return!1;const I=Object.keys(e[0]).sort();let i=!0;return I.forEach(n=>{if(Array.from(new Set(e.map(r=>JSON.stringify(r[n])))).length!==1){i=!1;return}}),i}const i9={viridis:bbe,grey:XUe,warm:TUe,spectral:GUe,cividis:HUe,bupu:vUe,rdbu:yUe,hot:RUe,pink:wUe};function PU(g){return typeof g=="object"&&g!==null}function $V(g){return PU(g)&&"getTabularData"in g}function S7e(g,e){var I;return((I=g.dataTransform)!=null?I:[]).some(i=>i.type===e)}function w7e(g="viridis",e=100){var I;const i=(I=i9[g])!=null?I:i9.viridis;return[...Array(e)].map((n,C)=>i(1/e*C))}function wbe(g){return!("alignment"in g)&&!g.tracks.find(e=>e.alignment==="overlay"||"tracks"in e)}function V7e(g){return"alignment"in g&&g.alignment==="overlay"}function R7e(g){return!wbe(g)&&!V7e(g)}function Vbe(g){return!si(g)&&"data"in g&&!("mark"in g)}function zS(g){return"type"in g&&g.type=="dummy-track"}function W7e(g){return!!("data"in g&&"overrideTemplate"in g&&g.overrideTemplate)}function Vte(g){return typeof g=="object"}function X7e(g){return"chromosome"in g&&!("interval"in g)}function H7e(g){return!("chromosome"in g)&&"interval"in g}function T7e(g){return"chromosome"in g&&"interval"in g}function zr(g){return!("_overlay"in g)}function si(g){return"_overlay"in g}function N7e(g){return"template"in g}function k7e(g){return zr(g)&&!lt(g.x)&<(g.y)&&g.y.type==="genomic"}function IC(g){const e=zr(g)?g:F0(g)[0];return lt(e.x)&&e.x.type==="genomic"&<(e.y)&&e.y.type==="genomic"}function Y7e(g){return IC(g)&&g.data.type==="matrix"&&(g.mark==="bar"||g.mark==="rect")&&g.xe&&g.ye}function L1(g){return g!==null&&typeof g=="object"&&"value"in g}function JU(g){return g!==void 0&&(g.type==="vector"||g.type==="beddb"||g.type==="multivec"||g.type==="bigwig"||g.type==="matrix"||g.type==="bam"||g.type==="vcf"||g.type==="gff"||g.type==="bed")}function lt(g){return PU(g)&&!("value"in g)}function K7e(g){return"oneOf"in g}function x7e(g){return"inRange"in g}function D7e(g){return"include"in g}function Rte(g){return Array.isArray(g)}function F7e(g){return Array.isArray(g)}function IN(g){return(g.mark==="bar"||g.mark==="area"||g.mark==="text")&<(g.color)&&g.color.type==="nominal"&&(!g.row||L1(g.row))&<(g.y)&&g.y.type==="quantitative"&&!lt(g.ye)}function E7e(g,e){const I=g[e];return IN(g)&&(e==="x"||e==="y")&<(I)&&I.type==="quantitative"}function bI(g,e){if(lt(e)&&e.field)return g[e==null?void 0:e.field]}function M7e(g){const e=[];return xd.forEach(I=>{const i=g[I];lt(i)&&"aggregate"in i&&e.push(I)}),e}function f5(g,e){const I=[];return xd.forEach(i=>{const n=g[i];lt(n)&&n.type===e&&I.push(i)}),I}function n9(g){if((zr(g)||si(g))&<(g.x)&&g.x.axis&&g.x.axis!=="none")return!0;if(si(g)){let e=!1;return g._overlay.forEach(I=>{e||lt(I.x)&&I.x.axis&&I.x.axis!=="none"&&(e=!0)}),e}return!1}function z7e(g){if((zr(g)||si(g))&<(g.y)&&g.y.axis&&g.y.axis!=="none")return!0;if(si(g)){let e=!1;return g._overlay.forEach(I=>{e||lt(I.y)&&I.y.axis&&I.y.axis!=="none"&&(e=!0)}),e}return!1}function zm(g){return typeof g=="object"}var oh=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function P7e(g){return g&&g.__esModule&&Object.prototype.hasOwnProperty.call(g,"default")?g.default:g}var g3={exports:{}};/** @license URI.js v4.4.1 (c) 2011 Gary Court. License: http://github.com/garycourt/uri-js */(function(g,e){(function(I,i){i(e)})(oh,function(I){function i(){for(var P=arguments.length,x=Array(P),U=0;U1){x[0]=x[0].slice(0,-1);for(var ce=x.length-1,de=1;de= 0x80 (not a basic code point)","invalid-input":"Invalid input"},S=h-m,X=Math.floor,W=String.fromCharCode;function V(P){throw new RangeError(R[P])}function H(P,x){for(var U=[],ce=P.length;ce--;)U[ce]=x(P[ce]);return U}function D(P,x){var U=P.split("@"),ce="";U.length>1&&(ce=U[0]+"@",P=U[1]),P=P.replace(w,".");var de=P.split("."),Pe=H(de,x).join(".");return ce+Pe}function Y(P){for(var x=[],U=0,ce=P.length;U=55296&&de<=56319&&U>1,x+=X(x/U);x>S*f>>1;de+=h)x=X(x/S);return X(de+(S+1)*x/(x+b))},q=function(x){var U=[],ce=x.length,de=0,Pe=Z,Je=y,ct=x.lastIndexOf(v);ct<0&&(ct=0);for(var bt=0;bt=128&&V("not-basic"),U.push(x.charCodeAt(bt));for(var Ft=ct>0?ct+1:0;Ft=ce&&V("invalid-input");var ot=_(x.charCodeAt(Ft++));(ot>=h||ot>X((d-de)/Xt))&&V("overflow"),de+=ot*Xt;var Nt=Ot<=Je?m:Ot>=Je+f?f:Ot-Je;if(otX(d/Ut)&&V("overflow"),Xt*=Ut}var Pt=U.length+1;Je=te(de-dt,Pt,dt==0),X(de/Pt)>d-Pe&&V("overflow"),Pe+=X(de/Pt),de%=Pt,U.splice(de++,0,Pe)}return String.fromCodePoint.apply(String,U)},$=function(x){var U=[];x=Y(x);var ce=x.length,de=Z,Pe=0,Je=y,ct=!0,bt=!1,Ft=void 0;try{for(var dt=x[Symbol.iterator](),Xt;!(ct=(Xt=dt.next()).done);ct=!0){var Ot=Xt.value;Ot<128&&U.push(W(Ot))}}catch(hC){bt=!0,Ft=hC}finally{try{!ct&&dt.return&&dt.return()}finally{if(bt)throw Ft}}var ot=U.length,Nt=ot;for(ot&&U.push(v);Nt=de&&qtX((d-Pe)/Et)&&V("overflow"),Pe+=(Ut-de)*Et,de=Ut;var Tt=!0,ig=!1,jt=void 0;try{for(var Ig=x[Symbol.iterator](),cg;!(Tt=(cg=Ig.next()).done);Tt=!0){var Hg=cg.value;if(Hgd&&V("overflow"),Hg==de){for(var bg=Pe,zI=h;;zI+=h){var Qi=zI<=Je?m:zI>=Je+f?f:zI-Je;if(bg>6|192).toString(16).toUpperCase()+"%"+(x&63|128).toString(16).toUpperCase():U="%"+(x>>12|224).toString(16).toUpperCase()+"%"+(x>>6&63|128).toString(16).toUpperCase()+"%"+(x&63|128).toString(16).toUpperCase(),U}function Ce(P){for(var x="",U=0,ce=P.length;U=194&&de<224){if(ce-U>=6){var Pe=parseInt(P.substr(U+4,2),16);x+=String.fromCharCode((de&31)<<6|Pe&63)}else x+=P.substr(U,6);U+=6}else if(de>=224){if(ce-U>=9){var Je=parseInt(P.substr(U+4,2),16),ct=parseInt(P.substr(U+7,2),16);x+=String.fromCharCode((de&15)<<12|(Je&63)<<6|ct&63)}else x+=P.substr(U,9);U+=9}else x+=P.substr(U,3),U+=3}return x}function Ze(P,x){function U(ce){var de=Ce(ce);return de.match(x.UNRESERVED)?de:ce}return P.scheme&&(P.scheme=String(P.scheme).replace(x.PCT_ENCODED,U).toLowerCase().replace(x.NOT_SCHEME,"")),P.userinfo!==void 0&&(P.userinfo=String(P.userinfo).replace(x.PCT_ENCODED,U).replace(x.NOT_USERINFO,fe).replace(x.PCT_ENCODED,r)),P.host!==void 0&&(P.host=String(P.host).replace(x.PCT_ENCODED,U).toLowerCase().replace(x.NOT_HOST,fe).replace(x.PCT_ENCODED,r)),P.path!==void 0&&(P.path=String(P.path).replace(x.PCT_ENCODED,U).replace(P.scheme?x.NOT_PATH:x.NOT_PATH_NOSCHEME,fe).replace(x.PCT_ENCODED,r)),P.query!==void 0&&(P.query=String(P.query).replace(x.PCT_ENCODED,U).replace(x.NOT_QUERY,fe).replace(x.PCT_ENCODED,r)),P.fragment!==void 0&&(P.fragment=String(P.fragment).replace(x.PCT_ENCODED,U).replace(x.NOT_FRAGMENT,fe).replace(x.PCT_ENCODED,r)),P}function Ge(P){return P.replace(/^0*(.*)/,"$1")||"0"}function ve(P,x){var U=P.match(x.IPV4ADDRESS)||[],ce=c(U,2),de=ce[1];return de?de.split(".").map(Ge).join("."):P}function ke(P,x){var U=P.match(x.IPV6ADDRESS)||[],ce=c(U,3),de=ce[1],Pe=ce[2];if(de){for(var Je=de.toLowerCase().split("::").reverse(),ct=c(Je,2),bt=ct[0],Ft=ct[1],dt=Ft?Ft.split(":").map(Ge):[],Xt=bt.split(":").map(Ge),Ot=x.IPV4ADDRESS.test(Xt[Xt.length-1]),ot=Ot?7:8,Nt=Xt.length-ot,Ut=Array(ot),Pt=0;Pt1){var yt=Ut.slice(0,eI.index),qt=Ut.slice(eI.index+eI.length);et=yt.join(":")+"::"+qt.join(":")}else et=Ut.join(":");return Pe&&(et+="%"+Pe),et}else return P}var Xe=/^(?:([^:\/?#]+):)?(?:\/\/((?:([^\/?#@]*)@)?(\[[^\/?#\]]+\]|[^\/?#:]*)(?:\:(\d*))?))?([^?#]*)(?:\?([^#]*))?(?:#((?:.|\n|\r)*))?/i,Oe="".match(/(){0}/)[1]===void 0;function ze(P){var x=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},U={},ce=x.iri!==!1?l:a;x.reference==="suffix"&&(P=(x.scheme?x.scheme+":":"")+"//"+P);var de=P.match(Xe);if(de){Oe?(U.scheme=de[1],U.userinfo=de[3],U.host=de[4],U.port=parseInt(de[5],10),U.path=de[6]||"",U.query=de[7],U.fragment=de[8],isNaN(U.port)&&(U.port=de[5])):(U.scheme=de[1]||void 0,U.userinfo=P.indexOf("@")!==-1?de[3]:void 0,U.host=P.indexOf("//")!==-1?de[4]:void 0,U.port=parseInt(de[5],10),U.path=de[6]||"",U.query=P.indexOf("?")!==-1?de[7]:void 0,U.fragment=P.indexOf("#")!==-1?de[8]:void 0,isNaN(U.port)&&(U.port=P.match(/\/\/(?:.|\n)*\:(?:\/|\?|\#|$)/)?de[4]:void 0)),U.host&&(U.host=ke(ve(U.host,ce),ce)),U.scheme===void 0&&U.userinfo===void 0&&U.host===void 0&&U.port===void 0&&!U.path&&U.query===void 0?U.reference="same-document":U.scheme===void 0?U.reference="relative":U.fragment===void 0?U.reference="absolute":U.reference="uri",x.reference&&x.reference!=="suffix"&&x.reference!==U.reference&&(U.error=U.error||"URI is not a "+x.reference+" reference.");var Pe=ne[(x.scheme||U.scheme||"").toLowerCase()];if(!x.unicodeSupport&&(!Pe||!Pe.unicodeSupport)){if(U.host&&(x.domainHost||Pe&&Pe.domainHost))try{U.host=Q.toASCII(U.host.replace(ce.PCT_ENCODED,Ce).toLowerCase())}catch(Je){U.error=U.error||"Host's domain name can not be converted to ASCII via punycode: "+Je}Ze(U,a)}else Ze(U,ce);Pe&&Pe.parse&&Pe.parse(U,x)}else U.error=U.error||"URI can not be parsed.";return U}function Me(P,x){var U=x.iri!==!1?l:a,ce=[];return P.userinfo!==void 0&&(ce.push(P.userinfo),ce.push("@")),P.host!==void 0&&ce.push(ke(ve(String(P.host),U),U).replace(U.IPV6ADDRESS,function(de,Pe,Je){return"["+Pe+(Je?"%25"+Je:"")+"]"})),(typeof P.port=="number"||typeof P.port=="string")&&(ce.push(":"),ce.push(String(P.port))),ce.length?ce.join(""):void 0}var Ue=/^\.\.?\//,_e=/^\/\.(\/|$)/,At=/^\/\.\.(\/|$)/,wt=/^\/?(?:.|\n)*?(?=\/|$)/;function rt(P){for(var x=[];P.length;)if(P.match(Ue))P=P.replace(Ue,"");else if(P.match(_e))P=P.replace(_e,"/");else if(P.match(At))P=P.replace(At,"/"),x.pop();else if(P==="."||P==="..")P="";else{var U=P.match(wt);if(U){var ce=U[0];P=P.slice(ce.length),x.push(ce)}else throw new Error("Unexpected dot segment condition")}return x.join("")}function Te(P){var x=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},U=x.iri?l:a,ce=[],de=ne[(x.scheme||P.scheme||"").toLowerCase()];if(de&&de.serialize&&de.serialize(P,x),P.host&&!U.IPV6ADDRESS.test(P.host)){if(x.domainHost||de&&de.domainHost)try{P.host=x.iri?Q.toUnicode(P.host):Q.toASCII(P.host.replace(U.PCT_ENCODED,Ce).toLowerCase())}catch(ct){P.error=P.error||"Host's domain name can not be converted to "+(x.iri?"Unicode":"ASCII")+" via punycode: "+ct}}Ze(P,U),x.reference!=="suffix"&&P.scheme&&(ce.push(P.scheme),ce.push(":"));var Pe=Me(P,x);if(Pe!==void 0&&(x.reference!=="suffix"&&ce.push("//"),ce.push(Pe),P.path&&P.path.charAt(0)!=="/"&&ce.push("/")),P.path!==void 0){var Je=P.path;!x.absolutePath&&(!de||!de.absolutePath)&&(Je=rt(Je)),Pe===void 0&&(Je=Je.replace(/^\/\//,"/%2F")),ce.push(Je)}return P.query!==void 0&&(ce.push("?"),ce.push(P.query)),P.fragment!==void 0&&(ce.push("#"),ce.push(P.fragment)),ce.join("")}function le(P,x){var U=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},ce=arguments[3],de={};return ce||(P=ze(Te(P,U),U),x=ze(Te(x,U),U)),U=U||{},!U.tolerant&&x.scheme?(de.scheme=x.scheme,de.userinfo=x.userinfo,de.host=x.host,de.port=x.port,de.path=rt(x.path||""),de.query=x.query):(x.userinfo!==void 0||x.host!==void 0||x.port!==void 0?(de.userinfo=x.userinfo,de.host=x.host,de.port=x.port,de.path=rt(x.path||""),de.query=x.query):(x.path?(x.path.charAt(0)==="/"?de.path=rt(x.path):((P.userinfo!==void 0||P.host!==void 0||P.port!==void 0)&&!P.path?de.path="/"+x.path:P.path?de.path=P.path.slice(0,P.path.lastIndexOf("/")+1)+x.path:de.path=x.path,de.path=rt(de.path)),de.query=x.query):(de.path=P.path,x.query!==void 0?de.query=x.query:de.query=P.query),de.userinfo=P.userinfo,de.host=P.host,de.port=P.port),de.scheme=P.scheme),de.fragment=x.fragment,de}function ye(P,x,U){var ce=A({scheme:"null"},U);return Te(le(ze(P,ce),ze(x,ce),ce,!0),ce)}function We(P,x){return typeof P=="string"?P=Te(ze(P,x),x):C(P)==="object"&&(P=ze(Te(P,x),x)),P}function K(P,x,U){return typeof P=="string"?P=Te(ze(P,U),U):C(P)==="object"&&(P=Te(P,U)),typeof x=="string"?x=Te(ze(x,U),U):C(x)==="object"&&(x=Te(x,U)),P===x}function T(P,x){return P&&P.toString().replace(!x||!x.iri?a.ESCAPE:l.ESCAPE,fe)}function k(P,x){return P&&P.toString().replace(!x||!x.iri?a.PCT_ENCODED:l.PCT_ENCODED,Ce)}var ge={scheme:"http",domainHost:!0,parse:function(x,U){return x.host||(x.error=x.error||"HTTP URIs must have a host."),x},serialize:function(x,U){var ce=String(x.scheme).toLowerCase()==="https";return(x.port===(ce?443:80)||x.port==="")&&(x.port=void 0),x.path||(x.path="/"),x}},he={scheme:"https",domainHost:ge.domainHost,parse:ge.parse,serialize:ge.serialize};function we(P){return typeof P.secure=="boolean"?P.secure:String(P.scheme).toLowerCase()==="wss"}var xe={scheme:"ws",domainHost:!0,parse:function(x,U){var ce=x;return ce.secure=we(ce),ce.resourceName=(ce.path||"/")+(ce.query?"?"+ce.query:""),ce.path=void 0,ce.query=void 0,ce},serialize:function(x,U){if((x.port===(we(x)?443:80)||x.port==="")&&(x.port=void 0),typeof x.secure=="boolean"&&(x.scheme=x.secure?"wss":"ws",x.secure=void 0),x.resourceName){var ce=x.resourceName.split("?"),de=c(ce,2),Pe=de[0],Je=de[1];x.path=Pe&&Pe!=="/"?Pe:void 0,x.query=Je,x.resourceName=void 0}return x.fragment=void 0,x}},qe={scheme:"wss",domainHost:xe.domainHost,parse:xe.parse,serialize:xe.serialize},mt={},St="[A-Za-z0-9\\-\\.\\_\\~\\xA0-\\u200D\\u2010-\\u2029\\u202F-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF]",ut="[0-9A-Fa-f]",Yt=n(n("%[EFef]"+ut+"%"+ut+ut+"%"+ut+ut)+"|"+n("%[89A-Fa-f]"+ut+"%"+ut+ut)+"|"+n("%"+ut+ut)),ie="[A-Za-z0-9\\!\\$\\%\\'\\*\\+\\-\\^\\_\\`\\{\\|\\}\\~]",E="[\\!\\$\\%\\'\\(\\)\\*\\+\\,\\-\\.0-9\\<\\>A-Z\\x5E-\\x7E]",O=i(E,'[\\"\\\\]'),me="[\\!\\$\\'\\(\\)\\*\\+\\,\\;\\:\\@]",Ne=new RegExp(St,"g"),ue=new RegExp(Yt,"g"),se=new RegExp(i("[^]",ie,"[\\.]",'[\\"]',O),"g"),re=new RegExp(i("[^]",St,me),"g"),oe=re;function Se(P){var x=Ce(P);return x.match(Ne)?x:P}var Ke={scheme:"mailto",parse:function(x,U){var ce=x,de=ce.to=ce.path?ce.path.split(","):[];if(ce.path=void 0,ce.query){for(var Pe=!1,Je={},ct=ce.query.split("&"),bt=0,Ft=ct.length;bt=55296&&C<=56319&&n=e)throw new Error("Cannot access property/index "+i+" levels up, current level is "+e);return I[e-i]}if(i>e)throw new Error("Cannot access data "+i+" levels up, current level is "+e);if(C="data"+(e-i||""),!n)return C}for(var o=C,A=n.split("/"),s=0;s=0?{index:i,compiling:!0}:(i=this._compilations.length,this._compilations[i]={schema:g,root:e,baseId:I},{index:i,compiling:!1})}function wQe(g,e,I){var i=Kbe.call(this,g,e,I);i>=0&&this._compilations.splice(i,1)}function Kbe(g,e,I){for(var i=0;i%\\^`{|}]|%[0-9a-f]{2})|\{[+#./;?&=,!@|]?(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?(?:,(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?)*\})*$/i,Ebe=/^(?:(?:http[s\u017F]?|ftp):\/\/)(?:(?:[\0-\x08\x0E-\x1F!-\x9F\xA1-\u167F\u1681-\u1FFF\u200B-\u2027\u202A-\u202E\u2030-\u205E\u2060-\u2FFF\u3001-\uD7FF\uE000-\uFEFE\uFF00-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+(?::(?:[\0-\x08\x0E-\x1F!-\x9F\xA1-\u167F\u1681-\u1FFF\u200B-\u2027\u202A-\u202E\u2030-\u205E\u2060-\u2FFF\u3001-\uD7FF\uE000-\uFEFE\uFF00-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*)?@)?(?:(?!10(?:\.[0-9]{1,3}){3})(?!127(?:\.[0-9]{1,3}){3})(?!169\.254(?:\.[0-9]{1,3}){2})(?!192\.168(?:\.[0-9]{1,3}){2})(?!172\.(?:1[6-9]|2[0-9]|3[01])(?:\.[0-9]{1,3}){2})(?:[1-9][0-9]?|1[0-9][0-9]|2[01][0-9]|22[0-3])(?:\.(?:1?[0-9]{1,2}|2[0-4][0-9]|25[0-5])){2}(?:\.(?:[1-9][0-9]?|1[0-9][0-9]|2[0-4][0-9]|25[0-4]))|(?:(?:(?:[0-9a-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+-)*(?:[0-9a-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+)(?:\.(?:(?:[0-9a-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+-)*(?:[0-9a-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+)*(?:\.(?:(?:[a-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]){2,})))(?::[0-9]{2,5})?(?:\/(?:[\0-\x08\x0E-\x1F!-\x9F\xA1-\u167F\u1681-\u1FFF\u200B-\u2027\u202A-\u202E\u2030-\u205E\u2060-\u2FFF\u3001-\uD7FF\uE000-\uFEFE\uFF00-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*)?$/i,Mbe=/^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i,zbe=/^(?:\/(?:[^~/]|~0|~1)*)*$/,Pbe=/^#(?:\/(?:[a-z0-9_\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i,Jbe=/^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/,DQe=rN;function rN(g){return g=g=="full"?"full":"fast",TQe.copy(rN[g])}rN.fast={date:/^\d\d\d\d-[0-1]\d-[0-3]\d$/,time:/^(?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d(?::?\d\d)?)?$/i,"date-time":/^\d\d\d\d-[0-1]\d-[0-3]\d[t\s](?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d(?::?\d\d)?)$/i,uri:/^(?:[a-z][a-z0-9+\-.]*:)(?:\/?\/)?[^\s]*$/i,"uri-reference":/^(?:(?:[a-z][a-z0-9+\-.]*:)?\/?\/)?(?:[^\\\s#][^\s#]*)?(?:#[^\\\s]*)?$/i,"uri-template":Fbe,url:Ebe,email:/^[a-z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*$/i,hostname:Dbe,ipv4:/^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/,ipv6:/^\s*(?:(?:(?:[0-9a-f]{1,4}:){7}(?:[0-9a-f]{1,4}|:))|(?:(?:[0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)))(?:%.+)?\s*$/i,regex:_be,uuid:Mbe,"json-pointer":zbe,"json-pointer-uri-fragment":Pbe,"relative-json-pointer":Jbe};rN.full={date:Obe,time:Lbe,"date-time":MQe,uri:PQe,"uri-reference":xQe,"uri-template":Fbe,url:Ebe,email:/^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i,hostname:Dbe,ipv4:/^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/,ipv6:/^\s*(?:(?:(?:[0-9a-f]{1,4}:){7}(?:[0-9a-f]{1,4}|:))|(?:(?:[0-9a-f]{1,4}:){6}(?::[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(?:(?:[0-9a-f]{1,4}:){5}(?:(?:(?::[0-9a-f]{1,4}){1,2})|:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(?:(?:[0-9a-f]{1,4}:){4}(?:(?:(?::[0-9a-f]{1,4}){1,3})|(?:(?::[0-9a-f]{1,4})?:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){3}(?:(?:(?::[0-9a-f]{1,4}){1,4})|(?:(?::[0-9a-f]{1,4}){0,2}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){2}(?:(?:(?::[0-9a-f]{1,4}){1,5})|(?:(?::[0-9a-f]{1,4}){0,3}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){1}(?:(?:(?::[0-9a-f]{1,4}){1,6})|(?:(?::[0-9a-f]{1,4}){0,4}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?::(?:(?:(?::[0-9a-f]{1,4}){1,7})|(?:(?::[0-9a-f]{1,4}){0,5}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(?:%.+)?\s*$/i,regex:_be,uuid:Mbe,"json-pointer":zbe,"json-pointer-uri-fragment":Pbe,"relative-json-pointer":Jbe};function FQe(g){return g%4===0&&(g%100!==0||g%400===0)}function Obe(g){var e=g.match(NQe);if(!e)return!1;var I=+e[1],i=+e[2],n=+e[3];return i>=1&&i<=12&&n>=1&&n<=(i==2&&FQe(I)?29:kQe[i])}function Lbe(g,e){var I=g.match(YQe);if(!I)return!1;var i=I[1],n=I[2],C=I[3],r=I[5];return(i<=23&&n<=59&&C<=59||i==23&&n==59&&C==60)&&(!e||r)}var EQe=/t|\s/i;function MQe(g){var e=g.split(EQe);return e.length==2&&Obe(e[0])&&Lbe(e[1],!0)}var zQe=/\/|:/;function PQe(g){return zQe.test(g)&&KQe.test(g)}var JQe=/[^\\]\\Z/;function _be(g){if(JQe.test(g))return!1;try{return new RegExp(g),!0}catch{return!1}}var OQe=function(e,I,i){var n=" ",C=e.level,r=e.dataLevel,o=e.schema[I],A=e.errSchemaPath+"/"+I,s=!e.opts.allErrors,a="data"+(r||""),l="valid"+C,c,u;if(o=="#"||o=="#/")e.isRoot?(c=e.async,u="validate"):(c=e.root.schema.$async===!0,u="root.refVal[0]");else{var d=e.resolveRef(e.baseId,o,e.isRoot);if(d===void 0){var h=e.MissingRefError.message(e.baseId,o);if(e.opts.missingRefs=="fail"){e.logger.error(h);var m=m||[];m.push(n),n="",e.createErrors!==!1?(n+=" { keyword: '$ref' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(A)+" , params: { ref: '"+e.util.escapeQuotes(o)+"' } ",e.opts.messages!==!1&&(n+=" , message: 'can\\'t resolve reference "+e.util.escapeQuotes(o)+"' "),e.opts.verbose&&(n+=" , schema: "+e.util.toQuotedString(o)+" , parentSchema: validate.schema"+e.schemaPath+" , data: "+a+" "),n+=" } "):n+=" {} ";var f=n;n=m.pop(),!e.compositeRule&&s?e.async?n+=" throw new ValidationError(["+f+"]); ":n+=" validate.errors = ["+f+"]; return false; ":n+=" var err = "+f+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",s&&(n+=" if (false) { ")}else if(e.opts.missingRefs=="ignore")e.logger.warn(h),s&&(n+=" if (true) { ");else throw new e.MissingRefError(e.baseId,o,h)}else if(d.inline){var b=e.util.copy(e);b.level++;var p="valid"+b.level;b.schema=d.schema,b.schemaPath="",b.errSchemaPath=o;var y=e.validate(b).replace(/validate\.schema/g,d.code);n+=" "+y+" ",s&&(n+=" if ("+p+") { ")}else c=d.$async===!0||e.async&&d.$async!==!1,u=d.code}if(u){var m=m||[];m.push(n),n="",e.opts.passContext?n+=" "+u+".call(this, ":n+=" "+u+"( ",n+=" "+a+", (dataPath || '')",e.errorPath!='""'&&(n+=" + "+e.errorPath);var Z=r?"data"+(r-1||""):"parentData",v=r?e.dataPathArr[r]:"parentDataProperty";n+=" , "+Z+" , "+v+", rootData) ";var G=n;if(n=m.pop(),c){if(!e.async)throw new Error("async schema referenced by sync schema");s&&(n+=" var "+l+"; "),n+=" try { await "+G+"; ",s&&(n+=" "+l+" = true; "),n+=" } catch (e) { if (!(e instanceof ValidationError)) throw e; if (vErrors === null) vErrors = e.errors; else vErrors = vErrors.concat(e.errors); errors = vErrors.length; ",s&&(n+=" "+l+" = false; "),n+=" } ",s&&(n+=" if ("+l+") { ")}else n+=" if (!"+G+") { if (vErrors === null) vErrors = "+u+".errors; else vErrors = vErrors.concat("+u+".errors); errors = vErrors.length; } ",s&&(n+=" else { ")}return n},LQe=function(e,I,i){var n=" ",C=e.schema[I],r=e.schemaPath+e.util.getProperty(I),o=e.errSchemaPath+"/"+I,A=!e.opts.allErrors,s=e.util.copy(e),a="";s.level++;var l="valid"+s.level,c=s.baseId,u=!0,d=C;if(d)for(var h,m=-1,f=d.length-1;m0||h===!1:e.util.schemaHasRules(h,e.RULES.all))&&(u=!1,s.schema=h,s.schemaPath=r+"["+m+"]",s.errSchemaPath=o+"/"+m,n+=" "+e.validate(s)+" ",s.baseId=c,A&&(n+=" if ("+l+") { ",a+="}"));return A&&(u?n+=" if (true) { ":n+=" "+a.slice(0,-1)+" "),n},_Qe=function(e,I,i){var n=" ",C=e.level,r=e.dataLevel,o=e.schema[I],A=e.schemaPath+e.util.getProperty(I),s=e.errSchemaPath+"/"+I,a=!e.opts.allErrors,l="data"+(r||""),c="valid"+C,u="errs__"+C,d=e.util.copy(e),h="";d.level++;var m="valid"+d.level,f=o.every(function(B){return e.opts.strictKeywords?typeof B=="object"&&Object.keys(B).length>0||B===!1:e.util.schemaHasRules(B,e.RULES.all)});if(f){var b=d.baseId;n+=" var "+u+" = errors; var "+c+" = false; ";var p=e.compositeRule;e.compositeRule=d.compositeRule=!0;var y=o;if(y)for(var Z,v=-1,G=y.length-1;v0||o===!1:e.util.schemaHasRules(o,e.RULES.all);if(n+="var "+u+" = errors;var "+c+";",Z){var v=e.compositeRule;e.compositeRule=d.compositeRule=!0,d.schema=o,d.schemaPath=A,d.errSchemaPath=s,n+=" var "+m+" = false; for (var "+f+" = 0; "+f+" < "+l+".length; "+f+"++) { ",d.errorPath=e.util.getPathExpr(e.errorPath,f,e.opts.jsonPointers,!0);var G=l+"["+f+"]";d.dataPathArr[b]=f;var B=e.validate(d);d.baseId=y,e.util.varOccurences(B,p)<2?n+=" "+e.util.varReplace(B,p,G)+" ":n+=" var "+p+" = "+G+"; "+B+" ",n+=" if ("+m+") break; } ",e.compositeRule=d.compositeRule=v,n+=" "+h+" if (!"+m+") {"}else n+=" if ("+l+".length == 0) {";var w=w||[];w.push(n),n="",e.createErrors!==!1?(n+=" { keyword: 'contains' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(s)+" , params: {} ",e.opts.messages!==!1&&(n+=" , message: 'should contain a valid item' "),e.opts.verbose&&(n+=" , schema: validate.schema"+A+" , parentSchema: validate.schema"+e.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ";var R=n;return n=w.pop(),!e.compositeRule&&a?e.async?n+=" throw new ValidationError(["+R+"]); ":n+=" validate.errors = ["+R+"]; return false; ":n+=" var err = "+R+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",n+=" } else { ",Z&&(n+=" errors = "+u+"; if (vErrors !== null) { if ("+u+") vErrors.length = "+u+"; else vErrors = null; } "),e.opts.allErrors&&(n+=" } "),n},$Qe=function(e,I,i){var n=" ",C=e.level,r=e.dataLevel,o=e.schema[I],A=e.schemaPath+e.util.getProperty(I),s=e.errSchemaPath+"/"+I,a=!e.opts.allErrors,l="data"+(r||""),c="errs__"+C,u=e.util.copy(e),d="";u.level++;var h="valid"+u.level,m={},f={},b=e.opts.ownProperties;for(v in o)if(v!="__proto__"){var p=o[v],y=Array.isArray(p)?f:m;y[v]=p}n+="var "+c+" = errors;";var Z=e.errorPath;n+="var missing"+C+";";for(var v in f)if(y=f[v],y.length){if(n+=" if ( "+l+e.util.getProperty(v)+" !== undefined ",b&&(n+=" && Object.prototype.hasOwnProperty.call("+l+", '"+e.util.escapeQuotes(v)+"') "),a){n+=" && ( ";var G=y;if(G)for(var B,w=-1,R=G.length-1;w0||p===!1:e.util.schemaHasRules(p,e.RULES.all))&&(n+=" "+h+" = true; if ( "+l+e.util.getProperty(v)+" !== undefined ",b&&(n+=" && Object.prototype.hasOwnProperty.call("+l+", '"+e.util.escapeQuotes(v)+"') "),n+=") { ",u.schema=p,u.schemaPath=A+e.util.getProperty(v),u.errSchemaPath=s+"/"+e.util.escapeFragment(v),n+=" "+e.validate(u)+" ",u.baseId=J,n+=" } ",a&&(n+=" if ("+h+") { ",d+="}"))}return a&&(n+=" "+d+" if ("+c+" == errors) {"),n},qQe=function(e,I,i){var n=" ",C=e.level,r=e.dataLevel,o=e.schema[I],A=e.schemaPath+e.util.getProperty(I),s=e.errSchemaPath+"/"+I,a=!e.opts.allErrors,l="data"+(r||""),c="valid"+C,u=e.opts.$data&&o&&o.$data;u&&(n+=" var schema"+C+" = "+e.util.getData(o.$data,r,e.dataPathArr)+"; ");var d="i"+C,h="schema"+C;u||(n+=" var "+h+" = validate.schema"+A+";"),n+="var "+c+";",u&&(n+=" if (schema"+C+" === undefined) "+c+" = true; else if (!Array.isArray(schema"+C+")) "+c+" = false; else {"),n+=""+c+" = false;for (var "+d+"=0; "+d+"<"+h+".length; "+d+"++) if (equal("+l+", "+h+"["+d+"])) { "+c+" = true; break; }",u&&(n+=" } "),n+=" if (!"+c+") { ";var m=m||[];m.push(n),n="",e.createErrors!==!1?(n+=" { keyword: 'enum' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(s)+" , params: { allowedValues: schema"+C+" } ",e.opts.messages!==!1&&(n+=" , message: 'should be equal to one of the allowed values' "),e.opts.verbose&&(n+=" , schema: validate.schema"+A+" , parentSchema: validate.schema"+e.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ";var f=n;return n=m.pop(),!e.compositeRule&&a?e.async?n+=" throw new ValidationError(["+f+"]); ":n+=" validate.errors = ["+f+"]; return false; ":n+=" var err = "+f+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",n+=" }",a&&(n+=" else { "),n},eje=function(e,I,i){var n=" ",C=e.level,r=e.dataLevel,o=e.schema[I],A=e.schemaPath+e.util.getProperty(I),s=e.errSchemaPath+"/"+I,a=!e.opts.allErrors,l="data"+(r||"");if(e.opts.format===!1)return a&&(n+=" if (true) { "),n;var c=e.opts.$data&&o&&o.$data,u;c?(n+=" var schema"+C+" = "+e.util.getData(o.$data,r,e.dataPathArr)+"; ",u="schema"+C):u=o;var d=e.opts.unknownFormats,h=Array.isArray(d);if(c){var m="format"+C,f="isObject"+C,b="formatType"+C;n+=" var "+m+" = formats["+u+"]; var "+f+" = typeof "+m+" == 'object' && !("+m+" instanceof RegExp) && "+m+".validate; var "+b+" = "+f+" && "+m+".type || 'string'; if ("+f+") { ",e.async&&(n+=" var async"+C+" = "+m+".async; "),n+=" "+m+" = "+m+".validate; } if ( ",c&&(n+=" ("+u+" !== undefined && typeof "+u+" != 'string') || "),n+=" (",d!="ignore"&&(n+=" ("+u+" && !"+m+" ",h&&(n+=" && self._opts.unknownFormats.indexOf("+u+") == -1 "),n+=") || "),n+=" ("+m+" && "+b+" == '"+i+"' && !(typeof "+m+" == 'function' ? ",e.async?n+=" (async"+C+" ? await "+m+"("+l+") : "+m+"("+l+")) ":n+=" "+m+"("+l+") ",n+=" : "+m+".test("+l+"))))) {"}else{var m=e.formats[o];if(!m){if(d=="ignore")return e.logger.warn('unknown format "'+o+'" ignored in schema at path "'+e.errSchemaPath+'"'),a&&(n+=" if (true) { "),n;if(h&&d.indexOf(o)>=0)return a&&(n+=" if (true) { "),n;throw new Error('unknown format "'+o+'" is used in schema at path "'+e.errSchemaPath+'"')}var f=typeof m=="object"&&!(m instanceof RegExp)&&m.validate,b=f&&m.type||"string";if(f){var p=m.async===!0;m=m.validate}if(b!=i)return a&&(n+=" if (true) { "),n;if(p){if(!e.async)throw new Error("async format in sync schema");var y="formats"+e.util.getProperty(o)+".validate";n+=" if (!(await "+y+"("+l+"))) { "}else{n+=" if (! ";var y="formats"+e.util.getProperty(o);f&&(y+=".validate"),typeof m=="function"?n+=" "+y+"("+l+") ":n+=" "+y+".test("+l+") ",n+=") { "}}var Z=Z||[];Z.push(n),n="",e.createErrors!==!1?(n+=" { keyword: 'format' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(s)+" , params: { format: ",c?n+=""+u:n+=""+e.util.toQuotedString(o),n+=" } ",e.opts.messages!==!1&&(n+=` , message: 'should match format "`,c?n+="' + "+u+" + '":n+=""+e.util.escapeQuotes(o),n+=`"' `),e.opts.verbose&&(n+=" , schema: ",c?n+="validate.schema"+A:n+=""+e.util.toQuotedString(o),n+=" , parentSchema: validate.schema"+e.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ";var v=n;return n=Z.pop(),!e.compositeRule&&a?e.async?n+=" throw new ValidationError(["+v+"]); ":n+=" validate.errors = ["+v+"]; return false; ":n+=" var err = "+v+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",n+=" } ",a&&(n+=" else { "),n},tje=function(e,I,i){var n=" ",C=e.level,r=e.dataLevel,o=e.schema[I],A=e.schemaPath+e.util.getProperty(I),s=e.errSchemaPath+"/"+I,a=!e.opts.allErrors,l="data"+(r||""),c="valid"+C,u="errs__"+C,d=e.util.copy(e);d.level++;var h="valid"+d.level,m=e.schema.then,f=e.schema.else,b=m!==void 0&&(e.opts.strictKeywords?typeof m=="object"&&Object.keys(m).length>0||m===!1:e.util.schemaHasRules(m,e.RULES.all)),p=f!==void 0&&(e.opts.strictKeywords?typeof f=="object"&&Object.keys(f).length>0||f===!1:e.util.schemaHasRules(f,e.RULES.all)),y=d.baseId;if(b||p){var Z;d.createErrors=!1,d.schema=o,d.schemaPath=A,d.errSchemaPath=s,n+=" var "+u+" = errors; var "+c+" = true; ";var v=e.compositeRule;e.compositeRule=d.compositeRule=!0,n+=" "+e.validate(d)+" ",d.baseId=y,d.createErrors=!0,n+=" errors = "+u+"; if (vErrors !== null) { if ("+u+") vErrors.length = "+u+"; else vErrors = null; } ",e.compositeRule=d.compositeRule=v,b?(n+=" if ("+h+") { ",d.schema=e.schema.then,d.schemaPath=e.schemaPath+".then",d.errSchemaPath=e.errSchemaPath+"/then",n+=" "+e.validate(d)+" ",d.baseId=y,n+=" "+c+" = "+h+"; ",b&&p?(Z="ifClause"+C,n+=" var "+Z+" = 'then'; "):Z="'then'",n+=" } ",p&&(n+=" else { ")):n+=" if (!"+h+") { ",p&&(d.schema=e.schema.else,d.schemaPath=e.schemaPath+".else",d.errSchemaPath=e.errSchemaPath+"/else",n+=" "+e.validate(d)+" ",d.baseId=y,n+=" "+c+" = "+h+"; ",b&&p?(Z="ifClause"+C,n+=" var "+Z+" = 'else'; "):Z="'else'",n+=" } "),n+=" if (!"+c+") { var err = ",e.createErrors!==!1?(n+=" { keyword: 'if' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(s)+" , params: { failingKeyword: "+Z+" } ",e.opts.messages!==!1&&(n+=` , message: 'should match "' + `+Z+` + '" schema' `),e.opts.verbose&&(n+=" , schema: validate.schema"+A+" , parentSchema: validate.schema"+e.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ",n+="; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",!e.compositeRule&&a&&(e.async?n+=" throw new ValidationError(vErrors); ":n+=" validate.errors = vErrors; return false; "),n+=" } ",a&&(n+=" else { ")}else a&&(n+=" if (true) { ");return n},gje=function(e,I,i){var n=" ",C=e.level,r=e.dataLevel,o=e.schema[I],A=e.schemaPath+e.util.getProperty(I),s=e.errSchemaPath+"/"+I,a=!e.opts.allErrors,l="data"+(r||""),c="valid"+C,u="errs__"+C,d=e.util.copy(e),h="";d.level++;var m="valid"+d.level,f="i"+C,b=d.dataLevel=e.dataLevel+1,p="data"+b,y=e.baseId;if(n+="var "+u+" = errors;var "+c+";",Array.isArray(o)){var Z=e.schema.additionalItems;if(Z===!1){n+=" "+c+" = "+l+".length <= "+o.length+"; ";var v=s;s=e.errSchemaPath+"/additionalItems",n+=" if (!"+c+") { ";var G=G||[];G.push(n),n="",e.createErrors!==!1?(n+=" { keyword: 'additionalItems' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(s)+" , params: { limit: "+o.length+" } ",e.opts.messages!==!1&&(n+=" , message: 'should NOT have more than "+o.length+" items' "),e.opts.verbose&&(n+=" , schema: false , parentSchema: validate.schema"+e.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ";var B=n;n=G.pop(),!e.compositeRule&&a?e.async?n+=" throw new ValidationError(["+B+"]); ":n+=" validate.errors = ["+B+"]; return false; ":n+=" var err = "+B+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",n+=" } ",s=v,a&&(h+="}",n+=" else { ")}var w=o;if(w){for(var R,S=-1,X=w.length-1;S0||R===!1:e.util.schemaHasRules(R,e.RULES.all)){n+=" "+m+" = true; if ("+l+".length > "+S+") { ";var W=l+"["+S+"]";d.schema=R,d.schemaPath=A+"["+S+"]",d.errSchemaPath=s+"/"+S,d.errorPath=e.util.getPathExpr(e.errorPath,S,e.opts.jsonPointers,!0),d.dataPathArr[b]=S;var V=e.validate(d);d.baseId=y,e.util.varOccurences(V,p)<2?n+=" "+e.util.varReplace(V,p,W)+" ":n+=" var "+p+" = "+W+"; "+V+" ",n+=" } ",a&&(n+=" if ("+m+") { ",h+="}")}}if(typeof Z=="object"&&(e.opts.strictKeywords?typeof Z=="object"&&Object.keys(Z).length>0||Z===!1:e.util.schemaHasRules(Z,e.RULES.all))){d.schema=Z,d.schemaPath=e.schemaPath+".additionalItems",d.errSchemaPath=e.errSchemaPath+"/additionalItems",n+=" "+m+" = true; if ("+l+".length > "+o.length+") { for (var "+f+" = "+o.length+"; "+f+" < "+l+".length; "+f+"++) { ",d.errorPath=e.util.getPathExpr(e.errorPath,f,e.opts.jsonPointers,!0);var W=l+"["+f+"]";d.dataPathArr[b]=f;var V=e.validate(d);d.baseId=y,e.util.varOccurences(V,p)<2?n+=" "+e.util.varReplace(V,p,W)+" ":n+=" var "+p+" = "+W+"; "+V+" ",a&&(n+=" if (!"+m+") break; "),n+=" } } ",a&&(n+=" if ("+m+") { ",h+="}")}}else if(e.opts.strictKeywords?typeof o=="object"&&Object.keys(o).length>0||o===!1:e.util.schemaHasRules(o,e.RULES.all)){d.schema=o,d.schemaPath=A,d.errSchemaPath=s,n+=" for (var "+f+" = 0; "+f+" < "+l+".length; "+f+"++) { ",d.errorPath=e.util.getPathExpr(e.errorPath,f,e.opts.jsonPointers,!0);var W=l+"["+f+"]";d.dataPathArr[b]=f;var V=e.validate(d);d.baseId=y,e.util.varOccurences(V,p)<2?n+=" "+e.util.varReplace(V,p,W)+" ":n+=" var "+p+" = "+W+"; "+V+" ",a&&(n+=" if (!"+m+") break; "),n+=" }"}return a&&(n+=" "+h+" if ("+u+" == errors) {"),n},Nte=function(e,I,i){var n=" ",C=e.level,r=e.dataLevel,o=e.schema[I],A=e.schemaPath+e.util.getProperty(I),s=e.errSchemaPath+"/"+I,a=!e.opts.allErrors,y,l="data"+(r||""),c=e.opts.$data&&o&&o.$data,u;c?(n+=" var schema"+C+" = "+e.util.getData(o.$data,r,e.dataPathArr)+"; ",u="schema"+C):u=o;var d=I=="maximum",h=d?"exclusiveMaximum":"exclusiveMinimum",m=e.schema[h],f=e.opts.$data&&m&&m.$data,b=d?"<":">",p=d?">":"<",y=void 0;if(!(c||typeof o=="number"||o===void 0))throw new Error(I+" must be number");if(!(f||m===void 0||typeof m=="number"||typeof m=="boolean"))throw new Error(h+" must be number or boolean");if(f){var Z=e.util.getData(m.$data,r,e.dataPathArr),v="exclusive"+C,G="exclType"+C,B="exclIsNumber"+C,w="op"+C,R="' + "+w+" + '";n+=" var schemaExcl"+C+" = "+Z+"; ",Z="schemaExcl"+C,n+=" var "+v+"; var "+G+" = typeof "+Z+"; if ("+G+" != 'boolean' && "+G+" != 'undefined' && "+G+" != 'number') { ";var y=h,S=S||[];S.push(n),n="",e.createErrors!==!1?(n+=" { keyword: '"+(y||"_exclusiveLimit")+"' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(s)+" , params: {} ",e.opts.messages!==!1&&(n+=" , message: '"+h+" should be boolean' "),e.opts.verbose&&(n+=" , schema: validate.schema"+A+" , parentSchema: validate.schema"+e.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ";var X=n;n=S.pop(),!e.compositeRule&&a?e.async?n+=" throw new ValidationError(["+X+"]); ":n+=" validate.errors = ["+X+"]; return false; ":n+=" var err = "+X+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",n+=" } else if ( ",c&&(n+=" ("+u+" !== undefined && typeof "+u+" != 'number') || "),n+=" "+G+" == 'number' ? ( ("+v+" = "+u+" === undefined || "+Z+" "+b+"= "+u+") ? "+l+" "+p+"= "+Z+" : "+l+" "+p+" "+u+" ) : ( ("+v+" = "+Z+" === true) ? "+l+" "+p+"= "+u+" : "+l+" "+p+" "+u+" ) || "+l+" !== "+l+") { var op"+C+" = "+v+" ? '"+b+"' : '"+b+"='; ",o===void 0&&(y=h,s=e.errSchemaPath+"/"+h,u=Z,c=f)}else{var B=typeof m=="number",R=b;if(B&&c){var w="'"+R+"'";n+=" if ( ",c&&(n+=" ("+u+" !== undefined && typeof "+u+" != 'number') || "),n+=" ( "+u+" === undefined || "+m+" "+b+"= "+u+" ? "+l+" "+p+"= "+m+" : "+l+" "+p+" "+u+" ) || "+l+" !== "+l+") { "}else{B&&o===void 0?(v=!0,y=h,s=e.errSchemaPath+"/"+h,u=m,p+="="):(B&&(u=Math[d?"min":"max"](m,o)),m===(B?u:!0)?(v=!0,y=h,s=e.errSchemaPath+"/"+h,p+="="):(v=!1,R+="="));var w="'"+R+"'";n+=" if ( ",c&&(n+=" ("+u+" !== undefined && typeof "+u+" != 'number') || "),n+=" "+l+" "+p+" "+u+" || "+l+" !== "+l+") { "}}y=y||I;var S=S||[];S.push(n),n="",e.createErrors!==!1?(n+=" { keyword: '"+(y||"_limit")+"' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(s)+" , params: { comparison: "+w+", limit: "+u+", exclusive: "+v+" } ",e.opts.messages!==!1&&(n+=" , message: 'should be "+R+" ",c?n+="' + "+u:n+=""+u+"'"),e.opts.verbose&&(n+=" , schema: ",c?n+="validate.schema"+A:n+=""+o,n+=" , parentSchema: validate.schema"+e.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ";var X=n;return n=S.pop(),!e.compositeRule&&a?e.async?n+=" throw new ValidationError(["+X+"]); ":n+=" validate.errors = ["+X+"]; return false; ":n+=" var err = "+X+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",n+=" } ",a&&(n+=" else { "),n},kte=function(e,I,i){var n=" ",C=e.level,r=e.dataLevel,o=e.schema[I],A=e.schemaPath+e.util.getProperty(I),s=e.errSchemaPath+"/"+I,a=!e.opts.allErrors,h,l="data"+(r||""),c=e.opts.$data&&o&&o.$data,u;if(c?(n+=" var schema"+C+" = "+e.util.getData(o.$data,r,e.dataPathArr)+"; ",u="schema"+C):u=o,!(c||typeof o=="number"))throw new Error(I+" must be number");var d=I=="maxItems"?">":"<";n+="if ( ",c&&(n+=" ("+u+" !== undefined && typeof "+u+" != 'number') || "),n+=" "+l+".length "+d+" "+u+") { ";var h=I,m=m||[];m.push(n),n="",e.createErrors!==!1?(n+=" { keyword: '"+(h||"_limitItems")+"' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(s)+" , params: { limit: "+u+" } ",e.opts.messages!==!1&&(n+=" , message: 'should NOT have ",I=="maxItems"?n+="more":n+="fewer",n+=" than ",c?n+="' + "+u+" + '":n+=""+o,n+=" items' "),e.opts.verbose&&(n+=" , schema: ",c?n+="validate.schema"+A:n+=""+o,n+=" , parentSchema: validate.schema"+e.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ";var f=n;return n=m.pop(),!e.compositeRule&&a?e.async?n+=" throw new ValidationError(["+f+"]); ":n+=" validate.errors = ["+f+"]; return false; ":n+=" var err = "+f+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",n+="} ",a&&(n+=" else { "),n},Yte=function(e,I,i){var n=" ",C=e.level,r=e.dataLevel,o=e.schema[I],A=e.schemaPath+e.util.getProperty(I),s=e.errSchemaPath+"/"+I,a=!e.opts.allErrors,h,l="data"+(r||""),c=e.opts.$data&&o&&o.$data,u;if(c?(n+=" var schema"+C+" = "+e.util.getData(o.$data,r,e.dataPathArr)+"; ",u="schema"+C):u=o,!(c||typeof o=="number"))throw new Error(I+" must be number");var d=I=="maxLength"?">":"<";n+="if ( ",c&&(n+=" ("+u+" !== undefined && typeof "+u+" != 'number') || "),e.opts.unicode===!1?n+=" "+l+".length ":n+=" ucs2length("+l+") ",n+=" "+d+" "+u+") { ";var h=I,m=m||[];m.push(n),n="",e.createErrors!==!1?(n+=" { keyword: '"+(h||"_limitLength")+"' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(s)+" , params: { limit: "+u+" } ",e.opts.messages!==!1&&(n+=" , message: 'should NOT be ",I=="maxLength"?n+="longer":n+="shorter",n+=" than ",c?n+="' + "+u+" + '":n+=""+o,n+=" characters' "),e.opts.verbose&&(n+=" , schema: ",c?n+="validate.schema"+A:n+=""+o,n+=" , parentSchema: validate.schema"+e.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ";var f=n;return n=m.pop(),!e.compositeRule&&a?e.async?n+=" throw new ValidationError(["+f+"]); ":n+=" validate.errors = ["+f+"]; return false; ":n+=" var err = "+f+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",n+="} ",a&&(n+=" else { "),n},Kte=function(e,I,i){var n=" ",C=e.level,r=e.dataLevel,o=e.schema[I],A=e.schemaPath+e.util.getProperty(I),s=e.errSchemaPath+"/"+I,a=!e.opts.allErrors,h,l="data"+(r||""),c=e.opts.$data&&o&&o.$data,u;if(c?(n+=" var schema"+C+" = "+e.util.getData(o.$data,r,e.dataPathArr)+"; ",u="schema"+C):u=o,!(c||typeof o=="number"))throw new Error(I+" must be number");var d=I=="maxProperties"?">":"<";n+="if ( ",c&&(n+=" ("+u+" !== undefined && typeof "+u+" != 'number') || "),n+=" Object.keys("+l+").length "+d+" "+u+") { ";var h=I,m=m||[];m.push(n),n="",e.createErrors!==!1?(n+=" { keyword: '"+(h||"_limitProperties")+"' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(s)+" , params: { limit: "+u+" } ",e.opts.messages!==!1&&(n+=" , message: 'should NOT have ",I=="maxProperties"?n+="more":n+="fewer",n+=" than ",c?n+="' + "+u+" + '":n+=""+o,n+=" properties' "),e.opts.verbose&&(n+=" , schema: ",c?n+="validate.schema"+A:n+=""+o,n+=" , parentSchema: validate.schema"+e.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ";var f=n;return n=m.pop(),!e.compositeRule&&a?e.async?n+=" throw new ValidationError(["+f+"]); ":n+=" validate.errors = ["+f+"]; return false; ":n+=" var err = "+f+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",n+="} ",a&&(n+=" else { "),n},Ije=function(e,I,i){var n=" ",C=e.level,r=e.dataLevel,o=e.schema[I],A=e.schemaPath+e.util.getProperty(I),s=e.errSchemaPath+"/"+I,a=!e.opts.allErrors,l="data"+(r||""),c=e.opts.$data&&o&&o.$data,u;if(c?(n+=" var schema"+C+" = "+e.util.getData(o.$data,r,e.dataPathArr)+"; ",u="schema"+C):u=o,!(c||typeof o=="number"))throw new Error(I+" must be number");n+="var division"+C+";if (",c&&(n+=" "+u+" !== undefined && ( typeof "+u+" != 'number' || "),n+=" (division"+C+" = "+l+" / "+u+", ",e.opts.multipleOfPrecision?n+=" Math.abs(Math.round(division"+C+") - division"+C+") > 1e-"+e.opts.multipleOfPrecision+" ":n+=" division"+C+" !== parseInt(division"+C+") ",n+=" ) ",c&&(n+=" ) "),n+=" ) { ";var d=d||[];d.push(n),n="",e.createErrors!==!1?(n+=" { keyword: 'multipleOf' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(s)+" , params: { multipleOf: "+u+" } ",e.opts.messages!==!1&&(n+=" , message: 'should be multiple of ",c?n+="' + "+u:n+=""+u+"'"),e.opts.verbose&&(n+=" , schema: ",c?n+="validate.schema"+A:n+=""+o,n+=" , parentSchema: validate.schema"+e.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ";var h=n;return n=d.pop(),!e.compositeRule&&a?e.async?n+=" throw new ValidationError(["+h+"]); ":n+=" validate.errors = ["+h+"]; return false; ":n+=" var err = "+h+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",n+="} ",a&&(n+=" else { "),n},ije=function(e,I,i){var n=" ",C=e.level,r=e.dataLevel,o=e.schema[I],A=e.schemaPath+e.util.getProperty(I),s=e.errSchemaPath+"/"+I,a=!e.opts.allErrors,l="data"+(r||""),c="errs__"+C,u=e.util.copy(e);u.level++;var d="valid"+u.level;if(e.opts.strictKeywords?typeof o=="object"&&Object.keys(o).length>0||o===!1:e.util.schemaHasRules(o,e.RULES.all)){u.schema=o,u.schemaPath=A,u.errSchemaPath=s,n+=" var "+c+" = errors; ";var h=e.compositeRule;e.compositeRule=u.compositeRule=!0,u.createErrors=!1;var m;u.opts.allErrors&&(m=u.opts.allErrors,u.opts.allErrors=!1),n+=" "+e.validate(u)+" ",u.createErrors=!0,m&&(u.opts.allErrors=m),e.compositeRule=u.compositeRule=h,n+=" if ("+d+") { ";var f=f||[];f.push(n),n="",e.createErrors!==!1?(n+=" { keyword: 'not' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(s)+" , params: {} ",e.opts.messages!==!1&&(n+=" , message: 'should NOT be valid' "),e.opts.verbose&&(n+=" , schema: validate.schema"+A+" , parentSchema: validate.schema"+e.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ";var b=n;n=f.pop(),!e.compositeRule&&a?e.async?n+=" throw new ValidationError(["+b+"]); ":n+=" validate.errors = ["+b+"]; return false; ":n+=" var err = "+b+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",n+=" } else { errors = "+c+"; if (vErrors !== null) { if ("+c+") vErrors.length = "+c+"; else vErrors = null; } ",e.opts.allErrors&&(n+=" } ")}else n+=" var err = ",e.createErrors!==!1?(n+=" { keyword: 'not' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(s)+" , params: {} ",e.opts.messages!==!1&&(n+=" , message: 'should NOT be valid' "),e.opts.verbose&&(n+=" , schema: validate.schema"+A+" , parentSchema: validate.schema"+e.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ",n+="; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",a&&(n+=" if (false) { ");return n},nje=function(e,I,i){var n=" ",C=e.level,r=e.dataLevel,o=e.schema[I],A=e.schemaPath+e.util.getProperty(I),s=e.errSchemaPath+"/"+I,a=!e.opts.allErrors,l="data"+(r||""),c="valid"+C,u="errs__"+C,d=e.util.copy(e),h="";d.level++;var m="valid"+d.level,f=d.baseId,b="prevValid"+C,p="passingSchemas"+C;n+="var "+u+" = errors , "+b+" = false , "+c+" = false , "+p+" = null; ";var y=e.compositeRule;e.compositeRule=d.compositeRule=!0;var Z=o;if(Z)for(var v,G=-1,B=Z.length-1;G0||v===!1:e.util.schemaHasRules(v,e.RULES.all))?(d.schema=v,d.schemaPath=A+"["+G+"]",d.errSchemaPath=s+"/"+G,n+=" "+e.validate(d)+" ",d.baseId=f):n+=" var "+m+" = true; ",G&&(n+=" if ("+m+" && "+b+") { "+c+" = false; "+p+" = ["+p+", "+G+"]; } else { ",h+="}"),n+=" if ("+m+") { "+c+" = "+b+" = true; "+p+" = "+G+"; }";return e.compositeRule=d.compositeRule=y,n+=""+h+"if (!"+c+") { var err = ",e.createErrors!==!1?(n+=" { keyword: 'oneOf' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(s)+" , params: { passingSchemas: "+p+" } ",e.opts.messages!==!1&&(n+=" , message: 'should match exactly one schema in oneOf' "),e.opts.verbose&&(n+=" , schema: validate.schema"+A+" , parentSchema: validate.schema"+e.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ",n+="; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",!e.compositeRule&&a&&(e.async?n+=" throw new ValidationError(vErrors); ":n+=" validate.errors = vErrors; return false; "),n+="} else { errors = "+u+"; if (vErrors !== null) { if ("+u+") vErrors.length = "+u+"; else vErrors = null; }",e.opts.allErrors&&(n+=" } "),n},Cje=function(e,I,i){var n=" ",C=e.level,r=e.dataLevel,o=e.schema[I],A=e.schemaPath+e.util.getProperty(I),s=e.errSchemaPath+"/"+I,a=!e.opts.allErrors,l="data"+(r||""),c=e.opts.$data&&o&&o.$data,u;c?(n+=" var schema"+C+" = "+e.util.getData(o.$data,r,e.dataPathArr)+"; ",u="schema"+C):u=o;var d=c?"(new RegExp("+u+"))":e.usePattern(o);n+="if ( ",c&&(n+=" ("+u+" !== undefined && typeof "+u+" != 'string') || "),n+=" !"+d+".test("+l+") ) { ";var h=h||[];h.push(n),n="",e.createErrors!==!1?(n+=" { keyword: 'pattern' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(s)+" , params: { pattern: ",c?n+=""+u:n+=""+e.util.toQuotedString(o),n+=" } ",e.opts.messages!==!1&&(n+=` , message: 'should match pattern "`,c?n+="' + "+u+" + '":n+=""+e.util.escapeQuotes(o),n+=`"' `),e.opts.verbose&&(n+=" , schema: ",c?n+="validate.schema"+A:n+=""+e.util.toQuotedString(o),n+=" , parentSchema: validate.schema"+e.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ";var m=n;return n=h.pop(),!e.compositeRule&&a?e.async?n+=" throw new ValidationError(["+m+"]); ":n+=" validate.errors = ["+m+"]; return false; ":n+=" var err = "+m+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",n+="} ",a&&(n+=" else { "),n},rje=function(e,I,i){var n=" ",C=e.level,r=e.dataLevel,o=e.schema[I],A=e.schemaPath+e.util.getProperty(I),s=e.errSchemaPath+"/"+I,a=!e.opts.allErrors,l="data"+(r||""),c="errs__"+C,u=e.util.copy(e),d="";u.level++;var h="valid"+u.level,m="key"+C,f="idx"+C,b=u.dataLevel=e.dataLevel+1,p="data"+b,y="dataProperties"+C,Z=Object.keys(o||{}).filter(F),v=e.schema.patternProperties||{},G=Object.keys(v).filter(F),B=e.schema.additionalProperties,w=Z.length||G.length,R=B===!1,S=typeof B=="object"&&Object.keys(B).length,X=e.opts.removeAdditional,W=R||S||X,V=e.opts.ownProperties,H=e.baseId,D=e.schema.required;if(D&&!(e.opts.$data&&D.$data)&&D.length8)n+=" || validate.schema"+A+".hasOwnProperty("+m+") ";else{var _=Z;if(_)for(var J,te=-1,q=_.length-1;te0||_e===!1:e.util.schemaHasRules(_e,e.RULES.all)){var At=e.util.getProperty(J),ke=l+At,wt=Oe&&_e.default!==void 0;u.schema=_e,u.schemaPath=A+At,u.errSchemaPath=s+"/"+e.util.escapeFragment(J),u.errorPath=e.util.getPath(e.errorPath,J,e.opts.jsonPointers),u.dataPathArr[b]=e.util.toQuotedString(J);var Xe=e.validate(u);if(u.baseId=H,e.util.varOccurences(Xe,p)<2){Xe=e.util.varReplace(Xe,p,ke);var rt=ke}else{var rt=p;n+=" var "+p+" = "+ke+"; "}if(wt)n+=" "+Xe+" ";else{if(Y&&Y[J]){n+=" if ( "+rt+" === undefined ",V&&(n+=" || ! Object.prototype.hasOwnProperty.call("+l+", '"+e.util.escapeQuotes(J)+"') "),n+=") { "+h+" = false; ";var ne=e.errorPath,Ce=s,Te=e.util.escapeQuotes(J);e.opts._errorDataPathProperty&&(e.errorPath=e.util.getPath(ne,J,e.opts.jsonPointers)),s=e.errSchemaPath+"/required";var Ze=Ze||[];Ze.push(n),n="",e.createErrors!==!1?(n+=" { keyword: 'required' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(s)+" , params: { missingProperty: '"+Te+"' } ",e.opts.messages!==!1&&(n+=" , message: '",e.opts._errorDataPathProperty?n+="is a required property":n+="should have required property \\'"+Te+"\\'",n+="' "),e.opts.verbose&&(n+=" , schema: validate.schema"+A+" , parentSchema: validate.schema"+e.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ";var Ge=n;n=Ze.pop(),!e.compositeRule&&a?e.async?n+=" throw new ValidationError(["+Ge+"]); ":n+=" validate.errors = ["+Ge+"]; return false; ":n+=" var err = "+Ge+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",s=Ce,e.errorPath=ne,n+=" } else { "}else a?(n+=" if ( "+rt+" === undefined ",V&&(n+=" || ! Object.prototype.hasOwnProperty.call("+l+", '"+e.util.escapeQuotes(J)+"') "),n+=") { "+h+" = true; } else { "):(n+=" if ("+rt+" !== undefined ",V&&(n+=" && Object.prototype.hasOwnProperty.call("+l+", '"+e.util.escapeQuotes(J)+"') "),n+=" ) { ");n+=" "+Xe+" } "}}a&&(n+=" if ("+h+") { ",d+="}")}}if(G.length){var le=G;if(le)for(var j,ye=-1,We=le.length-1;ye0||_e===!1:e.util.schemaHasRules(_e,e.RULES.all)){u.schema=_e,u.schemaPath=e.schemaPath+".patternProperties"+e.util.getProperty(j),u.errSchemaPath=e.errSchemaPath+"/patternProperties/"+e.util.escapeFragment(j),V?n+=" "+y+" = "+y+" || Object.keys("+l+"); for (var "+f+"=0; "+f+"<"+y+".length; "+f+"++) { var "+m+" = "+y+"["+f+"]; ":n+=" for (var "+m+" in "+l+") { ",n+=" if ("+e.usePattern(j)+".test("+m+")) { ",u.errorPath=e.util.getPathExpr(e.errorPath,m,e.opts.jsonPointers);var ke=l+"["+m+"]";u.dataPathArr[b]=m;var Xe=e.validate(u);u.baseId=H,e.util.varOccurences(Xe,p)<2?n+=" "+e.util.varReplace(Xe,p,ke)+" ":n+=" var "+p+" = "+ke+"; "+Xe+" ",a&&(n+=" if (!"+h+") break; "),n+=" } ",a&&(n+=" else "+h+" = true; "),n+=" } ",a&&(n+=" if ("+h+") { ",d+="}")}}}return a&&(n+=" "+d+" if ("+c+" == errors) {"),n},oje=function(e,I,i){var n=" ",C=e.level,r=e.dataLevel,o=e.schema[I],A=e.schemaPath+e.util.getProperty(I),s=e.errSchemaPath+"/"+I,a=!e.opts.allErrors,l="data"+(r||""),c="errs__"+C,u=e.util.copy(e),d="";u.level++;var h="valid"+u.level;if(n+="var "+c+" = errors;",e.opts.strictKeywords?typeof o=="object"&&Object.keys(o).length>0||o===!1:e.util.schemaHasRules(o,e.RULES.all)){u.schema=o,u.schemaPath=A,u.errSchemaPath=s;var m="key"+C,f="idx"+C,b="i"+C,p="' + "+m+" + '",y=u.dataLevel=e.dataLevel+1,Z="data"+y,v="dataProperties"+C,G=e.opts.ownProperties,B=e.baseId;G&&(n+=" var "+v+" = undefined; "),G?n+=" "+v+" = "+v+" || Object.keys("+l+"); for (var "+f+"=0; "+f+"<"+v+".length; "+f+"++) { var "+m+" = "+v+"["+f+"]; ":n+=" for (var "+m+" in "+l+") { ",n+=" var startErrs"+C+" = errors; ";var w=m,R=e.compositeRule;e.compositeRule=u.compositeRule=!0;var S=e.validate(u);u.baseId=B,e.util.varOccurences(S,Z)<2?n+=" "+e.util.varReplace(S,Z,w)+" ":n+=" var "+Z+" = "+w+"; "+S+" ",e.compositeRule=u.compositeRule=R,n+=" if (!"+h+") { for (var "+b+"=startErrs"+C+"; "+b+"0||y===!1:e.util.schemaHasRules(y,e.RULES.all))||(h[h.length]=f)}}else var h=o;if(u||h.length){var Z=e.errorPath,v=u||h.length>=e.opts.loopRequired,G=e.opts.ownProperties;if(a)if(n+=" var missing"+C+"; ",v){u||(n+=" var "+d+" = validate.schema"+A+"; ");var B="i"+C,w="schema"+C+"["+B+"]",R="' + "+w+" + '";e.opts._errorDataPathProperty&&(e.errorPath=e.util.getPathExpr(Z,w,e.opts.jsonPointers)),n+=" var "+c+" = true; ",u&&(n+=" if (schema"+C+" === undefined) "+c+" = true; else if (!Array.isArray(schema"+C+")) "+c+" = false; else {"),n+=" for (var "+B+" = 0; "+B+" < "+d+".length; "+B+"++) { "+c+" = "+l+"["+d+"["+B+"]] !== undefined ",G&&(n+=" && Object.prototype.hasOwnProperty.call("+l+", "+d+"["+B+"]) "),n+="; if (!"+c+") break; } ",u&&(n+=" } "),n+=" if (!"+c+") { ";var S=S||[];S.push(n),n="",e.createErrors!==!1?(n+=" { keyword: 'required' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(s)+" , params: { missingProperty: '"+R+"' } ",e.opts.messages!==!1&&(n+=" , message: '",e.opts._errorDataPathProperty?n+="is a required property":n+="should have required property \\'"+R+"\\'",n+="' "),e.opts.verbose&&(n+=" , schema: validate.schema"+A+" , parentSchema: validate.schema"+e.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ";var X=n;n=S.pop(),!e.compositeRule&&a?e.async?n+=" throw new ValidationError(["+X+"]); ":n+=" validate.errors = ["+X+"]; return false; ":n+=" var err = "+X+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",n+=" } else { "}else{n+=" if ( ";var W=h;if(W)for(var V,B=-1,H=W.length-1;B 1) { ";var h=e.schema.items&&e.schema.items.type,m=Array.isArray(h);if(!h||h=="object"||h=="array"||m&&(h.indexOf("object")>=0||h.indexOf("array")>=0))n+=" outer: for (;i--;) { for (j = i; j--;) { if (equal("+l+"[i], "+l+"[j])) { "+c+" = false; break outer; } } } ";else{n+=" var itemIndices = {}, item; for (;i--;) { var item = "+l+"[i]; ";var f="checkDataType"+(m?"s":"");n+=" if ("+e.util[f](h,"item",e.opts.strictNumbers,!0)+") continue; ",m&&(n+=` if (typeof item == 'string') item = '"' + item; `),n+=" if (typeof itemIndices[item] == 'number') { "+c+" = false; j = itemIndices[item]; break; } itemIndices[item] = i; } "}n+=" } ",u&&(n+=" } "),n+=" if (!"+c+") { ";var b=b||[];b.push(n),n="",e.createErrors!==!1?(n+=" { keyword: 'uniqueItems' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(s)+" , params: { i: i, j: j } ",e.opts.messages!==!1&&(n+=" , message: 'should NOT have duplicate items (items ## ' + j + ' and ' + i + ' are identical)' "),e.opts.verbose&&(n+=" , schema: ",u?n+="validate.schema"+A:n+=""+o,n+=" , parentSchema: validate.schema"+e.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ";var p=n;n=b.pop(),!e.compositeRule&&a?e.async?n+=" throw new ValidationError(["+p+"]); ":n+=" validate.errors = ["+p+"]; return false; ":n+=" var err = "+p+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",n+=" } ",a&&(n+=" else { ")}else a&&(n+=" if (true) { ");return n},sje={$ref:OQe,allOf:LQe,anyOf:_Qe,$comment:UQe,const:QQe,contains:jQe,dependencies:$Qe,enum:qQe,format:eje,if:tje,items:gje,maximum:Nte,minimum:Nte,maxItems:kte,minItems:kte,maxLength:Yte,minLength:Yte,maxProperties:Kte,minProperties:Kte,multipleOf:Ije,not:ije,oneOf:nje,pattern:Cje,properties:rje,propertyNames:oje,required:Aje,uniqueItems:aje,validate:kbe},xte=sje,b5=E0.toHash,lje=function(){var e=[{type:"number",rules:[{maximum:["exclusiveMaximum"]},{minimum:["exclusiveMinimum"]},"multipleOf","format"]},{type:"string",rules:["maxLength","minLength","pattern","format"]},{type:"array",rules:["maxItems","minItems","items","contains","uniqueItems"]},{type:"object",rules:["maxProperties","minProperties","required","dependencies","propertyNames",{properties:["additionalProperties","patternProperties"]}]},{rules:["$ref","const","enum","not","anyOf","oneOf","allOf","if"]}],I=["type","$comment"],i=["$schema","$id","id","$data","$async","title","description","default","definitions","examples","readOnly","writeOnly","contentMediaType","contentEncoding","additionalItems","then","else"],n=["number","integer","string","array","object","boolean","null"];return e.all=b5(I),e.types=b5(n),e.forEach(function(C){C.rules=C.rules.map(function(r){var o;if(typeof r=="object"){var A=Object.keys(r)[0];o=r[A],r=A,o.forEach(function(a){I.push(a),e.all[a]=!0})}I.push(r);var s=e.all[r]={keyword:r,code:xte[r],implements:o};return s}),e.all.$comment={keyword:"$comment",code:xte.$comment},C.type&&(e.types[C.type]=C)}),e.keywords=b5(I.concat(i)),e.custom={},e},Dte=["multipleOf","maximum","exclusiveMaximum","minimum","exclusiveMinimum","maxLength","minLength","pattern","additionalItems","maxItems","minItems","uniqueItems","maxProperties","minProperties","required","additionalProperties","enum","format","const"],cje=function(g,e){for(var I=0;I{e(I,i,n),s9(I,e)}):"views"in g&&g.views.forEach(I=>s9(I,e))}function Wb(g,e){"tracks"in g?g.tracks.forEach(I=>{e(I),Wb(I,e)}):"views"in g&&g.views.forEach(I=>{e(I),Wb(I,e)})}function i0e(g,e){"tracks"in g||(e(g),g.views.forEach(I=>{i0e(I,e)}))}function n0e(g){if(wbe(g)){const I={...g,tracks:void 0,id:void 0};return g.tracks.filter(i=>!i._invalidTrack).map(i=>Object.assign(JSON.parse(JSON.stringify(I)),i))}const e=[];return R7e(g)?g.tracks.filter(I=>!I._invalidTrack).map(I=>{if("alignment"in I)e.push({...I,_overlay:[...I.tracks],tracks:void 0,alignment:void 0});else{const i={...g,tracks:void 0,id:void 0},n=Object.assign(JSON.parse(JSON.stringify(i)),I);e.push(n)}}):e.push({...g,_overlay:[...g.tracks.filter(I=>!I._invalidTrack)],tracks:void 0,alignment:void 0}),JSON.parse(JSON.stringify(e))}function a3(g,e){if(e?(g.assembly===void 0&&(g.assembly=e.assembly),g.layout===void 0&&(g.layout=e.layout),g.orientation===void 0&&(g.orientation=e.orientation),g.static===void 0&&(g.static=e.static!==void 0?e.static:!1),g.zoomLimits===void 0&&(g.zoomLimits=e.zoomLimits),g.xDomain===void 0&&(g.xDomain=e.xDomain),g.yDomain===void 0&&(g.yDomain=e.yDomain),g.linkingId===void 0&&(g.linkingId=e.linkingId),g.centerRadius===void 0&&(g.centerRadius=e.centerRadius),g.spacing===void 0&&!("tracks"in g)&&(g.spacing=e.spacing),g.xOffset===void 0&&(g.xOffset=e.xOffset),g.yOffset===void 0&&(g.yOffset=e.yOffset),"views"in g&&"arrangement"in e&&g.arrangement===void 0&&(g.arrangement=e.arrangement),g.style=Z5(e.style,g.style)):(g.assembly===void 0&&(g.assembly="hg38"),g.layout===void 0&&(g.layout="linear"),g.orientation===void 0&&(g.orientation="horizontal"),g.static===void 0&&(g.static=!1),g.zoomLimits===void 0&&(g.zoomLimits=[1,null]),g.centerRadius===void 0&&(g.centerRadius=Gbe),g.spacing===void 0&&(g.spacing=O1),"views"in g&&g.arrangement===void 0&&(g.arrangement="vertical"),g.xOffset===void 0&&(g.xOffset=0),g.yOffset===void 0&&(g.yOffset=0)),g.id||(g.id=on()),"tracks"in g){let I=n0e(g);I=Sbe(I);const i=on();I.forEach((n,C,r)=>{var o,A,s;if(n.id||(n.id=on()),n.width||(n.width=IC(n)?vte:OUe),n.height||(n.height=IC(n)?vte:JUe),"displacement"in n)if(((o=n.displacement)==null?void 0:o.type)==="pile"&&n.row===void 0&<(n.x)&&n.x.field&<(n.xe)&&n.xe.field){const a=on(),l=n.x.field,c=n.xe.field,u=n.displacement.padding,d={type:"displace",newField:a,boundingBox:{startField:l,endField:c,padding:u},method:"pile"};n.dataTransform||(n.dataTransform=[]),n.dataTransform=[...n.dataTransform,d],n.row={field:a,type:"nominal"}}else(A=n.displacement)==null||A.type;if(n.layout&&(n.layout=void 0),n.zoomLimits&&(n.zoomLimits=void 0),n.assembly||(n.assembly=g.assembly),n.layout||(n.layout=g.layout),n.orientation||(n.orientation=g.orientation),n.static===void 0&&(n.static=g.static!==void 0?g.static:!1),n.zoomLimits||(n.zoomLimits=g.zoomLimits),n.layout=="circular"&&zS(n)){n._invalidTrack=!0;return}if(n.style=Z5(g.style,n.style),si(n)&&(n._overlay=n._overlay.filter(a=>!("type"in a&&a.type=="dummy-track")),n._overlay.forEach(a=>{a.style=Z5(n.style,a.style)})),(n.layout==="circular"||IC(n))&&n.orientation==="vertical"&&(n.orientation="horizontal"),IC(n)&&(n.layout="linear",(zr(n)||si(n))&<(n.y)&&!n.y.domain?n.y.domain=g.yDomain:si(n)&&n._overlay.forEach(a=>{lt(a.y)&&!a.y.domain&&(a.y.domain=g.yDomain)})),(zr(n)||si(n))&<(n.x)&&!n.x.domain?n.x.domain=g.xDomain:si(n)&&n._overlay.forEach(a=>{lt(a.x)&&!a.x.domain&&(a.x.domain=g.xDomain)}),(zr(n)||si(n))&<(n.x)&&!n.x.linkingId)n.x.linkingId=(s=g.linkingId)!=null?s:i;else if(si(n)){let a=!1;n._overlay.forEach(l=>{var c;a||lt(l.x)&&!l.x.linkingId&&(l.x.linkingId=(c=g.linkingId)!=null?c:i,a=!0)})}C===0&&(n.overlayOnPreviousTrack=!1),(C===0||C!==0&&I.slice(0,C).filter(a=>!a.overlayOnPreviousTrack).length===1&&n.overlayOnPreviousTrack===!0)&&((zr(n)||si(n))&<(n.x)&&!n.x.axis?n.orientation==="vertical"?n.x.axis="left":n.x.axis="top":si(n)&&n._overlay.forEach(a=>{lt(a.x)&&!a.x.axis&&(n.orientation==="vertical"?a.x.axis="left":a.x.axis="top")})),(zr(n)||si(n))&<(n.x)&&n.x.axis&&n.x.axis!=="none"?n.orientation==="vertical"?n.x.axis==="top"?n.x.axis="left":n.x.axis==="bottom"&&(n.x.axis="right"):n.x.axis==="left"?n.x.axis="top":n.x.axis==="right"&&(n.x.axis="bottom"):si(n)&&n._overlay.forEach(a=>{lt(a.x)&&a.x.axis&&a.x.axis!=="none"&&(n.orientation==="vertical"?a.x.axis==="top"?a.x.axis="left":a.x.axis==="bottom"&&(a.x.axis="right"):a.x.axis==="left"?a.x.axis="top":a.x.axis==="right"&&(a.x.axis="bottom"))}),C!==0&&(C===r.length-1&&r.slice(0,C+1).filter(a=>a.overlayOnPreviousTrack).lengtha.overlayOnPreviousTrack).length===r.length-C-1&&r.slice(0,C+1).filter(a=>a.overlayOnPreviousTrack).length{a.mark==="withinLink"&&a.flipY===void 0&&(a.flipY=!0)}))),n.overlayOnPreviousTrack&&r[C-1]&&(n.width=r[C-1].width,n.height=r[C-1].height,n.layout=r[C-1].layout,n.assembly=r[C-1].assembly)}),I=I.filter(n=>!n._invalidTrack),g.tracks=I}else g.views.forEach(I=>{a3(I,g)})}function h4e(g,e){return{data:{type:"vector",url:"",column:g,value:e},mark:"bar",x:{field:g,type:"genomic",axis:"top"},y:{field:e,type:"quantitative"},width:400,height:100}}function m4e(g,e,I,i){return i&&i.length<10?{data:{type:"multivec",url:"",row:g,column:e,value:I,categories:i},mark:"bar",x:{field:e,type:"genomic",axis:"top"},y:{field:I,type:"quantitative"},row:{field:g,type:"nominal",legend:!0},color:{field:g,type:"nominal"},width:400,height:100}:{data:{type:"multivec",url:"",row:g,column:e,value:I,categories:i},mark:"rect",x:{field:e,type:"genomic",axis:"top"},row:{field:g,type:"nominal",legend:!0},color:{field:I,type:"quantitative"},width:400,height:100}}function f4e(g){s9(g,(e,I,i)=>{var n,C,r,o,A;if(!(!("data"in e)||!e.data||!JU(e.data))&&!("alignment"in e)&&W7e(e))switch(e.data.type){case"vector":case"bigwig":i[I]=Object.assign(h4e((n=e.data.column)!=null?n:"position",(C=e.data.value)!=null?C:"value"),e);break;case"multivec":i[I]=Object.assign(m4e((r=e.data.row)!=null?r:"category",(o=e.data.column)!=null?o:"position",(A=e.data.value)!=null?A:"value",e.data.categories),e);break}})}const G5={chr1:248956422,chr2:242193529,chr3:198295559,chr4:190214555,chr5:181538259,chr6:170805979,chr7:159345973,chr8:145138636,chr9:138394717,chr10:133797422,chr11:135086622,chr12:133275309,chr13:114364328,chr14:107043718,chr15:101991189,chr16:90338345,chr17:83257441,chr18:80373285,chr19:58617616,chr20:64444167,chr21:46709983,chr22:50818468,chrX:156040895,chrY:57227415},B5={chr1:249250621,chr2:243199373,chr3:198022430,chr4:191154276,chr5:180915260,chr6:171115067,chr7:159138663,chr8:146364022,chr9:141213431,chr10:135534747,chr11:135006516,chr12:133851895,chr13:115169878,chr14:107349540,chr15:102531392,chr16:90354753,chr17:81195210,chr18:78077248,chr19:59128983,chr20:63025520,chr21:48129895,chr22:51304566,chrX:155270560,chrY:59373566,chrM:16571},v5={chr1:247249719,chr2:242951149,chr3:199501827,chr4:191273063,chr5:180857866,chr6:170899992,chr7:158821424,chr8:146274826,chr9:140273252,chr10:135374737,chr11:134452384,chr12:132349534,chr13:114142980,chr14:106368585,chr15:100338915,chr16:88827254,chr17:78774742,chr18:76117153,chr19:63811651,chr20:62435964,chr21:46944323,chr22:49691432,chrX:154913754,chrY:57772954,chrM:16571},S5={chr1:245522847,chr2:243018229,chr3:199505740,chr4:191411218,chr5:180857866,chr6:170975699,chr7:158628139,chr8:146274826,chr9:138429268,chr10:135413628,chr11:134452384,chr12:132449811,chr13:114142980,chr14:106368585,chr15:100338915,chr16:88827254,chr17:78774742,chr18:76117153,chr19:63811651,chr20:62435964,chr21:46944323,chr22:49554710,chrX:154824264,chrY:57701691,chrM:16571},w5={chr1:246127941,chr2:243615958,chr3:199344050,chr4:191731959,chr5:181034922,chr6:170914576,chr7:158545518,chr8:146308819,chr9:136372045,chr10:135037215,chr11:134482954,chr12:132078379,chr13:113042980,chr14:105311216,chr15:100256656,chr16:90041932,chr17:81860266,chr18:76115139,chr19:63811651,chr20:63741868,chr21:46976097,chr22:49396972,chrX:153692391,chrY:50286555,chrM:16571},V5={chr1:195471971,chr2:182113224,chr3:160039680,chr4:156508116,chr5:151834684,chr6:149736546,chr7:145441459,chr8:129401213,chr9:124595110,chr10:130694993,chr11:122082543,chr12:120129022,chr13:120421639,chr14:124902244,chr15:104043685,chr16:98207768,chr17:94987271,chr18:90702639,chr19:61431566,chrX:171031299,chrY:91744698,chrM:16299},R5={chr1:197195432,chr2:181748087,chr3:159599783,chr4:155630120,chr5:152537259,chr6:149517037,chr7:152524553,chr8:131738871,chr9:124076172,chr10:129993255,chr11:121843856,chr12:121257530,chr13:120284312,chr14:125194864,chr15:103494974,chr16:98319150,chr17:95272651,chr18:90772031,chr19:61342430,chrX:166650296,chrY:15902555,chrM:16299};function gd(g,e,I=!1){const i=Object.entries(yI(e).interval),n={chromosome:"unknown",position:1/0},C={chromosome:"unknown",position:0};for(const r of i){const[o,A]=r,[s,a]=A;if(s<=g&&gC.position&&(C.chromosome=o,C.position=a)}return I?gi.join(" ")).join(` -`),I=new Blob([e],{type:"text/tsv"});return URL.createObjectURL(I)}function yI(g){if(g&&typeof g=="string"&&g in W5)return W5[g];if(Array.isArray(g)&&g.length!==0){const e=Object.fromEntries(g);return{size:e,interval:Dl(e),total:Fl(e),path:p4e(g)}}else return W5.hg38}const Vl=g=>`https://s3.amazonaws.com/gosling-lang.org/data/${g}.chrom.sizes`,W5=Object.freeze({hg38:{size:G5,interval:Dl(G5),total:Fl(G5),path:Vl("hg38")},hg19:{size:B5,interval:Dl(B5),total:Fl(B5),path:Vl("hg19")},hg18:{size:v5,interval:Dl(v5),total:Fl(v5),path:Vl("hg18")},hg17:{size:S5,interval:Dl(S5),total:Fl(S5),path:Vl("hg17")},hg16:{size:w5,interval:Dl(w5),total:Fl(w5),path:Vl("hg16")},mm10:{size:V5,interval:Dl(V5),total:Fl(V5),path:Vl("mm10")},mm9:{size:R5,interval:Dl(R5),total:Fl(R5),path:Vl("mm9")},unknown:{size:{chr:Number.MAX_VALUE},interval:{chr:[0,Number.MAX_VALUE]},total:Number.MAX_VALUE,path:Vl("hg38")}});function b4e(g){switch(g){case"hg19":return"OHJakQICQD6gTD7skx4EWA";case"mm10":return"QDutvmyiSrec5nX4pA5WGQ";case"mm9":return"GUm5aBiLRCyz2PsBea7Yzg";case"hg38":default:return"P0PLbQMwTYGy-5uPIQid7A"}}function Dl(g){const e={};return Object.keys(g).reduce((I,i)=>(e[i]=[I,I+g[i]],I+g[i]),0),e}function Fl(g){return Object.values(g).reduce((e,I)=>e+I,0)}function y4e(g){const[e,I]=g.split(":");if(I){const[i,n]=I.split("-").map(C=>+C.replace(/,/g,""));if(!Number.isNaN(i)&&!Number.isNaN(n))return{chromosome:e,start:i,end:n}}return{chromosome:e}}class t7{constructor(e,I,i){this.chromosome=e,this.start=I,this.end=i}static fromString(e){const I=y4e(e);return new t7(I.chromosome,I.start,I.end)}toAbsoluteCoordinates(e,I=0){const i=yI(e),n=i.size[this.chromosome],C=i.interval[this.chromosome];if(n===void 0||C===void 0)throw new Error(`Chromosome name ${this.chromosome} is not valid`);let{start:r,end:o}=this;(r===void 0||o===void 0)&&([r,o]=[1,n]);const A=C[0];return[r+A-I,o+A+I]}}function C0e(g,[e,I],i){const{x:n,xe:C,x1:r,x1e:o}=i,A=[n,C,r,o].filter(s=>s);return g.filter(s=>{if(A.length===0)return!0;if(A.length===1){const a=+s[A[0]];return typeof a=="number"&&e+s[u]).filter(u=>!isNaN(u)),l=Math.min(...a),c=Math.max(...a);return e<=c&&l<=I}})}wU(g=>g.pos).left;function s3(g,e,I){return Array.isArray(e)||(I?g=g.replace(I,"chr"):g.includes("chr")||(g=`chr${g}`)),g}class r0e extends Zbe{constructor(){super(...arguments),PUe(this,"read",async(e,I=0,i,n=0,C={})=>{const{headers:r={},signal:o,overrides:A={}}=C;i<1/0?r.range=`bytes=${n}-${n+i}`:i===1/0&&n!==0&&(r.range=`bytes=${n}-`);const s={...this.baseOverrides,...A,headers:{...r,...A.headers,...this.baseOverrides.headers},method:"GET",redirect:"follow",mode:"cors",signal:o},a=await this.fetch(this.url,s);if(!a.ok)throw new Error(`HTTP ${a.status} ${a.statusText} ${this.url}`);if(a.status===200||a.status===206){const l=await this.getBufferFromResponse(a),c=l.copy(e,I,0,Math.min(i,l.length)),u=a.headers.get("content-range"),d=/\/(\d+)$/.exec(u||"");return d&&d[1]&&(this._stat={size:parseInt(d[1],10)}),{bytesRead:c,buffer:e}}throw new Error(`HTTP ${a.status} fetching ${this.url}`)})}}window.higlassTracks=window.higlassTracks||{};window.higlassTracksByType=window.higlassTracksByType||{};window.higlassDataFetchersByType=window.higlassDataFetchersByType||{};const Mte=()=>Math.random().toString(36).substring(2,8),Z4e=(g,{force:e=!1}={})=>{let I=Mte();for(;window.higlassTracks[I];)I=Mte();g.name=I,window.higlassTracks[g.name]=g,window.higlassTracksByType[g.config.type]&&!e?console.warn(`A track with the same type (${g.config.type}) was already registered. To override it, set force to true.`):window.higlassTracksByType[g.config.type]=g},G4e=(g,{force:e=!1}={})=>{window.higlassDataFetchersByType[g.config.type]&&!e?console.warn(`A data fetcher with the same type (${g.config.type}) was already registered. To override it, set force to true.`):window.higlassDataFetchersByType[g.config.type]=g},Yu=(g,e={})=>{const{pluginType:I="track"}=e;I==="track"?Z4e(g,e):I==="dataFetcher"&&G4e(g,e)};var JS={},l3={exports:{}},zte=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||typeof msCrypto<"u"&&typeof window.msCrypto.getRandomValues=="function"&&msCrypto.getRandomValues.bind(msCrypto);if(zte){var Pte=new Uint8Array(16);l3.exports=function(){return zte(Pte),Pte}}else{var Jte=new Array(16);l3.exports=function(){for(var e=0,I;e<16;e++)e&3||(I=Math.random()*4294967296),Jte[e]=I>>>((e&3)<<3)&255;return Jte}}var B4e=l3.exports,o0e=[];for(var gR=0;gR<256;++gR)o0e[gR]=(gR+256).toString(16).substr(1);function v4e(g,e){var I=e||0,i=o0e;return[i[g[I++]],i[g[I++]],i[g[I++]],i[g[I++]],"-",i[g[I++]],i[g[I++]],"-",i[g[I++]],i[g[I++]],"-",i[g[I++]],i[g[I++]],"-",i[g[I++]],i[g[I++]],i[g[I++]],i[g[I++]],i[g[I++]],i[g[I++]]].join("")}var S4e=v4e,w4e=B4e,V4e=S4e;function R4e(g,e,I){var i=e&&I||0;typeof g=="string"&&(e=g==="binary"?new Array(16):null,g=null),g=g||{};var n=g.random||(g.rng||w4e)();if(n[6]=n[6]&15|64,n[8]=n[8]&63|128,e)for(var C=0;C<16;++C)e[i+C]=n[C];return e||V4e(n)}var W4e=R4e,c3=[],A0e={};for(var Pm=0;Pm<256;Pm++)c3[Pm]=(Pm+256).toString(16).substr(1),A0e[c3[Pm]]=Pm;function X4e(g,e,I){var i=e&&I||0,n=0;for(e=e||[],g.toLowerCase().replace(/[0-9a-f]{2}/g,function(C){n<16&&(e[i+n++]=A0e[C])});n<16;)e[i+n++]=0;return e}function H4e(g,e){var I=e||0,i=c3;return i[g[I++]]+i[g[I++]]+i[g[I++]]+i[g[I++]]+"-"+i[g[I++]]+i[g[I++]]+"-"+i[g[I++]]+i[g[I++]]+"-"+i[g[I++]]+i[g[I++]]+"-"+i[g[I++]]+i[g[I++]]+i[g[I++]]+i[g[I++]]+i[g[I++]]+i[g[I++]]}var T4e={parse:X4e,unparse:H4e},a0e=W4e,s0e=T4e;JS.encode=function(g){var e=s0e.parse(g),I=new Buffer(e).toString("base64"),i=I.replace(/\+/g,"-").replace(/\//g,"_").substring(0,22);return i};JS.decode=function(g){var e=g.replace(/-/g,"+").replace(/_/g,"/")+"==";return s0e.unparse(new Buffer(e,"base64"))};JS.v4=function(){var g=a0e(null,new Buffer(16)),e=g.toString("base64"),I=e.replace(/\+/g,"-").replace(/\//g,"_").substring(0,22);return I};JS.nice=function(){var g=a0e(null,new Buffer(16));g[0]=g[0]&127;var e=g.toString("base64"),I=e.replace(/\+/g,"-").replace(/\//g,"_").substring(0,22);return I};var N4e=JS;const k4e=jh(N4e);var Y4e=function(){function g(e,I){for(var i=0;i1?I-1:0),n=1;nI;){if(i-I>600){var C=i-I+1,r=e-I+1,o=Math.log(C),A=.5*Math.exp(2*o/3),s=.5*Math.sqrt(o*A*(C-A)/C)*(r-C/2<0?-1:1),a=Math.max(I,Math.floor(e-r*A/C+s)),l=Math.min(i,Math.floor(e+(C-r)*A/C+s));l0e(g,e,a,l,n)}var c=g[e],u=I,d=i;for(Ly(g,I,e),n(g[i],c)>0&&Ly(g,I,i);u0;)d--}n(g[I],c)===0?Ly(g,I,d):(d++,Ly(g,d,i)),d<=e&&(I=d+1),e<=d&&(i=d-1)}}function Ly(g,e,I){var i=g[e];g[e]=g[I],g[I]=i}function O4e(g,e){return ge?1:0}class L4e{constructor(e=9){this._maxEntries=Math.max(4,e),this._minEntries=Math.max(2,Math.ceil(this._maxEntries*.4)),this.clear()}all(){return this._all(this.data,[])}search(e){let I=this.data;const i=[];if(!iR(e,I))return i;const n=this.toBBox,C=[];for(;I;){for(let r=0;r=0&&C[I].children.length>this._maxEntries;)this._split(C,I),I--;this._adjustParentBBoxes(n,C,I)}_split(e,I){const i=e[I],n=i.children.length,C=this._minEntries;this._chooseSplitAxis(i,C,n);const r=this._chooseSplitIndex(i,C,n),o=Xf(i.children.splice(r,i.children.length-r));o.height=i.height,o.leaf=i.leaf,Jm(i,this.toBBox),Jm(o,this.toBBox),I?e[I-1].children.push(o):this._splitRoot(i,o)}_splitRoot(e,I){this.data=Xf([e,I]),this.data.height=e.height+1,this.data.leaf=!1,Jm(this.data,this.toBBox)}_chooseSplitIndex(e,I,i){let n,C=1/0,r=1/0;for(let o=I;o<=i-I;o++){const A=OZ(e,0,o,this.toBBox),s=OZ(e,o,i,this.toBBox),a=$4e(A,s),l=X5(A)+X5(s);a=I;s--){const a=e.children[s];LZ(o,e.leaf?C(a):a),A+=IR(o)}return A}_adjustParentBBoxes(e,I,i){for(let n=i;n>=0;n--)LZ(I[n],e)}_condense(e){for(let I=e.length-1,i;I>=0;I--)e[I].children.length===0?I>0?(i=e[I-1].children,i.splice(i.indexOf(e[I]),1)):this.clear():Jm(e[I],this.toBBox)}}function _4e(g,e,I){if(!I)return e.indexOf(g);for(let i=0;i=g.minX&&e.maxY>=g.minY}function Xf(g){return{children:g,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function Ote(g,e,I,i,n){const C=[e,I];for(;C.length;){if(I=C.pop(),e=C.pop(),I-e<=i)continue;const r=e+Math.ceil((I-e)/i/2)*i;J4e(g,r,e,I,n),C.push(e,r,r,I)}}function q4e(g){return Math.abs(g=Math.round(g))>=1e21?g.toLocaleString("en").replace(/,/g,""):g.toString(10)}function l9(g,e){if((I=(g=e?g.toExponential(e-1):g.toExponential()).indexOf("e"))<0)return null;var I,i=g.slice(0,I);return[i.length>1?i[0]+i.slice(2):i,+g.slice(I+1)]}function d3(g){return g=l9(Math.abs(g)),g?g[1]:NaN}function e$e(g,e){return function(I,i){for(var n=I.length,C=[],r=0,o=g[0],A=0;n>0&&o>0&&(A+o+1>i&&(o=Math.max(1,i-A)),C.push(I.substring(n-=o,n+o)),!((A+=o+1)>i));)o=g[r=(r+1)%g.length];return C.reverse().join(e)}}function t$e(g){return function(e){return e.replace(/[0-9]/g,function(I){return g[+I]})}}var g$e=/^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;function h3(g){if(!(e=g$e.exec(g)))throw new Error("invalid format: "+g);var e;return new g7({fill:e[1],align:e[2],sign:e[3],symbol:e[4],zero:e[5],width:e[6],comma:e[7],precision:e[8]&&e[8].slice(1),trim:e[9],type:e[10]})}h3.prototype=g7.prototype;function g7(g){this.fill=g.fill===void 0?" ":g.fill+"",this.align=g.align===void 0?">":g.align+"",this.sign=g.sign===void 0?"-":g.sign+"",this.symbol=g.symbol===void 0?"":g.symbol+"",this.zero=!!g.zero,this.width=g.width===void 0?void 0:+g.width,this.comma=!!g.comma,this.precision=g.precision===void 0?void 0:+g.precision,this.trim=!!g.trim,this.type=g.type===void 0?"":g.type+""}g7.prototype.toString=function(){return this.fill+this.align+this.sign+this.symbol+(this.zero?"0":"")+(this.width===void 0?"":Math.max(1,this.width|0))+(this.comma?",":"")+(this.precision===void 0?"":"."+Math.max(0,this.precision|0))+(this.trim?"~":"")+this.type};function I$e(g){e:for(var e=g.length,I=1,i=-1,n;I0&&(i=0);break}return i>0?g.slice(0,i)+g.slice(n+1):g}var c0e;function i$e(g,e){var I=l9(g,e);if(!I)return g+"";var i=I[0],n=I[1],C=n-(c0e=Math.max(-8,Math.min(8,Math.floor(n/3)))*3)+1,r=i.length;return C===r?i:C>r?i+new Array(C-r+1).join("0"):C>0?i.slice(0,C)+"."+i.slice(C):"0."+new Array(1-C).join("0")+l9(g,Math.max(0,e+C-1))[0]}function Lte(g,e){var I=l9(g,e);if(!I)return g+"";var i=I[0],n=I[1];return n<0?"0."+new Array(-n).join("0")+i:i.length>n+1?i.slice(0,n+1)+"."+i.slice(n+1):i+new Array(n-i.length+2).join("0")}const _te={"%":(g,e)=>(g*100).toFixed(e),b:g=>Math.round(g).toString(2),c:g=>g+"",d:q4e,e:(g,e)=>g.toExponential(e),f:(g,e)=>g.toFixed(e),g:(g,e)=>g.toPrecision(e),o:g=>Math.round(g).toString(8),p:(g,e)=>Lte(g*100,e),r:Lte,s:i$e,X:g=>Math.round(g).toString(16).toUpperCase(),x:g=>Math.round(g).toString(16)};function Ute(g){return g}var Qte=Array.prototype.map,jte=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"];function n$e(g){var e=g.grouping===void 0||g.thousands===void 0?Ute:e$e(Qte.call(g.grouping,Number),g.thousands+""),I=g.currency===void 0?"":g.currency[0]+"",i=g.currency===void 0?"":g.currency[1]+"",n=g.decimal===void 0?".":g.decimal+"",C=g.numerals===void 0?Ute:t$e(Qte.call(g.numerals,String)),r=g.percent===void 0?"%":g.percent+"",o=g.minus===void 0?"−":g.minus+"",A=g.nan===void 0?"NaN":g.nan+"";function s(l){l=h3(l);var c=l.fill,u=l.align,d=l.sign,h=l.symbol,m=l.zero,f=l.width,b=l.comma,p=l.precision,y=l.trim,Z=l.type;Z==="n"?(b=!0,Z="g"):_te[Z]||(p===void 0&&(p=12),y=!0,Z="g"),(m||c==="0"&&u==="=")&&(m=!0,c="0",u="=");var v=h==="$"?I:h==="#"&&/[boxX]/.test(Z)?"0"+Z.toLowerCase():"",G=h==="$"?i:/[%p]/.test(Z)?r:"",B=_te[Z],w=/[defgprs%]/.test(Z);p=p===void 0?6:/[gprs]/.test(Z)?Math.max(1,Math.min(21,p)):Math.max(0,Math.min(20,p));function R(S){var X=v,W=G,V,H,D;if(Z==="c")W=B(S)+W,S="";else{S=+S;var Y=S<0||1/S<0;if(S=isNaN(S)?A:B(Math.abs(S),p),y&&(S=I$e(S)),Y&&+S==0&&d!=="+"&&(Y=!1),X=(Y?d==="("?d:o:d==="-"||d==="("?"":d)+X,W=(Z==="s"?jte[8+c0e/3]:"")+W+(Y&&d==="("?")":""),w){for(V=-1,H=S.length;++VD||D>57){W=(D===46?n+S.slice(V+1):S.slice(V))+W,S=S.slice(0,V);break}}}b&&!m&&(S=e(S,1/0));var F=X.length+S.length+W.length,_=F>1)+X+S+W+_.slice(F);break;default:S=_+X+S+W;break}return C(S)}return R.toString=function(){return l+""},R}function a(l,c){var u=s((l=h3(l),l.type="f",l)),d=Math.max(-8,Math.min(8,Math.floor(d3(c)/3)))*3,h=Math.pow(10,-d),m=jte[8+d/3];return function(f){return u(h*f)+m}}return{format:s,formatPrefix:a}}var nR,u0e,d0e;C$e({thousands:",",grouping:[3],currency:["$",""]});function C$e(g){return nR=n$e(g),u0e=nR.format,d0e=nR.formatPrefix,nR}function r$e(g,e){return Math.max(0,Math.max(-8,Math.min(8,Math.floor(d3(e)/3)))*3-d3(Math.abs(g)))}const m3=Math.PI,f3=2*m3,Id=1e-6,o$e=f3-Id;function p3(){this._x0=this._y0=this._x1=this._y1=null,this._=""}function h0e(){return new p3}p3.prototype=h0e.prototype={constructor:p3,moveTo:function(g,e){this._+="M"+(this._x0=this._x1=+g)+","+(this._y0=this._y1=+e)},closePath:function(){this._x1!==null&&(this._x1=this._x0,this._y1=this._y0,this._+="Z")},lineTo:function(g,e){this._+="L"+(this._x1=+g)+","+(this._y1=+e)},quadraticCurveTo:function(g,e,I,i){this._+="Q"+ +g+","+ +e+","+(this._x1=+I)+","+(this._y1=+i)},bezierCurveTo:function(g,e,I,i,n,C){this._+="C"+ +g+","+ +e+","+ +I+","+ +i+","+(this._x1=+n)+","+(this._y1=+C)},arcTo:function(g,e,I,i,n){g=+g,e=+e,I=+I,i=+i,n=+n;var C=this._x1,r=this._y1,o=I-g,A=i-e,s=C-g,a=r-e,l=s*s+a*a;if(n<0)throw new Error("negative radius: "+n);if(this._x1===null)this._+="M"+(this._x1=g)+","+(this._y1=e);else if(l>Id)if(!(Math.abs(a*o-A*s)>Id)||!n)this._+="L"+(this._x1=g)+","+(this._y1=e);else{var c=I-C,u=i-r,d=o*o+A*A,h=c*c+u*u,m=Math.sqrt(d),f=Math.sqrt(l),b=n*Math.tan((m3-Math.acos((d+l-h)/(2*m*f)))/2),p=b/f,y=b/m;Math.abs(p-1)>Id&&(this._+="L"+(g+p*s)+","+(e+p*a)),this._+="A"+n+","+n+",0,0,"+ +(a*c>s*u)+","+(this._x1=g+y*o)+","+(this._y1=e+y*A)}},arc:function(g,e,I,i,n,C){g=+g,e=+e,I=+I,C=!!C;var r=I*Math.cos(i),o=I*Math.sin(i),A=g+r,s=e+o,a=1^C,l=C?i-n:n-i;if(I<0)throw new Error("negative radius: "+I);this._x1===null?this._+="M"+A+","+s:(Math.abs(this._x1-A)>Id||Math.abs(this._y1-s)>Id)&&(this._+="L"+A+","+s),I&&(l<0&&(l=l%f3+f3),l>o$e?this._+="A"+I+","+I+",0,1,"+a+","+(g-r)+","+(e-o)+"A"+I+","+I+",0,1,"+a+","+(this._x1=A)+","+(this._y1=s):l>Id&&(this._+="A"+I+","+I+",0,"+ +(l>=m3)+","+a+","+(this._x1=g+I*Math.cos(n))+","+(this._y1=e+I*Math.sin(n))))},rect:function(g,e,I,i){this._+="M"+(this._x0=this._x1=+g)+","+(this._y0=this._y1=+e)+"h"+ +I+"v"+ +i+"h"+-I+"Z"},toString:function(){return this._}};function Rl(g){return function(){return g}}var $te=Math.abs,pn=Math.atan2,Ku=Math.cos,A$e=Math.max,T5=Math.min,RA=Math.sin,hp=Math.sqrt,yC=1e-12,Hv=Math.PI,c9=Hv/2,a$e=2*Hv;function s$e(g){return g>1?0:g<-1?Hv:Math.acos(g)}function qte(g){return g>=1?c9:g<=-1?-c9:Math.asin(g)}function l$e(g){return g.innerRadius}function c$e(g){return g.outerRadius}function u$e(g){return g.startAngle}function d$e(g){return g.endAngle}function h$e(g){return g&&g.padAngle}function m$e(g,e,I,i,n,C,r,o){var A=I-g,s=i-e,a=r-n,l=o-C,c=l*A-a*s;if(!(c*cV*V+H*H&&(B=R,w=S),{cx:B,cy:w,x01:-a,y01:-l,x11:B*(n/Z-1),y11:w*(n/Z-1)}}function f$e(){var g=l$e,e=c$e,I=Rl(0),i=null,n=u$e,C=d$e,r=h$e,o=null;function A(){var s,a,l=+g.apply(this,arguments),c=+e.apply(this,arguments),u=n.apply(this,arguments)-c9,d=C.apply(this,arguments)-c9,h=$te(d-u),m=d>u;if(o||(o=s=h0e()),cyC))o.moveTo(0,0);else if(h>a$e-yC)o.moveTo(c*Ku(u),c*RA(u)),o.arc(0,0,c,u,d,!m),l>yC&&(o.moveTo(l*Ku(d),l*RA(d)),o.arc(0,0,l,d,u,m));else{var f=u,b=d,p=u,y=d,Z=h,v=h,G=r.apply(this,arguments)/2,B=G>yC&&(i?+i.apply(this,arguments):hp(l*l+c*c)),w=T5($te(c-l)/2,+I.apply(this,arguments)),R=w,S=w,X,W;if(B>yC){var V=qte(B/l*RA(G)),H=qte(B/c*RA(G));(Z-=V*2)>yC?(V*=m?1:-1,p+=V,y-=V):(Z=0,p=y=(u+d)/2),(v-=H*2)>yC?(H*=m?1:-1,f+=H,b-=H):(v=0,f=b=(u+d)/2)}var D=c*Ku(f),Y=c*RA(f),F=l*Ku(y),_=l*RA(y);if(w>yC){var J=c*Ku(b),te=c*RA(b),q=l*Ku(p),$=l*RA(p),j;if(hyC?S>yC?(X=CR(q,$,D,Y,c,S,m),W=CR(J,te,F,_,c,S,m),o.moveTo(X.cx+X.x01,X.cy+X.y01),SyC)||!(Z>yC)?o.lineTo(F,_):R>yC?(X=CR(F,_,J,te,l,-R,m),W=CR(D,Y,q,$,l,-R,m),o.lineTo(X.cx+X.x01,X.cy+X.y01),R({events:{},emit(g,...e){let I=this.events[g]||[];for(let i=0,n=I.length;i{var i;this.events[g]=(i=this.events[g])==null?void 0:i.filter(n=>e!==n)}}});var m0e={},Io={},Ah={};Object.defineProperty(Ah,"__esModule",{value:!0});Ah.DefaultSerializer=Ah.extendSerializer=void 0;function b$e(g,e){const I=g.deserialize.bind(g),i=g.serialize.bind(g);return{deserialize(n){return e.deserialize(n,I)},serialize(n){return e.serialize(n,i)}}}Ah.extendSerializer=b$e;const ege={deserialize(g){return Object.assign(Error(g.message),{name:g.name,stack:g.stack})},serialize(g){return{__error_marker:"$$error",message:g.message,name:g.name,stack:g.stack}}},y$e=g=>g&&typeof g=="object"&&"__error_marker"in g&&g.__error_marker==="$$error";Ah.DefaultSerializer={deserialize(g){return y$e(g)?ege.deserialize(g):g},serialize(g){return g instanceof Error?ege.serialize(g):g}};Object.defineProperty(Io,"__esModule",{value:!0});Io.serialize=Io.deserialize=Io.registerSerializer=void 0;const f0e=Ah;let u9=f0e.DefaultSerializer;function Z$e(g){u9=f0e.extendSerializer(u9,g)}Io.registerSerializer=Z$e;function G$e(g){return u9.deserialize(g)}Io.deserialize=G$e;function B$e(g){return u9.serialize(g)}Io.serialize=B$e;var p0e={},Hs={},Xb={};Object.defineProperty(Xb,"__esModule",{value:!0});Xb.getBundleURL=Xb.getBaseURL=void 0;let N5;function v$e(){return N5||(N5=S$e()),N5}Xb.getBundleURL=v$e;function S$e(){try{throw new Error}catch(g){const e=(""+g.stack).match(/(https?|file|ftp|chrome-extension|moz-extension):\/\/[^)\n]+/g);if(e)return b0e(e[0])}return"/"}function b0e(g){return(""+g).replace(/^((?:https?|file|ftp|chrome-extension|moz-extension):\/\/.+)?\/[^/]+(?:\?.*)?$/,"$1")+"/"}Xb.getBaseURL=b0e;Object.defineProperty(Hs,"__esModule",{value:!0});Hs.isWorkerRuntime=Hs.getWorkerImplementation=Hs.defaultPoolSize=void 0;const tge=Xb;Hs.defaultPoolSize=typeof navigator<"u"&&navigator.hardwareConcurrency?navigator.hardwareConcurrency:4;const gge=g=>/^[a-zA-Z][a-zA-Z\d+\-.]*:/.test(g);function Ige(g){const e=new Blob([g],{type:"application/javascript"});return URL.createObjectURL(e)}function w$e(){if(typeof Worker>"u")return class{constructor(){throw Error("No web worker implementation available. You might have tried to spawn a worker within a worker in a browser that doesn't support workers in workers.")}};class g extends Worker{constructor(i,n){var C,r;typeof i=="string"&&n&&n._baseURL?i=new URL(i,n._baseURL):typeof i=="string"&&!gge(i)&&tge.getBundleURL().match(/^file:\/\//i)&&(i=new URL(i,tge.getBundleURL().replace(/\/[^\/]+$/,"/")),(!((C=n==null?void 0:n.CORSWorkaround)!==null&&C!==void 0)||C)&&(i=Ige(`importScripts(${JSON.stringify(i)});`))),typeof i=="string"&&gge(i)&&(!((r=n==null?void 0:n.CORSWorkaround)!==null&&r!==void 0)||r)&&(i=Ige(`importScripts(${JSON.stringify(i)});`)),super(i,n)}}class e extends g{constructor(i,n){const C=window.URL.createObjectURL(i);super(C,n)}static fromText(i,n){const C=new window.Blob([i],{type:"text/javascript"});return new e(C,n)}}return{blob:e,default:g}}let k5;function V$e(){return k5||(k5=w$e()),k5}Hs.getWorkerImplementation=V$e;function R$e(){const g=typeof self<"u"&&typeof Window<"u"&&self instanceof Window;return!!(typeof self<"u"&&self.postMessage&&!g)}Hs.isWorkerRuntime=R$e;var y0e={},b3={exports:{}},Y5,ige;function W$e(){if(ige)return Y5;ige=1;var g=1e3,e=g*60,I=e*60,i=I*24,n=i*7,C=i*365.25;Y5=function(a,l){l=l||{};var c=typeof a;if(c==="string"&&a.length>0)return r(a);if(c==="number"&&isFinite(a))return l.long?A(a):o(a);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(a))};function r(a){if(a=String(a),!(a.length>100)){var l=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(a);if(l){var c=parseFloat(l[1]),u=(l[2]||"ms").toLowerCase();switch(u){case"years":case"year":case"yrs":case"yr":case"y":return c*C;case"weeks":case"week":case"w":return c*n;case"days":case"day":case"d":return c*i;case"hours":case"hour":case"hrs":case"hr":case"h":return c*I;case"minutes":case"minute":case"mins":case"min":case"m":return c*e;case"seconds":case"second":case"secs":case"sec":case"s":return c*g;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return c;default:return}}}}function o(a){var l=Math.abs(a);return l>=i?Math.round(a/i)+"d":l>=I?Math.round(a/I)+"h":l>=e?Math.round(a/e)+"m":l>=g?Math.round(a/g)+"s":a+"ms"}function A(a){var l=Math.abs(a);return l>=i?s(a,l,i,"day"):l>=I?s(a,l,I,"hour"):l>=e?s(a,l,e,"minute"):l>=g?s(a,l,g,"second"):a+" ms"}function s(a,l,c,u){var d=l>=c*1.5;return Math.round(a/c)+" "+u+(d?"s":"")}return Y5}function X$e(g){I.debug=I,I.default=I,I.coerce=A,I.disable=C,I.enable=n,I.enabled=r,I.humanize=W$e(),I.destroy=s,Object.keys(g).forEach(a=>{I[a]=g[a]}),I.names=[],I.skips=[],I.formatters={};function e(a){let l=0;for(let c=0;c{if(v==="%%")return"%";y++;const B=I.formatters[G];if(typeof B=="function"){const w=m[y];v=B.call(f,w),m.splice(y,1),y--}return v}),I.formatArgs.call(f,m),(f.log||I.log).apply(f,m)}return h.namespace=a,h.useColors=I.useColors(),h.color=I.selectColor(a),h.extend=i,h.destroy=I.destroy,Object.defineProperty(h,"enabled",{enumerable:!0,configurable:!1,get:()=>c!==null?c:(u!==I.namespaces&&(u=I.namespaces,d=I.enabled(a)),d),set:m=>{c=m}}),typeof I.init=="function"&&I.init(h),h}function i(a,l){const c=I(this.namespace+(typeof l>"u"?":":l)+a);return c.log=this.log,c}function n(a){I.save(a),I.namespaces=a,I.names=[],I.skips=[];let l;const c=(typeof a=="string"?a:"").split(/[\s,]+/),u=c.length;for(l=0;l"-"+l)].join(",");return I.enable(""),a}function r(a){if(a[a.length-1]==="*")return!0;let l,c;for(l=0,c=I.skips.length;l{let A=!1;return()=>{A||(A=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),e.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function I(){return typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs)?!0:typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)?!1:typeof document<"u"&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function i(A){if(A[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+A[0]+(this.useColors?"%c ":" ")+"+"+g.exports.humanize(this.diff),!this.useColors)return;const s="color: "+this.color;A.splice(1,0,s,"color: inherit");let a=0,l=0;A[0].replace(/%[a-zA-Z%]/g,c=>{c!=="%%"&&(a++,c==="%c"&&(l=a))}),A.splice(l,0,s)}e.log=console.debug||console.log||(()=>{});function n(A){try{A?e.storage.setItem("debug",A):e.storage.removeItem("debug")}catch{}}function C(){let A;try{A=e.storage.getItem("debug")}catch{}return!A&&typeof process<"u"&&"env"in process&&(A={}.DEBUG),A}function r(){try{return localStorage}catch{}}g.exports=H$e(e);const{formatters:o}=g.exports;o.j=function(A){try{return JSON.stringify(A)}catch(s){return"[UnexpectedJSONParseError]: "+s.message}}})(b3,b3.exports);var I7=b3.exports,T$e=globalThis&&globalThis.__awaiter||function(g,e,I,i){function n(C){return C instanceof I?C:new I(function(r){r(C)})}return new(I||(I=Promise))(function(C,r){function o(a){try{s(i.next(a))}catch(l){r(l)}}function A(a){try{s(i.throw(a))}catch(l){r(l)}}function s(a){a.done?C(a.value):n(a.value).then(o,A)}s((i=i.apply(g,e||[])).next())})};class AN{constructor(e){this._baseObserver=e,this._pendingPromises=new Set}complete(){Promise.all(this._pendingPromises).then(()=>this._baseObserver.complete()).catch(e=>this._baseObserver.error(e))}error(e){this._baseObserver.error(e)}schedule(e){const I=Promise.all(this._pendingPromises),i=[],n=r=>i.push(r),C=Promise.resolve().then(()=>T$e(this,void 0,void 0,function*(){yield I,yield e(n),this._pendingPromises.delete(C);for(const r of i)this._baseObserver.next(r)})).catch(r=>{this._pendingPromises.delete(C),this._baseObserver.error(r)});this._pendingPromises.add(C)}}const Z0e=()=>typeof Symbol=="function",OS=g=>Z0e()&&!!Symbol[g],i7=g=>OS(g)?Symbol[g]:"@@"+g;OS("asyncIterator")||(Symbol.asyncIterator=Symbol.asyncIterator||Symbol.for("Symbol.asyncIterator"));const N$e=i7("iterator"),y3=i7("observable"),G0e=i7("species");function d9(g,e){const I=g[e];if(I!=null){if(typeof I!="function")throw new TypeError(I+" is not a function");return I}}function _y(g){let e=g.constructor;return e!==void 0&&(e=e[G0e],e===null&&(e=void 0)),e!==void 0?e:ah}function k$e(g){return g instanceof ah}function Hb(g){Hb.log?Hb.log(g):setTimeout(()=>{throw g},0)}function U1(g){Promise.resolve().then(()=>{try{g()}catch(e){Hb(e)}})}function B0e(g){const e=g._cleanup;if(e!==void 0&&(g._cleanup=void 0,!!e))try{if(typeof e=="function")e();else{const I=d9(e,"unsubscribe");I&&I.call(e)}}catch(I){Hb(I)}}function Z3(g){g._observer=void 0,g._queue=void 0,g._state="closed"}function Y$e(g){const e=g._queue;if(e){g._queue=void 0,g._state="ready";for(const I of e)if(v0e(g,I.type,I.value),g._state==="closed")break}}function v0e(g,e,I){g._state="running";const i=g._observer;try{const n=i?d9(i,e):void 0;switch(e){case"next":n&&n.call(i,I);break;case"error":if(Z3(g),n)n.call(i,I);else throw I;break;case"complete":Z3(g),n&&n.call(i);break}}catch(n){Hb(n)}g._state==="closed"?B0e(g):g._state==="running"&&(g._state="ready")}function K5(g,e,I){if(g._state!=="closed"){if(g._state==="buffering"){g._queue=g._queue||[],g._queue.push({type:e,value:I});return}if(g._state!=="ready"){g._state="buffering",g._queue=[{type:e,value:I}],U1(()=>Y$e(g));return}v0e(g,e,I)}}let K$e=class{constructor(e,I){this._cleanup=void 0,this._observer=e,this._queue=void 0,this._state="initializing";const i=new x$e(this);try{this._cleanup=I.call(void 0,i)}catch(n){i.error(n)}this._state==="initializing"&&(this._state="ready")}get closed(){return this._state==="closed"}unsubscribe(){this._state!=="closed"&&(Z3(this),B0e(this))}};class x$e{constructor(e){this._subscription=e}get closed(){return this._subscription._state==="closed"}next(e){K5(this._subscription,"next",e)}error(e){K5(this._subscription,"error",e)}complete(){K5(this._subscription,"complete")}}let ah=class _Z{constructor(e){if(!(this instanceof _Z))throw new TypeError("Observable cannot be called as a function");if(typeof e!="function")throw new TypeError("Observable initializer must be a function");this._subscriber=e}subscribe(e,I,i){return(typeof e!="object"||e===null)&&(e={next:e,error:I,complete:i}),new K$e(e,this._subscriber)}pipe(e,...I){let i=this;for(const n of[e,...I])i=n(i);return i}tap(e,I,i){const n=typeof e!="object"||e===null?{next:e,error:I,complete:i}:e;return new _Z(C=>this.subscribe({next(r){n.next&&n.next(r),C.next(r)},error(r){n.error&&n.error(r),C.error(r)},complete(){n.complete&&n.complete(),C.complete()},start(r){n.start&&n.start(r)}}))}forEach(e){return new Promise((I,i)=>{if(typeof e!="function"){i(new TypeError(e+" is not a function"));return}function n(){C.unsubscribe(),I(void 0)}const C=this.subscribe({next(r){try{e(r,n)}catch(o){i(o),C.unsubscribe()}},error(r){i(r)},complete(){I(void 0)}})})}map(e){if(typeof e!="function")throw new TypeError(e+" is not a function");const I=_y(this);return new I(i=>this.subscribe({next(n){let C=n;try{C=e(n)}catch(r){return i.error(r)}i.next(C)},error(n){i.error(n)},complete(){i.complete()}}))}filter(e){if(typeof e!="function")throw new TypeError(e+" is not a function");const I=_y(this);return new I(i=>this.subscribe({next(n){try{if(!e(n))return}catch(C){return i.error(C)}i.next(n)},error(n){i.error(n)},complete(){i.complete()}}))}reduce(e,I){if(typeof e!="function")throw new TypeError(e+" is not a function");const i=_y(this),n=arguments.length>1;let C=!1,r=I;return new i(o=>this.subscribe({next(A){const s=!C;if(C=!0,!s||n)try{r=e(r,A)}catch(a){return o.error(a)}else r=A},error(A){o.error(A)},complete(){if(!C&&!n)return o.error(new TypeError("Cannot reduce an empty sequence"));o.next(r),o.complete()}}))}concat(...e){const I=_y(this);return new I(i=>{let n,C=0;function r(o){n=o.subscribe({next(A){i.next(A)},error(A){i.error(A)},complete(){C===e.length?(n=void 0,i.complete()):r(I.from(e[C++]))}})}return r(this),()=>{n&&(n.unsubscribe(),n=void 0)}})}flatMap(e){if(typeof e!="function")throw new TypeError(e+" is not a function");const I=_y(this);return new I(i=>{const n=[],C=this.subscribe({next(o){let A;if(e)try{A=e(o)}catch(a){return i.error(a)}else A=o;const s=I.from(A).subscribe({next(a){i.next(a)},error(a){i.error(a)},complete(){const a=n.indexOf(s);a>=0&&n.splice(a,1),r()}});n.push(s)},error(o){i.error(o)},complete(){r()}});function r(){C.closed&&n.length===0&&i.complete()}return()=>{n.forEach(o=>o.unsubscribe()),C.unsubscribe()}})}[y3](){return this}static from(e){const I=typeof this=="function"?this:_Z;if(e==null)throw new TypeError(e+" is not an object");const i=d9(e,y3);if(i){const n=i.call(e);if(Object(n)!==n)throw new TypeError(n+" is not an object");return k$e(n)&&n.constructor===I?n:new I(C=>n.subscribe(C))}if(OS("iterator")){const n=d9(e,N$e);if(n)return new I(C=>{U1(()=>{if(!C.closed){for(const r of n.call(e))if(C.next(r),C.closed)return;C.complete()}})})}if(Array.isArray(e))return new I(n=>{U1(()=>{if(!n.closed){for(const C of e)if(n.next(C),n.closed)return;n.complete()}})});throw new TypeError(e+" is not observable")}static of(...e){const I=typeof this=="function"?this:_Z;return new I(i=>{U1(()=>{if(!i.closed){for(const n of e)if(i.next(n),i.closed)return;i.complete()}})})}static get[G0e](){return this}};Z0e()&&Object.defineProperty(ah,Symbol("extensions"),{value:{symbol:y3,hostReportError:Hb},configurable:!0});const im=ah;function nm(g){typeof g=="function"?g():g&&typeof g.unsubscribe=="function"&&g.unsubscribe()}var D$e=globalThis&&globalThis.__awaiter||function(g,e,I,i){function n(C){return C instanceof I?C:new I(function(r){r(C)})}return new(I||(I=Promise))(function(C,r){function o(a){try{s(i.next(a))}catch(l){r(l)}}function A(a){try{s(i.throw(a))}catch(l){r(l)}}function s(a){a.done?C(a.value):n(a.value).then(o,A)}s((i=i.apply(g,e||[])).next())})};function F$e(g){return e=>new im(I=>{const i=new AN(I),n=e.subscribe({complete(){i.complete()},error(C){i.error(C)},next(C){i.schedule(r=>D$e(this,void 0,void 0,function*(){(yield g(C))&&r(C)}))}});return()=>nm(n)})}function E$e(g){return g&&OS("asyncIterator")&&g[Symbol.asyncIterator]}function M$e(g){return g&&OS("iterator")&&g[Symbol.iterator]}var z$e=globalThis&&globalThis.__awaiter||function(g,e,I,i){function n(C){return C instanceof I?C:new I(function(r){r(C)})}return new(I||(I=Promise))(function(C,r){function o(a){try{s(i.next(a))}catch(l){r(l)}}function A(a){try{s(i.throw(a))}catch(l){r(l)}}function s(a){a.done?C(a.value):n(a.value).then(o,A)}s((i=i.apply(g,e||[])).next())})},P$e=globalThis&&globalThis.__asyncValues||function(g){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e=g[Symbol.asyncIterator],I;return e?e.call(g):(g=typeof __values=="function"?__values(g):g[Symbol.iterator](),I={},i("next"),i("throw"),i("return"),I[Symbol.asyncIterator]=function(){return this},I);function i(C){I[C]=g[C]&&function(r){return new Promise(function(o,A){r=g[C](r),n(o,A,r.done,r.value)})}}function n(C,r,o,A){Promise.resolve(A).then(function(s){C({value:s,done:o})},r)}};function J$e(g){return e=>new im(I=>{const i=new AN(I),n=e.subscribe({complete(){i.complete()},error(C){i.error(C)},next(C){i.schedule(r=>z$e(this,void 0,void 0,function*(){var o,A;const s=yield g(C);if(M$e(s)||E$e(s))try{for(var a=P$e(s),l;l=yield a.next(),!l.done;){const c=l.value;r(c)}}catch(c){o={error:c}}finally{try{l&&!l.done&&(A=a.return)&&(yield A.call(a))}finally{if(o)throw o.error}}else s.map(c=>r(c))}))}});return()=>nm(n)})}function O$e(g){return new ah(e=>{let I=0;const i=setInterval(()=>{e.next(I++)},g);return()=>clearInterval(i)})}var L$e=globalThis&&globalThis.__awaiter||function(g,e,I,i){function n(C){return C instanceof I?C:new I(function(r){r(C)})}return new(I||(I=Promise))(function(C,r){function o(a){try{s(i.next(a))}catch(l){r(l)}}function A(a){try{s(i.throw(a))}catch(l){r(l)}}function s(a){a.done?C(a.value):n(a.value).then(o,A)}s((i=i.apply(g,e||[])).next())})};function _$e(g){return e=>new im(I=>{const i=new AN(I),n=e.subscribe({complete(){i.complete()},error(C){i.error(C)},next(C){i.schedule(r=>L$e(this,void 0,void 0,function*(){const o=yield g(C);r(o)}))}});return()=>nm(n)})}function U$e(...g){return g.length===0?ah.from([]):new ah(e=>{let I=0;const i=g.map(C=>C.subscribe({error(r){e.error(r),n()},next(r){e.next(r)},complete(){++I===g.length&&(e.complete(),n())}})),n=()=>{i.forEach(C=>nm(C))};return n})}class Q$e extends im{constructor(){super(e=>(this._observers.add(e),()=>this._observers.delete(e))),this._observers=new Set}next(e){for(const I of this._observers)I.next(e)}error(e){for(const I of this._observers)I.error(e)}complete(){for(const e of this._observers)e.complete()}}const S0e=Q$e;function j$e(g){const e=new S0e;let I,i=0;return new im(n=>{I||(I=g.subscribe(e));const C=e.subscribe(n);return i++,()=>{i--,C.unsubscribe(),i===0&&(nm(I),I=void 0)}})}var $$e=globalThis&&globalThis.__awaiter||function(g,e,I,i){function n(C){return C instanceof I?C:new I(function(r){r(C)})}return new(I||(I=Promise))(function(C,r){function o(a){try{s(i.next(a))}catch(l){r(l)}}function A(a){try{s(i.throw(a))}catch(l){r(l)}}function s(a){a.done?C(a.value):n(a.value).then(o,A)}s((i=i.apply(g,e||[])).next())})};function q$e(g,e){return I=>new im(i=>{let n,C=0;const r=new AN(i),o=I.subscribe({complete(){r.complete()},error(A){r.error(A)},next(A){r.schedule(s=>$$e(this,void 0,void 0,function*(){n=yield g(C===0?typeof e>"u"?A:e:n,A,C++),s(n)}))}});return()=>nm(o)})}const e8e=Object.freeze(Object.defineProperty({__proto__:null,Observable:im,Subject:S0e,filter:F$e,flatMap:J$e,interval:O$e,map:_$e,merge:U$e,multicast:j$e,scan:q$e,unsubscribe:nm},Symbol.toStringTag,{value:"Module"})),aN=TL(e8e);var sN={};Object.defineProperty(sN,"__esModule",{value:!0});sN.allSettled=void 0;function t8e(g){return Promise.all(g.map(e=>{const I=C=>({status:"fulfilled",value:C}),i=C=>({status:"rejected",reason:C}),n=Promise.resolve(e);try{return n.then(I,i)}catch(C){return Promise.reject(C)}}))}sN.allSettled=t8e;var w0e={};(function(g){Object.defineProperty(g,"__esModule",{value:!0}),g.PoolEventType=void 0,function(e){e.initialized="initialized",e.taskCanceled="taskCanceled",e.taskCompleted="taskCompleted",e.taskFailed="taskFailed",e.taskQueued="taskQueued",e.taskQueueDrained="taskQueueDrained",e.taskStart="taskStart",e.terminated="terminated"}(g.PoolEventType||(g.PoolEventType={}))})(w0e);var LS={},XC={};Object.defineProperty(XC,"__esModule",{value:!0});XC.$worker=XC.$transferable=XC.$terminate=XC.$events=XC.$errors=void 0;XC.$errors=Symbol("thread.errors");XC.$events=Symbol("thread.events");XC.$terminate=Symbol("thread.terminate");XC.$transferable=Symbol("thread.transferable");XC.$worker=Symbol("thread.worker");Object.defineProperty(LS,"__esModule",{value:!0});LS.Thread=void 0;const x5=XC;function nge(g){throw Error(g)}LS.Thread={errors(g){return g[x5.$errors]||nge("Error observable not found. Make sure to pass a thread instance as returned by the spawn() promise.")},events(g){return g[x5.$events]||nge("Events observable not found. Make sure to pass a thread instance as returned by the spawn() promise.")},terminate(g){return g[x5.$terminate]()}};(function(g){var e=ZI&&ZI.__awaiter||function(f,b,p,y){function Z(v){return v instanceof p?v:new p(function(G){G(v)})}return new(p||(p=Promise))(function(v,G){function B(S){try{R(y.next(S))}catch(X){G(X)}}function w(S){try{R(y.throw(S))}catch(X){G(X)}}function R(S){S.done?v(S.value):Z(S.value).then(B,w)}R((y=y.apply(f,b||[])).next())})},I=ZI&&ZI.__importDefault||function(f){return f&&f.__esModule?f:{default:f}};Object.defineProperty(g,"__esModule",{value:!0}),g.Pool=g.Thread=g.PoolEventType=void 0;const i=I(I7),n=aN,C=sN,r=Hs,o=w0e;Object.defineProperty(g,"PoolEventType",{enumerable:!0,get:function(){return o.PoolEventType}});const A=LS;Object.defineProperty(g,"Thread",{enumerable:!0,get:function(){return A.Thread}});let s=1;function a(f){const b=[];for(let p=0;psetTimeout(b,f))}function c(f,b){return f.reduce((p,y)=>[...p,...b(y)],[])}function u(f){return f.replace(/\W/g," ").trim().replace(/\s+/g,"-")}function d(f,b){return a(b).map(()=>({init:f(),runningTasks:[]}))}class h{constructor(b,p){this.eventSubject=new n.Subject,this.initErrors=[],this.isClosing=!1,this.nextTaskID=1,this.taskQueue=[];const y=typeof p=="number"?{size:p}:p||{},{size:Z=r.defaultPoolSize}=y;this.debug=i.default(`threads:pool:${u(y.name||String(s++))}`),this.options=y,this.workers=d(b,Z),this.eventObservable=n.multicast(n.Observable.from(this.eventSubject)),Promise.all(this.workers.map(v=>v.init)).then(()=>this.eventSubject.next({type:o.PoolEventType.initialized,size:this.workers.length}),v=>{this.debug("Error while initializing pool worker:",v),this.eventSubject.error(v),this.initErrors.push(v)})}findIdlingWorker(){const{concurrency:b=1}=this.options;return this.workers.find(p=>p.runningTasks.lengthe(this,void 0,void 0,function*(){const Z=()=>{b.runningTasks=b.runningTasks.filter(v=>v!==y)};yield l(0);try{yield this.runPoolTask(b,p)}finally{Z(),this.isClosing||this.scheduleWork()}}))();b.runningTasks.push(y)})}scheduleWork(){this.debug("Attempt de-queueing a task in order to run it...");const b=this.findIdlingWorker();if(!b)return;const p=this.taskQueue.shift();if(!p){this.debug("Task queue is empty"),this.eventSubject.next({type:o.PoolEventType.taskQueueDrained});return}this.run(b,p)}taskCompletion(b){return new Promise((p,y)=>{const Z=this.events().subscribe(v=>{v.type===o.PoolEventType.taskCompleted&&v.taskID===b?(Z.unsubscribe(),p(v.returnValue)):v.type===o.PoolEventType.taskFailed&&v.taskID===b?(Z.unsubscribe(),y(v.error)):v.type===o.PoolEventType.terminated&&(Z.unsubscribe(),y(Error("Pool has been terminated before task was run.")))})})}settled(b=!1){return e(this,void 0,void 0,function*(){const p=()=>c(this.workers,v=>v.runningTasks),y=[],Z=this.eventObservable.subscribe(v=>{v.type===o.PoolEventType.taskFailed&&y.push(v.error)});return this.initErrors.length>0?Promise.reject(this.initErrors[0]):b&&this.taskQueue.length===0?(yield C.allSettled(p()),y):(yield new Promise((v,G)=>{const B=this.eventObservable.subscribe({next(w){w.type===o.PoolEventType.taskQueueDrained&&(B.unsubscribe(),v(void 0))},error:G})}),yield C.allSettled(p()),Z.unsubscribe(),y)})}completed(b=!1){return e(this,void 0,void 0,function*(){const p=this.settled(b),y=new Promise((v,G)=>{const B=this.eventObservable.subscribe({next(w){w.type===o.PoolEventType.taskQueueDrained?(B.unsubscribe(),v(p)):w.type===o.PoolEventType.taskFailed&&(B.unsubscribe(),G(w.error))},error:G})}),Z=yield Promise.race([p,y]);if(Z.length>0)throw Z[0]})}events(){return this.eventObservable}queue(b){const{maxQueuedJobs:p=1/0}=this.options;if(this.isClosing)throw Error("Cannot schedule pool tasks after terminate() has been called.");if(this.initErrors.length>0)throw this.initErrors[0];const y=this.nextTaskID++,Z=this.taskCompletion(y);Z.catch(G=>{this.debug(`Task #${y} errored:`,G)});const v={id:y,run:b,cancel:()=>{this.taskQueue.indexOf(v)!==-1&&(this.taskQueue=this.taskQueue.filter(G=>G!==v),this.eventSubject.next({type:o.PoolEventType.taskCanceled,taskID:v.id}))},then:Z.then.bind(Z)};if(this.taskQueue.length>=p)throw Error(`Maximum number of pool tasks queued. Refusing to queue another one. -This usually happens for one of two reasons: We are either at peak workload right now or some tasks just won't finish, thus blocking the pool.`);return this.debug(`Queueing task #${v.id}...`),this.taskQueue.push(v),this.eventSubject.next({type:o.PoolEventType.taskQueued,taskID:v.id}),this.scheduleWork(),v}terminate(b){return e(this,void 0,void 0,function*(){this.isClosing=!0,b||(yield this.completed(!0)),this.eventSubject.next({type:o.PoolEventType.terminated,remainingQueue:[...this.taskQueue]}),this.eventSubject.complete(),yield Promise.all(this.workers.map(p=>e(this,void 0,void 0,function*(){return A.Thread.terminate(yield p.init)})))})}}h.EventType=o.PoolEventType;function m(f,b){return new h(f,b)}m.EventType=o.PoolEventType,g.Pool=m})(y0e);var lN={},cN={};Object.defineProperty(cN,"__esModule",{value:!0});cN.createPromiseWithResolver=void 0;const g8e=()=>{};function I8e(){let g=!1,e,I=g8e;return[new Promise(C=>{g?C(e):I=C}),C=>{g=!0,e=C,I(e)}]}cN.createPromiseWithResolver=I8e;var V0e={};(function(g){Object.defineProperty(g,"__esModule",{value:!0}),g.WorkerEventType=void 0,function(e){e.internalError="internalError",e.message="message",e.termination="termination"}(g.WorkerEventType||(g.WorkerEventType={}))})(V0e);var Tb={},uN={};Object.defineProperty(uN,"__esModule",{value:!0});uN.ObservablePromise=void 0;const i8e=aN,n8e=()=>{},C8e=g=>g,Cge=g=>Promise.resolve().then(g);function r8e(g){throw g}function o8e(g){return g&&typeof g.then=="function"}class n7 extends i8e.Observable{constructor(e){super(I=>{const i=this,n=Object.assign(Object.assign({},I),{complete(){I.complete(),i.onCompletion()},error(C){I.error(C),i.onError(C)},next(C){I.next(C),i.onNext(C)}});try{return this.initHasRun=!0,e(n)}catch(C){n.error(C)}}),this.initHasRun=!1,this.fulfillmentCallbacks=[],this.rejectionCallbacks=[],this.firstValueSet=!1,this.state="pending"}onNext(e){this.firstValueSet||(this.firstValue=e,this.firstValueSet=!0)}onError(e){this.state="rejected",this.rejection=e;for(const I of this.rejectionCallbacks)Cge(()=>I(e))}onCompletion(){this.state="fulfilled";for(const e of this.fulfillmentCallbacks)Cge(()=>e(this.firstValue))}then(e,I){const i=e||C8e,n=I||r8e;let C=!1;return new Promise((r,o)=>{const A=a=>{if(!C){C=!0;try{r(n(a))}catch(l){o(l)}}},s=a=>{try{r(i(a))}catch(l){A(l)}};if(this.initHasRun||this.subscribe({error:A}),this.state==="fulfilled")return r(i(this.firstValue));if(this.state==="rejected")return C=!0,r(n(this.rejection));this.fulfillmentCallbacks.push(s),this.rejectionCallbacks.push(A)})}catch(e){return this.then(void 0,e)}finally(e){const I=e||n8e;return this.then(i=>(I(),i),()=>I())}static from(e){return o8e(e)?new n7(I=>{const i=C=>{I.next(C),I.complete()},n=C=>{I.error(C)};e.then(i,n)}):super.from(e)}}uN.ObservablePromise=n7;var Ls={};Object.defineProperty(Ls,"__esModule",{value:!0});Ls.Transfer=Ls.isTransferDescriptor=void 0;const R0e=XC;function A8e(g){return!(!g||typeof g!="object")}function a8e(g){return g&&typeof g=="object"&&g[R0e.$transferable]}Ls.isTransferDescriptor=a8e;function s8e(g,e){if(!e){if(!A8e(g))throw Error();e=[g]}return{[R0e.$transferable]:!0,send:g,transferables:e}}Ls.Transfer=s8e;var C7={};(function(g){Object.defineProperty(g,"__esModule",{value:!0}),g.WorkerMessageType=g.MasterMessageType=void 0,function(e){e.cancel="cancel",e.run="run"}(g.MasterMessageType||(g.MasterMessageType={})),function(e){e.error="error",e.init="init",e.result="result",e.running="running",e.uncaughtError="uncaughtError"}(g.WorkerMessageType||(g.WorkerMessageType={}))})(C7);var l8e=ZI&&ZI.__importDefault||function(g){return g&&g.__esModule?g:{default:g}};Object.defineProperty(Tb,"__esModule",{value:!0});Tb.createProxyModule=Tb.createProxyFunction=void 0;const c8e=l8e(I7),W0e=aN,qG=Io,rge=uN,u8e=Ls,_S=C7,X0e=c8e.default("threads:master:messages");let d8e=1;const h8e=g=>Array.from(new Set(g)),m8e=g=>g&&g.type===_S.WorkerMessageType.error,f8e=g=>g&&g.type===_S.WorkerMessageType.result,p8e=g=>g&&g.type===_S.WorkerMessageType.running;function b8e(g,e){return new W0e.Observable(I=>{let i;const n=C=>{if(X0e("Message from worker:",C.data),!(!C.data||C.data.uid!==e)){if(p8e(C.data))i=C.data.resultType;else if(f8e(C.data))i==="promise"?(typeof C.data.payload<"u"&&I.next(qG.deserialize(C.data.payload)),I.complete(),g.removeEventListener("message",n)):(C.data.payload&&I.next(qG.deserialize(C.data.payload)),C.data.complete&&(I.complete(),g.removeEventListener("message",n)));else if(m8e(C.data)){const r=qG.deserialize(C.data.error);I.error(r),g.removeEventListener("message",n)}}};return g.addEventListener("message",n),()=>{if(i==="observable"||!i){const C={type:_S.MasterMessageType.cancel,uid:e};g.postMessage(C)}g.removeEventListener("message",n)}})}function y8e(g){if(g.length===0)return{args:[],transferables:[]};const e=[],I=[];for(const i of g)u8e.isTransferDescriptor(i)?(e.push(qG.serialize(i.send)),I.push(...i.transferables)):e.push(qG.serialize(i));return{args:e,transferables:I.length===0?I:h8e(I)}}function H0e(g,e){return(...I)=>{const i=d8e++,{args:n,transferables:C}=y8e(I),r={type:_S.MasterMessageType.run,uid:i,method:e,args:n};X0e("Sending command to run function to worker:",r);try{g.postMessage(r,C)}catch(o){return rge.ObservablePromise.from(Promise.reject(o))}return rge.ObservablePromise.from(W0e.multicast(b8e(g,i)))}}Tb.createProxyFunction=H0e;function Z8e(g,e){const I={};for(const i of e)I[i]=H0e(g,i);return I}Tb.createProxyModule=Z8e;var r7=ZI&&ZI.__awaiter||function(g,e,I,i){function n(C){return C instanceof I?C:new I(function(r){r(C)})}return new(I||(I=Promise))(function(C,r){function o(a){try{s(i.next(a))}catch(l){r(l)}}function A(a){try{s(i.throw(a))}catch(l){r(l)}}function s(a){a.done?C(a.value):n(a.value).then(o,A)}s((i=i.apply(g,e||[])).next())})},G8e=ZI&&ZI.__importDefault||function(g){return g&&g.__esModule?g:{default:g}};Object.defineProperty(lN,"__esModule",{value:!0});lN.spawn=void 0;const o7=G8e(I7),B8e=aN,v8e=Io,S8e=cN,rR=XC,Q1=V0e,oge=Tb,w8e=o7.default("threads:master:messages"),V8e=o7.default("threads:master:spawn"),T0e=o7.default("threads:master:thread-utils"),R8e=g=>g&&g.type==="init",W8e=g=>g&&g.type==="uncaughtError",X8e=typeof process<"u"&&{}.THREADS_WORKER_INIT_TIMEOUT?Number.parseInt({}.THREADS_WORKER_INIT_TIMEOUT,10):1e4;function H8e(g,e,I){return r7(this,void 0,void 0,function*(){let i;const n=new Promise((r,o)=>{i=setTimeout(()=>o(Error(I)),e)}),C=yield Promise.race([g,n]);return clearTimeout(i),C})}function T8e(g){return new Promise((e,I)=>{const i=n=>{w8e("Message from worker before finishing initialization:",n.data),R8e(n.data)?(g.removeEventListener("message",i),e(n.data)):W8e(n.data)&&(g.removeEventListener("message",i),I(v8e.deserialize(n.data.error)))};g.addEventListener("message",i)})}function N8e(g,e){return new B8e.Observable(I=>{const i=C=>{const r={type:Q1.WorkerEventType.message,data:C.data};I.next(r)},n=C=>{T0e("Unhandled promise rejection event in thread:",C);const r={type:Q1.WorkerEventType.internalError,error:Error(C.reason)};I.next(r)};g.addEventListener("message",i),g.addEventListener("unhandledrejection",n),e.then(()=>{const C={type:Q1.WorkerEventType.termination};g.removeEventListener("message",i),g.removeEventListener("unhandledrejection",n),I.next(C),I.complete()})})}function k8e(g){const[e,I]=S8e.createPromiseWithResolver();return{terminate:()=>r7(this,void 0,void 0,function*(){T0e("Terminating worker"),yield g.terminate(),I()}),termination:e}}function Age(g,e,I,i){const n=I.filter(C=>C.type===Q1.WorkerEventType.internalError).map(C=>C.error);return Object.assign(g,{[rR.$errors]:n,[rR.$events]:I,[rR.$terminate]:i,[rR.$worker]:e})}function Y8e(g,e){return r7(this,void 0,void 0,function*(){V8e("Initializing new thread");const I=e&&e.timeout?e.timeout:X8e,n=(yield H8e(T8e(g),I,`Timeout: Did not receive an init message from worker after ${I}ms. Make sure the worker calls expose().`)).exposed,{termination:C,terminate:r}=k8e(g),o=N8e(g,C);if(n.type==="function"){const A=oge.createProxyFunction(g);return Age(A,g,o,r)}else if(n.type==="module"){const A=oge.createProxyModule(g,n.methods);return Age(A,g,o,r)}else{const A=n.type;throw Error(`Worker init message states unexpected type of expose(): ${A}`)}})}lN.spawn=Y8e;(function(g){Object.defineProperty(g,"__esModule",{value:!0}),g.Worker=g.BlobWorker=g.isWorkerRuntime=g.Thread=g.spawn=g.Pool=void 0;const e=Hs;Object.defineProperty(g,"isWorkerRuntime",{enumerable:!0,get:function(){return e.isWorkerRuntime}});var I=y0e;Object.defineProperty(g,"Pool",{enumerable:!0,get:function(){return I.Pool}});var i=lN;Object.defineProperty(g,"spawn",{enumerable:!0,get:function(){return i.spawn}});var n=LS;Object.defineProperty(g,"Thread",{enumerable:!0,get:function(){return n.Thread}}),g.BlobWorker=e.getWorkerImplementation().blob,g.Worker=e.getWorkerImplementation().default})(p0e);var N0e={},K8e=g=>g?typeof Symbol.observable=="symbol"&&typeof g[Symbol.observable]=="function"?g===g[Symbol.observable]():typeof g["@@observable"]=="function"?g===g["@@observable"]():!1:!1,A7={};Object.defineProperty(A7,"__esModule",{value:!0});const x8e=function(){const e=typeof self<"u"&&typeof Window<"u"&&self instanceof Window;return!!(typeof self<"u"&&self.postMessage&&!e)},D8e=function(e,I){self.postMessage(e,I)},F8e=function(e){const I=n=>{e(n.data)},i=()=>{self.removeEventListener("message",I)};return self.addEventListener("message",I),i};A7.default={isWorkerRuntime:x8e,postMessageToMaster:D8e,subscribeToMasterMessages:F8e};(function(g){var e=ZI&&ZI.__awaiter||function(w,R,S,X){function W(V){return V instanceof S?V:new S(function(H){H(V)})}return new(S||(S=Promise))(function(V,H){function D(_){try{F(X.next(_))}catch(J){H(J)}}function Y(_){try{F(X.throw(_))}catch(J){H(J)}}function F(_){_.done?V(_.value):W(_.value).then(D,Y)}F((X=X.apply(w,R||[])).next())})},I=ZI&&ZI.__importDefault||function(w){return w&&w.__esModule?w:{default:w}};Object.defineProperty(g,"__esModule",{value:!0}),g.expose=g.isWorkerRuntime=g.Transfer=g.registerSerializer=void 0;const i=I(K8e),n=Io,C=Ls,r=C7,o=I(A7);var A=Io;Object.defineProperty(g,"registerSerializer",{enumerable:!0,get:function(){return A.registerSerializer}});var s=Ls;Object.defineProperty(g,"Transfer",{enumerable:!0,get:function(){return s.Transfer}}),g.isWorkerRuntime=o.default.isWorkerRuntime;let a=!1;const l=new Map,c=w=>w&&w.type===r.MasterMessageType.cancel,u=w=>w&&w.type===r.MasterMessageType.run,d=w=>i.default(w)||h(w);function h(w){return w&&typeof w=="object"&&typeof w.subscribe=="function"}function m(w){return C.isTransferDescriptor(w)?{payload:w.send,transferables:w.transferables}:{payload:w,transferables:void 0}}function f(){const w={type:r.WorkerMessageType.init,exposed:{type:"function"}};o.default.postMessageToMaster(w)}function b(w){const R={type:r.WorkerMessageType.init,exposed:{type:"module",methods:w}};o.default.postMessageToMaster(R)}function p(w,R){const{payload:S,transferables:X}=m(R),W={type:r.WorkerMessageType.error,uid:w,error:n.serialize(S)};o.default.postMessageToMaster(W,X)}function y(w,R,S){const{payload:X,transferables:W}=m(S),V={type:r.WorkerMessageType.result,uid:w,complete:R?!0:void 0,payload:X};o.default.postMessageToMaster(V,W)}function Z(w,R){const S={type:r.WorkerMessageType.running,uid:w,resultType:R};o.default.postMessageToMaster(S)}function v(w){try{const R={type:r.WorkerMessageType.uncaughtError,error:n.serialize(w)};o.default.postMessageToMaster(R)}catch(R){console.error(`Not reporting uncaught error back to master thread as it occured while reporting an uncaught error already. -Latest error:`,R,` -Original error:`,w)}}function G(w,R,S){return e(this,void 0,void 0,function*(){let X;try{X=R(...S)}catch(V){return p(w,V)}const W=d(X)?"observable":"promise";if(Z(w,W),d(X)){const V=X.subscribe(H=>y(w,!1,n.serialize(H)),H=>{p(w,n.serialize(H)),l.delete(w)},()=>{y(w,!0),l.delete(w)});l.set(w,V)}else try{const V=yield X;y(w,!0,n.serialize(V))}catch(V){p(w,n.serialize(V))}})}function B(w){if(!o.default.isWorkerRuntime())throw Error("expose() called in the master thread.");if(a)throw Error("expose() called more than once. This is not possible. Pass an object to expose() if you want to expose multiple functions.");if(a=!0,typeof w=="function")o.default.subscribeToMasterMessages(R=>{u(R)&&!R.method&&G(R.uid,w,R.args.map(n.deserialize))}),f();else if(typeof w=="object"&&w){o.default.subscribeToMasterMessages(S=>{u(S)&&S.method&&G(S.uid,w[S.method],S.args.map(n.deserialize))});const R=Object.keys(w).filter(S=>typeof w[S]=="function");b(R)}else throw Error(`Invalid argument passed to expose(). Expected a function or an object, got: ${w}`);o.default.subscribeToMasterMessages(R=>{if(c(R)){const S=R.uid,X=l.get(S);X&&(X.unsubscribe(),l.delete(S))}})}g.expose=B,typeof self<"u"&&typeof self.addEventListener=="function"&&o.default.isWorkerRuntime()&&(self.addEventListener("error",w=>{setTimeout(()=>v(w.error||w),250)}),self.addEventListener("unhandledrejection",w=>{const R=w.reason;R&&typeof R.message=="string"&&setTimeout(()=>v(R),250)})),typeof process<"u"&&typeof process.on=="function"&&o.default.isWorkerRuntime()&&(process.on("uncaughtException",w=>{setTimeout(()=>v(w),250)}),process.on("unhandledRejection",w=>{w&&typeof w.message=="string"&&setTimeout(()=>v(w),250)}))})(N0e);(function(g){var e=ZI&&ZI.__createBinding||(Object.create?function(o,A,s,a){a===void 0&&(a=s),Object.defineProperty(o,a,{enumerable:!0,get:function(){return A[s]}})}:function(o,A,s,a){a===void 0&&(a=s),o[a]=A[s]}),I=ZI&&ZI.__exportStar||function(o,A){for(var s in o)s!=="default"&&!Object.prototype.hasOwnProperty.call(A,s)&&e(A,o,s)};Object.defineProperty(g,"__esModule",{value:!0}),g.Transfer=g.DefaultSerializer=g.expose=g.registerSerializer=void 0;var i=Io;Object.defineProperty(g,"registerSerializer",{enumerable:!0,get:function(){return i.registerSerializer}}),I(p0e,g);var n=N0e;Object.defineProperty(g,"expose",{enumerable:!0,get:function(){return n.expose}});var C=Ah;Object.defineProperty(g,"DefaultSerializer",{enumerable:!0,get:function(){return C.DefaultSerializer}});var r=Ls;Object.defineProperty(g,"Transfer",{enumerable:!0,get:function(){return r.Transfer}})})(m0e);const uu=jh(m0e);uu.registerSerializer;const dN=uu.spawn;uu.BlobWorker;uu.DefaultSerializer;uu.Pool;uu.Thread;uu.Transfer;uu.Worker;class E8e extends Map{constructor(e={}){if(super(),!(e.maxSize&&e.maxSize>0))throw new TypeError("`maxSize` must be a number greater than 0");if(typeof e.maxAge=="number"&&e.maxAge===0)throw new TypeError("`maxAge` must be a number greater than 0");this.maxSize=e.maxSize,this.maxAge=e.maxAge||Number.POSITIVE_INFINITY,this.onEviction=e.onEviction,this.cache=new Map,this.oldCache=new Map,this._size=0}_emitEvictions(e){if(typeof this.onEviction=="function")for(const[I,i]of e)this.onEviction(I,i.value)}_deleteIfExpired(e,I){return typeof I.expiry=="number"&&I.expiry<=Date.now()?(typeof this.onEviction=="function"&&this.onEviction(e,I.value),this.delete(e)):!1}_getOrDeleteIfExpired(e,I){if(this._deleteIfExpired(e,I)===!1)return I.value}_getItemValue(e,I){return I.expiry?this._getOrDeleteIfExpired(e,I):I.value}_peek(e,I){const i=I.get(e);return this._getItemValue(e,i)}_set(e,I){this.cache.set(e,I),this._size++,this._size>=this.maxSize&&(this._size=0,this._emitEvictions(this.oldCache),this.oldCache=this.cache,this.cache=new Map)}_moveToRecent(e,I){this.oldCache.delete(e),this._set(e,I)}*_entriesAscending(){for(const e of this.oldCache){const[I,i]=e;this.cache.has(I)||this._deleteIfExpired(I,i)===!1&&(yield e)}for(const e of this.cache){const[I,i]=e;this._deleteIfExpired(I,i)===!1&&(yield e)}}get(e){if(this.cache.has(e)){const I=this.cache.get(e);return this._getItemValue(e,I)}if(this.oldCache.has(e)){const I=this.oldCache.get(e);if(this._deleteIfExpired(e,I)===!1)return this._moveToRecent(e,I),I.value}}set(e,I,{maxAge:i=this.maxAge}={}){const n=typeof i=="number"&&i!==Number.POSITIVE_INFINITY?Date.now()+i:void 0;return this.cache.has(e)?this.cache.set(e,{value:I,expiry:n}):this._set(e,{value:I,expiry:n}),this}has(e){return this.cache.has(e)?!this._deleteIfExpired(e,this.cache.get(e)):this.oldCache.has(e)?!this._deleteIfExpired(e,this.oldCache.get(e)):!1}peek(e){if(this.cache.has(e))return this._peek(e,this.cache);if(this.oldCache.has(e))return this._peek(e,this.oldCache)}delete(e){const I=this.cache.delete(e);return I&&this._size--,this.oldCache.delete(e)||I}clear(){this.cache.clear(),this.oldCache.clear(),this._size=0}resize(e){if(!(e&&e>0))throw new TypeError("`maxSize` must be a number greater than 0");const I=[...this._entriesAscending()],i=I.length-e;i<0?(this.cache=new Map(I),this.oldCache=new Map,this._size=I.length):(i>0&&this._emitEvictions(I.slice(0,i)),this.oldCache=new Map(I.slice(i)),this.cache=new Map,this._size=0),this.maxSize=e}*keys(){for(const[e]of this)yield e}*values(){for(const[,e]of this)yield e}*[Symbol.iterator](){for(const e of this.cache){const[I,i]=e;this._deleteIfExpired(I,i)===!1&&(yield[I,i.value])}for(const e of this.oldCache){const[I,i]=e;this.cache.has(I)||this._deleteIfExpired(I,i)===!1&&(yield[I,i.value])}}*entriesDescending(){let e=[...this.cache];for(let I=e.length-1;I>=0;--I){const i=e[I],[n,C]=i;this._deleteIfExpired(n,C)===!1&&(yield[n,C.value])}e=[...this.oldCache];for(let I=e.length-1;I>=0;--I){const i=e[I],[n,C]=i;this.cache.has(n)||this._deleteIfExpired(n,C)===!1&&(yield[n,C.value])}}*entriesAscending(){for(const[e,I]of this._entriesAscending())yield[e,I.value]}get size(){if(!this._size)return this.oldCache.size;let e=0;for(const I of this.oldCache.keys())this.cache.has(I)||e++;return Math.min(this._size+e,this.maxSize)}entries(){return this.entriesAscending()}forEach(e,I=this){for(const[i,n]of this.entriesAscending())e.call(I,n,i,this)}get[Symbol.toStringTag](){return JSON.stringify([...this.entriesAscending()])}}var age={},D5={},F5=34,Uy=10,E5=13;function k0e(g){return new Function("d","return {"+g.map(function(e,I){return JSON.stringify(e)+": d["+I+'] || ""'}).join(",")+"}")}function M8e(g,e){var I=k0e(g);return function(i,n){return e(I(i),n,g)}}function sge(g){var e=Object.create(null),I=[];return g.forEach(function(i){for(var n in i)n in e||I.push(e[n]=n)}),I}function ZC(g,e){var I=g+"",i=I.length;return i9999?"+"+ZC(g,6):ZC(g,4)}function P8e(g){var e=g.getUTCHours(),I=g.getUTCMinutes(),i=g.getUTCSeconds(),n=g.getUTCMilliseconds();return isNaN(g)?"Invalid Date":z8e(g.getUTCFullYear())+"-"+ZC(g.getUTCMonth()+1,2)+"-"+ZC(g.getUTCDate(),2)+(n?"T"+ZC(e,2)+":"+ZC(I,2)+":"+ZC(i,2)+"."+ZC(n,3)+"Z":i?"T"+ZC(e,2)+":"+ZC(I,2)+":"+ZC(i,2)+"Z":I||e?"T"+ZC(e,2)+":"+ZC(I,2)+"Z":"")}function J8e(g){var e=new RegExp('["'+g+` -\r]`),I=g.charCodeAt(0);function i(l,c){var u,d,h=n(l,function(m,f){if(u)return u(m,f-1);d=m,u=c?M8e(m,c):k0e(m)});return h.columns=d||[],h}function n(l,c){var u=[],d=l.length,h=0,m=0,f,b=d<=0,p=!1;l.charCodeAt(d-1)===Uy&&--d,l.charCodeAt(d-1)===E5&&--d;function y(){if(b)return D5;if(p)return p=!1,age;var v,G=h,B;if(l.charCodeAt(G)===F5){for(;h++=d?b=!0:(B=l.charCodeAt(h++))===Uy?p=!0:B===E5&&(p=!0,l.charCodeAt(h)===Uy&&++h),l.slice(G+1,v-1).replace(/""/g,'"')}for(;hn)throw new RangeError('The value "'+K+'" is invalid for option "size"');const T=new Uint8Array(K);return Object.setPrototypeOf(T,o.prototype),T}function o(K,T,k){if(typeof K=="number"){if(typeof T=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return l(K)}return A(K,T,k)}o.poolSize=8192;function A(K,T,k){if(typeof K=="string")return c(K,T);if(ArrayBuffer.isView(K))return d(K);if(K==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof K);if(nt(K,ArrayBuffer)||K&&nt(K.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(nt(K,SharedArrayBuffer)||K&&nt(K.buffer,SharedArrayBuffer)))return h(K,T,k);if(typeof K=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');const ge=K.valueOf&&K.valueOf();if(ge!=null&&ge!==K)return o.from(ge,T,k);const he=m(K);if(he)return he;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof K[Symbol.toPrimitive]=="function")return o.from(K[Symbol.toPrimitive]("string"),T,k);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof K)}o.from=function(K,T,k){return A(K,T,k)},Object.setPrototypeOf(o.prototype,Uint8Array.prototype),Object.setPrototypeOf(o,Uint8Array);function s(K){if(typeof K!="number")throw new TypeError('"size" argument must be of type number');if(K<0)throw new RangeError('The value "'+K+'" is invalid for option "size"')}function a(K,T,k){return s(K),K<=0?r(K):T!==void 0?typeof k=="string"?r(K).fill(T,k):r(K).fill(T):r(K)}o.alloc=function(K,T,k){return a(K,T,k)};function l(K){return s(K),r(K<0?0:f(K)|0)}o.allocUnsafe=function(K){return l(K)},o.allocUnsafeSlow=function(K){return l(K)};function c(K,T){if((typeof T!="string"||T==="")&&(T="utf8"),!o.isEncoding(T))throw new TypeError("Unknown encoding: "+T);const k=p(K,T)|0;let ge=r(k);const he=ge.write(K,T);return he!==k&&(ge=ge.slice(0,he)),ge}function u(K){const T=K.length<0?0:f(K.length)|0,k=r(T);for(let ge=0;ge=n)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+n.toString(16)+" bytes");return K|0}function b(K){return+K!=K&&(K=0),o.alloc(+K)}o.isBuffer=function(T){return T!=null&&T._isBuffer===!0&&T!==o.prototype},o.compare=function(T,k){if(nt(T,Uint8Array)&&(T=o.from(T,T.offset,T.byteLength)),nt(k,Uint8Array)&&(k=o.from(k,k.offset,k.byteLength)),!o.isBuffer(T)||!o.isBuffer(k))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(T===k)return 0;let ge=T.length,he=k.length;for(let Ve=0,De=Math.min(ge,he);Vehe.length?(o.isBuffer(De)||(De=o.from(De)),De.copy(he,Ve)):Uint8Array.prototype.set.call(he,De,Ve);else if(o.isBuffer(De))De.copy(he,Ve);else throw new TypeError('"list" argument must be an Array of Buffers');Ve+=De.length}return he};function p(K,T){if(o.isBuffer(K))return K.length;if(ArrayBuffer.isView(K)||nt(K,ArrayBuffer))return K.byteLength;if(typeof K!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof K);const k=K.length,ge=arguments.length>2&&arguments[2]===!0;if(!ge&&k===0)return 0;let he=!1;for(;;)switch(T){case"ascii":case"latin1":case"binary":return k;case"utf8":case"utf-8":return Fe(K).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return k*2;case"hex":return k>>>1;case"base64":return ot(K).length;default:if(he)return ge?-1:Fe(K).length;T=(""+T).toLowerCase(),he=!0}}o.byteLength=p;function y(K,T,k){let ge=!1;if((T===void 0||T<0)&&(T=0),T>this.length||((k===void 0||k>this.length)&&(k=this.length),k<=0)||(k>>>=0,T>>>=0,k<=T))return"";for(K||(K="utf8");;)switch(K){case"hex":return O(this,T,k);case"utf8":case"utf-8":return R(this,T,k);case"ascii":return D(this,T,k);case"latin1":case"binary":return E(this,T,k);case"base64":return W(this,T,k);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return J(this,T,k);default:if(ge)throw new TypeError("Unknown encoding: "+K);K=(K+"").toLowerCase(),ge=!0}}o.prototype._isBuffer=!0;function Z(K,T,k){const ge=K[T];K[T]=K[k],K[k]=ge}o.prototype.swap16=function(){const T=this.length;if(T%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let k=0;kk&&(T+=" ... "),""},i&&(o.prototype[i]=o.prototype.inspect),o.prototype.compare=function(T,k,ge,he,Ve){if(nt(T,Uint8Array)&&(T=o.from(T,T.offset,T.byteLength)),!o.isBuffer(T))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof T);if(k===void 0&&(k=0),ge===void 0&&(ge=T?T.length:0),he===void 0&&(he=0),Ve===void 0&&(Ve=this.length),k<0||ge>T.length||he<0||Ve>this.length)throw new RangeError("out of range index");if(he>=Ve&&k>=ge)return 0;if(he>=Ve)return-1;if(k>=ge)return 1;if(k>>>=0,ge>>>=0,he>>>=0,Ve>>>=0,this===T)return 0;let De=Ve-he,qe=ge-k;const mt=Math.min(De,qe),vt=this.slice(he,Ve),ct=T.slice(k,ge);for(let Ht=0;Ht2147483647?k=2147483647:k<-2147483648&&(k=-2147483648),k=+k,Te(k)&&(k=he?0:K.length-1),k<0&&(k=K.length+k),k>=K.length){if(he)return-1;k=K.length-1}else if(k<0)if(he)k=0;else return-1;if(typeof T=="string"&&(T=o.from(T,ge)),o.isBuffer(T))return T.length===0?-1:G(K,T,k,ge,he);if(typeof T=="number")return T=T&255,typeof Uint8Array.prototype.indexOf=="function"?he?Uint8Array.prototype.indexOf.call(K,T,k):Uint8Array.prototype.lastIndexOf.call(K,T,k):G(K,[T],k,ge,he);throw new TypeError("val must be string, number or Buffer")}function G(K,T,k,ge,he){let Ve=1,De=K.length,qe=T.length;if(ge!==void 0&&(ge=String(ge).toLowerCase(),ge==="ucs2"||ge==="ucs-2"||ge==="utf16le"||ge==="utf-16le")){if(K.length<2||T.length<2)return-1;Ve=2,De/=2,qe/=2,k/=2}function mt(ct,Ht){return Ve===1?ct[Ht]:ct.readUInt16BE(Ht*Ve)}let vt;if(he){let ct=-1;for(vt=k;vtDe&&(k=De-qe),vt=k;vt>=0;vt--){let ct=!0;for(let Ht=0;Hthe&&(ge=he)):ge=he;const Ve=T.length;ge>Ve/2&&(ge=Ve/2);let De;for(De=0;De>>0,isFinite(ge)?(ge=ge>>>0,he===void 0&&(he="utf8")):(he=ge,ge=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");const Ve=this.length-k;if((ge===void 0||ge>Ve)&&(ge=Ve),T.length>0&&(ge<0||k<0)||k>this.length)throw new RangeError("Attempt to write outside buffer bounds");he||(he="utf8");let De=!1;for(;;)switch(he){case"hex":return v(this,T,k,ge);case"utf8":case"utf-8":return w(this,T,k,ge);case"ascii":case"latin1":case"binary":return V(this,T,k,ge);case"base64":return S(this,T,k,ge);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return X(this,T,k,ge);default:if(De)throw new TypeError("Unknown encoding: "+he);he=(""+he).toLowerCase(),De=!0}},o.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function W(K,T,k){return T===0&&k===K.length?g.fromByteArray(K):g.fromByteArray(K.slice(T,k))}function R(K,T,k){k=Math.min(K.length,k);const ge=[];let he=T;for(;he239?4:Ve>223?3:Ve>191?2:1;if(he+qe<=k){let mt,vt,ct,Ht;switch(qe){case 1:Ve<128&&(De=Ve);break;case 2:mt=K[he+1],(mt&192)===128&&(Ht=(Ve&31)<<6|mt&63,Ht>127&&(De=Ht));break;case 3:mt=K[he+1],vt=K[he+2],(mt&192)===128&&(vt&192)===128&&(Ht=(Ve&15)<<12|(mt&63)<<6|vt&63,Ht>2047&&(Ht<55296||Ht>57343)&&(De=Ht));break;case 4:mt=K[he+1],vt=K[he+2],ct=K[he+3],(mt&192)===128&&(vt&192)===128&&(ct&192)===128&&(Ht=(Ve&15)<<18|(mt&63)<<12|(vt&63)<<6|ct&63,Ht>65535&&Ht<1114112&&(De=Ht))}}De===null?(De=65533,qe=1):De>65535&&(De-=65536,ge.push(De>>>10&1023|55296),De=56320|De&1023),ge.push(De),he+=qe}return Y(ge)}const H=4096;function Y(K){const T=K.length;if(T<=H)return String.fromCharCode.apply(String,K);let k="",ge=0;for(;gege)&&(k=ge);let he="";for(let Ve=T;Vege&&(T=ge),k<0?(k+=ge,k<0&&(k=0)):k>ge&&(k=ge),kk)throw new RangeError("Trying to access beyond buffer length")}o.prototype.readUintLE=o.prototype.readUIntLE=function(T,k,ge){T=T>>>0,k=k>>>0,ge||ee(T,k,this.length);let he=this[T],Ve=1,De=0;for(;++De>>0,k=k>>>0,ge||ee(T,k,this.length);let he=this[T+--k],Ve=1;for(;k>0&&(Ve*=256);)he+=this[T+--k]*Ve;return he},o.prototype.readUint8=o.prototype.readUInt8=function(T,k){return T=T>>>0,k||ee(T,1,this.length),this[T]},o.prototype.readUint16LE=o.prototype.readUInt16LE=function(T,k){return T=T>>>0,k||ee(T,2,this.length),this[T]|this[T+1]<<8},o.prototype.readUint16BE=o.prototype.readUInt16BE=function(T,k){return T=T>>>0,k||ee(T,2,this.length),this[T]<<8|this[T+1]},o.prototype.readUint32LE=o.prototype.readUInt32LE=function(T,k){return T=T>>>0,k||ee(T,4,this.length),(this[T]|this[T+1]<<8|this[T+2]<<16)+this[T+3]*16777216},o.prototype.readUint32BE=o.prototype.readUInt32BE=function(T,k){return T=T>>>0,k||ee(T,4,this.length),this[T]*16777216+(this[T+1]<<16|this[T+2]<<8|this[T+3])},o.prototype.readBigUInt64LE=ye(function(T){T=T>>>0,Ne(T,"offset");const k=this[T],ge=this[T+7];(k===void 0||ge===void 0)&&Se(T,this.length-8);const he=k+this[++T]*2**8+this[++T]*2**16+this[++T]*2**24,Ve=this[++T]+this[++T]*2**8+this[++T]*2**16+ge*2**24;return BigInt(he)+(BigInt(Ve)<>>0,Ne(T,"offset");const k=this[T],ge=this[T+7];(k===void 0||ge===void 0)&&Se(T,this.length-8);const he=k*2**24+this[++T]*2**16+this[++T]*2**8+this[++T],Ve=this[++T]*2**24+this[++T]*2**16+this[++T]*2**8+ge;return(BigInt(he)<>>0,k=k>>>0,ge||ee(T,k,this.length);let he=this[T],Ve=1,De=0;for(;++De=Ve&&(he-=Math.pow(2,8*k)),he},o.prototype.readIntBE=function(T,k,ge){T=T>>>0,k=k>>>0,ge||ee(T,k,this.length);let he=k,Ve=1,De=this[T+--he];for(;he>0&&(Ve*=256);)De+=this[T+--he]*Ve;return Ve*=128,De>=Ve&&(De-=Math.pow(2,8*k)),De},o.prototype.readInt8=function(T,k){return T=T>>>0,k||ee(T,1,this.length),this[T]&128?(255-this[T]+1)*-1:this[T]},o.prototype.readInt16LE=function(T,k){T=T>>>0,k||ee(T,2,this.length);const ge=this[T]|this[T+1]<<8;return ge&32768?ge|4294901760:ge},o.prototype.readInt16BE=function(T,k){T=T>>>0,k||ee(T,2,this.length);const ge=this[T+1]|this[T]<<8;return ge&32768?ge|4294901760:ge},o.prototype.readInt32LE=function(T,k){return T=T>>>0,k||ee(T,4,this.length),this[T]|this[T+1]<<8|this[T+2]<<16|this[T+3]<<24},o.prototype.readInt32BE=function(T,k){return T=T>>>0,k||ee(T,4,this.length),this[T]<<24|this[T+1]<<16|this[T+2]<<8|this[T+3]},o.prototype.readBigInt64LE=ye(function(T){T=T>>>0,Ne(T,"offset");const k=this[T],ge=this[T+7];(k===void 0||ge===void 0)&&Se(T,this.length-8);const he=this[T+4]+this[T+5]*2**8+this[T+6]*2**16+(ge<<24);return(BigInt(he)<>>0,Ne(T,"offset");const k=this[T],ge=this[T+7];(k===void 0||ge===void 0)&&Se(T,this.length-8);const he=(k<<24)+this[++T]*2**16+this[++T]*2**8+this[++T];return(BigInt(he)<>>0,k||ee(T,4,this.length),I.read(this,T,!0,23,4)},o.prototype.readFloatBE=function(T,k){return T=T>>>0,k||ee(T,4,this.length),I.read(this,T,!1,23,4)},o.prototype.readDoubleLE=function(T,k){return T=T>>>0,k||ee(T,8,this.length),I.read(this,T,!0,52,8)},o.prototype.readDoubleBE=function(T,k){return T=T>>>0,k||ee(T,8,this.length),I.read(this,T,!1,52,8)};function q(K,T,k,ge,he,Ve){if(!o.isBuffer(K))throw new TypeError('"buffer" argument must be a Buffer instance');if(T>he||TK.length)throw new RangeError("Index out of range")}o.prototype.writeUintLE=o.prototype.writeUIntLE=function(T,k,ge,he){if(T=+T,k=k>>>0,ge=ge>>>0,!he){const qe=Math.pow(2,8*ge)-1;q(this,T,k,ge,qe,0)}let Ve=1,De=0;for(this[k]=T&255;++De>>0,ge=ge>>>0,!he){const qe=Math.pow(2,8*ge)-1;q(this,T,k,ge,qe,0)}let Ve=ge-1,De=1;for(this[k+Ve]=T&255;--Ve>=0&&(De*=256);)this[k+Ve]=T/De&255;return k+ge},o.prototype.writeUint8=o.prototype.writeUInt8=function(T,k,ge){return T=+T,k=k>>>0,ge||q(this,T,k,1,255,0),this[k]=T&255,k+1},o.prototype.writeUint16LE=o.prototype.writeUInt16LE=function(T,k,ge){return T=+T,k=k>>>0,ge||q(this,T,k,2,65535,0),this[k]=T&255,this[k+1]=T>>>8,k+2},o.prototype.writeUint16BE=o.prototype.writeUInt16BE=function(T,k,ge){return T=+T,k=k>>>0,ge||q(this,T,k,2,65535,0),this[k]=T>>>8,this[k+1]=T&255,k+2},o.prototype.writeUint32LE=o.prototype.writeUInt32LE=function(T,k,ge){return T=+T,k=k>>>0,ge||q(this,T,k,4,4294967295,0),this[k+3]=T>>>24,this[k+2]=T>>>16,this[k+1]=T>>>8,this[k]=T&255,k+4},o.prototype.writeUint32BE=o.prototype.writeUInt32BE=function(T,k,ge){return T=+T,k=k>>>0,ge||q(this,T,k,4,4294967295,0),this[k]=T>>>24,this[k+1]=T>>>16,this[k+2]=T>>>8,this[k+3]=T&255,k+4};function $(K,T,k,ge,he){Be(T,ge,he,K,k,7);let Ve=Number(T&BigInt(4294967295));K[k++]=Ve,Ve=Ve>>8,K[k++]=Ve,Ve=Ve>>8,K[k++]=Ve,Ve=Ve>>8,K[k++]=Ve;let De=Number(T>>BigInt(32)&BigInt(4294967295));return K[k++]=De,De=De>>8,K[k++]=De,De=De>>8,K[k++]=De,De=De>>8,K[k++]=De,k}function j(K,T,k,ge,he){Be(T,ge,he,K,k,7);let Ve=Number(T&BigInt(4294967295));K[k+7]=Ve,Ve=Ve>>8,K[k+6]=Ve,Ve=Ve>>8,K[k+5]=Ve,Ve=Ve>>8,K[k+4]=Ve;let De=Number(T>>BigInt(32)&BigInt(4294967295));return K[k+3]=De,De=De>>8,K[k+2]=De,De=De>>8,K[k+1]=De,De=De>>8,K[k]=De,k+8}o.prototype.writeBigUInt64LE=ye(function(T,k=0){return $(this,T,k,BigInt(0),BigInt("0xffffffffffffffff"))}),o.prototype.writeBigUInt64BE=ye(function(T,k=0){return j(this,T,k,BigInt(0),BigInt("0xffffffffffffffff"))}),o.prototype.writeIntLE=function(T,k,ge,he){if(T=+T,k=k>>>0,!he){const mt=Math.pow(2,8*ge-1);q(this,T,k,ge,mt-1,-mt)}let Ve=0,De=1,qe=0;for(this[k]=T&255;++Ve>0)-qe&255;return k+ge},o.prototype.writeIntBE=function(T,k,ge,he){if(T=+T,k=k>>>0,!he){const mt=Math.pow(2,8*ge-1);q(this,T,k,ge,mt-1,-mt)}let Ve=ge-1,De=1,qe=0;for(this[k+Ve]=T&255;--Ve>=0&&(De*=256);)T<0&&qe===0&&this[k+Ve+1]!==0&&(qe=1),this[k+Ve]=(T/De>>0)-qe&255;return k+ge},o.prototype.writeInt8=function(T,k,ge){return T=+T,k=k>>>0,ge||q(this,T,k,1,127,-128),T<0&&(T=255+T+1),this[k]=T&255,k+1},o.prototype.writeInt16LE=function(T,k,ge){return T=+T,k=k>>>0,ge||q(this,T,k,2,32767,-32768),this[k]=T&255,this[k+1]=T>>>8,k+2},o.prototype.writeInt16BE=function(T,k,ge){return T=+T,k=k>>>0,ge||q(this,T,k,2,32767,-32768),this[k]=T>>>8,this[k+1]=T&255,k+2},o.prototype.writeInt32LE=function(T,k,ge){return T=+T,k=k>>>0,ge||q(this,T,k,4,2147483647,-2147483648),this[k]=T&255,this[k+1]=T>>>8,this[k+2]=T>>>16,this[k+3]=T>>>24,k+4},o.prototype.writeInt32BE=function(T,k,ge){return T=+T,k=k>>>0,ge||q(this,T,k,4,2147483647,-2147483648),T<0&&(T=4294967295+T+1),this[k]=T>>>24,this[k+1]=T>>>16,this[k+2]=T>>>8,this[k+3]=T&255,k+4},o.prototype.writeBigInt64LE=ye(function(T,k=0){return $(this,T,k,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),o.prototype.writeBigInt64BE=ye(function(T,k=0){return j(this,T,k,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function te(K,T,k,ge,he,Ve){if(k+ge>K.length)throw new RangeError("Index out of range");if(k<0)throw new RangeError("Index out of range")}function U(K,T,k,ge,he){return T=+T,k=k>>>0,he||te(K,T,k,4),I.write(K,T,k,ge,23,4),k+4}o.prototype.writeFloatLE=function(T,k,ge){return U(this,T,k,!0,ge)},o.prototype.writeFloatBE=function(T,k,ge){return U(this,T,k,!1,ge)};function ie(K,T,k,ge,he){return T=+T,k=k>>>0,he||te(K,T,k,8),I.write(K,T,k,ge,52,8),k+8}o.prototype.writeDoubleLE=function(T,k,ge){return ie(this,T,k,!0,ge)},o.prototype.writeDoubleBE=function(T,k,ge){return ie(this,T,k,!1,ge)},o.prototype.copy=function(T,k,ge,he){if(!o.isBuffer(T))throw new TypeError("argument should be a Buffer");if(ge||(ge=0),!he&&he!==0&&(he=this.length),k>=T.length&&(k=T.length),k||(k=0),he>0&&he=this.length)throw new RangeError("Index out of range");if(he<0)throw new RangeError("sourceEnd out of bounds");he>this.length&&(he=this.length),T.length-k>>0,ge=ge===void 0?this.length:ge>>>0,T||(T=0);let Ve;if(typeof T=="number")for(Ve=k;Ve2**32?he=Ze(String(k)):typeof k=="bigint"&&(he=String(k),(k>BigInt(2)**BigInt(32)||k<-(BigInt(2)**BigInt(32)))&&(he=Ze(he)),he+="n"),ge+=` It must be ${T}. Received ${he}`,ge},RangeError);function Ze(K){let T="",k=K.length;const ge=K[0]==="-"?1:0;for(;k>=ge+4;k-=3)T=`_${K.slice(k-3,k)}${T}`;return`${K.slice(0,k)}${T}`}function Ge(K,T,k){Ne(T,"offset"),(K[T]===void 0||K[T+k]===void 0)&&Se(T,K.length-(k+1))}function Be(K,T,k,ge,he,Ve){if(K>k||K3?T===0||T===BigInt(0)?qe=`>= 0${De} and < 2${De} ** ${(Ve+1)*8}${De}`:qe=`>= -(2${De} ** ${(Ve+1)*8-1}${De}) and < 2 ** ${(Ve+1)*8-1}${De}`:qe=`>= ${T}${De} and <= ${k}${De}`,new me.ERR_OUT_OF_RANGE("value",qe,K)}Ge(ge,he,Ve)}function Ne(K,T){if(typeof K!="number")throw new me.ERR_INVALID_ARG_TYPE(T,"number",K)}function Se(K,T,k){throw Math.floor(K)!==K?(Ne(K,k),new me.ERR_OUT_OF_RANGE(k||"offset","an integer",K)):T<0?new me.ERR_BUFFER_OUT_OF_BOUNDS:new me.ERR_OUT_OF_RANGE(k||"offset",`>= ${k?1:0} and <= ${T}`,K)}const Pe=/[^+/0-9A-Za-z-_]/g;function ze(K){if(K=K.split("=")[0],K=K.trim().replace(Pe,""),K.length<2)return"";for(;K.length%4!==0;)K=K+"=";return K}function Fe(K,T){T=T||1/0;let k;const ge=K.length;let he=null;const Ve=[];for(let De=0;De55295&&k<57344){if(!he){if(k>56319){(T-=3)>-1&&Ve.push(239,191,189);continue}else if(De+1===ge){(T-=3)>-1&&Ve.push(239,191,189);continue}he=k;continue}if(k<56320){(T-=3)>-1&&Ve.push(239,191,189),he=k;continue}k=(he-55296<<10|k-56320)+65536}else he&&(T-=3)>-1&&Ve.push(239,191,189);if(he=null,k<128){if((T-=1)<0)break;Ve.push(k)}else if(k<2048){if((T-=2)<0)break;Ve.push(k>>6|192,k&63|128)}else if(k<65536){if((T-=3)<0)break;Ve.push(k>>12|224,k>>6&63|128,k&63|128)}else if(k<1114112){if((T-=4)<0)break;Ve.push(k>>18|240,k>>12&63|128,k>>6&63|128,k&63|128)}else throw new Error("Invalid code point")}return Ve}function Ue(K){const T=[];for(let k=0;k>8,he=k%256,Ve.push(he),Ve.push(ge);return Ve}function ot(K){return g.toByteArray(ze(K))}function Zt(K,T,k,ge){let he;for(he=0;he=T.length||he>=K.length);++he)T[he+k]=K[he];return he}function nt(K,T){return K instanceof T||K!=null&&K.constructor!=null&&K.constructor.name!=null&&K.constructor.name===T.name}function Te(K){return K!==K}const se=function(){const K="0123456789abcdef",T=new Array(256);for(let k=0;k<16;++k){const ge=k*16;for(let he=0;he<16;++he)T[ge+he]=K[k]+K[he]}return T}();function ye(K){return typeof BigInt>"u"?Xe:K}function Xe(){throw new Error("BigInt not supported")}})(Jd);let lpe=class{async getBufferFromResponse(g){if(typeof g.buffer=="function")return g.buffer();if(typeof g.arrayBuffer=="function"){const I=await g.arrayBuffer();return Jd.Buffer.from(I)}else throw new TypeError("invalid HTTP response object, has no buffer method, and no arrayBuffer method")}constructor(g,I={}){this.baseOverrides={},this.url=g;const i=I.fetch||globalThis.fetch.bind(globalThis);if(!i)throw new TypeError("no fetch function supplied, and none found in global environment");I.overrides&&(this.baseOverrides=I.overrides),this.fetchImplementation=i}async fetch(g,I){let i;try{i=await this.fetchImplementation(g,I)}catch(n){if(`${n}`.includes("Failed to fetch"))console.warn(`generic-filehandle: refetching ${g} to attempt to work around chrome CORS header caching bug`),i=await this.fetchImplementation(g,{...I,cache:"reload"});else throw n}return i}async read(g,I=0,i,n=0,C={}){const{headers:r={},signal:o,overrides:A={}}=C;i<1/0?r.range=`bytes=${n}-${n+i}`:i===1/0&&n!==0&&(r.range=`bytes=${n}-`);const s={...this.baseOverrides,...A,headers:{...r,...A.headers,...this.baseOverrides.headers},method:"GET",redirect:"follow",mode:"cors",signal:o},a=await this.fetch(this.url,s);if(!a.ok)throw new Error(`HTTP ${a.status} ${a.statusText} ${this.url}`);if(a.status===200&&n===0||a.status===206){const l=await this.getBufferFromResponse(a),c=l.copy(g,I,0,Math.min(i,l.length)),u=a.headers.get("content-range"),d=/\/(\d+)$/.exec(u||"");return d&&d[1]&&(this._stat={size:parseInt(d[1],10)}),{bytesRead:c,buffer:g}}throw a.status===200?new Error("${this.url} fetch returned status 200, expected 206"):new Error(`HTTP ${a.status} fetching ${this.url}`)}async readFile(g={}){let I,i;typeof g=="string"?(I=g,i={}):(I=g.encoding,i=g,delete i.encoding);const{headers:n={},signal:C,overrides:r={}}=i,o={headers:n,method:"GET",redirect:"follow",mode:"cors",signal:C,...this.baseOverrides,...r},A=await this.fetch(this.url,o);if(!A)throw new Error("generic-filehandle failed to fetch");if(A.status!==200)throw Object.assign(new Error(`HTTP ${A.status} fetching ${this.url}`),{status:A.status});if(I==="utf8")return A.text();if(I)throw new Error(`unsupported encoding: ${I}`);return this.getBufferFromResponse(A)}async stat(){if(!this._stat){const g=Jd.Buffer.allocUnsafe(10);if(await this.read(g,0,10,0),!this._stat)throw new Error(`unable to determine size of file at ${this.url}`)}return this._stat}async close(){}};var bQe=Object.defineProperty,yQe=(e,g,I)=>g in e?bQe(e,g,{enumerable:!0,configurable:!0,writable:!0,value:I}):e[g]=I,ZQe=(e,g,I)=>(yQe(e,typeof g!="symbol"?g+"":g,I),I);const cX=6,GQe=130,vQe=600,Fee=600,s1=10,cpe=.3,BQe=0,SQe="gray",ft=e=>{let g=Md(e);return g||(g=Md(SQe)),Xhe([g.rgb().r/255,g.rgb().g/255,g.rgb().b/255])},ji=0;function Ug(e,g,I,i,n){const C=Math.max(Math.min(g,e),0),r=n??ji,o=(i-I)/360*Math.PI*2-r*2;return-(I/360*Math.PI*2+C/g*o)-Math.PI/2-r}function Mt(e,g,I,i,n,C,r){return{x:i+I*Math.cos(Ug(e,g,C,r)),y:n+I*Math.sin(Ug(e,g,C,r))}}function ic(e,g,I,i){return I<=e?Math.atan((g-i)/(e-I)):Math.atan((g-i)/(e-I))-Math.PI}function wQe(e,g,I,i){return(Math.atan2(-(g-i),e-I)/Math.PI*180+270)%360}function VQe(e,g,I){var i,n,C,r,o;const A=I.spec();if(!A.width||!A.height){console.warn("Size of a track is not properly determined, so visual mark cannot be rendered");return}const s=I.data(),[a,l]=e.dimensions,c=I.getChannelScale("x").invert(a)-I.getChannelScale("x").invert(0),u=A.layout==="circular",d=(i=A.innerRadius)!=null?i:220,h=(n=A.outerRadius)!=null?n:300,m=(C=A.startAngle)!=null?C:0,f=(r=A.endAngle)!=null?r:360,b=h-d,p=a/2,y=l/2,Z=(o=I.getChannelDomainArray("row"))!=null?o:["___SINGLE_ROW___"],B=l/Z.length;Z.forEach(G=>{const v=I.encodedValue("row",G);s.filter(w=>!fI(w,A.row)||fI(w,A.row)===G).forEach(w=>{const V=I.encodedPIXIProperty("x-center",w),S=I.encodedPIXIProperty("y-center",w),X=I.encodedPIXIProperty("color",w),W=I.encodedPIXIProperty("p-size",w),R=I.encodedPIXIProperty("strokeWidth",w),H=I.encodedPIXIProperty("stroke",w),Y=I.encodedPIXIProperty("opacity",w),D=I.markVisibility(w,{width:W,zoomLevel:c}),E=Math.min(D,Y);if(!(W<=.1||E===0||V+W<0||V-W>a))if(g.lineStyle(R,ft(H),E,1),u){const O=h-(v+B-S)/l*b,J=Mt(V,a,O,p,y,m,f);g.beginFill(ft(X),E),g.drawCircle(J.x,J.y,W),I.getMouseEventModel().addPointBasedEvent(w,[J.x,J.y,W])}else g.beginFill(ft(X),E),g.drawCircle(V,v+B-S,W),I.getMouseEventModel().addPointBasedEvent(w,[V,v+B-S,W])})})}function RQe(e,g,I){const i=e.visualPropertyByChannel("xe",I),n=e.visualPropertyByChannel("x",I),C=e.visualPropertyByChannel("size",I);switch(g){case"x-center":return i?(i+n)/2:n;case"y-center":{const r=e.visualPropertyByChannel("ye",I),o=e.visualPropertyByChannel("y",I);return r?(r+o)/2:o}case"p-size":return i&&e.spec().stretch?(i-n)/2:C;default:return}}function WQe(e,g,I,i){var n,C,r,o,A,s;const a=g.spec();if(!a.width||!a.height){console.warn("Size of a track is not properly determined, so visual mark cannot be rendered");return}const l=g.data(),c=a.layout==="circular",u=(n=a.innerRadius)!=null?n:220,d=(C=a.outerRadius)!=null?C:300,h=(r=a.startAngle)!=null?r:0,m=(o=a.endAngle)!=null?o:360,f=d-u,b=I/2,p=i/2,y=(A=g.getChannelDomainArray("row"))!=null?A:["___SINGLE_ROW___"],Z=i/y.length,B=(s=g.getChannelDomainArray("color"))!=null?s:["___SINGLE_COLOR___"];y.forEach(G=>{const v=g.encodedValue("row",G);B.forEach(w=>{l.filter(V=>(!fI(V,a.row)||fI(V,a.row)===G)&&(!fI(V,a.color)||fI(V,a.color)===w)).sort((V,S)=>fI(V,a.x)-fI(S,a.x)).forEach((V,S)=>{const X=g.encodedPIXIProperty("x",V),W=g.encodedPIXIProperty("y",V),R=g.encodedPIXIProperty("size",V),H=g.encodedPIXIProperty("color",V),Y=g.encodedPIXIProperty("opacity",V);if(e.lineStyle(R,ft(H),Y,.5),c){const D=d-(v+Z-W)/i*f,E=Mt(X,I,D,b,p,h,m);S===0?e.moveTo(E.x,E.y):e.lineTo(E.x,E.y),g.getMouseEventModel().addPointBasedEvent(V,[E.x,E.y,1])}else S===0?e.moveTo(X,v+Z-W):e.lineTo(X,v+Z-W),g.getMouseEventModel().addPointBasedEvent(V,[X,v+Z-W,1])})})})}function XQe(e,g,I){var i,n,C,r,o,A,s;const a=I.spec();if(!a.width||!a.height){console.warn("Size of a track is not properly determined, so visual mark cannot be rendered");return}const l=I.data(),[c,u]=e.dimensions,d=e.tilesetInfo.tile_size,h=I.getChannelScale("x").invert(c)-I.getChannelScale("x").invert(0),m=a.layout==="circular",f=(i=a.innerRadius)!=null?i:220,b=(n=a.outerRadius)!=null?n:300,p=(C=a.startAngle)!=null?C:0,y=(r=a.endAngle)!=null?r:360,Z=b-f,B=c/2,G=u/2,v=I.getChannelScale("x");let w;if(g.tileData.tilePos){const{tileX:Y,tileWidth:D}=e.getTilePosAndDimensions(g.tileData.zoomLevel,g.tileData.tilePos,d);w=v(Y+D/d)-v(Y)}const V=(o=I.getChannelDomainArray("row"))!=null?o:["___SINGLE_ROW___"],S=u/V.length,X=!st(a.row)||st(a.row)&&typeof a.row.clip>"u"||a.row.clip,W=st(a.y)?(A=a.y)==null?void 0:A.baseline:void 0,R=(s=I.encodedValue("y",W))!=null?s:0,H=g.graphics;if(sT(a)){const Y=I.getGenomicChannel();if(!Y||!Y.field){console.warn("Genomic field is not provided in the specification");return}const D=qH(l,O=>O[Y.field]);[...D.keys()].forEach(O=>{var J;let ee=0;(J=D.get(O))==null||J.forEach(q=>{const $=I.encodedPIXIProperty("color",q),j=I.encodedPIXIProperty("stroke",q),te=I.encodedPIXIProperty("strokeWidth",q),U=I.encodedPIXIProperty("opacity",q),ie=I.encodedPIXIProperty("y",q),me=I.encodedPIXIProperty("width",q,{tileUnitWidth:w}),Ce=I.encodedPIXIProperty("x-start",q,{markWidth:me}),Ze=Ce+me,Ge=I.markVisibility(q,{width:me,zoomLevel:h}),Be=Math.min(Ge,U);if(Be===0||me<=0||ie<=0)return;H.lineStyle(te,ft(j),Be,0);let Ne=[];if(m){const Se=b-(S-ee)/u*Z,Pe=b-(S-ie-ee)/u*Z,ze=Mt(Ce,c,Pe,B,G,p,y),Fe=Ug(Ce,c,p,y),Ue=Ug(Ce+me,c,p,y);H.beginFill(ft($),$==="none"?0:Be),H.moveTo(ze.x,ze.y),H.arc(B,G,Pe,Fe,Ue,!0),H.arc(B,G,Se,Ue,Fe,!1),Ne=Array.from(H.currentPath.points),H.closePath()}else{H.beginFill(ft($),$==="none"?0:Be),H.drawRect(Ce,S-ie-ee,me,ie);const Se=S-ie-ee,Pe=Se+ie;Ne=[Ce,Se,Ce,Pe,Ze,Pe,Ze,Se]}I.getMouseEventModel().addPolygonBasedEvent(q,Ne),ee+=ie})})}else V.forEach(Y=>{const D=I.encodedValue("row",Y);l.filter(E=>{const O=fI(E,a.row);return!O||O===Y}).forEach(E=>{const O=I.encodedPIXIProperty("color",E),J=I.encodedPIXIProperty("stroke",E),ee=I.encodedPIXIProperty("strokeWidth",E),q=I.encodedPIXIProperty("opacity");let $=I.encodedPIXIProperty("y",E),j=I.encodedPIXIProperty("ye",E);typeof j<"u"&&$>j&&([$,j]=[j,$]);const te=I.encodedPIXIProperty("width",E,{tileUnitWidth:w}),U=I.encodedPIXIProperty("x-start",E,{markWidth:te}),ie=U+te;let me;typeof j>"u"?(me=D+S-R-$,j=D+S-R,(st(a.y)&&a.y.flip||a.flipY)&&(j=me,me=D)):(me=D+S-j,j=D+S-$),X&&(me=Math.max(D,me),me=Math.min(me,D+S),j=Math.max(D,j),j=Math.min(j,D+S));const Ce=I.markVisibility(E,{width:te,zoomLevel:h}),Ze=Math.min(Ce,q);if(Ze===0||te===0||j-me===0)return;H.lineStyle(ee,ft(J),Ze,0);let Ge=[];if(m){const Be=b-me/u*Z,Ne=b-j/u*Z,Se=Mt(U,c,Ne,B,G,p,y),Pe=Ug(U,c,p,y),ze=Ug(U+te,c,p,y);H.beginFill(ft(O),O==="none"?0:Ze),H.moveTo(Se.x,Se.y),H.arc(B,G,Ne,Pe,ze,!0),H.arc(B,G,Be,ze,Pe,!1),Ge=Array.from(H.currentPath.points),H.closePath()}else H.beginFill(ft(O),O==="none"?0:Ze),H.drawRect(U,me,te,j-me),Ge=[U,me,U,j,ie,j,ie,me];I.getMouseEventModel().addPolygonBasedEvent(E,Ge)})})}function HQe(e,g,I,i){const n=e.visualPropertyByChannel("x",I),C=e.visualPropertyByChannel("xe",I),r=e.visualPropertyByChannel("size",I);switch(g){case"width":return r??(C?C-n:i==null?void 0:i.tileUnitWidth);case"x-start":return i!=null&&i.markWidth?C?(n+C-(i==null?void 0:i.markWidth))/2:n-(i==null?void 0:i.markWidth)/2:void 0;default:return}}function TQe(e,g,I,i){var n,C,r,o,A,s;const a=i.spec(),l=i.data(),[c,u]=g.dimensions,d=a.layout==="circular",h=(n=a.innerRadius)!=null?n:220,m=(C=a.outerRadius)!=null?C:300,f=(r=a.startAngle)!=null?r:0,b=(o=a.endAngle)!=null?o:360,p=m-h,y=c/2,Z=u/2,B=g._xScale,G=(A=i.getChannelDomainArray("row"))!=null?A:["___SINGLE_ROW___"],v=u/G.length,w=(s=i.getChannelDomainArray("color"))!=null?s:["___SINGLE_COLOR___"],V=i.encodedPIXIProperty("opacity"),S=i.encodedPIXIProperty("strokeWidth"),X=i.encodedPIXIProperty("stroke"),W=I.graphics;if(sT(a)){const R=i.getGenomicChannel();if(!R||!R.field){console.warn("Genomic field is not provided in the specification");return}const H=qH(l,E=>E[R.field]),Y=[...H.keys()];W.lineStyle(S,ft(X),V,1);const D={};w.forEach(E=>{const O=[],J=[];Y.forEach((q,$,j)=>{var te,U;(U=(te=H.get(q))==null?void 0:te.filter(ie=>fI(ie,a.color)===E))==null||U.forEach(ie=>{const me=+q,Ce=B(me),Ze=BG([i.encodedPIXIProperty("y",ie),0]);typeof D[q]>"u"&&(D[q]=0);const Ge=v-Ze-D[q],Be=v-D[q];if(d){if($===0){const Fe=m-v/u*p,Ue=Mt(Ce,c,Fe,y,Z,f,b);O.push([Ue.x,Ue.y]),J.push([Ue.x,Ue.y])}const Ne=m-Ge/u*p,Se=Mt(Ce,c,Ne,y,Z,f,b);O.push([Se.x,Se.y]);const Pe=m-Be/u*p,ze=Mt(Ce,c,Pe,y,Z,f,b);if(J.push([ze.x,ze.y]),$===j.length-1){const Fe=m-v/u*p,Ue=Mt(Ce,c,Fe,y,Z,f,b);O.push([Ue.x,Ue.y]),J.push([Ue.x,Ue.y])}i.getMouseEventModel().addPointBasedEvent(ie,[ze.x,ze.y,1])}else $===0&&(O.push([Ce,v]),J.push([Ce,v])),O.push([Ce,Ge]),J.push([Ce,Be]),$===j.length-1&&(O.push([Ce,v]),J.push([Ce,v])),i.getMouseEventModel().addPointBasedEvent(ie,[Ce,Ge,1]);D[q]+=Ze})});const ee=i.encodedValue("color",E);W.beginFill(ft(ee),V),W.drawPolygon([...O.reduce((q,$)=>q.concat($)),...J.reverse().reduce((q,$)=>q.concat($))]),W.endFill()})}else G.forEach(R=>{const H=i.encodedValue("row",R);W.lineStyle(S,ft(X),V,0),w.forEach(Y=>{const D=[],E=[],O=m-(H+v)/u*p;let J=0;l.filter(q=>(typeof fI(q,a.row)>"u"||fI(q,a.row)===R)&&(typeof fI(q,a.color)>"u"||fI(q,a.color)===Y)).sort((q,$)=>i.encodedPIXIProperty("x",q)-i.encodedPIXIProperty("x",$)).forEach((q,$,j)=>{const te=A1([BG([i.encodedPIXIProperty("y",q),0]),v]),U=i.encodedPIXIProperty("x",q);if(d){const ie=Mt(U,c,O,y,Z,f,b);D.push([ie.x,ie.y]),$===0&&E.push(ie.x,ie.y);const me=m-(H+v-te)/u*p,Ce=Mt(U,c,me,y,Z,f,b);if(E.push(Ce.x,Ce.y),$===j.length-1){const Ze=m-(H+v)/u*p,Ge=Mt(U,c,Ze,y,Z,f,b);E.push(Ge.x,Ge.y)}i.getMouseEventModel().addPointBasedEvent(q,[Ce.x,Ce.y,1])}else $===0&&(E.push(U,H+v),J=U),E.push(U,H+v-te),$===j.length-1&&(E.push(U,H+v),E.push(J,H+v)),i.getMouseEventModel().addPointBasedEvent(q,[U,H+v-te,1])}),d&&D.length!==0&&E.push(...D.reverse().reduce((q,$)=>q.concat($)));const ee=i.encodedValue("color",Y);W.beginFill(ft(ee),V),W.drawPolygon(E),W.endFill()})})}function NQe(e,g,I,i){var n,C,r,o,A,s;const a=i.spec(),l=i.data(),[c,u]=g.dimensions,d=a.layout==="circular",h=(n=a.innerRadius)!=null?n:220,m=(C=a.outerRadius)!=null?C:300,f=(r=a.startAngle)!=null?r:0,b=(o=a.endAngle)!=null?o:360,p=m-h,y=c/2,Z=u/2,B=g._xScale;let G;if(I.tileData.tilePos){const R=g.tilesetInfo.tile_size,{tileX:H,tileWidth:Y}=g.getTilePosAndDimensions(I.tileData.zoomLevel,I.tileData.tilePos,R);G=B(H+Y/R)-B(H)}const v=(A=i.getChannelDomainArray("row"))!=null?A:["___SINGLE_ROW___"],w=u/v.length,V=st(a.row)&&a.row.padding?a.row.padding:0,S=(s=i.getChannelDomainArray("y"))!=null?s:["___SINGLE_Y_POSITION___"],X=w/S.length-V*2,W=I.graphics;l.forEach(R=>{var H;const Y=i.encodedPIXIProperty("row",R)+V,D=i.encodedPIXIProperty("x",R),E=i.encodedPIXIProperty("color",R),O=i.encodedPIXIProperty("stroke",R),J=i.encodedPIXIProperty("strokeWidth",R),ee=i.encodedPIXIProperty("opacity",R),q=i.encodedPIXIProperty("width",R,{markWidth:G}),$=i.encodedPIXIProperty("height",R,{markHeight:X}),j=i.encodedPIXIProperty("y",R),te=i.markVisibility(R,{width:q,zoomLevel:g._xScale.invert(c)-g._xScale.invert(0)}),U=Math.min(te,ee);if(U===0||$===0||q<=1e-4)return;const[ie,me,Ce,Ze]=[D,D+q,Y+w-j-$/2,Y+w-j+$/2],Ge=(H=i.visualPropertyByChannel("size",R))!=null?H:void 0;W.lineStyle(J,ft(O),U,.5);let Be=[];if(d){if(me<0||c{const S=g.encodedValue("row",V);c.filter(X=>!fI(X,l.row)||fI(X,l.row)===V).forEach(X=>{var W,R,H;const Y=g.encodedPIXIProperty("x",X),D=g.encodedPIXIProperty("xe",X),E=(W=g.encodedPIXIProperty("size",X))!=null?W:D===void 0?w:D-Y,O=g.encodedPIXIProperty("y",X),J=g.encodedPIXIProperty("strokeWidth",X),ee=g.encodedPIXIProperty("stroke",X),q=g.encodedPIXIProperty("color",X),$=g.encodedPIXIProperty("opacity",X);let j=[];if(d){let te=Y||D-E,U=D||Y+E,ie=(te+U)/2;const me=m-(S+G-O)/i*p,Ce=me-w/2,Ze=me+w/2;if(((R=l.style)==null?void 0:R.align)==="right"&&!D&&(te-=E,U-=E,ie-=E),l.mark==="triangleLeft"){const Ne=Mt(U,I,Ce,y,Z,f,b),Se=Mt(te,I,me,y,Z,f,b),Pe=Mt(U,I,Ze,y,Z,f,b),ze=Mt(U,I,Ce,y,Z,f,b);j=[Ne.x,Ne.y,Se.x,Se.y,Pe.x,Pe.y,ze.x,ze.y]}else if(l.mark==="triangleRight"){const Ne=Mt(te,I,Ce,y,Z,f,b),Se=Mt(U,I,me,y,Z,f,b),Pe=Mt(te,I,Ze,y,Z,f,b),ze=Mt(te,I,Ce,y,Z,f,b);j=[Ne.x,Ne.y,Se.x,Se.y,Pe.x,Pe.y,ze.x,ze.y]}else if(l.mark==="triangleBottom"){te=ie-E/2,U=ie+E/2;const Ne=Mt(te,I,Ze,y,Z,f,b),Se=Mt(U,I,Ze,y,Z,f,b),Pe=Mt(ie,I,Ce,y,Z,f,b),ze=Mt(te,I,Ze,y,Z,f,b);j=[Ne.x,Ne.y,Se.x,Se.y,Pe.x,Pe.y,ze.x,ze.y]}const Ge=g.markVisibility(X,{width:U-te,zoomLevel:u}),Be=Math.min(Ge,$);e.lineStyle(J,ft(ee),U-te>2?Be:0,0),e.beginFill(ft(q),Be),e.drawPolygon(j),e.endFill()}else{let te=Y||D-E,U=D||Y+E,ie=te+(U-te)/2;const me=S+G-O,Ce=S+G-O-w/2,Ze=S+G-O+w/2;((H=l.style)==null?void 0:H.align)==="right"&&!D&&(te-=E,U-=E,ie-=E),j={triangleLeft:[U,Ce,te,me,U,Ze,U,Ce],triangleRight:[te,Ce,U,me,te,Ze,te,Ce],triangleBottom:[te,Ce,U,Ce,ie,Ze,te,Ce]}[l.mark];const Ge=g.markVisibility(X,{width:U-te,zoomLevel:u}),Be=Math.min(Ge,$);e.lineStyle(J,ft(ee),U-te>2?Be:0,.5),e.beginFill(ft(q),Be),e.drawPolygon(j),e.endFill()}g.getMouseEventModel().addPolygonBasedEvent(X,j)})})}const yA={fontSize:"12px",fontFamily:"sans-serif",fontWeight:"normal",fill:"black",background:"white",lineJoin:"round",stroke:"#ffffff",strokeThickness:0};function KQe(e,g,I,i){var n,C,r,o,A,s,a,l,c,u;const d=i.spec(),h=i.data(),[m,f]=g.dimensions,b=d.layout==="circular",p=(n=d.innerRadius)!=null?n:220,y=(C=d.outerRadius)!=null?C:300,Z=(r=d.startAngle)!=null?r:0,B=(o=d.endAngle)!=null?o:360,G=y-p,v=m/2,w=f/2,V=(A=i.getChannelDomainArray("row"))!=null?A:["___SINGLE_ROW___"],S=f/V.length,X=(a=(s=d.style)==null?void 0:s.dx)!=null?a:0,W=(c=(l=d.style)==null?void 0:l.dy)!=null?c:0,R=(u=d.style)!=null&&u.textAnchor?d.style.textAnchor:"middle";if(sT(d)){if(b)return;const H=I.graphics,Y=i.getGenomicChannel();if(!Y||!Y.field){console.warn("Genomic field is not provided in the specification");return}const D=qH(h,O=>O[Y.field]);[...D.keys()].forEach(O=>{var J;let ee=0;(J=D.get(O))==null||J.forEach(q=>{var $,j,te,U,ie,me,Ce,Ze;const Ge=i.encodedPIXIProperty("text",q),Be=i.encodedPIXIProperty("color",q),Ne=i.encodedPIXIProperty("x",q)+X,Se=i.encodedPIXIProperty("xe",q)+X,Pe=i.encodedPIXIProperty("x-center",q)+X,ze=i.encodedPIXIProperty("y",q)+W,Fe=i.encodedPIXIProperty("size",q),Ue=i.encodedPIXIProperty("stroke",q),_e=i.encodedPIXIProperty("strokeWidth",q),ot=i.encodedPIXIProperty("opacity",q);if(Pe<0||Pe>m||g.textsBeingUsed>1e3)return;const Zt={...yA,fontSize:Fe??(($=d.style)!=null&&$.textFontSize?`${(j=d.style)==null?void 0:j.textFontSize}px`:yA.fontSize),stroke:(U=Ue??((te=d.style)==null?void 0:te.textStroke))!=null?U:yA.stroke,strokeThickness:(me=_e??((ie=d.style)==null?void 0:ie.textStrokeWidth))!=null?me:yA.strokeThickness,fontWeight:(Ze=(Ce=d.style)==null?void 0:Ce.textFontWeight)!=null?Ze:yA.fontWeight},nt=new e.libraries.PIXI.TextStyle(Zt);let Te;g.textGraphics.length>g.textsBeingUsed?(Te=g.textGraphics[g.textsBeingUsed],Te.style.fill=Be,Te.visible=!0,Te.text=Ge,Te.alpha=1):(Te=new e.libraries.PIXI.Text(Ge,{...Zt,fill:Be}),g.textGraphics.push(Te));const se=e.libraries.PIXI.TextMetrics.measureText(Ge,nt);g.textsBeingUsed++;const ye=i.markVisibility(q,{...se,zoomLevel:g._xScale.invert(m)-g._xScale.invert(0)}),Xe=Math.min(ye,ot);if(!Ge||Xe===0){g.textsBeingUsed--,Te.visible=!1;return}Te.alpha=Xe,Te.resolution=8,Te.updateText(),Te.texture.baseTexture.scaleMode=e.libraries.PIXI.SCALE_MODES.LINEAR;const K=new e.libraries.PIXI.Sprite(Te.texture);K.x=Ne,K.y=S-ze-ee,K.width=Se-Ne,K.height=ze,H.addChild(K),ee+=ze})})}else V.forEach(H=>{const Y=I.graphics,D=i.encodedValue("row",H);h.filter(E=>!fI(E,d.row)||fI(E,d.row)===H).forEach(E=>{var O,J,ee,q,$,j,te,U;const ie=i.encodedPIXIProperty("text",E),me=i.encodedPIXIProperty("color",E),Ce=i.encodedPIXIProperty("x-center",E)+X,Ze=i.encodedPIXIProperty("y",E)+W,Ge=i.encodedPIXIProperty("size",E),Be=i.encodedPIXIProperty("stroke",E),Ne=i.encodedPIXIProperty("strokeWidth",E),Se=i.encodedPIXIProperty("opacity",E);if(Ce<0||Ce>m||g.textsBeingUsed>1e3)return;const Pe={...yA,fontSize:Ge??((O=d.style)!=null&&O.textFontSize?`${(J=d.style)==null?void 0:J.textFontSize}px`:yA.fontSize),stroke:(q=Be??((ee=d.style)==null?void 0:ee.textStroke))!=null?q:yA.stroke,strokeThickness:(j=Ne??(($=d.style)==null?void 0:$.textStrokeWidth))!=null?j:yA.strokeThickness,fontWeight:(U=(te=d.style)==null?void 0:te.textFontWeight)!=null?U:yA.fontWeight},ze=new e.libraries.PIXI.TextStyle(Pe);let Fe;g.textGraphics.length>g.textsBeingUsed?(Fe=g.textGraphics[g.textsBeingUsed],Fe.style.fill=me,Fe.visible=!0,Fe.text=ie,Fe.alpha=1):(Fe=new e.libraries.PIXI.Text(ie,{...Pe,fill:me}),g.textGraphics.push(Fe));const Ue=e.libraries.PIXI.TextMetrics.measureText(ie,ze);g.textsBeingUsed++;const _e=i.markVisibility(E,{...Ue,zoomLevel:g._xScale.invert(m)-g._xScale.invert(0)}),ot=Math.min(_e,Se);if(!ie||ot===0){g.textsBeingUsed--,Fe.visible=!1;return}Fe.alpha=ot,Fe.anchor.y=.5,Fe.anchor.x=R==="middle"?.5:R==="start"?0:1;let Zt=[];if(b){const nt=y-(D+S-Ze)/f*G,Te=Mt(Ce,m,nt,v,w,Z,B);Fe.x=Te.x,Fe.y=Te.y,Fe.resolution=4;const se=Ue.width/(2*nt*Math.PI)*m;let[ye,Xe]=[Ce-se/2,Ce+se/2];if(ye<0){const he=-ye;ye=0,Xe+=he}else if(Xe>m){const he=Xe-m;Xe=m,ye-=he}const K=[],T=[],k=[];for(let he=Xe;he>=ye;he-=se/10){const Ve=Mt(he,m,nt,v,w,Z,B);K.push(new e.libraries.PIXI.Point(Ve.x,Ve.y));const De=Mt(he,m,nt+Ue.height/2,v,w,Z,B),qe=Mt(he,m,nt-Ue.height/2,v,w,Z,B);T.push(De.x,De.y),he===Xe&&k.push(De.y,De.x),k.push(qe.y,qe.x)}Fe.updateText();const ge=new e.libraries.PIXI.SimpleRope(Fe.texture,K);ge.alpha=ot,Y.addChild(ge),k.reverse(),Zt=T.concat(k)}else{Fe.position.x=Ce,Fe.position.y=D+S-Ze,Y.addChild(Fe);const{height:nt,width:Te}=Ue,se=Fe.position.y-nt/2,ye=se+nt;let Xe=0,K=0;R==="start"?(Xe=Ce,K=Ce+Te):R==="middle"?(Xe=Ce-Te/2,K=Ce+Te/2):(Xe=Ce-Te,K=Ce),Zt=[Xe,se,Xe,ye,K,ye,K,se]}i.getMouseEventModel().addPolygonBasedEvent(E,Zt)})})}function DQe(e,g,I,i){var n,C,r,o,A,s,a,l;const c=i.spec(),u=i.data(),[d,h]=g.dimensions,m=c.layout==="circular",f=(n=c.innerRadius)!=null?n:220,b=(C=c.outerRadius)!=null?C:300,p=(r=c.startAngle)!=null?r:0,y=(o=c.endAngle)!=null?o:360,Z=b-f,B=d/2,G=h/2,v=(A=i.getChannelDomainArray("row"))!=null?A:["___SINGLE_ROW___"],w=h/v.length,V=(s=c.style)==null?void 0:s.dashed,S=(a=c.style)==null?void 0:a.linePattern,X=(l=c.style)==null?void 0:l.curve,W=I.graphics;v.forEach(R=>{const H=i.encodedValue("row",R);u.filter(Y=>!fI(Y,c.row)||fI(Y,c.row)===R).forEach(Y=>{const D=i.encodedPIXIProperty("x",Y),E=i.encodedPIXIProperty("xe",Y),O=i.encodedPIXIProperty("y",Y),J=i.encodedPIXIProperty("color",Y),ee=i.encodedPIXIProperty("strokeWidth",Y),q=i.encodedPIXIProperty("opacity",Y),$=i.markVisibility(Y,{width:E-D,zoomLevel:g._xScale.invert(d)-g._xScale.invert(0)}),j=Math.min($,q);if(W.lineStyle(ee,ft(J),j,.5),!E&&(!c.y||!("field"in c.y))){if(m)return;if(V){const[te,U]=V;let ie=0;do W.moveTo(D,ie),W.lineTo(D,ie+te),ie+=te+U;while(ie{const H=I.encodedValue("row",R);d.filter(Y=>!fI(Y,u.row)||fI(Y,u.row)===R).forEach(Y=>{var D,E,O,J,ee;let q=I.encodedPIXIProperty("x",Y),$=I.encodedPIXIProperty("xe",Y),j=I.encodedPIXIProperty("x1",Y),te=I.encodedPIXIProperty("x1e",Y);const U=I.encodedPIXIProperty("y",Y),ie=I.encodedPIXIProperty("ye",Y),me=I.encodedPIXIProperty("stroke",Y),Ce=I.encodedPIXIProperty("strokeWidth",Y),Ze=I.encodedPIXIProperty("color",Y),Ge=I.encodedPIXIProperty("opacity",Y);typeof $<"u"&&([q,$]=[q,$].sort((ze,Fe)=>ze-Fe)),typeof j<"u"&&typeof te<"u"&&([j,te]=[j,te].sort((ze,Fe)=>ze-Fe));const Be=typeof $<"u"&&typeof j<"u"&&typeof te<"u"&&Math.abs(q-$)>.1&&Math.abs(j-te)>.1;if(!Be&&$===void 0&&!qn(u)){if(j===void 0&&te===void 0)return;$=j!==void 0?j:te}!Be&&Math.abs(q-$)<=.1&&Math.abs(j-te)<=.1&&(q=(q+$)/2,$=(j+te)/2),e.lineStyle(Ce,ft(me),Ge,.5);const Ne=st(u.y)&&u.y.flip||u.flipY,Se=(D=u.baselineY)!=null?D:H+(Ne?0:V);let Pe=[];if(Be){e.beginFill(ft(Ze==="none"?"white":Ze),Ze==="none"?0:Ge);let[ze,Fe,Ue,_e]=[q,$,j,te];if([ze,Fe,Ue,_e]=[ze,Fe,Ue,_e].sort((ot,Zt)=>ot-Zt),ze>h||_e<0||Math.abs(_e-ze)<.5)return;if(f){if(ze<0||_e>h)return;const ot=p-H/m*B,Zt=Mt(ze,h,ot,G,v,y,Z),nt=Mt(Fe,h,ot,G,v,y,Z),Te=Mt(Ue,h,ot,G,v,y,Z),se=Mt(_e,h,ot,G,v,y,Z);e.moveTo(Zt.x,Zt.y),e.bezierCurveTo(G,v,G,v,se.x,se.y),e.arc(G,v,p,ic(se.x,se.y,G,v),ic(Te.x,Te.y,G,v),!1),e.bezierCurveTo(G,v,G,v,nt.x,nt.y),e.arc(G,v,p,ic(nt.x,nt.y,G,v),ic(Zt.x,Zt.y,G,v),!1),Pe=Array.from(e.currentPath.points),e.endFill()}else e.moveTo(ze,Se),!((E=u.style)!=null&&E.linkStyle)||((O=u.style)==null?void 0:O.linkStyle)==="circular"?(e.arc((ze+_e)/2,Se,(_e-ze)/2,-Math.PI,Math.PI,!1),e.arc((Fe+Ue)/2,Se,(Ue-Fe)/2,Math.PI,-Math.PI,!0),Pe=Array.from(e.currentPath.points),e.closePath()):(e.lineTo(Ue,H+V),e.bezierCurveTo(Ue+(Fe-Ue)/3,H+V-(Fe-Ue)/2,Ue+(Fe-Ue)/3*2,H+V-(Fe-Ue)/2,Fe,H+V),e.lineTo(_e,H+V),e.bezierCurveTo(ze+(_e-ze)/3*2,H+V-(_e-ze)/2,ze+(_e-ze)/3,H+V-(_e-ze)/2,ze,H+V),Pe=Array.from(e.currentPath.points),e.endFill());I.getMouseEventModel().addPolygonBasedEvent(Y,Pe)}else{const ze=(q+$)/2;if(e.beginFill(ft("white"),0),f){if(q<0||$>h)return;if(((J=u.style)==null?void 0:J.linkStyle)==="straight"){const Fe=p-H/m*B,Ue=Mt(q,h,Fe,G,v,y,Z),_e=Mt($,h,Fe,G,v,y,Z),ot=Ue.x,Zt=Ue.y,nt=_e.x,Te=_e.y;e.moveTo(ot,Zt),e.lineTo(nt,Te);const se=100;Pe=Array.from({length:se},(Xe,K)=>({x:(nt-ot)/(se-1)*K+ot,y:(Te-Zt)/(se-1)*K+Zt})).flatMap(Xe=>[Xe.x,Xe.y])}else{const Fe=p-H/m*B,Ue=Mt(q,h,Fe,G,v,y,Z),_e=Mt($,h,Fe,G,v,y,Z),ot=Ue.x,Zt=Ue.y,nt=Ue.x,Te=Ue.y,se=h/2,ye=m/2,Xe=_e.x,K=_e.y;e.moveTo(ot,Zt);const T=new ti(ot,Zt,nt,Te,se,ye,Xe,K);T.getLUT(14).forEach(he=>e.lineTo(he.x,he.y)),Pe=T.getLUT(1e3).flatMap(he=>[he.x,he.y])}}else if(((ee=u.style)==null?void 0:ee.linkStyle)==="elliptical"){if(!(0<=q&&q<=h)&&!(0<=$&&$<=h))return;const Fe=[],Ue=st(u.y);for(let _e=0;_e<=X;_e++){const ot=Math.PI*(_e/X),Zt=($-q)/2*Math.cos(ot)+(q+$)/2;let nt=Se-U*Math.sin(ot)*(Ue?1:Math.min($-q+h*S,h)/h)*(Ne?-1:1);if(typeof U<"u"&&typeof ie<"u"){const Te=Math.abs(ie-U),se=ie>U;nt=U-Te*Math.sin(ot)*(se?-1:1)}if(_e===0)if(W){const Te=Ne?Se-m:Se;e.moveTo(Zt,Te),Fe.push({x:Zt,y:Te}),e.lineTo(Zt,nt)}else e.moveTo(Zt,nt);else e.lineTo(Zt,nt);if(Fe.push({x:Zt,y:nt}),_e===X&&W){const Te=Ne?Se-m:Se;e.lineTo(Zt,Te),Fe.push({x:Zt,y:Te})}}Pe=Fe.flatMap(_e=>[_e.x,_e.y])}else{if($<0||q>h)return;e.arc(ze,Se,($-q)/2,-Math.PI,Math.PI),Pe=Array.from(e.currentPath.points),e.closePath()}I.getMouseEventModel().addLineBasedEvent(Y,Pe)}})})}function FQe(e,g,I){return[...e.slice(0,g),I,...e.slice(g)]}function EQe(e){const g=[];for(let I=0;Itypeof g=="number")}function dpe(e){return upe(e,g=>typeof g=="string")}function MQe(e,g,I){PQe(e,g,I),zQe(e,g,I)}function zQe(e,g,I){var i,n,C,r;const o=g.spec();if(!st(o.row)||o.row.grid!==!0)return;const[A,s]=e.position,[a,l]=e.dimensions,c=g.spec().layout==="circular",u=(i=o.innerRadius)!=null?i:220,d=(n=o.outerRadius)!=null?n:300,h=(C=o.startAngle)!=null?C:0,m=(r=o.endAngle)!=null?r:360,f=d-u,b=a/2,p=l/2,y=g.getChannelDomainArray("row");if(!y)return;const Z=l/y.length;if(c&&f<=20||!c&&Z<=20)return;const B=e.pBackground,G=I.axis.gridStrokeWidth;y.forEach(v=>{const w=g.encodedValue("row",v);if(c){const V=w+Z/2,S=d-V/l*f,X=S+G/2,W=S-G/2,R=Mt(0,a,W,b,p,h,m),H=Ug(0,a,h,m),Y=Ug(a,a,h,m);B.lineStyle(G,ft("black"),0,.5),B.beginFill(ft(I.axis.gridColor),1),B.moveTo(A+R.x,s+R.y),B.arc(A+b,s+p,W,H,Y,!0),B.arc(A+b,s+p,X,Y,H,!1),B.closePath()}else{B.lineStyle(G,ft(I.axis.gridColor),1,.5);const V=s+w+Z/2;B.moveTo(A,V),B.lineTo(A+a,V)}})}function PQe(e,g,I){var i,n,C,r,o;const A=g.spec();if(!st(A.y)||A.y.grid!==!0)return;const[s,a]=e.position,[l,c]=e.dimensions,u=s,d=s+l,h=g.spec().layout==="circular",m=(i=A.innerRadius)!=null?i:220,f=(n=A.outerRadius)!=null?n:300,b=(C=A.startAngle)!=null?C:0,p=(r=A.endAngle)!=null?r:360,y=f-m,Z=l/2,B=c/2,G=(o=g.getChannelDomainArray("row"))!=null?o:["___SINGLE_ROW___"],v=c/G.length;if(!dpe(G))return;const w=g.getChannelScale("y"),V=g.getChannelDomainArray("y");if(!w||!V||!aU(V)||h&&v/c*y<=20||!h&&v<=20)return;const S=e.pBackground,X=I.axis.gridStrokeWidth;G.forEach(W=>{const R=g.encodedValue("row",W),H=h?v/c*y:v,Y=Math.max(Math.ceil(H/40),1);let D=w.ticks(Y).filter(E=>V[0]<=E&&E<=V[1]);D.length===1&&(D=w.ticks(Y+1).filter(E=>V[0]<=E&&E<=V[1])),h?D.forEach(E=>{const O=w(E),J=f-(R+v-O)/c*y,ee=J+X/2,q=J-X/2,$=Mt(0,l,q,Z,B,b,p),j=Ug(0,l,b,p),te=Ug(l,l,b,p);S.lineStyle(X,ft("black"),0,.5),S.beginFill(ft(I.axis.gridColor),1),S.moveTo(s+$.x,a+$.y),S.arc(s+Z,a+B,q,j,te,!0),S.arc(s+Z,a+B,ee,te,j,!1),S.closePath()}):(S.lineStyle(X,ft(I.axis.gridColor),1,.5),D.forEach(E=>{var O;const J=a+R+v-w(E);if(I.axis.gridStrokeType==="solid")S.moveTo(u,J),S.lineTo(d,J);else if(I.axis.gridStrokeType==="dashed"){const[ee,q]=(O=I.axis.gridStrokeDash)!=null?O:[1,1];for(let $=u;$=V;Y-=w/10){const D=Mt(Y,a,b-v.height/2,h,m,u,d);X.push(new e.libraries.PIXI.Point(D.x,D.y))}const W=Ug(V,a,u,d),R=Ug(S+p,a,u,d);f.lineStyle(1,ft("red"),0,.5),f.beginFill(ft(n.track.titleBackground),.5),f.moveTo(y.x,y.y),f.arc(h,m,b-v.height,W,R,!0),f.arc(h,m,b,R,W,!1),f.closePath(),B.updateText();const H=new e.libraries.PIXI.SimpleRope(B.texture,X);f.addChild(H)}function OQe(e,g,I){var i,n,C,r;const o=e.pBorder,[A,s]=e.position,[a,l]=e.dimensions;o.lineStyle((n=(i=g.spec().style)==null?void 0:i.outlineWidth)!=null?n:1,ft((r=(C=g.spec().style)==null?void 0:C.outline)!=null?r:I.track.outline),1,.5),o.beginFill(ft("white"),0),o.drawRect(A,s,a,l);const c=g.spec().x;o.lineStyle(1,ft(I.axis.baselineColor),1,.5),st(c)&&c.axis==="top"?(o.moveTo(A,s),o.lineTo(A+a,s)):st(c)&&c.axis==="bottom"&&(o.moveTo(A,s+l),o.lineTo(A+a,s+l))}function _Qe(e,g,I,i,n){if(!g.gLegend)return;g.gLegend.selectAll(".brush").remove();const C=i.spec(),r={offsetRight:0};if(st(C.color)&&C.color.legend)switch(C.color.type){case"nominal":LQe(e,g,I,i,n);break;case"quantitative":Eee(e,g,I,i,n,"color",r);break}if(st(C.stroke)&&C.stroke.legend)switch(C.stroke.type){case"quantitative":Eee(e,g,I,i,n,"stroke",r);break}}function Eee(e,g,I,i,n,C,r){const o=i.spec(),A=o[C];if(!st(A)||A.type!=="quantitative"||!A.legend)return;const[s,a]=g.position,[l,c]=g.dimensions,u=80,d=c-2>110?110:Math.max(c-2,40-2),h={top:10,left:55,width:20,height:d-20},m=s+l-u-1-r.offsetRight,f=a+1,b=i.getChannelScale(C),p=i.getChannelDomainArray(C);if(!b||!p)return;const y=g.pBorder;if(y.beginFill(ft(n.legend.background),n.legend.backgroundOpacity),y.lineStyle(1,ft(n.legend.backgroundStroke),n.legend.backgroundOpacity,0),y.drawRect(m,f,u,d),A.title){const H=A.title,Y=Hs({color:n.legend.labelColor,size:n.legend.labelFontSize,fontWeight:n.legend.labelFontWeight,fontFamily:n.legend.labelFontFamily}),D=new e.libraries.PIXI.Text(H,{...Y,fontWeight:"bold"});D.anchor.x=0,D.anchor.y=0,D.position.x=m+10,D.position.y=f+10;const E=new e.libraries.PIXI.TextStyle({...Y,fontWeight:"bold"}),O=e.libraries.PIXI.TextMetrics.measureText(H,E);y.addChild(D),h.top+=O.height+4,h.height-=O.height+4}const[Z,B]=p,G=B-Z,v=st(A)&&A.scaleOffset?A.scaleOffset:[0,1];[...Array(h.height).keys()].forEach(H=>{let Y;const D=Array.from(v).sort();if(H/h.height>=D[1])Y=B;else if(H/h.height<=D[0])Y=Z;else{const E=zd().domain([h.height*D[0],h.height*D[1]]).range([0,h.height]);Y=zd().domain([0,h.height]).range([Z,B])(E(H))}y.beginFill(ft(b(Y)),1),y.lineStyle(1,ft(n.legend.backgroundStroke),0,.5),y.drawRect(m+h.left,f+h.top+h.height-H,h.width,1)});const w=4;g.colorBrushes=g.gLegend.append("g").attr("class",C).selectAll(".brush").data(v.map((H,Y)=>({y:H,id:Y}))).enter().append("rect").attr("class","brush").attr("pointer-events","all").attr("cursor","ns-resize").attr("transform",H=>`translate(${m+h.left}, ${f+h.top-w/2+h.height-h.height*H.y})`).attr("width",`${h.width}px`).attr("height",`${w}px`).attr("fill","lightgrey").attr("stroke","black").attr("stroke-width","0.5px").call(e.libraries.d3Drag.drag().on("start",H=>{g.startEvent=H.sourceEvent}).on("drag",(H,Y)=>{if(A&&A.scaleOffset){const D=H.sourceEvent,E=g.startEvent.clientY-D.clientY,O=[A.scaleOffset[0],A.scaleOffset[1]];Y.id===0?O[0]+=E/h.height:O[1]+=E/h.height,O[0]=Math.min(1,Math.max(0,O[0])),O[1]=Math.min(1,Math.max(0,O[1])),g.updateScaleOffsetFromOriginalSpec(o._renderingId,O,C),g.shareScaleOffsetAcrossTracksAndTiles(O,C),g.draw(),g.startEvent=H.sourceEvent}}));const V=Math.max(Math.ceil(h.height/30),2);let S=b.ticks(V).filter(H=>p[0]<=H&&H<=p[1]);S.length===1&&(S=b.ticks(V+1).filter(H=>p[0]<=H&&H<=p[1]));const X=1;y.lineStyle(X,ft(n.legend.tickColor),1,.5);const W=Hs({color:n.legend.labelColor,size:n.legend.labelFontSize,fontWeight:n.legend.labelFontWeight,fontFamily:n.legend.labelFontFamily}),R=m+h.left;S.forEach(H=>{let Y=f+h.top+h.height-(H-Z)/G*h.height;Y===f+h.top?Y+=X/2:Y===f+h.top+h.height&&(Y-=X/2),y.moveTo(R-3,Y),y.lineTo(R,Y);const D=new e.libraries.PIXI.Text(H,W);D.anchor.x=1,D.anchor.y=.5,D.position.x=R-6,D.position.y=Y,y.addChild(D)}),r.offsetRight=l-m}function LQe(e,g,I,i,n){var C,r,o,A,s;const a=i.spec();if(!st(a.color)||a.color.type!=="nominal"||!a.color.legend)return;const l=(C=i.getChannelDomainArray("color"))!=null?C:["___SINGLE_COLOR___"];if(l.length===0)return;const c=a.color.domain,u=a.color.range,d=g.displayedLegends,h=G=>typeof G=="string"?G:G.join();if(d.find(G=>h(G.domain)===h(c)&&h(G.range)===h(u)))return;d.push({domain:c,range:u});const m=g.pBorder,f=10,b=4;let p=b,y=0;const Z=[],B=Hs({color:n.legend.labelColor,size:n.legend.labelFontSize,fontWeight:n.legend.labelFontWeight,fontFamily:n.legend.labelFontFamily});if((r=a.style)!=null&&r.inlineLegend)l.map(G=>G).reverse().forEach(G=>{if(y>g.dimensions[0])return;const v=i.encodedValue("color",G),w=new e.libraries.PIXI.Text(G,B);w.anchor.x=1,w.anchor.y=0,w.position.x=g.position[0]+g.dimensions[0]-y-f,w.position.y=g.position[1]+b,m.addChild(w);const V=new e.libraries.PIXI.TextStyle(B),S=e.libraries.PIXI.TextMetrics.measureText(G,V);p{if(p>g.dimensions[1])return;const v=i.encodedValue("color",G),w=new e.libraries.PIXI.Text(G,B);w.anchor.x=1,w.anchor.y=0,w.position.x=g.position[0]+g.dimensions[0]-f,w.position.y=g.position[1]+p,m.addChild(w);const V=new e.libraries.PIXI.TextStyle(B),S=e.libraries.PIXI.TextMetrics.measureText(G,V);y{m.lineStyle(1,ft("black"),0,0),m.beginFill(ft(G.color),1),m.drawCircle(G.x,G.y,4)})}function UQe(e,g,I,i,n){var C;const r=i.spec();if(!st(r.row)||r.row.type!=="nominal"||!r.row.legend)return;const o=(C=i.getChannelDomainArray("row"))!=null?C:["___SINGLE_ROW___"];if(o.length===0)return;const A=g.pBorder,s=4,a=2,l=Hs({color:n.legend.labelColor,size:n.legend.labelFontSize,fontWeight:n.legend.labelFontWeight,fontFamily:n.legend.labelFontFamily});o.forEach(c=>{const u=i.encodedValue("row",c),d=new e.libraries.PIXI.Text(c,l);d.anchor.x=0,d.anchor.y=0,d.position.x=g.position[0]+s,d.position.y=g.position[1]+u+a,A.addChild(d);const h=new e.libraries.PIXI.TextStyle(l),m=e.libraries.PIXI.TextMetrics.measureText(c,h);A.beginFill(ft(n.legend.background),n.legend.backgroundOpacity),A.lineStyle(1,ft(n.legend.backgroundStroke),0,0),A.drawRect(g.position[0]+1,g.position[1]+u+1,m.width+s*2,m.height+a*2)})}const bM=8,pZ=6;function QQe(e,g,I,i,n){var C;const r=i.spec(),o=r.layout==="circular",A=i.getChannelDomainArray("y"),s=i.getChannelRangeArray("y");if(o||!i.isShowYAxis()||!A||!s||!aU(A))return;const[a,l]=g.dimensions,[c,u]=g.position,d=(C=i.getChannelDomainArray("row"))!=null?C:["___SINGLE_ROW___"];if(!dpe(d))return;const h=l/d.length;if(h<=20)return;const m=i.spec().y,f=!(st(m)&&"axis"in m&&m.axis==="right"),b=zd().domain(A).range(s),p=g.pBorder;d.forEach(y=>{const Z=i.encodedValue("row",y),B=f?c:c+a,G=u+Z;p.lineStyle(1,ft(n.axis.baselineColor),1,.5),p.moveTo(B,G),p.lineTo(B,G+h);const v=Math.max(Math.ceil(h/40),1);let w=b.ticks(v).filter(X=>A[0]<=X&&X<=A[1]);w.length===1&&(w=b.ticks(v+1).filter(X=>A[0]<=X&&X<=A[1])),p.lineStyle(1,ft(n.axis.tickColor),1,.5);let V=f?B+pZ:B-pZ;w.forEach(X=>{const W=b(X);p.moveTo(B,G+h-W),p.lineTo(V,G+h-W)}),V=f?B+bM:B-bM,p.moveTo(B,G),p.lineTo(V,G),p.moveTo(B,G+h),p.lineTo(V,G+h);const S=Hs({color:n.axis.labelColor,size:n.axis.labelFontSize,fontFamily:n.axis.labelFontFamily,fontWeight:n.axis.labelFontWeight});w.forEach(X=>{const W=b(X);V=f?B+pZ*2:B-pZ*2;const R=new e.libraries.PIXI.Text(X,S);R.anchor.x=f?0:1,R.anchor.y=W===0?.9:.5,R.position.x=V,R.position.y=G+h-W,r.orientation==="vertical"&&(R.anchor.x=f?1:0,R.scale.x*=-1),p.addChild(R)})})}function jQe(e,g,I,i,n){var C,r,o,A,s;const a=i.spec(),l=a.layout==="circular",c=i.getChannelDomainArray("y"),u=i.getChannelRangeArray("y");if(!l||!i.isShowYAxis()||!c||!u||!aU(c))return;const[d,h]=g.dimensions,m=(C=a.innerRadius)!=null?C:220,f=(r=a.outerRadius)!=null?r:300,b=f-m,p=(o=a.startAngle)!=null?o:0,y=(A=a.endAngle)!=null?A:360,Z=d/2,B=h/2,G=(s=i.getChannelDomainArray("row"))!=null?s:["___SINGLE_ROW___"],v=h/G.length;if(v/h*b<=20)return;const w=i.spec().y,V=!(st(w)&&"axis"in w&&w.axis==="right"),S=zd().domain(c).range(u),X=I.graphics;G.forEach(W=>{const R=i.encodedValue("row",W),H=f-(R+v)/h*b,Y=f-R/h*b,D=Mt(V?0:d,d,H,Z,B,p,y),E=Mt(V?0:d,d,Y,Z,B,p,y);X.lineStyle(1,ft(n.axis.baselineColor),1,.5),X.moveTo(D.x,D.y),X.lineTo(E.x,E.y);const O=j=>pZ*d/2/Math.PI/j,J=j=>bM*d/2/Math.PI/j,ee=v/h*b,q=Math.max(Math.ceil(ee/40),1);let $=S.ticks(q).filter(j=>c[0]<=j&&j<=c[1]);$.length===1&&($=S.ticks(q+1).filter(j=>c[0]<=j&&j<=c[1])),X.lineStyle(1,ft(n.axis.tickColor),1,.5),$.forEach(j=>{const te=S(j),U=f-(R+v-te)/h*b,ie=V?0:d-O(U),me=V?O(U):d,Ce=Mt(ie,d,U,Z,B,p,y),Ze=Ug(ie,d,p,y),Ge=Ug(me,d,p,y);X.moveTo(Ce.x,Ce.y),X.arc(Z,B,U,Ze,Ge,!0),X.arc(Z,B,U,Ge,Ze,!1),X.closePath()});{const j=V?0:d-J(m),te=V?J(m):d,U=Ug(j,d,p,y),ie=Ug(te,d,p,y);X.moveTo(D.x,D.y),X.arc(Z,B,m,U,ie,!0),X.arc(Z,B,m,ie,U,!1),X.closePath()}{const j=V?0:d-J(f),te=V?J(f):d,U=Ug(j,d,p,y),ie=Ug(te,d,p,y);X.moveTo(E.x,E.y),X.arc(Z,B,f,U,ie,!0),X.arc(Z,B,f,ie,U,!1),X.closePath()}$.forEach(j=>{const te=S(j),U=f-(R+v-te)/h*b,ie=Mt(O(U)*2,d,U,Z,B,p,y),me=Hs({color:n.axis.labelColor,size:n.axis.labelFontSize,fontFamily:n.axis.labelFontFamily,fontWeight:n.axis.labelFontWeight}),Ce=new e.libraries.PIXI.Text(j,me);Ce.anchor.x=V?1:0,Ce.anchor.y=.5,Ce.position.x=ie.x,Ce.position.y=ie.y,Ce.resolution=4;const Ze=new e.libraries.PIXI.TextStyle(me),Be=e.libraries.PIXI.TextMetrics.measureText(Ce.text,Ze).width/(2*U*Math.PI)*d*360/(y-p),Ne=V?O(U)*2:d-O(U)*2-Be,Se=V?O(U)*2+Be:d-O(U)*2,Pe=[];for(let Fe=Se;Fe>=Ne;Fe-=Be/10){const Ue=Mt(Fe,d,U,Z,B,p,y);Pe.push(new e.libraries.PIXI.Point(Ue.x,Ue.y))}Ce.updateText();const ze=new e.libraries.PIXI.SimpleRope(Ce.texture,Pe);X.addChild(ze)})})}function $Qe(e,g,I){var i,n,C,r,o,A,s,a,l,c,u,d;const h=g.spec(),[m,f]=e.position,[b,p]=e.dimensions,y=(i=h.innerRadius)!=null?i:220,Z=(n=h.outerRadius)!=null?n:300,B=(C=h.startAngle)!=null?C:0,G=(r=h.endAngle)!=null?r:360,v=m+b/2,w=f+p/2,V=Mt(0,b,y,v,w,B,G),S=Ug(0,b,B,G),X=Ug(b,b,B,G),W=e.pBackground;h.layout==="circular"&&h.mark==="withinLink"||(W.lineStyle((o=h.style)!=null&&o.outlineWidth?((A=h.style)==null?void 0:A.outlineWidth)/2.5:0,ft((a=(s=h.style)==null?void 0:s.outline)!=null?a:"#DBDBDB"),1,1),W.beginFill(ft((c=(l=g.spec().style)==null?void 0:l.background)!=null?c:I.track.background),(d=(u=g.spec().style)==null?void 0:u.backgroundOpacity)!=null?d:!I.track.background||I.track.background==="transparent"?0:1),W.moveTo(V.x,V.y),W.arc(v,w,y,S,X,!0),W.arc(v,w,Z,X,S,!1),W.closePath()),st(h.x)&&h.x.axis==="top"&&(W.lineStyle(.5,ft("black"),0,.5),W.beginFill(ft("white"),0),W.moveTo(V.x,V.y),W.arc(v,w,Z-.5,S,X,!0),W.arc(v,w,Z,X,S,!1),W.closePath()),W.lineStyle(.5,ft("black"),0,.5),W.beginFill(ft("white"),0),W.moveTo(v,w),W.arc(v,w,Z+3,S,X,!1),W.closePath(),W.lineStyle(1,ft("#DBDBDB"),0,0),W.beginFill(ft("white"),0),W.drawCircle(v,w,y-1)}function qQe(e,g,I){var i,n,C,r,o,A;const[s,a]=e.position,[l,c]=e.dimensions,u=e.pBackground;if((i=g.spec().style)!=null&&i.background||I.track.background&&I.track.background!=="transparent"){u.clear();const d=(C=(n=g.spec().style)==null?void 0:n.background)!=null?C:I.track.background,h=xee((r=g.spec().style)==null?void 0:r.backgroundOpacity)?1:(o=g.spec().style)==null?void 0:o.backgroundOpacity;u.lineStyle(1,ft("white"),0,0),u.beginFill(ft(d),h),u.drawRect(s,a,l,c)}if(I.track.alternatingBackground&&I.track.alternatingBackground!=="transparent"){const d=g.spec();if(!st(d.row)||d.row.type!=="nominal")return;const h=(A=g.getChannelDomainArray("row"))!=null?A:["___SINGLE_ROW___"];if(h.length===0)return;h.forEach((m,f)=>{var b,p,y,Z;if(f%2===0)return;const B=g.encodedValue("row",m),G=(p=(b=g.spec().style)==null?void 0:b.background)!=null?p:I.track.alternatingBackground,v=xee((y=g.spec().style)==null?void 0:y.backgroundOpacity)?1:(Z=g.spec().style)==null?void 0:Z.backgroundOpacity;u.lineStyle(1,ft("white"),0,0),u.beginFill(ft(G),v),u.drawRect(e.position[0],e.position[1]+B,l,c/h.length)})}}function eje(e,g,I){var i,n,C,r,o;const A=I.spec();if(!A.width||!A.height){console.warn("Size of a track is not properly determined, so visual mark cannot be rendered");return}const s=I.data(),[a,l]=g.dimensions,c=A.layout==="circular",u=(i=A.innerRadius)!=null?i:220,d=(n=A.outerRadius)!=null?n:300,h=(C=A.startAngle)!=null?C:0,m=(r=A.endAngle)!=null?r:360,f=d-u,b=a/2,p=l/2,y=(o=I.getChannelDomainArray("row"))!=null?o:["___SINGLE_ROW___"],Z=l/y.length;y.forEach(B=>{const G=I.encodedValue("row",B);s.filter(v=>!fI(v,A.row)||fI(v,A.row)===B).forEach(v=>{var w,V;let S=I.encodedPIXIProperty("x",v),X=I.encodedPIXIProperty("xe",v),W=I.encodedPIXIProperty("x1",v),R=I.encodedPIXIProperty("x1e",v);const H=I.encodedPIXIProperty("y",v),Y=I.encodedPIXIProperty("stroke",v),D=I.encodedPIXIProperty("strokeWidth",v),E=I.encodedPIXIProperty("color",v),O=I.encodedPIXIProperty("opacity",v);typeof X<"u"&&([S,X]=[S,X].sort((ee,q)=>ee-q)),typeof W<"u"&&typeof R<"u"&&([W,R]=[W,R].sort((ee,q)=>ee-q));const J=typeof X<"u"&&typeof W<"u"&&typeof R<"u"&&Math.abs(S-X)>.1&&Math.abs(W-R)>.1;if(!J&&X===void 0&&!qn(A)){if(W===void 0&&R===void 0)return;X=W!==void 0?W:R}if(!J&&Math.abs(S-X)<=.1&&Math.abs(W-R)<=.1&&(S=(S+X)/2,X=(W+R)/2),e.lineStyle(D,ft(Y),O,.5),J){e.beginFill(ft(E==="none"?"white":E),E==="none"?0:O);let[ee,q,$,j]=[S,X,W,R];if([ee,q]=[ee,q].sort((te,U)=>te-U),[$,j]=[$,j].sort((te,U)=>te-U),ee>a||j<0||Math.abs(j-ee)<.5)return;if(c){if(ee<0||j>a)return;const te=d-G/l*f,U=Mt(ee,a,te,b,p,h,m),ie=Mt(q,a,te,b,p,h,m),me=Mt($,a,te,b,p,h,m),Ce=Mt(j,a,te,b,p,h,m);e.moveTo(U.x,U.y),e.bezierCurveTo(b,p,b,p,Ce.x,Ce.y),e.arc(b,p,d,ic(Ce.x,Ce.y,b,p),ic(me.x,me.y,b,p),!1),e.bezierCurveTo(b,p,b,p,ie.x,ie.y),e.arc(b,p,d,ic(ie.x,ie.y,b,p),ic(U.x,U.y,b,p),!1),e.endFill()}else e.moveTo(ee,G),e.lineTo(q,G),e.lineTo(j,G+Z),e.lineTo($,G+Z),e.lineTo(ee,G),e.closePath()}else{if(qn(A)){((w=A.style)==null?void 0:w.linkConnectionType)==="curve"?(e.moveTo(S,0),e.bezierCurveTo(S/5*4,(G+Z-H)/2,S/2,(G+Z-H)/5*4,0,G+Z-H)):((V=A.style)==null?void 0:V.linkConnectionType)==="straight"?(e.moveTo(S,0),e.lineTo(0,G+Z-H)):(e.moveTo(S,0),e.lineTo(S,G+Z-H),e.lineTo(0,G+Z-H));return}if(c){let ee,q;for(let $=0;$<=1;$+=.02){const j=Ce=>Math.log(Ce/(1-Ce)),te=Ce=>d-1/(1+Math.exp(j(Ce)))*f+3,U=(Ce,Ze,Ge)=>((Ge-Ze)*Ce+Ze)/a,ie=b+te($)*Math.cos(-U($,S,X)*2*Math.PI-Math.PI/2),me=p+te($)*Math.sin(-U($,S,X)*2*Math.PI-Math.PI/2);ee&&q&&(e.lineStyle(D,ft(Y),O,.5),e.moveTo(ee,q),e.lineTo(ie,me)),ee=ie,q=me}return}e.moveTo(X,G+Z),e.lineTo(S,G)}})})}const pd=["x","xe","x1","x1e","y","ye","y1","y1e","color","size","row","stroke","strokeWidth","opacity","text"];function tje(e,g,I,i){if(!e||!g||!I||i.spec().mark==="brush")return;if(["x","x1","x1e","xe"].forEach(r=>{i.setChannelScale(r,g._xScale)}),qn(i.spec())||cje(i.spec())){const r=g._yScale.copy();r.range([r.range()[1],r.range()[0]]),["y","y1","y1e","ye"].forEach(o=>{i.setChannelScale(o,r)})}const[n,C]=g.dimensions;switch(i.spec().mark){case"point":VQe(g,I.graphics,i);break;case"bar":XQe(g,I,i);break;case"line":WQe(I.graphics,i,n,C);break;case"area":TQe(e,g,I,i);break;case"rect":NQe(e,g,I,i);break;case"triangleLeft":case"triangleRight":case"triangleBottom":YQe(I.graphics,i,n,C);break;case"text":KQe(e,g,I,i);break;case"rule":DQe(e,g,I,i);break;case"betweenLink":eje(I.graphics,g,i);break;case"withinLink":xQe(I.graphics,g,i);break;default:console.warn("Unsupported mark type");break}}function gje(e,g,I,i,n){if(!e||!g||!I||i.spec().mark==="brush")return;["x","x1","x1e","xe"].forEach(r=>{i.setChannelScale(r,g._xScale)}),i.spec().layout==="circular"?$Qe(g,i,n):(qQe(g,i,n),OQe(g,i,n)),MQe(g,i,n)}function Ije(e,g,I,i,n){if(!e||!g||!I||i.spec().mark==="brush")return;["x","x1","x1e","xe"].forEach(r=>{i.setChannelScale(r,g._xScale)}),i.spec().layout==="circular"?(jQe(e,g,I,i,n),JQe(e,g,I,i,n)):(QQe(e,g,I,i,n),UQe(e,g,I,i,n)),_Qe(e,g,I,i,n)}function y0(e){if(fpe(e)||aS(e))return[];if(!ai(e))return[e];if(e._overlay.length===0)return[{...e,superpose:void 0}];const g=JSON.parse(JSON.stringify(e));delete g._overlay;const I=[];e._overlay.forEach((C,r)=>{const o=Object.assign(JSON.parse(JSON.stringify(g)),C);o.title&&r!==0&&delete o.title,I.push(o)});let i;return I.forEach(C=>{st(C.x)&&C.x.axis&&!i&&(i=C.x.axis)}),I.map(C=>({...C,x:{...C.x,axis:i}}))}function hpe(e){return[].concat(...e.map(g=>{if(fpe(g)||!ai(g)||g._overlay.length<=1)return[g];if(g._overlay.filter(r=>r.data).length===0)return[g];if(Mee([g.data,...g._overlay.map(r=>r.data)]))return[g];const I={...g,id:void 0,_overlay:void 0},i=[],n=JSON.parse(JSON.stringify(I));return n._overlay=[],g._overlay.forEach(r=>{if(n.data||(n.data=r.data),n.id||(n.id=r.id),!r.data||Mee([n.data,r.data])){n._overlay.push(r);return}const o=Object.assign(JSON.parse(JSON.stringify(I)),r);i.push(o)}),(n._overlay.length>0?[n,...i]:i).map((r,o,A)=>{const s=o!==0,a=Yr(r)&&st(r.y)&&!r.y.axis&&s?{...r.y,axis:o===1?"right":"none"}:Yr(r)?r.y:void 0;return r.title&&o!==A.length-1&&A.length!==1&&delete r.title,{...r,overlayOnPreviousTrack:s,y:a}})}))}function Mee(e){if(e.length===0)return!1;const g=e.filter(n=>n);if(g.length!==e.length)return!1;const I=Object.keys(g[0]).sort();let i=!0;return I.forEach(n=>{if(Array.from(new Set(g.map(r=>JSON.stringify(r[n])))).length!==1){i=!1;return}}),i}const uX={viridis:ape,grey:AQe,warm:sQe,spectral:tQe,cividis:aQe,bupu:IQe,rdbu:q7e,hot:rQe,pink:nQe};function sU(e){return typeof e=="object"&&e!==null}function GV(e){return sU(e)&&"getTabularData"in e}function ije(e,g){var I;return((I=e.dataTransform)!=null?I:[]).some(i=>i.type===g)}function nje(e="viridis",g=100){var I;const i=(I=uX[e])!=null?I:uX.viridis;return[...Array(g)].map((n,C)=>i(1/g*C))}function mpe(e){return!("alignment"in e)&&!e.tracks.find(g=>g.alignment==="overlay"||"tracks"in g)}function Cje(e){return"alignment"in e&&e.alignment==="overlay"}function rje(e){return!mpe(e)&&!Cje(e)}function fpe(e){return!ai(e)&&"data"in e&&!("mark"in e)}function aS(e){return"type"in e&&e.type=="dummy-track"}function oje(e){return!!("data"in e&&"overrideTemplate"in e&&e.overrideTemplate)}function zee(e){return typeof e=="object"}function Aje(e){return"chromosome"in e&&!("interval"in e)}function aje(e){return!("chromosome"in e)&&"interval"in e}function sje(e){return"chromosome"in e&&"interval"in e}function Yr(e){return!("_overlay"in e)}function ai(e){return"_overlay"in e}function lje(e){return"template"in e}function cje(e){return Yr(e)&&!st(e.x)&&st(e.y)&&e.y.type==="genomic"}function qn(e){const g=Yr(e)?e:y0(e)[0];return st(g.x)&&g.x.type==="genomic"&&st(g.y)&&g.y.type==="genomic"}function uje(e){return qn(e)&&e.data.type==="matrix"&&(e.mark==="bar"||e.mark==="rect")&&e.xe&&e.ye}function l1(e){return e!==null&&typeof e=="object"&&"value"in e}function lU(e){return e!==void 0&&(e.type==="vector"||e.type==="beddb"||e.type==="multivec"||e.type==="bigwig"||e.type==="matrix"||e.type==="bam"||e.type==="vcf"||e.type==="gff"||e.type==="bed")}function st(e){return sU(e)&&!("value"in e)}function dje(e){return"oneOf"in e}function hje(e){return"inRange"in e}function mje(e){return"include"in e}function Pee(e){return Array.isArray(e)}function fje(e){return Array.isArray(e)}function sT(e){return(e.mark==="bar"||e.mark==="area"||e.mark==="text")&&st(e.color)&&e.color.type==="nominal"&&(!e.row||l1(e.row))&&st(e.y)&&e.y.type==="quantitative"&&!st(e.ye)}function pje(e,g){const I=e[g];return sT(e)&&(g==="x"||g==="y")&&st(I)&&I.type==="quantitative"}function fI(e,g){if(st(g)&&g.field)return e[g==null?void 0:g.field]}function bje(e){const g=[];return pd.forEach(I=>{const i=e[I];st(i)&&"aggregate"in i&&g.push(I)}),g}function VK(e,g){const I=[];return pd.forEach(i=>{const n=e[i];st(n)&&n.type===g&&I.push(i)}),I}function dX(e){if((Yr(e)||ai(e))&&st(e.x)&&e.x.axis&&e.x.axis!=="none")return!0;if(ai(e)){let g=!1;return e._overlay.forEach(I=>{g||st(I.x)&&I.x.axis&&I.x.axis!=="none"&&(g=!0)}),g}return!1}function yje(e){if((Yr(e)||ai(e))&&st(e.y)&&e.y.axis&&e.y.axis!=="none")return!0;if(ai(e)){let g=!1;return e._overlay.forEach(I=>{g||st(I.y)&&I.y.axis&&I.y.axis!=="none"&&(g=!0)}),g}return!1}function Sm(e){return typeof e=="object"}var Od=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Zje(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var yM={exports:{}};/** @license URI.js v4.4.1 (c) 2011 Gary Court. License: http://github.com/garycourt/uri-js */(function(e,g){(function(I,i){i(g)})(Od,function(I){function i(){for(var P=arguments.length,x=Array(P),Q=0;Q1){x[0]=x[0].slice(0,-1);for(var ce=x.length-1,de=1;de= 0x80 (not a basic code point)","invalid-input":"Invalid input"},S=h-m,X=Math.floor,W=String.fromCharCode;function R(P){throw new RangeError(V[P])}function H(P,x){for(var Q=[],ce=P.length;ce--;)Q[ce]=x(P[ce]);return Q}function Y(P,x){var Q=P.split("@"),ce="";Q.length>1&&(ce=Q[0]+"@",P=Q[1]),P=P.replace(w,".");var de=P.split("."),Je=H(de,x).join(".");return ce+Je}function D(P){for(var x=[],Q=0,ce=P.length;Q=55296&&de<=56319&&Q>1,x+=X(x/Q);x>S*f>>1;de+=h)x=X(x/S);return X(de+(S+1)*x/(x+b))},q=function(x){var Q=[],ce=x.length,de=0,Je=Z,Oe=y,lt=x.lastIndexOf(B);lt<0&&(lt=0);for(var pt=0;pt=128&&R("not-basic"),Q.push(x.charCodeAt(pt));for(var kt=lt>0?lt+1:0;kt=ce&&R("invalid-input");var At=O(x.charCodeAt(kt++));(At>=h||At>X((d-de)/Vt))&&R("overflow"),de+=At*Vt;var Xt=Ft<=Oe?m:Ft>=Oe+f?f:Ft-Oe;if(AtX(d/Pt)&&R("overflow"),Vt*=Pt}var Dt=Q.length+1;Oe=ee(de-ut,Dt,ut==0),X(de/Dt)>d-Je&&R("overflow"),Je+=X(de/Dt),de%=Dt,Q.splice(de++,0,Je)}return String.fromCodePoint.apply(String,Q)},$=function(x){var Q=[];x=D(x);var ce=x.length,de=Z,Je=0,Oe=y,lt=!0,pt=!1,kt=void 0;try{for(var ut=x[Symbol.iterator](),Vt;!(lt=(Vt=ut.next()).done);lt=!0){var Ft=Vt.value;Ft<128&&Q.push(W(Ft))}}catch(cC){pt=!0,kt=cC}finally{try{!lt&&ut.return&&ut.return()}finally{if(pt)throw kt}}var At=Q.length,Xt=At;for(At&&Q.push(B);Xt=de&&LtX((d-Je)/Yt)&&R("overflow"),Je+=(Pt-de)*Yt,de=Pt;var Wt=!0,$t=!1,_t=void 0;try{for(var jt=x[Symbol.iterator](),rg;!(Wt=(rg=jt.next()).done);Wt=!0){var wg=rg.value;if(wgd&&R("overflow"),wg==de){for(var ug=Je,MI=h;;MI+=h){var Ui=MI<=Oe?m:MI>=Oe+f?f:MI-Oe;if(ug>6|192).toString(16).toUpperCase()+"%"+(x&63|128).toString(16).toUpperCase():Q="%"+(x>>12|224).toString(16).toUpperCase()+"%"+(x>>6&63|128).toString(16).toUpperCase()+"%"+(x&63|128).toString(16).toUpperCase(),Q}function Ce(P){for(var x="",Q=0,ce=P.length;Q=194&&de<224){if(ce-Q>=6){var Je=parseInt(P.substr(Q+4,2),16);x+=String.fromCharCode((de&31)<<6|Je&63)}else x+=P.substr(Q,6);Q+=6}else if(de>=224){if(ce-Q>=9){var Oe=parseInt(P.substr(Q+4,2),16),lt=parseInt(P.substr(Q+7,2),16);x+=String.fromCharCode((de&15)<<12|(Oe&63)<<6|lt&63)}else x+=P.substr(Q,9);Q+=9}else x+=P.substr(Q,3),Q+=3}return x}function Ze(P,x){function Q(ce){var de=Ce(ce);return de.match(x.UNRESERVED)?de:ce}return P.scheme&&(P.scheme=String(P.scheme).replace(x.PCT_ENCODED,Q).toLowerCase().replace(x.NOT_SCHEME,"")),P.userinfo!==void 0&&(P.userinfo=String(P.userinfo).replace(x.PCT_ENCODED,Q).replace(x.NOT_USERINFO,me).replace(x.PCT_ENCODED,r)),P.host!==void 0&&(P.host=String(P.host).replace(x.PCT_ENCODED,Q).toLowerCase().replace(x.NOT_HOST,me).replace(x.PCT_ENCODED,r)),P.path!==void 0&&(P.path=String(P.path).replace(x.PCT_ENCODED,Q).replace(P.scheme?x.NOT_PATH:x.NOT_PATH_NOSCHEME,me).replace(x.PCT_ENCODED,r)),P.query!==void 0&&(P.query=String(P.query).replace(x.PCT_ENCODED,Q).replace(x.NOT_QUERY,me).replace(x.PCT_ENCODED,r)),P.fragment!==void 0&&(P.fragment=String(P.fragment).replace(x.PCT_ENCODED,Q).replace(x.NOT_FRAGMENT,me).replace(x.PCT_ENCODED,r)),P}function Ge(P){return P.replace(/^0*(.*)/,"$1")||"0"}function Be(P,x){var Q=P.match(x.IPV4ADDRESS)||[],ce=c(Q,2),de=ce[1];return de?de.split(".").map(Ge).join("."):P}function Ne(P,x){var Q=P.match(x.IPV6ADDRESS)||[],ce=c(Q,3),de=ce[1],Je=ce[2];if(de){for(var Oe=de.toLowerCase().split("::").reverse(),lt=c(Oe,2),pt=lt[0],kt=lt[1],ut=kt?kt.split(":").map(Ge):[],Vt=pt.split(":").map(Ge),Ft=x.IPV4ADDRESS.test(Vt[Vt.length-1]),At=Ft?7:8,Xt=Vt.length-At,Pt=Array(At),Dt=0;Dt1){var bt=Pt.slice(0,Qg.index),Lt=Pt.slice(Qg.index+Qg.length);et=bt.join(":")+"::"+Lt.join(":")}else et=Pt.join(":");return Je&&(et+="%"+Je),et}else return P}var Se=/^(?:([^:\/?#]+):)?(?:\/\/((?:([^\/?#@]*)@)?(\[[^\/?#\]]+\]|[^\/?#:]*)(?:\:(\d*))?))?([^?#]*)(?:\?([^#]*))?(?:#((?:.|\n|\r)*))?/i,Pe="".match(/(){0}/)[1]===void 0;function ze(P){var x=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},Q={},ce=x.iri!==!1?l:a;x.reference==="suffix"&&(P=(x.scheme?x.scheme+":":"")+"//"+P);var de=P.match(Se);if(de){Pe?(Q.scheme=de[1],Q.userinfo=de[3],Q.host=de[4],Q.port=parseInt(de[5],10),Q.path=de[6]||"",Q.query=de[7],Q.fragment=de[8],isNaN(Q.port)&&(Q.port=de[5])):(Q.scheme=de[1]||void 0,Q.userinfo=P.indexOf("@")!==-1?de[3]:void 0,Q.host=P.indexOf("//")!==-1?de[4]:void 0,Q.port=parseInt(de[5],10),Q.path=de[6]||"",Q.query=P.indexOf("?")!==-1?de[7]:void 0,Q.fragment=P.indexOf("#")!==-1?de[8]:void 0,isNaN(Q.port)&&(Q.port=P.match(/\/\/(?:.|\n)*\:(?:\/|\?|\#|$)/)?de[4]:void 0)),Q.host&&(Q.host=Ne(Be(Q.host,ce),ce)),Q.scheme===void 0&&Q.userinfo===void 0&&Q.host===void 0&&Q.port===void 0&&!Q.path&&Q.query===void 0?Q.reference="same-document":Q.scheme===void 0?Q.reference="relative":Q.fragment===void 0?Q.reference="absolute":Q.reference="uri",x.reference&&x.reference!=="suffix"&&x.reference!==Q.reference&&(Q.error=Q.error||"URI is not a "+x.reference+" reference.");var Je=ie[(x.scheme||Q.scheme||"").toLowerCase()];if(!x.unicodeSupport&&(!Je||!Je.unicodeSupport)){if(Q.host&&(x.domainHost||Je&&Je.domainHost))try{Q.host=U.toASCII(Q.host.replace(ce.PCT_ENCODED,Ce).toLowerCase())}catch(Oe){Q.error=Q.error||"Host's domain name can not be converted to ASCII via punycode: "+Oe}Ze(Q,a)}else Ze(Q,ce);Je&&Je.parse&&Je.parse(Q,x)}else Q.error=Q.error||"URI can not be parsed.";return Q}function Fe(P,x){var Q=x.iri!==!1?l:a,ce=[];return P.userinfo!==void 0&&(ce.push(P.userinfo),ce.push("@")),P.host!==void 0&&ce.push(Ne(Be(String(P.host),Q),Q).replace(Q.IPV6ADDRESS,function(de,Je,Oe){return"["+Je+(Oe?"%25"+Oe:"")+"]"})),(typeof P.port=="number"||typeof P.port=="string")&&(ce.push(":"),ce.push(String(P.port))),ce.length?ce.join(""):void 0}var Ue=/^\.\.?\//,_e=/^\/\.(\/|$)/,ot=/^\/\.\.(\/|$)/,Zt=/^\/?(?:.|\n)*?(?=\/|$)/;function nt(P){for(var x=[];P.length;)if(P.match(Ue))P=P.replace(Ue,"");else if(P.match(_e))P=P.replace(_e,"/");else if(P.match(ot))P=P.replace(ot,"/"),x.pop();else if(P==="."||P==="..")P="";else{var Q=P.match(Zt);if(Q){var ce=Q[0];P=P.slice(ce.length),x.push(ce)}else throw new Error("Unexpected dot segment condition")}return x.join("")}function Te(P){var x=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},Q=x.iri?l:a,ce=[],de=ie[(x.scheme||P.scheme||"").toLowerCase()];if(de&&de.serialize&&de.serialize(P,x),P.host&&!Q.IPV6ADDRESS.test(P.host)){if(x.domainHost||de&&de.domainHost)try{P.host=x.iri?U.toUnicode(P.host):U.toASCII(P.host.replace(Q.PCT_ENCODED,Ce).toLowerCase())}catch(lt){P.error=P.error||"Host's domain name can not be converted to "+(x.iri?"Unicode":"ASCII")+" via punycode: "+lt}}Ze(P,Q),x.reference!=="suffix"&&P.scheme&&(ce.push(P.scheme),ce.push(":"));var Je=Fe(P,x);if(Je!==void 0&&(x.reference!=="suffix"&&ce.push("//"),ce.push(Je),P.path&&P.path.charAt(0)!=="/"&&ce.push("/")),P.path!==void 0){var Oe=P.path;!x.absolutePath&&(!de||!de.absolutePath)&&(Oe=nt(Oe)),Je===void 0&&(Oe=Oe.replace(/^\/\//,"/%2F")),ce.push(Oe)}return P.query!==void 0&&(ce.push("?"),ce.push(P.query)),P.fragment!==void 0&&(ce.push("#"),ce.push(P.fragment)),ce.join("")}function se(P,x){var Q=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},ce=arguments[3],de={};return ce||(P=ze(Te(P,Q),Q),x=ze(Te(x,Q),Q)),Q=Q||{},!Q.tolerant&&x.scheme?(de.scheme=x.scheme,de.userinfo=x.userinfo,de.host=x.host,de.port=x.port,de.path=nt(x.path||""),de.query=x.query):(x.userinfo!==void 0||x.host!==void 0||x.port!==void 0?(de.userinfo=x.userinfo,de.host=x.host,de.port=x.port,de.path=nt(x.path||""),de.query=x.query):(x.path?(x.path.charAt(0)==="/"?de.path=nt(x.path):((P.userinfo!==void 0||P.host!==void 0||P.port!==void 0)&&!P.path?de.path="/"+x.path:P.path?de.path=P.path.slice(0,P.path.lastIndexOf("/")+1)+x.path:de.path=x.path,de.path=nt(de.path)),de.query=x.query):(de.path=P.path,x.query!==void 0?de.query=x.query:de.query=P.query),de.userinfo=P.userinfo,de.host=P.host,de.port=P.port),de.scheme=P.scheme),de.fragment=x.fragment,de}function ye(P,x,Q){var ce=A({scheme:"null"},Q);return Te(se(ze(P,ce),ze(x,ce),ce,!0),ce)}function Xe(P,x){return typeof P=="string"?P=Te(ze(P,x),x):C(P)==="object"&&(P=ze(Te(P,x),x)),P}function K(P,x,Q){return typeof P=="string"?P=Te(ze(P,Q),Q):C(P)==="object"&&(P=Te(P,Q)),typeof x=="string"?x=Te(ze(x,Q),Q):C(x)==="object"&&(x=Te(x,Q)),P===x}function T(P,x){return P&&P.toString().replace(!x||!x.iri?a.ESCAPE:l.ESCAPE,me)}function k(P,x){return P&&P.toString().replace(!x||!x.iri?a.PCT_ENCODED:l.PCT_ENCODED,Ce)}var ge={scheme:"http",domainHost:!0,parse:function(x,Q){return x.host||(x.error=x.error||"HTTP URIs must have a host."),x},serialize:function(x,Q){var ce=String(x.scheme).toLowerCase()==="https";return(x.port===(ce?443:80)||x.port==="")&&(x.port=void 0),x.path||(x.path="/"),x}},he={scheme:"https",domainHost:ge.domainHost,parse:ge.parse,serialize:ge.serialize};function Ve(P){return typeof P.secure=="boolean"?P.secure:String(P.scheme).toLowerCase()==="wss"}var De={scheme:"ws",domainHost:!0,parse:function(x,Q){var ce=x;return ce.secure=Ve(ce),ce.resourceName=(ce.path||"/")+(ce.query?"?"+ce.query:""),ce.path=void 0,ce.query=void 0,ce},serialize:function(x,Q){if((x.port===(Ve(x)?443:80)||x.port==="")&&(x.port=void 0),typeof x.secure=="boolean"&&(x.scheme=x.secure?"wss":"ws",x.secure=void 0),x.resourceName){var ce=x.resourceName.split("?"),de=c(ce,2),Je=de[0],Oe=de[1];x.path=Je&&Je!=="/"?Je:void 0,x.query=Oe,x.resourceName=void 0}return x.fragment=void 0,x}},qe={scheme:"wss",domainHost:De.domainHost,parse:De.parse,serialize:De.serialize},mt={},vt="[A-Za-z0-9\\-\\.\\_\\~\\xA0-\\u200D\\u2010-\\u2029\\u202F-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF]",ct="[0-9A-Fa-f]",Ht=n(n("%[EFef]"+ct+"%"+ct+ct+"%"+ct+ct)+"|"+n("%[89A-Fa-f]"+ct+"%"+ct+ct)+"|"+n("%"+ct+ct)),ne="[A-Za-z0-9\\!\\$\\%\\'\\*\\+\\-\\^\\_\\`\\{\\|\\}\\~]",F="[\\!\\$\\%\\'\\(\\)\\*\\+\\,\\-\\.0-9\\<\\>A-Z\\x5E-\\x7E]",_=i(F,'[\\"\\\\]'),fe="[\\!\\$\\'\\(\\)\\*\\+\\,\\;\\:\\@]",ke=new RegExp(vt,"g"),ue=new RegExp(Ht,"g"),le=new RegExp(i("[^]",ne,"[\\.]",'[\\"]',_),"g"),re=new RegExp(i("[^]",vt,fe),"g"),oe=re;function we(P){var x=Ce(P);return x.match(ke)?x:P}var Ke={scheme:"mailto",parse:function(x,Q){var ce=x,de=ce.to=ce.path?ce.path.split(","):[];if(ce.path=void 0,ce.query){for(var Je=!1,Oe={},lt=ce.query.split("&"),pt=0,kt=lt.length;pt=55296&&C<=56319&&n=g)throw new Error("Cannot access property/index "+i+" levels up, current level is "+g);return I[g-i]}if(i>g)throw new Error("Cannot access data "+i+" levels up, current level is "+g);if(C="data"+(g-i||""),!n)return C}for(var o=C,A=n.split("/"),s=0;s=0?{index:i,compiling:!0}:(i=this._compilations.length,this._compilations[i]={schema:e,root:g,baseId:I},{index:i,compiling:!1})}function n4e(e,g,I){var i=wpe.call(this,e,g,I);i>=0&&this._compilations.splice(i,1)}function wpe(e,g,I){for(var i=0;i%\\^`{|}]|%[0-9a-f]{2})|\{[+#./;?&=,!@|]?(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?(?:,(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?)*\})*$/i,Xpe=/^(?:(?:http[s\u017F]?|ftp):\/\/)(?:(?:[\0-\x08\x0E-\x1F!-\x9F\xA1-\u167F\u1681-\u1FFF\u200B-\u2027\u202A-\u202E\u2030-\u205E\u2060-\u2FFF\u3001-\uD7FF\uE000-\uFEFE\uFF00-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+(?::(?:[\0-\x08\x0E-\x1F!-\x9F\xA1-\u167F\u1681-\u1FFF\u200B-\u2027\u202A-\u202E\u2030-\u205E\u2060-\u2FFF\u3001-\uD7FF\uE000-\uFEFE\uFF00-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*)?@)?(?:(?!10(?:\.[0-9]{1,3}){3})(?!127(?:\.[0-9]{1,3}){3})(?!169\.254(?:\.[0-9]{1,3}){2})(?!192\.168(?:\.[0-9]{1,3}){2})(?!172\.(?:1[6-9]|2[0-9]|3[01])(?:\.[0-9]{1,3}){2})(?:[1-9][0-9]?|1[0-9][0-9]|2[01][0-9]|22[0-3])(?:\.(?:1?[0-9]{1,2}|2[0-4][0-9]|25[0-5])){2}(?:\.(?:[1-9][0-9]?|1[0-9][0-9]|2[0-4][0-9]|25[0-4]))|(?:(?:(?:[0-9a-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+-)*(?:[0-9a-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+)(?:\.(?:(?:[0-9a-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+-)*(?:[0-9a-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+)*(?:\.(?:(?:[a-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]){2,})))(?::[0-9]{2,5})?(?:\/(?:[\0-\x08\x0E-\x1F!-\x9F\xA1-\u167F\u1681-\u1FFF\u200B-\u2027\u202A-\u202E\u2030-\u205E\u2060-\u2FFF\u3001-\uD7FF\uE000-\uFEFE\uFF00-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*)?$/i,Hpe=/^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i,Tpe=/^(?:\/(?:[^~/]|~0|~1)*)*$/,Npe=/^#(?:\/(?:[a-z0-9_\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i,kpe=/^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/,m4e=dT;function dT(e){return e=e=="full"?"full":"fast",s4e.copy(dT[e])}dT.fast={date:/^\d\d\d\d-[0-1]\d-[0-3]\d$/,time:/^(?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d(?::?\d\d)?)?$/i,"date-time":/^\d\d\d\d-[0-1]\d-[0-3]\d[t\s](?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d(?::?\d\d)?)$/i,uri:/^(?:[a-z][a-z0-9+\-.]*:)(?:\/?\/)?[^\s]*$/i,"uri-reference":/^(?:(?:[a-z][a-z0-9+\-.]*:)?\/?\/)?(?:[^\\\s#][^\s#]*)?(?:#[^\\\s]*)?$/i,"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1}(?:(?:(?::[0-9a-f]{1,4}){1,6})|(?:(?::[0-9a-f]{1,4}){0,4}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?::(?:(?:(?::[0-9a-f]{1,4}){1,7})|(?:(?::[0-9a-f]{1,4}){0,5}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(?:%.+)?\s*$/i,regex:Dpe,uuid:Hpe,"json-pointer":Tpe,"json-pointer-uri-fragment":Npe,"relative-json-pointer":kpe};dT.full={date:Ype,time:Kpe,"date-time":b4e,uri:Z4e,"uri-reference":h4e,"uri-template":Wpe,url:Xpe,email:/^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i,hostname:Rpe,ipv4:/^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/,ipv6:/^\s*(?:(?:(?:[0-9a-f]{1,4}:){7}(?:[0-9a-f]{1,4}|:))|(?:(?:[0-9a-f]{1,4}:){6}(?::[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(?:(?:[0-9a-f]{1,4}:){5}(?:(?:(?::[0-9a-f]{1,4}){1,2})|:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(?:(?:[0-9a-f]{1,4}:){4}(?:(?:(?::[0-9a-f]{1,4}){1,3})|(?:(?::[0-9a-f]{1,4})?:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){3}(?:(?:(?::[0-9a-f]{1,4}){1,4})|(?:(?::[0-9a-f]{1,4}){0,2}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){2}(?:(?:(?::[0-9a-f]{1,4}){1,5})|(?:(?::[0-9a-f]{1,4}){0,3}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){1}(?:(?:(?::[0-9a-f]{1,4}){1,6})|(?:(?::[0-9a-f]{1,4}){0,4}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?::(?:(?:(?::[0-9a-f]{1,4}){1,7})|(?:(?::[0-9a-f]{1,4}){0,5}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(?:%.+)?\s*$/i,regex:Dpe,uuid:Hpe,"json-pointer":Tpe,"json-pointer-uri-fragment":Npe,"relative-json-pointer":kpe};function f4e(e){return e%4===0&&(e%100!==0||e%400===0)}function Ype(e){var g=e.match(l4e);if(!g)return!1;var I=+g[1],i=+g[2],n=+g[3];return i>=1&&i<=12&&n>=1&&n<=(i==2&&f4e(I)?29:c4e[i])}function Kpe(e,g){var I=e.match(u4e);if(!I)return!1;var i=I[1],n=I[2],C=I[3],r=I[5];return(i<=23&&n<=59&&C<=59||i==23&&n==59&&C==60)&&(!g||r)}var p4e=/t|\s/i;function b4e(e){var g=e.split(p4e);return g.length==2&&Ype(g[0])&&Kpe(g[1],!0)}var y4e=/\/|:/;function Z4e(e){return y4e.test(e)&&d4e.test(e)}var G4e=/[^\\]\\Z/;function Dpe(e){if(G4e.test(e))return!1;try{return new RegExp(e),!0}catch{return!1}}var v4e=function(g,I,i){var n=" ",C=g.level,r=g.dataLevel,o=g.schema[I],A=g.errSchemaPath+"/"+I,s=!g.opts.allErrors,a="data"+(r||""),l="valid"+C,c,u;if(o=="#"||o=="#/")g.isRoot?(c=g.async,u="validate"):(c=g.root.schema.$async===!0,u="root.refVal[0]");else{var d=g.resolveRef(g.baseId,o,g.isRoot);if(d===void 0){var h=g.MissingRefError.message(g.baseId,o);if(g.opts.missingRefs=="fail"){g.logger.error(h);var m=m||[];m.push(n),n="",g.createErrors!==!1?(n+=" { keyword: '$ref' , dataPath: (dataPath || '') + "+g.errorPath+" , schemaPath: "+g.util.toQuotedString(A)+" , params: { ref: '"+g.util.escapeQuotes(o)+"' } ",g.opts.messages!==!1&&(n+=" , message: 'can\\'t resolve reference "+g.util.escapeQuotes(o)+"' "),g.opts.verbose&&(n+=" , schema: "+g.util.toQuotedString(o)+" , parentSchema: validate.schema"+g.schemaPath+" , data: "+a+" "),n+=" } "):n+=" {} ";var f=n;n=m.pop(),!g.compositeRule&&s?g.async?n+=" throw new ValidationError(["+f+"]); ":n+=" validate.errors = ["+f+"]; return false; ":n+=" var err = "+f+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",s&&(n+=" if (false) { ")}else if(g.opts.missingRefs=="ignore")g.logger.warn(h),s&&(n+=" if (true) { ");else throw new g.MissingRefError(g.baseId,o,h)}else if(d.inline){var b=g.util.copy(g);b.level++;var p="valid"+b.level;b.schema=d.schema,b.schemaPath="",b.errSchemaPath=o;var y=g.validate(b).replace(/validate\.schema/g,d.code);n+=" "+y+" ",s&&(n+=" if ("+p+") { ")}else c=d.$async===!0||g.async&&d.$async!==!1,u=d.code}if(u){var m=m||[];m.push(n),n="",g.opts.passContext?n+=" "+u+".call(this, ":n+=" "+u+"( ",n+=" "+a+", (dataPath || '')",g.errorPath!='""'&&(n+=" + "+g.errorPath);var Z=r?"data"+(r-1||""):"parentData",B=r?g.dataPathArr[r]:"parentDataProperty";n+=" , "+Z+" , "+B+", rootData) ";var G=n;if(n=m.pop(),c){if(!g.async)throw new Error("async schema referenced by sync schema");s&&(n+=" var "+l+"; "),n+=" try { await "+G+"; ",s&&(n+=" "+l+" = true; "),n+=" } catch (e) { if (!(e instanceof ValidationError)) throw e; if (vErrors === null) vErrors = e.errors; else vErrors = vErrors.concat(e.errors); errors = vErrors.length; ",s&&(n+=" "+l+" = false; "),n+=" } ",s&&(n+=" if ("+l+") { ")}else n+=" if (!"+G+") { if (vErrors === null) vErrors = "+u+".errors; else vErrors = vErrors.concat("+u+".errors); errors = vErrors.length; } ",s&&(n+=" else { ")}return n},B4e=function(g,I,i){var n=" ",C=g.schema[I],r=g.schemaPath+g.util.getProperty(I),o=g.errSchemaPath+"/"+I,A=!g.opts.allErrors,s=g.util.copy(g),a="";s.level++;var l="valid"+s.level,c=s.baseId,u=!0,d=C;if(d)for(var h,m=-1,f=d.length-1;m0||h===!1:g.util.schemaHasRules(h,g.RULES.all))&&(u=!1,s.schema=h,s.schemaPath=r+"["+m+"]",s.errSchemaPath=o+"/"+m,n+=" "+g.validate(s)+" ",s.baseId=c,A&&(n+=" if ("+l+") { ",a+="}"));return A&&(u?n+=" if (true) { ":n+=" "+a.slice(0,-1)+" "),n},S4e=function(g,I,i){var n=" ",C=g.level,r=g.dataLevel,o=g.schema[I],A=g.schemaPath+g.util.getProperty(I),s=g.errSchemaPath+"/"+I,a=!g.opts.allErrors,l="data"+(r||""),c="valid"+C,u="errs__"+C,d=g.util.copy(g),h="";d.level++;var m="valid"+d.level,f=o.every(function(v){return g.opts.strictKeywords?typeof v=="object"&&Object.keys(v).length>0||v===!1:g.util.schemaHasRules(v,g.RULES.all)});if(f){var b=d.baseId;n+=" var "+u+" = errors; var "+c+" = false; ";var p=g.compositeRule;g.compositeRule=d.compositeRule=!0;var y=o;if(y)for(var Z,B=-1,G=y.length-1;B0||o===!1:g.util.schemaHasRules(o,g.RULES.all);if(n+="var "+u+" = errors;var "+c+";",Z){var B=g.compositeRule;g.compositeRule=d.compositeRule=!0,d.schema=o,d.schemaPath=A,d.errSchemaPath=s,n+=" var "+m+" = false; for (var "+f+" = 0; "+f+" < "+l+".length; "+f+"++) { ",d.errorPath=g.util.getPathExpr(g.errorPath,f,g.opts.jsonPointers,!0);var G=l+"["+f+"]";d.dataPathArr[b]=f;var v=g.validate(d);d.baseId=y,g.util.varOccurences(v,p)<2?n+=" "+g.util.varReplace(v,p,G)+" ":n+=" var "+p+" = "+G+"; "+v+" ",n+=" if ("+m+") break; } ",g.compositeRule=d.compositeRule=B,n+=" "+h+" if (!"+m+") {"}else n+=" if ("+l+".length == 0) {";var w=w||[];w.push(n),n="",g.createErrors!==!1?(n+=" { keyword: 'contains' , dataPath: (dataPath || '') + "+g.errorPath+" , schemaPath: "+g.util.toQuotedString(s)+" , params: {} ",g.opts.messages!==!1&&(n+=" , message: 'should contain a valid item' "),g.opts.verbose&&(n+=" , schema: validate.schema"+A+" , parentSchema: validate.schema"+g.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ";var V=n;return n=w.pop(),!g.compositeRule&&a?g.async?n+=" throw new ValidationError(["+V+"]); ":n+=" validate.errors = ["+V+"]; return false; ":n+=" var err = "+V+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",n+=" } else { ",Z&&(n+=" errors = "+u+"; if (vErrors !== null) { if ("+u+") vErrors.length = "+u+"; else vErrors = null; } "),g.opts.allErrors&&(n+=" } "),n},W4e=function(g,I,i){var n=" ",C=g.level,r=g.dataLevel,o=g.schema[I],A=g.schemaPath+g.util.getProperty(I),s=g.errSchemaPath+"/"+I,a=!g.opts.allErrors,l="data"+(r||""),c="errs__"+C,u=g.util.copy(g),d="";u.level++;var h="valid"+u.level,m={},f={},b=g.opts.ownProperties;for(B in o)if(B!="__proto__"){var p=o[B],y=Array.isArray(p)?f:m;y[B]=p}n+="var "+c+" = errors;";var Z=g.errorPath;n+="var missing"+C+";";for(var B in f)if(y=f[B],y.length){if(n+=" if ( "+l+g.util.getProperty(B)+" !== undefined ",b&&(n+=" && Object.prototype.hasOwnProperty.call("+l+", '"+g.util.escapeQuotes(B)+"') "),a){n+=" && ( ";var G=y;if(G)for(var v,w=-1,V=G.length-1;w0||p===!1:g.util.schemaHasRules(p,g.RULES.all))&&(n+=" "+h+" = true; if ( "+l+g.util.getProperty(B)+" !== undefined ",b&&(n+=" && Object.prototype.hasOwnProperty.call("+l+", '"+g.util.escapeQuotes(B)+"') "),n+=") { ",u.schema=p,u.schemaPath=A+g.util.getProperty(B),u.errSchemaPath=s+"/"+g.util.escapeFragment(B),n+=" "+g.validate(u)+" ",u.baseId=J,n+=" } ",a&&(n+=" if ("+h+") { ",d+="}"))}return a&&(n+=" "+d+" if ("+c+" == errors) {"),n},X4e=function(g,I,i){var n=" ",C=g.level,r=g.dataLevel,o=g.schema[I],A=g.schemaPath+g.util.getProperty(I),s=g.errSchemaPath+"/"+I,a=!g.opts.allErrors,l="data"+(r||""),c="valid"+C,u=g.opts.$data&&o&&o.$data;u&&(n+=" var schema"+C+" = "+g.util.getData(o.$data,r,g.dataPathArr)+"; ");var d="i"+C,h="schema"+C;u||(n+=" var "+h+" = validate.schema"+A+";"),n+="var "+c+";",u&&(n+=" if (schema"+C+" === undefined) "+c+" = true; else if (!Array.isArray(schema"+C+")) "+c+" = false; else {"),n+=""+c+" = false;for (var "+d+"=0; "+d+"<"+h+".length; "+d+"++) if (equal("+l+", "+h+"["+d+"])) { "+c+" = true; break; }",u&&(n+=" } "),n+=" if (!"+c+") { ";var m=m||[];m.push(n),n="",g.createErrors!==!1?(n+=" { keyword: 'enum' , dataPath: (dataPath || '') + "+g.errorPath+" , schemaPath: "+g.util.toQuotedString(s)+" , params: { allowedValues: schema"+C+" } ",g.opts.messages!==!1&&(n+=" , message: 'should be equal to one of the allowed values' "),g.opts.verbose&&(n+=" , schema: validate.schema"+A+" , parentSchema: validate.schema"+g.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ";var f=n;return n=m.pop(),!g.compositeRule&&a?g.async?n+=" throw new ValidationError(["+f+"]); ":n+=" validate.errors = ["+f+"]; return false; ":n+=" var err = "+f+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",n+=" }",a&&(n+=" else { "),n},H4e=function(g,I,i){var n=" ",C=g.level,r=g.dataLevel,o=g.schema[I],A=g.schemaPath+g.util.getProperty(I),s=g.errSchemaPath+"/"+I,a=!g.opts.allErrors,l="data"+(r||"");if(g.opts.format===!1)return a&&(n+=" if (true) { "),n;var c=g.opts.$data&&o&&o.$data,u;c?(n+=" var schema"+C+" = "+g.util.getData(o.$data,r,g.dataPathArr)+"; ",u="schema"+C):u=o;var d=g.opts.unknownFormats,h=Array.isArray(d);if(c){var m="format"+C,f="isObject"+C,b="formatType"+C;n+=" var "+m+" = formats["+u+"]; var "+f+" = typeof "+m+" == 'object' && !("+m+" instanceof RegExp) && "+m+".validate; var "+b+" = "+f+" && "+m+".type || 'string'; if ("+f+") { ",g.async&&(n+=" var async"+C+" = "+m+".async; "),n+=" "+m+" = "+m+".validate; } if ( ",c&&(n+=" ("+u+" !== undefined && typeof "+u+" != 'string') || "),n+=" (",d!="ignore"&&(n+=" ("+u+" && !"+m+" ",h&&(n+=" && self._opts.unknownFormats.indexOf("+u+") == -1 "),n+=") || "),n+=" ("+m+" && "+b+" == '"+i+"' && !(typeof "+m+" == 'function' ? ",g.async?n+=" (async"+C+" ? await "+m+"("+l+") : "+m+"("+l+")) ":n+=" "+m+"("+l+") ",n+=" : "+m+".test("+l+"))))) {"}else{var m=g.formats[o];if(!m){if(d=="ignore")return g.logger.warn('unknown format "'+o+'" ignored in schema at path "'+g.errSchemaPath+'"'),a&&(n+=" if (true) { "),n;if(h&&d.indexOf(o)>=0)return a&&(n+=" if (true) { "),n;throw new Error('unknown format "'+o+'" is used in schema at path "'+g.errSchemaPath+'"')}var f=typeof m=="object"&&!(m instanceof RegExp)&&m.validate,b=f&&m.type||"string";if(f){var p=m.async===!0;m=m.validate}if(b!=i)return a&&(n+=" if (true) { "),n;if(p){if(!g.async)throw new Error("async format in sync schema");var y="formats"+g.util.getProperty(o)+".validate";n+=" if (!(await "+y+"("+l+"))) { "}else{n+=" if (! ";var y="formats"+g.util.getProperty(o);f&&(y+=".validate"),typeof m=="function"?n+=" "+y+"("+l+") ":n+=" "+y+".test("+l+") ",n+=") { "}}var Z=Z||[];Z.push(n),n="",g.createErrors!==!1?(n+=" { keyword: 'format' , dataPath: (dataPath || '') + "+g.errorPath+" , schemaPath: "+g.util.toQuotedString(s)+" , params: { format: ",c?n+=""+u:n+=""+g.util.toQuotedString(o),n+=" } ",g.opts.messages!==!1&&(n+=` , message: 'should match format "`,c?n+="' + "+u+" + '":n+=""+g.util.escapeQuotes(o),n+=`"' `),g.opts.verbose&&(n+=" , schema: ",c?n+="validate.schema"+A:n+=""+g.util.toQuotedString(o),n+=" , parentSchema: validate.schema"+g.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ";var B=n;return n=Z.pop(),!g.compositeRule&&a?g.async?n+=" throw new ValidationError(["+B+"]); ":n+=" validate.errors = ["+B+"]; return false; ":n+=" var err = "+B+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",n+=" } ",a&&(n+=" else { "),n},T4e=function(g,I,i){var n=" ",C=g.level,r=g.dataLevel,o=g.schema[I],A=g.schemaPath+g.util.getProperty(I),s=g.errSchemaPath+"/"+I,a=!g.opts.allErrors,l="data"+(r||""),c="valid"+C,u="errs__"+C,d=g.util.copy(g);d.level++;var h="valid"+d.level,m=g.schema.then,f=g.schema.else,b=m!==void 0&&(g.opts.strictKeywords?typeof m=="object"&&Object.keys(m).length>0||m===!1:g.util.schemaHasRules(m,g.RULES.all)),p=f!==void 0&&(g.opts.strictKeywords?typeof f=="object"&&Object.keys(f).length>0||f===!1:g.util.schemaHasRules(f,g.RULES.all)),y=d.baseId;if(b||p){var Z;d.createErrors=!1,d.schema=o,d.schemaPath=A,d.errSchemaPath=s,n+=" var "+u+" = errors; var "+c+" = true; ";var B=g.compositeRule;g.compositeRule=d.compositeRule=!0,n+=" "+g.validate(d)+" ",d.baseId=y,d.createErrors=!0,n+=" errors = "+u+"; if (vErrors !== null) { if ("+u+") vErrors.length = "+u+"; else vErrors = null; } ",g.compositeRule=d.compositeRule=B,b?(n+=" if ("+h+") { ",d.schema=g.schema.then,d.schemaPath=g.schemaPath+".then",d.errSchemaPath=g.errSchemaPath+"/then",n+=" "+g.validate(d)+" ",d.baseId=y,n+=" "+c+" = "+h+"; ",b&&p?(Z="ifClause"+C,n+=" var "+Z+" = 'then'; "):Z="'then'",n+=" } ",p&&(n+=" else { ")):n+=" if (!"+h+") { ",p&&(d.schema=g.schema.else,d.schemaPath=g.schemaPath+".else",d.errSchemaPath=g.errSchemaPath+"/else",n+=" "+g.validate(d)+" ",d.baseId=y,n+=" "+c+" = "+h+"; ",b&&p?(Z="ifClause"+C,n+=" var "+Z+" = 'else'; "):Z="'else'",n+=" } "),n+=" if (!"+c+") { var err = ",g.createErrors!==!1?(n+=" { keyword: 'if' , dataPath: (dataPath || '') + "+g.errorPath+" , schemaPath: "+g.util.toQuotedString(s)+" , params: { failingKeyword: "+Z+" } ",g.opts.messages!==!1&&(n+=` , message: 'should match "' + `+Z+` + '" schema' `),g.opts.verbose&&(n+=" , schema: validate.schema"+A+" , parentSchema: validate.schema"+g.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ",n+="; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",!g.compositeRule&&a&&(g.async?n+=" throw new ValidationError(vErrors); ":n+=" validate.errors = vErrors; return false; "),n+=" } ",a&&(n+=" else { ")}else a&&(n+=" if (true) { ");return n},N4e=function(g,I,i){var n=" ",C=g.level,r=g.dataLevel,o=g.schema[I],A=g.schemaPath+g.util.getProperty(I),s=g.errSchemaPath+"/"+I,a=!g.opts.allErrors,l="data"+(r||""),c="valid"+C,u="errs__"+C,d=g.util.copy(g),h="";d.level++;var m="valid"+d.level,f="i"+C,b=d.dataLevel=g.dataLevel+1,p="data"+b,y=g.baseId;if(n+="var "+u+" = errors;var "+c+";",Array.isArray(o)){var Z=g.schema.additionalItems;if(Z===!1){n+=" "+c+" = "+l+".length <= "+o.length+"; ";var B=s;s=g.errSchemaPath+"/additionalItems",n+=" if (!"+c+") { ";var G=G||[];G.push(n),n="",g.createErrors!==!1?(n+=" { keyword: 'additionalItems' , dataPath: (dataPath || '') + "+g.errorPath+" , schemaPath: "+g.util.toQuotedString(s)+" , params: { limit: "+o.length+" } ",g.opts.messages!==!1&&(n+=" , message: 'should NOT have more than "+o.length+" items' "),g.opts.verbose&&(n+=" , schema: false , parentSchema: validate.schema"+g.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ";var v=n;n=G.pop(),!g.compositeRule&&a?g.async?n+=" throw new ValidationError(["+v+"]); ":n+=" validate.errors = ["+v+"]; return false; ":n+=" var err = "+v+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",n+=" } ",s=B,a&&(h+="}",n+=" else { ")}var w=o;if(w){for(var V,S=-1,X=w.length-1;S0||V===!1:g.util.schemaHasRules(V,g.RULES.all)){n+=" "+m+" = true; if ("+l+".length > "+S+") { ";var W=l+"["+S+"]";d.schema=V,d.schemaPath=A+"["+S+"]",d.errSchemaPath=s+"/"+S,d.errorPath=g.util.getPathExpr(g.errorPath,S,g.opts.jsonPointers,!0),d.dataPathArr[b]=S;var R=g.validate(d);d.baseId=y,g.util.varOccurences(R,p)<2?n+=" "+g.util.varReplace(R,p,W)+" ":n+=" var "+p+" = "+W+"; "+R+" ",n+=" } ",a&&(n+=" if ("+m+") { ",h+="}")}}if(typeof Z=="object"&&(g.opts.strictKeywords?typeof Z=="object"&&Object.keys(Z).length>0||Z===!1:g.util.schemaHasRules(Z,g.RULES.all))){d.schema=Z,d.schemaPath=g.schemaPath+".additionalItems",d.errSchemaPath=g.errSchemaPath+"/additionalItems",n+=" "+m+" = true; if ("+l+".length > "+o.length+") { for (var "+f+" = "+o.length+"; "+f+" < "+l+".length; "+f+"++) { ",d.errorPath=g.util.getPathExpr(g.errorPath,f,g.opts.jsonPointers,!0);var W=l+"["+f+"]";d.dataPathArr[b]=f;var R=g.validate(d);d.baseId=y,g.util.varOccurences(R,p)<2?n+=" "+g.util.varReplace(R,p,W)+" ":n+=" var "+p+" = "+W+"; "+R+" ",a&&(n+=" if (!"+m+") break; "),n+=" } } ",a&&(n+=" if ("+m+") { ",h+="}")}}else if(g.opts.strictKeywords?typeof o=="object"&&Object.keys(o).length>0||o===!1:g.util.schemaHasRules(o,g.RULES.all)){d.schema=o,d.schemaPath=A,d.errSchemaPath=s,n+=" for (var "+f+" = 0; "+f+" < "+l+".length; "+f+"++) { ",d.errorPath=g.util.getPathExpr(g.errorPath,f,g.opts.jsonPointers,!0);var W=l+"["+f+"]";d.dataPathArr[b]=f;var R=g.validate(d);d.baseId=y,g.util.varOccurences(R,p)<2?n+=" "+g.util.varReplace(R,p,W)+" ":n+=" var "+p+" = "+W+"; "+R+" ",a&&(n+=" if (!"+m+") break; "),n+=" }"}return a&&(n+=" "+h+" if ("+u+" == errors) {"),n},Uee=function(g,I,i){var n=" ",C=g.level,r=g.dataLevel,o=g.schema[I],A=g.schemaPath+g.util.getProperty(I),s=g.errSchemaPath+"/"+I,a=!g.opts.allErrors,y,l="data"+(r||""),c=g.opts.$data&&o&&o.$data,u;c?(n+=" var schema"+C+" = "+g.util.getData(o.$data,r,g.dataPathArr)+"; ",u="schema"+C):u=o;var d=I=="maximum",h=d?"exclusiveMaximum":"exclusiveMinimum",m=g.schema[h],f=g.opts.$data&&m&&m.$data,b=d?"<":">",p=d?">":"<",y=void 0;if(!(c||typeof o=="number"||o===void 0))throw new Error(I+" must be number");if(!(f||m===void 0||typeof m=="number"||typeof m=="boolean"))throw new Error(h+" must be number or boolean");if(f){var Z=g.util.getData(m.$data,r,g.dataPathArr),B="exclusive"+C,G="exclType"+C,v="exclIsNumber"+C,w="op"+C,V="' + "+w+" + '";n+=" var schemaExcl"+C+" = "+Z+"; ",Z="schemaExcl"+C,n+=" var "+B+"; var "+G+" = typeof "+Z+"; if ("+G+" != 'boolean' && "+G+" != 'undefined' && "+G+" != 'number') { ";var y=h,S=S||[];S.push(n),n="",g.createErrors!==!1?(n+=" { keyword: '"+(y||"_exclusiveLimit")+"' , dataPath: (dataPath || '') + "+g.errorPath+" , schemaPath: "+g.util.toQuotedString(s)+" , params: {} ",g.opts.messages!==!1&&(n+=" , message: '"+h+" should be boolean' "),g.opts.verbose&&(n+=" , schema: validate.schema"+A+" , parentSchema: validate.schema"+g.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ";var X=n;n=S.pop(),!g.compositeRule&&a?g.async?n+=" throw new ValidationError(["+X+"]); ":n+=" validate.errors = ["+X+"]; return false; ":n+=" var err = "+X+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",n+=" } else if ( ",c&&(n+=" ("+u+" !== undefined && typeof "+u+" != 'number') || "),n+=" "+G+" == 'number' ? ( ("+B+" = "+u+" === undefined || "+Z+" "+b+"= "+u+") ? "+l+" "+p+"= "+Z+" : "+l+" "+p+" "+u+" ) : ( ("+B+" = "+Z+" === true) ? "+l+" "+p+"= "+u+" : "+l+" "+p+" "+u+" ) || "+l+" !== "+l+") { var op"+C+" = "+B+" ? '"+b+"' : '"+b+"='; ",o===void 0&&(y=h,s=g.errSchemaPath+"/"+h,u=Z,c=f)}else{var v=typeof m=="number",V=b;if(v&&c){var w="'"+V+"'";n+=" if ( ",c&&(n+=" ("+u+" !== undefined && typeof "+u+" != 'number') || "),n+=" ( "+u+" === undefined || "+m+" "+b+"= "+u+" ? "+l+" "+p+"= "+m+" : "+l+" "+p+" "+u+" ) || "+l+" !== "+l+") { "}else{v&&o===void 0?(B=!0,y=h,s=g.errSchemaPath+"/"+h,u=m,p+="="):(v&&(u=Math[d?"min":"max"](m,o)),m===(v?u:!0)?(B=!0,y=h,s=g.errSchemaPath+"/"+h,p+="="):(B=!1,V+="="));var w="'"+V+"'";n+=" if ( ",c&&(n+=" ("+u+" !== undefined && typeof "+u+" != 'number') || "),n+=" "+l+" "+p+" "+u+" || "+l+" !== "+l+") { "}}y=y||I;var S=S||[];S.push(n),n="",g.createErrors!==!1?(n+=" { keyword: '"+(y||"_limit")+"' , dataPath: (dataPath || '') + "+g.errorPath+" , schemaPath: "+g.util.toQuotedString(s)+" , params: { comparison: "+w+", limit: "+u+", exclusive: "+B+" } ",g.opts.messages!==!1&&(n+=" , message: 'should be "+V+" ",c?n+="' + "+u:n+=""+u+"'"),g.opts.verbose&&(n+=" , schema: ",c?n+="validate.schema"+A:n+=""+o,n+=" , parentSchema: validate.schema"+g.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ";var X=n;return n=S.pop(),!g.compositeRule&&a?g.async?n+=" throw new ValidationError(["+X+"]); ":n+=" validate.errors = ["+X+"]; return false; ":n+=" var err = "+X+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",n+=" } ",a&&(n+=" else { "),n},Qee=function(g,I,i){var n=" ",C=g.level,r=g.dataLevel,o=g.schema[I],A=g.schemaPath+g.util.getProperty(I),s=g.errSchemaPath+"/"+I,a=!g.opts.allErrors,h,l="data"+(r||""),c=g.opts.$data&&o&&o.$data,u;if(c?(n+=" var schema"+C+" = "+g.util.getData(o.$data,r,g.dataPathArr)+"; ",u="schema"+C):u=o,!(c||typeof o=="number"))throw new Error(I+" must be number");var d=I=="maxItems"?">":"<";n+="if ( ",c&&(n+=" ("+u+" !== undefined && typeof "+u+" != 'number') || "),n+=" "+l+".length "+d+" "+u+") { ";var h=I,m=m||[];m.push(n),n="",g.createErrors!==!1?(n+=" { keyword: '"+(h||"_limitItems")+"' , dataPath: (dataPath || '') + "+g.errorPath+" , schemaPath: "+g.util.toQuotedString(s)+" , params: { limit: "+u+" } ",g.opts.messages!==!1&&(n+=" , message: 'should NOT have ",I=="maxItems"?n+="more":n+="fewer",n+=" than ",c?n+="' + "+u+" + '":n+=""+o,n+=" items' "),g.opts.verbose&&(n+=" , schema: ",c?n+="validate.schema"+A:n+=""+o,n+=" , parentSchema: validate.schema"+g.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ";var f=n;return n=m.pop(),!g.compositeRule&&a?g.async?n+=" throw new ValidationError(["+f+"]); ":n+=" validate.errors = ["+f+"]; return false; ":n+=" var err = "+f+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",n+="} ",a&&(n+=" else { "),n},jee=function(g,I,i){var n=" ",C=g.level,r=g.dataLevel,o=g.schema[I],A=g.schemaPath+g.util.getProperty(I),s=g.errSchemaPath+"/"+I,a=!g.opts.allErrors,h,l="data"+(r||""),c=g.opts.$data&&o&&o.$data,u;if(c?(n+=" var schema"+C+" = "+g.util.getData(o.$data,r,g.dataPathArr)+"; ",u="schema"+C):u=o,!(c||typeof o=="number"))throw new Error(I+" must be number");var d=I=="maxLength"?">":"<";n+="if ( ",c&&(n+=" ("+u+" !== undefined && typeof "+u+" != 'number') || "),g.opts.unicode===!1?n+=" "+l+".length ":n+=" ucs2length("+l+") ",n+=" "+d+" "+u+") { ";var h=I,m=m||[];m.push(n),n="",g.createErrors!==!1?(n+=" { keyword: '"+(h||"_limitLength")+"' , dataPath: (dataPath || '') + "+g.errorPath+" , schemaPath: "+g.util.toQuotedString(s)+" , params: { limit: "+u+" } ",g.opts.messages!==!1&&(n+=" , message: 'should NOT be ",I=="maxLength"?n+="longer":n+="shorter",n+=" than ",c?n+="' + "+u+" + '":n+=""+o,n+=" characters' "),g.opts.verbose&&(n+=" , schema: ",c?n+="validate.schema"+A:n+=""+o,n+=" , parentSchema: validate.schema"+g.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ";var f=n;return n=m.pop(),!g.compositeRule&&a?g.async?n+=" throw new ValidationError(["+f+"]); ":n+=" validate.errors = ["+f+"]; return false; ":n+=" var err = "+f+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",n+="} ",a&&(n+=" else { "),n},$ee=function(g,I,i){var n=" ",C=g.level,r=g.dataLevel,o=g.schema[I],A=g.schemaPath+g.util.getProperty(I),s=g.errSchemaPath+"/"+I,a=!g.opts.allErrors,h,l="data"+(r||""),c=g.opts.$data&&o&&o.$data,u;if(c?(n+=" var schema"+C+" = "+g.util.getData(o.$data,r,g.dataPathArr)+"; ",u="schema"+C):u=o,!(c||typeof o=="number"))throw new Error(I+" must be number");var d=I=="maxProperties"?">":"<";n+="if ( ",c&&(n+=" ("+u+" !== undefined && typeof "+u+" != 'number') || "),n+=" Object.keys("+l+").length "+d+" "+u+") { ";var h=I,m=m||[];m.push(n),n="",g.createErrors!==!1?(n+=" { keyword: '"+(h||"_limitProperties")+"' , dataPath: (dataPath || '') + "+g.errorPath+" , schemaPath: "+g.util.toQuotedString(s)+" , params: { limit: "+u+" } ",g.opts.messages!==!1&&(n+=" , message: 'should NOT have ",I=="maxProperties"?n+="more":n+="fewer",n+=" than ",c?n+="' + "+u+" + '":n+=""+o,n+=" properties' "),g.opts.verbose&&(n+=" , schema: ",c?n+="validate.schema"+A:n+=""+o,n+=" , parentSchema: validate.schema"+g.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ";var f=n;return n=m.pop(),!g.compositeRule&&a?g.async?n+=" throw new ValidationError(["+f+"]); ":n+=" validate.errors = ["+f+"]; return false; ":n+=" var err = "+f+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",n+="} ",a&&(n+=" else { "),n},k4e=function(g,I,i){var n=" ",C=g.level,r=g.dataLevel,o=g.schema[I],A=g.schemaPath+g.util.getProperty(I),s=g.errSchemaPath+"/"+I,a=!g.opts.allErrors,l="data"+(r||""),c=g.opts.$data&&o&&o.$data,u;if(c?(n+=" var schema"+C+" = "+g.util.getData(o.$data,r,g.dataPathArr)+"; ",u="schema"+C):u=o,!(c||typeof o=="number"))throw new Error(I+" must be number");n+="var division"+C+";if (",c&&(n+=" "+u+" !== undefined && ( typeof "+u+" != 'number' || "),n+=" (division"+C+" = "+l+" / "+u+", ",g.opts.multipleOfPrecision?n+=" Math.abs(Math.round(division"+C+") - division"+C+") > 1e-"+g.opts.multipleOfPrecision+" ":n+=" division"+C+" !== parseInt(division"+C+") ",n+=" ) ",c&&(n+=" ) "),n+=" ) { ";var d=d||[];d.push(n),n="",g.createErrors!==!1?(n+=" { keyword: 'multipleOf' , dataPath: (dataPath || '') + "+g.errorPath+" , schemaPath: "+g.util.toQuotedString(s)+" , params: { multipleOf: "+u+" } ",g.opts.messages!==!1&&(n+=" , message: 'should be multiple of ",c?n+="' + "+u:n+=""+u+"'"),g.opts.verbose&&(n+=" , schema: ",c?n+="validate.schema"+A:n+=""+o,n+=" , parentSchema: validate.schema"+g.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ";var h=n;return n=d.pop(),!g.compositeRule&&a?g.async?n+=" throw new ValidationError(["+h+"]); ":n+=" validate.errors = ["+h+"]; return false; ":n+=" var err = "+h+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",n+="} ",a&&(n+=" else { "),n},Y4e=function(g,I,i){var n=" ",C=g.level,r=g.dataLevel,o=g.schema[I],A=g.schemaPath+g.util.getProperty(I),s=g.errSchemaPath+"/"+I,a=!g.opts.allErrors,l="data"+(r||""),c="errs__"+C,u=g.util.copy(g);u.level++;var d="valid"+u.level;if(g.opts.strictKeywords?typeof o=="object"&&Object.keys(o).length>0||o===!1:g.util.schemaHasRules(o,g.RULES.all)){u.schema=o,u.schemaPath=A,u.errSchemaPath=s,n+=" var "+c+" = errors; ";var h=g.compositeRule;g.compositeRule=u.compositeRule=!0,u.createErrors=!1;var m;u.opts.allErrors&&(m=u.opts.allErrors,u.opts.allErrors=!1),n+=" "+g.validate(u)+" ",u.createErrors=!0,m&&(u.opts.allErrors=m),g.compositeRule=u.compositeRule=h,n+=" if ("+d+") { ";var f=f||[];f.push(n),n="",g.createErrors!==!1?(n+=" { keyword: 'not' , dataPath: (dataPath || '') + "+g.errorPath+" , schemaPath: "+g.util.toQuotedString(s)+" , params: {} ",g.opts.messages!==!1&&(n+=" , message: 'should NOT be valid' "),g.opts.verbose&&(n+=" , schema: validate.schema"+A+" , parentSchema: validate.schema"+g.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ";var b=n;n=f.pop(),!g.compositeRule&&a?g.async?n+=" throw new ValidationError(["+b+"]); ":n+=" validate.errors = ["+b+"]; return false; ":n+=" var err = "+b+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",n+=" } else { errors = "+c+"; if (vErrors !== null) { if ("+c+") vErrors.length = "+c+"; else vErrors = null; } ",g.opts.allErrors&&(n+=" } ")}else n+=" var err = ",g.createErrors!==!1?(n+=" { keyword: 'not' , dataPath: (dataPath || '') + "+g.errorPath+" , schemaPath: "+g.util.toQuotedString(s)+" , params: {} ",g.opts.messages!==!1&&(n+=" , message: 'should NOT be valid' "),g.opts.verbose&&(n+=" , schema: validate.schema"+A+" , parentSchema: validate.schema"+g.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ",n+="; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",a&&(n+=" if (false) { ");return n},K4e=function(g,I,i){var n=" ",C=g.level,r=g.dataLevel,o=g.schema[I],A=g.schemaPath+g.util.getProperty(I),s=g.errSchemaPath+"/"+I,a=!g.opts.allErrors,l="data"+(r||""),c="valid"+C,u="errs__"+C,d=g.util.copy(g),h="";d.level++;var m="valid"+d.level,f=d.baseId,b="prevValid"+C,p="passingSchemas"+C;n+="var "+u+" = errors , "+b+" = false , "+c+" = false , "+p+" = null; ";var y=g.compositeRule;g.compositeRule=d.compositeRule=!0;var Z=o;if(Z)for(var B,G=-1,v=Z.length-1;G0||B===!1:g.util.schemaHasRules(B,g.RULES.all))?(d.schema=B,d.schemaPath=A+"["+G+"]",d.errSchemaPath=s+"/"+G,n+=" "+g.validate(d)+" ",d.baseId=f):n+=" var "+m+" = true; ",G&&(n+=" if ("+m+" && "+b+") { "+c+" = false; "+p+" = ["+p+", "+G+"]; } else { ",h+="}"),n+=" if ("+m+") { "+c+" = "+b+" = true; "+p+" = "+G+"; }";return g.compositeRule=d.compositeRule=y,n+=""+h+"if (!"+c+") { var err = ",g.createErrors!==!1?(n+=" { keyword: 'oneOf' , dataPath: (dataPath || '') + "+g.errorPath+" , schemaPath: "+g.util.toQuotedString(s)+" , params: { passingSchemas: "+p+" } ",g.opts.messages!==!1&&(n+=" , message: 'should match exactly one schema in oneOf' "),g.opts.verbose&&(n+=" , schema: validate.schema"+A+" , parentSchema: validate.schema"+g.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ",n+="; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",!g.compositeRule&&a&&(g.async?n+=" throw new ValidationError(vErrors); ":n+=" validate.errors = vErrors; return false; "),n+="} else { errors = "+u+"; if (vErrors !== null) { if ("+u+") vErrors.length = "+u+"; else vErrors = null; }",g.opts.allErrors&&(n+=" } "),n},D4e=function(g,I,i){var n=" ",C=g.level,r=g.dataLevel,o=g.schema[I],A=g.schemaPath+g.util.getProperty(I),s=g.errSchemaPath+"/"+I,a=!g.opts.allErrors,l="data"+(r||""),c=g.opts.$data&&o&&o.$data,u;c?(n+=" var schema"+C+" = "+g.util.getData(o.$data,r,g.dataPathArr)+"; ",u="schema"+C):u=o;var d=c?"(new RegExp("+u+"))":g.usePattern(o);n+="if ( ",c&&(n+=" ("+u+" !== undefined && typeof "+u+" != 'string') || "),n+=" !"+d+".test("+l+") ) { ";var h=h||[];h.push(n),n="",g.createErrors!==!1?(n+=" { keyword: 'pattern' , dataPath: (dataPath || '') + "+g.errorPath+" , schemaPath: "+g.util.toQuotedString(s)+" , params: { pattern: ",c?n+=""+u:n+=""+g.util.toQuotedString(o),n+=" } ",g.opts.messages!==!1&&(n+=` , message: 'should match pattern "`,c?n+="' + "+u+" + '":n+=""+g.util.escapeQuotes(o),n+=`"' `),g.opts.verbose&&(n+=" , schema: ",c?n+="validate.schema"+A:n+=""+g.util.toQuotedString(o),n+=" , parentSchema: validate.schema"+g.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ";var m=n;return n=h.pop(),!g.compositeRule&&a?g.async?n+=" throw new ValidationError(["+m+"]); ":n+=" validate.errors = ["+m+"]; return false; ":n+=" var err = "+m+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",n+="} ",a&&(n+=" else { "),n},x4e=function(g,I,i){var n=" ",C=g.level,r=g.dataLevel,o=g.schema[I],A=g.schemaPath+g.util.getProperty(I),s=g.errSchemaPath+"/"+I,a=!g.opts.allErrors,l="data"+(r||""),c="errs__"+C,u=g.util.copy(g),d="";u.level++;var h="valid"+u.level,m="key"+C,f="idx"+C,b=u.dataLevel=g.dataLevel+1,p="data"+b,y="dataProperties"+C,Z=Object.keys(o||{}).filter(E),B=g.schema.patternProperties||{},G=Object.keys(B).filter(E),v=g.schema.additionalProperties,w=Z.length||G.length,V=v===!1,S=typeof v=="object"&&Object.keys(v).length,X=g.opts.removeAdditional,W=V||S||X,R=g.opts.ownProperties,H=g.baseId,Y=g.schema.required;if(Y&&!(g.opts.$data&&Y.$data)&&Y.length8)n+=" || validate.schema"+A+".hasOwnProperty("+m+") ";else{var O=Z;if(O)for(var J,ee=-1,q=O.length-1;ee0||_e===!1:g.util.schemaHasRules(_e,g.RULES.all)){var ot=g.util.getProperty(J),Ne=l+ot,Zt=Pe&&_e.default!==void 0;u.schema=_e,u.schemaPath=A+ot,u.errSchemaPath=s+"/"+g.util.escapeFragment(J),u.errorPath=g.util.getPath(g.errorPath,J,g.opts.jsonPointers),u.dataPathArr[b]=g.util.toQuotedString(J);var Se=g.validate(u);if(u.baseId=H,g.util.varOccurences(Se,p)<2){Se=g.util.varReplace(Se,p,Ne);var nt=Ne}else{var nt=p;n+=" var "+p+" = "+Ne+"; "}if(Zt)n+=" "+Se+" ";else{if(D&&D[J]){n+=" if ( "+nt+" === undefined ",R&&(n+=" || ! Object.prototype.hasOwnProperty.call("+l+", '"+g.util.escapeQuotes(J)+"') "),n+=") { "+h+" = false; ";var ie=g.errorPath,Ce=s,Te=g.util.escapeQuotes(J);g.opts._errorDataPathProperty&&(g.errorPath=g.util.getPath(ie,J,g.opts.jsonPointers)),s=g.errSchemaPath+"/required";var Ze=Ze||[];Ze.push(n),n="",g.createErrors!==!1?(n+=" { keyword: 'required' , dataPath: (dataPath || '') + "+g.errorPath+" , schemaPath: "+g.util.toQuotedString(s)+" , params: { missingProperty: '"+Te+"' } ",g.opts.messages!==!1&&(n+=" , message: '",g.opts._errorDataPathProperty?n+="is a required property":n+="should have required property \\'"+Te+"\\'",n+="' "),g.opts.verbose&&(n+=" , schema: validate.schema"+A+" , parentSchema: validate.schema"+g.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ";var Ge=n;n=Ze.pop(),!g.compositeRule&&a?g.async?n+=" throw new ValidationError(["+Ge+"]); ":n+=" validate.errors = ["+Ge+"]; return false; ":n+=" var err = "+Ge+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",s=Ce,g.errorPath=ie,n+=" } else { "}else a?(n+=" if ( "+nt+" === undefined ",R&&(n+=" || ! Object.prototype.hasOwnProperty.call("+l+", '"+g.util.escapeQuotes(J)+"') "),n+=") { "+h+" = true; } else { "):(n+=" if ("+nt+" !== undefined ",R&&(n+=" && Object.prototype.hasOwnProperty.call("+l+", '"+g.util.escapeQuotes(J)+"') "),n+=" ) { ");n+=" "+Se+" } "}}a&&(n+=" if ("+h+") { ",d+="}")}}if(G.length){var se=G;if(se)for(var j,ye=-1,Xe=se.length-1;ye0||_e===!1:g.util.schemaHasRules(_e,g.RULES.all)){u.schema=_e,u.schemaPath=g.schemaPath+".patternProperties"+g.util.getProperty(j),u.errSchemaPath=g.errSchemaPath+"/patternProperties/"+g.util.escapeFragment(j),R?n+=" "+y+" = "+y+" || Object.keys("+l+"); for (var "+f+"=0; "+f+"<"+y+".length; "+f+"++) { var "+m+" = "+y+"["+f+"]; ":n+=" for (var "+m+" in "+l+") { ",n+=" if ("+g.usePattern(j)+".test("+m+")) { ",u.errorPath=g.util.getPathExpr(g.errorPath,m,g.opts.jsonPointers);var Ne=l+"["+m+"]";u.dataPathArr[b]=m;var Se=g.validate(u);u.baseId=H,g.util.varOccurences(Se,p)<2?n+=" "+g.util.varReplace(Se,p,Ne)+" ":n+=" var "+p+" = "+Ne+"; "+Se+" ",a&&(n+=" if (!"+h+") break; "),n+=" } ",a&&(n+=" else "+h+" = true; "),n+=" } ",a&&(n+=" if ("+h+") { ",d+="}")}}}return a&&(n+=" "+d+" if ("+c+" == errors) {"),n},F4e=function(g,I,i){var n=" ",C=g.level,r=g.dataLevel,o=g.schema[I],A=g.schemaPath+g.util.getProperty(I),s=g.errSchemaPath+"/"+I,a=!g.opts.allErrors,l="data"+(r||""),c="errs__"+C,u=g.util.copy(g),d="";u.level++;var h="valid"+u.level;if(n+="var "+c+" = errors;",g.opts.strictKeywords?typeof o=="object"&&Object.keys(o).length>0||o===!1:g.util.schemaHasRules(o,g.RULES.all)){u.schema=o,u.schemaPath=A,u.errSchemaPath=s;var m="key"+C,f="idx"+C,b="i"+C,p="' + "+m+" + '",y=u.dataLevel=g.dataLevel+1,Z="data"+y,B="dataProperties"+C,G=g.opts.ownProperties,v=g.baseId;G&&(n+=" var "+B+" = undefined; "),G?n+=" "+B+" = "+B+" || Object.keys("+l+"); for (var "+f+"=0; "+f+"<"+B+".length; "+f+"++) { var "+m+" = "+B+"["+f+"]; ":n+=" for (var "+m+" in "+l+") { ",n+=" var startErrs"+C+" = errors; ";var w=m,V=g.compositeRule;g.compositeRule=u.compositeRule=!0;var S=g.validate(u);u.baseId=v,g.util.varOccurences(S,Z)<2?n+=" "+g.util.varReplace(S,Z,w)+" ":n+=" var "+Z+" = "+w+"; "+S+" ",g.compositeRule=u.compositeRule=V,n+=" if (!"+h+") { for (var "+b+"=startErrs"+C+"; "+b+"0||y===!1:g.util.schemaHasRules(y,g.RULES.all))||(h[h.length]=f)}}else var h=o;if(u||h.length){var Z=g.errorPath,B=u||h.length>=g.opts.loopRequired,G=g.opts.ownProperties;if(a)if(n+=" var missing"+C+"; ",B){u||(n+=" var "+d+" = validate.schema"+A+"; ");var v="i"+C,w="schema"+C+"["+v+"]",V="' + "+w+" + '";g.opts._errorDataPathProperty&&(g.errorPath=g.util.getPathExpr(Z,w,g.opts.jsonPointers)),n+=" var "+c+" = true; ",u&&(n+=" if (schema"+C+" === undefined) "+c+" = true; else if (!Array.isArray(schema"+C+")) "+c+" = false; else {"),n+=" for (var "+v+" = 0; "+v+" < "+d+".length; "+v+"++) { "+c+" = "+l+"["+d+"["+v+"]] !== undefined ",G&&(n+=" && Object.prototype.hasOwnProperty.call("+l+", "+d+"["+v+"]) "),n+="; if (!"+c+") break; } ",u&&(n+=" } "),n+=" if (!"+c+") { ";var S=S||[];S.push(n),n="",g.createErrors!==!1?(n+=" { keyword: 'required' , dataPath: (dataPath || '') + "+g.errorPath+" , schemaPath: "+g.util.toQuotedString(s)+" , params: { missingProperty: '"+V+"' } ",g.opts.messages!==!1&&(n+=" , message: '",g.opts._errorDataPathProperty?n+="is a required property":n+="should have required property \\'"+V+"\\'",n+="' "),g.opts.verbose&&(n+=" , schema: validate.schema"+A+" , parentSchema: validate.schema"+g.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ";var X=n;n=S.pop(),!g.compositeRule&&a?g.async?n+=" throw new ValidationError(["+X+"]); ":n+=" validate.errors = ["+X+"]; return false; ":n+=" var err = "+X+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",n+=" } else { "}else{n+=" if ( ";var W=h;if(W)for(var R,v=-1,H=W.length-1;v 1) { ";var h=g.schema.items&&g.schema.items.type,m=Array.isArray(h);if(!h||h=="object"||h=="array"||m&&(h.indexOf("object")>=0||h.indexOf("array")>=0))n+=" outer: for (;i--;) { for (j = i; j--;) { if (equal("+l+"[i], "+l+"[j])) { "+c+" = false; break outer; } } } ";else{n+=" var itemIndices = {}, item; for (;i--;) { var item = "+l+"[i]; ";var f="checkDataType"+(m?"s":"");n+=" if ("+g.util[f](h,"item",g.opts.strictNumbers,!0)+") continue; ",m&&(n+=` if (typeof item == 'string') item = '"' + item; `),n+=" if (typeof itemIndices[item] == 'number') { "+c+" = false; j = itemIndices[item]; break; } itemIndices[item] = i; } "}n+=" } ",u&&(n+=" } "),n+=" if (!"+c+") { ";var b=b||[];b.push(n),n="",g.createErrors!==!1?(n+=" { keyword: 'uniqueItems' , dataPath: (dataPath || '') + "+g.errorPath+" , schemaPath: "+g.util.toQuotedString(s)+" , params: { i: i, j: j } ",g.opts.messages!==!1&&(n+=" , message: 'should NOT have duplicate items (items ## ' + j + ' and ' + i + ' are identical)' "),g.opts.verbose&&(n+=" , schema: ",u?n+="validate.schema"+A:n+=""+o,n+=" , parentSchema: validate.schema"+g.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ";var p=n;n=b.pop(),!g.compositeRule&&a?g.async?n+=" throw new ValidationError(["+p+"]); ":n+=" validate.errors = ["+p+"]; return false; ":n+=" var err = "+p+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",n+=" } ",a&&(n+=" else { ")}else a&&(n+=" if (true) { ");return n},z4e={$ref:v4e,allOf:B4e,anyOf:S4e,$comment:w4e,const:V4e,contains:R4e,dependencies:W4e,enum:X4e,format:H4e,if:T4e,items:N4e,maximum:Uee,minimum:Uee,maxItems:Qee,minItems:Qee,maxLength:jee,minLength:jee,maxProperties:$ee,minProperties:$ee,multipleOf:k4e,not:Y4e,oneOf:K4e,pattern:D4e,properties:x4e,propertyNames:F4e,required:E4e,uniqueItems:M4e,validate:Bpe},qee=z4e,WK=Z0.toHash,P4e=function(){var g=[{type:"number",rules:[{maximum:["exclusiveMaximum"]},{minimum:["exclusiveMinimum"]},"multipleOf","format"]},{type:"string",rules:["maxLength","minLength","pattern","format"]},{type:"array",rules:["maxItems","minItems","items","contains","uniqueItems"]},{type:"object",rules:["maxProperties","minProperties","required","dependencies","propertyNames",{properties:["additionalProperties","patternProperties"]}]},{rules:["$ref","const","enum","not","anyOf","oneOf","allOf","if"]}],I=["type","$comment"],i=["$schema","$id","id","$data","$async","title","description","default","definitions","examples","readOnly","writeOnly","contentMediaType","contentEncoding","additionalItems","then","else"],n=["number","integer","string","array","object","boolean","null"];return g.all=WK(I),g.types=WK(n),g.forEach(function(C){C.rules=C.rules.map(function(r){var o;if(typeof r=="object"){var A=Object.keys(r)[0];o=r[A],r=A,o.forEach(function(a){I.push(a),g.all[a]=!0})}I.push(r);var s=g.all[r]={keyword:r,code:qee[r],implements:o};return s}),g.all.$comment={keyword:"$comment",code:qee.$comment},C.type&&(g.types[C.type]=C)}),g.keywords=WK(I.concat(i)),g.custom={},g},ete=["multipleOf","maximum","exclusiveMaximum","minimum","exclusiveMinimum","maxLength","minLength","pattern","additionalItems","maxItems","minItems","uniqueItems","maxProperties","minProperties","required","additionalProperties","enum","format","const"],J4e=function(e,g){for(var I=0;I{g(I,i,n),yX(I,g)}):"views"in e&&e.views.forEach(I=>yX(I,g))}function Ab(e,g){"tracks"in e?e.tracks.forEach(I=>{g(I),Ab(I,g)}):"views"in e&&e.views.forEach(I=>{g(I),Ab(I,g)})}function Lpe(e,g){"tracks"in e||(g(e),e.views.forEach(I=>{Lpe(I,g)}))}function Upe(e){if(mpe(e)){const I={...e,tracks:void 0,id:void 0};return e.tracks.filter(i=>!i._invalidTrack).map(i=>Object.assign(JSON.parse(JSON.stringify(I)),i))}const g=[];return rje(e)?e.tracks.filter(I=>!I._invalidTrack).map(I=>{if("alignment"in I)g.push({...I,_overlay:[...I.tracks],tracks:void 0,alignment:void 0});else{const i={...e,tracks:void 0,id:void 0},n=Object.assign(JSON.parse(JSON.stringify(i)),I);g.push(n)}}):g.push({...e,_overlay:[...e.tracks.filter(I=>!I._invalidTrack)],tracks:void 0,alignment:void 0}),JSON.parse(JSON.stringify(g))}function RM(e,g){if(g?(e.assembly===void 0&&(e.assembly=g.assembly),e.layout===void 0&&(e.layout=g.layout),e.orientation===void 0&&(e.orientation=g.orientation),e.static===void 0&&(e.static=g.static!==void 0?g.static:!1),e.zoomLimits===void 0&&(e.zoomLimits=g.zoomLimits),e.xDomain===void 0&&(e.xDomain=g.xDomain),e.yDomain===void 0&&(e.yDomain=g.yDomain),e.linkingId===void 0&&(e.linkingId=g.linkingId),e.centerRadius===void 0&&(e.centerRadius=g.centerRadius),e.spacing===void 0&&!("tracks"in e)&&(e.spacing=g.spacing),e.xOffset===void 0&&(e.xOffset=g.xOffset),e.yOffset===void 0&&(e.yOffset=g.yOffset),"views"in e&&"arrangement"in g&&e.arrangement===void 0&&(e.arrangement=g.arrangement),e.style=HK(g.style,e.style)):(e.assembly===void 0&&(e.assembly="hg38"),e.layout===void 0&&(e.layout="linear"),e.orientation===void 0&&(e.orientation="horizontal"),e.static===void 0&&(e.static=!1),e.zoomLimits===void 0&&(e.zoomLimits=[1,null]),e.centerRadius===void 0&&(e.centerRadius=cpe),e.spacing===void 0&&(e.spacing=s1),"views"in e&&e.arrangement===void 0&&(e.arrangement="vertical"),e.xOffset===void 0&&(e.xOffset=0),e.yOffset===void 0&&(e.yOffset=0)),e.id||(e.id=rn()),"tracks"in e){let I=Upe(e);I=hpe(I);const i=rn();I.forEach((n,C,r)=>{var o,A,s;if(n.id||(n.id=rn()),n.width||(n.width=qn(n)?Fee:vQe),n.height||(n.height=qn(n)?Fee:GQe),"displacement"in n)if(((o=n.displacement)==null?void 0:o.type)==="pile"&&n.row===void 0&&st(n.x)&&n.x.field&&st(n.xe)&&n.xe.field){const a=rn(),l=n.x.field,c=n.xe.field,u=n.displacement.padding,d={type:"displace",newField:a,boundingBox:{startField:l,endField:c,padding:u},method:"pile"};n.dataTransform||(n.dataTransform=[]),n.dataTransform=[...n.dataTransform,d],n.row={field:a,type:"nominal"}}else(A=n.displacement)==null||A.type;if(n.layout&&(n.layout=void 0),n.zoomLimits&&(n.zoomLimits=void 0),n.assembly||(n.assembly=e.assembly),n.layout||(n.layout=e.layout),n.orientation||(n.orientation=e.orientation),n.static===void 0&&(n.static=e.static!==void 0?e.static:!1),n.zoomLimits||(n.zoomLimits=e.zoomLimits),n.layout=="circular"&&aS(n)){n._invalidTrack=!0;return}if(n.style=HK(e.style,n.style),ai(n)&&(n._overlay=n._overlay.filter(a=>!("type"in a&&a.type=="dummy-track")),n._overlay.forEach(a=>{a.style=HK(n.style,a.style)})),(n.layout==="circular"||qn(n))&&n.orientation==="vertical"&&(n.orientation="horizontal"),qn(n)&&(n.layout="linear",(Yr(n)||ai(n))&&st(n.y)&&!n.y.domain?n.y.domain=e.yDomain:ai(n)&&n._overlay.forEach(a=>{st(a.y)&&!a.y.domain&&(a.y.domain=e.yDomain)})),(Yr(n)||ai(n))&&st(n.x)&&!n.x.domain?n.x.domain=e.xDomain:ai(n)&&n._overlay.forEach(a=>{st(a.x)&&!a.x.domain&&(a.x.domain=e.xDomain)}),(Yr(n)||ai(n))&&st(n.x)&&!n.x.linkingId)n.x.linkingId=(s=e.linkingId)!=null?s:i;else if(ai(n)){let a=!1;n._overlay.forEach(l=>{var c;a||st(l.x)&&!l.x.linkingId&&(l.x.linkingId=(c=e.linkingId)!=null?c:i,a=!0)})}C===0&&(n.overlayOnPreviousTrack=!1),(C===0||C!==0&&I.slice(0,C).filter(a=>!a.overlayOnPreviousTrack).length===1&&n.overlayOnPreviousTrack===!0)&&((Yr(n)||ai(n))&&st(n.x)&&!n.x.axis?n.orientation==="vertical"?n.x.axis="left":n.x.axis="top":ai(n)&&n._overlay.forEach(a=>{st(a.x)&&!a.x.axis&&(n.orientation==="vertical"?a.x.axis="left":a.x.axis="top")})),(Yr(n)||ai(n))&&st(n.x)&&n.x.axis&&n.x.axis!=="none"?n.orientation==="vertical"?n.x.axis==="top"?n.x.axis="left":n.x.axis==="bottom"&&(n.x.axis="right"):n.x.axis==="left"?n.x.axis="top":n.x.axis==="right"&&(n.x.axis="bottom"):ai(n)&&n._overlay.forEach(a=>{st(a.x)&&a.x.axis&&a.x.axis!=="none"&&(n.orientation==="vertical"?a.x.axis==="top"?a.x.axis="left":a.x.axis==="bottom"&&(a.x.axis="right"):a.x.axis==="left"?a.x.axis="top":a.x.axis==="right"&&(a.x.axis="bottom"))}),C!==0&&(C===r.length-1&&r.slice(0,C+1).filter(a=>a.overlayOnPreviousTrack).lengtha.overlayOnPreviousTrack).length===r.length-C-1&&r.slice(0,C+1).filter(a=>a.overlayOnPreviousTrack).length{a.mark==="withinLink"&&a.flipY===void 0&&(a.flipY=!0)}))),n.overlayOnPreviousTrack&&r[C-1]&&(n.width=r[C-1].width,n.height=r[C-1].height,n.layout=r[C-1].layout,n.assembly=r[C-1].assembly)}),I=I.filter(n=>!n._invalidTrack),e.tracks=I}else e.views.forEach(I=>{RM(I,e)})}function L$e(e,g){return{data:{type:"vector",url:"",column:e,value:g},mark:"bar",x:{field:e,type:"genomic",axis:"top"},y:{field:g,type:"quantitative"},width:400,height:100}}function U$e(e,g,I,i){return i&&i.length<10?{data:{type:"multivec",url:"",row:e,column:g,value:I,categories:i},mark:"bar",x:{field:g,type:"genomic",axis:"top"},y:{field:I,type:"quantitative"},row:{field:e,type:"nominal",legend:!0},color:{field:e,type:"nominal"},width:400,height:100}:{data:{type:"multivec",url:"",row:e,column:g,value:I,categories:i},mark:"rect",x:{field:g,type:"genomic",axis:"top"},row:{field:e,type:"nominal",legend:!0},color:{field:I,type:"quantitative"},width:400,height:100}}function Q$e(e){yX(e,(g,I,i)=>{var n,C,r,o,A;if(!(!("data"in g)||!g.data||!lU(g.data))&&!("alignment"in g)&&oje(g))switch(g.data.type){case"vector":case"bigwig":i[I]=Object.assign(L$e((n=g.data.column)!=null?n:"position",(C=g.data.value)!=null?C:"value"),g);break;case"multivec":i[I]=Object.assign(U$e((r=g.data.row)!=null?r:"category",(o=g.data.column)!=null?o:"position",(A=g.data.value)!=null?A:"value",g.data.categories),g);break}})}const TK={chr1:248956422,chr2:242193529,chr3:198295559,chr4:190214555,chr5:181538259,chr6:170805979,chr7:159345973,chr8:145138636,chr9:138394717,chr10:133797422,chr11:135086622,chr12:133275309,chr13:114364328,chr14:107043718,chr15:101991189,chr16:90338345,chr17:83257441,chr18:80373285,chr19:58617616,chr20:64444167,chr21:46709983,chr22:50818468,chrX:156040895,chrY:57227415},NK={chr1:249250621,chr2:243199373,chr3:198022430,chr4:191154276,chr5:180915260,chr6:171115067,chr7:159138663,chr8:146364022,chr9:141213431,chr10:135534747,chr11:135006516,chr12:133851895,chr13:115169878,chr14:107349540,chr15:102531392,chr16:90354753,chr17:81195210,chr18:78077248,chr19:59128983,chr20:63025520,chr21:48129895,chr22:51304566,chrX:155270560,chrY:59373566,chrM:16571},kK={chr1:247249719,chr2:242951149,chr3:199501827,chr4:191273063,chr5:180857866,chr6:170899992,chr7:158821424,chr8:146274826,chr9:140273252,chr10:135374737,chr11:134452384,chr12:132349534,chr13:114142980,chr14:106368585,chr15:100338915,chr16:88827254,chr17:78774742,chr18:76117153,chr19:63811651,chr20:62435964,chr21:46944323,chr22:49691432,chrX:154913754,chrY:57772954,chrM:16571},YK={chr1:245522847,chr2:243018229,chr3:199505740,chr4:191411218,chr5:180857866,chr6:170975699,chr7:158628139,chr8:146274826,chr9:138429268,chr10:135413628,chr11:134452384,chr12:132449811,chr13:114142980,chr14:106368585,chr15:100338915,chr16:88827254,chr17:78774742,chr18:76117153,chr19:63811651,chr20:62435964,chr21:46944323,chr22:49554710,chrX:154824264,chrY:57701691,chrM:16571},KK={chr1:246127941,chr2:243615958,chr3:199344050,chr4:191731959,chr5:181034922,chr6:170914576,chr7:158545518,chr8:146308819,chr9:136372045,chr10:135037215,chr11:134482954,chr12:132078379,chr13:113042980,chr14:105311216,chr15:100256656,chr16:90041932,chr17:81860266,chr18:76115139,chr19:63811651,chr20:63741868,chr21:46976097,chr22:49396972,chrX:153692391,chrY:50286555,chrM:16571},DK={chr1:195471971,chr2:182113224,chr3:160039680,chr4:156508116,chr5:151834684,chr6:149736546,chr7:145441459,chr8:129401213,chr9:124595110,chr10:130694993,chr11:122082543,chr12:120129022,chr13:120421639,chr14:124902244,chr15:104043685,chr16:98207768,chr17:94987271,chr18:90702639,chr19:61431566,chrX:171031299,chrY:91744698,chrM:16299},xK={chr1:197195432,chr2:181748087,chr3:159599783,chr4:155630120,chr5:152537259,chr6:149517037,chr7:152524553,chr8:131738871,chr9:124076172,chr10:129993255,chr11:121843856,chr12:121257530,chr13:120284312,chr14:125194864,chr15:103494974,chr16:98319150,chr17:95272651,chr18:90772031,chr19:61342430,chrX:166650296,chrY:15902555,chrM:16299};function Ku(e,g,I=!1){const i=Object.entries(pI(g).interval),n={chromosome:"unknown",position:1/0},C={chromosome:"unknown",position:0};for(const r of i){const[o,A]=r,[s,a]=A;if(s<=e&&eC.position&&(C.chromosome=o,C.position=a)}return I?ei.join(" ")).join(` +`),I=new Blob([g],{type:"text/tsv"});return URL.createObjectURL(I)}function pI(e){if(e&&typeof e=="string"&&e in FK)return FK[e];if(Array.isArray(e)&&e.length!==0){const g=Object.fromEntries(e);return{size:g,interval:Zl(g),total:Gl(g),path:j$e(e)}}else return FK.hg38}const ll=e=>`https://s3.amazonaws.com/gosling-lang.org/data/${e}.chrom.sizes`,FK=Object.freeze({hg38:{size:TK,interval:Zl(TK),total:Gl(TK),path:ll("hg38")},hg19:{size:NK,interval:Zl(NK),total:Gl(NK),path:ll("hg19")},hg18:{size:kK,interval:Zl(kK),total:Gl(kK),path:ll("hg18")},hg17:{size:YK,interval:Zl(YK),total:Gl(YK),path:ll("hg17")},hg16:{size:KK,interval:Zl(KK),total:Gl(KK),path:ll("hg16")},mm10:{size:DK,interval:Zl(DK),total:Gl(DK),path:ll("mm10")},mm9:{size:xK,interval:Zl(xK),total:Gl(xK),path:ll("mm9")},unknown:{size:{chr:Number.MAX_VALUE},interval:{chr:[0,Number.MAX_VALUE]},total:Number.MAX_VALUE,path:ll("hg38")}});function $$e(e){switch(e){case"hg19":return"OHJakQICQD6gTD7skx4EWA";case"mm10":return"QDutvmyiSrec5nX4pA5WGQ";case"mm9":return"GUm5aBiLRCyz2PsBea7Yzg";case"hg38":default:return"P0PLbQMwTYGy-5uPIQid7A"}}function Zl(e){const g={};return Object.keys(e).reduce((I,i)=>(g[i]=[I,I+e[i]],I+e[i]),0),g}function Gl(e){return Object.values(e).reduce((g,I)=>g+I,0)}function q$e(e){const[g,I]=e.split(":");if(I){const[i,n]=I.split("-").map(C=>+C.replace(/,/g,""));if(!Number.isNaN(i)&&!Number.isNaN(n))return{chromosome:g,start:i,end:n}}return{chromosome:g}}class ZU{constructor(g,I,i){this.chromosome=g,this.start=I,this.end=i}static fromString(g){const I=q$e(g);return new ZU(I.chromosome,I.start,I.end)}toAbsoluteCoordinates(g,I=0){const i=pI(g),n=i.size[this.chromosome],C=i.interval[this.chromosome];if(n===void 0||C===void 0)throw new Error(`Chromosome name ${this.chromosome} is not valid`);let{start:r,end:o}=this;(r===void 0||o===void 0)&&([r,o]=[1,n]);const A=C[0];return[r+A-I,o+A+I]}}function Qpe(e,[g,I],i){const{x:n,xe:C,x1:r,x1e:o}=i,A=[n,C,r,o].filter(s=>s);return e.filter(s=>{if(A.length===0)return!0;if(A.length===1){const a=+s[A[0]];return typeof a=="number"&&g+s[u]).filter(u=>!isNaN(u)),l=Math.min(...a),c=Math.max(...a);return g<=c&&l<=I}})}LL(e=>e.pos).left;function WM(e,g,I){return Array.isArray(g)||(I?e=e.replace(I,"chr"):e.includes("chr")||(e=`chr${e}`)),e}class jpe extends lpe{constructor(){super(...arguments),ZQe(this,"read",async(g,I=0,i,n=0,C={})=>{const{headers:r={},signal:o,overrides:A={}}=C;i<1/0?r.range=`bytes=${n}-${n+i}`:i===1/0&&n!==0&&(r.range=`bytes=${n}-`);const s={...this.baseOverrides,...A,headers:{...r,...A.headers,...this.baseOverrides.headers},method:"GET",redirect:"follow",mode:"cors",signal:o},a=await this.fetch(this.url,s);if(!a.ok)throw new Error(`HTTP ${a.status} ${a.statusText} ${this.url}`);if(a.status===200||a.status===206){const l=await this.getBufferFromResponse(a),c=l.copy(g,I,0,Math.min(i,l.length)),u=a.headers.get("content-range"),d=/\/(\d+)$/.exec(u||"");return d&&d[1]&&(this._stat={size:parseInt(d[1],10)}),{bytesRead:c,buffer:g}}throw new Error(`HTTP ${a.status} fetching ${this.url}`)})}}window.higlassTracks=window.higlassTracks||{};window.higlassTracksByType=window.higlassTracksByType||{};window.higlassDataFetchersByType=window.higlassDataFetchersByType||{};const Ite=()=>Math.random().toString(36).substring(2,8),e8e=(e,{force:g=!1}={})=>{let I=Ite();for(;window.higlassTracks[I];)I=Ite();e.name=I,window.higlassTracks[e.name]=e,window.higlassTracksByType[e.config.type]&&!g?console.warn(`A track with the same type (${e.config.type}) was already registered. To override it, set force to true.`):window.higlassTracksByType[e.config.type]=e},t8e=(e,{force:g=!1}={})=>{window.higlassDataFetchersByType[e.config.type]&&!g?console.warn(`A data fetcher with the same type (${e.config.type}) was already registered. To override it, set force to true.`):window.higlassDataFetchersByType[e.config.type]=e},mu=(e,g={})=>{const{pluginType:I="track"}=g;I==="track"?e8e(e,g):I==="dataFetcher"&&t8e(e,g)};var lS={},XM={exports:{}},ite=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||typeof msCrypto<"u"&&typeof window.msCrypto.getRandomValues=="function"&&msCrypto.getRandomValues.bind(msCrypto);if(ite){var nte=new Uint8Array(16);XM.exports=function(){return ite(nte),nte}}else{var Cte=new Array(16);XM.exports=function(){for(var g=0,I;g<16;g++)g&3||(I=Math.random()*4294967296),Cte[g]=I>>>((g&3)<<3)&255;return Cte}}var g8e=XM.exports,$pe=[];for(var wV=0;wV<256;++wV)$pe[wV]=(wV+256).toString(16).substr(1);function I8e(e,g){var I=g||0,i=$pe;return[i[e[I++]],i[e[I++]],i[e[I++]],i[e[I++]],"-",i[e[I++]],i[e[I++]],"-",i[e[I++]],i[e[I++]],"-",i[e[I++]],i[e[I++]],"-",i[e[I++]],i[e[I++]],i[e[I++]],i[e[I++]],i[e[I++]],i[e[I++]]].join("")}var i8e=I8e,n8e=g8e,C8e=i8e;function r8e(e,g,I){var i=g&&I||0;typeof e=="string"&&(g=e==="binary"?new Array(16):null,e=null),e=e||{};var n=e.random||(e.rng||n8e)();if(n[6]=n[6]&15|64,n[8]=n[8]&63|128,g)for(var C=0;C<16;++C)g[i+C]=n[C];return g||C8e(n)}var o8e=r8e,HM=[],qpe={};for(var wm=0;wm<256;wm++)HM[wm]=(wm+256).toString(16).substr(1),qpe[HM[wm]]=wm;function A8e(e,g,I){var i=g&&I||0,n=0;for(g=g||[],e.toLowerCase().replace(/[0-9a-f]{2}/g,function(C){n<16&&(g[i+n++]=qpe[C])});n<16;)g[i+n++]=0;return g}function a8e(e,g){var I=g||0,i=HM;return i[e[I++]]+i[e[I++]]+i[e[I++]]+i[e[I++]]+"-"+i[e[I++]]+i[e[I++]]+"-"+i[e[I++]]+i[e[I++]]+"-"+i[e[I++]]+i[e[I++]]+"-"+i[e[I++]]+i[e[I++]]+i[e[I++]]+i[e[I++]]+i[e[I++]]+i[e[I++]]}var s8e={parse:A8e,unparse:a8e},ebe=o8e,tbe=s8e;lS.encode=function(e){var g=tbe.parse(e),I=new Buffer(g).toString("base64"),i=I.replace(/\+/g,"-").replace(/\//g,"_").substring(0,22);return i};lS.decode=function(e){var g=e.replace(/-/g,"+").replace(/_/g,"/")+"==";return tbe.unparse(new Buffer(g,"base64"))};lS.v4=function(){var e=ebe(null,new Buffer(16)),g=e.toString("base64"),I=g.replace(/\+/g,"-").replace(/\//g,"_").substring(0,22);return I};lS.nice=function(){var e=ebe(null,new Buffer(16));e[0]=e[0]&127;var g=e.toString("base64"),I=g.replace(/\+/g,"-").replace(/\//g,"_").substring(0,22);return I};var l8e=lS;const c8e=Fc(l8e);var u8e=function(){function e(g,I){for(var i=0;i1?I-1:0),n=1;nI;){if(i-I>600){var C=i-I+1,r=g-I+1,o=Math.log(C),A=.5*Math.exp(2*o/3),s=.5*Math.sqrt(o*A*(C-A)/C)*(r-C/2<0?-1:1),a=Math.max(I,Math.floor(g-r*A/C+s)),l=Math.min(i,Math.floor(g+(C-r)*A/C+s));gbe(e,g,a,l,n)}var c=e[g],u=I,d=i;for(Wy(e,I,g),n(e[i],c)>0&&Wy(e,I,i);u0;)d--}n(e[I],c)===0?Wy(e,I,d):(d++,Wy(e,d,i)),d<=g&&(I=d+1),g<=d&&(i=d-1)}}function Wy(e,g,I){var i=e[g];e[g]=e[I],e[I]=i}function v8e(e,g){return eg?1:0}class B8e{constructor(g=9){this._maxEntries=Math.max(4,g),this._minEntries=Math.max(2,Math.ceil(this._maxEntries*.4)),this.clear()}all(){return this._all(this.data,[])}search(g){let I=this.data;const i=[];if(!RV(g,I))return i;const n=this.toBBox,C=[];for(;I;){for(let r=0;r=0&&C[I].children.length>this._maxEntries;)this._split(C,I),I--;this._adjustParentBBoxes(n,C,I)}_split(g,I){const i=g[I],n=i.children.length,C=this._minEntries;this._chooseSplitAxis(i,C,n);const r=this._chooseSplitIndex(i,C,n),o=of(i.children.splice(r,i.children.length-r));o.height=i.height,o.leaf=i.leaf,Vm(i,this.toBBox),Vm(o,this.toBBox),I?g[I-1].children.push(o):this._splitRoot(i,o)}_splitRoot(g,I){this.data=of([g,I]),this.data.height=g.height+1,this.data.leaf=!1,Vm(this.data,this.toBBox)}_chooseSplitIndex(g,I,i){let n,C=1/0,r=1/0;for(let o=I;o<=i-I;o++){const A=bZ(g,0,o,this.toBBox),s=bZ(g,o,i,this.toBBox),a=W8e(A,s),l=EK(A)+EK(s);a=I;s--){const a=g.children[s];yZ(o,g.leaf?C(a):a),A+=VV(o)}return A}_adjustParentBBoxes(g,I,i){for(let n=i;n>=0;n--)yZ(I[n],g)}_condense(g){for(let I=g.length-1,i;I>=0;I--)g[I].children.length===0?I>0?(i=g[I-1].children,i.splice(i.indexOf(g[I]),1)):this.clear():Vm(g[I],this.toBBox)}}function S8e(e,g,I){if(!I)return g.indexOf(e);for(let i=0;i=e.minX&&g.maxY>=e.minY}function of(e){return{children:e,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function rte(e,g,I,i,n){const C=[g,I];for(;C.length;){if(I=C.pop(),g=C.pop(),I-g<=i)continue;const r=g+Math.ceil((I-g)/i/2)*i;G8e(e,r,g,I,n),C.push(g,r,r,I)}}function X8e(e){return Math.abs(e=Math.round(e))>=1e21?e.toLocaleString("en").replace(/,/g,""):e.toString(10)}function ZX(e,g){if((I=(e=g?e.toExponential(g-1):e.toExponential()).indexOf("e"))<0)return null;var I,i=e.slice(0,I);return[i.length>1?i[0]+i.slice(2):i,+e.slice(I+1)]}function NM(e){return e=ZX(Math.abs(e)),e?e[1]:NaN}function H8e(e,g){return function(I,i){for(var n=I.length,C=[],r=0,o=e[0],A=0;n>0&&o>0&&(A+o+1>i&&(o=Math.max(1,i-A)),C.push(I.substring(n-=o,n+o)),!((A+=o+1)>i));)o=e[r=(r+1)%e.length];return C.reverse().join(g)}}function T8e(e){return function(g){return g.replace(/[0-9]/g,function(I){return e[+I]})}}var N8e=/^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;function kM(e){if(!(g=N8e.exec(e)))throw new Error("invalid format: "+e);var g;return new GU({fill:g[1],align:g[2],sign:g[3],symbol:g[4],zero:g[5],width:g[6],comma:g[7],precision:g[8]&&g[8].slice(1),trim:g[9],type:g[10]})}kM.prototype=GU.prototype;function GU(e){this.fill=e.fill===void 0?" ":e.fill+"",this.align=e.align===void 0?">":e.align+"",this.sign=e.sign===void 0?"-":e.sign+"",this.symbol=e.symbol===void 0?"":e.symbol+"",this.zero=!!e.zero,this.width=e.width===void 0?void 0:+e.width,this.comma=!!e.comma,this.precision=e.precision===void 0?void 0:+e.precision,this.trim=!!e.trim,this.type=e.type===void 0?"":e.type+""}GU.prototype.toString=function(){return this.fill+this.align+this.sign+this.symbol+(this.zero?"0":"")+(this.width===void 0?"":Math.max(1,this.width|0))+(this.comma?",":"")+(this.precision===void 0?"":"."+Math.max(0,this.precision|0))+(this.trim?"~":"")+this.type};function k8e(e){e:for(var g=e.length,I=1,i=-1,n;I0&&(i=0);break}return i>0?e.slice(0,i)+e.slice(n+1):e}var Ibe;function Y8e(e,g){var I=ZX(e,g);if(!I)return e+"";var i=I[0],n=I[1],C=n-(Ibe=Math.max(-8,Math.min(8,Math.floor(n/3)))*3)+1,r=i.length;return C===r?i:C>r?i+new Array(C-r+1).join("0"):C>0?i.slice(0,C)+"."+i.slice(C):"0."+new Array(1-C).join("0")+ZX(e,Math.max(0,g+C-1))[0]}function ote(e,g){var I=ZX(e,g);if(!I)return e+"";var i=I[0],n=I[1];return n<0?"0."+new Array(-n).join("0")+i:i.length>n+1?i.slice(0,n+1)+"."+i.slice(n+1):i+new Array(n-i.length+2).join("0")}const Ate={"%":(e,g)=>(e*100).toFixed(g),b:e=>Math.round(e).toString(2),c:e=>e+"",d:X8e,e:(e,g)=>e.toExponential(g),f:(e,g)=>e.toFixed(g),g:(e,g)=>e.toPrecision(g),o:e=>Math.round(e).toString(8),p:(e,g)=>ote(e*100,g),r:ote,s:Y8e,X:e=>Math.round(e).toString(16).toUpperCase(),x:e=>Math.round(e).toString(16)};function ate(e){return e}var ste=Array.prototype.map,lte=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"];function K8e(e){var g=e.grouping===void 0||e.thousands===void 0?ate:H8e(ste.call(e.grouping,Number),e.thousands+""),I=e.currency===void 0?"":e.currency[0]+"",i=e.currency===void 0?"":e.currency[1]+"",n=e.decimal===void 0?".":e.decimal+"",C=e.numerals===void 0?ate:T8e(ste.call(e.numerals,String)),r=e.percent===void 0?"%":e.percent+"",o=e.minus===void 0?"−":e.minus+"",A=e.nan===void 0?"NaN":e.nan+"";function s(l){l=kM(l);var c=l.fill,u=l.align,d=l.sign,h=l.symbol,m=l.zero,f=l.width,b=l.comma,p=l.precision,y=l.trim,Z=l.type;Z==="n"?(b=!0,Z="g"):Ate[Z]||(p===void 0&&(p=12),y=!0,Z="g"),(m||c==="0"&&u==="=")&&(m=!0,c="0",u="=");var B=h==="$"?I:h==="#"&&/[boxX]/.test(Z)?"0"+Z.toLowerCase():"",G=h==="$"?i:/[%p]/.test(Z)?r:"",v=Ate[Z],w=/[defgprs%]/.test(Z);p=p===void 0?6:/[gprs]/.test(Z)?Math.max(1,Math.min(21,p)):Math.max(0,Math.min(20,p));function V(S){var X=B,W=G,R,H,Y;if(Z==="c")W=v(S)+W,S="";else{S=+S;var D=S<0||1/S<0;if(S=isNaN(S)?A:v(Math.abs(S),p),y&&(S=k8e(S)),D&&+S==0&&d!=="+"&&(D=!1),X=(D?d==="("?d:o:d==="-"||d==="("?"":d)+X,W=(Z==="s"?lte[8+Ibe/3]:"")+W+(D&&d==="("?")":""),w){for(R=-1,H=S.length;++RY||Y>57){W=(Y===46?n+S.slice(R+1):S.slice(R))+W,S=S.slice(0,R);break}}}b&&!m&&(S=g(S,1/0));var E=X.length+S.length+W.length,O=E>1)+X+S+W+O.slice(E);break;default:S=O+X+S+W;break}return C(S)}return V.toString=function(){return l+""},V}function a(l,c){var u=s((l=kM(l),l.type="f",l)),d=Math.max(-8,Math.min(8,Math.floor(NM(c)/3)))*3,h=Math.pow(10,-d),m=lte[8+d/3];return function(f){return u(h*f)+m}}return{format:s,formatPrefix:a}}var WV,ibe,nbe;D8e({thousands:",",grouping:[3],currency:["$",""]});function D8e(e){return WV=K8e(e),ibe=WV.format,nbe=WV.formatPrefix,WV}function x8e(e,g){return Math.max(0,Math.max(-8,Math.min(8,Math.floor(NM(g)/3)))*3-NM(Math.abs(e)))}const YM=Math.PI,KM=2*YM,Du=1e-6,F8e=KM-Du;function DM(){this._x0=this._y0=this._x1=this._y1=null,this._=""}function Cbe(){return new DM}DM.prototype=Cbe.prototype={constructor:DM,moveTo:function(e,g){this._+="M"+(this._x0=this._x1=+e)+","+(this._y0=this._y1=+g)},closePath:function(){this._x1!==null&&(this._x1=this._x0,this._y1=this._y0,this._+="Z")},lineTo:function(e,g){this._+="L"+(this._x1=+e)+","+(this._y1=+g)},quadraticCurveTo:function(e,g,I,i){this._+="Q"+ +e+","+ +g+","+(this._x1=+I)+","+(this._y1=+i)},bezierCurveTo:function(e,g,I,i,n,C){this._+="C"+ +e+","+ +g+","+ +I+","+ +i+","+(this._x1=+n)+","+(this._y1=+C)},arcTo:function(e,g,I,i,n){e=+e,g=+g,I=+I,i=+i,n=+n;var C=this._x1,r=this._y1,o=I-e,A=i-g,s=C-e,a=r-g,l=s*s+a*a;if(n<0)throw new Error("negative radius: "+n);if(this._x1===null)this._+="M"+(this._x1=e)+","+(this._y1=g);else if(l>Du)if(!(Math.abs(a*o-A*s)>Du)||!n)this._+="L"+(this._x1=e)+","+(this._y1=g);else{var c=I-C,u=i-r,d=o*o+A*A,h=c*c+u*u,m=Math.sqrt(d),f=Math.sqrt(l),b=n*Math.tan((YM-Math.acos((d+l-h)/(2*m*f)))/2),p=b/f,y=b/m;Math.abs(p-1)>Du&&(this._+="L"+(e+p*s)+","+(g+p*a)),this._+="A"+n+","+n+",0,0,"+ +(a*c>s*u)+","+(this._x1=e+y*o)+","+(this._y1=g+y*A)}},arc:function(e,g,I,i,n,C){e=+e,g=+g,I=+I,C=!!C;var r=I*Math.cos(i),o=I*Math.sin(i),A=e+r,s=g+o,a=1^C,l=C?i-n:n-i;if(I<0)throw new Error("negative radius: "+I);this._x1===null?this._+="M"+A+","+s:(Math.abs(this._x1-A)>Du||Math.abs(this._y1-s)>Du)&&(this._+="L"+A+","+s),I&&(l<0&&(l=l%KM+KM),l>F8e?this._+="A"+I+","+I+",0,1,"+a+","+(e-r)+","+(g-o)+"A"+I+","+I+",0,1,"+a+","+(this._x1=A)+","+(this._y1=s):l>Du&&(this._+="A"+I+","+I+",0,"+ +(l>=YM)+","+a+","+(this._x1=e+I*Math.cos(n))+","+(this._y1=g+I*Math.sin(n))))},rect:function(e,g,I,i){this._+="M"+(this._x0=this._x1=+e)+","+(this._y0=this._y1=+g)+"h"+ +I+"v"+ +i+"h"+-I+"Z"},toString:function(){return this._}};function cl(e){return function(){return e}}var cte=Math.abs,fn=Math.atan2,fu=Math.cos,E8e=Math.max,zK=Math.min,ZA=Math.sin,_f=Math.sqrt,fC=1e-12,CB=Math.PI,GX=CB/2,M8e=2*CB;function z8e(e){return e>1?0:e<-1?CB:Math.acos(e)}function ute(e){return e>=1?GX:e<=-1?-GX:Math.asin(e)}function P8e(e){return e.innerRadius}function J8e(e){return e.outerRadius}function O8e(e){return e.startAngle}function _8e(e){return e.endAngle}function L8e(e){return e&&e.padAngle}function U8e(e,g,I,i,n,C,r,o){var A=I-e,s=i-g,a=r-n,l=o-C,c=l*A-a*s;if(!(c*cR*R+H*H&&(v=V,w=S),{cx:v,cy:w,x01:-a,y01:-l,x11:v*(n/Z-1),y11:w*(n/Z-1)}}function Q8e(){var e=P8e,g=J8e,I=cl(0),i=null,n=O8e,C=_8e,r=L8e,o=null;function A(){var s,a,l=+e.apply(this,arguments),c=+g.apply(this,arguments),u=n.apply(this,arguments)-GX,d=C.apply(this,arguments)-GX,h=cte(d-u),m=d>u;if(o||(o=s=Cbe()),cfC))o.moveTo(0,0);else if(h>M8e-fC)o.moveTo(c*fu(u),c*ZA(u)),o.arc(0,0,c,u,d,!m),l>fC&&(o.moveTo(l*fu(d),l*ZA(d)),o.arc(0,0,l,d,u,m));else{var f=u,b=d,p=u,y=d,Z=h,B=h,G=r.apply(this,arguments)/2,v=G>fC&&(i?+i.apply(this,arguments):_f(l*l+c*c)),w=zK(cte(c-l)/2,+I.apply(this,arguments)),V=w,S=w,X,W;if(v>fC){var R=ute(v/l*ZA(G)),H=ute(v/c*ZA(G));(Z-=R*2)>fC?(R*=m?1:-1,p+=R,y-=R):(Z=0,p=y=(u+d)/2),(B-=H*2)>fC?(H*=m?1:-1,f+=H,b-=H):(B=0,f=b=(u+d)/2)}var Y=c*fu(f),D=c*ZA(f),E=l*fu(y),O=l*ZA(y);if(w>fC){var J=c*fu(b),ee=c*ZA(b),q=l*fu(p),$=l*ZA(p),j;if(hfC?S>fC?(X=XV(q,$,Y,D,c,S,m),W=XV(J,ee,E,O,c,S,m),o.moveTo(X.cx+X.x01,X.cy+X.y01),SfC)||!(Z>fC)?o.lineTo(E,O):V>fC?(X=XV(E,O,J,ee,l,-V,m),W=XV(Y,D,q,$,l,-V,m),o.lineTo(X.cx+X.x01,X.cy+X.y01),V({events:{},emit(e,...g){let I=this.events[e]||[];for(let i=0,n=I.length;i{var i;this.events[e]=(i=this.events[e])==null?void 0:i.filter(n=>g!==n)}}});var rbe={},Ur={},_d={};Object.defineProperty(_d,"__esModule",{value:!0});_d.DefaultSerializer=_d.extendSerializer=void 0;function $8e(e,g){const I=e.deserialize.bind(e),i=e.serialize.bind(e);return{deserialize(n){return g.deserialize(n,I)},serialize(n){return g.serialize(n,i)}}}_d.extendSerializer=$8e;const dte={deserialize(e){return Object.assign(Error(e.message),{name:e.name,stack:e.stack})},serialize(e){return{__error_marker:"$$error",message:e.message,name:e.name,stack:e.stack}}},q8e=e=>e&&typeof e=="object"&&"__error_marker"in e&&e.__error_marker==="$$error";_d.DefaultSerializer={deserialize(e){return q8e(e)?dte.deserialize(e):e},serialize(e){return e instanceof Error?dte.serialize(e):e}};Object.defineProperty(Ur,"__esModule",{value:!0});Ur.serialize=Ur.deserialize=Ur.registerSerializer=void 0;const obe=_d;let vX=obe.DefaultSerializer;function e6e(e){vX=obe.extendSerializer(vX,e)}Ur.registerSerializer=e6e;function t6e(e){return vX.deserialize(e)}Ur.deserialize=t6e;function g6e(e){return vX.serialize(e)}Ur.serialize=g6e;var Abe={},ys={},ab={};Object.defineProperty(ab,"__esModule",{value:!0});ab.getBundleURL=ab.getBaseURL=void 0;let PK;function I6e(){return PK||(PK=i6e()),PK}ab.getBundleURL=I6e;function i6e(){try{throw new Error}catch(e){const g=(""+e.stack).match(/(https?|file|ftp|chrome-extension|moz-extension):\/\/[^)\n]+/g);if(g)return abe(g[0])}return"/"}function abe(e){return(""+e).replace(/^((?:https?|file|ftp|chrome-extension|moz-extension):\/\/.+)?\/[^/]+(?:\?.*)?$/,"$1")+"/"}ab.getBaseURL=abe;Object.defineProperty(ys,"__esModule",{value:!0});ys.isWorkerRuntime=ys.getWorkerImplementation=ys.defaultPoolSize=void 0;const hte=ab;ys.defaultPoolSize=typeof navigator<"u"&&navigator.hardwareConcurrency?navigator.hardwareConcurrency:4;const mte=e=>/^[a-zA-Z][a-zA-Z\d+\-.]*:/.test(e);function fte(e){const g=new Blob([e],{type:"application/javascript"});return URL.createObjectURL(g)}function n6e(){if(typeof Worker>"u")return class{constructor(){throw Error("No web worker implementation available. You might have tried to spawn a worker within a worker in a browser that doesn't support workers in workers.")}};class e extends Worker{constructor(i,n){var C,r;typeof i=="string"&&n&&n._baseURL?i=new URL(i,n._baseURL):typeof i=="string"&&!mte(i)&&hte.getBundleURL().match(/^file:\/\//i)&&(i=new URL(i,hte.getBundleURL().replace(/\/[^\/]+$/,"/")),(!((C=n==null?void 0:n.CORSWorkaround)!==null&&C!==void 0)||C)&&(i=fte(`importScripts(${JSON.stringify(i)});`))),typeof i=="string"&&mte(i)&&(!((r=n==null?void 0:n.CORSWorkaround)!==null&&r!==void 0)||r)&&(i=fte(`importScripts(${JSON.stringify(i)});`)),super(i,n)}}class g extends e{constructor(i,n){const C=window.URL.createObjectURL(i);super(C,n)}static fromText(i,n){const C=new window.Blob([i],{type:"text/javascript"});return new g(C,n)}}return{blob:g,default:e}}let JK;function C6e(){return JK||(JK=n6e()),JK}ys.getWorkerImplementation=C6e;function r6e(){const e=typeof self<"u"&&typeof Window<"u"&&self instanceof Window;return!!(typeof self<"u"&&self.postMessage&&!e)}ys.isWorkerRuntime=r6e;var sbe={},xM={exports:{}},OK,pte;function o6e(){if(pte)return OK;pte=1;var e=1e3,g=e*60,I=g*60,i=I*24,n=i*7,C=i*365.25;OK=function(a,l){l=l||{};var c=typeof a;if(c==="string"&&a.length>0)return r(a);if(c==="number"&&isFinite(a))return l.long?A(a):o(a);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(a))};function r(a){if(a=String(a),!(a.length>100)){var l=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(a);if(l){var c=parseFloat(l[1]),u=(l[2]||"ms").toLowerCase();switch(u){case"years":case"year":case"yrs":case"yr":case"y":return c*C;case"weeks":case"week":case"w":return c*n;case"days":case"day":case"d":return c*i;case"hours":case"hour":case"hrs":case"hr":case"h":return c*I;case"minutes":case"minute":case"mins":case"min":case"m":return c*g;case"seconds":case"second":case"secs":case"sec":case"s":return c*e;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return c;default:return}}}}function o(a){var l=Math.abs(a);return l>=i?Math.round(a/i)+"d":l>=I?Math.round(a/I)+"h":l>=g?Math.round(a/g)+"m":l>=e?Math.round(a/e)+"s":a+"ms"}function A(a){var l=Math.abs(a);return l>=i?s(a,l,i,"day"):l>=I?s(a,l,I,"hour"):l>=g?s(a,l,g,"minute"):l>=e?s(a,l,e,"second"):a+" ms"}function s(a,l,c,u){var d=l>=c*1.5;return Math.round(a/c)+" "+u+(d?"s":"")}return OK}function A6e(e){I.debug=I,I.default=I,I.coerce=A,I.disable=C,I.enable=n,I.enabled=r,I.humanize=o6e(),I.destroy=s,Object.keys(e).forEach(a=>{I[a]=e[a]}),I.names=[],I.skips=[],I.formatters={};function g(a){let l=0;for(let c=0;c{if(B==="%%")return"%";y++;const v=I.formatters[G];if(typeof v=="function"){const w=m[y];B=v.call(f,w),m.splice(y,1),y--}return B}),I.formatArgs.call(f,m),(f.log||I.log).apply(f,m)}return h.namespace=a,h.useColors=I.useColors(),h.color=I.selectColor(a),h.extend=i,h.destroy=I.destroy,Object.defineProperty(h,"enabled",{enumerable:!0,configurable:!1,get:()=>c!==null?c:(u!==I.namespaces&&(u=I.namespaces,d=I.enabled(a)),d),set:m=>{c=m}}),typeof I.init=="function"&&I.init(h),h}function i(a,l){const c=I(this.namespace+(typeof l>"u"?":":l)+a);return c.log=this.log,c}function n(a){I.save(a),I.namespaces=a,I.names=[],I.skips=[];let l;const c=(typeof a=="string"?a:"").split(/[\s,]+/),u=c.length;for(l=0;l"-"+l)].join(",");return I.enable(""),a}function r(a){if(a[a.length-1]==="*")return!0;let l,c;for(l=0,c=I.skips.length;l{let A=!1;return()=>{A||(A=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),g.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function I(){return typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs)?!0:typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)?!1:typeof document<"u"&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function i(A){if(A[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+A[0]+(this.useColors?"%c ":" ")+"+"+e.exports.humanize(this.diff),!this.useColors)return;const s="color: "+this.color;A.splice(1,0,s,"color: inherit");let a=0,l=0;A[0].replace(/%[a-zA-Z%]/g,c=>{c!=="%%"&&(a++,c==="%c"&&(l=a))}),A.splice(l,0,s)}g.log=console.debug||console.log||(()=>{});function n(A){try{A?g.storage.setItem("debug",A):g.storage.removeItem("debug")}catch{}}function C(){let A;try{A=g.storage.getItem("debug")}catch{}return!A&&typeof process<"u"&&"env"in process&&(A={}.DEBUG),A}function r(){try{return localStorage}catch{}}e.exports=a6e(g);const{formatters:o}=e.exports;o.j=function(A){try{return JSON.stringify(A)}catch(s){return"[UnexpectedJSONParseError]: "+s.message}}})(xM,xM.exports);var vU=xM.exports,s6e=globalThis&&globalThis.__awaiter||function(e,g,I,i){function n(C){return C instanceof I?C:new I(function(r){r(C)})}return new(I||(I=Promise))(function(C,r){function o(a){try{s(i.next(a))}catch(l){r(l)}}function A(a){try{s(i.throw(a))}catch(l){r(l)}}function s(a){a.done?C(a.value):n(a.value).then(o,A)}s((i=i.apply(e,g||[])).next())})};class mT{constructor(g){this._baseObserver=g,this._pendingPromises=new Set}complete(){Promise.all(this._pendingPromises).then(()=>this._baseObserver.complete()).catch(g=>this._baseObserver.error(g))}error(g){this._baseObserver.error(g)}schedule(g){const I=Promise.all(this._pendingPromises),i=[],n=r=>i.push(r),C=Promise.resolve().then(()=>s6e(this,void 0,void 0,function*(){yield I,yield g(n),this._pendingPromises.delete(C);for(const r of i)this._baseObserver.next(r)})).catch(r=>{this._pendingPromises.delete(C),this._baseObserver.error(r)});this._pendingPromises.add(C)}}const lbe=()=>typeof Symbol=="function",cS=e=>lbe()&&!!Symbol[e],BU=e=>cS(e)?Symbol[e]:"@@"+e;cS("asyncIterator")||(Symbol.asyncIterator=Symbol.asyncIterator||Symbol.for("Symbol.asyncIterator"));const l6e=BU("iterator"),FM=BU("observable"),cbe=BU("species");function BX(e,g){const I=e[g];if(I!=null){if(typeof I!="function")throw new TypeError(I+" is not a function");return I}}function Xy(e){let g=e.constructor;return g!==void 0&&(g=g[cbe],g===null&&(g=void 0)),g!==void 0?g:Ld}function c6e(e){return e instanceof Ld}function sb(e){sb.log?sb.log(e):setTimeout(()=>{throw e},0)}function u1(e){Promise.resolve().then(()=>{try{e()}catch(g){sb(g)}})}function ube(e){const g=e._cleanup;if(g!==void 0&&(e._cleanup=void 0,!!g))try{if(typeof g=="function")g();else{const I=BX(g,"unsubscribe");I&&I.call(g)}}catch(I){sb(I)}}function EM(e){e._observer=void 0,e._queue=void 0,e._state="closed"}function u6e(e){const g=e._queue;if(g){e._queue=void 0,e._state="ready";for(const I of g)if(dbe(e,I.type,I.value),e._state==="closed")break}}function dbe(e,g,I){e._state="running";const i=e._observer;try{const n=i?BX(i,g):void 0;switch(g){case"next":n&&n.call(i,I);break;case"error":if(EM(e),n)n.call(i,I);else throw I;break;case"complete":EM(e),n&&n.call(i);break}}catch(n){sb(n)}e._state==="closed"?ube(e):e._state==="running"&&(e._state="ready")}function _K(e,g,I){if(e._state!=="closed"){if(e._state==="buffering"){e._queue=e._queue||[],e._queue.push({type:g,value:I});return}if(e._state!=="ready"){e._state="buffering",e._queue=[{type:g,value:I}],u1(()=>u6e(e));return}dbe(e,g,I)}}let d6e=class{constructor(g,I){this._cleanup=void 0,this._observer=g,this._queue=void 0,this._state="initializing";const i=new h6e(this);try{this._cleanup=I.call(void 0,i)}catch(n){i.error(n)}this._state==="initializing"&&(this._state="ready")}get closed(){return this._state==="closed"}unsubscribe(){this._state!=="closed"&&(EM(this),ube(this))}};class h6e{constructor(g){this._subscription=g}get closed(){return this._subscription._state==="closed"}next(g){_K(this._subscription,"next",g)}error(g){_K(this._subscription,"error",g)}complete(){_K(this._subscription,"complete")}}let Ld=class ZZ{constructor(g){if(!(this instanceof ZZ))throw new TypeError("Observable cannot be called as a function");if(typeof g!="function")throw new TypeError("Observable initializer must be a function");this._subscriber=g}subscribe(g,I,i){return(typeof g!="object"||g===null)&&(g={next:g,error:I,complete:i}),new d6e(g,this._subscriber)}pipe(g,...I){let i=this;for(const n of[g,...I])i=n(i);return i}tap(g,I,i){const n=typeof g!="object"||g===null?{next:g,error:I,complete:i}:g;return new ZZ(C=>this.subscribe({next(r){n.next&&n.next(r),C.next(r)},error(r){n.error&&n.error(r),C.error(r)},complete(){n.complete&&n.complete(),C.complete()},start(r){n.start&&n.start(r)}}))}forEach(g){return new Promise((I,i)=>{if(typeof g!="function"){i(new TypeError(g+" is not a function"));return}function n(){C.unsubscribe(),I(void 0)}const C=this.subscribe({next(r){try{g(r,n)}catch(o){i(o),C.unsubscribe()}},error(r){i(r)},complete(){I(void 0)}})})}map(g){if(typeof g!="function")throw new TypeError(g+" is not a function");const I=Xy(this);return new I(i=>this.subscribe({next(n){let C=n;try{C=g(n)}catch(r){return i.error(r)}i.next(C)},error(n){i.error(n)},complete(){i.complete()}}))}filter(g){if(typeof g!="function")throw new TypeError(g+" is not a function");const I=Xy(this);return new I(i=>this.subscribe({next(n){try{if(!g(n))return}catch(C){return i.error(C)}i.next(n)},error(n){i.error(n)},complete(){i.complete()}}))}reduce(g,I){if(typeof g!="function")throw new TypeError(g+" is not a function");const i=Xy(this),n=arguments.length>1;let C=!1,r=I;return new i(o=>this.subscribe({next(A){const s=!C;if(C=!0,!s||n)try{r=g(r,A)}catch(a){return o.error(a)}else r=A},error(A){o.error(A)},complete(){if(!C&&!n)return o.error(new TypeError("Cannot reduce an empty sequence"));o.next(r),o.complete()}}))}concat(...g){const I=Xy(this);return new I(i=>{let n,C=0;function r(o){n=o.subscribe({next(A){i.next(A)},error(A){i.error(A)},complete(){C===g.length?(n=void 0,i.complete()):r(I.from(g[C++]))}})}return r(this),()=>{n&&(n.unsubscribe(),n=void 0)}})}flatMap(g){if(typeof g!="function")throw new TypeError(g+" is not a function");const I=Xy(this);return new I(i=>{const n=[],C=this.subscribe({next(o){let A;if(g)try{A=g(o)}catch(a){return i.error(a)}else A=o;const s=I.from(A).subscribe({next(a){i.next(a)},error(a){i.error(a)},complete(){const a=n.indexOf(s);a>=0&&n.splice(a,1),r()}});n.push(s)},error(o){i.error(o)},complete(){r()}});function r(){C.closed&&n.length===0&&i.complete()}return()=>{n.forEach(o=>o.unsubscribe()),C.unsubscribe()}})}[FM](){return this}static from(g){const I=typeof this=="function"?this:ZZ;if(g==null)throw new TypeError(g+" is not an object");const i=BX(g,FM);if(i){const n=i.call(g);if(Object(n)!==n)throw new TypeError(n+" is not an object");return c6e(n)&&n.constructor===I?n:new I(C=>n.subscribe(C))}if(cS("iterator")){const n=BX(g,l6e);if(n)return new I(C=>{u1(()=>{if(!C.closed){for(const r of n.call(g))if(C.next(r),C.closed)return;C.complete()}})})}if(Array.isArray(g))return new I(n=>{u1(()=>{if(!n.closed){for(const C of g)if(n.next(C),n.closed)return;n.complete()}})});throw new TypeError(g+" is not observable")}static of(...g){const I=typeof this=="function"?this:ZZ;return new I(i=>{u1(()=>{if(!i.closed){for(const n of g)if(i.next(n),i.closed)return;i.complete()}})})}static get[cbe](){return this}};lbe()&&Object.defineProperty(Ld,Symbol("extensions"),{value:{symbol:FM,hostReportError:sb},configurable:!0});const Eh=Ld;function Mh(e){typeof e=="function"?e():e&&typeof e.unsubscribe=="function"&&e.unsubscribe()}var m6e=globalThis&&globalThis.__awaiter||function(e,g,I,i){function n(C){return C instanceof I?C:new I(function(r){r(C)})}return new(I||(I=Promise))(function(C,r){function o(a){try{s(i.next(a))}catch(l){r(l)}}function A(a){try{s(i.throw(a))}catch(l){r(l)}}function s(a){a.done?C(a.value):n(a.value).then(o,A)}s((i=i.apply(e,g||[])).next())})};function f6e(e){return g=>new Eh(I=>{const i=new mT(I),n=g.subscribe({complete(){i.complete()},error(C){i.error(C)},next(C){i.schedule(r=>m6e(this,void 0,void 0,function*(){(yield e(C))&&r(C)}))}});return()=>Mh(n)})}function p6e(e){return e&&cS("asyncIterator")&&e[Symbol.asyncIterator]}function b6e(e){return e&&cS("iterator")&&e[Symbol.iterator]}var y6e=globalThis&&globalThis.__awaiter||function(e,g,I,i){function n(C){return C instanceof I?C:new I(function(r){r(C)})}return new(I||(I=Promise))(function(C,r){function o(a){try{s(i.next(a))}catch(l){r(l)}}function A(a){try{s(i.throw(a))}catch(l){r(l)}}function s(a){a.done?C(a.value):n(a.value).then(o,A)}s((i=i.apply(e,g||[])).next())})},Z6e=globalThis&&globalThis.__asyncValues||function(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var g=e[Symbol.asyncIterator],I;return g?g.call(e):(e=typeof __values=="function"?__values(e):e[Symbol.iterator](),I={},i("next"),i("throw"),i("return"),I[Symbol.asyncIterator]=function(){return this},I);function i(C){I[C]=e[C]&&function(r){return new Promise(function(o,A){r=e[C](r),n(o,A,r.done,r.value)})}}function n(C,r,o,A){Promise.resolve(A).then(function(s){C({value:s,done:o})},r)}};function G6e(e){return g=>new Eh(I=>{const i=new mT(I),n=g.subscribe({complete(){i.complete()},error(C){i.error(C)},next(C){i.schedule(r=>y6e(this,void 0,void 0,function*(){var o,A;const s=yield e(C);if(b6e(s)||p6e(s))try{for(var a=Z6e(s),l;l=yield a.next(),!l.done;){const c=l.value;r(c)}}catch(c){o={error:c}}finally{try{l&&!l.done&&(A=a.return)&&(yield A.call(a))}finally{if(o)throw o.error}}else s.map(c=>r(c))}))}});return()=>Mh(n)})}function v6e(e){return new Ld(g=>{let I=0;const i=setInterval(()=>{g.next(I++)},e);return()=>clearInterval(i)})}var B6e=globalThis&&globalThis.__awaiter||function(e,g,I,i){function n(C){return C instanceof I?C:new I(function(r){r(C)})}return new(I||(I=Promise))(function(C,r){function o(a){try{s(i.next(a))}catch(l){r(l)}}function A(a){try{s(i.throw(a))}catch(l){r(l)}}function s(a){a.done?C(a.value):n(a.value).then(o,A)}s((i=i.apply(e,g||[])).next())})};function S6e(e){return g=>new Eh(I=>{const i=new mT(I),n=g.subscribe({complete(){i.complete()},error(C){i.error(C)},next(C){i.schedule(r=>B6e(this,void 0,void 0,function*(){const o=yield e(C);r(o)}))}});return()=>Mh(n)})}function w6e(...e){return e.length===0?Ld.from([]):new Ld(g=>{let I=0;const i=e.map(C=>C.subscribe({error(r){g.error(r),n()},next(r){g.next(r)},complete(){++I===e.length&&(g.complete(),n())}})),n=()=>{i.forEach(C=>Mh(C))};return n})}class V6e extends Eh{constructor(){super(g=>(this._observers.add(g),()=>this._observers.delete(g))),this._observers=new Set}next(g){for(const I of this._observers)I.next(g)}error(g){for(const I of this._observers)I.error(g)}complete(){for(const g of this._observers)g.complete()}}const hbe=V6e;function R6e(e){const g=new hbe;let I,i=0;return new Eh(n=>{I||(I=e.subscribe(g));const C=g.subscribe(n);return i++,()=>{i--,C.unsubscribe(),i===0&&(Mh(I),I=void 0)}})}var W6e=globalThis&&globalThis.__awaiter||function(e,g,I,i){function n(C){return C instanceof I?C:new I(function(r){r(C)})}return new(I||(I=Promise))(function(C,r){function o(a){try{s(i.next(a))}catch(l){r(l)}}function A(a){try{s(i.throw(a))}catch(l){r(l)}}function s(a){a.done?C(a.value):n(a.value).then(o,A)}s((i=i.apply(e,g||[])).next())})};function X6e(e,g){return I=>new Eh(i=>{let n,C=0;const r=new mT(i),o=I.subscribe({complete(){r.complete()},error(A){r.error(A)},next(A){r.schedule(s=>W6e(this,void 0,void 0,function*(){n=yield e(C===0?typeof g>"u"?A:g:n,A,C++),s(n)}))}});return()=>Mh(o)})}const H6e=Object.freeze(Object.defineProperty({__proto__:null,Observable:Eh,Subject:hbe,filter:f6e,flatMap:G6e,interval:v6e,map:S6e,merge:w6e,multicast:R6e,scan:X6e,unsubscribe:Mh},Symbol.toStringTag,{value:"Module"})),fT=$O(H6e);var pT={};Object.defineProperty(pT,"__esModule",{value:!0});pT.allSettled=void 0;function T6e(e){return Promise.all(e.map(g=>{const I=C=>({status:"fulfilled",value:C}),i=C=>({status:"rejected",reason:C}),n=Promise.resolve(g);try{return n.then(I,i)}catch(C){return Promise.reject(C)}}))}pT.allSettled=T6e;var mbe={};(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.PoolEventType=void 0,function(g){g.initialized="initialized",g.taskCanceled="taskCanceled",g.taskCompleted="taskCompleted",g.taskFailed="taskFailed",g.taskQueued="taskQueued",g.taskQueueDrained="taskQueueDrained",g.taskStart="taskStart",g.terminated="terminated"}(e.PoolEventType||(e.PoolEventType={}))})(mbe);var uS={},VC={};Object.defineProperty(VC,"__esModule",{value:!0});VC.$worker=VC.$transferable=VC.$terminate=VC.$events=VC.$errors=void 0;VC.$errors=Symbol("thread.errors");VC.$events=Symbol("thread.events");VC.$terminate=Symbol("thread.terminate");VC.$transferable=Symbol("thread.transferable");VC.$worker=Symbol("thread.worker");Object.defineProperty(uS,"__esModule",{value:!0});uS.Thread=void 0;const LK=VC;function bte(e){throw Error(e)}uS.Thread={errors(e){return e[LK.$errors]||bte("Error observable not found. Make sure to pass a thread instance as returned by the spawn() promise.")},events(e){return e[LK.$events]||bte("Events observable not found. Make sure to pass a thread instance as returned by the spawn() promise.")},terminate(e){return e[LK.$terminate]()}};(function(e){var g=bI&&bI.__awaiter||function(f,b,p,y){function Z(B){return B instanceof p?B:new p(function(G){G(B)})}return new(p||(p=Promise))(function(B,G){function v(S){try{V(y.next(S))}catch(X){G(X)}}function w(S){try{V(y.throw(S))}catch(X){G(X)}}function V(S){S.done?B(S.value):Z(S.value).then(v,w)}V((y=y.apply(f,b||[])).next())})},I=bI&&bI.__importDefault||function(f){return f&&f.__esModule?f:{default:f}};Object.defineProperty(e,"__esModule",{value:!0}),e.Pool=e.Thread=e.PoolEventType=void 0;const i=I(vU),n=fT,C=pT,r=ys,o=mbe;Object.defineProperty(e,"PoolEventType",{enumerable:!0,get:function(){return o.PoolEventType}});const A=uS;Object.defineProperty(e,"Thread",{enumerable:!0,get:function(){return A.Thread}});let s=1;function a(f){const b=[];for(let p=0;psetTimeout(b,f))}function c(f,b){return f.reduce((p,y)=>[...p,...b(y)],[])}function u(f){return f.replace(/\W/g," ").trim().replace(/\s+/g,"-")}function d(f,b){return a(b).map(()=>({init:f(),runningTasks:[]}))}class h{constructor(b,p){this.eventSubject=new n.Subject,this.initErrors=[],this.isClosing=!1,this.nextTaskID=1,this.taskQueue=[];const y=typeof p=="number"?{size:p}:p||{},{size:Z=r.defaultPoolSize}=y;this.debug=i.default(`threads:pool:${u(y.name||String(s++))}`),this.options=y,this.workers=d(b,Z),this.eventObservable=n.multicast(n.Observable.from(this.eventSubject)),Promise.all(this.workers.map(B=>B.init)).then(()=>this.eventSubject.next({type:o.PoolEventType.initialized,size:this.workers.length}),B=>{this.debug("Error while initializing pool worker:",B),this.eventSubject.error(B),this.initErrors.push(B)})}findIdlingWorker(){const{concurrency:b=1}=this.options;return this.workers.find(p=>p.runningTasks.lengthg(this,void 0,void 0,function*(){const Z=()=>{b.runningTasks=b.runningTasks.filter(B=>B!==y)};yield l(0);try{yield this.runPoolTask(b,p)}finally{Z(),this.isClosing||this.scheduleWork()}}))();b.runningTasks.push(y)})}scheduleWork(){this.debug("Attempt de-queueing a task in order to run it...");const b=this.findIdlingWorker();if(!b)return;const p=this.taskQueue.shift();if(!p){this.debug("Task queue is empty"),this.eventSubject.next({type:o.PoolEventType.taskQueueDrained});return}this.run(b,p)}taskCompletion(b){return new Promise((p,y)=>{const Z=this.events().subscribe(B=>{B.type===o.PoolEventType.taskCompleted&&B.taskID===b?(Z.unsubscribe(),p(B.returnValue)):B.type===o.PoolEventType.taskFailed&&B.taskID===b?(Z.unsubscribe(),y(B.error)):B.type===o.PoolEventType.terminated&&(Z.unsubscribe(),y(Error("Pool has been terminated before task was run.")))})})}settled(b=!1){return g(this,void 0,void 0,function*(){const p=()=>c(this.workers,B=>B.runningTasks),y=[],Z=this.eventObservable.subscribe(B=>{B.type===o.PoolEventType.taskFailed&&y.push(B.error)});return this.initErrors.length>0?Promise.reject(this.initErrors[0]):b&&this.taskQueue.length===0?(yield C.allSettled(p()),y):(yield new Promise((B,G)=>{const v=this.eventObservable.subscribe({next(w){w.type===o.PoolEventType.taskQueueDrained&&(v.unsubscribe(),B(void 0))},error:G})}),yield C.allSettled(p()),Z.unsubscribe(),y)})}completed(b=!1){return g(this,void 0,void 0,function*(){const p=this.settled(b),y=new Promise((B,G)=>{const v=this.eventObservable.subscribe({next(w){w.type===o.PoolEventType.taskQueueDrained?(v.unsubscribe(),B(p)):w.type===o.PoolEventType.taskFailed&&(v.unsubscribe(),G(w.error))},error:G})}),Z=yield Promise.race([p,y]);if(Z.length>0)throw Z[0]})}events(){return this.eventObservable}queue(b){const{maxQueuedJobs:p=1/0}=this.options;if(this.isClosing)throw Error("Cannot schedule pool tasks after terminate() has been called.");if(this.initErrors.length>0)throw this.initErrors[0];const y=this.nextTaskID++,Z=this.taskCompletion(y);Z.catch(G=>{this.debug(`Task #${y} errored:`,G)});const B={id:y,run:b,cancel:()=>{this.taskQueue.indexOf(B)!==-1&&(this.taskQueue=this.taskQueue.filter(G=>G!==B),this.eventSubject.next({type:o.PoolEventType.taskCanceled,taskID:B.id}))},then:Z.then.bind(Z)};if(this.taskQueue.length>=p)throw Error(`Maximum number of pool tasks queued. Refusing to queue another one. +This usually happens for one of two reasons: We are either at peak workload right now or some tasks just won't finish, thus blocking the pool.`);return this.debug(`Queueing task #${B.id}...`),this.taskQueue.push(B),this.eventSubject.next({type:o.PoolEventType.taskQueued,taskID:B.id}),this.scheduleWork(),B}terminate(b){return g(this,void 0,void 0,function*(){this.isClosing=!0,b||(yield this.completed(!0)),this.eventSubject.next({type:o.PoolEventType.terminated,remainingQueue:[...this.taskQueue]}),this.eventSubject.complete(),yield Promise.all(this.workers.map(p=>g(this,void 0,void 0,function*(){return A.Thread.terminate(yield p.init)})))})}}h.EventType=o.PoolEventType;function m(f,b){return new h(f,b)}m.EventType=o.PoolEventType,e.Pool=m})(sbe);var bT={},yT={};Object.defineProperty(yT,"__esModule",{value:!0});yT.createPromiseWithResolver=void 0;const N6e=()=>{};function k6e(){let e=!1,g,I=N6e;return[new Promise(C=>{e?C(g):I=C}),C=>{e=!0,g=C,I(g)}]}yT.createPromiseWithResolver=k6e;var fbe={};(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.WorkerEventType=void 0,function(g){g.internalError="internalError",g.message="message",g.termination="termination"}(e.WorkerEventType||(e.WorkerEventType={}))})(fbe);var lb={},ZT={};Object.defineProperty(ZT,"__esModule",{value:!0});ZT.ObservablePromise=void 0;const Y6e=fT,K6e=()=>{},D6e=e=>e,yte=e=>Promise.resolve().then(e);function x6e(e){throw e}function F6e(e){return e&&typeof e.then=="function"}class SU extends Y6e.Observable{constructor(g){super(I=>{const i=this,n=Object.assign(Object.assign({},I),{complete(){I.complete(),i.onCompletion()},error(C){I.error(C),i.onError(C)},next(C){I.next(C),i.onNext(C)}});try{return this.initHasRun=!0,g(n)}catch(C){n.error(C)}}),this.initHasRun=!1,this.fulfillmentCallbacks=[],this.rejectionCallbacks=[],this.firstValueSet=!1,this.state="pending"}onNext(g){this.firstValueSet||(this.firstValue=g,this.firstValueSet=!0)}onError(g){this.state="rejected",this.rejection=g;for(const I of this.rejectionCallbacks)yte(()=>I(g))}onCompletion(){this.state="fulfilled";for(const g of this.fulfillmentCallbacks)yte(()=>g(this.firstValue))}then(g,I){const i=g||D6e,n=I||x6e;let C=!1;return new Promise((r,o)=>{const A=a=>{if(!C){C=!0;try{r(n(a))}catch(l){o(l)}}},s=a=>{try{r(i(a))}catch(l){A(l)}};if(this.initHasRun||this.subscribe({error:A}),this.state==="fulfilled")return r(i(this.firstValue));if(this.state==="rejected")return C=!0,r(n(this.rejection));this.fulfillmentCallbacks.push(s),this.rejectionCallbacks.push(A)})}catch(g){return this.then(void 0,g)}finally(g){const I=g||K6e;return this.then(i=>(I(),i),()=>I())}static from(g){return F6e(g)?new SU(I=>{const i=C=>{I.next(C),I.complete()},n=C=>{I.error(C)};g.then(i,n)}):super.from(g)}}ZT.ObservablePromise=SU;var Ts={};Object.defineProperty(Ts,"__esModule",{value:!0});Ts.Transfer=Ts.isTransferDescriptor=void 0;const pbe=VC;function E6e(e){return!(!e||typeof e!="object")}function M6e(e){return e&&typeof e=="object"&&e[pbe.$transferable]}Ts.isTransferDescriptor=M6e;function z6e(e,g){if(!g){if(!E6e(e))throw Error();g=[e]}return{[pbe.$transferable]:!0,send:e,transferables:g}}Ts.Transfer=z6e;var wU={};(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.WorkerMessageType=e.MasterMessageType=void 0,function(g){g.cancel="cancel",g.run="run"}(e.MasterMessageType||(e.MasterMessageType={})),function(g){g.error="error",g.init="init",g.result="result",g.running="running",g.uncaughtError="uncaughtError"}(e.WorkerMessageType||(e.WorkerMessageType={}))})(wU);var P6e=bI&&bI.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(lb,"__esModule",{value:!0});lb.createProxyModule=lb.createProxyFunction=void 0;const J6e=P6e(vU),bbe=fT,wG=Ur,Zte=ZT,O6e=Ts,dS=wU,ybe=J6e.default("threads:master:messages");let _6e=1;const L6e=e=>Array.from(new Set(e)),U6e=e=>e&&e.type===dS.WorkerMessageType.error,Q6e=e=>e&&e.type===dS.WorkerMessageType.result,j6e=e=>e&&e.type===dS.WorkerMessageType.running;function $6e(e,g){return new bbe.Observable(I=>{let i;const n=C=>{if(ybe("Message from worker:",C.data),!(!C.data||C.data.uid!==g)){if(j6e(C.data))i=C.data.resultType;else if(Q6e(C.data))i==="promise"?(typeof C.data.payload<"u"&&I.next(wG.deserialize(C.data.payload)),I.complete(),e.removeEventListener("message",n)):(C.data.payload&&I.next(wG.deserialize(C.data.payload)),C.data.complete&&(I.complete(),e.removeEventListener("message",n)));else if(U6e(C.data)){const r=wG.deserialize(C.data.error);I.error(r),e.removeEventListener("message",n)}}};return e.addEventListener("message",n),()=>{if(i==="observable"||!i){const C={type:dS.MasterMessageType.cancel,uid:g};e.postMessage(C)}e.removeEventListener("message",n)}})}function q6e(e){if(e.length===0)return{args:[],transferables:[]};const g=[],I=[];for(const i of e)O6e.isTransferDescriptor(i)?(g.push(wG.serialize(i.send)),I.push(...i.transferables)):g.push(wG.serialize(i));return{args:g,transferables:I.length===0?I:L6e(I)}}function Zbe(e,g){return(...I)=>{const i=_6e++,{args:n,transferables:C}=q6e(I),r={type:dS.MasterMessageType.run,uid:i,method:g,args:n};ybe("Sending command to run function to worker:",r);try{e.postMessage(r,C)}catch(o){return Zte.ObservablePromise.from(Promise.reject(o))}return Zte.ObservablePromise.from(bbe.multicast($6e(e,i)))}}lb.createProxyFunction=Zbe;function eqe(e,g){const I={};for(const i of g)I[i]=Zbe(e,i);return I}lb.createProxyModule=eqe;var VU=bI&&bI.__awaiter||function(e,g,I,i){function n(C){return C instanceof I?C:new I(function(r){r(C)})}return new(I||(I=Promise))(function(C,r){function o(a){try{s(i.next(a))}catch(l){r(l)}}function A(a){try{s(i.throw(a))}catch(l){r(l)}}function s(a){a.done?C(a.value):n(a.value).then(o,A)}s((i=i.apply(e,g||[])).next())})},tqe=bI&&bI.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(bT,"__esModule",{value:!0});bT.spawn=void 0;const RU=tqe(vU),gqe=fT,Iqe=Ur,iqe=yT,HV=VC,d1=fbe,Gte=lb,nqe=RU.default("threads:master:messages"),Cqe=RU.default("threads:master:spawn"),Gbe=RU.default("threads:master:thread-utils"),rqe=e=>e&&e.type==="init",oqe=e=>e&&e.type==="uncaughtError",Aqe=typeof process<"u"&&{}.THREADS_WORKER_INIT_TIMEOUT?Number.parseInt({}.THREADS_WORKER_INIT_TIMEOUT,10):1e4;function aqe(e,g,I){return VU(this,void 0,void 0,function*(){let i;const n=new Promise((r,o)=>{i=setTimeout(()=>o(Error(I)),g)}),C=yield Promise.race([e,n]);return clearTimeout(i),C})}function sqe(e){return new Promise((g,I)=>{const i=n=>{nqe("Message from worker before finishing initialization:",n.data),rqe(n.data)?(e.removeEventListener("message",i),g(n.data)):oqe(n.data)&&(e.removeEventListener("message",i),I(Iqe.deserialize(n.data.error)))};e.addEventListener("message",i)})}function lqe(e,g){return new gqe.Observable(I=>{const i=C=>{const r={type:d1.WorkerEventType.message,data:C.data};I.next(r)},n=C=>{Gbe("Unhandled promise rejection event in thread:",C);const r={type:d1.WorkerEventType.internalError,error:Error(C.reason)};I.next(r)};e.addEventListener("message",i),e.addEventListener("unhandledrejection",n),g.then(()=>{const C={type:d1.WorkerEventType.termination};e.removeEventListener("message",i),e.removeEventListener("unhandledrejection",n),I.next(C),I.complete()})})}function cqe(e){const[g,I]=iqe.createPromiseWithResolver();return{terminate:()=>VU(this,void 0,void 0,function*(){Gbe("Terminating worker"),yield e.terminate(),I()}),termination:g}}function vte(e,g,I,i){const n=I.filter(C=>C.type===d1.WorkerEventType.internalError).map(C=>C.error);return Object.assign(e,{[HV.$errors]:n,[HV.$events]:I,[HV.$terminate]:i,[HV.$worker]:g})}function uqe(e,g){return VU(this,void 0,void 0,function*(){Cqe("Initializing new thread");const I=g&&g.timeout?g.timeout:Aqe,n=(yield aqe(sqe(e),I,`Timeout: Did not receive an init message from worker after ${I}ms. Make sure the worker calls expose().`)).exposed,{termination:C,terminate:r}=cqe(e),o=lqe(e,C);if(n.type==="function"){const A=Gte.createProxyFunction(e);return vte(A,e,o,r)}else if(n.type==="module"){const A=Gte.createProxyModule(e,n.methods);return vte(A,e,o,r)}else{const A=n.type;throw Error(`Worker init message states unexpected type of expose(): ${A}`)}})}bT.spawn=uqe;(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.Worker=e.BlobWorker=e.isWorkerRuntime=e.Thread=e.spawn=e.Pool=void 0;const g=ys;Object.defineProperty(e,"isWorkerRuntime",{enumerable:!0,get:function(){return g.isWorkerRuntime}});var I=sbe;Object.defineProperty(e,"Pool",{enumerable:!0,get:function(){return I.Pool}});var i=bT;Object.defineProperty(e,"spawn",{enumerable:!0,get:function(){return i.spawn}});var n=uS;Object.defineProperty(e,"Thread",{enumerable:!0,get:function(){return n.Thread}}),e.BlobWorker=g.getWorkerImplementation().blob,e.Worker=g.getWorkerImplementation().default})(Abe);var vbe={},dqe=e=>e?typeof Symbol.observable=="symbol"&&typeof e[Symbol.observable]=="function"?e===e[Symbol.observable]():typeof e["@@observable"]=="function"?e===e["@@observable"]():!1:!1,WU={};Object.defineProperty(WU,"__esModule",{value:!0});const hqe=function(){const g=typeof self<"u"&&typeof Window<"u"&&self instanceof Window;return!!(typeof self<"u"&&self.postMessage&&!g)},mqe=function(g,I){self.postMessage(g,I)},fqe=function(g){const I=n=>{g(n.data)},i=()=>{self.removeEventListener("message",I)};return self.addEventListener("message",I),i};WU.default={isWorkerRuntime:hqe,postMessageToMaster:mqe,subscribeToMasterMessages:fqe};(function(e){var g=bI&&bI.__awaiter||function(w,V,S,X){function W(R){return R instanceof S?R:new S(function(H){H(R)})}return new(S||(S=Promise))(function(R,H){function Y(O){try{E(X.next(O))}catch(J){H(J)}}function D(O){try{E(X.throw(O))}catch(J){H(J)}}function E(O){O.done?R(O.value):W(O.value).then(Y,D)}E((X=X.apply(w,V||[])).next())})},I=bI&&bI.__importDefault||function(w){return w&&w.__esModule?w:{default:w}};Object.defineProperty(e,"__esModule",{value:!0}),e.expose=e.isWorkerRuntime=e.Transfer=e.registerSerializer=void 0;const i=I(dqe),n=Ur,C=Ts,r=wU,o=I(WU);var A=Ur;Object.defineProperty(e,"registerSerializer",{enumerable:!0,get:function(){return A.registerSerializer}});var s=Ts;Object.defineProperty(e,"Transfer",{enumerable:!0,get:function(){return s.Transfer}}),e.isWorkerRuntime=o.default.isWorkerRuntime;let a=!1;const l=new Map,c=w=>w&&w.type===r.MasterMessageType.cancel,u=w=>w&&w.type===r.MasterMessageType.run,d=w=>i.default(w)||h(w);function h(w){return w&&typeof w=="object"&&typeof w.subscribe=="function"}function m(w){return C.isTransferDescriptor(w)?{payload:w.send,transferables:w.transferables}:{payload:w,transferables:void 0}}function f(){const w={type:r.WorkerMessageType.init,exposed:{type:"function"}};o.default.postMessageToMaster(w)}function b(w){const V={type:r.WorkerMessageType.init,exposed:{type:"module",methods:w}};o.default.postMessageToMaster(V)}function p(w,V){const{payload:S,transferables:X}=m(V),W={type:r.WorkerMessageType.error,uid:w,error:n.serialize(S)};o.default.postMessageToMaster(W,X)}function y(w,V,S){const{payload:X,transferables:W}=m(S),R={type:r.WorkerMessageType.result,uid:w,complete:V?!0:void 0,payload:X};o.default.postMessageToMaster(R,W)}function Z(w,V){const S={type:r.WorkerMessageType.running,uid:w,resultType:V};o.default.postMessageToMaster(S)}function B(w){try{const V={type:r.WorkerMessageType.uncaughtError,error:n.serialize(w)};o.default.postMessageToMaster(V)}catch(V){console.error(`Not reporting uncaught error back to master thread as it occured while reporting an uncaught error already. +Latest error:`,V,` +Original error:`,w)}}function G(w,V,S){return g(this,void 0,void 0,function*(){let X;try{X=V(...S)}catch(R){return p(w,R)}const W=d(X)?"observable":"promise";if(Z(w,W),d(X)){const R=X.subscribe(H=>y(w,!1,n.serialize(H)),H=>{p(w,n.serialize(H)),l.delete(w)},()=>{y(w,!0),l.delete(w)});l.set(w,R)}else try{const R=yield X;y(w,!0,n.serialize(R))}catch(R){p(w,n.serialize(R))}})}function v(w){if(!o.default.isWorkerRuntime())throw Error("expose() called in the master thread.");if(a)throw Error("expose() called more than once. This is not possible. Pass an object to expose() if you want to expose multiple functions.");if(a=!0,typeof w=="function")o.default.subscribeToMasterMessages(V=>{u(V)&&!V.method&&G(V.uid,w,V.args.map(n.deserialize))}),f();else if(typeof w=="object"&&w){o.default.subscribeToMasterMessages(S=>{u(S)&&S.method&&G(S.uid,w[S.method],S.args.map(n.deserialize))});const V=Object.keys(w).filter(S=>typeof w[S]=="function");b(V)}else throw Error(`Invalid argument passed to expose(). Expected a function or an object, got: ${w}`);o.default.subscribeToMasterMessages(V=>{if(c(V)){const S=V.uid,X=l.get(S);X&&(X.unsubscribe(),l.delete(S))}})}e.expose=v,typeof self<"u"&&typeof self.addEventListener=="function"&&o.default.isWorkerRuntime()&&(self.addEventListener("error",w=>{setTimeout(()=>B(w.error||w),250)}),self.addEventListener("unhandledrejection",w=>{const V=w.reason;V&&typeof V.message=="string"&&setTimeout(()=>B(V),250)})),typeof process<"u"&&typeof process.on=="function"&&o.default.isWorkerRuntime()&&(process.on("uncaughtException",w=>{setTimeout(()=>B(w),250)}),process.on("unhandledRejection",w=>{w&&typeof w.message=="string"&&setTimeout(()=>B(w),250)}))})(vbe);(function(e){var g=bI&&bI.__createBinding||(Object.create?function(o,A,s,a){a===void 0&&(a=s),Object.defineProperty(o,a,{enumerable:!0,get:function(){return A[s]}})}:function(o,A,s,a){a===void 0&&(a=s),o[a]=A[s]}),I=bI&&bI.__exportStar||function(o,A){for(var s in o)s!=="default"&&!Object.prototype.hasOwnProperty.call(A,s)&&g(A,o,s)};Object.defineProperty(e,"__esModule",{value:!0}),e.Transfer=e.DefaultSerializer=e.expose=e.registerSerializer=void 0;var i=Ur;Object.defineProperty(e,"registerSerializer",{enumerable:!0,get:function(){return i.registerSerializer}}),I(Abe,e);var n=vbe;Object.defineProperty(e,"expose",{enumerable:!0,get:function(){return n.expose}});var C=_d;Object.defineProperty(e,"DefaultSerializer",{enumerable:!0,get:function(){return C.DefaultSerializer}});var r=Ts;Object.defineProperty(e,"Transfer",{enumerable:!0,get:function(){return r.Transfer}})})(rbe);const _c=Fc(rbe);_c.registerSerializer;const GT=_c.spawn;_c.BlobWorker;_c.DefaultSerializer;_c.Pool;_c.Thread;_c.Transfer;_c.Worker;class pqe extends Map{constructor(g={}){if(super(),!(g.maxSize&&g.maxSize>0))throw new TypeError("`maxSize` must be a number greater than 0");if(typeof g.maxAge=="number"&&g.maxAge===0)throw new TypeError("`maxAge` must be a number greater than 0");this.maxSize=g.maxSize,this.maxAge=g.maxAge||Number.POSITIVE_INFINITY,this.onEviction=g.onEviction,this.cache=new Map,this.oldCache=new Map,this._size=0}_emitEvictions(g){if(typeof this.onEviction=="function")for(const[I,i]of g)this.onEviction(I,i.value)}_deleteIfExpired(g,I){return typeof I.expiry=="number"&&I.expiry<=Date.now()?(typeof this.onEviction=="function"&&this.onEviction(g,I.value),this.delete(g)):!1}_getOrDeleteIfExpired(g,I){if(this._deleteIfExpired(g,I)===!1)return I.value}_getItemValue(g,I){return I.expiry?this._getOrDeleteIfExpired(g,I):I.value}_peek(g,I){const i=I.get(g);return this._getItemValue(g,i)}_set(g,I){this.cache.set(g,I),this._size++,this._size>=this.maxSize&&(this._size=0,this._emitEvictions(this.oldCache),this.oldCache=this.cache,this.cache=new Map)}_moveToRecent(g,I){this.oldCache.delete(g),this._set(g,I)}*_entriesAscending(){for(const g of this.oldCache){const[I,i]=g;this.cache.has(I)||this._deleteIfExpired(I,i)===!1&&(yield g)}for(const g of this.cache){const[I,i]=g;this._deleteIfExpired(I,i)===!1&&(yield g)}}get(g){if(this.cache.has(g)){const I=this.cache.get(g);return this._getItemValue(g,I)}if(this.oldCache.has(g)){const I=this.oldCache.get(g);if(this._deleteIfExpired(g,I)===!1)return this._moveToRecent(g,I),I.value}}set(g,I,{maxAge:i=this.maxAge}={}){const n=typeof i=="number"&&i!==Number.POSITIVE_INFINITY?Date.now()+i:void 0;return this.cache.has(g)?this.cache.set(g,{value:I,expiry:n}):this._set(g,{value:I,expiry:n}),this}has(g){return this.cache.has(g)?!this._deleteIfExpired(g,this.cache.get(g)):this.oldCache.has(g)?!this._deleteIfExpired(g,this.oldCache.get(g)):!1}peek(g){if(this.cache.has(g))return this._peek(g,this.cache);if(this.oldCache.has(g))return this._peek(g,this.oldCache)}delete(g){const I=this.cache.delete(g);return I&&this._size--,this.oldCache.delete(g)||I}clear(){this.cache.clear(),this.oldCache.clear(),this._size=0}resize(g){if(!(g&&g>0))throw new TypeError("`maxSize` must be a number greater than 0");const I=[...this._entriesAscending()],i=I.length-g;i<0?(this.cache=new Map(I),this.oldCache=new Map,this._size=I.length):(i>0&&this._emitEvictions(I.slice(0,i)),this.oldCache=new Map(I.slice(i)),this.cache=new Map,this._size=0),this.maxSize=g}*keys(){for(const[g]of this)yield g}*values(){for(const[,g]of this)yield g}*[Symbol.iterator](){for(const g of this.cache){const[I,i]=g;this._deleteIfExpired(I,i)===!1&&(yield[I,i.value])}for(const g of this.oldCache){const[I,i]=g;this.cache.has(I)||this._deleteIfExpired(I,i)===!1&&(yield[I,i.value])}}*entriesDescending(){let g=[...this.cache];for(let I=g.length-1;I>=0;--I){const i=g[I],[n,C]=i;this._deleteIfExpired(n,C)===!1&&(yield[n,C.value])}g=[...this.oldCache];for(let I=g.length-1;I>=0;--I){const i=g[I],[n,C]=i;this.cache.has(n)||this._deleteIfExpired(n,C)===!1&&(yield[n,C.value])}}*entriesAscending(){for(const[g,I]of this._entriesAscending())yield[g,I.value]}get size(){if(!this._size)return this.oldCache.size;let g=0;for(const I of this.oldCache.keys())this.cache.has(I)||g++;return Math.min(this._size+g,this.maxSize)}entries(){return this.entriesAscending()}forEach(g,I=this){for(const[i,n]of this.entriesAscending())g.call(I,n,i,this)}get[Symbol.toStringTag](){return JSON.stringify([...this.entriesAscending()])}}var Bte={},UK={},QK=34,Hy=10,jK=13;function Bbe(e){return new Function("d","return {"+e.map(function(g,I){return JSON.stringify(g)+": d["+I+'] || ""'}).join(",")+"}")}function bqe(e,g){var I=Bbe(e);return function(i,n){return g(I(i),n,e)}}function Ste(e){var g=Object.create(null),I=[];return e.forEach(function(i){for(var n in i)n in g||I.push(g[n]=n)}),I}function pC(e,g){var I=e+"",i=I.length;return i9999?"+"+pC(e,6):pC(e,4)}function Zqe(e){var g=e.getUTCHours(),I=e.getUTCMinutes(),i=e.getUTCSeconds(),n=e.getUTCMilliseconds();return isNaN(e)?"Invalid Date":yqe(e.getUTCFullYear())+"-"+pC(e.getUTCMonth()+1,2)+"-"+pC(e.getUTCDate(),2)+(n?"T"+pC(g,2)+":"+pC(I,2)+":"+pC(i,2)+"."+pC(n,3)+"Z":i?"T"+pC(g,2)+":"+pC(I,2)+":"+pC(i,2)+"Z":I||g?"T"+pC(g,2)+":"+pC(I,2)+"Z":"")}function Gqe(e){var g=new RegExp('["'+e+` +\r]`),I=e.charCodeAt(0);function i(l,c){var u,d,h=n(l,function(m,f){if(u)return u(m,f-1);d=m,u=c?bqe(m,c):Bbe(m)});return h.columns=d||[],h}function n(l,c){var u=[],d=l.length,h=0,m=0,f,b=d<=0,p=!1;l.charCodeAt(d-1)===Hy&&--d,l.charCodeAt(d-1)===jK&&--d;function y(){if(b)return UK;if(p)return p=!1,Bte;var B,G=h,v;if(l.charCodeAt(G)===QK){for(;h++=d?b=!0:(v=l.charCodeAt(h++))===Hy?p=!0:v===jK&&(p=!0,l.charCodeAt(h)===Hy&&++h),l.slice(G+1,B-1).replace(/""/g,'"')}for(;hsvg{width:30px;height:20px}._context-menu-item_18ock_27{padding:2px;white-space:nowrap;border-radius:2px;transition:background .15s cubic-bezier(.25,.1,.25,1),color .15s cubic-bezier(.25,.1,.25,1)}._context-menu-item_18ock_27:hover{background:#337ab7;color:#fff}._context-menu-hr_18ock_38{margin-top:5px;margin-bottom:5px;border:0;border-top:1px solid rgba(0,0,0,.1)}._play-icon_18ock_45{width:12px;height:12px;position:absolute;right:5px}._context-menu-span_18ock_52{margin-right:20px;vertical-align:middle;display:inline-block;line-height:normal;white-space:nowrap}._context-menu-thumbnail_18ock_60{margin-right:10px;border:1px solid #888888}._context-menu-thumbnail-inline_18ock_65{display:inline-block;margin-right:10px;vertical-align:middle}._multitrack-header_1yz7l_1,._multitrack-header-focus_1yz7l_2,._multitrack-header-squeazed_1yz7l_3{position:relative;display:flex;justify-content:space-between;height:24px;margin-top:4px;margin-bottom:4px;color:#999;font-size:12px;line-height:24px;vertical-align:middle;border:0;border-radius:3px;background:#e5e5e5;transition:height .15s cubic-bezier(.25,.1,.25,1),margin .15s cubic-bezier(.25,.1,.25,1)}._multitrack-header-dark_1yz7l_20{background:#222}._multitrack-header-focus_1yz7l_2{height:32px;margin-top:0;margin-bottom:0}._multitrack-header-id_1yz7l_30{padding-left:3px}._multitrack-header-id_1yz7l_30:before{content:"ID:";font-weight:700;padding-right:5px}._multitrack-header-left_1yz7l_39{display:flex;flex-grow:1}._multitrack-header-grabber_1yz7l_44,._multitrack-header-grabber-squeazed_1yz7l_45{display:flex;align-items:center;justify-content:center;width:24px;height:100%;cursor:move;border-radius:3px 0 0 3px;transition:background .15s cubic-bezier(.25,.1,.25,1)}._multitrack-header-grabber_1yz7l_44:hover,._multitrack-header-grabber-squeazed_1yz7l_45:hover{background:#999}._multitrack-header-grabber_1yz7l_44:hover div,._multitrack-header-grabber-squeazed_1yz7l_45:hover div{background:#fff}._multitrack-header-grabber_1yz7l_44 div,._multitrack-header-grabber-squeazed_1yz7l_45 div{width:1px;height:50%;margin:1px;background:#999;transition:background .15s cubic-bezier(.25,.1,.25,1)}._multitrack-header-dark_1yz7l_20 ._multitrack-header-grabber_1yz7l_44 div{background:#666}._multitrack-header-grabber-squeazed_1yz7l_45{width:19.2px}._multitrack-header-search_1yz7l_80{position:relative;flex-grow:1;height:100%;margin-right:12px}._multitrack-header-search_1yz7l_80:after{position:absolute;top:3px;bottom:3px;right:-12px;display:block;content:"";width:1px;margin:0 6px;background:#cccccc}._multitrack-header-dark_1yz7l_20 ._multitrack-header-search_1yz7l_80:after{background:#666}._multitrack-header-nav-list_1yz7l_102,._multitrack-header_1yz7l_1>nav{display:flex}._multitrack-header-icon_1yz7l_107,._multitrack-header-icon-squeazed_1yz7l_108{width:24px;height:100%;padding:6px;transition:background .15s cubic-bezier(.25,.1,.25,1),color .15s cubic-bezier(.25,.1,.25,1)}._multitrack-header-icon_1yz7l_107 g,._multitrack-header-icon-squeazed_1yz7l_108 g{stroke:#999}._multitrack-header-icon_1yz7l_107:hover,._multitrack-header-icon_1yz7l_107:active,._multitrack-header-icon_1yz7l_107:focus,._multitrack-header-icon-squeazed_1yz7l_108:hover,._multitrack-header-icon-squeazed_1yz7l_108:active,._multitrack-header-icon-squeazed_1yz7l_108:focus{color:#fff;background:#337ab7}._multitrack-header-icon_1yz7l_107:hover g,._multitrack-header-icon_1yz7l_107:active g,._multitrack-header-icon_1yz7l_107:focus g,._multitrack-header-icon-squeazed_1yz7l_108:hover g,._multitrack-header-icon-squeazed_1yz7l_108:active g,._multitrack-header-icon-squeazed_1yz7l_108:focus g{stroke:#fff}._multitrack-header-icon_1yz7l_107:last-child,._multitrack-header-icon-squeazed_1yz7l_108:last-child{border-radius:0 3px 3px 0}._mouse-tool-selection_1yz7l_136{color:#fff;border-radius:3px 0 0 3px;background:#337ab7}._multitrack-header-icon-squeazed_1yz7l_108{width:20px 5;padding-left:3px;padding-right:3px}._track-control_w7hx2_1,._track-control-vertical_w7hx2_2{position:absolute;z-index:1;display:flex;background:rgba(255,255,255,.75);right:2px;top:2px;border-radius:2.5px;box-shadow:0 0 0 1px #0000000d,0 0 3px #0000001a;opacity:0;transition:opacity .15s cubic-bezier(.25,.1,.25,1),background .15s cubic-bezier(.25,.1,.25,1),box-shadow .15s cubic-bezier(.25,.1,.25,1)}._track-control-dark_w7hx2_15,._track-control-dark_w7hx2_15 ._track-control-active_w7hx2_16{background:rgba(40,40,40,.85)}._track-control-vertical_w7hx2_2{flex-direction:column-reverse}._track-control-left_w7hx2_24{left:2px;right:auto}._track-control-active_w7hx2_16,._track-control-vertical-active_w7hx2_30{opacity:1;z-index:1}._track-control-active_w7hx2_16:hover,._track-control-vertical-active_w7hx2_30:hover{background:rgb(255,255,255);box-shadow:0 0 0 1px #0000001a,0 0 3px #0003}._track-control-dark_w7hx2_15._track-control-active_w7hx2_16:hover{background:rgba(34,34,34,.95)}._track-control-padding-right_w7hx2_48{right:80px}._track-control-button_w7hx2_52{width:20px;height:20px;padding:4px;cursor:pointer;opacity:.66;transition:background .15s cubic-bezier(.25,.1,.25,1),color .15s cubic-bezier(.25,.1,.25,1),opacity .15s cubic-bezier(.25,.1,.25,1)}._track-control-button_w7hx2_52:hover{color:#fff;background:#337ab7;opacity:1}._track-control-button_w7hx2_52:first-child{border-radius:2.5px 0 0 2.5px}._track-control-button_w7hx2_52:last-child{border-radius:0 2.5px 2.5px 0}._track-control-dark_w7hx2_15 ._track-control-button_w7hx2_52{color:#ccc}._track-control-dark_w7hx2_15 ._track-control-button_w7hx2_52:hover{color:#fff;background:#337ab7;opacity:1}._track-control-button-vertical_w7hx2_81:first-child{border-radius:0 0 2.5px 2.5px}._track-control-button-vertical_w7hx2_81:last-child{border-radius:2.5px 2.5px 0 0}._center-track_fiu64_1{position:relative;background:transparent}._center-track-container_fiu64_6{position:absolute;z-index:1}._track-range-selection_5bcsr_1{position:absolute;z-index:-1;opacity:0;transition:opacity .15s cubic-bezier(.25,.1,.25,1)}._track-range-selection-active_5bcsr_8{z-index:1;opacity:1}._track-range-selection-group-inactive_5bcsr_22{display:none}._track-range-selection-group-brush-selection_5bcsr_26{outline:2px solid rgba(0,0,0,.33);fill:#000;fill-opacity:.1}._drag-listening-div-active_19gkt_1{z-index:10;box-shadow:inset 0 0 3px red}._gallery-tracks_fbxxi_1{position:relative;top:0;left:0;width:100%;height:100%}._gallery-track_fbxxi_1{position:absolute;box-sizing:border-box;top:0;right:0;bottom:0;left:0}._gallery-sub-track_fbxxi_18,._gallery-invisible-track_fbxxi_19{position:absolute}._tiled-plot_1y7td_1{position:relative;flex:1;overflow:hidden}._horizontalList_1y7td_7{display:flex;width:600px;height:300px;white-space:nowrap}._list_1y7td_14{width:400px;height:600px;overflow:hidden;-webkit-overflow-scrolling:touch}._stylizedList_1y7td_21{position:relative;z-index:0;background-color:#f3f3f3;outline:none}._stylizedItem_1y7td_28{position:relative;display:flex;align-items:center;width:100%;background-color:transparent;-webkit-user-select:none;user-select:none;color:#333;font-weight:400}._stylizedHelper_1y7td_39{box-shadow:0 5px 5px -5px #0003,0 -5px 5px -5px #0003;background-color:#fffc;cursor:row-resize}._stylizedHelper_1y7td_39._horizontalItem_1y7td_44{cursor:col-resize}._horizontalItem_1y7td_44{display:flex;flex-shrink:0;align-items:center;justify-content:center}._resizable-track_1y7td_55{width:100%;height:100%}path._domain_1y7td_60{stroke-width:0px}._top-right-handle_cizw2_1,._bottom-right-handle_cizw2_2{border-right:black solid;border-top:black solid}._top-left-handle_cizw2_7,._bottom-left-handle_cizw2_8{border-left:black solid;border-top:black solid}._top-draggable-handle_cizw2_13,._bottom-draggable-handle_cizw2_14,._left-draggable-handle_cizw2_15,._right-draggable-handle_cizw2_16{position:absolute;opacity:0;transition:transform .15s cubic-bezier(.25,.1,.25,1),opacity .15s cubic-bezier(.25,.1,.25,1)}._draggable-div_cizw2_22{background-color:transparent;box-sizing:border-box}._top-draggable-handle-grabber_cizw2_27,._bottom-draggable-handle-grabber_cizw2_28{width:10px;height:4px;border-top:1px solid black;border-bottom:1px solid black}._top-draggable-handle-grabber_cizw2_27,._bottom-draggable-handle-grabber_cizw2_28{margin:4px 7px}._left-draggable-handle-grabber_cizw2_43,._right-draggable-handle-grabber_cizw2_44{width:4px;height:10px;border-left:1px solid black;border-right:1px solid black}._left-draggable-handle-grabber_cizw2_43,._right-draggable-handle-grabber_cizw2_44{margin:7px 4px}._draggable-div_cizw2_22:hover ._top-draggable-handle_cizw2_13,._draggable-div_cizw2_22:hover ._bottom-draggable-handle_cizw2_14,._draggable-div_cizw2_22:hover ._left-draggable-handle_cizw2_15,._draggable-div_cizw2_22:hover ._right-draggable-handle_cizw2_16{opacity:.5;background:rgba(255,255,255,.75);box-shadow:0 0 3px 1px #ffffffbf;border-radius:3px}._top-draggable-handle_cizw2_13:hover,._top-draggable-handle_cizw2_13:active,._bottom-draggable-handle_cizw2_14:hover,._bottom-draggable-handle_cizw2_14:active,._left-draggable-handle_cizw2_15:hover,._left-draggable-handle_cizw2_15:active,._right-draggable-handle_cizw2_16:hover,._right-draggable-handle_cizw2_16:active{opacity:1!important;transform:scale(2)}._top-draggable-handle_cizw2_13:hover ._top-draggable-handle-grabber_cizw2_27,._top-draggable-handle_cizw2_13:hover ._bottom-draggable-handle-grabber_cizw2_28,._top-draggable-handle_cizw2_13:hover ._left-draggable-handle-grabber_cizw2_43,._top-draggable-handle_cizw2_13:hover ._right-draggable-handle-grabber_cizw2_44,._top-draggable-handle_cizw2_13:active ._top-draggable-handle-grabber_cizw2_27,._top-draggable-handle_cizw2_13:active ._bottom-draggable-handle-grabber_cizw2_28,._top-draggable-handle_cizw2_13:active ._left-draggable-handle-grabber_cizw2_43,._top-draggable-handle_cizw2_13:active ._right-draggable-handle-grabber_cizw2_44,._bottom-draggable-handle_cizw2_14:hover ._top-draggable-handle-grabber_cizw2_27,._bottom-draggable-handle_cizw2_14:hover ._bottom-draggable-handle-grabber_cizw2_28,._bottom-draggable-handle_cizw2_14:hover ._left-draggable-handle-grabber_cizw2_43,._bottom-draggable-handle_cizw2_14:hover ._right-draggable-handle-grabber_cizw2_44,._bottom-draggable-handle_cizw2_14:active ._top-draggable-handle-grabber_cizw2_27,._bottom-draggable-handle_cizw2_14:active ._bottom-draggable-handle-grabber_cizw2_28,._bottom-draggable-handle_cizw2_14:active ._left-draggable-handle-grabber_cizw2_43,._bottom-draggable-handle_cizw2_14:active ._right-draggable-handle-grabber_cizw2_44,._left-draggable-handle_cizw2_15:hover ._top-draggable-handle-grabber_cizw2_27,._left-draggable-handle_cizw2_15:hover ._bottom-draggable-handle-grabber_cizw2_28,._left-draggable-handle_cizw2_15:hover ._left-draggable-handle-grabber_cizw2_43,._left-draggable-handle_cizw2_15:hover ._right-draggable-handle-grabber_cizw2_44,._left-draggable-handle_cizw2_15:active ._top-draggable-handle-grabber_cizw2_27,._left-draggable-handle_cizw2_15:active ._bottom-draggable-handle-grabber_cizw2_28,._left-draggable-handle_cizw2_15:active ._left-draggable-handle-grabber_cizw2_43,._left-draggable-handle_cizw2_15:active ._right-draggable-handle-grabber_cizw2_44,._right-draggable-handle_cizw2_16:hover ._top-draggable-handle-grabber_cizw2_27,._right-draggable-handle_cizw2_16:hover ._bottom-draggable-handle-grabber_cizw2_28,._right-draggable-handle_cizw2_16:hover ._left-draggable-handle-grabber_cizw2_43,._right-draggable-handle_cizw2_16:hover ._right-draggable-handle-grabber_cizw2_44,._right-draggable-handle_cizw2_16:active ._top-draggable-handle-grabber_cizw2_27,._right-draggable-handle_cizw2_16:active ._bottom-draggable-handle-grabber_cizw2_28,._right-draggable-handle_cizw2_16:active ._left-draggable-handle-grabber_cizw2_43,._right-draggable-handle_cizw2_16:active ._right-draggable-handle-grabber_cizw2_44{box-shadow:0 0 3px 1px #0089ff;background:#0089ff}._top-draggable-handle_cizw2_13,._bottom-draggable-handle_cizw2_14{height:12px;cursor:row-resize}._left-draggable-handle_cizw2_15,._right-draggable-handle_cizw2_16{width:12px;cursor:col-resize}._horizontal-tiled-plot_1bqkg_1{position:relative}._button_1wnjn_1{display:flex;align-items:center;box-sizing:border-box;padding:.5em;color:#000;font-size:1em;line-height:1em;border:0;border-radius:2.5px;background:#fff;box-shadow:0 0 0 1px #ccc;transition:transform .15s cubic-bezier(.25,.1,.25,1),box-shadow .15s cubic-bezier(.25,.1,.25,1),background .15s cubic-bezier(.25,.1,.25,1);-webkit-appearance:none}._button_1wnjn_1:hover{background:#f2f2f2;box-shadow:0 0 0 1px #ccc}._button_1wnjn_1:focus{box-shadow:0 0 0 2px #0089ff}._button_1wnjn_1:active{transform:scale(.9)}._button_1wnjn_1:hover,._button_1wnjn_1:focus,._button_1wnjn_1:active{cursor:pointer;outline:none}._button-shortcut_1wnjn_35{padding:.1em 5px;color:#999;font-size:.8em;transition:color .15s cubic-bezier(.25,.1,.25,1)}._cross_2ke8w_1{position:relative;width:1em;height:1em}._cross_2ke8w_1:before,._cross_2ke8w_1:after{content:"";display:block;position:absolute;top:50%;left:0;width:1em;height:1px;background:black;transform-origin:center}._cross_2ke8w_1:before{-webkit-transform:translate(0,-50%) rotate(45deg);-moz-transform:translate(0,-50%) rotate(45deg);transform:translateY(-50%) rotate(45deg)}._cross_2ke8w_1:after{-webkit-transform:translate(0,-50%) rotate(-45deg);-moz-transform:translate(0,-50%) rotate(-45deg);transform:translateY(-50%) rotate(-45deg)}._modal-background_zzhoe_1{position:absolute;z-index:1000;top:0;right:0;bottom:0;left:0;background:rgba(0,0,0,.666);animation:_fade-in_zzhoe_1 .2s cubic-bezier(.25,.1,.25,1) 1;transition:opacity .2s cubic-bezier(.25,.1,.25,1)}._modal-hide_zzhoe_13{opacity:0}._modal-wrap_zzhoe_17{position:absolute;top:20px;right:20px;bottom:20px;left:20px}._modal-window_zzhoe_25{position:relative;width:100%;max-width:640px;max-height:100%;margin-left:auto;margin-right:auto;color:#000;border-radius:5px;background:#fff;animation:_fade-scale-in_zzhoe_1 .2s cubic-bezier(.25,.1,.25,1) 1}._modal-window-max-height_zzhoe_38{height:100%}._modal-content_zzhoe_42{padding:10px}@keyframes _fade-in_zzhoe_1{0%{opacity:0}to{opacity:1}}@keyframes _fade-scale-in_zzhoe_1{0%{opacity:0;transform:scale(.5)}to{opacity:1;transform:scale(1)}}._dialog-header_wp50s_1{position:relative;z-index:2;display:flex;justify-content:space-between;margin:0 -10px 10px;padding:0 10px 10px;border-bottom:1px solid #cccccc}._dialog-header_wp50s_1 h3{margin:0;padding:0;font-size:20px;line-height:1em}._dialog-header_wp50s_1 button{font-size:10px}._dialog-main-max-height_wp50s_20{position:absolute;z-index:1;top:40px;right:0;bottom:50px;left:0;padding:10px;overflow:auto}._dialog-footer_wp50s_31,._dialog-footer-max-height_wp50s_31{display:flex;justify-content:space-between;margin:10px -10px 0;padding:10px 10px 0;border-top:1px solid #cccccc}._dialog-footer_wp50s_31 button,._dialog-footer-max-height_wp50s_31 button{font-size:14px}._dialog-footer-max-height_wp50s_31{position:absolute;z-index:2;left:10px;right:10px;bottom:10px}table.table-track-options{border-collapse:collapse;margin-left:auto;margin-right:auto}td.td-track-options{border:1px solid #fff;outline:none;padding:3px;position:relative;font-family:Roboto,sans-serif;font-size:14px;color:#666}.cell-label{position:absolute;left:0;top:0;margin-left:5px;color:#777}.modal-dialog{position:relative;display:table;overflow-y:auto;overflow-x:auto;width:auto;min-width:300px;margin:auto}._track-renderer_11dwb_1{position:relative}._track-renderer-element_11dwb_5,._track-renderer-events_11dwb_6{position:absolute;top:0;right:0;bottom:0;left:0;z-index:-1}._track-renderer-events_11dwb_6{z-index:1}.tileset-finder-label{font-weight:700}.tileset-finder-search-box{margin-left:10px}.tileset-finder-search-bar{display:flex;margin-left:5px;justify-content:space-between;align-items:center}.tileset-finder-checkbox-tree{margin:5px;padding:3px;border:1px solid #aaaaaa;border-radius:5px}.react-checkbox-tree{display:-webkit-box;display:-ms-flexbox;display:flex;-webkit-box-orient:horizontal;-webkit-box-direction:reverse;-ms-flex-direction:row-reverse;flex-direction:row-reverse;font-size:16px}.react-checkbox-tree>ol{-webkit-box-flex:1;-ms-flex:1 1 auto;flex:1 1 auto}.react-checkbox-tree ol{margin:0;padding-left:0;list-style-type:none}.react-checkbox-tree ol ol{padding-left:24px}.react-checkbox-tree button{line-height:normal;color:inherit}.react-checkbox-tree button:disabled{cursor:not-allowed}.react-checkbox-tree .rct-bare-label{cursor:default}.react-checkbox-tree label{margin-bottom:0;cursor:pointer}.react-checkbox-tree label:hover{background:rgba(51,51,204,.1)}.react-checkbox-tree label:active,.react-checkbox-tree label:focus{background:rgba(51,51,204,.15)}.react-checkbox-tree:not(.rct-native-display) input{display:none}.react-checkbox-tree.rct-native-display input{margin:0 5px}.react-checkbox-tree .rct-icon{display:inline-block;text-align:center;text-rendering:auto;font-family:"Font Awesome 5 Free",FontAwesome,sans-serif;font-weight:400;font-variant:normal;font-style:normal}.rct-disabled>.rct-text>label{opacity:.75;cursor:not-allowed}.rct-disabled>.rct-text>label:hover{background:transparent}.rct-disabled>.rct-text>label:active{background:transparent}.rct-text{display:-webkit-box;display:-ms-flexbox;display:flex;-webkit-box-align:center;-ms-flex-align:center;align-items:center}.rct-options{-webkit-box-flex:0;-ms-flex:0 0 auto;flex:0 0 auto;margin-left:.5rem;text-align:right}.rct-option{opacity:.75;border:0;background:none;cursor:pointer;padding:0 4px;font-size:18px}.rct-option:hover{opacity:1}.rct-option+.rct-option{margin-left:2px}.rct-collapse,.rct-checkbox,.rct-node-icon{padding:0 5px}.rct-collapse *,.rct-checkbox *,.rct-node-icon *{display:inline-block;margin:0;width:14px}.rct-collapse{-ms-flex-item-align:stretch;align-self:stretch;border:0;background:none;line-height:normal;color:inherit;font-size:12px}.rct-collapse.rct-collapse-btn{cursor:pointer}.rct-collapse>.rct-icon-expand-close{opacity:.5}.rct-collapse>.rct-icon-expand-close:hover{opacity:1}.rct-native-display .rct-checkbox{display:none}.rct-node-clickable{cursor:pointer}.rct-node-clickable:hover{background:rgba(51,51,204,.1)}.rct-node-clickable:focus{outline:0;background:rgba(51,51,204,.2)}.rct-node-icon{color:#33c}.rct-title{padding:0 5px}.rct-icons-fa4 .rct-icon-expand-close:before{content:""}.rct-icons-fa4 .rct-icon-expand-open:before{content:""}.rct-icons-fa4 .rct-icon-uncheck:before{content:""}.rct-icons-fa4 .rct-icon-check:before{content:""}.rct-icons-fa4 .rct-icon-half-check:before{opacity:.5;content:""}.rct-icons-fa4 .rct-icon-leaf:before{content:""}.rct-icons-fa4 .rct-icon-parent-open:before{content:""}.rct-icons-fa4 .rct-icon-parent-close:before{content:""}.rct-icons-fa4 .rct-icon-expand-all:before{content:""}.rct-icons-fa4 .rct-icon-collapse-all:before{content:""}.rct-icons-fa5 .rct-icon-expand-close:before{font-weight:900;content:""}.rct-icons-fa5 .rct-icon-expand-open:before{font-weight:900;content:""}.rct-icons-fa5 .rct-icon-uncheck:before{content:""}.rct-icons-fa5 .rct-icon-check:before{content:""}.rct-icons-fa5 .rct-icon-half-check:before{opacity:.5;content:""}.rct-icons-fa5 .rct-icon-leaf:before{content:""}.rct-icons-fa5 .rct-icon-parent-open:before{content:""}.rct-icons-fa5 .rct-icon-parent-close:before{content:""}.rct-icons-fa5 .rct-icon-expand-all:before{content:""}.rct-icons-fa5 .rct-icon-collapse-all:before{content:""}.rct-direction-rtl{direction:rtl}.rct-direction-rtl ol ol{padding-right:24px;padding-left:0}.rct-direction-rtl.rct-icons-fa4 .rct-icon-expand-close:before{content:""}.rct-direction-rtl.rct-icons-fa5 .rct-icon-expand-close:before{content:""}.plot-type-selected{background-color:#0000ff4d}.plot-type-container{overflow-y:scroll;margin:5px;padding:3px;border:1px solid #aaaaaa;border-radius:5px;max-height:15vh}.plot-type-container-empty{margin:5px;padding:3px 8px;border:1px solid #aaaaaa;background-color:#e8e8e8;border-radius:5px}.plot-type-item{cursor:pointer}.plot-type-item:not(.plot-type-selected):hover{background-color:#3333cc1a}.track-thumbnail{width:30px;height:20px;display:inline-block;margin-right:10;vertical-align:middle}.track-thumbnail>svg{width:20px;height:20px}._collapse-toggle-icon_ub7s6_1:before{font-family:Glyphicons Halflings;content:"";float:left;padding-right:3px}._collapse-toggle-icon_ub7s6_1._collapsed_ub7s6_9:before{content:""}._modal-title_ub7s6_14{font-family:Roboto;font-weight:700}._modal-container_ub7s6_19{position:relative}._modal-container_ub7s6_19 ._modal_ub7s6_14,._modal-container_ub7s6_19 ._modal-backdrop_ub7s6_23{position:absolute}._modal-dialog_ub7s6_27{position:relative;display:table;overflow-y:auto;overflow-x:auto;width:600px;min-width:300px;margin:auto}._vertical-tiled-plot_f3ho8_1{position:relative}._genome-position-search_1l2sx_1,._genome-position-search-focus_1l2sx_2{position:relative;display:flex;align-items:stretch;height:100%;margin-bottom:0;font-size:13.7142857143px;transition:box-shadow .15s cubic-bezier(.25,.1,.25,1),font-size .15s cubic-bezier(.25,.1,.25,1)}._genome-position-search-focus_1l2sx_2{box-shadow:0 0 0 1px #337ab7,0 0 3px 1px #337ab7}._genome-position-search-bar_1l2sx_16{position:relative;box-sizing:border-box;width:100%;height:100%;padding:3px;color:#666;font-size:inherit;line-height:24px;border:0;border-radius:3px 0 0 3px;background:transparent}._genome-position-search-bar_1l2sx_16:focus{outline:none;color:#000}._genome-position-search-dark_1l2sx_34 ._genome-position-search-bar_1l2sx_16:focus{color:#e5e5e5}._genome-position-search-bar-button_1l2sx_38,._genome-position-search-bar-button-focus_1l2sx_39{display:block;height:100%;padding:0 8px!important;color:#999;border:0!important;border-radius:0!important;background:transparent;transition:background .15s cubic-bezier(.25,.1,.25,1),color .15s cubic-bezier(.25,.1,.25,1)}._genome-position-search-bar-button_1l2sx_38:active,._genome-position-search-bar-button_1l2sx_38:focus,._genome-position-search-bar-button_1l2sx_38:hover,._genome-position-search-bar-button-focus_1l2sx_39:active,._genome-position-search-bar-button-focus_1l2sx_39:focus,._genome-position-search-bar-button-focus_1l2sx_39:hover{color:#fff;background:#337ab7}._genome-position-search-bar-button-focus_1l2sx_39{color:#fff;background:#337ab7}._genome-position-search-bar-icon_1l2sx_62,._genome-position-search-bar-icon-focus_1l2sx_63{display:flex;align-items:center;transition:color .15s cubic-bezier(.25,.1,.25,1)}._genome-position-search-bar-icon_1l2sx_62:first-child,._genome-position-search-bar-icon-focus_1l2sx_63:first-child{margin-left:6px;margin-right:2px}._genome-position-search-bar-icon_1l2sx_62 span,._genome-position-search-bar-icon-focus_1l2sx_63 span{display:block;margin-top:-2px}._genome-position-search-bar-icon-focus_1l2sx_63{color:#337ab7}._genome-position-search-bar-suggestions_1l2sx_83{position:fixed;border-radius:3px;box-shadow:0 0 3px #0000001a,0 1px 5px #0000000d;background-color:#fffffff2;border:1px solid rgba(0,0,0,.1);padding:2px 0;font-size:90%;overflow:auto;max-height:50%}._btn_1l2sx_95{display:inline-block;margin-bottom:0;font-size:13.7142857143px;font-weight:400;line-height:1.42857143;text-align:center;white-space:nowrap;vertical-align:middle;-ms-touch-action:manipulation;touch-action:manipulation;cursor:pointer;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;background-image:none;border:1px solid transparent;border-radius:4px}._btn-sm_1l2sx_116{font-size:12px;line-height:1.5;border-radius:3px}._btn-default_1l2sx_122{color:#666;background-color:#fff;border-color:#ccc}._btn-default_1l2sx_122:hover{color:#000;background:#ccc}._btn-default_1l2sx_122:active,._btn-default_1l2sx_122:focus{color:#fff;border-color:#000;background:#000}._genome-position-search_1l2sx_1 ._btn_1l2sx_95{border-radius:0 3px 3px 0}._export-link-dialog-wrapper_p9gxw_1{display:flex}._export-link-dialog-wrapper_p9gxw_1 input{flex-grow:1}._add-track-position-table_wdy5w_1{border-collapse:collapse;margin:5px;color:#666}._add-track-position-table-dark_wdy5w_7{color:#ccc}._add-track-position-other_wdy5w_11{outline:none}._add-track-position-top-center_wdy5w_15{min-width:80px;min-height:20px;text-align:center;outline:none;border-top:1px solid #999;border-left:1px solid #999;border-right:1px solid #999;border-radius:2px 2px 0 0}._add-track-position-top-center_wdy5w_15:hover{color:#fff;background-color:#337ab7}._add-track-position-middle-left_wdy5w_30{min-width:40px;text-align:center;outline:none;border-top:1px solid #999;border-left:1px solid #999;border-bottom:1px solid #999;border-radius:2px 0 0 2px}._add-track-position-middle-left_wdy5w_30:hover{background-color:#337ab7;color:#fff}._add-track-position-middle-right_wdy5w_45{min-width:40px;text-align:center;outline:none;border-top:1px solid #999;border-right:1px solid #999;border-bottom:1px solid #999;border-radius:0 2px 2px 0}._add-track-position-middle-right_wdy5w_45:hover{background-color:#337ab7;color:#fff}._add-track-position-middle-middle_wdy5w_60{text-align:center;outline:none;border:1px solid #999}._add-track-position-middle-middle_wdy5w_60:hover{background-color:#337ab7;color:#fff}._add-track-position-bottom-middle_wdy5w_71{min-height:20px;text-align:center;outline:none;border-left:1px solid #999;border-right:1px solid #999;border-bottom:1px solid #999;border-radius:0 0 2px 2px}._add-track-position-bottom-middle_wdy5w_71:hover{background-color:#337ab7;color:#fff}._add-track-position-span_wdy5w_86{margin:5px}._view-config-editor-header_1hlm6_1{margin:-10px -10px 0;padding:10px;display:flex;justify-content:space-between;background:#f2f2f2}._view-config-editor-header_1hlm6_1 button{display:flex;align-items:center;font-size:14px;background:#f2f2f2}._view-config-editor-header_1hlm6_1 button:hover{background:#e5e5e5}._view-config-editor-header_1hlm6_1 button:hover span{color:#666}._view-config-editor_1hlm6_1{position:absolute;top:50px;right:0;bottom:0;left:0;margin:1px 0 0;padding:0;overflow:auto;font-size:12.5px;height:calc(100% - 80px)}._view-config-log_1hlm6_34{position:absolute;right:0;bottom:0;left:0;margin:1px 0 0;padding:0;min-height:30px;background:#f2f2f2;transition:height .15s cubic-bezier(.25,.1,.25,1)}._view-config-log-header_1hlm6_46{background:#f2f2f2;border-top:1px solid #cccccc;border-bottom:1px solid #cccccc;padding-left:10px;height:30px;display:flex;align-items:center;cursor:pointer;position:sticky;position:-webkit-sticky;top:0}._view-config-log-msg_1hlm6_60{background:#f2f2f2;overflow:auto;height:calc(100% - 30px)}._view-config-log-msg_1hlm6_60 tr,._view-config-log-msg_1hlm6_60 td{outline:none;vertical-align:top}._view-config-log-msg_1hlm6_60 ._title_1hlm6_70{font-weight:700;padding-left:8px;padding-top:8px;width:100px}._view-config-log-msg_1hlm6_60 ._Warning_1hlm6_76{color:orange}._view-config-log-msg_1hlm6_60 ._Success_1hlm6_79{color:green}._view-config-log-msg_1hlm6_60 ._Error_1hlm6_82{color:red}._view-config-log-msg_1hlm6_60 pre{background:white;white-space:pre-wrap;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;word-wrap:break-word}._higlass_1uoq8_1{position:relative}._higlass-dark-theme_1uoq8_5{background:black}._higlass-container-overflow_1uoq8_9,._higlass-scroll-container-overflow_1uoq8_10,._higlass-scroll-container-scroll_1uoq8_11{position:absolute;top:0;right:0;bottom:0;left:0}._higlass-scroll-container-overflow_1uoq8_10{overflow:hidden}._higlass-scroll-container-scroll_1uoq8_11{overflow-x:hidden;overflow-y:auto}._higlass-canvas_1uoq8_28{position:absolute;width:100%;height:100%}._higlass-drawing-surface_1uoq8_34{position:relative}._higlass-svg_1uoq8_38{position:absolute;width:100%;height:100%;left:0;top:0;pointer-events:none}._tiled-area_1uoq8_47{display:flex;flex-direction:column}._track-mouseover-menu_1uoq8_52{position:fixed;z-index:1;margin:17px 0 0 9px;padding:0 .25rem;max-width:50vw;word-wrap:break-word;font-size:.8em;pointer-events:none;background:white;border-radius:.25rem;box-shadow:0 0 0 1px #0000001a,0 0 3px #00000013,0 0 7px #0000000d}.react-grid-layout{position:relative;transition:height .2s ease}.react-grid-item{transition:all .2s ease;transition-property:left,top}.react-grid-item.cssTransforms{transition-property:transform}.react-grid-item.resizing{z-index:1;will-change:width,height}.react-grid-item.react-draggable-dragging{transition:none;z-index:3;will-change:transform}.react-grid-item.react-grid-placeholder{background:red;opacity:.2;transition-duration:.1s;z-index:2;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;-o-user-select:none;user-select:none}.react-grid-item>.react-resizable-handle{position:absolute;width:20px;height:20px;bottom:0;right:0;cursor:se-resize}.react-grid-item>.react-resizable-handle:after{content:"";position:absolute;right:3px;bottom:3px;width:5px;height:5px;border-right:2px solid rgba(0,0,0,.4);border-bottom:2px solid rgba(0,0,0,.4)}.react-resizable{position:relative}.react-resizable-handle{position:absolute;width:20px;height:20px;background-repeat:no-repeat;background-origin:content-box;box-sizing:border-box;background-image:url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA2IDYiIHN0eWxlPSJiYWNrZ3JvdW5kLWNvbG9yOiNmZmZmZmYwMCIgeD0iMHB4IiB5PSIwcHgiIHdpZHRoPSI2cHgiIGhlaWdodD0iNnB4Ij48ZyBvcGFjaXR5PSIwLjMwMiI+PHBhdGggZD0iTSA2IDYgTCAwIDYgTCAwIDQuMiBMIDQgNC4yIEwgNC4yIDQuMiBMIDQuMiAwIEwgNiAwIEwgNiA2IEwgNiA2IFoiIGZpbGw9IiMwMDAwMDAiLz48L2c+PC9zdmc+);background-position:bottom right;padding:0 3px 3px 0}.react-resizable-handle-sw{bottom:0;left:0;cursor:sw-resize;transform:rotate(90deg)}.react-resizable-handle-se{bottom:0;right:0;cursor:se-resize}.react-resizable-handle-nw{top:0;left:0;cursor:nw-resize;transform:rotate(180deg)}.react-resizable-handle-ne{top:0;right:0;cursor:ne-resize;transform:rotate(270deg)}.react-resizable-handle-w,.react-resizable-handle-e{top:50%;margin-top:-10px;cursor:ew-resize}.react-resizable-handle-w{left:0;transform:rotate(135deg)}.react-resizable-handle-e{right:0;transform:rotate(315deg)}.react-resizable-handle-n,.react-resizable-handle-s{left:50%;margin-left:-10px;cursor:ns-resize}.react-resizable-handle-n{top:0;transform:rotate(225deg)}.react-resizable-handle-s{bottom:0;transform:rotate(45deg)}code[class*=language-],pre[class*=language-]{color:#393a34;font-family:Consolas,Bitstream Vera Sans Mono,Courier New,Courier,monospace;direction:ltr;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;font-size:.95em;line-height:1.2em;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none}pre[class*=language-]::-moz-selection,pre[class*=language-] ::-moz-selection,code[class*=language-]::-moz-selection,code[class*=language-] ::-moz-selection{background:#b3d4fc}pre[class*=language-]::selection,pre[class*=language-] ::selection,code[class*=language-]::selection,code[class*=language-] ::selection{background:#b3d4fc}pre[class*=language-]{padding:1em;margin:.5em 0;overflow:auto;border:1px solid #dddddd;background-color:#fff}:not(pre)>code[class*=language-]{padding:1px .2em;background:#f8f8f8;border:1px solid #dddddd}.token.comment,.token.prolog,.token.doctype,.token.cdata{color:#998;font-style:italic}.token.namespace{opacity:.7}.token.string,.token.attr-value{color:#e3116c}.token.punctuation,.token.operator{color:#393a34}.token.entity,.token.url,.token.symbol,.token.number,.token.boolean,.token.variable,.token.constant,.token.property,.token.regex,.token.inserted{color:#36acaa}.token.atrule,.token.keyword,.token.attr-name,.language-autohotkey .token.selector{color:#00a4db}.token.function,.token.deleted,.language-autohotkey .token.tag{color:#9a050f}.token.tag,.token.selector,.language-autohotkey .token.keyword{color:#00009f}.token.important,.token.function,.token.bold{font-weight:700}.token.italic{font-style:italic}.higlass *{box-sizing:border-box}.higlass .react-resizable-handle{z-index:1}')),document.head.appendChild(g)}}catch(e){console.error("vite-plugin-css-injected-by-js",e)}})();var Le=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{};function FC(g){return g&&g.__esModule&&Object.prototype.hasOwnProperty.call(g,"default")?g.default:g}function Al(g){if(g.__esModule)return g;var e=g.default;if(typeof e=="function"){var I=function i(){return this instanceof i?Reflect.construct(e,arguments,this.constructor):e.apply(this,arguments)};I.prototype=e.prototype}else I={};return Object.defineProperty(I,"__esModule",{value:!0}),Object.keys(g).forEach(function(i){var n=Object.getOwnPropertyDescriptor(g,i);Object.defineProperty(I,i,n.get?n:{enumerable:!0,get:function(){return g[i]}})}),I}var Y0e={exports:{}},L8e="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED",_8e=L8e,U8e=_8e;function K0e(){}function x0e(){}x0e.resetWarningCache=K0e;var Q8e=function(){function g(i,n,C,r,o,A){if(A!==U8e){var s=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw s.name="Invariant Violation",s}}g.isRequired=g;function e(){return g}var I={array:g,bigint:g,bool:g,func:g,number:g,object:g,string:g,symbol:g,any:g,arrayOf:e,element:g,elementType:g,instanceOf:e,node:g,objectOf:e,oneOf:e,oneOfType:e,shape:e,exact:e,checkPropTypes:x0e,resetWarningCache:K0e};return I.PropTypes=I,I};Y0e.exports=Q8e();var al=Y0e.exports;const L=FC(al);var G3="http://www.w3.org/1999/xhtml";const B3={svg:"http://www.w3.org/2000/svg",xhtml:G3,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function Cm(g){var e=g+="",I=e.indexOf(":");return I>=0&&(e=g.slice(0,I))!=="xmlns"&&(g=g.slice(I+1)),B3.hasOwnProperty(e)?{space:B3[e],local:g}:g}function j8e(g){return function(){var e=this.ownerDocument,I=this.namespaceURI;return I===G3&&e.documentElement.namespaceURI===G3?e.createElement(g):e.createElementNS(I,g)}}function $8e(g){return function(){return this.ownerDocument.createElementNS(g.space,g.local)}}function hN(g){var e=Cm(g);return(e.local?$8e:j8e)(e)}function q8e(){}function US(g){return g==null?q8e:function(){return this.querySelector(g)}}function e6e(g){typeof g!="function"&&(g=US(g));for(var e=this._groups,I=e.length,i=new Array(I),n=0;n=p&&(p=b+1);!(Z=m[p])&&++p=0;)(r=i[n])&&(C&&r.compareDocumentPosition(C)^4&&C.parentNode.insertBefore(r,C),C=r);return this}function G6e(g){g||(g=B6e);function e(l,c){return l&&c?g(l.__data__,c.__data__):!l-!c}for(var I=this._groups,i=I.length,n=new Array(i),C=0;Ce?1:g>=e?0:NaN}function v6e(){var g=arguments[0];return arguments[0]=this,g.apply(null,arguments),this}function S6e(){return Array.from(this)}function w6e(){for(var g=this._groups,e=0,I=g.length;e1?this.each((e==null?x6e:typeof e=="function"?F6e:D6e)(g,e,I??"")):oo(this.node(),g)}function oo(g,e){return g.style.getPropertyValue(e)||l7(g).getComputedStyle(g,null).getPropertyValue(e)}function M6e(g){return function(){delete this[g]}}function z6e(g,e){return function(){this[g]=e}}function P6e(g,e){return function(){var I=e.apply(this,arguments);I==null?delete this[g]:this[g]=I}}function J6e(g,e){return arguments.length>1?this.each((e==null?M6e:typeof e=="function"?P6e:z6e)(g,e)):this.node()[g]}function E0e(g){return g.trim().split(/^|\s+/)}function c7(g){return g.classList||new M0e(g)}function M0e(g){this._node=g,this._names=E0e(g.getAttribute("class")||"")}M0e.prototype={add:function(g){var e=this._names.indexOf(g);e<0&&(this._names.push(g),this._node.setAttribute("class",this._names.join(" ")))},remove:function(g){var e=this._names.indexOf(g);e>=0&&(this._names.splice(e,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(g){return this._names.indexOf(g)>=0}};function z0e(g,e){for(var I=c7(g),i=-1,n=e.length;++i=0&&(I=e.slice(i+1),e=e.slice(0,i)),{type:e,name:I}})}function pqe(g){return function(){var e=this.__on;if(e){for(var I=0,i=-1,n=e.length,C;IOg(I,e))}function Wqe(g){return typeof g=="string"?new kn([document.querySelectorAll(g)],[document.documentElement]):new kn([g==null?[]:s7(g)],u7)}const Xqe=Object.freeze(Object.defineProperty({__proto__:null,create:wqe,creator:hN,local:O0e,matcher:fN,namespace:Cm,namespaces:B3,pointer:Og,pointers:Rqe,select:pg,selectAll:Wqe,selection:fA,selector:US,selectorAll:mN,style:oo,window:l7},Symbol.toStringTag,{value:"Module"}));function pi(g,e){return ge?1:g>=e?0:NaN}function M0(g){let e=g,I=g;g.length===1&&(e=(r,o)=>g(r)-o,I=Hqe(g));function i(r,o,A,s){for(A==null&&(A=0),s==null&&(s=r.length);A>>1;I(r[a],o)<0?A=a+1:s=a}return A}function n(r,o,A,s){for(A==null&&(A=0),s==null&&(s=r.length);A>>1;I(r[a],o)>0?s=a:A=a+1}return A}function C(r,o,A,s){A==null&&(A=0),s==null&&(s=r.length);const a=i(r,o,A,s-1);return a>A&&e(r[a-1],o)>-e(r[a],o)?a-1:a}return{left:i,center:C,right:n}}function Hqe(g){return(e,I)=>pi(g(e),I)}function _0e(g){return g===null?NaN:+g}function*Tqe(g,e){if(e===void 0)for(let I of g)I!=null&&(I=+I)>=I&&(yield I);else{let I=-1;for(let i of g)(i=e(i,++I,g))!=null&&(i=+i)>=i&&(yield i)}}const U0e=M0(pi),Q0e=U0e.right,Nqe=U0e.left,kqe=M0(_0e).center,rm=Q0e;function pN(g,e){let I=0;if(e===void 0)for(let i of g)i!=null&&(i=+i)>=i&&++I;else{let i=-1;for(let n of g)(n=e(n,++i,g))!=null&&(n=+n)>=n&&++I}return I}function Yqe(g){return g.length|0}function Kqe(g){return!(g>0)}function xqe(g){return typeof g!="object"||"length"in g?g:Array.from(g)}function Dqe(g){return e=>g(...e)}function Fqe(...g){const e=typeof g[g.length-1]=="function"&&Dqe(g.pop());g=g.map(xqe);const I=g.map(Yqe),i=g.length-1,n=new Array(i+1).fill(0),C=[];if(i<0||I.some(Kqe))return C;for(;;){C.push(n.map((o,A)=>g[A][o]));let r=i;for(;++n[r]===I[r];){if(r===0)return e?C.map(e):C;n[r--]=0}}}function Eqe(g,e){var I=0,i=0;return Float64Array.from(g,e===void 0?n=>I+=+n||0:n=>I+=+e(n,i++,g)||0)}function Mqe(g,e){return eg?1:e>=g?0:NaN}function d7(g,e){let I=0,i,n=0,C=0;if(e===void 0)for(let r of g)r!=null&&(r=+r)>=r&&(i=r-n,n+=i/++I,C+=i*(r-n));else{let r=-1;for(let o of g)(o=e(o,++r,g))!=null&&(o=+o)>=o&&(i=o-n,n+=i/++I,C+=i*(o-n))}if(I>1)return C/(I-1)}function h7(g,e){const I=d7(g,e);return I&&Math.sqrt(I)}function j1(g,e){let I,i;if(e===void 0)for(const n of g)n!=null&&(I===void 0?n>=n&&(I=i=n):(I>n&&(I=n),i=C&&(I=i=C):(I>C&&(I=C),i0){for(o=I[--i];i>0&&(n=o,C=I[--i],o=n+C,r=C-(o-n),!r););i>0&&(r<0&&I[i-1]<0||r>0&&I[i-1]>0)&&(C=r*2,n=o+C,C==n-o&&(o=n))}return o}}]),g}();function Lqe(g,e){const I=new Xi;if(e===void 0)for(let i of g)(i=+i)&&I.add(i);else{let i=-1;for(let n of g)(n=+e(n,++i,g))&&I.add(n)}return+I}function _qe(g,e){const I=new Xi;let i=-1;return Float64Array.from(g,e===void 0?n=>I.add(+n||0):n=>I.add(+e(n,++i,g)||0))}function j0e(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function cge(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function qqe(g){try{return Function.toString.call(g).indexOf("[native code]")!==-1}catch{return typeof g=="function"}}function Tv(g,e){return Tv=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(i,n){return i.__proto__=n,i},Tv(g,e)}function lr(g){return lr=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},lr(g)}let p9=function(g){q0e(I,g);var e=eye(I);function I(i,n=iye){var C;if(j0e(this,I),C=e.call(this),Object.defineProperties(m7(C),{_intern:{value:new Map},_key:{value:n}}),i!=null)for(const[r,o]of i)C.set(r,o);return C}return $0e(I,[{key:"get",value:function(n){return Aa(lr(I.prototype),"get",this).call(this,S3(this,n))}},{key:"has",value:function(n){return Aa(lr(I.prototype),"has",this).call(this,S3(this,n))}},{key:"set",value:function(n,C){return Aa(lr(I.prototype),"set",this).call(this,gye(this,n),C)}},{key:"delete",value:function(n){return Aa(lr(I.prototype),"delete",this).call(this,Iye(this,n))}}]),I}(f9(Map)),eet=function(g){q0e(I,g);var e=eye(I);function I(i,n=iye){var C;if(j0e(this,I),C=e.call(this),Object.defineProperties(m7(C),{_intern:{value:new Map},_key:{value:n}}),i!=null)for(const r of i)C.add(r);return C}return $0e(I,[{key:"has",value:function(n){return Aa(lr(I.prototype),"has",this).call(this,S3(this,n))}},{key:"add",value:function(n){return Aa(lr(I.prototype),"add",this).call(this,gye(this,n))}},{key:"delete",value:function(n){return Aa(lr(I.prototype),"delete",this).call(this,Iye(this,n))}}]),I}(f9(Set));function S3({_intern:g,_key:e},I){const i=e(I);return g.has(i)?g.get(i):I}function gye({_intern:g,_key:e},I){const i=e(I);return g.has(i)?g.get(i):(g.set(i,I),I)}function Iye({_intern:g,_key:e},I){const i=e(I);return g.has(i)&&(I=g.get(I),g.delete(i)),I}function iye(g){return g!==null&&typeof g=="object"?g.valueOf():g}function Nb(g){return g}function nye(g,...e){return z0(g,Nb,Nb,e)}function tet(g,...e){return z0(g,Array.from,Nb,e)}function Cye(g,e,...I){return z0(g,Nb,e,I)}function get(g,e,...I){return z0(g,Array.from,e,I)}function Iet(g,...e){return z0(g,Nb,rye,e)}function iet(g,...e){return z0(g,Array.from,rye,e)}function rye(g){if(g.length!==1)throw new Error("duplicate key");return g[0]}function z0(g,e,I,i){return function n(C,r){if(r>=i.length)return I(C);const o=new p9,A=i[r++];let s=-1;for(const a of C){const l=A(a,++s,C),c=o.get(l);c?c.push(a):o.set(l,[a])}for(const[a,l]of o)o.set(a,n(l,r));return e(o)}(g,0)}function oye(g,e){return Array.from(e,I=>g[I])}function w3(g,...e){if(typeof g[Symbol.iterator]!="function")throw new TypeError("values is not iterable");g=Array.from(g);let[I=pi]=e;if(I.length===1||e.length>1){const i=Uint32Array.from(g,(n,C)=>C);return e.length>1?(e=e.map(n=>g.map(n)),i.sort((n,C)=>{for(const r of e){const o=pi(r[n],r[C]);if(o)return o}})):(I=g.map(I),i.sort((n,C)=>pi(I[n],I[C]))),oye(g,i)}return g.sort(I)}function net(g,e,I){return(e.length===1?w3(Cye(g,e,I),([i,n],[C,r])=>pi(n,r)||pi(i,C)):w3(nye(g,I),([i,n],[C,r])=>e(n,r)||pi(i,C))).map(([i])=>i)}var Cet=Array.prototype,ret=Cet.slice;function oR(g){return function(){return g}}var V3=Math.sqrt(50),R3=Math.sqrt(10),W3=Math.sqrt(2);function sh(g,e,I){var i,n=-1,C,r,o;if(e=+e,g=+g,I=+I,g===e&&I>0)return[g];if((i=e0){let A=Math.round(g/o),s=Math.round(e/o);for(A*oe&&--s,r=new Array(C=s-A+1);++ne&&--s,r=new Array(C=s-A+1);++n=0?(C>=V3?10:C>=R3?5:C>=W3?2:1)*Math.pow(10,n):-Math.pow(10,-n)/(C>=V3?10:C>=R3?5:C>=W3?2:1)}function b9(g,e,I){var i=Math.abs(e-g)/Math.max(0,I),n=Math.pow(10,Math.floor(Math.log(i)/Math.LN10)),C=i/n;return C>=V3?n*=10:C>=R3?n*=5:C>=W3&&(n*=2),e0?(g=Math.floor(g/n)*n,e=Math.ceil(e/n)*n):n<0&&(g=Math.ceil(g*n)/n,e=Math.floor(e*n)/n),i=n}}function aye(g){return Math.ceil(Math.log(pN(g))/Math.LN2)+1}function uge(){var g=Nb,e=j1,I=aye;function i(n){Array.isArray(n)||(n=Array.from(n));var C,r=n.length,o,A=new Array(r);for(C=0;C=l)if(m>=l&&e===j1){const b=QS(a,l,f);isFinite(b)&&(b>0?l=(Math.floor(l/b)+1)*b:b<0&&(l=(Math.ceil(l*-b)+1)/-b))}else c.pop()}for(var u=c.length;c[0]<=a;)c.shift(),--u;for(;c[u-1]>l;)c.pop(),--u;var d=new Array(u+1),h;for(C=0;C<=u;++C)h=d[C]=[],h.x0=C>0?c[C-1]:a,h.x1=C=i)&&(I=i);else{let i=-1;for(let n of g)(n=e(n,++i,g))!=null&&(I=n)&&(I=n)}return I}function y9(g,e){let I;if(e===void 0)for(const i of g)i!=null&&(I>i||I===void 0&&i>=i)&&(I=i);else{let i=-1;for(let n of g)(n=e(n,++i,g))!=null&&(I>n||I===void 0&&n>=n)&&(I=n)}return I}function f7(g,e,I=0,i=g.length-1,n=pi){for(;i>I;){if(i-I>600){const A=i-I+1,s=e-I+1,a=Math.log(A),l=.5*Math.exp(2*a/3),c=.5*Math.sqrt(a*l*(A-l)/A)*(s-A/2<0?-1:1),u=Math.max(I,Math.floor(e-s*l/A+c)),d=Math.min(i,Math.floor(e+(A-s)*l/A+c));f7(g,e,u,d,n)}const C=g[e];let r=I,o=i;for(Qy(g,I,e),n(g[i],C)>0&&Qy(g,I,i);r0;)--o}n(g[I],C)===0?Qy(g,I,o):(++o,Qy(g,o,i)),o<=e&&(I=o+1),e<=o&&(i=o-1)}return g}function Qy(g,e,I){const i=g[e];g[e]=g[I],g[I]=i}function Nv(g,e,I){if(g=Float64Array.from(Tqe(g,I)),!!(i=g.length)){if((e=+e)<=0||i<2)return y9(g);if(e>=1)return X3(g);var i,n=(i-1)*e,C=Math.floor(n),r=X3(f7(g,C).subarray(0,C+1)),o=y9(g.subarray(C+1));return r+(o-r)*(n-C)}}function sye(g,e,I=_0e){if(i=g.length){if((e=+e)<=0||i<2)return+I(g[0],0,g);if(e>=1)return+I(g[i-1],i-1,g);var i,n=(i-1)*e,C=Math.floor(n),r=+I(g[C],C,g),o=+I(g[C+1],C+1,g);return r+(o-r)*(n-C)}}function oet(g,e,I){return Math.ceil((I-e)/(2*(Nv(g,.75)-Nv(g,.25))*Math.pow(pN(g),-1/3)))}function Aet(g,e,I){return Math.ceil((I-e)/(3.5*h7(g)*Math.pow(pN(g),-1/3)))}function lye(g,e){let I,i=-1,n=-1;if(e===void 0)for(const C of g)++n,C!=null&&(I=C)&&(I=C,i=n);else for(let C of g)(C=e(C,++n,g))!=null&&(I=C)&&(I=C,i=n);return i}function H3(g,e){let I=0,i=0;if(e===void 0)for(let n of g)n!=null&&(n=+n)>=n&&(++I,i+=n);else{let n=-1;for(let C of g)(C=e(C,++n,g))!=null&&(C=+C)>=C&&(++I,i+=C)}if(I)return i/I}function p7(g,e){return Nv(g,.5,e)}function*aet(g){for(const e of g)yield*e}function b7(g){return Array.from(aet(g))}function cye(g,e){let I,i=-1,n=-1;if(e===void 0)for(const C of g)++n,C!=null&&(I>C||I===void 0&&C>=C)&&(I=C,i=n);else for(let C of g)(C=e(C,++n,g))!=null&&(I>C||I===void 0&&C>=C)&&(I=C,i=n);return i}function set(g,e=cet){const I=[];let i,n=!1;for(const C of g)n&&I.push(e(i,C)),i=C,n=!0;return I}function cet(g,e){return[g,e]}function iC(g,e,I){g=+g,e=+e,I=(n=arguments.length)<2?(e=g,g=0,1):n<3?1:+I;for(var i=-1,n=Math.max(0,Math.ceil((e-g)/I))|0,C=new Array(n);++i0:pi(r,r)===0)&&(I=C,n=r,i=!0)}}else for(const n of g)(i?e(n,I)>0:e(n,n)===0)&&(I=n,i=!0);return I}function het(g,e=pi){if(e.length===1)return lye(g,e);let I,i=-1,n=-1;for(const C of g)++n,(i<0?e(C,C)===0:e(C,I)>0)&&(I=C,i=n);return i}function met(g,e){const I=uye(g,e);return I<0?void 0:I}const fet=dye(Math.random);function dye(g){return function(I,i=0,n=I.length){let C=n-(i=+i);for(;C;){const r=g()*C--|0,o=I[C+i];I[C+i]=I[r+i],I[r+i]=o}return I}}function hye(g,e){let I=0;if(e===void 0)for(let i of g)(i=+i)&&(I+=i);else{let i=-1;for(let n of g)(n=+e(n,++i,g))&&(I+=n)}return I}function mye(g){if(!(C=g.length))return[];for(var e=-1,I=y9(g,pet),i=new Array(I);++ee(I,i,g))}function vet(g,e,I){if(typeof e!="function")throw new TypeError("reducer is not a function");const i=g[Symbol.iterator]();let n,C,r=-1;if(arguments.length<3){if({done:n,value:I}=i.next(),n)return;++r}for(;{done:n,value:C}=i.next(),!n;)I=e(I,C,++r,g);return I}function wet(g){if(typeof g[Symbol.iterator]!="function")throw new TypeError("values is not iterable");return Array.from(g).reverse()}function Vet(g,...e){g=new Set(g);for(const I of e)for(const i of I)g.delete(i);return g}function Ret(g,e){const I=e[Symbol.iterator](),i=new Set;for(const n of g){if(i.has(n))return!1;let C,r;for(;({value:C,done:r}=I.next())&&!r;){if(Object.is(n,C))return!1;i.add(C)}}return!0}function Wet(g){return g instanceof Set?g:new Set(g)}function Xet(g,...e){g=new Set(g),e=e.map(Wet);e:for(const I of g)for(const i of e)if(!i.has(I)){g.delete(I);continue e}return g}function fye(g,e){const I=g[Symbol.iterator](),i=new Set;for(const n of e){if(i.has(n))continue;let C,r;for(;{value:C,done:r}=I.next();){if(r)return!1;if(i.add(C),Object.is(n,C))break}}return!0}function Het(g,e){return fye(e,g)}function Tet(...g){const e=new Set;for(const I of g)for(const i of I)e.add(i);return e}const Net=Object.freeze(Object.defineProperty({__proto__:null,Adder:Xi,InternMap:p9,InternSet:eet,ascending:pi,bin:uge,bisect:rm,bisectCenter:kqe,bisectLeft:Nqe,bisectRight:Q0e,bisector:M0,count:pN,cross:Fqe,cumsum:Eqe,descending:Mqe,deviation:h7,difference:Vet,disjoint:Ret,every:yet,extent:j1,fcumsum:_qe,filter:Get,fsum:Lqe,greatest:det,greatestIndex:het,group:nye,groupSort:net,groups:tet,histogram:uge,index:Iet,indexes:iet,intersection:Xet,least:uet,leastIndex:uye,map:Bet,max:X3,maxIndex:lye,mean:H3,median:p7,merge:b7,min:y9,minIndex:cye,nice:Aye,pairs:set,permute:oye,quantile:Nv,quantileSorted:sye,quickselect:f7,range:iC,reduce:vet,reverse:wet,rollup:Cye,rollups:get,scan:met,shuffle:fet,shuffler:dye,some:Zet,sort:w3,subset:Het,sum:hye,superset:fye,thresholdFreedmanDiaconis:oet,thresholdScott:Aet,thresholdSturges:aye,tickIncrement:QS,tickStep:b9,ticks:sh,transpose:mye,union:Tet,variance:d7,zip:bet},Symbol.toStringTag,{value:"Module"}));function lo(g,e){switch(arguments.length){case 0:break;case 1:this.range(g);break;default:this.range(e).domain(g);break}return this}function sl(g,e){switch(arguments.length){case 0:break;case 1:{typeof g=="function"?this.interpolator(g):this.range(g);break}default:{this.domain(g),typeof e=="function"?this.interpolator(e):this.range(e);break}}return this}const T3=Symbol("implicit");function y7(){var g=new p9,e=[],I=[],i=T3;function n(C){let r=g.get(C);if(r===void 0){if(i!==T3)return i;g.set(C,r=e.push(C)-1)}return I[r%I.length]}return n.domain=function(C){if(!arguments.length)return e.slice();e=[],g=new p9;for(const r of C)g.has(r)||g.set(r,e.push(r)-1);return n},n.range=function(C){return arguments.length?(I=Array.from(C),n):I.slice()},n.unknown=function(C){return arguments.length?(i=C,n):i},n.copy=function(){return y7(e,I).unknown(i)},lo.apply(n,arguments),n}function jS(){var g=y7().unknown(void 0),e=g.domain,I=g.range,i=0,n=1,C,r,o=!1,A=0,s=0,a=.5;delete g.unknown;function l(){var c=e().length,u=n>8&15|e>>4&240,e>>4&15|e&240,(e&15)<<4|e&15,1):I===8?AR(e>>24&255,e>>16&255,e>>8&255,(e&255)/255):I===4?AR(e>>12&15|e>>8&240,e>>8&15|e>>4&240,e>>4&15|e&240,((e&15)<<4|e&15)/255):null):(e=Ket.exec(g))?new An(e[1],e[2],e[3],1):(e=xet.exec(g))?new An(e[1]*255/100,e[2]*255/100,e[3]*255/100,1):(e=Det.exec(g))?AR(e[1],e[2],e[3],e[4]):(e=Fet.exec(g))?AR(e[1]*255/100,e[2]*255/100,e[3]*255/100,e[4]):(e=Eet.exec(g))?yge(e[1],e[2]/100,e[3]/100,1):(e=Met.exec(g))?yge(e[1],e[2]/100,e[3]/100,e[4]):dge.hasOwnProperty(g)?fge(dge[g]):g==="transparent"?new An(NaN,NaN,NaN,0):null}function fge(g){return new An(g>>16&255,g>>8&255,g&255,1)}function AR(g,e,I,i){return i<=0&&(g=e=I=NaN),new An(g,e,I,i)}function Z7(g){return g instanceof du||(g=wi(g)),g?(g=g.rgb(),new An(g.r,g.g,g.b,g.opacity)):new An}function Yb(g,e,I,i){return arguments.length===1?Z7(g):new An(g,e,I,i??1)}function An(g,e,I,i){this.r=+g,this.g=+e,this.b=+I,this.opacity=+i}P0(An,Yb,$S(du,{brighter:function(g){return g=g==null?kb:Math.pow(kb,g),new An(this.r*g,this.g*g,this.b*g,this.opacity)},darker:function(g){return g=g==null?lh:Math.pow(lh,g),new An(this.r*g,this.g*g,this.b*g,this.opacity)},rgb:function(){return this},displayable:function(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:pge,formatHex:pge,formatRgb:bge,toString:bge}));function pge(){return"#"+M5(this.r)+M5(this.g)+M5(this.b)}function bge(){var g=this.opacity;return g=isNaN(g)?1:Math.max(0,Math.min(1,g)),(g===1?"rgb(":"rgba(")+Math.max(0,Math.min(255,Math.round(this.r)||0))+", "+Math.max(0,Math.min(255,Math.round(this.g)||0))+", "+Math.max(0,Math.min(255,Math.round(this.b)||0))+(g===1?")":", "+g+")")}function M5(g){return g=Math.max(0,Math.min(255,Math.round(g)||0)),(g<16?"0":"")+g.toString(16)}function yge(g,e,I,i){return i<=0?g=e=I=NaN:I<=0||I>=1?g=e=NaN:e<=0&&(g=NaN),new _A(g,e,I,i)}function bye(g){if(g instanceof _A)return new _A(g.h,g.s,g.l,g.opacity);if(g instanceof du||(g=wi(g)),!g)return new _A;if(g instanceof _A)return g;g=g.rgb();var e=g.r/255,I=g.g/255,i=g.b/255,n=Math.min(e,I,i),C=Math.max(e,I,i),r=NaN,o=C-n,A=(C+n)/2;return o?(e===C?r=(I-i)/o+(I0&&A<1?0:r,new _A(r,o,A,g.opacity)}function yye(g,e,I,i){return arguments.length===1?bye(g):new _A(g,e,I,i??1)}function _A(g,e,I,i){this.h=+g,this.s=+e,this.l=+I,this.opacity=+i}P0(_A,yye,$S(du,{brighter:function(g){return g=g==null?kb:Math.pow(kb,g),new _A(this.h,this.s,this.l*g,this.opacity)},darker:function(g){return g=g==null?lh:Math.pow(lh,g),new _A(this.h,this.s,this.l*g,this.opacity)},rgb:function(){var g=this.h%360+(this.h<0)*360,e=isNaN(g)||isNaN(this.s)?0:this.s,I=this.l,i=I+(I<.5?I:1-I)*e,n=2*I-i;return new An(z5(g>=240?g-240:g+120,n,i),z5(g,n,i),z5(g<120?g+240:g-120,n,i),this.opacity)},displayable:function(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl:function(){var g=this.opacity;return g=isNaN(g)?1:Math.max(0,Math.min(1,g)),(g===1?"hsl(":"hsla(")+(this.h||0)+", "+(this.s||0)*100+"%, "+(this.l||0)*100+"%"+(g===1?")":", "+g+")")}}));function z5(g,e,I){return(g<60?e+(I-e)*g/60:g<180?I:g<240?e+(I-e)*(240-g)/60:e)*255}const Zye=Math.PI/180,Gye=180/Math.PI,Z9=18,Bye=.96422,vye=1,Sye=.82521,wye=4/29,Ep=6/29,Vye=3*Ep*Ep,Pet=Ep*Ep*Ep;function Rye(g){if(g instanceof AA)return new AA(g.l,g.a,g.b,g.opacity);if(g instanceof aa)return Tye(g);g instanceof An||(g=Z7(g));var e=L5(g.r),I=L5(g.g),i=L5(g.b),n=P5((.2225045*e+.7168786*I+.0606169*i)/vye),C,r;return e===I&&I===i?C=r=n:(C=P5((.4360747*e+.3850649*I+.1430804*i)/Bye),r=P5((.0139322*e+.0971045*I+.7141733*i)/Sye)),new AA(116*n-16,500*(C-n),200*(n-r),g.opacity)}function Jet(g,e){return new AA(g,0,0,e??1)}function Wye(g,e,I,i){return arguments.length===1?Rye(g):new AA(g,e,I,i??1)}function AA(g,e,I,i){this.l=+g,this.a=+e,this.b=+I,this.opacity=+i}P0(AA,Wye,$S(du,{brighter:function(g){return new AA(this.l+Z9*(g??1),this.a,this.b,this.opacity)},darker:function(g){return new AA(this.l-Z9*(g??1),this.a,this.b,this.opacity)},rgb:function(){var g=(this.l+16)/116,e=isNaN(this.a)?g:g+this.a/500,I=isNaN(this.b)?g:g-this.b/200;return e=Bye*J5(e),g=vye*J5(g),I=Sye*J5(I),new An(O5(3.1338561*e-1.6168667*g-.4906146*I),O5(-.9787684*e+1.9161415*g+.033454*I),O5(.0719453*e-.2289914*g+1.4052427*I),this.opacity)}}));function P5(g){return g>Pet?Math.pow(g,1/3):g/Vye+wye}function J5(g){return g>Ep?g*g*g:Vye*(g-wye)}function O5(g){return 255*(g<=.0031308?12.92*g:1.055*Math.pow(g,1/2.4)-.055)}function L5(g){return(g/=255)<=.04045?g/12.92:Math.pow((g+.055)/1.055,2.4)}function Xye(g){if(g instanceof aa)return new aa(g.h,g.c,g.l,g.opacity);if(g instanceof AA||(g=Rye(g)),g.a===0&&g.b===0)return new aa(NaN,0()=>g;function Uet(g,e){return function(I){return g+I*e}}function Qet(g,e,I){return g=Math.pow(g,I),e=Math.pow(e,I)-g,I=1/I,function(i){return Math.pow(g+i*e,I)}}function jet(g){return(g=+g)==1?Yye:function(e,I){return I-e?Qet(e,I,g):v7(isNaN(e)?I:e)}}function Yye(g,e){var I=e-g;return I?Uet(g,I):v7(isNaN(g)?e:g)}const Kb=function g(e){var I=jet(e);function i(n,C){var r=I((n=Yb(n)).r,(C=Yb(C)).r),o=I(n.g,C.g),A=I(n.b,C.b),s=Yye(n.opacity,C.opacity);return function(a){return n.r=r(a),n.g=o(a),n.b=A(a),n.opacity=s(a),n+""}}return i.gamma=g,i}(1);function $et(g,e){e||(e=[]);var I=g?Math.min(e.length,g.length):0,i=e.slice(),n;return function(C){for(n=0;nI&&(C=e.slice(I,C),o[r]?o[r]+=C:o[++r]=C),(i=i[0])===(n=n[0])?o[r]?o[r]+=n:o[++r]=n:(o[++r]=null,A.push({i:r,x:Pr(i,n)})),I=_5.lastIndex;return I180?a+=360:a-s>180&&(s+=360),c.push({i:l.push(n(l)+"rotate(",null,i)-2,x:Pr(s,a)})):a&&l.push(n(l)+"rotate("+a+i)}function o(s,a,l,c){s!==a?c.push({i:l.push(n(l)+"skewX(",null,i)-2,x:Pr(s,a)}):a&&l.push(n(l)+"skewX("+a+i)}function A(s,a,l,c,u,d){if(s!==l||a!==c){var h=u.push(n(u)+"scale(",null,",",null,")");d.push({i:h-4,x:Pr(s,l)},{i:h-2,x:Pr(a,c)})}else(l!==1||c!==1)&&u.push(n(u)+"scale("+l+","+c+")")}return function(s,a){var l=[],c=[];return s=g(s),a=g(a),C(s.translateX,s.translateY,a.translateX,a.translateY,l,c),r(s.rotate,a.rotate,l,c),o(s.skewX,a.skewX,l,c),A(s.scaleX,s.scaleY,a.scaleX,a.scaleY,l,c),s=a=null,function(u){for(var d=-1,h=c.length,m;++de&&(I=g,g=e,e=I),function(i){return Math.max(g,Math.min(e,i))}}function utt(g,e,I){var i=g[0],n=g[1],C=e[0],r=e[1];return n2?dtt:utt,A=s=null,l}function l(c){return c==null||isNaN(c=+c)?C:(A||(A=o(g.map(i),e,I)))(i(r(c)))}return l.invert=function(c){return r(n((s||(s=o(e,g.map(i),Pr)))(c)))},l.domain=function(c){return arguments.length?(g=Array.from(c,G9),a()):g.slice()},l.range=function(c){return arguments.length?(e=Array.from(c),a()):e.slice()},l.rangeRound=function(c){return e=Array.from(c),I=w7,a()},l.clamp=function(c){return arguments.length?(r=c?!0:nC,a()):r!==nC},l.interpolate=function(c){return arguments.length?(I=c,a()):I},l.unknown=function(c){return arguments.length?(C=c,l):C},function(c,u){return i=c,n=u,a()}}function V7(){return yN()(nC,nC)}function htt(g){return Math.abs(g=Math.round(g))>=1e21?g.toLocaleString("en").replace(/,/g,""):g.toString(10)}function B9(g,e){if((I=(g=e?g.toExponential(e-1):g.toExponential()).indexOf("e"))<0)return null;var I,i=g.slice(0,I);return[i.length>1?i[0]+i.slice(2):i,+g.slice(I+1)]}function xb(g){return g=B9(Math.abs(g)),g?g[1]:NaN}function mtt(g,e){return function(I,i){for(var n=I.length,C=[],r=0,o=g[0],A=0;n>0&&o>0&&(A+o+1>i&&(o=Math.max(1,i-A)),C.push(I.substring(n-=o,n+o)),!((A+=o+1)>i));)o=g[r=(r+1)%g.length];return C.reverse().join(e)}}function ftt(g){return function(e){return e.replace(/[0-9]/g,function(I){return g[+I]})}}var ptt=/^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;function Db(g){if(!(e=ptt.exec(g)))throw new Error("invalid format: "+g);var e;return new ZN({fill:e[1],align:e[2],sign:e[3],symbol:e[4],zero:e[5],width:e[6],comma:e[7],precision:e[8]&&e[8].slice(1),trim:e[9],type:e[10]})}Db.prototype=ZN.prototype;function ZN(g){this.fill=g.fill===void 0?" ":g.fill+"",this.align=g.align===void 0?">":g.align+"",this.sign=g.sign===void 0?"-":g.sign+"",this.symbol=g.symbol===void 0?"":g.symbol+"",this.zero=!!g.zero,this.width=g.width===void 0?void 0:+g.width,this.comma=!!g.comma,this.precision=g.precision===void 0?void 0:+g.precision,this.trim=!!g.trim,this.type=g.type===void 0?"":g.type+""}ZN.prototype.toString=function(){return this.fill+this.align+this.sign+this.symbol+(this.zero?"0":"")+(this.width===void 0?"":Math.max(1,this.width|0))+(this.comma?",":"")+(this.precision===void 0?"":"."+Math.max(0,this.precision|0))+(this.trim?"~":"")+this.type};function btt(g){e:for(var e=g.length,I=1,i=-1,n;I0&&(i=0);break}return i>0?g.slice(0,i)+g.slice(n+1):g}var Eye;function ytt(g,e){var I=B9(g,e);if(!I)return g+"";var i=I[0],n=I[1],C=n-(Eye=Math.max(-8,Math.min(8,Math.floor(n/3)))*3)+1,r=i.length;return C===r?i:C>r?i+new Array(C-r+1).join("0"):C>0?i.slice(0,C)+"."+i.slice(C):"0."+new Array(1-C).join("0")+B9(g,Math.max(0,e+C-1))[0]}function Vge(g,e){var I=B9(g,e);if(!I)return g+"";var i=I[0],n=I[1];return n<0?"0."+new Array(-n).join("0")+i:i.length>n+1?i.slice(0,n+1)+"."+i.slice(n+1):i+new Array(n-i.length+2).join("0")}const Rge={"%":(g,e)=>(g*100).toFixed(e),b:g=>Math.round(g).toString(2),c:g=>g+"",d:htt,e:(g,e)=>g.toExponential(e),f:(g,e)=>g.toFixed(e),g:(g,e)=>g.toPrecision(e),o:g=>Math.round(g).toString(8),p:(g,e)=>Vge(g*100,e),r:Vge,s:ytt,X:g=>Math.round(g).toString(16).toUpperCase(),x:g=>Math.round(g).toString(16)};function Wge(g){return g}var Xge=Array.prototype.map,Hge=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"];function Mye(g){var e=g.grouping===void 0||g.thousands===void 0?Wge:mtt(Xge.call(g.grouping,Number),g.thousands+""),I=g.currency===void 0?"":g.currency[0]+"",i=g.currency===void 0?"":g.currency[1]+"",n=g.decimal===void 0?".":g.decimal+"",C=g.numerals===void 0?Wge:ftt(Xge.call(g.numerals,String)),r=g.percent===void 0?"%":g.percent+"",o=g.minus===void 0?"−":g.minus+"",A=g.nan===void 0?"NaN":g.nan+"";function s(l){l=Db(l);var c=l.fill,u=l.align,d=l.sign,h=l.symbol,m=l.zero,f=l.width,b=l.comma,p=l.precision,y=l.trim,Z=l.type;Z==="n"?(b=!0,Z="g"):Rge[Z]||(p===void 0&&(p=12),y=!0,Z="g"),(m||c==="0"&&u==="=")&&(m=!0,c="0",u="=");var v=h==="$"?I:h==="#"&&/[boxX]/.test(Z)?"0"+Z.toLowerCase():"",G=h==="$"?i:/[%p]/.test(Z)?r:"",B=Rge[Z],w=/[defgprs%]/.test(Z);p=p===void 0?6:/[gprs]/.test(Z)?Math.max(1,Math.min(21,p)):Math.max(0,Math.min(20,p));function R(S){var X=v,W=G,V,H,D;if(Z==="c")W=B(S)+W,S="";else{S=+S;var Y=S<0||1/S<0;if(S=isNaN(S)?A:B(Math.abs(S),p),y&&(S=btt(S)),Y&&+S==0&&d!=="+"&&(Y=!1),X=(Y?d==="("?d:o:d==="-"||d==="("?"":d)+X,W=(Z==="s"?Hge[8+Eye/3]:"")+W+(Y&&d==="("?")":""),w){for(V=-1,H=S.length;++VD||D>57){W=(D===46?n+S.slice(V+1):S.slice(V))+W,S=S.slice(0,V);break}}}b&&!m&&(S=e(S,1/0));var F=X.length+S.length+W.length,_=F>1)+X+S+W+_.slice(F);break;default:S=_+X+S+W;break}return C(S)}return R.toString=function(){return l+""},R}function a(l,c){var u=s((l=Db(l),l.type="f",l)),d=Math.max(-8,Math.min(8,Math.floor(xb(c)/3)))*3,h=Math.pow(10,-d),m=Hge[8+d/3];return function(f){return u(h*f)+m}}return{format:s,formatPrefix:a}}var sR,hr,Am;zye({thousands:",",grouping:[3],currency:["$",""]});function zye(g){return sR=Mye(g),hr=sR.format,Am=sR.formatPrefix,sR}function Pye(g){return Math.max(0,-xb(Math.abs(g)))}function J0(g,e){return Math.max(0,Math.max(-8,Math.min(8,Math.floor(xb(e)/3)))*3-xb(Math.abs(g)))}function Jye(g,e){return g=Math.abs(g),e=Math.abs(e)-g,Math.max(0,xb(e)-xb(g))+1}const Ztt=Object.freeze(Object.defineProperty({__proto__:null,FormatSpecifier:ZN,get format(){return hr},formatDefaultLocale:zye,formatLocale:Mye,get formatPrefix(){return Am},formatSpecifier:Db,precisionFixed:Pye,precisionPrefix:J0,precisionRound:Jye},Symbol.toStringTag,{value:"Module"}));function Oye(g,e,I,i){var n=b9(g,e,I),C;switch(i=Db(i??",f"),i.type){case"s":{var r=Math.max(Math.abs(g),Math.abs(e));return i.precision==null&&!isNaN(C=J0(n,r))&&(i.precision=C),Am(i,r)}case"":case"e":case"g":case"p":case"r":{i.precision==null&&!isNaN(C=Jye(n,Math.max(Math.abs(g),Math.abs(e))))&&(i.precision=C-(i.type==="e"));break}case"f":case"%":{i.precision==null&&!isNaN(C=Pye(n))&&(i.precision=C-(i.type==="%")*2);break}}return hr(i)}function hu(g){var e=g.domain;return g.ticks=function(I){var i=e();return sh(i[0],i[i.length-1],I??10)},g.tickFormat=function(I,i){var n=e();return Oye(n[0],n[n.length-1],I??10,i)},g.nice=function(I){I==null&&(I=10);var i=e(),n=0,C=i.length-1,r=i[n],o=i[C],A,s,a=10;for(o0;){if(s=QS(r,o,I),s===A)return i[n]=r,i[C]=o,e(i);if(s>0)r=Math.floor(r/s)*s,o=Math.ceil(o/s)*s;else if(s<0)r=Math.ceil(r*s)/s,o=Math.floor(o*s)/s;else break;A=s}return g},g}function Cg(){var g=V7();return g.copy=function(){return qS(g,Cg())},lo.apply(g,arguments),hu(g)}function Lye(g){var e;function I(i){return i==null||isNaN(i=+i)?e:i}return I.invert=I,I.domain=I.range=function(i){return arguments.length?(g=Array.from(i,G9),I):g.slice()},I.unknown=function(i){return arguments.length?(e=i,I):e},I.copy=function(){return Lye(g).unknown(e)},g=arguments.length?Array.from(g,G9):[0,1],hu(I)}function _ye(g,e){g=g.slice();var I=0,i=g.length-1,n=g[I],C=g[i],r;return CMath.pow(g,e)}function wtt(g){return g===Math.E?Math.log:g===10&&Math.log10||g===2&&Math.log2||(g=Math.log(g),e=>Math.log(e)/g)}function kge(g){return(e,I)=>-g(-e,I)}function R7(g){const e=g(Tge,Nge),I=e.domain;let i=10,n,C;function r(){return n=wtt(i),C=Stt(i),I()[0]<0?(n=kge(n),C=kge(C),g(Gtt,Btt)):g(Tge,Nge),e}return e.base=function(o){return arguments.length?(i=+o,r()):i},e.domain=function(o){return arguments.length?(I(o),r()):I()},e.ticks=o=>{const A=I();let s=A[0],a=A[A.length-1];const l=a0){for(;c<=u;++c)for(d=1;da)break;f.push(h)}}else for(;c<=u;++c)for(d=i-1;d>=1;--d)if(h=c>0?d/C(-c):d*C(c),!(ha)break;f.push(h)}f.length*2{if(o==null&&(o=10),A==null&&(A=i===10?"s":","),typeof A!="function"&&(!(i%1)&&(A=Db(A)).precision==null&&(A.trim=!0),A=hr(A)),o===1/0)return A;const s=Math.max(1,i*o/e.ticks().length);return a=>{let l=a/C(Math.round(n(a)));return l*iI(_ye(I(),{floor:o=>C(Math.floor(n(o))),ceil:o=>C(Math.ceil(n(o)))})),e}function mu(){const g=R7(yN()).domain([1,10]);return g.copy=()=>qS(g,mu()).base(g.base()),lo.apply(g,arguments),g}function Yge(g){return function(e){return Math.sign(e)*Math.log1p(Math.abs(e/g))}}function Kge(g){return function(e){return Math.sign(e)*Math.expm1(Math.abs(e))*g}}function W7(g){var e=1,I=g(Yge(e),Kge(e));return I.constant=function(i){return arguments.length?g(Yge(e=+i),Kge(e)):e},hu(I)}function Uye(){var g=W7(yN());return g.copy=function(){return qS(g,Uye()).constant(g.constant())},lo.apply(g,arguments)}function xge(g){return function(e){return e<0?-Math.pow(-e,g):Math.pow(e,g)}}function Vtt(g){return g<0?-Math.sqrt(-g):Math.sqrt(g)}function Rtt(g){return g<0?-g*g:g*g}function X7(g){var e=g(nC,nC),I=1;function i(){return I===1?g(nC,nC):I===.5?g(Vtt,Rtt):g(xge(I),xge(1/I))}return e.exponent=function(n){return arguments.length?(I=+n,i()):I},hu(e)}function H7(){var g=X7(yN());return g.copy=function(){return qS(g,H7()).exponent(g.exponent())},lo.apply(g,arguments),g}function Wtt(){return H7.apply(null,arguments).exponent(.5)}function Dge(g){return Math.sign(g)*g*g}function Xtt(g){return Math.sign(g)*Math.sqrt(Math.abs(g))}function Qye(){var g=V7(),e=[0,1],I=!1,i;function n(C){var r=Xtt(g(C));return isNaN(r)?i:I?Math.round(r):r}return n.invert=function(C){return g.invert(Dge(C))},n.domain=function(C){return arguments.length?(g.domain(C),n):g.domain()},n.range=function(C){return arguments.length?(g.range((e=Array.from(C,G9)).map(Dge)),n):e.slice()},n.rangeRound=function(C){return n.range(C).round(!0)},n.round=function(C){return arguments.length?(I=!!C,n):I},n.clamp=function(C){return arguments.length?(g.clamp(C),n):g.clamp()},n.unknown=function(C){return arguments.length?(i=C,n):i},n.copy=function(){return Qye(g.domain(),e).round(I).clamp(g.clamp()).unknown(i)},lo.apply(n,arguments),hu(n)}function v9(){var g=[],e=[],I=[],i;function n(){var r=0,o=Math.max(1,e.length);for(I=new Array(o-1);++r0?I[o-1]:g[0],o=I?[i[I-1],e]:[i[s-1],i[s]]},r.unknown=function(A){return arguments.length&&(C=A),r},r.thresholds=function(){return i.slice()},r.copy=function(){return jye().domain([g,e]).range(n).unknown(C)},lo.apply(hu(r),arguments)}function $ye(){var g=[.5],e=[0,1],I,i=1;function n(C){return C!=null&&C<=C?e[rm(g,C,0,i)]:I}return n.domain=function(C){return arguments.length?(g=Array.from(C),i=Math.min(g.length,e.length-1),n):g.slice()},n.range=function(C){return arguments.length?(e=Array.from(C),i=Math.min(g.length,e.length-1),n):e.slice()},n.invertExtent=function(C){var r=e.indexOf(C);return[g[r-1],g[r]]},n.unknown=function(C){return arguments.length?(I=C,n):I},n.copy=function(){return $ye().domain(g).range(e).unknown(I)},lo.apply(n,arguments)}const U5=new Date,Q5=new Date;function Ti(g,e,I,i){function n(C){return g(C=arguments.length===0?new Date:new Date(+C)),C}return n.floor=C=>(g(C=new Date(+C)),C),n.ceil=C=>(g(C=new Date(C-1)),e(C,1),g(C),C),n.round=C=>{const r=n(C),o=n.ceil(C);return C-r(e(C=new Date(+C),r==null?1:Math.floor(r)),C),n.range=(C,r,o)=>{const A=[];if(C=n.ceil(C),o=o==null?1:Math.floor(o),!(C0))return A;let s;do A.push(s=new Date(+C)),e(C,o),g(C);while(sTi(r=>{if(r>=r)for(;g(r),!C(r);)r.setTime(r-1)},(r,o)=>{if(r>=r)if(o<0)for(;++o<=0;)for(;e(r,-1),!C(r););else for(;--o>=0;)for(;e(r,1),!C(r););}),I&&(n.count=(C,r)=>(U5.setTime(+C),Q5.setTime(+r),g(U5),g(Q5),Math.floor(I(U5,Q5))),n.every=C=>(C=Math.floor(C),!isFinite(C)||!(C>0)?null:C>1?n.filter(i?r=>i(r)%C===0:r=>n.count(0,r)%C===0):n)),n}const S9=Ti(()=>{},(g,e)=>{g.setTime(+g+e)},(g,e)=>e-g);S9.every=g=>(g=Math.floor(g),!isFinite(g)||!(g>0)?null:g>1?Ti(e=>{e.setTime(Math.floor(e/g)*g)},(e,I)=>{e.setTime(+e+I*g)},(e,I)=>(I-e)/g):S9);S9.range;const bs=1e3,jr=bs*60,ys=jr*60,_s=ys*24,T7=_s*7,Fge=_s*30,j5=_s*365,md=Ti(g=>{g.setTime(g-g.getMilliseconds())},(g,e)=>{g.setTime(+g+e*bs)},(g,e)=>(e-g)/bs,g=>g.getUTCSeconds());md.range;const N7=Ti(g=>{g.setTime(g-g.getMilliseconds()-g.getSeconds()*bs)},(g,e)=>{g.setTime(+g+e*jr)},(g,e)=>(e-g)/jr,g=>g.getMinutes());N7.range;const k7=Ti(g=>{g.setUTCSeconds(0,0)},(g,e)=>{g.setTime(+g+e*jr)},(g,e)=>(e-g)/jr,g=>g.getUTCMinutes());k7.range;const Y7=Ti(g=>{g.setTime(g-g.getMilliseconds()-g.getSeconds()*bs-g.getMinutes()*jr)},(g,e)=>{g.setTime(+g+e*ys)},(g,e)=>(e-g)/ys,g=>g.getHours());Y7.range;const K7=Ti(g=>{g.setUTCMinutes(0,0,0)},(g,e)=>{g.setTime(+g+e*ys)},(g,e)=>(e-g)/ys,g=>g.getUTCHours());K7.range;const ew=Ti(g=>g.setHours(0,0,0,0),(g,e)=>g.setDate(g.getDate()+e),(g,e)=>(e-g-(e.getTimezoneOffset()-g.getTimezoneOffset())*jr)/_s,g=>g.getDate()-1);ew.range;const GN=Ti(g=>{g.setUTCHours(0,0,0,0)},(g,e)=>{g.setUTCDate(g.getUTCDate()+e)},(g,e)=>(e-g)/_s,g=>g.getUTCDate()-1);GN.range;const qye=Ti(g=>{g.setUTCHours(0,0,0,0)},(g,e)=>{g.setUTCDate(g.getUTCDate()+e)},(g,e)=>(e-g)/_s,g=>Math.floor(g/_s));qye.range;function am(g){return Ti(e=>{e.setDate(e.getDate()-(e.getDay()+7-g)%7),e.setHours(0,0,0,0)},(e,I)=>{e.setDate(e.getDate()+I*7)},(e,I)=>(I-e-(I.getTimezoneOffset()-e.getTimezoneOffset())*jr)/T7)}const BN=am(0),w9=am(1),Htt=am(2),Ttt=am(3),Fb=am(4),Ntt=am(5),ktt=am(6);BN.range;w9.range;Htt.range;Ttt.range;Fb.range;Ntt.range;ktt.range;function sm(g){return Ti(e=>{e.setUTCDate(e.getUTCDate()-(e.getUTCDay()+7-g)%7),e.setUTCHours(0,0,0,0)},(e,I)=>{e.setUTCDate(e.getUTCDate()+I*7)},(e,I)=>(I-e)/T7)}const vN=sm(0),V9=sm(1),Ytt=sm(2),Ktt=sm(3),Eb=sm(4),xtt=sm(5),Dtt=sm(6);vN.range;V9.range;Ytt.range;Ktt.range;Eb.range;xtt.range;Dtt.range;const x7=Ti(g=>{g.setDate(1),g.setHours(0,0,0,0)},(g,e)=>{g.setMonth(g.getMonth()+e)},(g,e)=>e.getMonth()-g.getMonth()+(e.getFullYear()-g.getFullYear())*12,g=>g.getMonth());x7.range;const D7=Ti(g=>{g.setUTCDate(1),g.setUTCHours(0,0,0,0)},(g,e)=>{g.setUTCMonth(g.getUTCMonth()+e)},(g,e)=>e.getUTCMonth()-g.getUTCMonth()+(e.getUTCFullYear()-g.getUTCFullYear())*12,g=>g.getUTCMonth());D7.range;const Us=Ti(g=>{g.setMonth(0,1),g.setHours(0,0,0,0)},(g,e)=>{g.setFullYear(g.getFullYear()+e)},(g,e)=>e.getFullYear()-g.getFullYear(),g=>g.getFullYear());Us.every=g=>!isFinite(g=Math.floor(g))||!(g>0)?null:Ti(e=>{e.setFullYear(Math.floor(e.getFullYear()/g)*g),e.setMonth(0,1),e.setHours(0,0,0,0)},(e,I)=>{e.setFullYear(e.getFullYear()+I*g)});Us.range;const Qs=Ti(g=>{g.setUTCMonth(0,1),g.setUTCHours(0,0,0,0)},(g,e)=>{g.setUTCFullYear(g.getUTCFullYear()+e)},(g,e)=>e.getUTCFullYear()-g.getUTCFullYear(),g=>g.getUTCFullYear());Qs.every=g=>!isFinite(g=Math.floor(g))||!(g>0)?null:Ti(e=>{e.setUTCFullYear(Math.floor(e.getUTCFullYear()/g)*g),e.setUTCMonth(0,1),e.setUTCHours(0,0,0,0)},(e,I)=>{e.setUTCFullYear(e.getUTCFullYear()+I*g)});Qs.range;function eZe(g,e,I,i,n,C){const r=[[md,1,bs],[md,5,5*bs],[md,15,15*bs],[md,30,30*bs],[C,1,jr],[C,5,5*jr],[C,15,15*jr],[C,30,30*jr],[n,1,ys],[n,3,3*ys],[n,6,6*ys],[n,12,12*ys],[i,1,_s],[i,2,2*_s],[I,1,T7],[e,1,Fge],[e,3,3*Fge],[g,1,j5]];function o(s,a,l){const c=am).right(r,c);if(u===r.length)return g.every(b9(s/j5,a/j5,l));if(u===0)return S9.every(Math.max(b9(s,a,l),1));const[d,h]=r[c/r[u-1][2]53)return null;"w"in ve||(ve.w=1),"Z"in ve?(Xe=q5(jy(ve.y,0,1)),Oe=Xe.getUTCDay(),Xe=Oe>4||Oe===0?V9.ceil(Xe):V9(Xe),Xe=GN.offset(Xe,(ve.V-1)*7),ve.y=Xe.getUTCFullYear(),ve.m=Xe.getUTCMonth(),ve.d=Xe.getUTCDate()+(ve.w+6)%7):(Xe=$5(jy(ve.y,0,1)),Oe=Xe.getDay(),Xe=Oe>4||Oe===0?w9.ceil(Xe):w9(Xe),Xe=ew.offset(Xe,(ve.V-1)*7),ve.y=Xe.getFullYear(),ve.m=Xe.getMonth(),ve.d=Xe.getDate()+(ve.w+6)%7)}else("W"in ve||"U"in ve)&&("w"in ve||(ve.w="u"in ve?ve.u%7:"W"in ve?1:0),Oe="Z"in ve?q5(jy(ve.y,0,1)).getUTCDay():$5(jy(ve.y,0,1)).getDay(),ve.m=0,ve.d="W"in ve?(ve.w+6)%7+ve.W*7-(Oe+5)%7:ve.w+ve.U*7-(Oe+6)%7);return"Z"in ve?(ve.H+=ve.Z/100|0,ve.M+=ve.Z%100,q5(ve)):$5(ve)}}function B(Ce,Ze,Ge,ve){for(var ke=0,Xe=Ze.length,Oe=Ge.length,ze,Me;ke=Oe)return-1;if(ze=Ze.charCodeAt(ke++),ze===37){if(ze=Ze.charAt(ke++),Me=Z[ze in Ege?Ze.charAt(ke++):ze],!Me||(ve=Me(Ce,Ge,ve))<0)return-1}else if(ze!=Ge.charCodeAt(ve++))return-1}return ve}function w(Ce,Ze,Ge){var ve=s.exec(Ze.slice(Ge));return ve?(Ce.p=a.get(ve[0].toLowerCase()),Ge+ve[0].length):-1}function R(Ce,Ze,Ge){var ve=u.exec(Ze.slice(Ge));return ve?(Ce.w=d.get(ve[0].toLowerCase()),Ge+ve[0].length):-1}function S(Ce,Ze,Ge){var ve=l.exec(Ze.slice(Ge));return ve?(Ce.w=c.get(ve[0].toLowerCase()),Ge+ve[0].length):-1}function X(Ce,Ze,Ge){var ve=f.exec(Ze.slice(Ge));return ve?(Ce.m=b.get(ve[0].toLowerCase()),Ge+ve[0].length):-1}function W(Ce,Ze,Ge){var ve=h.exec(Ze.slice(Ge));return ve?(Ce.m=m.get(ve[0].toLowerCase()),Ge+ve[0].length):-1}function V(Ce,Ze,Ge){return B(Ce,e,Ze,Ge)}function H(Ce,Ze,Ge){return B(Ce,I,Ze,Ge)}function D(Ce,Ze,Ge){return B(Ce,i,Ze,Ge)}function Y(Ce){return r[Ce.getDay()]}function F(Ce){return C[Ce.getDay()]}function _(Ce){return A[Ce.getMonth()]}function J(Ce){return o[Ce.getMonth()]}function te(Ce){return n[+(Ce.getHours()>=12)]}function q(Ce){return 1+~~(Ce.getMonth()/3)}function $(Ce){return r[Ce.getUTCDay()]}function j(Ce){return C[Ce.getUTCDay()]}function ee(Ce){return A[Ce.getUTCMonth()]}function Q(Ce){return o[Ce.getUTCMonth()]}function ne(Ce){return n[+(Ce.getUTCHours()>=12)]}function fe(Ce){return 1+~~(Ce.getUTCMonth()/3)}return{format:function(Ce){var Ze=v(Ce+="",p);return Ze.toString=function(){return Ce},Ze},parse:function(Ce){var Ze=G(Ce+="",!1);return Ze.toString=function(){return Ce},Ze},utcFormat:function(Ce){var Ze=v(Ce+="",y);return Ze.toString=function(){return Ce},Ze},utcParse:function(Ce){var Ze=G(Ce+="",!0);return Ze.toString=function(){return Ce},Ze}}}var Ege={"-":"",_:" ",0:"0"},_i=/^\s*\d+/,Jtt=/^%/,Ott=/[\\^$*+?|[\]().{}]/g;function Dg(g,e,I){var i=g<0?"-":"",n=(i?-g:g)+"",C=n.length;return i+(C[e.toLowerCase(),I]))}function _tt(g,e,I){var i=_i.exec(e.slice(I,I+1));return i?(g.w=+i[0],I+i[0].length):-1}function Utt(g,e,I){var i=_i.exec(e.slice(I,I+1));return i?(g.u=+i[0],I+i[0].length):-1}function Qtt(g,e,I){var i=_i.exec(e.slice(I,I+2));return i?(g.U=+i[0],I+i[0].length):-1}function jtt(g,e,I){var i=_i.exec(e.slice(I,I+2));return i?(g.V=+i[0],I+i[0].length):-1}function $tt(g,e,I){var i=_i.exec(e.slice(I,I+2));return i?(g.W=+i[0],I+i[0].length):-1}function Mge(g,e,I){var i=_i.exec(e.slice(I,I+4));return i?(g.y=+i[0],I+i[0].length):-1}function zge(g,e,I){var i=_i.exec(e.slice(I,I+2));return i?(g.y=+i[0]+(+i[0]>68?1900:2e3),I+i[0].length):-1}function qtt(g,e,I){var i=/^(Z)|([+-]\d\d)(?::?(\d\d))?/.exec(e.slice(I,I+6));return i?(g.Z=i[1]?0:-(i[2]+(i[3]||"00")),I+i[0].length):-1}function egt(g,e,I){var i=_i.exec(e.slice(I,I+1));return i?(g.q=i[0]*3-3,I+i[0].length):-1}function tgt(g,e,I){var i=_i.exec(e.slice(I,I+2));return i?(g.m=i[0]-1,I+i[0].length):-1}function Pge(g,e,I){var i=_i.exec(e.slice(I,I+2));return i?(g.d=+i[0],I+i[0].length):-1}function ggt(g,e,I){var i=_i.exec(e.slice(I,I+3));return i?(g.m=0,g.d=+i[0],I+i[0].length):-1}function Jge(g,e,I){var i=_i.exec(e.slice(I,I+2));return i?(g.H=+i[0],I+i[0].length):-1}function Igt(g,e,I){var i=_i.exec(e.slice(I,I+2));return i?(g.M=+i[0],I+i[0].length):-1}function igt(g,e,I){var i=_i.exec(e.slice(I,I+2));return i?(g.S=+i[0],I+i[0].length):-1}function ngt(g,e,I){var i=_i.exec(e.slice(I,I+3));return i?(g.L=+i[0],I+i[0].length):-1}function Cgt(g,e,I){var i=_i.exec(e.slice(I,I+6));return i?(g.L=Math.floor(i[0]/1e3),I+i[0].length):-1}function rgt(g,e,I){var i=Jtt.exec(e.slice(I,I+1));return i?I+i[0].length:-1}function ogt(g,e,I){var i=_i.exec(e.slice(I));return i?(g.Q=+i[0],I+i[0].length):-1}function Agt(g,e,I){var i=_i.exec(e.slice(I));return i?(g.s=+i[0],I+i[0].length):-1}function Oge(g,e){return Dg(g.getDate(),e,2)}function agt(g,e){return Dg(g.getHours(),e,2)}function sgt(g,e){return Dg(g.getHours()%12||12,e,2)}function lgt(g,e){return Dg(1+ew.count(Us(g),g),e,3)}function tZe(g,e){return Dg(g.getMilliseconds(),e,3)}function cgt(g,e){return tZe(g,e)+"000"}function ugt(g,e){return Dg(g.getMonth()+1,e,2)}function dgt(g,e){return Dg(g.getMinutes(),e,2)}function hgt(g,e){return Dg(g.getSeconds(),e,2)}function mgt(g){var e=g.getDay();return e===0?7:e}function fgt(g,e){return Dg(BN.count(Us(g)-1,g),e,2)}function gZe(g){var e=g.getDay();return e>=4||e===0?Fb(g):Fb.ceil(g)}function pgt(g,e){return g=gZe(g),Dg(Fb.count(Us(g),g)+(Us(g).getDay()===4),e,2)}function bgt(g){return g.getDay()}function ygt(g,e){return Dg(w9.count(Us(g)-1,g),e,2)}function Zgt(g,e){return Dg(g.getFullYear()%100,e,2)}function Ggt(g,e){return g=gZe(g),Dg(g.getFullYear()%100,e,2)}function Bgt(g,e){return Dg(g.getFullYear()%1e4,e,4)}function vgt(g,e){var I=g.getDay();return g=I>=4||I===0?Fb(g):Fb.ceil(g),Dg(g.getFullYear()%1e4,e,4)}function Sgt(g){var e=g.getTimezoneOffset();return(e>0?"-":(e*=-1,"+"))+Dg(e/60|0,"0",2)+Dg(e%60,"0",2)}function Lge(g,e){return Dg(g.getUTCDate(),e,2)}function wgt(g,e){return Dg(g.getUTCHours(),e,2)}function Vgt(g,e){return Dg(g.getUTCHours()%12||12,e,2)}function Rgt(g,e){return Dg(1+GN.count(Qs(g),g),e,3)}function IZe(g,e){return Dg(g.getUTCMilliseconds(),e,3)}function Wgt(g,e){return IZe(g,e)+"000"}function Xgt(g,e){return Dg(g.getUTCMonth()+1,e,2)}function Hgt(g,e){return Dg(g.getUTCMinutes(),e,2)}function Tgt(g,e){return Dg(g.getUTCSeconds(),e,2)}function Ngt(g){var e=g.getUTCDay();return e===0?7:e}function kgt(g,e){return Dg(vN.count(Qs(g)-1,g),e,2)}function iZe(g){var e=g.getUTCDay();return e>=4||e===0?Eb(g):Eb.ceil(g)}function Ygt(g,e){return g=iZe(g),Dg(Eb.count(Qs(g),g)+(Qs(g).getUTCDay()===4),e,2)}function Kgt(g){return g.getUTCDay()}function xgt(g,e){return Dg(V9.count(Qs(g)-1,g),e,2)}function Dgt(g,e){return Dg(g.getUTCFullYear()%100,e,2)}function Fgt(g,e){return g=iZe(g),Dg(g.getUTCFullYear()%100,e,2)}function Egt(g,e){return Dg(g.getUTCFullYear()%1e4,e,4)}function Mgt(g,e){var I=g.getUTCDay();return g=I>=4||I===0?Eb(g):Eb.ceil(g),Dg(g.getUTCFullYear()%1e4,e,4)}function zgt(){return"+0000"}function _ge(){return"%"}function Uge(g){return+g}function Qge(g){return Math.floor(+g/1e3)}var Om,nZe,CZe;Pgt({dateTime:"%x, %X",date:"%-m/%-d/%Y",time:"%-I:%M:%S %p",periods:["AM","PM"],days:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],shortDays:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],months:["January","February","March","April","May","June","July","August","September","October","November","December"],shortMonths:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]});function Pgt(g){return Om=Ptt(g),nZe=Om.format,Om.parse,CZe=Om.utcFormat,Om.utcParse,Om}function Jgt(g){return new Date(g)}function Ogt(g){return g instanceof Date?+g:+new Date(+g)}function F7(g,e,I,i,n,C,r,o,A,s){var a=V7(),l=a.invert,c=a.domain,u=s(".%L"),d=s(":%S"),h=s("%I:%M"),m=s("%I %p"),f=s("%a %d"),b=s("%b %d"),p=s("%B"),y=s("%Y");function Z(v){return(A(v)e(n/(g.length-1)))},I.quantiles=function(i){return Array.from({length:i+1},(n,C)=>Nv(g,C/i))},I.copy=function(){return aZe(e).domain(g)},sl.apply(I,arguments)}function wN(){var g=0,e=.5,I=1,i=1,n,C,r,o,A,s=nC,a,l=!1,c;function u(h){return isNaN(h=+h)?c:(h=.5+((h=+a(h))-C)*(i*h1&&arguments[1]!==void 0?arguments[1]:0,I=(qi[g[e+0]]+qi[g[e+1]]+qi[g[e+2]]+qi[g[e+3]]+"-"+qi[g[e+4]]+qi[g[e+5]]+"-"+qi[g[e+6]]+qi[g[e+7]]+"-"+qi[g[e+8]]+qi[g[e+9]]+"-"+qi[g[e+10]]+qi[g[e+11]]+qi[g[e+12]]+qi[g[e+13]]+qi[g[e+14]]+qi[g[e+15]]).toLowerCase();if(!VN(I))throw TypeError("Stringified UUID is invalid");return I}var jge,tx,gx=0,Ix=0;function eIt(g,e,I){var i=e&&I||0,n=e||new Array(16);g=g||{};var C=g.node||jge,r=g.clockseq!==void 0?g.clockseq:tx;if(C==null||r==null){var o=g.random||(g.rng||uZe)();C==null&&(C=jge=[o[0]|1,o[1],o[2],o[3],o[4],o[5]]),r==null&&(r=tx=(o[6]<<8|o[7])&16383)}var A=g.msecs!==void 0?g.msecs:Date.now(),s=g.nsecs!==void 0?g.nsecs:Ix+1,a=A-gx+(s-Ix)/1e4;if(a<0&&g.clockseq===void 0&&(r=r+1&16383),(a<0||A>gx)&&g.nsecs===void 0&&(s=0),s>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");gx=A,Ix=s,tx=r,A+=122192928e5;var l=((A&268435455)*1e4+s)%4294967296;n[i++]=l>>>24&255,n[i++]=l>>>16&255,n[i++]=l>>>8&255,n[i++]=l&255;var c=A/4294967296*1e4&268435455;n[i++]=c>>>8&255,n[i++]=c&255,n[i++]=c>>>24&15|16,n[i++]=c>>>16&255,n[i++]=r>>>8|128,n[i++]=r&255;for(var u=0;u<6;++u)n[i+u]=C[u];return e||RN(n)}function dZe(g){if(!VN(g))throw TypeError("Invalid UUID");var e,I=new Uint8Array(16);return I[0]=(e=parseInt(g.slice(0,8),16))>>>24,I[1]=e>>>16&255,I[2]=e>>>8&255,I[3]=e&255,I[4]=(e=parseInt(g.slice(9,13),16))>>>8,I[5]=e&255,I[6]=(e=parseInt(g.slice(14,18),16))>>>8,I[7]=e&255,I[8]=(e=parseInt(g.slice(19,23),16))>>>8,I[9]=e&255,I[10]=(e=parseInt(g.slice(24,36),16))/1099511627776&255,I[11]=e/4294967296&255,I[12]=e>>>24&255,I[13]=e>>>16&255,I[14]=e>>>8&255,I[15]=e&255,I}function tIt(g){g=unescape(encodeURIComponent(g));for(var e=[],I=0;I>5]>>>n%32&255,r=parseInt(i.charAt(C>>>4&15)+i.charAt(C&15),16);e.push(r)}return e}function mZe(g){return(g+64>>>9<<4)+14+1}function CIt(g,e){g[e>>5]|=128<>5]|=(g[i/8]&255)<>16)+(e>>16)+(I>>16);return i<<16|I&65535}function oIt(g,e){return g<>>32-e}function WN(g,e,I,i,n,C){return wc(oIt(wc(wc(e,g),wc(i,C)),n),I)}function bn(g,e,I,i,n,C,r){return WN(e&I|~e&i,g,e,n,C,r)}function yn(g,e,I,i,n,C,r){return WN(e&i|I&~i,g,e,n,C,r)}function Zn(g,e,I,i,n,C,r){return WN(e^I^i,g,e,n,C,r)}function Gn(g,e,I,i,n,C,r){return WN(I^(e|~i),g,e,n,C,r)}var AIt=hZe("v3",48,iIt);const aIt=AIt;function sIt(g,e,I){g=g||{};var i=g.random||(g.rng||uZe)();if(i[6]=i[6]&15|64,i[8]=i[8]&63|128,e){I=I||0;for(var n=0;n<16;++n)e[I+n]=i[n];return e}return RN(i)}function lIt(g,e,I,i){switch(g){case 0:return e&I^~e&i;case 1:return e^I^i;case 2:return e&I^e&i^I&i;case 3:return e^I^i}}function ix(g,e){return g<>>32-e}function cIt(g){var e=[1518500249,1859775393,2400959708,3395469782],I=[1732584193,4023233417,2562383102,271733878,3285377520];if(typeof g=="string"){var i=unescape(encodeURIComponent(g));g=[];for(var n=0;n>>0;p=b,b=f,f=ix(m,30)>>>0,m=h,h=v}I[0]=I[0]+h>>>0,I[1]=I[1]+m>>>0,I[2]=I[2]+f>>>0,I[3]=I[3]+b>>>0,I[4]=I[4]+p>>>0}return[I[0]>>24&255,I[0]>>16&255,I[0]>>8&255,I[0]&255,I[1]>>24&255,I[1]>>16&255,I[1]>>8&255,I[1]&255,I[2]>>24&255,I[2]>>16&255,I[2]>>8&255,I[2]&255,I[3]>>24&255,I[3]>>16&255,I[3]>>8&255,I[3]&255,I[4]>>24&255,I[4]>>16&255,I[4]>>8&255,I[4]&255]}var uIt=hZe("v5",80,cIt);const dIt=uIt,hIt="00000000-0000-0000-0000-000000000000";function mIt(g){if(!VN(g))throw TypeError("Invalid UUID");return parseInt(g.substr(14,1),16)}const fIt=Object.freeze(Object.defineProperty({__proto__:null,NIL:hIt,parse:dZe,stringify:RN,v1:eIt,v3:aIt,v4:sIt,v5:dIt,validate:VN,version:mIt},Symbol.toStringTag,{value:"Module"})),pIt=Al(fIt);var XN=pIt,z7=(()=>typeof Buffer<"u"?g=>Buffer.from(g).toString("base64"):g=>btoa(String.fromCharCode(...g)))(),bIt=(()=>typeof Buffer<"u"?g=>Buffer.from(g,"base64"):g=>Uint8Array.from(atob(g),e=>e.charCodeAt(0)))();tw.encode=function(g){var e=XN.parse(g),I=z7(e),i=I.replace(/\+/g,"-").replace(/\//g,"_").substring(0,22);return i};tw.decode=function(g){var e=g.replace(/-/g,"+").replace(/_/g,"/")+"==";return XN.stringify(bIt(e))};tw.v4=function(){var g=XN.v4(null,new Uint8Array(16)),e=z7(g),I=e.replace(/\+/g,"-").replace(/\//g,"_").substring(0,22);return I};tw.nice=function(){var g=XN.v4(null,new Uint8Array(16));g[0]=g[0]&127;var e=z7(g),I=e.replace(/\+/g,"-").replace(/\//g,"_").substring(0,22);return I};var yIt=tw;const dg=FC(yIt);var fZe={exports:{}},HN={},R9={exports:{}};R9.exports;(function(g,e){var I=200,i="__lodash_hash_undefined__",n=1,C=2,r=9007199254740991,o="[object Arguments]",A="[object Array]",s="[object AsyncFunction]",a="[object Boolean]",l="[object Date]",c="[object Error]",u="[object Function]",d="[object GeneratorFunction]",h="[object Map]",m="[object Number]",f="[object Null]",b="[object Object]",p="[object Promise]",y="[object Proxy]",Z="[object RegExp]",v="[object Set]",G="[object String]",B="[object Symbol]",w="[object Undefined]",R="[object WeakMap]",S="[object ArrayBuffer]",X="[object DataView]",W="[object Float32Array]",V="[object Float64Array]",H="[object Int8Array]",D="[object Int16Array]",Y="[object Int32Array]",F="[object Uint8Array]",_="[object Uint8ClampedArray]",J="[object Uint16Array]",te="[object Uint32Array]",q=/[\\^$.*+?()[\]{}|]/g,$=/^\[object .+?Constructor\]$/,j=/^(?:0|[1-9]\d*)$/,ee={};ee[W]=ee[V]=ee[H]=ee[D]=ee[Y]=ee[F]=ee[_]=ee[J]=ee[te]=!0,ee[o]=ee[A]=ee[S]=ee[a]=ee[X]=ee[l]=ee[c]=ee[u]=ee[h]=ee[m]=ee[b]=ee[Z]=ee[v]=ee[G]=ee[R]=!1;var Q=typeof globalThis=="object"&&globalThis&&globalThis.Object===Object&&globalThis,ne=typeof self=="object"&&self&&self.Object===Object&&self,fe=Q||ne||Function("return this")(),Ce=e&&!e.nodeType&&e,Ze=Ce&&!0&&g&&!g.nodeType&&g,Ge=Ze&&Ze.exports===Ce,ve=Ge&&Q.process,ke=function(){try{return ve&&ve.binding&&ve.binding("util")}catch{}}(),Xe=ke&&ke.isTypedArray;function Oe(Be,Ee){for(var it=-1,Rt=Be==null?0:Be.length,cI=0,ag=[];++it-1}function ot(Be,Ee){var it=this.__data__,Rt=zI(it,Be);return Rt<0?(++this.size,it.push([Be,Ee])):it[Rt][1]=Ee,this}bt.prototype.clear=Ft,bt.prototype.delete=dt,bt.prototype.get=Xt,bt.prototype.has=Ot,bt.prototype.set=ot;function Nt(Be){var Ee=-1,it=Be==null?0:Be.length;for(this.clear();++Eeki))return!1;var NI=ag.get(Be);if(NI&&ag.get(Ee))return NI==Ee;var JC=-1,fo=!0,hn=it&C?new yt:void 0;for(ag.set(Be,Ee),ag.set(Ee,Be);++JC-1&&Be%1==0&&Be-1&&Be%1==0&&Be<=r}function M8(Be){var Ee=typeof Be;return Be!=null&&(Ee=="object"||Ee=="function")}function Sy(Be){return Be!=null&&typeof Be=="object"}var z8=Xe?_e(Xe):yke;function kke(Be){return Tke(Be)?bg(Be):Zke(Be)}function Yke(){return[]}function Kke(){return!1}g.exports=Nke})(R9,R9.exports);var TN=R9.exports,pZe={exports:{}};/*! +`)}function s(l){return l.map(a).join(e)}function a(l){return l==null?"":l instanceof Date?Zqe(l):g.test(l+="")?'"'+l.replace(/"/g,'""')+'"':l}return{parse:i,parseRows:n,format:r,formatBody:o,formatRows:A,formatRow:s,formatValue:a}}var SX={exports:{}};SX.exports;(function(e,g){(function(I,i){var n={};I.PubSub?(n=I.PubSub,console.warn("PubSub already loaded, using existing version")):(I.PubSub=n,i(n)),e!==void 0&&e.exports&&(g=e.exports=n),g.PubSub=n,e.exports=g=n})(typeof window=="object"&&window||bI,function(I){var i={},n=-1,C="*";function r(h){var m;for(m in h)if(Object.prototype.hasOwnProperty.call(h,m))return!0;return!1}function o(h){return function(){throw h}}function A(h,m,f){try{h(m,f)}catch(b){setTimeout(o(b),0)}}function s(h,m,f){h(m,f)}function a(h,m,f,b){var p=i[m],y=b?s:A,Z;if(Object.prototype.hasOwnProperty.call(i,m))for(Z in p)Object.prototype.hasOwnProperty.call(p,Z)&&y(p[Z],h,f)}function l(h,m,f){return function(){var p=String(h),y=p.lastIndexOf(".");for(a(h,h,m,f);y!==-1;)p=p.substr(0,y),y=p.lastIndexOf("."),a(h,p,m,f);a(h,C,m,f)}}function c(h){var m=String(h),f=!!(Object.prototype.hasOwnProperty.call(i,m)&&r(i[m]));return f}function u(h){for(var m=String(h),f=c(m)||c(C),b=m.lastIndexOf(".");!f&&b!==-1;)m=m.substr(0,b),b=m.lastIndexOf("."),f=c(m);return f}function d(h,m,f,b){h=typeof h=="symbol"?h.toString():h;var p=l(h,m,b),y=u(h);return y?(f===!0?p():setTimeout(p,0),!0):!1}I.publish=function(h,m){return d(h,m,!1,I.immediateExceptions)},I.publishSync=function(h,m){return d(h,m,!0,I.immediateExceptions)},I.subscribe=function(h,m){if(typeof m!="function")return!1;h=typeof h=="symbol"?h.toString():h,Object.prototype.hasOwnProperty.call(i,h)||(i[h]={});var f="uid_"+String(++n);return i[h][f]=m,f},I.subscribeAll=function(h){return I.subscribe(C,h)},I.subscribeOnce=function(h,m){var f=I.subscribe(h,function(){I.unsubscribe(f),m.apply(this,arguments)});return I},I.clearAllSubscriptions=function(){i={}},I.clearSubscriptions=function(m){var f;for(f in i)Object.prototype.hasOwnProperty.call(i,f)&&f.indexOf(m)===0&&delete i[f]},I.countSubscriptions=function(m){var f,b,p=0;for(f in i)if(Object.prototype.hasOwnProperty.call(i,f)&&f.indexOf(m)===0){for(b in i[f])p++;break}return p},I.getSubscriptions=function(m){var f,b=[];for(f in i)Object.prototype.hasOwnProperty.call(i,f)&&f.indexOf(m)===0&&b.push(f);return b},I.unsubscribe=function(h){var m=function(v){var w;for(w in i)if(Object.prototype.hasOwnProperty.call(i,w)&&w.indexOf(v)===0)return!0;return!1},f=typeof h=="string"&&(Object.prototype.hasOwnProperty.call(i,h)||m(h)),b=!f&&typeof h=="string",p=typeof h=="function",y=!1,Z,B,G;if(f){I.clearSubscriptions(h);return}for(Z in i)if(Object.prototype.hasOwnProperty.call(i,Z)){if(B=i[Z],b&&B[h]){delete B[h],y=h;break}if(p)for(G in B)Object.prototype.hasOwnProperty.call(B,G)&&B[G]===h&&(delete B[G],y=!0)}return y}})})(SX,SX.exports);var vqe=SX.exports;const XU=Fc(vqe);(function(){try{if(typeof document<"u"){var e=document.createElement("style");e.appendChild(document.createTextNode('._context-menu_18ock_1{position:fixed;background-color:#fffffff2;border:1px solid rgba(0,0,0,.1);border-radius:3px;font-size:12px;cursor:default;padding:3px;box-shadow:0 0 3px #0000001a,0 1px 5px #0000000d}._context-menu-dark_18ock_12{color:#ccc;background-color:#444444f7}._context-menu-icon_18ock_17{display:inline-block;margin-right:3px;vertical-align:middle}._context-menu-icon_18ock_17>svg{width:30px;height:20px}._context-menu-item_18ock_27{padding:2px;white-space:nowrap;border-radius:2px;transition:background .15s cubic-bezier(.25,.1,.25,1),color .15s cubic-bezier(.25,.1,.25,1)}._context-menu-item_18ock_27:hover{background:#337ab7;color:#fff}._context-menu-hr_18ock_38{margin-top:5px;margin-bottom:5px;border:0;border-top:1px solid rgba(0,0,0,.1)}._play-icon_18ock_45{width:12px;height:12px;position:absolute;right:5px}._context-menu-span_18ock_52{margin-right:20px;vertical-align:middle;display:inline-block;line-height:normal;white-space:nowrap}._context-menu-thumbnail_18ock_60{margin-right:10px;border:1px solid #888888}._context-menu-thumbnail-inline_18ock_65{display:inline-block;margin-right:10px;vertical-align:middle}._multitrack-header_1yz7l_1,._multitrack-header-focus_1yz7l_2,._multitrack-header-squeazed_1yz7l_3{position:relative;display:flex;justify-content:space-between;height:24px;margin-top:4px;margin-bottom:4px;color:#999;font-size:12px;line-height:24px;vertical-align:middle;border:0;border-radius:3px;background:#e5e5e5;transition:height .15s cubic-bezier(.25,.1,.25,1),margin .15s cubic-bezier(.25,.1,.25,1)}._multitrack-header-dark_1yz7l_20{background:#222}._multitrack-header-focus_1yz7l_2{height:32px;margin-top:0;margin-bottom:0}._multitrack-header-id_1yz7l_30{padding-left:3px}._multitrack-header-id_1yz7l_30:before{content:"ID:";font-weight:700;padding-right:5px}._multitrack-header-left_1yz7l_39{display:flex;flex-grow:1}._multitrack-header-grabber_1yz7l_44,._multitrack-header-grabber-squeazed_1yz7l_45{display:flex;align-items:center;justify-content:center;width:24px;height:100%;cursor:move;border-radius:3px 0 0 3px;transition:background .15s cubic-bezier(.25,.1,.25,1)}._multitrack-header-grabber_1yz7l_44:hover,._multitrack-header-grabber-squeazed_1yz7l_45:hover{background:#999}._multitrack-header-grabber_1yz7l_44:hover div,._multitrack-header-grabber-squeazed_1yz7l_45:hover div{background:#fff}._multitrack-header-grabber_1yz7l_44 div,._multitrack-header-grabber-squeazed_1yz7l_45 div{width:1px;height:50%;margin:1px;background:#999;transition:background .15s cubic-bezier(.25,.1,.25,1)}._multitrack-header-dark_1yz7l_20 ._multitrack-header-grabber_1yz7l_44 div{background:#666}._multitrack-header-grabber-squeazed_1yz7l_45{width:19.2px}._multitrack-header-search_1yz7l_80{position:relative;flex-grow:1;height:100%;margin-right:12px}._multitrack-header-search_1yz7l_80:after{position:absolute;top:3px;bottom:3px;right:-12px;display:block;content:"";width:1px;margin:0 6px;background:#cccccc}._multitrack-header-dark_1yz7l_20 ._multitrack-header-search_1yz7l_80:after{background:#666}._multitrack-header-nav-list_1yz7l_102,._multitrack-header_1yz7l_1>nav{display:flex}._multitrack-header-icon_1yz7l_107,._multitrack-header-icon-squeazed_1yz7l_108{width:24px;height:100%;padding:6px;transition:background .15s cubic-bezier(.25,.1,.25,1),color .15s cubic-bezier(.25,.1,.25,1)}._multitrack-header-icon_1yz7l_107 g,._multitrack-header-icon-squeazed_1yz7l_108 g{stroke:#999}._multitrack-header-icon_1yz7l_107:hover,._multitrack-header-icon_1yz7l_107:active,._multitrack-header-icon_1yz7l_107:focus,._multitrack-header-icon-squeazed_1yz7l_108:hover,._multitrack-header-icon-squeazed_1yz7l_108:active,._multitrack-header-icon-squeazed_1yz7l_108:focus{color:#fff;background:#337ab7}._multitrack-header-icon_1yz7l_107:hover g,._multitrack-header-icon_1yz7l_107:active g,._multitrack-header-icon_1yz7l_107:focus g,._multitrack-header-icon-squeazed_1yz7l_108:hover g,._multitrack-header-icon-squeazed_1yz7l_108:active g,._multitrack-header-icon-squeazed_1yz7l_108:focus g{stroke:#fff}._multitrack-header-icon_1yz7l_107:last-child,._multitrack-header-icon-squeazed_1yz7l_108:last-child{border-radius:0 3px 3px 0}._mouse-tool-selection_1yz7l_136{color:#fff;border-radius:3px 0 0 3px;background:#337ab7}._multitrack-header-icon-squeazed_1yz7l_108{width:20px 5;padding-left:3px;padding-right:3px}._track-control_w7hx2_1,._track-control-vertical_w7hx2_2{position:absolute;z-index:1;display:flex;background:rgba(255,255,255,.75);right:2px;top:2px;border-radius:2.5px;box-shadow:0 0 0 1px #0000000d,0 0 3px #0000001a;opacity:0;transition:opacity .15s cubic-bezier(.25,.1,.25,1),background .15s cubic-bezier(.25,.1,.25,1),box-shadow .15s cubic-bezier(.25,.1,.25,1)}._track-control-dark_w7hx2_15,._track-control-dark_w7hx2_15 ._track-control-active_w7hx2_16{background:rgba(40,40,40,.85)}._track-control-vertical_w7hx2_2{flex-direction:column-reverse}._track-control-left_w7hx2_24{left:2px;right:auto}._track-control-active_w7hx2_16,._track-control-vertical-active_w7hx2_30{opacity:1;z-index:1}._track-control-active_w7hx2_16:hover,._track-control-vertical-active_w7hx2_30:hover{background:rgb(255,255,255);box-shadow:0 0 0 1px #0000001a,0 0 3px #0003}._track-control-dark_w7hx2_15._track-control-active_w7hx2_16:hover{background:rgba(34,34,34,.95)}._track-control-padding-right_w7hx2_48{right:80px}._track-control-button_w7hx2_52{width:20px;height:20px;padding:4px;cursor:pointer;opacity:.66;transition:background .15s cubic-bezier(.25,.1,.25,1),color .15s cubic-bezier(.25,.1,.25,1),opacity .15s cubic-bezier(.25,.1,.25,1)}._track-control-button_w7hx2_52:hover{color:#fff;background:#337ab7;opacity:1}._track-control-button_w7hx2_52:first-child{border-radius:2.5px 0 0 2.5px}._track-control-button_w7hx2_52:last-child{border-radius:0 2.5px 2.5px 0}._track-control-dark_w7hx2_15 ._track-control-button_w7hx2_52{color:#ccc}._track-control-dark_w7hx2_15 ._track-control-button_w7hx2_52:hover{color:#fff;background:#337ab7;opacity:1}._track-control-button-vertical_w7hx2_81:first-child{border-radius:0 0 2.5px 2.5px}._track-control-button-vertical_w7hx2_81:last-child{border-radius:2.5px 2.5px 0 0}._center-track_fiu64_1{position:relative;background:transparent}._center-track-container_fiu64_6{position:absolute;z-index:1}._track-range-selection_5bcsr_1{position:absolute;z-index:-1;opacity:0;transition:opacity .15s cubic-bezier(.25,.1,.25,1)}._track-range-selection-active_5bcsr_8{z-index:1;opacity:1}._track-range-selection-group-inactive_5bcsr_22{display:none}._track-range-selection-group-brush-selection_5bcsr_26{outline:2px solid rgba(0,0,0,.33);fill:#000;fill-opacity:.1}._drag-listening-div-active_19gkt_1{z-index:10;box-shadow:inset 0 0 3px red}._gallery-tracks_fbxxi_1{position:relative;top:0;left:0;width:100%;height:100%}._gallery-track_fbxxi_1{position:absolute;box-sizing:border-box;top:0;right:0;bottom:0;left:0}._gallery-sub-track_fbxxi_18,._gallery-invisible-track_fbxxi_19{position:absolute}._tiled-plot_1y7td_1{position:relative;flex:1;overflow:hidden}._horizontalList_1y7td_7{display:flex;width:600px;height:300px;white-space:nowrap}._list_1y7td_14{width:400px;height:600px;overflow:hidden;-webkit-overflow-scrolling:touch}._stylizedList_1y7td_21{position:relative;z-index:0;background-color:#f3f3f3;outline:none}._stylizedItem_1y7td_28{position:relative;display:flex;align-items:center;width:100%;background-color:transparent;-webkit-user-select:none;user-select:none;color:#333;font-weight:400}._stylizedHelper_1y7td_39{box-shadow:0 5px 5px -5px #0003,0 -5px 5px -5px #0003;background-color:#fffc;cursor:row-resize}._stylizedHelper_1y7td_39._horizontalItem_1y7td_44{cursor:col-resize}._horizontalItem_1y7td_44{display:flex;flex-shrink:0;align-items:center;justify-content:center}._resizable-track_1y7td_55{width:100%;height:100%}path._domain_1y7td_60{stroke-width:0px}._top-right-handle_cizw2_1,._bottom-right-handle_cizw2_2{border-right:black solid;border-top:black solid}._top-left-handle_cizw2_7,._bottom-left-handle_cizw2_8{border-left:black solid;border-top:black solid}._top-draggable-handle_cizw2_13,._bottom-draggable-handle_cizw2_14,._left-draggable-handle_cizw2_15,._right-draggable-handle_cizw2_16{position:absolute;opacity:0;transition:transform .15s cubic-bezier(.25,.1,.25,1),opacity .15s cubic-bezier(.25,.1,.25,1)}._draggable-div_cizw2_22{background-color:transparent;box-sizing:border-box}._top-draggable-handle-grabber_cizw2_27,._bottom-draggable-handle-grabber_cizw2_28{width:10px;height:4px;border-top:1px solid black;border-bottom:1px solid black}._top-draggable-handle-grabber_cizw2_27,._bottom-draggable-handle-grabber_cizw2_28{margin:4px 7px}._left-draggable-handle-grabber_cizw2_43,._right-draggable-handle-grabber_cizw2_44{width:4px;height:10px;border-left:1px solid black;border-right:1px solid black}._left-draggable-handle-grabber_cizw2_43,._right-draggable-handle-grabber_cizw2_44{margin:7px 4px}._draggable-div_cizw2_22:hover ._top-draggable-handle_cizw2_13,._draggable-div_cizw2_22:hover ._bottom-draggable-handle_cizw2_14,._draggable-div_cizw2_22:hover ._left-draggable-handle_cizw2_15,._draggable-div_cizw2_22:hover ._right-draggable-handle_cizw2_16{opacity:.5;background:rgba(255,255,255,.75);box-shadow:0 0 3px 1px #ffffffbf;border-radius:3px}._top-draggable-handle_cizw2_13:hover,._top-draggable-handle_cizw2_13:active,._bottom-draggable-handle_cizw2_14:hover,._bottom-draggable-handle_cizw2_14:active,._left-draggable-handle_cizw2_15:hover,._left-draggable-handle_cizw2_15:active,._right-draggable-handle_cizw2_16:hover,._right-draggable-handle_cizw2_16:active{opacity:1!important;transform:scale(2)}._top-draggable-handle_cizw2_13:hover ._top-draggable-handle-grabber_cizw2_27,._top-draggable-handle_cizw2_13:hover ._bottom-draggable-handle-grabber_cizw2_28,._top-draggable-handle_cizw2_13:hover ._left-draggable-handle-grabber_cizw2_43,._top-draggable-handle_cizw2_13:hover ._right-draggable-handle-grabber_cizw2_44,._top-draggable-handle_cizw2_13:active ._top-draggable-handle-grabber_cizw2_27,._top-draggable-handle_cizw2_13:active ._bottom-draggable-handle-grabber_cizw2_28,._top-draggable-handle_cizw2_13:active ._left-draggable-handle-grabber_cizw2_43,._top-draggable-handle_cizw2_13:active ._right-draggable-handle-grabber_cizw2_44,._bottom-draggable-handle_cizw2_14:hover ._top-draggable-handle-grabber_cizw2_27,._bottom-draggable-handle_cizw2_14:hover ._bottom-draggable-handle-grabber_cizw2_28,._bottom-draggable-handle_cizw2_14:hover ._left-draggable-handle-grabber_cizw2_43,._bottom-draggable-handle_cizw2_14:hover ._right-draggable-handle-grabber_cizw2_44,._bottom-draggable-handle_cizw2_14:active ._top-draggable-handle-grabber_cizw2_27,._bottom-draggable-handle_cizw2_14:active ._bottom-draggable-handle-grabber_cizw2_28,._bottom-draggable-handle_cizw2_14:active ._left-draggable-handle-grabber_cizw2_43,._bottom-draggable-handle_cizw2_14:active ._right-draggable-handle-grabber_cizw2_44,._left-draggable-handle_cizw2_15:hover ._top-draggable-handle-grabber_cizw2_27,._left-draggable-handle_cizw2_15:hover ._bottom-draggable-handle-grabber_cizw2_28,._left-draggable-handle_cizw2_15:hover ._left-draggable-handle-grabber_cizw2_43,._left-draggable-handle_cizw2_15:hover ._right-draggable-handle-grabber_cizw2_44,._left-draggable-handle_cizw2_15:active ._top-draggable-handle-grabber_cizw2_27,._left-draggable-handle_cizw2_15:active ._bottom-draggable-handle-grabber_cizw2_28,._left-draggable-handle_cizw2_15:active ._left-draggable-handle-grabber_cizw2_43,._left-draggable-handle_cizw2_15:active ._right-draggable-handle-grabber_cizw2_44,._right-draggable-handle_cizw2_16:hover ._top-draggable-handle-grabber_cizw2_27,._right-draggable-handle_cizw2_16:hover ._bottom-draggable-handle-grabber_cizw2_28,._right-draggable-handle_cizw2_16:hover ._left-draggable-handle-grabber_cizw2_43,._right-draggable-handle_cizw2_16:hover ._right-draggable-handle-grabber_cizw2_44,._right-draggable-handle_cizw2_16:active ._top-draggable-handle-grabber_cizw2_27,._right-draggable-handle_cizw2_16:active ._bottom-draggable-handle-grabber_cizw2_28,._right-draggable-handle_cizw2_16:active ._left-draggable-handle-grabber_cizw2_43,._right-draggable-handle_cizw2_16:active ._right-draggable-handle-grabber_cizw2_44{box-shadow:0 0 3px 1px #0089ff;background:#0089ff}._top-draggable-handle_cizw2_13,._bottom-draggable-handle_cizw2_14{height:12px;cursor:row-resize}._left-draggable-handle_cizw2_15,._right-draggable-handle_cizw2_16{width:12px;cursor:col-resize}._horizontal-tiled-plot_1bqkg_1{position:relative}._button_1wnjn_1{display:flex;align-items:center;box-sizing:border-box;padding:.5em;color:#000;font-size:1em;line-height:1em;border:0;border-radius:2.5px;background:#fff;box-shadow:0 0 0 1px #ccc;transition:transform .15s cubic-bezier(.25,.1,.25,1),box-shadow .15s cubic-bezier(.25,.1,.25,1),background .15s cubic-bezier(.25,.1,.25,1);-webkit-appearance:none}._button_1wnjn_1:hover{background:#f2f2f2;box-shadow:0 0 0 1px #ccc}._button_1wnjn_1:focus{box-shadow:0 0 0 2px #0089ff}._button_1wnjn_1:active{transform:scale(.9)}._button_1wnjn_1:hover,._button_1wnjn_1:focus,._button_1wnjn_1:active{cursor:pointer;outline:none}._button-shortcut_1wnjn_35{padding:.1em 5px;color:#999;font-size:.8em;transition:color .15s cubic-bezier(.25,.1,.25,1)}._cross_2ke8w_1{position:relative;width:1em;height:1em}._cross_2ke8w_1:before,._cross_2ke8w_1:after{content:"";display:block;position:absolute;top:50%;left:0;width:1em;height:1px;background:black;transform-origin:center}._cross_2ke8w_1:before{-webkit-transform:translate(0,-50%) rotate(45deg);-moz-transform:translate(0,-50%) rotate(45deg);transform:translateY(-50%) rotate(45deg)}._cross_2ke8w_1:after{-webkit-transform:translate(0,-50%) rotate(-45deg);-moz-transform:translate(0,-50%) rotate(-45deg);transform:translateY(-50%) rotate(-45deg)}._modal-background_zzhoe_1{position:absolute;z-index:1000;top:0;right:0;bottom:0;left:0;background:rgba(0,0,0,.666);animation:_fade-in_zzhoe_1 .2s cubic-bezier(.25,.1,.25,1) 1;transition:opacity .2s cubic-bezier(.25,.1,.25,1)}._modal-hide_zzhoe_13{opacity:0}._modal-wrap_zzhoe_17{position:absolute;top:20px;right:20px;bottom:20px;left:20px}._modal-window_zzhoe_25{position:relative;width:100%;max-width:640px;max-height:100%;margin-left:auto;margin-right:auto;color:#000;border-radius:5px;background:#fff;animation:_fade-scale-in_zzhoe_1 .2s cubic-bezier(.25,.1,.25,1) 1}._modal-window-max-height_zzhoe_38{height:100%}._modal-content_zzhoe_42{padding:10px}@keyframes _fade-in_zzhoe_1{0%{opacity:0}to{opacity:1}}@keyframes _fade-scale-in_zzhoe_1{0%{opacity:0;transform:scale(.5)}to{opacity:1;transform:scale(1)}}._dialog-header_wp50s_1{position:relative;z-index:2;display:flex;justify-content:space-between;margin:0 -10px 10px;padding:0 10px 10px;border-bottom:1px solid #cccccc}._dialog-header_wp50s_1 h3{margin:0;padding:0;font-size:20px;line-height:1em}._dialog-header_wp50s_1 button{font-size:10px}._dialog-main-max-height_wp50s_20{position:absolute;z-index:1;top:40px;right:0;bottom:50px;left:0;padding:10px;overflow:auto}._dialog-footer_wp50s_31,._dialog-footer-max-height_wp50s_31{display:flex;justify-content:space-between;margin:10px -10px 0;padding:10px 10px 0;border-top:1px solid #cccccc}._dialog-footer_wp50s_31 button,._dialog-footer-max-height_wp50s_31 button{font-size:14px}._dialog-footer-max-height_wp50s_31{position:absolute;z-index:2;left:10px;right:10px;bottom:10px}table.table-track-options{border-collapse:collapse;margin-left:auto;margin-right:auto}td.td-track-options{border:1px solid #fff;outline:none;padding:3px;position:relative;font-family:Roboto,sans-serif;font-size:14px;color:#666}.cell-label{position:absolute;left:0;top:0;margin-left:5px;color:#777}.modal-dialog{position:relative;display:table;overflow-y:auto;overflow-x:auto;width:auto;min-width:300px;margin:auto}._track-renderer_11dwb_1{position:relative}._track-renderer-element_11dwb_5,._track-renderer-events_11dwb_6{position:absolute;top:0;right:0;bottom:0;left:0;z-index:-1}._track-renderer-events_11dwb_6{z-index:1}.tileset-finder-label{font-weight:700}.tileset-finder-search-box{margin-left:10px}.tileset-finder-search-bar{display:flex;margin-left:5px;justify-content:space-between;align-items:center}.tileset-finder-checkbox-tree{margin:5px;padding:3px;border:1px solid #aaaaaa;border-radius:5px}.react-checkbox-tree{display:-webkit-box;display:-ms-flexbox;display:flex;-webkit-box-orient:horizontal;-webkit-box-direction:reverse;-ms-flex-direction:row-reverse;flex-direction:row-reverse;font-size:16px}.react-checkbox-tree>ol{-webkit-box-flex:1;-ms-flex:1 1 auto;flex:1 1 auto}.react-checkbox-tree ol{margin:0;padding-left:0;list-style-type:none}.react-checkbox-tree ol ol{padding-left:24px}.react-checkbox-tree button{line-height:normal;color:inherit}.react-checkbox-tree button:disabled{cursor:not-allowed}.react-checkbox-tree .rct-bare-label{cursor:default}.react-checkbox-tree label{margin-bottom:0;cursor:pointer}.react-checkbox-tree label:hover{background:rgba(51,51,204,.1)}.react-checkbox-tree label:active,.react-checkbox-tree label:focus{background:rgba(51,51,204,.15)}.react-checkbox-tree:not(.rct-native-display) input{display:none}.react-checkbox-tree.rct-native-display input{margin:0 5px}.react-checkbox-tree .rct-icon{display:inline-block;text-align:center;text-rendering:auto;font-family:"Font Awesome 5 Free",FontAwesome,sans-serif;font-weight:400;font-variant:normal;font-style:normal}.rct-disabled>.rct-text>label{opacity:.75;cursor:not-allowed}.rct-disabled>.rct-text>label:hover{background:transparent}.rct-disabled>.rct-text>label:active{background:transparent}.rct-text{display:-webkit-box;display:-ms-flexbox;display:flex;-webkit-box-align:center;-ms-flex-align:center;align-items:center}.rct-options{-webkit-box-flex:0;-ms-flex:0 0 auto;flex:0 0 auto;margin-left:.5rem;text-align:right}.rct-option{opacity:.75;border:0;background:none;cursor:pointer;padding:0 4px;font-size:18px}.rct-option:hover{opacity:1}.rct-option+.rct-option{margin-left:2px}.rct-collapse,.rct-checkbox,.rct-node-icon{padding:0 5px}.rct-collapse *,.rct-checkbox *,.rct-node-icon *{display:inline-block;margin:0;width:14px}.rct-collapse{-ms-flex-item-align:stretch;align-self:stretch;border:0;background:none;line-height:normal;color:inherit;font-size:12px}.rct-collapse.rct-collapse-btn{cursor:pointer}.rct-collapse>.rct-icon-expand-close{opacity:.5}.rct-collapse>.rct-icon-expand-close:hover{opacity:1}.rct-native-display .rct-checkbox{display:none}.rct-node-clickable{cursor:pointer}.rct-node-clickable:hover{background:rgba(51,51,204,.1)}.rct-node-clickable:focus{outline:0;background:rgba(51,51,204,.2)}.rct-node-icon{color:#33c}.rct-title{padding:0 5px}.rct-icons-fa4 .rct-icon-expand-close:before{content:""}.rct-icons-fa4 .rct-icon-expand-open:before{content:""}.rct-icons-fa4 .rct-icon-uncheck:before{content:""}.rct-icons-fa4 .rct-icon-check:before{content:""}.rct-icons-fa4 .rct-icon-half-check:before{opacity:.5;content:""}.rct-icons-fa4 .rct-icon-leaf:before{content:""}.rct-icons-fa4 .rct-icon-parent-open:before{content:""}.rct-icons-fa4 .rct-icon-parent-close:before{content:""}.rct-icons-fa4 .rct-icon-expand-all:before{content:""}.rct-icons-fa4 .rct-icon-collapse-all:before{content:""}.rct-icons-fa5 .rct-icon-expand-close:before{font-weight:900;content:""}.rct-icons-fa5 .rct-icon-expand-open:before{font-weight:900;content:""}.rct-icons-fa5 .rct-icon-uncheck:before{content:""}.rct-icons-fa5 .rct-icon-check:before{content:""}.rct-icons-fa5 .rct-icon-half-check:before{opacity:.5;content:""}.rct-icons-fa5 .rct-icon-leaf:before{content:""}.rct-icons-fa5 .rct-icon-parent-open:before{content:""}.rct-icons-fa5 .rct-icon-parent-close:before{content:""}.rct-icons-fa5 .rct-icon-expand-all:before{content:""}.rct-icons-fa5 .rct-icon-collapse-all:before{content:""}.rct-direction-rtl{direction:rtl}.rct-direction-rtl ol ol{padding-right:24px;padding-left:0}.rct-direction-rtl.rct-icons-fa4 .rct-icon-expand-close:before{content:""}.rct-direction-rtl.rct-icons-fa5 .rct-icon-expand-close:before{content:""}.plot-type-selected{background-color:#0000ff4d}.plot-type-container{overflow-y:scroll;margin:5px;padding:3px;border:1px solid #aaaaaa;border-radius:5px;max-height:15vh}.plot-type-container-empty{margin:5px;padding:3px 8px;border:1px solid #aaaaaa;background-color:#e8e8e8;border-radius:5px}.plot-type-item{cursor:pointer}.plot-type-item:not(.plot-type-selected):hover{background-color:#3333cc1a}.track-thumbnail{width:30px;height:20px;display:inline-block;margin-right:10;vertical-align:middle}.track-thumbnail>svg{width:20px;height:20px}._collapse-toggle-icon_ub7s6_1:before{font-family:Glyphicons Halflings;content:"";float:left;padding-right:3px}._collapse-toggle-icon_ub7s6_1._collapsed_ub7s6_9:before{content:""}._modal-title_ub7s6_14{font-family:Roboto;font-weight:700}._modal-container_ub7s6_19{position:relative}._modal-container_ub7s6_19 ._modal_ub7s6_14,._modal-container_ub7s6_19 ._modal-backdrop_ub7s6_23{position:absolute}._modal-dialog_ub7s6_27{position:relative;display:table;overflow-y:auto;overflow-x:auto;width:600px;min-width:300px;margin:auto}._vertical-tiled-plot_f3ho8_1{position:relative}._genome-position-search_1l2sx_1,._genome-position-search-focus_1l2sx_2{position:relative;display:flex;align-items:stretch;height:100%;margin-bottom:0;font-size:13.7142857143px;transition:box-shadow .15s cubic-bezier(.25,.1,.25,1),font-size .15s cubic-bezier(.25,.1,.25,1)}._genome-position-search-focus_1l2sx_2{box-shadow:0 0 0 1px #337ab7,0 0 3px 1px #337ab7}._genome-position-search-bar_1l2sx_16{position:relative;box-sizing:border-box;width:100%;height:100%;padding:3px;color:#666;font-size:inherit;line-height:24px;border:0;border-radius:3px 0 0 3px;background:transparent}._genome-position-search-bar_1l2sx_16:focus{outline:none;color:#000}._genome-position-search-dark_1l2sx_34 ._genome-position-search-bar_1l2sx_16:focus{color:#e5e5e5}._genome-position-search-bar-button_1l2sx_38,._genome-position-search-bar-button-focus_1l2sx_39{display:block;height:100%;padding:0 8px!important;color:#999;border:0!important;border-radius:0!important;background:transparent;transition:background .15s cubic-bezier(.25,.1,.25,1),color .15s cubic-bezier(.25,.1,.25,1)}._genome-position-search-bar-button_1l2sx_38:active,._genome-position-search-bar-button_1l2sx_38:focus,._genome-position-search-bar-button_1l2sx_38:hover,._genome-position-search-bar-button-focus_1l2sx_39:active,._genome-position-search-bar-button-focus_1l2sx_39:focus,._genome-position-search-bar-button-focus_1l2sx_39:hover{color:#fff;background:#337ab7}._genome-position-search-bar-button-focus_1l2sx_39{color:#fff;background:#337ab7}._genome-position-search-bar-icon_1l2sx_62,._genome-position-search-bar-icon-focus_1l2sx_63{display:flex;align-items:center;transition:color .15s cubic-bezier(.25,.1,.25,1)}._genome-position-search-bar-icon_1l2sx_62:first-child,._genome-position-search-bar-icon-focus_1l2sx_63:first-child{margin-left:6px;margin-right:2px}._genome-position-search-bar-icon_1l2sx_62 span,._genome-position-search-bar-icon-focus_1l2sx_63 span{display:block;margin-top:-2px}._genome-position-search-bar-icon-focus_1l2sx_63{color:#337ab7}._genome-position-search-bar-suggestions_1l2sx_83{position:fixed;border-radius:3px;box-shadow:0 0 3px #0000001a,0 1px 5px #0000000d;background-color:#fffffff2;border:1px solid rgba(0,0,0,.1);padding:2px 0;font-size:90%;overflow:auto;max-height:50%}._btn_1l2sx_95{display:inline-block;margin-bottom:0;font-size:13.7142857143px;font-weight:400;line-height:1.42857143;text-align:center;white-space:nowrap;vertical-align:middle;-ms-touch-action:manipulation;touch-action:manipulation;cursor:pointer;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;background-image:none;border:1px solid transparent;border-radius:4px}._btn-sm_1l2sx_116{font-size:12px;line-height:1.5;border-radius:3px}._btn-default_1l2sx_122{color:#666;background-color:#fff;border-color:#ccc}._btn-default_1l2sx_122:hover{color:#000;background:#ccc}._btn-default_1l2sx_122:active,._btn-default_1l2sx_122:focus{color:#fff;border-color:#000;background:#000}._genome-position-search_1l2sx_1 ._btn_1l2sx_95{border-radius:0 3px 3px 0}._export-link-dialog-wrapper_p9gxw_1{display:flex}._export-link-dialog-wrapper_p9gxw_1 input{flex-grow:1}._add-track-position-table_wdy5w_1{border-collapse:collapse;margin:5px;color:#666}._add-track-position-table-dark_wdy5w_7{color:#ccc}._add-track-position-other_wdy5w_11{outline:none}._add-track-position-top-center_wdy5w_15{min-width:80px;min-height:20px;text-align:center;outline:none;border-top:1px solid #999;border-left:1px solid #999;border-right:1px solid #999;border-radius:2px 2px 0 0}._add-track-position-top-center_wdy5w_15:hover{color:#fff;background-color:#337ab7}._add-track-position-middle-left_wdy5w_30{min-width:40px;text-align:center;outline:none;border-top:1px solid #999;border-left:1px solid #999;border-bottom:1px solid #999;border-radius:2px 0 0 2px}._add-track-position-middle-left_wdy5w_30:hover{background-color:#337ab7;color:#fff}._add-track-position-middle-right_wdy5w_45{min-width:40px;text-align:center;outline:none;border-top:1px solid #999;border-right:1px solid #999;border-bottom:1px solid #999;border-radius:0 2px 2px 0}._add-track-position-middle-right_wdy5w_45:hover{background-color:#337ab7;color:#fff}._add-track-position-middle-middle_wdy5w_60{text-align:center;outline:none;border:1px solid #999}._add-track-position-middle-middle_wdy5w_60:hover{background-color:#337ab7;color:#fff}._add-track-position-bottom-middle_wdy5w_71{min-height:20px;text-align:center;outline:none;border-left:1px solid #999;border-right:1px solid #999;border-bottom:1px solid #999;border-radius:0 0 2px 2px}._add-track-position-bottom-middle_wdy5w_71:hover{background-color:#337ab7;color:#fff}._add-track-position-span_wdy5w_86{margin:5px}._view-config-editor-header_1hlm6_1{margin:-10px -10px 0;padding:10px;display:flex;justify-content:space-between;background:#f2f2f2}._view-config-editor-header_1hlm6_1 button{display:flex;align-items:center;font-size:14px;background:#f2f2f2}._view-config-editor-header_1hlm6_1 button:hover{background:#e5e5e5}._view-config-editor-header_1hlm6_1 button:hover span{color:#666}._view-config-editor_1hlm6_1{position:absolute;top:50px;right:0;bottom:0;left:0;margin:1px 0 0;padding:0;overflow:auto;font-size:12.5px;height:calc(100% - 80px)}._view-config-log_1hlm6_34{position:absolute;right:0;bottom:0;left:0;margin:1px 0 0;padding:0;min-height:30px;background:#f2f2f2;transition:height .15s cubic-bezier(.25,.1,.25,1)}._view-config-log-header_1hlm6_46{background:#f2f2f2;border-top:1px solid #cccccc;border-bottom:1px solid #cccccc;padding-left:10px;height:30px;display:flex;align-items:center;cursor:pointer;position:sticky;position:-webkit-sticky;top:0}._view-config-log-msg_1hlm6_60{background:#f2f2f2;overflow:auto;height:calc(100% - 30px)}._view-config-log-msg_1hlm6_60 tr,._view-config-log-msg_1hlm6_60 td{outline:none;vertical-align:top}._view-config-log-msg_1hlm6_60 ._title_1hlm6_70{font-weight:700;padding-left:8px;padding-top:8px;width:100px}._view-config-log-msg_1hlm6_60 ._Warning_1hlm6_76{color:orange}._view-config-log-msg_1hlm6_60 ._Success_1hlm6_79{color:green}._view-config-log-msg_1hlm6_60 ._Error_1hlm6_82{color:red}._view-config-log-msg_1hlm6_60 pre{background:white;white-space:pre-wrap;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;word-wrap:break-word}._higlass_1uoq8_1{position:relative}._higlass-dark-theme_1uoq8_5{background:black}._higlass-container-overflow_1uoq8_9,._higlass-scroll-container-overflow_1uoq8_10,._higlass-scroll-container-scroll_1uoq8_11{position:absolute;top:0;right:0;bottom:0;left:0}._higlass-scroll-container-overflow_1uoq8_10{overflow:hidden}._higlass-scroll-container-scroll_1uoq8_11{overflow-x:hidden;overflow-y:auto}._higlass-canvas_1uoq8_28{position:absolute;width:100%;height:100%}._higlass-drawing-surface_1uoq8_34{position:relative}._higlass-svg_1uoq8_38{position:absolute;width:100%;height:100%;left:0;top:0;pointer-events:none}._tiled-area_1uoq8_47{display:flex;flex-direction:column}._track-mouseover-menu_1uoq8_52{position:fixed;z-index:1;margin:17px 0 0 9px;padding:0 .25rem;max-width:50vw;word-wrap:break-word;font-size:.8em;pointer-events:none;background:white;border-radius:.25rem;box-shadow:0 0 0 1px #0000001a,0 0 3px #00000013,0 0 7px #0000000d}.react-grid-layout{position:relative;transition:height .2s ease}.react-grid-item{transition:all .2s ease;transition-property:left,top}.react-grid-item.cssTransforms{transition-property:transform}.react-grid-item.resizing{z-index:1;will-change:width,height}.react-grid-item.react-draggable-dragging{transition:none;z-index:3;will-change:transform}.react-grid-item.react-grid-placeholder{background:red;opacity:.2;transition-duration:.1s;z-index:2;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;-o-user-select:none;user-select:none}.react-grid-item>.react-resizable-handle{position:absolute;width:20px;height:20px;bottom:0;right:0;cursor:se-resize}.react-grid-item>.react-resizable-handle:after{content:"";position:absolute;right:3px;bottom:3px;width:5px;height:5px;border-right:2px solid rgba(0,0,0,.4);border-bottom:2px solid rgba(0,0,0,.4)}.react-resizable{position:relative}.react-resizable-handle{position:absolute;width:20px;height:20px;background-repeat:no-repeat;background-origin:content-box;box-sizing:border-box;background-image:url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA2IDYiIHN0eWxlPSJiYWNrZ3JvdW5kLWNvbG9yOiNmZmZmZmYwMCIgeD0iMHB4IiB5PSIwcHgiIHdpZHRoPSI2cHgiIGhlaWdodD0iNnB4Ij48ZyBvcGFjaXR5PSIwLjMwMiI+PHBhdGggZD0iTSA2IDYgTCAwIDYgTCAwIDQuMiBMIDQgNC4yIEwgNC4yIDQuMiBMIDQuMiAwIEwgNiAwIEwgNiA2IEwgNiA2IFoiIGZpbGw9IiMwMDAwMDAiLz48L2c+PC9zdmc+);background-position:bottom right;padding:0 3px 3px 0}.react-resizable-handle-sw{bottom:0;left:0;cursor:sw-resize;transform:rotate(90deg)}.react-resizable-handle-se{bottom:0;right:0;cursor:se-resize}.react-resizable-handle-nw{top:0;left:0;cursor:nw-resize;transform:rotate(180deg)}.react-resizable-handle-ne{top:0;right:0;cursor:ne-resize;transform:rotate(270deg)}.react-resizable-handle-w,.react-resizable-handle-e{top:50%;margin-top:-10px;cursor:ew-resize}.react-resizable-handle-w{left:0;transform:rotate(135deg)}.react-resizable-handle-e{right:0;transform:rotate(315deg)}.react-resizable-handle-n,.react-resizable-handle-s{left:50%;margin-left:-10px;cursor:ns-resize}.react-resizable-handle-n{top:0;transform:rotate(225deg)}.react-resizable-handle-s{bottom:0;transform:rotate(45deg)}code[class*=language-],pre[class*=language-]{color:#393a34;font-family:Consolas,Bitstream Vera Sans Mono,Courier New,Courier,monospace;direction:ltr;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;font-size:.95em;line-height:1.2em;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none}pre[class*=language-]::-moz-selection,pre[class*=language-] ::-moz-selection,code[class*=language-]::-moz-selection,code[class*=language-] ::-moz-selection{background:#b3d4fc}pre[class*=language-]::selection,pre[class*=language-] ::selection,code[class*=language-]::selection,code[class*=language-] ::selection{background:#b3d4fc}pre[class*=language-]{padding:1em;margin:.5em 0;overflow:auto;border:1px solid #dddddd;background-color:#fff}:not(pre)>code[class*=language-]{padding:1px .2em;background:#f8f8f8;border:1px solid #dddddd}.token.comment,.token.prolog,.token.doctype,.token.cdata{color:#998;font-style:italic}.token.namespace{opacity:.7}.token.string,.token.attr-value{color:#e3116c}.token.punctuation,.token.operator{color:#393a34}.token.entity,.token.url,.token.symbol,.token.number,.token.boolean,.token.variable,.token.constant,.token.property,.token.regex,.token.inserted{color:#36acaa}.token.atrule,.token.keyword,.token.attr-name,.language-autohotkey .token.selector{color:#00a4db}.token.function,.token.deleted,.language-autohotkey .token.tag{color:#9a050f}.token.tag,.token.selector,.language-autohotkey .token.keyword{color:#00009f}.token.important,.token.function,.token.bold{font-weight:700}.token.italic{font-style:italic}.higlass *{box-sizing:border-box}.higlass .react-resizable-handle{z-index:1}')),document.head.appendChild(e)}}catch(g){console.error("vite-plugin-css-injected-by-js",g)}})();var Le=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{};function DC(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function Os(e){if(e.__esModule)return e;var g=e.default;if(typeof g=="function"){var I=function i(){return this instanceof i?Reflect.construct(g,arguments,this.constructor):g.apply(this,arguments)};I.prototype=g.prototype}else I={};return Object.defineProperty(I,"__esModule",{value:!0}),Object.keys(e).forEach(function(i){var n=Object.getOwnPropertyDescriptor(e,i);Object.defineProperty(I,i,n.get?n:{enumerable:!0,get:function(){return e[i]}})}),I}var Sbe={exports:{}},Bqe="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED",Sqe=Bqe,wqe=Sqe;function wbe(){}function Vbe(){}Vbe.resetWarningCache=wbe;var Vqe=function(){function e(i,n,C,r,o,A){if(A!==wqe){var s=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw s.name="Invariant Violation",s}}e.isRequired=e;function g(){return e}var I={array:e,bigint:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:g,element:e,elementType:e,instanceOf:g,node:e,objectOf:g,oneOf:g,oneOfType:g,shape:g,exact:g,checkPropTypes:Vbe,resetWarningCache:wbe};return I.PropTypes=I,I};Sbe.exports=Vqe();var _s=Sbe.exports;const L=DC(_s);var MM="http://www.w3.org/1999/xhtml";const zM={svg:"http://www.w3.org/2000/svg",xhtml:MM,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function zh(e){var g=e+="",I=g.indexOf(":");return I>=0&&(g=e.slice(0,I))!=="xmlns"&&(e=e.slice(I+1)),zM.hasOwnProperty(g)?{space:zM[g],local:e}:e}function Rqe(e){return function(){var g=this.ownerDocument,I=this.namespaceURI;return I===MM&&g.documentElement.namespaceURI===MM?g.createElement(e):g.createElementNS(I,e)}}function Wqe(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function vT(e){var g=zh(e);return(g.local?Wqe:Rqe)(g)}function Xqe(){}function hS(e){return e==null?Xqe:function(){return this.querySelector(e)}}function Hqe(e){typeof e!="function"&&(e=hS(e));for(var g=this._groups,I=g.length,i=new Array(I),n=0;n=p&&(p=b+1);!(Z=m[p])&&++p=0;)(r=i[n])&&(C&&r.compareDocumentPosition(C)^4&&C.parentNode.insertBefore(r,C),C=r);return this}function tet(e){e||(e=get);function g(l,c){return l&&c?e(l.__data__,c.__data__):!l-!c}for(var I=this._groups,i=I.length,n=new Array(i),C=0;Cg?1:e>=g?0:NaN}function Iet(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function iet(){return Array.from(this)}function net(){for(var e=this._groups,g=0,I=e.length;g1?this.each((g==null?met:typeof g=="function"?pet:fet)(e,g,I??"")):go(this.node(),e)}function go(e,g){return e.style.getPropertyValue(g)||TU(e).getComputedStyle(e,null).getPropertyValue(g)}function yet(e){return function(){delete this[e]}}function Zet(e,g){return function(){this[e]=g}}function Get(e,g){return function(){var I=g.apply(this,arguments);I==null?delete this[e]:this[e]=I}}function vet(e,g){return arguments.length>1?this.each((g==null?yet:typeof g=="function"?Get:Zet)(e,g)):this.node()[e]}function Xbe(e){return e.trim().split(/^|\s+/)}function NU(e){return e.classList||new Hbe(e)}function Hbe(e){this._node=e,this._names=Xbe(e.getAttribute("class")||"")}Hbe.prototype={add:function(e){var g=this._names.indexOf(e);g<0&&(this._names.push(e),this._node.setAttribute("class",this._names.join(" ")))},remove:function(e){var g=this._names.indexOf(e);g>=0&&(this._names.splice(g,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(e){return this._names.indexOf(e)>=0}};function Tbe(e,g){for(var I=NU(e),i=-1,n=g.length;++i=0&&(I=g.slice(i+1),g=g.slice(0,i)),{type:g,name:I}})}function qet(e){return function(){var g=this.__on;if(g){for(var I=0,i=-1,n=g.length,C;IEg(I,g))}function att(e){return typeof e=="string"?new Tn([document.querySelectorAll(e)],[document.documentElement]):new Tn([e==null?[]:HU(e)],kU)}const stt=Object.freeze(Object.defineProperty({__proto__:null,create:rtt,creator:vT,local:Ybe,matcher:ST,namespace:zh,namespaces:zM,pointer:Eg,pointers:Att,select:cg,selectAll:att,selection:sA,selector:hS,selectorAll:BT,style:go,window:TU},Symbol.toStringTag,{value:"Module"}));function mi(e,g){return eg?1:e>=g?0:NaN}function G0(e){let g=e,I=e;e.length===1&&(g=(r,o)=>e(r)-o,I=ltt(e));function i(r,o,A,s){for(A==null&&(A=0),s==null&&(s=r.length);A>>1;I(r[a],o)<0?A=a+1:s=a}return A}function n(r,o,A,s){for(A==null&&(A=0),s==null&&(s=r.length);A>>1;I(r[a],o)>0?s=a:A=a+1}return A}function C(r,o,A,s){A==null&&(A=0),s==null&&(s=r.length);const a=i(r,o,A,s-1);return a>A&&g(r[a-1],o)>-g(r[a],o)?a-1:a}return{left:i,center:C,right:n}}function ltt(e){return(g,I)=>mi(e(g),I)}function Dbe(e){return e===null?NaN:+e}function*ctt(e,g){if(g===void 0)for(let I of e)I!=null&&(I=+I)>=I&&(yield I);else{let I=-1;for(let i of e)(i=g(i,++I,e))!=null&&(i=+i)>=i&&(yield i)}}const xbe=G0(mi),Fbe=xbe.right,utt=xbe.left,dtt=G0(Dbe).center,Ph=Fbe;function wT(e,g){let I=0;if(g===void 0)for(let i of e)i!=null&&(i=+i)>=i&&++I;else{let i=-1;for(let n of e)(n=g(n,++i,e))!=null&&(n=+n)>=n&&++I}return I}function htt(e){return e.length|0}function mtt(e){return!(e>0)}function ftt(e){return typeof e!="object"||"length"in e?e:Array.from(e)}function ptt(e){return g=>e(...g)}function btt(...e){const g=typeof e[e.length-1]=="function"&&ptt(e.pop());e=e.map(ftt);const I=e.map(htt),i=e.length-1,n=new Array(i+1).fill(0),C=[];if(i<0||I.some(mtt))return C;for(;;){C.push(n.map((o,A)=>e[A][o]));let r=i;for(;++n[r]===I[r];){if(r===0)return g?C.map(g):C;n[r--]=0}}}function ytt(e,g){var I=0,i=0;return Float64Array.from(e,g===void 0?n=>I+=+n||0:n=>I+=+g(n,i++,e)||0)}function Ztt(e,g){return ge?1:g>=e?0:NaN}function YU(e,g){let I=0,i,n=0,C=0;if(g===void 0)for(let r of e)r!=null&&(r=+r)>=r&&(i=r-n,n+=i/++I,C+=i*(r-n));else{let r=-1;for(let o of e)(o=g(o,++r,e))!=null&&(o=+o)>=o&&(i=o-n,n+=i/++I,C+=i*(o-n))}if(I>1)return C/(I-1)}function KU(e,g){const I=YU(e,g);return I&&Math.sqrt(I)}function h1(e,g){let I,i;if(g===void 0)for(const n of e)n!=null&&(I===void 0?n>=n&&(I=i=n):(I>n&&(I=n),i=C&&(I=i=C):(I>C&&(I=C),i0){for(o=I[--i];i>0&&(n=o,C=I[--i],o=n+C,r=C-(o-n),!r););i>0&&(r<0&&I[i-1]<0||r>0&&I[i-1]>0)&&(C=r*2,n=o+C,C==n-o&&(o=n))}return o}}]),e}();function wtt(e,g){const I=new Xi;if(g===void 0)for(let i of e)(i=+i)&&I.add(i);else{let i=-1;for(let n of e)(n=+g(n,++i,e))&&I.add(n)}return+I}function Vtt(e,g){const I=new Xi;let i=-1;return Float64Array.from(e,g===void 0?n=>I.add(+n||0):n=>I.add(+g(n,++i,e)||0))}function Ebe(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function Vte(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function Ttt(e){try{return Function.toString.call(e).indexOf("[native code]")!==-1}catch{return typeof e=="function"}}function rB(e,g){return rB=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(i,n){return i.__proto__=n,i},rB(e,g)}function Cr(e){return Cr=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},Cr(e)}let RX=function(e){zbe(I,e);var g=Pbe(I);function I(i,n=Lbe){var C;if(Ebe(this,I),C=g.call(this),Object.defineProperties(DU(C),{_intern:{value:new Map},_key:{value:n}}),i!=null)for(const[r,o]of i)C.set(r,o);return C}return Mbe(I,[{key:"get",value:function(n){return jA(Cr(I.prototype),"get",this).call(this,JM(this,n))}},{key:"has",value:function(n){return jA(Cr(I.prototype),"has",this).call(this,JM(this,n))}},{key:"set",value:function(n,C){return jA(Cr(I.prototype),"set",this).call(this,Obe(this,n),C)}},{key:"delete",value:function(n){return jA(Cr(I.prototype),"delete",this).call(this,_be(this,n))}}]),I}(VX(Map)),Ntt=function(e){zbe(I,e);var g=Pbe(I);function I(i,n=Lbe){var C;if(Ebe(this,I),C=g.call(this),Object.defineProperties(DU(C),{_intern:{value:new Map},_key:{value:n}}),i!=null)for(const r of i)C.add(r);return C}return Mbe(I,[{key:"has",value:function(n){return jA(Cr(I.prototype),"has",this).call(this,JM(this,n))}},{key:"add",value:function(n){return jA(Cr(I.prototype),"add",this).call(this,Obe(this,n))}},{key:"delete",value:function(n){return jA(Cr(I.prototype),"delete",this).call(this,_be(this,n))}}]),I}(VX(Set));function JM({_intern:e,_key:g},I){const i=g(I);return e.has(i)?e.get(i):I}function Obe({_intern:e,_key:g},I){const i=g(I);return e.has(i)?e.get(i):(e.set(i,I),I)}function _be({_intern:e,_key:g},I){const i=g(I);return e.has(i)&&(I=e.get(I),e.delete(i)),I}function Lbe(e){return e!==null&&typeof e=="object"?e.valueOf():e}function cb(e){return e}function Ube(e,...g){return v0(e,cb,cb,g)}function ktt(e,...g){return v0(e,Array.from,cb,g)}function Qbe(e,g,...I){return v0(e,cb,g,I)}function Ytt(e,g,...I){return v0(e,Array.from,g,I)}function Ktt(e,...g){return v0(e,cb,jbe,g)}function Dtt(e,...g){return v0(e,Array.from,jbe,g)}function jbe(e){if(e.length!==1)throw new Error("duplicate key");return e[0]}function v0(e,g,I,i){return function n(C,r){if(r>=i.length)return I(C);const o=new RX,A=i[r++];let s=-1;for(const a of C){const l=A(a,++s,C),c=o.get(l);c?c.push(a):o.set(l,[a])}for(const[a,l]of o)o.set(a,n(l,r));return g(o)}(e,0)}function $be(e,g){return Array.from(g,I=>e[I])}function OM(e,...g){if(typeof e[Symbol.iterator]!="function")throw new TypeError("values is not iterable");e=Array.from(e);let[I=mi]=g;if(I.length===1||g.length>1){const i=Uint32Array.from(e,(n,C)=>C);return g.length>1?(g=g.map(n=>e.map(n)),i.sort((n,C)=>{for(const r of g){const o=mi(r[n],r[C]);if(o)return o}})):(I=e.map(I),i.sort((n,C)=>mi(I[n],I[C]))),$be(e,i)}return e.sort(I)}function xtt(e,g,I){return(g.length===1?OM(Qbe(e,g,I),([i,n],[C,r])=>mi(n,r)||mi(i,C)):OM(Ube(e,I),([i,n],[C,r])=>g(n,r)||mi(i,C))).map(([i])=>i)}var Ftt=Array.prototype,Ett=Ftt.slice;function TV(e){return function(){return e}}var _M=Math.sqrt(50),LM=Math.sqrt(10),UM=Math.sqrt(2);function Ud(e,g,I){var i,n=-1,C,r,o;if(g=+g,e=+e,I=+I,e===g&&I>0)return[e];if((i=g0){let A=Math.round(e/o),s=Math.round(g/o);for(A*og&&--s,r=new Array(C=s-A+1);++ng&&--s,r=new Array(C=s-A+1);++n=0?(C>=_M?10:C>=LM?5:C>=UM?2:1)*Math.pow(10,n):-Math.pow(10,-n)/(C>=_M?10:C>=LM?5:C>=UM?2:1)}function WX(e,g,I){var i=Math.abs(g-e)/Math.max(0,I),n=Math.pow(10,Math.floor(Math.log(i)/Math.LN10)),C=i/n;return C>=_M?n*=10:C>=LM?n*=5:C>=UM&&(n*=2),g0?(e=Math.floor(e/n)*n,g=Math.ceil(g/n)*n):n<0&&(e=Math.ceil(e*n)/n,g=Math.floor(g*n)/n),i=n}}function e0e(e){return Math.ceil(Math.log(wT(e))/Math.LN2)+1}function Rte(){var e=cb,g=h1,I=e0e;function i(n){Array.isArray(n)||(n=Array.from(n));var C,r=n.length,o,A=new Array(r);for(C=0;C=l)if(m>=l&&g===h1){const b=mS(a,l,f);isFinite(b)&&(b>0?l=(Math.floor(l/b)+1)*b:b<0&&(l=(Math.ceil(l*-b)+1)/-b))}else c.pop()}for(var u=c.length;c[0]<=a;)c.shift(),--u;for(;c[u-1]>l;)c.pop(),--u;var d=new Array(u+1),h;for(C=0;C<=u;++C)h=d[C]=[],h.x0=C>0?c[C-1]:a,h.x1=C=i)&&(I=i);else{let i=-1;for(let n of e)(n=g(n,++i,e))!=null&&(I=n)&&(I=n)}return I}function XX(e,g){let I;if(g===void 0)for(const i of e)i!=null&&(I>i||I===void 0&&i>=i)&&(I=i);else{let i=-1;for(let n of e)(n=g(n,++i,e))!=null&&(I>n||I===void 0&&n>=n)&&(I=n)}return I}function xU(e,g,I=0,i=e.length-1,n=mi){for(;i>I;){if(i-I>600){const A=i-I+1,s=g-I+1,a=Math.log(A),l=.5*Math.exp(2*a/3),c=.5*Math.sqrt(a*l*(A-l)/A)*(s-A/2<0?-1:1),u=Math.max(I,Math.floor(g-s*l/A+c)),d=Math.min(i,Math.floor(g+(A-s)*l/A+c));xU(e,g,u,d,n)}const C=e[g];let r=I,o=i;for(Ty(e,I,g),n(e[i],C)>0&&Ty(e,I,i);r0;)--o}n(e[I],C)===0?Ty(e,I,o):(++o,Ty(e,o,i)),o<=g&&(I=o+1),g<=o&&(i=o-1)}return e}function Ty(e,g,I){const i=e[g];e[g]=e[I],e[I]=i}function oB(e,g,I){if(e=Float64Array.from(ctt(e,I)),!!(i=e.length)){if((g=+g)<=0||i<2)return XX(e);if(g>=1)return QM(e);var i,n=(i-1)*g,C=Math.floor(n),r=QM(xU(e,C).subarray(0,C+1)),o=XX(e.subarray(C+1));return r+(o-r)*(n-C)}}function t0e(e,g,I=Dbe){if(i=e.length){if((g=+g)<=0||i<2)return+I(e[0],0,e);if(g>=1)return+I(e[i-1],i-1,e);var i,n=(i-1)*g,C=Math.floor(n),r=+I(e[C],C,e),o=+I(e[C+1],C+1,e);return r+(o-r)*(n-C)}}function Mtt(e,g,I){return Math.ceil((I-g)/(2*(oB(e,.75)-oB(e,.25))*Math.pow(wT(e),-1/3)))}function ztt(e,g,I){return Math.ceil((I-g)/(3.5*KU(e)*Math.pow(wT(e),-1/3)))}function g0e(e,g){let I,i=-1,n=-1;if(g===void 0)for(const C of e)++n,C!=null&&(I=C)&&(I=C,i=n);else for(let C of e)(C=g(C,++n,e))!=null&&(I=C)&&(I=C,i=n);return i}function jM(e,g){let I=0,i=0;if(g===void 0)for(let n of e)n!=null&&(n=+n)>=n&&(++I,i+=n);else{let n=-1;for(let C of e)(C=g(C,++n,e))!=null&&(C=+C)>=C&&(++I,i+=C)}if(I)return i/I}function FU(e,g){return oB(e,.5,g)}function*Ptt(e){for(const g of e)yield*g}function EU(e){return Array.from(Ptt(e))}function I0e(e,g){let I,i=-1,n=-1;if(g===void 0)for(const C of e)++n,C!=null&&(I>C||I===void 0&&C>=C)&&(I=C,i=n);else for(let C of e)(C=g(C,++n,e))!=null&&(I>C||I===void 0&&C>=C)&&(I=C,i=n);return i}function Jtt(e,g=Ott){const I=[];let i,n=!1;for(const C of e)n&&I.push(g(i,C)),i=C,n=!0;return I}function Ott(e,g){return[e,g]}function eC(e,g,I){e=+e,g=+g,I=(n=arguments.length)<2?(g=e,e=0,1):n<3?1:+I;for(var i=-1,n=Math.max(0,Math.ceil((g-e)/I))|0,C=new Array(n);++i0:mi(r,r)===0)&&(I=C,n=r,i=!0)}}else for(const n of e)(i?g(n,I)>0:g(n,n)===0)&&(I=n,i=!0);return I}function Utt(e,g=mi){if(g.length===1)return g0e(e,g);let I,i=-1,n=-1;for(const C of e)++n,(i<0?g(C,C)===0:g(C,I)>0)&&(I=C,i=n);return i}function Qtt(e,g){const I=i0e(e,g);return I<0?void 0:I}const jtt=n0e(Math.random);function n0e(e){return function(I,i=0,n=I.length){let C=n-(i=+i);for(;C;){const r=e()*C--|0,o=I[C+i];I[C+i]=I[r+i],I[r+i]=o}return I}}function C0e(e,g){let I=0;if(g===void 0)for(let i of e)(i=+i)&&(I+=i);else{let i=-1;for(let n of e)(n=+g(n,++i,e))&&(I+=n)}return I}function r0e(e){if(!(C=e.length))return[];for(var g=-1,I=XX(e,$tt),i=new Array(I);++gg(I,i,e))}function igt(e,g,I){if(typeof g!="function")throw new TypeError("reducer is not a function");const i=e[Symbol.iterator]();let n,C,r=-1;if(arguments.length<3){if({done:n,value:I}=i.next(),n)return;++r}for(;{done:n,value:C}=i.next(),!n;)I=g(I,C,++r,e);return I}function ngt(e){if(typeof e[Symbol.iterator]!="function")throw new TypeError("values is not iterable");return Array.from(e).reverse()}function Cgt(e,...g){e=new Set(e);for(const I of g)for(const i of I)e.delete(i);return e}function rgt(e,g){const I=g[Symbol.iterator](),i=new Set;for(const n of e){if(i.has(n))return!1;let C,r;for(;({value:C,done:r}=I.next())&&!r;){if(Object.is(n,C))return!1;i.add(C)}}return!0}function ogt(e){return e instanceof Set?e:new Set(e)}function Agt(e,...g){e=new Set(e),g=g.map(ogt);e:for(const I of e)for(const i of g)if(!i.has(I)){e.delete(I);continue e}return e}function o0e(e,g){const I=e[Symbol.iterator](),i=new Set;for(const n of g){if(i.has(n))continue;let C,r;for(;{value:C,done:r}=I.next();){if(r)return!1;if(i.add(C),Object.is(n,C))break}}return!0}function agt(e,g){return o0e(g,e)}function sgt(...e){const g=new Set;for(const I of e)for(const i of I)g.add(i);return g}const lgt=Object.freeze(Object.defineProperty({__proto__:null,Adder:Xi,InternMap:RX,InternSet:Ntt,ascending:mi,bin:Rte,bisect:Ph,bisectCenter:dtt,bisectLeft:utt,bisectRight:Fbe,bisector:G0,count:wT,cross:btt,cumsum:ytt,descending:Ztt,deviation:KU,difference:Cgt,disjoint:rgt,every:egt,extent:h1,fcumsum:Vtt,filter:ggt,fsum:wtt,greatest:Ltt,greatestIndex:Utt,group:Ube,groupSort:xtt,groups:ktt,histogram:Rte,index:Ktt,indexes:Dtt,intersection:Agt,least:_tt,leastIndex:i0e,map:Igt,max:QM,maxIndex:g0e,mean:jM,median:FU,merge:EU,min:XX,minIndex:I0e,nice:qbe,pairs:Jtt,permute:$be,quantile:oB,quantileSorted:t0e,quickselect:xU,range:eC,reduce:igt,reverse:ngt,rollup:Qbe,rollups:Ytt,scan:Qtt,shuffle:jtt,shuffler:n0e,some:tgt,sort:OM,subset:agt,sum:C0e,superset:o0e,thresholdFreedmanDiaconis:Mtt,thresholdScott:ztt,thresholdSturges:e0e,tickIncrement:mS,tickStep:WX,ticks:Ud,transpose:r0e,union:sgt,variance:YU,zip:qtt},Symbol.toStringTag,{value:"Module"}));function no(e,g){switch(arguments.length){case 0:break;case 1:this.range(e);break;default:this.range(g).domain(e);break}return this}function Ls(e,g){switch(arguments.length){case 0:break;case 1:{typeof e=="function"?this.interpolator(e):this.range(e);break}default:{this.domain(e),typeof g=="function"?this.interpolator(g):this.range(g);break}}return this}const $M=Symbol("implicit");function MU(){var e=new RX,g=[],I=[],i=$M;function n(C){let r=e.get(C);if(r===void 0){if(i!==$M)return i;e.set(C,r=g.push(C)-1)}return I[r%I.length]}return n.domain=function(C){if(!arguments.length)return g.slice();g=[],e=new RX;for(const r of C)e.has(r)||e.set(r,g.push(r)-1);return n},n.range=function(C){return arguments.length?(I=Array.from(C),n):I.slice()},n.unknown=function(C){return arguments.length?(i=C,n):i},n.copy=function(){return MU(g,I).unknown(i)},no.apply(n,arguments),n}function fS(){var e=MU().unknown(void 0),g=e.domain,I=e.range,i=0,n=1,C,r,o=!1,A=0,s=0,a=.5;delete e.unknown;function l(){var c=g().length,u=n>8&15|g>>4&240,g>>4&15|g&240,(g&15)<<4|g&15,1):I===8?NV(g>>24&255,g>>16&255,g>>8&255,(g&255)/255):I===4?NV(g>>12&15|g>>8&240,g>>8&15|g>>4&240,g>>4&15|g&240,((g&15)<<4|g&15)/255):null):(g=dgt.exec(e))?new on(g[1],g[2],g[3],1):(g=hgt.exec(e))?new on(g[1]*255/100,g[2]*255/100,g[3]*255/100,1):(g=mgt.exec(e))?NV(g[1],g[2],g[3],g[4]):(g=fgt.exec(e))?NV(g[1]*255/100,g[2]*255/100,g[3]*255/100,g[4]):(g=pgt.exec(e))?Yte(g[1],g[2]/100,g[3]/100,1):(g=bgt.exec(e))?Yte(g[1],g[2]/100,g[3]/100,g[4]):Wte.hasOwnProperty(e)?Tte(Wte[e]):e==="transparent"?new on(NaN,NaN,NaN,0):null}function Tte(e){return new on(e>>16&255,e>>8&255,e&255,1)}function NV(e,g,I,i){return i<=0&&(e=g=I=NaN),new on(e,g,I,i)}function zU(e){return e instanceof Lc||(e=wi(e)),e?(e=e.rgb(),new on(e.r,e.g,e.b,e.opacity)):new on}function db(e,g,I,i){return arguments.length===1?zU(e):new on(e,g,I,i??1)}function on(e,g,I,i){this.r=+e,this.g=+g,this.b=+I,this.opacity=+i}B0(on,db,pS(Lc,{brighter:function(e){return e=e==null?ub:Math.pow(ub,e),new on(this.r*e,this.g*e,this.b*e,this.opacity)},darker:function(e){return e=e==null?Qd:Math.pow(Qd,e),new on(this.r*e,this.g*e,this.b*e,this.opacity)},rgb:function(){return this},displayable:function(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:Nte,formatHex:Nte,formatRgb:kte,toString:kte}));function Nte(){return"#"+$K(this.r)+$K(this.g)+$K(this.b)}function kte(){var e=this.opacity;return e=isNaN(e)?1:Math.max(0,Math.min(1,e)),(e===1?"rgb(":"rgba(")+Math.max(0,Math.min(255,Math.round(this.r)||0))+", "+Math.max(0,Math.min(255,Math.round(this.g)||0))+", "+Math.max(0,Math.min(255,Math.round(this.b)||0))+(e===1?")":", "+e+")")}function $K(e){return e=Math.max(0,Math.min(255,Math.round(e)||0)),(e<16?"0":"")+e.toString(16)}function Yte(e,g,I,i){return i<=0?e=g=I=NaN:I<=0||I>=1?e=g=NaN:g<=0&&(e=NaN),new xA(e,g,I,i)}function a0e(e){if(e instanceof xA)return new xA(e.h,e.s,e.l,e.opacity);if(e instanceof Lc||(e=wi(e)),!e)return new xA;if(e instanceof xA)return e;e=e.rgb();var g=e.r/255,I=e.g/255,i=e.b/255,n=Math.min(g,I,i),C=Math.max(g,I,i),r=NaN,o=C-n,A=(C+n)/2;return o?(g===C?r=(I-i)/o+(I0&&A<1?0:r,new xA(r,o,A,e.opacity)}function s0e(e,g,I,i){return arguments.length===1?a0e(e):new xA(e,g,I,i??1)}function xA(e,g,I,i){this.h=+e,this.s=+g,this.l=+I,this.opacity=+i}B0(xA,s0e,pS(Lc,{brighter:function(e){return e=e==null?ub:Math.pow(ub,e),new xA(this.h,this.s,this.l*e,this.opacity)},darker:function(e){return e=e==null?Qd:Math.pow(Qd,e),new xA(this.h,this.s,this.l*e,this.opacity)},rgb:function(){var e=this.h%360+(this.h<0)*360,g=isNaN(e)||isNaN(this.s)?0:this.s,I=this.l,i=I+(I<.5?I:1-I)*g,n=2*I-i;return new on(qK(e>=240?e-240:e+120,n,i),qK(e,n,i),qK(e<120?e+240:e-120,n,i),this.opacity)},displayable:function(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl:function(){var e=this.opacity;return e=isNaN(e)?1:Math.max(0,Math.min(1,e)),(e===1?"hsl(":"hsla(")+(this.h||0)+", "+(this.s||0)*100+"%, "+(this.l||0)*100+"%"+(e===1?")":", "+e+")")}}));function qK(e,g,I){return(e<60?g+(I-g)*e/60:e<180?I:e<240?g+(I-g)*(240-e)/60:g)*255}const l0e=Math.PI/180,c0e=180/Math.PI,HX=18,u0e=.96422,d0e=1,h0e=.82521,m0e=4/29,fp=6/29,f0e=3*fp*fp,Zgt=fp*fp*fp;function p0e(e){if(e instanceof tA)return new tA(e.l,e.a,e.b,e.opacity);if(e instanceof $A)return G0e(e);e instanceof on||(e=zU(e));var g=I5(e.r),I=I5(e.g),i=I5(e.b),n=e5((.2225045*g+.7168786*I+.0606169*i)/d0e),C,r;return g===I&&I===i?C=r=n:(C=e5((.4360747*g+.3850649*I+.1430804*i)/u0e),r=e5((.0139322*g+.0971045*I+.7141733*i)/h0e)),new tA(116*n-16,500*(C-n),200*(n-r),e.opacity)}function Ggt(e,g){return new tA(e,0,0,g??1)}function b0e(e,g,I,i){return arguments.length===1?p0e(e):new tA(e,g,I,i??1)}function tA(e,g,I,i){this.l=+e,this.a=+g,this.b=+I,this.opacity=+i}B0(tA,b0e,pS(Lc,{brighter:function(e){return new tA(this.l+HX*(e??1),this.a,this.b,this.opacity)},darker:function(e){return new tA(this.l-HX*(e??1),this.a,this.b,this.opacity)},rgb:function(){var e=(this.l+16)/116,g=isNaN(this.a)?e:e+this.a/500,I=isNaN(this.b)?e:e-this.b/200;return g=u0e*t5(g),e=d0e*t5(e),I=h0e*t5(I),new on(g5(3.1338561*g-1.6168667*e-.4906146*I),g5(-.9787684*g+1.9161415*e+.033454*I),g5(.0719453*g-.2289914*e+1.4052427*I),this.opacity)}}));function e5(e){return e>Zgt?Math.pow(e,1/3):e/f0e+m0e}function t5(e){return e>fp?e*e*e:f0e*(e-m0e)}function g5(e){return 255*(e<=.0031308?12.92*e:1.055*Math.pow(e,1/2.4)-.055)}function I5(e){return(e/=255)<=.04045?e/12.92:Math.pow((e+.055)/1.055,2.4)}function y0e(e){if(e instanceof $A)return new $A(e.h,e.c,e.l,e.opacity);if(e instanceof tA||(e=p0e(e)),e.a===0&&e.b===0)return new $A(NaN,0()=>e;function wgt(e,g){return function(I){return e+I*g}}function Vgt(e,g,I){return e=Math.pow(e,I),g=Math.pow(g,I)-e,I=1/I,function(i){return Math.pow(e+i*g,I)}}function Rgt(e){return(e=+e)==1?S0e:function(g,I){return I-g?Vgt(g,I,e):OU(isNaN(g)?I:g)}}function S0e(e,g){var I=g-e;return I?wgt(e,I):OU(isNaN(e)?g:e)}const hb=function e(g){var I=Rgt(g);function i(n,C){var r=I((n=db(n)).r,(C=db(C)).r),o=I(n.g,C.g),A=I(n.b,C.b),s=S0e(n.opacity,C.opacity);return function(a){return n.r=r(a),n.g=o(a),n.b=A(a),n.opacity=s(a),n+""}}return i.gamma=e,i}(1);function Wgt(e,g){g||(g=[]);var I=e?Math.min(g.length,e.length):0,i=g.slice(),n;return function(C){for(n=0;nI&&(C=g.slice(I,C),o[r]?o[r]+=C:o[++r]=C),(i=i[0])===(n=n[0])?o[r]?o[r]+=n:o[++r]=n:(o[++r]=null,A.push({i:r,x:Kr(i,n)})),I=i5.lastIndex;return I180?a+=360:a-s>180&&(s+=360),c.push({i:l.push(n(l)+"rotate(",null,i)-2,x:Kr(s,a)})):a&&l.push(n(l)+"rotate("+a+i)}function o(s,a,l,c){s!==a?c.push({i:l.push(n(l)+"skewX(",null,i)-2,x:Kr(s,a)}):a&&l.push(n(l)+"skewX("+a+i)}function A(s,a,l,c,u,d){if(s!==l||a!==c){var h=u.push(n(u)+"scale(",null,",",null,")");d.push({i:h-4,x:Kr(s,l)},{i:h-2,x:Kr(a,c)})}else(l!==1||c!==1)&&u.push(n(u)+"scale("+l+","+c+")")}return function(s,a){var l=[],c=[];return s=e(s),a=e(a),C(s.translateX,s.translateY,a.translateX,a.translateY,l,c),r(s.rotate,a.rotate,l,c),o(s.skewX,a.skewX,l,c),A(s.scaleX,s.scaleY,a.scaleX,a.scaleY,l,c),s=a=null,function(u){for(var d=-1,h=c.length,m;++dg&&(I=e,e=g,g=I),function(i){return Math.max(e,Math.min(g,i))}}function Ogt(e,g,I){var i=e[0],n=e[1],C=g[0],r=g[1];return n2?_gt:Ogt,A=s=null,l}function l(c){return c==null||isNaN(c=+c)?C:(A||(A=o(e.map(i),g,I)))(i(r(c)))}return l.invert=function(c){return r(n((s||(s=o(g,e.map(i),Kr)))(c)))},l.domain=function(c){return arguments.length?(e=Array.from(c,TX),a()):e.slice()},l.range=function(c){return arguments.length?(g=Array.from(c),a()):g.slice()},l.rangeRound=function(c){return g=Array.from(c),I=LU,a()},l.clamp=function(c){return arguments.length?(r=c?!0:tC,a()):r!==tC},l.interpolate=function(c){return arguments.length?(I=c,a()):I},l.unknown=function(c){return arguments.length?(C=c,l):C},function(c,u){return i=c,n=u,a()}}function UU(){return RT()(tC,tC)}function Lgt(e){return Math.abs(e=Math.round(e))>=1e21?e.toLocaleString("en").replace(/,/g,""):e.toString(10)}function NX(e,g){if((I=(e=g?e.toExponential(g-1):e.toExponential()).indexOf("e"))<0)return null;var I,i=e.slice(0,I);return[i.length>1?i[0]+i.slice(2):i,+e.slice(I+1)]}function mb(e){return e=NX(Math.abs(e)),e?e[1]:NaN}function Ugt(e,g){return function(I,i){for(var n=I.length,C=[],r=0,o=e[0],A=0;n>0&&o>0&&(A+o+1>i&&(o=Math.max(1,i-A)),C.push(I.substring(n-=o,n+o)),!((A+=o+1)>i));)o=e[r=(r+1)%e.length];return C.reverse().join(g)}}function Qgt(e){return function(g){return g.replace(/[0-9]/g,function(I){return e[+I]})}}var jgt=/^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;function fb(e){if(!(g=jgt.exec(e)))throw new Error("invalid format: "+e);var g;return new WT({fill:g[1],align:g[2],sign:g[3],symbol:g[4],zero:g[5],width:g[6],comma:g[7],precision:g[8]&&g[8].slice(1),trim:g[9],type:g[10]})}fb.prototype=WT.prototype;function WT(e){this.fill=e.fill===void 0?" ":e.fill+"",this.align=e.align===void 0?">":e.align+"",this.sign=e.sign===void 0?"-":e.sign+"",this.symbol=e.symbol===void 0?"":e.symbol+"",this.zero=!!e.zero,this.width=e.width===void 0?void 0:+e.width,this.comma=!!e.comma,this.precision=e.precision===void 0?void 0:+e.precision,this.trim=!!e.trim,this.type=e.type===void 0?"":e.type+""}WT.prototype.toString=function(){return this.fill+this.align+this.sign+this.symbol+(this.zero?"0":"")+(this.width===void 0?"":Math.max(1,this.width|0))+(this.comma?",":"")+(this.precision===void 0?"":"."+Math.max(0,this.precision|0))+(this.trim?"~":"")+this.type};function $gt(e){e:for(var g=e.length,I=1,i=-1,n;I0&&(i=0);break}return i>0?e.slice(0,i)+e.slice(n+1):e}var X0e;function qgt(e,g){var I=NX(e,g);if(!I)return e+"";var i=I[0],n=I[1],C=n-(X0e=Math.max(-8,Math.min(8,Math.floor(n/3)))*3)+1,r=i.length;return C===r?i:C>r?i+new Array(C-r+1).join("0"):C>0?i.slice(0,C)+"."+i.slice(C):"0."+new Array(1-C).join("0")+NX(e,Math.max(0,g+C-1))[0]}function zte(e,g){var I=NX(e,g);if(!I)return e+"";var i=I[0],n=I[1];return n<0?"0."+new Array(-n).join("0")+i:i.length>n+1?i.slice(0,n+1)+"."+i.slice(n+1):i+new Array(n-i.length+2).join("0")}const Pte={"%":(e,g)=>(e*100).toFixed(g),b:e=>Math.round(e).toString(2),c:e=>e+"",d:Lgt,e:(e,g)=>e.toExponential(g),f:(e,g)=>e.toFixed(g),g:(e,g)=>e.toPrecision(g),o:e=>Math.round(e).toString(8),p:(e,g)=>zte(e*100,g),r:zte,s:qgt,X:e=>Math.round(e).toString(16).toUpperCase(),x:e=>Math.round(e).toString(16)};function Jte(e){return e}var Ote=Array.prototype.map,_te=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"];function H0e(e){var g=e.grouping===void 0||e.thousands===void 0?Jte:Ugt(Ote.call(e.grouping,Number),e.thousands+""),I=e.currency===void 0?"":e.currency[0]+"",i=e.currency===void 0?"":e.currency[1]+"",n=e.decimal===void 0?".":e.decimal+"",C=e.numerals===void 0?Jte:Qgt(Ote.call(e.numerals,String)),r=e.percent===void 0?"%":e.percent+"",o=e.minus===void 0?"−":e.minus+"",A=e.nan===void 0?"NaN":e.nan+"";function s(l){l=fb(l);var c=l.fill,u=l.align,d=l.sign,h=l.symbol,m=l.zero,f=l.width,b=l.comma,p=l.precision,y=l.trim,Z=l.type;Z==="n"?(b=!0,Z="g"):Pte[Z]||(p===void 0&&(p=12),y=!0,Z="g"),(m||c==="0"&&u==="=")&&(m=!0,c="0",u="=");var B=h==="$"?I:h==="#"&&/[boxX]/.test(Z)?"0"+Z.toLowerCase():"",G=h==="$"?i:/[%p]/.test(Z)?r:"",v=Pte[Z],w=/[defgprs%]/.test(Z);p=p===void 0?6:/[gprs]/.test(Z)?Math.max(1,Math.min(21,p)):Math.max(0,Math.min(20,p));function V(S){var X=B,W=G,R,H,Y;if(Z==="c")W=v(S)+W,S="";else{S=+S;var D=S<0||1/S<0;if(S=isNaN(S)?A:v(Math.abs(S),p),y&&(S=$gt(S)),D&&+S==0&&d!=="+"&&(D=!1),X=(D?d==="("?d:o:d==="-"||d==="("?"":d)+X,W=(Z==="s"?_te[8+X0e/3]:"")+W+(D&&d==="("?")":""),w){for(R=-1,H=S.length;++RY||Y>57){W=(Y===46?n+S.slice(R+1):S.slice(R))+W,S=S.slice(0,R);break}}}b&&!m&&(S=g(S,1/0));var E=X.length+S.length+W.length,O=E>1)+X+S+W+O.slice(E);break;default:S=O+X+S+W;break}return C(S)}return V.toString=function(){return l+""},V}function a(l,c){var u=s((l=fb(l),l.type="f",l)),d=Math.max(-8,Math.min(8,Math.floor(mb(c)/3)))*3,h=Math.pow(10,-d),m=_te[8+d/3];return function(f){return u(h*f)+m}}return{format:s,formatPrefix:a}}var YV,Ar,Oh;T0e({thousands:",",grouping:[3],currency:["$",""]});function T0e(e){return YV=H0e(e),Ar=YV.format,Oh=YV.formatPrefix,YV}function N0e(e){return Math.max(0,-mb(Math.abs(e)))}function S0(e,g){return Math.max(0,Math.max(-8,Math.min(8,Math.floor(mb(g)/3)))*3-mb(Math.abs(e)))}function k0e(e,g){return e=Math.abs(e),g=Math.abs(g)-e,Math.max(0,mb(g)-mb(e))+1}const eIt=Object.freeze(Object.defineProperty({__proto__:null,FormatSpecifier:WT,get format(){return Ar},formatDefaultLocale:T0e,formatLocale:H0e,get formatPrefix(){return Oh},formatSpecifier:fb,precisionFixed:N0e,precisionPrefix:S0,precisionRound:k0e},Symbol.toStringTag,{value:"Module"}));function Y0e(e,g,I,i){var n=WX(e,g,I),C;switch(i=fb(i??",f"),i.type){case"s":{var r=Math.max(Math.abs(e),Math.abs(g));return i.precision==null&&!isNaN(C=S0(n,r))&&(i.precision=C),Oh(i,r)}case"":case"e":case"g":case"p":case"r":{i.precision==null&&!isNaN(C=k0e(n,Math.max(Math.abs(e),Math.abs(g))))&&(i.precision=C-(i.type==="e"));break}case"f":case"%":{i.precision==null&&!isNaN(C=N0e(n))&&(i.precision=C-(i.type==="%")*2);break}}return Ar(i)}function Uc(e){var g=e.domain;return e.ticks=function(I){var i=g();return Ud(i[0],i[i.length-1],I??10)},e.tickFormat=function(I,i){var n=g();return Y0e(n[0],n[n.length-1],I??10,i)},e.nice=function(I){I==null&&(I=10);var i=g(),n=0,C=i.length-1,r=i[n],o=i[C],A,s,a=10;for(o0;){if(s=mS(r,o,I),s===A)return i[n]=r,i[C]=o,g(i);if(s>0)r=Math.floor(r/s)*s,o=Math.ceil(o/s)*s;else if(s<0)r=Math.ceil(r*s)/s,o=Math.floor(o*s)/s;else break;A=s}return e},e}function qt(){var e=UU();return e.copy=function(){return bS(e,qt())},no.apply(e,arguments),Uc(e)}function K0e(e){var g;function I(i){return i==null||isNaN(i=+i)?g:i}return I.invert=I,I.domain=I.range=function(i){return arguments.length?(e=Array.from(i,TX),I):e.slice()},I.unknown=function(i){return arguments.length?(g=i,I):g},I.copy=function(){return K0e(e).unknown(g)},e=arguments.length?Array.from(e,TX):[0,1],Uc(I)}function D0e(e,g){e=e.slice();var I=0,i=e.length-1,n=e[I],C=e[i],r;return CMath.pow(e,g)}function nIt(e){return e===Math.E?Math.log:e===10&&Math.log10||e===2&&Math.log2||(e=Math.log(e),g=>Math.log(g)/e)}function Qte(e){return(g,I)=>-e(-g,I)}function QU(e){const g=e(Lte,Ute),I=g.domain;let i=10,n,C;function r(){return n=nIt(i),C=iIt(i),I()[0]<0?(n=Qte(n),C=Qte(C),e(tIt,gIt)):e(Lte,Ute),g}return g.base=function(o){return arguments.length?(i=+o,r()):i},g.domain=function(o){return arguments.length?(I(o),r()):I()},g.ticks=o=>{const A=I();let s=A[0],a=A[A.length-1];const l=a0){for(;c<=u;++c)for(d=1;da)break;f.push(h)}}else for(;c<=u;++c)for(d=i-1;d>=1;--d)if(h=c>0?d/C(-c):d*C(c),!(ha)break;f.push(h)}f.length*2{if(o==null&&(o=10),A==null&&(A=i===10?"s":","),typeof A!="function"&&(!(i%1)&&(A=fb(A)).precision==null&&(A.trim=!0),A=Ar(A)),o===1/0)return A;const s=Math.max(1,i*o/g.ticks().length);return a=>{let l=a/C(Math.round(n(a)));return l*iI(D0e(I(),{floor:o=>C(Math.floor(n(o))),ceil:o=>C(Math.ceil(n(o)))})),g}function Qc(){const e=QU(RT()).domain([1,10]);return e.copy=()=>bS(e,Qc()).base(e.base()),no.apply(e,arguments),e}function jte(e){return function(g){return Math.sign(g)*Math.log1p(Math.abs(g/e))}}function $te(e){return function(g){return Math.sign(g)*Math.expm1(Math.abs(g))*e}}function jU(e){var g=1,I=e(jte(g),$te(g));return I.constant=function(i){return arguments.length?e(jte(g=+i),$te(g)):g},Uc(I)}function x0e(){var e=jU(RT());return e.copy=function(){return bS(e,x0e()).constant(e.constant())},no.apply(e,arguments)}function qte(e){return function(g){return g<0?-Math.pow(-g,e):Math.pow(g,e)}}function CIt(e){return e<0?-Math.sqrt(-e):Math.sqrt(e)}function rIt(e){return e<0?-e*e:e*e}function $U(e){var g=e(tC,tC),I=1;function i(){return I===1?e(tC,tC):I===.5?e(CIt,rIt):e(qte(I),qte(1/I))}return g.exponent=function(n){return arguments.length?(I=+n,i()):I},Uc(g)}function qU(){var e=$U(RT());return e.copy=function(){return bS(e,qU()).exponent(e.exponent())},no.apply(e,arguments),e}function oIt(){return qU.apply(null,arguments).exponent(.5)}function ege(e){return Math.sign(e)*e*e}function AIt(e){return Math.sign(e)*Math.sqrt(Math.abs(e))}function F0e(){var e=UU(),g=[0,1],I=!1,i;function n(C){var r=AIt(e(C));return isNaN(r)?i:I?Math.round(r):r}return n.invert=function(C){return e.invert(ege(C))},n.domain=function(C){return arguments.length?(e.domain(C),n):e.domain()},n.range=function(C){return arguments.length?(e.range((g=Array.from(C,TX)).map(ege)),n):g.slice()},n.rangeRound=function(C){return n.range(C).round(!0)},n.round=function(C){return arguments.length?(I=!!C,n):I},n.clamp=function(C){return arguments.length?(e.clamp(C),n):e.clamp()},n.unknown=function(C){return arguments.length?(i=C,n):i},n.copy=function(){return F0e(e.domain(),g).round(I).clamp(e.clamp()).unknown(i)},no.apply(n,arguments),Uc(n)}function kX(){var e=[],g=[],I=[],i;function n(){var r=0,o=Math.max(1,g.length);for(I=new Array(o-1);++r0?I[o-1]:e[0],o=I?[i[I-1],g]:[i[s-1],i[s]]},r.unknown=function(A){return arguments.length&&(C=A),r},r.thresholds=function(){return i.slice()},r.copy=function(){return E0e().domain([e,g]).range(n).unknown(C)},no.apply(Uc(r),arguments)}function M0e(){var e=[.5],g=[0,1],I,i=1;function n(C){return C!=null&&C<=C?g[Ph(e,C,0,i)]:I}return n.domain=function(C){return arguments.length?(e=Array.from(C),i=Math.min(e.length,g.length-1),n):e.slice()},n.range=function(C){return arguments.length?(g=Array.from(C),i=Math.min(e.length,g.length-1),n):g.slice()},n.invertExtent=function(C){var r=g.indexOf(C);return[e[r-1],e[r]]},n.unknown=function(C){return arguments.length?(I=C,n):I},n.copy=function(){return M0e().domain(e).range(g).unknown(I)},no.apply(n,arguments)}const n5=new Date,C5=new Date;function Ti(e,g,I,i){function n(C){return e(C=arguments.length===0?new Date:new Date(+C)),C}return n.floor=C=>(e(C=new Date(+C)),C),n.ceil=C=>(e(C=new Date(C-1)),g(C,1),e(C),C),n.round=C=>{const r=n(C),o=n.ceil(C);return C-r(g(C=new Date(+C),r==null?1:Math.floor(r)),C),n.range=(C,r,o)=>{const A=[];if(C=n.ceil(C),o=o==null?1:Math.floor(o),!(C0))return A;let s;do A.push(s=new Date(+C)),g(C,o),e(C);while(sTi(r=>{if(r>=r)for(;e(r),!C(r);)r.setTime(r-1)},(r,o)=>{if(r>=r)if(o<0)for(;++o<=0;)for(;g(r,-1),!C(r););else for(;--o>=0;)for(;g(r,1),!C(r););}),I&&(n.count=(C,r)=>(n5.setTime(+C),C5.setTime(+r),e(n5),e(C5),Math.floor(I(n5,C5))),n.every=C=>(C=Math.floor(C),!isFinite(C)||!(C>0)?null:C>1?n.filter(i?r=>i(r)%C===0:r=>n.count(0,r)%C===0):n)),n}const YX=Ti(()=>{},(e,g)=>{e.setTime(+e+g)},(e,g)=>g-e);YX.every=e=>(e=Math.floor(e),!isFinite(e)||!(e>0)?null:e>1?Ti(g=>{g.setTime(Math.floor(g/e)*e)},(g,I)=>{g.setTime(+g+I*e)},(g,I)=>(I-g)/e):YX);YX.range;const os=1e3,Pr=os*60,As=Pr*60,Ns=As*24,e7=Ns*7,tge=Ns*30,r5=Ns*365,ed=Ti(e=>{e.setTime(e-e.getMilliseconds())},(e,g)=>{e.setTime(+e+g*os)},(e,g)=>(g-e)/os,e=>e.getUTCSeconds());ed.range;const t7=Ti(e=>{e.setTime(e-e.getMilliseconds()-e.getSeconds()*os)},(e,g)=>{e.setTime(+e+g*Pr)},(e,g)=>(g-e)/Pr,e=>e.getMinutes());t7.range;const g7=Ti(e=>{e.setUTCSeconds(0,0)},(e,g)=>{e.setTime(+e+g*Pr)},(e,g)=>(g-e)/Pr,e=>e.getUTCMinutes());g7.range;const I7=Ti(e=>{e.setTime(e-e.getMilliseconds()-e.getSeconds()*os-e.getMinutes()*Pr)},(e,g)=>{e.setTime(+e+g*As)},(e,g)=>(g-e)/As,e=>e.getHours());I7.range;const i7=Ti(e=>{e.setUTCMinutes(0,0,0)},(e,g)=>{e.setTime(+e+g*As)},(e,g)=>(g-e)/As,e=>e.getUTCHours());i7.range;const yS=Ti(e=>e.setHours(0,0,0,0),(e,g)=>e.setDate(e.getDate()+g),(e,g)=>(g-e-(g.getTimezoneOffset()-e.getTimezoneOffset())*Pr)/Ns,e=>e.getDate()-1);yS.range;const XT=Ti(e=>{e.setUTCHours(0,0,0,0)},(e,g)=>{e.setUTCDate(e.getUTCDate()+g)},(e,g)=>(g-e)/Ns,e=>e.getUTCDate()-1);XT.range;const z0e=Ti(e=>{e.setUTCHours(0,0,0,0)},(e,g)=>{e.setUTCDate(e.getUTCDate()+g)},(e,g)=>(g-e)/Ns,e=>Math.floor(e/Ns));z0e.range;function _h(e){return Ti(g=>{g.setDate(g.getDate()-(g.getDay()+7-e)%7),g.setHours(0,0,0,0)},(g,I)=>{g.setDate(g.getDate()+I*7)},(g,I)=>(I-g-(I.getTimezoneOffset()-g.getTimezoneOffset())*Pr)/e7)}const HT=_h(0),KX=_h(1),aIt=_h(2),sIt=_h(3),pb=_h(4),lIt=_h(5),cIt=_h(6);HT.range;KX.range;aIt.range;sIt.range;pb.range;lIt.range;cIt.range;function Lh(e){return Ti(g=>{g.setUTCDate(g.getUTCDate()-(g.getUTCDay()+7-e)%7),g.setUTCHours(0,0,0,0)},(g,I)=>{g.setUTCDate(g.getUTCDate()+I*7)},(g,I)=>(I-g)/e7)}const TT=Lh(0),DX=Lh(1),uIt=Lh(2),dIt=Lh(3),bb=Lh(4),hIt=Lh(5),mIt=Lh(6);TT.range;DX.range;uIt.range;dIt.range;bb.range;hIt.range;mIt.range;const n7=Ti(e=>{e.setDate(1),e.setHours(0,0,0,0)},(e,g)=>{e.setMonth(e.getMonth()+g)},(e,g)=>g.getMonth()-e.getMonth()+(g.getFullYear()-e.getFullYear())*12,e=>e.getMonth());n7.range;const C7=Ti(e=>{e.setUTCDate(1),e.setUTCHours(0,0,0,0)},(e,g)=>{e.setUTCMonth(e.getUTCMonth()+g)},(e,g)=>g.getUTCMonth()-e.getUTCMonth()+(g.getUTCFullYear()-e.getUTCFullYear())*12,e=>e.getUTCMonth());C7.range;const ks=Ti(e=>{e.setMonth(0,1),e.setHours(0,0,0,0)},(e,g)=>{e.setFullYear(e.getFullYear()+g)},(e,g)=>g.getFullYear()-e.getFullYear(),e=>e.getFullYear());ks.every=e=>!isFinite(e=Math.floor(e))||!(e>0)?null:Ti(g=>{g.setFullYear(Math.floor(g.getFullYear()/e)*e),g.setMonth(0,1),g.setHours(0,0,0,0)},(g,I)=>{g.setFullYear(g.getFullYear()+I*e)});ks.range;const Ys=Ti(e=>{e.setUTCMonth(0,1),e.setUTCHours(0,0,0,0)},(e,g)=>{e.setUTCFullYear(e.getUTCFullYear()+g)},(e,g)=>g.getUTCFullYear()-e.getUTCFullYear(),e=>e.getUTCFullYear());Ys.every=e=>!isFinite(e=Math.floor(e))||!(e>0)?null:Ti(g=>{g.setUTCFullYear(Math.floor(g.getUTCFullYear()/e)*e),g.setUTCMonth(0,1),g.setUTCHours(0,0,0,0)},(g,I)=>{g.setUTCFullYear(g.getUTCFullYear()+I*e)});Ys.range;function P0e(e,g,I,i,n,C){const r=[[ed,1,os],[ed,5,5*os],[ed,15,15*os],[ed,30,30*os],[C,1,Pr],[C,5,5*Pr],[C,15,15*Pr],[C,30,30*Pr],[n,1,As],[n,3,3*As],[n,6,6*As],[n,12,12*As],[i,1,Ns],[i,2,2*Ns],[I,1,e7],[g,1,tge],[g,3,3*tge],[e,1,r5]];function o(s,a,l){const c=am).right(r,c);if(u===r.length)return e.every(WX(s/r5,a/r5,l));if(u===0)return YX.every(Math.max(WX(s,a,l),1));const[d,h]=r[c/r[u-1][2]53)return null;"w"in Be||(Be.w=1),"Z"in Be?(Se=A5(Ny(Be.y,0,1)),Pe=Se.getUTCDay(),Se=Pe>4||Pe===0?DX.ceil(Se):DX(Se),Se=XT.offset(Se,(Be.V-1)*7),Be.y=Se.getUTCFullYear(),Be.m=Se.getUTCMonth(),Be.d=Se.getUTCDate()+(Be.w+6)%7):(Se=o5(Ny(Be.y,0,1)),Pe=Se.getDay(),Se=Pe>4||Pe===0?KX.ceil(Se):KX(Se),Se=yS.offset(Se,(Be.V-1)*7),Be.y=Se.getFullYear(),Be.m=Se.getMonth(),Be.d=Se.getDate()+(Be.w+6)%7)}else("W"in Be||"U"in Be)&&("w"in Be||(Be.w="u"in Be?Be.u%7:"W"in Be?1:0),Pe="Z"in Be?A5(Ny(Be.y,0,1)).getUTCDay():o5(Ny(Be.y,0,1)).getDay(),Be.m=0,Be.d="W"in Be?(Be.w+6)%7+Be.W*7-(Pe+5)%7:Be.w+Be.U*7-(Pe+6)%7);return"Z"in Be?(Be.H+=Be.Z/100|0,Be.M+=Be.Z%100,A5(Be)):o5(Be)}}function v(Ce,Ze,Ge,Be){for(var Ne=0,Se=Ze.length,Pe=Ge.length,ze,Fe;Ne=Pe)return-1;if(ze=Ze.charCodeAt(Ne++),ze===37){if(ze=Ze.charAt(Ne++),Fe=Z[ze in gge?Ze.charAt(Ne++):ze],!Fe||(Be=Fe(Ce,Ge,Be))<0)return-1}else if(ze!=Ge.charCodeAt(Be++))return-1}return Be}function w(Ce,Ze,Ge){var Be=s.exec(Ze.slice(Ge));return Be?(Ce.p=a.get(Be[0].toLowerCase()),Ge+Be[0].length):-1}function V(Ce,Ze,Ge){var Be=u.exec(Ze.slice(Ge));return Be?(Ce.w=d.get(Be[0].toLowerCase()),Ge+Be[0].length):-1}function S(Ce,Ze,Ge){var Be=l.exec(Ze.slice(Ge));return Be?(Ce.w=c.get(Be[0].toLowerCase()),Ge+Be[0].length):-1}function X(Ce,Ze,Ge){var Be=f.exec(Ze.slice(Ge));return Be?(Ce.m=b.get(Be[0].toLowerCase()),Ge+Be[0].length):-1}function W(Ce,Ze,Ge){var Be=h.exec(Ze.slice(Ge));return Be?(Ce.m=m.get(Be[0].toLowerCase()),Ge+Be[0].length):-1}function R(Ce,Ze,Ge){return v(Ce,g,Ze,Ge)}function H(Ce,Ze,Ge){return v(Ce,I,Ze,Ge)}function Y(Ce,Ze,Ge){return v(Ce,i,Ze,Ge)}function D(Ce){return r[Ce.getDay()]}function E(Ce){return C[Ce.getDay()]}function O(Ce){return A[Ce.getMonth()]}function J(Ce){return o[Ce.getMonth()]}function ee(Ce){return n[+(Ce.getHours()>=12)]}function q(Ce){return 1+~~(Ce.getMonth()/3)}function $(Ce){return r[Ce.getUTCDay()]}function j(Ce){return C[Ce.getUTCDay()]}function te(Ce){return A[Ce.getUTCMonth()]}function U(Ce){return o[Ce.getUTCMonth()]}function ie(Ce){return n[+(Ce.getUTCHours()>=12)]}function me(Ce){return 1+~~(Ce.getUTCMonth()/3)}return{format:function(Ce){var Ze=B(Ce+="",p);return Ze.toString=function(){return Ce},Ze},parse:function(Ce){var Ze=G(Ce+="",!1);return Ze.toString=function(){return Ce},Ze},utcFormat:function(Ce){var Ze=B(Ce+="",y);return Ze.toString=function(){return Ce},Ze},utcParse:function(Ce){var Ze=G(Ce+="",!0);return Ze.toString=function(){return Ce},Ze}}}var gge={"-":"",_:" ",0:"0"},_i=/^\s*\d+/,GIt=/^%/,vIt=/[\\^$*+?|[\]().{}]/g;function Tg(e,g,I){var i=e<0?"-":"",n=(i?-e:e)+"",C=n.length;return i+(C[g.toLowerCase(),I]))}function SIt(e,g,I){var i=_i.exec(g.slice(I,I+1));return i?(e.w=+i[0],I+i[0].length):-1}function wIt(e,g,I){var i=_i.exec(g.slice(I,I+1));return i?(e.u=+i[0],I+i[0].length):-1}function VIt(e,g,I){var i=_i.exec(g.slice(I,I+2));return i?(e.U=+i[0],I+i[0].length):-1}function RIt(e,g,I){var i=_i.exec(g.slice(I,I+2));return i?(e.V=+i[0],I+i[0].length):-1}function WIt(e,g,I){var i=_i.exec(g.slice(I,I+2));return i?(e.W=+i[0],I+i[0].length):-1}function Ige(e,g,I){var i=_i.exec(g.slice(I,I+4));return i?(e.y=+i[0],I+i[0].length):-1}function ige(e,g,I){var i=_i.exec(g.slice(I,I+2));return i?(e.y=+i[0]+(+i[0]>68?1900:2e3),I+i[0].length):-1}function XIt(e,g,I){var i=/^(Z)|([+-]\d\d)(?::?(\d\d))?/.exec(g.slice(I,I+6));return i?(e.Z=i[1]?0:-(i[2]+(i[3]||"00")),I+i[0].length):-1}function HIt(e,g,I){var i=_i.exec(g.slice(I,I+1));return i?(e.q=i[0]*3-3,I+i[0].length):-1}function TIt(e,g,I){var i=_i.exec(g.slice(I,I+2));return i?(e.m=i[0]-1,I+i[0].length):-1}function nge(e,g,I){var i=_i.exec(g.slice(I,I+2));return i?(e.d=+i[0],I+i[0].length):-1}function NIt(e,g,I){var i=_i.exec(g.slice(I,I+3));return i?(e.m=0,e.d=+i[0],I+i[0].length):-1}function Cge(e,g,I){var i=_i.exec(g.slice(I,I+2));return i?(e.H=+i[0],I+i[0].length):-1}function kIt(e,g,I){var i=_i.exec(g.slice(I,I+2));return i?(e.M=+i[0],I+i[0].length):-1}function YIt(e,g,I){var i=_i.exec(g.slice(I,I+2));return i?(e.S=+i[0],I+i[0].length):-1}function KIt(e,g,I){var i=_i.exec(g.slice(I,I+3));return i?(e.L=+i[0],I+i[0].length):-1}function DIt(e,g,I){var i=_i.exec(g.slice(I,I+6));return i?(e.L=Math.floor(i[0]/1e3),I+i[0].length):-1}function xIt(e,g,I){var i=GIt.exec(g.slice(I,I+1));return i?I+i[0].length:-1}function FIt(e,g,I){var i=_i.exec(g.slice(I));return i?(e.Q=+i[0],I+i[0].length):-1}function EIt(e,g,I){var i=_i.exec(g.slice(I));return i?(e.s=+i[0],I+i[0].length):-1}function rge(e,g){return Tg(e.getDate(),g,2)}function MIt(e,g){return Tg(e.getHours(),g,2)}function zIt(e,g){return Tg(e.getHours()%12||12,g,2)}function PIt(e,g){return Tg(1+yS.count(ks(e),e),g,3)}function J0e(e,g){return Tg(e.getMilliseconds(),g,3)}function JIt(e,g){return J0e(e,g)+"000"}function OIt(e,g){return Tg(e.getMonth()+1,g,2)}function _It(e,g){return Tg(e.getMinutes(),g,2)}function LIt(e,g){return Tg(e.getSeconds(),g,2)}function UIt(e){var g=e.getDay();return g===0?7:g}function QIt(e,g){return Tg(HT.count(ks(e)-1,e),g,2)}function O0e(e){var g=e.getDay();return g>=4||g===0?pb(e):pb.ceil(e)}function jIt(e,g){return e=O0e(e),Tg(pb.count(ks(e),e)+(ks(e).getDay()===4),g,2)}function $It(e){return e.getDay()}function qIt(e,g){return Tg(KX.count(ks(e)-1,e),g,2)}function eit(e,g){return Tg(e.getFullYear()%100,g,2)}function tit(e,g){return e=O0e(e),Tg(e.getFullYear()%100,g,2)}function git(e,g){return Tg(e.getFullYear()%1e4,g,4)}function Iit(e,g){var I=e.getDay();return e=I>=4||I===0?pb(e):pb.ceil(e),Tg(e.getFullYear()%1e4,g,4)}function iit(e){var g=e.getTimezoneOffset();return(g>0?"-":(g*=-1,"+"))+Tg(g/60|0,"0",2)+Tg(g%60,"0",2)}function oge(e,g){return Tg(e.getUTCDate(),g,2)}function nit(e,g){return Tg(e.getUTCHours(),g,2)}function Cit(e,g){return Tg(e.getUTCHours()%12||12,g,2)}function rit(e,g){return Tg(1+XT.count(Ys(e),e),g,3)}function _0e(e,g){return Tg(e.getUTCMilliseconds(),g,3)}function oit(e,g){return _0e(e,g)+"000"}function Ait(e,g){return Tg(e.getUTCMonth()+1,g,2)}function ait(e,g){return Tg(e.getUTCMinutes(),g,2)}function sit(e,g){return Tg(e.getUTCSeconds(),g,2)}function lit(e){var g=e.getUTCDay();return g===0?7:g}function cit(e,g){return Tg(TT.count(Ys(e)-1,e),g,2)}function L0e(e){var g=e.getUTCDay();return g>=4||g===0?bb(e):bb.ceil(e)}function uit(e,g){return e=L0e(e),Tg(bb.count(Ys(e),e)+(Ys(e).getUTCDay()===4),g,2)}function dit(e){return e.getUTCDay()}function hit(e,g){return Tg(DX.count(Ys(e)-1,e),g,2)}function mit(e,g){return Tg(e.getUTCFullYear()%100,g,2)}function fit(e,g){return e=L0e(e),Tg(e.getUTCFullYear()%100,g,2)}function pit(e,g){return Tg(e.getUTCFullYear()%1e4,g,4)}function bit(e,g){var I=e.getUTCDay();return e=I>=4||I===0?bb(e):bb.ceil(e),Tg(e.getUTCFullYear()%1e4,g,4)}function yit(){return"+0000"}function Age(){return"%"}function age(e){return+e}function sge(e){return Math.floor(+e/1e3)}var Rm,U0e,Q0e;Zit({dateTime:"%x, %X",date:"%-m/%-d/%Y",time:"%-I:%M:%S %p",periods:["AM","PM"],days:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],shortDays:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],months:["January","February","March","April","May","June","July","August","September","October","November","December"],shortMonths:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]});function Zit(e){return Rm=ZIt(e),U0e=Rm.format,Rm.parse,Q0e=Rm.utcFormat,Rm.utcParse,Rm}function Git(e){return new Date(e)}function vit(e){return e instanceof Date?+e:+new Date(+e)}function r7(e,g,I,i,n,C,r,o,A,s){var a=UU(),l=a.invert,c=a.domain,u=s(".%L"),d=s(":%S"),h=s("%I:%M"),m=s("%I %p"),f=s("%a %d"),b=s("%b %d"),p=s("%B"),y=s("%Y");function Z(B){return(A(B)g(n/(e.length-1)))},I.quantiles=function(i){return Array.from({length:i+1},(n,C)=>oB(e,C/i))},I.copy=function(){return eye(g).domain(e)},Ls.apply(I,arguments)}function kT(){var e=0,g=.5,I=1,i=1,n,C,r,o,A,s=tC,a,l=!1,c;function u(h){return isNaN(h=+h)?c:(h=.5+((h=+a(h))-C)*(i*h1&&arguments[1]!==void 0?arguments[1]:0,I=($i[e[g+0]]+$i[e[g+1]]+$i[e[g+2]]+$i[e[g+3]]+"-"+$i[e[g+4]]+$i[e[g+5]]+"-"+$i[e[g+6]]+$i[e[g+7]]+"-"+$i[e[g+8]]+$i[e[g+9]]+"-"+$i[e[g+10]]+$i[e[g+11]]+$i[e[g+12]]+$i[e[g+13]]+$i[e[g+14]]+$i[e[g+15]]).toLowerCase();if(!YT(I))throw TypeError("Stringified UUID is invalid");return I}var lge,s5,l5=0,c5=0;function Hit(e,g,I){var i=g&&I||0,n=g||new Array(16);e=e||{};var C=e.node||lge,r=e.clockseq!==void 0?e.clockseq:s5;if(C==null||r==null){var o=e.random||(e.rng||iye)();C==null&&(C=lge=[o[0]|1,o[1],o[2],o[3],o[4],o[5]]),r==null&&(r=s5=(o[6]<<8|o[7])&16383)}var A=e.msecs!==void 0?e.msecs:Date.now(),s=e.nsecs!==void 0?e.nsecs:c5+1,a=A-l5+(s-c5)/1e4;if(a<0&&e.clockseq===void 0&&(r=r+1&16383),(a<0||A>l5)&&e.nsecs===void 0&&(s=0),s>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");l5=A,c5=s,s5=r,A+=122192928e5;var l=((A&268435455)*1e4+s)%4294967296;n[i++]=l>>>24&255,n[i++]=l>>>16&255,n[i++]=l>>>8&255,n[i++]=l&255;var c=A/4294967296*1e4&268435455;n[i++]=c>>>8&255,n[i++]=c&255,n[i++]=c>>>24&15|16,n[i++]=c>>>16&255,n[i++]=r>>>8|128,n[i++]=r&255;for(var u=0;u<6;++u)n[i+u]=C[u];return g||KT(n)}function nye(e){if(!YT(e))throw TypeError("Invalid UUID");var g,I=new Uint8Array(16);return I[0]=(g=parseInt(e.slice(0,8),16))>>>24,I[1]=g>>>16&255,I[2]=g>>>8&255,I[3]=g&255,I[4]=(g=parseInt(e.slice(9,13),16))>>>8,I[5]=g&255,I[6]=(g=parseInt(e.slice(14,18),16))>>>8,I[7]=g&255,I[8]=(g=parseInt(e.slice(19,23),16))>>>8,I[9]=g&255,I[10]=(g=parseInt(e.slice(24,36),16))/1099511627776&255,I[11]=g/4294967296&255,I[12]=g>>>24&255,I[13]=g>>>16&255,I[14]=g>>>8&255,I[15]=g&255,I}function Tit(e){e=unescape(encodeURIComponent(e));for(var g=[],I=0;I>5]>>>n%32&255,r=parseInt(i.charAt(C>>>4&15)+i.charAt(C&15),16);g.push(r)}return g}function rye(e){return(e+64>>>9<<4)+14+1}function Dit(e,g){e[g>>5]|=128<>5]|=(e[i/8]&255)<>16)+(g>>16)+(I>>16);return i<<16|I&65535}function Fit(e,g){return e<>>32-g}function DT(e,g,I,i,n,C){return Cc(Fit(Cc(Cc(g,e),Cc(i,C)),n),I)}function pn(e,g,I,i,n,C,r){return DT(g&I|~g&i,e,g,n,C,r)}function bn(e,g,I,i,n,C,r){return DT(g&i|I&~i,e,g,n,C,r)}function yn(e,g,I,i,n,C,r){return DT(g^I^i,e,g,n,C,r)}function Zn(e,g,I,i,n,C,r){return DT(I^(g|~i),e,g,n,C,r)}var Eit=Cye("v3",48,Yit);const Mit=Eit;function zit(e,g,I){e=e||{};var i=e.random||(e.rng||iye)();if(i[6]=i[6]&15|64,i[8]=i[8]&63|128,g){I=I||0;for(var n=0;n<16;++n)g[I+n]=i[n];return g}return KT(i)}function Pit(e,g,I,i){switch(e){case 0:return g&I^~g&i;case 1:return g^I^i;case 2:return g&I^g&i^I&i;case 3:return g^I^i}}function u5(e,g){return e<>>32-g}function Jit(e){var g=[1518500249,1859775393,2400959708,3395469782],I=[1732584193,4023233417,2562383102,271733878,3285377520];if(typeof e=="string"){var i=unescape(encodeURIComponent(e));e=[];for(var n=0;n>>0;p=b,b=f,f=u5(m,30)>>>0,m=h,h=B}I[0]=I[0]+h>>>0,I[1]=I[1]+m>>>0,I[2]=I[2]+f>>>0,I[3]=I[3]+b>>>0,I[4]=I[4]+p>>>0}return[I[0]>>24&255,I[0]>>16&255,I[0]>>8&255,I[0]&255,I[1]>>24&255,I[1]>>16&255,I[1]>>8&255,I[1]&255,I[2]>>24&255,I[2]>>16&255,I[2]>>8&255,I[2]&255,I[3]>>24&255,I[3]>>16&255,I[3]>>8&255,I[3]&255,I[4]>>24&255,I[4]>>16&255,I[4]>>8&255,I[4]&255]}var Oit=Cye("v5",80,Jit);const _it=Oit,Lit="00000000-0000-0000-0000-000000000000";function Uit(e){if(!YT(e))throw TypeError("Invalid UUID");return parseInt(e.substr(14,1),16)}const Qit=Object.freeze(Object.defineProperty({__proto__:null,NIL:Lit,parse:nye,stringify:KT,v1:Hit,v3:Mit,v4:zit,v5:_it,validate:YT,version:Uit},Symbol.toStringTag,{value:"Module"})),jit=Os(Qit);var xT=jit,a7=(()=>typeof Buffer<"u"?e=>Buffer.from(e).toString("base64"):e=>btoa(String.fromCharCode(...e)))(),$it=(()=>typeof Buffer<"u"?e=>Buffer.from(e,"base64"):e=>Uint8Array.from(atob(e),g=>g.charCodeAt(0)))();ZS.encode=function(e){var g=xT.parse(e),I=a7(g),i=I.replace(/\+/g,"-").replace(/\//g,"_").substring(0,22);return i};ZS.decode=function(e){var g=e.replace(/-/g,"+").replace(/_/g,"/")+"==";return xT.stringify($it(g))};ZS.v4=function(){var e=xT.v4(null,new Uint8Array(16)),g=a7(e),I=g.replace(/\+/g,"-").replace(/\//g,"_").substring(0,22);return I};ZS.nice=function(){var e=xT.v4(null,new Uint8Array(16));e[0]=e[0]&127;var g=a7(e),I=g.replace(/\+/g,"-").replace(/\//g,"_").substring(0,22);return I};var qit=ZS;const Ag=DC(qit);var oye={exports:{}},FT={},xX={exports:{}};xX.exports;(function(e,g){var I=200,i="__lodash_hash_undefined__",n=1,C=2,r=9007199254740991,o="[object Arguments]",A="[object Array]",s="[object AsyncFunction]",a="[object Boolean]",l="[object Date]",c="[object Error]",u="[object Function]",d="[object GeneratorFunction]",h="[object Map]",m="[object Number]",f="[object Null]",b="[object Object]",p="[object Promise]",y="[object Proxy]",Z="[object RegExp]",B="[object Set]",G="[object String]",v="[object Symbol]",w="[object Undefined]",V="[object WeakMap]",S="[object ArrayBuffer]",X="[object DataView]",W="[object Float32Array]",R="[object Float64Array]",H="[object Int8Array]",Y="[object Int16Array]",D="[object Int32Array]",E="[object Uint8Array]",O="[object Uint8ClampedArray]",J="[object Uint16Array]",ee="[object Uint32Array]",q=/[\\^$.*+?()[\]{}|]/g,$=/^\[object .+?Constructor\]$/,j=/^(?:0|[1-9]\d*)$/,te={};te[W]=te[R]=te[H]=te[Y]=te[D]=te[E]=te[O]=te[J]=te[ee]=!0,te[o]=te[A]=te[S]=te[a]=te[X]=te[l]=te[c]=te[u]=te[h]=te[m]=te[b]=te[Z]=te[B]=te[G]=te[V]=!1;var U=typeof globalThis=="object"&&globalThis&&globalThis.Object===Object&&globalThis,ie=typeof self=="object"&&self&&self.Object===Object&&self,me=U||ie||Function("return this")(),Ce=g&&!g.nodeType&&g,Ze=Ce&&!0&&e&&!e.nodeType&&e,Ge=Ze&&Ze.exports===Ce,Be=Ge&&U.process,Ne=function(){try{return Be&&Be.binding&&Be.binding("util")}catch{}}(),Se=Ne&&Ne.isTypedArray;function Pe(ve,Me){for(var it=-1,St=ve==null?0:ve.length,aI=0,ig=[];++it-1}function At(ve,Me){var it=this.__data__,St=MI(it,ve);return St<0?(++this.size,it.push([ve,Me])):it[St][1]=Me,this}pt.prototype.clear=kt,pt.prototype.delete=ut,pt.prototype.get=Vt,pt.prototype.has=Ft,pt.prototype.set=At;function Xt(ve){var Me=-1,it=ve==null?0:ve.length;for(this.clear();++Meki))return!1;var XI=ig.get(ve);if(XI&&ig.get(Me))return XI==Me;var zC=-1,ao=!0,dn=it&C?new bt:void 0;for(ig.set(ve,Me),ig.set(Me,ve);++zC-1&&ve%1==0&&ve-1&&ve%1==0&&ve<=r}function A8(ve){var Me=typeof ve;return ve!=null&&(Me=="object"||Me=="function")}function ry(ve){return ve!=null&&typeof ve=="object"}var a8=Se?_e(Se):sNe;function BNe(ve){return GNe(ve)?ug(ve):lNe(ve)}function SNe(){return[]}function wNe(){return!1}e.exports=vNe})(xX,xX.exports);var ET=xX.exports,Aye={exports:{}};/*! Copyright (c) 2018 Jed Watson. Licensed under the MIT License (MIT), see http://jedwatson.github.io/classnames -*/(function(g){(function(){var e={}.hasOwnProperty;function I(){for(var i=[],n=0;ne&&(e=I);return e}function SIt(g){for(var e=Array(g.length),I=0,i=g.length;I=e.x+e.w||g.y+g.h<=e.y||g.y>=e.y+e.h)}function ZZe(g,e,I){for(var i=P7(g),n=J7(g,e),C=Array(g.length),r=0,o=n.length;re.y+e.h)break;NN(e,o)&&x3(g,o,I+e[n],i)}}e[i]=I}function GZe(g,e,I,i,n){var C=I==="vertical",r=I==="horizontal";if(C)for(e.y=Math.min(W9(g),e.y);e.y>0&&!zp(g,e);)e.y--;else if(r)for(e.y=Math.min(W9(g),e.y);e.x>0&&!zp(g,e);)e.x--;for(var o=void 0;o=zp(g,e);)r?x3(n,e,o.x+o.w,"x"):x3(n,e,o.y+o.h,"y"),r&&e.x+e.w>i&&(e.x=i-e.w,e.y++);return e}function BZe(g,e){for(var I=P7(g),i=0,n=g.length;ie.cols&&(C.x=e.cols-C.w),C.x<0&&(C.x=0,C.w=e.cols),!C.static)I.push(C);else for(;zp(I,C);)C.y++}return g}function vZe(g,e){for(var I=0,i=g.length;I=i:r==="horizontal"&&typeof I=="number"?A>=I:!1;l&&(a=a.reverse());var c=SZe(a,e);if(C&&c.length)return""+e.i,e.x=A,e.y=s,e.moved=!1,g;for(var u=0,d=c.length;uI.y||e.y===I.y&&e.x>I.x?1:e.y===I.y&&e.x===I.x?0:-1})}function VZe(g){return[].concat(g).sort(function(e,I){return e.x>I.x||e.x===I.x&&e.y>I.y?1:-1})}function HIt(g,e,I,i){g=g||[];var n=[];return K3.default.Children.forEach(e,function(C,r){var o=vZe(g,String(C.key));if(o)n[r]=Mp(o);else{var A=C.props["data-grid"]||C.props._grid;A?n[r]=Mp(ZIt({},A,{i:C.key})):n[r]=Mp({w:1,h:1,x:0,y:W9(n),i:String(C.key)})}}),n=BZe(n,{cols:I}),n=ZZe(n,i,I),n}function TIt(g){var e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"Layout",I=["x","y","w","h"];if(!Array.isArray(g))throw new Error(e+" must be an array!");for(var i=0,n=g.length;i1?Se-1:0),Ye=1;Ye2?Ke-2:0),Fe=2;Feg&&(g=I);return g}function int(e){for(var g=Array(e.length),I=0,i=e.length;I=g.x+g.w||e.y+e.h<=g.y||e.y>=g.y+g.h)}function lye(e,g,I){for(var i=s7(e),n=l7(e,g),C=Array(e.length),r=0,o=n.length;rg.y+g.h)break;MT(g,o)&&I3(e,o,I+g[n],i)}}g[i]=I}function cye(e,g,I,i,n){var C=I==="vertical",r=I==="horizontal";if(C)for(g.y=Math.min(FX(e),g.y);g.y>0&&!bp(e,g);)g.y--;else if(r)for(g.y=Math.min(FX(e),g.y);g.x>0&&!bp(e,g);)g.x--;for(var o=void 0;o=bp(e,g);)r?I3(n,g,o.x+o.w,"x"):I3(n,g,o.y+o.h,"y"),r&&g.x+g.w>i&&(g.x=i-g.w,g.y++);return g}function uye(e,g){for(var I=s7(e),i=0,n=e.length;ig.cols&&(C.x=g.cols-C.w),C.x<0&&(C.x=0,C.w=g.cols),!C.static)I.push(C);else for(;bp(I,C);)C.y++}return e}function dye(e,g){for(var I=0,i=e.length;I=i:r==="horizontal"&&typeof I=="number"?A>=I:!1;l&&(a=a.reverse());var c=hye(a,g);if(C&&c.length)return""+g.i,g.x=A,g.y=s,g.moved=!1,e;for(var u=0,d=c.length;uI.y||g.y===I.y&&g.x>I.x?1:g.y===I.y&&g.x===I.x?0:-1})}function fye(e){return[].concat(e).sort(function(g,I){return g.x>I.x||g.x===I.x&&g.y>I.y?1:-1})}function ant(e,g,I,i){e=e||[];var n=[];return g3.default.Children.forEach(g,function(C,r){var o=dye(e,String(C.key));if(o)n[r]=pp(o);else{var A=C.props["data-grid"]||C.props._grid;A?n[r]=pp(ent({},A,{i:C.key})):n[r]=pp({w:1,h:1,x:0,y:FX(n),i:String(C.key)})}}),n=uye(n,{cols:I}),n=lye(n,i,I),n}function snt(e){var g=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"Layout",I=["x","y","w","h"];if(!Array.isArray(e))throw new Error(g+" must be an array!");for(var i=0,n=e.length;i1?we-1:0),Ye=1;Ye2?Ke-2:0),Ee=2;Ee"u"||et===null)return""+et;var yt=Ut(et);if(yt==="object"){if(et instanceof Date)return"date";if(et instanceof RegExp)return"regexp"}return yt}function Xg(et){var yt=Pt(et);switch(yt){case"array":case"object":return"an "+yt;case"boolean":case"date":case"regexp":return"a "+yt;default:return yt}}function eI(et){return!et.constructor||!et.constructor.name?Fe:et.constructor.name}return He.checkPropTypes=S,He.PropTypes=He,He},W=n(function(re){{var oe=typeof Symbol=="function"&&Symbol.for&&Symbol.for("react.element")||60103,Se=function(Ye){return typeof Ye=="object"&&Ye!==null&&Ye.$$typeof===oe},Ke=!0;re.exports=X(Se,Ke)}}),V=n(function(re){/*! +*/var d=Object.getOwnPropertySymbols,h=Object.prototype.hasOwnProperty,m=Object.prototype.propertyIsEnumerable;function f(re){if(re==null)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(re)}function b(){try{if(!Object.assign)return!1;var re=new String("abc");if(re[5]="de",Object.getOwnPropertyNames(re)[0]==="5")return!1;for(var oe={},we=0;we<10;we++)oe["_"+String.fromCharCode(we)]=we;var Ke=Object.getOwnPropertyNames(oe).map(function(Ee){return oe[Ee]});if(Ke.join("")!=="0123456789")return!1;var Ye={};return"abcdefghijklmnopqrst".split("").forEach(function(Ee){Ye[Ee]=Ee}),Object.keys(Object.assign({},Ye)).join("")==="abcdefghijklmnopqrst"}catch{return!1}}var p=b()?Object.assign:function(re,oe){for(var we,Ke=f(re),Ye,Ee=1;Ee"u"||et===null)return""+et;var bt=Pt(et);if(bt==="object"){if(et instanceof Date)return"date";if(et instanceof RegExp)return"regexp"}return bt}function Sg(et){var bt=Dt(et);switch(bt){case"array":case"object":return"an "+bt;case"boolean":case"date":case"regexp":return"a "+bt;default:return bt}}function Qg(et){return!et.constructor||!et.constructor.name?Ee:et.constructor.name}return He.checkPropTypes=S,He.PropTypes=He,He},W=n(function(re){{var oe=typeof Symbol=="function"&&Symbol.for&&Symbol.for("react.element")||60103,we=function(Ye){return typeof Ye=="object"&&Ye!==null&&Ye.$$typeof===oe},Ke=!0;re.exports=X(we,Ke)}}),R=n(function(re){/*! Copyright (c) 2016 Jed Watson. Licensed under the MIT License (MIT), see http://jedwatson.github.io/classnames -*/(function(){var oe={}.hasOwnProperty;function Se(){for(var Ke=[],Ye=0;Ye0&&arguments[0]!==void 0?arguments[0]:"transform";if(typeof window>"u"||typeof window.document>"u")return"";var oe=window.document.documentElement.style;if(re in oe)return"";for(var Se=0;Se0&&arguments[0]!==void 0?arguments[0]:"transform";if(typeof window>"u"||typeof window.document>"u")return"";var oe=window.document.documentElement.style;if(re in oe)return"";for(var we=0;we0&&arguments[0]!==void 0?arguments[0]:{};return fe({touchAction:"none"},re)}function ge(re,oe){re.classList?re.classList.add(oe):re.className.match(new RegExp("(?:^|\\s)"+oe+"(?!\\S)"))||(re.className+=" "+oe)}function he(re,oe){re.classList?re.classList.remove(oe):re.className=re.className.replace(new RegExp("(?:^|\\s)"+oe+"(?!\\S)","g"),"")}function we(re,oe,Se){if(!re.props.bounds)return[oe,Se];var Ke=re.props.bounds;Ke=typeof Ke=="string"?Ke:ie(Ke);var Ye=E(re);if(typeof Ke=="string"){var Fe=Ye.ownerDocument,He=Fe.defaultView,De=void 0;if(Ke==="parent"?De=Ye.parentNode:De=Fe.querySelector(Ke),!(De instanceof He.HTMLElement))throw new Error('Bounds selector "'+Ke+'" could not find an element.');var P=He.getComputedStyle(Ye),x=He.getComputedStyle(De);Ke={left:-Ye.offsetLeft+F(x.paddingLeft)+F(P.marginLeft),top:-Ye.offsetTop+F(x.paddingTop)+F(P.marginTop),right:At(De)-Ue(Ye)-Ye.offsetLeft+F(x.paddingRight)-F(P.marginRight),bottom:_e(De)-Me(Ye)-Ye.offsetTop+F(x.paddingBottom)-F(P.marginBottom)}}return Y(Ke.right)&&(oe=Math.min(oe,Ke.right)),Y(Ke.bottom)&&(Se=Math.min(Se,Ke.bottom)),Y(Ke.left)&&(oe=Math.max(oe,Ke.left)),Y(Ke.top)&&(Se=Math.max(Se,Ke.top)),[oe,Se]}function xe(re,oe,Se){var Ke=Math.round(oe/re[0])*re[0],Ye=Math.round(Se/re[1])*re[1];return[Ke,Ye]}function qe(re){return re.props.axis==="both"||re.props.axis==="x"}function mt(re){return re.props.axis==="both"||re.props.axis==="y"}function St(re,oe,Se){var Ke=typeof oe=="number"?ye(re,oe):null;if(typeof oe=="number"&&!Ke)return null;var Ye=E(Se),Fe=Se.props.offsetParent||Ye.offsetParent||Ye.ownerDocument.body;return wt(Ke||re,Fe)}function ut(re,oe,Se){var Ke=re.state,Ye=!Y(Ke.lastX),Fe=E(re);return Ye?{node:Fe,deltaX:0,deltaY:0,lastX:oe,lastY:Se,x:oe,y:Se}:{node:Fe,deltaX:oe-Ke.lastX,deltaY:Se-Ke.lastY,lastX:Ke.lastX,lastY:Ke.lastY,x:oe,y:Se}}function Yt(re,oe){var Se=re.props.scale;return{node:oe.node,x:re.state.x+oe.deltaX/Se,y:re.state.y+oe.deltaY/Se,deltaX:oe.deltaX/Se,deltaY:oe.deltaY/Se,lastX:re.state.x,lastY:re.state.y}}function ie(re){return{left:re.left,top:re.top,right:re.right,bottom:re.bottom}}function E(re){var oe=I.findDOMNode(re);if(!oe)throw new Error(": Unmounted during event!");return oe}function O(){}var me={touch:{start:"touchstart",move:"touchmove",stop:"touchend"},mouse:{start:"mousedown",move:"mousemove",stop:"mouseup"}},Ne=me.mouse,ue=function(re){Ce(oe,re);function oe(){var Se,Ke,Ye,Fe;ee(this,oe);for(var He=arguments.length,De=Array(He),P=0;P not mounted on DragStart!");var ce=U.ownerDocument;if(!(Ye.props.disabled||!(x.target instanceof ce.defaultView.Node)||Ye.props.handle&&!Xe(x.target,Ye.props.handle,U)||Ye.props.cancel&&Xe(x.target,Ye.props.cancel,U))){var de=We(x);Ye.setState({touchIdentifier:de});var Pe=St(x,de,Ye);if(Pe!=null){var Je=Pe.x,ct=Pe.y,bt=ut(Ye,Je,ct);Ye.props.onStart;var Ft=Ye.props.onStart(x,bt);Ft!==!1&&(Ye.props.enableUserSelectHack&&K(ce),Ye.setState({dragging:!0,lastX:Je,lastY:ct}),Oe(ce,Ne.move,Ye.handleDrag),Oe(ce,Ne.stop,Ye.handleDragStop))}}},Ye.handleDrag=function(x){x.type==="touchmove"&&x.preventDefault();var U=St(x,Ye.state.touchIdentifier,Ye);if(U!=null){var ce=U.x,de=U.y;if(Array.isArray(Ye.props.grid)){var Pe=ce-Ye.state.lastX,Je=de-Ye.state.lastY,ct=xe(Ye.props.grid,Pe,Je),bt=Ge(ct,2);if(Pe=bt[0],Je=bt[1],!Pe&&!Je)return;ce=Ye.state.lastX+Pe,de=Ye.state.lastY+Je}var Ft=ut(Ye,ce,de),dt=Ye.props.onDrag(x,Ft);if(dt===!1){try{Ye.handleDragStop(new MouseEvent("mouseup"))}catch{var Xt=document.createEvent("MouseEvents");Xt.initMouseEvent("mouseup",!0,!0,window,0,0,0,0,0,!1,!1,!1,!1,0,null),Ye.handleDragStop(Xt)}return}Ye.setState({lastX:ce,lastY:de})}},Ye.handleDragStop=function(x){if(Ye.state.dragging){var U=St(x,Ye.state.touchIdentifier,Ye);if(U!=null){var ce=U.x,de=U.y,Pe=ut(Ye,ce,de),Je=I.findDOMNode(Ye);Je&&Ye.props.enableUserSelectHack&&T(Je.ownerDocument),Ye.setState({dragging:!1,lastX:NaN,lastY:NaN}),Ye.props.onStop(x,Pe),Je&&(ze(Je.ownerDocument,Ne.move,Ye.handleDrag),ze(Je.ownerDocument,Ne.stop,Ye.handleDragStop))}}},Ye.onMouseDown=function(x){return Ne=me.mouse,Ye.handleDragStart(x)},Ye.onMouseUp=function(x){return Ne=me.mouse,Ye.handleDragStop(x)},Ye.onTouchStart=function(x){return Ne=me.touch,Ye.handleDragStart(x)},Ye.onTouchEnd=function(x){return Ne=me.touch,Ye.handleDragStop(x)},Ke),Ze(Ye,Fe)}return Q(oe,[{key:"componentWillUnmount",value:function(){var Ke=I.findDOMNode(this);if(Ke){var Ye=Ke.ownerDocument;ze(Ye,me.mouse.move,this.handleDrag),ze(Ye,me.touch.move,this.handleDrag),ze(Ye,me.mouse.stop,this.handleDragStop),ze(Ye,me.touch.stop,this.handleDragStop),this.props.enableUserSelectHack&&T(Ye)}}},{key:"render",value:function(){return i.cloneElement(i.Children.only(this.props.children),{style:k(this.props.children.props.style),onMouseDown:this.onMouseDown,onTouchStart:this.onTouchStart,onMouseUp:this.onMouseUp,onTouchEnd:this.onTouchEnd})}}]),oe}(i.Component);ue.displayName="DraggableCore",ue.propTypes={allowAnyClick:W.bool,disabled:W.bool,enableUserSelectHack:W.bool,offsetParent:function(oe,Se){if(oe[Se]&&oe[Se].nodeType!==1)throw new Error("Draggable's offsetParent must be a DOM Node.")},grid:W.arrayOf(W.number),scale:W.number,handle:W.string,cancel:W.string,onStart:W.func,onDrag:W.func,onStop:W.func,onMouseDown:W.func,className:_,style:_,transform:_},ue.defaultProps={allowAnyClick:!1,cancel:null,disabled:!1,enableUserSelectHack:!0,offsetParent:null,handle:null,grid:null,transform:null,onStart:function(){},onDrag:function(){},onStop:function(){},onMouseDown:function(){}};var se=function(re){Ce(oe,re);function oe(Se){ee(this,oe);var Ke=Ze(this,(oe.__proto__||Object.getPrototypeOf(oe)).call(this,Se));return Ke.onDragStart=function(Ye,Fe){var He=Ke.props.onStart(Ye,Yt(Ke,Fe));if(He===!1)return!1;Ke.setState({dragging:!0,dragged:!0})},Ke.onDrag=function(Ye,Fe){if(!Ke.state.dragging)return!1;var He=Yt(Ke,Fe),De={x:He.x,y:He.y};if(Ke.props.bounds){var P=De.x,x=De.y;De.x+=Ke.state.slackX,De.y+=Ke.state.slackY;var U=we(Ke,De.x,De.y),ce=Ge(U,2),de=ce[0],Pe=ce[1];De.x=de,De.y=Pe,De.slackX=Ke.state.slackX+(P-De.x),De.slackY=Ke.state.slackY+(x-De.y),He.x=De.x,He.y=De.y,He.deltaX=De.x-Ke.state.x,He.deltaY=De.y-Ke.state.y}var Je=Ke.props.onDrag(Ye,He);if(Je===!1)return!1;Ke.setState(De)},Ke.onDragStop=function(Ye,Fe){if(!Ke.state.dragging)return!1;var He=Ke.props.onStop(Ye,Yt(Ke,Fe));if(He===!1)return!1;var De={dragging:!1,slackX:0,slackY:0},P=!!Ke.props.position;if(P){var x=Ke.props.position,U=x.x,ce=x.y;De.x=U,De.y=ce}Ke.setState(De)},Ke.state={dragging:!1,dragged:!1,x:Se.position?Se.position.x:Se.defaultPosition.x,y:Se.position?Se.position.y:Se.defaultPosition.y,slackX:0,slackY:0,isElementSVG:!1},Se.position&&!(Se.onDrag||Se.onStop)&&console.warn("A `position` was applied to this , without drag handlers. This will make this component effectively undraggable. Please attach `onDrag` or `onStop` handlers so you can adjust the `position` of this element."),Ke}return Q(oe,[{key:"componentDidMount",value:function(){typeof window.SVGElement<"u"&&I.findDOMNode(this)instanceof window.SVGElement&&this.setState({isElementSVG:!0})}},{key:"componentWillReceiveProps",value:function(Ke){Ke.position&&(!this.props.position||Ke.position.x!==this.props.position.x||Ke.position.y!==this.props.position.y)&&this.setState({x:Ke.position.x,y:Ke.position.y})}},{key:"componentWillUnmount",value:function(){this.setState({dragging:!1})}},{key:"render",value:function(){var Ke,Ye={},Fe=null,He=!!this.props.position,De=!He||this.state.dragging,P=this.props.position||this.props.defaultPosition,x={x:qe(this)&&De?this.state.x:P.x,y:mt(this)&&De?this.state.y:P.y};this.state.isElementSVG?Fe=Te(x,this.props.positionOffset):Ye=rt(x,this.props.positionOffset);var U=this.props,ce=U.defaultClassName,de=U.defaultClassNameDragging,Pe=U.defaultClassNameDragged,Je=i.Children.only(this.props.children),ct=V(Je.props.className||"",ce,(Ke={},ne(Ke,de,this.state.dragging),ne(Ke,Pe,this.state.dragged),Ke));return i.createElement(ue,fe({},this.props,{onStart:this.onDragStart,onDrag:this.onDrag,onStop:this.onDragStop}),i.cloneElement(Je,{className:ct,style:fe({},Je.props.style,Ye),transform:Fe}))}}]),oe}(i.Component);return se.displayName="Draggable",se.propTypes=fe({},ue.propTypes,{axis:W.oneOf(["both","x","y","none"]),bounds:W.oneOfType([W.shape({left:W.number,right:W.number,top:W.number,bottom:W.number}),W.string,W.oneOf([!1])]),defaultClassName:W.string,defaultClassNameDragging:W.string,defaultClassNameDragged:W.string,defaultPosition:W.shape({x:W.number,y:W.number}),positionOffset:W.shape({x:W.oneOfType([W.number,W.string]),y:W.oneOfType([W.number,W.string])}),position:W.shape({x:W.number,y:W.number}),className:_,style:_,transform:_}),se.defaultProps=fe({},ue.defaultProps,{axis:"both",bounds:!1,defaultClassName:"react-draggable",defaultClassNameDragging:"react-draggable-dragging",defaultClassNameDragged:"react-draggable-dragged",defaultPosition:{x:0,y:0},position:null,scale:1}),se.default=se,se.DraggableCore=ue,se})})(RZe);var kIt=RZe.exports,kN={exports:{}},gw={},YN={exports:{}},WZe={};function XZe(g){var e,I,i="";if(typeof g=="string"||typeof g=="number")i+=g;else if(typeof g=="object")if(Array.isArray(g))for(e=0;e0&&arguments[0]!==void 0?arguments[0]:"transform";if(typeof window>"u")return"";const I=(g=window.document)===null||g===void 0||(g=g.documentElement)===null||g===void 0?void 0:g.style;if(!I||e in I)return"";for(let i=0;ie===I.identifier)||g.changedTouches&&(0,mr.findInArray)(g.changedTouches,I=>e===I.identifier)}function Iit(g){if(g.targetTouches&&g.targetTouches[0])return g.targetTouches[0].identifier;if(g.changedTouches&&g.changedTouches[0])return g.changedTouches[0].identifier}function iit(g){if(!g)return;let e=g.getElementById("react-draggable-style-el");e||(e=g.createElement("style"),e.type="text/css",e.id="react-draggable-style-el",e.innerHTML=`.react-draggable-transparent-selection *::-moz-selection {all: inherit;} -`,e.innerHTML+=`.react-draggable-transparent-selection *::selection {all: inherit;} -`,g.getElementsByTagName("head")[0].appendChild(e)),g.body&&YZe(g.body,"react-draggable-transparent-selection")}function nit(g){if(g)try{if(g.body&&KZe(g.body,"react-draggable-transparent-selection"),g.selection)g.selection.empty();else{const e=(g.defaultView||window).getSelection();e&&e.type!=="Caret"&&e.removeAllRanges()}}catch{}}function YZe(g,e){g.classList?g.classList.add(e):g.className.match(new RegExp("(?:^|\\s)".concat(e,"(?!\\S)")))||(g.className+=" ".concat(e))}function KZe(g,e){g.classList?g.classList.remove(e):g.className=g.className.replace(new RegExp("(?:^|\\s)".concat(e,"(?!\\S)"),"g"),"")}var Na={};Object.defineProperty(Na,"__esModule",{value:!0});Na.canDragX=oit;Na.canDragY=Ait;Na.createCoreData=sit;Na.createDraggableData=lit;Na.getBoundPosition=Cit;Na.getControlPosition=ait;Na.snapToGrid=rit;var _C=Ta,mp=ei;function Cit(g,e,I){if(!g.props.bounds)return[e,I];let{bounds:i}=g.props;i=typeof i=="string"?i:cit(i);const n=_7(g);if(typeof i=="string"){const{ownerDocument:C}=n,r=C.defaultView;let o;if(i==="parent"?o=n.parentNode:o=C.querySelector(i),!(o instanceof r.HTMLElement))throw new Error('Bounds selector "'+i+'" could not find an element.');const A=o,s=r.getComputedStyle(n),a=r.getComputedStyle(A);i={left:-n.offsetLeft+(0,_C.int)(a.paddingLeft)+(0,_C.int)(s.marginLeft),top:-n.offsetTop+(0,_C.int)(a.paddingTop)+(0,_C.int)(s.marginTop),right:(0,mp.innerWidth)(A)-(0,mp.outerWidth)(n)-n.offsetLeft+(0,_C.int)(a.paddingRight)-(0,_C.int)(s.marginRight),bottom:(0,mp.innerHeight)(A)-(0,mp.outerHeight)(n)-n.offsetTop+(0,_C.int)(a.paddingBottom)-(0,_C.int)(s.marginBottom)}}return(0,_C.isNum)(i.right)&&(e=Math.min(e,i.right)),(0,_C.isNum)(i.bottom)&&(I=Math.min(I,i.bottom)),(0,_C.isNum)(i.left)&&(e=Math.max(e,i.left)),(0,_C.isNum)(i.top)&&(I=Math.max(I,i.top)),[e,I]}function rit(g,e,I){const i=Math.round(e/g[0])*g[0],n=Math.round(I/g[1])*g[1];return[i,n]}function oit(g){return g.props.axis==="both"||g.props.axis==="x"}function Ait(g){return g.props.axis==="both"||g.props.axis==="y"}function ait(g,e,I){const i=typeof e=="number"?(0,mp.getTouch)(g,e):null;if(typeof e=="number"&&!i)return null;const n=_7(I),C=I.props.offsetParent||n.offsetParent||n.ownerDocument.body;return(0,mp.offsetXYFromParent)(i||g,C,I.props.scale)}function sit(g,e,I){const i=!(0,_C.isNum)(g.lastX),n=_7(g);return i?{node:n,deltaX:0,deltaY:0,lastX:e,lastY:I,x:e,y:I}:{node:n,deltaX:e-g.lastX,deltaY:I-g.lastY,lastX:g.lastX,lastY:g.lastY,x:e,y:I}}function lit(g,e){const I=g.props.scale;return{node:e.node,x:g.state.x+e.deltaX/I,y:g.state.y+e.deltaY/I,deltaX:e.deltaX/I,deltaY:e.deltaY/I,lastX:g.state.x,lastY:g.state.y}}function cit(g){return{left:g.left,top:g.top,right:g.right,bottom:g.bottom}}function _7(g){const e=g.findDOMNode();if(!e)throw new Error(": Unmounted during event!");return e}var KN={},xN={};Object.defineProperty(xN,"__esModule",{value:!0});xN.default=uit;function uit(){}function dit(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function qge(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function X9(g){return X9=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},X9(g)}Object.defineProperty(KN,"__esModule",{value:!0});KN.default=void 0;var Cx=Bit(N),mC=U7(al),Git=U7(QI),Bn=ei,Wl=Na,rx=Ta,eZ=U7(xN);function U7(g){return g&&g.__esModule?g:{default:g}}function xZe(g){if(typeof WeakMap!="function")return null;var e=new WeakMap,I=new WeakMap;return(xZe=function(i){return i?I:e})(g)}function Bit(g,e){if(!e&&g&&g.__esModule)return g;if(g===null||typeof g!="object"&&typeof g!="function")return{default:g};var I=xZe(e);if(I&&I.has(g))return I.get(g);var i={},n=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var C in g)if(C!=="default"&&Object.prototype.hasOwnProperty.call(g,C)){var r=n?Object.getOwnPropertyDescriptor(g,C):null;r&&(r.get||r.set)?Object.defineProperty(i,C,r):i[C]=g[C]}return i.default=g,I&&I.set(g,i),i}function Pn(g,e,I){return e=vit(e),e in g?Object.defineProperty(g,e,{value:I,enumerable:!0,configurable:!0,writable:!0}):g[e]=I,g}function vit(g){var e=Sit(g,"string");return typeof e=="symbol"?e:String(e)}function Sit(g,e){if(typeof g!="object"||g===null)return g;var I=g[Symbol.toPrimitive];if(I!==void 0){var i=I.call(g,e||"default");if(typeof i!="object")return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return(e==="string"?String:Number)(g)}const xo={touch:{start:"touchstart",move:"touchmove",stop:"touchend"},mouse:{start:"mousedown",move:"mousemove",stop:"mouseup"}};let Xl=xo.mouse,DN=function(g){pit(I,g);var e=bit(I);function I(){var i;return dit(this,I),i=e.apply(this,arguments),Pn(yi(i),"dragging",!1),Pn(yi(i),"lastX",NaN),Pn(yi(i),"lastY",NaN),Pn(yi(i),"touchIdentifier",null),Pn(yi(i),"mounted",!1),Pn(yi(i),"handleDragStart",n=>{if(i.props.onMouseDown(n),!i.props.allowAnyClick&&typeof n.button=="number"&&n.button!==0)return!1;const C=i.findDOMNode();if(!C||!C.ownerDocument||!C.ownerDocument.body)throw new Error(" not mounted on DragStart!");const{ownerDocument:r}=C;if(i.props.disabled||!(n.target instanceof r.defaultView.Node)||i.props.handle&&!(0,Bn.matchesSelectorAndParentsTo)(n.target,i.props.handle,C)||i.props.cancel&&(0,Bn.matchesSelectorAndParentsTo)(n.target,i.props.cancel,C))return;n.type==="touchstart"&&n.preventDefault();const o=(0,Bn.getTouchIdentifier)(n);i.touchIdentifier=o;const A=(0,Wl.getControlPosition)(n,o,yi(i));if(A==null)return;const{x:s,y:a}=A,l=(0,Wl.createCoreData)(yi(i),s,a);(0,eZ.default)("DraggableCore: handleDragStart: %j",l),(0,eZ.default)("calling",i.props.onStart),!(i.props.onStart(n,l)===!1||i.mounted===!1)&&(i.props.enableUserSelectHack&&(0,Bn.addUserSelectStyles)(r),i.dragging=!0,i.lastX=s,i.lastY=a,(0,Bn.addEvent)(r,Xl.move,i.handleDrag),(0,Bn.addEvent)(r,Xl.stop,i.handleDragStop))}),Pn(yi(i),"handleDrag",n=>{const C=(0,Wl.getControlPosition)(n,i.touchIdentifier,yi(i));if(C==null)return;let{x:r,y:o}=C;if(Array.isArray(i.props.grid)){let a=r-i.lastX,l=o-i.lastY;if([a,l]=(0,Wl.snapToGrid)(i.props.grid,a,l),!a&&!l)return;r=i.lastX+a,o=i.lastY+l}const A=(0,Wl.createCoreData)(yi(i),r,o);if((0,eZ.default)("DraggableCore: handleDrag: %j",A),i.props.onDrag(n,A)===!1||i.mounted===!1){try{i.handleDragStop(new MouseEvent("mouseup"))}catch{const l=document.createEvent("MouseEvents");l.initMouseEvent("mouseup",!0,!0,window,0,0,0,0,0,!1,!1,!1,!1,0,null),i.handleDragStop(l)}return}i.lastX=r,i.lastY=o}),Pn(yi(i),"handleDragStop",n=>{if(!i.dragging)return;const C=(0,Wl.getControlPosition)(n,i.touchIdentifier,yi(i));if(C==null)return;let{x:r,y:o}=C;if(Array.isArray(i.props.grid)){let l=r-i.lastX||0,c=o-i.lastY||0;[l,c]=(0,Wl.snapToGrid)(i.props.grid,l,c),r=i.lastX+l,o=i.lastY+c}const A=(0,Wl.createCoreData)(yi(i),r,o);if(i.props.onStop(n,A)===!1||i.mounted===!1)return!1;const a=i.findDOMNode();a&&i.props.enableUserSelectHack&&(0,Bn.removeUserSelectStyles)(a.ownerDocument),(0,eZ.default)("DraggableCore: handleDragStop: %j",A),i.dragging=!1,i.lastX=NaN,i.lastY=NaN,a&&((0,eZ.default)("DraggableCore: Removing handlers"),(0,Bn.removeEvent)(a.ownerDocument,Xl.move,i.handleDrag),(0,Bn.removeEvent)(a.ownerDocument,Xl.stop,i.handleDragStop))}),Pn(yi(i),"onMouseDown",n=>(Xl=xo.mouse,i.handleDragStart(n))),Pn(yi(i),"onMouseUp",n=>(Xl=xo.mouse,i.handleDragStop(n))),Pn(yi(i),"onTouchStart",n=>(Xl=xo.touch,i.handleDragStart(n))),Pn(yi(i),"onTouchEnd",n=>(Xl=xo.touch,i.handleDragStop(n))),i}return hit(I,[{key:"componentDidMount",value:function(){this.mounted=!0;const n=this.findDOMNode();n&&(0,Bn.addEvent)(n,xo.touch.start,this.onTouchStart,{passive:!1})}},{key:"componentWillUnmount",value:function(){this.mounted=!1;const n=this.findDOMNode();if(n){const{ownerDocument:C}=n;(0,Bn.removeEvent)(C,xo.mouse.move,this.handleDrag),(0,Bn.removeEvent)(C,xo.touch.move,this.handleDrag),(0,Bn.removeEvent)(C,xo.mouse.stop,this.handleDragStop),(0,Bn.removeEvent)(C,xo.touch.stop,this.handleDragStop),(0,Bn.removeEvent)(n,xo.touch.start,this.onTouchStart,{passive:!1}),this.props.enableUserSelectHack&&(0,Bn.removeUserSelectStyles)(C)}}},{key:"findDOMNode",value:function(){var n,C;return(n=this.props)!==null&&n!==void 0&&n.nodeRef?(C=this.props)===null||C===void 0||(C=C.nodeRef)===null||C===void 0?void 0:C.current:Git.default.findDOMNode(this)}},{key:"render",value:function(){return Cx.cloneElement(Cx.Children.only(this.props.children),{onMouseDown:this.onMouseDown,onMouseUp:this.onMouseUp,onTouchEnd:this.onTouchEnd})}}]),I}(Cx.Component);KN.default=DN;Pn(DN,"displayName","DraggableCore");Pn(DN,"propTypes",{allowAnyClick:mC.default.bool,children:mC.default.node.isRequired,disabled:mC.default.bool,enableUserSelectHack:mC.default.bool,offsetParent:function(g,e){if(g[e]&&g[e].nodeType!==1)throw new Error("Draggable's offsetParent must be a DOM Node.")},grid:mC.default.arrayOf(mC.default.number),handle:mC.default.string,cancel:mC.default.string,nodeRef:mC.default.object,onStart:mC.default.func,onDrag:mC.default.func,onStop:mC.default.func,onMouseDown:mC.default.func,scale:mC.default.number,className:rx.dontSetMe,style:rx.dontSetMe,transform:rx.dontSetMe});Pn(DN,"defaultProps",{allowAnyClick:!1,disabled:!1,enableUserSelectHack:!0,onStart:function(){},onDrag:function(){},onStop:function(){},onMouseDown:function(){},scale:1});(function(g){function e(V,H){if(!(V instanceof H))throw new TypeError("Cannot call a class as a function")}function I(V,H){for(var D=0;D"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function c(V){return c=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(D){return D.__proto__||Object.getPrototypeOf(D)},c(V)}Object.defineProperty(g,"__esModule",{value:!0}),Object.defineProperty(g,"DraggableCore",{enumerable:!0,get:function(){return y.default}}),g.default=void 0;var u=B(N),d=v(al),h=v(QI),m=v(KIt),f=ei,b=Na,p=Ta,y=v(KN),Z=v(xN);function v(V){return V&&V.__esModule?V:{default:V}}function G(V){if(typeof WeakMap!="function")return null;var H=new WeakMap,D=new WeakMap;return(G=function(Y){return Y?D:H})(V)}function B(V,H){if(!H&&V&&V.__esModule)return V;if(V===null||typeof V!="object"&&typeof V!="function")return{default:V};var D=G(H);if(D&&D.has(V))return D.get(V);var Y={},F=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var _ in V)if(_!=="default"&&Object.prototype.hasOwnProperty.call(V,_)){var J=F?Object.getOwnPropertyDescriptor(V,_):null;J&&(J.get||J.set)?Object.defineProperty(Y,_,J):Y[_]=V[_]}return Y.default=V,D&&D.set(V,Y),Y}function w(){return w=Object.assign?Object.assign.bind():function(V){for(var H=1;H{if((0,Z.default)("Draggable: onDragStart: %j",J),F.props.onStart(_,(0,b.createDraggableData)(a(F),J))===!1)return!1;F.setState({dragging:!0,dragged:!0})}),R(a(F),"onDrag",(_,J)=>{if(!F.state.dragging)return!1;(0,Z.default)("Draggable: onDrag: %j",J);const te=(0,b.createDraggableData)(a(F),J),q={x:te.x,y:te.y,slackX:0,slackY:0};if(F.props.bounds){const{x:j,y:ee}=q;q.x+=F.state.slackX,q.y+=F.state.slackY;const[Q,ne]=(0,b.getBoundPosition)(a(F),q.x,q.y);q.x=Q,q.y=ne,q.slackX=F.state.slackX+(j-q.x),q.slackY=F.state.slackY+(ee-q.y),te.x=q.x,te.y=q.y,te.deltaX=q.x-F.state.x,te.deltaY=q.y-F.state.y}if(F.props.onDrag(_,te)===!1)return!1;F.setState(q)}),R(a(F),"onDragStop",(_,J)=>{if(!F.state.dragging||F.props.onStop(_,(0,b.createDraggableData)(a(F),J))===!1)return!1;(0,Z.default)("Draggable: onDragStop: %j",J);const q={dragging:!1,slackX:0,slackY:0};if(!!F.props.position){const{x:j,y:ee}=F.props.position;q.x=j,q.y=ee}F.setState(q)}),F.state={dragging:!1,dragged:!1,x:Y.position?Y.position.x:Y.defaultPosition.x,y:Y.position?Y.position.y:Y.defaultPosition.y,prevPropsPosition:{...Y.position},slackX:0,slackY:0,isElementSVG:!1},Y.position&&!(Y.onDrag||Y.onStop)&&console.warn("A `position` was applied to this , without drag handlers. This will make this component effectively undraggable. Please attach `onDrag` or `onStop` handlers so you can adjust the `position` of this element."),F}return i(D,[{key:"componentDidMount",value:function(){typeof window.SVGElement<"u"&&this.findDOMNode()instanceof window.SVGElement&&this.setState({isElementSVG:!0})}},{key:"componentWillUnmount",value:function(){this.setState({dragging:!1})}},{key:"findDOMNode",value:function(){var F,_;return(F=(_=this.props)===null||_===void 0||(_=_.nodeRef)===null||_===void 0?void 0:_.current)!==null&&F!==void 0?F:h.default.findDOMNode(this)}},{key:"render",value:function(){const{axis:F,bounds:_,children:J,defaultPosition:te,defaultClassName:q,defaultClassNameDragging:$,defaultClassNameDragged:j,position:ee,positionOffset:Q,scale:ne,...fe}=this.props;let Ce={},Ze=null;const ve=!!!ee||this.state.dragging,ke=ee||te,Xe={x:(0,b.canDragX)(this)&&ve?this.state.x:ke.x,y:(0,b.canDragY)(this)&&ve?this.state.y:ke.y};this.state.isElementSVG?Ze=(0,f.createSVGTransform)(Xe,Q):Ce=(0,f.createCSSTransform)(Xe,Q);const Oe=(0,m.default)(J.props.className||"",q,{[$]:this.state.dragging,[j]:this.state.dragged});return u.createElement(y.default,w({},fe,{onStart:this.onDragStart,onDrag:this.onDrag,onStop:this.onDragStop}),u.cloneElement(u.Children.only(J),{className:Oe,style:{...J.props.style,...Ce},transform:Ze}))}}],[{key:"getDerivedStateFromProps",value:function(F,_){let{position:J}=F,{prevPropsPosition:te}=_;return J&&(!te||J.x!==te.x||J.y!==te.y)?((0,Z.default)("Draggable: getDerivedStateFromProps %j",{position:J,prevPropsPosition:te}),{x:J.x,y:J.y,prevPropsPosition:{...J}}):null}}]),D}(u.Component);g.default=W,R(W,"displayName","Draggable"),R(W,"propTypes",{...y.default.propTypes,axis:d.default.oneOf(["both","x","y","none"]),bounds:d.default.oneOfType([d.default.shape({left:d.default.number,right:d.default.number,top:d.default.number,bottom:d.default.number}),d.default.string,d.default.oneOf([!1])]),defaultClassName:d.default.string,defaultClassNameDragging:d.default.string,defaultClassNameDragged:d.default.string,defaultPosition:d.default.shape({x:d.default.number,y:d.default.number}),positionOffset:d.default.shape({x:d.default.oneOfType([d.default.number,d.default.string]),y:d.default.oneOfType([d.default.number,d.default.string])}),position:d.default.shape({x:d.default.number,y:d.default.number}),className:p.dontSetMe,style:p.dontSetMe,transform:p.dontSetMe}),R(W,"defaultProps",{...y.default.defaultProps,axis:"both",bounds:!1,defaultClassName:"react-draggable",defaultClassNameDragging:"react-draggable-dragging",defaultClassNameDragged:"react-draggable-dragged",defaultPosition:{x:0,y:0},scale:1})})(WZe);const{default:DZe,DraggableCore:wit}=WZe;YN.exports=DZe;YN.exports.default=DZe;YN.exports.DraggableCore=wit;var Vit=YN.exports,Q7={};Q7.__esModule=!0;Q7.cloneElement=Hit;var Rit=Wit(N);function Wit(g){return g&&g.__esModule?g:{default:g}}function eIe(g,e){var I=Object.keys(g);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(g);e&&(i=i.filter(function(n){return Object.getOwnPropertyDescriptor(g,n).enumerable})),I.push.apply(I,i)}return I}function tIe(g){for(var e=1;e=0)&&(I[n]=g[n]);return I}function Ax(g){if(g===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return g}function Fit(g,e){g.prototype=Object.create(e.prototype),g.prototype.constructor=g,g.__proto__=e}function Pp(g,e,I){return e in g?Object.defineProperty(g,e,{value:I,enumerable:!0,configurable:!0,writable:!0}):g[e]=I,g}var j7=function(g){Fit(e,g);function e(){for(var i,n=arguments.length,C=new Array(n),r=0;r=0)&&(I[n]=g[n]);return I}function nIe(g){if(g===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return g}function Oit(g,e){g.prototype=Object.create(e.prototype),g.prototype.constructor=g,g.__proto__=e}function T9(g,e,I){return e in g?Object.defineProperty(g,e,{value:I,enumerable:!0,configurable:!0,writable:!0}):g[e]=I,g}var MZe=function(g){Oit(e,g);function e(){for(var i,n=arguments.length,C=new Array(n),r=0;re.w||i>e.maxW)return new Error("minWidth larger than item width/maxWidth")},maxW:function(e,I){var i=e[I];if(typeof i!="number")return new Error("maxWidth not Number");if(ie.h||i>e.maxH)return new Error("minHeight larger than item height/maxHeight")},maxH:function(e,I){var i=e[I];if(typeof i!="number")return new Error("maxHeight not Number");if(i0,m){var b=1/0,p=1/0;f.forEach(function(Z){Z.x>h.x&&(b=Math.min(b,Z.x)),Z.y>h.y&&(p=Math.min(p,Z.y))}),Number.isFinite(b)&&(h.w=b-h.x),Number.isFinite(p)&&(h.h=p-h.y)}}m||(h.w=n,h.h=C);var y={w:h.w,h:h.h,x:h.x,y:h.y,static:!0,i};this.props.onResize(a,l,h,y,o,A),this.setState({layout:(0,Jg.compact)(a,this.compactType(),u),activeDrag:y})}},e.prototype.onResizeStop=function(i,n,C,r){var o=r.e,A=r.node,s=this.state,a=s.layout,l=s.oldResizeItem,c=this.props.cols,u=(0,Jg.getLayoutItem)(a,i);this.props.onResizeStop(a,l,u,null,o,A);var d=(0,Jg.compact)(a,this.compactType(),c),h=this.state.oldLayout;this.setState({activeDrag:null,layout:d,oldResizeItem:null,oldLayout:null}),this.onLayoutMaybeChanged(d,h)},e.prototype.placeholder=function(){var i=this.state.activeDrag;if(!i)return null;var n=this.props,C=n.width,r=n.cols,o=n.margin,A=n.containerPadding,s=n.rowHeight,a=n.maxRows,l=n.useCSSTransforms;return id.default.createElement(AIe.default,{w:i.w,h:i.h,x:i.x,y:i.y,i:i.i,className:"react-grid-placeholder",containerWidth:C,cols:r,margin:o,containerPadding:A||o,maxRows:a,rowHeight:s,isDraggable:!1,isResizable:!1,useCSSTransforms:l},id.default.createElement("div",null))},e.prototype.processGridItem=function(i){if(!(!i||!i.key)){var n=(0,Jg.getLayoutItem)(this.state.layout,String(i.key));if(!n)return null;var C=this.props,r=C.width,o=C.cols,A=C.margin,s=C.containerPadding,a=C.rowHeight,l=C.maxRows,c=C.isDraggable,u=C.isResizable,d=C.useCSSTransforms,h=C.draggableCancel,m=C.draggableHandle,f=this.state.mounted,b=!!(!n.static&&c&&(n.isDraggable||n.isDraggable==null)),p=!!(!n.static&&u&&(n.isResizable||n.isResizable==null));return id.default.createElement(AIe.default,{containerWidth:r,cols:o,margin:A,containerPadding:s||A,maxRows:l,rowHeight:a,cancel:h,handle:m,onDragStop:this.onDragStop,onDragStart:this.onDragStart,onDrag:this.onDrag,onResizeStart:this.onResizeStart,onResize:this.onResize,onResizeStop:this.onResizeStop,isDraggable:b,isResizable:p,useCSSTransforms:d&&f,usePercentages:!f,w:n.w,h:n.h,x:n.x,y:n.y,i:n.i,minH:n.minH,minW:n.minW,maxH:n.maxH,maxW:n.maxW,static:n.static},i)}},e.prototype.render=function(){var i=this,n=this.props,C=n.className,r=n.style,o=(0,rnt.default)("react-grid-layout",C),A=rIe({height:this.containerHeight()},r);return id.default.createElement("div",{className:o,style:A},id.default.Children.map(this.props.children,function(s){return i.processGridItem(s)}),this.placeholder())},e}(id.default.Component);EN.displayName="ReactGridLayout";EN.propTypes={className:dI.default.string,style:dI.default.object,width:dI.default.number,autoSize:dI.default.bool,cols:dI.default.number,draggableCancel:dI.default.string,draggableHandle:dI.default.string,verticalCompact:function(e){e.verticalCompact},compactType:dI.default.oneOf(["vertical","horizontal"]),layout:function(e){var I=e.layout;I!==void 0&&(0,Jg.validateLayout)(I,"layout")},margin:dI.default.arrayOf(dI.default.number),containerPadding:dI.default.arrayOf(dI.default.number),rowHeight:dI.default.number,maxRows:dI.default.number,isDraggable:dI.default.bool,isResizable:dI.default.bool,preventCollision:dI.default.bool,useCSSTransforms:dI.default.bool,onLayoutChange:dI.default.func,onDragStart:dI.default.func,onDrag:dI.default.func,onDragStop:dI.default.func,onResizeStart:dI.default.func,onResize:dI.default.func,onResizeStop:dI.default.func,children:function(e,I){var i=e[I],n={};id.default.Children.forEach(i,function(C){if(n[C.key])throw new Error('Duplicate child key "'+C.key+'" found! This will cause problems in ReactGridLayout.');n[C.key]=!0})}};EN.defaultProps={autoSize:!0,cols:12,className:"",style:{},draggableHandle:"",draggableCancel:"",containerPadding:null,rowHeight:150,maxRows:1/0,layout:[],margin:[10,10],isDraggable:!0,isResizable:!0,useCSSTransforms:!0,verticalCompact:!0,compactType:"vertical",preventCollision:!1,onLayoutChange:Jg.noop,onDragStart:Jg.noop,onDrag:Jg.noop,onDragStop:Jg.noop,onResizeStart:Jg.noop,onResize:Jg.noop,onResizeStop:Jg.noop};var lnt=function(){this.state={activeDrag:null,layout:(0,Jg.synchronizeLayoutWithChildren)(this.props.layout,this.props.children,this.props.cols,this.compactType()),mounted:!1,oldDragItem:null,oldLayout:null,oldResizeItem:null}};HN.default=EN;var eQ={},cm={};cm.__esModule=!0;cm.getBreakpointFromWidth=cnt;cm.getColsFromBreakpoint=unt;cm.findOrGenerateResponsiveLayout=dnt;cm.sortBreakpoints=tQ;var dR=Mg;function cnt(g,e){for(var I=tQ(g),i=I[0],n=1,C=I.length;ng[r]&&(i=r)}return i}function unt(g,e){if(!e[g])throw new Error("ResponsiveReactGridLayout: `cols` entry for breakpoint "+g+" is missing!");return e[g]}function dnt(g,e,I,i,n,C){if(g[I])return(0,dR.cloneLayout)(g[I]);for(var r=g[i],o=tQ(e),A=o.slice(o.indexOf(I)),s=0,a=A.length;s=0||Object.prototype.hasOwnProperty.call(g,i)&&(I[i]=g[i]);return I}function Znt(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function lIe(g,e){if(!g)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e&&(typeof e=="object"||typeof e=="function")?e:g}function Gnt(g,e){if(typeof e!="function"&&e!==null)throw new TypeError("Super expression must either be null or a function, not "+typeof e);g.prototype=Object.create(e&&e.prototype,{constructor:{value:g,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(g,e):g.__proto__=e)}var cIe=function(e){return Object.prototype.toString.call(e)},gQ=function(g){Gnt(e,g);function e(){var I,i,n;Znt(this,e);for(var C=arguments.length,r=Array(C),o=0;o=0||Object.prototype.hasOwnProperty.call(g,i)&&(I[i]=g[i]);return I}function Xnt(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function uIe(g,e){if(!g)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e&&(typeof e=="object"||typeof e=="function")?e:g}function Hnt(g,e){if(typeof e!="function"&&e!==null)throw new TypeError("Super expression must either be null or a function, not "+typeof e);g.prototype=Object.create(e&&e.prototype,{constructor:{value:g,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(g,e):g.__proto__=e)}function Tnt(g){var e,I;return I=e=function(i){Hnt(n,i);function n(){var C,r,o;Xnt(this,n);for(var A=arguments.length,s=Array(A),a=0;a"u")return null;var I=typeof window<"u"&&window.Math==Math?window:typeof self<"u"&&self.Math==Math?self:Function("return this")(),i=I.requestAnimationFrame||I.mozRequestAnimationFrame||I.webkitRequestAnimationFrame||function(a){return I.setTimeout(a,20)},n=I.cancelAnimationFrame||I.mozCancelAnimationFrame||I.webkitCancelAnimationFrame||function(a){I.clearTimeout(a)};function C(a,l){var c=Object.prototype.toString.call(a),u=c==="[object Array]"||c==="[object NodeList]"||c==="[object HTMLCollection]"||c==="[object Object]"||typeof jQuery<"u"&&a instanceof jQuery||typeof Elements<"u"&&a instanceof Elements,d=0,h=a.length;if(u)for(;d=X&&(H+=R.value),R.mode==="max"&&W<=X&&(H+=R.value),V[D]||(V[D]=""),H&&(" "+V[D]+" ").indexOf(" "+H+" ")===-1&&(V[D]+=" "+H));for(var F in Y)Y.hasOwnProperty(F)&&(V[Y[F]]?this.element.setAttribute(Y[F],V[Y[F]].substr(1)):this.element.removeAttribute(Y[F]))}}function c(G,B){G.elementQueriesSetupInformation||(G.elementQueriesSetupInformation=new l(G,B)),G.elementQueriesSensor||(G.elementQueriesSensor=new I(G,function(){G.elementQueriesSetupInformation.call()}))}function u(G,B,w,R){if(typeof r[G]>"u"){r[G]=[];var S=o.length;C.innerHTML+=` +`,re.getElementsByTagName("head")[0].appendChild(oe)),re.body&&ge(re.body,"react-draggable-transparent-selection")}}function T(re){try{re&&re.body&&he(re.body,"react-draggable-transparent-selection"),re.selection?re.selection.empty():window.getSelection().removeAllRanges()}catch{}}function k(){var re=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};return me({touchAction:"none"},re)}function ge(re,oe){re.classList?re.classList.add(oe):re.className.match(new RegExp("(?:^|\\s)"+oe+"(?!\\S)"))||(re.className+=" "+oe)}function he(re,oe){re.classList?re.classList.remove(oe):re.className=re.className.replace(new RegExp("(?:^|\\s)"+oe+"(?!\\S)","g"),"")}function Ve(re,oe,we){if(!re.props.bounds)return[oe,we];var Ke=re.props.bounds;Ke=typeof Ke=="string"?Ke:ne(Ke);var Ye=F(re);if(typeof Ke=="string"){var Ee=Ye.ownerDocument,He=Ee.defaultView,xe=void 0;if(Ke==="parent"?xe=Ye.parentNode:xe=Ee.querySelector(Ke),!(xe instanceof He.HTMLElement))throw new Error('Bounds selector "'+Ke+'" could not find an element.');var P=He.getComputedStyle(Ye),x=He.getComputedStyle(xe);Ke={left:-Ye.offsetLeft+E(x.paddingLeft)+E(P.marginLeft),top:-Ye.offsetTop+E(x.paddingTop)+E(P.marginTop),right:ot(xe)-Ue(Ye)-Ye.offsetLeft+E(x.paddingRight)-E(P.marginRight),bottom:_e(xe)-Fe(Ye)-Ye.offsetTop+E(x.paddingBottom)-E(P.marginBottom)}}return D(Ke.right)&&(oe=Math.min(oe,Ke.right)),D(Ke.bottom)&&(we=Math.min(we,Ke.bottom)),D(Ke.left)&&(oe=Math.max(oe,Ke.left)),D(Ke.top)&&(we=Math.max(we,Ke.top)),[oe,we]}function De(re,oe,we){var Ke=Math.round(oe/re[0])*re[0],Ye=Math.round(we/re[1])*re[1];return[Ke,Ye]}function qe(re){return re.props.axis==="both"||re.props.axis==="x"}function mt(re){return re.props.axis==="both"||re.props.axis==="y"}function vt(re,oe,we){var Ke=typeof oe=="number"?ye(re,oe):null;if(typeof oe=="number"&&!Ke)return null;var Ye=F(we),Ee=we.props.offsetParent||Ye.offsetParent||Ye.ownerDocument.body;return Zt(Ke||re,Ee)}function ct(re,oe,we){var Ke=re.state,Ye=!D(Ke.lastX),Ee=F(re);return Ye?{node:Ee,deltaX:0,deltaY:0,lastX:oe,lastY:we,x:oe,y:we}:{node:Ee,deltaX:oe-Ke.lastX,deltaY:we-Ke.lastY,lastX:Ke.lastX,lastY:Ke.lastY,x:oe,y:we}}function Ht(re,oe){var we=re.props.scale;return{node:oe.node,x:re.state.x+oe.deltaX/we,y:re.state.y+oe.deltaY/we,deltaX:oe.deltaX/we,deltaY:oe.deltaY/we,lastX:re.state.x,lastY:re.state.y}}function ne(re){return{left:re.left,top:re.top,right:re.right,bottom:re.bottom}}function F(re){var oe=I.findDOMNode(re);if(!oe)throw new Error(": Unmounted during event!");return oe}function _(){}var fe={touch:{start:"touchstart",move:"touchmove",stop:"touchend"},mouse:{start:"mousedown",move:"mousemove",stop:"mouseup"}},ke=fe.mouse,ue=function(re){Ce(oe,re);function oe(){var we,Ke,Ye,Ee;te(this,oe);for(var He=arguments.length,xe=Array(He),P=0;P not mounted on DragStart!");var ce=Q.ownerDocument;if(!(Ye.props.disabled||!(x.target instanceof ce.defaultView.Node)||Ye.props.handle&&!Se(x.target,Ye.props.handle,Q)||Ye.props.cancel&&Se(x.target,Ye.props.cancel,Q))){var de=Xe(x);Ye.setState({touchIdentifier:de});var Je=vt(x,de,Ye);if(Je!=null){var Oe=Je.x,lt=Je.y,pt=ct(Ye,Oe,lt);Ye.props.onStart;var kt=Ye.props.onStart(x,pt);kt!==!1&&(Ye.props.enableUserSelectHack&&K(ce),Ye.setState({dragging:!0,lastX:Oe,lastY:lt}),Pe(ce,ke.move,Ye.handleDrag),Pe(ce,ke.stop,Ye.handleDragStop))}}},Ye.handleDrag=function(x){x.type==="touchmove"&&x.preventDefault();var Q=vt(x,Ye.state.touchIdentifier,Ye);if(Q!=null){var ce=Q.x,de=Q.y;if(Array.isArray(Ye.props.grid)){var Je=ce-Ye.state.lastX,Oe=de-Ye.state.lastY,lt=De(Ye.props.grid,Je,Oe),pt=Ge(lt,2);if(Je=pt[0],Oe=pt[1],!Je&&!Oe)return;ce=Ye.state.lastX+Je,de=Ye.state.lastY+Oe}var kt=ct(Ye,ce,de),ut=Ye.props.onDrag(x,kt);if(ut===!1){try{Ye.handleDragStop(new MouseEvent("mouseup"))}catch{var Vt=document.createEvent("MouseEvents");Vt.initMouseEvent("mouseup",!0,!0,window,0,0,0,0,0,!1,!1,!1,!1,0,null),Ye.handleDragStop(Vt)}return}Ye.setState({lastX:ce,lastY:de})}},Ye.handleDragStop=function(x){if(Ye.state.dragging){var Q=vt(x,Ye.state.touchIdentifier,Ye);if(Q!=null){var ce=Q.x,de=Q.y,Je=ct(Ye,ce,de),Oe=I.findDOMNode(Ye);Oe&&Ye.props.enableUserSelectHack&&T(Oe.ownerDocument),Ye.setState({dragging:!1,lastX:NaN,lastY:NaN}),Ye.props.onStop(x,Je),Oe&&(ze(Oe.ownerDocument,ke.move,Ye.handleDrag),ze(Oe.ownerDocument,ke.stop,Ye.handleDragStop))}}},Ye.onMouseDown=function(x){return ke=fe.mouse,Ye.handleDragStart(x)},Ye.onMouseUp=function(x){return ke=fe.mouse,Ye.handleDragStop(x)},Ye.onTouchStart=function(x){return ke=fe.touch,Ye.handleDragStart(x)},Ye.onTouchEnd=function(x){return ke=fe.touch,Ye.handleDragStop(x)},Ke),Ze(Ye,Ee)}return U(oe,[{key:"componentWillUnmount",value:function(){var Ke=I.findDOMNode(this);if(Ke){var Ye=Ke.ownerDocument;ze(Ye,fe.mouse.move,this.handleDrag),ze(Ye,fe.touch.move,this.handleDrag),ze(Ye,fe.mouse.stop,this.handleDragStop),ze(Ye,fe.touch.stop,this.handleDragStop),this.props.enableUserSelectHack&&T(Ye)}}},{key:"render",value:function(){return i.cloneElement(i.Children.only(this.props.children),{style:k(this.props.children.props.style),onMouseDown:this.onMouseDown,onTouchStart:this.onTouchStart,onMouseUp:this.onMouseUp,onTouchEnd:this.onTouchEnd})}}]),oe}(i.Component);ue.displayName="DraggableCore",ue.propTypes={allowAnyClick:W.bool,disabled:W.bool,enableUserSelectHack:W.bool,offsetParent:function(oe,we){if(oe[we]&&oe[we].nodeType!==1)throw new Error("Draggable's offsetParent must be a DOM Node.")},grid:W.arrayOf(W.number),scale:W.number,handle:W.string,cancel:W.string,onStart:W.func,onDrag:W.func,onStop:W.func,onMouseDown:W.func,className:O,style:O,transform:O},ue.defaultProps={allowAnyClick:!1,cancel:null,disabled:!1,enableUserSelectHack:!0,offsetParent:null,handle:null,grid:null,transform:null,onStart:function(){},onDrag:function(){},onStop:function(){},onMouseDown:function(){}};var le=function(re){Ce(oe,re);function oe(we){te(this,oe);var Ke=Ze(this,(oe.__proto__||Object.getPrototypeOf(oe)).call(this,we));return Ke.onDragStart=function(Ye,Ee){var He=Ke.props.onStart(Ye,Ht(Ke,Ee));if(He===!1)return!1;Ke.setState({dragging:!0,dragged:!0})},Ke.onDrag=function(Ye,Ee){if(!Ke.state.dragging)return!1;var He=Ht(Ke,Ee),xe={x:He.x,y:He.y};if(Ke.props.bounds){var P=xe.x,x=xe.y;xe.x+=Ke.state.slackX,xe.y+=Ke.state.slackY;var Q=Ve(Ke,xe.x,xe.y),ce=Ge(Q,2),de=ce[0],Je=ce[1];xe.x=de,xe.y=Je,xe.slackX=Ke.state.slackX+(P-xe.x),xe.slackY=Ke.state.slackY+(x-xe.y),He.x=xe.x,He.y=xe.y,He.deltaX=xe.x-Ke.state.x,He.deltaY=xe.y-Ke.state.y}var Oe=Ke.props.onDrag(Ye,He);if(Oe===!1)return!1;Ke.setState(xe)},Ke.onDragStop=function(Ye,Ee){if(!Ke.state.dragging)return!1;var He=Ke.props.onStop(Ye,Ht(Ke,Ee));if(He===!1)return!1;var xe={dragging:!1,slackX:0,slackY:0},P=!!Ke.props.position;if(P){var x=Ke.props.position,Q=x.x,ce=x.y;xe.x=Q,xe.y=ce}Ke.setState(xe)},Ke.state={dragging:!1,dragged:!1,x:we.position?we.position.x:we.defaultPosition.x,y:we.position?we.position.y:we.defaultPosition.y,slackX:0,slackY:0,isElementSVG:!1},we.position&&!(we.onDrag||we.onStop)&&console.warn("A `position` was applied to this , without drag handlers. This will make this component effectively undraggable. Please attach `onDrag` or `onStop` handlers so you can adjust the `position` of this element."),Ke}return U(oe,[{key:"componentDidMount",value:function(){typeof window.SVGElement<"u"&&I.findDOMNode(this)instanceof window.SVGElement&&this.setState({isElementSVG:!0})}},{key:"componentWillReceiveProps",value:function(Ke){Ke.position&&(!this.props.position||Ke.position.x!==this.props.position.x||Ke.position.y!==this.props.position.y)&&this.setState({x:Ke.position.x,y:Ke.position.y})}},{key:"componentWillUnmount",value:function(){this.setState({dragging:!1})}},{key:"render",value:function(){var Ke,Ye={},Ee=null,He=!!this.props.position,xe=!He||this.state.dragging,P=this.props.position||this.props.defaultPosition,x={x:qe(this)&&xe?this.state.x:P.x,y:mt(this)&&xe?this.state.y:P.y};this.state.isElementSVG?Ee=Te(x,this.props.positionOffset):Ye=nt(x,this.props.positionOffset);var Q=this.props,ce=Q.defaultClassName,de=Q.defaultClassNameDragging,Je=Q.defaultClassNameDragged,Oe=i.Children.only(this.props.children),lt=R(Oe.props.className||"",ce,(Ke={},ie(Ke,de,this.state.dragging),ie(Ke,Je,this.state.dragged),Ke));return i.createElement(ue,me({},this.props,{onStart:this.onDragStart,onDrag:this.onDrag,onStop:this.onDragStop}),i.cloneElement(Oe,{className:lt,style:me({},Oe.props.style,Ye),transform:Ee}))}}]),oe}(i.Component);return le.displayName="Draggable",le.propTypes=me({},ue.propTypes,{axis:W.oneOf(["both","x","y","none"]),bounds:W.oneOfType([W.shape({left:W.number,right:W.number,top:W.number,bottom:W.number}),W.string,W.oneOf([!1])]),defaultClassName:W.string,defaultClassNameDragging:W.string,defaultClassNameDragged:W.string,defaultPosition:W.shape({x:W.number,y:W.number}),positionOffset:W.shape({x:W.oneOfType([W.number,W.string]),y:W.oneOfType([W.number,W.string])}),position:W.shape({x:W.number,y:W.number}),className:O,style:O,transform:O}),le.defaultProps=me({},ue.defaultProps,{axis:"both",bounds:!1,defaultClassName:"react-draggable",defaultClassNameDragging:"react-draggable-dragging",defaultClassNameDragged:"react-draggable-dragged",defaultPosition:{x:0,y:0},position:null,scale:1}),le.default=le,le.DraggableCore=ue,le})})(pye);var cnt=pye.exports,zT={exports:{}},GS={},PT={exports:{}},bye={};function yye(e){var g,I,i="";if(typeof e=="string"||typeof e=="number")i+=e;else if(typeof e=="object")if(Array.isArray(e))for(g=0;g0&&arguments[0]!==void 0?arguments[0]:"transform";if(typeof window>"u")return"";const I=(e=window.document)===null||e===void 0||(e=e.documentElement)===null||e===void 0?void 0:e.style;if(!I||g in I)return"";for(let i=0;ig===I.identifier)||e.changedTouches&&(0,ar.findInArray)(e.changedTouches,I=>g===I.identifier)}function knt(e){if(e.targetTouches&&e.targetTouches[0])return e.targetTouches[0].identifier;if(e.changedTouches&&e.changedTouches[0])return e.changedTouches[0].identifier}function Ynt(e){if(!e)return;let g=e.getElementById("react-draggable-style-el");g||(g=e.createElement("style"),g.type="text/css",g.id="react-draggable-style-el",g.innerHTML=`.react-draggable-transparent-selection *::-moz-selection {all: inherit;} +`,g.innerHTML+=`.react-draggable-transparent-selection *::selection {all: inherit;} +`,e.getElementsByTagName("head")[0].appendChild(g)),e.body&&Sye(e.body,"react-draggable-transparent-selection")}function Knt(e){if(e)try{if(e.body&&wye(e.body,"react-draggable-transparent-selection"),e.selection)e.selection.empty();else{const g=(e.defaultView||window).getSelection();g&&g.type!=="Caret"&&g.removeAllRanges()}}catch{}}function Sye(e,g){e.classList?e.classList.add(g):e.className.match(new RegExp("(?:^|\\s)".concat(g,"(?!\\S)")))||(e.className+=" ".concat(g))}function wye(e,g){e.classList?e.classList.remove(g):e.className=e.className.replace(new RegExp("(?:^|\\s)".concat(g,"(?!\\S)"),"g"),"")}var va={};Object.defineProperty(va,"__esModule",{value:!0});va.canDragX=Fnt;va.canDragY=Ent;va.createCoreData=znt;va.createDraggableData=Pnt;va.getBoundPosition=Dnt;va.getControlPosition=Mnt;va.snapToGrid=xnt;var JC=Ga,Lf=ei;function Dnt(e,g,I){if(!e.props.bounds)return[g,I];let{bounds:i}=e.props;i=typeof i=="string"?i:Jnt(i);const n=d7(e);if(typeof i=="string"){const{ownerDocument:C}=n,r=C.defaultView;let o;if(i==="parent"?o=n.parentNode:o=C.querySelector(i),!(o instanceof r.HTMLElement))throw new Error('Bounds selector "'+i+'" could not find an element.');const A=o,s=r.getComputedStyle(n),a=r.getComputedStyle(A);i={left:-n.offsetLeft+(0,JC.int)(a.paddingLeft)+(0,JC.int)(s.marginLeft),top:-n.offsetTop+(0,JC.int)(a.paddingTop)+(0,JC.int)(s.marginTop),right:(0,Lf.innerWidth)(A)-(0,Lf.outerWidth)(n)-n.offsetLeft+(0,JC.int)(a.paddingRight)-(0,JC.int)(s.marginRight),bottom:(0,Lf.innerHeight)(A)-(0,Lf.outerHeight)(n)-n.offsetTop+(0,JC.int)(a.paddingBottom)-(0,JC.int)(s.marginBottom)}}return(0,JC.isNum)(i.right)&&(g=Math.min(g,i.right)),(0,JC.isNum)(i.bottom)&&(I=Math.min(I,i.bottom)),(0,JC.isNum)(i.left)&&(g=Math.max(g,i.left)),(0,JC.isNum)(i.top)&&(I=Math.max(I,i.top)),[g,I]}function xnt(e,g,I){const i=Math.round(g/e[0])*e[0],n=Math.round(I/e[1])*e[1];return[i,n]}function Fnt(e){return e.props.axis==="both"||e.props.axis==="x"}function Ent(e){return e.props.axis==="both"||e.props.axis==="y"}function Mnt(e,g,I){const i=typeof g=="number"?(0,Lf.getTouch)(e,g):null;if(typeof g=="number"&&!i)return null;const n=d7(I),C=I.props.offsetParent||n.offsetParent||n.ownerDocument.body;return(0,Lf.offsetXYFromParent)(i||e,C,I.props.scale)}function znt(e,g,I){const i=!(0,JC.isNum)(e.lastX),n=d7(e);return i?{node:n,deltaX:0,deltaY:0,lastX:g,lastY:I,x:g,y:I}:{node:n,deltaX:g-e.lastX,deltaY:I-e.lastY,lastX:e.lastX,lastY:e.lastY,x:g,y:I}}function Pnt(e,g){const I=e.props.scale;return{node:g.node,x:e.state.x+g.deltaX/I,y:e.state.y+g.deltaY/I,deltaX:g.deltaX/I,deltaY:g.deltaY/I,lastX:e.state.x,lastY:e.state.y}}function Jnt(e){return{left:e.left,top:e.top,right:e.right,bottom:e.bottom}}function d7(e){const g=e.findDOMNode();if(!g)throw new Error(": Unmounted during event!");return g}var JT={},OT={};Object.defineProperty(OT,"__esModule",{value:!0});OT.default=Ont;function Ont(){}function _nt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function uge(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function EX(e){return EX=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},EX(e)}Object.defineProperty(JT,"__esModule",{value:!0});JT.default=void 0;var h5=gCt(N),uC=h7(_s),tCt=h7(UI),Gn=ei,ul=va,m5=Ga,Ky=h7(OT);function h7(e){return e&&e.__esModule?e:{default:e}}function Vye(e){if(typeof WeakMap!="function")return null;var g=new WeakMap,I=new WeakMap;return(Vye=function(i){return i?I:g})(e)}function gCt(e,g){if(!g&&e&&e.__esModule)return e;if(e===null||typeof e!="object"&&typeof e!="function")return{default:e};var I=Vye(g);if(I&&I.has(e))return I.get(e);var i={},n=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var C in e)if(C!=="default"&&Object.prototype.hasOwnProperty.call(e,C)){var r=n?Object.getOwnPropertyDescriptor(e,C):null;r&&(r.get||r.set)?Object.defineProperty(i,C,r):i[C]=e[C]}return i.default=e,I&&I.set(e,i),i}function Mn(e,g,I){return g=ICt(g),g in e?Object.defineProperty(e,g,{value:I,enumerable:!0,configurable:!0,writable:!0}):e[g]=I,e}function ICt(e){var g=iCt(e,"string");return typeof g=="symbol"?g:String(g)}function iCt(e,g){if(typeof e!="object"||e===null)return e;var I=e[Symbol.toPrimitive];if(I!==void 0){var i=I.call(e,g||"default");if(typeof i!="object")return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return(g==="string"?String:Number)(e)}const Xo={touch:{start:"touchstart",move:"touchmove",stop:"touchend"},mouse:{start:"mousedown",move:"mousemove",stop:"mouseup"}};let dl=Xo.mouse,_T=function(e){jnt(I,e);var g=$nt(I);function I(){var i;return _nt(this,I),i=g.apply(this,arguments),Mn(bi(i),"dragging",!1),Mn(bi(i),"lastX",NaN),Mn(bi(i),"lastY",NaN),Mn(bi(i),"touchIdentifier",null),Mn(bi(i),"mounted",!1),Mn(bi(i),"handleDragStart",n=>{if(i.props.onMouseDown(n),!i.props.allowAnyClick&&typeof n.button=="number"&&n.button!==0)return!1;const C=i.findDOMNode();if(!C||!C.ownerDocument||!C.ownerDocument.body)throw new Error(" not mounted on DragStart!");const{ownerDocument:r}=C;if(i.props.disabled||!(n.target instanceof r.defaultView.Node)||i.props.handle&&!(0,Gn.matchesSelectorAndParentsTo)(n.target,i.props.handle,C)||i.props.cancel&&(0,Gn.matchesSelectorAndParentsTo)(n.target,i.props.cancel,C))return;n.type==="touchstart"&&n.preventDefault();const o=(0,Gn.getTouchIdentifier)(n);i.touchIdentifier=o;const A=(0,ul.getControlPosition)(n,o,bi(i));if(A==null)return;const{x:s,y:a}=A,l=(0,ul.createCoreData)(bi(i),s,a);(0,Ky.default)("DraggableCore: handleDragStart: %j",l),(0,Ky.default)("calling",i.props.onStart),!(i.props.onStart(n,l)===!1||i.mounted===!1)&&(i.props.enableUserSelectHack&&(0,Gn.addUserSelectStyles)(r),i.dragging=!0,i.lastX=s,i.lastY=a,(0,Gn.addEvent)(r,dl.move,i.handleDrag),(0,Gn.addEvent)(r,dl.stop,i.handleDragStop))}),Mn(bi(i),"handleDrag",n=>{const C=(0,ul.getControlPosition)(n,i.touchIdentifier,bi(i));if(C==null)return;let{x:r,y:o}=C;if(Array.isArray(i.props.grid)){let a=r-i.lastX,l=o-i.lastY;if([a,l]=(0,ul.snapToGrid)(i.props.grid,a,l),!a&&!l)return;r=i.lastX+a,o=i.lastY+l}const A=(0,ul.createCoreData)(bi(i),r,o);if((0,Ky.default)("DraggableCore: handleDrag: %j",A),i.props.onDrag(n,A)===!1||i.mounted===!1){try{i.handleDragStop(new MouseEvent("mouseup"))}catch{const l=document.createEvent("MouseEvents");l.initMouseEvent("mouseup",!0,!0,window,0,0,0,0,0,!1,!1,!1,!1,0,null),i.handleDragStop(l)}return}i.lastX=r,i.lastY=o}),Mn(bi(i),"handleDragStop",n=>{if(!i.dragging)return;const C=(0,ul.getControlPosition)(n,i.touchIdentifier,bi(i));if(C==null)return;let{x:r,y:o}=C;if(Array.isArray(i.props.grid)){let l=r-i.lastX||0,c=o-i.lastY||0;[l,c]=(0,ul.snapToGrid)(i.props.grid,l,c),r=i.lastX+l,o=i.lastY+c}const A=(0,ul.createCoreData)(bi(i),r,o);if(i.props.onStop(n,A)===!1||i.mounted===!1)return!1;const a=i.findDOMNode();a&&i.props.enableUserSelectHack&&(0,Gn.removeUserSelectStyles)(a.ownerDocument),(0,Ky.default)("DraggableCore: handleDragStop: %j",A),i.dragging=!1,i.lastX=NaN,i.lastY=NaN,a&&((0,Ky.default)("DraggableCore: Removing handlers"),(0,Gn.removeEvent)(a.ownerDocument,dl.move,i.handleDrag),(0,Gn.removeEvent)(a.ownerDocument,dl.stop,i.handleDragStop))}),Mn(bi(i),"onMouseDown",n=>(dl=Xo.mouse,i.handleDragStart(n))),Mn(bi(i),"onMouseUp",n=>(dl=Xo.mouse,i.handleDragStop(n))),Mn(bi(i),"onTouchStart",n=>(dl=Xo.touch,i.handleDragStart(n))),Mn(bi(i),"onTouchEnd",n=>(dl=Xo.touch,i.handleDragStop(n))),i}return Lnt(I,[{key:"componentDidMount",value:function(){this.mounted=!0;const n=this.findDOMNode();n&&(0,Gn.addEvent)(n,Xo.touch.start,this.onTouchStart,{passive:!1})}},{key:"componentWillUnmount",value:function(){this.mounted=!1;const n=this.findDOMNode();if(n){const{ownerDocument:C}=n;(0,Gn.removeEvent)(C,Xo.mouse.move,this.handleDrag),(0,Gn.removeEvent)(C,Xo.touch.move,this.handleDrag),(0,Gn.removeEvent)(C,Xo.mouse.stop,this.handleDragStop),(0,Gn.removeEvent)(C,Xo.touch.stop,this.handleDragStop),(0,Gn.removeEvent)(n,Xo.touch.start,this.onTouchStart,{passive:!1}),this.props.enableUserSelectHack&&(0,Gn.removeUserSelectStyles)(C)}}},{key:"findDOMNode",value:function(){var n,C;return(n=this.props)!==null&&n!==void 0&&n.nodeRef?(C=this.props)===null||C===void 0||(C=C.nodeRef)===null||C===void 0?void 0:C.current:tCt.default.findDOMNode(this)}},{key:"render",value:function(){return h5.cloneElement(h5.Children.only(this.props.children),{onMouseDown:this.onMouseDown,onMouseUp:this.onMouseUp,onTouchEnd:this.onTouchEnd})}}]),I}(h5.Component);JT.default=_T;Mn(_T,"displayName","DraggableCore");Mn(_T,"propTypes",{allowAnyClick:uC.default.bool,children:uC.default.node.isRequired,disabled:uC.default.bool,enableUserSelectHack:uC.default.bool,offsetParent:function(e,g){if(e[g]&&e[g].nodeType!==1)throw new Error("Draggable's offsetParent must be a DOM Node.")},grid:uC.default.arrayOf(uC.default.number),handle:uC.default.string,cancel:uC.default.string,nodeRef:uC.default.object,onStart:uC.default.func,onDrag:uC.default.func,onStop:uC.default.func,onMouseDown:uC.default.func,scale:uC.default.number,className:m5.dontSetMe,style:m5.dontSetMe,transform:m5.dontSetMe});Mn(_T,"defaultProps",{allowAnyClick:!1,disabled:!1,enableUserSelectHack:!0,onStart:function(){},onDrag:function(){},onStop:function(){},onMouseDown:function(){},scale:1});(function(e){function g(R,H){if(!(R instanceof H))throw new TypeError("Cannot call a class as a function")}function I(R,H){for(var Y=0;Y"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function c(R){return c=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(Y){return Y.__proto__||Object.getPrototypeOf(Y)},c(R)}Object.defineProperty(e,"__esModule",{value:!0}),Object.defineProperty(e,"DraggableCore",{enumerable:!0,get:function(){return y.default}}),e.default=void 0;var u=v(N),d=B(_s),h=B(UI),m=B(dnt),f=ei,b=va,p=Ga,y=B(JT),Z=B(OT);function B(R){return R&&R.__esModule?R:{default:R}}function G(R){if(typeof WeakMap!="function")return null;var H=new WeakMap,Y=new WeakMap;return(G=function(D){return D?Y:H})(R)}function v(R,H){if(!H&&R&&R.__esModule)return R;if(R===null||typeof R!="object"&&typeof R!="function")return{default:R};var Y=G(H);if(Y&&Y.has(R))return Y.get(R);var D={},E=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var O in R)if(O!=="default"&&Object.prototype.hasOwnProperty.call(R,O)){var J=E?Object.getOwnPropertyDescriptor(R,O):null;J&&(J.get||J.set)?Object.defineProperty(D,O,J):D[O]=R[O]}return D.default=R,Y&&Y.set(R,D),D}function w(){return w=Object.assign?Object.assign.bind():function(R){for(var H=1;H{if((0,Z.default)("Draggable: onDragStart: %j",J),E.props.onStart(O,(0,b.createDraggableData)(a(E),J))===!1)return!1;E.setState({dragging:!0,dragged:!0})}),V(a(E),"onDrag",(O,J)=>{if(!E.state.dragging)return!1;(0,Z.default)("Draggable: onDrag: %j",J);const ee=(0,b.createDraggableData)(a(E),J),q={x:ee.x,y:ee.y,slackX:0,slackY:0};if(E.props.bounds){const{x:j,y:te}=q;q.x+=E.state.slackX,q.y+=E.state.slackY;const[U,ie]=(0,b.getBoundPosition)(a(E),q.x,q.y);q.x=U,q.y=ie,q.slackX=E.state.slackX+(j-q.x),q.slackY=E.state.slackY+(te-q.y),ee.x=q.x,ee.y=q.y,ee.deltaX=q.x-E.state.x,ee.deltaY=q.y-E.state.y}if(E.props.onDrag(O,ee)===!1)return!1;E.setState(q)}),V(a(E),"onDragStop",(O,J)=>{if(!E.state.dragging||E.props.onStop(O,(0,b.createDraggableData)(a(E),J))===!1)return!1;(0,Z.default)("Draggable: onDragStop: %j",J);const q={dragging:!1,slackX:0,slackY:0};if(!!E.props.position){const{x:j,y:te}=E.props.position;q.x=j,q.y=te}E.setState(q)}),E.state={dragging:!1,dragged:!1,x:D.position?D.position.x:D.defaultPosition.x,y:D.position?D.position.y:D.defaultPosition.y,prevPropsPosition:{...D.position},slackX:0,slackY:0,isElementSVG:!1},D.position&&!(D.onDrag||D.onStop)&&console.warn("A `position` was applied to this , without drag handlers. This will make this component effectively undraggable. Please attach `onDrag` or `onStop` handlers so you can adjust the `position` of this element."),E}return i(Y,[{key:"componentDidMount",value:function(){typeof window.SVGElement<"u"&&this.findDOMNode()instanceof window.SVGElement&&this.setState({isElementSVG:!0})}},{key:"componentWillUnmount",value:function(){this.setState({dragging:!1})}},{key:"findDOMNode",value:function(){var E,O;return(E=(O=this.props)===null||O===void 0||(O=O.nodeRef)===null||O===void 0?void 0:O.current)!==null&&E!==void 0?E:h.default.findDOMNode(this)}},{key:"render",value:function(){const{axis:E,bounds:O,children:J,defaultPosition:ee,defaultClassName:q,defaultClassNameDragging:$,defaultClassNameDragged:j,position:te,positionOffset:U,scale:ie,...me}=this.props;let Ce={},Ze=null;const Be=!!!te||this.state.dragging,Ne=te||ee,Se={x:(0,b.canDragX)(this)&&Be?this.state.x:Ne.x,y:(0,b.canDragY)(this)&&Be?this.state.y:Ne.y};this.state.isElementSVG?Ze=(0,f.createSVGTransform)(Se,U):Ce=(0,f.createCSSTransform)(Se,U);const Pe=(0,m.default)(J.props.className||"",q,{[$]:this.state.dragging,[j]:this.state.dragged});return u.createElement(y.default,w({},me,{onStart:this.onDragStart,onDrag:this.onDrag,onStop:this.onDragStop}),u.cloneElement(u.Children.only(J),{className:Pe,style:{...J.props.style,...Ce},transform:Ze}))}}],[{key:"getDerivedStateFromProps",value:function(E,O){let{position:J}=E,{prevPropsPosition:ee}=O;return J&&(!ee||J.x!==ee.x||J.y!==ee.y)?((0,Z.default)("Draggable: getDerivedStateFromProps %j",{position:J,prevPropsPosition:ee}),{x:J.x,y:J.y,prevPropsPosition:{...J}}):null}}]),Y}(u.Component);e.default=W,V(W,"displayName","Draggable"),V(W,"propTypes",{...y.default.propTypes,axis:d.default.oneOf(["both","x","y","none"]),bounds:d.default.oneOfType([d.default.shape({left:d.default.number,right:d.default.number,top:d.default.number,bottom:d.default.number}),d.default.string,d.default.oneOf([!1])]),defaultClassName:d.default.string,defaultClassNameDragging:d.default.string,defaultClassNameDragged:d.default.string,defaultPosition:d.default.shape({x:d.default.number,y:d.default.number}),positionOffset:d.default.shape({x:d.default.oneOfType([d.default.number,d.default.string]),y:d.default.oneOfType([d.default.number,d.default.string])}),position:d.default.shape({x:d.default.number,y:d.default.number}),className:p.dontSetMe,style:p.dontSetMe,transform:p.dontSetMe}),V(W,"defaultProps",{...y.default.defaultProps,axis:"both",bounds:!1,defaultClassName:"react-draggable",defaultClassNameDragging:"react-draggable-dragging",defaultClassNameDragged:"react-draggable-dragged",defaultPosition:{x:0,y:0},scale:1})})(bye);const{default:Rye,DraggableCore:nCt}=bye;PT.exports=Rye;PT.exports.default=Rye;PT.exports.DraggableCore=nCt;var CCt=PT.exports,m7={};m7.__esModule=!0;m7.cloneElement=aCt;var rCt=oCt(N);function oCt(e){return e&&e.__esModule?e:{default:e}}function dge(e,g){var I=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);g&&(i=i.filter(function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable})),I.push.apply(I,i)}return I}function hge(e){for(var g=1;g=0)&&(I[n]=e[n]);return I}function p5(e){if(e===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function fCt(e,g){e.prototype=Object.create(g.prototype),e.prototype.constructor=e,e.__proto__=g}function yp(e,g,I){return g in e?Object.defineProperty(e,g,{value:I,enumerable:!0,configurable:!0,writable:!0}):e[g]=I,e}var f7=function(e){fCt(g,e);function g(){for(var i,n=arguments.length,C=new Array(n),r=0;r=0)&&(I[n]=e[n]);return I}function bge(e){if(e===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function vCt(e,g){e.prototype=Object.create(g.prototype),e.prototype.constructor=e,e.__proto__=g}function zX(e,g,I){return g in e?Object.defineProperty(e,g,{value:I,enumerable:!0,configurable:!0,writable:!0}):e[g]=I,e}var Hye=function(e){vCt(g,e);function g(){for(var i,n=arguments.length,C=new Array(n),r=0;rg.w||i>g.maxW)return new Error("minWidth larger than item width/maxWidth")},maxW:function(g,I){var i=g[I];if(typeof i!="number")return new Error("maxWidth not Number");if(ig.h||i>g.maxH)return new Error("minHeight larger than item height/maxHeight")},maxH:function(g,I){var i=g[I];if(typeof i!="number")return new Error("maxHeight not Number");if(i0,m){var b=1/0,p=1/0;f.forEach(function(Z){Z.x>h.x&&(b=Math.min(b,Z.x)),Z.y>h.y&&(p=Math.min(p,Z.y))}),Number.isFinite(b)&&(h.w=b-h.x),Number.isFinite(p)&&(h.h=p-h.y)}}m||(h.w=n,h.h=C);var y={w:h.w,h:h.h,x:h.x,y:h.y,static:!0,i};this.props.onResize(a,l,h,y,o,A),this.setState({layout:(0,Fg.compact)(a,this.compactType(),u),activeDrag:y})}},g.prototype.onResizeStop=function(i,n,C,r){var o=r.e,A=r.node,s=this.state,a=s.layout,l=s.oldResizeItem,c=this.props.cols,u=(0,Fg.getLayoutItem)(a,i);this.props.onResizeStop(a,l,u,null,o,A);var d=(0,Fg.compact)(a,this.compactType(),c),h=this.state.oldLayout;this.setState({activeDrag:null,layout:d,oldResizeItem:null,oldLayout:null}),this.onLayoutMaybeChanged(d,h)},g.prototype.placeholder=function(){var i=this.state.activeDrag;if(!i)return null;var n=this.props,C=n.width,r=n.cols,o=n.margin,A=n.containerPadding,s=n.rowHeight,a=n.maxRows,l=n.useCSSTransforms;return xu.default.createElement(vge.default,{w:i.w,h:i.h,x:i.x,y:i.y,i:i.i,className:"react-grid-placeholder",containerWidth:C,cols:r,margin:o,containerPadding:A||o,maxRows:a,rowHeight:s,isDraggable:!1,isResizable:!1,useCSSTransforms:l},xu.default.createElement("div",null))},g.prototype.processGridItem=function(i){if(!(!i||!i.key)){var n=(0,Fg.getLayoutItem)(this.state.layout,String(i.key));if(!n)return null;var C=this.props,r=C.width,o=C.cols,A=C.margin,s=C.containerPadding,a=C.rowHeight,l=C.maxRows,c=C.isDraggable,u=C.isResizable,d=C.useCSSTransforms,h=C.draggableCancel,m=C.draggableHandle,f=this.state.mounted,b=!!(!n.static&&c&&(n.isDraggable||n.isDraggable==null)),p=!!(!n.static&&u&&(n.isResizable||n.isResizable==null));return xu.default.createElement(vge.default,{containerWidth:r,cols:o,margin:A,containerPadding:s||A,maxRows:l,rowHeight:a,cancel:h,handle:m,onDragStop:this.onDragStop,onDragStart:this.onDragStart,onDrag:this.onDrag,onResizeStart:this.onResizeStart,onResize:this.onResize,onResizeStop:this.onResizeStop,isDraggable:b,isResizable:p,useCSSTransforms:d&&f,usePercentages:!f,w:n.w,h:n.h,x:n.x,y:n.y,i:n.i,minH:n.minH,minW:n.minW,maxH:n.maxH,maxW:n.maxW,static:n.static},i)}},g.prototype.render=function(){var i=this,n=this.props,C=n.className,r=n.style,o=(0,xCt.default)("react-grid-layout",C),A=Zge({height:this.containerHeight()},r);return xu.default.createElement("div",{className:o,style:A},xu.default.Children.map(this.props.children,function(s){return i.processGridItem(s)}),this.placeholder())},g}(xu.default.Component);UT.displayName="ReactGridLayout";UT.propTypes={className:lI.default.string,style:lI.default.object,width:lI.default.number,autoSize:lI.default.bool,cols:lI.default.number,draggableCancel:lI.default.string,draggableHandle:lI.default.string,verticalCompact:function(g){g.verticalCompact},compactType:lI.default.oneOf(["vertical","horizontal"]),layout:function(g){var I=g.layout;I!==void 0&&(0,Fg.validateLayout)(I,"layout")},margin:lI.default.arrayOf(lI.default.number),containerPadding:lI.default.arrayOf(lI.default.number),rowHeight:lI.default.number,maxRows:lI.default.number,isDraggable:lI.default.bool,isResizable:lI.default.bool,preventCollision:lI.default.bool,useCSSTransforms:lI.default.bool,onLayoutChange:lI.default.func,onDragStart:lI.default.func,onDrag:lI.default.func,onDragStop:lI.default.func,onResizeStart:lI.default.func,onResize:lI.default.func,onResizeStop:lI.default.func,children:function(g,I){var i=g[I],n={};xu.default.Children.forEach(i,function(C){if(n[C.key])throw new Error('Duplicate child key "'+C.key+'" found! This will cause problems in ReactGridLayout.');n[C.key]=!0})}};UT.defaultProps={autoSize:!0,cols:12,className:"",style:{},draggableHandle:"",draggableCancel:"",containerPadding:null,rowHeight:150,maxRows:1/0,layout:[],margin:[10,10],isDraggable:!0,isResizable:!0,useCSSTransforms:!0,verticalCompact:!0,compactType:"vertical",preventCollision:!1,onLayoutChange:Fg.noop,onDragStart:Fg.noop,onDrag:Fg.noop,onDragStop:Fg.noop,onResizeStart:Fg.noop,onResize:Fg.noop,onResizeStop:Fg.noop};var PCt=function(){this.state={activeDrag:null,layout:(0,Fg.synchronizeLayoutWithChildren)(this.props.layout,this.props.children,this.props.cols,this.compactType()),mounted:!1,oldDragItem:null,oldLayout:null,oldResizeItem:null}};FT.default=UT;var y7={},Qh={};Qh.__esModule=!0;Qh.getBreakpointFromWidth=JCt;Qh.getColsFromBreakpoint=OCt;Qh.findOrGenerateResponsiveLayout=_Ct;Qh.sortBreakpoints=Z7;var FV=Yg;function JCt(e,g){for(var I=Z7(e),i=I[0],n=1,C=I.length;ne[r]&&(i=r)}return i}function OCt(e,g){if(!g[e])throw new Error("ResponsiveReactGridLayout: `cols` entry for breakpoint "+e+" is missing!");return g[e]}function _Ct(e,g,I,i,n,C){if(e[I])return(0,FV.cloneLayout)(e[I]);for(var r=e[i],o=Z7(g),A=o.slice(o.indexOf(I)),s=0,a=A.length;s=0||Object.prototype.hasOwnProperty.call(e,i)&&(I[i]=e[i]);return I}function ert(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function wge(e,g){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return g&&(typeof g=="object"||typeof g=="function")?g:e}function trt(e,g){if(typeof g!="function"&&g!==null)throw new TypeError("Super expression must either be null or a function, not "+typeof g);e.prototype=Object.create(g&&g.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),g&&(Object.setPrototypeOf?Object.setPrototypeOf(e,g):e.__proto__=g)}var Vge=function(g){return Object.prototype.toString.call(g)},G7=function(e){trt(g,e);function g(){var I,i,n;ert(this,g);for(var C=arguments.length,r=Array(C),o=0;o=0||Object.prototype.hasOwnProperty.call(e,i)&&(I[i]=e[i]);return I}function Art(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function Rge(e,g){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return g&&(typeof g=="object"||typeof g=="function")?g:e}function art(e,g){if(typeof g!="function"&&g!==null)throw new TypeError("Super expression must either be null or a function, not "+typeof g);e.prototype=Object.create(g&&g.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),g&&(Object.setPrototypeOf?Object.setPrototypeOf(e,g):e.__proto__=g)}function srt(e){var g,I;return I=g=function(i){art(n,i);function n(){var C,r,o;Art(this,n);for(var A=arguments.length,s=Array(A),a=0;a"u")return null;var I=typeof window<"u"&&window.Math==Math?window:typeof self<"u"&&self.Math==Math?self:Function("return this")(),i=I.requestAnimationFrame||I.mozRequestAnimationFrame||I.webkitRequestAnimationFrame||function(a){return I.setTimeout(a,20)},n=I.cancelAnimationFrame||I.mozCancelAnimationFrame||I.webkitCancelAnimationFrame||function(a){I.clearTimeout(a)};function C(a,l){var c=Object.prototype.toString.call(a),u=c==="[object Array]"||c==="[object NodeList]"||c==="[object HTMLCollection]"||c==="[object Object]"||typeof jQuery<"u"&&a instanceof jQuery||typeof Elements<"u"&&a instanceof Elements,d=0,h=a.length;if(u)for(;d=X&&(H+=V.value),V.mode==="max"&&W<=X&&(H+=V.value),R[Y]||(R[Y]=""),H&&(" "+R[Y]+" ").indexOf(" "+H+" ")===-1&&(R[Y]+=" "+H));for(var E in D)D.hasOwnProperty(E)&&(R[D[E]]?this.element.setAttribute(D[E],R[D[E]].substr(1)):this.element.removeAttribute(D[E]))}}function c(G,v){G.elementQueriesSetupInformation||(G.elementQueriesSetupInformation=new l(G,v)),G.elementQueriesSensor||(G.elementQueriesSensor=new I(G,function(){G.elementQueriesSetupInformation.call()}))}function u(G,v,w,V){if(typeof r[G]>"u"){r[G]=[];var S=o.length;C.innerHTML+=` `+G+" {animation: 0.1s element-queries;}",C.innerHTML+=` -`+G+" > .resize-sensor {min-width: "+S+"px;}",o.push(G)}r[G].push({mode:B,property:w,value:R})}function d(G){var B;if(document.querySelectorAll&&(B=G?G.querySelectorAll.bind(G):document.querySelectorAll.bind(document)),!B&&typeof $$<"u"&&(B=$$),!B&&typeof jQuery<"u"&&(B=jQuery),!B)throw"No document.querySelectorAll, jQuery or Mootools's $$ found.";return B}function h(G){var B=d(G);for(var w in r)if(r.hasOwnProperty(w))for(var R=B(w,G),S=0,X=R.length;Sw[J].minWidth&&(_=J);if(_||(_=S),X!==_)if(W[_])B[X].style.display="none",B[_].style.display="block",X=_;else{var te=new Image;te.onload=function(){B[_].src=R[_],B[X].style.display="none",B[_].style.display="block",W[_]=!0,X=_},te.src=R[_]}else B[_].src=R[_]}G.resizeSensorInstance=new I(G,F),F()}function f(){for(var G=d(),B=G("[data-responsive-image],[responsive-image]"),w=0,R=B.length;w img, [data-responsive-image] {overflow: hidden; padding: 0; } [responsive-image] > img, [data-responsive-image] > img {width: 100%;}",C.innerHTML+=` -@keyframes element-queries { 0% { visibility: inherit; } }`,document.getElementsByTagName("head")[0].appendChild(C),v=!0);for(var B=0,w=document.styleSheets.length;B\s{0,}<").replace(/-1?(r+=A[C]+I[o],n=!0,(I[o].search(/-->/)>-1||I[o].search(/\]>/)>-1||I[o].search(/!DOCTYPE/)>-1)&&(n=!1)):I[o].search(/-->/)>-1||I[o].search(/\]>/)>-1?(r+=I[o],n=!1):/^<\w/.exec(I[o-1])&&/^<\/\w/.exec(I[o])&&/^<[\w:\-\.\,]+/.exec(I[o-1])==/^<\/[\w:\-\.\,]+/.exec(I[o])[0].replace("/","")?(r+=I[o],n||C--):I[o].search(/<\w/)>-1&&I[o].search(/<\//)==-1&&I[o].search(/\/>/)==-1?r=n?r+=I[o]:r+=A[C++]+I[o]:I[o].search(/<\w/)>-1&&I[o].search(/<\//)>-1?r=n?r+=I[o]:r+=A[C]+I[o]:I[o].search(/<\//)>-1?r=n?r+=I[o]:r+=A[--C]+I[o]:I[o].search(/\/>/)>-1?r=n?r+=I[o]:r+=A[C]+I[o]:I[o].search(/<\?/)>-1||I[o].search(/xmlns\:/)>-1||I[o].search(/xmlns\=/)>-1?r+=A[C]+I[o]:r+=I[o];return r[0]==` -`?r.slice(1):r};ll.prototype.json=function(g,I){var I=I||this.step;return typeof JSON>"u"?g:typeof g=="string"?JSON.stringify(JSON.parse(g),null,I):typeof g=="object"?JSON.stringify(g,null,I):g};ll.prototype.css=function(g,e){var I=g.replace(/\s{1,}/g," ").replace(/\{/g,"{~::~").replace(/\}/g,"~::~}~::~").replace(/\;/g,";~::~").replace(/\/\*/g,"~::~/*").replace(/\*\//g,"*/~::~").replace(/~::~\s{0,}~::~/g,"~::~").split("~::~"),i=I.length,n=0,C="",r=0,o=e?zN(e):this.shift;for(r=0;r .resize-sensor {min-width: "+S+"px;}",o.push(G)}r[G].push({mode:v,property:w,value:V})}function d(G){var v;if(document.querySelectorAll&&(v=G?G.querySelectorAll.bind(G):document.querySelectorAll.bind(document)),!v&&typeof $$<"u"&&(v=$$),!v&&typeof jQuery<"u"&&(v=jQuery),!v)throw"No document.querySelectorAll, jQuery or Mootools's $$ found.";return v}function h(G){var v=d(G);for(var w in r)if(r.hasOwnProperty(w))for(var V=v(w,G),S=0,X=V.length;Sw[J].minWidth&&(O=J);if(O||(O=S),X!==O)if(W[O])v[X].style.display="none",v[O].style.display="block",X=O;else{var ee=new Image;ee.onload=function(){v[O].src=V[O],v[X].style.display="none",v[O].style.display="block",W[O]=!0,X=O},ee.src=V[O]}else v[O].src=V[O]}G.resizeSensorInstance=new I(G,E),E()}function f(){for(var G=d(),v=G("[data-responsive-image],[responsive-image]"),w=0,V=v.length;w img, [data-responsive-image] {overflow: hidden; padding: 0; } [responsive-image] > img, [data-responsive-image] > img {width: 100%;}",C.innerHTML+=` +@keyframes element-queries { 0% { visibility: inherit; } }`,document.getElementsByTagName("head")[0].appendChild(C),B=!0);for(var v=0,w=document.styleSheets.length;v\s{0,}<").replace(/-1?(r+=A[C]+I[o],n=!0,(I[o].search(/-->/)>-1||I[o].search(/\]>/)>-1||I[o].search(/!DOCTYPE/)>-1)&&(n=!1)):I[o].search(/-->/)>-1||I[o].search(/\]>/)>-1?(r+=I[o],n=!1):/^<\w/.exec(I[o-1])&&/^<\/\w/.exec(I[o])&&/^<[\w:\-\.\,]+/.exec(I[o-1])==/^<\/[\w:\-\.\,]+/.exec(I[o])[0].replace("/","")?(r+=I[o],n||C--):I[o].search(/<\w/)>-1&&I[o].search(/<\//)==-1&&I[o].search(/\/>/)==-1?r=n?r+=I[o]:r+=A[C++]+I[o]:I[o].search(/<\w/)>-1&&I[o].search(/<\//)>-1?r=n?r+=I[o]:r+=A[C]+I[o]:I[o].search(/<\//)>-1?r=n?r+=I[o]:r+=A[--C]+I[o]:I[o].search(/\/>/)>-1?r=n?r+=I[o]:r+=A[C]+I[o]:I[o].search(/<\?/)>-1||I[o].search(/xmlns\:/)>-1||I[o].search(/xmlns\=/)>-1?r+=A[C]+I[o]:r+=I[o];return r[0]==` +`?r.slice(1):r};Us.prototype.json=function(e,I){var I=I||this.step;return typeof JSON>"u"?e:typeof e=="string"?JSON.stringify(JSON.parse(e),null,I):typeof e=="object"?JSON.stringify(e,null,I):e};Us.prototype.css=function(e,g){var I=e.replace(/\s{1,}/g," ").replace(/\{/g,"{~::~").replace(/\}/g,"~::~}~::~").replace(/\;/g,";~::~").replace(/\/\*/g,"~::~/*").replace(/\*\//g,"*/~::~").replace(/~::~\s{0,}~::~/g,"~::~").split("~::~"),i=I.length,n=0,C="",r=0,o=g?jT(g):this.shift;for(r=0;r/g,"").replace(/[ \r\n\t]{1,}xmlns/g," xmlns");return I.replace(/>\s{0,}<")};ll.prototype.jsonmin=function(g){return typeof JSON>"u"?g:JSON.stringify(JSON.parse(g),null,0)};ll.prototype.cssmin=function(g,e){var I=e?g:g.replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\//g,"");return I.replace(/\s{1,}/g," ").replace(/\{\s{1,}/g,"{").replace(/\}\s{1,}/g,"}").replace(/\;\s{1,}/g,";").replace(/\/\*\s{1,}/g,"/*").replace(/\*\/\s{1,}/g,"*/")};ll.prototype.sqlmin=function(g){return g.replace(/\s{1,}/g," ").replace(/\s{1,}\(/,"(").replace(/\s{1,}\)/,")")};var Dnt=new ll;const Fnt=FC(Dnt);var Ent=function(e,I){if(I=I.split(":")[0],e=+e,!e)return!1;switch(I){case"http":case"ws":return e!==80;case"https":case"wss":return e!==443;case"ftp":return e!==21;case"gopher":return e!==70;case"file":return!1}return e!==0},nQ={},Mnt=Object.prototype.hasOwnProperty,znt;function dIe(g){try{return decodeURIComponent(g.replace(/\+/g," "))}catch{return null}}function hIe(g){try{return encodeURIComponent(g)}catch{return null}}function Pnt(g){for(var e=/([^=?#&]+)=?([^&]*)/g,I={},i;i=e.exec(g);){var n=dIe(i[1]),C=dIe(i[2]);n===null||C===null||n in I||(I[n]=C)}return I}function Jnt(g,e){e=e||"";var I=[],i,n;typeof e!="string"&&(e="?");for(n in g)if(Mnt.call(g,n)){if(i=g[n],!i&&(i===null||i===znt||isNaN(i))&&(i=""),n=hIe(n),i=hIe(i),n===null||i===null)continue;I.push(n+"="+i)}return I.length?e+I.join("&"):""}nQ.stringify=Jnt;nQ.parse=Pnt;var OZe=Ent,PN=nQ,Ont=/^[\x00-\x20\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff]+/,LZe=/[\n\r\t]/g,Lnt=/^[A-Za-z][A-Za-z0-9+-.]*:\/\//,_Ze=/:\d+$/,_nt=/^([a-z][a-z0-9.+-]*:)?(\/\/)?([\\/]+)?([\S\s]*)/i,Unt=/^[a-zA-Z]:/;function CQ(g){return(g||"").toString().replace(Ont,"")}var P3=[["#","hash"],["?","query"],function(e,I){return pa(I.protocol)?e.replace(/\\/g,"/"):e},["/","pathname"],["@","auth",1],[NaN,"host",void 0,1,1],[/:(\d*)$/,"port",void 0,1],[NaN,"hostname",void 0,1,1]],mIe={hash:1,query:1};function UZe(g){var e;typeof window<"u"?e=window:typeof globalThis<"u"?e=globalThis:typeof self<"u"?e=self:e={};var I=e.location||{};g=g||I;var i={},n=typeof g,C;if(g.protocol==="blob:")i=new va(unescape(g.pathname),{});else if(n==="string"){i=new va(g,{});for(C in mIe)delete i[C]}else if(n==="object"){for(C in g)C in mIe||(i[C]=g[C]);i.slashes===void 0&&(i.slashes=Lnt.test(g.href))}return i}function pa(g){return g==="file:"||g==="ftp:"||g==="http:"||g==="https:"||g==="ws:"||g==="wss:"}function QZe(g,e){g=CQ(g),g=g.replace(LZe,""),e=e||{};var I=_nt.exec(g),i=I[1]?I[1].toLowerCase():"",n=!!I[2],C=!!I[3],r=0,o;return n?C?(o=I[2]+I[3]+I[4],r=I[2].length+I[3].length):(o=I[2]+I[4],r=I[2].length):C?(o=I[3]+I[4],r=I[3].length):o=I[4],i==="file:"?r>=2&&(o=o.slice(2)):pa(i)?o=I[4]:i?n&&(o=o.slice(2)):r>=2&&pa(e.protocol)&&(o=I[4]),{protocol:i,slashes:n||pa(i),slashesCount:r,rest:o}}function Qnt(g,e){if(g==="")return e;for(var I=(e||"/").split("/").slice(0,-1).concat(g.split("/")),i=I.length,n=I[i-1],C=!1,r=0;i--;)I[i]==="."?I.splice(i,1):I[i]===".."?(I.splice(i,1),r++):r&&(i===0&&(C=!0),I.splice(i,1),r--);return C&&I.unshift(""),(n==="."||n==="..")&&I.push(""),I.join("/")}function va(g,e,I){if(g=CQ(g),g=g.replace(LZe,""),!(this instanceof va))return new va(g,e,I);var i,n,C,r,o,A,s=P3.slice(),a=typeof e,l=this,c=0;for(a!=="object"&&a!=="string"&&(I=e,e=null),I&&typeof I!="function"&&(I=PN.parse),e=UZe(e),n=QZe(g||"",e),i=!n.protocol&&!n.slashes,l.slashes=n.slashes||i&&e.slashes,l.protocol=n.protocol||e.protocol||"",g=n.rest,(n.protocol==="file:"&&(n.slashesCount!==2||Unt.test(g))||!n.slashes&&(n.protocol||n.slashesCount<2||!pa(l.protocol)))&&(s[3]=[/(.*)/,"pathname"]);c{try{return new window.BroadcastChannel("pub-sub-es")}catch{return{postMessage:()=>{}}}})(),rQ=(g,e)=>e?g.toLowerCase():g,$Ze=(g,{caseInsensitive:e}={})=>(I,i,n=1/0)=>{const C=rQ(I,e);return g[C]||(g[C]=[],g.__times__[C]=[]),g[C].push(i),g.__times__[C].push(+n||1/0),{event:C,handler:i}},oQ=(g,{caseInsensitive:e}={})=>(I,i)=>{typeof I=="object"&&(i=I.handler,I=I.event);const n=rQ(I,e);if(!g[n])return;const C=g[n].indexOf(i);C===-1||C>=g[n].length||(g[n].splice(C,1),g.__times__[n].splice(C,1))},fIe=(g,e)=>()=>{g.forEach(I=>I(e))},qZe=(g,{isGlobal:e,caseInsensitive:I,async:i}={})=>{const n=oQ(g);return(C,r,o={})=>{const A=rQ(C,I);if(!g[A])return;const s=[...g[A]];if(s.forEach((a,l)=>{--g.__times__[A][l]<1&&n(A,a)}),i||o.async?setTimeout(fIe(s,r),0):fIe(s,r)(),e&&!o.isNoGlobalBroadcast)try{jZe.postMessage({event:A,news:r})}catch(a){if(a instanceof DOMException)console.warn(`Could not broadcast '${A}' globally. Payload is not clonable.`);else throw a}}},eGe=g=>()=>{Object.keys(g).filter(e=>e[0]!=="_").forEach(e=>{g[e]=void 0,g.__times__[e]=void 0,delete g[e],delete g.__times__[e]})},tGe=()=>({__times__:{}}),JN=(g={})=>{const e=g.async||!1,I=g.caseInsensitive||!1,i=g.stack||tGe();return i.__times__||(i.__times__={}),{publish:qZe(i,{async:e,caseInsensitive:I}),subscribe:$Ze(i,{caseInsensitive:I}),unsubscribe:oQ(i,{caseInsensitive:I}),clear:eGe(i),stack:i}},gZ=tGe(),eB={publish:qZe(gZ,{isGlobal:!0}),subscribe:$Ze(gZ),unsubscribe:oQ(gZ),clear:eGe(gZ),stack:gZ};jZe.onmessage=({data:{event:g,news:e}})=>eB.publish(g,e,{isNoGlobalBroadcast:!0});const eg={"context-menu":"_context-menu_18ock_1","context-menu-dark":"_context-menu-dark_18ock_12","context-menu-icon":"_context-menu-icon_18ock_17","context-menu-item":"_context-menu-item_18ock_27","context-menu-hr":"_context-menu-hr_18ock_38","play-icon":"_play-icon_18ock_45","context-menu-span":"_context-menu-span_18ock_52","context-menu-thumbnail":"_context-menu-thumbnail_18ock_60","context-menu-thumbnail-inline":"_context-menu-thumbnail-inline_18ock_65"};function og(g){return N.createElement("div",{"data-menu-item-for":typeof g.children=="string"?g.children:null,className:eg["context-menu-item"],onClick:e=>g.onClick(e),onMouseEnter:e=>g.onMouseEnter(e),onMouseLeave:e=>g.onMouseLeave(e),role:"button",tabIndex:0},N.createElement("span",{className:eg["context-menu-span"]},g.children))}og.defaultProps={onMouseEnter:()=>{},onMouseLeave:()=>{}};og.propTypes={children:L.node.isRequired,onClick:L.func.isRequired,onMouseEnter:L.func,onMouseLeave:L.func};var tCt={value:()=>{}};function O0(){for(var g=0,e=arguments.length,I={},i;g=0&&(i=I.slice(n+1),I=I.slice(0,n)),I&&!e.hasOwnProperty(I))throw new Error("unknown type: "+I);return{type:I,name:i}})}q1.prototype=O0.prototype={constructor:q1,on:function(g,e){var I=this._,i=gCt(g+"",I),n,C=-1,r=i.length;if(arguments.length<2){for(;++C0)for(var I=new Array(n),i=0,n,C;i()=>g;function J3(g,{sourceEvent:e,subject:I,target:i,identifier:n,active:C,x:r,y:o,dx:A,dy:s,dispatch:a}){Object.defineProperties(this,{type:{value:g,enumerable:!0,configurable:!0},sourceEvent:{value:e,enumerable:!0,configurable:!0},subject:{value:I,enumerable:!0,configurable:!0},target:{value:i,enumerable:!0,configurable:!0},identifier:{value:n,enumerable:!0,configurable:!0},active:{value:C,enumerable:!0,configurable:!0},x:{value:r,enumerable:!0,configurable:!0},y:{value:o,enumerable:!0,configurable:!0},dx:{value:A,enumerable:!0,configurable:!0},dy:{value:s,enumerable:!0,configurable:!0},_:{value:a}})}J3.prototype.on=function(){var g=this._.on.apply(this._,arguments);return g===this._?this:g};function iCt(g){return!g.ctrlKey&&!g.button}function nCt(){return this.parentNode}function CCt(g,e){return e??{x:g.x,y:g.y}}function rCt(){return navigator.maxTouchPoints||"ontouchstart"in this}function es(){var g=iCt,e=nCt,I=CCt,i=rCt,n={},C=O0("start","drag","end"),r=0,o,A,s,a,l=0;function c(y){y.on("mousedown.drag",u).filter(i).on("touchstart.drag",m).on("touchmove.drag",f).on("touchend.drag touchcancel.drag",b).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function u(y,Z){if(!(a||!g.call(this,y,Z))){var v=p(this,e.call(this,y,Z),y,Z,"mouse");v&&(pg(y.view).on("mousemove.drag",d,!0).on("mouseup.drag",h,!0),ON(y.view),cx(y),s=!1,o=y.clientX,A=y.clientY,v("start",y))}}function d(y){if(Op(y),!s){var Z=y.clientX-o,v=y.clientY-A;s=Z*Z+v*v>l}n.mouse("drag",y)}function h(y){pg(y.view).on("mousemove.drag mouseup.drag",null),LN(y.view,s),Op(y),n.mouse("end",y)}function m(y,Z){if(g.call(this,y,Z)){var v=y.changedTouches,G=e.call(this,y,Z),B=v.length,w,R;for(w=0;w=0&&g._call.call(null,e),g=g._next;--Mb}function bIe(){ch=(Y9=Kv.now())+_N,Mb=UZ=0;try{aCt()}finally{Mb=0,lCt(),ch=0}}function sCt(){var g=Kv.now(),e=g-Y9;e>gGe&&(_N-=e,Y9=g)}function lCt(){for(var g,e=k9,I,i=1/0;e;)e._call?(i>e._time&&(i=e._time),g=e,e=e._next):(I=e._next,e._next=null,e=g?g._next=I:k9=I);QZ=g,O3(i)}function O3(g){if(!Mb){UZ&&(UZ=clearTimeout(UZ));var e=g-ch;e>24?(g<1/0&&(UZ=setTimeout(bIe,g-Kv.now()-_N)),IZ&&(IZ=clearInterval(IZ))):(IZ||(Y9=Kv.now(),IZ=setInterval(sCt,gGe)),Mb=1,IGe(bIe))}}function yIe(g,e,I){var i=new K9;return e=e==null?0:+e,i.restart(n=>{i.stop(),g(n+e)},e,I),i}var cCt=O0("start","end","cancel","interrupt"),uCt=[],nGe=0,ZIe=1,L3=2,eW=3,GIe=4,_3=5,tW=6;function UN(g,e,I,i,n,C){var r=g.__transition;if(!r)g.__transition={};else if(I in r)return;dCt(g,I,{name:e,index:i,group:n,on:cCt,tween:uCt,time:C.time,delay:C.delay,duration:C.duration,ease:C.ease,timer:null,state:nGe})}function aQ(g,e){var I=pA(g,e);if(I.state>nGe)throw new Error("too late; already scheduled");return I}function ka(g,e){var I=pA(g,e);if(I.state>eW)throw new Error("too late; already running");return I}function pA(g,e){var I=g.__transition;if(!I||!(I=I[e]))throw new Error("transition not found");return I}function dCt(g,e,I){var i=g.__transition,n;i[e]=I,I.timer=iGe(C,0,I.time);function C(s){I.state=ZIe,I.timer.restart(r,I.delay,I.time),I.delay<=s&&r(s-I.delay)}function r(s){var a,l,c,u;if(I.state!==ZIe)return A();for(a in i)if(u=i[a],u.name===I.name){if(u.state===eW)return yIe(r);u.state===GIe?(u.state=tW,u.timer.stop(),u.on.call("interrupt",g,g.__data__,u.index,u.group),delete i[a]):+aL3&&i.state<_3,i.state=tW,i.timer.stop(),i.on.call(n?"interrupt":"cancel",g,g.__data__,i.index,i.group),delete I[r]}C&&delete g.__transition}}function hCt(g){return this.each(function(){U3(this,g)})}function mCt(g,e){var I,i;return function(){var n=ka(this,g),C=n.tween;if(C!==I){i=I=C;for(var r=0,o=i.length;r=0&&(e=e.slice(0,I)),!e||e==="start"})}function JCt(g,e,I){var i,n,C=PCt(e)?aQ:ka;return function(){var r=C(this,g),o=r.on;o!==i&&(n=(i=o).copy()).on(e,I),r.on=n}}function OCt(g,e){var I=this._id;return arguments.length<2?pA(this.node(),I).on.on(g):this.each(JCt(I,g,e))}function LCt(g){return function(){var e=this.parentNode;for(var I in this.__transition)if(+I!==g)return;e&&e.removeChild(this)}}function _Ct(){return this.on("end.remove",LCt(this._id))}function UCt(g){var e=this._name,I=this._id;typeof g!="function"&&(g=US(g));for(var i=this._groups,n=i.length,C=new Array(n),r=0;r()=>g;function brt(g,{sourceEvent:e,target:I,selection:i,mode:n,dispatch:C}){Object.defineProperties(this,{type:{value:g,enumerable:!0,configurable:!0},sourceEvent:{value:e,enumerable:!0,configurable:!0},target:{value:I,enumerable:!0,configurable:!0},selection:{value:i,enumerable:!0,configurable:!0},mode:{value:n,enumerable:!0,configurable:!0},_:{value:C}})}function yrt(g){g.stopImmediatePropagation()}function dx(g){g.preventDefault(),g.stopImmediatePropagation()}var BIe={name:"drag"},hx={name:"space"},Lm={name:"handle"},_m={name:"center"};const{abs:vIe,max:vn,min:Sn}=Math;function SIe(g){return[+g[0],+g[1]]}function Q3(g){return[SIe(g[0]),SIe(g[1])]}var gW={name:"x",handles:["w","e"].map(xv),input:function(g,e){return g==null?null:[[+g[0],e[0][1]],[+g[1],e[1][1]]]},output:function(g){return g&&[g[0][0],g[1][0]]}},IW={name:"y",handles:["n","s"].map(xv),input:function(g,e){return g==null?null:[[e[0][0],+g[0]],[e[1][0],+g[1]]]},output:function(g){return g&&[g[0][1],g[1][1]]}},Zrt={name:"xy",handles:["n","w","e","s","nw","ne","sw","se"].map(xv),input:function(g){return g==null?null:Q3(g)},output:function(g){return g}},Pa={overlay:"crosshair",selection:"move",n:"ns-resize",e:"ew-resize",s:"ns-resize",w:"ew-resize",nw:"nwse-resize",ne:"nesw-resize",se:"nwse-resize",sw:"nesw-resize"},wIe={e:"w",w:"e",nw:"ne",ne:"nw",se:"sw",sw:"se"},VIe={n:"s",s:"n",nw:"sw",ne:"se",se:"ne",sw:"nw"},Grt={overlay:1,selection:1,n:null,e:1,s:null,w:-1,nw:-1,ne:1,se:1,sw:-1},Brt={overlay:1,selection:1,n:-1,e:null,s:1,w:null,nw:-1,ne:-1,se:1,sw:1};function xv(g){return{type:g}}function vrt(g){return!g.ctrlKey&&!g.button}function Srt(){var g=this.ownerSVGElement||this;return g.hasAttribute("viewBox")?(g=g.viewBox.baseVal,[[g.x,g.y],[g.x+g.width,g.y+g.height]]):[[0,0],[g.width.baseVal.value,g.height.baseVal.value]]}function wrt(){return navigator.maxTouchPoints||"ontouchstart"in this}function mx(g){for(;!g.__brush;)if(!(g=g.parentNode))return;return g.__brush}function Vrt(g){return g[0][0]===g[1][0]||g[0][1]===g[1][1]}function Rrt(g){var e=g.__brush;return e?e.dim.output(e.selection):null}function QN(){return cQ(gW)}function nw(){return cQ(IW)}function lQ(){return cQ(Zrt)}function cQ(g){var e=Srt,I=vrt,i=wrt,n=!0,C=O0("start","brush","end"),r=6,o;function A(m){var f=m.property("__brush",h).selectAll(".overlay").data([xv("overlay")]);f.enter().append("rect").attr("class","overlay").attr("pointer-events","all").attr("cursor",Pa.overlay).merge(f).each(function(){var p=mx(this).extent;pg(this).attr("x",p[0][0]).attr("y",p[0][1]).attr("width",p[1][0]-p[0][0]).attr("height",p[1][1]-p[0][1])}),m.selectAll(".selection").data([xv("selection")]).enter().append("rect").attr("class","selection").attr("cursor",Pa.selection).attr("fill","#777").attr("fill-opacity",.3).attr("stroke","#fff").attr("shape-rendering","crispEdges");var b=m.selectAll(".handle").data(g.handles,function(p){return p.type});b.exit().remove(),b.enter().append("rect").attr("class",function(p){return"handle handle--"+p.type}).attr("cursor",function(p){return Pa[p.type]}),m.each(s).attr("fill","none").attr("pointer-events","all").on("mousedown.brush",c).filter(i).on("touchstart.brush",c).on("touchmove.brush",u).on("touchend.brush touchcancel.brush",d).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}A.move=function(m,f){m.tween?m.on("start.brush",function(b){a(this,arguments).beforestart().start(b)}).on("interrupt.brush end.brush",function(b){a(this,arguments).end(b)}).tween("brush",function(){var b=this,p=b.__brush,y=a(b,arguments),Z=p.selection,v=g.input(typeof f=="function"?f.apply(this,arguments):f,p.extent),G=om(Z,v);function B(w){p.selection=w===1&&v===null?null:G(w),s.call(b),y.brush()}return Z!==null&&v!==null?B:B(1)}):m.each(function(){var b=this,p=arguments,y=b.__brush,Z=g.input(typeof f=="function"?f.apply(b,p):f,y.extent),v=a(b,p).beforestart();U3(b),y.selection=Z===null?null:Z,s.call(b),v.start().brush().end()})},A.clear=function(m){A.move(m,null)};function s(){var m=pg(this),f=mx(this).selection;f?(m.selectAll(".selection").style("display",null).attr("x",f[0][0]).attr("y",f[0][1]).attr("width",f[1][0]-f[0][0]).attr("height",f[1][1]-f[0][1]),m.selectAll(".handle").style("display",null).attr("x",function(b){return b.type[b.type.length-1]==="e"?f[1][0]-r/2:f[0][0]-r/2}).attr("y",function(b){return b.type[0]==="s"?f[1][1]-r/2:f[0][1]-r/2}).attr("width",function(b){return b.type==="n"||b.type==="s"?f[1][0]-f[0][0]+r:r}).attr("height",function(b){return b.type==="e"||b.type==="w"?f[1][1]-f[0][1]+r:r})):m.selectAll(".selection,.handle").style("display","none").attr("x",null).attr("y",null).attr("width",null).attr("height",null)}function a(m,f,b){var p=m.__brush.emitter;return p&&(!b||!p.clean)?p:new l(m,f,b)}function l(m,f,b){this.that=m,this.args=f,this.state=m.__brush,this.active=0,this.clean=b}l.prototype={beforestart:function(){return++this.active===1&&(this.state.emitter=this,this.starting=!0),this},start:function(m,f){return this.starting?(this.starting=!1,this.emit("start",m,f)):this.emit("brush",m),this},brush:function(m,f){return this.emit("brush",m,f),this},end:function(m,f){return--this.active===0&&(delete this.state.emitter,this.emit("end",m,f)),this},emit:function(m,f,b){var p=pg(this.that).datum();C.call(m,this.that,new brt(m,{sourceEvent:f,target:A,selection:g.output(this.state.selection),mode:b,dispatch:C}),p)}};function c(m){if(o&&!m.touches||!I.apply(this,arguments))return;var f=this,b=m.target.__data__.type,p=(n&&m.metaKey?b="overlay":b)==="selection"?BIe:n&&m.altKey?_m:Lm,y=g===IW?null:Grt[b],Z=g===gW?null:Brt[b],v=mx(f),G=v.extent,B=v.selection,w=G[0][0],R,S,X=G[0][1],W,V,H=G[1][0],D,Y,F=G[1][1],_,J,te=0,q=0,$,j=y&&Z&&n&&m.shiftKey,ee,Q,ne=Array.from(m.touches||[m],Me=>{const Ue=Me.identifier;return Me=Og(Me,f),Me.point0=Me.slice(),Me.identifier=Ue,Me});if(b==="overlay"){B&&($=!0);const Me=[ne[0],ne[1]||ne[0]];v.selection=B=[[R=g===IW?w:Sn(Me[0][0],Me[1][0]),W=g===gW?X:Sn(Me[0][1],Me[1][1])],[D=g===IW?H:vn(Me[0][0],Me[1][0]),_=g===gW?F:vn(Me[0][1],Me[1][1])]],ne.length>1&&ke()}else R=B[0][0],W=B[0][1],D=B[1][0],_=B[1][1];S=R,V=W,Y=D,J=_;var fe=pg(f).attr("pointer-events","none"),Ce=fe.selectAll(".overlay").attr("cursor",Pa[b]);U3(f);var Ze=a(f,arguments,!0).beforestart();if(m.touches)Ze.moved=ve,Ze.ended=Xe;else{var Ge=pg(m.view).on("mousemove.brush",ve,!0).on("mouseup.brush",Xe,!0);n&&Ge.on("keydown.brush",Oe,!0).on("keyup.brush",ze,!0),ON(m.view)}s.call(f),Ze.start(m,p.name);function ve(Me){for(const Ue of Me.changedTouches||[Me])for(const _e of ne)_e.identifier===Ue.identifier&&(_e.cur=Og(Ue,f));if(j&&!ee&&!Q&&ne.length===1){const Ue=ne[0];vIe(Ue.cur[0]-Ue[0])>vIe(Ue.cur[1]-Ue[1])?Q=!0:ee=!0}for(const Ue of ne)Ue.cur&&(Ue[0]=Ue.cur[0],Ue[1]=Ue.cur[1]);$=!0,dx(Me),ke(Me)}function ke(Me){const Ue=ne[0],_e=Ue.point0;var At;switch(te=Ue[0]-_e[0],q=Ue[1]-_e[1],p){case hx:case BIe:{y&&(te=vn(w-R,Sn(H-D,te)),S=R+te,Y=D+te),Z&&(q=vn(X-W,Sn(F-_,q)),V=W+q,J=_+q);break}case Lm:{ne[1]?(y&&(S=vn(w,Sn(H,ne[0][0])),Y=vn(w,Sn(H,ne[1][0])),y=1),Z&&(V=vn(X,Sn(F,ne[0][1])),J=vn(X,Sn(F,ne[1][1])),Z=1)):(y<0?(te=vn(w-R,Sn(H-R,te)),S=R+te,Y=D):y>0&&(te=vn(w-D,Sn(H-D,te)),S=R,Y=D+te),Z<0?(q=vn(X-W,Sn(F-W,q)),V=W+q,J=_):Z>0&&(q=vn(X-_,Sn(F-_,q)),V=W,J=_+q));break}case _m:{y&&(S=vn(w,Sn(H,R-te*y)),Y=vn(w,Sn(H,D+te*y))),Z&&(V=vn(X,Sn(F,W-q*Z)),J=vn(X,Sn(F,_+q*Z)));break}}Y0&&(R=S-te),Z<0?_=J-q:Z>0&&(W=V-q),p=hx,Ce.attr("cursor",Pa.selection),ke());break}default:return}dx(Me)}function ze(Me){switch(Me.keyCode){case 16:{j&&(ee=Q=j=!1,ke());break}case 18:{p===_m&&(y<0?D=Y:y>0&&(R=S),Z<0?_=J:Z>0&&(W=V),p=Lm,ke());break}case 32:{p===hx&&(Me.altKey?(y&&(D=Y-te*y,R=S+te*y),Z&&(_=J-q*Z,W=V+q*Z),p=_m):(y<0?D=Y:y>0&&(R=S),Z<0?_=J:Z>0&&(W=V),p=Lm),Ce.attr("cursor",Pa[b]),ke());break}default:return}dx(Me)}}function u(m){a(this,arguments).moved(m)}function d(m){a(this,arguments).ended(m)}function h(){var m=this.__brush||{selection:null};return m.extent=Q3(e.apply(this,arguments)),m.dim=g,m}return A.extent=function(m){return arguments.length?(e=typeof m=="function"?m:ux(Q3(m)),A):e},A.filter=function(m){return arguments.length?(I=typeof m=="function"?m:ux(!!m),A):I},A.touchable=function(m){return arguments.length?(i=typeof m=="function"?m:ux(!!m),A):i},A.handleSize=function(m){return arguments.length?(r=+m,A):r},A.keyModifiers=function(m){return arguments.length?(n=!!m,A):n},A.on=function(){var m=C.on.apply(C,arguments);return m===C?A:m},A}const Wrt=Object.freeze(Object.defineProperty({__proto__:null,brush:lQ,brushSelection:Rrt,brushX:QN,brushY:nw},Symbol.toStringTag,{value:"Module"}));function Dv(){return Dv=Object.assign?Object.assign.bind():function(g){for(var e=1;eg.length)&&(e=g.length);for(var I=0,i=new Array(e);I0&&arguments[0]!==void 0?arguments[0]:this.active.collection;return this.refs[I].sort(Mrt)}}]),g}();function Mrt(g,e){var I=g.node.sortableInfo.index,i=e.node.sortableInfo.index;return I-i}function zrt(g,e,I){return g=g.slice(),g.splice(I<0?g.length+I:I,0,g.splice(e,1)[0]),g}function lGe(g,e){return Object.keys(g).reduce(function(I,i){return e.indexOf(i)===-1&&(I[i]=g[i]),I},{})}var Um={end:["touchend","touchcancel","mouseup"],move:["touchmove","mousemove"],start:["touchstart","mousedown"]},cGe=function(){if(typeof window>"u"||typeof document>"u")return"";var g=window.getComputedStyle(document.documentElement,"")||["-moz-hidden-iframe"],e=(Array.prototype.slice.call(g).join("").match(/-(moz|webkit|ms)-/)||g.OLink===""&&["","o"])[1];switch(e){case"ms":return"ms";default:return e&&e.length?e[0].toUpperCase()+e.substr(1):""}}();function mR(g,e){Object.keys(e).forEach(function(I){g.style[I]=e[I]})}function fR(g,e){g.style["".concat(cGe,"Transform")]=e==null?"":"translate3d(".concat(e.x,"px,").concat(e.y,"px,0)")}function px(g,e){g.style["".concat(cGe,"TransitionDuration")]=e==null?"":"".concat(e,"ms")}function jZ(g,e){for(;g;){if(e(g))return g;g=g.parentNode}return null}function WIe(g,e,I){return Math.max(g,Math.min(I,e))}function fp(g){return g.substr(-2)==="px"?parseFloat(g):0}function Prt(g){var e=window.getComputedStyle(g);return{bottom:fp(e.marginBottom),left:fp(e.marginLeft),right:fp(e.marginRight),top:fp(e.marginTop)}}function hQ(g,e){var I=e.displayName||e.name;return I?"".concat(g,"(").concat(I,")"):g}function bx(g,e){var I=g.getBoundingClientRect();return{top:I.top+e.top,left:I.left+e.left}}function iZ(g){return g.touches&&g.touches.length?{x:g.touches[0].pageX,y:g.touches[0].pageY}:g.changedTouches&&g.changedTouches.length?{x:g.changedTouches[0].pageX,y:g.changedTouches[0].pageY}:{x:g.pageX,y:g.pageY}}function Jrt(g){return g.touches&&g.touches.length||g.changedTouches&&g.changedTouches.length}function iW(g,e){var I=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{left:0,top:0};if(g){var i={left:I.left+g.offsetLeft,top:I.top+g.offsetTop};return g.parentNode===e?i:iW(g.parentNode,e,i)}}function Ort(g,e,I){return ge?g-1:g>I&&g0&&I[r].height>0){var o=C.getContext("2d");o.drawImage(I[r],0,0)}}),i}function q3(g){var e,I,i=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{withRef:!1};return I=e=function(n){dQ(C,n);function C(){return Cw(this,C),uQ(this,Fv(C).apply(this,arguments))}return rw(C,[{key:"componentDidMount",value:function(){var o=Fs.findDOMNode(this);o.sortableHandle=!0}},{key:"getWrappedInstance",value:function(){return uh(i.withRef,"To access the wrapped instance, you need to pass in {withRef: true} as the second argument of the SortableHandle() call"),this.refs.wrappedInstance}},{key:"render",value:function(){var o=i.withRef?"wrappedInstance":null;return Ie.createElement(g,Dv({ref:o},this.props))}}]),C}(Ie.Component),jg(e,"displayName",hQ("sortableHandle",g)),I}function HIe(g){return g.sortableHandle!=null}var jrt=function(){function g(e,I){Cw(this,g),this.container=e,this.onScrollCallback=I}return rw(g,[{key:"clear",value:function(){this.interval!=null&&(clearInterval(this.interval),this.interval=null)}},{key:"update",value:function(I){var i=this,n=I.translate,C=I.minTranslate,r=I.maxTranslate,o=I.width,A=I.height,s={x:0,y:0},a={x:1,y:1},l={x:10,y:10},c=this.container,u=c.scrollTop,d=c.scrollLeft,h=c.scrollHeight,m=c.scrollWidth,f=c.clientHeight,b=c.clientWidth,p=u===0,y=h-u-f===0,Z=d===0,v=m-d-b===0;n.y>=r.y-A/2&&!y?(s.y=1,a.y=l.y*Math.abs((r.y-A/2-n.y)/A)):n.x>=r.x-o/2&&!v?(s.x=1,a.x=l.x*Math.abs((r.x-o/2-n.x)/o)):n.y<=C.y+A/2&&!p?(s.y=-1,a.y=l.y*Math.abs((n.y-A/2-C.y)/A)):n.x<=C.x+o/2&&!Z&&(s.x=-1,a.x=l.x*Math.abs((n.x-o/2-C.x)/o)),this.interval&&(this.clear(),this.isAutoScrolling=!1),(s.x!==0||s.y!==0)&&(this.interval=setInterval(function(){i.isAutoScrolling=!0;var G={left:a.x*s.x,top:a.y*s.y};i.container.scrollTop+=G.top,i.container.scrollLeft+=G.left,i.onScrollCallback(G)},5))}}]),g}();function $rt(g){var e=g.node;return{height:e.offsetHeight,width:e.offsetWidth}}function qrt(g){var e=[sd.Input,sd.Textarea,sd.Select,sd.Option,sd.Button];return!!(e.indexOf(g.target.tagName)!==-1||jZ(g.target,function(I){return I.contentEditable==="true"}))}var dGe={axis:L.oneOf(["x","y","xy"]),contentWindow:L.any,disableAutoscroll:L.bool,distance:L.number,getContainer:L.func,getHelperDimensions:L.func,helperClass:L.string,helperContainer:L.oneOfType([L.func,typeof HTMLElement>"u"?L.any:L.instanceOf(HTMLElement)]),hideSortableGhost:L.bool,keyboardSortingTransitionDuration:L.number,lockAxis:L.string,lockOffset:L.oneOfType([L.number,L.string,L.arrayOf(L.oneOfType([L.number,L.string]))]),lockToContainerEdges:L.bool,onSortEnd:L.func,onSortMove:L.func,onSortOver:L.func,onSortStart:L.func,pressDelay:L.number,pressThreshold:L.number,keyCodes:L.shape({lift:L.arrayOf(L.number),drop:L.arrayOf(L.number),cancel:L.arrayOf(L.number),up:L.arrayOf(L.number),down:L.arrayOf(L.number)}),shouldCancelStart:L.func,transitionDuration:L.number,updateBeforeSortStart:L.func,useDragHandle:L.bool,useWindowAsScrollContainer:L.bool},hGe={lift:[Eu.SPACE],drop:[Eu.SPACE],cancel:[Eu.ESC],up:[Eu.UP,Eu.LEFT],down:[Eu.DOWN,Eu.RIGHT]},eot={axis:"y",disableAutoscroll:!1,distance:0,getHelperDimensions:$rt,hideSortableGhost:!0,lockOffset:"50%",lockToContainerEdges:!1,pressDelay:0,pressThreshold:5,keyCodes:hGe,shouldCancelStart:qrt,transitionDuration:300,useWindowAsScrollContainer:!1},tot=Object.keys(dGe);function got(g){uh(!(g.distance&&g.pressDelay),"Attempted to set both `pressDelay` and `distance` on SortableContainer, you may only use one or the other, not both at the same time.")}function Iot(g,e){try{var I=g()}catch(i){return e(!0,i)}return I&&I.then?I.then(e.bind(null,!1),e.bind(null,!0)):e(!1,value)}function iot(g){var e,I,i=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{withRef:!1};return I=e=function(n){dQ(C,n);function C(r){var o;return Cw(this,C),o=uQ(this,Fv(C).call(this,r)),jg(vg(vg(o)),"state",{}),jg(vg(vg(o)),"handleStart",function(A){var s=o.props,a=s.distance,l=s.shouldCancelStart;if(!(A.button===2||l(A))){o.touched=!0,o.position=iZ(A);var c=jZ(A.target,function(b){return b.sortableInfo!=null});if(c&&c.sortableInfo&&o.nodeIsChild(c)&&!o.state.sorting){var u=o.props.useDragHandle,d=c.sortableInfo,h=d.index,m=d.collection,f=d.disabled;if(f||u&&!jZ(A.target,HIe))return;o.manager.active={collection:m,index:h},!Jrt(A)&&A.target.tagName===sd.Anchor&&A.preventDefault(),a||(o.props.pressDelay===0?o.handlePress(A):o.pressTimer=setTimeout(function(){return o.handlePress(A)},o.props.pressDelay))}}}),jg(vg(vg(o)),"nodeIsChild",function(A){return A.sortableInfo.manager===o.manager}),jg(vg(vg(o)),"handleMove",function(A){var s=o.props,a=s.distance,l=s.pressThreshold;if(!o.state.sorting&&o.touched&&!o._awaitingUpdateBeforeSortStart){var c=iZ(A),u={x:o.position.x-c.x,y:o.position.y-c.y},d=Math.abs(u.x)+Math.abs(u.y);o.delta=u,!a&&(!l||d>=l)?(clearTimeout(o.cancelTimer),o.cancelTimer=setTimeout(o.cancel,0)):a&&d>=a&&o.manager.isActive()&&o.handlePress(A)}}),jg(vg(vg(o)),"handleEnd",function(){o.touched=!1,o.cancel()}),jg(vg(vg(o)),"cancel",function(){var A=o.props.distance,s=o.state.sorting;s||(A||clearTimeout(o.pressTimer),o.manager.active=null)}),jg(vg(vg(o)),"handlePress",function(A){try{var s=o.manager.getActive(),a=function(){if(s){var l=function(){var w=y.sortableInfo.index,R=Prt(y),S=Urt(o.container),X=o.scrollContainer.getBoundingClientRect(),W=d({index:w,node:y,collection:Z});if(o.node=y,o.margin=R,o.gridGap=S,o.width=W.width,o.height=W.height,o.marginOffset={x:o.margin.left+o.margin.right+o.gridGap.x,y:Math.max(o.margin.top,o.margin.bottom,o.gridGap.y)},o.boundingClientRect=y.getBoundingClientRect(),o.containerBoundingRect=X,o.index=w,o.newIndex=w,o.axis={x:u.indexOf("x")>=0,y:u.indexOf("y")>=0},o.offsetEdge=iW(y,o.container),v?o.initialOffset=iZ(fx({},A,{pageX:o.boundingClientRect.left,pageY:o.boundingClientRect.top})):o.initialOffset=iZ(A),o.initialScroll={left:o.scrollContainer.scrollLeft,top:o.scrollContainer.scrollTop},o.initialWindowScroll={left:window.pageXOffset,top:window.pageYOffset},o.helper=o.helperContainer.appendChild(Qrt(y)),mR(o.helper,{boxSizing:"border-box",height:"".concat(o.height,"px"),left:"".concat(o.boundingClientRect.left-R.left,"px"),pointerEvents:"none",position:"fixed",top:"".concat(o.boundingClientRect.top-R.top,"px"),width:"".concat(o.width,"px")}),v&&o.helper.focus(),m&&(o.sortableGhost=y,mR(y,{opacity:0,visibility:"hidden"})),o.minTranslate={},o.maxTranslate={},v){var V=p?{top:0,left:0,width:o.contentWindow.innerWidth,height:o.contentWindow.innerHeight}:o.containerBoundingRect,H=V.top,D=V.left,Y=V.width,F=V.height,_=H+F,J=D+Y;o.axis.x&&(o.minTranslate.x=D-o.boundingClientRect.left,o.maxTranslate.x=J-(o.boundingClientRect.left+o.width)),o.axis.y&&(o.minTranslate.y=H-o.boundingClientRect.top,o.maxTranslate.y=_-(o.boundingClientRect.top+o.height))}else o.axis.x&&(o.minTranslate.x=(p?0:X.left)-o.boundingClientRect.left-o.width/2,o.maxTranslate.x=(p?o.contentWindow.innerWidth:X.left+X.width)-o.boundingClientRect.left-o.width/2),o.axis.y&&(o.minTranslate.y=(p?0:X.top)-o.boundingClientRect.top-o.height/2,o.maxTranslate.y=(p?o.contentWindow.innerHeight:X.top+X.height)-o.boundingClientRect.top-o.height/2);h&&h.split(" ").forEach(function(te){return o.helper.classList.add(te)}),o.listenerNode=A.touches?y:o.contentWindow,v?(o.listenerNode.addEventListener("wheel",o.handleKeyEnd,!0),o.listenerNode.addEventListener("mousedown",o.handleKeyEnd,!0),o.listenerNode.addEventListener("keydown",o.handleKeyDown)):(Um.move.forEach(function(te){return o.listenerNode.addEventListener(te,o.handleSortMove,!1)}),Um.end.forEach(function(te){return o.listenerNode.addEventListener(te,o.handleSortEnd,!1)})),o.setState({sorting:!0,sortingIndex:w}),b&&b({node:y,index:w,collection:Z,isKeySorting:v,nodes:o.manager.getOrderedRefs(),helper:o.helper},A),v&&o.keyMove(0)},c=o.props,u=c.axis,d=c.getHelperDimensions,h=c.helperClass,m=c.hideSortableGhost,f=c.updateBeforeSortStart,b=c.onSortStart,p=c.useWindowAsScrollContainer,y=s.node,Z=s.collection,v=o.manager.isKeySorting,G=function(){if(typeof f=="function"){o._awaitingUpdateBeforeSortStart=!0;var B=Iot(function(){var w=y.sortableInfo.index;return Promise.resolve(f({collection:Z,index:w,node:y,isKeySorting:v},A)).then(function(){})},function(w,R){if(o._awaitingUpdateBeforeSortStart=!1,w)throw R;return R});if(B&&B.then)return B.then(function(){})}}();return G&&G.then?G.then(l):l(G)}}();return Promise.resolve(a&&a.then?a.then(function(){}):void 0)}catch(l){return Promise.reject(l)}}),jg(vg(vg(o)),"handleSortMove",function(A){var s=o.props.onSortMove;typeof A.preventDefault=="function"&&A.preventDefault(),o.updateHelperPosition(A),o.animateNodes(),o.autoscroll(),s&&s(A)}),jg(vg(vg(o)),"handleSortEnd",function(A){var s=o.props,a=s.hideSortableGhost,l=s.onSortEnd,c=o.manager,u=c.active.collection,d=c.isKeySorting,h=o.manager.getOrderedRefs();o.listenerNode&&(d?(o.listenerNode.removeEventListener("wheel",o.handleKeyEnd,!0),o.listenerNode.removeEventListener("mousedown",o.handleKeyEnd,!0),o.listenerNode.removeEventListener("keydown",o.handleKeyDown)):(Um.move.forEach(function(y){return o.listenerNode.removeEventListener(y,o.handleSortMove)}),Um.end.forEach(function(y){return o.listenerNode.removeEventListener(y,o.handleSortEnd)}))),o.helper.parentNode.removeChild(o.helper),a&&o.sortableGhost&&mR(o.sortableGhost,{opacity:"",visibility:""});for(var m=0,f=h.length;ma)){o.prevIndex=c,o.newIndex=l;var u=Ort(o.newIndex,o.prevIndex,o.index),d=s.find(function(v){var G=v.node;return G.sortableInfo.index===u}),h=d.node,m=o.containerScrollDelta,f=d.boundingClientRect||bx(h,m),b=d.translate||{x:0,y:0},p={top:f.top+b.y-m.top,left:f.left+b.x-m.left},y=cv?v/2:this.height/2,width:this.width>Z?Z/2:this.width/2},B=h&&y>this.index&&y<=m,w=h&&y=m,R={x:0,y:0},S=u[f].edgeOffset;S||(S=iW(p,this.container),u[f].edgeOffset=S,h&&(u[f].boundingClientRect=bx(p,l)));var X=f0&&u[f-1];if(X&&!X.edgeOffset&&(X.edgeOffset=iW(X.node,this.container),h&&(X.boundingClientRect=bx(X.node,l))),y===this.index){s&&(this.sortableGhost=p,mR(p,{opacity:0,visibility:"hidden"}));continue}A&&px(p,A),this.axis.x?this.axis.y?w||ythis.containerBoundingRect.width-G.width&&X&&(R.x=X.edgeOffset.left-S.left,R.y=X.edgeOffset.top-S.top),this.newIndex===null&&(this.newIndex=y)):(B||y>this.index&&(d.left+c.left+G.width>=S.left&&d.top+c.top+G.height>=S.top||d.top+c.top+G.height>=S.top+v))&&(R.x=-(this.width+this.marginOffset.x),S.left+R.xthis.index&&d.left+c.left+G.width>=S.left?(R.x=-(this.width+this.marginOffset.x),this.newIndex=y):(w||ythis.index&&d.top+c.top+G.height>=S.top?(R.y=-(this.height+this.marginOffset.y),this.newIndex=y):(w||y1&&arguments[1]!==void 0?arguments[1]:{withRef:!1};return I=e=function(n){dQ(C,n);function C(){return Cw(this,C),uQ(this,Fv(C).apply(this,arguments))}return rw(C,[{key:"componentDidMount",value:function(){this.register()}},{key:"componentDidUpdate",value:function(o){this.node&&(o.index!==this.props.index&&(this.node.sortableInfo.index=this.props.index),o.disabled!==this.props.disabled&&(this.node.sortableInfo.disabled=this.props.disabled)),o.collection!==this.props.collection&&(this.unregister(o.collection),this.register())}},{key:"componentWillUnmount",value:function(){this.unregister()}},{key:"register",value:function(){var o=this.props,A=o.collection,s=o.disabled,a=o.index,l=Fs.findDOMNode(this);l.sortableInfo={collection:A,disabled:s,index:a,manager:this.context.manager},this.node=l,this.ref={node:l},this.context.manager.add(A,this.ref)}},{key:"unregister",value:function(){var o=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.props.collection;this.context.manager.remove(o,this.ref)}},{key:"getWrappedInstance",value:function(){return uh(i.withRef,"To access the wrapped instance, you need to pass in {withRef: true} as the second argument of the SortableElement() call"),this.refs.wrappedInstance}},{key:"render",value:function(){var o=i.withRef?"wrappedInstance":null;return Ie.createElement(g,Dv({ref:o},lGe(this.props,not)))}}]),C}(Ie.Component),jg(e,"displayName",hQ("sortableElement",g)),jg(e,"contextTypes",{manager:L.object.isRequired}),jg(e,"propTypes",mGe),jg(e,"defaultProps",{collection:0}),I}const pGe=M0(g=>g.pos).left,Vi=(g,e)=>{if(!e||!e.cumPositions||!e.cumPositions.length)return null;let I=pGe(e.cumPositions,g);const i=e.cumPositions[e.cumPositions.length-1].chr,n=e.chromLengths[i];I>0&&(I-=1);let C=Math.floor(g-e.cumPositions[I].pos),r=0;return C<0&&(r=C-1,C=1),I===e.cumPositions.length-1&&C>n&&(r=C-n,C=n),[e.cumPositions[I].chr,C,r,I]},bGe=(g,e)=>I=>I%g*e+Math.floor(I/g),Cot=g=>g,yGe=(g,e,I=Cot)=>g.map((i,n)=>i+e[I(n)]),rot="http://www.w3.org/2000/svg",x9=(g,e)=>{if(g.namespaceURI===rot){const I=g.getAttribute("class");return!!I&&!!I.match(new RegExp(`(\\s|^)${e}(\\s|$)`))}return g.classList?g.classList.contains(e):!!g.className.match(new RegExp(`(\\s|^)${e}(\\s|$)`))},oot="http://www.w3.org/2000/svg",Aot=(g,e)=>{if(g.namespaceURI===oot){if(!x9(g,e)){const I=g.getAttribute("class")||"";g.setAttribute("class",`${I} ${e}`)}}else g.classList?g.classList.add(e):x9(g,e)||(g.className+=` ${e}`)},aot=(g,e,I)=>{const i=document.createElement("canvas");return new Promise((n,C)=>{const r=new window.Image;r.onload=()=>{i.width=e||r.width,i.height=I||r.height;const o=i.getContext("2d");if(!o){C(new Error("Could not get canvas context"));return}o.drawImage(r,0,0),n(i)},r.onerror=()=>{C(new Error("Could not convert base64 to canvas"))},r.src=`data:image/png;base64,${g}`})},D9=(g,e,I)=>I.chrPositions[g].pos+e,ZGe=g=>{if(!(g instanceof Event))throw new Error("Event must be an instance of Event");const e=new g.constructor(g.type,g);return e.sourceUid=g.sourceUid,e.forwarded=g.forwarded,e},Cu=(g,e=!1)=>{const I=g.map((r,o)=>o*(255/(g.length-1))),i=Cg().domain(I).range(g),C=iC(e?255:254,-1,-1).map(i).map(r=>{const o=Yb(r);return[o.r,o.g,o.b,o.opacity*255]});return C.length<256&&C.push([255,255,255,0]),C},$Z=0,qZ=5,GGe=10,BGe=10,vGe=300,F9="move",Jr="select",ez=100,E9=10,SGe=110,eG=3e3,tG="locationListenerPrefix",wGe=1e3,tz="http://higlass.io/api/v1",VGe=400,RGe=300,gz=["top","left","right","bottom","center","whole","gallery"],WGe=20,XGe=20,M9=Symbol("Light theme"),II=Symbol("Dark theme"),sot=M9,Ct={PIXI:Bpe},Tr={"multitrack-header":"_multitrack-header_1yz7l_1","multitrack-header-focus":"_multitrack-header-focus_1yz7l_2","multitrack-header-squeazed":"_multitrack-header-squeazed_1yz7l_3","multitrack-header-dark":"_multitrack-header-dark_1yz7l_20","multitrack-header-id":"_multitrack-header-id_1yz7l_30","multitrack-header-left":"_multitrack-header-left_1yz7l_39","multitrack-header-grabber":"_multitrack-header-grabber_1yz7l_44","multitrack-header-grabber-squeazed":"_multitrack-header-grabber-squeazed_1yz7l_45","multitrack-header-search":"_multitrack-header-search_1yz7l_80","multitrack-header-nav-list":"_multitrack-header-nav-list_1yz7l_102","multitrack-header-icon":"_multitrack-header-icon_1yz7l_107","multitrack-header-icon-squeazed":"_multitrack-header-icon-squeazed_1yz7l_108","mouse-tool-selection":"_mouse-tool-selection_1yz7l_136"},lot={id:"cog",paths:["M466.895 305.125c-26.863-46.527-10.708-106.152 36.076-133.244l-50.313-87.146c-14.375 8.427-31.088 13.259-48.923 13.259-53.768 0-97.354-43.873-97.354-97.995h-100.629c0.133 16.705-4.037 33.641-12.979 49.126-26.862 46.528-86.578 62.351-133.431 35.379l-50.312 87.146c14.485 8.236 27.025 20.294 35.943 35.739 26.819 46.454 10.756 105.96-35.854 133.112l50.313 87.146c14.325-8.348 30.958-13.127 48.7-13.127 53.598 0 97.072 43.596 97.35 97.479h100.627c-0.043-16.537 4.136-33.285 12.983-48.609 26.818-46.453 86.388-62.297 133.207-35.506l50.313-87.145c-14.39-8.233-26.846-20.249-35.717-35.614zM256 359.666c-57.254 0-103.668-46.412-103.668-103.667 0-57.254 46.413-103.667 103.668-103.667s103.666 46.413 103.666 103.667c-0.001 57.255-46.412 103.667-103.666 103.667z"],viewBox:"0 0 512 512"},cot={id:"cross",paths:["M507.331 411.33c-0.002-0.002-0.004-0.004-0.006-0.005l-155.322-155.325 155.322-155.325c0.002-0.002 0.004-0.003 0.006-0.005 1.672-1.673 2.881-3.627 3.656-5.708 2.123-5.688 0.912-12.341-3.662-16.915l-73.373-73.373c-4.574-4.573-11.225-5.783-16.914-3.66-2.080 0.775-4.035 1.984-5.709 3.655 0 0.002-0.002 0.003-0.004 0.005l-155.324 155.326-155.324-155.325c-0.002-0.002-0.003-0.003-0.005-0.005-1.673-1.671-3.627-2.88-5.707-3.655-5.69-2.124-12.341-0.913-16.915 3.66l-73.374 73.374c-4.574 4.574-5.784 11.226-3.661 16.914 0.776 2.080 1.985 4.036 3.656 5.708 0.002 0.001 0.003 0.003 0.005 0.005l155.325 155.324-155.325 155.326c-0.001 0.002-0.003 0.003-0.004 0.005-1.671 1.673-2.88 3.627-3.657 5.707-2.124 5.688-0.913 12.341 3.661 16.915l73.374 73.373c4.575 4.574 11.226 5.784 16.915 3.661 2.080-0.776 4.035-1.985 5.708-3.656 0.001-0.002 0.003-0.003 0.005-0.005l155.324-155.325 155.324 155.325c0.002 0.001 0.004 0.003 0.006 0.004 1.674 1.672 3.627 2.881 5.707 3.657 5.689 2.123 12.342 0.913 16.914-3.661l73.373-73.374c4.574-4.574 5.785-11.227 3.662-16.915-0.776-2.080-1.985-4.034-3.657-5.707z"],viewBox:"0 0 512 512"},uot={id:"enlarge",paths:["M512 0h-208l80 80-96 96 48 48 96-96 80 80z","M512 512v-208l-80 80-96-96-48 48 96 96-80 80z","M0 512h208l-80-80 96-96-48-48-96 96-80-80z","M0 0v208l80-80 96 96 48-48-96-96 80-80z"],viewBox:"0 0 512 512"},dot={id:"minus",paths:["M0 208v96c0 8.836 7.164 16 16 16h480c8.836 0 16-7.164 16-16v-96c0-8.836-7.164-16-16-16h-480c-8.836 0-16 7.164-16 16z"],viewBox:"0 0 512 512"},hot={id:"move",paths:["M512,260.096L405.5,161.79v49.155H301.061v-104.45h49.149L251.904,0L160.77,106.495h49.15v104.45H106.495V161.79L0,260.096l106.495,91.135v-49.149h104.45v104.45H161.79L251.904,512l98.306-106.5h-49.149V301.061H405.5v49.149L512,260.096z"],viewBox:"0 0 512 512"},mot={id:"play",paths:["M96 64l320 192-320 192z"],viewBox:"0 0 512 512"},fot={id:"plus",paths:["M496 192h-176v-176c0-8.836-7.164-16-16-16h-96c-8.836 0-16 7.164-16 16v176h-176c-8.836 0-16 7.164-16 16v96c0 8.836 7.164 16 16 16h176v176c0 8.836 7.164 16 16 16h96c8.836 0 16-7.164 16-16v-176h176c8.836 0 16-7.164 16-16v-96c0-8.836-7.164-16-16-16z"],viewBox:"0 0 512 512"},pot={id:"copy",paths:["M607.5 672v-448.5h-351v448.5h351zM607.5 160.5c34.5 0 64.5 28.5 64.5 63v448.5c0 34.5-30 64.5-64.5 64.5h-351c-34.5 0-64.5-30-64.5-64.5v-448.5c0-34.5 30-63 64.5-63h351zM511.5 31.5v64.5h-384v448.5h-63v-448.5c0-34.5 28.5-64.5 63-64.5h384z"],viewBox:"0 0 712 712"},bot={id:"select",viewBox:"0 0 16 16",paths:["M2 14h2v1H1v-3h1v2zm8 1H6v-1h4v1zm5 0h-3v-1h2v-2h1v3zm0-5h-1V6h1v4zM2 10H1V6h1v4zm13-6h-1V2h-2V1h3v3zM4 2H2v2H1V1h3v1zm6 0H6V1h4.03L10 2z"]},yot={id:"check_square_o",viewBox:"0 0 1792 1792",paths:["M1472 930v318q0 119-84.5 203.5t-203.5 84.5h-832q-119 0-203.5-84.5t-84.5-203.5v-832q0-119 84.5-203.5t203.5-84.5h832q63 0 117 25 15 7 18 23 3 17-9 29l-49 49q-10 10-23 10-3 0-9-2-23-6-45-6h-832q-66 0-113 47t-47 113v832q0 66 47 113t113 47h832q66 0 113-47t47-113v-254q0-13 9-22l64-64q10-10 23-10 6 0 12 3 20 8 20 29zm231-489l-814 814q-24 24-57 24t-57-24l-430-430q-24-24-24-57t24-57l110-110q24-24 57-24t57 24l263 263 647-647q24-24 57-24t57 24l110 110q24 24 24 57t-24 57z"]},Zot={id:"square_o",viewBox:"0 0 1792 1792",paths:["M1312 256h-832q-66 0-113 47t-47 113v832q0 66 47 113t113 47h832q66 0 113-47t47-113v-832q0-66-47-113t-113-47zm288 160v832q0 119-84.5 203.5t-203.5 84.5h-832q-119 0-203.5-84.5t-84.5-203.5v-832q0-119 84.5-203.5t203.5-84.5h832q119 0 203.5 84.5t84.5 203.5z"]},Got={id:"file_o",viewBox:"0 0 1792 1792",paths:["M1596 380q28 28 48 76t20 88v1152q0 40-28 68t-68 28h-1344q-40 0-68-28t-28-68v-1600q0-40 28-68t68-28h896q40 0 88 20t76 48zm-444-244v376h376q-10-29-22-41l-313-313q-12-12-41-22zm384 1528v-1024h-416q-40 0-68-28t-28-68v-416h-768v1536h1280z"]},Bot={id:"chevron_right",viewBox:"0 0 1792 1792",paths:["M1363 877l-742 742q-19 19-45 19t-45-19l-166-166q-19-19-19-45t19-45l531-531-531-531q-19-19-19-45t19-45l166-166q19-19 45-19t45 19l742 742q19 19 19 45t-19 45z"]},vot={id:"chevron_down",viewBox:"0 0 1792 1792",paths:["M1683 808l-742 741q-19 19-45 19t-45-19l-742-741q-19-19-19-45.5t19-45.5l166-165q19-19 45-19t45 19l531 531 531-531q19-19 45-19t45 19l166 165q19 19 19 45.5t-19 45.5z"]},Sot={id:"folder_o",viewBox:"0 0 1792 1792",paths:["M1600 1312v-704q0-40-28-68t-68-28h-704q-40 0-68-28t-28-68v-64q0-40-28-68t-68-28h-320q-40 0-68 28t-28 68v960q0 40 28 68t68 28h1216q40 0 68-28t28-68zm128-704v704q0 92-66 158t-158 66h-1216q-92 0-158-66t-66-158v-960q0-92 66-158t158-66h320q92 0 158 66t66 158v32h672q92 0 158 66t66 158z"]},wot={id:"folder_open_o",viewBox:"0 0 1792 1792",paths:["M1845 931q0-35-53-35h-1088q-40 0-85.5 21.5t-71.5 52.5l-294 363q-18 24-18 40 0 35 53 35h1088q40 0 86-22t71-53l294-363q18-22 18-39zm-1141-163h768v-160q0-40-28-68t-68-28h-576q-40 0-68-28t-28-68v-64q0-40-28-68t-68-28h-320q-40 0-68 28t-28 68v853l256-315q44-53 116-87.5t140-34.5zm1269 163q0 62-46 120l-295 363q-43 53-116 87.5t-140 34.5h-1088q-92 0-158-66t-66-158v-960q0-92 66-158t158-66h320q92 0 158 66t66 158v32h544q92 0 158 66t66 158v160h192q54 0 99 24.5t67 70.5q15 32 15 68z"]},Vot=[lot,cot,uot,dot,hot,mot,fot,pot,bot,yot,Zot,Got,Sot,wot,Bot,vot],bA=new DOMParser,Rot='',mQ=bA.parseFromString(Rot,"text/xml").documentElement,Wot=` +`),A};Us.prototype.xmlmin=function(e,g){var I=g?e:e.replace(/\/g,"").replace(/[ \r\n\t]{1,}xmlns/g," xmlns");return I.replace(/>\s{0,}<")};Us.prototype.jsonmin=function(e){return typeof JSON>"u"?e:JSON.stringify(JSON.parse(e),null,0)};Us.prototype.cssmin=function(e,g){var I=g?e:e.replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\//g,"");return I.replace(/\s{1,}/g," ").replace(/\{\s{1,}/g,"{").replace(/\}\s{1,}/g,"}").replace(/\;\s{1,}/g,";").replace(/\/\*\s{1,}/g,"/*").replace(/\*\/\s{1,}/g,"*/")};Us.prototype.sqlmin=function(e){return e.replace(/\s{1,}/g," ").replace(/\s{1,}\(/,"(").replace(/\s{1,}\)/,")")};var mrt=new Us;const frt=DC(mrt);var prt=function(g,I){if(I=I.split(":")[0],g=+g,!g)return!1;switch(I){case"http":case"ws":return g!==80;case"https":case"wss":return g!==443;case"ftp":return g!==21;case"gopher":return g!==70;case"file":return!1}return g!==0},S7={},brt=Object.prototype.hasOwnProperty,yrt;function Wge(e){try{return decodeURIComponent(e.replace(/\+/g," "))}catch{return null}}function Xge(e){try{return encodeURIComponent(e)}catch{return null}}function Zrt(e){for(var g=/([^=?#&]+)=?([^&]*)/g,I={},i;i=g.exec(e);){var n=Wge(i[1]),C=Wge(i[2]);n===null||C===null||n in I||(I[n]=C)}return I}function Grt(e,g){g=g||"";var I=[],i,n;typeof g!="string"&&(g="?");for(n in e)if(brt.call(e,n)){if(i=e[n],!i&&(i===null||i===yrt||isNaN(i))&&(i=""),n=Xge(n),i=Xge(i),n===null||i===null)continue;I.push(n+"="+i)}return I.length?g+I.join("&"):""}S7.stringify=Grt;S7.parse=Zrt;var Yye=prt,$T=S7,vrt=/^[\x00-\x20\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff]+/,Kye=/[\n\r\t]/g,Brt=/^[A-Za-z][A-Za-z0-9+-.]*:\/\//,Dye=/:\d+$/,Srt=/^([a-z][a-z0-9.+-]*:)?(\/\/)?([\\/]+)?([\S\s]*)/i,wrt=/^[a-zA-Z]:/;function w7(e){return(e||"").toString().replace(vrt,"")}var A3=[["#","hash"],["?","query"],function(g,I){return Ca(I.protocol)?g.replace(/\\/g,"/"):g},["/","pathname"],["@","auth",1],[NaN,"host",void 0,1,1],[/:(\d*)$/,"port",void 0,1],[NaN,"hostname",void 0,1,1]],Hge={hash:1,query:1};function xye(e){var g;typeof window<"u"?g=window:typeof globalThis<"u"?g=globalThis:typeof self<"u"?g=self:g={};var I=g.location||{};e=e||I;var i={},n=typeof e,C;if(e.protocol==="blob:")i=new ua(unescape(e.pathname),{});else if(n==="string"){i=new ua(e,{});for(C in Hge)delete i[C]}else if(n==="object"){for(C in e)C in Hge||(i[C]=e[C]);i.slashes===void 0&&(i.slashes=Brt.test(e.href))}return i}function Ca(e){return e==="file:"||e==="ftp:"||e==="http:"||e==="https:"||e==="ws:"||e==="wss:"}function Fye(e,g){e=w7(e),e=e.replace(Kye,""),g=g||{};var I=Srt.exec(e),i=I[1]?I[1].toLowerCase():"",n=!!I[2],C=!!I[3],r=0,o;return n?C?(o=I[2]+I[3]+I[4],r=I[2].length+I[3].length):(o=I[2]+I[4],r=I[2].length):C?(o=I[3]+I[4],r=I[3].length):o=I[4],i==="file:"?r>=2&&(o=o.slice(2)):Ca(i)?o=I[4]:i?n&&(o=o.slice(2)):r>=2&&Ca(g.protocol)&&(o=I[4]),{protocol:i,slashes:n||Ca(i),slashesCount:r,rest:o}}function Vrt(e,g){if(e==="")return g;for(var I=(g||"/").split("/").slice(0,-1).concat(e.split("/")),i=I.length,n=I[i-1],C=!1,r=0;i--;)I[i]==="."?I.splice(i,1):I[i]===".."?(I.splice(i,1),r++):r&&(i===0&&(C=!0),I.splice(i,1),r--);return C&&I.unshift(""),(n==="."||n==="..")&&I.push(""),I.join("/")}function ua(e,g,I){if(e=w7(e),e=e.replace(Kye,""),!(this instanceof ua))return new ua(e,g,I);var i,n,C,r,o,A,s=A3.slice(),a=typeof g,l=this,c=0;for(a!=="object"&&a!=="string"&&(I=g,g=null),I&&typeof I!="function"&&(I=$T.parse),g=xye(g),n=Fye(e||"",g),i=!n.protocol&&!n.slashes,l.slashes=n.slashes||i&&g.slashes,l.protocol=n.protocol||g.protocol||"",e=n.rest,(n.protocol==="file:"&&(n.slashesCount!==2||wrt.test(e))||!n.slashes&&(n.protocol||n.slashesCount<2||!Ca(l.protocol)))&&(s[3]=[/(.*)/,"pathname"]);c{try{return new window.BroadcastChannel("pub-sub-es")}catch{return{postMessage:()=>{}}}})(),V7=(e,g)=>g?e.toLowerCase():e,Mye=(e,{caseInsensitive:g}={})=>(I,i,n=1/0)=>{const C=V7(I,g);return e[C]||(e[C]=[],e.__times__[C]=[]),e[C].push(i),e.__times__[C].push(+n||1/0),{event:C,handler:i}},R7=(e,{caseInsensitive:g}={})=>(I,i)=>{typeof I=="object"&&(i=I.handler,I=I.event);const n=V7(I,g);if(!e[n])return;const C=e[n].indexOf(i);C===-1||C>=e[n].length||(e[n].splice(C,1),e.__times__[n].splice(C,1))},Tge=(e,g)=>()=>{e.forEach(I=>I(g))},zye=(e,{isGlobal:g,caseInsensitive:I,async:i}={})=>{const n=R7(e);return(C,r,o={})=>{const A=V7(C,I);if(!e[A])return;const s=[...e[A]];if(s.forEach((a,l)=>{--e.__times__[A][l]<1&&n(A,a)}),i||o.async?setTimeout(Tge(s,r),0):Tge(s,r)(),g&&!o.isNoGlobalBroadcast)try{Eye.postMessage({event:A,news:r})}catch(a){if(a instanceof DOMException)console.warn(`Could not broadcast '${A}' globally. Payload is not clonable.`);else throw a}}},Pye=e=>()=>{Object.keys(e).filter(g=>g[0]!=="_").forEach(g=>{e[g]=void 0,e.__times__[g]=void 0,delete e[g],delete e.__times__[g]})},Jye=()=>({__times__:{}}),qT=(e={})=>{const g=e.async||!1,I=e.caseInsensitive||!1,i=e.stack||Jye();return i.__times__||(i.__times__={}),{publish:zye(i,{async:g,caseInsensitive:I}),subscribe:Mye(i,{caseInsensitive:I}),unsubscribe:R7(i,{caseInsensitive:I}),clear:Pye(i),stack:i}},xy=Jye(),VG={publish:zye(xy,{isGlobal:!0}),subscribe:Mye(xy),unsubscribe:R7(xy),clear:Pye(xy),stack:xy};Eye.onmessage=({data:{event:e,news:g}})=>VG.publish(e,g,{isNoGlobalBroadcast:!0});const Ut={"context-menu":"_context-menu_18ock_1","context-menu-dark":"_context-menu-dark_18ock_12","context-menu-icon":"_context-menu-icon_18ock_17","context-menu-item":"_context-menu-item_18ock_27","context-menu-hr":"_context-menu-hr_18ock_38","play-icon":"_play-icon_18ock_45","context-menu-span":"_context-menu-span_18ock_52","context-menu-thumbnail":"_context-menu-thumbnail_18ock_60","context-menu-thumbnail-inline":"_context-menu-thumbnail-inline_18ock_65"};function tg(e){return N.createElement("div",{"data-menu-item-for":typeof e.children=="string"?e.children:null,className:Ut["context-menu-item"],onClick:g=>e.onClick(g),onMouseEnter:g=>e.onMouseEnter(g),onMouseLeave:g=>e.onMouseLeave(g),role:"button",tabIndex:0},N.createElement("span",{className:Ut["context-menu-span"]},e.children))}tg.defaultProps={onMouseEnter:()=>{},onMouseLeave:()=>{}};tg.propTypes={children:L.node.isRequired,onClick:L.func.isRequired,onMouseEnter:L.func,onMouseLeave:L.func};var Trt={value:()=>{}};function w0(){for(var e=0,g=arguments.length,I={},i;e=0&&(i=I.slice(n+1),I=I.slice(0,n)),I&&!g.hasOwnProperty(I))throw new Error("unknown type: "+I);return{type:I,name:i}})}f1.prototype=w0.prototype={constructor:f1,on:function(e,g){var I=this._,i=Nrt(e+"",I),n,C=-1,r=i.length;if(arguments.length<2){for(;++C0)for(var I=new Array(n),i=0,n,C;i()=>e;function a3(e,{sourceEvent:g,subject:I,target:i,identifier:n,active:C,x:r,y:o,dx:A,dy:s,dispatch:a}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:g,enumerable:!0,configurable:!0},subject:{value:I,enumerable:!0,configurable:!0},target:{value:i,enumerable:!0,configurable:!0},identifier:{value:n,enumerable:!0,configurable:!0},active:{value:C,enumerable:!0,configurable:!0},x:{value:r,enumerable:!0,configurable:!0},y:{value:o,enumerable:!0,configurable:!0},dx:{value:A,enumerable:!0,configurable:!0},dy:{value:s,enumerable:!0,configurable:!0},_:{value:a}})}a3.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function Yrt(e){return!e.ctrlKey&&!e.button}function Krt(){return this.parentNode}function Drt(e,g){return g??{x:e.x,y:e.y}}function xrt(){return navigator.maxTouchPoints||"ontouchstart"in this}function za(){var e=Yrt,g=Krt,I=Drt,i=xrt,n={},C=w0("start","drag","end"),r=0,o,A,s,a,l=0;function c(y){y.on("mousedown.drag",u).filter(i).on("touchstart.drag",m).on("touchmove.drag",f).on("touchend.drag touchcancel.drag",b).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function u(y,Z){if(!(a||!e.call(this,y,Z))){var B=p(this,g.call(this,y,Z),y,Z,"mouse");B&&(cg(y.view).on("mousemove.drag",d,!0).on("mouseup.drag",h,!0),eN(y.view),G5(y),s=!1,o=y.clientX,A=y.clientY,B("start",y))}}function d(y){if(Gp(y),!s){var Z=y.clientX-o,B=y.clientY-A;s=Z*Z+B*B>l}n.mouse("drag",y)}function h(y){cg(y.view).on("mousemove.drag mouseup.drag",null),tN(y.view,s),Gp(y),n.mouse("end",y)}function m(y,Z){if(e.call(this,y,Z)){var B=y.changedTouches,G=g.call(this,y,Z),v=B.length,w,V;for(w=0;w=0&&e._call.call(null,g),e=e._next;--yb}function kge(){jd=(OX=sB.now())+gN,yb=GZ=0;try{Mrt()}finally{yb=0,Prt(),jd=0}}function zrt(){var e=sB.now(),g=e-OX;g>Oye&&(gN-=g,OX=e)}function Prt(){for(var e,g=JX,I,i=1/0;g;)g._call?(i>g._time&&(i=g._time),e=g,g=g._next):(I=g._next,g._next=null,g=e?e._next=I:JX=I);vZ=e,s3(i)}function s3(e){if(!yb){GZ&&(GZ=clearTimeout(GZ));var g=e-jd;g>24?(e<1/0&&(GZ=setTimeout(kge,e-sB.now()-gN)),Fy&&(Fy=clearInterval(Fy))):(Fy||(OX=sB.now(),Fy=setInterval(zrt,Oye)),yb=1,_ye(kge))}}function Yge(e,g,I){var i=new _X;return g=g==null?0:+g,i.restart(n=>{i.stop(),e(n+g)},g,I),i}var Jrt=w0("start","end","cancel","interrupt"),Ort=[],Uye=0,Kge=1,l3=2,p1=3,Dge=4,c3=5,b1=6;function IN(e,g,I,i,n,C){var r=e.__transition;if(!r)e.__transition={};else if(I in r)return;_rt(e,I,{name:g,index:i,group:n,on:Jrt,tween:Ort,time:C.time,delay:C.delay,duration:C.duration,ease:C.ease,timer:null,state:Uye})}function X7(e,g){var I=lA(e,g);if(I.state>Uye)throw new Error("too late; already scheduled");return I}function Ba(e,g){var I=lA(e,g);if(I.state>p1)throw new Error("too late; already running");return I}function lA(e,g){var I=e.__transition;if(!I||!(I=I[g]))throw new Error("transition not found");return I}function _rt(e,g,I){var i=e.__transition,n;i[g]=I,I.timer=Lye(C,0,I.time);function C(s){I.state=Kge,I.timer.restart(r,I.delay,I.time),I.delay<=s&&r(s-I.delay)}function r(s){var a,l,c,u;if(I.state!==Kge)return A();for(a in i)if(u=i[a],u.name===I.name){if(u.state===p1)return Yge(r);u.state===Dge?(u.state=b1,u.timer.stop(),u.on.call("interrupt",e,e.__data__,u.index,u.group),delete i[a]):+al3&&i.state=0&&(g=g.slice(0,I)),!g||g==="start"})}function Got(e,g,I){var i,n,C=Zot(g)?X7:Ba;return function(){var r=C(this,e),o=r.on;o!==i&&(n=(i=o).copy()).on(g,I),r.on=n}}function vot(e,g){var I=this._id;return arguments.length<2?lA(this.node(),I).on.on(e):this.each(Got(I,e,g))}function Bot(e){return function(){var g=this.parentNode;for(var I in this.__transition)if(+I!==e)return;g&&g.removeChild(this)}}function Sot(){return this.on("end.remove",Bot(this._id))}function wot(e){var g=this._name,I=this._id;typeof e!="function"&&(e=hS(e));for(var i=this._groups,n=i.length,C=new Array(n),r=0;r()=>e;function $ot(e,{sourceEvent:g,target:I,selection:i,mode:n,dispatch:C}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:g,enumerable:!0,configurable:!0},target:{value:I,enumerable:!0,configurable:!0},selection:{value:i,enumerable:!0,configurable:!0},mode:{value:n,enumerable:!0,configurable:!0},_:{value:C}})}function qot(e){e.stopImmediatePropagation()}function B5(e){e.preventDefault(),e.stopImmediatePropagation()}var xge={name:"drag"},S5={name:"space"},Wm={name:"handle"},Xm={name:"center"};const{abs:Fge,max:vn,min:Bn}=Math;function Ege(e){return[+e[0],+e[1]]}function d3(e){return[Ege(e[0]),Ege(e[1])]}var y1={name:"x",handles:["w","e"].map(lB),input:function(e,g){return e==null?null:[[+e[0],g[0][1]],[+e[1],g[1][1]]]},output:function(e){return e&&[e[0][0],e[1][0]]}},Z1={name:"y",handles:["n","s"].map(lB),input:function(e,g){return e==null?null:[[g[0][0],+e[0]],[g[1][0],+e[1]]]},output:function(e){return e&&[e[0][1],e[1][1]]}},eAt={name:"xy",handles:["n","w","e","s","nw","ne","sw","se"].map(lB),input:function(e){return e==null?null:d3(e)},output:function(e){return e}},Na={overlay:"crosshair",selection:"move",n:"ns-resize",e:"ew-resize",s:"ns-resize",w:"ew-resize",nw:"nwse-resize",ne:"nesw-resize",se:"nwse-resize",sw:"nesw-resize"},Mge={e:"w",w:"e",nw:"ne",ne:"nw",se:"sw",sw:"se"},zge={n:"s",s:"n",nw:"sw",ne:"se",se:"ne",sw:"nw"},tAt={overlay:1,selection:1,n:null,e:1,s:null,w:-1,nw:-1,ne:1,se:1,sw:-1},gAt={overlay:1,selection:1,n:-1,e:null,s:1,w:null,nw:-1,ne:-1,se:1,sw:1};function lB(e){return{type:e}}function IAt(e){return!e.ctrlKey&&!e.button}function iAt(){var e=this.ownerSVGElement||this;return e.hasAttribute("viewBox")?(e=e.viewBox.baseVal,[[e.x,e.y],[e.x+e.width,e.y+e.height]]):[[0,0],[e.width.baseVal.value,e.height.baseVal.value]]}function nAt(){return navigator.maxTouchPoints||"ontouchstart"in this}function w5(e){for(;!e.__brush;)if(!(e=e.parentNode))return;return e.__brush}function CAt(e){return e[0][0]===e[1][0]||e[0][1]===e[1][1]}function rAt(e){var g=e.__brush;return g?g.dim.output(g.selection):null}function iN(){return N7(y1)}function SS(){return N7(Z1)}function T7(){return N7(eAt)}function N7(e){var g=iAt,I=IAt,i=nAt,n=!0,C=w0("start","brush","end"),r=6,o;function A(m){var f=m.property("__brush",h).selectAll(".overlay").data([lB("overlay")]);f.enter().append("rect").attr("class","overlay").attr("pointer-events","all").attr("cursor",Na.overlay).merge(f).each(function(){var p=w5(this).extent;cg(this).attr("x",p[0][0]).attr("y",p[0][1]).attr("width",p[1][0]-p[0][0]).attr("height",p[1][1]-p[0][1])}),m.selectAll(".selection").data([lB("selection")]).enter().append("rect").attr("class","selection").attr("cursor",Na.selection).attr("fill","#777").attr("fill-opacity",.3).attr("stroke","#fff").attr("shape-rendering","crispEdges");var b=m.selectAll(".handle").data(e.handles,function(p){return p.type});b.exit().remove(),b.enter().append("rect").attr("class",function(p){return"handle handle--"+p.type}).attr("cursor",function(p){return Na[p.type]}),m.each(s).attr("fill","none").attr("pointer-events","all").on("mousedown.brush",c).filter(i).on("touchstart.brush",c).on("touchmove.brush",u).on("touchend.brush touchcancel.brush",d).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}A.move=function(m,f){m.tween?m.on("start.brush",function(b){a(this,arguments).beforestart().start(b)}).on("interrupt.brush end.brush",function(b){a(this,arguments).end(b)}).tween("brush",function(){var b=this,p=b.__brush,y=a(b,arguments),Z=p.selection,B=e.input(typeof f=="function"?f.apply(this,arguments):f,p.extent),G=Jh(Z,B);function v(w){p.selection=w===1&&B===null?null:G(w),s.call(b),y.brush()}return Z!==null&&B!==null?v:v(1)}):m.each(function(){var b=this,p=arguments,y=b.__brush,Z=e.input(typeof f=="function"?f.apply(b,p):f,y.extent),B=a(b,p).beforestart();u3(b),y.selection=Z===null?null:Z,s.call(b),B.start().brush().end()})},A.clear=function(m){A.move(m,null)};function s(){var m=cg(this),f=w5(this).selection;f?(m.selectAll(".selection").style("display",null).attr("x",f[0][0]).attr("y",f[0][1]).attr("width",f[1][0]-f[0][0]).attr("height",f[1][1]-f[0][1]),m.selectAll(".handle").style("display",null).attr("x",function(b){return b.type[b.type.length-1]==="e"?f[1][0]-r/2:f[0][0]-r/2}).attr("y",function(b){return b.type[0]==="s"?f[1][1]-r/2:f[0][1]-r/2}).attr("width",function(b){return b.type==="n"||b.type==="s"?f[1][0]-f[0][0]+r:r}).attr("height",function(b){return b.type==="e"||b.type==="w"?f[1][1]-f[0][1]+r:r})):m.selectAll(".selection,.handle").style("display","none").attr("x",null).attr("y",null).attr("width",null).attr("height",null)}function a(m,f,b){var p=m.__brush.emitter;return p&&(!b||!p.clean)?p:new l(m,f,b)}function l(m,f,b){this.that=m,this.args=f,this.state=m.__brush,this.active=0,this.clean=b}l.prototype={beforestart:function(){return++this.active===1&&(this.state.emitter=this,this.starting=!0),this},start:function(m,f){return this.starting?(this.starting=!1,this.emit("start",m,f)):this.emit("brush",m),this},brush:function(m,f){return this.emit("brush",m,f),this},end:function(m,f){return--this.active===0&&(delete this.state.emitter,this.emit("end",m,f)),this},emit:function(m,f,b){var p=cg(this.that).datum();C.call(m,this.that,new $ot(m,{sourceEvent:f,target:A,selection:e.output(this.state.selection),mode:b,dispatch:C}),p)}};function c(m){if(o&&!m.touches||!I.apply(this,arguments))return;var f=this,b=m.target.__data__.type,p=(n&&m.metaKey?b="overlay":b)==="selection"?xge:n&&m.altKey?Xm:Wm,y=e===Z1?null:tAt[b],Z=e===y1?null:gAt[b],B=w5(f),G=B.extent,v=B.selection,w=G[0][0],V,S,X=G[0][1],W,R,H=G[1][0],Y,D,E=G[1][1],O,J,ee=0,q=0,$,j=y&&Z&&n&&m.shiftKey,te,U,ie=Array.from(m.touches||[m],Fe=>{const Ue=Fe.identifier;return Fe=Eg(Fe,f),Fe.point0=Fe.slice(),Fe.identifier=Ue,Fe});if(b==="overlay"){v&&($=!0);const Fe=[ie[0],ie[1]||ie[0]];B.selection=v=[[V=e===Z1?w:Bn(Fe[0][0],Fe[1][0]),W=e===y1?X:Bn(Fe[0][1],Fe[1][1])],[Y=e===Z1?H:vn(Fe[0][0],Fe[1][0]),O=e===y1?E:vn(Fe[0][1],Fe[1][1])]],ie.length>1&&Ne()}else V=v[0][0],W=v[0][1],Y=v[1][0],O=v[1][1];S=V,R=W,D=Y,J=O;var me=cg(f).attr("pointer-events","none"),Ce=me.selectAll(".overlay").attr("cursor",Na[b]);u3(f);var Ze=a(f,arguments,!0).beforestart();if(m.touches)Ze.moved=Be,Ze.ended=Se;else{var Ge=cg(m.view).on("mousemove.brush",Be,!0).on("mouseup.brush",Se,!0);n&&Ge.on("keydown.brush",Pe,!0).on("keyup.brush",ze,!0),eN(m.view)}s.call(f),Ze.start(m,p.name);function Be(Fe){for(const Ue of Fe.changedTouches||[Fe])for(const _e of ie)_e.identifier===Ue.identifier&&(_e.cur=Eg(Ue,f));if(j&&!te&&!U&&ie.length===1){const Ue=ie[0];Fge(Ue.cur[0]-Ue[0])>Fge(Ue.cur[1]-Ue[1])?U=!0:te=!0}for(const Ue of ie)Ue.cur&&(Ue[0]=Ue.cur[0],Ue[1]=Ue.cur[1]);$=!0,B5(Fe),Ne(Fe)}function Ne(Fe){const Ue=ie[0],_e=Ue.point0;var ot;switch(ee=Ue[0]-_e[0],q=Ue[1]-_e[1],p){case S5:case xge:{y&&(ee=vn(w-V,Bn(H-Y,ee)),S=V+ee,D=Y+ee),Z&&(q=vn(X-W,Bn(E-O,q)),R=W+q,J=O+q);break}case Wm:{ie[1]?(y&&(S=vn(w,Bn(H,ie[0][0])),D=vn(w,Bn(H,ie[1][0])),y=1),Z&&(R=vn(X,Bn(E,ie[0][1])),J=vn(X,Bn(E,ie[1][1])),Z=1)):(y<0?(ee=vn(w-V,Bn(H-V,ee)),S=V+ee,D=Y):y>0&&(ee=vn(w-Y,Bn(H-Y,ee)),S=V,D=Y+ee),Z<0?(q=vn(X-W,Bn(E-W,q)),R=W+q,J=O):Z>0&&(q=vn(X-O,Bn(E-O,q)),R=W,J=O+q));break}case Xm:{y&&(S=vn(w,Bn(H,V-ee*y)),D=vn(w,Bn(H,Y+ee*y))),Z&&(R=vn(X,Bn(E,W-q*Z)),J=vn(X,Bn(E,O+q*Z)));break}}D0&&(V=S-ee),Z<0?O=J-q:Z>0&&(W=R-q),p=S5,Ce.attr("cursor",Na.selection),Ne());break}default:return}B5(Fe)}function ze(Fe){switch(Fe.keyCode){case 16:{j&&(te=U=j=!1,Ne());break}case 18:{p===Xm&&(y<0?Y=D:y>0&&(V=S),Z<0?O=J:Z>0&&(W=R),p=Wm,Ne());break}case 32:{p===S5&&(Fe.altKey?(y&&(Y=D-ee*y,V=S+ee*y),Z&&(O=J-q*Z,W=R+q*Z),p=Xm):(y<0?Y=D:y>0&&(V=S),Z<0?O=J:Z>0&&(W=R),p=Wm),Ce.attr("cursor",Na[b]),Ne());break}default:return}B5(Fe)}}function u(m){a(this,arguments).moved(m)}function d(m){a(this,arguments).ended(m)}function h(){var m=this.__brush||{selection:null};return m.extent=d3(g.apply(this,arguments)),m.dim=e,m}return A.extent=function(m){return arguments.length?(g=typeof m=="function"?m:v5(d3(m)),A):g},A.filter=function(m){return arguments.length?(I=typeof m=="function"?m:v5(!!m),A):I},A.touchable=function(m){return arguments.length?(i=typeof m=="function"?m:v5(!!m),A):i},A.handleSize=function(m){return arguments.length?(r=+m,A):r},A.keyModifiers=function(m){return arguments.length?(n=!!m,A):n},A.on=function(){var m=C.on.apply(C,arguments);return m===C?A:m},A}const oAt=Object.freeze(Object.defineProperty({__proto__:null,brush:T7,brushSelection:rAt,brushX:iN,brushY:SS},Symbol.toStringTag,{value:"Module"}));function cB(){return cB=Object.assign?Object.assign.bind():function(e){for(var g=1;ge.length)&&(g=e.length);for(var I=0,i=new Array(g);I0&&arguments[0]!==void 0?arguments[0]:this.active.collection;return this.refs[I].sort(bAt)}}]),e}();function bAt(e,g){var I=e.node.sortableInfo.index,i=g.node.sortableInfo.index;return I-i}function yAt(e,g,I){return e=e.slice(),e.splice(I<0?e.length+I:I,0,e.splice(g,1)[0]),e}function gZe(e,g){return Object.keys(e).reduce(function(I,i){return g.indexOf(i)===-1&&(I[i]=e[i]),I},{})}var Hm={end:["touchend","touchcancel","mouseup"],move:["touchmove","mousemove"],start:["touchstart","mousedown"]},IZe=function(){if(typeof window>"u"||typeof document>"u")return"";var e=window.getComputedStyle(document.documentElement,"")||["-moz-hidden-iframe"],g=(Array.prototype.slice.call(e).join("").match(/-(moz|webkit|ms)-/)||e.OLink===""&&["","o"])[1];switch(g){case"ms":return"ms";default:return g&&g.length?g[0].toUpperCase()+g.substr(1):""}}();function MV(e,g){Object.keys(g).forEach(function(I){e.style[I]=g[I]})}function zV(e,g){e.style["".concat(IZe,"Transform")]=g==null?"":"translate3d(".concat(g.x,"px,").concat(g.y,"px,0)")}function R5(e,g){e.style["".concat(IZe,"TransitionDuration")]=g==null?"":"".concat(g,"ms")}function BZ(e,g){for(;e;){if(g(e))return e;e=e.parentNode}return null}function Jge(e,g,I){return Math.max(e,Math.min(I,g))}function Uf(e){return e.substr(-2)==="px"?parseFloat(e):0}function ZAt(e){var g=window.getComputedStyle(e);return{bottom:Uf(g.marginBottom),left:Uf(g.marginLeft),right:Uf(g.marginRight),top:Uf(g.marginTop)}}function K7(e,g){var I=g.displayName||g.name;return I?"".concat(e,"(").concat(I,")"):e}function W5(e,g){var I=e.getBoundingClientRect();return{top:I.top+g.top,left:I.left+g.left}}function Ey(e){return e.touches&&e.touches.length?{x:e.touches[0].pageX,y:e.touches[0].pageY}:e.changedTouches&&e.changedTouches.length?{x:e.changedTouches[0].pageX,y:e.changedTouches[0].pageY}:{x:e.pageX,y:e.pageY}}function GAt(e){return e.touches&&e.touches.length||e.changedTouches&&e.changedTouches.length}function G1(e,g){var I=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{left:0,top:0};if(e){var i={left:I.left+e.offsetLeft,top:I.top+e.offsetTop};return e.parentNode===g?i:G1(e.parentNode,g,i)}}function vAt(e,g,I){return eg?e-1:e>I&&e0&&I[r].height>0){var o=C.getContext("2d");o.drawImage(I[r],0,0)}}),i}function f3(e){var g,I,i=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{withRef:!1};return I=g=function(n){Y7(C,n);function C(){return wS(this,C),k7(this,uB(C).apply(this,arguments))}return VS(C,[{key:"componentDidMount",value:function(){var o=Rs.findDOMNode(this);o.sortableHandle=!0}},{key:"getWrappedInstance",value:function(){return $d(i.withRef,"To access the wrapped instance, you need to pass in {withRef: true} as the second argument of the SortableHandle() call"),this.refs.wrappedInstance}},{key:"render",value:function(){var o=i.withRef?"wrappedInstance":null;return Ie.createElement(e,cB({ref:o},this.props))}}]),C}(Ie.Component),_g(g,"displayName",K7("sortableHandle",e)),I}function _ge(e){return e.sortableHandle!=null}var RAt=function(){function e(g,I){wS(this,e),this.container=g,this.onScrollCallback=I}return VS(e,[{key:"clear",value:function(){this.interval!=null&&(clearInterval(this.interval),this.interval=null)}},{key:"update",value:function(I){var i=this,n=I.translate,C=I.minTranslate,r=I.maxTranslate,o=I.width,A=I.height,s={x:0,y:0},a={x:1,y:1},l={x:10,y:10},c=this.container,u=c.scrollTop,d=c.scrollLeft,h=c.scrollHeight,m=c.scrollWidth,f=c.clientHeight,b=c.clientWidth,p=u===0,y=h-u-f===0,Z=d===0,B=m-d-b===0;n.y>=r.y-A/2&&!y?(s.y=1,a.y=l.y*Math.abs((r.y-A/2-n.y)/A)):n.x>=r.x-o/2&&!B?(s.x=1,a.x=l.x*Math.abs((r.x-o/2-n.x)/o)):n.y<=C.y+A/2&&!p?(s.y=-1,a.y=l.y*Math.abs((n.y-A/2-C.y)/A)):n.x<=C.x+o/2&&!Z&&(s.x=-1,a.x=l.x*Math.abs((n.x-o/2-C.x)/o)),this.interval&&(this.clear(),this.isAutoScrolling=!1),(s.x!==0||s.y!==0)&&(this.interval=setInterval(function(){i.isAutoScrolling=!0;var G={left:a.x*s.x,top:a.y*s.y};i.container.scrollTop+=G.top,i.container.scrollLeft+=G.left,i.onScrollCallback(G)},5))}}]),e}();function WAt(e){var g=e.node;return{height:g.offsetHeight,width:g.offsetWidth}}function XAt(e){var g=[Ou.Input,Ou.Textarea,Ou.Select,Ou.Option,Ou.Button];return!!(g.indexOf(e.target.tagName)!==-1||BZ(e.target,function(I){return I.contentEditable==="true"}))}var nZe={axis:L.oneOf(["x","y","xy"]),contentWindow:L.any,disableAutoscroll:L.bool,distance:L.number,getContainer:L.func,getHelperDimensions:L.func,helperClass:L.string,helperContainer:L.oneOfType([L.func,typeof HTMLElement>"u"?L.any:L.instanceOf(HTMLElement)]),hideSortableGhost:L.bool,keyboardSortingTransitionDuration:L.number,lockAxis:L.string,lockOffset:L.oneOfType([L.number,L.string,L.arrayOf(L.oneOfType([L.number,L.string]))]),lockToContainerEdges:L.bool,onSortEnd:L.func,onSortMove:L.func,onSortOver:L.func,onSortStart:L.func,pressDelay:L.number,pressThreshold:L.number,keyCodes:L.shape({lift:L.arrayOf(L.number),drop:L.arrayOf(L.number),cancel:L.arrayOf(L.number),up:L.arrayOf(L.number),down:L.arrayOf(L.number)}),shouldCancelStart:L.func,transitionDuration:L.number,updateBeforeSortStart:L.func,useDragHandle:L.bool,useWindowAsScrollContainer:L.bool},CZe={lift:[Zu.SPACE],drop:[Zu.SPACE],cancel:[Zu.ESC],up:[Zu.UP,Zu.LEFT],down:[Zu.DOWN,Zu.RIGHT]},HAt={axis:"y",disableAutoscroll:!1,distance:0,getHelperDimensions:WAt,hideSortableGhost:!0,lockOffset:"50%",lockToContainerEdges:!1,pressDelay:0,pressThreshold:5,keyCodes:CZe,shouldCancelStart:XAt,transitionDuration:300,useWindowAsScrollContainer:!1},TAt=Object.keys(nZe);function NAt(e){$d(!(e.distance&&e.pressDelay),"Attempted to set both `pressDelay` and `distance` on SortableContainer, you may only use one or the other, not both at the same time.")}function kAt(e,g){try{var I=e()}catch(i){return g(!0,i)}return I&&I.then?I.then(g.bind(null,!1),g.bind(null,!0)):g(!1,value)}function YAt(e){var g,I,i=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{withRef:!1};return I=g=function(n){Y7(C,n);function C(r){var o;return wS(this,C),o=k7(this,uB(C).call(this,r)),_g(fg(fg(o)),"state",{}),_g(fg(fg(o)),"handleStart",function(A){var s=o.props,a=s.distance,l=s.shouldCancelStart;if(!(A.button===2||l(A))){o.touched=!0,o.position=Ey(A);var c=BZ(A.target,function(b){return b.sortableInfo!=null});if(c&&c.sortableInfo&&o.nodeIsChild(c)&&!o.state.sorting){var u=o.props.useDragHandle,d=c.sortableInfo,h=d.index,m=d.collection,f=d.disabled;if(f||u&&!BZ(A.target,_ge))return;o.manager.active={collection:m,index:h},!GAt(A)&&A.target.tagName===Ou.Anchor&&A.preventDefault(),a||(o.props.pressDelay===0?o.handlePress(A):o.pressTimer=setTimeout(function(){return o.handlePress(A)},o.props.pressDelay))}}}),_g(fg(fg(o)),"nodeIsChild",function(A){return A.sortableInfo.manager===o.manager}),_g(fg(fg(o)),"handleMove",function(A){var s=o.props,a=s.distance,l=s.pressThreshold;if(!o.state.sorting&&o.touched&&!o._awaitingUpdateBeforeSortStart){var c=Ey(A),u={x:o.position.x-c.x,y:o.position.y-c.y},d=Math.abs(u.x)+Math.abs(u.y);o.delta=u,!a&&(!l||d>=l)?(clearTimeout(o.cancelTimer),o.cancelTimer=setTimeout(o.cancel,0)):a&&d>=a&&o.manager.isActive()&&o.handlePress(A)}}),_g(fg(fg(o)),"handleEnd",function(){o.touched=!1,o.cancel()}),_g(fg(fg(o)),"cancel",function(){var A=o.props.distance,s=o.state.sorting;s||(A||clearTimeout(o.pressTimer),o.manager.active=null)}),_g(fg(fg(o)),"handlePress",function(A){try{var s=o.manager.getActive(),a=function(){if(s){var l=function(){var w=y.sortableInfo.index,V=ZAt(y),S=wAt(o.container),X=o.scrollContainer.getBoundingClientRect(),W=d({index:w,node:y,collection:Z});if(o.node=y,o.margin=V,o.gridGap=S,o.width=W.width,o.height=W.height,o.marginOffset={x:o.margin.left+o.margin.right+o.gridGap.x,y:Math.max(o.margin.top,o.margin.bottom,o.gridGap.y)},o.boundingClientRect=y.getBoundingClientRect(),o.containerBoundingRect=X,o.index=w,o.newIndex=w,o.axis={x:u.indexOf("x")>=0,y:u.indexOf("y")>=0},o.offsetEdge=G1(y,o.container),B?o.initialOffset=Ey(V5({},A,{pageX:o.boundingClientRect.left,pageY:o.boundingClientRect.top})):o.initialOffset=Ey(A),o.initialScroll={left:o.scrollContainer.scrollLeft,top:o.scrollContainer.scrollTop},o.initialWindowScroll={left:window.pageXOffset,top:window.pageYOffset},o.helper=o.helperContainer.appendChild(VAt(y)),MV(o.helper,{boxSizing:"border-box",height:"".concat(o.height,"px"),left:"".concat(o.boundingClientRect.left-V.left,"px"),pointerEvents:"none",position:"fixed",top:"".concat(o.boundingClientRect.top-V.top,"px"),width:"".concat(o.width,"px")}),B&&o.helper.focus(),m&&(o.sortableGhost=y,MV(y,{opacity:0,visibility:"hidden"})),o.minTranslate={},o.maxTranslate={},B){var R=p?{top:0,left:0,width:o.contentWindow.innerWidth,height:o.contentWindow.innerHeight}:o.containerBoundingRect,H=R.top,Y=R.left,D=R.width,E=R.height,O=H+E,J=Y+D;o.axis.x&&(o.minTranslate.x=Y-o.boundingClientRect.left,o.maxTranslate.x=J-(o.boundingClientRect.left+o.width)),o.axis.y&&(o.minTranslate.y=H-o.boundingClientRect.top,o.maxTranslate.y=O-(o.boundingClientRect.top+o.height))}else o.axis.x&&(o.minTranslate.x=(p?0:X.left)-o.boundingClientRect.left-o.width/2,o.maxTranslate.x=(p?o.contentWindow.innerWidth:X.left+X.width)-o.boundingClientRect.left-o.width/2),o.axis.y&&(o.minTranslate.y=(p?0:X.top)-o.boundingClientRect.top-o.height/2,o.maxTranslate.y=(p?o.contentWindow.innerHeight:X.top+X.height)-o.boundingClientRect.top-o.height/2);h&&h.split(" ").forEach(function(ee){return o.helper.classList.add(ee)}),o.listenerNode=A.touches?y:o.contentWindow,B?(o.listenerNode.addEventListener("wheel",o.handleKeyEnd,!0),o.listenerNode.addEventListener("mousedown",o.handleKeyEnd,!0),o.listenerNode.addEventListener("keydown",o.handleKeyDown)):(Hm.move.forEach(function(ee){return o.listenerNode.addEventListener(ee,o.handleSortMove,!1)}),Hm.end.forEach(function(ee){return o.listenerNode.addEventListener(ee,o.handleSortEnd,!1)})),o.setState({sorting:!0,sortingIndex:w}),b&&b({node:y,index:w,collection:Z,isKeySorting:B,nodes:o.manager.getOrderedRefs(),helper:o.helper},A),B&&o.keyMove(0)},c=o.props,u=c.axis,d=c.getHelperDimensions,h=c.helperClass,m=c.hideSortableGhost,f=c.updateBeforeSortStart,b=c.onSortStart,p=c.useWindowAsScrollContainer,y=s.node,Z=s.collection,B=o.manager.isKeySorting,G=function(){if(typeof f=="function"){o._awaitingUpdateBeforeSortStart=!0;var v=kAt(function(){var w=y.sortableInfo.index;return Promise.resolve(f({collection:Z,index:w,node:y,isKeySorting:B},A)).then(function(){})},function(w,V){if(o._awaitingUpdateBeforeSortStart=!1,w)throw V;return V});if(v&&v.then)return v.then(function(){})}}();return G&&G.then?G.then(l):l(G)}}();return Promise.resolve(a&&a.then?a.then(function(){}):void 0)}catch(l){return Promise.reject(l)}}),_g(fg(fg(o)),"handleSortMove",function(A){var s=o.props.onSortMove;typeof A.preventDefault=="function"&&A.preventDefault(),o.updateHelperPosition(A),o.animateNodes(),o.autoscroll(),s&&s(A)}),_g(fg(fg(o)),"handleSortEnd",function(A){var s=o.props,a=s.hideSortableGhost,l=s.onSortEnd,c=o.manager,u=c.active.collection,d=c.isKeySorting,h=o.manager.getOrderedRefs();o.listenerNode&&(d?(o.listenerNode.removeEventListener("wheel",o.handleKeyEnd,!0),o.listenerNode.removeEventListener("mousedown",o.handleKeyEnd,!0),o.listenerNode.removeEventListener("keydown",o.handleKeyDown)):(Hm.move.forEach(function(y){return o.listenerNode.removeEventListener(y,o.handleSortMove)}),Hm.end.forEach(function(y){return o.listenerNode.removeEventListener(y,o.handleSortEnd)}))),o.helper.parentNode.removeChild(o.helper),a&&o.sortableGhost&&MV(o.sortableGhost,{opacity:"",visibility:""});for(var m=0,f=h.length;ma)){o.prevIndex=c,o.newIndex=l;var u=vAt(o.newIndex,o.prevIndex,o.index),d=s.find(function(B){var G=B.node;return G.sortableInfo.index===u}),h=d.node,m=o.containerScrollDelta,f=d.boundingClientRect||W5(h,m),b=d.translate||{x:0,y:0},p={top:f.top+b.y-m.top,left:f.left+b.x-m.left},y=cB?B/2:this.height/2,width:this.width>Z?Z/2:this.width/2},v=h&&y>this.index&&y<=m,w=h&&y=m,V={x:0,y:0},S=u[f].edgeOffset;S||(S=G1(p,this.container),u[f].edgeOffset=S,h&&(u[f].boundingClientRect=W5(p,l)));var X=f0&&u[f-1];if(X&&!X.edgeOffset&&(X.edgeOffset=G1(X.node,this.container),h&&(X.boundingClientRect=W5(X.node,l))),y===this.index){s&&(this.sortableGhost=p,MV(p,{opacity:0,visibility:"hidden"}));continue}A&&R5(p,A),this.axis.x?this.axis.y?w||ythis.containerBoundingRect.width-G.width&&X&&(V.x=X.edgeOffset.left-S.left,V.y=X.edgeOffset.top-S.top),this.newIndex===null&&(this.newIndex=y)):(v||y>this.index&&(d.left+c.left+G.width>=S.left&&d.top+c.top+G.height>=S.top||d.top+c.top+G.height>=S.top+B))&&(V.x=-(this.width+this.marginOffset.x),S.left+V.xthis.index&&d.left+c.left+G.width>=S.left?(V.x=-(this.width+this.marginOffset.x),this.newIndex=y):(w||ythis.index&&d.top+c.top+G.height>=S.top?(V.y=-(this.height+this.marginOffset.y),this.newIndex=y):(w||y1&&arguments[1]!==void 0?arguments[1]:{withRef:!1};return I=g=function(n){Y7(C,n);function C(){return wS(this,C),k7(this,uB(C).apply(this,arguments))}return VS(C,[{key:"componentDidMount",value:function(){this.register()}},{key:"componentDidUpdate",value:function(o){this.node&&(o.index!==this.props.index&&(this.node.sortableInfo.index=this.props.index),o.disabled!==this.props.disabled&&(this.node.sortableInfo.disabled=this.props.disabled)),o.collection!==this.props.collection&&(this.unregister(o.collection),this.register())}},{key:"componentWillUnmount",value:function(){this.unregister()}},{key:"register",value:function(){var o=this.props,A=o.collection,s=o.disabled,a=o.index,l=Rs.findDOMNode(this);l.sortableInfo={collection:A,disabled:s,index:a,manager:this.context.manager},this.node=l,this.ref={node:l},this.context.manager.add(A,this.ref)}},{key:"unregister",value:function(){var o=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.props.collection;this.context.manager.remove(o,this.ref)}},{key:"getWrappedInstance",value:function(){return $d(i.withRef,"To access the wrapped instance, you need to pass in {withRef: true} as the second argument of the SortableElement() call"),this.refs.wrappedInstance}},{key:"render",value:function(){var o=i.withRef?"wrappedInstance":null;return Ie.createElement(e,cB({ref:o},gZe(this.props,KAt)))}}]),C}(Ie.Component),_g(g,"displayName",K7("sortableElement",e)),_g(g,"contextTypes",{manager:L.object.isRequired}),_g(g,"propTypes",rZe),_g(g,"defaultProps",{collection:0}),I}const AZe=G0(e=>e.pos).left,Vi=(e,g)=>{if(!g||!g.cumPositions||!g.cumPositions.length)return null;let I=AZe(g.cumPositions,e);const i=g.cumPositions[g.cumPositions.length-1].chr,n=g.chromLengths[i];I>0&&(I-=1);let C=Math.floor(e-g.cumPositions[I].pos),r=0;return C<0&&(r=C-1,C=1),I===g.cumPositions.length-1&&C>n&&(r=C-n,C=n),[g.cumPositions[I].chr,C,r,I]},aZe=(e,g)=>I=>I%e*g+Math.floor(I/e),DAt=e=>e,sZe=(e,g,I=DAt)=>e.map((i,n)=>i+g[I(n)]),xAt="http://www.w3.org/2000/svg",LX=(e,g)=>{if(e.namespaceURI===xAt){const I=e.getAttribute("class");return!!I&&!!I.match(new RegExp(`(\\s|^)${g}(\\s|$)`))}return e.classList?e.classList.contains(g):!!e.className.match(new RegExp(`(\\s|^)${g}(\\s|$)`))},FAt="http://www.w3.org/2000/svg",EAt=(e,g)=>{if(e.namespaceURI===FAt){if(!LX(e,g)){const I=e.getAttribute("class")||"";e.setAttribute("class",`${I} ${g}`)}}else e.classList?e.classList.add(g):LX(e,g)||(e.className+=` ${g}`)},MAt=(e,g,I)=>{const i=document.createElement("canvas");return new Promise((n,C)=>{const r=new window.Image;r.onload=()=>{i.width=g||r.width,i.height=I||r.height;const o=i.getContext("2d");if(!o){C(new Error("Could not get canvas context"));return}o.drawImage(r,0,0),n(i)},r.onerror=()=>{C(new Error("Could not convert base64 to canvas"))},r.src=`data:image/png;base64,${e}`})},UX=(e,g,I)=>I.chrPositions[e].pos+g,lZe=e=>{if(!(e instanceof Event))throw new Error("Event must be an instance of Event");const g=new e.constructor(e.type,e);return g.sourceUid=e.sourceUid,g.forwarded=e.forwarded,g},Dc=(e,g=!1)=>{const I=e.map((r,o)=>o*(255/(e.length-1))),i=qt().domain(I).range(e),C=eC(g?255:254,-1,-1).map(i).map(r=>{const o=db(r);return[o.r,o.g,o.b,o.opacity*255]});return C.length<256&&C.push([255,255,255,0]),C},SZ=0,wZ=5,cZe=10,uZe=10,dZe=300,QX="move",Dr="select",p3=100,jX=10,hZe=110,VZ=3e3,RZ="locationListenerPrefix",mZe=1e3,b3="http://higlass.io/api/v1",fZe=400,pZe=300,y3=["top","left","right","bottom","center","whole","gallery"],bZe=20,yZe=20,$X=Symbol("Light theme"),qg=Symbol("Dark theme"),zAt=$X,rt={PIXI:ufe},vr={"multitrack-header":"_multitrack-header_1yz7l_1","multitrack-header-focus":"_multitrack-header-focus_1yz7l_2","multitrack-header-squeazed":"_multitrack-header-squeazed_1yz7l_3","multitrack-header-dark":"_multitrack-header-dark_1yz7l_20","multitrack-header-id":"_multitrack-header-id_1yz7l_30","multitrack-header-left":"_multitrack-header-left_1yz7l_39","multitrack-header-grabber":"_multitrack-header-grabber_1yz7l_44","multitrack-header-grabber-squeazed":"_multitrack-header-grabber-squeazed_1yz7l_45","multitrack-header-search":"_multitrack-header-search_1yz7l_80","multitrack-header-nav-list":"_multitrack-header-nav-list_1yz7l_102","multitrack-header-icon":"_multitrack-header-icon_1yz7l_107","multitrack-header-icon-squeazed":"_multitrack-header-icon-squeazed_1yz7l_108","mouse-tool-selection":"_mouse-tool-selection_1yz7l_136"},PAt={id:"cog",paths:["M466.895 305.125c-26.863-46.527-10.708-106.152 36.076-133.244l-50.313-87.146c-14.375 8.427-31.088 13.259-48.923 13.259-53.768 0-97.354-43.873-97.354-97.995h-100.629c0.133 16.705-4.037 33.641-12.979 49.126-26.862 46.528-86.578 62.351-133.431 35.379l-50.312 87.146c14.485 8.236 27.025 20.294 35.943 35.739 26.819 46.454 10.756 105.96-35.854 133.112l50.313 87.146c14.325-8.348 30.958-13.127 48.7-13.127 53.598 0 97.072 43.596 97.35 97.479h100.627c-0.043-16.537 4.136-33.285 12.983-48.609 26.818-46.453 86.388-62.297 133.207-35.506l50.313-87.145c-14.39-8.233-26.846-20.249-35.717-35.614zM256 359.666c-57.254 0-103.668-46.412-103.668-103.667 0-57.254 46.413-103.667 103.668-103.667s103.666 46.413 103.666 103.667c-0.001 57.255-46.412 103.667-103.666 103.667z"],viewBox:"0 0 512 512"},JAt={id:"cross",paths:["M507.331 411.33c-0.002-0.002-0.004-0.004-0.006-0.005l-155.322-155.325 155.322-155.325c0.002-0.002 0.004-0.003 0.006-0.005 1.672-1.673 2.881-3.627 3.656-5.708 2.123-5.688 0.912-12.341-3.662-16.915l-73.373-73.373c-4.574-4.573-11.225-5.783-16.914-3.66-2.080 0.775-4.035 1.984-5.709 3.655 0 0.002-0.002 0.003-0.004 0.005l-155.324 155.326-155.324-155.325c-0.002-0.002-0.003-0.003-0.005-0.005-1.673-1.671-3.627-2.88-5.707-3.655-5.69-2.124-12.341-0.913-16.915 3.66l-73.374 73.374c-4.574 4.574-5.784 11.226-3.661 16.914 0.776 2.080 1.985 4.036 3.656 5.708 0.002 0.001 0.003 0.003 0.005 0.005l155.325 155.324-155.325 155.326c-0.001 0.002-0.003 0.003-0.004 0.005-1.671 1.673-2.88 3.627-3.657 5.707-2.124 5.688-0.913 12.341 3.661 16.915l73.374 73.373c4.575 4.574 11.226 5.784 16.915 3.661 2.080-0.776 4.035-1.985 5.708-3.656 0.001-0.002 0.003-0.003 0.005-0.005l155.324-155.325 155.324 155.325c0.002 0.001 0.004 0.003 0.006 0.004 1.674 1.672 3.627 2.881 5.707 3.657 5.689 2.123 12.342 0.913 16.914-3.661l73.373-73.374c4.574-4.574 5.785-11.227 3.662-16.915-0.776-2.080-1.985-4.034-3.657-5.707z"],viewBox:"0 0 512 512"},OAt={id:"enlarge",paths:["M512 0h-208l80 80-96 96 48 48 96-96 80 80z","M512 512v-208l-80 80-96-96-48 48 96 96-80 80z","M0 512h208l-80-80 96-96-48-48-96 96-80-80z","M0 0v208l80-80 96 96 48-48-96-96 80-80z"],viewBox:"0 0 512 512"},_At={id:"minus",paths:["M0 208v96c0 8.836 7.164 16 16 16h480c8.836 0 16-7.164 16-16v-96c0-8.836-7.164-16-16-16h-480c-8.836 0-16 7.164-16 16z"],viewBox:"0 0 512 512"},LAt={id:"move",paths:["M512,260.096L405.5,161.79v49.155H301.061v-104.45h49.149L251.904,0L160.77,106.495h49.15v104.45H106.495V161.79L0,260.096l106.495,91.135v-49.149h104.45v104.45H161.79L251.904,512l98.306-106.5h-49.149V301.061H405.5v49.149L512,260.096z"],viewBox:"0 0 512 512"},UAt={id:"play",paths:["M96 64l320 192-320 192z"],viewBox:"0 0 512 512"},QAt={id:"plus",paths:["M496 192h-176v-176c0-8.836-7.164-16-16-16h-96c-8.836 0-16 7.164-16 16v176h-176c-8.836 0-16 7.164-16 16v96c0 8.836 7.164 16 16 16h176v176c0 8.836 7.164 16 16 16h96c8.836 0 16-7.164 16-16v-176h176c8.836 0 16-7.164 16-16v-96c0-8.836-7.164-16-16-16z"],viewBox:"0 0 512 512"},jAt={id:"copy",paths:["M607.5 672v-448.5h-351v448.5h351zM607.5 160.5c34.5 0 64.5 28.5 64.5 63v448.5c0 34.5-30 64.5-64.5 64.5h-351c-34.5 0-64.5-30-64.5-64.5v-448.5c0-34.5 30-63 64.5-63h351zM511.5 31.5v64.5h-384v448.5h-63v-448.5c0-34.5 28.5-64.5 63-64.5h384z"],viewBox:"0 0 712 712"},$At={id:"select",viewBox:"0 0 16 16",paths:["M2 14h2v1H1v-3h1v2zm8 1H6v-1h4v1zm5 0h-3v-1h2v-2h1v3zm0-5h-1V6h1v4zM2 10H1V6h1v4zm13-6h-1V2h-2V1h3v3zM4 2H2v2H1V1h3v1zm6 0H6V1h4.03L10 2z"]},qAt={id:"check_square_o",viewBox:"0 0 1792 1792",paths:["M1472 930v318q0 119-84.5 203.5t-203.5 84.5h-832q-119 0-203.5-84.5t-84.5-203.5v-832q0-119 84.5-203.5t203.5-84.5h832q63 0 117 25 15 7 18 23 3 17-9 29l-49 49q-10 10-23 10-3 0-9-2-23-6-45-6h-832q-66 0-113 47t-47 113v832q0 66 47 113t113 47h832q66 0 113-47t47-113v-254q0-13 9-22l64-64q10-10 23-10 6 0 12 3 20 8 20 29zm231-489l-814 814q-24 24-57 24t-57-24l-430-430q-24-24-24-57t24-57l110-110q24-24 57-24t57 24l263 263 647-647q24-24 57-24t57 24l110 110q24 24 24 57t-24 57z"]},eat={id:"square_o",viewBox:"0 0 1792 1792",paths:["M1312 256h-832q-66 0-113 47t-47 113v832q0 66 47 113t113 47h832q66 0 113-47t47-113v-832q0-66-47-113t-113-47zm288 160v832q0 119-84.5 203.5t-203.5 84.5h-832q-119 0-203.5-84.5t-84.5-203.5v-832q0-119 84.5-203.5t203.5-84.5h832q119 0 203.5 84.5t84.5 203.5z"]},tat={id:"file_o",viewBox:"0 0 1792 1792",paths:["M1596 380q28 28 48 76t20 88v1152q0 40-28 68t-68 28h-1344q-40 0-68-28t-28-68v-1600q0-40 28-68t68-28h896q40 0 88 20t76 48zm-444-244v376h376q-10-29-22-41l-313-313q-12-12-41-22zm384 1528v-1024h-416q-40 0-68-28t-28-68v-416h-768v1536h1280z"]},gat={id:"chevron_right",viewBox:"0 0 1792 1792",paths:["M1363 877l-742 742q-19 19-45 19t-45-19l-166-166q-19-19-19-45t19-45l531-531-531-531q-19-19-19-45t19-45l166-166q19-19 45-19t45 19l742 742q19 19 19 45t-19 45z"]},Iat={id:"chevron_down",viewBox:"0 0 1792 1792",paths:["M1683 808l-742 741q-19 19-45 19t-45-19l-742-741q-19-19-19-45.5t19-45.5l166-165q19-19 45-19t45 19l531 531 531-531q19-19 45-19t45 19l166 165q19 19 19 45.5t-19 45.5z"]},iat={id:"folder_o",viewBox:"0 0 1792 1792",paths:["M1600 1312v-704q0-40-28-68t-68-28h-704q-40 0-68-28t-28-68v-64q0-40-28-68t-68-28h-320q-40 0-68 28t-28 68v960q0 40 28 68t68 28h1216q40 0 68-28t28-68zm128-704v704q0 92-66 158t-158 66h-1216q-92 0-158-66t-66-158v-960q0-92 66-158t158-66h320q92 0 158 66t66 158v32h672q92 0 158 66t66 158z"]},nat={id:"folder_open_o",viewBox:"0 0 1792 1792",paths:["M1845 931q0-35-53-35h-1088q-40 0-85.5 21.5t-71.5 52.5l-294 363q-18 24-18 40 0 35 53 35h1088q40 0 86-22t71-53l294-363q18-22 18-39zm-1141-163h768v-160q0-40-28-68t-68-28h-576q-40 0-68-28t-28-68v-64q0-40-28-68t-68-28h-320q-40 0-68 28t-28 68v853l256-315q44-53 116-87.5t140-34.5zm1269 163q0 62-46 120l-295 363q-43 53-116 87.5t-140 34.5h-1088q-92 0-158-66t-66-158v-960q0-92 66-158t158-66h320q92 0 158 66t66 158v32h544q92 0 158 66t66 158v160h192q54 0 99 24.5t67 70.5q15 32 15 68z"]},Cat=[PAt,JAt,OAt,_At,LAt,UAt,QAt,jAt,$At,qAt,eat,tat,iat,nat,gat,Iat],cA=new DOMParser,rat='',D7=cA.parseFromString(rat,"text/xml").documentElement,oat=` @@ -1244,7 +1643,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho -`,Xot=bA.parseFromString(Wot,"text/xml").documentElement,Hot=` +`,Aat=cA.parseFromString(oat,"text/xml").documentElement,aat=` line @@ -1252,7 +1651,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho -`,Tot=bA.parseFromString(Hot,"text/xml").documentElement,Not=` +`,sat=cA.parseFromString(aat,"text/xml").documentElement,lat=` 2d-tiles-icon @@ -1282,7 +1681,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho -`,TIe=bA.parseFromString(Not,"text/xml").documentElement,kot=` +`,Lge=cA.parseFromString(lat,"text/xml").documentElement,cat=` 2d-heatmap @@ -1310,7 +1709,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho -`,NIe=bA.parseFromString(kot,"text/xml").documentElement,HGe=` +`,Uge=cA.parseFromString(cat,"text/xml").documentElement,ZZe=` axis-1d @@ -1320,7 +1719,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho -`,Yot=bA.parseFromString(HGe,"text/xml").documentElement,Kot=pg(bA.parseFromString(HGe,"text/xml").documentElement).style("transform","rotate(90deg)").node(),xot=` +`,uat=cA.parseFromString(ZZe,"text/xml").documentElement,dat=cg(cA.parseFromString(ZZe,"text/xml").documentElement).style("transform","rotate(90deg)").node(),hat=` gene-annotations @@ -1347,7 +1746,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho -`,Dot=bA.parseFromString(xot,"text/xml").documentElement,TGe=` +`,mat=cA.parseFromString(hat,"text/xml").documentElement,GZe=` 1d-tiles-icon @@ -1367,7 +1766,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho -`,Fot=bA.parseFromString(TGe,"text/xml").documentElement,Eot=pg(bA.parseFromString(TGe,"text/xml").documentElement).style("transform","rotate(90deg)").node(),Mot=` +`,fat=cA.parseFromString(GZe,"text/xml").documentElement,pat=cg(cA.parseFromString(GZe,"text/xml").documentElement).style("transform","rotate(90deg)").node(),bat=` arrowhead-domains @@ -1387,27 +1786,27 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho -`,nZ=bA.parseFromString(Mot,"text/xml").documentElement;function NGe({theStyle:g,onClick:e}){return N.createElement("svg",{className:Tr[g],viewBox:"0 0 12 13",onClick:e,xmlns:"http://www.w3.org/2000/svg"},N.createElement("g",{fill:"none",stroke:"#6c6c6c",strokeWidth:"2"},N.createElement("path",{d:"M11.29 11.71l-4-4"}),N.createElement("circle",{cx:"5",cy:"5",r:"4"})))}NGe.propTypes={theStyle:L.string,onClick:L.func};const kIe={type:"osm-tiles",datatype:["map-tiles"],local:!0,orientation:"2d",hidden:!0,name:"OSM Tiles",thumbnail:mQ,availableOptions:["minPos","maxPos","maxZoom","labelPosition","labelLeftMargin","labelRightMargin","labelTopMargin","labelBottomMargin","name"],defaultOptions:{minPos:-180,maxPos:180,maxZoom:19,labelPosition:"bottomRight",labelLeftMargin:0,labelRightMargin:0,labelTopMargin:0,labelBottomMargin:0}},YIe={type:"mapbox-tiles",datatype:["map-tiles"],local:!0,orientation:"2d",hidden:!0,name:"Mapbox Tiles",thumbnail:mQ,availableOptions:["style","labelPosition","labelLeftMargin","labelRightMargin","labelTopMargin","labelBottomMargin","name"],defaultOptions:{style:"mapbox.streets",labelPosition:"bottomRight",labelLeftMargin:0,labelRightMargin:0,labelTopMargin:0,labelBottomMargin:0}},dh=[kIe,{...kIe,type:"osm"},YIe,{...YIe,type:"mapbox"},{type:"left-axis",datatype:["axis"],local:!0,orientation:"1d-vertical",name:"Left Axis",thumbnail:Kot,availableOptions:["minWidth"],defaultOptions:{minWidth:100}},{type:"top-axis",datatype:["axis"],local:!0,orientation:"1d-horizontal",name:"Top Axis",thumbnail:Yot,defaultOptions:{}},{type:"horizontal-rule",datatype:["x-coord"],local:!0,orientation:"whole",name:"Horizontal Rule",thumbnail:null,availableOptions:["color"],defaultOptions:{color:"black"}},{type:"vertical-rule",datatype:["y-coord"],local:!0,orientation:"whole",name:"Vertical Rule",thumbnail:null,availableOptions:["color"],defaultOptions:{color:"black"}},{type:"cross-rule",datatype:["xy-coord"],local:!0,orientation:"whole",name:"Cross Rule",thumbnail:null,availableOptions:["color"],defaultOptions:{color:"black"}},{type:"simple-svg",datatype:[],local:!1,orientation:"2d",exportable:!0,availableOptions:["minWidth","minHeight"],defaultOptions:{minWidth:100,minHeight:100}},{type:"heatmap",datatype:["matrix"],local:!1,orientation:"2d",thumbnail:NIe,exportable:!0,availableOptions:["backgroundColor","labelPosition","labelLeftMargin","labelRightMargin","labelTopMargin","labelBottomMargin","labelShowResolution","labelShowAssembly","labelColor","labelTextOpacity","labelBackgroundOpacity","colorRange","colorbarBackgroundColor","maxZoom","minWidth","minHeight","dataTransform","colorbarPosition","trackBorderWidth","trackBorderColor","heatmapValueScaling","showMousePosition","mousePositionColor","showTooltip","extent","zeroValueColor"],defaultOptions:{backgroundColor:"#eeeeee",labelPosition:"bottomRight",labelLeftMargin:0,labelRightMargin:0,labelTopMargin:0,labelBottomMargin:0,labelShowResolution:!0,labelShowAssembly:!0,colorRange:["white","rgba(245,166,35,1.0)","rgba(208,2,27,1.0)","black"],colorbarBackgroundColor:"#ffffff",maxZoom:null,minWidth:100,minHeight:100,colorbarPosition:"topRight",trackBorderWidth:0,trackBorderColor:"black",heatmapValueScaling:"log",showMousePosition:!1,mousePositionColor:"#000000",showTooltip:!1,extent:"full",zeroValueColor:null},defaultOptionsByTheme:{[II]:{backgroundColor:"#000000",colorRange:["black","rgba(208,2,27,1.0)","rgba(245,166,35,1.0)","white"],colorbarBackgroundColor:"#000000",labelColor:"#ffffff",labelBackgroundColor:"#000000",trackBorderColor:"#ffffff",mousePositionColor:"#ffffff"}}},{type:"linear-heatmap",aliases:["horizontal-heatmap","vertical-heatmap"],datatype:["matrix"],local:!1,orientation:"1d-horizontal",rotatable:!0,thumbnail:NIe,defaultOptions:{backgroundColor:"#eeeeee",labelPosition:"bottomRight",labelLeftMargin:0,labelRightMargin:0,labelTopMargin:0,labelBottomMargin:0,labelShowResolution:!0,labelShowAssembly:!0,labelColor:"black",colorRange:["white","rgba(245,166,35,1.0)","rgba(208,2,27,1.0)","black"],maxZoom:null,minWidth:100,minHeight:40,trackBorderWidth:0,trackBorderColor:"black"},availableOptions:["backgroundColor","labelPosition","labelLeftMargin","labelRightMargin","labelTopMargin","labelBottomMargin","labelShowResolution","labelShowAssembly","labelColor","labelTextOpacity","labelBackgroundOpacity","colorRange","maxZoom","minWidth","minHeight","dataTransform","oneDHeatmapFlipped","colorbarPosition","trackBorderWidth","trackBorderColor","heatmapValueScaling"]},{type:"line",aliases:["horizontal-line","vertical-line"],datatype:["vector"],local:!1,orientation:"1d-horizontal",rotatable:!0,thumbnail:Tot,availableOptions:["labelPosition","labelLeftMargin","labelRightMargin","labelTopMargin","labelBottomMargin","labelShowResolution","labelShowAssembly","labelColor","labelTextOpacity","labelBackgroundColor","labelBackgroundOpacity","axisLabelFormatting","axisPositionHorizontal","axisMargin","lineStrokeWidth","lineStrokeColor","valueScaling","valueScaleMin","valueScaleMax","trackBorderWidth","trackBorderColor","trackType","showMousePosition","showTooltip","mousePositionColor","aggregationMode","minHeight"],defaultOptions:{labelColor:"black",labelPosition:"topLeft",labelLeftMargin:0,labelRightMargin:0,labelTopMargin:0,labelBottomMargin:0,labelBackgroundColor:"white",labelShowResolution:!1,labelShowAssembly:!0,axisLabelFormatting:"scientific",axisPositionHorizontal:"right",lineStrokeColor:"blue",lineStrokeWidth:1,valueScaling:"linear",trackBorderWidth:0,trackBorderColor:"black",labelTextOpacity:.4,showMousePosition:!1,minHeight:20,mousePositionColor:"#000000",showTooltip:!1},defaultOptionsByTheme:{[II]:{labelColor:"#ffffff",labelBackgroundColor:"#000000",trackBorderColor:"#ffffff",mousePositionColor:"#ffffff"}}},{type:"1d-heatmap",aliases:["horizontal-1d-heatmap","vertical-1d-heatmap"],datatype:["vector"],local:!1,orientation:"1d-horizontal",rotatable:!0,thumbnail:Xot,availableOptions:["labelPosition","labelLeftMargin","labelRightMargin","labelTopMargin","labelBottomMargin","labelShowResolution","labelShowAssembly","labelColor","labelTextOpacity","labelBackgroundOpacity","axisPositionHorizontal","axisMargin","colorRange","valueScaling","trackBorderWidth","trackBorderColor","trackType","showMousePosition","showTooltip","mousePositionColor","aggregationMode"],defaultOptions:{labelColor:"black",labelPosition:"topLeft",labelLeftMargin:0,labelRightMargin:0,labelTopMargin:0,labelBottomMargin:0,labelShowResolution:!1,labelShowAssembly:!0,axisPositionHorizontal:"right",colorRange:["white","rgba(245,166,35,1.0)","rgba(208,2,27,1.0)","black"],valueScaling:"linear",trackBorderWidth:0,trackBorderColor:"black",labelTextOpacity:.4,showMousePosition:!1,mousePositionColor:"#000000",showTooltip:!1}},{type:"vector-heatmap",aliases:["horizontal-vector-heatmap","vertical-vector-heatmap"],datatype:["vector"],local:!1,orientation:"1d-horizontal",rotatable:!0,minHeight:1,thumbnail:null,availableOptions:["labelPosition","labelLeftMargin","labelRightMargin","labelTopMargin","labelBottomMargin","labelShowResolution","labelShowAssembly","labelColor","valueScaling","labelTextOpacity","labelBackgroundOpacity","colorRange","trackBorderWidth","trackBorderColor","trackType","heatmapValueScaling"],defaultOptions:{labelPosition:"topLeft",labelLeftMargin:0,labelRightMargin:0,labelTopMargin:0,labelBottomMargin:0,labelShowResolution:!1,labelShowAssembly:!0,labelColor:"black",labelTextOpacity:.4,valueScaling:"linear",trackBorderWidth:0,trackBorderColor:"black",heatmapValueScaling:"log"}},{type:"multivec",aliases:["horizontal-multivec","vertical-multivec"],datatype:["multivec"],local:!1,orientation:"1d-horizontal",rotatable:!0,thumbnail:null,availableOptions:["labelPosition","labelLeftMargin","labelRightMargin","labelTopMargin","labelBottomMargin","labelShowResolution","labelShowAssembly","labelColor","minHeight","valueScaling","labelTextOpacity","labelBackgroundOpacity","colorRange","trackBorderWidth","trackBorderColor","trackType","heatmapValueScaling","selectRows","selectRowsAggregationMode","selectRowsAggregationWithRelativeHeight","selectRowsAggregationMethod","colorbarBackgroundColor","colorbarPosition","zeroValueColor"],defaultOptions:{labelPosition:"topLeft",labelLeftMargin:0,labelRightMargin:0,labelTopMargin:0,labelBottomMargin:0,labelShowResolution:!0,labelShowAssembly:!0,labelColor:"black",labelTextOpacity:.4,minHeight:100,valueScaling:"linear",trackBorderWidth:0,trackBorderColor:"black",heatmapValueScaling:"log",selectRows:null,selectRowsAggregationMode:"mean",selectRowsAggregationWithRelativeHeight:!0,selectRowsAggregationMethod:"client",colorbarBackgroundColor:"#ffffff",colorbarPosition:"topRight",zeroValueColor:null},defaultOptionsByTheme:{[II]:{colorbarBackgroundColor:"#000000"}}},{type:"point",aliases:["horizontal-point","vertical-point"],datatype:["vector"],local:!1,orientation:"1d-horizontal",rotatable:!0,availableOptions:["labelPosition","labelLeftMargin","labelRightMargin","labelTopMargin","labelBottomMargin","labelShowResolution","labelShowAssembly","labelColor","labelTextOpacity","labelBackgroundOpacity","axisLabelFormatting","axisPositionHorizontal","axisMargin","pointColor","pointSize","valueScaling","trackBorderWidth","trackBorderColor"],defaultOptions:{labelColor:"black",labelPosition:"topLeft",labelLeftMargin:0,labelRightMargin:0,labelTopMargin:0,labelBottomMargin:0,labelShowResolution:!1,labelShowAssembly:!0,axisLabelFormatting:"scientific",axisPositionHorizontal:"right",pointColor:"red",pointSize:3,valueScaling:"linear",trackBorderWidth:0,trackBorderColor:"black",labelTextOpacity:.4}},{type:"divergent-bar",aliases:["horizontal-divergent-bar","vertical-divergent-bar"],datatype:["vector"],local:!1,orientation:"1d-horizontal",rotatable:!0,availableOptions:["labelPosition","labelLeftMargin","labelRightMargin","labelTopMargin","labelBottomMargin","labelShowResolution","labelShowAssembly","labelColor","labelTextOpacity","labelBackgroundOpacity","axisLabelFormatting","axisPositionHorizontal","axisMargin","barFillColorTop","barFillColorBottom","valueScaling","trackBorderWidth","trackBorderColor","barOpacity"],defaultOptions:{labelColor:"black",labelPosition:"topLeft",labelLeftMargin:0,labelRightMargin:0,labelTopMargin:0,labelBottomMargin:0,labelShowResolution:!1,labelShowAssembly:!0,axisPositionHorizontal:"right",axisLabelFormatting:"scientific",barFillColorBottom:"red",barFillColorTop:"green",valueScaling:"linear",trackBorderWidth:0,trackBorderColor:"black",labelTextOpacity:.4,barOpacity:1}},{type:"bar",aliases:["horizontal-bar","vertical-bar"],datatype:["vector"],local:!1,orientation:"1d-horizontal",rotatable:!0,availableOptions:["align","labelPosition","labelLeftMargin","labelRightMargin","labelTopMargin","labelBottomMargin","labelShowResolution","labelShowAssembly","labelColor","labelTextOpacity","labelBackgroundOpacity","axisLabelFormatting","axisPositionHorizontal","axisMargin","barFillColor","colorRange","colorRangeGradient","valueScaling","valueScaleMin","valueScaleMax","trackBorderWidth","trackBorderColor","barOpacity","showMousePosition","showTooltip","aggregationMode","zeroLineVisible","zeroLineColor","zeroLineOpacity"],defaultOptions:{align:"bottom",labelColor:"[glyph-color]",labelPosition:"topLeft",labelLeftMargin:0,labelRightMargin:0,labelTopMargin:0,labelBottomMargin:0,labelShowResolution:!1,labelShowAssembly:!0,axisLabelFormatting:"scientific",axisPositionHorizontal:"right",barFillColor:"darkgreen",valueScaling:"linear",trackBorderWidth:0,trackBorderColor:"black",labelTextOpacity:.4,barOpacity:1}},{type:"2d-tiles",datatype:["matrix"],local:!1,orientation:"2d",name:"2D Tile Outlines",thumbnail:TIe},{type:"1d-value-interval",aliases:["horizontal-1d-value-interval","vertical-1d-value-interval"],datatype:["bed-value"],local:!1,orientation:"1d-horizontal",rotatable:!0,name:"1D Rectangles",availableOptions:["labelPosition","labelLeftMargin","labelRightMargin","labelTopMargin","labelBottomMargin","labelColor","labelTextOpacity","labelBackgroundOpacity","axisPositionHorizontal","axisMargin"],defaultOptions:{labelColor:"black",labelPosition:"bottomLeft",labelLeftMargin:0,labelRightMargin:0,labelTopMargin:0,labelBottomMargin:0,axisPositionHorizontal:"left",lineStrokeColor:"blue",valueScaling:"linear"}},{type:"stacked-interval",aliases:["top-stacked-interval","left-stacked-interval"],datatype:["stacked-interval"],local:!1,orientation:"1d-horizontal",rotatable:!0,thumbnail:"horizontal-stacked-interval.png",availableOptions:["labelPosition","labelLeftMargin","labelRightMargin","labelTopMargin","labelBottomMargin","labelColor","labelTextOpacity","labelBackgroundOpacity"]},{type:"viewport-projection-vertical",datatype:["1d-projection"],local:!0,hidden:!0,projection:!0,orientation:"1d-vertical",name:"Viewport Projection",thumbnail:"viewport-projection-center.png",availableOptions:["projectionFillColor","projectionStrokeColor","strokeWidth"],defaultOptions:{projectionFillColor:"#777",projectionStrokeColor:"#777",projectionFillOpacity:.3,projectionStrokeOpacity:.7,strokeWidth:1}},{type:"viewport-projection-horizontal",datatype:["1d-projection"],local:!0,hidden:!0,projection:!0,orientation:"1d-horizontal",name:"Viewport Projection",thumbnail:"viewport-projection-center.png",availableOptions:["projectionFillColor","projectionStrokeColor","strokeWidth"],defaultOptions:{projectionFillColor:"#777",projectionStrokeColor:"#777",projectionFillOpacity:.3,projectionStrokeOpacity:.7,strokeWidth:1}},{type:"viewport-projection-center",datatype:["2d-projection"],local:!0,hidden:!0,projection:!0,orientation:"2d",name:"Viewport Projection",thumbnail:"viewport-projection-center.png",availableOptions:["projectionFillColor","projectionStrokeColor","strokeWidth"],defaultOptions:{projectionFillColor:"#777",projectionStrokeColor:"#777",projectionFillOpacity:.3,projectionStrokeOpacity:.7,strokeWidth:1}},{type:"gene-annotations",aliases:["horizontal-gene-annotations","vertical-gene-annotations"],datatype:["gene-annotation"],local:!1,defaultHeight:90,defaultWidth:90,rotatable:!0,orientation:"1d-horizontal",name:"Gene Annotations",thumbnail:Dot,availableOptions:["labelPosition","labelLeftMargin","labelRightMargin","labelTopMargin","labelBottomMargin","labelColor","labelTextOpacity","labelBackgroundColor","labelBackgroundOpacity","minHeight","plusStrandColor","minusStrandColor","trackBorderWidth","trackBorderColor","showMousePosition","mousePositionColor","fontSize","geneAnnotationHeight","geneLabelPosition","geneStrandSpacing"],defaultOptions:{fontSize:10,labelColor:"black",labelBackgroundColor:"#ffffff",labelPosition:"hidden",labelLeftMargin:0,labelRightMargin:0,labelTopMargin:0,labelBottomMargin:0,minHeight:24,plusStrandColor:"blue",minusStrandColor:"red",trackBorderWidth:0,trackBorderColor:"black",showMousePosition:!1,mousePositionColor:"#000000",geneAnnotationHeight:16,geneLabelPosition:"outside",geneStrandSpacing:4},defaultOptionsByTheme:{[II]:{labelColor:"#ffffff",labelBackgroundColor:"#000000",trackBorderColor:"#ffffff",mousePositionColor:"#ffffff",plusStrandColor:"#40a0ff"}}},{type:"arrowhead-domains",datatype:["arrowhead-domains"],local:!1,orientation:"2d",name:"Arrowhead Domains",thumbnail:nZ,availableOptions:["labelPosition","labelLeftMargin","labelRightMargin","labelTopMargin","labelBottomMargin","labelColor","labelTextOpacity","labelBackgroundOpacity","trackBorderWidth","trackBorderColor"],defaultOptions:{labelColor:"black",labelPosition:"hidden",labelLeftMargin:0,labelRightMargin:0,labelTopMargin:0,labelBottomMargin:0,trackBorderWidth:0,trackBorderColor:"black"}},{type:"linear-2d-rectangle-domains",aliases:["horizontal-2d-rectangle-domains","vertical-2d-rectangle-domains"],datatype:["2d-rectangle-domains"],local:!1,orientation:"1d-horizontal",rotatable:!0,name:"Horizontal 2D Rectangle Domains",thumbnail:nZ,availableOptions:["labelPosition","labelLeftMargin","labelRightMargin","labelTopMargin","labelBottomMargin","labelColor","labelTextOpacity","labelBackgroundOpacity","trackBorderWidth","trackBorderColor","rectangleDomainFillColor","rectangleDomainStrokeColor","rectangleDomainOpacity","minSquareSize"],defaultOptions:{labelColor:"black",labelPosition:"bottomLeft",labelLeftMargin:0,labelRightMargin:0,labelTopMargin:0,labelBottomMargin:0,trackBorderWidth:0,trackBorderColor:"black",rectangleDomainFillColor:"grey",rectangleDomainStrokeColor:"black",rectangleDomainOpacity:.6,minSquareSize:"none"}},{type:"2d-rectangle-domains",datatype:["2d-rectangle-domains"],local:!1,orientation:"2d",name:"2D Rectangle Domains",thumbnail:nZ,availableOptions:["flipDiagonal","labelPosition","labelLeftMargin","labelRightMargin","labelTopMargin","labelBottomMargin","labelColor","labelTextOpacity","labelBackgroundOpacity","trackBorderWidth","trackBorderColor","rectangleDomainFillColor","rectangleDomainFillOpacity","rectangleDomainStrokeColor","rectangleDomainOpacity","minSquareSize"],defaultOptions:{flipDiagonal:"none",labelColor:"black",labelPosition:"hidden",labelLeftMargin:0,labelRightMargin:0,labelTopMargin:0,labelBottomMargin:0,trackBorderWidth:0,trackBorderColor:"black",rectangleDomainFillColor:"grey",rectangleDomainFillOpacity:.4,rectangleDomainStrokeColor:"black",rectangleDomainOpacity:.6,minSquareSize:"none"}},{type:"horizontal-1d-annotations",datatype:["nothing"],local:!1,orientation:"1d-horizontal",name:"Horizontal 1D Annotations",thumbnail:null,availableOptions:["fill","fillOpacity","stroke","strokeOpacity","strokeWidth","strokePos","regions"],defaultOptions:{fill:"red",fillOpacity:.2,stroke:"red",strokeOpacity:0,strokeWidth:1,regions:[],strokePos:[]}},{type:"vertical-1d-annotations",datatype:["nothing"],local:!1,orientation:"1d-vertical",name:"Vertical 1D Annotations",thumbnail:null,availableOptions:["fill","fillOpacity","stroke","strokeOpacity","regions"],defaultOptions:{fill:"red",fillOpacity:"0.2",stroke:"red",strokeOpacity:"0",regions:[]}},{type:"2d-annotations",datatype:["2d-annotations"],local:!1,orientation:"2d",name:"2D Annotations",thumbnail:nZ,availableOptions:["labelPosition","labelLeftMargin","labelRightMargin","labelTopMargin","labelBottomMargin","labelColor","labelTextOpacity","labelBackgroundOpacity","trackBorderWidth","trackBorderColor","rectangleDomainFillColor","rectangleDomainStrokeColor","rectangleDomainOpacity","minSquareSize","isClickable","hoverColor","selectColor","exclude","trackBorderBgWidth","trackBorderBgColor","trackBorderBgAlpha"],defaultOptions:{labelColor:"black",labelPosition:"hidden",labelLeftMargin:0,labelRightMargin:0,labelTopMargin:0,labelBottomMargin:0,trackBorderWidth:0,trackBorderColor:"black",rectangleDomainFillColor:"grey",rectangleDomainStrokeColor:"black",rectangleDomainOpacity:.6,minSquareSize:"none",isClickable:!1,hoverColor:"orange",selectColor:"fuchsia",exclude:[],trackBorderBgWidth:0,trackBorderBgColor:"black",trackBorderBgAlpha:.33}},{type:"square-markers",datatype:["bedpe"],local:!1,orientation:"2d",name:"Square Markers",thumbnail:nZ,availableOptions:["labelPosition","labelLeftMargin","labelRightMargin","labelTopMargin","labelBottomMargin","labelColor"],defaultOptions:{labelColor:"black",labelPosition:"hidden",labelLeftMargin:0,labelRightMargin:0,labelTopMargin:0,labelBottomMargin:0,trackBorderWidth:0,trackBorderColor:"black"}},{type:"combined",datatype:"any",local:!0,orientation:"any"},{type:"horizontal-chromosome-grid",datatype:["chromsizes"],local:!1,orientation:"1d-horizontal",name:"Chromosome Grid",chromInfoPath:"//s3.amazonaws.com/pkerp/data/hg19/chromSizes.tsv",thumbnail:null,availableOptions:["lineStrokeWidth","lineStrokeColor","showMousePosition"],defaultOptions:{lineStrokeWidth:1,lineStrokeColor:"grey",showMousePosition:!1}},{type:"vertical-chromosome-grid",datatype:["chromsizes"],local:!1,orientation:"1d-vertical",name:"Chromosome Grid",chromInfoPath:"//s3.amazonaws.com/pkerp/data/hg19/chromSizes.tsv",thumbnail:null,availableOptions:["lineStrokeWidth","lineStrokeColor","showMousePosition"],defaultOptions:{lineStrokeWidth:1,lineStrokeColor:"grey",showMousePosition:!1}},{type:"2d-chromosome-grid",datatype:["chromsizes"],local:!1,orientation:"2d",name:"Chromosome Grid",chromInfoPath:"//s3.amazonaws.com/pkerp/data/hg19/chromSizes.tsv",thumbnail:null,availableOptions:["lineStrokeWidth","lineStrokeColor"],defaultOptions:{lineStrokeWidth:1,lineStrokeColor:"grey"}},{type:"2d-chromosome-annotations",datatype:["chromsizes"],local:!0,orientation:"2d",name:"2D Chromosome Annotations",thumbnail:null,hidden:!0},{type:"2d-chromosome-labels",datatype:["chromsizes"],local:!0,orientation:"2d",name:"Pairwise Chromosome Labels",thumbnail:null},{type:"chromosome-labels",aliases:["horizontal-chromosome-labels","vertical-chromosome-labels"],datatype:["chromsizes"],orientation:"1d-horizontal",rotatable:!0,minHeight:35,defaultHeight:30,name:"Chromosome Axis",thumbnail:null,availableOptions:["color","stroke","fontSize","fontIsLeftAligned","showMousePosition","mousePositionColor","tickPositions","tickFormat","reverseOrientation"],defaultOptions:{color:"#808080",stroke:"#ffffff",fontSize:12,fontIsLeftAligned:!1,showMousePosition:!1,mousePositionColor:"#000000",reverseOrientation:!1},defaultOptionsByTheme:{[II]:{color:"#808080",stroke:"#000000",mousePositionColor:"#ffffff"}}},{type:"vertical-1d-tiles",datatype:["1d-tiles"],local:!1,orientation:"1d-vertical",name:"Vertical 1D Tile Outlines",thumbnail:Eot},{type:"horizontal-1d-tiles",datatype:["vector","stacked-interval","gene-annotation"],local:!1,orientation:"1d-horizontal",name:"Horizontal 1D Tile Outlines",thumbnail:Fot},{type:"osm-2d-tile-ids",datatype:["map-tiles"],local:!1,orientation:"2d",name:"OSM Tile Outlines",thumbnail:TIe,availableOptions:["minPos","maxPos","maxZoom","labelPosition","labelLeftMargin","labelRightMargin","labelTopMargin","labelBottomMargin","name"],defaultOptions:{minPos:-180,maxPos:180,maxZoom:19,labelPosition:"bottomRight",labelLeftMargin:0,labelRightMargin:0,labelTopMargin:0,labelBottomMargin:0}},{type:"raster-tiles",datatype:["map-tiles"],local:!0,orientation:"2d",hidden:!0,name:"Raster Tiles",thumbnail:mQ,availableOptions:["labelPosition","labelLeftMargin","labelRightMargin","labelTopMargin","labelBottomMargin","name"],defaultOptions:{labelPosition:"bottomRight",labelLeftMargin:0,labelRightMargin:0,labelTopMargin:0,labelBottomMargin:0}},{type:"image-tiles",datatype:["image-tiles"],local:!0,orientation:"2d",hidden:!0,name:"Image Tiles",thumbnail:null},{type:"bedlike",datatype:["bedlike"],aliases:["vertical-bedlike"],local:!1,orientation:"1d-horizontal",rotatable:!0,name:"BED-like track",thumbnail:null,availableOptions:["alternating","annotationHeight","annotationStyle","fillColor","fillOpacity","fontColor","fontSize","minusStrandColor","plusStrandColor","labelBottomMargin","labelColor","labelLeftMargin","labelPosition","labelRightMargin","labelTopMargin","labelTextOpacity","labelBackgroundOpacity","maxAnnotationHeight","minHeight","trackBorderWidth","trackBorderColor","valueColumn","colorEncoding","colorRange","colorEncodingRange","separatePlusMinusStrands","showTexts","axisPositionHorizontal","axisMargin"],defaultOptions:{alternating:!1,annotationStyle:"box",fillColor:"blue",fillOpacity:.3,fontSize:"10",axisPositionHorizontal:"right",labelColor:"black",labelPosition:"hidden",labelLeftMargin:0,labelRightMargin:0,labelTopMargin:0,labelBottomMargin:0,minHeight:20,maxAnnotationHeight:null,trackBorderWidth:0,trackBorderColor:"black",valueColumn:null,colorEncoding:"itemRgb",showTexts:!1,colorRange:["#000000","#652537","#bf5458","#fba273","#ffffe0"],colorEncodingRange:!1,separatePlusMinusStrands:!0,annotationHeight:16}},{type:"empty",datatype:[],orientation:"1d-horizontal",name:"Empty track",thumbnail:null,availableOptions:[],defaultOptions:{}}],fQ=g=>{const e={},I=i=>!!(i.orientation===g||g==="1d-vertical"&&i.orientation==="1d-horizontal"&&i.rotatable);return dh.filter(I).forEach(i=>{let n=i.datatype;Array.isArray(i.datatype)||(n=[n]),n.forEach(C=>{C in e||(e[C]=[]),e[C].push(i)})}),e.none=[],e},Pb=[[0,0,0,255],[35,0,0,255],[52,0,0,255],[60,0,0,255],[63,1,0,255],[64,2,0,255],[68,5,0,255],[69,6,0,255],[72,8,0,255],[74,10,0,255],[77,12,0,255],[78,14,0,255],[81,16,0,255],[83,17,0,255],[85,19,0,255],[86,20,0,255],[89,22,0,255],[91,24,0,255],[92,25,0,255],[94,26,0,255],[95,28,0,255],[98,30,0,255],[100,31,0,255],[102,33,0,255],[103,34,0,255],[105,35,0,255],[106,36,0,255],[108,38,0,255],[109,39,0,255],[111,40,0,255],[112,42,0,255],[114,43,0,255],[115,44,0,255],[117,45,0,255],[119,47,0,255],[119,47,0,255],[120,48,0,255],[122,49,0,255],[123,51,0,255],[125,52,0,255],[125,52,0,255],[126,53,0,255],[128,54,0,255],[129,56,0,255],[129,56,0,255],[131,57,0,255],[132,58,0,255],[134,59,0,255],[134,59,0,255],[136,61,0,255],[137,62,0,255],[137,62,0,255],[139,63,0,255],[139,63,0,255],[140,65,0,255],[142,66,0,255],[142,66,0,255],[143,67,0,255],[143,67,0,255],[145,68,0,255],[145,68,0,255],[146,70,0,255],[146,70,0,255],[148,71,0,255],[148,71,0,255],[149,72,0,255],[149,72,0,255],[151,73,0,255],[151,73,0,255],[153,75,0,255],[153,75,0,255],[154,76,0,255],[154,76,0,255],[154,76,0,255],[156,77,0,255],[156,77,0,255],[157,79,0,255],[157,79,0,255],[159,80,0,255],[159,80,0,255],[159,80,0,255],[160,81,0,255],[160,81,0,255],[162,82,0,255],[162,82,0,255],[163,84,0,255],[163,84,0,255],[165,85,0,255],[165,85,0,255],[166,86,0,255],[166,86,0,255],[166,86,0,255],[168,87,0,255],[168,87,0,255],[170,89,0,255],[170,89,0,255],[171,90,0,255],[171,90,0,255],[173,91,0,255],[173,91,0,255],[174,93,0,255],[174,93,0,255],[176,94,0,255],[176,94,0,255],[177,95,0,255],[177,95,0,255],[179,96,0,255],[179,96,0,255],[180,98,0,255],[182,99,0,255],[182,99,0,255],[183,100,0,255],[183,100,0,255],[185,102,0,255],[185,102,0,255],[187,103,0,255],[187,103,0,255],[188,104,0,255],[188,104,0,255],[190,105,0,255],[191,107,0,255],[191,107,0,255],[193,108,0,255],[193,108,0,255],[194,109,0,255],[196,110,0,255],[196,110,0,255],[197,112,0,255],[197,112,0,255],[199,113,0,255],[200,114,0,255],[200,114,0,255],[202,116,0,255],[202,116,0,255],[204,117,0,255],[205,118,0,255],[205,118,0,255],[207,119,0,255],[208,121,0,255],[208,121,0,255],[210,122,0,255],[211,123,0,255],[211,123,0,255],[213,124,0,255],[214,126,0,255],[214,126,0,255],[216,127,0,255],[217,128,0,255],[217,128,0,255],[219,130,0,255],[221,131,0,255],[221,131,0,255],[222,132,0,255],[224,133,0,255],[224,133,0,255],[225,135,0,255],[227,136,0,255],[227,136,0,255],[228,137,0,255],[230,138,0,255],[230,138,0,255],[231,140,0,255],[233,141,0,255],[233,141,0,255],[234,142,0,255],[236,144,0,255],[236,144,0,255],[238,145,0,255],[239,146,0,255],[241,147,0,255],[241,147,0,255],[242,149,0,255],[244,150,0,255],[244,150,0,255],[245,151,0,255],[247,153,0,255],[247,153,0,255],[248,154,0,255],[250,155,0,255],[251,156,0,255],[251,156,0,255],[253,158,0,255],[255,159,0,255],[255,159,0,255],[255,160,0,255],[255,161,0,255],[255,163,0,255],[255,163,0,255],[255,164,0,255],[255,165,0,255],[255,167,0,255],[255,167,0,255],[255,168,0,255],[255,169,0,255],[255,169,0,255],[255,170,0,255],[255,172,0,255],[255,173,0,255],[255,173,0,255],[255,174,0,255],[255,175,0,255],[255,177,0,255],[255,178,0,255],[255,179,0,255],[255,181,0,255],[255,181,0,255],[255,182,0,255],[255,183,0,255],[255,184,0,255],[255,187,7,255],[255,188,10,255],[255,189,14,255],[255,191,18,255],[255,192,21,255],[255,193,25,255],[255,195,29,255],[255,197,36,255],[255,198,40,255],[255,200,43,255],[255,202,51,255],[255,204,54,255],[255,206,61,255],[255,207,65,255],[255,210,72,255],[255,211,76,255],[255,214,83,255],[255,216,91,255],[255,219,98,255],[255,221,105,255],[255,223,109,255],[255,225,116,255],[255,228,123,255],[255,232,134,255],[255,234,142,255],[255,237,149,255],[255,239,156,255],[255,240,160,255],[255,243,167,255],[255,246,174,255],[255,248,182,255],[255,249,185,255],[255,252,193,255],[255,253,196,255],[255,255,204,255],[255,255,207,255],[255,255,211,255],[255,255,218,255],[255,255,222,255],[255,255,225,255],[255,255,229,255],[255,255,233,255],[255,255,236,255],[255,255,240,255],[255,255,244,255],[255,255,247,255],[255,255,255,0]],$g=dh.reduce((g,e)=>{if(g[e.type]=e,e.aliases)for(const I of e.aliases)g[I]=e;return g},{}),zot=dh.reduce((g,e)=>{for(let I=0;I{const I=fQ(e);let i=new Set(Object.values(I).flatMap(n=>n));for(const n of g){const C=new Set(n);i=new Set([...i].filter(r=>r.datatype.filter(o=>C.has(o)).length>0))}return[...i]},kGe=8,pQ=8,Pot=Object.freeze(Object.defineProperty({__proto__:null,AVAILABLE_TRACK_TYPES:z9,DATATYPE_TO_TRACK_TYPE:fQ,DEFAULT_CONTAINER_PADDING_X:GGe,DEFAULT_CONTAINER_PADDING_Y:BGe,DEFAULT_SERVER:tz,DEFAULT_TRACKS_FOR_DATATYPE:Ev,DEFAULT_VIEW_MARGIN:$Z,DEFAULT_VIEW_PADDING:qZ,GLOBALS:Ct,HEATED_OBJECT_MAP:Pb,LOCATION_LISTENER_PREFIX:tG,LONG_DRAG_TIMEOUT:eG,MAX_CLICK_DELAY:vGe,MIN_HORIZONTAL_HEIGHT:WGe,MIN_VERTICAL_WIDTH:XGe,MOUSE_TOOL_MOVE:F9,MOUSE_TOOL_SELECT:Jr,NUM_PRECOMP_SUBSETS_PER_1D_TTILE:kGe,NUM_PRECOMP_SUBSETS_PER_2D_TTILE:pQ,POSITIONS_BY_DATATYPE:zot,SHORT_DRAG_TIMEOUT:SGe,THEME_DARK:II,THEME_DEFAULT:sot,THEME_LIGHT:M9,TILE_FETCH_DEBOUNCE:ez,TRACKS_INFO:dh,TRACKS_INFO_BY_TYPE:$g,TRACK_LOCATIONS:gz,VIEW_HEADER_MED_WIDTH_SEARCH_BAR:VGe,VIEW_HEADER_MIN_WIDTH_SEARCH_BAR:RGe,ZOOM_DEBOUNCE:E9,ZOOM_TRANSITION_DURATION:wGe},Symbol.toStringTag,{value:"Module"})),zt=g=>{const e=wi(g);return Ct.PIXI.utils.rgb2hex([e.r/255,e.g/255,e.b/255])},YGe=g=>{if(g==="transparent")return[255,255,255,0];const e=wi(g);return[e.r,e.g,e.b,255]},P9=(g,e,I)=>{const i=Vi(g,I),n=Vi(e,I);if(!i||!n)throw new Error("Couldn't convert data to genomic coordinates");return[i[0],Math.round(i[1]),n[0],Math.round(n[1])]},bQ=(g,e,I)=>{let i;const n=(...C)=>{const r=()=>{i=void 0,I||g(...C)},o=I&&!i;clearTimeout(i),i=setTimeout(r,e),o&&g(...C)};return n.cancel=()=>{clearTimeout(i),i=void 0},n},Iz=g=>(g+16**6).toString(16).substr(-6),KGe=g=>{const e={};return g.forEach(I=>{e[I[0]]=I[1]}),e},xr=g=>{const e=[];for(const I in g)g.hasOwnProperty(I)&&e.push([I,g[I]]);return e};function Nr(g){const e=[];for(const I in g)g.hasOwnProperty(I)&&e.push(I);return e}function Pg(g){const e=[];for(const I in g)g.hasOwnProperty(I)&&e.push(g[I]);return e}function tB(g,e){const I=typeof e=="string"?new Blob([e],{type:"application/octet-stream"}):e,i=window.document.createElement("a");i.href=window.URL.createObjectURL(I),i.download=g,document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(i.href)}const xGe=g=>{const e=["top","bottom","gallery"],I=["left","right","gallery"];return g.center=g.center||[],g.left=g.left||[],g.right=g.right||[],g.top=g.top||[],g.bottom=g.bottom||[],g.whole=g.whole||[],g.gallery=g.gallery||[],e.map(i=>g[i]).forEach(i=>i.forEach(n=>{const C=$g[n.type],r=C&&C.defaultOptions||{},o=n.options?{...r,...n.options}:r;o.minHeight!==void 0&&n.height===void 0&&(n.height=o.minHeight),n.height===void 0&&(n.height=C&&C.defaultHeight||WGe)})),I.map(i=>g[i]).forEach(i=>i.forEach(n=>{const C=$g[n.type],r=C&&C.defaultOptions||{},o=n.options?{...r,...n.options}:r;o.minWidth!==void 0&&n.width===void 0&&(n.width=o.minWidth),n.width===void 0&&(n.width=C&&C.defaultWidth||XGe)})),g},DGe=g=>e=>Array.prototype.reduce.call(e,g),Jot=DGe((g,e)=>g.concat(e)),Oot=g=>e=>Array.prototype.forEach.call(e,g),J9=(g,e)=>{e.dispatchEvent(ZGe(g))},Lot=(g,e)=>[D9(g[0],g[1],e),D9(g[2],g[3],e)];function _ot(g,e,I,i,n){const{chr:C,pos:r}=e,{chr:o,pos:A}=I,s=[];if(C===o){const a=C,l=Math.floor(r/i),c=Math.min(l+n,Math.ceil(A/i));s.push([a,l,c])}else{let a=n;const l=g.findIndex(([u])=>u===C),c=g.findIndex(([u])=>u===o);for(let u=l;u<=c;u++){let d,h;const[m,f]=g[u];u{if(I.length===0)return;if(I.length===1)return I[0];let i=I[0];const n=Ev[g]!==void 0?Ev[g][e]:void 0;return n!==void 0&&(i=I.find(C=>C.type===n)||i),i};var KIe={},yx={},Zx=34,CZ=10,Gx=13;function FGe(g){return new Function("d","return {"+g.map(function(e,I){return JSON.stringify(e)+": d["+I+'] || ""'}).join(",")+"}")}function Uot(g,e){var I=FGe(g);return function(i,n){return e(I(i),n,g)}}function xIe(g){var e=Object.create(null),I=[];return g.forEach(function(i){for(var n in i)n in e||I.push(e[n]=n)}),I}function GC(g,e){var I=g+"",i=I.length;return i9999?"+"+GC(g,6):GC(g,4)}function jot(g){var e=g.getUTCHours(),I=g.getUTCMinutes(),i=g.getUTCSeconds(),n=g.getUTCMilliseconds();return isNaN(g)?"Invalid Date":Qot(g.getUTCFullYear())+"-"+GC(g.getUTCMonth()+1,2)+"-"+GC(g.getUTCDate(),2)+(n?"T"+GC(e,2)+":"+GC(I,2)+":"+GC(i,2)+"."+GC(n,3)+"Z":i?"T"+GC(e,2)+":"+GC(I,2)+":"+GC(i,2)+"Z":I||e?"T"+GC(e,2)+":"+GC(I,2)+"Z":"")}function ZQ(g){var e=new RegExp('["'+g+` -\r]`),I=g.charCodeAt(0);function i(l,c){var u,d,h=n(l,function(m,f){if(u)return u(m,f-1);d=m,u=c?Uot(m,c):FGe(m)});return h.columns=d||[],h}function n(l,c){var u=[],d=l.length,h=0,m=0,f,b=d<=0,p=!1;l.charCodeAt(d-1)===CZ&&--d,l.charCodeAt(d-1)===Gx&&--d;function y(){if(b)return yx;if(p)return p=!1,KIe;var v,G=h,B;if(l.charCodeAt(G)===Zx){for(;h++=d?b=!0:(B=l.charCodeAt(h++))===CZ?p=!0:B===Gx&&(p=!0,l.charCodeAt(h)===CZ&&++h),l.slice(G+1,v-1).replace(/""/g,'"')}for(;h{const g={},I=i=>!!(i.orientation===e||e==="1d-vertical"&&i.orientation==="1d-horizontal"&&i.rotatable);return qd.filter(I).forEach(i=>{let n=i.datatype;Array.isArray(i.datatype)||(n=[n]),n.forEach(C=>{C in g||(g[C]=[]),g[C].push(i)})}),g.none=[],g},Gb=[[0,0,0,255],[35,0,0,255],[52,0,0,255],[60,0,0,255],[63,1,0,255],[64,2,0,255],[68,5,0,255],[69,6,0,255],[72,8,0,255],[74,10,0,255],[77,12,0,255],[78,14,0,255],[81,16,0,255],[83,17,0,255],[85,19,0,255],[86,20,0,255],[89,22,0,255],[91,24,0,255],[92,25,0,255],[94,26,0,255],[95,28,0,255],[98,30,0,255],[100,31,0,255],[102,33,0,255],[103,34,0,255],[105,35,0,255],[106,36,0,255],[108,38,0,255],[109,39,0,255],[111,40,0,255],[112,42,0,255],[114,43,0,255],[115,44,0,255],[117,45,0,255],[119,47,0,255],[119,47,0,255],[120,48,0,255],[122,49,0,255],[123,51,0,255],[125,52,0,255],[125,52,0,255],[126,53,0,255],[128,54,0,255],[129,56,0,255],[129,56,0,255],[131,57,0,255],[132,58,0,255],[134,59,0,255],[134,59,0,255],[136,61,0,255],[137,62,0,255],[137,62,0,255],[139,63,0,255],[139,63,0,255],[140,65,0,255],[142,66,0,255],[142,66,0,255],[143,67,0,255],[143,67,0,255],[145,68,0,255],[145,68,0,255],[146,70,0,255],[146,70,0,255],[148,71,0,255],[148,71,0,255],[149,72,0,255],[149,72,0,255],[151,73,0,255],[151,73,0,255],[153,75,0,255],[153,75,0,255],[154,76,0,255],[154,76,0,255],[154,76,0,255],[156,77,0,255],[156,77,0,255],[157,79,0,255],[157,79,0,255],[159,80,0,255],[159,80,0,255],[159,80,0,255],[160,81,0,255],[160,81,0,255],[162,82,0,255],[162,82,0,255],[163,84,0,255],[163,84,0,255],[165,85,0,255],[165,85,0,255],[166,86,0,255],[166,86,0,255],[166,86,0,255],[168,87,0,255],[168,87,0,255],[170,89,0,255],[170,89,0,255],[171,90,0,255],[171,90,0,255],[173,91,0,255],[173,91,0,255],[174,93,0,255],[174,93,0,255],[176,94,0,255],[176,94,0,255],[177,95,0,255],[177,95,0,255],[179,96,0,255],[179,96,0,255],[180,98,0,255],[182,99,0,255],[182,99,0,255],[183,100,0,255],[183,100,0,255],[185,102,0,255],[185,102,0,255],[187,103,0,255],[187,103,0,255],[188,104,0,255],[188,104,0,255],[190,105,0,255],[191,107,0,255],[191,107,0,255],[193,108,0,255],[193,108,0,255],[194,109,0,255],[196,110,0,255],[196,110,0,255],[197,112,0,255],[197,112,0,255],[199,113,0,255],[200,114,0,255],[200,114,0,255],[202,116,0,255],[202,116,0,255],[204,117,0,255],[205,118,0,255],[205,118,0,255],[207,119,0,255],[208,121,0,255],[208,121,0,255],[210,122,0,255],[211,123,0,255],[211,123,0,255],[213,124,0,255],[214,126,0,255],[214,126,0,255],[216,127,0,255],[217,128,0,255],[217,128,0,255],[219,130,0,255],[221,131,0,255],[221,131,0,255],[222,132,0,255],[224,133,0,255],[224,133,0,255],[225,135,0,255],[227,136,0,255],[227,136,0,255],[228,137,0,255],[230,138,0,255],[230,138,0,255],[231,140,0,255],[233,141,0,255],[233,141,0,255],[234,142,0,255],[236,144,0,255],[236,144,0,255],[238,145,0,255],[239,146,0,255],[241,147,0,255],[241,147,0,255],[242,149,0,255],[244,150,0,255],[244,150,0,255],[245,151,0,255],[247,153,0,255],[247,153,0,255],[248,154,0,255],[250,155,0,255],[251,156,0,255],[251,156,0,255],[253,158,0,255],[255,159,0,255],[255,159,0,255],[255,160,0,255],[255,161,0,255],[255,163,0,255],[255,163,0,255],[255,164,0,255],[255,165,0,255],[255,167,0,255],[255,167,0,255],[255,168,0,255],[255,169,0,255],[255,169,0,255],[255,170,0,255],[255,172,0,255],[255,173,0,255],[255,173,0,255],[255,174,0,255],[255,175,0,255],[255,177,0,255],[255,178,0,255],[255,179,0,255],[255,181,0,255],[255,181,0,255],[255,182,0,255],[255,183,0,255],[255,184,0,255],[255,187,7,255],[255,188,10,255],[255,189,14,255],[255,191,18,255],[255,192,21,255],[255,193,25,255],[255,195,29,255],[255,197,36,255],[255,198,40,255],[255,200,43,255],[255,202,51,255],[255,204,54,255],[255,206,61,255],[255,207,65,255],[255,210,72,255],[255,211,76,255],[255,214,83,255],[255,216,91,255],[255,219,98,255],[255,221,105,255],[255,223,109,255],[255,225,116,255],[255,228,123,255],[255,232,134,255],[255,234,142,255],[255,237,149,255],[255,239,156,255],[255,240,160,255],[255,243,167,255],[255,246,174,255],[255,248,182,255],[255,249,185,255],[255,252,193,255],[255,253,196,255],[255,255,204,255],[255,255,207,255],[255,255,211,255],[255,255,218,255],[255,255,222,255],[255,255,225,255],[255,255,229,255],[255,255,233,255],[255,255,236,255],[255,255,240,255],[255,255,244,255],[255,255,247,255],[255,255,255,0]],Lg=qd.reduce((e,g)=>{if(e[g.type]=g,g.aliases)for(const I of g.aliases)e[I]=g;return e},{}),yat=qd.reduce((e,g)=>{for(let I=0;I{const I=x7(g);let i=new Set(Object.values(I).flatMap(n=>n));for(const n of e){const C=new Set(n);i=new Set([...i].filter(r=>r.datatype.filter(o=>C.has(o)).length>0))}return[...i]},BZe=8,F7=8,Zat=Object.freeze(Object.defineProperty({__proto__:null,AVAILABLE_TRACK_TYPES:qX,DATATYPE_TO_TRACK_TYPE:x7,DEFAULT_CONTAINER_PADDING_X:cZe,DEFAULT_CONTAINER_PADDING_Y:uZe,DEFAULT_SERVER:b3,DEFAULT_TRACKS_FOR_DATATYPE:dB,DEFAULT_VIEW_MARGIN:SZ,DEFAULT_VIEW_PADDING:wZ,GLOBALS:rt,HEATED_OBJECT_MAP:Gb,LOCATION_LISTENER_PREFIX:RZ,LONG_DRAG_TIMEOUT:VZ,MAX_CLICK_DELAY:dZe,MIN_HORIZONTAL_HEIGHT:bZe,MIN_VERTICAL_WIDTH:yZe,MOUSE_TOOL_MOVE:QX,MOUSE_TOOL_SELECT:Dr,NUM_PRECOMP_SUBSETS_PER_1D_TTILE:BZe,NUM_PRECOMP_SUBSETS_PER_2D_TTILE:F7,POSITIONS_BY_DATATYPE:yat,SHORT_DRAG_TIMEOUT:hZe,THEME_DARK:qg,THEME_DEFAULT:zAt,THEME_LIGHT:$X,TILE_FETCH_DEBOUNCE:p3,TRACKS_INFO:qd,TRACKS_INFO_BY_TYPE:Lg,TRACK_LOCATIONS:y3,VIEW_HEADER_MED_WIDTH_SEARCH_BAR:fZe,VIEW_HEADER_MIN_WIDTH_SEARCH_BAR:pZe,ZOOM_DEBOUNCE:jX,ZOOM_TRANSITION_DURATION:mZe},Symbol.toStringTag,{value:"Module"})),Kt=e=>{const g=wi(e);return rt.PIXI.utils.rgb2hex([g.r/255,g.g/255,g.b/255])},SZe=e=>{if(e==="transparent")return[255,255,255,0];const g=wi(e);return[g.r,g.g,g.b,255]},e9=(e,g,I)=>{const i=Vi(e,I),n=Vi(g,I);if(!i||!n)throw new Error("Couldn't convert data to genomic coordinates");return[i[0],Math.round(i[1]),n[0],Math.round(n[1])]},E7=(e,g,I)=>{let i;const n=(...C)=>{const r=()=>{i=void 0,I||e(...C)},o=I&&!i;clearTimeout(i),i=setTimeout(r,g),o&&e(...C)};return n.cancel=()=>{clearTimeout(i),i=void 0},n},Z3=e=>(e+16**6).toString(16).substr(-6),wZe=e=>{const g={};return e.forEach(I=>{g[I[0]]=I[1]}),g},Rr=e=>{const g=[];for(const I in e)e.hasOwnProperty(I)&&g.push([I,e[I]]);return g};function Br(e){const g=[];for(const I in e)e.hasOwnProperty(I)&&g.push(I);return g}function xg(e){const g=[];for(const I in e)e.hasOwnProperty(I)&&g.push(e[I]);return g}function RG(e,g){const I=typeof g=="string"?new Blob([g],{type:"application/octet-stream"}):g,i=window.document.createElement("a");i.href=window.URL.createObjectURL(I),i.download=e,document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(i.href)}const VZe=e=>{const g=["top","bottom","gallery"],I=["left","right","gallery"];return e.center=e.center||[],e.left=e.left||[],e.right=e.right||[],e.top=e.top||[],e.bottom=e.bottom||[],e.whole=e.whole||[],e.gallery=e.gallery||[],g.map(i=>e[i]).forEach(i=>i.forEach(n=>{const C=Lg[n.type],r=C&&C.defaultOptions||{},o=n.options?{...r,...n.options}:r;o.minHeight!==void 0&&n.height===void 0&&(n.height=o.minHeight),n.height===void 0&&(n.height=C&&C.defaultHeight||bZe)})),I.map(i=>e[i]).forEach(i=>i.forEach(n=>{const C=Lg[n.type],r=C&&C.defaultOptions||{},o=n.options?{...r,...n.options}:r;o.minWidth!==void 0&&n.width===void 0&&(n.width=o.minWidth),n.width===void 0&&(n.width=C&&C.defaultWidth||yZe)})),e},RZe=e=>g=>Array.prototype.reduce.call(g,e),Gat=RZe((e,g)=>e.concat(g)),vat=e=>g=>Array.prototype.forEach.call(g,e),t9=(e,g)=>{g.dispatchEvent(lZe(e))},Bat=(e,g)=>[UX(e[0],e[1],g),UX(e[2],e[3],g)];function Sat(e,g,I,i,n){const{chr:C,pos:r}=g,{chr:o,pos:A}=I,s=[];if(C===o){const a=C,l=Math.floor(r/i),c=Math.min(l+n,Math.ceil(A/i));s.push([a,l,c])}else{let a=n;const l=e.findIndex(([u])=>u===C),c=e.findIndex(([u])=>u===o);for(let u=l;u<=c;u++){let d,h;const[m,f]=e[u];u{if(I.length===0)return;if(I.length===1)return I[0];let i=I[0];const n=dB[e]!==void 0?dB[e][g]:void 0;return n!==void 0&&(i=I.find(C=>C.type===n)||i),i};var $ge={},X5={},H5=34,zy=10,T5=13;function WZe(e){return new Function("d","return {"+e.map(function(g,I){return JSON.stringify(g)+": d["+I+'] || ""'}).join(",")+"}")}function wat(e,g){var I=WZe(e);return function(i,n){return g(I(i),n,e)}}function qge(e){var g=Object.create(null),I=[];return e.forEach(function(i){for(var n in i)n in g||I.push(g[n]=n)}),I}function bC(e,g){var I=e+"",i=I.length;return i9999?"+"+bC(e,6):bC(e,4)}function Rat(e){var g=e.getUTCHours(),I=e.getUTCMinutes(),i=e.getUTCSeconds(),n=e.getUTCMilliseconds();return isNaN(e)?"Invalid Date":Vat(e.getUTCFullYear())+"-"+bC(e.getUTCMonth()+1,2)+"-"+bC(e.getUTCDate(),2)+(n?"T"+bC(g,2)+":"+bC(I,2)+":"+bC(i,2)+"."+bC(n,3)+"Z":i?"T"+bC(g,2)+":"+bC(I,2)+":"+bC(i,2)+"Z":I||g?"T"+bC(g,2)+":"+bC(I,2)+"Z":"")}function z7(e){var g=new RegExp('["'+e+` +\r]`),I=e.charCodeAt(0);function i(l,c){var u,d,h=n(l,function(m,f){if(u)return u(m,f-1);d=m,u=c?wat(m,c):WZe(m)});return h.columns=d||[],h}function n(l,c){var u=[],d=l.length,h=0,m=0,f,b=d<=0,p=!1;l.charCodeAt(d-1)===zy&&--d,l.charCodeAt(d-1)===T5&&--d;function y(){if(b)return X5;if(p)return p=!1,$ge;var B,G=h,v;if(l.charCodeAt(G)===H5){for(;h++=d?b=!0:(v=l.charCodeAt(h++))===zy?p=!0:v===T5&&(p=!0,l.charCodeAt(h)===zy&&++h),l.slice(G+1,B-1).replace(/""/g,'"')}for(;hO9[g]?Promise.resolve(O9[g]):e(g),dAt=g=>{if(g.length===0)return null;const e=GQ(g);return $N(e)},hAt=g=>fetch(g,{credentials:"same-origin"}).then(e=>e.text()).then(e=>dAt(e)).catch(e=>{console.error("Could not retrieve or parse chrom info.",e)}),mAt=(g,e,I)=>e(g,I).then(i=>(O9[g]=i,O9[g])),fAt=g=>mAt(g,uAt,hAt),BQ={get:fAt};function pAt(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function DIe(g,e){for(var I=0;Ithis.pubSub.publish(I,i)}},{key:"unregister",value:function(I,i){!this.registeredEls[I]&&this.registeredEls[I]!==i||(this.registeredEls[I].removeEventListener(I,this.registeredEls[I].__handler__),this.registeredEls[I]=void 0,delete this.registeredEls[I])}},{key:"register",value:function(I,i,n=!1){!i||this.registeredEls[I]===i||(this.registeredEls[I]&&this.unregister(this.registeredEls[I]),this.registeredEls[I]=i,this.registeredEls[I].__handler__=this.getEventHandler(I),this.registeredEls[I].addEventListener(I,this.registeredEls[I].__handler__,{capture:n,passive:!1}))}}]),g}();const EGe=g=>new GAt(g);let FIe=!1;const BAt=()=>{if(FIe)return;const[g,e]=LGe(),I="102117110099116105111110040041123115101108102046099111110115111108101046108111103040039",i="072",n="105",C="071",r="108097115115",o="032118",A="058032104116116112058047047104105103108097115115046105111039041125",s=[String.fromCharCode(...I.match(/.{1,3}/g).map(G=>+G)).toLowerCase(),String.fromCharCode(...i.match(/.{1,3}/g).map(G=>+G)),String.fromCharCode(...n.match(/.{1,3}/g).map(G=>+G)).toLowerCase(),String.fromCharCode(...C.match(/.{1,3}/g).map(G=>+G)),String.fromCharCode(...r.match(/.{1,3}/g).map(G=>+G)).toLowerCase(),String.fromCharCode(...o.match(/.{1,3}/g).map(G=>+G)).toLowerCase(),String.fromCharCode(...e.match(/.{1,3}/g).map(G=>+G)).toLowerCase(),String.fromCharCode(...A.match(/.{1,3}/g).map(G=>+G)).toLowerCase()].join(""),a="085082076",l="066076079066",c="087111114107101114",u="099114101097116101079098106101099116085082076",d="114101118111107101079098106101099116085082076",h=G=>G.charAt(0).toUpperCase()+G.slice(1),m=G=>G.slice(0,6)+G.charAt(6).toUpperCase()+G.slice(7,12)+G.slice(12).toUpperCase(),f=g[String.fromCharCode(...a.match(/.{1,3}/g).map(G=>+G))],b=g[h(String.fromCharCode(...l.match(/.{1,3}/g).map(G=>+G)).toLowerCase())],p=g[h(String.fromCharCode(...c.match(/.{1,3}/g).map(G=>+G)).toLowerCase())],y=m(String.fromCharCode(...u.match(/.{1,3}/g).map(G=>+G)).toLowerCase()),Z=m(String.fromCharCode(...d.match(/.{1,3}/g).map(G=>+G)).toLowerCase()),v=f[y](new b([`(${s})()`],{type:"application/javascript"}));new p(v),f[Z](v),FIe=!0},MGe={listen:BAt};function vAt(g,e,I,i,n,C,r){let o,A;if(n){const h=TQ(n);o=h,A=(m,f)=>h(f.map(b=>g[b*e[1]+m]))??0}let s,a,l,c,u,d;for(l=0;l{const w=l(B);return Number.isNaN(w)?254:Math.max(0,Math.min(254,Math.floor(w)))},v=(B,w)=>{b=255,!(r&&Math.floor(B/p)B%p)&&!Number.isNaN(+w)&&(b=Z(w+n)),(b<0||b>255)&&console.warn("out of bounds rgbIdx:",b," (should be 0 <= rgbIdx <= 255)"),s&&!Number.isNaN(+w)&&+w==0?f=s:f=C[b],y[B*4]=f[0],y[B*4+1]=f[1],y[B*4+2]=f[2],y[B*4+3]=f[3]};let G;try{if(c&&A)vAt(e,A,v,c,u,d,h);else for(let B=0;B+A).filter(A=>!Number.isNaN(A));if(i[C].tilePos=o,i[C].tilesetUid=r[0],"dense"in i[C]){const A=i[C].dense,s=VAt(A);let a;if(i[C].dtype==="float16"){const c=new Uint16Array(s);a=RAt(c)}else a=new Float32Array(s);const l=o.length===2?new HQ(a):new Q9(a);i[C].dense=a,i[C].denseDataExtrema=l,i[C].minNonZero=l.minNonZeroInTile,i[C].maxNonZero=l.maxNonZeroInTile}}return i}function WAt(g,e,I,i,n,C){const r={"content-type":"application/json"};i&&(r.Authorization=i),fetch(g,{credentials:"same-origin",headers:r,...C&&Object.keys(C).length>0?{method:"POST",body:JSON.stringify(C)}:{}}).then(o=>o.json()).then(o=>{n(vQ(o,e,I))}).catch(o=>console.warn("err:",o))}const EIe=15,L9=dg.nice();let Mv=0,Jb=null;const XAt=(g,e,I)=>{let i,n=[],C={},r=0;const o=u=>{const d=C[u.id];d&&n[d]?n[d].ids=n[d].ids.concat(u.ids):(C[u.id]=n.length,n.push(u))},A=()=>{i=null,n=[],C={}},s=(u,...d)=>{g({sessionId:L9,requests:n},...d),A()},a=(u,...d)=>{const h=()=>{r>0&&(s(u,...d),r=0)};clearTimeout(i),i=setTimeout(h,I)};a.cancel=()=>{clearTimeout(i),A()},a.immediate=()=>{g({sessionId:L9,requests:n})};let l=!1;return(u,...d)=>{o(u),l?r++:(s(u,...d),a(u,...d),l=!0,r=0,setTimeout(()=>{l=!1},e))}},zv=g=>{Jb=g},HAt=()=>Jb;function TAt(g,e){const I=g.requests,i=[],n={},C={};for(const o of I){n[o.server]||(n[o.server]={},C[o.server]=[]);for(const A of o.ids)if(n[o.server][A]=!0,o.options){const s=A.indexOf("."),a=A.substring(0,s),l=A.substring(s+1),c=C[o.server].find(u=>u.tilesetUid===a);c?c.tileIds.push(l):C[o.server].push({tilesetUid:a,tileIds:[l],options:o.options})}}const r=Object.keys(n);for(const o of r){const A=Object.keys(n[o]),s=C[o];for(let a=0;a`d=${h}`).join("&"),u=`${o}/tiles/?${c}&s=${L9}`,d=new Promise((h,m)=>{e.publish("requestSent",u);const f={};f.outUrl=u,f.server=o,f.theseTileIds=l,f.authHeader=Jb,WAt(f.outUrl,f.server,f.theseTileIds,f.authHeader,h,s),e.publish("requestReceived",u)});i.push(d)}}Promise.all(i).then(o=>{const A={};for(const s of o){const a=Object.keys(s);for(const l of a)A[`${s[l].server}/${l}`]=s[l]}for(const s of I){const a={},{server:l}=s;for(const c of s.ids)a[c]=A[`${l}/${c}`];s.done(a)}})}const NAt=XAt(TAt,ez,ez),kAt=(g,e)=>{const I=g.map(o=>+o).sort((o,A)=>A-o),i=e.range()[1]-e.range()[0],C=I.map(o=>(e.domain()[1]-e.domain()[0])/o).map(o=>o/i),r=C.filter(o=>o<1);return r.length===0?0:C.indexOf(r[r.length-1])},YAt=(g,e)=>{if(g.resolutions)return g.resolutions.map(o=>+o).sort((o,A)=>A-o)[e];const I=g.max_width,i=+g.bins_per_dimension;return I/(2**e*i)},KAt=(g,e,I,i)=>{const n=g.range()[1]-g.range()[0],C=Math.max((I-e)/(g.domain()[1]-g.domain()[0]),1),o=Math.max(0,Math.ceil(Math.log(n/384)/Math.LN2));let A=Math.round(Math.log(C)/Math.LN2)+o,s=0;return i&&(s=Math.floor(Math.log(256)/Math.log(2)-Math.log(i)/Math.log(2))),A+=s,A};function xAt(g,e,I,i,n){let C=null;const r=g.bins_per_dimension||256;g.resolutions?C=g.resolutions[i]*r:C=e/2**i;const o=Math.floor((n-I)/C),A=Math.floor(r*(n-o*C)/C);return[o,A]}const DAt=(g,e,I,i,n,C)=>{const r=Math.min(g,n),o=C/2**r,A=1e-7;return iC(Math.max(0,Math.floor((e.domain()[0]-I)/o)),Math.min(2**r,Math.ceil((e.domain()[1]-I-A)/o)))},FAt=(g,e,I)=>g.resolutions?g.resolutions.map(n=>+n).sort((n,C)=>C-n)[e]*I:g.max_width/2**e,EAt=(g,e,I,i,n)=>{const o=g*(n||256),A=20;i||(i=Number.MAX_VALUE);const s=Math.max(0,Math.floor((e.domain()[0]-I)/o)),a=Math.ceil(Math.min(i,e.domain()[1]-I-1e-7)/o);let l=iC(s,a);return l.length>A&&(console.warn(`Too many visible tiles: ${l.length} truncating to ${A}`),l=l.slice(0,A)),l},MAt=(g,e,I,i,n,C,r,o,A,s)=>{const{tileData:a}=g;if(!a.dense){C(null);return}if(g.mirrored&&!g.isMirrored&&g.tileData.tilePos.length>0&&g.tileData.tilePos[0]===g.tileData.tilePos[1]){g.tileData.dense=g.tileData.dense.slice();const c=Math.floor(Math.sqrt(g.tileData.dense.length));for(let u=0;u{if(!r.ok)throw Error(r.statusText);return r[I]()}).then(r=>(e(void 0,r),r)).catch(r=>(console.error(`Could not fetch ${g}`,r),e(r,void 0),r)).finally(()=>{i.publish("requestReceived",g),Mv-=1})}function zAt(g,e,I){return zGe(g,e,"text",I)}async function PGe(g,e,I){return g.indexOf("hg19")>=0&&await WQ(1),zGe(g,e,"json",I)}const PAt=(g,e,I,i,n)=>{const C=`${qN(g)}/tileset_info/?d=${e}&s=${L9}`;n.publish("requestSent",C),PGe(C,(r,o)=>{n.publish("requestReceived",C),r?i?i(`Error retrieving tilesetInfo from: ${g}`):console.warn("Error retrieving: ",C):I(o)},n)},vt={calculateResolution:YAt,calculateTileAndPosInTile:xAt,calculateTiles:DAt,calculateTilesFromResolution:EAt,calculateTileWidth:FAt,calculateZoomLevel:KAt,calculateZoomLevelFromResolutions:kAt,fetchTilesDebounced:NAt,json:PGe,text:zAt,tileDataToPixData:MAt,trackInfo:PAt},JAt=Object.freeze(Object.defineProperty({__proto__:null,ElementResizeListener:MGe,get authHeader(){return Jb},chromInfo:BQ,createDomEvent:EGe,getTileProxyAuthHeader:HAt,get requestsInFlight(){return Mv},setTileProxyAuthHeader:zv,tileProxy:vt,tileResponseToData:vQ},Symbol.toStringTag,{value:"Module"})),JGe=g=>(MGe.listen(),[g.clientWidth,g.clientHeight]),gr=(g,e)=>{let I=null;const i=n=>(n.uid===e&&(I=n),n.type.substr(0,8)==="combined"&&n.contents.forEach(i),null);return Object.keys(g).map(n=>g[n]).filter(n=>n.filter).reduce((n,C)=>n.concat(C),[]).forEach(i),I},OAt=(g,e,I)=>{const n=g.state.views[e];if(!n)return null;let C=null;const r=A=>(A.uid===I&&(C=A),A.type.substr(0,8)==="combined"&&A.contents.forEach(r),null),o=n.tracks;return Object.keys(o).map(A=>o[A]).filter(A=>A.filter).reduce((A,s)=>A.concat(s),[]).forEach(r),C},gG=(g,e,I)=>{const i=e?g[e]:Object.values(g)[0];if(!i){console.warn(e?`Could't find view with id "${e}"`:"No views available.");return}let n=i.trackRenderer.trackDefObjects[I];return n?n=n.trackObject:Object.values(i.trackRenderer.trackDefObjects).map(C=>C.trackObject).filter(C=>C.childTracks).forEach(C=>{C.createdTracks[I]&&(n=C.createdTracks[I])}),n};function nW(g){return g.type==="combined"}function LAt(g){return"deltaY"in g&&"deltaMode"in g}function OGe(g){return g!==null&&typeof g=="object"}function _At(g){return OGe(g)&&"max_width"in g}function UAt(g){return OGe(g)&&"resolutions"in g}const SQ=(g,e,I=!0,i=null)=>g.forEach(n=>{I&&nW(n)&&SQ(n.contents,e,I,i),e(n,i)}),os=(g,e,I=!0)=>{const i=[];for(const[n,C]of Object.entries(g))SQ(C,e,I,n),i.push(...C);return i},gB=(g,e)=>{let I=null;return os(g,(i,n)=>{i.uid===e&&(I=n)}),I},wQ=g=>e=>Array.prototype.map.call(e,g),LGe=()=>[window,wQ(g=>g.charCodeAt(0))("1.13.3").map(g=>g<=999?`00${g}`.slice(-3):g).join("")],_Ge=(g,e=1,I=100,i=0,n=0,C=0,r=100)=>{const o=document.createElement("canvas");o.width=e,o.height=I;const A=o.getContext("2d");if(!A)throw new Error("Could not get canvas context");const s=A.createLinearGradient(i,n,C,r);return g.forEach(a=>{s.addColorStop(a.from,a.color)}),A.fillStyle=s,A.fillRect(0,0,e,I),o},UGe=(g,e)=>{let I=g;for(;I&&I!==e&&I.tagName!=="HTML";)I=I.parentNode;return I===e},QGe=g=>parseInt(g.replace(/^#/,""),16),jGe=()=>{};function QAt(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function MIe(g,e){for(var I=0;I{this.createdTracks[I[C].uid]=n});for(let n=0;n{if(C.add(A.uid),A.uid in this.createdTracks)n.push(this.createdTracks[A.uid]);else{const s=i(A);s.setPosition(this.position),s.setDimensions(this.dimensions),n.push(s),s.zoomed(this._xScale,this._yScale),this.createdTracks[A.uid]=s}}),this.childTracks=n;const r=new Set(Object.keys(this.createdTracks));return[...new Set([...r].filter(A=>!C.has(A)))].forEach(A=>{this.createdTracks[A].remove(),delete this.createdTracks[A]}),this}},{key:"setPosition",value:function(I){this.position=I;for(let i=0;in.minValue).map(n=>n.minValue()).filter(n=>n);return Math.min(...i)}for(const i of this.childTracks)i.minValue&&i.minValue(I)}},{key:"maxValue",value:function(I){if(arguments.length===0){const i=this.childTracks.filter(n=>n.maxValue).map(n=>n.maxValue()).filter(n=>n);return Math.max(...i)}for(const i of this.childTracks)i.maxValue&&i.maxValue(I)}},{key:"respondsToPosition",value:function(I,i){return I>=this.position[0]&&I<=this.dimensions[0]+this.position[0]&&i>=this.position[1]&&i<=this.dimensions[1]+this.position[1]}},{key:"stopHover",value:function(){for(const I of this.childTracks)I.stopHover&&I.stopHover()}},{key:"getMouseOverHtml",value:function(I,i){let n="";for(const C of this.childTracks)if(C.getMouseOverHtml){const r=C.getMouseOverHtml(I,i);r&&r.length&&(n+=r,n+="
")}return n}}]),g}();const $Ge=(g,e)=>e===g?!0:e instanceof VQ?Object.keys(e.createdTracks).map(I=>e.createdTracks[I]).some(I=>$Ge(g,I)):!1,RQ=(g,e,I,i,n,C,r=!1)=>r?g>=I&&g<=i||e>=n&&e<=C:g>=I&&g<=i&&e>=n&&e<=C,eat=g=>Math.log(Math.tan((g+Math.PI/2)/2)),tat=(g,e)=>{let I=g*Math.PI/180;return I=eat(I),2**e*(Math.PI-I)/(2*Math.PI)},jN=g=>wQ(e=>g[e])(Object.keys(g)),gat=g=>jN(g).map(e=>e.chromInfoPath).forEach(e=>BQ.get(e)),Iat=(g,e)=>2**e*(g+180)/360,iz=(g,e)=>g>e?g:e,zIe=1e-7;function nz(g){let e=Number.MIN_SAFE_INTEGER;for(let I=0;I-zIe||i>e&&(e=i)}return e}const qGe=(g,e)=>g-PIe||i(g%e+e)%e,eBe=(g,e)=>{const I=+e;if(!Number.isNaN(I))if(g.dimension===1)for(let n=0;ng9[e]?Promise.resolve(g9[e]):g(e),_at=e=>{if(e.length===0)return null;const g=P7(e);return CN(g)},Lat=e=>fetch(e,{credentials:"same-origin"}).then(g=>g.text()).then(g=>_at(g)).catch(g=>{console.error("Could not retrieve or parse chrom info.",g)}),Uat=(e,g,I)=>g(e,I).then(i=>(g9[e]=i,g9[e])),Qat=e=>Uat(e,Oat,Lat),J7={get:Qat};function jat(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function eIe(e,g){for(var I=0;Ithis.pubSub.publish(I,i)}},{key:"unregister",value:function(I,i){!this.registeredEls[I]&&this.registeredEls[I]!==i||(this.registeredEls[I].removeEventListener(I,this.registeredEls[I].__handler__),this.registeredEls[I]=void 0,delete this.registeredEls[I])}},{key:"register",value:function(I,i,n=!1){!i||this.registeredEls[I]===i||(this.registeredEls[I]&&this.unregister(this.registeredEls[I]),this.registeredEls[I]=i,this.registeredEls[I].__handler__=this.getEventHandler(I),this.registeredEls[I].addEventListener(I,this.registeredEls[I].__handler__,{capture:n,passive:!1}))}}]),e}();const XZe=e=>new tst(e);let tIe=!1;const gst=()=>{if(tIe)return;const[e,g]=KZe(),I="102117110099116105111110040041123115101108102046099111110115111108101046108111103040039",i="072",n="105",C="071",r="108097115115",o="032118",A="058032104116116112058047047104105103108097115115046105111039041125",s=[String.fromCharCode(...I.match(/.{1,3}/g).map(G=>+G)).toLowerCase(),String.fromCharCode(...i.match(/.{1,3}/g).map(G=>+G)),String.fromCharCode(...n.match(/.{1,3}/g).map(G=>+G)).toLowerCase(),String.fromCharCode(...C.match(/.{1,3}/g).map(G=>+G)),String.fromCharCode(...r.match(/.{1,3}/g).map(G=>+G)).toLowerCase(),String.fromCharCode(...o.match(/.{1,3}/g).map(G=>+G)).toLowerCase(),String.fromCharCode(...g.match(/.{1,3}/g).map(G=>+G)).toLowerCase(),String.fromCharCode(...A.match(/.{1,3}/g).map(G=>+G)).toLowerCase()].join(""),a="085082076",l="066076079066",c="087111114107101114",u="099114101097116101079098106101099116085082076",d="114101118111107101079098106101099116085082076",h=G=>G.charAt(0).toUpperCase()+G.slice(1),m=G=>G.slice(0,6)+G.charAt(6).toUpperCase()+G.slice(7,12)+G.slice(12).toUpperCase(),f=e[String.fromCharCode(...a.match(/.{1,3}/g).map(G=>+G))],b=e[h(String.fromCharCode(...l.match(/.{1,3}/g).map(G=>+G)).toLowerCase())],p=e[h(String.fromCharCode(...c.match(/.{1,3}/g).map(G=>+G)).toLowerCase())],y=m(String.fromCharCode(...u.match(/.{1,3}/g).map(G=>+G)).toLowerCase()),Z=m(String.fromCharCode(...d.match(/.{1,3}/g).map(G=>+G)).toLowerCase()),B=f[y](new b([`(${s})()`],{type:"application/javascript"}));new p(B),f[Z](B),tIe=!0},HZe={listen:gst};function Ist(e,g,I,i,n,C,r){let o,A;if(n){const h=eQ(n);o=h,A=(m,f)=>h(f.map(b=>e[b*g[1]+m]))??0}let s,a,l,c,u,d;for(l=0;l{const w=l(v);return Number.isNaN(w)?254:Math.max(0,Math.min(254,Math.floor(w)))},B=(v,w)=>{b=255,!(r&&Math.floor(v/p)v%p)&&!Number.isNaN(+w)&&(b=Z(w+n)),(b<0||b>255)&&console.warn("out of bounds rgbIdx:",b," (should be 0 <= rgbIdx <= 255)"),s&&!Number.isNaN(+w)&&+w==0?f=s:f=C[b],y[v*4]=f[0],y[v*4+1]=f[1],y[v*4+2]=f[2],y[v*4+3]=f[3]};let G;try{if(c&&A)Ist(g,A,B,c,u,d,h);else for(let v=0;v+A).filter(A=>!Number.isNaN(A));if(i[C].tilePos=o,i[C].tilesetUid=r[0],"dense"in i[C]){const A=i[C].dense,s=Cst(A);let a;if(i[C].dtype==="float16"){const c=new Uint16Array(s);a=rst(c)}else a=new Float32Array(s);const l=o.length===2?new q7(a):new C9(a);i[C].dense=a,i[C].denseDataExtrema=l,i[C].minNonZero=l.minNonZeroInTile,i[C].maxNonZero=l.maxNonZeroInTile}}return i}function ost(e,g,I,i,n,C){const r={"content-type":"application/json"};i&&(r.Authorization=i),fetch(e,{credentials:"same-origin",headers:r,...C&&Object.keys(C).length>0?{method:"POST",body:JSON.stringify(C)}:{}}).then(o=>o.json()).then(o=>{n(O7(o,g,I))}).catch(o=>console.warn("err:",o))}const gIe=15,I9=Ag.nice();let hB=0,vb=null;const Ast=(e,g,I)=>{let i,n=[],C={},r=0;const o=u=>{const d=C[u.id];d&&n[d]?n[d].ids=n[d].ids.concat(u.ids):(C[u.id]=n.length,n.push(u))},A=()=>{i=null,n=[],C={}},s=(u,...d)=>{e({sessionId:I9,requests:n},...d),A()},a=(u,...d)=>{const h=()=>{r>0&&(s(u,...d),r=0)};clearTimeout(i),i=setTimeout(h,I)};a.cancel=()=>{clearTimeout(i),A()},a.immediate=()=>{e({sessionId:I9,requests:n})};let l=!1;return(u,...d)=>{o(u),l?r++:(s(u,...d),a(u,...d),l=!0,r=0,setTimeout(()=>{l=!1},g))}},mB=e=>{vb=e},ast=()=>vb;function sst(e,g){const I=e.requests,i=[],n={},C={};for(const o of I){n[o.server]||(n[o.server]={},C[o.server]=[]);for(const A of o.ids)if(n[o.server][A]=!0,o.options){const s=A.indexOf("."),a=A.substring(0,s),l=A.substring(s+1),c=C[o.server].find(u=>u.tilesetUid===a);c?c.tileIds.push(l):C[o.server].push({tilesetUid:a,tileIds:[l],options:o.options})}}const r=Object.keys(n);for(const o of r){const A=Object.keys(n[o]),s=C[o];for(let a=0;a`d=${h}`).join("&"),u=`${o}/tiles/?${c}&s=${I9}`,d=new Promise((h,m)=>{g.publish("requestSent",u);const f={};f.outUrl=u,f.server=o,f.theseTileIds=l,f.authHeader=vb,ost(f.outUrl,f.server,f.theseTileIds,f.authHeader,h,s),g.publish("requestReceived",u)});i.push(d)}}Promise.all(i).then(o=>{const A={};for(const s of o){const a=Object.keys(s);for(const l of a)A[`${s[l].server}/${l}`]=s[l]}for(const s of I){const a={},{server:l}=s;for(const c of s.ids)a[c]=A[`${l}/${c}`];s.done(a)}})}const lst=Ast(sst,p3,p3),cst=(e,g)=>{const I=e.map(o=>+o).sort((o,A)=>A-o),i=g.range()[1]-g.range()[0],C=I.map(o=>(g.domain()[1]-g.domain()[0])/o).map(o=>o/i),r=C.filter(o=>o<1);return r.length===0?0:C.indexOf(r[r.length-1])},ust=(e,g)=>{if(e.resolutions)return e.resolutions.map(o=>+o).sort((o,A)=>A-o)[g];const I=e.max_width,i=+e.bins_per_dimension;return I/(2**g*i)},dst=(e,g,I,i)=>{const n=e.range()[1]-e.range()[0],C=Math.max((I-g)/(e.domain()[1]-e.domain()[0]),1),o=Math.max(0,Math.ceil(Math.log(n/384)/Math.LN2));let A=Math.round(Math.log(C)/Math.LN2)+o,s=0;return i&&(s=Math.floor(Math.log(256)/Math.log(2)-Math.log(i)/Math.log(2))),A+=s,A};function hst(e,g,I,i,n){let C=null;const r=e.bins_per_dimension||256;e.resolutions?C=e.resolutions[i]*r:C=g/2**i;const o=Math.floor((n-I)/C),A=Math.floor(r*(n-o*C)/C);return[o,A]}const mst=(e,g,I,i,n,C)=>{const r=Math.min(e,n),o=C/2**r,A=1e-7;return eC(Math.max(0,Math.floor((g.domain()[0]-I)/o)),Math.min(2**r,Math.ceil((g.domain()[1]-I-A)/o)))},fst=(e,g,I)=>e.resolutions?e.resolutions.map(n=>+n).sort((n,C)=>C-n)[g]*I:e.max_width/2**g,pst=(e,g,I,i,n)=>{const o=e*(n||256),A=20;i||(i=Number.MAX_VALUE);const s=Math.max(0,Math.floor((g.domain()[0]-I)/o)),a=Math.ceil(Math.min(i,g.domain()[1]-I-1e-7)/o);let l=eC(s,a);return l.length>A&&(console.warn(`Too many visible tiles: ${l.length} truncating to ${A}`),l=l.slice(0,A)),l},bst=(e,g,I,i,n,C,r,o,A,s)=>{const{tileData:a}=e;if(!a.dense){C(null);return}if(e.mirrored&&!e.isMirrored&&e.tileData.tilePos.length>0&&e.tileData.tilePos[0]===e.tileData.tilePos[1]){e.tileData.dense=e.tileData.dense.slice();const c=Math.floor(Math.sqrt(e.tileData.dense.length));for(let u=0;u{if(!r.ok)throw Error(r.statusText);return r[I]()}).then(r=>(g(void 0,r),r)).catch(r=>(console.error(`Could not fetch ${e}`,r),g(r,void 0),r)).finally(()=>{i.publish("requestReceived",e),hB-=1})}function yst(e,g,I){return TZe(e,g,"text",I)}async function NZe(e,g,I){return e.indexOf("hg19")>=0&&await j7(1),TZe(e,g,"json",I)}const Zst=(e,g,I,i,n)=>{const C=`${rN(e)}/tileset_info/?d=${g}&s=${I9}`;n.publish("requestSent",C),NZe(C,(r,o)=>{n.publish("requestReceived",C),r?i?i(`Error retrieving tilesetInfo from: ${e}`):console.warn("Error retrieving: ",C):I(o)},n)},Gt={calculateResolution:ust,calculateTileAndPosInTile:hst,calculateTiles:mst,calculateTilesFromResolution:pst,calculateTileWidth:fst,calculateZoomLevel:dst,calculateZoomLevelFromResolutions:cst,fetchTilesDebounced:lst,json:NZe,text:yst,tileDataToPixData:bst,trackInfo:Zst},Gst=Object.freeze(Object.defineProperty({__proto__:null,ElementResizeListener:HZe,get authHeader(){return vb},chromInfo:J7,createDomEvent:XZe,getTileProxyAuthHeader:ast,get requestsInFlight(){return hB},setTileProxyAuthHeader:mB,tileProxy:Gt,tileResponseToData:O7},Symbol.toStringTag,{value:"Module"})),kZe=e=>(HZe.listen(),[e.clientWidth,e.clientHeight]),jC=(e,g)=>{let I=null;const i=n=>(n.uid===g&&(I=n),n.type.substr(0,8)==="combined"&&n.contents.forEach(i),null);return Object.keys(e).map(n=>e[n]).filter(n=>n.filter).reduce((n,C)=>n.concat(C),[]).forEach(i),I},vst=(e,g,I)=>{const n=e.state.views[g];if(!n)return null;let C=null;const r=A=>(A.uid===I&&(C=A),A.type.substr(0,8)==="combined"&&A.contents.forEach(r),null),o=n.tracks;return Object.keys(o).map(A=>o[A]).filter(A=>A.filter).reduce((A,s)=>A.concat(s),[]).forEach(r),C},WZ=(e,g,I)=>{const i=g?e[g]:Object.values(e)[0];if(!i){console.warn(g?`Could't find view with id "${g}"`:"No views available.");return}let n=i.trackRenderer.trackDefObjects[I];return n?n=n.trackObject:Object.values(i.trackRenderer.trackDefObjects).map(C=>C.trackObject).filter(C=>C.childTracks).forEach(C=>{C.createdTracks[I]&&(n=C.createdTracks[I])}),n};function v1(e){return e.type==="combined"}function Bst(e){return"deltaY"in e&&"deltaMode"in e}function YZe(e){return e!==null&&typeof e=="object"}function Sst(e){return YZe(e)&&"max_width"in e}function wst(e){return YZe(e)&&"resolutions"in e}const _7=(e,g,I=!0,i=null)=>e.forEach(n=>{I&&v1(n)&&_7(n.contents,g,I,i),g(n,i)}),Qa=(e,g,I=!0)=>{const i=[];for(const[n,C]of Object.entries(e))_7(C,g,I,n),i.push(...C);return i},WG=(e,g)=>{let I=null;return Qa(e,(i,n)=>{i.uid===g&&(I=n)}),I},L7=e=>g=>Array.prototype.map.call(g,e),KZe=()=>[window,L7(e=>e.charCodeAt(0))("1.13.3").map(e=>e<=999?`00${e}`.slice(-3):e).join("")],DZe=(e,g=1,I=100,i=0,n=0,C=0,r=100)=>{const o=document.createElement("canvas");o.width=g,o.height=I;const A=o.getContext("2d");if(!A)throw new Error("Could not get canvas context");const s=A.createLinearGradient(i,n,C,r);return e.forEach(a=>{s.addColorStop(a.from,a.color)}),A.fillStyle=s,A.fillRect(0,0,g,I),o},xZe=(e,g)=>{let I=e;for(;I&&I!==g&&I.tagName!=="HTML";)I=I.parentNode;return I===g},FZe=e=>parseInt(e.replace(/^#/,""),16),EZe=()=>{};function Vst(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function IIe(e,g){for(var I=0;I{this.createdTracks[I[C].uid]=n});for(let n=0;n{if(C.add(A.uid),A.uid in this.createdTracks)n.push(this.createdTracks[A.uid]);else{const s=i(A);s.setPosition(this.position),s.setDimensions(this.dimensions),n.push(s),s.zoomed(this._xScale,this._yScale),this.createdTracks[A.uid]=s}}),this.childTracks=n;const r=new Set(Object.keys(this.createdTracks));return[...new Set([...r].filter(A=>!C.has(A)))].forEach(A=>{this.createdTracks[A].remove(),delete this.createdTracks[A]}),this}},{key:"setPosition",value:function(I){this.position=I;for(let i=0;in.minValue).map(n=>n.minValue()).filter(n=>n);return Math.min(...i)}for(const i of this.childTracks)i.minValue&&i.minValue(I)}},{key:"maxValue",value:function(I){if(arguments.length===0){const i=this.childTracks.filter(n=>n.maxValue).map(n=>n.maxValue()).filter(n=>n);return Math.max(...i)}for(const i of this.childTracks)i.maxValue&&i.maxValue(I)}},{key:"respondsToPosition",value:function(I,i){return I>=this.position[0]&&I<=this.dimensions[0]+this.position[0]&&i>=this.position[1]&&i<=this.dimensions[1]+this.position[1]}},{key:"stopHover",value:function(){for(const I of this.childTracks)I.stopHover&&I.stopHover()}},{key:"getMouseOverHtml",value:function(I,i){let n="";for(const C of this.childTracks)if(C.getMouseOverHtml){const r=C.getMouseOverHtml(I,i);r&&r.length&&(n+=r,n+="
")}return n}}]),e}();const MZe=(e,g)=>g===e?!0:g instanceof U7?Object.keys(g.createdTracks).map(I=>g.createdTracks[I]).some(I=>MZe(e,I)):!1,Q7=(e,g,I,i,n,C,r=!1)=>r?e>=I&&e<=i||g>=n&&g<=C:e>=I&&e<=i&&g>=n&&g<=C,Hst=e=>Math.log(Math.tan((e+Math.PI/2)/2)),Tst=(e,g)=>{let I=e*Math.PI/180;return I=Hst(I),2**g*(Math.PI-I)/(2*Math.PI)},nN=e=>L7(g=>e[g])(Object.keys(e)),Nst=e=>nN(e).map(g=>g.chromInfoPath).forEach(g=>J7.get(g)),kst=(e,g)=>2**g*(e+180)/360,G3=(e,g)=>e>g?e:g,iIe=1e-7;function v3(e){let g=Number.MIN_SAFE_INTEGER;for(let I=0;I-iIe||i>g&&(g=i)}return g}const zZe=(e,g)=>e-nIe||i(e%g+g)%g,PZe=(e,g)=>{const I=+g;if(!Number.isNaN(I))if(e.dimension===1)for(let n=0;n * @license MIT - */var rat=function(g){return g!=null&&(tBe(g)||oat(g)||!!g._isBuffer)};function tBe(g){return!!g.constructor&&typeof g.constructor.isBuffer=="function"&&g.constructor.isBuffer(g)}function oat(g){return typeof g.readFloatLE=="function"&&typeof g.slice=="function"&&tBe(g.slice(0,0))}var Aat=Cat,aat=rat,sat=typeof Float64Array<"u";function lat(g,e){return g[0]-e[0]}function cat(){var g=this.stride,e=new Array(g.length),I;for(I=0;IMath.abs(this.stride[1]))?[1,0]:[0,1]}})"):e===3&&n.push("var s0=Math.abs(this.stride[0]),s1=Math.abs(this.stride[1]),s2=Math.abs(this.stride[2]);if(s0>s1){if(s1>s2){return [2,1,0];}else if(s0>s2){return [1,2,0];}else{return [1,0,2];}}else if(s0>s2){return [2,0,1];}else if(s2>s1){return [0,1,2];}else{return [0,2,1];}}})")):n.push("ORDER})")),n.push("proto.set=function "+I+"_set("+r.join(",")+",v){"),i?n.push("return this.data.set("+o+",v)}"):n.push("return this.data["+o+"]=v}"),n.push("proto.get=function "+I+"_get("+r.join(",")+"){"),i?n.push("return this.data.get("+o+")}"):n.push("return this.data["+o+"]}"),n.push("proto.index=function "+I+"_index(",r.join(),"){return "+o+"}"),n.push("proto.hi=function "+I+"_hi("+r.join(",")+"){return new "+I+"(this.data,"+C.map(function(m){return["(typeof i",m,"!=='number'||i",m,"<0)?this.shape[",m,"]:i",m,"|0"].join("")}).join(",")+","+C.map(function(m){return"this.stride["+m+"]"}).join(",")+",this.offset)}");var a=C.map(function(m){return"a"+m+"=this.shape["+m+"]"}),l=C.map(function(m){return"c"+m+"=this.stride["+m+"]"});n.push("proto.lo=function "+I+"_lo("+r.join(",")+"){var b=this.offset,d=0,"+a.join(",")+","+l.join(","));for(var c=0;c=0){d=i"+c+"|0;b+=c"+c+"*d;a"+c+"-=d}");n.push("return new "+I+"(this.data,"+C.map(function(m){return"a"+m}).join(",")+","+C.map(function(m){return"c"+m}).join(",")+",b)}"),n.push("proto.step=function "+I+"_step("+r.join(",")+"){var "+C.map(function(m){return"a"+m+"=this.shape["+m+"]"}).join(",")+","+C.map(function(m){return"b"+m+"=this.stride["+m+"]"}).join(",")+",c=this.offset,d=0,ceil=Math.ceil");for(var c=0;c=0){c=(c+this.stride["+c+"]*i"+c+")|0}else{a.push(this.shape["+c+"]);b.push(this.stride["+c+"])}");n.push("var ctor=CTOR_LIST[a.length+1];return ctor(this.data,a,b,c)}"),n.push("return function construct_"+I+"(data,shape,stride,offset){return new "+I+"(data,"+C.map(function(m){return"shape["+m+"]"}).join(",")+","+C.map(function(m){return"stride["+m+"]"}).join(",")+",offset)}");var h=new Function("CTOR_LIST","ORDER",n.join(` -`));return h(_9[g],cat)}function dat(g){if(aat(g))return"buffer";if(sat)switch(Object.prototype.toString.call(g)){case"[object Float64Array]":return"float64";case"[object Float32Array]":return"float32";case"[object Int8Array]":return"int8";case"[object Int16Array]":return"int16";case"[object Int32Array]":return"int32";case"[object Uint8Array]":return"uint8";case"[object Uint16Array]":return"uint16";case"[object Uint32Array]":return"uint32";case"[object Uint8ClampedArray]":return"uint8_clamped";case"[object BigInt64Array]":return"bigint64";case"[object BigUint64Array]":return"biguint64"}return Array.isArray(g)?"array":"generic"}var _9={float32:[],float64:[],int8:[],int16:[],int32:[],uint8:[],uint16:[],uint32:[],array:[],uint8_clamped:[],bigint64:[],biguint64:[],buffer:[],generic:[]};function hat(g,e,I,i){if(g===void 0){var s=_9.array[0];return s([])}else typeof g=="number"&&(g=[g]);e===void 0&&(e=[g.length]);var n=e.length;if(I===void 0){I=new Array(n);for(var C=n-1,r=1;C>=0;--C)I[C]=r,r*=e[C]}if(i===void 0){i=0;for(var C=0;C{const e=g.shape.reduce((i,n)=>i*n,1),I=new Array(e);if(g.dimension===1){let i=0;for(let n=0;ng.shape.length===1?g:Lp(gBe(g)),iBe=g=>{const e=g.split("."),I=e.slice(1).join("").length;return+e.join("")/10**I},ow=(g,e)=>g||e;function $N(g){const e=[],I={},i={};let n=0;for(let C=0;C{const e=document.createElement("g"),I=document.createElement("text");return g.anchor.x===0?I.setAttribute("text-anchor","start"):g.anchor.x===1?I.setAttribute("text-anchor","end"):I.setAttribute("text-anchor","middle"),I.setAttribute("font-family",g.style.fontFamily),I.setAttribute("font-size",g.style.fontSize),e.setAttribute("transform",`scale(${g.scale.x},1)`),I.setAttribute("fill",g.style.fill),I.innerHTML=g.text,e.appendChild(I),e.setAttribute("transform",`translate(${g.x},${g.y})scale(${g.scale.x},1)`),e},fat=g=>{try{const e=g.split(".");return I=>{let i=I;return e.forEach(n=>{i=i[n]}),i}}catch{return}},pat=(g,e,I,i,n,C,r=0,o=0,A)=>{const s=C?n:i,a=C?i:n,l=C?o:r,c=C?r:o,u=Math.max(0,+s[0]||0),d=Math.max(0,+s[1]||0),h=Math.max(0,+a[0]||0),m=Math.max(0,+a[1]||0);let f=[];ArrayBuffer.isView(A)||console.warn("Not supported yet");try{const b=new A.constructor(A.length);let p=0+c;for(let Z=h;Z[i.chrPositions[g].pos+ +e,i.chrPositions[g].pos+ +I],yat="http://www.w3.org/2000/svg",Zat=(g,e)=>{const I=new RegExp(`(\\s|^)${e}(\\s|$)`);if(g.namespaceURI===yat){const i=g.getAttribute("class")||"";g.setAttribute("class",i.replace(I," "))}else g.classList?g.classList.remove(e):x9(g,e)&&(g.className=g.className.replace(I," "))},_p=(g,e)=>{g.select(".selection").attr("fill",null).attr("fill-opacity",null).attr("stroke",null).classed(e,!0)},Bx=g=>{const e=g.toString(16);return e.length===1?`0${e}`:e},Gat=(g,e,I)=>`#${Bx(g)}${Bx(e)}${Bx(I)}`,Zi=(g,e)=>{const I=g.invert((g.range()[0]+g.range()[1])/2),i=e.invert((e.range()[0]+e.range()[1])/2),n=g.invert(1)-g.invert(0);return[I,i,n]},nBe=(g,e,I)=>{if(I===null||!g||!e)return;const i=g.domain()[0],n=g.domain()[1],C=e.domain()[0],r=e.domain()[1];return[...P9(i,n,I),...P9(C,r,I)]},Bat=11184810,vat=1,Sat=(g,e,I,i,n,C,r,o,A)=>{g.publish("app.animateOnMouseMove",!0);const s=I.mousePositionColor?QGe(I.mousePositionColor):Bat,a=I.mousePositionAlpha||vat,l=new Ct.PIXI.Graphics,c=()=>{l.clear()},u=(h,m,f)=>{if(f||c(),l.lineStyle(1,s,a),m){const b=o?n()[0]:0;l.moveTo(0,h),l.lineTo(C()[0]+b,h)}else{const b=o?n()[1]:0;l.moveTo(h,0),l.lineTo(h,C()[1]+b)}},d=h=>{if(h.noHoveredTracks)return c(),l;let m,f;h.isFromVerticalTrack?(m=h.dataY,f=h.dataY):(m=h.dataX,f=h.isFrom2dTrack?h.dataY:h.dataX);const b=o?n():[0,0],p=r()?i()[0](f)+b[1]:i()[0](m)+b[0];return u(p),o&&u(i()[1](f)+b[1],!0,!0),l};return e.push(g.subscribe("app.mouseMove",d)),e.push(g.subscribe("app.mouseLeave",c)),e.push(g.subscribe("blur",c)),A&&e.push(eB.subscribe("higlass.mouseMove",d)),l},hh=(g,e=!1,I=!1)=>{const i=e?g.pMasked:g.pForeground||g.pMain;if(!i)throw new Error("setupShowMousePosition: No scene found. Please make sure to call this method after the scene has been initialized.");const n=()=>[g.xScale(),g.yScale()],C=Sat(g.pubSub,g.pubSubs,g.options,n,g.getPosition.bind(g),g.getDimensions.bind(g),g.getProp("flipText"),e,I);return i.addChild(C),()=>{i.removeChild(C)}},wat=g=>e=>Array.prototype.some.call(e,g),sc=(g,e)=>g+e,CBe=(g,e,I,i,n,C)=>{const r=document.createElement("line");return r.setAttribute("x1",g),r.setAttribute("x2",I),r.setAttribute("y1",e),r.setAttribute("y2",i),n&&r.setAttribute("stroke-width",n),C&&r.setAttribute("stroke",C),r},rBe=(g,e,I)=>{let i,n=0;const C=()=>{i=void 0},r=(...s)=>{const a=()=>{n>0&&(g(...s),n=0)};clearTimeout(i),i=setTimeout(a,I)};r.cancel=()=>{clearTimeout(i),C()},r.immediate=(...s)=>{g(...s)};let o=!1;return(s,...a)=>{o?n++:(g(...a),r(...a),o=!0,n=0,setTimeout(()=>{o=!1},e))}},Vat=(g,e=256,I=256)=>{const i=document.createElement("canvas");i.width=e,i.height=I;const n=i.getContext("2d");if(!n)throw new Error("Could not get canvas context");n.fillStyle="transparent",n.fillRect(0,0,i.width,i.height);const C=new ImageData(g,i.width,i.height);return n.putImageData(C,0,0),i},WQ=g=>new Promise(e=>{setTimeout(e,g)}),Rat=g=>{if(!g.tracks)return 0;let e=0;return g.tracks.top&&(e+=g.tracks.top.map(I=>I.height).reduce((I,i)=>I+i,0)),g.tracks.center&&(e+=g.tracks.center.map(I=>I.height).reduce((I,i)=>I+i,0)),g.tracks.bottom&&(e+=g.tracks.bottom.map(I=>I.height).reduce((I,i)=>I+i,0)),e},tA=()=>{},qN=g=>(g||"").replace(/\/$/,""),XQ=(g,e,I=0,i=1e-6)=>n=>{let C=255;return n>i&&(C=Math.max(0,Math.min(255,Math.floor(g(n+I))))),e[C]},CW=g=>{let e=[];for(let I=0;Ie[0]?g.left?oz(g.left,e):JIe(g,"left",e):g.right?oz(g.right,e):JIe(g,"right",e)}$s.prototype.add=function(e){if(!this.root){this.root=new oBe(e[0],e[1]),this.root.max=e[1];return}oz(this.root,e)};function ABe(g,e){if(!e)return!1;if(e.interval[0]<=g&&e.interval[1]>=g)return!0;let I=!1,i;return["left","right"].forEach(n=>{i=e[n],i&&i.max>g&&(I=I||ABe(g,i))}),I}$s.prototype.contains=function(e){return ABe(e,this.root)};function Wat(g,e){return g[0]===e[0]&&g[1]===e[1]||g[0]e[0]||g[0]e[1]||e[0]g[0]||e[0]g[1]}function aBe(g,e){if(!e)return!1;if(Wat(e.interval,g))return!0;let I=!1,i;return["left","right"].forEach(n=>{i=e[n],i&&i.max>=g[0]&&(I=I||aBe(g,i))}),I}$s.prototype.intersects=function(e){return aBe(e,this.root)};function Az(g){return g?1+Math.max(Az(g.left),Az(g.right)):0}$s.prototype.height=function(){return Az(this.root)};$s.prototype.findMax=function(e){const I=[e];let i,n=-1/0,C;for(;I.length;)i=I.pop(),i.left&&I.push(i.left),i.right&&I.push(i.right),i.interval[1]>n&&(n=i.interval[1],C=i);return C};$s.prototype._removeHelper=function(e,I){if(I)if(I.interval[0]===e[0]&&I.interval[1]===e[1]){if(I.left&&I.right){let n=I.left;for(;n.left;)n=n.left;const C=n.interval;n.interval=I.interval,I.interval=C,this._removeHelper(n.interval,I)}else{let n="left";I.right&&(n="right");const C=I.parentNode;C?(C.left===I?C.left=I[n]:C.right=I[n],I[n]&&(I[n].parentNode=C)):(this.root=I[n],this.root&&(this.root.parentNode=null))}const i=I.parentNode;if(i){let n=this.findMax(i);const C=n.interval[1];for(;n;)n.max===I.interval[1]?(n.max=C,n=n.parentNode):n=!1}}else this._removeHelper(e,I.left),this._removeHelper(e,I.right)};$s.prototype.remove=function(e){return this._removeHelper(e,this.root)};function U9(g){g.sort((i,n)=>n.to-n.from-(i.to-i.from));const e=[[]],I=[new $s];for(let i=0;i=o?this.minNonZero(this.data,i,n):(io*this.subsetSize&&(C=Math.min(C,this.minNonZero(this.data,o*this.subsetSize,n))),C)}},{key:"getMaxNonZeroInSubset",value:function(I){const i=I[0],n=I[1];let C=Number.MIN_SAFE_INTEGER;if(i===0&&n===this.tileSize)return this.maxNonZeroInTile;const r=Math.ceil(i/this.subsetSize),o=Math.floor((n-1)/this.subsetSize);return r>=o?this.maxNonZero(this.data,i,n):(io*this.subsetSize&&(C=Math.max(C,this.maxNonZero(this.data,o*this.subsetSize,n))),C)}},{key:"computeSubsetNonZeroMinimums",value:function(){const I=[];for(let i=0;i-this.epsilon||r-this.epsilon||r>n&&(n=r))}I.push(n)}return I}},{key:"getMinNonZeroInTile",value:function(){return Math.min(...this.subsetMinimums)}},{key:"getMaxNonZeroInTile",value:function(){return Math.max(...this.subsetMaximums)}},{key:"minNonZero",value:function(I,i,n){let C=Number.MAX_SAFE_INTEGER;for(let r=i;r-this.epsilon||o-this.epsilon||o>C&&(C=o)}return C}}]),g}();function kat(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function LIe(g,e){for(var I=0;I-this.epsilon||a-this.epsilon||a>o&&(o=a)}return o}},{key:"mirrorPrecomputedExtrema",value:function(){for(let I=1;I{let e;switch(g&&g.toLowerCase()){case"mean":e=H3;break;case"sum":e=hye;break;case"variance":e=d7;break;case"deviation":e=h7;break;default:e=H3,console.warn("Encountered an unsupported selectedRowsAggregationMode option.")}return e},Pv=(g,e)=>g.reduce((I,i)=>I+(Array.isArray(i)&&e?i.length:1),0),L0=g=>{switch(g.type){case"heatmap":case"horizontal-1d-heatmap":case"horizontal-bar":case"horizontal-line":case"horizontal-point":case"vertical-1d-heatmap":case"vertical-bar":case"vertical-line":case"vertical-point":case"horizontal-1d-tiles":case"vertical-1d-tiles":case"2d-tiles":case"horizontal-gene-annotations":case"vertical-gene-annotations":case"horizontal-heatmap":case"vertical-heatmap":case"osm-tiles":case"mapbox-tiles":case"horizontal-multivec":return!0;case"combined":return g.contents.map(I=>L0(I)).reduce(ow,!1);default:return!1}},NQ=(g,e,I)=>{let i=e,n=I;return I||(n=e,i=Object.values(g.state.views)[0].uid),g.tiledPlots[i].trackRenderer.getTrackObject(n)},sBe=(g,e)=>g.tiledPlots[e].trackRenderer,Dat=(g,e)=>g.tiledPlots[e];var kQ={},_Ie=Object.prototype.toString,lBe=function(e){var I=_Ie.call(e),i=I==="[object Arguments]";return i||(i=I!=="[object Array]"&&e!==null&&typeof e=="object"&&typeof e.length=="number"&&e.length>=0&&_Ie.call(e.callee)==="[object Function]"),i},vx,UIe;function Fat(){if(UIe)return vx;UIe=1;var g;if(!Object.keys){var e=Object.prototype.hasOwnProperty,I=Object.prototype.toString,i=lBe,n=Object.prototype.propertyIsEnumerable,C=!n.call({toString:null},"toString"),r=n.call(function(){},"prototype"),o=["toString","toLocaleString","valueOf","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","constructor"],A=function(c){var u=c.constructor;return u&&u.prototype===c},s={$applicationCache:!0,$console:!0,$external:!0,$frame:!0,$frameElement:!0,$frames:!0,$innerHeight:!0,$innerWidth:!0,$onmozfullscreenchange:!0,$onmozfullscreenerror:!0,$outerHeight:!0,$outerWidth:!0,$pageXOffset:!0,$pageYOffset:!0,$parent:!0,$scrollLeft:!0,$scrollTop:!0,$scrollX:!0,$scrollY:!0,$self:!0,$webkitIndexedDB:!0,$webkitStorageInfo:!0,$window:!0},a=function(){if(typeof window>"u")return!1;for(var c in window)try{if(!s["$"+c]&&e.call(window,c)&&window[c]!==null&&typeof window[c]=="object")try{A(window[c])}catch{return!0}}catch{return!0}return!1}(),l=function(c){if(typeof window>"u"||!a)return A(c);try{return A(c)}catch{return!1}};g=function(u){var d=u!==null&&typeof u=="object",h=I.call(u)==="[object Function]",m=i(u),f=d&&I.call(u)==="[object String]",b=[];if(!d&&!h&&!m)throw new TypeError("Object.keys called on a non-object");var p=r&&h;if(f&&u.length>0&&!e.call(u,0))for(var y=0;y0)for(var Z=0;Z"u"||!Di?Sg:Di(Uint8Array),Md={"%AggregateError%":typeof AggregateError>"u"?Sg:AggregateError,"%Array%":Array,"%ArrayBuffer%":typeof ArrayBuffer>"u"?Sg:ArrayBuffer,"%ArrayIteratorPrototype%":Qm&&Di?Di([][Symbol.iterator]()):Sg,"%AsyncFromSyncIteratorPrototype%":Sg,"%AsyncFunction%":Hf,"%AsyncGenerator%":Hf,"%AsyncGeneratorFunction%":Hf,"%AsyncIteratorPrototype%":Hf,"%Atomics%":typeof Atomics>"u"?Sg:Atomics,"%BigInt%":typeof BigInt>"u"?Sg:BigInt,"%BigInt64Array%":typeof BigInt64Array>"u"?Sg:BigInt64Array,"%BigUint64Array%":typeof BigUint64Array>"u"?Sg:BigUint64Array,"%Boolean%":Boolean,"%DataView%":typeof DataView>"u"?Sg:DataView,"%Date%":Date,"%decodeURI%":decodeURI,"%decodeURIComponent%":decodeURIComponent,"%encodeURI%":encodeURI,"%encodeURIComponent%":encodeURIComponent,"%Error%":Error,"%eval%":eval,"%EvalError%":EvalError,"%Float32Array%":typeof Float32Array>"u"?Sg:Float32Array,"%Float64Array%":typeof Float64Array>"u"?Sg:Float64Array,"%FinalizationRegistry%":typeof FinalizationRegistry>"u"?Sg:FinalizationRegistry,"%Function%":hBe,"%GeneratorFunction%":Hf,"%Int8Array%":typeof Int8Array>"u"?Sg:Int8Array,"%Int16Array%":typeof Int16Array>"u"?Sg:Int16Array,"%Int32Array%":typeof Int32Array>"u"?Sg:Int32Array,"%isFinite%":isFinite,"%isNaN%":isNaN,"%IteratorPrototype%":Qm&&Di?Di(Di([][Symbol.iterator]())):Sg,"%JSON%":typeof JSON=="object"?JSON:Sg,"%Map%":typeof Map>"u"?Sg:Map,"%MapIteratorPrototype%":typeof Map>"u"||!Qm||!Di?Sg:Di(new Map()[Symbol.iterator]()),"%Math%":Math,"%Number%":Number,"%Object%":Object,"%parseFloat%":parseFloat,"%parseInt%":parseInt,"%Promise%":typeof Promise>"u"?Sg:Promise,"%Proxy%":typeof Proxy>"u"?Sg:Proxy,"%RangeError%":RangeError,"%ReferenceError%":ReferenceError,"%Reflect%":typeof Reflect>"u"?Sg:Reflect,"%RegExp%":RegExp,"%Set%":typeof Set>"u"?Sg:Set,"%SetIteratorPrototype%":typeof Set>"u"||!Qm||!Di?Sg:Di(new Set()[Symbol.iterator]()),"%SharedArrayBuffer%":typeof SharedArrayBuffer>"u"?Sg:SharedArrayBuffer,"%String%":String,"%StringIteratorPrototype%":Qm&&Di?Di(""[Symbol.iterator]()):Sg,"%Symbol%":Qm?Symbol:Sg,"%SyntaxError%":Ob,"%ThrowTypeError%":gst,"%TypedArray%":ist,"%TypeError%":Up,"%Uint8Array%":typeof Uint8Array>"u"?Sg:Uint8Array,"%Uint8ClampedArray%":typeof Uint8ClampedArray>"u"?Sg:Uint8ClampedArray,"%Uint16Array%":typeof Uint16Array>"u"?Sg:Uint16Array,"%Uint32Array%":typeof Uint32Array>"u"?Sg:Uint32Array,"%URIError%":URIError,"%WeakMap%":typeof WeakMap>"u"?Sg:WeakMap,"%WeakRef%":typeof WeakRef>"u"?Sg:WeakRef,"%WeakSet%":typeof WeakSet>"u"?Sg:WeakSet};if(Di)try{null.error}catch(g){var nst=Di(Di(g));Md["%Error.prototype%"]=nst}var Cst=function g(e){var I;if(e==="%AsyncFunction%")I=Sx("async function () {}");else if(e==="%GeneratorFunction%")I=Sx("function* () {}");else if(e==="%AsyncGeneratorFunction%")I=Sx("async function* () {}");else if(e==="%AsyncGenerator%"){var i=g("%AsyncGeneratorFunction%");i&&(I=i.prototype)}else if(e==="%AsyncIteratorPrototype%"){var n=g("%AsyncGenerator%");n&&Di&&(I=Di(n.prototype))}return Md[e]=I,I},tie={"%ArrayBufferPrototype%":["ArrayBuffer","prototype"],"%ArrayPrototype%":["Array","prototype"],"%ArrayProto_entries%":["Array","prototype","entries"],"%ArrayProto_forEach%":["Array","prototype","forEach"],"%ArrayProto_keys%":["Array","prototype","keys"],"%ArrayProto_values%":["Array","prototype","values"],"%AsyncFunctionPrototype%":["AsyncFunction","prototype"],"%AsyncGenerator%":["AsyncGeneratorFunction","prototype"],"%AsyncGeneratorPrototype%":["AsyncGeneratorFunction","prototype","prototype"],"%BooleanPrototype%":["Boolean","prototype"],"%DataViewPrototype%":["DataView","prototype"],"%DatePrototype%":["Date","prototype"],"%ErrorPrototype%":["Error","prototype"],"%EvalErrorPrototype%":["EvalError","prototype"],"%Float32ArrayPrototype%":["Float32Array","prototype"],"%Float64ArrayPrototype%":["Float64Array","prototype"],"%FunctionPrototype%":["Function","prototype"],"%Generator%":["GeneratorFunction","prototype"],"%GeneratorPrototype%":["GeneratorFunction","prototype","prototype"],"%Int8ArrayPrototype%":["Int8Array","prototype"],"%Int16ArrayPrototype%":["Int16Array","prototype"],"%Int32ArrayPrototype%":["Int32Array","prototype"],"%JSONParse%":["JSON","parse"],"%JSONStringify%":["JSON","stringify"],"%MapPrototype%":["Map","prototype"],"%NumberPrototype%":["Number","prototype"],"%ObjectPrototype%":["Object","prototype"],"%ObjProto_toString%":["Object","prototype","toString"],"%ObjProto_valueOf%":["Object","prototype","valueOf"],"%PromisePrototype%":["Promise","prototype"],"%PromiseProto_then%":["Promise","prototype","then"],"%Promise_all%":["Promise","all"],"%Promise_reject%":["Promise","reject"],"%Promise_resolve%":["Promise","resolve"],"%RangeErrorPrototype%":["RangeError","prototype"],"%ReferenceErrorPrototype%":["ReferenceError","prototype"],"%RegExpPrototype%":["RegExp","prototype"],"%SetPrototype%":["Set","prototype"],"%SharedArrayBufferPrototype%":["SharedArrayBuffer","prototype"],"%StringPrototype%":["String","prototype"],"%SymbolPrototype%":["Symbol","prototype"],"%SyntaxErrorPrototype%":["SyntaxError","prototype"],"%TypedArrayPrototype%":["TypedArray","prototype"],"%TypeErrorPrototype%":["TypeError","prototype"],"%Uint8ArrayPrototype%":["Uint8Array","prototype"],"%Uint8ClampedArrayPrototype%":["Uint8ClampedArray","prototype"],"%Uint16ArrayPrototype%":["Uint16Array","prototype"],"%Uint32ArrayPrototype%":["Uint32Array","prototype"],"%URIErrorPrototype%":["URIError","prototype"],"%WeakMapPrototype%":["WeakMap","prototype"],"%WeakSetPrototype%":["WeakSet","prototype"]},Aw=KQ,j9=cl,rst=Aw.call(Function.call,Array.prototype.concat),ost=Aw.call(Function.apply,Array.prototype.splice),gie=Aw.call(Function.call,String.prototype.replace),$9=Aw.call(Function.call,String.prototype.slice),Ast=Aw.call(Function.call,RegExp.prototype.exec),ast=/[^%.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|%$))/g,sst=/\\(\\)?/g,lst=function(e){var I=$9(e,0,1),i=$9(e,-1);if(I==="%"&&i!=="%")throw new Ob("invalid intrinsic syntax, expected closing `%`");if(i==="%"&&I!=="%")throw new Ob("invalid intrinsic syntax, expected opening `%`");var n=[];return gie(e,ast,function(C,r,o,A){n[n.length]=o?gie(A,sst,"$1"):r||C}),n},cst=function(e,I){var i=e,n;if(j9(tie,i)&&(n=tie[i],i="%"+n[0]+"%"),j9(Md,i)){var C=Md[i];if(C===Hf&&(C=Cst(i)),typeof C>"u"&&!I)throw new Up("intrinsic "+e+" exists, but is not available. Please file an issue!");return{alias:n,name:i,value:C}}throw new Ob("intrinsic "+e+" does not exist!")},Ng=function(e,I){if(typeof e!="string"||e.length===0)throw new Up("intrinsic name must be a non-empty string");if(arguments.length>1&&typeof I!="boolean")throw new Up('"allowMissing" argument must be a boolean');if(Ast(/^%?[^%]*%?$/,e)===null)throw new Ob("`%` may not be present anywhere but at the beginning and end of the intrinsic name");var i=lst(e),n=i.length>0?i[0]:"",C=cst("%"+n+"%",I),r=C.name,o=C.value,A=!1,s=C.alias;s&&(n=s[0],ost(i,rst([0,1],s)));for(var a=1,l=!0;a=i.length){var h=Ed(o,c);l=!!h,l&&"get"in h&&!("originalValue"in h.get)?o=h.get:o=o[c]}else l=j9(o,c),o=o[c];l&&!A&&(Md[r]=o)}}return o},ust=Ng,az=ust("%Object.defineProperty%",!0),sz=function(){if(az)try{return az({},"a",{value:1}),!0}catch{return!1}return!1};sz.hasArrayLengthDefineBug=function(){if(!sz())return null;try{return az([],"length",{value:1}).length!==1}catch{return!0}};var ek=sz,dst=Ng,oW=dst("%Object.getOwnPropertyDescriptor%",!0);if(oW)try{oW([],"length")}catch{oW=null}var xQ=oW,hst=ek(),DQ=Ng,IB=hst&&DQ("%Object.defineProperty%",!0);if(IB)try{IB({},"a",{value:1})}catch{IB=!1}var mst=DQ("%SyntaxError%"),jm=DQ("%TypeError%"),Iie=xQ,mBe=function(e,I,i){if(!e||typeof e!="object"&&typeof e!="function")throw new jm("`obj` must be an object or a function`");if(typeof I!="string"&&typeof I!="symbol")throw new jm("`property` must be a string or a symbol`");if(arguments.length>3&&typeof arguments[3]!="boolean"&&arguments[3]!==null)throw new jm("`nonEnumerable`, if provided, must be a boolean or null");if(arguments.length>4&&typeof arguments[4]!="boolean"&&arguments[4]!==null)throw new jm("`nonWritable`, if provided, must be a boolean or null");if(arguments.length>5&&typeof arguments[5]!="boolean"&&arguments[5]!==null)throw new jm("`nonConfigurable`, if provided, must be a boolean or null");if(arguments.length>6&&typeof arguments[6]!="boolean")throw new jm("`loose`, if provided, must be a boolean");var n=arguments.length>3?arguments[3]:null,C=arguments.length>4?arguments[4]:null,r=arguments.length>5?arguments[5]:null,o=arguments.length>6?arguments[6]:!1,A=!!Iie&&Iie(e,I);if(IB)IB(e,I,{configurable:r===null&&A?A.configurable:!r,enumerable:n===null&&A?A.enumerable:!n,value:i,writable:C===null&&A?A.writable:!C});else if(o||!n&&!C&&!r)e[I]=i;else throw new mst("This environment does not support defining a property as non-configurable, non-writable, or non-enumerable.")},fst=cBe,pst=typeof Symbol=="function"&&typeof Symbol("foo")=="symbol",bst=Object.prototype.toString,yst=Array.prototype.concat,iie=mBe,Zst=function(g){return typeof g=="function"&&bst.call(g)==="[object Function]"},fBe=ek(),Gst=function(g,e,I,i){if(e in g){if(i===!0){if(g[e]===I)return}else if(!Zst(i)||!i())return}fBe?iie(g,e,I,!0):iie(g,e,I)},pBe=function(g,e){var I=arguments.length>2?arguments[2]:{},i=fst(e);pst&&(i=yst.call(i,Object.getOwnPropertySymbols(e)));for(var n=0;n4294967295||vst(I)!==I)throw new rie("`length` must be a positive 32-bit integer");var i=arguments.length>2&&!!arguments[2],n=!0,C=!0;if("length"in e&&Cie){var r=Cie(e,"length");r&&!r.configurable&&(n=!1),r&&!r.writable&&(C=!1)}return(n||C||!i)&&(Bst?nie(e,"length",I,!0,!0):nie(e,"length",I)),e};(function(g){var e=KQ,I=Ng,i=Sst,n=I("%TypeError%"),C=I("%Function.prototype.apply%"),r=I("%Function.prototype.call%"),o=I("%Reflect.apply%",!0)||e.call(r,C),A=I("%Object.defineProperty%",!0),s=I("%Math.max%");if(A)try{A({},"a",{value:1})}catch{A=null}g.exports=function(c){if(typeof c!="function")throw new n("a function is required");var u=o(e,r,arguments);return i(u,1+s(0,c.length-(arguments.length-1)),!0)};var a=function(){return o(e,C,arguments)};A?A(g.exports,"apply",{value:a}):g.exports.apply=a})(bBe);var ul=bBe.exports,ZBe=Ng,GBe=ul,wst=GBe(ZBe("String.prototype.indexOf")),uC=function(e,I){var i=ZBe(e,!!I);return typeof i=="function"&&wst(e,".prototype.")>-1?GBe(i):i},Vst=cBe,BBe=YQ(),vBe=uC,oie=Object,Rst=vBe("Array.prototype.push"),Aie=vBe("Object.prototype.propertyIsEnumerable"),Wst=BBe?Object.getOwnPropertySymbols:null,SBe=function(e,I){if(e==null)throw new TypeError("target must be an object");var i=oie(e);if(arguments.length===1)return i;for(var n=1;n= 0");if(a>r)throw new I("length is greater than (2**32 - 1)");var l=arguments.length>1?arguments[1]:e,c=[];if(l!==e){if(!A)throw new i("ArrayCreate: a `proto` argument that is not `Array.prototype` is not supported in an environment that does not support setting the [[Prototype]]");A(c,l)}return a!==0&&(c.length=a),c},Wx}const zst={},Pst=Object.freeze(Object.defineProperty({__proto__:null,default:zst},Symbol.toStringTag,{value:"Module"})),Jst=Al(Pst);var EQ=typeof Map=="function"&&Map.prototype,Xx=Object.getOwnPropertyDescriptor&&EQ?Object.getOwnPropertyDescriptor(Map.prototype,"size"):null,q9=EQ&&Xx&&typeof Xx.get=="function"?Xx.get:null,lie=EQ&&Map.prototype.forEach,MQ=typeof Set=="function"&&Set.prototype,Hx=Object.getOwnPropertyDescriptor&&MQ?Object.getOwnPropertyDescriptor(Set.prototype,"size"):null,eH=MQ&&Hx&&typeof Hx.get=="function"?Hx.get:null,cie=MQ&&Set.prototype.forEach,Ost=typeof WeakMap=="function"&&WeakMap.prototype,iB=Ost?WeakMap.prototype.has:null,Lst=typeof WeakSet=="function"&&WeakSet.prototype,nB=Lst?WeakSet.prototype.has:null,_st=typeof WeakRef=="function"&&WeakRef.prototype,uie=_st?WeakRef.prototype.deref:null,Ust=Boolean.prototype.valueOf,Qst=Object.prototype.toString,jst=Function.prototype.toString,$st=String.prototype.match,zQ=String.prototype.slice,Vc=String.prototype.replace,qst=String.prototype.toUpperCase,die=String.prototype.toLowerCase,XBe=RegExp.prototype.test,hie=Array.prototype.concat,MA=Array.prototype.join,elt=Array.prototype.slice,mie=Math.floor,lz=typeof BigInt=="function"?BigInt.prototype.valueOf:null,Tx=Object.getOwnPropertySymbols,cz=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Symbol.prototype.toString:null,Lb=typeof Symbol=="function"&&typeof Symbol.iterator=="object",Yn=typeof Symbol=="function"&&Symbol.toStringTag&&(typeof Symbol.toStringTag===Lb||"symbol")?Symbol.toStringTag:null,HBe=Object.prototype.propertyIsEnumerable,fie=(typeof Reflect=="function"?Reflect.getPrototypeOf:Object.getPrototypeOf)||([].__proto__===Array.prototype?function(g){return g.__proto__}:null);function pie(g,e){if(g===1/0||g===-1/0||g!==g||g&&g>-1e3&&g<1e3||XBe.call(/e/,e))return e;var I=/[0-9](?=(?:[0-9]{3})+(?![0-9]))/g;if(typeof g=="number"){var i=g<0?-mie(-g):mie(g);if(i!==g){var n=String(i),C=zQ.call(e,n.length+1);return Vc.call(n,I,"$&_")+"."+Vc.call(Vc.call(C,/([0-9]{3})/g,"$&_"),/_$/,"")}}return Vc.call(e,I,"$&_")}var uz=Jst,bie=uz.custom,yie=kBe(bie)?bie:null,TBe=function g(e,I,i,n){var C=I||{};if(tc(C,"quoteStyle")&&C.quoteStyle!=="single"&&C.quoteStyle!=="double")throw new TypeError('option "quoteStyle" must be "single" or "double"');if(tc(C,"maxStringLength")&&(typeof C.maxStringLength=="number"?C.maxStringLength<0&&C.maxStringLength!==1/0:C.maxStringLength!==null))throw new TypeError('option "maxStringLength", if provided, must be a positive integer, Infinity, or `null`');var r=tc(C,"customInspect")?C.customInspect:!0;if(typeof r!="boolean"&&r!=="symbol")throw new TypeError("option \"customInspect\", if provided, must be `true`, `false`, or `'symbol'`");if(tc(C,"indent")&&C.indent!==null&&C.indent!==" "&&!(parseInt(C.indent,10)===C.indent&&C.indent>0))throw new TypeError('option "indent" must be "\\t", an integer > 0, or `null`');if(tc(C,"numericSeparator")&&typeof C.numericSeparator!="boolean")throw new TypeError('option "numericSeparator", if provided, must be `true` or `false`');var o=C.numericSeparator;if(typeof e>"u")return"undefined";if(e===null)return"null";if(typeof e=="boolean")return e?"true":"false";if(typeof e=="string")return KBe(e,C);if(typeof e=="number"){if(e===0)return 1/0/e>0?"0":"-0";var A=String(e);return o?pie(e,A):A}if(typeof e=="bigint"){var s=String(e)+"n";return o?pie(e,s):s}var a=typeof C.depth>"u"?5:C.depth;if(typeof i>"u"&&(i=0),i>=a&&a>0&&typeof e=="object")return dz(e)?"[Array]":"[Object]";var l=flt(C,i);if(typeof n>"u")n=[];else if(YBe(n,e)>=0)return"[Circular]";function c(W,V,H){if(V&&(n=elt.call(n),n.push(V)),H){var D={depth:C.depth};return tc(C,"quoteStyle")&&(D.quoteStyle=C.quoteStyle),g(W,D,i+1,n)}return g(W,C,i+1,n)}if(typeof e=="function"&&!Zie(e)){var u=Alt(e),d=pR(e,c);return"[Function"+(u?": "+u:" (anonymous)")+"]"+(d.length>0?" { "+MA.call(d,", ")+" }":"")}if(kBe(e)){var h=Lb?Vc.call(String(e),/^(Symbol\(.*\))_[^)]*$/,"$1"):cz.call(e);return typeof e=="object"&&!Lb?rZ(h):h}if(dlt(e)){for(var m="<"+die.call(String(e.nodeName)),f=e.attributes||[],b=0;b",m}if(dz(e)){if(e.length===0)return"[]";var p=pR(e,c);return l&&!mlt(p)?"["+hz(p,l)+"]":"[ "+MA.call(p,", ")+" ]"}if(Ilt(e)){var y=pR(e,c);return!("cause"in Error.prototype)&&"cause"in e&&!HBe.call(e,"cause")?"{ ["+String(e)+"] "+MA.call(hie.call("[cause]: "+c(e.cause),y),", ")+" }":y.length===0?"["+String(e)+"]":"{ ["+String(e)+"] "+MA.call(y,", ")+" }"}if(typeof e=="object"&&r){if(yie&&typeof e[yie]=="function"&&uz)return uz(e,{depth:a-i});if(r!=="symbol"&&typeof e.inspect=="function")return e.inspect()}if(alt(e)){var Z=[];return lie&&lie.call(e,function(W,V){Z.push(c(V,e,!0)+" => "+c(W,e))}),Gie("Map",q9.call(e),Z,l)}if(clt(e)){var v=[];return cie&&cie.call(e,function(W){v.push(c(W,e))}),Gie("Set",eH.call(e),v,l)}if(slt(e))return Nx("WeakMap");if(ult(e))return Nx("WeakSet");if(llt(e))return Nx("WeakRef");if(nlt(e))return rZ(c(Number(e)));if(rlt(e))return rZ(c(lz.call(e)));if(Clt(e))return rZ(Ust.call(e));if(ilt(e))return rZ(c(String(e)));if(typeof window<"u"&&e===window)return"{ [object Window] }";if(e===globalThis)return"{ [object globalThis] }";if(!glt(e)&&!Zie(e)){var G=pR(e,c),B=fie?fie(e)===Object.prototype:e instanceof Object||e.constructor===Object,w=e instanceof Object?"":"null prototype",R=!B&&Yn&&Object(e)===e&&Yn in e?zQ.call(pu(e),8,-1):w?"Object":"",S=B||typeof e.constructor!="function"?"":e.constructor.name?e.constructor.name+" ":"",X=S+(R||w?"["+MA.call(hie.call([],R||[],w||[]),": ")+"] ":"");return G.length===0?X+"{}":l?X+"{"+hz(G,l)+"}":X+"{ "+MA.call(G,", ")+" }"}return String(e)};function NBe(g,e,I){var i=(I.quoteStyle||e)==="double"?'"':"'";return i+g+i}function tlt(g){return Vc.call(String(g),/"/g,""")}function dz(g){return pu(g)==="[object Array]"&&(!Yn||!(typeof g=="object"&&Yn in g))}function glt(g){return pu(g)==="[object Date]"&&(!Yn||!(typeof g=="object"&&Yn in g))}function Zie(g){return pu(g)==="[object RegExp]"&&(!Yn||!(typeof g=="object"&&Yn in g))}function Ilt(g){return pu(g)==="[object Error]"&&(!Yn||!(typeof g=="object"&&Yn in g))}function ilt(g){return pu(g)==="[object String]"&&(!Yn||!(typeof g=="object"&&Yn in g))}function nlt(g){return pu(g)==="[object Number]"&&(!Yn||!(typeof g=="object"&&Yn in g))}function Clt(g){return pu(g)==="[object Boolean]"&&(!Yn||!(typeof g=="object"&&Yn in g))}function kBe(g){if(Lb)return g&&typeof g=="object"&&g instanceof Symbol;if(typeof g=="symbol")return!0;if(!g||typeof g!="object"||!cz)return!1;try{return cz.call(g),!0}catch{}return!1}function rlt(g){if(!g||typeof g!="object"||!lz)return!1;try{return lz.call(g),!0}catch{}return!1}var olt=Object.prototype.hasOwnProperty||function(g){return g in this};function tc(g,e){return olt.call(g,e)}function pu(g){return Qst.call(g)}function Alt(g){if(g.name)return g.name;var e=$st.call(jst.call(g),/^function\s*([\w$]+)/);return e?e[1]:null}function YBe(g,e){if(g.indexOf)return g.indexOf(e);for(var I=0,i=g.length;Ie.maxStringLength){var I=g.length-e.maxStringLength,i="... "+I+" more character"+(I>1?"s":"");return KBe(zQ.call(g,0,e.maxStringLength),e)+i}var n=Vc.call(Vc.call(g,/(['\\])/g,"\\$1"),/[\x00-\x1f]/g,hlt);return NBe(n,"single",e)}function hlt(g){var e=g.charCodeAt(0),I={8:"b",9:"t",10:"n",12:"f",13:"r"}[e];return I?"\\"+I:"\\x"+(e<16?"0":"")+qst.call(e.toString(16))}function rZ(g){return"Object("+g+")"}function Nx(g){return g+" { ? }"}function Gie(g,e,I,i){var n=i?hz(I,i):MA.call(I,", ");return g+" ("+e+") {"+n+"}"}function mlt(g){for(var e=0;e=0)return!1;return!0}function flt(g,e){var I;if(g.indent===" ")I=" ";else if(typeof g.indent=="number"&&g.indent>0)I=MA.call(Array(g.indent+1)," ");else return null;return{base:I,prev:MA.call(Array(e+1),I)}}function hz(g,e){if(g.length===0)return"";var I=` -`+e.prev+e.base;return I+MA.call(g,","+I)+` -`+e.prev}function pR(g,e){var I=dz(g),i=[];if(I){i.length=g.length;for(var n=0;n"u")return"Undefined";if(typeof e=="function"||typeof e=="object")return"Object";if(typeof e=="number")return"Number";if(typeof e=="boolean")return"Boolean";if(typeof e=="string")return"String"}),Yx}var Kx,Sie;function dn(){if(Sie)return Kx;Sie=1;var g=plt();return Kx=function(I){return typeof I=="symbol"?"Symbol":typeof I=="bigint"?"BigInt":g(I)},Kx}var blt=Ng,wie=blt("%TypeError%"),ylt=TBe,Zlt=bu(),Glt=dn(),aw=function(e,I){if(Glt(e)!=="Object")throw new wie("Assertion failed: Type(O) is not Object");if(!Zlt(I))throw new wie("Assertion failed: IsPropertyKey(P) is not true, got "+ylt(I));return e[I]},xx,Vie;function xBe(){if(Vie)return xx;Vie=1;var g=Ng,e=g("%Array%"),I=!e.isArray&&uC("Object.prototype.toString");return xx=e.isArray||function(n){return I(n)==="[object Array]"},xx}var Dx,Rie;function PQ(){return Rie||(Rie=1,Dx=xBe()),Dx}var bR={exports:{}},Fx,Wie;function Blt(){return Wie||(Wie=1,Fx=Ng),Fx}var Ex,Xie;function JQ(){if(Xie)return Ex;Xie=1;var g=Ng,e=cl,I=g("%TypeError%");return Ex=function(n,C){if(n.Type(C)!=="Object")return!1;var r={"[[Configurable]]":!0,"[[Enumerable]]":!0,"[[Get]]":!0,"[[Set]]":!0,"[[Value]]":!0,"[[Writable]]":!0};for(var o in C)if(e(C,o)&&!r[o])return!1;if(n.IsDataDescriptor(C)&&n.IsAccessorDescriptor(C))throw new I("Property Descriptors may not be both accessor and data descriptors");return!0},Ex}var Mx,Hie;function DBe(){if(Hie)return Mx;Hie=1;var g=ek,e=Ng,I=g()&&e("%Object.defineProperty%",!0),i=g.hasArrayLengthDefineBug(),n=i&&xBe(),C=uC,r=C("Object.prototype.propertyIsEnumerable");return Mx=function(A,s,a,l,c,u){if(!I){if(!A(u)||!u["[[Configurable]]"]||!u["[[Writable]]"]||c in l&&r(l,c)!==!!u["[[Enumerable]]"])return!1;var d=u["[[Value]]"];return l[c]=d,s(l[c],d)}return i&&c==="length"&&"[[Value]]"in u&&n(l)&&l.length!==u["[[Value]]"]?(l.length=u["[[Value]]"],l.length===u["[[Value]]"]):(I(l,c,a(u)),!0)},Mx}var zx,Tie;function vlt(){if(Tie)return zx;Tie=1;var g=cl;return zx=function(I){return g(I,"[[StartIndex]]")&&g(I,"[[EndIndex]]")&&I["[[StartIndex]]"]>=0&&I["[[EndIndex]]"]>=I["[[StartIndex]]"]&&String(parseInt(I["[[StartIndex]]"],10))===String(I["[[StartIndex]]"])&&String(parseInt(I["[[EndIndex]]"],10))===String(I["[[EndIndex]]"])},zx}var Px,Nie;function gk(){if(Nie)return Px;Nie=1;var g=Ng,e=g("%TypeError%"),I=g("%SyntaxError%"),i=cl,n=FQ(),C=vlt(),r={"Property Descriptor":function(A){var s={"[[Configurable]]":!0,"[[Enumerable]]":!0,"[[Get]]":!0,"[[Set]]":!0,"[[Value]]":!0,"[[Writable]]":!0};if(!A)return!1;for(var a in A)if(i(A,a)&&!s[a])return!1;var l=i(A,"[[Value]]"),c=i(A,"[[Get]]")||i(A,"[[Set]]");if(l&&c)throw new e("Property Descriptors may not be both accessor and data descriptors");return!0},"Match Record":C,"Iterator Record":function(A){return i(A,"[[Iterator]]")&&i(A,"[[NextMethod]]")&&i(A,"[[Done]]")},"PromiseCapability Record":function(A){return!!A&&i(A,"[[Resolve]]")&&typeof A["[[Resolve]]"]=="function"&&i(A,"[[Reject]]")&&typeof A["[[Reject]]"]=="function"&&i(A,"[[Promise]]")&&A["[[Promise]]"]&&typeof A["[[Promise]]"].then=="function"},"AsyncGeneratorRequest Record":function(A){return!!A&&i(A,"[[Completion]]")&&i(A,"[[Capability]]")&&r["PromiseCapability Record"](A["[[Capability]]"])},"RegExp Record":function(A){return A&&i(A,"[[IgnoreCase]]")&&typeof A["[[IgnoreCase]]"]=="boolean"&&i(A,"[[Multiline]]")&&typeof A["[[Multiline]]"]=="boolean"&&i(A,"[[DotAll]]")&&typeof A["[[DotAll]]"]=="boolean"&&i(A,"[[Unicode]]")&&typeof A["[[Unicode]]"]=="boolean"&&i(A,"[[CapturingGroupsCount]]")&&typeof A["[[CapturingGroupsCount]]"]=="number"&&n(A["[[CapturingGroupsCount]]"])&&A["[[CapturingGroupsCount]]"]>=0}};return Px=function(A,s,a,l){var c=r[s];if(typeof c!="function")throw new I("unknown record type: "+s);if(A(l)!=="Object"||!c(l))throw new e(a+" must be a "+s)},Px}var Jx,kie;function Slt(){return kie||(kie=1,Jx=function(e){if(typeof e>"u")return e;var I={};return"[[Value]]"in e&&(I.value=e["[[Value]]"]),"[[Writable]]"in e&&(I.writable=!!e["[[Writable]]"]),"[[Get]]"in e&&(I.get=e["[[Get]]"]),"[[Set]]"in e&&(I.set=e["[[Set]]"]),"[[Enumerable]]"in e&&(I.enumerable=!!e["[[Enumerable]]"]),"[[Configurable]]"in e&&(I.configurable=!!e["[[Configurable]]"]),I}),Jx}var Ox,Yie;function FBe(){if(Yie)return Ox;Yie=1;var g=gk(),e=Slt(),I=dn();return Ox=function(n){return typeof n<"u"&&g(I,"Property Descriptor","Desc",n),e(n)},Ox}var Lx,Kie;function Ik(){if(Kie)return Lx;Kie=1;var g=cl,e=dn(),I=gk();return Lx=function(n){return!(typeof n>"u"||(I(e,"Property Descriptor","Desc",n),!g(n,"[[Get]]")&&!g(n,"[[Set]]")))},Lx}var _x,xie;function ik(){if(xie)return _x;xie=1;var g=cl,e=dn(),I=gk();return _x=function(n){return!(typeof n>"u"||(I(e,"Property Descriptor","Desc",n),!g(n,"[[Value]]")&&!g(n,"[[Writable]]")))},_x}var Ux,Die;function OQ(){if(Die)return Ux;Die=1;var g=tk;return Ux=function(I,i){return I===i?I===0?1/I===1/i:!0:g(I)&&g(i)},Ux}var EBe=function(e){return!!e},MBe=Function.prototype.toString,pp=typeof Reflect=="object"&&Reflect!==null&&Reflect.apply,mz,AW;if(typeof pp=="function"&&typeof Object.defineProperty=="function")try{mz=Object.defineProperty({},"length",{get:function(){throw AW}}),AW={},pp(function(){throw 42},null,mz)}catch(g){g!==AW&&(pp=null)}else pp=null;var wlt=/^\s*class\b/,fz=function(e){try{var I=MBe.call(e);return wlt.test(I)}catch{return!1}},Qx=function(e){try{return fz(e)?!1:(MBe.call(e),!0)}catch{return!1}},aW=Object.prototype.toString,Vlt="[object Object]",Rlt="[object Function]",Wlt="[object GeneratorFunction]",Xlt="[object HTMLAllCollection]",Hlt="[object HTML document.all class]",Tlt="[object HTMLCollection]",Nlt=typeof Symbol=="function"&&!!Symbol.toStringTag,klt=!(0 in[,]),pz=function(){return!1};if(typeof document=="object"){var Ylt=document.all;aW.call(Ylt)===aW.call(document.all)&&(pz=function(e){if((klt||!e)&&(typeof e>"u"||typeof e=="object"))try{var I=aW.call(e);return(I===Xlt||I===Hlt||I===Tlt||I===Vlt)&&e("")==null}catch{}return!1})}var LQ=pp?function(e){if(pz(e))return!0;if(!e||typeof e!="function"&&typeof e!="object")return!1;try{pp(e,null,mz)}catch(I){if(I!==AW)return!1}return!fz(e)&&Qx(e)}:function(e){if(pz(e))return!0;if(!e||typeof e!="function"&&typeof e!="object")return!1;if(Nlt)return Qx(e);if(fz(e))return!1;var I=aW.call(e);return I!==Rlt&&I!==Wlt&&!/^\[object HTML/.test(I)?!1:Qx(e)},_Q=LQ,jx,Fie;function zBe(){if(Fie)return jx;Fie=1;var g=cl,e=Ng,I=e("%TypeError%"),i=dn(),n=EBe,C=_Q;return jx=function(o){if(i(o)!=="Object")throw new I("ToPropertyDescriptor requires an object");var A={};if(g(o,"enumerable")&&(A["[[Enumerable]]"]=n(o.enumerable)),g(o,"configurable")&&(A["[[Configurable]]"]=n(o.configurable)),g(o,"value")&&(A["[[Value]]"]=o.value),g(o,"writable")&&(A["[[Writable]]"]=n(o.writable)),g(o,"get")){var s=o.get;if(typeof s<"u"&&!C(s))throw new I("getter must be a function");A["[[Get]]"]=s}if(g(o,"set")){var a=o.set;if(typeof a<"u"&&!C(a))throw new I("setter must be a function");A["[[Set]]"]=a}if((g(A,"[[Get]]")||g(A,"[[Set]]"))&&(g(A,"[[Value]]")||g(A,"[[Writable]]")))throw new I("Invalid property descriptor. Cannot both specify accessors and a value or writable attribute");return A},jx}var $x,Eie;function Klt(){if(Eie)return $x;Eie=1;var g=Ng,e=g("%TypeError%"),I=JQ(),i=DBe(),n=FBe(),C=Ik(),r=ik(),o=bu(),A=OQ(),s=zBe(),a=dn();return $x=function(c,u,d){if(a(c)!=="Object")throw new e("Assertion failed: Type(O) is not Object");if(!o(u))throw new e("Assertion failed: IsPropertyKey(P) is not true");var h=I({Type:a,IsDataDescriptor:r,IsAccessorDescriptor:C},d)?d:s(d);if(!I({Type:a,IsDataDescriptor:r,IsAccessorDescriptor:C},h))throw new e("Assertion failed: Desc is not a valid Property Descriptor");return i(r,A,n,c,u,h)},$x}var Mie;function xlt(){if(Mie)return bR.exports;Mie=1;var g=Blt(),e=g("%Reflect.construct%",!0),I=Klt();try{I({},"",{"[[Get]]":function(){}})}catch{I=null}if(I&&e){var i={},n={};I(n,"length",{"[[Get]]":function(){throw i},"[[Enumerable]]":!0}),bR.exports=function(r){try{e(r,n)}catch(o){return o===i}}}else bR.exports=function(r){return typeof r=="function"&&!!r.prototype};return bR.exports}var PBe=Ng,zie=PBe("%Symbol.species%",!0),Pie=PBe("%TypeError%"),Jie=Mst(),Oie=aw,Dlt=PQ(),Flt=xlt(),Elt=dn(),Mlt=FQ(),JBe=function(e,I){if(!Mlt(I)||I<0)throw new Pie("Assertion failed: length must be an integer >= 0");var i=Dlt(e);if(!i)return Jie(I);var n=Oie(e,"constructor");if(zie&&Elt(n)==="Object"&&(n=Oie(n,zie),n===null&&(n=void 0)),typeof n>"u")return Jie(I);if(!Flt(n))throw new Pie("C must be a constructor");return new n(I)},OBe=Number.MAX_SAFE_INTEGER||9007199254740991,qx,Lie;function LBe(){if(Lie)return qx;Lie=1;var g=Ng,e=uC,I=g("%TypeError%"),i=PQ(),n=g("%Reflect.apply%",!0)||e("Function.prototype.apply");return qx=function(r,o){var A=arguments.length>2?arguments[2]:[];if(!i(A))throw new I("Assertion failed: optional `argumentsList`, if provided, must be a List");return n(r,o,A)},qx}var eD,_ie;function _Be(){return _ie||(_ie=1,eD=function(e){return e===null||typeof e!="function"&&typeof e!="object"}),eD}var tD,Uie;function zlt(){if(Uie)return tD;Uie=1;var g=Ng,e=g("%Object.preventExtensions%",!0),I=g("%Object.isExtensible%",!0),i=_Be();return tD=e?function(C){return!i(C)&&I(C)}:function(C){return!i(C)},tD}var gD,Qie;function Plt(){return Qie||(Qie=1,gD=function(e,I){return!!I&&typeof I=="object"&&"[[Enumerable]]"in I&&"[[Configurable]]"in I&&(e.IsAccessorDescriptor(I)||e.IsDataDescriptor(I))}),gD}var ID,jie;function Jlt(){if(jie)return ID;jie=1;var g=gk(),e=Ik(),I=ik(),i=dn();return ID=function(C){return typeof C>"u"?!1:(g(i,"Property Descriptor","Desc",C),!e(C)&&!I(C))},ID}var iD,$ie;function Olt(){if($ie)return iD;$ie=1;var g=Ng,e=g("%TypeError%"),I=DBe(),i=Plt(),n=JQ(),C=FBe(),r=Ik(),o=ik(),A=Jlt(),s=bu(),a=OQ(),l=dn();return iD=function(u,d,h,m,f){var b=l(u);if(b!=="Undefined"&&b!=="Object")throw new e("Assertion failed: O must be undefined or an Object");if(!s(d))throw new e("Assertion failed: P must be a Property Key");if(l(h)!=="Boolean")throw new e("Assertion failed: extensible must be a Boolean");if(!n({Type:l,IsDataDescriptor:o,IsAccessorDescriptor:r},m))throw new e("Assertion failed: Desc must be a Property Descriptor");if(l(f)!=="Undefined"&&!n({Type:l,IsDataDescriptor:o,IsAccessorDescriptor:r},f))throw new e("Assertion failed: current must be a Property Descriptor, or undefined");if(l(f)==="Undefined")return h?b==="Undefined"?!0:r(m)?I(o,a,C,u,d,m):I(o,a,C,u,d,{"[[Configurable]]":!!m["[[Configurable]]"],"[[Enumerable]]":!!m["[[Enumerable]]"],"[[Value]]":m["[[Value]]"],"[[Writable]]":!!m["[[Writable]]"]}):!1;if(!i({IsAccessorDescriptor:r,IsDataDescriptor:o},f))throw new e("`current`, when present, must be a fully populated and valid Property Descriptor");if(!f["[[Configurable]]"]){if("[[Configurable]]"in m&&m["[[Configurable]]"]||"[[Enumerable]]"in m&&!a(m["[[Enumerable]]"],f["[[Enumerable]]"])||!A(m)&&!a(r(m),r(f)))return!1;if(r(f)){if("[[Get]]"in m&&!a(m["[[Get]]"],f["[[Get]]"])||"[[Set]]"in m&&!a(m["[[Set]]"],f["[[Set]]"]))return!1}else if(!f["[[Writable]]"]&&("[[Writable]]"in m&&m["[[Writable]]"]||"[[Value]]"in m&&!a(m["[[Value]]"],f["[[Value]]"])))return!1}if(b!=="Undefined"){var p,y;return o(f)&&r(m)?(p=("[[Configurable]]"in m?m:f)["[[Configurable]]"],y=("[[Enumerable]]"in m?m:f)["[[Enumerable]]"],I(o,a,C,u,d,{"[[Configurable]]":!!p,"[[Enumerable]]":!!y,"[[Get]]":("[[Get]]"in m?m:f)["[[Get]]"],"[[Set]]":("[[Set]]"in m?m:f)["[[Set]]"]})):r(f)&&o(m)?(p=("[[Configurable]]"in m?m:f)["[[Configurable]]"],y=("[[Enumerable]]"in m?m:f)["[[Enumerable]]"],I(o,a,C,u,d,{"[[Configurable]]":!!p,"[[Enumerable]]":!!y,"[[Value]]":("[[Value]]"in m?m:f)["[[Value]]"],"[[Writable]]":!!("[[Writable]]"in m?m:f)["[[Writable]]"]})):I(o,a,C,u,d,m)}return!0},iD}var nD,qie;function Llt(){if(qie)return nD;qie=1;var g=Ng,e=xQ,I=g("%SyntaxError%"),i=g("%TypeError%"),n=JQ(),C=Ik(),r=ik(),o=zlt(),A=bu(),s=zBe(),a=OQ(),l=dn(),c=Olt();return nD=function(d,h,m){if(l(d)!=="Object")throw new i("Assertion failed: O must be an Object");if(!A(h))throw new i("Assertion failed: P must be a Property Key");if(!n({Type:l,IsDataDescriptor:r,IsAccessorDescriptor:C},m))throw new i("Assertion failed: Desc must be a Property Descriptor");if(!e){if(C(m))throw new I("This environment does not support accessor property descriptors.");var f=!(h in d)&&m["[[Writable]]"]&&m["[[Enumerable]]"]&&m["[[Configurable]]"]&&"[[Value]]"in m,b=h in d&&(!("[[Configurable]]"in m)||m["[[Configurable]]"])&&(!("[[Enumerable]]"in m)||m["[[Enumerable]]"])&&(!("[[Writable]]"in m)||m["[[Writable]]"])&&"[[Value]]"in m;if(f||b)return d[h]=m["[[Value]]"],a(d[h],m["[[Value]]"]);throw new I("This environment does not support defining non-writable, non-enumerable, or non-configurable properties")}var p=e(d,h),y=p&&s(p),Z=o(d);return c(d,h,Z,m,y)},nD}var CD,ene;function _lt(){if(ene)return CD;ene=1;var g=Ng,e=g("%TypeError%"),I=bu(),i=Llt(),n=dn();return CD=function(r,o,A){if(n(r)!=="Object")throw new e("Assertion failed: Type(O) is not Object");if(!I(o))throw new e("Assertion failed: IsPropertyKey(P) is not true");var s={"[[Configurable]]":!0,"[[Enumerable]]":!0,"[[Value]]":A,"[[Writable]]":!0};return i(r,o,s)},CD}var rD,tne;function UBe(){if(tne)return rD;tne=1;var g=Ng,e=g("%TypeError%"),I=_lt(),i=bu(),n=dn();return rD=function(r,o,A){if(n(r)!=="Object")throw new e("Assertion failed: Type(O) is not Object");if(!i(o))throw new e("Assertion failed: IsPropertyKey(P) is not true");var s=I(r,o,A);if(!s)throw new e("unable to create data property")},rD}var oD,gne;function QBe(){if(gne)return oD;gne=1;var g=Ng,e=g("%TypeError%"),I=bu(),i=dn();return oD=function(C,r){if(i(C)!=="Object")throw new e("Assertion failed: `O` must be an Object");if(!I(r))throw new e("Assertion failed: `P` must be a Property Key");return r in C},oD}var AD,Ine;function Ult(){return Ine||(Ine=1,AD=function(e){return e===null||typeof e!="function"&&typeof e!="object"}),AD}var Qlt=YQ,sw=function(){return Qlt()&&!!Symbol.toStringTag},aD,ine;function jlt(){if(ine)return aD;ine=1;var g=Date.prototype.getDay,e=function(r){try{return g.call(r),!0}catch{return!1}},I=Object.prototype.toString,i="[object Date]",n=sw();return aD=function(r){return typeof r!="object"||r===null?!1:n?e(r):I.call(r)===i},aD}var yR={exports:{}},nne;function $lt(){if(nne)return yR.exports;nne=1;var g=Object.prototype.toString,e=uBe();if(e){var I=Symbol.prototype.toString,i=/^Symbol\(.*\)$/,n=function(r){return typeof r.valueOf()!="symbol"?!1:i.test(I.call(r))};yR.exports=function(r){if(typeof r=="symbol")return!0;if(g.call(r)!=="[object Symbol]")return!1;try{return n(r)}catch{return!1}}}else yR.exports=function(r){return!1};return yR.exports}var sD,Cne;function qlt(){if(Cne)return sD;Cne=1;var g=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol",e=Ult(),I=LQ,i=jlt(),n=$lt(),C=function(A,s){if(typeof A>"u"||A===null)throw new TypeError("Cannot call method on "+A);if(typeof s!="string"||s!=="number"&&s!=="string")throw new TypeError('hint must be "string" or "number"');var a=s==="string"?["toString","valueOf"]:["valueOf","toString"],l,c,u;for(u=0;u1&&(arguments[1]===String?s="string":arguments[1]===Number&&(s="number"));var a;if(g&&(Symbol.toPrimitive?a=r(A,Symbol.toPrimitive):n(A)&&(a=Symbol.prototype.valueOf)),typeof a<"u"){var l=a.call(A,s);if(e(l))return l;throw new TypeError("unable to convert exotic object to primitive")}return s==="default"&&(i(A)||n(A))&&(s="string"),C(A,s==="default"?"number":s)},sD}var lD,rne;function ect(){if(rne)return lD;rne=1;var g=qlt();return lD=function(I){return arguments.length>1?g(I,arguments[1]):g(I)},lD}var bz=uC,jBe=sw(),$Be,qBe,yz,Zz;if(jBe){$Be=bz("Object.prototype.hasOwnProperty"),qBe=bz("RegExp.prototype.exec"),yz={};var cD=function(){throw yz};Zz={toString:cD,valueOf:cD},typeof Symbol.toPrimitive=="symbol"&&(Zz[Symbol.toPrimitive]=cD)}var tct=bz("Object.prototype.toString"),gct=Object.getOwnPropertyDescriptor,Ict="[object RegExp]",eve=jBe?function(e){if(!e||typeof e!="object")return!1;var I=gct(e,"lastIndex"),i=I&&$Be(I,"value");if(!i)return!1;try{qBe(e,Zz)}catch(n){return n===yz}}:function(e){return!e||typeof e!="object"&&typeof e!="function"?!1:tct(e)===Ict},uD,one;function ict(){if(one)return uD;one=1;var g=uC,e=Ng,I=eve,i=g("RegExp.prototype.exec"),n=e("%TypeError%");return uD=function(r){if(!I(r))throw new n("`regex` must be a RegExp");return function(A){return i(r,A)!==null}},uD}var nct=Ng,Cct=nct("%TypeError%"),rct=function(e,I){if(e==null)throw new Cct(I||"Cannot call method on "+e);return e},U0=rct,tve=Ng,oct=tve("%String%"),Act=tve("%TypeError%"),UQ=function(e){if(typeof e=="symbol")throw new Act("Cannot convert a Symbol value to a string");return oct(e)},act=U0,sct=UQ,lct=uC,Ane=lct("String.prototype.replace"),gve=/^\s$/.test("᠎"),cct=gve?/^[\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028\u2029\uFEFF]+/:/^[\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028\u2029\uFEFF]+/,uct=gve?/[\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028\u2029\uFEFF]+$/:/[\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028\u2029\uFEFF]+$/,Ive=function(){var e=sct(act(this));return Ane(Ane(e,cct,""),uct,"")},dct=Ive,ane="​",$m="᠎",ive=function(){return String.prototype.trim&&ane.trim()===ane&&$m.trim()===$m&&("_"+$m).trim()==="_"+$m&&($m+"_").trim()===$m+"_"?String.prototype.trim:dct},hct=xn,mct=ive,fct=function(){var e=mct();return hct(String.prototype,{trim:e},{trim:function(){return String.prototype.trim!==e}}),e},pct=ul,bct=xn,yct=U0,Zct=Ive,nve=ive,Gct=fct,Bct=pct(nve()),Cve=function(e){return yct(e),Bct(e)};bct(Cve,{getPolyfill:nve,implementation:Zct,shim:Gct});var rve=Cve,dD,sne;function vct(){if(sne)return dD;sne=1;var g=Ng,e=g("%Number%"),I=g("%RegExp%"),i=g("%TypeError%"),n=g("%parseInt%"),C=uC,r=ict(),o=C("String.prototype.slice"),A=r(/^0b[01]+$/i),s=r(/^0o[0-7]+$/i),a=r(/^[-+]0x[0-9a-f]+$/i),l=["…","​","￾"].join(""),c=new I("["+l+"]","g"),u=r(c),d=rve,h=dn();return dD=function m(f){if(h(f)!=="String")throw new i("Assertion failed: `argument` is not a String");if(A(f))return e(n(o(f,2),2));if(s(f))return e(n(o(f,2),8));if(u(f)||a(f))return NaN;var b=d(f);return b!==f?m(b):e(f)},dD}var ove=Ng,lne=ove("%TypeError%"),cne=ove("%Number%"),Sct=_Be(),wct=ect(),Vct=vct(),Rct=function(e){var I=Sct(e)?e:wct(e,cne);if(typeof I=="symbol")throw new lne("Cannot convert a Symbol value to a number");if(typeof I=="bigint")throw new lne("Conversion from 'BigInt' to 'number' is not allowed.");return typeof I=="string"?Vct(I):cne(I)},Wct=dn(),Xct=Math.floor,Hct=function(e){return Wct(e)==="BigInt"?e:Xct(e)},Tct=Ng,une=Hct,Nct=Tct("%TypeError%"),kct=function(e){if(typeof e!="number"&&typeof e!="bigint")throw new Nct("argument must be a Number or a BigInt");var I=e<0?-une(-e):une(e);return I===0?0:I},Yct=Rct,Kct=kct,xct=tk,Dct=WBe,Ave=function(e){var I=Yct(e);return xct(I)||I===0?0:Dct(I)?Kct(I):I},dne=OBe,Fct=Ave,ave=function(e){var I=Fct(e);return I<=0?0:I>dne?dne:I},hD,hne;function sve(){if(hne)return hD;hne=1;var g=Ng,e=g("%TypeError%"),I=aw,i=ave,n=dn();return hD=function(r){if(n(r)!=="Object")throw new e("Assertion failed: `obj` must be an Object");return i(I(r,"length"))},hD}var Ect=Ng,mne=Ect("%TypeError%"),Mct=OBe,zct=LBe(),Pct=UBe(),Jct=aw,Oct=QBe(),Lct=PQ(),_ct=sve(),fne=UQ,Uct=function g(e,I,i,n,C){var r;arguments.length>5&&(r=arguments[5]);for(var o=n,A=0;A0&&(c=Lct(l)),c){var u=_ct(l);o=g(e,l,u,o,C-1)}else{if(o>=Mct)throw new mne("index too large");Pct(e,fne(o),l),o+=1}}A+=1}return o},Qct=Ng,jct=Qct("%Object%"),$ct=U0,lve=function(e){return $ct(e),jct(e)},qct=JBe,eut=Uct,tut=aw,gut=Ave,Iut=ave,iut=lve,cve=function(){var e=iut(this),I=Iut(tut(e,"length")),i=1;arguments.length>0&&typeof arguments[0]<"u"&&(i=gut(arguments[0]));var n=qct(e,0);return eut(n,e,I,0,i),n},nut=cve,uve=function(){return Array.prototype.flat||nut},mD,pne;function Cut(){if(pne)return mD;pne=1;var g=cl,e=typeof Symbol=="function"&&typeof Symbol.unscopables=="symbol",I=e&&Array.prototype[Symbol.unscopables],i=TypeError;return mD=function(C){if(typeof C!="string"||!C)throw new i("method must be a non-empty string");if(!g(Array.prototype,C))throw new i("method must be on Array.prototype");e&&(I[C]=!0)},mD}var fD,bne;function rut(){if(bne)return fD;bne=1;var g=xn,e=Cut(),I=uve;return fD=function(){var n=I();return g(Array.prototype,{flat:n},{flat:function(){return Array.prototype.flat!==n}}),e("flat"),n},fD}var out=xn,Aut=ul,aut=cve,dve=uve,sut=dve(),lut=rut(),hve=Aut(sut);out(hve,{getPolyfill:dve,implementation:aut,shim:lut});var lw=hve,yne={}.hasOwnProperty,pD=Function.prototype.call,Q0=pD.bind?pD.bind(yne):function(g,e){return pD.call(yne,g,e)},cw={},Gz={exports:{}},Zne=function(g){return g!==g},mve=function(e,I){return e===0&&I===0?1/e===1/I:!!(e===I||Zne(e)&&Zne(I))},cut=mve,fve=function(){return typeof Object.is=="function"?Object.is:cut},uut=fve,dut=xn,hut=function(){var e=uut();return dut(Object,{is:e},{is:function(){return Object.is!==e}}),e},mut=xn,fut=ul,put=mve,pve=fve,but=hut,bve=fut(pve(),Object);mut(bve,{getPolyfill:pve,implementation:put,shim:but});var QQ=bve;(function(g,e){Object.defineProperty(e,"__esModule",{value:!0}),e.default=r;var I=n(QQ),i=n(Q0);function n(o){return o&&o.__esModule?o:{default:o}}function C(o){"@babel/helpers - typeof";return C=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(A){return typeof A}:function(A){return A&&typeof Symbol=="function"&&A.constructor===Symbol&&A!==Symbol.prototype?"symbol":typeof A},C(o)}function r(o,A){if((0,I.default)(o,A))return!0;if(!o||!A||C(o)!=="object"||C(A)!=="object")return!1;var s=Object.keys(o),a=Object.keys(A);if(s.length!==a.length)return!1;s.sort(),a.sort();for(var l=0;l"u"||typeof e=="object"))try{var I=bD(e);return(I===Jut||I===Put)&&e("")==null}catch{}return!1})}var Tve=function(){if(Hve(this)||!Eut(this)&&!Rve(this))throw new TypeError("Function.prototype.name sham getter called on non-function");if(Dut&&xut(this,"name"))return this.name;if(this===Out)return"";var e=Wve(this),I=Xve(e,Mut),i=I&&I[1];return i},_ut=Tve,Nve=function(){return _ut},Uut=xn.supportsDescriptors,Qut=Vve(),jut=Nve,Bne=Object.defineProperty,$ut=TypeError,qut=function(){var e=jut();if(Qut)return e;if(!Uut)throw new $ut("Shimming Function.prototype.name support requires ES5 property descriptor support.");var I=Function.prototype;return Bne(I,"name",{configurable:!0,enumerable:!1,get:function(){var i=e.call(this);return this!==I&&Bne(this,"name",{configurable:!0,enumerable:!1,value:i,writable:!1}),i}}),e},edt=xn,tdt=ul,kve=Tve,gdt=Nve,Idt=qut,Yve=tdt(kve);edt(Yve,{getPolyfill:gdt,implementation:kve,shim:Idt});var $Q=Yve,Kve={},xve={};Object.defineProperty(xve,"__esModule",{value:!0});var nk={},j0={},tH=Le&&Le.__assign||function(){return tH=Object.assign||function(g){for(var e,I=1,i=arguments.length;I0?this.children[this.children.length-1]:null},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"childNodes",{get:function(){return this.children},set:function(I){this.children=I},enumerable:!1,configurable:!0}),e}(qQ);fg.NodeWithChildren=rk;var Mve=function(g){yu(e,g);function e(){var I=g!==null&&g.apply(this,arguments)||this;return I.type=KC.ElementType.CDATA,I}return Object.defineProperty(e.prototype,"nodeType",{get:function(){return 4},enumerable:!1,configurable:!0}),e}(rk);fg.CDATA=Mve;var zve=function(g){yu(e,g);function e(){var I=g!==null&&g.apply(this,arguments)||this;return I.type=KC.ElementType.Root,I}return Object.defineProperty(e.prototype,"nodeType",{get:function(){return 9},enumerable:!1,configurable:!0}),e}(rk);fg.Document=zve;var Pve=function(g){yu(e,g);function e(I,i,n,C){n===void 0&&(n=[]),C===void 0&&(C=I==="script"?KC.ElementType.Script:I==="style"?KC.ElementType.Style:KC.ElementType.Tag);var r=g.call(this,n)||this;return r.name=I,r.attribs=i,r.type=C,r}return Object.defineProperty(e.prototype,"nodeType",{get:function(){return 1},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"tagName",{get:function(){return this.name},set:function(I){this.name=I},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"attributes",{get:function(){var I=this;return Object.keys(this.attribs).map(function(i){var n,C;return{name:i,value:I.attribs[i],namespace:(n=I["x-attribsNamespace"])===null||n===void 0?void 0:n[i],prefix:(C=I["x-attribsPrefix"])===null||C===void 0?void 0:C[i]}})},enumerable:!1,configurable:!0}),e}(rk);fg.Element=Pve;function Jve(g){return(0,KC.isTag)(g)}fg.isTag=Jve;function Ove(g){return g.type===KC.ElementType.CDATA}fg.isCDATA=Ove;function Lve(g){return g.type===KC.ElementType.Text}fg.isText=Lve;function _ve(g){return g.type===KC.ElementType.Comment}fg.isComment=_ve;function Uve(g){return g.type===KC.ElementType.Directive}fg.isDirective=Uve;function Qve(g){return g.type===KC.ElementType.Root}fg.isDocument=Qve;function Cdt(g){return Object.prototype.hasOwnProperty.call(g,"children")}fg.hasChildren=Cdt;function ej(g,e){e===void 0&&(e=!1);var I;if(Lve(g))I=new Dve(g.data);else if(_ve(g))I=new Fve(g.data);else if(Jve(g)){var i=e?yD(g.children):[],n=new Pve(g.name,rB({},g.attribs),i);i.forEach(function(A){return A.parent=n}),g.namespace!=null&&(n.namespace=g.namespace),g["x-attribsNamespace"]&&(n["x-attribsNamespace"]=rB({},g["x-attribsNamespace"])),g["x-attribsPrefix"]&&(n["x-attribsPrefix"]=rB({},g["x-attribsPrefix"])),I=n}else if(Ove(g)){var i=e?yD(g.children):[],C=new Mve(i);i.forEach(function(s){return s.parent=C}),I=C}else if(Qve(g)){var i=e?yD(g.children):[],r=new zve(i);i.forEach(function(s){return s.parent=r}),g["x-mode"]&&(r["x-mode"]=g["x-mode"]),I=r}else if(Uve(g)){var o=new Eve(g.name,g.data);g["x-name"]!=null&&(o["x-name"]=g["x-name"],o["x-publicId"]=g["x-publicId"],o["x-systemId"]=g["x-systemId"]),I=o}else throw new Error("Not implemented yet: ".concat(g.type));return I.startIndex=g.startIndex,I.endIndex=g.endIndex,g.sourceCodeLocation!=null&&(I.sourceCodeLocation=g.sourceCodeLocation),I}fg.cloneNode=ej;function yD(g){for(var e=g.map(function(i){return ej(i,!0)}),I=1;I䀾mmaĀ;d׷׸䎓;䏜reve;䄞ƀeiy؇،ؐdil;䄢rc;䄜;䐓ot;䄠r;쀀𝔊;拙pf;쀀𝔾eater̀EFGLSTصلَٖٛ٦qualĀ;Lؾؿ扥ess;招ullEqual;执reater;檢ess;扷lantEqual;橾ilde;扳cr;쀀𝒢;扫ЀAacfiosuڅڋږڛڞڪھۊRDcy;䐪Āctڐڔek;䋇;䁞irc;䄤r;愌lbertSpace;愋ǰگ\0ڲf;愍izontalLine;攀Āctۃۅòکrok;䄦mpńېۘownHumðįqual;扏܀EJOacdfgmnostuۺ۾܃܇܎ܚܞܡܨ݄ݸދޏޕcy;䐕lig;䄲cy;䐁cute耻Í䃍Āiyܓܘrc耻Î䃎;䐘ot;䄰r;愑rave耻Ì䃌ƀ;apܠܯܿĀcgܴܷr;䄪inaryI;慈lieóϝǴ݉\0ݢĀ;eݍݎ戬Āgrݓݘral;戫section;拂isibleĀCTݬݲomma;恣imes;恢ƀgptݿރވon;䄮f;쀀𝕀a;䎙cr;愐ilde;䄨ǫޚ\0ޞcy;䐆l耻Ï䃏ʀcfosuެ޷޼߂ߐĀiyޱ޵rc;䄴;䐙r;쀀𝔍pf;쀀𝕁ǣ߇\0ߌr;쀀𝒥rcy;䐈kcy;䐄΀HJacfosߤߨ߽߬߱ࠂࠈcy;䐥cy;䐌ppa;䎚Āey߶߻dil;䄶;䐚r;쀀𝔎pf;쀀𝕂cr;쀀𝒦րJTaceflmostࠥࠩࠬࡐࡣ঳সে্਷ੇcy;䐉耻<䀼ʀcmnpr࠷࠼ࡁࡄࡍute;䄹bda;䎛g;柪lacetrf;愒r;憞ƀaeyࡗ࡜ࡡron;䄽dil;䄻;䐛Āfsࡨ॰tԀACDFRTUVarࡾࢩࢱࣦ࣠ࣼयज़ΐ४Ānrࢃ࢏gleBracket;柨rowƀ;BR࢙࢚࢞憐ar;懤ightArrow;懆eiling;挈oǵࢷ\0ࣃbleBracket;柦nǔࣈ\0࣒eeVector;楡ectorĀ;Bࣛࣜ懃ar;楙loor;挊ightĀAV࣯ࣵrrow;憔ector;楎Āerँगeƀ;AVउऊऐ抣rrow;憤ector;楚iangleƀ;BEतथऩ抲ar;槏qual;抴pƀDTVषूौownVector;楑eeVector;楠ectorĀ;Bॖॗ憿ar;楘ectorĀ;B॥०憼ar;楒ightáΜs̀EFGLSTॾঋকঝঢভqualGreater;拚ullEqual;扦reater;扶ess;檡lantEqual;橽ilde;扲r;쀀𝔏Ā;eঽা拘ftarrow;懚idot;䄿ƀnpw৔ਖਛgȀLRlr৞৷ਂਐeftĀAR০৬rrow;柵ightArrow;柷ightArrow;柶eftĀarγਊightáοightáϊf;쀀𝕃erĀLRਢਬeftArrow;憙ightArrow;憘ƀchtਾੀੂòࡌ;憰rok;䅁;扪Ѐacefiosuਗ਼੝੠੷੼અઋ઎p;椅y;䐜Ādl੥੯iumSpace;恟lintrf;愳r;쀀𝔐nusPlus;戓pf;쀀𝕄cò੶;䎜ҀJacefostuણધભીଔଙඑ඗ඞcy;䐊cute;䅃ƀaey઴હાron;䅇dil;䅅;䐝ƀgswે૰଎ativeƀMTV૓૟૨ediumSpace;怋hiĀcn૦૘ë૙eryThiî૙tedĀGL૸ଆreaterGreateòٳessLesóੈLine;䀊r;쀀𝔑ȀBnptଢନଷ଺reak;恠BreakingSpace;䂠f;愕ڀ;CDEGHLNPRSTV୕ୖ୪୼஡௫ఄ౞಄ದ೘ൡඅ櫬Āou୛୤ngruent;扢pCap;扭oubleVerticalBar;戦ƀlqxஃஊ஛ement;戉ualĀ;Tஒஓ扠ilde;쀀≂̸ists;戄reater΀;EFGLSTஶஷ஽௉௓௘௥扯qual;扱ullEqual;쀀≧̸reater;쀀≫̸ess;批lantEqual;쀀⩾̸ilde;扵umpń௲௽ownHump;쀀≎̸qual;쀀≏̸eĀfsఊధtTriangleƀ;BEచఛడ拪ar;쀀⧏̸qual;括s̀;EGLSTవశ఼ౄోౘ扮qual;扰reater;扸ess;쀀≪̸lantEqual;쀀⩽̸ilde;扴estedĀGL౨౹reaterGreater;쀀⪢̸essLess;쀀⪡̸recedesƀ;ESಒಓಛ技qual;쀀⪯̸lantEqual;拠ĀeiಫಹverseElement;戌ghtTriangleƀ;BEೋೌ೒拫ar;쀀⧐̸qual;拭ĀquೝഌuareSuĀbp೨೹setĀ;E೰ೳ쀀⊏̸qual;拢ersetĀ;Eഃആ쀀⊐̸qual;拣ƀbcpഓതൎsetĀ;Eഛഞ쀀⊂⃒qual;抈ceedsȀ;ESTലള഻െ抁qual;쀀⪰̸lantEqual;拡ilde;쀀≿̸ersetĀ;E൘൛쀀⊃⃒qual;抉ildeȀ;EFT൮൯൵ൿ扁qual;扄ullEqual;扇ilde;扉erticalBar;戤cr;쀀𝒩ilde耻Ñ䃑;䎝܀Eacdfgmoprstuvලෂ෉෕ෛ෠෧෼ขภยา฿ไlig;䅒cute耻Ó䃓Āiy෎ීrc耻Ô䃔;䐞blac;䅐r;쀀𝔒rave耻Ò䃒ƀaei෮ෲ෶cr;䅌ga;䎩cron;䎟pf;쀀𝕆enCurlyĀDQฎบoubleQuote;怜uote;怘;橔Āclวฬr;쀀𝒪ash耻Ø䃘iŬื฼de耻Õ䃕es;樷ml耻Ö䃖erĀBP๋๠Āar๐๓r;怾acĀek๚๜;揞et;掴arenthesis;揜Ҁacfhilors๿ງຊຏຒດຝະ໼rtialD;戂y;䐟r;쀀𝔓i;䎦;䎠usMinus;䂱Āipຢອncareplanåڝf;愙Ȁ;eio຺ູ໠໤檻cedesȀ;EST່້໏໚扺qual;檯lantEqual;扼ilde;找me;怳Ādp໩໮uct;戏ortionĀ;aȥ໹l;戝Āci༁༆r;쀀𝒫;䎨ȀUfos༑༖༛༟OT耻"䀢r;쀀𝔔pf;愚cr;쀀𝒬؀BEacefhiorsu༾གྷཇའཱིྦྷྪྭ႖ႩႴႾarr;椐G耻®䂮ƀcnrཎནབute;䅔g;柫rĀ;tཛྷཝ憠l;椖ƀaeyཧཬཱron;䅘dil;䅖;䐠Ā;vླྀཹ愜erseĀEUྂྙĀlq྇ྎement;戋uilibrium;懋pEquilibrium;楯r»ཹo;䎡ghtЀACDFTUVa࿁࿫࿳ဢဨၛႇϘĀnr࿆࿒gleBracket;柩rowƀ;BL࿜࿝࿡憒ar;懥eftArrow;懄eiling;按oǵ࿹\0စbleBracket;柧nǔည\0နeeVector;楝ectorĀ;Bဝသ懂ar;楕loor;挋Āerိ၃eƀ;AVဵံြ抢rrow;憦ector;楛iangleƀ;BEၐၑၕ抳ar;槐qual;抵pƀDTVၣၮၸownVector;楏eeVector;楜ectorĀ;Bႂႃ憾ar;楔ectorĀ;B႑႒懀ar;楓Āpuႛ႞f;愝ndImplies;楰ightarrow;懛ĀchႹႼr;愛;憱leDelayed;槴ڀHOacfhimoqstuფჱჷჽᄙᄞᅑᅖᅡᅧᆵᆻᆿĀCcჩხHcy;䐩y;䐨FTcy;䐬cute;䅚ʀ;aeiyᄈᄉᄎᄓᄗ檼ron;䅠dil;䅞rc;䅜;䐡r;쀀𝔖ortȀDLRUᄪᄴᄾᅉownArrow»ОeftArrow»࢚ightArrow»࿝pArrow;憑gma;䎣allCircle;战pf;쀀𝕊ɲᅭ\0\0ᅰt;戚areȀ;ISUᅻᅼᆉᆯ斡ntersection;抓uĀbpᆏᆞsetĀ;Eᆗᆘ抏qual;抑ersetĀ;Eᆨᆩ抐qual;抒nion;抔cr;쀀𝒮ar;拆ȀbcmpᇈᇛሉላĀ;sᇍᇎ拐etĀ;Eᇍᇕqual;抆ĀchᇠህeedsȀ;ESTᇭᇮᇴᇿ扻qual;檰lantEqual;扽ilde;承Tháྌ;我ƀ;esሒሓሣ拑rsetĀ;Eሜም抃qual;抇et»ሓրHRSacfhiorsሾቄ቉ቕ቞ቱቶኟዂወዑORN耻Þ䃞ADE;愢ĀHc቎ቒcy;䐋y;䐦Ābuቚቜ;䀉;䎤ƀaeyብቪቯron;䅤dil;䅢;䐢r;쀀𝔗Āeiቻ኉Dzኀ\0ኇefore;戴a;䎘Ācn኎ኘkSpace;쀀  Space;怉ldeȀ;EFTካኬኲኼ戼qual;扃ullEqual;扅ilde;扈pf;쀀𝕋ipleDot;惛Āctዖዛr;쀀𝒯rok;䅦ૡዷጎጚጦ\0ጬጱ\0\0\0\0\0ጸጽ፷ᎅ\0᏿ᐄᐊᐐĀcrዻጁute耻Ú䃚rĀ;oጇገ憟cir;楉rǣጓ\0጖y;䐎ve;䅬Āiyጞጣrc耻Û䃛;䐣blac;䅰r;쀀𝔘rave耻Ù䃙acr;䅪Ādiፁ፩erĀBPፈ፝Āarፍፐr;䁟acĀekፗፙ;揟et;掵arenthesis;揝onĀ;P፰፱拃lus;抎Āgp፻፿on;䅲f;쀀𝕌ЀADETadps᎕ᎮᎸᏄϨᏒᏗᏳrrowƀ;BDᅐᎠᎤar;椒ownArrow;懅ownArrow;憕quilibrium;楮eeĀ;AᏋᏌ报rrow;憥ownáϳerĀLRᏞᏨeftArrow;憖ightArrow;憗iĀ;lᏹᏺ䏒on;䎥ing;䅮cr;쀀𝒰ilde;䅨ml耻Ü䃜ҀDbcdefosvᐧᐬᐰᐳᐾᒅᒊᒐᒖash;披ar;櫫y;䐒ashĀ;lᐻᐼ抩;櫦Āerᑃᑅ;拁ƀbtyᑌᑐᑺar;怖Ā;iᑏᑕcalȀBLSTᑡᑥᑪᑴar;戣ine;䁼eparator;杘ilde;所ThinSpace;怊r;쀀𝔙pf;쀀𝕍cr;쀀𝒱dash;抪ʀcefosᒧᒬᒱᒶᒼirc;䅴dge;拀r;쀀𝔚pf;쀀𝕎cr;쀀𝒲Ȁfiosᓋᓐᓒᓘr;쀀𝔛;䎞pf;쀀𝕏cr;쀀𝒳ҀAIUacfosuᓱᓵᓹᓽᔄᔏᔔᔚᔠcy;䐯cy;䐇cy;䐮cute耻Ý䃝Āiyᔉᔍrc;䅶;䐫r;쀀𝔜pf;쀀𝕐cr;쀀𝒴ml;䅸ЀHacdefosᔵᔹᔿᕋᕏᕝᕠᕤcy;䐖cute;䅹Āayᕄᕉron;䅽;䐗ot;䅻Dzᕔ\0ᕛoWidtè૙a;䎖r;愨pf;愤cr;쀀𝒵௡ᖃᖊᖐ\0ᖰᖶᖿ\0\0\0\0ᗆᗛᗫᙟ᙭\0ᚕ᚛ᚲᚹ\0ᚾcute耻á䃡reve;䄃̀;Ediuyᖜᖝᖡᖣᖨᖭ戾;쀀∾̳;房rc耻â䃢te肻´̆;䐰lig耻æ䃦Ā;r²ᖺ;쀀𝔞rave耻à䃠ĀepᗊᗖĀfpᗏᗔsym;愵èᗓha;䎱ĀapᗟcĀclᗤᗧr;䄁g;樿ɤᗰ\0\0ᘊʀ;adsvᗺᗻᗿᘁᘇ戧nd;橕;橜lope;橘;橚΀;elmrszᘘᘙᘛᘞᘿᙏᙙ戠;榤e»ᘙsdĀ;aᘥᘦ戡ѡᘰᘲᘴᘶᘸᘺᘼᘾ;榨;榩;榪;榫;榬;榭;榮;榯tĀ;vᙅᙆ戟bĀ;dᙌᙍ抾;榝Āptᙔᙗh;戢»¹arr;捼Āgpᙣᙧon;䄅f;쀀𝕒΀;Eaeiop዁ᙻᙽᚂᚄᚇᚊ;橰cir;橯;扊d;手s;䀧roxĀ;e዁ᚒñᚃing耻å䃥ƀctyᚡᚦᚨr;쀀𝒶;䀪mpĀ;e዁ᚯñʈilde耻ã䃣ml耻ä䃤Āciᛂᛈoninôɲnt;樑ࠀNabcdefiklnoprsu᛭ᛱᜰ᜼ᝃᝈ᝸᝽០៦ᠹᡐᜍ᤽᥈ᥰot;櫭Ācrᛶ᜞kȀcepsᜀᜅᜍᜓong;扌psilon;䏶rime;怵imĀ;e᜚᜛戽q;拍Ŷᜢᜦee;抽edĀ;gᜬᜭ挅e»ᜭrkĀ;t፜᜷brk;掶Āoyᜁᝁ;䐱quo;怞ʀcmprtᝓ᝛ᝡᝤᝨausĀ;eĊĉptyv;榰séᜌnoõēƀahwᝯ᝱ᝳ;䎲;愶een;扬r;쀀𝔟g΀costuvwឍឝឳេ៕៛៞ƀaiuបពរðݠrc;旯p»፱ƀdptឤឨឭot;樀lus;樁imes;樂ɱឹ\0\0ើcup;樆ar;昅riangleĀdu៍្own;施p;斳plus;樄eåᑄåᒭarow;植ƀako៭ᠦᠵĀcn៲ᠣkƀlst៺֫᠂ozenge;槫riangleȀ;dlr᠒᠓᠘᠝斴own;斾eft;旂ight;斸k;搣Ʊᠫ\0ᠳƲᠯ\0ᠱ;斒;斑4;斓ck;斈ĀeoᠾᡍĀ;qᡃᡆ쀀=⃥uiv;쀀≡⃥t;挐Ȁptwxᡙᡞᡧᡬf;쀀𝕓Ā;tᏋᡣom»Ꮜtie;拈؀DHUVbdhmptuvᢅᢖᢪᢻᣗᣛᣬ᣿ᤅᤊᤐᤡȀLRlrᢎᢐᢒᢔ;敗;敔;敖;敓ʀ;DUduᢡᢢᢤᢦᢨ敐;敦;敩;敤;敧ȀLRlrᢳᢵᢷᢹ;敝;敚;敜;教΀;HLRhlrᣊᣋᣍᣏᣑᣓᣕ救;敬;散;敠;敫;敢;敟ox;槉ȀLRlrᣤᣦᣨᣪ;敕;敒;攐;攌ʀ;DUduڽ᣷᣹᣻᣽;敥;敨;攬;攴inus;抟lus;択imes;抠ȀLRlrᤙᤛᤝ᤟;敛;敘;攘;攔΀;HLRhlrᤰᤱᤳᤵᤷ᤻᤹攂;敪;敡;敞;攼;攤;攜Āevģ᥂bar耻¦䂦Ȁceioᥑᥖᥚᥠr;쀀𝒷mi;恏mĀ;e᜚᜜lƀ;bhᥨᥩᥫ䁜;槅sub;柈Ŭᥴ᥾lĀ;e᥹᥺怢t»᥺pƀ;Eeįᦅᦇ;檮Ā;qۜۛೡᦧ\0᧨ᨑᨕᨲ\0ᨷᩐ\0\0᪴\0\0᫁\0\0ᬡᬮ᭍᭒\0᯽\0ᰌƀcpr᦭ᦲ᧝ute;䄇̀;abcdsᦿᧀᧄ᧊᧕᧙戩nd;橄rcup;橉Āau᧏᧒p;橋p;橇ot;橀;쀀∩︀Āeo᧢᧥t;恁îړȀaeiu᧰᧻ᨁᨅǰ᧵\0᧸s;橍on;䄍dil耻ç䃧rc;䄉psĀ;sᨌᨍ橌m;橐ot;䄋ƀdmnᨛᨠᨦil肻¸ƭptyv;榲t脀¢;eᨭᨮ䂢räƲr;쀀𝔠ƀceiᨽᩀᩍy;䑇ckĀ;mᩇᩈ朓ark»ᩈ;䏇r΀;Ecefms᩟᩠ᩢᩫ᪤᪪᪮旋;槃ƀ;elᩩᩪᩭ䋆q;扗eɡᩴ\0\0᪈rrowĀlr᩼᪁eft;憺ight;憻ʀRSacd᪒᪔᪖᪚᪟»ཇ;擈st;抛irc;抚ash;抝nint;樐id;櫯cir;槂ubsĀ;u᪻᪼晣it»᪼ˬ᫇᫔᫺\0ᬊonĀ;eᫍᫎ䀺Ā;qÇÆɭ᫙\0\0᫢aĀ;t᫞᫟䀬;䁀ƀ;fl᫨᫩᫫戁îᅠeĀmx᫱᫶ent»᫩eóɍǧ᫾\0ᬇĀ;dኻᬂot;橭nôɆƀfryᬐᬔᬗ;쀀𝕔oäɔ脀©;sŕᬝr;愗Āaoᬥᬩrr;憵ss;朗Ācuᬲᬷr;쀀𝒸Ābpᬼ᭄Ā;eᭁᭂ櫏;櫑Ā;eᭉᭊ櫐;櫒dot;拯΀delprvw᭠᭬᭷ᮂᮬᯔ᯹arrĀlr᭨᭪;椸;椵ɰ᭲\0\0᭵r;拞c;拟arrĀ;p᭿ᮀ憶;椽̀;bcdosᮏᮐᮖᮡᮥᮨ截rcap;橈Āauᮛᮞp;橆p;橊ot;抍r;橅;쀀∪︀Ȁalrv᮵ᮿᯞᯣrrĀ;mᮼᮽ憷;椼yƀevwᯇᯔᯘqɰᯎ\0\0ᯒreã᭳uã᭵ee;拎edge;拏en耻¤䂤earrowĀlrᯮ᯳eft»ᮀight»ᮽeäᯝĀciᰁᰇoninôǷnt;戱lcty;挭ঀAHabcdefhijlorstuwz᰸᰻᰿ᱝᱩᱵᲊᲞᲬᲷ᳻᳿ᴍᵻᶑᶫᶻ᷆᷍rò΁ar;楥Ȁglrs᱈ᱍ᱒᱔ger;怠eth;愸òᄳhĀ;vᱚᱛ怐»ऊūᱡᱧarow;椏aã̕Āayᱮᱳron;䄏;䐴ƀ;ao̲ᱼᲄĀgrʿᲁr;懊tseq;橷ƀglmᲑᲔᲘ耻°䂰ta;䎴ptyv;榱ĀirᲣᲨsht;楿;쀀𝔡arĀlrᲳᲵ»ࣜ»သʀaegsv᳂͸᳖᳜᳠mƀ;oș᳊᳔ndĀ;ș᳑uit;晦amma;䏝in;拲ƀ;io᳧᳨᳸䃷de脀÷;o᳧ᳰntimes;拇nø᳷cy;䑒cɯᴆ\0\0ᴊrn;挞op;挍ʀlptuwᴘᴝᴢᵉᵕlar;䀤f;쀀𝕕ʀ;emps̋ᴭᴷᴽᵂqĀ;d͒ᴳot;扑inus;戸lus;戔quare;抡blebarwedgåúnƀadhᄮᵝᵧownarrowóᲃarpoonĀlrᵲᵶefôᲴighôᲶŢᵿᶅkaro÷གɯᶊ\0\0ᶎrn;挟op;挌ƀcotᶘᶣᶦĀryᶝᶡ;쀀𝒹;䑕l;槶rok;䄑Ādrᶰᶴot;拱iĀ;fᶺ᠖斿Āah᷀᷃ròЩaòྦangle;榦Āci᷒ᷕy;䑟grarr;柿ऀDacdefglmnopqrstuxḁḉḙḸոḼṉṡṾấắẽỡἪἷὄ὎὚ĀDoḆᴴoôᲉĀcsḎḔute耻é䃩ter;橮ȀaioyḢḧḱḶron;䄛rĀ;cḭḮ扖耻ê䃪lon;払;䑍ot;䄗ĀDrṁṅot;扒;쀀𝔢ƀ;rsṐṑṗ檚ave耻è䃨Ā;dṜṝ檖ot;檘Ȁ;ilsṪṫṲṴ檙nters;揧;愓Ā;dṹṺ檕ot;檗ƀapsẅẉẗcr;䄓tyƀ;svẒẓẕ戅et»ẓpĀ1;ẝẤijạả;怄;怅怃ĀgsẪẬ;䅋p;怂ĀgpẴẸon;䄙f;쀀𝕖ƀalsỄỎỒrĀ;sỊị拕l;槣us;橱iƀ;lvỚớở䎵on»ớ;䏵ȀcsuvỪỳἋἣĀioữḱrc»Ḯɩỹ\0\0ỻíՈantĀglἂἆtr»ṝess»Ṻƀaeiἒ἖Ἒls;䀽st;扟vĀ;DȵἠD;橸parsl;槥ĀDaἯἳot;打rr;楱ƀcdiἾὁỸr;愯oô͒ĀahὉὋ;䎷耻ð䃰Āmrὓὗl耻ë䃫o;悬ƀcipὡὤὧl;䀡sôծĀeoὬὴctatioîՙnentialåչৡᾒ\0ᾞ\0ᾡᾧ\0\0ῆῌ\0ΐ\0ῦῪ \0 ⁚llingdotseñṄy;䑄male;晀ƀilrᾭᾳ῁lig;耀ffiɩᾹ\0\0᾽g;耀ffig;耀ffl;쀀𝔣lig;耀filig;쀀fjƀaltῙ῜ῡt;晭ig;耀flns;斱of;䆒ǰ΅\0ῳf;쀀𝕗ĀakֿῷĀ;vῼ´拔;櫙artint;樍Āao‌⁕Ācs‑⁒ႉ‸⁅⁈\0⁐β•‥‧‪‬\0‮耻½䂽;慓耻¼䂼;慕;慙;慛Ƴ‴\0‶;慔;慖ʴ‾⁁\0\0⁃耻¾䂾;慗;慜5;慘ƶ⁌\0⁎;慚;慝8;慞l;恄wn;挢cr;쀀𝒻ࢀEabcdefgijlnorstv₂₉₟₥₰₴⃰⃵⃺⃿℃ℒℸ̗ℾ⅒↞Ā;lٍ₇;檌ƀcmpₐₕ₝ute;䇵maĀ;dₜ᳚䎳;檆reve;䄟Āiy₪₮rc;䄝;䐳ot;䄡Ȁ;lqsؾق₽⃉ƀ;qsؾٌ⃄lanô٥Ȁ;cdl٥⃒⃥⃕c;檩otĀ;o⃜⃝檀Ā;l⃢⃣檂;檄Ā;e⃪⃭쀀⋛︀s;檔r;쀀𝔤Ā;gٳ؛mel;愷cy;䑓Ȁ;Eajٚℌℎℐ;檒;檥;檤ȀEaesℛℝ℩ℴ;扩pĀ;p℣ℤ檊rox»ℤĀ;q℮ℯ檈Ā;q℮ℛim;拧pf;쀀𝕘Āci⅃ⅆr;愊mƀ;el٫ⅎ⅐;檎;檐茀>;cdlqr׮ⅠⅪⅮⅳⅹĀciⅥⅧ;檧r;橺ot;拗Par;榕uest;橼ʀadelsↄⅪ←ٖ↛ǰ↉\0↎proø₞r;楸qĀlqؿ↖lesó₈ií٫Āen↣↭rtneqq;쀀≩︀Å↪ԀAabcefkosy⇄⇇⇱⇵⇺∘∝∯≨≽ròΠȀilmr⇐⇔⇗⇛rsðᒄf»․ilôکĀdr⇠⇤cy;䑊ƀ;cwࣴ⇫⇯ir;楈;憭ar;意irc;䄥ƀalr∁∎∓rtsĀ;u∉∊晥it»∊lip;怦con;抹r;쀀𝔥sĀew∣∩arow;椥arow;椦ʀamopr∺∾≃≞≣rr;懿tht;戻kĀlr≉≓eftarrow;憩ightarrow;憪f;쀀𝕙bar;怕ƀclt≯≴≸r;쀀𝒽asè⇴rok;䄧Ābp⊂⊇ull;恃hen»ᱛૡ⊣\0⊪\0⊸⋅⋎\0⋕⋳\0\0⋸⌢⍧⍢⍿\0⎆⎪⎴cute耻í䃭ƀ;iyݱ⊰⊵rc耻î䃮;䐸Ācx⊼⊿y;䐵cl耻¡䂡ĀfrΟ⋉;쀀𝔦rave耻ì䃬Ȁ;inoܾ⋝⋩⋮Āin⋢⋦nt;樌t;戭fin;槜ta;愩lig;䄳ƀaop⋾⌚⌝ƀcgt⌅⌈⌗r;䄫ƀelpܟ⌏⌓inåގarôܠh;䄱f;抷ed;䆵ʀ;cfotӴ⌬⌱⌽⍁are;愅inĀ;t⌸⌹戞ie;槝doô⌙ʀ;celpݗ⍌⍐⍛⍡al;抺Āgr⍕⍙eróᕣã⍍arhk;樗rod;樼Ȁcgpt⍯⍲⍶⍻y;䑑on;䄯f;쀀𝕚a;䎹uest耻¿䂿Āci⎊⎏r;쀀𝒾nʀ;EdsvӴ⎛⎝⎡ӳ;拹ot;拵Ā;v⎦⎧拴;拳Ā;iݷ⎮lde;䄩ǫ⎸\0⎼cy;䑖l耻ï䃯̀cfmosu⏌⏗⏜⏡⏧⏵Āiy⏑⏕rc;䄵;䐹r;쀀𝔧ath;䈷pf;쀀𝕛ǣ⏬\0⏱r;쀀𝒿rcy;䑘kcy;䑔Ѐacfghjos␋␖␢␧␭␱␵␻ppaĀ;v␓␔䎺;䏰Āey␛␠dil;䄷;䐺r;쀀𝔨reen;䄸cy;䑅cy;䑜pf;쀀𝕜cr;쀀𝓀஀ABEHabcdefghjlmnoprstuv⑰⒁⒆⒍⒑┎┽╚▀♎♞♥♹♽⚚⚲⛘❝❨➋⟀⠁⠒ƀart⑷⑺⑼rò৆òΕail;椛arr;椎Ā;gঔ⒋;檋ar;楢ॣ⒥\0⒪\0⒱\0\0\0\0\0⒵Ⓔ\0ⓆⓈⓍ\0⓹ute;䄺mptyv;榴raîࡌbda;䎻gƀ;dlࢎⓁⓃ;榑åࢎ;檅uo耻«䂫rЀ;bfhlpst࢙ⓞⓦⓩ⓫⓮⓱⓵Ā;f࢝ⓣs;椟s;椝ë≒p;憫l;椹im;楳l;憢ƀ;ae⓿─┄檫il;椙Ā;s┉┊檭;쀀⪭︀ƀabr┕┙┝rr;椌rk;杲Āak┢┬cĀek┨┪;䁻;䁛Āes┱┳;榋lĀdu┹┻;榏;榍Ȁaeuy╆╋╖╘ron;䄾Ādi═╔il;䄼ìࢰâ┩;䐻Ȁcqrs╣╦╭╽a;椶uoĀ;rนᝆĀdu╲╷har;楧shar;楋h;憲ʀ;fgqs▋▌উ◳◿扤tʀahlrt▘▤▷◂◨rrowĀ;t࢙□aé⓶arpoonĀdu▯▴own»њp»०eftarrows;懇ightƀahs◍◖◞rrowĀ;sࣴࢧarpoonó྘quigarro÷⇰hreetimes;拋ƀ;qs▋ও◺lanôবʀ;cdgsব☊☍☝☨c;檨otĀ;o☔☕橿Ā;r☚☛檁;檃Ā;e☢☥쀀⋚︀s;檓ʀadegs☳☹☽♉♋pproøⓆot;拖qĀgq♃♅ôউgtò⒌ôছiíলƀilr♕࣡♚sht;楼;쀀𝔩Ā;Eজ♣;檑š♩♶rĀdu▲♮Ā;l॥♳;楪lk;斄cy;䑙ʀ;achtੈ⚈⚋⚑⚖rò◁orneòᴈard;楫ri;旺Āio⚟⚤dot;䅀ustĀ;a⚬⚭掰che»⚭ȀEaes⚻⚽⛉⛔;扨pĀ;p⛃⛄檉rox»⛄Ā;q⛎⛏檇Ā;q⛎⚻im;拦Ѐabnoptwz⛩⛴⛷✚✯❁❇❐Ānr⛮⛱g;柬r;懽rëࣁgƀlmr⛿✍✔eftĀar০✇ightá৲apsto;柼ightá৽parrowĀlr✥✩efô⓭ight;憬ƀafl✶✹✽r;榅;쀀𝕝us;樭imes;樴š❋❏st;戗áፎƀ;ef❗❘᠀旊nge»❘arĀ;l❤❥䀨t;榓ʀachmt❳❶❼➅➇ròࢨorneòᶌarĀ;d྘➃;業;怎ri;抿̀achiqt➘➝ੀ➢➮➻quo;怹r;쀀𝓁mƀ;egল➪➬;檍;檏Ābu┪➳oĀ;rฟ➹;怚rok;䅂萀<;cdhilqrࠫ⟒☹⟜⟠⟥⟪⟰Āci⟗⟙;檦r;橹reå◲mes;拉arr;楶uest;橻ĀPi⟵⟹ar;榖ƀ;ef⠀भ᠛旃rĀdu⠇⠍shar;楊har;楦Āen⠗⠡rtneqq;쀀≨︀Å⠞܀Dacdefhilnopsu⡀⡅⢂⢎⢓⢠⢥⢨⣚⣢⣤ઃ⣳⤂Dot;戺Ȁclpr⡎⡒⡣⡽r耻¯䂯Āet⡗⡙;時Ā;e⡞⡟朠se»⡟Ā;sျ⡨toȀ;dluျ⡳⡷⡻owîҌefôएðᏑker;斮Āoy⢇⢌mma;権;䐼ash;怔asuredangle»ᘦr;쀀𝔪o;愧ƀcdn⢯⢴⣉ro耻µ䂵Ȁ;acdᑤ⢽⣀⣄sôᚧir;櫰ot肻·Ƶusƀ;bd⣒ᤃ⣓戒Ā;uᴼ⣘;横ţ⣞⣡p;櫛ò−ðઁĀdp⣩⣮els;抧f;쀀𝕞Āct⣸⣽r;쀀𝓂pos»ᖝƀ;lm⤉⤊⤍䎼timap;抸ఀGLRVabcdefghijlmoprstuvw⥂⥓⥾⦉⦘⧚⧩⨕⨚⩘⩝⪃⪕⪤⪨⬄⬇⭄⭿⮮ⰴⱧⱼ⳩Āgt⥇⥋;쀀⋙̸Ā;v⥐௏쀀≫⃒ƀelt⥚⥲⥶ftĀar⥡⥧rrow;懍ightarrow;懎;쀀⋘̸Ā;v⥻ే쀀≪⃒ightarrow;懏ĀDd⦎⦓ash;抯ash;抮ʀbcnpt⦣⦧⦬⦱⧌la»˞ute;䅄g;쀀∠⃒ʀ;Eiop඄⦼⧀⧅⧈;쀀⩰̸d;쀀≋̸s;䅉roø඄urĀ;a⧓⧔普lĀ;s⧓ସdz⧟\0⧣p肻 ଷmpĀ;e௹ఀʀaeouy⧴⧾⨃⨐⨓ǰ⧹\0⧻;橃on;䅈dil;䅆ngĀ;dൾ⨊ot;쀀⩭̸p;橂;䐽ash;怓΀;Aadqsxஒ⨩⨭⨻⩁⩅⩐rr;懗rĀhr⨳⨶k;椤Ā;oᏲᏰot;쀀≐̸uiöୣĀei⩊⩎ar;椨í஘istĀ;s஠டr;쀀𝔫ȀEest௅⩦⩹⩼ƀ;qs஼⩭௡ƀ;qs஼௅⩴lanô௢ií௪Ā;rஶ⪁»ஷƀAap⪊⪍⪑rò⥱rr;憮ar;櫲ƀ;svྍ⪜ྌĀ;d⪡⪢拼;拺cy;䑚΀AEadest⪷⪺⪾⫂⫅⫶⫹rò⥦;쀀≦̸rr;憚r;急Ȁ;fqs఻⫎⫣⫯tĀar⫔⫙rro÷⫁ightarro÷⪐ƀ;qs఻⪺⫪lanôౕĀ;sౕ⫴»శiíౝĀ;rవ⫾iĀ;eచథiäඐĀpt⬌⬑f;쀀𝕟膀¬;in⬙⬚⬶䂬nȀ;Edvஉ⬤⬨⬮;쀀⋹̸ot;쀀⋵̸ǡஉ⬳⬵;拷;拶iĀ;vಸ⬼ǡಸ⭁⭃;拾;拽ƀaor⭋⭣⭩rȀ;ast୻⭕⭚⭟lleì୻l;쀀⫽⃥;쀀∂̸lint;樔ƀ;ceಒ⭰⭳uåಥĀ;cಘ⭸Ā;eಒ⭽ñಘȀAait⮈⮋⮝⮧rò⦈rrƀ;cw⮔⮕⮙憛;쀀⤳̸;쀀↝̸ghtarrow»⮕riĀ;eೋೖ΀chimpqu⮽⯍⯙⬄୸⯤⯯Ȁ;cerല⯆ഷ⯉uå൅;쀀𝓃ortɭ⬅\0\0⯖ará⭖mĀ;e൮⯟Ā;q൴൳suĀbp⯫⯭å೸åഋƀbcp⯶ⰑⰙȀ;Ees⯿ⰀഢⰄ抄;쀀⫅̸etĀ;eഛⰋqĀ;qണⰀcĀ;eലⰗñസȀ;EesⰢⰣൟⰧ抅;쀀⫆̸etĀ;e൘ⰮqĀ;qൠⰣȀgilrⰽⰿⱅⱇìௗlde耻ñ䃱çృiangleĀlrⱒⱜeftĀ;eచⱚñదightĀ;eೋⱥñ೗Ā;mⱬⱭ䎽ƀ;esⱴⱵⱹ䀣ro;愖p;怇ҀDHadgilrsⲏⲔⲙⲞⲣⲰⲶⳓⳣash;抭arr;椄p;쀀≍⃒ash;抬ĀetⲨⲬ;쀀≥⃒;쀀>⃒nfin;槞ƀAetⲽⳁⳅrr;椂;쀀≤⃒Ā;rⳊⳍ쀀<⃒ie;쀀⊴⃒ĀAtⳘⳜrr;椃rie;쀀⊵⃒im;쀀∼⃒ƀAan⳰⳴ⴂrr;懖rĀhr⳺⳽k;椣Ā;oᏧᏥear;椧ቓ᪕\0\0\0\0\0\0\0\0\0\0\0\0\0ⴭ\0ⴸⵈⵠⵥ⵲ⶄᬇ\0\0ⶍⶫ\0ⷈⷎ\0ⷜ⸙⸫⸾⹃Ācsⴱ᪗ute耻ó䃳ĀiyⴼⵅrĀ;c᪞ⵂ耻ô䃴;䐾ʀabios᪠ⵒⵗLjⵚlac;䅑v;樸old;榼lig;䅓Ācr⵩⵭ir;榿;쀀𝔬ͯ⵹\0\0⵼\0ⶂn;䋛ave耻ò䃲;槁Ābmⶈ෴ar;榵Ȁacitⶕ⶘ⶥⶨrò᪀Āir⶝ⶠr;榾oss;榻nå๒;槀ƀaeiⶱⶵⶹcr;䅍ga;䏉ƀcdnⷀⷅǍron;䎿;榶pf;쀀𝕠ƀaelⷔ⷗ǒr;榷rp;榹΀;adiosvⷪⷫⷮ⸈⸍⸐⸖戨rò᪆Ȁ;efmⷷⷸ⸂⸅橝rĀ;oⷾⷿ愴f»ⷿ耻ª䂪耻º䂺gof;抶r;橖lope;橗;橛ƀclo⸟⸡⸧ò⸁ash耻ø䃸l;折iŬⸯ⸴de耻õ䃵esĀ;aǛ⸺s;樶ml耻ö䃶bar;挽ૡ⹞\0⹽\0⺀⺝\0⺢⺹\0\0⻋ຜ\0⼓\0\0⼫⾼\0⿈rȀ;astЃ⹧⹲຅脀¶;l⹭⹮䂶leìЃɩ⹸\0\0⹻m;櫳;櫽y;䐿rʀcimpt⺋⺏⺓ᡥ⺗nt;䀥od;䀮il;怰enk;怱r;쀀𝔭ƀimo⺨⺰⺴Ā;v⺭⺮䏆;䏕maô੶ne;明ƀ;tv⺿⻀⻈䏀chfork»´;䏖Āau⻏⻟nĀck⻕⻝kĀ;h⇴⻛;愎ö⇴sҀ;abcdemst⻳⻴ᤈ⻹⻽⼄⼆⼊⼎䀫cir;樣ir;樢Āouᵀ⼂;樥;橲n肻±ຝim;樦wo;樧ƀipu⼙⼠⼥ntint;樕f;쀀𝕡nd耻£䂣Ԁ;Eaceinosu່⼿⽁⽄⽇⾁⾉⾒⽾⾶;檳p;檷uå໙Ā;c໎⽌̀;acens່⽙⽟⽦⽨⽾pproø⽃urlyeñ໙ñ໎ƀaes⽯⽶⽺pprox;檹qq;檵im;拨iíໟmeĀ;s⾈ຮ怲ƀEas⽸⾐⽺ð⽵ƀdfp໬⾙⾯ƀals⾠⾥⾪lar;挮ine;挒urf;挓Ā;t໻⾴ï໻rel;抰Āci⿀⿅r;쀀𝓅;䏈ncsp;怈̀fiopsu⿚⋢⿟⿥⿫⿱r;쀀𝔮pf;쀀𝕢rime;恗cr;쀀𝓆ƀaeo⿸〉〓tĀei⿾々rnionóڰnt;樖stĀ;e【】䀿ñἙô༔઀ABHabcdefhilmnoprstux぀けさすムㄎㄫㅇㅢㅲㆎ㈆㈕㈤㈩㉘㉮㉲㊐㊰㊷ƀartぇおがròႳòϝail;検aròᱥar;楤΀cdenqrtとふへみわゔヌĀeuねぱ;쀀∽̱te;䅕iãᅮmptyv;榳gȀ;del࿑らるろ;榒;榥å࿑uo耻»䂻rր;abcfhlpstw࿜ガクシスゼゾダッデナp;極Ā;f࿠ゴs;椠;椳s;椞ë≝ð✮l;楅im;楴l;憣;憝Āaiパフil;椚oĀ;nホボ戶aló༞ƀabrョリヮrò៥rk;杳ĀakンヽcĀekヹ・;䁽;䁝Āes㄂㄄;榌lĀduㄊㄌ;榎;榐Ȁaeuyㄗㄜㄧㄩron;䅙Ādiㄡㄥil;䅗ì࿲âヺ;䑀Ȁclqsㄴㄷㄽㅄa;椷dhar;楩uoĀ;rȎȍh;憳ƀacgㅎㅟངlȀ;ipsླྀㅘㅛႜnåႻarôྩt;断ƀilrㅩဣㅮsht;楽;쀀𝔯ĀaoㅷㆆrĀduㅽㅿ»ѻĀ;l႑ㆄ;楬Ā;vㆋㆌ䏁;䏱ƀgns㆕ㇹㇼht̀ahlrstㆤㆰ㇂㇘㇤㇮rrowĀ;t࿜ㆭaéトarpoonĀduㆻㆿowîㅾp»႒eftĀah㇊㇐rrowó࿪arpoonóՑightarrows;應quigarro÷ニhreetimes;拌g;䋚ingdotseñἲƀahm㈍㈐㈓rò࿪aòՑ;怏oustĀ;a㈞㈟掱che»㈟mid;櫮Ȁabpt㈲㈽㉀㉒Ānr㈷㈺g;柭r;懾rëဃƀafl㉇㉊㉎r;榆;쀀𝕣us;樮imes;樵Āap㉝㉧rĀ;g㉣㉤䀩t;榔olint;樒arò㇣Ȁachq㉻㊀Ⴜ㊅quo;怺r;쀀𝓇Ābu・㊊oĀ;rȔȓƀhir㊗㊛㊠reåㇸmes;拊iȀ;efl㊪ၙᠡ㊫方tri;槎luhar;楨;愞ൡ㋕㋛㋟㌬㌸㍱\0㍺㎤\0\0㏬㏰\0㐨㑈㑚㒭㒱㓊㓱\0㘖\0\0㘳cute;䅛quï➺Ԁ;Eaceinpsyᇭ㋳㋵㋿㌂㌋㌏㌟㌦㌩;檴ǰ㋺\0㋼;檸on;䅡uåᇾĀ;dᇳ㌇il;䅟rc;䅝ƀEas㌖㌘㌛;檶p;檺im;择olint;樓iíሄ;䑁otƀ;be㌴ᵇ㌵担;橦΀Aacmstx㍆㍊㍗㍛㍞㍣㍭rr;懘rĀhr㍐㍒ë∨Ā;oਸ਼਴t耻§䂧i;䀻war;椩mĀin㍩ðnuóñt;朶rĀ;o㍶⁕쀀𝔰Ȁacoy㎂㎆㎑㎠rp;景Āhy㎋㎏cy;䑉;䑈rtɭ㎙\0\0㎜iäᑤaraì⹯耻­䂭Āgm㎨㎴maƀ;fv㎱㎲㎲䏃;䏂Ѐ;deglnprካ㏅㏉㏎㏖㏞㏡㏦ot;橪Ā;q኱ኰĀ;E㏓㏔檞;檠Ā;E㏛㏜檝;檟e;扆lus;樤arr;楲aròᄽȀaeit㏸㐈㐏㐗Āls㏽㐄lsetmé㍪hp;樳parsl;槤Ādlᑣ㐔e;挣Ā;e㐜㐝檪Ā;s㐢㐣檬;쀀⪬︀ƀflp㐮㐳㑂tcy;䑌Ā;b㐸㐹䀯Ā;a㐾㐿槄r;挿f;쀀𝕤aĀdr㑍ЂesĀ;u㑔㑕晠it»㑕ƀcsu㑠㑹㒟Āau㑥㑯pĀ;sᆈ㑫;쀀⊓︀pĀ;sᆴ㑵;쀀⊔︀uĀbp㑿㒏ƀ;esᆗᆜ㒆etĀ;eᆗ㒍ñᆝƀ;esᆨᆭ㒖etĀ;eᆨ㒝ñᆮƀ;afᅻ㒦ְrť㒫ֱ»ᅼaròᅈȀcemt㒹㒾㓂㓅r;쀀𝓈tmîñiì㐕aræᆾĀar㓎㓕rĀ;f㓔ឿ昆Āan㓚㓭ightĀep㓣㓪psiloîỠhé⺯s»⡒ʀbcmnp㓻㕞ሉ㖋㖎Ҁ;Edemnprs㔎㔏㔑㔕㔞㔣㔬㔱㔶抂;櫅ot;檽Ā;dᇚ㔚ot;櫃ult;櫁ĀEe㔨㔪;櫋;把lus;檿arr;楹ƀeiu㔽㕒㕕tƀ;en㔎㕅㕋qĀ;qᇚ㔏eqĀ;q㔫㔨m;櫇Ābp㕚㕜;櫕;櫓c̀;acensᇭ㕬㕲㕹㕻㌦pproø㋺urlyeñᇾñᇳƀaes㖂㖈㌛pproø㌚qñ㌗g;晪ڀ123;Edehlmnps㖩㖬㖯ሜ㖲㖴㗀㗉㗕㗚㗟㗨㗭耻¹䂹耻²䂲耻³䂳;櫆Āos㖹㖼t;檾ub;櫘Ā;dሢ㗅ot;櫄sĀou㗏㗒l;柉b;櫗arr;楻ult;櫂ĀEe㗤㗦;櫌;抋lus;櫀ƀeiu㗴㘉㘌tƀ;enሜ㗼㘂qĀ;qሢ㖲eqĀ;q㗧㗤m;櫈Ābp㘑㘓;櫔;櫖ƀAan㘜㘠㘭rr;懙rĀhr㘦㘨ë∮Ā;oਫ਩war;椪lig耻ß䃟௡㙑㙝㙠ዎ㙳㙹\0㙾㛂\0\0\0\0\0㛛㜃\0㜉㝬\0\0\0㞇ɲ㙖\0\0㙛get;挖;䏄rë๟ƀaey㙦㙫㙰ron;䅥dil;䅣;䑂lrec;挕r;쀀𝔱Ȁeiko㚆㚝㚵㚼Dz㚋\0㚑eĀ4fኄኁaƀ;sv㚘㚙㚛䎸ym;䏑Ācn㚢㚲kĀas㚨㚮pproø዁im»ኬsðኞĀas㚺㚮ð዁rn耻þ䃾Ǭ̟㛆⋧es膀×;bd㛏㛐㛘䃗Ā;aᤏ㛕r;樱;樰ƀeps㛡㛣㜀á⩍Ȁ;bcf҆㛬㛰㛴ot;挶ir;櫱Ā;o㛹㛼쀀𝕥rk;櫚á㍢rime;怴ƀaip㜏㜒㝤dåቈ΀adempst㜡㝍㝀㝑㝗㝜㝟ngleʀ;dlqr㜰㜱㜶㝀㝂斵own»ᶻeftĀ;e⠀㜾ñम;扜ightĀ;e㊪㝋ñၚot;旬inus;樺lus;樹b;槍ime;樻ezium;揢ƀcht㝲㝽㞁Āry㝷㝻;쀀𝓉;䑆cy;䑛rok;䅧Āio㞋㞎xô᝷headĀlr㞗㞠eftarro÷ࡏightarrow»ཝऀAHabcdfghlmoprstuw㟐㟓㟗㟤㟰㟼㠎㠜㠣㠴㡑㡝㡫㢩㣌㣒㣪㣶ròϭar;楣Ācr㟜㟢ute耻ú䃺òᅐrǣ㟪\0㟭y;䑞ve;䅭Āiy㟵㟺rc耻û䃻;䑃ƀabh㠃㠆㠋ròᎭlac;䅱aòᏃĀir㠓㠘sht;楾;쀀𝔲rave耻ù䃹š㠧㠱rĀlr㠬㠮»ॗ»ႃlk;斀Āct㠹㡍ɯ㠿\0\0㡊rnĀ;e㡅㡆挜r»㡆op;挏ri;旸Āal㡖㡚cr;䅫肻¨͉Āgp㡢㡦on;䅳f;쀀𝕦̀adhlsuᅋ㡸㡽፲㢑㢠ownáᎳarpoonĀlr㢈㢌efô㠭ighô㠯iƀ;hl㢙㢚㢜䏅»ᏺon»㢚parrows;懈ƀcit㢰㣄㣈ɯ㢶\0\0㣁rnĀ;e㢼㢽挝r»㢽op;挎ng;䅯ri;旹cr;쀀𝓊ƀdir㣙㣝㣢ot;拰lde;䅩iĀ;f㜰㣨»᠓Āam㣯㣲rò㢨l耻ü䃼angle;榧ހABDacdeflnoprsz㤜㤟㤩㤭㦵㦸㦽㧟㧤㧨㧳㧹㧽㨁㨠ròϷarĀ;v㤦㤧櫨;櫩asèϡĀnr㤲㤷grt;榜΀eknprst㓣㥆㥋㥒㥝㥤㦖appá␕othinçẖƀhir㓫⻈㥙opô⾵Ā;hᎷ㥢ïㆍĀiu㥩㥭gmá㎳Ābp㥲㦄setneqĀ;q㥽㦀쀀⊊︀;쀀⫋︀setneqĀ;q㦏㦒쀀⊋︀;쀀⫌︀Āhr㦛㦟etá㚜iangleĀlr㦪㦯eft»थight»ၑy;䐲ash»ံƀelr㧄㧒㧗ƀ;beⷪ㧋㧏ar;抻q;扚lip;拮Ābt㧜ᑨaòᑩr;쀀𝔳tré㦮suĀbp㧯㧱»ജ»൙pf;쀀𝕧roð໻tré㦴Ācu㨆㨋r;쀀𝓋Ābp㨐㨘nĀEe㦀㨖»㥾nĀEe㦒㨞»㦐igzag;榚΀cefoprs㨶㨻㩖㩛㩔㩡㩪irc;䅵Ādi㩀㩑Ābg㩅㩉ar;機eĀ;qᗺ㩏;扙erp;愘r;쀀𝔴pf;쀀𝕨Ā;eᑹ㩦atèᑹcr;쀀𝓌ૣណ㪇\0㪋\0㪐㪛\0\0㪝㪨㪫㪯\0\0㫃㫎\0㫘ៜ៟tré៑r;쀀𝔵ĀAa㪔㪗ròσrò৶;䎾ĀAa㪡㪤ròθrò৫að✓is;拻ƀdptឤ㪵㪾Āfl㪺ឩ;쀀𝕩imåឲĀAa㫇㫊ròώròਁĀcq㫒ីr;쀀𝓍Āpt៖㫜ré។Ѐacefiosu㫰㫽㬈㬌㬑㬕㬛㬡cĀuy㫶㫻te耻ý䃽;䑏Āiy㬂㬆rc;䅷;䑋n耻¥䂥r;쀀𝔶cy;䑗pf;쀀𝕪cr;쀀𝓎Ācm㬦㬩y;䑎l耻ÿ䃿Ԁacdefhiosw㭂㭈㭔㭘㭤㭩㭭㭴㭺㮀cute;䅺Āay㭍㭒ron;䅾;䐷ot;䅼Āet㭝㭡træᕟa;䎶r;쀀𝔷cy;䐶grarr;懝pf;쀀𝕫cr;쀀𝓏Ājn㮅㮇;怍j;怌'.split("").map(function(g){return g.charCodeAt(0)}));var gj={};Object.defineProperty(gj,"__esModule",{value:!0});gj.default=new Uint16Array("Ȁaglq \x1Bɭ\0\0p;䀦os;䀧t;䀾t;䀼uot;䀢".split("").map(function(g){return g.charCodeAt(0)}));var Bz={};(function(g){var e;Object.defineProperty(g,"__esModule",{value:!0}),g.replaceCodePoint=g.fromCodePoint=void 0;var I=new Map([[0,65533],[128,8364],[130,8218],[131,402],[132,8222],[133,8230],[134,8224],[135,8225],[136,710],[137,8240],[138,352],[139,8249],[140,338],[142,381],[145,8216],[146,8217],[147,8220],[148,8221],[149,8226],[150,8211],[151,8212],[152,732],[153,8482],[154,353],[155,8250],[156,339],[158,382],[159,376]]);g.fromCodePoint=(e=String.fromCodePoint)!==null&&e!==void 0?e:function(C){var r="";return C>65535&&(C-=65536,r+=String.fromCharCode(C>>>10&1023|55296),C=56320|C&1023),r+=String.fromCharCode(C),r};function i(C){var r;return C>=55296&&C<=57343||C>1114111?65533:(r=I.get(C))!==null&&r!==void 0?r:C}g.replaceCodePoint=i;function n(C){return(0,g.fromCodePoint)(i(C))}g.default=n})(Bz);(function(g){var e=Le&&Le.__createBinding||(Object.create?function(S,X,W,V){V===void 0&&(V=W);var H=Object.getOwnPropertyDescriptor(X,W);(!H||("get"in H?!X.__esModule:H.writable||H.configurable))&&(H={enumerable:!0,get:function(){return X[W]}}),Object.defineProperty(S,V,H)}:function(S,X,W,V){V===void 0&&(V=W),S[V]=X[W]}),I=Le&&Le.__setModuleDefault||(Object.create?function(S,X){Object.defineProperty(S,"default",{enumerable:!0,value:X})}:function(S,X){S.default=X}),i=Le&&Le.__importStar||function(S){if(S&&S.__esModule)return S;var X={};if(S!=null)for(var W in S)W!=="default"&&Object.prototype.hasOwnProperty.call(S,W)&&e(X,S,W);return I(X,S),X},n=Le&&Le.__importDefault||function(S){return S&&S.__esModule?S:{default:S}};Object.defineProperty(g,"__esModule",{value:!0}),g.decodeXML=g.decodeHTMLStrict=g.decodeHTMLAttribute=g.decodeHTML=g.determineBranch=g.EntityDecoder=g.DecodingMode=g.BinTrieFlags=g.fromCodePoint=g.replaceCodePoint=g.decodeCodePoint=g.xmlDecodeTree=g.htmlDecodeTree=void 0;var C=n(tj);g.htmlDecodeTree=C.default;var r=n(gj);g.xmlDecodeTree=r.default;var o=i(Bz);g.decodeCodePoint=o.default;var A=Bz;Object.defineProperty(g,"replaceCodePoint",{enumerable:!0,get:function(){return A.replaceCodePoint}}),Object.defineProperty(g,"fromCodePoint",{enumerable:!0,get:function(){return A.fromCodePoint}});var s;(function(S){S[S.NUM=35]="NUM",S[S.SEMI=59]="SEMI",S[S.EQUALS=61]="EQUALS",S[S.ZERO=48]="ZERO",S[S.NINE=57]="NINE",S[S.LOWER_A=97]="LOWER_A",S[S.LOWER_F=102]="LOWER_F",S[S.LOWER_X=120]="LOWER_X",S[S.LOWER_Z=122]="LOWER_Z",S[S.UPPER_A=65]="UPPER_A",S[S.UPPER_F=70]="UPPER_F",S[S.UPPER_Z=90]="UPPER_Z"})(s||(s={}));var a=32,l;(function(S){S[S.VALUE_LENGTH=49152]="VALUE_LENGTH",S[S.BRANCH_LENGTH=16256]="BRANCH_LENGTH",S[S.JUMP_TABLE=127]="JUMP_TABLE"})(l=g.BinTrieFlags||(g.BinTrieFlags={}));function c(S){return S>=s.ZERO&&S<=s.NINE}function u(S){return S>=s.UPPER_A&&S<=s.UPPER_F||S>=s.LOWER_A&&S<=s.LOWER_F}function d(S){return S>=s.UPPER_A&&S<=s.UPPER_Z||S>=s.LOWER_A&&S<=s.LOWER_Z||c(S)}function h(S){return S===s.EQUALS||d(S)}var m;(function(S){S[S.EntityStart=0]="EntityStart",S[S.NumericStart=1]="NumericStart",S[S.NumericDecimal=2]="NumericDecimal",S[S.NumericHex=3]="NumericHex",S[S.NamedEntity=4]="NamedEntity"})(m||(m={}));var f;(function(S){S[S.Legacy=0]="Legacy",S[S.Strict=1]="Strict",S[S.Attribute=2]="Attribute"})(f=g.DecodingMode||(g.DecodingMode={}));var b=function(){function S(X,W,V){this.decodeTree=X,this.emitCodePoint=W,this.errors=V,this.state=m.EntityStart,this.consumed=1,this.result=0,this.treeIndex=0,this.excess=1,this.decodeMode=f.Strict}return S.prototype.startEntity=function(X){this.decodeMode=X,this.state=m.EntityStart,this.result=0,this.treeIndex=0,this.excess=1,this.consumed=1},S.prototype.write=function(X,W){switch(this.state){case m.EntityStart:return X.charCodeAt(W)===s.NUM?(this.state=m.NumericStart,this.consumed+=1,this.stateNumericStart(X,W+1)):(this.state=m.NamedEntity,this.stateNamedEntity(X,W));case m.NumericStart:return this.stateNumericStart(X,W);case m.NumericDecimal:return this.stateNumericDecimal(X,W);case m.NumericHex:return this.stateNumericHex(X,W);case m.NamedEntity:return this.stateNamedEntity(X,W)}},S.prototype.stateNumericStart=function(X,W){return W>=X.length?-1:(X.charCodeAt(W)|a)===s.LOWER_X?(this.state=m.NumericHex,this.consumed+=1,this.stateNumericHex(X,W+1)):(this.state=m.NumericDecimal,this.stateNumericDecimal(X,W))},S.prototype.addToNumericResult=function(X,W,V,H){if(W!==V){var D=V-W;this.result=this.result*Math.pow(H,D)+parseInt(X.substr(W,D),H),this.consumed+=D}},S.prototype.stateNumericHex=function(X,W){for(var V=W;W>14;W>14,D!==0){if(Y===s.SEMI)return this.emitNamedEntityData(this.treeIndex,D,this.consumed+this.excess);this.decodeMode!==f.Strict&&(this.result=this.treeIndex,this.consumed+=this.excess,this.excess=0)}}return-1},S.prototype.emitNotTerminatedNamedEntity=function(){var X,W=this,V=W.result,H=W.decodeTree,D=(H[V]&l.VALUE_LENGTH)>>14;return this.emitNamedEntityData(V,D,this.consumed),(X=this.errors)===null||X===void 0||X.missingSemicolonAfterCharacterReference(),this.consumed},S.prototype.emitNamedEntityData=function(X,W,V){var H=this.decodeTree;return this.emitCodePoint(W===1?H[X]&~l.VALUE_LENGTH:H[X+1],V),W===3&&this.emitCodePoint(H[X+2],V),V},S.prototype.end=function(){var X;switch(this.state){case m.NamedEntity:return this.result!==0&&(this.decodeMode!==f.Attribute||this.result===this.treeIndex)?this.emitNotTerminatedNamedEntity():0;case m.NumericDecimal:return this.emitNumericEntity(0,2);case m.NumericHex:return this.emitNumericEntity(0,3);case m.NumericStart:return(X=this.errors)===null||X===void 0||X.absenceOfDigitsInNumericCharacterReference(this.consumed),0;case m.EntityStart:return 0}},S}();g.EntityDecoder=b;function p(S){var X="",W=new b(S,function(V){return X+=(0,o.fromCodePoint)(V)});return function(H,D){for(var Y=0,F=0;(F=H.indexOf("&",F))>=0;){X+=H.slice(Y,F),W.startEntity(D);var _=W.write(H,F+1);if(_<0){Y=F+W.end();break}Y=F+_,F=_===0?Y+1:Y}var J=X+H.slice(Y);return X="",J}}function y(S,X,W,V){var H=(X&l.BRANCH_LENGTH)>>7,D=X&l.JUMP_TABLE;if(H===0)return D!==0&&V===D?W:-1;if(D){var Y=V-D;return Y<0||Y>=H?-1:S[W+Y]-1}for(var F=W,_=F+H-1;F<=_;){var J=F+_>>>1,te=S[J];if(teV)_=J-1;else return S[J+H]}return-1}g.determineBranch=y;var Z=p(C.default),v=p(r.default);function G(S,X){return X===void 0&&(X=f.Legacy),Z(S,X)}g.decodeHTML=G;function B(S){return Z(S,f.Attribute)}g.decodeHTMLAttribute=B;function w(S){return Z(S,f.Strict)}g.decodeHTMLStrict=w;function R(S){return v(S,f.Strict)}g.decodeXML=R})(mh);var fh={},Ij={};Object.defineProperty(Ij,"__esModule",{value:!0});function ZR(g){for(var e=1;e$\x80-\uFFFF]/g;var e=new Map([[34,"""],[38,"&"],[39,"'"],[60,"<"],[62,">"]]);g.getCodePoint=String.prototype.codePointAt!=null?function(n,C){return n.codePointAt(C)}:function(n,C){return(n.charCodeAt(C)&64512)===55296?(n.charCodeAt(C)-55296)*1024+n.charCodeAt(C+1)-56320+65536:n.charCodeAt(C)};function I(n){for(var C="",r=0,o;(o=g.xmlReplacer.exec(n))!==null;){var A=o.index,s=n.charCodeAt(A),a=e.get(s);a!==void 0?(C+=n.substring(r,A)+a,r=A+1):(C+="".concat(n.substring(r,A),"&#x").concat((0,g.getCodePoint)(n,A).toString(16),";"),r=g.xmlReplacer.lastIndex+=+((s&64512)===55296))}return C+n.substr(r)}g.encodeXML=I,g.escape=I;function i(n,C){return function(o){for(var A,s=0,a="";A=n.exec(o);)s!==A.index&&(a+=o.substring(s,A.index)),a+=C.get(A[0].charCodeAt(0)),s=A.index+1;return a+o.substring(s)}}g.escapeUTF8=i(/[&<>'"]/g,e),g.escapeAttribute=i(/["&\u00A0]/g,new Map([[34,"""],[38,"&"],[160," "]])),g.escapeText=i(/[&<>\u00A0]/g,new Map([[38,"&"],[60,"<"],[62,">"],[160," "]]))})(_b);var rdt=Le&&Le.__importDefault||function(g){return g&&g.__esModule?g:{default:g}};Object.defineProperty(fh,"__esModule",{value:!0});fh.encodeNonAsciiHTML=fh.encodeHTML=void 0;var odt=rdt(Ij),$ve=_b,Adt=/[\t\n!-,./:-@[-`\f{-}$\x80-\uFFFF]/g;function adt(g){return qve(Adt,g)}fh.encodeHTML=adt;function sdt(g){return qve($ve.xmlReplacer,g)}fh.encodeNonAsciiHTML=sdt;function qve(g,e){for(var I="",i=0,n;(n=g.exec(e))!==null;){var C=n.index;I+=e.substring(i,C);var r=e.charCodeAt(C),o=odt.default.get(r);if(typeof o=="object"){if(C+10&&(i+=ok(g.children,e)),(e.xmlMode||!Sne.has(g.name))&&(i+=""))),i}function Zdt(g){return"<".concat(g.data,">")}function Gdt(g,e){var I,i=g.data||"";return((I=e.encodeEntities)!==null&&I!==void 0?I:e.decodeEntities)!==!1&&!(!e.xmlMode&&g.parent&&ddt.has(g.parent.name))&&(i=e.xmlMode||e.encodeEntities!=="utf8"?(0,gH.encodeXML)(i):(0,gH.escapeText)(i)),i}function Bdt(g){return"")}function vdt(g){return"")}var Sdt=Le&&Le.__importDefault||function(g){return g&&g.__esModule?g:{default:g}};Object.defineProperty(nr,"__esModule",{value:!0});nr.innerText=nr.textContent=nr.getText=nr.getInnerHTML=nr.getOuterHTML=void 0;var ba=Kn,wdt=Sdt(q0),Vdt=$0;function tSe(g,e){return(0,wdt.default)(g,e)}nr.getOuterHTML=tSe;function Rdt(g,e){return(0,ba.hasChildren)(g)?g.children.map(function(I){return tSe(I,e)}).join(""):""}nr.getInnerHTML=Rdt;function sW(g){return Array.isArray(g)?g.map(sW).join(""):(0,ba.isTag)(g)?g.name==="br"?` -`:sW(g.children):(0,ba.isCDATA)(g)?sW(g.children):(0,ba.isText)(g)?g.data:""}nr.getText=sW;function vz(g){return Array.isArray(g)?g.map(vz).join(""):(0,ba.hasChildren)(g)&&!(0,ba.isComment)(g)?vz(g.children):(0,ba.isText)(g)?g.data:""}nr.textContent=vz;function Sz(g){return Array.isArray(g)?g.map(Sz).join(""):(0,ba.hasChildren)(g)&&(g.type===Vdt.ElementType.Tag||(0,ba.isCDATA)(g))?Sz(g.children):(0,ba.isText)(g)?g.data:""}nr.innerText=Sz;var zi={};Object.defineProperty(zi,"__esModule",{value:!0});zi.prevElementSibling=zi.nextElementSibling=zi.getName=zi.hasAttrib=zi.getAttributeValue=zi.getSiblings=zi.getParent=zi.getChildren=void 0;var ij=Kn;function gSe(g){return(0,ij.hasChildren)(g)?g.children:[]}zi.getChildren=gSe;function ISe(g){return g.parent||null}zi.getParent=ISe;function Wdt(g){var e,I,i=ISe(g);if(i!=null)return gSe(i);for(var n=[g],C=g.prev,r=g.next;C!=null;)n.unshift(C),e=C,C=e.prev;for(;r!=null;)n.push(r),I=r,r=I.next;return n}zi.getSiblings=Wdt;function Xdt(g,e){var I;return(I=g.attribs)===null||I===void 0?void 0:I[e]}zi.getAttributeValue=Xdt;function Hdt(g,e){return g.attribs!=null&&Object.prototype.hasOwnProperty.call(g.attribs,e)&&g.attribs[e]!=null}zi.hasAttrib=Hdt;function Tdt(g){return g.name}zi.getName=Tdt;function Ndt(g){for(var e,I=g.next;I!==null&&!(0,ij.isTag)(I);)e=I,I=e.next;return I}zi.nextElementSibling=Ndt;function kdt(g){for(var e,I=g.prev;I!==null&&!(0,ij.isTag)(I);)e=I,I=e.prev;return I}zi.prevElementSibling=kdt;var RC={};Object.defineProperty(RC,"__esModule",{value:!0});RC.prepend=RC.prependChild=RC.append=RC.appendChild=RC.replaceElement=RC.removeElement=void 0;function uw(g){if(g.prev&&(g.prev.next=g.next),g.next&&(g.next.prev=g.prev),g.parent){var e=g.parent.children,I=e.lastIndexOf(g);I>=0&&e.splice(I,1)}g.next=null,g.prev=null,g.parent=null}RC.removeElement=uw;function Ydt(g,e){var I=e.prev=g.prev;I&&(I.next=e);var i=e.next=g.next;i&&(i.prev=e);var n=e.parent=g.parent;if(n){var C=n.children;C[C.lastIndexOf(g)]=e,g.parent=null}}RC.replaceElement=Ydt;function Kdt(g,e){if(uw(e),e.next=null,e.parent=g,g.children.push(e)>1){var I=g.children[g.children.length-2];I.next=e,e.prev=I}else e.prev=null}RC.appendChild=Kdt;function xdt(g,e){uw(e);var I=g.parent,i=g.next;if(e.next=i,e.prev=g,g.next=e,e.parent=I,i){if(i.prev=e,I){var n=I.children;n.splice(n.lastIndexOf(i),0,e)}}else I&&I.children.push(e)}RC.append=xdt;function Ddt(g,e){if(uw(e),e.parent=g,e.prev=null,g.children.unshift(e)!==1){var I=g.children[1];I.prev=e,e.next=I}else e.next=null}RC.prependChild=Ddt;function Fdt(g,e){uw(e);var I=g.parent;if(I){var i=I.children;i.splice(i.indexOf(g),0,e)}g.prev&&(g.prev.next=e),e.parent=I,e.prev=g.prev,e.next=g,g.prev=e}RC.prepend=Fdt;var Ln={};Object.defineProperty(Ln,"__esModule",{value:!0});Ln.findAll=Ln.existsOne=Ln.findOne=Ln.findOneChild=Ln.find=Ln.filter=void 0;var Ak=Kn;function Edt(g,e,I,i){return I===void 0&&(I=!0),i===void 0&&(i=1/0),iSe(g,Array.isArray(e)?e:[e],I,i)}Ln.filter=Edt;function iSe(g,e,I,i){for(var n=[],C=[e],r=[0];;){if(r[0]>=C[0].length){if(r.length===1)return n;C.shift(),r.shift();continue}var o=C[0][r[0]++];if(g(o)&&(n.push(o),--i<=0))return n;I&&(0,Ak.hasChildren)(o)&&o.children.length>0&&(r.unshift(0),C.unshift(o.children))}}Ln.find=iSe;function Mdt(g,e){return e.find(g)}Ln.findOneChild=Mdt;function nSe(g,e,I){I===void 0&&(I=!0);for(var i=null,n=0;n0&&(i=nSe(g,C.children,!0));else continue}return i}Ln.findOne=nSe;function CSe(g,e){return e.some(function(I){return(0,Ak.isTag)(I)&&(g(I)||CSe(g,I.children))})}Ln.existsOne=CSe;function zdt(g,e){for(var I=[],i=[e],n=[0];;){if(n[0]>=i[0].length){if(i.length===1)return I;i.shift(),n.shift();continue}var C=i[0][n[0]++];(0,Ak.isTag)(C)&&(g(C)&&I.push(C),C.children.length>0&&(n.unshift(0),i.unshift(C.children)))}}Ln.findAll=zdt;var Cr={};Object.defineProperty(Cr,"__esModule",{value:!0});Cr.getElementsByTagType=Cr.getElementsByTagName=Cr.getElementById=Cr.getElements=Cr.testElement=void 0;var ld=Kn,ak=Ln,IH={tag_name:function(g){return typeof g=="function"?function(e){return(0,ld.isTag)(e)&&g(e.name)}:g==="*"?ld.isTag:function(e){return(0,ld.isTag)(e)&&e.name===g}},tag_type:function(g){return typeof g=="function"?function(e){return g(e.type)}:function(e){return e.type===g}},tag_contains:function(g){return typeof g=="function"?function(e){return(0,ld.isText)(e)&&g(e.data)}:function(e){return(0,ld.isText)(e)&&e.data===g}}};function rSe(g,e){return typeof e=="function"?function(I){return(0,ld.isTag)(I)&&e(I.attribs[g])}:function(I){return(0,ld.isTag)(I)&&I.attribs[g]===e}}function Pdt(g,e){return function(I){return g(I)||e(I)}}function oSe(g){var e=Object.keys(g).map(function(I){var i=g[I];return Object.prototype.hasOwnProperty.call(IH,I)?IH[I](i):rSe(I,i)});return e.length===0?null:e.reduce(Pdt)}function Jdt(g,e){var I=oSe(g);return I?I(e):!0}Cr.testElement=Jdt;function Odt(g,e,I,i){i===void 0&&(i=1/0);var n=oSe(g);return n?(0,ak.filter)(n,e,I,i):[]}Cr.getElements=Odt;function Ldt(g,e,I){return I===void 0&&(I=!0),Array.isArray(e)||(e=[e]),(0,ak.findOne)(rSe("id",g),e,I)}Cr.getElementById=Ldt;function _dt(g,e,I,i){return I===void 0&&(I=!0),i===void 0&&(i=1/0),(0,ak.filter)(IH.tag_name(g),e,I,i)}Cr.getElementsByTagName=_dt;function Udt(g,e,I,i){return I===void 0&&(I=!0),i===void 0&&(i=1/0),(0,ak.filter)(IH.tag_type(g),e,I,i)}Cr.getElementsByTagType=Udt;var ASe={};(function(g){Object.defineProperty(g,"__esModule",{value:!0}),g.uniqueSort=g.compareDocumentPosition=g.DocumentPosition=g.removeSubsets=void 0;var e=Kn;function I(r){for(var o=r.length;--o>=0;){var A=r[o];if(o>0&&r.lastIndexOf(A,o-1)>=0){r.splice(o,1);continue}for(var s=A.parent;s;s=s.parent)if(r.includes(s)){r.splice(o,1);break}}return r}g.removeSubsets=I;var i;(function(r){r[r.DISCONNECTED=1]="DISCONNECTED",r[r.PRECEDING=2]="PRECEDING",r[r.FOLLOWING=4]="FOLLOWING",r[r.CONTAINS=8]="CONTAINS",r[r.CONTAINED_BY=16]="CONTAINED_BY"})(i=g.DocumentPosition||(g.DocumentPosition={}));function n(r,o){var A=[],s=[];if(r===o)return 0;for(var a=(0,e.hasChildren)(r)?r:r.parent;a;)A.unshift(a),a=a.parent;for(a=(0,e.hasChildren)(o)?o:o.parent;a;)s.unshift(a),a=a.parent;for(var l=Math.min(A.length,s.length),c=0;cd.indexOf(m)?u===o?i.FOLLOWING|i.CONTAINED_BY:i.FOLLOWING:u===r?i.PRECEDING|i.CONTAINS:i.PRECEDING}g.compareDocumentPosition=n;function C(r){return r=r.filter(function(o,A,s){return!s.includes(o,A+1)}),r.sort(function(o,A){var s=n(o,A);return s&i.PRECEDING?-1:s&i.FOLLOWING?1:0}),r}g.uniqueSort=C})(ASe);var sk={};Object.defineProperty(sk,"__esModule",{value:!0});sk.getFeed=void 0;var Qdt=nr,dw=Cr;function jdt(g){var e=iH(ght,g);return e?e.name==="feed"?$dt(e):qdt(e):null}sk.getFeed=jdt;function $dt(g){var e,I=g.children,i={type:"atom",items:(0,dw.getElementsByTagName)("entry",I).map(function(r){var o,A=r.children,s={media:aSe(A)};SC(s,"id","id",A),SC(s,"title","title",A);var a=(o=iH("link",A))===null||o===void 0?void 0:o.attribs.href;a&&(s.link=a);var l=Rc("summary",A)||Rc("content",A);l&&(s.description=l);var c=Rc("updated",A);return c&&(s.pubDate=new Date(c)),s})};SC(i,"id","id",I),SC(i,"title","title",I);var n=(e=iH("link",I))===null||e===void 0?void 0:e.attribs.href;n&&(i.link=n),SC(i,"description","subtitle",I);var C=Rc("updated",I);return C&&(i.updated=new Date(C)),SC(i,"author","email",I,!0),i}function qdt(g){var e,I,i=(I=(e=iH("channel",g.children))===null||e===void 0?void 0:e.children)!==null&&I!==void 0?I:[],n={type:g.name.substr(0,3),id:"",items:(0,dw.getElementsByTagName)("item",g.children).map(function(r){var o=r.children,A={media:aSe(o)};SC(A,"id","guid",o),SC(A,"title","title",o),SC(A,"link","link",o),SC(A,"description","description",o);var s=Rc("pubDate",o)||Rc("dc:date",o);return s&&(A.pubDate=new Date(s)),A})};SC(n,"title","title",i),SC(n,"link","link",i),SC(n,"description","description",i);var C=Rc("lastBuildDate",i);return C&&(n.updated=new Date(C)),SC(n,"author","managingEditor",i,!0),n}var eht=["url","type","lang"],tht=["fileSize","bitrate","framerate","samplingrate","channels","duration","height","width"];function aSe(g){return(0,dw.getElementsByTagName)("media:content",g).map(function(e){for(var I=e.attribs,i={medium:I.medium,isDefault:!!I.isDefault},n=0,C=eht;na.length-3)return!1;var c=a.charCodeAt(l+1);return(c>=A.LowerA&&c<=A.LowerZ||c>=A.UpperA&&c<=A.UpperZ||c===A.Exclamation)&&a.includes(">",l+2)}g.isHtml=s})(Zu);Object.defineProperty(ci,"__esModule",{value:!0});ci.toggleClass=ci.removeClass=ci.addClass=ci.hasClass=ci.removeAttr=ci.val=ci.data=ci.prop=ci.attr=void 0;var lSe=ri,Lg=Zu,Vne=aA,Qp=Object.prototype.hasOwnProperty,Ov=/\s+/,ZD="data-",Rne={null:null,true:!0,false:!1},nj=/^(?:autofocus|autoplay|async|checked|controls|defer|disabled|hidden|loop|multiple|open|readonly|required|scoped|selected)$/i,dht=/^{[^]*}$|^\[[^]*]$/;function nH(g,e,I){var i;if(!(!g||!(0,Lg.isTag)(g))){if((i=g.attribs)!==null&&i!==void 0||(g.attribs={}),!e)return g.attribs;if(Qp.call(g.attribs,e))return!I&&nj.test(e)?e:g.attribs[e];if(g.name==="option"&&e==="value")return(0,lSe.text)(g.children);if(g.name==="input"&&(g.attribs.type==="radio"||g.attribs.type==="checkbox")&&e==="value")return"on"}}function jp(g,e,I){I===null?cSe(g,e):g.attribs[e]="".concat(I)}function hht(g,e){if(typeof g=="object"||e!==void 0){if(typeof e=="function"){if(typeof g!="string")throw new Error("Bad combination of arguments.");return(0,Lg.domEach)(this,function(I,i){(0,Lg.isTag)(I)&&jp(I,g,e.call(I,i,I.attribs[g]))})}return(0,Lg.domEach)(this,function(I){(0,Lg.isTag)(I)&&(typeof g=="object"?Object.keys(g).forEach(function(i){var n=g[i];jp(I,i,n)}):jp(I,g,e))})}return arguments.length>1?this:nH(this[0],g,this.options.xmlMode)}ci.attr=hht;function Wne(g,e,I){return e in g?g[e]:!I&&nj.test(e)?nH(g,e,!1)!==void 0:nH(g,e,I)}function GD(g,e,I,i){e in g?g[e]=I:jp(g,e,!i&&nj.test(e)?I?"":null:"".concat(I))}function mht(g,e){var I=this,i;if(typeof g=="string"&&e===void 0){var n=this[0];if(!n||!(0,Lg.isTag)(n))return;switch(g){case"style":{var C=this.css(),r=Object.keys(C);return r.forEach(function(A,s){C[s]=A}),C.length=r.length,C}case"tagName":case"nodeName":return n.name.toUpperCase();case"href":case"src":{var o=(i=n.attribs)===null||i===void 0?void 0:i[g];return typeof URL<"u"&&(g==="href"&&(n.tagName==="a"||n.name==="link")||g==="src"&&(n.tagName==="img"||n.tagName==="iframe"||n.tagName==="audio"||n.tagName==="video"||n.tagName==="source"))&&o!==void 0&&this.options.baseURI?new URL(o,this.options.baseURI).href:o}case"innerText":return(0,Vne.innerText)(n);case"textContent":return(0,Vne.textContent)(n);case"outerHTML":return this.clone().wrap("").parent().html();case"innerHTML":return this.html();default:return Wne(n,g,this.options.xmlMode)}}if(typeof g=="object"||e!==void 0){if(typeof e=="function"){if(typeof g=="object")throw new Error("Bad combination of arguments.");return(0,Lg.domEach)(this,function(A,s){(0,Lg.isTag)(A)&&GD(A,g,e.call(A,s,Wne(A,g,I.options.xmlMode)),I.options.xmlMode)})}return(0,Lg.domEach)(this,function(A){(0,Lg.isTag)(A)&&(typeof g=="object"?Object.keys(g).forEach(function(s){var a=g[s];GD(A,s,a,I.options.xmlMode)}):GD(A,g,e,I.options.xmlMode))})}}ci.prop=mht;function Xne(g,e,I){var i,n=g;(i=n.data)!==null&&i!==void 0||(n.data={}),typeof e=="object"?Object.assign(n.data,e):typeof e=="string"&&I!==void 0&&(n.data[e]=I)}function Hne(g,e){var I,i,n;e==null?(I=Object.keys(g.attribs).filter(function(A){return A.startsWith(ZD)}),i=I.map(function(A){return(0,Lg.camelCase)(A.slice(ZD.length))})):(I=[ZD+(0,Lg.cssCase)(e)],i=[e]);for(var C=0;C-1;){var n=i+g.length;if((i===0||Ov.test(I[i-1]))&&(n===I.length||Ov.test(I[n])))return!0}return!1})}ci.hasClass=yht;function uSe(g){if(typeof g=="function")return(0,Lg.domEach)(this,function(s,a){if((0,Lg.isTag)(s)){var l=s.attribs.class||"";uSe.call([s],g.call(s,a,l))}});if(!g||typeof g!="string")return this;for(var e=g.split(Ov),I=this.length,i=0;i=0&&(C.splice(A,1),r=!0,o--)}r&&(n.attribs.class=C.join(" "))}})}ci.removeClass=dSe;function hSe(g,e){if(typeof g=="function")return(0,Lg.domEach)(this,function(l,c){(0,Lg.isTag)(l)&&hSe.call([l],g.call(l,c,l.attribs.class||"",e),e)});if(!g||typeof g!="string")return this;for(var I=g.split(Ov),i=I.length,n=typeof e=="boolean"?e?1:-1:0,C=this.length,r=0;r=0&&a<0?A.push(I[s]):n<=0&&a>=0&&A.splice(a,1)}o.attribs.class=A.join(" ")}}return this}ci.toggleClass=hSe;var Ht={},mSe={},wg;(function(g){g.Attribute="attribute",g.Pseudo="pseudo",g.PseudoElement="pseudo-element",g.Tag="tag",g.Universal="universal",g.Adjacent="adjacent",g.Child="child",g.Descendant="descendant",g.Parent="parent",g.Sibling="sibling",g.ColumnCombinator="column-combinator"})(wg||(wg={}));const Zht={Unknown:null,QuirksMode:"quirks",IgnoreCase:!0,CaseSensitive:!1};var WI;(function(g){g.Any="any",g.Element="element",g.End="end",g.Equals="equals",g.Exists="exists",g.Hyphen="hyphen",g.Not="not",g.Start="start"})(WI||(WI={}));const Tne=/^[^\\#]?(?:\\(?:[\da-f]{1,6}\s?|.)|[\w\-\u00b0-\uFFFF])+/,Ght=/\\([\da-f]{1,6}\s?|(\s)|.)/gi,Bht=new Map([[126,WI.Element],[94,WI.Start],[36,WI.End],[42,WI.Any],[33,WI.Not],[124,WI.Hyphen]]),vht=new Set(["has","not","matches","is","where","host","host-context"]);function fSe(g){switch(g.type){case wg.Adjacent:case wg.Child:case wg.Descendant:case wg.Parent:case wg.Sibling:case wg.ColumnCombinator:return!0;default:return!1}}const Sht=new Set(["contains","icontains"]);function wht(g,e,I){const i=parseInt(e,16)-65536;return i!==i||I?e:i<0?String.fromCharCode(i+65536):String.fromCharCode(i>>10|55296,i&1023|56320)}function oZ(g){return g.replace(Ght,wht)}function BD(g){return g===39||g===34}function Nne(g){return g===32||g===9||g===10||g===12||g===13}function Vht(g){const e=[],I=pSe(e,`${g}`,0);if(I0&&I0&&fSe(i[i.length-1]))throw new Error("Did not expect successive traversals.")}function s(c){if(i.length>0&&i[i.length-1].type===wg.Descendant){i[i.length-1].type=c;return}A(),i.push({type:c})}function a(c,u){i.push({type:wg.Attribute,name:c,action:u,value:n(1),namespace:null,ignoreCase:"quirks"})}function l(){if(i.length&&i[i.length-1].type===wg.Descendant&&i.pop(),i.length===0)throw new Error("Empty sub-selector");g.push(i)}if(C(0),e.length===I)return I;e:for(;Ig.charCodeAt(0))),kne=new Set(ySe.map(g=>g.charCodeAt(0))),yp=new Set([...ySe,"~","^","$","*","+","!","|",":","[","]"," ","."].map(g=>g.charCodeAt(0)));function ZSe(g){return g.map(e=>e.map(Wht).join("")).join(", ")}function Wht(g,e,I){switch(g.type){case wg.Child:return e===0?"> ":" > ";case wg.Parent:return e===0?"< ":" < ";case wg.Sibling:return e===0?"~ ":" ~ ";case wg.Adjacent:return e===0?"+ ":" + ";case wg.Descendant:return" ";case wg.ColumnCombinator:return e===0?"|| ":" || ";case wg.Universal:return g.namespace==="*"&&e+10?i+g.slice(I):g}const Hht=Object.freeze(Object.defineProperty({__proto__:null,get AttributeAction(){return WI},IgnoreCaseMode:Zht,get SelectorType(){return wg},isTraversal:fSe,parse:Vht,stringify:ZSe},Symbol.toStringTag,{value:"Module"})),hw=Al(Hht);var Vz={},hm={trueFunc:function(){return!0},falseFunc:function(){return!1}},Oc={},ey={};Object.defineProperty(ey,"__esModule",{value:!0});ey.isTraversal=void 0;var Ir=hw,BSe=new Map([[Ir.SelectorType.Universal,50],[Ir.SelectorType.Tag,30],[Ir.SelectorType.Attribute,1],[Ir.SelectorType.Pseudo,0]]);function Tht(g){return!BSe.has(g.type)}ey.isTraversal=Tht;var Nht=new Map([[Ir.AttributeAction.Exists,10],[Ir.AttributeAction.Equals,8],[Ir.AttributeAction.Not,7],[Ir.AttributeAction.Start,6],[Ir.AttributeAction.End,6],[Ir.AttributeAction.Any,5]]);function kht(g){for(var e=g.map(vSe),I=1;I=0&&i>=1)):g.type===Ir.SelectorType.Pseudo&&(g.data?g.name==="has"||g.name==="contains"?i=0:Array.isArray(g.data)?(i=Math.min.apply(Math,g.data.map(function(n){return Math.min.apply(Math,n.map(vSe))})),i<0&&(i=0)):i=2:i=3),i}var ck={},uk={},Yht=Le&&Le.__importDefault||function(g){return g&&g.__esModule?g:{default:g}};Object.defineProperty(uk,"__esModule",{value:!0});uk.attributeRules=void 0;var GR=Yht(hm),Kht=/[-[\]{}()*+?.,\\^$|#\s]/g;function Kne(g){return g.replace(Kht,"\\$&")}var xht=new Set(["accept","accept-charset","align","alink","axis","bgcolor","charset","checked","clear","codetype","color","compact","declare","defer","dir","direction","disabled","enctype","face","frame","hreflang","http-equiv","lang","language","link","media","method","multiple","nohref","noresize","noshade","nowrap","readonly","rel","rev","rules","scope","scrolling","selected","shape","target","text","type","valign","valuetype","vlink"]);function Mu(g,e){return typeof g.ignoreCase=="boolean"?g.ignoreCase:g.ignoreCase==="quirks"?!!e.quirksMode:!e.xmlMode&&xht.has(g.name)}uk.attributeRules={equals:function(g,e,I){var i=I.adapter,n=e.name,C=e.value;return Mu(e,I)?(C=C.toLowerCase(),function(r){var o=i.getAttributeValue(r,n);return o!=null&&o.length===C.length&&o.toLowerCase()===C&&g(r)}):function(r){return i.getAttributeValue(r,n)===C&&g(r)}},hyphen:function(g,e,I){var i=I.adapter,n=e.name,C=e.value,r=C.length;return Mu(e,I)?(C=C.toLowerCase(),function(A){var s=i.getAttributeValue(A,n);return s!=null&&(s.length===r||s.charAt(r)==="-")&&s.substr(0,r).toLowerCase()===C&&g(A)}):function(A){var s=i.getAttributeValue(A,n);return s!=null&&(s.length===r||s.charAt(r)==="-")&&s.substr(0,r)===C&&g(A)}},element:function(g,e,I){var i=I.adapter,n=e.name,C=e.value;if(/\s/.test(C))return GR.default.falseFunc;var r=new RegExp("(?:^|\\s)".concat(Kne(C),"(?:$|\\s)"),Mu(e,I)?"i":"");return function(A){var s=i.getAttributeValue(A,n);return s!=null&&s.length>=C.length&&r.test(s)&&g(A)}},exists:function(g,e,I){var i=e.name,n=I.adapter;return function(C){return n.hasAttrib(C,i)&&g(C)}},start:function(g,e,I){var i=I.adapter,n=e.name,C=e.value,r=C.length;return r===0?GR.default.falseFunc:Mu(e,I)?(C=C.toLowerCase(),function(o){var A=i.getAttributeValue(o,n);return A!=null&&A.length>=r&&A.substr(0,r).toLowerCase()===C&&g(o)}):function(o){var A;return!!(!((A=i.getAttributeValue(o,n))===null||A===void 0)&&A.startsWith(C))&&g(o)}},end:function(g,e,I){var i=I.adapter,n=e.name,C=e.value,r=-C.length;return r===0?GR.default.falseFunc:Mu(e,I)?(C=C.toLowerCase(),function(o){var A;return((A=i.getAttributeValue(o,n))===null||A===void 0?void 0:A.substr(r).toLowerCase())===C&&g(o)}):function(o){var A;return!!(!((A=i.getAttributeValue(o,n))===null||A===void 0)&&A.endsWith(C))&&g(o)}},any:function(g,e,I){var i=I.adapter,n=e.name,C=e.value;if(C==="")return GR.default.falseFunc;if(Mu(e,I)){var r=new RegExp(Kne(C),"i");return function(A){var s=i.getAttributeValue(A,n);return s!=null&&s.length>=C.length&&r.test(s)&&g(A)}}return function(o){var A;return!!(!((A=i.getAttributeValue(o,n))===null||A===void 0)&&A.includes(C))&&g(o)}},not:function(g,e,I){var i=I.adapter,n=e.name,C=e.value;return C===""?function(r){return!!i.getAttributeValue(r,n)&&g(r)}:Mu(e,I)?(C=C.toLowerCase(),function(r){var o=i.getAttributeValue(r,n);return(o==null||o.length!==C.length||o.toLowerCase()!==C)&&g(r)}):function(r){return i.getAttributeValue(r,n)!==C&&g(r)}}};var Cj={},SSe={},wSe={},dk={};Object.defineProperty(dk,"__esModule",{value:!0});dk.parse=void 0;var Dht=new Set([9,10,12,13,32]),xne="0".charCodeAt(0),Fht="9".charCodeAt(0);function Eht(g){if(g=g.trim().toLowerCase(),g==="even")return[2,0];if(g==="odd")return[2,1];var e=0,I=0,i=C(),n=r();if(e=xne&&g.charCodeAt(e)<=Fht;)s=s*10+(g.charCodeAt(e)-xne),e++;return e===A?null:s}function o(){for(;e=I};var i=Math.abs(e),n=(I%i+i)%i;return e>1?function(C){return C>=I&&C%i===n}:function(C){return C<=I&&C%i===n}}Qb.compile=zht;function Pht(g){var e=g[0],I=g[1]-1,i=0;if(e<0){var n=-e,C=(I%n+n)%n;return function(){var r=C+n*i++;return r>I?null:r}}return e===0?I<0?function(){return null}:function(){return i++===0?I:null}:(I<0&&(I+=e*Math.ceil(-I/e)),function(){return e*i+++I})}Qb.generate=Pht;(function(g){Object.defineProperty(g,"__esModule",{value:!0}),g.sequence=g.generate=g.compile=g.parse=void 0;var e=dk;Object.defineProperty(g,"parse",{enumerable:!0,get:function(){return e.parse}});var I=Qb;Object.defineProperty(g,"compile",{enumerable:!0,get:function(){return I.compile}}),Object.defineProperty(g,"generate",{enumerable:!0,get:function(){return I.generate}});function i(C){return(0,I.compile)((0,e.parse)(C))}g.default=i;function n(C){return(0,I.generate)((0,e.parse)(C))}g.sequence=n})(wSe);(function(g){var e=Le&&Le.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(g,"__esModule",{value:!0}),g.filters=void 0;var I=e(wSe),i=e(hm);function n(r,o){return function(A){var s=o.getParent(A);return s!=null&&o.isTag(s)&&r(A)}}g.filters={contains:function(r,o,A){var s=A.adapter;return function(l){return r(l)&&s.getText(l).includes(o)}},icontains:function(r,o,A){var s=A.adapter,a=o.toLowerCase();return function(c){return r(c)&&s.getText(c).toLowerCase().includes(a)}},"nth-child":function(r,o,A){var s=A.adapter,a=A.equals,l=(0,I.default)(o);return l===i.default.falseFunc?i.default.falseFunc:l===i.default.trueFunc?n(r,s):function(u){for(var d=s.getSiblings(u),h=0,m=0;m=0&&!a(u,d[m]);m--)s.isTag(d[m])&&h++;return l(h)&&r(u)}},"nth-of-type":function(r,o,A){var s=A.adapter,a=A.equals,l=(0,I.default)(o);return l===i.default.falseFunc?i.default.falseFunc:l===i.default.trueFunc?n(r,s):function(u){for(var d=s.getSiblings(u),h=0,m=0;m=0;m--){var f=d[m];if(a(u,f))break;s.isTag(f)&&s.getName(f)===s.getName(u)&&h++}return l(h)&&r(u)}},root:function(r,o,A){var s=A.adapter;return function(a){var l=s.getParent(a);return(l==null||!s.isTag(l))&&r(a)}},scope:function(r,o,A,s){var a=A.equals;return!s||s.length===0?g.filters.root(r,o,A):s.length===1?function(l){return a(s[0],l)&&r(l)}:function(l){return s.includes(l)&&r(l)}},hover:C("isHovered"),visited:C("isVisited"),active:C("isActive")};function C(r){return function(A,s,a){var l=a.adapter,c=l[r];return typeof c!="function"?i.default.falseFunc:function(d){return c(d)&&A(d)}}}})(SSe);var jb={};Object.defineProperty(jb,"__esModule",{value:!0});jb.verifyPseudoArgs=jb.pseudos=void 0;jb.pseudos={empty:function(g,e){var I=e.adapter;return!I.getChildren(g).some(function(i){return I.isTag(i)||I.getText(i)!==""})},"first-child":function(g,e){var I=e.adapter,i=e.equals;if(I.prevElementSibling)return I.prevElementSibling(g)==null;var n=I.getSiblings(g).find(function(C){return I.isTag(C)});return n!=null&&i(g,n)},"last-child":function(g,e){for(var I=e.adapter,i=e.equals,n=I.getSiblings(g),C=n.length-1;C>=0;C--){if(i(g,n[C]))return!0;if(I.isTag(n[C]))break}return!1},"first-of-type":function(g,e){for(var I=e.adapter,i=e.equals,n=I.getSiblings(g),C=I.getName(g),r=0;r=0;r--){var o=n[r];if(i(g,o))return!0;if(I.isTag(o)&&I.getName(o)===C)break}return!1},"only-of-type":function(g,e){var I=e.adapter,i=e.equals,n=I.getName(g);return I.getSiblings(g).every(function(C){return i(g,C)||!I.isTag(C)||I.getName(C)!==n})},"only-child":function(g,e){var I=e.adapter,i=e.equals;return I.getSiblings(g).every(function(n){return i(g,n)||!I.isTag(n)})}};function Jht(g,e,I,i){if(I===null){if(g.length>i)throw new Error("Pseudo-class :".concat(e," requires an argument"))}else if(g.length===i)throw new Error("Pseudo-class :".concat(e," doesn't have any arguments"))}jb.verifyPseudoArgs=Jht;var hk={};Object.defineProperty(hk,"__esModule",{value:!0});hk.aliases=void 0;hk.aliases={"any-link":":is(a, area, link)[href]",link:":any-link:not(:visited)",disabled:`:is( + */var xst=function(e){return e!=null&&(JZe(e)||Fst(e)||!!e._isBuffer)};function JZe(e){return!!e.constructor&&typeof e.constructor.isBuffer=="function"&&e.constructor.isBuffer(e)}function Fst(e){return typeof e.readFloatLE=="function"&&typeof e.slice=="function"&&JZe(e.slice(0,0))}var Est=Dst,Mst=xst,zst=typeof Float64Array<"u";function Pst(e,g){return e[0]-g[0]}function Jst(){var e=this.stride,g=new Array(e.length),I;for(I=0;IMath.abs(this.stride[1]))?[1,0]:[0,1]}})"):g===3&&n.push("var s0=Math.abs(this.stride[0]),s1=Math.abs(this.stride[1]),s2=Math.abs(this.stride[2]);if(s0>s1){if(s1>s2){return [2,1,0];}else if(s0>s2){return [1,2,0];}else{return [1,0,2];}}else if(s0>s2){return [2,0,1];}else if(s2>s1){return [0,1,2];}else{return [0,2,1];}}})")):n.push("ORDER})")),n.push("proto.set=function "+I+"_set("+r.join(",")+",v){"),i?n.push("return this.data.set("+o+",v)}"):n.push("return this.data["+o+"]=v}"),n.push("proto.get=function "+I+"_get("+r.join(",")+"){"),i?n.push("return this.data.get("+o+")}"):n.push("return this.data["+o+"]}"),n.push("proto.index=function "+I+"_index(",r.join(),"){return "+o+"}"),n.push("proto.hi=function "+I+"_hi("+r.join(",")+"){return new "+I+"(this.data,"+C.map(function(m){return["(typeof i",m,"!=='number'||i",m,"<0)?this.shape[",m,"]:i",m,"|0"].join("")}).join(",")+","+C.map(function(m){return"this.stride["+m+"]"}).join(",")+",this.offset)}");var a=C.map(function(m){return"a"+m+"=this.shape["+m+"]"}),l=C.map(function(m){return"c"+m+"=this.stride["+m+"]"});n.push("proto.lo=function "+I+"_lo("+r.join(",")+"){var b=this.offset,d=0,"+a.join(",")+","+l.join(","));for(var c=0;c=0){d=i"+c+"|0;b+=c"+c+"*d;a"+c+"-=d}");n.push("return new "+I+"(this.data,"+C.map(function(m){return"a"+m}).join(",")+","+C.map(function(m){return"c"+m}).join(",")+",b)}"),n.push("proto.step=function "+I+"_step("+r.join(",")+"){var "+C.map(function(m){return"a"+m+"=this.shape["+m+"]"}).join(",")+","+C.map(function(m){return"b"+m+"=this.stride["+m+"]"}).join(",")+",c=this.offset,d=0,ceil=Math.ceil");for(var c=0;c=0){c=(c+this.stride["+c+"]*i"+c+")|0}else{a.push(this.shape["+c+"]);b.push(this.stride["+c+"])}");n.push("var ctor=CTOR_LIST[a.length+1];return ctor(this.data,a,b,c)}"),n.push("return function construct_"+I+"(data,shape,stride,offset){return new "+I+"(data,"+C.map(function(m){return"shape["+m+"]"}).join(",")+","+C.map(function(m){return"stride["+m+"]"}).join(",")+",offset)}");var h=new Function("CTOR_LIST","ORDER",n.join(` +`));return h(i9[e],Jst)}function _st(e){if(Mst(e))return"buffer";if(zst)switch(Object.prototype.toString.call(e)){case"[object Float64Array]":return"float64";case"[object Float32Array]":return"float32";case"[object Int8Array]":return"int8";case"[object Int16Array]":return"int16";case"[object Int32Array]":return"int32";case"[object Uint8Array]":return"uint8";case"[object Uint16Array]":return"uint16";case"[object Uint32Array]":return"uint32";case"[object Uint8ClampedArray]":return"uint8_clamped";case"[object BigInt64Array]":return"bigint64";case"[object BigUint64Array]":return"biguint64"}return Array.isArray(e)?"array":"generic"}var i9={float32:[],float64:[],int8:[],int16:[],int32:[],uint8:[],uint16:[],uint32:[],array:[],uint8_clamped:[],bigint64:[],biguint64:[],buffer:[],generic:[]};function Lst(e,g,I,i){if(e===void 0){var s=i9.array[0];return s([])}else typeof e=="number"&&(e=[e]);g===void 0&&(g=[e.length]);var n=g.length;if(I===void 0){I=new Array(n);for(var C=n-1,r=1;C>=0;--C)I[C]=r,r*=g[C]}if(i===void 0){i=0;for(var C=0;C{const g=e.shape.reduce((i,n)=>i*n,1),I=new Array(g);if(e.dimension===1){let i=0;for(let n=0;ne.shape.length===1?e:vp(OZe(e)),LZe=e=>{const g=e.split("."),I=g.slice(1).join("").length;return+g.join("")/10**I},RS=(e,g)=>e||g;function CN(e){const g=[],I={},i={};let n=0;for(let C=0;C{const g=document.createElement("g"),I=document.createElement("text");return e.anchor.x===0?I.setAttribute("text-anchor","start"):e.anchor.x===1?I.setAttribute("text-anchor","end"):I.setAttribute("text-anchor","middle"),I.setAttribute("font-family",e.style.fontFamily),I.setAttribute("font-size",e.style.fontSize),g.setAttribute("transform",`scale(${e.scale.x},1)`),I.setAttribute("fill",e.style.fill),I.innerHTML=e.text,g.appendChild(I),g.setAttribute("transform",`translate(${e.x},${e.y})scale(${e.scale.x},1)`),g},Qst=e=>{try{const g=e.split(".");return I=>{let i=I;return g.forEach(n=>{i=i[n]}),i}}catch{return}},jst=(e,g,I,i,n,C,r=0,o=0,A)=>{const s=C?n:i,a=C?i:n,l=C?o:r,c=C?r:o,u=Math.max(0,+s[0]||0),d=Math.max(0,+s[1]||0),h=Math.max(0,+a[0]||0),m=Math.max(0,+a[1]||0);let f=[];ArrayBuffer.isView(A)||console.warn("Not supported yet");try{const b=new A.constructor(A.length);let p=0+c;for(let Z=h;Z[i.chrPositions[e].pos+ +g,i.chrPositions[e].pos+ +I],qst="http://www.w3.org/2000/svg",elt=(e,g)=>{const I=new RegExp(`(\\s|^)${g}(\\s|$)`);if(e.namespaceURI===qst){const i=e.getAttribute("class")||"";e.setAttribute("class",i.replace(I," "))}else e.classList?e.classList.remove(g):LX(e,g)&&(e.className=e.className.replace(I," "))},Bp=(e,g)=>{e.select(".selection").attr("fill",null).attr("fill-opacity",null).attr("stroke",null).classed(g,!0)},N5=e=>{const g=e.toString(16);return g.length===1?`0${g}`:g},tlt=(e,g,I)=>`#${N5(e)}${N5(g)}${N5(I)}`,yi=(e,g)=>{const I=e.invert((e.range()[0]+e.range()[1])/2),i=g.invert((g.range()[0]+g.range()[1])/2),n=e.invert(1)-e.invert(0);return[I,i,n]},UZe=(e,g,I)=>{if(I===null||!e||!g)return;const i=e.domain()[0],n=e.domain()[1],C=g.domain()[0],r=g.domain()[1];return[...e9(i,n,I),...e9(C,r,I)]},glt=11184810,Ilt=1,ilt=(e,g,I,i,n,C,r,o,A)=>{e.publish("app.animateOnMouseMove",!0);const s=I.mousePositionColor?FZe(I.mousePositionColor):glt,a=I.mousePositionAlpha||Ilt,l=new rt.PIXI.Graphics,c=()=>{l.clear()},u=(h,m,f)=>{if(f||c(),l.lineStyle(1,s,a),m){const b=o?n()[0]:0;l.moveTo(0,h),l.lineTo(C()[0]+b,h)}else{const b=o?n()[1]:0;l.moveTo(h,0),l.lineTo(h,C()[1]+b)}},d=h=>{if(h.noHoveredTracks)return c(),l;let m,f;h.isFromVerticalTrack?(m=h.dataY,f=h.dataY):(m=h.dataX,f=h.isFrom2dTrack?h.dataY:h.dataX);const b=o?n():[0,0],p=r()?i()[0](f)+b[1]:i()[0](m)+b[0];return u(p),o&&u(i()[1](f)+b[1],!0,!0),l};return g.push(e.subscribe("app.mouseMove",d)),g.push(e.subscribe("app.mouseLeave",c)),g.push(e.subscribe("blur",c)),A&&g.push(VG.subscribe("higlass.mouseMove",d)),l},eh=(e,g=!1,I=!1)=>{const i=g?e.pMasked:e.pForeground||e.pMain;if(!i)throw new Error("setupShowMousePosition: No scene found. Please make sure to call this method after the scene has been initialized.");const n=()=>[e.xScale(),e.yScale()],C=ilt(e.pubSub,e.pubSubs,e.options,n,e.getPosition.bind(e),e.getDimensions.bind(e),e.getProp("flipText"),g,I);return i.addChild(C),()=>{i.removeChild(C)}},nlt=e=>g=>Array.prototype.some.call(g,e),Pl=(e,g)=>e+g,QZe=(e,g,I,i,n,C)=>{const r=document.createElement("line");return r.setAttribute("x1",e),r.setAttribute("x2",I),r.setAttribute("y1",g),r.setAttribute("y2",i),n&&r.setAttribute("stroke-width",n),C&&r.setAttribute("stroke",C),r},jZe=(e,g,I)=>{let i,n=0;const C=()=>{i=void 0},r=(...s)=>{const a=()=>{n>0&&(e(...s),n=0)};clearTimeout(i),i=setTimeout(a,I)};r.cancel=()=>{clearTimeout(i),C()},r.immediate=(...s)=>{e(...s)};let o=!1;return(s,...a)=>{o?n++:(e(...a),r(...a),o=!0,n=0,setTimeout(()=>{o=!1},g))}},Clt=(e,g=256,I=256)=>{const i=document.createElement("canvas");i.width=g,i.height=I;const n=i.getContext("2d");if(!n)throw new Error("Could not get canvas context");n.fillStyle="transparent",n.fillRect(0,0,i.width,i.height);const C=new ImageData(e,i.width,i.height);return n.putImageData(C,0,0),i},j7=e=>new Promise(g=>{setTimeout(g,e)}),rlt=e=>{if(!e.tracks)return 0;let g=0;return e.tracks.top&&(g+=e.tracks.top.map(I=>I.height).reduce((I,i)=>I+i,0)),e.tracks.center&&(g+=e.tracks.center.map(I=>I.height).reduce((I,i)=>I+i,0)),e.tracks.bottom&&(g+=e.tracks.bottom.map(I=>I.height).reduce((I,i)=>I+i,0)),g},_o=()=>{},rN=e=>(e||"").replace(/\/$/,""),$7=(e,g,I=0,i=1e-6)=>n=>{let C=255;return n>i&&(C=Math.max(0,Math.min(255,Math.floor(e(n+I))))),g[C]},B1=e=>{let g=[];for(let I=0;Ig[0]?e.left?w3(e.left,g):CIe(e,"left",g):e.right?w3(e.right,g):CIe(e,"right",g)}Ds.prototype.add=function(g){if(!this.root){this.root=new $Ze(g[0],g[1]),this.root.max=g[1];return}w3(this.root,g)};function qZe(e,g){if(!g)return!1;if(g.interval[0]<=e&&g.interval[1]>=e)return!0;let I=!1,i;return["left","right"].forEach(n=>{i=g[n],i&&i.max>e&&(I=I||qZe(e,i))}),I}Ds.prototype.contains=function(g){return qZe(g,this.root)};function olt(e,g){return e[0]===g[0]&&e[1]===g[1]||e[0]g[0]||e[0]g[1]||g[0]e[0]||g[0]e[1]}function eGe(e,g){if(!g)return!1;if(olt(g.interval,e))return!0;let I=!1,i;return["left","right"].forEach(n=>{i=g[n],i&&i.max>=e[0]&&(I=I||eGe(e,i))}),I}Ds.prototype.intersects=function(g){return eGe(g,this.root)};function V3(e){return e?1+Math.max(V3(e.left),V3(e.right)):0}Ds.prototype.height=function(){return V3(this.root)};Ds.prototype.findMax=function(g){const I=[g];let i,n=-1/0,C;for(;I.length;)i=I.pop(),i.left&&I.push(i.left),i.right&&I.push(i.right),i.interval[1]>n&&(n=i.interval[1],C=i);return C};Ds.prototype._removeHelper=function(g,I){if(I)if(I.interval[0]===g[0]&&I.interval[1]===g[1]){if(I.left&&I.right){let n=I.left;for(;n.left;)n=n.left;const C=n.interval;n.interval=I.interval,I.interval=C,this._removeHelper(n.interval,I)}else{let n="left";I.right&&(n="right");const C=I.parentNode;C?(C.left===I?C.left=I[n]:C.right=I[n],I[n]&&(I[n].parentNode=C)):(this.root=I[n],this.root&&(this.root.parentNode=null))}const i=I.parentNode;if(i){let n=this.findMax(i);const C=n.interval[1];for(;n;)n.max===I.interval[1]?(n.max=C,n=n.parentNode):n=!1}}else this._removeHelper(g,I.left),this._removeHelper(g,I.right)};Ds.prototype.remove=function(g){return this._removeHelper(g,this.root)};function n9(e){e.sort((i,n)=>n.to-n.from-(i.to-i.from));const g=[[]],I=[new Ds];for(let i=0;i=o?this.minNonZero(this.data,i,n):(io*this.subsetSize&&(C=Math.min(C,this.minNonZero(this.data,o*this.subsetSize,n))),C)}},{key:"getMaxNonZeroInSubset",value:function(I){const i=I[0],n=I[1];let C=Number.MIN_SAFE_INTEGER;if(i===0&&n===this.tileSize)return this.maxNonZeroInTile;const r=Math.ceil(i/this.subsetSize),o=Math.floor((n-1)/this.subsetSize);return r>=o?this.maxNonZero(this.data,i,n):(io*this.subsetSize&&(C=Math.max(C,this.maxNonZero(this.data,o*this.subsetSize,n))),C)}},{key:"computeSubsetNonZeroMinimums",value:function(){const I=[];for(let i=0;i-this.epsilon||r-this.epsilon||r>n&&(n=r))}I.push(n)}return I}},{key:"getMinNonZeroInTile",value:function(){return Math.min(...this.subsetMinimums)}},{key:"getMaxNonZeroInTile",value:function(){return Math.max(...this.subsetMaximums)}},{key:"minNonZero",value:function(I,i,n){let C=Number.MAX_SAFE_INTEGER;for(let r=i;r-this.epsilon||o-this.epsilon||o>C&&(C=o)}return C}}]),e}();function clt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function oIe(e,g){for(var I=0;I-this.epsilon||a-this.epsilon||a>o&&(o=a)}return o}},{key:"mirrorPrecomputedExtrema",value:function(){for(let I=1;I{let g;switch(e&&e.toLowerCase()){case"mean":g=jM;break;case"sum":g=C0e;break;case"variance":g=YU;break;case"deviation":g=KU;break;default:g=jM,console.warn("Encountered an unsupported selectedRowsAggregationMode option.")}return g},fB=(e,g)=>e.reduce((I,i)=>I+(Array.isArray(i)&&g?i.length:1),0),V0=e=>{switch(e.type){case"heatmap":case"horizontal-1d-heatmap":case"horizontal-bar":case"horizontal-line":case"horizontal-point":case"vertical-1d-heatmap":case"vertical-bar":case"vertical-line":case"vertical-point":case"horizontal-1d-tiles":case"vertical-1d-tiles":case"2d-tiles":case"horizontal-gene-annotations":case"vertical-gene-annotations":case"horizontal-heatmap":case"vertical-heatmap":case"osm-tiles":case"mapbox-tiles":case"horizontal-multivec":return!0;case"combined":return e.contents.map(I=>V0(I)).reduce(RS,!1);default:return!1}},tQ=(e,g,I)=>{let i=g,n=I;return I||(n=g,i=Object.values(e.state.views)[0].uid),e.tiledPlots[i].trackRenderer.getTrackObject(n)},tGe=(e,g)=>e.tiledPlots[g].trackRenderer,mlt=(e,g)=>e.tiledPlots[g];var gQ={},AIe=Object.prototype.toString,gGe=function(g){var I=AIe.call(g),i=I==="[object Arguments]";return i||(i=I!=="[object Array]"&&g!==null&&typeof g=="object"&&typeof g.length=="number"&&g.length>=0&&AIe.call(g.callee)==="[object Function]"),i},k5,aIe;function flt(){if(aIe)return k5;aIe=1;var e;if(!Object.keys){var g=Object.prototype.hasOwnProperty,I=Object.prototype.toString,i=gGe,n=Object.prototype.propertyIsEnumerable,C=!n.call({toString:null},"toString"),r=n.call(function(){},"prototype"),o=["toString","toLocaleString","valueOf","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","constructor"],A=function(c){var u=c.constructor;return u&&u.prototype===c},s={$applicationCache:!0,$console:!0,$external:!0,$frame:!0,$frameElement:!0,$frames:!0,$innerHeight:!0,$innerWidth:!0,$onmozfullscreenchange:!0,$onmozfullscreenerror:!0,$outerHeight:!0,$outerWidth:!0,$pageXOffset:!0,$pageYOffset:!0,$parent:!0,$scrollLeft:!0,$scrollTop:!0,$scrollX:!0,$scrollY:!0,$self:!0,$webkitIndexedDB:!0,$webkitStorageInfo:!0,$window:!0},a=function(){if(typeof window>"u")return!1;for(var c in window)try{if(!s["$"+c]&&g.call(window,c)&&window[c]!==null&&typeof window[c]=="object")try{A(window[c])}catch{return!0}}catch{return!0}return!1}(),l=function(c){if(typeof window>"u"||!a)return A(c);try{return A(c)}catch{return!1}};e=function(u){var d=u!==null&&typeof u=="object",h=I.call(u)==="[object Function]",m=i(u),f=d&&I.call(u)==="[object String]",b=[];if(!d&&!h&&!m)throw new TypeError("Object.keys called on a non-object");var p=r&&h;if(f&&u.length>0&&!g.call(u,0))for(var y=0;y0)for(var Z=0;Z"u"||!xi?pg:xi(Uint8Array),Gd={"%AggregateError%":typeof AggregateError>"u"?pg:AggregateError,"%Array%":Array,"%ArrayBuffer%":typeof ArrayBuffer>"u"?pg:ArrayBuffer,"%ArrayIteratorPrototype%":Tm&&xi?xi([][Symbol.iterator]()):pg,"%AsyncFromSyncIteratorPrototype%":pg,"%AsyncFunction%":Af,"%AsyncGenerator%":Af,"%AsyncGeneratorFunction%":Af,"%AsyncIteratorPrototype%":Af,"%Atomics%":typeof Atomics>"u"?pg:Atomics,"%BigInt%":typeof BigInt>"u"?pg:BigInt,"%BigInt64Array%":typeof BigInt64Array>"u"?pg:BigInt64Array,"%BigUint64Array%":typeof BigUint64Array>"u"?pg:BigUint64Array,"%Boolean%":Boolean,"%DataView%":typeof DataView>"u"?pg:DataView,"%Date%":Date,"%decodeURI%":decodeURI,"%decodeURIComponent%":decodeURIComponent,"%encodeURI%":encodeURI,"%encodeURIComponent%":encodeURIComponent,"%Error%":Error,"%eval%":eval,"%EvalError%":EvalError,"%Float32Array%":typeof Float32Array>"u"?pg:Float32Array,"%Float64Array%":typeof Float64Array>"u"?pg:Float64Array,"%FinalizationRegistry%":typeof FinalizationRegistry>"u"?pg:FinalizationRegistry,"%Function%":CGe,"%GeneratorFunction%":Af,"%Int8Array%":typeof Int8Array>"u"?pg:Int8Array,"%Int16Array%":typeof Int16Array>"u"?pg:Int16Array,"%Int32Array%":typeof Int32Array>"u"?pg:Int32Array,"%isFinite%":isFinite,"%isNaN%":isNaN,"%IteratorPrototype%":Tm&&xi?xi(xi([][Symbol.iterator]())):pg,"%JSON%":typeof JSON=="object"?JSON:pg,"%Map%":typeof Map>"u"?pg:Map,"%MapIteratorPrototype%":typeof Map>"u"||!Tm||!xi?pg:xi(new Map()[Symbol.iterator]()),"%Math%":Math,"%Number%":Number,"%Object%":Object,"%parseFloat%":parseFloat,"%parseInt%":parseInt,"%Promise%":typeof Promise>"u"?pg:Promise,"%Proxy%":typeof Proxy>"u"?pg:Proxy,"%RangeError%":RangeError,"%ReferenceError%":ReferenceError,"%Reflect%":typeof Reflect>"u"?pg:Reflect,"%RegExp%":RegExp,"%Set%":typeof Set>"u"?pg:Set,"%SetIteratorPrototype%":typeof Set>"u"||!Tm||!xi?pg:xi(new Set()[Symbol.iterator]()),"%SharedArrayBuffer%":typeof SharedArrayBuffer>"u"?pg:SharedArrayBuffer,"%String%":String,"%StringIteratorPrototype%":Tm&&xi?xi(""[Symbol.iterator]()):pg,"%Symbol%":Tm?Symbol:pg,"%SyntaxError%":Bb,"%ThrowTypeError%":Nlt,"%TypedArray%":Ylt,"%TypeError%":Sp,"%Uint8Array%":typeof Uint8Array>"u"?pg:Uint8Array,"%Uint8ClampedArray%":typeof Uint8ClampedArray>"u"?pg:Uint8ClampedArray,"%Uint16Array%":typeof Uint16Array>"u"?pg:Uint16Array,"%Uint32Array%":typeof Uint32Array>"u"?pg:Uint32Array,"%URIError%":URIError,"%WeakMap%":typeof WeakMap>"u"?pg:WeakMap,"%WeakRef%":typeof WeakRef>"u"?pg:WeakRef,"%WeakSet%":typeof WeakSet>"u"?pg:WeakSet};if(xi)try{null.error}catch(e){var Klt=xi(xi(e));Gd["%Error.prototype%"]=Klt}var Dlt=function e(g){var I;if(g==="%AsyncFunction%")I=Y5("async function () {}");else if(g==="%GeneratorFunction%")I=Y5("function* () {}");else if(g==="%AsyncGeneratorFunction%")I=Y5("async function* () {}");else if(g==="%AsyncGenerator%"){var i=e("%AsyncGeneratorFunction%");i&&(I=i.prototype)}else if(g==="%AsyncIteratorPrototype%"){var n=e("%AsyncGenerator%");n&&xi&&(I=xi(n.prototype))}return Gd[g]=I,I},hIe={"%ArrayBufferPrototype%":["ArrayBuffer","prototype"],"%ArrayPrototype%":["Array","prototype"],"%ArrayProto_entries%":["Array","prototype","entries"],"%ArrayProto_forEach%":["Array","prototype","forEach"],"%ArrayProto_keys%":["Array","prototype","keys"],"%ArrayProto_values%":["Array","prototype","values"],"%AsyncFunctionPrototype%":["AsyncFunction","prototype"],"%AsyncGenerator%":["AsyncGeneratorFunction","prototype"],"%AsyncGeneratorPrototype%":["AsyncGeneratorFunction","prototype","prototype"],"%BooleanPrototype%":["Boolean","prototype"],"%DataViewPrototype%":["DataView","prototype"],"%DatePrototype%":["Date","prototype"],"%ErrorPrototype%":["Error","prototype"],"%EvalErrorPrototype%":["EvalError","prototype"],"%Float32ArrayPrototype%":["Float32Array","prototype"],"%Float64ArrayPrototype%":["Float64Array","prototype"],"%FunctionPrototype%":["Function","prototype"],"%Generator%":["GeneratorFunction","prototype"],"%GeneratorPrototype%":["GeneratorFunction","prototype","prototype"],"%Int8ArrayPrototype%":["Int8Array","prototype"],"%Int16ArrayPrototype%":["Int16Array","prototype"],"%Int32ArrayPrototype%":["Int32Array","prototype"],"%JSONParse%":["JSON","parse"],"%JSONStringify%":["JSON","stringify"],"%MapPrototype%":["Map","prototype"],"%NumberPrototype%":["Number","prototype"],"%ObjectPrototype%":["Object","prototype"],"%ObjProto_toString%":["Object","prototype","toString"],"%ObjProto_valueOf%":["Object","prototype","valueOf"],"%PromisePrototype%":["Promise","prototype"],"%PromiseProto_then%":["Promise","prototype","then"],"%Promise_all%":["Promise","all"],"%Promise_reject%":["Promise","reject"],"%Promise_resolve%":["Promise","resolve"],"%RangeErrorPrototype%":["RangeError","prototype"],"%ReferenceErrorPrototype%":["ReferenceError","prototype"],"%RegExpPrototype%":["RegExp","prototype"],"%SetPrototype%":["Set","prototype"],"%SharedArrayBufferPrototype%":["SharedArrayBuffer","prototype"],"%StringPrototype%":["String","prototype"],"%SymbolPrototype%":["Symbol","prototype"],"%SyntaxErrorPrototype%":["SyntaxError","prototype"],"%TypedArrayPrototype%":["TypedArray","prototype"],"%TypeErrorPrototype%":["TypeError","prototype"],"%Uint8ArrayPrototype%":["Uint8Array","prototype"],"%Uint8ClampedArrayPrototype%":["Uint8ClampedArray","prototype"],"%Uint16ArrayPrototype%":["Uint16Array","prototype"],"%Uint32ArrayPrototype%":["Uint32Array","prototype"],"%URIErrorPrototype%":["URIError","prototype"],"%WeakMapPrototype%":["WeakMap","prototype"],"%WeakSetPrototype%":["WeakSet","prototype"]},WS=iQ,r9=Qs,xlt=WS.call(Function.call,Array.prototype.concat),Flt=WS.call(Function.apply,Array.prototype.splice),mIe=WS.call(Function.call,String.prototype.replace),o9=WS.call(Function.call,String.prototype.slice),Elt=WS.call(Function.call,RegExp.prototype.exec),Mlt=/[^%.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|%$))/g,zlt=/\\(\\)?/g,Plt=function(g){var I=o9(g,0,1),i=o9(g,-1);if(I==="%"&&i!=="%")throw new Bb("invalid intrinsic syntax, expected closing `%`");if(i==="%"&&I!=="%")throw new Bb("invalid intrinsic syntax, expected opening `%`");var n=[];return mIe(g,Mlt,function(C,r,o,A){n[n.length]=o?mIe(A,zlt,"$1"):r||C}),n},Jlt=function(g,I){var i=g,n;if(r9(hIe,i)&&(n=hIe[i],i="%"+n[0]+"%"),r9(Gd,i)){var C=Gd[i];if(C===Af&&(C=Dlt(i)),typeof C>"u"&&!I)throw new Sp("intrinsic "+g+" exists, but is not available. Please file an issue!");return{alias:n,name:i,value:C}}throw new Bb("intrinsic "+g+" does not exist!")},Rg=function(g,I){if(typeof g!="string"||g.length===0)throw new Sp("intrinsic name must be a non-empty string");if(arguments.length>1&&typeof I!="boolean")throw new Sp('"allowMissing" argument must be a boolean');if(Elt(/^%?[^%]*%?$/,g)===null)throw new Bb("`%` may not be present anywhere but at the beginning and end of the intrinsic name");var i=Plt(g),n=i.length>0?i[0]:"",C=Jlt("%"+n+"%",I),r=C.name,o=C.value,A=!1,s=C.alias;s&&(n=s[0],Flt(i,xlt([0,1],s)));for(var a=1,l=!0;a=i.length){var h=Zd(o,c);l=!!h,l&&"get"in h&&!("originalValue"in h.get)?o=h.get:o=o[c]}else l=r9(o,c),o=o[c];l&&!A&&(Gd[r]=o)}}return o},Olt=Rg,R3=Olt("%Object.defineProperty%",!0),W3=function(){if(R3)try{return R3({},"a",{value:1}),!0}catch{return!1}return!1};W3.hasArrayLengthDefineBug=function(){if(!W3())return null;try{return R3([],"length",{value:1}).length!==1}catch{return!0}};var oN=W3,_lt=Rg,w1=_lt("%Object.getOwnPropertyDescriptor%",!0);if(w1)try{w1([],"length")}catch{w1=null}var nQ=w1,Llt=oN(),CQ=Rg,XG=Llt&&CQ("%Object.defineProperty%",!0);if(XG)try{XG({},"a",{value:1})}catch{XG=!1}var Ult=CQ("%SyntaxError%"),Nm=CQ("%TypeError%"),fIe=nQ,rGe=function(g,I,i){if(!g||typeof g!="object"&&typeof g!="function")throw new Nm("`obj` must be an object or a function`");if(typeof I!="string"&&typeof I!="symbol")throw new Nm("`property` must be a string or a symbol`");if(arguments.length>3&&typeof arguments[3]!="boolean"&&arguments[3]!==null)throw new Nm("`nonEnumerable`, if provided, must be a boolean or null");if(arguments.length>4&&typeof arguments[4]!="boolean"&&arguments[4]!==null)throw new Nm("`nonWritable`, if provided, must be a boolean or null");if(arguments.length>5&&typeof arguments[5]!="boolean"&&arguments[5]!==null)throw new Nm("`nonConfigurable`, if provided, must be a boolean or null");if(arguments.length>6&&typeof arguments[6]!="boolean")throw new Nm("`loose`, if provided, must be a boolean");var n=arguments.length>3?arguments[3]:null,C=arguments.length>4?arguments[4]:null,r=arguments.length>5?arguments[5]:null,o=arguments.length>6?arguments[6]:!1,A=!!fIe&&fIe(g,I);if(XG)XG(g,I,{configurable:r===null&&A?A.configurable:!r,enumerable:n===null&&A?A.enumerable:!n,value:i,writable:C===null&&A?A.writable:!C});else if(o||!n&&!C&&!r)g[I]=i;else throw new Ult("This environment does not support defining a property as non-configurable, non-writable, or non-enumerable.")},Qlt=IGe,jlt=typeof Symbol=="function"&&typeof Symbol("foo")=="symbol",$lt=Object.prototype.toString,qlt=Array.prototype.concat,pIe=rGe,ect=function(e){return typeof e=="function"&&$lt.call(e)==="[object Function]"},oGe=oN(),tct=function(e,g,I,i){if(g in e){if(i===!0){if(e[g]===I)return}else if(!ect(i)||!i())return}oGe?pIe(e,g,I,!0):pIe(e,g,I)},AGe=function(e,g){var I=arguments.length>2?arguments[2]:{},i=Qlt(g);jlt&&(i=qlt.call(i,Object.getOwnPropertySymbols(g)));for(var n=0;n4294967295||Ict(I)!==I)throw new ZIe("`length` must be a positive 32-bit integer");var i=arguments.length>2&&!!arguments[2],n=!0,C=!0;if("length"in g&&yIe){var r=yIe(g,"length");r&&!r.configurable&&(n=!1),r&&!r.writable&&(C=!1)}return(n||C||!i)&&(gct?bIe(g,"length",I,!0,!0):bIe(g,"length",I)),g};(function(e){var g=iQ,I=Rg,i=ict,n=I("%TypeError%"),C=I("%Function.prototype.apply%"),r=I("%Function.prototype.call%"),o=I("%Reflect.apply%",!0)||g.call(r,C),A=I("%Object.defineProperty%",!0),s=I("%Math.max%");if(A)try{A({},"a",{value:1})}catch{A=null}e.exports=function(c){if(typeof c!="function")throw new n("a function is required");var u=o(g,r,arguments);return i(u,1+s(0,c.length-(arguments.length-1)),!0)};var a=function(){return o(g,C,arguments)};A?A(e.exports,"apply",{value:a}):e.exports.apply=a})(aGe);var js=aGe.exports,lGe=Rg,cGe=js,nct=cGe(lGe("String.prototype.indexOf")),sC=function(g,I){var i=lGe(g,!!I);return typeof i=="function"&&nct(g,".prototype.")>-1?cGe(i):i},Cct=IGe,uGe=IQ(),dGe=sC,GIe=Object,rct=dGe("Array.prototype.push"),vIe=dGe("Object.prototype.propertyIsEnumerable"),oct=uGe?Object.getOwnPropertySymbols:null,hGe=function(g,I){if(g==null)throw new TypeError("target must be an object");var i=GIe(g);if(arguments.length===1)return i;for(var n=1;n= 0");if(a>r)throw new I("length is greater than (2**32 - 1)");var l=arguments.length>1?arguments[1]:g,c=[];if(l!==g){if(!A)throw new i("ArrayCreate: a `proto` argument that is not `Array.prototype` is not supported in an environment that does not support setting the [[Prototype]]");A(c,l)}return a!==0&&(c.length=a),c},F5}const yct={},Zct=Object.freeze(Object.defineProperty({__proto__:null,default:yct},Symbol.toStringTag,{value:"Module"})),Gct=Os(Zct);var oQ=typeof Map=="function"&&Map.prototype,E5=Object.getOwnPropertyDescriptor&&oQ?Object.getOwnPropertyDescriptor(Map.prototype,"size"):null,A9=oQ&&E5&&typeof E5.get=="function"?E5.get:null,wIe=oQ&&Map.prototype.forEach,AQ=typeof Set=="function"&&Set.prototype,M5=Object.getOwnPropertyDescriptor&&AQ?Object.getOwnPropertyDescriptor(Set.prototype,"size"):null,a9=AQ&&M5&&typeof M5.get=="function"?M5.get:null,VIe=AQ&&Set.prototype.forEach,vct=typeof WeakMap=="function"&&WeakMap.prototype,HG=vct?WeakMap.prototype.has:null,Bct=typeof WeakSet=="function"&&WeakSet.prototype,TG=Bct?WeakSet.prototype.has:null,Sct=typeof WeakRef=="function"&&WeakRef.prototype,RIe=Sct?WeakRef.prototype.deref:null,wct=Boolean.prototype.valueOf,Vct=Object.prototype.toString,Rct=Function.prototype.toString,Wct=String.prototype.match,aQ=String.prototype.slice,rc=String.prototype.replace,Xct=String.prototype.toUpperCase,WIe=String.prototype.toLowerCase,yGe=RegExp.prototype.test,XIe=Array.prototype.concat,HA=Array.prototype.join,Hct=Array.prototype.slice,HIe=Math.floor,X3=typeof BigInt=="function"?BigInt.prototype.valueOf:null,z5=Object.getOwnPropertySymbols,H3=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Symbol.prototype.toString:null,Sb=typeof Symbol=="function"&&typeof Symbol.iterator=="object",Nn=typeof Symbol=="function"&&Symbol.toStringTag&&(typeof Symbol.toStringTag===Sb||"symbol")?Symbol.toStringTag:null,ZGe=Object.prototype.propertyIsEnumerable,TIe=(typeof Reflect=="function"?Reflect.getPrototypeOf:Object.getPrototypeOf)||([].__proto__===Array.prototype?function(e){return e.__proto__}:null);function NIe(e,g){if(e===1/0||e===-1/0||e!==e||e&&e>-1e3&&e<1e3||yGe.call(/e/,g))return g;var I=/[0-9](?=(?:[0-9]{3})+(?![0-9]))/g;if(typeof e=="number"){var i=e<0?-HIe(-e):HIe(e);if(i!==e){var n=String(i),C=aQ.call(g,n.length+1);return rc.call(n,I,"$&_")+"."+rc.call(rc.call(C,/([0-9]{3})/g,"$&_"),/_$/,"")}}return rc.call(g,I,"$&_")}var T3=Gct,kIe=T3.custom,YIe=BGe(kIe)?kIe:null,GGe=function e(g,I,i,n){var C=I||{};if(Yl(C,"quoteStyle")&&C.quoteStyle!=="single"&&C.quoteStyle!=="double")throw new TypeError('option "quoteStyle" must be "single" or "double"');if(Yl(C,"maxStringLength")&&(typeof C.maxStringLength=="number"?C.maxStringLength<0&&C.maxStringLength!==1/0:C.maxStringLength!==null))throw new TypeError('option "maxStringLength", if provided, must be a positive integer, Infinity, or `null`');var r=Yl(C,"customInspect")?C.customInspect:!0;if(typeof r!="boolean"&&r!=="symbol")throw new TypeError("option \"customInspect\", if provided, must be `true`, `false`, or `'symbol'`");if(Yl(C,"indent")&&C.indent!==null&&C.indent!==" "&&!(parseInt(C.indent,10)===C.indent&&C.indent>0))throw new TypeError('option "indent" must be "\\t", an integer > 0, or `null`');if(Yl(C,"numericSeparator")&&typeof C.numericSeparator!="boolean")throw new TypeError('option "numericSeparator", if provided, must be `true` or `false`');var o=C.numericSeparator;if(typeof g>"u")return"undefined";if(g===null)return"null";if(typeof g=="boolean")return g?"true":"false";if(typeof g=="string")return wGe(g,C);if(typeof g=="number"){if(g===0)return 1/0/g>0?"0":"-0";var A=String(g);return o?NIe(g,A):A}if(typeof g=="bigint"){var s=String(g)+"n";return o?NIe(g,s):s}var a=typeof C.depth>"u"?5:C.depth;if(typeof i>"u"&&(i=0),i>=a&&a>0&&typeof g=="object")return N3(g)?"[Array]":"[Object]";var l=Qct(C,i);if(typeof n>"u")n=[];else if(SGe(n,g)>=0)return"[Circular]";function c(W,R,H){if(R&&(n=Hct.call(n),n.push(R)),H){var Y={depth:C.depth};return Yl(C,"quoteStyle")&&(Y.quoteStyle=C.quoteStyle),e(W,Y,i+1,n)}return e(W,C,i+1,n)}if(typeof g=="function"&&!KIe(g)){var u=Ect(g),d=PV(g,c);return"[Function"+(u?": "+u:" (anonymous)")+"]"+(d.length>0?" { "+HA.call(d,", ")+" }":"")}if(BGe(g)){var h=Sb?rc.call(String(g),/^(Symbol\(.*\))_[^)]*$/,"$1"):H3.call(g);return typeof g=="object"&&!Sb?Py(h):h}if(_ct(g)){for(var m="<"+WIe.call(String(g.nodeName)),f=g.attributes||[],b=0;b",m}if(N3(g)){if(g.length===0)return"[]";var p=PV(g,c);return l&&!Uct(p)?"["+k3(p,l)+"]":"[ "+HA.call(p,", ")+" ]"}if(kct(g)){var y=PV(g,c);return!("cause"in Error.prototype)&&"cause"in g&&!ZGe.call(g,"cause")?"{ ["+String(g)+"] "+HA.call(XIe.call("[cause]: "+c(g.cause),y),", ")+" }":y.length===0?"["+String(g)+"]":"{ ["+String(g)+"] "+HA.call(y,", ")+" }"}if(typeof g=="object"&&r){if(YIe&&typeof g[YIe]=="function"&&T3)return T3(g,{depth:a-i});if(r!=="symbol"&&typeof g.inspect=="function")return g.inspect()}if(Mct(g)){var Z=[];return wIe&&wIe.call(g,function(W,R){Z.push(c(R,g,!0)+" => "+c(W,g))}),DIe("Map",A9.call(g),Z,l)}if(Jct(g)){var B=[];return VIe&&VIe.call(g,function(W){B.push(c(W,g))}),DIe("Set",a9.call(g),B,l)}if(zct(g))return P5("WeakMap");if(Oct(g))return P5("WeakSet");if(Pct(g))return P5("WeakRef");if(Kct(g))return Py(c(Number(g)));if(xct(g))return Py(c(X3.call(g)));if(Dct(g))return Py(wct.call(g));if(Yct(g))return Py(c(String(g)));if(typeof window<"u"&&g===window)return"{ [object Window] }";if(g===globalThis)return"{ [object globalThis] }";if(!Nct(g)&&!KIe(g)){var G=PV(g,c),v=TIe?TIe(g)===Object.prototype:g instanceof Object||g.constructor===Object,w=g instanceof Object?"":"null prototype",V=!v&&Nn&&Object(g)===g&&Nn in g?aQ.call($c(g),8,-1):w?"Object":"",S=v||typeof g.constructor!="function"?"":g.constructor.name?g.constructor.name+" ":"",X=S+(V||w?"["+HA.call(XIe.call([],V||[],w||[]),": ")+"] ":"");return G.length===0?X+"{}":l?X+"{"+k3(G,l)+"}":X+"{ "+HA.call(G,", ")+" }"}return String(g)};function vGe(e,g,I){var i=(I.quoteStyle||g)==="double"?'"':"'";return i+e+i}function Tct(e){return rc.call(String(e),/"/g,""")}function N3(e){return $c(e)==="[object Array]"&&(!Nn||!(typeof e=="object"&&Nn in e))}function Nct(e){return $c(e)==="[object Date]"&&(!Nn||!(typeof e=="object"&&Nn in e))}function KIe(e){return $c(e)==="[object RegExp]"&&(!Nn||!(typeof e=="object"&&Nn in e))}function kct(e){return $c(e)==="[object Error]"&&(!Nn||!(typeof e=="object"&&Nn in e))}function Yct(e){return $c(e)==="[object String]"&&(!Nn||!(typeof e=="object"&&Nn in e))}function Kct(e){return $c(e)==="[object Number]"&&(!Nn||!(typeof e=="object"&&Nn in e))}function Dct(e){return $c(e)==="[object Boolean]"&&(!Nn||!(typeof e=="object"&&Nn in e))}function BGe(e){if(Sb)return e&&typeof e=="object"&&e instanceof Symbol;if(typeof e=="symbol")return!0;if(!e||typeof e!="object"||!H3)return!1;try{return H3.call(e),!0}catch{}return!1}function xct(e){if(!e||typeof e!="object"||!X3)return!1;try{return X3.call(e),!0}catch{}return!1}var Fct=Object.prototype.hasOwnProperty||function(e){return e in this};function Yl(e,g){return Fct.call(e,g)}function $c(e){return Vct.call(e)}function Ect(e){if(e.name)return e.name;var g=Wct.call(Rct.call(e),/^function\s*([\w$]+)/);return g?g[1]:null}function SGe(e,g){if(e.indexOf)return e.indexOf(g);for(var I=0,i=e.length;Ig.maxStringLength){var I=e.length-g.maxStringLength,i="... "+I+" more character"+(I>1?"s":"");return wGe(aQ.call(e,0,g.maxStringLength),g)+i}var n=rc.call(rc.call(e,/(['\\])/g,"\\$1"),/[\x00-\x1f]/g,Lct);return vGe(n,"single",g)}function Lct(e){var g=e.charCodeAt(0),I={8:"b",9:"t",10:"n",12:"f",13:"r"}[g];return I?"\\"+I:"\\x"+(g<16?"0":"")+Xct.call(g.toString(16))}function Py(e){return"Object("+e+")"}function P5(e){return e+" { ? }"}function DIe(e,g,I,i){var n=i?k3(I,i):HA.call(I,", ");return e+" ("+g+") {"+n+"}"}function Uct(e){for(var g=0;g=0)return!1;return!0}function Qct(e,g){var I;if(e.indent===" ")I=" ";else if(typeof e.indent=="number"&&e.indent>0)I=HA.call(Array(e.indent+1)," ");else return null;return{base:I,prev:HA.call(Array(g+1),I)}}function k3(e,g){if(e.length===0)return"";var I=` +`+g.prev+g.base;return I+HA.call(e,","+I)+` +`+g.prev}function PV(e,g){var I=N3(e),i=[];if(I){i.length=e.length;for(var n=0;n"u")return"Undefined";if(typeof g=="function"||typeof g=="object")return"Object";if(typeof g=="number")return"Number";if(typeof g=="boolean")return"Boolean";if(typeof g=="string")return"String"}),O5}var _5,EIe;function un(){if(EIe)return _5;EIe=1;var e=jct();return _5=function(I){return typeof I=="symbol"?"Symbol":typeof I=="bigint"?"BigInt":e(I)},_5}var $ct=Rg,MIe=$ct("%TypeError%"),qct=GGe,eut=qc(),tut=un(),XS=function(g,I){if(tut(g)!=="Object")throw new MIe("Assertion failed: Type(O) is not Object");if(!eut(I))throw new MIe("Assertion failed: IsPropertyKey(P) is not true, got "+qct(I));return g[I]},L5,zIe;function VGe(){if(zIe)return L5;zIe=1;var e=Rg,g=e("%Array%"),I=!g.isArray&&sC("Object.prototype.toString");return L5=g.isArray||function(n){return I(n)==="[object Array]"},L5}var U5,PIe;function sQ(){return PIe||(PIe=1,U5=VGe()),U5}var JV={exports:{}},Q5,JIe;function gut(){return JIe||(JIe=1,Q5=Rg),Q5}var j5,OIe;function lQ(){if(OIe)return j5;OIe=1;var e=Rg,g=Qs,I=e("%TypeError%");return j5=function(n,C){if(n.Type(C)!=="Object")return!1;var r={"[[Configurable]]":!0,"[[Enumerable]]":!0,"[[Get]]":!0,"[[Set]]":!0,"[[Value]]":!0,"[[Writable]]":!0};for(var o in C)if(g(C,o)&&!r[o])return!1;if(n.IsDataDescriptor(C)&&n.IsAccessorDescriptor(C))throw new I("Property Descriptors may not be both accessor and data descriptors");return!0},j5}var $5,_Ie;function RGe(){if(_Ie)return $5;_Ie=1;var e=oN,g=Rg,I=e()&&g("%Object.defineProperty%",!0),i=e.hasArrayLengthDefineBug(),n=i&&VGe(),C=sC,r=C("Object.prototype.propertyIsEnumerable");return $5=function(A,s,a,l,c,u){if(!I){if(!A(u)||!u["[[Configurable]]"]||!u["[[Writable]]"]||c in l&&r(l,c)!==!!u["[[Enumerable]]"])return!1;var d=u["[[Value]]"];return l[c]=d,s(l[c],d)}return i&&c==="length"&&"[[Value]]"in u&&n(l)&&l.length!==u["[[Value]]"]?(l.length=u["[[Value]]"],l.length===u["[[Value]]"]):(I(l,c,a(u)),!0)},$5}var q5,LIe;function Iut(){if(LIe)return q5;LIe=1;var e=Qs;return q5=function(I){return e(I,"[[StartIndex]]")&&e(I,"[[EndIndex]]")&&I["[[StartIndex]]"]>=0&&I["[[EndIndex]]"]>=I["[[StartIndex]]"]&&String(parseInt(I["[[StartIndex]]"],10))===String(I["[[StartIndex]]"])&&String(parseInt(I["[[EndIndex]]"],10))===String(I["[[EndIndex]]"])},q5}var eD,UIe;function aN(){if(UIe)return eD;UIe=1;var e=Rg,g=e("%TypeError%"),I=e("%SyntaxError%"),i=Qs,n=rQ(),C=Iut(),r={"Property Descriptor":function(A){var s={"[[Configurable]]":!0,"[[Enumerable]]":!0,"[[Get]]":!0,"[[Set]]":!0,"[[Value]]":!0,"[[Writable]]":!0};if(!A)return!1;for(var a in A)if(i(A,a)&&!s[a])return!1;var l=i(A,"[[Value]]"),c=i(A,"[[Get]]")||i(A,"[[Set]]");if(l&&c)throw new g("Property Descriptors may not be both accessor and data descriptors");return!0},"Match Record":C,"Iterator Record":function(A){return i(A,"[[Iterator]]")&&i(A,"[[NextMethod]]")&&i(A,"[[Done]]")},"PromiseCapability Record":function(A){return!!A&&i(A,"[[Resolve]]")&&typeof A["[[Resolve]]"]=="function"&&i(A,"[[Reject]]")&&typeof A["[[Reject]]"]=="function"&&i(A,"[[Promise]]")&&A["[[Promise]]"]&&typeof A["[[Promise]]"].then=="function"},"AsyncGeneratorRequest Record":function(A){return!!A&&i(A,"[[Completion]]")&&i(A,"[[Capability]]")&&r["PromiseCapability Record"](A["[[Capability]]"])},"RegExp Record":function(A){return A&&i(A,"[[IgnoreCase]]")&&typeof A["[[IgnoreCase]]"]=="boolean"&&i(A,"[[Multiline]]")&&typeof A["[[Multiline]]"]=="boolean"&&i(A,"[[DotAll]]")&&typeof A["[[DotAll]]"]=="boolean"&&i(A,"[[Unicode]]")&&typeof A["[[Unicode]]"]=="boolean"&&i(A,"[[CapturingGroupsCount]]")&&typeof A["[[CapturingGroupsCount]]"]=="number"&&n(A["[[CapturingGroupsCount]]"])&&A["[[CapturingGroupsCount]]"]>=0}};return eD=function(A,s,a,l){var c=r[s];if(typeof c!="function")throw new I("unknown record type: "+s);if(A(l)!=="Object"||!c(l))throw new g(a+" must be a "+s)},eD}var tD,QIe;function iut(){return QIe||(QIe=1,tD=function(g){if(typeof g>"u")return g;var I={};return"[[Value]]"in g&&(I.value=g["[[Value]]"]),"[[Writable]]"in g&&(I.writable=!!g["[[Writable]]"]),"[[Get]]"in g&&(I.get=g["[[Get]]"]),"[[Set]]"in g&&(I.set=g["[[Set]]"]),"[[Enumerable]]"in g&&(I.enumerable=!!g["[[Enumerable]]"]),"[[Configurable]]"in g&&(I.configurable=!!g["[[Configurable]]"]),I}),tD}var gD,jIe;function WGe(){if(jIe)return gD;jIe=1;var e=aN(),g=iut(),I=un();return gD=function(n){return typeof n<"u"&&e(I,"Property Descriptor","Desc",n),g(n)},gD}var ID,$Ie;function sN(){if($Ie)return ID;$Ie=1;var e=Qs,g=un(),I=aN();return ID=function(n){return!(typeof n>"u"||(I(g,"Property Descriptor","Desc",n),!e(n,"[[Get]]")&&!e(n,"[[Set]]")))},ID}var iD,qIe;function lN(){if(qIe)return iD;qIe=1;var e=Qs,g=un(),I=aN();return iD=function(n){return!(typeof n>"u"||(I(g,"Property Descriptor","Desc",n),!e(n,"[[Value]]")&&!e(n,"[[Writable]]")))},iD}var nD,eie;function cQ(){if(eie)return nD;eie=1;var e=AN;return nD=function(I,i){return I===i?I===0?1/I===1/i:!0:e(I)&&e(i)},nD}var XGe=function(g){return!!g},HGe=Function.prototype.toString,Qf=typeof Reflect=="object"&&Reflect!==null&&Reflect.apply,Y3,V1;if(typeof Qf=="function"&&typeof Object.defineProperty=="function")try{Y3=Object.defineProperty({},"length",{get:function(){throw V1}}),V1={},Qf(function(){throw 42},null,Y3)}catch(e){e!==V1&&(Qf=null)}else Qf=null;var nut=/^\s*class\b/,K3=function(g){try{var I=HGe.call(g);return nut.test(I)}catch{return!1}},CD=function(g){try{return K3(g)?!1:(HGe.call(g),!0)}catch{return!1}},R1=Object.prototype.toString,Cut="[object Object]",rut="[object Function]",out="[object GeneratorFunction]",Aut="[object HTMLAllCollection]",aut="[object HTML document.all class]",sut="[object HTMLCollection]",lut=typeof Symbol=="function"&&!!Symbol.toStringTag,cut=!(0 in[,]),D3=function(){return!1};if(typeof document=="object"){var uut=document.all;R1.call(uut)===R1.call(document.all)&&(D3=function(g){if((cut||!g)&&(typeof g>"u"||typeof g=="object"))try{var I=R1.call(g);return(I===Aut||I===aut||I===sut||I===Cut)&&g("")==null}catch{}return!1})}var uQ=Qf?function(g){if(D3(g))return!0;if(!g||typeof g!="function"&&typeof g!="object")return!1;try{Qf(g,null,Y3)}catch(I){if(I!==V1)return!1}return!K3(g)&&CD(g)}:function(g){if(D3(g))return!0;if(!g||typeof g!="function"&&typeof g!="object")return!1;if(lut)return CD(g);if(K3(g))return!1;var I=R1.call(g);return I!==rut&&I!==out&&!/^\[object HTML/.test(I)?!1:CD(g)},dQ=uQ,rD,tie;function TGe(){if(tie)return rD;tie=1;var e=Qs,g=Rg,I=g("%TypeError%"),i=un(),n=XGe,C=dQ;return rD=function(o){if(i(o)!=="Object")throw new I("ToPropertyDescriptor requires an object");var A={};if(e(o,"enumerable")&&(A["[[Enumerable]]"]=n(o.enumerable)),e(o,"configurable")&&(A["[[Configurable]]"]=n(o.configurable)),e(o,"value")&&(A["[[Value]]"]=o.value),e(o,"writable")&&(A["[[Writable]]"]=n(o.writable)),e(o,"get")){var s=o.get;if(typeof s<"u"&&!C(s))throw new I("getter must be a function");A["[[Get]]"]=s}if(e(o,"set")){var a=o.set;if(typeof a<"u"&&!C(a))throw new I("setter must be a function");A["[[Set]]"]=a}if((e(A,"[[Get]]")||e(A,"[[Set]]"))&&(e(A,"[[Value]]")||e(A,"[[Writable]]")))throw new I("Invalid property descriptor. Cannot both specify accessors and a value or writable attribute");return A},rD}var oD,gie;function dut(){if(gie)return oD;gie=1;var e=Rg,g=e("%TypeError%"),I=lQ(),i=RGe(),n=WGe(),C=sN(),r=lN(),o=qc(),A=cQ(),s=TGe(),a=un();return oD=function(c,u,d){if(a(c)!=="Object")throw new g("Assertion failed: Type(O) is not Object");if(!o(u))throw new g("Assertion failed: IsPropertyKey(P) is not true");var h=I({Type:a,IsDataDescriptor:r,IsAccessorDescriptor:C},d)?d:s(d);if(!I({Type:a,IsDataDescriptor:r,IsAccessorDescriptor:C},h))throw new g("Assertion failed: Desc is not a valid Property Descriptor");return i(r,A,n,c,u,h)},oD}var Iie;function hut(){if(Iie)return JV.exports;Iie=1;var e=gut(),g=e("%Reflect.construct%",!0),I=dut();try{I({},"",{"[[Get]]":function(){}})}catch{I=null}if(I&&g){var i={},n={};I(n,"length",{"[[Get]]":function(){throw i},"[[Enumerable]]":!0}),JV.exports=function(r){try{g(r,n)}catch(o){return o===i}}}else JV.exports=function(r){return typeof r=="function"&&!!r.prototype};return JV.exports}var NGe=Rg,iie=NGe("%Symbol.species%",!0),nie=NGe("%TypeError%"),Cie=bct(),rie=XS,mut=sQ(),fut=hut(),put=un(),but=rQ(),kGe=function(g,I){if(!but(I)||I<0)throw new nie("Assertion failed: length must be an integer >= 0");var i=mut(g);if(!i)return Cie(I);var n=rie(g,"constructor");if(iie&&put(n)==="Object"&&(n=rie(n,iie),n===null&&(n=void 0)),typeof n>"u")return Cie(I);if(!fut(n))throw new nie("C must be a constructor");return new n(I)},YGe=Number.MAX_SAFE_INTEGER||9007199254740991,AD,oie;function KGe(){if(oie)return AD;oie=1;var e=Rg,g=sC,I=e("%TypeError%"),i=sQ(),n=e("%Reflect.apply%",!0)||g("Function.prototype.apply");return AD=function(r,o){var A=arguments.length>2?arguments[2]:[];if(!i(A))throw new I("Assertion failed: optional `argumentsList`, if provided, must be a List");return n(r,o,A)},AD}var aD,Aie;function DGe(){return Aie||(Aie=1,aD=function(g){return g===null||typeof g!="function"&&typeof g!="object"}),aD}var sD,aie;function yut(){if(aie)return sD;aie=1;var e=Rg,g=e("%Object.preventExtensions%",!0),I=e("%Object.isExtensible%",!0),i=DGe();return sD=g?function(C){return!i(C)&&I(C)}:function(C){return!i(C)},sD}var lD,sie;function Zut(){return sie||(sie=1,lD=function(g,I){return!!I&&typeof I=="object"&&"[[Enumerable]]"in I&&"[[Configurable]]"in I&&(g.IsAccessorDescriptor(I)||g.IsDataDescriptor(I))}),lD}var cD,lie;function Gut(){if(lie)return cD;lie=1;var e=aN(),g=sN(),I=lN(),i=un();return cD=function(C){return typeof C>"u"?!1:(e(i,"Property Descriptor","Desc",C),!g(C)&&!I(C))},cD}var uD,cie;function vut(){if(cie)return uD;cie=1;var e=Rg,g=e("%TypeError%"),I=RGe(),i=Zut(),n=lQ(),C=WGe(),r=sN(),o=lN(),A=Gut(),s=qc(),a=cQ(),l=un();return uD=function(u,d,h,m,f){var b=l(u);if(b!=="Undefined"&&b!=="Object")throw new g("Assertion failed: O must be undefined or an Object");if(!s(d))throw new g("Assertion failed: P must be a Property Key");if(l(h)!=="Boolean")throw new g("Assertion failed: extensible must be a Boolean");if(!n({Type:l,IsDataDescriptor:o,IsAccessorDescriptor:r},m))throw new g("Assertion failed: Desc must be a Property Descriptor");if(l(f)!=="Undefined"&&!n({Type:l,IsDataDescriptor:o,IsAccessorDescriptor:r},f))throw new g("Assertion failed: current must be a Property Descriptor, or undefined");if(l(f)==="Undefined")return h?b==="Undefined"?!0:r(m)?I(o,a,C,u,d,m):I(o,a,C,u,d,{"[[Configurable]]":!!m["[[Configurable]]"],"[[Enumerable]]":!!m["[[Enumerable]]"],"[[Value]]":m["[[Value]]"],"[[Writable]]":!!m["[[Writable]]"]}):!1;if(!i({IsAccessorDescriptor:r,IsDataDescriptor:o},f))throw new g("`current`, when present, must be a fully populated and valid Property Descriptor");if(!f["[[Configurable]]"]){if("[[Configurable]]"in m&&m["[[Configurable]]"]||"[[Enumerable]]"in m&&!a(m["[[Enumerable]]"],f["[[Enumerable]]"])||!A(m)&&!a(r(m),r(f)))return!1;if(r(f)){if("[[Get]]"in m&&!a(m["[[Get]]"],f["[[Get]]"])||"[[Set]]"in m&&!a(m["[[Set]]"],f["[[Set]]"]))return!1}else if(!f["[[Writable]]"]&&("[[Writable]]"in m&&m["[[Writable]]"]||"[[Value]]"in m&&!a(m["[[Value]]"],f["[[Value]]"])))return!1}if(b!=="Undefined"){var p,y;return o(f)&&r(m)?(p=("[[Configurable]]"in m?m:f)["[[Configurable]]"],y=("[[Enumerable]]"in m?m:f)["[[Enumerable]]"],I(o,a,C,u,d,{"[[Configurable]]":!!p,"[[Enumerable]]":!!y,"[[Get]]":("[[Get]]"in m?m:f)["[[Get]]"],"[[Set]]":("[[Set]]"in m?m:f)["[[Set]]"]})):r(f)&&o(m)?(p=("[[Configurable]]"in m?m:f)["[[Configurable]]"],y=("[[Enumerable]]"in m?m:f)["[[Enumerable]]"],I(o,a,C,u,d,{"[[Configurable]]":!!p,"[[Enumerable]]":!!y,"[[Value]]":("[[Value]]"in m?m:f)["[[Value]]"],"[[Writable]]":!!("[[Writable]]"in m?m:f)["[[Writable]]"]})):I(o,a,C,u,d,m)}return!0},uD}var dD,uie;function But(){if(uie)return dD;uie=1;var e=Rg,g=nQ,I=e("%SyntaxError%"),i=e("%TypeError%"),n=lQ(),C=sN(),r=lN(),o=yut(),A=qc(),s=TGe(),a=cQ(),l=un(),c=vut();return dD=function(d,h,m){if(l(d)!=="Object")throw new i("Assertion failed: O must be an Object");if(!A(h))throw new i("Assertion failed: P must be a Property Key");if(!n({Type:l,IsDataDescriptor:r,IsAccessorDescriptor:C},m))throw new i("Assertion failed: Desc must be a Property Descriptor");if(!g){if(C(m))throw new I("This environment does not support accessor property descriptors.");var f=!(h in d)&&m["[[Writable]]"]&&m["[[Enumerable]]"]&&m["[[Configurable]]"]&&"[[Value]]"in m,b=h in d&&(!("[[Configurable]]"in m)||m["[[Configurable]]"])&&(!("[[Enumerable]]"in m)||m["[[Enumerable]]"])&&(!("[[Writable]]"in m)||m["[[Writable]]"])&&"[[Value]]"in m;if(f||b)return d[h]=m["[[Value]]"],a(d[h],m["[[Value]]"]);throw new I("This environment does not support defining non-writable, non-enumerable, or non-configurable properties")}var p=g(d,h),y=p&&s(p),Z=o(d);return c(d,h,Z,m,y)},dD}var hD,die;function Sut(){if(die)return hD;die=1;var e=Rg,g=e("%TypeError%"),I=qc(),i=But(),n=un();return hD=function(r,o,A){if(n(r)!=="Object")throw new g("Assertion failed: Type(O) is not Object");if(!I(o))throw new g("Assertion failed: IsPropertyKey(P) is not true");var s={"[[Configurable]]":!0,"[[Enumerable]]":!0,"[[Value]]":A,"[[Writable]]":!0};return i(r,o,s)},hD}var mD,hie;function xGe(){if(hie)return mD;hie=1;var e=Rg,g=e("%TypeError%"),I=Sut(),i=qc(),n=un();return mD=function(r,o,A){if(n(r)!=="Object")throw new g("Assertion failed: Type(O) is not Object");if(!i(o))throw new g("Assertion failed: IsPropertyKey(P) is not true");var s=I(r,o,A);if(!s)throw new g("unable to create data property")},mD}var fD,mie;function FGe(){if(mie)return fD;mie=1;var e=Rg,g=e("%TypeError%"),I=qc(),i=un();return fD=function(C,r){if(i(C)!=="Object")throw new g("Assertion failed: `O` must be an Object");if(!I(r))throw new g("Assertion failed: `P` must be a Property Key");return r in C},fD}var pD,fie;function wut(){return fie||(fie=1,pD=function(g){return g===null||typeof g!="function"&&typeof g!="object"}),pD}var Vut=IQ,HS=function(){return Vut()&&!!Symbol.toStringTag},bD,pie;function Rut(){if(pie)return bD;pie=1;var e=Date.prototype.getDay,g=function(r){try{return e.call(r),!0}catch{return!1}},I=Object.prototype.toString,i="[object Date]",n=HS();return bD=function(r){return typeof r!="object"||r===null?!1:n?g(r):I.call(r)===i},bD}var OV={exports:{}},bie;function Wut(){if(bie)return OV.exports;bie=1;var e=Object.prototype.toString,g=iGe();if(g){var I=Symbol.prototype.toString,i=/^Symbol\(.*\)$/,n=function(r){return typeof r.valueOf()!="symbol"?!1:i.test(I.call(r))};OV.exports=function(r){if(typeof r=="symbol")return!0;if(e.call(r)!=="[object Symbol]")return!1;try{return n(r)}catch{return!1}}}else OV.exports=function(r){return!1};return OV.exports}var yD,yie;function Xut(){if(yie)return yD;yie=1;var e=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol",g=wut(),I=uQ,i=Rut(),n=Wut(),C=function(A,s){if(typeof A>"u"||A===null)throw new TypeError("Cannot call method on "+A);if(typeof s!="string"||s!=="number"&&s!=="string")throw new TypeError('hint must be "string" or "number"');var a=s==="string"?["toString","valueOf"]:["valueOf","toString"],l,c,u;for(u=0;u1&&(arguments[1]===String?s="string":arguments[1]===Number&&(s="number"));var a;if(e&&(Symbol.toPrimitive?a=r(A,Symbol.toPrimitive):n(A)&&(a=Symbol.prototype.valueOf)),typeof a<"u"){var l=a.call(A,s);if(g(l))return l;throw new TypeError("unable to convert exotic object to primitive")}return s==="default"&&(i(A)||n(A))&&(s="string"),C(A,s==="default"?"number":s)},yD}var ZD,Zie;function Hut(){if(Zie)return ZD;Zie=1;var e=Xut();return ZD=function(I){return arguments.length>1?e(I,arguments[1]):e(I)},ZD}var x3=sC,EGe=HS(),MGe,zGe,F3,E3;if(EGe){MGe=x3("Object.prototype.hasOwnProperty"),zGe=x3("RegExp.prototype.exec"),F3={};var GD=function(){throw F3};E3={toString:GD,valueOf:GD},typeof Symbol.toPrimitive=="symbol"&&(E3[Symbol.toPrimitive]=GD)}var Tut=x3("Object.prototype.toString"),Nut=Object.getOwnPropertyDescriptor,kut="[object RegExp]",PGe=EGe?function(g){if(!g||typeof g!="object")return!1;var I=Nut(g,"lastIndex"),i=I&&MGe(I,"value");if(!i)return!1;try{zGe(g,E3)}catch(n){return n===F3}}:function(g){return!g||typeof g!="object"&&typeof g!="function"?!1:Tut(g)===kut},vD,Gie;function Yut(){if(Gie)return vD;Gie=1;var e=sC,g=Rg,I=PGe,i=e("RegExp.prototype.exec"),n=g("%TypeError%");return vD=function(r){if(!I(r))throw new n("`regex` must be a RegExp");return function(A){return i(r,A)!==null}},vD}var Kut=Rg,Dut=Kut("%TypeError%"),xut=function(g,I){if(g==null)throw new Dut(I||"Cannot call method on "+g);return g},W0=xut,JGe=Rg,Fut=JGe("%String%"),Eut=JGe("%TypeError%"),hQ=function(g){if(typeof g=="symbol")throw new Eut("Cannot convert a Symbol value to a string");return Fut(g)},Mut=W0,zut=hQ,Put=sC,vie=Put("String.prototype.replace"),OGe=/^\s$/.test("᠎"),Jut=OGe?/^[\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028\u2029\uFEFF]+/:/^[\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028\u2029\uFEFF]+/,Out=OGe?/[\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028\u2029\uFEFF]+$/:/[\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028\u2029\uFEFF]+$/,_Ge=function(){var g=zut(Mut(this));return vie(vie(g,Jut,""),Out,"")},_ut=_Ge,Bie="​",km="᠎",LGe=function(){return String.prototype.trim&&Bie.trim()===Bie&&km.trim()===km&&("_"+km).trim()==="_"+km&&(km+"_").trim()===km+"_"?String.prototype.trim:_ut},Lut=Yn,Uut=LGe,Qut=function(){var g=Uut();return Lut(String.prototype,{trim:g},{trim:function(){return String.prototype.trim!==g}}),g},jut=js,$ut=Yn,qut=W0,edt=_Ge,UGe=LGe,tdt=Qut,gdt=jut(UGe()),QGe=function(g){return qut(g),gdt(g)};$ut(QGe,{getPolyfill:UGe,implementation:edt,shim:tdt});var jGe=QGe,BD,Sie;function Idt(){if(Sie)return BD;Sie=1;var e=Rg,g=e("%Number%"),I=e("%RegExp%"),i=e("%TypeError%"),n=e("%parseInt%"),C=sC,r=Yut(),o=C("String.prototype.slice"),A=r(/^0b[01]+$/i),s=r(/^0o[0-7]+$/i),a=r(/^[-+]0x[0-9a-f]+$/i),l=["…","​","￾"].join(""),c=new I("["+l+"]","g"),u=r(c),d=jGe,h=un();return BD=function m(f){if(h(f)!=="String")throw new i("Assertion failed: `argument` is not a String");if(A(f))return g(n(o(f,2),2));if(s(f))return g(n(o(f,2),8));if(u(f)||a(f))return NaN;var b=d(f);return b!==f?m(b):g(f)},BD}var $Ge=Rg,wie=$Ge("%TypeError%"),Vie=$Ge("%Number%"),idt=DGe(),ndt=Hut(),Cdt=Idt(),rdt=function(g){var I=idt(g)?g:ndt(g,Vie);if(typeof I=="symbol")throw new wie("Cannot convert a Symbol value to a number");if(typeof I=="bigint")throw new wie("Conversion from 'BigInt' to 'number' is not allowed.");return typeof I=="string"?Cdt(I):Vie(I)},odt=un(),Adt=Math.floor,adt=function(g){return odt(g)==="BigInt"?g:Adt(g)},sdt=Rg,Rie=adt,ldt=sdt("%TypeError%"),cdt=function(g){if(typeof g!="number"&&typeof g!="bigint")throw new ldt("argument must be a Number or a BigInt");var I=g<0?-Rie(-g):Rie(g);return I===0?0:I},udt=rdt,ddt=cdt,hdt=AN,mdt=bGe,qGe=function(g){var I=udt(g);return hdt(I)||I===0?0:mdt(I)?ddt(I):I},Wie=YGe,fdt=qGe,eve=function(g){var I=fdt(g);return I<=0?0:I>Wie?Wie:I},SD,Xie;function tve(){if(Xie)return SD;Xie=1;var e=Rg,g=e("%TypeError%"),I=XS,i=eve,n=un();return SD=function(r){if(n(r)!=="Object")throw new g("Assertion failed: `obj` must be an Object");return i(I(r,"length"))},SD}var pdt=Rg,Hie=pdt("%TypeError%"),bdt=YGe,ydt=KGe(),Zdt=xGe(),Gdt=XS,vdt=FGe(),Bdt=sQ(),Sdt=tve(),Tie=hQ,wdt=function e(g,I,i,n,C){var r;arguments.length>5&&(r=arguments[5]);for(var o=n,A=0;A0&&(c=Bdt(l)),c){var u=Sdt(l);o=e(g,l,u,o,C-1)}else{if(o>=bdt)throw new Hie("index too large");Zdt(g,Tie(o),l),o+=1}}A+=1}return o},Vdt=Rg,Rdt=Vdt("%Object%"),Wdt=W0,gve=function(g){return Wdt(g),Rdt(g)},Xdt=kGe,Hdt=wdt,Tdt=XS,Ndt=qGe,kdt=eve,Ydt=gve,Ive=function(){var g=Ydt(this),I=kdt(Tdt(g,"length")),i=1;arguments.length>0&&typeof arguments[0]<"u"&&(i=Ndt(arguments[0]));var n=Xdt(g,0);return Hdt(n,g,I,0,i),n},Kdt=Ive,ive=function(){return Array.prototype.flat||Kdt},wD,Nie;function Ddt(){if(Nie)return wD;Nie=1;var e=Qs,g=typeof Symbol=="function"&&typeof Symbol.unscopables=="symbol",I=g&&Array.prototype[Symbol.unscopables],i=TypeError;return wD=function(C){if(typeof C!="string"||!C)throw new i("method must be a non-empty string");if(!e(Array.prototype,C))throw new i("method must be on Array.prototype");g&&(I[C]=!0)},wD}var VD,kie;function xdt(){if(kie)return VD;kie=1;var e=Yn,g=Ddt(),I=ive;return VD=function(){var n=I();return e(Array.prototype,{flat:n},{flat:function(){return Array.prototype.flat!==n}}),g("flat"),n},VD}var Fdt=Yn,Edt=js,Mdt=Ive,nve=ive,zdt=nve(),Pdt=xdt(),Cve=Edt(zdt);Fdt(Cve,{getPolyfill:nve,implementation:Mdt,shim:Pdt});var TS=Cve,Yie={}.hasOwnProperty,RD=Function.prototype.call,X0=RD.bind?RD.bind(Yie):function(e,g){return RD.call(Yie,e,g)},NS={},M3={exports:{}},Kie=function(e){return e!==e},rve=function(g,I){return g===0&&I===0?1/g===1/I:!!(g===I||Kie(g)&&Kie(I))},Jdt=rve,ove=function(){return typeof Object.is=="function"?Object.is:Jdt},Odt=ove,_dt=Yn,Ldt=function(){var g=Odt();return _dt(Object,{is:g},{is:function(){return Object.is!==g}}),g},Udt=Yn,Qdt=js,jdt=rve,Ave=ove,$dt=Ldt,ave=Qdt(Ave(),Object);Udt(ave,{getPolyfill:Ave,implementation:jdt,shim:$dt});var mQ=ave;(function(e,g){Object.defineProperty(g,"__esModule",{value:!0}),g.default=r;var I=n(mQ),i=n(X0);function n(o){return o&&o.__esModule?o:{default:o}}function C(o){"@babel/helpers - typeof";return C=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(A){return typeof A}:function(A){return A&&typeof Symbol=="function"&&A.constructor===Symbol&&A!==Symbol.prototype?"symbol":typeof A},C(o)}function r(o,A){if((0,I.default)(o,A))return!0;if(!o||!A||C(o)!=="object"||C(A)!=="object")return!1;var s=Object.keys(o),a=Object.keys(A);if(s.length!==a.length)return!1;s.sort(),a.sort();for(var l=0;l"u"||typeof g=="object"))try{var I=WD(g);return(I===Ght||I===Zht)&&g("")==null}catch{}return!1})}var Gve=function(){if(Zve(this)||!pht(this)&&!pve(this))throw new TypeError("Function.prototype.name sham getter called on non-function");if(mht&&hht(this,"name"))return this.name;if(this===vht)return"";var g=bve(this),I=yve(g,bht),i=I&&I[1];return i},Sht=Gve,vve=function(){return Sht},wht=Yn.supportsDescriptors,Vht=fve(),Rht=vve,xie=Object.defineProperty,Wht=TypeError,Xht=function(){var g=Rht();if(Vht)return g;if(!wht)throw new Wht("Shimming Function.prototype.name support requires ES5 property descriptor support.");var I=Function.prototype;return xie(I,"name",{configurable:!0,enumerable:!1,get:function(){var i=g.call(this);return this!==I&&xie(this,"name",{configurable:!0,enumerable:!1,value:i,writable:!1}),i}}),g},Hht=Yn,Tht=js,Bve=Gve,Nht=vve,kht=Xht,Sve=Tht(Bve);Hht(Sve,{getPolyfill:Nht,implementation:Bve,shim:kht});var pQ=Sve,wve={},Vve={};Object.defineProperty(Vve,"__esModule",{value:!0});var cN={},H0={},s9=Le&&Le.__assign||function(){return s9=Object.assign||function(e){for(var g,I=1,i=arguments.length;I0?this.children[this.children.length-1]:null},enumerable:!1,configurable:!0}),Object.defineProperty(g.prototype,"childNodes",{get:function(){return this.children},set:function(I){this.children=I},enumerable:!1,configurable:!0}),g}(bQ);lg.NodeWithChildren=dN;var Hve=function(e){eu(g,e);function g(){var I=e!==null&&e.apply(this,arguments)||this;return I.type=kC.ElementType.CDATA,I}return Object.defineProperty(g.prototype,"nodeType",{get:function(){return 4},enumerable:!1,configurable:!0}),g}(dN);lg.CDATA=Hve;var Tve=function(e){eu(g,e);function g(){var I=e!==null&&e.apply(this,arguments)||this;return I.type=kC.ElementType.Root,I}return Object.defineProperty(g.prototype,"nodeType",{get:function(){return 9},enumerable:!1,configurable:!0}),g}(dN);lg.Document=Tve;var Nve=function(e){eu(g,e);function g(I,i,n,C){n===void 0&&(n=[]),C===void 0&&(C=I==="script"?kC.ElementType.Script:I==="style"?kC.ElementType.Style:kC.ElementType.Tag);var r=e.call(this,n)||this;return r.name=I,r.attribs=i,r.type=C,r}return Object.defineProperty(g.prototype,"nodeType",{get:function(){return 1},enumerable:!1,configurable:!0}),Object.defineProperty(g.prototype,"tagName",{get:function(){return this.name},set:function(I){this.name=I},enumerable:!1,configurable:!0}),Object.defineProperty(g.prototype,"attributes",{get:function(){var I=this;return Object.keys(this.attribs).map(function(i){var n,C;return{name:i,value:I.attribs[i],namespace:(n=I["x-attribsNamespace"])===null||n===void 0?void 0:n[i],prefix:(C=I["x-attribsPrefix"])===null||C===void 0?void 0:C[i]}})},enumerable:!1,configurable:!0}),g}(dN);lg.Element=Nve;function kve(e){return(0,kC.isTag)(e)}lg.isTag=kve;function Yve(e){return e.type===kC.ElementType.CDATA}lg.isCDATA=Yve;function Kve(e){return e.type===kC.ElementType.Text}lg.isText=Kve;function Dve(e){return e.type===kC.ElementType.Comment}lg.isComment=Dve;function xve(e){return e.type===kC.ElementType.Directive}lg.isDirective=xve;function Fve(e){return e.type===kC.ElementType.Root}lg.isDocument=Fve;function Dht(e){return Object.prototype.hasOwnProperty.call(e,"children")}lg.hasChildren=Dht;function yQ(e,g){g===void 0&&(g=!1);var I;if(Kve(e))I=new Rve(e.data);else if(Dve(e))I=new Wve(e.data);else if(kve(e)){var i=g?XD(e.children):[],n=new Nve(e.name,kG({},e.attribs),i);i.forEach(function(A){return A.parent=n}),e.namespace!=null&&(n.namespace=e.namespace),e["x-attribsNamespace"]&&(n["x-attribsNamespace"]=kG({},e["x-attribsNamespace"])),e["x-attribsPrefix"]&&(n["x-attribsPrefix"]=kG({},e["x-attribsPrefix"])),I=n}else if(Yve(e)){var i=g?XD(e.children):[],C=new Hve(i);i.forEach(function(s){return s.parent=C}),I=C}else if(Fve(e)){var i=g?XD(e.children):[],r=new Tve(i);i.forEach(function(s){return s.parent=r}),e["x-mode"]&&(r["x-mode"]=e["x-mode"]),I=r}else if(xve(e)){var o=new Xve(e.name,e.data);e["x-name"]!=null&&(o["x-name"]=e["x-name"],o["x-publicId"]=e["x-publicId"],o["x-systemId"]=e["x-systemId"]),I=o}else throw new Error("Not implemented yet: ".concat(e.type));return I.startIndex=e.startIndex,I.endIndex=e.endIndex,e.sourceCodeLocation!=null&&(I.sourceCodeLocation=e.sourceCodeLocation),I}lg.cloneNode=yQ;function XD(e){for(var g=e.map(function(i){return yQ(i,!0)}),I=1;I䀾mmaĀ;d׷׸䎓;䏜reve;䄞ƀeiy؇،ؐdil;䄢rc;䄜;䐓ot;䄠r;쀀𝔊;拙pf;쀀𝔾eater̀EFGLSTصلَٖٛ٦qualĀ;Lؾؿ扥ess;招ullEqual;执reater;檢ess;扷lantEqual;橾ilde;扳cr;쀀𝒢;扫ЀAacfiosuڅڋږڛڞڪھۊRDcy;䐪Āctڐڔek;䋇;䁞irc;䄤r;愌lbertSpace;愋ǰگ\0ڲf;愍izontalLine;攀Āctۃۅòکrok;䄦mpńېۘownHumðįqual;扏܀EJOacdfgmnostuۺ۾܃܇܎ܚܞܡܨ݄ݸދޏޕcy;䐕lig;䄲cy;䐁cute耻Í䃍Āiyܓܘrc耻Î䃎;䐘ot;䄰r;愑rave耻Ì䃌ƀ;apܠܯܿĀcgܴܷr;䄪inaryI;慈lieóϝǴ݉\0ݢĀ;eݍݎ戬Āgrݓݘral;戫section;拂isibleĀCTݬݲomma;恣imes;恢ƀgptݿރވon;䄮f;쀀𝕀a;䎙cr;愐ilde;䄨ǫޚ\0ޞcy;䐆l耻Ï䃏ʀcfosuެ޷޼߂ߐĀiyޱ޵rc;䄴;䐙r;쀀𝔍pf;쀀𝕁ǣ߇\0ߌr;쀀𝒥rcy;䐈kcy;䐄΀HJacfosߤߨ߽߬߱ࠂࠈcy;䐥cy;䐌ppa;䎚Āey߶߻dil;䄶;䐚r;쀀𝔎pf;쀀𝕂cr;쀀𝒦րJTaceflmostࠥࠩࠬࡐࡣ঳সে্਷ੇcy;䐉耻<䀼ʀcmnpr࠷࠼ࡁࡄࡍute;䄹bda;䎛g;柪lacetrf;愒r;憞ƀaeyࡗ࡜ࡡron;䄽dil;䄻;䐛Āfsࡨ॰tԀACDFRTUVarࡾࢩࢱࣦ࣠ࣼयज़ΐ४Ānrࢃ࢏gleBracket;柨rowƀ;BR࢙࢚࢞憐ar;懤ightArrow;懆eiling;挈oǵࢷ\0ࣃbleBracket;柦nǔࣈ\0࣒eeVector;楡ectorĀ;Bࣛࣜ懃ar;楙loor;挊ightĀAV࣯ࣵrrow;憔ector;楎Āerँगeƀ;AVउऊऐ抣rrow;憤ector;楚iangleƀ;BEतथऩ抲ar;槏qual;抴pƀDTVषूौownVector;楑eeVector;楠ectorĀ;Bॖॗ憿ar;楘ectorĀ;B॥०憼ar;楒ightáΜs̀EFGLSTॾঋকঝঢভqualGreater;拚ullEqual;扦reater;扶ess;檡lantEqual;橽ilde;扲r;쀀𝔏Ā;eঽা拘ftarrow;懚idot;䄿ƀnpw৔ਖਛgȀLRlr৞৷ਂਐeftĀAR০৬rrow;柵ightArrow;柷ightArrow;柶eftĀarγਊightáοightáϊf;쀀𝕃erĀLRਢਬeftArrow;憙ightArrow;憘ƀchtਾੀੂòࡌ;憰rok;䅁;扪Ѐacefiosuਗ਼੝੠੷੼અઋ઎p;椅y;䐜Ādl੥੯iumSpace;恟lintrf;愳r;쀀𝔐nusPlus;戓pf;쀀𝕄cò੶;䎜ҀJacefostuણધભીଔଙඑ඗ඞcy;䐊cute;䅃ƀaey઴હાron;䅇dil;䅅;䐝ƀgswે૰଎ativeƀMTV૓૟૨ediumSpace;怋hiĀcn૦૘ë૙eryThiî૙tedĀGL૸ଆreaterGreateòٳessLesóੈLine;䀊r;쀀𝔑ȀBnptଢନଷ଺reak;恠BreakingSpace;䂠f;愕ڀ;CDEGHLNPRSTV୕ୖ୪୼஡௫ఄ౞಄ದ೘ൡඅ櫬Āou୛୤ngruent;扢pCap;扭oubleVerticalBar;戦ƀlqxஃஊ஛ement;戉ualĀ;Tஒஓ扠ilde;쀀≂̸ists;戄reater΀;EFGLSTஶஷ஽௉௓௘௥扯qual;扱ullEqual;쀀≧̸reater;쀀≫̸ess;批lantEqual;쀀⩾̸ilde;扵umpń௲௽ownHump;쀀≎̸qual;쀀≏̸eĀfsఊధtTriangleƀ;BEచఛడ拪ar;쀀⧏̸qual;括s̀;EGLSTవశ఼ౄోౘ扮qual;扰reater;扸ess;쀀≪̸lantEqual;쀀⩽̸ilde;扴estedĀGL౨౹reaterGreater;쀀⪢̸essLess;쀀⪡̸recedesƀ;ESಒಓಛ技qual;쀀⪯̸lantEqual;拠ĀeiಫಹverseElement;戌ghtTriangleƀ;BEೋೌ೒拫ar;쀀⧐̸qual;拭ĀquೝഌuareSuĀbp೨೹setĀ;E೰ೳ쀀⊏̸qual;拢ersetĀ;Eഃആ쀀⊐̸qual;拣ƀbcpഓതൎsetĀ;Eഛഞ쀀⊂⃒qual;抈ceedsȀ;ESTലള഻െ抁qual;쀀⪰̸lantEqual;拡ilde;쀀≿̸ersetĀ;E൘൛쀀⊃⃒qual;抉ildeȀ;EFT൮൯൵ൿ扁qual;扄ullEqual;扇ilde;扉erticalBar;戤cr;쀀𝒩ilde耻Ñ䃑;䎝܀Eacdfgmoprstuvලෂ෉෕ෛ෠෧෼ขภยา฿ไlig;䅒cute耻Ó䃓Āiy෎ීrc耻Ô䃔;䐞blac;䅐r;쀀𝔒rave耻Ò䃒ƀaei෮ෲ෶cr;䅌ga;䎩cron;䎟pf;쀀𝕆enCurlyĀDQฎบoubleQuote;怜uote;怘;橔Āclวฬr;쀀𝒪ash耻Ø䃘iŬื฼de耻Õ䃕es;樷ml耻Ö䃖erĀBP๋๠Āar๐๓r;怾acĀek๚๜;揞et;掴arenthesis;揜Ҁacfhilors๿ງຊຏຒດຝະ໼rtialD;戂y;䐟r;쀀𝔓i;䎦;䎠usMinus;䂱Āipຢອncareplanåڝf;愙Ȁ;eio຺ູ໠໤檻cedesȀ;EST່້໏໚扺qual;檯lantEqual;扼ilde;找me;怳Ādp໩໮uct;戏ortionĀ;aȥ໹l;戝Āci༁༆r;쀀𝒫;䎨ȀUfos༑༖༛༟OT耻"䀢r;쀀𝔔pf;愚cr;쀀𝒬؀BEacefhiorsu༾གྷཇའཱིྦྷྪྭ႖ႩႴႾarr;椐G耻®䂮ƀcnrཎནབute;䅔g;柫rĀ;tཛྷཝ憠l;椖ƀaeyཧཬཱron;䅘dil;䅖;䐠Ā;vླྀཹ愜erseĀEUྂྙĀlq྇ྎement;戋uilibrium;懋pEquilibrium;楯r»ཹo;䎡ghtЀACDFTUVa࿁࿫࿳ဢဨၛႇϘĀnr࿆࿒gleBracket;柩rowƀ;BL࿜࿝࿡憒ar;懥eftArrow;懄eiling;按oǵ࿹\0စbleBracket;柧nǔည\0နeeVector;楝ectorĀ;Bဝသ懂ar;楕loor;挋Āerိ၃eƀ;AVဵံြ抢rrow;憦ector;楛iangleƀ;BEၐၑၕ抳ar;槐qual;抵pƀDTVၣၮၸownVector;楏eeVector;楜ectorĀ;Bႂႃ憾ar;楔ectorĀ;B႑႒懀ar;楓Āpuႛ႞f;愝ndImplies;楰ightarrow;懛ĀchႹႼr;愛;憱leDelayed;槴ڀHOacfhimoqstuფჱჷჽᄙᄞᅑᅖᅡᅧᆵᆻᆿĀCcჩხHcy;䐩y;䐨FTcy;䐬cute;䅚ʀ;aeiyᄈᄉᄎᄓᄗ檼ron;䅠dil;䅞rc;䅜;䐡r;쀀𝔖ortȀDLRUᄪᄴᄾᅉownArrow»ОeftArrow»࢚ightArrow»࿝pArrow;憑gma;䎣allCircle;战pf;쀀𝕊ɲᅭ\0\0ᅰt;戚areȀ;ISUᅻᅼᆉᆯ斡ntersection;抓uĀbpᆏᆞsetĀ;Eᆗᆘ抏qual;抑ersetĀ;Eᆨᆩ抐qual;抒nion;抔cr;쀀𝒮ar;拆ȀbcmpᇈᇛሉላĀ;sᇍᇎ拐etĀ;Eᇍᇕqual;抆ĀchᇠህeedsȀ;ESTᇭᇮᇴᇿ扻qual;檰lantEqual;扽ilde;承Tháྌ;我ƀ;esሒሓሣ拑rsetĀ;Eሜም抃qual;抇et»ሓրHRSacfhiorsሾቄ቉ቕ቞ቱቶኟዂወዑORN耻Þ䃞ADE;愢ĀHc቎ቒcy;䐋y;䐦Ābuቚቜ;䀉;䎤ƀaeyብቪቯron;䅤dil;䅢;䐢r;쀀𝔗Āeiቻ኉Dzኀ\0ኇefore;戴a;䎘Ācn኎ኘkSpace;쀀  Space;怉ldeȀ;EFTካኬኲኼ戼qual;扃ullEqual;扅ilde;扈pf;쀀𝕋ipleDot;惛Āctዖዛr;쀀𝒯rok;䅦ૡዷጎጚጦ\0ጬጱ\0\0\0\0\0ጸጽ፷ᎅ\0᏿ᐄᐊᐐĀcrዻጁute耻Ú䃚rĀ;oጇገ憟cir;楉rǣጓ\0጖y;䐎ve;䅬Āiyጞጣrc耻Û䃛;䐣blac;䅰r;쀀𝔘rave耻Ù䃙acr;䅪Ādiፁ፩erĀBPፈ፝Āarፍፐr;䁟acĀekፗፙ;揟et;掵arenthesis;揝onĀ;P፰፱拃lus;抎Āgp፻፿on;䅲f;쀀𝕌ЀADETadps᎕ᎮᎸᏄϨᏒᏗᏳrrowƀ;BDᅐᎠᎤar;椒ownArrow;懅ownArrow;憕quilibrium;楮eeĀ;AᏋᏌ报rrow;憥ownáϳerĀLRᏞᏨeftArrow;憖ightArrow;憗iĀ;lᏹᏺ䏒on;䎥ing;䅮cr;쀀𝒰ilde;䅨ml耻Ü䃜ҀDbcdefosvᐧᐬᐰᐳᐾᒅᒊᒐᒖash;披ar;櫫y;䐒ashĀ;lᐻᐼ抩;櫦Āerᑃᑅ;拁ƀbtyᑌᑐᑺar;怖Ā;iᑏᑕcalȀBLSTᑡᑥᑪᑴar;戣ine;䁼eparator;杘ilde;所ThinSpace;怊r;쀀𝔙pf;쀀𝕍cr;쀀𝒱dash;抪ʀcefosᒧᒬᒱᒶᒼirc;䅴dge;拀r;쀀𝔚pf;쀀𝕎cr;쀀𝒲Ȁfiosᓋᓐᓒᓘr;쀀𝔛;䎞pf;쀀𝕏cr;쀀𝒳ҀAIUacfosuᓱᓵᓹᓽᔄᔏᔔᔚᔠcy;䐯cy;䐇cy;䐮cute耻Ý䃝Āiyᔉᔍrc;䅶;䐫r;쀀𝔜pf;쀀𝕐cr;쀀𝒴ml;䅸ЀHacdefosᔵᔹᔿᕋᕏᕝᕠᕤcy;䐖cute;䅹Āayᕄᕉron;䅽;䐗ot;䅻Dzᕔ\0ᕛoWidtè૙a;䎖r;愨pf;愤cr;쀀𝒵௡ᖃᖊᖐ\0ᖰᖶᖿ\0\0\0\0ᗆᗛᗫᙟ᙭\0ᚕ᚛ᚲᚹ\0ᚾcute耻á䃡reve;䄃̀;Ediuyᖜᖝᖡᖣᖨᖭ戾;쀀∾̳;房rc耻â䃢te肻´̆;䐰lig耻æ䃦Ā;r²ᖺ;쀀𝔞rave耻à䃠ĀepᗊᗖĀfpᗏᗔsym;愵èᗓha;䎱ĀapᗟcĀclᗤᗧr;䄁g;樿ɤᗰ\0\0ᘊʀ;adsvᗺᗻᗿᘁᘇ戧nd;橕;橜lope;橘;橚΀;elmrszᘘᘙᘛᘞᘿᙏᙙ戠;榤e»ᘙsdĀ;aᘥᘦ戡ѡᘰᘲᘴᘶᘸᘺᘼᘾ;榨;榩;榪;榫;榬;榭;榮;榯tĀ;vᙅᙆ戟bĀ;dᙌᙍ抾;榝Āptᙔᙗh;戢»¹arr;捼Āgpᙣᙧon;䄅f;쀀𝕒΀;Eaeiop዁ᙻᙽᚂᚄᚇᚊ;橰cir;橯;扊d;手s;䀧roxĀ;e዁ᚒñᚃing耻å䃥ƀctyᚡᚦᚨr;쀀𝒶;䀪mpĀ;e዁ᚯñʈilde耻ã䃣ml耻ä䃤Āciᛂᛈoninôɲnt;樑ࠀNabcdefiklnoprsu᛭ᛱᜰ᜼ᝃᝈ᝸᝽០៦ᠹᡐᜍ᤽᥈ᥰot;櫭Ācrᛶ᜞kȀcepsᜀᜅᜍᜓong;扌psilon;䏶rime;怵imĀ;e᜚᜛戽q;拍Ŷᜢᜦee;抽edĀ;gᜬᜭ挅e»ᜭrkĀ;t፜᜷brk;掶Āoyᜁᝁ;䐱quo;怞ʀcmprtᝓ᝛ᝡᝤᝨausĀ;eĊĉptyv;榰séᜌnoõēƀahwᝯ᝱ᝳ;䎲;愶een;扬r;쀀𝔟g΀costuvwឍឝឳេ៕៛៞ƀaiuបពរðݠrc;旯p»፱ƀdptឤឨឭot;樀lus;樁imes;樂ɱឹ\0\0ើcup;樆ar;昅riangleĀdu៍្own;施p;斳plus;樄eåᑄåᒭarow;植ƀako៭ᠦᠵĀcn៲ᠣkƀlst៺֫᠂ozenge;槫riangleȀ;dlr᠒᠓᠘᠝斴own;斾eft;旂ight;斸k;搣Ʊᠫ\0ᠳƲᠯ\0ᠱ;斒;斑4;斓ck;斈ĀeoᠾᡍĀ;qᡃᡆ쀀=⃥uiv;쀀≡⃥t;挐Ȁptwxᡙᡞᡧᡬf;쀀𝕓Ā;tᏋᡣom»Ꮜtie;拈؀DHUVbdhmptuvᢅᢖᢪᢻᣗᣛᣬ᣿ᤅᤊᤐᤡȀLRlrᢎᢐᢒᢔ;敗;敔;敖;敓ʀ;DUduᢡᢢᢤᢦᢨ敐;敦;敩;敤;敧ȀLRlrᢳᢵᢷᢹ;敝;敚;敜;教΀;HLRhlrᣊᣋᣍᣏᣑᣓᣕ救;敬;散;敠;敫;敢;敟ox;槉ȀLRlrᣤᣦᣨᣪ;敕;敒;攐;攌ʀ;DUduڽ᣷᣹᣻᣽;敥;敨;攬;攴inus;抟lus;択imes;抠ȀLRlrᤙᤛᤝ᤟;敛;敘;攘;攔΀;HLRhlrᤰᤱᤳᤵᤷ᤻᤹攂;敪;敡;敞;攼;攤;攜Āevģ᥂bar耻¦䂦Ȁceioᥑᥖᥚᥠr;쀀𝒷mi;恏mĀ;e᜚᜜lƀ;bhᥨᥩᥫ䁜;槅sub;柈Ŭᥴ᥾lĀ;e᥹᥺怢t»᥺pƀ;Eeįᦅᦇ;檮Ā;qۜۛೡᦧ\0᧨ᨑᨕᨲ\0ᨷᩐ\0\0᪴\0\0᫁\0\0ᬡᬮ᭍᭒\0᯽\0ᰌƀcpr᦭ᦲ᧝ute;䄇̀;abcdsᦿᧀᧄ᧊᧕᧙戩nd;橄rcup;橉Āau᧏᧒p;橋p;橇ot;橀;쀀∩︀Āeo᧢᧥t;恁îړȀaeiu᧰᧻ᨁᨅǰ᧵\0᧸s;橍on;䄍dil耻ç䃧rc;䄉psĀ;sᨌᨍ橌m;橐ot;䄋ƀdmnᨛᨠᨦil肻¸ƭptyv;榲t脀¢;eᨭᨮ䂢räƲr;쀀𝔠ƀceiᨽᩀᩍy;䑇ckĀ;mᩇᩈ朓ark»ᩈ;䏇r΀;Ecefms᩟᩠ᩢᩫ᪤᪪᪮旋;槃ƀ;elᩩᩪᩭ䋆q;扗eɡᩴ\0\0᪈rrowĀlr᩼᪁eft;憺ight;憻ʀRSacd᪒᪔᪖᪚᪟»ཇ;擈st;抛irc;抚ash;抝nint;樐id;櫯cir;槂ubsĀ;u᪻᪼晣it»᪼ˬ᫇᫔᫺\0ᬊonĀ;eᫍᫎ䀺Ā;qÇÆɭ᫙\0\0᫢aĀ;t᫞᫟䀬;䁀ƀ;fl᫨᫩᫫戁îᅠeĀmx᫱᫶ent»᫩eóɍǧ᫾\0ᬇĀ;dኻᬂot;橭nôɆƀfryᬐᬔᬗ;쀀𝕔oäɔ脀©;sŕᬝr;愗Āaoᬥᬩrr;憵ss;朗Ācuᬲᬷr;쀀𝒸Ābpᬼ᭄Ā;eᭁᭂ櫏;櫑Ā;eᭉᭊ櫐;櫒dot;拯΀delprvw᭠᭬᭷ᮂᮬᯔ᯹arrĀlr᭨᭪;椸;椵ɰ᭲\0\0᭵r;拞c;拟arrĀ;p᭿ᮀ憶;椽̀;bcdosᮏᮐᮖᮡᮥᮨ截rcap;橈Āauᮛᮞp;橆p;橊ot;抍r;橅;쀀∪︀Ȁalrv᮵ᮿᯞᯣrrĀ;mᮼᮽ憷;椼yƀevwᯇᯔᯘqɰᯎ\0\0ᯒreã᭳uã᭵ee;拎edge;拏en耻¤䂤earrowĀlrᯮ᯳eft»ᮀight»ᮽeäᯝĀciᰁᰇoninôǷnt;戱lcty;挭ঀAHabcdefhijlorstuwz᰸᰻᰿ᱝᱩᱵᲊᲞᲬᲷ᳻᳿ᴍᵻᶑᶫᶻ᷆᷍rò΁ar;楥Ȁglrs᱈ᱍ᱒᱔ger;怠eth;愸òᄳhĀ;vᱚᱛ怐»ऊūᱡᱧarow;椏aã̕Āayᱮᱳron;䄏;䐴ƀ;ao̲ᱼᲄĀgrʿᲁr;懊tseq;橷ƀglmᲑᲔᲘ耻°䂰ta;䎴ptyv;榱ĀirᲣᲨsht;楿;쀀𝔡arĀlrᲳᲵ»ࣜ»သʀaegsv᳂͸᳖᳜᳠mƀ;oș᳊᳔ndĀ;ș᳑uit;晦amma;䏝in;拲ƀ;io᳧᳨᳸䃷de脀÷;o᳧ᳰntimes;拇nø᳷cy;䑒cɯᴆ\0\0ᴊrn;挞op;挍ʀlptuwᴘᴝᴢᵉᵕlar;䀤f;쀀𝕕ʀ;emps̋ᴭᴷᴽᵂqĀ;d͒ᴳot;扑inus;戸lus;戔quare;抡blebarwedgåúnƀadhᄮᵝᵧownarrowóᲃarpoonĀlrᵲᵶefôᲴighôᲶŢᵿᶅkaro÷གɯᶊ\0\0ᶎrn;挟op;挌ƀcotᶘᶣᶦĀryᶝᶡ;쀀𝒹;䑕l;槶rok;䄑Ādrᶰᶴot;拱iĀ;fᶺ᠖斿Āah᷀᷃ròЩaòྦangle;榦Āci᷒ᷕy;䑟grarr;柿ऀDacdefglmnopqrstuxḁḉḙḸոḼṉṡṾấắẽỡἪἷὄ὎὚ĀDoḆᴴoôᲉĀcsḎḔute耻é䃩ter;橮ȀaioyḢḧḱḶron;䄛rĀ;cḭḮ扖耻ê䃪lon;払;䑍ot;䄗ĀDrṁṅot;扒;쀀𝔢ƀ;rsṐṑṗ檚ave耻è䃨Ā;dṜṝ檖ot;檘Ȁ;ilsṪṫṲṴ檙nters;揧;愓Ā;dṹṺ檕ot;檗ƀapsẅẉẗcr;䄓tyƀ;svẒẓẕ戅et»ẓpĀ1;ẝẤijạả;怄;怅怃ĀgsẪẬ;䅋p;怂ĀgpẴẸon;䄙f;쀀𝕖ƀalsỄỎỒrĀ;sỊị拕l;槣us;橱iƀ;lvỚớở䎵on»ớ;䏵ȀcsuvỪỳἋἣĀioữḱrc»Ḯɩỹ\0\0ỻíՈantĀglἂἆtr»ṝess»Ṻƀaeiἒ἖Ἒls;䀽st;扟vĀ;DȵἠD;橸parsl;槥ĀDaἯἳot;打rr;楱ƀcdiἾὁỸr;愯oô͒ĀahὉὋ;䎷耻ð䃰Āmrὓὗl耻ë䃫o;悬ƀcipὡὤὧl;䀡sôծĀeoὬὴctatioîՙnentialåչৡᾒ\0ᾞ\0ᾡᾧ\0\0ῆῌ\0ΐ\0ῦῪ \0 ⁚llingdotseñṄy;䑄male;晀ƀilrᾭᾳ῁lig;耀ffiɩᾹ\0\0᾽g;耀ffig;耀ffl;쀀𝔣lig;耀filig;쀀fjƀaltῙ῜ῡt;晭ig;耀flns;斱of;䆒ǰ΅\0ῳf;쀀𝕗ĀakֿῷĀ;vῼ´拔;櫙artint;樍Āao‌⁕Ācs‑⁒ႉ‸⁅⁈\0⁐β•‥‧‪‬\0‮耻½䂽;慓耻¼䂼;慕;慙;慛Ƴ‴\0‶;慔;慖ʴ‾⁁\0\0⁃耻¾䂾;慗;慜5;慘ƶ⁌\0⁎;慚;慝8;慞l;恄wn;挢cr;쀀𝒻ࢀEabcdefgijlnorstv₂₉₟₥₰₴⃰⃵⃺⃿℃ℒℸ̗ℾ⅒↞Ā;lٍ₇;檌ƀcmpₐₕ₝ute;䇵maĀ;dₜ᳚䎳;檆reve;䄟Āiy₪₮rc;䄝;䐳ot;䄡Ȁ;lqsؾق₽⃉ƀ;qsؾٌ⃄lanô٥Ȁ;cdl٥⃒⃥⃕c;檩otĀ;o⃜⃝檀Ā;l⃢⃣檂;檄Ā;e⃪⃭쀀⋛︀s;檔r;쀀𝔤Ā;gٳ؛mel;愷cy;䑓Ȁ;Eajٚℌℎℐ;檒;檥;檤ȀEaesℛℝ℩ℴ;扩pĀ;p℣ℤ檊rox»ℤĀ;q℮ℯ檈Ā;q℮ℛim;拧pf;쀀𝕘Āci⅃ⅆr;愊mƀ;el٫ⅎ⅐;檎;檐茀>;cdlqr׮ⅠⅪⅮⅳⅹĀciⅥⅧ;檧r;橺ot;拗Par;榕uest;橼ʀadelsↄⅪ←ٖ↛ǰ↉\0↎proø₞r;楸qĀlqؿ↖lesó₈ií٫Āen↣↭rtneqq;쀀≩︀Å↪ԀAabcefkosy⇄⇇⇱⇵⇺∘∝∯≨≽ròΠȀilmr⇐⇔⇗⇛rsðᒄf»․ilôکĀdr⇠⇤cy;䑊ƀ;cwࣴ⇫⇯ir;楈;憭ar;意irc;䄥ƀalr∁∎∓rtsĀ;u∉∊晥it»∊lip;怦con;抹r;쀀𝔥sĀew∣∩arow;椥arow;椦ʀamopr∺∾≃≞≣rr;懿tht;戻kĀlr≉≓eftarrow;憩ightarrow;憪f;쀀𝕙bar;怕ƀclt≯≴≸r;쀀𝒽asè⇴rok;䄧Ābp⊂⊇ull;恃hen»ᱛૡ⊣\0⊪\0⊸⋅⋎\0⋕⋳\0\0⋸⌢⍧⍢⍿\0⎆⎪⎴cute耻í䃭ƀ;iyݱ⊰⊵rc耻î䃮;䐸Ācx⊼⊿y;䐵cl耻¡䂡ĀfrΟ⋉;쀀𝔦rave耻ì䃬Ȁ;inoܾ⋝⋩⋮Āin⋢⋦nt;樌t;戭fin;槜ta;愩lig;䄳ƀaop⋾⌚⌝ƀcgt⌅⌈⌗r;䄫ƀelpܟ⌏⌓inåގarôܠh;䄱f;抷ed;䆵ʀ;cfotӴ⌬⌱⌽⍁are;愅inĀ;t⌸⌹戞ie;槝doô⌙ʀ;celpݗ⍌⍐⍛⍡al;抺Āgr⍕⍙eróᕣã⍍arhk;樗rod;樼Ȁcgpt⍯⍲⍶⍻y;䑑on;䄯f;쀀𝕚a;䎹uest耻¿䂿Āci⎊⎏r;쀀𝒾nʀ;EdsvӴ⎛⎝⎡ӳ;拹ot;拵Ā;v⎦⎧拴;拳Ā;iݷ⎮lde;䄩ǫ⎸\0⎼cy;䑖l耻ï䃯̀cfmosu⏌⏗⏜⏡⏧⏵Āiy⏑⏕rc;䄵;䐹r;쀀𝔧ath;䈷pf;쀀𝕛ǣ⏬\0⏱r;쀀𝒿rcy;䑘kcy;䑔Ѐacfghjos␋␖␢␧␭␱␵␻ppaĀ;v␓␔䎺;䏰Āey␛␠dil;䄷;䐺r;쀀𝔨reen;䄸cy;䑅cy;䑜pf;쀀𝕜cr;쀀𝓀஀ABEHabcdefghjlmnoprstuv⑰⒁⒆⒍⒑┎┽╚▀♎♞♥♹♽⚚⚲⛘❝❨➋⟀⠁⠒ƀart⑷⑺⑼rò৆òΕail;椛arr;椎Ā;gঔ⒋;檋ar;楢ॣ⒥\0⒪\0⒱\0\0\0\0\0⒵Ⓔ\0ⓆⓈⓍ\0⓹ute;䄺mptyv;榴raîࡌbda;䎻gƀ;dlࢎⓁⓃ;榑åࢎ;檅uo耻«䂫rЀ;bfhlpst࢙ⓞⓦⓩ⓫⓮⓱⓵Ā;f࢝ⓣs;椟s;椝ë≒p;憫l;椹im;楳l;憢ƀ;ae⓿─┄檫il;椙Ā;s┉┊檭;쀀⪭︀ƀabr┕┙┝rr;椌rk;杲Āak┢┬cĀek┨┪;䁻;䁛Āes┱┳;榋lĀdu┹┻;榏;榍Ȁaeuy╆╋╖╘ron;䄾Ādi═╔il;䄼ìࢰâ┩;䐻Ȁcqrs╣╦╭╽a;椶uoĀ;rนᝆĀdu╲╷har;楧shar;楋h;憲ʀ;fgqs▋▌উ◳◿扤tʀahlrt▘▤▷◂◨rrowĀ;t࢙□aé⓶arpoonĀdu▯▴own»њp»०eftarrows;懇ightƀahs◍◖◞rrowĀ;sࣴࢧarpoonó྘quigarro÷⇰hreetimes;拋ƀ;qs▋ও◺lanôবʀ;cdgsব☊☍☝☨c;檨otĀ;o☔☕橿Ā;r☚☛檁;檃Ā;e☢☥쀀⋚︀s;檓ʀadegs☳☹☽♉♋pproøⓆot;拖qĀgq♃♅ôউgtò⒌ôছiíলƀilr♕࣡♚sht;楼;쀀𝔩Ā;Eজ♣;檑š♩♶rĀdu▲♮Ā;l॥♳;楪lk;斄cy;䑙ʀ;achtੈ⚈⚋⚑⚖rò◁orneòᴈard;楫ri;旺Āio⚟⚤dot;䅀ustĀ;a⚬⚭掰che»⚭ȀEaes⚻⚽⛉⛔;扨pĀ;p⛃⛄檉rox»⛄Ā;q⛎⛏檇Ā;q⛎⚻im;拦Ѐabnoptwz⛩⛴⛷✚✯❁❇❐Ānr⛮⛱g;柬r;懽rëࣁgƀlmr⛿✍✔eftĀar০✇ightá৲apsto;柼ightá৽parrowĀlr✥✩efô⓭ight;憬ƀafl✶✹✽r;榅;쀀𝕝us;樭imes;樴š❋❏st;戗áፎƀ;ef❗❘᠀旊nge»❘arĀ;l❤❥䀨t;榓ʀachmt❳❶❼➅➇ròࢨorneòᶌarĀ;d྘➃;業;怎ri;抿̀achiqt➘➝ੀ➢➮➻quo;怹r;쀀𝓁mƀ;egল➪➬;檍;檏Ābu┪➳oĀ;rฟ➹;怚rok;䅂萀<;cdhilqrࠫ⟒☹⟜⟠⟥⟪⟰Āci⟗⟙;檦r;橹reå◲mes;拉arr;楶uest;橻ĀPi⟵⟹ar;榖ƀ;ef⠀भ᠛旃rĀdu⠇⠍shar;楊har;楦Āen⠗⠡rtneqq;쀀≨︀Å⠞܀Dacdefhilnopsu⡀⡅⢂⢎⢓⢠⢥⢨⣚⣢⣤ઃ⣳⤂Dot;戺Ȁclpr⡎⡒⡣⡽r耻¯䂯Āet⡗⡙;時Ā;e⡞⡟朠se»⡟Ā;sျ⡨toȀ;dluျ⡳⡷⡻owîҌefôएðᏑker;斮Āoy⢇⢌mma;権;䐼ash;怔asuredangle»ᘦr;쀀𝔪o;愧ƀcdn⢯⢴⣉ro耻µ䂵Ȁ;acdᑤ⢽⣀⣄sôᚧir;櫰ot肻·Ƶusƀ;bd⣒ᤃ⣓戒Ā;uᴼ⣘;横ţ⣞⣡p;櫛ò−ðઁĀdp⣩⣮els;抧f;쀀𝕞Āct⣸⣽r;쀀𝓂pos»ᖝƀ;lm⤉⤊⤍䎼timap;抸ఀGLRVabcdefghijlmoprstuvw⥂⥓⥾⦉⦘⧚⧩⨕⨚⩘⩝⪃⪕⪤⪨⬄⬇⭄⭿⮮ⰴⱧⱼ⳩Āgt⥇⥋;쀀⋙̸Ā;v⥐௏쀀≫⃒ƀelt⥚⥲⥶ftĀar⥡⥧rrow;懍ightarrow;懎;쀀⋘̸Ā;v⥻ే쀀≪⃒ightarrow;懏ĀDd⦎⦓ash;抯ash;抮ʀbcnpt⦣⦧⦬⦱⧌la»˞ute;䅄g;쀀∠⃒ʀ;Eiop඄⦼⧀⧅⧈;쀀⩰̸d;쀀≋̸s;䅉roø඄urĀ;a⧓⧔普lĀ;s⧓ସdz⧟\0⧣p肻 ଷmpĀ;e௹ఀʀaeouy⧴⧾⨃⨐⨓ǰ⧹\0⧻;橃on;䅈dil;䅆ngĀ;dൾ⨊ot;쀀⩭̸p;橂;䐽ash;怓΀;Aadqsxஒ⨩⨭⨻⩁⩅⩐rr;懗rĀhr⨳⨶k;椤Ā;oᏲᏰot;쀀≐̸uiöୣĀei⩊⩎ar;椨í஘istĀ;s஠டr;쀀𝔫ȀEest௅⩦⩹⩼ƀ;qs஼⩭௡ƀ;qs஼௅⩴lanô௢ií௪Ā;rஶ⪁»ஷƀAap⪊⪍⪑rò⥱rr;憮ar;櫲ƀ;svྍ⪜ྌĀ;d⪡⪢拼;拺cy;䑚΀AEadest⪷⪺⪾⫂⫅⫶⫹rò⥦;쀀≦̸rr;憚r;急Ȁ;fqs఻⫎⫣⫯tĀar⫔⫙rro÷⫁ightarro÷⪐ƀ;qs఻⪺⫪lanôౕĀ;sౕ⫴»శiíౝĀ;rవ⫾iĀ;eచథiäඐĀpt⬌⬑f;쀀𝕟膀¬;in⬙⬚⬶䂬nȀ;Edvஉ⬤⬨⬮;쀀⋹̸ot;쀀⋵̸ǡஉ⬳⬵;拷;拶iĀ;vಸ⬼ǡಸ⭁⭃;拾;拽ƀaor⭋⭣⭩rȀ;ast୻⭕⭚⭟lleì୻l;쀀⫽⃥;쀀∂̸lint;樔ƀ;ceಒ⭰⭳uåಥĀ;cಘ⭸Ā;eಒ⭽ñಘȀAait⮈⮋⮝⮧rò⦈rrƀ;cw⮔⮕⮙憛;쀀⤳̸;쀀↝̸ghtarrow»⮕riĀ;eೋೖ΀chimpqu⮽⯍⯙⬄୸⯤⯯Ȁ;cerല⯆ഷ⯉uå൅;쀀𝓃ortɭ⬅\0\0⯖ará⭖mĀ;e൮⯟Ā;q൴൳suĀbp⯫⯭å೸åഋƀbcp⯶ⰑⰙȀ;Ees⯿ⰀഢⰄ抄;쀀⫅̸etĀ;eഛⰋqĀ;qണⰀcĀ;eലⰗñസȀ;EesⰢⰣൟⰧ抅;쀀⫆̸etĀ;e൘ⰮqĀ;qൠⰣȀgilrⰽⰿⱅⱇìௗlde耻ñ䃱çృiangleĀlrⱒⱜeftĀ;eచⱚñదightĀ;eೋⱥñ೗Ā;mⱬⱭ䎽ƀ;esⱴⱵⱹ䀣ro;愖p;怇ҀDHadgilrsⲏⲔⲙⲞⲣⲰⲶⳓⳣash;抭arr;椄p;쀀≍⃒ash;抬ĀetⲨⲬ;쀀≥⃒;쀀>⃒nfin;槞ƀAetⲽⳁⳅrr;椂;쀀≤⃒Ā;rⳊⳍ쀀<⃒ie;쀀⊴⃒ĀAtⳘⳜrr;椃rie;쀀⊵⃒im;쀀∼⃒ƀAan⳰⳴ⴂrr;懖rĀhr⳺⳽k;椣Ā;oᏧᏥear;椧ቓ᪕\0\0\0\0\0\0\0\0\0\0\0\0\0ⴭ\0ⴸⵈⵠⵥ⵲ⶄᬇ\0\0ⶍⶫ\0ⷈⷎ\0ⷜ⸙⸫⸾⹃Ācsⴱ᪗ute耻ó䃳ĀiyⴼⵅrĀ;c᪞ⵂ耻ô䃴;䐾ʀabios᪠ⵒⵗLjⵚlac;䅑v;樸old;榼lig;䅓Ācr⵩⵭ir;榿;쀀𝔬ͯ⵹\0\0⵼\0ⶂn;䋛ave耻ò䃲;槁Ābmⶈ෴ar;榵Ȁacitⶕ⶘ⶥⶨrò᪀Āir⶝ⶠr;榾oss;榻nå๒;槀ƀaeiⶱⶵⶹcr;䅍ga;䏉ƀcdnⷀⷅǍron;䎿;榶pf;쀀𝕠ƀaelⷔ⷗ǒr;榷rp;榹΀;adiosvⷪⷫⷮ⸈⸍⸐⸖戨rò᪆Ȁ;efmⷷⷸ⸂⸅橝rĀ;oⷾⷿ愴f»ⷿ耻ª䂪耻º䂺gof;抶r;橖lope;橗;橛ƀclo⸟⸡⸧ò⸁ash耻ø䃸l;折iŬⸯ⸴de耻õ䃵esĀ;aǛ⸺s;樶ml耻ö䃶bar;挽ૡ⹞\0⹽\0⺀⺝\0⺢⺹\0\0⻋ຜ\0⼓\0\0⼫⾼\0⿈rȀ;astЃ⹧⹲຅脀¶;l⹭⹮䂶leìЃɩ⹸\0\0⹻m;櫳;櫽y;䐿rʀcimpt⺋⺏⺓ᡥ⺗nt;䀥od;䀮il;怰enk;怱r;쀀𝔭ƀimo⺨⺰⺴Ā;v⺭⺮䏆;䏕maô੶ne;明ƀ;tv⺿⻀⻈䏀chfork»´;䏖Āau⻏⻟nĀck⻕⻝kĀ;h⇴⻛;愎ö⇴sҀ;abcdemst⻳⻴ᤈ⻹⻽⼄⼆⼊⼎䀫cir;樣ir;樢Āouᵀ⼂;樥;橲n肻±ຝim;樦wo;樧ƀipu⼙⼠⼥ntint;樕f;쀀𝕡nd耻£䂣Ԁ;Eaceinosu່⼿⽁⽄⽇⾁⾉⾒⽾⾶;檳p;檷uå໙Ā;c໎⽌̀;acens່⽙⽟⽦⽨⽾pproø⽃urlyeñ໙ñ໎ƀaes⽯⽶⽺pprox;檹qq;檵im;拨iíໟmeĀ;s⾈ຮ怲ƀEas⽸⾐⽺ð⽵ƀdfp໬⾙⾯ƀals⾠⾥⾪lar;挮ine;挒urf;挓Ā;t໻⾴ï໻rel;抰Āci⿀⿅r;쀀𝓅;䏈ncsp;怈̀fiopsu⿚⋢⿟⿥⿫⿱r;쀀𝔮pf;쀀𝕢rime;恗cr;쀀𝓆ƀaeo⿸〉〓tĀei⿾々rnionóڰnt;樖stĀ;e【】䀿ñἙô༔઀ABHabcdefhilmnoprstux぀けさすムㄎㄫㅇㅢㅲㆎ㈆㈕㈤㈩㉘㉮㉲㊐㊰㊷ƀartぇおがròႳòϝail;検aròᱥar;楤΀cdenqrtとふへみわゔヌĀeuねぱ;쀀∽̱te;䅕iãᅮmptyv;榳gȀ;del࿑らるろ;榒;榥å࿑uo耻»䂻rր;abcfhlpstw࿜ガクシスゼゾダッデナp;極Ā;f࿠ゴs;椠;椳s;椞ë≝ð✮l;楅im;楴l;憣;憝Āaiパフil;椚oĀ;nホボ戶aló༞ƀabrョリヮrò៥rk;杳ĀakンヽcĀekヹ・;䁽;䁝Āes㄂㄄;榌lĀduㄊㄌ;榎;榐Ȁaeuyㄗㄜㄧㄩron;䅙Ādiㄡㄥil;䅗ì࿲âヺ;䑀Ȁclqsㄴㄷㄽㅄa;椷dhar;楩uoĀ;rȎȍh;憳ƀacgㅎㅟངlȀ;ipsླྀㅘㅛႜnåႻarôྩt;断ƀilrㅩဣㅮsht;楽;쀀𝔯ĀaoㅷㆆrĀduㅽㅿ»ѻĀ;l႑ㆄ;楬Ā;vㆋㆌ䏁;䏱ƀgns㆕ㇹㇼht̀ahlrstㆤㆰ㇂㇘㇤㇮rrowĀ;t࿜ㆭaéトarpoonĀduㆻㆿowîㅾp»႒eftĀah㇊㇐rrowó࿪arpoonóՑightarrows;應quigarro÷ニhreetimes;拌g;䋚ingdotseñἲƀahm㈍㈐㈓rò࿪aòՑ;怏oustĀ;a㈞㈟掱che»㈟mid;櫮Ȁabpt㈲㈽㉀㉒Ānr㈷㈺g;柭r;懾rëဃƀafl㉇㉊㉎r;榆;쀀𝕣us;樮imes;樵Āap㉝㉧rĀ;g㉣㉤䀩t;榔olint;樒arò㇣Ȁachq㉻㊀Ⴜ㊅quo;怺r;쀀𝓇Ābu・㊊oĀ;rȔȓƀhir㊗㊛㊠reåㇸmes;拊iȀ;efl㊪ၙᠡ㊫方tri;槎luhar;楨;愞ൡ㋕㋛㋟㌬㌸㍱\0㍺㎤\0\0㏬㏰\0㐨㑈㑚㒭㒱㓊㓱\0㘖\0\0㘳cute;䅛quï➺Ԁ;Eaceinpsyᇭ㋳㋵㋿㌂㌋㌏㌟㌦㌩;檴ǰ㋺\0㋼;檸on;䅡uåᇾĀ;dᇳ㌇il;䅟rc;䅝ƀEas㌖㌘㌛;檶p;檺im;择olint;樓iíሄ;䑁otƀ;be㌴ᵇ㌵担;橦΀Aacmstx㍆㍊㍗㍛㍞㍣㍭rr;懘rĀhr㍐㍒ë∨Ā;oਸ਼਴t耻§䂧i;䀻war;椩mĀin㍩ðnuóñt;朶rĀ;o㍶⁕쀀𝔰Ȁacoy㎂㎆㎑㎠rp;景Āhy㎋㎏cy;䑉;䑈rtɭ㎙\0\0㎜iäᑤaraì⹯耻­䂭Āgm㎨㎴maƀ;fv㎱㎲㎲䏃;䏂Ѐ;deglnprካ㏅㏉㏎㏖㏞㏡㏦ot;橪Ā;q኱ኰĀ;E㏓㏔檞;檠Ā;E㏛㏜檝;檟e;扆lus;樤arr;楲aròᄽȀaeit㏸㐈㐏㐗Āls㏽㐄lsetmé㍪hp;樳parsl;槤Ādlᑣ㐔e;挣Ā;e㐜㐝檪Ā;s㐢㐣檬;쀀⪬︀ƀflp㐮㐳㑂tcy;䑌Ā;b㐸㐹䀯Ā;a㐾㐿槄r;挿f;쀀𝕤aĀdr㑍ЂesĀ;u㑔㑕晠it»㑕ƀcsu㑠㑹㒟Āau㑥㑯pĀ;sᆈ㑫;쀀⊓︀pĀ;sᆴ㑵;쀀⊔︀uĀbp㑿㒏ƀ;esᆗᆜ㒆etĀ;eᆗ㒍ñᆝƀ;esᆨᆭ㒖etĀ;eᆨ㒝ñᆮƀ;afᅻ㒦ְrť㒫ֱ»ᅼaròᅈȀcemt㒹㒾㓂㓅r;쀀𝓈tmîñiì㐕aræᆾĀar㓎㓕rĀ;f㓔ឿ昆Āan㓚㓭ightĀep㓣㓪psiloîỠhé⺯s»⡒ʀbcmnp㓻㕞ሉ㖋㖎Ҁ;Edemnprs㔎㔏㔑㔕㔞㔣㔬㔱㔶抂;櫅ot;檽Ā;dᇚ㔚ot;櫃ult;櫁ĀEe㔨㔪;櫋;把lus;檿arr;楹ƀeiu㔽㕒㕕tƀ;en㔎㕅㕋qĀ;qᇚ㔏eqĀ;q㔫㔨m;櫇Ābp㕚㕜;櫕;櫓c̀;acensᇭ㕬㕲㕹㕻㌦pproø㋺urlyeñᇾñᇳƀaes㖂㖈㌛pproø㌚qñ㌗g;晪ڀ123;Edehlmnps㖩㖬㖯ሜ㖲㖴㗀㗉㗕㗚㗟㗨㗭耻¹䂹耻²䂲耻³䂳;櫆Āos㖹㖼t;檾ub;櫘Ā;dሢ㗅ot;櫄sĀou㗏㗒l;柉b;櫗arr;楻ult;櫂ĀEe㗤㗦;櫌;抋lus;櫀ƀeiu㗴㘉㘌tƀ;enሜ㗼㘂qĀ;qሢ㖲eqĀ;q㗧㗤m;櫈Ābp㘑㘓;櫔;櫖ƀAan㘜㘠㘭rr;懙rĀhr㘦㘨ë∮Ā;oਫ਩war;椪lig耻ß䃟௡㙑㙝㙠ዎ㙳㙹\0㙾㛂\0\0\0\0\0㛛㜃\0㜉㝬\0\0\0㞇ɲ㙖\0\0㙛get;挖;䏄rë๟ƀaey㙦㙫㙰ron;䅥dil;䅣;䑂lrec;挕r;쀀𝔱Ȁeiko㚆㚝㚵㚼Dz㚋\0㚑eĀ4fኄኁaƀ;sv㚘㚙㚛䎸ym;䏑Ācn㚢㚲kĀas㚨㚮pproø዁im»ኬsðኞĀas㚺㚮ð዁rn耻þ䃾Ǭ̟㛆⋧es膀×;bd㛏㛐㛘䃗Ā;aᤏ㛕r;樱;樰ƀeps㛡㛣㜀á⩍Ȁ;bcf҆㛬㛰㛴ot;挶ir;櫱Ā;o㛹㛼쀀𝕥rk;櫚á㍢rime;怴ƀaip㜏㜒㝤dåቈ΀adempst㜡㝍㝀㝑㝗㝜㝟ngleʀ;dlqr㜰㜱㜶㝀㝂斵own»ᶻeftĀ;e⠀㜾ñम;扜ightĀ;e㊪㝋ñၚot;旬inus;樺lus;樹b;槍ime;樻ezium;揢ƀcht㝲㝽㞁Āry㝷㝻;쀀𝓉;䑆cy;䑛rok;䅧Āio㞋㞎xô᝷headĀlr㞗㞠eftarro÷ࡏightarrow»ཝऀAHabcdfghlmoprstuw㟐㟓㟗㟤㟰㟼㠎㠜㠣㠴㡑㡝㡫㢩㣌㣒㣪㣶ròϭar;楣Ācr㟜㟢ute耻ú䃺òᅐrǣ㟪\0㟭y;䑞ve;䅭Āiy㟵㟺rc耻û䃻;䑃ƀabh㠃㠆㠋ròᎭlac;䅱aòᏃĀir㠓㠘sht;楾;쀀𝔲rave耻ù䃹š㠧㠱rĀlr㠬㠮»ॗ»ႃlk;斀Āct㠹㡍ɯ㠿\0\0㡊rnĀ;e㡅㡆挜r»㡆op;挏ri;旸Āal㡖㡚cr;䅫肻¨͉Āgp㡢㡦on;䅳f;쀀𝕦̀adhlsuᅋ㡸㡽፲㢑㢠ownáᎳarpoonĀlr㢈㢌efô㠭ighô㠯iƀ;hl㢙㢚㢜䏅»ᏺon»㢚parrows;懈ƀcit㢰㣄㣈ɯ㢶\0\0㣁rnĀ;e㢼㢽挝r»㢽op;挎ng;䅯ri;旹cr;쀀𝓊ƀdir㣙㣝㣢ot;拰lde;䅩iĀ;f㜰㣨»᠓Āam㣯㣲rò㢨l耻ü䃼angle;榧ހABDacdeflnoprsz㤜㤟㤩㤭㦵㦸㦽㧟㧤㧨㧳㧹㧽㨁㨠ròϷarĀ;v㤦㤧櫨;櫩asèϡĀnr㤲㤷grt;榜΀eknprst㓣㥆㥋㥒㥝㥤㦖appá␕othinçẖƀhir㓫⻈㥙opô⾵Ā;hᎷ㥢ïㆍĀiu㥩㥭gmá㎳Ābp㥲㦄setneqĀ;q㥽㦀쀀⊊︀;쀀⫋︀setneqĀ;q㦏㦒쀀⊋︀;쀀⫌︀Āhr㦛㦟etá㚜iangleĀlr㦪㦯eft»थight»ၑy;䐲ash»ံƀelr㧄㧒㧗ƀ;beⷪ㧋㧏ar;抻q;扚lip;拮Ābt㧜ᑨaòᑩr;쀀𝔳tré㦮suĀbp㧯㧱»ജ»൙pf;쀀𝕧roð໻tré㦴Ācu㨆㨋r;쀀𝓋Ābp㨐㨘nĀEe㦀㨖»㥾nĀEe㦒㨞»㦐igzag;榚΀cefoprs㨶㨻㩖㩛㩔㩡㩪irc;䅵Ādi㩀㩑Ābg㩅㩉ar;機eĀ;qᗺ㩏;扙erp;愘r;쀀𝔴pf;쀀𝕨Ā;eᑹ㩦atèᑹcr;쀀𝓌ૣណ㪇\0㪋\0㪐㪛\0\0㪝㪨㪫㪯\0\0㫃㫎\0㫘ៜ៟tré៑r;쀀𝔵ĀAa㪔㪗ròσrò৶;䎾ĀAa㪡㪤ròθrò৫að✓is;拻ƀdptឤ㪵㪾Āfl㪺ឩ;쀀𝕩imåឲĀAa㫇㫊ròώròਁĀcq㫒ីr;쀀𝓍Āpt៖㫜ré។Ѐacefiosu㫰㫽㬈㬌㬑㬕㬛㬡cĀuy㫶㫻te耻ý䃽;䑏Āiy㬂㬆rc;䅷;䑋n耻¥䂥r;쀀𝔶cy;䑗pf;쀀𝕪cr;쀀𝓎Ācm㬦㬩y;䑎l耻ÿ䃿Ԁacdefhiosw㭂㭈㭔㭘㭤㭩㭭㭴㭺㮀cute;䅺Āay㭍㭒ron;䅾;䐷ot;䅼Āet㭝㭡træᕟa;䎶r;쀀𝔷cy;䐶grarr;懝pf;쀀𝕫cr;쀀𝓏Ājn㮅㮇;怍j;怌'.split("").map(function(e){return e.charCodeAt(0)}));var GQ={};Object.defineProperty(GQ,"__esModule",{value:!0});GQ.default=new Uint16Array("Ȁaglq \x1Bɭ\0\0p;䀦os;䀧t;䀾t;䀼uot;䀢".split("").map(function(e){return e.charCodeAt(0)}));var z3={};(function(e){var g;Object.defineProperty(e,"__esModule",{value:!0}),e.replaceCodePoint=e.fromCodePoint=void 0;var I=new Map([[0,65533],[128,8364],[130,8218],[131,402],[132,8222],[133,8230],[134,8224],[135,8225],[136,710],[137,8240],[138,352],[139,8249],[140,338],[142,381],[145,8216],[146,8217],[147,8220],[148,8221],[149,8226],[150,8211],[151,8212],[152,732],[153,8482],[154,353],[155,8250],[156,339],[158,382],[159,376]]);e.fromCodePoint=(g=String.fromCodePoint)!==null&&g!==void 0?g:function(C){var r="";return C>65535&&(C-=65536,r+=String.fromCharCode(C>>>10&1023|55296),C=56320|C&1023),r+=String.fromCharCode(C),r};function i(C){var r;return C>=55296&&C<=57343||C>1114111?65533:(r=I.get(C))!==null&&r!==void 0?r:C}e.replaceCodePoint=i;function n(C){return(0,e.fromCodePoint)(i(C))}e.default=n})(z3);(function(e){var g=Le&&Le.__createBinding||(Object.create?function(S,X,W,R){R===void 0&&(R=W);var H=Object.getOwnPropertyDescriptor(X,W);(!H||("get"in H?!X.__esModule:H.writable||H.configurable))&&(H={enumerable:!0,get:function(){return X[W]}}),Object.defineProperty(S,R,H)}:function(S,X,W,R){R===void 0&&(R=W),S[R]=X[W]}),I=Le&&Le.__setModuleDefault||(Object.create?function(S,X){Object.defineProperty(S,"default",{enumerable:!0,value:X})}:function(S,X){S.default=X}),i=Le&&Le.__importStar||function(S){if(S&&S.__esModule)return S;var X={};if(S!=null)for(var W in S)W!=="default"&&Object.prototype.hasOwnProperty.call(S,W)&&g(X,S,W);return I(X,S),X},n=Le&&Le.__importDefault||function(S){return S&&S.__esModule?S:{default:S}};Object.defineProperty(e,"__esModule",{value:!0}),e.decodeXML=e.decodeHTMLStrict=e.decodeHTMLAttribute=e.decodeHTML=e.determineBranch=e.EntityDecoder=e.DecodingMode=e.BinTrieFlags=e.fromCodePoint=e.replaceCodePoint=e.decodeCodePoint=e.xmlDecodeTree=e.htmlDecodeTree=void 0;var C=n(ZQ);e.htmlDecodeTree=C.default;var r=n(GQ);e.xmlDecodeTree=r.default;var o=i(z3);e.decodeCodePoint=o.default;var A=z3;Object.defineProperty(e,"replaceCodePoint",{enumerable:!0,get:function(){return A.replaceCodePoint}}),Object.defineProperty(e,"fromCodePoint",{enumerable:!0,get:function(){return A.fromCodePoint}});var s;(function(S){S[S.NUM=35]="NUM",S[S.SEMI=59]="SEMI",S[S.EQUALS=61]="EQUALS",S[S.ZERO=48]="ZERO",S[S.NINE=57]="NINE",S[S.LOWER_A=97]="LOWER_A",S[S.LOWER_F=102]="LOWER_F",S[S.LOWER_X=120]="LOWER_X",S[S.LOWER_Z=122]="LOWER_Z",S[S.UPPER_A=65]="UPPER_A",S[S.UPPER_F=70]="UPPER_F",S[S.UPPER_Z=90]="UPPER_Z"})(s||(s={}));var a=32,l;(function(S){S[S.VALUE_LENGTH=49152]="VALUE_LENGTH",S[S.BRANCH_LENGTH=16256]="BRANCH_LENGTH",S[S.JUMP_TABLE=127]="JUMP_TABLE"})(l=e.BinTrieFlags||(e.BinTrieFlags={}));function c(S){return S>=s.ZERO&&S<=s.NINE}function u(S){return S>=s.UPPER_A&&S<=s.UPPER_F||S>=s.LOWER_A&&S<=s.LOWER_F}function d(S){return S>=s.UPPER_A&&S<=s.UPPER_Z||S>=s.LOWER_A&&S<=s.LOWER_Z||c(S)}function h(S){return S===s.EQUALS||d(S)}var m;(function(S){S[S.EntityStart=0]="EntityStart",S[S.NumericStart=1]="NumericStart",S[S.NumericDecimal=2]="NumericDecimal",S[S.NumericHex=3]="NumericHex",S[S.NamedEntity=4]="NamedEntity"})(m||(m={}));var f;(function(S){S[S.Legacy=0]="Legacy",S[S.Strict=1]="Strict",S[S.Attribute=2]="Attribute"})(f=e.DecodingMode||(e.DecodingMode={}));var b=function(){function S(X,W,R){this.decodeTree=X,this.emitCodePoint=W,this.errors=R,this.state=m.EntityStart,this.consumed=1,this.result=0,this.treeIndex=0,this.excess=1,this.decodeMode=f.Strict}return S.prototype.startEntity=function(X){this.decodeMode=X,this.state=m.EntityStart,this.result=0,this.treeIndex=0,this.excess=1,this.consumed=1},S.prototype.write=function(X,W){switch(this.state){case m.EntityStart:return X.charCodeAt(W)===s.NUM?(this.state=m.NumericStart,this.consumed+=1,this.stateNumericStart(X,W+1)):(this.state=m.NamedEntity,this.stateNamedEntity(X,W));case m.NumericStart:return this.stateNumericStart(X,W);case m.NumericDecimal:return this.stateNumericDecimal(X,W);case m.NumericHex:return this.stateNumericHex(X,W);case m.NamedEntity:return this.stateNamedEntity(X,W)}},S.prototype.stateNumericStart=function(X,W){return W>=X.length?-1:(X.charCodeAt(W)|a)===s.LOWER_X?(this.state=m.NumericHex,this.consumed+=1,this.stateNumericHex(X,W+1)):(this.state=m.NumericDecimal,this.stateNumericDecimal(X,W))},S.prototype.addToNumericResult=function(X,W,R,H){if(W!==R){var Y=R-W;this.result=this.result*Math.pow(H,Y)+parseInt(X.substr(W,Y),H),this.consumed+=Y}},S.prototype.stateNumericHex=function(X,W){for(var R=W;W>14;W>14,Y!==0){if(D===s.SEMI)return this.emitNamedEntityData(this.treeIndex,Y,this.consumed+this.excess);this.decodeMode!==f.Strict&&(this.result=this.treeIndex,this.consumed+=this.excess,this.excess=0)}}return-1},S.prototype.emitNotTerminatedNamedEntity=function(){var X,W=this,R=W.result,H=W.decodeTree,Y=(H[R]&l.VALUE_LENGTH)>>14;return this.emitNamedEntityData(R,Y,this.consumed),(X=this.errors)===null||X===void 0||X.missingSemicolonAfterCharacterReference(),this.consumed},S.prototype.emitNamedEntityData=function(X,W,R){var H=this.decodeTree;return this.emitCodePoint(W===1?H[X]&~l.VALUE_LENGTH:H[X+1],R),W===3&&this.emitCodePoint(H[X+2],R),R},S.prototype.end=function(){var X;switch(this.state){case m.NamedEntity:return this.result!==0&&(this.decodeMode!==f.Attribute||this.result===this.treeIndex)?this.emitNotTerminatedNamedEntity():0;case m.NumericDecimal:return this.emitNumericEntity(0,2);case m.NumericHex:return this.emitNumericEntity(0,3);case m.NumericStart:return(X=this.errors)===null||X===void 0||X.absenceOfDigitsInNumericCharacterReference(this.consumed),0;case m.EntityStart:return 0}},S}();e.EntityDecoder=b;function p(S){var X="",W=new b(S,function(R){return X+=(0,o.fromCodePoint)(R)});return function(H,Y){for(var D=0,E=0;(E=H.indexOf("&",E))>=0;){X+=H.slice(D,E),W.startEntity(Y);var O=W.write(H,E+1);if(O<0){D=E+W.end();break}D=E+O,E=O===0?D+1:D}var J=X+H.slice(D);return X="",J}}function y(S,X,W,R){var H=(X&l.BRANCH_LENGTH)>>7,Y=X&l.JUMP_TABLE;if(H===0)return Y!==0&&R===Y?W:-1;if(Y){var D=R-Y;return D<0||D>=H?-1:S[W+D]-1}for(var E=W,O=E+H-1;E<=O;){var J=E+O>>>1,ee=S[J];if(eeR)O=J-1;else return S[J+H]}return-1}e.determineBranch=y;var Z=p(C.default),B=p(r.default);function G(S,X){return X===void 0&&(X=f.Legacy),Z(S,X)}e.decodeHTML=G;function v(S){return Z(S,f.Attribute)}e.decodeHTMLAttribute=v;function w(S){return Z(S,f.Strict)}e.decodeHTMLStrict=w;function V(S){return B(S,f.Strict)}e.decodeXML=V})(th);var gh={},vQ={};Object.defineProperty(vQ,"__esModule",{value:!0});function _V(e){for(var g=1;g$\x80-\uFFFF]/g;var g=new Map([[34,"""],[38,"&"],[39,"'"],[60,"<"],[62,">"]]);e.getCodePoint=String.prototype.codePointAt!=null?function(n,C){return n.codePointAt(C)}:function(n,C){return(n.charCodeAt(C)&64512)===55296?(n.charCodeAt(C)-55296)*1024+n.charCodeAt(C+1)-56320+65536:n.charCodeAt(C)};function I(n){for(var C="",r=0,o;(o=e.xmlReplacer.exec(n))!==null;){var A=o.index,s=n.charCodeAt(A),a=g.get(s);a!==void 0?(C+=n.substring(r,A)+a,r=A+1):(C+="".concat(n.substring(r,A),"&#x").concat((0,e.getCodePoint)(n,A).toString(16),";"),r=e.xmlReplacer.lastIndex+=+((s&64512)===55296))}return C+n.substr(r)}e.encodeXML=I,e.escape=I;function i(n,C){return function(o){for(var A,s=0,a="";A=n.exec(o);)s!==A.index&&(a+=o.substring(s,A.index)),a+=C.get(A[0].charCodeAt(0)),s=A.index+1;return a+o.substring(s)}}e.escapeUTF8=i(/[&<>'"]/g,g),e.escapeAttribute=i(/["&\u00A0]/g,new Map([[34,"""],[38,"&"],[160," "]])),e.escapeText=i(/[&<>\u00A0]/g,new Map([[38,"&"],[60,"<"],[62,">"],[160," "]]))})(wb);var xht=Le&&Le.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(gh,"__esModule",{value:!0});gh.encodeNonAsciiHTML=gh.encodeHTML=void 0;var Fht=xht(vQ),Mve=wb,Eht=/[\t\n!-,./:-@[-`\f{-}$\x80-\uFFFF]/g;function Mht(e){return zve(Eht,e)}gh.encodeHTML=Mht;function zht(e){return zve(Mve.xmlReplacer,e)}gh.encodeNonAsciiHTML=zht;function zve(e,g){for(var I="",i=0,n;(n=e.exec(g))!==null;){var C=n.index;I+=g.substring(i,C);var r=g.charCodeAt(C),o=Fht.default.get(r);if(typeof o=="object"){if(C+10&&(i+=hN(e.children,g)),(g.xmlMode||!Eie.has(e.name))&&(i+=""))),i}function emt(e){return"<".concat(e.data,">")}function tmt(e,g){var I,i=e.data||"";return((I=g.encodeEntities)!==null&&I!==void 0?I:g.decodeEntities)!==!1&&!(!g.xmlMode&&e.parent&&_ht.has(e.parent.name))&&(i=g.xmlMode||g.encodeEntities!=="utf8"?(0,l9.encodeXML)(i):(0,l9.escapeText)(i)),i}function gmt(e){return"")}function Imt(e){return"")}var imt=Le&&Le.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(er,"__esModule",{value:!0});er.innerText=er.textContent=er.getText=er.getInnerHTML=er.getOuterHTML=void 0;var ra=kn,nmt=imt(N0),Cmt=T0;function Jve(e,g){return(0,nmt.default)(e,g)}er.getOuterHTML=Jve;function rmt(e,g){return(0,ra.hasChildren)(e)?e.children.map(function(I){return Jve(I,g)}).join(""):""}er.getInnerHTML=rmt;function W1(e){return Array.isArray(e)?e.map(W1).join(""):(0,ra.isTag)(e)?e.name==="br"?` +`:W1(e.children):(0,ra.isCDATA)(e)?W1(e.children):(0,ra.isText)(e)?e.data:""}er.getText=W1;function P3(e){return Array.isArray(e)?e.map(P3).join(""):(0,ra.hasChildren)(e)&&!(0,ra.isComment)(e)?P3(e.children):(0,ra.isText)(e)?e.data:""}er.textContent=P3;function J3(e){return Array.isArray(e)?e.map(J3).join(""):(0,ra.hasChildren)(e)&&(e.type===Cmt.ElementType.Tag||(0,ra.isCDATA)(e))?J3(e.children):(0,ra.isText)(e)?e.data:""}er.innerText=J3;var Mi={};Object.defineProperty(Mi,"__esModule",{value:!0});Mi.prevElementSibling=Mi.nextElementSibling=Mi.getName=Mi.hasAttrib=Mi.getAttributeValue=Mi.getSiblings=Mi.getParent=Mi.getChildren=void 0;var BQ=kn;function Ove(e){return(0,BQ.hasChildren)(e)?e.children:[]}Mi.getChildren=Ove;function _ve(e){return e.parent||null}Mi.getParent=_ve;function omt(e){var g,I,i=_ve(e);if(i!=null)return Ove(i);for(var n=[e],C=e.prev,r=e.next;C!=null;)n.unshift(C),g=C,C=g.prev;for(;r!=null;)n.push(r),I=r,r=I.next;return n}Mi.getSiblings=omt;function Amt(e,g){var I;return(I=e.attribs)===null||I===void 0?void 0:I[g]}Mi.getAttributeValue=Amt;function amt(e,g){return e.attribs!=null&&Object.prototype.hasOwnProperty.call(e.attribs,g)&&e.attribs[g]!=null}Mi.hasAttrib=amt;function smt(e){return e.name}Mi.getName=smt;function lmt(e){for(var g,I=e.next;I!==null&&!(0,BQ.isTag)(I);)g=I,I=g.next;return I}Mi.nextElementSibling=lmt;function cmt(e){for(var g,I=e.prev;I!==null&&!(0,BQ.isTag)(I);)g=I,I=g.prev;return I}Mi.prevElementSibling=cmt;var SC={};Object.defineProperty(SC,"__esModule",{value:!0});SC.prepend=SC.prependChild=SC.append=SC.appendChild=SC.replaceElement=SC.removeElement=void 0;function kS(e){if(e.prev&&(e.prev.next=e.next),e.next&&(e.next.prev=e.prev),e.parent){var g=e.parent.children,I=g.lastIndexOf(e);I>=0&&g.splice(I,1)}e.next=null,e.prev=null,e.parent=null}SC.removeElement=kS;function umt(e,g){var I=g.prev=e.prev;I&&(I.next=g);var i=g.next=e.next;i&&(i.prev=g);var n=g.parent=e.parent;if(n){var C=n.children;C[C.lastIndexOf(e)]=g,e.parent=null}}SC.replaceElement=umt;function dmt(e,g){if(kS(g),g.next=null,g.parent=e,e.children.push(g)>1){var I=e.children[e.children.length-2];I.next=g,g.prev=I}else g.prev=null}SC.appendChild=dmt;function hmt(e,g){kS(g);var I=e.parent,i=e.next;if(g.next=i,g.prev=e,e.next=g,g.parent=I,i){if(i.prev=g,I){var n=I.children;n.splice(n.lastIndexOf(i),0,g)}}else I&&I.children.push(g)}SC.append=hmt;function mmt(e,g){if(kS(g),g.parent=e,g.prev=null,e.children.unshift(g)!==1){var I=e.children[1];I.prev=g,g.next=I}else g.next=null}SC.prependChild=mmt;function fmt(e,g){kS(g);var I=e.parent;if(I){var i=I.children;i.splice(i.indexOf(e),0,g)}e.prev&&(e.prev.next=g),g.parent=I,g.prev=e.prev,g.next=e,e.prev=g}SC.prepend=fmt;var Pn={};Object.defineProperty(Pn,"__esModule",{value:!0});Pn.findAll=Pn.existsOne=Pn.findOne=Pn.findOneChild=Pn.find=Pn.filter=void 0;var mN=kn;function pmt(e,g,I,i){return I===void 0&&(I=!0),i===void 0&&(i=1/0),Lve(e,Array.isArray(g)?g:[g],I,i)}Pn.filter=pmt;function Lve(e,g,I,i){for(var n=[],C=[g],r=[0];;){if(r[0]>=C[0].length){if(r.length===1)return n;C.shift(),r.shift();continue}var o=C[0][r[0]++];if(e(o)&&(n.push(o),--i<=0))return n;I&&(0,mN.hasChildren)(o)&&o.children.length>0&&(r.unshift(0),C.unshift(o.children))}}Pn.find=Lve;function bmt(e,g){return g.find(e)}Pn.findOneChild=bmt;function Uve(e,g,I){I===void 0&&(I=!0);for(var i=null,n=0;n0&&(i=Uve(e,C.children,!0));else continue}return i}Pn.findOne=Uve;function Qve(e,g){return g.some(function(I){return(0,mN.isTag)(I)&&(e(I)||Qve(e,I.children))})}Pn.existsOne=Qve;function ymt(e,g){for(var I=[],i=[g],n=[0];;){if(n[0]>=i[0].length){if(i.length===1)return I;i.shift(),n.shift();continue}var C=i[0][n[0]++];(0,mN.isTag)(C)&&(e(C)&&I.push(C),C.children.length>0&&(n.unshift(0),i.unshift(C.children)))}}Pn.findAll=ymt;var tr={};Object.defineProperty(tr,"__esModule",{value:!0});tr.getElementsByTagType=tr.getElementsByTagName=tr.getElementById=tr.getElements=tr.testElement=void 0;var _u=kn,fN=Pn,c9={tag_name:function(e){return typeof e=="function"?function(g){return(0,_u.isTag)(g)&&e(g.name)}:e==="*"?_u.isTag:function(g){return(0,_u.isTag)(g)&&g.name===e}},tag_type:function(e){return typeof e=="function"?function(g){return e(g.type)}:function(g){return g.type===e}},tag_contains:function(e){return typeof e=="function"?function(g){return(0,_u.isText)(g)&&e(g.data)}:function(g){return(0,_u.isText)(g)&&g.data===e}}};function jve(e,g){return typeof g=="function"?function(I){return(0,_u.isTag)(I)&&g(I.attribs[e])}:function(I){return(0,_u.isTag)(I)&&I.attribs[e]===g}}function Zmt(e,g){return function(I){return e(I)||g(I)}}function $ve(e){var g=Object.keys(e).map(function(I){var i=e[I];return Object.prototype.hasOwnProperty.call(c9,I)?c9[I](i):jve(I,i)});return g.length===0?null:g.reduce(Zmt)}function Gmt(e,g){var I=$ve(e);return I?I(g):!0}tr.testElement=Gmt;function vmt(e,g,I,i){i===void 0&&(i=1/0);var n=$ve(e);return n?(0,fN.filter)(n,g,I,i):[]}tr.getElements=vmt;function Bmt(e,g,I){return I===void 0&&(I=!0),Array.isArray(g)||(g=[g]),(0,fN.findOne)(jve("id",e),g,I)}tr.getElementById=Bmt;function Smt(e,g,I,i){return I===void 0&&(I=!0),i===void 0&&(i=1/0),(0,fN.filter)(c9.tag_name(e),g,I,i)}tr.getElementsByTagName=Smt;function wmt(e,g,I,i){return I===void 0&&(I=!0),i===void 0&&(i=1/0),(0,fN.filter)(c9.tag_type(e),g,I,i)}tr.getElementsByTagType=wmt;var qve={};(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.uniqueSort=e.compareDocumentPosition=e.DocumentPosition=e.removeSubsets=void 0;var g=kn;function I(r){for(var o=r.length;--o>=0;){var A=r[o];if(o>0&&r.lastIndexOf(A,o-1)>=0){r.splice(o,1);continue}for(var s=A.parent;s;s=s.parent)if(r.includes(s)){r.splice(o,1);break}}return r}e.removeSubsets=I;var i;(function(r){r[r.DISCONNECTED=1]="DISCONNECTED",r[r.PRECEDING=2]="PRECEDING",r[r.FOLLOWING=4]="FOLLOWING",r[r.CONTAINS=8]="CONTAINS",r[r.CONTAINED_BY=16]="CONTAINED_BY"})(i=e.DocumentPosition||(e.DocumentPosition={}));function n(r,o){var A=[],s=[];if(r===o)return 0;for(var a=(0,g.hasChildren)(r)?r:r.parent;a;)A.unshift(a),a=a.parent;for(a=(0,g.hasChildren)(o)?o:o.parent;a;)s.unshift(a),a=a.parent;for(var l=Math.min(A.length,s.length),c=0;cd.indexOf(m)?u===o?i.FOLLOWING|i.CONTAINED_BY:i.FOLLOWING:u===r?i.PRECEDING|i.CONTAINS:i.PRECEDING}e.compareDocumentPosition=n;function C(r){return r=r.filter(function(o,A,s){return!s.includes(o,A+1)}),r.sort(function(o,A){var s=n(o,A);return s&i.PRECEDING?-1:s&i.FOLLOWING?1:0}),r}e.uniqueSort=C})(qve);var pN={};Object.defineProperty(pN,"__esModule",{value:!0});pN.getFeed=void 0;var Vmt=er,YS=tr;function Rmt(e){var g=u9(Nmt,e);return g?g.name==="feed"?Wmt(g):Xmt(g):null}pN.getFeed=Rmt;function Wmt(e){var g,I=e.children,i={type:"atom",items:(0,YS.getElementsByTagName)("entry",I).map(function(r){var o,A=r.children,s={media:eBe(A)};GC(s,"id","id",A),GC(s,"title","title",A);var a=(o=u9("link",A))===null||o===void 0?void 0:o.attribs.href;a&&(s.link=a);var l=oc("summary",A)||oc("content",A);l&&(s.description=l);var c=oc("updated",A);return c&&(s.pubDate=new Date(c)),s})};GC(i,"id","id",I),GC(i,"title","title",I);var n=(g=u9("link",I))===null||g===void 0?void 0:g.attribs.href;n&&(i.link=n),GC(i,"description","subtitle",I);var C=oc("updated",I);return C&&(i.updated=new Date(C)),GC(i,"author","email",I,!0),i}function Xmt(e){var g,I,i=(I=(g=u9("channel",e.children))===null||g===void 0?void 0:g.children)!==null&&I!==void 0?I:[],n={type:e.name.substr(0,3),id:"",items:(0,YS.getElementsByTagName)("item",e.children).map(function(r){var o=r.children,A={media:eBe(o)};GC(A,"id","guid",o),GC(A,"title","title",o),GC(A,"link","link",o),GC(A,"description","description",o);var s=oc("pubDate",o)||oc("dc:date",o);return s&&(A.pubDate=new Date(s)),A})};GC(n,"title","title",i),GC(n,"link","link",i),GC(n,"description","description",i);var C=oc("lastBuildDate",i);return C&&(n.updated=new Date(C)),GC(n,"author","managingEditor",i,!0),n}var Hmt=["url","type","lang"],Tmt=["fileSize","bitrate","framerate","samplingrate","channels","duration","height","width"];function eBe(e){return(0,YS.getElementsByTagName)("media:content",e).map(function(g){for(var I=g.attribs,i={medium:I.medium,isDefault:!!I.isDefault},n=0,C=Hmt;na.length-3)return!1;var c=a.charCodeAt(l+1);return(c>=A.LowerA&&c<=A.LowerZ||c>=A.UpperA&&c<=A.UpperZ||c===A.Exclamation)&&a.includes(">",l+2)}e.isHtml=s})(tu);Object.defineProperty(li,"__esModule",{value:!0});li.toggleClass=li.removeClass=li.addClass=li.hasClass=li.removeAttr=li.val=li.data=li.prop=li.attr=void 0;var gBe=ri,Mg=tu,zie=gA,wp=Object.prototype.hasOwnProperty,bB=/\s+/,HD="data-",Pie={null:null,true:!0,false:!1},SQ=/^(?:autofocus|autoplay|async|checked|controls|defer|disabled|hidden|loop|multiple|open|readonly|required|scoped|selected)$/i,_mt=/^{[^]*}$|^\[[^]*]$/;function d9(e,g,I){var i;if(!(!e||!(0,Mg.isTag)(e))){if((i=e.attribs)!==null&&i!==void 0||(e.attribs={}),!g)return e.attribs;if(wp.call(e.attribs,g))return!I&&SQ.test(g)?g:e.attribs[g];if(e.name==="option"&&g==="value")return(0,gBe.text)(e.children);if(e.name==="input"&&(e.attribs.type==="radio"||e.attribs.type==="checkbox")&&g==="value")return"on"}}function Vp(e,g,I){I===null?IBe(e,g):e.attribs[g]="".concat(I)}function Lmt(e,g){if(typeof e=="object"||g!==void 0){if(typeof g=="function"){if(typeof e!="string")throw new Error("Bad combination of arguments.");return(0,Mg.domEach)(this,function(I,i){(0,Mg.isTag)(I)&&Vp(I,e,g.call(I,i,I.attribs[e]))})}return(0,Mg.domEach)(this,function(I){(0,Mg.isTag)(I)&&(typeof e=="object"?Object.keys(e).forEach(function(i){var n=e[i];Vp(I,i,n)}):Vp(I,e,g))})}return arguments.length>1?this:d9(this[0],e,this.options.xmlMode)}li.attr=Lmt;function Jie(e,g,I){return g in e?e[g]:!I&&SQ.test(g)?d9(e,g,!1)!==void 0:d9(e,g,I)}function TD(e,g,I,i){g in e?e[g]=I:Vp(e,g,!i&&SQ.test(g)?I?"":null:"".concat(I))}function Umt(e,g){var I=this,i;if(typeof e=="string"&&g===void 0){var n=this[0];if(!n||!(0,Mg.isTag)(n))return;switch(e){case"style":{var C=this.css(),r=Object.keys(C);return r.forEach(function(A,s){C[s]=A}),C.length=r.length,C}case"tagName":case"nodeName":return n.name.toUpperCase();case"href":case"src":{var o=(i=n.attribs)===null||i===void 0?void 0:i[e];return typeof URL<"u"&&(e==="href"&&(n.tagName==="a"||n.name==="link")||e==="src"&&(n.tagName==="img"||n.tagName==="iframe"||n.tagName==="audio"||n.tagName==="video"||n.tagName==="source"))&&o!==void 0&&this.options.baseURI?new URL(o,this.options.baseURI).href:o}case"innerText":return(0,zie.innerText)(n);case"textContent":return(0,zie.textContent)(n);case"outerHTML":return this.clone().wrap("").parent().html();case"innerHTML":return this.html();default:return Jie(n,e,this.options.xmlMode)}}if(typeof e=="object"||g!==void 0){if(typeof g=="function"){if(typeof e=="object")throw new Error("Bad combination of arguments.");return(0,Mg.domEach)(this,function(A,s){(0,Mg.isTag)(A)&&TD(A,e,g.call(A,s,Jie(A,e,I.options.xmlMode)),I.options.xmlMode)})}return(0,Mg.domEach)(this,function(A){(0,Mg.isTag)(A)&&(typeof e=="object"?Object.keys(e).forEach(function(s){var a=e[s];TD(A,s,a,I.options.xmlMode)}):TD(A,e,g,I.options.xmlMode))})}}li.prop=Umt;function Oie(e,g,I){var i,n=e;(i=n.data)!==null&&i!==void 0||(n.data={}),typeof g=="object"?Object.assign(n.data,g):typeof g=="string"&&I!==void 0&&(n.data[g]=I)}function _ie(e,g){var I,i,n;g==null?(I=Object.keys(e.attribs).filter(function(A){return A.startsWith(HD)}),i=I.map(function(A){return(0,Mg.camelCase)(A.slice(HD.length))})):(I=[HD+(0,Mg.cssCase)(g)],i=[g]);for(var C=0;C-1;){var n=i+e.length;if((i===0||bB.test(I[i-1]))&&(n===I.length||bB.test(I[n])))return!0}return!1})}li.hasClass=qmt;function iBe(e){if(typeof e=="function")return(0,Mg.domEach)(this,function(s,a){if((0,Mg.isTag)(s)){var l=s.attribs.class||"";iBe.call([s],e.call(s,a,l))}});if(!e||typeof e!="string")return this;for(var g=e.split(bB),I=this.length,i=0;i=0&&(C.splice(A,1),r=!0,o--)}r&&(n.attribs.class=C.join(" "))}})}li.removeClass=nBe;function CBe(e,g){if(typeof e=="function")return(0,Mg.domEach)(this,function(l,c){(0,Mg.isTag)(l)&&CBe.call([l],e.call(l,c,l.attribs.class||"",g),g)});if(!e||typeof e!="string")return this;for(var I=e.split(bB),i=I.length,n=typeof g=="boolean"?g?1:-1:0,C=this.length,r=0;r=0&&a<0?A.push(I[s]):n<=0&&a>=0&&A.splice(a,1)}o.attribs.class=A.join(" ")}}return this}li.toggleClass=CBe;var Rt={},rBe={},bg;(function(e){e.Attribute="attribute",e.Pseudo="pseudo",e.PseudoElement="pseudo-element",e.Tag="tag",e.Universal="universal",e.Adjacent="adjacent",e.Child="child",e.Descendant="descendant",e.Parent="parent",e.Sibling="sibling",e.ColumnCombinator="column-combinator"})(bg||(bg={}));const eft={Unknown:null,QuirksMode:"quirks",IgnoreCase:!0,CaseSensitive:!1};var VI;(function(e){e.Any="any",e.Element="element",e.End="end",e.Equals="equals",e.Exists="exists",e.Hyphen="hyphen",e.Not="not",e.Start="start"})(VI||(VI={}));const Lie=/^[^\\#]?(?:\\(?:[\da-f]{1,6}\s?|.)|[\w\-\u00b0-\uFFFF])+/,tft=/\\([\da-f]{1,6}\s?|(\s)|.)/gi,gft=new Map([[126,VI.Element],[94,VI.Start],[36,VI.End],[42,VI.Any],[33,VI.Not],[124,VI.Hyphen]]),Ift=new Set(["has","not","matches","is","where","host","host-context"]);function oBe(e){switch(e.type){case bg.Adjacent:case bg.Child:case bg.Descendant:case bg.Parent:case bg.Sibling:case bg.ColumnCombinator:return!0;default:return!1}}const ift=new Set(["contains","icontains"]);function nft(e,g,I){const i=parseInt(g,16)-65536;return i!==i||I?g:i<0?String.fromCharCode(i+65536):String.fromCharCode(i>>10|55296,i&1023|56320)}function Jy(e){return e.replace(tft,nft)}function ND(e){return e===39||e===34}function Uie(e){return e===32||e===9||e===10||e===12||e===13}function Cft(e){const g=[],I=ABe(g,`${e}`,0);if(I0&&I0&&oBe(i[i.length-1]))throw new Error("Did not expect successive traversals.")}function s(c){if(i.length>0&&i[i.length-1].type===bg.Descendant){i[i.length-1].type=c;return}A(),i.push({type:c})}function a(c,u){i.push({type:bg.Attribute,name:c,action:u,value:n(1),namespace:null,ignoreCase:"quirks"})}function l(){if(i.length&&i[i.length-1].type===bg.Descendant&&i.pop(),i.length===0)throw new Error("Empty sub-selector");e.push(i)}if(C(0),g.length===I)return I;e:for(;Ie.charCodeAt(0))),Qie=new Set(sBe.map(e=>e.charCodeAt(0))),$f=new Set([...sBe,"~","^","$","*","+","!","|",":","[","]"," ","."].map(e=>e.charCodeAt(0)));function lBe(e){return e.map(g=>g.map(oft).join("")).join(", ")}function oft(e,g,I){switch(e.type){case bg.Child:return g===0?"> ":" > ";case bg.Parent:return g===0?"< ":" < ";case bg.Sibling:return g===0?"~ ":" ~ ";case bg.Adjacent:return g===0?"+ ":" + ";case bg.Descendant:return" ";case bg.ColumnCombinator:return g===0?"|| ":" || ";case bg.Universal:return e.namespace==="*"&&g+10?i+e.slice(I):e}const aft=Object.freeze(Object.defineProperty({__proto__:null,get AttributeAction(){return VI},IgnoreCaseMode:eft,get SelectorType(){return bg},isTraversal:oBe,parse:Cft,stringify:lBe},Symbol.toStringTag,{value:"Module"})),KS=Os(aft);var _3={},qh={trueFunc:function(){return!0},falseFunc:function(){return!1}},Bc={},k0={};Object.defineProperty(k0,"__esModule",{value:!0});k0.isTraversal=void 0;var $C=KS,uBe=new Map([[$C.SelectorType.Universal,50],[$C.SelectorType.Tag,30],[$C.SelectorType.Attribute,1],[$C.SelectorType.Pseudo,0]]);function sft(e){return!uBe.has(e.type)}k0.isTraversal=sft;var lft=new Map([[$C.AttributeAction.Exists,10],[$C.AttributeAction.Equals,8],[$C.AttributeAction.Not,7],[$C.AttributeAction.Start,6],[$C.AttributeAction.End,6],[$C.AttributeAction.Any,5]]);function cft(e){for(var g=e.map(dBe),I=1;I=0&&i>=1)):e.type===$C.SelectorType.Pseudo&&(e.data?e.name==="has"||e.name==="contains"?i=0:Array.isArray(e.data)?(i=Math.min.apply(Math,e.data.map(function(n){return Math.min.apply(Math,n.map(dBe))})),i<0&&(i=0)):i=2:i=3),i}var yN={},ZN={},uft=Le&&Le.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(ZN,"__esModule",{value:!0});ZN.attributeRules=void 0;var LV=uft(qh),dft=/[-[\]{}()*+?.,\\^$|#\s]/g;function $ie(e){return e.replace(dft,"\\$&")}var hft=new Set(["accept","accept-charset","align","alink","axis","bgcolor","charset","checked","clear","codetype","color","compact","declare","defer","dir","direction","disabled","enctype","face","frame","hreflang","http-equiv","lang","language","link","media","method","multiple","nohref","noresize","noshade","nowrap","readonly","rel","rev","rules","scope","scrolling","selected","shape","target","text","type","valign","valuetype","vlink"]);function Gu(e,g){return typeof e.ignoreCase=="boolean"?e.ignoreCase:e.ignoreCase==="quirks"?!!g.quirksMode:!g.xmlMode&&hft.has(e.name)}ZN.attributeRules={equals:function(e,g,I){var i=I.adapter,n=g.name,C=g.value;return Gu(g,I)?(C=C.toLowerCase(),function(r){var o=i.getAttributeValue(r,n);return o!=null&&o.length===C.length&&o.toLowerCase()===C&&e(r)}):function(r){return i.getAttributeValue(r,n)===C&&e(r)}},hyphen:function(e,g,I){var i=I.adapter,n=g.name,C=g.value,r=C.length;return Gu(g,I)?(C=C.toLowerCase(),function(A){var s=i.getAttributeValue(A,n);return s!=null&&(s.length===r||s.charAt(r)==="-")&&s.substr(0,r).toLowerCase()===C&&e(A)}):function(A){var s=i.getAttributeValue(A,n);return s!=null&&(s.length===r||s.charAt(r)==="-")&&s.substr(0,r)===C&&e(A)}},element:function(e,g,I){var i=I.adapter,n=g.name,C=g.value;if(/\s/.test(C))return LV.default.falseFunc;var r=new RegExp("(?:^|\\s)".concat($ie(C),"(?:$|\\s)"),Gu(g,I)?"i":"");return function(A){var s=i.getAttributeValue(A,n);return s!=null&&s.length>=C.length&&r.test(s)&&e(A)}},exists:function(e,g,I){var i=g.name,n=I.adapter;return function(C){return n.hasAttrib(C,i)&&e(C)}},start:function(e,g,I){var i=I.adapter,n=g.name,C=g.value,r=C.length;return r===0?LV.default.falseFunc:Gu(g,I)?(C=C.toLowerCase(),function(o){var A=i.getAttributeValue(o,n);return A!=null&&A.length>=r&&A.substr(0,r).toLowerCase()===C&&e(o)}):function(o){var A;return!!(!((A=i.getAttributeValue(o,n))===null||A===void 0)&&A.startsWith(C))&&e(o)}},end:function(e,g,I){var i=I.adapter,n=g.name,C=g.value,r=-C.length;return r===0?LV.default.falseFunc:Gu(g,I)?(C=C.toLowerCase(),function(o){var A;return((A=i.getAttributeValue(o,n))===null||A===void 0?void 0:A.substr(r).toLowerCase())===C&&e(o)}):function(o){var A;return!!(!((A=i.getAttributeValue(o,n))===null||A===void 0)&&A.endsWith(C))&&e(o)}},any:function(e,g,I){var i=I.adapter,n=g.name,C=g.value;if(C==="")return LV.default.falseFunc;if(Gu(g,I)){var r=new RegExp($ie(C),"i");return function(A){var s=i.getAttributeValue(A,n);return s!=null&&s.length>=C.length&&r.test(s)&&e(A)}}return function(o){var A;return!!(!((A=i.getAttributeValue(o,n))===null||A===void 0)&&A.includes(C))&&e(o)}},not:function(e,g,I){var i=I.adapter,n=g.name,C=g.value;return C===""?function(r){return!!i.getAttributeValue(r,n)&&e(r)}:Gu(g,I)?(C=C.toLowerCase(),function(r){var o=i.getAttributeValue(r,n);return(o==null||o.length!==C.length||o.toLowerCase()!==C)&&e(r)}):function(r){return i.getAttributeValue(r,n)!==C&&e(r)}}};var wQ={},hBe={},mBe={},GN={};Object.defineProperty(GN,"__esModule",{value:!0});GN.parse=void 0;var mft=new Set([9,10,12,13,32]),qie="0".charCodeAt(0),fft="9".charCodeAt(0);function pft(e){if(e=e.trim().toLowerCase(),e==="even")return[2,0];if(e==="odd")return[2,1];var g=0,I=0,i=C(),n=r();if(g=qie&&e.charCodeAt(g)<=fft;)s=s*10+(e.charCodeAt(g)-qie),g++;return g===A?null:s}function o(){for(;g=I};var i=Math.abs(g),n=(I%i+i)%i;return g>1?function(C){return C>=I&&C%i===n}:function(C){return C<=I&&C%i===n}}Rb.compile=yft;function Zft(e){var g=e[0],I=e[1]-1,i=0;if(g<0){var n=-g,C=(I%n+n)%n;return function(){var r=C+n*i++;return r>I?null:r}}return g===0?I<0?function(){return null}:function(){return i++===0?I:null}:(I<0&&(I+=g*Math.ceil(-I/g)),function(){return g*i+++I})}Rb.generate=Zft;(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.sequence=e.generate=e.compile=e.parse=void 0;var g=GN;Object.defineProperty(e,"parse",{enumerable:!0,get:function(){return g.parse}});var I=Rb;Object.defineProperty(e,"compile",{enumerable:!0,get:function(){return I.compile}}),Object.defineProperty(e,"generate",{enumerable:!0,get:function(){return I.generate}});function i(C){return(0,I.compile)((0,g.parse)(C))}e.default=i;function n(C){return(0,I.generate)((0,g.parse)(C))}e.sequence=n})(mBe);(function(e){var g=Le&&Le.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(e,"__esModule",{value:!0}),e.filters=void 0;var I=g(mBe),i=g(qh);function n(r,o){return function(A){var s=o.getParent(A);return s!=null&&o.isTag(s)&&r(A)}}e.filters={contains:function(r,o,A){var s=A.adapter;return function(l){return r(l)&&s.getText(l).includes(o)}},icontains:function(r,o,A){var s=A.adapter,a=o.toLowerCase();return function(c){return r(c)&&s.getText(c).toLowerCase().includes(a)}},"nth-child":function(r,o,A){var s=A.adapter,a=A.equals,l=(0,I.default)(o);return l===i.default.falseFunc?i.default.falseFunc:l===i.default.trueFunc?n(r,s):function(u){for(var d=s.getSiblings(u),h=0,m=0;m=0&&!a(u,d[m]);m--)s.isTag(d[m])&&h++;return l(h)&&r(u)}},"nth-of-type":function(r,o,A){var s=A.adapter,a=A.equals,l=(0,I.default)(o);return l===i.default.falseFunc?i.default.falseFunc:l===i.default.trueFunc?n(r,s):function(u){for(var d=s.getSiblings(u),h=0,m=0;m=0;m--){var f=d[m];if(a(u,f))break;s.isTag(f)&&s.getName(f)===s.getName(u)&&h++}return l(h)&&r(u)}},root:function(r,o,A){var s=A.adapter;return function(a){var l=s.getParent(a);return(l==null||!s.isTag(l))&&r(a)}},scope:function(r,o,A,s){var a=A.equals;return!s||s.length===0?e.filters.root(r,o,A):s.length===1?function(l){return a(s[0],l)&&r(l)}:function(l){return s.includes(l)&&r(l)}},hover:C("isHovered"),visited:C("isVisited"),active:C("isActive")};function C(r){return function(A,s,a){var l=a.adapter,c=l[r];return typeof c!="function"?i.default.falseFunc:function(d){return c(d)&&A(d)}}}})(hBe);var Wb={};Object.defineProperty(Wb,"__esModule",{value:!0});Wb.verifyPseudoArgs=Wb.pseudos=void 0;Wb.pseudos={empty:function(e,g){var I=g.adapter;return!I.getChildren(e).some(function(i){return I.isTag(i)||I.getText(i)!==""})},"first-child":function(e,g){var I=g.adapter,i=g.equals;if(I.prevElementSibling)return I.prevElementSibling(e)==null;var n=I.getSiblings(e).find(function(C){return I.isTag(C)});return n!=null&&i(e,n)},"last-child":function(e,g){for(var I=g.adapter,i=g.equals,n=I.getSiblings(e),C=n.length-1;C>=0;C--){if(i(e,n[C]))return!0;if(I.isTag(n[C]))break}return!1},"first-of-type":function(e,g){for(var I=g.adapter,i=g.equals,n=I.getSiblings(e),C=I.getName(e),r=0;r=0;r--){var o=n[r];if(i(e,o))return!0;if(I.isTag(o)&&I.getName(o)===C)break}return!1},"only-of-type":function(e,g){var I=g.adapter,i=g.equals,n=I.getName(e);return I.getSiblings(e).every(function(C){return i(e,C)||!I.isTag(C)||I.getName(C)!==n})},"only-child":function(e,g){var I=g.adapter,i=g.equals;return I.getSiblings(e).every(function(n){return i(e,n)||!I.isTag(n)})}};function Gft(e,g,I,i){if(I===null){if(e.length>i)throw new Error("Pseudo-class :".concat(g," requires an argument"))}else if(e.length===i)throw new Error("Pseudo-class :".concat(g," doesn't have any arguments"))}Wb.verifyPseudoArgs=Gft;var vN={};Object.defineProperty(vN,"__esModule",{value:!0});vN.aliases=void 0;vN.aliases={"any-link":":is(a, area, link)[href]",link:":any-link:not(:visited)",disabled:`:is( :is(button, input, select, textarea, optgroup, option)[disabled], optgroup[disabled] > option, fieldset[disabled]:not(fieldset[disabled] legend:first-of-type *) - )`,enabled:":not(:disabled)",checked:":is(:is(input[type=radio], input[type=checkbox])[checked], option:selected)",required:":is(input, select, textarea)[required]",optional:":is(input, select, textarea):not([required])",selected:"option:is([selected], select:not([multiple]):not(:has(> option[selected])) > :first-of-type)",checkbox:"[type=checkbox]",file:"[type=file]",password:"[type=password]",radio:"[type=radio]",reset:"[type=reset]",image:"[type=image]",submit:"[type=submit]",parent:":not(:empty)",header:":is(h1, h2, h3, h4, h5, h6)",button:":is(button, input[type=button])",input:":is(input, textarea, select, button)",text:"input:is(:not([type!='']), [type=text])"};var mk={};(function(g){var e=Le&&Le.__spreadArray||function(s,a,l){if(l||arguments.length===2)for(var c=0,u=a.length,d;c"u")return function(a){for(var l=a;l=vD(l,C);)if(g(l))return!0;return!1};var A=new WeakSet;return function(a){for(var l=a;l=vD(l,C);)if(!A.has(l)){if(C.isTag(l)&&g(l))return!0;A.add(l)}return!1}}case"_flexibleDescendant":return function(a){var l=a;do if(g(l))return!0;while(l=vD(l,C));return!1};case Zo.SelectorType.Parent:return function(a){return C.getChildren(a).some(function(l){return C.isTag(l)&&g(l)})};case Zo.SelectorType.Child:return function(a){var l=C.getParent(a);return l!=null&&C.isTag(l)&&g(l)};case Zo.SelectorType.Sibling:return function(a){for(var l=C.getSiblings(a),c=0;c0&&(0,Rz.isTraversal)(o[0])&&o[0].type!==Zs.SelectorType.Descendant))if(n&&!o.some(WSe))o.unshift(tmt);else continue;o.unshift(Imt)}}function rj(g,e,I){var i;g.forEach(Rz.default),I=(i=e.context)!==null&&i!==void 0?i:I;var n=Array.isArray(I),C=I&&(Array.isArray(I)?I:[I]);if(e.relativeSelector!==!1)imt(g,e,C);else if(g.some(function(A){return A.length>0&&(0,Rz.isTraversal)(A[0])}))throw new Error("Relative selectors are not allowed when the `relativeSelector` option is disabled");var r=!1,o=g.map(function(A){if(A.length>=2){var s=A[0],a=A[1];s.type!==Zs.SelectorType.Pseudo||s.name!=="scope"||(n&&a.type===Zs.SelectorType.Descendant?A[1]=gmt:(a.type===Zs.SelectorType.Adjacent||a.type===Zs.SelectorType.Sibling)&&(r=!0))}return nmt(A,e,C)}).reduce(Cmt,Wc.default.falseFunc);return o.shouldTestNextSiblings=r,o}Oc.compileToken=rj;function nmt(g,e,I){var i;return g.reduce(function(n,C){return n===Wc.default.falseFunc?Wc.default.falseFunc:(0,qht.compileGeneralSelector)(n,C,e,I,rj)},(i=e.rootFunc)!==null&&i!==void 0?i:Wc.default.trueFunc)}function Cmt(g,e){return e===Wc.default.falseFunc||g===Wc.default.trueFunc?g:g===Wc.default.falseFunc||e===Wc.default.trueFunc?e:function(i){return g(i)||e(i)}}(function(g){var e=Le&&Le.__createBinding||(Object.create?function(b,p,y,Z){Z===void 0&&(Z=y);var v=Object.getOwnPropertyDescriptor(p,y);(!v||("get"in v?!p.__esModule:v.writable||v.configurable))&&(v={enumerable:!0,get:function(){return p[y]}}),Object.defineProperty(b,Z,v)}:function(b,p,y,Z){Z===void 0&&(Z=y),b[Z]=p[y]}),I=Le&&Le.__setModuleDefault||(Object.create?function(b,p){Object.defineProperty(b,"default",{enumerable:!0,value:p})}:function(b,p){b.default=p}),i=Le&&Le.__importStar||function(b){if(b&&b.__esModule)return b;var p={};if(b!=null)for(var y in b)y!=="default"&&Object.prototype.hasOwnProperty.call(b,y)&&e(p,b,y);return I(p,b),p},n=Le&&Le.__importDefault||function(b){return b&&b.__esModule?b:{default:b}};Object.defineProperty(g,"__esModule",{value:!0}),g.aliases=g.pseudos=g.filters=g.is=g.selectOne=g.selectAll=g.prepareContext=g._compileToken=g._compileUnsafe=g.compile=void 0;var C=i(aA),r=n(hm),o=Oc,A=mk,s=function(b,p){return b===p},a={adapter:C,equals:s};function l(b){var p,y,Z,v,G=b??a;return(p=G.adapter)!==null&&p!==void 0||(G.adapter=C),(y=G.equals)!==null&&y!==void 0||(G.equals=(v=(Z=G.adapter)===null||Z===void 0?void 0:Z.equals)!==null&&v!==void 0?v:s),G}function c(b){return function(y,Z,v){var G=l(Z);return b(y,G,v)}}g.compile=c(o.compile),g._compileUnsafe=c(o.compileUnsafe),g._compileToken=c(o.compileToken);function u(b){return function(y,Z,v){var G=l(v);typeof y!="function"&&(y=(0,o.compileUnsafe)(y,G,Z));var B=d(Z,G.adapter,y.shouldTestNextSiblings);return b(y,B,G)}}function d(b,p,y){return y===void 0&&(y=!1),y&&(b=h(b,p)),Array.isArray(b)?p.removeSubsets(b):p.getChildren(b)}g.prepareContext=d;function h(b,p){for(var y=Array.isArray(b)?b.slice(0):[b],Z=y.length,v=0;v=0?r+1:1/0:0;case"lt":return isFinite(r)?r>=0?Math.min(r,C):1/0:0;case"gt":return isFinite(r)?1/0:0;case"odd":return 2*C;case"even":return 2*C-1;case"last":case"not":return 1/0}}g.getLimit=I})(oj);Object.defineProperty($b,"__esModule",{value:!0});$b.groupSelectors=$b.getDocumentRoot=void 0;var rmt=oj;function omt(g){for(;g.parent;)g=g.parent;return g}$b.getDocumentRoot=omt;function Amt(g){for(var e=[],I=[],i=0,n=g;i0&&R.some((0,o._compileToken)(V,X))||H.some(function(D){return y(D,R,X).length>0})}g.some=m;function f(R,S,X,W){var V=typeof X=="string"?parseInt(X,10):NaN;switch(R){case"first":case"lt":return S;case"last":return S.length>0?[S[S.length-1]]:S;case"nth":case"eq":return isFinite(V)&&Math.abs(V)1&&r.length>1?I.reduce(function(o,A){return A(o)},r):r)}}}var mw=Aj(function(g,e){for(var I,i=[],n=0;n0})}Ht.has=Gmt;function Bmt(){return this.length>1?this._make(this[0]):this}Ht.first=Bmt;function vmt(){return this.length>0?this._make(this[this.length-1]):this}Ht.last=vmt;function Smt(g){var e;return g=+g,g===0&&this.length<=1?this:(g<0&&(g=this.length+g),this._make((e=this[g])!==null&&e!==void 0?e:[]))}Ht.eq=Smt;function wmt(g){return g==null?this.toArray():this[g<0?this.length+g:g]}Ht.get=wmt;function Vmt(){return Array.prototype.slice.call(this)}Ht.toArray=Vmt;function Rmt(g){var e,I;return g==null?(e=this.parent().children(),I=this[0]):typeof g=="string"?(e=this._make(g),I=this[0]):(e=this,I=(0,hA.isCheerio)(g)?g[0]:g),Array.prototype.indexOf.call(e,I)}Ht.index=Rmt;function Wmt(g,e){return this._make(Array.prototype.slice.call(this,g,e))}Ht.slice=Wmt;function Xmt(){var g;return(g=this.prevObject)!==null&&g!==void 0?g:this._make([])}Ht.end=Xmt;function Hmt(g,e){var I=this._make(g,e),i=(0,Sa.uniqueSort)(Wz(Wz([],this.get(),!0),I.get(),!0));return this._make(i)}Ht.add=Hmt;function Tmt(g){return this.prevObject?this.add(g?this.prevObject.filter(g):this.prevObject):this}Ht.addBack=Tmt;var Ag={},ph={};Object.defineProperty(ph,"__esModule",{value:!0});ph.update=ph.getParse=void 0;var Nmt=aA,Fne=Kn;function kmt(g){return function(I,i,n,C){if(typeof Buffer<"u"&&Buffer.isBuffer(I)&&(I=I.toString()),typeof I=="string")return g(I,i,n,C);var r=I;if(!Array.isArray(r)&&(0,Fne.isDocument)(r))return r;var o=new Fne.Document([]);return XSe(r,o),o}}ph.getParse=kmt;function XSe(g,e){var I=Array.isArray(g)?g:[g];e?e.children=I:e=null;for(var i=0;i=g.length?null:g[e+I],a=0;a-1&&(c.children.splice(d,1),n===c&&e>d&&o[0]--)}l.parent=n,l.prev&&(l.prev.next=(C=l.next)!==null&&C!==void 0?C:null),l.next&&(l.next.prev=(r=l.prev)!==null&&r!==void 0?r:null),l.prev=a===0?A:i[a-1],l.next=a===i.length-1?s:i[a+1]}return A&&(A.next=i[0]),s&&(s.prev=i[i.length-1]),g.splice.apply(g,o)}function Dmt(g){var e=(0,Hi.isCheerio)(g)?g:this._make(g);return e.append(this),this}Ag.appendTo=Dmt;function Fmt(g){var e=(0,Hi.isCheerio)(g)?g:this._make(g);return e.prepend(this),this}Ag.prependTo=Fmt;Ag.append=HSe(function(g,e,I){Gu(e,e.length,0,g,I)});Ag.prepend=HSe(function(g,e,I){Gu(e,0,0,g,I)});function TSe(g){return function(e){for(var I=this.length-1,i=this.parents().last(),n=0;n0&&I!==void 0&&(e[I]+=";".concat(o))}else I=C.slice(0,r).trim(),e[I]=C.slice(r+1).trim()}return e}var e0={};Object.defineProperty(e0,"__esModule",{value:!0});e0.serializeArray=e0.serialize=void 0;var Ift=Zu,Mne="input,select,textarea,keygen",ift=/%20/g,zne=/\r?\n/g;function nft(){var g=this.serializeArray(),e=g.map(function(I){return"".concat(encodeURIComponent(I.name),"=").concat(encodeURIComponent(I.value))});return e.join("&").replace(ift,"+")}e0.serialize=nft;function Cft(){var g=this;return this.map(function(e,I){var i=g._make(I);return(0,Ift.isTag)(I)&&I.name==="form"?i.find(Mne).toArray():i.filter(Mne).toArray()}).filter('[name!=""]:enabled:not(:submit, :button, :image, :reset, :file):matches([checked], :not(:checkbox, :radio))').map(function(e,I){var i,n=g._make(I),C=n.attr("name"),r=(i=n.val())!==null&&i!==void 0?i:"";return Array.isArray(r)?r.map(function(o){return{name:C,value:o.replace(zne,`\r -`)}}):{name:C,value:r.replace(zne,`\r -`)}}).toArray()}e0.serializeArray=Cft;var rft=Le&&Le.__createBinding||(Object.create?function(g,e,I,i){i===void 0&&(i=I);var n=Object.getOwnPropertyDescriptor(e,I);(!n||("get"in n?!e.__esModule:n.writable||n.configurable))&&(n={enumerable:!0,get:function(){return e[I]}}),Object.defineProperty(g,i,n)}:function(g,e,I,i){i===void 0&&(i=I),g[i]=e[I]}),oft=Le&&Le.__setModuleDefault||(Object.create?function(g,e){Object.defineProperty(g,"default",{enumerable:!0,value:e})}:function(g,e){g.default=e}),pw=Le&&Le.__importStar||function(g){if(g&&g.__esModule)return g;var e={};if(g!=null)for(var I in g)I!=="default"&&Object.prototype.hasOwnProperty.call(g,I)&&rft(e,g,I);return oft(e,g),e};Object.defineProperty(lk,"__esModule",{value:!0});lk.Cheerio=void 0;var Aft=pw(ci),aft=pw(Ht),sft=pw(Ag),lft=pw(pk),cft=pw(e0),bw=function(){function g(e,I,i){if(this.length=0,this.options=i,this._root=I,e){for(var n=0;n=55296&&o<=57343}g.isSurrogate=I;function i(o){return o>=56320&&o<=57343}g.isSurrogatePair=i;function n(o,A){return(o-55296)*1024+9216+A}g.getSurrogatePairCodePoint=n;function C(o){return o!==32&&o!==10&&o!==13&&o!==9&&o!==12&&o>=1&&o<=31||o>=127&&o<=159}g.isControlCodePoint=C;function r(o){return o>=64976&&o<=65007||e.has(o)}g.isUndefinedCodePoint=r})(yk);var yw={};(function(g){Object.defineProperty(g,"__esModule",{value:!0}),g.ERR=void 0,function(e){e.controlCharacterInInputStream="control-character-in-input-stream",e.noncharacterInInputStream="noncharacter-in-input-stream",e.surrogateInInputStream="surrogate-in-input-stream",e.nonVoidHtmlElementStartTagWithTrailingSolidus="non-void-html-element-start-tag-with-trailing-solidus",e.endTagWithAttributes="end-tag-with-attributes",e.endTagWithTrailingSolidus="end-tag-with-trailing-solidus",e.unexpectedSolidusInTag="unexpected-solidus-in-tag",e.unexpectedNullCharacter="unexpected-null-character",e.unexpectedQuestionMarkInsteadOfTagName="unexpected-question-mark-instead-of-tag-name",e.invalidFirstCharacterOfTagName="invalid-first-character-of-tag-name",e.unexpectedEqualsSignBeforeAttributeName="unexpected-equals-sign-before-attribute-name",e.missingEndTagName="missing-end-tag-name",e.unexpectedCharacterInAttributeName="unexpected-character-in-attribute-name",e.unknownNamedCharacterReference="unknown-named-character-reference",e.missingSemicolonAfterCharacterReference="missing-semicolon-after-character-reference",e.unexpectedCharacterAfterDoctypeSystemIdentifier="unexpected-character-after-doctype-system-identifier",e.unexpectedCharacterInUnquotedAttributeValue="unexpected-character-in-unquoted-attribute-value",e.eofBeforeTagName="eof-before-tag-name",e.eofInTag="eof-in-tag",e.missingAttributeValue="missing-attribute-value",e.missingWhitespaceBetweenAttributes="missing-whitespace-between-attributes",e.missingWhitespaceAfterDoctypePublicKeyword="missing-whitespace-after-doctype-public-keyword",e.missingWhitespaceBetweenDoctypePublicAndSystemIdentifiers="missing-whitespace-between-doctype-public-and-system-identifiers",e.missingWhitespaceAfterDoctypeSystemKeyword="missing-whitespace-after-doctype-system-keyword",e.missingQuoteBeforeDoctypePublicIdentifier="missing-quote-before-doctype-public-identifier",e.missingQuoteBeforeDoctypeSystemIdentifier="missing-quote-before-doctype-system-identifier",e.missingDoctypePublicIdentifier="missing-doctype-public-identifier",e.missingDoctypeSystemIdentifier="missing-doctype-system-identifier",e.abruptDoctypePublicIdentifier="abrupt-doctype-public-identifier",e.abruptDoctypeSystemIdentifier="abrupt-doctype-system-identifier",e.cdataInHtmlContent="cdata-in-html-content",e.incorrectlyOpenedComment="incorrectly-opened-comment",e.eofInScriptHtmlCommentLikeText="eof-in-script-html-comment-like-text",e.eofInDoctype="eof-in-doctype",e.nestedComment="nested-comment",e.abruptClosingOfEmptyComment="abrupt-closing-of-empty-comment",e.eofInComment="eof-in-comment",e.incorrectlyClosedComment="incorrectly-closed-comment",e.eofInCdata="eof-in-cdata",e.absenceOfDigitsInNumericCharacterReference="absence-of-digits-in-numeric-character-reference",e.nullCharacterReference="null-character-reference",e.surrogateCharacterReference="surrogate-character-reference",e.characterReferenceOutsideUnicodeRange="character-reference-outside-unicode-range",e.controlCharacterReference="control-character-reference",e.noncharacterCharacterReference="noncharacter-character-reference",e.missingWhitespaceBeforeDoctypeName="missing-whitespace-before-doctype-name",e.missingDoctypeName="missing-doctype-name",e.invalidCharacterSequenceAfterDoctypeName="invalid-character-sequence-after-doctype-name",e.duplicateAttribute="duplicate-attribute",e.nonConformingDoctype="non-conforming-doctype",e.missingDoctype="missing-doctype",e.misplacedDoctype="misplaced-doctype",e.endTagWithoutMatchingOpenElement="end-tag-without-matching-open-element",e.closingOfElementWithOpenChildElements="closing-of-element-with-open-child-elements",e.disallowedContentInNoscriptInHead="disallowed-content-in-noscript-in-head",e.openElementsLeftAfterEof="open-elements-left-after-eof",e.abandonedHeadElementChild="abandoned-head-element-child",e.misplacedStartTagForHeadElement="misplaced-start-tag-for-head-element",e.nestedNoscriptInHead="nested-noscript-in-head",e.eofInElementThatCanContainOnlyText="eof-in-element-that-can-contain-only-text"}(g.ERR||(g.ERR={}))})(yw);function yft(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function Pne(g,e){for(var I=0;Ithis.bufferWaterline}},{key:"dropParsedChunk",value:function(){this.willDropParsedChunk()&&(this.html=this.html.substring(this.pos),this.lineStartPos-=this.pos,this.droppedBufferSize+=this.pos,this.pos=0,this.lastGapPos=-2,this.gapStack.length=0)}},{key:"write",value:function(I,i){this.html.length>0?this.html+=I:this.html=I,this.endOfChunkHit=!1,this.lastChunkWritten=i}},{key:"insertHtmlAtCurrentPos",value:function(I){this.html=this.html.substring(0,this.pos+1)+I+this.html.substring(this.pos+1),this.endOfChunkHit=!1}},{key:"startsWith",value:function(I,i){if(this.pos+I.length>this.html.length)return this.endOfChunkHit=!this.lastChunkWritten,!1;if(i)return this.html.startsWith(I,this.pos);for(let n=0;n=this.html.length)return this.endOfChunkHit=!this.lastChunkWritten,En.CODE_POINTS.EOF;const n=this.html.charCodeAt(i);return n===En.CODE_POINTS.CARRIAGE_RETURN?En.CODE_POINTS.LINE_FEED:n}},{key:"advance",value:function(){if(this.pos++,this.isEol&&(this.isEol=!1,this.line++,this.lineStartPos=this.pos),this.pos>=this.html.length)return this.endOfChunkHit=!this.lastChunkWritten,En.CODE_POINTS.EOF;let I=this.html.charCodeAt(this.pos);return I===En.CODE_POINTS.CARRIAGE_RETURN?(this.isEol=!0,this.skipNextNewLine=!0,En.CODE_POINTS.LINE_FEED):I===En.CODE_POINTS.LINE_FEED&&(this.isEol=!0,this.skipNextNewLine)?(this.line--,this.skipNextNewLine=!1,this._addGap(),this.advance()):(this.skipNextNewLine=!1,(0,En.isSurrogate)(I)&&(I=this._processSurrogate(I)),this.handler.onParseError===null||I>31&&I<127||I===En.CODE_POINTS.LINE_FEED||I===En.CODE_POINTS.CARRIAGE_RETURN||I>159&&I<64976||this._checkForProblematicCharacters(I),I)}},{key:"_checkForProblematicCharacters",value:function(I){(0,En.isControlCodePoint)(I)?this._err(wD.ERR.controlCharacterInInputStream):(0,En.isUndefinedCodePoint)(I)&&this._err(wD.ERR.noncharacterInInputStream)}},{key:"retreat",value:function(I){for(this.pos-=I;this.pos=0;n--)if(I.attrs[n].name===i)return I.attrs[n].value;return null}g.getTokenAttr=e})(Zk);var dl={};(function(g){Object.defineProperty(g,"__esModule",{value:!0}),g.hasUnescapedText=g.isNumberedHeader=g.SPECIAL_ELEMENTS=g.getTagID=g.TAG_ID=g.TAG_NAMES=g.DOCUMENT_MODE=g.ATTRS=g.NS=void 0;var e;(function(a){a.HTML="http://www.w3.org/1999/xhtml",a.MATHML="http://www.w3.org/1998/Math/MathML",a.SVG="http://www.w3.org/2000/svg",a.XLINK="http://www.w3.org/1999/xlink",a.XML="http://www.w3.org/XML/1998/namespace",a.XMLNS="http://www.w3.org/2000/xmlns/"})(e=g.NS||(g.NS={})),function(a){a.TYPE="type",a.ACTION="action",a.ENCODING="encoding",a.PROMPT="prompt",a.NAME="name",a.COLOR="color",a.FACE="face",a.SIZE="size"}(g.ATTRS||(g.ATTRS={})),function(a){a.NO_QUIRKS="no-quirks",a.QUIRKS="quirks",a.LIMITED_QUIRKS="limited-quirks"}(g.DOCUMENT_MODE||(g.DOCUMENT_MODE={}));var I;(function(a){a.A="a",a.ADDRESS="address",a.ANNOTATION_XML="annotation-xml",a.APPLET="applet",a.AREA="area",a.ARTICLE="article",a.ASIDE="aside",a.B="b",a.BASE="base",a.BASEFONT="basefont",a.BGSOUND="bgsound",a.BIG="big",a.BLOCKQUOTE="blockquote",a.BODY="body",a.BR="br",a.BUTTON="button",a.CAPTION="caption",a.CENTER="center",a.CODE="code",a.COL="col",a.COLGROUP="colgroup",a.DD="dd",a.DESC="desc",a.DETAILS="details",a.DIALOG="dialog",a.DIR="dir",a.DIV="div",a.DL="dl",a.DT="dt",a.EM="em",a.EMBED="embed",a.FIELDSET="fieldset",a.FIGCAPTION="figcaption",a.FIGURE="figure",a.FONT="font",a.FOOTER="footer",a.FOREIGN_OBJECT="foreignObject",a.FORM="form",a.FRAME="frame",a.FRAMESET="frameset",a.H1="h1",a.H2="h2",a.H3="h3",a.H4="h4",a.H5="h5",a.H6="h6",a.HEAD="head",a.HEADER="header",a.HGROUP="hgroup",a.HR="hr",a.HTML="html",a.I="i",a.IMG="img",a.IMAGE="image",a.INPUT="input",a.IFRAME="iframe",a.KEYGEN="keygen",a.LABEL="label",a.LI="li",a.LINK="link",a.LISTING="listing",a.MAIN="main",a.MALIGNMARK="malignmark",a.MARQUEE="marquee",a.MATH="math",a.MENU="menu",a.META="meta",a.MGLYPH="mglyph",a.MI="mi",a.MO="mo",a.MN="mn",a.MS="ms",a.MTEXT="mtext",a.NAV="nav",a.NOBR="nobr",a.NOFRAMES="noframes",a.NOEMBED="noembed",a.NOSCRIPT="noscript",a.OBJECT="object",a.OL="ol",a.OPTGROUP="optgroup",a.OPTION="option",a.P="p",a.PARAM="param",a.PLAINTEXT="plaintext",a.PRE="pre",a.RB="rb",a.RP="rp",a.RT="rt",a.RTC="rtc",a.RUBY="ruby",a.S="s",a.SCRIPT="script",a.SECTION="section",a.SELECT="select",a.SOURCE="source",a.SMALL="small",a.SPAN="span",a.STRIKE="strike",a.STRONG="strong",a.STYLE="style",a.SUB="sub",a.SUMMARY="summary",a.SUP="sup",a.TABLE="table",a.TBODY="tbody",a.TEMPLATE="template",a.TEXTAREA="textarea",a.TFOOT="tfoot",a.TD="td",a.TH="th",a.THEAD="thead",a.TITLE="title",a.TR="tr",a.TRACK="track",a.TT="tt",a.U="u",a.UL="ul",a.SVG="svg",a.VAR="var",a.WBR="wbr",a.XMP="xmp"})(I=g.TAG_NAMES||(g.TAG_NAMES={}));var i;(function(a){a[a.UNKNOWN=0]="UNKNOWN",a[a.A=1]="A",a[a.ADDRESS=2]="ADDRESS",a[a.ANNOTATION_XML=3]="ANNOTATION_XML",a[a.APPLET=4]="APPLET",a[a.AREA=5]="AREA",a[a.ARTICLE=6]="ARTICLE",a[a.ASIDE=7]="ASIDE",a[a.B=8]="B",a[a.BASE=9]="BASE",a[a.BASEFONT=10]="BASEFONT",a[a.BGSOUND=11]="BGSOUND",a[a.BIG=12]="BIG",a[a.BLOCKQUOTE=13]="BLOCKQUOTE",a[a.BODY=14]="BODY",a[a.BR=15]="BR",a[a.BUTTON=16]="BUTTON",a[a.CAPTION=17]="CAPTION",a[a.CENTER=18]="CENTER",a[a.CODE=19]="CODE",a[a.COL=20]="COL",a[a.COLGROUP=21]="COLGROUP",a[a.DD=22]="DD",a[a.DESC=23]="DESC",a[a.DETAILS=24]="DETAILS",a[a.DIALOG=25]="DIALOG",a[a.DIR=26]="DIR",a[a.DIV=27]="DIV",a[a.DL=28]="DL",a[a.DT=29]="DT",a[a.EM=30]="EM",a[a.EMBED=31]="EMBED",a[a.FIELDSET=32]="FIELDSET",a[a.FIGCAPTION=33]="FIGCAPTION",a[a.FIGURE=34]="FIGURE",a[a.FONT=35]="FONT",a[a.FOOTER=36]="FOOTER",a[a.FOREIGN_OBJECT=37]="FOREIGN_OBJECT",a[a.FORM=38]="FORM",a[a.FRAME=39]="FRAME",a[a.FRAMESET=40]="FRAMESET",a[a.H1=41]="H1",a[a.H2=42]="H2",a[a.H3=43]="H3",a[a.H4=44]="H4",a[a.H5=45]="H5",a[a.H6=46]="H6",a[a.HEAD=47]="HEAD",a[a.HEADER=48]="HEADER",a[a.HGROUP=49]="HGROUP",a[a.HR=50]="HR",a[a.HTML=51]="HTML",a[a.I=52]="I",a[a.IMG=53]="IMG",a[a.IMAGE=54]="IMAGE",a[a.INPUT=55]="INPUT",a[a.IFRAME=56]="IFRAME",a[a.KEYGEN=57]="KEYGEN",a[a.LABEL=58]="LABEL",a[a.LI=59]="LI",a[a.LINK=60]="LINK",a[a.LISTING=61]="LISTING",a[a.MAIN=62]="MAIN",a[a.MALIGNMARK=63]="MALIGNMARK",a[a.MARQUEE=64]="MARQUEE",a[a.MATH=65]="MATH",a[a.MENU=66]="MENU",a[a.META=67]="META",a[a.MGLYPH=68]="MGLYPH",a[a.MI=69]="MI",a[a.MO=70]="MO",a[a.MN=71]="MN",a[a.MS=72]="MS",a[a.MTEXT=73]="MTEXT",a[a.NAV=74]="NAV",a[a.NOBR=75]="NOBR",a[a.NOFRAMES=76]="NOFRAMES",a[a.NOEMBED=77]="NOEMBED",a[a.NOSCRIPT=78]="NOSCRIPT",a[a.OBJECT=79]="OBJECT",a[a.OL=80]="OL",a[a.OPTGROUP=81]="OPTGROUP",a[a.OPTION=82]="OPTION",a[a.P=83]="P",a[a.PARAM=84]="PARAM",a[a.PLAINTEXT=85]="PLAINTEXT",a[a.PRE=86]="PRE",a[a.RB=87]="RB",a[a.RP=88]="RP",a[a.RT=89]="RT",a[a.RTC=90]="RTC",a[a.RUBY=91]="RUBY",a[a.S=92]="S",a[a.SCRIPT=93]="SCRIPT",a[a.SECTION=94]="SECTION",a[a.SELECT=95]="SELECT",a[a.SOURCE=96]="SOURCE",a[a.SMALL=97]="SMALL",a[a.SPAN=98]="SPAN",a[a.STRIKE=99]="STRIKE",a[a.STRONG=100]="STRONG",a[a.STYLE=101]="STYLE",a[a.SUB=102]="SUB",a[a.SUMMARY=103]="SUMMARY",a[a.SUP=104]="SUP",a[a.TABLE=105]="TABLE",a[a.TBODY=106]="TBODY",a[a.TEMPLATE=107]="TEMPLATE",a[a.TEXTAREA=108]="TEXTAREA",a[a.TFOOT=109]="TFOOT",a[a.TD=110]="TD",a[a.TH=111]="TH",a[a.THEAD=112]="THEAD",a[a.TITLE=113]="TITLE",a[a.TR=114]="TR",a[a.TRACK=115]="TRACK",a[a.TT=116]="TT",a[a.U=117]="U",a[a.UL=118]="UL",a[a.SVG=119]="SVG",a[a.VAR=120]="VAR",a[a.WBR=121]="WBR",a[a.XMP=122]="XMP"})(i=g.TAG_ID||(g.TAG_ID={}));const n=new Map([[I.A,i.A],[I.ADDRESS,i.ADDRESS],[I.ANNOTATION_XML,i.ANNOTATION_XML],[I.APPLET,i.APPLET],[I.AREA,i.AREA],[I.ARTICLE,i.ARTICLE],[I.ASIDE,i.ASIDE],[I.B,i.B],[I.BASE,i.BASE],[I.BASEFONT,i.BASEFONT],[I.BGSOUND,i.BGSOUND],[I.BIG,i.BIG],[I.BLOCKQUOTE,i.BLOCKQUOTE],[I.BODY,i.BODY],[I.BR,i.BR],[I.BUTTON,i.BUTTON],[I.CAPTION,i.CAPTION],[I.CENTER,i.CENTER],[I.CODE,i.CODE],[I.COL,i.COL],[I.COLGROUP,i.COLGROUP],[I.DD,i.DD],[I.DESC,i.DESC],[I.DETAILS,i.DETAILS],[I.DIALOG,i.DIALOG],[I.DIR,i.DIR],[I.DIV,i.DIV],[I.DL,i.DL],[I.DT,i.DT],[I.EM,i.EM],[I.EMBED,i.EMBED],[I.FIELDSET,i.FIELDSET],[I.FIGCAPTION,i.FIGCAPTION],[I.FIGURE,i.FIGURE],[I.FONT,i.FONT],[I.FOOTER,i.FOOTER],[I.FOREIGN_OBJECT,i.FOREIGN_OBJECT],[I.FORM,i.FORM],[I.FRAME,i.FRAME],[I.FRAMESET,i.FRAMESET],[I.H1,i.H1],[I.H2,i.H2],[I.H3,i.H3],[I.H4,i.H4],[I.H5,i.H5],[I.H6,i.H6],[I.HEAD,i.HEAD],[I.HEADER,i.HEADER],[I.HGROUP,i.HGROUP],[I.HR,i.HR],[I.HTML,i.HTML],[I.I,i.I],[I.IMG,i.IMG],[I.IMAGE,i.IMAGE],[I.INPUT,i.INPUT],[I.IFRAME,i.IFRAME],[I.KEYGEN,i.KEYGEN],[I.LABEL,i.LABEL],[I.LI,i.LI],[I.LINK,i.LINK],[I.LISTING,i.LISTING],[I.MAIN,i.MAIN],[I.MALIGNMARK,i.MALIGNMARK],[I.MARQUEE,i.MARQUEE],[I.MATH,i.MATH],[I.MENU,i.MENU],[I.META,i.META],[I.MGLYPH,i.MGLYPH],[I.MI,i.MI],[I.MO,i.MO],[I.MN,i.MN],[I.MS,i.MS],[I.MTEXT,i.MTEXT],[I.NAV,i.NAV],[I.NOBR,i.NOBR],[I.NOFRAMES,i.NOFRAMES],[I.NOEMBED,i.NOEMBED],[I.NOSCRIPT,i.NOSCRIPT],[I.OBJECT,i.OBJECT],[I.OL,i.OL],[I.OPTGROUP,i.OPTGROUP],[I.OPTION,i.OPTION],[I.P,i.P],[I.PARAM,i.PARAM],[I.PLAINTEXT,i.PLAINTEXT],[I.PRE,i.PRE],[I.RB,i.RB],[I.RP,i.RP],[I.RT,i.RT],[I.RTC,i.RTC],[I.RUBY,i.RUBY],[I.S,i.S],[I.SCRIPT,i.SCRIPT],[I.SECTION,i.SECTION],[I.SELECT,i.SELECT],[I.SOURCE,i.SOURCE],[I.SMALL,i.SMALL],[I.SPAN,i.SPAN],[I.STRIKE,i.STRIKE],[I.STRONG,i.STRONG],[I.STYLE,i.STYLE],[I.SUB,i.SUB],[I.SUMMARY,i.SUMMARY],[I.SUP,i.SUP],[I.TABLE,i.TABLE],[I.TBODY,i.TBODY],[I.TEMPLATE,i.TEMPLATE],[I.TEXTAREA,i.TEXTAREA],[I.TFOOT,i.TFOOT],[I.TD,i.TD],[I.TH,i.TH],[I.THEAD,i.THEAD],[I.TITLE,i.TITLE],[I.TR,i.TR],[I.TRACK,i.TRACK],[I.TT,i.TT],[I.U,i.U],[I.UL,i.UL],[I.SVG,i.SVG],[I.VAR,i.VAR],[I.WBR,i.WBR],[I.XMP,i.XMP]]);function C(a){var l;return(l=n.get(a))!==null&&l!==void 0?l:i.UNKNOWN}g.getTagID=C;const r=i;g.SPECIAL_ELEMENTS={[e.HTML]:new Set([r.ADDRESS,r.APPLET,r.AREA,r.ARTICLE,r.ASIDE,r.BASE,r.BASEFONT,r.BGSOUND,r.BLOCKQUOTE,r.BODY,r.BR,r.BUTTON,r.CAPTION,r.CENTER,r.COL,r.COLGROUP,r.DD,r.DETAILS,r.DIR,r.DIV,r.DL,r.DT,r.EMBED,r.FIELDSET,r.FIGCAPTION,r.FIGURE,r.FOOTER,r.FORM,r.FRAME,r.FRAMESET,r.H1,r.H2,r.H3,r.H4,r.H5,r.H6,r.HEAD,r.HEADER,r.HGROUP,r.HR,r.HTML,r.IFRAME,r.IMG,r.INPUT,r.LI,r.LINK,r.LISTING,r.MAIN,r.MARQUEE,r.MENU,r.META,r.NAV,r.NOEMBED,r.NOFRAMES,r.NOSCRIPT,r.OBJECT,r.OL,r.P,r.PARAM,r.PLAINTEXT,r.PRE,r.SCRIPT,r.SECTION,r.SELECT,r.SOURCE,r.STYLE,r.SUMMARY,r.TABLE,r.TBODY,r.TD,r.TEMPLATE,r.TEXTAREA,r.TFOOT,r.TH,r.THEAD,r.TITLE,r.TR,r.TRACK,r.UL,r.WBR,r.XMP]),[e.MATHML]:new Set([r.MI,r.MO,r.MN,r.MS,r.MTEXT,r.ANNOTATION_XML]),[e.SVG]:new Set([r.TITLE,r.FOREIGN_OBJECT,r.DESC]),[e.XLINK]:new Set,[e.XML]:new Set,[e.XMLNS]:new Set};function o(a){return a===r.H1||a===r.H2||a===r.H3||a===r.H4||a===r.H5||a===r.H6}g.isNumberedHeader=o;const A=new Set([I.STYLE,I.SCRIPT,I.XMP,I.IFRAME,I.NOEMBED,I.NOFRAMES,I.PLAINTEXT]);function s(a,l){return A.has(a)||l&&a===I.NOSCRIPT}g.hasUnescapedText=s})(dl);function wft(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function Jne(g,e){for(var I=0;I=Ae.CODE_POINTS.DIGIT_0&&g<=Ae.CODE_POINTS.DIGIT_9}function IG(g){return g>=Ae.CODE_POINTS.LATIN_CAPITAL_A&&g<=Ae.CODE_POINTS.LATIN_CAPITAL_Z}function Tft(g){return g>=Ae.CODE_POINTS.LATIN_SMALL_A&&g<=Ae.CODE_POINTS.LATIN_SMALL_Z}function El(g){return Tft(g)||IG(g)}function Hz(g){return El(g)||oB(g)}function xSe(g){return g>=Ae.CODE_POINTS.LATIN_CAPITAL_A&&g<=Ae.CODE_POINTS.LATIN_CAPITAL_F}function DSe(g){return g>=Ae.CODE_POINTS.LATIN_SMALL_A&&g<=Ae.CODE_POINTS.LATIN_SMALL_F}function Nft(g){return oB(g)||xSe(g)||DSe(g)}function BR(g){return g+32}function FSe(g){return g===Ae.CODE_POINTS.SPACE||g===Ae.CODE_POINTS.LINE_FEED||g===Ae.CODE_POINTS.TABULATION||g===Ae.CODE_POINTS.FORM_FEED}function kft(g){return g===Ae.CODE_POINTS.EQUALS_SIGN||Hz(g)}function One(g){return FSe(g)||g===Ae.CODE_POINTS.SOLIDUS||g===Ae.CODE_POINTS.GREATER_THAN_SIGN}let Yft=function(){function g(e,I){wft(this,g),this.options=e,this.handler=I,this.paused=!1,this.inLoop=!1,this.inForeignNode=!1,this.lastStartTagName="",this.active=!1,this.state=pe.DATA,this.returnState=pe.DATA,this.charRefCode=-1,this.consumedAfterSnapshot=-1,this.currentCharacterToken=null,this.currentToken=null,this.currentAttr={name:"",value:""},this.preprocessor=new Xft.Preprocessor(I),this.currentLocation=this.getCurrentLocation(-1)}return Vft(g,[{key:"_err",value:function(I){var i,n;(n=(i=this.handler).onParseError)===null||n===void 0||n.call(i,this.preprocessor.getError(I))}},{key:"getCurrentLocation",value:function(I){return this.options.sourceCodeLocationInfo?{startLine:this.preprocessor.line,startCol:this.preprocessor.col-I,startOffset:this.preprocessor.offset-I,endLine:-1,endCol:-1,endOffset:-1}:null}},{key:"_runParsingLoop",value:function(){if(!this.inLoop){for(this.inLoop=!0;this.active&&!this.paused;){this.consumedAfterSnapshot=0;const I=this._consume();this._ensureHibernation()||this._callState(I)}this.inLoop=!1}}},{key:"pause",value:function(){this.paused=!0}},{key:"resume",value:function(I){if(!this.paused)throw new Error("Parser was already resumed");this.paused=!1,!this.inLoop&&(this._runParsingLoop(),this.paused||I==null||I())}},{key:"write",value:function(I,i,n){this.active=!0,this.preprocessor.write(I,i),this._runParsingLoop(),this.paused||n==null||n()}},{key:"insertHtmlAtCurrentPos",value:function(I){this.active=!0,this.preprocessor.insertHtmlAtCurrentPos(I),this._runParsingLoop()}},{key:"_ensureHibernation",value:function(){return this.preprocessor.endOfChunkHit?(this._unconsume(this.consumedAfterSnapshot),this.active=!1,!0):!1}},{key:"_consume",value:function(){return this.consumedAfterSnapshot++,this.preprocessor.advance()}},{key:"_unconsume",value:function(I){this.consumedAfterSnapshot-=I,this.preprocessor.retreat(I)}},{key:"_reconsumeInState",value:function(I,i){this.state=I,this._callState(i)}},{key:"_advanceBy",value:function(I){this.consumedAfterSnapshot+=I;for(let i=0;i0&&this._err(je.ERR.endTagWithAttributes),I.selfClosing&&this._err(je.ERR.endTagWithTrailingSolidus),this.handler.onEndTag(I)),this.preprocessor.dropParsedChunk()}},{key:"emitCurrentComment",value:function(I){this.prepareToken(I),this.handler.onComment(I),this.preprocessor.dropParsedChunk()}},{key:"emitCurrentDoctype",value:function(I){this.prepareToken(I),this.handler.onDoctype(I),this.preprocessor.dropParsedChunk()}},{key:"_emitCurrentCharacterToken",value:function(I){if(this.currentCharacterToken){switch(I&&this.currentCharacterToken.location&&(this.currentCharacterToken.location.endLine=I.startLine,this.currentCharacterToken.location.endCol=I.startCol,this.currentCharacterToken.location.endOffset=I.startOffset),this.currentCharacterToken.type){case fC.TokenType.CHARACTER:{this.handler.onCharacter(this.currentCharacterToken);break}case fC.TokenType.NULL_CHARACTER:{this.handler.onNullCharacter(this.currentCharacterToken);break}case fC.TokenType.WHITESPACE_CHARACTER:{this.handler.onWhitespaceCharacter(this.currentCharacterToken);break}}this.currentCharacterToken=null}}},{key:"_emitEOFToken",value:function(){const I=this.getCurrentLocation(0);I&&(I.endLine=I.startLine,I.endCol=I.startCol,I.endOffset=I.startOffset),this._emitCurrentCharacterToken(I),this.handler.onEof({type:fC.TokenType.EOF,location:I}),this.active=!1}},{key:"_appendCharToCurrentCharacterToken",value:function(I,i){if(this.currentCharacterToken)if(this.currentCharacterToken.type!==I)this.currentLocation=this.getCurrentLocation(0),this._emitCurrentCharacterToken(this.currentLocation),this.preprocessor.dropParsedChunk();else{this.currentCharacterToken.chars+=i;return}this._createCharacterToken(I,i)}},{key:"_emitCodePoint",value:function(I){const i=FSe(I)?fC.TokenType.WHITESPACE_CHARACTER:I===Ae.CODE_POINTS.NULL?fC.TokenType.NULL_CHARACTER:fC.TokenType.CHARACTER;this._appendCharToCurrentCharacterToken(i,String.fromCodePoint(I))}},{key:"_emitChars",value:function(I){this._appendCharToCurrentCharacterToken(fC.TokenType.CHARACTER,I)}},{key:"_matchNamedCharacterReference",value:function(I){let i=null,n=0,C=!1;for(let r=0,o=WA.htmlDecodeTree[0];r>=0&&(r=(0,WA.determineBranch)(WA.htmlDecodeTree,o,r+1,I),!(r<0));I=this._consume()){n+=1,o=WA.htmlDecodeTree[r];const A=o&WA.BinTrieFlags.VALUE_LENGTH;if(A){const s=(A>>14)-1;if(I!==Ae.CODE_POINTS.SEMICOLON&&this._isCharacterReferenceInAttribute()&&kft(this.preprocessor.peek(1))?(i=[Ae.CODE_POINTS.AMPERSAND],r+=s):(i=s===0?[WA.htmlDecodeTree[r]&~WA.BinTrieFlags.VALUE_LENGTH]:s===1?[WA.htmlDecodeTree[++r]]:[WA.htmlDecodeTree[++r],WA.htmlDecodeTree[++r]],n=0,C=I!==Ae.CODE_POINTS.SEMICOLON),s===0){this._consume();break}}}return this._unconsume(n),C&&!this.preprocessor.endOfChunkHit&&this._err(je.ERR.missingSemicolonAfterCharacterReference),this._unconsume(1),i}},{key:"_isCharacterReferenceInAttribute",value:function(){return this.returnState===pe.ATTRIBUTE_VALUE_DOUBLE_QUOTED||this.returnState===pe.ATTRIBUTE_VALUE_SINGLE_QUOTED||this.returnState===pe.ATTRIBUTE_VALUE_UNQUOTED}},{key:"_flushCodePointConsumedAsCharacterReference",value:function(I){this._isCharacterReferenceInAttribute()?this.currentAttr.value+=String.fromCodePoint(I):this._emitCodePoint(I)}},{key:"_callState",value:function(I){switch(this.state){case pe.DATA:{this._stateData(I);break}case pe.RCDATA:{this._stateRcdata(I);break}case pe.RAWTEXT:{this._stateRawtext(I);break}case pe.SCRIPT_DATA:{this._stateScriptData(I);break}case pe.PLAINTEXT:{this._statePlaintext(I);break}case pe.TAG_OPEN:{this._stateTagOpen(I);break}case pe.END_TAG_OPEN:{this._stateEndTagOpen(I);break}case pe.TAG_NAME:{this._stateTagName(I);break}case pe.RCDATA_LESS_THAN_SIGN:{this._stateRcdataLessThanSign(I);break}case pe.RCDATA_END_TAG_OPEN:{this._stateRcdataEndTagOpen(I);break}case pe.RCDATA_END_TAG_NAME:{this._stateRcdataEndTagName(I);break}case pe.RAWTEXT_LESS_THAN_SIGN:{this._stateRawtextLessThanSign(I);break}case pe.RAWTEXT_END_TAG_OPEN:{this._stateRawtextEndTagOpen(I);break}case pe.RAWTEXT_END_TAG_NAME:{this._stateRawtextEndTagName(I);break}case pe.SCRIPT_DATA_LESS_THAN_SIGN:{this._stateScriptDataLessThanSign(I);break}case pe.SCRIPT_DATA_END_TAG_OPEN:{this._stateScriptDataEndTagOpen(I);break}case pe.SCRIPT_DATA_END_TAG_NAME:{this._stateScriptDataEndTagName(I);break}case pe.SCRIPT_DATA_ESCAPE_START:{this._stateScriptDataEscapeStart(I);break}case pe.SCRIPT_DATA_ESCAPE_START_DASH:{this._stateScriptDataEscapeStartDash(I);break}case pe.SCRIPT_DATA_ESCAPED:{this._stateScriptDataEscaped(I);break}case pe.SCRIPT_DATA_ESCAPED_DASH:{this._stateScriptDataEscapedDash(I);break}case pe.SCRIPT_DATA_ESCAPED_DASH_DASH:{this._stateScriptDataEscapedDashDash(I);break}case pe.SCRIPT_DATA_ESCAPED_LESS_THAN_SIGN:{this._stateScriptDataEscapedLessThanSign(I);break}case pe.SCRIPT_DATA_ESCAPED_END_TAG_OPEN:{this._stateScriptDataEscapedEndTagOpen(I);break}case pe.SCRIPT_DATA_ESCAPED_END_TAG_NAME:{this._stateScriptDataEscapedEndTagName(I);break}case pe.SCRIPT_DATA_DOUBLE_ESCAPE_START:{this._stateScriptDataDoubleEscapeStart(I);break}case pe.SCRIPT_DATA_DOUBLE_ESCAPED:{this._stateScriptDataDoubleEscaped(I);break}case pe.SCRIPT_DATA_DOUBLE_ESCAPED_DASH:{this._stateScriptDataDoubleEscapedDash(I);break}case pe.SCRIPT_DATA_DOUBLE_ESCAPED_DASH_DASH:{this._stateScriptDataDoubleEscapedDashDash(I);break}case pe.SCRIPT_DATA_DOUBLE_ESCAPED_LESS_THAN_SIGN:{this._stateScriptDataDoubleEscapedLessThanSign(I);break}case pe.SCRIPT_DATA_DOUBLE_ESCAPE_END:{this._stateScriptDataDoubleEscapeEnd(I);break}case pe.BEFORE_ATTRIBUTE_NAME:{this._stateBeforeAttributeName(I);break}case pe.ATTRIBUTE_NAME:{this._stateAttributeName(I);break}case pe.AFTER_ATTRIBUTE_NAME:{this._stateAfterAttributeName(I);break}case pe.BEFORE_ATTRIBUTE_VALUE:{this._stateBeforeAttributeValue(I);break}case pe.ATTRIBUTE_VALUE_DOUBLE_QUOTED:{this._stateAttributeValueDoubleQuoted(I);break}case pe.ATTRIBUTE_VALUE_SINGLE_QUOTED:{this._stateAttributeValueSingleQuoted(I);break}case pe.ATTRIBUTE_VALUE_UNQUOTED:{this._stateAttributeValueUnquoted(I);break}case pe.AFTER_ATTRIBUTE_VALUE_QUOTED:{this._stateAfterAttributeValueQuoted(I);break}case pe.SELF_CLOSING_START_TAG:{this._stateSelfClosingStartTag(I);break}case pe.BOGUS_COMMENT:{this._stateBogusComment(I);break}case pe.MARKUP_DECLARATION_OPEN:{this._stateMarkupDeclarationOpen(I);break}case pe.COMMENT_START:{this._stateCommentStart(I);break}case pe.COMMENT_START_DASH:{this._stateCommentStartDash(I);break}case pe.COMMENT:{this._stateComment(I);break}case pe.COMMENT_LESS_THAN_SIGN:{this._stateCommentLessThanSign(I);break}case pe.COMMENT_LESS_THAN_SIGN_BANG:{this._stateCommentLessThanSignBang(I);break}case pe.COMMENT_LESS_THAN_SIGN_BANG_DASH:{this._stateCommentLessThanSignBangDash(I);break}case pe.COMMENT_LESS_THAN_SIGN_BANG_DASH_DASH:{this._stateCommentLessThanSignBangDashDash(I);break}case pe.COMMENT_END_DASH:{this._stateCommentEndDash(I);break}case pe.COMMENT_END:{this._stateCommentEnd(I);break}case pe.COMMENT_END_BANG:{this._stateCommentEndBang(I);break}case pe.DOCTYPE:{this._stateDoctype(I);break}case pe.BEFORE_DOCTYPE_NAME:{this._stateBeforeDoctypeName(I);break}case pe.DOCTYPE_NAME:{this._stateDoctypeName(I);break}case pe.AFTER_DOCTYPE_NAME:{this._stateAfterDoctypeName(I);break}case pe.AFTER_DOCTYPE_PUBLIC_KEYWORD:{this._stateAfterDoctypePublicKeyword(I);break}case pe.BEFORE_DOCTYPE_PUBLIC_IDENTIFIER:{this._stateBeforeDoctypePublicIdentifier(I);break}case pe.DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED:{this._stateDoctypePublicIdentifierDoubleQuoted(I);break}case pe.DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED:{this._stateDoctypePublicIdentifierSingleQuoted(I);break}case pe.AFTER_DOCTYPE_PUBLIC_IDENTIFIER:{this._stateAfterDoctypePublicIdentifier(I);break}case pe.BETWEEN_DOCTYPE_PUBLIC_AND_SYSTEM_IDENTIFIERS:{this._stateBetweenDoctypePublicAndSystemIdentifiers(I);break}case pe.AFTER_DOCTYPE_SYSTEM_KEYWORD:{this._stateAfterDoctypeSystemKeyword(I);break}case pe.BEFORE_DOCTYPE_SYSTEM_IDENTIFIER:{this._stateBeforeDoctypeSystemIdentifier(I);break}case pe.DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED:{this._stateDoctypeSystemIdentifierDoubleQuoted(I);break}case pe.DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED:{this._stateDoctypeSystemIdentifierSingleQuoted(I);break}case pe.AFTER_DOCTYPE_SYSTEM_IDENTIFIER:{this._stateAfterDoctypeSystemIdentifier(I);break}case pe.BOGUS_DOCTYPE:{this._stateBogusDoctype(I);break}case pe.CDATA_SECTION:{this._stateCdataSection(I);break}case pe.CDATA_SECTION_BRACKET:{this._stateCdataSectionBracket(I);break}case pe.CDATA_SECTION_END:{this._stateCdataSectionEnd(I);break}case pe.CHARACTER_REFERENCE:{this._stateCharacterReference(I);break}case pe.NAMED_CHARACTER_REFERENCE:{this._stateNamedCharacterReference(I);break}case pe.AMBIGUOUS_AMPERSAND:{this._stateAmbiguousAmpersand(I);break}case pe.NUMERIC_CHARACTER_REFERENCE:{this._stateNumericCharacterReference(I);break}case pe.HEXADEMICAL_CHARACTER_REFERENCE_START:{this._stateHexademicalCharacterReferenceStart(I);break}case pe.HEXADEMICAL_CHARACTER_REFERENCE:{this._stateHexademicalCharacterReference(I);break}case pe.DECIMAL_CHARACTER_REFERENCE:{this._stateDecimalCharacterReference(I);break}case pe.NUMERIC_CHARACTER_REFERENCE_END:{this._stateNumericCharacterReferenceEnd(I);break}default:throw new Error("Unknown state")}}},{key:"_stateData",value:function(I){switch(I){case Ae.CODE_POINTS.LESS_THAN_SIGN:{this.state=pe.TAG_OPEN;break}case Ae.CODE_POINTS.AMPERSAND:{this.returnState=pe.DATA,this.state=pe.CHARACTER_REFERENCE;break}case Ae.CODE_POINTS.NULL:{this._err(je.ERR.unexpectedNullCharacter),this._emitCodePoint(I);break}case Ae.CODE_POINTS.EOF:{this._emitEOFToken();break}default:this._emitCodePoint(I)}}},{key:"_stateRcdata",value:function(I){switch(I){case Ae.CODE_POINTS.AMPERSAND:{this.returnState=pe.RCDATA,this.state=pe.CHARACTER_REFERENCE;break}case Ae.CODE_POINTS.LESS_THAN_SIGN:{this.state=pe.RCDATA_LESS_THAN_SIGN;break}case Ae.CODE_POINTS.NULL:{this._err(je.ERR.unexpectedNullCharacter),this._emitChars(Ae.REPLACEMENT_CHARACTER);break}case Ae.CODE_POINTS.EOF:{this._emitEOFToken();break}default:this._emitCodePoint(I)}}},{key:"_stateRawtext",value:function(I){switch(I){case Ae.CODE_POINTS.LESS_THAN_SIGN:{this.state=pe.RAWTEXT_LESS_THAN_SIGN;break}case Ae.CODE_POINTS.NULL:{this._err(je.ERR.unexpectedNullCharacter),this._emitChars(Ae.REPLACEMENT_CHARACTER);break}case Ae.CODE_POINTS.EOF:{this._emitEOFToken();break}default:this._emitCodePoint(I)}}},{key:"_stateScriptData",value:function(I){switch(I){case Ae.CODE_POINTS.LESS_THAN_SIGN:{this.state=pe.SCRIPT_DATA_LESS_THAN_SIGN;break}case Ae.CODE_POINTS.NULL:{this._err(je.ERR.unexpectedNullCharacter),this._emitChars(Ae.REPLACEMENT_CHARACTER);break}case Ae.CODE_POINTS.EOF:{this._emitEOFToken();break}default:this._emitCodePoint(I)}}},{key:"_statePlaintext",value:function(I){switch(I){case Ae.CODE_POINTS.NULL:{this._err(je.ERR.unexpectedNullCharacter),this._emitChars(Ae.REPLACEMENT_CHARACTER);break}case Ae.CODE_POINTS.EOF:{this._emitEOFToken();break}default:this._emitCodePoint(I)}}},{key:"_stateTagOpen",value:function(I){if(El(I))this._createStartTagToken(),this.state=pe.TAG_NAME,this._stateTagName(I);else switch(I){case Ae.CODE_POINTS.EXCLAMATION_MARK:{this.state=pe.MARKUP_DECLARATION_OPEN;break}case Ae.CODE_POINTS.SOLIDUS:{this.state=pe.END_TAG_OPEN;break}case Ae.CODE_POINTS.QUESTION_MARK:{this._err(je.ERR.unexpectedQuestionMarkInsteadOfTagName),this._createCommentToken(1),this.state=pe.BOGUS_COMMENT,this._stateBogusComment(I);break}case Ae.CODE_POINTS.EOF:{this._err(je.ERR.eofBeforeTagName),this._emitChars("<"),this._emitEOFToken();break}default:this._err(je.ERR.invalidFirstCharacterOfTagName),this._emitChars("<"),this.state=pe.DATA,this._stateData(I)}}},{key:"_stateEndTagOpen",value:function(I){if(El(I))this._createEndTagToken(),this.state=pe.TAG_NAME,this._stateTagName(I);else switch(I){case Ae.CODE_POINTS.GREATER_THAN_SIGN:{this._err(je.ERR.missingEndTagName),this.state=pe.DATA;break}case Ae.CODE_POINTS.EOF:{this._err(je.ERR.eofBeforeTagName),this._emitChars("");break}case Ae.CODE_POINTS.NULL:{this._err(je.ERR.unexpectedNullCharacter),this.state=pe.SCRIPT_DATA_ESCAPED,this._emitChars(Ae.REPLACEMENT_CHARACTER);break}case Ae.CODE_POINTS.EOF:{this._err(je.ERR.eofInScriptHtmlCommentLikeText),this._emitEOFToken();break}default:this.state=pe.SCRIPT_DATA_ESCAPED,this._emitCodePoint(I)}}},{key:"_stateScriptDataEscapedLessThanSign",value:function(I){I===Ae.CODE_POINTS.SOLIDUS?this.state=pe.SCRIPT_DATA_ESCAPED_END_TAG_OPEN:El(I)?(this._emitChars("<"),this.state=pe.SCRIPT_DATA_DOUBLE_ESCAPE_START,this._stateScriptDataDoubleEscapeStart(I)):(this._emitChars("<"),this.state=pe.SCRIPT_DATA_ESCAPED,this._stateScriptDataEscaped(I))}},{key:"_stateScriptDataEscapedEndTagOpen",value:function(I){El(I)?(this.state=pe.SCRIPT_DATA_ESCAPED_END_TAG_NAME,this._stateScriptDataEscapedEndTagName(I)):(this._emitChars("");break}case Ae.CODE_POINTS.NULL:{this._err(je.ERR.unexpectedNullCharacter),this.state=pe.SCRIPT_DATA_DOUBLE_ESCAPED,this._emitChars(Ae.REPLACEMENT_CHARACTER);break}case Ae.CODE_POINTS.EOF:{this._err(je.ERR.eofInScriptHtmlCommentLikeText),this._emitEOFToken();break}default:this.state=pe.SCRIPT_DATA_DOUBLE_ESCAPED,this._emitCodePoint(I)}}},{key:"_stateScriptDataDoubleEscapedLessThanSign",value:function(I){I===Ae.CODE_POINTS.SOLIDUS?(this.state=pe.SCRIPT_DATA_DOUBLE_ESCAPE_END,this._emitChars("/")):(this.state=pe.SCRIPT_DATA_DOUBLE_ESCAPED,this._stateScriptDataDoubleEscaped(I))}},{key:"_stateScriptDataDoubleEscapeEnd",value:function(I){if(this.preprocessor.startsWith(Ae.SEQUENCES.SCRIPT,!1)&&One(this.preprocessor.peek(Ae.SEQUENCES.SCRIPT.length))){this._emitCodePoint(I);for(let i=0;i1114111)this._err(je.ERR.characterReferenceOutsideUnicodeRange),this.charRefCode=Ae.CODE_POINTS.REPLACEMENT_CHARACTER;else if((0,Ae.isSurrogate)(this.charRefCode))this._err(je.ERR.surrogateCharacterReference),this.charRefCode=Ae.CODE_POINTS.REPLACEMENT_CHARACTER;else if((0,Ae.isUndefinedCodePoint)(this.charRefCode))this._err(je.ERR.noncharacterCharacterReference);else if((0,Ae.isControlCodePoint)(this.charRefCode)||this.charRefCode===Ae.CODE_POINTS.CARRIAGE_RETURN){this._err(je.ERR.controlCharacterReference);const i=Hft.get(this.charRefCode);i!==void 0&&(this.charRefCode=i)}this._flushCodePointConsumedAsCharacterReference(this.charRefCode),this._reconsumeInState(this.returnState,I)}}]),g}();bh.Tokenizer=Yft;var Gk={};function Kft(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function Lne(g,e){for(var I=0;I0&&this._isInTemplate()&&this.tmplCount--,this.stackTop--,this._updateCurrentElement(),this.handler.onItemPop(I,!0)}},{key:"replace",value:function(I,i){const n=this._indexOf(I);this.items[n]=i,n===this.stackTop&&(this.current=i)}},{key:"insertAfter",value:function(I,i,n){const C=this._indexOf(I)+1;this.items.splice(C,0,i),this.tagIDs.splice(C,0,n),this.stackTop++,C===this.stackTop&&this._updateCurrentElement(),this.handler.onItemPush(this.current,this.currentTagId,C===this.stackTop)}},{key:"popUntilTagNamePopped",value:function(I){let i=this.stackTop+1;do i=this.tagIDs.lastIndexOf(I,i-1);while(i>0&&this.treeAdapter.getNamespaceURI(this.items[i])!==gt.NS.HTML);this.shortenToLength(i<0?0:i)}},{key:"shortenToLength",value:function(I){for(;this.stackTop>=I;){const i=this.current;this.tmplCount>0&&this._isInTemplate()&&(this.tmplCount-=1),this.stackTop--,this._updateCurrentElement(),this.handler.onItemPop(i,this.stackTop=0;n--)if(I.includes(this.tagIDs[n])&&this.treeAdapter.getNamespaceURI(this.items[n])===i)return n;return-1}},{key:"clearBackTo",value:function(I,i){const n=this._indexOfTagNames(I,i);this.shortenToLength(n+1)}},{key:"clearBackToTableContext",value:function(){this.clearBackTo(Pft,gt.NS.HTML)}},{key:"clearBackToTableBodyContext",value:function(){this.clearBackTo(zft,gt.NS.HTML)}},{key:"clearBackToTableRowContext",value:function(){this.clearBackTo(Mft,gt.NS.HTML)}},{key:"remove",value:function(I){const i=this._indexOf(I);i>=0&&(i===this.stackTop?this.pop():(this.items.splice(i,1),this.tagIDs.splice(i,1),this.stackTop--,this._updateCurrentElement(),this.handler.onItemPop(I,!1)))}},{key:"tryPeekProperlyNestedBodyElement",value:function(){return this.stackTop>=1&&this.tagIDs[1]===gt.TAG_ID.BODY?this.items[1]:null}},{key:"contains",value:function(I){return this._indexOf(I)>-1}},{key:"getCommonAncestor",value:function(I){const i=this._indexOf(I)-1;return i>=0?this.items[i]:null}},{key:"isRootHtmlElementCurrent",value:function(){return this.stackTop===0&&this.tagIDs[0]===gt.TAG_ID.HTML}},{key:"hasInScope",value:function(I){for(let i=this.stackTop;i>=0;i--){const n=this.tagIDs[i],C=this.treeAdapter.getNamespaceURI(this.items[i]);if(n===I&&C===gt.NS.HTML)return!0;if(vR.get(n)===C)return!1}return!0}},{key:"hasNumberedHeaderInScope",value:function(){for(let I=this.stackTop;I>=0;I--){const i=this.tagIDs[I],n=this.treeAdapter.getNamespaceURI(this.items[I]);if((0,gt.isNumberedHeader)(i)&&n===gt.NS.HTML)return!0;if(vR.get(i)===n)return!1}return!0}},{key:"hasInListItemScope",value:function(I){for(let i=this.stackTop;i>=0;i--){const n=this.tagIDs[i],C=this.treeAdapter.getNamespaceURI(this.items[i]);if(n===I&&C===gt.NS.HTML)return!0;if((n===gt.TAG_ID.UL||n===gt.TAG_ID.OL)&&C===gt.NS.HTML||vR.get(n)===C)return!1}return!0}},{key:"hasInButtonScope",value:function(I){for(let i=this.stackTop;i>=0;i--){const n=this.tagIDs[i],C=this.treeAdapter.getNamespaceURI(this.items[i]);if(n===I&&C===gt.NS.HTML)return!0;if(n===gt.TAG_ID.BUTTON&&C===gt.NS.HTML||vR.get(n)===C)return!1}return!0}},{key:"hasInTableScope",value:function(I){for(let i=this.stackTop;i>=0;i--){const n=this.tagIDs[i];if(this.treeAdapter.getNamespaceURI(this.items[i])===gt.NS.HTML){if(n===I)return!0;if(n===gt.TAG_ID.TABLE||n===gt.TAG_ID.TEMPLATE||n===gt.TAG_ID.HTML)return!1}}return!0}},{key:"hasTableBodyContextInTableScope",value:function(){for(let I=this.stackTop;I>=0;I--){const i=this.tagIDs[I];if(this.treeAdapter.getNamespaceURI(this.items[I])===gt.NS.HTML){if(i===gt.TAG_ID.TBODY||i===gt.TAG_ID.THEAD||i===gt.TAG_ID.TFOOT)return!0;if(i===gt.TAG_ID.TABLE||i===gt.TAG_ID.HTML)return!1}}return!0}},{key:"hasInSelectScope",value:function(I){for(let i=this.stackTop;i>=0;i--){const n=this.tagIDs[i];if(this.treeAdapter.getNamespaceURI(this.items[i])===gt.NS.HTML){if(n===I)return!0;if(n!==gt.TAG_ID.OPTION&&n!==gt.TAG_ID.OPTGROUP)return!1}}return!0}},{key:"generateImpliedEndTags",value:function(){for(;ESe.has(this.currentTagId);)this.pop()}},{key:"generateImpliedEndTagsThoroughly",value:function(){for(;_ne.has(this.currentTagId);)this.pop()}},{key:"generateImpliedEndTagsWithExclusion",value:function(I){for(;this.currentTagId!==I&&_ne.has(this.currentTagId);)this.pop()}}]),g}();Gk.OpenElementStack=Oft;var MSe={};(function(g){function e(a,l){if(!(a instanceof l))throw new TypeError("Cannot call a class as a function")}function I(a,l){for(var c=0;c[f.name,f.value]));let m=0;for(let f=0;fh.get(p.name)===p.value)&&(m+=1,m>=r&&this.entries.splice(b.idx,1))}}},{key:"insertMarker",value:function(){this.entries.unshift(A)}},{key:"pushElement",value:function(c,u){this._ensureNoahArkCondition(c),this.entries.unshift({type:o.Element,element:c,token:u})}},{key:"insertElementAfterBookmark",value:function(c,u){const d=this.entries.indexOf(this.bookmark);this.entries.splice(d,0,{type:o.Element,element:c,token:u})}},{key:"removeEntry",value:function(c){const u=this.entries.indexOf(c);u>=0&&this.entries.splice(u,1)}},{key:"clearToLastMarker",value:function(){const c=this.entries.indexOf(A);c>=0?this.entries.splice(0,c+1):this.entries.length=0}},{key:"getElementEntryInScopeWithTagName",value:function(c){const u=this.entries.find(d=>d.type===o.Marker||this.treeAdapter.getTagName(d.element)===c);return u&&u.type===o.Element?u:null}},{key:"getElementEntry",value:function(c){return this.entries.find(u=>u.type===o.Element&&u.element===c)}}]),a}();g.FormattingElementList=s})(MSe);var Bk={};(function(g){Object.defineProperty(g,"__esModule",{value:!0}),g.defaultTreeAdapter=void 0;const e=dl;function I(i){return{nodeName:"#text",value:i,parentNode:null}}g.defaultTreeAdapter={createDocument(){return{nodeName:"#document",mode:e.DOCUMENT_MODE.NO_QUIRKS,childNodes:[]}},createDocumentFragment(){return{nodeName:"#document-fragment",childNodes:[]}},createElement(i,n,C){return{nodeName:i,tagName:i,attrs:C,namespaceURI:n,childNodes:[],parentNode:null}},createCommentNode(i){return{nodeName:"#comment",data:i,parentNode:null}},appendChild(i,n){i.childNodes.push(n),n.parentNode=i},insertBefore(i,n,C){const r=i.childNodes.indexOf(C);i.childNodes.splice(r,0,n),n.parentNode=i},setTemplateContent(i,n){i.content=n},getTemplateContent(i){return i.content},setDocumentType(i,n,C,r){const o=i.childNodes.find(A=>A.nodeName==="#documentType");if(o)o.name=n,o.publicId=C,o.systemId=r;else{const A={nodeName:"#documentType",name:n,publicId:C,systemId:r,parentNode:null};g.defaultTreeAdapter.appendChild(i,A)}},setDocumentMode(i,n){i.mode=n},getDocumentMode(i){return i.mode},detachNode(i){if(i.parentNode){const n=i.parentNode.childNodes.indexOf(i);i.parentNode.childNodes.splice(n,1),i.parentNode=null}},insertText(i,n){if(i.childNodes.length>0){const C=i.childNodes[i.childNodes.length-1];if(g.defaultTreeAdapter.isTextNode(C)){C.value+=n;return}}g.defaultTreeAdapter.appendChild(i,I(n))},insertTextBefore(i,n,C){const r=i.childNodes[i.childNodes.indexOf(C)-1];r&&g.defaultTreeAdapter.isTextNode(r)?r.value+=n:g.defaultTreeAdapter.insertBefore(i,I(n),C)},adoptAttributes(i,n){const C=new Set(i.attrs.map(r=>r.name));for(let r=0;rg.startsWith(I))}function $ft(g){return g.name===zSe&&g.publicId===null&&(g.systemId===null||g.systemId===Lft)}g0.isConforming=$ft;function qft(g){if(g.name!==zSe)return qm.DOCUMENT_MODE.QUIRKS;const{systemId:e}=g;if(e&&e.toLowerCase()===_ft)return qm.DOCUMENT_MODE.QUIRKS;let{publicId:I}=g;if(I!==null){if(I=I.toLowerCase(),Qft.has(I))return qm.DOCUMENT_MODE.QUIRKS;let i=e===null?Uft:PSe;if(Une(I,i))return qm.DOCUMENT_MODE.QUIRKS;if(i=e===null?JSe:jft,Une(I,i))return qm.DOCUMENT_MODE.LIMITED_QUIRKS}return qm.DOCUMENT_MODE.NO_QUIRKS}g0.getDocumentMode=qft;var cj={};(function(g){Object.defineProperty(g,"__esModule",{value:!0}),g.isIntegrationPoint=g.adjustTokenSVGTagName=g.adjustTokenXMLAttrs=g.adjustTokenSVGAttrs=g.adjustTokenMathMLAttrs=g.causesExit=g.SVG_TAG_NAMES_ADJUSTMENT_MAP=void 0;const e=dl,I={TEXT_HTML:"text/html",APPLICATION_XML:"application/xhtml+xml"},i="definitionurl",n="definitionURL",C=new Map(["attributeName","attributeType","baseFrequency","baseProfile","calcMode","clipPathUnits","diffuseConstant","edgeMode","filterUnits","glyphRef","gradientTransform","gradientUnits","kernelMatrix","kernelUnitLength","keyPoints","keySplines","keyTimes","lengthAdjust","limitingConeAngle","markerHeight","markerUnits","markerWidth","maskContentUnits","maskUnits","numOctaves","pathLength","patternContentUnits","patternTransform","patternUnits","pointsAtX","pointsAtY","pointsAtZ","preserveAlpha","preserveAspectRatio","primitiveUnits","refX","refY","repeatCount","repeatDur","requiredExtensions","requiredFeatures","specularConstant","specularExponent","spreadMethod","startOffset","stdDeviation","stitchTiles","surfaceScale","systemLanguage","tableValues","targetX","targetY","textLength","viewBox","viewTarget","xChannelSelector","yChannelSelector","zoomAndPan"].map(m=>[m.toLowerCase(),m])),r=new Map([["xlink:actuate",{prefix:"xlink",name:"actuate",namespace:e.NS.XLINK}],["xlink:arcrole",{prefix:"xlink",name:"arcrole",namespace:e.NS.XLINK}],["xlink:href",{prefix:"xlink",name:"href",namespace:e.NS.XLINK}],["xlink:role",{prefix:"xlink",name:"role",namespace:e.NS.XLINK}],["xlink:show",{prefix:"xlink",name:"show",namespace:e.NS.XLINK}],["xlink:title",{prefix:"xlink",name:"title",namespace:e.NS.XLINK}],["xlink:type",{prefix:"xlink",name:"type",namespace:e.NS.XLINK}],["xml:base",{prefix:"xml",name:"base",namespace:e.NS.XML}],["xml:lang",{prefix:"xml",name:"lang",namespace:e.NS.XML}],["xml:space",{prefix:"xml",name:"space",namespace:e.NS.XML}],["xmlns",{prefix:"",name:"xmlns",namespace:e.NS.XMLNS}],["xmlns:xlink",{prefix:"xmlns",name:"xlink",namespace:e.NS.XMLNS}]]);g.SVG_TAG_NAMES_ADJUSTMENT_MAP=new Map(["altGlyph","altGlyphDef","altGlyphItem","animateColor","animateMotion","animateTransform","clipPath","feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feDistantLight","feFlood","feFuncA","feFuncB","feFuncG","feFuncR","feGaussianBlur","feImage","feMerge","feMergeNode","feMorphology","feOffset","fePointLight","feSpecularLighting","feSpotLight","feTile","feTurbulence","foreignObject","glyphRef","linearGradient","radialGradient","textPath"].map(m=>[m.toLowerCase(),m]));const o=new Set([e.TAG_ID.B,e.TAG_ID.BIG,e.TAG_ID.BLOCKQUOTE,e.TAG_ID.BODY,e.TAG_ID.BR,e.TAG_ID.CENTER,e.TAG_ID.CODE,e.TAG_ID.DD,e.TAG_ID.DIV,e.TAG_ID.DL,e.TAG_ID.DT,e.TAG_ID.EM,e.TAG_ID.EMBED,e.TAG_ID.H1,e.TAG_ID.H2,e.TAG_ID.H3,e.TAG_ID.H4,e.TAG_ID.H5,e.TAG_ID.H6,e.TAG_ID.HEAD,e.TAG_ID.HR,e.TAG_ID.I,e.TAG_ID.IMG,e.TAG_ID.LI,e.TAG_ID.LISTING,e.TAG_ID.MENU,e.TAG_ID.META,e.TAG_ID.NOBR,e.TAG_ID.OL,e.TAG_ID.P,e.TAG_ID.PRE,e.TAG_ID.RUBY,e.TAG_ID.S,e.TAG_ID.SMALL,e.TAG_ID.SPAN,e.TAG_ID.STRONG,e.TAG_ID.STRIKE,e.TAG_ID.SUB,e.TAG_ID.SUP,e.TAG_ID.TABLE,e.TAG_ID.TT,e.TAG_ID.U,e.TAG_ID.UL,e.TAG_ID.VAR]);function A(m){const f=m.tagID;return f===e.TAG_ID.FONT&&m.attrs.some(({name:p})=>p===e.ATTRS.COLOR||p===e.ATTRS.SIZE||p===e.ATTRS.FACE)||o.has(f)}g.causesExit=A;function s(m){for(let f=0;f0&&this._setContextModes(I,i)}},{key:"onItemPop",value:function(I,i){var n,C;if(this.options.sourceCodeLocationInfo&&this._setEndLocation(I,this.currentToken),(C=(n=this.treeAdapter).onItemPop)===null||C===void 0||C.call(n,I,this.openElements.current),i){let r,o;this.openElements.stackTop===0&&this.fragmentContext?(r=this.fragmentContext,o=this.fragmentContextID):{current:r,currentTagId:o}=this.openElements,this._setContextModes(r,o)}}},{key:"_setContextModes",value:function(I,i){const n=I===this.document||this.treeAdapter.getNamespaceURI(I)===M.NS.HTML;this.currentNotInHTML=!n,this.tokenizer.inForeignNode=!n&&!this._isIntegrationPoint(i,I)}},{key:"_switchToTextParsing",value:function(I,i){this._insertElement(I,M.NS.HTML),this.tokenizer.state=i,this.originalInsertionMode=this.insertionMode,this.insertionMode=Ve.TEXT}},{key:"switchToPlaintextParsing",value:function(){this.insertionMode=Ve.TEXT,this.originalInsertionMode=Ve.IN_BODY,this.tokenizer.state=_n.TokenizerMode.PLAINTEXT}},{key:"_getAdjustedCurrentElement",value:function(){return this.openElements.stackTop===0&&this.fragmentContext?this.fragmentContext:this.openElements.current}},{key:"_findFormInFragmentContext",value:function(){let I=this.fragmentContext;for(;I;){if(this.treeAdapter.getTagName(I)===M.TAG_NAMES.FORM){this.formElement=I;break}I=this.treeAdapter.getParentNode(I)}}},{key:"_initTokenizerForFragmentParsing",value:function(){if(!(!this.fragmentContext||this.treeAdapter.getNamespaceURI(this.fragmentContext)!==M.NS.HTML))switch(this.fragmentContextID){case M.TAG_ID.TITLE:case M.TAG_ID.TEXTAREA:{this.tokenizer.state=_n.TokenizerMode.RCDATA;break}case M.TAG_ID.STYLE:case M.TAG_ID.XMP:case M.TAG_ID.IFRAME:case M.TAG_ID.NOEMBED:case M.TAG_ID.NOFRAMES:case M.TAG_ID.NOSCRIPT:{this.tokenizer.state=_n.TokenizerMode.RAWTEXT;break}case M.TAG_ID.SCRIPT:{this.tokenizer.state=_n.TokenizerMode.SCRIPT_DATA;break}case M.TAG_ID.PLAINTEXT:{this.tokenizer.state=_n.TokenizerMode.PLAINTEXT;break}}}},{key:"_setDocumentType",value:function(I){const i=I.name||"",n=I.publicId||"",C=I.systemId||"";if(this.treeAdapter.setDocumentType(this.document,i,n,C),I.location){const o=this.treeAdapter.getChildNodes(this.document).find(A=>this.treeAdapter.isDocumentTypeNode(A));o&&this.treeAdapter.setNodeSourceCodeLocation(o,I.location)}}},{key:"_attachElementToTree",value:function(I,i){if(this.options.sourceCodeLocationInfo){const n=i&&Object.assign(Object.assign({},i),{startTag:i});this.treeAdapter.setNodeSourceCodeLocation(I,n)}if(this._shouldFosterParentOnInsertion())this._fosterParentElement(I);else{const n=this.openElements.currentTmplContentOrNode;this.treeAdapter.appendChild(n,I)}}},{key:"_appendElement",value:function(I,i){const n=this.treeAdapter.createElement(I.tagName,i,I.attrs);this._attachElementToTree(n,I.location)}},{key:"_insertElement",value:function(I,i){const n=this.treeAdapter.createElement(I.tagName,i,I.attrs);this._attachElementToTree(n,I.location),this.openElements.push(n,I.tagID)}},{key:"_insertFakeElement",value:function(I,i){const n=this.treeAdapter.createElement(I,M.NS.HTML,[]);this._attachElementToTree(n,null),this.openElements.push(n,i)}},{key:"_insertTemplate",value:function(I){const i=this.treeAdapter.createElement(I.tagName,M.NS.HTML,I.attrs),n=this.treeAdapter.createDocumentFragment();this.treeAdapter.setTemplateContent(i,n),this._attachElementToTree(i,I.location),this.openElements.push(i,I.tagID),this.options.sourceCodeLocationInfo&&this.treeAdapter.setNodeSourceCodeLocation(n,null)}},{key:"_insertFakeRootElement",value:function(){const I=this.treeAdapter.createElement(M.TAG_NAMES.HTML,M.NS.HTML,[]);this.options.sourceCodeLocationInfo&&this.treeAdapter.setNodeSourceCodeLocation(I,null),this.treeAdapter.appendChild(this.openElements.current,I),this.openElements.push(I,M.TAG_ID.HTML)}},{key:"_appendCommentNode",value:function(I,i){const n=this.treeAdapter.createCommentNode(I.data);this.treeAdapter.appendChild(i,n),this.options.sourceCodeLocationInfo&&this.treeAdapter.setNodeSourceCodeLocation(n,I.location)}},{key:"_insertCharacters",value:function(I){let i,n;if(this._shouldFosterParentOnInsertion()?({parent:i,beforeElement:n}=this._findFosterParentingLocation(),n?this.treeAdapter.insertTextBefore(i,I.chars,n):this.treeAdapter.insertText(i,I.chars)):(i=this.openElements.currentTmplContentOrNode,this.treeAdapter.insertText(i,I.chars)),!I.location)return;const C=this.treeAdapter.getChildNodes(i),r=n?C.lastIndexOf(n):C.length,o=C[r-1];if(this.treeAdapter.getNodeSourceCodeLocation(o)){const{endLine:s,endCol:a,endOffset:l}=I.location;this.treeAdapter.updateNodeSourceCodeLocation(o,{endLine:s,endCol:a,endOffset:l})}else this.options.sourceCodeLocationInfo&&this.treeAdapter.setNodeSourceCodeLocation(o,I.location)}},{key:"_adoptNodes",value:function(I,i){for(let n=this.treeAdapter.getFirstChild(I);n;n=this.treeAdapter.getFirstChild(I))this.treeAdapter.detachNode(n),this.treeAdapter.appendChild(i,n)}},{key:"_setEndLocation",value:function(I,i){if(this.treeAdapter.getNodeSourceCodeLocation(I)&&i.location){const n=i.location,C=this.treeAdapter.getTagName(I),r=i.type===Bi.TokenType.END_TAG&&C===i.tagName?{endTag:Object.assign({},n),endLine:n.endLine,endCol:n.endCol,endOffset:n.endOffset}:{endLine:n.startLine,endCol:n.startCol,endOffset:n.startOffset};this.treeAdapter.updateNodeSourceCodeLocation(I,r)}}},{key:"shouldProcessStartTagTokenInForeignContent",value:function(I){if(!this.currentNotInHTML)return!1;let i,n;return this.openElements.stackTop===0&&this.fragmentContext?(i=this.fragmentContext,n=this.fragmentContextID):{current:i,currentTagId:n}=this.openElements,I.tagID===M.TAG_ID.SVG&&this.treeAdapter.getTagName(i)===M.TAG_NAMES.ANNOTATION_XML&&this.treeAdapter.getNamespaceURI(i)===M.NS.MATHML?!1:this.tokenizer.inForeignNode||(I.tagID===M.TAG_ID.MGLYPH||I.tagID===M.TAG_ID.MALIGNMARK)&&!this._isIntegrationPoint(n,i,M.NS.HTML)}},{key:"_processToken",value:function(I){switch(I.type){case Bi.TokenType.CHARACTER:{this.onCharacter(I);break}case Bi.TokenType.NULL_CHARACTER:{this.onNullCharacter(I);break}case Bi.TokenType.COMMENT:{this.onComment(I);break}case Bi.TokenType.DOCTYPE:{this.onDoctype(I);break}case Bi.TokenType.START_TAG:{this._processStartTag(I);break}case Bi.TokenType.END_TAG:{this.onEndTag(I);break}case Bi.TokenType.EOF:{this.onEof(I);break}case Bi.TokenType.WHITESPACE_CHARACTER:{this.onWhitespaceCharacter(I);break}}}},{key:"_isIntegrationPoint",value:function(I,i,n){const C=this.treeAdapter.getNamespaceURI(i),r=this.treeAdapter.getAttrList(i);return UA.isIntegrationPoint(I,C,r,n)}},{key:"_reconstructActiveFormattingElements",value:function(){const I=this.activeFormattingElements.entries.length;if(I){const i=this.activeFormattingElements.entries.findIndex(C=>C.type===jne.EntryType.Marker||this.openElements.contains(C.element)),n=i<0?I-1:i-1;for(let C=n;C>=0;C--){const r=this.activeFormattingElements.entries[C];this._insertElement(r.token,this.treeAdapter.getNamespaceURI(r.element)),r.element=this.openElements.current}}}},{key:"_closeTableCell",value:function(){this.openElements.generateImpliedEndTags(),this.openElements.popUntilTableCellPopped(),this.activeFormattingElements.clearToLastMarker(),this.insertionMode=Ve.IN_ROW}},{key:"_closePElement",value:function(){this.openElements.generateImpliedEndTagsWithExclusion(M.TAG_ID.P),this.openElements.popUntilTagNamePopped(M.TAG_ID.P)}},{key:"_resetInsertionMode",value:function(){for(let I=this.openElements.stackTop;I>=0;I--)switch(I===0&&this.fragmentContext?this.fragmentContextID:this.openElements.tagIDs[I]){case M.TAG_ID.TR:{this.insertionMode=Ve.IN_ROW;return}case M.TAG_ID.TBODY:case M.TAG_ID.THEAD:case M.TAG_ID.TFOOT:{this.insertionMode=Ve.IN_TABLE_BODY;return}case M.TAG_ID.CAPTION:{this.insertionMode=Ve.IN_CAPTION;return}case M.TAG_ID.COLGROUP:{this.insertionMode=Ve.IN_COLUMN_GROUP;return}case M.TAG_ID.TABLE:{this.insertionMode=Ve.IN_TABLE;return}case M.TAG_ID.BODY:{this.insertionMode=Ve.IN_BODY;return}case M.TAG_ID.FRAMESET:{this.insertionMode=Ve.IN_FRAMESET;return}case M.TAG_ID.SELECT:{this._resetInsertionModeForSelect(I);return}case M.TAG_ID.TEMPLATE:{this.insertionMode=this.tmplInsertionModeStack[0];return}case M.TAG_ID.HTML:{this.insertionMode=this.headElement?Ve.AFTER_HEAD:Ve.BEFORE_HEAD;return}case M.TAG_ID.TD:case M.TAG_ID.TH:{if(I>0){this.insertionMode=Ve.IN_CELL;return}break}case M.TAG_ID.HEAD:{if(I>0){this.insertionMode=Ve.IN_HEAD;return}break}}this.insertionMode=Ve.IN_BODY}},{key:"_resetInsertionModeForSelect",value:function(I){if(I>0)for(let i=I-1;i>0;i--){const n=this.openElements.tagIDs[i];if(n===M.TAG_ID.TEMPLATE)break;if(n===M.TAG_ID.TABLE){this.insertionMode=Ve.IN_SELECT_IN_TABLE;return}}this.insertionMode=Ve.IN_SELECT}},{key:"_isElementCausesFosterParenting",value:function(I){return LSe.has(I)}},{key:"_shouldFosterParentOnInsertion",value:function(){return this.fosterParentingEnabled&&this._isElementCausesFosterParenting(this.openElements.currentTagId)}},{key:"_findFosterParentingLocation",value:function(){for(let I=this.openElements.stackTop;I>=0;I--){const i=this.openElements.items[I];switch(this.openElements.tagIDs[I]){case M.TAG_ID.TEMPLATE:{if(this.treeAdapter.getNamespaceURI(i)===M.NS.HTML)return{parent:this.treeAdapter.getTemplateContent(i),beforeElement:null};break}case M.TAG_ID.TABLE:{const n=this.treeAdapter.getParentNode(i);return n?{parent:n,beforeElement:i}:{parent:this.openElements.items[I-1],beforeElement:null}}}}return{parent:this.openElements.items[0],beforeElement:null}}},{key:"_fosterParentElement",value:function(I){const i=this._findFosterParentingLocation();i.beforeElement?this.treeAdapter.insertBefore(i.parent,I,i.beforeElement):this.treeAdapter.appendChild(i.parent,I)}},{key:"_isSpecialElement",value:function(I,i){const n=this.treeAdapter.getNamespaceURI(I);return M.SPECIAL_ELEMENTS[n].has(i)}},{key:"onCharacter",value:function(I){if(this.skipNextNewLine=!1,this.tokenizer.inForeignNode){Fbt(this,I);return}switch(this.insertionMode){case Ve.INITIAL:{aZ(this,I);break}case Ve.BEFORE_HTML:{AB(this,I);break}case Ve.BEFORE_HEAD:{aB(this,I);break}case Ve.IN_HEAD:{sB(this,I);break}case Ve.IN_HEAD_NO_SCRIPT:{lB(this,I);break}case Ve.AFTER_HEAD:{cB(this,I);break}case Ve.IN_BODY:case Ve.IN_CAPTION:case Ve.IN_CELL:case Ve.IN_TEMPLATE:{USe(this,I);break}case Ve.TEXT:case Ve.IN_SELECT:case Ve.IN_SELECT_IN_TABLE:{this._insertCharacters(I);break}case Ve.IN_TABLE:case Ve.IN_TABLE_BODY:case Ve.IN_ROW:{RD(this,I);break}case Ve.IN_TABLE_TEXT:{twe(this,I);break}case Ve.IN_COLUMN_GROUP:{rH(this,I);break}case Ve.AFTER_BODY:{oH(this,I);break}case Ve.AFTER_AFTER_BODY:{lW(this,I);break}}}},{key:"onNullCharacter",value:function(I){if(this.skipNextNewLine=!1,this.tokenizer.inForeignNode){Dbt(this,I);return}switch(this.insertionMode){case Ve.INITIAL:{aZ(this,I);break}case Ve.BEFORE_HTML:{AB(this,I);break}case Ve.BEFORE_HEAD:{aB(this,I);break}case Ve.IN_HEAD:{sB(this,I);break}case Ve.IN_HEAD_NO_SCRIPT:{lB(this,I);break}case Ve.AFTER_HEAD:{cB(this,I);break}case Ve.TEXT:{this._insertCharacters(I);break}case Ve.IN_TABLE:case Ve.IN_TABLE_BODY:case Ve.IN_ROW:{RD(this,I);break}case Ve.IN_COLUMN_GROUP:{rH(this,I);break}case Ve.AFTER_BODY:{oH(this,I);break}case Ve.AFTER_AFTER_BODY:{lW(this,I);break}}}},{key:"onComment",value:function(I){if(this.skipNextNewLine=!1,this.currentNotInHTML){Tz(this,I);return}switch(this.insertionMode){case Ve.INITIAL:case Ve.BEFORE_HTML:case Ve.BEFORE_HEAD:case Ve.IN_HEAD:case Ve.IN_HEAD_NO_SCRIPT:case Ve.AFTER_HEAD:case Ve.IN_BODY:case Ve.IN_TABLE:case Ve.IN_CAPTION:case Ve.IN_COLUMN_GROUP:case Ve.IN_TABLE_BODY:case Ve.IN_ROW:case Ve.IN_CELL:case Ve.IN_SELECT:case Ve.IN_SELECT_IN_TABLE:case Ve.IN_TEMPLATE:case Ve.IN_FRAMESET:case Ve.AFTER_FRAMESET:{Tz(this,I);break}case Ve.IN_TABLE_TEXT:{sZ(this,I);break}case Ve.AFTER_BODY:{mpt(this,I);break}case Ve.AFTER_AFTER_BODY:case Ve.AFTER_AFTER_FRAMESET:{fpt(this,I);break}}}},{key:"onDoctype",value:function(I){switch(this.skipNextNewLine=!1,this.insertionMode){case Ve.INITIAL:{ppt(this,I);break}case Ve.BEFORE_HEAD:case Ve.IN_HEAD:case Ve.IN_HEAD_NO_SCRIPT:case Ve.AFTER_HEAD:{this._err(I,cn.ERR.misplacedDoctype);break}case Ve.IN_TABLE_TEXT:{sZ(this,I);break}}}},{key:"onStartTag",value:function(I){this.skipNextNewLine=!1,this.currentToken=I,this._processStartTag(I),I.selfClosing&&!I.ackSelfClosing&&this._err(I,cn.ERR.nonVoidHtmlElementStartTagWithTrailingSolidus)}},{key:"_processStartTag",value:function(I){this.shouldProcessStartTagTokenInForeignContent(I)?Ebt(this,I):this._startTagOutsideForeignContent(I)}},{key:"_startTagOutsideForeignContent",value:function(I){switch(this.insertionMode){case Ve.INITIAL:{aZ(this,I);break}case Ve.BEFORE_HTML:{bpt(this,I);break}case Ve.BEFORE_HEAD:{Zpt(this,I);break}case Ve.IN_HEAD:{yA(this,I);break}case Ve.IN_HEAD_NO_SCRIPT:{vpt(this,I);break}case Ve.AFTER_HEAD:{wpt(this,I);break}case Ve.IN_BODY:{Dn(this,I);break}case Ve.IN_TABLE:{I0(this,I);break}case Ve.IN_TABLE_TEXT:{sZ(this,I);break}case Ve.IN_CAPTION:{Gbt(this,I);break}case Ve.IN_COLUMN_GROUP:{hj(this,I);break}case Ve.IN_TABLE_BODY:{wk(this,I);break}case Ve.IN_ROW:{Vk(this,I);break}case Ve.IN_CELL:{Sbt(this,I);break}case Ve.IN_SELECT:{iwe(this,I);break}case Ve.IN_SELECT_IN_TABLE:{Vbt(this,I);break}case Ve.IN_TEMPLATE:{Wbt(this,I);break}case Ve.AFTER_BODY:{Hbt(this,I);break}case Ve.IN_FRAMESET:{Tbt(this,I);break}case Ve.AFTER_FRAMESET:{kbt(this,I);break}case Ve.AFTER_AFTER_BODY:{Kbt(this,I);break}case Ve.AFTER_AFTER_FRAMESET:{xbt(this,I);break}}}},{key:"onEndTag",value:function(I){this.skipNextNewLine=!1,this.currentToken=I,this.currentNotInHTML?Mbt(this,I):this._endTagOutsideForeignContent(I)}},{key:"_endTagOutsideForeignContent",value:function(I){switch(this.insertionMode){case Ve.INITIAL:{aZ(this,I);break}case Ve.BEFORE_HTML:{ypt(this,I);break}case Ve.BEFORE_HEAD:{Gpt(this,I);break}case Ve.IN_HEAD:{Bpt(this,I);break}case Ve.IN_HEAD_NO_SCRIPT:{Spt(this,I);break}case Ve.AFTER_HEAD:{Vpt(this,I);break}case Ve.IN_BODY:{Sk(this,I);break}case Ve.TEXT:{cbt(this,I);break}case Ve.IN_TABLE:{_v(this,I);break}case Ve.IN_TABLE_TEXT:{sZ(this,I);break}case Ve.IN_CAPTION:{Bbt(this,I);break}case Ve.IN_COLUMN_GROUP:{vbt(this,I);break}case Ve.IN_TABLE_BODY:{Nz(this,I);break}case Ve.IN_ROW:{Iwe(this,I);break}case Ve.IN_CELL:{wbt(this,I);break}case Ve.IN_SELECT:{nwe(this,I);break}case Ve.IN_SELECT_IN_TABLE:{Rbt(this,I);break}case Ve.IN_TEMPLATE:{Xbt(this,I);break}case Ve.AFTER_BODY:{rwe(this,I);break}case Ve.IN_FRAMESET:{Nbt(this,I);break}case Ve.AFTER_FRAMESET:{Ybt(this,I);break}case Ve.AFTER_AFTER_BODY:{lW(this,I);break}}}},{key:"onEof",value:function(I){switch(this.insertionMode){case Ve.INITIAL:{aZ(this,I);break}case Ve.BEFORE_HTML:{AB(this,I);break}case Ve.BEFORE_HEAD:{aB(this,I);break}case Ve.IN_HEAD:{sB(this,I);break}case Ve.IN_HEAD_NO_SCRIPT:{lB(this,I);break}case Ve.AFTER_HEAD:{cB(this,I);break}case Ve.IN_BODY:case Ve.IN_TABLE:case Ve.IN_CAPTION:case Ve.IN_COLUMN_GROUP:case Ve.IN_TABLE_BODY:case Ve.IN_ROW:case Ve.IN_CELL:case Ve.IN_SELECT:case Ve.IN_SELECT_IN_TABLE:{qSe(this,I);break}case Ve.TEXT:{ubt(this,I);break}case Ve.IN_TABLE_TEXT:{sZ(this,I);break}case Ve.IN_TEMPLATE:{Cwe(this,I);break}case Ve.AFTER_BODY:case Ve.IN_FRAMESET:case Ve.AFTER_FRAMESET:case Ve.AFTER_AFTER_BODY:case Ve.AFTER_AFTER_FRAMESET:{dj(this,I);break}}}},{key:"onWhitespaceCharacter",value:function(I){if(this.skipNextNewLine&&(this.skipNextNewLine=!1,I.chars.charCodeAt(0)===OSe.CODE_POINTS.LINE_FEED)){if(I.chars.length===1)return;I.chars=I.chars.substr(1)}if(this.tokenizer.inForeignNode){this._insertCharacters(I);return}switch(this.insertionMode){case Ve.IN_HEAD:case Ve.IN_HEAD_NO_SCRIPT:case Ve.AFTER_HEAD:case Ve.TEXT:case Ve.IN_COLUMN_GROUP:case Ve.IN_SELECT:case Ve.IN_SELECT_IN_TABLE:case Ve.IN_FRAMESET:case Ve.AFTER_FRAMESET:{this._insertCharacters(I);break}case Ve.IN_BODY:case Ve.IN_CAPTION:case Ve.IN_CELL:case Ve.IN_TEMPLATE:case Ve.AFTER_BODY:case Ve.AFTER_AFTER_BODY:case Ve.AFTER_AFTER_FRAMESET:{_Se(this,I);break}case Ve.IN_TABLE:case Ve.IN_TABLE_BODY:case Ve.IN_ROW:{RD(this,I);break}case Ve.IN_TABLE_TEXT:{ewe(this,I);break}}}}],[{key:"parse",value:function(I,i){const n=new this(i);return n.tokenizer.write(I,!0),n.document}},{key:"getFragmentParser",value:function(I,i){const n=Object.assign(Object.assign({},qne),i);I??(I=n.treeAdapter.createElement(M.TAG_NAMES.TEMPLATE,M.NS.HTML,[]));const C=n.treeAdapter.createElement("documentmock",M.NS.HTML,[]),r=new this(n,C,I);return r.fragmentContextID===M.TAG_ID.TEMPLATE&&r.tmplInsertionModeStack.unshift(Ve.IN_TEMPLATE),r._initTokenizerForFragmentParsing(),r._insertFakeRootElement(),r._resetInsertionMode(),r._findFormInFragmentContext(),r}}]),g}();Lv.Parser=apt;function spt(g,e){let I=g.activeFormattingElements.getElementEntryInScopeWithTagName(e.tagName);return I?g.openElements.contains(I.element)?g.openElements.hasInScope(e.tagID)||(I=null):(g.activeFormattingElements.removeEntry(I),I=null):$Se(g,e),I}function lpt(g,e){let I=null,i=g.openElements.stackTop;for(;i>=0;i--){const n=g.openElements.items[i];if(n===e.element)break;g._isSpecialElement(n,g.openElements.tagIDs[i])&&(I=n)}return I||(g.openElements.shortenToLength(i<0?0:i),g.activeFormattingElements.removeEntry(e)),I}function cpt(g,e,I){let i=e,n=g.openElements.getCommonAncestor(e);for(let C=0,r=n;r!==I;C++,r=n){n=g.openElements.getCommonAncestor(r);const o=g.activeFormattingElements.getElementEntry(r),A=o&&C>=opt;!o||A?(A&&g.activeFormattingElements.removeEntry(o),g.openElements.remove(r)):(r=upt(g,o),i===e&&(g.activeFormattingElements.bookmark=o),g.treeAdapter.detachNode(i),g.treeAdapter.appendChild(r,i),i=r)}return i}function upt(g,e){const I=g.treeAdapter.getNamespaceURI(e.element),i=g.treeAdapter.createElement(e.token.tagName,I,e.token.attrs);return g.openElements.replace(e.element,i),e.element=i,i}function dpt(g,e,I){const i=g.treeAdapter.getTagName(e),n=(0,M.getTagID)(i);if(g._isElementCausesFosterParenting(n))g._fosterParentElement(I);else{const C=g.treeAdapter.getNamespaceURI(e);n===M.TAG_ID.TEMPLATE&&C===M.NS.HTML&&(e=g.treeAdapter.getTemplateContent(e)),g.treeAdapter.appendChild(e,I)}}function hpt(g,e,I){const i=g.treeAdapter.getNamespaceURI(I.element),{token:n}=I,C=g.treeAdapter.createElement(n.tagName,i,n.attrs);g._adoptNodes(e,C),g.treeAdapter.appendChild(e,C),g.activeFormattingElements.insertElementAfterBookmark(C,n),g.activeFormattingElements.removeEntry(I),g.openElements.remove(I.element),g.openElements.insertAfter(e,C,n.tagID)}function uj(g,e){for(let I=0;I=I;i--)g._setEndLocation(g.openElements.items[i],e);if(!g.fragmentContext&&g.openElements.stackTop>=0){const i=g.openElements.items[0],n=g.treeAdapter.getNodeSourceCodeLocation(i);if(n&&!n.endTag&&(g._setEndLocation(i,e),g.openElements.stackTop>=1)){const C=g.openElements.items[1],r=g.treeAdapter.getNodeSourceCodeLocation(C);r&&!r.endTag&&g._setEndLocation(C,e)}}}}function ppt(g,e){g._setDocumentType(e);const I=e.forceQuirks?M.DOCUMENT_MODE.QUIRKS:$ne.getDocumentMode(e);$ne.isConforming(e)||g._err(e,cn.ERR.nonConformingDoctype),g.treeAdapter.setDocumentMode(g.document,I),g.insertionMode=Ve.BEFORE_HTML}function aZ(g,e){g._err(e,cn.ERR.missingDoctype,!0),g.treeAdapter.setDocumentMode(g.document,M.DOCUMENT_MODE.QUIRKS),g.insertionMode=Ve.BEFORE_HTML,g._processToken(e)}function bpt(g,e){e.tagID===M.TAG_ID.HTML?(g._insertElement(e,M.NS.HTML),g.insertionMode=Ve.BEFORE_HEAD):AB(g,e)}function ypt(g,e){const I=e.tagID;(I===M.TAG_ID.HTML||I===M.TAG_ID.HEAD||I===M.TAG_ID.BODY||I===M.TAG_ID.BR)&&AB(g,e)}function AB(g,e){g._insertFakeRootElement(),g.insertionMode=Ve.BEFORE_HEAD,g._processToken(e)}function Zpt(g,e){switch(e.tagID){case M.TAG_ID.HTML:{Dn(g,e);break}case M.TAG_ID.HEAD:{g._insertElement(e,M.NS.HTML),g.headElement=g.openElements.current,g.insertionMode=Ve.IN_HEAD;break}default:aB(g,e)}}function Gpt(g,e){const I=e.tagID;I===M.TAG_ID.HEAD||I===M.TAG_ID.BODY||I===M.TAG_ID.HTML||I===M.TAG_ID.BR?aB(g,e):g._err(e,cn.ERR.endTagWithoutMatchingOpenElement)}function aB(g,e){g._insertFakeElement(M.TAG_NAMES.HEAD,M.TAG_ID.HEAD),g.headElement=g.openElements.current,g.insertionMode=Ve.IN_HEAD,g._processToken(e)}function yA(g,e){switch(e.tagID){case M.TAG_ID.HTML:{Dn(g,e);break}case M.TAG_ID.BASE:case M.TAG_ID.BASEFONT:case M.TAG_ID.BGSOUND:case M.TAG_ID.LINK:case M.TAG_ID.META:{g._appendElement(e,M.NS.HTML),e.ackSelfClosing=!0;break}case M.TAG_ID.TITLE:{g._switchToTextParsing(e,_n.TokenizerMode.RCDATA);break}case M.TAG_ID.NOSCRIPT:{g.options.scriptingEnabled?g._switchToTextParsing(e,_n.TokenizerMode.RAWTEXT):(g._insertElement(e,M.NS.HTML),g.insertionMode=Ve.IN_HEAD_NO_SCRIPT);break}case M.TAG_ID.NOFRAMES:case M.TAG_ID.STYLE:{g._switchToTextParsing(e,_n.TokenizerMode.RAWTEXT);break}case M.TAG_ID.SCRIPT:{g._switchToTextParsing(e,_n.TokenizerMode.SCRIPT_DATA);break}case M.TAG_ID.TEMPLATE:{g._insertTemplate(e),g.activeFormattingElements.insertMarker(),g.framesetOk=!1,g.insertionMode=Ve.IN_TEMPLATE,g.tmplInsertionModeStack.unshift(Ve.IN_TEMPLATE);break}case M.TAG_ID.HEAD:{g._err(e,cn.ERR.misplacedStartTagForHeadElement);break}default:sB(g,e)}}function Bpt(g,e){switch(e.tagID){case M.TAG_ID.HEAD:{g.openElements.pop(),g.insertionMode=Ve.AFTER_HEAD;break}case M.TAG_ID.BODY:case M.TAG_ID.BR:case M.TAG_ID.HTML:{sB(g,e);break}case M.TAG_ID.TEMPLATE:{mm(g,e);break}default:g._err(e,cn.ERR.endTagWithoutMatchingOpenElement)}}function mm(g,e){g.openElements.tmplCount>0?(g.openElements.generateImpliedEndTagsThoroughly(),g.openElements.currentTagId!==M.TAG_ID.TEMPLATE&&g._err(e,cn.ERR.closingOfElementWithOpenChildElements),g.openElements.popUntilTagNamePopped(M.TAG_ID.TEMPLATE),g.activeFormattingElements.clearToLastMarker(),g.tmplInsertionModeStack.shift(),g._resetInsertionMode()):g._err(e,cn.ERR.endTagWithoutMatchingOpenElement)}function sB(g,e){g.openElements.pop(),g.insertionMode=Ve.AFTER_HEAD,g._processToken(e)}function vpt(g,e){switch(e.tagID){case M.TAG_ID.HTML:{Dn(g,e);break}case M.TAG_ID.BASEFONT:case M.TAG_ID.BGSOUND:case M.TAG_ID.HEAD:case M.TAG_ID.LINK:case M.TAG_ID.META:case M.TAG_ID.NOFRAMES:case M.TAG_ID.STYLE:{yA(g,e);break}case M.TAG_ID.NOSCRIPT:{g._err(e,cn.ERR.nestedNoscriptInHead);break}default:lB(g,e)}}function Spt(g,e){switch(e.tagID){case M.TAG_ID.NOSCRIPT:{g.openElements.pop(),g.insertionMode=Ve.IN_HEAD;break}case M.TAG_ID.BR:{lB(g,e);break}default:g._err(e,cn.ERR.endTagWithoutMatchingOpenElement)}}function lB(g,e){const I=e.type===Bi.TokenType.EOF?cn.ERR.openElementsLeftAfterEof:cn.ERR.disallowedContentInNoscriptInHead;g._err(e,I),g.openElements.pop(),g.insertionMode=Ve.IN_HEAD,g._processToken(e)}function wpt(g,e){switch(e.tagID){case M.TAG_ID.HTML:{Dn(g,e);break}case M.TAG_ID.BODY:{g._insertElement(e,M.NS.HTML),g.framesetOk=!1,g.insertionMode=Ve.IN_BODY;break}case M.TAG_ID.FRAMESET:{g._insertElement(e,M.NS.HTML),g.insertionMode=Ve.IN_FRAMESET;break}case M.TAG_ID.BASE:case M.TAG_ID.BASEFONT:case M.TAG_ID.BGSOUND:case M.TAG_ID.LINK:case M.TAG_ID.META:case M.TAG_ID.NOFRAMES:case M.TAG_ID.SCRIPT:case M.TAG_ID.STYLE:case M.TAG_ID.TEMPLATE:case M.TAG_ID.TITLE:{g._err(e,cn.ERR.abandonedHeadElementChild),g.openElements.push(g.headElement,M.TAG_ID.HEAD),yA(g,e),g.openElements.remove(g.headElement);break}case M.TAG_ID.HEAD:{g._err(e,cn.ERR.misplacedStartTagForHeadElement);break}default:cB(g,e)}}function Vpt(g,e){switch(e.tagID){case M.TAG_ID.BODY:case M.TAG_ID.HTML:case M.TAG_ID.BR:{cB(g,e);break}case M.TAG_ID.TEMPLATE:{mm(g,e);break}default:g._err(e,cn.ERR.endTagWithoutMatchingOpenElement)}}function cB(g,e){g._insertFakeElement(M.TAG_NAMES.BODY,M.TAG_ID.BODY),g.insertionMode=Ve.IN_BODY,vk(g,e)}function vk(g,e){switch(e.type){case Bi.TokenType.CHARACTER:{USe(g,e);break}case Bi.TokenType.WHITESPACE_CHARACTER:{_Se(g,e);break}case Bi.TokenType.COMMENT:{Tz(g,e);break}case Bi.TokenType.START_TAG:{Dn(g,e);break}case Bi.TokenType.END_TAG:{Sk(g,e);break}case Bi.TokenType.EOF:{qSe(g,e);break}}}function _Se(g,e){g._reconstructActiveFormattingElements(),g._insertCharacters(e)}function USe(g,e){g._reconstructActiveFormattingElements(),g._insertCharacters(e),g.framesetOk=!1}function Rpt(g,e){g.openElements.tmplCount===0&&g.treeAdapter.adoptAttributes(g.openElements.items[0],e.attrs)}function Wpt(g,e){const I=g.openElements.tryPeekProperlyNestedBodyElement();I&&g.openElements.tmplCount===0&&(g.framesetOk=!1,g.treeAdapter.adoptAttributes(I,e.attrs))}function Xpt(g,e){const I=g.openElements.tryPeekProperlyNestedBodyElement();g.framesetOk&&I&&(g.treeAdapter.detachNode(I),g.openElements.popAllUpToHtmlElement(),g._insertElement(e,M.NS.HTML),g.insertionMode=Ve.IN_FRAMESET)}function Hpt(g,e){g.openElements.hasInButtonScope(M.TAG_ID.P)&&g._closePElement(),g._insertElement(e,M.NS.HTML)}function Tpt(g,e){g.openElements.hasInButtonScope(M.TAG_ID.P)&&g._closePElement(),(0,M.isNumberedHeader)(g.openElements.currentTagId)&&g.openElements.pop(),g._insertElement(e,M.NS.HTML)}function Npt(g,e){g.openElements.hasInButtonScope(M.TAG_ID.P)&&g._closePElement(),g._insertElement(e,M.NS.HTML),g.skipNextNewLine=!0,g.framesetOk=!1}function kpt(g,e){const I=g.openElements.tmplCount>0;(!g.formElement||I)&&(g.openElements.hasInButtonScope(M.TAG_ID.P)&&g._closePElement(),g._insertElement(e,M.NS.HTML),I||(g.formElement=g.openElements.current))}function Ypt(g,e){g.framesetOk=!1;const I=e.tagID;for(let i=g.openElements.stackTop;i>=0;i--){const n=g.openElements.tagIDs[i];if(I===M.TAG_ID.LI&&n===M.TAG_ID.LI||(I===M.TAG_ID.DD||I===M.TAG_ID.DT)&&(n===M.TAG_ID.DD||n===M.TAG_ID.DT)){g.openElements.generateImpliedEndTagsWithExclusion(n),g.openElements.popUntilTagNamePopped(n);break}if(n!==M.TAG_ID.ADDRESS&&n!==M.TAG_ID.DIV&&n!==M.TAG_ID.P&&g._isSpecialElement(g.openElements.items[i],n))break}g.openElements.hasInButtonScope(M.TAG_ID.P)&&g._closePElement(),g._insertElement(e,M.NS.HTML)}function Kpt(g,e){g.openElements.hasInButtonScope(M.TAG_ID.P)&&g._closePElement(),g._insertElement(e,M.NS.HTML),g.tokenizer.state=_n.TokenizerMode.PLAINTEXT}function xpt(g,e){g.openElements.hasInScope(M.TAG_ID.BUTTON)&&(g.openElements.generateImpliedEndTags(),g.openElements.popUntilTagNamePopped(M.TAG_ID.BUTTON)),g._reconstructActiveFormattingElements(),g._insertElement(e,M.NS.HTML),g.framesetOk=!1}function Dpt(g,e){const I=g.activeFormattingElements.getElementEntryInScopeWithTagName(M.TAG_NAMES.A);I&&(uj(g,e),g.openElements.remove(I.element),g.activeFormattingElements.removeEntry(I)),g._reconstructActiveFormattingElements(),g._insertElement(e,M.NS.HTML),g.activeFormattingElements.pushElement(g.openElements.current,e)}function Fpt(g,e){g._reconstructActiveFormattingElements(),g._insertElement(e,M.NS.HTML),g.activeFormattingElements.pushElement(g.openElements.current,e)}function Ept(g,e){g._reconstructActiveFormattingElements(),g.openElements.hasInScope(M.TAG_ID.NOBR)&&(uj(g,e),g._reconstructActiveFormattingElements()),g._insertElement(e,M.NS.HTML),g.activeFormattingElements.pushElement(g.openElements.current,e)}function Mpt(g,e){g._reconstructActiveFormattingElements(),g._insertElement(e,M.NS.HTML),g.activeFormattingElements.insertMarker(),g.framesetOk=!1}function zpt(g,e){g.treeAdapter.getDocumentMode(g.document)!==M.DOCUMENT_MODE.QUIRKS&&g.openElements.hasInButtonScope(M.TAG_ID.P)&&g._closePElement(),g._insertElement(e,M.NS.HTML),g.framesetOk=!1,g.insertionMode=Ve.IN_TABLE}function QSe(g,e){g._reconstructActiveFormattingElements(),g._appendElement(e,M.NS.HTML),g.framesetOk=!1,e.ackSelfClosing=!0}function jSe(g){const e=(0,Bi.getTokenAttr)(g,M.ATTRS.TYPE);return e!=null&&e.toLowerCase()===Cpt}function Ppt(g,e){g._reconstructActiveFormattingElements(),g._appendElement(e,M.NS.HTML),jSe(e)||(g.framesetOk=!1),e.ackSelfClosing=!0}function Jpt(g,e){g._appendElement(e,M.NS.HTML),e.ackSelfClosing=!0}function Opt(g,e){g.openElements.hasInButtonScope(M.TAG_ID.P)&&g._closePElement(),g._appendElement(e,M.NS.HTML),g.framesetOk=!1,e.ackSelfClosing=!0}function Lpt(g,e){e.tagName=M.TAG_NAMES.IMG,e.tagID=M.TAG_ID.IMG,QSe(g,e)}function _pt(g,e){g._insertElement(e,M.NS.HTML),g.skipNextNewLine=!0,g.tokenizer.state=_n.TokenizerMode.RCDATA,g.originalInsertionMode=g.insertionMode,g.framesetOk=!1,g.insertionMode=Ve.TEXT}function Upt(g,e){g.openElements.hasInButtonScope(M.TAG_ID.P)&&g._closePElement(),g._reconstructActiveFormattingElements(),g.framesetOk=!1,g._switchToTextParsing(e,_n.TokenizerMode.RAWTEXT)}function Qpt(g,e){g.framesetOk=!1,g._switchToTextParsing(e,_n.TokenizerMode.RAWTEXT)}function eCe(g,e){g._switchToTextParsing(e,_n.TokenizerMode.RAWTEXT)}function jpt(g,e){g._reconstructActiveFormattingElements(),g._insertElement(e,M.NS.HTML),g.framesetOk=!1,g.insertionMode=g.insertionMode===Ve.IN_TABLE||g.insertionMode===Ve.IN_CAPTION||g.insertionMode===Ve.IN_TABLE_BODY||g.insertionMode===Ve.IN_ROW||g.insertionMode===Ve.IN_CELL?Ve.IN_SELECT_IN_TABLE:Ve.IN_SELECT}function $pt(g,e){g.openElements.currentTagId===M.TAG_ID.OPTION&&g.openElements.pop(),g._reconstructActiveFormattingElements(),g._insertElement(e,M.NS.HTML)}function qpt(g,e){g.openElements.hasInScope(M.TAG_ID.RUBY)&&g.openElements.generateImpliedEndTags(),g._insertElement(e,M.NS.HTML)}function ebt(g,e){g.openElements.hasInScope(M.TAG_ID.RUBY)&&g.openElements.generateImpliedEndTagsWithExclusion(M.TAG_ID.RTC),g._insertElement(e,M.NS.HTML)}function tbt(g,e){g._reconstructActiveFormattingElements(),UA.adjustTokenMathMLAttrs(e),UA.adjustTokenXMLAttrs(e),e.selfClosing?g._appendElement(e,M.NS.MATHML):g._insertElement(e,M.NS.MATHML),e.ackSelfClosing=!0}function gbt(g,e){g._reconstructActiveFormattingElements(),UA.adjustTokenSVGAttrs(e),UA.adjustTokenXMLAttrs(e),e.selfClosing?g._appendElement(e,M.NS.SVG):g._insertElement(e,M.NS.SVG),e.ackSelfClosing=!0}function tCe(g,e){g._reconstructActiveFormattingElements(),g._insertElement(e,M.NS.HTML)}function Dn(g,e){switch(e.tagID){case M.TAG_ID.I:case M.TAG_ID.S:case M.TAG_ID.B:case M.TAG_ID.U:case M.TAG_ID.EM:case M.TAG_ID.TT:case M.TAG_ID.BIG:case M.TAG_ID.CODE:case M.TAG_ID.FONT:case M.TAG_ID.SMALL:case M.TAG_ID.STRIKE:case M.TAG_ID.STRONG:{Fpt(g,e);break}case M.TAG_ID.A:{Dpt(g,e);break}case M.TAG_ID.H1:case M.TAG_ID.H2:case M.TAG_ID.H3:case M.TAG_ID.H4:case M.TAG_ID.H5:case M.TAG_ID.H6:{Tpt(g,e);break}case M.TAG_ID.P:case M.TAG_ID.DL:case M.TAG_ID.OL:case M.TAG_ID.UL:case M.TAG_ID.DIV:case M.TAG_ID.DIR:case M.TAG_ID.NAV:case M.TAG_ID.MAIN:case M.TAG_ID.MENU:case M.TAG_ID.ASIDE:case M.TAG_ID.CENTER:case M.TAG_ID.FIGURE:case M.TAG_ID.FOOTER:case M.TAG_ID.HEADER:case M.TAG_ID.HGROUP:case M.TAG_ID.DIALOG:case M.TAG_ID.DETAILS:case M.TAG_ID.ADDRESS:case M.TAG_ID.ARTICLE:case M.TAG_ID.SECTION:case M.TAG_ID.SUMMARY:case M.TAG_ID.FIELDSET:case M.TAG_ID.BLOCKQUOTE:case M.TAG_ID.FIGCAPTION:{Hpt(g,e);break}case M.TAG_ID.LI:case M.TAG_ID.DD:case M.TAG_ID.DT:{Ypt(g,e);break}case M.TAG_ID.BR:case M.TAG_ID.IMG:case M.TAG_ID.WBR:case M.TAG_ID.AREA:case M.TAG_ID.EMBED:case M.TAG_ID.KEYGEN:{QSe(g,e);break}case M.TAG_ID.HR:{Opt(g,e);break}case M.TAG_ID.RB:case M.TAG_ID.RTC:{qpt(g,e);break}case M.TAG_ID.RT:case M.TAG_ID.RP:{ebt(g,e);break}case M.TAG_ID.PRE:case M.TAG_ID.LISTING:{Npt(g,e);break}case M.TAG_ID.XMP:{Upt(g,e);break}case M.TAG_ID.SVG:{gbt(g,e);break}case M.TAG_ID.HTML:{Rpt(g,e);break}case M.TAG_ID.BASE:case M.TAG_ID.LINK:case M.TAG_ID.META:case M.TAG_ID.STYLE:case M.TAG_ID.TITLE:case M.TAG_ID.SCRIPT:case M.TAG_ID.BGSOUND:case M.TAG_ID.BASEFONT:case M.TAG_ID.TEMPLATE:{yA(g,e);break}case M.TAG_ID.BODY:{Wpt(g,e);break}case M.TAG_ID.FORM:{kpt(g,e);break}case M.TAG_ID.NOBR:{Ept(g,e);break}case M.TAG_ID.MATH:{tbt(g,e);break}case M.TAG_ID.TABLE:{zpt(g,e);break}case M.TAG_ID.INPUT:{Ppt(g,e);break}case M.TAG_ID.PARAM:case M.TAG_ID.TRACK:case M.TAG_ID.SOURCE:{Jpt(g,e);break}case M.TAG_ID.IMAGE:{Lpt(g,e);break}case M.TAG_ID.BUTTON:{xpt(g,e);break}case M.TAG_ID.APPLET:case M.TAG_ID.OBJECT:case M.TAG_ID.MARQUEE:{Mpt(g,e);break}case M.TAG_ID.IFRAME:{Qpt(g,e);break}case M.TAG_ID.SELECT:{jpt(g,e);break}case M.TAG_ID.OPTION:case M.TAG_ID.OPTGROUP:{$pt(g,e);break}case M.TAG_ID.NOEMBED:{eCe(g,e);break}case M.TAG_ID.FRAMESET:{Xpt(g,e);break}case M.TAG_ID.TEXTAREA:{_pt(g,e);break}case M.TAG_ID.NOSCRIPT:{g.options.scriptingEnabled?eCe(g,e):tCe(g,e);break}case M.TAG_ID.PLAINTEXT:{Kpt(g,e);break}case M.TAG_ID.COL:case M.TAG_ID.TH:case M.TAG_ID.TD:case M.TAG_ID.TR:case M.TAG_ID.HEAD:case M.TAG_ID.FRAME:case M.TAG_ID.TBODY:case M.TAG_ID.TFOOT:case M.TAG_ID.THEAD:case M.TAG_ID.CAPTION:case M.TAG_ID.COLGROUP:break;default:tCe(g,e)}}function Ibt(g,e){if(g.openElements.hasInScope(M.TAG_ID.BODY)&&(g.insertionMode=Ve.AFTER_BODY,g.options.sourceCodeLocationInfo)){const I=g.openElements.tryPeekProperlyNestedBodyElement();I&&g._setEndLocation(I,e)}}function ibt(g,e){g.openElements.hasInScope(M.TAG_ID.BODY)&&(g.insertionMode=Ve.AFTER_BODY,rwe(g,e))}function nbt(g,e){const I=e.tagID;g.openElements.hasInScope(I)&&(g.openElements.generateImpliedEndTags(),g.openElements.popUntilTagNamePopped(I))}function Cbt(g){const e=g.openElements.tmplCount>0,{formElement:I}=g;e||(g.formElement=null),(I||e)&&g.openElements.hasInScope(M.TAG_ID.FORM)&&(g.openElements.generateImpliedEndTags(),e?g.openElements.popUntilTagNamePopped(M.TAG_ID.FORM):I&&g.openElements.remove(I))}function rbt(g){g.openElements.hasInButtonScope(M.TAG_ID.P)||g._insertFakeElement(M.TAG_NAMES.P,M.TAG_ID.P),g._closePElement()}function obt(g){g.openElements.hasInListItemScope(M.TAG_ID.LI)&&(g.openElements.generateImpliedEndTagsWithExclusion(M.TAG_ID.LI),g.openElements.popUntilTagNamePopped(M.TAG_ID.LI))}function Abt(g,e){const I=e.tagID;g.openElements.hasInScope(I)&&(g.openElements.generateImpliedEndTagsWithExclusion(I),g.openElements.popUntilTagNamePopped(I))}function abt(g){g.openElements.hasNumberedHeaderInScope()&&(g.openElements.generateImpliedEndTags(),g.openElements.popUntilNumberedHeaderPopped())}function sbt(g,e){const I=e.tagID;g.openElements.hasInScope(I)&&(g.openElements.generateImpliedEndTags(),g.openElements.popUntilTagNamePopped(I),g.activeFormattingElements.clearToLastMarker())}function lbt(g){g._reconstructActiveFormattingElements(),g._insertFakeElement(M.TAG_NAMES.BR,M.TAG_ID.BR),g.openElements.pop(),g.framesetOk=!1}function $Se(g,e){const I=e.tagName,i=e.tagID;for(let n=g.openElements.stackTop;n>0;n--){const C=g.openElements.items[n],r=g.openElements.tagIDs[n];if(i===r&&(i!==M.TAG_ID.UNKNOWN||g.treeAdapter.getTagName(C)===I)){g.openElements.generateImpliedEndTagsWithExclusion(i),g.openElements.stackTop>=n&&g.openElements.shortenToLength(n);break}if(g._isSpecialElement(C,r))break}}function Sk(g,e){switch(e.tagID){case M.TAG_ID.A:case M.TAG_ID.B:case M.TAG_ID.I:case M.TAG_ID.S:case M.TAG_ID.U:case M.TAG_ID.EM:case M.TAG_ID.TT:case M.TAG_ID.BIG:case M.TAG_ID.CODE:case M.TAG_ID.FONT:case M.TAG_ID.NOBR:case M.TAG_ID.SMALL:case M.TAG_ID.STRIKE:case M.TAG_ID.STRONG:{uj(g,e);break}case M.TAG_ID.P:{rbt(g);break}case M.TAG_ID.DL:case M.TAG_ID.UL:case M.TAG_ID.OL:case M.TAG_ID.DIR:case M.TAG_ID.DIV:case M.TAG_ID.NAV:case M.TAG_ID.PRE:case M.TAG_ID.MAIN:case M.TAG_ID.MENU:case M.TAG_ID.ASIDE:case M.TAG_ID.BUTTON:case M.TAG_ID.CENTER:case M.TAG_ID.FIGURE:case M.TAG_ID.FOOTER:case M.TAG_ID.HEADER:case M.TAG_ID.HGROUP:case M.TAG_ID.DIALOG:case M.TAG_ID.ADDRESS:case M.TAG_ID.ARTICLE:case M.TAG_ID.DETAILS:case M.TAG_ID.SECTION:case M.TAG_ID.SUMMARY:case M.TAG_ID.LISTING:case M.TAG_ID.FIELDSET:case M.TAG_ID.BLOCKQUOTE:case M.TAG_ID.FIGCAPTION:{nbt(g,e);break}case M.TAG_ID.LI:{obt(g);break}case M.TAG_ID.DD:case M.TAG_ID.DT:{Abt(g,e);break}case M.TAG_ID.H1:case M.TAG_ID.H2:case M.TAG_ID.H3:case M.TAG_ID.H4:case M.TAG_ID.H5:case M.TAG_ID.H6:{abt(g);break}case M.TAG_ID.BR:{lbt(g);break}case M.TAG_ID.BODY:{Ibt(g,e);break}case M.TAG_ID.HTML:{ibt(g,e);break}case M.TAG_ID.FORM:{Cbt(g);break}case M.TAG_ID.APPLET:case M.TAG_ID.OBJECT:case M.TAG_ID.MARQUEE:{sbt(g,e);break}case M.TAG_ID.TEMPLATE:{mm(g,e);break}default:$Se(g,e)}}function qSe(g,e){g.tmplInsertionModeStack.length>0?Cwe(g,e):dj(g,e)}function cbt(g,e){var I;e.tagID===M.TAG_ID.SCRIPT&&((I=g.scriptHandler)===null||I===void 0||I.call(g,g.openElements.current)),g.openElements.pop(),g.insertionMode=g.originalInsertionMode}function ubt(g,e){g._err(e,cn.ERR.eofInElementThatCanContainOnlyText),g.openElements.pop(),g.insertionMode=g.originalInsertionMode,g.onEof(e)}function RD(g,e){if(LSe.has(g.openElements.currentTagId))switch(g.pendingCharacterTokens.length=0,g.hasNonWhitespacePendingCharacterToken=!1,g.originalInsertionMode=g.insertionMode,g.insertionMode=Ve.IN_TABLE_TEXT,e.type){case Bi.TokenType.CHARACTER:{twe(g,e);break}case Bi.TokenType.WHITESPACE_CHARACTER:{ewe(g,e);break}}else Zw(g,e)}function dbt(g,e){g.openElements.clearBackToTableContext(),g.activeFormattingElements.insertMarker(),g._insertElement(e,M.NS.HTML),g.insertionMode=Ve.IN_CAPTION}function hbt(g,e){g.openElements.clearBackToTableContext(),g._insertElement(e,M.NS.HTML),g.insertionMode=Ve.IN_COLUMN_GROUP}function mbt(g,e){g.openElements.clearBackToTableContext(),g._insertFakeElement(M.TAG_NAMES.COLGROUP,M.TAG_ID.COLGROUP),g.insertionMode=Ve.IN_COLUMN_GROUP,hj(g,e)}function fbt(g,e){g.openElements.clearBackToTableContext(),g._insertElement(e,M.NS.HTML),g.insertionMode=Ve.IN_TABLE_BODY}function pbt(g,e){g.openElements.clearBackToTableContext(),g._insertFakeElement(M.TAG_NAMES.TBODY,M.TAG_ID.TBODY),g.insertionMode=Ve.IN_TABLE_BODY,wk(g,e)}function bbt(g,e){g.openElements.hasInTableScope(M.TAG_ID.TABLE)&&(g.openElements.popUntilTagNamePopped(M.TAG_ID.TABLE),g._resetInsertionMode(),g._processStartTag(e))}function ybt(g,e){jSe(e)?g._appendElement(e,M.NS.HTML):Zw(g,e),e.ackSelfClosing=!0}function Zbt(g,e){!g.formElement&&g.openElements.tmplCount===0&&(g._insertElement(e,M.NS.HTML),g.formElement=g.openElements.current,g.openElements.pop())}function I0(g,e){switch(e.tagID){case M.TAG_ID.TD:case M.TAG_ID.TH:case M.TAG_ID.TR:{pbt(g,e);break}case M.TAG_ID.STYLE:case M.TAG_ID.SCRIPT:case M.TAG_ID.TEMPLATE:{yA(g,e);break}case M.TAG_ID.COL:{mbt(g,e);break}case M.TAG_ID.FORM:{Zbt(g,e);break}case M.TAG_ID.TABLE:{bbt(g,e);break}case M.TAG_ID.TBODY:case M.TAG_ID.TFOOT:case M.TAG_ID.THEAD:{fbt(g,e);break}case M.TAG_ID.INPUT:{ybt(g,e);break}case M.TAG_ID.CAPTION:{dbt(g,e);break}case M.TAG_ID.COLGROUP:{hbt(g,e);break}default:Zw(g,e)}}function _v(g,e){switch(e.tagID){case M.TAG_ID.TABLE:{g.openElements.hasInTableScope(M.TAG_ID.TABLE)&&(g.openElements.popUntilTagNamePopped(M.TAG_ID.TABLE),g._resetInsertionMode());break}case M.TAG_ID.TEMPLATE:{mm(g,e);break}case M.TAG_ID.BODY:case M.TAG_ID.CAPTION:case M.TAG_ID.COL:case M.TAG_ID.COLGROUP:case M.TAG_ID.HTML:case M.TAG_ID.TBODY:case M.TAG_ID.TD:case M.TAG_ID.TFOOT:case M.TAG_ID.TH:case M.TAG_ID.THEAD:case M.TAG_ID.TR:break;default:Zw(g,e)}}function Zw(g,e){const I=g.fosterParentingEnabled;g.fosterParentingEnabled=!0,vk(g,e),g.fosterParentingEnabled=I}function ewe(g,e){g.pendingCharacterTokens.push(e)}function twe(g,e){g.pendingCharacterTokens.push(e),g.hasNonWhitespacePendingCharacterToken=!0}function sZ(g,e){let I=0;if(g.hasNonWhitespacePendingCharacterToken)for(;I0&&g.openElements.currentTagId===M.TAG_ID.OPTION&&g.openElements.tagIDs[g.openElements.stackTop-1]===M.TAG_ID.OPTGROUP&&g.openElements.pop(),g.openElements.currentTagId===M.TAG_ID.OPTGROUP&&g.openElements.pop();break}case M.TAG_ID.OPTION:{g.openElements.currentTagId===M.TAG_ID.OPTION&&g.openElements.pop();break}case M.TAG_ID.SELECT:{g.openElements.hasInSelectScope(M.TAG_ID.SELECT)&&(g.openElements.popUntilTagNamePopped(M.TAG_ID.SELECT),g._resetInsertionMode());break}case M.TAG_ID.TEMPLATE:{mm(g,e);break}}}function Vbt(g,e){const I=e.tagID;I===M.TAG_ID.CAPTION||I===M.TAG_ID.TABLE||I===M.TAG_ID.TBODY||I===M.TAG_ID.TFOOT||I===M.TAG_ID.THEAD||I===M.TAG_ID.TR||I===M.TAG_ID.TD||I===M.TAG_ID.TH?(g.openElements.popUntilTagNamePopped(M.TAG_ID.SELECT),g._resetInsertionMode(),g._processStartTag(e)):iwe(g,e)}function Rbt(g,e){const I=e.tagID;I===M.TAG_ID.CAPTION||I===M.TAG_ID.TABLE||I===M.TAG_ID.TBODY||I===M.TAG_ID.TFOOT||I===M.TAG_ID.THEAD||I===M.TAG_ID.TR||I===M.TAG_ID.TD||I===M.TAG_ID.TH?g.openElements.hasInTableScope(I)&&(g.openElements.popUntilTagNamePopped(M.TAG_ID.SELECT),g._resetInsertionMode(),g.onEndTag(e)):nwe(g,e)}function Wbt(g,e){switch(e.tagID){case M.TAG_ID.BASE:case M.TAG_ID.BASEFONT:case M.TAG_ID.BGSOUND:case M.TAG_ID.LINK:case M.TAG_ID.META:case M.TAG_ID.NOFRAMES:case M.TAG_ID.SCRIPT:case M.TAG_ID.STYLE:case M.TAG_ID.TEMPLATE:case M.TAG_ID.TITLE:{yA(g,e);break}case M.TAG_ID.CAPTION:case M.TAG_ID.COLGROUP:case M.TAG_ID.TBODY:case M.TAG_ID.TFOOT:case M.TAG_ID.THEAD:{g.tmplInsertionModeStack[0]=Ve.IN_TABLE,g.insertionMode=Ve.IN_TABLE,I0(g,e);break}case M.TAG_ID.COL:{g.tmplInsertionModeStack[0]=Ve.IN_COLUMN_GROUP,g.insertionMode=Ve.IN_COLUMN_GROUP,hj(g,e);break}case M.TAG_ID.TR:{g.tmplInsertionModeStack[0]=Ve.IN_TABLE_BODY,g.insertionMode=Ve.IN_TABLE_BODY,wk(g,e);break}case M.TAG_ID.TD:case M.TAG_ID.TH:{g.tmplInsertionModeStack[0]=Ve.IN_ROW,g.insertionMode=Ve.IN_ROW,Vk(g,e);break}default:g.tmplInsertionModeStack[0]=Ve.IN_BODY,g.insertionMode=Ve.IN_BODY,Dn(g,e)}}function Xbt(g,e){e.tagID===M.TAG_ID.TEMPLATE&&mm(g,e)}function Cwe(g,e){g.openElements.tmplCount>0?(g.openElements.popUntilTagNamePopped(M.TAG_ID.TEMPLATE),g.activeFormattingElements.clearToLastMarker(),g.tmplInsertionModeStack.shift(),g._resetInsertionMode(),g.onEof(e)):dj(g,e)}function Hbt(g,e){e.tagID===M.TAG_ID.HTML?Dn(g,e):oH(g,e)}function rwe(g,e){var I;if(e.tagID===M.TAG_ID.HTML){if(g.fragmentContext||(g.insertionMode=Ve.AFTER_AFTER_BODY),g.options.sourceCodeLocationInfo&&g.openElements.tagIDs[0]===M.TAG_ID.HTML){g._setEndLocation(g.openElements.items[0],e);const i=g.openElements.items[1];i&&!(!((I=g.treeAdapter.getNodeSourceCodeLocation(i))===null||I===void 0)&&I.endTag)&&g._setEndLocation(i,e)}}else oH(g,e)}function oH(g,e){g.insertionMode=Ve.IN_BODY,vk(g,e)}function Tbt(g,e){switch(e.tagID){case M.TAG_ID.HTML:{Dn(g,e);break}case M.TAG_ID.FRAMESET:{g._insertElement(e,M.NS.HTML);break}case M.TAG_ID.FRAME:{g._appendElement(e,M.NS.HTML),e.ackSelfClosing=!0;break}case M.TAG_ID.NOFRAMES:{yA(g,e);break}}}function Nbt(g,e){e.tagID===M.TAG_ID.FRAMESET&&!g.openElements.isRootHtmlElementCurrent()&&(g.openElements.pop(),!g.fragmentContext&&g.openElements.currentTagId!==M.TAG_ID.FRAMESET&&(g.insertionMode=Ve.AFTER_FRAMESET))}function kbt(g,e){switch(e.tagID){case M.TAG_ID.HTML:{Dn(g,e);break}case M.TAG_ID.NOFRAMES:{yA(g,e);break}}}function Ybt(g,e){e.tagID===M.TAG_ID.HTML&&(g.insertionMode=Ve.AFTER_AFTER_FRAMESET)}function Kbt(g,e){e.tagID===M.TAG_ID.HTML?Dn(g,e):lW(g,e)}function lW(g,e){g.insertionMode=Ve.IN_BODY,vk(g,e)}function xbt(g,e){switch(e.tagID){case M.TAG_ID.HTML:{Dn(g,e);break}case M.TAG_ID.NOFRAMES:{yA(g,e);break}}}function Dbt(g,e){e.chars=OSe.REPLACEMENT_CHARACTER,g._insertCharacters(e)}function Fbt(g,e){g._insertCharacters(e),g.framesetOk=!1}function owe(g){for(;g.treeAdapter.getNamespaceURI(g.openElements.current)!==M.NS.HTML&&!g._isIntegrationPoint(g.openElements.currentTagId,g.openElements.current);)g.openElements.pop()}function Ebt(g,e){if(UA.causesExit(e))owe(g),g._startTagOutsideForeignContent(e);else{const I=g._getAdjustedCurrentElement(),i=g.treeAdapter.getNamespaceURI(I);i===M.NS.MATHML?UA.adjustTokenMathMLAttrs(e):i===M.NS.SVG&&(UA.adjustTokenSVGTagName(e),UA.adjustTokenSVGAttrs(e)),UA.adjustTokenXMLAttrs(e),e.selfClosing?g._appendElement(e,i):g._insertElement(e,i),e.ackSelfClosing=!0}}function Mbt(g,e){if(e.tagID===M.TAG_ID.P||e.tagID===M.TAG_ID.BR){owe(g),g._endTagOutsideForeignContent(e);return}for(let I=g.openElements.stackTop;I>0;I--){const i=g.openElements.items[I];if(g.treeAdapter.getNamespaceURI(i)===M.NS.HTML){g._endTagOutsideForeignContent(e);break}const n=g.treeAdapter.getTagName(i);if(n.toLowerCase()===e.tagName){e.tagName=n,g.openElements.shortenToLength(I);break}}}var i0={};Object.defineProperty(i0,"__esModule",{value:!0});i0.serializeOuter=i0.serialize=void 0;const rI=dl,Awe=_b,zbt=Bk,Pbt=new Set([rI.TAG_NAMES.AREA,rI.TAG_NAMES.BASE,rI.TAG_NAMES.BASEFONT,rI.TAG_NAMES.BGSOUND,rI.TAG_NAMES.BR,rI.TAG_NAMES.COL,rI.TAG_NAMES.EMBED,rI.TAG_NAMES.FRAME,rI.TAG_NAMES.HR,rI.TAG_NAMES.IMG,rI.TAG_NAMES.INPUT,rI.TAG_NAMES.KEYGEN,rI.TAG_NAMES.LINK,rI.TAG_NAMES.META,rI.TAG_NAMES.PARAM,rI.TAG_NAMES.SOURCE,rI.TAG_NAMES.TRACK,rI.TAG_NAMES.WBR]);function awe(g,e){return e.treeAdapter.isElementNode(g)&&e.treeAdapter.getNamespaceURI(g)===rI.NS.HTML&&Pbt.has(e.treeAdapter.getTagName(g))}const swe={treeAdapter:zbt.defaultTreeAdapter,scriptingEnabled:!0};function Jbt(g,e){const I=Object.assign(Object.assign({},swe),e);return awe(g,I)?"":lwe(g,I)}i0.serialize=Jbt;function Obt(g,e){const I=Object.assign(Object.assign({},swe),e);return cwe(g,I)}i0.serializeOuter=Obt;function lwe(g,e){let I="";const i=e.treeAdapter.isElementNode(g)&&e.treeAdapter.getTagName(g)===rI.TAG_NAMES.TEMPLATE&&e.treeAdapter.getNamespaceURI(g)===rI.NS.HTML?e.treeAdapter.getTemplateContent(g):g,n=e.treeAdapter.getChildNodes(i);if(n)for(const C of n)I+=cwe(C,e);return I}function cwe(g,e){return e.treeAdapter.isElementNode(g)?Lbt(g,e):e.treeAdapter.isTextNode(g)?Ubt(g,e):e.treeAdapter.isCommentNode(g)?Qbt(g,e):e.treeAdapter.isDocumentTypeNode(g)?jbt(g,e):""}function Lbt(g,e){const I=e.treeAdapter.getTagName(g);return`<${I}${_bt(g,e)}>${awe(g,e)?"":`${lwe(g,e)}`}`}function _bt(g,{treeAdapter:e}){let I="";for(const i of e.getAttrList(g)){if(I+=" ",!i.namespace)I+=i.name;else switch(i.namespace){case rI.NS.XML:{I+=`xml:${i.name}`;break}case rI.NS.XMLNS:{i.name!=="xmlns"&&(I+="xmlns:"),I+=i.name;break}case rI.NS.XLINK:{I+=`xlink:${i.name}`;break}default:I+=`${i.prefix}:${i.name}`}I+=`="${(0,Awe.escapeAttribute)(i.value)}"`}return I}function Ubt(g,e){const{treeAdapter:I}=e,i=I.getTextNodeContent(g),n=I.getParentNode(g),C=n&&I.isElementNode(n)&&I.getTagName(n);return C&&I.getNamespaceURI(n)===rI.NS.HTML&&(0,rI.hasUnescapedText)(C,e.scriptingEnabled)?i:(0,Awe.escapeText)(i)}function Qbt(g,{treeAdapter:e}){return``}function jbt(g,{treeAdapter:e}){return``}(function(g){Object.defineProperty(g,"__esModule",{value:!0}),g.parseFragment=g.parse=g.TokenizerMode=g.Tokenizer=g.Token=g.html=g.foreignContent=g.ErrorCodes=g.serializeOuter=g.serialize=g.Parser=g.defaultTreeAdapter=void 0;const e=Lv;var I=Bk;Object.defineProperty(g,"defaultTreeAdapter",{enumerable:!0,get:function(){return I.defaultTreeAdapter}});var i=Lv;Object.defineProperty(g,"Parser",{enumerable:!0,get:function(){return i.Parser}});var n=i0;Object.defineProperty(g,"serialize",{enumerable:!0,get:function(){return n.serialize}}),Object.defineProperty(g,"serializeOuter",{enumerable:!0,get:function(){return n.serializeOuter}});var C=yw;Object.defineProperty(g,"ErrorCodes",{enumerable:!0,get:function(){return C.ERR}}),g.foreignContent=cj,g.html=dl,g.Token=Zk;var r=bh;Object.defineProperty(g,"Tokenizer",{enumerable:!0,get:function(){return r.Tokenizer}}),Object.defineProperty(g,"TokenizerMode",{enumerable:!0,get:function(){return r.TokenizerMode}});function o(s,a){return e.Parser.parse(s,a)}g.parse=o;function A(s,a,l){typeof s=="string"&&(l=a,a=s,s=null);const c=e.Parser.getFragmentParser(s,l);return c.tokenizer.write(a,!0),c.getFragment()}g.parseFragment=A})(KSe);var uwe={},dwe={},Uv={},yh={},Rk={},Wk={};(function(g){Object.defineProperty(g,"__esModule",{value:!0}),g.isUndefinedCodePoint=g.isControlCodePoint=g.getSurrogatePairCodePoint=g.isSurrogatePair=g.isSurrogate=g.SEQUENCES=g.CODE_POINTS=g.REPLACEMENT_CHARACTER=void 0;const e=new Set([65534,65535,131070,131071,196606,196607,262142,262143,327678,327679,393214,393215,458750,458751,524286,524287,589822,589823,655358,655359,720894,720895,786430,786431,851966,851967,917502,917503,983038,983039,1048574,1048575,1114110,1114111]);g.REPLACEMENT_CHARACTER="�",function(o){o[o.EOF=-1]="EOF",o[o.NULL=0]="NULL",o[o.TABULATION=9]="TABULATION",o[o.CARRIAGE_RETURN=13]="CARRIAGE_RETURN",o[o.LINE_FEED=10]="LINE_FEED",o[o.FORM_FEED=12]="FORM_FEED",o[o.SPACE=32]="SPACE",o[o.EXCLAMATION_MARK=33]="EXCLAMATION_MARK",o[o.QUOTATION_MARK=34]="QUOTATION_MARK",o[o.NUMBER_SIGN=35]="NUMBER_SIGN",o[o.AMPERSAND=38]="AMPERSAND",o[o.APOSTROPHE=39]="APOSTROPHE",o[o.HYPHEN_MINUS=45]="HYPHEN_MINUS",o[o.SOLIDUS=47]="SOLIDUS",o[o.DIGIT_0=48]="DIGIT_0",o[o.DIGIT_9=57]="DIGIT_9",o[o.SEMICOLON=59]="SEMICOLON",o[o.LESS_THAN_SIGN=60]="LESS_THAN_SIGN",o[o.EQUALS_SIGN=61]="EQUALS_SIGN",o[o.GREATER_THAN_SIGN=62]="GREATER_THAN_SIGN",o[o.QUESTION_MARK=63]="QUESTION_MARK",o[o.LATIN_CAPITAL_A=65]="LATIN_CAPITAL_A",o[o.LATIN_CAPITAL_F=70]="LATIN_CAPITAL_F",o[o.LATIN_CAPITAL_X=88]="LATIN_CAPITAL_X",o[o.LATIN_CAPITAL_Z=90]="LATIN_CAPITAL_Z",o[o.RIGHT_SQUARE_BRACKET=93]="RIGHT_SQUARE_BRACKET",o[o.GRAVE_ACCENT=96]="GRAVE_ACCENT",o[o.LATIN_SMALL_A=97]="LATIN_SMALL_A",o[o.LATIN_SMALL_F=102]="LATIN_SMALL_F",o[o.LATIN_SMALL_X=120]="LATIN_SMALL_X",o[o.LATIN_SMALL_Z=122]="LATIN_SMALL_Z",o[o.REPLACEMENT_CHARACTER=65533]="REPLACEMENT_CHARACTER"}(g.CODE_POINTS||(g.CODE_POINTS={})),g.SEQUENCES={DASH_DASH:"--",CDATA_START:"[CDATA[",DOCTYPE:"doctype",SCRIPT:"script",PUBLIC:"public",SYSTEM:"system"};function I(o){return o>=55296&&o<=57343}g.isSurrogate=I;function i(o){return o>=56320&&o<=57343}g.isSurrogatePair=i;function n(o,A){return(o-55296)*1024+9216+A}g.getSurrogatePairCodePoint=n;function C(o){return o!==32&&o!==10&&o!==13&&o!==9&&o!==12&&o>=1&&o<=31||o>=127&&o<=159}g.isControlCodePoint=C;function r(o){return o>=64976&&o<=65007||e.has(o)}g.isUndefinedCodePoint=r})(Wk);var Gw={};(function(g){Object.defineProperty(g,"__esModule",{value:!0}),g.ERR=void 0,function(e){e.controlCharacterInInputStream="control-character-in-input-stream",e.noncharacterInInputStream="noncharacter-in-input-stream",e.surrogateInInputStream="surrogate-in-input-stream",e.nonVoidHtmlElementStartTagWithTrailingSolidus="non-void-html-element-start-tag-with-trailing-solidus",e.endTagWithAttributes="end-tag-with-attributes",e.endTagWithTrailingSolidus="end-tag-with-trailing-solidus",e.unexpectedSolidusInTag="unexpected-solidus-in-tag",e.unexpectedNullCharacter="unexpected-null-character",e.unexpectedQuestionMarkInsteadOfTagName="unexpected-question-mark-instead-of-tag-name",e.invalidFirstCharacterOfTagName="invalid-first-character-of-tag-name",e.unexpectedEqualsSignBeforeAttributeName="unexpected-equals-sign-before-attribute-name",e.missingEndTagName="missing-end-tag-name",e.unexpectedCharacterInAttributeName="unexpected-character-in-attribute-name",e.unknownNamedCharacterReference="unknown-named-character-reference",e.missingSemicolonAfterCharacterReference="missing-semicolon-after-character-reference",e.unexpectedCharacterAfterDoctypeSystemIdentifier="unexpected-character-after-doctype-system-identifier",e.unexpectedCharacterInUnquotedAttributeValue="unexpected-character-in-unquoted-attribute-value",e.eofBeforeTagName="eof-before-tag-name",e.eofInTag="eof-in-tag",e.missingAttributeValue="missing-attribute-value",e.missingWhitespaceBetweenAttributes="missing-whitespace-between-attributes",e.missingWhitespaceAfterDoctypePublicKeyword="missing-whitespace-after-doctype-public-keyword",e.missingWhitespaceBetweenDoctypePublicAndSystemIdentifiers="missing-whitespace-between-doctype-public-and-system-identifiers",e.missingWhitespaceAfterDoctypeSystemKeyword="missing-whitespace-after-doctype-system-keyword",e.missingQuoteBeforeDoctypePublicIdentifier="missing-quote-before-doctype-public-identifier",e.missingQuoteBeforeDoctypeSystemIdentifier="missing-quote-before-doctype-system-identifier",e.missingDoctypePublicIdentifier="missing-doctype-public-identifier",e.missingDoctypeSystemIdentifier="missing-doctype-system-identifier",e.abruptDoctypePublicIdentifier="abrupt-doctype-public-identifier",e.abruptDoctypeSystemIdentifier="abrupt-doctype-system-identifier",e.cdataInHtmlContent="cdata-in-html-content",e.incorrectlyOpenedComment="incorrectly-opened-comment",e.eofInScriptHtmlCommentLikeText="eof-in-script-html-comment-like-text",e.eofInDoctype="eof-in-doctype",e.nestedComment="nested-comment",e.abruptClosingOfEmptyComment="abrupt-closing-of-empty-comment",e.eofInComment="eof-in-comment",e.incorrectlyClosedComment="incorrectly-closed-comment",e.eofInCdata="eof-in-cdata",e.absenceOfDigitsInNumericCharacterReference="absence-of-digits-in-numeric-character-reference",e.nullCharacterReference="null-character-reference",e.surrogateCharacterReference="surrogate-character-reference",e.characterReferenceOutsideUnicodeRange="character-reference-outside-unicode-range",e.controlCharacterReference="control-character-reference",e.noncharacterCharacterReference="noncharacter-character-reference",e.missingWhitespaceBeforeDoctypeName="missing-whitespace-before-doctype-name",e.missingDoctypeName="missing-doctype-name",e.invalidCharacterSequenceAfterDoctypeName="invalid-character-sequence-after-doctype-name",e.duplicateAttribute="duplicate-attribute",e.nonConformingDoctype="non-conforming-doctype",e.missingDoctype="missing-doctype",e.misplacedDoctype="misplaced-doctype",e.endTagWithoutMatchingOpenElement="end-tag-without-matching-open-element",e.closingOfElementWithOpenChildElements="closing-of-element-with-open-child-elements",e.disallowedContentInNoscriptInHead="disallowed-content-in-noscript-in-head",e.openElementsLeftAfterEof="open-elements-left-after-eof",e.abandonedHeadElementChild="abandoned-head-element-child",e.misplacedStartTagForHeadElement="misplaced-start-tag-for-head-element",e.nestedNoscriptInHead="nested-noscript-in-head",e.eofInElementThatCanContainOnlyText="eof-in-element-that-can-contain-only-text"}(g.ERR||(g.ERR={}))})(Gw);function $bt(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function gCe(g,e){for(var I=0;Ithis.bufferWaterline}},{key:"dropParsedChunk",value:function(){this.willDropParsedChunk()&&(this.html=this.html.substring(this.pos),this.lineStartPos-=this.pos,this.droppedBufferSize+=this.pos,this.pos=0,this.lastGapPos=-2,this.gapStack.length=0)}},{key:"write",value:function(I,i){this.html.length>0?this.html+=I:this.html=I,this.endOfChunkHit=!1,this.lastChunkWritten=i}},{key:"insertHtmlAtCurrentPos",value:function(I){this.html=this.html.substring(0,this.pos+1)+I+this.html.substring(this.pos+1),this.endOfChunkHit=!1}},{key:"startsWith",value:function(I,i){if(this.pos+I.length>this.html.length)return this.endOfChunkHit=!this.lastChunkWritten,!1;if(i)return this.html.startsWith(I,this.pos);for(let n=0;n=this.html.length)return this.endOfChunkHit=!this.lastChunkWritten,Mn.CODE_POINTS.EOF;const n=this.html.charCodeAt(i);return n===Mn.CODE_POINTS.CARRIAGE_RETURN?Mn.CODE_POINTS.LINE_FEED:n}},{key:"advance",value:function(){if(this.pos++,this.isEol&&(this.isEol=!1,this.line++,this.lineStartPos=this.pos),this.pos>=this.html.length)return this.endOfChunkHit=!this.lastChunkWritten,Mn.CODE_POINTS.EOF;let I=this.html.charCodeAt(this.pos);return I===Mn.CODE_POINTS.CARRIAGE_RETURN?(this.isEol=!0,this.skipNextNewLine=!0,Mn.CODE_POINTS.LINE_FEED):I===Mn.CODE_POINTS.LINE_FEED&&(this.isEol=!0,this.skipNextNewLine)?(this.line--,this.skipNextNewLine=!1,this._addGap(),this.advance()):(this.skipNextNewLine=!1,(0,Mn.isSurrogate)(I)&&(I=this._processSurrogate(I)),this.handler.onParseError===null||I>31&&I<127||I===Mn.CODE_POINTS.LINE_FEED||I===Mn.CODE_POINTS.CARRIAGE_RETURN||I>159&&I<64976||this._checkForProblematicCharacters(I),I)}},{key:"_checkForProblematicCharacters",value:function(I){(0,Mn.isControlCodePoint)(I)?this._err(WD.ERR.controlCharacterInInputStream):(0,Mn.isUndefinedCodePoint)(I)&&this._err(WD.ERR.noncharacterInInputStream)}},{key:"retreat",value:function(I){for(this.pos-=I;this.pos=0;n--)if(I.attrs[n].name===i)return I.attrs[n].value;return null}g.getTokenAttr=e})(Xk);var hl={};(function(g){Object.defineProperty(g,"__esModule",{value:!0}),g.hasUnescapedText=g.isNumberedHeader=g.SPECIAL_ELEMENTS=g.getTagID=g.TAG_ID=g.TAG_NAMES=g.DOCUMENT_MODE=g.ATTRS=g.NS=void 0;var e;(function(a){a.HTML="http://www.w3.org/1999/xhtml",a.MATHML="http://www.w3.org/1998/Math/MathML",a.SVG="http://www.w3.org/2000/svg",a.XLINK="http://www.w3.org/1999/xlink",a.XML="http://www.w3.org/XML/1998/namespace",a.XMLNS="http://www.w3.org/2000/xmlns/"})(e=g.NS||(g.NS={})),function(a){a.TYPE="type",a.ACTION="action",a.ENCODING="encoding",a.PROMPT="prompt",a.NAME="name",a.COLOR="color",a.FACE="face",a.SIZE="size"}(g.ATTRS||(g.ATTRS={})),function(a){a.NO_QUIRKS="no-quirks",a.QUIRKS="quirks",a.LIMITED_QUIRKS="limited-quirks"}(g.DOCUMENT_MODE||(g.DOCUMENT_MODE={}));var I;(function(a){a.A="a",a.ADDRESS="address",a.ANNOTATION_XML="annotation-xml",a.APPLET="applet",a.AREA="area",a.ARTICLE="article",a.ASIDE="aside",a.B="b",a.BASE="base",a.BASEFONT="basefont",a.BGSOUND="bgsound",a.BIG="big",a.BLOCKQUOTE="blockquote",a.BODY="body",a.BR="br",a.BUTTON="button",a.CAPTION="caption",a.CENTER="center",a.CODE="code",a.COL="col",a.COLGROUP="colgroup",a.DD="dd",a.DESC="desc",a.DETAILS="details",a.DIALOG="dialog",a.DIR="dir",a.DIV="div",a.DL="dl",a.DT="dt",a.EM="em",a.EMBED="embed",a.FIELDSET="fieldset",a.FIGCAPTION="figcaption",a.FIGURE="figure",a.FONT="font",a.FOOTER="footer",a.FOREIGN_OBJECT="foreignObject",a.FORM="form",a.FRAME="frame",a.FRAMESET="frameset",a.H1="h1",a.H2="h2",a.H3="h3",a.H4="h4",a.H5="h5",a.H6="h6",a.HEAD="head",a.HEADER="header",a.HGROUP="hgroup",a.HR="hr",a.HTML="html",a.I="i",a.IMG="img",a.IMAGE="image",a.INPUT="input",a.IFRAME="iframe",a.KEYGEN="keygen",a.LABEL="label",a.LI="li",a.LINK="link",a.LISTING="listing",a.MAIN="main",a.MALIGNMARK="malignmark",a.MARQUEE="marquee",a.MATH="math",a.MENU="menu",a.META="meta",a.MGLYPH="mglyph",a.MI="mi",a.MO="mo",a.MN="mn",a.MS="ms",a.MTEXT="mtext",a.NAV="nav",a.NOBR="nobr",a.NOFRAMES="noframes",a.NOEMBED="noembed",a.NOSCRIPT="noscript",a.OBJECT="object",a.OL="ol",a.OPTGROUP="optgroup",a.OPTION="option",a.P="p",a.PARAM="param",a.PLAINTEXT="plaintext",a.PRE="pre",a.RB="rb",a.RP="rp",a.RT="rt",a.RTC="rtc",a.RUBY="ruby",a.S="s",a.SCRIPT="script",a.SECTION="section",a.SELECT="select",a.SOURCE="source",a.SMALL="small",a.SPAN="span",a.STRIKE="strike",a.STRONG="strong",a.STYLE="style",a.SUB="sub",a.SUMMARY="summary",a.SUP="sup",a.TABLE="table",a.TBODY="tbody",a.TEMPLATE="template",a.TEXTAREA="textarea",a.TFOOT="tfoot",a.TD="td",a.TH="th",a.THEAD="thead",a.TITLE="title",a.TR="tr",a.TRACK="track",a.TT="tt",a.U="u",a.UL="ul",a.SVG="svg",a.VAR="var",a.WBR="wbr",a.XMP="xmp"})(I=g.TAG_NAMES||(g.TAG_NAMES={}));var i;(function(a){a[a.UNKNOWN=0]="UNKNOWN",a[a.A=1]="A",a[a.ADDRESS=2]="ADDRESS",a[a.ANNOTATION_XML=3]="ANNOTATION_XML",a[a.APPLET=4]="APPLET",a[a.AREA=5]="AREA",a[a.ARTICLE=6]="ARTICLE",a[a.ASIDE=7]="ASIDE",a[a.B=8]="B",a[a.BASE=9]="BASE",a[a.BASEFONT=10]="BASEFONT",a[a.BGSOUND=11]="BGSOUND",a[a.BIG=12]="BIG",a[a.BLOCKQUOTE=13]="BLOCKQUOTE",a[a.BODY=14]="BODY",a[a.BR=15]="BR",a[a.BUTTON=16]="BUTTON",a[a.CAPTION=17]="CAPTION",a[a.CENTER=18]="CENTER",a[a.CODE=19]="CODE",a[a.COL=20]="COL",a[a.COLGROUP=21]="COLGROUP",a[a.DD=22]="DD",a[a.DESC=23]="DESC",a[a.DETAILS=24]="DETAILS",a[a.DIALOG=25]="DIALOG",a[a.DIR=26]="DIR",a[a.DIV=27]="DIV",a[a.DL=28]="DL",a[a.DT=29]="DT",a[a.EM=30]="EM",a[a.EMBED=31]="EMBED",a[a.FIELDSET=32]="FIELDSET",a[a.FIGCAPTION=33]="FIGCAPTION",a[a.FIGURE=34]="FIGURE",a[a.FONT=35]="FONT",a[a.FOOTER=36]="FOOTER",a[a.FOREIGN_OBJECT=37]="FOREIGN_OBJECT",a[a.FORM=38]="FORM",a[a.FRAME=39]="FRAME",a[a.FRAMESET=40]="FRAMESET",a[a.H1=41]="H1",a[a.H2=42]="H2",a[a.H3=43]="H3",a[a.H4=44]="H4",a[a.H5=45]="H5",a[a.H6=46]="H6",a[a.HEAD=47]="HEAD",a[a.HEADER=48]="HEADER",a[a.HGROUP=49]="HGROUP",a[a.HR=50]="HR",a[a.HTML=51]="HTML",a[a.I=52]="I",a[a.IMG=53]="IMG",a[a.IMAGE=54]="IMAGE",a[a.INPUT=55]="INPUT",a[a.IFRAME=56]="IFRAME",a[a.KEYGEN=57]="KEYGEN",a[a.LABEL=58]="LABEL",a[a.LI=59]="LI",a[a.LINK=60]="LINK",a[a.LISTING=61]="LISTING",a[a.MAIN=62]="MAIN",a[a.MALIGNMARK=63]="MALIGNMARK",a[a.MARQUEE=64]="MARQUEE",a[a.MATH=65]="MATH",a[a.MENU=66]="MENU",a[a.META=67]="META",a[a.MGLYPH=68]="MGLYPH",a[a.MI=69]="MI",a[a.MO=70]="MO",a[a.MN=71]="MN",a[a.MS=72]="MS",a[a.MTEXT=73]="MTEXT",a[a.NAV=74]="NAV",a[a.NOBR=75]="NOBR",a[a.NOFRAMES=76]="NOFRAMES",a[a.NOEMBED=77]="NOEMBED",a[a.NOSCRIPT=78]="NOSCRIPT",a[a.OBJECT=79]="OBJECT",a[a.OL=80]="OL",a[a.OPTGROUP=81]="OPTGROUP",a[a.OPTION=82]="OPTION",a[a.P=83]="P",a[a.PARAM=84]="PARAM",a[a.PLAINTEXT=85]="PLAINTEXT",a[a.PRE=86]="PRE",a[a.RB=87]="RB",a[a.RP=88]="RP",a[a.RT=89]="RT",a[a.RTC=90]="RTC",a[a.RUBY=91]="RUBY",a[a.S=92]="S",a[a.SCRIPT=93]="SCRIPT",a[a.SECTION=94]="SECTION",a[a.SELECT=95]="SELECT",a[a.SOURCE=96]="SOURCE",a[a.SMALL=97]="SMALL",a[a.SPAN=98]="SPAN",a[a.STRIKE=99]="STRIKE",a[a.STRONG=100]="STRONG",a[a.STYLE=101]="STYLE",a[a.SUB=102]="SUB",a[a.SUMMARY=103]="SUMMARY",a[a.SUP=104]="SUP",a[a.TABLE=105]="TABLE",a[a.TBODY=106]="TBODY",a[a.TEMPLATE=107]="TEMPLATE",a[a.TEXTAREA=108]="TEXTAREA",a[a.TFOOT=109]="TFOOT",a[a.TD=110]="TD",a[a.TH=111]="TH",a[a.THEAD=112]="THEAD",a[a.TITLE=113]="TITLE",a[a.TR=114]="TR",a[a.TRACK=115]="TRACK",a[a.TT=116]="TT",a[a.U=117]="U",a[a.UL=118]="UL",a[a.SVG=119]="SVG",a[a.VAR=120]="VAR",a[a.WBR=121]="WBR",a[a.XMP=122]="XMP"})(i=g.TAG_ID||(g.TAG_ID={}));const n=new Map([[I.A,i.A],[I.ADDRESS,i.ADDRESS],[I.ANNOTATION_XML,i.ANNOTATION_XML],[I.APPLET,i.APPLET],[I.AREA,i.AREA],[I.ARTICLE,i.ARTICLE],[I.ASIDE,i.ASIDE],[I.B,i.B],[I.BASE,i.BASE],[I.BASEFONT,i.BASEFONT],[I.BGSOUND,i.BGSOUND],[I.BIG,i.BIG],[I.BLOCKQUOTE,i.BLOCKQUOTE],[I.BODY,i.BODY],[I.BR,i.BR],[I.BUTTON,i.BUTTON],[I.CAPTION,i.CAPTION],[I.CENTER,i.CENTER],[I.CODE,i.CODE],[I.COL,i.COL],[I.COLGROUP,i.COLGROUP],[I.DD,i.DD],[I.DESC,i.DESC],[I.DETAILS,i.DETAILS],[I.DIALOG,i.DIALOG],[I.DIR,i.DIR],[I.DIV,i.DIV],[I.DL,i.DL],[I.DT,i.DT],[I.EM,i.EM],[I.EMBED,i.EMBED],[I.FIELDSET,i.FIELDSET],[I.FIGCAPTION,i.FIGCAPTION],[I.FIGURE,i.FIGURE],[I.FONT,i.FONT],[I.FOOTER,i.FOOTER],[I.FOREIGN_OBJECT,i.FOREIGN_OBJECT],[I.FORM,i.FORM],[I.FRAME,i.FRAME],[I.FRAMESET,i.FRAMESET],[I.H1,i.H1],[I.H2,i.H2],[I.H3,i.H3],[I.H4,i.H4],[I.H5,i.H5],[I.H6,i.H6],[I.HEAD,i.HEAD],[I.HEADER,i.HEADER],[I.HGROUP,i.HGROUP],[I.HR,i.HR],[I.HTML,i.HTML],[I.I,i.I],[I.IMG,i.IMG],[I.IMAGE,i.IMAGE],[I.INPUT,i.INPUT],[I.IFRAME,i.IFRAME],[I.KEYGEN,i.KEYGEN],[I.LABEL,i.LABEL],[I.LI,i.LI],[I.LINK,i.LINK],[I.LISTING,i.LISTING],[I.MAIN,i.MAIN],[I.MALIGNMARK,i.MALIGNMARK],[I.MARQUEE,i.MARQUEE],[I.MATH,i.MATH],[I.MENU,i.MENU],[I.META,i.META],[I.MGLYPH,i.MGLYPH],[I.MI,i.MI],[I.MO,i.MO],[I.MN,i.MN],[I.MS,i.MS],[I.MTEXT,i.MTEXT],[I.NAV,i.NAV],[I.NOBR,i.NOBR],[I.NOFRAMES,i.NOFRAMES],[I.NOEMBED,i.NOEMBED],[I.NOSCRIPT,i.NOSCRIPT],[I.OBJECT,i.OBJECT],[I.OL,i.OL],[I.OPTGROUP,i.OPTGROUP],[I.OPTION,i.OPTION],[I.P,i.P],[I.PARAM,i.PARAM],[I.PLAINTEXT,i.PLAINTEXT],[I.PRE,i.PRE],[I.RB,i.RB],[I.RP,i.RP],[I.RT,i.RT],[I.RTC,i.RTC],[I.RUBY,i.RUBY],[I.S,i.S],[I.SCRIPT,i.SCRIPT],[I.SECTION,i.SECTION],[I.SELECT,i.SELECT],[I.SOURCE,i.SOURCE],[I.SMALL,i.SMALL],[I.SPAN,i.SPAN],[I.STRIKE,i.STRIKE],[I.STRONG,i.STRONG],[I.STYLE,i.STYLE],[I.SUB,i.SUB],[I.SUMMARY,i.SUMMARY],[I.SUP,i.SUP],[I.TABLE,i.TABLE],[I.TBODY,i.TBODY],[I.TEMPLATE,i.TEMPLATE],[I.TEXTAREA,i.TEXTAREA],[I.TFOOT,i.TFOOT],[I.TD,i.TD],[I.TH,i.TH],[I.THEAD,i.THEAD],[I.TITLE,i.TITLE],[I.TR,i.TR],[I.TRACK,i.TRACK],[I.TT,i.TT],[I.U,i.U],[I.UL,i.UL],[I.SVG,i.SVG],[I.VAR,i.VAR],[I.WBR,i.WBR],[I.XMP,i.XMP]]);function C(a){var l;return(l=n.get(a))!==null&&l!==void 0?l:i.UNKNOWN}g.getTagID=C;const r=i;g.SPECIAL_ELEMENTS={[e.HTML]:new Set([r.ADDRESS,r.APPLET,r.AREA,r.ARTICLE,r.ASIDE,r.BASE,r.BASEFONT,r.BGSOUND,r.BLOCKQUOTE,r.BODY,r.BR,r.BUTTON,r.CAPTION,r.CENTER,r.COL,r.COLGROUP,r.DD,r.DETAILS,r.DIR,r.DIV,r.DL,r.DT,r.EMBED,r.FIELDSET,r.FIGCAPTION,r.FIGURE,r.FOOTER,r.FORM,r.FRAME,r.FRAMESET,r.H1,r.H2,r.H3,r.H4,r.H5,r.H6,r.HEAD,r.HEADER,r.HGROUP,r.HR,r.HTML,r.IFRAME,r.IMG,r.INPUT,r.LI,r.LINK,r.LISTING,r.MAIN,r.MARQUEE,r.MENU,r.META,r.NAV,r.NOEMBED,r.NOFRAMES,r.NOSCRIPT,r.OBJECT,r.OL,r.P,r.PARAM,r.PLAINTEXT,r.PRE,r.SCRIPT,r.SECTION,r.SELECT,r.SOURCE,r.STYLE,r.SUMMARY,r.TABLE,r.TBODY,r.TD,r.TEMPLATE,r.TEXTAREA,r.TFOOT,r.TH,r.THEAD,r.TITLE,r.TR,r.TRACK,r.UL,r.WBR,r.XMP]),[e.MATHML]:new Set([r.MI,r.MO,r.MN,r.MS,r.MTEXT,r.ANNOTATION_XML]),[e.SVG]:new Set([r.TITLE,r.FOREIGN_OBJECT,r.DESC]),[e.XLINK]:new Set,[e.XML]:new Set,[e.XMLNS]:new Set};function o(a){return a===r.H1||a===r.H2||a===r.H3||a===r.H4||a===r.H5||a===r.H6}g.isNumberedHeader=o;const A=new Set([I.STYLE,I.SCRIPT,I.XMP,I.IFRAME,I.NOEMBED,I.NOFRAMES,I.PLAINTEXT]);function s(a,l){return A.has(a)||l&&a===I.NOSCRIPT}g.hasUnescapedText=s})(hl);function i0t(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function ICe(g,e){for(var I=0;I=ae.CODE_POINTS.DIGIT_0&&g<=ae.CODE_POINTS.DIGIT_9}function iG(g){return g>=ae.CODE_POINTS.LATIN_CAPITAL_A&&g<=ae.CODE_POINTS.LATIN_CAPITAL_Z}function a0t(g){return g>=ae.CODE_POINTS.LATIN_SMALL_A&&g<=ae.CODE_POINTS.LATIN_SMALL_Z}function Ml(g){return a0t(g)||iG(g)}function kz(g){return Ml(g)||uB(g)}function hwe(g){return g>=ae.CODE_POINTS.LATIN_CAPITAL_A&&g<=ae.CODE_POINTS.LATIN_CAPITAL_F}function mwe(g){return g>=ae.CODE_POINTS.LATIN_SMALL_A&&g<=ae.CODE_POINTS.LATIN_SMALL_F}function s0t(g){return uB(g)||hwe(g)||mwe(g)}function SR(g){return g+32}function fwe(g){return g===ae.CODE_POINTS.SPACE||g===ae.CODE_POINTS.LINE_FEED||g===ae.CODE_POINTS.TABULATION||g===ae.CODE_POINTS.FORM_FEED}function l0t(g){return g===ae.CODE_POINTS.EQUALS_SIGN||kz(g)}function iCe(g){return fwe(g)||g===ae.CODE_POINTS.SOLIDUS||g===ae.CODE_POINTS.GREATER_THAN_SIGN}let c0t=function(){function g(e,I){i0t(this,g),this.options=e,this.handler=I,this.paused=!1,this.inLoop=!1,this.inForeignNode=!1,this.lastStartTagName="",this.active=!1,this.state=be.DATA,this.returnState=be.DATA,this.charRefCode=-1,this.consumedAfterSnapshot=-1,this.currentCharacterToken=null,this.currentToken=null,this.currentAttr={name:"",value:""},this.preprocessor=new o0t.Preprocessor(I),this.currentLocation=this.getCurrentLocation(-1)}return n0t(g,[{key:"_err",value:function(I){var i,n;(n=(i=this.handler).onParseError)===null||n===void 0||n.call(i,this.preprocessor.getError(I))}},{key:"getCurrentLocation",value:function(I){return this.options.sourceCodeLocationInfo?{startLine:this.preprocessor.line,startCol:this.preprocessor.col-I,startOffset:this.preprocessor.offset-I,endLine:-1,endCol:-1,endOffset:-1}:null}},{key:"_runParsingLoop",value:function(){if(!this.inLoop){for(this.inLoop=!0;this.active&&!this.paused;){this.consumedAfterSnapshot=0;const I=this._consume();this._ensureHibernation()||this._callState(I)}this.inLoop=!1}}},{key:"pause",value:function(){this.paused=!0}},{key:"resume",value:function(I){if(!this.paused)throw new Error("Parser was already resumed");this.paused=!1,!this.inLoop&&(this._runParsingLoop(),this.paused||I==null||I())}},{key:"write",value:function(I,i,n){this.active=!0,this.preprocessor.write(I,i),this._runParsingLoop(),this.paused||n==null||n()}},{key:"insertHtmlAtCurrentPos",value:function(I){this.active=!0,this.preprocessor.insertHtmlAtCurrentPos(I),this._runParsingLoop()}},{key:"_ensureHibernation",value:function(){return this.preprocessor.endOfChunkHit?(this._unconsume(this.consumedAfterSnapshot),this.active=!1,!0):!1}},{key:"_consume",value:function(){return this.consumedAfterSnapshot++,this.preprocessor.advance()}},{key:"_unconsume",value:function(I){this.consumedAfterSnapshot-=I,this.preprocessor.retreat(I)}},{key:"_reconsumeInState",value:function(I,i){this.state=I,this._callState(i)}},{key:"_advanceBy",value:function(I){this.consumedAfterSnapshot+=I;for(let i=0;i0&&this._err($e.ERR.endTagWithAttributes),I.selfClosing&&this._err($e.ERR.endTagWithTrailingSolidus),this.handler.onEndTag(I)),this.preprocessor.dropParsedChunk()}},{key:"emitCurrentComment",value:function(I){this.prepareToken(I),this.handler.onComment(I),this.preprocessor.dropParsedChunk()}},{key:"emitCurrentDoctype",value:function(I){this.prepareToken(I),this.handler.onDoctype(I),this.preprocessor.dropParsedChunk()}},{key:"_emitCurrentCharacterToken",value:function(I){if(this.currentCharacterToken){switch(I&&this.currentCharacterToken.location&&(this.currentCharacterToken.location.endLine=I.startLine,this.currentCharacterToken.location.endCol=I.startCol,this.currentCharacterToken.location.endOffset=I.startOffset),this.currentCharacterToken.type){case pC.TokenType.CHARACTER:{this.handler.onCharacter(this.currentCharacterToken);break}case pC.TokenType.NULL_CHARACTER:{this.handler.onNullCharacter(this.currentCharacterToken);break}case pC.TokenType.WHITESPACE_CHARACTER:{this.handler.onWhitespaceCharacter(this.currentCharacterToken);break}}this.currentCharacterToken=null}}},{key:"_emitEOFToken",value:function(){const I=this.getCurrentLocation(0);I&&(I.endLine=I.startLine,I.endCol=I.startCol,I.endOffset=I.startOffset),this._emitCurrentCharacterToken(I),this.handler.onEof({type:pC.TokenType.EOF,location:I}),this.active=!1}},{key:"_appendCharToCurrentCharacterToken",value:function(I,i){if(this.currentCharacterToken)if(this.currentCharacterToken.type!==I)this.currentLocation=this.getCurrentLocation(0),this._emitCurrentCharacterToken(this.currentLocation),this.preprocessor.dropParsedChunk();else{this.currentCharacterToken.chars+=i;return}this._createCharacterToken(I,i)}},{key:"_emitCodePoint",value:function(I){const i=fwe(I)?pC.TokenType.WHITESPACE_CHARACTER:I===ae.CODE_POINTS.NULL?pC.TokenType.NULL_CHARACTER:pC.TokenType.CHARACTER;this._appendCharToCurrentCharacterToken(i,String.fromCodePoint(I))}},{key:"_emitChars",value:function(I){this._appendCharToCurrentCharacterToken(pC.TokenType.CHARACTER,I)}},{key:"_matchNamedCharacterReference",value:function(I){let i=null,n=0,C=!1;for(let r=0,o=XA.htmlDecodeTree[0];r>=0&&(r=(0,XA.determineBranch)(XA.htmlDecodeTree,o,r+1,I),!(r<0));I=this._consume()){n+=1,o=XA.htmlDecodeTree[r];const A=o&XA.BinTrieFlags.VALUE_LENGTH;if(A){const s=(A>>14)-1;if(I!==ae.CODE_POINTS.SEMICOLON&&this._isCharacterReferenceInAttribute()&&l0t(this.preprocessor.peek(1))?(i=[ae.CODE_POINTS.AMPERSAND],r+=s):(i=s===0?[XA.htmlDecodeTree[r]&~XA.BinTrieFlags.VALUE_LENGTH]:s===1?[XA.htmlDecodeTree[++r]]:[XA.htmlDecodeTree[++r],XA.htmlDecodeTree[++r]],n=0,C=I!==ae.CODE_POINTS.SEMICOLON),s===0){this._consume();break}}}return this._unconsume(n),C&&!this.preprocessor.endOfChunkHit&&this._err($e.ERR.missingSemicolonAfterCharacterReference),this._unconsume(1),i}},{key:"_isCharacterReferenceInAttribute",value:function(){return this.returnState===be.ATTRIBUTE_VALUE_DOUBLE_QUOTED||this.returnState===be.ATTRIBUTE_VALUE_SINGLE_QUOTED||this.returnState===be.ATTRIBUTE_VALUE_UNQUOTED}},{key:"_flushCodePointConsumedAsCharacterReference",value:function(I){this._isCharacterReferenceInAttribute()?this.currentAttr.value+=String.fromCodePoint(I):this._emitCodePoint(I)}},{key:"_callState",value:function(I){switch(this.state){case be.DATA:{this._stateData(I);break}case be.RCDATA:{this._stateRcdata(I);break}case be.RAWTEXT:{this._stateRawtext(I);break}case be.SCRIPT_DATA:{this._stateScriptData(I);break}case be.PLAINTEXT:{this._statePlaintext(I);break}case be.TAG_OPEN:{this._stateTagOpen(I);break}case be.END_TAG_OPEN:{this._stateEndTagOpen(I);break}case be.TAG_NAME:{this._stateTagName(I);break}case be.RCDATA_LESS_THAN_SIGN:{this._stateRcdataLessThanSign(I);break}case be.RCDATA_END_TAG_OPEN:{this._stateRcdataEndTagOpen(I);break}case be.RCDATA_END_TAG_NAME:{this._stateRcdataEndTagName(I);break}case be.RAWTEXT_LESS_THAN_SIGN:{this._stateRawtextLessThanSign(I);break}case be.RAWTEXT_END_TAG_OPEN:{this._stateRawtextEndTagOpen(I);break}case be.RAWTEXT_END_TAG_NAME:{this._stateRawtextEndTagName(I);break}case be.SCRIPT_DATA_LESS_THAN_SIGN:{this._stateScriptDataLessThanSign(I);break}case be.SCRIPT_DATA_END_TAG_OPEN:{this._stateScriptDataEndTagOpen(I);break}case be.SCRIPT_DATA_END_TAG_NAME:{this._stateScriptDataEndTagName(I);break}case be.SCRIPT_DATA_ESCAPE_START:{this._stateScriptDataEscapeStart(I);break}case be.SCRIPT_DATA_ESCAPE_START_DASH:{this._stateScriptDataEscapeStartDash(I);break}case be.SCRIPT_DATA_ESCAPED:{this._stateScriptDataEscaped(I);break}case be.SCRIPT_DATA_ESCAPED_DASH:{this._stateScriptDataEscapedDash(I);break}case be.SCRIPT_DATA_ESCAPED_DASH_DASH:{this._stateScriptDataEscapedDashDash(I);break}case be.SCRIPT_DATA_ESCAPED_LESS_THAN_SIGN:{this._stateScriptDataEscapedLessThanSign(I);break}case be.SCRIPT_DATA_ESCAPED_END_TAG_OPEN:{this._stateScriptDataEscapedEndTagOpen(I);break}case be.SCRIPT_DATA_ESCAPED_END_TAG_NAME:{this._stateScriptDataEscapedEndTagName(I);break}case be.SCRIPT_DATA_DOUBLE_ESCAPE_START:{this._stateScriptDataDoubleEscapeStart(I);break}case be.SCRIPT_DATA_DOUBLE_ESCAPED:{this._stateScriptDataDoubleEscaped(I);break}case be.SCRIPT_DATA_DOUBLE_ESCAPED_DASH:{this._stateScriptDataDoubleEscapedDash(I);break}case be.SCRIPT_DATA_DOUBLE_ESCAPED_DASH_DASH:{this._stateScriptDataDoubleEscapedDashDash(I);break}case be.SCRIPT_DATA_DOUBLE_ESCAPED_LESS_THAN_SIGN:{this._stateScriptDataDoubleEscapedLessThanSign(I);break}case be.SCRIPT_DATA_DOUBLE_ESCAPE_END:{this._stateScriptDataDoubleEscapeEnd(I);break}case be.BEFORE_ATTRIBUTE_NAME:{this._stateBeforeAttributeName(I);break}case be.ATTRIBUTE_NAME:{this._stateAttributeName(I);break}case be.AFTER_ATTRIBUTE_NAME:{this._stateAfterAttributeName(I);break}case be.BEFORE_ATTRIBUTE_VALUE:{this._stateBeforeAttributeValue(I);break}case be.ATTRIBUTE_VALUE_DOUBLE_QUOTED:{this._stateAttributeValueDoubleQuoted(I);break}case be.ATTRIBUTE_VALUE_SINGLE_QUOTED:{this._stateAttributeValueSingleQuoted(I);break}case be.ATTRIBUTE_VALUE_UNQUOTED:{this._stateAttributeValueUnquoted(I);break}case be.AFTER_ATTRIBUTE_VALUE_QUOTED:{this._stateAfterAttributeValueQuoted(I);break}case be.SELF_CLOSING_START_TAG:{this._stateSelfClosingStartTag(I);break}case be.BOGUS_COMMENT:{this._stateBogusComment(I);break}case be.MARKUP_DECLARATION_OPEN:{this._stateMarkupDeclarationOpen(I);break}case be.COMMENT_START:{this._stateCommentStart(I);break}case be.COMMENT_START_DASH:{this._stateCommentStartDash(I);break}case be.COMMENT:{this._stateComment(I);break}case be.COMMENT_LESS_THAN_SIGN:{this._stateCommentLessThanSign(I);break}case be.COMMENT_LESS_THAN_SIGN_BANG:{this._stateCommentLessThanSignBang(I);break}case be.COMMENT_LESS_THAN_SIGN_BANG_DASH:{this._stateCommentLessThanSignBangDash(I);break}case be.COMMENT_LESS_THAN_SIGN_BANG_DASH_DASH:{this._stateCommentLessThanSignBangDashDash(I);break}case be.COMMENT_END_DASH:{this._stateCommentEndDash(I);break}case be.COMMENT_END:{this._stateCommentEnd(I);break}case be.COMMENT_END_BANG:{this._stateCommentEndBang(I);break}case be.DOCTYPE:{this._stateDoctype(I);break}case be.BEFORE_DOCTYPE_NAME:{this._stateBeforeDoctypeName(I);break}case be.DOCTYPE_NAME:{this._stateDoctypeName(I);break}case be.AFTER_DOCTYPE_NAME:{this._stateAfterDoctypeName(I);break}case be.AFTER_DOCTYPE_PUBLIC_KEYWORD:{this._stateAfterDoctypePublicKeyword(I);break}case be.BEFORE_DOCTYPE_PUBLIC_IDENTIFIER:{this._stateBeforeDoctypePublicIdentifier(I);break}case be.DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED:{this._stateDoctypePublicIdentifierDoubleQuoted(I);break}case be.DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED:{this._stateDoctypePublicIdentifierSingleQuoted(I);break}case be.AFTER_DOCTYPE_PUBLIC_IDENTIFIER:{this._stateAfterDoctypePublicIdentifier(I);break}case be.BETWEEN_DOCTYPE_PUBLIC_AND_SYSTEM_IDENTIFIERS:{this._stateBetweenDoctypePublicAndSystemIdentifiers(I);break}case be.AFTER_DOCTYPE_SYSTEM_KEYWORD:{this._stateAfterDoctypeSystemKeyword(I);break}case be.BEFORE_DOCTYPE_SYSTEM_IDENTIFIER:{this._stateBeforeDoctypeSystemIdentifier(I);break}case be.DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED:{this._stateDoctypeSystemIdentifierDoubleQuoted(I);break}case be.DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED:{this._stateDoctypeSystemIdentifierSingleQuoted(I);break}case be.AFTER_DOCTYPE_SYSTEM_IDENTIFIER:{this._stateAfterDoctypeSystemIdentifier(I);break}case be.BOGUS_DOCTYPE:{this._stateBogusDoctype(I);break}case be.CDATA_SECTION:{this._stateCdataSection(I);break}case be.CDATA_SECTION_BRACKET:{this._stateCdataSectionBracket(I);break}case be.CDATA_SECTION_END:{this._stateCdataSectionEnd(I);break}case be.CHARACTER_REFERENCE:{this._stateCharacterReference(I);break}case be.NAMED_CHARACTER_REFERENCE:{this._stateNamedCharacterReference(I);break}case be.AMBIGUOUS_AMPERSAND:{this._stateAmbiguousAmpersand(I);break}case be.NUMERIC_CHARACTER_REFERENCE:{this._stateNumericCharacterReference(I);break}case be.HEXADEMICAL_CHARACTER_REFERENCE_START:{this._stateHexademicalCharacterReferenceStart(I);break}case be.HEXADEMICAL_CHARACTER_REFERENCE:{this._stateHexademicalCharacterReference(I);break}case be.DECIMAL_CHARACTER_REFERENCE:{this._stateDecimalCharacterReference(I);break}case be.NUMERIC_CHARACTER_REFERENCE_END:{this._stateNumericCharacterReferenceEnd(I);break}default:throw new Error("Unknown state")}}},{key:"_stateData",value:function(I){switch(I){case ae.CODE_POINTS.LESS_THAN_SIGN:{this.state=be.TAG_OPEN;break}case ae.CODE_POINTS.AMPERSAND:{this.returnState=be.DATA,this.state=be.CHARACTER_REFERENCE;break}case ae.CODE_POINTS.NULL:{this._err($e.ERR.unexpectedNullCharacter),this._emitCodePoint(I);break}case ae.CODE_POINTS.EOF:{this._emitEOFToken();break}default:this._emitCodePoint(I)}}},{key:"_stateRcdata",value:function(I){switch(I){case ae.CODE_POINTS.AMPERSAND:{this.returnState=be.RCDATA,this.state=be.CHARACTER_REFERENCE;break}case ae.CODE_POINTS.LESS_THAN_SIGN:{this.state=be.RCDATA_LESS_THAN_SIGN;break}case ae.CODE_POINTS.NULL:{this._err($e.ERR.unexpectedNullCharacter),this._emitChars(ae.REPLACEMENT_CHARACTER);break}case ae.CODE_POINTS.EOF:{this._emitEOFToken();break}default:this._emitCodePoint(I)}}},{key:"_stateRawtext",value:function(I){switch(I){case ae.CODE_POINTS.LESS_THAN_SIGN:{this.state=be.RAWTEXT_LESS_THAN_SIGN;break}case ae.CODE_POINTS.NULL:{this._err($e.ERR.unexpectedNullCharacter),this._emitChars(ae.REPLACEMENT_CHARACTER);break}case ae.CODE_POINTS.EOF:{this._emitEOFToken();break}default:this._emitCodePoint(I)}}},{key:"_stateScriptData",value:function(I){switch(I){case ae.CODE_POINTS.LESS_THAN_SIGN:{this.state=be.SCRIPT_DATA_LESS_THAN_SIGN;break}case ae.CODE_POINTS.NULL:{this._err($e.ERR.unexpectedNullCharacter),this._emitChars(ae.REPLACEMENT_CHARACTER);break}case ae.CODE_POINTS.EOF:{this._emitEOFToken();break}default:this._emitCodePoint(I)}}},{key:"_statePlaintext",value:function(I){switch(I){case ae.CODE_POINTS.NULL:{this._err($e.ERR.unexpectedNullCharacter),this._emitChars(ae.REPLACEMENT_CHARACTER);break}case ae.CODE_POINTS.EOF:{this._emitEOFToken();break}default:this._emitCodePoint(I)}}},{key:"_stateTagOpen",value:function(I){if(Ml(I))this._createStartTagToken(),this.state=be.TAG_NAME,this._stateTagName(I);else switch(I){case ae.CODE_POINTS.EXCLAMATION_MARK:{this.state=be.MARKUP_DECLARATION_OPEN;break}case ae.CODE_POINTS.SOLIDUS:{this.state=be.END_TAG_OPEN;break}case ae.CODE_POINTS.QUESTION_MARK:{this._err($e.ERR.unexpectedQuestionMarkInsteadOfTagName),this._createCommentToken(1),this.state=be.BOGUS_COMMENT,this._stateBogusComment(I);break}case ae.CODE_POINTS.EOF:{this._err($e.ERR.eofBeforeTagName),this._emitChars("<"),this._emitEOFToken();break}default:this._err($e.ERR.invalidFirstCharacterOfTagName),this._emitChars("<"),this.state=be.DATA,this._stateData(I)}}},{key:"_stateEndTagOpen",value:function(I){if(Ml(I))this._createEndTagToken(),this.state=be.TAG_NAME,this._stateTagName(I);else switch(I){case ae.CODE_POINTS.GREATER_THAN_SIGN:{this._err($e.ERR.missingEndTagName),this.state=be.DATA;break}case ae.CODE_POINTS.EOF:{this._err($e.ERR.eofBeforeTagName),this._emitChars("");break}case ae.CODE_POINTS.NULL:{this._err($e.ERR.unexpectedNullCharacter),this.state=be.SCRIPT_DATA_ESCAPED,this._emitChars(ae.REPLACEMENT_CHARACTER);break}case ae.CODE_POINTS.EOF:{this._err($e.ERR.eofInScriptHtmlCommentLikeText),this._emitEOFToken();break}default:this.state=be.SCRIPT_DATA_ESCAPED,this._emitCodePoint(I)}}},{key:"_stateScriptDataEscapedLessThanSign",value:function(I){I===ae.CODE_POINTS.SOLIDUS?this.state=be.SCRIPT_DATA_ESCAPED_END_TAG_OPEN:Ml(I)?(this._emitChars("<"),this.state=be.SCRIPT_DATA_DOUBLE_ESCAPE_START,this._stateScriptDataDoubleEscapeStart(I)):(this._emitChars("<"),this.state=be.SCRIPT_DATA_ESCAPED,this._stateScriptDataEscaped(I))}},{key:"_stateScriptDataEscapedEndTagOpen",value:function(I){Ml(I)?(this.state=be.SCRIPT_DATA_ESCAPED_END_TAG_NAME,this._stateScriptDataEscapedEndTagName(I)):(this._emitChars("");break}case ae.CODE_POINTS.NULL:{this._err($e.ERR.unexpectedNullCharacter),this.state=be.SCRIPT_DATA_DOUBLE_ESCAPED,this._emitChars(ae.REPLACEMENT_CHARACTER);break}case ae.CODE_POINTS.EOF:{this._err($e.ERR.eofInScriptHtmlCommentLikeText),this._emitEOFToken();break}default:this.state=be.SCRIPT_DATA_DOUBLE_ESCAPED,this._emitCodePoint(I)}}},{key:"_stateScriptDataDoubleEscapedLessThanSign",value:function(I){I===ae.CODE_POINTS.SOLIDUS?(this.state=be.SCRIPT_DATA_DOUBLE_ESCAPE_END,this._emitChars("/")):(this.state=be.SCRIPT_DATA_DOUBLE_ESCAPED,this._stateScriptDataDoubleEscaped(I))}},{key:"_stateScriptDataDoubleEscapeEnd",value:function(I){if(this.preprocessor.startsWith(ae.SEQUENCES.SCRIPT,!1)&&iCe(this.preprocessor.peek(ae.SEQUENCES.SCRIPT.length))){this._emitCodePoint(I);for(let i=0;i1114111)this._err($e.ERR.characterReferenceOutsideUnicodeRange),this.charRefCode=ae.CODE_POINTS.REPLACEMENT_CHARACTER;else if((0,ae.isSurrogate)(this.charRefCode))this._err($e.ERR.surrogateCharacterReference),this.charRefCode=ae.CODE_POINTS.REPLACEMENT_CHARACTER;else if((0,ae.isUndefinedCodePoint)(this.charRefCode))this._err($e.ERR.noncharacterCharacterReference);else if((0,ae.isControlCodePoint)(this.charRefCode)||this.charRefCode===ae.CODE_POINTS.CARRIAGE_RETURN){this._err($e.ERR.controlCharacterReference);const i=A0t.get(this.charRefCode);i!==void 0&&(this.charRefCode=i)}this._flushCodePointConsumedAsCharacterReference(this.charRefCode),this._reconsumeInState(this.returnState,I)}}]),g}();yh.Tokenizer=c0t;var Hk={};function u0t(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function nCe(g,e){for(var I=0;I0&&this._isInTemplate()&&this.tmplCount--,this.stackTop--,this._updateCurrentElement(),this.handler.onItemPop(I,!0)}},{key:"replace",value:function(I,i){const n=this._indexOf(I);this.items[n]=i,n===this.stackTop&&(this.current=i)}},{key:"insertAfter",value:function(I,i,n){const C=this._indexOf(I)+1;this.items.splice(C,0,i),this.tagIDs.splice(C,0,n),this.stackTop++,C===this.stackTop&&this._updateCurrentElement(),this.handler.onItemPush(this.current,this.currentTagId,C===this.stackTop)}},{key:"popUntilTagNamePopped",value:function(I){let i=this.stackTop+1;do i=this.tagIDs.lastIndexOf(I,i-1);while(i>0&&this.treeAdapter.getNamespaceURI(this.items[i])!==It.NS.HTML);this.shortenToLength(i<0?0:i)}},{key:"shortenToLength",value:function(I){for(;this.stackTop>=I;){const i=this.current;this.tmplCount>0&&this._isInTemplate()&&(this.tmplCount-=1),this.stackTop--,this._updateCurrentElement(),this.handler.onItemPop(i,this.stackTop=0;n--)if(I.includes(this.tagIDs[n])&&this.treeAdapter.getNamespaceURI(this.items[n])===i)return n;return-1}},{key:"clearBackTo",value:function(I,i){const n=this._indexOfTagNames(I,i);this.shortenToLength(n+1)}},{key:"clearBackToTableContext",value:function(){this.clearBackTo(y0t,It.NS.HTML)}},{key:"clearBackToTableBodyContext",value:function(){this.clearBackTo(b0t,It.NS.HTML)}},{key:"clearBackToTableRowContext",value:function(){this.clearBackTo(p0t,It.NS.HTML)}},{key:"remove",value:function(I){const i=this._indexOf(I);i>=0&&(i===this.stackTop?this.pop():(this.items.splice(i,1),this.tagIDs.splice(i,1),this.stackTop--,this._updateCurrentElement(),this.handler.onItemPop(I,!1)))}},{key:"tryPeekProperlyNestedBodyElement",value:function(){return this.stackTop>=1&&this.tagIDs[1]===It.TAG_ID.BODY?this.items[1]:null}},{key:"contains",value:function(I){return this._indexOf(I)>-1}},{key:"getCommonAncestor",value:function(I){const i=this._indexOf(I)-1;return i>=0?this.items[i]:null}},{key:"isRootHtmlElementCurrent",value:function(){return this.stackTop===0&&this.tagIDs[0]===It.TAG_ID.HTML}},{key:"hasInScope",value:function(I){for(let i=this.stackTop;i>=0;i--){const n=this.tagIDs[i],C=this.treeAdapter.getNamespaceURI(this.items[i]);if(n===I&&C===It.NS.HTML)return!0;if(wR.get(n)===C)return!1}return!0}},{key:"hasNumberedHeaderInScope",value:function(){for(let I=this.stackTop;I>=0;I--){const i=this.tagIDs[I],n=this.treeAdapter.getNamespaceURI(this.items[I]);if((0,It.isNumberedHeader)(i)&&n===It.NS.HTML)return!0;if(wR.get(i)===n)return!1}return!0}},{key:"hasInListItemScope",value:function(I){for(let i=this.stackTop;i>=0;i--){const n=this.tagIDs[i],C=this.treeAdapter.getNamespaceURI(this.items[i]);if(n===I&&C===It.NS.HTML)return!0;if((n===It.TAG_ID.UL||n===It.TAG_ID.OL)&&C===It.NS.HTML||wR.get(n)===C)return!1}return!0}},{key:"hasInButtonScope",value:function(I){for(let i=this.stackTop;i>=0;i--){const n=this.tagIDs[i],C=this.treeAdapter.getNamespaceURI(this.items[i]);if(n===I&&C===It.NS.HTML)return!0;if(n===It.TAG_ID.BUTTON&&C===It.NS.HTML||wR.get(n)===C)return!1}return!0}},{key:"hasInTableScope",value:function(I){for(let i=this.stackTop;i>=0;i--){const n=this.tagIDs[i];if(this.treeAdapter.getNamespaceURI(this.items[i])===It.NS.HTML){if(n===I)return!0;if(n===It.TAG_ID.TABLE||n===It.TAG_ID.TEMPLATE||n===It.TAG_ID.HTML)return!1}}return!0}},{key:"hasTableBodyContextInTableScope",value:function(){for(let I=this.stackTop;I>=0;I--){const i=this.tagIDs[I];if(this.treeAdapter.getNamespaceURI(this.items[I])===It.NS.HTML){if(i===It.TAG_ID.TBODY||i===It.TAG_ID.THEAD||i===It.TAG_ID.TFOOT)return!0;if(i===It.TAG_ID.TABLE||i===It.TAG_ID.HTML)return!1}}return!0}},{key:"hasInSelectScope",value:function(I){for(let i=this.stackTop;i>=0;i--){const n=this.tagIDs[i];if(this.treeAdapter.getNamespaceURI(this.items[i])===It.NS.HTML){if(n===I)return!0;if(n!==It.TAG_ID.OPTION&&n!==It.TAG_ID.OPTGROUP)return!1}}return!0}},{key:"generateImpliedEndTags",value:function(){for(;pwe.has(this.currentTagId);)this.pop()}},{key:"generateImpliedEndTagsThoroughly",value:function(){for(;CCe.has(this.currentTagId);)this.pop()}},{key:"generateImpliedEndTagsWithExclusion",value:function(I){for(;this.currentTagId!==I&&CCe.has(this.currentTagId);)this.pop()}}]),g}();Hk.OpenElementStack=G0t;var bwe={};(function(g){function e(a,l){if(!(a instanceof l))throw new TypeError("Cannot call a class as a function")}function I(a,l){for(var c=0;c[f.name,f.value]));let m=0;for(let f=0;fh.get(p.name)===p.value)&&(m+=1,m>=r&&this.entries.splice(b.idx,1))}}},{key:"insertMarker",value:function(){this.entries.unshift(A)}},{key:"pushElement",value:function(c,u){this._ensureNoahArkCondition(c),this.entries.unshift({type:o.Element,element:c,token:u})}},{key:"insertElementAfterBookmark",value:function(c,u){const d=this.entries.indexOf(this.bookmark);this.entries.splice(d,0,{type:o.Element,element:c,token:u})}},{key:"removeEntry",value:function(c){const u=this.entries.indexOf(c);u>=0&&this.entries.splice(u,1)}},{key:"clearToLastMarker",value:function(){const c=this.entries.indexOf(A);c>=0?this.entries.splice(0,c+1):this.entries.length=0}},{key:"getElementEntryInScopeWithTagName",value:function(c){const u=this.entries.find(d=>d.type===o.Marker||this.treeAdapter.getTagName(d.element)===c);return u&&u.type===o.Element?u:null}},{key:"getElementEntry",value:function(c){return this.entries.find(u=>u.type===o.Element&&u.element===c)}}]),a}();g.FormattingElementList=s})(bwe);var Tk={};(function(g){Object.defineProperty(g,"__esModule",{value:!0}),g.defaultTreeAdapter=void 0;const e=hl;function I(i){return{nodeName:"#text",value:i,parentNode:null}}g.defaultTreeAdapter={createDocument(){return{nodeName:"#document",mode:e.DOCUMENT_MODE.NO_QUIRKS,childNodes:[]}},createDocumentFragment(){return{nodeName:"#document-fragment",childNodes:[]}},createElement(i,n,C){return{nodeName:i,tagName:i,attrs:C,namespaceURI:n,childNodes:[],parentNode:null}},createCommentNode(i){return{nodeName:"#comment",data:i,parentNode:null}},appendChild(i,n){i.childNodes.push(n),n.parentNode=i},insertBefore(i,n,C){const r=i.childNodes.indexOf(C);i.childNodes.splice(r,0,n),n.parentNode=i},setTemplateContent(i,n){i.content=n},getTemplateContent(i){return i.content},setDocumentType(i,n,C,r){const o=i.childNodes.find(A=>A.nodeName==="#documentType");if(o)o.name=n,o.publicId=C,o.systemId=r;else{const A={nodeName:"#documentType",name:n,publicId:C,systemId:r,parentNode:null};g.defaultTreeAdapter.appendChild(i,A)}},setDocumentMode(i,n){i.mode=n},getDocumentMode(i){return i.mode},detachNode(i){if(i.parentNode){const n=i.parentNode.childNodes.indexOf(i);i.parentNode.childNodes.splice(n,1),i.parentNode=null}},insertText(i,n){if(i.childNodes.length>0){const C=i.childNodes[i.childNodes.length-1];if(g.defaultTreeAdapter.isTextNode(C)){C.value+=n;return}}g.defaultTreeAdapter.appendChild(i,I(n))},insertTextBefore(i,n,C){const r=i.childNodes[i.childNodes.indexOf(C)-1];r&&g.defaultTreeAdapter.isTextNode(r)?r.value+=n:g.defaultTreeAdapter.insertBefore(i,I(n),C)},adoptAttributes(i,n){const C=new Set(i.attrs.map(r=>r.name));for(let r=0;rg.startsWith(I))}function R0t(g){return g.name===ywe&&g.publicId===null&&(g.systemId===null||g.systemId===B0t)}n0.isConforming=R0t;function W0t(g){if(g.name!==ywe)return ef.DOCUMENT_MODE.QUIRKS;const{systemId:e}=g;if(e&&e.toLowerCase()===v0t)return ef.DOCUMENT_MODE.QUIRKS;let{publicId:I}=g;if(I!==null){if(I=I.toLowerCase(),w0t.has(I))return ef.DOCUMENT_MODE.QUIRKS;let i=e===null?S0t:Zwe;if(rCe(I,i))return ef.DOCUMENT_MODE.QUIRKS;if(i=e===null?Gwe:V0t,rCe(I,i))return ef.DOCUMENT_MODE.LIMITED_QUIRKS}return ef.DOCUMENT_MODE.NO_QUIRKS}n0.getDocumentMode=W0t;var mj={};(function(g){Object.defineProperty(g,"__esModule",{value:!0}),g.isIntegrationPoint=g.adjustTokenSVGTagName=g.adjustTokenXMLAttrs=g.adjustTokenSVGAttrs=g.adjustTokenMathMLAttrs=g.causesExit=g.SVG_TAG_NAMES_ADJUSTMENT_MAP=void 0;const e=hl,I={TEXT_HTML:"text/html",APPLICATION_XML:"application/xhtml+xml"},i="definitionurl",n="definitionURL",C=new Map(["attributeName","attributeType","baseFrequency","baseProfile","calcMode","clipPathUnits","diffuseConstant","edgeMode","filterUnits","glyphRef","gradientTransform","gradientUnits","kernelMatrix","kernelUnitLength","keyPoints","keySplines","keyTimes","lengthAdjust","limitingConeAngle","markerHeight","markerUnits","markerWidth","maskContentUnits","maskUnits","numOctaves","pathLength","patternContentUnits","patternTransform","patternUnits","pointsAtX","pointsAtY","pointsAtZ","preserveAlpha","preserveAspectRatio","primitiveUnits","refX","refY","repeatCount","repeatDur","requiredExtensions","requiredFeatures","specularConstant","specularExponent","spreadMethod","startOffset","stdDeviation","stitchTiles","surfaceScale","systemLanguage","tableValues","targetX","targetY","textLength","viewBox","viewTarget","xChannelSelector","yChannelSelector","zoomAndPan"].map(m=>[m.toLowerCase(),m])),r=new Map([["xlink:actuate",{prefix:"xlink",name:"actuate",namespace:e.NS.XLINK}],["xlink:arcrole",{prefix:"xlink",name:"arcrole",namespace:e.NS.XLINK}],["xlink:href",{prefix:"xlink",name:"href",namespace:e.NS.XLINK}],["xlink:role",{prefix:"xlink",name:"role",namespace:e.NS.XLINK}],["xlink:show",{prefix:"xlink",name:"show",namespace:e.NS.XLINK}],["xlink:title",{prefix:"xlink",name:"title",namespace:e.NS.XLINK}],["xlink:type",{prefix:"xlink",name:"type",namespace:e.NS.XLINK}],["xml:base",{prefix:"xml",name:"base",namespace:e.NS.XML}],["xml:lang",{prefix:"xml",name:"lang",namespace:e.NS.XML}],["xml:space",{prefix:"xml",name:"space",namespace:e.NS.XML}],["xmlns",{prefix:"",name:"xmlns",namespace:e.NS.XMLNS}],["xmlns:xlink",{prefix:"xmlns",name:"xlink",namespace:e.NS.XMLNS}]]);g.SVG_TAG_NAMES_ADJUSTMENT_MAP=new Map(["altGlyph","altGlyphDef","altGlyphItem","animateColor","animateMotion","animateTransform","clipPath","feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feDistantLight","feFlood","feFuncA","feFuncB","feFuncG","feFuncR","feGaussianBlur","feImage","feMerge","feMergeNode","feMorphology","feOffset","fePointLight","feSpecularLighting","feSpotLight","feTile","feTurbulence","foreignObject","glyphRef","linearGradient","radialGradient","textPath"].map(m=>[m.toLowerCase(),m]));const o=new Set([e.TAG_ID.B,e.TAG_ID.BIG,e.TAG_ID.BLOCKQUOTE,e.TAG_ID.BODY,e.TAG_ID.BR,e.TAG_ID.CENTER,e.TAG_ID.CODE,e.TAG_ID.DD,e.TAG_ID.DIV,e.TAG_ID.DL,e.TAG_ID.DT,e.TAG_ID.EM,e.TAG_ID.EMBED,e.TAG_ID.H1,e.TAG_ID.H2,e.TAG_ID.H3,e.TAG_ID.H4,e.TAG_ID.H5,e.TAG_ID.H6,e.TAG_ID.HEAD,e.TAG_ID.HR,e.TAG_ID.I,e.TAG_ID.IMG,e.TAG_ID.LI,e.TAG_ID.LISTING,e.TAG_ID.MENU,e.TAG_ID.META,e.TAG_ID.NOBR,e.TAG_ID.OL,e.TAG_ID.P,e.TAG_ID.PRE,e.TAG_ID.RUBY,e.TAG_ID.S,e.TAG_ID.SMALL,e.TAG_ID.SPAN,e.TAG_ID.STRONG,e.TAG_ID.STRIKE,e.TAG_ID.SUB,e.TAG_ID.SUP,e.TAG_ID.TABLE,e.TAG_ID.TT,e.TAG_ID.U,e.TAG_ID.UL,e.TAG_ID.VAR]);function A(m){const f=m.tagID;return f===e.TAG_ID.FONT&&m.attrs.some(({name:p})=>p===e.ATTRS.COLOR||p===e.ATTRS.SIZE||p===e.ATTRS.FACE)||o.has(f)}g.causesExit=A;function s(m){for(let f=0;f0&&this._setContextModes(I,i)}},{key:"onItemPop",value:function(I,i){var n,C;if(this.options.sourceCodeLocationInfo&&this._setEndLocation(I,this.currentToken),(C=(n=this.treeAdapter).onItemPop)===null||C===void 0||C.call(n,I,this.openElements.current),i){let r,o;this.openElements.stackTop===0&&this.fragmentContext?(r=this.fragmentContext,o=this.fragmentContextID):{current:r,currentTagId:o}=this.openElements,this._setContextModes(r,o)}}},{key:"_setContextModes",value:function(I,i){const n=I===this.document||this.treeAdapter.getNamespaceURI(I)===z.NS.HTML;this.currentNotInHTML=!n,this.tokenizer.inForeignNode=!n&&!this._isIntegrationPoint(i,I)}},{key:"_switchToTextParsing",value:function(I,i){this._insertElement(I,z.NS.HTML),this.tokenizer.state=i,this.originalInsertionMode=this.insertionMode,this.insertionMode=Re.TEXT}},{key:"switchToPlaintextParsing",value:function(){this.insertionMode=Re.TEXT,this.originalInsertionMode=Re.IN_BODY,this.tokenizer.state=Un.TokenizerMode.PLAINTEXT}},{key:"_getAdjustedCurrentElement",value:function(){return this.openElements.stackTop===0&&this.fragmentContext?this.fragmentContext:this.openElements.current}},{key:"_findFormInFragmentContext",value:function(){let I=this.fragmentContext;for(;I;){if(this.treeAdapter.getTagName(I)===z.TAG_NAMES.FORM){this.formElement=I;break}I=this.treeAdapter.getParentNode(I)}}},{key:"_initTokenizerForFragmentParsing",value:function(){if(!(!this.fragmentContext||this.treeAdapter.getNamespaceURI(this.fragmentContext)!==z.NS.HTML))switch(this.fragmentContextID){case z.TAG_ID.TITLE:case z.TAG_ID.TEXTAREA:{this.tokenizer.state=Un.TokenizerMode.RCDATA;break}case z.TAG_ID.STYLE:case z.TAG_ID.XMP:case z.TAG_ID.IFRAME:case z.TAG_ID.NOEMBED:case z.TAG_ID.NOFRAMES:case z.TAG_ID.NOSCRIPT:{this.tokenizer.state=Un.TokenizerMode.RAWTEXT;break}case z.TAG_ID.SCRIPT:{this.tokenizer.state=Un.TokenizerMode.SCRIPT_DATA;break}case z.TAG_ID.PLAINTEXT:{this.tokenizer.state=Un.TokenizerMode.PLAINTEXT;break}}}},{key:"_setDocumentType",value:function(I){const i=I.name||"",n=I.publicId||"",C=I.systemId||"";if(this.treeAdapter.setDocumentType(this.document,i,n,C),I.location){const o=this.treeAdapter.getChildNodes(this.document).find(A=>this.treeAdapter.isDocumentTypeNode(A));o&&this.treeAdapter.setNodeSourceCodeLocation(o,I.location)}}},{key:"_attachElementToTree",value:function(I,i){if(this.options.sourceCodeLocationInfo){const n=i&&Object.assign(Object.assign({},i),{startTag:i});this.treeAdapter.setNodeSourceCodeLocation(I,n)}if(this._shouldFosterParentOnInsertion())this._fosterParentElement(I);else{const n=this.openElements.currentTmplContentOrNode;this.treeAdapter.appendChild(n,I)}}},{key:"_appendElement",value:function(I,i){const n=this.treeAdapter.createElement(I.tagName,i,I.attrs);this._attachElementToTree(n,I.location)}},{key:"_insertElement",value:function(I,i){const n=this.treeAdapter.createElement(I.tagName,i,I.attrs);this._attachElementToTree(n,I.location),this.openElements.push(n,I.tagID)}},{key:"_insertFakeElement",value:function(I,i){const n=this.treeAdapter.createElement(I,z.NS.HTML,[]);this._attachElementToTree(n,null),this.openElements.push(n,i)}},{key:"_insertTemplate",value:function(I){const i=this.treeAdapter.createElement(I.tagName,z.NS.HTML,I.attrs),n=this.treeAdapter.createDocumentFragment();this.treeAdapter.setTemplateContent(i,n),this._attachElementToTree(i,I.location),this.openElements.push(i,I.tagID),this.options.sourceCodeLocationInfo&&this.treeAdapter.setNodeSourceCodeLocation(n,null)}},{key:"_insertFakeRootElement",value:function(){const I=this.treeAdapter.createElement(z.TAG_NAMES.HTML,z.NS.HTML,[]);this.options.sourceCodeLocationInfo&&this.treeAdapter.setNodeSourceCodeLocation(I,null),this.treeAdapter.appendChild(this.openElements.current,I),this.openElements.push(I,z.TAG_ID.HTML)}},{key:"_appendCommentNode",value:function(I,i){const n=this.treeAdapter.createCommentNode(I.data);this.treeAdapter.appendChild(i,n),this.options.sourceCodeLocationInfo&&this.treeAdapter.setNodeSourceCodeLocation(n,I.location)}},{key:"_insertCharacters",value:function(I){let i,n;if(this._shouldFosterParentOnInsertion()?({parent:i,beforeElement:n}=this._findFosterParentingLocation(),n?this.treeAdapter.insertTextBefore(i,I.chars,n):this.treeAdapter.insertText(i,I.chars)):(i=this.openElements.currentTmplContentOrNode,this.treeAdapter.insertText(i,I.chars)),!I.location)return;const C=this.treeAdapter.getChildNodes(i),r=n?C.lastIndexOf(n):C.length,o=C[r-1];if(this.treeAdapter.getNodeSourceCodeLocation(o)){const{endLine:s,endCol:a,endOffset:l}=I.location;this.treeAdapter.updateNodeSourceCodeLocation(o,{endLine:s,endCol:a,endOffset:l})}else this.options.sourceCodeLocationInfo&&this.treeAdapter.setNodeSourceCodeLocation(o,I.location)}},{key:"_adoptNodes",value:function(I,i){for(let n=this.treeAdapter.getFirstChild(I);n;n=this.treeAdapter.getFirstChild(I))this.treeAdapter.detachNode(n),this.treeAdapter.appendChild(i,n)}},{key:"_setEndLocation",value:function(I,i){if(this.treeAdapter.getNodeSourceCodeLocation(I)&&i.location){const n=i.location,C=this.treeAdapter.getTagName(I),r=i.type===vi.TokenType.END_TAG&&C===i.tagName?{endTag:Object.assign({},n),endLine:n.endLine,endCol:n.endCol,endOffset:n.endOffset}:{endLine:n.startLine,endCol:n.startCol,endOffset:n.startOffset};this.treeAdapter.updateNodeSourceCodeLocation(I,r)}}},{key:"shouldProcessStartTagTokenInForeignContent",value:function(I){if(!this.currentNotInHTML)return!1;let i,n;return this.openElements.stackTop===0&&this.fragmentContext?(i=this.fragmentContext,n=this.fragmentContextID):{current:i,currentTagId:n}=this.openElements,I.tagID===z.TAG_ID.SVG&&this.treeAdapter.getTagName(i)===z.TAG_NAMES.ANNOTATION_XML&&this.treeAdapter.getNamespaceURI(i)===z.NS.MATHML?!1:this.tokenizer.inForeignNode||(I.tagID===z.TAG_ID.MGLYPH||I.tagID===z.TAG_ID.MALIGNMARK)&&!this._isIntegrationPoint(n,i,z.NS.HTML)}},{key:"_processToken",value:function(I){switch(I.type){case vi.TokenType.CHARACTER:{this.onCharacter(I);break}case vi.TokenType.NULL_CHARACTER:{this.onNullCharacter(I);break}case vi.TokenType.COMMENT:{this.onComment(I);break}case vi.TokenType.DOCTYPE:{this.onDoctype(I);break}case vi.TokenType.START_TAG:{this._processStartTag(I);break}case vi.TokenType.END_TAG:{this.onEndTag(I);break}case vi.TokenType.EOF:{this.onEof(I);break}case vi.TokenType.WHITESPACE_CHARACTER:{this.onWhitespaceCharacter(I);break}}}},{key:"_isIntegrationPoint",value:function(I,i,n){const C=this.treeAdapter.getNamespaceURI(i),r=this.treeAdapter.getAttrList(i);return QA.isIntegrationPoint(I,C,r,n)}},{key:"_reconstructActiveFormattingElements",value:function(){const I=this.activeFormattingElements.entries.length;if(I){const i=this.activeFormattingElements.entries.findIndex(C=>C.type===ACe.EntryType.Marker||this.openElements.contains(C.element)),n=i<0?I-1:i-1;for(let C=n;C>=0;C--){const r=this.activeFormattingElements.entries[C];this._insertElement(r.token,this.treeAdapter.getNamespaceURI(r.element)),r.element=this.openElements.current}}}},{key:"_closeTableCell",value:function(){this.openElements.generateImpliedEndTags(),this.openElements.popUntilTableCellPopped(),this.activeFormattingElements.clearToLastMarker(),this.insertionMode=Re.IN_ROW}},{key:"_closePElement",value:function(){this.openElements.generateImpliedEndTagsWithExclusion(z.TAG_ID.P),this.openElements.popUntilTagNamePopped(z.TAG_ID.P)}},{key:"_resetInsertionMode",value:function(){for(let I=this.openElements.stackTop;I>=0;I--)switch(I===0&&this.fragmentContext?this.fragmentContextID:this.openElements.tagIDs[I]){case z.TAG_ID.TR:{this.insertionMode=Re.IN_ROW;return}case z.TAG_ID.TBODY:case z.TAG_ID.THEAD:case z.TAG_ID.TFOOT:{this.insertionMode=Re.IN_TABLE_BODY;return}case z.TAG_ID.CAPTION:{this.insertionMode=Re.IN_CAPTION;return}case z.TAG_ID.COLGROUP:{this.insertionMode=Re.IN_COLUMN_GROUP;return}case z.TAG_ID.TABLE:{this.insertionMode=Re.IN_TABLE;return}case z.TAG_ID.BODY:{this.insertionMode=Re.IN_BODY;return}case z.TAG_ID.FRAMESET:{this.insertionMode=Re.IN_FRAMESET;return}case z.TAG_ID.SELECT:{this._resetInsertionModeForSelect(I);return}case z.TAG_ID.TEMPLATE:{this.insertionMode=this.tmplInsertionModeStack[0];return}case z.TAG_ID.HTML:{this.insertionMode=this.headElement?Re.AFTER_HEAD:Re.BEFORE_HEAD;return}case z.TAG_ID.TD:case z.TAG_ID.TH:{if(I>0){this.insertionMode=Re.IN_CELL;return}break}case z.TAG_ID.HEAD:{if(I>0){this.insertionMode=Re.IN_HEAD;return}break}}this.insertionMode=Re.IN_BODY}},{key:"_resetInsertionModeForSelect",value:function(I){if(I>0)for(let i=I-1;i>0;i--){const n=this.openElements.tagIDs[i];if(n===z.TAG_ID.TEMPLATE)break;if(n===z.TAG_ID.TABLE){this.insertionMode=Re.IN_SELECT_IN_TABLE;return}}this.insertionMode=Re.IN_SELECT}},{key:"_isElementCausesFosterParenting",value:function(I){return vwe.has(I)}},{key:"_shouldFosterParentOnInsertion",value:function(){return this.fosterParentingEnabled&&this._isElementCausesFosterParenting(this.openElements.currentTagId)}},{key:"_findFosterParentingLocation",value:function(){for(let I=this.openElements.stackTop;I>=0;I--){const i=this.openElements.items[I];switch(this.openElements.tagIDs[I]){case z.TAG_ID.TEMPLATE:{if(this.treeAdapter.getNamespaceURI(i)===z.NS.HTML)return{parent:this.treeAdapter.getTemplateContent(i),beforeElement:null};break}case z.TAG_ID.TABLE:{const n=this.treeAdapter.getParentNode(i);return n?{parent:n,beforeElement:i}:{parent:this.openElements.items[I-1],beforeElement:null}}}}return{parent:this.openElements.items[0],beforeElement:null}}},{key:"_fosterParentElement",value:function(I){const i=this._findFosterParentingLocation();i.beforeElement?this.treeAdapter.insertBefore(i.parent,I,i.beforeElement):this.treeAdapter.appendChild(i.parent,I)}},{key:"_isSpecialElement",value:function(I,i){const n=this.treeAdapter.getNamespaceURI(I);return z.SPECIAL_ELEMENTS[n].has(i)}},{key:"onCharacter",value:function(I){if(this.skipNextNewLine=!1,this.tokenizer.inForeignNode){mZt(this,I);return}switch(this.insertionMode){case Re.INITIAL:{lZ(this,I);break}case Re.BEFORE_HTML:{dB(this,I);break}case Re.BEFORE_HEAD:{hB(this,I);break}case Re.IN_HEAD:{mB(this,I);break}case Re.IN_HEAD_NO_SCRIPT:{fB(this,I);break}case Re.AFTER_HEAD:{pB(this,I);break}case Re.IN_BODY:case Re.IN_CAPTION:case Re.IN_CELL:case Re.IN_TEMPLATE:{wwe(this,I);break}case Re.TEXT:case Re.IN_SELECT:case Re.IN_SELECT_IN_TABLE:{this._insertCharacters(I);break}case Re.IN_TABLE:case Re.IN_TABLE_BODY:case Re.IN_ROW:{HD(this,I);break}case Re.IN_TABLE_TEXT:{Twe(this,I);break}case Re.IN_COLUMN_GROUP:{AH(this,I);break}case Re.AFTER_BODY:{aH(this,I);break}case Re.AFTER_AFTER_BODY:{cW(this,I);break}}}},{key:"onNullCharacter",value:function(I){if(this.skipNextNewLine=!1,this.tokenizer.inForeignNode){hZt(this,I);return}switch(this.insertionMode){case Re.INITIAL:{lZ(this,I);break}case Re.BEFORE_HTML:{dB(this,I);break}case Re.BEFORE_HEAD:{hB(this,I);break}case Re.IN_HEAD:{mB(this,I);break}case Re.IN_HEAD_NO_SCRIPT:{fB(this,I);break}case Re.AFTER_HEAD:{pB(this,I);break}case Re.TEXT:{this._insertCharacters(I);break}case Re.IN_TABLE:case Re.IN_TABLE_BODY:case Re.IN_ROW:{HD(this,I);break}case Re.IN_COLUMN_GROUP:{AH(this,I);break}case Re.AFTER_BODY:{aH(this,I);break}case Re.AFTER_AFTER_BODY:{cW(this,I);break}}}},{key:"onComment",value:function(I){if(this.skipNextNewLine=!1,this.currentNotInHTML){Yz(this,I);return}switch(this.insertionMode){case Re.INITIAL:case Re.BEFORE_HTML:case Re.BEFORE_HEAD:case Re.IN_HEAD:case Re.IN_HEAD_NO_SCRIPT:case Re.AFTER_HEAD:case Re.IN_BODY:case Re.IN_TABLE:case Re.IN_CAPTION:case Re.IN_COLUMN_GROUP:case Re.IN_TABLE_BODY:case Re.IN_ROW:case Re.IN_CELL:case Re.IN_SELECT:case Re.IN_SELECT_IN_TABLE:case Re.IN_TEMPLATE:case Re.IN_FRAMESET:case Re.AFTER_FRAMESET:{Yz(this,I);break}case Re.IN_TABLE_TEXT:{cZ(this,I);break}case Re.AFTER_BODY:{_0t(this,I);break}case Re.AFTER_AFTER_BODY:case Re.AFTER_AFTER_FRAMESET:{U0t(this,I);break}}}},{key:"onDoctype",value:function(I){switch(this.skipNextNewLine=!1,this.insertionMode){case Re.INITIAL:{Q0t(this,I);break}case Re.BEFORE_HEAD:case Re.IN_HEAD:case Re.IN_HEAD_NO_SCRIPT:case Re.AFTER_HEAD:{this._err(I,un.ERR.misplacedDoctype);break}case Re.IN_TABLE_TEXT:{cZ(this,I);break}}}},{key:"onStartTag",value:function(I){this.skipNextNewLine=!1,this.currentToken=I,this._processStartTag(I),I.selfClosing&&!I.ackSelfClosing&&this._err(I,un.ERR.nonVoidHtmlElementStartTagWithTrailingSolidus)}},{key:"_processStartTag",value:function(I){this.shouldProcessStartTagTokenInForeignContent(I)?fZt(this,I):this._startTagOutsideForeignContent(I)}},{key:"_startTagOutsideForeignContent",value:function(I){switch(this.insertionMode){case Re.INITIAL:{lZ(this,I);break}case Re.BEFORE_HTML:{j0t(this,I);break}case Re.BEFORE_HEAD:{q0t(this,I);break}case Re.IN_HEAD:{ZA(this,I);break}case Re.IN_HEAD_NO_SCRIPT:{gyt(this,I);break}case Re.AFTER_HEAD:{iyt(this,I);break}case Re.IN_BODY:{Fn(this,I);break}case Re.IN_TABLE:{C0(this,I);break}case Re.IN_TABLE_TEXT:{cZ(this,I);break}case Re.IN_CAPTION:{eZt(this,I);break}case Re.IN_COLUMN_GROUP:{bj(this,I);break}case Re.IN_TABLE_BODY:{Yk(this,I);break}case Re.IN_ROW:{Kk(this,I);break}case Re.IN_CELL:{IZt(this,I);break}case Re.IN_SELECT:{Ywe(this,I);break}case Re.IN_SELECT_IN_TABLE:{nZt(this,I);break}case Re.IN_TEMPLATE:{rZt(this,I);break}case Re.AFTER_BODY:{AZt(this,I);break}case Re.IN_FRAMESET:{aZt(this,I);break}case Re.AFTER_FRAMESET:{lZt(this,I);break}case Re.AFTER_AFTER_BODY:{uZt(this,I);break}case Re.AFTER_AFTER_FRAMESET:{dZt(this,I);break}}}},{key:"onEndTag",value:function(I){this.skipNextNewLine=!1,this.currentToken=I,this.currentNotInHTML?pZt(this,I):this._endTagOutsideForeignContent(I)}},{key:"_endTagOutsideForeignContent",value:function(I){switch(this.insertionMode){case Re.INITIAL:{lZ(this,I);break}case Re.BEFORE_HTML:{$0t(this,I);break}case Re.BEFORE_HEAD:{eyt(this,I);break}case Re.IN_HEAD:{tyt(this,I);break}case Re.IN_HEAD_NO_SCRIPT:{Iyt(this,I);break}case Re.AFTER_HEAD:{nyt(this,I);break}case Re.IN_BODY:{kk(this,I);break}case Re.TEXT:{Pyt(this,I);break}case Re.IN_TABLE:{Qv(this,I);break}case Re.IN_TABLE_TEXT:{cZ(this,I);break}case Re.IN_CAPTION:{tZt(this,I);break}case Re.IN_COLUMN_GROUP:{gZt(this,I);break}case Re.IN_TABLE_BODY:{Kz(this,I);break}case Re.IN_ROW:{kwe(this,I);break}case Re.IN_CELL:{iZt(this,I);break}case Re.IN_SELECT:{Kwe(this,I);break}case Re.IN_SELECT_IN_TABLE:{CZt(this,I);break}case Re.IN_TEMPLATE:{oZt(this,I);break}case Re.AFTER_BODY:{Dwe(this,I);break}case Re.IN_FRAMESET:{sZt(this,I);break}case Re.AFTER_FRAMESET:{cZt(this,I);break}case Re.AFTER_AFTER_BODY:{cW(this,I);break}}}},{key:"onEof",value:function(I){switch(this.insertionMode){case Re.INITIAL:{lZ(this,I);break}case Re.BEFORE_HTML:{dB(this,I);break}case Re.BEFORE_HEAD:{hB(this,I);break}case Re.IN_HEAD:{mB(this,I);break}case Re.IN_HEAD_NO_SCRIPT:{fB(this,I);break}case Re.AFTER_HEAD:{pB(this,I);break}case Re.IN_BODY:case Re.IN_TABLE:case Re.IN_CAPTION:case Re.IN_COLUMN_GROUP:case Re.IN_TABLE_BODY:case Re.IN_ROW:case Re.IN_CELL:case Re.IN_SELECT:case Re.IN_SELECT_IN_TABLE:{Xwe(this,I);break}case Re.TEXT:{Jyt(this,I);break}case Re.IN_TABLE_TEXT:{cZ(this,I);break}case Re.IN_TEMPLATE:{xwe(this,I);break}case Re.AFTER_BODY:case Re.IN_FRAMESET:case Re.AFTER_FRAMESET:case Re.AFTER_AFTER_BODY:case Re.AFTER_AFTER_FRAMESET:{pj(this,I);break}}}},{key:"onWhitespaceCharacter",value:function(I){if(this.skipNextNewLine&&(this.skipNextNewLine=!1,I.chars.charCodeAt(0)===Bwe.CODE_POINTS.LINE_FEED)){if(I.chars.length===1)return;I.chars=I.chars.substr(1)}if(this.tokenizer.inForeignNode){this._insertCharacters(I);return}switch(this.insertionMode){case Re.IN_HEAD:case Re.IN_HEAD_NO_SCRIPT:case Re.AFTER_HEAD:case Re.TEXT:case Re.IN_COLUMN_GROUP:case Re.IN_SELECT:case Re.IN_SELECT_IN_TABLE:case Re.IN_FRAMESET:case Re.AFTER_FRAMESET:{this._insertCharacters(I);break}case Re.IN_BODY:case Re.IN_CAPTION:case Re.IN_CELL:case Re.IN_TEMPLATE:case Re.AFTER_BODY:case Re.AFTER_AFTER_BODY:case Re.AFTER_AFTER_FRAMESET:{Swe(this,I);break}case Re.IN_TABLE:case Re.IN_TABLE_BODY:case Re.IN_ROW:{HD(this,I);break}case Re.IN_TABLE_TEXT:{Hwe(this,I);break}}}}],[{key:"parse",value:function(I,i){const n=new this(i);return n.tokenizer.write(I,!0),n.document}},{key:"getFragmentParser",value:function(I,i){const n=Object.assign(Object.assign({},sCe),i);I??(I=n.treeAdapter.createElement(z.TAG_NAMES.TEMPLATE,z.NS.HTML,[]));const C=n.treeAdapter.createElement("documentmock",z.NS.HTML,[]),r=new this(n,C,I);return r.fragmentContextID===z.TAG_ID.TEMPLATE&&r.tmplInsertionModeStack.unshift(Re.IN_TEMPLATE),r._initTokenizerForFragmentParsing(),r._insertFakeRootElement(),r._resetInsertionMode(),r._findFormInFragmentContext(),r}}]),g}();Uv.Parser=E0t;function M0t(g,e){let I=g.activeFormattingElements.getElementEntryInScopeWithTagName(e.tagName);return I?g.openElements.contains(I.element)?g.openElements.hasInScope(e.tagID)||(I=null):(g.activeFormattingElements.removeEntry(I),I=null):Wwe(g,e),I}function z0t(g,e){let I=null,i=g.openElements.stackTop;for(;i>=0;i--){const n=g.openElements.items[i];if(n===e.element)break;g._isSpecialElement(n,g.openElements.tagIDs[i])&&(I=n)}return I||(g.openElements.shortenToLength(i<0?0:i),g.activeFormattingElements.removeEntry(e)),I}function P0t(g,e,I){let i=e,n=g.openElements.getCommonAncestor(e);for(let C=0,r=n;r!==I;C++,r=n){n=g.openElements.getCommonAncestor(r);const o=g.activeFormattingElements.getElementEntry(r),A=o&&C>=D0t;!o||A?(A&&g.activeFormattingElements.removeEntry(o),g.openElements.remove(r)):(r=J0t(g,o),i===e&&(g.activeFormattingElements.bookmark=o),g.treeAdapter.detachNode(i),g.treeAdapter.appendChild(r,i),i=r)}return i}function J0t(g,e){const I=g.treeAdapter.getNamespaceURI(e.element),i=g.treeAdapter.createElement(e.token.tagName,I,e.token.attrs);return g.openElements.replace(e.element,i),e.element=i,i}function O0t(g,e,I){const i=g.treeAdapter.getTagName(e),n=(0,z.getTagID)(i);if(g._isElementCausesFosterParenting(n))g._fosterParentElement(I);else{const C=g.treeAdapter.getNamespaceURI(e);n===z.TAG_ID.TEMPLATE&&C===z.NS.HTML&&(e=g.treeAdapter.getTemplateContent(e)),g.treeAdapter.appendChild(e,I)}}function L0t(g,e,I){const i=g.treeAdapter.getNamespaceURI(I.element),{token:n}=I,C=g.treeAdapter.createElement(n.tagName,i,n.attrs);g._adoptNodes(e,C),g.treeAdapter.appendChild(e,C),g.activeFormattingElements.insertElementAfterBookmark(C,n),g.activeFormattingElements.removeEntry(I),g.openElements.remove(I.element),g.openElements.insertAfter(e,C,n.tagID)}function fj(g,e){for(let I=0;I=I;i--)g._setEndLocation(g.openElements.items[i],e);if(!g.fragmentContext&&g.openElements.stackTop>=0){const i=g.openElements.items[0],n=g.treeAdapter.getNodeSourceCodeLocation(i);if(n&&!n.endTag&&(g._setEndLocation(i,e),g.openElements.stackTop>=1)){const C=g.openElements.items[1],r=g.treeAdapter.getNodeSourceCodeLocation(C);r&&!r.endTag&&g._setEndLocation(C,e)}}}}function Q0t(g,e){g._setDocumentType(e);const I=e.forceQuirks?z.DOCUMENT_MODE.QUIRKS:aCe.getDocumentMode(e);aCe.isConforming(e)||g._err(e,un.ERR.nonConformingDoctype),g.treeAdapter.setDocumentMode(g.document,I),g.insertionMode=Re.BEFORE_HTML}function lZ(g,e){g._err(e,un.ERR.missingDoctype,!0),g.treeAdapter.setDocumentMode(g.document,z.DOCUMENT_MODE.QUIRKS),g.insertionMode=Re.BEFORE_HTML,g._processToken(e)}function j0t(g,e){e.tagID===z.TAG_ID.HTML?(g._insertElement(e,z.NS.HTML),g.insertionMode=Re.BEFORE_HEAD):dB(g,e)}function $0t(g,e){const I=e.tagID;(I===z.TAG_ID.HTML||I===z.TAG_ID.HEAD||I===z.TAG_ID.BODY||I===z.TAG_ID.BR)&&dB(g,e)}function dB(g,e){g._insertFakeRootElement(),g.insertionMode=Re.BEFORE_HEAD,g._processToken(e)}function q0t(g,e){switch(e.tagID){case z.TAG_ID.HTML:{Fn(g,e);break}case z.TAG_ID.HEAD:{g._insertElement(e,z.NS.HTML),g.headElement=g.openElements.current,g.insertionMode=Re.IN_HEAD;break}default:hB(g,e)}}function eyt(g,e){const I=e.tagID;I===z.TAG_ID.HEAD||I===z.TAG_ID.BODY||I===z.TAG_ID.HTML||I===z.TAG_ID.BR?hB(g,e):g._err(e,un.ERR.endTagWithoutMatchingOpenElement)}function hB(g,e){g._insertFakeElement(z.TAG_NAMES.HEAD,z.TAG_ID.HEAD),g.headElement=g.openElements.current,g.insertionMode=Re.IN_HEAD,g._processToken(e)}function ZA(g,e){switch(e.tagID){case z.TAG_ID.HTML:{Fn(g,e);break}case z.TAG_ID.BASE:case z.TAG_ID.BASEFONT:case z.TAG_ID.BGSOUND:case z.TAG_ID.LINK:case z.TAG_ID.META:{g._appendElement(e,z.NS.HTML),e.ackSelfClosing=!0;break}case z.TAG_ID.TITLE:{g._switchToTextParsing(e,Un.TokenizerMode.RCDATA);break}case z.TAG_ID.NOSCRIPT:{g.options.scriptingEnabled?g._switchToTextParsing(e,Un.TokenizerMode.RAWTEXT):(g._insertElement(e,z.NS.HTML),g.insertionMode=Re.IN_HEAD_NO_SCRIPT);break}case z.TAG_ID.NOFRAMES:case z.TAG_ID.STYLE:{g._switchToTextParsing(e,Un.TokenizerMode.RAWTEXT);break}case z.TAG_ID.SCRIPT:{g._switchToTextParsing(e,Un.TokenizerMode.SCRIPT_DATA);break}case z.TAG_ID.TEMPLATE:{g._insertTemplate(e),g.activeFormattingElements.insertMarker(),g.framesetOk=!1,g.insertionMode=Re.IN_TEMPLATE,g.tmplInsertionModeStack.unshift(Re.IN_TEMPLATE);break}case z.TAG_ID.HEAD:{g._err(e,un.ERR.misplacedStartTagForHeadElement);break}default:mB(g,e)}}function tyt(g,e){switch(e.tagID){case z.TAG_ID.HEAD:{g.openElements.pop(),g.insertionMode=Re.AFTER_HEAD;break}case z.TAG_ID.BODY:case z.TAG_ID.BR:case z.TAG_ID.HTML:{mB(g,e);break}case z.TAG_ID.TEMPLATE:{fm(g,e);break}default:g._err(e,un.ERR.endTagWithoutMatchingOpenElement)}}function fm(g,e){g.openElements.tmplCount>0?(g.openElements.generateImpliedEndTagsThoroughly(),g.openElements.currentTagId!==z.TAG_ID.TEMPLATE&&g._err(e,un.ERR.closingOfElementWithOpenChildElements),g.openElements.popUntilTagNamePopped(z.TAG_ID.TEMPLATE),g.activeFormattingElements.clearToLastMarker(),g.tmplInsertionModeStack.shift(),g._resetInsertionMode()):g._err(e,un.ERR.endTagWithoutMatchingOpenElement)}function mB(g,e){g.openElements.pop(),g.insertionMode=Re.AFTER_HEAD,g._processToken(e)}function gyt(g,e){switch(e.tagID){case z.TAG_ID.HTML:{Fn(g,e);break}case z.TAG_ID.BASEFONT:case z.TAG_ID.BGSOUND:case z.TAG_ID.HEAD:case z.TAG_ID.LINK:case z.TAG_ID.META:case z.TAG_ID.NOFRAMES:case z.TAG_ID.STYLE:{ZA(g,e);break}case z.TAG_ID.NOSCRIPT:{g._err(e,un.ERR.nestedNoscriptInHead);break}default:fB(g,e)}}function Iyt(g,e){switch(e.tagID){case z.TAG_ID.NOSCRIPT:{g.openElements.pop(),g.insertionMode=Re.IN_HEAD;break}case z.TAG_ID.BR:{fB(g,e);break}default:g._err(e,un.ERR.endTagWithoutMatchingOpenElement)}}function fB(g,e){const I=e.type===vi.TokenType.EOF?un.ERR.openElementsLeftAfterEof:un.ERR.disallowedContentInNoscriptInHead;g._err(e,I),g.openElements.pop(),g.insertionMode=Re.IN_HEAD,g._processToken(e)}function iyt(g,e){switch(e.tagID){case z.TAG_ID.HTML:{Fn(g,e);break}case z.TAG_ID.BODY:{g._insertElement(e,z.NS.HTML),g.framesetOk=!1,g.insertionMode=Re.IN_BODY;break}case z.TAG_ID.FRAMESET:{g._insertElement(e,z.NS.HTML),g.insertionMode=Re.IN_FRAMESET;break}case z.TAG_ID.BASE:case z.TAG_ID.BASEFONT:case z.TAG_ID.BGSOUND:case z.TAG_ID.LINK:case z.TAG_ID.META:case z.TAG_ID.NOFRAMES:case z.TAG_ID.SCRIPT:case z.TAG_ID.STYLE:case z.TAG_ID.TEMPLATE:case z.TAG_ID.TITLE:{g._err(e,un.ERR.abandonedHeadElementChild),g.openElements.push(g.headElement,z.TAG_ID.HEAD),ZA(g,e),g.openElements.remove(g.headElement);break}case z.TAG_ID.HEAD:{g._err(e,un.ERR.misplacedStartTagForHeadElement);break}default:pB(g,e)}}function nyt(g,e){switch(e.tagID){case z.TAG_ID.BODY:case z.TAG_ID.HTML:case z.TAG_ID.BR:{pB(g,e);break}case z.TAG_ID.TEMPLATE:{fm(g,e);break}default:g._err(e,un.ERR.endTagWithoutMatchingOpenElement)}}function pB(g,e){g._insertFakeElement(z.TAG_NAMES.BODY,z.TAG_ID.BODY),g.insertionMode=Re.IN_BODY,Nk(g,e)}function Nk(g,e){switch(e.type){case vi.TokenType.CHARACTER:{wwe(g,e);break}case vi.TokenType.WHITESPACE_CHARACTER:{Swe(g,e);break}case vi.TokenType.COMMENT:{Yz(g,e);break}case vi.TokenType.START_TAG:{Fn(g,e);break}case vi.TokenType.END_TAG:{kk(g,e);break}case vi.TokenType.EOF:{Xwe(g,e);break}}}function Swe(g,e){g._reconstructActiveFormattingElements(),g._insertCharacters(e)}function wwe(g,e){g._reconstructActiveFormattingElements(),g._insertCharacters(e),g.framesetOk=!1}function Cyt(g,e){g.openElements.tmplCount===0&&g.treeAdapter.adoptAttributes(g.openElements.items[0],e.attrs)}function ryt(g,e){const I=g.openElements.tryPeekProperlyNestedBodyElement();I&&g.openElements.tmplCount===0&&(g.framesetOk=!1,g.treeAdapter.adoptAttributes(I,e.attrs))}function oyt(g,e){const I=g.openElements.tryPeekProperlyNestedBodyElement();g.framesetOk&&I&&(g.treeAdapter.detachNode(I),g.openElements.popAllUpToHtmlElement(),g._insertElement(e,z.NS.HTML),g.insertionMode=Re.IN_FRAMESET)}function Ayt(g,e){g.openElements.hasInButtonScope(z.TAG_ID.P)&&g._closePElement(),g._insertElement(e,z.NS.HTML)}function ayt(g,e){g.openElements.hasInButtonScope(z.TAG_ID.P)&&g._closePElement(),(0,z.isNumberedHeader)(g.openElements.currentTagId)&&g.openElements.pop(),g._insertElement(e,z.NS.HTML)}function syt(g,e){g.openElements.hasInButtonScope(z.TAG_ID.P)&&g._closePElement(),g._insertElement(e,z.NS.HTML),g.skipNextNewLine=!0,g.framesetOk=!1}function lyt(g,e){const I=g.openElements.tmplCount>0;(!g.formElement||I)&&(g.openElements.hasInButtonScope(z.TAG_ID.P)&&g._closePElement(),g._insertElement(e,z.NS.HTML),I||(g.formElement=g.openElements.current))}function cyt(g,e){g.framesetOk=!1;const I=e.tagID;for(let i=g.openElements.stackTop;i>=0;i--){const n=g.openElements.tagIDs[i];if(I===z.TAG_ID.LI&&n===z.TAG_ID.LI||(I===z.TAG_ID.DD||I===z.TAG_ID.DT)&&(n===z.TAG_ID.DD||n===z.TAG_ID.DT)){g.openElements.generateImpliedEndTagsWithExclusion(n),g.openElements.popUntilTagNamePopped(n);break}if(n!==z.TAG_ID.ADDRESS&&n!==z.TAG_ID.DIV&&n!==z.TAG_ID.P&&g._isSpecialElement(g.openElements.items[i],n))break}g.openElements.hasInButtonScope(z.TAG_ID.P)&&g._closePElement(),g._insertElement(e,z.NS.HTML)}function uyt(g,e){g.openElements.hasInButtonScope(z.TAG_ID.P)&&g._closePElement(),g._insertElement(e,z.NS.HTML),g.tokenizer.state=Un.TokenizerMode.PLAINTEXT}function dyt(g,e){g.openElements.hasInScope(z.TAG_ID.BUTTON)&&(g.openElements.generateImpliedEndTags(),g.openElements.popUntilTagNamePopped(z.TAG_ID.BUTTON)),g._reconstructActiveFormattingElements(),g._insertElement(e,z.NS.HTML),g.framesetOk=!1}function hyt(g,e){const I=g.activeFormattingElements.getElementEntryInScopeWithTagName(z.TAG_NAMES.A);I&&(fj(g,e),g.openElements.remove(I.element),g.activeFormattingElements.removeEntry(I)),g._reconstructActiveFormattingElements(),g._insertElement(e,z.NS.HTML),g.activeFormattingElements.pushElement(g.openElements.current,e)}function myt(g,e){g._reconstructActiveFormattingElements(),g._insertElement(e,z.NS.HTML),g.activeFormattingElements.pushElement(g.openElements.current,e)}function fyt(g,e){g._reconstructActiveFormattingElements(),g.openElements.hasInScope(z.TAG_ID.NOBR)&&(fj(g,e),g._reconstructActiveFormattingElements()),g._insertElement(e,z.NS.HTML),g.activeFormattingElements.pushElement(g.openElements.current,e)}function pyt(g,e){g._reconstructActiveFormattingElements(),g._insertElement(e,z.NS.HTML),g.activeFormattingElements.insertMarker(),g.framesetOk=!1}function byt(g,e){g.treeAdapter.getDocumentMode(g.document)!==z.DOCUMENT_MODE.QUIRKS&&g.openElements.hasInButtonScope(z.TAG_ID.P)&&g._closePElement(),g._insertElement(e,z.NS.HTML),g.framesetOk=!1,g.insertionMode=Re.IN_TABLE}function Vwe(g,e){g._reconstructActiveFormattingElements(),g._appendElement(e,z.NS.HTML),g.framesetOk=!1,e.ackSelfClosing=!0}function Rwe(g){const e=(0,vi.getTokenAttr)(g,z.ATTRS.TYPE);return e!=null&&e.toLowerCase()===K0t}function yyt(g,e){g._reconstructActiveFormattingElements(),g._appendElement(e,z.NS.HTML),Rwe(e)||(g.framesetOk=!1),e.ackSelfClosing=!0}function Zyt(g,e){g._appendElement(e,z.NS.HTML),e.ackSelfClosing=!0}function Gyt(g,e){g.openElements.hasInButtonScope(z.TAG_ID.P)&&g._closePElement(),g._appendElement(e,z.NS.HTML),g.framesetOk=!1,e.ackSelfClosing=!0}function Byt(g,e){e.tagName=z.TAG_NAMES.IMG,e.tagID=z.TAG_ID.IMG,Vwe(g,e)}function vyt(g,e){g._insertElement(e,z.NS.HTML),g.skipNextNewLine=!0,g.tokenizer.state=Un.TokenizerMode.RCDATA,g.originalInsertionMode=g.insertionMode,g.framesetOk=!1,g.insertionMode=Re.TEXT}function Syt(g,e){g.openElements.hasInButtonScope(z.TAG_ID.P)&&g._closePElement(),g._reconstructActiveFormattingElements(),g.framesetOk=!1,g._switchToTextParsing(e,Un.TokenizerMode.RAWTEXT)}function wyt(g,e){g.framesetOk=!1,g._switchToTextParsing(e,Un.TokenizerMode.RAWTEXT)}function lCe(g,e){g._switchToTextParsing(e,Un.TokenizerMode.RAWTEXT)}function Vyt(g,e){g._reconstructActiveFormattingElements(),g._insertElement(e,z.NS.HTML),g.framesetOk=!1,g.insertionMode=g.insertionMode===Re.IN_TABLE||g.insertionMode===Re.IN_CAPTION||g.insertionMode===Re.IN_TABLE_BODY||g.insertionMode===Re.IN_ROW||g.insertionMode===Re.IN_CELL?Re.IN_SELECT_IN_TABLE:Re.IN_SELECT}function Ryt(g,e){g.openElements.currentTagId===z.TAG_ID.OPTION&&g.openElements.pop(),g._reconstructActiveFormattingElements(),g._insertElement(e,z.NS.HTML)}function Wyt(g,e){g.openElements.hasInScope(z.TAG_ID.RUBY)&&g.openElements.generateImpliedEndTags(),g._insertElement(e,z.NS.HTML)}function Xyt(g,e){g.openElements.hasInScope(z.TAG_ID.RUBY)&&g.openElements.generateImpliedEndTagsWithExclusion(z.TAG_ID.RTC),g._insertElement(e,z.NS.HTML)}function Hyt(g,e){g._reconstructActiveFormattingElements(),QA.adjustTokenMathMLAttrs(e),QA.adjustTokenXMLAttrs(e),e.selfClosing?g._appendElement(e,z.NS.MATHML):g._insertElement(e,z.NS.MATHML),e.ackSelfClosing=!0}function Tyt(g,e){g._reconstructActiveFormattingElements(),QA.adjustTokenSVGAttrs(e),QA.adjustTokenXMLAttrs(e),e.selfClosing?g._appendElement(e,z.NS.SVG):g._insertElement(e,z.NS.SVG),e.ackSelfClosing=!0}function cCe(g,e){g._reconstructActiveFormattingElements(),g._insertElement(e,z.NS.HTML)}function Fn(g,e){switch(e.tagID){case z.TAG_ID.I:case z.TAG_ID.S:case z.TAG_ID.B:case z.TAG_ID.U:case z.TAG_ID.EM:case z.TAG_ID.TT:case z.TAG_ID.BIG:case z.TAG_ID.CODE:case z.TAG_ID.FONT:case z.TAG_ID.SMALL:case z.TAG_ID.STRIKE:case z.TAG_ID.STRONG:{myt(g,e);break}case z.TAG_ID.A:{hyt(g,e);break}case z.TAG_ID.H1:case z.TAG_ID.H2:case z.TAG_ID.H3:case z.TAG_ID.H4:case z.TAG_ID.H5:case z.TAG_ID.H6:{ayt(g,e);break}case z.TAG_ID.P:case z.TAG_ID.DL:case z.TAG_ID.OL:case z.TAG_ID.UL:case z.TAG_ID.DIV:case z.TAG_ID.DIR:case z.TAG_ID.NAV:case z.TAG_ID.MAIN:case z.TAG_ID.MENU:case z.TAG_ID.ASIDE:case z.TAG_ID.CENTER:case z.TAG_ID.FIGURE:case z.TAG_ID.FOOTER:case z.TAG_ID.HEADER:case z.TAG_ID.HGROUP:case z.TAG_ID.DIALOG:case z.TAG_ID.DETAILS:case z.TAG_ID.ADDRESS:case z.TAG_ID.ARTICLE:case z.TAG_ID.SECTION:case z.TAG_ID.SUMMARY:case z.TAG_ID.FIELDSET:case z.TAG_ID.BLOCKQUOTE:case z.TAG_ID.FIGCAPTION:{Ayt(g,e);break}case z.TAG_ID.LI:case z.TAG_ID.DD:case z.TAG_ID.DT:{cyt(g,e);break}case z.TAG_ID.BR:case z.TAG_ID.IMG:case z.TAG_ID.WBR:case z.TAG_ID.AREA:case z.TAG_ID.EMBED:case z.TAG_ID.KEYGEN:{Vwe(g,e);break}case z.TAG_ID.HR:{Gyt(g,e);break}case z.TAG_ID.RB:case z.TAG_ID.RTC:{Wyt(g,e);break}case z.TAG_ID.RT:case z.TAG_ID.RP:{Xyt(g,e);break}case z.TAG_ID.PRE:case z.TAG_ID.LISTING:{syt(g,e);break}case z.TAG_ID.XMP:{Syt(g,e);break}case z.TAG_ID.SVG:{Tyt(g,e);break}case z.TAG_ID.HTML:{Cyt(g,e);break}case z.TAG_ID.BASE:case z.TAG_ID.LINK:case z.TAG_ID.META:case z.TAG_ID.STYLE:case z.TAG_ID.TITLE:case z.TAG_ID.SCRIPT:case z.TAG_ID.BGSOUND:case z.TAG_ID.BASEFONT:case z.TAG_ID.TEMPLATE:{ZA(g,e);break}case z.TAG_ID.BODY:{ryt(g,e);break}case z.TAG_ID.FORM:{lyt(g,e);break}case z.TAG_ID.NOBR:{fyt(g,e);break}case z.TAG_ID.MATH:{Hyt(g,e);break}case z.TAG_ID.TABLE:{byt(g,e);break}case z.TAG_ID.INPUT:{yyt(g,e);break}case z.TAG_ID.PARAM:case z.TAG_ID.TRACK:case z.TAG_ID.SOURCE:{Zyt(g,e);break}case z.TAG_ID.IMAGE:{Byt(g,e);break}case z.TAG_ID.BUTTON:{dyt(g,e);break}case z.TAG_ID.APPLET:case z.TAG_ID.OBJECT:case z.TAG_ID.MARQUEE:{pyt(g,e);break}case z.TAG_ID.IFRAME:{wyt(g,e);break}case z.TAG_ID.SELECT:{Vyt(g,e);break}case z.TAG_ID.OPTION:case z.TAG_ID.OPTGROUP:{Ryt(g,e);break}case z.TAG_ID.NOEMBED:{lCe(g,e);break}case z.TAG_ID.FRAMESET:{oyt(g,e);break}case z.TAG_ID.TEXTAREA:{vyt(g,e);break}case z.TAG_ID.NOSCRIPT:{g.options.scriptingEnabled?lCe(g,e):cCe(g,e);break}case z.TAG_ID.PLAINTEXT:{uyt(g,e);break}case z.TAG_ID.COL:case z.TAG_ID.TH:case z.TAG_ID.TD:case z.TAG_ID.TR:case z.TAG_ID.HEAD:case z.TAG_ID.FRAME:case z.TAG_ID.TBODY:case z.TAG_ID.TFOOT:case z.TAG_ID.THEAD:case z.TAG_ID.CAPTION:case z.TAG_ID.COLGROUP:break;default:cCe(g,e)}}function Nyt(g,e){if(g.openElements.hasInScope(z.TAG_ID.BODY)&&(g.insertionMode=Re.AFTER_BODY,g.options.sourceCodeLocationInfo)){const I=g.openElements.tryPeekProperlyNestedBodyElement();I&&g._setEndLocation(I,e)}}function kyt(g,e){g.openElements.hasInScope(z.TAG_ID.BODY)&&(g.insertionMode=Re.AFTER_BODY,Dwe(g,e))}function Yyt(g,e){const I=e.tagID;g.openElements.hasInScope(I)&&(g.openElements.generateImpliedEndTags(),g.openElements.popUntilTagNamePopped(I))}function Kyt(g){const e=g.openElements.tmplCount>0,{formElement:I}=g;e||(g.formElement=null),(I||e)&&g.openElements.hasInScope(z.TAG_ID.FORM)&&(g.openElements.generateImpliedEndTags(),e?g.openElements.popUntilTagNamePopped(z.TAG_ID.FORM):I&&g.openElements.remove(I))}function xyt(g){g.openElements.hasInButtonScope(z.TAG_ID.P)||g._insertFakeElement(z.TAG_NAMES.P,z.TAG_ID.P),g._closePElement()}function Dyt(g){g.openElements.hasInListItemScope(z.TAG_ID.LI)&&(g.openElements.generateImpliedEndTagsWithExclusion(z.TAG_ID.LI),g.openElements.popUntilTagNamePopped(z.TAG_ID.LI))}function Fyt(g,e){const I=e.tagID;g.openElements.hasInScope(I)&&(g.openElements.generateImpliedEndTagsWithExclusion(I),g.openElements.popUntilTagNamePopped(I))}function Eyt(g){g.openElements.hasNumberedHeaderInScope()&&(g.openElements.generateImpliedEndTags(),g.openElements.popUntilNumberedHeaderPopped())}function Myt(g,e){const I=e.tagID;g.openElements.hasInScope(I)&&(g.openElements.generateImpliedEndTags(),g.openElements.popUntilTagNamePopped(I),g.activeFormattingElements.clearToLastMarker())}function zyt(g){g._reconstructActiveFormattingElements(),g._insertFakeElement(z.TAG_NAMES.BR,z.TAG_ID.BR),g.openElements.pop(),g.framesetOk=!1}function Wwe(g,e){const I=e.tagName,i=e.tagID;for(let n=g.openElements.stackTop;n>0;n--){const C=g.openElements.items[n],r=g.openElements.tagIDs[n];if(i===r&&(i!==z.TAG_ID.UNKNOWN||g.treeAdapter.getTagName(C)===I)){g.openElements.generateImpliedEndTagsWithExclusion(i),g.openElements.stackTop>=n&&g.openElements.shortenToLength(n);break}if(g._isSpecialElement(C,r))break}}function kk(g,e){switch(e.tagID){case z.TAG_ID.A:case z.TAG_ID.B:case z.TAG_ID.I:case z.TAG_ID.S:case z.TAG_ID.U:case z.TAG_ID.EM:case z.TAG_ID.TT:case z.TAG_ID.BIG:case z.TAG_ID.CODE:case z.TAG_ID.FONT:case z.TAG_ID.NOBR:case z.TAG_ID.SMALL:case z.TAG_ID.STRIKE:case z.TAG_ID.STRONG:{fj(g,e);break}case z.TAG_ID.P:{xyt(g);break}case z.TAG_ID.DL:case z.TAG_ID.UL:case z.TAG_ID.OL:case z.TAG_ID.DIR:case z.TAG_ID.DIV:case z.TAG_ID.NAV:case z.TAG_ID.PRE:case z.TAG_ID.MAIN:case z.TAG_ID.MENU:case z.TAG_ID.ASIDE:case z.TAG_ID.BUTTON:case z.TAG_ID.CENTER:case z.TAG_ID.FIGURE:case z.TAG_ID.FOOTER:case z.TAG_ID.HEADER:case z.TAG_ID.HGROUP:case z.TAG_ID.DIALOG:case z.TAG_ID.ADDRESS:case z.TAG_ID.ARTICLE:case z.TAG_ID.DETAILS:case z.TAG_ID.SECTION:case z.TAG_ID.SUMMARY:case z.TAG_ID.LISTING:case z.TAG_ID.FIELDSET:case z.TAG_ID.BLOCKQUOTE:case z.TAG_ID.FIGCAPTION:{Yyt(g,e);break}case z.TAG_ID.LI:{Dyt(g);break}case z.TAG_ID.DD:case z.TAG_ID.DT:{Fyt(g,e);break}case z.TAG_ID.H1:case z.TAG_ID.H2:case z.TAG_ID.H3:case z.TAG_ID.H4:case z.TAG_ID.H5:case z.TAG_ID.H6:{Eyt(g);break}case z.TAG_ID.BR:{zyt(g);break}case z.TAG_ID.BODY:{Nyt(g,e);break}case z.TAG_ID.HTML:{kyt(g,e);break}case z.TAG_ID.FORM:{Kyt(g);break}case z.TAG_ID.APPLET:case z.TAG_ID.OBJECT:case z.TAG_ID.MARQUEE:{Myt(g,e);break}case z.TAG_ID.TEMPLATE:{fm(g,e);break}default:Wwe(g,e)}}function Xwe(g,e){g.tmplInsertionModeStack.length>0?xwe(g,e):pj(g,e)}function Pyt(g,e){var I;e.tagID===z.TAG_ID.SCRIPT&&((I=g.scriptHandler)===null||I===void 0||I.call(g,g.openElements.current)),g.openElements.pop(),g.insertionMode=g.originalInsertionMode}function Jyt(g,e){g._err(e,un.ERR.eofInElementThatCanContainOnlyText),g.openElements.pop(),g.insertionMode=g.originalInsertionMode,g.onEof(e)}function HD(g,e){if(vwe.has(g.openElements.currentTagId))switch(g.pendingCharacterTokens.length=0,g.hasNonWhitespacePendingCharacterToken=!1,g.originalInsertionMode=g.insertionMode,g.insertionMode=Re.IN_TABLE_TEXT,e.type){case vi.TokenType.CHARACTER:{Twe(g,e);break}case vi.TokenType.WHITESPACE_CHARACTER:{Hwe(g,e);break}}else Bw(g,e)}function Oyt(g,e){g.openElements.clearBackToTableContext(),g.activeFormattingElements.insertMarker(),g._insertElement(e,z.NS.HTML),g.insertionMode=Re.IN_CAPTION}function Lyt(g,e){g.openElements.clearBackToTableContext(),g._insertElement(e,z.NS.HTML),g.insertionMode=Re.IN_COLUMN_GROUP}function _yt(g,e){g.openElements.clearBackToTableContext(),g._insertFakeElement(z.TAG_NAMES.COLGROUP,z.TAG_ID.COLGROUP),g.insertionMode=Re.IN_COLUMN_GROUP,bj(g,e)}function Uyt(g,e){g.openElements.clearBackToTableContext(),g._insertElement(e,z.NS.HTML),g.insertionMode=Re.IN_TABLE_BODY}function Qyt(g,e){g.openElements.clearBackToTableContext(),g._insertFakeElement(z.TAG_NAMES.TBODY,z.TAG_ID.TBODY),g.insertionMode=Re.IN_TABLE_BODY,Yk(g,e)}function jyt(g,e){g.openElements.hasInTableScope(z.TAG_ID.TABLE)&&(g.openElements.popUntilTagNamePopped(z.TAG_ID.TABLE),g._resetInsertionMode(),g._processStartTag(e))}function $yt(g,e){Rwe(e)?g._appendElement(e,z.NS.HTML):Bw(g,e),e.ackSelfClosing=!0}function qyt(g,e){!g.formElement&&g.openElements.tmplCount===0&&(g._insertElement(e,z.NS.HTML),g.formElement=g.openElements.current,g.openElements.pop())}function C0(g,e){switch(e.tagID){case z.TAG_ID.TD:case z.TAG_ID.TH:case z.TAG_ID.TR:{Qyt(g,e);break}case z.TAG_ID.STYLE:case z.TAG_ID.SCRIPT:case z.TAG_ID.TEMPLATE:{ZA(g,e);break}case z.TAG_ID.COL:{_yt(g,e);break}case z.TAG_ID.FORM:{qyt(g,e);break}case z.TAG_ID.TABLE:{jyt(g,e);break}case z.TAG_ID.TBODY:case z.TAG_ID.TFOOT:case z.TAG_ID.THEAD:{Uyt(g,e);break}case z.TAG_ID.INPUT:{$yt(g,e);break}case z.TAG_ID.CAPTION:{Oyt(g,e);break}case z.TAG_ID.COLGROUP:{Lyt(g,e);break}default:Bw(g,e)}}function Qv(g,e){switch(e.tagID){case z.TAG_ID.TABLE:{g.openElements.hasInTableScope(z.TAG_ID.TABLE)&&(g.openElements.popUntilTagNamePopped(z.TAG_ID.TABLE),g._resetInsertionMode());break}case z.TAG_ID.TEMPLATE:{fm(g,e);break}case z.TAG_ID.BODY:case z.TAG_ID.CAPTION:case z.TAG_ID.COL:case z.TAG_ID.COLGROUP:case z.TAG_ID.HTML:case z.TAG_ID.TBODY:case z.TAG_ID.TD:case z.TAG_ID.TFOOT:case z.TAG_ID.TH:case z.TAG_ID.THEAD:case z.TAG_ID.TR:break;default:Bw(g,e)}}function Bw(g,e){const I=g.fosterParentingEnabled;g.fosterParentingEnabled=!0,Nk(g,e),g.fosterParentingEnabled=I}function Hwe(g,e){g.pendingCharacterTokens.push(e)}function Twe(g,e){g.pendingCharacterTokens.push(e),g.hasNonWhitespacePendingCharacterToken=!0}function cZ(g,e){let I=0;if(g.hasNonWhitespacePendingCharacterToken)for(;I0&&g.openElements.currentTagId===z.TAG_ID.OPTION&&g.openElements.tagIDs[g.openElements.stackTop-1]===z.TAG_ID.OPTGROUP&&g.openElements.pop(),g.openElements.currentTagId===z.TAG_ID.OPTGROUP&&g.openElements.pop();break}case z.TAG_ID.OPTION:{g.openElements.currentTagId===z.TAG_ID.OPTION&&g.openElements.pop();break}case z.TAG_ID.SELECT:{g.openElements.hasInSelectScope(z.TAG_ID.SELECT)&&(g.openElements.popUntilTagNamePopped(z.TAG_ID.SELECT),g._resetInsertionMode());break}case z.TAG_ID.TEMPLATE:{fm(g,e);break}}}function nZt(g,e){const I=e.tagID;I===z.TAG_ID.CAPTION||I===z.TAG_ID.TABLE||I===z.TAG_ID.TBODY||I===z.TAG_ID.TFOOT||I===z.TAG_ID.THEAD||I===z.TAG_ID.TR||I===z.TAG_ID.TD||I===z.TAG_ID.TH?(g.openElements.popUntilTagNamePopped(z.TAG_ID.SELECT),g._resetInsertionMode(),g._processStartTag(e)):Ywe(g,e)}function CZt(g,e){const I=e.tagID;I===z.TAG_ID.CAPTION||I===z.TAG_ID.TABLE||I===z.TAG_ID.TBODY||I===z.TAG_ID.TFOOT||I===z.TAG_ID.THEAD||I===z.TAG_ID.TR||I===z.TAG_ID.TD||I===z.TAG_ID.TH?g.openElements.hasInTableScope(I)&&(g.openElements.popUntilTagNamePopped(z.TAG_ID.SELECT),g._resetInsertionMode(),g.onEndTag(e)):Kwe(g,e)}function rZt(g,e){switch(e.tagID){case z.TAG_ID.BASE:case z.TAG_ID.BASEFONT:case z.TAG_ID.BGSOUND:case z.TAG_ID.LINK:case z.TAG_ID.META:case z.TAG_ID.NOFRAMES:case z.TAG_ID.SCRIPT:case z.TAG_ID.STYLE:case z.TAG_ID.TEMPLATE:case z.TAG_ID.TITLE:{ZA(g,e);break}case z.TAG_ID.CAPTION:case z.TAG_ID.COLGROUP:case z.TAG_ID.TBODY:case z.TAG_ID.TFOOT:case z.TAG_ID.THEAD:{g.tmplInsertionModeStack[0]=Re.IN_TABLE,g.insertionMode=Re.IN_TABLE,C0(g,e);break}case z.TAG_ID.COL:{g.tmplInsertionModeStack[0]=Re.IN_COLUMN_GROUP,g.insertionMode=Re.IN_COLUMN_GROUP,bj(g,e);break}case z.TAG_ID.TR:{g.tmplInsertionModeStack[0]=Re.IN_TABLE_BODY,g.insertionMode=Re.IN_TABLE_BODY,Yk(g,e);break}case z.TAG_ID.TD:case z.TAG_ID.TH:{g.tmplInsertionModeStack[0]=Re.IN_ROW,g.insertionMode=Re.IN_ROW,Kk(g,e);break}default:g.tmplInsertionModeStack[0]=Re.IN_BODY,g.insertionMode=Re.IN_BODY,Fn(g,e)}}function oZt(g,e){e.tagID===z.TAG_ID.TEMPLATE&&fm(g,e)}function xwe(g,e){g.openElements.tmplCount>0?(g.openElements.popUntilTagNamePopped(z.TAG_ID.TEMPLATE),g.activeFormattingElements.clearToLastMarker(),g.tmplInsertionModeStack.shift(),g._resetInsertionMode(),g.onEof(e)):pj(g,e)}function AZt(g,e){e.tagID===z.TAG_ID.HTML?Fn(g,e):aH(g,e)}function Dwe(g,e){var I;if(e.tagID===z.TAG_ID.HTML){if(g.fragmentContext||(g.insertionMode=Re.AFTER_AFTER_BODY),g.options.sourceCodeLocationInfo&&g.openElements.tagIDs[0]===z.TAG_ID.HTML){g._setEndLocation(g.openElements.items[0],e);const i=g.openElements.items[1];i&&!(!((I=g.treeAdapter.getNodeSourceCodeLocation(i))===null||I===void 0)&&I.endTag)&&g._setEndLocation(i,e)}}else aH(g,e)}function aH(g,e){g.insertionMode=Re.IN_BODY,Nk(g,e)}function aZt(g,e){switch(e.tagID){case z.TAG_ID.HTML:{Fn(g,e);break}case z.TAG_ID.FRAMESET:{g._insertElement(e,z.NS.HTML);break}case z.TAG_ID.FRAME:{g._appendElement(e,z.NS.HTML),e.ackSelfClosing=!0;break}case z.TAG_ID.NOFRAMES:{ZA(g,e);break}}}function sZt(g,e){e.tagID===z.TAG_ID.FRAMESET&&!g.openElements.isRootHtmlElementCurrent()&&(g.openElements.pop(),!g.fragmentContext&&g.openElements.currentTagId!==z.TAG_ID.FRAMESET&&(g.insertionMode=Re.AFTER_FRAMESET))}function lZt(g,e){switch(e.tagID){case z.TAG_ID.HTML:{Fn(g,e);break}case z.TAG_ID.NOFRAMES:{ZA(g,e);break}}}function cZt(g,e){e.tagID===z.TAG_ID.HTML&&(g.insertionMode=Re.AFTER_AFTER_FRAMESET)}function uZt(g,e){e.tagID===z.TAG_ID.HTML?Fn(g,e):cW(g,e)}function cW(g,e){g.insertionMode=Re.IN_BODY,Nk(g,e)}function dZt(g,e){switch(e.tagID){case z.TAG_ID.HTML:{Fn(g,e);break}case z.TAG_ID.NOFRAMES:{ZA(g,e);break}}}function hZt(g,e){e.chars=Bwe.REPLACEMENT_CHARACTER,g._insertCharacters(e)}function mZt(g,e){g._insertCharacters(e),g.framesetOk=!1}function Fwe(g){for(;g.treeAdapter.getNamespaceURI(g.openElements.current)!==z.NS.HTML&&!g._isIntegrationPoint(g.openElements.currentTagId,g.openElements.current);)g.openElements.pop()}function fZt(g,e){if(QA.causesExit(e))Fwe(g),g._startTagOutsideForeignContent(e);else{const I=g._getAdjustedCurrentElement(),i=g.treeAdapter.getNamespaceURI(I);i===z.NS.MATHML?QA.adjustTokenMathMLAttrs(e):i===z.NS.SVG&&(QA.adjustTokenSVGTagName(e),QA.adjustTokenSVGAttrs(e)),QA.adjustTokenXMLAttrs(e),e.selfClosing?g._appendElement(e,i):g._insertElement(e,i),e.ackSelfClosing=!0}}function pZt(g,e){if(e.tagID===z.TAG_ID.P||e.tagID===z.TAG_ID.BR){Fwe(g),g._endTagOutsideForeignContent(e);return}for(let I=g.openElements.stackTop;I>0;I--){const i=g.openElements.items[I];if(g.treeAdapter.getNamespaceURI(i)===z.NS.HTML){g._endTagOutsideForeignContent(e);break}const n=g.treeAdapter.getTagName(i);if(n.toLowerCase()===e.tagName){e.tagName=n,g.openElements.shortenToLength(I);break}}}var r0={};Object.defineProperty(r0,"__esModule",{value:!0});r0.serializeOuter=r0.serialize=void 0;const oI=hl,Ewe=_b,bZt=Tk,yZt=new Set([oI.TAG_NAMES.AREA,oI.TAG_NAMES.BASE,oI.TAG_NAMES.BASEFONT,oI.TAG_NAMES.BGSOUND,oI.TAG_NAMES.BR,oI.TAG_NAMES.COL,oI.TAG_NAMES.EMBED,oI.TAG_NAMES.FRAME,oI.TAG_NAMES.HR,oI.TAG_NAMES.IMG,oI.TAG_NAMES.INPUT,oI.TAG_NAMES.KEYGEN,oI.TAG_NAMES.LINK,oI.TAG_NAMES.META,oI.TAG_NAMES.PARAM,oI.TAG_NAMES.SOURCE,oI.TAG_NAMES.TRACK,oI.TAG_NAMES.WBR]);function Mwe(g,e){return e.treeAdapter.isElementNode(g)&&e.treeAdapter.getNamespaceURI(g)===oI.NS.HTML&&yZt.has(e.treeAdapter.getTagName(g))}const zwe={treeAdapter:bZt.defaultTreeAdapter,scriptingEnabled:!0};function ZZt(g,e){const I=Object.assign(Object.assign({},zwe),e);return Mwe(g,I)?"":Pwe(g,I)}r0.serialize=ZZt;function GZt(g,e){const I=Object.assign(Object.assign({},zwe),e);return Jwe(g,I)}r0.serializeOuter=GZt;function Pwe(g,e){let I="";const i=e.treeAdapter.isElementNode(g)&&e.treeAdapter.getTagName(g)===oI.TAG_NAMES.TEMPLATE&&e.treeAdapter.getNamespaceURI(g)===oI.NS.HTML?e.treeAdapter.getTemplateContent(g):g,n=e.treeAdapter.getChildNodes(i);if(n)for(const C of n)I+=Jwe(C,e);return I}function Jwe(g,e){return e.treeAdapter.isElementNode(g)?BZt(g,e):e.treeAdapter.isTextNode(g)?SZt(g,e):e.treeAdapter.isCommentNode(g)?wZt(g,e):e.treeAdapter.isDocumentTypeNode(g)?VZt(g,e):""}function BZt(g,e){const I=e.treeAdapter.getTagName(g);return`<${I}${vZt(g,e)}>${Mwe(g,e)?"":`${Pwe(g,e)}`}`}function vZt(g,{treeAdapter:e}){let I="";for(const i of e.getAttrList(g)){if(I+=" ",!i.namespace)I+=i.name;else switch(i.namespace){case oI.NS.XML:{I+=`xml:${i.name}`;break}case oI.NS.XMLNS:{i.name!=="xmlns"&&(I+="xmlns:"),I+=i.name;break}case oI.NS.XLINK:{I+=`xlink:${i.name}`;break}default:I+=`${i.prefix}:${i.name}`}I+=`="${(0,Ewe.escapeAttribute)(i.value)}"`}return I}function SZt(g,e){const{treeAdapter:I}=e,i=I.getTextNodeContent(g),n=I.getParentNode(g),C=n&&I.isElementNode(n)&&I.getTagName(n);return C&&I.getNamespaceURI(n)===oI.NS.HTML&&(0,oI.hasUnescapedText)(C,e.scriptingEnabled)?i:(0,Ewe.escapeText)(i)}function wZt(g,{treeAdapter:e}){return``}function VZt(g,{treeAdapter:e}){return``}(function(g){Object.defineProperty(g,"__esModule",{value:!0}),g.parseFragment=g.parse=g.TokenizerMode=g.Tokenizer=g.Token=g.html=g.foreignContent=g.ErrorCodes=g.serializeOuter=g.serialize=g.Parser=g.defaultTreeAdapter=void 0;const e=Uv;var I=Tk;Object.defineProperty(g,"defaultTreeAdapter",{enumerable:!0,get:function(){return I.defaultTreeAdapter}});var i=Uv;Object.defineProperty(g,"Parser",{enumerable:!0,get:function(){return i.Parser}});var n=r0;Object.defineProperty(g,"serialize",{enumerable:!0,get:function(){return n.serialize}}),Object.defineProperty(g,"serializeOuter",{enumerable:!0,get:function(){return n.serializeOuter}});var C=Gw;Object.defineProperty(g,"ErrorCodes",{enumerable:!0,get:function(){return C.ERR}}),g.foreignContent=mj,g.html=hl,g.Token=Xk;var r=yh;Object.defineProperty(g,"Tokenizer",{enumerable:!0,get:function(){return r.Tokenizer}}),Object.defineProperty(g,"TokenizerMode",{enumerable:!0,get:function(){return r.TokenizerMode}});function o(s,a){return e.Parser.parse(s,a)}g.parse=o;function A(s,a,l){typeof s=="string"&&(l=a,a=s,s=null);const c=e.Parser.getFragmentParser(s,l);return c.tokenizer.write(a,!0),c.getFragment()}g.parseFragment=A})(dwe);(function(g){Object.defineProperty(g,"__esModule",{value:!0}),g.adapter=g.serializeDoctypeContent=void 0;const e=dwe,I=Kn;function i(r){return new I.Text(r)}function n(r){const o=r.includes('"')?"'":'"';return o+r+o}function C(r,o,A){let s="!DOCTYPE ";return r&&(s+=r),o?s+=` PUBLIC ${n(o)}`:A&&(s+=" SYSTEM"),A&&(s+=` ${n(A)}`),s}g.serializeDoctypeContent=C,g.adapter={isCommentNode:I.isComment,isElementNode:I.isTag,isTextNode:I.isText,createDocument(){const r=new I.Document([]);return r["x-mode"]=e.html.DOCUMENT_MODE.NO_QUIRKS,r},createDocumentFragment(){return new I.Document([])},createElement(r,o,A){const s=Object.create(null),a=Object.create(null),l=Object.create(null);for(let u=0;u(0,I.isDirective)(c)&&c.name==="!doctype");l?l.data=a??null:(l=new I.ProcessingInstruction("!doctype",a),g.adapter.appendChild(r,l)),l["x-name"]=o??void 0,l["x-publicId"]=A??void 0,l["x-systemId"]=s??void 0},setDocumentMode(r,o){r["x-mode"]=o},getDocumentMode(r){return r["x-mode"]},detachNode(r){if(r.parent){const o=r.parent.children.indexOf(r),{prev:A,next:s}=r;r.prev=null,r.next=null,A&&(A.next=s),s&&(s.prev=A),r.parent.children.splice(o,1),r.parent=null}},insertText(r,o){const A=r.children[r.children.length-1];A&&(0,I.isText)(A)?A.data+=o:g.adapter.appendChild(r,i(o))},insertTextBefore(r,o,A){const s=r.children[r.children.indexOf(A)-1];s&&(0,I.isText)(s)?s.data+=o:g.adapter.insertBefore(r,i(o),A)},adoptAttributes(r,o){for(let A=0;A"u"&&(r.attribs[s]=o[A].value,r["x-attribsNamespace"][s]=o[A].namespace,r["x-attribsPrefix"][s]=o[A].prefix)}},getFirstChild(r){return r.children[0]},getChildNodes(r){return r.children},getParentNode(r){return r.parent},getAttrList(r){return r.attributes},getTagName(r){return r.name},getNamespaceURI(r){return r.namespace},getTextNodeContent(r){return r.data},getCommentNodeContent(r){return r.data},getDocumentTypeNodeName(r){var o;return(o=r["x-name"])!==null&&o!==void 0?o:""},getDocumentTypeNodePublicId(r){var o;return(o=r["x-publicId"])!==null&&o!==void 0?o:""},getDocumentTypeNodeSystemId(r){var o;return(o=r["x-systemId"])!==null&&o!==void 0?o:""},isDocumentTypeNode(r){return(0,I.isDirective)(r)&&r.name==="!doctype"},setNodeSourceCodeLocation(r,o){o&&(r.startIndex=o.startOffset,r.endIndex=o.endOffset),r.sourceCodeLocation=o},getNodeSourceCodeLocation(r){return r.sourceCodeLocation},updateNodeSourceCodeLocation(r,o){o.endOffset!=null&&(r.endIndex=o.endOffset),r.sourceCodeLocation=Object.assign(Object.assign({},r.sourceCodeLocation),o)}}})(uwe);var RZt=Le&&Le.__spreadArray||function(g,e,I){if(I||arguments.length===2)for(var i=0,n=e.length,C;i=I.Zero&&c<=I.Nine}function o(c){return c>=I.LowerA&&c<=I.LowerZ||c>=I.UpperA&&c<=I.UpperZ}function A(c){return c>=I.UpperA&&c<=I.UpperF||c>=I.LowerA&&c<=I.LowerF}var s;(function(c){c[c.NoValue=0]="NoValue",c[c.Unquoted=1]="Unquoted",c[c.Single=2]="Single",c[c.Double=3]="Double"})(s=g.QuoteType||(g.QuoteType={}));var a={Cdata:new Uint8Array([67,68,65,84,65,91]),CdataEnd:new Uint8Array([93,93,62]),CommentEnd:new Uint8Array([45,45,62]),ScriptEnd:new Uint8Array([60,47,115,99,114,105,112,116]),StyleEnd:new Uint8Array([60,47,115,116,121,108,101]),TitleEnd:new Uint8Array([60,47,116,105,116,108,101])},l=function(){function c(u,d){var h=u.xmlMode,m=h===void 0?!1:h,f=u.decodeEntities,b=f===void 0?!0:f;this.cbs=d,this.state=i.Text,this.buffer="",this.sectionStart=0,this.index=0,this.baseState=i.Text,this.isSpecial=!1,this.running=!0,this.offset=0,this.currentSequence=void 0,this.sequenceIndex=0,this.trieIndex=0,this.trieCurrent=0,this.entityResult=0,this.entityExcess=0,this.xmlMode=m,this.decodeEntities=b,this.entityTrie=m?e.xmlDecodeTree:e.htmlDecodeTree}return c.prototype.reset=function(){this.state=i.Text,this.buffer="",this.sectionStart=0,this.index=0,this.baseState=i.Text,this.currentSequence=void 0,this.running=!0,this.offset=0},c.prototype.write=function(u){this.offset+=this.buffer.length,this.buffer=u,this.parse()},c.prototype.end=function(){this.running&&this.finish()},c.prototype.pause=function(){this.running=!1},c.prototype.resume=function(){this.running=!0,this.indexthis.sectionStart&&this.cbs.ontext(this.sectionStart,this.index),this.state=i.BeforeTagName,this.sectionStart=this.index):this.decodeEntities&&u===I.Amp&&(this.state=i.BeforeEntity)},c.prototype.stateSpecialStartSequence=function(u){var d=this.sequenceIndex===this.currentSequence.length,h=d?C(u):(u|32)===this.currentSequence[this.sequenceIndex];if(!h)this.isSpecial=!1;else if(!d){this.sequenceIndex++;return}this.sequenceIndex=0,this.state=i.InTagName,this.stateInTagName(u)},c.prototype.stateInSpecialTag=function(u){if(this.sequenceIndex===this.currentSequence.length){if(u===I.Gt||n(u)){var d=this.index-this.currentSequence.length;if(this.sectionStart>14)-1;if(!this.allowLegacyEntity()&&u!==I.Semi)this.trieIndex+=h;else{var m=this.index-this.entityExcess+1;m>this.sectionStart&&this.emitPartial(this.sectionStart,m),this.entityResult=this.trieIndex,this.trieIndex+=h,this.entityExcess=0,this.sectionStart=this.index+1,h===0&&this.emitNamedEntity()}}},c.prototype.emitNamedEntity=function(){if(this.state=this.baseState,this.entityResult!==0){var u=(this.entityTrie[this.entityResult]&e.BinTrieFlags.VALUE_LENGTH)>>14;switch(u){case 1:{this.emitCodePoint(this.entityTrie[this.entityResult]&~e.BinTrieFlags.VALUE_LENGTH);break}case 2:{this.emitCodePoint(this.entityTrie[this.entityResult+1]);break}case 3:this.emitCodePoint(this.entityTrie[this.entityResult+1]),this.emitCodePoint(this.entityTrie[this.entityResult+2])}}},c.prototype.stateBeforeNumericEntity=function(u){(u|32)===I.LowerX?(this.entityExcess++,this.state=i.InHexEntity):(this.state=i.InNumericEntity,this.stateInNumericEntity(u))},c.prototype.emitNumericEntity=function(u){var d=this.index-this.entityExcess-1,h=d+2+ +(this.state===i.InHexEntity);h!==this.index&&(d>this.sectionStart&&this.emitPartial(this.sectionStart,d),this.sectionStart=this.index+Number(u),this.emitCodePoint((0,e.replaceCodePoint)(this.entityResult))),this.state=this.baseState},c.prototype.stateInNumericEntity=function(u){u===I.Semi?this.emitNumericEntity(!0):r(u)?(this.entityResult=this.entityResult*10+(u-I.Zero),this.entityExcess++):(this.allowLegacyEntity()?this.emitNumericEntity(!1):this.state=this.baseState,this.index--)},c.prototype.stateInHexEntity=function(u){u===I.Semi?this.emitNumericEntity(!0):r(u)?(this.entityResult=this.entityResult*16+(u-I.Zero),this.entityExcess++):A(u)?(this.entityResult=this.entityResult*16+((u|32)-I.LowerA+10),this.entityExcess++):(this.allowLegacyEntity()?this.emitNumericEntity(!1):this.state=this.baseState,this.index--)},c.prototype.allowLegacyEntity=function(){return!this.xmlMode&&(this.baseState===i.Text||this.baseState===i.InSpecialTag)},c.prototype.cleanup=function(){this.running&&this.sectionStart!==this.index&&(this.state===i.Text||this.state===i.InSpecialTag&&this.sequenceIndex===0?(this.cbs.ontext(this.sectionStart,this.index),this.sectionStart=this.index):(this.state===i.InAttributeValueDq||this.state===i.InAttributeValueSq||this.state===i.InAttributeValueNq)&&(this.cbs.onattribdata(this.sectionStart,this.index),this.sectionStart=this.index))},c.prototype.shouldContinue=function(){return this.index0&&r.has(this.stack[this.stack.length-1]);){var o=this.stack.pop();(i=(I=this.cbs).onclosetag)===null||i===void 0||i.call(I,o,!0)}this.isVoidElement(e)||(this.stack.push(e),fCe.has(e)?this.foreignContext.push(!0):pCe.has(e)&&this.foreignContext.push(!1)),(C=(n=this.cbs).onopentagname)===null||C===void 0||C.call(n,e),this.cbs.onopentag&&(this.attribs={})},g.prototype.endOpenTag=function(e){var I,i;this.startIndex=this.openTagStart,this.attribs&&((i=(I=this.cbs).onopentag)===null||i===void 0||i.call(I,this.tagname,this.attribs,e),this.attribs=null),this.cbs.onclosetag&&this.isVoidElement(this.tagname)&&this.cbs.onclosetag(this.tagname,!0),this.tagname=""},g.prototype.onopentagend=function(e){this.endIndex=e,this.endOpenTag(!1),this.startIndex=e+1},g.prototype.onclosetag=function(e,I){var i,n,C,r,o,A;this.endIndex=I;var s=this.getSlice(e,I);if(this.lowerCaseTagNames&&(s=s.toLowerCase()),(fCe.has(s)||pCe.has(s))&&this.foreignContext.pop(),this.isVoidElement(s))!this.options.xmlMode&&s==="br"&&((n=(i=this.cbs).onopentagname)===null||n===void 0||n.call(i,"br"),(r=(C=this.cbs).onopentag)===null||r===void 0||r.call(C,"br",{},!0),(A=(o=this.cbs).onclosetag)===null||A===void 0||A.call(o,"br",!1));else{var a=this.stack.lastIndexOf(s);if(a!==-1)if(this.cbs.onclosetag)for(var l=this.stack.length-a;l--;)this.cbs.onclosetag(this.stack.pop(),l!==0);else this.stack.length=a;else!this.options.xmlMode&&s==="p"&&(this.emitOpenTag("p"),this.closeCurrentTag(!0))}this.startIndex=I+1},g.prototype.onselfclosingtag=function(e){this.endIndex=e,this.options.xmlMode||this.options.recognizeSelfClosing||this.foreignContext[this.foreignContext.length-1]?(this.closeCurrentTag(!1),this.startIndex=e+1):this.onopentagend(e)},g.prototype.closeCurrentTag=function(e){var I,i,n=this.tagname;this.endOpenTag(e),this.stack[this.stack.length-1]===n&&((i=(I=this.cbs).onclosetag)===null||i===void 0||i.call(I,n,!e),this.stack.pop())},g.prototype.onattribname=function(e,I){this.startIndex=e;var i=this.getSlice(e,I);this.attribname=this.lowerCaseAttributeNames?i.toLowerCase():i},g.prototype.onattribdata=function(e,I){this.attribvalue+=this.getSlice(e,I)},g.prototype.onattribentity=function(e){this.attribvalue+=(0,uCe.fromCodePoint)(e)},g.prototype.onattribend=function(e,I){var i,n;this.endIndex=I,(n=(i=this.cbs).onattribute)===null||n===void 0||n.call(i,this.attribname,this.attribvalue,e===VR.QuoteType.Double?'"':e===VR.QuoteType.Single?"'":e===VR.QuoteType.NoValue?void 0:null),this.attribs&&!Object.prototype.hasOwnProperty.call(this.attribs,this.attribname)&&(this.attribs[this.attribname]=this.attribvalue),this.attribvalue=""},g.prototype.getInstructionName=function(e){var I=e.search(DZt),i=I<0?e:e.substr(0,I);return this.lowerCaseTagNames&&(i=i.toLowerCase()),i},g.prototype.ondeclaration=function(e,I){this.endIndex=I;var i=this.getSlice(e,I);if(this.cbs.onprocessinginstruction){var n=this.getInstructionName(i);this.cbs.onprocessinginstruction("!".concat(n),"!".concat(i))}this.startIndex=I+1},g.prototype.onprocessinginstruction=function(e,I){this.endIndex=I;var i=this.getSlice(e,I);if(this.cbs.onprocessinginstruction){var n=this.getInstructionName(i);this.cbs.onprocessinginstruction("?".concat(n),"?".concat(i))}this.startIndex=I+1},g.prototype.oncomment=function(e,I,i){var n,C,r,o;this.endIndex=I,(C=(n=this.cbs).oncomment)===null||C===void 0||C.call(n,this.getSlice(e,I-i)),(o=(r=this.cbs).oncommentend)===null||o===void 0||o.call(r),this.startIndex=I+1},g.prototype.oncdata=function(e,I,i){var n,C,r,o,A,s,a,l,c,u;this.endIndex=I;var d=this.getSlice(e,I-i);this.options.xmlMode||this.options.recognizeCDATA?((C=(n=this.cbs).oncdatastart)===null||C===void 0||C.call(n),(o=(r=this.cbs).ontext)===null||o===void 0||o.call(r,d),(s=(A=this.cbs).oncdataend)===null||s===void 0||s.call(A)):((l=(a=this.cbs).oncomment)===null||l===void 0||l.call(a,"[CDATA[".concat(d,"]]")),(u=(c=this.cbs).oncommentend)===null||u===void 0||u.call(c)),this.startIndex=I+1},g.prototype.onend=function(){var e,I;if(this.cbs.onclosetag){this.endIndex=this.startIndex;for(var i=this.stack.length;i>0;this.cbs.onclosetag(this.stack[--i],!0));}(I=(e=this.cbs).onend)===null||I===void 0||I.call(e)},g.prototype.reset=function(){var e,I,i,n;(I=(e=this.cbs).onreset)===null||I===void 0||I.call(e),this.tokenizer.reset(),this.tagname="",this.attribname="",this.attribs=null,this.stack.length=0,this.startIndex=0,this.endIndex=0,(n=(i=this.cbs).onparserinit)===null||n===void 0||n.call(i,this),this.buffers.length=0,this.bufferOffset=0,this.writeIndex=0,this.ended=!1},g.prototype.parseComplete=function(e){this.reset(),this.end(e)},g.prototype.getSlice=function(e,I){for(;e-this.bufferOffset>=this.buffers[0].length;)this.shiftBuffer();for(var i=this.buffers[0].slice(e-this.bufferOffset,I-this.bufferOffset);I-this.bufferOffset>this.buffers[0].length;)this.shiftBuffer(),i+=this.buffers[0].slice(0,I-this.bufferOffset);return i},g.prototype.shiftBuffer=function(){this.bufferOffset+=this.buffers[0].length,this.writeIndex--,this.buffers.shift()},g.prototype.write=function(e){var I,i;if(this.ended){(i=(I=this.cbs).onerror)===null||i===void 0||i.call(I,new Error(".write() after done!"));return}this.buffers.push(e),this.tokenizer.running&&(this.tokenizer.write(e),this.writeIndex++)},g.prototype.end=function(e){var I,i;if(this.ended){(i=(I=this.cbs).onerror)===null||i===void 0||i.call(I,new Error(".end() after done!"));return}e&&this.write(e),this.ended=!0,this.tokenizer.end()},g.prototype.pause=function(){this.tokenizer.pause()},g.prototype.resume=function(){for(this.tokenizer.resume();this.tokenizer.running&&this.writeIndex option[selected])) > :first-of-type)",checkbox:"[type=checkbox]",file:"[type=file]",password:"[type=password]",radio:"[type=radio]",reset:"[type=reset]",image:"[type=image]",submit:"[type=submit]",parent:":not(:empty)",header:":is(h1, h2, h3, h4, h5, h6)",button:":is(button, input[type=button])",input:":is(input, textarea, select, button)",text:"input:is(:not([type!='']), [type=text])"};var BN={};(function(e){var g=Le&&Le.__spreadArray||function(s,a,l){if(l||arguments.length===2)for(var c=0,u=a.length,d;c"u")return function(a){for(var l=a;l=kD(l,C);)if(e(l))return!0;return!1};var A=new WeakSet;return function(a){for(var l=a;l=kD(l,C);)if(!A.has(l)){if(C.isTag(l)&&e(l))return!0;A.add(l)}return!1}}case"_flexibleDescendant":return function(a){var l=a;do if(e(l))return!0;while(l=kD(l,C));return!1};case ho.SelectorType.Parent:return function(a){return C.getChildren(a).some(function(l){return C.isTag(l)&&e(l)})};case ho.SelectorType.Child:return function(a){var l=C.getParent(a);return l!=null&&C.isTag(l)&&e(l)};case ho.SelectorType.Sibling:return function(a){for(var l=C.getSiblings(a),c=0;c0&&(0,L3.isTraversal)(o[0])&&o[0].type!==as.SelectorType.Descendant))if(n&&!o.some(bBe))o.unshift(Tft);else continue;o.unshift(kft)}}function VQ(e,g,I){var i;e.forEach(L3.default),I=(i=g.context)!==null&&i!==void 0?i:I;var n=Array.isArray(I),C=I&&(Array.isArray(I)?I:[I]);if(g.relativeSelector!==!1)Yft(e,g,C);else if(e.some(function(A){return A.length>0&&(0,L3.isTraversal)(A[0])}))throw new Error("Relative selectors are not allowed when the `relativeSelector` option is disabled");var r=!1,o=e.map(function(A){if(A.length>=2){var s=A[0],a=A[1];s.type!==as.SelectorType.Pseudo||s.name!=="scope"||(n&&a.type===as.SelectorType.Descendant?A[1]=Nft:(a.type===as.SelectorType.Adjacent||a.type===as.SelectorType.Sibling)&&(r=!0))}return Kft(A,g,C)}).reduce(Dft,Ac.default.falseFunc);return o.shouldTestNextSiblings=r,o}Bc.compileToken=VQ;function Kft(e,g,I){var i;return e.reduce(function(n,C){return n===Ac.default.falseFunc?Ac.default.falseFunc:(0,Xft.compileGeneralSelector)(n,C,g,I,VQ)},(i=g.rootFunc)!==null&&i!==void 0?i:Ac.default.trueFunc)}function Dft(e,g){return g===Ac.default.falseFunc||e===Ac.default.trueFunc?e:e===Ac.default.falseFunc||g===Ac.default.trueFunc?g:function(i){return e(i)||g(i)}}(function(e){var g=Le&&Le.__createBinding||(Object.create?function(b,p,y,Z){Z===void 0&&(Z=y);var B=Object.getOwnPropertyDescriptor(p,y);(!B||("get"in B?!p.__esModule:B.writable||B.configurable))&&(B={enumerable:!0,get:function(){return p[y]}}),Object.defineProperty(b,Z,B)}:function(b,p,y,Z){Z===void 0&&(Z=y),b[Z]=p[y]}),I=Le&&Le.__setModuleDefault||(Object.create?function(b,p){Object.defineProperty(b,"default",{enumerable:!0,value:p})}:function(b,p){b.default=p}),i=Le&&Le.__importStar||function(b){if(b&&b.__esModule)return b;var p={};if(b!=null)for(var y in b)y!=="default"&&Object.prototype.hasOwnProperty.call(b,y)&&g(p,b,y);return I(p,b),p},n=Le&&Le.__importDefault||function(b){return b&&b.__esModule?b:{default:b}};Object.defineProperty(e,"__esModule",{value:!0}),e.aliases=e.pseudos=e.filters=e.is=e.selectOne=e.selectAll=e.prepareContext=e._compileToken=e._compileUnsafe=e.compile=void 0;var C=i(gA),r=n(qh),o=Bc,A=BN,s=function(b,p){return b===p},a={adapter:C,equals:s};function l(b){var p,y,Z,B,G=b??a;return(p=G.adapter)!==null&&p!==void 0||(G.adapter=C),(y=G.equals)!==null&&y!==void 0||(G.equals=(B=(Z=G.adapter)===null||Z===void 0?void 0:Z.equals)!==null&&B!==void 0?B:s),G}function c(b){return function(y,Z,B){var G=l(Z);return b(y,G,B)}}e.compile=c(o.compile),e._compileUnsafe=c(o.compileUnsafe),e._compileToken=c(o.compileToken);function u(b){return function(y,Z,B){var G=l(B);typeof y!="function"&&(y=(0,o.compileUnsafe)(y,G,Z));var v=d(Z,G.adapter,y.shouldTestNextSiblings);return b(y,v,G)}}function d(b,p,y){return y===void 0&&(y=!1),y&&(b=h(b,p)),Array.isArray(b)?p.removeSubsets(b):p.getChildren(b)}e.prepareContext=d;function h(b,p){for(var y=Array.isArray(b)?b.slice(0):[b],Z=y.length,B=0;B=0?r+1:1/0:0;case"lt":return isFinite(r)?r>=0?Math.min(r,C):1/0:0;case"gt":return isFinite(r)?1/0:0;case"odd":return 2*C;case"even":return 2*C-1;case"last":case"not":return 1/0}}e.getLimit=I})(RQ);Object.defineProperty(Xb,"__esModule",{value:!0});Xb.groupSelectors=Xb.getDocumentRoot=void 0;var xft=RQ;function Fft(e){for(;e.parent;)e=e.parent;return e}Xb.getDocumentRoot=Fft;function Eft(e){for(var g=[],I=[],i=0,n=e;i0&&V.some((0,o._compileToken)(R,X))||H.some(function(Y){return y(Y,V,X).length>0})}e.some=m;function f(V,S,X,W){var R=typeof X=="string"?parseInt(X,10):NaN;switch(V){case"first":case"lt":return S;case"last":return S.length>0?[S[S.length-1]]:S;case"nth":case"eq":return isFinite(R)&&Math.abs(R)1&&r.length>1?I.reduce(function(o,A){return A(o)},r):r)}}}var DS=WQ(function(e,g){for(var I,i=[],n=0;n0})}Rt.has=tpt;function gpt(){return this.length>1?this._make(this[0]):this}Rt.first=gpt;function Ipt(){return this.length>0?this._make(this[this.length-1]):this}Rt.last=Ipt;function ipt(e){var g;return e=+e,e===0&&this.length<=1?this:(e<0&&(e=this.length+e),this._make((g=this[e])!==null&&g!==void 0?g:[]))}Rt.eq=ipt;function npt(e){return e==null?this.toArray():this[e<0?this.length+e:e]}Rt.get=npt;function Cpt(){return Array.prototype.slice.call(this)}Rt.toArray=Cpt;function rpt(e){var g,I;return e==null?(g=this.parent().children(),I=this[0]):typeof e=="string"?(g=this._make(e),I=this[0]):(g=this,I=(0,oA.isCheerio)(e)?e[0]:e),Array.prototype.indexOf.call(g,I)}Rt.index=rpt;function opt(e,g){return this._make(Array.prototype.slice.call(this,e,g))}Rt.slice=opt;function Apt(){var e;return(e=this.prevObject)!==null&&e!==void 0?e:this._make([])}Rt.end=Apt;function apt(e,g){var I=this._make(e,g),i=(0,da.uniqueSort)(U3(U3([],this.get(),!0),I.get(),!0));return this._make(i)}Rt.add=apt;function spt(e){return this.prevObject?this.add(e?this.prevObject.filter(e):this.prevObject):this}Rt.addBack=spt;var Ig={},Ih={};Object.defineProperty(Ih,"__esModule",{value:!0});Ih.update=Ih.getParse=void 0;var lpt=gA,tne=kn;function cpt(e){return function(I,i,n,C){if(typeof Buffer<"u"&&Buffer.isBuffer(I)&&(I=I.toString()),typeof I=="string")return e(I,i,n,C);var r=I;if(!Array.isArray(r)&&(0,tne.isDocument)(r))return r;var o=new tne.Document([]);return yBe(r,o),o}}Ih.getParse=cpt;function yBe(e,g){var I=Array.isArray(e)?e:[e];g?g.children=I:g=null;for(var i=0;i=e.length?null:e[g+I],a=0;a-1&&(c.children.splice(d,1),n===c&&g>d&&o[0]--)}l.parent=n,l.prev&&(l.prev.next=(C=l.next)!==null&&C!==void 0?C:null),l.next&&(l.next.prev=(r=l.prev)!==null&&r!==void 0?r:null),l.prev=a===0?A:i[a-1],l.next=a===i.length-1?s:i[a+1]}return A&&(A.next=i[0]),s&&(s.prev=i[i.length-1]),e.splice.apply(e,o)}function mpt(e){var g=(0,Hi.isCheerio)(e)?e:this._make(e);return g.append(this),this}Ig.appendTo=mpt;function fpt(e){var g=(0,Hi.isCheerio)(e)?e:this._make(e);return g.prepend(this),this}Ig.prependTo=fpt;Ig.append=ZBe(function(e,g,I){gu(g,g.length,0,e,I)});Ig.prepend=ZBe(function(e,g,I){gu(g,0,0,e,I)});function GBe(e){return function(g){for(var I=this.length-1,i=this.parents().last(),n=0;n0&&I!==void 0&&(g[I]+=";".concat(o))}else I=C.slice(0,r).trim(),g[I]=C.slice(r+1).trim()}return g}var Tb={};Object.defineProperty(Tb,"__esModule",{value:!0});Tb.serializeArray=Tb.serialize=void 0;var kpt=tu,Ine="input,select,textarea,keygen",Ypt=/%20/g,ine=/\r?\n/g;function Kpt(){var e=this.serializeArray(),g=e.map(function(I){return"".concat(encodeURIComponent(I.name),"=").concat(encodeURIComponent(I.value))});return g.join("&").replace(Ypt,"+")}Tb.serialize=Kpt;function Dpt(){var e=this;return this.map(function(g,I){var i=e._make(I);return(0,kpt.isTag)(I)&&I.name==="form"?i.find(Ine).toArray():i.filter(Ine).toArray()}).filter('[name!=""]:enabled:not(:submit, :button, :image, :reset, :file):matches([checked], :not(:checkbox, :radio))').map(function(g,I){var i,n=e._make(I),C=n.attr("name"),r=(i=n.val())!==null&&i!==void 0?i:"";return Array.isArray(r)?r.map(function(o){return{name:C,value:o.replace(ine,`\r +`)}}):{name:C,value:r.replace(ine,`\r +`)}}).toArray()}Tb.serializeArray=Dpt;var xpt=Le&&Le.__createBinding||(Object.create?function(e,g,I,i){i===void 0&&(i=I);var n=Object.getOwnPropertyDescriptor(g,I);(!n||("get"in n?!g.__esModule:n.writable||n.configurable))&&(n={enumerable:!0,get:function(){return g[I]}}),Object.defineProperty(e,i,n)}:function(e,g,I,i){i===void 0&&(i=I),e[i]=g[I]}),Fpt=Le&&Le.__setModuleDefault||(Object.create?function(e,g){Object.defineProperty(e,"default",{enumerable:!0,value:g})}:function(e,g){e.default=g}),FS=Le&&Le.__importStar||function(e){if(e&&e.__esModule)return e;var g={};if(e!=null)for(var I in e)I!=="default"&&Object.prototype.hasOwnProperty.call(e,I)&&xpt(g,e,I);return Fpt(g,e),g};Object.defineProperty(bN,"__esModule",{value:!0});bN.Cheerio=void 0;var Ept=FS(li),Mpt=FS(Rt),zpt=FS(Ig),Ppt=FS(wN),Jpt=FS(Tb),ES=function(){function e(g,I,i){if(this.length=0,this.options=i,this._root=I,g){for(var n=0;n=55296&&o<=57343}e.isSurrogate=I;function i(o){return o>=56320&&o<=57343}e.isSurrogatePair=i;function n(o,A){return(o-55296)*1024+9216+A}e.getSurrogatePairCodePoint=n;function C(o){return o!==32&&o!==10&&o!==13&&o!==9&&o!==12&&o>=1&&o<=31||o>=127&&o<=159}e.isControlCodePoint=C;function r(o){return o>=64976&&o<=65007||g.has(o)}e.isUndefinedCodePoint=r})(RN);var MS={};(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.ERR=void 0,function(g){g.controlCharacterInInputStream="control-character-in-input-stream",g.noncharacterInInputStream="noncharacter-in-input-stream",g.surrogateInInputStream="surrogate-in-input-stream",g.nonVoidHtmlElementStartTagWithTrailingSolidus="non-void-html-element-start-tag-with-trailing-solidus",g.endTagWithAttributes="end-tag-with-attributes",g.endTagWithTrailingSolidus="end-tag-with-trailing-solidus",g.unexpectedSolidusInTag="unexpected-solidus-in-tag",g.unexpectedNullCharacter="unexpected-null-character",g.unexpectedQuestionMarkInsteadOfTagName="unexpected-question-mark-instead-of-tag-name",g.invalidFirstCharacterOfTagName="invalid-first-character-of-tag-name",g.unexpectedEqualsSignBeforeAttributeName="unexpected-equals-sign-before-attribute-name",g.missingEndTagName="missing-end-tag-name",g.unexpectedCharacterInAttributeName="unexpected-character-in-attribute-name",g.unknownNamedCharacterReference="unknown-named-character-reference",g.missingSemicolonAfterCharacterReference="missing-semicolon-after-character-reference",g.unexpectedCharacterAfterDoctypeSystemIdentifier="unexpected-character-after-doctype-system-identifier",g.unexpectedCharacterInUnquotedAttributeValue="unexpected-character-in-unquoted-attribute-value",g.eofBeforeTagName="eof-before-tag-name",g.eofInTag="eof-in-tag",g.missingAttributeValue="missing-attribute-value",g.missingWhitespaceBetweenAttributes="missing-whitespace-between-attributes",g.missingWhitespaceAfterDoctypePublicKeyword="missing-whitespace-after-doctype-public-keyword",g.missingWhitespaceBetweenDoctypePublicAndSystemIdentifiers="missing-whitespace-between-doctype-public-and-system-identifiers",g.missingWhitespaceAfterDoctypeSystemKeyword="missing-whitespace-after-doctype-system-keyword",g.missingQuoteBeforeDoctypePublicIdentifier="missing-quote-before-doctype-public-identifier",g.missingQuoteBeforeDoctypeSystemIdentifier="missing-quote-before-doctype-system-identifier",g.missingDoctypePublicIdentifier="missing-doctype-public-identifier",g.missingDoctypeSystemIdentifier="missing-doctype-system-identifier",g.abruptDoctypePublicIdentifier="abrupt-doctype-public-identifier",g.abruptDoctypeSystemIdentifier="abrupt-doctype-system-identifier",g.cdataInHtmlContent="cdata-in-html-content",g.incorrectlyOpenedComment="incorrectly-opened-comment",g.eofInScriptHtmlCommentLikeText="eof-in-script-html-comment-like-text",g.eofInDoctype="eof-in-doctype",g.nestedComment="nested-comment",g.abruptClosingOfEmptyComment="abrupt-closing-of-empty-comment",g.eofInComment="eof-in-comment",g.incorrectlyClosedComment="incorrectly-closed-comment",g.eofInCdata="eof-in-cdata",g.absenceOfDigitsInNumericCharacterReference="absence-of-digits-in-numeric-character-reference",g.nullCharacterReference="null-character-reference",g.surrogateCharacterReference="surrogate-character-reference",g.characterReferenceOutsideUnicodeRange="character-reference-outside-unicode-range",g.controlCharacterReference="control-character-reference",g.noncharacterCharacterReference="noncharacter-character-reference",g.missingWhitespaceBeforeDoctypeName="missing-whitespace-before-doctype-name",g.missingDoctypeName="missing-doctype-name",g.invalidCharacterSequenceAfterDoctypeName="invalid-character-sequence-after-doctype-name",g.duplicateAttribute="duplicate-attribute",g.nonConformingDoctype="non-conforming-doctype",g.missingDoctype="missing-doctype",g.misplacedDoctype="misplaced-doctype",g.endTagWithoutMatchingOpenElement="end-tag-without-matching-open-element",g.closingOfElementWithOpenChildElements="closing-of-element-with-open-child-elements",g.disallowedContentInNoscriptInHead="disallowed-content-in-noscript-in-head",g.openElementsLeftAfterEof="open-elements-left-after-eof",g.abandonedHeadElementChild="abandoned-head-element-child",g.misplacedStartTagForHeadElement="misplaced-start-tag-for-head-element",g.nestedNoscriptInHead="nested-noscript-in-head",g.eofInElementThatCanContainOnlyText="eof-in-element-that-can-contain-only-text"}(e.ERR||(e.ERR={}))})(MS);function qpt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function nne(e,g){for(var I=0;Ithis.bufferWaterline}},{key:"dropParsedChunk",value:function(){this.willDropParsedChunk()&&(this.html=this.html.substring(this.pos),this.lineStartPos-=this.pos,this.droppedBufferSize+=this.pos,this.pos=0,this.lastGapPos=-2,this.gapStack.length=0)}},{key:"write",value:function(I,i){this.html.length>0?this.html+=I:this.html=I,this.endOfChunkHit=!1,this.lastChunkWritten=i}},{key:"insertHtmlAtCurrentPos",value:function(I){this.html=this.html.substring(0,this.pos+1)+I+this.html.substring(this.pos+1),this.endOfChunkHit=!1}},{key:"startsWith",value:function(I,i){if(this.pos+I.length>this.html.length)return this.endOfChunkHit=!this.lastChunkWritten,!1;if(i)return this.html.startsWith(I,this.pos);for(let n=0;n=this.html.length)return this.endOfChunkHit=!this.lastChunkWritten,xn.CODE_POINTS.EOF;const n=this.html.charCodeAt(i);return n===xn.CODE_POINTS.CARRIAGE_RETURN?xn.CODE_POINTS.LINE_FEED:n}},{key:"advance",value:function(){if(this.pos++,this.isEol&&(this.isEol=!1,this.line++,this.lineStartPos=this.pos),this.pos>=this.html.length)return this.endOfChunkHit=!this.lastChunkWritten,xn.CODE_POINTS.EOF;let I=this.html.charCodeAt(this.pos);return I===xn.CODE_POINTS.CARRIAGE_RETURN?(this.isEol=!0,this.skipNextNewLine=!0,xn.CODE_POINTS.LINE_FEED):I===xn.CODE_POINTS.LINE_FEED&&(this.isEol=!0,this.skipNextNewLine)?(this.line--,this.skipNextNewLine=!1,this._addGap(),this.advance()):(this.skipNextNewLine=!1,(0,xn.isSurrogate)(I)&&(I=this._processSurrogate(I)),this.handler.onParseError===null||I>31&&I<127||I===xn.CODE_POINTS.LINE_FEED||I===xn.CODE_POINTS.CARRIAGE_RETURN||I>159&&I<64976||this._checkForProblematicCharacters(I),I)}},{key:"_checkForProblematicCharacters",value:function(I){(0,xn.isControlCodePoint)(I)?this._err(KD.ERR.controlCharacterInInputStream):(0,xn.isUndefinedCodePoint)(I)&&this._err(KD.ERR.noncharacterInInputStream)}},{key:"retreat",value:function(I){for(this.pos-=I;this.pos=0;n--)if(I.attrs[n].name===i)return I.attrs[n].value;return null}e.getTokenAttr=g})(WN);var $s={};(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.hasUnescapedText=e.isNumberedHeader=e.SPECIAL_ELEMENTS=e.getTagID=e.TAG_ID=e.TAG_NAMES=e.DOCUMENT_MODE=e.ATTRS=e.NS=void 0;var g;(function(a){a.HTML="http://www.w3.org/1999/xhtml",a.MATHML="http://www.w3.org/1998/Math/MathML",a.SVG="http://www.w3.org/2000/svg",a.XLINK="http://www.w3.org/1999/xlink",a.XML="http://www.w3.org/XML/1998/namespace",a.XMLNS="http://www.w3.org/2000/xmlns/"})(g=e.NS||(e.NS={})),function(a){a.TYPE="type",a.ACTION="action",a.ENCODING="encoding",a.PROMPT="prompt",a.NAME="name",a.COLOR="color",a.FACE="face",a.SIZE="size"}(e.ATTRS||(e.ATTRS={})),function(a){a.NO_QUIRKS="no-quirks",a.QUIRKS="quirks",a.LIMITED_QUIRKS="limited-quirks"}(e.DOCUMENT_MODE||(e.DOCUMENT_MODE={}));var I;(function(a){a.A="a",a.ADDRESS="address",a.ANNOTATION_XML="annotation-xml",a.APPLET="applet",a.AREA="area",a.ARTICLE="article",a.ASIDE="aside",a.B="b",a.BASE="base",a.BASEFONT="basefont",a.BGSOUND="bgsound",a.BIG="big",a.BLOCKQUOTE="blockquote",a.BODY="body",a.BR="br",a.BUTTON="button",a.CAPTION="caption",a.CENTER="center",a.CODE="code",a.COL="col",a.COLGROUP="colgroup",a.DD="dd",a.DESC="desc",a.DETAILS="details",a.DIALOG="dialog",a.DIR="dir",a.DIV="div",a.DL="dl",a.DT="dt",a.EM="em",a.EMBED="embed",a.FIELDSET="fieldset",a.FIGCAPTION="figcaption",a.FIGURE="figure",a.FONT="font",a.FOOTER="footer",a.FOREIGN_OBJECT="foreignObject",a.FORM="form",a.FRAME="frame",a.FRAMESET="frameset",a.H1="h1",a.H2="h2",a.H3="h3",a.H4="h4",a.H5="h5",a.H6="h6",a.HEAD="head",a.HEADER="header",a.HGROUP="hgroup",a.HR="hr",a.HTML="html",a.I="i",a.IMG="img",a.IMAGE="image",a.INPUT="input",a.IFRAME="iframe",a.KEYGEN="keygen",a.LABEL="label",a.LI="li",a.LINK="link",a.LISTING="listing",a.MAIN="main",a.MALIGNMARK="malignmark",a.MARQUEE="marquee",a.MATH="math",a.MENU="menu",a.META="meta",a.MGLYPH="mglyph",a.MI="mi",a.MO="mo",a.MN="mn",a.MS="ms",a.MTEXT="mtext",a.NAV="nav",a.NOBR="nobr",a.NOFRAMES="noframes",a.NOEMBED="noembed",a.NOSCRIPT="noscript",a.OBJECT="object",a.OL="ol",a.OPTGROUP="optgroup",a.OPTION="option",a.P="p",a.PARAM="param",a.PLAINTEXT="plaintext",a.PRE="pre",a.RB="rb",a.RP="rp",a.RT="rt",a.RTC="rtc",a.RUBY="ruby",a.S="s",a.SCRIPT="script",a.SECTION="section",a.SELECT="select",a.SOURCE="source",a.SMALL="small",a.SPAN="span",a.STRIKE="strike",a.STRONG="strong",a.STYLE="style",a.SUB="sub",a.SUMMARY="summary",a.SUP="sup",a.TABLE="table",a.TBODY="tbody",a.TEMPLATE="template",a.TEXTAREA="textarea",a.TFOOT="tfoot",a.TD="td",a.TH="th",a.THEAD="thead",a.TITLE="title",a.TR="tr",a.TRACK="track",a.TT="tt",a.U="u",a.UL="ul",a.SVG="svg",a.VAR="var",a.WBR="wbr",a.XMP="xmp"})(I=e.TAG_NAMES||(e.TAG_NAMES={}));var i;(function(a){a[a.UNKNOWN=0]="UNKNOWN",a[a.A=1]="A",a[a.ADDRESS=2]="ADDRESS",a[a.ANNOTATION_XML=3]="ANNOTATION_XML",a[a.APPLET=4]="APPLET",a[a.AREA=5]="AREA",a[a.ARTICLE=6]="ARTICLE",a[a.ASIDE=7]="ASIDE",a[a.B=8]="B",a[a.BASE=9]="BASE",a[a.BASEFONT=10]="BASEFONT",a[a.BGSOUND=11]="BGSOUND",a[a.BIG=12]="BIG",a[a.BLOCKQUOTE=13]="BLOCKQUOTE",a[a.BODY=14]="BODY",a[a.BR=15]="BR",a[a.BUTTON=16]="BUTTON",a[a.CAPTION=17]="CAPTION",a[a.CENTER=18]="CENTER",a[a.CODE=19]="CODE",a[a.COL=20]="COL",a[a.COLGROUP=21]="COLGROUP",a[a.DD=22]="DD",a[a.DESC=23]="DESC",a[a.DETAILS=24]="DETAILS",a[a.DIALOG=25]="DIALOG",a[a.DIR=26]="DIR",a[a.DIV=27]="DIV",a[a.DL=28]="DL",a[a.DT=29]="DT",a[a.EM=30]="EM",a[a.EMBED=31]="EMBED",a[a.FIELDSET=32]="FIELDSET",a[a.FIGCAPTION=33]="FIGCAPTION",a[a.FIGURE=34]="FIGURE",a[a.FONT=35]="FONT",a[a.FOOTER=36]="FOOTER",a[a.FOREIGN_OBJECT=37]="FOREIGN_OBJECT",a[a.FORM=38]="FORM",a[a.FRAME=39]="FRAME",a[a.FRAMESET=40]="FRAMESET",a[a.H1=41]="H1",a[a.H2=42]="H2",a[a.H3=43]="H3",a[a.H4=44]="H4",a[a.H5=45]="H5",a[a.H6=46]="H6",a[a.HEAD=47]="HEAD",a[a.HEADER=48]="HEADER",a[a.HGROUP=49]="HGROUP",a[a.HR=50]="HR",a[a.HTML=51]="HTML",a[a.I=52]="I",a[a.IMG=53]="IMG",a[a.IMAGE=54]="IMAGE",a[a.INPUT=55]="INPUT",a[a.IFRAME=56]="IFRAME",a[a.KEYGEN=57]="KEYGEN",a[a.LABEL=58]="LABEL",a[a.LI=59]="LI",a[a.LINK=60]="LINK",a[a.LISTING=61]="LISTING",a[a.MAIN=62]="MAIN",a[a.MALIGNMARK=63]="MALIGNMARK",a[a.MARQUEE=64]="MARQUEE",a[a.MATH=65]="MATH",a[a.MENU=66]="MENU",a[a.META=67]="META",a[a.MGLYPH=68]="MGLYPH",a[a.MI=69]="MI",a[a.MO=70]="MO",a[a.MN=71]="MN",a[a.MS=72]="MS",a[a.MTEXT=73]="MTEXT",a[a.NAV=74]="NAV",a[a.NOBR=75]="NOBR",a[a.NOFRAMES=76]="NOFRAMES",a[a.NOEMBED=77]="NOEMBED",a[a.NOSCRIPT=78]="NOSCRIPT",a[a.OBJECT=79]="OBJECT",a[a.OL=80]="OL",a[a.OPTGROUP=81]="OPTGROUP",a[a.OPTION=82]="OPTION",a[a.P=83]="P",a[a.PARAM=84]="PARAM",a[a.PLAINTEXT=85]="PLAINTEXT",a[a.PRE=86]="PRE",a[a.RB=87]="RB",a[a.RP=88]="RP",a[a.RT=89]="RT",a[a.RTC=90]="RTC",a[a.RUBY=91]="RUBY",a[a.S=92]="S",a[a.SCRIPT=93]="SCRIPT",a[a.SECTION=94]="SECTION",a[a.SELECT=95]="SELECT",a[a.SOURCE=96]="SOURCE",a[a.SMALL=97]="SMALL",a[a.SPAN=98]="SPAN",a[a.STRIKE=99]="STRIKE",a[a.STRONG=100]="STRONG",a[a.STYLE=101]="STYLE",a[a.SUB=102]="SUB",a[a.SUMMARY=103]="SUMMARY",a[a.SUP=104]="SUP",a[a.TABLE=105]="TABLE",a[a.TBODY=106]="TBODY",a[a.TEMPLATE=107]="TEMPLATE",a[a.TEXTAREA=108]="TEXTAREA",a[a.TFOOT=109]="TFOOT",a[a.TD=110]="TD",a[a.TH=111]="TH",a[a.THEAD=112]="THEAD",a[a.TITLE=113]="TITLE",a[a.TR=114]="TR",a[a.TRACK=115]="TRACK",a[a.TT=116]="TT",a[a.U=117]="U",a[a.UL=118]="UL",a[a.SVG=119]="SVG",a[a.VAR=120]="VAR",a[a.WBR=121]="WBR",a[a.XMP=122]="XMP"})(i=e.TAG_ID||(e.TAG_ID={}));const n=new Map([[I.A,i.A],[I.ADDRESS,i.ADDRESS],[I.ANNOTATION_XML,i.ANNOTATION_XML],[I.APPLET,i.APPLET],[I.AREA,i.AREA],[I.ARTICLE,i.ARTICLE],[I.ASIDE,i.ASIDE],[I.B,i.B],[I.BASE,i.BASE],[I.BASEFONT,i.BASEFONT],[I.BGSOUND,i.BGSOUND],[I.BIG,i.BIG],[I.BLOCKQUOTE,i.BLOCKQUOTE],[I.BODY,i.BODY],[I.BR,i.BR],[I.BUTTON,i.BUTTON],[I.CAPTION,i.CAPTION],[I.CENTER,i.CENTER],[I.CODE,i.CODE],[I.COL,i.COL],[I.COLGROUP,i.COLGROUP],[I.DD,i.DD],[I.DESC,i.DESC],[I.DETAILS,i.DETAILS],[I.DIALOG,i.DIALOG],[I.DIR,i.DIR],[I.DIV,i.DIV],[I.DL,i.DL],[I.DT,i.DT],[I.EM,i.EM],[I.EMBED,i.EMBED],[I.FIELDSET,i.FIELDSET],[I.FIGCAPTION,i.FIGCAPTION],[I.FIGURE,i.FIGURE],[I.FONT,i.FONT],[I.FOOTER,i.FOOTER],[I.FOREIGN_OBJECT,i.FOREIGN_OBJECT],[I.FORM,i.FORM],[I.FRAME,i.FRAME],[I.FRAMESET,i.FRAMESET],[I.H1,i.H1],[I.H2,i.H2],[I.H3,i.H3],[I.H4,i.H4],[I.H5,i.H5],[I.H6,i.H6],[I.HEAD,i.HEAD],[I.HEADER,i.HEADER],[I.HGROUP,i.HGROUP],[I.HR,i.HR],[I.HTML,i.HTML],[I.I,i.I],[I.IMG,i.IMG],[I.IMAGE,i.IMAGE],[I.INPUT,i.INPUT],[I.IFRAME,i.IFRAME],[I.KEYGEN,i.KEYGEN],[I.LABEL,i.LABEL],[I.LI,i.LI],[I.LINK,i.LINK],[I.LISTING,i.LISTING],[I.MAIN,i.MAIN],[I.MALIGNMARK,i.MALIGNMARK],[I.MARQUEE,i.MARQUEE],[I.MATH,i.MATH],[I.MENU,i.MENU],[I.META,i.META],[I.MGLYPH,i.MGLYPH],[I.MI,i.MI],[I.MO,i.MO],[I.MN,i.MN],[I.MS,i.MS],[I.MTEXT,i.MTEXT],[I.NAV,i.NAV],[I.NOBR,i.NOBR],[I.NOFRAMES,i.NOFRAMES],[I.NOEMBED,i.NOEMBED],[I.NOSCRIPT,i.NOSCRIPT],[I.OBJECT,i.OBJECT],[I.OL,i.OL],[I.OPTGROUP,i.OPTGROUP],[I.OPTION,i.OPTION],[I.P,i.P],[I.PARAM,i.PARAM],[I.PLAINTEXT,i.PLAINTEXT],[I.PRE,i.PRE],[I.RB,i.RB],[I.RP,i.RP],[I.RT,i.RT],[I.RTC,i.RTC],[I.RUBY,i.RUBY],[I.S,i.S],[I.SCRIPT,i.SCRIPT],[I.SECTION,i.SECTION],[I.SELECT,i.SELECT],[I.SOURCE,i.SOURCE],[I.SMALL,i.SMALL],[I.SPAN,i.SPAN],[I.STRIKE,i.STRIKE],[I.STRONG,i.STRONG],[I.STYLE,i.STYLE],[I.SUB,i.SUB],[I.SUMMARY,i.SUMMARY],[I.SUP,i.SUP],[I.TABLE,i.TABLE],[I.TBODY,i.TBODY],[I.TEMPLATE,i.TEMPLATE],[I.TEXTAREA,i.TEXTAREA],[I.TFOOT,i.TFOOT],[I.TD,i.TD],[I.TH,i.TH],[I.THEAD,i.THEAD],[I.TITLE,i.TITLE],[I.TR,i.TR],[I.TRACK,i.TRACK],[I.TT,i.TT],[I.U,i.U],[I.UL,i.UL],[I.SVG,i.SVG],[I.VAR,i.VAR],[I.WBR,i.WBR],[I.XMP,i.XMP]]);function C(a){var l;return(l=n.get(a))!==null&&l!==void 0?l:i.UNKNOWN}e.getTagID=C;const r=i;e.SPECIAL_ELEMENTS={[g.HTML]:new Set([r.ADDRESS,r.APPLET,r.AREA,r.ARTICLE,r.ASIDE,r.BASE,r.BASEFONT,r.BGSOUND,r.BLOCKQUOTE,r.BODY,r.BR,r.BUTTON,r.CAPTION,r.CENTER,r.COL,r.COLGROUP,r.DD,r.DETAILS,r.DIR,r.DIV,r.DL,r.DT,r.EMBED,r.FIELDSET,r.FIGCAPTION,r.FIGURE,r.FOOTER,r.FORM,r.FRAME,r.FRAMESET,r.H1,r.H2,r.H3,r.H4,r.H5,r.H6,r.HEAD,r.HEADER,r.HGROUP,r.HR,r.HTML,r.IFRAME,r.IMG,r.INPUT,r.LI,r.LINK,r.LISTING,r.MAIN,r.MARQUEE,r.MENU,r.META,r.NAV,r.NOEMBED,r.NOFRAMES,r.NOSCRIPT,r.OBJECT,r.OL,r.P,r.PARAM,r.PLAINTEXT,r.PRE,r.SCRIPT,r.SECTION,r.SELECT,r.SOURCE,r.STYLE,r.SUMMARY,r.TABLE,r.TBODY,r.TD,r.TEMPLATE,r.TEXTAREA,r.TFOOT,r.TH,r.THEAD,r.TITLE,r.TR,r.TRACK,r.UL,r.WBR,r.XMP]),[g.MATHML]:new Set([r.MI,r.MO,r.MN,r.MS,r.MTEXT,r.ANNOTATION_XML]),[g.SVG]:new Set([r.TITLE,r.FOREIGN_OBJECT,r.DESC]),[g.XLINK]:new Set,[g.XML]:new Set,[g.XMLNS]:new Set};function o(a){return a===r.H1||a===r.H2||a===r.H3||a===r.H4||a===r.H5||a===r.H6}e.isNumberedHeader=o;const A=new Set([I.STYLE,I.SCRIPT,I.XMP,I.IFRAME,I.NOEMBED,I.NOFRAMES,I.PLAINTEXT]);function s(a,l){return A.has(a)||l&&a===I.NOSCRIPT}e.hasUnescapedText=s})($s);function nbt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function Cne(e,g){for(var I=0;I=Ae.CODE_POINTS.DIGIT_0&&e<=Ae.CODE_POINTS.DIGIT_9}function XZ(e){return e>=Ae.CODE_POINTS.LATIN_CAPITAL_A&&e<=Ae.CODE_POINTS.LATIN_CAPITAL_Z}function sbt(e){return e>=Ae.CODE_POINTS.LATIN_SMALL_A&&e<=Ae.CODE_POINTS.LATIN_SMALL_Z}function vl(e){return sbt(e)||XZ(e)}function j3(e){return vl(e)||YG(e)}function VBe(e){return e>=Ae.CODE_POINTS.LATIN_CAPITAL_A&&e<=Ae.CODE_POINTS.LATIN_CAPITAL_F}function RBe(e){return e>=Ae.CODE_POINTS.LATIN_SMALL_A&&e<=Ae.CODE_POINTS.LATIN_SMALL_F}function lbt(e){return YG(e)||VBe(e)||RBe(e)}function UV(e){return e+32}function WBe(e){return e===Ae.CODE_POINTS.SPACE||e===Ae.CODE_POINTS.LINE_FEED||e===Ae.CODE_POINTS.TABULATION||e===Ae.CODE_POINTS.FORM_FEED}function cbt(e){return e===Ae.CODE_POINTS.EQUALS_SIGN||j3(e)}function rne(e){return WBe(e)||e===Ae.CODE_POINTS.SOLIDUS||e===Ae.CODE_POINTS.GREATER_THAN_SIGN}let ubt=function(){function e(g,I){nbt(this,e),this.options=g,this.handler=I,this.paused=!1,this.inLoop=!1,this.inForeignNode=!1,this.lastStartTagName="",this.active=!1,this.state=pe.DATA,this.returnState=pe.DATA,this.charRefCode=-1,this.consumedAfterSnapshot=-1,this.currentCharacterToken=null,this.currentToken=null,this.currentAttr={name:"",value:""},this.preprocessor=new Abt.Preprocessor(I),this.currentLocation=this.getCurrentLocation(-1)}return Cbt(e,[{key:"_err",value:function(I){var i,n;(n=(i=this.handler).onParseError)===null||n===void 0||n.call(i,this.preprocessor.getError(I))}},{key:"getCurrentLocation",value:function(I){return this.options.sourceCodeLocationInfo?{startLine:this.preprocessor.line,startCol:this.preprocessor.col-I,startOffset:this.preprocessor.offset-I,endLine:-1,endCol:-1,endOffset:-1}:null}},{key:"_runParsingLoop",value:function(){if(!this.inLoop){for(this.inLoop=!0;this.active&&!this.paused;){this.consumedAfterSnapshot=0;const I=this._consume();this._ensureHibernation()||this._callState(I)}this.inLoop=!1}}},{key:"pause",value:function(){this.paused=!0}},{key:"resume",value:function(I){if(!this.paused)throw new Error("Parser was already resumed");this.paused=!1,!this.inLoop&&(this._runParsingLoop(),this.paused||I==null||I())}},{key:"write",value:function(I,i,n){this.active=!0,this.preprocessor.write(I,i),this._runParsingLoop(),this.paused||n==null||n()}},{key:"insertHtmlAtCurrentPos",value:function(I){this.active=!0,this.preprocessor.insertHtmlAtCurrentPos(I),this._runParsingLoop()}},{key:"_ensureHibernation",value:function(){return this.preprocessor.endOfChunkHit?(this._unconsume(this.consumedAfterSnapshot),this.active=!1,!0):!1}},{key:"_consume",value:function(){return this.consumedAfterSnapshot++,this.preprocessor.advance()}},{key:"_unconsume",value:function(I){this.consumedAfterSnapshot-=I,this.preprocessor.retreat(I)}},{key:"_reconsumeInState",value:function(I,i){this.state=I,this._callState(i)}},{key:"_advanceBy",value:function(I){this.consumedAfterSnapshot+=I;for(let i=0;i0&&this._err(je.ERR.endTagWithAttributes),I.selfClosing&&this._err(je.ERR.endTagWithTrailingSolidus),this.handler.onEndTag(I)),this.preprocessor.dropParsedChunk()}},{key:"emitCurrentComment",value:function(I){this.prepareToken(I),this.handler.onComment(I),this.preprocessor.dropParsedChunk()}},{key:"emitCurrentDoctype",value:function(I){this.prepareToken(I),this.handler.onDoctype(I),this.preprocessor.dropParsedChunk()}},{key:"_emitCurrentCharacterToken",value:function(I){if(this.currentCharacterToken){switch(I&&this.currentCharacterToken.location&&(this.currentCharacterToken.location.endLine=I.startLine,this.currentCharacterToken.location.endCol=I.startCol,this.currentCharacterToken.location.endOffset=I.startOffset),this.currentCharacterToken.type){case dC.TokenType.CHARACTER:{this.handler.onCharacter(this.currentCharacterToken);break}case dC.TokenType.NULL_CHARACTER:{this.handler.onNullCharacter(this.currentCharacterToken);break}case dC.TokenType.WHITESPACE_CHARACTER:{this.handler.onWhitespaceCharacter(this.currentCharacterToken);break}}this.currentCharacterToken=null}}},{key:"_emitEOFToken",value:function(){const I=this.getCurrentLocation(0);I&&(I.endLine=I.startLine,I.endCol=I.startCol,I.endOffset=I.startOffset),this._emitCurrentCharacterToken(I),this.handler.onEof({type:dC.TokenType.EOF,location:I}),this.active=!1}},{key:"_appendCharToCurrentCharacterToken",value:function(I,i){if(this.currentCharacterToken)if(this.currentCharacterToken.type!==I)this.currentLocation=this.getCurrentLocation(0),this._emitCurrentCharacterToken(this.currentLocation),this.preprocessor.dropParsedChunk();else{this.currentCharacterToken.chars+=i;return}this._createCharacterToken(I,i)}},{key:"_emitCodePoint",value:function(I){const i=WBe(I)?dC.TokenType.WHITESPACE_CHARACTER:I===Ae.CODE_POINTS.NULL?dC.TokenType.NULL_CHARACTER:dC.TokenType.CHARACTER;this._appendCharToCurrentCharacterToken(i,String.fromCodePoint(I))}},{key:"_emitChars",value:function(I){this._appendCharToCurrentCharacterToken(dC.TokenType.CHARACTER,I)}},{key:"_matchNamedCharacterReference",value:function(I){let i=null,n=0,C=!1;for(let r=0,o=GA.htmlDecodeTree[0];r>=0&&(r=(0,GA.determineBranch)(GA.htmlDecodeTree,o,r+1,I),!(r<0));I=this._consume()){n+=1,o=GA.htmlDecodeTree[r];const A=o&GA.BinTrieFlags.VALUE_LENGTH;if(A){const s=(A>>14)-1;if(I!==Ae.CODE_POINTS.SEMICOLON&&this._isCharacterReferenceInAttribute()&&cbt(this.preprocessor.peek(1))?(i=[Ae.CODE_POINTS.AMPERSAND],r+=s):(i=s===0?[GA.htmlDecodeTree[r]&~GA.BinTrieFlags.VALUE_LENGTH]:s===1?[GA.htmlDecodeTree[++r]]:[GA.htmlDecodeTree[++r],GA.htmlDecodeTree[++r]],n=0,C=I!==Ae.CODE_POINTS.SEMICOLON),s===0){this._consume();break}}}return this._unconsume(n),C&&!this.preprocessor.endOfChunkHit&&this._err(je.ERR.missingSemicolonAfterCharacterReference),this._unconsume(1),i}},{key:"_isCharacterReferenceInAttribute",value:function(){return this.returnState===pe.ATTRIBUTE_VALUE_DOUBLE_QUOTED||this.returnState===pe.ATTRIBUTE_VALUE_SINGLE_QUOTED||this.returnState===pe.ATTRIBUTE_VALUE_UNQUOTED}},{key:"_flushCodePointConsumedAsCharacterReference",value:function(I){this._isCharacterReferenceInAttribute()?this.currentAttr.value+=String.fromCodePoint(I):this._emitCodePoint(I)}},{key:"_callState",value:function(I){switch(this.state){case pe.DATA:{this._stateData(I);break}case pe.RCDATA:{this._stateRcdata(I);break}case pe.RAWTEXT:{this._stateRawtext(I);break}case pe.SCRIPT_DATA:{this._stateScriptData(I);break}case pe.PLAINTEXT:{this._statePlaintext(I);break}case pe.TAG_OPEN:{this._stateTagOpen(I);break}case pe.END_TAG_OPEN:{this._stateEndTagOpen(I);break}case pe.TAG_NAME:{this._stateTagName(I);break}case pe.RCDATA_LESS_THAN_SIGN:{this._stateRcdataLessThanSign(I);break}case pe.RCDATA_END_TAG_OPEN:{this._stateRcdataEndTagOpen(I);break}case pe.RCDATA_END_TAG_NAME:{this._stateRcdataEndTagName(I);break}case pe.RAWTEXT_LESS_THAN_SIGN:{this._stateRawtextLessThanSign(I);break}case pe.RAWTEXT_END_TAG_OPEN:{this._stateRawtextEndTagOpen(I);break}case pe.RAWTEXT_END_TAG_NAME:{this._stateRawtextEndTagName(I);break}case pe.SCRIPT_DATA_LESS_THAN_SIGN:{this._stateScriptDataLessThanSign(I);break}case pe.SCRIPT_DATA_END_TAG_OPEN:{this._stateScriptDataEndTagOpen(I);break}case pe.SCRIPT_DATA_END_TAG_NAME:{this._stateScriptDataEndTagName(I);break}case pe.SCRIPT_DATA_ESCAPE_START:{this._stateScriptDataEscapeStart(I);break}case pe.SCRIPT_DATA_ESCAPE_START_DASH:{this._stateScriptDataEscapeStartDash(I);break}case pe.SCRIPT_DATA_ESCAPED:{this._stateScriptDataEscaped(I);break}case pe.SCRIPT_DATA_ESCAPED_DASH:{this._stateScriptDataEscapedDash(I);break}case pe.SCRIPT_DATA_ESCAPED_DASH_DASH:{this._stateScriptDataEscapedDashDash(I);break}case pe.SCRIPT_DATA_ESCAPED_LESS_THAN_SIGN:{this._stateScriptDataEscapedLessThanSign(I);break}case pe.SCRIPT_DATA_ESCAPED_END_TAG_OPEN:{this._stateScriptDataEscapedEndTagOpen(I);break}case pe.SCRIPT_DATA_ESCAPED_END_TAG_NAME:{this._stateScriptDataEscapedEndTagName(I);break}case pe.SCRIPT_DATA_DOUBLE_ESCAPE_START:{this._stateScriptDataDoubleEscapeStart(I);break}case pe.SCRIPT_DATA_DOUBLE_ESCAPED:{this._stateScriptDataDoubleEscaped(I);break}case pe.SCRIPT_DATA_DOUBLE_ESCAPED_DASH:{this._stateScriptDataDoubleEscapedDash(I);break}case pe.SCRIPT_DATA_DOUBLE_ESCAPED_DASH_DASH:{this._stateScriptDataDoubleEscapedDashDash(I);break}case pe.SCRIPT_DATA_DOUBLE_ESCAPED_LESS_THAN_SIGN:{this._stateScriptDataDoubleEscapedLessThanSign(I);break}case pe.SCRIPT_DATA_DOUBLE_ESCAPE_END:{this._stateScriptDataDoubleEscapeEnd(I);break}case pe.BEFORE_ATTRIBUTE_NAME:{this._stateBeforeAttributeName(I);break}case pe.ATTRIBUTE_NAME:{this._stateAttributeName(I);break}case pe.AFTER_ATTRIBUTE_NAME:{this._stateAfterAttributeName(I);break}case pe.BEFORE_ATTRIBUTE_VALUE:{this._stateBeforeAttributeValue(I);break}case pe.ATTRIBUTE_VALUE_DOUBLE_QUOTED:{this._stateAttributeValueDoubleQuoted(I);break}case pe.ATTRIBUTE_VALUE_SINGLE_QUOTED:{this._stateAttributeValueSingleQuoted(I);break}case pe.ATTRIBUTE_VALUE_UNQUOTED:{this._stateAttributeValueUnquoted(I);break}case pe.AFTER_ATTRIBUTE_VALUE_QUOTED:{this._stateAfterAttributeValueQuoted(I);break}case pe.SELF_CLOSING_START_TAG:{this._stateSelfClosingStartTag(I);break}case pe.BOGUS_COMMENT:{this._stateBogusComment(I);break}case pe.MARKUP_DECLARATION_OPEN:{this._stateMarkupDeclarationOpen(I);break}case pe.COMMENT_START:{this._stateCommentStart(I);break}case pe.COMMENT_START_DASH:{this._stateCommentStartDash(I);break}case pe.COMMENT:{this._stateComment(I);break}case pe.COMMENT_LESS_THAN_SIGN:{this._stateCommentLessThanSign(I);break}case pe.COMMENT_LESS_THAN_SIGN_BANG:{this._stateCommentLessThanSignBang(I);break}case pe.COMMENT_LESS_THAN_SIGN_BANG_DASH:{this._stateCommentLessThanSignBangDash(I);break}case pe.COMMENT_LESS_THAN_SIGN_BANG_DASH_DASH:{this._stateCommentLessThanSignBangDashDash(I);break}case pe.COMMENT_END_DASH:{this._stateCommentEndDash(I);break}case pe.COMMENT_END:{this._stateCommentEnd(I);break}case pe.COMMENT_END_BANG:{this._stateCommentEndBang(I);break}case pe.DOCTYPE:{this._stateDoctype(I);break}case pe.BEFORE_DOCTYPE_NAME:{this._stateBeforeDoctypeName(I);break}case pe.DOCTYPE_NAME:{this._stateDoctypeName(I);break}case pe.AFTER_DOCTYPE_NAME:{this._stateAfterDoctypeName(I);break}case pe.AFTER_DOCTYPE_PUBLIC_KEYWORD:{this._stateAfterDoctypePublicKeyword(I);break}case pe.BEFORE_DOCTYPE_PUBLIC_IDENTIFIER:{this._stateBeforeDoctypePublicIdentifier(I);break}case pe.DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED:{this._stateDoctypePublicIdentifierDoubleQuoted(I);break}case pe.DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED:{this._stateDoctypePublicIdentifierSingleQuoted(I);break}case pe.AFTER_DOCTYPE_PUBLIC_IDENTIFIER:{this._stateAfterDoctypePublicIdentifier(I);break}case pe.BETWEEN_DOCTYPE_PUBLIC_AND_SYSTEM_IDENTIFIERS:{this._stateBetweenDoctypePublicAndSystemIdentifiers(I);break}case pe.AFTER_DOCTYPE_SYSTEM_KEYWORD:{this._stateAfterDoctypeSystemKeyword(I);break}case pe.BEFORE_DOCTYPE_SYSTEM_IDENTIFIER:{this._stateBeforeDoctypeSystemIdentifier(I);break}case pe.DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED:{this._stateDoctypeSystemIdentifierDoubleQuoted(I);break}case pe.DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED:{this._stateDoctypeSystemIdentifierSingleQuoted(I);break}case pe.AFTER_DOCTYPE_SYSTEM_IDENTIFIER:{this._stateAfterDoctypeSystemIdentifier(I);break}case pe.BOGUS_DOCTYPE:{this._stateBogusDoctype(I);break}case pe.CDATA_SECTION:{this._stateCdataSection(I);break}case pe.CDATA_SECTION_BRACKET:{this._stateCdataSectionBracket(I);break}case pe.CDATA_SECTION_END:{this._stateCdataSectionEnd(I);break}case pe.CHARACTER_REFERENCE:{this._stateCharacterReference(I);break}case pe.NAMED_CHARACTER_REFERENCE:{this._stateNamedCharacterReference(I);break}case pe.AMBIGUOUS_AMPERSAND:{this._stateAmbiguousAmpersand(I);break}case pe.NUMERIC_CHARACTER_REFERENCE:{this._stateNumericCharacterReference(I);break}case pe.HEXADEMICAL_CHARACTER_REFERENCE_START:{this._stateHexademicalCharacterReferenceStart(I);break}case pe.HEXADEMICAL_CHARACTER_REFERENCE:{this._stateHexademicalCharacterReference(I);break}case pe.DECIMAL_CHARACTER_REFERENCE:{this._stateDecimalCharacterReference(I);break}case pe.NUMERIC_CHARACTER_REFERENCE_END:{this._stateNumericCharacterReferenceEnd(I);break}default:throw new Error("Unknown state")}}},{key:"_stateData",value:function(I){switch(I){case Ae.CODE_POINTS.LESS_THAN_SIGN:{this.state=pe.TAG_OPEN;break}case Ae.CODE_POINTS.AMPERSAND:{this.returnState=pe.DATA,this.state=pe.CHARACTER_REFERENCE;break}case Ae.CODE_POINTS.NULL:{this._err(je.ERR.unexpectedNullCharacter),this._emitCodePoint(I);break}case Ae.CODE_POINTS.EOF:{this._emitEOFToken();break}default:this._emitCodePoint(I)}}},{key:"_stateRcdata",value:function(I){switch(I){case Ae.CODE_POINTS.AMPERSAND:{this.returnState=pe.RCDATA,this.state=pe.CHARACTER_REFERENCE;break}case Ae.CODE_POINTS.LESS_THAN_SIGN:{this.state=pe.RCDATA_LESS_THAN_SIGN;break}case Ae.CODE_POINTS.NULL:{this._err(je.ERR.unexpectedNullCharacter),this._emitChars(Ae.REPLACEMENT_CHARACTER);break}case Ae.CODE_POINTS.EOF:{this._emitEOFToken();break}default:this._emitCodePoint(I)}}},{key:"_stateRawtext",value:function(I){switch(I){case Ae.CODE_POINTS.LESS_THAN_SIGN:{this.state=pe.RAWTEXT_LESS_THAN_SIGN;break}case Ae.CODE_POINTS.NULL:{this._err(je.ERR.unexpectedNullCharacter),this._emitChars(Ae.REPLACEMENT_CHARACTER);break}case Ae.CODE_POINTS.EOF:{this._emitEOFToken();break}default:this._emitCodePoint(I)}}},{key:"_stateScriptData",value:function(I){switch(I){case Ae.CODE_POINTS.LESS_THAN_SIGN:{this.state=pe.SCRIPT_DATA_LESS_THAN_SIGN;break}case Ae.CODE_POINTS.NULL:{this._err(je.ERR.unexpectedNullCharacter),this._emitChars(Ae.REPLACEMENT_CHARACTER);break}case Ae.CODE_POINTS.EOF:{this._emitEOFToken();break}default:this._emitCodePoint(I)}}},{key:"_statePlaintext",value:function(I){switch(I){case Ae.CODE_POINTS.NULL:{this._err(je.ERR.unexpectedNullCharacter),this._emitChars(Ae.REPLACEMENT_CHARACTER);break}case Ae.CODE_POINTS.EOF:{this._emitEOFToken();break}default:this._emitCodePoint(I)}}},{key:"_stateTagOpen",value:function(I){if(vl(I))this._createStartTagToken(),this.state=pe.TAG_NAME,this._stateTagName(I);else switch(I){case Ae.CODE_POINTS.EXCLAMATION_MARK:{this.state=pe.MARKUP_DECLARATION_OPEN;break}case Ae.CODE_POINTS.SOLIDUS:{this.state=pe.END_TAG_OPEN;break}case Ae.CODE_POINTS.QUESTION_MARK:{this._err(je.ERR.unexpectedQuestionMarkInsteadOfTagName),this._createCommentToken(1),this.state=pe.BOGUS_COMMENT,this._stateBogusComment(I);break}case Ae.CODE_POINTS.EOF:{this._err(je.ERR.eofBeforeTagName),this._emitChars("<"),this._emitEOFToken();break}default:this._err(je.ERR.invalidFirstCharacterOfTagName),this._emitChars("<"),this.state=pe.DATA,this._stateData(I)}}},{key:"_stateEndTagOpen",value:function(I){if(vl(I))this._createEndTagToken(),this.state=pe.TAG_NAME,this._stateTagName(I);else switch(I){case Ae.CODE_POINTS.GREATER_THAN_SIGN:{this._err(je.ERR.missingEndTagName),this.state=pe.DATA;break}case Ae.CODE_POINTS.EOF:{this._err(je.ERR.eofBeforeTagName),this._emitChars("");break}case Ae.CODE_POINTS.NULL:{this._err(je.ERR.unexpectedNullCharacter),this.state=pe.SCRIPT_DATA_ESCAPED,this._emitChars(Ae.REPLACEMENT_CHARACTER);break}case Ae.CODE_POINTS.EOF:{this._err(je.ERR.eofInScriptHtmlCommentLikeText),this._emitEOFToken();break}default:this.state=pe.SCRIPT_DATA_ESCAPED,this._emitCodePoint(I)}}},{key:"_stateScriptDataEscapedLessThanSign",value:function(I){I===Ae.CODE_POINTS.SOLIDUS?this.state=pe.SCRIPT_DATA_ESCAPED_END_TAG_OPEN:vl(I)?(this._emitChars("<"),this.state=pe.SCRIPT_DATA_DOUBLE_ESCAPE_START,this._stateScriptDataDoubleEscapeStart(I)):(this._emitChars("<"),this.state=pe.SCRIPT_DATA_ESCAPED,this._stateScriptDataEscaped(I))}},{key:"_stateScriptDataEscapedEndTagOpen",value:function(I){vl(I)?(this.state=pe.SCRIPT_DATA_ESCAPED_END_TAG_NAME,this._stateScriptDataEscapedEndTagName(I)):(this._emitChars("");break}case Ae.CODE_POINTS.NULL:{this._err(je.ERR.unexpectedNullCharacter),this.state=pe.SCRIPT_DATA_DOUBLE_ESCAPED,this._emitChars(Ae.REPLACEMENT_CHARACTER);break}case Ae.CODE_POINTS.EOF:{this._err(je.ERR.eofInScriptHtmlCommentLikeText),this._emitEOFToken();break}default:this.state=pe.SCRIPT_DATA_DOUBLE_ESCAPED,this._emitCodePoint(I)}}},{key:"_stateScriptDataDoubleEscapedLessThanSign",value:function(I){I===Ae.CODE_POINTS.SOLIDUS?(this.state=pe.SCRIPT_DATA_DOUBLE_ESCAPE_END,this._emitChars("/")):(this.state=pe.SCRIPT_DATA_DOUBLE_ESCAPED,this._stateScriptDataDoubleEscaped(I))}},{key:"_stateScriptDataDoubleEscapeEnd",value:function(I){if(this.preprocessor.startsWith(Ae.SEQUENCES.SCRIPT,!1)&&rne(this.preprocessor.peek(Ae.SEQUENCES.SCRIPT.length))){this._emitCodePoint(I);for(let i=0;i1114111)this._err(je.ERR.characterReferenceOutsideUnicodeRange),this.charRefCode=Ae.CODE_POINTS.REPLACEMENT_CHARACTER;else if((0,Ae.isSurrogate)(this.charRefCode))this._err(je.ERR.surrogateCharacterReference),this.charRefCode=Ae.CODE_POINTS.REPLACEMENT_CHARACTER;else if((0,Ae.isUndefinedCodePoint)(this.charRefCode))this._err(je.ERR.noncharacterCharacterReference);else if((0,Ae.isControlCodePoint)(this.charRefCode)||this.charRefCode===Ae.CODE_POINTS.CARRIAGE_RETURN){this._err(je.ERR.controlCharacterReference);const i=abt.get(this.charRefCode);i!==void 0&&(this.charRefCode=i)}this._flushCodePointConsumedAsCharacterReference(this.charRefCode),this._reconsumeInState(this.returnState,I)}}]),e}();ih.Tokenizer=ubt;var XN={};function dbt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function one(e,g){for(var I=0;I0&&this._isInTemplate()&&this.tmplCount--,this.stackTop--,this._updateCurrentElement(),this.handler.onItemPop(I,!0)}},{key:"replace",value:function(I,i){const n=this._indexOf(I);this.items[n]=i,n===this.stackTop&&(this.current=i)}},{key:"insertAfter",value:function(I,i,n){const C=this._indexOf(I)+1;this.items.splice(C,0,i),this.tagIDs.splice(C,0,n),this.stackTop++,C===this.stackTop&&this._updateCurrentElement(),this.handler.onItemPush(this.current,this.currentTagId,C===this.stackTop)}},{key:"popUntilTagNamePopped",value:function(I){let i=this.stackTop+1;do i=this.tagIDs.lastIndexOf(I,i-1);while(i>0&&this.treeAdapter.getNamespaceURI(this.items[i])!==gt.NS.HTML);this.shortenToLength(i<0?0:i)}},{key:"shortenToLength",value:function(I){for(;this.stackTop>=I;){const i=this.current;this.tmplCount>0&&this._isInTemplate()&&(this.tmplCount-=1),this.stackTop--,this._updateCurrentElement(),this.handler.onItemPop(i,this.stackTop=0;n--)if(I.includes(this.tagIDs[n])&&this.treeAdapter.getNamespaceURI(this.items[n])===i)return n;return-1}},{key:"clearBackTo",value:function(I,i){const n=this._indexOfTagNames(I,i);this.shortenToLength(n+1)}},{key:"clearBackToTableContext",value:function(){this.clearBackTo(Zbt,gt.NS.HTML)}},{key:"clearBackToTableBodyContext",value:function(){this.clearBackTo(ybt,gt.NS.HTML)}},{key:"clearBackToTableRowContext",value:function(){this.clearBackTo(bbt,gt.NS.HTML)}},{key:"remove",value:function(I){const i=this._indexOf(I);i>=0&&(i===this.stackTop?this.pop():(this.items.splice(i,1),this.tagIDs.splice(i,1),this.stackTop--,this._updateCurrentElement(),this.handler.onItemPop(I,!1)))}},{key:"tryPeekProperlyNestedBodyElement",value:function(){return this.stackTop>=1&&this.tagIDs[1]===gt.TAG_ID.BODY?this.items[1]:null}},{key:"contains",value:function(I){return this._indexOf(I)>-1}},{key:"getCommonAncestor",value:function(I){const i=this._indexOf(I)-1;return i>=0?this.items[i]:null}},{key:"isRootHtmlElementCurrent",value:function(){return this.stackTop===0&&this.tagIDs[0]===gt.TAG_ID.HTML}},{key:"hasInScope",value:function(I){for(let i=this.stackTop;i>=0;i--){const n=this.tagIDs[i],C=this.treeAdapter.getNamespaceURI(this.items[i]);if(n===I&&C===gt.NS.HTML)return!0;if(QV.get(n)===C)return!1}return!0}},{key:"hasNumberedHeaderInScope",value:function(){for(let I=this.stackTop;I>=0;I--){const i=this.tagIDs[I],n=this.treeAdapter.getNamespaceURI(this.items[I]);if((0,gt.isNumberedHeader)(i)&&n===gt.NS.HTML)return!0;if(QV.get(i)===n)return!1}return!0}},{key:"hasInListItemScope",value:function(I){for(let i=this.stackTop;i>=0;i--){const n=this.tagIDs[i],C=this.treeAdapter.getNamespaceURI(this.items[i]);if(n===I&&C===gt.NS.HTML)return!0;if((n===gt.TAG_ID.UL||n===gt.TAG_ID.OL)&&C===gt.NS.HTML||QV.get(n)===C)return!1}return!0}},{key:"hasInButtonScope",value:function(I){for(let i=this.stackTop;i>=0;i--){const n=this.tagIDs[i],C=this.treeAdapter.getNamespaceURI(this.items[i]);if(n===I&&C===gt.NS.HTML)return!0;if(n===gt.TAG_ID.BUTTON&&C===gt.NS.HTML||QV.get(n)===C)return!1}return!0}},{key:"hasInTableScope",value:function(I){for(let i=this.stackTop;i>=0;i--){const n=this.tagIDs[i];if(this.treeAdapter.getNamespaceURI(this.items[i])===gt.NS.HTML){if(n===I)return!0;if(n===gt.TAG_ID.TABLE||n===gt.TAG_ID.TEMPLATE||n===gt.TAG_ID.HTML)return!1}}return!0}},{key:"hasTableBodyContextInTableScope",value:function(){for(let I=this.stackTop;I>=0;I--){const i=this.tagIDs[I];if(this.treeAdapter.getNamespaceURI(this.items[I])===gt.NS.HTML){if(i===gt.TAG_ID.TBODY||i===gt.TAG_ID.THEAD||i===gt.TAG_ID.TFOOT)return!0;if(i===gt.TAG_ID.TABLE||i===gt.TAG_ID.HTML)return!1}}return!0}},{key:"hasInSelectScope",value:function(I){for(let i=this.stackTop;i>=0;i--){const n=this.tagIDs[i];if(this.treeAdapter.getNamespaceURI(this.items[i])===gt.NS.HTML){if(n===I)return!0;if(n!==gt.TAG_ID.OPTION&&n!==gt.TAG_ID.OPTGROUP)return!1}}return!0}},{key:"generateImpliedEndTags",value:function(){for(;XBe.has(this.currentTagId);)this.pop()}},{key:"generateImpliedEndTagsThoroughly",value:function(){for(;Ane.has(this.currentTagId);)this.pop()}},{key:"generateImpliedEndTagsWithExclusion",value:function(I){for(;this.currentTagId!==I&&Ane.has(this.currentTagId);)this.pop()}}]),e}();XN.OpenElementStack=vbt;var HBe={};(function(e){function g(a,l){if(!(a instanceof l))throw new TypeError("Cannot call a class as a function")}function I(a,l){for(var c=0;c[f.name,f.value]));let m=0;for(let f=0;fh.get(p.name)===p.value)&&(m+=1,m>=r&&this.entries.splice(b.idx,1))}}},{key:"insertMarker",value:function(){this.entries.unshift(A)}},{key:"pushElement",value:function(c,u){this._ensureNoahArkCondition(c),this.entries.unshift({type:o.Element,element:c,token:u})}},{key:"insertElementAfterBookmark",value:function(c,u){const d=this.entries.indexOf(this.bookmark);this.entries.splice(d,0,{type:o.Element,element:c,token:u})}},{key:"removeEntry",value:function(c){const u=this.entries.indexOf(c);u>=0&&this.entries.splice(u,1)}},{key:"clearToLastMarker",value:function(){const c=this.entries.indexOf(A);c>=0?this.entries.splice(0,c+1):this.entries.length=0}},{key:"getElementEntryInScopeWithTagName",value:function(c){const u=this.entries.find(d=>d.type===o.Marker||this.treeAdapter.getTagName(d.element)===c);return u&&u.type===o.Element?u:null}},{key:"getElementEntry",value:function(c){return this.entries.find(u=>u.type===o.Element&&u.element===c)}}]),a}();e.FormattingElementList=s})(HBe);var HN={};(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.defaultTreeAdapter=void 0;const g=$s;function I(i){return{nodeName:"#text",value:i,parentNode:null}}e.defaultTreeAdapter={createDocument(){return{nodeName:"#document",mode:g.DOCUMENT_MODE.NO_QUIRKS,childNodes:[]}},createDocumentFragment(){return{nodeName:"#document-fragment",childNodes:[]}},createElement(i,n,C){return{nodeName:i,tagName:i,attrs:C,namespaceURI:n,childNodes:[],parentNode:null}},createCommentNode(i){return{nodeName:"#comment",data:i,parentNode:null}},appendChild(i,n){i.childNodes.push(n),n.parentNode=i},insertBefore(i,n,C){const r=i.childNodes.indexOf(C);i.childNodes.splice(r,0,n),n.parentNode=i},setTemplateContent(i,n){i.content=n},getTemplateContent(i){return i.content},setDocumentType(i,n,C,r){const o=i.childNodes.find(A=>A.nodeName==="#documentType");if(o)o.name=n,o.publicId=C,o.systemId=r;else{const A={nodeName:"#documentType",name:n,publicId:C,systemId:r,parentNode:null};e.defaultTreeAdapter.appendChild(i,A)}},setDocumentMode(i,n){i.mode=n},getDocumentMode(i){return i.mode},detachNode(i){if(i.parentNode){const n=i.parentNode.childNodes.indexOf(i);i.parentNode.childNodes.splice(n,1),i.parentNode=null}},insertText(i,n){if(i.childNodes.length>0){const C=i.childNodes[i.childNodes.length-1];if(e.defaultTreeAdapter.isTextNode(C)){C.value+=n;return}}e.defaultTreeAdapter.appendChild(i,I(n))},insertTextBefore(i,n,C){const r=i.childNodes[i.childNodes.indexOf(C)-1];r&&e.defaultTreeAdapter.isTextNode(r)?r.value+=n:e.defaultTreeAdapter.insertBefore(i,I(n),C)},adoptAttributes(i,n){const C=new Set(i.attrs.map(r=>r.name));for(let r=0;re.startsWith(I))}function Wbt(e){return e.name===TBe&&e.publicId===null&&(e.systemId===null||e.systemId===Bbt)}kb.isConforming=Wbt;function Xbt(e){if(e.name!==TBe)return Ym.DOCUMENT_MODE.QUIRKS;const{systemId:g}=e;if(g&&g.toLowerCase()===Sbt)return Ym.DOCUMENT_MODE.QUIRKS;let{publicId:I}=e;if(I!==null){if(I=I.toLowerCase(),Vbt.has(I))return Ym.DOCUMENT_MODE.QUIRKS;let i=g===null?wbt:NBe;if(ane(I,i))return Ym.DOCUMENT_MODE.QUIRKS;if(i=g===null?kBe:Rbt,ane(I,i))return Ym.DOCUMENT_MODE.LIMITED_QUIRKS}return Ym.DOCUMENT_MODE.NO_QUIRKS}kb.getDocumentMode=Xbt;var NQ={};(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.isIntegrationPoint=e.adjustTokenSVGTagName=e.adjustTokenXMLAttrs=e.adjustTokenSVGAttrs=e.adjustTokenMathMLAttrs=e.causesExit=e.SVG_TAG_NAMES_ADJUSTMENT_MAP=void 0;const g=$s,I={TEXT_HTML:"text/html",APPLICATION_XML:"application/xhtml+xml"},i="definitionurl",n="definitionURL",C=new Map(["attributeName","attributeType","baseFrequency","baseProfile","calcMode","clipPathUnits","diffuseConstant","edgeMode","filterUnits","glyphRef","gradientTransform","gradientUnits","kernelMatrix","kernelUnitLength","keyPoints","keySplines","keyTimes","lengthAdjust","limitingConeAngle","markerHeight","markerUnits","markerWidth","maskContentUnits","maskUnits","numOctaves","pathLength","patternContentUnits","patternTransform","patternUnits","pointsAtX","pointsAtY","pointsAtZ","preserveAlpha","preserveAspectRatio","primitiveUnits","refX","refY","repeatCount","repeatDur","requiredExtensions","requiredFeatures","specularConstant","specularExponent","spreadMethod","startOffset","stdDeviation","stitchTiles","surfaceScale","systemLanguage","tableValues","targetX","targetY","textLength","viewBox","viewTarget","xChannelSelector","yChannelSelector","zoomAndPan"].map(m=>[m.toLowerCase(),m])),r=new Map([["xlink:actuate",{prefix:"xlink",name:"actuate",namespace:g.NS.XLINK}],["xlink:arcrole",{prefix:"xlink",name:"arcrole",namespace:g.NS.XLINK}],["xlink:href",{prefix:"xlink",name:"href",namespace:g.NS.XLINK}],["xlink:role",{prefix:"xlink",name:"role",namespace:g.NS.XLINK}],["xlink:show",{prefix:"xlink",name:"show",namespace:g.NS.XLINK}],["xlink:title",{prefix:"xlink",name:"title",namespace:g.NS.XLINK}],["xlink:type",{prefix:"xlink",name:"type",namespace:g.NS.XLINK}],["xml:base",{prefix:"xml",name:"base",namespace:g.NS.XML}],["xml:lang",{prefix:"xml",name:"lang",namespace:g.NS.XML}],["xml:space",{prefix:"xml",name:"space",namespace:g.NS.XML}],["xmlns",{prefix:"",name:"xmlns",namespace:g.NS.XMLNS}],["xmlns:xlink",{prefix:"xmlns",name:"xlink",namespace:g.NS.XMLNS}]]);e.SVG_TAG_NAMES_ADJUSTMENT_MAP=new Map(["altGlyph","altGlyphDef","altGlyphItem","animateColor","animateMotion","animateTransform","clipPath","feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feDistantLight","feFlood","feFuncA","feFuncB","feFuncG","feFuncR","feGaussianBlur","feImage","feMerge","feMergeNode","feMorphology","feOffset","fePointLight","feSpecularLighting","feSpotLight","feTile","feTurbulence","foreignObject","glyphRef","linearGradient","radialGradient","textPath"].map(m=>[m.toLowerCase(),m]));const o=new Set([g.TAG_ID.B,g.TAG_ID.BIG,g.TAG_ID.BLOCKQUOTE,g.TAG_ID.BODY,g.TAG_ID.BR,g.TAG_ID.CENTER,g.TAG_ID.CODE,g.TAG_ID.DD,g.TAG_ID.DIV,g.TAG_ID.DL,g.TAG_ID.DT,g.TAG_ID.EM,g.TAG_ID.EMBED,g.TAG_ID.H1,g.TAG_ID.H2,g.TAG_ID.H3,g.TAG_ID.H4,g.TAG_ID.H5,g.TAG_ID.H6,g.TAG_ID.HEAD,g.TAG_ID.HR,g.TAG_ID.I,g.TAG_ID.IMG,g.TAG_ID.LI,g.TAG_ID.LISTING,g.TAG_ID.MENU,g.TAG_ID.META,g.TAG_ID.NOBR,g.TAG_ID.OL,g.TAG_ID.P,g.TAG_ID.PRE,g.TAG_ID.RUBY,g.TAG_ID.S,g.TAG_ID.SMALL,g.TAG_ID.SPAN,g.TAG_ID.STRONG,g.TAG_ID.STRIKE,g.TAG_ID.SUB,g.TAG_ID.SUP,g.TAG_ID.TABLE,g.TAG_ID.TT,g.TAG_ID.U,g.TAG_ID.UL,g.TAG_ID.VAR]);function A(m){const f=m.tagID;return f===g.TAG_ID.FONT&&m.attrs.some(({name:p})=>p===g.ATTRS.COLOR||p===g.ATTRS.SIZE||p===g.ATTRS.FACE)||o.has(f)}e.causesExit=A;function s(m){for(let f=0;f0&&this._setContextModes(I,i)}},{key:"onItemPop",value:function(I,i){var n,C;if(this.options.sourceCodeLocationInfo&&this._setEndLocation(I,this.currentToken),(C=(n=this.treeAdapter).onItemPop)===null||C===void 0||C.call(n,I,this.openElements.current),i){let r,o;this.openElements.stackTop===0&&this.fragmentContext?(r=this.fragmentContext,o=this.fragmentContextID):{current:r,currentTagId:o}=this.openElements,this._setContextModes(r,o)}}},{key:"_setContextModes",value:function(I,i){const n=I===this.document||this.treeAdapter.getNamespaceURI(I)===M.NS.HTML;this.currentNotInHTML=!n,this.tokenizer.inForeignNode=!n&&!this._isIntegrationPoint(i,I)}},{key:"_switchToTextParsing",value:function(I,i){this._insertElement(I,M.NS.HTML),this.tokenizer.state=i,this.originalInsertionMode=this.insertionMode,this.insertionMode=Re.TEXT}},{key:"switchToPlaintextParsing",value:function(){this.insertionMode=Re.TEXT,this.originalInsertionMode=Re.IN_BODY,this.tokenizer.state=Jn.TokenizerMode.PLAINTEXT}},{key:"_getAdjustedCurrentElement",value:function(){return this.openElements.stackTop===0&&this.fragmentContext?this.fragmentContext:this.openElements.current}},{key:"_findFormInFragmentContext",value:function(){let I=this.fragmentContext;for(;I;){if(this.treeAdapter.getTagName(I)===M.TAG_NAMES.FORM){this.formElement=I;break}I=this.treeAdapter.getParentNode(I)}}},{key:"_initTokenizerForFragmentParsing",value:function(){if(!(!this.fragmentContext||this.treeAdapter.getNamespaceURI(this.fragmentContext)!==M.NS.HTML))switch(this.fragmentContextID){case M.TAG_ID.TITLE:case M.TAG_ID.TEXTAREA:{this.tokenizer.state=Jn.TokenizerMode.RCDATA;break}case M.TAG_ID.STYLE:case M.TAG_ID.XMP:case M.TAG_ID.IFRAME:case M.TAG_ID.NOEMBED:case M.TAG_ID.NOFRAMES:case M.TAG_ID.NOSCRIPT:{this.tokenizer.state=Jn.TokenizerMode.RAWTEXT;break}case M.TAG_ID.SCRIPT:{this.tokenizer.state=Jn.TokenizerMode.SCRIPT_DATA;break}case M.TAG_ID.PLAINTEXT:{this.tokenizer.state=Jn.TokenizerMode.PLAINTEXT;break}}}},{key:"_setDocumentType",value:function(I){const i=I.name||"",n=I.publicId||"",C=I.systemId||"";if(this.treeAdapter.setDocumentType(this.document,i,n,C),I.location){const o=this.treeAdapter.getChildNodes(this.document).find(A=>this.treeAdapter.isDocumentTypeNode(A));o&&this.treeAdapter.setNodeSourceCodeLocation(o,I.location)}}},{key:"_attachElementToTree",value:function(I,i){if(this.options.sourceCodeLocationInfo){const n=i&&Object.assign(Object.assign({},i),{startTag:i});this.treeAdapter.setNodeSourceCodeLocation(I,n)}if(this._shouldFosterParentOnInsertion())this._fosterParentElement(I);else{const n=this.openElements.currentTmplContentOrNode;this.treeAdapter.appendChild(n,I)}}},{key:"_appendElement",value:function(I,i){const n=this.treeAdapter.createElement(I.tagName,i,I.attrs);this._attachElementToTree(n,I.location)}},{key:"_insertElement",value:function(I,i){const n=this.treeAdapter.createElement(I.tagName,i,I.attrs);this._attachElementToTree(n,I.location),this.openElements.push(n,I.tagID)}},{key:"_insertFakeElement",value:function(I,i){const n=this.treeAdapter.createElement(I,M.NS.HTML,[]);this._attachElementToTree(n,null),this.openElements.push(n,i)}},{key:"_insertTemplate",value:function(I){const i=this.treeAdapter.createElement(I.tagName,M.NS.HTML,I.attrs),n=this.treeAdapter.createDocumentFragment();this.treeAdapter.setTemplateContent(i,n),this._attachElementToTree(i,I.location),this.openElements.push(i,I.tagID),this.options.sourceCodeLocationInfo&&this.treeAdapter.setNodeSourceCodeLocation(n,null)}},{key:"_insertFakeRootElement",value:function(){const I=this.treeAdapter.createElement(M.TAG_NAMES.HTML,M.NS.HTML,[]);this.options.sourceCodeLocationInfo&&this.treeAdapter.setNodeSourceCodeLocation(I,null),this.treeAdapter.appendChild(this.openElements.current,I),this.openElements.push(I,M.TAG_ID.HTML)}},{key:"_appendCommentNode",value:function(I,i){const n=this.treeAdapter.createCommentNode(I.data);this.treeAdapter.appendChild(i,n),this.options.sourceCodeLocationInfo&&this.treeAdapter.setNodeSourceCodeLocation(n,I.location)}},{key:"_insertCharacters",value:function(I){let i,n;if(this._shouldFosterParentOnInsertion()?({parent:i,beforeElement:n}=this._findFosterParentingLocation(),n?this.treeAdapter.insertTextBefore(i,I.chars,n):this.treeAdapter.insertText(i,I.chars)):(i=this.openElements.currentTmplContentOrNode,this.treeAdapter.insertText(i,I.chars)),!I.location)return;const C=this.treeAdapter.getChildNodes(i),r=n?C.lastIndexOf(n):C.length,o=C[r-1];if(this.treeAdapter.getNodeSourceCodeLocation(o)){const{endLine:s,endCol:a,endOffset:l}=I.location;this.treeAdapter.updateNodeSourceCodeLocation(o,{endLine:s,endCol:a,endOffset:l})}else this.options.sourceCodeLocationInfo&&this.treeAdapter.setNodeSourceCodeLocation(o,I.location)}},{key:"_adoptNodes",value:function(I,i){for(let n=this.treeAdapter.getFirstChild(I);n;n=this.treeAdapter.getFirstChild(I))this.treeAdapter.detachNode(n),this.treeAdapter.appendChild(i,n)}},{key:"_setEndLocation",value:function(I,i){if(this.treeAdapter.getNodeSourceCodeLocation(I)&&i.location){const n=i.location,C=this.treeAdapter.getTagName(I),r=i.type===Gi.TokenType.END_TAG&&C===i.tagName?{endTag:Object.assign({},n),endLine:n.endLine,endCol:n.endCol,endOffset:n.endOffset}:{endLine:n.startLine,endCol:n.startCol,endOffset:n.startOffset};this.treeAdapter.updateNodeSourceCodeLocation(I,r)}}},{key:"shouldProcessStartTagTokenInForeignContent",value:function(I){if(!this.currentNotInHTML)return!1;let i,n;return this.openElements.stackTop===0&&this.fragmentContext?(i=this.fragmentContext,n=this.fragmentContextID):{current:i,currentTagId:n}=this.openElements,I.tagID===M.TAG_ID.SVG&&this.treeAdapter.getTagName(i)===M.TAG_NAMES.ANNOTATION_XML&&this.treeAdapter.getNamespaceURI(i)===M.NS.MATHML?!1:this.tokenizer.inForeignNode||(I.tagID===M.TAG_ID.MGLYPH||I.tagID===M.TAG_ID.MALIGNMARK)&&!this._isIntegrationPoint(n,i,M.NS.HTML)}},{key:"_processToken",value:function(I){switch(I.type){case Gi.TokenType.CHARACTER:{this.onCharacter(I);break}case Gi.TokenType.NULL_CHARACTER:{this.onNullCharacter(I);break}case Gi.TokenType.COMMENT:{this.onComment(I);break}case Gi.TokenType.DOCTYPE:{this.onDoctype(I);break}case Gi.TokenType.START_TAG:{this._processStartTag(I);break}case Gi.TokenType.END_TAG:{this.onEndTag(I);break}case Gi.TokenType.EOF:{this.onEof(I);break}case Gi.TokenType.WHITESPACE_CHARACTER:{this.onWhitespaceCharacter(I);break}}}},{key:"_isIntegrationPoint",value:function(I,i,n){const C=this.treeAdapter.getNamespaceURI(i),r=this.treeAdapter.getAttrList(i);return FA.isIntegrationPoint(I,C,r,n)}},{key:"_reconstructActiveFormattingElements",value:function(){const I=this.activeFormattingElements.entries.length;if(I){const i=this.activeFormattingElements.entries.findIndex(C=>C.type===lne.EntryType.Marker||this.openElements.contains(C.element)),n=i<0?I-1:i-1;for(let C=n;C>=0;C--){const r=this.activeFormattingElements.entries[C];this._insertElement(r.token,this.treeAdapter.getNamespaceURI(r.element)),r.element=this.openElements.current}}}},{key:"_closeTableCell",value:function(){this.openElements.generateImpliedEndTags(),this.openElements.popUntilTableCellPopped(),this.activeFormattingElements.clearToLastMarker(),this.insertionMode=Re.IN_ROW}},{key:"_closePElement",value:function(){this.openElements.generateImpliedEndTagsWithExclusion(M.TAG_ID.P),this.openElements.popUntilTagNamePopped(M.TAG_ID.P)}},{key:"_resetInsertionMode",value:function(){for(let I=this.openElements.stackTop;I>=0;I--)switch(I===0&&this.fragmentContext?this.fragmentContextID:this.openElements.tagIDs[I]){case M.TAG_ID.TR:{this.insertionMode=Re.IN_ROW;return}case M.TAG_ID.TBODY:case M.TAG_ID.THEAD:case M.TAG_ID.TFOOT:{this.insertionMode=Re.IN_TABLE_BODY;return}case M.TAG_ID.CAPTION:{this.insertionMode=Re.IN_CAPTION;return}case M.TAG_ID.COLGROUP:{this.insertionMode=Re.IN_COLUMN_GROUP;return}case M.TAG_ID.TABLE:{this.insertionMode=Re.IN_TABLE;return}case M.TAG_ID.BODY:{this.insertionMode=Re.IN_BODY;return}case M.TAG_ID.FRAMESET:{this.insertionMode=Re.IN_FRAMESET;return}case M.TAG_ID.SELECT:{this._resetInsertionModeForSelect(I);return}case M.TAG_ID.TEMPLATE:{this.insertionMode=this.tmplInsertionModeStack[0];return}case M.TAG_ID.HTML:{this.insertionMode=this.headElement?Re.AFTER_HEAD:Re.BEFORE_HEAD;return}case M.TAG_ID.TD:case M.TAG_ID.TH:{if(I>0){this.insertionMode=Re.IN_CELL;return}break}case M.TAG_ID.HEAD:{if(I>0){this.insertionMode=Re.IN_HEAD;return}break}}this.insertionMode=Re.IN_BODY}},{key:"_resetInsertionModeForSelect",value:function(I){if(I>0)for(let i=I-1;i>0;i--){const n=this.openElements.tagIDs[i];if(n===M.TAG_ID.TEMPLATE)break;if(n===M.TAG_ID.TABLE){this.insertionMode=Re.IN_SELECT_IN_TABLE;return}}this.insertionMode=Re.IN_SELECT}},{key:"_isElementCausesFosterParenting",value:function(I){return KBe.has(I)}},{key:"_shouldFosterParentOnInsertion",value:function(){return this.fosterParentingEnabled&&this._isElementCausesFosterParenting(this.openElements.currentTagId)}},{key:"_findFosterParentingLocation",value:function(){for(let I=this.openElements.stackTop;I>=0;I--){const i=this.openElements.items[I];switch(this.openElements.tagIDs[I]){case M.TAG_ID.TEMPLATE:{if(this.treeAdapter.getNamespaceURI(i)===M.NS.HTML)return{parent:this.treeAdapter.getTemplateContent(i),beforeElement:null};break}case M.TAG_ID.TABLE:{const n=this.treeAdapter.getParentNode(i);return n?{parent:n,beforeElement:i}:{parent:this.openElements.items[I-1],beforeElement:null}}}}return{parent:this.openElements.items[0],beforeElement:null}}},{key:"_fosterParentElement",value:function(I){const i=this._findFosterParentingLocation();i.beforeElement?this.treeAdapter.insertBefore(i.parent,I,i.beforeElement):this.treeAdapter.appendChild(i.parent,I)}},{key:"_isSpecialElement",value:function(I,i){const n=this.treeAdapter.getNamespaceURI(I);return M.SPECIAL_ELEMENTS[n].has(i)}},{key:"onCharacter",value:function(I){if(this.skipNextNewLine=!1,this.tokenizer.inForeignNode){fyt(this,I);return}switch(this.insertionMode){case Re.INITIAL:{_y(this,I);break}case Re.BEFORE_HTML:{KG(this,I);break}case Re.BEFORE_HEAD:{DG(this,I);break}case Re.IN_HEAD:{xG(this,I);break}case Re.IN_HEAD_NO_SCRIPT:{FG(this,I);break}case Re.AFTER_HEAD:{EG(this,I);break}case Re.IN_BODY:case Re.IN_CAPTION:case Re.IN_CELL:case Re.IN_TEMPLATE:{xBe(this,I);break}case Re.TEXT:case Re.IN_SELECT:case Re.IN_SELECT_IN_TABLE:{this._insertCharacters(I);break}case Re.IN_TABLE:case Re.IN_TABLE_BODY:case Re.IN_ROW:{xD(this,I);break}case Re.IN_TABLE_TEXT:{JBe(this,I);break}case Re.IN_COLUMN_GROUP:{m9(this,I);break}case Re.AFTER_BODY:{f9(this,I);break}case Re.AFTER_AFTER_BODY:{X1(this,I);break}}}},{key:"onNullCharacter",value:function(I){if(this.skipNextNewLine=!1,this.tokenizer.inForeignNode){myt(this,I);return}switch(this.insertionMode){case Re.INITIAL:{_y(this,I);break}case Re.BEFORE_HTML:{KG(this,I);break}case Re.BEFORE_HEAD:{DG(this,I);break}case Re.IN_HEAD:{xG(this,I);break}case Re.IN_HEAD_NO_SCRIPT:{FG(this,I);break}case Re.AFTER_HEAD:{EG(this,I);break}case Re.TEXT:{this._insertCharacters(I);break}case Re.IN_TABLE:case Re.IN_TABLE_BODY:case Re.IN_ROW:{xD(this,I);break}case Re.IN_COLUMN_GROUP:{m9(this,I);break}case Re.AFTER_BODY:{f9(this,I);break}case Re.AFTER_AFTER_BODY:{X1(this,I);break}}}},{key:"onComment",value:function(I){if(this.skipNextNewLine=!1,this.currentNotInHTML){$3(this,I);return}switch(this.insertionMode){case Re.INITIAL:case Re.BEFORE_HTML:case Re.BEFORE_HEAD:case Re.IN_HEAD:case Re.IN_HEAD_NO_SCRIPT:case Re.AFTER_HEAD:case Re.IN_BODY:case Re.IN_TABLE:case Re.IN_CAPTION:case Re.IN_COLUMN_GROUP:case Re.IN_TABLE_BODY:case Re.IN_ROW:case Re.IN_CELL:case Re.IN_SELECT:case Re.IN_SELECT_IN_TABLE:case Re.IN_TEMPLATE:case Re.IN_FRAMESET:case Re.AFTER_FRAMESET:{$3(this,I);break}case Re.IN_TABLE_TEXT:{Ly(this,I);break}case Re.AFTER_BODY:{Ubt(this,I);break}case Re.AFTER_AFTER_BODY:case Re.AFTER_AFTER_FRAMESET:{Qbt(this,I);break}}}},{key:"onDoctype",value:function(I){switch(this.skipNextNewLine=!1,this.insertionMode){case Re.INITIAL:{jbt(this,I);break}case Re.BEFORE_HEAD:case Re.IN_HEAD:case Re.IN_HEAD_NO_SCRIPT:case Re.AFTER_HEAD:{this._err(I,ln.ERR.misplacedDoctype);break}case Re.IN_TABLE_TEXT:{Ly(this,I);break}}}},{key:"onStartTag",value:function(I){this.skipNextNewLine=!1,this.currentToken=I,this._processStartTag(I),I.selfClosing&&!I.ackSelfClosing&&this._err(I,ln.ERR.nonVoidHtmlElementStartTagWithTrailingSolidus)}},{key:"_processStartTag",value:function(I){this.shouldProcessStartTagTokenInForeignContent(I)?pyt(this,I):this._startTagOutsideForeignContent(I)}},{key:"_startTagOutsideForeignContent",value:function(I){switch(this.insertionMode){case Re.INITIAL:{_y(this,I);break}case Re.BEFORE_HTML:{$bt(this,I);break}case Re.BEFORE_HEAD:{e0t(this,I);break}case Re.IN_HEAD:{uA(this,I);break}case Re.IN_HEAD_NO_SCRIPT:{I0t(this,I);break}case Re.AFTER_HEAD:{n0t(this,I);break}case Re.IN_BODY:{Kn(this,I);break}case Re.IN_TABLE:{Yb(this,I);break}case Re.IN_TABLE_TEXT:{Ly(this,I);break}case Re.IN_CAPTION:{tyt(this,I);break}case Re.IN_COLUMN_GROUP:{KQ(this,I);break}case Re.IN_TABLE_BODY:{kN(this,I);break}case Re.IN_ROW:{YN(this,I);break}case Re.IN_CELL:{iyt(this,I);break}case Re.IN_SELECT:{LBe(this,I);break}case Re.IN_SELECT_IN_TABLE:{Cyt(this,I);break}case Re.IN_TEMPLATE:{oyt(this,I);break}case Re.AFTER_BODY:{ayt(this,I);break}case Re.IN_FRAMESET:{syt(this,I);break}case Re.AFTER_FRAMESET:{cyt(this,I);break}case Re.AFTER_AFTER_BODY:{dyt(this,I);break}case Re.AFTER_AFTER_FRAMESET:{hyt(this,I);break}}}},{key:"onEndTag",value:function(I){this.skipNextNewLine=!1,this.currentToken=I,this.currentNotInHTML?byt(this,I):this._endTagOutsideForeignContent(I)}},{key:"_endTagOutsideForeignContent",value:function(I){switch(this.insertionMode){case Re.INITIAL:{_y(this,I);break}case Re.BEFORE_HTML:{qbt(this,I);break}case Re.BEFORE_HEAD:{t0t(this,I);break}case Re.IN_HEAD:{g0t(this,I);break}case Re.IN_HEAD_NO_SCRIPT:{i0t(this,I);break}case Re.AFTER_HEAD:{C0t(this,I);break}case Re.IN_BODY:{NN(this,I);break}case Re.TEXT:{J0t(this,I);break}case Re.IN_TABLE:{ZB(this,I);break}case Re.IN_TABLE_TEXT:{Ly(this,I);break}case Re.IN_CAPTION:{gyt(this,I);break}case Re.IN_COLUMN_GROUP:{Iyt(this,I);break}case Re.IN_TABLE_BODY:{q3(this,I);break}case Re.IN_ROW:{_Be(this,I);break}case Re.IN_CELL:{nyt(this,I);break}case Re.IN_SELECT:{UBe(this,I);break}case Re.IN_SELECT_IN_TABLE:{ryt(this,I);break}case Re.IN_TEMPLATE:{Ayt(this,I);break}case Re.AFTER_BODY:{jBe(this,I);break}case Re.IN_FRAMESET:{lyt(this,I);break}case Re.AFTER_FRAMESET:{uyt(this,I);break}case Re.AFTER_AFTER_BODY:{X1(this,I);break}}}},{key:"onEof",value:function(I){switch(this.insertionMode){case Re.INITIAL:{_y(this,I);break}case Re.BEFORE_HTML:{KG(this,I);break}case Re.BEFORE_HEAD:{DG(this,I);break}case Re.IN_HEAD:{xG(this,I);break}case Re.IN_HEAD_NO_SCRIPT:{FG(this,I);break}case Re.AFTER_HEAD:{EG(this,I);break}case Re.IN_BODY:case Re.IN_TABLE:case Re.IN_CAPTION:case Re.IN_COLUMN_GROUP:case Re.IN_TABLE_BODY:case Re.IN_ROW:case Re.IN_CELL:case Re.IN_SELECT:case Re.IN_SELECT_IN_TABLE:{zBe(this,I);break}case Re.TEXT:{O0t(this,I);break}case Re.IN_TABLE_TEXT:{Ly(this,I);break}case Re.IN_TEMPLATE:{QBe(this,I);break}case Re.AFTER_BODY:case Re.IN_FRAMESET:case Re.AFTER_FRAMESET:case Re.AFTER_AFTER_BODY:case Re.AFTER_AFTER_FRAMESET:{YQ(this,I);break}}}},{key:"onWhitespaceCharacter",value:function(I){if(this.skipNextNewLine&&(this.skipNextNewLine=!1,I.chars.charCodeAt(0)===YBe.CODE_POINTS.LINE_FEED)){if(I.chars.length===1)return;I.chars=I.chars.substr(1)}if(this.tokenizer.inForeignNode){this._insertCharacters(I);return}switch(this.insertionMode){case Re.IN_HEAD:case Re.IN_HEAD_NO_SCRIPT:case Re.AFTER_HEAD:case Re.TEXT:case Re.IN_COLUMN_GROUP:case Re.IN_SELECT:case Re.IN_SELECT_IN_TABLE:case Re.IN_FRAMESET:case Re.AFTER_FRAMESET:{this._insertCharacters(I);break}case Re.IN_BODY:case Re.IN_CAPTION:case Re.IN_CELL:case Re.IN_TEMPLATE:case Re.AFTER_BODY:case Re.AFTER_AFTER_BODY:case Re.AFTER_AFTER_FRAMESET:{DBe(this,I);break}case Re.IN_TABLE:case Re.IN_TABLE_BODY:case Re.IN_ROW:{xD(this,I);break}case Re.IN_TABLE_TEXT:{PBe(this,I);break}}}}],[{key:"parse",value:function(I,i){const n=new this(i);return n.tokenizer.write(I,!0),n.document}},{key:"getFragmentParser",value:function(I,i){const n=Object.assign(Object.assign({},une),i);I??(I=n.treeAdapter.createElement(M.TAG_NAMES.TEMPLATE,M.NS.HTML,[]));const C=n.treeAdapter.createElement("documentmock",M.NS.HTML,[]),r=new this(n,C,I);return r.fragmentContextID===M.TAG_ID.TEMPLATE&&r.tmplInsertionModeStack.unshift(Re.IN_TEMPLATE),r._initTokenizerForFragmentParsing(),r._insertFakeRootElement(),r._resetInsertionMode(),r._findFormInFragmentContext(),r}}]),e}();yB.Parser=Mbt;function zbt(e,g){let I=e.activeFormattingElements.getElementEntryInScopeWithTagName(g.tagName);return I?e.openElements.contains(I.element)?e.openElements.hasInScope(g.tagID)||(I=null):(e.activeFormattingElements.removeEntry(I),I=null):MBe(e,g),I}function Pbt(e,g){let I=null,i=e.openElements.stackTop;for(;i>=0;i--){const n=e.openElements.items[i];if(n===g.element)break;e._isSpecialElement(n,e.openElements.tagIDs[i])&&(I=n)}return I||(e.openElements.shortenToLength(i<0?0:i),e.activeFormattingElements.removeEntry(g)),I}function Jbt(e,g,I){let i=g,n=e.openElements.getCommonAncestor(g);for(let C=0,r=n;r!==I;C++,r=n){n=e.openElements.getCommonAncestor(r);const o=e.activeFormattingElements.getElementEntry(r),A=o&&C>=Fbt;!o||A?(A&&e.activeFormattingElements.removeEntry(o),e.openElements.remove(r)):(r=Obt(e,o),i===g&&(e.activeFormattingElements.bookmark=o),e.treeAdapter.detachNode(i),e.treeAdapter.appendChild(r,i),i=r)}return i}function Obt(e,g){const I=e.treeAdapter.getNamespaceURI(g.element),i=e.treeAdapter.createElement(g.token.tagName,I,g.token.attrs);return e.openElements.replace(g.element,i),g.element=i,i}function _bt(e,g,I){const i=e.treeAdapter.getTagName(g),n=(0,M.getTagID)(i);if(e._isElementCausesFosterParenting(n))e._fosterParentElement(I);else{const C=e.treeAdapter.getNamespaceURI(g);n===M.TAG_ID.TEMPLATE&&C===M.NS.HTML&&(g=e.treeAdapter.getTemplateContent(g)),e.treeAdapter.appendChild(g,I)}}function Lbt(e,g,I){const i=e.treeAdapter.getNamespaceURI(I.element),{token:n}=I,C=e.treeAdapter.createElement(n.tagName,i,n.attrs);e._adoptNodes(g,C),e.treeAdapter.appendChild(g,C),e.activeFormattingElements.insertElementAfterBookmark(C,n),e.activeFormattingElements.removeEntry(I),e.openElements.remove(I.element),e.openElements.insertAfter(g,C,n.tagID)}function kQ(e,g){for(let I=0;I=I;i--)e._setEndLocation(e.openElements.items[i],g);if(!e.fragmentContext&&e.openElements.stackTop>=0){const i=e.openElements.items[0],n=e.treeAdapter.getNodeSourceCodeLocation(i);if(n&&!n.endTag&&(e._setEndLocation(i,g),e.openElements.stackTop>=1)){const C=e.openElements.items[1],r=e.treeAdapter.getNodeSourceCodeLocation(C);r&&!r.endTag&&e._setEndLocation(C,g)}}}}function jbt(e,g){e._setDocumentType(g);const I=g.forceQuirks?M.DOCUMENT_MODE.QUIRKS:cne.getDocumentMode(g);cne.isConforming(g)||e._err(g,ln.ERR.nonConformingDoctype),e.treeAdapter.setDocumentMode(e.document,I),e.insertionMode=Re.BEFORE_HTML}function _y(e,g){e._err(g,ln.ERR.missingDoctype,!0),e.treeAdapter.setDocumentMode(e.document,M.DOCUMENT_MODE.QUIRKS),e.insertionMode=Re.BEFORE_HTML,e._processToken(g)}function $bt(e,g){g.tagID===M.TAG_ID.HTML?(e._insertElement(g,M.NS.HTML),e.insertionMode=Re.BEFORE_HEAD):KG(e,g)}function qbt(e,g){const I=g.tagID;(I===M.TAG_ID.HTML||I===M.TAG_ID.HEAD||I===M.TAG_ID.BODY||I===M.TAG_ID.BR)&&KG(e,g)}function KG(e,g){e._insertFakeRootElement(),e.insertionMode=Re.BEFORE_HEAD,e._processToken(g)}function e0t(e,g){switch(g.tagID){case M.TAG_ID.HTML:{Kn(e,g);break}case M.TAG_ID.HEAD:{e._insertElement(g,M.NS.HTML),e.headElement=e.openElements.current,e.insertionMode=Re.IN_HEAD;break}default:DG(e,g)}}function t0t(e,g){const I=g.tagID;I===M.TAG_ID.HEAD||I===M.TAG_ID.BODY||I===M.TAG_ID.HTML||I===M.TAG_ID.BR?DG(e,g):e._err(g,ln.ERR.endTagWithoutMatchingOpenElement)}function DG(e,g){e._insertFakeElement(M.TAG_NAMES.HEAD,M.TAG_ID.HEAD),e.headElement=e.openElements.current,e.insertionMode=Re.IN_HEAD,e._processToken(g)}function uA(e,g){switch(g.tagID){case M.TAG_ID.HTML:{Kn(e,g);break}case M.TAG_ID.BASE:case M.TAG_ID.BASEFONT:case M.TAG_ID.BGSOUND:case M.TAG_ID.LINK:case M.TAG_ID.META:{e._appendElement(g,M.NS.HTML),g.ackSelfClosing=!0;break}case M.TAG_ID.TITLE:{e._switchToTextParsing(g,Jn.TokenizerMode.RCDATA);break}case M.TAG_ID.NOSCRIPT:{e.options.scriptingEnabled?e._switchToTextParsing(g,Jn.TokenizerMode.RAWTEXT):(e._insertElement(g,M.NS.HTML),e.insertionMode=Re.IN_HEAD_NO_SCRIPT);break}case M.TAG_ID.NOFRAMES:case M.TAG_ID.STYLE:{e._switchToTextParsing(g,Jn.TokenizerMode.RAWTEXT);break}case M.TAG_ID.SCRIPT:{e._switchToTextParsing(g,Jn.TokenizerMode.SCRIPT_DATA);break}case M.TAG_ID.TEMPLATE:{e._insertTemplate(g),e.activeFormattingElements.insertMarker(),e.framesetOk=!1,e.insertionMode=Re.IN_TEMPLATE,e.tmplInsertionModeStack.unshift(Re.IN_TEMPLATE);break}case M.TAG_ID.HEAD:{e._err(g,ln.ERR.misplacedStartTagForHeadElement);break}default:xG(e,g)}}function g0t(e,g){switch(g.tagID){case M.TAG_ID.HEAD:{e.openElements.pop(),e.insertionMode=Re.AFTER_HEAD;break}case M.TAG_ID.BODY:case M.TAG_ID.BR:case M.TAG_ID.HTML:{xG(e,g);break}case M.TAG_ID.TEMPLATE:{em(e,g);break}default:e._err(g,ln.ERR.endTagWithoutMatchingOpenElement)}}function em(e,g){e.openElements.tmplCount>0?(e.openElements.generateImpliedEndTagsThoroughly(),e.openElements.currentTagId!==M.TAG_ID.TEMPLATE&&e._err(g,ln.ERR.closingOfElementWithOpenChildElements),e.openElements.popUntilTagNamePopped(M.TAG_ID.TEMPLATE),e.activeFormattingElements.clearToLastMarker(),e.tmplInsertionModeStack.shift(),e._resetInsertionMode()):e._err(g,ln.ERR.endTagWithoutMatchingOpenElement)}function xG(e,g){e.openElements.pop(),e.insertionMode=Re.AFTER_HEAD,e._processToken(g)}function I0t(e,g){switch(g.tagID){case M.TAG_ID.HTML:{Kn(e,g);break}case M.TAG_ID.BASEFONT:case M.TAG_ID.BGSOUND:case M.TAG_ID.HEAD:case M.TAG_ID.LINK:case M.TAG_ID.META:case M.TAG_ID.NOFRAMES:case M.TAG_ID.STYLE:{uA(e,g);break}case M.TAG_ID.NOSCRIPT:{e._err(g,ln.ERR.nestedNoscriptInHead);break}default:FG(e,g)}}function i0t(e,g){switch(g.tagID){case M.TAG_ID.NOSCRIPT:{e.openElements.pop(),e.insertionMode=Re.IN_HEAD;break}case M.TAG_ID.BR:{FG(e,g);break}default:e._err(g,ln.ERR.endTagWithoutMatchingOpenElement)}}function FG(e,g){const I=g.type===Gi.TokenType.EOF?ln.ERR.openElementsLeftAfterEof:ln.ERR.disallowedContentInNoscriptInHead;e._err(g,I),e.openElements.pop(),e.insertionMode=Re.IN_HEAD,e._processToken(g)}function n0t(e,g){switch(g.tagID){case M.TAG_ID.HTML:{Kn(e,g);break}case M.TAG_ID.BODY:{e._insertElement(g,M.NS.HTML),e.framesetOk=!1,e.insertionMode=Re.IN_BODY;break}case M.TAG_ID.FRAMESET:{e._insertElement(g,M.NS.HTML),e.insertionMode=Re.IN_FRAMESET;break}case M.TAG_ID.BASE:case M.TAG_ID.BASEFONT:case M.TAG_ID.BGSOUND:case M.TAG_ID.LINK:case M.TAG_ID.META:case M.TAG_ID.NOFRAMES:case M.TAG_ID.SCRIPT:case M.TAG_ID.STYLE:case M.TAG_ID.TEMPLATE:case M.TAG_ID.TITLE:{e._err(g,ln.ERR.abandonedHeadElementChild),e.openElements.push(e.headElement,M.TAG_ID.HEAD),uA(e,g),e.openElements.remove(e.headElement);break}case M.TAG_ID.HEAD:{e._err(g,ln.ERR.misplacedStartTagForHeadElement);break}default:EG(e,g)}}function C0t(e,g){switch(g.tagID){case M.TAG_ID.BODY:case M.TAG_ID.HTML:case M.TAG_ID.BR:{EG(e,g);break}case M.TAG_ID.TEMPLATE:{em(e,g);break}default:e._err(g,ln.ERR.endTagWithoutMatchingOpenElement)}}function EG(e,g){e._insertFakeElement(M.TAG_NAMES.BODY,M.TAG_ID.BODY),e.insertionMode=Re.IN_BODY,TN(e,g)}function TN(e,g){switch(g.type){case Gi.TokenType.CHARACTER:{xBe(e,g);break}case Gi.TokenType.WHITESPACE_CHARACTER:{DBe(e,g);break}case Gi.TokenType.COMMENT:{$3(e,g);break}case Gi.TokenType.START_TAG:{Kn(e,g);break}case Gi.TokenType.END_TAG:{NN(e,g);break}case Gi.TokenType.EOF:{zBe(e,g);break}}}function DBe(e,g){e._reconstructActiveFormattingElements(),e._insertCharacters(g)}function xBe(e,g){e._reconstructActiveFormattingElements(),e._insertCharacters(g),e.framesetOk=!1}function r0t(e,g){e.openElements.tmplCount===0&&e.treeAdapter.adoptAttributes(e.openElements.items[0],g.attrs)}function o0t(e,g){const I=e.openElements.tryPeekProperlyNestedBodyElement();I&&e.openElements.tmplCount===0&&(e.framesetOk=!1,e.treeAdapter.adoptAttributes(I,g.attrs))}function A0t(e,g){const I=e.openElements.tryPeekProperlyNestedBodyElement();e.framesetOk&&I&&(e.treeAdapter.detachNode(I),e.openElements.popAllUpToHtmlElement(),e._insertElement(g,M.NS.HTML),e.insertionMode=Re.IN_FRAMESET)}function a0t(e,g){e.openElements.hasInButtonScope(M.TAG_ID.P)&&e._closePElement(),e._insertElement(g,M.NS.HTML)}function s0t(e,g){e.openElements.hasInButtonScope(M.TAG_ID.P)&&e._closePElement(),(0,M.isNumberedHeader)(e.openElements.currentTagId)&&e.openElements.pop(),e._insertElement(g,M.NS.HTML)}function l0t(e,g){e.openElements.hasInButtonScope(M.TAG_ID.P)&&e._closePElement(),e._insertElement(g,M.NS.HTML),e.skipNextNewLine=!0,e.framesetOk=!1}function c0t(e,g){const I=e.openElements.tmplCount>0;(!e.formElement||I)&&(e.openElements.hasInButtonScope(M.TAG_ID.P)&&e._closePElement(),e._insertElement(g,M.NS.HTML),I||(e.formElement=e.openElements.current))}function u0t(e,g){e.framesetOk=!1;const I=g.tagID;for(let i=e.openElements.stackTop;i>=0;i--){const n=e.openElements.tagIDs[i];if(I===M.TAG_ID.LI&&n===M.TAG_ID.LI||(I===M.TAG_ID.DD||I===M.TAG_ID.DT)&&(n===M.TAG_ID.DD||n===M.TAG_ID.DT)){e.openElements.generateImpliedEndTagsWithExclusion(n),e.openElements.popUntilTagNamePopped(n);break}if(n!==M.TAG_ID.ADDRESS&&n!==M.TAG_ID.DIV&&n!==M.TAG_ID.P&&e._isSpecialElement(e.openElements.items[i],n))break}e.openElements.hasInButtonScope(M.TAG_ID.P)&&e._closePElement(),e._insertElement(g,M.NS.HTML)}function d0t(e,g){e.openElements.hasInButtonScope(M.TAG_ID.P)&&e._closePElement(),e._insertElement(g,M.NS.HTML),e.tokenizer.state=Jn.TokenizerMode.PLAINTEXT}function h0t(e,g){e.openElements.hasInScope(M.TAG_ID.BUTTON)&&(e.openElements.generateImpliedEndTags(),e.openElements.popUntilTagNamePopped(M.TAG_ID.BUTTON)),e._reconstructActiveFormattingElements(),e._insertElement(g,M.NS.HTML),e.framesetOk=!1}function m0t(e,g){const I=e.activeFormattingElements.getElementEntryInScopeWithTagName(M.TAG_NAMES.A);I&&(kQ(e,g),e.openElements.remove(I.element),e.activeFormattingElements.removeEntry(I)),e._reconstructActiveFormattingElements(),e._insertElement(g,M.NS.HTML),e.activeFormattingElements.pushElement(e.openElements.current,g)}function f0t(e,g){e._reconstructActiveFormattingElements(),e._insertElement(g,M.NS.HTML),e.activeFormattingElements.pushElement(e.openElements.current,g)}function p0t(e,g){e._reconstructActiveFormattingElements(),e.openElements.hasInScope(M.TAG_ID.NOBR)&&(kQ(e,g),e._reconstructActiveFormattingElements()),e._insertElement(g,M.NS.HTML),e.activeFormattingElements.pushElement(e.openElements.current,g)}function b0t(e,g){e._reconstructActiveFormattingElements(),e._insertElement(g,M.NS.HTML),e.activeFormattingElements.insertMarker(),e.framesetOk=!1}function y0t(e,g){e.treeAdapter.getDocumentMode(e.document)!==M.DOCUMENT_MODE.QUIRKS&&e.openElements.hasInButtonScope(M.TAG_ID.P)&&e._closePElement(),e._insertElement(g,M.NS.HTML),e.framesetOk=!1,e.insertionMode=Re.IN_TABLE}function FBe(e,g){e._reconstructActiveFormattingElements(),e._appendElement(g,M.NS.HTML),e.framesetOk=!1,g.ackSelfClosing=!0}function EBe(e){const g=(0,Gi.getTokenAttr)(e,M.ATTRS.TYPE);return g!=null&&g.toLowerCase()===Dbt}function Z0t(e,g){e._reconstructActiveFormattingElements(),e._appendElement(g,M.NS.HTML),EBe(g)||(e.framesetOk=!1),g.ackSelfClosing=!0}function G0t(e,g){e._appendElement(g,M.NS.HTML),g.ackSelfClosing=!0}function v0t(e,g){e.openElements.hasInButtonScope(M.TAG_ID.P)&&e._closePElement(),e._appendElement(g,M.NS.HTML),e.framesetOk=!1,g.ackSelfClosing=!0}function B0t(e,g){g.tagName=M.TAG_NAMES.IMG,g.tagID=M.TAG_ID.IMG,FBe(e,g)}function S0t(e,g){e._insertElement(g,M.NS.HTML),e.skipNextNewLine=!0,e.tokenizer.state=Jn.TokenizerMode.RCDATA,e.originalInsertionMode=e.insertionMode,e.framesetOk=!1,e.insertionMode=Re.TEXT}function w0t(e,g){e.openElements.hasInButtonScope(M.TAG_ID.P)&&e._closePElement(),e._reconstructActiveFormattingElements(),e.framesetOk=!1,e._switchToTextParsing(g,Jn.TokenizerMode.RAWTEXT)}function V0t(e,g){e.framesetOk=!1,e._switchToTextParsing(g,Jn.TokenizerMode.RAWTEXT)}function dne(e,g){e._switchToTextParsing(g,Jn.TokenizerMode.RAWTEXT)}function R0t(e,g){e._reconstructActiveFormattingElements(),e._insertElement(g,M.NS.HTML),e.framesetOk=!1,e.insertionMode=e.insertionMode===Re.IN_TABLE||e.insertionMode===Re.IN_CAPTION||e.insertionMode===Re.IN_TABLE_BODY||e.insertionMode===Re.IN_ROW||e.insertionMode===Re.IN_CELL?Re.IN_SELECT_IN_TABLE:Re.IN_SELECT}function W0t(e,g){e.openElements.currentTagId===M.TAG_ID.OPTION&&e.openElements.pop(),e._reconstructActiveFormattingElements(),e._insertElement(g,M.NS.HTML)}function X0t(e,g){e.openElements.hasInScope(M.TAG_ID.RUBY)&&e.openElements.generateImpliedEndTags(),e._insertElement(g,M.NS.HTML)}function H0t(e,g){e.openElements.hasInScope(M.TAG_ID.RUBY)&&e.openElements.generateImpliedEndTagsWithExclusion(M.TAG_ID.RTC),e._insertElement(g,M.NS.HTML)}function T0t(e,g){e._reconstructActiveFormattingElements(),FA.adjustTokenMathMLAttrs(g),FA.adjustTokenXMLAttrs(g),g.selfClosing?e._appendElement(g,M.NS.MATHML):e._insertElement(g,M.NS.MATHML),g.ackSelfClosing=!0}function N0t(e,g){e._reconstructActiveFormattingElements(),FA.adjustTokenSVGAttrs(g),FA.adjustTokenXMLAttrs(g),g.selfClosing?e._appendElement(g,M.NS.SVG):e._insertElement(g,M.NS.SVG),g.ackSelfClosing=!0}function hne(e,g){e._reconstructActiveFormattingElements(),e._insertElement(g,M.NS.HTML)}function Kn(e,g){switch(g.tagID){case M.TAG_ID.I:case M.TAG_ID.S:case M.TAG_ID.B:case M.TAG_ID.U:case M.TAG_ID.EM:case M.TAG_ID.TT:case M.TAG_ID.BIG:case M.TAG_ID.CODE:case M.TAG_ID.FONT:case M.TAG_ID.SMALL:case M.TAG_ID.STRIKE:case M.TAG_ID.STRONG:{f0t(e,g);break}case M.TAG_ID.A:{m0t(e,g);break}case M.TAG_ID.H1:case M.TAG_ID.H2:case M.TAG_ID.H3:case M.TAG_ID.H4:case M.TAG_ID.H5:case M.TAG_ID.H6:{s0t(e,g);break}case M.TAG_ID.P:case M.TAG_ID.DL:case M.TAG_ID.OL:case M.TAG_ID.UL:case M.TAG_ID.DIV:case M.TAG_ID.DIR:case M.TAG_ID.NAV:case M.TAG_ID.MAIN:case M.TAG_ID.MENU:case M.TAG_ID.ASIDE:case M.TAG_ID.CENTER:case M.TAG_ID.FIGURE:case M.TAG_ID.FOOTER:case M.TAG_ID.HEADER:case M.TAG_ID.HGROUP:case M.TAG_ID.DIALOG:case M.TAG_ID.DETAILS:case M.TAG_ID.ADDRESS:case M.TAG_ID.ARTICLE:case M.TAG_ID.SECTION:case M.TAG_ID.SUMMARY:case M.TAG_ID.FIELDSET:case M.TAG_ID.BLOCKQUOTE:case M.TAG_ID.FIGCAPTION:{a0t(e,g);break}case M.TAG_ID.LI:case M.TAG_ID.DD:case M.TAG_ID.DT:{u0t(e,g);break}case M.TAG_ID.BR:case M.TAG_ID.IMG:case M.TAG_ID.WBR:case M.TAG_ID.AREA:case M.TAG_ID.EMBED:case M.TAG_ID.KEYGEN:{FBe(e,g);break}case M.TAG_ID.HR:{v0t(e,g);break}case M.TAG_ID.RB:case M.TAG_ID.RTC:{X0t(e,g);break}case M.TAG_ID.RT:case M.TAG_ID.RP:{H0t(e,g);break}case M.TAG_ID.PRE:case M.TAG_ID.LISTING:{l0t(e,g);break}case M.TAG_ID.XMP:{w0t(e,g);break}case M.TAG_ID.SVG:{N0t(e,g);break}case M.TAG_ID.HTML:{r0t(e,g);break}case M.TAG_ID.BASE:case M.TAG_ID.LINK:case M.TAG_ID.META:case M.TAG_ID.STYLE:case M.TAG_ID.TITLE:case M.TAG_ID.SCRIPT:case M.TAG_ID.BGSOUND:case M.TAG_ID.BASEFONT:case M.TAG_ID.TEMPLATE:{uA(e,g);break}case M.TAG_ID.BODY:{o0t(e,g);break}case M.TAG_ID.FORM:{c0t(e,g);break}case M.TAG_ID.NOBR:{p0t(e,g);break}case M.TAG_ID.MATH:{T0t(e,g);break}case M.TAG_ID.TABLE:{y0t(e,g);break}case M.TAG_ID.INPUT:{Z0t(e,g);break}case M.TAG_ID.PARAM:case M.TAG_ID.TRACK:case M.TAG_ID.SOURCE:{G0t(e,g);break}case M.TAG_ID.IMAGE:{B0t(e,g);break}case M.TAG_ID.BUTTON:{h0t(e,g);break}case M.TAG_ID.APPLET:case M.TAG_ID.OBJECT:case M.TAG_ID.MARQUEE:{b0t(e,g);break}case M.TAG_ID.IFRAME:{V0t(e,g);break}case M.TAG_ID.SELECT:{R0t(e,g);break}case M.TAG_ID.OPTION:case M.TAG_ID.OPTGROUP:{W0t(e,g);break}case M.TAG_ID.NOEMBED:{dne(e,g);break}case M.TAG_ID.FRAMESET:{A0t(e,g);break}case M.TAG_ID.TEXTAREA:{S0t(e,g);break}case M.TAG_ID.NOSCRIPT:{e.options.scriptingEnabled?dne(e,g):hne(e,g);break}case M.TAG_ID.PLAINTEXT:{d0t(e,g);break}case M.TAG_ID.COL:case M.TAG_ID.TH:case M.TAG_ID.TD:case M.TAG_ID.TR:case M.TAG_ID.HEAD:case M.TAG_ID.FRAME:case M.TAG_ID.TBODY:case M.TAG_ID.TFOOT:case M.TAG_ID.THEAD:case M.TAG_ID.CAPTION:case M.TAG_ID.COLGROUP:break;default:hne(e,g)}}function k0t(e,g){if(e.openElements.hasInScope(M.TAG_ID.BODY)&&(e.insertionMode=Re.AFTER_BODY,e.options.sourceCodeLocationInfo)){const I=e.openElements.tryPeekProperlyNestedBodyElement();I&&e._setEndLocation(I,g)}}function Y0t(e,g){e.openElements.hasInScope(M.TAG_ID.BODY)&&(e.insertionMode=Re.AFTER_BODY,jBe(e,g))}function K0t(e,g){const I=g.tagID;e.openElements.hasInScope(I)&&(e.openElements.generateImpliedEndTags(),e.openElements.popUntilTagNamePopped(I))}function D0t(e){const g=e.openElements.tmplCount>0,{formElement:I}=e;g||(e.formElement=null),(I||g)&&e.openElements.hasInScope(M.TAG_ID.FORM)&&(e.openElements.generateImpliedEndTags(),g?e.openElements.popUntilTagNamePopped(M.TAG_ID.FORM):I&&e.openElements.remove(I))}function x0t(e){e.openElements.hasInButtonScope(M.TAG_ID.P)||e._insertFakeElement(M.TAG_NAMES.P,M.TAG_ID.P),e._closePElement()}function F0t(e){e.openElements.hasInListItemScope(M.TAG_ID.LI)&&(e.openElements.generateImpliedEndTagsWithExclusion(M.TAG_ID.LI),e.openElements.popUntilTagNamePopped(M.TAG_ID.LI))}function E0t(e,g){const I=g.tagID;e.openElements.hasInScope(I)&&(e.openElements.generateImpliedEndTagsWithExclusion(I),e.openElements.popUntilTagNamePopped(I))}function M0t(e){e.openElements.hasNumberedHeaderInScope()&&(e.openElements.generateImpliedEndTags(),e.openElements.popUntilNumberedHeaderPopped())}function z0t(e,g){const I=g.tagID;e.openElements.hasInScope(I)&&(e.openElements.generateImpliedEndTags(),e.openElements.popUntilTagNamePopped(I),e.activeFormattingElements.clearToLastMarker())}function P0t(e){e._reconstructActiveFormattingElements(),e._insertFakeElement(M.TAG_NAMES.BR,M.TAG_ID.BR),e.openElements.pop(),e.framesetOk=!1}function MBe(e,g){const I=g.tagName,i=g.tagID;for(let n=e.openElements.stackTop;n>0;n--){const C=e.openElements.items[n],r=e.openElements.tagIDs[n];if(i===r&&(i!==M.TAG_ID.UNKNOWN||e.treeAdapter.getTagName(C)===I)){e.openElements.generateImpliedEndTagsWithExclusion(i),e.openElements.stackTop>=n&&e.openElements.shortenToLength(n);break}if(e._isSpecialElement(C,r))break}}function NN(e,g){switch(g.tagID){case M.TAG_ID.A:case M.TAG_ID.B:case M.TAG_ID.I:case M.TAG_ID.S:case M.TAG_ID.U:case M.TAG_ID.EM:case M.TAG_ID.TT:case M.TAG_ID.BIG:case M.TAG_ID.CODE:case M.TAG_ID.FONT:case M.TAG_ID.NOBR:case M.TAG_ID.SMALL:case M.TAG_ID.STRIKE:case M.TAG_ID.STRONG:{kQ(e,g);break}case M.TAG_ID.P:{x0t(e);break}case M.TAG_ID.DL:case M.TAG_ID.UL:case M.TAG_ID.OL:case M.TAG_ID.DIR:case M.TAG_ID.DIV:case M.TAG_ID.NAV:case M.TAG_ID.PRE:case M.TAG_ID.MAIN:case M.TAG_ID.MENU:case M.TAG_ID.ASIDE:case M.TAG_ID.BUTTON:case M.TAG_ID.CENTER:case M.TAG_ID.FIGURE:case M.TAG_ID.FOOTER:case M.TAG_ID.HEADER:case M.TAG_ID.HGROUP:case M.TAG_ID.DIALOG:case M.TAG_ID.ADDRESS:case M.TAG_ID.ARTICLE:case M.TAG_ID.DETAILS:case M.TAG_ID.SECTION:case M.TAG_ID.SUMMARY:case M.TAG_ID.LISTING:case M.TAG_ID.FIELDSET:case M.TAG_ID.BLOCKQUOTE:case M.TAG_ID.FIGCAPTION:{K0t(e,g);break}case M.TAG_ID.LI:{F0t(e);break}case M.TAG_ID.DD:case M.TAG_ID.DT:{E0t(e,g);break}case M.TAG_ID.H1:case M.TAG_ID.H2:case M.TAG_ID.H3:case M.TAG_ID.H4:case M.TAG_ID.H5:case M.TAG_ID.H6:{M0t(e);break}case M.TAG_ID.BR:{P0t(e);break}case M.TAG_ID.BODY:{k0t(e,g);break}case M.TAG_ID.HTML:{Y0t(e,g);break}case M.TAG_ID.FORM:{D0t(e);break}case M.TAG_ID.APPLET:case M.TAG_ID.OBJECT:case M.TAG_ID.MARQUEE:{z0t(e,g);break}case M.TAG_ID.TEMPLATE:{em(e,g);break}default:MBe(e,g)}}function zBe(e,g){e.tmplInsertionModeStack.length>0?QBe(e,g):YQ(e,g)}function J0t(e,g){var I;g.tagID===M.TAG_ID.SCRIPT&&((I=e.scriptHandler)===null||I===void 0||I.call(e,e.openElements.current)),e.openElements.pop(),e.insertionMode=e.originalInsertionMode}function O0t(e,g){e._err(g,ln.ERR.eofInElementThatCanContainOnlyText),e.openElements.pop(),e.insertionMode=e.originalInsertionMode,e.onEof(g)}function xD(e,g){if(KBe.has(e.openElements.currentTagId))switch(e.pendingCharacterTokens.length=0,e.hasNonWhitespacePendingCharacterToken=!1,e.originalInsertionMode=e.insertionMode,e.insertionMode=Re.IN_TABLE_TEXT,g.type){case Gi.TokenType.CHARACTER:{JBe(e,g);break}case Gi.TokenType.WHITESPACE_CHARACTER:{PBe(e,g);break}}else zS(e,g)}function _0t(e,g){e.openElements.clearBackToTableContext(),e.activeFormattingElements.insertMarker(),e._insertElement(g,M.NS.HTML),e.insertionMode=Re.IN_CAPTION}function L0t(e,g){e.openElements.clearBackToTableContext(),e._insertElement(g,M.NS.HTML),e.insertionMode=Re.IN_COLUMN_GROUP}function U0t(e,g){e.openElements.clearBackToTableContext(),e._insertFakeElement(M.TAG_NAMES.COLGROUP,M.TAG_ID.COLGROUP),e.insertionMode=Re.IN_COLUMN_GROUP,KQ(e,g)}function Q0t(e,g){e.openElements.clearBackToTableContext(),e._insertElement(g,M.NS.HTML),e.insertionMode=Re.IN_TABLE_BODY}function j0t(e,g){e.openElements.clearBackToTableContext(),e._insertFakeElement(M.TAG_NAMES.TBODY,M.TAG_ID.TBODY),e.insertionMode=Re.IN_TABLE_BODY,kN(e,g)}function $0t(e,g){e.openElements.hasInTableScope(M.TAG_ID.TABLE)&&(e.openElements.popUntilTagNamePopped(M.TAG_ID.TABLE),e._resetInsertionMode(),e._processStartTag(g))}function q0t(e,g){EBe(g)?e._appendElement(g,M.NS.HTML):zS(e,g),g.ackSelfClosing=!0}function eyt(e,g){!e.formElement&&e.openElements.tmplCount===0&&(e._insertElement(g,M.NS.HTML),e.formElement=e.openElements.current,e.openElements.pop())}function Yb(e,g){switch(g.tagID){case M.TAG_ID.TD:case M.TAG_ID.TH:case M.TAG_ID.TR:{j0t(e,g);break}case M.TAG_ID.STYLE:case M.TAG_ID.SCRIPT:case M.TAG_ID.TEMPLATE:{uA(e,g);break}case M.TAG_ID.COL:{U0t(e,g);break}case M.TAG_ID.FORM:{eyt(e,g);break}case M.TAG_ID.TABLE:{$0t(e,g);break}case M.TAG_ID.TBODY:case M.TAG_ID.TFOOT:case M.TAG_ID.THEAD:{Q0t(e,g);break}case M.TAG_ID.INPUT:{q0t(e,g);break}case M.TAG_ID.CAPTION:{_0t(e,g);break}case M.TAG_ID.COLGROUP:{L0t(e,g);break}default:zS(e,g)}}function ZB(e,g){switch(g.tagID){case M.TAG_ID.TABLE:{e.openElements.hasInTableScope(M.TAG_ID.TABLE)&&(e.openElements.popUntilTagNamePopped(M.TAG_ID.TABLE),e._resetInsertionMode());break}case M.TAG_ID.TEMPLATE:{em(e,g);break}case M.TAG_ID.BODY:case M.TAG_ID.CAPTION:case M.TAG_ID.COL:case M.TAG_ID.COLGROUP:case M.TAG_ID.HTML:case M.TAG_ID.TBODY:case M.TAG_ID.TD:case M.TAG_ID.TFOOT:case M.TAG_ID.TH:case M.TAG_ID.THEAD:case M.TAG_ID.TR:break;default:zS(e,g)}}function zS(e,g){const I=e.fosterParentingEnabled;e.fosterParentingEnabled=!0,TN(e,g),e.fosterParentingEnabled=I}function PBe(e,g){e.pendingCharacterTokens.push(g)}function JBe(e,g){e.pendingCharacterTokens.push(g),e.hasNonWhitespacePendingCharacterToken=!0}function Ly(e,g){let I=0;if(e.hasNonWhitespacePendingCharacterToken)for(;I0&&e.openElements.currentTagId===M.TAG_ID.OPTION&&e.openElements.tagIDs[e.openElements.stackTop-1]===M.TAG_ID.OPTGROUP&&e.openElements.pop(),e.openElements.currentTagId===M.TAG_ID.OPTGROUP&&e.openElements.pop();break}case M.TAG_ID.OPTION:{e.openElements.currentTagId===M.TAG_ID.OPTION&&e.openElements.pop();break}case M.TAG_ID.SELECT:{e.openElements.hasInSelectScope(M.TAG_ID.SELECT)&&(e.openElements.popUntilTagNamePopped(M.TAG_ID.SELECT),e._resetInsertionMode());break}case M.TAG_ID.TEMPLATE:{em(e,g);break}}}function Cyt(e,g){const I=g.tagID;I===M.TAG_ID.CAPTION||I===M.TAG_ID.TABLE||I===M.TAG_ID.TBODY||I===M.TAG_ID.TFOOT||I===M.TAG_ID.THEAD||I===M.TAG_ID.TR||I===M.TAG_ID.TD||I===M.TAG_ID.TH?(e.openElements.popUntilTagNamePopped(M.TAG_ID.SELECT),e._resetInsertionMode(),e._processStartTag(g)):LBe(e,g)}function ryt(e,g){const I=g.tagID;I===M.TAG_ID.CAPTION||I===M.TAG_ID.TABLE||I===M.TAG_ID.TBODY||I===M.TAG_ID.TFOOT||I===M.TAG_ID.THEAD||I===M.TAG_ID.TR||I===M.TAG_ID.TD||I===M.TAG_ID.TH?e.openElements.hasInTableScope(I)&&(e.openElements.popUntilTagNamePopped(M.TAG_ID.SELECT),e._resetInsertionMode(),e.onEndTag(g)):UBe(e,g)}function oyt(e,g){switch(g.tagID){case M.TAG_ID.BASE:case M.TAG_ID.BASEFONT:case M.TAG_ID.BGSOUND:case M.TAG_ID.LINK:case M.TAG_ID.META:case M.TAG_ID.NOFRAMES:case M.TAG_ID.SCRIPT:case M.TAG_ID.STYLE:case M.TAG_ID.TEMPLATE:case M.TAG_ID.TITLE:{uA(e,g);break}case M.TAG_ID.CAPTION:case M.TAG_ID.COLGROUP:case M.TAG_ID.TBODY:case M.TAG_ID.TFOOT:case M.TAG_ID.THEAD:{e.tmplInsertionModeStack[0]=Re.IN_TABLE,e.insertionMode=Re.IN_TABLE,Yb(e,g);break}case M.TAG_ID.COL:{e.tmplInsertionModeStack[0]=Re.IN_COLUMN_GROUP,e.insertionMode=Re.IN_COLUMN_GROUP,KQ(e,g);break}case M.TAG_ID.TR:{e.tmplInsertionModeStack[0]=Re.IN_TABLE_BODY,e.insertionMode=Re.IN_TABLE_BODY,kN(e,g);break}case M.TAG_ID.TD:case M.TAG_ID.TH:{e.tmplInsertionModeStack[0]=Re.IN_ROW,e.insertionMode=Re.IN_ROW,YN(e,g);break}default:e.tmplInsertionModeStack[0]=Re.IN_BODY,e.insertionMode=Re.IN_BODY,Kn(e,g)}}function Ayt(e,g){g.tagID===M.TAG_ID.TEMPLATE&&em(e,g)}function QBe(e,g){e.openElements.tmplCount>0?(e.openElements.popUntilTagNamePopped(M.TAG_ID.TEMPLATE),e.activeFormattingElements.clearToLastMarker(),e.tmplInsertionModeStack.shift(),e._resetInsertionMode(),e.onEof(g)):YQ(e,g)}function ayt(e,g){g.tagID===M.TAG_ID.HTML?Kn(e,g):f9(e,g)}function jBe(e,g){var I;if(g.tagID===M.TAG_ID.HTML){if(e.fragmentContext||(e.insertionMode=Re.AFTER_AFTER_BODY),e.options.sourceCodeLocationInfo&&e.openElements.tagIDs[0]===M.TAG_ID.HTML){e._setEndLocation(e.openElements.items[0],g);const i=e.openElements.items[1];i&&!(!((I=e.treeAdapter.getNodeSourceCodeLocation(i))===null||I===void 0)&&I.endTag)&&e._setEndLocation(i,g)}}else f9(e,g)}function f9(e,g){e.insertionMode=Re.IN_BODY,TN(e,g)}function syt(e,g){switch(g.tagID){case M.TAG_ID.HTML:{Kn(e,g);break}case M.TAG_ID.FRAMESET:{e._insertElement(g,M.NS.HTML);break}case M.TAG_ID.FRAME:{e._appendElement(g,M.NS.HTML),g.ackSelfClosing=!0;break}case M.TAG_ID.NOFRAMES:{uA(e,g);break}}}function lyt(e,g){g.tagID===M.TAG_ID.FRAMESET&&!e.openElements.isRootHtmlElementCurrent()&&(e.openElements.pop(),!e.fragmentContext&&e.openElements.currentTagId!==M.TAG_ID.FRAMESET&&(e.insertionMode=Re.AFTER_FRAMESET))}function cyt(e,g){switch(g.tagID){case M.TAG_ID.HTML:{Kn(e,g);break}case M.TAG_ID.NOFRAMES:{uA(e,g);break}}}function uyt(e,g){g.tagID===M.TAG_ID.HTML&&(e.insertionMode=Re.AFTER_AFTER_FRAMESET)}function dyt(e,g){g.tagID===M.TAG_ID.HTML?Kn(e,g):X1(e,g)}function X1(e,g){e.insertionMode=Re.IN_BODY,TN(e,g)}function hyt(e,g){switch(g.tagID){case M.TAG_ID.HTML:{Kn(e,g);break}case M.TAG_ID.NOFRAMES:{uA(e,g);break}}}function myt(e,g){g.chars=YBe.REPLACEMENT_CHARACTER,e._insertCharacters(g)}function fyt(e,g){e._insertCharacters(g),e.framesetOk=!1}function $Be(e){for(;e.treeAdapter.getNamespaceURI(e.openElements.current)!==M.NS.HTML&&!e._isIntegrationPoint(e.openElements.currentTagId,e.openElements.current);)e.openElements.pop()}function pyt(e,g){if(FA.causesExit(g))$Be(e),e._startTagOutsideForeignContent(g);else{const I=e._getAdjustedCurrentElement(),i=e.treeAdapter.getNamespaceURI(I);i===M.NS.MATHML?FA.adjustTokenMathMLAttrs(g):i===M.NS.SVG&&(FA.adjustTokenSVGTagName(g),FA.adjustTokenSVGAttrs(g)),FA.adjustTokenXMLAttrs(g),g.selfClosing?e._appendElement(g,i):e._insertElement(g,i),g.ackSelfClosing=!0}}function byt(e,g){if(g.tagID===M.TAG_ID.P||g.tagID===M.TAG_ID.BR){$Be(e),e._endTagOutsideForeignContent(g);return}for(let I=e.openElements.stackTop;I>0;I--){const i=e.openElements.items[I];if(e.treeAdapter.getNamespaceURI(i)===M.NS.HTML){e._endTagOutsideForeignContent(g);break}const n=e.treeAdapter.getTagName(i);if(n.toLowerCase()===g.tagName){g.tagName=n,e.openElements.shortenToLength(I);break}}}var Kb={};Object.defineProperty(Kb,"__esModule",{value:!0});Kb.serializeOuter=Kb.serialize=void 0;const II=$s,qBe=wb,yyt=HN,Zyt=new Set([II.TAG_NAMES.AREA,II.TAG_NAMES.BASE,II.TAG_NAMES.BASEFONT,II.TAG_NAMES.BGSOUND,II.TAG_NAMES.BR,II.TAG_NAMES.COL,II.TAG_NAMES.EMBED,II.TAG_NAMES.FRAME,II.TAG_NAMES.HR,II.TAG_NAMES.IMG,II.TAG_NAMES.INPUT,II.TAG_NAMES.KEYGEN,II.TAG_NAMES.LINK,II.TAG_NAMES.META,II.TAG_NAMES.PARAM,II.TAG_NAMES.SOURCE,II.TAG_NAMES.TRACK,II.TAG_NAMES.WBR]);function eSe(e,g){return g.treeAdapter.isElementNode(e)&&g.treeAdapter.getNamespaceURI(e)===II.NS.HTML&&Zyt.has(g.treeAdapter.getTagName(e))}const tSe={treeAdapter:yyt.defaultTreeAdapter,scriptingEnabled:!0};function Gyt(e,g){const I=Object.assign(Object.assign({},tSe),g);return eSe(e,I)?"":gSe(e,I)}Kb.serialize=Gyt;function vyt(e,g){const I=Object.assign(Object.assign({},tSe),g);return ISe(e,I)}Kb.serializeOuter=vyt;function gSe(e,g){let I="";const i=g.treeAdapter.isElementNode(e)&&g.treeAdapter.getTagName(e)===II.TAG_NAMES.TEMPLATE&&g.treeAdapter.getNamespaceURI(e)===II.NS.HTML?g.treeAdapter.getTemplateContent(e):e,n=g.treeAdapter.getChildNodes(i);if(n)for(const C of n)I+=ISe(C,g);return I}function ISe(e,g){return g.treeAdapter.isElementNode(e)?Byt(e,g):g.treeAdapter.isTextNode(e)?wyt(e,g):g.treeAdapter.isCommentNode(e)?Vyt(e,g):g.treeAdapter.isDocumentTypeNode(e)?Ryt(e,g):""}function Byt(e,g){const I=g.treeAdapter.getTagName(e);return`<${I}${Syt(e,g)}>${eSe(e,g)?"":`${gSe(e,g)}`}`}function Syt(e,{treeAdapter:g}){let I="";for(const i of g.getAttrList(e)){if(I+=" ",!i.namespace)I+=i.name;else switch(i.namespace){case II.NS.XML:{I+=`xml:${i.name}`;break}case II.NS.XMLNS:{i.name!=="xmlns"&&(I+="xmlns:"),I+=i.name;break}case II.NS.XLINK:{I+=`xlink:${i.name}`;break}default:I+=`${i.prefix}:${i.name}`}I+=`="${(0,qBe.escapeAttribute)(i.value)}"`}return I}function wyt(e,g){const{treeAdapter:I}=g,i=I.getTextNodeContent(e),n=I.getParentNode(e),C=n&&I.isElementNode(n)&&I.getTagName(n);return C&&I.getNamespaceURI(n)===II.NS.HTML&&(0,II.hasUnescapedText)(C,g.scriptingEnabled)?i:(0,qBe.escapeText)(i)}function Vyt(e,{treeAdapter:g}){return``}function Ryt(e,{treeAdapter:g}){return``}(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.parseFragment=e.parse=e.TokenizerMode=e.Tokenizer=e.Token=e.html=e.foreignContent=e.ErrorCodes=e.serializeOuter=e.serialize=e.Parser=e.defaultTreeAdapter=void 0;const g=yB;var I=HN;Object.defineProperty(e,"defaultTreeAdapter",{enumerable:!0,get:function(){return I.defaultTreeAdapter}});var i=yB;Object.defineProperty(e,"Parser",{enumerable:!0,get:function(){return i.Parser}});var n=Kb;Object.defineProperty(e,"serialize",{enumerable:!0,get:function(){return n.serialize}}),Object.defineProperty(e,"serializeOuter",{enumerable:!0,get:function(){return n.serializeOuter}});var C=MS;Object.defineProperty(e,"ErrorCodes",{enumerable:!0,get:function(){return C.ERR}}),e.foreignContent=NQ,e.html=$s,e.Token=WN;var r=ih;Object.defineProperty(e,"Tokenizer",{enumerable:!0,get:function(){return r.Tokenizer}}),Object.defineProperty(e,"TokenizerMode",{enumerable:!0,get:function(){return r.TokenizerMode}});function o(s,a){return g.Parser.parse(s,a)}e.parse=o;function A(s,a,l){typeof s=="string"&&(l=a,a=s,s=null);const c=g.Parser.getFragmentParser(s,l);return c.tokenizer.write(a,!0),c.getFragment()}e.parseFragment=A})(wBe);var iSe={},nSe={},GB={},nh={},KN={},DN={};(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.isUndefinedCodePoint=e.isControlCodePoint=e.getSurrogatePairCodePoint=e.isSurrogatePair=e.isSurrogate=e.SEQUENCES=e.CODE_POINTS=e.REPLACEMENT_CHARACTER=void 0;const g=new Set([65534,65535,131070,131071,196606,196607,262142,262143,327678,327679,393214,393215,458750,458751,524286,524287,589822,589823,655358,655359,720894,720895,786430,786431,851966,851967,917502,917503,983038,983039,1048574,1048575,1114110,1114111]);e.REPLACEMENT_CHARACTER="�",function(o){o[o.EOF=-1]="EOF",o[o.NULL=0]="NULL",o[o.TABULATION=9]="TABULATION",o[o.CARRIAGE_RETURN=13]="CARRIAGE_RETURN",o[o.LINE_FEED=10]="LINE_FEED",o[o.FORM_FEED=12]="FORM_FEED",o[o.SPACE=32]="SPACE",o[o.EXCLAMATION_MARK=33]="EXCLAMATION_MARK",o[o.QUOTATION_MARK=34]="QUOTATION_MARK",o[o.NUMBER_SIGN=35]="NUMBER_SIGN",o[o.AMPERSAND=38]="AMPERSAND",o[o.APOSTROPHE=39]="APOSTROPHE",o[o.HYPHEN_MINUS=45]="HYPHEN_MINUS",o[o.SOLIDUS=47]="SOLIDUS",o[o.DIGIT_0=48]="DIGIT_0",o[o.DIGIT_9=57]="DIGIT_9",o[o.SEMICOLON=59]="SEMICOLON",o[o.LESS_THAN_SIGN=60]="LESS_THAN_SIGN",o[o.EQUALS_SIGN=61]="EQUALS_SIGN",o[o.GREATER_THAN_SIGN=62]="GREATER_THAN_SIGN",o[o.QUESTION_MARK=63]="QUESTION_MARK",o[o.LATIN_CAPITAL_A=65]="LATIN_CAPITAL_A",o[o.LATIN_CAPITAL_F=70]="LATIN_CAPITAL_F",o[o.LATIN_CAPITAL_X=88]="LATIN_CAPITAL_X",o[o.LATIN_CAPITAL_Z=90]="LATIN_CAPITAL_Z",o[o.RIGHT_SQUARE_BRACKET=93]="RIGHT_SQUARE_BRACKET",o[o.GRAVE_ACCENT=96]="GRAVE_ACCENT",o[o.LATIN_SMALL_A=97]="LATIN_SMALL_A",o[o.LATIN_SMALL_F=102]="LATIN_SMALL_F",o[o.LATIN_SMALL_X=120]="LATIN_SMALL_X",o[o.LATIN_SMALL_Z=122]="LATIN_SMALL_Z",o[o.REPLACEMENT_CHARACTER=65533]="REPLACEMENT_CHARACTER"}(e.CODE_POINTS||(e.CODE_POINTS={})),e.SEQUENCES={DASH_DASH:"--",CDATA_START:"[CDATA[",DOCTYPE:"doctype",SCRIPT:"script",PUBLIC:"public",SYSTEM:"system"};function I(o){return o>=55296&&o<=57343}e.isSurrogate=I;function i(o){return o>=56320&&o<=57343}e.isSurrogatePair=i;function n(o,A){return(o-55296)*1024+9216+A}e.getSurrogatePairCodePoint=n;function C(o){return o!==32&&o!==10&&o!==13&&o!==9&&o!==12&&o>=1&&o<=31||o>=127&&o<=159}e.isControlCodePoint=C;function r(o){return o>=64976&&o<=65007||g.has(o)}e.isUndefinedCodePoint=r})(DN);var PS={};(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.ERR=void 0,function(g){g.controlCharacterInInputStream="control-character-in-input-stream",g.noncharacterInInputStream="noncharacter-in-input-stream",g.surrogateInInputStream="surrogate-in-input-stream",g.nonVoidHtmlElementStartTagWithTrailingSolidus="non-void-html-element-start-tag-with-trailing-solidus",g.endTagWithAttributes="end-tag-with-attributes",g.endTagWithTrailingSolidus="end-tag-with-trailing-solidus",g.unexpectedSolidusInTag="unexpected-solidus-in-tag",g.unexpectedNullCharacter="unexpected-null-character",g.unexpectedQuestionMarkInsteadOfTagName="unexpected-question-mark-instead-of-tag-name",g.invalidFirstCharacterOfTagName="invalid-first-character-of-tag-name",g.unexpectedEqualsSignBeforeAttributeName="unexpected-equals-sign-before-attribute-name",g.missingEndTagName="missing-end-tag-name",g.unexpectedCharacterInAttributeName="unexpected-character-in-attribute-name",g.unknownNamedCharacterReference="unknown-named-character-reference",g.missingSemicolonAfterCharacterReference="missing-semicolon-after-character-reference",g.unexpectedCharacterAfterDoctypeSystemIdentifier="unexpected-character-after-doctype-system-identifier",g.unexpectedCharacterInUnquotedAttributeValue="unexpected-character-in-unquoted-attribute-value",g.eofBeforeTagName="eof-before-tag-name",g.eofInTag="eof-in-tag",g.missingAttributeValue="missing-attribute-value",g.missingWhitespaceBetweenAttributes="missing-whitespace-between-attributes",g.missingWhitespaceAfterDoctypePublicKeyword="missing-whitespace-after-doctype-public-keyword",g.missingWhitespaceBetweenDoctypePublicAndSystemIdentifiers="missing-whitespace-between-doctype-public-and-system-identifiers",g.missingWhitespaceAfterDoctypeSystemKeyword="missing-whitespace-after-doctype-system-keyword",g.missingQuoteBeforeDoctypePublicIdentifier="missing-quote-before-doctype-public-identifier",g.missingQuoteBeforeDoctypeSystemIdentifier="missing-quote-before-doctype-system-identifier",g.missingDoctypePublicIdentifier="missing-doctype-public-identifier",g.missingDoctypeSystemIdentifier="missing-doctype-system-identifier",g.abruptDoctypePublicIdentifier="abrupt-doctype-public-identifier",g.abruptDoctypeSystemIdentifier="abrupt-doctype-system-identifier",g.cdataInHtmlContent="cdata-in-html-content",g.incorrectlyOpenedComment="incorrectly-opened-comment",g.eofInScriptHtmlCommentLikeText="eof-in-script-html-comment-like-text",g.eofInDoctype="eof-in-doctype",g.nestedComment="nested-comment",g.abruptClosingOfEmptyComment="abrupt-closing-of-empty-comment",g.eofInComment="eof-in-comment",g.incorrectlyClosedComment="incorrectly-closed-comment",g.eofInCdata="eof-in-cdata",g.absenceOfDigitsInNumericCharacterReference="absence-of-digits-in-numeric-character-reference",g.nullCharacterReference="null-character-reference",g.surrogateCharacterReference="surrogate-character-reference",g.characterReferenceOutsideUnicodeRange="character-reference-outside-unicode-range",g.controlCharacterReference="control-character-reference",g.noncharacterCharacterReference="noncharacter-character-reference",g.missingWhitespaceBeforeDoctypeName="missing-whitespace-before-doctype-name",g.missingDoctypeName="missing-doctype-name",g.invalidCharacterSequenceAfterDoctypeName="invalid-character-sequence-after-doctype-name",g.duplicateAttribute="duplicate-attribute",g.nonConformingDoctype="non-conforming-doctype",g.missingDoctype="missing-doctype",g.misplacedDoctype="misplaced-doctype",g.endTagWithoutMatchingOpenElement="end-tag-without-matching-open-element",g.closingOfElementWithOpenChildElements="closing-of-element-with-open-child-elements",g.disallowedContentInNoscriptInHead="disallowed-content-in-noscript-in-head",g.openElementsLeftAfterEof="open-elements-left-after-eof",g.abandonedHeadElementChild="abandoned-head-element-child",g.misplacedStartTagForHeadElement="misplaced-start-tag-for-head-element",g.nestedNoscriptInHead="nested-noscript-in-head",g.eofInElementThatCanContainOnlyText="eof-in-element-that-can-contain-only-text"}(e.ERR||(e.ERR={}))})(PS);function Wyt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function mne(e,g){for(var I=0;Ithis.bufferWaterline}},{key:"dropParsedChunk",value:function(){this.willDropParsedChunk()&&(this.html=this.html.substring(this.pos),this.lineStartPos-=this.pos,this.droppedBufferSize+=this.pos,this.pos=0,this.lastGapPos=-2,this.gapStack.length=0)}},{key:"write",value:function(I,i){this.html.length>0?this.html+=I:this.html=I,this.endOfChunkHit=!1,this.lastChunkWritten=i}},{key:"insertHtmlAtCurrentPos",value:function(I){this.html=this.html.substring(0,this.pos+1)+I+this.html.substring(this.pos+1),this.endOfChunkHit=!1}},{key:"startsWith",value:function(I,i){if(this.pos+I.length>this.html.length)return this.endOfChunkHit=!this.lastChunkWritten,!1;if(i)return this.html.startsWith(I,this.pos);for(let n=0;n=this.html.length)return this.endOfChunkHit=!this.lastChunkWritten,Fn.CODE_POINTS.EOF;const n=this.html.charCodeAt(i);return n===Fn.CODE_POINTS.CARRIAGE_RETURN?Fn.CODE_POINTS.LINE_FEED:n}},{key:"advance",value:function(){if(this.pos++,this.isEol&&(this.isEol=!1,this.line++,this.lineStartPos=this.pos),this.pos>=this.html.length)return this.endOfChunkHit=!this.lastChunkWritten,Fn.CODE_POINTS.EOF;let I=this.html.charCodeAt(this.pos);return I===Fn.CODE_POINTS.CARRIAGE_RETURN?(this.isEol=!0,this.skipNextNewLine=!0,Fn.CODE_POINTS.LINE_FEED):I===Fn.CODE_POINTS.LINE_FEED&&(this.isEol=!0,this.skipNextNewLine)?(this.line--,this.skipNextNewLine=!1,this._addGap(),this.advance()):(this.skipNextNewLine=!1,(0,Fn.isSurrogate)(I)&&(I=this._processSurrogate(I)),this.handler.onParseError===null||I>31&&I<127||I===Fn.CODE_POINTS.LINE_FEED||I===Fn.CODE_POINTS.CARRIAGE_RETURN||I>159&&I<64976||this._checkForProblematicCharacters(I),I)}},{key:"_checkForProblematicCharacters",value:function(I){(0,Fn.isControlCodePoint)(I)?this._err(FD.ERR.controlCharacterInInputStream):(0,Fn.isUndefinedCodePoint)(I)&&this._err(FD.ERR.noncharacterInInputStream)}},{key:"retreat",value:function(I){for(this.pos-=I;this.pos=0;n--)if(I.attrs[n].name===i)return I.attrs[n].value;return null}e.getTokenAttr=g})(xN);var qs={};(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.hasUnescapedText=e.isNumberedHeader=e.SPECIAL_ELEMENTS=e.getTagID=e.TAG_ID=e.TAG_NAMES=e.DOCUMENT_MODE=e.ATTRS=e.NS=void 0;var g;(function(a){a.HTML="http://www.w3.org/1999/xhtml",a.MATHML="http://www.w3.org/1998/Math/MathML",a.SVG="http://www.w3.org/2000/svg",a.XLINK="http://www.w3.org/1999/xlink",a.XML="http://www.w3.org/XML/1998/namespace",a.XMLNS="http://www.w3.org/2000/xmlns/"})(g=e.NS||(e.NS={})),function(a){a.TYPE="type",a.ACTION="action",a.ENCODING="encoding",a.PROMPT="prompt",a.NAME="name",a.COLOR="color",a.FACE="face",a.SIZE="size"}(e.ATTRS||(e.ATTRS={})),function(a){a.NO_QUIRKS="no-quirks",a.QUIRKS="quirks",a.LIMITED_QUIRKS="limited-quirks"}(e.DOCUMENT_MODE||(e.DOCUMENT_MODE={}));var I;(function(a){a.A="a",a.ADDRESS="address",a.ANNOTATION_XML="annotation-xml",a.APPLET="applet",a.AREA="area",a.ARTICLE="article",a.ASIDE="aside",a.B="b",a.BASE="base",a.BASEFONT="basefont",a.BGSOUND="bgsound",a.BIG="big",a.BLOCKQUOTE="blockquote",a.BODY="body",a.BR="br",a.BUTTON="button",a.CAPTION="caption",a.CENTER="center",a.CODE="code",a.COL="col",a.COLGROUP="colgroup",a.DD="dd",a.DESC="desc",a.DETAILS="details",a.DIALOG="dialog",a.DIR="dir",a.DIV="div",a.DL="dl",a.DT="dt",a.EM="em",a.EMBED="embed",a.FIELDSET="fieldset",a.FIGCAPTION="figcaption",a.FIGURE="figure",a.FONT="font",a.FOOTER="footer",a.FOREIGN_OBJECT="foreignObject",a.FORM="form",a.FRAME="frame",a.FRAMESET="frameset",a.H1="h1",a.H2="h2",a.H3="h3",a.H4="h4",a.H5="h5",a.H6="h6",a.HEAD="head",a.HEADER="header",a.HGROUP="hgroup",a.HR="hr",a.HTML="html",a.I="i",a.IMG="img",a.IMAGE="image",a.INPUT="input",a.IFRAME="iframe",a.KEYGEN="keygen",a.LABEL="label",a.LI="li",a.LINK="link",a.LISTING="listing",a.MAIN="main",a.MALIGNMARK="malignmark",a.MARQUEE="marquee",a.MATH="math",a.MENU="menu",a.META="meta",a.MGLYPH="mglyph",a.MI="mi",a.MO="mo",a.MN="mn",a.MS="ms",a.MTEXT="mtext",a.NAV="nav",a.NOBR="nobr",a.NOFRAMES="noframes",a.NOEMBED="noembed",a.NOSCRIPT="noscript",a.OBJECT="object",a.OL="ol",a.OPTGROUP="optgroup",a.OPTION="option",a.P="p",a.PARAM="param",a.PLAINTEXT="plaintext",a.PRE="pre",a.RB="rb",a.RP="rp",a.RT="rt",a.RTC="rtc",a.RUBY="ruby",a.S="s",a.SCRIPT="script",a.SECTION="section",a.SELECT="select",a.SOURCE="source",a.SMALL="small",a.SPAN="span",a.STRIKE="strike",a.STRONG="strong",a.STYLE="style",a.SUB="sub",a.SUMMARY="summary",a.SUP="sup",a.TABLE="table",a.TBODY="tbody",a.TEMPLATE="template",a.TEXTAREA="textarea",a.TFOOT="tfoot",a.TD="td",a.TH="th",a.THEAD="thead",a.TITLE="title",a.TR="tr",a.TRACK="track",a.TT="tt",a.U="u",a.UL="ul",a.SVG="svg",a.VAR="var",a.WBR="wbr",a.XMP="xmp"})(I=e.TAG_NAMES||(e.TAG_NAMES={}));var i;(function(a){a[a.UNKNOWN=0]="UNKNOWN",a[a.A=1]="A",a[a.ADDRESS=2]="ADDRESS",a[a.ANNOTATION_XML=3]="ANNOTATION_XML",a[a.APPLET=4]="APPLET",a[a.AREA=5]="AREA",a[a.ARTICLE=6]="ARTICLE",a[a.ASIDE=7]="ASIDE",a[a.B=8]="B",a[a.BASE=9]="BASE",a[a.BASEFONT=10]="BASEFONT",a[a.BGSOUND=11]="BGSOUND",a[a.BIG=12]="BIG",a[a.BLOCKQUOTE=13]="BLOCKQUOTE",a[a.BODY=14]="BODY",a[a.BR=15]="BR",a[a.BUTTON=16]="BUTTON",a[a.CAPTION=17]="CAPTION",a[a.CENTER=18]="CENTER",a[a.CODE=19]="CODE",a[a.COL=20]="COL",a[a.COLGROUP=21]="COLGROUP",a[a.DD=22]="DD",a[a.DESC=23]="DESC",a[a.DETAILS=24]="DETAILS",a[a.DIALOG=25]="DIALOG",a[a.DIR=26]="DIR",a[a.DIV=27]="DIV",a[a.DL=28]="DL",a[a.DT=29]="DT",a[a.EM=30]="EM",a[a.EMBED=31]="EMBED",a[a.FIELDSET=32]="FIELDSET",a[a.FIGCAPTION=33]="FIGCAPTION",a[a.FIGURE=34]="FIGURE",a[a.FONT=35]="FONT",a[a.FOOTER=36]="FOOTER",a[a.FOREIGN_OBJECT=37]="FOREIGN_OBJECT",a[a.FORM=38]="FORM",a[a.FRAME=39]="FRAME",a[a.FRAMESET=40]="FRAMESET",a[a.H1=41]="H1",a[a.H2=42]="H2",a[a.H3=43]="H3",a[a.H4=44]="H4",a[a.H5=45]="H5",a[a.H6=46]="H6",a[a.HEAD=47]="HEAD",a[a.HEADER=48]="HEADER",a[a.HGROUP=49]="HGROUP",a[a.HR=50]="HR",a[a.HTML=51]="HTML",a[a.I=52]="I",a[a.IMG=53]="IMG",a[a.IMAGE=54]="IMAGE",a[a.INPUT=55]="INPUT",a[a.IFRAME=56]="IFRAME",a[a.KEYGEN=57]="KEYGEN",a[a.LABEL=58]="LABEL",a[a.LI=59]="LI",a[a.LINK=60]="LINK",a[a.LISTING=61]="LISTING",a[a.MAIN=62]="MAIN",a[a.MALIGNMARK=63]="MALIGNMARK",a[a.MARQUEE=64]="MARQUEE",a[a.MATH=65]="MATH",a[a.MENU=66]="MENU",a[a.META=67]="META",a[a.MGLYPH=68]="MGLYPH",a[a.MI=69]="MI",a[a.MO=70]="MO",a[a.MN=71]="MN",a[a.MS=72]="MS",a[a.MTEXT=73]="MTEXT",a[a.NAV=74]="NAV",a[a.NOBR=75]="NOBR",a[a.NOFRAMES=76]="NOFRAMES",a[a.NOEMBED=77]="NOEMBED",a[a.NOSCRIPT=78]="NOSCRIPT",a[a.OBJECT=79]="OBJECT",a[a.OL=80]="OL",a[a.OPTGROUP=81]="OPTGROUP",a[a.OPTION=82]="OPTION",a[a.P=83]="P",a[a.PARAM=84]="PARAM",a[a.PLAINTEXT=85]="PLAINTEXT",a[a.PRE=86]="PRE",a[a.RB=87]="RB",a[a.RP=88]="RP",a[a.RT=89]="RT",a[a.RTC=90]="RTC",a[a.RUBY=91]="RUBY",a[a.S=92]="S",a[a.SCRIPT=93]="SCRIPT",a[a.SECTION=94]="SECTION",a[a.SELECT=95]="SELECT",a[a.SOURCE=96]="SOURCE",a[a.SMALL=97]="SMALL",a[a.SPAN=98]="SPAN",a[a.STRIKE=99]="STRIKE",a[a.STRONG=100]="STRONG",a[a.STYLE=101]="STYLE",a[a.SUB=102]="SUB",a[a.SUMMARY=103]="SUMMARY",a[a.SUP=104]="SUP",a[a.TABLE=105]="TABLE",a[a.TBODY=106]="TBODY",a[a.TEMPLATE=107]="TEMPLATE",a[a.TEXTAREA=108]="TEXTAREA",a[a.TFOOT=109]="TFOOT",a[a.TD=110]="TD",a[a.TH=111]="TH",a[a.THEAD=112]="THEAD",a[a.TITLE=113]="TITLE",a[a.TR=114]="TR",a[a.TRACK=115]="TRACK",a[a.TT=116]="TT",a[a.U=117]="U",a[a.UL=118]="UL",a[a.SVG=119]="SVG",a[a.VAR=120]="VAR",a[a.WBR=121]="WBR",a[a.XMP=122]="XMP"})(i=e.TAG_ID||(e.TAG_ID={}));const n=new Map([[I.A,i.A],[I.ADDRESS,i.ADDRESS],[I.ANNOTATION_XML,i.ANNOTATION_XML],[I.APPLET,i.APPLET],[I.AREA,i.AREA],[I.ARTICLE,i.ARTICLE],[I.ASIDE,i.ASIDE],[I.B,i.B],[I.BASE,i.BASE],[I.BASEFONT,i.BASEFONT],[I.BGSOUND,i.BGSOUND],[I.BIG,i.BIG],[I.BLOCKQUOTE,i.BLOCKQUOTE],[I.BODY,i.BODY],[I.BR,i.BR],[I.BUTTON,i.BUTTON],[I.CAPTION,i.CAPTION],[I.CENTER,i.CENTER],[I.CODE,i.CODE],[I.COL,i.COL],[I.COLGROUP,i.COLGROUP],[I.DD,i.DD],[I.DESC,i.DESC],[I.DETAILS,i.DETAILS],[I.DIALOG,i.DIALOG],[I.DIR,i.DIR],[I.DIV,i.DIV],[I.DL,i.DL],[I.DT,i.DT],[I.EM,i.EM],[I.EMBED,i.EMBED],[I.FIELDSET,i.FIELDSET],[I.FIGCAPTION,i.FIGCAPTION],[I.FIGURE,i.FIGURE],[I.FONT,i.FONT],[I.FOOTER,i.FOOTER],[I.FOREIGN_OBJECT,i.FOREIGN_OBJECT],[I.FORM,i.FORM],[I.FRAME,i.FRAME],[I.FRAMESET,i.FRAMESET],[I.H1,i.H1],[I.H2,i.H2],[I.H3,i.H3],[I.H4,i.H4],[I.H5,i.H5],[I.H6,i.H6],[I.HEAD,i.HEAD],[I.HEADER,i.HEADER],[I.HGROUP,i.HGROUP],[I.HR,i.HR],[I.HTML,i.HTML],[I.I,i.I],[I.IMG,i.IMG],[I.IMAGE,i.IMAGE],[I.INPUT,i.INPUT],[I.IFRAME,i.IFRAME],[I.KEYGEN,i.KEYGEN],[I.LABEL,i.LABEL],[I.LI,i.LI],[I.LINK,i.LINK],[I.LISTING,i.LISTING],[I.MAIN,i.MAIN],[I.MALIGNMARK,i.MALIGNMARK],[I.MARQUEE,i.MARQUEE],[I.MATH,i.MATH],[I.MENU,i.MENU],[I.META,i.META],[I.MGLYPH,i.MGLYPH],[I.MI,i.MI],[I.MO,i.MO],[I.MN,i.MN],[I.MS,i.MS],[I.MTEXT,i.MTEXT],[I.NAV,i.NAV],[I.NOBR,i.NOBR],[I.NOFRAMES,i.NOFRAMES],[I.NOEMBED,i.NOEMBED],[I.NOSCRIPT,i.NOSCRIPT],[I.OBJECT,i.OBJECT],[I.OL,i.OL],[I.OPTGROUP,i.OPTGROUP],[I.OPTION,i.OPTION],[I.P,i.P],[I.PARAM,i.PARAM],[I.PLAINTEXT,i.PLAINTEXT],[I.PRE,i.PRE],[I.RB,i.RB],[I.RP,i.RP],[I.RT,i.RT],[I.RTC,i.RTC],[I.RUBY,i.RUBY],[I.S,i.S],[I.SCRIPT,i.SCRIPT],[I.SECTION,i.SECTION],[I.SELECT,i.SELECT],[I.SOURCE,i.SOURCE],[I.SMALL,i.SMALL],[I.SPAN,i.SPAN],[I.STRIKE,i.STRIKE],[I.STRONG,i.STRONG],[I.STYLE,i.STYLE],[I.SUB,i.SUB],[I.SUMMARY,i.SUMMARY],[I.SUP,i.SUP],[I.TABLE,i.TABLE],[I.TBODY,i.TBODY],[I.TEMPLATE,i.TEMPLATE],[I.TEXTAREA,i.TEXTAREA],[I.TFOOT,i.TFOOT],[I.TD,i.TD],[I.TH,i.TH],[I.THEAD,i.THEAD],[I.TITLE,i.TITLE],[I.TR,i.TR],[I.TRACK,i.TRACK],[I.TT,i.TT],[I.U,i.U],[I.UL,i.UL],[I.SVG,i.SVG],[I.VAR,i.VAR],[I.WBR,i.WBR],[I.XMP,i.XMP]]);function C(a){var l;return(l=n.get(a))!==null&&l!==void 0?l:i.UNKNOWN}e.getTagID=C;const r=i;e.SPECIAL_ELEMENTS={[g.HTML]:new Set([r.ADDRESS,r.APPLET,r.AREA,r.ARTICLE,r.ASIDE,r.BASE,r.BASEFONT,r.BGSOUND,r.BLOCKQUOTE,r.BODY,r.BR,r.BUTTON,r.CAPTION,r.CENTER,r.COL,r.COLGROUP,r.DD,r.DETAILS,r.DIR,r.DIV,r.DL,r.DT,r.EMBED,r.FIELDSET,r.FIGCAPTION,r.FIGURE,r.FOOTER,r.FORM,r.FRAME,r.FRAMESET,r.H1,r.H2,r.H3,r.H4,r.H5,r.H6,r.HEAD,r.HEADER,r.HGROUP,r.HR,r.HTML,r.IFRAME,r.IMG,r.INPUT,r.LI,r.LINK,r.LISTING,r.MAIN,r.MARQUEE,r.MENU,r.META,r.NAV,r.NOEMBED,r.NOFRAMES,r.NOSCRIPT,r.OBJECT,r.OL,r.P,r.PARAM,r.PLAINTEXT,r.PRE,r.SCRIPT,r.SECTION,r.SELECT,r.SOURCE,r.STYLE,r.SUMMARY,r.TABLE,r.TBODY,r.TD,r.TEMPLATE,r.TEXTAREA,r.TFOOT,r.TH,r.THEAD,r.TITLE,r.TR,r.TRACK,r.UL,r.WBR,r.XMP]),[g.MATHML]:new Set([r.MI,r.MO,r.MN,r.MS,r.MTEXT,r.ANNOTATION_XML]),[g.SVG]:new Set([r.TITLE,r.FOREIGN_OBJECT,r.DESC]),[g.XLINK]:new Set,[g.XML]:new Set,[g.XMLNS]:new Set};function o(a){return a===r.H1||a===r.H2||a===r.H3||a===r.H4||a===r.H5||a===r.H6}e.isNumberedHeader=o;const A=new Set([I.STYLE,I.SCRIPT,I.XMP,I.IFRAME,I.NOEMBED,I.NOFRAMES,I.PLAINTEXT]);function s(a,l){return A.has(a)||l&&a===I.NOSCRIPT}e.hasUnescapedText=s})(qs);function Yyt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function fne(e,g){for(var I=0;I=ae.CODE_POINTS.DIGIT_0&&e<=ae.CODE_POINTS.DIGIT_9}function HZ(e){return e>=ae.CODE_POINTS.LATIN_CAPITAL_A&&e<=ae.CODE_POINTS.LATIN_CAPITAL_Z}function Myt(e){return e>=ae.CODE_POINTS.LATIN_SMALL_A&&e<=ae.CODE_POINTS.LATIN_SMALL_Z}function Bl(e){return Myt(e)||HZ(e)}function ez(e){return Bl(e)||MG(e)}function CSe(e){return e>=ae.CODE_POINTS.LATIN_CAPITAL_A&&e<=ae.CODE_POINTS.LATIN_CAPITAL_F}function rSe(e){return e>=ae.CODE_POINTS.LATIN_SMALL_A&&e<=ae.CODE_POINTS.LATIN_SMALL_F}function zyt(e){return MG(e)||CSe(e)||rSe(e)}function jV(e){return e+32}function oSe(e){return e===ae.CODE_POINTS.SPACE||e===ae.CODE_POINTS.LINE_FEED||e===ae.CODE_POINTS.TABULATION||e===ae.CODE_POINTS.FORM_FEED}function Pyt(e){return e===ae.CODE_POINTS.EQUALS_SIGN||ez(e)}function pne(e){return oSe(e)||e===ae.CODE_POINTS.SOLIDUS||e===ae.CODE_POINTS.GREATER_THAN_SIGN}let Jyt=function(){function e(g,I){Yyt(this,e),this.options=g,this.handler=I,this.paused=!1,this.inLoop=!1,this.inForeignNode=!1,this.lastStartTagName="",this.active=!1,this.state=be.DATA,this.returnState=be.DATA,this.charRefCode=-1,this.consumedAfterSnapshot=-1,this.currentCharacterToken=null,this.currentToken=null,this.currentAttr={name:"",value:""},this.preprocessor=new Fyt.Preprocessor(I),this.currentLocation=this.getCurrentLocation(-1)}return Kyt(e,[{key:"_err",value:function(I){var i,n;(n=(i=this.handler).onParseError)===null||n===void 0||n.call(i,this.preprocessor.getError(I))}},{key:"getCurrentLocation",value:function(I){return this.options.sourceCodeLocationInfo?{startLine:this.preprocessor.line,startCol:this.preprocessor.col-I,startOffset:this.preprocessor.offset-I,endLine:-1,endCol:-1,endOffset:-1}:null}},{key:"_runParsingLoop",value:function(){if(!this.inLoop){for(this.inLoop=!0;this.active&&!this.paused;){this.consumedAfterSnapshot=0;const I=this._consume();this._ensureHibernation()||this._callState(I)}this.inLoop=!1}}},{key:"pause",value:function(){this.paused=!0}},{key:"resume",value:function(I){if(!this.paused)throw new Error("Parser was already resumed");this.paused=!1,!this.inLoop&&(this._runParsingLoop(),this.paused||I==null||I())}},{key:"write",value:function(I,i,n){this.active=!0,this.preprocessor.write(I,i),this._runParsingLoop(),this.paused||n==null||n()}},{key:"insertHtmlAtCurrentPos",value:function(I){this.active=!0,this.preprocessor.insertHtmlAtCurrentPos(I),this._runParsingLoop()}},{key:"_ensureHibernation",value:function(){return this.preprocessor.endOfChunkHit?(this._unconsume(this.consumedAfterSnapshot),this.active=!1,!0):!1}},{key:"_consume",value:function(){return this.consumedAfterSnapshot++,this.preprocessor.advance()}},{key:"_unconsume",value:function(I){this.consumedAfterSnapshot-=I,this.preprocessor.retreat(I)}},{key:"_reconsumeInState",value:function(I,i){this.state=I,this._callState(i)}},{key:"_advanceBy",value:function(I){this.consumedAfterSnapshot+=I;for(let i=0;i0&&this._err($e.ERR.endTagWithAttributes),I.selfClosing&&this._err($e.ERR.endTagWithTrailingSolidus),this.handler.onEndTag(I)),this.preprocessor.dropParsedChunk()}},{key:"emitCurrentComment",value:function(I){this.prepareToken(I),this.handler.onComment(I),this.preprocessor.dropParsedChunk()}},{key:"emitCurrentDoctype",value:function(I){this.prepareToken(I),this.handler.onDoctype(I),this.preprocessor.dropParsedChunk()}},{key:"_emitCurrentCharacterToken",value:function(I){if(this.currentCharacterToken){switch(I&&this.currentCharacterToken.location&&(this.currentCharacterToken.location.endLine=I.startLine,this.currentCharacterToken.location.endCol=I.startCol,this.currentCharacterToken.location.endOffset=I.startOffset),this.currentCharacterToken.type){case hC.TokenType.CHARACTER:{this.handler.onCharacter(this.currentCharacterToken);break}case hC.TokenType.NULL_CHARACTER:{this.handler.onNullCharacter(this.currentCharacterToken);break}case hC.TokenType.WHITESPACE_CHARACTER:{this.handler.onWhitespaceCharacter(this.currentCharacterToken);break}}this.currentCharacterToken=null}}},{key:"_emitEOFToken",value:function(){const I=this.getCurrentLocation(0);I&&(I.endLine=I.startLine,I.endCol=I.startCol,I.endOffset=I.startOffset),this._emitCurrentCharacterToken(I),this.handler.onEof({type:hC.TokenType.EOF,location:I}),this.active=!1}},{key:"_appendCharToCurrentCharacterToken",value:function(I,i){if(this.currentCharacterToken)if(this.currentCharacterToken.type!==I)this.currentLocation=this.getCurrentLocation(0),this._emitCurrentCharacterToken(this.currentLocation),this.preprocessor.dropParsedChunk();else{this.currentCharacterToken.chars+=i;return}this._createCharacterToken(I,i)}},{key:"_emitCodePoint",value:function(I){const i=oSe(I)?hC.TokenType.WHITESPACE_CHARACTER:I===ae.CODE_POINTS.NULL?hC.TokenType.NULL_CHARACTER:hC.TokenType.CHARACTER;this._appendCharToCurrentCharacterToken(i,String.fromCodePoint(I))}},{key:"_emitChars",value:function(I){this._appendCharToCurrentCharacterToken(hC.TokenType.CHARACTER,I)}},{key:"_matchNamedCharacterReference",value:function(I){let i=null,n=0,C=!1;for(let r=0,o=vA.htmlDecodeTree[0];r>=0&&(r=(0,vA.determineBranch)(vA.htmlDecodeTree,o,r+1,I),!(r<0));I=this._consume()){n+=1,o=vA.htmlDecodeTree[r];const A=o&vA.BinTrieFlags.VALUE_LENGTH;if(A){const s=(A>>14)-1;if(I!==ae.CODE_POINTS.SEMICOLON&&this._isCharacterReferenceInAttribute()&&Pyt(this.preprocessor.peek(1))?(i=[ae.CODE_POINTS.AMPERSAND],r+=s):(i=s===0?[vA.htmlDecodeTree[r]&~vA.BinTrieFlags.VALUE_LENGTH]:s===1?[vA.htmlDecodeTree[++r]]:[vA.htmlDecodeTree[++r],vA.htmlDecodeTree[++r]],n=0,C=I!==ae.CODE_POINTS.SEMICOLON),s===0){this._consume();break}}}return this._unconsume(n),C&&!this.preprocessor.endOfChunkHit&&this._err($e.ERR.missingSemicolonAfterCharacterReference),this._unconsume(1),i}},{key:"_isCharacterReferenceInAttribute",value:function(){return this.returnState===be.ATTRIBUTE_VALUE_DOUBLE_QUOTED||this.returnState===be.ATTRIBUTE_VALUE_SINGLE_QUOTED||this.returnState===be.ATTRIBUTE_VALUE_UNQUOTED}},{key:"_flushCodePointConsumedAsCharacterReference",value:function(I){this._isCharacterReferenceInAttribute()?this.currentAttr.value+=String.fromCodePoint(I):this._emitCodePoint(I)}},{key:"_callState",value:function(I){switch(this.state){case be.DATA:{this._stateData(I);break}case be.RCDATA:{this._stateRcdata(I);break}case be.RAWTEXT:{this._stateRawtext(I);break}case be.SCRIPT_DATA:{this._stateScriptData(I);break}case be.PLAINTEXT:{this._statePlaintext(I);break}case be.TAG_OPEN:{this._stateTagOpen(I);break}case be.END_TAG_OPEN:{this._stateEndTagOpen(I);break}case be.TAG_NAME:{this._stateTagName(I);break}case be.RCDATA_LESS_THAN_SIGN:{this._stateRcdataLessThanSign(I);break}case be.RCDATA_END_TAG_OPEN:{this._stateRcdataEndTagOpen(I);break}case be.RCDATA_END_TAG_NAME:{this._stateRcdataEndTagName(I);break}case be.RAWTEXT_LESS_THAN_SIGN:{this._stateRawtextLessThanSign(I);break}case be.RAWTEXT_END_TAG_OPEN:{this._stateRawtextEndTagOpen(I);break}case be.RAWTEXT_END_TAG_NAME:{this._stateRawtextEndTagName(I);break}case be.SCRIPT_DATA_LESS_THAN_SIGN:{this._stateScriptDataLessThanSign(I);break}case be.SCRIPT_DATA_END_TAG_OPEN:{this._stateScriptDataEndTagOpen(I);break}case be.SCRIPT_DATA_END_TAG_NAME:{this._stateScriptDataEndTagName(I);break}case be.SCRIPT_DATA_ESCAPE_START:{this._stateScriptDataEscapeStart(I);break}case be.SCRIPT_DATA_ESCAPE_START_DASH:{this._stateScriptDataEscapeStartDash(I);break}case be.SCRIPT_DATA_ESCAPED:{this._stateScriptDataEscaped(I);break}case be.SCRIPT_DATA_ESCAPED_DASH:{this._stateScriptDataEscapedDash(I);break}case be.SCRIPT_DATA_ESCAPED_DASH_DASH:{this._stateScriptDataEscapedDashDash(I);break}case be.SCRIPT_DATA_ESCAPED_LESS_THAN_SIGN:{this._stateScriptDataEscapedLessThanSign(I);break}case be.SCRIPT_DATA_ESCAPED_END_TAG_OPEN:{this._stateScriptDataEscapedEndTagOpen(I);break}case be.SCRIPT_DATA_ESCAPED_END_TAG_NAME:{this._stateScriptDataEscapedEndTagName(I);break}case be.SCRIPT_DATA_DOUBLE_ESCAPE_START:{this._stateScriptDataDoubleEscapeStart(I);break}case be.SCRIPT_DATA_DOUBLE_ESCAPED:{this._stateScriptDataDoubleEscaped(I);break}case be.SCRIPT_DATA_DOUBLE_ESCAPED_DASH:{this._stateScriptDataDoubleEscapedDash(I);break}case be.SCRIPT_DATA_DOUBLE_ESCAPED_DASH_DASH:{this._stateScriptDataDoubleEscapedDashDash(I);break}case be.SCRIPT_DATA_DOUBLE_ESCAPED_LESS_THAN_SIGN:{this._stateScriptDataDoubleEscapedLessThanSign(I);break}case be.SCRIPT_DATA_DOUBLE_ESCAPE_END:{this._stateScriptDataDoubleEscapeEnd(I);break}case be.BEFORE_ATTRIBUTE_NAME:{this._stateBeforeAttributeName(I);break}case be.ATTRIBUTE_NAME:{this._stateAttributeName(I);break}case be.AFTER_ATTRIBUTE_NAME:{this._stateAfterAttributeName(I);break}case be.BEFORE_ATTRIBUTE_VALUE:{this._stateBeforeAttributeValue(I);break}case be.ATTRIBUTE_VALUE_DOUBLE_QUOTED:{this._stateAttributeValueDoubleQuoted(I);break}case be.ATTRIBUTE_VALUE_SINGLE_QUOTED:{this._stateAttributeValueSingleQuoted(I);break}case be.ATTRIBUTE_VALUE_UNQUOTED:{this._stateAttributeValueUnquoted(I);break}case be.AFTER_ATTRIBUTE_VALUE_QUOTED:{this._stateAfterAttributeValueQuoted(I);break}case be.SELF_CLOSING_START_TAG:{this._stateSelfClosingStartTag(I);break}case be.BOGUS_COMMENT:{this._stateBogusComment(I);break}case be.MARKUP_DECLARATION_OPEN:{this._stateMarkupDeclarationOpen(I);break}case be.COMMENT_START:{this._stateCommentStart(I);break}case be.COMMENT_START_DASH:{this._stateCommentStartDash(I);break}case be.COMMENT:{this._stateComment(I);break}case be.COMMENT_LESS_THAN_SIGN:{this._stateCommentLessThanSign(I);break}case be.COMMENT_LESS_THAN_SIGN_BANG:{this._stateCommentLessThanSignBang(I);break}case be.COMMENT_LESS_THAN_SIGN_BANG_DASH:{this._stateCommentLessThanSignBangDash(I);break}case be.COMMENT_LESS_THAN_SIGN_BANG_DASH_DASH:{this._stateCommentLessThanSignBangDashDash(I);break}case be.COMMENT_END_DASH:{this._stateCommentEndDash(I);break}case be.COMMENT_END:{this._stateCommentEnd(I);break}case be.COMMENT_END_BANG:{this._stateCommentEndBang(I);break}case be.DOCTYPE:{this._stateDoctype(I);break}case be.BEFORE_DOCTYPE_NAME:{this._stateBeforeDoctypeName(I);break}case be.DOCTYPE_NAME:{this._stateDoctypeName(I);break}case be.AFTER_DOCTYPE_NAME:{this._stateAfterDoctypeName(I);break}case be.AFTER_DOCTYPE_PUBLIC_KEYWORD:{this._stateAfterDoctypePublicKeyword(I);break}case be.BEFORE_DOCTYPE_PUBLIC_IDENTIFIER:{this._stateBeforeDoctypePublicIdentifier(I);break}case be.DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED:{this._stateDoctypePublicIdentifierDoubleQuoted(I);break}case be.DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED:{this._stateDoctypePublicIdentifierSingleQuoted(I);break}case be.AFTER_DOCTYPE_PUBLIC_IDENTIFIER:{this._stateAfterDoctypePublicIdentifier(I);break}case be.BETWEEN_DOCTYPE_PUBLIC_AND_SYSTEM_IDENTIFIERS:{this._stateBetweenDoctypePublicAndSystemIdentifiers(I);break}case be.AFTER_DOCTYPE_SYSTEM_KEYWORD:{this._stateAfterDoctypeSystemKeyword(I);break}case be.BEFORE_DOCTYPE_SYSTEM_IDENTIFIER:{this._stateBeforeDoctypeSystemIdentifier(I);break}case be.DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED:{this._stateDoctypeSystemIdentifierDoubleQuoted(I);break}case be.DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED:{this._stateDoctypeSystemIdentifierSingleQuoted(I);break}case be.AFTER_DOCTYPE_SYSTEM_IDENTIFIER:{this._stateAfterDoctypeSystemIdentifier(I);break}case be.BOGUS_DOCTYPE:{this._stateBogusDoctype(I);break}case be.CDATA_SECTION:{this._stateCdataSection(I);break}case be.CDATA_SECTION_BRACKET:{this._stateCdataSectionBracket(I);break}case be.CDATA_SECTION_END:{this._stateCdataSectionEnd(I);break}case be.CHARACTER_REFERENCE:{this._stateCharacterReference(I);break}case be.NAMED_CHARACTER_REFERENCE:{this._stateNamedCharacterReference(I);break}case be.AMBIGUOUS_AMPERSAND:{this._stateAmbiguousAmpersand(I);break}case be.NUMERIC_CHARACTER_REFERENCE:{this._stateNumericCharacterReference(I);break}case be.HEXADEMICAL_CHARACTER_REFERENCE_START:{this._stateHexademicalCharacterReferenceStart(I);break}case be.HEXADEMICAL_CHARACTER_REFERENCE:{this._stateHexademicalCharacterReference(I);break}case be.DECIMAL_CHARACTER_REFERENCE:{this._stateDecimalCharacterReference(I);break}case be.NUMERIC_CHARACTER_REFERENCE_END:{this._stateNumericCharacterReferenceEnd(I);break}default:throw new Error("Unknown state")}}},{key:"_stateData",value:function(I){switch(I){case ae.CODE_POINTS.LESS_THAN_SIGN:{this.state=be.TAG_OPEN;break}case ae.CODE_POINTS.AMPERSAND:{this.returnState=be.DATA,this.state=be.CHARACTER_REFERENCE;break}case ae.CODE_POINTS.NULL:{this._err($e.ERR.unexpectedNullCharacter),this._emitCodePoint(I);break}case ae.CODE_POINTS.EOF:{this._emitEOFToken();break}default:this._emitCodePoint(I)}}},{key:"_stateRcdata",value:function(I){switch(I){case ae.CODE_POINTS.AMPERSAND:{this.returnState=be.RCDATA,this.state=be.CHARACTER_REFERENCE;break}case ae.CODE_POINTS.LESS_THAN_SIGN:{this.state=be.RCDATA_LESS_THAN_SIGN;break}case ae.CODE_POINTS.NULL:{this._err($e.ERR.unexpectedNullCharacter),this._emitChars(ae.REPLACEMENT_CHARACTER);break}case ae.CODE_POINTS.EOF:{this._emitEOFToken();break}default:this._emitCodePoint(I)}}},{key:"_stateRawtext",value:function(I){switch(I){case ae.CODE_POINTS.LESS_THAN_SIGN:{this.state=be.RAWTEXT_LESS_THAN_SIGN;break}case ae.CODE_POINTS.NULL:{this._err($e.ERR.unexpectedNullCharacter),this._emitChars(ae.REPLACEMENT_CHARACTER);break}case ae.CODE_POINTS.EOF:{this._emitEOFToken();break}default:this._emitCodePoint(I)}}},{key:"_stateScriptData",value:function(I){switch(I){case ae.CODE_POINTS.LESS_THAN_SIGN:{this.state=be.SCRIPT_DATA_LESS_THAN_SIGN;break}case ae.CODE_POINTS.NULL:{this._err($e.ERR.unexpectedNullCharacter),this._emitChars(ae.REPLACEMENT_CHARACTER);break}case ae.CODE_POINTS.EOF:{this._emitEOFToken();break}default:this._emitCodePoint(I)}}},{key:"_statePlaintext",value:function(I){switch(I){case ae.CODE_POINTS.NULL:{this._err($e.ERR.unexpectedNullCharacter),this._emitChars(ae.REPLACEMENT_CHARACTER);break}case ae.CODE_POINTS.EOF:{this._emitEOFToken();break}default:this._emitCodePoint(I)}}},{key:"_stateTagOpen",value:function(I){if(Bl(I))this._createStartTagToken(),this.state=be.TAG_NAME,this._stateTagName(I);else switch(I){case ae.CODE_POINTS.EXCLAMATION_MARK:{this.state=be.MARKUP_DECLARATION_OPEN;break}case ae.CODE_POINTS.SOLIDUS:{this.state=be.END_TAG_OPEN;break}case ae.CODE_POINTS.QUESTION_MARK:{this._err($e.ERR.unexpectedQuestionMarkInsteadOfTagName),this._createCommentToken(1),this.state=be.BOGUS_COMMENT,this._stateBogusComment(I);break}case ae.CODE_POINTS.EOF:{this._err($e.ERR.eofBeforeTagName),this._emitChars("<"),this._emitEOFToken();break}default:this._err($e.ERR.invalidFirstCharacterOfTagName),this._emitChars("<"),this.state=be.DATA,this._stateData(I)}}},{key:"_stateEndTagOpen",value:function(I){if(Bl(I))this._createEndTagToken(),this.state=be.TAG_NAME,this._stateTagName(I);else switch(I){case ae.CODE_POINTS.GREATER_THAN_SIGN:{this._err($e.ERR.missingEndTagName),this.state=be.DATA;break}case ae.CODE_POINTS.EOF:{this._err($e.ERR.eofBeforeTagName),this._emitChars("");break}case ae.CODE_POINTS.NULL:{this._err($e.ERR.unexpectedNullCharacter),this.state=be.SCRIPT_DATA_ESCAPED,this._emitChars(ae.REPLACEMENT_CHARACTER);break}case ae.CODE_POINTS.EOF:{this._err($e.ERR.eofInScriptHtmlCommentLikeText),this._emitEOFToken();break}default:this.state=be.SCRIPT_DATA_ESCAPED,this._emitCodePoint(I)}}},{key:"_stateScriptDataEscapedLessThanSign",value:function(I){I===ae.CODE_POINTS.SOLIDUS?this.state=be.SCRIPT_DATA_ESCAPED_END_TAG_OPEN:Bl(I)?(this._emitChars("<"),this.state=be.SCRIPT_DATA_DOUBLE_ESCAPE_START,this._stateScriptDataDoubleEscapeStart(I)):(this._emitChars("<"),this.state=be.SCRIPT_DATA_ESCAPED,this._stateScriptDataEscaped(I))}},{key:"_stateScriptDataEscapedEndTagOpen",value:function(I){Bl(I)?(this.state=be.SCRIPT_DATA_ESCAPED_END_TAG_NAME,this._stateScriptDataEscapedEndTagName(I)):(this._emitChars("");break}case ae.CODE_POINTS.NULL:{this._err($e.ERR.unexpectedNullCharacter),this.state=be.SCRIPT_DATA_DOUBLE_ESCAPED,this._emitChars(ae.REPLACEMENT_CHARACTER);break}case ae.CODE_POINTS.EOF:{this._err($e.ERR.eofInScriptHtmlCommentLikeText),this._emitEOFToken();break}default:this.state=be.SCRIPT_DATA_DOUBLE_ESCAPED,this._emitCodePoint(I)}}},{key:"_stateScriptDataDoubleEscapedLessThanSign",value:function(I){I===ae.CODE_POINTS.SOLIDUS?(this.state=be.SCRIPT_DATA_DOUBLE_ESCAPE_END,this._emitChars("/")):(this.state=be.SCRIPT_DATA_DOUBLE_ESCAPED,this._stateScriptDataDoubleEscaped(I))}},{key:"_stateScriptDataDoubleEscapeEnd",value:function(I){if(this.preprocessor.startsWith(ae.SEQUENCES.SCRIPT,!1)&&pne(this.preprocessor.peek(ae.SEQUENCES.SCRIPT.length))){this._emitCodePoint(I);for(let i=0;i1114111)this._err($e.ERR.characterReferenceOutsideUnicodeRange),this.charRefCode=ae.CODE_POINTS.REPLACEMENT_CHARACTER;else if((0,ae.isSurrogate)(this.charRefCode))this._err($e.ERR.surrogateCharacterReference),this.charRefCode=ae.CODE_POINTS.REPLACEMENT_CHARACTER;else if((0,ae.isUndefinedCodePoint)(this.charRefCode))this._err($e.ERR.noncharacterCharacterReference);else if((0,ae.isControlCodePoint)(this.charRefCode)||this.charRefCode===ae.CODE_POINTS.CARRIAGE_RETURN){this._err($e.ERR.controlCharacterReference);const i=Eyt.get(this.charRefCode);i!==void 0&&(this.charRefCode=i)}this._flushCodePointConsumedAsCharacterReference(this.charRefCode),this._reconsumeInState(this.returnState,I)}}]),e}();nh.Tokenizer=Jyt;var FN={};function Oyt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function bne(e,g){for(var I=0;I0&&this._isInTemplate()&&this.tmplCount--,this.stackTop--,this._updateCurrentElement(),this.handler.onItemPop(I,!0)}},{key:"replace",value:function(I,i){const n=this._indexOf(I);this.items[n]=i,n===this.stackTop&&(this.current=i)}},{key:"insertAfter",value:function(I,i,n){const C=this._indexOf(I)+1;this.items.splice(C,0,i),this.tagIDs.splice(C,0,n),this.stackTop++,C===this.stackTop&&this._updateCurrentElement(),this.handler.onItemPush(this.current,this.currentTagId,C===this.stackTop)}},{key:"popUntilTagNamePopped",value:function(I){let i=this.stackTop+1;do i=this.tagIDs.lastIndexOf(I,i-1);while(i>0&&this.treeAdapter.getNamespaceURI(this.items[i])!==It.NS.HTML);this.shortenToLength(i<0?0:i)}},{key:"shortenToLength",value:function(I){for(;this.stackTop>=I;){const i=this.current;this.tmplCount>0&&this._isInTemplate()&&(this.tmplCount-=1),this.stackTop--,this._updateCurrentElement(),this.handler.onItemPop(i,this.stackTop=0;n--)if(I.includes(this.tagIDs[n])&&this.treeAdapter.getNamespaceURI(this.items[n])===i)return n;return-1}},{key:"clearBackTo",value:function(I,i){const n=this._indexOfTagNames(I,i);this.shortenToLength(n+1)}},{key:"clearBackToTableContext",value:function(){this.clearBackTo(qyt,It.NS.HTML)}},{key:"clearBackToTableBodyContext",value:function(){this.clearBackTo($yt,It.NS.HTML)}},{key:"clearBackToTableRowContext",value:function(){this.clearBackTo(jyt,It.NS.HTML)}},{key:"remove",value:function(I){const i=this._indexOf(I);i>=0&&(i===this.stackTop?this.pop():(this.items.splice(i,1),this.tagIDs.splice(i,1),this.stackTop--,this._updateCurrentElement(),this.handler.onItemPop(I,!1)))}},{key:"tryPeekProperlyNestedBodyElement",value:function(){return this.stackTop>=1&&this.tagIDs[1]===It.TAG_ID.BODY?this.items[1]:null}},{key:"contains",value:function(I){return this._indexOf(I)>-1}},{key:"getCommonAncestor",value:function(I){const i=this._indexOf(I)-1;return i>=0?this.items[i]:null}},{key:"isRootHtmlElementCurrent",value:function(){return this.stackTop===0&&this.tagIDs[0]===It.TAG_ID.HTML}},{key:"hasInScope",value:function(I){for(let i=this.stackTop;i>=0;i--){const n=this.tagIDs[i],C=this.treeAdapter.getNamespaceURI(this.items[i]);if(n===I&&C===It.NS.HTML)return!0;if($V.get(n)===C)return!1}return!0}},{key:"hasNumberedHeaderInScope",value:function(){for(let I=this.stackTop;I>=0;I--){const i=this.tagIDs[I],n=this.treeAdapter.getNamespaceURI(this.items[I]);if((0,It.isNumberedHeader)(i)&&n===It.NS.HTML)return!0;if($V.get(i)===n)return!1}return!0}},{key:"hasInListItemScope",value:function(I){for(let i=this.stackTop;i>=0;i--){const n=this.tagIDs[i],C=this.treeAdapter.getNamespaceURI(this.items[i]);if(n===I&&C===It.NS.HTML)return!0;if((n===It.TAG_ID.UL||n===It.TAG_ID.OL)&&C===It.NS.HTML||$V.get(n)===C)return!1}return!0}},{key:"hasInButtonScope",value:function(I){for(let i=this.stackTop;i>=0;i--){const n=this.tagIDs[i],C=this.treeAdapter.getNamespaceURI(this.items[i]);if(n===I&&C===It.NS.HTML)return!0;if(n===It.TAG_ID.BUTTON&&C===It.NS.HTML||$V.get(n)===C)return!1}return!0}},{key:"hasInTableScope",value:function(I){for(let i=this.stackTop;i>=0;i--){const n=this.tagIDs[i];if(this.treeAdapter.getNamespaceURI(this.items[i])===It.NS.HTML){if(n===I)return!0;if(n===It.TAG_ID.TABLE||n===It.TAG_ID.TEMPLATE||n===It.TAG_ID.HTML)return!1}}return!0}},{key:"hasTableBodyContextInTableScope",value:function(){for(let I=this.stackTop;I>=0;I--){const i=this.tagIDs[I];if(this.treeAdapter.getNamespaceURI(this.items[I])===It.NS.HTML){if(i===It.TAG_ID.TBODY||i===It.TAG_ID.THEAD||i===It.TAG_ID.TFOOT)return!0;if(i===It.TAG_ID.TABLE||i===It.TAG_ID.HTML)return!1}}return!0}},{key:"hasInSelectScope",value:function(I){for(let i=this.stackTop;i>=0;i--){const n=this.tagIDs[i];if(this.treeAdapter.getNamespaceURI(this.items[i])===It.NS.HTML){if(n===I)return!0;if(n!==It.TAG_ID.OPTION&&n!==It.TAG_ID.OPTGROUP)return!1}}return!0}},{key:"generateImpliedEndTags",value:function(){for(;ASe.has(this.currentTagId);)this.pop()}},{key:"generateImpliedEndTagsThoroughly",value:function(){for(;yne.has(this.currentTagId);)this.pop()}},{key:"generateImpliedEndTagsWithExclusion",value:function(I){for(;this.currentTagId!==I&&yne.has(this.currentTagId);)this.pop()}}]),e}();FN.OpenElementStack=tZt;var aSe={};(function(e){function g(a,l){if(!(a instanceof l))throw new TypeError("Cannot call a class as a function")}function I(a,l){for(var c=0;c[f.name,f.value]));let m=0;for(let f=0;fh.get(p.name)===p.value)&&(m+=1,m>=r&&this.entries.splice(b.idx,1))}}},{key:"insertMarker",value:function(){this.entries.unshift(A)}},{key:"pushElement",value:function(c,u){this._ensureNoahArkCondition(c),this.entries.unshift({type:o.Element,element:c,token:u})}},{key:"insertElementAfterBookmark",value:function(c,u){const d=this.entries.indexOf(this.bookmark);this.entries.splice(d,0,{type:o.Element,element:c,token:u})}},{key:"removeEntry",value:function(c){const u=this.entries.indexOf(c);u>=0&&this.entries.splice(u,1)}},{key:"clearToLastMarker",value:function(){const c=this.entries.indexOf(A);c>=0?this.entries.splice(0,c+1):this.entries.length=0}},{key:"getElementEntryInScopeWithTagName",value:function(c){const u=this.entries.find(d=>d.type===o.Marker||this.treeAdapter.getTagName(d.element)===c);return u&&u.type===o.Element?u:null}},{key:"getElementEntry",value:function(c){return this.entries.find(u=>u.type===o.Element&&u.element===c)}}]),a}();e.FormattingElementList=s})(aSe);var EN={};(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.defaultTreeAdapter=void 0;const g=qs;function I(i){return{nodeName:"#text",value:i,parentNode:null}}e.defaultTreeAdapter={createDocument(){return{nodeName:"#document",mode:g.DOCUMENT_MODE.NO_QUIRKS,childNodes:[]}},createDocumentFragment(){return{nodeName:"#document-fragment",childNodes:[]}},createElement(i,n,C){return{nodeName:i,tagName:i,attrs:C,namespaceURI:n,childNodes:[],parentNode:null}},createCommentNode(i){return{nodeName:"#comment",data:i,parentNode:null}},appendChild(i,n){i.childNodes.push(n),n.parentNode=i},insertBefore(i,n,C){const r=i.childNodes.indexOf(C);i.childNodes.splice(r,0,n),n.parentNode=i},setTemplateContent(i,n){i.content=n},getTemplateContent(i){return i.content},setDocumentType(i,n,C,r){const o=i.childNodes.find(A=>A.nodeName==="#documentType");if(o)o.name=n,o.publicId=C,o.systemId=r;else{const A={nodeName:"#documentType",name:n,publicId:C,systemId:r,parentNode:null};e.defaultTreeAdapter.appendChild(i,A)}},setDocumentMode(i,n){i.mode=n},getDocumentMode(i){return i.mode},detachNode(i){if(i.parentNode){const n=i.parentNode.childNodes.indexOf(i);i.parentNode.childNodes.splice(n,1),i.parentNode=null}},insertText(i,n){if(i.childNodes.length>0){const C=i.childNodes[i.childNodes.length-1];if(e.defaultTreeAdapter.isTextNode(C)){C.value+=n;return}}e.defaultTreeAdapter.appendChild(i,I(n))},insertTextBefore(i,n,C){const r=i.childNodes[i.childNodes.indexOf(C)-1];r&&e.defaultTreeAdapter.isTextNode(r)?r.value+=n:e.defaultTreeAdapter.insertBefore(i,I(n),C)},adoptAttributes(i,n){const C=new Set(i.attrs.map(r=>r.name));for(let r=0;re.startsWith(I))}function rZt(e){return e.name===sSe&&e.publicId===null&&(e.systemId===null||e.systemId===gZt)}Db.isConforming=rZt;function oZt(e){if(e.name!==sSe)return Km.DOCUMENT_MODE.QUIRKS;const{systemId:g}=e;if(g&&g.toLowerCase()===IZt)return Km.DOCUMENT_MODE.QUIRKS;let{publicId:I}=e;if(I!==null){if(I=I.toLowerCase(),nZt.has(I))return Km.DOCUMENT_MODE.QUIRKS;let i=g===null?iZt:lSe;if(Zne(I,i))return Km.DOCUMENT_MODE.QUIRKS;if(i=g===null?cSe:CZt,Zne(I,i))return Km.DOCUMENT_MODE.LIMITED_QUIRKS}return Km.DOCUMENT_MODE.NO_QUIRKS}Db.getDocumentMode=oZt;var DQ={};(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.isIntegrationPoint=e.adjustTokenSVGTagName=e.adjustTokenXMLAttrs=e.adjustTokenSVGAttrs=e.adjustTokenMathMLAttrs=e.causesExit=e.SVG_TAG_NAMES_ADJUSTMENT_MAP=void 0;const g=qs,I={TEXT_HTML:"text/html",APPLICATION_XML:"application/xhtml+xml"},i="definitionurl",n="definitionURL",C=new Map(["attributeName","attributeType","baseFrequency","baseProfile","calcMode","clipPathUnits","diffuseConstant","edgeMode","filterUnits","glyphRef","gradientTransform","gradientUnits","kernelMatrix","kernelUnitLength","keyPoints","keySplines","keyTimes","lengthAdjust","limitingConeAngle","markerHeight","markerUnits","markerWidth","maskContentUnits","maskUnits","numOctaves","pathLength","patternContentUnits","patternTransform","patternUnits","pointsAtX","pointsAtY","pointsAtZ","preserveAlpha","preserveAspectRatio","primitiveUnits","refX","refY","repeatCount","repeatDur","requiredExtensions","requiredFeatures","specularConstant","specularExponent","spreadMethod","startOffset","stdDeviation","stitchTiles","surfaceScale","systemLanguage","tableValues","targetX","targetY","textLength","viewBox","viewTarget","xChannelSelector","yChannelSelector","zoomAndPan"].map(m=>[m.toLowerCase(),m])),r=new Map([["xlink:actuate",{prefix:"xlink",name:"actuate",namespace:g.NS.XLINK}],["xlink:arcrole",{prefix:"xlink",name:"arcrole",namespace:g.NS.XLINK}],["xlink:href",{prefix:"xlink",name:"href",namespace:g.NS.XLINK}],["xlink:role",{prefix:"xlink",name:"role",namespace:g.NS.XLINK}],["xlink:show",{prefix:"xlink",name:"show",namespace:g.NS.XLINK}],["xlink:title",{prefix:"xlink",name:"title",namespace:g.NS.XLINK}],["xlink:type",{prefix:"xlink",name:"type",namespace:g.NS.XLINK}],["xml:base",{prefix:"xml",name:"base",namespace:g.NS.XML}],["xml:lang",{prefix:"xml",name:"lang",namespace:g.NS.XML}],["xml:space",{prefix:"xml",name:"space",namespace:g.NS.XML}],["xmlns",{prefix:"",name:"xmlns",namespace:g.NS.XMLNS}],["xmlns:xlink",{prefix:"xmlns",name:"xlink",namespace:g.NS.XMLNS}]]);e.SVG_TAG_NAMES_ADJUSTMENT_MAP=new Map(["altGlyph","altGlyphDef","altGlyphItem","animateColor","animateMotion","animateTransform","clipPath","feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feDistantLight","feFlood","feFuncA","feFuncB","feFuncG","feFuncR","feGaussianBlur","feImage","feMerge","feMergeNode","feMorphology","feOffset","fePointLight","feSpecularLighting","feSpotLight","feTile","feTurbulence","foreignObject","glyphRef","linearGradient","radialGradient","textPath"].map(m=>[m.toLowerCase(),m]));const o=new Set([g.TAG_ID.B,g.TAG_ID.BIG,g.TAG_ID.BLOCKQUOTE,g.TAG_ID.BODY,g.TAG_ID.BR,g.TAG_ID.CENTER,g.TAG_ID.CODE,g.TAG_ID.DD,g.TAG_ID.DIV,g.TAG_ID.DL,g.TAG_ID.DT,g.TAG_ID.EM,g.TAG_ID.EMBED,g.TAG_ID.H1,g.TAG_ID.H2,g.TAG_ID.H3,g.TAG_ID.H4,g.TAG_ID.H5,g.TAG_ID.H6,g.TAG_ID.HEAD,g.TAG_ID.HR,g.TAG_ID.I,g.TAG_ID.IMG,g.TAG_ID.LI,g.TAG_ID.LISTING,g.TAG_ID.MENU,g.TAG_ID.META,g.TAG_ID.NOBR,g.TAG_ID.OL,g.TAG_ID.P,g.TAG_ID.PRE,g.TAG_ID.RUBY,g.TAG_ID.S,g.TAG_ID.SMALL,g.TAG_ID.SPAN,g.TAG_ID.STRONG,g.TAG_ID.STRIKE,g.TAG_ID.SUB,g.TAG_ID.SUP,g.TAG_ID.TABLE,g.TAG_ID.TT,g.TAG_ID.U,g.TAG_ID.UL,g.TAG_ID.VAR]);function A(m){const f=m.tagID;return f===g.TAG_ID.FONT&&m.attrs.some(({name:p})=>p===g.ATTRS.COLOR||p===g.ATTRS.SIZE||p===g.ATTRS.FACE)||o.has(f)}e.causesExit=A;function s(m){for(let f=0;f0&&this._setContextModes(I,i)}},{key:"onItemPop",value:function(I,i){var n,C;if(this.options.sourceCodeLocationInfo&&this._setEndLocation(I,this.currentToken),(C=(n=this.treeAdapter).onItemPop)===null||C===void 0||C.call(n,I,this.openElements.current),i){let r,o;this.openElements.stackTop===0&&this.fragmentContext?(r=this.fragmentContext,o=this.fragmentContextID):{current:r,currentTagId:o}=this.openElements,this._setContextModes(r,o)}}},{key:"_setContextModes",value:function(I,i){const n=I===this.document||this.treeAdapter.getNamespaceURI(I)===z.NS.HTML;this.currentNotInHTML=!n,this.tokenizer.inForeignNode=!n&&!this._isIntegrationPoint(i,I)}},{key:"_switchToTextParsing",value:function(I,i){this._insertElement(I,z.NS.HTML),this.tokenizer.state=i,this.originalInsertionMode=this.insertionMode,this.insertionMode=We.TEXT}},{key:"switchToPlaintextParsing",value:function(){this.insertionMode=We.TEXT,this.originalInsertionMode=We.IN_BODY,this.tokenizer.state=On.TokenizerMode.PLAINTEXT}},{key:"_getAdjustedCurrentElement",value:function(){return this.openElements.stackTop===0&&this.fragmentContext?this.fragmentContext:this.openElements.current}},{key:"_findFormInFragmentContext",value:function(){let I=this.fragmentContext;for(;I;){if(this.treeAdapter.getTagName(I)===z.TAG_NAMES.FORM){this.formElement=I;break}I=this.treeAdapter.getParentNode(I)}}},{key:"_initTokenizerForFragmentParsing",value:function(){if(!(!this.fragmentContext||this.treeAdapter.getNamespaceURI(this.fragmentContext)!==z.NS.HTML))switch(this.fragmentContextID){case z.TAG_ID.TITLE:case z.TAG_ID.TEXTAREA:{this.tokenizer.state=On.TokenizerMode.RCDATA;break}case z.TAG_ID.STYLE:case z.TAG_ID.XMP:case z.TAG_ID.IFRAME:case z.TAG_ID.NOEMBED:case z.TAG_ID.NOFRAMES:case z.TAG_ID.NOSCRIPT:{this.tokenizer.state=On.TokenizerMode.RAWTEXT;break}case z.TAG_ID.SCRIPT:{this.tokenizer.state=On.TokenizerMode.SCRIPT_DATA;break}case z.TAG_ID.PLAINTEXT:{this.tokenizer.state=On.TokenizerMode.PLAINTEXT;break}}}},{key:"_setDocumentType",value:function(I){const i=I.name||"",n=I.publicId||"",C=I.systemId||"";if(this.treeAdapter.setDocumentType(this.document,i,n,C),I.location){const o=this.treeAdapter.getChildNodes(this.document).find(A=>this.treeAdapter.isDocumentTypeNode(A));o&&this.treeAdapter.setNodeSourceCodeLocation(o,I.location)}}},{key:"_attachElementToTree",value:function(I,i){if(this.options.sourceCodeLocationInfo){const n=i&&Object.assign(Object.assign({},i),{startTag:i});this.treeAdapter.setNodeSourceCodeLocation(I,n)}if(this._shouldFosterParentOnInsertion())this._fosterParentElement(I);else{const n=this.openElements.currentTmplContentOrNode;this.treeAdapter.appendChild(n,I)}}},{key:"_appendElement",value:function(I,i){const n=this.treeAdapter.createElement(I.tagName,i,I.attrs);this._attachElementToTree(n,I.location)}},{key:"_insertElement",value:function(I,i){const n=this.treeAdapter.createElement(I.tagName,i,I.attrs);this._attachElementToTree(n,I.location),this.openElements.push(n,I.tagID)}},{key:"_insertFakeElement",value:function(I,i){const n=this.treeAdapter.createElement(I,z.NS.HTML,[]);this._attachElementToTree(n,null),this.openElements.push(n,i)}},{key:"_insertTemplate",value:function(I){const i=this.treeAdapter.createElement(I.tagName,z.NS.HTML,I.attrs),n=this.treeAdapter.createDocumentFragment();this.treeAdapter.setTemplateContent(i,n),this._attachElementToTree(i,I.location),this.openElements.push(i,I.tagID),this.options.sourceCodeLocationInfo&&this.treeAdapter.setNodeSourceCodeLocation(n,null)}},{key:"_insertFakeRootElement",value:function(){const I=this.treeAdapter.createElement(z.TAG_NAMES.HTML,z.NS.HTML,[]);this.options.sourceCodeLocationInfo&&this.treeAdapter.setNodeSourceCodeLocation(I,null),this.treeAdapter.appendChild(this.openElements.current,I),this.openElements.push(I,z.TAG_ID.HTML)}},{key:"_appendCommentNode",value:function(I,i){const n=this.treeAdapter.createCommentNode(I.data);this.treeAdapter.appendChild(i,n),this.options.sourceCodeLocationInfo&&this.treeAdapter.setNodeSourceCodeLocation(n,I.location)}},{key:"_insertCharacters",value:function(I){let i,n;if(this._shouldFosterParentOnInsertion()?({parent:i,beforeElement:n}=this._findFosterParentingLocation(),n?this.treeAdapter.insertTextBefore(i,I.chars,n):this.treeAdapter.insertText(i,I.chars)):(i=this.openElements.currentTmplContentOrNode,this.treeAdapter.insertText(i,I.chars)),!I.location)return;const C=this.treeAdapter.getChildNodes(i),r=n?C.lastIndexOf(n):C.length,o=C[r-1];if(this.treeAdapter.getNodeSourceCodeLocation(o)){const{endLine:s,endCol:a,endOffset:l}=I.location;this.treeAdapter.updateNodeSourceCodeLocation(o,{endLine:s,endCol:a,endOffset:l})}else this.options.sourceCodeLocationInfo&&this.treeAdapter.setNodeSourceCodeLocation(o,I.location)}},{key:"_adoptNodes",value:function(I,i){for(let n=this.treeAdapter.getFirstChild(I);n;n=this.treeAdapter.getFirstChild(I))this.treeAdapter.detachNode(n),this.treeAdapter.appendChild(i,n)}},{key:"_setEndLocation",value:function(I,i){if(this.treeAdapter.getNodeSourceCodeLocation(I)&&i.location){const n=i.location,C=this.treeAdapter.getTagName(I),r=i.type===vi.TokenType.END_TAG&&C===i.tagName?{endTag:Object.assign({},n),endLine:n.endLine,endCol:n.endCol,endOffset:n.endOffset}:{endLine:n.startLine,endCol:n.startCol,endOffset:n.startOffset};this.treeAdapter.updateNodeSourceCodeLocation(I,r)}}},{key:"shouldProcessStartTagTokenInForeignContent",value:function(I){if(!this.currentNotInHTML)return!1;let i,n;return this.openElements.stackTop===0&&this.fragmentContext?(i=this.fragmentContext,n=this.fragmentContextID):{current:i,currentTagId:n}=this.openElements,I.tagID===z.TAG_ID.SVG&&this.treeAdapter.getTagName(i)===z.TAG_NAMES.ANNOTATION_XML&&this.treeAdapter.getNamespaceURI(i)===z.NS.MATHML?!1:this.tokenizer.inForeignNode||(I.tagID===z.TAG_ID.MGLYPH||I.tagID===z.TAG_ID.MALIGNMARK)&&!this._isIntegrationPoint(n,i,z.NS.HTML)}},{key:"_processToken",value:function(I){switch(I.type){case vi.TokenType.CHARACTER:{this.onCharacter(I);break}case vi.TokenType.NULL_CHARACTER:{this.onNullCharacter(I);break}case vi.TokenType.COMMENT:{this.onComment(I);break}case vi.TokenType.DOCTYPE:{this.onDoctype(I);break}case vi.TokenType.START_TAG:{this._processStartTag(I);break}case vi.TokenType.END_TAG:{this.onEndTag(I);break}case vi.TokenType.EOF:{this.onEof(I);break}case vi.TokenType.WHITESPACE_CHARACTER:{this.onWhitespaceCharacter(I);break}}}},{key:"_isIntegrationPoint",value:function(I,i,n){const C=this.treeAdapter.getNamespaceURI(i),r=this.treeAdapter.getAttrList(i);return EA.isIntegrationPoint(I,C,r,n)}},{key:"_reconstructActiveFormattingElements",value:function(){const I=this.activeFormattingElements.entries.length;if(I){const i=this.activeFormattingElements.entries.findIndex(C=>C.type===vne.EntryType.Marker||this.openElements.contains(C.element)),n=i<0?I-1:i-1;for(let C=n;C>=0;C--){const r=this.activeFormattingElements.entries[C];this._insertElement(r.token,this.treeAdapter.getNamespaceURI(r.element)),r.element=this.openElements.current}}}},{key:"_closeTableCell",value:function(){this.openElements.generateImpliedEndTags(),this.openElements.popUntilTableCellPopped(),this.activeFormattingElements.clearToLastMarker(),this.insertionMode=We.IN_ROW}},{key:"_closePElement",value:function(){this.openElements.generateImpliedEndTagsWithExclusion(z.TAG_ID.P),this.openElements.popUntilTagNamePopped(z.TAG_ID.P)}},{key:"_resetInsertionMode",value:function(){for(let I=this.openElements.stackTop;I>=0;I--)switch(I===0&&this.fragmentContext?this.fragmentContextID:this.openElements.tagIDs[I]){case z.TAG_ID.TR:{this.insertionMode=We.IN_ROW;return}case z.TAG_ID.TBODY:case z.TAG_ID.THEAD:case z.TAG_ID.TFOOT:{this.insertionMode=We.IN_TABLE_BODY;return}case z.TAG_ID.CAPTION:{this.insertionMode=We.IN_CAPTION;return}case z.TAG_ID.COLGROUP:{this.insertionMode=We.IN_COLUMN_GROUP;return}case z.TAG_ID.TABLE:{this.insertionMode=We.IN_TABLE;return}case z.TAG_ID.BODY:{this.insertionMode=We.IN_BODY;return}case z.TAG_ID.FRAMESET:{this.insertionMode=We.IN_FRAMESET;return}case z.TAG_ID.SELECT:{this._resetInsertionModeForSelect(I);return}case z.TAG_ID.TEMPLATE:{this.insertionMode=this.tmplInsertionModeStack[0];return}case z.TAG_ID.HTML:{this.insertionMode=this.headElement?We.AFTER_HEAD:We.BEFORE_HEAD;return}case z.TAG_ID.TD:case z.TAG_ID.TH:{if(I>0){this.insertionMode=We.IN_CELL;return}break}case z.TAG_ID.HEAD:{if(I>0){this.insertionMode=We.IN_HEAD;return}break}}this.insertionMode=We.IN_BODY}},{key:"_resetInsertionModeForSelect",value:function(I){if(I>0)for(let i=I-1;i>0;i--){const n=this.openElements.tagIDs[i];if(n===z.TAG_ID.TEMPLATE)break;if(n===z.TAG_ID.TABLE){this.insertionMode=We.IN_SELECT_IN_TABLE;return}}this.insertionMode=We.IN_SELECT}},{key:"_isElementCausesFosterParenting",value:function(I){return dSe.has(I)}},{key:"_shouldFosterParentOnInsertion",value:function(){return this.fosterParentingEnabled&&this._isElementCausesFosterParenting(this.openElements.currentTagId)}},{key:"_findFosterParentingLocation",value:function(){for(let I=this.openElements.stackTop;I>=0;I--){const i=this.openElements.items[I];switch(this.openElements.tagIDs[I]){case z.TAG_ID.TEMPLATE:{if(this.treeAdapter.getNamespaceURI(i)===z.NS.HTML)return{parent:this.treeAdapter.getTemplateContent(i),beforeElement:null};break}case z.TAG_ID.TABLE:{const n=this.treeAdapter.getParentNode(i);return n?{parent:n,beforeElement:i}:{parent:this.openElements.items[I-1],beforeElement:null}}}}return{parent:this.openElements.items[0],beforeElement:null}}},{key:"_fosterParentElement",value:function(I){const i=this._findFosterParentingLocation();i.beforeElement?this.treeAdapter.insertBefore(i.parent,I,i.beforeElement):this.treeAdapter.appendChild(i.parent,I)}},{key:"_isSpecialElement",value:function(I,i){const n=this.treeAdapter.getNamespaceURI(I);return z.SPECIAL_ELEMENTS[n].has(i)}},{key:"onCharacter",value:function(I){if(this.skipNextNewLine=!1,this.tokenizer.inForeignNode){UGt(this,I);return}switch(this.insertionMode){case We.INITIAL:{Uy(this,I);break}case We.BEFORE_HTML:{zG(this,I);break}case We.BEFORE_HEAD:{PG(this,I);break}case We.IN_HEAD:{JG(this,I);break}case We.IN_HEAD_NO_SCRIPT:{OG(this,I);break}case We.AFTER_HEAD:{_G(this,I);break}case We.IN_BODY:case We.IN_CAPTION:case We.IN_CELL:case We.IN_TEMPLATE:{mSe(this,I);break}case We.TEXT:case We.IN_SELECT:case We.IN_SELECT_IN_TABLE:{this._insertCharacters(I);break}case We.IN_TABLE:case We.IN_TABLE_BODY:case We.IN_ROW:{MD(this,I);break}case We.IN_TABLE_TEXT:{GSe(this,I);break}case We.IN_COLUMN_GROUP:{p9(this,I);break}case We.AFTER_BODY:{b9(this,I);break}case We.AFTER_AFTER_BODY:{H1(this,I);break}}}},{key:"onNullCharacter",value:function(I){if(this.skipNextNewLine=!1,this.tokenizer.inForeignNode){LGt(this,I);return}switch(this.insertionMode){case We.INITIAL:{Uy(this,I);break}case We.BEFORE_HTML:{zG(this,I);break}case We.BEFORE_HEAD:{PG(this,I);break}case We.IN_HEAD:{JG(this,I);break}case We.IN_HEAD_NO_SCRIPT:{OG(this,I);break}case We.AFTER_HEAD:{_G(this,I);break}case We.TEXT:{this._insertCharacters(I);break}case We.IN_TABLE:case We.IN_TABLE_BODY:case We.IN_ROW:{MD(this,I);break}case We.IN_COLUMN_GROUP:{p9(this,I);break}case We.AFTER_BODY:{b9(this,I);break}case We.AFTER_AFTER_BODY:{H1(this,I);break}}}},{key:"onComment",value:function(I){if(this.skipNextNewLine=!1,this.currentNotInHTML){tz(this,I);return}switch(this.insertionMode){case We.INITIAL:case We.BEFORE_HTML:case We.BEFORE_HEAD:case We.IN_HEAD:case We.IN_HEAD_NO_SCRIPT:case We.AFTER_HEAD:case We.IN_BODY:case We.IN_TABLE:case We.IN_CAPTION:case We.IN_COLUMN_GROUP:case We.IN_TABLE_BODY:case We.IN_ROW:case We.IN_CELL:case We.IN_SELECT:case We.IN_SELECT_IN_TABLE:case We.IN_TEMPLATE:case We.IN_FRAMESET:case We.AFTER_FRAMESET:{tz(this,I);break}case We.IN_TABLE_TEXT:{Qy(this,I);break}case We.AFTER_BODY:{SZt(this,I);break}case We.AFTER_AFTER_BODY:case We.AFTER_AFTER_FRAMESET:{wZt(this,I);break}}}},{key:"onDoctype",value:function(I){switch(this.skipNextNewLine=!1,this.insertionMode){case We.INITIAL:{VZt(this,I);break}case We.BEFORE_HEAD:case We.IN_HEAD:case We.IN_HEAD_NO_SCRIPT:case We.AFTER_HEAD:{this._err(I,cn.ERR.misplacedDoctype);break}case We.IN_TABLE_TEXT:{Qy(this,I);break}}}},{key:"onStartTag",value:function(I){this.skipNextNewLine=!1,this.currentToken=I,this._processStartTag(I),I.selfClosing&&!I.ackSelfClosing&&this._err(I,cn.ERR.nonVoidHtmlElementStartTagWithTrailingSolidus)}},{key:"_processStartTag",value:function(I){this.shouldProcessStartTagTokenInForeignContent(I)?QGt(this,I):this._startTagOutsideForeignContent(I)}},{key:"_startTagOutsideForeignContent",value:function(I){switch(this.insertionMode){case We.INITIAL:{Uy(this,I);break}case We.BEFORE_HTML:{RZt(this,I);break}case We.BEFORE_HEAD:{XZt(this,I);break}case We.IN_HEAD:{dA(this,I);break}case We.IN_HEAD_NO_SCRIPT:{NZt(this,I);break}case We.AFTER_HEAD:{YZt(this,I);break}case We.IN_BODY:{Dn(this,I);break}case We.IN_TABLE:{xb(this,I);break}case We.IN_TABLE_TEXT:{Qy(this,I);break}case We.IN_CAPTION:{HGt(this,I);break}case We.IN_COLUMN_GROUP:{EQ(this,I);break}case We.IN_TABLE_BODY:{PN(this,I);break}case We.IN_ROW:{JN(this,I);break}case We.IN_CELL:{kGt(this,I);break}case We.IN_SELECT:{SSe(this,I);break}case We.IN_SELECT_IN_TABLE:{KGt(this,I);break}case We.IN_TEMPLATE:{xGt(this,I);break}case We.AFTER_BODY:{EGt(this,I);break}case We.IN_FRAMESET:{MGt(this,I);break}case We.AFTER_FRAMESET:{PGt(this,I);break}case We.AFTER_AFTER_BODY:{OGt(this,I);break}case We.AFTER_AFTER_FRAMESET:{_Gt(this,I);break}}}},{key:"onEndTag",value:function(I){this.skipNextNewLine=!1,this.currentToken=I,this.currentNotInHTML?jGt(this,I):this._endTagOutsideForeignContent(I)}},{key:"_endTagOutsideForeignContent",value:function(I){switch(this.insertionMode){case We.INITIAL:{Uy(this,I);break}case We.BEFORE_HTML:{WZt(this,I);break}case We.BEFORE_HEAD:{HZt(this,I);break}case We.IN_HEAD:{TZt(this,I);break}case We.IN_HEAD_NO_SCRIPT:{kZt(this,I);break}case We.AFTER_HEAD:{KZt(this,I);break}case We.IN_BODY:{zN(this,I);break}case We.TEXT:{ZGt(this,I);break}case We.IN_TABLE:{vB(this,I);break}case We.IN_TABLE_TEXT:{Qy(this,I);break}case We.IN_CAPTION:{TGt(this,I);break}case We.IN_COLUMN_GROUP:{NGt(this,I);break}case We.IN_TABLE_BODY:{gz(this,I);break}case We.IN_ROW:{BSe(this,I);break}case We.IN_CELL:{YGt(this,I);break}case We.IN_SELECT:{wSe(this,I);break}case We.IN_SELECT_IN_TABLE:{DGt(this,I);break}case We.IN_TEMPLATE:{FGt(this,I);break}case We.AFTER_BODY:{RSe(this,I);break}case We.IN_FRAMESET:{zGt(this,I);break}case We.AFTER_FRAMESET:{JGt(this,I);break}case We.AFTER_AFTER_BODY:{H1(this,I);break}}}},{key:"onEof",value:function(I){switch(this.insertionMode){case We.INITIAL:{Uy(this,I);break}case We.BEFORE_HTML:{zG(this,I);break}case We.BEFORE_HEAD:{PG(this,I);break}case We.IN_HEAD:{JG(this,I);break}case We.IN_HEAD_NO_SCRIPT:{OG(this,I);break}case We.AFTER_HEAD:{_G(this,I);break}case We.IN_BODY:case We.IN_TABLE:case We.IN_CAPTION:case We.IN_COLUMN_GROUP:case We.IN_TABLE_BODY:case We.IN_ROW:case We.IN_CELL:case We.IN_SELECT:case We.IN_SELECT_IN_TABLE:{ySe(this,I);break}case We.TEXT:{GGt(this,I);break}case We.IN_TABLE_TEXT:{Qy(this,I);break}case We.IN_TEMPLATE:{VSe(this,I);break}case We.AFTER_BODY:case We.IN_FRAMESET:case We.AFTER_FRAMESET:case We.AFTER_AFTER_BODY:case We.AFTER_AFTER_FRAMESET:{FQ(this,I);break}}}},{key:"onWhitespaceCharacter",value:function(I){if(this.skipNextNewLine&&(this.skipNextNewLine=!1,I.chars.charCodeAt(0)===uSe.CODE_POINTS.LINE_FEED)){if(I.chars.length===1)return;I.chars=I.chars.substr(1)}if(this.tokenizer.inForeignNode){this._insertCharacters(I);return}switch(this.insertionMode){case We.IN_HEAD:case We.IN_HEAD_NO_SCRIPT:case We.AFTER_HEAD:case We.TEXT:case We.IN_COLUMN_GROUP:case We.IN_SELECT:case We.IN_SELECT_IN_TABLE:case We.IN_FRAMESET:case We.AFTER_FRAMESET:{this._insertCharacters(I);break}case We.IN_BODY:case We.IN_CAPTION:case We.IN_CELL:case We.IN_TEMPLATE:case We.AFTER_BODY:case We.AFTER_AFTER_BODY:case We.AFTER_AFTER_FRAMESET:{hSe(this,I);break}case We.IN_TABLE:case We.IN_TABLE_BODY:case We.IN_ROW:{MD(this,I);break}case We.IN_TABLE_TEXT:{ZSe(this,I);break}}}}],[{key:"parse",value:function(I,i){const n=new this(i);return n.tokenizer.write(I,!0),n.document}},{key:"getFragmentParser",value:function(I,i){const n=Object.assign(Object.assign({},Sne),i);I??(I=n.treeAdapter.createElement(z.TAG_NAMES.TEMPLATE,z.NS.HTML,[]));const C=n.treeAdapter.createElement("documentmock",z.NS.HTML,[]),r=new this(n,C,I);return r.fragmentContextID===z.TAG_ID.TEMPLATE&&r.tmplInsertionModeStack.unshift(We.IN_TEMPLATE),r._initTokenizerForFragmentParsing(),r._insertFakeRootElement(),r._resetInsertionMode(),r._findFormInFragmentContext(),r}}]),e}();GB.Parser=pZt;function bZt(e,g){let I=e.activeFormattingElements.getElementEntryInScopeWithTagName(g.tagName);return I?e.openElements.contains(I.element)?e.openElements.hasInScope(g.tagID)||(I=null):(e.activeFormattingElements.removeEntry(I),I=null):bSe(e,g),I}function yZt(e,g){let I=null,i=e.openElements.stackTop;for(;i>=0;i--){const n=e.openElements.items[i];if(n===g.element)break;e._isSpecialElement(n,e.openElements.tagIDs[i])&&(I=n)}return I||(e.openElements.shortenToLength(i<0?0:i),e.activeFormattingElements.removeEntry(g)),I}function ZZt(e,g,I){let i=g,n=e.openElements.getCommonAncestor(g);for(let C=0,r=n;r!==I;C++,r=n){n=e.openElements.getCommonAncestor(r);const o=e.activeFormattingElements.getElementEntry(r),A=o&&C>=mZt;!o||A?(A&&e.activeFormattingElements.removeEntry(o),e.openElements.remove(r)):(r=GZt(e,o),i===g&&(e.activeFormattingElements.bookmark=o),e.treeAdapter.detachNode(i),e.treeAdapter.appendChild(r,i),i=r)}return i}function GZt(e,g){const I=e.treeAdapter.getNamespaceURI(g.element),i=e.treeAdapter.createElement(g.token.tagName,I,g.token.attrs);return e.openElements.replace(g.element,i),g.element=i,i}function vZt(e,g,I){const i=e.treeAdapter.getTagName(g),n=(0,z.getTagID)(i);if(e._isElementCausesFosterParenting(n))e._fosterParentElement(I);else{const C=e.treeAdapter.getNamespaceURI(g);n===z.TAG_ID.TEMPLATE&&C===z.NS.HTML&&(g=e.treeAdapter.getTemplateContent(g)),e.treeAdapter.appendChild(g,I)}}function BZt(e,g,I){const i=e.treeAdapter.getNamespaceURI(I.element),{token:n}=I,C=e.treeAdapter.createElement(n.tagName,i,n.attrs);e._adoptNodes(g,C),e.treeAdapter.appendChild(g,C),e.activeFormattingElements.insertElementAfterBookmark(C,n),e.activeFormattingElements.removeEntry(I),e.openElements.remove(I.element),e.openElements.insertAfter(g,C,n.tagID)}function xQ(e,g){for(let I=0;I=I;i--)e._setEndLocation(e.openElements.items[i],g);if(!e.fragmentContext&&e.openElements.stackTop>=0){const i=e.openElements.items[0],n=e.treeAdapter.getNodeSourceCodeLocation(i);if(n&&!n.endTag&&(e._setEndLocation(i,g),e.openElements.stackTop>=1)){const C=e.openElements.items[1],r=e.treeAdapter.getNodeSourceCodeLocation(C);r&&!r.endTag&&e._setEndLocation(C,g)}}}}function VZt(e,g){e._setDocumentType(g);const I=g.forceQuirks?z.DOCUMENT_MODE.QUIRKS:Bne.getDocumentMode(g);Bne.isConforming(g)||e._err(g,cn.ERR.nonConformingDoctype),e.treeAdapter.setDocumentMode(e.document,I),e.insertionMode=We.BEFORE_HTML}function Uy(e,g){e._err(g,cn.ERR.missingDoctype,!0),e.treeAdapter.setDocumentMode(e.document,z.DOCUMENT_MODE.QUIRKS),e.insertionMode=We.BEFORE_HTML,e._processToken(g)}function RZt(e,g){g.tagID===z.TAG_ID.HTML?(e._insertElement(g,z.NS.HTML),e.insertionMode=We.BEFORE_HEAD):zG(e,g)}function WZt(e,g){const I=g.tagID;(I===z.TAG_ID.HTML||I===z.TAG_ID.HEAD||I===z.TAG_ID.BODY||I===z.TAG_ID.BR)&&zG(e,g)}function zG(e,g){e._insertFakeRootElement(),e.insertionMode=We.BEFORE_HEAD,e._processToken(g)}function XZt(e,g){switch(g.tagID){case z.TAG_ID.HTML:{Dn(e,g);break}case z.TAG_ID.HEAD:{e._insertElement(g,z.NS.HTML),e.headElement=e.openElements.current,e.insertionMode=We.IN_HEAD;break}default:PG(e,g)}}function HZt(e,g){const I=g.tagID;I===z.TAG_ID.HEAD||I===z.TAG_ID.BODY||I===z.TAG_ID.HTML||I===z.TAG_ID.BR?PG(e,g):e._err(g,cn.ERR.endTagWithoutMatchingOpenElement)}function PG(e,g){e._insertFakeElement(z.TAG_NAMES.HEAD,z.TAG_ID.HEAD),e.headElement=e.openElements.current,e.insertionMode=We.IN_HEAD,e._processToken(g)}function dA(e,g){switch(g.tagID){case z.TAG_ID.HTML:{Dn(e,g);break}case z.TAG_ID.BASE:case z.TAG_ID.BASEFONT:case z.TAG_ID.BGSOUND:case z.TAG_ID.LINK:case z.TAG_ID.META:{e._appendElement(g,z.NS.HTML),g.ackSelfClosing=!0;break}case z.TAG_ID.TITLE:{e._switchToTextParsing(g,On.TokenizerMode.RCDATA);break}case z.TAG_ID.NOSCRIPT:{e.options.scriptingEnabled?e._switchToTextParsing(g,On.TokenizerMode.RAWTEXT):(e._insertElement(g,z.NS.HTML),e.insertionMode=We.IN_HEAD_NO_SCRIPT);break}case z.TAG_ID.NOFRAMES:case z.TAG_ID.STYLE:{e._switchToTextParsing(g,On.TokenizerMode.RAWTEXT);break}case z.TAG_ID.SCRIPT:{e._switchToTextParsing(g,On.TokenizerMode.SCRIPT_DATA);break}case z.TAG_ID.TEMPLATE:{e._insertTemplate(g),e.activeFormattingElements.insertMarker(),e.framesetOk=!1,e.insertionMode=We.IN_TEMPLATE,e.tmplInsertionModeStack.unshift(We.IN_TEMPLATE);break}case z.TAG_ID.HEAD:{e._err(g,cn.ERR.misplacedStartTagForHeadElement);break}default:JG(e,g)}}function TZt(e,g){switch(g.tagID){case z.TAG_ID.HEAD:{e.openElements.pop(),e.insertionMode=We.AFTER_HEAD;break}case z.TAG_ID.BODY:case z.TAG_ID.BR:case z.TAG_ID.HTML:{JG(e,g);break}case z.TAG_ID.TEMPLATE:{tm(e,g);break}default:e._err(g,cn.ERR.endTagWithoutMatchingOpenElement)}}function tm(e,g){e.openElements.tmplCount>0?(e.openElements.generateImpliedEndTagsThoroughly(),e.openElements.currentTagId!==z.TAG_ID.TEMPLATE&&e._err(g,cn.ERR.closingOfElementWithOpenChildElements),e.openElements.popUntilTagNamePopped(z.TAG_ID.TEMPLATE),e.activeFormattingElements.clearToLastMarker(),e.tmplInsertionModeStack.shift(),e._resetInsertionMode()):e._err(g,cn.ERR.endTagWithoutMatchingOpenElement)}function JG(e,g){e.openElements.pop(),e.insertionMode=We.AFTER_HEAD,e._processToken(g)}function NZt(e,g){switch(g.tagID){case z.TAG_ID.HTML:{Dn(e,g);break}case z.TAG_ID.BASEFONT:case z.TAG_ID.BGSOUND:case z.TAG_ID.HEAD:case z.TAG_ID.LINK:case z.TAG_ID.META:case z.TAG_ID.NOFRAMES:case z.TAG_ID.STYLE:{dA(e,g);break}case z.TAG_ID.NOSCRIPT:{e._err(g,cn.ERR.nestedNoscriptInHead);break}default:OG(e,g)}}function kZt(e,g){switch(g.tagID){case z.TAG_ID.NOSCRIPT:{e.openElements.pop(),e.insertionMode=We.IN_HEAD;break}case z.TAG_ID.BR:{OG(e,g);break}default:e._err(g,cn.ERR.endTagWithoutMatchingOpenElement)}}function OG(e,g){const I=g.type===vi.TokenType.EOF?cn.ERR.openElementsLeftAfterEof:cn.ERR.disallowedContentInNoscriptInHead;e._err(g,I),e.openElements.pop(),e.insertionMode=We.IN_HEAD,e._processToken(g)}function YZt(e,g){switch(g.tagID){case z.TAG_ID.HTML:{Dn(e,g);break}case z.TAG_ID.BODY:{e._insertElement(g,z.NS.HTML),e.framesetOk=!1,e.insertionMode=We.IN_BODY;break}case z.TAG_ID.FRAMESET:{e._insertElement(g,z.NS.HTML),e.insertionMode=We.IN_FRAMESET;break}case z.TAG_ID.BASE:case z.TAG_ID.BASEFONT:case z.TAG_ID.BGSOUND:case z.TAG_ID.LINK:case z.TAG_ID.META:case z.TAG_ID.NOFRAMES:case z.TAG_ID.SCRIPT:case z.TAG_ID.STYLE:case z.TAG_ID.TEMPLATE:case z.TAG_ID.TITLE:{e._err(g,cn.ERR.abandonedHeadElementChild),e.openElements.push(e.headElement,z.TAG_ID.HEAD),dA(e,g),e.openElements.remove(e.headElement);break}case z.TAG_ID.HEAD:{e._err(g,cn.ERR.misplacedStartTagForHeadElement);break}default:_G(e,g)}}function KZt(e,g){switch(g.tagID){case z.TAG_ID.BODY:case z.TAG_ID.HTML:case z.TAG_ID.BR:{_G(e,g);break}case z.TAG_ID.TEMPLATE:{tm(e,g);break}default:e._err(g,cn.ERR.endTagWithoutMatchingOpenElement)}}function _G(e,g){e._insertFakeElement(z.TAG_NAMES.BODY,z.TAG_ID.BODY),e.insertionMode=We.IN_BODY,MN(e,g)}function MN(e,g){switch(g.type){case vi.TokenType.CHARACTER:{mSe(e,g);break}case vi.TokenType.WHITESPACE_CHARACTER:{hSe(e,g);break}case vi.TokenType.COMMENT:{tz(e,g);break}case vi.TokenType.START_TAG:{Dn(e,g);break}case vi.TokenType.END_TAG:{zN(e,g);break}case vi.TokenType.EOF:{ySe(e,g);break}}}function hSe(e,g){e._reconstructActiveFormattingElements(),e._insertCharacters(g)}function mSe(e,g){e._reconstructActiveFormattingElements(),e._insertCharacters(g),e.framesetOk=!1}function DZt(e,g){e.openElements.tmplCount===0&&e.treeAdapter.adoptAttributes(e.openElements.items[0],g.attrs)}function xZt(e,g){const I=e.openElements.tryPeekProperlyNestedBodyElement();I&&e.openElements.tmplCount===0&&(e.framesetOk=!1,e.treeAdapter.adoptAttributes(I,g.attrs))}function FZt(e,g){const I=e.openElements.tryPeekProperlyNestedBodyElement();e.framesetOk&&I&&(e.treeAdapter.detachNode(I),e.openElements.popAllUpToHtmlElement(),e._insertElement(g,z.NS.HTML),e.insertionMode=We.IN_FRAMESET)}function EZt(e,g){e.openElements.hasInButtonScope(z.TAG_ID.P)&&e._closePElement(),e._insertElement(g,z.NS.HTML)}function MZt(e,g){e.openElements.hasInButtonScope(z.TAG_ID.P)&&e._closePElement(),(0,z.isNumberedHeader)(e.openElements.currentTagId)&&e.openElements.pop(),e._insertElement(g,z.NS.HTML)}function zZt(e,g){e.openElements.hasInButtonScope(z.TAG_ID.P)&&e._closePElement(),e._insertElement(g,z.NS.HTML),e.skipNextNewLine=!0,e.framesetOk=!1}function PZt(e,g){const I=e.openElements.tmplCount>0;(!e.formElement||I)&&(e.openElements.hasInButtonScope(z.TAG_ID.P)&&e._closePElement(),e._insertElement(g,z.NS.HTML),I||(e.formElement=e.openElements.current))}function JZt(e,g){e.framesetOk=!1;const I=g.tagID;for(let i=e.openElements.stackTop;i>=0;i--){const n=e.openElements.tagIDs[i];if(I===z.TAG_ID.LI&&n===z.TAG_ID.LI||(I===z.TAG_ID.DD||I===z.TAG_ID.DT)&&(n===z.TAG_ID.DD||n===z.TAG_ID.DT)){e.openElements.generateImpliedEndTagsWithExclusion(n),e.openElements.popUntilTagNamePopped(n);break}if(n!==z.TAG_ID.ADDRESS&&n!==z.TAG_ID.DIV&&n!==z.TAG_ID.P&&e._isSpecialElement(e.openElements.items[i],n))break}e.openElements.hasInButtonScope(z.TAG_ID.P)&&e._closePElement(),e._insertElement(g,z.NS.HTML)}function OZt(e,g){e.openElements.hasInButtonScope(z.TAG_ID.P)&&e._closePElement(),e._insertElement(g,z.NS.HTML),e.tokenizer.state=On.TokenizerMode.PLAINTEXT}function _Zt(e,g){e.openElements.hasInScope(z.TAG_ID.BUTTON)&&(e.openElements.generateImpliedEndTags(),e.openElements.popUntilTagNamePopped(z.TAG_ID.BUTTON)),e._reconstructActiveFormattingElements(),e._insertElement(g,z.NS.HTML),e.framesetOk=!1}function LZt(e,g){const I=e.activeFormattingElements.getElementEntryInScopeWithTagName(z.TAG_NAMES.A);I&&(xQ(e,g),e.openElements.remove(I.element),e.activeFormattingElements.removeEntry(I)),e._reconstructActiveFormattingElements(),e._insertElement(g,z.NS.HTML),e.activeFormattingElements.pushElement(e.openElements.current,g)}function UZt(e,g){e._reconstructActiveFormattingElements(),e._insertElement(g,z.NS.HTML),e.activeFormattingElements.pushElement(e.openElements.current,g)}function QZt(e,g){e._reconstructActiveFormattingElements(),e.openElements.hasInScope(z.TAG_ID.NOBR)&&(xQ(e,g),e._reconstructActiveFormattingElements()),e._insertElement(g,z.NS.HTML),e.activeFormattingElements.pushElement(e.openElements.current,g)}function jZt(e,g){e._reconstructActiveFormattingElements(),e._insertElement(g,z.NS.HTML),e.activeFormattingElements.insertMarker(),e.framesetOk=!1}function $Zt(e,g){e.treeAdapter.getDocumentMode(e.document)!==z.DOCUMENT_MODE.QUIRKS&&e.openElements.hasInButtonScope(z.TAG_ID.P)&&e._closePElement(),e._insertElement(g,z.NS.HTML),e.framesetOk=!1,e.insertionMode=We.IN_TABLE}function fSe(e,g){e._reconstructActiveFormattingElements(),e._appendElement(g,z.NS.HTML),e.framesetOk=!1,g.ackSelfClosing=!0}function pSe(e){const g=(0,vi.getTokenAttr)(e,z.ATTRS.TYPE);return g!=null&&g.toLowerCase()===dZt}function qZt(e,g){e._reconstructActiveFormattingElements(),e._appendElement(g,z.NS.HTML),pSe(g)||(e.framesetOk=!1),g.ackSelfClosing=!0}function eGt(e,g){e._appendElement(g,z.NS.HTML),g.ackSelfClosing=!0}function tGt(e,g){e.openElements.hasInButtonScope(z.TAG_ID.P)&&e._closePElement(),e._appendElement(g,z.NS.HTML),e.framesetOk=!1,g.ackSelfClosing=!0}function gGt(e,g){g.tagName=z.TAG_NAMES.IMG,g.tagID=z.TAG_ID.IMG,fSe(e,g)}function IGt(e,g){e._insertElement(g,z.NS.HTML),e.skipNextNewLine=!0,e.tokenizer.state=On.TokenizerMode.RCDATA,e.originalInsertionMode=e.insertionMode,e.framesetOk=!1,e.insertionMode=We.TEXT}function iGt(e,g){e.openElements.hasInButtonScope(z.TAG_ID.P)&&e._closePElement(),e._reconstructActiveFormattingElements(),e.framesetOk=!1,e._switchToTextParsing(g,On.TokenizerMode.RAWTEXT)}function nGt(e,g){e.framesetOk=!1,e._switchToTextParsing(g,On.TokenizerMode.RAWTEXT)}function wne(e,g){e._switchToTextParsing(g,On.TokenizerMode.RAWTEXT)}function CGt(e,g){e._reconstructActiveFormattingElements(),e._insertElement(g,z.NS.HTML),e.framesetOk=!1,e.insertionMode=e.insertionMode===We.IN_TABLE||e.insertionMode===We.IN_CAPTION||e.insertionMode===We.IN_TABLE_BODY||e.insertionMode===We.IN_ROW||e.insertionMode===We.IN_CELL?We.IN_SELECT_IN_TABLE:We.IN_SELECT}function rGt(e,g){e.openElements.currentTagId===z.TAG_ID.OPTION&&e.openElements.pop(),e._reconstructActiveFormattingElements(),e._insertElement(g,z.NS.HTML)}function oGt(e,g){e.openElements.hasInScope(z.TAG_ID.RUBY)&&e.openElements.generateImpliedEndTags(),e._insertElement(g,z.NS.HTML)}function AGt(e,g){e.openElements.hasInScope(z.TAG_ID.RUBY)&&e.openElements.generateImpliedEndTagsWithExclusion(z.TAG_ID.RTC),e._insertElement(g,z.NS.HTML)}function aGt(e,g){e._reconstructActiveFormattingElements(),EA.adjustTokenMathMLAttrs(g),EA.adjustTokenXMLAttrs(g),g.selfClosing?e._appendElement(g,z.NS.MATHML):e._insertElement(g,z.NS.MATHML),g.ackSelfClosing=!0}function sGt(e,g){e._reconstructActiveFormattingElements(),EA.adjustTokenSVGAttrs(g),EA.adjustTokenXMLAttrs(g),g.selfClosing?e._appendElement(g,z.NS.SVG):e._insertElement(g,z.NS.SVG),g.ackSelfClosing=!0}function Vne(e,g){e._reconstructActiveFormattingElements(),e._insertElement(g,z.NS.HTML)}function Dn(e,g){switch(g.tagID){case z.TAG_ID.I:case z.TAG_ID.S:case z.TAG_ID.B:case z.TAG_ID.U:case z.TAG_ID.EM:case z.TAG_ID.TT:case z.TAG_ID.BIG:case z.TAG_ID.CODE:case z.TAG_ID.FONT:case z.TAG_ID.SMALL:case z.TAG_ID.STRIKE:case z.TAG_ID.STRONG:{UZt(e,g);break}case z.TAG_ID.A:{LZt(e,g);break}case z.TAG_ID.H1:case z.TAG_ID.H2:case z.TAG_ID.H3:case z.TAG_ID.H4:case z.TAG_ID.H5:case z.TAG_ID.H6:{MZt(e,g);break}case z.TAG_ID.P:case z.TAG_ID.DL:case z.TAG_ID.OL:case z.TAG_ID.UL:case z.TAG_ID.DIV:case z.TAG_ID.DIR:case z.TAG_ID.NAV:case z.TAG_ID.MAIN:case z.TAG_ID.MENU:case z.TAG_ID.ASIDE:case z.TAG_ID.CENTER:case z.TAG_ID.FIGURE:case z.TAG_ID.FOOTER:case z.TAG_ID.HEADER:case z.TAG_ID.HGROUP:case z.TAG_ID.DIALOG:case z.TAG_ID.DETAILS:case z.TAG_ID.ADDRESS:case z.TAG_ID.ARTICLE:case z.TAG_ID.SECTION:case z.TAG_ID.SUMMARY:case z.TAG_ID.FIELDSET:case z.TAG_ID.BLOCKQUOTE:case z.TAG_ID.FIGCAPTION:{EZt(e,g);break}case z.TAG_ID.LI:case z.TAG_ID.DD:case z.TAG_ID.DT:{JZt(e,g);break}case z.TAG_ID.BR:case z.TAG_ID.IMG:case z.TAG_ID.WBR:case z.TAG_ID.AREA:case z.TAG_ID.EMBED:case z.TAG_ID.KEYGEN:{fSe(e,g);break}case z.TAG_ID.HR:{tGt(e,g);break}case z.TAG_ID.RB:case z.TAG_ID.RTC:{oGt(e,g);break}case z.TAG_ID.RT:case z.TAG_ID.RP:{AGt(e,g);break}case z.TAG_ID.PRE:case z.TAG_ID.LISTING:{zZt(e,g);break}case z.TAG_ID.XMP:{iGt(e,g);break}case z.TAG_ID.SVG:{sGt(e,g);break}case z.TAG_ID.HTML:{DZt(e,g);break}case z.TAG_ID.BASE:case z.TAG_ID.LINK:case z.TAG_ID.META:case z.TAG_ID.STYLE:case z.TAG_ID.TITLE:case z.TAG_ID.SCRIPT:case z.TAG_ID.BGSOUND:case z.TAG_ID.BASEFONT:case z.TAG_ID.TEMPLATE:{dA(e,g);break}case z.TAG_ID.BODY:{xZt(e,g);break}case z.TAG_ID.FORM:{PZt(e,g);break}case z.TAG_ID.NOBR:{QZt(e,g);break}case z.TAG_ID.MATH:{aGt(e,g);break}case z.TAG_ID.TABLE:{$Zt(e,g);break}case z.TAG_ID.INPUT:{qZt(e,g);break}case z.TAG_ID.PARAM:case z.TAG_ID.TRACK:case z.TAG_ID.SOURCE:{eGt(e,g);break}case z.TAG_ID.IMAGE:{gGt(e,g);break}case z.TAG_ID.BUTTON:{_Zt(e,g);break}case z.TAG_ID.APPLET:case z.TAG_ID.OBJECT:case z.TAG_ID.MARQUEE:{jZt(e,g);break}case z.TAG_ID.IFRAME:{nGt(e,g);break}case z.TAG_ID.SELECT:{CGt(e,g);break}case z.TAG_ID.OPTION:case z.TAG_ID.OPTGROUP:{rGt(e,g);break}case z.TAG_ID.NOEMBED:{wne(e,g);break}case z.TAG_ID.FRAMESET:{FZt(e,g);break}case z.TAG_ID.TEXTAREA:{IGt(e,g);break}case z.TAG_ID.NOSCRIPT:{e.options.scriptingEnabled?wne(e,g):Vne(e,g);break}case z.TAG_ID.PLAINTEXT:{OZt(e,g);break}case z.TAG_ID.COL:case z.TAG_ID.TH:case z.TAG_ID.TD:case z.TAG_ID.TR:case z.TAG_ID.HEAD:case z.TAG_ID.FRAME:case z.TAG_ID.TBODY:case z.TAG_ID.TFOOT:case z.TAG_ID.THEAD:case z.TAG_ID.CAPTION:case z.TAG_ID.COLGROUP:break;default:Vne(e,g)}}function lGt(e,g){if(e.openElements.hasInScope(z.TAG_ID.BODY)&&(e.insertionMode=We.AFTER_BODY,e.options.sourceCodeLocationInfo)){const I=e.openElements.tryPeekProperlyNestedBodyElement();I&&e._setEndLocation(I,g)}}function cGt(e,g){e.openElements.hasInScope(z.TAG_ID.BODY)&&(e.insertionMode=We.AFTER_BODY,RSe(e,g))}function uGt(e,g){const I=g.tagID;e.openElements.hasInScope(I)&&(e.openElements.generateImpliedEndTags(),e.openElements.popUntilTagNamePopped(I))}function dGt(e){const g=e.openElements.tmplCount>0,{formElement:I}=e;g||(e.formElement=null),(I||g)&&e.openElements.hasInScope(z.TAG_ID.FORM)&&(e.openElements.generateImpliedEndTags(),g?e.openElements.popUntilTagNamePopped(z.TAG_ID.FORM):I&&e.openElements.remove(I))}function hGt(e){e.openElements.hasInButtonScope(z.TAG_ID.P)||e._insertFakeElement(z.TAG_NAMES.P,z.TAG_ID.P),e._closePElement()}function mGt(e){e.openElements.hasInListItemScope(z.TAG_ID.LI)&&(e.openElements.generateImpliedEndTagsWithExclusion(z.TAG_ID.LI),e.openElements.popUntilTagNamePopped(z.TAG_ID.LI))}function fGt(e,g){const I=g.tagID;e.openElements.hasInScope(I)&&(e.openElements.generateImpliedEndTagsWithExclusion(I),e.openElements.popUntilTagNamePopped(I))}function pGt(e){e.openElements.hasNumberedHeaderInScope()&&(e.openElements.generateImpliedEndTags(),e.openElements.popUntilNumberedHeaderPopped())}function bGt(e,g){const I=g.tagID;e.openElements.hasInScope(I)&&(e.openElements.generateImpliedEndTags(),e.openElements.popUntilTagNamePopped(I),e.activeFormattingElements.clearToLastMarker())}function yGt(e){e._reconstructActiveFormattingElements(),e._insertFakeElement(z.TAG_NAMES.BR,z.TAG_ID.BR),e.openElements.pop(),e.framesetOk=!1}function bSe(e,g){const I=g.tagName,i=g.tagID;for(let n=e.openElements.stackTop;n>0;n--){const C=e.openElements.items[n],r=e.openElements.tagIDs[n];if(i===r&&(i!==z.TAG_ID.UNKNOWN||e.treeAdapter.getTagName(C)===I)){e.openElements.generateImpliedEndTagsWithExclusion(i),e.openElements.stackTop>=n&&e.openElements.shortenToLength(n);break}if(e._isSpecialElement(C,r))break}}function zN(e,g){switch(g.tagID){case z.TAG_ID.A:case z.TAG_ID.B:case z.TAG_ID.I:case z.TAG_ID.S:case z.TAG_ID.U:case z.TAG_ID.EM:case z.TAG_ID.TT:case z.TAG_ID.BIG:case z.TAG_ID.CODE:case z.TAG_ID.FONT:case z.TAG_ID.NOBR:case z.TAG_ID.SMALL:case z.TAG_ID.STRIKE:case z.TAG_ID.STRONG:{xQ(e,g);break}case z.TAG_ID.P:{hGt(e);break}case z.TAG_ID.DL:case z.TAG_ID.UL:case z.TAG_ID.OL:case z.TAG_ID.DIR:case z.TAG_ID.DIV:case z.TAG_ID.NAV:case z.TAG_ID.PRE:case z.TAG_ID.MAIN:case z.TAG_ID.MENU:case z.TAG_ID.ASIDE:case z.TAG_ID.BUTTON:case z.TAG_ID.CENTER:case z.TAG_ID.FIGURE:case z.TAG_ID.FOOTER:case z.TAG_ID.HEADER:case z.TAG_ID.HGROUP:case z.TAG_ID.DIALOG:case z.TAG_ID.ADDRESS:case z.TAG_ID.ARTICLE:case z.TAG_ID.DETAILS:case z.TAG_ID.SECTION:case z.TAG_ID.SUMMARY:case z.TAG_ID.LISTING:case z.TAG_ID.FIELDSET:case z.TAG_ID.BLOCKQUOTE:case z.TAG_ID.FIGCAPTION:{uGt(e,g);break}case z.TAG_ID.LI:{mGt(e);break}case z.TAG_ID.DD:case z.TAG_ID.DT:{fGt(e,g);break}case z.TAG_ID.H1:case z.TAG_ID.H2:case z.TAG_ID.H3:case z.TAG_ID.H4:case z.TAG_ID.H5:case z.TAG_ID.H6:{pGt(e);break}case z.TAG_ID.BR:{yGt(e);break}case z.TAG_ID.BODY:{lGt(e,g);break}case z.TAG_ID.HTML:{cGt(e,g);break}case z.TAG_ID.FORM:{dGt(e);break}case z.TAG_ID.APPLET:case z.TAG_ID.OBJECT:case z.TAG_ID.MARQUEE:{bGt(e,g);break}case z.TAG_ID.TEMPLATE:{tm(e,g);break}default:bSe(e,g)}}function ySe(e,g){e.tmplInsertionModeStack.length>0?VSe(e,g):FQ(e,g)}function ZGt(e,g){var I;g.tagID===z.TAG_ID.SCRIPT&&((I=e.scriptHandler)===null||I===void 0||I.call(e,e.openElements.current)),e.openElements.pop(),e.insertionMode=e.originalInsertionMode}function GGt(e,g){e._err(g,cn.ERR.eofInElementThatCanContainOnlyText),e.openElements.pop(),e.insertionMode=e.originalInsertionMode,e.onEof(g)}function MD(e,g){if(dSe.has(e.openElements.currentTagId))switch(e.pendingCharacterTokens.length=0,e.hasNonWhitespacePendingCharacterToken=!1,e.originalInsertionMode=e.insertionMode,e.insertionMode=We.IN_TABLE_TEXT,g.type){case vi.TokenType.CHARACTER:{GSe(e,g);break}case vi.TokenType.WHITESPACE_CHARACTER:{ZSe(e,g);break}}else JS(e,g)}function vGt(e,g){e.openElements.clearBackToTableContext(),e.activeFormattingElements.insertMarker(),e._insertElement(g,z.NS.HTML),e.insertionMode=We.IN_CAPTION}function BGt(e,g){e.openElements.clearBackToTableContext(),e._insertElement(g,z.NS.HTML),e.insertionMode=We.IN_COLUMN_GROUP}function SGt(e,g){e.openElements.clearBackToTableContext(),e._insertFakeElement(z.TAG_NAMES.COLGROUP,z.TAG_ID.COLGROUP),e.insertionMode=We.IN_COLUMN_GROUP,EQ(e,g)}function wGt(e,g){e.openElements.clearBackToTableContext(),e._insertElement(g,z.NS.HTML),e.insertionMode=We.IN_TABLE_BODY}function VGt(e,g){e.openElements.clearBackToTableContext(),e._insertFakeElement(z.TAG_NAMES.TBODY,z.TAG_ID.TBODY),e.insertionMode=We.IN_TABLE_BODY,PN(e,g)}function RGt(e,g){e.openElements.hasInTableScope(z.TAG_ID.TABLE)&&(e.openElements.popUntilTagNamePopped(z.TAG_ID.TABLE),e._resetInsertionMode(),e._processStartTag(g))}function WGt(e,g){pSe(g)?e._appendElement(g,z.NS.HTML):JS(e,g),g.ackSelfClosing=!0}function XGt(e,g){!e.formElement&&e.openElements.tmplCount===0&&(e._insertElement(g,z.NS.HTML),e.formElement=e.openElements.current,e.openElements.pop())}function xb(e,g){switch(g.tagID){case z.TAG_ID.TD:case z.TAG_ID.TH:case z.TAG_ID.TR:{VGt(e,g);break}case z.TAG_ID.STYLE:case z.TAG_ID.SCRIPT:case z.TAG_ID.TEMPLATE:{dA(e,g);break}case z.TAG_ID.COL:{SGt(e,g);break}case z.TAG_ID.FORM:{XGt(e,g);break}case z.TAG_ID.TABLE:{RGt(e,g);break}case z.TAG_ID.TBODY:case z.TAG_ID.TFOOT:case z.TAG_ID.THEAD:{wGt(e,g);break}case z.TAG_ID.INPUT:{WGt(e,g);break}case z.TAG_ID.CAPTION:{vGt(e,g);break}case z.TAG_ID.COLGROUP:{BGt(e,g);break}default:JS(e,g)}}function vB(e,g){switch(g.tagID){case z.TAG_ID.TABLE:{e.openElements.hasInTableScope(z.TAG_ID.TABLE)&&(e.openElements.popUntilTagNamePopped(z.TAG_ID.TABLE),e._resetInsertionMode());break}case z.TAG_ID.TEMPLATE:{tm(e,g);break}case z.TAG_ID.BODY:case z.TAG_ID.CAPTION:case z.TAG_ID.COL:case z.TAG_ID.COLGROUP:case z.TAG_ID.HTML:case z.TAG_ID.TBODY:case z.TAG_ID.TD:case z.TAG_ID.TFOOT:case z.TAG_ID.TH:case z.TAG_ID.THEAD:case z.TAG_ID.TR:break;default:JS(e,g)}}function JS(e,g){const I=e.fosterParentingEnabled;e.fosterParentingEnabled=!0,MN(e,g),e.fosterParentingEnabled=I}function ZSe(e,g){e.pendingCharacterTokens.push(g)}function GSe(e,g){e.pendingCharacterTokens.push(g),e.hasNonWhitespacePendingCharacterToken=!0}function Qy(e,g){let I=0;if(e.hasNonWhitespacePendingCharacterToken)for(;I0&&e.openElements.currentTagId===z.TAG_ID.OPTION&&e.openElements.tagIDs[e.openElements.stackTop-1]===z.TAG_ID.OPTGROUP&&e.openElements.pop(),e.openElements.currentTagId===z.TAG_ID.OPTGROUP&&e.openElements.pop();break}case z.TAG_ID.OPTION:{e.openElements.currentTagId===z.TAG_ID.OPTION&&e.openElements.pop();break}case z.TAG_ID.SELECT:{e.openElements.hasInSelectScope(z.TAG_ID.SELECT)&&(e.openElements.popUntilTagNamePopped(z.TAG_ID.SELECT),e._resetInsertionMode());break}case z.TAG_ID.TEMPLATE:{tm(e,g);break}}}function KGt(e,g){const I=g.tagID;I===z.TAG_ID.CAPTION||I===z.TAG_ID.TABLE||I===z.TAG_ID.TBODY||I===z.TAG_ID.TFOOT||I===z.TAG_ID.THEAD||I===z.TAG_ID.TR||I===z.TAG_ID.TD||I===z.TAG_ID.TH?(e.openElements.popUntilTagNamePopped(z.TAG_ID.SELECT),e._resetInsertionMode(),e._processStartTag(g)):SSe(e,g)}function DGt(e,g){const I=g.tagID;I===z.TAG_ID.CAPTION||I===z.TAG_ID.TABLE||I===z.TAG_ID.TBODY||I===z.TAG_ID.TFOOT||I===z.TAG_ID.THEAD||I===z.TAG_ID.TR||I===z.TAG_ID.TD||I===z.TAG_ID.TH?e.openElements.hasInTableScope(I)&&(e.openElements.popUntilTagNamePopped(z.TAG_ID.SELECT),e._resetInsertionMode(),e.onEndTag(g)):wSe(e,g)}function xGt(e,g){switch(g.tagID){case z.TAG_ID.BASE:case z.TAG_ID.BASEFONT:case z.TAG_ID.BGSOUND:case z.TAG_ID.LINK:case z.TAG_ID.META:case z.TAG_ID.NOFRAMES:case z.TAG_ID.SCRIPT:case z.TAG_ID.STYLE:case z.TAG_ID.TEMPLATE:case z.TAG_ID.TITLE:{dA(e,g);break}case z.TAG_ID.CAPTION:case z.TAG_ID.COLGROUP:case z.TAG_ID.TBODY:case z.TAG_ID.TFOOT:case z.TAG_ID.THEAD:{e.tmplInsertionModeStack[0]=We.IN_TABLE,e.insertionMode=We.IN_TABLE,xb(e,g);break}case z.TAG_ID.COL:{e.tmplInsertionModeStack[0]=We.IN_COLUMN_GROUP,e.insertionMode=We.IN_COLUMN_GROUP,EQ(e,g);break}case z.TAG_ID.TR:{e.tmplInsertionModeStack[0]=We.IN_TABLE_BODY,e.insertionMode=We.IN_TABLE_BODY,PN(e,g);break}case z.TAG_ID.TD:case z.TAG_ID.TH:{e.tmplInsertionModeStack[0]=We.IN_ROW,e.insertionMode=We.IN_ROW,JN(e,g);break}default:e.tmplInsertionModeStack[0]=We.IN_BODY,e.insertionMode=We.IN_BODY,Dn(e,g)}}function FGt(e,g){g.tagID===z.TAG_ID.TEMPLATE&&tm(e,g)}function VSe(e,g){e.openElements.tmplCount>0?(e.openElements.popUntilTagNamePopped(z.TAG_ID.TEMPLATE),e.activeFormattingElements.clearToLastMarker(),e.tmplInsertionModeStack.shift(),e._resetInsertionMode(),e.onEof(g)):FQ(e,g)}function EGt(e,g){g.tagID===z.TAG_ID.HTML?Dn(e,g):b9(e,g)}function RSe(e,g){var I;if(g.tagID===z.TAG_ID.HTML){if(e.fragmentContext||(e.insertionMode=We.AFTER_AFTER_BODY),e.options.sourceCodeLocationInfo&&e.openElements.tagIDs[0]===z.TAG_ID.HTML){e._setEndLocation(e.openElements.items[0],g);const i=e.openElements.items[1];i&&!(!((I=e.treeAdapter.getNodeSourceCodeLocation(i))===null||I===void 0)&&I.endTag)&&e._setEndLocation(i,g)}}else b9(e,g)}function b9(e,g){e.insertionMode=We.IN_BODY,MN(e,g)}function MGt(e,g){switch(g.tagID){case z.TAG_ID.HTML:{Dn(e,g);break}case z.TAG_ID.FRAMESET:{e._insertElement(g,z.NS.HTML);break}case z.TAG_ID.FRAME:{e._appendElement(g,z.NS.HTML),g.ackSelfClosing=!0;break}case z.TAG_ID.NOFRAMES:{dA(e,g);break}}}function zGt(e,g){g.tagID===z.TAG_ID.FRAMESET&&!e.openElements.isRootHtmlElementCurrent()&&(e.openElements.pop(),!e.fragmentContext&&e.openElements.currentTagId!==z.TAG_ID.FRAMESET&&(e.insertionMode=We.AFTER_FRAMESET))}function PGt(e,g){switch(g.tagID){case z.TAG_ID.HTML:{Dn(e,g);break}case z.TAG_ID.NOFRAMES:{dA(e,g);break}}}function JGt(e,g){g.tagID===z.TAG_ID.HTML&&(e.insertionMode=We.AFTER_AFTER_FRAMESET)}function OGt(e,g){g.tagID===z.TAG_ID.HTML?Dn(e,g):H1(e,g)}function H1(e,g){e.insertionMode=We.IN_BODY,MN(e,g)}function _Gt(e,g){switch(g.tagID){case z.TAG_ID.HTML:{Dn(e,g);break}case z.TAG_ID.NOFRAMES:{dA(e,g);break}}}function LGt(e,g){g.chars=uSe.REPLACEMENT_CHARACTER,e._insertCharacters(g)}function UGt(e,g){e._insertCharacters(g),e.framesetOk=!1}function WSe(e){for(;e.treeAdapter.getNamespaceURI(e.openElements.current)!==z.NS.HTML&&!e._isIntegrationPoint(e.openElements.currentTagId,e.openElements.current);)e.openElements.pop()}function QGt(e,g){if(EA.causesExit(g))WSe(e),e._startTagOutsideForeignContent(g);else{const I=e._getAdjustedCurrentElement(),i=e.treeAdapter.getNamespaceURI(I);i===z.NS.MATHML?EA.adjustTokenMathMLAttrs(g):i===z.NS.SVG&&(EA.adjustTokenSVGTagName(g),EA.adjustTokenSVGAttrs(g)),EA.adjustTokenXMLAttrs(g),g.selfClosing?e._appendElement(g,i):e._insertElement(g,i),g.ackSelfClosing=!0}}function jGt(e,g){if(g.tagID===z.TAG_ID.P||g.tagID===z.TAG_ID.BR){WSe(e),e._endTagOutsideForeignContent(g);return}for(let I=e.openElements.stackTop;I>0;I--){const i=e.openElements.items[I];if(e.treeAdapter.getNamespaceURI(i)===z.NS.HTML){e._endTagOutsideForeignContent(g);break}const n=e.treeAdapter.getTagName(i);if(n.toLowerCase()===g.tagName){g.tagName=n,e.openElements.shortenToLength(I);break}}}var Fb={};Object.defineProperty(Fb,"__esModule",{value:!0});Fb.serializeOuter=Fb.serialize=void 0;const iI=qs,XSe=wb,$Gt=EN,qGt=new Set([iI.TAG_NAMES.AREA,iI.TAG_NAMES.BASE,iI.TAG_NAMES.BASEFONT,iI.TAG_NAMES.BGSOUND,iI.TAG_NAMES.BR,iI.TAG_NAMES.COL,iI.TAG_NAMES.EMBED,iI.TAG_NAMES.FRAME,iI.TAG_NAMES.HR,iI.TAG_NAMES.IMG,iI.TAG_NAMES.INPUT,iI.TAG_NAMES.KEYGEN,iI.TAG_NAMES.LINK,iI.TAG_NAMES.META,iI.TAG_NAMES.PARAM,iI.TAG_NAMES.SOURCE,iI.TAG_NAMES.TRACK,iI.TAG_NAMES.WBR]);function HSe(e,g){return g.treeAdapter.isElementNode(e)&&g.treeAdapter.getNamespaceURI(e)===iI.NS.HTML&&qGt.has(g.treeAdapter.getTagName(e))}const TSe={treeAdapter:$Gt.defaultTreeAdapter,scriptingEnabled:!0};function evt(e,g){const I=Object.assign(Object.assign({},TSe),g);return HSe(e,I)?"":NSe(e,I)}Fb.serialize=evt;function tvt(e,g){const I=Object.assign(Object.assign({},TSe),g);return kSe(e,I)}Fb.serializeOuter=tvt;function NSe(e,g){let I="";const i=g.treeAdapter.isElementNode(e)&&g.treeAdapter.getTagName(e)===iI.TAG_NAMES.TEMPLATE&&g.treeAdapter.getNamespaceURI(e)===iI.NS.HTML?g.treeAdapter.getTemplateContent(e):e,n=g.treeAdapter.getChildNodes(i);if(n)for(const C of n)I+=kSe(C,g);return I}function kSe(e,g){return g.treeAdapter.isElementNode(e)?gvt(e,g):g.treeAdapter.isTextNode(e)?ivt(e,g):g.treeAdapter.isCommentNode(e)?nvt(e,g):g.treeAdapter.isDocumentTypeNode(e)?Cvt(e,g):""}function gvt(e,g){const I=g.treeAdapter.getTagName(e);return`<${I}${Ivt(e,g)}>${HSe(e,g)?"":`${NSe(e,g)}`}`}function Ivt(e,{treeAdapter:g}){let I="";for(const i of g.getAttrList(e)){if(I+=" ",!i.namespace)I+=i.name;else switch(i.namespace){case iI.NS.XML:{I+=`xml:${i.name}`;break}case iI.NS.XMLNS:{i.name!=="xmlns"&&(I+="xmlns:"),I+=i.name;break}case iI.NS.XLINK:{I+=`xlink:${i.name}`;break}default:I+=`${i.prefix}:${i.name}`}I+=`="${(0,XSe.escapeAttribute)(i.value)}"`}return I}function ivt(e,g){const{treeAdapter:I}=g,i=I.getTextNodeContent(e),n=I.getParentNode(e),C=n&&I.isElementNode(n)&&I.getTagName(n);return C&&I.getNamespaceURI(n)===iI.NS.HTML&&(0,iI.hasUnescapedText)(C,g.scriptingEnabled)?i:(0,XSe.escapeText)(i)}function nvt(e,{treeAdapter:g}){return``}function Cvt(e,{treeAdapter:g}){return``}(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.parseFragment=e.parse=e.TokenizerMode=e.Tokenizer=e.Token=e.html=e.foreignContent=e.ErrorCodes=e.serializeOuter=e.serialize=e.Parser=e.defaultTreeAdapter=void 0;const g=GB;var I=EN;Object.defineProperty(e,"defaultTreeAdapter",{enumerable:!0,get:function(){return I.defaultTreeAdapter}});var i=GB;Object.defineProperty(e,"Parser",{enumerable:!0,get:function(){return i.Parser}});var n=Fb;Object.defineProperty(e,"serialize",{enumerable:!0,get:function(){return n.serialize}}),Object.defineProperty(e,"serializeOuter",{enumerable:!0,get:function(){return n.serializeOuter}});var C=PS;Object.defineProperty(e,"ErrorCodes",{enumerable:!0,get:function(){return C.ERR}}),e.foreignContent=DQ,e.html=qs,e.Token=xN;var r=nh;Object.defineProperty(e,"Tokenizer",{enumerable:!0,get:function(){return r.Tokenizer}}),Object.defineProperty(e,"TokenizerMode",{enumerable:!0,get:function(){return r.TokenizerMode}});function o(s,a){return g.Parser.parse(s,a)}e.parse=o;function A(s,a,l){typeof s=="string"&&(l=a,a=s,s=null);const c=g.Parser.getFragmentParser(s,l);return c.tokenizer.write(a,!0),c.getFragment()}e.parseFragment=A})(nSe);(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.adapter=e.serializeDoctypeContent=void 0;const g=nSe,I=kn;function i(r){return new I.Text(r)}function n(r){const o=r.includes('"')?"'":'"';return o+r+o}function C(r,o,A){let s="!DOCTYPE ";return r&&(s+=r),o?s+=` PUBLIC ${n(o)}`:A&&(s+=" SYSTEM"),A&&(s+=` ${n(A)}`),s}e.serializeDoctypeContent=C,e.adapter={isCommentNode:I.isComment,isElementNode:I.isTag,isTextNode:I.isText,createDocument(){const r=new I.Document([]);return r["x-mode"]=g.html.DOCUMENT_MODE.NO_QUIRKS,r},createDocumentFragment(){return new I.Document([])},createElement(r,o,A){const s=Object.create(null),a=Object.create(null),l=Object.create(null);for(let u=0;u(0,I.isDirective)(c)&&c.name==="!doctype");l?l.data=a??null:(l=new I.ProcessingInstruction("!doctype",a),e.adapter.appendChild(r,l)),l["x-name"]=o??void 0,l["x-publicId"]=A??void 0,l["x-systemId"]=s??void 0},setDocumentMode(r,o){r["x-mode"]=o},getDocumentMode(r){return r["x-mode"]},detachNode(r){if(r.parent){const o=r.parent.children.indexOf(r),{prev:A,next:s}=r;r.prev=null,r.next=null,A&&(A.next=s),s&&(s.prev=A),r.parent.children.splice(o,1),r.parent=null}},insertText(r,o){const A=r.children[r.children.length-1];A&&(0,I.isText)(A)?A.data+=o:e.adapter.appendChild(r,i(o))},insertTextBefore(r,o,A){const s=r.children[r.children.indexOf(A)-1];s&&(0,I.isText)(s)?s.data+=o:e.adapter.insertBefore(r,i(o),A)},adoptAttributes(r,o){for(let A=0;A"u"&&(r.attribs[s]=o[A].value,r["x-attribsNamespace"][s]=o[A].namespace,r["x-attribsPrefix"][s]=o[A].prefix)}},getFirstChild(r){return r.children[0]},getChildNodes(r){return r.children},getParentNode(r){return r.parent},getAttrList(r){return r.attributes},getTagName(r){return r.name},getNamespaceURI(r){return r.namespace},getTextNodeContent(r){return r.data},getCommentNodeContent(r){return r.data},getDocumentTypeNodeName(r){var o;return(o=r["x-name"])!==null&&o!==void 0?o:""},getDocumentTypeNodePublicId(r){var o;return(o=r["x-publicId"])!==null&&o!==void 0?o:""},getDocumentTypeNodeSystemId(r){var o;return(o=r["x-systemId"])!==null&&o!==void 0?o:""},isDocumentTypeNode(r){return(0,I.isDirective)(r)&&r.name==="!doctype"},setNodeSourceCodeLocation(r,o){o&&(r.startIndex=o.startOffset,r.endIndex=o.endOffset),r.sourceCodeLocation=o},getNodeSourceCodeLocation(r){return r.sourceCodeLocation},updateNodeSourceCodeLocation(r,o){o.endOffset!=null&&(r.endIndex=o.endOffset),r.sourceCodeLocation=Object.assign(Object.assign({},r.sourceCodeLocation),o)}}})(iSe);var rvt=Le&&Le.__spreadArray||function(e,g,I){if(I||arguments.length===2)for(var i=0,n=g.length,C;i=I.Zero&&c<=I.Nine}function o(c){return c>=I.LowerA&&c<=I.LowerZ||c>=I.UpperA&&c<=I.UpperZ}function A(c){return c>=I.UpperA&&c<=I.UpperF||c>=I.LowerA&&c<=I.LowerF}var s;(function(c){c[c.NoValue=0]="NoValue",c[c.Unquoted=1]="Unquoted",c[c.Single=2]="Single",c[c.Double=3]="Double"})(s=e.QuoteType||(e.QuoteType={}));var a={Cdata:new Uint8Array([67,68,65,84,65,91]),CdataEnd:new Uint8Array([93,93,62]),CommentEnd:new Uint8Array([45,45,62]),ScriptEnd:new Uint8Array([60,47,115,99,114,105,112,116]),StyleEnd:new Uint8Array([60,47,115,116,121,108,101]),TitleEnd:new Uint8Array([60,47,116,105,116,108,101])},l=function(){function c(u,d){var h=u.xmlMode,m=h===void 0?!1:h,f=u.decodeEntities,b=f===void 0?!0:f;this.cbs=d,this.state=i.Text,this.buffer="",this.sectionStart=0,this.index=0,this.baseState=i.Text,this.isSpecial=!1,this.running=!0,this.offset=0,this.currentSequence=void 0,this.sequenceIndex=0,this.trieIndex=0,this.trieCurrent=0,this.entityResult=0,this.entityExcess=0,this.xmlMode=m,this.decodeEntities=b,this.entityTrie=m?g.xmlDecodeTree:g.htmlDecodeTree}return c.prototype.reset=function(){this.state=i.Text,this.buffer="",this.sectionStart=0,this.index=0,this.baseState=i.Text,this.currentSequence=void 0,this.running=!0,this.offset=0},c.prototype.write=function(u){this.offset+=this.buffer.length,this.buffer=u,this.parse()},c.prototype.end=function(){this.running&&this.finish()},c.prototype.pause=function(){this.running=!1},c.prototype.resume=function(){this.running=!0,this.indexthis.sectionStart&&this.cbs.ontext(this.sectionStart,this.index),this.state=i.BeforeTagName,this.sectionStart=this.index):this.decodeEntities&&u===I.Amp&&(this.state=i.BeforeEntity)},c.prototype.stateSpecialStartSequence=function(u){var d=this.sequenceIndex===this.currentSequence.length,h=d?C(u):(u|32)===this.currentSequence[this.sequenceIndex];if(!h)this.isSpecial=!1;else if(!d){this.sequenceIndex++;return}this.sequenceIndex=0,this.state=i.InTagName,this.stateInTagName(u)},c.prototype.stateInSpecialTag=function(u){if(this.sequenceIndex===this.currentSequence.length){if(u===I.Gt||n(u)){var d=this.index-this.currentSequence.length;if(this.sectionStart>14)-1;if(!this.allowLegacyEntity()&&u!==I.Semi)this.trieIndex+=h;else{var m=this.index-this.entityExcess+1;m>this.sectionStart&&this.emitPartial(this.sectionStart,m),this.entityResult=this.trieIndex,this.trieIndex+=h,this.entityExcess=0,this.sectionStart=this.index+1,h===0&&this.emitNamedEntity()}}},c.prototype.emitNamedEntity=function(){if(this.state=this.baseState,this.entityResult!==0){var u=(this.entityTrie[this.entityResult]&g.BinTrieFlags.VALUE_LENGTH)>>14;switch(u){case 1:{this.emitCodePoint(this.entityTrie[this.entityResult]&~g.BinTrieFlags.VALUE_LENGTH);break}case 2:{this.emitCodePoint(this.entityTrie[this.entityResult+1]);break}case 3:this.emitCodePoint(this.entityTrie[this.entityResult+1]),this.emitCodePoint(this.entityTrie[this.entityResult+2])}}},c.prototype.stateBeforeNumericEntity=function(u){(u|32)===I.LowerX?(this.entityExcess++,this.state=i.InHexEntity):(this.state=i.InNumericEntity,this.stateInNumericEntity(u))},c.prototype.emitNumericEntity=function(u){var d=this.index-this.entityExcess-1,h=d+2+ +(this.state===i.InHexEntity);h!==this.index&&(d>this.sectionStart&&this.emitPartial(this.sectionStart,d),this.sectionStart=this.index+Number(u),this.emitCodePoint((0,g.replaceCodePoint)(this.entityResult))),this.state=this.baseState},c.prototype.stateInNumericEntity=function(u){u===I.Semi?this.emitNumericEntity(!0):r(u)?(this.entityResult=this.entityResult*10+(u-I.Zero),this.entityExcess++):(this.allowLegacyEntity()?this.emitNumericEntity(!1):this.state=this.baseState,this.index--)},c.prototype.stateInHexEntity=function(u){u===I.Semi?this.emitNumericEntity(!0):r(u)?(this.entityResult=this.entityResult*16+(u-I.Zero),this.entityExcess++):A(u)?(this.entityResult=this.entityResult*16+((u|32)-I.LowerA+10),this.entityExcess++):(this.allowLegacyEntity()?this.emitNumericEntity(!1):this.state=this.baseState,this.index--)},c.prototype.allowLegacyEntity=function(){return!this.xmlMode&&(this.baseState===i.Text||this.baseState===i.InSpecialTag)},c.prototype.cleanup=function(){this.running&&this.sectionStart!==this.index&&(this.state===i.Text||this.state===i.InSpecialTag&&this.sequenceIndex===0?(this.cbs.ontext(this.sectionStart,this.index),this.sectionStart=this.index):(this.state===i.InAttributeValueDq||this.state===i.InAttributeValueSq||this.state===i.InAttributeValueNq)&&(this.cbs.onattribdata(this.sectionStart,this.index),this.sectionStart=this.index))},c.prototype.shouldContinue=function(){return this.index0&&r.has(this.stack[this.stack.length-1]);){var o=this.stack.pop();(i=(I=this.cbs).onclosetag)===null||i===void 0||i.call(I,o,!0)}this.isVoidElement(g)||(this.stack.push(g),Tne.has(g)?this.foreignContext.push(!0):Nne.has(g)&&this.foreignContext.push(!1)),(C=(n=this.cbs).onopentagname)===null||C===void 0||C.call(n,g),this.cbs.onopentag&&(this.attribs={})},e.prototype.endOpenTag=function(g){var I,i;this.startIndex=this.openTagStart,this.attribs&&((i=(I=this.cbs).onopentag)===null||i===void 0||i.call(I,this.tagname,this.attribs,g),this.attribs=null),this.cbs.onclosetag&&this.isVoidElement(this.tagname)&&this.cbs.onclosetag(this.tagname,!0),this.tagname=""},e.prototype.onopentagend=function(g){this.endIndex=g,this.endOpenTag(!1),this.startIndex=g+1},e.prototype.onclosetag=function(g,I){var i,n,C,r,o,A;this.endIndex=I;var s=this.getSlice(g,I);if(this.lowerCaseTagNames&&(s=s.toLowerCase()),(Tne.has(s)||Nne.has(s))&&this.foreignContext.pop(),this.isVoidElement(s))!this.options.xmlMode&&s==="br"&&((n=(i=this.cbs).onopentagname)===null||n===void 0||n.call(i,"br"),(r=(C=this.cbs).onopentag)===null||r===void 0||r.call(C,"br",{},!0),(A=(o=this.cbs).onclosetag)===null||A===void 0||A.call(o,"br",!1));else{var a=this.stack.lastIndexOf(s);if(a!==-1)if(this.cbs.onclosetag)for(var l=this.stack.length-a;l--;)this.cbs.onclosetag(this.stack.pop(),l!==0);else this.stack.length=a;else!this.options.xmlMode&&s==="p"&&(this.emitOpenTag("p"),this.closeCurrentTag(!0))}this.startIndex=I+1},e.prototype.onselfclosingtag=function(g){this.endIndex=g,this.options.xmlMode||this.options.recognizeSelfClosing||this.foreignContext[this.foreignContext.length-1]?(this.closeCurrentTag(!1),this.startIndex=g+1):this.onopentagend(g)},e.prototype.closeCurrentTag=function(g){var I,i,n=this.tagname;this.endOpenTag(g),this.stack[this.stack.length-1]===n&&((i=(I=this.cbs).onclosetag)===null||i===void 0||i.call(I,n,!g),this.stack.pop())},e.prototype.onattribname=function(g,I){this.startIndex=g;var i=this.getSlice(g,I);this.attribname=this.lowerCaseAttributeNames?i.toLowerCase():i},e.prototype.onattribdata=function(g,I){this.attribvalue+=this.getSlice(g,I)},e.prototype.onattribentity=function(g){this.attribvalue+=(0,Rne.fromCodePoint)(g)},e.prototype.onattribend=function(g,I){var i,n;this.endIndex=I,(n=(i=this.cbs).onattribute)===null||n===void 0||n.call(i,this.attribname,this.attribvalue,g===qV.QuoteType.Double?'"':g===qV.QuoteType.Single?"'":g===qV.QuoteType.NoValue?void 0:null),this.attribs&&!Object.prototype.hasOwnProperty.call(this.attribs,this.attribname)&&(this.attribs[this.attribname]=this.attribvalue),this.attribvalue=""},e.prototype.getInstructionName=function(g){var I=g.search(mvt),i=I<0?g:g.substr(0,I);return this.lowerCaseTagNames&&(i=i.toLowerCase()),i},e.prototype.ondeclaration=function(g,I){this.endIndex=I;var i=this.getSlice(g,I);if(this.cbs.onprocessinginstruction){var n=this.getInstructionName(i);this.cbs.onprocessinginstruction("!".concat(n),"!".concat(i))}this.startIndex=I+1},e.prototype.onprocessinginstruction=function(g,I){this.endIndex=I;var i=this.getSlice(g,I);if(this.cbs.onprocessinginstruction){var n=this.getInstructionName(i);this.cbs.onprocessinginstruction("?".concat(n),"?".concat(i))}this.startIndex=I+1},e.prototype.oncomment=function(g,I,i){var n,C,r,o;this.endIndex=I,(C=(n=this.cbs).oncomment)===null||C===void 0||C.call(n,this.getSlice(g,I-i)),(o=(r=this.cbs).oncommentend)===null||o===void 0||o.call(r),this.startIndex=I+1},e.prototype.oncdata=function(g,I,i){var n,C,r,o,A,s,a,l,c,u;this.endIndex=I;var d=this.getSlice(g,I-i);this.options.xmlMode||this.options.recognizeCDATA?((C=(n=this.cbs).oncdatastart)===null||C===void 0||C.call(n),(o=(r=this.cbs).ontext)===null||o===void 0||o.call(r,d),(s=(A=this.cbs).oncdataend)===null||s===void 0||s.call(A)):((l=(a=this.cbs).oncomment)===null||l===void 0||l.call(a,"[CDATA[".concat(d,"]]")),(u=(c=this.cbs).oncommentend)===null||u===void 0||u.call(c)),this.startIndex=I+1},e.prototype.onend=function(){var g,I;if(this.cbs.onclosetag){this.endIndex=this.startIndex;for(var i=this.stack.length;i>0;this.cbs.onclosetag(this.stack[--i],!0));}(I=(g=this.cbs).onend)===null||I===void 0||I.call(g)},e.prototype.reset=function(){var g,I,i,n;(I=(g=this.cbs).onreset)===null||I===void 0||I.call(g),this.tokenizer.reset(),this.tagname="",this.attribname="",this.attribs=null,this.stack.length=0,this.startIndex=0,this.endIndex=0,(n=(i=this.cbs).onparserinit)===null||n===void 0||n.call(i,this),this.buffers.length=0,this.bufferOffset=0,this.writeIndex=0,this.ended=!1},e.prototype.parseComplete=function(g){this.reset(),this.end(g)},e.prototype.getSlice=function(g,I){for(;g-this.bufferOffset>=this.buffers[0].length;)this.shiftBuffer();for(var i=this.buffers[0].slice(g-this.bufferOffset,I-this.bufferOffset);I-this.bufferOffset>this.buffers[0].length;)this.shiftBuffer(),i+=this.buffers[0].slice(0,I-this.bufferOffset);return i},e.prototype.shiftBuffer=function(){this.bufferOffset+=this.buffers[0].length,this.writeIndex--,this.buffers.shift()},e.prototype.write=function(g){var I,i;if(this.ended){(i=(I=this.cbs).onerror)===null||i===void 0||i.call(I,new Error(".write() after done!"));return}this.buffers.push(g),this.tokenizer.running&&(this.tokenizer.write(g),this.writeIndex++)},e.prototype.end=function(g){var I,i;if(this.ended){(i=(I=this.cbs).onerror)===null||i===void 0||i.call(I,new Error(".end() after done!"));return}g&&this.write(g),this.ended=!0,this.tokenizer.end()},e.prototype.pause=function(){this.tokenizer.pause()},e.prototype.resume=function(){for(this.tokenizer.resume();this.tokenizer.running&&this.writeIndex0&&arguments[0]!==void 0?arguments[0]:{};Zj={},$we(g)}var Ni={},Dz={exports:{}};(function(g,e){Object.defineProperty(e,"__esModule",{value:!0});var I=function(i){function n(C,r){return i.apply(this,arguments)}return n.toString=function(){return i.toString()},n}(function(i,n){return typeof i!="object"||i===null||typeof n!="object"||n===null?!1:Object.keys(n).every(function(C){if(!i.propertyIsEnumerable(C))return!1;var r=n[C],o=i[C];return!(typeof r=="object"&&r!==null?!I(o,r):o!==r)})});e.default=I,g.exports=e.default})(Dz,Dz.exports);var _Zt=Dz.exports,Bu={};(function(g){Object.defineProperty(g,"__esModule",{value:!0}),g.default=C;var e=xk,I=n(e),i=pm;function n(r){return r&&r.__esModule?r:{default:r}}function C(){var r=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(r.adapter)return(0,I.default)(r.adapter),r.adapter;var o=(0,i.get)(),A=o.adapter;return(0,I.default)(A),A}})(Bu);Object.defineProperty(Ni,"__esModule",{value:!0});var UZt=function(){function g(e,I){var i=[],n=!0,C=!1,r=void 0;try{for(var o=e[Symbol.iterator](),A;!(n=(A=o.next()).done)&&(i.push(A.value),!(I&&i.length===I));n=!0);}catch(s){C=!0,r=s}finally{try{!n&&o.return&&o.return()}finally{if(C)throw r}}return i}return function(e,I){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return g(e,I);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}();Ni.propsOfNode=Dk;Ni.childrenOfNode=Iy;Ni.hasClassName=sGt;Ni.treeForEach=Gj;Ni.treeFilter=Bj;Ni.findParentNode=lGt;Ni.pathToNode=qwe;Ni.parentsOfNode=uGt;Ni.nodeHasId=dGt;Ni.nodeMatchesObjectProps=pGt;Ni.getTextFromNode=eVe;Ni.getTextFromHostNodes=tVe;Ni.getHTMLFromHostNodes=gVe;var QZt=_0,jZt=bm(QZt),$Zt=lw,bCe=bm($Zt),qZt=wve,eGt=bm(qZt),tGt=_Zt,gGt=bm(tGt),IGt=$Q,iGt=bm(IGt),nGt=eve,CGt=bm(nGt),rGt=Bu,oGt=bm(rGt);function bm(g){return g&&g.__esModule?g:{default:g}}function AGt(g,e,I){return e in g?Object.defineProperty(g,e,{value:I,enumerable:!0,configurable:!0,writable:!0}):g[e]=I,g}function aGt(g){if(Array.isArray(g)){for(var e=0,I=Array(g.length);e-1}function Gj(g,e){g&&e(g),Iy(g).forEach(function(I){return Gj(I,e)})}function Bj(g,e){var I=[];return Gj(g,function(i){e(i)&&I.push(i)}),I}function lGt(g,e){var I=Bj(g,function(i){return i.rendered?Iy(i).indexOf(e)!==-1:!1});return I[0]||null}function cGt(g,e){return g.filter(function(I){return Bj(I,e).length!==0})}function qwe(g,e){for(var I=[e],i=[],n=function(A){return g===A};I.length;){var C=I.pop(),r=Iy(C);if(C===g)return cGt(i,n);i.push(C),r.length===0&&i.pop(),I.push.apply(I,aGt(r))}return null}function uGt(g,e){return(qwe(g,e)||[]).reverse()}function dGt(g,e){return Dk(g).id===e}var hGt={};function mGt(g){return typeof g<"u"?g:hGt}function fGt(g){return(0,eGt.default)(g).reduce(function(e,I){var i=UZt(I,2),n=i[0],C=i[1];return(0,jZt.default)({},e,AGt({},n,mGt(C)))},{})}function pGt(g,e){return(0,gGt.default)(Dk(g),fGt(e))}function bGt(g){return typeof g=="string"?String(g||""):g&&g.textContent||""}function vj(g,e){var I=e.getCustom,i=e.handleHostNodes,n=e.recurse,C=e.nullRenderReturnsNull,r=C===void 0?!1:C;return g==null?"":typeof g=="string"||typeof g=="number"?String(g):I&&g.type&&typeof g.type=="function"?I(g):i&&g.nodeType==="host"?i(g):g.rendered==null&&r?null:Iy(g).map(n).join("")}function eVe(g){return vj(g,{recurse:eVe,getCustom:function(){function e(I){var i=I.type;return"<"+String(i.displayName||(0,iGt.default)(i))+" />"}return e}()})}function tVe(g,e){return vj(g,{recurse:function(){function I(i){return tVe(i,e)}return I}(),handleHostNodes:function(){function I(i){var n=[].concat(e.nodeToHostNode(i,!0));return n.map(bGt).join("")}return I}()})}function yGt(g){return g==null?null:g.outerHTML.replace(/\sdata-(reactid|reactroot)+="([^"]*)+"/g,"")}function gVe(g,e){return vj(g,{recurse:function(){function I(i){return gVe(i,e)}return I}(),handleHostNodes:function(){function I(i){var n=[].concat(e.nodeToHostNode(i,!0));return n.map(yGt).join("")}return I}(),nullRenderReturnsNull:!0})}(function(g){Object.defineProperty(g,"__esModule",{value:!0}),g.shallowEqual=g.ITERATOR_SYMBOL=void 0;var e=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(K){return typeof K}:function(K){return K&&typeof Symbol=="function"&&K.constructor===Symbol&&K!==Symbol.prototype?"symbol":typeof K},I=function(){function K(T,k){var ge=[],he=!0,we=!1,xe=void 0;try{for(var qe=T[Symbol.iterator](),mt;!(he=(mt=qe.next()).done)&&(ge.push(mt.value),!(k&&ge.length===k));he=!0);}catch(St){we=!0,xe=St}finally{try{!he&&qe.return&&qe.return()}finally{if(we)throw xe}}return ge}return function(T,k){if(Array.isArray(T))return T;if(Symbol.iterator in Object(T))return K(T,k);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}();g.getAdapter=D,g.makeOptions=F,g.isCustomComponent=_,g.isCustomComponentElement=J,g.propsOfNode=te,g.typeOfNode=q,g.nodeHasType=$,g.nodeMatches=Ce,g.nodeEqual=Ze,g.containsChildrenSubArray=Ge,g.childrenToSimplifiedArray=Xe,g.isReactElementAlike=ze,g.withSetStateAllowed=Me,g.AND=Ue,g.displayNameOfNode=_e,g.sym=At,g.privateSet=wt,g.cloneElement=rt,g.spyMethod=Te;var i=yve;Object.defineProperty(g,"shallowEqual",{enumerable:!0,get:function(){function K(){return W(i).default}return K}()}),g.isEmptyValue=le,g.renderedDive=ye,g.loadCheerioRoot=We;var n=_0,C=W(n),r=TN,o=W(r),A=QQ,s=W(A),a=wve,l=W(a),c=$Q,u=W(c),d=Q0,h=W(d),m=lw,f=W(m),b=rve,p=W(b),y=Kve,Z=W(y),v=Zu,G=pm,B=Ni,w=Bu,R=W(w),S=xk,X=W(S);function W(K){return K&&K.__esModule?K:{default:K}}function V(K,T,k){return T in K?Object.defineProperty(K,T,{value:k,enumerable:!0,configurable:!0,writable:!0}):K[T]=k,K}function H(K,T){var k={};for(var ge in K)T.indexOf(ge)>=0||Object.prototype.hasOwnProperty.call(K,ge)&&(k[ge]=K[ge]);return k}g.ITERATOR_SYMBOL=typeof Symbol=="function"&&Symbol.iterator;function D(){var K=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};return console.warn("getAdapter from Utils is deprecated; please use ./getAdapter instead"),(0,R.default)(K)}function Y(K,T){if(K&&T&&K!==T)throw new TypeError("If both the `attachTo` and `hydrateIn` options are provided, they must be === (for backwards compatibility)")}function F(K){var T=(0,G.get)(),k=T.attachTo,ge=T.hydrateIn,he=H(T,["attachTo","hydrateIn"]);Y(k,ge);var we=K.attachTo,xe=K.hydrateIn;Y(we,xe);var qe=xe||ge||k||we||void 0,mt=xe||ge||void 0,St=(0,C.default)({},qe&&{attachTo:qe},mt&&{hydrateIn:mt});return(0,C.default)({},he,K,St)}function _(K,T){return(0,X.default)(T),T.isCustomComponent?!!T.isCustomComponent(K):typeof K=="function"}function J(K,T){return T.isCustomComponentElement?!!T.isCustomComponentElement(K):!!K&&T.isValidElement(K)&&typeof K.type=="function"}function te(K){return(0,l.default)(K&&K.props||{}).filter(function(T){var k=I(T,2),ge=k[1];return typeof ge<"u"}).reduce(function(T,k){var ge=I(k,2),he=ge[0],we=ge[1];return(0,C.default)(T,V({},he,we))},{})}function q(K){return K?K.type:null}function $(K,T){if(!T||!K)return!1;var k=(0,R.default)();if(k.displayNameOfNode){var ge=k.displayNameOfNode(K);return ge===T}return K.type?typeof K.type=="string"?K.type===T:(typeof K.type=="function"?(0,u.default)(K.type)===T:K.type.name===T)||K.type.displayName===T:!1}function j(K,T,k,ge){var he=ge?Ce:Ze;if(K===T)return!0;if(!Array.isArray(K)&&!Array.isArray(T))return he(K,T,k);var we=(0,f.default)(K,1/0),xe=(0,f.default)(T,1/0);if(we.length!==xe.length)return!1;if(we.length===0&&xe.length===0)return!0;for(var qe=0;qe2&&arguments[2]!==void 0?arguments[2]:s.default;return fe(K,T,k,!0)}function Ze(K,T){var k=arguments.length>2&&arguments[2]!==void 0?arguments[2]:s.default;return fe(K,T,k,!1)}function Ge(K,T,k){var ge=(0,B.childrenOfNode)(T),he=function(xe,qe){return ve(K,ge.slice(qe,qe+k.length),k)};return ge.some(he)}function ve(K,T,k){return T.length===k.length&&T.every(function(ge,he){return K(ge,k[he])})}function ke(K){var T=[],k=function(he){he===null||he===!1||typeof he>"u"||T.push(he)};return Array.isArray(K)?K.forEach(k):k(K),T}function Xe(K){for(var T=arguments.length>1&&arguments[1]!==void 0?arguments[1]:!1,k=ke(K),ge=[],he=0;he"u"?ge.push(we):Oe(we)&&Oe(xe)?ge.push(xe+we):(ge.push(xe),ge.push(we))}return T?ge.map(function(qe){return typeof qe=="string"?(0,p.default)(qe):qe}):ge}function Oe(K){return typeof K=="string"||typeof K=="number"}function ze(K,T){return T.isValidElement(K)||Oe(K)||Array.isArray(K)}function Me(K){var T=!1;typeof globalThis.document>"u"&&(T=!0,globalThis.document={}),K(),T&&(globalThis.document=void 0,delete globalThis.document)}function Ue(K){var T=K.slice().reverse();return function(k){return T.every(function(ge){return ge(k)})}}function _e(K){if(!K)return null;var T=K.type;return T?T.displayName||(typeof T=="function"?(0,u.default)(T):T.name||T):null}function At(K){return typeof Symbol=="function"?Symbol.for("enzyme."+String(K)):K}function wt(K,T,k){Object.defineProperty(K,T,{value:k,enumerable:!1,writable:!0})}function rt(K,T,k){return K.createElement(T.type,(0,C.default)({},T.props,k))}function Te(K,T){var k=arguments.length>2&&arguments[2]!==void 0?arguments[2]:function(){},ge=void 0,he=K[T],we=(0,h.default)(K,T),xe=void 0;return we&&(xe=Object.getOwnPropertyDescriptor(K,T)),Object.defineProperty(K,T,{configurable:!0,enumerable:!xe||!!xe.enumerable,value:k(he)||function(){function qe(){for(var mt=arguments.length,St=Array(mt),ut=0;ut"'`]/g,BGt=RegExp(IVe.source),vGt={"&":"&","<":"<",">":">",'"':""","'":"'","`":"`"},SGt=typeof globalThis=="object"&&globalThis&&globalThis.Object===Object&&globalThis,wGt=typeof self=="object"&&self&&self.Object===Object&&self,VGt=SGt||wGt||Function("return this")();function RGt(g){return function(e){return g==null?void 0:g[e]}}var WGt=RGt(vGt),XGt=Object.prototype,HGt=XGt.toString,yCe=VGt.Symbol,ZCe=yCe?yCe.prototype:void 0,GCe=ZCe?ZCe.toString:void 0;function TGt(g){if(typeof g=="string")return g;if(kGt(g))return GCe?GCe.call(g):"";var e=g+"";return e=="0"&&1/g==-ZGt?"-0":e}function NGt(g){return!!g&&typeof g=="object"}function kGt(g){return typeof g=="symbol"||NGt(g)&&HGt.call(g)==GGt}function YGt(g){return g==null?"":TGt(g)}function KGt(g){return g=YGt(g),g&&BGt.test(g)?g.replace(IVe,WGt):g}var xGt=KGt,DGt=String.prototype.valueOf,FGt=function(e){try{return DGt.call(e),!0}catch{return!1}},EGt=Object.prototype.toString,MGt="[object String]",zGt=sw(),iVe=function(e){return typeof e=="string"?!0:typeof e!="object"?!1:zGt?FGt(e):EGt.call(e)===MGt},PGt=Number.prototype.toString,JGt=function(e){try{return PGt.call(e),!0}catch{return!1}},OGt=Object.prototype.toString,LGt="[object Number]",_Gt=sw(),UGt=function(e){return typeof e=="number"?!0:typeof e!="object"?!1:_Gt?JGt(e):OGt.call(e)===LGt},nVe=uC,QGt=nVe("Boolean.prototype.toString"),jGt=nVe("Object.prototype.toString"),$Gt=function(e){try{return QGt(e),!0}catch{return!1}},qGt="[object Boolean]",eBt=sw(),tBt=function(e){return typeof e=="boolean"?!0:e===null||typeof e!="object"?!1:eBt&&Symbol.toStringTag in e?$Gt(e):jGt(e)===qGt};Object.defineProperty(vu,"__esModule",{value:!0});var BCe=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(g){return typeof g}:function(g){return g&&typeof Symbol=="function"&&g.constructor===Symbol&&g!==Symbol.prototype?"symbol":typeof g};vu.typeName=oVe;vu.spaces=AVe;vu.indent=aVe;vu.debugNode=Sj;vu.debugNodes=yBt;var gBt=xGt,IBt=ml(gBt),iBt=$Q,CVe=ml(iBt),nBt=iVe,CBt=ml(nBt),rBt=UGt,oBt=ml(rBt),ABt=LQ,aBt=ml(ABt),sBt=tBt,lBt=ml(sBt),cBt=TBe,Tf=ml(cBt),uBt=Q0,gf=ml(uBt),rVe=Ni,dBt=Bu,Fz=ml(dBt);function ml(g){return g&&g.__esModule?g:{default:g}}var hBt=Function.bind.call(Function.call,Boolean.prototype.valueOf);function oVe(g){var e=(0,Fz.default)();return e.displayNameOfNode?(0,Fz.default)().displayNameOfNode(g)||"Component":typeof g.type=="function"?g.type.displayName||(0,CVe.default)(g.type)||"Component":g.type}function AVe(g){return Array(g+1).join(" ")}function aVe(g,e){return e.split(` -`).map(function(I){return""+String(AVe(g))+String(I)}).join(` -`)}function mBt(g,e){return(0,CBt.default)(g)?(0,Tf.default)(String(g),{quoteStyle:"double"}):(0,oBt.default)(g)?"{"+String((0,Tf.default)(Number(g)))+"}":(0,lBt.default)(g)?"{"+String((0,Tf.default)(hBt(g)))+"}":(0,aBt.default)(g)?"{"+String((0,Tf.default)(g))+"}":(typeof g>"u"?"undefined":BCe(g))==="object"?e.verbose?"{"+String((0,Tf.default)(g))+"}":"{{...}}":"{["+(typeof g>"u"?"undefined":BCe(g))+"]}"}function fBt(g,e){var I=(0,rVe.propsOfNode)(g),i=Object.keys(I).filter(function(n){return n!=="children"});return i.map(function(n){return String(n)+"="+String(mBt(I[n],e))}).join(" ")}function pBt(g,e){return g.length?` -`+String(g.map(function(I){return aVe(e,I)}).join(` + `);if(!(C instanceof I.default))throw new Error("Enzyme Internal Error: configured enzyme adapter did not inherit from the EnzymeAdapter base class")}})(ON);Object.defineProperty(gm,"__esModule",{value:!0});gm.get=vvt;gm.merge=MSe;gm.reset=Bvt;var yvt=R0,FSe=ESe(yvt),Zvt=ON,Gvt=ESe(Zvt);function ESe(e){return e&&e.__esModule?e:{default:e}}var zQ={};function vvt(){return(0,FSe.default)({},zQ)}function MSe(e){e.adapter&&(0,Gvt.default)(e.adapter),(0,FSe.default)(zQ,e)}function Bvt(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};zQ={},MSe(e)}var Ni={},iz={exports:{}};(function(e,g){Object.defineProperty(g,"__esModule",{value:!0});var I=function(i){function n(C,r){return i.apply(this,arguments)}return n.toString=function(){return i.toString()},n}(function(i,n){return typeof i!="object"||i===null||typeof n!="object"||n===null?!1:Object.keys(n).every(function(C){if(!i.propertyIsEnumerable(C))return!1;var r=n[C],o=i[C];return!(typeof r=="object"&&r!==null?!I(o,r):o!==r)})});g.default=I,e.exports=g.default})(iz,iz.exports);var Svt=iz.exports,Iu={};(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.default=C;var g=ON,I=n(g),i=gm;function n(r){return r&&r.__esModule?r:{default:r}}function C(){var r=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(r.adapter)return(0,I.default)(r.adapter),r.adapter;var o=(0,i.get)(),A=o.adapter;return(0,I.default)(A),A}})(Iu);Object.defineProperty(Ni,"__esModule",{value:!0});var wvt=function(){function e(g,I){var i=[],n=!0,C=!1,r=void 0;try{for(var o=g[Symbol.iterator](),A;!(n=(A=o.next()).done)&&(i.push(A.value),!(I&&i.length===I));n=!0);}catch(s){C=!0,r=s}finally{try{!n&&o.return&&o.return()}finally{if(C)throw r}}return i}return function(g,I){if(Array.isArray(g))return g;if(Symbol.iterator in Object(g))return e(g,I);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}();Ni.propsOfNode=_N;Ni.childrenOfNode=D0;Ni.hasClassName=zvt;Ni.treeForEach=PQ;Ni.treeFilter=JQ;Ni.findParentNode=Pvt;Ni.pathToNode=zSe;Ni.parentsOfNode=Ovt;Ni.nodeHasId=_vt;Ni.nodeMatchesObjectProps=jvt;Ni.getTextFromNode=PSe;Ni.getTextFromHostNodes=JSe;Ni.getHTMLFromHostNodes=OSe;var Vvt=R0,Rvt=Im(Vvt),Wvt=TS,kne=Im(Wvt),Xvt=mve,Hvt=Im(Xvt),Tvt=Svt,Nvt=Im(Tvt),kvt=pQ,Yvt=Im(kvt),Kvt=PGe,Dvt=Im(Kvt),xvt=Iu,Fvt=Im(xvt);function Im(e){return e&&e.__esModule?e:{default:e}}function Evt(e,g,I){return g in e?Object.defineProperty(e,g,{value:I,enumerable:!0,configurable:!0,writable:!0}):e[g]=I,e}function Mvt(e){if(Array.isArray(e)){for(var g=0,I=Array(e.length);g-1}function PQ(e,g){e&&g(e),D0(e).forEach(function(I){return PQ(I,g)})}function JQ(e,g){var I=[];return PQ(e,function(i){g(i)&&I.push(i)}),I}function Pvt(e,g){var I=JQ(e,function(i){return i.rendered?D0(i).indexOf(g)!==-1:!1});return I[0]||null}function Jvt(e,g){return e.filter(function(I){return JQ(I,g).length!==0})}function zSe(e,g){for(var I=[g],i=[],n=function(A){return e===A};I.length;){var C=I.pop(),r=D0(C);if(C===e)return Jvt(i,n);i.push(C),r.length===0&&i.pop(),I.push.apply(I,Mvt(r))}return null}function Ovt(e,g){return(zSe(e,g)||[]).reverse()}function _vt(e,g){return _N(e).id===g}var Lvt={};function Uvt(e){return typeof e<"u"?e:Lvt}function Qvt(e){return(0,Hvt.default)(e).reduce(function(g,I){var i=wvt(I,2),n=i[0],C=i[1];return(0,Rvt.default)({},g,Evt({},n,Uvt(C)))},{})}function jvt(e,g){return(0,Nvt.default)(_N(e),Qvt(g))}function $vt(e){return typeof e=="string"?String(e||""):e&&e.textContent||""}function OQ(e,g){var I=g.getCustom,i=g.handleHostNodes,n=g.recurse,C=g.nullRenderReturnsNull,r=C===void 0?!1:C;return e==null?"":typeof e=="string"||typeof e=="number"?String(e):I&&e.type&&typeof e.type=="function"?I(e):i&&e.nodeType==="host"?i(e):e.rendered==null&&r?null:D0(e).map(n).join("")}function PSe(e){return OQ(e,{recurse:PSe,getCustom:function(){function g(I){var i=I.type;return"<"+String(i.displayName||(0,Yvt.default)(i))+" />"}return g}()})}function JSe(e,g){return OQ(e,{recurse:function(){function I(i){return JSe(i,g)}return I}(),handleHostNodes:function(){function I(i){var n=[].concat(g.nodeToHostNode(i,!0));return n.map($vt).join("")}return I}()})}function qvt(e){return e==null?null:e.outerHTML.replace(/\sdata-(reactid|reactroot)+="([^"]*)+"/g,"")}function OSe(e,g){return OQ(e,{recurse:function(){function I(i){return OSe(i,g)}return I}(),handleHostNodes:function(){function I(i){var n=[].concat(g.nodeToHostNode(i,!0));return n.map(qvt).join("")}return I}(),nullRenderReturnsNull:!0})}(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.shallowEqual=e.ITERATOR_SYMBOL=void 0;var g=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(K){return typeof K}:function(K){return K&&typeof Symbol=="function"&&K.constructor===Symbol&&K!==Symbol.prototype?"symbol":typeof K},I=function(){function K(T,k){var ge=[],he=!0,Ve=!1,De=void 0;try{for(var qe=T[Symbol.iterator](),mt;!(he=(mt=qe.next()).done)&&(ge.push(mt.value),!(k&&ge.length===k));he=!0);}catch(vt){Ve=!0,De=vt}finally{try{!he&&qe.return&&qe.return()}finally{if(Ve)throw De}}return ge}return function(T,k){if(Array.isArray(T))return T;if(Symbol.iterator in Object(T))return K(T,k);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}();e.getAdapter=Y,e.makeOptions=E,e.isCustomComponent=O,e.isCustomComponentElement=J,e.propsOfNode=ee,e.typeOfNode=q,e.nodeHasType=$,e.nodeMatches=Ce,e.nodeEqual=Ze,e.containsChildrenSubArray=Ge,e.childrenToSimplifiedArray=Se,e.isReactElementAlike=ze,e.withSetStateAllowed=Fe,e.AND=Ue,e.displayNameOfNode=_e,e.sym=ot,e.privateSet=Zt,e.cloneElement=nt,e.spyMethod=Te;var i=sve;Object.defineProperty(e,"shallowEqual",{enumerable:!0,get:function(){function K(){return W(i).default}return K}()}),e.isEmptyValue=se,e.renderedDive=ye,e.loadCheerioRoot=Xe;var n=R0,C=W(n),r=ET,o=W(r),A=mQ,s=W(A),a=mve,l=W(a),c=pQ,u=W(c),d=X0,h=W(d),m=TS,f=W(m),b=jGe,p=W(b),y=wve,Z=W(y),B=tu,G=gm,v=Ni,w=Iu,V=W(w),S=ON,X=W(S);function W(K){return K&&K.__esModule?K:{default:K}}function R(K,T,k){return T in K?Object.defineProperty(K,T,{value:k,enumerable:!0,configurable:!0,writable:!0}):K[T]=k,K}function H(K,T){var k={};for(var ge in K)T.indexOf(ge)>=0||Object.prototype.hasOwnProperty.call(K,ge)&&(k[ge]=K[ge]);return k}e.ITERATOR_SYMBOL=typeof Symbol=="function"&&Symbol.iterator;function Y(){var K=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};return console.warn("getAdapter from Utils is deprecated; please use ./getAdapter instead"),(0,V.default)(K)}function D(K,T){if(K&&T&&K!==T)throw new TypeError("If both the `attachTo` and `hydrateIn` options are provided, they must be === (for backwards compatibility)")}function E(K){var T=(0,G.get)(),k=T.attachTo,ge=T.hydrateIn,he=H(T,["attachTo","hydrateIn"]);D(k,ge);var Ve=K.attachTo,De=K.hydrateIn;D(Ve,De);var qe=De||ge||k||Ve||void 0,mt=De||ge||void 0,vt=(0,C.default)({},qe&&{attachTo:qe},mt&&{hydrateIn:mt});return(0,C.default)({},he,K,vt)}function O(K,T){return(0,X.default)(T),T.isCustomComponent?!!T.isCustomComponent(K):typeof K=="function"}function J(K,T){return T.isCustomComponentElement?!!T.isCustomComponentElement(K):!!K&&T.isValidElement(K)&&typeof K.type=="function"}function ee(K){return(0,l.default)(K&&K.props||{}).filter(function(T){var k=I(T,2),ge=k[1];return typeof ge<"u"}).reduce(function(T,k){var ge=I(k,2),he=ge[0],Ve=ge[1];return(0,C.default)(T,R({},he,Ve))},{})}function q(K){return K?K.type:null}function $(K,T){if(!T||!K)return!1;var k=(0,V.default)();if(k.displayNameOfNode){var ge=k.displayNameOfNode(K);return ge===T}return K.type?typeof K.type=="string"?K.type===T:(typeof K.type=="function"?(0,u.default)(K.type)===T:K.type.name===T)||K.type.displayName===T:!1}function j(K,T,k,ge){var he=ge?Ce:Ze;if(K===T)return!0;if(!Array.isArray(K)&&!Array.isArray(T))return he(K,T,k);var Ve=(0,f.default)(K,1/0),De=(0,f.default)(T,1/0);if(Ve.length!==De.length)return!1;if(Ve.length===0&&De.length===0)return!0;for(var qe=0;qe2&&arguments[2]!==void 0?arguments[2]:s.default;return me(K,T,k,!0)}function Ze(K,T){var k=arguments.length>2&&arguments[2]!==void 0?arguments[2]:s.default;return me(K,T,k,!1)}function Ge(K,T,k){var ge=(0,v.childrenOfNode)(T),he=function(De,qe){return Be(K,ge.slice(qe,qe+k.length),k)};return ge.some(he)}function Be(K,T,k){return T.length===k.length&&T.every(function(ge,he){return K(ge,k[he])})}function Ne(K){var T=[],k=function(he){he===null||he===!1||typeof he>"u"||T.push(he)};return Array.isArray(K)?K.forEach(k):k(K),T}function Se(K){for(var T=arguments.length>1&&arguments[1]!==void 0?arguments[1]:!1,k=Ne(K),ge=[],he=0;he"u"?ge.push(Ve):Pe(Ve)&&Pe(De)?ge.push(De+Ve):(ge.push(De),ge.push(Ve))}return T?ge.map(function(qe){return typeof qe=="string"?(0,p.default)(qe):qe}):ge}function Pe(K){return typeof K=="string"||typeof K=="number"}function ze(K,T){return T.isValidElement(K)||Pe(K)||Array.isArray(K)}function Fe(K){var T=!1;typeof globalThis.document>"u"&&(T=!0,globalThis.document={}),K(),T&&(globalThis.document=void 0,delete globalThis.document)}function Ue(K){var T=K.slice().reverse();return function(k){return T.every(function(ge){return ge(k)})}}function _e(K){if(!K)return null;var T=K.type;return T?T.displayName||(typeof T=="function"?(0,u.default)(T):T.name||T):null}function ot(K){return typeof Symbol=="function"?Symbol.for("enzyme."+String(K)):K}function Zt(K,T,k){Object.defineProperty(K,T,{value:k,enumerable:!1,writable:!0})}function nt(K,T,k){return K.createElement(T.type,(0,C.default)({},T.props,k))}function Te(K,T){var k=arguments.length>2&&arguments[2]!==void 0?arguments[2]:function(){},ge=void 0,he=K[T],Ve=(0,h.default)(K,T),De=void 0;return Ve&&(De=Object.getOwnPropertyDescriptor(K,T)),Object.defineProperty(K,T,{configurable:!0,enumerable:!De||!!De.enumerable,value:k(he)||function(){function qe(){for(var mt=arguments.length,vt=Array(mt),ct=0;ct"'`]/g,gBt=RegExp(_Se.source),IBt={"&":"&","<":"<",">":">",'"':""","'":"'","`":"`"},iBt=typeof globalThis=="object"&&globalThis&&globalThis.Object===Object&&globalThis,nBt=typeof self=="object"&&self&&self.Object===Object&&self,CBt=iBt||nBt||Function("return this")();function rBt(e){return function(g){return e==null?void 0:e[g]}}var oBt=rBt(IBt),ABt=Object.prototype,aBt=ABt.toString,Yne=CBt.Symbol,Kne=Yne?Yne.prototype:void 0,Dne=Kne?Kne.toString:void 0;function sBt(e){if(typeof e=="string")return e;if(cBt(e))return Dne?Dne.call(e):"";var g=e+"";return g=="0"&&1/e==-eBt?"-0":g}function lBt(e){return!!e&&typeof e=="object"}function cBt(e){return typeof e=="symbol"||lBt(e)&&aBt.call(e)==tBt}function uBt(e){return e==null?"":sBt(e)}function dBt(e){return e=uBt(e),e&&gBt.test(e)?e.replace(_Se,oBt):e}var hBt=dBt,mBt=String.prototype.valueOf,fBt=function(g){try{return mBt.call(g),!0}catch{return!1}},pBt=Object.prototype.toString,bBt="[object String]",yBt=HS(),LSe=function(g){return typeof g=="string"?!0:typeof g!="object"?!1:yBt?fBt(g):pBt.call(g)===bBt},ZBt=Number.prototype.toString,GBt=function(g){try{return ZBt.call(g),!0}catch{return!1}},vBt=Object.prototype.toString,BBt="[object Number]",SBt=HS(),wBt=function(g){return typeof g=="number"?!0:typeof g!="object"?!1:SBt?GBt(g):vBt.call(g)===BBt},USe=sC,VBt=USe("Boolean.prototype.toString"),RBt=USe("Object.prototype.toString"),WBt=function(g){try{return VBt(g),!0}catch{return!1}},XBt="[object Boolean]",HBt=HS(),TBt=function(g){return typeof g=="boolean"?!0:g===null||typeof g!="object"?!1:HBt&&Symbol.toStringTag in g?WBt(g):RBt(g)===XBt};Object.defineProperty(iu,"__esModule",{value:!0});var xne=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(e){return typeof e}:function(e){return e&&typeof Symbol=="function"&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};iu.typeName=$Se;iu.spaces=qSe;iu.indent=ewe;iu.debugNode=_Q;iu.debugNodes=qBt;var NBt=hBt,kBt=el(NBt),YBt=pQ,QSe=el(YBt),KBt=LSe,DBt=el(KBt),xBt=wBt,FBt=el(xBt),EBt=uQ,MBt=el(EBt),zBt=TBt,PBt=el(zBt),JBt=GGe,af=el(JBt),OBt=X0,xm=el(OBt),jSe=Ni,_Bt=Iu,nz=el(_Bt);function el(e){return e&&e.__esModule?e:{default:e}}var LBt=Function.bind.call(Function.call,Boolean.prototype.valueOf);function $Se(e){var g=(0,nz.default)();return g.displayNameOfNode?(0,nz.default)().displayNameOfNode(e)||"Component":typeof e.type=="function"?e.type.displayName||(0,QSe.default)(e.type)||"Component":e.type}function qSe(e){return Array(e+1).join(" ")}function ewe(e,g){return g.split(` +`).map(function(I){return""+String(qSe(e))+String(I)}).join(` +`)}function UBt(e,g){return(0,DBt.default)(e)?(0,af.default)(String(e),{quoteStyle:"double"}):(0,FBt.default)(e)?"{"+String((0,af.default)(Number(e)))+"}":(0,PBt.default)(e)?"{"+String((0,af.default)(LBt(e)))+"}":(0,MBt.default)(e)?"{"+String((0,af.default)(e))+"}":(typeof e>"u"?"undefined":xne(e))==="object"?g.verbose?"{"+String((0,af.default)(e))+"}":"{{...}}":"{["+(typeof e>"u"?"undefined":xne(e))+"]}"}function QBt(e,g){var I=(0,jSe.propsOfNode)(e),i=Object.keys(I).filter(function(n){return n!=="children"});return i.map(function(n){return String(n)+"="+String(UBt(I[n],g))}).join(" ")}function jBt(e,g){return e.length?` +`+String(e.map(function(I){return ewe(g,I)}).join(` `))+` -`:""}function bBt(g){return(0,gf.default)(g,"nodeType")&&typeof g.nodeType=="string"&&(0,gf.default)(g,"type")&&(0,gf.default)(g,"key")&&(0,gf.default)(g,"ref")&&(0,gf.default)(g,"instance")&&(0,gf.default)(g,"rendered")}function Sj(g){var e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:2,I=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};if(typeof g=="string"||typeof g=="number")return(0,IBt.default)(g);if(typeof g=="function"){var i=(0,CVe.default)(g);return"[function"+(i?" "+String(i):"")+"]"}if(!g)return"";var n=(0,Fz.default)();if(!n.isValidElement(g)&&!bBt(g))return"{"+String((0,Tf.default)(g))+"}";var C=(0,rVe.childrenOfNode)(g).map(function(c){return Sj(c,e,I)}).filter(Boolean),r=oVe(g),o=I.ignoreProps?"":fBt(g,I),A=o?" ":"",s=C.length?">":" ",a=pBt(C,e),l=C.length?"":"/>";return"<"+String(r)+A+String(o)+s+String(a)+l}function yBt(g){var e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return g.map(function(I){return Sj(I,void 0,e)}).join(` +`:""}function $Bt(e){return(0,xm.default)(e,"nodeType")&&typeof e.nodeType=="string"&&(0,xm.default)(e,"type")&&(0,xm.default)(e,"key")&&(0,xm.default)(e,"ref")&&(0,xm.default)(e,"instance")&&(0,xm.default)(e,"rendered")}function _Q(e){var g=arguments.length>1&&arguments[1]!==void 0?arguments[1]:2,I=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};if(typeof e=="string"||typeof e=="number")return(0,kBt.default)(e);if(typeof e=="function"){var i=(0,QSe.default)(e);return"[function"+(i?" "+String(i):"")+"]"}if(!e)return"";var n=(0,nz.default)();if(!n.isValidElement(e)&&!$Bt(e))return"{"+String((0,af.default)(e))+"}";var C=(0,jSe.childrenOfNode)(e).map(function(c){return _Q(c,g,I)}).filter(Boolean),r=$Se(e),o=I.ignoreProps?"":QBt(e,I),A=o?" ":"",s=C.length?">":" ",a=jBt(C,g),l=C.length?"":"/>";return"<"+String(r)+A+String(o)+s+String(a)+l}function qBt(e){var g=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return e.map(function(I){return _Q(I,void 0,g)}).join(` -`)}var iy={},o0={},wj={};Object.defineProperty(wj,"__esModule",{value:!0});var vCe=function(e){return JSON.stringify(e)},ZBt=function(e){var I=e.body,i=[],n=!0,C=!1,r=void 0;try{for(var o=I[Symbol.iterator](),A;!(n=(A=o.next()).done);n=!0){var s=A.value,a=void 0;if(s.type==="universalSelector")a="*";else if(s.type==="typeSelector")a=s.name;else if(s.type==="idSelector")a="#"+s.name;else if(s.type==="classSelector")a="."+s.name;else if(s.type==="attributePresenceSelector")a="["+s.name+"]";else if(s.type==="attributeValueSelector")a="["+s.name+s.operator+vCe(s.value)+"]";else if(s.type==="pseudoClassSelector")a=":"+s.name,s.parameters.length&&(a+="("+s.parameters.map(vCe).join(", ")+")");else if(s.type==="pseudoElementSelector")a="::"+s.name;else throw new Error("Unknown token.");i.push(a)}}catch(l){C=!0,r=l}finally{try{!n&&o.return&&o.return()}finally{if(C)throw r}}return i.join("")};wj.default=function(){var g=function(I){var i=[],n=!0,C=!1,r=void 0;try{for(var o=I[Symbol.iterator](),A;!(n=(A=o.next()).done);n=!0){var s=A.value;if(s.type==="selector")i.push(ZBt(s));else if(s.type==="descendantCombinator")i.push(" ");else if(s.type==="childCombinator")i.push(" > ");else if(s.type==="adjacentSiblingCombinator")i.push(" + ");else if(s.type==="generalSiblingCombinator")i.push(" ~ ");else throw new Error("Unknown token.")}}catch(a){C=!0,r=a}finally{try{!n&&o.return&&o.return()}finally{if(C)throw r}}return i.join("")};return{generate:g}};var Vj={},sVe={exports:{}};(function(g){(function(e,I){g.exports?g.exports=I():e.nearley=I()})(Le,function(){function e(s,a,l){return this.id=++e.highestId,this.name=s,this.symbols=a,this.postprocess=l,this}e.highestId=0,e.prototype.toString=function(s){var a=typeof s>"u"?this.symbols.map(A).join(" "):this.symbols.slice(0,s).map(A).join(" ")+" ● "+this.symbols.slice(s).map(A).join(" ");return this.name+" → "+a};function I(s,a,l,c){this.rule=s,this.dot=a,this.reference=l,this.data=[],this.wantedBy=c,this.isComplete=this.dot===s.symbols.length}I.prototype.toString=function(){return"{"+this.rule.toString(this.dot)+"}, from: "+(this.reference||0)},I.prototype.nextState=function(s){var a=new I(this.rule,this.dot+1,this.reference,this.wantedBy);return a.left=this,a.right=s,a.isComplete&&(a.data=a.build(),a.right=void 0),a},I.prototype.build=function(){var s=[],a=this;do s.push(a.right.data),a=a.left;while(a.left);return s.reverse(),s},I.prototype.finish=function(){this.rule.postprocess&&(this.data=this.rule.postprocess(this.data,this.reference,r.fail))};function i(s,a){this.grammar=s,this.index=a,this.states=[],this.wants={},this.scannable=[],this.completed={}}i.prototype.process=function(s){for(var a=this.states,l=this.wants,c=this.completed,u=0;u ");else if(s.type==="adjacentSiblingCombinator")i.push(" + ");else if(s.type==="generalSiblingCombinator")i.push(" ~ ");else throw new Error("Unknown token.")}}catch(a){C=!0,r=a}finally{try{!n&&o.return&&o.return()}finally{if(C)throw r}}return i.join("")};return{generate:e}};var UQ={},twe={exports:{}};(function(e){(function(g,I){e.exports?e.exports=I():g.nearley=I()})(Le,function(){function g(s,a,l){return this.id=++g.highestId,this.name=s,this.symbols=a,this.postprocess=l,this}g.highestId=0,g.prototype.toString=function(s){var a=typeof s>"u"?this.symbols.map(A).join(" "):this.symbols.slice(0,s).map(A).join(" ")+" ● "+this.symbols.slice(s).map(A).join(" ");return this.name+" → "+a};function I(s,a,l,c){this.rule=s,this.dot=a,this.reference=l,this.data=[],this.wantedBy=c,this.isComplete=this.dot===s.symbols.length}I.prototype.toString=function(){return"{"+this.rule.toString(this.dot)+"}, from: "+(this.reference||0)},I.prototype.nextState=function(s){var a=new I(this.rule,this.dot+1,this.reference,this.wantedBy);return a.left=this,a.right=s,a.isComplete&&(a.data=a.build(),a.right=void 0),a},I.prototype.build=function(){var s=[],a=this;do s.push(a.right.data),a=a.left;while(a.left);return s.reverse(),s},I.prototype.finish=function(){this.rule.postprocess&&(this.data=this.rule.postprocess(this.data,this.reference,r.fail))};function i(s,a){this.grammar=s,this.index=a,this.states=[],this.wants={},this.scannable=[],this.completed={}}i.prototype.process=function(s){for(var a=this.states,l=this.wants,c=this.completed,u=0;u0&&a.push(" ^ "+c+" more lines identical to this"),c=0,a.push(" "+h)),l=h}},r.prototype.getSymbolDisplay=function(s){return o(s)},r.prototype.buildFirstStateStack=function(s,a){if(a.indexOf(s)!==-1)return null;if(s.wantedBy.length===0)return[s];var l=s.wantedBy[0],c=[s].concat(a),u=this.buildFirstStateStack(l,c);return u===null?null:[s].concat(u)},r.prototype.save=function(){var s=this.table[this.current];return s.lexerState=this.lexerState,s},r.prototype.restore=function(s){var a=s.index;this.current=a,this.table[a]=s,this.table.splice(a+1),this.lexerState=s.lexerState,this.results=this.finish()},r.prototype.rewind=function(s){if(!this.options.keepHistory)throw new Error("set option `keepHistory` to enable rewinding");this.restore(this.table[s])},r.prototype.finish=function(){var s=[],a=this.grammar.start,l=this.table[this.table.length-1];return l.states.forEach(function(c){c.rule.name===a&&c.dot===c.rule.symbols.length&&c.reference===0&&c.data!==r.fail&&s.push(c)}),s.map(function(c){return c.data})};function o(s){var a=typeof s;if(a==="string")return s;if(a==="object"){if(s.literal)return JSON.stringify(s.literal);if(s instanceof RegExp)return"character matching "+s;if(s.type)return s.type+" token";if(s.test)return"token matching "+String(s.test);throw new Error("Unknown symbol type: "+s)}}function A(s){var a=typeof s;if(a==="string")return s;if(a==="object"){if(s.literal)return JSON.stringify(s.literal);if(s instanceof RegExp)return s.toString();if(s.type)return"%"+s.type;if(s.test)return"<"+String(s.test)+">";throw new Error("Unknown symbol type: "+s)}}return{Parser:r,Grammar:n,Rule:e}})})(sVe);var GBt=sVe.exports,lVe={exports:{}},BBt=1/0,vBt=9007199254740991,SBt="[object Arguments]",wBt="[object Function]",VBt="[object GeneratorFunction]",RBt=typeof globalThis=="object"&&globalThis&&globalThis.Object===Object&&globalThis,WBt=typeof self=="object"&&self&&self.Object===Object&&self,XBt=RBt||WBt||Function("return this")();function HBt(g,e){for(var I=-1,i=e.length,n=g.length;++I0&&I(o)?e>1?uVe(o,e-1,I,i,n):HBt(n,o):i||(n[n.length]=o)}return n}function kBt(g){return xBt(g)||KBt(g)||!!(wCe&&g&&g[wCe])}function YBt(g){var e=g?g.length:0;return e?uVe(g,BBt):[]}function KBt(g){return FBt(g)&&TBt.call(g,"callee")&&(!NBt.call(g,"callee")||cVe.call(g)==SBt)}var xBt=Array.isArray;function DBt(g){return g!=null&&MBt(g.length)&&!EBt(g)}function FBt(g){return PBt(g)&&DBt(g)}function EBt(g){var e=zBt(g)?cVe.call(g):"";return e==wBt||e==VBt}function MBt(g){return typeof g=="number"&&g>-1&&g%1==0&&g<=vBt}function zBt(g){var e=typeof g;return!!g&&(e=="object"||e=="function")}function PBt(g){return!!g&&typeof g=="object"}var JBt=YBt;(function(g){(function(){function e(l){return l[0]}var I=JBt,i=function(c,u){return function(d){return d[c].concat([d[u]])}},n=function(c){return c=c.filter(function(u){return u!==null}),I(c)},C={" ":"descendantCombinator","+":"adjacentSiblingCombinator",">":"childCombinator","~":"generalSiblingCombinator"},r=function(c){return(Array.isArray(c[0])?c[0]:[c[0]]).concat({type:C[c[2]]}).concat(c[4])},o=function(c,u,d){var h=I(c).join(""),m=parseFloat(h);return isNaN(m)?d:m},A=function(c,u,d){return c[0]==="true"?!0:c[0]==="false"?!1:d},s=function(c,u,d){if(c[0]==="NaN")return NaN;if(c[0]!=="undefined")return c[0]==="null"?null:d},a={Lexer:void 0,ParserRules:[{name:"combinator",symbols:["selector"]},{name:"combinator",symbols:["combinator","_",/[>+~ ]/,"_","selector"],postprocess:r},{name:"selector",symbols:["selectorBody"],postprocess:function(c){return{type:"selector",body:c[0]}}},{name:"selectorBody$ebnf$1",symbols:["typeSelector"],postprocess:e},{name:"selectorBody$ebnf$1",symbols:[],postprocess:function(c){return null}},{name:"selectorBody$ebnf$2",symbols:[]},{name:"selectorBody$ebnf$2",symbols:["selectorBody$ebnf$2","simpleSelector"],postprocess:function(c){return c[0].concat([c[1]])}},{name:"selectorBody",symbols:["selectorBody$ebnf$1","selectorBody$ebnf$2"],postprocess:function(c,u,d){var h=n(c);return h.length?h:d}},{name:"selectorBody$ebnf$3",symbols:[]},{name:"selectorBody$ebnf$3",symbols:["selectorBody$ebnf$3","simpleSelector"],postprocess:function(c){return c[0].concat([c[1]])}},{name:"selectorBody",symbols:["universalSelector","selectorBody$ebnf$3"],postprocess:n},{name:"simpleSelector",symbols:["idSelector"]},{name:"simpleSelector",symbols:["classSelector"]},{name:"simpleSelector",symbols:["attributeValueSelector"]},{name:"simpleSelector",symbols:["attributePresenceSelector"]},{name:"simpleSelector",symbols:["pseudoClassSelector"]},{name:"simpleSelector",symbols:["pseudoElementSelector"]},{name:"typeSelector",symbols:["attributeName"],postprocess:function(c){return{type:"typeSelector",name:c[0]}}},{name:"className$ebnf$1",symbols:[{literal:"-"}],postprocess:e},{name:"className$ebnf$1",symbols:[],postprocess:function(c){return null}},{name:"className$ebnf$2",symbols:[]},{name:"className$ebnf$2",symbols:["className$ebnf$2",/[_a-zA-Z0-9-]/],postprocess:function(c){return c[0].concat([c[1]])}},{name:"className",symbols:["className$ebnf$1",/[_a-zA-Z]/,"className$ebnf$2"],postprocess:function(c){return(c[0]||"")+c[1]+c[2].join("")}},{name:"attributeName$ebnf$1",symbols:[]},{name:"attributeName$ebnf$1",symbols:["attributeName$ebnf$1",/[_a-zA-Z()0-9-]/],postprocess:function(c){return c[0].concat([c[1]])}},{name:"attributeName",symbols:[/[_a-z()A-Z]/,"attributeName$ebnf$1"],postprocess:function(c){return c[0]+c[1].join("")}},{name:"classSelector",symbols:[{literal:"."},"className"],postprocess:function(c){return{type:"classSelector",name:c[1]}}},{name:"idSelector",symbols:[{literal:"#"},"attributeName"],postprocess:function(c){return{type:"idSelector",name:c[1]}}},{name:"universalSelector",symbols:[{literal:"*"}],postprocess:function(c){return{type:"universalSelector"}}},{name:"attributePresenceSelector",symbols:[{literal:"["},"attributeName",{literal:"]"}],postprocess:function(c){return{type:"attributePresenceSelector",name:c[1]}}},{name:"attributeOperator",symbols:[{literal:"="}]},{name:"attributeOperator$string$1",symbols:[{literal:"~"},{literal:"="}],postprocess:function(c){return c.join("")}},{name:"attributeOperator",symbols:["attributeOperator$string$1"]},{name:"attributeOperator$string$2",symbols:[{literal:"|"},{literal:"="}],postprocess:function(c){return c.join("")}},{name:"attributeOperator",symbols:["attributeOperator$string$2"]},{name:"attributeOperator$string$3",symbols:[{literal:"^"},{literal:"="}],postprocess:function(c){return c.join("")}},{name:"attributeOperator",symbols:["attributeOperator$string$3"]},{name:"attributeOperator$string$4",symbols:[{literal:"$"},{literal:"="}],postprocess:function(c){return c.join("")}},{name:"attributeOperator",symbols:["attributeOperator$string$4"]},{name:"attributeOperator$string$5",symbols:[{literal:"*"},{literal:"="}],postprocess:function(c){return c.join("")}},{name:"attributeOperator",symbols:["attributeOperator$string$5"]},{name:"attributeValueSelector",symbols:[{literal:"["},"attributeName","attributeOperator","attributeValue",{literal:"]"}],postprocess:function(c){return{type:"attributeValueSelector",name:c[1],value:c[3],operator:c[2][0]}}},{name:"attributeValue",symbols:["falsyPrimitiveStrings"],postprocess:e},{name:"attributeValue",symbols:["numericValue"],postprocess:e},{name:"attributeValue",symbols:["sqstring"],postprocess:e},{name:"attributeValue",symbols:["dqstring"],postprocess:e},{name:"falsyPrimitiveStrings$string$1",symbols:[{literal:"f"},{literal:"a"},{literal:"l"},{literal:"s"},{literal:"e"}],postprocess:function(c){return c.join("")}},{name:"falsyPrimitiveStrings",symbols:["falsyPrimitiveStrings$string$1"],postprocess:A},{name:"falsyPrimitiveStrings$string$2",symbols:[{literal:"t"},{literal:"r"},{literal:"u"},{literal:"e"}],postprocess:function(c){return c.join("")}},{name:"falsyPrimitiveStrings",symbols:["falsyPrimitiveStrings$string$2"],postprocess:A},{name:"falsyPrimitiveStrings$string$3",symbols:[{literal:"N"},{literal:"a"},{literal:"N"}],postprocess:function(c){return c.join("")}},{name:"falsyPrimitiveStrings",symbols:["falsyPrimitiveStrings$string$3"],postprocess:s},{name:"falsyPrimitiveStrings$string$4",symbols:[{literal:"n"},{literal:"u"},{literal:"l"},{literal:"l"}],postprocess:function(c){return c.join("")}},{name:"falsyPrimitiveStrings",symbols:["falsyPrimitiveStrings$string$4"],postprocess:s},{name:"falsyPrimitiveStrings$string$5",symbols:[{literal:"u"},{literal:"n"},{literal:"d"},{literal:"e"},{literal:"f"},{literal:"i"},{literal:"n"},{literal:"e"},{literal:"d"}],postprocess:function(c){return c.join("")}},{name:"falsyPrimitiveStrings",symbols:["falsyPrimitiveStrings$string$5"],postprocess:s},{name:"numericValue",symbols:["int",{literal:"."},"int"],postprocess:o},{name:"numericValue",symbols:[{literal:"+"},"int",{literal:"."},"int"],postprocess:o},{name:"numericValue",symbols:[{literal:"-"},"int",{literal:"."},"int"],postprocess:o},{name:"numericValue",symbols:[{literal:"-"},"int"],postprocess:o},{name:"numericValue",symbols:["int"],postprocess:o},{name:"numericValue",symbols:[{literal:"+"},"int"],postprocess:o},{name:"numericValue$string$1",symbols:[{literal:"I"},{literal:"n"},{literal:"f"},{literal:"i"},{literal:"n"},{literal:"i"},{literal:"t"},{literal:"y"}],postprocess:function(c){return c.join("")}},{name:"numericValue",symbols:["numericValue$string$1"],postprocess:o},{name:"numericValue$string$2",symbols:[{literal:"+"},{literal:"I"},{literal:"n"},{literal:"f"},{literal:"i"},{literal:"n"},{literal:"i"},{literal:"t"},{literal:"y"}],postprocess:function(c){return c.join("")}},{name:"numericValue",symbols:["numericValue$string$2"],postprocess:o},{name:"numericValue$string$3",symbols:[{literal:"-"},{literal:"I"},{literal:"n"},{literal:"f"},{literal:"i"},{literal:"n"},{literal:"i"},{literal:"t"},{literal:"y"}],postprocess:function(c){return c.join("")}},{name:"numericValue",symbols:["numericValue$string$3"],postprocess:o},{name:"int$ebnf$1",symbols:[/[0-9]/]},{name:"int$ebnf$1",symbols:["int$ebnf$1",/[0-9]/],postprocess:function(c){return c[0].concat([c[1]])}},{name:"int",symbols:["int$ebnf$1"]},{name:"classParameters",symbols:[]},{name:"classParameters",symbols:["classParameter"]},{name:"classParameters",symbols:["classParameters",{literal:","},"_","classParameter"],postprocess:i(0,3)},{name:"classParameter$ebnf$1",symbols:[/[^()"', ]/]},{name:"classParameter$ebnf$1",symbols:["classParameter$ebnf$1",/[^()"', ]/],postprocess:function(c){return c[0].concat([c[1]])}},{name:"classParameter",symbols:["classParameter$ebnf$1"],postprocess:function(c){return c[0].join("")}},{name:"classParameter",symbols:["sqstring"],postprocess:e},{name:"classParameter",symbols:["dqstring"],postprocess:e},{name:"pseudoElementSelector$string$1",symbols:[{literal:":"},{literal:":"}],postprocess:function(c){return c.join("")}},{name:"pseudoElementSelector",symbols:["pseudoElementSelector$string$1","pseudoClassSelectorName"],postprocess:function(c){return{type:"pseudoElementSelector",name:c[1]}}},{name:"pseudoClassSelector",symbols:[{literal:":"},"pseudoClassSelectorName"],postprocess:function(c){return{type:"pseudoClassSelector",name:c[1]}}},{name:"pseudoClassSelector",symbols:[{literal:":"},"pseudoClassSelectorName",{literal:"("},"classParameters",{literal:")"}],postprocess:function(c){return{type:"pseudoClassSelector",name:c[1],parameters:c[3]}}},{name:"pseudoClassSelectorName$ebnf$1",symbols:[/[a-zA-Z0-9-_]/]},{name:"pseudoClassSelectorName$ebnf$1",symbols:["pseudoClassSelectorName$ebnf$1",/[a-zA-Z0-9-_]/],postprocess:function(c){return c[0].concat([c[1]])}},{name:"pseudoClassSelectorName",symbols:[/[a-zA-Z]/,"pseudoClassSelectorName$ebnf$1"],postprocess:function(c){return c[0]+c[1].join("")}},{name:"dqstring$ebnf$1",symbols:[]},{name:"dqstring$ebnf$1",symbols:["dqstring$ebnf$1","dstrchar"],postprocess:function(c){return c[0].concat([c[1]])}},{name:"dqstring",symbols:[{literal:'"'},"dqstring$ebnf$1",{literal:'"'}],postprocess:function(c){return c[1].join("")}},{name:"dstrchar",symbols:[/[^"]/],postprocess:e},{name:"dstrchar$string$1",symbols:[{literal:"\\"},{literal:'"'}],postprocess:function(c){return c.join("")}},{name:"dstrchar",symbols:["dstrchar$string$1"],postprocess:function(c){return'"'}},{name:"sqstring$ebnf$1",symbols:[]},{name:"sqstring$ebnf$1",symbols:["sqstring$ebnf$1","sstrchar"],postprocess:function(c){return c[0].concat([c[1]])}},{name:"sqstring",symbols:[{literal:"'"},"sqstring$ebnf$1",{literal:"'"}],postprocess:function(c){return c[1].join("")}},{name:"sstrchar",symbols:[/[^']/],postprocess:e},{name:"sstrchar$string$1",symbols:[{literal:"\\"},{literal:"'"}],postprocess:function(c){return c.join("")}},{name:"sstrchar",symbols:["sstrchar$string$1"],postprocess:function(c){return"'"}},{name:"_$ebnf$1",symbols:[]},{name:"_$ebnf$1",symbols:["_$ebnf$1",/[ ]/],postprocess:function(c){return c[0].concat([c[1]])}},{name:"_",symbols:["_$ebnf$1"],postprocess:function(c){return null}}],ParserStart:"combinator"};g.exports=a})()})(lVe);var OBt=lVe.exports;Object.defineProperty(Vj,"__esModule",{value:!0});var LBt=GBt,_Bt=OBt,VCe=UBt(_Bt);function UBt(g){return g&&g.__esModule?g:{default:g}}Vj.default=function(){var g=function(I){var i=new LBt.Parser(VCe.default.ParserRules,VCe.default.ParserStart),n=i.feed(I).results;if(n.length===0)throw new Error("Found no parsings.");if(n.length>1)throw new Error("Ambiguous results.");return n[0]};return{parse:g}};Object.defineProperty(o0,"__esModule",{value:!0});o0.createParser=o0.createGenerator=void 0;var QBt=wj,jBt=dVe(QBt),$Bt=Vj,qBt=dVe($Bt);function dVe(g){return g&&g.__esModule?g:{default:g}}o0.createGenerator=jBt.default;o0.createParser=qBt.default;var evt=U0,hVe=uC,tvt=hVe("Object.prototype.propertyIsEnumerable"),gvt=hVe("Array.prototype.push"),mVe=function(e){var I=evt(e),i=[];for(var n in I)tvt(I,n)&&gvt(i,I[n]);return i},Ivt=mVe,fVe=function(){return typeof Object.values=="function"?Object.values:Ivt},ivt=fVe,nvt=xn,Cvt=function(){var e=ivt();return nvt(Object,{values:e},{values:function(){return Object.values!==e}}),e},rvt=xn,ovt=ul,Avt=mVe,pVe=fVe,avt=Cvt,bVe=ovt(pVe(),Object);rvt(bVe,{getPolyfill:pVe,implementation:Avt,shim:avt});var svt=bVe,lvt=JBe,cvt=LBe(),uvt=UBe(),dvt=aw,hvt=QBe(),mvt=_Q,fvt=sve(),pvt=EBe,bvt=lve,RCe=UQ,yvt=uC,Zvt=iVe,WCe=Object("a"),Gvt=WCe[0]!=="a"||!(0 in WCe),Bvt=yvt("String.prototype.split"),yVe=function(e){var I=bvt(this),i=Gvt&&Zvt(I)?Bvt(I,""):I,n=fvt(i);if(!mvt(e))throw new TypeError("Array.prototype.filter callback must be a function");var C;arguments.length>1&&(C=arguments[1]);for(var r=lvt(I,0),o=0,A=0;o"u")return!1;if(e.type===RVe)return(0,tSt.default)(C,e.name);if((typeof o!="string"||typeof i!="string")&&I!==HCe)return!1;switch(I){case HCe:return(0,qvt.default)(o,i);case fSt:return o.split(" ").indexOf(i)!==-1;case pSt:return o===i||o.startsWith(String(i)+"-");case bSt:return i===""?!1:o.slice(0,i.length)===i;case ySt:return i===""?!1:o.slice(-i.length)===i;case ZSt:return i===""?!1:o.indexOf(i)!==-1;default:throw new Error('Enzyme::Selector: Unknown attribute selector operator "'+String(I)+'"')}}function GSt(g,e,I){var i=e.name,n=e.parameters;if(i==="not")return n.every(function(c){return Fk(c,g).length===0});if(i==="empty")return(0,rC.treeFilter)(g,function(c){return c!==g}).length===0;if(i==="first-child"){var C=(0,rC.findParentNode)(I,g),r=C.rendered,o=Lvt(r,1),A=o[0];return A===g}if(i==="last-child"){var s=(0,rC.findParentNode)(I,g),a=s.rendered;return a[a.length-1]===g}if(i==="focus"){if(typeof document>"u")throw new Error('Enzyme::Selector does not support the ":focus" pseudo-element without a global `document`.');var l=(0,wVe.default)();return document.activeElement&&l.nodeToHostNode(g)===document.activeElement}throw new TypeError('Enzyme::Selector does not support the "'+String(e.name)+'" pseudo-element or pseudo-class selectors.')}function BSt(g,e,I){if(g===null||typeof g=="string")return!1;switch(e.type){case uSt:return!0;case lSt:return(0,rC.hasClassName)(g,e.name);case sSt:return(0,SVe.nodeHasType)(g,e.name);case cSt:return(0,rC.nodeHasId)(g,e.name);case RVe:return TCe(g,e);case dSt:return TCe(g,e);case mSt:case hSt:return GSt(g,e,I);default:throw new Error("Unknown token type: "+String(e.type))}}function Ez(g,e){return function(I){return g.body.every(function(i){return BSt(I,i,e)})}}function vSt(g){return g.some(function(e){return e.type!==VVe})}function HVe(g){if(typeof g=="string"){var e=XVe(g);if(vSt(e))throw new TypeError("This method does not support complex CSS selectors");return Ez(e[0])}var I=(0,wVe.default)(),i=I.isValidElementType?I.isValidElementType(g):typeof g=="function";if(i)return function(C){return I.matchesElementType(C,g)};if((typeof g>"u"?"undefined":vVe(g))==="object"){if(!Array.isArray(g)&&g!==null&&Object.keys(g).length>0){var n=(0,Qvt.default)(g).some(function(C){return typeof C>"u"});if(n)throw new TypeError("Enzyme::Props can’t have `undefined` values. Try using ‘findWhere()’ instead.");return function(C){return(0,rC.nodeMatchesObjectProps)(C,g)}}throw new TypeError("Enzyme::Selector does not support an array, null, or empty object as a selector")}throw new TypeError("Enzyme::Selector expects a string, object, or valid element type (Component Constructor)")}function SSt(g,e,I){return g.reduce(function(i,n){var C=(0,rC.findParentNode)(I,n);if(!C)return i;var r=(0,rC.childrenOfNode)(C),o=r.indexOf(n),A=r[o+1];return A&&e(A)&&i.push(A),i},[])}function wSt(g,e,I){return Xj(function(i,n){var C=(0,rC.findParentNode)(I,n);if(!C)return i;var r=(0,rC.childrenOfNode)(C),o=r.indexOf(n),A=r.slice(o+1);return i.concat(A.filter(e))},g)}function VSt(g,e){return Xj(function(I,i){return I.concat((0,rC.childrenOfNode)(i).filter(e))},g)}function RSt(g,e){return Xj(function(I,i){return I.concat((0,rC.treeFilter)(i,e))},(0,Wj.default)(g.map(rC.childrenOfNode)))}function Fk(g,e){if(typeof g!="string"){var I=(0,ISt.default)(g);if(I.length>0)return(0,Wj.default)(I.map(function(a){return Fk(a.tag,e)}))}if(typeof g=="function"||(typeof g>"u"?"undefined":vVe(g))==="object")return(0,rC.treeFilter)(e,HVe(g));var i=[];if(typeof g=="string")for(var n=XVe(g),C=0;C2&&arguments[2]!==void 0?arguments[2]:u.treeFilter;return q.flatMap(function(ee){return j(ee.getNodeInternal(),$)})}function H(q,$){return q.wrap(q.getNodesInternal().filter($).filter(Boolean))}function D(q){if(q[B].length!==1)throw new Error("getRootNodeInternal(wrapper) can only be called when wrapper wraps one node");return q[B]!==q?q[R][0]:q[B][y]}function Y(q,$){return(0,u.parentsOfNode)($,D(q))}function F(q,$){$?Array.isArray($)?((0,s.privateSet)(q,y,$[0]),(0,s.privateSet)(q,Z,$)):((0,s.privateSet)(q,y,$),(0,s.privateSet)(q,Z,[$])):((0,s.privateSet)(q,y,null),(0,s.privateSet)(q,Z,[])),(0,s.privateSet)(q,"length",q[Z].length)}var _=function(){function q($,j){var ee=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};if(p(this,q),!globalThis.window&&!globalThis.document)throw new Error("It looks like you called `mount()` without a global document being loaded.");var Q=(0,s.makeOptions)(ee);if(j)(0,s.privateSet)(this,v,j[v]),(0,s.privateSet)(this,B,j),F(this,$),(0,s.privateSet)(this,R,j[Z]),(0,s.privateSet)(this,w,j[w]),(0,s.privateSet)(this,X,[]);else{var ne=(0,l.default)(Q);if(!ne.isValidElement($))throw new TypeError("ReactWrapper can only wrap valid elements");var fe=ne.createRenderer((0,n.default)({mode:"mount"},Q));if((0,s.privateSet)(this,v,fe),fe.render($,Q.context),(0,s.privateSet)(this,B,this),F(this,this[v].getNode()),(0,s.privateSet)(this,w,Q),(0,s.privateSet)(this,X,[]),(0,s.isCustomComponent)(Q.wrappingComponent,ne)){if(typeof this[v].getWrappingComponentRenderer!="function")throw new TypeError("your adapter does not support `wrappingComponent`. Try upgrading it!");(0,s.privateSet)(this,S,new J(this,this[v].getWrappingComponentRenderer())),this[X].push(this[S])}}(0,s.privateSet)(this,G,$),(0,s.privateSet)(this,W,null)}return I(q,[{key:"root",value:function(){function $(){return this[B]}return $}()},{key:"getNodeInternal",value:function(){function $(){if(this.length!==1)throw new Error("ReactWrapper::getNode() can only be called when wrapping one node");return this[Z][0]}return $}()},{key:"getNodesInternal",value:function(){function $(){return this[Z]}return $}()},{key:"getElement",value:function(){function $(){var j=this;return this.single("getElement",function(){return(0,l.default)(j[w]).nodeToElement(j[y])})}return $}()},{key:"getElements",value:function(){function $(){var j=this;return this[Z].map(function(ee){return(0,l.default)(j[w]).nodeToElement(ee)})}return $}()},{key:"getNode",value:function(){function $(){throw new Error("ReactWrapper::getNode() is no longer supported. Use ReactWrapper::instance() instead")}return $}()},{key:"getNodes",value:function(){function $(){throw new Error("ReactWrapper::getNodes() is no longer supported.")}return $}()},{key:"getDOMNode",value:function(){function $(){var j=(0,l.default)(this[w]);return this.single("getDOMNode",function(ee){return j.nodeToHostNode(ee,!0)})}return $}()},{key:"ref",value:function(){function $(j){if(this[B]!==this)throw new Error("ReactWrapper::ref(refname) can only be called on the root");return this.instance().refs[j]}return $}()},{key:"instance",value:function(){function $(){var j=this;return this.single("instance",function(){return j[y].instance})}return $}()},{key:"getWrappingComponent",value:function(){function $(){if(this[B]!==this)throw new Error("ReactWrapper::getWrappingComponent() can only be called on the root");if(!this[w].wrappingComponent)throw new Error("ReactWrapper::getWrappingComponent() can only be called on a wrapper that was originally passed a `wrappingComponent` option");return this[S]}return $}()},{key:"update",value:function(){function $(){var j=this,ee=this[B];return this!==ee?ee.update():(F(this,this[v].getNode()),this[X].forEach(function(Q){if(Q!==j[W]){Q[W]=j;try{Q.update()}finally{Q[W]=null}}}),this)}return $}()},{key:"unmount",value:function(){function $(){var j=this;if(this[B]!==this)throw new Error("ReactWrapper::unmount() can only be called on the root");return this.single("unmount",function(){j[v].unmount(),j.update()}),this}return $}()},{key:"mount",value:function(){function $(){var j=this;if(this[B]!==this)throw new Error("ReactWrapper::mount() can only be called on the root");return this[v].render(this[G],this[w].context,function(){return j.update()}),this}return $}()},{key:"setProps",value:function(){function $(j){var ee=this,Q=arguments.length>1&&arguments[1]!==void 0?arguments[1]:void 0;if(this[B]!==this)throw new Error("ReactWrapper::setProps() can only be called on the root");if(arguments.length>1&&typeof Q!="function")throw new TypeError("ReactWrapper::setProps() expects a function as its second argument");var ne=(0,l.default)(this[w]);return this[G]=(0,s.cloneElement)(ne,this[G],j),this[v].render(this[G],null,function(){ee.update(),Q&&Q()}),this}return $}()},{key:"setState",value:function(){function $(j){var ee=this,Q=arguments.length>1&&arguments[1]!==void 0?arguments[1]:void 0;if(this.instance()===null||this.getNodeInternal().nodeType!=="class")throw new Error("ReactWrapper::setState() can only be called on class components");if(arguments.length>1&&typeof Q!="function")throw new TypeError("ReactWrapper::setState() expects a function as its second argument");return this.instance().setState(j,function(){if(ee.update(),Q){var ne=(0,l.default)(ee[w]),fe=ee.instance();ne.invokeSetStateCallback?ne.invokeSetStateCallback(fe,Q):Q.call(fe)}}),this}return $}()},{key:"setContext",value:function(){function $(j){var ee=this;if(this[B]!==this)throw new Error("ReactWrapper::setContext() can only be called on the root");if(!this[w].context)throw new Error("ReactWrapper::setContext() can only be called on a wrapper that was originally passed a context option");return this[v].render(this[G],j,function(){return ee.update()}),this}return $}()},{key:"contains",value:function(){function $(j){var ee=(0,l.default)(this[w]),Q=Array.isArray(j)?function(ne){return(0,s.containsChildrenSubArray)(s.nodeEqual,ne,j.map(function(fe){return ee.elementToNode(fe)}))}:function(ne){return(0,s.nodeEqual)(ee.elementToNode(j),ne)};return V(this,Q).length>0}return $}()},{key:"containsMatchingElement",value:function(){function $(j){var ee=(0,l.default)(this[w]).elementToNode(j),Q=function(){function ne(fe){return(0,s.nodeMatches)(ee,fe,function(Ce,Ze){return Ce<=Ze})}return ne}();return V(this,Q).length>0}return $}()},{key:"containsAllMatchingElements",value:function(){function $(j){var ee=this;if(!Array.isArray(j))throw new TypeError("nodes should be an Array");return j.every(function(Q){return ee.containsMatchingElement(Q)})}return $}()},{key:"containsAnyMatchingElements",value:function(){function $(j){var ee=this;return Array.isArray(j)&&j.some(function(Q){return ee.containsMatchingElement(Q)})}return $}()},{key:"equals",value:function(){function $(j){var ee=this;return this.single("equals",function(){return(0,s.nodeEqual)(ee.getNodeInternal(),j)})}return $}()},{key:"matchesElement",value:function(){function $(j){var ee=this;return this.single("matchesElement",function(){var Q=(0,l.default)(ee[w]),ne=Q.elementToNode(j);return(0,s.nodeMatches)(ne,ee.getNodeInternal(),function(fe,Ce){return fe<=Ce})})}return $}()},{key:"find",value:function(){function $(j){return this.wrap((0,d.reduceTreesBySelector)(j,this.getNodesInternal()))}return $}()},{key:"is",value:function(){function $(j){var ee=(0,d.buildPredicate)(j);return this.single("is",function(Q){return ee(Q)})}return $}()},{key:"isEmptyRender",value:function(){function $(){var j=this.getNodeInternal();return(0,s.renderedDive)(j)}return $}()},{key:"filterWhere",value:function(){function $(j){var ee=this;return H(this,function(Q){return j(ee.wrap(Q))})}return $}()},{key:"filter",value:function(){function $(j){var ee=(0,d.buildPredicate)(j);return H(this,ee)}return $}()},{key:"not",value:function(){function $(j){var ee=(0,d.buildPredicate)(j);return H(this,function(Q){return!ee(Q)})}return $}()},{key:"text",value:function(){function $(){var j=(0,l.default)(this[w]);return this.single("text",function(ee){return(0,u.getTextFromHostNodes)(ee,j)})}return $}()},{key:"html",value:function(){function $(){var j=(0,l.default)(this[w]);return this.single("html",function(ee){return(0,u.getHTMLFromHostNodes)(ee,j)})}return $}()},{key:"render",value:function(){function $(){var j=this.html();return(0,s.loadCheerioRoot)(j)}return $}()},{key:"simulate",value:function(){function $(j){var ee=this,Q=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return this.single("simulate",function(ne){return ee[v].simulateEvent(ne,j,Q),ee[B].update(),ee})}return $}()},{key:"simulateError",value:function(){function $(j){var ee=this;if(this[B]===this)throw new Error("ReactWrapper::simulateError() may not be called on the root");return this.single("simulateError",function(Q){if(Q.nodeType==="host")throw new Error("ReactWrapper::simulateError() can only be called on custom components");var ne=ee[v];if(typeof ne.simulateError!="function")throw new TypeError("your adapter does not support `simulateError`. Try upgrading it!");var fe=D(ee),Ce=[Q].concat(Y(ee,Q));return ne.simulateError(Ce,fe,j),ee[B].update(),ee})}return $}()},{key:"props",value:function(){function $(){return this.single("props",u.propsOfNode)}return $}()},{key:"state",value:function(){function $(j){var ee=this,Q=this[B]===this?this[v].getNode():this.getNodeInternal();if(this.instance()===null||Q.nodeType!=="class")throw new Error("ReactWrapper::state() can only be called on class components");var ne=this.single("state",function(){return ee.instance().state});if(typeof j<"u"){if(ne==null)throw new TypeError('ReactWrapper::state("'+String(j)+'") requires that `state` not be `null` or `undefined`');return ne[j]}return ne}return $}()},{key:"context",value:function(){function $(j){var ee=this;if(this[B]!==this)throw new Error("ReactWrapper::context() can only be called on the root");var Q=this.single("context",function(){return ee.instance()});if(Q===null)throw new Error("ReactWrapper::context() can only be called on components with instances");var ne=Q.context;return typeof j<"u"?ne[j]:ne}return $}()},{key:"children",value:function(){function $(j){var ee=this.flatMap(function(Q){return(0,u.childrenOfNode)(Q.getNodeInternal())});return j?ee.filter(j):ee}return $}()},{key:"childAt",value:function(){function $(j){var ee=this;return this.single("childAt",function(){return ee.children().at(j)})}return $}()},{key:"parents",value:function(){function $(j){var ee=this;return this.single("parents",function(Q){var ne=ee.wrap(Y(ee,Q));return j?ne.filter(j):ne})}return $}()},{key:"parent",value:function(){function $(){return this.flatMap(function(j){return[j.parents().get(0)]})}return $}()},{key:"closest",value:function(){function $(j){if(this.is(j))return this;var ee=this.parents().filter(j);return ee.length>0?ee.first():this.findWhere(function(){return!1})}return $}()},{key:"prop",value:function(){function $(j){return this.props()[j]}return $}()},{key:"invoke",value:function(){function $(j){var ee=this;return this.single("invoke",function(){var Q=ee.prop(j);if(typeof Q!="function")throw new TypeError("ReactWrapper::invoke() requires the name of a prop whose value is a function");return function(){for(var ne=arguments.length,fe=Array(ne),Ce=0;Ce"u"?"undefined":e(Ce))+"“");return function(){var Ze=Ce.apply(void 0,arguments),Ge=Q.wrap(Ze);return ee.wrap(Ge,null,ee[w])}})}return $}()},{key:"key",value:function(){function $(){return this.single("key",function(j){return j.key===void 0?null:j.key})}return $}()},{key:"type",value:function(){function $(){return this.single("type",function(j){return(0,s.typeOfNode)(j)})}return $}()},{key:"name",value:function(){function $(){var j=(0,l.default)(this[w]);return this.single("name",function(ee){return j.displayNameOfNode?j.displayNameOfNode(ee):(0,s.displayNameOfNode)(ee)})}return $}()},{key:"hasClass",value:function(){function $(j){return typeof j=="string"&&j.indexOf(".")!==-1&&console.warn("It looks like you're calling `ReactWrapper::hasClass()` with a CSS selector. hasClass() expects a class name, not a CSS selector."),this.single("hasClass",function(ee){return(0,u.hasClassName)(ee,j)})}return $}()},{key:"forEach",value:function(){function $(j){var ee=this;return this.getNodesInternal().forEach(function(Q,ne){return j.call(ee,ee.wrap(Q),ne)}),this}return $}()},{key:"map",value:function(){function $(j){var ee=this;return this.getNodesInternal().map(function(Q,ne){return j.call(ee,ee.wrap(Q),ne)})}return $}()},{key:"reduce",value:function(){function $(j){var ee=this,Q=arguments.length>1&&arguments[1]!==void 0?arguments[1]:void 0;return arguments.length>1?this.getNodesInternal().reduce(function(ne,fe,Ce){return j.call(ee,ne,ee.wrap(fe),Ce)},Q):this.getNodesInternal().reduce(function(ne,fe,Ce){return j.call(ee,Ce===1?ee.wrap(ne):ne,ee.wrap(fe),Ce)})}return $}()},{key:"reduceRight",value:function(){function $(j){var ee=this,Q=arguments.length>1&&arguments[1]!==void 0?arguments[1]:void 0;return arguments.length>1?this.getNodesInternal().reduceRight(function(ne,fe,Ce){return j.call(ee,ne,ee.wrap(fe),Ce)},Q):this.getNodesInternal().reduceRight(function(ne,fe,Ce){return j.call(ee,Ce===1?ee.wrap(ne):ne,ee.wrap(fe),Ce)})}return $}()},{key:"slice",value:function(){function $(j,ee){return this.wrap(this.getNodesInternal().slice(j,ee))}return $}()},{key:"some",value:function(){function $(j){if(this[B]===this)throw new Error("ReactWrapper::some() can not be called on the root");var ee=(0,d.buildPredicate)(j);return this.getNodesInternal().some(ee)}return $}()},{key:"someWhere",value:function(){function $(j){var ee=this;return this.getNodesInternal().some(function(Q,ne){return j.call(ee,ee.wrap(Q),ne)})}return $}()},{key:"every",value:function(){function $(j){var ee=(0,d.buildPredicate)(j);return this.getNodesInternal().every(ee)}return $}()},{key:"everyWhere",value:function(){function $(j){var ee=this;return this.getNodesInternal().every(function(Q,ne){return j.call(ee,ee.wrap(Q),ne)})}return $}()},{key:"flatMap",value:function(){function $(j){var ee=this,Q=this.getNodesInternal().map(function(fe,Ce){return j.call(ee,ee.wrap(fe),Ce)}),ne=(0,r.default)(Q,1);return this.wrap(ne.filter(Boolean))}return $}()},{key:"findWhere",value:function(){function $(j){var ee=this;return V(this,function(Q){var ne=ee.wrap(Q);return ne.length>0&&j(ne)})}return $}()},{key:"get",value:function(){function $(j){return this.getElements()[j]}return $}()},{key:"at",value:function(){function $(j){var ee=this.getNodesInternal();return j0&&arguments[0]!==void 0?arguments[0]:null;return arguments.length>0?this.find(j).exists():this.length>0}return $}()},{key:"single",value:function(){function $(j,ee){var Q=typeof j=="string"?j:"unknown",ne=typeof ee=="function"?ee:j;if(this.length!==1)throw new Error("Method “"+Q+"” is meant to be run on 1 node. "+String(this.length)+" found instead.");return ne.call(this,this.getNodeInternal())}return $}()},{key:"wrap",value:function(){function $(j){var ee=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this[B];if(j instanceof q)return j;for(var Q=arguments.length,ne=Array(Q>2?Q-2:0),fe=2;fe0&&arguments[0]!==void 0?arguments[0]:{};return(0,c.debugNodes)(this.getNodesInternal(),j)}return $}()},{key:"tap",value:function(){function $(j){return j(this),this}return $}()},{key:"detach",value:function(){function $(){if(this[B]!==this)throw new Error("ReactWrapper::detach() can only be called on the root");if(!this[w].attachTo)throw new Error("ReactWrapper::detach() can only be called on when the `attachTo` option was passed into `mount()`.");this[v].unmount()}return $}()},{key:"hostNodes",value:function(){function $(){return this.filterWhere(function(j){return typeof j.type()=="string"})}return $}()}]),q}(),J=function(q){b($,q);function $(j,ee){p(this,$);var Q=f(this,($.__proto__||Object.getPrototypeOf($)).call(this,ee.getNode(),j));return(0,s.privateSet)(Q,B,Q),(0,s.privateSet)(Q,v,ee),Q[X].push(j),Q}return I($,[{key:"getWrappingComponent",value:function(){function j(){throw new TypeError("ReactWrapper::getWrappingComponent() can only be called on the root")}return j}()}]),$}(_);s.ITERATOR_SYMBOL&&Object.defineProperty(_.prototype,s.ITERATOR_SYMBOL,{configurable:!0,value:function(){function q(){var $,j=this[Z][s.ITERATOR_SYMBOL](),ee=(0,l.default)(this[w]);return $={},m($,s.ITERATOR_SYMBOL,function(){return this}),m($,"next",function(){function Q(){var ne=j.next();return ne.done?{done:!0}:{done:!1,value:ee.nodeToElement(ne.value)}}return Q}()),$}return q}()});function te(q,$){Object.defineProperty(_.prototype,q,{get:function(){function j(){throw new Error(` +`)},r.prototype.displayStateStack=function(s,a){for(var l,c=0,u=0;u0&&a.push(" ^ "+c+" more lines identical to this"),c=0,a.push(" "+h)),l=h}},r.prototype.getSymbolDisplay=function(s){return o(s)},r.prototype.buildFirstStateStack=function(s,a){if(a.indexOf(s)!==-1)return null;if(s.wantedBy.length===0)return[s];var l=s.wantedBy[0],c=[s].concat(a),u=this.buildFirstStateStack(l,c);return u===null?null:[s].concat(u)},r.prototype.save=function(){var s=this.table[this.current];return s.lexerState=this.lexerState,s},r.prototype.restore=function(s){var a=s.index;this.current=a,this.table[a]=s,this.table.splice(a+1),this.lexerState=s.lexerState,this.results=this.finish()},r.prototype.rewind=function(s){if(!this.options.keepHistory)throw new Error("set option `keepHistory` to enable rewinding");this.restore(this.table[s])},r.prototype.finish=function(){var s=[],a=this.grammar.start,l=this.table[this.table.length-1];return l.states.forEach(function(c){c.rule.name===a&&c.dot===c.rule.symbols.length&&c.reference===0&&c.data!==r.fail&&s.push(c)}),s.map(function(c){return c.data})};function o(s){var a=typeof s;if(a==="string")return s;if(a==="object"){if(s.literal)return JSON.stringify(s.literal);if(s instanceof RegExp)return"character matching "+s;if(s.type)return s.type+" token";if(s.test)return"token matching "+String(s.test);throw new Error("Unknown symbol type: "+s)}}function A(s){var a=typeof s;if(a==="string")return s;if(a==="object"){if(s.literal)return JSON.stringify(s.literal);if(s instanceof RegExp)return s.toString();if(s.type)return"%"+s.type;if(s.test)return"<"+String(s.test)+">";throw new Error("Unknown symbol type: "+s)}}return{Parser:r,Grammar:n,Rule:g}})})(twe);var tSt=twe.exports,gwe={exports:{}},gSt=1/0,ISt=9007199254740991,iSt="[object Arguments]",nSt="[object Function]",CSt="[object GeneratorFunction]",rSt=typeof globalThis=="object"&&globalThis&&globalThis.Object===Object&&globalThis,oSt=typeof self=="object"&&self&&self.Object===Object&&self,ASt=rSt||oSt||Function("return this")();function aSt(e,g){for(var I=-1,i=g.length,n=e.length;++I0&&I(o)?g>1?iwe(o,g-1,I,i,n):aSt(n,o):i||(n[n.length]=o)}return n}function cSt(e){return hSt(e)||dSt(e)||!!(Mne&&e&&e[Mne])}function uSt(e){var g=e?e.length:0;return g?iwe(e,gSt):[]}function dSt(e){return fSt(e)&&sSt.call(e,"callee")&&(!lSt.call(e,"callee")||Iwe.call(e)==iSt)}var hSt=Array.isArray;function mSt(e){return e!=null&&bSt(e.length)&&!pSt(e)}function fSt(e){return ZSt(e)&&mSt(e)}function pSt(e){var g=ySt(e)?Iwe.call(e):"";return g==nSt||g==CSt}function bSt(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=ISt}function ySt(e){var g=typeof e;return!!e&&(g=="object"||g=="function")}function ZSt(e){return!!e&&typeof e=="object"}var GSt=uSt;(function(e){(function(){function g(l){return l[0]}var I=GSt,i=function(c,u){return function(d){return d[c].concat([d[u]])}},n=function(c){return c=c.filter(function(u){return u!==null}),I(c)},C={" ":"descendantCombinator","+":"adjacentSiblingCombinator",">":"childCombinator","~":"generalSiblingCombinator"},r=function(c){return(Array.isArray(c[0])?c[0]:[c[0]]).concat({type:C[c[2]]}).concat(c[4])},o=function(c,u,d){var h=I(c).join(""),m=parseFloat(h);return isNaN(m)?d:m},A=function(c,u,d){return c[0]==="true"?!0:c[0]==="false"?!1:d},s=function(c,u,d){if(c[0]==="NaN")return NaN;if(c[0]!=="undefined")return c[0]==="null"?null:d},a={Lexer:void 0,ParserRules:[{name:"combinator",symbols:["selector"]},{name:"combinator",symbols:["combinator","_",/[>+~ ]/,"_","selector"],postprocess:r},{name:"selector",symbols:["selectorBody"],postprocess:function(c){return{type:"selector",body:c[0]}}},{name:"selectorBody$ebnf$1",symbols:["typeSelector"],postprocess:g},{name:"selectorBody$ebnf$1",symbols:[],postprocess:function(c){return null}},{name:"selectorBody$ebnf$2",symbols:[]},{name:"selectorBody$ebnf$2",symbols:["selectorBody$ebnf$2","simpleSelector"],postprocess:function(c){return c[0].concat([c[1]])}},{name:"selectorBody",symbols:["selectorBody$ebnf$1","selectorBody$ebnf$2"],postprocess:function(c,u,d){var h=n(c);return h.length?h:d}},{name:"selectorBody$ebnf$3",symbols:[]},{name:"selectorBody$ebnf$3",symbols:["selectorBody$ebnf$3","simpleSelector"],postprocess:function(c){return c[0].concat([c[1]])}},{name:"selectorBody",symbols:["universalSelector","selectorBody$ebnf$3"],postprocess:n},{name:"simpleSelector",symbols:["idSelector"]},{name:"simpleSelector",symbols:["classSelector"]},{name:"simpleSelector",symbols:["attributeValueSelector"]},{name:"simpleSelector",symbols:["attributePresenceSelector"]},{name:"simpleSelector",symbols:["pseudoClassSelector"]},{name:"simpleSelector",symbols:["pseudoElementSelector"]},{name:"typeSelector",symbols:["attributeName"],postprocess:function(c){return{type:"typeSelector",name:c[0]}}},{name:"className$ebnf$1",symbols:[{literal:"-"}],postprocess:g},{name:"className$ebnf$1",symbols:[],postprocess:function(c){return null}},{name:"className$ebnf$2",symbols:[]},{name:"className$ebnf$2",symbols:["className$ebnf$2",/[_a-zA-Z0-9-]/],postprocess:function(c){return c[0].concat([c[1]])}},{name:"className",symbols:["className$ebnf$1",/[_a-zA-Z]/,"className$ebnf$2"],postprocess:function(c){return(c[0]||"")+c[1]+c[2].join("")}},{name:"attributeName$ebnf$1",symbols:[]},{name:"attributeName$ebnf$1",symbols:["attributeName$ebnf$1",/[_a-zA-Z()0-9-]/],postprocess:function(c){return c[0].concat([c[1]])}},{name:"attributeName",symbols:[/[_a-z()A-Z]/,"attributeName$ebnf$1"],postprocess:function(c){return c[0]+c[1].join("")}},{name:"classSelector",symbols:[{literal:"."},"className"],postprocess:function(c){return{type:"classSelector",name:c[1]}}},{name:"idSelector",symbols:[{literal:"#"},"attributeName"],postprocess:function(c){return{type:"idSelector",name:c[1]}}},{name:"universalSelector",symbols:[{literal:"*"}],postprocess:function(c){return{type:"universalSelector"}}},{name:"attributePresenceSelector",symbols:[{literal:"["},"attributeName",{literal:"]"}],postprocess:function(c){return{type:"attributePresenceSelector",name:c[1]}}},{name:"attributeOperator",symbols:[{literal:"="}]},{name:"attributeOperator$string$1",symbols:[{literal:"~"},{literal:"="}],postprocess:function(c){return c.join("")}},{name:"attributeOperator",symbols:["attributeOperator$string$1"]},{name:"attributeOperator$string$2",symbols:[{literal:"|"},{literal:"="}],postprocess:function(c){return c.join("")}},{name:"attributeOperator",symbols:["attributeOperator$string$2"]},{name:"attributeOperator$string$3",symbols:[{literal:"^"},{literal:"="}],postprocess:function(c){return c.join("")}},{name:"attributeOperator",symbols:["attributeOperator$string$3"]},{name:"attributeOperator$string$4",symbols:[{literal:"$"},{literal:"="}],postprocess:function(c){return c.join("")}},{name:"attributeOperator",symbols:["attributeOperator$string$4"]},{name:"attributeOperator$string$5",symbols:[{literal:"*"},{literal:"="}],postprocess:function(c){return c.join("")}},{name:"attributeOperator",symbols:["attributeOperator$string$5"]},{name:"attributeValueSelector",symbols:[{literal:"["},"attributeName","attributeOperator","attributeValue",{literal:"]"}],postprocess:function(c){return{type:"attributeValueSelector",name:c[1],value:c[3],operator:c[2][0]}}},{name:"attributeValue",symbols:["falsyPrimitiveStrings"],postprocess:g},{name:"attributeValue",symbols:["numericValue"],postprocess:g},{name:"attributeValue",symbols:["sqstring"],postprocess:g},{name:"attributeValue",symbols:["dqstring"],postprocess:g},{name:"falsyPrimitiveStrings$string$1",symbols:[{literal:"f"},{literal:"a"},{literal:"l"},{literal:"s"},{literal:"e"}],postprocess:function(c){return c.join("")}},{name:"falsyPrimitiveStrings",symbols:["falsyPrimitiveStrings$string$1"],postprocess:A},{name:"falsyPrimitiveStrings$string$2",symbols:[{literal:"t"},{literal:"r"},{literal:"u"},{literal:"e"}],postprocess:function(c){return c.join("")}},{name:"falsyPrimitiveStrings",symbols:["falsyPrimitiveStrings$string$2"],postprocess:A},{name:"falsyPrimitiveStrings$string$3",symbols:[{literal:"N"},{literal:"a"},{literal:"N"}],postprocess:function(c){return c.join("")}},{name:"falsyPrimitiveStrings",symbols:["falsyPrimitiveStrings$string$3"],postprocess:s},{name:"falsyPrimitiveStrings$string$4",symbols:[{literal:"n"},{literal:"u"},{literal:"l"},{literal:"l"}],postprocess:function(c){return c.join("")}},{name:"falsyPrimitiveStrings",symbols:["falsyPrimitiveStrings$string$4"],postprocess:s},{name:"falsyPrimitiveStrings$string$5",symbols:[{literal:"u"},{literal:"n"},{literal:"d"},{literal:"e"},{literal:"f"},{literal:"i"},{literal:"n"},{literal:"e"},{literal:"d"}],postprocess:function(c){return c.join("")}},{name:"falsyPrimitiveStrings",symbols:["falsyPrimitiveStrings$string$5"],postprocess:s},{name:"numericValue",symbols:["int",{literal:"."},"int"],postprocess:o},{name:"numericValue",symbols:[{literal:"+"},"int",{literal:"."},"int"],postprocess:o},{name:"numericValue",symbols:[{literal:"-"},"int",{literal:"."},"int"],postprocess:o},{name:"numericValue",symbols:[{literal:"-"},"int"],postprocess:o},{name:"numericValue",symbols:["int"],postprocess:o},{name:"numericValue",symbols:[{literal:"+"},"int"],postprocess:o},{name:"numericValue$string$1",symbols:[{literal:"I"},{literal:"n"},{literal:"f"},{literal:"i"},{literal:"n"},{literal:"i"},{literal:"t"},{literal:"y"}],postprocess:function(c){return c.join("")}},{name:"numericValue",symbols:["numericValue$string$1"],postprocess:o},{name:"numericValue$string$2",symbols:[{literal:"+"},{literal:"I"},{literal:"n"},{literal:"f"},{literal:"i"},{literal:"n"},{literal:"i"},{literal:"t"},{literal:"y"}],postprocess:function(c){return c.join("")}},{name:"numericValue",symbols:["numericValue$string$2"],postprocess:o},{name:"numericValue$string$3",symbols:[{literal:"-"},{literal:"I"},{literal:"n"},{literal:"f"},{literal:"i"},{literal:"n"},{literal:"i"},{literal:"t"},{literal:"y"}],postprocess:function(c){return c.join("")}},{name:"numericValue",symbols:["numericValue$string$3"],postprocess:o},{name:"int$ebnf$1",symbols:[/[0-9]/]},{name:"int$ebnf$1",symbols:["int$ebnf$1",/[0-9]/],postprocess:function(c){return c[0].concat([c[1]])}},{name:"int",symbols:["int$ebnf$1"]},{name:"classParameters",symbols:[]},{name:"classParameters",symbols:["classParameter"]},{name:"classParameters",symbols:["classParameters",{literal:","},"_","classParameter"],postprocess:i(0,3)},{name:"classParameter$ebnf$1",symbols:[/[^()"', ]/]},{name:"classParameter$ebnf$1",symbols:["classParameter$ebnf$1",/[^()"', ]/],postprocess:function(c){return c[0].concat([c[1]])}},{name:"classParameter",symbols:["classParameter$ebnf$1"],postprocess:function(c){return c[0].join("")}},{name:"classParameter",symbols:["sqstring"],postprocess:g},{name:"classParameter",symbols:["dqstring"],postprocess:g},{name:"pseudoElementSelector$string$1",symbols:[{literal:":"},{literal:":"}],postprocess:function(c){return c.join("")}},{name:"pseudoElementSelector",symbols:["pseudoElementSelector$string$1","pseudoClassSelectorName"],postprocess:function(c){return{type:"pseudoElementSelector",name:c[1]}}},{name:"pseudoClassSelector",symbols:[{literal:":"},"pseudoClassSelectorName"],postprocess:function(c){return{type:"pseudoClassSelector",name:c[1]}}},{name:"pseudoClassSelector",symbols:[{literal:":"},"pseudoClassSelectorName",{literal:"("},"classParameters",{literal:")"}],postprocess:function(c){return{type:"pseudoClassSelector",name:c[1],parameters:c[3]}}},{name:"pseudoClassSelectorName$ebnf$1",symbols:[/[a-zA-Z0-9-_]/]},{name:"pseudoClassSelectorName$ebnf$1",symbols:["pseudoClassSelectorName$ebnf$1",/[a-zA-Z0-9-_]/],postprocess:function(c){return c[0].concat([c[1]])}},{name:"pseudoClassSelectorName",symbols:[/[a-zA-Z]/,"pseudoClassSelectorName$ebnf$1"],postprocess:function(c){return c[0]+c[1].join("")}},{name:"dqstring$ebnf$1",symbols:[]},{name:"dqstring$ebnf$1",symbols:["dqstring$ebnf$1","dstrchar"],postprocess:function(c){return c[0].concat([c[1]])}},{name:"dqstring",symbols:[{literal:'"'},"dqstring$ebnf$1",{literal:'"'}],postprocess:function(c){return c[1].join("")}},{name:"dstrchar",symbols:[/[^"]/],postprocess:g},{name:"dstrchar$string$1",symbols:[{literal:"\\"},{literal:'"'}],postprocess:function(c){return c.join("")}},{name:"dstrchar",symbols:["dstrchar$string$1"],postprocess:function(c){return'"'}},{name:"sqstring$ebnf$1",symbols:[]},{name:"sqstring$ebnf$1",symbols:["sqstring$ebnf$1","sstrchar"],postprocess:function(c){return c[0].concat([c[1]])}},{name:"sqstring",symbols:[{literal:"'"},"sqstring$ebnf$1",{literal:"'"}],postprocess:function(c){return c[1].join("")}},{name:"sstrchar",symbols:[/[^']/],postprocess:g},{name:"sstrchar$string$1",symbols:[{literal:"\\"},{literal:"'"}],postprocess:function(c){return c.join("")}},{name:"sstrchar",symbols:["sstrchar$string$1"],postprocess:function(c){return"'"}},{name:"_$ebnf$1",symbols:[]},{name:"_$ebnf$1",symbols:["_$ebnf$1",/[ ]/],postprocess:function(c){return c[0].concat([c[1]])}},{name:"_",symbols:["_$ebnf$1"],postprocess:function(c){return null}}],ParserStart:"combinator"};e.exports=a})()})(gwe);var vSt=gwe.exports;Object.defineProperty(UQ,"__esModule",{value:!0});var BSt=tSt,SSt=vSt,zne=wSt(SSt);function wSt(e){return e&&e.__esModule?e:{default:e}}UQ.default=function(){var e=function(I){var i=new BSt.Parser(zne.default.ParserRules,zne.default.ParserStart),n=i.feed(I).results;if(n.length===0)throw new Error("Found no parsings.");if(n.length>1)throw new Error("Ambiguous results.");return n[0]};return{parse:e}};Object.defineProperty(Eb,"__esModule",{value:!0});Eb.createParser=Eb.createGenerator=void 0;var VSt=LQ,RSt=nwe(VSt),WSt=UQ,XSt=nwe(WSt);function nwe(e){return e&&e.__esModule?e:{default:e}}Eb.createGenerator=RSt.default;Eb.createParser=XSt.default;var HSt=W0,Cwe=sC,TSt=Cwe("Object.prototype.propertyIsEnumerable"),NSt=Cwe("Array.prototype.push"),rwe=function(g){var I=HSt(g),i=[];for(var n in I)TSt(I,n)&&NSt(i,I[n]);return i},kSt=rwe,owe=function(){return typeof Object.values=="function"?Object.values:kSt},YSt=owe,KSt=Yn,DSt=function(){var g=YSt();return KSt(Object,{values:g},{values:function(){return Object.values!==g}}),g},xSt=Yn,FSt=js,ESt=rwe,Awe=owe,MSt=DSt,awe=FSt(Awe(),Object);xSt(awe,{getPolyfill:Awe,implementation:ESt,shim:MSt});var zSt=awe,PSt=kGe,JSt=KGe(),OSt=xGe(),_St=XS,LSt=FGe(),USt=dQ,QSt=tve(),jSt=XGe,$St=gve,Pne=hQ,qSt=sC,ewt=LSe,Jne=Object("a"),twt=Jne[0]!=="a"||!(0 in Jne),gwt=qSt("String.prototype.split"),swe=function(g){var I=$St(this),i=twt&&ewt(I)?gwt(I,""):I,n=QSt(i);if(!USt(g))throw new TypeError("Array.prototype.filter callback must be a function");var C;arguments.length>1&&(C=arguments[1]);for(var r=PSt(I,0),o=0,A=0;o"u")return!1;if(g.type===pwe)return(0,Twt.default)(C,g.name);if((typeof o!="string"||typeof i!="string")&&I!==_ne)return!1;switch(I){case _ne:return(0,Xwt.default)(o,i);case Qwt:return o.split(" ").indexOf(i)!==-1;case jwt:return o===i||o.startsWith(String(i)+"-");case $wt:return i===""?!1:o.slice(0,i.length)===i;case qwt:return i===""?!1:o.slice(-i.length)===i;case eVt:return i===""?!1:o.indexOf(i)!==-1;default:throw new Error('Enzyme::Selector: Unknown attribute selector operator "'+String(I)+'"')}}function tVt(e,g,I){var i=g.name,n=g.parameters;if(i==="not")return n.every(function(c){return LN(c,e).length===0});if(i==="empty")return(0,iC.treeFilter)(e,function(c){return c!==e}).length===0;if(i==="first-child"){var C=(0,iC.findParentNode)(I,e),r=C.rendered,o=Bwt(r,1),A=o[0];return A===e}if(i==="last-child"){var s=(0,iC.findParentNode)(I,e),a=s.rendered;return a[a.length-1]===e}if(i==="focus"){if(typeof document>"u")throw new Error('Enzyme::Selector does not support the ":focus" pseudo-element without a global `document`.');var l=(0,mwe.default)();return document.activeElement&&l.nodeToHostNode(e)===document.activeElement}throw new TypeError('Enzyme::Selector does not support the "'+String(g.name)+'" pseudo-element or pseudo-class selectors.')}function gVt(e,g,I){if(e===null||typeof e=="string")return!1;switch(g.type){case Owt:return!0;case Pwt:return(0,iC.hasClassName)(e,g.name);case zwt:return(0,hwe.nodeHasType)(e,g.name);case Jwt:return(0,iC.nodeHasId)(e,g.name);case pwe:return Lne(e,g);case _wt:return Lne(e,g);case Uwt:case Lwt:return tVt(e,g,I);default:throw new Error("Unknown token type: "+String(g.type))}}function Cz(e,g){return function(I){return e.body.every(function(i){return gVt(I,i,g)})}}function IVt(e){return e.some(function(g){return g.type!==fwe})}function Zwe(e){if(typeof e=="string"){var g=ywe(e);if(IVt(g))throw new TypeError("This method does not support complex CSS selectors");return Cz(g[0])}var I=(0,mwe.default)(),i=I.isValidElementType?I.isValidElementType(e):typeof e=="function";if(i)return function(C){return I.matchesElementType(C,e)};if((typeof e>"u"?"undefined":dwe(e))==="object"){if(!Array.isArray(e)&&e!==null&&Object.keys(e).length>0){var n=(0,Vwt.default)(e).some(function(C){return typeof C>"u"});if(n)throw new TypeError("Enzyme::Props can’t have `undefined` values. Try using ‘findWhere()’ instead.");return function(C){return(0,iC.nodeMatchesObjectProps)(C,e)}}throw new TypeError("Enzyme::Selector does not support an array, null, or empty object as a selector")}throw new TypeError("Enzyme::Selector expects a string, object, or valid element type (Component Constructor)")}function iVt(e,g,I){return e.reduce(function(i,n){var C=(0,iC.findParentNode)(I,n);if(!C)return i;var r=(0,iC.childrenOfNode)(C),o=r.indexOf(n),A=r[o+1];return A&&g(A)&&i.push(A),i},[])}function nVt(e,g,I){return $Q(function(i,n){var C=(0,iC.findParentNode)(I,n);if(!C)return i;var r=(0,iC.childrenOfNode)(C),o=r.indexOf(n),A=r.slice(o+1);return i.concat(A.filter(g))},e)}function CVt(e,g){return $Q(function(I,i){return I.concat((0,iC.childrenOfNode)(i).filter(g))},e)}function rVt(e,g){return $Q(function(I,i){return I.concat((0,iC.treeFilter)(i,g))},(0,jQ.default)(e.map(iC.childrenOfNode)))}function LN(e,g){if(typeof e!="string"){var I=(0,kwt.default)(e);if(I.length>0)return(0,jQ.default)(I.map(function(a){return LN(a.tag,g)}))}if(typeof e=="function"||(typeof e>"u"?"undefined":dwe(e))==="object")return(0,iC.treeFilter)(g,Zwe(e));var i=[];if(typeof e=="string")for(var n=ywe(e),C=0;C2&&arguments[2]!==void 0?arguments[2]:u.treeFilter;return q.flatMap(function(te){return j(te.getNodeInternal(),$)})}function H(q,$){return q.wrap(q.getNodesInternal().filter($).filter(Boolean))}function Y(q){if(q[v].length!==1)throw new Error("getRootNodeInternal(wrapper) can only be called when wrapper wraps one node");return q[v]!==q?q[V][0]:q[v][y]}function D(q,$){return(0,u.parentsOfNode)($,Y(q))}function E(q,$){$?Array.isArray($)?((0,s.privateSet)(q,y,$[0]),(0,s.privateSet)(q,Z,$)):((0,s.privateSet)(q,y,$),(0,s.privateSet)(q,Z,[$])):((0,s.privateSet)(q,y,null),(0,s.privateSet)(q,Z,[])),(0,s.privateSet)(q,"length",q[Z].length)}var O=function(){function q($,j){var te=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};if(p(this,q),!globalThis.window&&!globalThis.document)throw new Error("It looks like you called `mount()` without a global document being loaded.");var U=(0,s.makeOptions)(te);if(j)(0,s.privateSet)(this,B,j[B]),(0,s.privateSet)(this,v,j),E(this,$),(0,s.privateSet)(this,V,j[Z]),(0,s.privateSet)(this,w,j[w]),(0,s.privateSet)(this,X,[]);else{var ie=(0,l.default)(U);if(!ie.isValidElement($))throw new TypeError("ReactWrapper can only wrap valid elements");var me=ie.createRenderer((0,n.default)({mode:"mount"},U));if((0,s.privateSet)(this,B,me),me.render($,U.context),(0,s.privateSet)(this,v,this),E(this,this[B].getNode()),(0,s.privateSet)(this,w,U),(0,s.privateSet)(this,X,[]),(0,s.isCustomComponent)(U.wrappingComponent,ie)){if(typeof this[B].getWrappingComponentRenderer!="function")throw new TypeError("your adapter does not support `wrappingComponent`. Try upgrading it!");(0,s.privateSet)(this,S,new J(this,this[B].getWrappingComponentRenderer())),this[X].push(this[S])}}(0,s.privateSet)(this,G,$),(0,s.privateSet)(this,W,null)}return I(q,[{key:"root",value:function(){function $(){return this[v]}return $}()},{key:"getNodeInternal",value:function(){function $(){if(this.length!==1)throw new Error("ReactWrapper::getNode() can only be called when wrapping one node");return this[Z][0]}return $}()},{key:"getNodesInternal",value:function(){function $(){return this[Z]}return $}()},{key:"getElement",value:function(){function $(){var j=this;return this.single("getElement",function(){return(0,l.default)(j[w]).nodeToElement(j[y])})}return $}()},{key:"getElements",value:function(){function $(){var j=this;return this[Z].map(function(te){return(0,l.default)(j[w]).nodeToElement(te)})}return $}()},{key:"getNode",value:function(){function $(){throw new Error("ReactWrapper::getNode() is no longer supported. Use ReactWrapper::instance() instead")}return $}()},{key:"getNodes",value:function(){function $(){throw new Error("ReactWrapper::getNodes() is no longer supported.")}return $}()},{key:"getDOMNode",value:function(){function $(){var j=(0,l.default)(this[w]);return this.single("getDOMNode",function(te){return j.nodeToHostNode(te,!0)})}return $}()},{key:"ref",value:function(){function $(j){if(this[v]!==this)throw new Error("ReactWrapper::ref(refname) can only be called on the root");return this.instance().refs[j]}return $}()},{key:"instance",value:function(){function $(){var j=this;return this.single("instance",function(){return j[y].instance})}return $}()},{key:"getWrappingComponent",value:function(){function $(){if(this[v]!==this)throw new Error("ReactWrapper::getWrappingComponent() can only be called on the root");if(!this[w].wrappingComponent)throw new Error("ReactWrapper::getWrappingComponent() can only be called on a wrapper that was originally passed a `wrappingComponent` option");return this[S]}return $}()},{key:"update",value:function(){function $(){var j=this,te=this[v];return this!==te?te.update():(E(this,this[B].getNode()),this[X].forEach(function(U){if(U!==j[W]){U[W]=j;try{U.update()}finally{U[W]=null}}}),this)}return $}()},{key:"unmount",value:function(){function $(){var j=this;if(this[v]!==this)throw new Error("ReactWrapper::unmount() can only be called on the root");return this.single("unmount",function(){j[B].unmount(),j.update()}),this}return $}()},{key:"mount",value:function(){function $(){var j=this;if(this[v]!==this)throw new Error("ReactWrapper::mount() can only be called on the root");return this[B].render(this[G],this[w].context,function(){return j.update()}),this}return $}()},{key:"setProps",value:function(){function $(j){var te=this,U=arguments.length>1&&arguments[1]!==void 0?arguments[1]:void 0;if(this[v]!==this)throw new Error("ReactWrapper::setProps() can only be called on the root");if(arguments.length>1&&typeof U!="function")throw new TypeError("ReactWrapper::setProps() expects a function as its second argument");var ie=(0,l.default)(this[w]);return this[G]=(0,s.cloneElement)(ie,this[G],j),this[B].render(this[G],null,function(){te.update(),U&&U()}),this}return $}()},{key:"setState",value:function(){function $(j){var te=this,U=arguments.length>1&&arguments[1]!==void 0?arguments[1]:void 0;if(this.instance()===null||this.getNodeInternal().nodeType!=="class")throw new Error("ReactWrapper::setState() can only be called on class components");if(arguments.length>1&&typeof U!="function")throw new TypeError("ReactWrapper::setState() expects a function as its second argument");return this.instance().setState(j,function(){if(te.update(),U){var ie=(0,l.default)(te[w]),me=te.instance();ie.invokeSetStateCallback?ie.invokeSetStateCallback(me,U):U.call(me)}}),this}return $}()},{key:"setContext",value:function(){function $(j){var te=this;if(this[v]!==this)throw new Error("ReactWrapper::setContext() can only be called on the root");if(!this[w].context)throw new Error("ReactWrapper::setContext() can only be called on a wrapper that was originally passed a context option");return this[B].render(this[G],j,function(){return te.update()}),this}return $}()},{key:"contains",value:function(){function $(j){var te=(0,l.default)(this[w]),U=Array.isArray(j)?function(ie){return(0,s.containsChildrenSubArray)(s.nodeEqual,ie,j.map(function(me){return te.elementToNode(me)}))}:function(ie){return(0,s.nodeEqual)(te.elementToNode(j),ie)};return R(this,U).length>0}return $}()},{key:"containsMatchingElement",value:function(){function $(j){var te=(0,l.default)(this[w]).elementToNode(j),U=function(){function ie(me){return(0,s.nodeMatches)(te,me,function(Ce,Ze){return Ce<=Ze})}return ie}();return R(this,U).length>0}return $}()},{key:"containsAllMatchingElements",value:function(){function $(j){var te=this;if(!Array.isArray(j))throw new TypeError("nodes should be an Array");return j.every(function(U){return te.containsMatchingElement(U)})}return $}()},{key:"containsAnyMatchingElements",value:function(){function $(j){var te=this;return Array.isArray(j)&&j.some(function(U){return te.containsMatchingElement(U)})}return $}()},{key:"equals",value:function(){function $(j){var te=this;return this.single("equals",function(){return(0,s.nodeEqual)(te.getNodeInternal(),j)})}return $}()},{key:"matchesElement",value:function(){function $(j){var te=this;return this.single("matchesElement",function(){var U=(0,l.default)(te[w]),ie=U.elementToNode(j);return(0,s.nodeMatches)(ie,te.getNodeInternal(),function(me,Ce){return me<=Ce})})}return $}()},{key:"find",value:function(){function $(j){return this.wrap((0,d.reduceTreesBySelector)(j,this.getNodesInternal()))}return $}()},{key:"is",value:function(){function $(j){var te=(0,d.buildPredicate)(j);return this.single("is",function(U){return te(U)})}return $}()},{key:"isEmptyRender",value:function(){function $(){var j=this.getNodeInternal();return(0,s.renderedDive)(j)}return $}()},{key:"filterWhere",value:function(){function $(j){var te=this;return H(this,function(U){return j(te.wrap(U))})}return $}()},{key:"filter",value:function(){function $(j){var te=(0,d.buildPredicate)(j);return H(this,te)}return $}()},{key:"not",value:function(){function $(j){var te=(0,d.buildPredicate)(j);return H(this,function(U){return!te(U)})}return $}()},{key:"text",value:function(){function $(){var j=(0,l.default)(this[w]);return this.single("text",function(te){return(0,u.getTextFromHostNodes)(te,j)})}return $}()},{key:"html",value:function(){function $(){var j=(0,l.default)(this[w]);return this.single("html",function(te){return(0,u.getHTMLFromHostNodes)(te,j)})}return $}()},{key:"render",value:function(){function $(){var j=this.html();return(0,s.loadCheerioRoot)(j)}return $}()},{key:"simulate",value:function(){function $(j){var te=this,U=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return this.single("simulate",function(ie){return te[B].simulateEvent(ie,j,U),te[v].update(),te})}return $}()},{key:"simulateError",value:function(){function $(j){var te=this;if(this[v]===this)throw new Error("ReactWrapper::simulateError() may not be called on the root");return this.single("simulateError",function(U){if(U.nodeType==="host")throw new Error("ReactWrapper::simulateError() can only be called on custom components");var ie=te[B];if(typeof ie.simulateError!="function")throw new TypeError("your adapter does not support `simulateError`. Try upgrading it!");var me=Y(te),Ce=[U].concat(D(te,U));return ie.simulateError(Ce,me,j),te[v].update(),te})}return $}()},{key:"props",value:function(){function $(){return this.single("props",u.propsOfNode)}return $}()},{key:"state",value:function(){function $(j){var te=this,U=this[v]===this?this[B].getNode():this.getNodeInternal();if(this.instance()===null||U.nodeType!=="class")throw new Error("ReactWrapper::state() can only be called on class components");var ie=this.single("state",function(){return te.instance().state});if(typeof j<"u"){if(ie==null)throw new TypeError('ReactWrapper::state("'+String(j)+'") requires that `state` not be `null` or `undefined`');return ie[j]}return ie}return $}()},{key:"context",value:function(){function $(j){var te=this;if(this[v]!==this)throw new Error("ReactWrapper::context() can only be called on the root");var U=this.single("context",function(){return te.instance()});if(U===null)throw new Error("ReactWrapper::context() can only be called on components with instances");var ie=U.context;return typeof j<"u"?ie[j]:ie}return $}()},{key:"children",value:function(){function $(j){var te=this.flatMap(function(U){return(0,u.childrenOfNode)(U.getNodeInternal())});return j?te.filter(j):te}return $}()},{key:"childAt",value:function(){function $(j){var te=this;return this.single("childAt",function(){return te.children().at(j)})}return $}()},{key:"parents",value:function(){function $(j){var te=this;return this.single("parents",function(U){var ie=te.wrap(D(te,U));return j?ie.filter(j):ie})}return $}()},{key:"parent",value:function(){function $(){return this.flatMap(function(j){return[j.parents().get(0)]})}return $}()},{key:"closest",value:function(){function $(j){if(this.is(j))return this;var te=this.parents().filter(j);return te.length>0?te.first():this.findWhere(function(){return!1})}return $}()},{key:"prop",value:function(){function $(j){return this.props()[j]}return $}()},{key:"invoke",value:function(){function $(j){var te=this;return this.single("invoke",function(){var U=te.prop(j);if(typeof U!="function")throw new TypeError("ReactWrapper::invoke() requires the name of a prop whose value is a function");return function(){for(var ie=arguments.length,me=Array(ie),Ce=0;Ce"u"?"undefined":g(Ce))+"“");return function(){var Ze=Ce.apply(void 0,arguments),Ge=U.wrap(Ze);return te.wrap(Ge,null,te[w])}})}return $}()},{key:"key",value:function(){function $(){return this.single("key",function(j){return j.key===void 0?null:j.key})}return $}()},{key:"type",value:function(){function $(){return this.single("type",function(j){return(0,s.typeOfNode)(j)})}return $}()},{key:"name",value:function(){function $(){var j=(0,l.default)(this[w]);return this.single("name",function(te){return j.displayNameOfNode?j.displayNameOfNode(te):(0,s.displayNameOfNode)(te)})}return $}()},{key:"hasClass",value:function(){function $(j){return typeof j=="string"&&j.indexOf(".")!==-1&&console.warn("It looks like you're calling `ReactWrapper::hasClass()` with a CSS selector. hasClass() expects a class name, not a CSS selector."),this.single("hasClass",function(te){return(0,u.hasClassName)(te,j)})}return $}()},{key:"forEach",value:function(){function $(j){var te=this;return this.getNodesInternal().forEach(function(U,ie){return j.call(te,te.wrap(U),ie)}),this}return $}()},{key:"map",value:function(){function $(j){var te=this;return this.getNodesInternal().map(function(U,ie){return j.call(te,te.wrap(U),ie)})}return $}()},{key:"reduce",value:function(){function $(j){var te=this,U=arguments.length>1&&arguments[1]!==void 0?arguments[1]:void 0;return arguments.length>1?this.getNodesInternal().reduce(function(ie,me,Ce){return j.call(te,ie,te.wrap(me),Ce)},U):this.getNodesInternal().reduce(function(ie,me,Ce){return j.call(te,Ce===1?te.wrap(ie):ie,te.wrap(me),Ce)})}return $}()},{key:"reduceRight",value:function(){function $(j){var te=this,U=arguments.length>1&&arguments[1]!==void 0?arguments[1]:void 0;return arguments.length>1?this.getNodesInternal().reduceRight(function(ie,me,Ce){return j.call(te,ie,te.wrap(me),Ce)},U):this.getNodesInternal().reduceRight(function(ie,me,Ce){return j.call(te,Ce===1?te.wrap(ie):ie,te.wrap(me),Ce)})}return $}()},{key:"slice",value:function(){function $(j,te){return this.wrap(this.getNodesInternal().slice(j,te))}return $}()},{key:"some",value:function(){function $(j){if(this[v]===this)throw new Error("ReactWrapper::some() can not be called on the root");var te=(0,d.buildPredicate)(j);return this.getNodesInternal().some(te)}return $}()},{key:"someWhere",value:function(){function $(j){var te=this;return this.getNodesInternal().some(function(U,ie){return j.call(te,te.wrap(U),ie)})}return $}()},{key:"every",value:function(){function $(j){var te=(0,d.buildPredicate)(j);return this.getNodesInternal().every(te)}return $}()},{key:"everyWhere",value:function(){function $(j){var te=this;return this.getNodesInternal().every(function(U,ie){return j.call(te,te.wrap(U),ie)})}return $}()},{key:"flatMap",value:function(){function $(j){var te=this,U=this.getNodesInternal().map(function(me,Ce){return j.call(te,te.wrap(me),Ce)}),ie=(0,r.default)(U,1);return this.wrap(ie.filter(Boolean))}return $}()},{key:"findWhere",value:function(){function $(j){var te=this;return R(this,function(U){var ie=te.wrap(U);return ie.length>0&&j(ie)})}return $}()},{key:"get",value:function(){function $(j){return this.getElements()[j]}return $}()},{key:"at",value:function(){function $(j){var te=this.getNodesInternal();return j0&&arguments[0]!==void 0?arguments[0]:null;return arguments.length>0?this.find(j).exists():this.length>0}return $}()},{key:"single",value:function(){function $(j,te){var U=typeof j=="string"?j:"unknown",ie=typeof te=="function"?te:j;if(this.length!==1)throw new Error("Method “"+U+"” is meant to be run on 1 node. "+String(this.length)+" found instead.");return ie.call(this,this.getNodeInternal())}return $}()},{key:"wrap",value:function(){function $(j){var te=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this[v];if(j instanceof q)return j;for(var U=arguments.length,ie=Array(U>2?U-2:0),me=2;me0&&arguments[0]!==void 0?arguments[0]:{};return(0,c.debugNodes)(this.getNodesInternal(),j)}return $}()},{key:"tap",value:function(){function $(j){return j(this),this}return $}()},{key:"detach",value:function(){function $(){if(this[v]!==this)throw new Error("ReactWrapper::detach() can only be called on the root");if(!this[w].attachTo)throw new Error("ReactWrapper::detach() can only be called on when the `attachTo` option was passed into `mount()`.");this[B].unmount()}return $}()},{key:"hostNodes",value:function(){function $(){return this.filterWhere(function(j){return typeof j.type()=="string"})}return $}()}]),q}(),J=function(q){b($,q);function $(j,te){p(this,$);var U=f(this,($.__proto__||Object.getPrototypeOf($)).call(this,te.getNode(),j));return(0,s.privateSet)(U,v,U),(0,s.privateSet)(U,B,te),U[X].push(j),U}return I($,[{key:"getWrappingComponent",value:function(){function j(){throw new TypeError("ReactWrapper::getWrappingComponent() can only be called on the root")}return j}()}]),$}(O);s.ITERATOR_SYMBOL&&Object.defineProperty(O.prototype,s.ITERATOR_SYMBOL,{configurable:!0,value:function(){function q(){var $,j=this[Z][s.ITERATOR_SYMBOL](),te=(0,l.default)(this[w]);return $={},m($,s.ITERATOR_SYMBOL,function(){return this}),m($,"next",function(){function U(){var ie=j.next();return ie.done?{done:!0}:{done:!1,value:te.nodeToElement(ie.value)}}return U}()),$}return q}()});function ee(q,$){Object.defineProperty(O.prototype,q,{get:function(){function j(){throw new Error(` Attempted to access ReactWrapper::`+String(q)+`, which was previously a private property on Enzyme ReactWrapper instances, but is no longer and should not be relied upon. `+String($)+` - `)}return j}(),enumerable:!1,configurable:!1})}te("node","Consider using the getElement() method instead."),te("nodes","Consider using the getElements() method instead."),te("renderer",""),te("options",""),te("complexSelector",""),g.default=_})(kQ);var Hj={};(function(g){Object.defineProperty(g,"__esModule",{value:!0});var e=function(){function Te(le,ye,We){le===null&&(le=Function.prototype);var K=Object.getOwnPropertyDescriptor(le,ye);if(K===void 0){var T=Object.getPrototypeOf(le);return T===null?void 0:Te(T,ye,We)}else{if("value"in K)return K.value;var k=K.get;return k===void 0?void 0:k.call(We)}}return Te}(),I=function(){function Te(le,ye){for(var We=0;We2&&arguments[2]!==void 0?arguments[2]:m.treeFilter;return Te.flatMap(function(We){return ye(We.getNodeInternal(),le)})}function q(Te,le){return Te.wrap(Te.getNodesInternal().filter(le).filter(Boolean))}function $(Te){var le=Te.lifecycleExperimental,ye=Te.disableLifecycleMethods,We=Te.enableComponentDidUpdateOnSetState,K=Te.supportPrevContextArgumentOfComponentDidUpdate,T=Te.lifecycles;if(typeof le<"u"&&typeof le!="boolean")throw new Error("lifecycleExperimental must be either true or false if provided");if(typeof ye<"u"&&typeof ye!="boolean")throw new Error("disableLifecycleMethods must be either true or false if provided");if(le!=null&&ye!=null&&le===ye)throw new Error("lifecycleExperimental and disableLifecycleMethods cannot be set to the same value");if(typeof We<"u"&&T.componentDidUpdate&&T.componentDidUpdate.onSetState!==We)throw new TypeError("the legacy enableComponentDidUpdateOnSetState option should be matched by `lifecycles: { componentDidUpdate: { onSetState: true } }`, for compatibility");if(typeof K<"u"&&T.componentDidUpdate&&T.componentDidUpdate.prevContext!==K)throw new TypeError("the legacy supportPrevContextArgumentOfComponentDidUpdate option should be matched by `lifecycles: { componentDidUpdate: { prevContext: true } }`, for compatibility")}function j(Te){var le=Te.options,ye=le.lifecycles,We=ye===void 0?{}:ye,K=le.enableComponentDidUpdateOnSetState,T=le.supportPrevContextArgumentOfComponentDidUpdate,k=typeof K<"u",ge=typeof T<"u",he=k||ge?(0,C.default)({},k&&{onSetState:!!K},ge&&{prevContext:!!T}):null,we=We.getDerivedStateFromProps,xe=we?{hasShouldComponentUpdateBug:!!we.hasShouldComponentUpdateBug}:!1;return(0,C.default)({},We,{setState:(0,C.default)({},We.setState),getChildContext:(0,C.default)({calledByRenderer:!0},We.getChildContext)},he&&{componentDidUpdate:he},{getDerivedStateFromProps:xe})}function ee(Te){return Te.nodeType==="host"?Te:Te.rendered}function Q(Te){if(Te[X].length!==1)throw new Error("getRootNodeInternal(wrapper) can only be called when wrapper wraps one node");return Te[X]!==Te?Te[H][0]:Te[X][B]}function ne(Te,le){return(0,m.parentsOfNode)(le,Q(Te))}function fe(Te,le){Array.isArray(le)?((0,c.privateSet)(Te,B,le[0]),(0,c.privateSet)(Te,w,le)):((0,c.privateSet)(Te,B,le),(0,c.privateSet)(Te,w,[le])),(0,c.privateSet)(Te,"length",Te[w].length)}function Ce(Te,le,ye,We){return!(0,l.default)(Te,le)||!(0,l.default)(ye,We)}function Ze(Te){return Te&&Te.isPureReactComponent}function Ge(Te,le,ye){var We=Te.instance,K=Te.type,T=(0,c.displayNameOfNode)(Te);if(i(K.childContextTypes)!=="object")return console.warn(String(T)+".getChildContext(): childContextTypes must be defined in order to use getChildContext()."),{};var k=We.getChildContext();return Object.keys(k).forEach(function(ge){if(!(ge in K.childContextTypes))throw new Error(String(T)+'.getChildContext(): key "'+String(ge)+'" is not defined in childContextTypes.')}),typeof ye.checkPropTypes=="function"&&ye.checkPropTypes(K.childContextTypes,k,"child context",le),k}function ve(Te,le){return!(0,c.isCustomComponentElement)(Te,le)||!Te.type.prototype||typeof Te.type.prototype.getChildContext!="function"?null:(0,c.spyMethod)(Te.type.prototype,"getChildContext")}function ke(Te,le,ye,We,K){var T=le[R];if(Te.options.legacyContextMode==="parent")if(K)(0,c.privateSet)(le,D,K.getLastReturnValue()),K.restore();else if(typeof ye.getChildContext=="function"){var k=[le[B]].concat(ne(le,le[B])),ge=Ge(We,k,T);(0,c.privateSet)(le,D,ge)}else(0,c.privateSet)(le,D,null)}function Xe(Te,le){var ye=Te.type.getDerivedStateFromProps;if(typeof ye=="function")var We=Te.instance,K=(0,c.spyMethod)(We,"shouldComponentUpdate",function(k){return function(){function ge(){We.state=le;for(var he=arguments.length,we=Array(he),xe=0;xe1&&arguments[1]!==void 0?arguments[1]:{},ye=(0,C.default)({},Te[W],le,{context:le.context||(0,C.default)({},Te[W].context,Te[X][D])});return(0,c.privateSet)(ye,J,Te[X][J]),ye}var _e=function(){function Te(le,ye){var We=this,K=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};v(this,Te),$(K);var T=Me(le,ye,K,this),k=(0,d.default)(T),ge=j(k);if(ye)(0,c.privateSet)(this,X,ye),(0,c.privateSet)(this,S,null),(0,c.privateSet)(this,R,ye[R]),fe(this,le),(0,c.privateSet)(this,W,ye[W]),(0,c.privateSet)(this,H,ye[w]),(0,c.privateSet)(this,J,null);else{if(!k.isValidElement(le))throw new TypeError("ShallowWrapper can only wrap valid elements");var he=ge.getChildContext.calledByRenderer?ve(le,k):null;(0,c.privateSet)(this,X,this),(0,c.privateSet)(this,S,le);var we=k.createRenderer((0,C.default)({mode:"shallow"},T));(0,c.privateSet)(this,R,we);var xe=new Map(T[J]||[]);this[R].render(le,T.context,{providerValues:xe});var qe=this[R].getNode();fe(this,ee(qe)),(0,c.privateSet)(this,W,T),(0,c.privateSet)(this,J,xe);var mt=qe.instance;mt&&!T.disableLifecycleMethods&&(ge.componentDidUpdate.onSetState&&!mt[V]&&((0,c.privateSet)(mt,V,mt.setState),mt.setState=function(St){var ut=arguments.length>1&&arguments[1]!==void 0?arguments[1]:void 0;return We.setState.apply(We,Z(ut==null?[St]:[St,ut]))}),typeof mt.componentDidMount=="function"&&this[R].batchedUpdates(function(){mt.componentDidMount()}),ke(k,this,mt,qe,he))}}return I(Te,[{key:"root",value:function(){function le(){return this[X]}return le}()},{key:"getNodeInternal",value:function(){function le(){if(this.length!==1)throw new Error("ShallowWrapper::getNode() can only be called when wrapping one node");return this[X]===this&&this.update(),this[B]}return le}()},{key:"getNodesInternal",value:function(){function le(){return this[X]===this&&this.length===1&&this.update(),this[w]}return le}()},{key:"getElement",value:function(){function le(){var ye=this;return this.single("getElement",function(We){return(0,d.default)(ye[W]).nodeToElement(We)})}return le}()},{key:"getElements",value:function(){function le(){var ye=this;return this.getNodesInternal().map(function(We){return(0,d.default)(ye[W]).nodeToElement(We)})}return le}()},{key:"getNode",value:function(){function le(){throw new Error("ShallowWrapper::getNode() is no longer supported. Use ShallowWrapper::getElement() instead")}return le}()},{key:"getNodes",value:function(){function le(){throw new Error("ShallowWrapper::getNodes() is no longer supported. Use ShallowWrapper::getElements() instead")}return le}()},{key:"instance",value:function(){function le(){if(this[X]!==this)throw new Error("ShallowWrapper::instance() can only be called on the root");return this[R].getNode().instance}return le}()},{key:"getWrappingComponent",value:function(){function le(){if(this[X]!==this)throw new Error("ShallowWrapper::getWrappingComponent() can only be called on the root");if(!this[W].wrappingComponent)throw new Error("ShallowWrapper::getWrappingComponent() can only be called on a wrapper that was originally passed a `wrappingComponent` option");return this[Y]}return le}()},{key:"update",value:function(){function le(){if(this[X]!==this)throw new Error("ShallowWrapper::update() can only be called on the root");if(this.length!==1)throw new Error("ShallowWrapper::update() can only be called when wrapping one node");return fe(this,ee(this[R].getNode())),this}return le}()},{key:"unmount",value:function(){function le(){return this[R].unmount(),this[X][Y]&&this[X][Y].unmount(),this}return le}()},{key:"rerender",value:function(){function le(ye,We){var K=this,T=(0,d.default)(this[W]);return this.single("rerender",function(){(0,c.withSetStateAllowed)(function(){var k=K[R].getNode(),ge=k.instance||{},he=k.type||{},we=ge.state,xe=ge.props||K[S].props,qe=ge.context||K[W].context,mt=We||qe;We&&(K[W]=(0,C.default)({},K[W],{context:mt})),K[R].batchedUpdates(function(){var St=j(T),ut=!0,Yt=void 0,ie=void 0;if(!K[W].disableLifecycleMethods&&ge){if(typeof ge.shouldComponentUpdate=="function"){var E=St.getDerivedStateFromProps;E&&E.hasShouldComponentUpdateBug&&Xe(k,we),Yt=(0,c.spyMethod)(ge,"shouldComponentUpdate")}St.getChildContext.calledByRenderer&&typeof ge.getChildContext=="function"&&(ie=(0,c.spyMethod)(ge,"getChildContext"))}if(!Yt&&Ze(ge)&&(ut=Ce(xe,ye,we,ge.state)),ye&&(K[S]=(0,c.cloneElement)(T,K[S],ye)),K[R].render(K[S],mt,{providerValues:K[J]}),Yt&&(ut=Yt.getLastReturnValue(),Yt.restore()),ut&&!K[W].disableLifecycleMethods&&ge)if(ke(T,K,ge,k,ie),St.getSnapshotBeforeUpdate){var O=void 0;typeof ge.getSnapshotBeforeUpdate=="function"&&(O=ge.getSnapshotBeforeUpdate(xe,we)),St.componentDidUpdate&&typeof ge.componentDidUpdate=="function"&&(!we||(0,l.default)(we,K.instance().state)||typeof he.getDerivedStateFromProps=="function")&&ge.componentDidUpdate(xe,we,O)}else St.componentDidUpdate&&typeof ge.componentDidUpdate=="function"&&(St.componentDidUpdate.prevContext?ge.componentDidUpdate(xe,we,qe):(!we||(0,l.default)(K.instance().state,we))&&ge.componentDidUpdate(xe,we));else(0,l.default)(ye,ge.props)||(ge.props=(Object.freeze||Object)((0,C.default)({},ge.props,ye)));K.update()})})}),this}return le}()},{key:"setProps",value:function(){function le(ye){var We=arguments.length>1&&arguments[1]!==void 0?arguments[1]:void 0;if(this[X]!==this)throw new Error("ShallowWrapper::setProps() can only be called on the root");if(arguments.length>1&&typeof We!="function")throw new TypeError("ReactWrapper::setProps() expects a function as its second argument");return this.rerender(ye),We&&We(),this}return le}()},{key:"setState",value:function(){function le(ye){var We=this,K=arguments.length>1&&arguments[1]!==void 0?arguments[1]:void 0;if(this[X]!==this)throw new Error("ShallowWrapper::setState() can only be called on the root");if(this.instance()===null||this[R].getNode().nodeType!=="class")throw new Error("ShallowWrapper::setState() can only be called on class components");if(arguments.length>1&&typeof K!="function")throw new TypeError("ReactWrapper::setState() expects a function as its second argument");return this.single("setState",function(){(0,c.withSetStateAllowed)(function(){var T=(0,d.default)(We[W]),k=j(T),ge=We[R].getNode(),he=ge.instance,we=he.props,xe=he.state,qe=he.context,mt=typeof ye=="function"?ye.call(he,xe,we):ye,St=!k.setState.skipsComponentDidUpdateOnNullish||mt!=null,ut=void 0,Yt=void 0,ie=!0;if(!We[W].disableLifecycleMethods&&he){if(k.componentDidUpdate&&k.componentDidUpdate.onSetState&&typeof he.shouldComponentUpdate=="function"){var E=k.getDerivedStateFromProps;E&&E.hasShouldComponentUpdateBug&&Xe(ge,ye),ut=(0,c.spyMethod)(he,"shouldComponentUpdate")}k.getChildContext.calledByRenderer&&typeof he.getChildContext=="function"&&(Yt=(0,c.spyMethod)(he,"getChildContext"))}if(!ut&&Ze(he)&&(ie=Ce(we,he.props,xe,(0,C.default)({},xe,mt))),he[V]?he[V](mt):he.setState(mt),ut&&(ie=ut.getLastReturnValue(),ut.restore()),St&&ie&&!We[W].disableLifecycleMethods&&(ke(T,We,he,ge,Yt),k.componentDidUpdate&&k.componentDidUpdate.onSetState))if(k.getSnapshotBeforeUpdate&&typeof he.getSnapshotBeforeUpdate=="function"){var O=he.getSnapshotBeforeUpdate(we,xe);typeof he.componentDidUpdate=="function"&&he.componentDidUpdate(we,xe,O)}else typeof he.componentDidUpdate=="function"&&(k.componentDidUpdate.prevContext?he.componentDidUpdate(we,xe,qe):he.componentDidUpdate(we,xe));We.update(),K&&(T.invokeSetStateCallback?T.invokeSetStateCallback(he,K):K.call(he))})}),this}return le}()},{key:"setContext",value:function(){function le(ye){if(this[X]!==this)throw new Error("ShallowWrapper::setContext() can only be called on the root");if(!this[W].context)throw new Error("ShallowWrapper::setContext() can only be called on a wrapper that was originally passed a context option");return this.rerender(null,ye)}return le}()},{key:"contains",value:function(){function le(ye){var We=(0,d.default)(this[W]);if(!(0,c.isReactElementAlike)(ye,We))throw new Error("ShallowWrapper::contains() can only be called with a ReactElement (or an array of them), a string, or a number as an argument.");var K=Array.isArray(ye)?function(T){return(0,c.containsChildrenSubArray)(c.nodeEqual,T,ye.map(function(k){return We.elementToNode(k)}))}:function(T){return(0,c.nodeEqual)(We.elementToNode(ye),T)};return te(this,K).length>0}return le}()},{key:"containsMatchingElement",value:function(){function le(ye){var We=(0,d.default)(this[W]),K=We.elementToNode(ye),T=function(){function k(ge){return(0,c.nodeMatches)(K,ge,function(he,we){return he<=we})}return k}();return te(this,T).length>0}return le}()},{key:"containsAllMatchingElements",value:function(){function le(ye){var We=this;if(!Array.isArray(ye))throw new TypeError("nodes should be an Array");return ye.every(function(K){return We.containsMatchingElement(K)})}return le}()},{key:"containsAnyMatchingElements",value:function(){function le(ye){var We=this;return Array.isArray(ye)&&ye.some(function(K){return We.containsMatchingElement(K)})}return le}()},{key:"equals",value:function(){function le(ye){var We=this;return this.single("equals",function(){return(0,c.nodeEqual)(We.getNodeInternal(),ye)})}return le}()},{key:"matchesElement",value:function(){function le(ye){var We=this;return this.single("matchesElement",function(){var K=(0,d.default)(We[W]),T=K.elementToNode(ye);return(0,c.nodeMatches)(T,We.getNodeInternal(),function(k,ge){return k<=ge})})}return le}()},{key:"find",value:function(){function le(ye){return this.wrap((0,f.reduceTreesBySelector)(ye,this.getNodesInternal()))}return le}()},{key:"is",value:function(){function le(ye){var We=(0,f.buildPredicate)(ye);return this.single("is",function(K){return We(K)})}return le}()},{key:"isEmptyRender",value:function(){function le(){var ye=this.getNodesInternal();return ye.every(function(We){return(0,c.isEmptyValue)(We)})}return le}()},{key:"filterWhere",value:function(){function le(ye){var We=this;return q(this,function(K){return ye(We.wrap(K))})}return le}()},{key:"filter",value:function(){function le(ye){var We=(0,f.buildPredicate)(ye);return q(this,We)}return le}()},{key:"not",value:function(){function le(ye){var We=(0,f.buildPredicate)(ye);return q(this,function(K){return!We(K)})}return le}()},{key:"text",value:function(){function le(){return this.single("text",m.getTextFromNode)}return le}()},{key:"html",value:function(){function le(){var ye=this;return this.single("html",function(We){if(ye.type()===null)return null;var K=(0,d.default)(ye[W]),T=K.createRenderer((0,C.default)({},ye[W],{mode:"string"}));return T.render(K.nodeToElement(We))})}return le}()},{key:"render",value:function(){function le(){var ye=this.html();return(0,c.loadCheerioRoot)(ye)}return le}()},{key:"simulate",value:function(){function le(ye){for(var We=this,K=arguments.length,T=Array(K>1?K-1:0),k=1;k0?We.first():this.findWhere(function(){return!1})}return le}()},{key:"shallow",value:function(){function le(){var ye=this,We=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};return this.single("shallow",function(K){var T=Ue(ye,We);return ye.wrap((0,d.default)(ye[W]).nodeToElement(K),null,T)})}return le}()},{key:"prop",value:function(){function le(ye){return this.props()[ye]}return le}()},{key:"invoke",value:function(){function le(ye){var We=this;return this.single("invoke",function(){var K=We.prop(ye);if(typeof K!="function")throw new TypeError("ShallowWrapper::invoke() requires the name of a prop whose value is a function");return function(){var T=K.apply(void 0,arguments);return We[X].update(),T}})}return le}()},{key:"renderProp",value:function(){function le(ye){var We=this,K=(0,d.default)(this[W]);if(typeof K.wrap!="function")throw new RangeError("your adapter does not support `wrap`. Try upgrading it!");return this.single("renderProp",function(T){if(T.nodeType==="host")throw new TypeError("ShallowWrapper::renderProp() can only be called on custom components");if(typeof ye!="string")throw new TypeError("ShallowWrapper::renderProp(): `propName` must be a string");var k=We.props();if(!(0,s.default)(k,ye))throw new Error("ShallowWrapper::renderProp(): no prop called “"+String(ye)+"“ found");var ge=k[ye];if(typeof ge!="function")throw new TypeError("ShallowWrapper::renderProp(): expected prop “"+String(ye)+"“ to contain a function, but it holds “"+(typeof ge>"u"?"undefined":i(ge))+"“");return function(){var he=ge.apply(void 0,arguments),we=K.wrap(he);return We.wrap(we,null,We[W])}})}return le}()},{key:"key",value:function(){function le(){return this.single("key",function(ye){return ye.key===void 0?null:ye.key})}return le}()},{key:"type",value:function(){function le(){return this.single("type",function(ye){return(0,c.typeOfNode)(ye)})}return le}()},{key:"name",value:function(){function le(){var ye=(0,d.default)(this[W]);return this.single("name",function(We){return ye.displayNameOfNode?ye.displayNameOfNode(We):(0,c.displayNameOfNode)(We)})}return le}()},{key:"hasClass",value:function(){function le(ye){return typeof ye=="string"&&ye.indexOf(".")!==-1&&console.warn("It looks like you're calling `ShallowWrapper::hasClass()` with a CSS selector. hasClass() expects a class name, not a CSS selector."),this.single("hasClass",function(We){return(0,m.hasClassName)(We,ye)})}return le}()},{key:"forEach",value:function(){function le(ye){var We=this;return this.getNodesInternal().forEach(function(K,T){return ye.call(We,We.wrap(K),T)}),this}return le}()},{key:"map",value:function(){function le(ye){var We=this;return this.getNodesInternal().map(function(K,T){return ye.call(We,We.wrap(K),T)})}return le}()},{key:"reduce",value:function(){function le(ye){var We=this,K=arguments.length>1&&arguments[1]!==void 0?arguments[1]:void 0;return arguments.length>1?this.getNodesInternal().reduce(function(T,k,ge){return ye.call(We,T,We.wrap(k),ge)},K):this.getNodesInternal().reduce(function(T,k,ge){return ye.call(We,ge===1?We.wrap(T):T,We.wrap(k),ge)})}return le}()},{key:"reduceRight",value:function(){function le(ye){var We=this,K=arguments.length>1&&arguments[1]!==void 0?arguments[1]:void 0;return arguments.length>1?this.getNodesInternal().reduceRight(function(T,k,ge){return ye.call(We,T,We.wrap(k),ge)},K):this.getNodesInternal().reduceRight(function(T,k,ge){return ye.call(We,ge===1?We.wrap(T):T,We.wrap(k),ge)})}return le}()},{key:"slice",value:function(){function le(ye,We){return this.wrap(this.getNodesInternal().slice(ye,We))}return le}()},{key:"some",value:function(){function le(ye){if(this[X]===this)throw new Error("ShallowWrapper::some() can not be called on the root");var We=(0,f.buildPredicate)(ye);return this.getNodesInternal().some(We)}return le}()},{key:"someWhere",value:function(){function le(ye){var We=this;return this.getNodesInternal().some(function(K,T){return ye.call(We,We.wrap(K),T)})}return le}()},{key:"every",value:function(){function le(ye){var We=(0,f.buildPredicate)(ye);return this.getNodesInternal().every(We)}return le}()},{key:"everyWhere",value:function(){function le(ye){var We=this;return this.getNodesInternal().every(function(K,T){return ye.call(We,We.wrap(K),T)})}return le}()},{key:"flatMap",value:function(){function le(ye){var We=this,K=this.getNodesInternal().map(function(k,ge){return ye.call(We,We.wrap(k),ge)}),T=(0,o.default)(K,1);return this.wrap(T.filter(Boolean))}return le}()},{key:"findWhere",value:function(){function le(ye){var We=this;return te(this,function(K){var T=We.wrap(K);return T.length>0&&ye(T)})}return le}()},{key:"get",value:function(){function le(ye){return this.getElements()[ye]}return le}()},{key:"at",value:function(){function le(ye){var We=this.getNodesInternal();return ye0&&arguments[0]!==void 0?arguments[0]:null;return arguments.length>0?this.find(ye).exists():this.length>0}return le}()},{key:"single",value:function(){function le(ye,We){var K=typeof ye=="string"?ye:"unknown",T=typeof We=="function"?We:ye;if(this.length!==1)throw new Error("Method “"+K+"” is meant to be run on 1 node. "+String(this.length)+" found instead.");return T.call(this,this.getNodeInternal())}return le}()},{key:"wrap",value:function(){function le(ye){var We=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this[X];if(ye instanceof Te)return ye;for(var K=arguments.length,T=Array(K>2?K-2:0),k=2;k0&&arguments[0]!==void 0?arguments[0]:{};return(0,h.debugNodes)(this.getNodesInternal(),ye)}return le}()},{key:"tap",value:function(){function le(ye){return ye(this),this}return le}()},{key:"dive",value:function(){function le(){var ye=this,We=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},K=(0,d.default)(this[W]),T="dive";return this.single(T,function(k){if(k&&k.nodeType==="host")throw new TypeError("ShallowWrapper::"+T+"() can not be called on Host Components");var ge=(0,d.default)(ye[W]).nodeToElement(k);if(!(0,c.isCustomComponentElement)(ge,K))throw new TypeError("ShallowWrapper::"+T+"() can only be called on components");var he=Ue(ye,We);return ye.wrap(ge,null,he)})}return le}()},{key:"hostNodes",value:function(){function le(){return this.filterWhere(function(ye){return typeof ye.type()=="string"})}return le}()}]),Te}();function At(Te){var le=(0,d.default)(Te[W]),ye=Te[F],We=ye[R],K=We.getNode(),T=ze(Te,le),k=T.legacyContext,ge=T.providerValues,he=ye[J];if(ye.setContext((0,C.default)({},Te[F][W].context,k)),ye[J]=new Map([].concat(Z(he),Z(ge))),typeof le.isContextConsumer=="function"&&le.isContextConsumer(K.type)){var we=K.type,xe=le.getProviderFromConsumer(we),qe=ge.get(xe),mt=he.get(xe);qe!==mt&&ye.rerender()}}var wt=function(Te){y(le,Te);function le(ye,We,K){v(this,le);var T=p(this,(le.__proto__||Object.getPrototypeOf(le)).call(this,ye));return(0,c.privateSet)(T,F,We),(0,c.privateSet)(T,_,K),T}return I(le,[{key:"rerender",value:function(){function ye(){for(var We,K=arguments.length,T=Array(K),k=0;k2&&arguments[2]!==void 0?arguments[2]:m.treeFilter;return Te.flatMap(function(Xe){return ye(Xe.getNodeInternal(),se)})}function q(Te,se){return Te.wrap(Te.getNodesInternal().filter(se).filter(Boolean))}function $(Te){var se=Te.lifecycleExperimental,ye=Te.disableLifecycleMethods,Xe=Te.enableComponentDidUpdateOnSetState,K=Te.supportPrevContextArgumentOfComponentDidUpdate,T=Te.lifecycles;if(typeof se<"u"&&typeof se!="boolean")throw new Error("lifecycleExperimental must be either true or false if provided");if(typeof ye<"u"&&typeof ye!="boolean")throw new Error("disableLifecycleMethods must be either true or false if provided");if(se!=null&&ye!=null&&se===ye)throw new Error("lifecycleExperimental and disableLifecycleMethods cannot be set to the same value");if(typeof Xe<"u"&&T.componentDidUpdate&&T.componentDidUpdate.onSetState!==Xe)throw new TypeError("the legacy enableComponentDidUpdateOnSetState option should be matched by `lifecycles: { componentDidUpdate: { onSetState: true } }`, for compatibility");if(typeof K<"u"&&T.componentDidUpdate&&T.componentDidUpdate.prevContext!==K)throw new TypeError("the legacy supportPrevContextArgumentOfComponentDidUpdate option should be matched by `lifecycles: { componentDidUpdate: { prevContext: true } }`, for compatibility")}function j(Te){var se=Te.options,ye=se.lifecycles,Xe=ye===void 0?{}:ye,K=se.enableComponentDidUpdateOnSetState,T=se.supportPrevContextArgumentOfComponentDidUpdate,k=typeof K<"u",ge=typeof T<"u",he=k||ge?(0,C.default)({},k&&{onSetState:!!K},ge&&{prevContext:!!T}):null,Ve=Xe.getDerivedStateFromProps,De=Ve?{hasShouldComponentUpdateBug:!!Ve.hasShouldComponentUpdateBug}:!1;return(0,C.default)({},Xe,{setState:(0,C.default)({},Xe.setState),getChildContext:(0,C.default)({calledByRenderer:!0},Xe.getChildContext)},he&&{componentDidUpdate:he},{getDerivedStateFromProps:De})}function te(Te){return Te.nodeType==="host"?Te:Te.rendered}function U(Te){if(Te[X].length!==1)throw new Error("getRootNodeInternal(wrapper) can only be called when wrapper wraps one node");return Te[X]!==Te?Te[H][0]:Te[X][v]}function ie(Te,se){return(0,m.parentsOfNode)(se,U(Te))}function me(Te,se){Array.isArray(se)?((0,c.privateSet)(Te,v,se[0]),(0,c.privateSet)(Te,w,se)):((0,c.privateSet)(Te,v,se),(0,c.privateSet)(Te,w,[se])),(0,c.privateSet)(Te,"length",Te[w].length)}function Ce(Te,se,ye,Xe){return!(0,l.default)(Te,se)||!(0,l.default)(ye,Xe)}function Ze(Te){return Te&&Te.isPureReactComponent}function Ge(Te,se,ye){var Xe=Te.instance,K=Te.type,T=(0,c.displayNameOfNode)(Te);if(i(K.childContextTypes)!=="object")return console.warn(String(T)+".getChildContext(): childContextTypes must be defined in order to use getChildContext()."),{};var k=Xe.getChildContext();return Object.keys(k).forEach(function(ge){if(!(ge in K.childContextTypes))throw new Error(String(T)+'.getChildContext(): key "'+String(ge)+'" is not defined in childContextTypes.')}),typeof ye.checkPropTypes=="function"&&ye.checkPropTypes(K.childContextTypes,k,"child context",se),k}function Be(Te,se){return!(0,c.isCustomComponentElement)(Te,se)||!Te.type.prototype||typeof Te.type.prototype.getChildContext!="function"?null:(0,c.spyMethod)(Te.type.prototype,"getChildContext")}function Ne(Te,se,ye,Xe,K){var T=se[V];if(Te.options.legacyContextMode==="parent")if(K)(0,c.privateSet)(se,Y,K.getLastReturnValue()),K.restore();else if(typeof ye.getChildContext=="function"){var k=[se[v]].concat(ie(se,se[v])),ge=Ge(Xe,k,T);(0,c.privateSet)(se,Y,ge)}else(0,c.privateSet)(se,Y,null)}function Se(Te,se){var ye=Te.type.getDerivedStateFromProps;if(typeof ye=="function")var Xe=Te.instance,K=(0,c.spyMethod)(Xe,"shouldComponentUpdate",function(k){return function(){function ge(){Xe.state=se;for(var he=arguments.length,Ve=Array(he),De=0;De1&&arguments[1]!==void 0?arguments[1]:{},ye=(0,C.default)({},Te[W],se,{context:se.context||(0,C.default)({},Te[W].context,Te[X][Y])});return(0,c.privateSet)(ye,J,Te[X][J]),ye}var _e=function(){function Te(se,ye){var Xe=this,K=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};B(this,Te),$(K);var T=Fe(se,ye,K,this),k=(0,d.default)(T),ge=j(k);if(ye)(0,c.privateSet)(this,X,ye),(0,c.privateSet)(this,S,null),(0,c.privateSet)(this,V,ye[V]),me(this,se),(0,c.privateSet)(this,W,ye[W]),(0,c.privateSet)(this,H,ye[w]),(0,c.privateSet)(this,J,null);else{if(!k.isValidElement(se))throw new TypeError("ShallowWrapper can only wrap valid elements");var he=ge.getChildContext.calledByRenderer?Be(se,k):null;(0,c.privateSet)(this,X,this),(0,c.privateSet)(this,S,se);var Ve=k.createRenderer((0,C.default)({mode:"shallow"},T));(0,c.privateSet)(this,V,Ve);var De=new Map(T[J]||[]);this[V].render(se,T.context,{providerValues:De});var qe=this[V].getNode();me(this,te(qe)),(0,c.privateSet)(this,W,T),(0,c.privateSet)(this,J,De);var mt=qe.instance;mt&&!T.disableLifecycleMethods&&(ge.componentDidUpdate.onSetState&&!mt[R]&&((0,c.privateSet)(mt,R,mt.setState),mt.setState=function(vt){var ct=arguments.length>1&&arguments[1]!==void 0?arguments[1]:void 0;return Xe.setState.apply(Xe,Z(ct==null?[vt]:[vt,ct]))}),typeof mt.componentDidMount=="function"&&this[V].batchedUpdates(function(){mt.componentDidMount()}),Ne(k,this,mt,qe,he))}}return I(Te,[{key:"root",value:function(){function se(){return this[X]}return se}()},{key:"getNodeInternal",value:function(){function se(){if(this.length!==1)throw new Error("ShallowWrapper::getNode() can only be called when wrapping one node");return this[X]===this&&this.update(),this[v]}return se}()},{key:"getNodesInternal",value:function(){function se(){return this[X]===this&&this.length===1&&this.update(),this[w]}return se}()},{key:"getElement",value:function(){function se(){var ye=this;return this.single("getElement",function(Xe){return(0,d.default)(ye[W]).nodeToElement(Xe)})}return se}()},{key:"getElements",value:function(){function se(){var ye=this;return this.getNodesInternal().map(function(Xe){return(0,d.default)(ye[W]).nodeToElement(Xe)})}return se}()},{key:"getNode",value:function(){function se(){throw new Error("ShallowWrapper::getNode() is no longer supported. Use ShallowWrapper::getElement() instead")}return se}()},{key:"getNodes",value:function(){function se(){throw new Error("ShallowWrapper::getNodes() is no longer supported. Use ShallowWrapper::getElements() instead")}return se}()},{key:"instance",value:function(){function se(){if(this[X]!==this)throw new Error("ShallowWrapper::instance() can only be called on the root");return this[V].getNode().instance}return se}()},{key:"getWrappingComponent",value:function(){function se(){if(this[X]!==this)throw new Error("ShallowWrapper::getWrappingComponent() can only be called on the root");if(!this[W].wrappingComponent)throw new Error("ShallowWrapper::getWrappingComponent() can only be called on a wrapper that was originally passed a `wrappingComponent` option");return this[D]}return se}()},{key:"update",value:function(){function se(){if(this[X]!==this)throw new Error("ShallowWrapper::update() can only be called on the root");if(this.length!==1)throw new Error("ShallowWrapper::update() can only be called when wrapping one node");return me(this,te(this[V].getNode())),this}return se}()},{key:"unmount",value:function(){function se(){return this[V].unmount(),this[X][D]&&this[X][D].unmount(),this}return se}()},{key:"rerender",value:function(){function se(ye,Xe){var K=this,T=(0,d.default)(this[W]);return this.single("rerender",function(){(0,c.withSetStateAllowed)(function(){var k=K[V].getNode(),ge=k.instance||{},he=k.type||{},Ve=ge.state,De=ge.props||K[S].props,qe=ge.context||K[W].context,mt=Xe||qe;Xe&&(K[W]=(0,C.default)({},K[W],{context:mt})),K[V].batchedUpdates(function(){var vt=j(T),ct=!0,Ht=void 0,ne=void 0;if(!K[W].disableLifecycleMethods&&ge){if(typeof ge.shouldComponentUpdate=="function"){var F=vt.getDerivedStateFromProps;F&&F.hasShouldComponentUpdateBug&&Se(k,Ve),Ht=(0,c.spyMethod)(ge,"shouldComponentUpdate")}vt.getChildContext.calledByRenderer&&typeof ge.getChildContext=="function"&&(ne=(0,c.spyMethod)(ge,"getChildContext"))}if(!Ht&&Ze(ge)&&(ct=Ce(De,ye,Ve,ge.state)),ye&&(K[S]=(0,c.cloneElement)(T,K[S],ye)),K[V].render(K[S],mt,{providerValues:K[J]}),Ht&&(ct=Ht.getLastReturnValue(),Ht.restore()),ct&&!K[W].disableLifecycleMethods&&ge)if(Ne(T,K,ge,k,ne),vt.getSnapshotBeforeUpdate){var _=void 0;typeof ge.getSnapshotBeforeUpdate=="function"&&(_=ge.getSnapshotBeforeUpdate(De,Ve)),vt.componentDidUpdate&&typeof ge.componentDidUpdate=="function"&&(!Ve||(0,l.default)(Ve,K.instance().state)||typeof he.getDerivedStateFromProps=="function")&&ge.componentDidUpdate(De,Ve,_)}else vt.componentDidUpdate&&typeof ge.componentDidUpdate=="function"&&(vt.componentDidUpdate.prevContext?ge.componentDidUpdate(De,Ve,qe):(!Ve||(0,l.default)(K.instance().state,Ve))&&ge.componentDidUpdate(De,Ve));else(0,l.default)(ye,ge.props)||(ge.props=(Object.freeze||Object)((0,C.default)({},ge.props,ye)));K.update()})})}),this}return se}()},{key:"setProps",value:function(){function se(ye){var Xe=arguments.length>1&&arguments[1]!==void 0?arguments[1]:void 0;if(this[X]!==this)throw new Error("ShallowWrapper::setProps() can only be called on the root");if(arguments.length>1&&typeof Xe!="function")throw new TypeError("ReactWrapper::setProps() expects a function as its second argument");return this.rerender(ye),Xe&&Xe(),this}return se}()},{key:"setState",value:function(){function se(ye){var Xe=this,K=arguments.length>1&&arguments[1]!==void 0?arguments[1]:void 0;if(this[X]!==this)throw new Error("ShallowWrapper::setState() can only be called on the root");if(this.instance()===null||this[V].getNode().nodeType!=="class")throw new Error("ShallowWrapper::setState() can only be called on class components");if(arguments.length>1&&typeof K!="function")throw new TypeError("ReactWrapper::setState() expects a function as its second argument");return this.single("setState",function(){(0,c.withSetStateAllowed)(function(){var T=(0,d.default)(Xe[W]),k=j(T),ge=Xe[V].getNode(),he=ge.instance,Ve=he.props,De=he.state,qe=he.context,mt=typeof ye=="function"?ye.call(he,De,Ve):ye,vt=!k.setState.skipsComponentDidUpdateOnNullish||mt!=null,ct=void 0,Ht=void 0,ne=!0;if(!Xe[W].disableLifecycleMethods&&he){if(k.componentDidUpdate&&k.componentDidUpdate.onSetState&&typeof he.shouldComponentUpdate=="function"){var F=k.getDerivedStateFromProps;F&&F.hasShouldComponentUpdateBug&&Se(ge,ye),ct=(0,c.spyMethod)(he,"shouldComponentUpdate")}k.getChildContext.calledByRenderer&&typeof he.getChildContext=="function"&&(Ht=(0,c.spyMethod)(he,"getChildContext"))}if(!ct&&Ze(he)&&(ne=Ce(Ve,he.props,De,(0,C.default)({},De,mt))),he[R]?he[R](mt):he.setState(mt),ct&&(ne=ct.getLastReturnValue(),ct.restore()),vt&&ne&&!Xe[W].disableLifecycleMethods&&(Ne(T,Xe,he,ge,Ht),k.componentDidUpdate&&k.componentDidUpdate.onSetState))if(k.getSnapshotBeforeUpdate&&typeof he.getSnapshotBeforeUpdate=="function"){var _=he.getSnapshotBeforeUpdate(Ve,De);typeof he.componentDidUpdate=="function"&&he.componentDidUpdate(Ve,De,_)}else typeof he.componentDidUpdate=="function"&&(k.componentDidUpdate.prevContext?he.componentDidUpdate(Ve,De,qe):he.componentDidUpdate(Ve,De));Xe.update(),K&&(T.invokeSetStateCallback?T.invokeSetStateCallback(he,K):K.call(he))})}),this}return se}()},{key:"setContext",value:function(){function se(ye){if(this[X]!==this)throw new Error("ShallowWrapper::setContext() can only be called on the root");if(!this[W].context)throw new Error("ShallowWrapper::setContext() can only be called on a wrapper that was originally passed a context option");return this.rerender(null,ye)}return se}()},{key:"contains",value:function(){function se(ye){var Xe=(0,d.default)(this[W]);if(!(0,c.isReactElementAlike)(ye,Xe))throw new Error("ShallowWrapper::contains() can only be called with a ReactElement (or an array of them), a string, or a number as an argument.");var K=Array.isArray(ye)?function(T){return(0,c.containsChildrenSubArray)(c.nodeEqual,T,ye.map(function(k){return Xe.elementToNode(k)}))}:function(T){return(0,c.nodeEqual)(Xe.elementToNode(ye),T)};return ee(this,K).length>0}return se}()},{key:"containsMatchingElement",value:function(){function se(ye){var Xe=(0,d.default)(this[W]),K=Xe.elementToNode(ye),T=function(){function k(ge){return(0,c.nodeMatches)(K,ge,function(he,Ve){return he<=Ve})}return k}();return ee(this,T).length>0}return se}()},{key:"containsAllMatchingElements",value:function(){function se(ye){var Xe=this;if(!Array.isArray(ye))throw new TypeError("nodes should be an Array");return ye.every(function(K){return Xe.containsMatchingElement(K)})}return se}()},{key:"containsAnyMatchingElements",value:function(){function se(ye){var Xe=this;return Array.isArray(ye)&&ye.some(function(K){return Xe.containsMatchingElement(K)})}return se}()},{key:"equals",value:function(){function se(ye){var Xe=this;return this.single("equals",function(){return(0,c.nodeEqual)(Xe.getNodeInternal(),ye)})}return se}()},{key:"matchesElement",value:function(){function se(ye){var Xe=this;return this.single("matchesElement",function(){var K=(0,d.default)(Xe[W]),T=K.elementToNode(ye);return(0,c.nodeMatches)(T,Xe.getNodeInternal(),function(k,ge){return k<=ge})})}return se}()},{key:"find",value:function(){function se(ye){return this.wrap((0,f.reduceTreesBySelector)(ye,this.getNodesInternal()))}return se}()},{key:"is",value:function(){function se(ye){var Xe=(0,f.buildPredicate)(ye);return this.single("is",function(K){return Xe(K)})}return se}()},{key:"isEmptyRender",value:function(){function se(){var ye=this.getNodesInternal();return ye.every(function(Xe){return(0,c.isEmptyValue)(Xe)})}return se}()},{key:"filterWhere",value:function(){function se(ye){var Xe=this;return q(this,function(K){return ye(Xe.wrap(K))})}return se}()},{key:"filter",value:function(){function se(ye){var Xe=(0,f.buildPredicate)(ye);return q(this,Xe)}return se}()},{key:"not",value:function(){function se(ye){var Xe=(0,f.buildPredicate)(ye);return q(this,function(K){return!Xe(K)})}return se}()},{key:"text",value:function(){function se(){return this.single("text",m.getTextFromNode)}return se}()},{key:"html",value:function(){function se(){var ye=this;return this.single("html",function(Xe){if(ye.type()===null)return null;var K=(0,d.default)(ye[W]),T=K.createRenderer((0,C.default)({},ye[W],{mode:"string"}));return T.render(K.nodeToElement(Xe))})}return se}()},{key:"render",value:function(){function se(){var ye=this.html();return(0,c.loadCheerioRoot)(ye)}return se}()},{key:"simulate",value:function(){function se(ye){for(var Xe=this,K=arguments.length,T=Array(K>1?K-1:0),k=1;k0?Xe.first():this.findWhere(function(){return!1})}return se}()},{key:"shallow",value:function(){function se(){var ye=this,Xe=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};return this.single("shallow",function(K){var T=Ue(ye,Xe);return ye.wrap((0,d.default)(ye[W]).nodeToElement(K),null,T)})}return se}()},{key:"prop",value:function(){function se(ye){return this.props()[ye]}return se}()},{key:"invoke",value:function(){function se(ye){var Xe=this;return this.single("invoke",function(){var K=Xe.prop(ye);if(typeof K!="function")throw new TypeError("ShallowWrapper::invoke() requires the name of a prop whose value is a function");return function(){var T=K.apply(void 0,arguments);return Xe[X].update(),T}})}return se}()},{key:"renderProp",value:function(){function se(ye){var Xe=this,K=(0,d.default)(this[W]);if(typeof K.wrap!="function")throw new RangeError("your adapter does not support `wrap`. Try upgrading it!");return this.single("renderProp",function(T){if(T.nodeType==="host")throw new TypeError("ShallowWrapper::renderProp() can only be called on custom components");if(typeof ye!="string")throw new TypeError("ShallowWrapper::renderProp(): `propName` must be a string");var k=Xe.props();if(!(0,s.default)(k,ye))throw new Error("ShallowWrapper::renderProp(): no prop called “"+String(ye)+"“ found");var ge=k[ye];if(typeof ge!="function")throw new TypeError("ShallowWrapper::renderProp(): expected prop “"+String(ye)+"“ to contain a function, but it holds “"+(typeof ge>"u"?"undefined":i(ge))+"“");return function(){var he=ge.apply(void 0,arguments),Ve=K.wrap(he);return Xe.wrap(Ve,null,Xe[W])}})}return se}()},{key:"key",value:function(){function se(){return this.single("key",function(ye){return ye.key===void 0?null:ye.key})}return se}()},{key:"type",value:function(){function se(){return this.single("type",function(ye){return(0,c.typeOfNode)(ye)})}return se}()},{key:"name",value:function(){function se(){var ye=(0,d.default)(this[W]);return this.single("name",function(Xe){return ye.displayNameOfNode?ye.displayNameOfNode(Xe):(0,c.displayNameOfNode)(Xe)})}return se}()},{key:"hasClass",value:function(){function se(ye){return typeof ye=="string"&&ye.indexOf(".")!==-1&&console.warn("It looks like you're calling `ShallowWrapper::hasClass()` with a CSS selector. hasClass() expects a class name, not a CSS selector."),this.single("hasClass",function(Xe){return(0,m.hasClassName)(Xe,ye)})}return se}()},{key:"forEach",value:function(){function se(ye){var Xe=this;return this.getNodesInternal().forEach(function(K,T){return ye.call(Xe,Xe.wrap(K),T)}),this}return se}()},{key:"map",value:function(){function se(ye){var Xe=this;return this.getNodesInternal().map(function(K,T){return ye.call(Xe,Xe.wrap(K),T)})}return se}()},{key:"reduce",value:function(){function se(ye){var Xe=this,K=arguments.length>1&&arguments[1]!==void 0?arguments[1]:void 0;return arguments.length>1?this.getNodesInternal().reduce(function(T,k,ge){return ye.call(Xe,T,Xe.wrap(k),ge)},K):this.getNodesInternal().reduce(function(T,k,ge){return ye.call(Xe,ge===1?Xe.wrap(T):T,Xe.wrap(k),ge)})}return se}()},{key:"reduceRight",value:function(){function se(ye){var Xe=this,K=arguments.length>1&&arguments[1]!==void 0?arguments[1]:void 0;return arguments.length>1?this.getNodesInternal().reduceRight(function(T,k,ge){return ye.call(Xe,T,Xe.wrap(k),ge)},K):this.getNodesInternal().reduceRight(function(T,k,ge){return ye.call(Xe,ge===1?Xe.wrap(T):T,Xe.wrap(k),ge)})}return se}()},{key:"slice",value:function(){function se(ye,Xe){return this.wrap(this.getNodesInternal().slice(ye,Xe))}return se}()},{key:"some",value:function(){function se(ye){if(this[X]===this)throw new Error("ShallowWrapper::some() can not be called on the root");var Xe=(0,f.buildPredicate)(ye);return this.getNodesInternal().some(Xe)}return se}()},{key:"someWhere",value:function(){function se(ye){var Xe=this;return this.getNodesInternal().some(function(K,T){return ye.call(Xe,Xe.wrap(K),T)})}return se}()},{key:"every",value:function(){function se(ye){var Xe=(0,f.buildPredicate)(ye);return this.getNodesInternal().every(Xe)}return se}()},{key:"everyWhere",value:function(){function se(ye){var Xe=this;return this.getNodesInternal().every(function(K,T){return ye.call(Xe,Xe.wrap(K),T)})}return se}()},{key:"flatMap",value:function(){function se(ye){var Xe=this,K=this.getNodesInternal().map(function(k,ge){return ye.call(Xe,Xe.wrap(k),ge)}),T=(0,o.default)(K,1);return this.wrap(T.filter(Boolean))}return se}()},{key:"findWhere",value:function(){function se(ye){var Xe=this;return ee(this,function(K){var T=Xe.wrap(K);return T.length>0&&ye(T)})}return se}()},{key:"get",value:function(){function se(ye){return this.getElements()[ye]}return se}()},{key:"at",value:function(){function se(ye){var Xe=this.getNodesInternal();return ye0&&arguments[0]!==void 0?arguments[0]:null;return arguments.length>0?this.find(ye).exists():this.length>0}return se}()},{key:"single",value:function(){function se(ye,Xe){var K=typeof ye=="string"?ye:"unknown",T=typeof Xe=="function"?Xe:ye;if(this.length!==1)throw new Error("Method “"+K+"” is meant to be run on 1 node. "+String(this.length)+" found instead.");return T.call(this,this.getNodeInternal())}return se}()},{key:"wrap",value:function(){function se(ye){var Xe=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this[X];if(ye instanceof Te)return ye;for(var K=arguments.length,T=Array(K>2?K-2:0),k=2;k0&&arguments[0]!==void 0?arguments[0]:{};return(0,h.debugNodes)(this.getNodesInternal(),ye)}return se}()},{key:"tap",value:function(){function se(ye){return ye(this),this}return se}()},{key:"dive",value:function(){function se(){var ye=this,Xe=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},K=(0,d.default)(this[W]),T="dive";return this.single(T,function(k){if(k&&k.nodeType==="host")throw new TypeError("ShallowWrapper::"+T+"() can not be called on Host Components");var ge=(0,d.default)(ye[W]).nodeToElement(k);if(!(0,c.isCustomComponentElement)(ge,K))throw new TypeError("ShallowWrapper::"+T+"() can only be called on components");var he=Ue(ye,Xe);return ye.wrap(ge,null,he)})}return se}()},{key:"hostNodes",value:function(){function se(){return this.filterWhere(function(ye){return typeof ye.type()=="string"})}return se}()}]),Te}();function ot(Te){var se=(0,d.default)(Te[W]),ye=Te[E],Xe=ye[V],K=Xe.getNode(),T=ze(Te,se),k=T.legacyContext,ge=T.providerValues,he=ye[J];if(ye.setContext((0,C.default)({},Te[E][W].context,k)),ye[J]=new Map([].concat(Z(he),Z(ge))),typeof se.isContextConsumer=="function"&&se.isContextConsumer(K.type)){var Ve=K.type,De=se.getProviderFromConsumer(Ve),qe=ge.get(De),mt=he.get(De);qe!==mt&&ye.rerender()}}var Zt=function(Te){y(se,Te);function se(ye,Xe,K){B(this,se);var T=p(this,(se.__proto__||Object.getPrototypeOf(se)).call(this,ye));return(0,c.privateSet)(T,E,Xe),(0,c.privateSet)(T,O,K),T}return I(se,[{key:"rerender",value:function(){function ye(){for(var Xe,K=arguments.length,T=Array(K),k=0;k1&&arguments[1]!==void 0?arguments[1]:{},a=(0,n.default)(s),l=a.createRenderer((0,I.default)({mode:"string"},s)),c=l.render(A,s.context);return(0,C.loadCheerioRoot)(c)}})(kVe);var XSt=kQ,HSt=Cy(XSt),TSt=Hj,NSt=Cy(TSt),kSt=Uwe,YSt=Cy(kSt),KSt=TVe,xSt=Cy(KSt),DSt=NVe,FSt=Cy(DSt),ESt=kVe,MSt=Cy(ESt),zSt=pm;function Cy(g){return g&&g.__esModule?g:{default:g}}var PSt={render:MSt.default,shallow:FSt.default,mount:xSt.default,ShallowWrapper:NSt.default,ReactWrapper:HSt.default,configure:zSt.merge,EnzymeAdapter:YSt.default};const Tj=100,JSt=(g,e,I,i)=>{for(const{viewId:n,trackId:C,track:r}of g.instance().iterateOverTracks())n===e&&C===I&&(r.options={...r.options,...i});g.setState(g.instance().state)},OSt=g=>{for(const e of g.iterateOverTracks())if(sBe(g,e.viewId,e.trackId).activeTransitions>0)return!0;return!1},YVe=(g,e)=>{OSt(g)?setTimeout(()=>{YVe(g,e)},Tj):e()},Nj=g=>{Mv>0?setTimeout(()=>Nj(g),Tj):g()},LSt=g=>{for(const e of g.iterateOverTracks()){let I=NQ(g,e.viewId,e.trackId);if(!(!e.track.server&&!e.track.tilesetUid&&!(e.track.data&&e.track.data.type==="divided")))if(e.track.data&&e.track.data.type==="divided"||e.track.server&&e.track.tilesetUid){if(I.originalTrack&&(I=I.originalTrack),!(I.tilesetInfo||I.chromInfo)||I.fetching&&I.fetching.size)return!0}else throw Error('"server" and "tilesetUid" belong together')}return!1},sH=(g,e)=>{LSt(g)?setTimeout(()=>{sH(g,e)},Tj):e()},KVe=(g,e,I,i,n={})=>{const{style:C="width:800px; background-color: lightgreen;",bounded:r=!1,extendedDelay:o=!1}=n;e&&(e.unmount(),e.detach()),g&&globalThis.document.body.removeChild(g);const A=globalThis.document.createElement("div");globalThis.document.body.appendChild(A),A.setAttribute("style",C),A.setAttribute("id","simple-hg-component");const s=PSt.mount(N.createElement(yy,{options:{bounded:r},viewConfig:I}),{attachTo:A});return s.update(),Nj(()=>{if(o){const a=()=>setTimeout(()=>{i()},1e3);sH(s.instance(),a)}else sH(s.instance(),i)}),[A,s]},_St=g=>{g&&(QI.unmountComponentAtNode(g),document.body.removeChild(g))};async function USt(g,e,I,i){let n;return await new Promise(C=>{n=KVe(g,e,I,C,i)}),n}var A0=0,nG=0,uZ=0,xVe=1e3,lH,CG,cH=0,Zh=0,Ek=0,$v=typeof performance=="object"&&performance.now?performance:Date,DVe=typeof window=="object"&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(g){setTimeout(g,17)};function kj(){return Zh||(DVe(QSt),Zh=$v.now()+Ek)}function QSt(){Zh=0}function uH(){this._call=this._time=this._next=null}uH.prototype=FVe.prototype={constructor:uH,restart:function(g,e,I){if(typeof g!="function")throw new TypeError("callback is not a function");I=(I==null?kj():+I)+(e==null?0:+e),!this._next&&CG!==this&&(CG?CG._next=this:lH=this,CG=this),this._call=g,this._time=I,Mz()},stop:function(){this._call&&(this._call=null,this._time=1/0,Mz())}};function FVe(g,e,I){var i=new uH;return i.restart(g,e,I),i}function jSt(){kj(),++A0;for(var g=lH,e;g;)(e=Zh-g._time)>=0&&g._call.call(void 0,e),g=g._next;--A0}function NCe(){Zh=(cH=$v.now())+Ek,A0=nG=0;try{jSt()}finally{A0=0,qSt(),Zh=0}}function $St(){var g=$v.now(),e=g-cH;e>xVe&&(Ek-=e,cH=g)}function qSt(){for(var g,e=lH,I,i=1/0;e;)e._call?(i>e._time&&(i=e._time),g=e,e=e._next):(I=e._next,e._next=null,e=g?g._next=I:lH=I);CG=g,Mz(i)}function Mz(g){if(!A0){nG&&(nG=clearTimeout(nG));var e=g-Zh;e>24?(g<1/0&&(nG=setTimeout(NCe,g-$v.now()-Ek)),uZ&&(uZ=clearInterval(uZ))):(uZ||(cH=$v.now(),uZ=setInterval($St,xVe)),A0=1,DVe(NCe))}}function kCe(g,e,I){var i=new uH;return e=e==null?0:+e,i.restart(n=>{i.stop(),g(n+e)},e,I),i}var ewt=O0("start","end","cancel","interrupt"),twt=[],EVe=0,zz=1,Pz=2,uW=3,YCe=4,Jz=5,dW=6;function Mk(g,e,I,i,n,C){var r=g.__transition;if(!r)g.__transition={};else if(I in r)return;gwt(g,I,{name:e,index:i,group:n,on:ewt,tween:twt,time:C.time,delay:C.delay,duration:C.duration,ease:C.ease,timer:null,state:EVe})}function Yj(g,e){var I=GA(g,e);if(I.state>EVe)throw new Error("too late; already scheduled");return I}function Ya(g,e){var I=GA(g,e);if(I.state>uW)throw new Error("too late; already running");return I}function GA(g,e){var I=g.__transition;if(!I||!(I=I[e]))throw new Error("transition not found");return I}function gwt(g,e,I){var i=g.__transition,n;i[e]=I,I.timer=FVe(C,0,I.time);function C(s){I.state=zz,I.timer.restart(r,I.delay,I.time),I.delay<=s&&r(s-I.delay)}function r(s){var a,l,c,u;if(I.state!==zz)return A();for(a in i)if(u=i[a],u.name===I.name){if(u.state===uW)return kCe(r);u.state===YCe?(u.state=dW,u.timer.stop(),u.on.call("interrupt",g,g.__data__,u.index,u.group),delete i[a]):+aPz&&i.state=0&&(e=e.slice(0,I)),!e||e==="start"})}function Hwt(g,e,I){var i,n,C=Xwt(e)?Yj:Ya;return function(){var r=C(this,g),o=r.on;o!==i&&(n=(i=o).copy()).on(e,I),r.on=n}}function Twt(g,e){var I=this._id;return arguments.length<2?GA(this.node(),I).on.on(g):this.each(Hwt(I,g,e))}function Nwt(g){return function(){var e=this.parentNode;for(var I in this.__transition)if(+I!==g)return;e&&e.removeChild(this)}}function kwt(){return this.on("end.remove",Nwt(this._id))}function Ywt(g){var e=this._name,I=this._id;typeof g!="function"&&(g=US(g));for(var i=this._groups,n=i.length,C=new Array(n),r=0;rzz&&i.name===e)return new Va([[g]],rVt,e,+n)}return null}const AVt=Object.freeze(Object.defineProperty({__proto__:null,active:oVt,interrupt:bB,transition:PVe},Symbol.toStringTag,{value:"Module"})),WR=g=>()=>g;function aVt(g,{sourceEvent:e,target:I,transform:i,dispatch:n}){Object.defineProperties(this,{type:{value:g,enumerable:!0,configurable:!0},sourceEvent:{value:e,enumerable:!0,configurable:!0},target:{value:I,enumerable:!0,configurable:!0},transform:{value:i,enumerable:!0,configurable:!0},_:{value:n}})}function sa(g,e,I){this.k=g,this.x=e,this.y=I}sa.prototype={constructor:sa,scale:function(g){return g===1?this:new sa(this.k*g,this.x,this.y)},translate:function(g,e){return g===0&e===0?this:new sa(this.k,this.x+this.k*g,this.y+this.k*e)},apply:function(g){return[g[0]*this.k+this.x,g[1]*this.k+this.y]},applyX:function(g){return g*this.k+this.x},applyY:function(g){return g*this.k+this.y},invert:function(g){return[(g[0]-this.x)/this.k,(g[1]-this.y)/this.k]},invertX:function(g){return(g-this.x)/this.k},invertY:function(g){return(g-this.y)/this.k},rescaleX:function(g){return g.copy().domain(g.range().map(this.invertX,this).map(g.invert,g))},rescaleY:function(g){return g.copy().domain(g.range().map(this.invertY,this).map(g.invert,g))},toString:function(){return"translate("+this.x+","+this.y+") scale("+this.k+")"}};var Fi=new sa(1,0,0);OVe.prototype=sa.prototype;function OVe(g){for(;!g.__zoom;)if(!(g=g.parentNode))return Fi;return g.__zoom}function ND(g){g.stopImmediatePropagation()}function dZ(g){g.preventDefault(),g.stopImmediatePropagation()}function sVt(g){return(!g.ctrlKey||g.type==="wheel")&&!g.button}function lVt(){var g=this;return g instanceof SVGElement?(g=g.ownerSVGElement||g,g.hasAttribute("viewBox")?(g=g.viewBox.baseVal,[[g.x,g.y],[g.x+g.width,g.y+g.height]]):[[0,0],[g.width.baseVal.value,g.height.baseVal.value]]):[[0,0],[g.clientWidth,g.clientHeight]]}function KCe(){return this.__zoom||Fi}function cVt(g){return-g.deltaY*(g.deltaMode===1?.05:g.deltaMode?1:.002)*(g.ctrlKey?10:1)}function uVt(){return navigator.maxTouchPoints||"ontouchstart"in this}function dVt(g,e,I){var i=g.invertX(e[0][0])-I[0][0],n=g.invertX(e[1][0])-I[1][0],C=g.invertY(e[0][1])-I[0][1],r=g.invertY(e[1][1])-I[1][1];return g.translate(n>i?(i+n)/2:Math.min(0,i)||Math.max(0,n),r>C?(C+r)/2:Math.min(0,C)||Math.max(0,r))}function Oz(){var g=sVt,e=lVt,I=dVt,i=cVt,n=uVt,C=[0,1/0],r=[[-1/0,-1/0],[1/0,1/0]],o=250,A=att,s=O0("start","zoom","end"),a,l,c,u=500,d=150,h=0,m=10;function f(V){V.property("__zoom",KCe).on("wheel.zoom",B,{passive:!1}).on("mousedown.zoom",w).on("dblclick.zoom",R).filter(n).on("touchstart.zoom",S).on("touchmove.zoom",X).on("touchend.zoom touchcancel.zoom",W).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}f.transform=function(V,H,D,Y){var F=V.selection?V.selection():V;F.property("__zoom",KCe),V!==F?Z(V,H,D,Y):F.interrupt().each(function(){v(this,arguments).event(Y).start().zoom(null,typeof H=="function"?H.apply(this,arguments):H).end()})},f.scaleBy=function(V,H,D,Y){f.scaleTo(V,function(){var F=this.__zoom.k,_=typeof H=="function"?H.apply(this,arguments):H;return F*_},D,Y)},f.scaleTo=function(V,H,D,Y){f.transform(V,function(){var F=e.apply(this,arguments),_=this.__zoom,J=D==null?y(F):typeof D=="function"?D.apply(this,arguments):D,te=_.invert(J),q=typeof H=="function"?H.apply(this,arguments):H;return I(p(b(_,q),J,te),F,r)},D,Y)},f.translateBy=function(V,H,D,Y){f.transform(V,function(){return I(this.__zoom.translate(typeof H=="function"?H.apply(this,arguments):H,typeof D=="function"?D.apply(this,arguments):D),e.apply(this,arguments),r)},null,Y)},f.translateTo=function(V,H,D,Y,F){f.transform(V,function(){var _=e.apply(this,arguments),J=this.__zoom,te=Y==null?y(_):typeof Y=="function"?Y.apply(this,arguments):Y;return I(Fi.translate(te[0],te[1]).scale(J.k).translate(typeof H=="function"?-H.apply(this,arguments):-H,typeof D=="function"?-D.apply(this,arguments):-D),_,r)},Y,F)};function b(V,H){return H=Math.max(C[0],Math.min(C[1],H)),H===V.k?V:new sa(H,V.x,V.y)}function p(V,H,D){var Y=H[0]-D[0]*V.k,F=H[1]-D[1]*V.k;return Y===V.x&&F===V.y?V:new sa(V.k,Y,F)}function y(V){return[(+V[0][0]+ +V[1][0])/2,(+V[0][1]+ +V[1][1])/2]}function Z(V,H,D,Y){V.on("start.zoom",function(){v(this,arguments).event(Y).start()}).on("interrupt.zoom end.zoom",function(){v(this,arguments).event(Y).end()}).tween("zoom",function(){var F=this,_=arguments,J=v(F,_).event(Y),te=e.apply(F,_),q=D==null?y(te):typeof D=="function"?D.apply(F,_):D,$=Math.max(te[1][0]-te[0][0],te[1][1]-te[0][1]),j=F.__zoom,ee=typeof H=="function"?H.apply(F,_):H,Q=A(j.invert(q).concat($/j.k),ee.invert(q).concat($/ee.k));return function(ne){if(ne===1)ne=ee;else{var fe=Q(ne),Ce=$/fe[2];ne=new sa(Ce,q[0]-fe[0]*Ce,q[1]-fe[1]*Ce)}J.zoom(null,ne)}})}function v(V,H,D){return!D&&V.__zooming||new G(V,H)}function G(V,H){this.that=V,this.args=H,this.active=0,this.sourceEvent=null,this.extent=e.apply(V,H),this.taps=0}G.prototype={event:function(V){return V&&(this.sourceEvent=V),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(V,H){return this.mouse&&V!=="mouse"&&(this.mouse[1]=H.invert(this.mouse[0])),this.touch0&&V!=="touch"&&(this.touch0[1]=H.invert(this.touch0[0])),this.touch1&&V!=="touch"&&(this.touch1[1]=H.invert(this.touch1[0])),this.that.__zoom=H,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(V){var H=pg(this.that).datum();s.call(V,this.that,new aVt(V,{sourceEvent:this.sourceEvent,target:f,type:V,transform:this.that.__zoom,dispatch:s}),H)}};function B(V,...H){if(!g.apply(this,arguments))return;var D=v(this,H).event(V),Y=this.__zoom,F=Math.max(C[0],Math.min(C[1],Y.k*Math.pow(2,i.apply(this,arguments)))),_=Og(V);if(D.wheel)(D.mouse[0][0]!==_[0]||D.mouse[0][1]!==_[1])&&(D.mouse[1]=Y.invert(D.mouse[0]=_)),clearTimeout(D.wheel);else{if(Y.k===F)return;D.mouse=[_,Y.invert(_)],bB(this),D.start()}dZ(V),D.wheel=setTimeout(J,d),D.zoom("mouse",I(p(b(Y,F),D.mouse[0],D.mouse[1]),D.extent,r));function J(){D.wheel=null,D.end()}}function w(V,...H){if(c||!g.apply(this,arguments))return;var D=V.currentTarget,Y=v(this,H,!0).event(V),F=pg(V.view).on("mousemove.zoom",q,!0).on("mouseup.zoom",$,!0),_=Og(V,D),J=V.clientX,te=V.clientY;ON(V.view),ND(V),Y.mouse=[_,this.__zoom.invert(_)],bB(this),Y.start();function q(j){if(dZ(j),!Y.moved){var ee=j.clientX-J,Q=j.clientY-te;Y.moved=ee*ee+Q*Q>h}Y.event(j).zoom("mouse",I(p(Y.that.__zoom,Y.mouse[0]=Og(j,D),Y.mouse[1]),Y.extent,r))}function $(j){F.on("mousemove.zoom mouseup.zoom",null),LN(j.view,Y.moved),dZ(j),Y.event(j).end()}}function R(V,...H){if(g.apply(this,arguments)){var D=this.__zoom,Y=Og(V.changedTouches?V.changedTouches[0]:V,this),F=D.invert(Y),_=D.k*(V.shiftKey?.5:2),J=I(p(b(D,_),Y,F),e.apply(this,H),r);dZ(V),o>0?pg(this).transition().duration(o).call(Z,J,Y,V):pg(this).call(f.transform,J,Y,V)}}function S(V,...H){if(g.apply(this,arguments)){var D=V.touches,Y=D.length,F=v(this,H,V.changedTouches.length===Y).event(V),_,J,te,q;for(ND(V),J=0;Jr;nthis.tickValues.length;){const r=this.axisTexts.pop();this.pAxis.removeChild(r),r.destroy(!0)}}},{key:"calculateAxisTickValues",value:function(I,i){const n=Math.max(Math.ceil(i/yVt),1);let C=I.ticks(n);return C.length<1&&(C=I.ticks(n+1),C.length>1&&(C=[C[0]])),C}},{key:"drawAxisLeft",value:function(I,i){this.startAxis(i),this.createAxisTexts(I,i);const n=this.pAxis;this.track.getTheme()===II&&n.lineStyle(n.lineWidth||n._lineStyle.width,zt("#ffffff")),n.moveTo(0,0),n.lineTo(-(Yi+bC),0),n.moveTo(0,i),n.lineTo(-(Yi+bC),i);for(let C=0;C=0;I--)this.axisTexts[I].visible=!0;for(let I=this.axisTexts.length-1;I>=0;I--){if(!this.axisTexts[I].visible)continue;let i=I-1;for(;i>=0&&this.axisTexts[I].y+this.axisTexts[I].height/2>this.axisTexts[i].y-this.axisTexts[i].height/2;){this.axisTexts[i].visible=!1;i-=1}}}},{key:"exportVerticalAxis",value:function(I){const i=document.createElement("g");i.setAttribute("class","axis-vertical");let n="black";this.track&&this.track.options.lineStrokeColor&&(n=this.track.options.lineStrokeColor),this.track.getTheme()===II&&(n="#cccccc");const C=document.createElement("path");return C.setAttribute("fill","transparent"),C.setAttribute("stroke",n),C.setAttribute("id","axis-line"),C.setAttribute("d",`M0,0 L0,${I}`),i.appendChild(C),i}},{key:"createAxisSVGLine",value:function(){let I="black";this.track&&this.track.options.lineStrokeColor&&(I=this.track.options.lineStrokeColor),this.track.getTheme()===II&&(I="#cccccc");const i=document.createElement("path");return i.setAttribute("id","tick-mark"),i.setAttribute("fill","transparent"),i.setAttribute("stroke",I),i}},{key:"createAxisSVGText",value:function(I){const i=document.createElement("text");return i.innerHTML=I,i.setAttribute("id","axis-text"),i.setAttribute("text-anchor","middle"),i.setAttribute("font-family",this.axisTextFontFamily),i.setAttribute("font-size",this.axisTextFontSize),i.setAttribute("dy",this.axisTextFontSize/2-2),i}},{key:"exportAxisLeftSVG",value:function(I,i){const n=this.exportVerticalAxis(i),C=this.createAxisSVGLine();n.appendChild(C),C.setAttribute("d",`M0,0 L${+(Yi+bC)},0`);const r=this.createAxisSVGLine();n.appendChild(r),r.setAttribute("d",`M0,${i} L${+(Yi+bC)},${i}`);for(let o=0;o{const I=[];for(let i=g;i{const I=g.map(o=>+o).sort((o,A)=>A-o),i=e.range()[1]-e.range()[0],C=I.map(o=>(e.domain()[1]-e.domain()[0])/o).map(o=>o/i),r=C.filter(o=>o<1);return r.length===0?0:C.indexOf(r[r.length-1])},GVt=(g,e,I,i)=>{const n=g.range()[1]-g.range()[0],C=Math.max((I-e)/(g.domain()[1]-g.domain()[0]),1),o=Math.max(0,Math.ceil(Math.log(n/384)/Math.LN2));let A=Math.round(Math.log(C)/Math.LN2)+o,s=0;return i&&(s=Math.floor(Math.log(256)/Math.log(2)-Math.log(i)/Math.log(2))),A+=s,A},_Ve=(g,e,I)=>{if(typeof I>"u"&&(I=Number.MAX_SAFE_INTEGER),g.resolutions)return ZVt(g.resolutions,e,g.min_pos[0],g.max_pos[0]-2);const i=GVt(e,g.min_pos[0],g.max_pos[0],g.bins_per_dimension||g.tile_size),n=Math.min(i,I);return Math.max(n,0)},BVt=(g,e,I,i,n,C)=>{const r=Math.min(g,n),o=C/2**r,A=1e-7;return LVe(Math.max(0,Math.floor((e.domain()[0]-I)/o)),Math.min(2**r,Math.ceil((e.domain()[1]-I-A)/o)))},vVt=(g,e,I,i=Number.MAX_VALUE,n=256)=>{const r=g*n,o=20,A=Math.max(0,Math.floor((e.domain()[0]-I)/r)),s=Math.ceil(Math.min(i,e.domain()[1]-I-1e-7)/r);let a=LVe(A,s);return a.length>o&&(console.warn(`Too many visible tiles: ${a.length} truncating to ${o}`),a=a.slice(0,o)),a},SVt=(g,e)=>{if(!g)return[];const I=_Ve(g,e,g.max_zoom);if(g.resolutions){const C=g.resolutions.map(A=>+A).sort((A,s)=>s-A);return vVt(C[I],e,g.min_pos[0],g.max_pos[0]).map(A=>[I,A])}return BVt(I,e,g.min_pos[0],g.max_pos[0],g.max_zoom,g.max_width).map(C=>[I,C])},wVt=(g,e)=>{if(g.axis||(g.axis=new zk(g),g.pBase.addChild(g.axis.pAxis)),!g.options.axisPositionVertical&&!g.options.axisPositionHorizontal){g.axis.clearAxis();return}if(g.options.axisPositionVertical&&g.options.axisPositionVertical==="hidden"){g.axis.clearAxis();return}if(g.options.axisPositionHorizontal&&g.options.axisPositionHorizontal==="hidden"){g.axis.clearAxis();return}const I=g.options.axisMargin||0;g.options.axisPositionHorizontal==="left"||g.options.axisPositionVertical==="top"?(g.axis.pAxis.position.x=g.position[0]+I,g.axis.pAxis.position.y=g.position[1],g.axis.drawAxisRight(e,g.dimensions[1])):g.options.axisPositionHorizontal==="outsideLeft"||g.options.axisPositionVertical==="outsideTop"?(g.axis.pAxis.position.x=g.position[0]+I,g.axis.pAxis.position.y=g.position[1],g.axis.drawAxisLeft(e,g.dimensions[1])):g.options.axisPositionHorizontal==="right"||g.options.axisPositionVertical==="bottom"?(g.axis.pAxis.position.x=g.position[0]+g.dimensions[0]-I,g.axis.pAxis.position.y=g.position[1],g.axis.drawAxisLeft(e,g.dimensions[1])):(g.options.axisPositionHorizontal==="outsideRight"||g.options.axisPositionVertical==="outsideBottom")&&(g.axis.pAxis.position.x=g.position[0]+g.dimensions[0]-I,g.axis.pAxis.position.y=g.position[1],g.axis.drawAxisRight(e,g.dimensions[1]))},VVt=(g,e)=>{const I=g.valueScaleTransform,{y:i,k:n}=I,C=g.dimensions[1];i+e/n>-(n-1)*C&&i+e/n<0&&(g.valueScaleTransform=I.translate(0,e/n)),Object.values(g.fetchedTiles).forEach(r=>{r.graphics.position.y=g.valueScaleTransform.y}),g.animate()},RVt=(g,e,I,i)=>{const n=I.k,C=I.y,r=(g-C)/n,o=Math.max(n/e,1);let A=n*r+C-o*r;return A=Math.max(A,-(o-1)*i),A=Math.min(A,0),Fi.translate(0,A).scale(o)},WVt=(g,e)=>{const I=+e.split(".")[0],i=+e.split(".")[1],n=g.max_width,C=g.min_pos[0],r=n/2**I;return{tileX:C+i*r,tileWidth:r}};function XVt(g,e){Object.values(g.fetchedTiles).forEach(I=>{if(!I.drawnAtScale)return;const i=I.drawnAtScale.range(),n=g._xScale.range();if(i[0]!==n[0]||i[1]!==n[1]){g.renderTile(I);return}const C=(I.drawnAtScale.domain()[1]-I.drawnAtScale.domain()[0])/(g._xScale.domain()[1]-g._xScale.domain()[0]);if(C>2||C<.5)g.renderTile(I);else{const o=g._xScale.domain().map(I.drawnAtScale)[0];for(const A of e)A(I).scale.x=C,A(I).x=-o*C}})}const Pd={calculate1DVisibleTiles:SVt,calculate1DZoomLevel:_Ve,drawAxis:wVt,movedY:VVt,getTilePosAndDimensions:WVt,stretchRects:XVt,zoomedY:RVt},HVt=Object.freeze(Object.defineProperty({__proto__:null,DenseDataExtrema1D:Q9,DenseDataExtrema2D:HQ,IS_TRACK_RANGE_SELECTABLE:L0,absToChr:Vi,accessorTransposition:bGe,addArrays:yGe,addClass:Aot,base64ToCanvas:aot,changeOptions:JSt,chrToAbs:D9,chromInfoBisector:pGe,cloneEvent:ZGe,colorDomainToRgbaArray:Cu,colorToHex:zt,colorToRgba:YGe,dataToGenomicLoci:P9,debounce:bQ,decToHexStr:Iz,dictFromTuples:KGe,dictItems:xr,dictKeys:Nr,dictValues:Pg,download:tB,expandCombinedTracks:CW,fillInMinWidths:xGe,flatten:Jot,forEach:Oot,forwardEvent:J9,genomeLociToPixels:Lot,genomicRangeToChromosomeChunks:_ot,getAggregationFunction:TQ,getDefaultTrackForDatatype:yQ,getElementDim:JGe,getTiledPlot:Dat,getTrackByUid:gr,getTrackConfFromHGC:OAt,getTrackObjById:gG,getTrackObjectFromHGC:NQ,getTrackPositionByUid:gB,getTrackRenderer:sBe,getXylofon:LGe,gradient:_Ge,hasClass:x9,hasParent:UGe,hexStrToInt:QGe,intoTheVoid:jGe,isTrackOrChildTrack:$Ge,isWithin:RQ,latToY:tat,lngToX:Iat,loadChromInfos:gat,map:wQ,max:iz,maxNonZero:nz,min:qGe,minNonZero:Cz,mod:iat,mountHGComponent:KVe,mountHGComponentAsync:USt,ndarrayAssign:eBe,ndarrayFlatten:IBe,ndarrayToList:gBe,numericifyVersion:iBe,objVals:jN,or:ow,parseChromsizesRows:$N,pixiTextToSvg:rz,q:fat,rangeQuery2d:pat,reduce:DGe,relToAbsChromPos:bat,removeClass:Zat,removeHGComponent:_St,resetD3BrushStyle:_p,rgbToHex:Gat,scalesCenterAndK:Zi,scalesToGenomeLoci:nBe,segmentsToRows:U9,selectedItemsToSize:Pv,showMousePosition:hh,some:wat,sum:sc,svgLine:CBe,throttleAndDebounce:rBe,tileToCanvas:Vat,timeout:WQ,toVoid:tA,totalTrackPixelHeight:Rat,trackUtils:Pd,trimTrailingSlash:qN,valueToColor:XQ,visitPositionedTracks:os,visitTracks:SQ,waitForJsonComplete:Nj,waitForTilesLoaded:sH,waitForTransitionsFinished:YVe},Symbol.toStringTag,{value:"Module"}));function Lz(){return Lz=Object.assign?Object.assign.bind():function(g){for(var e=1;eN.forwardRef((e,I)=>N.createElement(NVt,null,i=>N.createElement(g,Lz({ref:I},e,{theme:i})))),gc={"track-control":"_track-control_w7hx2_1","track-control-vertical":"_track-control-vertical_w7hx2_2","track-control-dark":"_track-control-dark_w7hx2_15","track-control-active":"_track-control-active_w7hx2_16 _track-control_w7hx2_1","track-control-left":"_track-control-left_w7hx2_24","track-control-vertical-active":"_track-control-vertical-active_w7hx2_30","track-control-padding-right":"_track-control-padding-right_w7hx2_48","track-control-button":"_track-control-button_w7hx2_52","track-control-button-vertical":"_track-control-button-vertical_w7hx2_81"},kVt=g=>Tg({[gc["track-control-active"]]:g.isVisible,[gc["track-control"]]:!g.isVisible,[gc["track-control-left"]]:g.isAlignLeft,[gc["track-control-vertical"]]:g.isVertical,[gc["track-control-padding-right"]]:g.paddingRight,[gc["track-control-dark"]]:g.theme===II}),XR=g=>Tg("no-zoom",gc["track-control-button"],{[gc["track-control-button-vertical"]]:g.isVertical});let kD=null,FCe=null;function UVe(g){(!g||!kD||Object.keys(g).some(i=>kD[i]!==g[i]))&&(kD=g,FCe=q3(()=>N.createElement("svg",{className:XR(g),style:{height:"20px",width:"20px",...g.imgStyleMove}},N.createElement("title",null,"Move track"),N.createElement("use",{xlinkHref:"#move"}))));let e,I;return N.createElement("div",{className:kVt(g)},g.isMoveable&&N.createElement(FCe,null),N.createElement("svg",{ref:i=>{e=i},className:XR(g),onClick:()=>{g.onConfigTrackMenuOpened(g.uid,e.getBoundingClientRect())},style:{height:"20px",width:"20px",...g.imgStyleSettings}},N.createElement("title",null,"Configure track"),N.createElement("use",{xlinkHref:"#cog"})),g.onAddSeries&&N.createElement("svg",{className:XR(g),onClick:()=>g.onAddSeries(g.uid),style:{height:"20px",width:"20px",...g.imgStyleAdd}},N.createElement("title",null,"Add series"),N.createElement("use",{xlinkHref:"#plus"})),N.createElement("svg",{ref:i=>{I=i},className:XR(g),onClick:()=>{g.onCloseTrackMenuOpened(g.uid,I.getBoundingClientRect())},style:{height:"20px",width:"20px",...g.imgStyleClose}},N.createElement("title",null,"Close track"),N.createElement("use",{xlinkHref:"#cross"})))}UVe.propTypes={imgStyleAdd:L.object,imgStyleClose:L.object,imgStyleMove:L.object,imgStyleSettings:L.object,isAlignLeft:L.bool,isMoveable:L.bool,isVertical:L.bool,isVisible:L.bool,onConfigTrackMenuOpened:L.func,onCloseTrackMenuOpened:L.func,onAddSeries:L.func,paddingRight:L.bool,theme:L.symbol.isRequired,uid:L.string};const Pk=ym(UVe),_z={"center-track":"_center-track_fiu64_1","center-track-container":"_center-track-container_fiu64_6"},Lo={"track-range-selection":"_track-range-selection_5bcsr_1","track-range-selection-active":"_track-range-selection-active_5bcsr_8 _track-range-selection_5bcsr_1","track-range-selection-active-primary":"_track-range-selection-active-primary_5bcsr_14 _track-range-selection-active_5bcsr_8 _track-range-selection_5bcsr_1","track-range-selection-active-secondary":"_track-range-selection-active-secondary_5bcsr_18 _track-range-selection-active_5bcsr_8 _track-range-selection_5bcsr_1","track-range-selection-group-inactive":"_track-range-selection-group-inactive_5bcsr_22","track-range-selection-group-brush-selection":"_track-range-selection-group-brush-selection_5bcsr_26"};function YVt(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function ECe(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function dH(g){return dH=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},dH(g)}const HR={pointerEvents:"all"};function If(g){return g&&g.sourceEvent}let xj=function(g){FVt(I,g);var e=EVt(I);function I(i){var n;return YVt(this,I),n=e.call(this,i),n.state={isVisible:!1},n.brushBehaviorX=QN().on("brush",n.brushedX.bind(zl(n))).on("end",n.brushedXEnded.bind(zl(n))),n.brushBehaviorY=nw().on("brush",n.brushedY.bind(zl(n))).on("end",n.brushedYEnded.bind(zl(n))),n.brushBehaviorXY=lQ().on("start",n.brushStarted.bind(zl(n))).on("brush",n.brushedXY.bind(zl(n))).on("end",n.brushedXYEnded.bind(zl(n))),n}return KVt(I,[{key:"componentDidMount",value:function(){this.props.isRangeSelectionActive&&this.addBrush2d()}},{key:"shouldComponentUpdate",value:function(n,C){if(this.rangeSelectionTriggeredXY){if(this.rangeSelectionTriggeredXY=!1,this.rangeSelectionTriggeredXYEnd){const r=n.rangeSelection[0]||null;this.moveBrushXY([r,n.rangeSelection[1]],!0),this.rangeSelectionTriggeredXYEnd=!1}return this.state!==C}if(this.props.rangeSelection!==n.rangeSelection){const r=n.rangeSelection[0]||null;this.props.is1dRangeSelection?(this.rangeSelectionTriggeredX||this.moveBrushX(r,n.rangeSelectionEnd),this.rangeSelectionTriggeredXEnd&&this.moveBrushX(r,n.rangeSelectionEnd,!0),this.rangeSelectionTriggeredY||this.moveBrushY(r,n.rangeSelectionEnd),this.rangeSelectionTriggeredYEnd&&this.moveBrushY(r,n.rangeSelectionEnd,!0),this.rangeSelectionTriggeredX=!1,this.rangeSelectionTriggeredXEnd=!1,this.rangeSelectionTriggeredY=!1,this.rangeSelectionTriggeredYEnd=!1):this.moveBrushXY([r,n.rangeSelection[1]],n.rangeSelectionEnd);const o=this.props.is1dRangeSelection&&!n.is1dRangeSelection&&r===null;return this.state!==C||o}return!0}},{key:"componentDidUpdate",value:function(){this.props.isRangeSelectionActive?this.addBrush2d():(this.removeBrush1d(),this.removeBrush2d())}},{key:"addBrush1d",value:function(){!this.brushElX||!this.brushElY||this.brushElXOld===this.brushElX&&this.brushElYOld===this.brushElY||(this.brushElXOld&&this.brushElXOld.on(".brush",null),this.brushElYOld&&this.brushElYOld.on(".brush",null),this.brushElX.call(this.brushBehaviorX),this.brushElY.call(this.brushBehaviorY),_p(this.brushElX,Lo["track-range-selection-group-brush-selection"]),_p(this.brushElY,Lo["track-range-selection-group-brush-selection"]),this.brushElXOld=this.brushElX,this.brushElYOld=this.brushElY,this.brushIs1dBound=!0)}},{key:"addBrush2d",value:function(){!this.brushElXY||this.brushElXYOld===this.brushElXY||(this.brushElXYOld&&this.brushElXYOld.on(".brush",null),this.brushElXY.call(this.brushBehaviorXY),this.brushElXYOld=this.brushElXY,this.brushIs2dBound=!0,_p(this.brushElXY,Lo["track-range-selection-group-brush-selection"]))}},{key:"brushedX",value:function(n){const C=this.rangeSelectionMoved;this.rangeSelectionMoved=!1,!(!If(n)||!this.props.onRangeSelectionX||!this.props.is1dRangeSelection||C)&&(this.rangeSelectionTriggeredX=!0,this.props.onRangeSelectionX(n.selection))}},{key:"brushedXEnded",value:function(n){const C=this.rangeSelectionMovedEnd;this.rangeSelectionMovedEnd=!1,!(!If(n)||!this.props.onRangeSelectionX||!this.props.is1dRangeSelection||C)&&(this.rangeSelectionTriggeredX=!0,this.rangeSelectionTriggeredXEnd=!0,this.props.onRangeSelectionXEnd(n.selection))}},{key:"brushedY",value:function(n){const C=this.rangeSelectionMoved;this.rangeSelectionMoved=!1,!(!If(n)||!this.props.onRangeSelectionY||!this.props.is1dRangeSelection||C)&&(this.rangeSelectionTriggeredY=!0,this.props.onRangeSelectionY(n.selection))}},{key:"brushedYEnded",value:function(n){const C=this.rangeSelectionMovedEnd;this.rangeSelectionMovedEnd=!1,!(!If(n)||!this.props.onRangeSelectionY||!this.props.is1dRangeSelection||C)&&(this.rangeSelectionTriggeredY=!0,this.rangeSelectionTriggeredYEnd=!0,this.props.onRangeSelectionYEnd(n.selection))}},{key:"brushedXY",value:function(n){const C=this.rangeSelectionMoved;this.rangeSelectionMoved=!1,!(!If(n)||!this.props.onRangeSelectionXY||C||this.props.is1dRangeSelection)&&(this.rangeSelectionTriggeredXY=!0,this.props.onRangeSelectionXY([[n.selection[0][0],n.selection[1][0]],[n.selection[0][1],n.selection[1][1]]]))}},{key:"brushedXYEnded",value:function(n){if(this.props.is1dRangeSelection)return;const C=this.rangeSelectionMovedEnd;this.rangeSelectionMovedEnd=!1,n.selection&&n.sourceEvent&&this.props.onRangeSelectionXY&&!C&&(this.rangeSelectionTriggeredXY=!0,this.rangeSelectionTriggeredXYEnd=!0,this.props.onRangeSelectionXYEnd([[n.selection[0][0],n.selection[1][0]],[n.selection[0][1],n.selection[1][1]]])),n.selection||(this.rangeSelectionTriggeredXY=!0,this.props.onRangeSelectionReset())}},{key:"brushStarted",value:function(n){If(n)&&this.props.onRangeSelectionStart()}},{key:"moveBrushX",value:function(n,C=!1){if(!this.brushEl)return;this.brushIs2dBound&&(this.removeBrush2d(),this.addBrush1d());const r=n?[this.props.scaleX(n[0]),this.props.scaleX(n[1])]:null;this.rangeSelectionMoved=!0,this.rangeSelectionMovedEnd=!0,C?this.brushElX.transition().call(this.brushBehaviorX.move,r):this.brushElX.call(this.brushBehaviorX.move,r)}},{key:"moveBrushY",value:function(n,C=!1){if(!this.brushEl)return;this.brushIs2dBound&&(this.removeBrush2d(),this.addBrush1d());const r=n?[this.props.scaleY(n[0]),this.props.scaleY(n[1])]:null;this.rangeSelectionMoved=!0,this.rangeSelectionMovedEnd=!0,C?this.brushElY.transition().call(this.brushBehaviorY.move,r):this.brushElY.call(this.brushBehaviorY.move,r)}},{key:"moveBrushXY",value:function(n,C=!1){if(!this.brushEl)return;const r=[[this.props.scaleX(n[0][0]),this.props.scaleY(n[1][0])],[this.props.scaleX(n[0][1]),this.props.scaleY(n[1][1])]];this.rangeSelectionMoved=!0,this.rangeSelectionMovedEnd=!0,C?this.brushElXY.transition().call(this.brushBehaviorXY.move,r):this.brushElXY.call(this.brushBehaviorXY.move,r)}},{key:"mouseEnterHandler",value:function(){this.props.isRangeSelectionActive||this.setState({isVisible:!0})}},{key:"mouseLeaveHandler",value:function(){this.setState({isVisible:!1})}},{key:"removeBrush1d",value:function(){this.brushIs1dBound&&(this.brushElX&&(this.brushElX.call(this.brushBehaviorX.move,null),this.brushElX.on(".brush",null)),this.brushElY&&(this.brushElY.call(this.brushBehaviorY.move,null),this.brushElY.on(".brush",null)),this.brushIs1dBound=!1)}},{key:"removeBrush2d",value:function(){this.brushIs2dBound&&this.brushElXY&&(this.brushElXY.call(this.brushBehaviorXY.move,null),this.brushElXY.on(".brush",null),this.brushElXYOld=void 0,this.brushIs2dBound=!1,this.props.is1dRangeSelection||this.props.onRangeSelectionReset())}},{key:"render",value:function(){const n=this.props.tracks.map(s=>L0(s)).reduce(ow,!1),C=this.props.tracks.some(s=>s.contents?s.contents.some(a=>a.type==="heatmap"?a.options.colorbarPosition==="topRight":!1):s.type==="heatmap"?s.options.colorbarPosition==="topRight":!1);let r="track-range-selection";this.props.isRangeSelectionActive&&(r+=this.props.is1dRangeSelection?"-active-secondary":"-active-primary");const o=Tg(!this.props.is1dRangeSelection&&Lo["track-range-selection-group-inactive"]),A=Tg(this.props.is1dRangeSelection&&Lo["track-range-selection-group-inactive"]);return N.createElement("div",{className:Tg(this.props.className,_z["center-track"]),onMouseEnter:this.mouseEnterHandler.bind(this),onMouseLeave:this.mouseLeaveHandler.bind(this),style:{height:this.props.height,width:this.props.width}},n&&N.createElement("svg",{className:Lo[r],style:{height:this.props.height,width:this.props.width},xmlns:"http://www.w3.org/2000/svg"},N.createElement("g",{ref:s=>{this.brushElX=pg(s)},className:o}),N.createElement("g",{ref:s=>{this.brushElY=pg(s)},className:o}),N.createElement("g",{ref:s=>{this.brushElXY=pg(s)},className:A})),this.props.editable&&N.createElement(Pk,{imgStyleAdd:HR,imgStyleClose:HR,imgStyleMove:HR,imgStyleSettings:HR,isMoveable:!1,isVisible:this.state.isVisible||this.props.uid===this.props.configTrackMenuId,onAddSeries:this.props.onAddSeries,onCloseTrackMenuOpened:this.props.onCloseTrackMenuOpened,onConfigTrackMenuOpened:this.props.onConfigTrackMenuOpened,paddingRight:C,uid:this.props.uid}))}}]),I}(N.Component);xj.defaultProps={className:"center-track",configTrackMenuId:null,is1dRangeSelection:!1,rangeSelectionEnd:L.bool,isRangeSelectionActive:!1,scaleX:g=>g,scaleY:g=>g};xj.propTypes={className:L.string,configTrackMenuId:L.string,editable:L.bool,height:L.number.isRequired,is1dRangeSelection:L.bool,isRangeSelectionActive:L.bool,onAddSeries:L.func.isRequired,onCloseTrackMenuOpened:L.func.isRequired,onConfigTrackMenuOpened:L.func.isRequired,onRangeSelectionX:L.func.isRequired,onRangeSelectionXEnd:L.func.isRequired,onRangeSelectionY:L.func.isRequired,onRangeSelectionYEnd:L.func.isRequired,onRangeSelectionXY:L.func.isRequired,onRangeSelectionXYEnd:L.func.isRequired,onRangeSelectionReset:L.func.isRequired,onRangeSelectionStart:L.func.isRequired,rangeSelection:L.array.isRequired,rangeSelectionEnd:L.bool,scaleX:L.func,scaleY:L.func,tracks:L.array.isRequired,uid:L.string.isRequired,width:L.number.isRequired};function Qz(){return Qz=Object.assign?Object.assign.bind():function(g){for(var e=1;e({event:"fake",handler:tA}),unsubscribe:tA,clear:tA},{Provider:PVt,Consumer:JVt}=N.createContext(Dj),ry=g=>N.forwardRef((e,I)=>N.createElement(JVt,null,i=>N.createElement(g,Qz({ref:I},e,{pubSub:i})))),OVt={"drag-listening-div-active":"_drag-listening-div-active_19gkt_1"};function LVt(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function MCe(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function hH(g){return hH=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},hH(g)}let Fj=function(g){jVt(I,g);var e=$Vt(I);function I(i){var n;return LVt(this,I),n=e.call(this,i),n.state={dragOnTop:!1},n}return _Vt(I,[{key:"render",value:function(){let n="red";return this.props.enabled&&this.state.dragOnTop?n="green":this.props.enabled&&(n="blue"),N.createElement("div",{className:Tg("DragListeningDiv",{[OVt["drag-listening-div-active"]]:this.props.enabled}),onDragEnter:()=>{this.setState({dragOnTop:!0})},onDragLeave:()=>{this.setState({dragOnTop:!1})},onDragOver:C=>{C.preventDefault()},onDrop:()=>{if(!this.props.enabled)return;const C=this.props.draggingHappening,r={type:this.props.defaultTrackType,uid:dg.nice(),tilesetUid:C.tilesetUid,server:C.server};this.props.onTrackDropped(r),this.props.pubSub.publish("trackDropped",r)},style:{background:n,opacity:.6,...this.props.style}})}}]),I}(N.Component);Fj.defaultProps={enabled:!1,style:{},draggingHappening:{},onTrackDropped:()=>{}};Fj.propTypes={enabled:L.bool,style:L.object,defaultTrackType:L.object,draggingHappening:L.object,onTrackDropped:L.func,position:L.string.isRequired,pubSub:L.object.isRequired};const TR=ry(Fj),zu={"gallery-tracks":"_gallery-tracks_fbxxi_1","gallery-track":"_gallery-track_fbxxi_1","gallery-sub-track":"_gallery-sub-track_fbxxi_18","gallery-invisible-track":"_gallery-invisible-track_fbxxi_19"},gRt="_horizontalList_1y7td_7",IRt="_list_1y7td_14",iRt="_stylizedList_1y7td_21",nRt="_stylizedItem_1y7td_28",CRt="_stylizedHelper_1y7td_39",rRt="_horizontalItem_1y7td_44",oRt="_domain_1y7td_60",_o={"tiled-plot":"_tiled-plot_1y7td_1",horizontalList:gRt,list:IRt,stylizedList:iRt,stylizedItem:nRt,stylizedHelper:CRt,horizontalItem:rRt,"resizable-track":"_resizable-track_1y7td_55",domain:oRt};function ARt(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function zCe(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function mH(g){return mH=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},mH(g)}const NR={pointerEvents:"all"};let QVe=function(g){cRt(I,g);var e=uRt(I);function I(i){var n;return ARt(this,I),n=e.call(this,i),n.state={hovering:!1},n}return aRt(I,[{key:"mouseEnterHandler",value:function(){this.setState({hovering:!0})}},{key:"mouseLeaveHandler",value:function(){this.setState({hovering:!1})}},{key:"render",value:function(){return N.createElement("div",{className:Tg("gallery-tracks",zu["gallery-tracks"])},this.props.tracks&&this.props.tracks.map((n,C)=>N.createElement("div",{key:n.uid||C,className:zu["gallery-track"],onMouseLeave:this.mouseLeaveHandler.bind(this),style:{top:n.height*C,right:n.height*C,bottom:n.height*C,left:n.height*C}},N.createElement("div",{className:zu["gallery-sub-track"],onMouseEnter:this.mouseEnterHandler.bind(this),style:{top:0,right:0,left:0,height:n.height}}),N.createElement("div",{className:zu["gallery-sub-track"],onMouseEnter:this.mouseEnterHandler.bind(this),style:{top:0,right:0,bottom:0,width:n.height}}),N.createElement("div",{className:zu["gallery-sub-track"],onMouseEnter:this.mouseEnterHandler.bind(this),style:{right:0,bottom:0,left:0,height:n.height}}),N.createElement("div",{className:zu["gallery-sub-track"],onMouseEnter:this.mouseEnterHandler.bind(this),style:{top:0,bottom:0,left:0,width:n.height}}),N.createElement("div",{className:zu["gallery-invisible-track"],onMouseLeave:this.mouseLeaveHandler.bind(this),style:{top:n.height,right:n.height,bottom:n.height,left:n.height}}),this.props.editable&&N.createElement(Pk,{configMenuVisible:!0,imgStyleAdd:NR,imgStyleClose:NR,imgStyleMove:NR,imgStyleSettings:NR,isMoveable:!1,isVisible:this.state.hovering,onCloseTrackMenuOpened:this.props.onCloseTrackMenuOpened,onConfigTrackMenuOpened:this.props.onConfigTrackMenuOpened,uid:n.uid||C}))))}}]),I}(N.Component);QVe.propTypes={editable:L.bool,onCloseTrackMenuOpened:L.func.isRequired,onConfigTrackMenuOpened:L.func.isRequired,tracks:L.array};function fRt(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function PCe(g,e){for(var I=0;I{}),this.pubSubs.push(this.pubSub.subscribe("app.mouseMove",this.defaultMouseMoveHandler.bind(this))),this.isLeftModified=!1}return pRt(g,[{key:"isWithin",value:function(I,i){let n=I,C=i,r=this.position[0],o=this.position[1];return this.isLeftModified&&(n=i,C=I,r=this.position[1],o=this.position[0]),RQ(n,C,r,this.dimensions[0]+r,o,this.dimensions[1]+o)}},{key:"getProp",value:function(I){return()=>this[I]}},{key:"getData",value:function(){}},{key:"click",value:function(I,i,n){return{type:"generic",event:n,payload:null}}},{key:"clickOutside",value:function(){}},{key:"getDimensions",value:function(){return this.dimensions}},{key:"setDimensions",value:function(I){this.dimensions=I,this._xScale.range([0,this.dimensions[0]]),this._yScale.range([0,this.dimensions[1]])}},{key:"refXScale",value:function(I){return I?(this._refXScale=I,this):this._refXScale}},{key:"refYScale",value:function(I){return I?(this._refYScale=I,this):this._refYScale}},{key:"xScale",value:function(I){return I?(this._xScale=I,this):this._xScale}},{key:"yScale",value:function(I){return I?(this._yScale=I,this):this._yScale}},{key:"zoomed",value:function(I,i){this.xScale(I),this.yScale(i)}},{key:"refScalesChanged",value:function(I,i){this._refXScale=I,this._refYScale=i}},{key:"draw",value:function(){}},{key:"getPosition",value:function(){return this.position}},{key:"setPosition",value:function(I){this.position=I}},{key:"defaultMouseMoveHandler",value:function(I){}},{key:"remove",value:function(){this.pubSubs.forEach(I=>this.pubSub.unsubscribe(I)),this.pubSubs=[]}},{key:"rerender",value:function(I){}},{key:"respondsToPosition",value:function(I,i){return this.isWithin(I,i)}},{key:"zoomedY",value:function(I,i){}},{key:"movedY",value:function(I){}}]),g}();function ZRt(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function JCe(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function a0(g){return a0=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},a0(g)}function HRt(g,e){const I=J0(e,g);return Am(`.${I}`,g)(g)}function TRt(g,e){const I=g.map(C=>+C).sort((C,r)=>r-C),i=I[e],n=I[I.length-1];return HRt(i,n)}function NRt(g,e,I,i){const n=e/(2**g*I);if(!Number.isNaN(n)){const C=e/(2**i*I),r=J0(C,n);return Am(`.${r}`,n)(n)}return console.warn("NaN resolution, screen is probably too small."),""}let dC=function(g){wRt(I,g);var e=VRt(I);function I(i,n){var C;ZRt(this,I),C=e.call(this,i,n);const{scene:r}=i;C.scene=r,C.delayDrawing=!1,C.pBase=new Ct.PIXI.Graphics,C.pMasked=new Ct.PIXI.Graphics,C.pMask=new Ct.PIXI.Graphics,C.pMain=new Ct.PIXI.Graphics,C.pBorder=new Ct.PIXI.Graphics,C.pBackground=new Ct.PIXI.Graphics,C.pForeground=new Ct.PIXI.Graphics,C.pLabel=new Ct.PIXI.Graphics,C.pMobile=new Ct.PIXI.Graphics,C.pAxis=new Ct.PIXI.Graphics,C.pMouseOver=new Ct.PIXI.Graphics,C.scene.addChild(C.pBase),C.pBase.addChild(C.pMasked),C.pMasked.addChild(C.pBackground),C.pMasked.addChild(C.pMain),C.pMasked.addChild(C.pMask),C.pMasked.addChild(C.pMobile),C.pMasked.addChild(C.pBorder),C.pMasked.addChild(C.pLabel),C.pMasked.addChild(C.pForeground),C.pMasked.addChild(C.pMouseOver),C.pBase.addChild(C.pAxis),C.pMasked.mask=C.pMask,C.prevOptions="",C.options=Object.assign(C.options,n);const o=C.getName();return C.labelTextFontFamily="Arial",C.labelTextFontSize=12,C.labelXOffset=0,C.labelText=new Ct.PIXI.Text(o,{fontSize:`${C.labelTextFontSize}px`,fontFamily:C.labelTextFontFamily,fill:"black"}),C.pLabel.addChild(C.labelText),C.errorText=new Ct.PIXI.Text("",{fontSize:"12px",fontFamily:"Arial",fill:"red"}),C.errorText.anchor.x=.5,C.errorText.anchor.y=.5,C.pLabel.addChild(C.errorText),C.errorTextText="",C.flipText=!1,C.tilesetInfo=void 0,C}return GRt(I,[{key:"setLabelText",value:function(){}},{key:"setPosition",value:function(n){this.position=n,this.drawBorder(),this.drawLabel(),this.drawBackground(),this.setMask(this.position,this.dimensions),this.setForeground()}},{key:"setDimensions",value:function(n){hW(a0(I.prototype),"setDimensions",this).call(this,n),this.drawBorder(),this.drawLabel(),this.drawBackground(),this.setMask(this.position,this.dimensions),this.setForeground()}},{key:"setMask",value:function(n,C){this.pMask.clear(),this.pMask.beginFill(),this.pMask.drawRect(n[0],n[1],C[0],C[1]),this.pMask.endFill()}},{key:"setForeground",value:function(){this.pForeground.position.y=this.position[1],this.pForeground.position.x=this.position[0]}},{key:"remove",value:function(){this.pBase.clear(),this.scene.removeChild(this.pBase)}},{key:"drawBorder",value:function(){const n=this.pBorder;if(n.clear(),!this.options||!this.options.trackBorderWidth)return;const C=zt(this.options.trackBorderColor?this.options.trackBorderColor:"white");n.lineStyle(this.options.trackBorderWidth,C),n.drawRect(this.position[0],this.position[1],this.dimensions[0],this.dimensions[1])}},{key:"drawError",value:function(){if(this.errorText.x=this.position[0]+this.dimensions[0]/2,this.errorText.y=this.position[1]+this.dimensions[1]/2,this.errorText.text=this.errorTextText,this.errorTextText&&this.errorTextText.length){const n=this.pBorder;n.clear(),n.lineStyle(1,zt("red")),n.drawRect(this.position[0],this.position[1],this.dimensions[0],this.dimensions[1])}}},{key:"drawBackground",value:function(){const n=this.pBackground;if(n.clear(),!this.options||!this.options.backgroundColor)return;let C=1,r=this.options.backgroundColor;this.options.backgroundColor==="transparent"&&(C=0,r="white");const o=zt(r);n.beginFill(o,C),n.drawRect(this.position[0],this.position[1],this.dimensions[0],this.dimensions[1])}},{key:"getLabelColor",value:function(){return this.options.labelColor&&this.options.labelColor!=="[glyph-color]"?this.options.labelColor:this.options.lineStrokeColor||this.options.barFillColor||"black"}},{key:"getName",value:function(){return this.options.name?this.options.name:this.tilesetInfo&&this.tilesetInfo.name||""}},{key:"drawLabel",value:function(){if(!this.labelText)return;const n=this.pLabel;if(n.clear(),!this.options||!this.options.labelPosition||this.options.labelPosition==="hidden"){this.labelText.alpha=0;return}const{labelBackgroundColor:C="white",labelBackgroundOpacity:r=.5}=this.options;n.beginFill(zt(C),+r);const o=zt(this.getLabelColor()),A=2;if(this.dimensions[0]<0)return;let s=this.options.labelShowAssembly&&this.tilesetInfo&&this.tilesetInfo.coordSystem?`${this.tilesetInfo.coordSystem} | `:"";if(s+=this.getName(),this.options.labelShowResolution&&_At(this.tilesetInfo)&&this.tilesetInfo.bins_per_dimension){const d=NRt(this.calculateZoomLevel(),this.tilesetInfo.max_width,this.tilesetInfo.bins_per_dimension,this.tilesetInfo.max_zoom);s+=` -[Current data resolution: ${d}]`}else if(this.options.labelShowResolution&&UAt(this.tilesetInfo)){const d=TRt(this.tilesetInfo.resolutions,this.calculateZoomLevel());s+=` + `+String(se)+` + `)}return ye}(),enumerable:!1,configurable:!1})}nt("node","Consider using the getElement() method instead."),nt("nodes","Consider using the getElements() method instead."),nt("renderer",""),nt("options",""),nt("complexSelector",""),e.default=_e})(qQ);var Gwe={};(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.default=n;var g=gQ,I=i(g);function i(C){return C&&C.__esModule?C:{default:C}}function n(C,r){return new I.default(C,null,r)}})(Gwe);var vwe={};(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.default=n;var g=qQ,I=i(g);function i(C){return C&&C.__esModule?C:{default:C}}function n(C,r){return new I.default(C,null,r)}})(vwe);var Bwe={};(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.default=o;var g=R0,I=r(g),i=Iu,n=r(i),C=NS;function r(A){return A&&A.__esModule?A:{default:A}}function o(A){var s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},a=(0,n.default)(s),l=a.createRenderer((0,I.default)({mode:"string"},s)),c=l.render(A,s.context);return(0,C.loadCheerioRoot)(c)}})(Bwe);var AVt=gQ,aVt=E0(AVt),sVt=qQ,lVt=E0(sVt),cVt=xSe,uVt=E0(cVt),dVt=Gwe,hVt=E0(dVt),mVt=vwe,fVt=E0(mVt),pVt=Bwe,bVt=E0(pVt),yVt=gm;function E0(e){return e&&e.__esModule?e:{default:e}}var ZVt={render:bVt.default,shallow:fVt.default,mount:hVt.default,ShallowWrapper:lVt.default,ReactWrapper:aVt.default,configure:yVt.merge,EnzymeAdapter:uVt.default};const ej=100,GVt=(e,g,I,i)=>{for(const{viewId:n,trackId:C,track:r}of e.instance().iterateOverTracks())n===g&&C===I&&(r.options={...r.options,...i});e.setState(e.instance().state)},vVt=e=>{for(const g of e.iterateOverTracks())if(tGe(e,g.viewId,g.trackId).activeTransitions>0)return!0;return!1},Swe=(e,g)=>{vVt(e)?setTimeout(()=>{Swe(e,g)},ej):g()},tj=e=>{hB>0?setTimeout(()=>tj(e),ej):e()},BVt=e=>{for(const g of e.iterateOverTracks()){let I=tQ(e,g.viewId,g.trackId);if(!(!g.track.server&&!g.track.tilesetUid&&!(g.track.data&&g.track.data.type==="divided")))if(g.track.data&&g.track.data.type==="divided"||g.track.server&&g.track.tilesetUid){if(I.originalTrack&&(I=I.originalTrack),!(I.tilesetInfo||I.chromInfo)||I.fetching&&I.fetching.size)return!0}else throw Error('"server" and "tilesetUid" belong together')}return!1},y9=(e,g)=>{BVt(e)?setTimeout(()=>{y9(e,g)},ej):g()},wwe=(e,g,I,i,n={})=>{const{style:C="width:800px; background-color: lightgreen;",bounded:r=!1,extendedDelay:o=!1}=n;g&&(g.unmount(),g.detach()),e&&globalThis.document.body.removeChild(e);const A=globalThis.document.createElement("div");globalThis.document.body.appendChild(A),A.setAttribute("style",C),A.setAttribute("id","simple-hg-component");const s=ZVt.mount(N.createElement(gy,{options:{bounded:r},viewConfig:I}),{attachTo:A});return s.update(),tj(()=>{if(o){const a=()=>setTimeout(()=>{i()},1e3);y9(s.instance(),a)}else y9(s.instance(),i)}),[A,s]},SVt=e=>{e&&(UI.unmountComponentAtNode(e),document.body.removeChild(e))};async function wVt(e,g,I,i){let n;return await new Promise(C=>{n=wwe(e,g,I,C,i)}),n}var Mb=0,TZ=0,jy=0,Vwe=1e3,Z9,NZ,G9=0,Ch=0,UN=0,SB=typeof performance=="object"&&performance.now?performance:Date,Rwe=typeof window=="object"&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(e){setTimeout(e,17)};function gj(){return Ch||(Rwe(VVt),Ch=SB.now()+UN)}function VVt(){Ch=0}function v9(){this._call=this._time=this._next=null}v9.prototype=Wwe.prototype={constructor:v9,restart:function(e,g,I){if(typeof e!="function")throw new TypeError("callback is not a function");I=(I==null?gj():+I)+(g==null?0:+g),!this._next&&NZ!==this&&(NZ?NZ._next=this:Z9=this,NZ=this),this._call=e,this._time=I,rz()},stop:function(){this._call&&(this._call=null,this._time=1/0,rz())}};function Wwe(e,g,I){var i=new v9;return i.restart(e,g,I),i}function RVt(){gj(),++Mb;for(var e=Z9,g;e;)(g=Ch-e._time)>=0&&e._call.call(void 0,g),e=e._next;--Mb}function Une(){Ch=(G9=SB.now())+UN,Mb=TZ=0;try{RVt()}finally{Mb=0,XVt(),Ch=0}}function WVt(){var e=SB.now(),g=e-G9;g>Vwe&&(UN-=g,G9=e)}function XVt(){for(var e,g=Z9,I,i=1/0;g;)g._call?(i>g._time&&(i=g._time),e=g,g=g._next):(I=g._next,g._next=null,g=e?e._next=I:Z9=I);NZ=e,rz(i)}function rz(e){if(!Mb){TZ&&(TZ=clearTimeout(TZ));var g=e-Ch;g>24?(e<1/0&&(TZ=setTimeout(Une,e-SB.now()-UN)),jy&&(jy=clearInterval(jy))):(jy||(G9=SB.now(),jy=setInterval(WVt,Vwe)),Mb=1,Rwe(Une))}}function Qne(e,g,I){var i=new v9;return g=g==null?0:+g,i.restart(n=>{i.stop(),e(n+g)},g,I),i}var HVt=w0("start","end","cancel","interrupt"),TVt=[],Xwe=0,oz=1,Az=2,T1=3,jne=4,az=5,N1=6;function QN(e,g,I,i,n,C){var r=e.__transition;if(!r)e.__transition={};else if(I in r)return;NVt(e,I,{name:g,index:i,group:n,on:HVt,tween:TVt,time:C.time,delay:C.delay,duration:C.duration,ease:C.ease,timer:null,state:Xwe})}function Ij(e,g){var I=hA(e,g);if(I.state>Xwe)throw new Error("too late; already scheduled");return I}function Sa(e,g){var I=hA(e,g);if(I.state>T1)throw new Error("too late; already running");return I}function hA(e,g){var I=e.__transition;if(!I||!(I=I[g]))throw new Error("transition not found");return I}function NVt(e,g,I){var i=e.__transition,n;i[g]=I,I.timer=Wwe(C,0,I.time);function C(s){I.state=oz,I.timer.restart(r,I.delay,I.time),I.delay<=s&&r(s-I.delay)}function r(s){var a,l,c,u;if(I.state!==oz)return A();for(a in i)if(u=i[a],u.name===I.name){if(u.state===T1)return Qne(r);u.state===jne?(u.state=N1,u.timer.stop(),u.on.call("interrupt",e,e.__data__,u.index,u.group),delete i[a]):+aAz&&i.state=0&&(g=g.slice(0,I)),!g||g==="start"})}function aRt(e,g,I){var i,n,C=ARt(g)?Ij:Sa;return function(){var r=C(this,e),o=r.on;o!==i&&(n=(i=o).copy()).on(g,I),r.on=n}}function sRt(e,g){var I=this._id;return arguments.length<2?hA(this.node(),I).on.on(e):this.each(aRt(I,e,g))}function lRt(e){return function(){var g=this.parentNode;for(var I in this.__transition)if(+I!==e)return;g&&g.removeChild(this)}}function cRt(){return this.on("end.remove",lRt(this._id))}function uRt(e){var g=this._name,I=this._id;typeof e!="function"&&(e=hS(e));for(var i=this._groups,n=i.length,C=new Array(n),r=0;roz&&i.name===g)return new ma([[e]],xRt,g,+n)}return null}const ERt=Object.freeze(Object.defineProperty({__proto__:null,active:FRt,interrupt:LG,transition:Nwe},Symbol.toStringTag,{value:"Module"})),tR=e=>()=>e;function MRt(e,{sourceEvent:g,target:I,transform:i,dispatch:n}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:g,enumerable:!0,configurable:!0},target:{value:I,enumerable:!0,configurable:!0},transform:{value:i,enumerable:!0,configurable:!0},_:{value:n}})}function qA(e,g,I){this.k=e,this.x=g,this.y=I}qA.prototype={constructor:qA,scale:function(e){return e===1?this:new qA(this.k*e,this.x,this.y)},translate:function(e,g){return e===0&g===0?this:new qA(this.k,this.x+this.k*e,this.y+this.k*g)},apply:function(e){return[e[0]*this.k+this.x,e[1]*this.k+this.y]},applyX:function(e){return e*this.k+this.x},applyY:function(e){return e*this.k+this.y},invert:function(e){return[(e[0]-this.x)/this.k,(e[1]-this.y)/this.k]},invertX:function(e){return(e-this.x)/this.k},invertY:function(e){return(e-this.y)/this.k},rescaleX:function(e){return e.copy().domain(e.range().map(this.invertX,this).map(e.invert,e))},rescaleY:function(e){return e.copy().domain(e.range().map(this.invertY,this).map(e.invert,e))},toString:function(){return"translate("+this.x+","+this.y+") scale("+this.k+")"}};var Fi=new qA(1,0,0);Ywe.prototype=qA.prototype;function Ywe(e){for(;!e.__zoom;)if(!(e=e.parentNode))return Fi;return e.__zoom}function PD(e){e.stopImmediatePropagation()}function $y(e){e.preventDefault(),e.stopImmediatePropagation()}function zRt(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function PRt(){var e=this;return e instanceof SVGElement?(e=e.ownerSVGElement||e,e.hasAttribute("viewBox")?(e=e.viewBox.baseVal,[[e.x,e.y],[e.x+e.width,e.y+e.height]]):[[0,0],[e.width.baseVal.value,e.height.baseVal.value]]):[[0,0],[e.clientWidth,e.clientHeight]]}function $ne(){return this.__zoom||Fi}function JRt(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function ORt(){return navigator.maxTouchPoints||"ontouchstart"in this}function _Rt(e,g,I){var i=e.invertX(g[0][0])-I[0][0],n=e.invertX(g[1][0])-I[1][0],C=e.invertY(g[0][1])-I[0][1],r=e.invertY(g[1][1])-I[1][1];return e.translate(n>i?(i+n)/2:Math.min(0,i)||Math.max(0,n),r>C?(C+r)/2:Math.min(0,C)||Math.max(0,r))}function sz(){var e=zRt,g=PRt,I=_Rt,i=JRt,n=ORt,C=[0,1/0],r=[[-1/0,-1/0],[1/0,1/0]],o=250,A=Mgt,s=w0("start","zoom","end"),a,l,c,u=500,d=150,h=0,m=10;function f(R){R.property("__zoom",$ne).on("wheel.zoom",v,{passive:!1}).on("mousedown.zoom",w).on("dblclick.zoom",V).filter(n).on("touchstart.zoom",S).on("touchmove.zoom",X).on("touchend.zoom touchcancel.zoom",W).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}f.transform=function(R,H,Y,D){var E=R.selection?R.selection():R;E.property("__zoom",$ne),R!==E?Z(R,H,Y,D):E.interrupt().each(function(){B(this,arguments).event(D).start().zoom(null,typeof H=="function"?H.apply(this,arguments):H).end()})},f.scaleBy=function(R,H,Y,D){f.scaleTo(R,function(){var E=this.__zoom.k,O=typeof H=="function"?H.apply(this,arguments):H;return E*O},Y,D)},f.scaleTo=function(R,H,Y,D){f.transform(R,function(){var E=g.apply(this,arguments),O=this.__zoom,J=Y==null?y(E):typeof Y=="function"?Y.apply(this,arguments):Y,ee=O.invert(J),q=typeof H=="function"?H.apply(this,arguments):H;return I(p(b(O,q),J,ee),E,r)},Y,D)},f.translateBy=function(R,H,Y,D){f.transform(R,function(){return I(this.__zoom.translate(typeof H=="function"?H.apply(this,arguments):H,typeof Y=="function"?Y.apply(this,arguments):Y),g.apply(this,arguments),r)},null,D)},f.translateTo=function(R,H,Y,D,E){f.transform(R,function(){var O=g.apply(this,arguments),J=this.__zoom,ee=D==null?y(O):typeof D=="function"?D.apply(this,arguments):D;return I(Fi.translate(ee[0],ee[1]).scale(J.k).translate(typeof H=="function"?-H.apply(this,arguments):-H,typeof Y=="function"?-Y.apply(this,arguments):-Y),O,r)},D,E)};function b(R,H){return H=Math.max(C[0],Math.min(C[1],H)),H===R.k?R:new qA(H,R.x,R.y)}function p(R,H,Y){var D=H[0]-Y[0]*R.k,E=H[1]-Y[1]*R.k;return D===R.x&&E===R.y?R:new qA(R.k,D,E)}function y(R){return[(+R[0][0]+ +R[1][0])/2,(+R[0][1]+ +R[1][1])/2]}function Z(R,H,Y,D){R.on("start.zoom",function(){B(this,arguments).event(D).start()}).on("interrupt.zoom end.zoom",function(){B(this,arguments).event(D).end()}).tween("zoom",function(){var E=this,O=arguments,J=B(E,O).event(D),ee=g.apply(E,O),q=Y==null?y(ee):typeof Y=="function"?Y.apply(E,O):Y,$=Math.max(ee[1][0]-ee[0][0],ee[1][1]-ee[0][1]),j=E.__zoom,te=typeof H=="function"?H.apply(E,O):H,U=A(j.invert(q).concat($/j.k),te.invert(q).concat($/te.k));return function(ie){if(ie===1)ie=te;else{var me=U(ie),Ce=$/me[2];ie=new qA(Ce,q[0]-me[0]*Ce,q[1]-me[1]*Ce)}J.zoom(null,ie)}})}function B(R,H,Y){return!Y&&R.__zooming||new G(R,H)}function G(R,H){this.that=R,this.args=H,this.active=0,this.sourceEvent=null,this.extent=g.apply(R,H),this.taps=0}G.prototype={event:function(R){return R&&(this.sourceEvent=R),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(R,H){return this.mouse&&R!=="mouse"&&(this.mouse[1]=H.invert(this.mouse[0])),this.touch0&&R!=="touch"&&(this.touch0[1]=H.invert(this.touch0[0])),this.touch1&&R!=="touch"&&(this.touch1[1]=H.invert(this.touch1[0])),this.that.__zoom=H,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(R){var H=cg(this.that).datum();s.call(R,this.that,new MRt(R,{sourceEvent:this.sourceEvent,target:f,type:R,transform:this.that.__zoom,dispatch:s}),H)}};function v(R,...H){if(!e.apply(this,arguments))return;var Y=B(this,H).event(R),D=this.__zoom,E=Math.max(C[0],Math.min(C[1],D.k*Math.pow(2,i.apply(this,arguments)))),O=Eg(R);if(Y.wheel)(Y.mouse[0][0]!==O[0]||Y.mouse[0][1]!==O[1])&&(Y.mouse[1]=D.invert(Y.mouse[0]=O)),clearTimeout(Y.wheel);else{if(D.k===E)return;Y.mouse=[O,D.invert(O)],LG(this),Y.start()}$y(R),Y.wheel=setTimeout(J,d),Y.zoom("mouse",I(p(b(D,E),Y.mouse[0],Y.mouse[1]),Y.extent,r));function J(){Y.wheel=null,Y.end()}}function w(R,...H){if(c||!e.apply(this,arguments))return;var Y=R.currentTarget,D=B(this,H,!0).event(R),E=cg(R.view).on("mousemove.zoom",q,!0).on("mouseup.zoom",$,!0),O=Eg(R,Y),J=R.clientX,ee=R.clientY;eN(R.view),PD(R),D.mouse=[O,this.__zoom.invert(O)],LG(this),D.start();function q(j){if($y(j),!D.moved){var te=j.clientX-J,U=j.clientY-ee;D.moved=te*te+U*U>h}D.event(j).zoom("mouse",I(p(D.that.__zoom,D.mouse[0]=Eg(j,Y),D.mouse[1]),D.extent,r))}function $(j){E.on("mousemove.zoom mouseup.zoom",null),tN(j.view,D.moved),$y(j),D.event(j).end()}}function V(R,...H){if(e.apply(this,arguments)){var Y=this.__zoom,D=Eg(R.changedTouches?R.changedTouches[0]:R,this),E=Y.invert(D),O=Y.k*(R.shiftKey?.5:2),J=I(p(b(Y,O),D,E),g.apply(this,H),r);$y(R),o>0?cg(this).transition().duration(o).call(Z,J,D,R):cg(this).call(f.transform,J,D,R)}}function S(R,...H){if(e.apply(this,arguments)){var Y=R.touches,D=Y.length,E=B(this,H,R.changedTouches.length===D).event(R),O,J,ee,q;for(PD(R),J=0;Jr;nthis.tickValues.length;){const r=this.axisTexts.pop();this.pAxis.removeChild(r),r.destroy(!0)}}},{key:"calculateAxisTickValues",value:function(I,i){const n=Math.max(Math.ceil(i/qRt),1);let C=I.ticks(n);return C.length<1&&(C=I.ticks(n+1),C.length>1&&(C=[C[0]])),C}},{key:"drawAxisLeft",value:function(I,i){this.startAxis(i),this.createAxisTexts(I,i);const n=this.pAxis;this.track.getTheme()===qg&&n.lineStyle(n.lineWidth||n._lineStyle.width,Kt("#ffffff")),n.moveTo(0,0),n.lineTo(-(Yi+mC),0),n.moveTo(0,i),n.lineTo(-(Yi+mC),i);for(let C=0;C=0;I--)this.axisTexts[I].visible=!0;for(let I=this.axisTexts.length-1;I>=0;I--){if(!this.axisTexts[I].visible)continue;let i=I-1;for(;i>=0&&this.axisTexts[I].y+this.axisTexts[I].height/2>this.axisTexts[i].y-this.axisTexts[i].height/2;){this.axisTexts[i].visible=!1;i-=1}}}},{key:"exportVerticalAxis",value:function(I){const i=document.createElement("g");i.setAttribute("class","axis-vertical");let n="black";this.track&&this.track.options.lineStrokeColor&&(n=this.track.options.lineStrokeColor),this.track.getTheme()===qg&&(n="#cccccc");const C=document.createElement("path");return C.setAttribute("fill","transparent"),C.setAttribute("stroke",n),C.setAttribute("id","axis-line"),C.setAttribute("d",`M0,0 L0,${I}`),i.appendChild(C),i}},{key:"createAxisSVGLine",value:function(){let I="black";this.track&&this.track.options.lineStrokeColor&&(I=this.track.options.lineStrokeColor),this.track.getTheme()===qg&&(I="#cccccc");const i=document.createElement("path");return i.setAttribute("id","tick-mark"),i.setAttribute("fill","transparent"),i.setAttribute("stroke",I),i}},{key:"createAxisSVGText",value:function(I){const i=document.createElement("text");return i.innerHTML=I,i.setAttribute("id","axis-text"),i.setAttribute("text-anchor","middle"),i.setAttribute("font-family",this.axisTextFontFamily),i.setAttribute("font-size",this.axisTextFontSize),i.setAttribute("dy",this.axisTextFontSize/2-2),i}},{key:"exportAxisLeftSVG",value:function(I,i){const n=this.exportVerticalAxis(i),C=this.createAxisSVGLine();n.appendChild(C),C.setAttribute("d",`M0,0 L${+(Yi+mC)},0`);const r=this.createAxisSVGLine();n.appendChild(r),r.setAttribute("d",`M0,${i} L${+(Yi+mC)},${i}`);for(let o=0;o{const I=[];for(let i=e;i{const I=e.map(o=>+o).sort((o,A)=>A-o),i=g.range()[1]-g.range()[0],C=I.map(o=>(g.domain()[1]-g.domain()[0])/o).map(o=>o/i),r=C.filter(o=>o<1);return r.length===0?0:C.indexOf(r[r.length-1])},t1t=(e,g,I,i)=>{const n=e.range()[1]-e.range()[0],C=Math.max((I-g)/(e.domain()[1]-e.domain()[0]),1),o=Math.max(0,Math.ceil(Math.log(n/384)/Math.LN2));let A=Math.round(Math.log(C)/Math.LN2)+o,s=0;return i&&(s=Math.floor(Math.log(256)/Math.log(2)-Math.log(i)/Math.log(2))),A+=s,A},Dwe=(e,g,I)=>{if(typeof I>"u"&&(I=Number.MAX_SAFE_INTEGER),e.resolutions)return e1t(e.resolutions,g,e.min_pos[0],e.max_pos[0]-2);const i=t1t(g,e.min_pos[0],e.max_pos[0],e.bins_per_dimension||e.tile_size),n=Math.min(i,I);return Math.max(n,0)},g1t=(e,g,I,i,n,C)=>{const r=Math.min(e,n),o=C/2**r,A=1e-7;return Kwe(Math.max(0,Math.floor((g.domain()[0]-I)/o)),Math.min(2**r,Math.ceil((g.domain()[1]-I-A)/o)))},I1t=(e,g,I,i=Number.MAX_VALUE,n=256)=>{const r=e*n,o=20,A=Math.max(0,Math.floor((g.domain()[0]-I)/r)),s=Math.ceil(Math.min(i,g.domain()[1]-I-1e-7)/r);let a=Kwe(A,s);return a.length>o&&(console.warn(`Too many visible tiles: ${a.length} truncating to ${o}`),a=a.slice(0,o)),a},i1t=(e,g)=>{if(!e)return[];const I=Dwe(e,g,e.max_zoom);if(e.resolutions){const C=e.resolutions.map(A=>+A).sort((A,s)=>s-A);return I1t(C[I],g,e.min_pos[0],e.max_pos[0]).map(A=>[I,A])}return g1t(I,g,e.min_pos[0],e.max_pos[0],e.max_zoom,e.max_width).map(C=>[I,C])},n1t=(e,g)=>{if(e.axis||(e.axis=new jN(e),e.pBase.addChild(e.axis.pAxis)),!e.options.axisPositionVertical&&!e.options.axisPositionHorizontal){e.axis.clearAxis();return}if(e.options.axisPositionVertical&&e.options.axisPositionVertical==="hidden"){e.axis.clearAxis();return}if(e.options.axisPositionHorizontal&&e.options.axisPositionHorizontal==="hidden"){e.axis.clearAxis();return}const I=e.options.axisMargin||0;e.options.axisPositionHorizontal==="left"||e.options.axisPositionVertical==="top"?(e.axis.pAxis.position.x=e.position[0]+I,e.axis.pAxis.position.y=e.position[1],e.axis.drawAxisRight(g,e.dimensions[1])):e.options.axisPositionHorizontal==="outsideLeft"||e.options.axisPositionVertical==="outsideTop"?(e.axis.pAxis.position.x=e.position[0]+I,e.axis.pAxis.position.y=e.position[1],e.axis.drawAxisLeft(g,e.dimensions[1])):e.options.axisPositionHorizontal==="right"||e.options.axisPositionVertical==="bottom"?(e.axis.pAxis.position.x=e.position[0]+e.dimensions[0]-I,e.axis.pAxis.position.y=e.position[1],e.axis.drawAxisLeft(g,e.dimensions[1])):(e.options.axisPositionHorizontal==="outsideRight"||e.options.axisPositionVertical==="outsideBottom")&&(e.axis.pAxis.position.x=e.position[0]+e.dimensions[0]-I,e.axis.pAxis.position.y=e.position[1],e.axis.drawAxisRight(g,e.dimensions[1]))},C1t=(e,g)=>{const I=e.valueScaleTransform,{y:i,k:n}=I,C=e.dimensions[1];i+g/n>-(n-1)*C&&i+g/n<0&&(e.valueScaleTransform=I.translate(0,g/n)),Object.values(e.fetchedTiles).forEach(r=>{r.graphics.position.y=e.valueScaleTransform.y}),e.animate()},r1t=(e,g,I,i)=>{const n=I.k,C=I.y,r=(e-C)/n,o=Math.max(n/g,1);let A=n*r+C-o*r;return A=Math.max(A,-(o-1)*i),A=Math.min(A,0),Fi.translate(0,A).scale(o)},o1t=(e,g)=>{const I=+g.split(".")[0],i=+g.split(".")[1],n=e.max_width,C=e.min_pos[0],r=n/2**I;return{tileX:C+i*r,tileWidth:r}};function A1t(e,g){Object.values(e.fetchedTiles).forEach(I=>{if(!I.drawnAtScale)return;const i=I.drawnAtScale.range(),n=e._xScale.range();if(i[0]!==n[0]||i[1]!==n[1]){e.renderTile(I);return}const C=(I.drawnAtScale.domain()[1]-I.drawnAtScale.domain()[0])/(e._xScale.domain()[1]-e._xScale.domain()[0]);if(C>2||C<.5)e.renderTile(I);else{const o=e._xScale.domain().map(I.drawnAtScale)[0];for(const A of g)A(I).scale.x=C,A(I).x=-o*C}})}const Bd={calculate1DVisibleTiles:i1t,calculate1DZoomLevel:Dwe,drawAxis:n1t,movedY:C1t,getTilePosAndDimensions:o1t,stretchRects:A1t,zoomedY:r1t},a1t=Object.freeze(Object.defineProperty({__proto__:null,DenseDataExtrema1D:C9,DenseDataExtrema2D:q7,IS_TRACK_RANGE_SELECTABLE:V0,absToChr:Vi,accessorTransposition:aZe,addArrays:sZe,addClass:EAt,base64ToCanvas:MAt,changeOptions:GVt,chrToAbs:UX,chromInfoBisector:AZe,cloneEvent:lZe,colorDomainToRgbaArray:Dc,colorToHex:Kt,colorToRgba:SZe,dataToGenomicLoci:e9,debounce:E7,decToHexStr:Z3,dictFromTuples:wZe,dictItems:Rr,dictKeys:Br,dictValues:xg,download:RG,expandCombinedTracks:B1,fillInMinWidths:VZe,flatten:Gat,forEach:vat,forwardEvent:t9,genomeLociToPixels:Bat,genomicRangeToChromosomeChunks:Sat,getAggregationFunction:eQ,getDefaultTrackForDatatype:M7,getElementDim:kZe,getTiledPlot:mlt,getTrackByUid:jC,getTrackConfFromHGC:vst,getTrackObjById:WZ,getTrackObjectFromHGC:tQ,getTrackPositionByUid:WG,getTrackRenderer:tGe,getXylofon:KZe,gradient:DZe,hasClass:LX,hasParent:xZe,hexStrToInt:FZe,intoTheVoid:EZe,isTrackOrChildTrack:MZe,isWithin:Q7,latToY:Tst,lngToX:kst,loadChromInfos:Nst,map:L7,max:G3,maxNonZero:v3,min:zZe,minNonZero:B3,mod:Yst,mountHGComponent:wwe,mountHGComponentAsync:wVt,ndarrayAssign:PZe,ndarrayFlatten:_Ze,ndarrayToList:OZe,numericifyVersion:LZe,objVals:nN,or:RS,parseChromsizesRows:CN,pixiTextToSvg:S3,q:Qst,rangeQuery2d:jst,reduce:RZe,relToAbsChromPos:$st,removeClass:elt,removeHGComponent:SVt,resetD3BrushStyle:Bp,rgbToHex:tlt,scalesCenterAndK:yi,scalesToGenomeLoci:UZe,segmentsToRows:n9,selectedItemsToSize:fB,showMousePosition:eh,some:nlt,sum:Pl,svgLine:QZe,throttleAndDebounce:jZe,tileToCanvas:Clt,timeout:j7,toVoid:_o,totalTrackPixelHeight:rlt,trackUtils:Bd,trimTrailingSlash:rN,valueToColor:$7,visitPositionedTracks:Qa,visitTracks:_7,waitForJsonComplete:tj,waitForTilesLoaded:y9,waitForTransitionsFinished:Swe},Symbol.toStringTag,{value:"Module"}));function lz(){return lz=Object.assign?Object.assign.bind():function(e){for(var g=1;gN.forwardRef((g,I)=>N.createElement(l1t,null,i=>N.createElement(e,lz({ref:I},g,{theme:i})))),Kl={"track-control":"_track-control_w7hx2_1","track-control-vertical":"_track-control-vertical_w7hx2_2","track-control-dark":"_track-control-dark_w7hx2_15","track-control-active":"_track-control-active_w7hx2_16 _track-control_w7hx2_1","track-control-left":"_track-control-left_w7hx2_24","track-control-vertical-active":"_track-control-vertical-active_w7hx2_30","track-control-padding-right":"_track-control-padding-right_w7hx2_48","track-control-button":"_track-control-button_w7hx2_52","track-control-button-vertical":"_track-control-button-vertical_w7hx2_81"},c1t=e=>Vg({[Kl["track-control-active"]]:e.isVisible,[Kl["track-control"]]:!e.isVisible,[Kl["track-control-left"]]:e.isAlignLeft,[Kl["track-control-vertical"]]:e.isVertical,[Kl["track-control-padding-right"]]:e.paddingRight,[Kl["track-control-dark"]]:e.theme===qg}),gR=e=>Vg("no-zoom",Kl["track-control-button"],{[Kl["track-control-button-vertical"]]:e.isVertical});let JD=null,tCe=null;function xwe(e){(!e||!JD||Object.keys(e).some(i=>JD[i]!==e[i]))&&(JD=e,tCe=f3(()=>N.createElement("svg",{className:gR(e),style:{height:"20px",width:"20px",...e.imgStyleMove}},N.createElement("title",null,"Move track"),N.createElement("use",{xlinkHref:"#move"}))));let g,I;return N.createElement("div",{className:c1t(e)},e.isMoveable&&N.createElement(tCe,null),N.createElement("svg",{ref:i=>{g=i},className:gR(e),onClick:()=>{e.onConfigTrackMenuOpened(e.uid,g.getBoundingClientRect())},style:{height:"20px",width:"20px",...e.imgStyleSettings}},N.createElement("title",null,"Configure track"),N.createElement("use",{xlinkHref:"#cog"})),e.onAddSeries&&N.createElement("svg",{className:gR(e),onClick:()=>e.onAddSeries(e.uid),style:{height:"20px",width:"20px",...e.imgStyleAdd}},N.createElement("title",null,"Add series"),N.createElement("use",{xlinkHref:"#plus"})),N.createElement("svg",{ref:i=>{I=i},className:gR(e),onClick:()=>{e.onCloseTrackMenuOpened(e.uid,I.getBoundingClientRect())},style:{height:"20px",width:"20px",...e.imgStyleClose}},N.createElement("title",null,"Close track"),N.createElement("use",{xlinkHref:"#cross"})))}xwe.propTypes={imgStyleAdd:L.object,imgStyleClose:L.object,imgStyleMove:L.object,imgStyleSettings:L.object,isAlignLeft:L.bool,isMoveable:L.bool,isVertical:L.bool,isVisible:L.bool,onConfigTrackMenuOpened:L.func,onCloseTrackMenuOpened:L.func,onAddSeries:L.func,paddingRight:L.bool,theme:L.symbol.isRequired,uid:L.string};const $N=im(xwe),cz={"center-track":"_center-track_fiu64_1","center-track-container":"_center-track-container_fiu64_6"},Fo={"track-range-selection":"_track-range-selection_5bcsr_1","track-range-selection-active":"_track-range-selection-active_5bcsr_8 _track-range-selection_5bcsr_1","track-range-selection-active-primary":"_track-range-selection-active-primary_5bcsr_14 _track-range-selection-active_5bcsr_8 _track-range-selection_5bcsr_1","track-range-selection-active-secondary":"_track-range-selection-active-secondary_5bcsr_18 _track-range-selection-active_5bcsr_8 _track-range-selection_5bcsr_1","track-range-selection-group-inactive":"_track-range-selection-group-inactive_5bcsr_22","track-range-selection-group-brush-selection":"_track-range-selection-group-brush-selection_5bcsr_26"};function u1t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function gCe(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function B9(e){return B9=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},B9(e)}const IR={pointerEvents:"all"};function Fm(e){return e&&e.sourceEvent}let nj=function(e){f1t(I,e);var g=p1t(I);function I(i){var n;return u1t(this,I),n=g.call(this,i),n.state={isVisible:!1},n.brushBehaviorX=iN().on("brush",n.brushedX.bind(Sl(n))).on("end",n.brushedXEnded.bind(Sl(n))),n.brushBehaviorY=SS().on("brush",n.brushedY.bind(Sl(n))).on("end",n.brushedYEnded.bind(Sl(n))),n.brushBehaviorXY=T7().on("start",n.brushStarted.bind(Sl(n))).on("brush",n.brushedXY.bind(Sl(n))).on("end",n.brushedXYEnded.bind(Sl(n))),n}return d1t(I,[{key:"componentDidMount",value:function(){this.props.isRangeSelectionActive&&this.addBrush2d()}},{key:"shouldComponentUpdate",value:function(n,C){if(this.rangeSelectionTriggeredXY){if(this.rangeSelectionTriggeredXY=!1,this.rangeSelectionTriggeredXYEnd){const r=n.rangeSelection[0]||null;this.moveBrushXY([r,n.rangeSelection[1]],!0),this.rangeSelectionTriggeredXYEnd=!1}return this.state!==C}if(this.props.rangeSelection!==n.rangeSelection){const r=n.rangeSelection[0]||null;this.props.is1dRangeSelection?(this.rangeSelectionTriggeredX||this.moveBrushX(r,n.rangeSelectionEnd),this.rangeSelectionTriggeredXEnd&&this.moveBrushX(r,n.rangeSelectionEnd,!0),this.rangeSelectionTriggeredY||this.moveBrushY(r,n.rangeSelectionEnd),this.rangeSelectionTriggeredYEnd&&this.moveBrushY(r,n.rangeSelectionEnd,!0),this.rangeSelectionTriggeredX=!1,this.rangeSelectionTriggeredXEnd=!1,this.rangeSelectionTriggeredY=!1,this.rangeSelectionTriggeredYEnd=!1):this.moveBrushXY([r,n.rangeSelection[1]],n.rangeSelectionEnd);const o=this.props.is1dRangeSelection&&!n.is1dRangeSelection&&r===null;return this.state!==C||o}return!0}},{key:"componentDidUpdate",value:function(){this.props.isRangeSelectionActive?this.addBrush2d():(this.removeBrush1d(),this.removeBrush2d())}},{key:"addBrush1d",value:function(){!this.brushElX||!this.brushElY||this.brushElXOld===this.brushElX&&this.brushElYOld===this.brushElY||(this.brushElXOld&&this.brushElXOld.on(".brush",null),this.brushElYOld&&this.brushElYOld.on(".brush",null),this.brushElX.call(this.brushBehaviorX),this.brushElY.call(this.brushBehaviorY),Bp(this.brushElX,Fo["track-range-selection-group-brush-selection"]),Bp(this.brushElY,Fo["track-range-selection-group-brush-selection"]),this.brushElXOld=this.brushElX,this.brushElYOld=this.brushElY,this.brushIs1dBound=!0)}},{key:"addBrush2d",value:function(){!this.brushElXY||this.brushElXYOld===this.brushElXY||(this.brushElXYOld&&this.brushElXYOld.on(".brush",null),this.brushElXY.call(this.brushBehaviorXY),this.brushElXYOld=this.brushElXY,this.brushIs2dBound=!0,Bp(this.brushElXY,Fo["track-range-selection-group-brush-selection"]))}},{key:"brushedX",value:function(n){const C=this.rangeSelectionMoved;this.rangeSelectionMoved=!1,!(!Fm(n)||!this.props.onRangeSelectionX||!this.props.is1dRangeSelection||C)&&(this.rangeSelectionTriggeredX=!0,this.props.onRangeSelectionX(n.selection))}},{key:"brushedXEnded",value:function(n){const C=this.rangeSelectionMovedEnd;this.rangeSelectionMovedEnd=!1,!(!Fm(n)||!this.props.onRangeSelectionX||!this.props.is1dRangeSelection||C)&&(this.rangeSelectionTriggeredX=!0,this.rangeSelectionTriggeredXEnd=!0,this.props.onRangeSelectionXEnd(n.selection))}},{key:"brushedY",value:function(n){const C=this.rangeSelectionMoved;this.rangeSelectionMoved=!1,!(!Fm(n)||!this.props.onRangeSelectionY||!this.props.is1dRangeSelection||C)&&(this.rangeSelectionTriggeredY=!0,this.props.onRangeSelectionY(n.selection))}},{key:"brushedYEnded",value:function(n){const C=this.rangeSelectionMovedEnd;this.rangeSelectionMovedEnd=!1,!(!Fm(n)||!this.props.onRangeSelectionY||!this.props.is1dRangeSelection||C)&&(this.rangeSelectionTriggeredY=!0,this.rangeSelectionTriggeredYEnd=!0,this.props.onRangeSelectionYEnd(n.selection))}},{key:"brushedXY",value:function(n){const C=this.rangeSelectionMoved;this.rangeSelectionMoved=!1,!(!Fm(n)||!this.props.onRangeSelectionXY||C||this.props.is1dRangeSelection)&&(this.rangeSelectionTriggeredXY=!0,this.props.onRangeSelectionXY([[n.selection[0][0],n.selection[1][0]],[n.selection[0][1],n.selection[1][1]]]))}},{key:"brushedXYEnded",value:function(n){if(this.props.is1dRangeSelection)return;const C=this.rangeSelectionMovedEnd;this.rangeSelectionMovedEnd=!1,n.selection&&n.sourceEvent&&this.props.onRangeSelectionXY&&!C&&(this.rangeSelectionTriggeredXY=!0,this.rangeSelectionTriggeredXYEnd=!0,this.props.onRangeSelectionXYEnd([[n.selection[0][0],n.selection[1][0]],[n.selection[0][1],n.selection[1][1]]])),n.selection||(this.rangeSelectionTriggeredXY=!0,this.props.onRangeSelectionReset())}},{key:"brushStarted",value:function(n){Fm(n)&&this.props.onRangeSelectionStart()}},{key:"moveBrushX",value:function(n,C=!1){if(!this.brushEl)return;this.brushIs2dBound&&(this.removeBrush2d(),this.addBrush1d());const r=n?[this.props.scaleX(n[0]),this.props.scaleX(n[1])]:null;this.rangeSelectionMoved=!0,this.rangeSelectionMovedEnd=!0,C?this.brushElX.transition().call(this.brushBehaviorX.move,r):this.brushElX.call(this.brushBehaviorX.move,r)}},{key:"moveBrushY",value:function(n,C=!1){if(!this.brushEl)return;this.brushIs2dBound&&(this.removeBrush2d(),this.addBrush1d());const r=n?[this.props.scaleY(n[0]),this.props.scaleY(n[1])]:null;this.rangeSelectionMoved=!0,this.rangeSelectionMovedEnd=!0,C?this.brushElY.transition().call(this.brushBehaviorY.move,r):this.brushElY.call(this.brushBehaviorY.move,r)}},{key:"moveBrushXY",value:function(n,C=!1){if(!this.brushEl)return;const r=[[this.props.scaleX(n[0][0]),this.props.scaleY(n[1][0])],[this.props.scaleX(n[0][1]),this.props.scaleY(n[1][1])]];this.rangeSelectionMoved=!0,this.rangeSelectionMovedEnd=!0,C?this.brushElXY.transition().call(this.brushBehaviorXY.move,r):this.brushElXY.call(this.brushBehaviorXY.move,r)}},{key:"mouseEnterHandler",value:function(){this.props.isRangeSelectionActive||this.setState({isVisible:!0})}},{key:"mouseLeaveHandler",value:function(){this.setState({isVisible:!1})}},{key:"removeBrush1d",value:function(){this.brushIs1dBound&&(this.brushElX&&(this.brushElX.call(this.brushBehaviorX.move,null),this.brushElX.on(".brush",null)),this.brushElY&&(this.brushElY.call(this.brushBehaviorY.move,null),this.brushElY.on(".brush",null)),this.brushIs1dBound=!1)}},{key:"removeBrush2d",value:function(){this.brushIs2dBound&&this.brushElXY&&(this.brushElXY.call(this.brushBehaviorXY.move,null),this.brushElXY.on(".brush",null),this.brushElXYOld=void 0,this.brushIs2dBound=!1,this.props.is1dRangeSelection||this.props.onRangeSelectionReset())}},{key:"render",value:function(){const n=this.props.tracks.map(s=>V0(s)).reduce(RS,!1),C=this.props.tracks.some(s=>s.contents?s.contents.some(a=>a.type==="heatmap"?a.options.colorbarPosition==="topRight":!1):s.type==="heatmap"?s.options.colorbarPosition==="topRight":!1);let r="track-range-selection";this.props.isRangeSelectionActive&&(r+=this.props.is1dRangeSelection?"-active-secondary":"-active-primary");const o=Vg(!this.props.is1dRangeSelection&&Fo["track-range-selection-group-inactive"]),A=Vg(this.props.is1dRangeSelection&&Fo["track-range-selection-group-inactive"]);return N.createElement("div",{className:Vg(this.props.className,cz["center-track"]),onMouseEnter:this.mouseEnterHandler.bind(this),onMouseLeave:this.mouseLeaveHandler.bind(this),style:{height:this.props.height,width:this.props.width}},n&&N.createElement("svg",{className:Fo[r],style:{height:this.props.height,width:this.props.width},xmlns:"http://www.w3.org/2000/svg"},N.createElement("g",{ref:s=>{this.brushElX=cg(s)},className:o}),N.createElement("g",{ref:s=>{this.brushElY=cg(s)},className:o}),N.createElement("g",{ref:s=>{this.brushElXY=cg(s)},className:A})),this.props.editable&&N.createElement($N,{imgStyleAdd:IR,imgStyleClose:IR,imgStyleMove:IR,imgStyleSettings:IR,isMoveable:!1,isVisible:this.state.isVisible||this.props.uid===this.props.configTrackMenuId,onAddSeries:this.props.onAddSeries,onCloseTrackMenuOpened:this.props.onCloseTrackMenuOpened,onConfigTrackMenuOpened:this.props.onConfigTrackMenuOpened,paddingRight:C,uid:this.props.uid}))}}]),I}(N.Component);nj.defaultProps={className:"center-track",configTrackMenuId:null,is1dRangeSelection:!1,rangeSelectionEnd:L.bool,isRangeSelectionActive:!1,scaleX:e=>e,scaleY:e=>e};nj.propTypes={className:L.string,configTrackMenuId:L.string,editable:L.bool,height:L.number.isRequired,is1dRangeSelection:L.bool,isRangeSelectionActive:L.bool,onAddSeries:L.func.isRequired,onCloseTrackMenuOpened:L.func.isRequired,onConfigTrackMenuOpened:L.func.isRequired,onRangeSelectionX:L.func.isRequired,onRangeSelectionXEnd:L.func.isRequired,onRangeSelectionY:L.func.isRequired,onRangeSelectionYEnd:L.func.isRequired,onRangeSelectionXY:L.func.isRequired,onRangeSelectionXYEnd:L.func.isRequired,onRangeSelectionReset:L.func.isRequired,onRangeSelectionStart:L.func.isRequired,rangeSelection:L.array.isRequired,rangeSelectionEnd:L.bool,scaleX:L.func,scaleY:L.func,tracks:L.array.isRequired,uid:L.string.isRequired,width:L.number.isRequired};function dz(){return dz=Object.assign?Object.assign.bind():function(e){for(var g=1;g({event:"fake",handler:_o}),unsubscribe:_o,clear:_o},{Provider:Z1t,Consumer:G1t}=N.createContext(Cj),M0=e=>N.forwardRef((g,I)=>N.createElement(G1t,null,i=>N.createElement(e,dz({ref:I},g,{pubSub:i})))),v1t={"drag-listening-div-active":"_drag-listening-div-active_19gkt_1"};function B1t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function ICe(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function S9(e){return S9=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},S9(e)}let rj=function(e){R1t(I,e);var g=W1t(I);function I(i){var n;return B1t(this,I),n=g.call(this,i),n.state={dragOnTop:!1},n}return S1t(I,[{key:"render",value:function(){let n="red";return this.props.enabled&&this.state.dragOnTop?n="green":this.props.enabled&&(n="blue"),N.createElement("div",{className:Vg("DragListeningDiv",{[v1t["drag-listening-div-active"]]:this.props.enabled}),onDragEnter:()=>{this.setState({dragOnTop:!0})},onDragLeave:()=>{this.setState({dragOnTop:!1})},onDragOver:C=>{C.preventDefault()},onDrop:()=>{if(!this.props.enabled)return;const C=this.props.draggingHappening,r={type:this.props.defaultTrackType,uid:Ag.nice(),tilesetUid:C.tilesetUid,server:C.server};this.props.onTrackDropped(r),this.props.pubSub.publish("trackDropped",r)},style:{background:n,opacity:.6,...this.props.style}})}}]),I}(N.Component);rj.defaultProps={enabled:!1,style:{},draggingHappening:{},onTrackDropped:()=>{}};rj.propTypes={enabled:L.bool,style:L.object,defaultTrackType:L.object,draggingHappening:L.object,onTrackDropped:L.func,position:L.string.isRequired,pubSub:L.object.isRequired};const iR=M0(rj),vu={"gallery-tracks":"_gallery-tracks_fbxxi_1","gallery-track":"_gallery-track_fbxxi_1","gallery-sub-track":"_gallery-sub-track_fbxxi_18","gallery-invisible-track":"_gallery-invisible-track_fbxxi_19"},N1t="_horizontalList_1y7td_7",k1t="_list_1y7td_14",Y1t="_stylizedList_1y7td_21",K1t="_stylizedItem_1y7td_28",D1t="_stylizedHelper_1y7td_39",x1t="_horizontalItem_1y7td_44",F1t="_domain_1y7td_60",Eo={"tiled-plot":"_tiled-plot_1y7td_1",horizontalList:N1t,list:k1t,stylizedList:Y1t,stylizedItem:K1t,stylizedHelper:D1t,horizontalItem:x1t,"resizable-track":"_resizable-track_1y7td_55",domain:F1t};function E1t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function iCe(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function w9(e){return w9=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},w9(e)}const nR={pointerEvents:"all"};let Fwe=function(e){J1t(I,e);var g=O1t(I);function I(i){var n;return E1t(this,I),n=g.call(this,i),n.state={hovering:!1},n}return M1t(I,[{key:"mouseEnterHandler",value:function(){this.setState({hovering:!0})}},{key:"mouseLeaveHandler",value:function(){this.setState({hovering:!1})}},{key:"render",value:function(){return N.createElement("div",{className:Vg("gallery-tracks",vu["gallery-tracks"])},this.props.tracks&&this.props.tracks.map((n,C)=>N.createElement("div",{key:n.uid||C,className:vu["gallery-track"],onMouseLeave:this.mouseLeaveHandler.bind(this),style:{top:n.height*C,right:n.height*C,bottom:n.height*C,left:n.height*C}},N.createElement("div",{className:vu["gallery-sub-track"],onMouseEnter:this.mouseEnterHandler.bind(this),style:{top:0,right:0,left:0,height:n.height}}),N.createElement("div",{className:vu["gallery-sub-track"],onMouseEnter:this.mouseEnterHandler.bind(this),style:{top:0,right:0,bottom:0,width:n.height}}),N.createElement("div",{className:vu["gallery-sub-track"],onMouseEnter:this.mouseEnterHandler.bind(this),style:{right:0,bottom:0,left:0,height:n.height}}),N.createElement("div",{className:vu["gallery-sub-track"],onMouseEnter:this.mouseEnterHandler.bind(this),style:{top:0,bottom:0,left:0,width:n.height}}),N.createElement("div",{className:vu["gallery-invisible-track"],onMouseLeave:this.mouseLeaveHandler.bind(this),style:{top:n.height,right:n.height,bottom:n.height,left:n.height}}),this.props.editable&&N.createElement($N,{configMenuVisible:!0,imgStyleAdd:nR,imgStyleClose:nR,imgStyleMove:nR,imgStyleSettings:nR,isMoveable:!1,isVisible:this.state.hovering,onCloseTrackMenuOpened:this.props.onCloseTrackMenuOpened,onConfigTrackMenuOpened:this.props.onConfigTrackMenuOpened,uid:n.uid||C}))))}}]),I}(N.Component);Fwe.propTypes={editable:L.bool,onCloseTrackMenuOpened:L.func.isRequired,onConfigTrackMenuOpened:L.func.isRequired,tracks:L.array};function Q1t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function nCe(e,g){for(var I=0;I{}),this.pubSubs.push(this.pubSub.subscribe("app.mouseMove",this.defaultMouseMoveHandler.bind(this))),this.isLeftModified=!1}return j1t(e,[{key:"isWithin",value:function(I,i){let n=I,C=i,r=this.position[0],o=this.position[1];return this.isLeftModified&&(n=i,C=I,r=this.position[1],o=this.position[0]),Q7(n,C,r,this.dimensions[0]+r,o,this.dimensions[1]+o)}},{key:"getProp",value:function(I){return()=>this[I]}},{key:"getData",value:function(){}},{key:"click",value:function(I,i,n){return{type:"generic",event:n,payload:null}}},{key:"clickOutside",value:function(){}},{key:"getDimensions",value:function(){return this.dimensions}},{key:"setDimensions",value:function(I){this.dimensions=I,this._xScale.range([0,this.dimensions[0]]),this._yScale.range([0,this.dimensions[1]])}},{key:"refXScale",value:function(I){return I?(this._refXScale=I,this):this._refXScale}},{key:"refYScale",value:function(I){return I?(this._refYScale=I,this):this._refYScale}},{key:"xScale",value:function(I){return I?(this._xScale=I,this):this._xScale}},{key:"yScale",value:function(I){return I?(this._yScale=I,this):this._yScale}},{key:"zoomed",value:function(I,i){this.xScale(I),this.yScale(i)}},{key:"refScalesChanged",value:function(I,i){this._refXScale=I,this._refYScale=i}},{key:"draw",value:function(){}},{key:"getPosition",value:function(){return this.position}},{key:"setPosition",value:function(I){this.position=I}},{key:"defaultMouseMoveHandler",value:function(I){}},{key:"remove",value:function(){this.pubSubs.forEach(I=>this.pubSub.unsubscribe(I)),this.pubSubs=[]}},{key:"rerender",value:function(I){}},{key:"respondsToPosition",value:function(I,i){return this.isWithin(I,i)}},{key:"zoomedY",value:function(I,i){}},{key:"movedY",value:function(I){}}]),e}();function eWt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function CCe(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function zb(e){return zb=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},zb(e)}function aWt(e,g){const I=S0(g,e);return Oh(`.${I}`,e)(e)}function sWt(e,g){const I=e.map(C=>+C).sort((C,r)=>r-C),i=I[g],n=I[I.length-1];return aWt(i,n)}function lWt(e,g,I,i){const n=g/(2**e*I);if(!Number.isNaN(n)){const C=g/(2**i*I),r=S0(C,n);return Oh(`.${r}`,n)(n)}return console.warn("NaN resolution, screen is probably too small."),""}let lC=function(e){nWt(I,e);var g=CWt(I);function I(i,n){var C;eWt(this,I),C=g.call(this,i,n);const{scene:r}=i;C.scene=r,C.delayDrawing=!1,C.pBase=new rt.PIXI.Graphics,C.pMasked=new rt.PIXI.Graphics,C.pMask=new rt.PIXI.Graphics,C.pMain=new rt.PIXI.Graphics,C.pBorder=new rt.PIXI.Graphics,C.pBackground=new rt.PIXI.Graphics,C.pForeground=new rt.PIXI.Graphics,C.pLabel=new rt.PIXI.Graphics,C.pMobile=new rt.PIXI.Graphics,C.pAxis=new rt.PIXI.Graphics,C.pMouseOver=new rt.PIXI.Graphics,C.scene.addChild(C.pBase),C.pBase.addChild(C.pMasked),C.pMasked.addChild(C.pBackground),C.pMasked.addChild(C.pMain),C.pMasked.addChild(C.pMask),C.pMasked.addChild(C.pMobile),C.pMasked.addChild(C.pBorder),C.pMasked.addChild(C.pLabel),C.pMasked.addChild(C.pForeground),C.pMasked.addChild(C.pMouseOver),C.pBase.addChild(C.pAxis),C.pMasked.mask=C.pMask,C.prevOptions="",C.options=Object.assign(C.options,n);const o=C.getName();return C.labelTextFontFamily="Arial",C.labelTextFontSize=12,C.labelXOffset=0,C.labelText=new rt.PIXI.Text(o,{fontSize:`${C.labelTextFontSize}px`,fontFamily:C.labelTextFontFamily,fill:"black"}),C.pLabel.addChild(C.labelText),C.errorText=new rt.PIXI.Text("",{fontSize:"12px",fontFamily:"Arial",fill:"red"}),C.errorText.anchor.x=.5,C.errorText.anchor.y=.5,C.pLabel.addChild(C.errorText),C.errorTextText="",C.flipText=!1,C.tilesetInfo=void 0,C}return tWt(I,[{key:"setLabelText",value:function(){}},{key:"setPosition",value:function(n){this.position=n,this.drawBorder(),this.drawLabel(),this.drawBackground(),this.setMask(this.position,this.dimensions),this.setForeground()}},{key:"setDimensions",value:function(n){k1(zb(I.prototype),"setDimensions",this).call(this,n),this.drawBorder(),this.drawLabel(),this.drawBackground(),this.setMask(this.position,this.dimensions),this.setForeground()}},{key:"setMask",value:function(n,C){this.pMask.clear(),this.pMask.beginFill(),this.pMask.drawRect(n[0],n[1],C[0],C[1]),this.pMask.endFill()}},{key:"setForeground",value:function(){this.pForeground.position.y=this.position[1],this.pForeground.position.x=this.position[0]}},{key:"remove",value:function(){this.pBase.clear(),this.scene.removeChild(this.pBase)}},{key:"drawBorder",value:function(){const n=this.pBorder;if(n.clear(),!this.options||!this.options.trackBorderWidth)return;const C=Kt(this.options.trackBorderColor?this.options.trackBorderColor:"white");n.lineStyle(this.options.trackBorderWidth,C),n.drawRect(this.position[0],this.position[1],this.dimensions[0],this.dimensions[1])}},{key:"drawError",value:function(){if(this.errorText.x=this.position[0]+this.dimensions[0]/2,this.errorText.y=this.position[1]+this.dimensions[1]/2,this.errorText.text=this.errorTextText,this.errorTextText&&this.errorTextText.length){const n=this.pBorder;n.clear(),n.lineStyle(1,Kt("red")),n.drawRect(this.position[0],this.position[1],this.dimensions[0],this.dimensions[1])}}},{key:"drawBackground",value:function(){const n=this.pBackground;if(n.clear(),!this.options||!this.options.backgroundColor)return;let C=1,r=this.options.backgroundColor;this.options.backgroundColor==="transparent"&&(C=0,r="white");const o=Kt(r);n.beginFill(o,C),n.drawRect(this.position[0],this.position[1],this.dimensions[0],this.dimensions[1])}},{key:"getLabelColor",value:function(){return this.options.labelColor&&this.options.labelColor!=="[glyph-color]"?this.options.labelColor:this.options.lineStrokeColor||this.options.barFillColor||"black"}},{key:"getName",value:function(){return this.options.name?this.options.name:this.tilesetInfo&&this.tilesetInfo.name||""}},{key:"drawLabel",value:function(){if(!this.labelText)return;const n=this.pLabel;if(n.clear(),!this.options||!this.options.labelPosition||this.options.labelPosition==="hidden"){this.labelText.alpha=0;return}const{labelBackgroundColor:C="white",labelBackgroundOpacity:r=.5}=this.options;n.beginFill(Kt(C),+r);const o=Kt(this.getLabelColor()),A=2;if(this.dimensions[0]<0)return;let s=this.options.labelShowAssembly&&this.tilesetInfo&&this.tilesetInfo.coordSystem?`${this.tilesetInfo.coordSystem} | `:"";if(s+=this.getName(),this.options.labelShowResolution&&Sst(this.tilesetInfo)&&this.tilesetInfo.bins_per_dimension){const d=lWt(this.calculateZoomLevel(),this.tilesetInfo.max_width,this.tilesetInfo.bins_per_dimension,this.tilesetInfo.max_zoom);s+=` +[Current data resolution: ${d}]`}else if(this.options.labelShowResolution&&wst(this.tilesetInfo)){const d=sWt(this.tilesetInfo.resolutions,this.calculateZoomLevel());s+=` [Current data resolution: ${d}]`}if(this.options&&this.options.dataTransform){let d=null;if(this.tilesetInfo&&this.tilesetInfo.transforms)for(const h of this.tilesetInfo.transforms)h.value===this.options.dataTransform&&(d=h);d?s+=` [Transform: ${d.name}]`:this.options.dataTransform==="None"?s+=` [Transform: None ]`:s+=` -[Transform: Default ]`}this.labelText.text=s,this.labelText.style={fontSize:`${this.labelTextFontSize}px`,fontFamily:this.labelTextFontFamily,fill:o},this.labelText.alpha=typeof this.options.labelTextOpacity<"u"?this.options.labelTextOpacity:1,this.labelText.visible=!0,this.flipText&&(this.labelText.scale.x=-1);const{labelLeftMargin:a=0,labelRightMargin:l=0,labelTopMargin:c=0,labelBottomMargin:u=0}=this.options;this.options.labelPosition==="topLeft"?(this.labelText.x=this.position[0]+a+this.labelXOffset,this.labelText.y=this.position[1]+c,this.labelText.anchor.x=.5,this.labelText.anchor.y=0,this.labelText.x+=this.labelText.width/2,n.drawRect(this.position[0]+a+this.labelXOffset,this.position[1]+c,this.labelText.width+A,this.labelText.height+A)):this.options.labelPosition==="bottomLeft"&&!this.flipText||this.options.labelPosition==="topRight"&&this.flipText?(this.labelText.x=this.position[0]+(a||c),this.labelText.y=this.position[1]+this.dimensions[1]-(u||l),this.labelText.anchor.x=.5,this.labelText.anchor.y=1,this.labelText.x+=this.labelText.width/2+this.labelXOffset,n.drawRect(this.position[0]+(a||c)+this.labelXOffset,this.position[1]+this.dimensions[1]-this.labelText.height-A-(u||l),this.labelText.width+A,this.labelText.height+A)):this.options.labelPosition==="topRight"&&!this.flipText||this.options.labelPosition==="bottomLeft"&&this.flipText?(this.labelText.x=this.position[0]+this.dimensions[0]-(l||u),this.labelText.y=this.position[1]+(c||a),this.labelText.anchor.x=.5,this.labelText.anchor.y=0,this.labelText.x-=this.labelText.width/2+this.labelXOffset,n.drawRect(this.position[0]+this.dimensions[0]-this.labelText.width-A-(l||u)-this.labelXOffset,this.position[1]+(c||a),this.labelText.width+A,this.labelText.height+A)):this.options.labelPosition==="bottomRight"?(this.labelText.x=this.position[0]+this.dimensions[0]-l,this.labelText.y=this.position[1]+this.dimensions[1]-u,this.labelText.anchor.x=.5,this.labelText.anchor.y=1,this.labelText.x-=this.labelText.width/2+this.labelXOffset,n.drawRect(this.position[0]+this.dimensions[0]-this.labelText.width-A-l-this.labelXOffset,this.position[1]+this.dimensions[1]-this.labelText.height-A-u,this.labelText.width+A,this.labelText.height+A)):this.options.labelPosition==="outerLeft"&&!this.flipText||this.options.labelPosition==="outerTop"&&this.flipText?(this.labelText.x=this.position[0],this.labelText.y=this.position[1]+this.dimensions[1]/2,this.labelText.anchor.x=.5,this.labelText.anchor.y=.5,this.labelText.x-=this.labelText.width/2+3):this.options.labelPosition==="outerTop"&&!this.flipText||this.options.labelPosition==="outerLeft"&&this.flipText?(this.labelText.x=this.position[0]+this.dimensions[0]/2,this.labelText.y=this.position[1],this.labelText.anchor.x=.5,this.labelText.anchor.y=.5,this.labelText.y-=this.labelText.height/2+3):this.options.labelPosition==="outerBottom"&&!this.flipText||this.options.labelPosition==="outerRight"&&this.flipText?(this.labelText.x=this.position[0]+this.dimensions[0]/2,this.labelText.y=this.position[1]+this.dimensions[1],this.labelText.anchor.x=.5,this.labelText.anchor.y=.5,this.labelText.y+=this.labelText.height/2+3):this.options.labelPosition==="outerRight"&&!this.flipText||this.options.labelPosition==="outerBottom"&&this.flipText?(this.labelText.x=this.position[0]+this.dimensions[0],this.labelText.y=this.position[1]+this.dimensions[1]/2,this.labelText.anchor.x=.5,this.labelText.anchor.y=.5,this.labelText.x+=this.labelText.width/2+3):this.labelText.visible=!1,this.options.labelPosition==="outerLeft"||this.options.labelPosition==="outerRight"||this.options.labelPosition==="outerTop"||this.options.labelPosition==="outerBottom"?this.pLabel.setParent(this.pBase):this.pLabel.setParent(this.pMasked)}},{key:"rerender",value:function(n){this.options=n,this.draw(),this.drawBackground(),this.drawLabel(),this.drawError(),this.drawBorder()}},{key:"draw",value:function(){this.drawError()}},{key:"exportSVG",value:function(){const n=document.createElement("g"),C=document.createElement("rect");C.setAttribute("x",`${this.position[0]}`),C.setAttribute("y",`${this.position[1]}`),C.setAttribute("width",`${this.dimensions[0]}`),C.setAttribute("height",`${this.dimensions[1]}`),this.options&&this.options.backgroundColor?C.setAttribute("fill",this.options.backgroundColor):C.setAttribute("fill-opacity","0");const r=document.createElement("g");r.setAttribute("class","g-clipped"),n.appendChild(r),r.appendChild(C);const o=document.createElement("g");r.setAttribute("class","g-track"),r.appendChild(o);const A=document.createElement("g");r.setAttribute("class","g-labels"),r.appendChild(A);const s=document.createElementNS("http://www.w3.org/2000/svg","clipPath");n.appendChild(s);const a=document.createElementNS("http://www.w3.org/2000/svg","polygon");s.appendChild(a),a.setAttribute("points",`${this.position[0]},${this.position[1]} ${this.position[0]+this.dimensions[0]},${this.position[1]} ${this.position[0]+this.dimensions[0]},${this.position[1]+this.dimensions[1]} ${this.position[0]},${this.position[1]+this.dimensions[1]} `);const l=dg.nice();s.setAttribute("id",l),r.setAttribute("style",`clip-path:url(#${l});`);const c=this.labelText.text.split(` -`);let u=0;const d=3,h=(this.labelTextFontSize+2)*c.length+d;this.labelText.anchor.y===.5?u=h/2:this.labelText.anchor.y===1&&(u=-h);for(let m=0;mnew g(i,I)))}return YRt(g,[{key:"registerFileUrl",value:async function({server:I,url:i,filetype:n,coordSystem:C}){const r=`${qN(I)}/register_url/`;return fetch(r,{method:"POST",body:JSON.stringify({fileurl:i,filetype:n,coordSystem:C}),headers:{"Content-Type":"application/json; charset=utf-8"}})}},{key:"tilesetInfo",value:function(I){const{server:i,url:n,filetype:C,coordSystem:r}=this.dataConfig;return i&&n&&C?this.registerFileUrl({server:i,url:n,filetype:C,coordSystem:r}).then(o=>o.json()).then(o=>{this.dataConfig.tilesetUid=o.uid,this.tilesetInfoAfterRegister(I)}).catch(o=>{console.error("Error registering url",o)}):new Promise(()=>{this.tilesetInfoAfterRegister(I)})}},{key:"tilesetInfoAfterRegister",value:function(I){if(this.dataConfig.children){const i=this.dataConfig.children.map(n=>new Promise(C=>{n.tilesetInfo(C)}));Promise.all(i).then(n=>{I(n[0])})}else{const{server:i,tilesetUid:n}=this.dataConfig;!i||!n?(console.warn("No dataConfig children, server or tilesetUid:",this.dataConfig),I(null)):vt.trackInfo(i,n,C=>{this.dataConfig.tilesetInfo=C[n],I(C[n],n)},C=>{this.tilesetInfoLoading=!1,I({error:C})},this.pubSub)}}},{key:"fullTileId",value:function(I,i){return`${I}.${i}`}},{key:"fetchTilesDebounced",value:function(I,i){var n;if(this.dataConfig.type==="horizontal-section")return this.fetchHorizontalSection(I,i);if(this.dataConfig.type==="vertical-section")return this.fetchHorizontalSection(I,i,!0);if(!this.dataConfig.children&&this.dataConfig.tilesetUid)return new Promise(o=>{vt.fetchTilesDebounced({id:dg.nice(),server:this.dataConfig.server,done:o,ids:i.map(A=>`${this.dataConfig.tilesetUid}.${A}`),options:this.dataConfig.options},this.pubSub,!0)}).then(o=>{const A=Pg(o)[0].tilesetUid,s={};for(let a=0;anew Promise(o=>{r.fetchTilesDebounced(o,i)})))??[];return Promise.all(C).then(r=>{if(this.dataConfig.type==="divided"&&DRt(r)){const o=this.makeDivided(r,i);return I(o),o}return console.warn("Unimplemented dataConfig type. Returning first data source.",this.dataConfig),I(r[0]),r[0]})}},{key:"divideData",value:function(I,i){const n=new Float32Array(I.length);for(let C=0;C+p).sort((p,y)=>y-p);h=vt.calculateTilesFromResolution(b[c],d,A.min_pos[n?1:0],A.max_pos[n?1:0])}else h=vt.calculateTiles(c,d,A.min_pos[n?1:0],A.max_pos[n?1:0],A.max_zoom,A.max_width);const m=[u,h[0]].sort((b,p)=>b-p);m[0]===u?r.push(!1):r.push(!0);const f=`${c}.${m[0]}.${m[1]}`;C.push(f)}return new Promise(a=>{vt.fetchTilesDebounced({id:dg.nice(),server:this.dataConfig.server,done:a,ids:C.map(l=>`${this.dataConfig.tilesetUid}.${l}`)},this.pubSub,!0)}).then(a=>{const l=Pg(a)[0].tilesetUid,c={};for(let u=0;u=0;)g[e]=0}var zRt=0,jVe=1,PRt=2,JRt=3,ORt=258,Ej=29,Sw=256,qv=Sw+1+Ej,qp=30,Mj=19,$Ve=2*qv+1,fd=15,YD=16,LRt=7,zj=256,qVe=16,eRe=17,tRe=18,eP=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0],mW=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13],_Rt=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7],gRe=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],URt=512,As=new Array((qv+2)*2);Ay(As);var yB=new Array(qp*2);Ay(yB);var eS=new Array(URt);Ay(eS);var tS=new Array(ORt-JRt+1);Ay(tS);var Pj=new Array(Ej);Ay(Pj);var fH=new Array(qp);Ay(fH);function KD(g,e,I,i,n){this.static_tree=g,this.extra_bits=e,this.extra_base=I,this.elems=i,this.max_length=n,this.has_stree=g&&g.length}var IRe,iRe,nRe;function xD(g,e){this.dyn_tree=g,this.max_code=0,this.stat_desc=e}function CRe(g){return g<256?eS[g]:eS[256+(g>>>7)]}function gS(g,e){g.pending_buf[g.pending++]=e&255,g.pending_buf[g.pending++]=e>>>8&255}function TC(g,e,I){g.bi_valid>YD-I?(g.bi_buf|=e<>YD-g.bi_valid,g.bi_valid+=I-YD):(g.bi_buf|=e<>>=1,I<<=1;while(--e>0);return I>>>1}function QRt(g){g.bi_valid===16?(gS(g,g.bi_buf),g.bi_buf=0,g.bi_valid=0):g.bi_valid>=8&&(g.pending_buf[g.pending++]=g.bi_buf&255,g.bi_buf>>=8,g.bi_valid-=8)}function jRt(g,e){var I=e.dyn_tree,i=e.max_code,n=e.stat_desc.static_tree,C=e.stat_desc.has_stree,r=e.stat_desc.extra_bits,o=e.stat_desc.extra_base,A=e.stat_desc.max_length,s,a,l,c,u,d,h=0;for(c=0;c<=fd;c++)g.bl_count[c]=0;for(I[g.heap[g.heap_max]*2+1]=0,s=g.heap_max+1;s<$Ve;s++)a=g.heap[s],c=I[I[a*2+1]*2+1]+1,c>A&&(c=A,h++),I[a*2+1]=c,!(a>i)&&(g.bl_count[c]++,u=0,a>=o&&(u=r[a-o]),d=I[a*2],g.opt_len+=d*(c+u),C&&(g.static_len+=d*(n[a*2+1]+u)));if(h!==0){do{for(c=A-1;g.bl_count[c]===0;)c--;g.bl_count[c]--,g.bl_count[c+1]+=2,g.bl_count[A]--,h-=2}while(h>0);for(c=A;c!==0;c--)for(a=g.bl_count[c];a!==0;)l=g.heap[--s],!(l>i)&&(I[l*2+1]!==c&&(g.opt_len+=(c-I[l*2+1])*I[l*2],I[l*2+1]=c),a--)}}function oRe(g,e,I){var i=new Array(fd+1),n=0,C,r;for(C=1;C<=fd;C++)i[C]=n=n+I[C-1]<<1;for(r=0;r<=e;r++){var o=g[r*2+1];o!==0&&(g[r*2]=rRe(i[o]++,o))}}function $Rt(){var g,e,I,i,n,C=new Array(fd+1);for(I=0,i=0;i>=7;i8?gS(g,g.bi_buf):g.bi_valid>0&&(g.pending_buf[g.pending++]=g.bi_buf),g.bi_buf=0,g.bi_valid=0}function qRt(g,e,I,i){aRe(g),i&&(gS(g,I),gS(g,~I)),FRt.arraySet(g.pending_buf,g.window,e,I,g.pending),g.pending+=I}function UCe(g,e,I,i){var n=e*2,C=I*2;return g[n]>1;r>=1;r--)DD(g,I,r);s=C;do r=g.heap[1],g.heap[1]=g.heap[g.heap_len--],DD(g,I,1),o=g.heap[1],g.heap[--g.heap_max]=r,g.heap[--g.heap_max]=o,I[s*2]=I[r*2]+I[o*2],g.depth[s]=(g.depth[r]>=g.depth[o]?g.depth[r]:g.depth[o])+1,I[r*2+1]=I[o*2+1]=s,g.heap[1]=s++,DD(g,I,1);while(g.heap_len>=2);g.heap[--g.heap_max]=g.heap[1],jRt(g,e),oRe(I,A,g.bl_count)}function jCe(g,e,I){var i,n=-1,C,r=e[0*2+1],o=0,A=7,s=4;for(r===0&&(A=138,s=3),e[(I+1)*2+1]=65535,i=0;i<=I;i++)C=r,r=e[(i+1)*2+1],!(++o=3&&g.bl_tree[gRe[e]*2+1]===0;e--);return g.opt_len+=3*(e+1)+5+5+4,e}function t1t(g,e,I,i){var n;for(TC(g,e-257,5),TC(g,I-1,5),TC(g,i-4,4),n=0;n>>=1)if(e&1&&g.dyn_ltree[I*2]!==0)return LCe;if(g.dyn_ltree[9*2]!==0||g.dyn_ltree[10*2]!==0||g.dyn_ltree[13*2]!==0)return _Ce;for(I=32;I0?(g.strm.data_type===MRt&&(g.strm.data_type=g1t(g)),tP(g,g.l_desc),tP(g,g.d_desc),r=e1t(g),n=g.opt_len+3+7>>>3,C=g.static_len+3+7>>>3,C<=n&&(n=C)):n=C=I+5,I+4<=n&&e!==-1?sRe(g,e,I,i):g.strategy===ERt||C===n?(TC(g,(jVe<<1)+(i?1:0),3),QCe(g,As,yB)):(TC(g,(PRt<<1)+(i?1:0),3),t1t(g,g.l_desc.max_code+1,g.d_desc.max_code+1,r+1),QCe(g,g.dyn_ltree,g.dyn_dtree)),ARe(g),i&&aRe(g)}function C1t(g,e,I){return g.pending_buf[g.d_buf+g.last_lit*2]=e>>>8&255,g.pending_buf[g.d_buf+g.last_lit*2+1]=e&255,g.pending_buf[g.l_buf+g.last_lit]=I&255,g.last_lit++,e===0?g.dyn_ltree[I*2]++:(g.matches++,e--,g.dyn_ltree[(tS[I]+Sw+1)*2]++,g.dyn_dtree[CRe(e)*2]++),g.last_lit===g.lit_bufsize-1}oy._tr_init=I1t;oy._tr_stored_block=sRe;oy._tr_flush_block=n1t;oy._tr_tally=C1t;oy._tr_align=i1t;function r1t(g,e,I,i){for(var n=g&65535|0,C=g>>>16&65535|0,r=0;I!==0;){r=I>2e3?2e3:I,I-=r;do n=n+e[i++]|0,C=C+n|0;while(--r);n%=65521,C%=65521}return n|C<<16|0}var lRe=r1t;function o1t(){for(var g,e=[],I=0;I<256;I++){g=I;for(var i=0;i<8;i++)g=g&1?3988292384^g>>>1:g>>>1;e[I]=g}return e}var A1t=o1t();function a1t(g,e,I,i){var n=A1t,C=i+I;g^=-1;for(var r=i;r>>8^n[(g^e[r])&255];return g^-1}var cRe=a1t,Jj={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"},Qn=fl,io=oy,uRe=lRe,Pl=cRe,s1t=Jj,Zm=0,l1t=1,c1t=3,Lc=4,ere=5,$A=0,tre=1,no=-2,u1t=-3,FD=-5,d1t=-1,h1t=1,kR=2,m1t=3,f1t=4,p1t=0,b1t=2,Ok=8,y1t=9,Z1t=15,G1t=8,B1t=29,v1t=256,gP=v1t+1+B1t,S1t=30,w1t=19,V1t=2*gP+1,R1t=15,Vg=3,Xc=258,sA=Xc+Vg+1,W1t=32,Lk=42,IP=69,fW=73,pW=91,bW=103,pd=113,rG=666,Ri=1,ww=2,Gh=3,ay=4,X1t=3;function Hc(g,e){return g.msg=s1t[e],e}function gre(g){return(g<<1)-(g>4?9:0)}function lc(g){for(var e=g.length;--e>=0;)g[e]=0}function Jl(g){var e=g.state,I=e.pending;I>g.avail_out&&(I=g.avail_out),I!==0&&(Qn.arraySet(g.output,e.pending_buf,e.pending_out,I,g.next_out),g.next_out+=I,e.pending_out+=I,g.total_out+=I,g.avail_out-=I,e.pending-=I,e.pending===0&&(e.pending_out=0))}function an(g,e){io._tr_flush_block(g,g.block_start>=0?g.block_start:-1,g.strstart-g.block_start,e),g.block_start=g.strstart,Jl(g.strm)}function Yg(g,e){g.pending_buf[g.pending++]=e}function hZ(g,e){g.pending_buf[g.pending++]=e>>>8&255,g.pending_buf[g.pending++]=e&255}function H1t(g,e,I,i){var n=g.avail_in;return n>i&&(n=i),n===0?0:(g.avail_in-=n,Qn.arraySet(e,g.input,g.next_in,n,I),g.state.wrap===1?g.adler=uRe(g.adler,e,n,I):g.state.wrap===2&&(g.adler=Pl(g.adler,e,n,I)),g.next_in+=n,g.total_in+=n,n)}function dRe(g,e){var I=g.max_chain_length,i=g.strstart,n,C,r=g.prev_length,o=g.nice_match,A=g.strstart>g.w_size-sA?g.strstart-(g.w_size-sA):0,s=g.window,a=g.w_mask,l=g.prev,c=g.strstart+Xc,u=s[i+r-1],d=s[i+r];g.prev_length>=g.good_match&&(I>>=2),o>g.lookahead&&(o=g.lookahead);do if(n=e,!(s[n+r]!==d||s[n+r-1]!==u||s[n]!==s[i]||s[++n]!==s[i+1])){i+=2,n++;do;while(s[++i]===s[++n]&&s[++i]===s[++n]&&s[++i]===s[++n]&&s[++i]===s[++n]&&s[++i]===s[++n]&&s[++i]===s[++n]&&s[++i]===s[++n]&&s[++i]===s[++n]&&ir){if(g.match_start=e,r=C,C>=o)break;u=s[i+r-1],d=s[i+r]}}while((e=l[e&a])>A&&--I!==0);return r<=g.lookahead?r:g.lookahead}function Bh(g){var e=g.w_size,I,i,n,C,r;do{if(C=g.window_size-g.lookahead-g.strstart,g.strstart>=e+(e-sA)){Qn.arraySet(g.window,g.window,e,e,0),g.match_start-=e,g.strstart-=e,g.block_start-=e,i=g.hash_size,I=i;do n=g.head[--I],g.head[I]=n>=e?n-e:0;while(--i);i=e,I=i;do n=g.prev[--I],g.prev[I]=n>=e?n-e:0;while(--i);C+=e}if(g.strm.avail_in===0)break;if(i=H1t(g.strm,g.window,g.strstart+g.lookahead,C),g.lookahead+=i,g.lookahead+g.insert>=Vg)for(r=g.strstart-g.insert,g.ins_h=g.window[r],g.ins_h=(g.ins_h<g.pending_buf_size-5&&(I=g.pending_buf_size-5);;){if(g.lookahead<=1){if(Bh(g),g.lookahead===0&&e===Zm)return Ri;if(g.lookahead===0)break}g.strstart+=g.lookahead,g.lookahead=0;var i=g.block_start+I;if((g.strstart===0||g.strstart>=i)&&(g.lookahead=g.strstart-i,g.strstart=i,an(g,!1),g.strm.avail_out===0)||g.strstart-g.block_start>=g.w_size-sA&&(an(g,!1),g.strm.avail_out===0))return Ri}return g.insert=0,e===Lc?(an(g,!0),g.strm.avail_out===0?Gh:ay):(g.strstart>g.block_start&&(an(g,!1),g.strm.avail_out===0),Ri)}function ED(g,e){for(var I,i;;){if(g.lookahead=Vg&&(g.ins_h=(g.ins_h<=Vg)if(i=io._tr_tally(g,g.strstart-g.match_start,g.match_length-Vg),g.lookahead-=g.match_length,g.match_length<=g.max_lazy_match&&g.lookahead>=Vg){g.match_length--;do g.strstart++,g.ins_h=(g.ins_h<=Vg&&(g.ins_h=(g.ins_h<4096)&&(g.match_length=Vg-1)),g.prev_length>=Vg&&g.match_length<=g.prev_length){n=g.strstart+g.lookahead-Vg,i=io._tr_tally(g,g.strstart-1-g.prev_match,g.prev_length-Vg),g.lookahead-=g.prev_length-1,g.prev_length-=2;do++g.strstart<=n&&(g.ins_h=(g.ins_h<=Vg&&g.strstart>0&&(n=g.strstart-1,i=r[n],i===r[++n]&&i===r[++n]&&i===r[++n])){C=g.strstart+Xc;do;while(i===r[++n]&&i===r[++n]&&i===r[++n]&&i===r[++n]&&i===r[++n]&&i===r[++n]&&i===r[++n]&&i===r[++n]&&ng.lookahead&&(g.match_length=g.lookahead)}if(g.match_length>=Vg?(I=io._tr_tally(g,1,g.match_length-Vg),g.lookahead-=g.match_length,g.strstart+=g.match_length,g.match_length=0):(I=io._tr_tally(g,0,g.window[g.strstart]),g.lookahead--,g.strstart++),I&&(an(g,!1),g.strm.avail_out===0))return Ri}return g.insert=0,e===Lc?(an(g,!0),g.strm.avail_out===0?Gh:ay):g.last_lit&&(an(g,!1),g.strm.avail_out===0)?Ri:ww}function k1t(g,e){for(var I;;){if(g.lookahead===0&&(Bh(g),g.lookahead===0)){if(e===Zm)return Ri;break}if(g.match_length=0,I=io._tr_tally(g,0,g.window[g.strstart]),g.lookahead--,g.strstart++,I&&(an(g,!1),g.strm.avail_out===0))return Ri}return g.insert=0,e===Lc?(an(g,!0),g.strm.avail_out===0?Gh:ay):g.last_lit&&(an(g,!1),g.strm.avail_out===0)?Ri:ww}function HA(g,e,I,i,n){this.good_length=g,this.max_lazy=e,this.nice_length=I,this.max_chain=i,this.func=n}var Gp;Gp=[new HA(0,0,0,0,T1t),new HA(4,4,8,4,ED),new HA(4,5,16,8,ED),new HA(4,6,32,32,ED),new HA(4,4,16,16,nf),new HA(8,16,32,32,nf),new HA(8,16,128,128,nf),new HA(8,32,128,256,nf),new HA(32,128,258,1024,nf),new HA(32,258,258,4096,nf)];function Y1t(g){g.window_size=2*g.w_size,lc(g.head),g.max_lazy_match=Gp[g.level].max_lazy,g.good_match=Gp[g.level].good_length,g.nice_match=Gp[g.level].nice_length,g.max_chain_length=Gp[g.level].max_chain,g.strstart=0,g.block_start=0,g.lookahead=0,g.insert=0,g.match_length=g.prev_length=Vg-1,g.match_available=0,g.ins_h=0}function K1t(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=Ok,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new Qn.Buf16(V1t*2),this.dyn_dtree=new Qn.Buf16((2*S1t+1)*2),this.bl_tree=new Qn.Buf16((2*w1t+1)*2),lc(this.dyn_ltree),lc(this.dyn_dtree),lc(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new Qn.Buf16(R1t+1),this.heap=new Qn.Buf16(2*gP+1),lc(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new Qn.Buf16(2*gP+1),lc(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}function hRe(g){var e;return!g||!g.state?Hc(g,no):(g.total_in=g.total_out=0,g.data_type=b1t,e=g.state,e.pending=0,e.pending_out=0,e.wrap<0&&(e.wrap=-e.wrap),e.status=e.wrap?Lk:pd,g.adler=e.wrap===2?0:1,e.last_flush=Zm,io._tr_init(e),$A)}function mRe(g){var e=hRe(g);return e===$A&&Y1t(g.state),e}function x1t(g,e){return!g||!g.state||g.state.wrap!==2?no:(g.state.gzhead=e,$A)}function fRe(g,e,I,i,n,C){if(!g)return no;var r=1;if(e===d1t&&(e=6),i<0?(r=0,i=-i):i>15&&(r=2,i-=16),n<1||n>y1t||I!==Ok||i<8||i>15||e<0||e>9||C<0||C>f1t)return Hc(g,no);i===8&&(i=9);var o=new K1t;return g.state=o,o.strm=g,o.wrap=r,o.gzhead=null,o.w_bits=i,o.w_size=1<ere||e<0)return g?Hc(g,no):no;if(i=g.state,!g.output||!g.input&&g.avail_in!==0||i.status===rG&&e!==Lc)return Hc(g,g.avail_out===0?FD:no);if(i.strm=g,I=i.last_flush,i.last_flush=e,i.status===Lk)if(i.wrap===2)g.adler=0,Yg(i,31),Yg(i,139),Yg(i,8),i.gzhead?(Yg(i,(i.gzhead.text?1:0)+(i.gzhead.hcrc?2:0)+(i.gzhead.extra?4:0)+(i.gzhead.name?8:0)+(i.gzhead.comment?16:0)),Yg(i,i.gzhead.time&255),Yg(i,i.gzhead.time>>8&255),Yg(i,i.gzhead.time>>16&255),Yg(i,i.gzhead.time>>24&255),Yg(i,i.level===9?2:i.strategy>=kR||i.level<2?4:0),Yg(i,i.gzhead.os&255),i.gzhead.extra&&i.gzhead.extra.length&&(Yg(i,i.gzhead.extra.length&255),Yg(i,i.gzhead.extra.length>>8&255)),i.gzhead.hcrc&&(g.adler=Pl(g.adler,i.pending_buf,i.pending,0)),i.gzindex=0,i.status=IP):(Yg(i,0),Yg(i,0),Yg(i,0),Yg(i,0),Yg(i,0),Yg(i,i.level===9?2:i.strategy>=kR||i.level<2?4:0),Yg(i,X1t),i.status=pd);else{var r=Ok+(i.w_bits-8<<4)<<8,o=-1;i.strategy>=kR||i.level<2?o=0:i.level<6?o=1:i.level===6?o=2:o=3,r|=o<<6,i.strstart!==0&&(r|=W1t),r+=31-r%31,i.status=pd,hZ(i,r),i.strstart!==0&&(hZ(i,g.adler>>>16),hZ(i,g.adler&65535)),g.adler=1}if(i.status===IP)if(i.gzhead.extra){for(n=i.pending;i.gzindex<(i.gzhead.extra.length&65535)&&!(i.pending===i.pending_buf_size&&(i.gzhead.hcrc&&i.pending>n&&(g.adler=Pl(g.adler,i.pending_buf,i.pending-n,n)),Jl(g),n=i.pending,i.pending===i.pending_buf_size));)Yg(i,i.gzhead.extra[i.gzindex]&255),i.gzindex++;i.gzhead.hcrc&&i.pending>n&&(g.adler=Pl(g.adler,i.pending_buf,i.pending-n,n)),i.gzindex===i.gzhead.extra.length&&(i.gzindex=0,i.status=fW)}else i.status=fW;if(i.status===fW)if(i.gzhead.name){n=i.pending;do{if(i.pending===i.pending_buf_size&&(i.gzhead.hcrc&&i.pending>n&&(g.adler=Pl(g.adler,i.pending_buf,i.pending-n,n)),Jl(g),n=i.pending,i.pending===i.pending_buf_size)){C=1;break}i.gzindexn&&(g.adler=Pl(g.adler,i.pending_buf,i.pending-n,n)),C===0&&(i.gzindex=0,i.status=pW)}else i.status=pW;if(i.status===pW)if(i.gzhead.comment){n=i.pending;do{if(i.pending===i.pending_buf_size&&(i.gzhead.hcrc&&i.pending>n&&(g.adler=Pl(g.adler,i.pending_buf,i.pending-n,n)),Jl(g),n=i.pending,i.pending===i.pending_buf_size)){C=1;break}i.gzindexn&&(g.adler=Pl(g.adler,i.pending_buf,i.pending-n,n)),C===0&&(i.status=bW)}else i.status=bW;if(i.status===bW&&(i.gzhead.hcrc?(i.pending+2>i.pending_buf_size&&Jl(g),i.pending+2<=i.pending_buf_size&&(Yg(i,g.adler&255),Yg(i,g.adler>>8&255),g.adler=0,i.status=pd)):i.status=pd),i.pending!==0){if(Jl(g),g.avail_out===0)return i.last_flush=-1,$A}else if(g.avail_in===0&&gre(e)<=gre(I)&&e!==Lc)return Hc(g,FD);if(i.status===rG&&g.avail_in!==0)return Hc(g,FD);if(g.avail_in!==0||i.lookahead!==0||e!==Zm&&i.status!==rG){var A=i.strategy===kR?k1t(i,e):i.strategy===m1t?N1t(i,e):Gp[i.level].func(i,e);if((A===Gh||A===ay)&&(i.status=rG),A===Ri||A===Gh)return g.avail_out===0&&(i.last_flush=-1),$A;if(A===ww&&(e===l1t?io._tr_align(i):e!==ere&&(io._tr_stored_block(i,0,0,!1),e===c1t&&(lc(i.head),i.lookahead===0&&(i.strstart=0,i.block_start=0,i.insert=0))),Jl(g),g.avail_out===0))return i.last_flush=-1,$A}return e!==Lc?$A:i.wrap<=0?tre:(i.wrap===2?(Yg(i,g.adler&255),Yg(i,g.adler>>8&255),Yg(i,g.adler>>16&255),Yg(i,g.adler>>24&255),Yg(i,g.total_in&255),Yg(i,g.total_in>>8&255),Yg(i,g.total_in>>16&255),Yg(i,g.total_in>>24&255)):(hZ(i,g.adler>>>16),hZ(i,g.adler&65535)),Jl(g),i.wrap>0&&(i.wrap=-i.wrap),i.pending!==0?$A:tre)}function E1t(g){var e;return!g||!g.state?no:(e=g.state.status,e!==Lk&&e!==IP&&e!==fW&&e!==pW&&e!==bW&&e!==pd&&e!==rG?Hc(g,no):(g.state=null,e===pd?Hc(g,u1t):$A))}function M1t(g,e){var I=e.length,i,n,C,r,o,A,s,a;if(!g||!g.state||(i=g.state,r=i.wrap,r===2||r===1&&i.status!==Lk||i.lookahead))return no;for(r===1&&(g.adler=uRe(g.adler,e,I,0)),i.wrap=0,I>=i.w_size&&(r===0&&(lc(i.head),i.strstart=0,i.block_start=0,i.insert=0),a=new Qn.Buf8(i.w_size),Qn.arraySet(a,e,I-i.w_size,i.w_size,0),e=a,I=i.w_size),o=g.avail_in,A=g.next_in,s=g.input,g.avail_in=I,g.next_in=0,g.input=e,Bh(i);i.lookahead>=Vg;){n=i.strstart,C=i.lookahead-(Vg-1);do i.ins_h=(i.ins_h<=252?6:Hl>=248?5:Hl>=240?4:Hl>=224?3:Hl>=192?2:1;IS[254]=IS[254]=1;Gm.string2buf=function(g){var e,I,i,n,C,r=g.length,o=0;for(n=0;n>>6,e[C++]=128|I&63):I<65536?(e[C++]=224|I>>>12,e[C++]=128|I>>>6&63,e[C++]=128|I&63):(e[C++]=240|I>>>18,e[C++]=128|I>>>12&63,e[C++]=128|I>>>6&63,e[C++]=128|I&63);return e};function yRe(g,e){if(e<65534&&(g.subarray&&bRe||!g.subarray&&pRe))return String.fromCharCode.apply(null,_k.shrinkBuf(g,e));for(var I="",i=0;i4){o[i++]=65533,I+=C-1;continue}for(n&=C===2?31:C===3?15:7;C>1&&I1){o[i++]=65533;continue}n<65536?o[i++]=n:(n-=65536,o[i++]=55296|n>>10&1023,o[i++]=56320|n&1023)}return yRe(o,i)};Gm.utf8border=function(g,e){var I;for(e=e||g.length,e>g.length&&(e=g.length),I=e-1;I>=0&&(g[I]&192)===128;)I--;return I<0||I===0?e:I+IS[g[I]]>e?I:e};function z1t(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0}var ZRe=z1t,ZB=Ka,GB=fl,iP=Gm,nP=Jj,P1t=ZRe,GRe=Object.prototype.toString,J1t=0,MD=4,eb=0,Ire=1,ire=2,O1t=-1,L1t=0,_1t=8;function vh(g){if(!(this instanceof vh))return new vh(g);this.options=GB.assign({level:O1t,method:_1t,chunkSize:16384,windowBits:15,memLevel:8,strategy:L1t,to:""},g||{});var e=this.options;e.raw&&e.windowBits>0?e.windowBits=-e.windowBits:e.gzip&&e.windowBits>0&&e.windowBits<16&&(e.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new P1t,this.strm.avail_out=0;var I=ZB.deflateInit2(this.strm,e.level,e.method,e.windowBits,e.memLevel,e.strategy);if(I!==eb)throw new Error(nP[I]);if(e.header&&ZB.deflateSetHeader(this.strm,e.header),e.dictionary){var i;if(typeof e.dictionary=="string"?i=iP.string2buf(e.dictionary):GRe.call(e.dictionary)==="[object ArrayBuffer]"?i=new Uint8Array(e.dictionary):i=e.dictionary,I=ZB.deflateSetDictionary(this.strm,i),I!==eb)throw new Error(nP[I]);this._dict_set=!0}}vh.prototype.push=function(g,e){var I=this.strm,i=this.options.chunkSize,n,C;if(this.ended)return!1;C=e===~~e?e:e===!0?MD:J1t,typeof g=="string"?I.input=iP.string2buf(g):GRe.call(g)==="[object ArrayBuffer]"?I.input=new Uint8Array(g):I.input=g,I.next_in=0,I.avail_in=I.input.length;do{if(I.avail_out===0&&(I.output=new GB.Buf8(i),I.next_out=0,I.avail_out=i),n=ZB.deflate(I,C),n!==Ire&&n!==eb)return this.onEnd(n),this.ended=!0,!1;(I.avail_out===0||I.avail_in===0&&(C===MD||C===ire))&&(this.options.to==="string"?this.onData(iP.buf2binstring(GB.shrinkBuf(I.output,I.next_out))):this.onData(GB.shrinkBuf(I.output,I.next_out)))}while((I.avail_in>0||I.avail_out===0)&&n!==Ire);return C===MD?(n=ZB.deflateEnd(this.strm),this.onEnd(n),this.ended=!0,n===eb):(C===ire&&(this.onEnd(eb),I.avail_out=0),!0)};vh.prototype.onData=function(g){this.chunks.push(g)};vh.prototype.onEnd=function(g){g===eb&&(this.options.to==="string"?this.result=this.chunks.join(""):this.result=GB.flattenChunks(this.chunks)),this.chunks=[],this.err=g,this.msg=this.strm.msg};function Oj(g,e){var I=new vh(e);if(I.push(g,!0),I.err)throw I.msg||nP[I.err];return I.result}function U1t(g,e){return e=e||{},e.raw=!0,Oj(g,e)}function Q1t(g,e){return e=e||{},e.gzip=!0,Oj(g,e)}vw.Deflate=vh;vw.deflate=Oj;vw.deflateRaw=U1t;vw.gzip=Q1t;var Vw={},BA={},YR=30,j1t=12,$1t=function(e,I){var i,n,C,r,o,A,s,a,l,c,u,d,h,m,f,b,p,y,Z,v,G,B,w,R,S;i=e.state,n=e.next_in,R=e.input,C=n+(e.avail_in-5),r=e.next_out,S=e.output,o=r-(I-e.avail_out),A=r+(e.avail_out-257),s=i.dmax,a=i.wsize,l=i.whave,c=i.wnext,u=i.window,d=i.hold,h=i.bits,m=i.lencode,f=i.distcode,b=(1<>>24,d>>>=Z,h-=Z,Z=y>>>16&255,Z===0)S[r++]=y&65535;else if(Z&16){v=y&65535,Z&=15,Z&&(h>>=Z,h-=Z),h<15&&(d+=R[n++]<>>24,d>>>=Z,h-=Z,Z=y>>>16&255,Z&16){if(G=y&65535,Z&=15,hs){e.msg="invalid distance too far back",i.mode=YR;break e}if(d>>>=Z,h-=Z,Z=r-o,G>Z){if(Z=G-Z,Z>l&&i.sane){e.msg="invalid distance too far back",i.mode=YR;break e}if(B=0,w=u,c===0){if(B+=a-Z,Z2;)S[r++]=w[B++],S[r++]=w[B++],S[r++]=w[B++],v-=3;v&&(S[r++]=w[B++],v>1&&(S[r++]=w[B++]))}else{B=r-G;do S[r++]=S[B++],S[r++]=S[B++],S[r++]=S[B++],v-=3;while(v>2);v&&(S[r++]=S[B++],v>1&&(S[r++]=S[B++]))}}else if(Z&64){e.msg="invalid distance code",i.mode=YR;break e}else{y=f[(y&65535)+(d&(1<>3,n-=v,h-=v<<3,d&=(1<=1&&X[u]===0;u--);if(d>u&&(d=u),u===0)return C[r++]=1<<24|64<<16|0,C[r++]=1<<24|64<<16|0,A.bits=1,0;for(c=1;c0&&(e===ore||u!==1))return-1;for(W[1]=0,a=1;aCre||e===Are&&b>rre)return 1;for(;;){D=a-m,o[l]S?(Y=V[H+o[l]],F=w[R+o[l]]):(Y=32+64,F=0),y=1<>m)+Z]=D<<24|Y<<16|F|0;while(Z!==0);for(y=1<>=1;if(y!==0?(p&=y-1,p+=y):p=0,l++,--X[a]===0){if(a===u)break;a=I[i+o[l]]}if(a>d&&(p&G)!==v){for(m===0&&(m=d),B+=c,h=a-m,f=1<Cre||e===Are&&b>rre)return 1;v=p&G,C[v]=d<<24|h<<16|B-r|0}}return p!==0&&(C[B+p]=a-m<<24|64<<16|0),A.bits=d,0},cr=fl,CP=lRe,TA=cRe,iWt=$1t,BB=IWt,nWt=0,BRe=1,vRe=2,are=4,CWt=5,KR=6,Sh=0,rWt=1,oWt=2,Ao=-2,SRe=-3,wRe=-4,AWt=-5,sre=8,VRe=1,lre=2,cre=3,ure=4,dre=5,hre=6,mre=7,fre=8,pre=9,bre=10,pH=11,La=12,PD=13,yre=14,JD=15,Zre=16,Gre=17,Bre=18,vre=19,xR=20,DR=21,Sre=22,wre=23,Vre=24,Rre=25,Wre=26,OD=27,Xre=28,Hre=29,BI=30,RRe=31,aWt=32,sWt=852,lWt=592,cWt=15,uWt=cWt;function Tre(g){return(g>>>24&255)+(g>>>8&65280)+((g&65280)<<8)+((g&255)<<24)}function dWt(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new cr.Buf16(320),this.work=new cr.Buf16(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}function WRe(g){var e;return!g||!g.state?Ao:(e=g.state,g.total_in=g.total_out=e.total=0,g.msg="",e.wrap&&(g.adler=e.wrap&1),e.mode=VRe,e.last=0,e.havedict=0,e.dmax=32768,e.head=null,e.hold=0,e.bits=0,e.lencode=e.lendyn=new cr.Buf32(sWt),e.distcode=e.distdyn=new cr.Buf32(lWt),e.sane=1,e.back=-1,Sh)}function XRe(g){var e;return!g||!g.state?Ao:(e=g.state,e.wsize=0,e.whave=0,e.wnext=0,WRe(g))}function HRe(g,e){var I,i;return!g||!g.state||(i=g.state,e<0?(I=0,e=-e):(I=(e>>4)+1,e<48&&(e&=15)),e&&(e<8||e>15))?Ao:(i.window!==null&&i.wbits!==e&&(i.window=null),i.wrap=I,i.wbits=e,XRe(g))}function TRe(g,e){var I,i;return g?(i=new dWt,g.state=i,i.window=null,I=HRe(g,e),I!==Sh&&(g.state=null),I):Ao}function hWt(g){return TRe(g,uWt)}var Nre=!0,LD,_D;function mWt(g){if(Nre){var e;for(LD=new cr.Buf32(512),_D=new cr.Buf32(32),e=0;e<144;)g.lens[e++]=8;for(;e<256;)g.lens[e++]=9;for(;e<280;)g.lens[e++]=7;for(;e<288;)g.lens[e++]=8;for(BB(BRe,g.lens,0,288,LD,0,g.work,{bits:9}),e=0;e<32;)g.lens[e++]=5;BB(vRe,g.lens,0,32,_D,0,g.work,{bits:5}),Nre=!1}g.lencode=LD,g.lenbits=9,g.distcode=_D,g.distbits=5}function NRe(g,e,I,i){var n,C=g.state;return C.window===null&&(C.wsize=1<=C.wsize?(cr.arraySet(C.window,e,I-C.wsize,C.wsize,0),C.wnext=0,C.whave=C.wsize):(n=C.wsize-C.wnext,n>i&&(n=i),cr.arraySet(C.window,e,I-i,n,C.wnext),i-=n,i?(cr.arraySet(C.window,e,I-i,i,0),C.wnext=i,C.whave=C.wsize):(C.wnext+=n,C.wnext===C.wsize&&(C.wnext=0),C.whave>>8&255,I.check=TA(I.check,w,2,0),s=0,a=0,I.mode=lre;break}if(I.flags=0,I.head&&(I.head.done=!1),!(I.wrap&1)||(((s&255)<<8)+(s>>8))%31){g.msg="incorrect header check",I.mode=BI;break}if((s&15)!==sre){g.msg="unknown compression method",I.mode=BI;break}if(s>>>=4,a-=4,G=(s&15)+8,I.wbits===0)I.wbits=G;else if(G>I.wbits){g.msg="invalid window size",I.mode=BI;break}I.dmax=1<>8&1),I.flags&512&&(w[0]=s&255,w[1]=s>>>8&255,I.check=TA(I.check,w,2,0)),s=0,a=0,I.mode=cre;case cre:for(;a<32;){if(o===0)break e;o--,s+=i[C++]<>>8&255,w[2]=s>>>16&255,w[3]=s>>>24&255,I.check=TA(I.check,w,4,0)),s=0,a=0,I.mode=ure;case ure:for(;a<16;){if(o===0)break e;o--,s+=i[C++]<>8),I.flags&512&&(w[0]=s&255,w[1]=s>>>8&255,I.check=TA(I.check,w,2,0)),s=0,a=0,I.mode=dre;case dre:if(I.flags&1024){for(;a<16;){if(o===0)break e;o--,s+=i[C++]<>>8&255,I.check=TA(I.check,w,2,0)),s=0,a=0}else I.head&&(I.head.extra=null);I.mode=hre;case hre:if(I.flags&1024&&(u=I.length,u>o&&(u=o),u&&(I.head&&(G=I.head.extra_len-I.length,I.head.extra||(I.head.extra=new Array(I.head.extra_len)),cr.arraySet(I.head.extra,i,C,u,G)),I.flags&512&&(I.check=TA(I.check,i,u,C)),o-=u,C+=u,I.length-=u),I.length))break e;I.length=0,I.mode=mre;case mre:if(I.flags&2048){if(o===0)break e;u=0;do G=i[C+u++],I.head&&G&&I.length<65536&&(I.head.name+=String.fromCharCode(G));while(G&&u>9&1,I.head.done=!0),g.adler=I.check=0,I.mode=La;break;case bre:for(;a<32;){if(o===0)break e;o--,s+=i[C++]<>>=a&7,a-=a&7,I.mode=OD;break}for(;a<3;){if(o===0)break e;o--,s+=i[C++]<>>=1,a-=1,s&3){case 0:I.mode=yre;break;case 1:if(mWt(I),I.mode=xR,e===KR){s>>>=2,a-=2;break e}break;case 2:I.mode=Gre;break;case 3:g.msg="invalid block type",I.mode=BI}s>>>=2,a-=2;break;case yre:for(s>>>=a&7,a-=a&7;a<32;){if(o===0)break e;o--,s+=i[C++]<>>16^65535)){g.msg="invalid stored block lengths",I.mode=BI;break}if(I.length=s&65535,s=0,a=0,I.mode=JD,e===KR)break e;case JD:I.mode=Zre;case Zre:if(u=I.length,u){if(u>o&&(u=o),u>A&&(u=A),u===0)break e;cr.arraySet(n,i,C,u,r),o-=u,C+=u,A-=u,r+=u,I.length-=u;break}I.mode=La;break;case Gre:for(;a<14;){if(o===0)break e;o--,s+=i[C++]<>>=5,a-=5,I.ndist=(s&31)+1,s>>>=5,a-=5,I.ncode=(s&15)+4,s>>>=4,a-=4,I.nlen>286||I.ndist>30){g.msg="too many length or distance symbols",I.mode=BI;break}I.have=0,I.mode=Bre;case Bre:for(;I.have>>=3,a-=3}for(;I.have<19;)I.lens[X[I.have++]]=0;if(I.lencode=I.lendyn,I.lenbits=7,R={bits:I.lenbits},B=BB(nWt,I.lens,0,19,I.lencode,0,I.work,R),I.lenbits=R.bits,B){g.msg="invalid code lengths set",I.mode=BI;break}I.have=0,I.mode=vre;case vre:for(;I.have>>24,b=m>>>16&255,p=m&65535,!(f<=a);){if(o===0)break e;o--,s+=i[C++]<>>=f,a-=f,I.lens[I.have++]=p;else{if(p===16){for(S=f+2;a>>=f,a-=f,I.have===0){g.msg="invalid bit length repeat",I.mode=BI;break}G=I.lens[I.have-1],u=3+(s&3),s>>>=2,a-=2}else if(p===17){for(S=f+3;a>>=f,a-=f,G=0,u=3+(s&7),s>>>=3,a-=3}else{for(S=f+7;a>>=f,a-=f,G=0,u=11+(s&127),s>>>=7,a-=7}if(I.have+u>I.nlen+I.ndist){g.msg="invalid bit length repeat",I.mode=BI;break}for(;u--;)I.lens[I.have++]=G}}if(I.mode===BI)break;if(I.lens[256]===0){g.msg="invalid code -- missing end-of-block",I.mode=BI;break}if(I.lenbits=9,R={bits:I.lenbits},B=BB(BRe,I.lens,0,I.nlen,I.lencode,0,I.work,R),I.lenbits=R.bits,B){g.msg="invalid literal/lengths set",I.mode=BI;break}if(I.distbits=6,I.distcode=I.distdyn,R={bits:I.distbits},B=BB(vRe,I.lens,I.nlen,I.ndist,I.distcode,0,I.work,R),I.distbits=R.bits,B){g.msg="invalid distances set",I.mode=BI;break}if(I.mode=xR,e===KR)break e;case xR:I.mode=DR;case DR:if(o>=6&&A>=258){g.next_out=r,g.avail_out=A,g.next_in=C,g.avail_in=o,I.hold=s,I.bits=a,iWt(g,c),r=g.next_out,n=g.output,A=g.avail_out,C=g.next_in,i=g.input,o=g.avail_in,s=I.hold,a=I.bits,I.mode===La&&(I.back=-1);break}for(I.back=0;m=I.lencode[s&(1<>>24,b=m>>>16&255,p=m&65535,!(f<=a);){if(o===0)break e;o--,s+=i[C++]<>y)],f=m>>>24,b=m>>>16&255,p=m&65535,!(y+f<=a);){if(o===0)break e;o--,s+=i[C++]<>>=y,a-=y,I.back+=y}if(s>>>=f,a-=f,I.back+=f,I.length=p,b===0){I.mode=Wre;break}if(b&32){I.back=-1,I.mode=La;break}if(b&64){g.msg="invalid literal/length code",I.mode=BI;break}I.extra=b&15,I.mode=Sre;case Sre:if(I.extra){for(S=I.extra;a>>=I.extra,a-=I.extra,I.back+=I.extra}I.was=I.length,I.mode=wre;case wre:for(;m=I.distcode[s&(1<>>24,b=m>>>16&255,p=m&65535,!(f<=a);){if(o===0)break e;o--,s+=i[C++]<>y)],f=m>>>24,b=m>>>16&255,p=m&65535,!(y+f<=a);){if(o===0)break e;o--,s+=i[C++]<>>=y,a-=y,I.back+=y}if(s>>>=f,a-=f,I.back+=f,b&64){g.msg="invalid distance code",I.mode=BI;break}I.offset=p,I.extra=b&15,I.mode=Vre;case Vre:if(I.extra){for(S=I.extra;a>>=I.extra,a-=I.extra,I.back+=I.extra}if(I.offset>I.dmax){g.msg="invalid distance too far back",I.mode=BI;break}I.mode=Rre;case Rre:if(A===0)break e;if(u=c-A,I.offset>u){if(u=I.offset-u,u>I.whave&&I.sane){g.msg="invalid distance too far back",I.mode=BI;break}u>I.wnext?(u-=I.wnext,d=I.wsize-u):d=I.wnext-u,u>I.length&&(u=I.length),h=I.window}else h=n,d=r-I.offset,u=I.length;u>A&&(u=A),A-=u,I.length-=u;do n[r++]=h[d++];while(--u);I.length===0&&(I.mode=DR);break;case Wre:if(A===0)break e;n[r++]=I.length,A--,I.mode=DR;break;case OD:if(I.wrap){for(;a<32;){if(o===0)break e;o--,s|=i[C++]<=0&&e.windowBits<16&&(e.windowBits=-e.windowBits,e.windowBits===0&&(e.windowBits=-15)),e.windowBits>=0&&e.windowBits<16&&!(g&&g.windowBits)&&(e.windowBits+=32),e.windowBits>15&&e.windowBits<48&&(e.windowBits&15||(e.windowBits|=15)),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new BWt,this.strm.avail_out=0;var I=tb.inflateInit2(this.strm,e.windowBits);if(I!==gi.Z_OK)throw new Error(rP[I]);if(this.header=new vWt,tb.inflateGetHeader(this.strm,this.header),e.dictionary&&(typeof e.dictionary=="string"?e.dictionary=yW.string2buf(e.dictionary):YRe.call(e.dictionary)==="[object ArrayBuffer]"&&(e.dictionary=new Uint8Array(e.dictionary)),e.raw&&(I=tb.inflateSetDictionary(this.strm,e.dictionary),I!==gi.Z_OK)))throw new Error(rP[I])}wh.prototype.push=function(g,e){var I=this.strm,i=this.options.chunkSize,n=this.options.dictionary,C,r,o,A,s,a=!1;if(this.ended)return!1;r=e===~~e?e:e===!0?gi.Z_FINISH:gi.Z_NO_FLUSH,typeof g=="string"?I.input=yW.binstring2buf(g):YRe.call(g)==="[object ArrayBuffer]"?I.input=new Uint8Array(g):I.input=g,I.next_in=0,I.avail_in=I.input.length;do{if(I.avail_out===0&&(I.output=new vB.Buf8(i),I.next_out=0,I.avail_out=i),C=tb.inflate(I,gi.Z_NO_FLUSH),C===gi.Z_NEED_DICT&&n&&(C=tb.inflateSetDictionary(this.strm,n)),C===gi.Z_BUF_ERROR&&a===!0&&(C=gi.Z_OK,a=!1),C!==gi.Z_STREAM_END&&C!==gi.Z_OK)return this.onEnd(C),this.ended=!0,!1;I.next_out&&(I.avail_out===0||C===gi.Z_STREAM_END||I.avail_in===0&&(r===gi.Z_FINISH||r===gi.Z_SYNC_FLUSH))&&(this.options.to==="string"?(o=yW.utf8border(I.output,I.next_out),A=I.next_out-o,s=yW.buf2string(I.output,o),I.next_out=A,I.avail_out=i-A,A&&vB.arraySet(I.output,I.output,o,A,0),this.onData(s)):this.onData(vB.shrinkBuf(I.output,I.next_out))),I.avail_in===0&&I.avail_out===0&&(a=!0)}while((I.avail_in>0||I.avail_out===0)&&C!==gi.Z_STREAM_END);return C===gi.Z_STREAM_END&&(r=gi.Z_FINISH),r===gi.Z_FINISH?(C=tb.inflateEnd(this.strm),this.onEnd(C),this.ended=!0,C===gi.Z_OK):(r===gi.Z_SYNC_FLUSH&&(this.onEnd(gi.Z_OK),I.avail_out=0),!0)};wh.prototype.onData=function(g){this.chunks.push(g)};wh.prototype.onEnd=function(g){g===gi.Z_OK&&(this.options.to==="string"?this.result=this.chunks.join(""):this.result=vB.flattenChunks(this.chunks)),this.chunks=[],this.err=g,this.msg=this.strm.msg};function Lj(g,e){var I=new wh(e);if(I.push(g,!0),I.err)throw I.msg||rP[I.err];return I.result}function SWt(g,e){return e=e||{},e.raw=!0,Lj(g,e)}Vw.Inflate=wh;Vw.inflate=Lj;Vw.inflateRaw=SWt;Vw.ungzip=Lj;var wWt=fl.assign,VWt=vw,RWt=Vw,WWt=kRe,KRe={};wWt(KRe,VWt,RWt,WWt);var XWt=KRe;const HWt=FC(XWt);var TWt=["JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC"];const NWt=TWt;function kWt(g){if(typeof g!="string")throw new TypeError("input must be a string");let e=[],I,i,n={LOCUS_TAG:"LOCUS",DEFINITION_TAG:"DEFINITION",ACCESSION_TAG:"ACCESSION",VERSION_TAG:"VERSION",KEYWORDS_TAG:"KEYWORDS",SOURCE_TAG:"SOURCE",ORGANISM_TAG:"ORGANISM",REFERENCE_TAG:"REFERENCE",AUTHORS_TAG:"AUTHORS",CONSORTIUM_TAG:"CONSRTM",TITLE_TAG:"TITLE",JOURNAL_TAG:"JOURNAL",PUBMED_TAG:"PUBMED",REMARK_TAG:"REMARK",FEATURES_TAG:"FEATURES",BASE_COUNT_TAG:"BASE COUNT",ORIGIN_TAG:"ORIGIN",END_SEQUENCE_TAG:"//"},C=g.split(/\r?\n/),r,o,A,s,a,l=!1;for(let V of C){if(V===null)break;let H=B(V),D=R(V),Y=X(V),F=S(V);if(H===n.END_SEQUENCE_TAG||F?(r=H,o=null):Y&&(o=H),!(V.trim()===""||H===";")){if(!l&&r!==n.LOCUS_TAG)break;switch(r){case n.LOCUS_TAG:l=!0,m(V);break;case n.FEATURES_TAG:p(V,H,D);break;case n.ORIGIN_TAG:h(V,H);break;case n.DEFINITION_TAG:case n.ACCESSION_TAG:case n.VERSION_TAG:case n.KEYWORDS_TAG:w(r,V,r.toLowerCase());break;case n.SOURCE_TAG:o===n.ORGANISM_TAG?w(o,V,"organism"):w(H,V,"source");break;case n.REFERENCE_TAG:if(H===n.REFERENCE_TAG){const _=I.references||[];I.references=_,_.push({})}b(V,o);break;case n.END_SEQUENCE_TAG:c();break}}}return e[e.length-1]!==I&&c(),e;function c(){d(),e.push(I)}function u(){return I.features[I.features.length-1]}function d(){if(I&&I.features)for(let V=0;V0;e--){const I=Math.floor(Math.random()*(e+1)),i=g[e];g[e]=g[I],g[I]=i}return g}function PWt(g){return g.type==="filler"}function JWt(g){const e=g.end-g.start,I=g.strand===1?"+":"-",i=dg.nice();return PWt(g)?{xStart:g.start,xEnd:g.end,strand:g.strand,fields:[],type:"filler",uid:i}:{xStart:g.start,xEnd:g.end,strand:I,chrOffset:0,importance:g.end-g.start,uid:i,type:g.type,fields:["chrom",g.start,g.end,g.name,e,I,"","",g.type,g.name,g.start.toString(),g.end.toString(),g.start.toString(),g.end.toString()]}}function OWt(g){const e=xWt(g),I=zWt(e[0].features.filter(i=>i.type!=="source").sort((i,n)=>i.start-n.start));return{json:e,features:I}}async function LWt(g,{gzipped:e}){if(!e)return g.text();const I=await g.arrayBuffer();return HWt.inflate(I,{to:"string"})}let DRe=function(){function g(e){DWt(this,g),this.dataConfig=e,this.trackUid=dg.nice(),this.errorTxt="";let I;if(e.url){const i=e.url.slice(e.url.length-3);I=fetch(e.url,{mode:"cors",redirect:"follow",method:"GET"}).then(n=>LWt(n,{gzipped:i===".gz"}))}else if(e.text)I=Promise.resolve(e.text);else throw new Error("No data or URL specified");this.gbDataPromise=I.then(i=>OWt(i))}return FWt(g,[{key:"tilesetInfo",value:function(I){return this.tilesetInfoLoading=!0,this.gbDataPromise.then(i=>{this.tilesetInfoLoading=!1;const n=1024,C={name:`genbank-${this.trackUid}`,tile_size:n,max_zoom:Math.ceil(Math.log(i.json[0].size/n)/Math.log(2)),max_width:i.json[0].size,min_pos:[0],max_pos:[i.json[0].size]};return I&&I(C),C}).catch(i=>{this.tilesetInfoLoading=!1,I&&I({error:`Error parsing genbank: ${i}`})})}},{key:"fetchTilesDebounced",value:async function(I,i){const n={},C=[],r=[];for(const A of i){const s=A.split("."),a=parseInt(s[0],10),l=parseInt(s[1],10);if(Number.isNaN(l)||Number.isNaN(a)){console.warn("Invalid tile zoom or position:",a,l);continue}C.push(A),r.push(this.tile(a,l))}const o=await Promise.all(r);for(let A=0;Ah.end>o&&h.starth.strand===1),a,"+"),c=Yre(s.filter(h=>h.strand!==1),a,"-"),u=[],d=20;for(let h=0;h=d);h++)C.features[h].end>=o&&C.features[h].start<=A&&u.push(C.features[h]);return[u,l,c].flatMap(h=>h.map(JWt))}}]),g}();function _Wt(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function Kre(g,e){for(var I=0;I`localtile.${r}`);vQ(this.tilesData,"",C);for(const r of i)n[r]=this.tilesData[`localtile.${r}`];return I(n),n}},{key:"tile",value:function(I,i){}}]),g}();function $Wt(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function xre(g,e){for(var I=0;IC.trackId!==n),this.taskList.push({handler:I,data:i,trackId:n})),this.taskHandle||(this.taskHandle=requestIdleCallback(this.runTaskQueue.bind(this),{timeout:this.requestIdleCallbackTimeout}))}},{key:"runTaskQueue",value:function(I){for(;(I.timeRemaining()>0||I.didTimeout)&&this.taskList.length;){const i=this.taskList.shift();i&&gXt(i)?i.handler():i&&i.handler(i.data)}this.taskList.length?this.taskHandle=requestIdleCallback(this.runTaskQueue.bind(this),{timeout:this.requestIdleCallbackTimeout}):this.taskHandle=0}}]),g}();const iXt=new IXt;function nXt(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function Dre(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function Gs(g){return Gs=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},Gs(g)}function uXt(g,e,I,i,n){const C=g||n,r=0;return C==="log"&&e>0?["log",mu().range([254,0]).domain([e+r,i+r])]:["linear",Cg().range([254,0]).domain([e,i])]}let Bm=function(g){aXt(I,g);var e=sXt(I);function I(i,n){var C;nXt(this,I),C=e.call(this,i,n);const{pubSub:r,dataConfig:o,handleTilesetInfoReceived:A,animate:s,onValueScaleChanged:a}=i;return C.renderVersion=1,C.visibleTiles=new Set,C.visibleTileIds=new Set,C.renderingTiles=new Set,C.fetching=new Set,C.scale={},C.fetchedTiles={},C.tileGraphics={},C.maxZoom=0,C.medianVisibleValue=null,C.backgroundTaskScheduler=iXt,C.continuousScaling="requestIdleCallback"in window,C.valueScaleMin=null,C.fixedValueScaleMin=null,C.valueScaleMax=null,C.fixedValueScaleMax=null,C.listeners={},C.pubSub=r,C.animate=s,C.onValueScaleChanged=a,C.prevValueScale=null,i.dataFetcher?C.dataFetcher=i.dataFetcher:C.dataFetcher=new Jk(o,C.pubSub),C.tilesetInfo=null,C.uuid=dg.nice(),C.trackNotFoundText=new Ct.PIXI.Text("",{fontSize:"12px",fontFamily:"Arial",fill:"black"}),C.pLabel.addChild(C.trackNotFoundText),C.refreshTilesDebounced=rBe(C.refreshTiles.bind(AP(C)),E9,E9),C.dataFetcher.tilesetInfo((l,c)=>{if(l){if(C.tilesetInfo=l,C.dataFetcher.dataConfig.tilesetUid||(C.dataFetcher.dataConfig.tilesetUid=c),C.tilesetUid=C.dataFetcher.dataConfig.tilesetUid,C.server=C.dataFetcher.dataConfig.server||"unknown",C.tilesetInfo&&C.tilesetInfo.chromsizes&&(C.chromInfo=$N(C.tilesetInfo.chromsizes)),"error"in C.tilesetInfo){console.warn("Error retrieving tilesetInfo:",o,C.tilesetInfo.error),C.tilesetInfo=null,C.setError(C.tilesetInfo.error);return}C.tilesetInfo.resolutions?C.maxZoom=C.tilesetInfo.resolutions.length:C.maxZoom=+C.tilesetInfo.max_zoom,C.options&&C.options.maxZoom&&(C.options.maxZoom>=0?C.maxZoom=Math.min(C.options.maxZoom,C.maxZoom):console.error("Invalid maxZoom on track:",AP(C))),C.refreshTiles(),A&&A(l),C.options||(C.options={}),C.options.name=C.options.name||l.name,C.checkValueScaleLimits(),C.draw(),C.drawLabel(),C.animate()}}),C}return CXt(I,[{key:"setError",value:function(n){this.errorTextText=n,this.draw(),this.animate()}},{key:"setFixedValueScaleMin",value:function(n){Number.isNaN(+n)?this.fixedValueScaleMin=null:this.fixedValueScaleMin=+n}},{key:"setFixedValueScaleMax",value:function(n){Number.isNaN(+n)?this.fixedValueScaleMax=null:this.fixedValueScaleMax=+n}},{key:"checkValueScaleLimits",value:function(){this.valueScaleMin=typeof this.options.valueScaleMin<"u"?+this.options.valueScaleMin:null,this.fixedValueScaleMin!==null&&(this.valueScaleMin=this.fixedValueScaleMin),this.valueScaleMax=typeof this.options.valueScaleMax<"u"?+this.options.valueScaleMax:null,this.fixedValueScaleMax!==null&&(this.valueScaleMax=this.fixedValueScaleMax)}},{key:"on",value:function(n,C){this.listeners[n]||(this.listeners[n]=[]),this.listeners[n].push(C)}},{key:"off",value:function(n,C){const r=this.listeners[n].indexOf(C);r===-1||r>=this.listeners[n].length||this.listeners[n].splice(r,1)}},{key:"rerender",value:function(n){bd(Gs(I.prototype),"rerender",this).call(this,n),this.renderVersion+=1,this.tilesetInfo&&(this.checkValueScaleLimits(),this.tilesetInfo.resolutions?this.maxZoom=this.tilesetInfo.resolutions.length:this.maxZoom=+this.tilesetInfo.max_zoom,this.options&&this.options.maxZoom&&(this.options.maxZoom>=0?this.maxZoom=Math.min(this.options.maxZoom,this.maxZoom):console.error("Invalid maxZoom on track:",this)))}},{key:"visibleAndFetchedIds",value:function(){return Object.keys(this.fetchedTiles).filter(n=>this.visibleTileIds.has(n))}},{key:"visibleAndFetchedTiles",value:function(){return this.visibleAndFetchedIds().map(n=>this.fetchedTiles[n])}},{key:"setVisibleTiles",value:function(n){this.visibleTiles=n.map(C=>({tileId:this.tileToLocalId(C),remoteId:this.tileToRemoteId(C),mirrored:C.mirrored})),this.visibleTileIds=new Set(this.visibleTiles.map(C=>C.tileId))}},{key:"removeOldTiles",value:function(){this.calculateVisibleTiles();const C=[...new Set(Object.keys(this.fetchedTiles))].filter(r=>!this.visibleTileIds.has(r));this.removeTiles(C)}},{key:"refreshTiles",value:function(){if(!this.tilesetInfo)return;this.calculateVisibleTiles();const n=new Set(Object.keys(this.fetchedTiles)),C=[...this.visibleTiles].filter(r=>!this.fetching.has(r.remoteId)&&!n.has(r.tileId));for(let r=0;r0;)if(r-=1,o=o.map(s=>Math.floor(s/2)),`${C}.${r}.${o.join(".")}`in this.fetchedTiles)return!0;return!1}},{key:"parentTileId",value:function(n){const C=n.tileData.zoomLevel-1,r=n.tileData.tilePos.map(A=>Math.floor(A/2));return`${n.tileData.tilesetUid}.${C}.${r.join(".")}`}},{key:"removeTiles",value:function(n){!n.length||!this.areAllVisibleTilesLoaded()||this.renderingTiles.size||(n.forEach(C=>{const r=C;this.destroyTile(this.fetchedTiles[r]),r in this.tileGraphics&&(this.pMain.removeChild(this.tileGraphics[r]),delete this.tileGraphics[r]),delete this.fetchedTiles[r]}),this.synchronizeTilesAndGraphics(),this.draw())}},{key:"zoomed",value:function(n,C,r=1,o=0,A=0){this.xScale(n),this.yScale(C),this.refreshTilesDebounced(),this.pMobile.position.x=o,this.pMobile.position.y=this.position[1],this.pMobile.scale.x=r,this.pMobile.scale.y=1}},{key:"setPosition",value:function(n){bd(Gs(I.prototype),"setPosition",this).call(this,n)}},{key:"setDimensions",value:function(n){bd(Gs(I.prototype),"setDimensions",this).call(this,n)}},{key:"areAllVisibleTilesLoaded",value:function(){const n=new Set(Object.keys(this.fetchedTiles)),C=[...this.visibleTileIds];for(let r=0;rC.tileData))}},{key:"loadTileData",value:function(n,C){let r=this.lruCache.get(n.tileId);return r||(r=C(n.data,n.type),this.lruCache.put(n.tileId,r)),r}},{key:"fetchNewTiles",value:function(n){if(n.length>0){const C=[...new Set(n.map(r=>r.remoteId))];this.dataFetcher.fetchTilesDebounced(this.receivedTiles.bind(this),C)}}},{key:"receivedTiles",value:function(n){for(let C=0;CNumber.isNaN(+A)).forEach(A=>{this.fetchedTiles[r].tileData[A]=o[A]})}else this.fetchedTiles[r].tileData={...n[this.visibleTiles[C].remoteId]};this.fetchedTiles[r].tileData.error&&console.warn("Error in loaded tile",r,this.fetchedTiles[r].tileData)}}for(const C in n)if(n[C]){const r=n[C].tilePositionId;this.fetching.has(r)&&this.fetching.delete(r)}this.synchronizeTilesAndGraphics(),this.draw(),this.drawLabel(),this.valueScale&&(!this.prevValueScale||JSON.stringify(this.valueScale.domain())!==JSON.stringify(this.prevValueScale.domain()))&&(this.prevValueScale=this.valueScale.copy(),this.onValueScaleChanged&&this.onValueScaleChanged()),this.animate(),this.areAllVisibleTilesLoaded()&&this.pubSub&&this.pubSub.publish("TiledPixiTrack.tilesLoaded",{uuid:this.uuid})}},{key:"draw",value:function(){if(this.delayDrawing)return;this.tilesetInfo?this.trackNotFoundText.visible=!1:(this.dataFetcher.tilesetInfoLoading?this.trackNotFoundText.text="Loading...":this.trackNotFoundText.text=`Tileset info not found. Server: [${this.server}] tilesetUid: [${this.tilesetUid}]`,[this.trackNotFoundText.x,this.trackNotFoundText.y]=this.position,this.flipText&&(this.trackNotFoundText.anchor.x=1,this.trackNotFoundText.scale.x=-1),this.trackNotFoundText.visible=!0),this.pubSub&&this.pubSub.publish("TiledPixiTrack.tilesDrawnStart",{uuid:this.uuid});const n=Object.values(this.fetchedTiles).map(C=>C.tileData&&C.tileData.error&&`${C.tileId}: ${C.tileData.error}`).filter(C=>C);n.length?this.errorTextText=n.join(` -`):this.errorTextText="",bd(Gs(I.prototype),"draw",this).call(this),Object.keys(this.fetchedTiles).forEach(C=>{this.drawTile(this.fetchedTiles[C])}),this.pubSub&&this.pubSub.publish("TiledPixiTrack.tilesDrawnEnd",{uuid:this.uuid})}},{key:"drawTile",value:function(){}},{key:"calculateMedianVisibleValue",value:function(){this.areAllVisibleTilesLoaded()&&this.allTilesLoaded();let n=this.visibleAndFetchedIds();n.length===0&&(n=Object.keys(this.fetchedTiles));const C=[].concat(...n.filter(r=>this.fetchedTiles[r].tileData.dense).map(r=>Array.from(this.fetchedTiles[r].tileData.dense))).filter(r=>r>0);return this.medianVisibleValue=p7(C),this.medianVisibleValue}},{key:"allVisibleValues",value:function(){return[].concat(...this.visibleAndFetchedIds().map(n=>Array.from(this.fetchedTiles[n].tileData.dense)))}},{key:"minVisibleValue",value:function(n=!1){return this.minVisibleValueInTiles(n)}},{key:"minVisibleValueInTiles",value:function(n=!1){let C=this.visibleAndFetchedIds();C.length===0&&(C=Object.keys(this.fetchedTiles));let r=Math.min(...C.map(o=>this.fetchedTiles[o].tileData.minNonZero));return r===Number.MAX_SAFE_INTEGER&&(r=null),n?r:this.valueScaleMin!==null?this.valueScaleMin:r}},{key:"maxVisibleValue",value:function(n=!1){return this.maxVisibleValueInTiles(n)}},{key:"maxVisibleValueInTiles",value:function(n=!1){let C=this.visibleAndFetchedIds();C.length===0&&(C=Object.keys(this.fetchedTiles));let r=Math.max(...C.map(o=>this.fetchedTiles[o].tileData.maxNonZero));return r===Number.MIN_SAFE_INTEGER&&(r=null),n?r:this.valueScaleMax!==null?this.valueScaleMax:r}},{key:"makeValueScale",value:function(n,C,r,o){let A=null,s=0,a=o;(a===null||typeof a>"u")&&(a=6);let l=Math.min(this.dimensions[1]-a,a),c=Math.max(this.dimensions[1]-a,a);if(this.dimensions[1]-ash(u,d,m),[h,0]}else if(this.options.valueScaling==="setquantile"){const u=this.dimensions[1]-a,d=a,h=new Set(this.allVisibleValues()),m=v9().domain([...h]).range(iC(u,d,(d-u)/256));return m.ticks=f=>sh(u,d,f),[m,0]}else A=Cg().domain([n,r]).range([c,l]);return[A,s]}}]),I}(dC);function dXt(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function Fre(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function YI(g){return YI=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},YI(g)}const Ere=200,Ol=10,oG=40,Vn=10,Ll=Vn,Mre=4,Nf=1,_l=4,zre=5,BXt=256,mZ=Ol+oG+Vn+Nf+Ll+_l;let Rw=function(g){bXt(I,g);var e=yXt(I);function I(i,n){var C;dXt(this,I);const r={...i};r.onValueScaleChanged=()=>{i.onValueScaleChanged(),C.drawColorbar()},C=e.call(this,r,n);const{pubSub:o,animate:A,svgElement:s,onTrackOptionsChanged:a,onMouseMoveZoom:l,isShowGlobalMousePosition:c,isValueScaleLocked:u}=i;return C.pubSub=o,C.is2d=!0,C.animate=A,C.uid=dg.nice(),C.scaleBrush=nw(),C.onTrackOptionsChanged=a,C.isShowGlobalMousePosition=c,C.isValueScaleLocked=u,C.pColorbarArea=new Ct.PIXI.Graphics,C.pMasked.addChild(C.pColorbarArea),C.pColorbar=new Ct.PIXI.Graphics,C.pColorbarArea.addChild(C.pColorbar),C.axis=new zk(ZW(C)),C.pColorbarArea.addChild(C.axis.pAxis),C.colorScale=Pb,n&&n.colorRange&&(C.colorScale=Cu(n.colorRange)),C.gBase=pg(s).append("g"),C.gMain=C.gBase.append("g"),C.gColorscaleBrush=C.gMain.append("g"),C.brushing=!1,C.prevOptions="",C.prevIndUpperLeftTile="",C.onMouseMoveZoom=l,C.setDataLensSize(11),C.dataLens=new Float32Array(C.dataLensSize**2),C.mouseMoveHandlerBound=C.mouseMoveHandler.bind(ZW(C)),C.onMouseMoveZoom&&C.pubSubs.push(C.pubSub.subscribe("app.mouseMove",C.mouseMoveHandlerBound)),C.options&&C.options.showMousePosition&&!C.hideMousePosition&&(C.hideMousePosition=hh(ZW(C),C.is2d,C.isShowGlobalMousePosition())),C.prevOptions=JSON.stringify(n),C}return hXt(I,[{key:"mouseMoveHandler",value:function(n){this.isWithin(n.x,n.y)&&(this.mouseX=n.x,this.mouseY=n.y,this.mouseMoveZoomHandler())}},{key:"mouseMoveZoomHandler",value:function(n=this.mouseX,C=this.mouseY){if(typeof n>"u"||typeof C>"u"||!this.areAllVisibleTilesLoaded()||!this.tilesetInfo)return;const r=n-this.position[0],o=C-this.position[1];let A,s;try{s=this.getVisibleRectangleData(r-this.dataLensPadding,o-this.dataLensPadding,this.dataLensSize,this.dataLensSize),A=s.get(this.dataLensPadding,this.dataLensPadding)}catch{return}const a=this.dataLensSize;let l;try{l=XQ(this.limitedValueScale,this.colorScale,this.valueScale.domain()[0])}catch{return}if(!l)return;const c=Math.round(this._xScale.invert(r)),u=Math.round(this._yScale.invert(o));let d=[c,u],h=[Math.round(this._xScale.invert(r-this.dataLensPadding)),Math.round(this._xScale.invert(r+this.dataLensPadding))],m=[Math.round(this._yScale.invert(o-this.dataLensPadding)),Math.round(this._yScale.invert(o+this.dataLensPadding))];this.chromInfo&&(d=d.map(f=>Vi(f,this.chromInfo).slice(0,2)),h=h.map(f=>Vi(f,this.chromInfo).slice(0,2)),m=m.map(f=>Vi(f,this.chromInfo).slice(0,2))),this.onMouseMoveZoom({trackId:this.id,data:A,absX:n,absY:C,relX:r,relY:o,dataX:c,dataY:u,orientation:"2d",dataLens:s,dim:a,toRgb:l,center:d,xRange:h,yRange:m,isGenomicCoords:!!this.chromInfo})}},{key:"scheduleRerender",value:function(){this.backgroundTaskScheduler.enqueueTask(this.handleRerender.bind(this),null,this.uuid)}},{key:"handleRerender",value:function(){this.rerender(this.options,!0)}},{key:"getAbsTileDim",value:function(n,C,r){const{tileX:o,tileY:A,tileWidth:s,tileHeight:a}=this.getTilePosAndDimensions(n,C),l={};return l.width=this._refXScale(o+s)-this._refXScale(o),l.height=this._refYScale(A+a)-this._refYScale(A),r?(l.x=this._refXScale(A),l.y=this._refYScale(o)):(l.x=this._refXScale(o),l.y=this._refYScale(A)),l}},{key:"updateValueScale",value:function(){let n=this.minValue(),C=this.maxValue();const r=1e-6;n!=null&&C!==void 0&&C!==null&&Math.abs(n-C)this.renderTile(o)),this.hideMousePosition&&(this.hideMousePosition(),this.hideMousePosition=void 0),this.options&&this.options.showMousePosition&&!this.hideMousePosition&&(this.hideMousePosition=hh(this,this.is2d,this.isShowGlobalMousePosition())))}},{key:"drawLabel",value:function(){this.options.labelPosition===this.options.colorbarPosition?this.labelXOffset=mZ:this.labelXOffset=0,Ii(YI(I.prototype),"drawLabel",this).call(this)}},{key:"tileDataToCanvas",value:function(n){const C=document.createElement("canvas");C.width=this.binsPerTile(),C.height=this.binsPerTile();const r=C.getContext("2d");r.fillStyle="transparent",r.fillRect(0,0,C.width,C.height);const o=new ImageData(n,C.width,C.height);return r.putImageData(o,0,0),C}},{key:"exportData",value:function(){if(this.tilesetInfo){const n=this.getVisibleRectangleData(0,0,this.dimensions[0],this.dimensions[1]),C={bounds:[this._xScale.domain(),this._yScale.domain()],dimensions:n.shape,data:IBe(n)};tB("data.json",JSON.stringify(C))}}},{key:"setSpriteProperties",value:function(n,C,r,o){const A=this.getAbsTileDim(C,r,o);n.width=A.width,n.height=A.height,n.x=A.x,n.y=A.y,o&&r[0]!==r[1]&&(n.rotation=-Math.PI/2,n.scale.x=Math.abs(n.scale.x)*-1)}},{key:"refXScale",value:function(n){Ii(YI(I.prototype),"refXScale",this).call(this,n),this.draw()}},{key:"refYScale",value:function(n){Ii(YI(I.prototype),"refYScale",this).call(this,n),this.draw()}},{key:"draw",value:function(){Ii(YI(I.prototype),"draw",this).call(this)}},{key:"newBrushOptions",value:function(n){const C=JSON.parse(JSON.stringify(this.options)),r=this.valueScale.copy().range([this.colorbarHeight,0]),o=r.invert(n[0]),s=(r.invert(n[1])-r.domain()[0])/(r.domain()[1]-r.domain()[0]),a=(o-r.domain()[0])/(r.domain()[1]-r.domain()[0]);return C.scaleStartPercent=s.toFixed(zre),C.scaleEndPercent=a.toFixed(zre),C}},{key:"brushStart",value:function(){this.brushing=!0}},{key:"brushMoved",value:function(n){if(!n.selection)return;const C=this.newBrushOptions(n.selection),r=JSON.stringify(C);this.gColorscaleBrush.selectAll(".handle--custom").attr("y",o=>o.type==="n"?n.selection[0]:n.selection[1]-Mre/2),r!==this.prevOptions&&(this.prevOptions=r,this.rerender(C,!0),this.onTrackOptionsChanged(C),this.isValueScaleLocked()&&this.onValueScaleChanged())}},{key:"brushEnd",value:function(){this.brushing=!1}},{key:"setPosition",value:function(n){Ii(YI(I.prototype),"setPosition",this).call(this,n),this.drawColorbar()}},{key:"setDimensions",value:function(n){Ii(YI(I.prototype),"setDimensions",this).call(this,n),this.drawColorbar()}},{key:"removeColorbar",value:function(){this.pColorbarArea.visible=!1,this.scaleBrush.on(".brush")&&this.gColorscaleBrush.call(this.scaleBrush.move,null),this.gColorscaleBrush.on(".brush",null),this.gColorscaleBrush.selectAll("rect").remove()}},{key:"drawColorbar",value:function(){if(this.pColorbar.clear(),!this.options||!this.options.colorbarPosition||this.options.colorbarPosition==="hidden"){this.removeColorbar();return}if(this.pColorbarArea.visible=!0,!this.valueScale||Number.isNaN(+this.valueScale.domain()[0])||Number.isNaN(+this.valueScale.domain()[1]))return;const n=Math.min(this.dimensions[1]/2,Ere);if(this.colorbarHeight=n-2*Vn,this.colorbarHeight<0){this.removeColorbar();return}if(this.valueScale.domain()[1]===this.valueScale.domain()[0]){this.removeColorbar();return}const C=this.valueScale.copy().range([this.colorbarHeight,0]);this.options.colorbarPosition==="topLeft"||this.options.colorbarPosition==="bottomLeft"?this.scaleBrush.extent([[_l,0],[Ll,this.colorbarHeight]]):this.scaleBrush.extent([[0,0],[Ll-_l,this.colorbarHeight]]),this.options.colorbarPosition==="topLeft"&&([this.pColorbarArea.x,this.pColorbarArea.y]=this.position,this.pColorbar.y=Vn,this.axis.pAxis.y=Vn,this.axis.pAxis.x=_l+Ll+Nf+Ol,this.pColorbar.x=_l+Ll+Nf,this.gColorscaleBrush.attr("transform",`translate(${this.pColorbarArea.x+_l},${this.pColorbarArea.y+this.pColorbar.y-1})`)),this.options.colorbarPosition==="topRight"&&(this.pColorbarArea.x=this.position[0]+this.dimensions[0]-mZ,this.pColorbarArea.y=this.position[1],this.pColorbar.y=Vn,this.axis.pAxis.y=Vn,this.axis.pAxis.x=oG+Vn,this.pColorbar.x=oG+Vn,this.gColorscaleBrush.attr("transform",`translate(${this.pColorbarArea.x+this.pColorbar.x+Ol+2},${this.pColorbarArea.y+this.pColorbar.y-1})`)),this.options.colorbarPosition==="bottomRight"&&(this.pColorbarArea.x=this.position[0]+this.dimensions[0]-mZ,this.pColorbarArea.y=this.position[1]+this.dimensions[1]-n,this.pColorbar.y=Vn,this.axis.pAxis.y=Vn,this.axis.pAxis.x=oG+Vn,this.pColorbar.x=oG+Vn,this.gColorscaleBrush.attr("transform",`translate(${this.pColorbarArea.x+this.pColorbar.x+Ol+Nf},${this.pColorbarArea.y+this.pColorbar.y-1})`)),this.options.colorbarPosition==="bottomLeft"&&(this.pColorbarArea.x=this.position[0],this.pColorbarArea.y=this.position[1]+this.dimensions[1]-n,this.pColorbar.y=Vn,this.axis.pAxis.y=Vn,this.axis.pAxis.x=_l+Ll+Nf+Ol,this.pColorbar.x=_l+Ll+Nf,this.gColorscaleBrush.attr("transform",`translate(${this.pColorbarArea.x+2},${this.pColorbarArea.y+this.pColorbar.y-1})`)),this.pColorbarArea.clear(),this.pColorbarArea.beginFill(zt(this.options.colorbarBackgroundColor||"white"),+this.options.colorbarBackgroundOpacity>=0?+this.options.colorbarBackgroundOpacity:.6),this.pColorbarArea.drawRect(0,0,mZ,n),this.options?(this.options.scaleStartPercent||(this.options.scaleStartPercent=0),this.options.scaleEndPercent||(this.options.scaleEndPercent=1)):this.options={scaleStartPercent:0,scaleEndPercent:1};const r=C.domain()[1]-C.domain()[0],o=C(this.options.scaleStartPercent*r+C.domain()[0]),A=C(this.options.scaleEndPercent*r+C.domain()[0]);this.brushing||(this.scaleBrush.on("start",this.brushStart.bind(this)).on("brush",this.brushMoved.bind(this)).on("end",this.brushEnd.bind(this)).handleSize(0),this.gColorscaleBrush.on(".brush",null),this.gColorscaleBrush.call(this.scaleBrush),this.northHandle=this.gColorscaleBrush.selectAll(".handle--custom").data([{type:"n"},{type:"s"}]).enter().append("rect").classed("handle--custom",!0).attr("cursor","ns-resize").attr("width",Ll).attr("height",Mre).style("fill","#666").style("stroke","white"),this.flipText&&this.northHandle.attr("cursor","ew-resize"),this.gColorscaleBrush.call(this.scaleBrush.move,[A,o]));const s=Cg().domain([0,255]).range([0,this.colorbarHeight]);for(let a=0;a{const Z=y.mirrored?[y.tileData.tilePos[1],y.tileData.tilePos[0]]:y.tileData.tilePos,{tileX:v,tileY:G,tileWidth:B,tileHeight:w}=this.getTilePosAndDimensions(y.tileData.zoomLevel,Z,this.binsPerTile()),R=Math.floor(v/a),S=Math.floor((v+B)/a),X=Math.floor(G/a),W=Math.floor((G+w)/a);let V=Math.max(h,R)-R,H=Math.max(m,X)-X;const D=Math.min(h+f,S)-R,Y=Math.min(m+b,W)-X,F=Math.max(R-h,0),_=Math.max(X-m,0),J=D-V,te=Y-H;if(!(J<0||te<0)){if(y.mirrored&&V>H){const q=V;V=H,H=q}eBe(p.hi(_+te,F+J).lo(_,F),y.dataArray.hi(H+te,V+J).lo(H,V))}}),p}},{key:"initTile",value:function(n){Ii(YI(I.prototype),"initTile",this).call(this,n),n.tileData.dense.length===this.binsPerTile()**2&&(n.dataArray=Lp(Array.from(n.tileData.dense),[this.binsPerTile(),this.binsPerTile()]),this.continuousScaling&&n.tileData.tilePos[0]===n.tileData.tilePos[1]&&n.mirrored&&(n.tileData.denseDataExtrema.mirrorPrecomputedExtrema(),Ii(YI(I.prototype),"initTile",this).call(this,n))),!(this.scale.minValue===null||this.scale.maxValue===null)&&this.renderTile(n)}},{key:"updateTile",value:function(n){n.scale&&this.scale&&this.scale.minValue===n.scale.minValue&&this.scale.maxValue===n.scale.maxValue||(this.renderTile(n),this.drawColorbar())}},{key:"destroyTile",value:function(n){n.sprite.destroy(!0),n.canvas=null,n.sprite=null,n.texture=null}},{key:"pixDataFunction",value:function(n,C){if(C){const{graphics:r}=n,o=this.tileDataToCanvas(C.pixData);n.sprite&&n.sprite.destroy(!0);const A=Ct.PIXI.VERSION[0]==="4"?Ct.PIXI.Texture.fromCanvas(o,Ct.PIXI.SCALE_MODES.NEAREST):Ct.PIXI.Texture.from(o,{scaleMode:Ct.PIXI.SCALE_MODES.NEAREST}),s=new Ct.PIXI.Sprite(A);n.sprite=s,n.texture=A,n.canvas=o,this.setSpriteProperties(n.sprite,n.tileData.zoomLevel,n.tileData.tilePos,n.mirrored),r.removeChildren(),r.addChild(n.sprite)}this.renderingTiles.delete(n.tileId)}},{key:"renderTile",value:function(n){const[C]=this.updateValueScale(),r=0;if(this.renderingTiles.add(n.tileId),this.tilesetInfo.tile_size&&n.tileData.dense.lengththis.pixDataFunction(n,o),this.mirrorTiles()&&!n.mirrored&&n.tileData.tilePos[0]===n.tileData.tilePos[1],this.options.extent==="upper-right"&&n.tileData.tilePos[0]===n.tileData.tilePos[1],this.options.zeroValueColor?YGe(this.options.zeroValueColor):void 0,{selectedRows:this.options.selectRows,selectedRowsAggregationMode:this.options.selectRowsAggregationMode,selectedRowsAggregationWithRelativeHeight:this.options.selectRowsAggregationWithRelativeHeight,selectedRowsAggregationMethod:this.options.selectRowsAggregationMethod})}},{key:"remove",value:function(){this.gMain.remove(),this.gMain=null,Ii(YI(I.prototype),"remove",this).call(this)}},{key:"refScalesChanged",value:function(n,C){Ii(YI(I.prototype),"refScalesChanged",this).call(this,n,C),jN(this.fetchedTiles).filter(r=>r.sprite).forEach(r=>this.setSpriteProperties(r.sprite,r.tileData.zoomLevel,r.tileData.tilePos,r.mirrored))}},{key:"superSVG",value:function(){return Ii(YI(I.prototype),"exportSVG",this).call(this)}},{key:"exportSVG",value:function(){let n=null,C=null;Ii(YI(I.prototype),"exportSVG",this)?[C,n]=Ii(YI(I.prototype),"exportSVG",this).call(this):(C=document.createElement("g"),n=C);const r=document.createElement("g");n.appendChild(r),r.setAttribute("transform",`translate(${this.pMain.position.x},${this.pMain.position.y}) scale(${this.pMain.scale.x},${this.pMain.scale.y})`);for(const A of this.visibleAndFetchedTiles()){const s=A.sprite.rotation*180/Math.PI,a=document.createElement("g");a.setAttribute("transform",`translate(${A.sprite.x},${A.sprite.y}) rotate(${s}) scale(${A.sprite.scale.x},${A.sprite.scale.y})`);const l=document.createElement("image");l.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",A.canvas.toDataURL()),l.setAttribute("width",A.canvas.width),l.setAttribute("height",A.canvas.height),l.setAttribute("style","image-rendering: pixelated"),a.appendChild(l),r.appendChild(a)}const o=this.exportColorBarSVG();return n.appendChild(o),[C,C]}},{key:"getVisiblePartOfUppLeftTile",value:function(){const n=this.visibleAndFetchedTiles().map(d=>{const h=d.mirrored?[d.tileData.tilePos[1],d.tileData.tilePos[0]]:d.tileData.tilePos;return[h[0],h[1],d.tileId]});if(n.length===0)return null;let C=n[0];for(let d=0;dd.tileId===C[2])[0],s=this.getIndicesOfVisibleDataInTile(A),a=s[0],l=s[1],c=a-a%o,u=l-l%o;return[A.tileId,c,u]}},{key:"getIndicesOfVisibleDataInTile",value:function(n){const C=this._xScale.range(),r=this._yScale.range(),o=n.mirrored?[n.tileData.tilePos[1],n.tileData.tilePos[0]]:n.tileData.tilePos,{tileX:A,tileY:s,tileWidth:a,tileHeight:l}=this.getTilePosAndDimensions(n.tileData.zoomLevel,o,this.binsPerTile()),c=Cg().domain([0,this.binsPerTile()]).range([A,A+a]),u=Math.max(0,Math.round(c.invert(this._xScale.invert(C[0])))-1),d=Math.min(this.binsPerTile(),Math.round(c.invert(this._xScale.invert(C[1])))),h=Cg().domain([0,this.binsPerTile()]).range([s,s+l]),m=Math.max(0,Math.round(h.invert(this._yScale.invert(r[0])))-1),f=Math.min(this.binsPerTile(),Math.round(h.invert(this._yScale.invert(r[1]))));return n.mirrored&&o[0]!==o[1]?[m,u,f,d]:[u,m,d,f]}},{key:"minVisibleValue",value:function(n=!1){const C=this.visibleAndFetchedTiles().map(o=>{if(o.tileData.denseDataExtrema===void 0)return null;const A=this.getIndicesOfVisibleDataInTile(o);return o.tileData.denseDataExtrema.getMinNonZeroInSubset(A)});if(C.length===0&&this.valueScaleMax===null)return null;const r=Math.min.apply(null,C);return r===Number.MAX_SAFE_INTEGER?Ii(YI(I.prototype),"minVisibleValue",this).call(this,n):n?r:this.valueScaleMin!==null?this.valueScaleMin:r}},{key:"maxVisibleValue",value:function(n=!1){const C=this.visibleAndFetchedTiles().map(o=>{if(o.tileData.denseDataExtrema===void 0)return null;const A=this.getIndicesOfVisibleDataInTile(o);return o.tileData.denseDataExtrema.getMaxNonZeroInSubset(A)});if(C.length===0&&this.valueScaleMax===null)return null;const r=Math.max.apply(null,C);return r===Number.MIN_SAFE_INTEGER?Ii(YI(I.prototype),"maxVisibleValue",this).call(this,n):n?r:this.valueScaleMax!==null?this.valueScaleMax:r}},{key:"zoomed",value:function(n,C,r,o,A){if(this.brushing)return;Ii(YI(I.prototype),"zoomed",this).call(this,n,C),this.pMain.position.x=o,this.pMain.position.y=A,this.pMain.scale.x=r,this.pMain.scale.y=r;const s=this.isValueScaleLocked();if(this.continuousScaling&&this.minValue()!==void 0&&this.maxValue()!==void 0){const a=JSON.stringify(this.getVisiblePartOfUppLeftTile());if(this.valueScaleMin===null&&this.valueScaleMax===null&&!s&&a!==this.prevIndUpperLeftTile){const l=this.minVisibleValue(),c=this.maxVisibleValue(),u=1e-6;l!==null&&c!==null&&(Math.abs(this.minValue()-l)>u||Math.abs(this.maxValue()-c)>u)&&(this.minValue(l),this.maxValue(c),this.scheduleRerender()),this.prevIndUpperLeftTile=a}s&&this.onValueScaleChanged()}this.mouseMoveZoomHandler()}},{key:"addTileId",value:function(n,C,r,o,A,s=!1){const a=[C,r,o];a.mirrored=s,a.dataTransform=A,n.push(a)}},{key:"tilesToId",value:function(n,C,r){const o=n,A=C,s=this.options&&this.options.dataTransform||"default",a=[];for(let l=0;l=A[c]?this.options.extent!=="lower-left"&&this.addTileId(a,r,A[c],o[l],s,!0):this.options.extent!=="upper-right"&&this.addTileId(a,r,o[l],A[c],s),o[l]===A[c]&&this.options.extent==="lower-left"&&this.addTileId(a,r,o[l],A[c],s)):this.addTileId(a,r,o[l],A[c],s);return a}},{key:"calculateVisibleTiles",value:function(){if(this.tilesetInfo){if(this.zoomLevel=this.calculateZoomLevel(),this.tilesetInfo.resolutions){const n=this.tilesetInfo.resolutions.map(C=>+C).sort((C,r)=>r-C);this.xTiles=vt.calculateTilesFromResolution(n[this.zoomLevel],this._xScale,this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0]),this.yTiles=vt.calculateTilesFromResolution(n[this.zoomLevel],this._yScale,this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0])}else this.xTiles=vt.calculateTiles(this.zoomLevel,this._xScale,this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0],this.tilesetInfo.max_zoom,this.tilesetInfo.max_width),this.yTiles=vt.calculateTiles(this.zoomLevel,this._yScale,this.options.reverseYAxis?-this.tilesetInfo.max_pos[1]:this.tilesetInfo.min_pos[1],this.options.reverseYAxis?-this.tilesetInfo.min_pos[1]:this.tilesetInfo.max_pos[1],this.tilesetInfo.max_zoom,this.tilesetInfo.max_width1||this.tilesetInfo.max_width);this.setVisibleTiles(this.tilesToId(this.xTiles,this.yTiles,this.zoomLevel))}}},{key:"mirrorTiles",value:function(){return!(this.tilesetInfo.mirror_tiles&&(this.tilesetInfo.mirror_tiles===!1||this.tilesetInfo.mirror_tiles==="false"))}},{key:"getMouseOverHtml",value:function(n,C){if(!this.options||!this.options.showTooltip||!this.tilesetInfo)return"";const r=vt.calculateResolution(this.tilesetInfo,this.zoomLevel),o=Math.max(this.tilesetInfo.max_pos[1]-this.tilesetInfo.min_pos[1],this.tilesetInfo.max_pos[0]-this.tilesetInfo.min_pos[0]),A=Math.ceil(Math.log(o/r)/Math.log(10));this.setDataLensSize(1);const s=this._xScale.invert(n),a=this._yScale.invert(C);let l="Position: ";if(this.chromInfo){const u=Vi(s,this.chromInfo),d=Vi(a,this.chromInfo),h=m=>hr(`.${A}s`)(m);l+=`${u[0]}:${h(u[1])} & ${d[0]}:${h(d[1])}`,l+="
"}let c=null;try{c=this.getVisibleRectangleData(n,C,1,1).get(0,0)}catch{return""}return this.options&&this.options.heatmapValueScaling==="log"?c>0?`${l}Value: 1e${hr(".3f")(Math.log(c)/Math.log(10))}`:c===0?`${l}Value: 0`:`${l}Value: N/A`:`${l}Value: ${hr(".3f")(c)}`}},{key:"getTilePosAndDimensions",value:function(n,C,r){const o=r||this.binsPerTile();if(this.tilesetInfo.resolutions){const f=this.tilesetInfo.resolutions.map(v=>+v).sort((v,G)=>G-v)[n],b=f*o,p=b,y=f*o*C[0],Z=f*o*C[1];return{tileX:y,tileY:Z,tileWidth:b,tileHeight:p}}const A=C[0],s=C[1],a=this.tilesetInfo.min_pos[0],l=this.options.reverseYAxis?-this.tilesetInfo.max_pos[1]:this.tilesetInfo.min_pos[1],c=this.tilesetInfo.max_width/2**n,u=this.tilesetInfo.max_width/2**n,d=a+A*c,h=l+s*u;return{tileX:d,tileY:h,tileWidth:c,tileHeight:u}}},{key:"calculateZoomLevel",value:function(){const n=this.tilesetInfo.min_pos[0],C=this.tilesetInfo.max_pos[0],r=this.tilesetInfo.min_pos[1],o=this.tilesetInfo.max_pos[1];let A=null;if(this.tilesetInfo.resolutions){const s=vt.calculateZoomLevelFromResolutions(this.tilesetInfo.resolutions,this._xScale,n,C),a=vt.calculateZoomLevelFromResolutions(this.tilesetInfo.resolutions,this._yScale,r,o);A=Math.min(s,a)}else{const s=vt.calculateZoomLevel(this._xScale,this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0],this.binsPerTile()),a=vt.calculateZoomLevel(this._xScale,this.tilesetInfo.min_pos[1],this.tilesetInfo.max_pos[1],this.binsPerTile());A=Math.max(s,a),A=Math.min(A,this.maxZoom)}return this.options&&this.options.maxZoom&&(this.options.maxZoom>=0?A=Math.min(this.options.maxZoom,A):console.error("Invalid maxZoom on track:",this)),A}},{key:"tileToLocalId",value:function(n){return n.dataTransform&&n.dataTransform!=="default"?`${n.join(".")}.${n.mirrored}.${n.dataTransform}`:`${n.join(".")}.${n.mirrored}`}},{key:"tileToRemoteId",value:function(n){return n.dataTransform&&n.dataTransform!=="default"?`${n.join(".")}.${n.dataTransform}`:`${n.join(".")}`}},{key:"localToRemoteId",value:function(n){const C=n.split(".");return C.slice(0,C.length-1).join(".")}}]),I}(Bm);function vXt(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function Pre(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function bH(g){return bH=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},bH(g)}function ERe(g){if(!g.graphics)return;const e=g.graphics,{tileX:I,tileY:i,tileWidth:n}=this.getTilePosAndDimensions(g.tileData.zoomLevel,g.tileData.tilePos);g.drawnAtScale=this._xScale.copy();const C=1/((this._xScale(1)-this._xScale(0))/(this._refXScale(1)-this._refXScale(0))),r=1/((this._yScale(1)-this._yScale(0))/(this._refYScale(1)-this._refYScale(0)));g.text.scale.x=C,g.text.scale.y=r;const o=this._xScale(n)-this._xScale(0);if(g.textGraphics.scale.x=o/256,g.textGraphics.scale.y=o/256,e.clear(),e.lineStyle(4*C,255,1),e.beginFill(16740363,.4),e.alpha=.5,g.mirrored){const A=this._refXScale(i+n)-this._refXScale(i),s=this._refYScale(I+n)-this._refYScale(I);g.textGraphics.position.x=this._refXScale(i)+A/2,g.textGraphics.position.y=this._refYScale(I)+s/2,e.drawRect(this._refXScale(i),this._refYScale(I),A,s)}else{const A=this._refXScale(I+n)-this._refXScale(I),s=this._refYScale(i+n)-this._refYScale(i);g.textGraphics.position.x=this._refXScale(I)+A/2,g.textGraphics.position.y=this._refYScale(i)+s/2,e.drawRect(this._refXScale(I),this._refYScale(i),A,s)}}function MRe(g){const e=g.graphics;g.textGraphics=new Ct.PIXI.Graphics,g.mirrored?g.text=new Ct.PIXI.Text(`${g.tileData.zoomLevel}/${[g.tileData.tilePos[1],g.tileData.tilePos[0]].join("/")}`,{fontFamily:"Arial",fontSize:24,fill:16715792,align:"center"}):g.text=new Ct.PIXI.Text(`${g.tileData.zoomLevel}/${g.tileData.tilePos.join("/")}`,{fontFamily:"Arial",fontSize:24,fill:16715792,align:"center"}),g.textGraphics.addChild(g.text),g.text.anchor.x=.5,g.text.anchor.y=.5,e.addChild(g.textGraphics)}let zRe=function(g){RXt(I,g);var e=WXt(I);function I(){return vXt(this,I),e.apply(this,arguments)}return SXt(I,[{key:"areAllVisibleTilesLoaded",value:function(){return!0}},{key:"initTile",value:function(n){MRe.bind(this)(n),this.drawTile(n)}},{key:"destroyTile",value:function(n,C){}},{key:"drawTile",value:function(n){ERe.bind(this)(n)}},{key:"fetchNewTiles",value:function(n){n.forEach(C=>{const o=C.remoteId.split("."),A={zoomLevel:o[0],tilePos:o.slice(1,o.length).map(s=>+s)};this.fetchedTiles[C.tileId]=C,this.fetchedTiles[C.tileId].tileData=A,this.fetching.has(C.remoteId)&&this.fetching.delete(C.remoteId)}),this.synchronizeTilesAndGraphics()}}]),I}(Rw);function NXt(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function Jre(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function Vh(g){return Vh=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},Vh(g)}const zXt=1024;let _j=function(g){DXt(I,g);var e=FXt(I);function I(i,n){var C;NXt(this,I),C=e.call(this,i,n);const{onMouseMoveZoom:r,isValueScaleLocked:o,getLockGroupExtrema:A}=i;return C.onMouseMoveZoom=r,C.isValueScaleLocked=o,C.getLockGroupExtrema=A,C.onMouseMoveZoom&&C.pubSubs.push(C.pubSub.subscribe("app.mouseMove",C.mouseMoveHandler.bind(PRe(C)))),C}return kXt(I,[{key:"initTile",value:function(n){SB(Vh(I.prototype),"initTile",this).call(this,n)}},{key:"tileToLocalId",value:function(n){return`${n.join(".")}`}},{key:"tileToRemoteId",value:function(n){return`${n.join(".")}`}},{key:"relevantScale",value:function(){return null}},{key:"setVisibleTiles",value:function(n){this.visibleTiles=n.map(C=>({tileId:this.tileToLocalId(C),remoteId:this.tileToRemoteId(C)})),this.visibleTileIds=new Set(this.visibleTiles.map(C=>C.tileId))}},{key:"calculateVisibleTiles",value:function(){if(!this.tilesetInfo)return;if(this.zoomLevel=this.calculateZoomLevel(),this.tilesetInfo.resolutions){const r=this.tilesetInfo.resolutions.map(s=>+s).sort((s,a)=>a-s),A=vt.calculateTilesFromResolution(r[this.zoomLevel],this._xScale,this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0]).map(s=>[this.zoomLevel,s]);this.setVisibleTiles(A);return}const C=vt.calculateTiles(this.zoomLevel,this.relevantScale(),this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0],this.tilesetInfo.max_zoom,this.tilesetInfo.max_width).map(r=>[this.zoomLevel,r]);this.setVisibleTiles(C)}},{key:"getTilePosAndDimensions",value:function(n,C,r){const o=C[0],A=C[0];if(this.tilesetInfo.resolutions){const f=r||zXt,p=this.tilesetInfo.resolutions.map(B=>+B).sort((B,w)=>w-B)[n],y=p*f,Z=y,v=p*f*C[0],G=p*f*C[1];return{tileX:v,tileY:G,tileWidth:y,tileHeight:Z}}const s=this.tilesetInfo.max_width,a=this.tilesetInfo.max_width,l=this.tilesetInfo.min_pos[0],c=this.tilesetInfo.min_pos[1],u=s/2**n,d=a/2**n,h=l+o*u,m=c+A*d;return{tileX:h,tileY:m,tileWidth:u,tileHeight:d}}},{key:"updateTile",value:function(n){}},{key:"scheduleRerender",value:function(){this.backgroundTaskScheduler.enqueueTask(this.handleRerender.bind(this),null,this.uuid)}},{key:"handleRerender",value:function(){this.rerender(this.options,!1)}},{key:"getIndicesOfVisibleDataInTile",value:function(n){const C=this._xScale.range();if(!this.tilesetInfo)return[null,null];const{tileX:r,tileWidth:o}=this.getTilePosAndDimensions(n.tileData.zoomLevel,n.tileData.tilePos,this.tilesetInfo.bins_per_dimension||this.tilesetInfo.tile_size),A=Cg().domain([0,this.tilesetInfo.tile_size||this.tilesetInfo.bins_per_dimension]).range([r,r+o]),s=Math.max(0,Math.round(A.invert(this._xScale.invert(C[0])))),a=Math.min(n.tileData.dense.length,Math.round(A.invert(this._xScale.invert(C[1]))));return[s,a]}},{key:"minVisibleValue",value:function(n=!1){let C=this.visibleAndFetchedIds();C.length===0&&(C=Object.keys(this.fetchedTiles));const r=C.map(A=>this.fetchedTiles[A]).map(A=>{const s=this.getIndicesOfVisibleDataInTile(A);return A.tileData.denseDataExtrema.getMinNonZeroInSubset(s)}),o=Math.min(...r);return n?o:this.valueScaleMin!==null?this.valueScaleMin:o}},{key:"maxVisibleValue",value:function(n=!1){let C=this.visibleAndFetchedIds();C.length===0&&(C=Object.keys(this.fetchedTiles));const r=C.map(A=>this.fetchedTiles[A]).map(A=>{const s=this.getIndicesOfVisibleDataInTile(A);return A.tileData.denseDataExtrema.getMaxNonZeroInSubset(s)}),o=Math.max(...r);return n?o:this.valueScaleMax!==null?this.valueScaleMax:o}},{key:"getAggregatedVisibleValue",value:function(n="max"){const C=n==="min"?Math.min:Math.max,r=n==="min"?1/0:-1/0;let o=this.visibleAndFetchedIds();o.length===0&&(o=Object.keys(this.fetchedTiles));const A=this._xScale.range();return o.map(s=>this.fetchedTiles[s]).map(s=>{if(!s.tileData.tilePos)return n==="min"?this.minVisibleValue():this.maxVisibleValue();const{tileX:a,tileWidth:l}=this.getTilePosAndDimensions(s.tileData.zoomLevel,s.tileData.tilePos,this.tilesetInfo.bins_per_dimension||this.tilesetInfo.tile_size),c=Cg().domain([0,this.tilesetInfo.tile_size||this.tilesetInfo.bins_per_dimension]).range([a,a+l]),u=Math.max(0,Math.round(c.invert(this._xScale.invert(A[0])))),d=Math.min(s.tileData.dense.length,Math.round(c.invert(this._xScale.invert(A[1]))));return s.tileData.dense.slice(u,d)}).reduce((s,a)=>C(s,...a),r)}},{key:"getDataAtPos",value:function(n){let C;if(!this.tilesetInfo)return C;const r=this.calculateZoomLevel(),o=vt.calculateTileWidth(this.tilesetInfo,r,this.tilesetInfo.tile_size),A=this._xScale.invert(n)/o,s=this.tileToLocalId([r,Math.floor(A)]),a=this.fetchedTiles[s];if(!a)return C;const l=this.tilesetInfo.tile_size*(A-Math.floor(A));return a.tileData.dense?a.tileData.dense[Math.floor(l)]:null}},{key:"mouseMoveHandler",value:function({x:n,y:C}={}){this.isWithin(n,C)&&(this.mouseX=n,this.mouseY=C,this.mouseMoveZoomHandler())}},{key:"mouseMoveZoomHandler",value:function(){}},{key:"zoomed",value:function(...n){SB(Vh(I.prototype),"zoomed",this).call(this,...n),this.mouseMoveZoomHandler()}}]),I}(Bm);function PXt(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function Ore(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function Bs(g){return Bs=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},Bs(g)}let sy=function(g){UXt(I,g);var e=QXt(I);function I(i,n){var C;PXt(this,I),C=e.call(this,i,n);const{animate:r,isShowGlobalMousePosition:o}=i;return C.constIndicator=new Ct.PIXI.Graphics,C.pMain.addChild(C.constIndicator),C.axis=new zk(uP(C)),C.pBase.addChild(C.axis.pAxis),C.animate=r,C.options=n,C.isShowGlobalMousePosition=o,C.pubSubs=[],C.options.showMousePosition&&!C.hideMousePosition&&(C.hideMousePosition=hh(uP(C),C.is2d,C.isShowGlobalMousePosition())),C}return JXt(I,[{key:"rerender",value:function(n,C){const r=JSON.stringify(n);!C&&r===this.prevOptions||(yd(Bs(I.prototype),"rerender",this).call(this,n,C),this.prevOptions=r,this.options=n,this.options.showMousePosition&&!this.hideMousePosition&&(this.hideMousePosition=hh(this,this.is2d,this.isShowGlobalMousePosition())),!this.options.showMousePosition&&this.hideMousePosition&&(this.hideMousePosition(),this.hideMousePosition=void 0))}},{key:"calculateZoomLevel",value:function(){if(this.tilesetInfo.resolutions)return vt.calculateZoomLevelFromResolutions(this.tilesetInfo.resolutions,this._xScale,this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0]-2);const n=vt.calculateZoomLevel(this._xScale,this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0],this.tilesetInfo.bins_per_dimension||this.tilesetInfo.tile_size);let C=Math.min(n,this.maxZoom);return C=Math.max(C,0),C}},{key:"relevantScale",value:function(){return this._xScale}},{key:"draw",value:function(){yd(Bs(I.prototype),"draw",this).call(this),this.drawConstIndicator()}},{key:"drawAxis",value:function(n){if(!this.options.axisPositionVertical&&!this.options.axisPositionHorizontal){this.axis.clearAxis();return}if(this.options.axisPositionVertical&&this.options.axisPositionVertical==="hidden"){this.axis.clearAxis();return}if(this.options.axisPositionHorizontal&&this.options.axisPositionHorizontal==="hidden"){this.axis.clearAxis();return}const C=this.options.axisMargin||0;this.options.axisPositionHorizontal==="left"||this.options.axisPositionVertical==="top"?(this.axis.pAxis.position.x=this.position[0]+C,this.axis.pAxis.position.y=this.position[1],this.axis.drawAxisRight(n,this.dimensions[1])):this.options.axisPositionHorizontal==="outsideLeft"||this.options.axisPositionVertical==="outsideTop"?(this.axis.pAxis.position.x=this.position[0]+C,this.axis.pAxis.position.y=this.position[1],this.axis.drawAxisLeft(n,this.dimensions[1])):this.options.axisPositionHorizontal==="right"||this.options.axisPositionVertical==="bottom"?(this.axis.pAxis.position.x=this.position[0]+this.dimensions[0]-C,this.axis.pAxis.position.y=this.position[1],this.axis.drawAxisLeft(n,this.dimensions[1])):(this.options.axisPositionHorizontal==="outsideRight"||this.options.axisPositionVertical==="outsideBottom")&&(this.axis.pAxis.position.x=this.position[0]+this.dimensions[0]-C,this.axis.pAxis.position.y=this.position[1],this.axis.drawAxisRight(n,this.dimensions[1]))}},{key:"mouseMoveZoomHandler",value:function(n=this.mouseX,C=this.mouseY){if(typeof n>"u"||!this.areAllVisibleTilesLoaded()||!this.tilesetInfo)return;let r=0,o=0,A="1d-horizontal";this.isLeftModified?(r=C-this.position[1],o=n-this.position[0],A="1d-vertical"):(r=n-this.position[0],o=C-this.position[1]);const s=n-this.position[0],a=C-this.position[1],l=this._xScale.invert(r),c=this._yScale.invert(o),u=this.getDataAtPos(r);u&&this.onMouseMoveZoom({trackId:this.id,data:u,absX:n,absY:C,relX:s,relY:a,dataX:l,dataY:c,orientation:A})}},{key:"drawConstIndicator",value:function(){if(this.constIndicator){for(this.constIndicator.clear();this.constIndicator.children[0];)this.constIndicator.removeChild(this.constIndicator.children[0]);!this.options.constIndicators||!this.valueScale||this.options.constIndicators.forEach(({color:n="black",opacity:C=1,label:r=null,labelColor:o="black",labelOpacity:A=1,labelPosition:s="leftTop",labelSize:a=12,value:l=0}={})=>{const c=zt(n),u=zt(o);this.constIndicator.beginFill(c,C);const d=this.valueScale(l);let h=0,m=0;if(r){const f=new Ct.PIXI.Text(r,{fontFamily:"Arial",fontSize:a,fill:u});switch(f.alpha=A,s){case"right":f.anchor.x=1,f.anchor.y=.5,f.x=this.position[0]+this.dimensions[0]-6,f.y=d,m=f.width+8;break;case"rightBottom":f.anchor.x=1,f.anchor.y=0,f.x=this.position[0]+this.dimensions[0]-6,f.y=d;break;case"rightTop":f.anchor.x=1,f.anchor.y=1,f.x=this.position[0]+this.dimensions[0]-6,f.y=d;break;case"left":f.anchor.x=0,f.anchor.y=.5,f.x=this.position[0]+2,f.y=d,h=f.width+4;break;case"leftBottom":f.anchor.x=0,f.anchor.y=0,f.x=this.position[0]+2,f.y=d;break;case"leftTop":default:f.anchor.x=0,f.anchor.y=1,f.x=this.position[0]+2,f.y=d;break}this.constIndicator.addChild(f)}this.constIndicator.drawRect(this.position[0]+h,d,this.dimensions[0]-m,1)})}}},{key:"exportSVG",value:function(){let n=null,C=null;yd(Bs(I.prototype),"exportSVG",this)?[C,n]=yd(Bs(I.prototype),"exportSVG",this).call(this):(C=document.createElement("g"),n=C),C.setAttribute("class","horizontal-tiled-1d-track");const r=document.createElement("g");return n.appendChild(r),this.options.constIndicators&&this.options.constIndicators.forEach(({color:o="black",opacity:A=1,label:s=null,labelColor:a="black",labelOpacity:l=1,labelPosition:c="leftTop",labelSize:u=12,value:d=0}={})=>{const h=this.valueScale(d);if(s){const f=document.createElement("text");switch(f.textContent=s,f.setAttribute("x",this.position[0]),f.setAttribute("y",h),f.setAttribute("style",`font-family: 'Arial'; font-size: ${u}px; fill: ${a}; fill-opacity: ${l};`),c){case"rightBottom":f.setAttribute("x",this.position[0]+this.dimensions[0]-6),f.setAttribute("y",h+u+2),f.setAttribute("text-anchor","end");break;case"right":case"rightTop":f.setAttribute("x",this.position[0]+this.dimensions[0]-6),f.setAttribute("y",h-2),f.setAttribute("text-anchor","end");break;case"leftBottom":f.setAttribute("x",this.position[0]+2),f.setAttribute("y",h+u+2);break;case"left":case"leftTop":default:f.setAttribute("x",this.position[0]+2),f.setAttribute("y",h-2);break}r.appendChild(f)}const m=document.createElement("line");m.setAttribute("x1",this.position[0]),m.setAttribute("y1",h),m.setAttribute("x2",this.dimensions[0]),m.setAttribute("y2",h),m.setAttribute("stroke",o),m.setAttribute("stroke-opacity",A),r.appendChild(m)}),[C,n]}}]),I}(_j);function qXt(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function Lre(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function s0(g){return s0=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},s0(g)}let JRe=function(g){i9t(I,g);var e=n9t(I);function I(i,n){var C;return qXt(this,I),C=e.call(this,i,n),C.pMain=C.pMobile,C}return e9t(I,[{key:"areAllVisibleTilesLoaded",value:function(){return!0}},{key:"initTile",value:function(n){const C=n.graphics;n.textGraphics=new Ct.PIXI.Graphics,n.text=new Ct.PIXI.Text(`${n.tileData.zoomLevel}/${n.tileData.tilePos.join("/")}`,{fontFamily:"Arial",fontSize:32,fill:16715792,align:"center"}),n.textGraphics.addChild(n.text),n.text.anchor.x=.5,n.text.anchor.y=.5,C.addChild(n.textGraphics),this.drawTile(n)}},{key:"destroyTile",value:function(n){}},{key:"drawTile",value:function(n){if(GW(s0(I.prototype),"drawTile",this).call(this,n),!n.graphics)return;const C=n.graphics,{tileX:r,tileWidth:o}=this.getTilePosAndDimensions(n.tileData.zoomLevel,n.tileData.tilePos),A=1/((this._xScale(1)-this._xScale(0))/(this._refXScale(1)-this._refXScale(0)));n.text.scale.x=A,C.clear();const s=this.dimensions[1],a=this._refXScale(r+o)-this._refXScale(r);n.textGraphics.position.x=this._refXScale(r)+a/2,n.textGraphics.position.y=s/2;const l=this._refXScale(r);C.lineStyle(4*A,255,1),C.beginFill(16740363,.4),C.alpha=.5,C.moveTo(l,0),C.lineTo(l,s),C.moveTo(l+a,0),C.lineTo(l+a,s),C.lineStyle(0,255,1),C.drawRect(l,0,a,s)}}]),I}(sy);function A9t(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function _re(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function l0(g){return l0=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},l0(g)}let ORe=function(g){u9t(I,g);var e=d9t(I);function I(){return A9t(this,I),e.apply(this,arguments)}return a9t(I,[{key:"calculateZoomLevel",value:function(){const n=vt.calculateZoomLevel(this._yScale,this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0]);return Math.min(n,this.maxZoom)}},{key:"relevantScale",value:function(){return this._yScale}},{key:"zoomed",value:function(n,C){BW(l0(I.prototype),"zoomed",this).call(this,n,C);const r=1,o=(C(1)-C(0))/(this._refYScale(1)-this._refYScale(0)),A=this.position[0],s=C(0)+this.position[1]-this._refYScale(1)*o;this.pMain.position.x=A,this.pMain.position.y=s,this.pMain.scale.x=r,this.pMain.scale.y=o}}]),I}(_j);function p9t(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function Ure(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function c0(g){return c0=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},c0(g)}let LRe=function(g){B9t(I,g);var e=v9t(I);function I(){return p9t(this,I),e.apply(this,arguments)}return b9t(I,[{key:"areAllVisibleTilesLoaded",value:function(){return!0}},{key:"initTile",value:function(n){const C=n.graphics;n.textGraphics=new Ct.PIXI.Graphics,n.text=new Ct.PIXI.Text(`${n.tileData.zoomLevel}/${n.tileData.tilePos.join("/")}`,{fontFamily:"Arial",fontSize:32,fill:16715792,align:"center"}),n.textGraphics.addChild(n.text),n.text.anchor.x=.5,n.text.anchor.y=.5,n.text.rotation=-Math.PI/2,C.addChild(n.textGraphics),this.drawTile(n,C)}},{key:"destroyTile",value:function(n,C){}},{key:"drawTile",value:function(n){if(vW(c0(I.prototype),"drawTile",this).call(this,n),!n.graphics)return;const C=n.graphics,{tileY:r,tileHeight:o}=this.getTilePosAndDimensions(n.tileData.zoomLevel,n.tileData.tilePos),A=1/((this._yScale(1)-this._yScale(0))/(this._refYScale(1)-this._refYScale(0)));n.text.scale.x=A,C.clear(),C.lineStyle(4*A,255,1),C.beginFill(16740363,.4),C.alpha=.5;const s=this.dimensions[0],a=this._refYScale(r+o)-this._refYScale(r);n.textGraphics.position.x=s/2,n.textGraphics.position.y=this._refYScale(r)+a/2,C.drawRect(0,this._refYScale(r),s,a)}},{key:"fetchNewTiles",value:function(n){n.forEach(C=>{const o=C.remoteId.split("."),A={zoomLevel:o[1],tilePos:o.slice(2,o.length).map(s=>+s)};this.fetchedTiles[C.tileId]=C,this.fetchedTiles[C.tileId].tileData=A,this.fetching.has(C.remoteId)&&this.fetching.delete(C.remoteId)}),this.synchronizeTilesAndGraphics()}}]),I}(ORe);var UD=Array.prototype.slice;function R9t(g){return g}var SW=1,wW=2,fP=3,AG=4,Qre=1e-6;function W9t(g){return"translate("+g+",0)"}function X9t(g){return"translate(0,"+g+")"}function H9t(g){return e=>+g(e)}function T9t(g,e){return e=Math.max(0,g.bandwidth()-e*2)/2,g.round()&&(e=Math.round(e)),I=>+g(I)+e}function N9t(){return!this.__axis}function Uk(g,e){var I=[],i=null,n=null,C=6,r=6,o=3,A=typeof window<"u"&&window.devicePixelRatio>1?0:.5,s=g===SW||g===AG?-1:1,a=g===AG||g===wW?"x":"y",l=g===SW||g===fP?W9t:X9t;function c(u){var d=i??(e.ticks?e.ticks.apply(e,I):e.domain()),h=n??(e.tickFormat?e.tickFormat.apply(e,I):R9t),m=Math.max(C,0)+o,f=e.range(),b=+f[0]+A,p=+f[f.length-1]+A,y=(e.bandwidth?T9t:H9t)(e.copy(),A),Z=u.selection?u.selection():u,v=Z.selectAll(".domain").data([null]),G=Z.selectAll(".tick").data(d,e).order(),B=G.exit(),w=G.enter().append("g").attr("class","tick"),R=G.select("line"),S=G.select("text");v=v.merge(v.enter().insert("path",".tick").attr("class","domain").attr("stroke","currentColor")),G=G.merge(w),R=R.merge(w.append("line").attr("stroke","currentColor").attr(a+"2",s*C)),S=S.merge(w.append("text").attr("fill","currentColor").attr(a,s*m).attr("dy",g===SW?"0em":g===fP?"0.71em":"0.32em")),u!==Z&&(v=v.transition(u),G=G.transition(u),R=R.transition(u),S=S.transition(u),B=B.transition(u).attr("opacity",Qre).attr("transform",function(X){return isFinite(X=y(X))?l(X+A):this.getAttribute("transform")}),w.attr("opacity",Qre).attr("transform",function(X){var W=this.parentNode.__axis;return l((W&&isFinite(W=W(X))?W:y(X))+A)})),B.remove(),v.attr("d",g===AG||g===wW?r?"M"+s*r+","+b+"H"+A+"V"+p+"H"+s*r:"M"+A+","+b+"V"+p:r?"M"+b+","+s*r+"V"+A+"H"+p+"V"+s*r:"M"+b+","+A+"H"+p),G.attr("opacity",1).attr("transform",function(X){return l(y(X)+A)}),R.attr(a+"2",s*C),S.attr(a,s*m).text(h),Z.filter(N9t).attr("fill","none").attr("font-size",10).attr("font-family","sans-serif").attr("text-anchor",g===wW?"start":g===AG?"end":"middle"),Z.each(function(){this.__axis=y})}return c.scale=function(u){return arguments.length?(e=u,c):e},c.ticks=function(){return I=UD.call(arguments),c},c.tickArguments=function(u){return arguments.length?(I=u==null?[]:UD.call(u),c):I.slice()},c.tickValues=function(u){return arguments.length?(i=u==null?null:UD.call(u),c):i&&i.slice()},c.tickFormat=function(u){return arguments.length?(n=u,c):n},c.tickSize=function(u){return arguments.length?(C=r=+u,c):C},c.tickSizeInner=function(u){return arguments.length?(C=+u,c):C},c.tickSizeOuter=function(u){return arguments.length?(r=+u,c):r},c.tickPadding=function(u){return arguments.length?(o=+u,c):o},c.offset=function(u){return arguments.length?(A=+u,c):A},c}function _Re(g){return Uk(SW,g)}function k9t(g){return Uk(wW,g)}function Y9t(g){return Uk(fP,g)}function URe(g){return Uk(AG,g)}const K9t=Object.freeze(Object.defineProperty({__proto__:null,axisBottom:Y9t,axisLeft:URe,axisRight:k9t,axisTop:_Re},Symbol.toStringTag,{value:"Module"}));function x9t(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function jre(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function yH(g){return yH=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},yH(g)}let vm=function(g){M9t(I,g);var e=z9t(I);function I(i,n){var C;x9t(this,I),C=e.call(this,i,n);const{svgElement:r}=i;return C.gMain=pg(r).append("g"),C.clipUid=dg.nice(),C.clipRect=C.gMain.append("clipPath").attr("id",`track-bounds-${C.clipUid}`).append("rect"),C.gMain.attr("clip-path",`url(#track-bounds-${C.clipUid})`),C}return D9t(I,[{key:"setPosition",value:function(n){this.position=n,this.gMain.attr("transform",`translate(${this.position[0]},${this.position[1]})`),this.draw()}},{key:"setDimensions",value:function(n){this.dimensions=n,this._xScale.range([0,this.dimensions[0]]),this._yScale.range([0,this.dimensions[1]]),n[0]>=0&&n[1]>=0?(this.clipRect.attr("width",n[0]),this.clipRect.attr("height",n[1])):(this.clipRect.attr("width",0),this.clipRect.attr("height",0)),this.draw()}},{key:"remove",value:function(){this.gMain.remove(),this.gMain=null}},{key:"draw",value:function(){return this}}]),I}($p);function L9t(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function $re(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function Rh(g){return Rh=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},Rh(g)}let QRe=function(g){$9t(I,g);var e=q9t(I);function I(i,n){var C;return L9t(this,I),C=e.call(this,i,n),C.axis=_Re(C._xScale),C.gAxis=C.gMain.append("g"),C.tilesetInfo=!0,C}return _9t(I,[{key:"setDimensions",value:function(n){wB(Rh(I.prototype),"setDimensions",this).call(this,n),this.axis.ticks(Math.ceil(this.dimensions[0]/150)),this.gAxis.attr("transform",`translate(0,${n[1]})`)}},{key:"draw",value:function(){return this.axis.scale(this._xScale),this.gAxis.call(this.axis),this}},{key:"zoomed",value:function(n,C){wB(Rh(I.prototype),"zoomed",this).call(this,n,C),this.draw()}}]),I}(vm);function IHt(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function qre(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function Wh(g){return Wh=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},Wh(g)}let jRe=function(g){oHt(I,g);var e=AHt(I);function I(i,n){var C;return IHt(this,I),C=e.call(this,i,n),C.axis=URe(C._yScale),C.gAxis=C.gMain.append("g"),C.tilesetInfo=!0,C}return iHt(I,[{key:"setDimensions",value:function(n){VB(Wh(I.prototype),"setDimensions",this).call(this,n),this.axis.ticks(Math.ceil(this.dimensions[1]/150)),this.gAxis.attr("transform",`translate(${n[0]},0)`)}},{key:"draw",value:function(){return this.axis.scale(this._yScale),this.gAxis.call(this.axis),this}},{key:"zoomed",value:function(n,C){VB(Wh(I.prototype),"zoomed",this).call(this,n,C),this.draw()}}]),I}(vm);var ug={},TI={},Uj=32;TI.INT_BITS=Uj;TI.INT_MAX=2147483647;TI.INT_MIN=-1<0)-(g<0)};TI.abs=function(g){var e=g>>Uj-1;return(g^e)-e};TI.min=function(g,e){return e^(g^e)&-(g65535)<<4,g>>>=e,I=(g>255)<<3,g>>>=I,e|=I,I=(g>15)<<2,g>>>=I,e|=I,I=(g>3)<<1,g>>>=I,e|=I,e|g>>1};TI.log10=function(g){return g>=1e9?9:g>=1e8?8:g>=1e7?7:g>=1e6?6:g>=1e5?5:g>=1e4?4:g>=1e3?3:g>=100?2:g>=10?1:0};TI.popCount=function(g){return g=g-(g>>>1&1431655765),g=(g&858993459)+(g>>>2&858993459),(g+(g>>>4)&252645135)*16843009>>>24};function $Re(g){var e=32;return g&=-g,g&&e--,g&65535&&(e-=16),g&16711935&&(e-=8),g&252645135&&(e-=4),g&858993459&&(e-=2),g&1431655765&&(e-=1),e}TI.countTrailingZeros=$Re;TI.nextPow2=function(g){return g+=g===0,--g,g|=g>>>1,g|=g>>>2,g|=g>>>4,g|=g>>>8,g|=g>>>16,g+1};TI.prevPow2=function(g){return g|=g>>>1,g|=g>>>2,g|=g>>>4,g|=g>>>8,g|=g>>>16,g-(g>>>1)};TI.parity=function(g){return g^=g>>>16,g^=g>>>8,g^=g>>>4,g&=15,27030>>>g&1};var aG=new Array(256);(function(g){for(var e=0;e<256;++e){var I=e,i=e,n=7;for(I>>>=1;I;I>>>=1)i<<=1,i|=I&1,--n;g[e]=i<>>8&255]<<16|aG[g>>>16&255]<<8|aG[g>>>24&255]};TI.interleave2=function(g,e){return g&=65535,g=(g|g<<8)&16711935,g=(g|g<<4)&252645135,g=(g|g<<2)&858993459,g=(g|g<<1)&1431655765,e&=65535,e=(e|e<<8)&16711935,e=(e|e<<4)&252645135,e=(e|e<<2)&858993459,e=(e|e<<1)&1431655765,g|e<<1};TI.deinterleave2=function(g,e){return g=g>>>e&1431655765,g=(g|g>>>1)&858993459,g=(g|g>>>2)&252645135,g=(g|g>>>4)&16711935,g=(g|g>>>16)&65535,g<<16>>16};TI.interleave3=function(g,e,I){return g&=1023,g=(g|g<<16)&4278190335,g=(g|g<<8)&251719695,g=(g|g<<4)&3272356035,g=(g|g<<2)&1227133513,e&=1023,e=(e|e<<16)&4278190335,e=(e|e<<8)&251719695,e=(e|e<<4)&3272356035,e=(e|e<<2)&1227133513,g|=e<<1,I&=1023,I=(I|I<<16)&4278190335,I=(I|I<<8)&251719695,I=(I|I<<4)&3272356035,I=(I|I<<2)&1227133513,g|I<<2};TI.deinterleave3=function(g,e){return g=g>>>e&1227133513,g=(g|g>>>2)&3272356035,g=(g|g>>>4)&251719695,g=(g|g>>>8)&4278190335,g=(g|g>>>16)&1023,g<<22>>22};TI.nextCombination=function(g){var e=g|g-1;return e+1|(~e&-~e)-1>>>$Re(g)+1};function qRe(g,e,I){var i=g[I]|0;if(i<=0)return[];var n=new Array(i),C;if(I===g.length-1)for(C=0;C"u"&&(e=0),typeof g){case"number":if(g>0)return cHt(g|0,e);break;case"object":if(typeof g.length=="number")return qRe(g,e,0);break}return[]}var dHt=uHt,e1e={},Qk={};Qk.byteLength=fHt;Qk.toByteArray=bHt;Qk.fromByteArray=GHt;var qA=[],Yr=[],hHt=typeof Uint8Array<"u"?Uint8Array:Array,QD="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(var rf=0,mHt=QD.length;rf0)throw new Error("Invalid string. Length must be a multiple of 4");var I=g.indexOf("=");I===-1&&(I=e);var i=I===e?0:4-I%4;return[I,i]}function fHt(g){var e=t1e(g),I=e[0],i=e[1];return(I+i)*3/4-i}function pHt(g,e,I){return(e+I)*3/4-I}function bHt(g){var e,I=t1e(g),i=I[0],n=I[1],C=new hHt(pHt(g,i,n)),r=0,o=n>0?i-4:i,A;for(A=0;A>16&255,C[r++]=e>>8&255,C[r++]=e&255;return n===2&&(e=Yr[g.charCodeAt(A)]<<2|Yr[g.charCodeAt(A+1)]>>4,C[r++]=e&255),n===1&&(e=Yr[g.charCodeAt(A)]<<10|Yr[g.charCodeAt(A+1)]<<4|Yr[g.charCodeAt(A+2)]>>2,C[r++]=e>>8&255,C[r++]=e&255),C}function yHt(g){return qA[g>>18&63]+qA[g>>12&63]+qA[g>>6&63]+qA[g&63]}function ZHt(g,e,I){for(var i,n=[],C=e;Co?o:r+C));return i===1?(e=g[I-1],n.push(qA[e>>2]+qA[e<<4&63]+"==")):i===2&&(e=(g[I-2]<<8)+g[I-1],n.push(qA[e>>10]+qA[e>>4&63]+qA[e<<2&63]+"=")),n.join("")}var Qj={};/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh */Qj.read=function(g,e,I,i,n){var C,r,o=n*8-i-1,A=(1<>1,a=-7,l=I?n-1:0,c=I?-1:1,u=g[e+l];for(l+=c,C=u&(1<<-a)-1,u>>=-a,a+=o;a>0;C=C*256+g[e+l],l+=c,a-=8);for(r=C&(1<<-a)-1,C>>=-a,a+=i;a>0;r=r*256+g[e+l],l+=c,a-=8);if(C===0)C=1-s;else{if(C===A)return r?NaN:(u?-1:1)*(1/0);r=r+Math.pow(2,i),C=C-s}return(u?-1:1)*r*Math.pow(2,C-i)};Qj.write=function(g,e,I,i,n,C){var r,o,A,s=C*8-n-1,a=(1<>1,c=n===23?Math.pow(2,-24)-Math.pow(2,-77):0,u=i?0:C-1,d=i?1:-1,h=e<0||e===0&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(o=isNaN(e)?1:0,r=a):(r=Math.floor(Math.log(e)/Math.LN2),e*(A=Math.pow(2,-r))<1&&(r--,A*=2),r+l>=1?e+=c/A:e+=c*Math.pow(2,1-l),e*A>=2&&(r++,A/=2),r+l>=a?(o=0,r=a):r+l>=1?(o=(e*A-1)*Math.pow(2,n),r=r+l):(o=e*Math.pow(2,l-1)*Math.pow(2,n),r=0));n>=8;g[I+u]=o&255,u+=d,o/=256,n-=8);for(r=r<0;g[I+u]=r&255,u+=d,r/=256,s-=8);g[I+u-d]|=h*128};/*! +[Transform: Default ]`}this.labelText.text=s,this.labelText.style={fontSize:`${this.labelTextFontSize}px`,fontFamily:this.labelTextFontFamily,fill:o},this.labelText.alpha=typeof this.options.labelTextOpacity<"u"?this.options.labelTextOpacity:1,this.labelText.visible=!0,this.flipText&&(this.labelText.scale.x=-1);const{labelLeftMargin:a=0,labelRightMargin:l=0,labelTopMargin:c=0,labelBottomMargin:u=0}=this.options;this.options.labelPosition==="topLeft"?(this.labelText.x=this.position[0]+a+this.labelXOffset,this.labelText.y=this.position[1]+c,this.labelText.anchor.x=.5,this.labelText.anchor.y=0,this.labelText.x+=this.labelText.width/2,n.drawRect(this.position[0]+a+this.labelXOffset,this.position[1]+c,this.labelText.width+A,this.labelText.height+A)):this.options.labelPosition==="bottomLeft"&&!this.flipText||this.options.labelPosition==="topRight"&&this.flipText?(this.labelText.x=this.position[0]+(a||c),this.labelText.y=this.position[1]+this.dimensions[1]-(u||l),this.labelText.anchor.x=.5,this.labelText.anchor.y=1,this.labelText.x+=this.labelText.width/2+this.labelXOffset,n.drawRect(this.position[0]+(a||c)+this.labelXOffset,this.position[1]+this.dimensions[1]-this.labelText.height-A-(u||l),this.labelText.width+A,this.labelText.height+A)):this.options.labelPosition==="topRight"&&!this.flipText||this.options.labelPosition==="bottomLeft"&&this.flipText?(this.labelText.x=this.position[0]+this.dimensions[0]-(l||u),this.labelText.y=this.position[1]+(c||a),this.labelText.anchor.x=.5,this.labelText.anchor.y=0,this.labelText.x-=this.labelText.width/2+this.labelXOffset,n.drawRect(this.position[0]+this.dimensions[0]-this.labelText.width-A-(l||u)-this.labelXOffset,this.position[1]+(c||a),this.labelText.width+A,this.labelText.height+A)):this.options.labelPosition==="bottomRight"?(this.labelText.x=this.position[0]+this.dimensions[0]-l,this.labelText.y=this.position[1]+this.dimensions[1]-u,this.labelText.anchor.x=.5,this.labelText.anchor.y=1,this.labelText.x-=this.labelText.width/2+this.labelXOffset,n.drawRect(this.position[0]+this.dimensions[0]-this.labelText.width-A-l-this.labelXOffset,this.position[1]+this.dimensions[1]-this.labelText.height-A-u,this.labelText.width+A,this.labelText.height+A)):this.options.labelPosition==="outerLeft"&&!this.flipText||this.options.labelPosition==="outerTop"&&this.flipText?(this.labelText.x=this.position[0],this.labelText.y=this.position[1]+this.dimensions[1]/2,this.labelText.anchor.x=.5,this.labelText.anchor.y=.5,this.labelText.x-=this.labelText.width/2+3):this.options.labelPosition==="outerTop"&&!this.flipText||this.options.labelPosition==="outerLeft"&&this.flipText?(this.labelText.x=this.position[0]+this.dimensions[0]/2,this.labelText.y=this.position[1],this.labelText.anchor.x=.5,this.labelText.anchor.y=.5,this.labelText.y-=this.labelText.height/2+3):this.options.labelPosition==="outerBottom"&&!this.flipText||this.options.labelPosition==="outerRight"&&this.flipText?(this.labelText.x=this.position[0]+this.dimensions[0]/2,this.labelText.y=this.position[1]+this.dimensions[1],this.labelText.anchor.x=.5,this.labelText.anchor.y=.5,this.labelText.y+=this.labelText.height/2+3):this.options.labelPosition==="outerRight"&&!this.flipText||this.options.labelPosition==="outerBottom"&&this.flipText?(this.labelText.x=this.position[0]+this.dimensions[0],this.labelText.y=this.position[1]+this.dimensions[1]/2,this.labelText.anchor.x=.5,this.labelText.anchor.y=.5,this.labelText.x+=this.labelText.width/2+3):this.labelText.visible=!1,this.options.labelPosition==="outerLeft"||this.options.labelPosition==="outerRight"||this.options.labelPosition==="outerTop"||this.options.labelPosition==="outerBottom"?this.pLabel.setParent(this.pBase):this.pLabel.setParent(this.pMasked)}},{key:"rerender",value:function(n){this.options=n,this.draw(),this.drawBackground(),this.drawLabel(),this.drawError(),this.drawBorder()}},{key:"draw",value:function(){this.drawError()}},{key:"exportSVG",value:function(){const n=document.createElement("g"),C=document.createElement("rect");C.setAttribute("x",`${this.position[0]}`),C.setAttribute("y",`${this.position[1]}`),C.setAttribute("width",`${this.dimensions[0]}`),C.setAttribute("height",`${this.dimensions[1]}`),this.options&&this.options.backgroundColor?C.setAttribute("fill",this.options.backgroundColor):C.setAttribute("fill-opacity","0");const r=document.createElement("g");r.setAttribute("class","g-clipped"),n.appendChild(r),r.appendChild(C);const o=document.createElement("g");r.setAttribute("class","g-track"),r.appendChild(o);const A=document.createElement("g");r.setAttribute("class","g-labels"),r.appendChild(A);const s=document.createElementNS("http://www.w3.org/2000/svg","clipPath");n.appendChild(s);const a=document.createElementNS("http://www.w3.org/2000/svg","polygon");s.appendChild(a),a.setAttribute("points",`${this.position[0]},${this.position[1]} ${this.position[0]+this.dimensions[0]},${this.position[1]} ${this.position[0]+this.dimensions[0]},${this.position[1]+this.dimensions[1]} ${this.position[0]},${this.position[1]+this.dimensions[1]} `);const l=Ag.nice();s.setAttribute("id",l),r.setAttribute("style",`clip-path:url(#${l});`);const c=this.labelText.text.split(` +`);let u=0;const d=3,h=(this.labelTextFontSize+2)*c.length+d;this.labelText.anchor.y===.5?u=h/2:this.labelText.anchor.y===1&&(u=-h);for(let m=0;mnew e(i,I)))}return uWt(e,[{key:"registerFileUrl",value:async function({server:I,url:i,filetype:n,coordSystem:C}){const r=`${rN(I)}/register_url/`;return fetch(r,{method:"POST",body:JSON.stringify({fileurl:i,filetype:n,coordSystem:C}),headers:{"Content-Type":"application/json; charset=utf-8"}})}},{key:"tilesetInfo",value:function(I){const{server:i,url:n,filetype:C,coordSystem:r}=this.dataConfig;return i&&n&&C?this.registerFileUrl({server:i,url:n,filetype:C,coordSystem:r}).then(o=>o.json()).then(o=>{this.dataConfig.tilesetUid=o.uid,this.tilesetInfoAfterRegister(I)}).catch(o=>{console.error("Error registering url",o)}):new Promise(()=>{this.tilesetInfoAfterRegister(I)})}},{key:"tilesetInfoAfterRegister",value:function(I){if(this.dataConfig.children){const i=this.dataConfig.children.map(n=>new Promise(C=>{n.tilesetInfo(C)}));Promise.all(i).then(n=>{I(n[0])})}else{const{server:i,tilesetUid:n}=this.dataConfig;!i||!n?(console.warn("No dataConfig children, server or tilesetUid:",this.dataConfig),I(null)):Gt.trackInfo(i,n,C=>{this.dataConfig.tilesetInfo=C[n],I(C[n],n)},C=>{this.tilesetInfoLoading=!1,I({error:C})},this.pubSub)}}},{key:"fullTileId",value:function(I,i){return`${I}.${i}`}},{key:"fetchTilesDebounced",value:function(I,i){var n;if(this.dataConfig.type==="horizontal-section")return this.fetchHorizontalSection(I,i);if(this.dataConfig.type==="vertical-section")return this.fetchHorizontalSection(I,i,!0);if(!this.dataConfig.children&&this.dataConfig.tilesetUid)return new Promise(o=>{Gt.fetchTilesDebounced({id:Ag.nice(),server:this.dataConfig.server,done:o,ids:i.map(A=>`${this.dataConfig.tilesetUid}.${A}`),options:this.dataConfig.options},this.pubSub,!0)}).then(o=>{const A=xg(o)[0].tilesetUid,s={};for(let a=0;anew Promise(o=>{r.fetchTilesDebounced(o,i)})))??[];return Promise.all(C).then(r=>{if(this.dataConfig.type==="divided"&&mWt(r)){const o=this.makeDivided(r,i);return I(o),o}return console.warn("Unimplemented dataConfig type. Returning first data source.",this.dataConfig),I(r[0]),r[0]})}},{key:"divideData",value:function(I,i){const n=new Float32Array(I.length);for(let C=0;C+p).sort((p,y)=>y-p);h=Gt.calculateTilesFromResolution(b[c],d,A.min_pos[n?1:0],A.max_pos[n?1:0])}else h=Gt.calculateTiles(c,d,A.min_pos[n?1:0],A.max_pos[n?1:0],A.max_zoom,A.max_width);const m=[u,h[0]].sort((b,p)=>b-p);m[0]===u?r.push(!1):r.push(!0);const f=`${c}.${m[0]}.${m[1]}`;C.push(f)}return new Promise(a=>{Gt.fetchTilesDebounced({id:Ag.nice(),server:this.dataConfig.server,done:a,ids:C.map(l=>`${this.dataConfig.tilesetUid}.${l}`)},this.pubSub,!0)}).then(a=>{const l=xg(a)[0].tilesetUid,c={};for(let u=0;u=0;)e[g]=0}var yWt=0,Ewe=1,ZWt=2,GWt=3,vWt=258,oj=29,_S=256,wB=_S+1+oj,Wp=30,Aj=19,Mwe=2*wB+1,td=15,OD=16,BWt=7,aj=256,zwe=16,Pwe=17,Jwe=18,pz=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0],Y1=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13],SWt=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7],Owe=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],wWt=512,ja=new Array((wB+2)*2);P0(ja);var UG=new Array(Wp*2);P0(UG);var VB=new Array(wWt);P0(VB);var RB=new Array(vWt-GWt+1);P0(RB);var sj=new Array(oj);P0(sj);var V9=new Array(Wp);P0(V9);function _D(e,g,I,i,n){this.static_tree=e,this.extra_bits=g,this.extra_base=I,this.elems=i,this.max_length=n,this.has_stree=e&&e.length}var _we,Lwe,Uwe;function LD(e,g){this.dyn_tree=e,this.max_code=0,this.stat_desc=g}function Qwe(e){return e<256?VB[e]:VB[256+(e>>>7)]}function WB(e,g){e.pending_buf[e.pending++]=g&255,e.pending_buf[e.pending++]=g>>>8&255}function XC(e,g,I){e.bi_valid>OD-I?(e.bi_buf|=g<>OD-e.bi_valid,e.bi_valid+=I-OD):(e.bi_buf|=g<>>=1,I<<=1;while(--g>0);return I>>>1}function VWt(e){e.bi_valid===16?(WB(e,e.bi_buf),e.bi_buf=0,e.bi_valid=0):e.bi_valid>=8&&(e.pending_buf[e.pending++]=e.bi_buf&255,e.bi_buf>>=8,e.bi_valid-=8)}function RWt(e,g){var I=g.dyn_tree,i=g.max_code,n=g.stat_desc.static_tree,C=g.stat_desc.has_stree,r=g.stat_desc.extra_bits,o=g.stat_desc.extra_base,A=g.stat_desc.max_length,s,a,l,c,u,d,h=0;for(c=0;c<=td;c++)e.bl_count[c]=0;for(I[e.heap[e.heap_max]*2+1]=0,s=e.heap_max+1;sA&&(c=A,h++),I[a*2+1]=c,!(a>i)&&(e.bl_count[c]++,u=0,a>=o&&(u=r[a-o]),d=I[a*2],e.opt_len+=d*(c+u),C&&(e.static_len+=d*(n[a*2+1]+u)));if(h!==0){do{for(c=A-1;e.bl_count[c]===0;)c--;e.bl_count[c]--,e.bl_count[c+1]+=2,e.bl_count[A]--,h-=2}while(h>0);for(c=A;c!==0;c--)for(a=e.bl_count[c];a!==0;)l=e.heap[--s],!(l>i)&&(I[l*2+1]!==c&&(e.opt_len+=(c-I[l*2+1])*I[l*2],I[l*2+1]=c),a--)}}function $we(e,g,I){var i=new Array(td+1),n=0,C,r;for(C=1;C<=td;C++)i[C]=n=n+I[C-1]<<1;for(r=0;r<=g;r++){var o=e[r*2+1];o!==0&&(e[r*2]=jwe(i[o]++,o))}}function WWt(){var e,g,I,i,n,C=new Array(td+1);for(I=0,i=0;i>=7;i8?WB(e,e.bi_buf):e.bi_valid>0&&(e.pending_buf[e.pending++]=e.bi_buf),e.bi_buf=0,e.bi_valid=0}function XWt(e,g,I,i){eVe(e),i&&(WB(e,I),WB(e,~I)),fWt.arraySet(e.pending_buf,e.window,g,I,e.pending),e.pending+=I}function aCe(e,g,I,i){var n=g*2,C=I*2;return e[n]>1;r>=1;r--)UD(e,I,r);s=C;do r=e.heap[1],e.heap[1]=e.heap[e.heap_len--],UD(e,I,1),o=e.heap[1],e.heap[--e.heap_max]=r,e.heap[--e.heap_max]=o,I[s*2]=I[r*2]+I[o*2],e.depth[s]=(e.depth[r]>=e.depth[o]?e.depth[r]:e.depth[o])+1,I[r*2+1]=I[o*2+1]=s,e.heap[1]=s++,UD(e,I,1);while(e.heap_len>=2);e.heap[--e.heap_max]=e.heap[1],RWt(e,g),$we(I,A,e.bl_count)}function lCe(e,g,I){var i,n=-1,C,r=g[0*2+1],o=0,A=7,s=4;for(r===0&&(A=138,s=3),g[(I+1)*2+1]=65535,i=0;i<=I;i++)C=r,r=g[(i+1)*2+1],!(++o=3&&e.bl_tree[Owe[g]*2+1]===0;g--);return e.opt_len+=3*(g+1)+5+5+4,g}function TWt(e,g,I,i){var n;for(XC(e,g-257,5),XC(e,I-1,5),XC(e,i-4,4),n=0;n>>=1)if(g&1&&e.dyn_ltree[I*2]!==0)return oCe;if(e.dyn_ltree[9*2]!==0||e.dyn_ltree[10*2]!==0||e.dyn_ltree[13*2]!==0)return ACe;for(I=32;I<_S;I++)if(e.dyn_ltree[I*2]!==0)return ACe;return oCe}var uCe=!1;function kWt(e){uCe||(WWt(),uCe=!0),e.l_desc=new LD(e.dyn_ltree,_we),e.d_desc=new LD(e.dyn_dtree,Lwe),e.bl_desc=new LD(e.bl_tree,Uwe),e.bi_buf=0,e.bi_valid=0,qwe(e)}function tVe(e,g,I,i){XC(e,(yWt<<1)+(i?1:0),3),XWt(e,g,I,!0)}function YWt(e){XC(e,Ewe<<1,3),MA(e,aj,ja),VWt(e)}function KWt(e,g,I,i){var n,C,r=0;e.level>0?(e.strm.data_type===bWt&&(e.strm.data_type=NWt(e)),bz(e,e.l_desc),bz(e,e.d_desc),r=HWt(e),n=e.opt_len+3+7>>>3,C=e.static_len+3+7>>>3,C<=n&&(n=C)):n=C=I+5,I+4<=n&&g!==-1?tVe(e,g,I,i):e.strategy===pWt||C===n?(XC(e,(Ewe<<1)+(i?1:0),3),sCe(e,ja,UG)):(XC(e,(ZWt<<1)+(i?1:0),3),TWt(e,e.l_desc.max_code+1,e.d_desc.max_code+1,r+1),sCe(e,e.dyn_ltree,e.dyn_dtree)),qwe(e),i&&eVe(e)}function DWt(e,g,I){return e.pending_buf[e.d_buf+e.last_lit*2]=g>>>8&255,e.pending_buf[e.d_buf+e.last_lit*2+1]=g&255,e.pending_buf[e.l_buf+e.last_lit]=I&255,e.last_lit++,g===0?e.dyn_ltree[I*2]++:(e.matches++,g--,e.dyn_ltree[(RB[I]+_S+1)*2]++,e.dyn_dtree[Qwe(g)*2]++),e.last_lit===e.lit_bufsize-1}z0._tr_init=kWt;z0._tr_stored_block=tVe;z0._tr_flush_block=KWt;z0._tr_tally=DWt;z0._tr_align=YWt;function xWt(e,g,I,i){for(var n=e&65535|0,C=e>>>16&65535|0,r=0;I!==0;){r=I>2e3?2e3:I,I-=r;do n=n+g[i++]|0,C=C+n|0;while(--r);n%=65521,C%=65521}return n|C<<16|0}var gVe=xWt;function FWt(){for(var e,g=[],I=0;I<256;I++){e=I;for(var i=0;i<8;i++)e=e&1?3988292384^e>>>1:e>>>1;g[I]=e}return g}var EWt=FWt();function MWt(e,g,I,i){var n=EWt,C=i+I;e^=-1;for(var r=i;r>>8^n[(e^g[r])&255];return e^-1}var IVe=MWt,lj={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"},_n=tl,Qr=z0,iVe=gVe,wl=IVe,zWt=lj,nm=0,PWt=1,JWt=3,Sc=4,dCe=5,zA=0,hCe=1,jr=-2,OWt=-3,QD=-5,_Wt=-1,LWt=1,CR=2,UWt=3,QWt=4,jWt=0,$Wt=2,ek=8,qWt=9,eXt=15,tXt=8,gXt=29,IXt=256,yz=IXt+1+gXt,iXt=30,nXt=19,CXt=2*yz+1,rXt=15,Zg=3,ac=258,IA=ac+Zg+1,oXt=32,tk=42,Zz=69,K1=73,D1=91,x1=103,gd=113,kZ=666,Ri=1,LS=2,rh=3,J0=4,AXt=3;function sc(e,g){return e.msg=zWt[g],g}function mCe(e){return(e<<1)-(e>4?9:0)}function Jl(e){for(var g=e.length;--g>=0;)e[g]=0}function Vl(e){var g=e.state,I=g.pending;I>e.avail_out&&(I=e.avail_out),I!==0&&(_n.arraySet(e.output,g.pending_buf,g.pending_out,I,e.next_out),e.next_out+=I,g.pending_out+=I,e.total_out+=I,e.avail_out-=I,g.pending-=I,g.pending===0&&(g.pending_out=0))}function An(e,g){Qr._tr_flush_block(e,e.block_start>=0?e.block_start:-1,e.strstart-e.block_start,g),e.block_start=e.strstart,Vl(e.strm)}function Xg(e,g){e.pending_buf[e.pending++]=g}function qy(e,g){e.pending_buf[e.pending++]=g>>>8&255,e.pending_buf[e.pending++]=g&255}function aXt(e,g,I,i){var n=e.avail_in;return n>i&&(n=i),n===0?0:(e.avail_in-=n,_n.arraySet(g,e.input,e.next_in,n,I),e.state.wrap===1?e.adler=iVe(e.adler,g,n,I):e.state.wrap===2&&(e.adler=wl(e.adler,g,n,I)),e.next_in+=n,e.total_in+=n,n)}function nVe(e,g){var I=e.max_chain_length,i=e.strstart,n,C,r=e.prev_length,o=e.nice_match,A=e.strstart>e.w_size-IA?e.strstart-(e.w_size-IA):0,s=e.window,a=e.w_mask,l=e.prev,c=e.strstart+ac,u=s[i+r-1],d=s[i+r];e.prev_length>=e.good_match&&(I>>=2),o>e.lookahead&&(o=e.lookahead);do if(n=g,!(s[n+r]!==d||s[n+r-1]!==u||s[n]!==s[i]||s[++n]!==s[i+1])){i+=2,n++;do;while(s[++i]===s[++n]&&s[++i]===s[++n]&&s[++i]===s[++n]&&s[++i]===s[++n]&&s[++i]===s[++n]&&s[++i]===s[++n]&&s[++i]===s[++n]&&s[++i]===s[++n]&&ir){if(e.match_start=g,r=C,C>=o)break;u=s[i+r-1],d=s[i+r]}}while((g=l[g&a])>A&&--I!==0);return r<=e.lookahead?r:e.lookahead}function oh(e){var g=e.w_size,I,i,n,C,r;do{if(C=e.window_size-e.lookahead-e.strstart,e.strstart>=g+(g-IA)){_n.arraySet(e.window,e.window,g,g,0),e.match_start-=g,e.strstart-=g,e.block_start-=g,i=e.hash_size,I=i;do n=e.head[--I],e.head[I]=n>=g?n-g:0;while(--i);i=g,I=i;do n=e.prev[--I],e.prev[I]=n>=g?n-g:0;while(--i);C+=g}if(e.strm.avail_in===0)break;if(i=aXt(e.strm,e.window,e.strstart+e.lookahead,C),e.lookahead+=i,e.lookahead+e.insert>=Zg)for(r=e.strstart-e.insert,e.ins_h=e.window[r],e.ins_h=(e.ins_h<e.pending_buf_size-5&&(I=e.pending_buf_size-5);;){if(e.lookahead<=1){if(oh(e),e.lookahead===0&&g===nm)return Ri;if(e.lookahead===0)break}e.strstart+=e.lookahead,e.lookahead=0;var i=e.block_start+I;if((e.strstart===0||e.strstart>=i)&&(e.lookahead=e.strstart-i,e.strstart=i,An(e,!1),e.strm.avail_out===0)||e.strstart-e.block_start>=e.w_size-IA&&(An(e,!1),e.strm.avail_out===0))return Ri}return e.insert=0,g===Sc?(An(e,!0),e.strm.avail_out===0?rh:J0):(e.strstart>e.block_start&&(An(e,!1),e.strm.avail_out===0),Ri)}function jD(e,g){for(var I,i;;){if(e.lookahead=Zg&&(e.ins_h=(e.ins_h<=Zg)if(i=Qr._tr_tally(e,e.strstart-e.match_start,e.match_length-Zg),e.lookahead-=e.match_length,e.match_length<=e.max_lazy_match&&e.lookahead>=Zg){e.match_length--;do e.strstart++,e.ins_h=(e.ins_h<=Zg&&(e.ins_h=(e.ins_h<4096)&&(e.match_length=Zg-1)),e.prev_length>=Zg&&e.match_length<=e.prev_length){n=e.strstart+e.lookahead-Zg,i=Qr._tr_tally(e,e.strstart-1-e.prev_match,e.prev_length-Zg),e.lookahead-=e.prev_length-1,e.prev_length-=2;do++e.strstart<=n&&(e.ins_h=(e.ins_h<=Zg&&e.strstart>0&&(n=e.strstart-1,i=r[n],i===r[++n]&&i===r[++n]&&i===r[++n])){C=e.strstart+ac;do;while(i===r[++n]&&i===r[++n]&&i===r[++n]&&i===r[++n]&&i===r[++n]&&i===r[++n]&&i===r[++n]&&i===r[++n]&&ne.lookahead&&(e.match_length=e.lookahead)}if(e.match_length>=Zg?(I=Qr._tr_tally(e,1,e.match_length-Zg),e.lookahead-=e.match_length,e.strstart+=e.match_length,e.match_length=0):(I=Qr._tr_tally(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++),I&&(An(e,!1),e.strm.avail_out===0))return Ri}return e.insert=0,g===Sc?(An(e,!0),e.strm.avail_out===0?rh:J0):e.last_lit&&(An(e,!1),e.strm.avail_out===0)?Ri:LS}function cXt(e,g){for(var I;;){if(e.lookahead===0&&(oh(e),e.lookahead===0)){if(g===nm)return Ri;break}if(e.match_length=0,I=Qr._tr_tally(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++,I&&(An(e,!1),e.strm.avail_out===0))return Ri}return e.insert=0,g===Sc?(An(e,!0),e.strm.avail_out===0?rh:J0):e.last_lit&&(An(e,!1),e.strm.avail_out===0)?Ri:LS}function BA(e,g,I,i,n){this.good_length=e,this.max_lazy=g,this.nice_length=I,this.max_chain=i,this.func=n}var ep;ep=[new BA(0,0,0,0,sXt),new BA(4,4,8,4,jD),new BA(4,5,16,8,jD),new BA(4,6,32,32,jD),new BA(4,4,16,16,Em),new BA(8,16,32,32,Em),new BA(8,16,128,128,Em),new BA(8,32,128,256,Em),new BA(32,128,258,1024,Em),new BA(32,258,258,4096,Em)];function uXt(e){e.window_size=2*e.w_size,Jl(e.head),e.max_lazy_match=ep[e.level].max_lazy,e.good_match=ep[e.level].good_length,e.nice_match=ep[e.level].nice_length,e.max_chain_length=ep[e.level].max_chain,e.strstart=0,e.block_start=0,e.lookahead=0,e.insert=0,e.match_length=e.prev_length=Zg-1,e.match_available=0,e.ins_h=0}function dXt(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=ek,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new _n.Buf16(CXt*2),this.dyn_dtree=new _n.Buf16((2*iXt+1)*2),this.bl_tree=new _n.Buf16((2*nXt+1)*2),Jl(this.dyn_ltree),Jl(this.dyn_dtree),Jl(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new _n.Buf16(rXt+1),this.heap=new _n.Buf16(2*yz+1),Jl(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new _n.Buf16(2*yz+1),Jl(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}function CVe(e){var g;return!e||!e.state?sc(e,jr):(e.total_in=e.total_out=0,e.data_type=$Wt,g=e.state,g.pending=0,g.pending_out=0,g.wrap<0&&(g.wrap=-g.wrap),g.status=g.wrap?tk:gd,e.adler=g.wrap===2?0:1,g.last_flush=nm,Qr._tr_init(g),zA)}function rVe(e){var g=CVe(e);return g===zA&&uXt(e.state),g}function hXt(e,g){return!e||!e.state||e.state.wrap!==2?jr:(e.state.gzhead=g,zA)}function oVe(e,g,I,i,n,C){if(!e)return jr;var r=1;if(g===_Wt&&(g=6),i<0?(r=0,i=-i):i>15&&(r=2,i-=16),n<1||n>qWt||I!==ek||i<8||i>15||g<0||g>9||C<0||C>QWt)return sc(e,jr);i===8&&(i=9);var o=new dXt;return e.state=o,o.strm=e,o.wrap=r,o.gzhead=null,o.w_bits=i,o.w_size=1<dCe||g<0)return e?sc(e,jr):jr;if(i=e.state,!e.output||!e.input&&e.avail_in!==0||i.status===kZ&&g!==Sc)return sc(e,e.avail_out===0?QD:jr);if(i.strm=e,I=i.last_flush,i.last_flush=g,i.status===tk)if(i.wrap===2)e.adler=0,Xg(i,31),Xg(i,139),Xg(i,8),i.gzhead?(Xg(i,(i.gzhead.text?1:0)+(i.gzhead.hcrc?2:0)+(i.gzhead.extra?4:0)+(i.gzhead.name?8:0)+(i.gzhead.comment?16:0)),Xg(i,i.gzhead.time&255),Xg(i,i.gzhead.time>>8&255),Xg(i,i.gzhead.time>>16&255),Xg(i,i.gzhead.time>>24&255),Xg(i,i.level===9?2:i.strategy>=CR||i.level<2?4:0),Xg(i,i.gzhead.os&255),i.gzhead.extra&&i.gzhead.extra.length&&(Xg(i,i.gzhead.extra.length&255),Xg(i,i.gzhead.extra.length>>8&255)),i.gzhead.hcrc&&(e.adler=wl(e.adler,i.pending_buf,i.pending,0)),i.gzindex=0,i.status=Zz):(Xg(i,0),Xg(i,0),Xg(i,0),Xg(i,0),Xg(i,0),Xg(i,i.level===9?2:i.strategy>=CR||i.level<2?4:0),Xg(i,AXt),i.status=gd);else{var r=ek+(i.w_bits-8<<4)<<8,o=-1;i.strategy>=CR||i.level<2?o=0:i.level<6?o=1:i.level===6?o=2:o=3,r|=o<<6,i.strstart!==0&&(r|=oXt),r+=31-r%31,i.status=gd,qy(i,r),i.strstart!==0&&(qy(i,e.adler>>>16),qy(i,e.adler&65535)),e.adler=1}if(i.status===Zz)if(i.gzhead.extra){for(n=i.pending;i.gzindex<(i.gzhead.extra.length&65535)&&!(i.pending===i.pending_buf_size&&(i.gzhead.hcrc&&i.pending>n&&(e.adler=wl(e.adler,i.pending_buf,i.pending-n,n)),Vl(e),n=i.pending,i.pending===i.pending_buf_size));)Xg(i,i.gzhead.extra[i.gzindex]&255),i.gzindex++;i.gzhead.hcrc&&i.pending>n&&(e.adler=wl(e.adler,i.pending_buf,i.pending-n,n)),i.gzindex===i.gzhead.extra.length&&(i.gzindex=0,i.status=K1)}else i.status=K1;if(i.status===K1)if(i.gzhead.name){n=i.pending;do{if(i.pending===i.pending_buf_size&&(i.gzhead.hcrc&&i.pending>n&&(e.adler=wl(e.adler,i.pending_buf,i.pending-n,n)),Vl(e),n=i.pending,i.pending===i.pending_buf_size)){C=1;break}i.gzindexn&&(e.adler=wl(e.adler,i.pending_buf,i.pending-n,n)),C===0&&(i.gzindex=0,i.status=D1)}else i.status=D1;if(i.status===D1)if(i.gzhead.comment){n=i.pending;do{if(i.pending===i.pending_buf_size&&(i.gzhead.hcrc&&i.pending>n&&(e.adler=wl(e.adler,i.pending_buf,i.pending-n,n)),Vl(e),n=i.pending,i.pending===i.pending_buf_size)){C=1;break}i.gzindexn&&(e.adler=wl(e.adler,i.pending_buf,i.pending-n,n)),C===0&&(i.status=x1)}else i.status=x1;if(i.status===x1&&(i.gzhead.hcrc?(i.pending+2>i.pending_buf_size&&Vl(e),i.pending+2<=i.pending_buf_size&&(Xg(i,e.adler&255),Xg(i,e.adler>>8&255),e.adler=0,i.status=gd)):i.status=gd),i.pending!==0){if(Vl(e),e.avail_out===0)return i.last_flush=-1,zA}else if(e.avail_in===0&&mCe(g)<=mCe(I)&&g!==Sc)return sc(e,QD);if(i.status===kZ&&e.avail_in!==0)return sc(e,QD);if(e.avail_in!==0||i.lookahead!==0||g!==nm&&i.status!==kZ){var A=i.strategy===CR?cXt(i,g):i.strategy===UWt?lXt(i,g):ep[i.level].func(i,g);if((A===rh||A===J0)&&(i.status=kZ),A===Ri||A===rh)return e.avail_out===0&&(i.last_flush=-1),zA;if(A===LS&&(g===PWt?Qr._tr_align(i):g!==dCe&&(Qr._tr_stored_block(i,0,0,!1),g===JWt&&(Jl(i.head),i.lookahead===0&&(i.strstart=0,i.block_start=0,i.insert=0))),Vl(e),e.avail_out===0))return i.last_flush=-1,zA}return g!==Sc?zA:i.wrap<=0?hCe:(i.wrap===2?(Xg(i,e.adler&255),Xg(i,e.adler>>8&255),Xg(i,e.adler>>16&255),Xg(i,e.adler>>24&255),Xg(i,e.total_in&255),Xg(i,e.total_in>>8&255),Xg(i,e.total_in>>16&255),Xg(i,e.total_in>>24&255)):(qy(i,e.adler>>>16),qy(i,e.adler&65535)),Vl(e),i.wrap>0&&(i.wrap=-i.wrap),i.pending!==0?zA:hCe)}function pXt(e){var g;return!e||!e.state?jr:(g=e.state.status,g!==tk&&g!==Zz&&g!==K1&&g!==D1&&g!==x1&&g!==gd&&g!==kZ?sc(e,jr):(e.state=null,g===gd?sc(e,OWt):zA))}function bXt(e,g){var I=g.length,i,n,C,r,o,A,s,a;if(!e||!e.state||(i=e.state,r=i.wrap,r===2||r===1&&i.status!==tk||i.lookahead))return jr;for(r===1&&(e.adler=iVe(e.adler,g,I,0)),i.wrap=0,I>=i.w_size&&(r===0&&(Jl(i.head),i.strstart=0,i.block_start=0,i.insert=0),a=new _n.Buf8(i.w_size),_n.arraySet(a,g,I-i.w_size,i.w_size,0),g=a,I=i.w_size),o=e.avail_in,A=e.next_in,s=e.input,e.avail_in=I,e.next_in=0,e.input=g,oh(i);i.lookahead>=Zg;){n=i.strstart,C=i.lookahead-(Zg-1);do i.ins_h=(i.ins_h<=252?6:hl>=248?5:hl>=240?4:hl>=224?3:hl>=192?2:1;XB[254]=XB[254]=1;Cm.string2buf=function(e){var g,I,i,n,C,r=e.length,o=0;for(n=0;n>>6,g[C++]=128|I&63):I<65536?(g[C++]=224|I>>>12,g[C++]=128|I>>>6&63,g[C++]=128|I&63):(g[C++]=240|I>>>18,g[C++]=128|I>>>12&63,g[C++]=128|I>>>6&63,g[C++]=128|I&63);return g};function sVe(e,g){if(g<65534&&(e.subarray&&aVe||!e.subarray&&AVe))return String.fromCharCode.apply(null,gk.shrinkBuf(e,g));for(var I="",i=0;i4){o[i++]=65533,I+=C-1;continue}for(n&=C===2?31:C===3?15:7;C>1&&I1){o[i++]=65533;continue}n<65536?o[i++]=n:(n-=65536,o[i++]=55296|n>>10&1023,o[i++]=56320|n&1023)}return sVe(o,i)};Cm.utf8border=function(e,g){var I;for(g=g||e.length,g>e.length&&(g=e.length),I=g-1;I>=0&&(e[I]&192)===128;)I--;return I<0||I===0?g:I+XB[e[I]]>g?I:g};function yXt(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0}var lVe=yXt,QG=wa,jG=tl,Gz=Cm,vz=lj,ZXt=lVe,cVe=Object.prototype.toString,GXt=0,$D=4,Xp=0,fCe=1,pCe=2,vXt=-1,BXt=0,SXt=8;function Ah(e){if(!(this instanceof Ah))return new Ah(e);this.options=jG.assign({level:vXt,method:SXt,chunkSize:16384,windowBits:15,memLevel:8,strategy:BXt,to:""},e||{});var g=this.options;g.raw&&g.windowBits>0?g.windowBits=-g.windowBits:g.gzip&&g.windowBits>0&&g.windowBits<16&&(g.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new ZXt,this.strm.avail_out=0;var I=QG.deflateInit2(this.strm,g.level,g.method,g.windowBits,g.memLevel,g.strategy);if(I!==Xp)throw new Error(vz[I]);if(g.header&&QG.deflateSetHeader(this.strm,g.header),g.dictionary){var i;if(typeof g.dictionary=="string"?i=Gz.string2buf(g.dictionary):cVe.call(g.dictionary)==="[object ArrayBuffer]"?i=new Uint8Array(g.dictionary):i=g.dictionary,I=QG.deflateSetDictionary(this.strm,i),I!==Xp)throw new Error(vz[I]);this._dict_set=!0}}Ah.prototype.push=function(e,g){var I=this.strm,i=this.options.chunkSize,n,C;if(this.ended)return!1;C=g===~~g?g:g===!0?$D:GXt,typeof e=="string"?I.input=Gz.string2buf(e):cVe.call(e)==="[object ArrayBuffer]"?I.input=new Uint8Array(e):I.input=e,I.next_in=0,I.avail_in=I.input.length;do{if(I.avail_out===0&&(I.output=new jG.Buf8(i),I.next_out=0,I.avail_out=i),n=QG.deflate(I,C),n!==fCe&&n!==Xp)return this.onEnd(n),this.ended=!0,!1;(I.avail_out===0||I.avail_in===0&&(C===$D||C===pCe))&&(this.options.to==="string"?this.onData(Gz.buf2binstring(jG.shrinkBuf(I.output,I.next_out))):this.onData(jG.shrinkBuf(I.output,I.next_out)))}while((I.avail_in>0||I.avail_out===0)&&n!==fCe);return C===$D?(n=QG.deflateEnd(this.strm),this.onEnd(n),this.ended=!0,n===Xp):(C===pCe&&(this.onEnd(Xp),I.avail_out=0),!0)};Ah.prototype.onData=function(e){this.chunks.push(e)};Ah.prototype.onEnd=function(e){e===Xp&&(this.options.to==="string"?this.result=this.chunks.join(""):this.result=jG.flattenChunks(this.chunks)),this.chunks=[],this.err=e,this.msg=this.strm.msg};function cj(e,g){var I=new Ah(g);if(I.push(e,!0),I.err)throw I.msg||vz[I.err];return I.result}function wXt(e,g){return g=g||{},g.raw=!0,cj(e,g)}function VXt(e,g){return g=g||{},g.gzip=!0,cj(e,g)}OS.Deflate=Ah;OS.deflate=cj;OS.deflateRaw=wXt;OS.gzip=VXt;var US={},mA={},rR=30,RXt=12,WXt=function(g,I){var i,n,C,r,o,A,s,a,l,c,u,d,h,m,f,b,p,y,Z,B,G,v,w,V,S;i=g.state,n=g.next_in,V=g.input,C=n+(g.avail_in-5),r=g.next_out,S=g.output,o=r-(I-g.avail_out),A=r+(g.avail_out-257),s=i.dmax,a=i.wsize,l=i.whave,c=i.wnext,u=i.window,d=i.hold,h=i.bits,m=i.lencode,f=i.distcode,b=(1<>>24,d>>>=Z,h-=Z,Z=y>>>16&255,Z===0)S[r++]=y&65535;else if(Z&16){B=y&65535,Z&=15,Z&&(h>>=Z,h-=Z),h<15&&(d+=V[n++]<>>24,d>>>=Z,h-=Z,Z=y>>>16&255,Z&16){if(G=y&65535,Z&=15,hs){g.msg="invalid distance too far back",i.mode=rR;break e}if(d>>>=Z,h-=Z,Z=r-o,G>Z){if(Z=G-Z,Z>l&&i.sane){g.msg="invalid distance too far back",i.mode=rR;break e}if(v=0,w=u,c===0){if(v+=a-Z,Z2;)S[r++]=w[v++],S[r++]=w[v++],S[r++]=w[v++],B-=3;B&&(S[r++]=w[v++],B>1&&(S[r++]=w[v++]))}else{v=r-G;do S[r++]=S[v++],S[r++]=S[v++],S[r++]=S[v++],B-=3;while(B>2);B&&(S[r++]=S[v++],B>1&&(S[r++]=S[v++]))}}else if(Z&64){g.msg="invalid distance code",i.mode=rR;break e}else{y=f[(y&65535)+(d&(1<>3,n-=B,h-=B<<3,d&=(1<=1&&X[u]===0;u--);if(d>u&&(d=u),u===0)return C[r++]=1<<24|64<<16|0,C[r++]=1<<24|64<<16|0,A.bits=1,0;for(c=1;c0&&(g===GCe||u!==1))return-1;for(W[1]=0,a=1;ayCe||g===vCe&&b>ZCe)return 1;for(;;){Y=a-m,o[l]S?(D=R[H+o[l]],E=w[V+o[l]]):(D=32+64,E=0),y=1<>m)+Z]=Y<<24|D<<16|E|0;while(Z!==0);for(y=1<>=1;if(y!==0?(p&=y-1,p+=y):p=0,l++,--X[a]===0){if(a===u)break;a=I[i+o[l]]}if(a>d&&(p&G)!==B){for(m===0&&(m=d),v+=c,h=a-m,f=1<yCe||g===vCe&&b>ZCe)return 1;B=p&G,C[B]=d<<24|h<<16|v-r|0}}return p!==0&&(C[v+p]=a-m<<24|64<<16|0),A.bits=d,0},rr=tl,Bz=gVe,SA=IVe,YXt=WXt,$G=kXt,KXt=0,uVe=1,dVe=2,BCe=4,DXt=5,oR=6,ah=0,xXt=1,FXt=2,Io=-2,hVe=-3,mVe=-4,EXt=-5,SCe=8,fVe=1,wCe=2,VCe=3,RCe=4,WCe=5,XCe=6,HCe=7,TCe=8,NCe=9,kCe=10,R9=11,Ka=12,ex=13,YCe=14,tx=15,KCe=16,DCe=17,xCe=18,FCe=19,AR=20,aR=21,ECe=22,MCe=23,zCe=24,PCe=25,JCe=26,gx=27,OCe=28,_Ce=29,ZI=30,pVe=31,MXt=32,zXt=852,PXt=592,JXt=15,OXt=JXt;function LCe(e){return(e>>>24&255)+(e>>>8&65280)+((e&65280)<<8)+((e&255)<<24)}function _Xt(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new rr.Buf16(320),this.work=new rr.Buf16(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}function bVe(e){var g;return!e||!e.state?Io:(g=e.state,e.total_in=e.total_out=g.total=0,e.msg="",g.wrap&&(e.adler=g.wrap&1),g.mode=fVe,g.last=0,g.havedict=0,g.dmax=32768,g.head=null,g.hold=0,g.bits=0,g.lencode=g.lendyn=new rr.Buf32(zXt),g.distcode=g.distdyn=new rr.Buf32(PXt),g.sane=1,g.back=-1,ah)}function yVe(e){var g;return!e||!e.state?Io:(g=e.state,g.wsize=0,g.whave=0,g.wnext=0,bVe(e))}function ZVe(e,g){var I,i;return!e||!e.state||(i=e.state,g<0?(I=0,g=-g):(I=(g>>4)+1,g<48&&(g&=15)),g&&(g<8||g>15))?Io:(i.window!==null&&i.wbits!==g&&(i.window=null),i.wrap=I,i.wbits=g,yVe(e))}function GVe(e,g){var I,i;return e?(i=new _Xt,e.state=i,i.window=null,I=ZVe(e,g),I!==ah&&(e.state=null),I):Io}function LXt(e){return GVe(e,OXt)}var UCe=!0,Ix,ix;function UXt(e){if(UCe){var g;for(Ix=new rr.Buf32(512),ix=new rr.Buf32(32),g=0;g<144;)e.lens[g++]=8;for(;g<256;)e.lens[g++]=9;for(;g<280;)e.lens[g++]=7;for(;g<288;)e.lens[g++]=8;for($G(uVe,e.lens,0,288,Ix,0,e.work,{bits:9}),g=0;g<32;)e.lens[g++]=5;$G(dVe,e.lens,0,32,ix,0,e.work,{bits:5}),UCe=!1}e.lencode=Ix,e.lenbits=9,e.distcode=ix,e.distbits=5}function vVe(e,g,I,i){var n,C=e.state;return C.window===null&&(C.wsize=1<=C.wsize?(rr.arraySet(C.window,g,I-C.wsize,C.wsize,0),C.wnext=0,C.whave=C.wsize):(n=C.wsize-C.wnext,n>i&&(n=i),rr.arraySet(C.window,g,I-i,n,C.wnext),i-=n,i?(rr.arraySet(C.window,g,I-i,i,0),C.wnext=i,C.whave=C.wsize):(C.wnext+=n,C.wnext===C.wsize&&(C.wnext=0),C.whave>>8&255,I.check=SA(I.check,w,2,0),s=0,a=0,I.mode=wCe;break}if(I.flags=0,I.head&&(I.head.done=!1),!(I.wrap&1)||(((s&255)<<8)+(s>>8))%31){e.msg="incorrect header check",I.mode=ZI;break}if((s&15)!==SCe){e.msg="unknown compression method",I.mode=ZI;break}if(s>>>=4,a-=4,G=(s&15)+8,I.wbits===0)I.wbits=G;else if(G>I.wbits){e.msg="invalid window size",I.mode=ZI;break}I.dmax=1<>8&1),I.flags&512&&(w[0]=s&255,w[1]=s>>>8&255,I.check=SA(I.check,w,2,0)),s=0,a=0,I.mode=VCe;case VCe:for(;a<32;){if(o===0)break e;o--,s+=i[C++]<>>8&255,w[2]=s>>>16&255,w[3]=s>>>24&255,I.check=SA(I.check,w,4,0)),s=0,a=0,I.mode=RCe;case RCe:for(;a<16;){if(o===0)break e;o--,s+=i[C++]<>8),I.flags&512&&(w[0]=s&255,w[1]=s>>>8&255,I.check=SA(I.check,w,2,0)),s=0,a=0,I.mode=WCe;case WCe:if(I.flags&1024){for(;a<16;){if(o===0)break e;o--,s+=i[C++]<>>8&255,I.check=SA(I.check,w,2,0)),s=0,a=0}else I.head&&(I.head.extra=null);I.mode=XCe;case XCe:if(I.flags&1024&&(u=I.length,u>o&&(u=o),u&&(I.head&&(G=I.head.extra_len-I.length,I.head.extra||(I.head.extra=new Array(I.head.extra_len)),rr.arraySet(I.head.extra,i,C,u,G)),I.flags&512&&(I.check=SA(I.check,i,u,C)),o-=u,C+=u,I.length-=u),I.length))break e;I.length=0,I.mode=HCe;case HCe:if(I.flags&2048){if(o===0)break e;u=0;do G=i[C+u++],I.head&&G&&I.length<65536&&(I.head.name+=String.fromCharCode(G));while(G&&u>9&1,I.head.done=!0),e.adler=I.check=0,I.mode=Ka;break;case kCe:for(;a<32;){if(o===0)break e;o--,s+=i[C++]<>>=a&7,a-=a&7,I.mode=gx;break}for(;a<3;){if(o===0)break e;o--,s+=i[C++]<>>=1,a-=1,s&3){case 0:I.mode=YCe;break;case 1:if(UXt(I),I.mode=AR,g===oR){s>>>=2,a-=2;break e}break;case 2:I.mode=DCe;break;case 3:e.msg="invalid block type",I.mode=ZI}s>>>=2,a-=2;break;case YCe:for(s>>>=a&7,a-=a&7;a<32;){if(o===0)break e;o--,s+=i[C++]<>>16^65535)){e.msg="invalid stored block lengths",I.mode=ZI;break}if(I.length=s&65535,s=0,a=0,I.mode=tx,g===oR)break e;case tx:I.mode=KCe;case KCe:if(u=I.length,u){if(u>o&&(u=o),u>A&&(u=A),u===0)break e;rr.arraySet(n,i,C,u,r),o-=u,C+=u,A-=u,r+=u,I.length-=u;break}I.mode=Ka;break;case DCe:for(;a<14;){if(o===0)break e;o--,s+=i[C++]<>>=5,a-=5,I.ndist=(s&31)+1,s>>>=5,a-=5,I.ncode=(s&15)+4,s>>>=4,a-=4,I.nlen>286||I.ndist>30){e.msg="too many length or distance symbols",I.mode=ZI;break}I.have=0,I.mode=xCe;case xCe:for(;I.have>>=3,a-=3}for(;I.have<19;)I.lens[X[I.have++]]=0;if(I.lencode=I.lendyn,I.lenbits=7,V={bits:I.lenbits},v=$G(KXt,I.lens,0,19,I.lencode,0,I.work,V),I.lenbits=V.bits,v){e.msg="invalid code lengths set",I.mode=ZI;break}I.have=0,I.mode=FCe;case FCe:for(;I.have>>24,b=m>>>16&255,p=m&65535,!(f<=a);){if(o===0)break e;o--,s+=i[C++]<>>=f,a-=f,I.lens[I.have++]=p;else{if(p===16){for(S=f+2;a>>=f,a-=f,I.have===0){e.msg="invalid bit length repeat",I.mode=ZI;break}G=I.lens[I.have-1],u=3+(s&3),s>>>=2,a-=2}else if(p===17){for(S=f+3;a>>=f,a-=f,G=0,u=3+(s&7),s>>>=3,a-=3}else{for(S=f+7;a>>=f,a-=f,G=0,u=11+(s&127),s>>>=7,a-=7}if(I.have+u>I.nlen+I.ndist){e.msg="invalid bit length repeat",I.mode=ZI;break}for(;u--;)I.lens[I.have++]=G}}if(I.mode===ZI)break;if(I.lens[256]===0){e.msg="invalid code -- missing end-of-block",I.mode=ZI;break}if(I.lenbits=9,V={bits:I.lenbits},v=$G(uVe,I.lens,0,I.nlen,I.lencode,0,I.work,V),I.lenbits=V.bits,v){e.msg="invalid literal/lengths set",I.mode=ZI;break}if(I.distbits=6,I.distcode=I.distdyn,V={bits:I.distbits},v=$G(dVe,I.lens,I.nlen,I.ndist,I.distcode,0,I.work,V),I.distbits=V.bits,v){e.msg="invalid distances set",I.mode=ZI;break}if(I.mode=AR,g===oR)break e;case AR:I.mode=aR;case aR:if(o>=6&&A>=258){e.next_out=r,e.avail_out=A,e.next_in=C,e.avail_in=o,I.hold=s,I.bits=a,YXt(e,c),r=e.next_out,n=e.output,A=e.avail_out,C=e.next_in,i=e.input,o=e.avail_in,s=I.hold,a=I.bits,I.mode===Ka&&(I.back=-1);break}for(I.back=0;m=I.lencode[s&(1<>>24,b=m>>>16&255,p=m&65535,!(f<=a);){if(o===0)break e;o--,s+=i[C++]<>y)],f=m>>>24,b=m>>>16&255,p=m&65535,!(y+f<=a);){if(o===0)break e;o--,s+=i[C++]<>>=y,a-=y,I.back+=y}if(s>>>=f,a-=f,I.back+=f,I.length=p,b===0){I.mode=JCe;break}if(b&32){I.back=-1,I.mode=Ka;break}if(b&64){e.msg="invalid literal/length code",I.mode=ZI;break}I.extra=b&15,I.mode=ECe;case ECe:if(I.extra){for(S=I.extra;a>>=I.extra,a-=I.extra,I.back+=I.extra}I.was=I.length,I.mode=MCe;case MCe:for(;m=I.distcode[s&(1<>>24,b=m>>>16&255,p=m&65535,!(f<=a);){if(o===0)break e;o--,s+=i[C++]<>y)],f=m>>>24,b=m>>>16&255,p=m&65535,!(y+f<=a);){if(o===0)break e;o--,s+=i[C++]<>>=y,a-=y,I.back+=y}if(s>>>=f,a-=f,I.back+=f,b&64){e.msg="invalid distance code",I.mode=ZI;break}I.offset=p,I.extra=b&15,I.mode=zCe;case zCe:if(I.extra){for(S=I.extra;a>>=I.extra,a-=I.extra,I.back+=I.extra}if(I.offset>I.dmax){e.msg="invalid distance too far back",I.mode=ZI;break}I.mode=PCe;case PCe:if(A===0)break e;if(u=c-A,I.offset>u){if(u=I.offset-u,u>I.whave&&I.sane){e.msg="invalid distance too far back",I.mode=ZI;break}u>I.wnext?(u-=I.wnext,d=I.wsize-u):d=I.wnext-u,u>I.length&&(u=I.length),h=I.window}else h=n,d=r-I.offset,u=I.length;u>A&&(u=A),A-=u,I.length-=u;do n[r++]=h[d++];while(--u);I.length===0&&(I.mode=aR);break;case JCe:if(A===0)break e;n[r++]=I.length,A--,I.mode=aR;break;case gx:if(I.wrap){for(;a<32;){if(o===0)break e;o--,s|=i[C++]<=0&&g.windowBits<16&&(g.windowBits=-g.windowBits,g.windowBits===0&&(g.windowBits=-15)),g.windowBits>=0&&g.windowBits<16&&!(e&&e.windowBits)&&(g.windowBits+=32),g.windowBits>15&&g.windowBits<48&&(g.windowBits&15||(g.windowBits|=15)),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new g9t,this.strm.avail_out=0;var I=Hp.inflateInit2(this.strm,g.windowBits);if(I!==gi.Z_OK)throw new Error(Sz[I]);if(this.header=new I9t,Hp.inflateGetHeader(this.strm,this.header),g.dictionary&&(typeof g.dictionary=="string"?g.dictionary=F1.string2buf(g.dictionary):SVe.call(g.dictionary)==="[object ArrayBuffer]"&&(g.dictionary=new Uint8Array(g.dictionary)),g.raw&&(I=Hp.inflateSetDictionary(this.strm,g.dictionary),I!==gi.Z_OK)))throw new Error(Sz[I])}sh.prototype.push=function(e,g){var I=this.strm,i=this.options.chunkSize,n=this.options.dictionary,C,r,o,A,s,a=!1;if(this.ended)return!1;r=g===~~g?g:g===!0?gi.Z_FINISH:gi.Z_NO_FLUSH,typeof e=="string"?I.input=F1.binstring2buf(e):SVe.call(e)==="[object ArrayBuffer]"?I.input=new Uint8Array(e):I.input=e,I.next_in=0,I.avail_in=I.input.length;do{if(I.avail_out===0&&(I.output=new qG.Buf8(i),I.next_out=0,I.avail_out=i),C=Hp.inflate(I,gi.Z_NO_FLUSH),C===gi.Z_NEED_DICT&&n&&(C=Hp.inflateSetDictionary(this.strm,n)),C===gi.Z_BUF_ERROR&&a===!0&&(C=gi.Z_OK,a=!1),C!==gi.Z_STREAM_END&&C!==gi.Z_OK)return this.onEnd(C),this.ended=!0,!1;I.next_out&&(I.avail_out===0||C===gi.Z_STREAM_END||I.avail_in===0&&(r===gi.Z_FINISH||r===gi.Z_SYNC_FLUSH))&&(this.options.to==="string"?(o=F1.utf8border(I.output,I.next_out),A=I.next_out-o,s=F1.buf2string(I.output,o),I.next_out=A,I.avail_out=i-A,A&&qG.arraySet(I.output,I.output,o,A,0),this.onData(s)):this.onData(qG.shrinkBuf(I.output,I.next_out))),I.avail_in===0&&I.avail_out===0&&(a=!0)}while((I.avail_in>0||I.avail_out===0)&&C!==gi.Z_STREAM_END);return C===gi.Z_STREAM_END&&(r=gi.Z_FINISH),r===gi.Z_FINISH?(C=Hp.inflateEnd(this.strm),this.onEnd(C),this.ended=!0,C===gi.Z_OK):(r===gi.Z_SYNC_FLUSH&&(this.onEnd(gi.Z_OK),I.avail_out=0),!0)};sh.prototype.onData=function(e){this.chunks.push(e)};sh.prototype.onEnd=function(e){e===gi.Z_OK&&(this.options.to==="string"?this.result=this.chunks.join(""):this.result=qG.flattenChunks(this.chunks)),this.chunks=[],this.err=e,this.msg=this.strm.msg};function uj(e,g){var I=new sh(g);if(I.push(e,!0),I.err)throw I.msg||Sz[I.err];return I.result}function i9t(e,g){return g=g||{},g.raw=!0,uj(e,g)}US.Inflate=sh;US.inflate=uj;US.inflateRaw=i9t;US.ungzip=uj;var n9t=tl.assign,C9t=OS,r9t=US,o9t=BVe,wVe={};n9t(wVe,C9t,r9t,o9t);var A9t=wVe;const a9t=DC(A9t);var s9t=["JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC"];const l9t=s9t;function c9t(e){if(typeof e!="string")throw new TypeError("input must be a string");let g=[],I,i,n={LOCUS_TAG:"LOCUS",DEFINITION_TAG:"DEFINITION",ACCESSION_TAG:"ACCESSION",VERSION_TAG:"VERSION",KEYWORDS_TAG:"KEYWORDS",SOURCE_TAG:"SOURCE",ORGANISM_TAG:"ORGANISM",REFERENCE_TAG:"REFERENCE",AUTHORS_TAG:"AUTHORS",CONSORTIUM_TAG:"CONSRTM",TITLE_TAG:"TITLE",JOURNAL_TAG:"JOURNAL",PUBMED_TAG:"PUBMED",REMARK_TAG:"REMARK",FEATURES_TAG:"FEATURES",BASE_COUNT_TAG:"BASE COUNT",ORIGIN_TAG:"ORIGIN",END_SEQUENCE_TAG:"//"},C=e.split(/\r?\n/),r,o,A,s,a,l=!1;for(let R of C){if(R===null)break;let H=v(R),Y=V(R),D=X(R),E=S(R);if(H===n.END_SEQUENCE_TAG||E?(r=H,o=null):D&&(o=H),!(R.trim()===""||H===";")){if(!l&&r!==n.LOCUS_TAG)break;switch(r){case n.LOCUS_TAG:l=!0,m(R);break;case n.FEATURES_TAG:p(R,H,Y);break;case n.ORIGIN_TAG:h(R,H);break;case n.DEFINITION_TAG:case n.ACCESSION_TAG:case n.VERSION_TAG:case n.KEYWORDS_TAG:w(r,R,r.toLowerCase());break;case n.SOURCE_TAG:o===n.ORGANISM_TAG?w(o,R,"organism"):w(H,R,"source");break;case n.REFERENCE_TAG:if(H===n.REFERENCE_TAG){const O=I.references||[];I.references=O,O.push({})}b(R,o);break;case n.END_SEQUENCE_TAG:c();break}}}return g[g.length-1]!==I&&c(),g;function c(){d(),g.push(I)}function u(){return I.features[I.features.length-1]}function d(){if(I&&I.features)for(let R=0;R0;g--){const I=Math.floor(Math.random()*(g+1)),i=e[g];e[g]=e[I],e[I]=i}return e}function Z9t(e){return e.type==="filler"}function G9t(e){const g=e.end-e.start,I=e.strand===1?"+":"-",i=Ag.nice();return Z9t(e)?{xStart:e.start,xEnd:e.end,strand:e.strand,fields:[],type:"filler",uid:i}:{xStart:e.start,xEnd:e.end,strand:I,chrOffset:0,importance:e.end-e.start,uid:i,type:e.type,fields:["chrom",e.start,e.end,e.name,g,I,"","",e.type,e.name,e.start.toString(),e.end.toString(),e.start.toString(),e.end.toString()]}}function v9t(e){const g=h9t(e),I=y9t(g[0].features.filter(i=>i.type!=="source").sort((i,n)=>i.start-n.start));return{json:g,features:I}}async function B9t(e,{gzipped:g}){if(!g)return e.text();const I=await e.arrayBuffer();return a9t.inflate(I,{to:"string"})}let RVe=function(){function e(g){m9t(this,e),this.dataConfig=g,this.trackUid=Ag.nice(),this.errorTxt="";let I;if(g.url){const i=g.url.slice(g.url.length-3);I=fetch(g.url,{mode:"cors",redirect:"follow",method:"GET"}).then(n=>B9t(n,{gzipped:i===".gz"}))}else if(g.text)I=Promise.resolve(g.text);else throw new Error("No data or URL specified");this.gbDataPromise=I.then(i=>v9t(i))}return f9t(e,[{key:"tilesetInfo",value:function(I){return this.tilesetInfoLoading=!0,this.gbDataPromise.then(i=>{this.tilesetInfoLoading=!1;const n=1024,C={name:`genbank-${this.trackUid}`,tile_size:n,max_zoom:Math.ceil(Math.log(i.json[0].size/n)/Math.log(2)),max_width:i.json[0].size,min_pos:[0],max_pos:[i.json[0].size]};return I&&I(C),C}).catch(i=>{this.tilesetInfoLoading=!1,I&&I({error:`Error parsing genbank: ${i}`})})}},{key:"fetchTilesDebounced",value:async function(I,i){const n={},C=[],r=[];for(const A of i){const s=A.split("."),a=parseInt(s[0],10),l=parseInt(s[1],10);if(Number.isNaN(l)||Number.isNaN(a)){console.warn("Invalid tile zoom or position:",a,l);continue}C.push(A),r.push(this.tile(a,l))}const o=await Promise.all(r);for(let A=0;Ah.end>o&&h.starth.strand===1),a,"+"),c=jCe(s.filter(h=>h.strand!==1),a,"-"),u=[],d=20;for(let h=0;h=d);h++)C.features[h].end>=o&&C.features[h].start<=A&&u.push(C.features[h]);return[u,l,c].flatMap(h=>h.map(G9t))}}]),e}();function S9t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function $Ce(e,g){for(var I=0;I`localtile.${r}`);O7(this.tilesData,"",C);for(const r of i)n[r]=this.tilesData[`localtile.${r}`];return I(n),n}},{key:"tile",value:function(I,i){}}]),e}();function W9t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function qCe(e,g){for(var I=0;IC.trackId!==n),this.taskList.push({handler:I,data:i,trackId:n})),this.taskHandle||(this.taskHandle=requestIdleCallback(this.runTaskQueue.bind(this),{timeout:this.requestIdleCallbackTimeout}))}},{key:"runTaskQueue",value:function(I){for(;(I.timeRemaining()>0||I.didTimeout)&&this.taskList.length;){const i=this.taskList.shift();i&&N9t(i)?i.handler():i&&i.handler(i.data)}this.taskList.length?this.taskHandle=requestIdleCallback(this.runTaskQueue.bind(this),{timeout:this.requestIdleCallbackTimeout}):this.taskHandle=0}}]),e}();const Y9t=new k9t;function K9t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function ere(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function ss(e){return ss=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},ss(e)}function O9t(e,g,I,i,n){const C=e||n,r=0;return C==="log"&&g>0?["log",Qc().range([254,0]).domain([g+r,i+r])]:["linear",qt().range([254,0]).domain([g,i])]}let rm=function(e){M9t(I,e);var g=z9t(I);function I(i,n){var C;K9t(this,I),C=g.call(this,i,n);const{pubSub:r,dataConfig:o,handleTilesetInfoReceived:A,animate:s,onValueScaleChanged:a}=i;return C.renderVersion=1,C.visibleTiles=new Set,C.visibleTileIds=new Set,C.renderingTiles=new Set,C.fetching=new Set,C.scale={},C.fetchedTiles={},C.tileGraphics={},C.maxZoom=0,C.medianVisibleValue=null,C.backgroundTaskScheduler=Y9t,C.continuousScaling="requestIdleCallback"in window,C.valueScaleMin=null,C.fixedValueScaleMin=null,C.valueScaleMax=null,C.fixedValueScaleMax=null,C.listeners={},C.pubSub=r,C.animate=s,C.onValueScaleChanged=a,C.prevValueScale=null,i.dataFetcher?C.dataFetcher=i.dataFetcher:C.dataFetcher=new qN(o,C.pubSub),C.tilesetInfo=null,C.uuid=Ag.nice(),C.trackNotFoundText=new rt.PIXI.Text("",{fontSize:"12px",fontFamily:"Arial",fill:"black"}),C.pLabel.addChild(C.trackNotFoundText),C.refreshTilesDebounced=jZe(C.refreshTiles.bind(Vz(C)),jX,jX),C.dataFetcher.tilesetInfo((l,c)=>{if(l){if(C.tilesetInfo=l,C.dataFetcher.dataConfig.tilesetUid||(C.dataFetcher.dataConfig.tilesetUid=c),C.tilesetUid=C.dataFetcher.dataConfig.tilesetUid,C.server=C.dataFetcher.dataConfig.server||"unknown",C.tilesetInfo&&C.tilesetInfo.chromsizes&&(C.chromInfo=CN(C.tilesetInfo.chromsizes)),"error"in C.tilesetInfo){console.warn("Error retrieving tilesetInfo:",o,C.tilesetInfo.error),C.tilesetInfo=null,C.setError(C.tilesetInfo.error);return}C.tilesetInfo.resolutions?C.maxZoom=C.tilesetInfo.resolutions.length:C.maxZoom=+C.tilesetInfo.max_zoom,C.options&&C.options.maxZoom&&(C.options.maxZoom>=0?C.maxZoom=Math.min(C.options.maxZoom,C.maxZoom):console.error("Invalid maxZoom on track:",Vz(C))),C.refreshTiles(),A&&A(l),C.options||(C.options={}),C.options.name=C.options.name||l.name,C.checkValueScaleLimits(),C.draw(),C.drawLabel(),C.animate()}}),C}return D9t(I,[{key:"setError",value:function(n){this.errorTextText=n,this.draw(),this.animate()}},{key:"setFixedValueScaleMin",value:function(n){Number.isNaN(+n)?this.fixedValueScaleMin=null:this.fixedValueScaleMin=+n}},{key:"setFixedValueScaleMax",value:function(n){Number.isNaN(+n)?this.fixedValueScaleMax=null:this.fixedValueScaleMax=+n}},{key:"checkValueScaleLimits",value:function(){this.valueScaleMin=typeof this.options.valueScaleMin<"u"?+this.options.valueScaleMin:null,this.fixedValueScaleMin!==null&&(this.valueScaleMin=this.fixedValueScaleMin),this.valueScaleMax=typeof this.options.valueScaleMax<"u"?+this.options.valueScaleMax:null,this.fixedValueScaleMax!==null&&(this.valueScaleMax=this.fixedValueScaleMax)}},{key:"on",value:function(n,C){this.listeners[n]||(this.listeners[n]=[]),this.listeners[n].push(C)}},{key:"off",value:function(n,C){const r=this.listeners[n].indexOf(C);r===-1||r>=this.listeners[n].length||this.listeners[n].splice(r,1)}},{key:"rerender",value:function(n){Id(ss(I.prototype),"rerender",this).call(this,n),this.renderVersion+=1,this.tilesetInfo&&(this.checkValueScaleLimits(),this.tilesetInfo.resolutions?this.maxZoom=this.tilesetInfo.resolutions.length:this.maxZoom=+this.tilesetInfo.max_zoom,this.options&&this.options.maxZoom&&(this.options.maxZoom>=0?this.maxZoom=Math.min(this.options.maxZoom,this.maxZoom):console.error("Invalid maxZoom on track:",this)))}},{key:"visibleAndFetchedIds",value:function(){return Object.keys(this.fetchedTiles).filter(n=>this.visibleTileIds.has(n))}},{key:"visibleAndFetchedTiles",value:function(){return this.visibleAndFetchedIds().map(n=>this.fetchedTiles[n])}},{key:"setVisibleTiles",value:function(n){this.visibleTiles=n.map(C=>({tileId:this.tileToLocalId(C),remoteId:this.tileToRemoteId(C),mirrored:C.mirrored})),this.visibleTileIds=new Set(this.visibleTiles.map(C=>C.tileId))}},{key:"removeOldTiles",value:function(){this.calculateVisibleTiles();const C=[...new Set(Object.keys(this.fetchedTiles))].filter(r=>!this.visibleTileIds.has(r));this.removeTiles(C)}},{key:"refreshTiles",value:function(){if(!this.tilesetInfo)return;this.calculateVisibleTiles();const n=new Set(Object.keys(this.fetchedTiles)),C=[...this.visibleTiles].filter(r=>!this.fetching.has(r.remoteId)&&!n.has(r.tileId));for(let r=0;r0;)if(r-=1,o=o.map(s=>Math.floor(s/2)),`${C}.${r}.${o.join(".")}`in this.fetchedTiles)return!0;return!1}},{key:"parentTileId",value:function(n){const C=n.tileData.zoomLevel-1,r=n.tileData.tilePos.map(A=>Math.floor(A/2));return`${n.tileData.tilesetUid}.${C}.${r.join(".")}`}},{key:"removeTiles",value:function(n){!n.length||!this.areAllVisibleTilesLoaded()||this.renderingTiles.size||(n.forEach(C=>{const r=C;this.destroyTile(this.fetchedTiles[r]),r in this.tileGraphics&&(this.pMain.removeChild(this.tileGraphics[r]),delete this.tileGraphics[r]),delete this.fetchedTiles[r]}),this.synchronizeTilesAndGraphics(),this.draw())}},{key:"zoomed",value:function(n,C,r=1,o=0,A=0){this.xScale(n),this.yScale(C),this.refreshTilesDebounced(),this.pMobile.position.x=o,this.pMobile.position.y=this.position[1],this.pMobile.scale.x=r,this.pMobile.scale.y=1}},{key:"setPosition",value:function(n){Id(ss(I.prototype),"setPosition",this).call(this,n)}},{key:"setDimensions",value:function(n){Id(ss(I.prototype),"setDimensions",this).call(this,n)}},{key:"areAllVisibleTilesLoaded",value:function(){const n=new Set(Object.keys(this.fetchedTiles)),C=[...this.visibleTileIds];for(let r=0;rC.tileData))}},{key:"loadTileData",value:function(n,C){let r=this.lruCache.get(n.tileId);return r||(r=C(n.data,n.type),this.lruCache.put(n.tileId,r)),r}},{key:"fetchNewTiles",value:function(n){if(n.length>0){const C=[...new Set(n.map(r=>r.remoteId))];this.dataFetcher.fetchTilesDebounced(this.receivedTiles.bind(this),C)}}},{key:"receivedTiles",value:function(n){for(let C=0;CNumber.isNaN(+A)).forEach(A=>{this.fetchedTiles[r].tileData[A]=o[A]})}else this.fetchedTiles[r].tileData={...n[this.visibleTiles[C].remoteId]};this.fetchedTiles[r].tileData.error&&console.warn("Error in loaded tile",r,this.fetchedTiles[r].tileData)}}for(const C in n)if(n[C]){const r=n[C].tilePositionId;this.fetching.has(r)&&this.fetching.delete(r)}this.synchronizeTilesAndGraphics(),this.draw(),this.drawLabel(),this.valueScale&&(!this.prevValueScale||JSON.stringify(this.valueScale.domain())!==JSON.stringify(this.prevValueScale.domain()))&&(this.prevValueScale=this.valueScale.copy(),this.onValueScaleChanged&&this.onValueScaleChanged()),this.animate(),this.areAllVisibleTilesLoaded()&&this.pubSub&&this.pubSub.publish("TiledPixiTrack.tilesLoaded",{uuid:this.uuid})}},{key:"draw",value:function(){if(this.delayDrawing)return;this.tilesetInfo?this.trackNotFoundText.visible=!1:(this.dataFetcher.tilesetInfoLoading?this.trackNotFoundText.text="Loading...":this.trackNotFoundText.text=`Tileset info not found. Server: [${this.server}] tilesetUid: [${this.tilesetUid}]`,[this.trackNotFoundText.x,this.trackNotFoundText.y]=this.position,this.flipText&&(this.trackNotFoundText.anchor.x=1,this.trackNotFoundText.scale.x=-1),this.trackNotFoundText.visible=!0),this.pubSub&&this.pubSub.publish("TiledPixiTrack.tilesDrawnStart",{uuid:this.uuid});const n=Object.values(this.fetchedTiles).map(C=>C.tileData&&C.tileData.error&&`${C.tileId}: ${C.tileData.error}`).filter(C=>C);n.length?this.errorTextText=n.join(` +`):this.errorTextText="",Id(ss(I.prototype),"draw",this).call(this),Object.keys(this.fetchedTiles).forEach(C=>{this.drawTile(this.fetchedTiles[C])}),this.pubSub&&this.pubSub.publish("TiledPixiTrack.tilesDrawnEnd",{uuid:this.uuid})}},{key:"drawTile",value:function(){}},{key:"calculateMedianVisibleValue",value:function(){this.areAllVisibleTilesLoaded()&&this.allTilesLoaded();let n=this.visibleAndFetchedIds();n.length===0&&(n=Object.keys(this.fetchedTiles));const C=[].concat(...n.filter(r=>this.fetchedTiles[r].tileData.dense).map(r=>Array.from(this.fetchedTiles[r].tileData.dense))).filter(r=>r>0);return this.medianVisibleValue=FU(C),this.medianVisibleValue}},{key:"allVisibleValues",value:function(){return[].concat(...this.visibleAndFetchedIds().map(n=>Array.from(this.fetchedTiles[n].tileData.dense)))}},{key:"minVisibleValue",value:function(n=!1){return this.minVisibleValueInTiles(n)}},{key:"minVisibleValueInTiles",value:function(n=!1){let C=this.visibleAndFetchedIds();C.length===0&&(C=Object.keys(this.fetchedTiles));let r=Math.min(...C.map(o=>this.fetchedTiles[o].tileData.minNonZero));return r===Number.MAX_SAFE_INTEGER&&(r=null),n?r:this.valueScaleMin!==null?this.valueScaleMin:r}},{key:"maxVisibleValue",value:function(n=!1){return this.maxVisibleValueInTiles(n)}},{key:"maxVisibleValueInTiles",value:function(n=!1){let C=this.visibleAndFetchedIds();C.length===0&&(C=Object.keys(this.fetchedTiles));let r=Math.max(...C.map(o=>this.fetchedTiles[o].tileData.maxNonZero));return r===Number.MIN_SAFE_INTEGER&&(r=null),n?r:this.valueScaleMax!==null?this.valueScaleMax:r}},{key:"makeValueScale",value:function(n,C,r,o){let A=null,s=0,a=o;(a===null||typeof a>"u")&&(a=6);let l=Math.min(this.dimensions[1]-a,a),c=Math.max(this.dimensions[1]-a,a);if(this.dimensions[1]-aUd(u,d,m),[h,0]}else if(this.options.valueScaling==="setquantile"){const u=this.dimensions[1]-a,d=a,h=new Set(this.allVisibleValues()),m=kX().domain([...h]).range(eC(u,d,(d-u)/256));return m.ticks=f=>Ud(u,d,f),[m,0]}else A=qt().domain([n,r]).range([c,l]);return[A,s]}}]),I}(lC);function _9t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function tre(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function TI(e){return TI=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},TI(e)}const gre=200,Rl=10,YZ=40,wn=10,Wl=wn,Ire=4,sf=1,Xl=4,ire=5,g2t=256,eZ=Rl+YZ+wn+sf+Wl+Xl;let QS=function(e){$9t(I,e);var g=q9t(I);function I(i,n){var C;_9t(this,I);const r={...i};r.onValueScaleChanged=()=>{i.onValueScaleChanged(),C.drawColorbar()},C=g.call(this,r,n);const{pubSub:o,animate:A,svgElement:s,onTrackOptionsChanged:a,onMouseMoveZoom:l,isShowGlobalMousePosition:c,isValueScaleLocked:u}=i;return C.pubSub=o,C.is2d=!0,C.animate=A,C.uid=Ag.nice(),C.scaleBrush=SS(),C.onTrackOptionsChanged=a,C.isShowGlobalMousePosition=c,C.isValueScaleLocked=u,C.pColorbarArea=new rt.PIXI.Graphics,C.pMasked.addChild(C.pColorbarArea),C.pColorbar=new rt.PIXI.Graphics,C.pColorbarArea.addChild(C.pColorbar),C.axis=new jN(E1(C)),C.pColorbarArea.addChild(C.axis.pAxis),C.colorScale=Gb,n&&n.colorRange&&(C.colorScale=Dc(n.colorRange)),C.gBase=cg(s).append("g"),C.gMain=C.gBase.append("g"),C.gColorscaleBrush=C.gMain.append("g"),C.brushing=!1,C.prevOptions="",C.prevIndUpperLeftTile="",C.onMouseMoveZoom=l,C.setDataLensSize(11),C.dataLens=new Float32Array(C.dataLensSize**2),C.mouseMoveHandlerBound=C.mouseMoveHandler.bind(E1(C)),C.onMouseMoveZoom&&C.pubSubs.push(C.pubSub.subscribe("app.mouseMove",C.mouseMoveHandlerBound)),C.options&&C.options.showMousePosition&&!C.hideMousePosition&&(C.hideMousePosition=eh(E1(C),C.is2d,C.isShowGlobalMousePosition())),C.prevOptions=JSON.stringify(n),C}return L9t(I,[{key:"mouseMoveHandler",value:function(n){this.isWithin(n.x,n.y)&&(this.mouseX=n.x,this.mouseY=n.y,this.mouseMoveZoomHandler())}},{key:"mouseMoveZoomHandler",value:function(n=this.mouseX,C=this.mouseY){if(typeof n>"u"||typeof C>"u"||!this.areAllVisibleTilesLoaded()||!this.tilesetInfo)return;const r=n-this.position[0],o=C-this.position[1];let A,s;try{s=this.getVisibleRectangleData(r-this.dataLensPadding,o-this.dataLensPadding,this.dataLensSize,this.dataLensSize),A=s.get(this.dataLensPadding,this.dataLensPadding)}catch{return}const a=this.dataLensSize;let l;try{l=$7(this.limitedValueScale,this.colorScale,this.valueScale.domain()[0])}catch{return}if(!l)return;const c=Math.round(this._xScale.invert(r)),u=Math.round(this._yScale.invert(o));let d=[c,u],h=[Math.round(this._xScale.invert(r-this.dataLensPadding)),Math.round(this._xScale.invert(r+this.dataLensPadding))],m=[Math.round(this._yScale.invert(o-this.dataLensPadding)),Math.round(this._yScale.invert(o+this.dataLensPadding))];this.chromInfo&&(d=d.map(f=>Vi(f,this.chromInfo).slice(0,2)),h=h.map(f=>Vi(f,this.chromInfo).slice(0,2)),m=m.map(f=>Vi(f,this.chromInfo).slice(0,2))),this.onMouseMoveZoom({trackId:this.id,data:A,absX:n,absY:C,relX:r,relY:o,dataX:c,dataY:u,orientation:"2d",dataLens:s,dim:a,toRgb:l,center:d,xRange:h,yRange:m,isGenomicCoords:!!this.chromInfo})}},{key:"scheduleRerender",value:function(){this.backgroundTaskScheduler.enqueueTask(this.handleRerender.bind(this),null,this.uuid)}},{key:"handleRerender",value:function(){this.rerender(this.options,!0)}},{key:"getAbsTileDim",value:function(n,C,r){const{tileX:o,tileY:A,tileWidth:s,tileHeight:a}=this.getTilePosAndDimensions(n,C),l={};return l.width=this._refXScale(o+s)-this._refXScale(o),l.height=this._refYScale(A+a)-this._refYScale(A),r?(l.x=this._refXScale(A),l.y=this._refYScale(o)):(l.x=this._refXScale(o),l.y=this._refYScale(A)),l}},{key:"updateValueScale",value:function(){let n=this.minValue(),C=this.maxValue();const r=1e-6;n!=null&&C!==void 0&&C!==null&&Math.abs(n-C)this.renderTile(o)),this.hideMousePosition&&(this.hideMousePosition(),this.hideMousePosition=void 0),this.options&&this.options.showMousePosition&&!this.hideMousePosition&&(this.hideMousePosition=eh(this,this.is2d,this.isShowGlobalMousePosition())))}},{key:"drawLabel",value:function(){this.options.labelPosition===this.options.colorbarPosition?this.labelXOffset=eZ:this.labelXOffset=0,Ii(TI(I.prototype),"drawLabel",this).call(this)}},{key:"tileDataToCanvas",value:function(n){const C=document.createElement("canvas");C.width=this.binsPerTile(),C.height=this.binsPerTile();const r=C.getContext("2d");r.fillStyle="transparent",r.fillRect(0,0,C.width,C.height);const o=new ImageData(n,C.width,C.height);return r.putImageData(o,0,0),C}},{key:"exportData",value:function(){if(this.tilesetInfo){const n=this.getVisibleRectangleData(0,0,this.dimensions[0],this.dimensions[1]),C={bounds:[this._xScale.domain(),this._yScale.domain()],dimensions:n.shape,data:_Ze(n)};RG("data.json",JSON.stringify(C))}}},{key:"setSpriteProperties",value:function(n,C,r,o){const A=this.getAbsTileDim(C,r,o);n.width=A.width,n.height=A.height,n.x=A.x,n.y=A.y,o&&r[0]!==r[1]&&(n.rotation=-Math.PI/2,n.scale.x=Math.abs(n.scale.x)*-1)}},{key:"refXScale",value:function(n){Ii(TI(I.prototype),"refXScale",this).call(this,n),this.draw()}},{key:"refYScale",value:function(n){Ii(TI(I.prototype),"refYScale",this).call(this,n),this.draw()}},{key:"draw",value:function(){Ii(TI(I.prototype),"draw",this).call(this)}},{key:"newBrushOptions",value:function(n){const C=JSON.parse(JSON.stringify(this.options)),r=this.valueScale.copy().range([this.colorbarHeight,0]),o=r.invert(n[0]),s=(r.invert(n[1])-r.domain()[0])/(r.domain()[1]-r.domain()[0]),a=(o-r.domain()[0])/(r.domain()[1]-r.domain()[0]);return C.scaleStartPercent=s.toFixed(ire),C.scaleEndPercent=a.toFixed(ire),C}},{key:"brushStart",value:function(){this.brushing=!0}},{key:"brushMoved",value:function(n){if(!n.selection)return;const C=this.newBrushOptions(n.selection),r=JSON.stringify(C);this.gColorscaleBrush.selectAll(".handle--custom").attr("y",o=>o.type==="n"?n.selection[0]:n.selection[1]-Ire/2),r!==this.prevOptions&&(this.prevOptions=r,this.rerender(C,!0),this.onTrackOptionsChanged(C),this.isValueScaleLocked()&&this.onValueScaleChanged())}},{key:"brushEnd",value:function(){this.brushing=!1}},{key:"setPosition",value:function(n){Ii(TI(I.prototype),"setPosition",this).call(this,n),this.drawColorbar()}},{key:"setDimensions",value:function(n){Ii(TI(I.prototype),"setDimensions",this).call(this,n),this.drawColorbar()}},{key:"removeColorbar",value:function(){this.pColorbarArea.visible=!1,this.scaleBrush.on(".brush")&&this.gColorscaleBrush.call(this.scaleBrush.move,null),this.gColorscaleBrush.on(".brush",null),this.gColorscaleBrush.selectAll("rect").remove()}},{key:"drawColorbar",value:function(){if(this.pColorbar.clear(),!this.options||!this.options.colorbarPosition||this.options.colorbarPosition==="hidden"){this.removeColorbar();return}if(this.pColorbarArea.visible=!0,!this.valueScale||Number.isNaN(+this.valueScale.domain()[0])||Number.isNaN(+this.valueScale.domain()[1]))return;const n=Math.min(this.dimensions[1]/2,gre);if(this.colorbarHeight=n-2*wn,this.colorbarHeight<0){this.removeColorbar();return}if(this.valueScale.domain()[1]===this.valueScale.domain()[0]){this.removeColorbar();return}const C=this.valueScale.copy().range([this.colorbarHeight,0]);this.options.colorbarPosition==="topLeft"||this.options.colorbarPosition==="bottomLeft"?this.scaleBrush.extent([[Xl,0],[Wl,this.colorbarHeight]]):this.scaleBrush.extent([[0,0],[Wl-Xl,this.colorbarHeight]]),this.options.colorbarPosition==="topLeft"&&([this.pColorbarArea.x,this.pColorbarArea.y]=this.position,this.pColorbar.y=wn,this.axis.pAxis.y=wn,this.axis.pAxis.x=Xl+Wl+sf+Rl,this.pColorbar.x=Xl+Wl+sf,this.gColorscaleBrush.attr("transform",`translate(${this.pColorbarArea.x+Xl},${this.pColorbarArea.y+this.pColorbar.y-1})`)),this.options.colorbarPosition==="topRight"&&(this.pColorbarArea.x=this.position[0]+this.dimensions[0]-eZ,this.pColorbarArea.y=this.position[1],this.pColorbar.y=wn,this.axis.pAxis.y=wn,this.axis.pAxis.x=YZ+wn,this.pColorbar.x=YZ+wn,this.gColorscaleBrush.attr("transform",`translate(${this.pColorbarArea.x+this.pColorbar.x+Rl+2},${this.pColorbarArea.y+this.pColorbar.y-1})`)),this.options.colorbarPosition==="bottomRight"&&(this.pColorbarArea.x=this.position[0]+this.dimensions[0]-eZ,this.pColorbarArea.y=this.position[1]+this.dimensions[1]-n,this.pColorbar.y=wn,this.axis.pAxis.y=wn,this.axis.pAxis.x=YZ+wn,this.pColorbar.x=YZ+wn,this.gColorscaleBrush.attr("transform",`translate(${this.pColorbarArea.x+this.pColorbar.x+Rl+sf},${this.pColorbarArea.y+this.pColorbar.y-1})`)),this.options.colorbarPosition==="bottomLeft"&&(this.pColorbarArea.x=this.position[0],this.pColorbarArea.y=this.position[1]+this.dimensions[1]-n,this.pColorbar.y=wn,this.axis.pAxis.y=wn,this.axis.pAxis.x=Xl+Wl+sf+Rl,this.pColorbar.x=Xl+Wl+sf,this.gColorscaleBrush.attr("transform",`translate(${this.pColorbarArea.x+2},${this.pColorbarArea.y+this.pColorbar.y-1})`)),this.pColorbarArea.clear(),this.pColorbarArea.beginFill(Kt(this.options.colorbarBackgroundColor||"white"),+this.options.colorbarBackgroundOpacity>=0?+this.options.colorbarBackgroundOpacity:.6),this.pColorbarArea.drawRect(0,0,eZ,n),this.options?(this.options.scaleStartPercent||(this.options.scaleStartPercent=0),this.options.scaleEndPercent||(this.options.scaleEndPercent=1)):this.options={scaleStartPercent:0,scaleEndPercent:1};const r=C.domain()[1]-C.domain()[0],o=C(this.options.scaleStartPercent*r+C.domain()[0]),A=C(this.options.scaleEndPercent*r+C.domain()[0]);this.brushing||(this.scaleBrush.on("start",this.brushStart.bind(this)).on("brush",this.brushMoved.bind(this)).on("end",this.brushEnd.bind(this)).handleSize(0),this.gColorscaleBrush.on(".brush",null),this.gColorscaleBrush.call(this.scaleBrush),this.northHandle=this.gColorscaleBrush.selectAll(".handle--custom").data([{type:"n"},{type:"s"}]).enter().append("rect").classed("handle--custom",!0).attr("cursor","ns-resize").attr("width",Wl).attr("height",Ire).style("fill","#666").style("stroke","white"),this.flipText&&this.northHandle.attr("cursor","ew-resize"),this.gColorscaleBrush.call(this.scaleBrush.move,[A,o]));const s=qt().domain([0,255]).range([0,this.colorbarHeight]);for(let a=0;a{const Z=y.mirrored?[y.tileData.tilePos[1],y.tileData.tilePos[0]]:y.tileData.tilePos,{tileX:B,tileY:G,tileWidth:v,tileHeight:w}=this.getTilePosAndDimensions(y.tileData.zoomLevel,Z,this.binsPerTile()),V=Math.floor(B/a),S=Math.floor((B+v)/a),X=Math.floor(G/a),W=Math.floor((G+w)/a);let R=Math.max(h,V)-V,H=Math.max(m,X)-X;const Y=Math.min(h+f,S)-V,D=Math.min(m+b,W)-X,E=Math.max(V-h,0),O=Math.max(X-m,0),J=Y-R,ee=D-H;if(!(J<0||ee<0)){if(y.mirrored&&R>H){const q=R;R=H,H=q}PZe(p.hi(O+ee,E+J).lo(O,E),y.dataArray.hi(H+ee,R+J).lo(H,R))}}),p}},{key:"initTile",value:function(n){Ii(TI(I.prototype),"initTile",this).call(this,n),n.tileData.dense.length===this.binsPerTile()**2&&(n.dataArray=vp(Array.from(n.tileData.dense),[this.binsPerTile(),this.binsPerTile()]),this.continuousScaling&&n.tileData.tilePos[0]===n.tileData.tilePos[1]&&n.mirrored&&(n.tileData.denseDataExtrema.mirrorPrecomputedExtrema(),Ii(TI(I.prototype),"initTile",this).call(this,n))),!(this.scale.minValue===null||this.scale.maxValue===null)&&this.renderTile(n)}},{key:"updateTile",value:function(n){n.scale&&this.scale&&this.scale.minValue===n.scale.minValue&&this.scale.maxValue===n.scale.maxValue||(this.renderTile(n),this.drawColorbar())}},{key:"destroyTile",value:function(n){n.sprite.destroy(!0),n.canvas=null,n.sprite=null,n.texture=null}},{key:"pixDataFunction",value:function(n,C){if(C){const{graphics:r}=n,o=this.tileDataToCanvas(C.pixData);n.sprite&&n.sprite.destroy(!0);const A=rt.PIXI.VERSION[0]==="4"?rt.PIXI.Texture.fromCanvas(o,rt.PIXI.SCALE_MODES.NEAREST):rt.PIXI.Texture.from(o,{scaleMode:rt.PIXI.SCALE_MODES.NEAREST}),s=new rt.PIXI.Sprite(A);n.sprite=s,n.texture=A,n.canvas=o,this.setSpriteProperties(n.sprite,n.tileData.zoomLevel,n.tileData.tilePos,n.mirrored),r.removeChildren(),r.addChild(n.sprite)}this.renderingTiles.delete(n.tileId)}},{key:"renderTile",value:function(n){const[C]=this.updateValueScale(),r=0;if(this.renderingTiles.add(n.tileId),this.tilesetInfo.tile_size&&n.tileData.dense.lengththis.pixDataFunction(n,o),this.mirrorTiles()&&!n.mirrored&&n.tileData.tilePos[0]===n.tileData.tilePos[1],this.options.extent==="upper-right"&&n.tileData.tilePos[0]===n.tileData.tilePos[1],this.options.zeroValueColor?SZe(this.options.zeroValueColor):void 0,{selectedRows:this.options.selectRows,selectedRowsAggregationMode:this.options.selectRowsAggregationMode,selectedRowsAggregationWithRelativeHeight:this.options.selectRowsAggregationWithRelativeHeight,selectedRowsAggregationMethod:this.options.selectRowsAggregationMethod})}},{key:"remove",value:function(){this.gMain.remove(),this.gMain=null,Ii(TI(I.prototype),"remove",this).call(this)}},{key:"refScalesChanged",value:function(n,C){Ii(TI(I.prototype),"refScalesChanged",this).call(this,n,C),nN(this.fetchedTiles).filter(r=>r.sprite).forEach(r=>this.setSpriteProperties(r.sprite,r.tileData.zoomLevel,r.tileData.tilePos,r.mirrored))}},{key:"superSVG",value:function(){return Ii(TI(I.prototype),"exportSVG",this).call(this)}},{key:"exportSVG",value:function(){let n=null,C=null;Ii(TI(I.prototype),"exportSVG",this)?[C,n]=Ii(TI(I.prototype),"exportSVG",this).call(this):(C=document.createElement("g"),n=C);const r=document.createElement("g");n.appendChild(r),r.setAttribute("transform",`translate(${this.pMain.position.x},${this.pMain.position.y}) scale(${this.pMain.scale.x},${this.pMain.scale.y})`);for(const A of this.visibleAndFetchedTiles()){const s=A.sprite.rotation*180/Math.PI,a=document.createElement("g");a.setAttribute("transform",`translate(${A.sprite.x},${A.sprite.y}) rotate(${s}) scale(${A.sprite.scale.x},${A.sprite.scale.y})`);const l=document.createElement("image");l.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",A.canvas.toDataURL()),l.setAttribute("width",A.canvas.width),l.setAttribute("height",A.canvas.height),l.setAttribute("style","image-rendering: pixelated"),a.appendChild(l),r.appendChild(a)}const o=this.exportColorBarSVG();return n.appendChild(o),[C,C]}},{key:"getVisiblePartOfUppLeftTile",value:function(){const n=this.visibleAndFetchedTiles().map(d=>{const h=d.mirrored?[d.tileData.tilePos[1],d.tileData.tilePos[0]]:d.tileData.tilePos;return[h[0],h[1],d.tileId]});if(n.length===0)return null;let C=n[0];for(let d=0;dd.tileId===C[2])[0],s=this.getIndicesOfVisibleDataInTile(A),a=s[0],l=s[1],c=a-a%o,u=l-l%o;return[A.tileId,c,u]}},{key:"getIndicesOfVisibleDataInTile",value:function(n){const C=this._xScale.range(),r=this._yScale.range(),o=n.mirrored?[n.tileData.tilePos[1],n.tileData.tilePos[0]]:n.tileData.tilePos,{tileX:A,tileY:s,tileWidth:a,tileHeight:l}=this.getTilePosAndDimensions(n.tileData.zoomLevel,o,this.binsPerTile()),c=qt().domain([0,this.binsPerTile()]).range([A,A+a]),u=Math.max(0,Math.round(c.invert(this._xScale.invert(C[0])))-1),d=Math.min(this.binsPerTile(),Math.round(c.invert(this._xScale.invert(C[1])))),h=qt().domain([0,this.binsPerTile()]).range([s,s+l]),m=Math.max(0,Math.round(h.invert(this._yScale.invert(r[0])))-1),f=Math.min(this.binsPerTile(),Math.round(h.invert(this._yScale.invert(r[1]))));return n.mirrored&&o[0]!==o[1]?[m,u,f,d]:[u,m,d,f]}},{key:"minVisibleValue",value:function(n=!1){const C=this.visibleAndFetchedTiles().map(o=>{if(o.tileData.denseDataExtrema===void 0)return null;const A=this.getIndicesOfVisibleDataInTile(o);return o.tileData.denseDataExtrema.getMinNonZeroInSubset(A)});if(C.length===0&&this.valueScaleMax===null)return null;const r=Math.min.apply(null,C);return r===Number.MAX_SAFE_INTEGER?Ii(TI(I.prototype),"minVisibleValue",this).call(this,n):n?r:this.valueScaleMin!==null?this.valueScaleMin:r}},{key:"maxVisibleValue",value:function(n=!1){const C=this.visibleAndFetchedTiles().map(o=>{if(o.tileData.denseDataExtrema===void 0)return null;const A=this.getIndicesOfVisibleDataInTile(o);return o.tileData.denseDataExtrema.getMaxNonZeroInSubset(A)});if(C.length===0&&this.valueScaleMax===null)return null;const r=Math.max.apply(null,C);return r===Number.MIN_SAFE_INTEGER?Ii(TI(I.prototype),"maxVisibleValue",this).call(this,n):n?r:this.valueScaleMax!==null?this.valueScaleMax:r}},{key:"zoomed",value:function(n,C,r,o,A){if(this.brushing)return;Ii(TI(I.prototype),"zoomed",this).call(this,n,C),this.pMain.position.x=o,this.pMain.position.y=A,this.pMain.scale.x=r,this.pMain.scale.y=r;const s=this.isValueScaleLocked();if(this.continuousScaling&&this.minValue()!==void 0&&this.maxValue()!==void 0){const a=JSON.stringify(this.getVisiblePartOfUppLeftTile());if(this.valueScaleMin===null&&this.valueScaleMax===null&&!s&&a!==this.prevIndUpperLeftTile){const l=this.minVisibleValue(),c=this.maxVisibleValue(),u=1e-6;l!==null&&c!==null&&(Math.abs(this.minValue()-l)>u||Math.abs(this.maxValue()-c)>u)&&(this.minValue(l),this.maxValue(c),this.scheduleRerender()),this.prevIndUpperLeftTile=a}s&&this.onValueScaleChanged()}this.mouseMoveZoomHandler()}},{key:"addTileId",value:function(n,C,r,o,A,s=!1){const a=[C,r,o];a.mirrored=s,a.dataTransform=A,n.push(a)}},{key:"tilesToId",value:function(n,C,r){const o=n,A=C,s=this.options&&this.options.dataTransform||"default",a=[];for(let l=0;l=A[c]?this.options.extent!=="lower-left"&&this.addTileId(a,r,A[c],o[l],s,!0):this.options.extent!=="upper-right"&&this.addTileId(a,r,o[l],A[c],s),o[l]===A[c]&&this.options.extent==="lower-left"&&this.addTileId(a,r,o[l],A[c],s)):this.addTileId(a,r,o[l],A[c],s);return a}},{key:"calculateVisibleTiles",value:function(){if(this.tilesetInfo){if(this.zoomLevel=this.calculateZoomLevel(),this.tilesetInfo.resolutions){const n=this.tilesetInfo.resolutions.map(C=>+C).sort((C,r)=>r-C);this.xTiles=Gt.calculateTilesFromResolution(n[this.zoomLevel],this._xScale,this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0]),this.yTiles=Gt.calculateTilesFromResolution(n[this.zoomLevel],this._yScale,this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0])}else this.xTiles=Gt.calculateTiles(this.zoomLevel,this._xScale,this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0],this.tilesetInfo.max_zoom,this.tilesetInfo.max_width),this.yTiles=Gt.calculateTiles(this.zoomLevel,this._yScale,this.options.reverseYAxis?-this.tilesetInfo.max_pos[1]:this.tilesetInfo.min_pos[1],this.options.reverseYAxis?-this.tilesetInfo.min_pos[1]:this.tilesetInfo.max_pos[1],this.tilesetInfo.max_zoom,this.tilesetInfo.max_width1||this.tilesetInfo.max_width);this.setVisibleTiles(this.tilesToId(this.xTiles,this.yTiles,this.zoomLevel))}}},{key:"mirrorTiles",value:function(){return!(this.tilesetInfo.mirror_tiles&&(this.tilesetInfo.mirror_tiles===!1||this.tilesetInfo.mirror_tiles==="false"))}},{key:"getMouseOverHtml",value:function(n,C){if(!this.options||!this.options.showTooltip||!this.tilesetInfo)return"";const r=Gt.calculateResolution(this.tilesetInfo,this.zoomLevel),o=Math.max(this.tilesetInfo.max_pos[1]-this.tilesetInfo.min_pos[1],this.tilesetInfo.max_pos[0]-this.tilesetInfo.min_pos[0]),A=Math.ceil(Math.log(o/r)/Math.log(10));this.setDataLensSize(1);const s=this._xScale.invert(n),a=this._yScale.invert(C);let l="Position: ";if(this.chromInfo){const u=Vi(s,this.chromInfo),d=Vi(a,this.chromInfo),h=m=>Ar(`.${A}s`)(m);l+=`${u[0]}:${h(u[1])} & ${d[0]}:${h(d[1])}`,l+="
"}let c=null;try{c=this.getVisibleRectangleData(n,C,1,1).get(0,0)}catch{return""}return this.options&&this.options.heatmapValueScaling==="log"?c>0?`${l}Value: 1e${Ar(".3f")(Math.log(c)/Math.log(10))}`:c===0?`${l}Value: 0`:`${l}Value: N/A`:`${l}Value: ${Ar(".3f")(c)}`}},{key:"getTilePosAndDimensions",value:function(n,C,r){const o=r||this.binsPerTile();if(this.tilesetInfo.resolutions){const f=this.tilesetInfo.resolutions.map(B=>+B).sort((B,G)=>G-B)[n],b=f*o,p=b,y=f*o*C[0],Z=f*o*C[1];return{tileX:y,tileY:Z,tileWidth:b,tileHeight:p}}const A=C[0],s=C[1],a=this.tilesetInfo.min_pos[0],l=this.options.reverseYAxis?-this.tilesetInfo.max_pos[1]:this.tilesetInfo.min_pos[1],c=this.tilesetInfo.max_width/2**n,u=this.tilesetInfo.max_width/2**n,d=a+A*c,h=l+s*u;return{tileX:d,tileY:h,tileWidth:c,tileHeight:u}}},{key:"calculateZoomLevel",value:function(){const n=this.tilesetInfo.min_pos[0],C=this.tilesetInfo.max_pos[0],r=this.tilesetInfo.min_pos[1],o=this.tilesetInfo.max_pos[1];let A=null;if(this.tilesetInfo.resolutions){const s=Gt.calculateZoomLevelFromResolutions(this.tilesetInfo.resolutions,this._xScale,n,C),a=Gt.calculateZoomLevelFromResolutions(this.tilesetInfo.resolutions,this._yScale,r,o);A=Math.min(s,a)}else{const s=Gt.calculateZoomLevel(this._xScale,this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0],this.binsPerTile()),a=Gt.calculateZoomLevel(this._xScale,this.tilesetInfo.min_pos[1],this.tilesetInfo.max_pos[1],this.binsPerTile());A=Math.max(s,a),A=Math.min(A,this.maxZoom)}return this.options&&this.options.maxZoom&&(this.options.maxZoom>=0?A=Math.min(this.options.maxZoom,A):console.error("Invalid maxZoom on track:",this)),A}},{key:"tileToLocalId",value:function(n){return n.dataTransform&&n.dataTransform!=="default"?`${n.join(".")}.${n.mirrored}.${n.dataTransform}`:`${n.join(".")}.${n.mirrored}`}},{key:"tileToRemoteId",value:function(n){return n.dataTransform&&n.dataTransform!=="default"?`${n.join(".")}.${n.dataTransform}`:`${n.join(".")}`}},{key:"localToRemoteId",value:function(n){const C=n.split(".");return C.slice(0,C.length-1).join(".")}}]),I}(rm);function I2t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function nre(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function W9(e){return W9=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},W9(e)}function XVe(e){if(!e.graphics)return;const g=e.graphics,{tileX:I,tileY:i,tileWidth:n}=this.getTilePosAndDimensions(e.tileData.zoomLevel,e.tileData.tilePos);e.drawnAtScale=this._xScale.copy();const C=1/((this._xScale(1)-this._xScale(0))/(this._refXScale(1)-this._refXScale(0))),r=1/((this._yScale(1)-this._yScale(0))/(this._refYScale(1)-this._refYScale(0)));e.text.scale.x=C,e.text.scale.y=r;const o=this._xScale(n)-this._xScale(0);if(e.textGraphics.scale.x=o/256,e.textGraphics.scale.y=o/256,g.clear(),g.lineStyle(4*C,255,1),g.beginFill(16740363,.4),g.alpha=.5,e.mirrored){const A=this._refXScale(i+n)-this._refXScale(i),s=this._refYScale(I+n)-this._refYScale(I);e.textGraphics.position.x=this._refXScale(i)+A/2,e.textGraphics.position.y=this._refYScale(I)+s/2,g.drawRect(this._refXScale(i),this._refYScale(I),A,s)}else{const A=this._refXScale(I+n)-this._refXScale(I),s=this._refYScale(i+n)-this._refYScale(i);e.textGraphics.position.x=this._refXScale(I)+A/2,e.textGraphics.position.y=this._refYScale(i)+s/2,g.drawRect(this._refXScale(I),this._refYScale(i),A,s)}}function HVe(e){const g=e.graphics;e.textGraphics=new rt.PIXI.Graphics,e.mirrored?e.text=new rt.PIXI.Text(`${e.tileData.zoomLevel}/${[e.tileData.tilePos[1],e.tileData.tilePos[0]].join("/")}`,{fontFamily:"Arial",fontSize:24,fill:16715792,align:"center"}):e.text=new rt.PIXI.Text(`${e.tileData.zoomLevel}/${e.tileData.tilePos.join("/")}`,{fontFamily:"Arial",fontSize:24,fill:16715792,align:"center"}),e.textGraphics.addChild(e.text),e.text.anchor.x=.5,e.text.anchor.y=.5,g.addChild(e.textGraphics)}let TVe=function(e){r2t(I,e);var g=o2t(I);function I(){return I2t(this,I),g.apply(this,arguments)}return i2t(I,[{key:"areAllVisibleTilesLoaded",value:function(){return!0}},{key:"initTile",value:function(n){HVe.bind(this)(n),this.drawTile(n)}},{key:"destroyTile",value:function(n,C){}},{key:"drawTile",value:function(n){XVe.bind(this)(n)}},{key:"fetchNewTiles",value:function(n){n.forEach(C=>{const o=C.remoteId.split("."),A={zoomLevel:o[0],tilePos:o.slice(1,o.length).map(s=>+s)};this.fetchedTiles[C.tileId]=C,this.fetchedTiles[C.tileId].tileData=A,this.fetching.has(C.remoteId)&&this.fetching.delete(C.remoteId)}),this.synchronizeTilesAndGraphics()}}]),I}(QS);function l2t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function Cre(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function lh(e){return lh=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},lh(e)}const y2t=1024;let dj=function(e){m2t(I,e);var g=f2t(I);function I(i,n){var C;l2t(this,I),C=g.call(this,i,n);const{onMouseMoveZoom:r,isValueScaleLocked:o,getLockGroupExtrema:A}=i;return C.onMouseMoveZoom=r,C.isValueScaleLocked=o,C.getLockGroupExtrema=A,C.onMouseMoveZoom&&C.pubSubs.push(C.pubSub.subscribe("app.mouseMove",C.mouseMoveHandler.bind(NVe(C)))),C}return c2t(I,[{key:"initTile",value:function(n){ev(lh(I.prototype),"initTile",this).call(this,n)}},{key:"tileToLocalId",value:function(n){return`${n.join(".")}`}},{key:"tileToRemoteId",value:function(n){return`${n.join(".")}`}},{key:"relevantScale",value:function(){return null}},{key:"setVisibleTiles",value:function(n){this.visibleTiles=n.map(C=>({tileId:this.tileToLocalId(C),remoteId:this.tileToRemoteId(C)})),this.visibleTileIds=new Set(this.visibleTiles.map(C=>C.tileId))}},{key:"calculateVisibleTiles",value:function(){if(!this.tilesetInfo)return;if(this.zoomLevel=this.calculateZoomLevel(),this.tilesetInfo.resolutions){const r=this.tilesetInfo.resolutions.map(s=>+s).sort((s,a)=>a-s),A=Gt.calculateTilesFromResolution(r[this.zoomLevel],this._xScale,this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0]).map(s=>[this.zoomLevel,s]);this.setVisibleTiles(A);return}const C=Gt.calculateTiles(this.zoomLevel,this.relevantScale(),this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0],this.tilesetInfo.max_zoom,this.tilesetInfo.max_width).map(r=>[this.zoomLevel,r]);this.setVisibleTiles(C)}},{key:"getTilePosAndDimensions",value:function(n,C,r){const o=C[0],A=C[0];if(this.tilesetInfo.resolutions){const f=r||y2t,p=this.tilesetInfo.resolutions.map(v=>+v).sort((v,w)=>w-v)[n],y=p*f,Z=y,B=p*f*C[0],G=p*f*C[1];return{tileX:B,tileY:G,tileWidth:y,tileHeight:Z}}const s=this.tilesetInfo.max_width,a=this.tilesetInfo.max_width,l=this.tilesetInfo.min_pos[0],c=this.tilesetInfo.min_pos[1],u=s/2**n,d=a/2**n,h=l+o*u,m=c+A*d;return{tileX:h,tileY:m,tileWidth:u,tileHeight:d}}},{key:"updateTile",value:function(n){}},{key:"scheduleRerender",value:function(){this.backgroundTaskScheduler.enqueueTask(this.handleRerender.bind(this),null,this.uuid)}},{key:"handleRerender",value:function(){this.rerender(this.options,!1)}},{key:"getIndicesOfVisibleDataInTile",value:function(n){const C=this._xScale.range();if(!this.tilesetInfo)return[null,null];const{tileX:r,tileWidth:o}=this.getTilePosAndDimensions(n.tileData.zoomLevel,n.tileData.tilePos,this.tilesetInfo.bins_per_dimension||this.tilesetInfo.tile_size),A=qt().domain([0,this.tilesetInfo.tile_size||this.tilesetInfo.bins_per_dimension]).range([r,r+o]),s=Math.max(0,Math.round(A.invert(this._xScale.invert(C[0])))),a=Math.min(n.tileData.dense.length,Math.round(A.invert(this._xScale.invert(C[1]))));return[s,a]}},{key:"minVisibleValue",value:function(n=!1){let C=this.visibleAndFetchedIds();C.length===0&&(C=Object.keys(this.fetchedTiles));const r=C.map(A=>this.fetchedTiles[A]).map(A=>{const s=this.getIndicesOfVisibleDataInTile(A);return A.tileData.denseDataExtrema.getMinNonZeroInSubset(s)}),o=Math.min(...r);return n?o:this.valueScaleMin!==null?this.valueScaleMin:o}},{key:"maxVisibleValue",value:function(n=!1){let C=this.visibleAndFetchedIds();C.length===0&&(C=Object.keys(this.fetchedTiles));const r=C.map(A=>this.fetchedTiles[A]).map(A=>{const s=this.getIndicesOfVisibleDataInTile(A);return A.tileData.denseDataExtrema.getMaxNonZeroInSubset(s)}),o=Math.max(...r);return n?o:this.valueScaleMax!==null?this.valueScaleMax:o}},{key:"getAggregatedVisibleValue",value:function(n="max"){const C=n==="min"?Math.min:Math.max,r=n==="min"?1/0:-1/0;let o=this.visibleAndFetchedIds();o.length===0&&(o=Object.keys(this.fetchedTiles));const A=this._xScale.range();return o.map(s=>this.fetchedTiles[s]).map(s=>{if(!s.tileData.tilePos)return n==="min"?this.minVisibleValue():this.maxVisibleValue();const{tileX:a,tileWidth:l}=this.getTilePosAndDimensions(s.tileData.zoomLevel,s.tileData.tilePos,this.tilesetInfo.bins_per_dimension||this.tilesetInfo.tile_size),c=qt().domain([0,this.tilesetInfo.tile_size||this.tilesetInfo.bins_per_dimension]).range([a,a+l]),u=Math.max(0,Math.round(c.invert(this._xScale.invert(A[0])))),d=Math.min(s.tileData.dense.length,Math.round(c.invert(this._xScale.invert(A[1]))));return s.tileData.dense.slice(u,d)}).reduce((s,a)=>C(s,...a),r)}},{key:"getDataAtPos",value:function(n){let C;if(!this.tilesetInfo)return C;const r=this.calculateZoomLevel(),o=Gt.calculateTileWidth(this.tilesetInfo,r,this.tilesetInfo.tile_size),A=this._xScale.invert(n)/o,s=this.tileToLocalId([r,Math.floor(A)]),a=this.fetchedTiles[s];if(!a)return C;const l=this.tilesetInfo.tile_size*(A-Math.floor(A));return a.tileData.dense?a.tileData.dense[Math.floor(l)]:null}},{key:"mouseMoveHandler",value:function({x:n,y:C}={}){this.isWithin(n,C)&&(this.mouseX=n,this.mouseY=C,this.mouseMoveZoomHandler())}},{key:"mouseMoveZoomHandler",value:function(){}},{key:"zoomed",value:function(...n){ev(lh(I.prototype),"zoomed",this).call(this,...n),this.mouseMoveZoomHandler()}}]),I}(rm);function Z2t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function rre(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function ls(e){return ls=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},ls(e)}let O0=function(e){w2t(I,e);var g=V2t(I);function I(i,n){var C;Z2t(this,I),C=g.call(this,i,n);const{animate:r,isShowGlobalMousePosition:o}=i;return C.constIndicator=new rt.PIXI.Graphics,C.pMain.addChild(C.constIndicator),C.axis=new jN(Tz(C)),C.pBase.addChild(C.axis.pAxis),C.animate=r,C.options=n,C.isShowGlobalMousePosition=o,C.pubSubs=[],C.options.showMousePosition&&!C.hideMousePosition&&(C.hideMousePosition=eh(Tz(C),C.is2d,C.isShowGlobalMousePosition())),C}return G2t(I,[{key:"rerender",value:function(n,C){const r=JSON.stringify(n);!C&&r===this.prevOptions||(id(ls(I.prototype),"rerender",this).call(this,n,C),this.prevOptions=r,this.options=n,this.options.showMousePosition&&!this.hideMousePosition&&(this.hideMousePosition=eh(this,this.is2d,this.isShowGlobalMousePosition())),!this.options.showMousePosition&&this.hideMousePosition&&(this.hideMousePosition(),this.hideMousePosition=void 0))}},{key:"calculateZoomLevel",value:function(){if(this.tilesetInfo.resolutions)return Gt.calculateZoomLevelFromResolutions(this.tilesetInfo.resolutions,this._xScale,this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0]-2);const n=Gt.calculateZoomLevel(this._xScale,this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0],this.tilesetInfo.bins_per_dimension||this.tilesetInfo.tile_size);let C=Math.min(n,this.maxZoom);return C=Math.max(C,0),C}},{key:"relevantScale",value:function(){return this._xScale}},{key:"draw",value:function(){id(ls(I.prototype),"draw",this).call(this),this.drawConstIndicator()}},{key:"drawAxis",value:function(n){if(!this.options.axisPositionVertical&&!this.options.axisPositionHorizontal){this.axis.clearAxis();return}if(this.options.axisPositionVertical&&this.options.axisPositionVertical==="hidden"){this.axis.clearAxis();return}if(this.options.axisPositionHorizontal&&this.options.axisPositionHorizontal==="hidden"){this.axis.clearAxis();return}const C=this.options.axisMargin||0;this.options.axisPositionHorizontal==="left"||this.options.axisPositionVertical==="top"?(this.axis.pAxis.position.x=this.position[0]+C,this.axis.pAxis.position.y=this.position[1],this.axis.drawAxisRight(n,this.dimensions[1])):this.options.axisPositionHorizontal==="outsideLeft"||this.options.axisPositionVertical==="outsideTop"?(this.axis.pAxis.position.x=this.position[0]+C,this.axis.pAxis.position.y=this.position[1],this.axis.drawAxisLeft(n,this.dimensions[1])):this.options.axisPositionHorizontal==="right"||this.options.axisPositionVertical==="bottom"?(this.axis.pAxis.position.x=this.position[0]+this.dimensions[0]-C,this.axis.pAxis.position.y=this.position[1],this.axis.drawAxisLeft(n,this.dimensions[1])):(this.options.axisPositionHorizontal==="outsideRight"||this.options.axisPositionVertical==="outsideBottom")&&(this.axis.pAxis.position.x=this.position[0]+this.dimensions[0]-C,this.axis.pAxis.position.y=this.position[1],this.axis.drawAxisRight(n,this.dimensions[1]))}},{key:"mouseMoveZoomHandler",value:function(n=this.mouseX,C=this.mouseY){if(typeof n>"u"||!this.areAllVisibleTilesLoaded()||!this.tilesetInfo)return;let r=0,o=0,A="1d-horizontal";this.isLeftModified?(r=C-this.position[1],o=n-this.position[0],A="1d-vertical"):(r=n-this.position[0],o=C-this.position[1]);const s=n-this.position[0],a=C-this.position[1],l=this._xScale.invert(r),c=this._yScale.invert(o),u=this.getDataAtPos(r);u&&this.onMouseMoveZoom({trackId:this.id,data:u,absX:n,absY:C,relX:s,relY:a,dataX:l,dataY:c,orientation:A})}},{key:"drawConstIndicator",value:function(){if(this.constIndicator){for(this.constIndicator.clear();this.constIndicator.children[0];)this.constIndicator.removeChild(this.constIndicator.children[0]);!this.options.constIndicators||!this.valueScale||this.options.constIndicators.forEach(({color:n="black",opacity:C=1,label:r=null,labelColor:o="black",labelOpacity:A=1,labelPosition:s="leftTop",labelSize:a=12,value:l=0}={})=>{const c=Kt(n),u=Kt(o);this.constIndicator.beginFill(c,C);const d=this.valueScale(l);let h=0,m=0;if(r){const f=new rt.PIXI.Text(r,{fontFamily:"Arial",fontSize:a,fill:u});switch(f.alpha=A,s){case"right":f.anchor.x=1,f.anchor.y=.5,f.x=this.position[0]+this.dimensions[0]-6,f.y=d,m=f.width+8;break;case"rightBottom":f.anchor.x=1,f.anchor.y=0,f.x=this.position[0]+this.dimensions[0]-6,f.y=d;break;case"rightTop":f.anchor.x=1,f.anchor.y=1,f.x=this.position[0]+this.dimensions[0]-6,f.y=d;break;case"left":f.anchor.x=0,f.anchor.y=.5,f.x=this.position[0]+2,f.y=d,h=f.width+4;break;case"leftBottom":f.anchor.x=0,f.anchor.y=0,f.x=this.position[0]+2,f.y=d;break;case"leftTop":default:f.anchor.x=0,f.anchor.y=1,f.x=this.position[0]+2,f.y=d;break}this.constIndicator.addChild(f)}this.constIndicator.drawRect(this.position[0]+h,d,this.dimensions[0]-m,1)})}}},{key:"exportSVG",value:function(){let n=null,C=null;id(ls(I.prototype),"exportSVG",this)?[C,n]=id(ls(I.prototype),"exportSVG",this).call(this):(C=document.createElement("g"),n=C),C.setAttribute("class","horizontal-tiled-1d-track");const r=document.createElement("g");return n.appendChild(r),this.options.constIndicators&&this.options.constIndicators.forEach(({color:o="black",opacity:A=1,label:s=null,labelColor:a="black",labelOpacity:l=1,labelPosition:c="leftTop",labelSize:u=12,value:d=0}={})=>{const h=this.valueScale(d);if(s){const f=document.createElement("text");switch(f.textContent=s,f.setAttribute("x",this.position[0]),f.setAttribute("y",h),f.setAttribute("style",`font-family: 'Arial'; font-size: ${u}px; fill: ${a}; fill-opacity: ${l};`),c){case"rightBottom":f.setAttribute("x",this.position[0]+this.dimensions[0]-6),f.setAttribute("y",h+u+2),f.setAttribute("text-anchor","end");break;case"right":case"rightTop":f.setAttribute("x",this.position[0]+this.dimensions[0]-6),f.setAttribute("y",h-2),f.setAttribute("text-anchor","end");break;case"leftBottom":f.setAttribute("x",this.position[0]+2),f.setAttribute("y",h+u+2);break;case"left":case"leftTop":default:f.setAttribute("x",this.position[0]+2),f.setAttribute("y",h-2);break}r.appendChild(f)}const m=document.createElement("line");m.setAttribute("x1",this.position[0]),m.setAttribute("y1",h),m.setAttribute("x2",this.dimensions[0]),m.setAttribute("y2",h),m.setAttribute("stroke",o),m.setAttribute("stroke-opacity",A),r.appendChild(m)}),[C,n]}}]),I}(dj);function X2t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function ore(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function Pb(e){return Pb=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},Pb(e)}let kVe=function(e){Y2t(I,e);var g=K2t(I);function I(i,n){var C;return X2t(this,I),C=g.call(this,i,n),C.pMain=C.pMobile,C}return H2t(I,[{key:"areAllVisibleTilesLoaded",value:function(){return!0}},{key:"initTile",value:function(n){const C=n.graphics;n.textGraphics=new rt.PIXI.Graphics,n.text=new rt.PIXI.Text(`${n.tileData.zoomLevel}/${n.tileData.tilePos.join("/")}`,{fontFamily:"Arial",fontSize:32,fill:16715792,align:"center"}),n.textGraphics.addChild(n.text),n.text.anchor.x=.5,n.text.anchor.y=.5,C.addChild(n.textGraphics),this.drawTile(n)}},{key:"destroyTile",value:function(n){}},{key:"drawTile",value:function(n){if(M1(Pb(I.prototype),"drawTile",this).call(this,n),!n.graphics)return;const C=n.graphics,{tileX:r,tileWidth:o}=this.getTilePosAndDimensions(n.tileData.zoomLevel,n.tileData.tilePos),A=1/((this._xScale(1)-this._xScale(0))/(this._refXScale(1)-this._refXScale(0)));n.text.scale.x=A,C.clear();const s=this.dimensions[1],a=this._refXScale(r+o)-this._refXScale(r);n.textGraphics.position.x=this._refXScale(r)+a/2,n.textGraphics.position.y=s/2;const l=this._refXScale(r);C.lineStyle(4*A,255,1),C.beginFill(16740363,.4),C.alpha=.5,C.moveTo(l,0),C.lineTo(l,s),C.moveTo(l+a,0),C.lineTo(l+a,s),C.lineStyle(0,255,1),C.drawRect(l,0,a,s)}}]),I}(O0);function E2t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function Are(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function Jb(e){return Jb=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},Jb(e)}let YVe=function(e){O2t(I,e);var g=_2t(I);function I(){return E2t(this,I),g.apply(this,arguments)}return M2t(I,[{key:"calculateZoomLevel",value:function(){const n=Gt.calculateZoomLevel(this._yScale,this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0]);return Math.min(n,this.maxZoom)}},{key:"relevantScale",value:function(){return this._yScale}},{key:"zoomed",value:function(n,C){z1(Jb(I.prototype),"zoomed",this).call(this,n,C);const r=1,o=(C(1)-C(0))/(this._refYScale(1)-this._refYScale(0)),A=this.position[0],s=C(0)+this.position[1]-this._refYScale(1)*o;this.pMain.position.x=A,this.pMain.position.y=s,this.pMain.scale.x=r,this.pMain.scale.y=o}}]),I}(dj);function j2t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function are(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function Ob(e){return Ob=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},Ob(e)}let KVe=function(e){gHt(I,e);var g=IHt(I);function I(){return j2t(this,I),g.apply(this,arguments)}return $2t(I,[{key:"areAllVisibleTilesLoaded",value:function(){return!0}},{key:"initTile",value:function(n){const C=n.graphics;n.textGraphics=new rt.PIXI.Graphics,n.text=new rt.PIXI.Text(`${n.tileData.zoomLevel}/${n.tileData.tilePos.join("/")}`,{fontFamily:"Arial",fontSize:32,fill:16715792,align:"center"}),n.textGraphics.addChild(n.text),n.text.anchor.x=.5,n.text.anchor.y=.5,n.text.rotation=-Math.PI/2,C.addChild(n.textGraphics),this.drawTile(n,C)}},{key:"destroyTile",value:function(n,C){}},{key:"drawTile",value:function(n){if(P1(Ob(I.prototype),"drawTile",this).call(this,n),!n.graphics)return;const C=n.graphics,{tileY:r,tileHeight:o}=this.getTilePosAndDimensions(n.tileData.zoomLevel,n.tileData.tilePos),A=1/((this._yScale(1)-this._yScale(0))/(this._refYScale(1)-this._refYScale(0)));n.text.scale.x=A,C.clear(),C.lineStyle(4*A,255,1),C.beginFill(16740363,.4),C.alpha=.5;const s=this.dimensions[0],a=this._refYScale(r+o)-this._refYScale(r);n.textGraphics.position.x=s/2,n.textGraphics.position.y=this._refYScale(r)+a/2,C.drawRect(0,this._refYScale(r),s,a)}},{key:"fetchNewTiles",value:function(n){n.forEach(C=>{const o=C.remoteId.split("."),A={zoomLevel:o[1],tilePos:o.slice(2,o.length).map(s=>+s)};this.fetchedTiles[C.tileId]=C,this.fetchedTiles[C.tileId].tileData=A,this.fetching.has(C.remoteId)&&this.fetching.delete(C.remoteId)}),this.synchronizeTilesAndGraphics()}}]),I}(YVe);var nx=Array.prototype.slice;function rHt(e){return e}var J1=1,O1=2,Kz=3,KZ=4,sre=1e-6;function oHt(e){return"translate("+e+",0)"}function AHt(e){return"translate(0,"+e+")"}function aHt(e){return g=>+e(g)}function sHt(e,g){return g=Math.max(0,e.bandwidth()-g*2)/2,e.round()&&(g=Math.round(g)),I=>+e(I)+g}function lHt(){return!this.__axis}function Ik(e,g){var I=[],i=null,n=null,C=6,r=6,o=3,A=typeof window<"u"&&window.devicePixelRatio>1?0:.5,s=e===J1||e===KZ?-1:1,a=e===KZ||e===O1?"x":"y",l=e===J1||e===Kz?oHt:AHt;function c(u){var d=i??(g.ticks?g.ticks.apply(g,I):g.domain()),h=n??(g.tickFormat?g.tickFormat.apply(g,I):rHt),m=Math.max(C,0)+o,f=g.range(),b=+f[0]+A,p=+f[f.length-1]+A,y=(g.bandwidth?sHt:aHt)(g.copy(),A),Z=u.selection?u.selection():u,B=Z.selectAll(".domain").data([null]),G=Z.selectAll(".tick").data(d,g).order(),v=G.exit(),w=G.enter().append("g").attr("class","tick"),V=G.select("line"),S=G.select("text");B=B.merge(B.enter().insert("path",".tick").attr("class","domain").attr("stroke","currentColor")),G=G.merge(w),V=V.merge(w.append("line").attr("stroke","currentColor").attr(a+"2",s*C)),S=S.merge(w.append("text").attr("fill","currentColor").attr(a,s*m).attr("dy",e===J1?"0em":e===Kz?"0.71em":"0.32em")),u!==Z&&(B=B.transition(u),G=G.transition(u),V=V.transition(u),S=S.transition(u),v=v.transition(u).attr("opacity",sre).attr("transform",function(X){return isFinite(X=y(X))?l(X+A):this.getAttribute("transform")}),w.attr("opacity",sre).attr("transform",function(X){var W=this.parentNode.__axis;return l((W&&isFinite(W=W(X))?W:y(X))+A)})),v.remove(),B.attr("d",e===KZ||e===O1?r?"M"+s*r+","+b+"H"+A+"V"+p+"H"+s*r:"M"+A+","+b+"V"+p:r?"M"+b+","+s*r+"V"+A+"H"+p+"V"+s*r:"M"+b+","+A+"H"+p),G.attr("opacity",1).attr("transform",function(X){return l(y(X)+A)}),V.attr(a+"2",s*C),S.attr(a,s*m).text(h),Z.filter(lHt).attr("fill","none").attr("font-size",10).attr("font-family","sans-serif").attr("text-anchor",e===O1?"start":e===KZ?"end":"middle"),Z.each(function(){this.__axis=y})}return c.scale=function(u){return arguments.length?(g=u,c):g},c.ticks=function(){return I=nx.call(arguments),c},c.tickArguments=function(u){return arguments.length?(I=u==null?[]:nx.call(u),c):I.slice()},c.tickValues=function(u){return arguments.length?(i=u==null?null:nx.call(u),c):i&&i.slice()},c.tickFormat=function(u){return arguments.length?(n=u,c):n},c.tickSize=function(u){return arguments.length?(C=r=+u,c):C},c.tickSizeInner=function(u){return arguments.length?(C=+u,c):C},c.tickSizeOuter=function(u){return arguments.length?(r=+u,c):r},c.tickPadding=function(u){return arguments.length?(o=+u,c):o},c.offset=function(u){return arguments.length?(A=+u,c):A},c}function DVe(e){return Ik(J1,e)}function cHt(e){return Ik(O1,e)}function uHt(e){return Ik(Kz,e)}function xVe(e){return Ik(KZ,e)}const dHt=Object.freeze(Object.defineProperty({__proto__:null,axisBottom:uHt,axisLeft:xVe,axisRight:cHt,axisTop:DVe},Symbol.toStringTag,{value:"Module"}));function hHt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function lre(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function X9(e){return X9=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},X9(e)}let om=function(e){bHt(I,e);var g=yHt(I);function I(i,n){var C;hHt(this,I),C=g.call(this,i,n);const{svgElement:r}=i;return C.gMain=cg(r).append("g"),C.clipUid=Ag.nice(),C.clipRect=C.gMain.append("clipPath").attr("id",`track-bounds-${C.clipUid}`).append("rect"),C.gMain.attr("clip-path",`url(#track-bounds-${C.clipUid})`),C}return mHt(I,[{key:"setPosition",value:function(n){this.position=n,this.gMain.attr("transform",`translate(${this.position[0]},${this.position[1]})`),this.draw()}},{key:"setDimensions",value:function(n){this.dimensions=n,this._xScale.range([0,this.dimensions[0]]),this._yScale.range([0,this.dimensions[1]]),n[0]>=0&&n[1]>=0?(this.clipRect.attr("width",n[0]),this.clipRect.attr("height",n[1])):(this.clipRect.attr("width",0),this.clipRect.attr("height",0)),this.draw()}},{key:"remove",value:function(){this.gMain.remove(),this.gMain=null}},{key:"draw",value:function(){return this}}]),I}(Rp);function BHt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function cre(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function ch(e){return ch=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},ch(e)}let FVe=function(e){WHt(I,e);var g=XHt(I);function I(i,n){var C;return BHt(this,I),C=g.call(this,i,n),C.axis=DVe(C._xScale),C.gAxis=C.gMain.append("g"),C.tilesetInfo=!0,C}return SHt(I,[{key:"setDimensions",value:function(n){tv(ch(I.prototype),"setDimensions",this).call(this,n),this.axis.ticks(Math.ceil(this.dimensions[0]/150)),this.gAxis.attr("transform",`translate(0,${n[1]})`)}},{key:"draw",value:function(){return this.axis.scale(this._xScale),this.gAxis.call(this.axis),this}},{key:"zoomed",value:function(n,C){tv(ch(I.prototype),"zoomed",this).call(this,n,C),this.draw()}}]),I}(om);function kHt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function ure(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function uh(e){return uh=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},uh(e)}let EVe=function(e){FHt(I,e);var g=EHt(I);function I(i,n){var C;return kHt(this,I),C=g.call(this,i,n),C.axis=xVe(C._yScale),C.gAxis=C.gMain.append("g"),C.tilesetInfo=!0,C}return YHt(I,[{key:"setDimensions",value:function(n){gv(uh(I.prototype),"setDimensions",this).call(this,n),this.axis.ticks(Math.ceil(this.dimensions[1]/150)),this.gAxis.attr("transform",`translate(${n[0]},0)`)}},{key:"draw",value:function(){return this.axis.scale(this._yScale),this.gAxis.call(this.axis),this}},{key:"zoomed",value:function(n,C){gv(uh(I.prototype),"zoomed",this).call(this,n,C),this.draw()}}]),I}(om);var og={},WI={},hj=32;WI.INT_BITS=hj;WI.INT_MAX=2147483647;WI.INT_MIN=-1<0)-(e<0)};WI.abs=function(e){var g=e>>hj-1;return(e^g)-g};WI.min=function(e,g){return g^(e^g)&-(e65535)<<4,e>>>=g,I=(e>255)<<3,e>>>=I,g|=I,I=(e>15)<<2,e>>>=I,g|=I,I=(e>3)<<1,e>>>=I,g|=I,g|e>>1};WI.log10=function(e){return e>=1e9?9:e>=1e8?8:e>=1e7?7:e>=1e6?6:e>=1e5?5:e>=1e4?4:e>=1e3?3:e>=100?2:e>=10?1:0};WI.popCount=function(e){return e=e-(e>>>1&1431655765),e=(e&858993459)+(e>>>2&858993459),(e+(e>>>4)&252645135)*16843009>>>24};function MVe(e){var g=32;return e&=-e,e&&g--,e&65535&&(g-=16),e&16711935&&(g-=8),e&252645135&&(g-=4),e&858993459&&(g-=2),e&1431655765&&(g-=1),g}WI.countTrailingZeros=MVe;WI.nextPow2=function(e){return e+=e===0,--e,e|=e>>>1,e|=e>>>2,e|=e>>>4,e|=e>>>8,e|=e>>>16,e+1};WI.prevPow2=function(e){return e|=e>>>1,e|=e>>>2,e|=e>>>4,e|=e>>>8,e|=e>>>16,e-(e>>>1)};WI.parity=function(e){return e^=e>>>16,e^=e>>>8,e^=e>>>4,e&=15,27030>>>e&1};var DZ=new Array(256);(function(e){for(var g=0;g<256;++g){var I=g,i=g,n=7;for(I>>>=1;I;I>>>=1)i<<=1,i|=I&1,--n;e[g]=i<>>8&255]<<16|DZ[e>>>16&255]<<8|DZ[e>>>24&255]};WI.interleave2=function(e,g){return e&=65535,e=(e|e<<8)&16711935,e=(e|e<<4)&252645135,e=(e|e<<2)&858993459,e=(e|e<<1)&1431655765,g&=65535,g=(g|g<<8)&16711935,g=(g|g<<4)&252645135,g=(g|g<<2)&858993459,g=(g|g<<1)&1431655765,e|g<<1};WI.deinterleave2=function(e,g){return e=e>>>g&1431655765,e=(e|e>>>1)&858993459,e=(e|e>>>2)&252645135,e=(e|e>>>4)&16711935,e=(e|e>>>16)&65535,e<<16>>16};WI.interleave3=function(e,g,I){return e&=1023,e=(e|e<<16)&4278190335,e=(e|e<<8)&251719695,e=(e|e<<4)&3272356035,e=(e|e<<2)&1227133513,g&=1023,g=(g|g<<16)&4278190335,g=(g|g<<8)&251719695,g=(g|g<<4)&3272356035,g=(g|g<<2)&1227133513,e|=g<<1,I&=1023,I=(I|I<<16)&4278190335,I=(I|I<<8)&251719695,I=(I|I<<4)&3272356035,I=(I|I<<2)&1227133513,e|I<<2};WI.deinterleave3=function(e,g){return e=e>>>g&1227133513,e=(e|e>>>2)&3272356035,e=(e|e>>>4)&251719695,e=(e|e>>>8)&4278190335,e=(e|e>>>16)&1023,e<<22>>22};WI.nextCombination=function(e){var g=e|e-1;return g+1|(~g&-~g)-1>>>MVe(e)+1};function zVe(e,g,I){var i=e[I]|0;if(i<=0)return[];var n=new Array(i),C;if(I===e.length-1)for(C=0;C"u"&&(g=0),typeof e){case"number":if(e>0)return JHt(e|0,g);break;case"object":if(typeof e.length=="number")return zVe(e,g,0);break}return[]}var _Ht=OHt,PVe={},ik={};ik.byteLength=QHt;ik.toByteArray=$Ht;ik.fromByteArray=tTt;var PA=[],wr=[],LHt=typeof Uint8Array<"u"?Uint8Array:Array,Cx="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(var zm=0,UHt=Cx.length;zm0)throw new Error("Invalid string. Length must be a multiple of 4");var I=e.indexOf("=");I===-1&&(I=g);var i=I===g?0:4-I%4;return[I,i]}function QHt(e){var g=JVe(e),I=g[0],i=g[1];return(I+i)*3/4-i}function jHt(e,g,I){return(g+I)*3/4-I}function $Ht(e){var g,I=JVe(e),i=I[0],n=I[1],C=new LHt(jHt(e,i,n)),r=0,o=n>0?i-4:i,A;for(A=0;A>16&255,C[r++]=g>>8&255,C[r++]=g&255;return n===2&&(g=wr[e.charCodeAt(A)]<<2|wr[e.charCodeAt(A+1)]>>4,C[r++]=g&255),n===1&&(g=wr[e.charCodeAt(A)]<<10|wr[e.charCodeAt(A+1)]<<4|wr[e.charCodeAt(A+2)]>>2,C[r++]=g>>8&255,C[r++]=g&255),C}function qHt(e){return PA[e>>18&63]+PA[e>>12&63]+PA[e>>6&63]+PA[e&63]}function eTt(e,g,I){for(var i,n=[],C=g;Co?o:r+C));return i===1?(g=e[I-1],n.push(PA[g>>2]+PA[g<<4&63]+"==")):i===2&&(g=(e[I-2]<<8)+e[I-1],n.push(PA[g>>10]+PA[g>>4&63]+PA[g<<2&63]+"=")),n.join("")}var mj={};/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh */mj.read=function(e,g,I,i,n){var C,r,o=n*8-i-1,A=(1<>1,a=-7,l=I?n-1:0,c=I?-1:1,u=e[g+l];for(l+=c,C=u&(1<<-a)-1,u>>=-a,a+=o;a>0;C=C*256+e[g+l],l+=c,a-=8);for(r=C&(1<<-a)-1,C>>=-a,a+=i;a>0;r=r*256+e[g+l],l+=c,a-=8);if(C===0)C=1-s;else{if(C===A)return r?NaN:(u?-1:1)*(1/0);r=r+Math.pow(2,i),C=C-s}return(u?-1:1)*r*Math.pow(2,C-i)};mj.write=function(e,g,I,i,n,C){var r,o,A,s=C*8-n-1,a=(1<>1,c=n===23?Math.pow(2,-24)-Math.pow(2,-77):0,u=i?0:C-1,d=i?1:-1,h=g<0||g===0&&1/g<0?1:0;for(g=Math.abs(g),isNaN(g)||g===1/0?(o=isNaN(g)?1:0,r=a):(r=Math.floor(Math.log(g)/Math.LN2),g*(A=Math.pow(2,-r))<1&&(r--,A*=2),r+l>=1?g+=c/A:g+=c*Math.pow(2,1-l),g*A>=2&&(r++,A/=2),r+l>=a?(o=0,r=a):r+l>=1?(o=(g*A-1)*Math.pow(2,n),r=r+l):(o=g*Math.pow(2,l-1)*Math.pow(2,n),r=0));n>=8;e[I+u]=o&255,u+=d,o/=256,n-=8);for(r=r<0;e[I+u]=r&255,u+=d,r/=256,s-=8);e[I+u-d]|=h*128};/*! * The buffer module from node.js, for the browser. * * @author Feross Aboukhadijeh * @license MIT - */(function(g){function e(ie,E){if(!(ie instanceof E))throw new TypeError("Cannot call a class as a function")}function I(ie,E){for(var O=0;O"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function c(ie){return c=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(O){return O.__proto__||Object.getPrototypeOf(O)},c(ie)}const u=Qk,d=Qj,h=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;g.Buffer=p,g.SlowBuffer=V,g.INSPECT_MAX_BYTES=50;const m=2147483647;g.kMaxLength=m,p.TYPED_ARRAY_SUPPORT=f(),!p.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function f(){try{const ie=new Uint8Array(1),E={foo:function(){return 42}};return Object.setPrototypeOf(E,Uint8Array.prototype),Object.setPrototypeOf(ie,E),ie.foo()===42}catch{return!1}}Object.defineProperty(p.prototype,"parent",{enumerable:!0,get:function(){if(p.isBuffer(this))return this.buffer}}),Object.defineProperty(p.prototype,"offset",{enumerable:!0,get:function(){if(p.isBuffer(this))return this.byteOffset}});function b(ie){if(ie>m)throw new RangeError('The value "'+ie+'" is invalid for option "size"');const E=new Uint8Array(ie);return Object.setPrototypeOf(E,p.prototype),E}function p(ie,E,O){if(typeof ie=="number"){if(typeof E=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return G(ie)}return y(ie,E,O)}p.poolSize=8192;function y(ie,E,O){if(typeof ie=="string")return B(ie,E);if(ArrayBuffer.isView(ie))return R(ie);if(ie==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof ie);if(qe(ie,ArrayBuffer)||ie&&qe(ie.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(qe(ie,SharedArrayBuffer)||ie&&qe(ie.buffer,SharedArrayBuffer)))return S(ie,E,O);if(typeof ie=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');const me=ie.valueOf&&ie.valueOf();if(me!=null&&me!==ie)return p.from(me,E,O);const Ne=X(ie);if(Ne)return Ne;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof ie[Symbol.toPrimitive]=="function")return p.from(ie[Symbol.toPrimitive]("string"),E,O);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof ie)}p.from=function(ie,E,O){return y(ie,E,O)},Object.setPrototypeOf(p.prototype,Uint8Array.prototype),Object.setPrototypeOf(p,Uint8Array);function Z(ie){if(typeof ie!="number")throw new TypeError('"size" argument must be of type number');if(ie<0)throw new RangeError('The value "'+ie+'" is invalid for option "size"')}function v(ie,E,O){return Z(ie),ie<=0?b(ie):E!==void 0?typeof O=="string"?b(ie).fill(E,O):b(ie).fill(E):b(ie)}p.alloc=function(ie,E,O){return v(ie,E,O)};function G(ie){return Z(ie),b(ie<0?0:W(ie)|0)}p.allocUnsafe=function(ie){return G(ie)},p.allocUnsafeSlow=function(ie){return G(ie)};function B(ie,E){if((typeof E!="string"||E==="")&&(E="utf8"),!p.isEncoding(E))throw new TypeError("Unknown encoding: "+E);const O=H(ie,E)|0;let me=b(O);const Ne=me.write(ie,E);return Ne!==O&&(me=me.slice(0,Ne)),me}function w(ie){const E=ie.length<0?0:W(ie.length)|0,O=b(E);for(let me=0;me=m)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+m.toString(16)+" bytes");return ie|0}function V(ie){return+ie!=ie&&(ie=0),p.alloc(+ie)}p.isBuffer=function(E){return E!=null&&E._isBuffer===!0&&E!==p.prototype},p.compare=function(E,O){if(qe(E,Uint8Array)&&(E=p.from(E,E.offset,E.byteLength)),qe(O,Uint8Array)&&(O=p.from(O,O.offset,O.byteLength)),!p.isBuffer(E)||!p.isBuffer(O))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(E===O)return 0;let me=E.length,Ne=O.length;for(let ue=0,se=Math.min(me,Ne);ueNe.length?(p.isBuffer(se)||(se=p.from(se)),se.copy(Ne,ue)):Uint8Array.prototype.set.call(Ne,se,ue);else if(p.isBuffer(se))se.copy(Ne,ue);else throw new TypeError('"list" argument must be an Array of Buffers');ue+=se.length}return Ne};function H(ie,E){if(p.isBuffer(ie))return ie.length;if(ArrayBuffer.isView(ie)||qe(ie,ArrayBuffer))return ie.byteLength;if(typeof ie!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof ie);const O=ie.length,me=arguments.length>2&&arguments[2]===!0;if(!me&&O===0)return 0;let Ne=!1;for(;;)switch(E){case"ascii":case"latin1":case"binary":return O;case"utf8":case"utf-8":return k(ie).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return O*2;case"hex":return O>>>1;case"base64":return we(ie).length;default:if(Ne)return me?-1:k(ie).length;E=(""+E).toLowerCase(),Ne=!0}}p.byteLength=H;function D(ie,E,O){let me=!1;if((E===void 0||E<0)&&(E=0),E>this.length||((O===void 0||O>this.length)&&(O=this.length),O<=0)||(O>>>=0,E>>>=0,O<=E))return"";for(ie||(ie="utf8");;)switch(ie){case"hex":return Ge(this,E,O);case"utf8":case"utf-8":return Q(this,E,O);case"ascii":return Ce(this,E,O);case"latin1":case"binary":return Ze(this,E,O);case"base64":return ee(this,E,O);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return ve(this,E,O);default:if(me)throw new TypeError("Unknown encoding: "+ie);ie=(ie+"").toLowerCase(),me=!0}}p.prototype._isBuffer=!0;function Y(ie,E,O){const me=ie[E];ie[E]=ie[O],ie[O]=me}p.prototype.swap16=function(){const E=this.length;if(E%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let O=0;OO&&(E+=" ... "),""},h&&(p.prototype[h]=p.prototype.inspect),p.prototype.compare=function(E,O,me,Ne,ue){if(qe(E,Uint8Array)&&(E=p.from(E,E.offset,E.byteLength)),!p.isBuffer(E))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof E);if(O===void 0&&(O=0),me===void 0&&(me=E?E.length:0),Ne===void 0&&(Ne=0),ue===void 0&&(ue=this.length),O<0||me>E.length||Ne<0||ue>this.length)throw new RangeError("out of range index");if(Ne>=ue&&O>=me)return 0;if(Ne>=ue)return-1;if(O>=me)return 1;if(O>>>=0,me>>>=0,Ne>>>=0,ue>>>=0,this===E)return 0;let se=ue-Ne,re=me-O;const oe=Math.min(se,re),Se=this.slice(Ne,ue),Ke=E.slice(O,me);for(let Ye=0;Ye2147483647?O=2147483647:O<-2147483648&&(O=-2147483648),O=+O,mt(O)&&(O=Ne?0:ie.length-1),O<0&&(O=ie.length+O),O>=ie.length){if(Ne)return-1;O=ie.length-1}else if(O<0)if(Ne)O=0;else return-1;if(typeof E=="string"&&(E=p.from(E,me)),p.isBuffer(E))return E.length===0?-1:_(ie,E,O,me,Ne);if(typeof E=="number")return E=E&255,typeof Uint8Array.prototype.indexOf=="function"?Ne?Uint8Array.prototype.indexOf.call(ie,E,O):Uint8Array.prototype.lastIndexOf.call(ie,E,O):_(ie,[E],O,me,Ne);throw new TypeError("val must be string, number or Buffer")}function _(ie,E,O,me,Ne){let ue=1,se=ie.length,re=E.length;if(me!==void 0&&(me=String(me).toLowerCase(),me==="ucs2"||me==="ucs-2"||me==="utf16le"||me==="utf-16le")){if(ie.length<2||E.length<2)return-1;ue=2,se/=2,re/=2,O/=2}function oe(Ke,Ye){return ue===1?Ke[Ye]:Ke.readUInt16BE(Ye*ue)}let Se;if(Ne){let Ke=-1;for(Se=O;Sese&&(O=se-re),Se=O;Se>=0;Se--){let Ke=!0;for(let Ye=0;YeNe&&(me=Ne)):me=Ne;const ue=E.length;me>ue/2&&(me=ue/2);let se;for(se=0;se>>0,isFinite(me)?(me=me>>>0,Ne===void 0&&(Ne="utf8")):(Ne=me,me=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");const ue=this.length-O;if((me===void 0||me>ue)&&(me=ue),E.length>0&&(me<0||O<0)||O>this.length)throw new RangeError("Attempt to write outside buffer bounds");Ne||(Ne="utf8");let se=!1;for(;;)switch(Ne){case"hex":return J(this,E,O,me);case"utf8":case"utf-8":return te(this,E,O,me);case"ascii":case"latin1":case"binary":return q(this,E,O,me);case"base64":return $(this,E,O,me);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return j(this,E,O,me);default:if(se)throw new TypeError("Unknown encoding: "+Ne);Ne=(""+Ne).toLowerCase(),se=!0}},p.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function ee(ie,E,O){return E===0&&O===ie.length?u.fromByteArray(ie):u.fromByteArray(ie.slice(E,O))}function Q(ie,E,O){O=Math.min(ie.length,O);const me=[];let Ne=E;for(;Ne239?4:ue>223?3:ue>191?2:1;if(Ne+re<=O){let oe,Se,Ke,Ye;switch(re){case 1:ue<128&&(se=ue);break;case 2:oe=ie[Ne+1],(oe&192)===128&&(Ye=(ue&31)<<6|oe&63,Ye>127&&(se=Ye));break;case 3:oe=ie[Ne+1],Se=ie[Ne+2],(oe&192)===128&&(Se&192)===128&&(Ye=(ue&15)<<12|(oe&63)<<6|Se&63,Ye>2047&&(Ye<55296||Ye>57343)&&(se=Ye));break;case 4:oe=ie[Ne+1],Se=ie[Ne+2],Ke=ie[Ne+3],(oe&192)===128&&(Se&192)===128&&(Ke&192)===128&&(Ye=(ue&15)<<18|(oe&63)<<12|(Se&63)<<6|Ke&63,Ye>65535&&Ye<1114112&&(se=Ye))}}se===null?(se=65533,re=1):se>65535&&(se-=65536,me.push(se>>>10&1023|55296),se=56320|se&1023),me.push(se),Ne+=re}return fe(me)}const ne=4096;function fe(ie){const E=ie.length;if(E<=ne)return String.fromCharCode.apply(String,ie);let O="",me=0;for(;meme)&&(O=me);let Ne="";for(let ue=E;ueme&&(E=me),O<0?(O+=me,O<0&&(O=0)):O>me&&(O=me),OO)throw new RangeError("Trying to access beyond buffer length")}p.prototype.readUintLE=p.prototype.readUIntLE=function(E,O,me){E=E>>>0,O=O>>>0,me||ke(E,O,this.length);let Ne=this[E],ue=1,se=0;for(;++se>>0,O=O>>>0,me||ke(E,O,this.length);let Ne=this[E+--O],ue=1;for(;O>0&&(ue*=256);)Ne+=this[E+--O]*ue;return Ne},p.prototype.readUint8=p.prototype.readUInt8=function(E,O){return E=E>>>0,O||ke(E,1,this.length),this[E]},p.prototype.readUint16LE=p.prototype.readUInt16LE=function(E,O){return E=E>>>0,O||ke(E,2,this.length),this[E]|this[E+1]<<8},p.prototype.readUint16BE=p.prototype.readUInt16BE=function(E,O){return E=E>>>0,O||ke(E,2,this.length),this[E]<<8|this[E+1]},p.prototype.readUint32LE=p.prototype.readUInt32LE=function(E,O){return E=E>>>0,O||ke(E,4,this.length),(this[E]|this[E+1]<<8|this[E+2]<<16)+this[E+3]*16777216},p.prototype.readUint32BE=p.prototype.readUInt32BE=function(E,O){return E=E>>>0,O||ke(E,4,this.length),this[E]*16777216+(this[E+1]<<16|this[E+2]<<8|this[E+3])},p.prototype.readBigUInt64LE=ut(function(E){E=E>>>0,ye(E,"offset");const O=this[E],me=this[E+7];(O===void 0||me===void 0)&&We(E,this.length-8);const Ne=O+this[++E]*2**8+this[++E]*2**16+this[++E]*2**24,ue=this[++E]+this[++E]*2**8+this[++E]*2**16+me*2**24;return BigInt(Ne)+(BigInt(ue)<>>0,ye(E,"offset");const O=this[E],me=this[E+7];(O===void 0||me===void 0)&&We(E,this.length-8);const Ne=O*2**24+this[++E]*2**16+this[++E]*2**8+this[++E],ue=this[++E]*2**24+this[++E]*2**16+this[++E]*2**8+me;return(BigInt(Ne)<>>0,O=O>>>0,me||ke(E,O,this.length);let Ne=this[E],ue=1,se=0;for(;++se=ue&&(Ne-=Math.pow(2,8*O)),Ne},p.prototype.readIntBE=function(E,O,me){E=E>>>0,O=O>>>0,me||ke(E,O,this.length);let Ne=O,ue=1,se=this[E+--Ne];for(;Ne>0&&(ue*=256);)se+=this[E+--Ne]*ue;return ue*=128,se>=ue&&(se-=Math.pow(2,8*O)),se},p.prototype.readInt8=function(E,O){return E=E>>>0,O||ke(E,1,this.length),this[E]&128?(255-this[E]+1)*-1:this[E]},p.prototype.readInt16LE=function(E,O){E=E>>>0,O||ke(E,2,this.length);const me=this[E]|this[E+1]<<8;return me&32768?me|4294901760:me},p.prototype.readInt16BE=function(E,O){E=E>>>0,O||ke(E,2,this.length);const me=this[E+1]|this[E]<<8;return me&32768?me|4294901760:me},p.prototype.readInt32LE=function(E,O){return E=E>>>0,O||ke(E,4,this.length),this[E]|this[E+1]<<8|this[E+2]<<16|this[E+3]<<24},p.prototype.readInt32BE=function(E,O){return E=E>>>0,O||ke(E,4,this.length),this[E]<<24|this[E+1]<<16|this[E+2]<<8|this[E+3]},p.prototype.readBigInt64LE=ut(function(E){E=E>>>0,ye(E,"offset");const O=this[E],me=this[E+7];(O===void 0||me===void 0)&&We(E,this.length-8);const Ne=this[E+4]+this[E+5]*2**8+this[E+6]*2**16+(me<<24);return(BigInt(Ne)<>>0,ye(E,"offset");const O=this[E],me=this[E+7];(O===void 0||me===void 0)&&We(E,this.length-8);const Ne=(O<<24)+this[++E]*2**16+this[++E]*2**8+this[++E];return(BigInt(Ne)<>>0,O||ke(E,4,this.length),d.read(this,E,!0,23,4)},p.prototype.readFloatBE=function(E,O){return E=E>>>0,O||ke(E,4,this.length),d.read(this,E,!1,23,4)},p.prototype.readDoubleLE=function(E,O){return E=E>>>0,O||ke(E,8,this.length),d.read(this,E,!0,52,8)},p.prototype.readDoubleBE=function(E,O){return E=E>>>0,O||ke(E,8,this.length),d.read(this,E,!1,52,8)};function Xe(ie,E,O,me,Ne,ue){if(!p.isBuffer(ie))throw new TypeError('"buffer" argument must be a Buffer instance');if(E>Ne||Eie.length)throw new RangeError("Index out of range")}p.prototype.writeUintLE=p.prototype.writeUIntLE=function(E,O,me,Ne){if(E=+E,O=O>>>0,me=me>>>0,!Ne){const re=Math.pow(2,8*me)-1;Xe(this,E,O,me,re,0)}let ue=1,se=0;for(this[O]=E&255;++se>>0,me=me>>>0,!Ne){const re=Math.pow(2,8*me)-1;Xe(this,E,O,me,re,0)}let ue=me-1,se=1;for(this[O+ue]=E&255;--ue>=0&&(se*=256);)this[O+ue]=E/se&255;return O+me},p.prototype.writeUint8=p.prototype.writeUInt8=function(E,O,me){return E=+E,O=O>>>0,me||Xe(this,E,O,1,255,0),this[O]=E&255,O+1},p.prototype.writeUint16LE=p.prototype.writeUInt16LE=function(E,O,me){return E=+E,O=O>>>0,me||Xe(this,E,O,2,65535,0),this[O]=E&255,this[O+1]=E>>>8,O+2},p.prototype.writeUint16BE=p.prototype.writeUInt16BE=function(E,O,me){return E=+E,O=O>>>0,me||Xe(this,E,O,2,65535,0),this[O]=E>>>8,this[O+1]=E&255,O+2},p.prototype.writeUint32LE=p.prototype.writeUInt32LE=function(E,O,me){return E=+E,O=O>>>0,me||Xe(this,E,O,4,4294967295,0),this[O+3]=E>>>24,this[O+2]=E>>>16,this[O+1]=E>>>8,this[O]=E&255,O+4},p.prototype.writeUint32BE=p.prototype.writeUInt32BE=function(E,O,me){return E=+E,O=O>>>0,me||Xe(this,E,O,4,4294967295,0),this[O]=E>>>24,this[O+1]=E>>>16,this[O+2]=E>>>8,this[O+3]=E&255,O+4};function Oe(ie,E,O,me,Ne){le(E,me,Ne,ie,O,7);let ue=Number(E&BigInt(4294967295));ie[O++]=ue,ue=ue>>8,ie[O++]=ue,ue=ue>>8,ie[O++]=ue,ue=ue>>8,ie[O++]=ue;let se=Number(E>>BigInt(32)&BigInt(4294967295));return ie[O++]=se,se=se>>8,ie[O++]=se,se=se>>8,ie[O++]=se,se=se>>8,ie[O++]=se,O}function ze(ie,E,O,me,Ne){le(E,me,Ne,ie,O,7);let ue=Number(E&BigInt(4294967295));ie[O+7]=ue,ue=ue>>8,ie[O+6]=ue,ue=ue>>8,ie[O+5]=ue,ue=ue>>8,ie[O+4]=ue;let se=Number(E>>BigInt(32)&BigInt(4294967295));return ie[O+3]=se,se=se>>8,ie[O+2]=se,se=se>>8,ie[O+1]=se,se=se>>8,ie[O]=se,O+8}p.prototype.writeBigUInt64LE=ut(function(E,O=0){return Oe(this,E,O,BigInt(0),BigInt("0xffffffffffffffff"))}),p.prototype.writeBigUInt64BE=ut(function(E,O=0){return ze(this,E,O,BigInt(0),BigInt("0xffffffffffffffff"))}),p.prototype.writeIntLE=function(E,O,me,Ne){if(E=+E,O=O>>>0,!Ne){const oe=Math.pow(2,8*me-1);Xe(this,E,O,me,oe-1,-oe)}let ue=0,se=1,re=0;for(this[O]=E&255;++ue>0)-re&255;return O+me},p.prototype.writeIntBE=function(E,O,me,Ne){if(E=+E,O=O>>>0,!Ne){const oe=Math.pow(2,8*me-1);Xe(this,E,O,me,oe-1,-oe)}let ue=me-1,se=1,re=0;for(this[O+ue]=E&255;--ue>=0&&(se*=256);)E<0&&re===0&&this[O+ue+1]!==0&&(re=1),this[O+ue]=(E/se>>0)-re&255;return O+me},p.prototype.writeInt8=function(E,O,me){return E=+E,O=O>>>0,me||Xe(this,E,O,1,127,-128),E<0&&(E=255+E+1),this[O]=E&255,O+1},p.prototype.writeInt16LE=function(E,O,me){return E=+E,O=O>>>0,me||Xe(this,E,O,2,32767,-32768),this[O]=E&255,this[O+1]=E>>>8,O+2},p.prototype.writeInt16BE=function(E,O,me){return E=+E,O=O>>>0,me||Xe(this,E,O,2,32767,-32768),this[O]=E>>>8,this[O+1]=E&255,O+2},p.prototype.writeInt32LE=function(E,O,me){return E=+E,O=O>>>0,me||Xe(this,E,O,4,2147483647,-2147483648),this[O]=E&255,this[O+1]=E>>>8,this[O+2]=E>>>16,this[O+3]=E>>>24,O+4},p.prototype.writeInt32BE=function(E,O,me){return E=+E,O=O>>>0,me||Xe(this,E,O,4,2147483647,-2147483648),E<0&&(E=4294967295+E+1),this[O]=E>>>24,this[O+1]=E>>>16,this[O+2]=E>>>8,this[O+3]=E&255,O+4},p.prototype.writeBigInt64LE=ut(function(E,O=0){return Oe(this,E,O,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),p.prototype.writeBigInt64BE=ut(function(E,O=0){return ze(this,E,O,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function Me(ie,E,O,me,Ne,ue){if(O+me>ie.length)throw new RangeError("Index out of range");if(O<0)throw new RangeError("Index out of range")}function Ue(ie,E,O,me,Ne){return E=+E,O=O>>>0,Ne||Me(ie,E,O,4),d.write(ie,E,O,me,23,4),O+4}p.prototype.writeFloatLE=function(E,O,me){return Ue(this,E,O,!0,me)},p.prototype.writeFloatBE=function(E,O,me){return Ue(this,E,O,!1,me)};function _e(ie,E,O,me,Ne){return E=+E,O=O>>>0,Ne||Me(ie,E,O,8),d.write(ie,E,O,me,52,8),O+8}p.prototype.writeDoubleLE=function(E,O,me){return _e(this,E,O,!0,me)},p.prototype.writeDoubleBE=function(E,O,me){return _e(this,E,O,!1,me)},p.prototype.copy=function(E,O,me,Ne){if(!p.isBuffer(E))throw new TypeError("argument should be a Buffer");if(me||(me=0),!Ne&&Ne!==0&&(Ne=this.length),O>=E.length&&(O=E.length),O||(O=0),Ne>0&&Ne=this.length)throw new RangeError("Index out of range");if(Ne<0)throw new RangeError("sourceEnd out of bounds");Ne>this.length&&(Ne=this.length),E.length-O>>0,me=me===void 0?this.length:me>>>0,E||(E=0);let ue;if(typeof E=="number")for(ue=O;ue2**32?Ne=rt(String(O)):typeof O=="bigint"&&(Ne=String(O),(O>BigInt(2)**BigInt(32)||O<-(BigInt(2)**BigInt(32)))&&(Ne=rt(Ne)),Ne+="n"),me+=` It must be ${E}. Received ${Ne}`,me},RangeError);function rt(ie){let E="",O=ie.length;const me=ie[0]==="-"?1:0;for(;O>=me+4;O-=3)E=`_${ie.slice(O-3,O)}${E}`;return`${ie.slice(0,O)}${E}`}function Te(ie,E,O){ye(E,"offset"),(ie[E]===void 0||ie[E+O]===void 0)&&We(E,ie.length-(O+1))}function le(ie,E,O,me,Ne,ue){if(ie>O||ie3?E===0||E===BigInt(0)?re=`>= 0${se} and < 2${se} ** ${(ue+1)*8}${se}`:re=`>= -(2${se} ** ${(ue+1)*8-1}${se}) and < 2 ** ${(ue+1)*8-1}${se}`:re=`>= ${E}${se} and <= ${O}${se}`,new At.ERR_OUT_OF_RANGE("value",re,ie)}Te(me,Ne,ue)}function ye(ie,E){if(typeof ie!="number")throw new At.ERR_INVALID_ARG_TYPE(E,"number",ie)}function We(ie,E,O){throw Math.floor(ie)!==ie?(ye(ie,O),new At.ERR_OUT_OF_RANGE(O||"offset","an integer",ie)):E<0?new At.ERR_BUFFER_OUT_OF_BOUNDS:new At.ERR_OUT_OF_RANGE(O||"offset",`>= ${O?1:0} and <= ${E}`,ie)}const K=/[^+/0-9A-Za-z-_]/g;function T(ie){if(ie=ie.split("=")[0],ie=ie.trim().replace(K,""),ie.length<2)return"";for(;ie.length%4!==0;)ie=ie+"=";return ie}function k(ie,E){E=E||1/0;let O;const me=ie.length;let Ne=null;const ue=[];for(let se=0;se55295&&O<57344){if(!Ne){if(O>56319){(E-=3)>-1&&ue.push(239,191,189);continue}else if(se+1===me){(E-=3)>-1&&ue.push(239,191,189);continue}Ne=O;continue}if(O<56320){(E-=3)>-1&&ue.push(239,191,189),Ne=O;continue}O=(Ne-55296<<10|O-56320)+65536}else Ne&&(E-=3)>-1&&ue.push(239,191,189);if(Ne=null,O<128){if((E-=1)<0)break;ue.push(O)}else if(O<2048){if((E-=2)<0)break;ue.push(O>>6|192,O&63|128)}else if(O<65536){if((E-=3)<0)break;ue.push(O>>12|224,O>>6&63|128,O&63|128)}else if(O<1114112){if((E-=4)<0)break;ue.push(O>>18|240,O>>12&63|128,O>>6&63|128,O&63|128)}else throw new Error("Invalid code point")}return ue}function ge(ie){const E=[];for(let O=0;O>8,Ne=O%256,ue.push(Ne),ue.push(me);return ue}function we(ie){return u.toByteArray(T(ie))}function xe(ie,E,O,me){let Ne;for(Ne=0;Ne=E.length||Ne>=ie.length);++Ne)E[Ne+O]=ie[Ne];return Ne}function qe(ie,E){return ie instanceof E||ie!=null&&ie.constructor!=null&&ie.constructor.name!=null&&ie.constructor.name===E.name}function mt(ie){return ie!==ie}const St=function(){const ie="0123456789abcdef",E=new Array(256);for(let O=0;O<16;++O){const me=O*16;for(let Ne=0;Ne<16;++Ne)E[me+Ne]=ie[O]+ie[Ne]}return E}();function ut(ie){return typeof BigInt>"u"?Yt:ie}function Yt(){throw new Error("BigInt not supported")}})(e1e);var ru=TI,gn=dHt,g1e=e1e.Buffer;globalThis.__TYPEDARRAY_POOL||(globalThis.__TYPEDARRAY_POOL={UINT8:gn([32,0]),UINT16:gn([32,0]),UINT32:gn([32,0]),BIGUINT64:gn([32,0]),INT8:gn([32,0]),INT16:gn([32,0]),INT32:gn([32,0]),BIGINT64:gn([32,0]),FLOAT:gn([32,0]),DOUBLE:gn([32,0]),DATA:gn([32,0]),UINT8C:gn([32,0]),BUFFER:gn([32,0])});var BHt=typeof Uint8ClampedArray<"u",vHt=typeof BigUint64Array<"u",SHt=typeof BigInt64Array<"u",ni=globalThis.__TYPEDARRAY_POOL;ni.UINT8C||(ni.UINT8C=gn([32,0]));ni.BIGUINT64||(ni.BIGUINT64=gn([32,0]));ni.BIGINT64||(ni.BIGINT64=gn([32,0]));ni.BUFFER||(ni.BUFFER=gn([32,0]));var jk=ni.DATA,$k=ni.BUFFER;ug.free=function(e){if(g1e.isBuffer(e))$k[ru.log2(e.length)].push(e);else{if(Object.prototype.toString.call(e)!=="[object ArrayBuffer]"&&(e=e.buffer),!e)return;var I=e.length||e.byteLength,i=ru.log2(I)|0;jk[i].push(e)}};function I1e(g){if(g){var e=g.length||g.byteLength,I=ru.log2(e);jk[I].push(g)}}function wHt(g){I1e(g.buffer)}ug.freeUint8=ug.freeUint16=ug.freeUint32=ug.freeBigUint64=ug.freeInt8=ug.freeInt16=ug.freeInt32=ug.freeBigInt64=ug.freeFloat32=ug.freeFloat=ug.freeFloat64=ug.freeDouble=ug.freeUint8Clamped=ug.freeDataView=wHt;ug.freeArrayBuffer=I1e;ug.freeBuffer=function(e){$k[ru.log2(e.length)].push(e)};ug.malloc=function(e,I){if(I===void 0||I==="arraybuffer")return EC(e);switch(I){case"uint8":return jj(e);case"uint16":return i1e(e);case"uint32":return n1e(e);case"int8":return C1e(e);case"int16":return r1e(e);case"int32":return o1e(e);case"float":case"float32":return A1e(e);case"double":case"float64":return a1e(e);case"uint8_clamped":return s1e(e);case"bigint64":return c1e(e);case"biguint64":return l1e(e);case"buffer":return d1e(e);case"data":case"dataview":return u1e(e);default:return null}return null};function EC(e){var e=ru.nextPow2(e),I=ru.log2(e),i=jk[I];return i.length>0?i.pop():new ArrayBuffer(e)}ug.mallocArrayBuffer=EC;function jj(g){return new Uint8Array(EC(g),0,g)}ug.mallocUint8=jj;function i1e(g){return new Uint16Array(EC(2*g),0,g)}ug.mallocUint16=i1e;function n1e(g){return new Uint32Array(EC(4*g),0,g)}ug.mallocUint32=n1e;function C1e(g){return new Int8Array(EC(g),0,g)}ug.mallocInt8=C1e;function r1e(g){return new Int16Array(EC(2*g),0,g)}ug.mallocInt16=r1e;function o1e(g){return new Int32Array(EC(4*g),0,g)}ug.mallocInt32=o1e;function A1e(g){return new Float32Array(EC(4*g),0,g)}ug.mallocFloat32=ug.mallocFloat=A1e;function a1e(g){return new Float64Array(EC(8*g),0,g)}ug.mallocFloat64=ug.mallocDouble=a1e;function s1e(g){return BHt?new Uint8ClampedArray(EC(g),0,g):jj(g)}ug.mallocUint8Clamped=s1e;function l1e(g){return vHt?new BigUint64Array(EC(8*g),0,g):null}ug.mallocBigUint64=l1e;function c1e(g){return SHt?new BigInt64Array(EC(8*g),0,g):null}ug.mallocBigInt64=c1e;function u1e(g){return new DataView(EC(g),0,g)}ug.mallocDataView=u1e;function d1e(g){g=ru.nextPow2(g);var e=ru.log2(g),I=$k[e];return I.length>0?I.pop():new g1e(g)}ug.mallocBuffer=d1e;ug.clearCache=function(){for(var e=0;e<32;++e)ni.UINT8[e].length=0,ni.UINT16[e].length=0,ni.UINT32[e].length=0,ni.INT8[e].length=0,ni.INT16[e].length=0,ni.INT32[e].length=0,ni.FLOAT[e].length=0,ni.DOUBLE[e].length=0,ni.BIGUINT64[e].length=0,ni.BIGINT64[e].length=0,ni.UINT8C[e].length=0,jk[e].length=0,$k[e].length=0};var VHt=RHt,VW=32;function RHt(g,e){e<=4*VW?RW(0,e-1,g):WW(0,e-1,g)}function RW(g,e,I){for(var i=2*(g+1),n=g+1;n<=e;++n){for(var C=I[i++],r=I[i++],o=n,A=i-2;o-- >g;){var s=I[A-2],a=I[A-1];if(sI[e+1]:!0}function FR(g,e,I,i){g*=2;var n=i[g];return n>1,o=r-i,A=r+i,s=n,a=o,l=r,c=A,u=C,d=g+1,h=e-1,m=0;_a(s,a,I)&&(m=s,s=a,a=m),_a(c,u,I)&&(m=c,c=u,u=m),_a(s,l,I)&&(m=s,s=l,l=m),_a(a,l,I)&&(m=a,a=l,l=m),_a(s,c,I)&&(m=s,s=c,c=m),_a(l,c,I)&&(m=l,l=c,c=m),_a(a,u,I)&&(m=a,a=u,u=m),_a(a,l,I)&&(m=a,a=l,l=m),_a(c,u,I)&&(m=c,c=u,u=m);for(var f=I[2*a],b=I[2*a+1],p=I[2*c],y=I[2*c+1],Z=2*s,v=2*l,G=2*u,B=2*n,w=2*r,R=2*C,S=0;S<2;++S){var X=I[Z+S],W=I[v+S],V=I[G+S];I[B+S]=X,I[w+S]=W,I[R+S]=V}toe(o,g,I),toe(A,e,I);for(var H=d;H<=h;++H)if(FR(H,f,b,I))H!==d&&eoe(H,d,I),++d;else if(!FR(H,p,y,I))for(;;)if(FR(h,p,y,I)){FR(h,f,b,I)?(WHt(H,d,h,I),++d,--h):(eoe(H,h,I),--h);break}else{if(--h>>1;qk(sg,b);for(var p=0,y=0,d=0;d=rr)Z=Z-rr|0,Ib(Ns,Jd,y--,Z);else if(Z>=0)Ib(rn,Ts,p--,Z);else if(Z<=-rr){Z=-Z-rr|0;for(var v=0;v>>1;qk(sg,b);for(var p=0,y=0,Z=0,d=0;d>1===sg[2*d+3]>>1&&(G=2,d+=1),v<0){for(var B=-(v>>1)-1,w=0;w>1)-1;G===0?Ib(rn,Ts,p--,B):G===1?Ib(Ns,Jd,y--,B):G===2&&Ib(gb,RB,Z--,B)}}}function kHt(g,e,I,i,n,C,r,o,A,s,a,l){var c=0,u=2*g,d=e,h=e+g,m=1,f=1;i?f=rr:m=rr;for(var b=n;b>>1;qk(sg,v);for(var G=0,b=0;b=rr?(w=!i,p-=rr):(w=!!i,p-=1),w)ib(rn,Ts,G++,p);else{var R=l[p],S=u*p,X=a[S+e+1],W=a[S+e+1+g];e:for(var V=0;V>>1;qk(sg,p);for(var y=0,h=0;h=rr)rn[y++]=m-rr;else{m-=1;var v=a[m],G=c*m,B=s[G+e+1],w=s[G+e+1+g];e:for(var R=0;R=0;--R)if(rn[R]===m){for(var V=R+1;V"+e4+"-"+GH+"){"),g?(C(!0,!1),n.push("}else{"),C(!1,!1)):(n.push("if("+jD+"){"),C(!0,!0),n.push("}else{"),C(!0,!1),n.push("}}else{if("+jD+"){"),C(!1,!0),n.push("}else{"),C(!1,!1),n.push("}")),n.push("}}return "+e);var r=I.join("")+n.join(""),o=new Function(r);return o()}$j.partial=b1e(!1);$j.full=b1e(!0);var y1e=DHt,xHt="for(var j=2*a,k=j*c,l=k,m=c,n=b,o=a+b,p=c;d>p;++p,k+=j){var _;if($)if(m===p)m+=1,l+=j;else{for(var s=0;j>s;++s){var t=e[k+s];e[k+s]=e[l],e[l++]=t}var u=f[p];f[p]=f[m],f[m++]=u}}return m";function DHt(g,e){var I="abcdef".split("").concat(e),i=[];return g.indexOf("lo")>=0&&i.push("lo=e[k+n]"),g.indexOf("hi")>=0&&i.push("hi=e[k+o]"),I.push(xHt.replace("_",i.join()).replace("$",g)),Function.apply(void 0,I)}var FHt=PHt,EHt=y1e,Ioe=EHt("loI&&n[l+e]>s;--a,l-=r){for(var c=l,u=l+r,d=0;d>>1,s=2*g,a=A,l=n[s*A+e];r=m?(a=h,l=m):d>=b?(a=u,l=d):(a=f,l=b):m>=b?(a=h,l=m):b>=d?(a=u,l=d):(a=f,l=b);for(var Z=s*(o-1),v=s*a,p=0;p=p0)&&!(p1>=hi)",["p0","p1"]),noe=ly("lo===p0",["p0"]),$Ht=ly("lo0;){s-=1;var c=s*t4,u=jn[c],d=jn[c+1],h=jn[c+2],m=jn[c+3],f=jn[c+4],b=jn[c+5],p=s*g4,y=Od[p],Z=Od[p+1],v=b&1,G=!!(b&16),B=n,w=C,R=o,S=A;if(v&&(B=o,w=A,R=n,S=C),!(b&2&&(h=$Ht(g,u,d,h,B,w,Z),d>=h))&&!(b&4&&(d=qHt(g,u,d,h,B,w,y),d>=h))){var X=h-d,W=f-m;if(G){if(g*X*(X+W)>>1;if(!(r<=0)){var o,A=Nl.mallocDouble(2*r*n),s=Nl.mallocInt32(n);if(n=roe(g,r,A,s),n>0){if(r===1&&i)ER.init(n),o=ER.sweepComplete(r,I,0,n,A,s,0,n,A,s);else{var a=Nl.mallocDouble(2*r*C),l=Nl.mallocInt32(C);C=roe(e,r,a,l),C>0&&(ER.init(n+C),r===1?o=ER.sweepBipartite(r,I,0,n,A,s,0,C,a,l):o=C2t(r,I,i,n,A,s,C,a,l),Nl.free(a),Nl.free(l))}Nl.free(A),Nl.free(s)}return o}}}var iS;function B1e(g,e){iS.push([g,e])}function o2t(g){return iS=[],BH(g,g,B1e,!0),iS}function A2t(g,e){return iS=[],BH(g,e,B1e,!1),iS}function a2t(g,e,I){switch(arguments.length){case 1:return o2t(g);case 2:return typeof e=="function"?BH(g,g,e,!0):A2t(g,e);case 3:return BH(g,e,I,!1);default:throw new Error("box-intersect: Invalid arguments")}}const Ww=FC(n2t);var v1e={exports:{}},S1e=s2t,ooe=+(Math.pow(2,27)+1);function s2t(g,e,I){var i=g*e,n=ooe*g,C=n-g,r=n-C,o=g-r,A=ooe*e,s=A-e,a=A-s,l=e-a,c=i-r*a,u=c-o*a,d=u-r*l,h=o*l-d;return I?(I[0]=h,I[1]=i,I):[h,i]}var l2t=u2t;function c2t(g,e){var I=g+e,i=I-g,n=I-i,C=e-i,r=g-n,o=r+C;return o?[o,I]:[I]}function u2t(g,e){var I=g.length|0,i=e.length|0;if(I===1&&i===1)return c2t(g[0],e[0]);var n=I+i,C=new Array(n),r=0,o=0,A=0,s=Math.abs,a=g[o],l=s(a),c=e[A],u=s(c),d,h;l=i?(d=a,o+=1,o=i?(d=a,o+=1,o0){if(B<=0)return w;R=G+B}else if(G<0){if(B>=0)return w;R=-(G+B)}else return w;var S=o*R;return w>=S||w<=-S?w:u(y,Z,v)},function(y,Z,v,G){var B=y[0]-G[0],w=Z[0]-G[0],R=v[0]-G[0],S=y[1]-G[1],X=Z[1]-G[1],W=v[1]-G[1],V=y[2]-G[2],H=Z[2]-G[2],D=v[2]-G[2],Y=w*W,F=R*X,_=R*S,J=B*W,te=B*X,q=w*S,$=V*(Y-F)+H*(_-J)+D*(te-q),j=(Math.abs(Y)+Math.abs(F))*Math.abs(V)+(Math.abs(_)+Math.abs(J))*Math.abs(H)+(Math.abs(te)+Math.abs(q))*Math.abs(D),ee=A*j;return $>ee||-$>ee?$:d(y,Z,v,G)}];function m(p){var y=h[p.length];return y||(y=h[p.length]=c(p.length)),y.apply(void 0,p)}function f(p,y,Z,v,G,B,w){return function(S,X,W,V,H){switch(arguments.length){case 0:case 1:return 0;case 2:return v(S,X);case 3:return G(S,X,W);case 4:return B(S,X,W,V);case 5:return w(S,X,W,V,H)}for(var D=new Array(arguments.length),Y=0;Y0;){var b=(A+n-1)%n,p=g[b];if(p[1]!==i)break;var y=p[0];m=Math.min(m,y),f=Math.max(f,y),A=b}if(A===0)return m<=I&&I<=f?0:1;r=A+1}for(var Z=g[(A+n-1)%n][1];o+1"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function Dr(g){return Dr=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},Dr(g)}const aoe=16,soe=50,gF=5e3,loe=5,Y2t=14,Pu={fontSize:`${Y2t}px`,fontFamily:"Arial",stroke:"white",strokeThickness:2,fontWeight:400,dropShadow:!0,dropShadowColor:"white",dropShadowDistance:0,dropShadowBlur:2};let V1e=function(g){X2t(I,g);var e=H2t(I);function I(i,n){var C;return S2t(this,I),C=e.call(this,i,n),C.valueScaleTransform=Fi,C}return w2t(I,[{key:"initialize",value:function(){this.initialized||([this.prevK,this.vertK,this.vertY]=[1,1,0],this.drawnRects||(this.drawnRects={}),this.colorScale||(this.options.colorRange?this.colorScale=Cu(this.options.colorRange):this.colorScale=Pb),this.initialized=!0)}},{key:"initTile",value:function(n){n.texts={},n.rectGraphics=new Ct.PIXI.Graphics,n.textGraphics=new Ct.PIXI.Graphics,n.graphics.addChild(n.rectGraphics),n.graphics.addChild(n.textGraphics);let C=[],r=[];if(n.tileData&&n.tileData.length){if(n.tileData.sort((o,A)=>A.importance-o.importance),!this.options||!this.options.valueColumn){const o=n.tileData.map(A=>{const s=+A.chrOffset;return{from:+A.fields[1]+s,to:+A.fields[2]+s,value:A,text:A.fields[3],strand:A.fields.length>=6&&A.fields[5]==="-"?"-":"+"}});C=U9(o.filter(A=>A.strand==="+")),r=U9(o.filter(A=>A.strand==="-"))}else C=[n.tileData.map(o=>({value:o}))];n.plusStrandRows=C,n.minusStrandRows=r,this.options.showTexts&&n.tileData.forEach((o,A)=>{const s=o.fields;if(o.importance||(o.importance=Math.random()),n.textWidths={},n.textHeights={},A>=(+this.options.maxTexts||soe))return;const a=new Ct.PIXI.Text(s[3],{...Pu,fontSize:+this.options.fontSize||Pu.fontSize});this.flipText&&(a.scale.x=-1),a.anchor.x=.5,a.anchor.y=.5,n.texts[o.uid]=a,n.textGraphics.addChild(a)})}n.initialized=!0}},{key:"removeTileRects",value:function(n){const C=+n.tileId.split(".")[0];n.rectGraphics.clear(),n.rendered=!1,n.tileData&&n.tileData.length&&n.tileData.forEach((r,o)=>{this.drawnRects[C]&&this.drawnRects[C][r.uid]&&this.drawnRects[C][r.uid][2]===n.tileId&&delete this.drawnRects[C][r.uid]})}},{key:"destroyTile",value:function(n){this.removeTileRects(n),n.graphics.removeChild(n.textGraphics),n.graphics.removeChild(n.rectGraphics)}},{key:"removeTiles",value:function(n){FA(Dr(I.prototype),"removeTiles",this).call(this,n)}},{key:"drawTile",value:function(n){this.options&&this.options.valueColumn&&this.valueScale&&this.drawAxis(this.valueScale)}},{key:"rerender",value:function(n,C){FA(Dr(I.prototype),"rerender",this).call(this,n,C),this.valueScale=null,this.drawnRects={},this.options.colorRange?this.colorScale=Cu(this.options.colorRange):this.colorScale=Pb;for(const r of this.visibleAndFetchedTiles())this.destroyTile(r),this.initTile(r),this.renderTile(r)}},{key:"updateTile",value:function(n){this.areAllVisibleTilesLoaded()&&this.renderTile(n)}},{key:"allVisibleRects",value:function(){const n={};Object.values(this.fetchedTiles).forEach(A=>{if(A.plusStrandRows)for(const s of A.plusStrandRows[0])n[s.value.uid]||(n[s.value.uid]=s)});const C=Object.values(n).sort((A,s)=>A.from-s.from);let r=0,o=0;for(let A=0;A=0&&C.length;A--)C[A].staggeredStartPosition=(o+r-A)%2;return n}},{key:"drawSegmentStyle",value:function(n,C,r,o,A,s){const l=o+A/2,c=[C,o,C+2*.1,o,C+2*.1,l-.1,r-2*.1,l-.1,r-2*.1,o,r,o,r,o+A,r-2*.1,o+A,r-2*.1,l+.1,C+2*.1,l+.1,C+2*.1,o+A,C,o+A];return n.rectGraphics.drawPolygon(c),c}},{key:"drawPoly",value:function(n,C,r,o,A,s){let a=null;return this.options.annotationStyle==="segment"?this.drawSegmentStyle(n,C,r,o,A,s):((s==="+"||s==="-")&&r-C=(+this.options.maxTexts||soe)||!n.texts[h.uid])continue;const X=n.texts[h.uid];X.position.x=this._xScale(y),X.position.y=B+v/2,X.nominalY=B+v/2,S&&(X.alreadyDrawn=!0);const W=this.options.fontColor!==void 0?zt(this.options.fontColor):s;if(X.style={...Pu,fill:W,fontSize:+this.options.fontSize||Pu.fontSize},!(m[3]in n.textWidths)){X.updateTransform();const V=X.getBounds().width,H=X.getBounds().height,D=5;n.textWidths[m[3]]=V,n.textHeights[m[3]]=H-D}}}},{key:"renderTile",value:function(n){let C=n.plusStrandRows?n.plusStrandRows.length:1,r=n.minusStrandRows?n.minusStrandRows.length:1;for(const o of this.visibleAndFetchedTiles()){if(!o.initialized)return;!o.plusStrandRows&&!o.minusStrandRows||(C=Math.max(o.plusStrandRows.length,C),r=Math.max(o.minusStrandRows.length,r))}if(n.rendered&&this.removeTileRects(n),n.drawnAtScale=this._xScale.copy(),n.rendered=!0,this.setValueScale(),this.setColorValueScale(),n.tileData&&n.tileData.length){const o=this.options.plusStrandColor||this.options.fillColor||"blue",A=this.options.minusStrandColor||this.options.fillColor||"purple",s=0;let a=0;this.options.separatePlusMinusStrands?a=C*this.dimensions[1]/(C+r)-s/2:a=this.dimensions[1],this.renderRows(n,n.plusStrandRows,C,0,a,o),this.renderRows(n,n.minusStrandRows,r,this.options.separatePlusMinusStrands?a+s/2:0,this.dimensions[1],A)}Pd.stretchRects(this,[o=>o.rectGraphics])}},{key:"calculateZoomLevel",value:function(){const n=vt.calculateZoomLevel(this._xScale,this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0]);let C=Math.min(n,this.maxZoom);return C=Math.max(C,0),C}},{key:"minVisibleValueInTiles",value:function(n){let C=this.visibleAndFetchedIds();C.length===0&&(C=Object.keys(this.fetchedTiles));let r=Math.min.apply(null,C.map(o=>this.fetchedTiles[o]).filter(o=>o.tileData&&o.tileData.length).map(o=>Math.min.apply(null,o.tileData.sort((A,s)=>s.importance-A.importance).slice(0,gF).map(A=>+A.fields[n-1]).filter(A=>!Number.isNaN(A)))));return r===Number.MAX_SAFE_INTEGER&&(r=null),r}},{key:"maxVisibleValueInTiles",value:function(n){let C=this.visibleAndFetchedIds();C.length===0&&(C=Object.keys(this.fetchedTiles));let r=Math.max.apply(null,C.map(o=>this.fetchedTiles[o]).filter(o=>o.tileData&&o.tileData.length).map(o=>Math.max.apply(null,o.tileData.sort((A,s)=>s.importance-A.importance).slice(0,gF).map(A=>+A.fields[n-1]).filter(A=>!Number.isNaN(A)))));return r===Number.MIN_SAFE_INTEGER&&(r=null),r}},{key:"calculateMedianVisibleValue",value:function(n){this.areAllVisibleTilesLoaded()&&this.allTilesLoaded();let C=this.visibleAndFetchedIds();C.length===0&&(C=Object.keys(this.fetchedTiles));const r=[].concat(...C.map(o=>this.fetchedTiles[o]).filter(o=>o.tileData&&o.tileData.length).map(o=>o.tileData.sort((A,s)=>s.importance-A.importance).slice(0,gF).map(A=>+A.fields[n-1]))).filter(o=>o>0);this.medianVisibleValue=p7(r)}},{key:"draw",value:function(){FA(Dr(I.prototype),"draw",this).call(this),this.allTexts=[],this.allBoxes=[];for(const n in this.fetchedTiles){const C=this.fetchedTiles[n];if(C.rectGraphics.scale.y=this.vertK,C.rectGraphics.position.y=this.vertY,!C.drawnAtScale)return;Pd.stretchRects(this,[o=>o.rectGraphics]);const r=this.parentInFetched(C);C.initialized&&C.tileData&&C.tileData.length&&C.tileData.forEach(o=>{if(!C.texts)return;const A=o.fields,s=A[3],a=C.texts[o.uid];if(!a)return;const l=+o.chrOffset,c=+A[1]+l,u=+A[2]+l,d=(c+u)/2;if(a.position.x=this._xScale(d),a.position.y=a.nominalY*(this.vertK*this.prevK)+this.vertY,!r&&!a.alreadyDrawn){a.visible=!0;const h=3;this.allBoxes.push([a.position.x-h,a.position.y-C.textHeights[A[3]]/2,a.position.x+C.textWidths[A[3]]+h,a.position.y+C.textHeights[A[3]]/2]),this.allTexts.push({importance:o.importance,text:a,caption:s,strand:A[5]})}else a.visible=!1})}this.hideOverlaps(this.allBoxes,this.allTexts)}},{key:"hideOverlaps",value:function(n,C){Ww(n,(r,o)=>{C[r].importance>C[o].importance?C[r].text.visible&&(C[o].text.visible=!1):C[o].text.visible&&(C[r].text.visible=!1)})}},{key:"setPosition",value:function(n){FA(Dr(I.prototype),"setPosition",this).call(this,n),[this.pMain.position.x,this.pMain.position.y]=this.position}},{key:"setDimensions",value:function(n){FA(Dr(I.prototype),"setDimensions",this).call(this,n)}},{key:"zoomed",value:function(n,C){this.xScale(n),this.yScale(C),this.refreshTiles(),this.draw()}},{key:"exportSVG",value:function(){let n=null,C=null;FA(Dr(I.prototype),"exportSVG",this)?[C,n]=FA(Dr(I.prototype),"exportSVG",this).call(this):(C=document.createElement("g"),n=C);const r=document.createElement("g");r.setAttribute("transform",`translate(${this.position[0]},${this.position[1]})`),n.appendChild(r);const o=document.createElement("g"),A=document.createElement("g");r.appendChild(o),r.appendChild(A);for(const s of this.visibleAndFetchedTiles())s.tileData.length&&s.tileData.forEach(a=>{const l=+s.tileId.split(".")[0],c=document.createElement("g");if(c.setAttribute("transform",`translate(${s.rectGraphics.position.x},${s.rectGraphics.position.y})scale(${s.rectGraphics.scale.x},${s.rectGraphics.scale.y})`),o.appendChild(c),this.drawnRects[l]&&a.uid in this.drawnRects[l]){const u=this.drawnRects[l][a.uid][0],d=document.createElement("path");let h=`M ${u[0]} ${u[1]}`;for(let b=2;b{const r=this.valueScaleTransform,{y:o,k:A}=r,s=this.dimensions[1];o+n/A>-(A-1)*s&&o+n/A<0&&(this.valueScaleTransform=r.translate(0,n/A)),C.rectGraphics.position.y=this.valueScaleTransform.y,this.vertY=this.valueScaleTransform.y}),this.animate()}},{key:"zoomedY",value:function(n,C){const r=Pd.zoomedY(n,C,this.valueScaleTransform,this.dimensions[1]);this.valueScaleTransform=r;let o=r.k;const A=r.y;let s=!1;o/=this.prevK,(o>1.5||o<1/1.5)&&(this.prevK*=o,o=1,s=!0),this.vertK=o,this.vertY=A,Object.values(this.fetchedTiles).forEach(a=>{s&&this.renderTile(a),a.rectGraphics.scale.y=o,a.rectGraphics.position.y=A}),this.draw(),this.animate()}},{key:"getMouseOverHtml",value:function(n,C){if(!this.tilesetInfo)return"";const r=this.calculateZoomLevel(),o=[n,C];if(this.drawnRects[r]){const A=Object.values(this.drawnRects[r]);for(let s=0;s"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function ea(g){return ea=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},ea(g)}const L2t=(g,e,I,i,n)=>{n.drawRect(g,e,I,i)},_2t=(g,e,I,i,n,{fill:C=0,fillOpacity:r=0,stroke:o=0,strokeWidth:A=0,strokeOpacity:s=0}={})=>{const a=document.createElement("rect");a.setAttribute("x",g),a.setAttribute("y",e),a.setAttribute("width",I),a.setAttribute("height",i),a.setAttribute("fill",`#${Iz(C)}`),a.setAttribute("fill-opacity",r),a.setAttribute("stroke",`#${Iz(o)}`),a.setAttribute("stroke-opacity",s),a.setAttribute("stroke-width",A),n.appendChild(a)},NA=(g,e,I,i,n,C)=>{n instanceof HTMLElement?_2t(g,e,I,i,n,C):L2t(g,e,I,i,n)},uoe=(g,e,I,i,n,C,r,o,{isVertical:A=!1,svg:s=null}={})=>{let a=e,l=I,c=i,u=n;const d=o.width*2>i?i/2:o.width,h=o.width*2>n?n/2:o.width,m=s||g,f={fill:0,fillOpacity:0,stroke:0,strokeOpacity:0,strokeWidth:1};if(o.positions&&o.positions.length?(g.lineStyle(1,0,0),g.beginFill(o.color,o.opacity),f.fill=o.color,f.fillOpacity=o.opacity,f.stroke=0,f.strokeOpacity=0,f.strokeWidth=1,o.positions.forEach(b=>{b==="top"&&!A||b==="left"&&A?NA(e-d,I-h,i+d*2,h,m,f):b==="bottom"&&!A||b==="right"&&A?NA(e-d,I+n,i+d*2,h,m,f):b==="left"&&!A||b==="top"&&A?NA(e-d,I-h,d,n+h*2,m,f):(b==="right"&&!A||b==="bottom"&&A)&&NA(e+i,I-h,d,n+h*2,m,f)})):o.width>0&&o.opacity>0&&(g.lineStyle(o.width,o.color,o.opacity),g.beginFill(0,0),f.fill=0,f.fillOpacity=0,f.stroke=o.color,f.strokeOpacity=o.opacity,f.strokeWidth=o.width,NA(e-d,I-h,i+d*2,n+h*2,m,f)),r.positions&&r.positions.length){g.lineStyle(1,0,0),g.beginFill(r.color,r.opacity);const b=r.width*2>i?i/2:r.width,p=r.width*2>n?n/2:r.width;f.fill=r.color,f.fillOpacity=r.opacity,f.stroke=0,f.strokeOpacity=0,f.strokeWidth=1,r.positions.forEach(y=>{y==="top"&&!A||y==="left"&&A?(NA(e,I,i,p,m,f),l+=p,u-=p):y==="bottom"&&!A||y==="right"&&A?(NA(e,I+n-p,i,p,m,f),u-=p):y==="left"&&!A||y==="top"&&A?(NA(e,I,b,n,m,f),a+=b,c-=b):(y==="right"&&!A||y==="bottom"&&A)&&(NA(e+i-b,I,b,n,m,f),c-=b)})}else g.lineStyle(r.width,r.color,r.opacity),f.stroke=r.color,f.strokeOpacity=r.opacity,f.strokeWidth=r.width;g.beginFill(C.color,C.opacity),f.fill=C.color,f.fillOpacity=C.opacity,NA(a,l,c,u,m,f)};let R1e=function(g){M2t(I,g);var e=z2t(I);function I(i,n){var C;return K2t(this,I),C=e.call(this,i,n),C.options=n||{},C.drawnRects={},C}return x2t(I,[{key:"drawHorizontalOverlay",value:function(n,C,r,o=0,A,s,a,l){if(!r||r.length<2)return;let c=this.position[0]+C.left+this._xScale(r[0]);const u=this.position[1]+C.top,d=C.height;let h=this._xScale(r[1])-this._xScale(r[0]);h=4?r[2]:r[0]);const d=this.position[1]+C.top,h=this.position[1]+C.top+C.height;if(u>h)return;u=4?r[3]:r[1])-u+C.top+this.position[1];f<0||(u+f>h&&(f+=h-(u+f)),f{(l.orientation==="1d-horizontal"||l.orientation==="2d")&&this.options.extent.forEach(c=>this.drawHorizontalOverlay(C,l.position,c,s,r,o,A,n)),(l.orientation==="1d-vertical"||l.orientation==="2d")&&this.options.extent.forEach(c=>this.drawVerticalOverlay(C,l.position,c,a,r,o,A,n))})}},{key:"zoomed",value:function(n,C){this.xScale(n),this.yScale(C),this.draw()}},{key:"setPosition",value:function(n){cc(ea(I.prototype),"setPosition",this).call(this,n),this.draw()}},{key:"setDimensions",value:function(n){cc(ea(I.prototype),"setDimensions",this).call(this,n),this.draw()}},{key:"exportSVG",value:function(){let n=null,C=null;cc(ea(I.prototype),"exportSVG",this)?[C,n]=cc(ea(I.prototype),"exportSVG",this).call(this):(C=document.createElement("g"),n=C);const r=document.createElement("g");return n.appendChild(r),this.draw({svg:r}),[C,n]}}]),I}(dC);function U2t(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function doe(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function qC(g){return qC=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},qC(g)}let cy=function(g){eTt(I,g);var e=tTt(I);function I(){return U2t(this,I),e.apply(this,arguments)}return Q2t(I,[{key:"stopHover",value:function(){this.pMouseOver.clear(),this.animate()}},{key:"getMouseOverHtml",value:function(n){if(!this.tilesetInfo||!this.options.showTooltip||!this.valueScale)return"";const C=this.getDataAtPos(n);let r="";C&&(r=hr(".3f")(C));const o=this.pMouseOver,A=0,s=this.valueScale(C);o.clear(),o.beginFill(A,.5),o.lineStyle(1,A,1);const a=4;return o.drawRect(n-a/2,s-a/2,a,a),this.animate(),`${r}`}},{key:"initTile",value:function(n){if(Mo(qC(I.prototype),"initTile",this).call(this,n),!n.tileData||!n.tileData.dense){console.warn("emptyTile:",n);return}if(n.xValues=new Array(n.tileData.dense.length),n.yValues=new Array(n.tileData.dense.length),this.isValueScaleLocked()){const C=this.getLockGroupExtrema();C!==null&&(this.minValue(C[0]),this.maxValue(C[1]))}this.drawTile(n)}},{key:"rerender",value:function(n,C){Mo(qC(I.prototype),"rerender",this).call(this,n,C),this.options=n,Mo(qC(I.prototype),"draw",this).call(this),this.visibleAndFetchedTiles().forEach(r=>{this.renderTile(r)})}},{key:"renderTile",value:function(n){this.drawTile(n),this.drawAxis(this.valueScale)}},{key:"drawTile",value:function(n){if(Mo(qC(I.prototype),"drawTile",this).call(this,n),!n.graphics||!n.tileData||!n.tileData.dense)return;const C=n.graphics,{tileX:r,tileWidth:o}=this.getTilePosAndDimensions(n.tileData.zoomLevel,n.tileData.tilePos),A=n.tileData.dense;if(A.length===0)return;const[s,a]=this.makeValueScale(this.minValue(),this.medianVisibleValue,this.maxValue());if(this.valueScale=s,C.clear(),this.drawAxis(this.valueScale),this.options.valueScaling==="log"&&this.valueScale.domain()[1]<0){console.warn("Negative values present when using a log scale",this.valueScale.domain());return}const l=zt(this.options.lineStrokeColor?this.options.lineStrokeColor:"blue");!this.tilesetInfo.tile_size&&!this.tilesetInfo.bins_per_dimension&&console.warn("No tileset_info.tile_size or tileset_info.bins_per_dimension",this.tilesetInfo);const c=this.tilesetInfo.tile_size||this.tilesetInfo.bins_per_dimension,u=Cg().domain([0,c]).range([r,r+o]),d=this.options.lineStrokeWidth?this.options.lineStrokeWidth:1;C.lineStyle(d,l,1),n.segments=[];let h=[];for(let m=0;m1&&n.segments.push(h),h=[];continue}if(u(m)>this.tilesetInfo.max_pos[0])break;h.push([f,b])}h.length>1&&n.segments.push(h);for(const m of n.segments){const f=m[0],b=m.slice(1);C.moveTo(f[0],f[1]);for(const p of b)C.lineTo(p[0],p[1])}}},{key:"setPosition",value:function(n){Mo(qC(I.prototype),"setPosition",this).call(this,n),this.pMain.position.y=this.position[1],this.pMain.position.x=this.position[0],this.pMouseOver.position.y=this.position[1],this.pMouseOver.position.x=this.position[0]}},{key:"zoomed",value:function(n,C){this.xScale(n),this.yScale(C),this.refreshTiles(),this.draw();const r=this.isValueScaleLocked();if(this.continuousScaling&&this.minValue()!==void 0&&this.maxValue()!==void 0){if(this.valueScaleMin===null&&this.valueScaleMax===null&&!r){const o=this.minVisibleValue(),A=this.maxVisibleValue(),s=1e-6;o!==null&&A!==null&&(Math.abs(this.minValue()-o)>s||Math.abs(this.maxValue()-A)>s)&&(this.minValue(o),this.maxValue(A),this.scheduleRerender())}r&&this.onValueScaleChanged()}}},{key:"superSVG",value:function(){return Mo(qC(I.prototype),"exportSVG",this).call(this)}},{key:"exportSVG",value:function(){let n=null,C=null;Mo(qC(I.prototype),"exportSVG",this)?[C,n]=Mo(qC(I.prototype),"exportSVG",this).call(this):(C=document.createElement("g"),n=C),C.setAttribute("class","exported-line-track");const r=document.createElement("g");n.appendChild(r),r.setAttribute("transform",`translate(${this.position[0]},${this.position[1]})`);const o=this.options.lineStrokeColor?this.options.lineStrokeColor:"blue";this.visibleAndFetchedTiles().forEach(s=>{const a=document.createElement("path");a.setAttribute("fill","transparent"),a.setAttribute("stroke",o);let l="";for(const c of s.segments){const u=c[0],d=c.slice(1);l+=`M${u[0]} ${u[1]}`;for(const h of d)l+=`L${h[0]} ${h[1]}`}a.setAttribute("d",l),r.appendChild(a)});const A=document.createElement("g");if(A.setAttribute("id","axis"),C.appendChild(A),A.setAttribute("transform",`translate(${this.axis.pAxis.position.x}, ${this.axis.pAxis.position.y})`),this.options.axisPositionHorizontal==="left"||this.options.axisPositionVertical==="top"){const s=this.axis.exportAxisLeftSVG(this.valueScale,this.dimensions[1]);A.appendChild(s)}else if(this.options.axisPositionHorizontal==="right"||this.options.axisPositionVertical==="bottom"){const s=this.axis.exportAxisRightSVG(this.valueScale,this.dimensions[1]);A.appendChild(s)}return[C,n]}},{key:"tileToLocalId",value:function(n){return this.options.aggregationMode&&this.options.aggregationMode!=="mean"?`${n.join(".")}.${this.options.aggregationMode}`:`${n.join(".")}`}},{key:"tileToRemoteId",value:function(n){return this.tileToLocalId(n)}}]),I}(sy);function nTt(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function hoe(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function vs(g){return vs=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},vs(g)}let W1e=function(g){aTt(I,g);var e=sTt(I);function I(){return nTt(this,I),e.apply(this,arguments)}return CTt(I,[{key:"initTile",value:function(n){n.barXValues=new Array(n.tileData.dense.length),n.barYValues=new Array(n.tileData.dense.length),n.barWidths=new Array(n.tileData.dense.length),n.barHeights=new Array(n.tileData.dense.length),Zd(vs(I.prototype),"initTile",this).call(this,n)}},{key:"drawTile",value:function(n){if(!n.graphics||!n.tileData||!n.tileData.dense)return;const C=n.graphics,{tileX:r,tileWidth:o}=this.getTilePosAndDimensions(n.tileData.zoomLevel,n.tileData.tilePos),A=n.tileData.dense;if(A.length===0)return;let s=0;if(this.valueScale=null,this.options.valueScaling==="log"){let h=this.medianVisibleValue;this.medianVisibleValue||(h=this.minValue()),this.valueScale=mu().domain([h,this.maxValue()+h]).range([this.dimensions[1],0]),s=h}else this.valueScale=Cg().domain([this.minValue(),this.maxValue()]).range([this.dimensions[1],0]);if(C.clear(),this.drawAxis(this.valueScale),this.options.valueScaling==="log"&&this.valueScale.domain()[1]<0){console.warn("Negative values present when using a log scale",this.valueScale.domain());return}const a=zt(this.options.lineStrokeColor?this.options.lineStrokeColor:"blue"),l=Cg().domain([0,this.tilesetInfo.tile_size]).range([r,r+o]),c=0;C.lineStyle(c,a,1);const u=this.options.pointSize?this.options.pointSize:3,d=zt(this.options.pointColor?this.options.pointColor:"red");C.beginFill(d,1),n.drawnAtScale=this._xScale.copy();for(let h=0;hthis.tilesetInfo.max_pos[0])break;C.drawRect(m-u/2/this.pMain.scale.x,f-u/2/this.pMain.scale.y,u/this.pMain.scale.x,u/this.pMain.scale.y)}}},{key:"draw",value:function(){Zd(vs(I.prototype),"draw",this).call(this);for(const n of Pg(this.fetchedTiles)){const C=(n.drawnAtScale.domain()[1]-n.drawnAtScale.domain()[0])/(this._xScale.domain()[1]-this._xScale.domain()[0]),o=this._xScale.domain().map(n.drawnAtScale)[0];n.graphics.scale.x=C,n.graphics.position.x=-o*C}}},{key:"zoomed",value:function(n,C,r,o,A){Zd(vs(I.prototype),"zoomed",this).call(this,n,C)}},{key:"exportSVG",value:function(){let n=null,C=null;[C,n]=Zd(vs(I.prototype),"superSVG",this).call(this),C.setAttribute("class","exported-line-track");const r=document.createElement("g");n.appendChild(r),r.setAttribute("transform",`translate(${this.position[0]},${this.position[1]})`);for(const A of this.visibleAndFetchedTiles())for(let s=0;s{e+=+i||0,I.push(e)}),Float64Array.from(I)}const hTt=(g,e)=>{const I=Pv(g,e);return dTt(g.map(i=>(Array.isArray(i)&&e?i.length:1)/I))};function mTt(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function moe(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function Xh(g){return Xh=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},Xh(g)}let X1e=function(g){ZTt(I,g);var e=GTt(I);function I(i,n){var C;return mTt(this,I),C=e.call(this,i,n),C.pMain=C.pMobile,C.continuousScaling=!1,C.updateDataFetcher(n),C}return fTt(I,[{key:"updateDataFetcher",value:function(n){if(n&&n.selectRows&&n.selectRowsAggregationMethod==="server"){const{pubSub:C,dataFetcher:r}=this,o=r.dataConfig.options,A={aggGroups:n.selectRows,aggFunc:n.selectRowsAggregationMode};if(JSON.stringify(o)!==JSON.stringify(A)){const s={...r.dataConfig,options:A};this.dataFetcher=new r.constructor(s,C),this.dataFetcher.dataConfig.tilesetUid&&this.fetchNewTiles(Object.keys(this.fetchedTiles).map(a=>({tileId:a,remoteId:a})))}}}},{key:"rerender",value:function(n,C){this.updateDataFetcher(n),WB(Xh(I.prototype),"rerender",this).call(this,n,C),n.selectRows&&(this.selectRowsCumWeights=hTt(n.selectRows,n.selectRowsAggregationWithRelativeHeight))}},{key:"tileDataToCanvas",value:function(n){const C=document.createElement("canvas");this.options.selectRows&&this.tilesetInfo.shape?(C.width=this.tilesetInfo.shape[0],C.height=Pv(this.options.selectRows,this.options.selectRowsAggregationWithRelativeHeight)):this.tilesetInfo.shape?(C.width=this.tilesetInfo.shape[0],C.height=this.tilesetInfo.shape[1]):(C.width=this.tilesetInfo.tile_size,C.height=1);const r=C.getContext("2d");if(r.fillStyle="transparent",r.fillRect(0,0,C.width,C.height),n.length!==0&&n.length===4*C.width*C.height){const o=new ImageData(n,C.width,C.height);r.putImageData(o,0,0)}else console.warn("HorizontalMultivecTrack: pixData has an incorrect length.");return C}},{key:"setSpriteProperties",value:function(n,C,r){const{tileX:o,tileWidth:A}=this.getTilePosAndDimensions(C,r,this.tilesetInfo.tile_size),s=o+A;n.width=this._refXScale(s)-this._refXScale(o),n.height=this.dimensions[1],n.x=this._refXScale(o),n.y=0}},{key:"leftTrackZoomed",value:function(n,C,r,o,A){const s=this._xScale(0)-r*this._refXScale(0);this.pMobile.position.x=s+this.position[0],this.pMobile.position.y=this.position[1],this.pMobile.scale.x=r,this.pMobile.scale.y=1}},{key:"zoomed",value:function(n,C,r,o){WB(Xh(I.prototype),"zoomed",this).call(this,n,C),this.pMain.position.x=o,this.pMain.position.y=this.position[1],this.pMain.scale.x=r,this.pMain.scale.y=1,this.drawColorbar()}},{key:"calculateVisibleTiles",value:function(){if(!this.tilesetInfo)return;if(this.zoomLevel=this.calculateZoomLevel(),this.tilesetInfo.resolutions){const C=this.tilesetInfo.resolutions.map(r=>+r).sort((r,o)=>o-r);this.xTiles=vt.calculateTilesFromResolution(C[this.zoomLevel],this._xScale,this.tilesetInfo.min_pos[0],null,this.tilesetInfo.tile_size)}else this.xTiles=vt.calculateTiles(this.zoomLevel,this._xScale,this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0],this.tilesetInfo.max_zoom,this.tilesetInfo.max_width);const n=this.xTiles.map(C=>[this.zoomLevel,C]);this.setVisibleTiles(n)}},{key:"calculateZoomLevel",value:function(){if(!this.tilesetInfo)return;const n=this.tilesetInfo.min_pos[0];let C=null;return this.tilesetInfo.resolutions?C=vt.calculateZoomLevelFromResolutions(this.tilesetInfo.resolutions,this._xScale,n):C=vt.calculateZoomLevel(this._xScale,this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0]),C}},{key:"tileToLocalId",value:function(n){return n.join(".")}},{key:"tileToRemoteId",value:function(n){return n.join(".")}},{key:"getTilePosAtPosition",value:function(n,C){if(!this.tilesetInfo)return;const r=this.calculateZoomLevel(),o=vt.calculateTileWidth(this.tilesetInfo,r,this.tilesetInfo.tile_size),A=this._xScale.invert(n)/o;return[r,Math.floor(A)]}},{key:"getVisibleData",value:function(n,C){const r=this.calculateZoomLevel(),o=vt.calculateTileWidth(this.tilesetInfo,r,this.tilesetInfo.tile_size),A=this._xScale.invert(n)/o;let s=this.tilesetInfo.shape?this.tilesetInfo.shape[1]:1;this.options.selectRows&&(s=Pv(this.options.selectRows,this.options.selectRowsAggregationWithRelativeHeight));let a=this.tilesetInfo.tile_size*(A-Math.floor(A));const l=C/this.dimensions[1],c=l*s;let u=Math.floor(c),d;this.options.selectRows&&(this.options.selectRowsAggregationWithRelativeHeight&&(u=this.selectRowsCumWeights.findIndex((b,p)=>l<=b&&(p===this.selectRowsCumWeights.length-1||this.selectRowsCumWeights[p+1]>=l))),d=this.options.selectRows[u]);const h=this.tileToLocalId([r,Math.floor(A)]),m=this.fetchedTiles[h];let f="";if(m){this.tilesetInfo.shape||(a=m.tileData.dense.length*(A-Math.floor(A)));let b=null;if(this.tilesetInfo.shape?Array.isArray(d)&&this.options.selectRowsAggregationMethod==="client"?b=d.map(p=>this.tilesetInfo.shape[0]*p+Math.floor(a)):d&&this.options.selectRowsAggregationMethod==="client"?b=this.tilesetInfo.shape[0]*d+Math.floor(a):b=this.tilesetInfo.shape[0]*u+Math.floor(a):b=m.tileData.dense.length*u+Math.floor(a),Array.isArray(b)){const p=TQ(this.options.selectRowsAggregationMode),y=b.map(Z=>m.tileData.dense[Z]);f=hr(".3f")(p(y)),f+="
",f+=`${b.length}-item ${this.options.selectRowsAggregationMode}`}else f=hr(".3f")(m.tileData.dense[b]),Array.isArray(d)&&(f+="
",f+=`${d.length}-item ${this.options.selectRowsAggregationMode}`)}if(this.tilesetInfo.row_infos){f+="
";let b="";this.options.selectRows&&!Array.isArray(d)?b=this.tilesetInfo.row_infos[d]:u>=0&&u"),a=this.options.colorRange[parseInt(s[0],10)-1],l=s[1];if(Number.isNaN(a)||a==="NaN"||typeof a>"u"||a==="undefined")return"";o=` ${l}`}else o+=`Data value: ${this.getVisibleData(n,C)}
`,o+=`Zoom level: ${r[0]} tile position: ${r[1]}`;return o}}]),I}(Rw);function wTt(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function foe(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function Uo(g){return Uo=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},Uo(g)}const KTt=zt("#FFFFFF");let I4=function(g){HTt(I,g);var e=TTt(I);function I(...i){var n;return wTt(this,I),n=e.call(this,...i),n.zeroLine=new Ct.PIXI.Graphics,n.pMain.addChild(n.zeroLine),n.valueScaleTransform=Fi,n.options&&n.options.colorRange&&(n.options.colorRangeGradient?n.setColorGradient(n.options.colorRange):n.setColorScale(n.options.colorRange)),n.initialized=!0,n}return VTt(I,[{key:"setColorScale",value:function(n){n&&(this.colorScale=Cu(n),this.colorScale=this.colorScale.map(C=>C.map(r=>r/255)))}},{key:"setColorGradient",value:function(n){if(!n)return;const C=n.length-1;this.colorGradientColors=this.options.align==="bottom"?n.slice().reverse().map((r,o)=>({from:o/C,color:r})):n.map((r,o)=>({from:o/C,color:r}))}},{key:"initTile",value:function(n){this.initialized&&as(Uo(I.prototype),"initTile",this).call(this,n)}},{key:"updateTile",value:function(n){(!n.valueScale||!this.scale||this.scale.minValue!==n.scale.minValue||this.scale.maxValue!==n.scale.maxValue)&&this.renderTile(n)}},{key:"renderTile",value:function(n){this.initialized&&as(Uo(I.prototype),"renderTile",this).call(this,n)}},{key:"drawTile",value:function(n){if(!n.graphics||!n.tileData||!n.tileData.dense)return;const{graphics:C}=n;n.svgData=void 0;const{tileX:r,tileWidth:o}=this.getTilePosAndDimensions(n.tileData.zoomLevel,n.tileData.tilePos,this.tilesetInfo.bins_per_dimension||this.tilesetInfo.tile_size),A=n.tileData.dense;if(A.length===0)return;const[s,a]=this.makeValueScale(this.minValue(),this.medianVisibleValue,this.maxValue(),0);s.clamp(!0),this.valueScale=s;const l=s.copy();if(l.range([254,0]).clamp(!0),C.clear(),this.drawAxis(this.valueScale),this.options.valueScaling==="log"&&this.valueScale.domain()[1]<0){console.warn("Negative values present when using a log scale",this.valueScale.domain());return}const c=zt(this.options.lineStrokeColor||"blue"),u=Cg().domain([0,this.tilesetInfo.tile_size||this.tilesetInfo.bins_per_dimension]).range([r,r+o]),d=0;C.lineStyle(d,c,1);const h=this.options.barFillColor||"grey",m=zt(h),f="barOpacity"in this.options?this.options.barOpacity:1;C.beginFill(m,f),n.drawnAtScale=this._xScale.copy();const b=this.options.align==="top";let p,y,Z,v,G,B;if(this.colorGradientColors){G=new Ct.PIXI.Graphics,G.beginFill(KTt,1);const w=_Ge(this.colorGradientColors,1,this.dimensions[1],0,0,0,this.dimensions[1]);B=new Ct.PIXI.Sprite(Ct.PIXI.Texture.fromCanvas(w,Ct.PIXI.SCALE_MODES.NEAREST)),B.x=this._xScale(r),B.width=this._xScale(r+o)-B.x}for(let w=0;wthis.tilesetInfo.max_pos[0])break;if(this.colorScale&&!this.options.colorRangeGradient){const R=Math.round(l(A[w]+a)),S=this.colorScale[R],X=Ct.PIXI.utils.rgb2hex(S);C.beginFill(X,f)}(G||C).drawRect(p,Z,y,v)}this.colorGradientColors&&(B.mask=G,C.removeChildren(),C.addChild(B,G))}},{key:"rerender",value:function(n,C){n&&n.colorRange&&(n.colorRangeGradient?this.setColorGradient(n.colorRange):this.setColorScale(n.colorRange)),as(Uo(I.prototype),"rerender",this).call(this,n,C)}},{key:"drawZeroLine",value:function(){this.zeroLine.clear();const n=zt(this.options.barFillColor||"grey"),C=+this.options.barOpacity||1,r=this.options.zeroLineColor?zt(this.options.zeroLineColor):n,o=Number.isNaN(+this.options.zeroLineOpacity)?C:+this.options.zeroLineOpacity;this.zeroLine.beginFill(r,o),this.zeroLine.drawRect(0,this.dimensions[1]-1,this.dimensions[0],1)}},{key:"drawZeroLineSvg",value:function(n){const C=document.createElement("rect");C.setAttribute("id","zero-line"),C.setAttribute("x",0),C.setAttribute("y",this.dimensions[1]-1),C.setAttribute("height",1),C.setAttribute("width",this.dimensions[0]),C.setAttribute("fill",this.options.zeroLineColor||this.options.barFillColor),C.setAttribute("fill-opacity",this.options.zeroLineOpacity||this.options.barOpacity),n.appendChild(C)}},{key:"getXScaleAndOffset",value:function(n){const C=n.domain(),r=this._xScale.domain(),o=(C[1]-C[0])/(r[1]-r[0]),s=this._xScale.domain().map(n)[0];return[o,-s*o]}},{key:"draw",value:function(){this.initialized&&(as(Uo(I.prototype),"draw",this).call(this),this.options.zeroLineVisible?this.drawZeroLine():this.zeroLine.clear(),Object.values(this.fetchedTiles).forEach(n=>{const[C,r]=this.getXScaleAndOffset(n.drawnAtScale);n.graphics.scale.x=C,n.graphics.position.x=r}))}},{key:"zoomed",value:function(n,C){as(Uo(I.prototype),"zoomed",this).call(this,n,C)}},{key:"movedY",value:function(n){}},{key:"zoomedY",value:function(n,C){}},{key:"addSVGInfo",value:function(n,C,r,o,A,s){n.svgData?(n.svgData.barXValues.push(C),n.svgData.barYValues.push(r),n.svgData.barWidths.push(o),n.svgData.barHeights.push(A),n.svgData.barColors.push(s)):n.svgData={barXValues:[C],barYValues:[r],barWidths:[o],barHeights:[A],barColors:[s]}}},{key:"exportSVG",value:function(){let n=null,C=null;[C,n]=as(Uo(I.prototype),"superSVG",this).call(this),C.setAttribute("class","exported-line-track");const r=document.createElement("g");n.appendChild(r),r.setAttribute("transform",`translate(${this.position[0]},${this.position[1]})`),this.options.zeroLine&&this.drawZeroLineSvg(r),this.visibleAndFetchedTiles().filter(A=>A.svgData&&A.svgData.barXValues).forEach(A=>{const s=A.svgData;for(let a=0;a"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function vH(g){return vH=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},vH(g)}let H1e=function(g){MTt(I,g);var e=zTt(I);function I(){return xTt(this,I),e.apply(this,arguments)}return DTt(I,[{key:"drawTile",value:function(n){this.renderTile(n)}},{key:"renderTile",value:function(n){if(!n.graphics)return;const C=n.graphics,{tileX:r,tileWidth:o}=this.getTilePosAndDimensions(n.tileData.zoomLevel,n.tileData.tilePos,this.tilesetInfo.tile_size||this.tilesetInfo.bins_per_dimension),A=n.tileData.dense;if(A.length===0)return;let s=0;if(this.valueScale=null,this.options.valueScaling==="log"){let p=this.medianVisibleValue;this.medianVisibleValue||(p=this.minValue()),this.valueScale=mu().domain([p,this.maxValue()+p]).range([this.dimensions[1],0]),s=p}else this.valueScale=Cg().domain([this.minValue(),this.maxValue()]).range([this.dimensions[1],0]);if(C.clear(),this.drawAxis(this.valueScale),this.options.valueScaling==="log"&&this.valueScale.domain()[1]<0){console.warn("Negative values present when using a log scale",this.valueScale.domain());return}const a=zt(this.options.lineStrokeColor?this.options.lineStrokeColor:"blue"),l=Cg().domain([0,this.tilesetInfo.tile_size]).range([r,r+o]),c=0;C.lineStyle(c,a,1);const u=this.options.barFillColorTop?this.options.barFillColorTop:"green",d=this.options.barFillColorBottom?this.options.barFillColorBottom:"red",h=zt(u),m=zt(d),f="barOpacity"in this.options?this.options.barOpacity:1;n.drawnAtScale=this._xScale.copy();let b=0;this.options.valueScaling==="log"?b=this.valueScale(1):b=this.valueScale(0),delete n.svgData;for(let p=0;pb?(C.beginFill(m,f),this.addSVGInfo(n,y,b,v,Z-b,d)):(C.beginFill(h,f),this.addSVGInfo(n,y,Z,v,b-Z,u)),l(p)>this.tilesetInfo.max_pos[0])break;C.drawRect(y,n.svgData.barYValues[p],v,n.svgData.barHeights[p])}}}]),I}(I4);function LTt(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function boe(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function u0(g){return u0=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},u0(g)}let T1e=function(g){$Tt(I,g);var e=qTt(I);function I(i,n){var C;return LTt(this,I),C=e.call(this,i,n),C.setColorScale(n.colorRange),C.opacity=n.opacity||1,C}return _Tt(I,[{key:"setColorScale",value:function(n){this.colorScale=n?Cu(n):Pb,this.colorScale=this.colorScale.map(C=>C.map(r=>r/255))}},{key:"rerender",value:function(n){n&&n.colorRange&&this.setColorScale(n.colorRange),this.opacity=n.opacity||1,XW(u0(I.prototype),"rerender",this).call(this,n)}},{key:"drawAxis",value:function(){}},{key:"drawTile",value:function(n){if(!n.graphics||!n.tileData||!n.tileData.dense)return;const C=n.graphics,{tileX:r,tileWidth:o}=this.getTilePosAndDimensions(n.tileData.zoomLevel,n.tileData.tilePos),A=n.tileData.dense;if(A.length===0)return;const[s,a]=this.makeValueScale(this.minValue(),this.medianVisibleValue,this.maxValue());if(s.range([254,0]).clamp(!0),this.valueScale=s,C.clear(),this.options.valueScaling==="log"&&this.valueScale.domain()[1]<0){console.warn("Negative values present when using a log scale",this.valueScale.domain());return}const l=Cg().domain([0,this.tilesetInfo.tile_size]).range([r,r+o]);C.lineStyle(0,0,0);for(let c=0;cthis.tilesetInfo.max_pos[0])break;A[c]!==0&&C.drawRect(d,0,h,m)}}}}]),I}(cy);function INt(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function yoe(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function SH(g){return SH=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},SH(g)}let N1e=function(g){rNt(I,g);var e=oNt(I);function I(i,n){var C;return INt(this,I),C=e.call(this,i,n),C.seen=new Set,C.pMain=C.pMobile,C.rows=[],C}return iNt(I,[{key:"uid",value:function(n){return n[n.length-2]}},{key:"segmentOverlap",value:function(n,C){}},{key:"drawAll",value:function(n){this.pMain.clear();const C=new Set,r=n.map(A=>C.has(this.uid(A))?null:(C.add(this.uid(A)),{from:+A[1],to:+A[2],type:A[4],uid:this.uid(A)})).filter(A=>A),o=U9(r);this.rows=o,this.draw()}},{key:"draw",value:function(){const n=this.rows;if(!n)return;const C=jS().range([0,this.dimensions[1]]).padding(.1).domain(iC(0,this.maxRows())),r=this.pMain;r.clear(),r.lineStyle(1,255,0),r.beginFill(16740363,.8);for(let o=0;othis.fetchedTiles[o].tileData.discrete),r=[].concat(...C);this.drawAll(r)}},{key:"initTile",value:function(n){}},{key:"maxRows",value:function(){return this.rows.length}},{key:"updateTile",value:function(n){}},{key:"destroyTile",value:function(n){n.tileData.discrete.forEach(C=>{const r=C[C.length-2];this.seen.has(r)&&this.seen.delete(r)})}},{key:"drawTile",value:function(n){}}]),I}(sy);function lNt(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function Zoe(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function c(ne){return c=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(_){return _.__proto__||Object.getPrototypeOf(_)},c(ne)}const u=ik,d=mj,h=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;e.Buffer=p,e.SlowBuffer=R,e.INSPECT_MAX_BYTES=50;const m=2147483647;e.kMaxLength=m,p.TYPED_ARRAY_SUPPORT=f(),!p.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function f(){try{const ne=new Uint8Array(1),F={foo:function(){return 42}};return Object.setPrototypeOf(F,Uint8Array.prototype),Object.setPrototypeOf(ne,F),ne.foo()===42}catch{return!1}}Object.defineProperty(p.prototype,"parent",{enumerable:!0,get:function(){if(p.isBuffer(this))return this.buffer}}),Object.defineProperty(p.prototype,"offset",{enumerable:!0,get:function(){if(p.isBuffer(this))return this.byteOffset}});function b(ne){if(ne>m)throw new RangeError('The value "'+ne+'" is invalid for option "size"');const F=new Uint8Array(ne);return Object.setPrototypeOf(F,p.prototype),F}function p(ne,F,_){if(typeof ne=="number"){if(typeof F=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return G(ne)}return y(ne,F,_)}p.poolSize=8192;function y(ne,F,_){if(typeof ne=="string")return v(ne,F);if(ArrayBuffer.isView(ne))return V(ne);if(ne==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof ne);if(qe(ne,ArrayBuffer)||ne&&qe(ne.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(qe(ne,SharedArrayBuffer)||ne&&qe(ne.buffer,SharedArrayBuffer)))return S(ne,F,_);if(typeof ne=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');const fe=ne.valueOf&&ne.valueOf();if(fe!=null&&fe!==ne)return p.from(fe,F,_);const ke=X(ne);if(ke)return ke;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof ne[Symbol.toPrimitive]=="function")return p.from(ne[Symbol.toPrimitive]("string"),F,_);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof ne)}p.from=function(ne,F,_){return y(ne,F,_)},Object.setPrototypeOf(p.prototype,Uint8Array.prototype),Object.setPrototypeOf(p,Uint8Array);function Z(ne){if(typeof ne!="number")throw new TypeError('"size" argument must be of type number');if(ne<0)throw new RangeError('The value "'+ne+'" is invalid for option "size"')}function B(ne,F,_){return Z(ne),ne<=0?b(ne):F!==void 0?typeof _=="string"?b(ne).fill(F,_):b(ne).fill(F):b(ne)}p.alloc=function(ne,F,_){return B(ne,F,_)};function G(ne){return Z(ne),b(ne<0?0:W(ne)|0)}p.allocUnsafe=function(ne){return G(ne)},p.allocUnsafeSlow=function(ne){return G(ne)};function v(ne,F){if((typeof F!="string"||F==="")&&(F="utf8"),!p.isEncoding(F))throw new TypeError("Unknown encoding: "+F);const _=H(ne,F)|0;let fe=b(_);const ke=fe.write(ne,F);return ke!==_&&(fe=fe.slice(0,ke)),fe}function w(ne){const F=ne.length<0?0:W(ne.length)|0,_=b(F);for(let fe=0;fe=m)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+m.toString(16)+" bytes");return ne|0}function R(ne){return+ne!=ne&&(ne=0),p.alloc(+ne)}p.isBuffer=function(F){return F!=null&&F._isBuffer===!0&&F!==p.prototype},p.compare=function(F,_){if(qe(F,Uint8Array)&&(F=p.from(F,F.offset,F.byteLength)),qe(_,Uint8Array)&&(_=p.from(_,_.offset,_.byteLength)),!p.isBuffer(F)||!p.isBuffer(_))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(F===_)return 0;let fe=F.length,ke=_.length;for(let ue=0,le=Math.min(fe,ke);ueke.length?(p.isBuffer(le)||(le=p.from(le)),le.copy(ke,ue)):Uint8Array.prototype.set.call(ke,le,ue);else if(p.isBuffer(le))le.copy(ke,ue);else throw new TypeError('"list" argument must be an Array of Buffers');ue+=le.length}return ke};function H(ne,F){if(p.isBuffer(ne))return ne.length;if(ArrayBuffer.isView(ne)||qe(ne,ArrayBuffer))return ne.byteLength;if(typeof ne!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof ne);const _=ne.length,fe=arguments.length>2&&arguments[2]===!0;if(!fe&&_===0)return 0;let ke=!1;for(;;)switch(F){case"ascii":case"latin1":case"binary":return _;case"utf8":case"utf-8":return k(ne).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return _*2;case"hex":return _>>>1;case"base64":return Ve(ne).length;default:if(ke)return fe?-1:k(ne).length;F=(""+F).toLowerCase(),ke=!0}}p.byteLength=H;function Y(ne,F,_){let fe=!1;if((F===void 0||F<0)&&(F=0),F>this.length||((_===void 0||_>this.length)&&(_=this.length),_<=0)||(_>>>=0,F>>>=0,_<=F))return"";for(ne||(ne="utf8");;)switch(ne){case"hex":return Ge(this,F,_);case"utf8":case"utf-8":return U(this,F,_);case"ascii":return Ce(this,F,_);case"latin1":case"binary":return Ze(this,F,_);case"base64":return te(this,F,_);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Be(this,F,_);default:if(fe)throw new TypeError("Unknown encoding: "+ne);ne=(ne+"").toLowerCase(),fe=!0}}p.prototype._isBuffer=!0;function D(ne,F,_){const fe=ne[F];ne[F]=ne[_],ne[_]=fe}p.prototype.swap16=function(){const F=this.length;if(F%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let _=0;__&&(F+=" ... "),""},h&&(p.prototype[h]=p.prototype.inspect),p.prototype.compare=function(F,_,fe,ke,ue){if(qe(F,Uint8Array)&&(F=p.from(F,F.offset,F.byteLength)),!p.isBuffer(F))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof F);if(_===void 0&&(_=0),fe===void 0&&(fe=F?F.length:0),ke===void 0&&(ke=0),ue===void 0&&(ue=this.length),_<0||fe>F.length||ke<0||ue>this.length)throw new RangeError("out of range index");if(ke>=ue&&_>=fe)return 0;if(ke>=ue)return-1;if(_>=fe)return 1;if(_>>>=0,fe>>>=0,ke>>>=0,ue>>>=0,this===F)return 0;let le=ue-ke,re=fe-_;const oe=Math.min(le,re),we=this.slice(ke,ue),Ke=F.slice(_,fe);for(let Ye=0;Ye2147483647?_=2147483647:_<-2147483648&&(_=-2147483648),_=+_,mt(_)&&(_=ke?0:ne.length-1),_<0&&(_=ne.length+_),_>=ne.length){if(ke)return-1;_=ne.length-1}else if(_<0)if(ke)_=0;else return-1;if(typeof F=="string"&&(F=p.from(F,fe)),p.isBuffer(F))return F.length===0?-1:O(ne,F,_,fe,ke);if(typeof F=="number")return F=F&255,typeof Uint8Array.prototype.indexOf=="function"?ke?Uint8Array.prototype.indexOf.call(ne,F,_):Uint8Array.prototype.lastIndexOf.call(ne,F,_):O(ne,[F],_,fe,ke);throw new TypeError("val must be string, number or Buffer")}function O(ne,F,_,fe,ke){let ue=1,le=ne.length,re=F.length;if(fe!==void 0&&(fe=String(fe).toLowerCase(),fe==="ucs2"||fe==="ucs-2"||fe==="utf16le"||fe==="utf-16le")){if(ne.length<2||F.length<2)return-1;ue=2,le/=2,re/=2,_/=2}function oe(Ke,Ye){return ue===1?Ke[Ye]:Ke.readUInt16BE(Ye*ue)}let we;if(ke){let Ke=-1;for(we=_;wele&&(_=le-re),we=_;we>=0;we--){let Ke=!0;for(let Ye=0;Yeke&&(fe=ke)):fe=ke;const ue=F.length;fe>ue/2&&(fe=ue/2);let le;for(le=0;le>>0,isFinite(fe)?(fe=fe>>>0,ke===void 0&&(ke="utf8")):(ke=fe,fe=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");const ue=this.length-_;if((fe===void 0||fe>ue)&&(fe=ue),F.length>0&&(fe<0||_<0)||_>this.length)throw new RangeError("Attempt to write outside buffer bounds");ke||(ke="utf8");let le=!1;for(;;)switch(ke){case"hex":return J(this,F,_,fe);case"utf8":case"utf-8":return ee(this,F,_,fe);case"ascii":case"latin1":case"binary":return q(this,F,_,fe);case"base64":return $(this,F,_,fe);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return j(this,F,_,fe);default:if(le)throw new TypeError("Unknown encoding: "+ke);ke=(""+ke).toLowerCase(),le=!0}},p.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function te(ne,F,_){return F===0&&_===ne.length?u.fromByteArray(ne):u.fromByteArray(ne.slice(F,_))}function U(ne,F,_){_=Math.min(ne.length,_);const fe=[];let ke=F;for(;ke<_;){const ue=ne[ke];let le=null,re=ue>239?4:ue>223?3:ue>191?2:1;if(ke+re<=_){let oe,we,Ke,Ye;switch(re){case 1:ue<128&&(le=ue);break;case 2:oe=ne[ke+1],(oe&192)===128&&(Ye=(ue&31)<<6|oe&63,Ye>127&&(le=Ye));break;case 3:oe=ne[ke+1],we=ne[ke+2],(oe&192)===128&&(we&192)===128&&(Ye=(ue&15)<<12|(oe&63)<<6|we&63,Ye>2047&&(Ye<55296||Ye>57343)&&(le=Ye));break;case 4:oe=ne[ke+1],we=ne[ke+2],Ke=ne[ke+3],(oe&192)===128&&(we&192)===128&&(Ke&192)===128&&(Ye=(ue&15)<<18|(oe&63)<<12|(we&63)<<6|Ke&63,Ye>65535&&Ye<1114112&&(le=Ye))}}le===null?(le=65533,re=1):le>65535&&(le-=65536,fe.push(le>>>10&1023|55296),le=56320|le&1023),fe.push(le),ke+=re}return me(fe)}const ie=4096;function me(ne){const F=ne.length;if(F<=ie)return String.fromCharCode.apply(String,ne);let _="",fe=0;for(;fefe)&&(_=fe);let ke="";for(let ue=F;ue<_;++ue)ke+=vt[ne[ue]];return ke}function Be(ne,F,_){const fe=ne.slice(F,_);let ke="";for(let ue=0;uefe&&(F=fe),_<0?(_+=fe,_<0&&(_=0)):_>fe&&(_=fe),__)throw new RangeError("Trying to access beyond buffer length")}p.prototype.readUintLE=p.prototype.readUIntLE=function(F,_,fe){F=F>>>0,_=_>>>0,fe||Ne(F,_,this.length);let ke=this[F],ue=1,le=0;for(;++le<_&&(ue*=256);)ke+=this[F+le]*ue;return ke},p.prototype.readUintBE=p.prototype.readUIntBE=function(F,_,fe){F=F>>>0,_=_>>>0,fe||Ne(F,_,this.length);let ke=this[F+--_],ue=1;for(;_>0&&(ue*=256);)ke+=this[F+--_]*ue;return ke},p.prototype.readUint8=p.prototype.readUInt8=function(F,_){return F=F>>>0,_||Ne(F,1,this.length),this[F]},p.prototype.readUint16LE=p.prototype.readUInt16LE=function(F,_){return F=F>>>0,_||Ne(F,2,this.length),this[F]|this[F+1]<<8},p.prototype.readUint16BE=p.prototype.readUInt16BE=function(F,_){return F=F>>>0,_||Ne(F,2,this.length),this[F]<<8|this[F+1]},p.prototype.readUint32LE=p.prototype.readUInt32LE=function(F,_){return F=F>>>0,_||Ne(F,4,this.length),(this[F]|this[F+1]<<8|this[F+2]<<16)+this[F+3]*16777216},p.prototype.readUint32BE=p.prototype.readUInt32BE=function(F,_){return F=F>>>0,_||Ne(F,4,this.length),this[F]*16777216+(this[F+1]<<16|this[F+2]<<8|this[F+3])},p.prototype.readBigUInt64LE=ct(function(F){F=F>>>0,ye(F,"offset");const _=this[F],fe=this[F+7];(_===void 0||fe===void 0)&&Xe(F,this.length-8);const ke=_+this[++F]*2**8+this[++F]*2**16+this[++F]*2**24,ue=this[++F]+this[++F]*2**8+this[++F]*2**16+fe*2**24;return BigInt(ke)+(BigInt(ue)<>>0,ye(F,"offset");const _=this[F],fe=this[F+7];(_===void 0||fe===void 0)&&Xe(F,this.length-8);const ke=_*2**24+this[++F]*2**16+this[++F]*2**8+this[++F],ue=this[++F]*2**24+this[++F]*2**16+this[++F]*2**8+fe;return(BigInt(ke)<>>0,_=_>>>0,fe||Ne(F,_,this.length);let ke=this[F],ue=1,le=0;for(;++le<_&&(ue*=256);)ke+=this[F+le]*ue;return ue*=128,ke>=ue&&(ke-=Math.pow(2,8*_)),ke},p.prototype.readIntBE=function(F,_,fe){F=F>>>0,_=_>>>0,fe||Ne(F,_,this.length);let ke=_,ue=1,le=this[F+--ke];for(;ke>0&&(ue*=256);)le+=this[F+--ke]*ue;return ue*=128,le>=ue&&(le-=Math.pow(2,8*_)),le},p.prototype.readInt8=function(F,_){return F=F>>>0,_||Ne(F,1,this.length),this[F]&128?(255-this[F]+1)*-1:this[F]},p.prototype.readInt16LE=function(F,_){F=F>>>0,_||Ne(F,2,this.length);const fe=this[F]|this[F+1]<<8;return fe&32768?fe|4294901760:fe},p.prototype.readInt16BE=function(F,_){F=F>>>0,_||Ne(F,2,this.length);const fe=this[F+1]|this[F]<<8;return fe&32768?fe|4294901760:fe},p.prototype.readInt32LE=function(F,_){return F=F>>>0,_||Ne(F,4,this.length),this[F]|this[F+1]<<8|this[F+2]<<16|this[F+3]<<24},p.prototype.readInt32BE=function(F,_){return F=F>>>0,_||Ne(F,4,this.length),this[F]<<24|this[F+1]<<16|this[F+2]<<8|this[F+3]},p.prototype.readBigInt64LE=ct(function(F){F=F>>>0,ye(F,"offset");const _=this[F],fe=this[F+7];(_===void 0||fe===void 0)&&Xe(F,this.length-8);const ke=this[F+4]+this[F+5]*2**8+this[F+6]*2**16+(fe<<24);return(BigInt(ke)<>>0,ye(F,"offset");const _=this[F],fe=this[F+7];(_===void 0||fe===void 0)&&Xe(F,this.length-8);const ke=(_<<24)+this[++F]*2**16+this[++F]*2**8+this[++F];return(BigInt(ke)<>>0,_||Ne(F,4,this.length),d.read(this,F,!0,23,4)},p.prototype.readFloatBE=function(F,_){return F=F>>>0,_||Ne(F,4,this.length),d.read(this,F,!1,23,4)},p.prototype.readDoubleLE=function(F,_){return F=F>>>0,_||Ne(F,8,this.length),d.read(this,F,!0,52,8)},p.prototype.readDoubleBE=function(F,_){return F=F>>>0,_||Ne(F,8,this.length),d.read(this,F,!1,52,8)};function Se(ne,F,_,fe,ke,ue){if(!p.isBuffer(ne))throw new TypeError('"buffer" argument must be a Buffer instance');if(F>ke||Fne.length)throw new RangeError("Index out of range")}p.prototype.writeUintLE=p.prototype.writeUIntLE=function(F,_,fe,ke){if(F=+F,_=_>>>0,fe=fe>>>0,!ke){const re=Math.pow(2,8*fe)-1;Se(this,F,_,fe,re,0)}let ue=1,le=0;for(this[_]=F&255;++le>>0,fe=fe>>>0,!ke){const re=Math.pow(2,8*fe)-1;Se(this,F,_,fe,re,0)}let ue=fe-1,le=1;for(this[_+ue]=F&255;--ue>=0&&(le*=256);)this[_+ue]=F/le&255;return _+fe},p.prototype.writeUint8=p.prototype.writeUInt8=function(F,_,fe){return F=+F,_=_>>>0,fe||Se(this,F,_,1,255,0),this[_]=F&255,_+1},p.prototype.writeUint16LE=p.prototype.writeUInt16LE=function(F,_,fe){return F=+F,_=_>>>0,fe||Se(this,F,_,2,65535,0),this[_]=F&255,this[_+1]=F>>>8,_+2},p.prototype.writeUint16BE=p.prototype.writeUInt16BE=function(F,_,fe){return F=+F,_=_>>>0,fe||Se(this,F,_,2,65535,0),this[_]=F>>>8,this[_+1]=F&255,_+2},p.prototype.writeUint32LE=p.prototype.writeUInt32LE=function(F,_,fe){return F=+F,_=_>>>0,fe||Se(this,F,_,4,4294967295,0),this[_+3]=F>>>24,this[_+2]=F>>>16,this[_+1]=F>>>8,this[_]=F&255,_+4},p.prototype.writeUint32BE=p.prototype.writeUInt32BE=function(F,_,fe){return F=+F,_=_>>>0,fe||Se(this,F,_,4,4294967295,0),this[_]=F>>>24,this[_+1]=F>>>16,this[_+2]=F>>>8,this[_+3]=F&255,_+4};function Pe(ne,F,_,fe,ke){se(F,fe,ke,ne,_,7);let ue=Number(F&BigInt(4294967295));ne[_++]=ue,ue=ue>>8,ne[_++]=ue,ue=ue>>8,ne[_++]=ue,ue=ue>>8,ne[_++]=ue;let le=Number(F>>BigInt(32)&BigInt(4294967295));return ne[_++]=le,le=le>>8,ne[_++]=le,le=le>>8,ne[_++]=le,le=le>>8,ne[_++]=le,_}function ze(ne,F,_,fe,ke){se(F,fe,ke,ne,_,7);let ue=Number(F&BigInt(4294967295));ne[_+7]=ue,ue=ue>>8,ne[_+6]=ue,ue=ue>>8,ne[_+5]=ue,ue=ue>>8,ne[_+4]=ue;let le=Number(F>>BigInt(32)&BigInt(4294967295));return ne[_+3]=le,le=le>>8,ne[_+2]=le,le=le>>8,ne[_+1]=le,le=le>>8,ne[_]=le,_+8}p.prototype.writeBigUInt64LE=ct(function(F,_=0){return Pe(this,F,_,BigInt(0),BigInt("0xffffffffffffffff"))}),p.prototype.writeBigUInt64BE=ct(function(F,_=0){return ze(this,F,_,BigInt(0),BigInt("0xffffffffffffffff"))}),p.prototype.writeIntLE=function(F,_,fe,ke){if(F=+F,_=_>>>0,!ke){const oe=Math.pow(2,8*fe-1);Se(this,F,_,fe,oe-1,-oe)}let ue=0,le=1,re=0;for(this[_]=F&255;++ue>0)-re&255;return _+fe},p.prototype.writeIntBE=function(F,_,fe,ke){if(F=+F,_=_>>>0,!ke){const oe=Math.pow(2,8*fe-1);Se(this,F,_,fe,oe-1,-oe)}let ue=fe-1,le=1,re=0;for(this[_+ue]=F&255;--ue>=0&&(le*=256);)F<0&&re===0&&this[_+ue+1]!==0&&(re=1),this[_+ue]=(F/le>>0)-re&255;return _+fe},p.prototype.writeInt8=function(F,_,fe){return F=+F,_=_>>>0,fe||Se(this,F,_,1,127,-128),F<0&&(F=255+F+1),this[_]=F&255,_+1},p.prototype.writeInt16LE=function(F,_,fe){return F=+F,_=_>>>0,fe||Se(this,F,_,2,32767,-32768),this[_]=F&255,this[_+1]=F>>>8,_+2},p.prototype.writeInt16BE=function(F,_,fe){return F=+F,_=_>>>0,fe||Se(this,F,_,2,32767,-32768),this[_]=F>>>8,this[_+1]=F&255,_+2},p.prototype.writeInt32LE=function(F,_,fe){return F=+F,_=_>>>0,fe||Se(this,F,_,4,2147483647,-2147483648),this[_]=F&255,this[_+1]=F>>>8,this[_+2]=F>>>16,this[_+3]=F>>>24,_+4},p.prototype.writeInt32BE=function(F,_,fe){return F=+F,_=_>>>0,fe||Se(this,F,_,4,2147483647,-2147483648),F<0&&(F=4294967295+F+1),this[_]=F>>>24,this[_+1]=F>>>16,this[_+2]=F>>>8,this[_+3]=F&255,_+4},p.prototype.writeBigInt64LE=ct(function(F,_=0){return Pe(this,F,_,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),p.prototype.writeBigInt64BE=ct(function(F,_=0){return ze(this,F,_,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function Fe(ne,F,_,fe,ke,ue){if(_+fe>ne.length)throw new RangeError("Index out of range");if(_<0)throw new RangeError("Index out of range")}function Ue(ne,F,_,fe,ke){return F=+F,_=_>>>0,ke||Fe(ne,F,_,4),d.write(ne,F,_,fe,23,4),_+4}p.prototype.writeFloatLE=function(F,_,fe){return Ue(this,F,_,!0,fe)},p.prototype.writeFloatBE=function(F,_,fe){return Ue(this,F,_,!1,fe)};function _e(ne,F,_,fe,ke){return F=+F,_=_>>>0,ke||Fe(ne,F,_,8),d.write(ne,F,_,fe,52,8),_+8}p.prototype.writeDoubleLE=function(F,_,fe){return _e(this,F,_,!0,fe)},p.prototype.writeDoubleBE=function(F,_,fe){return _e(this,F,_,!1,fe)},p.prototype.copy=function(F,_,fe,ke){if(!p.isBuffer(F))throw new TypeError("argument should be a Buffer");if(fe||(fe=0),!ke&&ke!==0&&(ke=this.length),_>=F.length&&(_=F.length),_||(_=0),ke>0&&ke=this.length)throw new RangeError("Index out of range");if(ke<0)throw new RangeError("sourceEnd out of bounds");ke>this.length&&(ke=this.length),F.length-_>>0,fe=fe===void 0?this.length:fe>>>0,F||(F=0);let ue;if(typeof F=="number")for(ue=_;ue2**32?ke=nt(String(_)):typeof _=="bigint"&&(ke=String(_),(_>BigInt(2)**BigInt(32)||_<-(BigInt(2)**BigInt(32)))&&(ke=nt(ke)),ke+="n"),fe+=` It must be ${F}. Received ${ke}`,fe},RangeError);function nt(ne){let F="",_=ne.length;const fe=ne[0]==="-"?1:0;for(;_>=fe+4;_-=3)F=`_${ne.slice(_-3,_)}${F}`;return`${ne.slice(0,_)}${F}`}function Te(ne,F,_){ye(F,"offset"),(ne[F]===void 0||ne[F+_]===void 0)&&Xe(F,ne.length-(_+1))}function se(ne,F,_,fe,ke,ue){if(ne>_||ne3?F===0||F===BigInt(0)?re=`>= 0${le} and < 2${le} ** ${(ue+1)*8}${le}`:re=`>= -(2${le} ** ${(ue+1)*8-1}${le}) and < 2 ** ${(ue+1)*8-1}${le}`:re=`>= ${F}${le} and <= ${_}${le}`,new ot.ERR_OUT_OF_RANGE("value",re,ne)}Te(fe,ke,ue)}function ye(ne,F){if(typeof ne!="number")throw new ot.ERR_INVALID_ARG_TYPE(F,"number",ne)}function Xe(ne,F,_){throw Math.floor(ne)!==ne?(ye(ne,_),new ot.ERR_OUT_OF_RANGE(_||"offset","an integer",ne)):F<0?new ot.ERR_BUFFER_OUT_OF_BOUNDS:new ot.ERR_OUT_OF_RANGE(_||"offset",`>= ${_?1:0} and <= ${F}`,ne)}const K=/[^+/0-9A-Za-z-_]/g;function T(ne){if(ne=ne.split("=")[0],ne=ne.trim().replace(K,""),ne.length<2)return"";for(;ne.length%4!==0;)ne=ne+"=";return ne}function k(ne,F){F=F||1/0;let _;const fe=ne.length;let ke=null;const ue=[];for(let le=0;le55295&&_<57344){if(!ke){if(_>56319){(F-=3)>-1&&ue.push(239,191,189);continue}else if(le+1===fe){(F-=3)>-1&&ue.push(239,191,189);continue}ke=_;continue}if(_<56320){(F-=3)>-1&&ue.push(239,191,189),ke=_;continue}_=(ke-55296<<10|_-56320)+65536}else ke&&(F-=3)>-1&&ue.push(239,191,189);if(ke=null,_<128){if((F-=1)<0)break;ue.push(_)}else if(_<2048){if((F-=2)<0)break;ue.push(_>>6|192,_&63|128)}else if(_<65536){if((F-=3)<0)break;ue.push(_>>12|224,_>>6&63|128,_&63|128)}else if(_<1114112){if((F-=4)<0)break;ue.push(_>>18|240,_>>12&63|128,_>>6&63|128,_&63|128)}else throw new Error("Invalid code point")}return ue}function ge(ne){const F=[];for(let _=0;_>8,ke=_%256,ue.push(ke),ue.push(fe);return ue}function Ve(ne){return u.toByteArray(T(ne))}function De(ne,F,_,fe){let ke;for(ke=0;ke=F.length||ke>=ne.length);++ke)F[ke+_]=ne[ke];return ke}function qe(ne,F){return ne instanceof F||ne!=null&&ne.constructor!=null&&ne.constructor.name!=null&&ne.constructor.name===F.name}function mt(ne){return ne!==ne}const vt=function(){const ne="0123456789abcdef",F=new Array(256);for(let _=0;_<16;++_){const fe=_*16;for(let ke=0;ke<16;++ke)F[fe+ke]=ne[_]+ne[ke]}return F}();function ct(ne){return typeof BigInt>"u"?Ht:ne}function Ht(){throw new Error("BigInt not supported")}})(PVe);var xc=WI,tn=_Ht,OVe=PVe.Buffer;globalThis.__TYPEDARRAY_POOL||(globalThis.__TYPEDARRAY_POOL={UINT8:tn([32,0]),UINT16:tn([32,0]),UINT32:tn([32,0]),BIGUINT64:tn([32,0]),INT8:tn([32,0]),INT16:tn([32,0]),INT32:tn([32,0]),BIGINT64:tn([32,0]),FLOAT:tn([32,0]),DOUBLE:tn([32,0]),DATA:tn([32,0]),UINT8C:tn([32,0]),BUFFER:tn([32,0])});var gTt=typeof Uint8ClampedArray<"u",ITt=typeof BigUint64Array<"u",iTt=typeof BigInt64Array<"u",Ci=globalThis.__TYPEDARRAY_POOL;Ci.UINT8C||(Ci.UINT8C=tn([32,0]));Ci.BIGUINT64||(Ci.BIGUINT64=tn([32,0]));Ci.BIGINT64||(Ci.BIGINT64=tn([32,0]));Ci.BUFFER||(Ci.BUFFER=tn([32,0]));var nk=Ci.DATA,Ck=Ci.BUFFER;og.free=function(g){if(OVe.isBuffer(g))Ck[xc.log2(g.length)].push(g);else{if(Object.prototype.toString.call(g)!=="[object ArrayBuffer]"&&(g=g.buffer),!g)return;var I=g.length||g.byteLength,i=xc.log2(I)|0;nk[i].push(g)}};function _Ve(e){if(e){var g=e.length||e.byteLength,I=xc.log2(g);nk[I].push(e)}}function nTt(e){_Ve(e.buffer)}og.freeUint8=og.freeUint16=og.freeUint32=og.freeBigUint64=og.freeInt8=og.freeInt16=og.freeInt32=og.freeBigInt64=og.freeFloat32=og.freeFloat=og.freeFloat64=og.freeDouble=og.freeUint8Clamped=og.freeDataView=nTt;og.freeArrayBuffer=_Ve;og.freeBuffer=function(g){Ck[xc.log2(g.length)].push(g)};og.malloc=function(g,I){if(I===void 0||I==="arraybuffer")return xC(g);switch(I){case"uint8":return fj(g);case"uint16":return LVe(g);case"uint32":return UVe(g);case"int8":return QVe(g);case"int16":return jVe(g);case"int32":return $Ve(g);case"float":case"float32":return qVe(g);case"double":case"float64":return eRe(g);case"uint8_clamped":return tRe(g);case"bigint64":return IRe(g);case"biguint64":return gRe(g);case"buffer":return nRe(g);case"data":case"dataview":return iRe(g);default:return null}return null};function xC(g){var g=xc.nextPow2(g),I=xc.log2(g),i=nk[I];return i.length>0?i.pop():new ArrayBuffer(g)}og.mallocArrayBuffer=xC;function fj(e){return new Uint8Array(xC(e),0,e)}og.mallocUint8=fj;function LVe(e){return new Uint16Array(xC(2*e),0,e)}og.mallocUint16=LVe;function UVe(e){return new Uint32Array(xC(4*e),0,e)}og.mallocUint32=UVe;function QVe(e){return new Int8Array(xC(e),0,e)}og.mallocInt8=QVe;function jVe(e){return new Int16Array(xC(2*e),0,e)}og.mallocInt16=jVe;function $Ve(e){return new Int32Array(xC(4*e),0,e)}og.mallocInt32=$Ve;function qVe(e){return new Float32Array(xC(4*e),0,e)}og.mallocFloat32=og.mallocFloat=qVe;function eRe(e){return new Float64Array(xC(8*e),0,e)}og.mallocFloat64=og.mallocDouble=eRe;function tRe(e){return gTt?new Uint8ClampedArray(xC(e),0,e):fj(e)}og.mallocUint8Clamped=tRe;function gRe(e){return ITt?new BigUint64Array(xC(8*e),0,e):null}og.mallocBigUint64=gRe;function IRe(e){return iTt?new BigInt64Array(xC(8*e),0,e):null}og.mallocBigInt64=IRe;function iRe(e){return new DataView(xC(e),0,e)}og.mallocDataView=iRe;function nRe(e){e=xc.nextPow2(e);var g=xc.log2(e),I=Ck[g];return I.length>0?I.pop():new OVe(e)}og.mallocBuffer=nRe;og.clearCache=function(){for(var g=0;g<32;++g)Ci.UINT8[g].length=0,Ci.UINT16[g].length=0,Ci.UINT32[g].length=0,Ci.INT8[g].length=0,Ci.INT16[g].length=0,Ci.INT32[g].length=0,Ci.FLOAT[g].length=0,Ci.DOUBLE[g].length=0,Ci.BIGUINT64[g].length=0,Ci.BIGINT64[g].length=0,Ci.UINT8C[g].length=0,nk[g].length=0,Ck[g].length=0};var CTt=rTt,_1=32;function rTt(e,g){g<=4*_1?L1(0,g-1,e):U1(0,g-1,e)}function L1(e,g,I){for(var i=2*(e+1),n=e+1;n<=g;++n){for(var C=I[i++],r=I[i++],o=n,A=i-2;o-- >e;){var s=I[A-2],a=I[A-1];if(sI[g+1]:!0}function sR(e,g,I,i){e*=2;var n=i[e];return n>1,o=r-i,A=r+i,s=n,a=o,l=r,c=A,u=C,d=e+1,h=g-1,m=0;Da(s,a,I)&&(m=s,s=a,a=m),Da(c,u,I)&&(m=c,c=u,u=m),Da(s,l,I)&&(m=s,s=l,l=m),Da(a,l,I)&&(m=a,a=l,l=m),Da(s,c,I)&&(m=s,s=c,c=m),Da(l,c,I)&&(m=l,l=c,c=m),Da(a,u,I)&&(m=a,a=u,u=m),Da(a,l,I)&&(m=a,a=l,l=m),Da(c,u,I)&&(m=c,c=u,u=m);for(var f=I[2*a],b=I[2*a+1],p=I[2*c],y=I[2*c+1],Z=2*s,B=2*l,G=2*u,v=2*n,w=2*r,V=2*C,S=0;S<2;++S){var X=I[Z+S],W=I[B+S],R=I[G+S];I[v+S]=X,I[w+S]=W,I[V+S]=R}hre(o,e,I),hre(A,g,I);for(var H=d;H<=h;++H)if(sR(H,f,b,I))H!==d&&dre(H,d,I),++d;else if(!sR(H,p,y,I))for(;;)if(sR(h,p,y,I)){sR(h,f,b,I)?(oTt(H,d,h,I),++d,--h):(dre(H,h,I),--h);break}else{if(--h>>1;rk(ng,b);for(var p=0,y=0,d=0;d=gr)Z=Z-gr|0,Np(Gs,Sd,y--,Z);else if(Z>=0)Np(Cn,Zs,p--,Z);else if(Z<=-gr){Z=-Z-gr|0;for(var B=0;B>>1;rk(ng,b);for(var p=0,y=0,Z=0,d=0;d>1===ng[2*d+3]>>1&&(G=2,d+=1),B<0){for(var v=-(B>>1)-1,w=0;w>1)-1;G===0?Np(Cn,Zs,p--,v):G===1?Np(Gs,Sd,y--,v):G===2&&Np(Tp,Iv,Z--,v)}}}function cTt(e,g,I,i,n,C,r,o,A,s,a,l){var c=0,u=2*e,d=g,h=g+e,m=1,f=1;i?f=gr:m=gr;for(var b=n;b>>1;rk(ng,B);for(var G=0,b=0;b=gr?(w=!i,p-=gr):(w=!!i,p-=1),w)kp(Cn,Zs,G++,p);else{var V=l[p],S=u*p,X=a[S+g+1],W=a[S+g+1+e];e:for(var R=0;R>>1;rk(ng,p);for(var y=0,h=0;h=gr)Cn[y++]=m-gr;else{m-=1;var B=a[m],G=c*m,v=s[G+g+1],w=s[G+g+1+e];e:for(var V=0;V=0;--V)if(Cn[V]===m){for(var R=V+1;R"+yj+"-"+T9+"){"),e?(C(!0,!1),n.push("}else{"),C(!1,!1)):(n.push("if("+rx+"){"),C(!0,!0),n.push("}else{"),C(!0,!1),n.push("}}else{if("+rx+"){"),C(!1,!0),n.push("}else{"),C(!1,!1),n.push("}")),n.push("}}return "+g);var r=I.join("")+n.join(""),o=new Function(r);return o()}pj.partial=aRe(!1);pj.full=aRe(!0);var sRe=mTt,hTt="for(var j=2*a,k=j*c,l=k,m=c,n=b,o=a+b,p=c;d>p;++p,k+=j){var _;if($)if(m===p)m+=1,l+=j;else{for(var s=0;j>s;++s){var t=e[k+s];e[k+s]=e[l],e[l++]=t}var u=f[p];f[p]=f[m],f[m++]=u}}return m";function mTt(e,g){var I="abcdef".split("").concat(g),i=[];return e.indexOf("lo")>=0&&i.push("lo=e[k+n]"),e.indexOf("hi")>=0&&i.push("hi=e[k+o]"),I.push(hTt.replace("_",i.join()).replace("$",e)),Function.apply(void 0,I)}var fTt=ZTt,pTt=sRe,fre=pTt("loI&&n[l+g]>s;--a,l-=r){for(var c=l,u=l+r,d=0;d>>1,s=2*e,a=A,l=n[s*A+g];r=m?(a=h,l=m):d>=b?(a=u,l=d):(a=f,l=b):m>=b?(a=h,l=m):b>=d?(a=u,l=d):(a=f,l=b);for(var Z=s*(o-1),B=s*a,p=0;p=p0)&&!(p1>=hi)",["p0","p1"]),bre=_0("lo===p0",["p0"]),WTt=_0("lo0;){s-=1;var c=s*Zj,u=Ln[c],d=Ln[c+1],h=Ln[c+2],m=Ln[c+3],f=Ln[c+4],b=Ln[c+5],p=s*Gj,y=wd[p],Z=wd[p+1],B=b&1,G=!!(b&16),v=n,w=C,V=o,S=A;if(B&&(v=o,w=A,V=n,S=C),!(b&2&&(h=WTt(e,u,d,h,v,w,Z),d>=h))&&!(b&4&&(d=XTt(e,u,d,h,v,w,y),d>=h))){var X=h-d,W=f-m;if(G){if(e*X*(X+W)>>1;if(!(r<=0)){var o,A=fl.mallocDouble(2*r*n),s=fl.mallocInt32(n);if(n=Zre(e,r,A,s),n>0){if(r===1&&i)lR.init(n),o=lR.sweepComplete(r,I,0,n,A,s,0,n,A,s);else{var a=fl.mallocDouble(2*r*C),l=fl.mallocInt32(C);C=Zre(g,r,a,l),C>0&&(lR.init(n+C),r===1?o=lR.sweepBipartite(r,I,0,n,A,s,0,C,a,l):o=DTt(r,I,i,n,A,s,C,a,l),fl.free(a),fl.free(l))}fl.free(A),fl.free(s)}return o}}}var HB;function uRe(e,g){HB.push([e,g])}function FTt(e){return HB=[],N9(e,e,uRe,!0),HB}function ETt(e,g){return HB=[],N9(e,g,uRe,!1),HB}function MTt(e,g,I){switch(arguments.length){case 1:return FTt(e);case 2:return typeof g=="function"?N9(e,e,g,!0):ETt(e,g);case 3:return N9(e,g,I,!1);default:throw new Error("box-intersect: Invalid arguments")}}const jS=DC(KTt);var dRe={exports:{}},hRe=zTt,Gre=+(Math.pow(2,27)+1);function zTt(e,g,I){var i=e*g,n=Gre*e,C=n-e,r=n-C,o=e-r,A=Gre*g,s=A-g,a=A-s,l=g-a,c=i-r*a,u=c-o*a,d=u-r*l,h=o*l-d;return I?(I[0]=h,I[1]=i,I):[h,i]}var PTt=OTt;function JTt(e,g){var I=e+g,i=I-e,n=I-i,C=g-i,r=e-n,o=r+C;return o?[o,I]:[I]}function OTt(e,g){var I=e.length|0,i=g.length|0;if(I===1&&i===1)return JTt(e[0],g[0]);var n=I+i,C=new Array(n),r=0,o=0,A=0,s=Math.abs,a=e[o],l=s(a),c=g[A],u=s(c),d,h;l=i?(d=a,o+=1,o=i?(d=a,o+=1,o0){if(v<=0)return w;V=G+v}else if(G<0){if(v>=0)return w;V=-(G+v)}else return w;var S=o*V;return w>=S||w<=-S?w:u(y,Z,B)},function(y,Z,B,G){var v=y[0]-G[0],w=Z[0]-G[0],V=B[0]-G[0],S=y[1]-G[1],X=Z[1]-G[1],W=B[1]-G[1],R=y[2]-G[2],H=Z[2]-G[2],Y=B[2]-G[2],D=w*W,E=V*X,O=V*S,J=v*W,ee=v*X,q=w*S,$=R*(D-E)+H*(O-J)+Y*(ee-q),j=(Math.abs(D)+Math.abs(E))*Math.abs(R)+(Math.abs(O)+Math.abs(J))*Math.abs(H)+(Math.abs(ee)+Math.abs(q))*Math.abs(Y),te=A*j;return $>te||-$>te?$:d(y,Z,B,G)}];function m(p){var y=h[p.length];return y||(y=h[p.length]=c(p.length)),y.apply(void 0,p)}function f(p,y,Z,B,G,v,w){return function(S,X,W,R,H){switch(arguments.length){case 0:case 1:return 0;case 2:return B(S,X);case 3:return G(S,X,W);case 4:return v(S,X,W,R);case 5:return w(S,X,W,R,H)}for(var Y=new Array(arguments.length),D=0;D0;){var b=(A+n-1)%n,p=e[b];if(p[1]!==i)break;var y=p[0];m=Math.min(m,y),f=Math.max(f,y),A=b}if(A===0)return m<=I&&I<=f?0:1;r=A+1}for(var Z=e[(A+n-1)%n][1];o+1"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function Xr(e){return Xr=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},Xr(e)}const Bre=16,Sre=50,lx=5e3,wre=5,uNt=14,Bu={fontSize:`${uNt}px`,fontFamily:"Arial",stroke:"white",strokeThickness:2,fontWeight:400,dropShadow:!0,dropShadowColor:"white",dropShadowDistance:0,dropShadowBlur:2};let fRe=function(e){ANt(I,e);var g=aNt(I);function I(i,n){var C;return iNt(this,I),C=g.call(this,i,n),C.valueScaleTransform=Fi,C}return nNt(I,[{key:"initialize",value:function(){this.initialized||([this.prevK,this.vertK,this.vertY]=[1,1,0],this.drawnRects||(this.drawnRects={}),this.colorScale||(this.options.colorRange?this.colorScale=Dc(this.options.colorRange):this.colorScale=Gb),this.initialized=!0)}},{key:"initTile",value:function(n){n.texts={},n.rectGraphics=new rt.PIXI.Graphics,n.textGraphics=new rt.PIXI.Graphics,n.graphics.addChild(n.rectGraphics),n.graphics.addChild(n.textGraphics);let C=[],r=[];if(n.tileData&&n.tileData.length){if(n.tileData.sort((o,A)=>A.importance-o.importance),!this.options||!this.options.valueColumn){const o=n.tileData.map(A=>{const s=+A.chrOffset;return{from:+A.fields[1]+s,to:+A.fields[2]+s,value:A,text:A.fields[3],strand:A.fields.length>=6&&A.fields[5]==="-"?"-":"+"}});C=n9(o.filter(A=>A.strand==="+")),r=n9(o.filter(A=>A.strand==="-"))}else C=[n.tileData.map(o=>({value:o}))];n.plusStrandRows=C,n.minusStrandRows=r,this.options.showTexts&&n.tileData.forEach((o,A)=>{const s=o.fields;if(o.importance||(o.importance=Math.random()),n.textWidths={},n.textHeights={},A>=(+this.options.maxTexts||Sre))return;const a=new rt.PIXI.Text(s[3],{...Bu,fontSize:+this.options.fontSize||Bu.fontSize});this.flipText&&(a.scale.x=-1),a.anchor.x=.5,a.anchor.y=.5,n.texts[o.uid]=a,n.textGraphics.addChild(a)})}n.initialized=!0}},{key:"removeTileRects",value:function(n){const C=+n.tileId.split(".")[0];n.rectGraphics.clear(),n.rendered=!1,n.tileData&&n.tileData.length&&n.tileData.forEach((r,o)=>{this.drawnRects[C]&&this.drawnRects[C][r.uid]&&this.drawnRects[C][r.uid][2]===n.tileId&&delete this.drawnRects[C][r.uid]})}},{key:"destroyTile",value:function(n){this.removeTileRects(n),n.graphics.removeChild(n.textGraphics),n.graphics.removeChild(n.rectGraphics)}},{key:"removeTiles",value:function(n){WA(Xr(I.prototype),"removeTiles",this).call(this,n)}},{key:"drawTile",value:function(n){this.options&&this.options.valueColumn&&this.valueScale&&this.drawAxis(this.valueScale)}},{key:"rerender",value:function(n,C){WA(Xr(I.prototype),"rerender",this).call(this,n,C),this.valueScale=null,this.drawnRects={},this.options.colorRange?this.colorScale=Dc(this.options.colorRange):this.colorScale=Gb;for(const r of this.visibleAndFetchedTiles())this.destroyTile(r),this.initTile(r),this.renderTile(r)}},{key:"updateTile",value:function(n){this.areAllVisibleTilesLoaded()&&this.renderTile(n)}},{key:"allVisibleRects",value:function(){const n={};Object.values(this.fetchedTiles).forEach(A=>{if(A.plusStrandRows)for(const s of A.plusStrandRows[0])n[s.value.uid]||(n[s.value.uid]=s)});const C=Object.values(n).sort((A,s)=>A.from-s.from);let r=0,o=0;for(let A=0;A=0&&C.length;A--)C[A].staggeredStartPosition=(o+r-A)%2;return n}},{key:"drawSegmentStyle",value:function(n,C,r,o,A,s){const l=o+A/2,c=[C,o,C+2*.1,o,C+2*.1,l-.1,r-2*.1,l-.1,r-2*.1,o,r,o,r,o+A,r-2*.1,o+A,r-2*.1,l+.1,C+2*.1,l+.1,C+2*.1,o+A,C,o+A];return n.rectGraphics.drawPolygon(c),c}},{key:"drawPoly",value:function(n,C,r,o,A,s){let a=null;return this.options.annotationStyle==="segment"?this.drawSegmentStyle(n,C,r,o,A,s):((s==="+"||s==="-")&&r-C=(+this.options.maxTexts||Sre)||!n.texts[h.uid])continue;const X=n.texts[h.uid];X.position.x=this._xScale(y),X.position.y=v+B/2,X.nominalY=v+B/2,S&&(X.alreadyDrawn=!0);const W=this.options.fontColor!==void 0?Kt(this.options.fontColor):s;if(X.style={...Bu,fill:W,fontSize:+this.options.fontSize||Bu.fontSize},!(m[3]in n.textWidths)){X.updateTransform();const R=X.getBounds().width,H=X.getBounds().height,Y=5;n.textWidths[m[3]]=R,n.textHeights[m[3]]=H-Y}}}},{key:"renderTile",value:function(n){let C=n.plusStrandRows?n.plusStrandRows.length:1,r=n.minusStrandRows?n.minusStrandRows.length:1;for(const o of this.visibleAndFetchedTiles()){if(!o.initialized)return;!o.plusStrandRows&&!o.minusStrandRows||(C=Math.max(o.plusStrandRows.length,C),r=Math.max(o.minusStrandRows.length,r))}if(n.rendered&&this.removeTileRects(n),n.drawnAtScale=this._xScale.copy(),n.rendered=!0,this.setValueScale(),this.setColorValueScale(),n.tileData&&n.tileData.length){const o=this.options.plusStrandColor||this.options.fillColor||"blue",A=this.options.minusStrandColor||this.options.fillColor||"purple",s=0;let a=0;this.options.separatePlusMinusStrands?a=C*this.dimensions[1]/(C+r)-s/2:a=this.dimensions[1],this.renderRows(n,n.plusStrandRows,C,0,a,o),this.renderRows(n,n.minusStrandRows,r,this.options.separatePlusMinusStrands?a+s/2:0,this.dimensions[1],A)}Bd.stretchRects(this,[o=>o.rectGraphics])}},{key:"calculateZoomLevel",value:function(){const n=Gt.calculateZoomLevel(this._xScale,this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0]);let C=Math.min(n,this.maxZoom);return C=Math.max(C,0),C}},{key:"minVisibleValueInTiles",value:function(n){let C=this.visibleAndFetchedIds();C.length===0&&(C=Object.keys(this.fetchedTiles));let r=Math.min.apply(null,C.map(o=>this.fetchedTiles[o]).filter(o=>o.tileData&&o.tileData.length).map(o=>Math.min.apply(null,o.tileData.sort((A,s)=>s.importance-A.importance).slice(0,lx).map(A=>+A.fields[n-1]).filter(A=>!Number.isNaN(A)))));return r===Number.MAX_SAFE_INTEGER&&(r=null),r}},{key:"maxVisibleValueInTiles",value:function(n){let C=this.visibleAndFetchedIds();C.length===0&&(C=Object.keys(this.fetchedTiles));let r=Math.max.apply(null,C.map(o=>this.fetchedTiles[o]).filter(o=>o.tileData&&o.tileData.length).map(o=>Math.max.apply(null,o.tileData.sort((A,s)=>s.importance-A.importance).slice(0,lx).map(A=>+A.fields[n-1]).filter(A=>!Number.isNaN(A)))));return r===Number.MIN_SAFE_INTEGER&&(r=null),r}},{key:"calculateMedianVisibleValue",value:function(n){this.areAllVisibleTilesLoaded()&&this.allTilesLoaded();let C=this.visibleAndFetchedIds();C.length===0&&(C=Object.keys(this.fetchedTiles));const r=[].concat(...C.map(o=>this.fetchedTiles[o]).filter(o=>o.tileData&&o.tileData.length).map(o=>o.tileData.sort((A,s)=>s.importance-A.importance).slice(0,lx).map(A=>+A.fields[n-1]))).filter(o=>o>0);this.medianVisibleValue=FU(r)}},{key:"draw",value:function(){WA(Xr(I.prototype),"draw",this).call(this),this.allTexts=[],this.allBoxes=[];for(const n in this.fetchedTiles){const C=this.fetchedTiles[n];if(C.rectGraphics.scale.y=this.vertK,C.rectGraphics.position.y=this.vertY,!C.drawnAtScale)return;Bd.stretchRects(this,[o=>o.rectGraphics]);const r=this.parentInFetched(C);C.initialized&&C.tileData&&C.tileData.length&&C.tileData.forEach(o=>{if(!C.texts)return;const A=o.fields,s=A[3],a=C.texts[o.uid];if(!a)return;const l=+o.chrOffset,c=+A[1]+l,u=+A[2]+l,d=(c+u)/2;if(a.position.x=this._xScale(d),a.position.y=a.nominalY*(this.vertK*this.prevK)+this.vertY,!r&&!a.alreadyDrawn){a.visible=!0;const h=3;this.allBoxes.push([a.position.x-h,a.position.y-C.textHeights[A[3]]/2,a.position.x+C.textWidths[A[3]]+h,a.position.y+C.textHeights[A[3]]/2]),this.allTexts.push({importance:o.importance,text:a,caption:s,strand:A[5]})}else a.visible=!1})}this.hideOverlaps(this.allBoxes,this.allTexts)}},{key:"hideOverlaps",value:function(n,C){jS(n,(r,o)=>{C[r].importance>C[o].importance?C[r].text.visible&&(C[o].text.visible=!1):C[o].text.visible&&(C[r].text.visible=!1)})}},{key:"setPosition",value:function(n){WA(Xr(I.prototype),"setPosition",this).call(this,n),[this.pMain.position.x,this.pMain.position.y]=this.position}},{key:"setDimensions",value:function(n){WA(Xr(I.prototype),"setDimensions",this).call(this,n)}},{key:"zoomed",value:function(n,C){this.xScale(n),this.yScale(C),this.refreshTiles(),this.draw()}},{key:"exportSVG",value:function(){let n=null,C=null;WA(Xr(I.prototype),"exportSVG",this)?[C,n]=WA(Xr(I.prototype),"exportSVG",this).call(this):(C=document.createElement("g"),n=C);const r=document.createElement("g");r.setAttribute("transform",`translate(${this.position[0]},${this.position[1]})`),n.appendChild(r);const o=document.createElement("g"),A=document.createElement("g");r.appendChild(o),r.appendChild(A);for(const s of this.visibleAndFetchedTiles())s.tileData.length&&s.tileData.forEach(a=>{const l=+s.tileId.split(".")[0],c=document.createElement("g");if(c.setAttribute("transform",`translate(${s.rectGraphics.position.x},${s.rectGraphics.position.y})scale(${s.rectGraphics.scale.x},${s.rectGraphics.scale.y})`),o.appendChild(c),this.drawnRects[l]&&a.uid in this.drawnRects[l]){const u=this.drawnRects[l][a.uid][0],d=document.createElement("path");let h=`M ${u[0]} ${u[1]}`;for(let b=2;b{const r=this.valueScaleTransform,{y:o,k:A}=r,s=this.dimensions[1];o+n/A>-(A-1)*s&&o+n/A<0&&(this.valueScaleTransform=r.translate(0,n/A)),C.rectGraphics.position.y=this.valueScaleTransform.y,this.vertY=this.valueScaleTransform.y}),this.animate()}},{key:"zoomedY",value:function(n,C){const r=Bd.zoomedY(n,C,this.valueScaleTransform,this.dimensions[1]);this.valueScaleTransform=r;let o=r.k;const A=r.y;let s=!1;o/=this.prevK,(o>1.5||o<1/1.5)&&(this.prevK*=o,o=1,s=!0),this.vertK=o,this.vertY=A,Object.values(this.fetchedTiles).forEach(a=>{s&&this.renderTile(a),a.rectGraphics.scale.y=o,a.rectGraphics.position.y=A}),this.draw(),this.animate()}},{key:"getMouseOverHtml",value:function(n,C){if(!this.tilesetInfo)return"";const r=this.calculateZoomLevel(),o=[n,C];if(this.drawnRects[r]){const A=Object.values(this.drawnRects[r]);for(let s=0;s"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function JA(e){return JA=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},JA(e)}const BNt=(e,g,I,i,n)=>{n.drawRect(e,g,I,i)},SNt=(e,g,I,i,n,{fill:C=0,fillOpacity:r=0,stroke:o=0,strokeWidth:A=0,strokeOpacity:s=0}={})=>{const a=document.createElement("rect");a.setAttribute("x",e),a.setAttribute("y",g),a.setAttribute("width",I),a.setAttribute("height",i),a.setAttribute("fill",`#${Z3(C)}`),a.setAttribute("fill-opacity",r),a.setAttribute("stroke",`#${Z3(o)}`),a.setAttribute("stroke-opacity",s),a.setAttribute("stroke-width",A),n.appendChild(a)},wA=(e,g,I,i,n,C)=>{n instanceof HTMLElement?SNt(e,g,I,i,n,C):BNt(e,g,I,i,n)},Rre=(e,g,I,i,n,C,r,o,{isVertical:A=!1,svg:s=null}={})=>{let a=g,l=I,c=i,u=n;const d=o.width*2>i?i/2:o.width,h=o.width*2>n?n/2:o.width,m=s||e,f={fill:0,fillOpacity:0,stroke:0,strokeOpacity:0,strokeWidth:1};if(o.positions&&o.positions.length?(e.lineStyle(1,0,0),e.beginFill(o.color,o.opacity),f.fill=o.color,f.fillOpacity=o.opacity,f.stroke=0,f.strokeOpacity=0,f.strokeWidth=1,o.positions.forEach(b=>{b==="top"&&!A||b==="left"&&A?wA(g-d,I-h,i+d*2,h,m,f):b==="bottom"&&!A||b==="right"&&A?wA(g-d,I+n,i+d*2,h,m,f):b==="left"&&!A||b==="top"&&A?wA(g-d,I-h,d,n+h*2,m,f):(b==="right"&&!A||b==="bottom"&&A)&&wA(g+i,I-h,d,n+h*2,m,f)})):o.width>0&&o.opacity>0&&(e.lineStyle(o.width,o.color,o.opacity),e.beginFill(0,0),f.fill=0,f.fillOpacity=0,f.stroke=o.color,f.strokeOpacity=o.opacity,f.strokeWidth=o.width,wA(g-d,I-h,i+d*2,n+h*2,m,f)),r.positions&&r.positions.length){e.lineStyle(1,0,0),e.beginFill(r.color,r.opacity);const b=r.width*2>i?i/2:r.width,p=r.width*2>n?n/2:r.width;f.fill=r.color,f.fillOpacity=r.opacity,f.stroke=0,f.strokeOpacity=0,f.strokeWidth=1,r.positions.forEach(y=>{y==="top"&&!A||y==="left"&&A?(wA(g,I,i,p,m,f),l+=p,u-=p):y==="bottom"&&!A||y==="right"&&A?(wA(g,I+n-p,i,p,m,f),u-=p):y==="left"&&!A||y==="top"&&A?(wA(g,I,b,n,m,f),a+=b,c-=b):(y==="right"&&!A||y==="bottom"&&A)&&(wA(g+i-b,I,b,n,m,f),c-=b)})}else e.lineStyle(r.width,r.color,r.opacity),f.stroke=r.color,f.strokeOpacity=r.opacity,f.strokeWidth=r.width;e.beginFill(C.color,C.opacity),f.fill=C.color,f.fillOpacity=C.opacity,wA(a,l,c,u,m,f)};let pRe=function(e){bNt(I,e);var g=yNt(I);function I(i,n){var C;return dNt(this,I),C=g.call(this,i,n),C.options=n||{},C.drawnRects={},C}return hNt(I,[{key:"drawHorizontalOverlay",value:function(n,C,r,o=0,A,s,a,l){if(!r||r.length<2)return;let c=this.position[0]+C.left+this._xScale(r[0]);const u=this.position[1]+C.top,d=C.height;let h=this._xScale(r[1])-this._xScale(r[0]);h=4?r[2]:r[0]);const d=this.position[1]+C.top,h=this.position[1]+C.top+C.height;if(u>h)return;u=4?r[3]:r[1])-u+C.top+this.position[1];f<0||(u+f>h&&(f+=h-(u+f)),f{(l.orientation==="1d-horizontal"||l.orientation==="2d")&&this.options.extent.forEach(c=>this.drawHorizontalOverlay(C,l.position,c,s,r,o,A,n)),(l.orientation==="1d-vertical"||l.orientation==="2d")&&this.options.extent.forEach(c=>this.drawVerticalOverlay(C,l.position,c,a,r,o,A,n))})}},{key:"zoomed",value:function(n,C){this.xScale(n),this.yScale(C),this.draw()}},{key:"setPosition",value:function(n){Ol(JA(I.prototype),"setPosition",this).call(this,n),this.draw()}},{key:"setDimensions",value:function(n){Ol(JA(I.prototype),"setDimensions",this).call(this,n),this.draw()}},{key:"exportSVG",value:function(){let n=null,C=null;Ol(JA(I.prototype),"exportSVG",this)?[C,n]=Ol(JA(I.prototype),"exportSVG",this).call(this):(C=document.createElement("g"),n=C);const r=document.createElement("g");return n.appendChild(r),this.draw({svg:r}),[C,n]}}]),I}(lC);function wNt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function Wre(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function LC(e){return LC=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},LC(e)}let L0=function(e){HNt(I,e);var g=TNt(I);function I(){return wNt(this,I),g.apply(this,arguments)}return VNt(I,[{key:"stopHover",value:function(){this.pMouseOver.clear(),this.animate()}},{key:"getMouseOverHtml",value:function(n){if(!this.tilesetInfo||!this.options.showTooltip||!this.valueScale)return"";const C=this.getDataAtPos(n);let r="";C&&(r=Ar(".3f")(C));const o=this.pMouseOver,A=0,s=this.valueScale(C);o.clear(),o.beginFill(A,.5),o.lineStyle(1,A,1);const a=4;return o.drawRect(n-a/2,s-a/2,a,a),this.animate(),`${r}`}},{key:"initTile",value:function(n){if(Yo(LC(I.prototype),"initTile",this).call(this,n),!n.tileData||!n.tileData.dense){console.warn("emptyTile:",n);return}if(n.xValues=new Array(n.tileData.dense.length),n.yValues=new Array(n.tileData.dense.length),this.isValueScaleLocked()){const C=this.getLockGroupExtrema();C!==null&&(this.minValue(C[0]),this.maxValue(C[1]))}this.drawTile(n)}},{key:"rerender",value:function(n,C){Yo(LC(I.prototype),"rerender",this).call(this,n,C),this.options=n,Yo(LC(I.prototype),"draw",this).call(this),this.visibleAndFetchedTiles().forEach(r=>{this.renderTile(r)})}},{key:"renderTile",value:function(n){this.drawTile(n),this.drawAxis(this.valueScale)}},{key:"drawTile",value:function(n){if(Yo(LC(I.prototype),"drawTile",this).call(this,n),!n.graphics||!n.tileData||!n.tileData.dense)return;const C=n.graphics,{tileX:r,tileWidth:o}=this.getTilePosAndDimensions(n.tileData.zoomLevel,n.tileData.tilePos),A=n.tileData.dense;if(A.length===0)return;const[s,a]=this.makeValueScale(this.minValue(),this.medianVisibleValue,this.maxValue());if(this.valueScale=s,C.clear(),this.drawAxis(this.valueScale),this.options.valueScaling==="log"&&this.valueScale.domain()[1]<0){console.warn("Negative values present when using a log scale",this.valueScale.domain());return}const l=Kt(this.options.lineStrokeColor?this.options.lineStrokeColor:"blue");!this.tilesetInfo.tile_size&&!this.tilesetInfo.bins_per_dimension&&console.warn("No tileset_info.tile_size or tileset_info.bins_per_dimension",this.tilesetInfo);const c=this.tilesetInfo.tile_size||this.tilesetInfo.bins_per_dimension,u=qt().domain([0,c]).range([r,r+o]),d=this.options.lineStrokeWidth?this.options.lineStrokeWidth:1;C.lineStyle(d,l,1),n.segments=[];let h=[];for(let m=0;m1&&n.segments.push(h),h=[];continue}if(u(m)>this.tilesetInfo.max_pos[0])break;h.push([f,b])}h.length>1&&n.segments.push(h);for(const m of n.segments){const f=m[0],b=m.slice(1);C.moveTo(f[0],f[1]);for(const p of b)C.lineTo(p[0],p[1])}}},{key:"setPosition",value:function(n){Yo(LC(I.prototype),"setPosition",this).call(this,n),this.pMain.position.y=this.position[1],this.pMain.position.x=this.position[0],this.pMouseOver.position.y=this.position[1],this.pMouseOver.position.x=this.position[0]}},{key:"zoomed",value:function(n,C){this.xScale(n),this.yScale(C),this.refreshTiles(),this.draw();const r=this.isValueScaleLocked();if(this.continuousScaling&&this.minValue()!==void 0&&this.maxValue()!==void 0){if(this.valueScaleMin===null&&this.valueScaleMax===null&&!r){const o=this.minVisibleValue(),A=this.maxVisibleValue(),s=1e-6;o!==null&&A!==null&&(Math.abs(this.minValue()-o)>s||Math.abs(this.maxValue()-A)>s)&&(this.minValue(o),this.maxValue(A),this.scheduleRerender())}r&&this.onValueScaleChanged()}}},{key:"superSVG",value:function(){return Yo(LC(I.prototype),"exportSVG",this).call(this)}},{key:"exportSVG",value:function(){let n=null,C=null;Yo(LC(I.prototype),"exportSVG",this)?[C,n]=Yo(LC(I.prototype),"exportSVG",this).call(this):(C=document.createElement("g"),n=C),C.setAttribute("class","exported-line-track");const r=document.createElement("g");n.appendChild(r),r.setAttribute("transform",`translate(${this.position[0]},${this.position[1]})`);const o=this.options.lineStrokeColor?this.options.lineStrokeColor:"blue";this.visibleAndFetchedTiles().forEach(s=>{const a=document.createElement("path");a.setAttribute("fill","transparent"),a.setAttribute("stroke",o);let l="";for(const c of s.segments){const u=c[0],d=c.slice(1);l+=`M${u[0]} ${u[1]}`;for(const h of d)l+=`L${h[0]} ${h[1]}`}a.setAttribute("d",l),r.appendChild(a)});const A=document.createElement("g");if(A.setAttribute("id","axis"),C.appendChild(A),A.setAttribute("transform",`translate(${this.axis.pAxis.position.x}, ${this.axis.pAxis.position.y})`),this.options.axisPositionHorizontal==="left"||this.options.axisPositionVertical==="top"){const s=this.axis.exportAxisLeftSVG(this.valueScale,this.dimensions[1]);A.appendChild(s)}else if(this.options.axisPositionHorizontal==="right"||this.options.axisPositionVertical==="bottom"){const s=this.axis.exportAxisRightSVG(this.valueScale,this.dimensions[1]);A.appendChild(s)}return[C,n]}},{key:"tileToLocalId",value:function(n){return this.options.aggregationMode&&this.options.aggregationMode!=="mean"?`${n.join(".")}.${this.options.aggregationMode}`:`${n.join(".")}`}},{key:"tileToRemoteId",value:function(n){return this.tileToLocalId(n)}}]),I}(O0);function KNt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function Xre(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function cs(e){return cs=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},cs(e)}let bRe=function(e){MNt(I,e);var g=zNt(I);function I(){return KNt(this,I),g.apply(this,arguments)}return DNt(I,[{key:"initTile",value:function(n){n.barXValues=new Array(n.tileData.dense.length),n.barYValues=new Array(n.tileData.dense.length),n.barWidths=new Array(n.tileData.dense.length),n.barHeights=new Array(n.tileData.dense.length),nd(cs(I.prototype),"initTile",this).call(this,n)}},{key:"drawTile",value:function(n){if(!n.graphics||!n.tileData||!n.tileData.dense)return;const C=n.graphics,{tileX:r,tileWidth:o}=this.getTilePosAndDimensions(n.tileData.zoomLevel,n.tileData.tilePos),A=n.tileData.dense;if(A.length===0)return;let s=0;if(this.valueScale=null,this.options.valueScaling==="log"){let h=this.medianVisibleValue;this.medianVisibleValue||(h=this.minValue()),this.valueScale=Qc().domain([h,this.maxValue()+h]).range([this.dimensions[1],0]),s=h}else this.valueScale=qt().domain([this.minValue(),this.maxValue()]).range([this.dimensions[1],0]);if(C.clear(),this.drawAxis(this.valueScale),this.options.valueScaling==="log"&&this.valueScale.domain()[1]<0){console.warn("Negative values present when using a log scale",this.valueScale.domain());return}const a=Kt(this.options.lineStrokeColor?this.options.lineStrokeColor:"blue"),l=qt().domain([0,this.tilesetInfo.tile_size]).range([r,r+o]),c=0;C.lineStyle(c,a,1);const u=this.options.pointSize?this.options.pointSize:3,d=Kt(this.options.pointColor?this.options.pointColor:"red");C.beginFill(d,1),n.drawnAtScale=this._xScale.copy();for(let h=0;hthis.tilesetInfo.max_pos[0])break;C.drawRect(m-u/2/this.pMain.scale.x,f-u/2/this.pMain.scale.y,u/this.pMain.scale.x,u/this.pMain.scale.y)}}},{key:"draw",value:function(){nd(cs(I.prototype),"draw",this).call(this);for(const n of xg(this.fetchedTiles)){const C=(n.drawnAtScale.domain()[1]-n.drawnAtScale.domain()[0])/(this._xScale.domain()[1]-this._xScale.domain()[0]),o=this._xScale.domain().map(n.drawnAtScale)[0];n.graphics.scale.x=C,n.graphics.position.x=-o*C}}},{key:"zoomed",value:function(n,C,r,o,A){nd(cs(I.prototype),"zoomed",this).call(this,n,C)}},{key:"exportSVG",value:function(){let n=null,C=null;[C,n]=nd(cs(I.prototype),"superSVG",this).call(this),C.setAttribute("class","exported-line-track");const r=document.createElement("g");n.appendChild(r),r.setAttribute("transform",`translate(${this.position[0]},${this.position[1]})`);for(const A of this.visibleAndFetchedTiles())for(let s=0;s{g+=+i||0,I.push(g)}),Float64Array.from(I)}const LNt=(e,g)=>{const I=fB(e,g);return _Nt(e.map(i=>(Array.isArray(i)&&g?i.length:1)/I))};function UNt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function Hre(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function dh(e){return dh=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},dh(e)}let yRe=function(e){ekt(I,e);var g=tkt(I);function I(i,n){var C;return UNt(this,I),C=g.call(this,i,n),C.pMain=C.pMobile,C.continuousScaling=!1,C.updateDataFetcher(n),C}return QNt(I,[{key:"updateDataFetcher",value:function(n){if(n&&n.selectRows&&n.selectRowsAggregationMethod==="server"){const{pubSub:C,dataFetcher:r}=this,o=r.dataConfig.options,A={aggGroups:n.selectRows,aggFunc:n.selectRowsAggregationMode};if(JSON.stringify(o)!==JSON.stringify(A)){const s={...r.dataConfig,options:A};this.dataFetcher=new r.constructor(s,C),this.dataFetcher.dataConfig.tilesetUid&&this.fetchNewTiles(Object.keys(this.fetchedTiles).map(a=>({tileId:a,remoteId:a})))}}}},{key:"rerender",value:function(n,C){this.updateDataFetcher(n),iv(dh(I.prototype),"rerender",this).call(this,n,C),n.selectRows&&(this.selectRowsCumWeights=LNt(n.selectRows,n.selectRowsAggregationWithRelativeHeight))}},{key:"tileDataToCanvas",value:function(n){const C=document.createElement("canvas");this.options.selectRows&&this.tilesetInfo.shape?(C.width=this.tilesetInfo.shape[0],C.height=fB(this.options.selectRows,this.options.selectRowsAggregationWithRelativeHeight)):this.tilesetInfo.shape?(C.width=this.tilesetInfo.shape[0],C.height=this.tilesetInfo.shape[1]):(C.width=this.tilesetInfo.tile_size,C.height=1);const r=C.getContext("2d");if(r.fillStyle="transparent",r.fillRect(0,0,C.width,C.height),n.length!==0&&n.length===4*C.width*C.height){const o=new ImageData(n,C.width,C.height);r.putImageData(o,0,0)}else console.warn("HorizontalMultivecTrack: pixData has an incorrect length.");return C}},{key:"setSpriteProperties",value:function(n,C,r){const{tileX:o,tileWidth:A}=this.getTilePosAndDimensions(C,r,this.tilesetInfo.tile_size),s=o+A;n.width=this._refXScale(s)-this._refXScale(o),n.height=this.dimensions[1],n.x=this._refXScale(o),n.y=0}},{key:"leftTrackZoomed",value:function(n,C,r,o,A){const s=this._xScale(0)-r*this._refXScale(0);this.pMobile.position.x=s+this.position[0],this.pMobile.position.y=this.position[1],this.pMobile.scale.x=r,this.pMobile.scale.y=1}},{key:"zoomed",value:function(n,C,r,o){iv(dh(I.prototype),"zoomed",this).call(this,n,C),this.pMain.position.x=o,this.pMain.position.y=this.position[1],this.pMain.scale.x=r,this.pMain.scale.y=1,this.drawColorbar()}},{key:"calculateVisibleTiles",value:function(){if(!this.tilesetInfo)return;if(this.zoomLevel=this.calculateZoomLevel(),this.tilesetInfo.resolutions){const C=this.tilesetInfo.resolutions.map(r=>+r).sort((r,o)=>o-r);this.xTiles=Gt.calculateTilesFromResolution(C[this.zoomLevel],this._xScale,this.tilesetInfo.min_pos[0],null,this.tilesetInfo.tile_size)}else this.xTiles=Gt.calculateTiles(this.zoomLevel,this._xScale,this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0],this.tilesetInfo.max_zoom,this.tilesetInfo.max_width);const n=this.xTiles.map(C=>[this.zoomLevel,C]);this.setVisibleTiles(n)}},{key:"calculateZoomLevel",value:function(){if(!this.tilesetInfo)return;const n=this.tilesetInfo.min_pos[0];let C=null;return this.tilesetInfo.resolutions?C=Gt.calculateZoomLevelFromResolutions(this.tilesetInfo.resolutions,this._xScale,n):C=Gt.calculateZoomLevel(this._xScale,this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0]),C}},{key:"tileToLocalId",value:function(n){return n.join(".")}},{key:"tileToRemoteId",value:function(n){return n.join(".")}},{key:"getTilePosAtPosition",value:function(n,C){if(!this.tilesetInfo)return;const r=this.calculateZoomLevel(),o=Gt.calculateTileWidth(this.tilesetInfo,r,this.tilesetInfo.tile_size),A=this._xScale.invert(n)/o;return[r,Math.floor(A)]}},{key:"getVisibleData",value:function(n,C){const r=this.calculateZoomLevel(),o=Gt.calculateTileWidth(this.tilesetInfo,r,this.tilesetInfo.tile_size),A=this._xScale.invert(n)/o;let s=this.tilesetInfo.shape?this.tilesetInfo.shape[1]:1;this.options.selectRows&&(s=fB(this.options.selectRows,this.options.selectRowsAggregationWithRelativeHeight));let a=this.tilesetInfo.tile_size*(A-Math.floor(A));const l=C/this.dimensions[1],c=l*s;let u=Math.floor(c),d;this.options.selectRows&&(this.options.selectRowsAggregationWithRelativeHeight&&(u=this.selectRowsCumWeights.findIndex((b,p)=>l<=b&&(p===this.selectRowsCumWeights.length-1||this.selectRowsCumWeights[p+1]>=l))),d=this.options.selectRows[u]);const h=this.tileToLocalId([r,Math.floor(A)]),m=this.fetchedTiles[h];let f="";if(m){this.tilesetInfo.shape||(a=m.tileData.dense.length*(A-Math.floor(A)));let b=null;if(this.tilesetInfo.shape?Array.isArray(d)&&this.options.selectRowsAggregationMethod==="client"?b=d.map(p=>this.tilesetInfo.shape[0]*p+Math.floor(a)):d&&this.options.selectRowsAggregationMethod==="client"?b=this.tilesetInfo.shape[0]*d+Math.floor(a):b=this.tilesetInfo.shape[0]*u+Math.floor(a):b=m.tileData.dense.length*u+Math.floor(a),Array.isArray(b)){const p=eQ(this.options.selectRowsAggregationMode),y=b.map(Z=>m.tileData.dense[Z]);f=Ar(".3f")(p(y)),f+="
",f+=`${b.length}-item ${this.options.selectRowsAggregationMode}`}else f=Ar(".3f")(m.tileData.dense[b]),Array.isArray(d)&&(f+="
",f+=`${d.length}-item ${this.options.selectRowsAggregationMode}`)}if(this.tilesetInfo.row_infos){f+="
";let b="";this.options.selectRows&&!Array.isArray(d)?b=this.tilesetInfo.row_infos[d]:u>=0&&u"),a=this.options.colorRange[parseInt(s[0],10)-1],l=s[1];if(Number.isNaN(a)||a==="NaN"||typeof a>"u"||a==="undefined")return"";o=` ${l}`}else o+=`Data value: ${this.getVisibleData(n,C)}
`,o+=`Zoom level: ${r[0]} tile position: ${r[1]}`;return o}}]),I}(QS);function nkt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function Tre(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function Mo(e){return Mo=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},Mo(e)}const dkt=Kt("#FFFFFF");let vj=function(e){akt(I,e);var g=skt(I);function I(...i){var n;return nkt(this,I),n=g.call(this,...i),n.zeroLine=new rt.PIXI.Graphics,n.pMain.addChild(n.zeroLine),n.valueScaleTransform=Fi,n.options&&n.options.colorRange&&(n.options.colorRangeGradient?n.setColorGradient(n.options.colorRange):n.setColorScale(n.options.colorRange)),n.initialized=!0,n}return Ckt(I,[{key:"setColorScale",value:function(n){n&&(this.colorScale=Dc(n),this.colorScale=this.colorScale.map(C=>C.map(r=>r/255)))}},{key:"setColorGradient",value:function(n){if(!n)return;const C=n.length-1;this.colorGradientColors=this.options.align==="bottom"?n.slice().reverse().map((r,o)=>({from:o/C,color:r})):n.map((r,o)=>({from:o/C,color:r}))}},{key:"initTile",value:function(n){this.initialized&&$a(Mo(I.prototype),"initTile",this).call(this,n)}},{key:"updateTile",value:function(n){(!n.valueScale||!this.scale||this.scale.minValue!==n.scale.minValue||this.scale.maxValue!==n.scale.maxValue)&&this.renderTile(n)}},{key:"renderTile",value:function(n){this.initialized&&$a(Mo(I.prototype),"renderTile",this).call(this,n)}},{key:"drawTile",value:function(n){if(!n.graphics||!n.tileData||!n.tileData.dense)return;const{graphics:C}=n;n.svgData=void 0;const{tileX:r,tileWidth:o}=this.getTilePosAndDimensions(n.tileData.zoomLevel,n.tileData.tilePos,this.tilesetInfo.bins_per_dimension||this.tilesetInfo.tile_size),A=n.tileData.dense;if(A.length===0)return;const[s,a]=this.makeValueScale(this.minValue(),this.medianVisibleValue,this.maxValue(),0);s.clamp(!0),this.valueScale=s;const l=s.copy();if(l.range([254,0]).clamp(!0),C.clear(),this.drawAxis(this.valueScale),this.options.valueScaling==="log"&&this.valueScale.domain()[1]<0){console.warn("Negative values present when using a log scale",this.valueScale.domain());return}const c=Kt(this.options.lineStrokeColor||"blue"),u=qt().domain([0,this.tilesetInfo.tile_size||this.tilesetInfo.bins_per_dimension]).range([r,r+o]),d=0;C.lineStyle(d,c,1);const h=this.options.barFillColor||"grey",m=Kt(h),f="barOpacity"in this.options?this.options.barOpacity:1;C.beginFill(m,f),n.drawnAtScale=this._xScale.copy();const b=this.options.align==="top";let p,y,Z,B,G,v;if(this.colorGradientColors){G=new rt.PIXI.Graphics,G.beginFill(dkt,1);const w=DZe(this.colorGradientColors,1,this.dimensions[1],0,0,0,this.dimensions[1]);v=new rt.PIXI.Sprite(rt.PIXI.Texture.fromCanvas(w,rt.PIXI.SCALE_MODES.NEAREST)),v.x=this._xScale(r),v.width=this._xScale(r+o)-v.x}for(let w=0;wthis.tilesetInfo.max_pos[0])break;if(this.colorScale&&!this.options.colorRangeGradient){const V=Math.round(l(A[w]+a)),S=this.colorScale[V],X=rt.PIXI.utils.rgb2hex(S);C.beginFill(X,f)}(G||C).drawRect(p,Z,y,B)}this.colorGradientColors&&(v.mask=G,C.removeChildren(),C.addChild(v,G))}},{key:"rerender",value:function(n,C){n&&n.colorRange&&(n.colorRangeGradient?this.setColorGradient(n.colorRange):this.setColorScale(n.colorRange)),$a(Mo(I.prototype),"rerender",this).call(this,n,C)}},{key:"drawZeroLine",value:function(){this.zeroLine.clear();const n=Kt(this.options.barFillColor||"grey"),C=+this.options.barOpacity||1,r=this.options.zeroLineColor?Kt(this.options.zeroLineColor):n,o=Number.isNaN(+this.options.zeroLineOpacity)?C:+this.options.zeroLineOpacity;this.zeroLine.beginFill(r,o),this.zeroLine.drawRect(0,this.dimensions[1]-1,this.dimensions[0],1)}},{key:"drawZeroLineSvg",value:function(n){const C=document.createElement("rect");C.setAttribute("id","zero-line"),C.setAttribute("x",0),C.setAttribute("y",this.dimensions[1]-1),C.setAttribute("height",1),C.setAttribute("width",this.dimensions[0]),C.setAttribute("fill",this.options.zeroLineColor||this.options.barFillColor),C.setAttribute("fill-opacity",this.options.zeroLineOpacity||this.options.barOpacity),n.appendChild(C)}},{key:"getXScaleAndOffset",value:function(n){const C=n.domain(),r=this._xScale.domain(),o=(C[1]-C[0])/(r[1]-r[0]),s=this._xScale.domain().map(n)[0];return[o,-s*o]}},{key:"draw",value:function(){this.initialized&&($a(Mo(I.prototype),"draw",this).call(this),this.options.zeroLineVisible?this.drawZeroLine():this.zeroLine.clear(),Object.values(this.fetchedTiles).forEach(n=>{const[C,r]=this.getXScaleAndOffset(n.drawnAtScale);n.graphics.scale.x=C,n.graphics.position.x=r}))}},{key:"zoomed",value:function(n,C){$a(Mo(I.prototype),"zoomed",this).call(this,n,C)}},{key:"movedY",value:function(n){}},{key:"zoomedY",value:function(n,C){}},{key:"addSVGInfo",value:function(n,C,r,o,A,s){n.svgData?(n.svgData.barXValues.push(C),n.svgData.barYValues.push(r),n.svgData.barWidths.push(o),n.svgData.barHeights.push(A),n.svgData.barColors.push(s)):n.svgData={barXValues:[C],barYValues:[r],barWidths:[o],barHeights:[A],barColors:[s]}}},{key:"exportSVG",value:function(){let n=null,C=null;[C,n]=$a(Mo(I.prototype),"superSVG",this).call(this),C.setAttribute("class","exported-line-track");const r=document.createElement("g");n.appendChild(r),r.setAttribute("transform",`translate(${this.position[0]},${this.position[1]})`),this.options.zeroLine&&this.drawZeroLineSvg(r),this.visibleAndFetchedTiles().filter(A=>A.svgData&&A.svgData.barXValues).forEach(A=>{const s=A.svgData;for(let a=0;a"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function k9(e){return k9=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},k9(e)}let ZRe=function(e){bkt(I,e);var g=ykt(I);function I(){return hkt(this,I),g.apply(this,arguments)}return mkt(I,[{key:"drawTile",value:function(n){this.renderTile(n)}},{key:"renderTile",value:function(n){if(!n.graphics)return;const C=n.graphics,{tileX:r,tileWidth:o}=this.getTilePosAndDimensions(n.tileData.zoomLevel,n.tileData.tilePos,this.tilesetInfo.tile_size||this.tilesetInfo.bins_per_dimension),A=n.tileData.dense;if(A.length===0)return;let s=0;if(this.valueScale=null,this.options.valueScaling==="log"){let p=this.medianVisibleValue;this.medianVisibleValue||(p=this.minValue()),this.valueScale=Qc().domain([p,this.maxValue()+p]).range([this.dimensions[1],0]),s=p}else this.valueScale=qt().domain([this.minValue(),this.maxValue()]).range([this.dimensions[1],0]);if(C.clear(),this.drawAxis(this.valueScale),this.options.valueScaling==="log"&&this.valueScale.domain()[1]<0){console.warn("Negative values present when using a log scale",this.valueScale.domain());return}const a=Kt(this.options.lineStrokeColor?this.options.lineStrokeColor:"blue"),l=qt().domain([0,this.tilesetInfo.tile_size]).range([r,r+o]),c=0;C.lineStyle(c,a,1);const u=this.options.barFillColorTop?this.options.barFillColorTop:"green",d=this.options.barFillColorBottom?this.options.barFillColorBottom:"red",h=Kt(u),m=Kt(d),f="barOpacity"in this.options?this.options.barOpacity:1;n.drawnAtScale=this._xScale.copy();let b=0;this.options.valueScaling==="log"?b=this.valueScale(1):b=this.valueScale(0),delete n.svgData;for(let p=0;pb?(C.beginFill(m,f),this.addSVGInfo(n,y,b,B,Z-b,d)):(C.beginFill(h,f),this.addSVGInfo(n,y,Z,B,b-Z,u)),l(p)>this.tilesetInfo.max_pos[0])break;C.drawRect(y,n.svgData.barYValues[p],B,n.svgData.barHeights[p])}}}]),I}(vj);function Bkt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function kre(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function _b(e){return _b=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},_b(e)}let GRe=function(e){Wkt(I,e);var g=Xkt(I);function I(i,n){var C;return Bkt(this,I),C=g.call(this,i,n),C.setColorScale(n.colorRange),C.opacity=n.opacity||1,C}return Skt(I,[{key:"setColorScale",value:function(n){this.colorScale=n?Dc(n):Gb,this.colorScale=this.colorScale.map(C=>C.map(r=>r/255))}},{key:"rerender",value:function(n){n&&n.colorRange&&this.setColorScale(n.colorRange),this.opacity=n.opacity||1,Q1(_b(I.prototype),"rerender",this).call(this,n)}},{key:"drawAxis",value:function(){}},{key:"drawTile",value:function(n){if(!n.graphics||!n.tileData||!n.tileData.dense)return;const C=n.graphics,{tileX:r,tileWidth:o}=this.getTilePosAndDimensions(n.tileData.zoomLevel,n.tileData.tilePos),A=n.tileData.dense;if(A.length===0)return;const[s,a]=this.makeValueScale(this.minValue(),this.medianVisibleValue,this.maxValue());if(s.range([254,0]).clamp(!0),this.valueScale=s,C.clear(),this.options.valueScaling==="log"&&this.valueScale.domain()[1]<0){console.warn("Negative values present when using a log scale",this.valueScale.domain());return}const l=qt().domain([0,this.tilesetInfo.tile_size]).range([r,r+o]);C.lineStyle(0,0,0);for(let c=0;cthis.tilesetInfo.max_pos[0])break;A[c]!==0&&C.drawRect(d,0,h,m)}}}}]),I}(L0);function kkt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function Yre(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function Y9(e){return Y9=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},Y9(e)}let vRe=function(e){xkt(I,e);var g=Fkt(I);function I(i,n){var C;return kkt(this,I),C=g.call(this,i,n),C.seen=new Set,C.pMain=C.pMobile,C.rows=[],C}return Ykt(I,[{key:"uid",value:function(n){return n[n.length-2]}},{key:"segmentOverlap",value:function(n,C){}},{key:"drawAll",value:function(n){this.pMain.clear();const C=new Set,r=n.map(A=>C.has(this.uid(A))?null:(C.add(this.uid(A)),{from:+A[1],to:+A[2],type:A[4],uid:this.uid(A)})).filter(A=>A),o=n9(r);this.rows=o,this.draw()}},{key:"draw",value:function(){const n=this.rows;if(!n)return;const C=fS().range([0,this.dimensions[1]]).padding(.1).domain(eC(0,this.maxRows())),r=this.pMain;r.clear(),r.lineStyle(1,255,0),r.beginFill(16740363,.8);for(let o=0;othis.fetchedTiles[o].tileData.discrete),r=[].concat(...C);this.drawAll(r)}},{key:"initTile",value:function(n){}},{key:"maxRows",value:function(){return this.rows.length}},{key:"updateTile",value:function(n){}},{key:"destroyTile",value:function(n){n.tileData.discrete.forEach(C=>{const r=C[C.length-2];this.seen.has(r)&&this.seen.delete(r)})}},{key:"drawTile",value:function(n){}}]),I}(O0);function Pkt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function Kre(e,g){for(var I=0;I=this.position[0]&&I<=this.dimensions[0]+this.position[0]&&i>=this.position[1]&&i<=this.dimensions[1]+this.position[1]}}]),g}();function hNt(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function Boe(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function Qo(g){return Qo=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},Qo(g)}const voe=11,IF="Arial",Soe="outside",TP=10,SNt=4,wNt=20,VNt=zt("#ffffff"),zR=2,RNt=2*TP/3,af=2*RNt/3,WNt=50,XNt=5e3,NP="blue",kP="red",i4=(g,e,I)=>{I.type!=="filler"&&e.pubSub.publish("app.click",{type:"gene-annotation",event:g,payload:I})},woe=(g,e)=>{const I=g.concat(e),i=I.map(n=>[n.xStart,1,n.xEnd,1]);Ww(i,(n,C)=>{let r=null,o=null;if(I[n].type==="filler"?r=I[n]:o=I[n],I[C].type==="filler"){if(r)return;r=I[C]}else{if(!r)return;o=I[C]}r.xStart>=o.xStart&&r.xEnd<=o.xEnd&&(r.hide=!0)})};function HNt(g,e,I){const{flipText:i,fontSize:n,fontFamily:C,plusStrandColor:r,minusStrandColor:o,maxGeneEntries:A,maxFillerEntries:s,maxTexts:a}=I;if(e.texts={},e.rectGraphics=new Ct.PIXI.Graphics,e.textBgGraphics=new Ct.PIXI.Graphics,e.textGraphics=new Ct.PIXI.Graphics,e.rectMaskGraphics=new Ct.PIXI.Graphics,e.graphics.addChild(e.rectGraphics),e.graphics.addChild(e.textBgGraphics),e.graphics.addChild(e.textGraphics),e.graphics.addChild(e.rectMaskGraphics),e.rectGraphics.mask=e.rectMaskGraphics,!e.tileData.sort)return;e.tileData.sort((u,d)=>d.importance-u.importance);const l=e.tileData.filter(u=>u.type!=="filler").slice(0,A),c=e.tileData.filter(u=>u.type==="filler").slice(0,s);e.tileData=l.concat(c),e.tileData.forEach((u,d)=>{if(u.type==="filler")return;const h=u.fields,m=h[3],f=g.geneId(h,u.type),b=u.strand||h[5];u.strand=u.strand||b;let p=r||NP;if(b==="-"&&(p=o||kP),e.textWidths={},e.textHeights={},d>=a)return;const y=new Ct.PIXI.Text(m,{fontSize:`${n}px`,fontFamily:C,fill:zt(p)});y.interactive=!0,i&&(y.scale.x=-1),y.anchor.x=.5,y.anchor.y=1,e.texts[f]=y,e.texts[f].strand=b,e.textGraphics.addChild(y)}),e.initialized=!0}function Voe(g,e,I,i,n,C,r,o,A){const s=o-A/2,a=0;g.forEach(l=>{const c=new Ct.PIXI.Graphics;I.rectGraphics.addChild(c),c.beginFill(C,.1),c.lineStyle(0,C);const u=[n(l.xStart)-a,s,n(l.xEnd)+a,s,n(l.xEnd)+a,s+A,n(l.xStart)-a,s+A,n(l.xStart)-a,s];c.interactive=!0,c.buttonMode=!0,c.mouseup=d=>i4(d,e,l),c.drawPolygon(u),I.allRects.push([u,l.strand,l])})}function TNt(g,e,I,i,n,C,r,o,A,s){const a=o-A/2,l=n.split(",").map(y=>+y+r),c=C.split(",").map(y=>+y+r),u=g._xScale(I),d=g._xScale(i),h=d-u,m=o,f=[];let b=[u,m-zR/2,u+h,m-zR/2,u+h,m+zR/2,u,m+zR/2];e.drawPolygon(b),f.push(b);const p=2*A;for(let y=Math.max(g.position[0],u)+p;y{const l=e._xScale(a.xStart),c=e._xScale(a.xEnd),u=new Ct.PIXI.Graphics;I.rectGraphics.addChild(u),u.beginFill(C,r),u.interactive=!0,u.buttonMode=!0,u.mouseup=m=>i4(m,e,a);const d=e.geneRectHeight/2;let h=[];if(a.strand==="+"||a.fields[5]==="+"){const m=Math.max(l,c-d),f=m+d;h=[m,s,f,s+e.geneRectHeight/2,m,s+e.geneRectHeight]}else{const m=Math.min(c,l+d),f=m-d;h=[m,s,f,s+e.geneRectHeight/2,m,s+e.geneRectHeight]}u.drawPolygon(h),I.allRects.push([h,a.strand,a])})}function kNt(g,e,I,i,n,C,r,o,A){g.forEach(s=>{const a=s.fields,l=+s.chrOffset,c=a[12],u=a[13],d=new Ct.PIXI.Graphics;I.rectGraphics.addChild(d),d.beginFill(C,r),d.interactive=!0,d.buttonMode=!0,d.mouseup=h=>i4(h,e,s),I.allRects=I.allRects.concat(TNt(e,d,s.xStart,s.xEnd,c,u,l,o,A,s.strand||s.fields[5]).map(h=>[h,s.strand,s]))})}function Roe(g,e,I,i,n,C,r,o,A){NNt(g,e,I,i,n,C,r,o,A),kNt(g,e,I,i,n,C,r,o,A)}function YNt(g,e){const{tileX:I,tileWidth:i}=Pd.getTilePosAndDimensions(g.tilesetInfo,e.tileId);e.rectMaskGraphics.clear();const n=Math.floor(Math.random()*16**6);e.rectMaskGraphics.beginFill(n,.3);const C=g._xScale(I),r=0,o=g._xScale(I+i)-g._xScale(I),A=g.dimensions[1];e.rectMaskGraphics.drawRect(C,r,o,A)}let k1e=function(g){yNt(I,g);var e=ZNt(I);function I(i,n){var C;hNt(this,I),C=e.call(this,i,n);const{animate:r}=i;return C.animate=r,C.options=n,C.fontSize=+C.options.fontSize||voe,C.geneLabelPos=C.options.geneLabelPosition||Soe,C.geneRectHeight=+C.options.geneAnnotationHeight||TP,C.geneRectHeight-=2,C.geneStrandSpacing=+C.options.geneStrandSpacing||SNt,C.geneStrandHSpacing=C.geneStrandSpacing/2,C.geneRectHHeight=C.geneRectHeight/2,C}return mNt(I,[{key:"initTile",value:function(n){HNt(this,n,{flipText:this.flipText,fontSize:this.fontSize,fontFamily:IF,plusStrandColor:this.options.plusStrandColor,minusStrandColor:this.options.minusStrandColor,maxGeneEntries:WNt,maxFillerEntries:XNt,maxTexts:wNt}),this.renderTile(n)}},{key:"destroyTile",value:function(n){n.rectGraphics.destroy(),n.rectMaskGraphics.destroy(),n.textGraphics.destroy(),n.textBgGraphics.destroy(),n.graphics.destroy()}},{key:"rerender",value:function(n,C){const r=JSON.stringify(n);!C&&r===this.prevOptions||(ss(Qo(I.prototype),"rerender",this).call(this,n,C),this.fontSize=+this.options.fontSize||voe,this.geneLabelPos=this.options.geneLabelPosition||Soe,this.geneRectHeight=+this.options.geneAnnotationHeight||TP,this.geneStrandHSpacing=this.geneStrandSpacing/2,this.geneRectHHeight=this.geneRectHeight/2,this.prevOptions=r,this.visibleAndFetchedTiles().forEach(o=>{this.renderTile(o)}))}},{key:"drawTile",value:function(){}},{key:"geneId",value:function(n,C){return`${C}_${n[0]}_${n[1]}_${n[2]}_${n[3]}`}},{key:"renderTile",value:function(n){if(!n.initialized)return;n.allRects=[],n.drawnAtScale=this._xScale.copy(),n.rectGraphics.removeChildren(),n.rectGraphics.clear(),n.textBgGraphics.clear();const C={},r=.3,o=.3;C["+"]=zt(this.options.plusStrandColor||NP),C["-"]=zt(this.options.minusStrandColor||kP);let A=n.tileData.filter(f=>f.type==="filler"&&f.strand==="+"),s=n.tileData.filter(f=>f.type==="filler"&&f.strand==="-");const a=n.tileData.filter(f=>f.type!=="filler"&&(f.strand==="+"||f.fields[5]==="+")),l=n.tileData.filter(f=>f.type!=="filler"&&(f.strand==="-"||f.fields[5]==="-"));woe(a,A),woe(l,s),A=A.filter(f=>!f.hide),s=s.filter(f=>!f.hide);const c=this.dimensions[1]/2,u=c-this.geneRectHeight/2-this.geneStrandSpacing/2,d=c+this.geneRectHeight/2+this.geneStrandSpacing/2,h=[this,n,n.rectGraphics,this._xScale,C["+"],r,u,this.geneRectHeight],m=[this,n,n.rectGraphics,this._xScale,C["-"],r,d,this.geneRectHeight];Voe(A,...h),Voe(s,...m),h[5]=o,m[5]=o,Roe(a,...h),Roe(l,...m),YNt(this,n),Pd.stretchRects(this,[f=>f.rectGraphics,f=>f.rectMaskGraphics]);for(const f of Object.values(n.texts))f.style={fontSize:`${this.fontSize}px`,FONT_FAMILY:IF,fill:zt(f.strand==="-"?this.options.minusStrandColor||kP:this.options.plusStrandColor||NP)}}},{key:"calculateZoomLevel",value:function(){const n=vt.calculateZoomLevel(this._xScale,this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0]);let C=Math.min(n,this.maxZoom);return C=Math.max(C,0),C}},{key:"draw",value:function(){ss(Qo(I.prototype),"draw",this).call(this),this.allTexts=[],this.allBoxes=[];const n=[];this.geneAreaHeight=this.geneRectHeight;const C=this.fontSize/2;Pd.stretchRects(this,[r=>r.rectGraphics,r=>r.rectMaskGraphics]),Object.values(this.fetchedTiles).filter(r=>r.drawnAtScale).forEach(r=>{r.textBgGraphics.clear(),r.textBgGraphics.beginFill(typeof this.options.labelBackgroundColor<"u"?zt(this.options.labelBackgroundColor):VNt);const o=this.parentInFetched(r);r.initialized&&r.tileData.forEach(A=>{if(!r.texts||A.type==="filler")return;const s=A.fields,a=s[3],l=this.geneId(s,A.type),c=r.texts[l];if(!c)return;const u=+A.chrOffset,d=+s[1]+u,h=+s[2]+u,m=(d+h)/2;let f=this.dimensions[1]/2;const b=(this.geneAreaHeight-this.fontSize)/2;if(s[5]==="+"?f-=this.geneLabelPos==="inside"?b+this.geneStrandSpacing-2:this.fontSize/2+this.geneAreaHeight-2:f+=this.geneLabelPos==="inside"?this.fontSize+this.geneStrandSpacing/2+b+1:1.5*this.fontSize+this.geneAreaHeight+2,c.position.x=this._xScale(m),c.position.y=f,!r.textWidths[l]){const p=c.getBounds().width,y=c.getBounds().height;r.textHeights[l]=y,r.textWidths[l]=p}if(o)c.visible=!1;else{c.visible=!0;const p=2;this.flipText?this.allBoxes.push([c.position.x-r.textHeights[l]/2-p,f-C-1,c.position.x+r.textHeights[l]/2+p,f+C-1,a]):this.allBoxes.push([c.position.x-r.textWidths[l]/2-p,f-C-1,c.position.x+r.textWidths[l]/2+p,f+C-1,a]),this.allTexts.push({importance:+s[4],text:c,caption:a,strand:s[5]}),n.push(r.textBgGraphics)}})}),this.hideOverlaps(this.allBoxes,this.allTexts),this.renderTextBg(this.allBoxes,this.allTexts,n)}},{key:"renderTextBg",value:function(n,C,r){C.forEach((o,A)=>{if(o.text.visible&&n[A]&&r[A]){const[s,a,l,c]=n[A],u=l-s,d=c-a;r[A].drawRect(s-u/2,a-d/2,u,d)}})}},{key:"hideOverlaps",value:function(n,C){Ww(n,(r,o)=>{C[r].importance>C[o].importance?C[o].text.visible=!1:C[r].text.visible=!1})}},{key:"setPosition",value:function(n){ss(Qo(I.prototype),"setPosition",this).call(this,n),[this.pMain.position.x,this.pMain.position.y]=this.position}},{key:"setDimensions",value:function(n){ss(Qo(I.prototype),"setDimensions",this).call(this,n),this.halfRectHHeight=this.dimensions[1]/2,this.visibleAndFetchedTiles().forEach(C=>{this.renderTile(C)})}},{key:"zoomed",value:function(n,C){this.xScale(n),this.yScale(C),this.refreshTiles(),this.draw()}},{key:"getMouseOverHtml",value:function(n,C){if(!this.tilesetInfo)return"";const r=[n,C];for(const o of this.visibleAndFetchedTiles())for(let A=0;A=this.position[0]&&I<=this.dimensions[0]+this.position[0]&&i>=this.position[1]&&i<=this.dimensions[1]+this.position[1]}}]),e}();function Lkt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function xre(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function zo(e){return zo=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},zo(e)}const Fre=11,cx="Arial",Ere="outside",$z=10,iYt=4,nYt=20,CYt=Kt("#ffffff"),uR=2,rYt=2*$z/3,Om=2*rYt/3,oYt=50,AYt=5e3,qz="blue",eP="red",Bj=(e,g,I)=>{I.type!=="filler"&&g.pubSub.publish("app.click",{type:"gene-annotation",event:e,payload:I})},Mre=(e,g)=>{const I=e.concat(g),i=I.map(n=>[n.xStart,1,n.xEnd,1]);jS(i,(n,C)=>{let r=null,o=null;if(I[n].type==="filler"?r=I[n]:o=I[n],I[C].type==="filler"){if(r)return;r=I[C]}else{if(!r)return;o=I[C]}r.xStart>=o.xStart&&r.xEnd<=o.xEnd&&(r.hide=!0)})};function aYt(e,g,I){const{flipText:i,fontSize:n,fontFamily:C,plusStrandColor:r,minusStrandColor:o,maxGeneEntries:A,maxFillerEntries:s,maxTexts:a}=I;if(g.texts={},g.rectGraphics=new rt.PIXI.Graphics,g.textBgGraphics=new rt.PIXI.Graphics,g.textGraphics=new rt.PIXI.Graphics,g.rectMaskGraphics=new rt.PIXI.Graphics,g.graphics.addChild(g.rectGraphics),g.graphics.addChild(g.textBgGraphics),g.graphics.addChild(g.textGraphics),g.graphics.addChild(g.rectMaskGraphics),g.rectGraphics.mask=g.rectMaskGraphics,!g.tileData.sort)return;g.tileData.sort((u,d)=>d.importance-u.importance);const l=g.tileData.filter(u=>u.type!=="filler").slice(0,A),c=g.tileData.filter(u=>u.type==="filler").slice(0,s);g.tileData=l.concat(c),g.tileData.forEach((u,d)=>{if(u.type==="filler")return;const h=u.fields,m=h[3],f=e.geneId(h,u.type),b=u.strand||h[5];u.strand=u.strand||b;let p=r||qz;if(b==="-"&&(p=o||eP),g.textWidths={},g.textHeights={},d>=a)return;const y=new rt.PIXI.Text(m,{fontSize:`${n}px`,fontFamily:C,fill:Kt(p)});y.interactive=!0,i&&(y.scale.x=-1),y.anchor.x=.5,y.anchor.y=1,g.texts[f]=y,g.texts[f].strand=b,g.textGraphics.addChild(y)}),g.initialized=!0}function zre(e,g,I,i,n,C,r,o,A){const s=o-A/2,a=0;e.forEach(l=>{const c=new rt.PIXI.Graphics;I.rectGraphics.addChild(c),c.beginFill(C,.1),c.lineStyle(0,C);const u=[n(l.xStart)-a,s,n(l.xEnd)+a,s,n(l.xEnd)+a,s+A,n(l.xStart)-a,s+A,n(l.xStart)-a,s];c.interactive=!0,c.buttonMode=!0,c.mouseup=d=>Bj(d,g,l),c.drawPolygon(u),I.allRects.push([u,l.strand,l])})}function sYt(e,g,I,i,n,C,r,o,A,s){const a=o-A/2,l=n.split(",").map(y=>+y+r),c=C.split(",").map(y=>+y+r),u=e._xScale(I),d=e._xScale(i),h=d-u,m=o,f=[];let b=[u,m-uR/2,u+h,m-uR/2,u+h,m+uR/2,u,m+uR/2];g.drawPolygon(b),f.push(b);const p=2*A;for(let y=Math.max(e.position[0],u)+p;y{const l=g._xScale(a.xStart),c=g._xScale(a.xEnd),u=new rt.PIXI.Graphics;I.rectGraphics.addChild(u),u.beginFill(C,r),u.interactive=!0,u.buttonMode=!0,u.mouseup=m=>Bj(m,g,a);const d=g.geneRectHeight/2;let h=[];if(a.strand==="+"||a.fields[5]==="+"){const m=Math.max(l,c-d),f=m+d;h=[m,s,f,s+g.geneRectHeight/2,m,s+g.geneRectHeight]}else{const m=Math.min(c,l+d),f=m-d;h=[m,s,f,s+g.geneRectHeight/2,m,s+g.geneRectHeight]}u.drawPolygon(h),I.allRects.push([h,a.strand,a])})}function cYt(e,g,I,i,n,C,r,o,A){e.forEach(s=>{const a=s.fields,l=+s.chrOffset,c=a[12],u=a[13],d=new rt.PIXI.Graphics;I.rectGraphics.addChild(d),d.beginFill(C,r),d.interactive=!0,d.buttonMode=!0,d.mouseup=h=>Bj(h,g,s),I.allRects=I.allRects.concat(sYt(g,d,s.xStart,s.xEnd,c,u,l,o,A,s.strand||s.fields[5]).map(h=>[h,s.strand,s]))})}function Pre(e,g,I,i,n,C,r,o,A){lYt(e,g,I,i,n,C,r,o,A),cYt(e,g,I,i,n,C,r,o,A)}function uYt(e,g){const{tileX:I,tileWidth:i}=Bd.getTilePosAndDimensions(e.tilesetInfo,g.tileId);g.rectMaskGraphics.clear();const n=Math.floor(Math.random()*16**6);g.rectMaskGraphics.beginFill(n,.3);const C=e._xScale(I),r=0,o=e._xScale(I+i)-e._xScale(I),A=e.dimensions[1];g.rectMaskGraphics.drawRect(C,r,o,A)}let BRe=function(e){qkt(I,e);var g=eYt(I);function I(i,n){var C;Lkt(this,I),C=g.call(this,i,n);const{animate:r}=i;return C.animate=r,C.options=n,C.fontSize=+C.options.fontSize||Fre,C.geneLabelPos=C.options.geneLabelPosition||Ere,C.geneRectHeight=+C.options.geneAnnotationHeight||$z,C.geneRectHeight-=2,C.geneStrandSpacing=+C.options.geneStrandSpacing||iYt,C.geneStrandHSpacing=C.geneStrandSpacing/2,C.geneRectHHeight=C.geneRectHeight/2,C}return Ukt(I,[{key:"initTile",value:function(n){aYt(this,n,{flipText:this.flipText,fontSize:this.fontSize,fontFamily:cx,plusStrandColor:this.options.plusStrandColor,minusStrandColor:this.options.minusStrandColor,maxGeneEntries:oYt,maxFillerEntries:AYt,maxTexts:nYt}),this.renderTile(n)}},{key:"destroyTile",value:function(n){n.rectGraphics.destroy(),n.rectMaskGraphics.destroy(),n.textGraphics.destroy(),n.textBgGraphics.destroy(),n.graphics.destroy()}},{key:"rerender",value:function(n,C){const r=JSON.stringify(n);!C&&r===this.prevOptions||(qa(zo(I.prototype),"rerender",this).call(this,n,C),this.fontSize=+this.options.fontSize||Fre,this.geneLabelPos=this.options.geneLabelPosition||Ere,this.geneRectHeight=+this.options.geneAnnotationHeight||$z,this.geneStrandHSpacing=this.geneStrandSpacing/2,this.geneRectHHeight=this.geneRectHeight/2,this.prevOptions=r,this.visibleAndFetchedTiles().forEach(o=>{this.renderTile(o)}))}},{key:"drawTile",value:function(){}},{key:"geneId",value:function(n,C){return`${C}_${n[0]}_${n[1]}_${n[2]}_${n[3]}`}},{key:"renderTile",value:function(n){if(!n.initialized)return;n.allRects=[],n.drawnAtScale=this._xScale.copy(),n.rectGraphics.removeChildren(),n.rectGraphics.clear(),n.textBgGraphics.clear();const C={},r=.3,o=.3;C["+"]=Kt(this.options.plusStrandColor||qz),C["-"]=Kt(this.options.minusStrandColor||eP);let A=n.tileData.filter(f=>f.type==="filler"&&f.strand==="+"),s=n.tileData.filter(f=>f.type==="filler"&&f.strand==="-");const a=n.tileData.filter(f=>f.type!=="filler"&&(f.strand==="+"||f.fields[5]==="+")),l=n.tileData.filter(f=>f.type!=="filler"&&(f.strand==="-"||f.fields[5]==="-"));Mre(a,A),Mre(l,s),A=A.filter(f=>!f.hide),s=s.filter(f=>!f.hide);const c=this.dimensions[1]/2,u=c-this.geneRectHeight/2-this.geneStrandSpacing/2,d=c+this.geneRectHeight/2+this.geneStrandSpacing/2,h=[this,n,n.rectGraphics,this._xScale,C["+"],r,u,this.geneRectHeight],m=[this,n,n.rectGraphics,this._xScale,C["-"],r,d,this.geneRectHeight];zre(A,...h),zre(s,...m),h[5]=o,m[5]=o,Pre(a,...h),Pre(l,...m),uYt(this,n),Bd.stretchRects(this,[f=>f.rectGraphics,f=>f.rectMaskGraphics]);for(const f of Object.values(n.texts))f.style={fontSize:`${this.fontSize}px`,FONT_FAMILY:cx,fill:Kt(f.strand==="-"?this.options.minusStrandColor||eP:this.options.plusStrandColor||qz)}}},{key:"calculateZoomLevel",value:function(){const n=Gt.calculateZoomLevel(this._xScale,this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0]);let C=Math.min(n,this.maxZoom);return C=Math.max(C,0),C}},{key:"draw",value:function(){qa(zo(I.prototype),"draw",this).call(this),this.allTexts=[],this.allBoxes=[];const n=[];this.geneAreaHeight=this.geneRectHeight;const C=this.fontSize/2;Bd.stretchRects(this,[r=>r.rectGraphics,r=>r.rectMaskGraphics]),Object.values(this.fetchedTiles).filter(r=>r.drawnAtScale).forEach(r=>{r.textBgGraphics.clear(),r.textBgGraphics.beginFill(typeof this.options.labelBackgroundColor<"u"?Kt(this.options.labelBackgroundColor):CYt);const o=this.parentInFetched(r);r.initialized&&r.tileData.forEach(A=>{if(!r.texts||A.type==="filler")return;const s=A.fields,a=s[3],l=this.geneId(s,A.type),c=r.texts[l];if(!c)return;const u=+A.chrOffset,d=+s[1]+u,h=+s[2]+u,m=(d+h)/2;let f=this.dimensions[1]/2;const b=(this.geneAreaHeight-this.fontSize)/2;if(s[5]==="+"?f-=this.geneLabelPos==="inside"?b+this.geneStrandSpacing-2:this.fontSize/2+this.geneAreaHeight-2:f+=this.geneLabelPos==="inside"?this.fontSize+this.geneStrandSpacing/2+b+1:1.5*this.fontSize+this.geneAreaHeight+2,c.position.x=this._xScale(m),c.position.y=f,!r.textWidths[l]){const p=c.getBounds().width,y=c.getBounds().height;r.textHeights[l]=y,r.textWidths[l]=p}if(o)c.visible=!1;else{c.visible=!0;const p=2;this.flipText?this.allBoxes.push([c.position.x-r.textHeights[l]/2-p,f-C-1,c.position.x+r.textHeights[l]/2+p,f+C-1,a]):this.allBoxes.push([c.position.x-r.textWidths[l]/2-p,f-C-1,c.position.x+r.textWidths[l]/2+p,f+C-1,a]),this.allTexts.push({importance:+s[4],text:c,caption:a,strand:s[5]}),n.push(r.textBgGraphics)}})}),this.hideOverlaps(this.allBoxes,this.allTexts),this.renderTextBg(this.allBoxes,this.allTexts,n)}},{key:"renderTextBg",value:function(n,C,r){C.forEach((o,A)=>{if(o.text.visible&&n[A]&&r[A]){const[s,a,l,c]=n[A],u=l-s,d=c-a;r[A].drawRect(s-u/2,a-d/2,u,d)}})}},{key:"hideOverlaps",value:function(n,C){jS(n,(r,o)=>{C[r].importance>C[o].importance?C[o].text.visible=!1:C[r].text.visible=!1})}},{key:"setPosition",value:function(n){qa(zo(I.prototype),"setPosition",this).call(this,n),[this.pMain.position.x,this.pMain.position.y]=this.position}},{key:"setDimensions",value:function(n){qa(zo(I.prototype),"setDimensions",this).call(this,n),this.halfRectHHeight=this.dimensions[1]/2,this.visibleAndFetchedTiles().forEach(C=>{this.renderTile(C)})}},{key:"zoomed",value:function(n,C){this.xScale(n),this.yScale(C),this.refreshTiles(),this.draw()}},{key:"getMouseOverHtml",value:function(n,C){if(!this.tilesetInfo)return"";const r=[n,C];for(const o of this.visibleAndFetchedTiles())for(let A=0;A ${c.fields[3]}
Position: ${c.fields[0]}:${c.fields[1]}-${c.fields[2]}
Strand: ${c.fields[5]} - `}}return""}},{key:"exportSVG",value:function(){let n=null,C=null;ss(Qo(I.prototype),"exportSVG",this)?[C,n]=ss(Qo(I.prototype),"exportSVG",this).call(this):(C=document.createElement("g"),n=C);const r=document.createElement("g");return r.setAttribute("transform",`translate(${this.position[0]},${this.position[1]})`),n.appendChild(r),this.visibleAndFetchedTiles().filter(o=>o.allRects).forEach(o=>{const A=document.createElement("g");A.setAttribute("transform",`translate(${o.rectGraphics.position.x}, + `}}return""}},{key:"exportSVG",value:function(){let n=null,C=null;qa(zo(I.prototype),"exportSVG",this)?[C,n]=qa(zo(I.prototype),"exportSVG",this).call(this):(C=document.createElement("g"),n=C);const r=document.createElement("g");return r.setAttribute("transform",`translate(${this.position[0]},${this.position[1]})`),n.appendChild(r),this.visibleAndFetchedTiles().filter(o=>o.allRects).forEach(o=>{const A=document.createElement("g");A.setAttribute("transform",`translate(${o.rectGraphics.position.x}, ${o.rectGraphics.position.y}) scale(${o.rectGraphics.scale.x}, - ${o.rectGraphics.scale.y})`),o.allRects.forEach(s=>{const a=document.createElement("path"),l=s[0];let c=`M ${l[0]} ${l[1]}`;for(let u=2;uo.text.visible).forEach(o=>{const A=document.createElement("g"),s=document.createElement("text");s.setAttribute("text-anchor","middle"),s.setAttribute("font-family",IF),s.setAttribute("font-size",`${this.fontSize}px`),s.setAttribute("dy","-.2em"),A.setAttribute("transform",`scale(${o.text.scale.x},1)`),o.strand==="+"?s.setAttribute("fill",this.options.plusStrandColor):s.setAttribute("fill",this.options.minusStrandColor),s.innerHTML=o.text.text,A.appendChild(s),A.setAttribute("transform",`translate(${o.text.x},${o.text.y})scale(${o.text.scale.x},1)`),r.appendChild(A)}),[C,C]}}]),I}(sy);function KNt(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function Woe(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function Ss(g){return Ss=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},Ss(g)}function Xoe(g,e,I,i,n,C,r,o,A,s){const a=s?g._xScale(I.yStart):g._xScale(I.xStart),l=s?g._xScale(I.yEnd):g._xScale(I.xEnd),c=s?g._yScale(I.xStart):g._yScale(I.yStart),u=s?g._yScale(I.xEnd):g._yScale(I.yEnd),d=I.uid+s,h=l-a,m=u-c;let f={x:a,y:c,width:h,height:m};i&&(hn&&f.xn&&br&&f.yr&&pA||f.height>A)&&(e.drawRect(f.x,f.y,f.width,f.height),g.publish("annotationDrawn",{trackUuid:g.uuid,annotationUuid:d,viewPos:[f.x,f.y,f.width,f.height],dataPos:[I.xStart,I.xEnd,I.yStart,I.yEnd],importance:I.importance,info:{patternType:g.options.patternType}}))}let Y1e=function(g){MNt(I,g);var e=zNt(I);function I(...i){var n;KNt(this,I),n=e.call(this,...i),n.drawnRects={};const{publish:C,subscribe:r,unsubscribe:o}=JN();return n.publish=C,n.subscribe=r,n.unsubscribe=o,n}return xNt(I,[{key:"tileToLocalId",value:function(n){return`${n.join(".")}`}},{key:"tileToRemoteId",value:function(n){return`${n.join(".")}`}},{key:"localToRemoteId",value:function(n){const C=n.split(".");return C.slice(0,C.length-1).join(".")}},{key:"calculateZoomLevel",value:function(){const n=vt.calculateZoomLevel(this._xScale,this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0]),C=vt.calculateZoomLevel(this._xScale,this.tilesetInfo.min_pos[1],this.tilesetInfo.max_pos[1]);let r=Math.max(n,C);return r=Math.min(r,this.maxZoom),r}},{key:"setVisibleTiles",value:function(n){this.visibleTiles=n.map(C=>({tileId:this.tileToLocalId(C),remoteId:this.tileToRemoteId(C)})),this.visibleTileIds=new Set(this.visibleTiles.map(C=>C.remoteId))}},{key:"calculateVisibleTiles",value:function(){if(!this.tilesetInfo)return;this.zoomLevel=this.calculateZoomLevel(),this.xTiles=vt.calculateTiles(this.zoomLevel,this._xScale,this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0],this.tilesetInfo.max_zoom,this.tilesetInfo.max_width),this.yTiles=vt.calculateTiles(this.zoomLevel,this._yScale,this.tilesetInfo.min_pos[1],this.tilesetInfo.max_pos[1],this.tilesetInfo.max_zoom,this.tilesetInfo.max_width);const n=this.xTiles,C=this.yTiles,r=this.zoomLevel,o=[];for(let A=0;A!(d.uid in this.drawnRects)).forEach(d=>{Xoe(this,C,d,A,a,l,c,u,s,this.options.flipDiagonal==="yes"),this.options.flipDiagonal&&this.options.flipDiagonal==="copy"&&Xoe(this,C,d,A,a,l,c,u,s,!0)})}},{key:"exportSVG",value:function(){let n=null,C=null;Gd(Ss(I.prototype),"exportSVG",this)?[C,n]=Gd(Ss(I.prototype),"exportSVG",this).call(this):(C=document.createElement("g"),n=C);const r=document.createElement("g");r.setAttribute("transform",`translate(${this.position[0]},${this.position[1]})`),n.appendChild(r);for(const o of[!0,!1])for(const A of this.visibleAndFetchedTiles())!A.tileData||!A.tileData.length||A.tileData.forEach(s=>{const a=s.uid+o,l=document.createElement("g");if(l.setAttribute("transform",`translate(${A.graphics.position.x},${A.graphics.position.y})scale(${A.graphics.scale.x},${A.graphics.scale.y})`),r.appendChild(l),a in this.drawnRects){const c=this.drawnRects[a],u=document.createElement("rect");u.setAttribute("x",c.x),u.setAttribute("y",c.y),u.setAttribute("width",c.width),u.setAttribute("height",c.height),u.setAttribute("fill",this.options.rectangleDomainFillColor?this.options.rectangleDomainFillColor:"grey"),u.setAttribute("opacity",.3),u.style.stroke="black",u.style.strokeWidth="1px",l.appendChild(u)}});return[C,C]}},{key:"setPosition",value:function(n){Gd(Ss(I.prototype),"setPosition",this).call(this,n),this.pMain.position.y=this.position[1],this.pMain.position.x=this.position[0]}},{key:"zoomed",value:function(n,C){this.xScale().domain()[0]===n.domain()[0]&&this.xScale().domain()[1]===n.domain()[1]&&this.yScale().domain()[0]===C.domain()[0]&&this.yScale().domain()[1]===C.domain()[1]||(this.xScale(n),this.yScale(C),this.refreshTiles(),this.draw())}},{key:"leftTrackDraw",value:function(){this.draw()}}]),I}(Bm);function LNt(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function Hoe(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function ws(g){return ws=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},ws(g)}const gkt=250;let x1e=function(g){$Nt(I,g);var e=qNt(I);function I(i,n){var C;LNt(this,I),C=e.call(this,i,n);const{pubSub:r}=i;C.drawnAnnotations={},C.drawnAnnoGfx={},C.selectedAnno=null,C.options.minSquareSize=+C.options.minSquareSize;const{publish:o,subscribe:A,unsubscribe:s}=JN();return C.publish=o,C.subscribe=A,C.unsubscribe=s,C.sT=0,C.annoSelectedBound=C.annoSelected.bind(K1e(C)),C.pubSubs.push(r.subscribe("annoSelected",C.annoSelectedBound)),C}return _Nt(I,[{key:"minX",get:function(){return this.tilesetInfo&&this.tilesetInfo.min_pos?this.tilesetInfo.min_pos[0]:0}},{key:"maxX",get:function(){return this.tilesetInfo&&this.tilesetInfo.max_pos?this.tilesetInfo.max_pos[0]:this.tilesetInfo.max_width||this.tilesetInfo.max_size}},{key:"minY",get:function(){return this.minX}},{key:"maxY",get:function(){return this.maxX}},{key:"maxSize",get:function(){const i=this.tilesetInfo.max_pos&&Math.max(this.tilesetInfo.max_pos[0]-this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[1]-this.tilesetInfo.min_pos[1]);return i||(this.tilesetInfo.max_size?this.tilesetInfo.max_size:0)}},{key:"projection",value:function([n,C]){return[this._xScale(n),this._yScale(C)]}},{key:"tileToLocalId",value:function(n){return`${n.join(".")}`}},{key:"tileToRemoteId",value:function(n){return`${n.join(".")}`}},{key:"localToRemoteId",value:function(n){const C=n.split(".");return C.slice(0,C.length-1).join(".")}},{key:"calculateZoomLevel",value:function(){const n=vt.calculateZoomLevel(this._xScale,this.minX,this.maxX),C=vt.calculateZoomLevel(this._yScale,this.minY,this.maxY);return qGe(iz(n,C),this.maxZoom)}},{key:"setVisibleTiles",value:function(n){this.visibleTiles=n.map(C=>({tileId:this.tileToLocalId(C),remoteId:this.tileToRemoteId(C)})),this.visibleTileIds=new Set(this.visibleTiles.map(C=>C.tileId))}},{key:"calculateVisibleTiles",value:function(){if(!this.tilesetInfo)return;this.zoomLevel=this.calculateZoomLevel(),this.xTiles=vt.calculateTiles(this.zoomLevel,this._xScale,this.minX,this.maxX,this.tilesetInfo.max_zoom,this.maxSize),this.yTiles=vt.calculateTiles(this.zoomLevel,this._yScale,this.minY,this.maxY,this.tilesetInfo.max_zoom,this.maxSize);const n=this.zoomLevel,C=[];for(let r=0;r!(A.uid in this.drawnAnnotations)||C).forEach(A=>{const[s,a]=this.projection([A.xStart,A.yStart]),[l,c]=this.projection([A.xEnd,A.yEnd]);this.options.exclude&&this.options.exclude.indexOf(A.uid)>=0||this.drawAnnotation(this.prepAnnotation(o,A.uid,s,a,l-s,c-a,A),r)})}},{key:"prepAnnotation",value:function(n,C,r,o,A,s,a){let l;try{l=JSON.parse(a.fields)}catch{}return{graphics:n,id:a.id,uid:C,annotation:{x:r,y:o,width:A,height:s},dataPos:[a.xStart,a.xEnd,a.yStart,a.yEnd],importance:a.importance,info:l}}},{key:"drawAnnotation",value:function({graphics:n,id:C,uid:r,annotation:o,dataPos:A,importance:s,info:a},l){this.options.minSquareSize&&(o.widththis.hover(u,c,r),u.mouseout=()=>this.blur(u,c,r),u.mousedown=()=>this.mouseDown(),u.mouseup=h=>this.mouseUp(u,c,r,h,d),l||this.publish("annotationDrawn",{trackUuids:this.uuid,annotationUuid:r,annotationId:C,viewPos:c,dataPos:A,importance:s,info:a})}},{key:"_drawRect",value:function(n,C,r){let o=this.options.rectangleDomainStrokeColor,A=this.options.rectangleDomainStrokeWidth,s=this.options.rectangleDomainStrokeOpacity,a=this.options.rectangleDomainFillColor,l=this.options.rectangleDomainFillOpacity;this.hoveredAnno===r&&(o=this.options.hoverColor,A=this.options.rectangleDomainStrokeWidth+1||2,s=1,a=this.options.hoverColor,l=this.options.rectangleDomainFillOpacity),this.selectedAnno&&this.selectedAnno.uid===r&&(o=this.options.selectColor,A=this.options.rectangleDomainStrokeWidth+1||2,s=1,a=this.options.selectColor,l=iz(.33,this.options.rectangleDomainFillOpacity)),n.clear(),this.options.trackBorderBgWidth&&(this.setBorderStyle(n,this.options.trackBorderBgColor,this.options.trackBorderBgWidth,this.options.trackBorderBgAlpha),this.setFill(n,a,0),n.drawRect(...C)),this.setBorderStyle(n,o,A,s),this.setFill(n,a,l),n.drawRect(...C),n.__viewPos__=C}},{key:"context",value:function(n,C,r){return o=>o(n,C,r)}},{key:"click",value:function(n,C,r,o,A){this.select(n,C,r),this.pubSub.publish("app.click",{type:"annotation",event:o,payload:A})}},{key:"mouseDown",value:function(){this.sT=performance.now()}},{key:"mouseUp",value:function(n,C,r,o,A){performance.now()-this.sT<=gkt&&this.click(n,C,r,o,A)}},{key:"hover",value:function(n,C,r){this.hoveredAnno=r,this._drawRect(n,C,r),this.animate()}},{key:"focus",value:function(n,C,r){this._drawRect(n,C,r),this.animate()}},{key:"blur",value:function(n,C,r){this.hoveredAnno=null,this._drawRect(n,C,r),this.animate()}},{key:"select",value:function(n,C,r,o=!1){let A=null,s=null;this.selectedAnno&&(A=this.selectedAnno.graphics,s=this.selectedAnno.uid),this.selectedAnno={graphics:n,uid:r},this.focus(n,C,r),this.options.onSelect&&!o&&(window[this.options.onSelect](r),this.pubSub.publish("annoSelected",r)),A&&s&&this.blur(A,A.__viewPos__,s)}},{key:"unselect",value:function(){const n=this.selectedAnno.graphics,C=this.selectedAnno.uid;this.selectedAnno=null,this.blur(n,n.__viewPos__,C)}},{key:"annoSelected",value:function(n){if(!this.selectedAnno||this.selectedAnno.uid!==n){this.selectedAnno&&this.unselect();const C=this.drawnAnnoGfx[n];C&&this.select(C,C.__viewPos__,n,!0)}}},{key:"exportSVG",value:function(){let n=null,C=null;Bd(ws(I.prototype),"exportSVG",this)?[C,n]=Bd(ws(I.prototype),"exportSVG",this).call(this):(C=document.createElement("g"),n=C);const r=document.createElement("g");return r.setAttribute("transform",`translate(${this.position[0]},${this.position[1]})`),n.appendChild(r),this.visibleAndFetchedTiles().filter(o=>o.tileData&&o.tileData.length).map(o=>({graphics:o.graphics,td:o.tileData})).forEach(({td:o,graphics:A})=>{const s=document.createElement("g");if(s.setAttribute("transform",`translate(${A.position.x},${A.position.y})scale(${A.scale.x},${A.scale.y})`),r.appendChild(s),o.uid in this.drawnAnnotations){const a=this.drawnAnnotations[o.uid],l=document.createElement("rect");l.setAttribute("x",a.x),l.setAttribute("y",a.y),l.setAttribute("width",a.width),l.setAttribute("height",a.height),l.setAttribute("fill",this.options.fillColor||"grey"),l.setAttribute("opacity",.3),l.style.stroke=this.options.fillColor||"grey",l.style.strokeWidth="1px",s.appendChild(l)}}),[C,C]}},{key:"setBorderStyle",value:function(n,C=this.options.rectangleDomainStrokeColor,r=this.options.rectangleDomainStrokeWidth,o=this.options.rectangleDomainStrokeOpacity){n.lineStyle(typeof r<"u"?r:1,zt(C||"black"),typeof o<"u"?o:1)}},{key:"setFill",value:function(n,C=this.options.rectangleDomainFillColor,r=this.options.rectangleDomainFillOpacity){n.beginFill(zt(C||"grey"),typeof r<"u"?r:.4)}},{key:"setPosition",value:function(n){Bd(ws(I.prototype),"setPosition",this).call(this,n),this.pMain.position.y=this.position[1],this.pMain.position.x=this.position[0]}},{key:"zoomed",value:function(n,C){this.xScale(n),this.yScale(C),this.refreshTiles(),this.draw()}}]),I}(Bm);function Ikt(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function Toe(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function Hh(g){return Hh=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},Hh(g)}let DP=function(g){okt(I,g);var e=Akt(I);function I(i,n,C){var r;return Ikt(this,I),r=e.call(this,i,n),r.pubSub=i.pubSub,r.options=n,r.isVertical=C,r.rects={},r.defaultColor=wi("red"),r}return ikt(I,[{key:"draw",value:function(){const n=typeof this.options.minRectWidth<"u"?this.options.minRectWidth:10,C=typeof this.options.fill<"u"?wi(this.options.fill):this.defaultColor,r=typeof this.options.fillOpacity<"u"?+this.options.fillOpacity:.2,o=typeof this.options.stroke<"u"?wi(this.options.stroke):this.defaultColor,A=typeof this.options.strokeWidth<"u"?+this.options.strokeWidth:1,s=typeof this.options.strokeOpacity<"u"?+this.options.strokeOpacity:0;let a;this.options.strokePos&&this.options.strokePos.length&&(a=Array.isArray(this.options.strokePos)?this.options.strokePos:[this.options.strokePos]),XB(Hh(I.prototype),"draw",this).call(this);const l=this.pMain;l.clear();const c=performance.now();this.options.regions.forEach(u=>{const d=`${u[0]}-${u[1]}`;this.rects[d]||(this.rects[d]={graphics:new Ct.PIXI.Graphics},l.addChild(this.rects[d].graphics)),this.rects[d].timeStamp=c;const h=wi(u[2])||C;let m=wi(u[3])||o;m||(m=h);const f=Ct.PIXI.utils.rgb2hex([h.r/255,h.g/255,h.b/255]),b=Ct.PIXI.utils.rgb2hex([m.r/255,m.g/255,m.b/255]);a?(l.lineStyle(1,b,0),l.beginFill(b,+u[5]||s)):(l.lineStyle(A,b,+u[5]||s),l.beginFill(f,+u[4]||r));const p=this.isVertical?this._yScale:this._xScale;let y=p(+u[0]);const Z=p(+u[1]);let v=Z-y;const G=typeof u[6]<"u"?u[6]:n;v{(B==="top"||B==="around")&&(this.isVertical?l.drawRect(0,y,A,v):l.drawRect(y,0,v,A)),(B==="right"||B==="around")&&(this.isVertical?l.drawRect(0,y,this.dimensions[0],A):l.drawRect(y,0,A,this.dimensions[1])),(B==="bottom"||B==="around")&&(this.isVertical?l.drawRect(this.dimensions[0]-A,y,A,v):l.drawRect(y,this.dimensions[1]-A,v,A)),(B==="left"||B==="around")&&(this.isVertical?l.drawRect(0,y+v-A,this.dimensions[0],A):l.drawRect(y+v-A,0,A,this.dimensions[1]))})):l.lineStyle(A,b,+u[5]||s),this.rects[d].graphics.clear(),this.rects[d].graphics.interactive=!0,this.rects[d].graphics.buttonMode=!0,l.beginFill(f,+u[4]||r),this.isVertical?(l.drawRect(0,y,this.dimensions[0],v),this.rects[d].graphics.hitArea=new Ct.PIXI.Rectangle(0,y,this.dimensions[0],v)):(l.drawRect(y,0,v,this.dimensions[1]),this.rects[d].graphics.hitArea=new Ct.PIXI.Rectangle(y,0,v,this.dimensions[1])),this.rects[d].graphics.mousedown=()=>{this.rects[d].mouseDownTime=performance.now()},this.rects[d].graphics.mouseup=B=>{performance.now()-this.rects[d].mouseDownTimeu.timeStamp!==c).forEach(u=>l.removeChild(u.graphics))}},{key:"setPosition",value:function(n){XB(Hh(I.prototype),"setPosition",this).call(this,n),this.pMain.position.y=this.position[1],this.pMain.position.x=this.position[0]}},{key:"zoomed",value:function(n,C){this.xScale(n),this.yScale(C),this.draw()}}]),I}(dC);function ckt(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function Noe(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function ta(g){return ta=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},ta(g)}let D1e=function(g){fkt(I,g);var e=pkt(I);function I(i,n){var C;return ckt(this,I),C=e.call(this,i,n),C.drawnRects=new Set,C.pMain=C.pMobile,C}return ukt(I,[{key:"tileToLocalId",value:function(n){return`${n.join(".")}`}},{key:"tileToRemoteId",value:function(n){return`${n.join(".")}`}},{key:"localToRemoteId",value:function(n){const C=n.split(".");return C.slice(0,C.length-1).join(".")}},{key:"calculateZoomLevel",value:function(){const n=vt.calculateZoomLevel(this._xScale,this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0]),C=vt.calculateZoomLevel(this._xScale,this.tilesetInfo.min_pos[1],this.tilesetInfo.max_pos[1]);let r=Math.max(n,C);return r=Math.min(r,this.maxZoom),this.options&&this.options.maxZoom&&(this.options.maxZoom>=0?r=Math.min(this.options.maxZoom,r):console.error("Invalid maxZoom on track:",this)),r}},{key:"setVisibleTiles",value:function(n){this.visibleTiles=n.map(C=>({tileId:this.tileToLocalId(C),remoteId:this.tileToRemoteId(C)})),this.visibleTileIds=new Set(this.visibleTiles.map(C=>C.tileId))}},{key:"calculateVisibleTiles",value:function(){if(!this.tilesetInfo)return;this.zoomLevel=this.calculateZoomLevel();const n=this._xScale.copy();n.domain([this._xScale.invert(this._xScale.range()[0]-this.dimensions[1]*Math.sqrt(2)),this._xScale.invert(this._xScale.range()[1]+this.dimensions[1]*Math.sqrt(2))]),this.xTiles=vt.calculateTiles(this.zoomLevel,n,this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0],this.tilesetInfo.max_zoom,this.tilesetInfo.max_width),this.yTiles=vt.calculateTiles(this.zoomLevel,n,this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0],this.tilesetInfo.max_zoom,this.tilesetInfo.max_width);const C=this.xTiles,r=this.yTiles,o=this.zoomLevel,s=this.tilesetInfo.max_width/2**o,a=[];for(let l=0;lthis.dimensions[1])continue;const d=[o,C[l],r[c]];d.mirrored=!1,a.push(d)}this.setVisibleTiles(a)}},{key:"initTile",value:function(n){uc(ta(I.prototype),"initTile",this).call(this,n),this.drawTile(n)}},{key:"destroyTile",value:function(n,C){}},{key:"draw",value:function(){this.delayDrawing||this.drawnRects.clear(),uc(ta(I.prototype),"draw",this).call(this)}},{key:"drawTile",value:function(n){if(!n.graphics)return;const C=n.graphics;C.clear();const r=zt(this.options.rectangleDomainStrokeColor?this.options.rectangleDomainStrokeColor:"black"),o=zt(this.options.rectangleDomainFillColor?this.options.rectangleDomainFillColor:"grey");if(C.lineStyle(1/this.pMain.scale.x,r,1),C.beginFill(o,.4),C.alpha=this.options.rectangleDomainOpacity?this.options.rectangleDomainOpacity:.5,!!n.tileData.sort)for(const A of n.tileData){const s=this._refXScale(A.xStart),a=this._refXScale(A.xEnd),l=this._refYScale(A.yStart),c=this._refYScale(A.yEnd),u=A.uid;this.drawnRects.has(u)||(this.drawnRects.add(u),C.drawRect(s,l,a-s,c-l),C.pivot.x=this._refXScale(0),C.pivot.y=this._refYScale(0),C.scale.x=-1/Math.sqrt(2),C.rotation=-3*Math.PI/4,C.scale.y=1/Math.sqrt(2),C.position.x=this._refXScale(0),C.position.y=0)}}},{key:"setPosition",value:function(n){uc(ta(I.prototype),"setPosition",this).call(this,n),this.pMain.position.y=this.position[1],this.pMain.position.x=this.position[0]}},{key:"refScalesChanged",value:function(n,C){uc(ta(I.prototype),"refScalesChanged",this).call(this,n,C);for(const r in this.fetchedTiles){const o=this.fetchedTiles[r];if(o.sprite){const A=o.graphics;A.pivot.x=this._refXScale(0),A.pivot.y=this._refYScale(0),A.scale.x=-1/Math.sqrt(2),A.rotation=-3*Math.PI/4,A.scale.y=1/Math.sqrt(2),A.position.x=this._refXScale(0),A.position.y=0}}}},{key:"zoomed",value:function(n,C,r,o,A){uc(ta(I.prototype),"zoomed",this).call(this,n,C,r,o,A),this.pMain.position.x=o,this.pMain.position.y=this.position[1]+this.dimensions[1],this.pMain.scale.x=r,this.pMain.scale.y=r,this.options.oneDHeatmapFlipped&&(this.pMain.scale.y=-r,this.pMain.position.y=this.position[1]),this.draw()}},{key:"leftTrackDraw",value:function(){this.draw()}}]),I}(Bm);function Gkt(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function koe(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function Th(g){return Th=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},Th(g)}let F1e=function(g){Vkt(I,g);var e=Rkt(I);function I(i,n){var C;return Gkt(this,I),C=e.call(this,i,n),C.drawnRects=new Set,C}return Bkt(I,[{key:"tileToLocalId",value:function(n){return`${n.join(".")}`}},{key:"tileToRemoteId",value:function(n){return`${n.join(".")}`}},{key:"localToRemoteId",value:function(n){const C=n.split(".");return C.slice(0,C.length-1).join(".")}},{key:"calculateZoomLevel",value:function(){const n=vt.calculateZoomLevel(this._xScale,this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0]),C=vt.calculateZoomLevel(this._xScale,this.tilesetInfo.min_pos[1],this.tilesetInfo.max_pos[1]);let r=Math.max(n,C);return r=Math.min(r,this.maxZoom),r}},{key:"setVisibleTiles",value:function(n){this.visibleTiles=n.map(C=>({tileId:this.tileToLocalId(C),remoteId:this.tileToRemoteId(C)})),this.visibleTileIds=new Set(this.visibleTiles.map(C=>C.tileId))}},{key:"calculateVisibleTiles",value:function(n=!0){if(!this.tilesetInfo)return;this.zoomLevel=this.calculateZoomLevel(),this.xTiles=vt.calculateTiles(this.zoomLevel,this._xScale,this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0],this.tilesetInfo.max_zoom,this.tilesetInfo.max_width),this.yTiles=vt.calculateTiles(this.zoomLevel,this._yScale,this.tilesetInfo.min_pos[1],this.tilesetInfo.max_pos[1],this.tilesetInfo.max_zoom,this.tilesetInfo.max_width);const C=this.xTiles,r=this.yTiles,o=this.zoomLevel,A=[];for(let s=0;si.chrPositions?Vi(n,i):null,i.chrToAbs=([n,C]=[])=>i.chrPositions?D9(n,C,i):null,vt.text(g,(n,C)=>{if(n)e&&e(null);else{const r=GQ(C),o=$N(r);Object.keys(o).forEach(A=>{i[A]=o[A]}),e&&e(i)}},I).then(()=>i)}function Tkt(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function Yoe(g,e){for(var I=0;II.pos).left}return Nkt(g,[{key:"scalesToPositionText",value:function(I,i,n=!1){if(this.chromInfo===null||!I||!i)return"";const C=Vi(I.domain()[0],this.chromInfo),r=Vi(I.domain()[1],this.chromInfo),o=Vi(i.domain()[0],this.chromInfo),A=Vi(i.domain()[1],this.chromInfo);let s=null;const a=hr(",d");return C[0]!==r[0]?s=`${C[0]}:${a(Math.floor(C[1]))}-${r[0]}:${a(Math.ceil(r[1]))}`:s=`${C[0]}:${a(Math.floor(C[1]))}-${a(Math.ceil(r[1]))}`,n&&(o[0]!==A[0]?s+=` & ${o[0]}:${a(Math.floor(o[1]))}-${A[0]}:${a(Math.ceil(A[1]))}`:s+=` & ${o[0]}:${a(Math.floor(o[1]))}-${a(Math.ceil(A[1]))}`),(C[2]<=0||r[2]>0||n&&(o[2]<=0||A[2]>0))&&(s+=` [offset ${C[2]},${r[2]}`,n&&(s+=`:${o[2]},${A[2]}`),s+="]"),s}},{key:"convertNumberNotation",value:function(I){let i=I;if(!i.includes("M",i.length-1)&&!i.includes("K",i.length-1))return i;let n=0,C=0;if(i.includes("M",i.length-1)?(n=6,i=i.replace("M","")):(n=3,i=i.replace("K","")),Number.isNaN(+i))return I;i=(+i).toString(),i.includes(".")&&(C=i.length-1-i.indexOf("."),i=(+i.replace(".","")).toString());const r=n-C;return r<0?I:(i+="0".repeat(r),i)}},{key:"parsePosition",value:function(I,i=null){const n=I.split(":");let C=null,r=0;n.length>1?(C=n[0],r=+this.convertNumberNotation(n[1].replace(/,/g,""))):n[0]in this.chromInfo.chrPositions?(C=n[0],r=0,i!==null&&(r=+this.chromInfo.chromLengths[C])):(r=+this.convertNumberNotation(n[0].replace(/,/g,"")),C=null,i&&(C=i));let o=null;return C===null?(C=i,o=r):C in this.chromInfo.chrPositions&&(o=this.chromInfo.chrPositions[C].pos+r),[C,r,o]}},{key:"matchRangesToLarger",value:function(I,i){if(I[1]-I[0]C.length>0);let n=null;if(i[0].indexOf("-")===0&&(i[0]=i[0].slice(3,i[0].length)),i.length>1){let[C,r,o]=this.parsePosition(i[0]),[A,s,a]=this.parsePosition(i[1],C);const l=[o,a];[C,r,o]=this.parsePosition(i[1]),[A,s,a]=this.parsePosition(i[0],C),C===null&&A!==null&&([C,r,o]=this.parsePosition(i[1],A));const c=[o,a];return c[1]-c[0]>l[1]-l[0]?c:l}if(i[0]in this.chromInfo.chrPositions){const C=+this.chromInfo.chrPositions[i[0]].pos;n=[C,C+ +this.chromInfo.chromLengths[i[0]]]}else{const[C,r,o]=this.parsePosition(i[0]);n=[o-8e6,o+8e6]}return n[0]>n[1]?[n[1],n[0]]:n}},{key:"parseOffset",value:function(I){const i=I.split(":");if(i.length===0)return[[0,0],[0,0]];if(i.length===1){const r=i[0].split(",");return[[+r[0],+r[1]],[0,0]]}const n=i[0].split(","),C=i[1].split(",");return[[+n[0],+n[1]],[+C[0],+C[1]]]}},{key:"searchPosition",value:function(I){let i=null,n=null;I=I.trim();const C=/\[offset (.+?)\]/.exec(I);let r=[[0,0],[0,0]];C&&(I=I.replace(C[0],""),r=this.parseOffset(C[1]));const o=I.split(" & ");return o.length>1?(i=this.getSearchRange(o[0].split(" ")[0]),n=this.getSearchRange(o[1].split(" ")[0])):i=this.getSearchRange(o[0]),i!==null&&n!==null&&([i,n]=this.matchRangesToLarger(i,n)),i&&(i[0]+=r[0][0],i[1]+=r[0][1]),n&&(n[0]+=r[1][0],n[1]+=r[1][1]),[i,n]}}]),g}();function Kkt(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function Koe(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function h0(g){return h0=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},h0(g)}let E1e=function(g){Mkt(I,g);var e=zkt(I);function I(i,n){var C;Kkt(this,I),C=e.call(this,i,n);const{dataConfig:r,animate:o,pubSub:A}=i;C.searchField=null,C.chromInfo=null,C.animate=o;const s=r.server,a=r.tilesetUid,l=`${s}/chrom-sizes/?id=${a}`;return qs(l,c=>{C.chromInfo=c,C.searchField=new d0(C.chromInfo),C.draw(),C.texts=[];for(let u=0;uthis.dimensions[0]?f.x-=h+p-this.dimensions[0]:h-p<0&&(f.x-=h-p),m+y>this.dimensions[1]?f.y-=m+y-this.dimensions[1]:m-y<0&&(f.y-=m-y),f.visible=!0,n.push({importance:this.texts[s][a].hashValue,text:this.texts[s][a],caption:null})}this.hideOverlaps(n)}},{key:"hideOverlaps",value:function(n){let C=[];C=n.map(r=>{const o=r.text;o.updateTransform();const A=o.getBounds();return[A.x,A.y,A.x+A.width,A.y+A.height]}),Ww(C,(r,o)=>{n[r].importance>n[o].importance?n[o].text.visible=0:n[r].text.visible=0})}},{key:"setPosition",value:function(n){HW(h0(I.prototype),"setPosition",this).call(this,n),this.pMain.position.y=this.position[1],this.pMain.position.x=this.position[0]}},{key:"zoomed",value:function(n,C){this.xScale(n),this.yScale(C),this.draw()}}]),I}(dC);function Lkt(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function xoe(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function _c(g){return _c=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},_c(g)}let cG=function(g){$kt(I,g);var e=qkt(I);function I(i,n){var C;Lkt(this,I),C=e.call(this,i,n);const{chromInfoPath:r,dataConfig:o,animate:A,pubSub:s,orientation:a="2d",isOverlay:l=!1}=i;C.searchField=null,C.chromInfo=null,C.animate=A,C.orientation=a,C.isOverlay=l;let c=r;return c||(c=`${o.server}/chrom-sizes/?id=${o.tilesetUid}`),qs(c,u=>{C.chromInfo=u,C.searchField=new d0(C.chromInfo),C.texts=[],C.lineGraphics=new Ct.PIXI.Graphics,C.lineGraphics1dH=new Ct.PIXI.Graphics,C.lineGraphics1dV=new Ct.PIXI.Graphics,C.lineGraphics2d=new Ct.PIXI.Graphics,C.mask1dH=new Ct.PIXI.Graphics,C.mask1dV=new Ct.PIXI.Graphics,C.mask2d=new Ct.PIXI.Graphics,C.lineGraphics.addChild(C.lineGraphics1dH),C.lineGraphics1dH.addChild(C.mask1dH),C.lineGraphics.addChild(C.lineGraphics1dV),C.lineGraphics1dV.addChild(C.mask1dV),C.lineGraphics.addChild(C.lineGraphics2d),C.lineGraphics2d.addChild(C.mask2d),C.pMain.addChild(C.lineGraphics),C.draw(),C.animate()},s),C}return _kt(I,[{key:"drawLines",value:function(n=this.orientation,C=0,r=0){let o=this.lineGraphics;this.isOverlay&&n==="1d-horizontal"&&(o=this.lineGraphics1dH),this.isOverlay&&n==="1d-vertical"&&(o=this.lineGraphics1dV),this.isOverlay&&n==="2d"&&(o=this.lineGraphics2d);const A=zt(this.options.lineStrokeColor?this.options.lineStrokeColor:"blue"),s=this.options.lineStrokeWidth?this.options.lineStrokeWidth:1;o.lineStyle(s,A,1),(n==="2d"||n==="1d-horizontal")&&(o.moveTo(this._xScale(0)+C,r),o.lineTo(this._xScale(0)+C,this.dimensions[1]+r)),(n==="2d"||n==="1d-vertical")&&(o.moveTo(C,this._yScale(0)+r),o.lineTo(this.dimensions[0]+C,this._yScale(0)+r));for(let a=0;a0&&c0&&c0&&h0&&h"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function Nh(g){return Nh=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},Nh(g)}const cYt=300;let M1e=function(g){oYt(I,g);var e=AYt(I);function I(i,n){var C;IYt(this,I),C=e.call(this,i,n);const{chromInfoPath:r,pubSub:o}=i;return C.pubSub=o,C.rects={},qs(r,A=>{C.chromInfo=A,C.draw()},C.pubSub),C}return iYt(I,[{key:"draw",value:function(){if(!this.chromInfo)return;const n=this.options.minRectWidth?this.options.minRectWidth:10,C=this.options.minRectWidth?this.options.minRectHeight:10;TB(Nh(I.prototype),"draw",this).call(this);const r=this.pMain;r.clear();const o=performance.now();this.options.regions.forEach(A=>{const s=A.slice(0,6).join("-");this.rects[s]||(this.rects[s]={graphics:new Ct.PIXI.Graphics},r.addChild(this.rects[s].graphics)),this.rects[s].timeStamp=o;const a=wi(A[6]);let l=wi(A[7]);l||(l=a);const c=Ct.PIXI.utils.rgb2hex([a.r/255,a.g/255,a.b/255]),u=Ct.PIXI.utils.rgb2hex([l.r/255,l.g/255,l.b/255]);r.lineStyle(1,u,l.opacity),r.beginFill(c,a.opacity);let d=this._xScale(this.chromInfo.chrPositions[A[0]].pos+ +A[1]);const h=this._xScale(this.chromInfo.chrPositions[A[0]].pos+ +A[2]);let m=this._yScale(this.chromInfo.chrPositions[A[3]].pos+ +A[4]);const f=this._yScale(this.chromInfo.chrPositions[A[3]].pos+ +A[5]);let b=h-d,p=f-m;const y=typeof A[8]<"u"?A[8]:n,Z=typeof A[9]<"u"?A[9]:C;b{this.rects[s].mouseDownTime=performance.now()},this.rects[s].graphics.mouseup=v=>{performance.now()-this.rects[s].mouseDownTime"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function Vs(g){return Vs=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},Vs(g)}const GYt=200,BYt=6,vYt=2,Eoe=7829367;let P1e=function(g){pYt(I,g);var e=bYt(I);function I(i,n){var C;uYt(this,I),C=e.call(this,i,n);const{dataConfig:r,animate:o,chromInfoPath:A,isShowGlobalMousePosition:s}=i;C.searchField=null,C.chromInfo=null,C.dataConfig=r,C.pTicks=new Ct.PIXI.Graphics,C.pMain.addChild(C.pTicks),C.gTicks={},C.tickTexts={},C.options=n,C.isShowGlobalMousePosition=s,C.textFontSize=12,C.textFontFamily="Arial",C.textFontColor="#808080",C.textStrokeColor=C.getTheme()===II?"#000000":"#ffffff",C.pixiTextConfig={fontSize:+C.options.fontSize?`${+C.options.fontSize}px`:`${C.textFontSize}px`,fontFamily:C.textFontFamily,fill:C.options.color||C.textFontColor,lineJoin:"round",stroke:C.options.stroke||C.textStrokeColor,strokeThickness:2},C.stroke=zt(C.pixiTextConfig.stroke),C.tickWidth=GYt,C.tickHeight=BYt,C.tickTextSeparation=vYt,C.tickColor=C.options.tickColor?zt(C.options.tickColor):Eoe,C.animate=o,C.pubSubs=[],C.options.showMousePosition&&!C.hideMousePosition&&(C.hideMousePosition=hh(z1e(C),C.is2d,C.isShowGlobalMousePosition()));let a=A;return a||(a=`${r.server}/chrom-sizes/?id=${r.tilesetUid}`),qs(a,l=>{C.chromInfo=l,C.searchField=new d0(C.chromInfo),C.rerender(C.options,!0),C.draw(),C.animate()},C.pubSub),C}return dYt(I,[{key:"initBoundsTicks",value:function(){this.pTicks&&(this.pMain.removeChild(this.pTicks),this.pTicks=null),this.gBoundTicks||(this.gBoundTicks=new Ct.PIXI.Graphics,this.leftBoundTick=new Ct.PIXI.Text("",this.pixiTextConfig),this.rightBoundTick=new Ct.PIXI.Text("",this.pixiTextConfig),this.gBoundTicks.addChild(this.leftBoundTick),this.gBoundTicks.addChild(this.rightBoundTick),this.pMain.addChild(this.gBoundTicks)),this.texts=[]}},{key:"initChromLabels",value:function(){if(this.chromInfo){this.gBoundTicks&&(this.pMain.removeChild(this.gBoundTicks),this.gBoundTicks=null),this.pTicks||(this.pTicks=new Ct.PIXI.Graphics,this.pMain.addChild(this.pTicks)),this.texts=[],this.pTicks.removeChildren();for(let n=0;nNumber.isInteger(b)),c=this.tickTexts[n.chr],u=this.options.fontIsLeftAligned?(+this.options.fontSize||this.textFontSize)/2:this.tickHeight,d=this.flipText?-1:1,h=this.options.fontIsLeftAligned?d*4:0;let m=this.options.fontIsLeftAligned?0:u+this.tickTextSeparation;for(this.options.reverseOrientation&&(m=this.dimensions[1]-m);c.lengthl.length;){const b=c.pop();this.gTicks[n.chr].removeChild(b)}let f=0;for(;f{if(this.tickTexts[o])for(let A=0;A{r.updateTransform();const A=r.getBounds();return[A.x,A.y,A.x+A.width,A.y+A.height]}),Ww(C,(r,o)=>{n[r].importance>n[o].importance?n[o].text.visible=!1:n[r].text.visible=!1})}},{key:"setPosition",value:function(n){vd(Vs(I.prototype),"setPosition",this).call(this,n),[this.pMain.position.x,this.pMain.position.y]=this.position}},{key:"zoomed",value:function(n,C){this.xScale(n),this.yScale(C),this.draw()}},{key:"exportSVG",value:function(){let n=null,C=null;vd(Vs(I.prototype),"exportSVG",this)?[C,n]=vd(Vs(I.prototype),"exportSVG",this).call(this):(C=document.createElement("g"),n=C),C.setAttribute("class","chromosome-labels");const r=document.createElement("g");return n.appendChild(r),r.setAttribute("transform",`translate(${this.position[0]},${this.position[1]})`),this.allTexts.filter(o=>o.text.visible).forEach(o=>{const A=rz(o.text);r.appendChild(A)}),Object.values(this.tickTexts).forEach(o=>{o.filter(A=>A.visible).forEach(A=>{let s=rz(A);r.appendChild(s),s=CBe(A.x,this.options.reverseOrientation?0:this.dimensions[1],A.x,this.options.reverseOrientation?this.tickHeight:this.dimensions[1]-this.tickHeight,1,this.tickColor);const a=document.createElement("line");a.setAttribute("x1",A.tickLine[0]),a.setAttribute("y1",A.tickLine[1]),a.setAttribute("x2",A.tickLine[2]),a.setAttribute("y2",A.tickLine[3]),a.setAttribute("style","stroke: grey"),r.appendChild(s),r.appendChild(a)})}),[C,n]}}]),I}(dC);function SYt(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function Moe(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function ga(g){return ga=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},ga(g)}let J1e=function(g){XYt(I,g);var e=HYt(I);function I(i,n){var C;SYt(this,I),C=e.call(this,i,n);const{animate:r}=i;return C.pMain=C.pMobile,C.colorScale=Pb,C.continuousScaling=!1,n&&n.colorRange&&(C.colorScale=Cu(n.colorRange)),C.animate=r,C.options=n,C.pubSubs=[],C}return wYt(I,[{key:"rerender",value:function(n,C){dc(ga(I.prototype),"rerender",this).call(this,n,C),this.zoomed(this.xScale(),this.yScale(),this.pMain.scale.x,this.pMain.position.x,this.pMain.position.y)}},{key:"calculateZoomLevel",value:function(){let n=null;if(this.tilesetInfo.resolutions){const C=vt.calculateZoomLevelFromResolutions(this.tilesetInfo.resolutions,this._xScale,this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0]),r=vt.calculateZoomLevelFromResolutions(this.tilesetInfo.resolutions,this._xScale,this.tilesetInfo.min_pos[1],this.tilesetInfo.max_pos[1]);n=Math.min(C,r)}else{const C=vt.calculateZoomLevel(this._xScale,this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0]),r=vt.calculateZoomLevel(this._xScale,this.tilesetInfo.min_pos[1],this.tilesetInfo.max_pos[1]);n=Math.max(C,r),n=Math.min(n,this.maxZoom)}return this.options&&this.options.maxZoom&&(this.options.maxZoom>=0?n=Math.min(this.options.maxZoom,n):console.error("Invalid maxZoom on track:",this)),n}},{key:"calculateVisibleTiles",value:function(){if(!this.tilesetInfo)return;this.zoomLevel=this.calculateZoomLevel();const n=this._xScale.copy();if(n.domain([this._xScale.invert(this._xScale.range()[0]-this.dimensions[1]*Math.sqrt(2)),this._xScale.invert(this._xScale.range()[1]+this.dimensions[1]*Math.sqrt(2))]),this.tilesetInfo.resolutions){const l=this.tilesetInfo.resolutions.map(c=>+c).sort((c,u)=>u-c);this.xTiles=vt.calculateTilesFromResolution(l[this.zoomLevel],n,this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0]),this.yTiles=vt.calculateTilesFromResolution(l[this.zoomLevel],n,this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0])}else this.xTiles=vt.calculateTiles(this.zoomLevel,n,this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0],this.tilesetInfo.max_zoom,this.tilesetInfo.max_width),this.yTiles=vt.calculateTiles(this.zoomLevel,n,this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0],this.tilesetInfo.max_zoom,this.tilesetInfo.max_width);const C=this.xTiles,r=this.yTiles,o=this.zoomLevel,s=this.tilesetInfo.max_width/2**o,a=[];for(let l=0;lthis.dimensions[1])continue;const d=[o,C[l],r[c]];d.mirrored=!1,d.dataTransform=this.options.dataTransform?this.options.dataTransform:"default",a.push(d)}this.setVisibleTiles(a)}},{key:"tileDataToCanvas",value:function(n){const C=document.createElement("canvas");C.width=256,C.height=256;const r=C.getContext("2d");r.fillStyle="transparent",r.fillRect(0,0,C.width,C.height);const o=new ImageData(n,C.width,C.height);return r.putImageData(o,0,0),C}},{key:"setSpriteProperties",value:function(n,C,r,o){const{tileX:A,tileY:s,tileWidth:a,tileHeight:l}=this.getTilePosAndDimensions(C,r),c=A+a,u=s+l;n.width=this._refXScale(c)-this._refXScale(A),n.height=this._refYScale(u)-this._refYScale(s),n.x=this._refXScale(A),n.y=this._refYScale(s)}},{key:"pixDataFunction",value:function(n,C){if(C){const r=n.graphics,o=this.tileDataToCanvas(C.pixData),A=Ct.PIXI.VERSION[0]==="4"?Ct.PIXI.Texture.fromCanvas(o,Ct.PIXI.SCALE_MODES.NEAREST):Ct.PIXI.Texture.from(o,{scaleMode:Ct.PIXI.SCALE_MODES.NEAREST});n.sprite=new Ct.PIXI.Sprite(A),n.canvas=o,this.setSpriteProperties(n.sprite,n.tileData.zoomLevel,n.tileData.tilePos,n.mirrored),r.pivot.x=this._refXScale(0),r.pivot.y=this._refYScale(0),r.scale.x=-1/Math.sqrt(2),r.rotation=-3*Math.PI/4,r.scale.y=1/Math.sqrt(2),r.position.x=this._refXScale(0),r.position.y=0,r.removeChildren(),r.addChild(n.sprite)}this.renderingTiles.delete(n.tileId)}},{key:"refScalesChanged",value:function(n,C){dc(ga(I.prototype),"refScalesChanged",this).call(this,n,C);for(const r in this.fetchedTiles){const o=this.fetchedTiles[r];if(o.sprite){this.setSpriteProperties(o.sprite,o.tileData.zoomLevel,o.tileData.tilePos,o.mirrored);const A=o.graphics;A.pivot.x=this._refXScale(0),A.pivot.y=this._refYScale(0),A.scale.x=-1/Math.sqrt(2),A.rotation=-3*Math.PI/4,A.scale.y=1/Math.sqrt(2),A.position.x=this._refXScale(0),A.position.y=0}}}},{key:"zoomed",value:function(n,C,r,o,A){dc(ga(I.prototype),"zoomed",this).call(this,n,C,r,o,A),dc(ga(I.prototype),"draw",this).call(this),this.pMain.position.x=o,this.pMain.position.y=this.position[1]+this.dimensions[1],this.pMain.scale.x=r,this.pMain.scale.y=r,this.options.oneDHeatmapFlipped&&(this.pMain.scale.y=-r,this.pMain.position.y=this.position[1])}},{key:"leftTrackDraw",value:function(){this.draw()}},{key:"exportSVG",value:function(){let n=null,C=null;[C,n]=dc(ga(I.prototype),"superSVG",this).call(this);const r=document.createElement("g");n.appendChild(r),r.setAttribute("transform",`translate(${this.pMain.position.x},${this.pMain.position.y}) scale(${this.pMain.scale.x},${this.pMain.scale.y})`);for(const A of this.visibleAndFetchedTiles()){const s=document.createElement("g"),a=A.graphics,l=a.rotation*180/Math.PI,c=`translate(${a.position.x},${a.position.y}) rotate(${l}) scale(${a.scale.x},${a.scale.y}) translate(${-a.pivot.x},${-a.pivot.y})`;s.setAttribute("transform",c);const u=A.sprite.rotation*180/Math.PI,d=document.createElement("g");d.setAttribute("transform",`translate(${A.sprite.x},${A.sprite.y}) rotate(${u}) scale(${A.sprite.scale.x},${A.sprite.scale.y})`);const h=document.createElement("image");h.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",A.canvas.toDataURL()),h.setAttribute("width",256),h.setAttribute("height",256),d.appendChild(h),s.appendChild(d),r.appendChild(s)}const o=this.exportColorBarSVG();return n.appendChild(o),[C,C]}}]),I}(Rw);function YYt(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function zoe(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function wH(g){return wH=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},wH(g)}let Poe=function(g){FYt(I,g);var e=EYt(I);function I(i,n){var C;return YYt(this,I),C=e.call(this,i,n),C.tilesetInfo={},C.errorTextText=`Unknown track type: ${n.type}`,C}return KYt(I,[{key:"zoomed",value:function(){this.draw()}}]),I}(dC);function JYt(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function Joe(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function VH(g){return VH=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},VH(g)}let L1e=function(g){UYt(I,g);var e=QYt(I);function I(i,n){var C;return JYt(this,I),C=e.call(this,i,n),C.axis=new zk(O1e(C)),C.pBase.addChild(C.axis.pAxis),C}return OYt(I,[{key:"initTile",value:function(n){this.scale.minRawValue=this.minVisibleValueInTiles(),this.scale.maxRawValue=this.minVisibleValueInTiles(),this.scale.minValue=this.scale.minRawValue,this.scale.maxValue=this.scale.maxRawValue,this.drawTile(n)}},{key:"drawTile",value:function(n){if(!n.graphics)return;const C=n.graphics,r=6,o=4;C.clear(),this.valueScale=mu().domain([this.minValue()+.01,this.maxValue()]).range([this.dimensions[1]-r/2,r/2]);const A=zt("black");C.lineStyle(1,A,.3),C.beginFill(A,.3),this.drawAxis(this.valueScale),n.tileData.forEach(s=>{const a=s.fields,l=+s.chrOffset,c=+a[1]+l,u=+a[2]+l,d=+a[3],h=this._xScale(c),m=this._xScale(u),f=Math.max(m-h,o),b=this.valueScale(d),p=(m+h)/2;C.drawRect(p-f/2,b-r/2,f,r)})}},{key:"minVisibleValueInTiles",value:function(){let n=this.visibleAndFetchedIds();return n.length===0&&(n=Object.keys(this.fetchedTiles)),Math.min.apply(null,n.map(r=>+Math.min(...this.fetchedTiles[r].tileData.filter(o=>!Number.isNaN(o.fields[3])).map(o=>+o.fields[3]))))}},{key:"maxVisibleValueInTiles",value:function(){let n=this.visibleAndFetchedIds();return n.length===0&&(n=Object.keys(this.fetchedTiles)),Math.max.apply(null,n.map(r=>+Math.max(...this.fetchedTiles[r].tileData.filter(o=>!Number.isNaN(o.fields[3])).map(o=>+o.fields[3]))))}}]),I}(cy);function qYt(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function Ooe(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function Uc(g){return Uc=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},Uc(g)}let _1e=function(g){iKt(I,g);var e=nKt(I);function I(i,n){var C;qYt(this,I),C=e.call(this,i,n);const{registerViewportChanged:r,removeViewportChanged:o,setDomainsCallback:A}=i,s=dg.nice();return C.uid=s,C.options=n,C.hasFromView=!i.projectionXDomain||!i.projectionYDomain,C.removeViewportChanged=o,C.setDomainsCallback=A,C.viewportXDomain=C.hasFromView?null:i.projectionXDomain,C.viewportYDomain=C.hasFromView?null:i.projectionYDomain,C.brush=lQ().on("brush",C.brushed.bind(QP(C))),C.gBrush=C.gMain.append("g").attr("id",`brush-${C.uid}`).call(C.brush),C.gBrush.selectAll(".overlay").style("pointer-events","none"),C.gBrush.selectAll(".handle--n").style("pointer-events","none"),C.gBrush.selectAll(".handle--s").style("pointer-events","none"),C.gBrush.selectAll(".handle--w").style("pointer-events","none"),C.gBrush.selectAll(".handle--e").style("pointer-events","none"),r(s,C.viewportChanged.bind(QP(C))),C.rerender(),C.draw(),C}return eKt(I,[{key:"brushed",value:function(n){const C=n.selection;if(!this._xScale||!this._yScale)return;const r=[this._xScale.invert(C[0][0]),this._xScale.invert(C[1][0])],o=[this._yScale.invert(C[0][1]),this._yScale.invert(C[1][1])];this.hasFromView||(this.viewportXDomain=r,this.viewportYDomain=o),this.setDomainsCallback(r,o)}},{key:"viewportChanged",value:function(n,C){const r=n.domain(),o=C.domain();this.viewportXDomain=r,this.viewportYDomain=o,this.draw()}},{key:"remove",value:function(){this.removeViewportChanged(this.uid),Cb(Uc(I.prototype),"remove",this).call(this)}},{key:"rerender",value:function(){this.gBrush.selectAll(".selection").attr("fill",this.options.projectionFillColor).attr("stroke",this.options.projectionStrokeColor).attr("fill-opacity",this.options.projectionFillOpacity).attr("stroke-opacity",this.options.projectionStrokeOpacity).attr("stroke-width",this.options.strokeWidth)}},{key:"draw",value:function(){if(!this._xScale||!this.yScale||!this.viewportXDomain||!this.viewportYDomain)return;const n=this._xScale(this.viewportXDomain[0]),C=this._yScale(this.viewportYDomain[0]),r=this._xScale(this.viewportXDomain[1]),o=this._yScale(this.viewportYDomain[1]),A=[[n,C],[r,o]];this.brush.on("brush",null),this.gBrush.call(this.brush.move,A),this.brush.on("brush",this.brushed.bind(this))}},{key:"zoomed",value:function(n,C){this.xScale(n),this.yScale(C),this.draw()}},{key:"setPosition",value:function(n){Cb(Uc(I.prototype),"setPosition",this).call(this,n),this.draw()}},{key:"setDimensions",value:function(n){Cb(Uc(I.prototype),"setDimensions",this).call(this,n);const C=this._xScale.range(),r=this._yScale.range(),o=C[1]-C[0],A=r[1]-r[0];this.brush.extent([[C[0]-o,r[0]-A],[C[1]+o,r[1]+A]]),this.gBrush.call(this.brush),this.draw()}}]),I}(vm);function oKt(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function Loe(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function Qc(g){return Qc=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},Qc(g)}let U1e=function(g){cKt(I,g);var e=uKt(I);function I(i,n){var C;oKt(this,I),C=e.call(this,i,n);const{registerViewportChanged:r,removeViewportChanged:o,setDomainsCallback:A}=i,s=dg.nice();return C.uid=s,C.options=n,C.hasFromView=!i.projectionXDomain,C.removeViewportChanged=o,C.setDomainsCallback=A,C.viewportXDomain=C.hasFromView?null:i.projectionXDomain,C.viewportYDomain=C.hasFromView?null:[0,0],C.brush=QN().on("brush",C.brushed.bind($P(C))),C.gBrush=C.gMain.append("g").attr("id",`brush-${C.uid}`).call(C.brush),C.gBrush.selectAll(".overlay").style("pointer-events","none"),C.gBrush.selectAll(".handle--ne").style("pointer-events","none"),C.gBrush.selectAll(".handle--nw").style("pointer-events","none"),C.gBrush.selectAll(".handle--sw").style("pointer-events","none"),C.gBrush.selectAll(".handle--se").style("pointer-events","none"),C.gBrush.selectAll(".handle--n").style("pointer-events","none"),C.gBrush.selectAll(".handle--s").style("pointer-events","none"),r(s,C.viewportChanged.bind($P(C))),C.rerender(),C.draw(),C}return AKt(I,[{key:"brushed",value:function(n){const C=n.selection;if(!this._xScale||!this._yScale)return;const r=[this._xScale.invert(C[0]),this._xScale.invert(C[1])],o=this.viewportYDomain;this.hasFromView||(this.viewportXDomain=r),this.setDomainsCallback(r,o)}},{key:"viewportChanged",value:function(n,C,r=!0){const o=n.domain(),A=C.domain();this.viewportXDomain=o,this.viewportYDomain=A,this.draw()}},{key:"remove",value:function(){this.removeViewportChanged(this.uid),rb(Qc(I.prototype),"remove",this).call(this)}},{key:"rerender",value:function(){this.gBrush.selectAll(".selection").attr("fill",this.options.projectionFillColor).attr("stroke",this.options.projectionStrokeColor).attr("fill-opacity",this.options.projectionFillOpacity).attr("stroke-opacity",this.options.projectionStrokeOpacity).attr("stroke-width",this.options.strokeWidth)}},{key:"draw",value:function(){if(!this._xScale||!this.yScale||!this.viewportXDomain||!this.viewportYDomain)return;const n=this._xScale(this.viewportXDomain[0]),C=this._xScale(this.viewportXDomain[1]),r=[n,C];this.brush.on("brush",null),this.gBrush.call(this.brush.move,r),this.brush.on("brush",this.brushed.bind(this))}},{key:"zoomed",value:function(n,C){this.xScale(n),this.yScale(C),this.draw()}},{key:"setPosition",value:function(n){rb(Qc(I.prototype),"setPosition",this).call(this,n),this.draw()}},{key:"setDimensions",value:function(n){rb(Qc(I.prototype),"setDimensions",this).call(this,n);const C=this._xScale.range(),r=this._yScale.range(),o=C[1]-C[0];this.brush.extent([[C[0]-o,r[0]],[C[1]+o,r[1]]]),this.gBrush.call(this.brush),this.draw()}}]),I}(vm);function mKt(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function _oe(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function jc(g){return jc=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},jc(g)}let Q1e=function(g){ZKt(I,g);var e=GKt(I);function I(i,n){var C;mKt(this,I),C=e.call(this,i,n);const{registerViewportChanged:r,removeViewportChanged:o,setDomainsCallback:A}=i,s=dg.nice();return C.uid=s,C.options=n,C.hasFromView=!i.projectionYDomain,C.removeViewportChanged=o,C.setDomainsCallback=A,C.viewportXDomain=C.hasFromView?null:[0,0],C.viewportYDomain=C.hasFromView?null:i.projectionYDomain,C.brush=nw().on("brush",C.brushed.bind(eJ(C))),C.gBrush=C.gMain.append("g").attr("id",`brush-${C.uid}`).call(C.brush),C.gBrush.selectAll(".overlay").style("pointer-events","none"),C.gBrush.selectAll(".handle--ne").style("pointer-events","none"),C.gBrush.selectAll(".handle--nw").style("pointer-events","none"),C.gBrush.selectAll(".handle--sw").style("pointer-events","none"),C.gBrush.selectAll(".handle--se").style("pointer-events","none"),C.gBrush.selectAll(".handle--e").style("pointer-events","none"),C.gBrush.selectAll(".handle--w").style("pointer-events","none"),r(s,C.viewportChanged.bind(eJ(C))),C.rerender(),C.draw(),C}return fKt(I,[{key:"brushed",value:function(n){const C=n.selection;if(!this._xScale||!this._yScale)return;const r=this.viewportXDomain,o=[this._yScale.invert(C[0]),this._yScale.invert(C[1])];this.hasFromView||(this.viewportYDomain=o),this.setDomainsCallback(r,o)}},{key:"viewportChanged",value:function(n,C,r=!0){const o=n.domain(),A=C.domain();this.viewportXDomain=o,this.viewportYDomain=A,this.draw()}},{key:"remove",value:function(){this.removeViewportChanged(this.uid),ob(jc(I.prototype),"remove",this).call(this)}},{key:"rerender",value:function(){this.gBrush.selectAll(".selection").attr("fill",this.options.projectionFillColor).attr("stroke",this.options.projectionStrokeColor).attr("fill-opacity",this.options.projectionFillOpacity).attr("stroke-opacity",this.options.projectionStrokeOpacity).attr("stroke-width",this.options.strokeWidth)}},{key:"draw",value:function(){if(!this._xScale||!this.yScale||!this.viewportXDomain||!this.viewportYDomain)return;const n=this._yScale(this.viewportYDomain[0]),C=this._yScale(this.viewportYDomain[1]),r=[n,C];this.brush.on("brush",null),this.gBrush.call(this.brush.move,r),this.brush.on("brush",this.brushed.bind(this))}},{key:"zoomed",value:function(n,C){this.xScale(n),this.yScale(C),this.draw()}},{key:"setPosition",value:function(n){ob(jc(I.prototype),"setPosition",this).call(this,n),this.draw()}},{key:"setDimensions",value:function(n){ob(jc(I.prototype),"setDimensions",this).call(this,n);const C=this._xScale.range(),r=this._yScale.range(),o=r[1]-r[0];this.brush.extent([[C[0],r[0]-o],[C[1],r[1]+o]]),this.gBrush.call(this.brush),this.draw()}}]),I}(vm);function Uoe(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function Qoe(g,e){for(var I=0;Ig[gJ]||g,VKt=(g,e)=>{const I=e(g);return I.prototype[tJ]=j1e(e),I},RKt=(g,e)=>g.hasOwnProperty(tJ)&&g[tJ]===j1e(e),WKt=(g,e)=>{for(;g!==null;){if(RKt(g,e))return!0;g=Object.getPrototypeOf(g)}return!1},n4=(g,e)=>(Object.setPrototypeOf(e,g),g[gJ]||(g[gJ]=g),e),iF="__mixwith_cachedApplications",XKt=g=>n4(g,e=>{let I=e[iF];I||(e[iF]=new Map,I=e[iF]);let i=I.get(g);return i||(i=g(e),I.set(g,i)),i}),HKt=g=>n4(g,e=>WKt(e.prototype,g)?e:g(e)),TKt=g=>n4(g,e=>VKt(e,g)),eY=g=>HKt(XKt(TKt(g)));let NKt=function(){function g(e){Uoe(this,g),this.superclass=e||function(){function I(){Uoe(this,I)}return joe(I)}()}return joe(g,[{key:"with",value:function(...I){return I.reduce((i,n)=>n(i),this.superclass)}}]),g}();const uy=g=>new NKt(g);function kKt(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function $oe(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function kh(g){return kh=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},kh(g)}const C4=eY(g=>function(e){FKt(i,e);var I=EKt(i);function i(n,C){var r;kKt(this,i),r=I.call(this,n,C);const{animate:o}=n;return r.highlighted=!1,r.animate=o,r.MOUSEOVER_RADIUS=4,r.pubSub=n.pubSub,r.pubSubs.push(r.pubSub.subscribe("app.mouseMove",r.mouseMoveHandler.bind($1e(r)))),r}return YKt(i,[{key:"setPosition",value:function(C){NB(kh(i.prototype),"setPosition",this).call(this,C),this.pMain.position.x=this.position[0],this.pMain.position.y=this.position[1]}},{key:"zoomed",value:function(C,r){NB(kh(i.prototype),"zoomed",this).call(this,C,r),this.draw()}},{key:"respondsToPosition",value:function(){return this.highlighted}}]),i}(g));function kB(){return typeof Reflect<"u"&&Reflect.get?kB=Reflect.get.bind():kB=function(e,I,i){var n=PKt(e,I);if(n){var C=Object.getOwnPropertyDescriptor(n,I);return C.get?C.get.call(arguments.length<3?e:i):C.value}},kB.apply(this,arguments)}function PKt(g,e){for(;!Object.prototype.hasOwnProperty.call(g,e)&&(g=Yh(g),g!==null););return g}function q1e(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function qoe(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function Yh(g){return Yh=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},Yh(g)}const QKt=eY(g=>function(e){tWe(i,e);var I=gWe(i);function i(){return q1e(this,i),I.apply(this,arguments)}return eWe(i,[{key:"drawHorizontalRule",value:function(C){let r=zt(this.options.color||"black");this.highlighted&&(r=zt("red")),C.lineStyle(this.strokeWidth,r,this.strokeOpacity);let o=0;for(;o"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function Kh(g){return Kh=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},Kh(g)}const oWe=eY(g=>function(e){CWe(i,e);var I=rWe(i);function i(){return iWe(this,i),I.apply(this,arguments)}return nWe(i,[{key:"drawVerticalRule",value:function(C){let r=zt(this.options.color||"black");this.highlighted&&(r=zt("red")),C.lineStyle(this.strokeWidth,r,this.strokeOpacity);let o=0;for(;o"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function xh(g){return xh=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},xh(g)}let aWe=function(g){o5t(I,g);var e=A5t(I);function I(i,n){var C;I5t(this,I),C=e.call(this,i,n);const{x:r,y:o}=i;return C.xPosition=r,C.yPosition=o,C.strokeWidth=2,C.strokeOpacity=1,C.dashLength=5,C.dashGap=3,C}return i5t(I,[{key:"draw",value:function(){const n=this.pMain;n.clear(),this.drawHorizontalRule(n),this.drawVerticalRule(n)}},{key:"mouseMoveHandler",value:function(n){this.highlighted=this.isWithin(n.x,n.y)&&(this.isMouseOverHorizontalLine(n)||this.isMouseOverVerticalLine(n)),this.draw()}},{key:"drawHorizontalRule",value:function(n){let C=zt(this.options.color||"black");this.highlighted&&(C=zt("red")),n.lineStyle(this.strokeWidth,C,this.strokeOpacity);let r=0;for(;r"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function Ia(g){return Ia=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},Ia(g)}let Xw=function(g){f5t(I,g);var e=p5t(I);function I(i,n){var C;c5t(this,I),C=e.call(this,i,n);const{animate:r}=i;return C.visibleTiles=new Set,C.visibleTileIds=new Set,C.fetching=new Set,C.fetchedTiles={},C.tileGraphics={},C.minX=typeof C.options.minPos<"u"&&!Number.isNaN(+C.options.minPos)?+C.options.minPos:-180,C.maxX=+C.options.maxPos||180,C.maxX=typeof C.options.maxPos<"u"&&!Number.isNaN(+C.options.maxPos)?+C.options.maxPos:180,C.minY=C.options.minY||C.minX,C.maxY=C.options.maxY||C.maxX,C.maxZoom=19,C.maxWidth=C.maxX-C.minX,C.animate=r,C.uuid=dg.nice(),C.refreshTilesDebounced=bQ(C.refreshTiles.bind(sWe(C)),E9),C}return u5t(I,[{key:"visibleAndFetchedIds",value:function(){return Object.keys(this.fetchedTiles).filter(n=>this.visibleTileIds.has(n))}},{key:"visibleAndFetchedTiles",value:function(){return this.visibleAndFetchedIds().map(n=>this.fetchedTiles[n])}},{key:"setVisibleTiles",value:function(n){this.visibleTiles=n.map(C=>({tileId:this.tileToLocalId(C),remoteId:this.tileToRemoteId(C),mirrored:C.mirrored})),this.visibleTileIds=new Set(this.visibleTiles.map(C=>C.tileId))}},{key:"removeAllTiles",value:function(){const n=new Set(Object.keys(this.fetchedTiles));this.removeTiles([...n])}},{key:"refreshTiles",value:function(){this.calculateVisibleTiles();const n=new Set(Object.keys(this.fetchedTiles)),C=[...this.visibleTiles].filter(o=>!this.fetching.has(o.remoteId)&&!n.has(o.tileId));for(let o=0;o!this.visibleTileIds.has(o));this.removeTiles(r),this.fetchNewTiles(C)}},{key:"removeTiles",value:function(n){n.length&&this.areAllVisibleTilesLoaded()&&(n.forEach(C=>{const r=C;this.destroyTile(this.fetchedTiles[r]),r in this.tileGraphics&&(this.pMain.removeChild(this.tileGraphics[r]),delete this.tileGraphics[r]),delete this.fetchedTiles[r]}),this.synchronizeTilesAndGraphics(),this.draw())}},{key:"tileToLocalId",value:function(n){return n.join(".")}},{key:"tileToRemoteId",value:function(n){return n.join(".")}},{key:"localToRemoteId",value:function(n){const C=n.split(".");return C.slice(0,C.length-1).join(".")}},{key:"calculateZoomLevel",value:function(){const n=vt.calculateZoomLevel(this._xScale,this.minX,this.maxX),C=vt.calculateZoomLevel(this._xScale,this.minY,this.maxY);let r=Math.min(Math.max(n,C),this.maxZoom);return this.options.maxZoom&&(this.options.maxZoom>=0?r=Math.min(this.options.maxZoom,r):console.error("Invalid maxZoom on track:",this)),r}},{key:"calculateVisibleTiles",value:function(){this.zoomLevel=this.calculateZoomLevel(),this.xTiles=vt.calculateTiles(this.zoomLevel,this._xScale,this.minX,this.maxX,this.maxZoom,this.maxWidth),this.yTiles=vt.calculateTiles(this.zoomLevel,this._yScale,this.minY,this.maxY,this.maxZoom,this.maxWidth);const n=this.xTiles,C=this.yTiles,r=this.zoomLevel,o=[];for(let A=0;A0){const C=[...new Set(n.map(r=>r.remoteId))];for(const r of C){const o=r.split("."),A=this.getTileUrl(o),s=new Image;s.crossOrigin="Anonymous",s.src=A,s.onload=()=>{const a={};a[r]={tileId:r,img:s,zoomLevel:+o[0],tilePos:[+o[1],+o[2]],tileSrc:A},this.receivedTiles(a)}}}}},{key:"receivedTiles",value:function(n){for(let C=0;C"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function m0(g){return m0=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},m0(g)}let lWe=function(g){w5t(I,g);var e=V5t(I);function I(){return Z5t(this,I),e.apply(this,arguments)}return G5t(I,[{key:"initTile",value:function(n){MRe.bind(this)(n),this.drawTile(n)}},{key:"drawTile",value:function(n){ERe.bind(this)(n)}},{key:"areAllVisibleTilesLoaded",value:function(){return!0}},{key:"fetchNewTiles",value:function(n){n.forEach(C=>{const o=C.remoteId.split("."),A={zoomLevel:o[0],tilePos:o.slice(1,o.length).map(s=>+s)};this.fetchedTiles[C.tileId]=C,this.fetchedTiles[C.tileId].tileData=A,this.fetching.has(C.remoteId)&&this.fetching.delete(C.remoteId)}),this.synchronizeTilesAndGraphics(),this.draw(),this.animate()}},{key:"draw",value:function(){TW(m0(I.prototype),"draw",this).call(this)}}]),I}(Xw);function H5t(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function iAe(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function f0(g){return f0=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},f0(g)}let cWe=function(g){K5t(I,g);var e=x5t(I);function I(i,n){var C;return H5t(this,I),C=e.call(this,i,n),C.style=n.style,C.options.accessToken||(C.errorTextText="No access token provided in the viewconf's track options ('accessToken' option).",C.drawError()),C}return T5t(I,[{key:"rerender",value:function(n){NW(f0(I.prototype),"rerender",this).call(this,n),n.style!==this.style&&(this.style=n.style,this.removeAllTiles(),this.refreshTiles())}},{key:"getTileUrl",value:function(n){const C=this.options&&this.options.style?this.options.style:"streets-v10",r=this.options&&+this.options.tileSize?+this.options.tileSize:256;return`https://api.mapbox.com/styles/v1/mapbox/${C}/tiles/${r}/${n[0]}/${n[1]}/${n[2]}?access_token=${this.options.accessToken}`}}]),I}(Xw);function M5t(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function nAe(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function RH(g){return RH=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},RH(g)}let uWe=function(g){O5t(I,g);var e=L5t(I);function I(i,n){var C;return M5t(this,I),C=e.call(this,i,n),C.style=n.style,C.options.tileSource||(C.errorTextText="No tile source string provided in the options. It should be in the form of http://a.com/{z}/{x}/{y}",C.drawError()),C}return z5t(I,[{key:"getTileUrl",value:function(n){let C=this.options.tileSource.replace("{z}",n[0]);return C=C.replace("{x}",n[1]),C=C.replace("{y}",n[2]),C}}]),I}(Xw);const j5t=(g,e,I,i=m2)=>{const n=I[g.type];return n?new n.dataFetcher(i,g,e):g.type==="genbank"?new DRe(g,e):g.type==="local-tiles"?new FRe(g,e):new Jk(g,e)};var _t=1e-6,nS=1e-12,lg=Math.PI,UI=lg/2,WH=lg/4,oC=lg*2,gI=180/lg,Qt=lg/180,Wg=Math.abs,dy=Math.atan,AC=Math.atan2,xt=Math.cos,PR=Math.ceil,dWe=Math.exp,sJ=Math.hypot,XH=Math.log,nF=Math.pow,Vt=Math.sin,$r=Math.sign||function(g){return g>0?1:g<0?-1:0},Li=Math.sqrt,r4=Math.tan;function hWe(g){return g>1?0:g<-1?lg:Math.acos(g)}function aC(g){return g>1?UI:g<-1?-UI:Math.asin(g)}function CAe(g){return(g=Vt(g/2))*g}function FI(){}function HH(g,e){g&&oAe.hasOwnProperty(g.type)&&oAe[g.type](g,e)}var rAe={Feature:function(g,e){HH(g.geometry,e)},FeatureCollection:function(g,e){for(var I=g.features,i=-1,n=I.length;++i=0?1:-1,n=i*I,C=xt(e),r=Vt(e),o=dJ*r,A=uJ*C+o*xt(n),s=o*i*Vt(n);TH.add(AC(s,A)),cJ=g,uJ=C,dJ=r}function txt(g){return NH=new Xi,jo(g,Ra),NH*2}function kH(g){return[AC(g[1],g[0]),aC(g[2])]}function Dh(g){var e=g[0],I=g[1],i=xt(I);return[i*xt(e),i*Vt(e),Vt(I)]}function JR(g,e){return g[0]*e[0]+g[1]*e[1]+g[2]*e[2]}function p0(g,e){return[g[1]*e[2]-g[2]*e[1],g[2]*e[0]-g[0]*e[2],g[0]*e[1]-g[1]*e[0]]}function CF(g,e){g[0]+=e[0],g[1]+=e[1],g[2]+=e[2]}function OR(g,e){return[g[0]*e,g[1]*e,g[2]*e]}function YH(g){var e=Li(g[0]*g[0]+g[1]*g[1]+g[2]*g[2]);g[0]/=e,g[1]/=e,g[2]/=e}var KI,WC,LI,ir,Cd,bWe,yWe,Ab,xB,Ic,el,ls={point:hJ,lineStart:aAe,lineEnd:sAe,polygonStart:function(){ls.point=GWe,ls.lineStart=gxt,ls.lineEnd=Ixt,xB=new Xi,Ra.polygonStart()},polygonEnd:function(){Ra.polygonEnd(),ls.point=hJ,ls.lineStart=aAe,ls.lineEnd=sAe,TH<0?(KI=-(LI=180),WC=-(ir=90)):xB>_t?ir=90:xB<-_t&&(WC=-90),el[0]=KI,el[1]=LI},sphere:function(){KI=-(LI=180),WC=-(ir=90)}};function hJ(g,e){Ic.push(el=[KI=g,LI=g]),eir&&(ir=e)}function ZWe(g,e){var I=Dh([g*Qt,e*Qt]);if(Ab){var i=p0(Ab,I),n=[i[1],-i[0],0],C=p0(n,i);YH(C),C=kH(C);var r=g-Cd,o=r>0?1:-1,A=C[0]*gI*o,s,a=Wg(r)>180;a^(o*Cdir&&(ir=s)):(A=(A+360)%360-180,a^(o*Cdir&&(ir=e))),a?ger(KI,LI)&&(LI=g):er(g,LI)>er(KI,LI)&&(KI=g):LI>=KI?(gLI&&(LI=g)):g>Cd?er(KI,g)>er(KI,LI)&&(LI=g):er(g,LI)>er(KI,LI)&&(KI=g)}else Ic.push(el=[KI=g,LI=g]);eir&&(ir=e),Ab=I,Cd=g}function aAe(){ls.point=ZWe}function sAe(){el[0]=KI,el[1]=LI,ls.point=hJ,Ab=null}function GWe(g,e){if(Ab){var I=g-Cd;xB.add(Wg(I)>180?I+(I>0?360:-360):I)}else bWe=g,yWe=e;Ra.point(g,e),ZWe(g,e)}function gxt(){Ra.lineStart()}function Ixt(){GWe(bWe,yWe),Ra.lineEnd(),Wg(xB)>_t&&(KI=-(LI=180)),el[0]=KI,el[1]=LI,Ab=null}function er(g,e){return(e-=g)<0?e+360:e}function ixt(g,e){return g[0]-e[0]}function lAe(g,e){return g[0]<=g[1]?g[0]<=e&&e<=g[1]:eer(i[0],i[1])&&(i[1]=n[1]),er(n[0],i[1])>er(i[0],i[1])&&(i[0]=n[0])):C.push(i=n);for(r=-1/0,I=C.length-1,e=0,i=C[I];e<=I;i=n,++e)n=C[e],(o=er(i[1],n[0]))>r&&(r=o,KI=n[0],LI=i[1])}return Ic=el=null,KI===1/0||WC===1/0?[[NaN,NaN],[NaN,NaN]]:[[KI,WC],[LI,ir]]}var uG,KH,xH,DH,FH,EH,MH,zH,mJ,fJ,pJ,BWe,vWe,$n,qn,eC,gA={sphere:FI,point:o4,lineStart:cAe,lineEnd:uAe,polygonStart:function(){gA.lineStart=oxt,gA.lineEnd=Axt},polygonEnd:function(){gA.lineStart=cAe,gA.lineEnd=uAe}};function o4(g,e){g*=Qt,e*=Qt;var I=xt(e);Hw(I*xt(g),I*Vt(g),Vt(e))}function Hw(g,e,I){++uG,xH+=(g-xH)/uG,DH+=(e-DH)/uG,FH+=(I-FH)/uG}function cAe(){gA.point=Cxt}function Cxt(g,e){g*=Qt,e*=Qt;var I=xt(e);$n=I*xt(g),qn=I*Vt(g),eC=Vt(e),gA.point=rxt,Hw($n,qn,eC)}function rxt(g,e){g*=Qt,e*=Qt;var I=xt(e),i=I*xt(g),n=I*Vt(g),C=Vt(e),r=AC(Li((r=qn*C-eC*n)*r+(r=eC*i-$n*C)*r+(r=$n*n-qn*i)*r),$n*i+qn*n+eC*C);KH+=r,EH+=r*($n+($n=i)),MH+=r*(qn+(qn=n)),zH+=r*(eC+(eC=C)),Hw($n,qn,eC)}function uAe(){gA.point=o4}function oxt(){gA.point=axt}function Axt(){SWe(BWe,vWe),gA.point=o4}function axt(g,e){BWe=g,vWe=e,g*=Qt,e*=Qt,gA.point=SWe;var I=xt(e);$n=I*xt(g),qn=I*Vt(g),eC=Vt(e),Hw($n,qn,eC)}function SWe(g,e){g*=Qt,e*=Qt;var I=xt(e),i=I*xt(g),n=I*Vt(g),C=Vt(e),r=qn*C-eC*n,o=eC*i-$n*C,A=$n*n-qn*i,s=sJ(r,o,A),a=aC(s),l=s&&-a/s;mJ.add(l*r),fJ.add(l*o),pJ.add(l*A),KH+=a,EH+=a*($n+($n=i)),MH+=a*(qn+(qn=n)),zH+=a*(eC+(eC=C)),Hw($n,qn,eC)}function sxt(g){uG=KH=xH=DH=FH=EH=MH=zH=0,mJ=new Xi,fJ=new Xi,pJ=new Xi,jo(g,gA);var e=+mJ,I=+fJ,i=+pJ,n=sJ(e,I,i);return nlg?g+Math.round(-g/oC)*oC:g,e]}yJ.invert=yJ;function A4(g,e,I){return(g%=oC)?e||I?bJ(hAe(g),mAe(e,I)):hAe(g):e||I?mAe(e,I):yJ}function dAe(g){return function(e,I){return e+=g,[e>lg?e-oC:e<-lg?e+oC:e,I]}}function hAe(g){var e=dAe(g);return e.invert=dAe(-g),e}function mAe(g,e){var I=xt(g),i=Vt(g),n=xt(e),C=Vt(e);function r(o,A){var s=xt(A),a=xt(o)*s,l=Vt(o)*s,c=Vt(A),u=c*I+a*i;return[AC(l*n-u*C,a*I-c*i),aC(u*n+l*C)]}return r.invert=function(o,A){var s=xt(A),a=xt(o)*s,l=Vt(o)*s,c=Vt(A),u=c*n-l*C;return[AC(l*n+c*C,a*I+u*i),aC(u*I-a*i)]},r}function wWe(g){g=A4(g[0]*Qt,g[1]*Qt,g.length>2?g[2]*Qt:0);function e(I){return I=g(I[0]*Qt,I[1]*Qt),I[0]*=gI,I[1]*=gI,I}return e.invert=function(I){return I=g.invert(I[0]*Qt,I[1]*Qt),I[0]*=gI,I[1]*=gI,I},e}function VWe(g,e,I,i,n,C){if(I){var r=xt(e),o=Vt(e),A=i*I;n==null?(n=e+i*oC,C=e-A/2):(n=fAe(r,n),C=fAe(r,C),(i>0?nC)&&(n+=i*oC));for(var s,a=n;i>0?a>C:a1&&g.push(g.pop().concat(g.shift()))},result:function(){var I=g;return g=[],e=null,I}}}function kW(g,e){return Wg(g[0]-e[0])<_t&&Wg(g[1]-e[1])<_t}function LR(g,e,I,i){this.x=g,this.z=e,this.o=I,this.e=i,this.v=!1,this.n=this.p=null}function WWe(g,e,I,i,n){var C=[],r=[],o,A;if(g.forEach(function(d){if(!((h=d.length-1)<=0)){var h,m=d[0],f=d[h],b;if(kW(m,f)){if(!m[2]&&!f[2]){for(n.lineStart(),o=0;o=0;--o)n.point((l=a[o])[0],l[1]);else i(c.x,c.p.x,-1,n);c=c.p}c=c.o,a=c.z,u=!u}while(!c.v);n.lineEnd()}}}function pAe(g){if(e=g.length){for(var e,I=0,i=g[0],n;++I=0?1:-1,R=w*B,S=R>lg,X=m*v;if(A.add(AC(X*w*Vt(R),f*G+X*xt(R))),r+=S?B+w*oC:B,S^d>=I^y>=I){var W=p0(Dh(u),Dh(p));YH(W);var V=p0(C,W);YH(V);var H=(S^B>=0?-1:1)*aC(V[2]);(i>H||i===H&&(W[0]||W[1]))&&(o+=S^B>=0?1:-1)}}return(r<-_t||r<_t&&A<-nS)^o&1}function HWe(g,e,I,i){return function(n){var C=e(n),r=RWe(),o=e(r),A=!1,s,a,l,c={point:u,lineStart:h,lineEnd:m,polygonStart:function(){c.point=f,c.lineStart=b,c.lineEnd=p,a=[],s=[]},polygonEnd:function(){c.point=u,c.lineStart=h,c.lineEnd=m,a=b7(a);var y=XWe(s,i);a.length?(A||(n.polygonStart(),A=!0),WWe(a,uxt,y,I,n)):y&&(A||(n.polygonStart(),A=!0),n.lineStart(),I(null,null,1,n),n.lineEnd()),A&&(n.polygonEnd(),A=!1),a=s=null},sphere:function(){n.polygonStart(),n.lineStart(),I(null,null,1,n),n.lineEnd(),n.polygonEnd()}};function u(y,Z){g(y,Z)&&n.point(y,Z)}function d(y,Z){C.point(y,Z)}function h(){c.point=d,C.lineStart()}function m(){c.point=u,C.lineEnd()}function f(y,Z){l.push([y,Z]),o.point(y,Z)}function b(){o.lineStart(),l=[]}function p(){f(l[0][0],l[0][1]),o.lineEnd();var y=o.clean(),Z=r.result(),v,G=Z.length,B,w,R;if(l.pop(),s.push(l),l=null,!!G){if(y&1){if(w=Z[0],(B=w.length-1)>0){for(A||(n.polygonStart(),A=!0),n.lineStart(),v=0;v1&&y&2&&Z.push(Z.pop().concat(Z.shift())),a.push(Z.filter(cxt))}}return c}}function cxt(g){return g.length>1}function uxt(g,e){return((g=g.x)[0]<0?g[1]-UI-_t:UI-g[1])-((e=e.x)[0]<0?e[1]-UI-_t:UI-e[1])}const ZJ=HWe(function(){return!0},dxt,mxt,[-lg,-UI]);function dxt(g){var e=NaN,I=NaN,i=NaN,n;return{lineStart:function(){g.lineStart(),n=1},point:function(C,r){var o=C>0?lg:-lg,A=Wg(C-e);Wg(A-lg)<_t?(g.point(e,I=(I+r)/2>0?UI:-UI),g.point(i,I),g.lineEnd(),g.lineStart(),g.point(o,I),g.point(C,I),n=0):i!==o&&A>=lg&&(Wg(e-i)<_t&&(e-=i*_t),Wg(C-o)<_t&&(C-=o*_t),I=hxt(e,I,C,r),g.point(i,I),g.lineEnd(),g.lineStart(),g.point(o,I),n=0),g.point(e=C,I=r),i=o},lineEnd:function(){g.lineEnd(),e=I=NaN},clean:function(){return 2-n}}}function hxt(g,e,I,i){var n,C,r=Vt(g-I);return Wg(r)>_t?dy((Vt(e)*(C=xt(i))*Vt(I)-Vt(i)*(n=xt(e))*Vt(g))/(n*C*r)):(e+i)/2}function mxt(g,e,I,i){var n;if(g==null)n=I*UI,i.point(-lg,n),i.point(0,n),i.point(lg,n),i.point(lg,0),i.point(lg,-n),i.point(0,-n),i.point(-lg,-n),i.point(-lg,0),i.point(-lg,n);else if(Wg(g[0]-e[0])>_t){var C=g[0]0,n=Wg(e)>_t;function C(a,l,c,u){VWe(u,g,I,c,a,l)}function r(a,l){return xt(a)*xt(l)>e}function o(a){var l,c,u,d,h;return{lineStart:function(){d=u=!1,h=1},point:function(m,f){var b=[m,f],p,y=r(m,f),Z=i?y?0:s(m,f):y?s(m+(m<0?lg:-lg),f):0;if(!l&&(d=u=y)&&a.lineStart(),y!==u&&(p=A(l,b),(!p||kW(l,p)||kW(b,p))&&(b[2]=1)),y!==u)h=0,y?(a.lineStart(),p=A(b,l),a.point(p[0],p[1])):(p=A(l,b),a.point(p[0],p[1],2),a.lineEnd()),l=p;else if(n&&l&&i^y){var v;!(Z&c)&&(v=A(b,l,!0))&&(h=0,i?(a.lineStart(),a.point(v[0][0],v[0][1]),a.point(v[1][0],v[1][1]),a.lineEnd()):(a.point(v[1][0],v[1][1]),a.lineEnd(),a.lineStart(),a.point(v[0][0],v[0][1],3)))}y&&(!l||!kW(l,b))&&a.point(b[0],b[1]),l=b,u=y,c=Z},lineEnd:function(){u&&a.lineEnd(),l=null},clean:function(){return h|(d&&u)<<1}}}function A(a,l,c){var u=Dh(a),d=Dh(l),h=[1,0,0],m=p0(u,d),f=JR(m,m),b=m[0],p=f-b*b;if(!p)return!c&&a;var y=e*f/p,Z=-e*b/p,v=p0(h,m),G=OR(h,y),B=OR(m,Z);CF(G,B);var w=v,R=JR(G,w),S=JR(w,w),X=R*R-S*(JR(G,G)-1);if(!(X<0)){var W=Li(X),V=OR(w,(-R-W)/S);if(CF(V,G),V=kH(V),!c)return V;var H=a[0],D=l[0],Y=a[1],F=l[1],_;D0^V[1]<(Wg(V[0]-H)<_t?Y:F):Y<=V[1]&&V[1]<=F:J>lg^(H<=V[0]&&V[0]<=D)){var $=OR(w,(-R+W)/S);return CF($,G),[V,kH($)]}}}function s(a,l){var c=i?g:lg-g,u=0;return a<-c?u|=1:a>c&&(u|=2),l<-c?u|=4:l>c&&(u|=8),u}return HWe(r,o,C,i?[0,-g]:[-lg,g-lg])}function fxt(g,e,I,i,n,C){var r=g[0],o=g[1],A=e[0],s=e[1],a=0,l=1,c=A-r,u=s-o,d;if(d=I-r,!(!c&&d>0)){if(d/=c,c<0){if(d0){if(d>l)return;d>a&&(a=d)}if(d=n-r,!(!c&&d<0)){if(d/=c,c<0){if(d>l)return;d>a&&(a=d)}else if(c>0){if(d0)){if(d/=u,u<0){if(d0){if(d>l)return;d>a&&(a=d)}if(d=C-o,!(!u&&d<0)){if(d/=u,u<0){if(d>l)return;d>a&&(a=d)}else if(u>0){if(d0&&(g[0]=r+a*c,g[1]=o+a*u),l<1&&(e[0]=r+l*c,e[1]=o+l*u),!0}}}}}var dG=1e9,_R=-dG;function tY(g,e,I,i){function n(s,a){return g<=s&&s<=I&&e<=a&&a<=i}function C(s,a,l,c){var u=0,d=0;if(s==null||(u=r(s,l))!==(d=r(a,l))||A(s,a)<0^l>0)do c.point(u===0||u===3?g:I,u>1?i:e);while((u=(u+l+4)%4)!==d);else c.point(a[0],a[1])}function r(s,a){return Wg(s[0]-g)<_t?a>0?0:3:Wg(s[0]-I)<_t?a>0?2:1:Wg(s[1]-e)<_t?a>0?1:0:a>0?3:2}function o(s,a){return A(s.x,a.x)}function A(s,a){var l=r(s,1),c=r(a,1);return l!==c?l-c:l===0?a[1]-s[1]:l===1?s[0]-a[0]:l===2?s[1]-a[1]:a[0]-s[0]}return function(s){var a=s,l=RWe(),c,u,d,h,m,f,b,p,y,Z,v,G={point:B,lineStart:X,lineEnd:W,polygonStart:R,polygonEnd:S};function B(H,D){n(H,D)&&a.point(H,D)}function w(){for(var H=0,D=0,Y=u.length;Di&&(j-q)*(i-$)>(ee-$)*(g-q)&&++H:ee<=i&&(j-q)*(i-$)<(ee-$)*(g-q)&&--H;return H}function R(){a=l,c=[],u=[],v=!0}function S(){var H=w(),D=v&&H,Y=(c=b7(c)).length;(D||Y)&&(s.polygonStart(),D&&(s.lineStart(),C(null,null,1,s),s.lineEnd()),Y&&WWe(c,o,H,C,s),s.polygonEnd()),a=s,c=u=d=null}function X(){G.point=V,u&&u.push(d=[]),Z=!0,y=!1,b=p=NaN}function W(){c&&(V(h,m),f&&y&&l.rejoin(),c.push(l.result())),G.point=B,y&&a.lineEnd()}function V(H,D){var Y=n(H,D);if(u&&d.push([H,D]),Z)h=H,m=D,f=Y,Z=!1,Y&&(a.lineStart(),a.point(H,D));else if(Y&&y)a.point(H,D);else{var F=[b=Math.max(_R,Math.min(dG,b)),p=Math.max(_R,Math.min(dG,p))],_=[H=Math.max(_R,Math.min(dG,H)),D=Math.max(_R,Math.min(dG,D))];fxt(F,_,g,e,I,i)?(y||(a.lineStart(),a.point(F[0],F[1])),a.point(_[0],_[1]),Y||a.lineEnd(),v=!1):Y&&(a.lineStart(),a.point(H,D),v=!1)}b=H,p=D,y=Y}return G}}function pxt(){var g=0,e=0,I=960,i=500,n,C,r;return r={stream:function(o){return n&&C===o?n:n=tY(g,e,I,i)(C=o)},extent:function(o){return arguments.length?(g=+o[0][0],e=+o[0][1],I=+o[1][0],i=+o[1][1],n=C=null,r):[[g,e],[I,i]]}}}var GJ,BJ,YW,KW,b0={sphere:FI,point:FI,lineStart:bxt,lineEnd:FI,polygonStart:FI,polygonEnd:FI};function bxt(){b0.point=Zxt,b0.lineEnd=yxt}function yxt(){b0.point=b0.lineEnd=FI}function Zxt(g,e){g*=Qt,e*=Qt,BJ=g,YW=Vt(e),KW=xt(e),b0.point=Gxt}function Gxt(g,e){g*=Qt,e*=Qt;var I=Vt(e),i=xt(e),n=Wg(g-BJ),C=xt(n),r=Vt(n),o=i*r,A=KW*I-YW*i*C,s=YW*I+KW*i*C;GJ.add(AC(Li(o*o+A*A),s)),BJ=g,YW=I,KW=i}function NWe(g){return GJ=new Xi,jo(g,b0),+GJ}var vJ=[null,null],Bxt={type:"LineString",coordinates:vJ};function PH(g,e){return vJ[0]=g,vJ[1]=e,NWe(Bxt)}var bAe={Feature:function(g,e){return JH(g.geometry,e)},FeatureCollection:function(g,e){for(var I=g.features,i=-1,n=I.length;++i0&&(n=PH(g[C],g[C-1]),n>0&&I<=n&&i<=n&&(I+i-n)*(1-Math.pow((I-i)/n,2))_t}).map(c)).concat(iC(PR(C/s)*s,n,s).filter(function(p){return Wg(p%l)>_t}).map(u))}return f.lines=function(){return b().map(function(p){return{type:"LineString",coordinates:p}})},f.outline=function(){return{type:"Polygon",coordinates:[d(i).concat(h(r).slice(1),d(I).reverse().slice(1),h(o).reverse().slice(1))]}},f.extent=function(p){return arguments.length?f.extentMajor(p).extentMinor(p):f.extentMinor()},f.extentMajor=function(p){return arguments.length?(i=+p[0][0],I=+p[1][0],o=+p[0][1],r=+p[1][1],i>I&&(p=i,i=I,I=p),o>r&&(p=o,o=r,r=p),f.precision(m)):[[i,o],[I,r]]},f.extentMinor=function(p){return arguments.length?(e=+p[0][0],g=+p[1][0],C=+p[0][1],n=+p[1][1],e>g&&(p=e,e=g,g=p),C>n&&(p=C,C=n,n=p),f.precision(m)):[[e,C],[g,n]]},f.step=function(p){return arguments.length?f.stepMajor(p).stepMinor(p):f.stepMinor()},f.stepMajor=function(p){return arguments.length?(a=+p[0],l=+p[1],f):[a,l]},f.stepMinor=function(p){return arguments.length?(A=+p[0],s=+p[1],f):[A,s]},f.precision=function(p){return arguments.length?(m=+p,c=vAe(C,n,90),u=SAe(e,g,m),d=vAe(o,r,90),h=SAe(i,I,m),f):m},f.extentMajor([[-180,-90+_t],[180,90-_t]]).extentMinor([[-180,-80-_t],[180,80+_t]])}function wxt(){return YWe()()}function Vxt(g,e){var I=g[0]*Qt,i=g[1]*Qt,n=e[0]*Qt,C=e[1]*Qt,r=xt(i),o=Vt(i),A=xt(C),s=Vt(C),a=r*xt(I),l=r*Vt(I),c=A*xt(n),u=A*Vt(n),d=2*aC(Li(CAe(C-i)+r*A*CAe(n-I))),h=Vt(d),m=d?function(f){var b=Vt(f*=d)/h,p=Vt(d-f)/h,y=p*a+b*c,Z=p*l+b*u,v=p*o+b*s;return[AC(Z,y)*gI,AC(v,Li(y*y+Z*Z))*gI]}:function(){return[I*gI,i*gI]};return m.distance=d,m}const CS=g=>g;var oF=new Xi,SJ=new Xi,KWe,xWe,wJ,VJ,mc={point:FI,lineStart:FI,lineEnd:FI,polygonStart:function(){mc.lineStart=Rxt,mc.lineEnd=Xxt},polygonEnd:function(){mc.lineStart=mc.lineEnd=mc.point=FI,oF.add(Wg(SJ)),SJ=new Xi},result:function(){var g=oF/2;return oF=new Xi,g}};function Rxt(){mc.point=Wxt}function Wxt(g,e){mc.point=DWe,KWe=wJ=g,xWe=VJ=e}function DWe(g,e){SJ.add(VJ*g-wJ*e),wJ=g,VJ=e}function Xxt(){DWe(KWe,xWe)}const wAe=mc;var y0=1/0,OH=y0,rS=-y0,LH=rS,Hxt={point:Txt,lineStart:FI,lineEnd:FI,polygonStart:FI,polygonEnd:FI,result:function(){var g=[[y0,OH],[rS,LH]];return rS=LH=-(OH=y0=1/0),g}};function Txt(g,e){grS&&(rS=g),eLH&&(LH=e)}const _H=Hxt;var RJ=0,WJ=0,hG=0,UH=0,QH=0,vp=0,XJ=0,HJ=0,mG=0,FWe,EWe,ia,na,$o={point:Fh,lineStart:VAe,lineEnd:RAe,polygonStart:function(){$o.lineStart=Yxt,$o.lineEnd=Kxt},polygonEnd:function(){$o.point=Fh,$o.lineStart=VAe,$o.lineEnd=RAe},result:function(){var g=mG?[XJ/mG,HJ/mG]:vp?[UH/vp,QH/vp]:hG?[RJ/hG,WJ/hG]:[NaN,NaN];return RJ=WJ=hG=UH=QH=vp=XJ=HJ=mG=0,g}};function Fh(g,e){RJ+=g,WJ+=e,++hG}function VAe(){$o.point=Nxt}function Nxt(g,e){$o.point=kxt,Fh(ia=g,na=e)}function kxt(g,e){var I=g-ia,i=e-na,n=Li(I*I+i*i);UH+=n*(ia+g)/2,QH+=n*(na+e)/2,vp+=n,Fh(ia=g,na=e)}function RAe(){$o.point=Fh}function Yxt(){$o.point=xxt}function Kxt(){MWe(FWe,EWe)}function xxt(g,e){$o.point=MWe,Fh(FWe=ia=g,EWe=na=e)}function MWe(g,e){var I=g-ia,i=e-na,n=Li(I*I+i*i);UH+=n*(ia+g)/2,QH+=n*(na+e)/2,vp+=n,n=na*g-ia*e,XJ+=n*(ia+g),HJ+=n*(na+e),mG+=n*3,Fh(ia=g,na=e)}const WAe=$o;function zWe(g){this._context=g}zWe.prototype={_radius:4.5,pointRadius:function(g){return this._radius=g,this},polygonStart:function(){this._line=0},polygonEnd:function(){this._line=NaN},lineStart:function(){this._point=0},lineEnd:function(){this._line===0&&this._context.closePath(),this._point=NaN},point:function(g,e){switch(this._point){case 0:{this._context.moveTo(g,e),this._point=1;break}case 1:{this._context.lineTo(g,e);break}default:{this._context.moveTo(g+this._radius,e),this._context.arc(g,e,this._radius,0,oC);break}}},result:FI};var TJ=new Xi,AF,PWe,JWe,fG,pG,jH={point:FI,lineStart:function(){jH.point=Dxt},lineEnd:function(){AF&&OWe(PWe,JWe),jH.point=FI},polygonStart:function(){AF=!0},polygonEnd:function(){AF=null},result:function(){var g=+TJ;return TJ=new Xi,g}};function Dxt(g,e){jH.point=OWe,PWe=fG=g,JWe=pG=e}function OWe(g,e){fG-=g,pG-=e,TJ.add(Li(fG*fG+pG*pG)),fG=g,pG=e}const XAe=jH;function LWe(){this._string=[]}LWe.prototype={_radius:4.5,_circle:HAe(4.5),pointRadius:function(g){return(g=+g)!==this._radius&&(this._radius=g,this._circle=null),this},polygonStart:function(){this._line=0},polygonEnd:function(){this._line=NaN},lineStart:function(){this._point=0},lineEnd:function(){this._line===0&&this._string.push("Z"),this._point=NaN},point:function(g,e){switch(this._point){case 0:{this._string.push("M",g,",",e),this._point=1;break}case 1:{this._string.push("L",g,",",e);break}default:{this._circle==null&&(this._circle=HAe(this._radius)),this._string.push("M",g,",",e,this._circle);break}}},result:function(){if(this._string.length){var g=this._string.join("");return this._string=[],g}else return null}};function HAe(g){return"m0,"+g+"a"+g+","+g+" 0 1,1 0,"+-2*g+"a"+g+","+g+" 0 1,1 0,"+2*g+"z"}function Fxt(g,e){var I=4.5,i,n;function C(r){return r&&(typeof I=="function"&&n.pointRadius(+I.apply(this,arguments)),jo(r,i(n))),n.result()}return C.area=function(r){return jo(r,i(wAe)),wAe.result()},C.measure=function(r){return jo(r,i(XAe)),XAe.result()},C.bounds=function(r){return jo(r,i(_H)),_H.result()},C.centroid=function(r){return jo(r,i(WAe)),WAe.result()},C.projection=function(r){return arguments.length?(i=r==null?(g=null,CS):(g=r).stream,C):g},C.context=function(r){return arguments.length?(n=r==null?(e=null,new LWe):new zWe(e=r),typeof I!="function"&&n.pointRadius(I),C):e},C.pointRadius=function(r){return arguments.length?(I=typeof r=="function"?r:(n.pointRadius(+r),+r),C):I},C.projection(g).context(e)}function Ext(g){return{stream:Tw(g)}}function Tw(g){return function(e){var I=new NJ;for(var i in g)I[i]=g[i];return I.stream=e,I}}function NJ(){}NJ.prototype={constructor:NJ,point:function(g,e){this.stream.point(g,e)},sphere:function(){this.stream.sphere()},lineStart:function(){this.stream.lineStart()},lineEnd:function(){this.stream.lineEnd()},polygonStart:function(){this.stream.polygonStart()},polygonEnd:function(){this.stream.polygonEnd()}};function a4(g,e,I){var i=g.clipExtent&&g.clipExtent();return g.scale(150).translate([0,0]),i!=null&&g.clipExtent(null),jo(I,g.stream(_H)),e(_H.result()),i!=null&&g.clipExtent(i),g}function gY(g,e,I){return a4(g,function(i){var n=e[1][0]-e[0][0],C=e[1][1]-e[0][1],r=Math.min(n/(i[1][0]-i[0][0]),C/(i[1][1]-i[0][1])),o=+e[0][0]+(n-r*(i[1][0]+i[0][0]))/2,A=+e[0][1]+(C-r*(i[1][1]+i[0][1]))/2;g.scale(150*r).translate([o,A])},I)}function s4(g,e,I){return gY(g,[[0,0],e],I)}function l4(g,e,I){return a4(g,function(i){var n=+e,C=n/(i[1][0]-i[0][0]),r=(n-C*(i[1][0]+i[0][0]))/2,o=-C*i[0][1];g.scale(150*C).translate([r,o])},I)}function c4(g,e,I){return a4(g,function(i){var n=+e,C=n/(i[1][1]-i[0][1]),r=-C*i[0][0],o=(n-C*(i[1][1]+i[0][1]))/2;g.scale(150*C).translate([r,o])},I)}var TAe=16,Mxt=xt(30*Qt);function NAe(g,e){return+e?Pxt(g,e):zxt(g)}function zxt(g){return Tw({point:function(e,I){e=g(e,I),this.stream.point(e[0],e[1])}})}function Pxt(g,e){function I(i,n,C,r,o,A,s,a,l,c,u,d,h,m){var f=s-i,b=a-n,p=f*f+b*b;if(p>4*e&&h--){var y=r+c,Z=o+u,v=A+d,G=Li(y*y+Z*Z+v*v),B=aC(v/=G),w=Wg(Wg(v)-1)<_t||Wg(C-l)<_t?(C+l)/2:AC(Z,y),R=g(w,B),S=R[0],X=R[1],W=S-i,V=X-n,H=b*W-f*V;(H*H/p>e||Wg((f*W+b*V)/p-.5)>.3||r*c+o*u+A*d2?H[2]%360*Qt:0,W()):[o*gI,A*gI,s*gI]},S.angle=function(H){return arguments.length?(l=H%360*Qt,W()):l*gI},S.reflectX=function(H){return arguments.length?(c=H?-1:1,W()):c<0},S.reflectY=function(H){return arguments.length?(u=H?-1:1,W()):u<0},S.precision=function(H){return arguments.length?(v=NAe(G,Z=H*H),V()):Li(Z)},S.fitExtent=function(H,D){return gY(S,H,D)},S.fitSize=function(H,D){return s4(S,H,D)},S.fitWidth=function(H,D){return l4(S,H,D)},S.fitHeight=function(H,D){return c4(S,H,D)};function W(){var H=kAe(I,0,0,c,u,l).apply(null,e(C,r)),D=kAe(I,i-H[0],n-H[1],c,u,l);return a=A4(o,A,s),G=bJ(e,D),B=bJ(a,G),v=NAe(G,Z),V()}function V(){return w=R=null,S}return function(){return e=g.apply(this,arguments),S.invert=e.invert&&X,W()}}function d4(g){var e=0,I=lg/3,i=u4(g),n=i(e,I);return n.parallels=function(C){return arguments.length?i(e=C[0]*Qt,I=C[1]*Qt):[e*gI,I*gI]},n}function _xt(g){var e=xt(g);function I(i,n){return[i*e,Vt(n)/e]}return I.invert=function(i,n){return[i/e,aC(n*e)]},I}function _We(g,e){var I=Vt(g),i=(I+Vt(e))/2;if(Wg(i)<_t)return _xt(g);var n=1+I*(2*i-I),C=Li(n)/i;function r(o,A){var s=Li(n-2*i*Vt(A))/i;return[s*Vt(o*=i),C-s*xt(o)]}return r.invert=function(o,A){var s=C-A,a=AC(o,Wg(s))*$r(s);return s*i<0&&(a-=lg*$r(o)*$r(s)),[a/i,aC((n-(o*o+s*s)*i*i)/(2*i))]},r}function $H(){return d4(_We).scale(155.424).center([0,33.6442])}function UWe(){return $H().parallels([29.5,45.5]).scale(1070).translate([480,250]).rotate([96,0]).center([-.6,38.7])}function Uxt(g){var e=g.length;return{point:function(I,i){for(var n=-1;++n=.12&&m<.234&&h>=-.425&&h<-.214?n:m>=.166&&m<.234&&h>=-.214&&h<-.115?r:I).invert(c)},a.stream=function(c){return g&&e===c?g:g=Uxt([I.stream(e=c),n.stream(c),r.stream(c)])},a.precision=function(c){return arguments.length?(I.precision(c),n.precision(c),r.precision(c),l()):I.precision()},a.scale=function(c){return arguments.length?(I.scale(c),n.scale(c*.35),r.scale(c),a.translate(I.translate())):I.scale()},a.translate=function(c){if(!arguments.length)return I.translate();var u=I.scale(),d=+c[0],h=+c[1];return i=I.translate(c).clipExtent([[d-.455*u,h-.238*u],[d+.455*u,h+.238*u]]).stream(s),C=n.translate([d-.307*u,h+.201*u]).clipExtent([[d-.425*u+_t,h+.12*u+_t],[d-.214*u-_t,h+.234*u-_t]]).stream(s),o=r.translate([d-.205*u,h+.212*u]).clipExtent([[d-.214*u+_t,h+.166*u+_t],[d-.115*u-_t,h+.234*u-_t]]).stream(s),l()},a.fitExtent=function(c,u){return gY(a,c,u)},a.fitSize=function(c,u){return s4(a,c,u)},a.fitWidth=function(c,u){return l4(a,c,u)},a.fitHeight=function(c,u){return c4(a,c,u)};function l(){return g=e=null,a}return a.scale(1070)}function QWe(g){return function(e,I){var i=xt(e),n=xt(I),C=g(i*n);return C===1/0?[2,0]:[C*n*Vt(e),C*Vt(I)]}}function Nw(g){return function(e,I){var i=Li(e*e+I*I),n=g(i),C=Vt(n),r=xt(n);return[AC(e*C,i*r),aC(i&&I*C/i)]}}var h4=QWe(function(g){return Li(2/(1+g))});h4.invert=Nw(function(g){return 2*aC(g/2)});function jxt(){return xa(h4).scale(124.75).clipAngle(180-.001)}var m4=QWe(function(g){return(g=hWe(g))&&g/Vt(g)});m4.invert=Nw(function(g){return g});function $xt(){return xa(m4).scale(79.4188).clipAngle(180-.001)}function kw(g,e){return[g,XH(r4((UI+e)/2))]}kw.invert=function(g,e){return[g,2*dy(dWe(e))-UI]};function qxt(){return jWe(kw).scale(961/oC)}function jWe(g){var e=xa(g),I=e.center,i=e.scale,n=e.translate,C=e.clipExtent,r=null,o,A,s;e.scale=function(l){return arguments.length?(i(l),a()):i()},e.translate=function(l){return arguments.length?(n(l),a()):n()},e.center=function(l){return arguments.length?(I(l),a()):I()},e.clipExtent=function(l){return arguments.length?(l==null?r=o=A=s=null:(r=+l[0][0],o=+l[0][1],A=+l[1][0],s=+l[1][1]),a()):r==null?null:[[r,o],[A,s]]};function a(){var l=lg*i(),c=e(wWe(e.rotate()).invert([0,0]));return C(r==null?[[c[0]-l,c[1]-l],[c[0]+l,c[1]+l]]:g===kw?[[Math.max(c[0]-l,r),o],[Math.min(c[0]+l,A),s]]:[[r,Math.max(c[1]-l,o)],[A,Math.min(c[1]+l,s)]])}return a()}function UR(g){return r4((UI+g)/2)}function $We(g,e){var I=xt(g),i=g===e?Vt(g):XH(I/xt(e))/XH(UR(e)/UR(g)),n=I*nF(UR(g),i)/i;if(!i)return kw;function C(r,o){n>0?o<-UI+_t&&(o=-UI+_t):o>UI-_t&&(o=UI-_t);var A=n/nF(UR(o),i);return[A*Vt(i*r),n-A*xt(i*r)]}return C.invert=function(r,o){var A=n-o,s=$r(i)*Li(r*r+A*A),a=AC(r,Wg(A))*$r(A);return A*i<0&&(a-=lg*$r(r)*$r(A)),[a/i,2*dy(nF(n/s,1/i))-UI]},C}function eDt(){return d4($We).scale(109.5).parallels([30,30])}function oS(g,e){return[g,e]}oS.invert=oS;function tDt(){return xa(oS).scale(152.63)}function qWe(g,e){var I=xt(g),i=g===e?Vt(g):(I-xt(e))/(e-g),n=I/i+g;if(Wg(i)<_t)return oS;function C(r,o){var A=n-o,s=i*r;return[A*Vt(s),n-A*xt(s)]}return C.invert=function(r,o){var A=n-o,s=AC(r,Wg(A))*$r(A);return A*i<0&&(s-=lg*$r(r)*$r(A)),[s/i,n-$r(i)*Li(r*r+A*A)]},C}function gDt(){return d4(qWe).scale(131.154).center([0,13.9389])}var DB=1.340264,FB=-.081106,EB=893e-6,MB=.003796,qH=Li(3)/2,IDt=12;function f4(g,e){var I=aC(qH*Vt(e)),i=I*I,n=i*i*i;return[g*xt(I)/(qH*(DB+3*FB*i+n*(7*EB+9*MB*i))),I*(DB+FB*i+n*(EB+MB*i))]}f4.invert=function(g,e){for(var I=e,i=I*I,n=i*i*i,C=0,r,o,A;C_t&&--i>0);return[g/(.8707+(C=I*I)*(-.131979+C*(-.013791+C*C*C*(.003971-.001529*C)))),I]};function rDt(){return xa(b4).scale(175.295)}function y4(g,e){return[xt(e)*Vt(g),Vt(e)]}y4.invert=Nw(aC);function oDt(){return xa(y4).scale(249.5).clipAngle(90+_t)}function Z4(g,e){var I=xt(e),i=1+xt(g)*I;return[I*Vt(g)/i,Vt(e)/i]}Z4.invert=Nw(function(g){return 2*dy(g)});function ADt(){return xa(Z4).scale(250).clipAngle(142)}function G4(g,e){return[XH(r4((UI+e)/2)),-g]}G4.invert=function(g,e){return[-e,2*dy(dWe(g))-UI]};function aDt(){var g=jWe(G4),e=g.center,I=g.rotate;return g.center=function(i){return arguments.length?e([-i[1],i[0]]):(i=e(),[i[1],-i[0]])},g.rotate=function(i){return arguments.length?I([i[0],i[1],i.length>2?i[2]+90:90]):(i=I(),[i[0],i[1],i[2]-90])},I([0,0,90]).scale(159.155)}const sDt=Object.freeze(Object.defineProperty({__proto__:null,geoAlbers:UWe,geoAlbersUsa:Qxt,geoArea:txt,geoAzimuthalEqualArea:jxt,geoAzimuthalEqualAreaRaw:h4,geoAzimuthalEquidistant:$xt,geoAzimuthalEquidistantRaw:m4,geoBounds:nxt,geoCentroid:sxt,geoCircle:lxt,geoClipAntimeridian:ZJ,geoClipCircle:TWe,geoClipExtent:pxt,geoClipRectangle:tY,geoConicConformal:eDt,geoConicConformalRaw:$We,geoConicEqualArea:$H,geoConicEqualAreaRaw:_We,geoConicEquidistant:gDt,geoConicEquidistantRaw:qWe,geoContains:Sxt,geoDistance:PH,geoEqualEarth:iDt,geoEqualEarthRaw:f4,geoEquirectangular:tDt,geoEquirectangularRaw:oS,geoGnomonic:nDt,geoGnomonicRaw:p4,geoGraticule:YWe,geoGraticule10:wxt,geoIdentity:CDt,geoInterpolate:Vxt,geoLength:NWe,geoMercator:qxt,geoMercatorRaw:kw,geoNaturalEarth1:rDt,geoNaturalEarth1Raw:b4,geoOrthographic:oDt,geoOrthographicRaw:y4,geoPath:Fxt,geoProjection:xa,geoProjectionMutator:u4,geoRotation:wWe,geoStereographic:ADt,geoStereographicRaw:Z4,geoStream:jo,geoTransform:Ext,geoTransverseMercator:aDt,geoTransverseMercatorRaw:G4},Symbol.toStringTag,{value:"Module"}));var lDt=[].slice,cDt={};function kJ(g){this._size=g,this._call=this._error=null,this._tasks=[],this._data=[],this._waiting=this._active=this._ended=this._start=0}kJ.prototype=tXe.prototype={constructor:kJ,defer:function(g){if(typeof g!="function")throw new Error("invalid callback");if(this._call)throw new Error("defer after await");if(this._error!=null)return this;var e=lDt.call(arguments,1);return e.push(g),++this._waiting,this._tasks.push(e),eXe(this),this},abort:function(){return this._error==null&&B4(this,new Error("abort")),this},await:function(g){if(typeof g!="function")throw new Error("invalid callback");if(this._call)throw new Error("multiple await");return this._call=function(e,I){g.apply(null,[e].concat(I))},e2(this),this},awaitAll:function(g){if(typeof g!="function")throw new Error("invalid callback");if(this._call)throw new Error("multiple await");return this._call=g,e2(this),this}};function eXe(g){if(!g._start)try{uDt(g)}catch(e){if(g._tasks[g._ended+g._active-1])B4(g,e);else if(!g._data)throw e}}function uDt(g){for(;g._start=g._waiting&&g._active=0;)if((i=g._tasks[I])&&(g._tasks[I]=null,i.abort))try{i.abort()}catch{}g._active=NaN,e2(g)}function e2(g){if(!g._active&&g._call){var e=g._data;g._data=void 0,g._call(g._error,e)}}function tXe(g){if(g==null)g=1/0;else if(!((g=+g)>=1))throw new Error("invalid concurrency");return new kJ(g)}const hDt=Object.freeze(Object.defineProperty({__proto__:null,queue:tXe},Symbol.toStringTag,{value:"Module"}));var Wr="$";function t2(){}t2.prototype=v4.prototype={constructor:t2,has:function(g){return Wr+g in this},get:function(g){return this[Wr+g]},set:function(g,e){return this[Wr+g]=e,this},remove:function(g){var e=Wr+g;return e in this&&delete this[e]},clear:function(){for(var g in this)g[0]===Wr&&delete this[g]},keys:function(){var g=[];for(var e in this)e[0]===Wr&&g.push(e.slice(1));return g},values:function(){var g=[];for(var e in this)e[0]===Wr&&g.push(this[e]);return g},entries:function(){var g=[];for(var e in this)e[0]===Wr&&g.push({key:e.slice(1),value:this[e]});return g},size:function(){var g=0;for(var e in this)e[0]===Wr&&++g;return g},empty:function(){for(var g in this)if(g[0]===Wr)return!1;return!0},each:function(g){for(var e in this)e[0]===Wr&&g(this[e],e.slice(1),this)}};function v4(g,e){var I=new t2;if(g instanceof t2)g.each(function(o,A){I.set(A,o)});else if(Array.isArray(g)){var i=-1,n=g.length,C;if(e==null)for(;++i=0&&(i=I.slice(n+1),I=I.slice(0,n)),I&&!e.hasOwnProperty(I))throw new Error("unknown type: "+I);return{type:I,name:i}})}xW.prototype=gXe.prototype={constructor:xW,on:function(g,e){var I=this._,i=fDt(g+"",I),n,C=-1,r=i.length;if(arguments.length<2){for(;++C0)for(var I=new Array(n),i=0,n,C;i3&&c(u)};function c(u){var d=r.status,h;if(!d&&yDt(r)||d>=200&&d<300||d===304){if(s)try{h=s.call(I,r)}catch(m){i.call("error",I,m);return}else h=r;i.call("load",I,h)}else i.call("error",I,u)}if(r.onprogress=function(u){i.call("progress",I,u)},I={header:function(u,d){return u=(u+"").toLowerCase(),arguments.length<2?C.get(u):(d==null?C.remove(u):C.set(u,d+""),I)},mimeType:function(u){return arguments.length?(n=u==null?null:u+"",I):n},responseType:function(u){return arguments.length?(a=u,I):a},timeout:function(u){return arguments.length?(l=+u,I):l},user:function(u){return arguments.length<1?o:(o=u==null?null:u+"",I)},password:function(u){return arguments.length<1?A:(A=u==null?null:u+"",I)},response:function(u){return s=u,I},get:function(u,d){return I.send("GET",u,d)},post:function(u,d){return I.send("POST",u,d)},send:function(u,d,h){return r.open(u,g,!0,o,A),n!=null&&!C.has("accept")&&C.set("accept",n+",*/*"),r.setRequestHeader&&C.each(function(m,f){r.setRequestHeader(f,m)}),n!=null&&r.overrideMimeType&&r.overrideMimeType(n),a!=null&&(r.responseType=a),l>0&&(r.timeout=l),h==null&&typeof d=="function"&&(h=d,d=null),h!=null&&h.length===1&&(h=bDt(h)),h!=null&&I.on("error",h).on("load",function(m){h(null,m)}),i.call("beforesend",I,r),r.send(d??null),I},abort:function(){return r.abort(),I},on:function(){var u=i.on.apply(i,arguments);return u===i?I:u}},e!=null){if(typeof e!="function")throw new Error("invalid callback: "+e);return I.get(e)}return I}function bDt(g){return function(e,I){g(e==null?I:null)}}function yDt(g){var e=g.responseType;return e&&e!=="text"?g.response:g.responseText}function IY(g,e){return function(I,i){var n=S4(I).mimeType(g).response(e);if(i!=null){if(typeof i!="function")throw new Error("invalid callback: "+i);return n.get(i)}return n}}const ZDt=IY("text/html",function(g){return document.createRange().createContextualFragment(g.responseText)}),GDt=IY("application/json",function(g){return JSON.parse(g.responseText)}),BDt=IY("text/plain",function(g){return g.responseText}),vDt=IY("application/xml",function(g){var e=g.responseXML;if(!e)throw new Error("parse error");return e});var xAe={},aF={},sF=34,pZ=10,lF=13;function IXe(g){return new Function("d","return {"+g.map(function(e,I){return JSON.stringify(e)+": d["+I+'] || ""'}).join(",")+"}")}function SDt(g,e){var I=IXe(g);return function(i,n){return e(I(i),n,g)}}function DAe(g){var e=Object.create(null),I=[];return g.forEach(function(i){for(var n in i)n in e||I.push(e[n]=n)}),I}function BC(g,e){var I=g+"",i=I.length;return i9999?"+"+BC(g,6):BC(g,4)}function VDt(g){var e=g.getUTCHours(),I=g.getUTCMinutes(),i=g.getUTCSeconds(),n=g.getUTCMilliseconds();return isNaN(g)?"Invalid Date":wDt(g.getUTCFullYear())+"-"+BC(g.getUTCMonth()+1,2)+"-"+BC(g.getUTCDate(),2)+(n?"T"+BC(e,2)+":"+BC(I,2)+":"+BC(i,2)+"."+BC(n,3)+"Z":i?"T"+BC(e,2)+":"+BC(I,2)+":"+BC(i,2)+"Z":I||e?"T"+BC(e,2)+":"+BC(I,2)+"Z":"")}function iXe(g){var e=new RegExp('["'+g+` -\r]`),I=g.charCodeAt(0);function i(l,c){var u,d,h=n(l,function(m,f){if(u)return u(m,f-1);d=m,u=c?SDt(m,c):IXe(m)});return h.columns=d||[],h}function n(l,c){var u=[],d=l.length,h=0,m=0,f,b=d<=0,p=!1;l.charCodeAt(d-1)===pZ&&--d,l.charCodeAt(d-1)===lF&&--d;function y(){if(b)return aF;if(p)return p=!1,xAe;var v,G=h,B;if(l.charCodeAt(G)===sF){for(;h++=d?b=!0:(B=l.charCodeAt(h++))===pZ?p=!0:B===lF&&(p=!0,l.charCodeAt(h)===pZ&&++h),l.slice(G+1,v-1).replace(/""/g,'"')}for(;h{const a=document.createElement("path"),l=s[0];let c=`M ${l[0]} ${l[1]}`;for(let u=2;uo.text.visible).forEach(o=>{const A=document.createElement("g"),s=document.createElement("text");s.setAttribute("text-anchor","middle"),s.setAttribute("font-family",cx),s.setAttribute("font-size",`${this.fontSize}px`),s.setAttribute("dy","-.2em"),A.setAttribute("transform",`scale(${o.text.scale.x},1)`),o.strand==="+"?s.setAttribute("fill",this.options.plusStrandColor):s.setAttribute("fill",this.options.minusStrandColor),s.innerHTML=o.text.text,A.appendChild(s),A.setAttribute("transform",`translate(${o.text.x},${o.text.y})scale(${o.text.scale.x},1)`),r.appendChild(A)}),[C,C]}}]),I}(O0);function dYt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function Jre(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function us(e){return us=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},us(e)}function Ore(e,g,I,i,n,C,r,o,A,s){const a=s?e._xScale(I.yStart):e._xScale(I.xStart),l=s?e._xScale(I.yEnd):e._xScale(I.xEnd),c=s?e._yScale(I.xStart):e._yScale(I.yStart),u=s?e._yScale(I.xEnd):e._yScale(I.yEnd),d=I.uid+s,h=l-a,m=u-c;let f={x:a,y:c,width:h,height:m};i&&(hn&&f.xn&&br&&f.yr&&pA||f.height>A)&&(g.drawRect(f.x,f.y,f.width,f.height),e.publish("annotationDrawn",{trackUuid:e.uuid,annotationUuid:d,viewPos:[f.x,f.y,f.width,f.height],dataPos:[I.xStart,I.xEnd,I.yStart,I.yEnd],importance:I.importance,info:{patternType:e.options.patternType}}))}let SRe=function(e){bYt(I,e);var g=yYt(I);function I(...i){var n;dYt(this,I),n=g.call(this,...i),n.drawnRects={};const{publish:C,subscribe:r,unsubscribe:o}=qT();return n.publish=C,n.subscribe=r,n.unsubscribe=o,n}return hYt(I,[{key:"tileToLocalId",value:function(n){return`${n.join(".")}`}},{key:"tileToRemoteId",value:function(n){return`${n.join(".")}`}},{key:"localToRemoteId",value:function(n){const C=n.split(".");return C.slice(0,C.length-1).join(".")}},{key:"calculateZoomLevel",value:function(){const n=Gt.calculateZoomLevel(this._xScale,this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0]),C=Gt.calculateZoomLevel(this._xScale,this.tilesetInfo.min_pos[1],this.tilesetInfo.max_pos[1]);let r=Math.max(n,C);return r=Math.min(r,this.maxZoom),r}},{key:"setVisibleTiles",value:function(n){this.visibleTiles=n.map(C=>({tileId:this.tileToLocalId(C),remoteId:this.tileToRemoteId(C)})),this.visibleTileIds=new Set(this.visibleTiles.map(C=>C.remoteId))}},{key:"calculateVisibleTiles",value:function(){if(!this.tilesetInfo)return;this.zoomLevel=this.calculateZoomLevel(),this.xTiles=Gt.calculateTiles(this.zoomLevel,this._xScale,this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0],this.tilesetInfo.max_zoom,this.tilesetInfo.max_width),this.yTiles=Gt.calculateTiles(this.zoomLevel,this._yScale,this.tilesetInfo.min_pos[1],this.tilesetInfo.max_pos[1],this.tilesetInfo.max_zoom,this.tilesetInfo.max_width);const n=this.xTiles,C=this.yTiles,r=this.zoomLevel,o=[];for(let A=0;A!(d.uid in this.drawnRects)).forEach(d=>{Ore(this,C,d,A,a,l,c,u,s,this.options.flipDiagonal==="yes"),this.options.flipDiagonal&&this.options.flipDiagonal==="copy"&&Ore(this,C,d,A,a,l,c,u,s,!0)})}},{key:"exportSVG",value:function(){let n=null,C=null;Cd(us(I.prototype),"exportSVG",this)?[C,n]=Cd(us(I.prototype),"exportSVG",this).call(this):(C=document.createElement("g"),n=C);const r=document.createElement("g");r.setAttribute("transform",`translate(${this.position[0]},${this.position[1]})`),n.appendChild(r);for(const o of[!0,!1])for(const A of this.visibleAndFetchedTiles())!A.tileData||!A.tileData.length||A.tileData.forEach(s=>{const a=s.uid+o,l=document.createElement("g");if(l.setAttribute("transform",`translate(${A.graphics.position.x},${A.graphics.position.y})scale(${A.graphics.scale.x},${A.graphics.scale.y})`),r.appendChild(l),a in this.drawnRects){const c=this.drawnRects[a],u=document.createElement("rect");u.setAttribute("x",c.x),u.setAttribute("y",c.y),u.setAttribute("width",c.width),u.setAttribute("height",c.height),u.setAttribute("fill",this.options.rectangleDomainFillColor?this.options.rectangleDomainFillColor:"grey"),u.setAttribute("opacity",.3),u.style.stroke="black",u.style.strokeWidth="1px",l.appendChild(u)}});return[C,C]}},{key:"setPosition",value:function(n){Cd(us(I.prototype),"setPosition",this).call(this,n),this.pMain.position.y=this.position[1],this.pMain.position.x=this.position[0]}},{key:"zoomed",value:function(n,C){this.xScale().domain()[0]===n.domain()[0]&&this.xScale().domain()[1]===n.domain()[1]&&this.yScale().domain()[0]===C.domain()[0]&&this.yScale().domain()[1]===C.domain()[1]||(this.xScale(n),this.yScale(C),this.refreshTiles(),this.draw())}},{key:"leftTrackDraw",value:function(){this.draw()}}]),I}(rm);function BYt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function _re(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function ds(e){return ds=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},ds(e)}const NYt=250;let VRe=function(e){WYt(I,e);var g=XYt(I);function I(i,n){var C;BYt(this,I),C=g.call(this,i,n);const{pubSub:r}=i;C.drawnAnnotations={},C.drawnAnnoGfx={},C.selectedAnno=null,C.options.minSquareSize=+C.options.minSquareSize;const{publish:o,subscribe:A,unsubscribe:s}=qT();return C.publish=o,C.subscribe=A,C.unsubscribe=s,C.sT=0,C.annoSelectedBound=C.annoSelected.bind(wRe(C)),C.pubSubs.push(r.subscribe("annoSelected",C.annoSelectedBound)),C}return SYt(I,[{key:"minX",get:function(){return this.tilesetInfo&&this.tilesetInfo.min_pos?this.tilesetInfo.min_pos[0]:0}},{key:"maxX",get:function(){return this.tilesetInfo&&this.tilesetInfo.max_pos?this.tilesetInfo.max_pos[0]:this.tilesetInfo.max_width||this.tilesetInfo.max_size}},{key:"minY",get:function(){return this.minX}},{key:"maxY",get:function(){return this.maxX}},{key:"maxSize",get:function(){const i=this.tilesetInfo.max_pos&&Math.max(this.tilesetInfo.max_pos[0]-this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[1]-this.tilesetInfo.min_pos[1]);return i||(this.tilesetInfo.max_size?this.tilesetInfo.max_size:0)}},{key:"projection",value:function([n,C]){return[this._xScale(n),this._yScale(C)]}},{key:"tileToLocalId",value:function(n){return`${n.join(".")}`}},{key:"tileToRemoteId",value:function(n){return`${n.join(".")}`}},{key:"localToRemoteId",value:function(n){const C=n.split(".");return C.slice(0,C.length-1).join(".")}},{key:"calculateZoomLevel",value:function(){const n=Gt.calculateZoomLevel(this._xScale,this.minX,this.maxX),C=Gt.calculateZoomLevel(this._yScale,this.minY,this.maxY);return zZe(G3(n,C),this.maxZoom)}},{key:"setVisibleTiles",value:function(n){this.visibleTiles=n.map(C=>({tileId:this.tileToLocalId(C),remoteId:this.tileToRemoteId(C)})),this.visibleTileIds=new Set(this.visibleTiles.map(C=>C.tileId))}},{key:"calculateVisibleTiles",value:function(){if(!this.tilesetInfo)return;this.zoomLevel=this.calculateZoomLevel(),this.xTiles=Gt.calculateTiles(this.zoomLevel,this._xScale,this.minX,this.maxX,this.tilesetInfo.max_zoom,this.maxSize),this.yTiles=Gt.calculateTiles(this.zoomLevel,this._yScale,this.minY,this.maxY,this.tilesetInfo.max_zoom,this.maxSize);const n=this.zoomLevel,C=[];for(let r=0;r!(A.uid in this.drawnAnnotations)||C).forEach(A=>{const[s,a]=this.projection([A.xStart,A.yStart]),[l,c]=this.projection([A.xEnd,A.yEnd]);this.options.exclude&&this.options.exclude.indexOf(A.uid)>=0||this.drawAnnotation(this.prepAnnotation(o,A.uid,s,a,l-s,c-a,A),r)})}},{key:"prepAnnotation",value:function(n,C,r,o,A,s,a){let l;try{l=JSON.parse(a.fields)}catch{}return{graphics:n,id:a.id,uid:C,annotation:{x:r,y:o,width:A,height:s},dataPos:[a.xStart,a.xEnd,a.yStart,a.yEnd],importance:a.importance,info:l}}},{key:"drawAnnotation",value:function({graphics:n,id:C,uid:r,annotation:o,dataPos:A,importance:s,info:a},l){this.options.minSquareSize&&(o.widththis.hover(u,c,r),u.mouseout=()=>this.blur(u,c,r),u.mousedown=()=>this.mouseDown(),u.mouseup=h=>this.mouseUp(u,c,r,h,d),l||this.publish("annotationDrawn",{trackUuids:this.uuid,annotationUuid:r,annotationId:C,viewPos:c,dataPos:A,importance:s,info:a})}},{key:"_drawRect",value:function(n,C,r){let o=this.options.rectangleDomainStrokeColor,A=this.options.rectangleDomainStrokeWidth,s=this.options.rectangleDomainStrokeOpacity,a=this.options.rectangleDomainFillColor,l=this.options.rectangleDomainFillOpacity;this.hoveredAnno===r&&(o=this.options.hoverColor,A=this.options.rectangleDomainStrokeWidth+1||2,s=1,a=this.options.hoverColor,l=this.options.rectangleDomainFillOpacity),this.selectedAnno&&this.selectedAnno.uid===r&&(o=this.options.selectColor,A=this.options.rectangleDomainStrokeWidth+1||2,s=1,a=this.options.selectColor,l=G3(.33,this.options.rectangleDomainFillOpacity)),n.clear(),this.options.trackBorderBgWidth&&(this.setBorderStyle(n,this.options.trackBorderBgColor,this.options.trackBorderBgWidth,this.options.trackBorderBgAlpha),this.setFill(n,a,0),n.drawRect(...C)),this.setBorderStyle(n,o,A,s),this.setFill(n,a,l),n.drawRect(...C),n.__viewPos__=C}},{key:"context",value:function(n,C,r){return o=>o(n,C,r)}},{key:"click",value:function(n,C,r,o,A){this.select(n,C,r),this.pubSub.publish("app.click",{type:"annotation",event:o,payload:A})}},{key:"mouseDown",value:function(){this.sT=performance.now()}},{key:"mouseUp",value:function(n,C,r,o,A){performance.now()-this.sT<=NYt&&this.click(n,C,r,o,A)}},{key:"hover",value:function(n,C,r){this.hoveredAnno=r,this._drawRect(n,C,r),this.animate()}},{key:"focus",value:function(n,C,r){this._drawRect(n,C,r),this.animate()}},{key:"blur",value:function(n,C,r){this.hoveredAnno=null,this._drawRect(n,C,r),this.animate()}},{key:"select",value:function(n,C,r,o=!1){let A=null,s=null;this.selectedAnno&&(A=this.selectedAnno.graphics,s=this.selectedAnno.uid),this.selectedAnno={graphics:n,uid:r},this.focus(n,C,r),this.options.onSelect&&!o&&(window[this.options.onSelect](r),this.pubSub.publish("annoSelected",r)),A&&s&&this.blur(A,A.__viewPos__,s)}},{key:"unselect",value:function(){const n=this.selectedAnno.graphics,C=this.selectedAnno.uid;this.selectedAnno=null,this.blur(n,n.__viewPos__,C)}},{key:"annoSelected",value:function(n){if(!this.selectedAnno||this.selectedAnno.uid!==n){this.selectedAnno&&this.unselect();const C=this.drawnAnnoGfx[n];C&&this.select(C,C.__viewPos__,n,!0)}}},{key:"exportSVG",value:function(){let n=null,C=null;rd(ds(I.prototype),"exportSVG",this)?[C,n]=rd(ds(I.prototype),"exportSVG",this).call(this):(C=document.createElement("g"),n=C);const r=document.createElement("g");return r.setAttribute("transform",`translate(${this.position[0]},${this.position[1]})`),n.appendChild(r),this.visibleAndFetchedTiles().filter(o=>o.tileData&&o.tileData.length).map(o=>({graphics:o.graphics,td:o.tileData})).forEach(({td:o,graphics:A})=>{const s=document.createElement("g");if(s.setAttribute("transform",`translate(${A.position.x},${A.position.y})scale(${A.scale.x},${A.scale.y})`),r.appendChild(s),o.uid in this.drawnAnnotations){const a=this.drawnAnnotations[o.uid],l=document.createElement("rect");l.setAttribute("x",a.x),l.setAttribute("y",a.y),l.setAttribute("width",a.width),l.setAttribute("height",a.height),l.setAttribute("fill",this.options.fillColor||"grey"),l.setAttribute("opacity",.3),l.style.stroke=this.options.fillColor||"grey",l.style.strokeWidth="1px",s.appendChild(l)}}),[C,C]}},{key:"setBorderStyle",value:function(n,C=this.options.rectangleDomainStrokeColor,r=this.options.rectangleDomainStrokeWidth,o=this.options.rectangleDomainStrokeOpacity){n.lineStyle(typeof r<"u"?r:1,Kt(C||"black"),typeof o<"u"?o:1)}},{key:"setFill",value:function(n,C=this.options.rectangleDomainFillColor,r=this.options.rectangleDomainFillOpacity){n.beginFill(Kt(C||"grey"),typeof r<"u"?r:.4)}},{key:"setPosition",value:function(n){rd(ds(I.prototype),"setPosition",this).call(this,n),this.pMain.position.y=this.position[1],this.pMain.position.x=this.position[0]}},{key:"zoomed",value:function(n,C){this.xScale(n),this.yScale(C),this.refreshTiles(),this.draw()}}]),I}(rm);function kYt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function Lre(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function hh(e){return hh=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},hh(e)}let iP=function(e){FYt(I,e);var g=EYt(I);function I(i,n,C){var r;return kYt(this,I),r=g.call(this,i,n),r.pubSub=i.pubSub,r.options=n,r.isVertical=C,r.rects={},r.defaultColor=wi("red"),r}return YYt(I,[{key:"draw",value:function(){const n=typeof this.options.minRectWidth<"u"?this.options.minRectWidth:10,C=typeof this.options.fill<"u"?wi(this.options.fill):this.defaultColor,r=typeof this.options.fillOpacity<"u"?+this.options.fillOpacity:.2,o=typeof this.options.stroke<"u"?wi(this.options.stroke):this.defaultColor,A=typeof this.options.strokeWidth<"u"?+this.options.strokeWidth:1,s=typeof this.options.strokeOpacity<"u"?+this.options.strokeOpacity:0;let a;this.options.strokePos&&this.options.strokePos.length&&(a=Array.isArray(this.options.strokePos)?this.options.strokePos:[this.options.strokePos]),nv(hh(I.prototype),"draw",this).call(this);const l=this.pMain;l.clear();const c=performance.now();this.options.regions.forEach(u=>{const d=`${u[0]}-${u[1]}`;this.rects[d]||(this.rects[d]={graphics:new rt.PIXI.Graphics},l.addChild(this.rects[d].graphics)),this.rects[d].timeStamp=c;const h=wi(u[2])||C;let m=wi(u[3])||o;m||(m=h);const f=rt.PIXI.utils.rgb2hex([h.r/255,h.g/255,h.b/255]),b=rt.PIXI.utils.rgb2hex([m.r/255,m.g/255,m.b/255]);a?(l.lineStyle(1,b,0),l.beginFill(b,+u[5]||s)):(l.lineStyle(A,b,+u[5]||s),l.beginFill(f,+u[4]||r));const p=this.isVertical?this._yScale:this._xScale;let y=p(+u[0]);const Z=p(+u[1]);let B=Z-y;const G=typeof u[6]<"u"?u[6]:n;B{(v==="top"||v==="around")&&(this.isVertical?l.drawRect(0,y,A,B):l.drawRect(y,0,B,A)),(v==="right"||v==="around")&&(this.isVertical?l.drawRect(0,y,this.dimensions[0],A):l.drawRect(y,0,A,this.dimensions[1])),(v==="bottom"||v==="around")&&(this.isVertical?l.drawRect(this.dimensions[0]-A,y,A,B):l.drawRect(y,this.dimensions[1]-A,B,A)),(v==="left"||v==="around")&&(this.isVertical?l.drawRect(0,y+B-A,this.dimensions[0],A):l.drawRect(y+B-A,0,A,this.dimensions[1]))})):l.lineStyle(A,b,+u[5]||s),this.rects[d].graphics.clear(),this.rects[d].graphics.interactive=!0,this.rects[d].graphics.buttonMode=!0,l.beginFill(f,+u[4]||r),this.isVertical?(l.drawRect(0,y,this.dimensions[0],B),this.rects[d].graphics.hitArea=new rt.PIXI.Rectangle(0,y,this.dimensions[0],B)):(l.drawRect(y,0,B,this.dimensions[1]),this.rects[d].graphics.hitArea=new rt.PIXI.Rectangle(y,0,B,this.dimensions[1])),this.rects[d].graphics.mousedown=()=>{this.rects[d].mouseDownTime=performance.now()},this.rects[d].graphics.mouseup=v=>{performance.now()-this.rects[d].mouseDownTimeu.timeStamp!==c).forEach(u=>l.removeChild(u.graphics))}},{key:"setPosition",value:function(n){nv(hh(I.prototype),"setPosition",this).call(this,n),this.pMain.position.y=this.position[1],this.pMain.position.x=this.position[0]}},{key:"zoomed",value:function(n,C){this.xScale(n),this.yScale(C),this.draw()}}]),I}(lC);function JYt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function Ure(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function OA(e){return OA=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},OA(e)}let RRe=function(e){QYt(I,e);var g=jYt(I);function I(i,n){var C;return JYt(this,I),C=g.call(this,i,n),C.drawnRects=new Set,C.pMain=C.pMobile,C}return OYt(I,[{key:"tileToLocalId",value:function(n){return`${n.join(".")}`}},{key:"tileToRemoteId",value:function(n){return`${n.join(".")}`}},{key:"localToRemoteId",value:function(n){const C=n.split(".");return C.slice(0,C.length-1).join(".")}},{key:"calculateZoomLevel",value:function(){const n=Gt.calculateZoomLevel(this._xScale,this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0]),C=Gt.calculateZoomLevel(this._xScale,this.tilesetInfo.min_pos[1],this.tilesetInfo.max_pos[1]);let r=Math.max(n,C);return r=Math.min(r,this.maxZoom),this.options&&this.options.maxZoom&&(this.options.maxZoom>=0?r=Math.min(this.options.maxZoom,r):console.error("Invalid maxZoom on track:",this)),r}},{key:"setVisibleTiles",value:function(n){this.visibleTiles=n.map(C=>({tileId:this.tileToLocalId(C),remoteId:this.tileToRemoteId(C)})),this.visibleTileIds=new Set(this.visibleTiles.map(C=>C.tileId))}},{key:"calculateVisibleTiles",value:function(){if(!this.tilesetInfo)return;this.zoomLevel=this.calculateZoomLevel();const n=this._xScale.copy();n.domain([this._xScale.invert(this._xScale.range()[0]-this.dimensions[1]*Math.sqrt(2)),this._xScale.invert(this._xScale.range()[1]+this.dimensions[1]*Math.sqrt(2))]),this.xTiles=Gt.calculateTiles(this.zoomLevel,n,this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0],this.tilesetInfo.max_zoom,this.tilesetInfo.max_width),this.yTiles=Gt.calculateTiles(this.zoomLevel,n,this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0],this.tilesetInfo.max_zoom,this.tilesetInfo.max_width);const C=this.xTiles,r=this.yTiles,o=this.zoomLevel,s=this.tilesetInfo.max_width/2**o,a=[];for(let l=0;lthis.dimensions[1])continue;const d=[o,C[l],r[c]];d.mirrored=!1,a.push(d)}this.setVisibleTiles(a)}},{key:"initTile",value:function(n){_l(OA(I.prototype),"initTile",this).call(this,n),this.drawTile(n)}},{key:"destroyTile",value:function(n,C){}},{key:"draw",value:function(){this.delayDrawing||this.drawnRects.clear(),_l(OA(I.prototype),"draw",this).call(this)}},{key:"drawTile",value:function(n){if(!n.graphics)return;const C=n.graphics;C.clear();const r=Kt(this.options.rectangleDomainStrokeColor?this.options.rectangleDomainStrokeColor:"black"),o=Kt(this.options.rectangleDomainFillColor?this.options.rectangleDomainFillColor:"grey");if(C.lineStyle(1/this.pMain.scale.x,r,1),C.beginFill(o,.4),C.alpha=this.options.rectangleDomainOpacity?this.options.rectangleDomainOpacity:.5,!!n.tileData.sort)for(const A of n.tileData){const s=this._refXScale(A.xStart),a=this._refXScale(A.xEnd),l=this._refYScale(A.yStart),c=this._refYScale(A.yEnd),u=A.uid;this.drawnRects.has(u)||(this.drawnRects.add(u),C.drawRect(s,l,a-s,c-l),C.pivot.x=this._refXScale(0),C.pivot.y=this._refYScale(0),C.scale.x=-1/Math.sqrt(2),C.rotation=-3*Math.PI/4,C.scale.y=1/Math.sqrt(2),C.position.x=this._refXScale(0),C.position.y=0)}}},{key:"setPosition",value:function(n){_l(OA(I.prototype),"setPosition",this).call(this,n),this.pMain.position.y=this.position[1],this.pMain.position.x=this.position[0]}},{key:"refScalesChanged",value:function(n,C){_l(OA(I.prototype),"refScalesChanged",this).call(this,n,C);for(const r in this.fetchedTiles){const o=this.fetchedTiles[r];if(o.sprite){const A=o.graphics;A.pivot.x=this._refXScale(0),A.pivot.y=this._refYScale(0),A.scale.x=-1/Math.sqrt(2),A.rotation=-3*Math.PI/4,A.scale.y=1/Math.sqrt(2),A.position.x=this._refXScale(0),A.position.y=0}}}},{key:"zoomed",value:function(n,C,r,o,A){_l(OA(I.prototype),"zoomed",this).call(this,n,C,r,o,A),this.pMain.position.x=o,this.pMain.position.y=this.position[1]+this.dimensions[1],this.pMain.scale.x=r,this.pMain.scale.y=r,this.options.oneDHeatmapFlipped&&(this.pMain.scale.y=-r,this.pMain.position.y=this.position[1]),this.draw()}},{key:"leftTrackDraw",value:function(){this.draw()}}]),I}(rm);function tKt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function Qre(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function mh(e){return mh=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},mh(e)}let WRe=function(e){CKt(I,e);var g=rKt(I);function I(i,n){var C;return tKt(this,I),C=g.call(this,i,n),C.drawnRects=new Set,C}return gKt(I,[{key:"tileToLocalId",value:function(n){return`${n.join(".")}`}},{key:"tileToRemoteId",value:function(n){return`${n.join(".")}`}},{key:"localToRemoteId",value:function(n){const C=n.split(".");return C.slice(0,C.length-1).join(".")}},{key:"calculateZoomLevel",value:function(){const n=Gt.calculateZoomLevel(this._xScale,this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0]),C=Gt.calculateZoomLevel(this._xScale,this.tilesetInfo.min_pos[1],this.tilesetInfo.max_pos[1]);let r=Math.max(n,C);return r=Math.min(r,this.maxZoom),r}},{key:"setVisibleTiles",value:function(n){this.visibleTiles=n.map(C=>({tileId:this.tileToLocalId(C),remoteId:this.tileToRemoteId(C)})),this.visibleTileIds=new Set(this.visibleTiles.map(C=>C.tileId))}},{key:"calculateVisibleTiles",value:function(n=!0){if(!this.tilesetInfo)return;this.zoomLevel=this.calculateZoomLevel(),this.xTiles=Gt.calculateTiles(this.zoomLevel,this._xScale,this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0],this.tilesetInfo.max_zoom,this.tilesetInfo.max_width),this.yTiles=Gt.calculateTiles(this.zoomLevel,this._yScale,this.tilesetInfo.min_pos[1],this.tilesetInfo.max_pos[1],this.tilesetInfo.max_zoom,this.tilesetInfo.max_width);const C=this.xTiles,r=this.yTiles,o=this.zoomLevel,A=[];for(let s=0;si.chrPositions?Vi(n,i):null,i.chrToAbs=([n,C]=[])=>i.chrPositions?UX(n,C,i):null,Gt.text(e,(n,C)=>{if(n)g&&g(null);else{const r=P7(C),o=CN(r);Object.keys(o).forEach(A=>{i[A]=o[A]}),g&&g(i)}},I).then(()=>i)}function sKt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function jre(e,g){for(var I=0;II.pos).left}return lKt(e,[{key:"scalesToPositionText",value:function(I,i,n=!1){if(this.chromInfo===null||!I||!i)return"";const C=Vi(I.domain()[0],this.chromInfo),r=Vi(I.domain()[1],this.chromInfo),o=Vi(i.domain()[0],this.chromInfo),A=Vi(i.domain()[1],this.chromInfo);let s=null;const a=Ar(",d");return C[0]!==r[0]?s=`${C[0]}:${a(Math.floor(C[1]))}-${r[0]}:${a(Math.ceil(r[1]))}`:s=`${C[0]}:${a(Math.floor(C[1]))}-${a(Math.ceil(r[1]))}`,n&&(o[0]!==A[0]?s+=` & ${o[0]}:${a(Math.floor(o[1]))}-${A[0]}:${a(Math.ceil(A[1]))}`:s+=` & ${o[0]}:${a(Math.floor(o[1]))}-${a(Math.ceil(A[1]))}`),(C[2]<=0||r[2]>0||n&&(o[2]<=0||A[2]>0))&&(s+=` [offset ${C[2]},${r[2]}`,n&&(s+=`:${o[2]},${A[2]}`),s+="]"),s}},{key:"convertNumberNotation",value:function(I){let i=I;if(!i.includes("M",i.length-1)&&!i.includes("K",i.length-1))return i;let n=0,C=0;if(i.includes("M",i.length-1)?(n=6,i=i.replace("M","")):(n=3,i=i.replace("K","")),Number.isNaN(+i))return I;i=(+i).toString(),i.includes(".")&&(C=i.length-1-i.indexOf("."),i=(+i.replace(".","")).toString());const r=n-C;return r<0?I:(i+="0".repeat(r),i)}},{key:"parsePosition",value:function(I,i=null){const n=I.split(":");let C=null,r=0;n.length>1?(C=n[0],r=+this.convertNumberNotation(n[1].replace(/,/g,""))):n[0]in this.chromInfo.chrPositions?(C=n[0],r=0,i!==null&&(r=+this.chromInfo.chromLengths[C])):(r=+this.convertNumberNotation(n[0].replace(/,/g,"")),C=null,i&&(C=i));let o=null;return C===null?(C=i,o=r):C in this.chromInfo.chrPositions&&(o=this.chromInfo.chrPositions[C].pos+r),[C,r,o]}},{key:"matchRangesToLarger",value:function(I,i){if(I[1]-I[0]C.length>0);let n=null;if(i[0].indexOf("-")===0&&(i[0]=i[0].slice(3,i[0].length)),i.length>1){let[C,r,o]=this.parsePosition(i[0]),[A,s,a]=this.parsePosition(i[1],C);const l=[o,a];[C,r,o]=this.parsePosition(i[1]),[A,s,a]=this.parsePosition(i[0],C),C===null&&A!==null&&([C,r,o]=this.parsePosition(i[1],A));const c=[o,a];return c[1]-c[0]>l[1]-l[0]?c:l}if(i[0]in this.chromInfo.chrPositions){const C=+this.chromInfo.chrPositions[i[0]].pos;n=[C,C+ +this.chromInfo.chromLengths[i[0]]]}else{const[C,r,o]=this.parsePosition(i[0]);n=[o-8e6,o+8e6]}return n[0]>n[1]?[n[1],n[0]]:n}},{key:"parseOffset",value:function(I){const i=I.split(":");if(i.length===0)return[[0,0],[0,0]];if(i.length===1){const r=i[0].split(",");return[[+r[0],+r[1]],[0,0]]}const n=i[0].split(","),C=i[1].split(",");return[[+n[0],+n[1]],[+C[0],+C[1]]]}},{key:"searchPosition",value:function(I){let i=null,n=null;I=I.trim();const C=/\[offset (.+?)\]/.exec(I);let r=[[0,0],[0,0]];C&&(I=I.replace(C[0],""),r=this.parseOffset(C[1]));const o=I.split(" & ");return o.length>1?(i=this.getSearchRange(o[0].split(" ")[0]),n=this.getSearchRange(o[1].split(" ")[0])):i=this.getSearchRange(o[0]),i!==null&&n!==null&&([i,n]=this.matchRangesToLarger(i,n)),i&&(i[0]+=r[0][0],i[1]+=r[0][1]),n&&(n[0]+=r[1][0],n[1]+=r[1][1]),[i,n]}}]),e}();function dKt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function $re(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function Ub(e){return Ub=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},Ub(e)}let XRe=function(e){bKt(I,e);var g=yKt(I);function I(i,n){var C;dKt(this,I),C=g.call(this,i,n);const{dataConfig:r,animate:o,pubSub:A}=i;C.searchField=null,C.chromInfo=null,C.animate=o;const s=r.server,a=r.tilesetUid,l=`${s}/chrom-sizes/?id=${a}`;return xs(l,c=>{C.chromInfo=c,C.searchField=new Lb(C.chromInfo),C.draw(),C.texts=[];for(let u=0;uthis.dimensions[0]?f.x-=h+p-this.dimensions[0]:h-p<0&&(f.x-=h-p),m+y>this.dimensions[1]?f.y-=m+y-this.dimensions[1]:m-y<0&&(f.y-=m-y),f.visible=!0,n.push({importance:this.texts[s][a].hashValue,text:this.texts[s][a],caption:null})}this.hideOverlaps(n)}},{key:"hideOverlaps",value:function(n){let C=[];C=n.map(r=>{const o=r.text;o.updateTransform();const A=o.getBounds();return[A.x,A.y,A.x+A.width,A.y+A.height]}),jS(C,(r,o)=>{n[r].importance>n[o].importance?n[o].text.visible=0:n[r].text.visible=0})}},{key:"setPosition",value:function(n){j1(Ub(I.prototype),"setPosition",this).call(this,n),this.pMain.position.y=this.position[1],this.pMain.position.x=this.position[0]}},{key:"zoomed",value:function(n,C){this.xScale(n),this.yScale(C),this.draw()}}]),I}(lC);function BKt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function qre(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function wc(e){return wc=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},wc(e)}let EZ=function(e){WKt(I,e);var g=XKt(I);function I(i,n){var C;BKt(this,I),C=g.call(this,i,n);const{chromInfoPath:r,dataConfig:o,animate:A,pubSub:s,orientation:a="2d",isOverlay:l=!1}=i;C.searchField=null,C.chromInfo=null,C.animate=A,C.orientation=a,C.isOverlay=l;let c=r;return c||(c=`${o.server}/chrom-sizes/?id=${o.tilesetUid}`),xs(c,u=>{C.chromInfo=u,C.searchField=new Lb(C.chromInfo),C.texts=[],C.lineGraphics=new rt.PIXI.Graphics,C.lineGraphics1dH=new rt.PIXI.Graphics,C.lineGraphics1dV=new rt.PIXI.Graphics,C.lineGraphics2d=new rt.PIXI.Graphics,C.mask1dH=new rt.PIXI.Graphics,C.mask1dV=new rt.PIXI.Graphics,C.mask2d=new rt.PIXI.Graphics,C.lineGraphics.addChild(C.lineGraphics1dH),C.lineGraphics1dH.addChild(C.mask1dH),C.lineGraphics.addChild(C.lineGraphics1dV),C.lineGraphics1dV.addChild(C.mask1dV),C.lineGraphics.addChild(C.lineGraphics2d),C.lineGraphics2d.addChild(C.mask2d),C.pMain.addChild(C.lineGraphics),C.draw(),C.animate()},s),C}return SKt(I,[{key:"drawLines",value:function(n=this.orientation,C=0,r=0){let o=this.lineGraphics;this.isOverlay&&n==="1d-horizontal"&&(o=this.lineGraphics1dH),this.isOverlay&&n==="1d-vertical"&&(o=this.lineGraphics1dV),this.isOverlay&&n==="2d"&&(o=this.lineGraphics2d);const A=Kt(this.options.lineStrokeColor?this.options.lineStrokeColor:"blue"),s=this.options.lineStrokeWidth?this.options.lineStrokeWidth:1;o.lineStyle(s,A,1),(n==="2d"||n==="1d-horizontal")&&(o.moveTo(this._xScale(0)+C,r),o.lineTo(this._xScale(0)+C,this.dimensions[1]+r)),(n==="2d"||n==="1d-vertical")&&(o.moveTo(C,this._yScale(0)+r),o.lineTo(this.dimensions[0]+C,this._yScale(0)+r));for(let a=0;a0&&c0&&c0&&h0&&h"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function fh(e){return fh=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},fh(e)}const JKt=300;let HRe=function(e){FKt(I,e);var g=EKt(I);function I(i,n){var C;kKt(this,I),C=g.call(this,i,n);const{chromInfoPath:r,pubSub:o}=i;return C.pubSub=o,C.rects={},xs(r,A=>{C.chromInfo=A,C.draw()},C.pubSub),C}return YKt(I,[{key:"draw",value:function(){if(!this.chromInfo)return;const n=this.options.minRectWidth?this.options.minRectWidth:10,C=this.options.minRectWidth?this.options.minRectHeight:10;rv(fh(I.prototype),"draw",this).call(this);const r=this.pMain;r.clear();const o=performance.now();this.options.regions.forEach(A=>{const s=A.slice(0,6).join("-");this.rects[s]||(this.rects[s]={graphics:new rt.PIXI.Graphics},r.addChild(this.rects[s].graphics)),this.rects[s].timeStamp=o;const a=wi(A[6]);let l=wi(A[7]);l||(l=a);const c=rt.PIXI.utils.rgb2hex([a.r/255,a.g/255,a.b/255]),u=rt.PIXI.utils.rgb2hex([l.r/255,l.g/255,l.b/255]);r.lineStyle(1,u,l.opacity),r.beginFill(c,a.opacity);let d=this._xScale(this.chromInfo.chrPositions[A[0]].pos+ +A[1]);const h=this._xScale(this.chromInfo.chrPositions[A[0]].pos+ +A[2]);let m=this._yScale(this.chromInfo.chrPositions[A[3]].pos+ +A[4]);const f=this._yScale(this.chromInfo.chrPositions[A[3]].pos+ +A[5]);let b=h-d,p=f-m;const y=typeof A[8]<"u"?A[8]:n,Z=typeof A[9]<"u"?A[9]:C;b{this.rects[s].mouseDownTime=performance.now()},this.rects[s].graphics.mouseup=B=>{performance.now()-this.rects[s].mouseDownTime"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function hs(e){return hs=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},hs(e)}const t5t=200,g5t=6,I5t=2,goe=7829367;let NRe=function(e){jKt(I,e);var g=$Kt(I);function I(i,n){var C;OKt(this,I),C=g.call(this,i,n);const{dataConfig:r,animate:o,chromInfoPath:A,isShowGlobalMousePosition:s}=i;C.searchField=null,C.chromInfo=null,C.dataConfig=r,C.pTicks=new rt.PIXI.Graphics,C.pMain.addChild(C.pTicks),C.gTicks={},C.tickTexts={},C.options=n,C.isShowGlobalMousePosition=s,C.textFontSize=12,C.textFontFamily="Arial",C.textFontColor="#808080",C.textStrokeColor=C.getTheme()===qg?"#000000":"#ffffff",C.pixiTextConfig={fontSize:+C.options.fontSize?`${+C.options.fontSize}px`:`${C.textFontSize}px`,fontFamily:C.textFontFamily,fill:C.options.color||C.textFontColor,lineJoin:"round",stroke:C.options.stroke||C.textStrokeColor,strokeThickness:2},C.stroke=Kt(C.pixiTextConfig.stroke),C.tickWidth=t5t,C.tickHeight=g5t,C.tickTextSeparation=I5t,C.tickColor=C.options.tickColor?Kt(C.options.tickColor):goe,C.animate=o,C.pubSubs=[],C.options.showMousePosition&&!C.hideMousePosition&&(C.hideMousePosition=eh(TRe(C),C.is2d,C.isShowGlobalMousePosition()));let a=A;return a||(a=`${r.server}/chrom-sizes/?id=${r.tilesetUid}`),xs(a,l=>{C.chromInfo=l,C.searchField=new Lb(C.chromInfo),C.rerender(C.options,!0),C.draw(),C.animate()},C.pubSub),C}return _Kt(I,[{key:"initBoundsTicks",value:function(){this.pTicks&&(this.pMain.removeChild(this.pTicks),this.pTicks=null),this.gBoundTicks||(this.gBoundTicks=new rt.PIXI.Graphics,this.leftBoundTick=new rt.PIXI.Text("",this.pixiTextConfig),this.rightBoundTick=new rt.PIXI.Text("",this.pixiTextConfig),this.gBoundTicks.addChild(this.leftBoundTick),this.gBoundTicks.addChild(this.rightBoundTick),this.pMain.addChild(this.gBoundTicks)),this.texts=[]}},{key:"initChromLabels",value:function(){if(this.chromInfo){this.gBoundTicks&&(this.pMain.removeChild(this.gBoundTicks),this.gBoundTicks=null),this.pTicks||(this.pTicks=new rt.PIXI.Graphics,this.pMain.addChild(this.pTicks)),this.texts=[],this.pTicks.removeChildren();for(let n=0;nNumber.isInteger(b)),c=this.tickTexts[n.chr],u=this.options.fontIsLeftAligned?(+this.options.fontSize||this.textFontSize)/2:this.tickHeight,d=this.flipText?-1:1,h=this.options.fontIsLeftAligned?d*4:0;let m=this.options.fontIsLeftAligned?0:u+this.tickTextSeparation;for(this.options.reverseOrientation&&(m=this.dimensions[1]-m);c.lengthl.length;){const b=c.pop();this.gTicks[n.chr].removeChild(b)}let f=0;for(;f{if(this.tickTexts[o])for(let A=0;A{r.updateTransform();const A=r.getBounds();return[A.x,A.y,A.x+A.width,A.y+A.height]}),jS(C,(r,o)=>{n[r].importance>n[o].importance?n[o].text.visible=!1:n[r].text.visible=!1})}},{key:"setPosition",value:function(n){od(hs(I.prototype),"setPosition",this).call(this,n),[this.pMain.position.x,this.pMain.position.y]=this.position}},{key:"zoomed",value:function(n,C){this.xScale(n),this.yScale(C),this.draw()}},{key:"exportSVG",value:function(){let n=null,C=null;od(hs(I.prototype),"exportSVG",this)?[C,n]=od(hs(I.prototype),"exportSVG",this).call(this):(C=document.createElement("g"),n=C),C.setAttribute("class","chromosome-labels");const r=document.createElement("g");return n.appendChild(r),r.setAttribute("transform",`translate(${this.position[0]},${this.position[1]})`),this.allTexts.filter(o=>o.text.visible).forEach(o=>{const A=S3(o.text);r.appendChild(A)}),Object.values(this.tickTexts).forEach(o=>{o.filter(A=>A.visible).forEach(A=>{let s=S3(A);r.appendChild(s),s=QZe(A.x,this.options.reverseOrientation?0:this.dimensions[1],A.x,this.options.reverseOrientation?this.tickHeight:this.dimensions[1]-this.tickHeight,1,this.tickColor);const a=document.createElement("line");a.setAttribute("x1",A.tickLine[0]),a.setAttribute("y1",A.tickLine[1]),a.setAttribute("x2",A.tickLine[2]),a.setAttribute("y2",A.tickLine[3]),a.setAttribute("style","stroke: grey"),r.appendChild(s),r.appendChild(a)})}),[C,n]}}]),I}(lC);function i5t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function Ioe(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function _A(e){return _A=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},_A(e)}let kRe=function(e){A5t(I,e);var g=a5t(I);function I(i,n){var C;i5t(this,I),C=g.call(this,i,n);const{animate:r}=i;return C.pMain=C.pMobile,C.colorScale=Gb,C.continuousScaling=!1,n&&n.colorRange&&(C.colorScale=Dc(n.colorRange)),C.animate=r,C.options=n,C.pubSubs=[],C}return n5t(I,[{key:"rerender",value:function(n,C){Ll(_A(I.prototype),"rerender",this).call(this,n,C),this.zoomed(this.xScale(),this.yScale(),this.pMain.scale.x,this.pMain.position.x,this.pMain.position.y)}},{key:"calculateZoomLevel",value:function(){let n=null;if(this.tilesetInfo.resolutions){const C=Gt.calculateZoomLevelFromResolutions(this.tilesetInfo.resolutions,this._xScale,this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0]),r=Gt.calculateZoomLevelFromResolutions(this.tilesetInfo.resolutions,this._xScale,this.tilesetInfo.min_pos[1],this.tilesetInfo.max_pos[1]);n=Math.min(C,r)}else{const C=Gt.calculateZoomLevel(this._xScale,this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0]),r=Gt.calculateZoomLevel(this._xScale,this.tilesetInfo.min_pos[1],this.tilesetInfo.max_pos[1]);n=Math.max(C,r),n=Math.min(n,this.maxZoom)}return this.options&&this.options.maxZoom&&(this.options.maxZoom>=0?n=Math.min(this.options.maxZoom,n):console.error("Invalid maxZoom on track:",this)),n}},{key:"calculateVisibleTiles",value:function(){if(!this.tilesetInfo)return;this.zoomLevel=this.calculateZoomLevel();const n=this._xScale.copy();if(n.domain([this._xScale.invert(this._xScale.range()[0]-this.dimensions[1]*Math.sqrt(2)),this._xScale.invert(this._xScale.range()[1]+this.dimensions[1]*Math.sqrt(2))]),this.tilesetInfo.resolutions){const l=this.tilesetInfo.resolutions.map(c=>+c).sort((c,u)=>u-c);this.xTiles=Gt.calculateTilesFromResolution(l[this.zoomLevel],n,this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0]),this.yTiles=Gt.calculateTilesFromResolution(l[this.zoomLevel],n,this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0])}else this.xTiles=Gt.calculateTiles(this.zoomLevel,n,this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0],this.tilesetInfo.max_zoom,this.tilesetInfo.max_width),this.yTiles=Gt.calculateTiles(this.zoomLevel,n,this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0],this.tilesetInfo.max_zoom,this.tilesetInfo.max_width);const C=this.xTiles,r=this.yTiles,o=this.zoomLevel,s=this.tilesetInfo.max_width/2**o,a=[];for(let l=0;lthis.dimensions[1])continue;const d=[o,C[l],r[c]];d.mirrored=!1,d.dataTransform=this.options.dataTransform?this.options.dataTransform:"default",a.push(d)}this.setVisibleTiles(a)}},{key:"tileDataToCanvas",value:function(n){const C=document.createElement("canvas");C.width=256,C.height=256;const r=C.getContext("2d");r.fillStyle="transparent",r.fillRect(0,0,C.width,C.height);const o=new ImageData(n,C.width,C.height);return r.putImageData(o,0,0),C}},{key:"setSpriteProperties",value:function(n,C,r,o){const{tileX:A,tileY:s,tileWidth:a,tileHeight:l}=this.getTilePosAndDimensions(C,r),c=A+a,u=s+l;n.width=this._refXScale(c)-this._refXScale(A),n.height=this._refYScale(u)-this._refYScale(s),n.x=this._refXScale(A),n.y=this._refYScale(s)}},{key:"pixDataFunction",value:function(n,C){if(C){const r=n.graphics,o=this.tileDataToCanvas(C.pixData),A=rt.PIXI.VERSION[0]==="4"?rt.PIXI.Texture.fromCanvas(o,rt.PIXI.SCALE_MODES.NEAREST):rt.PIXI.Texture.from(o,{scaleMode:rt.PIXI.SCALE_MODES.NEAREST});n.sprite=new rt.PIXI.Sprite(A),n.canvas=o,this.setSpriteProperties(n.sprite,n.tileData.zoomLevel,n.tileData.tilePos,n.mirrored),r.pivot.x=this._refXScale(0),r.pivot.y=this._refYScale(0),r.scale.x=-1/Math.sqrt(2),r.rotation=-3*Math.PI/4,r.scale.y=1/Math.sqrt(2),r.position.x=this._refXScale(0),r.position.y=0,r.removeChildren(),r.addChild(n.sprite)}this.renderingTiles.delete(n.tileId)}},{key:"refScalesChanged",value:function(n,C){Ll(_A(I.prototype),"refScalesChanged",this).call(this,n,C);for(const r in this.fetchedTiles){const o=this.fetchedTiles[r];if(o.sprite){this.setSpriteProperties(o.sprite,o.tileData.zoomLevel,o.tileData.tilePos,o.mirrored);const A=o.graphics;A.pivot.x=this._refXScale(0),A.pivot.y=this._refYScale(0),A.scale.x=-1/Math.sqrt(2),A.rotation=-3*Math.PI/4,A.scale.y=1/Math.sqrt(2),A.position.x=this._refXScale(0),A.position.y=0}}}},{key:"zoomed",value:function(n,C,r,o,A){Ll(_A(I.prototype),"zoomed",this).call(this,n,C,r,o,A),Ll(_A(I.prototype),"draw",this).call(this),this.pMain.position.x=o,this.pMain.position.y=this.position[1]+this.dimensions[1],this.pMain.scale.x=r,this.pMain.scale.y=r,this.options.oneDHeatmapFlipped&&(this.pMain.scale.y=-r,this.pMain.position.y=this.position[1])}},{key:"leftTrackDraw",value:function(){this.draw()}},{key:"exportSVG",value:function(){let n=null,C=null;[C,n]=Ll(_A(I.prototype),"superSVG",this).call(this);const r=document.createElement("g");n.appendChild(r),r.setAttribute("transform",`translate(${this.pMain.position.x},${this.pMain.position.y}) scale(${this.pMain.scale.x},${this.pMain.scale.y})`);for(const A of this.visibleAndFetchedTiles()){const s=document.createElement("g"),a=A.graphics,l=a.rotation*180/Math.PI,c=`translate(${a.position.x},${a.position.y}) rotate(${l}) scale(${a.scale.x},${a.scale.y}) translate(${-a.pivot.x},${-a.pivot.y})`;s.setAttribute("transform",c);const u=A.sprite.rotation*180/Math.PI,d=document.createElement("g");d.setAttribute("transform",`translate(${A.sprite.x},${A.sprite.y}) rotate(${u}) scale(${A.sprite.scale.x},${A.sprite.scale.y})`);const h=document.createElement("image");h.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",A.canvas.toDataURL()),h.setAttribute("width",256),h.setAttribute("height",256),d.appendChild(h),s.appendChild(d),r.appendChild(s)}const o=this.exportColorBarSVG();return n.appendChild(o),[C,C]}}]),I}(QS);function u5t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function ioe(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function K9(e){return K9=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},K9(e)}let noe=function(e){f5t(I,e);var g=p5t(I);function I(i,n){var C;return u5t(this,I),C=g.call(this,i,n),C.tilesetInfo={},C.errorTextText=`Unknown track type: ${n.type}`,C}return d5t(I,[{key:"zoomed",value:function(){this.draw()}}]),I}(lC);function G5t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function Coe(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function D9(e){return D9=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},D9(e)}let KRe=function(e){w5t(I,e);var g=V5t(I);function I(i,n){var C;return G5t(this,I),C=g.call(this,i,n),C.axis=new jN(YRe(C)),C.pBase.addChild(C.axis.pAxis),C}return v5t(I,[{key:"initTile",value:function(n){this.scale.minRawValue=this.minVisibleValueInTiles(),this.scale.maxRawValue=this.minVisibleValueInTiles(),this.scale.minValue=this.scale.minRawValue,this.scale.maxValue=this.scale.maxRawValue,this.drawTile(n)}},{key:"drawTile",value:function(n){if(!n.graphics)return;const C=n.graphics,r=6,o=4;C.clear(),this.valueScale=Qc().domain([this.minValue()+.01,this.maxValue()]).range([this.dimensions[1]-r/2,r/2]);const A=Kt("black");C.lineStyle(1,A,.3),C.beginFill(A,.3),this.drawAxis(this.valueScale),n.tileData.forEach(s=>{const a=s.fields,l=+s.chrOffset,c=+a[1]+l,u=+a[2]+l,d=+a[3],h=this._xScale(c),m=this._xScale(u),f=Math.max(m-h,o),b=this.valueScale(d),p=(m+h)/2;C.drawRect(p-f/2,b-r/2,f,r)})}},{key:"minVisibleValueInTiles",value:function(){let n=this.visibleAndFetchedIds();return n.length===0&&(n=Object.keys(this.fetchedTiles)),Math.min.apply(null,n.map(r=>+Math.min(...this.fetchedTiles[r].tileData.filter(o=>!Number.isNaN(o.fields[3])).map(o=>+o.fields[3]))))}},{key:"maxVisibleValueInTiles",value:function(){let n=this.visibleAndFetchedIds();return n.length===0&&(n=Object.keys(this.fetchedTiles)),Math.max.apply(null,n.map(r=>+Math.max(...this.fetchedTiles[r].tileData.filter(o=>!Number.isNaN(o.fields[3])).map(o=>+o.fields[3]))))}}]),I}(L0);function X5t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function roe(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function Vc(e){return Vc=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},Vc(e)}let DRe=function(e){Y5t(I,e);var g=K5t(I);function I(i,n){var C;X5t(this,I),C=g.call(this,i,n);const{registerViewportChanged:r,removeViewportChanged:o,setDomainsCallback:A}=i,s=Ag.nice();return C.uid=s,C.options=n,C.hasFromView=!i.projectionXDomain||!i.projectionYDomain,C.removeViewportChanged=o,C.setDomainsCallback=A,C.viewportXDomain=C.hasFromView?null:i.projectionXDomain,C.viewportYDomain=C.hasFromView?null:i.projectionYDomain,C.brush=T7().on("brush",C.brushed.bind(dP(C))),C.gBrush=C.gMain.append("g").attr("id",`brush-${C.uid}`).call(C.brush),C.gBrush.selectAll(".overlay").style("pointer-events","none"),C.gBrush.selectAll(".handle--n").style("pointer-events","none"),C.gBrush.selectAll(".handle--s").style("pointer-events","none"),C.gBrush.selectAll(".handle--w").style("pointer-events","none"),C.gBrush.selectAll(".handle--e").style("pointer-events","none"),r(s,C.viewportChanged.bind(dP(C))),C.rerender(),C.draw(),C}return H5t(I,[{key:"brushed",value:function(n){const C=n.selection;if(!this._xScale||!this._yScale)return;const r=[this._xScale.invert(C[0][0]),this._xScale.invert(C[1][0])],o=[this._yScale.invert(C[0][1]),this._yScale.invert(C[1][1])];this.hasFromView||(this.viewportXDomain=r,this.viewportYDomain=o),this.setDomainsCallback(r,o)}},{key:"viewportChanged",value:function(n,C){const r=n.domain(),o=C.domain();this.viewportXDomain=r,this.viewportYDomain=o,this.draw()}},{key:"remove",value:function(){this.removeViewportChanged(this.uid),Kp(Vc(I.prototype),"remove",this).call(this)}},{key:"rerender",value:function(){this.gBrush.selectAll(".selection").attr("fill",this.options.projectionFillColor).attr("stroke",this.options.projectionStrokeColor).attr("fill-opacity",this.options.projectionFillOpacity).attr("stroke-opacity",this.options.projectionStrokeOpacity).attr("stroke-width",this.options.strokeWidth)}},{key:"draw",value:function(){if(!this._xScale||!this.yScale||!this.viewportXDomain||!this.viewportYDomain)return;const n=this._xScale(this.viewportXDomain[0]),C=this._yScale(this.viewportYDomain[0]),r=this._xScale(this.viewportXDomain[1]),o=this._yScale(this.viewportYDomain[1]),A=[[n,C],[r,o]];this.brush.on("brush",null),this.gBrush.call(this.brush.move,A),this.brush.on("brush",this.brushed.bind(this))}},{key:"zoomed",value:function(n,C){this.xScale(n),this.yScale(C),this.draw()}},{key:"setPosition",value:function(n){Kp(Vc(I.prototype),"setPosition",this).call(this,n),this.draw()}},{key:"setDimensions",value:function(n){Kp(Vc(I.prototype),"setDimensions",this).call(this,n);const C=this._xScale.range(),r=this._yScale.range(),o=C[1]-C[0],A=r[1]-r[0];this.brush.extent([[C[0]-o,r[0]-A],[C[1]+o,r[1]+A]]),this.gBrush.call(this.brush),this.draw()}}]),I}(om);function F5t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function ooe(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function Rc(e){return Rc=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},Rc(e)}let xRe=function(e){J5t(I,e);var g=O5t(I);function I(i,n){var C;F5t(this,I),C=g.call(this,i,n);const{registerViewportChanged:r,removeViewportChanged:o,setDomainsCallback:A}=i,s=Ag.nice();return C.uid=s,C.options=n,C.hasFromView=!i.projectionXDomain,C.removeViewportChanged=o,C.setDomainsCallback=A,C.viewportXDomain=C.hasFromView?null:i.projectionXDomain,C.viewportYDomain=C.hasFromView?null:[0,0],C.brush=iN().on("brush",C.brushed.bind(mP(C))),C.gBrush=C.gMain.append("g").attr("id",`brush-${C.uid}`).call(C.brush),C.gBrush.selectAll(".overlay").style("pointer-events","none"),C.gBrush.selectAll(".handle--ne").style("pointer-events","none"),C.gBrush.selectAll(".handle--nw").style("pointer-events","none"),C.gBrush.selectAll(".handle--sw").style("pointer-events","none"),C.gBrush.selectAll(".handle--se").style("pointer-events","none"),C.gBrush.selectAll(".handle--n").style("pointer-events","none"),C.gBrush.selectAll(".handle--s").style("pointer-events","none"),r(s,C.viewportChanged.bind(mP(C))),C.rerender(),C.draw(),C}return E5t(I,[{key:"brushed",value:function(n){const C=n.selection;if(!this._xScale||!this._yScale)return;const r=[this._xScale.invert(C[0]),this._xScale.invert(C[1])],o=this.viewportYDomain;this.hasFromView||(this.viewportXDomain=r),this.setDomainsCallback(r,o)}},{key:"viewportChanged",value:function(n,C,r=!0){const o=n.domain(),A=C.domain();this.viewportXDomain=o,this.viewportYDomain=A,this.draw()}},{key:"remove",value:function(){this.removeViewportChanged(this.uid),Dp(Rc(I.prototype),"remove",this).call(this)}},{key:"rerender",value:function(){this.gBrush.selectAll(".selection").attr("fill",this.options.projectionFillColor).attr("stroke",this.options.projectionStrokeColor).attr("fill-opacity",this.options.projectionFillOpacity).attr("stroke-opacity",this.options.projectionStrokeOpacity).attr("stroke-width",this.options.strokeWidth)}},{key:"draw",value:function(){if(!this._xScale||!this.yScale||!this.viewportXDomain||!this.viewportYDomain)return;const n=this._xScale(this.viewportXDomain[0]),C=this._xScale(this.viewportXDomain[1]),r=[n,C];this.brush.on("brush",null),this.gBrush.call(this.brush.move,r),this.brush.on("brush",this.brushed.bind(this))}},{key:"zoomed",value:function(n,C){this.xScale(n),this.yScale(C),this.draw()}},{key:"setPosition",value:function(n){Dp(Rc(I.prototype),"setPosition",this).call(this,n),this.draw()}},{key:"setDimensions",value:function(n){Dp(Rc(I.prototype),"setDimensions",this).call(this,n);const C=this._xScale.range(),r=this._yScale.range(),o=C[1]-C[0];this.brush.extent([[C[0]-o,r[0]],[C[1]+o,r[1]]]),this.gBrush.call(this.brush),this.draw()}}]),I}(om);function U5t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function Aoe(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function Wc(e){return Wc=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},Wc(e)}let FRe=function(e){eDt(I,e);var g=tDt(I);function I(i,n){var C;U5t(this,I),C=g.call(this,i,n);const{registerViewportChanged:r,removeViewportChanged:o,setDomainsCallback:A}=i,s=Ag.nice();return C.uid=s,C.options=n,C.hasFromView=!i.projectionYDomain,C.removeViewportChanged=o,C.setDomainsCallback=A,C.viewportXDomain=C.hasFromView?null:[0,0],C.viewportYDomain=C.hasFromView?null:i.projectionYDomain,C.brush=SS().on("brush",C.brushed.bind(pP(C))),C.gBrush=C.gMain.append("g").attr("id",`brush-${C.uid}`).call(C.brush),C.gBrush.selectAll(".overlay").style("pointer-events","none"),C.gBrush.selectAll(".handle--ne").style("pointer-events","none"),C.gBrush.selectAll(".handle--nw").style("pointer-events","none"),C.gBrush.selectAll(".handle--sw").style("pointer-events","none"),C.gBrush.selectAll(".handle--se").style("pointer-events","none"),C.gBrush.selectAll(".handle--e").style("pointer-events","none"),C.gBrush.selectAll(".handle--w").style("pointer-events","none"),r(s,C.viewportChanged.bind(pP(C))),C.rerender(),C.draw(),C}return Q5t(I,[{key:"brushed",value:function(n){const C=n.selection;if(!this._xScale||!this._yScale)return;const r=this.viewportXDomain,o=[this._yScale.invert(C[0]),this._yScale.invert(C[1])];this.hasFromView||(this.viewportYDomain=o),this.setDomainsCallback(r,o)}},{key:"viewportChanged",value:function(n,C,r=!0){const o=n.domain(),A=C.domain();this.viewportXDomain=o,this.viewportYDomain=A,this.draw()}},{key:"remove",value:function(){this.removeViewportChanged(this.uid),xp(Wc(I.prototype),"remove",this).call(this)}},{key:"rerender",value:function(){this.gBrush.selectAll(".selection").attr("fill",this.options.projectionFillColor).attr("stroke",this.options.projectionStrokeColor).attr("fill-opacity",this.options.projectionFillOpacity).attr("stroke-opacity",this.options.projectionStrokeOpacity).attr("stroke-width",this.options.strokeWidth)}},{key:"draw",value:function(){if(!this._xScale||!this.yScale||!this.viewportXDomain||!this.viewportYDomain)return;const n=this._yScale(this.viewportYDomain[0]),C=this._yScale(this.viewportYDomain[1]),r=[n,C];this.brush.on("brush",null),this.gBrush.call(this.brush.move,r),this.brush.on("brush",this.brushed.bind(this))}},{key:"zoomed",value:function(n,C){this.xScale(n),this.yScale(C),this.draw()}},{key:"setPosition",value:function(n){xp(Wc(I.prototype),"setPosition",this).call(this,n),this.draw()}},{key:"setDimensions",value:function(n){xp(Wc(I.prototype),"setDimensions",this).call(this,n);const C=this._xScale.range(),r=this._yScale.range(),o=r[1]-r[0];this.brush.extent([[C[0],r[0]-o],[C[1],r[1]+o]]),this.gBrush.call(this.brush),this.draw()}}]),I}(om);function aoe(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function soe(e,g){for(var I=0;Ie[yP]||e,CDt=(e,g)=>{const I=g(e);return I.prototype[bP]=ERe(g),I},rDt=(e,g)=>e.hasOwnProperty(bP)&&e[bP]===ERe(g),oDt=(e,g)=>{for(;e!==null;){if(rDt(e,g))return!0;e=Object.getPrototypeOf(e)}return!1},Sj=(e,g)=>(Object.setPrototypeOf(g,e),e[yP]||(e[yP]=e),g),ux="__mixwith_cachedApplications",ADt=e=>Sj(e,g=>{let I=g[ux];I||(g[ux]=new Map,I=g[ux]);let i=I.get(e);return i||(i=e(g),I.set(e,i)),i}),aDt=e=>Sj(e,g=>oDt(g.prototype,e)?g:e(g)),sDt=e=>Sj(e,g=>CDt(g,e)),ok=e=>aDt(ADt(sDt(e)));let lDt=function(){function e(g){aoe(this,e),this.superclass=g||function(){function I(){aoe(this,I)}return loe(I)}()}return loe(e,[{key:"with",value:function(...I){return I.reduce((i,n)=>n(i),this.superclass)}}]),e}();const U0=e=>new lDt(e);function cDt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function coe(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function ph(e){return ph=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},ph(e)}const wj=ok(e=>function(g){fDt(i,g);var I=pDt(i);function i(n,C){var r;cDt(this,i),r=I.call(this,n,C);const{animate:o}=n;return r.highlighted=!1,r.animate=o,r.MOUSEOVER_RADIUS=4,r.pubSub=n.pubSub,r.pubSubs.push(r.pubSub.subscribe("app.mouseMove",r.mouseMoveHandler.bind(MRe(r)))),r}return uDt(i,[{key:"setPosition",value:function(C){ov(ph(i.prototype),"setPosition",this).call(this,C),this.pMain.position.x=this.position[0],this.pMain.position.y=this.position[1]}},{key:"zoomed",value:function(C,r){ov(ph(i.prototype),"zoomed",this).call(this,C,r),this.draw()}},{key:"respondsToPosition",value:function(){return this.highlighted}}]),i}(e));function Av(){return typeof Reflect<"u"&&Reflect.get?Av=Reflect.get.bind():Av=function(g,I,i){var n=ZDt(g,I);if(n){var C=Object.getOwnPropertyDescriptor(n,I);return C.get?C.get.call(arguments.length<3?g:i):C.value}},Av.apply(this,arguments)}function ZDt(e,g){for(;!Object.prototype.hasOwnProperty.call(e,g)&&(e=bh(e),e!==null););return e}function zRe(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function uoe(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function bh(e){return bh=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},bh(e)}const VDt=ok(e=>function(g){JRe(i,g);var I=ORe(i);function i(){return zRe(this,i),I.apply(this,arguments)}return PRe(i,[{key:"drawHorizontalRule",value:function(C){let r=Kt(this.options.color||"black");this.highlighted&&(r=Kt("red")),C.lineStyle(this.strokeWidth,r,this.strokeOpacity);let o=0;for(;o"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function yh(e){return yh=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},yh(e)}const $Re=ok(e=>function(g){QRe(i,g);var I=jRe(i);function i(){return LRe(this,i),I.apply(this,arguments)}return URe(i,[{key:"drawVerticalRule",value:function(C){let r=Kt(this.options.color||"black");this.highlighted&&(r=Kt("red")),C.lineStyle(this.strokeWidth,r,this.strokeOpacity);let o=0;for(;o"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function Zh(e){return Zh=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},Zh(e)}let e1e=function(e){FDt(I,e);var g=EDt(I);function I(i,n){var C;kDt(this,I),C=g.call(this,i,n);const{x:r,y:o}=i;return C.xPosition=r,C.yPosition=o,C.strokeWidth=2,C.strokeOpacity=1,C.dashLength=5,C.dashGap=3,C}return YDt(I,[{key:"draw",value:function(){const n=this.pMain;n.clear(),this.drawHorizontalRule(n),this.drawVerticalRule(n)}},{key:"mouseMoveHandler",value:function(n){this.highlighted=this.isWithin(n.x,n.y)&&(this.isMouseOverHorizontalLine(n)||this.isMouseOverVerticalLine(n)),this.draw()}},{key:"drawHorizontalRule",value:function(n){let C=Kt(this.options.color||"black");this.highlighted&&(C=Kt("red")),n.lineStyle(this.strokeWidth,C,this.strokeOpacity);let r=0;for(;r"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function LA(e){return LA=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},LA(e)}let $S=function(e){QDt(I,e);var g=jDt(I);function I(i,n){var C;JDt(this,I),C=g.call(this,i,n);const{animate:r}=i;return C.visibleTiles=new Set,C.visibleTileIds=new Set,C.fetching=new Set,C.fetchedTiles={},C.tileGraphics={},C.minX=typeof C.options.minPos<"u"&&!Number.isNaN(+C.options.minPos)?+C.options.minPos:-180,C.maxX=+C.options.maxPos||180,C.maxX=typeof C.options.maxPos<"u"&&!Number.isNaN(+C.options.maxPos)?+C.options.maxPos:180,C.minY=C.options.minY||C.minX,C.maxY=C.options.maxY||C.maxX,C.maxZoom=19,C.maxWidth=C.maxX-C.minX,C.animate=r,C.uuid=Ag.nice(),C.refreshTilesDebounced=E7(C.refreshTiles.bind(t1e(C)),jX),C}return ODt(I,[{key:"visibleAndFetchedIds",value:function(){return Object.keys(this.fetchedTiles).filter(n=>this.visibleTileIds.has(n))}},{key:"visibleAndFetchedTiles",value:function(){return this.visibleAndFetchedIds().map(n=>this.fetchedTiles[n])}},{key:"setVisibleTiles",value:function(n){this.visibleTiles=n.map(C=>({tileId:this.tileToLocalId(C),remoteId:this.tileToRemoteId(C),mirrored:C.mirrored})),this.visibleTileIds=new Set(this.visibleTiles.map(C=>C.tileId))}},{key:"removeAllTiles",value:function(){const n=new Set(Object.keys(this.fetchedTiles));this.removeTiles([...n])}},{key:"refreshTiles",value:function(){this.calculateVisibleTiles();const n=new Set(Object.keys(this.fetchedTiles)),C=[...this.visibleTiles].filter(o=>!this.fetching.has(o.remoteId)&&!n.has(o.tileId));for(let o=0;o!this.visibleTileIds.has(o));this.removeTiles(r),this.fetchNewTiles(C)}},{key:"removeTiles",value:function(n){n.length&&this.areAllVisibleTilesLoaded()&&(n.forEach(C=>{const r=C;this.destroyTile(this.fetchedTiles[r]),r in this.tileGraphics&&(this.pMain.removeChild(this.tileGraphics[r]),delete this.tileGraphics[r]),delete this.fetchedTiles[r]}),this.synchronizeTilesAndGraphics(),this.draw())}},{key:"tileToLocalId",value:function(n){return n.join(".")}},{key:"tileToRemoteId",value:function(n){return n.join(".")}},{key:"localToRemoteId",value:function(n){const C=n.split(".");return C.slice(0,C.length-1).join(".")}},{key:"calculateZoomLevel",value:function(){const n=Gt.calculateZoomLevel(this._xScale,this.minX,this.maxX),C=Gt.calculateZoomLevel(this._xScale,this.minY,this.maxY);let r=Math.min(Math.max(n,C),this.maxZoom);return this.options.maxZoom&&(this.options.maxZoom>=0?r=Math.min(this.options.maxZoom,r):console.error("Invalid maxZoom on track:",this)),r}},{key:"calculateVisibleTiles",value:function(){this.zoomLevel=this.calculateZoomLevel(),this.xTiles=Gt.calculateTiles(this.zoomLevel,this._xScale,this.minX,this.maxX,this.maxZoom,this.maxWidth),this.yTiles=Gt.calculateTiles(this.zoomLevel,this._yScale,this.minY,this.maxY,this.maxZoom,this.maxWidth);const n=this.xTiles,C=this.yTiles,r=this.zoomLevel,o=[];for(let A=0;A0){const C=[...new Set(n.map(r=>r.remoteId))];for(const r of C){const o=r.split("."),A=this.getTileUrl(o),s=new Image;s.crossOrigin="Anonymous",s.src=A,s.onload=()=>{const a={};a[r]={tileId:r,img:s,zoomLevel:+o[0],tilePos:[+o[1],+o[2]],tileSrc:A},this.receivedTiles(a)}}}}},{key:"receivedTiles",value:function(n){for(let C=0;C"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function Qb(e){return Qb=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},Qb(e)}let g1e=function(e){nxt(I,e);var g=Cxt(I);function I(){return ext(this,I),g.apply(this,arguments)}return txt(I,[{key:"initTile",value:function(n){HVe.bind(this)(n),this.drawTile(n)}},{key:"drawTile",value:function(n){XVe.bind(this)(n)}},{key:"areAllVisibleTilesLoaded",value:function(){return!0}},{key:"fetchNewTiles",value:function(n){n.forEach(C=>{const o=C.remoteId.split("."),A={zoomLevel:o[0],tilePos:o.slice(1,o.length).map(s=>+s)};this.fetchedTiles[C.tileId]=C,this.fetchedTiles[C.tileId].tileData=A,this.fetching.has(C.remoteId)&&this.fetching.delete(C.remoteId)}),this.synchronizeTilesAndGraphics(),this.draw(),this.animate()}},{key:"draw",value:function(){$1(Qb(I.prototype),"draw",this).call(this)}}]),I}($S);function axt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function poe(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function jb(e){return jb=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},jb(e)}let I1e=function(e){dxt(I,e);var g=hxt(I);function I(i,n){var C;return axt(this,I),C=g.call(this,i,n),C.style=n.style,C.options.accessToken||(C.errorTextText="No access token provided in the viewconf's track options ('accessToken' option).",C.drawError()),C}return sxt(I,[{key:"rerender",value:function(n){q1(jb(I.prototype),"rerender",this).call(this,n),n.style!==this.style&&(this.style=n.style,this.removeAllTiles(),this.refreshTiles())}},{key:"getTileUrl",value:function(n){const C=this.options&&this.options.style?this.options.style:"streets-v10",r=this.options&&+this.options.tileSize?+this.options.tileSize:256;return`https://api.mapbox.com/styles/v1/mapbox/${C}/tiles/${r}/${n[0]}/${n[1]}/${n[2]}?access_token=${this.options.accessToken}`}}]),I}($S);function bxt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function boe(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function x9(e){return x9=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},x9(e)}let i1e=function(e){vxt(I,e);var g=Bxt(I);function I(i,n){var C;return bxt(this,I),C=g.call(this,i,n),C.style=n.style,C.options.tileSource||(C.errorTextText="No tile source string provided in the options. It should be in the form of http://a.com/{z}/{x}/{y}",C.drawError()),C}return yxt(I,[{key:"getTileUrl",value:function(n){let C=this.options.tileSource.replace("{z}",n[0]);return C=C.replace("{x}",n[1]),C=C.replace("{y}",n[2]),C}}]),I}($S);const Rxt=(e,g,I,i=w2)=>{const n=I[e.type];return n?new n.dataFetcher(i,e,g):e.type==="genbank"?new RVe(e,g):e.type==="local-tiles"?new WVe(e,g):new qN(e,g)};var zt=1e-6,TB=1e-12,Cg=Math.PI,LI=Cg/2,F9=Cg/4,nC=Cg*2,$g=180/Cg,Ot=Cg/180,Bg=Math.abs,Q0=Math.atan,CC=Math.atan2,Tt=Math.cos,dR=Math.ceil,n1e=Math.exp,WP=Math.hypot,E9=Math.log,dx=Math.pow,Bt=Math.sin,Jr=Math.sign||function(e){return e>0?1:e<0?-1:0},Oi=Math.sqrt,Vj=Math.tan;function C1e(e){return e>1?0:e<-1?Cg:Math.acos(e)}function rC(e){return e>1?LI:e<-1?-LI:Math.asin(e)}function yoe(e){return(e=Bt(e/2))*e}function DI(){}function M9(e,g){e&&Goe.hasOwnProperty(e.type)&&Goe[e.type](e,g)}var Zoe={Feature:function(e,g){M9(e.geometry,g)},FeatureCollection:function(e,g){for(var I=e.features,i=-1,n=I.length;++i=0?1:-1,n=i*I,C=Tt(g),r=Bt(g),o=NP*r,A=TP*C+o*Tt(n),s=o*i*Bt(n);z9.add(CC(s,A)),HP=e,TP=C,NP=r}function Txt(e){return P9=new Xi,Po(e,fa),P9*2}function J9(e){return[CC(e[1],e[0]),rC(e[2])]}function Gh(e){var g=e[0],I=e[1],i=Tt(I);return[i*Tt(g),i*Bt(g),Bt(I)]}function hR(e,g){return e[0]*g[0]+e[1]*g[1]+e[2]*g[2]}function $b(e,g){return[e[1]*g[2]-e[2]*g[1],e[2]*g[0]-e[0]*g[2],e[0]*g[1]-e[1]*g[0]]}function hx(e,g){e[0]+=g[0],e[1]+=g[1],e[2]+=g[2]}function mR(e,g){return[e[0]*g,e[1]*g,e[2]*g]}function O9(e){var g=Oi(e[0]*e[0]+e[1]*e[1]+e[2]*e[2]);e[0]/=g,e[1]/=g,e[2]/=g}var NI,wC,OI,qC,Eu,a1e,s1e,Fp,lv,Dl,Fs,es={point:kP,lineStart:Boe,lineEnd:Soe,polygonStart:function(){es.point=c1e,es.lineStart=Nxt,es.lineEnd=kxt,lv=new Xi,fa.polygonStart()},polygonEnd:function(){fa.polygonEnd(),es.point=kP,es.lineStart=Boe,es.lineEnd=Soe,z9<0?(NI=-(OI=180),wC=-(qC=90)):lv>zt?qC=90:lv<-zt&&(wC=-90),Fs[0]=NI,Fs[1]=OI},sphere:function(){NI=-(OI=180),wC=-(qC=90)}};function kP(e,g){Dl.push(Fs=[NI=e,OI=e]),gqC&&(qC=g)}function l1e(e,g){var I=Gh([e*Ot,g*Ot]);if(Fp){var i=$b(Fp,I),n=[i[1],-i[0],0],C=$b(n,i);O9(C),C=J9(C);var r=e-Eu,o=r>0?1:-1,A=C[0]*$g*o,s,a=Bg(r)>180;a^(o*EuqC&&(qC=s)):(A=(A+360)%360-180,a^(o*EuqC&&(qC=g))),a?eUC(NI,OI)&&(OI=e):UC(e,OI)>UC(NI,OI)&&(NI=e):OI>=NI?(eOI&&(OI=e)):e>Eu?UC(NI,e)>UC(NI,OI)&&(OI=e):UC(e,OI)>UC(NI,OI)&&(NI=e)}else Dl.push(Fs=[NI=e,OI=e]);gqC&&(qC=g),Fp=I,Eu=e}function Boe(){es.point=l1e}function Soe(){Fs[0]=NI,Fs[1]=OI,es.point=kP,Fp=null}function c1e(e,g){if(Fp){var I=e-Eu;lv.add(Bg(I)>180?I+(I>0?360:-360):I)}else a1e=e,s1e=g;fa.point(e,g),l1e(e,g)}function Nxt(){fa.lineStart()}function kxt(){c1e(a1e,s1e),fa.lineEnd(),Bg(lv)>zt&&(NI=-(OI=180)),Fs[0]=NI,Fs[1]=OI,Fp=null}function UC(e,g){return(g-=e)<0?g+360:g}function Yxt(e,g){return e[0]-g[0]}function woe(e,g){return e[0]<=e[1]?e[0]<=g&&g<=e[1]:gUC(i[0],i[1])&&(i[1]=n[1]),UC(n[0],i[1])>UC(i[0],i[1])&&(i[0]=n[0])):C.push(i=n);for(r=-1/0,I=C.length-1,g=0,i=C[I];g<=I;i=n,++g)n=C[g],(o=UC(i[1],n[0]))>r&&(r=o,NI=n[0],OI=i[1])}return Dl=Fs=null,NI===1/0||wC===1/0?[[NaN,NaN],[NaN,NaN]]:[[NI,wC],[OI,qC]]}var MZ,_9,L9,U9,Q9,j9,$9,q9,YP,KP,DP,u1e,d1e,Un,Qn,jn,Lo={sphere:DI,point:Rj,lineStart:Voe,lineEnd:Roe,polygonStart:function(){Lo.lineStart=Fxt,Lo.lineEnd=Ext},polygonEnd:function(){Lo.lineStart=Voe,Lo.lineEnd=Roe}};function Rj(e,g){e*=Ot,g*=Ot;var I=Tt(g);qS(I*Tt(e),I*Bt(e),Bt(g))}function qS(e,g,I){++MZ,L9+=(e-L9)/MZ,U9+=(g-U9)/MZ,Q9+=(I-Q9)/MZ}function Voe(){Lo.point=Dxt}function Dxt(e,g){e*=Ot,g*=Ot;var I=Tt(g);Un=I*Tt(e),Qn=I*Bt(e),jn=Bt(g),Lo.point=xxt,qS(Un,Qn,jn)}function xxt(e,g){e*=Ot,g*=Ot;var I=Tt(g),i=I*Tt(e),n=I*Bt(e),C=Bt(g),r=CC(Oi((r=Qn*C-jn*n)*r+(r=jn*i-Un*C)*r+(r=Un*n-Qn*i)*r),Un*i+Qn*n+jn*C);_9+=r,j9+=r*(Un+(Un=i)),$9+=r*(Qn+(Qn=n)),q9+=r*(jn+(jn=C)),qS(Un,Qn,jn)}function Roe(){Lo.point=Rj}function Fxt(){Lo.point=Mxt}function Ext(){h1e(u1e,d1e),Lo.point=Rj}function Mxt(e,g){u1e=e,d1e=g,e*=Ot,g*=Ot,Lo.point=h1e;var I=Tt(g);Un=I*Tt(e),Qn=I*Bt(e),jn=Bt(g),qS(Un,Qn,jn)}function h1e(e,g){e*=Ot,g*=Ot;var I=Tt(g),i=I*Tt(e),n=I*Bt(e),C=Bt(g),r=Qn*C-jn*n,o=jn*i-Un*C,A=Un*n-Qn*i,s=WP(r,o,A),a=rC(s),l=s&&-a/s;YP.add(l*r),KP.add(l*o),DP.add(l*A),_9+=a,j9+=a*(Un+(Un=i)),$9+=a*(Qn+(Qn=n)),q9+=a*(jn+(jn=C)),qS(Un,Qn,jn)}function zxt(e){MZ=_9=L9=U9=Q9=j9=$9=q9=0,YP=new Xi,KP=new Xi,DP=new Xi,Po(e,Lo);var g=+YP,I=+KP,i=+DP,n=WP(g,I,i);return nCg?e+Math.round(-e/nC)*nC:e,g]}FP.invert=FP;function Wj(e,g,I){return(e%=nC)?g||I?xP(Xoe(e),Hoe(g,I)):Xoe(e):g||I?Hoe(g,I):FP}function Woe(e){return function(g,I){return g+=e,[g>Cg?g-nC:g<-Cg?g+nC:g,I]}}function Xoe(e){var g=Woe(e);return g.invert=Woe(-e),g}function Hoe(e,g){var I=Tt(e),i=Bt(e),n=Tt(g),C=Bt(g);function r(o,A){var s=Tt(A),a=Tt(o)*s,l=Bt(o)*s,c=Bt(A),u=c*I+a*i;return[CC(l*n-u*C,a*I-c*i),rC(u*n+l*C)]}return r.invert=function(o,A){var s=Tt(A),a=Tt(o)*s,l=Bt(o)*s,c=Bt(A),u=c*n-l*C;return[CC(l*n+c*C,a*I+u*i),rC(u*I-a*i)]},r}function m1e(e){e=Wj(e[0]*Ot,e[1]*Ot,e.length>2?e[2]*Ot:0);function g(I){return I=e(I[0]*Ot,I[1]*Ot),I[0]*=$g,I[1]*=$g,I}return g.invert=function(I){return I=e.invert(I[0]*Ot,I[1]*Ot),I[0]*=$g,I[1]*=$g,I},g}function f1e(e,g,I,i,n,C){if(I){var r=Tt(g),o=Bt(g),A=i*I;n==null?(n=g+i*nC,C=g-A/2):(n=Toe(r,n),C=Toe(r,C),(i>0?nC)&&(n+=i*nC));for(var s,a=n;i>0?a>C:a1&&e.push(e.pop().concat(e.shift()))},result:function(){var I=e;return e=[],g=null,I}}}function eW(e,g){return Bg(e[0]-g[0])=0;--o)n.point((l=a[o])[0],l[1]);else i(c.x,c.p.x,-1,n);c=c.p}c=c.o,a=c.z,u=!u}while(!c.v);n.lineEnd()}}}function Noe(e){if(g=e.length){for(var g,I=0,i=e[0],n;++I=0?1:-1,V=w*v,S=V>Cg,X=m*B;if(A.add(CC(X*w*Bt(V),f*G+X*Tt(V))),r+=S?v+w*nC:v,S^d>=I^y>=I){var W=$b(Gh(u),Gh(p));O9(W);var R=$b(C,W);O9(R);var H=(S^v>=0?-1:1)*rC(R[2]);(i>H||i===H&&(W[0]||W[1]))&&(o+=S^v>=0?1:-1)}}return(r<-zt||r0){for(A||(n.polygonStart(),A=!0),n.lineStart(),B=0;B1&&y&2&&Z.push(Z.pop().concat(Z.shift())),a.push(Z.filter(Jxt))}}return c}}function Jxt(e){return e.length>1}function Oxt(e,g){return((e=e.x)[0]<0?e[1]-LI-zt:LI-e[1])-((g=g.x)[0]<0?g[1]-LI-zt:LI-g[1])}const EP=Z1e(function(){return!0},_xt,Uxt,[-Cg,-LI]);function _xt(e){var g=NaN,I=NaN,i=NaN,n;return{lineStart:function(){e.lineStart(),n=1},point:function(C,r){var o=C>0?Cg:-Cg,A=Bg(C-g);Bg(A-Cg)0?LI:-LI),e.point(i,I),e.lineEnd(),e.lineStart(),e.point(o,I),e.point(C,I),n=0):i!==o&&A>=Cg&&(Bg(g-i)zt?Q0((Bt(g)*(C=Tt(i))*Bt(I)-Bt(i)*(n=Tt(g))*Bt(e))/(n*C*r)):(g+i)/2}function Uxt(e,g,I,i){var n;if(e==null)n=I*LI,i.point(-Cg,n),i.point(0,n),i.point(Cg,n),i.point(Cg,0),i.point(Cg,-n),i.point(0,-n),i.point(-Cg,-n),i.point(-Cg,0),i.point(-Cg,n);else if(Bg(e[0]-g[0])>zt){var C=e[0]0,n=Bg(g)>zt;function C(a,l,c,u){f1e(u,e,I,c,a,l)}function r(a,l){return Tt(a)*Tt(l)>g}function o(a){var l,c,u,d,h;return{lineStart:function(){d=u=!1,h=1},point:function(m,f){var b=[m,f],p,y=r(m,f),Z=i?y?0:s(m,f):y?s(m+(m<0?Cg:-Cg),f):0;if(!l&&(d=u=y)&&a.lineStart(),y!==u&&(p=A(l,b),(!p||eW(l,p)||eW(b,p))&&(b[2]=1)),y!==u)h=0,y?(a.lineStart(),p=A(b,l),a.point(p[0],p[1])):(p=A(l,b),a.point(p[0],p[1],2),a.lineEnd()),l=p;else if(n&&l&&i^y){var B;!(Z&c)&&(B=A(b,l,!0))&&(h=0,i?(a.lineStart(),a.point(B[0][0],B[0][1]),a.point(B[1][0],B[1][1]),a.lineEnd()):(a.point(B[1][0],B[1][1]),a.lineEnd(),a.lineStart(),a.point(B[0][0],B[0][1],3)))}y&&(!l||!eW(l,b))&&a.point(b[0],b[1]),l=b,u=y,c=Z},lineEnd:function(){u&&a.lineEnd(),l=null},clean:function(){return h|(d&&u)<<1}}}function A(a,l,c){var u=Gh(a),d=Gh(l),h=[1,0,0],m=$b(u,d),f=hR(m,m),b=m[0],p=f-b*b;if(!p)return!c&&a;var y=g*f/p,Z=-g*b/p,B=$b(h,m),G=mR(h,y),v=mR(m,Z);hx(G,v);var w=B,V=hR(G,w),S=hR(w,w),X=V*V-S*(hR(G,G)-1);if(!(X<0)){var W=Oi(X),R=mR(w,(-V-W)/S);if(hx(R,G),R=J9(R),!c)return R;var H=a[0],Y=l[0],D=a[1],E=l[1],O;Y0^R[1]<(Bg(R[0]-H)Cg^(H<=R[0]&&R[0]<=Y)){var $=mR(w,(-V+W)/S);return hx($,G),[R,J9($)]}}}function s(a,l){var c=i?e:Cg-e,u=0;return a<-c?u|=1:a>c&&(u|=2),l<-c?u|=4:l>c&&(u|=8),u}return Z1e(r,o,C,i?[0,-e]:[-Cg,e-Cg])}function Qxt(e,g,I,i,n,C){var r=e[0],o=e[1],A=g[0],s=g[1],a=0,l=1,c=A-r,u=s-o,d;if(d=I-r,!(!c&&d>0)){if(d/=c,c<0){if(d0){if(d>l)return;d>a&&(a=d)}if(d=n-r,!(!c&&d<0)){if(d/=c,c<0){if(d>l)return;d>a&&(a=d)}else if(c>0){if(d0)){if(d/=u,u<0){if(d0){if(d>l)return;d>a&&(a=d)}if(d=C-o,!(!u&&d<0)){if(d/=u,u<0){if(d>l)return;d>a&&(a=d)}else if(u>0){if(d0&&(e[0]=r+a*c,e[1]=o+a*u),l<1&&(g[0]=r+l*c,g[1]=o+l*u),!0}}}}}var zZ=1e9,pR=-zZ;function Ak(e,g,I,i){function n(s,a){return e<=s&&s<=I&&g<=a&&a<=i}function C(s,a,l,c){var u=0,d=0;if(s==null||(u=r(s,l))!==(d=r(a,l))||A(s,a)<0^l>0)do c.point(u===0||u===3?e:I,u>1?i:g);while((u=(u+l+4)%4)!==d);else c.point(a[0],a[1])}function r(s,a){return Bg(s[0]-e)0?0:3:Bg(s[0]-I)0?2:1:Bg(s[1]-g)0?1:0:a>0?3:2}function o(s,a){return A(s.x,a.x)}function A(s,a){var l=r(s,1),c=r(a,1);return l!==c?l-c:l===0?a[1]-s[1]:l===1?s[0]-a[0]:l===2?s[1]-a[1]:a[0]-s[0]}return function(s){var a=s,l=p1e(),c,u,d,h,m,f,b,p,y,Z,B,G={point:v,lineStart:X,lineEnd:W,polygonStart:V,polygonEnd:S};function v(H,Y){n(H,Y)&&a.point(H,Y)}function w(){for(var H=0,Y=0,D=u.length;Yi&&(j-q)*(i-$)>(te-$)*(e-q)&&++H:te<=i&&(j-q)*(i-$)<(te-$)*(e-q)&&--H;return H}function V(){a=l,c=[],u=[],B=!0}function S(){var H=w(),Y=B&&H,D=(c=EU(c)).length;(Y||D)&&(s.polygonStart(),Y&&(s.lineStart(),C(null,null,1,s),s.lineEnd()),D&&b1e(c,o,H,C,s),s.polygonEnd()),a=s,c=u=d=null}function X(){G.point=R,u&&u.push(d=[]),Z=!0,y=!1,b=p=NaN}function W(){c&&(R(h,m),f&&y&&l.rejoin(),c.push(l.result())),G.point=v,y&&a.lineEnd()}function R(H,Y){var D=n(H,Y);if(u&&d.push([H,Y]),Z)h=H,m=Y,f=D,Z=!1,D&&(a.lineStart(),a.point(H,Y));else if(D&&y)a.point(H,Y);else{var E=[b=Math.max(pR,Math.min(zZ,b)),p=Math.max(pR,Math.min(zZ,p))],O=[H=Math.max(pR,Math.min(zZ,H)),Y=Math.max(pR,Math.min(zZ,Y))];Qxt(E,O,e,g,I,i)?(y||(a.lineStart(),a.point(E[0],E[1])),a.point(O[0],O[1]),D||a.lineEnd(),B=!1):D&&(a.lineStart(),a.point(H,Y),B=!1)}b=H,p=Y,y=D}return G}}function jxt(){var e=0,g=0,I=960,i=500,n,C,r;return r={stream:function(o){return n&&C===o?n:n=Ak(e,g,I,i)(C=o)},extent:function(o){return arguments.length?(e=+o[0][0],g=+o[0][1],I=+o[1][0],i=+o[1][1],n=C=null,r):[[e,g],[I,i]]}}}var MP,zP,tW,gW,qb={sphere:DI,point:DI,lineStart:$xt,lineEnd:DI,polygonStart:DI,polygonEnd:DI};function $xt(){qb.point=eFt,qb.lineEnd=qxt}function qxt(){qb.point=qb.lineEnd=DI}function eFt(e,g){e*=Ot,g*=Ot,zP=e,tW=Bt(g),gW=Tt(g),qb.point=tFt}function tFt(e,g){e*=Ot,g*=Ot;var I=Bt(g),i=Tt(g),n=Bg(e-zP),C=Tt(n),r=Bt(n),o=i*r,A=gW*I-tW*i*C,s=tW*I+gW*i*C;MP.add(CC(Oi(o*o+A*A),s)),zP=e,tW=I,gW=i}function v1e(e){return MP=new Xi,Po(e,qb),+MP}var PP=[null,null],gFt={type:"LineString",coordinates:PP};function e2(e,g){return PP[0]=e,PP[1]=g,v1e(gFt)}var koe={Feature:function(e,g){return t2(e.geometry,g)},FeatureCollection:function(e,g){for(var I=e.features,i=-1,n=I.length;++i0&&(n=e2(e[C],e[C-1]),n>0&&I<=n&&i<=n&&(I+i-n)*(1-Math.pow((I-i)/n,2))zt}).map(c)).concat(eC(dR(C/s)*s,n,s).filter(function(p){return Bg(p%l)>zt}).map(u))}return f.lines=function(){return b().map(function(p){return{type:"LineString",coordinates:p}})},f.outline=function(){return{type:"Polygon",coordinates:[d(i).concat(h(r).slice(1),d(I).reverse().slice(1),h(o).reverse().slice(1))]}},f.extent=function(p){return arguments.length?f.extentMajor(p).extentMinor(p):f.extentMinor()},f.extentMajor=function(p){return arguments.length?(i=+p[0][0],I=+p[1][0],o=+p[0][1],r=+p[1][1],i>I&&(p=i,i=I,I=p),o>r&&(p=o,o=r,r=p),f.precision(m)):[[i,o],[I,r]]},f.extentMinor=function(p){return arguments.length?(g=+p[0][0],e=+p[1][0],C=+p[0][1],n=+p[1][1],g>e&&(p=g,g=e,e=p),C>n&&(p=C,C=n,n=p),f.precision(m)):[[g,C],[e,n]]},f.step=function(p){return arguments.length?f.stepMajor(p).stepMinor(p):f.stepMinor()},f.stepMajor=function(p){return arguments.length?(a=+p[0],l=+p[1],f):[a,l]},f.stepMinor=function(p){return arguments.length?(A=+p[0],s=+p[1],f):[A,s]},f.precision=function(p){return arguments.length?(m=+p,c=Foe(C,n,90),u=Eoe(g,e,m),d=Foe(o,r,90),h=Eoe(i,I,m),f):m},f.extentMajor([[-180,-90+zt],[180,90-zt]]).extentMinor([[-180,-80-zt],[180,80+zt]])}function nFt(){return S1e()()}function CFt(e,g){var I=e[0]*Ot,i=e[1]*Ot,n=g[0]*Ot,C=g[1]*Ot,r=Tt(i),o=Bt(i),A=Tt(C),s=Bt(C),a=r*Tt(I),l=r*Bt(I),c=A*Tt(n),u=A*Bt(n),d=2*rC(Oi(yoe(C-i)+r*A*yoe(n-I))),h=Bt(d),m=d?function(f){var b=Bt(f*=d)/h,p=Bt(d-f)/h,y=p*a+b*c,Z=p*l+b*u,B=p*o+b*s;return[CC(Z,y)*$g,CC(B,Oi(y*y+Z*Z))*$g]}:function(){return[I*$g,i*$g]};return m.distance=d,m}const NB=e=>e;var fx=new Xi,JP=new Xi,w1e,V1e,OP,_P,Ql={point:DI,lineStart:DI,lineEnd:DI,polygonStart:function(){Ql.lineStart=rFt,Ql.lineEnd=AFt},polygonEnd:function(){Ql.lineStart=Ql.lineEnd=Ql.point=DI,fx.add(Bg(JP)),JP=new Xi},result:function(){var e=fx/2;return fx=new Xi,e}};function rFt(){Ql.point=oFt}function oFt(e,g){Ql.point=R1e,w1e=OP=e,V1e=_P=g}function R1e(e,g){JP.add(_P*e-OP*g),OP=e,_P=g}function AFt(){R1e(w1e,V1e)}const Moe=Ql;var e0=1/0,g2=e0,kB=-e0,I2=kB,aFt={point:sFt,lineStart:DI,lineEnd:DI,polygonStart:DI,polygonEnd:DI,result:function(){var e=[[e0,g2],[kB,I2]];return kB=I2=-(g2=e0=1/0),e}};function sFt(e,g){ekB&&(kB=e),gI2&&(I2=g)}const i2=aFt;var LP=0,UP=0,PZ=0,n2=0,C2=0,gp=0,QP=0,jP=0,JZ=0,W1e,X1e,UA,QA,Jo={point:vh,lineStart:zoe,lineEnd:Poe,polygonStart:function(){Jo.lineStart=uFt,Jo.lineEnd=dFt},polygonEnd:function(){Jo.point=vh,Jo.lineStart=zoe,Jo.lineEnd=Poe},result:function(){var e=JZ?[QP/JZ,jP/JZ]:gp?[n2/gp,C2/gp]:PZ?[LP/PZ,UP/PZ]:[NaN,NaN];return LP=UP=PZ=n2=C2=gp=QP=jP=JZ=0,e}};function vh(e,g){LP+=e,UP+=g,++PZ}function zoe(){Jo.point=lFt}function lFt(e,g){Jo.point=cFt,vh(UA=e,QA=g)}function cFt(e,g){var I=e-UA,i=g-QA,n=Oi(I*I+i*i);n2+=n*(UA+e)/2,C2+=n*(QA+g)/2,gp+=n,vh(UA=e,QA=g)}function Poe(){Jo.point=vh}function uFt(){Jo.point=hFt}function dFt(){H1e(W1e,X1e)}function hFt(e,g){Jo.point=H1e,vh(W1e=UA=e,X1e=QA=g)}function H1e(e,g){var I=e-UA,i=g-QA,n=Oi(I*I+i*i);n2+=n*(UA+e)/2,C2+=n*(QA+g)/2,gp+=n,n=QA*e-UA*g,QP+=n*(UA+e),jP+=n*(QA+g),JZ+=n*3,vh(UA=e,QA=g)}const Joe=Jo;function T1e(e){this._context=e}T1e.prototype={_radius:4.5,pointRadius:function(e){return this._radius=e,this},polygonStart:function(){this._line=0},polygonEnd:function(){this._line=NaN},lineStart:function(){this._point=0},lineEnd:function(){this._line===0&&this._context.closePath(),this._point=NaN},point:function(e,g){switch(this._point){case 0:{this._context.moveTo(e,g),this._point=1;break}case 1:{this._context.lineTo(e,g);break}default:{this._context.moveTo(e+this._radius,g),this._context.arc(e,g,this._radius,0,nC);break}}},result:DI};var $P=new Xi,px,N1e,k1e,OZ,_Z,r2={point:DI,lineStart:function(){r2.point=mFt},lineEnd:function(){px&&Y1e(N1e,k1e),r2.point=DI},polygonStart:function(){px=!0},polygonEnd:function(){px=null},result:function(){var e=+$P;return $P=new Xi,e}};function mFt(e,g){r2.point=Y1e,N1e=OZ=e,k1e=_Z=g}function Y1e(e,g){OZ-=e,_Z-=g,$P.add(Oi(OZ*OZ+_Z*_Z)),OZ=e,_Z=g}const Ooe=r2;function K1e(){this._string=[]}K1e.prototype={_radius:4.5,_circle:_oe(4.5),pointRadius:function(e){return(e=+e)!==this._radius&&(this._radius=e,this._circle=null),this},polygonStart:function(){this._line=0},polygonEnd:function(){this._line=NaN},lineStart:function(){this._point=0},lineEnd:function(){this._line===0&&this._string.push("Z"),this._point=NaN},point:function(e,g){switch(this._point){case 0:{this._string.push("M",e,",",g),this._point=1;break}case 1:{this._string.push("L",e,",",g);break}default:{this._circle==null&&(this._circle=_oe(this._radius)),this._string.push("M",e,",",g,this._circle);break}}},result:function(){if(this._string.length){var e=this._string.join("");return this._string=[],e}else return null}};function _oe(e){return"m0,"+e+"a"+e+","+e+" 0 1,1 0,"+-2*e+"a"+e+","+e+" 0 1,1 0,"+2*e+"z"}function fFt(e,g){var I=4.5,i,n;function C(r){return r&&(typeof I=="function"&&n.pointRadius(+I.apply(this,arguments)),Po(r,i(n))),n.result()}return C.area=function(r){return Po(r,i(Moe)),Moe.result()},C.measure=function(r){return Po(r,i(Ooe)),Ooe.result()},C.bounds=function(r){return Po(r,i(i2)),i2.result()},C.centroid=function(r){return Po(r,i(Joe)),Joe.result()},C.projection=function(r){return arguments.length?(i=r==null?(e=null,NB):(e=r).stream,C):e},C.context=function(r){return arguments.length?(n=r==null?(g=null,new K1e):new T1e(g=r),typeof I!="function"&&n.pointRadius(I),C):g},C.pointRadius=function(r){return arguments.length?(I=typeof r=="function"?r:(n.pointRadius(+r),+r),C):I},C.projection(e).context(g)}function pFt(e){return{stream:ew(e)}}function ew(e){return function(g){var I=new qP;for(var i in e)I[i]=e[i];return I.stream=g,I}}function qP(){}qP.prototype={constructor:qP,point:function(e,g){this.stream.point(e,g)},sphere:function(){this.stream.sphere()},lineStart:function(){this.stream.lineStart()},lineEnd:function(){this.stream.lineEnd()},polygonStart:function(){this.stream.polygonStart()},polygonEnd:function(){this.stream.polygonEnd()}};function Xj(e,g,I){var i=e.clipExtent&&e.clipExtent();return e.scale(150).translate([0,0]),i!=null&&e.clipExtent(null),Po(I,e.stream(i2)),g(i2.result()),i!=null&&e.clipExtent(i),e}function ak(e,g,I){return Xj(e,function(i){var n=g[1][0]-g[0][0],C=g[1][1]-g[0][1],r=Math.min(n/(i[1][0]-i[0][0]),C/(i[1][1]-i[0][1])),o=+g[0][0]+(n-r*(i[1][0]+i[0][0]))/2,A=+g[0][1]+(C-r*(i[1][1]+i[0][1]))/2;e.scale(150*r).translate([o,A])},I)}function Hj(e,g,I){return ak(e,[[0,0],g],I)}function Tj(e,g,I){return Xj(e,function(i){var n=+g,C=n/(i[1][0]-i[0][0]),r=(n-C*(i[1][0]+i[0][0]))/2,o=-C*i[0][1];e.scale(150*C).translate([r,o])},I)}function Nj(e,g,I){return Xj(e,function(i){var n=+g,C=n/(i[1][1]-i[0][1]),r=-C*i[0][0],o=(n-C*(i[1][1]+i[0][1]))/2;e.scale(150*C).translate([r,o])},I)}var Loe=16,bFt=Tt(30*Ot);function Uoe(e,g){return+g?ZFt(e,g):yFt(e)}function yFt(e){return ew({point:function(g,I){g=e(g,I),this.stream.point(g[0],g[1])}})}function ZFt(e,g){function I(i,n,C,r,o,A,s,a,l,c,u,d,h,m){var f=s-i,b=a-n,p=f*f+b*b;if(p>4*g&&h--){var y=r+c,Z=o+u,B=A+d,G=Oi(y*y+Z*Z+B*B),v=rC(B/=G),w=Bg(Bg(B)-1)g||Bg((f*W+b*R)/p-.5)>.3||r*c+o*u+A*d2?H[2]%360*Ot:0,W()):[o*$g,A*$g,s*$g]},S.angle=function(H){return arguments.length?(l=H%360*Ot,W()):l*$g},S.reflectX=function(H){return arguments.length?(c=H?-1:1,W()):c<0},S.reflectY=function(H){return arguments.length?(u=H?-1:1,W()):u<0},S.precision=function(H){return arguments.length?(B=Uoe(G,Z=H*H),R()):Oi(Z)},S.fitExtent=function(H,Y){return ak(S,H,Y)},S.fitSize=function(H,Y){return Hj(S,H,Y)},S.fitWidth=function(H,Y){return Tj(S,H,Y)},S.fitHeight=function(H,Y){return Nj(S,H,Y)};function W(){var H=Qoe(I,0,0,c,u,l).apply(null,g(C,r)),Y=Qoe(I,i-H[0],n-H[1],c,u,l);return a=Wj(o,A,s),G=xP(g,Y),v=xP(a,G),B=Uoe(G,Z),R()}function R(){return w=V=null,S}return function(){return g=e.apply(this,arguments),S.invert=g.invert&&X,W()}}function Yj(e){var g=0,I=Cg/3,i=kj(e),n=i(g,I);return n.parallels=function(C){return arguments.length?i(g=C[0]*Ot,I=C[1]*Ot):[g*$g,I*$g]},n}function SFt(e){var g=Tt(e);function I(i,n){return[i*g,Bt(n)/g]}return I.invert=function(i,n){return[i/g,rC(n*g)]},I}function D1e(e,g){var I=Bt(e),i=(I+Bt(g))/2;if(Bg(i)=.12&&m<.234&&h>=-.425&&h<-.214?n:m>=.166&&m<.234&&h>=-.214&&h<-.115?r:I).invert(c)},a.stream=function(c){return e&&g===c?e:e=wFt([I.stream(g=c),n.stream(c),r.stream(c)])},a.precision=function(c){return arguments.length?(I.precision(c),n.precision(c),r.precision(c),l()):I.precision()},a.scale=function(c){return arguments.length?(I.scale(c),n.scale(c*.35),r.scale(c),a.translate(I.translate())):I.scale()},a.translate=function(c){if(!arguments.length)return I.translate();var u=I.scale(),d=+c[0],h=+c[1];return i=I.translate(c).clipExtent([[d-.455*u,h-.238*u],[d+.455*u,h+.238*u]]).stream(s),C=n.translate([d-.307*u,h+.201*u]).clipExtent([[d-.425*u+zt,h+.12*u+zt],[d-.214*u-zt,h+.234*u-zt]]).stream(s),o=r.translate([d-.205*u,h+.212*u]).clipExtent([[d-.214*u+zt,h+.166*u+zt],[d-.115*u-zt,h+.234*u-zt]]).stream(s),l()},a.fitExtent=function(c,u){return ak(a,c,u)},a.fitSize=function(c,u){return Hj(a,c,u)},a.fitWidth=function(c,u){return Tj(a,c,u)},a.fitHeight=function(c,u){return Nj(a,c,u)};function l(){return e=g=null,a}return a.scale(1070)}function F1e(e){return function(g,I){var i=Tt(g),n=Tt(I),C=e(i*n);return C===1/0?[2,0]:[C*n*Bt(g),C*Bt(I)]}}function tw(e){return function(g,I){var i=Oi(g*g+I*I),n=e(i),C=Bt(n),r=Tt(n);return[CC(g*C,i*r),rC(i&&I*C/i)]}}var Kj=F1e(function(e){return Oi(2/(1+e))});Kj.invert=tw(function(e){return 2*rC(e/2)});function RFt(){return Va(Kj).scale(124.75).clipAngle(180-.001)}var Dj=F1e(function(e){return(e=C1e(e))&&e/Bt(e)});Dj.invert=tw(function(e){return e});function WFt(){return Va(Dj).scale(79.4188).clipAngle(180-.001)}function gw(e,g){return[e,E9(Vj((LI+g)/2))]}gw.invert=function(e,g){return[e,2*Q0(n1e(g))-LI]};function XFt(){return E1e(gw).scale(961/nC)}function E1e(e){var g=Va(e),I=g.center,i=g.scale,n=g.translate,C=g.clipExtent,r=null,o,A,s;g.scale=function(l){return arguments.length?(i(l),a()):i()},g.translate=function(l){return arguments.length?(n(l),a()):n()},g.center=function(l){return arguments.length?(I(l),a()):I()},g.clipExtent=function(l){return arguments.length?(l==null?r=o=A=s=null:(r=+l[0][0],o=+l[0][1],A=+l[1][0],s=+l[1][1]),a()):r==null?null:[[r,o],[A,s]]};function a(){var l=Cg*i(),c=g(m1e(g.rotate()).invert([0,0]));return C(r==null?[[c[0]-l,c[1]-l],[c[0]+l,c[1]+l]]:e===gw?[[Math.max(c[0]-l,r),o],[Math.min(c[0]+l,A),s]]:[[r,Math.max(c[1]-l,o)],[A,Math.min(c[1]+l,s)]])}return a()}function bR(e){return Vj((LI+e)/2)}function M1e(e,g){var I=Tt(e),i=e===g?Bt(e):E9(I/Tt(g))/E9(bR(g)/bR(e)),n=I*dx(bR(e),i)/i;if(!i)return gw;function C(r,o){n>0?o<-LI+zt&&(o=-LI+zt):o>LI-zt&&(o=LI-zt);var A=n/dx(bR(o),i);return[A*Bt(i*r),n-A*Tt(i*r)]}return C.invert=function(r,o){var A=n-o,s=Jr(i)*Oi(r*r+A*A),a=CC(r,Bg(A))*Jr(A);return A*i<0&&(a-=Cg*Jr(r)*Jr(A)),[a/i,2*Q0(dx(n/s,1/i))-LI]},C}function HFt(){return Yj(M1e).scale(109.5).parallels([30,30])}function YB(e,g){return[e,g]}YB.invert=YB;function TFt(){return Va(YB).scale(152.63)}function z1e(e,g){var I=Tt(e),i=e===g?Bt(e):(I-Tt(g))/(g-e),n=I/i+e;if(Bg(i)zt&&--i>0);return[e/(.8707+(C=I*I)*(-.131979+C*(-.013791+C*C*C*(.003971-.001529*C)))),I]};function xFt(){return Va(Ej).scale(175.295)}function Mj(e,g){return[Tt(g)*Bt(e),Bt(g)]}Mj.invert=tw(rC);function FFt(){return Va(Mj).scale(249.5).clipAngle(90+zt)}function zj(e,g){var I=Tt(g),i=1+Tt(e)*I;return[I*Bt(e)/i,Bt(g)/i]}zj.invert=tw(function(e){return 2*Q0(e)});function EFt(){return Va(zj).scale(250).clipAngle(142)}function Pj(e,g){return[E9(Vj((LI+g)/2)),-e]}Pj.invert=function(e,g){return[-g,2*Q0(n1e(e))-LI]};function MFt(){var e=E1e(Pj),g=e.center,I=e.rotate;return e.center=function(i){return arguments.length?g([-i[1],i[0]]):(i=g(),[i[1],-i[0]])},e.rotate=function(i){return arguments.length?I([i[0],i[1],i.length>2?i[2]+90:90]):(i=I(),[i[0],i[1],i[2]-90])},I([0,0,90]).scale(159.155)}const zFt=Object.freeze(Object.defineProperty({__proto__:null,geoAlbers:x1e,geoAlbersUsa:VFt,geoArea:Txt,geoAzimuthalEqualArea:RFt,geoAzimuthalEqualAreaRaw:Kj,geoAzimuthalEquidistant:WFt,geoAzimuthalEquidistantRaw:Dj,geoBounds:Kxt,geoCentroid:zxt,geoCircle:Pxt,geoClipAntimeridian:EP,geoClipCircle:G1e,geoClipExtent:jxt,geoClipRectangle:Ak,geoConicConformal:HFt,geoConicConformalRaw:M1e,geoConicEqualArea:o2,geoConicEqualAreaRaw:D1e,geoConicEquidistant:NFt,geoConicEquidistantRaw:z1e,geoContains:iFt,geoDistance:e2,geoEqualEarth:YFt,geoEqualEarthRaw:xj,geoEquirectangular:TFt,geoEquirectangularRaw:YB,geoGnomonic:KFt,geoGnomonicRaw:Fj,geoGraticule:S1e,geoGraticule10:nFt,geoIdentity:DFt,geoInterpolate:CFt,geoLength:v1e,geoMercator:XFt,geoMercatorRaw:gw,geoNaturalEarth1:xFt,geoNaturalEarth1Raw:Ej,geoOrthographic:FFt,geoOrthographicRaw:Mj,geoPath:fFt,geoProjection:Va,geoProjectionMutator:kj,geoRotation:m1e,geoStereographic:EFt,geoStereographicRaw:zj,geoStream:Po,geoTransform:pFt,geoTransverseMercator:MFt,geoTransverseMercatorRaw:Pj},Symbol.toStringTag,{value:"Module"}));var PFt=[].slice,JFt={};function eJ(e){this._size=e,this._call=this._error=null,this._tasks=[],this._data=[],this._waiting=this._active=this._ended=this._start=0}eJ.prototype=J1e.prototype={constructor:eJ,defer:function(e){if(typeof e!="function")throw new Error("invalid callback");if(this._call)throw new Error("defer after await");if(this._error!=null)return this;var g=PFt.call(arguments,1);return g.push(e),++this._waiting,this._tasks.push(g),P1e(this),this},abort:function(){return this._error==null&&Jj(this,new Error("abort")),this},await:function(e){if(typeof e!="function")throw new Error("invalid callback");if(this._call)throw new Error("multiple await");return this._call=function(g,I){e.apply(null,[g].concat(I))},a2(this),this},awaitAll:function(e){if(typeof e!="function")throw new Error("invalid callback");if(this._call)throw new Error("multiple await");return this._call=e,a2(this),this}};function P1e(e){if(!e._start)try{OFt(e)}catch(g){if(e._tasks[e._ended+e._active-1])Jj(e,g);else if(!e._data)throw g}}function OFt(e){for(;e._start=e._waiting&&e._active=0;)if((i=e._tasks[I])&&(e._tasks[I]=null,i.abort))try{i.abort()}catch{}e._active=NaN,a2(e)}function a2(e){if(!e._active&&e._call){var g=e._data;e._data=void 0,e._call(e._error,g)}}function J1e(e){if(e==null)e=1/0;else if(!((e=+e)>=1))throw new Error("invalid concurrency");return new eJ(e)}const LFt=Object.freeze(Object.defineProperty({__proto__:null,queue:J1e},Symbol.toStringTag,{value:"Module"}));var Zr="$";function s2(){}s2.prototype=Oj.prototype={constructor:s2,has:function(e){return Zr+e in this},get:function(e){return this[Zr+e]},set:function(e,g){return this[Zr+e]=g,this},remove:function(e){var g=Zr+e;return g in this&&delete this[g]},clear:function(){for(var e in this)e[0]===Zr&&delete this[e]},keys:function(){var e=[];for(var g in this)g[0]===Zr&&e.push(g.slice(1));return e},values:function(){var e=[];for(var g in this)g[0]===Zr&&e.push(this[g]);return e},entries:function(){var e=[];for(var g in this)g[0]===Zr&&e.push({key:g.slice(1),value:this[g]});return e},size:function(){var e=0;for(var g in this)g[0]===Zr&&++e;return e},empty:function(){for(var e in this)if(e[0]===Zr)return!1;return!0},each:function(e){for(var g in this)g[0]===Zr&&e(this[g],g.slice(1),this)}};function Oj(e,g){var I=new s2;if(e instanceof s2)e.each(function(o,A){I.set(A,o)});else if(Array.isArray(e)){var i=-1,n=e.length,C;if(g==null)for(;++i=0&&(i=I.slice(n+1),I=I.slice(0,n)),I&&!g.hasOwnProperty(I))throw new Error("unknown type: "+I);return{type:I,name:i}})}IW.prototype=O1e.prototype={constructor:IW,on:function(e,g){var I=this._,i=QFt(e+"",I),n,C=-1,r=i.length;if(arguments.length<2){for(;++C0)for(var I=new Array(n),i=0,n,C;i3&&c(u)};function c(u){var d=r.status,h;if(!d&&qFt(r)||d>=200&&d<300||d===304){if(s)try{h=s.call(I,r)}catch(m){i.call("error",I,m);return}else h=r;i.call("load",I,h)}else i.call("error",I,u)}if(r.onprogress=function(u){i.call("progress",I,u)},I={header:function(u,d){return u=(u+"").toLowerCase(),arguments.length<2?C.get(u):(d==null?C.remove(u):C.set(u,d+""),I)},mimeType:function(u){return arguments.length?(n=u==null?null:u+"",I):n},responseType:function(u){return arguments.length?(a=u,I):a},timeout:function(u){return arguments.length?(l=+u,I):l},user:function(u){return arguments.length<1?o:(o=u==null?null:u+"",I)},password:function(u){return arguments.length<1?A:(A=u==null?null:u+"",I)},response:function(u){return s=u,I},get:function(u,d){return I.send("GET",u,d)},post:function(u,d){return I.send("POST",u,d)},send:function(u,d,h){return r.open(u,e,!0,o,A),n!=null&&!C.has("accept")&&C.set("accept",n+",*/*"),r.setRequestHeader&&C.each(function(m,f){r.setRequestHeader(f,m)}),n!=null&&r.overrideMimeType&&r.overrideMimeType(n),a!=null&&(r.responseType=a),l>0&&(r.timeout=l),h==null&&typeof d=="function"&&(h=d,d=null),h!=null&&h.length===1&&(h=$Ft(h)),h!=null&&I.on("error",h).on("load",function(m){h(null,m)}),i.call("beforesend",I,r),r.send(d??null),I},abort:function(){return r.abort(),I},on:function(){var u=i.on.apply(i,arguments);return u===i?I:u}},g!=null){if(typeof g!="function")throw new Error("invalid callback: "+g);return I.get(g)}return I}function $Ft(e){return function(g,I){e(g==null?I:null)}}function qFt(e){var g=e.responseType;return g&&g!=="text"?e.response:e.responseText}function sk(e,g){return function(I,i){var n=_j(I).mimeType(e).response(g);if(i!=null){if(typeof i!="function")throw new Error("invalid callback: "+i);return n.get(i)}return n}}const eEt=sk("text/html",function(e){return document.createRange().createContextualFragment(e.responseText)}),tEt=sk("application/json",function(e){return JSON.parse(e.responseText)}),gEt=sk("text/plain",function(e){return e.responseText}),IEt=sk("application/xml",function(e){var g=e.responseXML;if(!g)throw new Error("parse error");return g});var qoe={},bx={},yx=34,gZ=10,Zx=13;function _1e(e){return new Function("d","return {"+e.map(function(g,I){return JSON.stringify(g)+": d["+I+'] || ""'}).join(",")+"}")}function iEt(e,g){var I=_1e(e);return function(i,n){return g(I(i),n,e)}}function eAe(e){var g=Object.create(null),I=[];return e.forEach(function(i){for(var n in i)n in g||I.push(g[n]=n)}),I}function yC(e,g){var I=e+"",i=I.length;return i9999?"+"+yC(e,6):yC(e,4)}function CEt(e){var g=e.getUTCHours(),I=e.getUTCMinutes(),i=e.getUTCSeconds(),n=e.getUTCMilliseconds();return isNaN(e)?"Invalid Date":nEt(e.getUTCFullYear())+"-"+yC(e.getUTCMonth()+1,2)+"-"+yC(e.getUTCDate(),2)+(n?"T"+yC(g,2)+":"+yC(I,2)+":"+yC(i,2)+"."+yC(n,3)+"Z":i?"T"+yC(g,2)+":"+yC(I,2)+":"+yC(i,2)+"Z":I||g?"T"+yC(g,2)+":"+yC(I,2)+"Z":"")}function L1e(e){var g=new RegExp('["'+e+` +\r]`),I=e.charCodeAt(0);function i(l,c){var u,d,h=n(l,function(m,f){if(u)return u(m,f-1);d=m,u=c?iEt(m,c):_1e(m)});return h.columns=d||[],h}function n(l,c){var u=[],d=l.length,h=0,m=0,f,b=d<=0,p=!1;l.charCodeAt(d-1)===gZ&&--d,l.charCodeAt(d-1)===Zx&&--d;function y(){if(b)return bx;if(p)return p=!1,qoe;var B,G=h,v;if(l.charCodeAt(G)===yx){for(;h++=d?b=!0:(v=l.charCodeAt(h++))===gZ?p=!0:v===Zx&&(p=!0,l.charCodeAt(h)===gZ&&++h),l.slice(G+1,B-1).replace(/""/g,'"')}for(;h"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function g2(g){return g2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},g2(g)}let iY=function(g){EDt(I,g);var e=MDt(I);function I({items:i}){var n;return KDt(this,I),n=e.call(this),n.state={items:i,isSorting:!1},n}return xDt(I,[{key:"UNSAFE_componentWillReceiveProps",value:function(n){this.setState({items:n.items})}},{key:"onSortStart",value:function({node:n,index:C,collection:r},o){o.stopImmediatePropagation();const{onSortStart:A}=this.props;this.setState({isSorting:!0}),A&&A(this.ref),this.sortingIndex=C,this.sortStartTop=o.offsetTop,this.sortStartLeft=o.offsetLeft}},{key:"onSortMove",value:function(){}},{key:"onSortEnd",value:function({oldIndex:n,newIndex:C}){const{onSortEnd:r}=this.props,{items:o}=this.state;this.setState({items:zrt(o,n,C),isSorting:!1}),r&&r(this.state.items),this.sortingIndex=null}},{key:"render",value:function(){const n=this.props.component,{items:C,isSorting:r}=this.state,o={isSorting:r,items:C,onSortEnd:this.onSortEnd.bind(this),onSortStart:this.onSortStart.bind(this),onSortMove:this.onSortMove.bind(this)};return N.createElement(n,YJ({},this.props,o,{ref:A=>{this.ref=A}}))}}]),I}(N.Component);iY.propTypes={axis:L.string,className:L.string,component:L.func,editable:L.bool,handleConfigTrack:L.func,handleResizeTrack:L.func,height:L.number,helperClass:L.string,itemClass:L.string,itemControlAlignLeft:L.bool,itemReactClass:L.func,items:L.array,onAddSeries:L.func,onCloseTrack:L.func,onCloseTrackMenuOpened:L.func,onConfigTrackMenuOpened:L.func,onSortEnd:L.func,onSortStart:L.func,referenceAncestor:L.string,resizeHandles:L.object,useDragHandle:L.bool,width:L.number};iY.defaultProps={className:"list stylizedList",itemClass:"item stylizedItem",width:400,height:600};const cF={"top-right-handle":"_top-right-handle_cizw2_1","bottom-right-handle":"_bottom-right-handle_cizw2_2","top-left-handle":"_top-left-handle_cizw2_7","bottom-left-handle":"_bottom-left-handle_cizw2_8","top-draggable-handle":"_top-draggable-handle_cizw2_13","bottom-draggable-handle":"_bottom-draggable-handle_cizw2_14","left-draggable-handle":"_left-draggable-handle_cizw2_15","right-draggable-handle":"_right-draggable-handle_cizw2_16","draggable-div":"_draggable-div_cizw2_22","top-draggable-handle-grabber":"_top-draggable-handle-grabber_cizw2_27","bottom-draggable-handle-grabber":"_bottom-draggable-handle-grabber_cizw2_28","left-draggable-handle-grabber":"_left-draggable-handle-grabber_cizw2_43","right-draggable-handle-grabber":"_right-draggable-handle-grabber_cizw2_44"};function ODt(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function EAe(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function I2(g){return I2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},I2(g)}let CXe=function(g){QDt(I,g);var e=jDt(I);function I(i){var n;return ODt(this,I),n=e.call(this,i),n.dragTopRight=es().on("start",n.dragStart.bind(en(n))).on("drag",n.dragTopRightFunc.bind(en(n))),n.dragTopLeft=es().on("start",n.dragStart.bind(en(n))).on("drag",n.dragTopLeftFunc.bind(en(n))),n.dragBottomRight=es().on("start",n.dragStart.bind(en(n))).on("drag",n.dragBottomRightFunc.bind(en(n))),n.dragBottomLeft=es().on("start",n.dragStart.bind(en(n))).on("drag",n.dragBottomLeftFunc.bind(en(n))),n.dragBottom=es().on("start",n.dragStart.bind(en(n))).on("drag",n.dragBottomFunc.bind(en(n))),n.dragTop=es().on("start",n.dragStart.bind(en(n))).on("drag",n.dragTopFunc.bind(en(n))),n.dragLeft=es().on("start",n.dragStart.bind(en(n))).on("drag",n.dragLeftFunc.bind(en(n))),n.dragRight=es().on("start",n.dragStart.bind(en(n))).on("drag",n.dragRightFunc.bind(en(n))),n.minWidth=10,n.minHeight=10,n.bottomHandleWidth=20,n.state={uid:n.props.uid,width:n.props.width,height:n.props.height,top:n.props.top,left:n.props.left},n.domBody=pg("body").node(),n}return LDt(I,[{key:"componentDidMount",value:function(){pg(this.bottomHandle).call(this.dragBottom),pg(this.topHandle).call(this.dragTop),pg(this.leftHandle).call(this.dragLeft),pg(this.rightHandle).call(this.dragRight)}},{key:"UNSAFE_componentWillReceiveProps",value:function(n){"width"in n&&this.setState({width:n.width}),"height"in n&&this.setState({height:n.height})}},{key:"dragBottomFunc",value:function(n){const C=Og(n,this.domBody);let r=this.dragStartHeight+(C[1]-this.dragStartMousePos[1]);r=r>this.minHeight?r:this.minHeight,this.setState({height:r}),n.sourceEvent.stopPropagation(),this.sizeChanged()}},{key:"dragLeftFunc",value:function(n){const C=Og(n,this.domBody);let r=this.dragStartWidth-(C[0]-this.dragStartMousePos[0]);r=r>this.minWidth?r:this.minWidth;let o=this.dragStartLeft+C[0]-this.dragStartMousePos[0];o=r>this.minWidth?o:this.dragStartLeft+this.dragStartWidth-this.minWidth,this.setState({left:o,width:r}),n.sourceEvent.stopPropagation(),this.sizeChanged()}},{key:"dragTopFunc",value:function(n){const C=Og(n,this.domBody);let r=this.dragStartHeight-(C[1]-this.dragStartMousePos[1]);r=r>this.minHeight?r:this.minHeight;let o=this.dragStartTop+C[1]-this.dragStartMousePos[1];o=r>this.minHeight?o:this.dragStartTop+this.dragStartHeight-this.minHeight,this.setState({top:o,height:r}),n.sourceEvent.stopPropagation(),this.sizeChanged()}},{key:"dragRightFunc",value:function(n){const C=Og(n,this.domBody);let r=this.dragStartWidth+(C[0]-this.dragStartMousePos[0]);r=r>this.minWidth?r:this.minWidth,this.setState({width:r}),n.sourceEvent.stopPropagation(),this.sizeChanged()}},{key:"dragBottomLeftFunc",value:function(n){const C=Og(n,this.domBody);let r=this.dragStartHeight+(C[1]-this.dragStartMousePos[1]);r=r>this.minHeight?r:this.minHeight;let o=this.dragStartWidth-(C[0]-this.dragStartMousePos[0]);o=o>this.minWidth?o:this.minWidth;let A=this.dragStartLeft+C[0]-this.dragStartMousePos[0];A=o>this.minWidth?A:this.dragStartLeft+this.dragStartWidth-this.minWidth,this.setState({left:A,width:o,height:r}),n.sourceEvent.stopPropagation(),this.sizeChanged()}},{key:"dragBottomRightFunc",value:function(n){const C=Og(n,this.domBody);let r=this.dragStartWidth+(C[0]-this.dragStartMousePos[0]);r=r>this.minWidth?r:this.minWidth;let o=this.dragStartHeight+(C[1]-this.dragStartMousePos[1]);o=o>this.minHeight?o:this.minHeight,this.setState({width:r,height:o}),n.sourceEvent.stopPropagation(),this.sizeChanged()}},{key:"dragTopRightFunc",value:function(n){const C=Og(n,this.domBody);let r=this.dragStartHeight-(C[1]-this.dragStartMousePos[1]);r=r>this.minHeight?r:this.minHeight;let o=this.dragStartTop+C[1]-this.dragStartMousePos[1];o=r>this.minHeight?o:this.dragStartTop+this.dragStartHeight-this.minHeight;let A=this.dragStartWidth+(C[0]-this.dragStartMousePos[0]);A=A>this.minWidth?A:this.minWidth,this.setState({top:o,width:A,height:r}),n.sourceEvent.stopPropagation(),this.sizeChanged()}},{key:"dragTopLeftFunc",value:function(n){const C=Og(n,this.domBody);let r=this.dragStartWidth-(C[0]-this.dragStartMousePos[0]);r=r>this.minWidth?r:this.minWidth;let o=this.dragStartLeft+C[0]-this.dragStartMousePos[0];o=r>this.minWidth?o:this.dragStartLeft+this.dragStartWidth-this.minWidth;let A=this.dragStartHeight-(C[1]-this.dragStartMousePos[1]);A=A>this.minHeight?A:this.minHeight;let s=this.dragStartTop+C[1]-this.dragStartMousePos[1];s=A>this.minHeight?s:this.dragStartTop+this.dragStartHeight-this.minHeight,this.setState({top:s,left:o,width:r,height:A}),n.sourceEvent.stopPropagation(),this.sizeChanged()}},{key:"dragStart",value:function(n){this.dragStartMousePos=Og(n,this.domBody),this.dragStartWidth=this.state.width,this.dragStartHeight=this.state.height,this.dragStartTop=this.state.top,this.dragStartLeft=this.state.left,n.sourceEvent.stopPropagation()}},{key:"sizeChanged",value:function(){this.props.sizeChanged&&this.props.sizeChanged(this.state)}},{key:"rotateClicked",value:function(){this.props.trackRotated(this.state.uid)}},{key:"closeClicked",value:function(){this.props.trackClosed(this.state.uid)}},{key:"render",value:function(){const n=this.props.theme===II?"white":"black",C={top:this.state.top,left:this.state.left,width:this.state.width,height:this.state.height,opacity:this.props.opacity},r=24,o=24,A={left:this.state.width/2-r/2,width:r},s={top:this.state.height/2-o/2,height:o},a={bottom:{...A,bottom:1},top:{...A,top:1},left:{...s,left:1},right:{...s,right:1}},l=[...this.props.resizeHandles].map(c=>N.createElement("div",{key:c,ref:u=>{this[`${c}Handle`]=u},className:cF[`${c}-draggable-handle`],style:a[c],title:"Resize track"},N.createElement("div",{className:cF[`${c}-draggable-handle-grabber`],style:{borderColor:n}})));return N.createElement("div",{ref:c=>{this.divContainer=c},className:Tg(this.props.className,cF["draggable-div"]),style:C},l)}}]),I}(N.Component);CXe.propTypes={className:L.string,height:L.number,left:L.number,opacity:L.number,resizeHandles:L.object,sizeChanged:L.func,top:L.number,trackClosed:L.func,trackRotated:L.func,uid:L.string,width:L.number,theme:L.symbol};const eFt=ym(CXe);function tFt(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function MAe(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function i2(g){return i2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},i2(g)}let rXe=function(g){nFt(I,g);var e=CFt(I);function I(i){var n;return tFt(this,I),n=e.call(this,i),n.state={controlsVisible:!1},n}return gFt(I,[{key:"shouldComponentUpdate",value:function(){return!this.resizing}},{key:"handleMouseEnter",value:function(){this.setState({controlsVisible:!0})}},{key:"handleMouseLeave",value:function(){this.setState({controlsVisible:!1})}},{key:"handleMouseMove",value:function(){this.setState({controlsVisible:!0})}},{key:"getControls",value:function(){let n=null;return this.moveable?n=q3(()=>N.createElement("svg",{className:"no-zoom",height:"10px",onClick:()=>{},style:this.getMoveImgStyle(),width:"10px"},N.createElement("use",{xlinkHref:"#move"}))):n=q3(()=>N.createElement("div",null)),N.createElement("div",{style:{position:"absolute",backgroundColor:"rgba(255,255,255,0.7)",right:"3px",top:"3px",pointerEvents:"none",paddingLeft:"5px",paddingRight:"5px",borderRadius:"5px",border:"1px solid #dddddd"}},N.createElement(n,null),N.createElement("svg",{ref:C=>{this.imgConfig=C},className:"no-zoom",height:"10px",onClick:()=>{const r=QI.findDOMNode(this.imgConfig).getBoundingClientRect();this.props.onConfigTrackMenuOpened(this.props.uid,r)},style:this.getSettingsImgStyle(),width:"10px"},N.createElement("use",{xlinkHref:"#cog"})),N.createElement("svg",{ref:C=>{this.imgAdd=C},className:"no-zoom",height:"10px",onClick:()=>this.props.onAddSeries(this.props.uid),style:this.getAddImgStyle(),width:"10px"},N.createElement("use",{xlinkHref:"#plus"})),N.createElement("svg",{ref:C=>{this.imgClose=C},className:"no-zoom",height:"10px",onClick:()=>{const r=QI.findDOMNode(this.imgClose).getBoundingClientRect();this.props.onCloseTrackMenuOpened(this.props.uid,r)},style:this.getCloseImgStyle(),width:"10px"},N.createElement("use",{xlinkHref:"#cross"})))}}]),I}(N.Component);rXe.propTypes={configMenuOpen:L.bool,onConfigTrackMenuOpened:L.func,onCloseTrackMenuOpened:L.func,onAddSeries:L.func,uid:L.string};function aFt(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function zAe(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function n2(g){return n2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},n2(g)}let nY=function(g){uFt(I,g);var e=dFt(I);function I(i){var n;return aFt(this,I),n=e.call(this,i),n.moveable=!0,n}return sFt(I,[{key:"render",value:function(){return N.createElement("div",{ref:n=>{this.el=n},className:this.props.className,onMouseEnter:this.handleMouseEnter.bind(this),onMouseLeave:()=>{this.handleMouseLeave()},style:{height:this.props.height,width:this.props.width}},N.createElement(eFt,{key:this.props.uid,height:this.props.height,resizeHandles:this.props.editable?this.props.resizeHandles:new Set,sizeChanged:n=>this.props.handleResizeTrack(this.props.uid,n.width,n.height),style:{background:"transparent"},uid:this.props.uid,width:this.props.width}),this.props.editable&&this.getControls(this.state.controlsVisible||this.props.item.configMenuVisible))}}]),I}(rXe);nY.propTypes={className:L.string,uid:L.string,item:L.object,height:L.number,width:L.number};function pFt(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function PAe(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function C2(g){return C2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},C2(g)}const QR={pointerEvents:"all"};let oXe=function(g){GFt(I,g);var e=BFt(I);function I(){return pFt(this,I),e.apply(this,arguments)}return bFt(I,[{key:"getControls",value:function(n){return N.createElement(Pk,{configMenuVisible:this.props.item.configMenuVisible,imgStyleAdd:QR,imgStyleClose:QR,imgStyleMove:QR,imgStyleSettings:QR,isMoveable:this.moveable,isVisible:n,onAddSeries:this.props.onAddSeries,onCloseTrackMenuOpened:this.props.onCloseTrackMenuOpened,onConfigTrackMenuOpened:this.props.onConfigTrackMenuOpened,uid:this.props.uid})}}]),I}(nY);const VFt=fGe(g=>N.createElement(oXe,{className:g.className,editable:g.editable,handleConfigTrack:g.handleConfigTrack,handleResizeTrack:g.handleResizeTrack,height:g.height,item:g.item,onAddSeries:g.onAddSeries,onCloseTrack:g.onCloseTrack,onCloseTrackMenuOpened:g.onCloseTrackMenuOpened,onConfigTrackMenuOpened:g.onConfigTrackMenuOpened,resizeHandles:g.resizeHandles,uid:g.uid,width:g.width}));function MJ(){return MJ=Object.assign?Object.assign.bind():function(g){for(var e=1;e{const b=e.map((p,y)=>N.createElement(h,{key:`sci-${p.uid}`,className:I,controlAlignLeft:i,sortingIndex:n,index:y,uid:p.uid,height:p.height,width:p.width,item:p,useDragHandle:C,onCloseTrack:s,onCloseTrackMenuOpened:a,onConfigTrackMenuOpened:l,onAddSeries:c,handleConfigTrack:u,editable:d,handleResizeTrack:m,resizeHandles:f}));return N.createElement("div",MJ({className:g,style:{height:o,width:A,background:"transparent"}},r),b)}),RFt={"horizontal-tiled-plot":"_horizontal-tiled-plot_1bqkg_1"};function WFt(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function JAe(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function r2(g){return r2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},r2(g)}function OAe(g){return g&&g.sourceEvent}let o2=function(g){NFt(I,g);var e=kFt(I);function I(i){var n;return WFt(this,I),n=e.call(this,i),n.brushBehavior=QN().on("start",n.brushStarted.bind(DW(n))).on("brush",n.brushed.bind(DW(n))).on("end",n.brushedEnded.bind(DW(n))),n}return XFt(I,[{key:"componentDidMount",value:function(){this.props.isRangeSelectionActive&&this.addBrush()}},{key:"shouldComponentUpdate",value:function(n,C){return this.rangeSelectionTriggered?(this.rangeSelectionTriggered=!1,this.rangeSelectionTriggeredEnd&&this.props.rangeSelection!==n.rangeSelection&&this.moveBrush(n.rangeSelection[0]?n.rangeSelection[0]:null,!0),this.rangeSelectionTriggeredEnd=!1,this.state!==C):this.props.rangeSelection!==n.rangeSelection?(this.moveBrush(n.rangeSelection[0]?n.rangeSelection[0]:null,n.rangeSelectionEnd),this.state!==C):!0}},{key:"componentDidUpdate",value:function(){this.props.isRangeSelectionActive?this.addBrush():this.removeBrush()}},{key:"addBrush",value:function(){!this.brushEl||this.brushElAddedBefore===this.brushEl||(this.brushElAddedBefore&&this.brushElAddedBefore.on(".brush",null),this.brushEl.call(this.brushBehavior),this.brushElAddedBefore=this.brushEl,_p(this.brushEl,Lo["track-range-selection-group-brush-selection"]))}},{key:"brushed",value:function(n){const C=this.rangeSelectionMoved;this.rangeSelectionMoved=!1,!(!OAe(n)||!this.props.onRangeSelection||C)&&(this.rangeSelectionTriggered=!0,this.props.onRangeSelection(n.selection))}},{key:"brushStarted",value:function(n){!OAe(n)||!n.selection||this.props.onRangeSelectionStart()}},{key:"brushedEnded",value:function(n){if(!this.props.is1dRangeSelection)return;const C=this.rangeSelectionMovedEnd;this.rangeSelectionMovedEnd=!1,n.selection&&n.sourceEvent&&this.props.onRangeSelection&&!C&&(this.rangeSelectionTriggered=!0,this.rangeSelectionTriggeredEnd=!0,this.props.onRangeSelectionEnd(n.selection)),n.selection||(this.rangeSelectionTriggered=!0,this.props.onRangeSelectionReset())}},{key:"moveBrush",value:function(n,C=!1){if(!this.brushEl)return;const r=n?[this.props.scale(n[0]),this.props.scale(n[1])]:null;this.rangeSelectionMoved=!0,this.rangeSelectionMovedEnd=!0,C?this.brushEl.transition().call(this.brushBehavior.move,r):this.brushEl.call(this.brushBehavior.move,r)}},{key:"removeBrush",value:function(){this.brushElAddedBefore&&(this.brushElAddedBefore.call(this.brushBehavior.move,null),this.brushElAddedBefore.on(".brush",null),this.brushElAddedBefore=void 0,this.props.onRangeSelectionReset())}},{key:"render",value:function(){const n=this.props.tracks.map(o=>o.height).reduce(sc,0),C=this.props.tracks.map(o=>L0(o)).reduce(ow,!1),r=this.props.isRangeSelectionActive?Lo["track-range-selection-active"]:Lo["track-range-selection"];return N.createElement("div",{className:Tg("horizontal-tiled-plot",RFt["horizontal-tiled-plot"])},C&&N.createElement("svg",{ref:o=>{this.brushEl=pg(o)},className:r,style:{height:n,width:this.props.width},xmlns:"http://www.w3.org/2000/svg"}),N.createElement(iY,{className:Tg(_o.list,_o.stylizedList),component:AXe,editable:this.props.editable,handleConfigTrack:this.props.handleConfigTrack,handleResizeTrack:this.props.handleResizeTrack,height:n,helperClass:_o.stylizedHelper,itemClass:_o.stylizedItem,itemReactClass:VFt,items:this.props.tracks.map(o=>({configMenuVisible:o.uid===this.props.configTrackMenuId,uid:o.uid||dg.nice(),width:this.props.width,height:o.height,value:o.value})),onAddSeries:this.props.onAddSeries,onCloseTrack:this.props.onCloseTrack,onCloseTrackMenuOpened:this.props.onCloseTrackMenuOpened,onConfigTrackMenuOpened:this.props.onConfigTrackMenuOpened,onSortEnd:this.props.handleSortEnd,referenceAncestor:this.props.referenceAncestor,resizeHandles:this.props.resizeHandles,useDragHandle:!0,width:this.props.width}))}}]),I}(N.Component);o2.propTypes={configTrackMenuId:L.string,editable:L.bool,handleConfigTrack:L.func,handleResizeTrack:L.func,handleSortEnd:L.func,is1dRangeSelection:L.bool,isRangeSelectionActive:L.bool,onAddSeries:L.func,onCloseTrack:L.func,onCloseTrackMenuOpened:L.func,onConfigTrackMenuOpened:L.func,onRangeSelection:L.func,onRangeSelectionEnd:L.func,onRangeSelectionReset:L.func,onRangeSelectionStart:L.func,rangeSelection:L.array,rangeSelectionEnd:L.bool,referenceAncestor:L.func,resizeHandles:L.object,scale:L.func,tracks:L.array,width:L.number};function xFt(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function LAe(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function A2(g){return A2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},A2(g)}const jR={pointerEvents:"all"};let aXe=function(g){MFt(I,g);var e=zFt(I);function I(){return xFt(this,I),e.apply(this,arguments)}return DFt(I,[{key:"getControls",value:function(n){return N.createElement(Pk,{imgStyleAdd:jR,imgStyleClose:jR,imgStyleMove:jR,imgStyleSettings:jR,isAlignLeft:this.props.controlAlignLeft,isMoveable:this.moveable,isVertical:!0,isVisible:n,onAddSeries:this.props.onAddSeries,onCloseTrackMenuOpened:this.props.onCloseTrackMenuOpened,onConfigTrackMenuOpened:this.props.onConfigTrackMenuOpened,uid:this.props.uid})}}]),I}(nY);function LFt(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function _Ae(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function Z0(g){return Z0=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},Z0(g)}let gEt=function(g){$Ft(I,g);var e=qFt(I);function I(i,n){var C;LFt(this,I),C=e.call(this,i,n);const{registerViewportChanged:r,removeViewportChanged:o}=i,A=dg.nice();return C.uid=A,C.removeViewportChanged=o,C.viewportXDomain=null,C.viewportYDomain=null,r(A,C.viewportChanged.bind(sXe(C))),C}return _Ft(I,[{key:"viewportChanged",value:function(n,C){const r=n.domain(),o=C.domain();this.viewportXDomain=r,this.viewportYDomain=o,this.draw()}},{key:"draw",value:function(){const n=this.pMain;if(!this.viewportXDomain||!this.viewportYDomain)return;n.clear(),n.lineStyle(1,255,1),n.beginFill(16740363,1);const C=this._xScale(this.viewportXDomain[0]),r=this._yScale(this.viewportYDomain[0]),o=this._xScale(this.viewportXDomain[1])-this._xScale(this.viewportXDomain[0]),A=this._yScale(this.viewportYDomain[1])-this._yScale(this.viewportYDomain[0]);this.pMain.drawRect(C,r,o,A)}},{key:"zoomed",value:function(n,C){this.xScale(n),this.yScale(C),this.draw()}},{key:"setPosition",value:function(n){FW(Z0(I.prototype),"setPosition",this).call(this,n),this.pMain.position.y=this.position[1],this.pMain.position.x=this.position[0],this.draw()}}]),I}(dC);function lXe(g){this.size=0,this.limit=g,this._keymap={}}function IEt(g,e){const I={key:g,value:e};if(this._keymap[g]=I,this.tail?(this.tail.newer=I,I.older=this.tail):this.head=I,this.tail=I,this.size===this.limit)return this.shift();this.size+=1}function iEt(){const g=this.head;return g&&(this.head.newer?(this.head=this.head.newer,this.head.older=void 0):(this.head=void 0,this.tail=void 0),g.newer=void 0,g.older=void 0,delete this._keymap[g.key],this.size-=1),g}function nEt(g,e){const I=this._keymap[g];if(I!==void 0)return I===this.tail||(I.newer&&(I===this.head&&(this.head=I.newer),I.newer.older=I.older),I.older&&(I.older.newer=I.newer),I.newer=void 0,I.older=this.tail,this.tail&&(this.tail.newer=I),this.tail=I),e?I:I.value}function CEt(g){return this._keymap[g]}function rEt(g,e){const I=this.get(g,!0);let i;return I?(i=I.value,I.value=e):(i=this.put(g,e),i&&(i=i.value)),i}function oEt(g){const e=this._keymap[g];if(e)return delete this._keymap[e.key],e.newer&&e.older?(e.older.newer=e.newer,e.newer.older=e.older):e.newer?(e.newer.older=void 0,this.head=e.newer):e.older?(e.older.newer=void 0,this.tail=e.older):(this.head=void 0,this.tail=void 0),this.size-=1,e.value}function AEt(){this.head=void 0,this.tail=void 0,this.size=0,this._keymap={}}function aEt(){return Object.keys(this._keymap)}function sEt(g,e,I){let i;if(e===!0?(I=!0,e=void 0):typeof e!="object"&&(e=this),I)for(i=this.tail;i;)g.call(e,i.key,i.value,this),i=i.older;else for(i=this.head;i;)g.call(e,i.key,i.value,this),i=i.newer}function lEt(){const g=[];let e=this.head;for(;e;)g.push({key:e.key.toJSON(),value:e.value.toJSON()}),e=e.newer;return g}function cEt(){let g="",e=this.head;for(;e;)g+=`${String(e.key)}:${e.value}`,e=e.newer,e&&(g+=" < ");return g}Object.assign(lXe.prototype,{put:IEt,get:nEt,find:CEt,keys:aEt,set:rEt,shift:iEt,remove:oEt,removeAll:AEt,forEach:sEt,toJSON:lEt,toString:cEt});const cXe="1.13.3",uEt="_button_1wnjn_1",uF={button:uEt,"button-shortcut":"_button-shortcut_1wnjn_35"},ks=N.forwardRef((g,e)=>N.createElement("button",{ref:e,className:uF[g.styleName]??uF.button,disabled:g.disable,onBlur:g.onBlur,onClick:g.onClick,onMouseDown:g.onMouseDown,onMouseOut:g.onMouseOut,onMouseUp:g.onMouseUp,type:"button"},g.children,g.shortcut&&N.createElement("span",{className:uF["button-shortcut"]},g.shortcut)));ks.defaultProps={onClick:()=>{},styleName:"",type:"button"};ks.propTypes={children:L.any,disable:L.bool,onBlur:L.func,onClick:L.func,onMouseDown:L.func,onMouseOut:L.func,onMouseUp:L.func,shortcut:L.string,type:L.string,styleName:L.string};const dEt="_cross_2ke8w_1",hEt={cross:dEt};function uXe(){return N.createElement("div",{className:hEt.cross})}function OJ(){return OJ=Object.assign?Object.assign.bind():function(g){for(var e=1;eN.forwardRef((e,I)=>N.createElement(fEt,null,i=>N.createElement(g,OJ({ref:I},e,{modal:i})))),lf={"modal-background":"_modal-background_zzhoe_1","fade-in":"_fade-in_zzhoe_1","modal-hide":"_modal-hide_zzhoe_13","modal-wrap":"_modal-wrap_zzhoe_17","modal-window":"_modal-window_zzhoe_25","fade-scale-in":"_fade-scale-in_zzhoe_1","modal-window-max-height":"_modal-window-max-height_zzhoe_38","modal-content":"_modal-content_zzhoe_42"};function w4(g){const e=()=>{g.modal.close(),g.onClose&&g.onClose()};return N.createElement("div",{className:Tg(lf["modal-background"],{[lf["modal-hide"]]:g.hide})},N.createElement("div",{className:lf["modal-wrap"]},N.createElement("div",{className:Tg(lf["modal-window"],{[lf["modal-window-max-height"]]:g.maxHeight})},g.closeButton&&N.createElement(ks,{onClick:e},N.createElement(uXe,null)),N.createElement("div",{className:lf["modal-content"]},g.children))))}w4.defaultProps={closeButton:!0,hide:!1,maxHeight:!1};w4.propTypes={children:L.element.isRequired,closeButton:L.bool,hide:L.bool,maxHeight:L.bool,modal:L.object.isRequired,onClose:L.func};const pEt=CY(w4),dF={"dialog-header":"_dialog-header_wp50s_1","dialog-main-max-height":"_dialog-main-max-height_wp50s_20","dialog-footer":"_dialog-footer_wp50s_31","dialog-footer-max-height":"_dialog-footer-max-height_wp50s_31"};function V4(g){const e=()=>{g.modal.close(),g.onCancel&&g.onCancel()},I=()=>{g.modal.close(),g.onOkay&&g.onOkay()};return N.createElement(pEt,{closeButton:!1,hide:g.hide,maxHeight:g.maxHeight},N.createElement(N.Fragment,null,N.createElement("header",{className:dF["dialog-header"]},N.createElement("h3",null,g.title),N.createElement(ks,{onClick:e},N.createElement(uXe,null))),g.maxHeight?N.createElement("main",{className:Tg(g.maxHeight&&dF["dialog-main-max-height"])},g.children):N.createElement("main",null,g.children),N.createElement("footer",{className:dF[g.maxHeight?"dialog-footer-max-height":"dialog-footer"]},g.okayOnly?N.createElement("div",null):N.createElement(ks,{onClick:e,shortcut:g.cancelShortcut},g.cancelTitle),N.createElement(ks,{onClick:I,shortcut:g.okayShortcut},g.okayTitle))))}V4.defaultProps={cancelTitle:"Cancel",hide:!1,maxHeight:!1,okayOnly:!1,okayTitle:"Ok"};V4.propTypes={cancelShortcut:L.string,cancelTitle:L.string,children:L.object,hide:L.bool,maxHeight:L.bool,modal:L.object.isRequired,okayShortcut:L.string,okayTitle:L.string,okayOnly:L.bool,onCancel:L.func.isRequired,onOkay:L.func.isRequired,title:L.string.isRequired};const Yw=CY(V4);var _r={},Kw={},bEt=typeof globalThis=="object"&&globalThis&&globalThis.Object===Object&&globalThis;const dXe=bEt;var yEt=typeof self=="object"&&self&&self.Object===Object&&self,ZEt=dXe||yEt||Function("return this")();const vA=ZEt;var GEt=vA.Symbol;const Wa=GEt;var hXe=Object.prototype,BEt=hXe.hasOwnProperty,vEt=hXe.toString,bZ=Wa?Wa.toStringTag:void 0;function SEt(g){var e=BEt.call(g,bZ),I=g[bZ];try{g[bZ]=void 0;var i=!0}catch{}var n=vEt.call(g);return i&&(e?g[bZ]=I:delete g[bZ]),n}var wEt=Object.prototype,VEt=wEt.toString;function REt(g){return VEt.call(g)}var WEt="[object Null]",XEt="[object Undefined]",UAe=Wa?Wa.toStringTag:void 0;function Su(g){return g==null?g===void 0?XEt:WEt:UAe&&UAe in Object(g)?SEt(g):REt(g)}var HEt=Array.isArray;const sC=HEt;function mA(g){return g!=null&&typeof g=="object"}var TEt="[object String]";function NEt(g){return typeof g=="string"||!sC(g)&&mA(g)&&Su(g)==TEt}const kEt=Object.freeze(Object.defineProperty({__proto__:null,default:NEt},Symbol.toStringTag,{value:"Module"})),YEt=Al(kEt);function KEt(g){return function(e,I,i){for(var n=-1,C=Object(e),r=i(e),o=r.length;o--;){var A=r[g?o:++n];if(I(C[A],A,C)===!1)break}return e}}var xEt=KEt();const mXe=xEt;function DEt(g,e){for(var I=-1,i=Array(g);++I-1&&g%1==0&&g-1&&g%1==0&&g<=QEt}var jEt="[object Arguments]",$Et="[object Array]",qEt="[object Boolean]",eMt="[object Date]",tMt="[object Error]",gMt="[object Function]",IMt="[object Map]",iMt="[object Number]",nMt="[object Object]",CMt="[object RegExp]",rMt="[object Set]",oMt="[object String]",AMt="[object WeakMap]",aMt="[object ArrayBuffer]",sMt="[object DataView]",lMt="[object Float32Array]",cMt="[object Float64Array]",uMt="[object Int8Array]",dMt="[object Int16Array]",hMt="[object Int32Array]",mMt="[object Uint8Array]",fMt="[object Uint8ClampedArray]",pMt="[object Uint16Array]",bMt="[object Uint32Array]",fI={};fI[lMt]=fI[cMt]=fI[uMt]=fI[dMt]=fI[hMt]=fI[mMt]=fI[fMt]=fI[pMt]=fI[bMt]=!0;fI[jEt]=fI[$Et]=fI[aMt]=fI[qEt]=fI[sMt]=fI[eMt]=fI[tMt]=fI[gMt]=fI[IMt]=fI[iMt]=fI[nMt]=fI[CMt]=fI[rMt]=fI[oMt]=fI[AMt]=!1;function yMt(g){return mA(g)&&W4(g.length)&&!!fI[Su(g)]}function X4(g){return function(e){return g(e)}}var bXe=typeof exports=="object"&&exports&&!exports.nodeType&&exports,zB=bXe&&typeof module=="object"&&module&&!module.nodeType&&module,ZMt=zB&&zB.exports===bXe,hF=ZMt&&dXe.process,GMt=function(){try{var g=zB&&zB.require&&zB.require("util").types;return g||hF&&hF.binding&&hF.binding("util")}catch{}}();const G0=GMt;var qAe=G0&&G0.isTypedArray,BMt=qAe?X4(qAe):yMt;const H4=BMt;var vMt=Object.prototype,SMt=vMt.hasOwnProperty;function yXe(g,e){var I=sC(g),i=!I&&a2(g),n=!I&&!i&&AS(g),C=!I&&!i&&!n&&H4(g),r=I||i||n||C,o=r?DEt(g.length,String):[],A=o.length;for(var s in g)(e||SMt.call(g,s))&&!(r&&(s=="length"||n&&(s=="offset"||s=="parent")||C&&(s=="buffer"||s=="byteLength"||s=="byteOffset")||R4(s,A)))&&o.push(s);return o}var wMt=Object.prototype;function T4(g){var e=g&&g.constructor,I=typeof e=="function"&&e.prototype||wMt;return g===I}function ZXe(g,e){return function(I){return g(e(I))}}var VMt=ZXe(Object.keys,Object);const RMt=VMt;var WMt=Object.prototype,XMt=WMt.hasOwnProperty;function HMt(g){if(!T4(g))return RMt(g);var e=[];for(var I in Object(g))XMt.call(g,I)&&I!="constructor"&&e.push(I);return e}function Zr(g){var e=typeof g;return g!=null&&(e=="object"||e=="function")}var TMt="[object AsyncFunction]",NMt="[object Function]",kMt="[object GeneratorFunction]",YMt="[object Proxy]";function N4(g){if(!Zr(g))return!1;var e=Su(g);return e==NMt||e==kMt||e==TMt||e==YMt}function hy(g){return g!=null&&W4(g.length)&&!N4(g)}function xw(g){return hy(g)?yXe(g):HMt(g)}function GXe(g,e){return g&&mXe(g,e,xw)}function rY(g){return g}function BXe(g){return typeof g=="function"?g:rY}function KMt(g,e){return g&&GXe(g,BXe(e))}const xMt=Object.freeze(Object.defineProperty({__proto__:null,default:KMt},Symbol.toStringTag,{value:"Module"})),k4=Al(xMt);var DMt=ZXe(Object.getPrototypeOf,Object);const Y4=DMt;var FMt="[object Object]",EMt=Function.prototype,MMt=Object.prototype,vXe=EMt.toString,zMt=MMt.hasOwnProperty,PMt=vXe.call(Object);function SXe(g){if(!mA(g)||Su(g)!=FMt)return!1;var e=Y4(g);if(e===null)return!0;var I=zMt.call(e,"constructor")&&e.constructor;return typeof I=="function"&&I instanceof I&&vXe.call(I)==PMt}const JMt=Object.freeze(Object.defineProperty({__proto__:null,default:SXe},Symbol.toStringTag,{value:"Module"})),OMt=Al(JMt);function wXe(g,e){for(var I=-1,i=g==null?0:g.length,n=Array(i);++I-1}function qMt(g,e){var I=this.__data__,i=oY(I,g);return i<0?(++this.size,I.push([g,e])):I[i][1]=e,this}function pl(g){var e=-1,I=g==null?0:g.length;for(this.clear();++eo))return!1;var s=C.get(g),a=C.get(e);if(s&&a)return s==e&&a==g;var l=-1,c=!0,u=I&P3t?new s2:void 0;for(C.set(g,e),C.set(e,g);++l0&&arguments[0]!==void 0?arguments[0]:[],I=[];return(0,hPt.default)(e,function(i){Array.isArray(i)?g(i).map(function(n){return I.push(n)}):(0,uPt.default)(i)?(0,lPt.default)(i,function(n,C){n===!0&&I.push(C),I.push(C+"-"+n)}):(0,aPt.default)(i)&&I.push(i)}),I};Kw.default=mPt;var Fw={};function xXe(g,e){for(var I=-1,i=g==null?0:g.length;++I1&&arguments[1]!==void 0?arguments[1]:[],i=e.default&&(0,QJt.default)(e.default)||{};return I.map(function(n){var C=e[n];return C&&(0,_Jt.default)(C,function(r,o){i[o]||(i[o]={}),i[o]=jJt({},i[o],C[o])}),n}),i};Fw.default=$Jt;var zw={};Object.defineProperty(zw,"__esModule",{value:!0});zw.autoprefix=void 0;var qJt=k4,yae=tOt(qJt),eOt=Object.assign||function(g){for(var e=1;e1&&arguments[1]!==void 0?arguments[1]:"span";return function(i){oOt(n,i);function n(){var C,r,o,A;rOt(this,n);for(var s=arguments.length,a=Array(s),l=0;l1&&arguments[1]!==void 0?arguments[1]:"span";return function(i){uOt(n,i);function n(){var C,r,o,A;cOt(this,n);for(var s=arguments.length,a=Array(s),l=0;l1&&arguments[1]!==void 0?arguments[1]:!0;i[r]=o};return e===0&&n("first-child"),e===I-1&&n("last-child"),(e===0||e%2===0)&&n("even"),Math.abs(e%2)===1&&n("odd"),n("nth-child",e),i};z4.default=hOt;Object.defineProperty(_r,"__esModule",{value:!0});_r.ReactCSS=_r.loop=_r.handleActive=P4=_r.handleHover=_r.hover=void 0;var mOt=Kw,fOt=my(mOt),pOt=Fw,bOt=my(pOt),yOt=zw,ZOt=my(yOt),GOt=Pw,QXe=my(GOt),BOt=Jw,vOt=my(BOt),SOt=z4,wOt=my(SOt);function my(g){return g&&g.__esModule?g:{default:g}}_r.hover=QXe.default;var P4=_r.handleHover=QXe.default;_r.handleActive=vOt.default;_r.loop=wOt.default;var VOt=_r.ReactCSS=function(e){for(var I=arguments.length,i=Array(I>1?I-1:0),n=1;no?c=1:c=Math.round(l*100/o)/100,I.a!==c)return{h:I.h,s:I.s,l:I.l,a:c,source:"rgb"}}else{var u=void 0;if(a<0?u=0:a>r?u=1:u=Math.round(a*100/r)/100,n!==u)return{h:I.h,s:I.s,l:I.l,a:u,source:"rgb"}}return null},yF={},WOt=function(e,I,i,n){if(typeof document>"u"&&!n)return null;var C=n?new n:document.createElement("canvas");C.width=i*2,C.height=i*2;var r=C.getContext("2d");return r?(r.fillStyle=e,r.fillRect(0,0,C.width,C.height),r.fillStyle=I,r.fillRect(0,0,i,i),r.translate(i,i),r.fillRect(0,0,i,i),C.toDataURL()):null},XOt=function(e,I,i,n){var C=e+"-"+I+"-"+i+(n?"-server":"");if(yF[C])return yF[C];var r=WOt(e,I,i,n);return yF[C]=r,r},Bae=Object.assign||function(g){for(var e=1;e"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function l2(e){return l2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},l2(e)}let lk=function(e){pEt(I,e);var g=bEt(I);function I({items:i}){var n;return dEt(this,I),n=g.call(this),n.state={items:i,isSorting:!1},n}return hEt(I,[{key:"UNSAFE_componentWillReceiveProps",value:function(n){this.setState({items:n.items})}},{key:"onSortStart",value:function({node:n,index:C,collection:r},o){o.stopImmediatePropagation();const{onSortStart:A}=this.props;this.setState({isSorting:!0}),A&&A(this.ref),this.sortingIndex=C,this.sortStartTop=o.offsetTop,this.sortStartLeft=o.offsetLeft}},{key:"onSortMove",value:function(){}},{key:"onSortEnd",value:function({oldIndex:n,newIndex:C}){const{onSortEnd:r}=this.props,{items:o}=this.state;this.setState({items:yAt(o,n,C),isSorting:!1}),r&&r(this.state.items),this.sortingIndex=null}},{key:"render",value:function(){const n=this.props.component,{items:C,isSorting:r}=this.state,o={isSorting:r,items:C,onSortEnd:this.onSortEnd.bind(this),onSortStart:this.onSortStart.bind(this),onSortMove:this.onSortMove.bind(this)};return N.createElement(n,tJ({},this.props,o,{ref:A=>{this.ref=A}}))}}]),I}(N.Component);lk.propTypes={axis:L.string,className:L.string,component:L.func,editable:L.bool,handleConfigTrack:L.func,handleResizeTrack:L.func,height:L.number,helperClass:L.string,itemClass:L.string,itemControlAlignLeft:L.bool,itemReactClass:L.func,items:L.array,onAddSeries:L.func,onCloseTrack:L.func,onCloseTrackMenuOpened:L.func,onConfigTrackMenuOpened:L.func,onSortEnd:L.func,onSortStart:L.func,referenceAncestor:L.string,resizeHandles:L.object,useDragHandle:L.bool,width:L.number};lk.defaultProps={className:"list stylizedList",itemClass:"item stylizedItem",width:400,height:600};const Gx={"top-right-handle":"_top-right-handle_cizw2_1","bottom-right-handle":"_bottom-right-handle_cizw2_2","top-left-handle":"_top-left-handle_cizw2_7","bottom-left-handle":"_bottom-left-handle_cizw2_8","top-draggable-handle":"_top-draggable-handle_cizw2_13","bottom-draggable-handle":"_bottom-draggable-handle_cizw2_14","left-draggable-handle":"_left-draggable-handle_cizw2_15","right-draggable-handle":"_right-draggable-handle_cizw2_16","draggable-div":"_draggable-div_cizw2_22","top-draggable-handle-grabber":"_top-draggable-handle-grabber_cizw2_27","bottom-draggable-handle-grabber":"_bottom-draggable-handle-grabber_cizw2_28","left-draggable-handle-grabber":"_left-draggable-handle-grabber_cizw2_43","right-draggable-handle-grabber":"_right-draggable-handle-grabber_cizw2_44"};function vEt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function gAe(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function c2(e){return c2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},c2(e)}let Q1e=function(e){VEt(I,e);var g=REt(I);function I(i){var n;return vEt(this,I),n=g.call(this,i),n.dragTopRight=za().on("start",n.dragStart.bind(qi(n))).on("drag",n.dragTopRightFunc.bind(qi(n))),n.dragTopLeft=za().on("start",n.dragStart.bind(qi(n))).on("drag",n.dragTopLeftFunc.bind(qi(n))),n.dragBottomRight=za().on("start",n.dragStart.bind(qi(n))).on("drag",n.dragBottomRightFunc.bind(qi(n))),n.dragBottomLeft=za().on("start",n.dragStart.bind(qi(n))).on("drag",n.dragBottomLeftFunc.bind(qi(n))),n.dragBottom=za().on("start",n.dragStart.bind(qi(n))).on("drag",n.dragBottomFunc.bind(qi(n))),n.dragTop=za().on("start",n.dragStart.bind(qi(n))).on("drag",n.dragTopFunc.bind(qi(n))),n.dragLeft=za().on("start",n.dragStart.bind(qi(n))).on("drag",n.dragLeftFunc.bind(qi(n))),n.dragRight=za().on("start",n.dragStart.bind(qi(n))).on("drag",n.dragRightFunc.bind(qi(n))),n.minWidth=10,n.minHeight=10,n.bottomHandleWidth=20,n.state={uid:n.props.uid,width:n.props.width,height:n.props.height,top:n.props.top,left:n.props.left},n.domBody=cg("body").node(),n}return BEt(I,[{key:"componentDidMount",value:function(){cg(this.bottomHandle).call(this.dragBottom),cg(this.topHandle).call(this.dragTop),cg(this.leftHandle).call(this.dragLeft),cg(this.rightHandle).call(this.dragRight)}},{key:"UNSAFE_componentWillReceiveProps",value:function(n){"width"in n&&this.setState({width:n.width}),"height"in n&&this.setState({height:n.height})}},{key:"dragBottomFunc",value:function(n){const C=Eg(n,this.domBody);let r=this.dragStartHeight+(C[1]-this.dragStartMousePos[1]);r=r>this.minHeight?r:this.minHeight,this.setState({height:r}),n.sourceEvent.stopPropagation(),this.sizeChanged()}},{key:"dragLeftFunc",value:function(n){const C=Eg(n,this.domBody);let r=this.dragStartWidth-(C[0]-this.dragStartMousePos[0]);r=r>this.minWidth?r:this.minWidth;let o=this.dragStartLeft+C[0]-this.dragStartMousePos[0];o=r>this.minWidth?o:this.dragStartLeft+this.dragStartWidth-this.minWidth,this.setState({left:o,width:r}),n.sourceEvent.stopPropagation(),this.sizeChanged()}},{key:"dragTopFunc",value:function(n){const C=Eg(n,this.domBody);let r=this.dragStartHeight-(C[1]-this.dragStartMousePos[1]);r=r>this.minHeight?r:this.minHeight;let o=this.dragStartTop+C[1]-this.dragStartMousePos[1];o=r>this.minHeight?o:this.dragStartTop+this.dragStartHeight-this.minHeight,this.setState({top:o,height:r}),n.sourceEvent.stopPropagation(),this.sizeChanged()}},{key:"dragRightFunc",value:function(n){const C=Eg(n,this.domBody);let r=this.dragStartWidth+(C[0]-this.dragStartMousePos[0]);r=r>this.minWidth?r:this.minWidth,this.setState({width:r}),n.sourceEvent.stopPropagation(),this.sizeChanged()}},{key:"dragBottomLeftFunc",value:function(n){const C=Eg(n,this.domBody);let r=this.dragStartHeight+(C[1]-this.dragStartMousePos[1]);r=r>this.minHeight?r:this.minHeight;let o=this.dragStartWidth-(C[0]-this.dragStartMousePos[0]);o=o>this.minWidth?o:this.minWidth;let A=this.dragStartLeft+C[0]-this.dragStartMousePos[0];A=o>this.minWidth?A:this.dragStartLeft+this.dragStartWidth-this.minWidth,this.setState({left:A,width:o,height:r}),n.sourceEvent.stopPropagation(),this.sizeChanged()}},{key:"dragBottomRightFunc",value:function(n){const C=Eg(n,this.domBody);let r=this.dragStartWidth+(C[0]-this.dragStartMousePos[0]);r=r>this.minWidth?r:this.minWidth;let o=this.dragStartHeight+(C[1]-this.dragStartMousePos[1]);o=o>this.minHeight?o:this.minHeight,this.setState({width:r,height:o}),n.sourceEvent.stopPropagation(),this.sizeChanged()}},{key:"dragTopRightFunc",value:function(n){const C=Eg(n,this.domBody);let r=this.dragStartHeight-(C[1]-this.dragStartMousePos[1]);r=r>this.minHeight?r:this.minHeight;let o=this.dragStartTop+C[1]-this.dragStartMousePos[1];o=r>this.minHeight?o:this.dragStartTop+this.dragStartHeight-this.minHeight;let A=this.dragStartWidth+(C[0]-this.dragStartMousePos[0]);A=A>this.minWidth?A:this.minWidth,this.setState({top:o,width:A,height:r}),n.sourceEvent.stopPropagation(),this.sizeChanged()}},{key:"dragTopLeftFunc",value:function(n){const C=Eg(n,this.domBody);let r=this.dragStartWidth-(C[0]-this.dragStartMousePos[0]);r=r>this.minWidth?r:this.minWidth;let o=this.dragStartLeft+C[0]-this.dragStartMousePos[0];o=r>this.minWidth?o:this.dragStartLeft+this.dragStartWidth-this.minWidth;let A=this.dragStartHeight-(C[1]-this.dragStartMousePos[1]);A=A>this.minHeight?A:this.minHeight;let s=this.dragStartTop+C[1]-this.dragStartMousePos[1];s=A>this.minHeight?s:this.dragStartTop+this.dragStartHeight-this.minHeight,this.setState({top:s,left:o,width:r,height:A}),n.sourceEvent.stopPropagation(),this.sizeChanged()}},{key:"dragStart",value:function(n){this.dragStartMousePos=Eg(n,this.domBody),this.dragStartWidth=this.state.width,this.dragStartHeight=this.state.height,this.dragStartTop=this.state.top,this.dragStartLeft=this.state.left,n.sourceEvent.stopPropagation()}},{key:"sizeChanged",value:function(){this.props.sizeChanged&&this.props.sizeChanged(this.state)}},{key:"rotateClicked",value:function(){this.props.trackRotated(this.state.uid)}},{key:"closeClicked",value:function(){this.props.trackClosed(this.state.uid)}},{key:"render",value:function(){const n=this.props.theme===qg?"white":"black",C={top:this.state.top,left:this.state.left,width:this.state.width,height:this.state.height,opacity:this.props.opacity},r=24,o=24,A={left:this.state.width/2-r/2,width:r},s={top:this.state.height/2-o/2,height:o},a={bottom:{...A,bottom:1},top:{...A,top:1},left:{...s,left:1},right:{...s,right:1}},l=[...this.props.resizeHandles].map(c=>N.createElement("div",{key:c,ref:u=>{this[`${c}Handle`]=u},className:Gx[`${c}-draggable-handle`],style:a[c],title:"Resize track"},N.createElement("div",{className:Gx[`${c}-draggable-handle-grabber`],style:{borderColor:n}})));return N.createElement("div",{ref:c=>{this.divContainer=c},className:Vg(this.props.className,Gx["draggable-div"]),style:C},l)}}]),I}(N.Component);Q1e.propTypes={className:L.string,height:L.number,left:L.number,opacity:L.number,resizeHandles:L.object,sizeChanged:L.func,top:L.number,trackClosed:L.func,trackRotated:L.func,uid:L.string,width:L.number,theme:L.symbol};const HEt=im(Q1e);function TEt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function IAe(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function u2(e){return u2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},u2(e)}let j1e=function(e){KEt(I,e);var g=DEt(I);function I(i){var n;return TEt(this,I),n=g.call(this,i),n.state={controlsVisible:!1},n}return NEt(I,[{key:"shouldComponentUpdate",value:function(){return!this.resizing}},{key:"handleMouseEnter",value:function(){this.setState({controlsVisible:!0})}},{key:"handleMouseLeave",value:function(){this.setState({controlsVisible:!1})}},{key:"handleMouseMove",value:function(){this.setState({controlsVisible:!0})}},{key:"getControls",value:function(){let n=null;return this.moveable?n=f3(()=>N.createElement("svg",{className:"no-zoom",height:"10px",onClick:()=>{},style:this.getMoveImgStyle(),width:"10px"},N.createElement("use",{xlinkHref:"#move"}))):n=f3(()=>N.createElement("div",null)),N.createElement("div",{style:{position:"absolute",backgroundColor:"rgba(255,255,255,0.7)",right:"3px",top:"3px",pointerEvents:"none",paddingLeft:"5px",paddingRight:"5px",borderRadius:"5px",border:"1px solid #dddddd"}},N.createElement(n,null),N.createElement("svg",{ref:C=>{this.imgConfig=C},className:"no-zoom",height:"10px",onClick:()=>{const r=UI.findDOMNode(this.imgConfig).getBoundingClientRect();this.props.onConfigTrackMenuOpened(this.props.uid,r)},style:this.getSettingsImgStyle(),width:"10px"},N.createElement("use",{xlinkHref:"#cog"})),N.createElement("svg",{ref:C=>{this.imgAdd=C},className:"no-zoom",height:"10px",onClick:()=>this.props.onAddSeries(this.props.uid),style:this.getAddImgStyle(),width:"10px"},N.createElement("use",{xlinkHref:"#plus"})),N.createElement("svg",{ref:C=>{this.imgClose=C},className:"no-zoom",height:"10px",onClick:()=>{const r=UI.findDOMNode(this.imgClose).getBoundingClientRect();this.props.onCloseTrackMenuOpened(this.props.uid,r)},style:this.getCloseImgStyle(),width:"10px"},N.createElement("use",{xlinkHref:"#cross"})))}}]),I}(N.Component);j1e.propTypes={configMenuOpen:L.bool,onConfigTrackMenuOpened:L.func,onCloseTrackMenuOpened:L.func,onAddSeries:L.func,uid:L.string};function MEt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function iAe(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function d2(e){return d2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},d2(e)}let ck=function(e){OEt(I,e);var g=_Et(I);function I(i){var n;return MEt(this,I),n=g.call(this,i),n.moveable=!0,n}return zEt(I,[{key:"render",value:function(){return N.createElement("div",{ref:n=>{this.el=n},className:this.props.className,onMouseEnter:this.handleMouseEnter.bind(this),onMouseLeave:()=>{this.handleMouseLeave()},style:{height:this.props.height,width:this.props.width}},N.createElement(HEt,{key:this.props.uid,height:this.props.height,resizeHandles:this.props.editable?this.props.resizeHandles:new Set,sizeChanged:n=>this.props.handleResizeTrack(this.props.uid,n.width,n.height),style:{background:"transparent"},uid:this.props.uid,width:this.props.width}),this.props.editable&&this.getControls(this.state.controlsVisible||this.props.item.configMenuVisible))}}]),I}(j1e);ck.propTypes={className:L.string,uid:L.string,item:L.object,height:L.number,width:L.number};function jEt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function nAe(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function h2(e){return h2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},h2(e)}const yR={pointerEvents:"all"};let $1e=function(e){tMt(I,e);var g=gMt(I);function I(){return jEt(this,I),g.apply(this,arguments)}return $Et(I,[{key:"getControls",value:function(n){return N.createElement($N,{configMenuVisible:this.props.item.configMenuVisible,imgStyleAdd:yR,imgStyleClose:yR,imgStyleMove:yR,imgStyleSettings:yR,isMoveable:this.moveable,isVisible:n,onAddSeries:this.props.onAddSeries,onCloseTrackMenuOpened:this.props.onCloseTrackMenuOpened,onConfigTrackMenuOpened:this.props.onConfigTrackMenuOpened,uid:this.props.uid})}}]),I}(ck);const CMt=oZe(e=>N.createElement($1e,{className:e.className,editable:e.editable,handleConfigTrack:e.handleConfigTrack,handleResizeTrack:e.handleResizeTrack,height:e.height,item:e.item,onAddSeries:e.onAddSeries,onCloseTrack:e.onCloseTrack,onCloseTrackMenuOpened:e.onCloseTrackMenuOpened,onConfigTrackMenuOpened:e.onConfigTrackMenuOpened,resizeHandles:e.resizeHandles,uid:e.uid,width:e.width}));function rJ(){return rJ=Object.assign?Object.assign.bind():function(e){for(var g=1;g{const b=g.map((p,y)=>N.createElement(h,{key:`sci-${p.uid}`,className:I,controlAlignLeft:i,sortingIndex:n,index:y,uid:p.uid,height:p.height,width:p.width,item:p,useDragHandle:C,onCloseTrack:s,onCloseTrackMenuOpened:a,onConfigTrackMenuOpened:l,onAddSeries:c,handleConfigTrack:u,editable:d,handleResizeTrack:m,resizeHandles:f}));return N.createElement("div",rJ({className:e,style:{height:o,width:A,background:"transparent"}},r),b)}),rMt={"horizontal-tiled-plot":"_horizontal-tiled-plot_1bqkg_1"};function oMt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function CAe(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function m2(e){return m2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},m2(e)}function rAe(e){return e&&e.sourceEvent}let f2=function(e){lMt(I,e);var g=cMt(I);function I(i){var n;return oMt(this,I),n=g.call(this,i),n.brushBehavior=iN().on("start",n.brushStarted.bind(iW(n))).on("brush",n.brushed.bind(iW(n))).on("end",n.brushedEnded.bind(iW(n))),n}return AMt(I,[{key:"componentDidMount",value:function(){this.props.isRangeSelectionActive&&this.addBrush()}},{key:"shouldComponentUpdate",value:function(n,C){return this.rangeSelectionTriggered?(this.rangeSelectionTriggered=!1,this.rangeSelectionTriggeredEnd&&this.props.rangeSelection!==n.rangeSelection&&this.moveBrush(n.rangeSelection[0]?n.rangeSelection[0]:null,!0),this.rangeSelectionTriggeredEnd=!1,this.state!==C):this.props.rangeSelection!==n.rangeSelection?(this.moveBrush(n.rangeSelection[0]?n.rangeSelection[0]:null,n.rangeSelectionEnd),this.state!==C):!0}},{key:"componentDidUpdate",value:function(){this.props.isRangeSelectionActive?this.addBrush():this.removeBrush()}},{key:"addBrush",value:function(){!this.brushEl||this.brushElAddedBefore===this.brushEl||(this.brushElAddedBefore&&this.brushElAddedBefore.on(".brush",null),this.brushEl.call(this.brushBehavior),this.brushElAddedBefore=this.brushEl,Bp(this.brushEl,Fo["track-range-selection-group-brush-selection"]))}},{key:"brushed",value:function(n){const C=this.rangeSelectionMoved;this.rangeSelectionMoved=!1,!(!rAe(n)||!this.props.onRangeSelection||C)&&(this.rangeSelectionTriggered=!0,this.props.onRangeSelection(n.selection))}},{key:"brushStarted",value:function(n){!rAe(n)||!n.selection||this.props.onRangeSelectionStart()}},{key:"brushedEnded",value:function(n){if(!this.props.is1dRangeSelection)return;const C=this.rangeSelectionMovedEnd;this.rangeSelectionMovedEnd=!1,n.selection&&n.sourceEvent&&this.props.onRangeSelection&&!C&&(this.rangeSelectionTriggered=!0,this.rangeSelectionTriggeredEnd=!0,this.props.onRangeSelectionEnd(n.selection)),n.selection||(this.rangeSelectionTriggered=!0,this.props.onRangeSelectionReset())}},{key:"moveBrush",value:function(n,C=!1){if(!this.brushEl)return;const r=n?[this.props.scale(n[0]),this.props.scale(n[1])]:null;this.rangeSelectionMoved=!0,this.rangeSelectionMovedEnd=!0,C?this.brushEl.transition().call(this.brushBehavior.move,r):this.brushEl.call(this.brushBehavior.move,r)}},{key:"removeBrush",value:function(){this.brushElAddedBefore&&(this.brushElAddedBefore.call(this.brushBehavior.move,null),this.brushElAddedBefore.on(".brush",null),this.brushElAddedBefore=void 0,this.props.onRangeSelectionReset())}},{key:"render",value:function(){const n=this.props.tracks.map(o=>o.height).reduce(Pl,0),C=this.props.tracks.map(o=>V0(o)).reduce(RS,!1),r=this.props.isRangeSelectionActive?Fo["track-range-selection-active"]:Fo["track-range-selection"];return N.createElement("div",{className:Vg("horizontal-tiled-plot",rMt["horizontal-tiled-plot"])},C&&N.createElement("svg",{ref:o=>{this.brushEl=cg(o)},className:r,style:{height:n,width:this.props.width},xmlns:"http://www.w3.org/2000/svg"}),N.createElement(lk,{className:Vg(Eo.list,Eo.stylizedList),component:q1e,editable:this.props.editable,handleConfigTrack:this.props.handleConfigTrack,handleResizeTrack:this.props.handleResizeTrack,height:n,helperClass:Eo.stylizedHelper,itemClass:Eo.stylizedItem,itemReactClass:CMt,items:this.props.tracks.map(o=>({configMenuVisible:o.uid===this.props.configTrackMenuId,uid:o.uid||Ag.nice(),width:this.props.width,height:o.height,value:o.value})),onAddSeries:this.props.onAddSeries,onCloseTrack:this.props.onCloseTrack,onCloseTrackMenuOpened:this.props.onCloseTrackMenuOpened,onConfigTrackMenuOpened:this.props.onConfigTrackMenuOpened,onSortEnd:this.props.handleSortEnd,referenceAncestor:this.props.referenceAncestor,resizeHandles:this.props.resizeHandles,useDragHandle:!0,width:this.props.width}))}}]),I}(N.Component);f2.propTypes={configTrackMenuId:L.string,editable:L.bool,handleConfigTrack:L.func,handleResizeTrack:L.func,handleSortEnd:L.func,is1dRangeSelection:L.bool,isRangeSelectionActive:L.bool,onAddSeries:L.func,onCloseTrack:L.func,onCloseTrackMenuOpened:L.func,onConfigTrackMenuOpened:L.func,onRangeSelection:L.func,onRangeSelectionEnd:L.func,onRangeSelectionReset:L.func,onRangeSelectionStart:L.func,rangeSelection:L.array,rangeSelectionEnd:L.bool,referenceAncestor:L.func,resizeHandles:L.object,scale:L.func,tracks:L.array,width:L.number};function hMt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function oAe(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function p2(e){return p2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},p2(e)}const ZR={pointerEvents:"all"};let eWe=function(e){bMt(I,e);var g=yMt(I);function I(){return hMt(this,I),g.apply(this,arguments)}return mMt(I,[{key:"getControls",value:function(n){return N.createElement($N,{imgStyleAdd:ZR,imgStyleClose:ZR,imgStyleMove:ZR,imgStyleSettings:ZR,isAlignLeft:this.props.controlAlignLeft,isMoveable:this.moveable,isVertical:!0,isVisible:n,onAddSeries:this.props.onAddSeries,onCloseTrackMenuOpened:this.props.onCloseTrackMenuOpened,onConfigTrackMenuOpened:this.props.onConfigTrackMenuOpened,uid:this.props.uid})}}]),I}(ck);function BMt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function AAe(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function t0(e){return t0=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},t0(e)}let NMt=function(e){WMt(I,e);var g=XMt(I);function I(i,n){var C;BMt(this,I),C=g.call(this,i,n);const{registerViewportChanged:r,removeViewportChanged:o}=i,A=Ag.nice();return C.uid=A,C.removeViewportChanged=o,C.viewportXDomain=null,C.viewportYDomain=null,r(A,C.viewportChanged.bind(tWe(C))),C}return SMt(I,[{key:"viewportChanged",value:function(n,C){const r=n.domain(),o=C.domain();this.viewportXDomain=r,this.viewportYDomain=o,this.draw()}},{key:"draw",value:function(){const n=this.pMain;if(!this.viewportXDomain||!this.viewportYDomain)return;n.clear(),n.lineStyle(1,255,1),n.beginFill(16740363,1);const C=this._xScale(this.viewportXDomain[0]),r=this._yScale(this.viewportYDomain[0]),o=this._xScale(this.viewportXDomain[1])-this._xScale(this.viewportXDomain[0]),A=this._yScale(this.viewportYDomain[1])-this._yScale(this.viewportYDomain[0]);this.pMain.drawRect(C,r,o,A)}},{key:"zoomed",value:function(n,C){this.xScale(n),this.yScale(C),this.draw()}},{key:"setPosition",value:function(n){nW(t0(I.prototype),"setPosition",this).call(this,n),this.pMain.position.y=this.position[1],this.pMain.position.x=this.position[0],this.draw()}}]),I}(lC);function gWe(e){this.size=0,this.limit=e,this._keymap={}}function kMt(e,g){const I={key:e,value:g};if(this._keymap[e]=I,this.tail?(this.tail.newer=I,I.older=this.tail):this.head=I,this.tail=I,this.size===this.limit)return this.shift();this.size+=1}function YMt(){const e=this.head;return e&&(this.head.newer?(this.head=this.head.newer,this.head.older=void 0):(this.head=void 0,this.tail=void 0),e.newer=void 0,e.older=void 0,delete this._keymap[e.key],this.size-=1),e}function KMt(e,g){const I=this._keymap[e];if(I!==void 0)return I===this.tail||(I.newer&&(I===this.head&&(this.head=I.newer),I.newer.older=I.older),I.older&&(I.older.newer=I.newer),I.newer=void 0,I.older=this.tail,this.tail&&(this.tail.newer=I),this.tail=I),g?I:I.value}function DMt(e){return this._keymap[e]}function xMt(e,g){const I=this.get(e,!0);let i;return I?(i=I.value,I.value=g):(i=this.put(e,g),i&&(i=i.value)),i}function FMt(e){const g=this._keymap[e];if(g)return delete this._keymap[g.key],g.newer&&g.older?(g.older.newer=g.newer,g.newer.older=g.older):g.newer?(g.newer.older=void 0,this.head=g.newer):g.older?(g.older.newer=void 0,this.tail=g.older):(this.head=void 0,this.tail=void 0),this.size-=1,g.value}function EMt(){this.head=void 0,this.tail=void 0,this.size=0,this._keymap={}}function MMt(){return Object.keys(this._keymap)}function zMt(e,g,I){let i;if(g===!0?(I=!0,g=void 0):typeof g!="object"&&(g=this),I)for(i=this.tail;i;)e.call(g,i.key,i.value,this),i=i.older;else for(i=this.head;i;)e.call(g,i.key,i.value,this),i=i.newer}function PMt(){const e=[];let g=this.head;for(;g;)e.push({key:g.key.toJSON(),value:g.value.toJSON()}),g=g.newer;return e}function JMt(){let e="",g=this.head;for(;g;)e+=`${String(g.key)}:${g.value}`,g=g.newer,g&&(e+=" < ");return e}Object.assign(gWe.prototype,{put:kMt,get:KMt,find:DMt,keys:MMt,set:xMt,shift:YMt,remove:FMt,removeAll:EMt,forEach:zMt,toJSON:PMt,toString:JMt});const IWe="1.13.3",OMt="_button_1wnjn_1",vx={button:OMt,"button-shortcut":"_button-shortcut_1wnjn_35"},vs=N.forwardRef((e,g)=>N.createElement("button",{ref:g,className:vx[e.styleName]??vx.button,disabled:e.disable,onBlur:e.onBlur,onClick:e.onClick,onMouseDown:e.onMouseDown,onMouseOut:e.onMouseOut,onMouseUp:e.onMouseUp,type:"button"},e.children,e.shortcut&&N.createElement("span",{className:vx["button-shortcut"]},e.shortcut)));vs.defaultProps={onClick:()=>{},styleName:"",type:"button"};vs.propTypes={children:L.any,disable:L.bool,onBlur:L.func,onClick:L.func,onMouseDown:L.func,onMouseOut:L.func,onMouseUp:L.func,shortcut:L.string,type:L.string,styleName:L.string};const _Mt="_cross_2ke8w_1",LMt={cross:_Mt};function iWe(){return N.createElement("div",{className:LMt.cross})}function sJ(){return sJ=Object.assign?Object.assign.bind():function(e){for(var g=1;gN.forwardRef((g,I)=>N.createElement(QMt,null,i=>N.createElement(e,sJ({ref:I},g,{modal:i})))),Lm={"modal-background":"_modal-background_zzhoe_1","fade-in":"_fade-in_zzhoe_1","modal-hide":"_modal-hide_zzhoe_13","modal-wrap":"_modal-wrap_zzhoe_17","modal-window":"_modal-window_zzhoe_25","fade-scale-in":"_fade-scale-in_zzhoe_1","modal-window-max-height":"_modal-window-max-height_zzhoe_38","modal-content":"_modal-content_zzhoe_42"};function Lj(e){const g=()=>{e.modal.close(),e.onClose&&e.onClose()};return N.createElement("div",{className:Vg(Lm["modal-background"],{[Lm["modal-hide"]]:e.hide})},N.createElement("div",{className:Lm["modal-wrap"]},N.createElement("div",{className:Vg(Lm["modal-window"],{[Lm["modal-window-max-height"]]:e.maxHeight})},e.closeButton&&N.createElement(vs,{onClick:g},N.createElement(iWe,null)),N.createElement("div",{className:Lm["modal-content"]},e.children))))}Lj.defaultProps={closeButton:!0,hide:!1,maxHeight:!1};Lj.propTypes={children:L.element.isRequired,closeButton:L.bool,hide:L.bool,maxHeight:L.bool,modal:L.object.isRequired,onClose:L.func};const jMt=uk(Lj),Bx={"dialog-header":"_dialog-header_wp50s_1","dialog-main-max-height":"_dialog-main-max-height_wp50s_20","dialog-footer":"_dialog-footer_wp50s_31","dialog-footer-max-height":"_dialog-footer-max-height_wp50s_31"};function Uj(e){const g=()=>{e.modal.close(),e.onCancel&&e.onCancel()},I=()=>{e.modal.close(),e.onOkay&&e.onOkay()};return N.createElement(jMt,{closeButton:!1,hide:e.hide,maxHeight:e.maxHeight},N.createElement(N.Fragment,null,N.createElement("header",{className:Bx["dialog-header"]},N.createElement("h3",null,e.title),N.createElement(vs,{onClick:g},N.createElement(iWe,null))),e.maxHeight?N.createElement("main",{className:Vg(e.maxHeight&&Bx["dialog-main-max-height"])},e.children):N.createElement("main",null,e.children),N.createElement("footer",{className:Bx[e.maxHeight?"dialog-footer-max-height":"dialog-footer"]},e.okayOnly?N.createElement("div",null):N.createElement(vs,{onClick:g,shortcut:e.cancelShortcut},e.cancelTitle),N.createElement(vs,{onClick:I,shortcut:e.okayShortcut},e.okayTitle))))}Uj.defaultProps={cancelTitle:"Cancel",hide:!1,maxHeight:!1,okayOnly:!1,okayTitle:"Ok"};Uj.propTypes={cancelShortcut:L.string,cancelTitle:L.string,children:L.object,hide:L.bool,maxHeight:L.bool,modal:L.object.isRequired,okayShortcut:L.string,okayTitle:L.string,okayOnly:L.bool,onCancel:L.func.isRequired,onOkay:L.func.isRequired,title:L.string.isRequired};const Iw=uk(Uj);var Fr={},iw={},$Mt=typeof globalThis=="object"&&globalThis&&globalThis.Object===Object&&globalThis;const nWe=$Mt;var qMt=typeof self=="object"&&self&&self.Object===Object&&self,e3t=nWe||qMt||Function("return this")();const fA=e3t;var t3t=fA.Symbol;const pa=t3t;var CWe=Object.prototype,g3t=CWe.hasOwnProperty,I3t=CWe.toString,IZ=pa?pa.toStringTag:void 0;function i3t(e){var g=g3t.call(e,IZ),I=e[IZ];try{e[IZ]=void 0;var i=!0}catch{}var n=I3t.call(e);return i&&(g?e[IZ]=I:delete e[IZ]),n}var n3t=Object.prototype,C3t=n3t.toString;function r3t(e){return C3t.call(e)}var o3t="[object Null]",A3t="[object Undefined]",aAe=pa?pa.toStringTag:void 0;function nu(e){return e==null?e===void 0?A3t:o3t:aAe&&aAe in Object(e)?i3t(e):r3t(e)}var a3t=Array.isArray;const oC=a3t;function AA(e){return e!=null&&typeof e=="object"}var s3t="[object String]";function l3t(e){return typeof e=="string"||!oC(e)&&AA(e)&&nu(e)==s3t}const c3t=Object.freeze(Object.defineProperty({__proto__:null,default:l3t},Symbol.toStringTag,{value:"Module"})),u3t=Os(c3t);function d3t(e){return function(g,I,i){for(var n=-1,C=Object(g),r=i(g),o=r.length;o--;){var A=r[e?o:++n];if(I(C[A],A,C)===!1)break}return g}}var h3t=d3t();const rWe=h3t;function m3t(e,g){for(var I=-1,i=Array(e);++I-1&&e%1==0&&e-1&&e%1==0&&e<=V3t}var R3t="[object Arguments]",W3t="[object Array]",X3t="[object Boolean]",H3t="[object Date]",T3t="[object Error]",N3t="[object Function]",k3t="[object Map]",Y3t="[object Number]",K3t="[object Object]",D3t="[object RegExp]",x3t="[object Set]",F3t="[object String]",E3t="[object WeakMap]",M3t="[object ArrayBuffer]",z3t="[object DataView]",P3t="[object Float32Array]",J3t="[object Float64Array]",O3t="[object Int8Array]",_3t="[object Int16Array]",L3t="[object Int32Array]",U3t="[object Uint8Array]",Q3t="[object Uint8ClampedArray]",j3t="[object Uint16Array]",$3t="[object Uint32Array]",dI={};dI[P3t]=dI[J3t]=dI[O3t]=dI[_3t]=dI[L3t]=dI[U3t]=dI[Q3t]=dI[j3t]=dI[$3t]=!0;dI[R3t]=dI[W3t]=dI[M3t]=dI[X3t]=dI[z3t]=dI[H3t]=dI[T3t]=dI[N3t]=dI[k3t]=dI[Y3t]=dI[K3t]=dI[D3t]=dI[x3t]=dI[F3t]=dI[E3t]=!1;function q3t(e){return AA(e)&&jj(e.length)&&!!dI[nu(e)]}function $j(e){return function(g){return e(g)}}var aWe=typeof exports=="object"&&exports&&!exports.nodeType&&exports,mv=aWe&&typeof module=="object"&&module&&!module.nodeType&&module,ezt=mv&&mv.exports===aWe,Sx=ezt&&nWe.process,tzt=function(){try{var e=mv&&mv.require&&mv.require("util").types;return e||Sx&&Sx.binding&&Sx.binding("util")}catch{}}();const g0=tzt;var uAe=g0&&g0.isTypedArray,gzt=uAe?$j(uAe):q3t;const qj=gzt;var Izt=Object.prototype,izt=Izt.hasOwnProperty;function sWe(e,g){var I=oC(e),i=!I&&b2(e),n=!I&&!i&&KB(e),C=!I&&!i&&!n&&qj(e),r=I||i||n||C,o=r?m3t(e.length,String):[],A=o.length;for(var s in e)(g||izt.call(e,s))&&!(r&&(s=="length"||n&&(s=="offset"||s=="parent")||C&&(s=="buffer"||s=="byteLength"||s=="byteOffset")||Qj(s,A)))&&o.push(s);return o}var nzt=Object.prototype;function e4(e){var g=e&&e.constructor,I=typeof g=="function"&&g.prototype||nzt;return e===I}function lWe(e,g){return function(I){return e(g(I))}}var Czt=lWe(Object.keys,Object);const rzt=Czt;var ozt=Object.prototype,Azt=ozt.hasOwnProperty;function azt(e){if(!e4(e))return rzt(e);var g=[];for(var I in Object(e))Azt.call(e,I)&&I!="constructor"&&g.push(I);return g}function ur(e){var g=typeof e;return e!=null&&(g=="object"||g=="function")}var szt="[object AsyncFunction]",lzt="[object Function]",czt="[object GeneratorFunction]",uzt="[object Proxy]";function t4(e){if(!ur(e))return!1;var g=nu(e);return g==lzt||g==czt||g==szt||g==uzt}function j0(e){return e!=null&&jj(e.length)&&!t4(e)}function nw(e){return j0(e)?sWe(e):azt(e)}function cWe(e,g){return e&&rWe(e,g,nw)}function dk(e){return e}function uWe(e){return typeof e=="function"?e:dk}function dzt(e,g){return e&&cWe(e,uWe(g))}const hzt=Object.freeze(Object.defineProperty({__proto__:null,default:dzt},Symbol.toStringTag,{value:"Module"})),g4=Os(hzt);var mzt=lWe(Object.getPrototypeOf,Object);const I4=mzt;var fzt="[object Object]",pzt=Function.prototype,bzt=Object.prototype,dWe=pzt.toString,yzt=bzt.hasOwnProperty,Zzt=dWe.call(Object);function hWe(e){if(!AA(e)||nu(e)!=fzt)return!1;var g=I4(e);if(g===null)return!0;var I=yzt.call(g,"constructor")&&g.constructor;return typeof I=="function"&&I instanceof I&&dWe.call(I)==Zzt}const Gzt=Object.freeze(Object.defineProperty({__proto__:null,default:hWe},Symbol.toStringTag,{value:"Module"})),vzt=Os(Gzt);function mWe(e,g){for(var I=-1,i=e==null?0:e.length,n=Array(i);++I-1}function Xzt(e,g){var I=this.__data__,i=hk(I,e);return i<0?(++this.size,I.push([e,g])):I[i][1]=g,this}function gl(e){var g=-1,I=e==null?0:e.length;for(this.clear();++go))return!1;var s=C.get(e),a=C.get(g);if(s&&a)return s==g&&a==e;var l=-1,c=!0,u=I&ZPt?new y2:void 0;for(C.set(e,g),C.set(g,e);++l0&&arguments[0]!==void 0?arguments[0]:[],I=[];return(0,LJt.default)(g,function(i){Array.isArray(i)?e(i).map(function(n){return I.push(n)}):(0,OJt.default)(i)?(0,PJt.default)(i,function(n,C){n===!0&&I.push(C),I.push(C+"-"+n)}):(0,MJt.default)(i)&&I.push(i)}),I};iw.default=UJt;var rw={};function VWe(e,g){for(var I=-1,i=e==null?0:e.length;++I1&&arguments[1]!==void 0?arguments[1]:[],i=g.default&&(0,V_t.default)(g.default)||{};return I.map(function(n){var C=g[n];return C&&(0,S_t.default)(C,function(r,o){i[o]||(i[o]={}),i[o]=R_t({},i[o],C[o])}),n}),i};rw.default=W_t;var aw={};Object.defineProperty(aw,"__esModule",{value:!0});aw.autoprefix=void 0;var X_t=g4,YAe=T_t(X_t),H_t=Object.assign||function(e){for(var g=1;g1&&arguments[1]!==void 0?arguments[1]:"span";return function(i){F_t(n,i);function n(){var C,r,o,A;x_t(this,n);for(var s=arguments.length,a=Array(s),l=0;l1&&arguments[1]!==void 0?arguments[1]:"span";return function(i){O_t(n,i);function n(){var C,r,o,A;J_t(this,n);for(var s=arguments.length,a=Array(s),l=0;l1&&arguments[1]!==void 0?arguments[1]:!0;i[r]=o};return g===0&&n("first-child"),g===I-1&&n("last-child"),(g===0||g%2===0)&&n("even"),Math.abs(g%2)===1&&n("odd"),n("nth-child",g),i};a4.default=L_t;Object.defineProperty(Fr,"__esModule",{value:!0});Fr.ReactCSS=Fr.loop=Fr.handleActive=s4=Fr.handleHover=Fr.hover=void 0;var U_t=iw,Q_t=$0(U_t),j_t=rw,$_t=$0(j_t),q_t=aw,eLt=$0(q_t),tLt=sw,FWe=$0(tLt),gLt=lw,ILt=$0(gLt),iLt=a4,nLt=$0(iLt);function $0(e){return e&&e.__esModule?e:{default:e}}Fr.hover=FWe.default;var s4=Fr.handleHover=FWe.default;Fr.handleActive=ILt.default;Fr.loop=nLt.default;var CLt=Fr.ReactCSS=function(g){for(var I=arguments.length,i=Array(I>1?I-1:0),n=1;no?c=1:c=Math.round(l*100/o)/100,I.a!==c)return{h:I.h,s:I.s,l:I.l,a:c,source:"rgb"}}else{var u=void 0;if(a<0?u=0:a>r?u=1:u=Math.round(a*100/r)/100,n!==u)return{h:I.h,s:I.s,l:I.l,a:u,source:"rgb"}}return null},Xx={},oLt=function(g,I,i,n){if(typeof document>"u"&&!n)return null;var C=n?new n:document.createElement("canvas");C.width=i*2,C.height=i*2;var r=C.getContext("2d");return r?(r.fillStyle=g,r.fillRect(0,0,C.width,C.height),r.fillStyle=I,r.fillRect(0,0,i,i),r.translate(i,i),r.fillRect(0,0,i,i),C.toDataURL()):null},ALt=function(g,I,i,n){var C=g+"-"+I+"-"+i+(n?"-server":"");if(Xx[C])return Xx[C];var r=oLt(g,I,i,n);return Xx[C]=r,r},xAe=Object.assign||function(e){for(var g=1;g-1},JOt=function(e){return Number(String(e).replace(/%/g,""))},OOt=1,Rg=function(g){FOt(e,g);function e(I){xOt(this,e);var i=DOt(this,(e.__proto__||Object.getPrototypeOf(e)).call(this));return i.handleBlur=function(){i.state.blurValue&&i.setState({value:i.state.blurValue,blurValue:null})},i.handleChange=function(n){i.setUpdatedValue(n.target.value,n)},i.handleKeyDown=function(n){var C=JOt(n.target.value);if(!isNaN(C)&&POt(n.keyCode)){var r=i.getArrowOffset(),o=n.keyCode===jXe?C+r:C-r;i.setUpdatedValue(o,n)}},i.handleDrag=function(n){if(i.props.dragLabel){var C=Math.round(i.props.value+n.movementX);C>=0&&C<=i.props.dragMax&&i.props.onChange&&i.props.onChange(i.getValueObjectWithLabel(C),n)}},i.handleMouseDown=function(n){i.props.dragLabel&&(n.preventDefault(),i.handleDrag(n),window.addEventListener("mousemove",i.handleDrag),window.addEventListener("mouseup",i.handleMouseUp))},i.handleMouseUp=function(){i.unbindEventListeners()},i.unbindEventListeners=function(){window.removeEventListener("mousemove",i.handleDrag),window.removeEventListener("mouseup",i.handleMouseUp)},i.state={value:String(I.value).toUpperCase(),blurValue:String(I.value).toUpperCase()},i.inputId="rc-editable-input-"+OOt++,i}return YOt(e,[{key:"componentDidUpdate",value:function(i,n){this.props.value!==this.state.value&&(i.value!==this.props.value||n.value!==this.state.value)&&(this.input===document.activeElement?this.setState({blurValue:String(this.props.value).toUpperCase()}):this.setState({value:String(this.props.value).toUpperCase(),blurValue:!this.state.blurValue&&String(this.props.value).toUpperCase()}))}},{key:"componentWillUnmount",value:function(){this.unbindEventListeners()}},{key:"getValueObjectWithLabel",value:function(i){return KOt({},this.props.label,i)}},{key:"getArrowOffset",value:function(){return this.props.arrowOffset||EOt}},{key:"setUpdatedValue",value:function(i,n){var C=this.props.label?this.getValueObjectWithLabel(i):i;this.props.onChange&&this.props.onChange(C,n),this.setState({value:i})}},{key:"render",value:function(){var i=this,n=gg({default:{wrap:{position:"relative"}},"user-override":{wrap:this.props.style&&this.props.style.wrap?this.props.style.wrap:{},input:this.props.style&&this.props.style.input?this.props.style.input:{},label:this.props.style&&this.props.style.label?this.props.style.label:{}},"dragLabel-true":{label:{cursor:"ew-resize"}}},{"user-override":!0},this.props);return N.createElement("div",{style:n.wrap},N.createElement("input",{id:this.inputId,style:n.input,ref:function(r){return i.input=r},value:this.state.value,onKeyDown:this.handleKeyDown,onChange:this.handleChange,onBlur:this.handleBlur,placeholder:this.props.placeholder,spellCheck:"false"}),this.props.label&&!this.props.hideLabel?N.createElement("label",{htmlFor:this.inputId,style:n.label,onMouseDown:this.handleMouseDown},this.props.label):null)}}]),e}(Ie.PureComponent||Ie.Component),LOt=function(e,I,i,n){var C=n.clientWidth,r=n.clientHeight,o=typeof e.pageX=="number"?e.pageX:e.touches[0].pageX,A=typeof e.pageY=="number"?e.pageY:e.touches[0].pageY,s=o-(n.getBoundingClientRect().left+window.pageXOffset),a=A-(n.getBoundingClientRect().top+window.pageYOffset);if(I==="vertical"){var l=void 0;if(a<0)l=359;else if(a>r)l=0;else{var c=-(a*100/r)+100;l=360*c/100}if(i.h!==l)return{h:l,s:i.s,l:i.l,a:i.a,source:"hsl"}}else{var u=void 0;if(s<0)u=0;else if(s>C)u=359;else{var d=s*100/C;u=360*d/100}if(i.h!==u)return{h:u,s:i.s,l:i.l,a:i.a,source:"hsl"}}return null},_Ot=function(){function g(e,I){for(var i=0;i-1},GLt=function(g){return Number(String(g).replace(/%/g,""))},vLt=1,Gg=function(e){fLt(g,e);function g(I){hLt(this,g);var i=mLt(this,(g.__proto__||Object.getPrototypeOf(g)).call(this));return i.handleBlur=function(){i.state.blurValue&&i.setState({value:i.state.blurValue,blurValue:null})},i.handleChange=function(n){i.setUpdatedValue(n.target.value,n)},i.handleKeyDown=function(n){var C=GLt(n.target.value);if(!isNaN(C)&&ZLt(n.keyCode)){var r=i.getArrowOffset(),o=n.keyCode===EWe?C+r:C-r;i.setUpdatedValue(o,n)}},i.handleDrag=function(n){if(i.props.dragLabel){var C=Math.round(i.props.value+n.movementX);C>=0&&C<=i.props.dragMax&&i.props.onChange&&i.props.onChange(i.getValueObjectWithLabel(C),n)}},i.handleMouseDown=function(n){i.props.dragLabel&&(n.preventDefault(),i.handleDrag(n),window.addEventListener("mousemove",i.handleDrag),window.addEventListener("mouseup",i.handleMouseUp))},i.handleMouseUp=function(){i.unbindEventListeners()},i.unbindEventListeners=function(){window.removeEventListener("mousemove",i.handleDrag),window.removeEventListener("mouseup",i.handleMouseUp)},i.state={value:String(I.value).toUpperCase(),blurValue:String(I.value).toUpperCase()},i.inputId="rc-editable-input-"+vLt++,i}return uLt(g,[{key:"componentDidUpdate",value:function(i,n){this.props.value!==this.state.value&&(i.value!==this.props.value||n.value!==this.state.value)&&(this.input===document.activeElement?this.setState({blurValue:String(this.props.value).toUpperCase()}):this.setState({value:String(this.props.value).toUpperCase(),blurValue:!this.state.blurValue&&String(this.props.value).toUpperCase()}))}},{key:"componentWillUnmount",value:function(){this.unbindEventListeners()}},{key:"getValueObjectWithLabel",value:function(i){return dLt({},this.props.label,i)}},{key:"getArrowOffset",value:function(){return this.props.arrowOffset||pLt}},{key:"setUpdatedValue",value:function(i,n){var C=this.props.label?this.getValueObjectWithLabel(i):i;this.props.onChange&&this.props.onChange(C,n),this.setState({value:i})}},{key:"render",value:function(){var i=this,n=Qt({default:{wrap:{position:"relative"}},"user-override":{wrap:this.props.style&&this.props.style.wrap?this.props.style.wrap:{},input:this.props.style&&this.props.style.input?this.props.style.input:{},label:this.props.style&&this.props.style.label?this.props.style.label:{}},"dragLabel-true":{label:{cursor:"ew-resize"}}},{"user-override":!0},this.props);return N.createElement("div",{style:n.wrap},N.createElement("input",{id:this.inputId,style:n.input,ref:function(r){return i.input=r},value:this.state.value,onKeyDown:this.handleKeyDown,onChange:this.handleChange,onBlur:this.handleBlur,placeholder:this.props.placeholder,spellCheck:"false"}),this.props.label&&!this.props.hideLabel?N.createElement("label",{htmlFor:this.inputId,style:n.label,onMouseDown:this.handleMouseDown},this.props.label):null)}}]),g}(Ie.PureComponent||Ie.Component),BLt=function(g,I,i,n){var C=n.clientWidth,r=n.clientHeight,o=typeof g.pageX=="number"?g.pageX:g.touches[0].pageX,A=typeof g.pageY=="number"?g.pageY:g.touches[0].pageY,s=o-(n.getBoundingClientRect().left+window.pageXOffset),a=A-(n.getBoundingClientRect().top+window.pageYOffset);if(I==="vertical"){var l=void 0;if(a<0)l=359;else if(a>r)l=0;else{var c=-(a*100/r)+100;l=360*c/100}if(i.h!==l)return{h:l,s:i.s,l:i.l,a:i.a,source:"hsl"}}else{var u=void 0;if(s<0)u=0;else if(s>C)u=359;else{var d=s*100/C;u=360*d/100}if(i.h!==u)return{h:u,s:i.s,l:i.l,a:i.a,source:"hsl"}}return null},SLt=function(){function e(g,I){for(var i=0;i0){if(++e>=nLt)return arguments[0]}else e=0;return g.apply(void 0,arguments)}}var ALt=oLt(iLt);const aLt=ALt;function sLt(g,e){return aLt(tLt(g,e,rY),g+"")}function lLt(g,e,I){if(!Zr(I))return!1;var i=typeof e;return(i=="number"?hy(I)&&R4(e,I.length):i=="string"&&e in I)?Dw(I[e],g):!1}function cLt(g){return sLt(function(e,I){var i=-1,n=I.length,C=n>1?I[n-1]:void 0,r=n>2?I[2]:void 0;for(C=g.length>3&&typeof C=="function"?(n--,C):void 0,r&&lLt(I[0],I[1],r)&&(C=n<3?void 0:C,n=1),e=Object(e);++i=e||G<0||l&&B>=C}function f(){var v=ZF();if(m(v))return b(v);o=setTimeout(f,h(v))}function b(v){return o=void 0,c&&i?u(v):(i=n=void 0,r)}function p(){o!==void 0&&clearTimeout(o),s=0,i=A=n=o=void 0}function y(){return o===void 0?r:b(ZF())}function Z(){var v=ZF(),G=m(v);if(i=arguments,n=this,A=v,G){if(o===void 0)return d(A);if(l)return clearTimeout(o),o=setTimeout(f,e),u(A)}return o===void 0&&(o=setTimeout(f,e)),r}return Z.cancel=p,Z.flush=y,Z}var wLt="Expected a function";function VLt(g,e,I){var i=!0,n=!0;if(typeof g!="function")throw new TypeError(wLt);return Zr(I)&&(i="leading"in I?!!I.leading:i,n="trailing"in I?!!I.trailing:n),qXe(g,e,{leading:i,maxWait:e,trailing:n})}var RLt=function(e,I,i){var n=i.getBoundingClientRect(),C=n.width,r=n.height,o=typeof e.pageX=="number"?e.pageX:e.touches[0].pageX,A=typeof e.pageY=="number"?e.pageY:e.touches[0].pageY,s=o-(i.getBoundingClientRect().left+window.pageXOffset),a=A-(i.getBoundingClientRect().top+window.pageYOffset);s<0?s=0:s>C&&(s=C),a<0?a=0:a>r&&(a=r);var l=s/C,c=1-a/r;return{h:I.h,s:l,v:c,a:I.a,source:"hsv"}},WLt=function(){function g(e,I){for(var i=0;i0){if(++g>=KLt)return arguments[0]}else g=0;return e.apply(void 0,arguments)}}var ELt=FLt(YLt);const MLt=ELt;function zLt(e,g){return MLt(TLt(e,g,dk),e+"")}function PLt(e,g,I){if(!ur(I))return!1;var i=typeof g;return(i=="number"?j0(I)&&Qj(g,I.length):i=="string"&&g in I)?Cw(I[g],e):!1}function JLt(e){return zLt(function(g,I){var i=-1,n=I.length,C=n>1?I[n-1]:void 0,r=n>2?I[2]:void 0;for(C=e.length>3&&typeof C=="function"?(n--,C):void 0,r&&PLt(I[0],I[1],r)&&(C=n<3?void 0:C,n=1),g=Object(g);++i=g||G<0||l&&v>=C}function f(){var B=Hx();if(m(B))return b(B);o=setTimeout(f,h(B))}function b(B){return o=void 0,c&&i?u(B):(i=n=void 0,r)}function p(){o!==void 0&&clearTimeout(o),s=0,i=A=n=o=void 0}function y(){return o===void 0?r:b(Hx())}function Z(){var B=Hx(),G=m(B);if(i=arguments,n=this,A=B,G){if(o===void 0)return d(A);if(l)return clearTimeout(o),o=setTimeout(f,g),u(A)}return o===void 0&&(o=setTimeout(f,g)),r}return Z.cancel=p,Z.flush=y,Z}var nUt="Expected a function";function CUt(e,g,I){var i=!0,n=!0;if(typeof e!="function")throw new TypeError(nUt);return ur(I)&&(i="leading"in I?!!I.leading:i,n="trailing"in I?!!I.trailing:n),zWe(e,g,{leading:i,maxWait:g,trailing:n})}var rUt=function(g,I,i){var n=i.getBoundingClientRect(),C=n.width,r=n.height,o=typeof g.pageX=="number"?g.pageX:g.touches[0].pageX,A=typeof g.pageY=="number"?g.pageY:g.touches[0].pageY,s=o-(i.getBoundingClientRect().left+window.pageXOffset),a=A-(i.getBoundingClientRect().top+window.pageYOffset);s<0?s=0:s>C&&(s=C),a<0?a=0:a>r&&(a=r);var l=s/C,c=1-a/r;return{h:I.h,s:l,v:c,a:I.a,source:"hsv"}},oUt=function(){function e(g,I){for(var i=0;i=0,C=!I&&n&&(e==="hex"||e==="hex6"||e==="hex3"||e==="hex4"||e==="hex8"||e==="name");return C?e==="name"&&this._a===0?this.toName():this.toRgbString():(e==="rgb"&&(i=this.toRgbString()),e==="prgb"&&(i=this.toPercentageRgbString()),(e==="hex"||e==="hex6")&&(i=this.toHexString()),e==="hex3"&&(i=this.toHexString(!0)),e==="hex4"&&(i=this.toHex8String(!0)),e==="hex8"&&(i=this.toHex8String()),e==="name"&&(i=this.toName()),e==="hsl"&&(i=this.toHslString()),e==="hsv"&&(i=this.toHsvString()),i||this.toHexString())},clone:function(){return Dt(this.toString())},_applyModification:function(e,I){var i=e.apply(null,[this].concat([].slice.call(I)));return this._r=i._r,this._g=i._g,this._b=i._b,this.setAlpha(i._a),this},lighten:function(){return this._applyModification(JLt,arguments)},brighten:function(){return this._applyModification(OLt,arguments)},darken:function(){return this._applyModification(LLt,arguments)},desaturate:function(){return this._applyModification(MLt,arguments)},saturate:function(){return this._applyModification(zLt,arguments)},greyscale:function(){return this._applyModification(PLt,arguments)},spin:function(){return this._applyModification(_Lt,arguments)},_applyCombination:function(e,I){return e.apply(null,[this].concat([].slice.call(I)))},analogous:function(){return this._applyCombination(jLt,arguments)},complement:function(){return this._applyCombination(ULt,arguments)},monochromatic:function(){return this._applyCombination($Lt,arguments)},splitcomplement:function(){return this._applyCombination(QLt,arguments)},triad:function(){return this._applyCombination(Nae,[3])},tetrad:function(){return this._applyCombination(Nae,[4])}};Dt.fromRatio=function(g,e){if(u2(g)=="object"){var I={};for(var i in g)g.hasOwnProperty(i)&&(i==="a"?I[i]=g[i]:I[i]=bG(g[i]));g=I}return Dt(g,e)};function KLt(g){var e={r:0,g:0,b:0},I=1,i=null,n=null,C=null,r=!1,o=!1;return typeof g=="string"&&(g=I_t(g)),u2(g)=="object"&&(Ua(g.r)&&Ua(g.g)&&Ua(g.b)?(e=xLt(g.r,g.g,g.b),r=!0,o=String(g.r).substr(-1)==="%"?"prgb":"rgb"):Ua(g.h)&&Ua(g.s)&&Ua(g.v)?(i=bG(g.s),n=bG(g.v),e=FLt(g.h,i,n),r=!0,o="hsv"):Ua(g.h)&&Ua(g.s)&&Ua(g.l)&&(i=bG(g.s),C=bG(g.l),e=DLt(g.h,i,C),r=!0,o="hsl"),g.hasOwnProperty("a")&&(I=g.a)),I=e9e(I),{ok:r,format:g.format||o,r:Math.min(255,Math.max(e.r,0)),g:Math.min(255,Math.max(e.g,0)),b:Math.min(255,Math.max(e.b,0)),a:I}}function xLt(g,e,I){return{r:RI(g,255)*255,g:RI(e,255)*255,b:RI(I,255)*255}}function Wae(g,e,I){g=RI(g,255),e=RI(e,255),I=RI(I,255);var i=Math.max(g,e,I),n=Math.min(g,e,I),C,r,o=(i+n)/2;if(i==n)C=r=0;else{var A=i-n;switch(r=o>.5?A/(2-i-n):A/(i+n),i){case g:C=(e-I)/A+(e1&&(l-=1),l<1/6?s+(a-s)*6*l:l<1/2?a:l<2/3?s+(a-s)*(2/3-l)*6:s}if(e===0)i=n=C=I;else{var o=I<.5?I*(1+e):I+e-I*e,A=2*I-o;i=r(A,o,g+1/3),n=r(A,o,g),C=r(A,o,g-1/3)}return{r:i*255,g:n*255,b:C*255}}function Xae(g,e,I){g=RI(g,255),e=RI(e,255),I=RI(I,255);var i=Math.max(g,e,I),n=Math.min(g,e,I),C,r,o=i,A=i-n;if(r=i===0?0:A/i,i==n)C=0;else{switch(i){case g:C=(e-I)/A+(e>1)+720)%360;--e;)i.h=(i.h+n)%360,C.push(Dt(i));return C}function $Lt(g,e){e=e||6;for(var I=Dt(g).toHsv(),i=I.h,n=I.s,C=I.v,r=[],o=1/e;e--;)r.push(Dt({h:i,s:n,v:C})),C=(C+o)%1;return r}Dt.mix=function(g,e,I){I=I===0?0:I||50;var i=Dt(g).toRgb(),n=Dt(e).toRgb(),C=I/100,r={r:(n.r-i.r)*C+i.r,g:(n.g-i.g)*C+i.g,b:(n.b-i.b)*C+i.b,a:(n.a-i.a)*C+i.a};return Dt(r)};Dt.readability=function(g,e){var I=Dt(g),i=Dt(e);return(Math.max(I.getLuminance(),i.getLuminance())+.05)/(Math.min(I.getLuminance(),i.getLuminance())+.05)};Dt.isReadable=function(g,e,I){var i=Dt.readability(g,e),n,C;switch(C=!1,n=i_t(I),n.level+n.size){case"AAsmall":case"AAAlarge":C=i>=4.5;break;case"AAlarge":C=i>=3;break;case"AAAsmall":C=i>=7;break}return C};Dt.mostReadable=function(g,e,I){var i=null,n=0,C,r,o,A;I=I||{},r=I.includeFallbackColors,o=I.level,A=I.size;for(var s=0;sn&&(n=C,i=Dt(e[s]));return Dt.isReadable(g,i,{level:o,size:A})||!r?i:(I.includeFallbackColors=!1,Dt.mostReadable(g,["#fff","#000"],I))};var eO=Dt.names={aliceblue:"f0f8ff",antiquewhite:"faebd7",aqua:"0ff",aquamarine:"7fffd4",azure:"f0ffff",beige:"f5f5dc",bisque:"ffe4c4",black:"000",blanchedalmond:"ffebcd",blue:"00f",blueviolet:"8a2be2",brown:"a52a2a",burlywood:"deb887",burntsienna:"ea7e5d",cadetblue:"5f9ea0",chartreuse:"7fff00",chocolate:"d2691e",coral:"ff7f50",cornflowerblue:"6495ed",cornsilk:"fff8dc",crimson:"dc143c",cyan:"0ff",darkblue:"00008b",darkcyan:"008b8b",darkgoldenrod:"b8860b",darkgray:"a9a9a9",darkgreen:"006400",darkgrey:"a9a9a9",darkkhaki:"bdb76b",darkmagenta:"8b008b",darkolivegreen:"556b2f",darkorange:"ff8c00",darkorchid:"9932cc",darkred:"8b0000",darksalmon:"e9967a",darkseagreen:"8fbc8f",darkslateblue:"483d8b",darkslategray:"2f4f4f",darkslategrey:"2f4f4f",darkturquoise:"00ced1",darkviolet:"9400d3",deeppink:"ff1493",deepskyblue:"00bfff",dimgray:"696969",dimgrey:"696969",dodgerblue:"1e90ff",firebrick:"b22222",floralwhite:"fffaf0",forestgreen:"228b22",fuchsia:"f0f",gainsboro:"dcdcdc",ghostwhite:"f8f8ff",gold:"ffd700",goldenrod:"daa520",gray:"808080",green:"008000",greenyellow:"adff2f",grey:"808080",honeydew:"f0fff0",hotpink:"ff69b4",indianred:"cd5c5c",indigo:"4b0082",ivory:"fffff0",khaki:"f0e68c",lavender:"e6e6fa",lavenderblush:"fff0f5",lawngreen:"7cfc00",lemonchiffon:"fffacd",lightblue:"add8e6",lightcoral:"f08080",lightcyan:"e0ffff",lightgoldenrodyellow:"fafad2",lightgray:"d3d3d3",lightgreen:"90ee90",lightgrey:"d3d3d3",lightpink:"ffb6c1",lightsalmon:"ffa07a",lightseagreen:"20b2aa",lightskyblue:"87cefa",lightslategray:"789",lightslategrey:"789",lightsteelblue:"b0c4de",lightyellow:"ffffe0",lime:"0f0",limegreen:"32cd32",linen:"faf0e6",magenta:"f0f",maroon:"800000",mediumaquamarine:"66cdaa",mediumblue:"0000cd",mediumorchid:"ba55d3",mediumpurple:"9370db",mediumseagreen:"3cb371",mediumslateblue:"7b68ee",mediumspringgreen:"00fa9a",mediumturquoise:"48d1cc",mediumvioletred:"c71585",midnightblue:"191970",mintcream:"f5fffa",mistyrose:"ffe4e1",moccasin:"ffe4b5",navajowhite:"ffdead",navy:"000080",oldlace:"fdf5e6",olive:"808000",olivedrab:"6b8e23",orange:"ffa500",orangered:"ff4500",orchid:"da70d6",palegoldenrod:"eee8aa",palegreen:"98fb98",paleturquoise:"afeeee",palevioletred:"db7093",papayawhip:"ffefd5",peachpuff:"ffdab9",peru:"cd853f",pink:"ffc0cb",plum:"dda0dd",powderblue:"b0e0e6",purple:"800080",rebeccapurple:"663399",red:"f00",rosybrown:"bc8f8f",royalblue:"4169e1",saddlebrown:"8b4513",salmon:"fa8072",sandybrown:"f4a460",seagreen:"2e8b57",seashell:"fff5ee",sienna:"a0522d",silver:"c0c0c0",skyblue:"87ceeb",slateblue:"6a5acd",slategray:"708090",slategrey:"708090",snow:"fffafa",springgreen:"00ff7f",steelblue:"4682b4",tan:"d2b48c",teal:"008080",thistle:"d8bfd8",tomato:"ff6347",turquoise:"40e0d0",violet:"ee82ee",wheat:"f5deb3",white:"fff",whitesmoke:"f5f5f5",yellow:"ff0",yellowgreen:"9acd32"},qLt=Dt.hexNames=e_t(eO);function e_t(g){var e={};for(var I in g)g.hasOwnProperty(I)&&(e[g[I]]=I);return e}function e9e(g){return g=parseFloat(g),(isNaN(g)||g<0||g>1)&&(g=1),g}function RI(g,e){t_t(g)&&(g="100%");var I=g_t(g);return g=Math.min(e,Math.max(0,parseFloat(g))),I&&(g=parseInt(g*e,10)/100),Math.abs(g-e)<1e-6?1:g%e/parseFloat(e)}function uY(g){return Math.min(1,Math.max(0,g))}function UC(g){return parseInt(g,16)}function t_t(g){return typeof g=="string"&&g.indexOf(".")!=-1&&parseFloat(g)===1}function g_t(g){return typeof g=="string"&&g.indexOf("%")!=-1}function IA(g){return g.length==1?"0"+g:""+g}function bG(g){return g<=1&&(g=g*100+"%"),g}function t9e(g){return Math.round(parseFloat(g)*255).toString(16)}function kae(g){return UC(g)/255}var Do=function(){var g="[-\\+]?\\d+%?",e="[-\\+]?\\d*\\.\\d+%?",I="(?:"+e+")|(?:"+g+")",i="[\\s|\\(]+("+I+")[,|\\s]+("+I+")[,|\\s]+("+I+")\\s*\\)?",n="[\\s|\\(]+("+I+")[,|\\s]+("+I+")[,|\\s]+("+I+")[,|\\s]+("+I+")\\s*\\)?";return{CSS_UNIT:new RegExp(I),rgb:new RegExp("rgb"+i),rgba:new RegExp("rgba"+n),hsl:new RegExp("hsl"+i),hsla:new RegExp("hsla"+n),hsv:new RegExp("hsv"+i),hsva:new RegExp("hsva"+n),hex3:/^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,hex6:/^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/,hex4:/^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,hex8:/^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/}}();function Ua(g){return!!Do.CSS_UNIT.exec(g)}function I_t(g){g=g.replace(kLt,"").replace(YLt,"").toLowerCase();var e=!1;if(eO[g])g=eO[g],e=!0;else if(g=="transparent")return{r:0,g:0,b:0,a:0,format:"name"};var I;return(I=Do.rgb.exec(g))?{r:I[1],g:I[2],b:I[3]}:(I=Do.rgba.exec(g))?{r:I[1],g:I[2],b:I[3],a:I[4]}:(I=Do.hsl.exec(g))?{h:I[1],s:I[2],l:I[3]}:(I=Do.hsla.exec(g))?{h:I[1],s:I[2],l:I[3],a:I[4]}:(I=Do.hsv.exec(g))?{h:I[1],s:I[2],v:I[3]}:(I=Do.hsva.exec(g))?{h:I[1],s:I[2],v:I[3],a:I[4]}:(I=Do.hex8.exec(g))?{r:UC(I[1]),g:UC(I[2]),b:UC(I[3]),a:kae(I[4]),format:e?"name":"hex8"}:(I=Do.hex6.exec(g))?{r:UC(I[1]),g:UC(I[2]),b:UC(I[3]),format:e?"name":"hex"}:(I=Do.hex4.exec(g))?{r:UC(I[1]+""+I[1]),g:UC(I[2]+""+I[2]),b:UC(I[3]+""+I[3]),a:kae(I[4]+""+I[4]),format:e?"name":"hex8"}:(I=Do.hex3.exec(g))?{r:UC(I[1]+""+I[1]),g:UC(I[2]+""+I[2]),b:UC(I[3]+""+I[3]),format:e?"name":"hex"}:!1}function i_t(g){var e,I;return g=g||{level:"AA",size:"small"},e=(g.level||"AA").toUpperCase(),I=(g.size||"small").toLowerCase(),e!=="AA"&&e!=="AAA"&&(e="AA"),I!=="small"&&I!=="large"&&(I="small"),{level:e,size:I}}var Yae=function(e){var I=["r","g","b","a","h","s","l","v"],i=0,n=0;return NLt(I,function(C){if(e[C]&&(i+=1,isNaN(e[C])||(n+=1),C==="s"||C==="l")){var r=/^\d+%$/;r.test(e[C])&&(n+=1)}}),i===n?e:!1},yG=function(e,I){var i=e.hex?Dt(e.hex):Dt(e),n=i.toHsl(),C=i.toHsv(),r=i.toRgb(),o=i.toHex();n.s===0&&(n.h=I||0,C.h=I||0);var A=o==="000000"&&r.a===0;return{hsl:n,hex:A?"transparent":"#"+o,rgb:r,hsv:C,oldHue:e.h||I||n.h,source:e.source}},Vu=function(e){if(e==="transparent")return!0;var I=String(e).charAt(0)==="#"?1:0;return e.length!==4+I&&e.length<7+I&&Dt(e).isValid()},O4=function(e){if(!e)return"#fff";var I=yG(e);if(I.hex==="transparent")return"rgba(0,0,0,0.4)";var i=(I.rgb.r*299+I.rgb.g*587+I.rgb.b*114)/1e3;return i>=128?"#000":"#fff"},GF=function(e,I){var i=e.replace("°","");return Dt(I+" ("+i+")")._ok},yZ=Object.assign||function(g){for(var e=1;e1&&arguments[1]!==void 0?arguments[1]:"span";return function(i){l_t(n,i);function n(){var C,r,o,A;s_t(this,n);for(var s=arguments.length,a=Array(s),l=0;l=0||Object.prototype.hasOwnProperty.call(g,i)&&(I[i]=g[i]);return I}var qR=24,G_t=i9e.default=function(g){var e=g.fill,I=e===void 0?"currentColor":e,i=g.width,n=i===void 0?qR:i,C=g.height,r=C===void 0?qR:C,o=g.style,A=o===void 0?{}:o,s=Z_t(g,["fill","width","height","style"]);return Eae.default.createElement("svg",Fae({viewBox:"0 0 "+qR+" "+qR,style:Fae({fill:I,width:n,height:r},A)},s),Eae.default.createElement("path",{d:"M12,18.17L8.83,15L7.42,16.41L12,21L16.59,16.41L15.17,15M12,5.83L15.17,9L16.58,7.59L12,3L7.41,7.59L8.83,9L12,5.83Z"}))},B_t=function(){function g(e,I){for(var i=0;i1&&(n.a=1),i.props.onChange({h:i.props.hsl.h,s:i.props.hsl.s,l:i.props.hsl.l,a:Math.round(n.a*100)/100,source:"rgb"},C)):(n.h||n.s||n.l)&&(typeof n.s=="string"&&n.s.includes("%")&&(n.s=n.s.replace("%","")),typeof n.l=="string"&&n.l.includes("%")&&(n.l=n.l.replace("%","")),n.s==1?n.s=.01:n.l==1&&(n.l=.01),i.props.onChange({h:n.h||i.props.hsl.h,s:Number(Dae(n.s)?i.props.hsl.s:n.s),l:Number(Dae(n.l)?i.props.hsl.l:n.l),source:"hsl"},C))},i.showHighlight=function(n){n.currentTarget.style.background="#eee"},i.hideHighlight=function(n){n.currentTarget.style.background="transparent"},I.hsl.a!==1&&I.view==="hex"?i.state={view:"rgb"}:i.state={view:I.view},i}return B_t(e,[{key:"render",value:function(){var i=this,n=gg({default:{wrap:{paddingTop:"16px",display:"flex"},fields:{flex:"1",display:"flex",marginLeft:"-6px"},field:{paddingLeft:"6px",width:"100%"},alpha:{paddingLeft:"6px",width:"100%"},toggle:{width:"32px",textAlign:"right",position:"relative"},icon:{marginRight:"-4px",marginTop:"12px",cursor:"pointer",position:"relative"},iconHighlight:{position:"absolute",width:"24px",height:"28px",background:"#eee",borderRadius:"4px",top:"10px",left:"12px",display:"none"},input:{fontSize:"11px",color:"#333",width:"100%",borderRadius:"2px",border:"none",boxShadow:"inset 0 0 0 1px #dadada",height:"21px",textAlign:"center"},label:{textTransform:"uppercase",fontSize:"11px",lineHeight:"11px",color:"#969696",textAlign:"center",display:"block",marginTop:"12px"},svg:{fill:"#333",width:"24px",height:"24px",border:"1px transparent solid",borderRadius:"5px"}},disableAlpha:{alpha:{display:"none"}}},this.props,this.state),C=void 0;return this.state.view==="hex"?C=N.createElement("div",{style:n.fields,className:"flexbox-fix"},N.createElement("div",{style:n.field},N.createElement(Rg,{style:{input:n.input,label:n.label},label:"hex",value:this.props.hex,onChange:this.handleChange}))):this.state.view==="rgb"?C=N.createElement("div",{style:n.fields,className:"flexbox-fix"},N.createElement("div",{style:n.field},N.createElement(Rg,{style:{input:n.input,label:n.label},label:"r",value:this.props.rgb.r,onChange:this.handleChange})),N.createElement("div",{style:n.field},N.createElement(Rg,{style:{input:n.input,label:n.label},label:"g",value:this.props.rgb.g,onChange:this.handleChange})),N.createElement("div",{style:n.field},N.createElement(Rg,{style:{input:n.input,label:n.label},label:"b",value:this.props.rgb.b,onChange:this.handleChange})),N.createElement("div",{style:n.alpha},N.createElement(Rg,{style:{input:n.input,label:n.label},label:"a",value:this.props.rgb.a,arrowOffset:.01,onChange:this.handleChange}))):this.state.view==="hsl"&&(C=N.createElement("div",{style:n.fields,className:"flexbox-fix"},N.createElement("div",{style:n.field},N.createElement(Rg,{style:{input:n.input,label:n.label},label:"h",value:Math.round(this.props.hsl.h),onChange:this.handleChange})),N.createElement("div",{style:n.field},N.createElement(Rg,{style:{input:n.input,label:n.label},label:"s",value:Math.round(this.props.hsl.s*100)+"%",onChange:this.handleChange})),N.createElement("div",{style:n.field},N.createElement(Rg,{style:{input:n.input,label:n.label},label:"l",value:Math.round(this.props.hsl.l*100)+"%",onChange:this.handleChange})),N.createElement("div",{style:n.alpha},N.createElement(Rg,{style:{input:n.input,label:n.label},label:"a",value:this.props.hsl.a,arrowOffset:.01,onChange:this.handleChange})))),N.createElement("div",{style:n.wrap,className:"flexbox-fix"},C,N.createElement("div",{style:n.toggle},N.createElement("div",{style:n.icon,onClick:this.toggleViews,ref:function(o){return i.icon=o}},N.createElement(G_t,{style:n.svg,onMouseOver:this.showHighlight,onMouseEnter:this.showHighlight,onMouseOut:this.hideHighlight}))))}}],[{key:"getDerivedStateFromProps",value:function(i,n){return i.hsl.a!==1&&n.view==="hex"?{view:"rgb"}:null}}]),e}(N.Component);n9e.defaultProps={view:"hex"};var Mae=function(){var e=gg({default:{picker:{width:"12px",height:"12px",borderRadius:"6px",transform:"translate(-6px, -1px)",backgroundColor:"rgb(248, 248, 248)",boxShadow:"0 1px 4px 0 rgba(0, 0, 0, 0.37)"}}});return N.createElement("div",{style:e.picker})},V_t=function(){var e=gg({default:{picker:{width:"12px",height:"12px",borderRadius:"6px",boxShadow:"inset 0 0 0 1px #fff",transform:"translate(-6px, -6px)"}}});return N.createElement("div",{style:e.picker})},U4=function(e){var I=e.width,i=e.onChange,n=e.disableAlpha,C=e.rgb,r=e.hsl,o=e.hsv,A=e.hex,s=e.renderers,a=e.styles,l=a===void 0?{}:a,c=e.className,u=c===void 0?"":c,d=e.defaultView,h=gg(MC({default:{picker:{width:I,background:"#fff",borderRadius:"2px",boxShadow:"0 0 2px rgba(0,0,0,.3), 0 4px 8px rgba(0,0,0,.3)",boxSizing:"initial",fontFamily:"Menlo"},saturation:{width:"100%",paddingBottom:"55%",position:"relative",borderRadius:"2px 2px 0 0",overflow:"hidden"},Saturation:{radius:"2px 2px 0 0"},body:{padding:"16px 16px 12px"},controls:{display:"flex"},color:{width:"32px"},swatch:{marginTop:"6px",width:"16px",height:"16px",borderRadius:"8px",position:"relative",overflow:"hidden"},active:{absolute:"0px 0px 0px 0px",borderRadius:"8px",boxShadow:"inset 0 0 0 1px rgba(0,0,0,.1)",background:"rgba("+C.r+", "+C.g+", "+C.b+", "+C.a+")",zIndex:"2"},toggles:{flex:"1"},hue:{height:"10px",position:"relative",marginBottom:"8px"},Hue:{radius:"2px"},alpha:{height:"10px",position:"relative"},Alpha:{radius:"2px"}},disableAlpha:{color:{width:"22px"},alpha:{display:"none"},hue:{marginBottom:"0px"},swatch:{width:"10px",height:"10px",marginTop:"0px"}}},l),{disableAlpha:n});return N.createElement("div",{style:h.picker,className:"chrome-picker "+u},N.createElement("div",{style:h.saturation},N.createElement(cY,{style:h.Saturation,hsl:r,hsv:o,pointer:V_t,onChange:i})),N.createElement("div",{style:h.body},N.createElement("div",{style:h.controls,className:"flexbox-fix"},N.createElement("div",{style:h.color},N.createElement("div",{style:h.swatch},N.createElement("div",{style:h.active}),N.createElement(fy,{renderers:s}))),N.createElement("div",{style:h.toggles},N.createElement("div",{style:h.hue},N.createElement(py,{style:h.Hue,hsl:r,pointer:Mae,onChange:i})),N.createElement("div",{style:h.alpha},N.createElement(J4,{style:h.Alpha,rgb:C,hsl:r,pointer:Mae,renderers:s,onChange:i})))),N.createElement(n9e,{rgb:C,hsl:r,hex:A,view:d,onChange:i,disableAlpha:n})))};U4.propTypes={width:L.oneOfType([L.string,L.number]),disableAlpha:L.bool,styles:L.object,defaultView:L.oneOf(["hex","rgb","hsl"])};U4.defaultProps={width:225,disableAlpha:!1,styles:{}};zC(U4);var R_t=function(e){var I=e.color,i=e.onClick,n=i===void 0?function(){}:i,C=e.onSwatchHover,r=e.active,o=gg({default:{color:{background:I,width:"15px",height:"15px",float:"left",marginRight:"5px",marginBottom:"5px",position:"relative",cursor:"pointer"},dot:{absolute:"5px 5px 5px 5px",background:O4(I),borderRadius:"50%",opacity:"0"}},active:{dot:{opacity:"1"}},"color-#FFFFFF":{color:{boxShadow:"inset 0 0 0 1px #ddd"},dot:{background:"#000"}},transparent:{dot:{background:"#000"}}},{active:r,"color-#FFFFFF":I==="#FFFFFF",transparent:I==="transparent"});return N.createElement(Rm,{style:o.color,color:I,onClick:n,onHover:C,focusStyle:{boxShadow:"0 0 4px "+I}},N.createElement("div",{style:o.dot}))},W_t=function(e){var I=e.hex,i=e.rgb,n=e.onChange,C=gg({default:{fields:{display:"flex",paddingBottom:"6px",paddingRight:"5px",position:"relative"},active:{position:"absolute",top:"6px",left:"5px",height:"9px",width:"9px",background:I},HEXwrap:{flex:"6",position:"relative"},HEXinput:{width:"80%",padding:"0px",paddingLeft:"20%",border:"none",outline:"none",background:"none",fontSize:"12px",color:"#333",height:"16px"},HEXlabel:{display:"none"},RGBwrap:{flex:"3",position:"relative"},RGBinput:{width:"70%",padding:"0px",paddingLeft:"30%",border:"none",outline:"none",background:"none",fontSize:"12px",color:"#333",height:"16px"},RGBlabel:{position:"absolute",top:"3px",left:"0px",lineHeight:"16px",textTransform:"uppercase",fontSize:"12px",color:"#999"}}}),r=function(A,s){A.r||A.g||A.b?n({r:A.r||i.r,g:A.g||i.g,b:A.b||i.b,source:"rgb"},s):n({hex:A.hex,source:"hex"},s)};return N.createElement("div",{style:C.fields,className:"flexbox-fix"},N.createElement("div",{style:C.active}),N.createElement(Rg,{style:{wrap:C.HEXwrap,input:C.HEXinput,label:C.HEXlabel},label:"hex",value:I,onChange:r}),N.createElement(Rg,{style:{wrap:C.RGBwrap,input:C.RGBinput,label:C.RGBlabel},label:"r",value:i.r,onChange:r}),N.createElement(Rg,{style:{wrap:C.RGBwrap,input:C.RGBinput,label:C.RGBlabel},label:"g",value:i.g,onChange:r}),N.createElement(Rg,{style:{wrap:C.RGBwrap,input:C.RGBinput,label:C.RGBlabel},label:"b",value:i.b,onChange:r}))},Q4=function(e){var I=e.onChange,i=e.onSwatchHover,n=e.colors,C=e.hex,r=e.rgb,o=e.styles,A=o===void 0?{}:o,s=e.className,a=s===void 0?"":s,l=gg(MC({default:{Compact:{background:"#f6f6f6",radius:"4px"},compact:{paddingTop:"5px",paddingLeft:"5px",boxSizing:"initial",width:"240px"},clear:{clear:"both"}}},A)),c=function(d,h){d.hex?Vu(d.hex)&&I({hex:d.hex,source:"hex"},h):I(d,h)};return N.createElement(Ow,{style:l.Compact,styles:A},N.createElement("div",{style:l.compact,className:"compact-picker "+a},N.createElement("div",null,wu(n,function(u){return N.createElement(R_t,{key:u,color:u,active:u.toLowerCase()===C,onClick:c,onSwatchHover:i})}),N.createElement("div",{style:l.clear})),N.createElement(W_t,{hex:C,rgb:r,onChange:c})))};Q4.propTypes={colors:L.arrayOf(L.string),styles:L.object};Q4.defaultProps={colors:["#4D4D4D","#999999","#FFFFFF","#F44E3B","#FE9200","#FCDC00","#DBDF00","#A4DD00","#68CCCA","#73D8FF","#AEA1FF","#FDA1FF","#333333","#808080","#cccccc","#D33115","#E27300","#FCC400","#B0BC00","#68BC00","#16A5A5","#009CE0","#7B64FF","#FA28FF","#000000","#666666","#B3B3B3","#9F0500","#C45100","#FB9E00","#808900","#194D33","#0C797D","#0062B1","#653294","#AB149E"],styles:{}};zC(Q4);var X_t=function(e){var I=e.hover,i=e.color,n=e.onClick,C=e.onSwatchHover,r={position:"relative",zIndex:"2",outline:"2px solid #fff",boxShadow:"0 0 5px 2px rgba(0,0,0,0.25)"},o=gg({default:{swatch:{width:"25px",height:"25px",fontSize:"0"}},hover:{swatch:r}},{hover:I});return N.createElement("div",{style:o.swatch},N.createElement(Rm,{color:i,onClick:n,onHover:C,focusStyle:r}))};const H_t=P4(X_t);var j4=function(e){var I=e.width,i=e.colors,n=e.onChange,C=e.onSwatchHover,r=e.triangle,o=e.styles,A=o===void 0?{}:o,s=e.className,a=s===void 0?"":s,l=gg(MC({default:{card:{width:I,background:"#fff",border:"1px solid rgba(0,0,0,0.2)",boxShadow:"0 3px 12px rgba(0,0,0,0.15)",borderRadius:"4px",position:"relative",padding:"5px",display:"flex",flexWrap:"wrap"},triangle:{position:"absolute",border:"7px solid transparent",borderBottomColor:"#fff"},triangleShadow:{position:"absolute",border:"8px solid transparent",borderBottomColor:"rgba(0,0,0,0.15)"}},"hide-triangle":{triangle:{display:"none"},triangleShadow:{display:"none"}},"top-left-triangle":{triangle:{top:"-14px",left:"10px"},triangleShadow:{top:"-16px",left:"9px"}},"top-right-triangle":{triangle:{top:"-14px",right:"10px"},triangleShadow:{top:"-16px",right:"9px"}},"bottom-left-triangle":{triangle:{top:"35px",left:"10px",transform:"rotate(180deg)"},triangleShadow:{top:"37px",left:"9px",transform:"rotate(180deg)"}},"bottom-right-triangle":{triangle:{top:"35px",right:"10px",transform:"rotate(180deg)"},triangleShadow:{top:"37px",right:"9px",transform:"rotate(180deg)"}}},A),{"hide-triangle":r==="hide","top-left-triangle":r==="top-left","top-right-triangle":r==="top-right","bottom-left-triangle":r==="bottom-left","bottom-right-triangle":r==="bottom-right"}),c=function(d,h){return n({hex:d,source:"hex"},h)};return N.createElement("div",{style:l.card,className:"github-picker "+a},N.createElement("div",{style:l.triangleShadow}),N.createElement("div",{style:l.triangle}),wu(i,function(u){return N.createElement(H_t,{color:u,key:u,onClick:c,onSwatchHover:C})}))};j4.propTypes={width:L.oneOfType([L.string,L.number]),colors:L.arrayOf(L.string),triangle:L.oneOf(["hide","top-left","top-right","bottom-left","bottom-right"]),styles:L.object};j4.defaultProps={width:200,colors:["#B80000","#DB3E00","#FCCB00","#008B02","#006B76","#1273DE","#004DCF","#5300EB","#EB9694","#FAD0C3","#FEF3BD","#C1E1C5","#BEDADC","#C4DEF6","#BED3F3","#D4C4FB"],triangle:"top-left",styles:{}};zC(j4);var T_t=function(e){var I=e.direction,i=gg({default:{picker:{width:"18px",height:"18px",borderRadius:"50%",transform:"translate(-9px, -1px)",backgroundColor:"rgb(248, 248, 248)",boxShadow:"0 1px 4px 0 rgba(0, 0, 0, 0.37)"}},vertical:{picker:{transform:"translate(-3px, -9px)"}}},{vertical:I==="vertical"});return N.createElement("div",{style:i.picker})},N_t=Object.assign||function(g){for(var e=1;e.5});return N.createElement("div",{style:i.picker})},x_t=function(){var e=gg({default:{triangle:{width:0,height:0,borderStyle:"solid",borderWidth:"4px 0 4px 6px",borderColor:"transparent transparent transparent #fff",position:"absolute",top:"1px",left:"1px"},triangleBorder:{width:0,height:0,borderStyle:"solid",borderWidth:"5px 0 5px 8px",borderColor:"transparent transparent transparent #555"},left:{Extend:"triangleBorder",transform:"translate(-13px, -4px)"},leftInside:{Extend:"triangle",transform:"translate(-8px, -5px)"},right:{Extend:"triangleBorder",transform:"translate(20px, -14px) rotate(180deg)"},rightInside:{Extend:"triangle",transform:"translate(-8px, -5px)"}}});return N.createElement("div",{style:e.pointer},N.createElement("div",{style:e.left},N.createElement("div",{style:e.leftInside})),N.createElement("div",{style:e.right},N.createElement("div",{style:e.rightInside})))},zae=function(e){var I=e.onClick,i=e.label,n=e.children,C=e.active,r=gg({default:{button:{backgroundImage:"linear-gradient(-180deg, #FFFFFF 0%, #E6E6E6 100%)",border:"1px solid #878787",borderRadius:"2px",height:"20px",boxShadow:"0 1px 0 0 #EAEAEA",fontSize:"14px",color:"#000",lineHeight:"20px",textAlign:"center",marginBottom:"10px",cursor:"pointer"}},active:{button:{boxShadow:"0 0 0 1px #878787"}}},{active:C});return N.createElement("div",{style:r.button,onClick:I},i||n)},D_t=function(e){var I=e.rgb,i=e.currentColor,n=gg({default:{swatches:{border:"1px solid #B3B3B3",borderBottom:"1px solid #F0F0F0",marginBottom:"2px",marginTop:"1px"},new:{height:"34px",background:"rgb("+I.r+","+I.g+", "+I.b+")",boxShadow:"inset 1px 0 0 #000, inset -1px 0 0 #000, inset 0 1px 0 #000"},current:{height:"34px",background:i,boxShadow:"inset 1px 0 0 #000, inset -1px 0 0 #000, inset 0 -1px 0 #000"},label:{fontSize:"14px",color:"#000",textAlign:"center"}}});return N.createElement("div",null,N.createElement("div",{style:n.label},"new"),N.createElement("div",{style:n.swatches},N.createElement("div",{style:n.new}),N.createElement("div",{style:n.current})),N.createElement("div",{style:n.label},"current"))},F_t=function(){function g(e,I){for(var i=0;i100&&(a.a=100),a.a/=100,I({h:n.h,s:n.s,l:n.l,a:a.a,source:"rgb"},l))};return N.createElement("div",{style:o.fields,className:"flexbox-fix"},N.createElement("div",{style:o.double},N.createElement(Rg,{style:{input:o.input,label:o.label},label:"hex",value:C.replace("#",""),onChange:A})),N.createElement("div",{style:o.single},N.createElement(Rg,{style:{input:o.input,label:o.label},label:"r",value:i.r,onChange:A,dragLabel:"true",dragMax:"255"})),N.createElement("div",{style:o.single},N.createElement(Rg,{style:{input:o.input,label:o.label},label:"g",value:i.g,onChange:A,dragLabel:"true",dragMax:"255"})),N.createElement("div",{style:o.single},N.createElement(Rg,{style:{input:o.input,label:o.label},label:"b",value:i.b,onChange:A,dragLabel:"true",dragMax:"255"})),N.createElement("div",{style:o.alpha},N.createElement(Rg,{style:{input:o.input,label:o.label},label:"a",value:Math.round(i.a*100),onChange:A,dragLabel:"true",dragMax:"100"})))},J_t=Object.assign||function(g){for(var e=1;e=0||Object.prototype.hasOwnProperty.call(g,i)&&(I[i]=g[i]);return I}var e1=24,q_t=r9e.default=function(g){var e=g.fill,I=e===void 0?"currentColor":e,i=g.width,n=i===void 0?e1:i,C=g.height,r=C===void 0?e1:C,o=g.style,A=o===void 0?{}:o,s=$_t(g,["fill","width","height","style"]);return Jae.default.createElement("svg",Pae({viewBox:"0 0 "+e1+" "+e1,style:Pae({fill:I,width:n,height:r},A)},s),Jae.default.createElement("path",{d:"M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"}))},eUt=function(e){var I=e.color,i=e.onClick,n=i===void 0?function(){}:i,C=e.onSwatchHover,r=e.first,o=e.last,A=e.active,s=gg({default:{color:{width:"40px",height:"24px",cursor:"pointer",background:I,marginBottom:"1px"},check:{color:O4(I),marginLeft:"8px",display:"none"}},first:{color:{overflow:"hidden",borderRadius:"2px 2px 0 0"}},last:{color:{overflow:"hidden",borderRadius:"0 0 2px 2px"}},active:{check:{display:"block"}},"color-#FFFFFF":{color:{boxShadow:"inset 0 0 0 1px #ddd"},check:{color:"#333"}},transparent:{check:{color:"#333"}}},{first:r,last:o,active:A,"color-#FFFFFF":I==="#FFFFFF",transparent:I==="transparent"});return N.createElement(Rm,{color:I,style:s.color,onClick:n,onHover:C,focusStyle:{boxShadow:"0 0 4px "+I}},N.createElement("div",{style:s.check},N.createElement(q_t,null)))},tUt=function(e){var I=e.onClick,i=e.onSwatchHover,n=e.group,C=e.active,r=gg({default:{group:{paddingBottom:"10px",width:"40px",float:"left",marginRight:"10px"}}});return N.createElement("div",{style:r.group},wu(n,function(o,A){return N.createElement(eUt,{key:o,color:o,active:o.toLowerCase()===C,first:A===0,last:A===n.length-1,onClick:I,onSwatchHover:i})}))},g$=function(e){var I=e.width,i=e.height,n=e.onChange,C=e.onSwatchHover,r=e.colors,o=e.hex,A=e.styles,s=A===void 0?{}:A,a=e.className,l=a===void 0?"":a,c=gg(MC({default:{picker:{width:I,height:i},overflow:{height:i,overflowY:"scroll"},body:{padding:"16px 0 6px 16px"},clear:{clear:"both"}}},s)),u=function(h,m){return n({hex:h,source:"hex"},m)};return N.createElement("div",{style:c.picker,className:"swatches-picker "+l},N.createElement(Ow,null,N.createElement("div",{style:c.overflow},N.createElement("div",{style:c.body},wu(r,function(d){return N.createElement(tUt,{key:d.toString(),group:d,active:o,onClick:u,onSwatchHover:C})}),N.createElement("div",{style:c.clear})))))};g$.propTypes={width:L.oneOfType([L.string,L.number]),height:L.oneOfType([L.string,L.number]),colors:L.arrayOf(L.arrayOf(L.string)),styles:L.object};g$.defaultProps={width:320,height:240,colors:[[Yf[900],Yf[700],Yf[500],Yf[300],Yf[100]],[Kf[900],Kf[700],Kf[500],Kf[300],Kf[100]],[xf[900],xf[700],xf[500],xf[300],xf[100]],[Df[900],Df[700],Df[500],Df[300],Df[100]],[Ff[900],Ff[700],Ff[500],Ff[300],Ff[100]],[Ef[900],Ef[700],Ef[500],Ef[300],Ef[100]],[Mf[900],Mf[700],Mf[500],Mf[300],Mf[100]],[zf[900],zf[700],zf[500],zf[300],zf[100]],[Pf[900],Pf[700],Pf[500],Pf[300],Pf[100]],["#194D33",ZG[700],ZG[500],ZG[300],ZG[100]],[Jf[900],Jf[700],Jf[500],Jf[300],Jf[100]],[Of[900],Of[700],Of[500],Of[300],Of[100]],[Lf[900],Lf[700],Lf[500],Lf[300],Lf[100]],[_f[900],_f[700],_f[500],_f[300],_f[100]],[Uf[900],Uf[700],Uf[500],Uf[300],Uf[100]],[Qf[900],Qf[700],Qf[500],Qf[300],Qf[100]],[jf[900],jf[700],jf[500],jf[300],jf[100]],[$f[900],$f[700],$f[500],$f[300],$f[100]],["#000000","#525252","#969696","#D9D9D9","#FFFFFF"]],styles:{}};zC(g$);var I$=function(e){var I=e.onChange,i=e.onSwatchHover,n=e.hex,C=e.colors,r=e.width,o=e.triangle,A=e.styles,s=A===void 0?{}:A,a=e.className,l=a===void 0?"":a,c=gg(MC({default:{card:{width:r,background:"#fff",border:"0 solid rgba(0,0,0,0.25)",boxShadow:"0 1px 4px rgba(0,0,0,0.25)",borderRadius:"4px",position:"relative"},body:{padding:"15px 9px 9px 15px"},label:{fontSize:"18px",color:"#fff"},triangle:{width:"0px",height:"0px",borderStyle:"solid",borderWidth:"0 9px 10px 9px",borderColor:"transparent transparent #fff transparent",position:"absolute"},triangleShadow:{width:"0px",height:"0px",borderStyle:"solid",borderWidth:"0 9px 10px 9px",borderColor:"transparent transparent rgba(0,0,0,.1) transparent",position:"absolute"},hash:{background:"#F0F0F0",height:"30px",width:"30px",borderRadius:"4px 0 0 4px",float:"left",color:"#98A1A4",display:"flex",alignItems:"center",justifyContent:"center"},input:{width:"100px",fontSize:"14px",color:"#666",border:"0px",outline:"none",height:"28px",boxShadow:"inset 0 0 0 1px #F0F0F0",boxSizing:"content-box",borderRadius:"0 4px 4px 0",float:"left",paddingLeft:"8px"},swatch:{width:"30px",height:"30px",float:"left",borderRadius:"4px",margin:"0 6px 6px 0"},clear:{clear:"both"}},"hide-triangle":{triangle:{display:"none"},triangleShadow:{display:"none"}},"top-left-triangle":{triangle:{top:"-10px",left:"12px"},triangleShadow:{top:"-11px",left:"12px"}},"top-right-triangle":{triangle:{top:"-10px",right:"12px"},triangleShadow:{top:"-11px",right:"12px"}}},s),{"hide-triangle":o==="hide","top-left-triangle":o==="top-left","top-right-triangle":o==="top-right"}),u=function(h,m){Vu(h)&&I({hex:h,source:"hex"},m)};return N.createElement("div",{style:c.card,className:"twitter-picker "+l},N.createElement("div",{style:c.triangleShadow}),N.createElement("div",{style:c.triangle}),N.createElement("div",{style:c.body},wu(C,function(d,h){return N.createElement(Rm,{key:h,color:d,hex:d,style:c.swatch,onClick:u,onHover:i,focusStyle:{boxShadow:"0 0 4px "+d}})}),N.createElement("div",{style:c.hash},"#"),N.createElement(Rg,{label:null,style:{input:c.input},value:n.replace("#",""),onChange:u}),N.createElement("div",{style:c.clear})))};I$.propTypes={width:L.oneOfType([L.string,L.number]),triangle:L.oneOf(["hide","top-left","top-right"]),colors:L.arrayOf(L.string),styles:L.object};I$.defaultProps={width:276,colors:["#FF6900","#FCB900","#7BDCB5","#00D084","#8ED1FC","#0693E3","#ABB8C3","#EB144C","#F78DA7","#9900EF"],triangle:"top-left",styles:{}};zC(I$);var i$=function(e){var I=gg({default:{picker:{width:"20px",height:"20px",borderRadius:"22px",border:"2px #fff solid",transform:"translate(-12px, -13px)",background:"hsl("+Math.round(e.hsl.h)+", "+Math.round(e.hsl.s*100)+"%, "+Math.round(e.hsl.l*100)+"%)"}}});return N.createElement("div",{style:I.picker})};i$.propTypes={hsl:L.shape({h:L.number,s:L.number,l:L.number,a:L.number})};i$.defaultProps={hsl:{a:1,h:249.94,l:.2,s:.5}};var n$=function(e){var I=gg({default:{picker:{width:"20px",height:"20px",borderRadius:"22px",transform:"translate(-10px, -7px)",background:"hsl("+Math.round(e.hsl.h)+", 100%, 50%)",border:"2px white solid"}}});return N.createElement("div",{style:I.picker})};n$.propTypes={hsl:L.shape({h:L.number,s:L.number,l:L.number,a:L.number})};n$.defaultProps={hsl:{a:1,h:249.94,l:.2,s:.5}};var gUt=function(e){var I=e.onChange,i=e.rgb,n=e.hsl,C=e.hex,r=e.hsv,o=function(u,d){if(u.hex)Vu(u.hex)&&I({hex:u.hex,source:"hex"},d);else if(u.rgb){var h=u.rgb.split(",");GF(u.rgb,"rgb")&&I({r:h[0],g:h[1],b:h[2],a:1,source:"rgb"},d)}else if(u.hsv){var m=u.hsv.split(",");GF(u.hsv,"hsv")&&(m[2]=m[2].replace("%",""),m[1]=m[1].replace("%",""),m[0]=m[0].replace("°",""),m[1]==1?m[1]=.01:m[2]==1&&(m[2]=.01),I({h:Number(m[0]),s:Number(m[1]),v:Number(m[2]),source:"hsv"},d))}else if(u.hsl){var f=u.hsl.split(",");GF(u.hsl,"hsl")&&(f[2]=f[2].replace("%",""),f[1]=f[1].replace("%",""),f[0]=f[0].replace("°",""),l[1]==1?l[1]=.01:l[2]==1&&(l[2]=.01),I({h:Number(f[0]),s:Number(f[1]),v:Number(f[2]),source:"hsl"},d))}},A=gg({default:{wrap:{display:"flex",height:"100px",marginTop:"4px"},fields:{width:"100%"},column:{paddingTop:"10px",display:"flex",justifyContent:"space-between"},double:{padding:"0px 4.4px",boxSizing:"border-box"},input:{width:"100%",height:"38px",boxSizing:"border-box",padding:"4px 10% 3px",textAlign:"center",border:"1px solid #dadce0",fontSize:"11px",textTransform:"lowercase",borderRadius:"5px",outline:"none",fontFamily:"Roboto,Arial,sans-serif"},input2:{height:"38px",width:"100%",border:"1px solid #dadce0",boxSizing:"border-box",fontSize:"11px",textTransform:"lowercase",borderRadius:"5px",outline:"none",paddingLeft:"10px",fontFamily:"Roboto,Arial,sans-serif"},label:{textAlign:"center",fontSize:"12px",background:"#fff",position:"absolute",textTransform:"uppercase",color:"#3c4043",width:"35px",top:"-6px",left:"0",right:"0",marginLeft:"auto",marginRight:"auto",fontFamily:"Roboto,Arial,sans-serif"},label2:{left:"10px",textAlign:"center",fontSize:"12px",background:"#fff",position:"absolute",textTransform:"uppercase",color:"#3c4043",width:"32px",top:"-6px",fontFamily:"Roboto,Arial,sans-serif"},single:{flexGrow:"1",margin:"0px 4.4px"}}}),s=i.r+", "+i.g+", "+i.b,a=Math.round(n.h)+"°, "+Math.round(n.s*100)+"%, "+Math.round(n.l*100)+"%",l=Math.round(r.h)+"°, "+Math.round(r.s*100)+"%, "+Math.round(r.v*100)+"%";return N.createElement("div",{style:A.wrap,className:"flexbox-fix"},N.createElement("div",{style:A.fields},N.createElement("div",{style:A.double},N.createElement(Rg,{style:{input:A.input,label:A.label},label:"hex",value:C,onChange:o})),N.createElement("div",{style:A.column},N.createElement("div",{style:A.single},N.createElement(Rg,{style:{input:A.input2,label:A.label2},label:"rgb",value:s,onChange:o})),N.createElement("div",{style:A.single},N.createElement(Rg,{style:{input:A.input2,label:A.label2},label:"hsv",value:l,onChange:o})),N.createElement("div",{style:A.single},N.createElement(Rg,{style:{input:A.input2,label:A.label2},label:"hsl",value:a,onChange:o})))))},C$=function(e){var I=e.width,i=e.onChange,n=e.rgb,C=e.hsl,r=e.hsv,o=e.hex,A=e.header,s=e.styles,a=s===void 0?{}:s,l=e.className,c=l===void 0?"":l,u=gg(MC({default:{picker:{width:I,background:"#fff",border:"1px solid #dfe1e5",boxSizing:"initial",display:"flex",flexWrap:"wrap",borderRadius:"8px 8px 0px 0px"},head:{height:"57px",width:"100%",paddingTop:"16px",paddingBottom:"16px",paddingLeft:"16px",fontSize:"20px",boxSizing:"border-box",fontFamily:"Roboto-Regular,HelveticaNeue,Arial,sans-serif"},saturation:{width:"70%",padding:"0px",position:"relative",overflow:"hidden"},swatch:{width:"30%",height:"228px",padding:"0px",background:"rgba("+n.r+", "+n.g+", "+n.b+", 1)",position:"relative",overflow:"hidden"},body:{margin:"auto",width:"95%"},controls:{display:"flex",boxSizing:"border-box",height:"52px",paddingTop:"22px"},color:{width:"32px"},hue:{height:"8px",position:"relative",margin:"0px 16px 0px 16px",width:"100%"},Hue:{radius:"2px"}}},a));return N.createElement("div",{style:u.picker,className:"google-picker "+c},N.createElement("div",{style:u.head},A),N.createElement("div",{style:u.swatch}),N.createElement("div",{style:u.saturation},N.createElement(cY,{hsl:C,hsv:r,pointer:i$,onChange:i})),N.createElement("div",{style:u.body},N.createElement("div",{style:u.controls,className:"flexbox-fix"},N.createElement("div",{style:u.hue},N.createElement(py,{style:u.Hue,hsl:C,radius:"4px",pointer:n$,onChange:i}))),N.createElement(gUt,{rgb:n,hsl:C,hex:o,hsv:r,onChange:i})))};C$.propTypes={width:L.oneOfType([L.string,L.number]),styles:L.object,header:L.string};C$.defaultProps={width:652,styles:{},header:"Color picker"};zC(C$);function IUt(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function Oae(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function d2(g){return d2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},d2(g)}let o9e=function(g){rUt(I,g);var e=oUt(I);function I(i){var n;IUt(this,I),n=e.call(this,i);const C=Yb(i.color);return n.state={displayColorPicker:!1,color:{r:C.r,g:C.g,b:C.b,a:C.opacity}},n}return iUt(I,[{key:"handleClick",value:function(){this.setState(n=>({displayColorPicker:!n.displayColorPicker}))}},{key:"handleClose",value:function(){this.setState({displayColorPicker:!1})}},{key:"handleChange",value:function(n){const C=n.rgb,r=`rgba(${C.r},${C.g},${C.b},${C.a})`;this.props.onChange(r),this.setState({color:n.rgb})}},{key:"render",value:function(){const n=gg({default:{color:{width:"32px",height:"14px",borderRadius:"2px",background:`rgba(${this.state.color.r}, ${this.state.color.g}, ${this.state.color.b}, ${this.state.color.a})`},swatch:{padding:"5px",background:"#fff",cursor:"pointer",borderRadius:"1px"},popover:{position:"absolute",zIndex:"2"},cover:{position:"fixed",top:"0px",right:"0px",bottom:"0px",left:"0px"}}});return N.createElement("div",null,N.createElement("div",{onClick:this.handleClick.bind(this),style:n.swatch},N.createElement("div",{style:n.color})),this.state.displayColorPicker?N.createElement("div",{style:n.popover},N.createElement("div",{onClick:this.handleClose.bind(this),style:n.cover}),N.createElement(L_t,{color:this.state.color,onChange:this.handleChange.bind(this)})):null)}}]),I}(N.Component);o9e.propTypes={color:L.string,onChange:L.func};function lUt(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function Lae(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function h2(g){return h2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},h2(g)}let IO=function(g){hUt(I,g);var e=mUt(I);function I(i){var n;return lUt(this,I),n=e.call(this,i),n.state={colors:i.track.options.colorRange.slice()},n}return cUt(I,[{key:"handleColorsChanged",value:function(n){this.setState({colors:n})}},{key:"handleSubmit",value:function(){const n=this.props.track.options;n.colorRange=this.state.colors,this.props.onSubmit(this.props.track.options)}},{key:"handleAddColor",value:function(){this.setState(n=>({colors:n.colors.concat(n.colors[n.colors.length-1])}))}},{key:"handleRemoveColor",value:function(n){this.setState(C=>({colors:C.colors.slice(0,n).concat(C.colors.slice(n+1))}))}},{key:"render",value:function(){const n=JSON.parse(JSON.stringify(this.props.track)),C=Object.assign(n,{options:{colorRange:this.state.colors}}),r={editable:!1,zoomFixed:!0,views:[{uid:`hmo-${this.props.track.uid}`,initialXDomain:this.props.xScale?this.props.xScale.domain():[0,1],initialYDomain:this.props.yScale?this.props.yScale.domain():[0,1],tracks:{center:[C]},layout:{x:0,y:0,h:12,w:12,i:`hmo-${this.props.track.id}`}}]},o=this.state.colors.map((s,a)=>{const l=this.state.colors.length>2&&a===this.state.colors.length-1?N.createElement("div",{onClick:()=>this.handleRemoveColor(a),style:{background:"white",position:"absolute",top:0,right:0,opacity:1,width:14,height:14,borderRadius:2,cursor:"pointer"}},N.createElement("svg",{height:"10px",style:{position:"absolute",top:2,right:2,opacity:.5,width:10,height:10}},N.createElement("use",{xlinkHref:"#cross"}))):null;return N.createElement("div",{key:`l${a}`,style:{borderRadius:"1px",boxShadow:"0 0 0 1px #E5E5E5",position:"relative",outline:"none"}},l,N.createElement(o9e,{key:a,color:this.state.colors[a],onChange:c=>{this.setState(u=>{const d=u.colors.slice();return d[a]=c,{colors:d}},()=>{this.handleColorsChanged(this.state.colors)})}}))}).reverse(),A=this.state.colors.length<10?N.createElement("div",{onClick:this.handleAddColor.bind(this),style:{position:"relative",outline:"none",height:"25px",padding:"5px",background:"#fff",borderRadius:"1px",boxShadow:"0 0 0 1px #E5E5E5",cursor:"pointer"}},N.createElement("div",{style:{textAlign:"center",width:"32px",height:"14px"}},N.createElement("svg",{height:"100%",style:{opacity:.5,margin:"auto",display:"block"},width:"10px"},N.createElement("use",{xlinkHref:"#plus"})))):null;return N.createElement(Yw,{okayTitle:"Submit",onCancel:this.props.onCancel,onOkay:this.handleSubmit.bind(this),title:"Custom Color Map"},N.createElement("table",{className:"table-track-options"},N.createElement("thead",null),N.createElement("tbody",{style:{verticalAlign:"top"}},N.createElement("tr",null,N.createElement("td",{className:"td-track-options"},N.createElement("table",null,N.createElement("tbody",null,N.createElement("tr",null,N.createElement("td",{className:"td-track-options"},"Preview")),N.createElement("tr",null,N.createElement("td",{className:"td-track-options"},N.createElement("div",{style:{width:200}},N.createElement(yy,{options:{bounded:!1},viewConfig:r}))))))),N.createElement("td",{className:"td-track-options"},N.createElement("table",null,N.createElement("tbody",null,N.createElement("tr",null,N.createElement("td",{className:"td-track-options"},"Colors")),N.createElement("tr",null,N.createElement("td",{className:"td-track-options"},A,N.createElement("div",{style:{position:"relative"}},o))))))))))}}]),I}(N.Component);IO.propTypes={handleCancel:L.func,onCancel:L.func,onSubmit:L.func,track:L.object,xScale:L.object,yScale:L.object};const _ae=g=>{if(!g.header)return[];const e=g.header.split(" "),I=[];for(let i=0;ig.reduce((i,n)=>(i[n]={name:`${n*I}${e}`,value:n},i),{}),OC={yes:{name:"Yes",value:!0},no:{name:"No",value:!1}},kI={black:{name:"Black",value:"black"},blue:{name:"Blue",value:"blue"},brown:{name:"Brown",value:"brown"},cyan:{name:"Cyan",value:"cyan"},green:{name:"Green",value:"green"},grey:{name:"Grey",value:"grey"},orange:{name:"Orange",value:"orange"},purple:{name:"Purple",value:"purple"},turquoise:{name:"Turquoise",value:"turquoise"},red:{name:"Red",value:"red"},white:{name:"White",value:"white"}},yUt={use_stroke:{name:"Glyph color",value:"[glyph-color]"}},GG=B0([1,2,3,5,8,13,21]),ZUt=Object.assign(GG,{none:{name:"none",value:"none"}}),t1=B0([0,2,4,8,16,32,64,128,256]),kl=B0([0,.2,.4,.6,.8,1],"%",100),GUt=B0([.2,.4,.6,.8,1],"%",100),nn={axisLabelFormatting:{name:"Axis Label Formatting",inlineOptions:{normal:{name:"normal",value:"normal"},scientific:{name:"scientific",value:"scientific"}}},flipDiagonal:{name:"Flip Across Diagonal",inlineOptions:{none:{name:"No",value:"none"},yes:{name:"Yes",value:"yes"},copy:{name:"Copy",value:"copy"}}},heatmapValueScaling:{name:"Value Scaling",inlineOptions:{linear:{name:"Linear",value:"linear"},log:{name:"Log",value:"log"}}},valueScaling:{name:"Value Scaling",inlineOptions:{linear:{name:"Linear",value:"linear"},log:{name:"Log",value:"log"}}},extent:{name:"Extent",inlineOptions:{full:{name:"Full",value:"full"},upperRight:{name:"Upper Right",value:"upper-right"},lowerLeft:{name:"Lower Left",value:"lower-left"}}},labelLeftMargin:{name:"Label Left Margin",inlineOptions:t1},labelRightMargin:{name:"Label Right Margin",inlineOptions:t1},labelTopMargin:{name:"Label Top Margin",inlineOptions:t1},labelBottomMargin:{name:"Label Bottom Margin",inlineOptions:t1},labelShowResolution:{name:"Label Show Resolution",inlineOptions:OC},labelShowAssembly:{name:"Label Show Assembly",inlineOptions:OC},lineStrokeWidth:{name:"Stroke Width",inlineOptions:GG},strokeWidth:{name:"Stroke Width",inlineOptions:GG},trackBorderWidth:{name:"Track Border Width",inlineOptions:GG},separatePlusMinusStrands:{name:"Separate +/- strands",inlineOptions:OC},sortLargestOnTop:{name:"Sort Largest On Top",inlineOptions:OC},showTexts:{name:"Show texts",inlineOptions:OC},staggered:{name:"Staggered",inlineOptions:OC},minSquareSize:{name:"Minimum size",inlineOptions:ZUt},pointSize:{name:"Point Size",inlineOptions:GG},pointColor:{name:"Point Color",inlineOptions:kI},trackBorderColor:{name:"Track Border Color",inlineOptions:kI},backgroundColor:{name:"Background Color",inlineOptions:{white:{name:"White",value:"white"},lightGrey:{name:"Light Grey",value:"#eeeeee"},grey:{name:"Grey",value:"#cccccc"},black:{name:"Black",value:"black"},transparent:{name:"Transparent",value:"transparent"}}},colorScale:{name:"Color Scale",inlineOptions:{epilogos:{name:"Epilogos",values:["#FF0000","#FF4500","#32CD32","#008000","#006400","#C2E105","#FFFF00","#66CDAA","#8A91D0","#CD5C5C","#E9967A","#BDB76B","#808080","#C0C0C0","#FFFFFF"]},category10:{name:"D3 Category10",values:["#1F77B4","#FF7F0E","#2CA02C","#D62728","#9467BD","#8C564B","#E377C2","#7F7F7F","#BCBD22","#17BECF"]}}},minusStrandColor:{name:"- Strand Color",inlineOptions:kI},plusStrandColor:{name:"+ Strand Color",inlineOptions:kI},lineStrokeColor:{name:"Stroke color",inlineOptions:kI},projectionStrokeColor:{name:"Stroke color",inlineOptions:kI},projectionFillColor:{name:"Fill color",inlineOptions:kI},stroke:{name:"Stroke Color",inlineOptions:kI},strokeColor:{name:"Stroke color",inlineOptions:kI},fill:{name:"Fill Color",inlineOptions:kI},color:{name:"Color",inlineOptions:kI},fontColor:{name:"Font color",inlineOptions:kI},fillColor:{name:"Fill color",inlineOptions:kI},barFillColor:{name:"Fill color",inlineOptions:kI},barFillColorTop:{name:"Top Fill color",inlineOptions:kI},barFillColorBottom:{name:"Bottom Fill color",inlineOptions:kI},barOpacity:{name:"Bar opacity",inlineOptions:kl},zeroLineVisible:{name:"Zero line visible",inlineOptions:OC},zeroLineColor:{name:"Zero line color",inlineOptions:kI},zeroLineOpacity:{name:"Zero line opacity",inlineOptions:GUt},fillOpacity:{name:"Fill Opacity",inlineOptions:kl},strokeOpacity:{name:"Stroke Opacity",inlineOptions:kl},strokePos:{name:"Stroke Position",inlineOptions:{aroundInner:{name:"Around Inner",value:"around"},aroundCenter:{name:"Around Center",value:null},hidden:{name:"Hidden",value:"hidden"},top:{name:"Top",value:"top"},right:{name:"Right",value:"right"},bottom:{name:"Bottom",value:"bottom"},left:{name:"Left",value:"left"}}},barBorder:{name:"Bar border",inlineOptions:OC},scaledHeight:{name:"Scaled height",inlineOptions:OC},rectangleDomainStrokeColor:{name:"Stroke color",inlineOptions:kI},rectangleDomainFillColor:{name:"Fill color",inlineOptions:kI},rectangleDomainFillOpacity:{name:"Fill opacity",inlineOptions:kl},rectangleDomainOpacity:{name:"Opacity",inlineOptions:kl},mapboxStyle:{name:"Map style",inlineOptions:{streets:{name:"streets",value:"mapbox.streets"},light:{name:"light",value:"mapbox.light"},dark:{name:"dark",value:"mapbox.dark"},satellite:{name:"satellite",value:"mapbox.satellite"},"streets-satellite":{name:"streets-satellite",value:"mapbox.streets-satellite"},wheatpaste:{name:"wheatpaste",value:"mapbox.wheatpaste"},"streets-basic":{name:"streets-basic",value:"mapbox.streets-basic"},comic:{name:"comic",value:"mapbox.comic"},outdoors:{name:"outdoors",value:"mapbox.outdoors"},"run-bike-hike":{name:"run-bike-hike",value:"mapbox.run-bike-hike"},pencil:{name:"pencil",value:"mapbox.pencil"},pirates:{name:"pirates",value:"mapbox.pirates"},emerald:{name:"emerald",value:"mapbox.emerald"},"high-contrast":{name:"high-contrast",value:"mapbox.high-contrast"}}},oneDHeatmapFlipped:{name:"Flip Heatmap",inlineOptions:{yes:{name:"Yes",value:"yes"},no:{name:"No",value:null}}},showMousePosition:{name:"Show Mouse Position",inlineOptions:OC},showTooltip:{name:"Show Tooltip",inlineOptions:OC},fontSize:{name:"Font Size",inlineOptions:B0([8,9,10,11,12,14,16,18,24],"px")},tickPositions:{name:"Tick Positions",inlineOptions:{even:{name:"Even",value:"even"},ends:{name:"Ends",value:"ends"}}},tickFormat:{name:"Tick Format",inlineOptions:{plain:{name:"Plain",value:"plain"},si:{name:"SI",value:"si"}}},colorEncoding:{name:"Color Encode Annotations",inlineOptions:{none:{name:"None",value:null},itemRgb:{name:"itemRgb",value:"itemRgb"}},generateOptions:_ae},fontIsAligned:{name:"Left-Align Font",inlineOptions:OC},axisPositionHorizontal:{name:"Axis Position",inlineOptions:{left:{name:"Left",value:"left"},outsideLeft:{name:"Outside left",value:"outsideLeft"},right:{name:"Right",value:"right"},outsideRight:{name:"Outside right",value:"outsideRight"},hidden:{name:"Hidden",value:null}}},axisPositionVertical:{name:"Axis Position",inlineOptions:{top:{name:"Top",value:"top"},outsideTop:{name:"Outside top",value:"outsideTop"},bottom:{name:"Bottom",value:"bottom"},outsideBottom:{name:"Outside bottom",value:"outsideBottom"},hidden:{name:"Hidden",value:null}}},axisMargin:{name:"Axis Margin",inlineOptions:B0([0,10,20,30,40,50,100,200,400],"px")},colorbarPosition:{name:"Colorbar Position",inlineOptions:{topLeft:{name:"Top Left",value:"topLeft"},topRight:{name:"Top Right",value:"topRight"},bottomLeft:{name:"Bottom Left",value:"bottomLeft"},bottomRight:{name:"Bottom Right",value:"bottomRight"},hidden:{name:"Hidden",value:null}}},colorbarBackgroundColor:{name:"Colorbar Background Color",inlineOptions:kI},colorbarBackgroundOpacity:{name:"Colorbar Background Opacity",inlineOptions:kl},colorbarLabelsPosition:{name:"Colorbar Labels Position",inlineOptions:{inside:{name:"Inside",value:"inside"},outside:{name:"Outside",value:"outside"}}},labelColor:{name:"Label Color",inlineOptions:{...kI,...yUt}},labelPosition:{name:"Label Position",inlineOptions:{ol:{name:"Outer left",value:"outerLeft"},or:{name:"Outer right",value:"outerRight"},ot:{name:"Outer top",value:"outerTop"},ob:{name:"Outer bottom",value:"outerBottom"},tl:{name:"Top left",value:"topLeft"},tr:{name:"Top right",value:"topRight"},bl:{name:"Bottom left",value:"bottomLeft"},br:{name:"Bottom right",value:"bottomRight"},hidden:{name:"Hidden",value:"hidden"}}},labelTextOpacity:{name:"Label Text Opacity",inlineOptions:kl},geneAnnotationHeight:{name:"Gene Annotation Height",inlineOptions:{8:{name:"8px",value:8},10:{name:"10px",value:10},12:{name:"12px",value:12},16:{name:"16px",value:16}}},annotationHeight:{name:"Annotation Height",inlineOptions:{5:{name:"5px",value:5},8:{name:"8px",value:8},10:{name:"10px",value:10},12:{name:"12px",value:12},16:{name:"16px",value:16},20:{name:"20px",value:20},scaled:{name:"scaled",value:"scaled"}}},maxAnnotationHeight:{name:"Max Annotation Height",inlineOptions:{5:{name:"5px",value:5},8:{name:"8px",value:8},10:{name:"10px",value:10},12:{name:"12px",value:12},16:{name:"16px",value:16},20:{name:"20px",value:20},none:{name:"none",value:null}}},annotationStyle:{name:"Annotation Style",inlineOptions:{box:{name:"Box",value:"box"},segment:{name:"Segment",value:"segment"}}},geneLabelPosition:{name:"Gene Label Position",inlineOptions:{inside:{name:"Inside",value:"inside"},outside:{name:"Outside",value:"outside"}}},geneStrandSpacing:{name:"Gene Strand Spacing",inlineOptions:{2:{name:"2px",value:2},4:{name:"4px",value:4},8:{name:"8px",value:8}}},labelBackgroundColor:{name:"Label Background Color",inlineOptions:kI},labelBackgroundOpacity:{name:"Label Background Opacity",inlineOptions:kl},viewResolution:{name:"View Resolution",inlineOptions:{high:{name:"High",value:384},medium:{name:"Medium",value:1024},low:{name:"Low",value:2048}}},colorRange:{name:"Color map",inlineOptions:{afmhot:{name:"afmhot",value:["rgba(0,0,0,1.0)","rgba(128,0,0,1.0)","rgba(256,129,1,1.0)","rgba(256,256,129,1.0)","rgba(256,256,256,1.0)"]},fall:{name:"fall",value:["white","rgba(245,166,35,1.0)","rgba(208,2,27,1.0)","black"]},hot:{name:"hot",value:["rgba(10,0,0,1.0)","rgba(179,0,0,1.0)","rgba(256,91,0,1.0)","rgba(256,256,6,1.0)","rgba(256,256,256,1.0)"]},jet:{name:"jet",value:["rgba(0,0,128,1.0)","rgba(0,129,256,1.0)","rgba(125,256,122,1.0)","rgba(256,148,0,1.0)","rgba(128,0,0,1.0)"]},bwr:{name:"bwr",value:["rgba(0,0,256,1.0)","rgba(128,128,256,1.0)","rgba(256,254,254,1.0)","rgba(256,126,126,1.0)","rgba(256,0,0,1.0)"]},cubehelix:{name:"cubehelix",value:["rgba(0,0,0,1.0)","rgba(21,83,76,1.0)","rgba(162,121,74,1.0)","rgba(199,180,238,1.0)","rgba(256,256,256,1.0)"]},rainbow:{name:"rainbow",value:["rgba(128,0,256,1.0)","rgba(0,181,236,1.0)","rgba(129,255,180,1.0)","rgba(256,179,96,1.0)","rgba(256,0,0,1.0)"]},gray:{name:"greys",value:["rgba(255,255,255,1)","rgba(0,0,0,1)"]},red:{name:"White to red",value:["rgba(255,255,255,1)","rgba(255,0,0,1)"]},green:{name:"White to green",value:["rgba(255,255,255,1)","rgba(0,255,0,1)"]},blue:{name:"White to blue",value:["rgba(255,255,255,1)","rgba(0,0,255,1)"]},custard:{name:"custard",value:["#FFFFFF","#F8E71C","rgba(245,166,35,1)","rgba(0,0,0,1)"]},magma:{name:"magma",value:["rgba(0,0,3,1)","rgba(0,0,4,1)","rgba(0,0,6,1)","rgba(1,0,7,1)","rgba(1,1,9,1)","rgba(1,1,11,1)","rgba(2,2,13,1)","rgba(2,2,15,1)","rgba(3,3,17,1)","rgba(4,3,19,1)","rgba(4,4,21,1)","rgba(5,4,23,1)","rgba(6,5,25,1)","rgba(7,5,27,1)","rgba(8,6,29,1)","rgba(9,7,32,1)","rgba(10,7,34,1)","rgba(11,8,36,1)","rgba(12,9,38,1)","rgba(13,10,40,1)","rgba(14,10,42,1)","rgba(15,11,45,1)","rgba(16,12,47,1)","rgba(17,12,49,1)","rgba(19,13,51,1)","rgba(20,13,54,1)","rgba(21,14,56,1)","rgba(22,14,58,1)","rgba(23,15,61,1)","rgba(25,15,63,1)","rgba(26,16,66,1)","rgba(27,16,68,1)","rgba(28,16,70,1)","rgba(30,17,73,1)","rgba(31,17,75,1)","rgba(33,17,78,1)","rgba(34,17,80,1)","rgba(36,17,83,1)","rgba(37,17,85,1)","rgba(39,17,87,1)","rgba(40,17,90,1)","rgba(42,17,92,1)","rgba(43,17,94,1)","rgba(45,17,97,1)","rgba(47,16,99,1)","rgba(49,16,101,1)","rgba(50,16,103,1)","rgba(52,16,105,1)","rgba(54,15,107,1)","rgba(55,15,108,1)","rgba(57,15,110,1)","rgba(59,15,112,1)","rgba(61,15,113,1)","rgba(62,15,114,1)","rgba(64,15,116,1)","rgba(66,15,117,1)","rgba(67,15,118,1)","rgba(69,15,119,1)","rgba(71,15,120,1)","rgba(72,16,120,1)","rgba(74,16,121,1)","rgba(76,16,122,1)","rgba(77,17,123,1)","rgba(79,17,123,1)","rgba(81,18,124,1)","rgba(82,18,124,1)","rgba(84,19,125,1)","rgba(85,20,125,1)","rgba(87,20,126,1)","rgba(88,21,126,1)","rgba(90,21,126,1)","rgba(92,22,127,1)","rgba(93,23,127,1)","rgba(95,23,127,1)","rgba(96,24,128,1)","rgba(98,25,128,1)","rgba(99,25,128,1)","rgba(101,26,128,1)","rgba(103,26,128,1)","rgba(104,27,129,1)","rgba(106,28,129,1)","rgba(107,28,129,1)","rgba(109,29,129,1)","rgba(110,30,129,1)","rgba(112,30,129,1)","rgba(113,31,129,1)","rgba(115,32,129,1)","rgba(117,32,129,1)","rgba(118,33,129,1)","rgba(120,33,129,1)","rgba(121,34,130,1)","rgba(123,35,130,1)","rgba(124,35,130,1)","rgba(126,36,130,1)","rgba(128,36,130,1)","rgba(129,37,129,1)","rgba(131,37,129,1)","rgba(132,38,129,1)","rgba(134,39,129,1)","rgba(136,39,129,1)","rgba(137,40,129,1)","rgba(139,40,129,1)","rgba(140,41,129,1)","rgba(142,41,129,1)","rgba(144,42,129,1)","rgba(145,42,129,1)","rgba(147,43,128,1)","rgba(148,43,128,1)","rgba(150,44,128,1)","rgba(152,44,128,1)","rgba(153,45,128,1)","rgba(155,46,127,1)","rgba(157,46,127,1)","rgba(158,47,127,1)","rgba(160,47,127,1)","rgba(161,48,126,1)","rgba(163,48,126,1)","rgba(165,49,126,1)","rgba(166,49,125,1)","rgba(168,50,125,1)","rgba(170,50,125,1)","rgba(171,51,124,1)","rgba(173,51,124,1)","rgba(175,52,123,1)","rgba(176,52,123,1)","rgba(178,53,123,1)","rgba(180,53,122,1)","rgba(181,54,122,1)","rgba(183,55,121,1)","rgba(185,55,121,1)","rgba(186,56,120,1)","rgba(188,56,120,1)","rgba(189,57,119,1)","rgba(191,57,118,1)","rgba(193,58,118,1)","rgba(194,59,117,1)","rgba(196,59,117,1)","rgba(198,60,116,1)","rgba(199,61,115,1)","rgba(201,61,115,1)","rgba(202,62,114,1)","rgba(204,63,113,1)","rgba(206,63,113,1)","rgba(207,64,112,1)","rgba(209,65,111,1)","rgba(210,66,110,1)","rgba(212,67,110,1)","rgba(213,67,109,1)","rgba(215,68,108,1)","rgba(216,69,107,1)","rgba(218,70,107,1)","rgba(219,71,106,1)","rgba(221,72,105,1)","rgba(222,73,104,1)","rgba(223,74,103,1)","rgba(225,75,103,1)","rgba(226,76,102,1)","rgba(227,78,101,1)","rgba(229,79,100,1)","rgba(230,80,100,1)","rgba(231,81,99,1)","rgba(232,83,98,1)","rgba(233,84,97,1)","rgba(234,85,97,1)","rgba(236,87,96,1)","rgba(237,88,95,1)","rgba(238,90,95,1)","rgba(239,91,94,1)","rgba(239,93,94,1)","rgba(240,95,93,1)","rgba(241,96,93,1)","rgba(242,98,93,1)","rgba(243,100,92,1)","rgba(243,101,92,1)","rgba(244,103,92,1)","rgba(245,105,92,1)","rgba(246,107,92,1)","rgba(246,108,92,1)","rgba(247,110,92,1)","rgba(247,112,92,1)","rgba(248,114,92,1)","rgba(248,116,92,1)","rgba(249,118,92,1)","rgba(249,120,92,1)","rgba(250,121,93,1)","rgba(250,123,93,1)","rgba(250,125,94,1)","rgba(251,127,94,1)","rgba(251,129,95,1)","rgba(251,131,95,1)","rgba(252,133,96,1)","rgba(252,135,97,1)","rgba(252,137,97,1)","rgba(252,139,98,1)","rgba(253,140,99,1)","rgba(253,142,100,1)","rgba(253,144,101,1)","rgba(253,146,102,1)","rgba(253,148,103,1)","rgba(254,150,104,1)","rgba(254,152,105,1)","rgba(254,154,106,1)","rgba(254,156,107,1)","rgba(254,157,108,1)","rgba(254,159,109,1)","rgba(254,161,110,1)","rgba(254,163,111,1)","rgba(254,165,112,1)","rgba(255,167,114,1)","rgba(255,169,115,1)","rgba(255,171,116,1)","rgba(255,172,118,1)","rgba(255,174,119,1)","rgba(255,176,120,1)","rgba(255,178,122,1)","rgba(255,180,123,1)","rgba(255,182,124,1)","rgba(255,184,126,1)","rgba(255,185,127,1)","rgba(255,187,129,1)","rgba(255,189,130,1)","rgba(255,191,132,1)","rgba(255,193,133,1)","rgba(255,195,135,1)","rgba(255,197,136,1)","rgba(255,198,138,1)","rgba(255,200,140,1)","rgba(255,202,141,1)","rgba(255,204,143,1)","rgba(254,206,144,1)","rgba(254,208,146,1)","rgba(254,209,148,1)","rgba(254,211,149,1)","rgba(254,213,151,1)","rgba(254,215,153,1)","rgba(254,217,155,1)","rgba(254,219,156,1)","rgba(254,220,158,1)","rgba(254,222,160,1)","rgba(254,224,162,1)","rgba(254,226,163,1)","rgba(253,228,165,1)","rgba(253,230,167,1)","rgba(253,231,169,1)","rgba(253,233,171,1)","rgba(253,235,172,1)","rgba(253,237,174,1)","rgba(253,239,176,1)","rgba(253,241,178,1)","rgba(253,242,180,1)","rgba(253,244,182,1)","rgba(253,246,184,1)","rgba(252,248,186,1)","rgba(252,250,188,1)","rgba(252,251,189,1)","rgba(252,253,191,1)"]},viridis:{name:"viridis",value:["rgba(68,1,84,1)","rgba(68,2,85,1)","rgba(69,3,87,1)","rgba(69,5,88,1)","rgba(69,6,90,1)","rgba(70,8,91,1)","rgba(70,9,93,1)","rgba(70,11,94,1)","rgba(70,12,96,1)","rgba(71,14,97,1)","rgba(71,15,98,1)","rgba(71,17,100,1)","rgba(71,18,101,1)","rgba(71,20,102,1)","rgba(72,21,104,1)","rgba(72,22,105,1)","rgba(72,24,106,1)","rgba(72,25,108,1)","rgba(72,26,109,1)","rgba(72,28,110,1)","rgba(72,29,111,1)","rgba(72,30,112,1)","rgba(72,32,113,1)","rgba(72,33,115,1)","rgba(72,34,116,1)","rgba(72,36,117,1)","rgba(72,37,118,1)","rgba(72,38,119,1)","rgba(72,39,120,1)","rgba(71,41,121,1)","rgba(71,42,121,1)","rgba(71,43,122,1)","rgba(71,44,123,1)","rgba(71,46,124,1)","rgba(70,47,125,1)","rgba(70,48,126,1)","rgba(70,49,126,1)","rgba(70,51,127,1)","rgba(69,52,128,1)","rgba(69,53,129,1)","rgba(69,54,129,1)","rgba(68,56,130,1)","rgba(68,57,131,1)","rgba(68,58,131,1)","rgba(67,59,132,1)","rgba(67,60,132,1)","rgba(67,62,133,1)","rgba(66,63,133,1)","rgba(66,64,134,1)","rgba(65,65,134,1)","rgba(65,66,135,1)","rgba(65,67,135,1)","rgba(64,69,136,1)","rgba(64,70,136,1)","rgba(63,71,136,1)","rgba(63,72,137,1)","rgba(62,73,137,1)","rgba(62,74,137,1)","rgba(61,75,138,1)","rgba(61,77,138,1)","rgba(60,78,138,1)","rgba(60,79,138,1)","rgba(59,80,139,1)","rgba(59,81,139,1)","rgba(58,82,139,1)","rgba(58,83,139,1)","rgba(57,84,140,1)","rgba(57,85,140,1)","rgba(56,86,140,1)","rgba(56,87,140,1)","rgba(55,88,140,1)","rgba(55,89,140,1)","rgba(54,91,141,1)","rgba(54,92,141,1)","rgba(53,93,141,1)","rgba(53,94,141,1)","rgba(52,95,141,1)","rgba(52,96,141,1)","rgba(51,97,141,1)","rgba(51,98,141,1)","rgba(51,99,141,1)","rgba(50,100,142,1)","rgba(50,101,142,1)","rgba(49,102,142,1)","rgba(49,103,142,1)","rgba(48,104,142,1)","rgba(48,105,142,1)","rgba(47,106,142,1)","rgba(47,107,142,1)","rgba(47,108,142,1)","rgba(46,109,142,1)","rgba(46,110,142,1)","rgba(45,111,142,1)","rgba(45,112,142,1)","rgba(45,112,142,1)","rgba(44,113,142,1)","rgba(44,114,142,1)","rgba(43,115,142,1)","rgba(43,116,142,1)","rgba(43,117,142,1)","rgba(42,118,142,1)","rgba(42,119,142,1)","rgba(41,120,142,1)","rgba(41,121,142,1)","rgba(41,122,142,1)","rgba(40,123,142,1)","rgba(40,124,142,1)","rgba(40,125,142,1)","rgba(39,126,142,1)","rgba(39,127,142,1)","rgba(38,128,142,1)","rgba(38,129,142,1)","rgba(38,130,142,1)","rgba(37,131,142,1)","rgba(37,131,142,1)","rgba(37,132,142,1)","rgba(36,133,142,1)","rgba(36,134,142,1)","rgba(35,135,142,1)","rgba(35,136,142,1)","rgba(35,137,142,1)","rgba(34,138,141,1)","rgba(34,139,141,1)","rgba(34,140,141,1)","rgba(33,141,141,1)","rgba(33,142,141,1)","rgba(33,143,141,1)","rgba(32,144,141,1)","rgba(32,145,140,1)","rgba(32,146,140,1)","rgba(32,147,140,1)","rgba(31,147,140,1)","rgba(31,148,140,1)","rgba(31,149,139,1)","rgba(31,150,139,1)","rgba(31,151,139,1)","rgba(30,152,139,1)","rgba(30,153,138,1)","rgba(30,154,138,1)","rgba(30,155,138,1)","rgba(30,156,137,1)","rgba(30,157,137,1)","rgba(30,158,137,1)","rgba(30,159,136,1)","rgba(30,160,136,1)","rgba(31,161,136,1)","rgba(31,162,135,1)","rgba(31,163,135,1)","rgba(31,163,134,1)","rgba(32,164,134,1)","rgba(32,165,134,1)","rgba(33,166,133,1)","rgba(33,167,133,1)","rgba(34,168,132,1)","rgba(35,169,131,1)","rgba(35,170,131,1)","rgba(36,171,130,1)","rgba(37,172,130,1)","rgba(38,173,129,1)","rgba(39,174,129,1)","rgba(40,175,128,1)","rgba(41,175,127,1)","rgba(42,176,127,1)","rgba(43,177,126,1)","rgba(44,178,125,1)","rgba(46,179,124,1)","rgba(47,180,124,1)","rgba(48,181,123,1)","rgba(50,182,122,1)","rgba(51,183,121,1)","rgba(53,183,121,1)","rgba(54,184,120,1)","rgba(56,185,119,1)","rgba(57,186,118,1)","rgba(59,187,117,1)","rgba(61,188,116,1)","rgba(62,189,115,1)","rgba(64,190,114,1)","rgba(66,190,113,1)","rgba(68,191,112,1)","rgba(70,192,111,1)","rgba(72,193,110,1)","rgba(73,194,109,1)","rgba(75,194,108,1)","rgba(77,195,107,1)","rgba(79,196,106,1)","rgba(81,197,105,1)","rgba(83,198,104,1)","rgba(85,198,102,1)","rgba(88,199,101,1)","rgba(90,200,100,1)","rgba(92,201,99,1)","rgba(94,201,98,1)","rgba(96,202,96,1)","rgba(98,203,95,1)","rgba(101,204,94,1)","rgba(103,204,92,1)","rgba(105,205,91,1)","rgba(108,206,90,1)","rgba(110,206,88,1)","rgba(112,207,87,1)","rgba(115,208,85,1)","rgba(117,208,84,1)","rgba(119,209,82,1)","rgba(122,210,81,1)","rgba(124,210,79,1)","rgba(127,211,78,1)","rgba(129,212,76,1)","rgba(132,212,75,1)","rgba(134,213,73,1)","rgba(137,213,72,1)","rgba(139,214,70,1)","rgba(142,215,68,1)","rgba(144,215,67,1)","rgba(147,216,65,1)","rgba(149,216,63,1)","rgba(152,217,62,1)","rgba(155,217,60,1)","rgba(157,218,58,1)","rgba(160,218,57,1)","rgba(163,219,55,1)","rgba(165,219,53,1)","rgba(168,220,51,1)","rgba(171,220,50,1)","rgba(173,221,48,1)","rgba(176,221,46,1)","rgba(179,221,45,1)","rgba(181,222,43,1)","rgba(184,222,41,1)","rgba(187,223,39,1)","rgba(189,223,38,1)","rgba(192,223,36,1)","rgba(195,224,35,1)","rgba(197,224,33,1)","rgba(200,225,32,1)","rgba(203,225,30,1)","rgba(205,225,29,1)","rgba(208,226,28,1)","rgba(211,226,27,1)","rgba(213,226,26,1)","rgba(216,227,25,1)","rgba(219,227,24,1)","rgba(221,227,24,1)","rgba(224,228,24,1)","rgba(226,228,24,1)","rgba(229,228,24,1)","rgba(232,229,25,1)","rgba(234,229,25,1)","rgba(237,229,26,1)","rgba(239,230,27,1)","rgba(242,230,28,1)","rgba(244,230,30,1)","rgba(247,230,31,1)","rgba(249,231,33,1)","rgba(251,231,35,1)","rgba(254,231,36,1)"]},custom:{name:"Custom...",componentPickers:{heatmap:IO,"horizontal-heatmap":IO}}}},align:{name:"Align",inlineOptions:{white:{name:"Top",value:"top"},lightGrey:{name:"Bottom",value:"bottom"}}},colorRangeGradient:{name:"Color Gradient",inlineOptions:OC},dataTransform:{name:"Transforms",inlineOptions:{default:{name:"Default",value:"default"},None:{name:"None",value:"None"}},generateOptions:g=>{const e=[];if(g.transforms)for(const I of g.transforms)e.push({name:I.name,value:I.value});return e}},aggregationMode:{name:"Aggregation Mode",inlineOptions:{},generateOptions:g=>{const e=[];return g.aggregationModes?Object.values(g.aggregationModes).forEach(({name:I,value:i})=>{e.push({name:I,value:i})}):e.push({name:"Default",value:"default"}),e}},maxZoom:{name:"Zoom limit",inlineOptions:{none:{name:"None",value:null}},generateOptions:g=>{if(g.maxZoom){const e=[];for(let I=0;I<=g.maxZoom;I++){const{maxWidth:i,binsPerDimension:n,maxZoom:C}=g;let r=1,o=1;if(g.resolutions){const l=g.resolutions.map(c=>+c).sort((c,u)=>u-c);[r]=l,o=l[I]}else o=g.maxWidth/(2**I*g.binsPerDimension),r=i/(2**C*n);const A=J0(r,o),a=Am(`.${A}`,o)(o);e.push({name:a,value:I.toString()})}return e}return[]}},valueColumn:{name:"Value column",inlineOptions:{none:{name:"None",value:null}},generateOptions:_ae},zeroValueColor:{name:"Zero Value Color",inlineOptions:kI}},A9e={...Pot,IS_TRACK_RANGE_SELECTABLE:L0,OPTIONS_INFO:nn},BUt={d3Array:Net,d3Axis:K9t,d3Brush:Wrt,d3Color:_et,d3Drag:oCt,d3Dsv:cAt,d3Format:Ztt,d3Geo:sDt,d3Queue:hDt,d3Request:YDt,d3Scale:jgt,d3Selection:Xqe,d3Transition:AVt,d3Zoom:hVt,PIXI:A9e.GLOBALS.PIXI,mix:uy,slugid:dg},vUt={Annotations1dTrack:DP,Annotations2dTrack:x1e,ArrowheadDomainsTrack:Y1e,BarTrack:I4,BedLikeTrack:V1e,CNVIntervalTrack:N1e,Chromosome2DAnnotations:M1e,Chromosome2DLabels:E1e,ChromosomeGrid:cG,CombinedTrack:VQ,CrossRule:aWe,DivergentBarTrack:H1e,HeatmapTiledPixiTrack:Rw,Horizontal1dHeatmapTrack:T1e,Horizontal2DDomainsTrack:D1e,HorizontalChromosomeLabels:P1e,HorizontalGeneAnnotationsTrack:k1e,HorizontalHeatmapTrack:J1e,HorizontalLine1DPixiTrack:cy,HorizontalMultivecTrack:X1e,HorizontalPoint1DPixiTrack:W1e,HorizontalRule:IWe,HorizontalTiled1DPixiTrack:sy,HorizontalTiledPlot:o2,HorizontalTrack:oXe,Id2DTiledPixiTrack:zRe,IdHorizontal1DTiledPixiTrack:JRe,IdVertical1DTiledPixiTrack:LRe,LeftAxisTrack:jRe,MapboxTilesTrack:cWe,MoveableTrack:nY,OSMTileIdsTrack:lWe,OSMTilesTrack:Xw,OverlayTrack:R1e,PixiTrack:dC,RasterTilesTrack:uWe,SVGTrack:vm,SquareMarkersTrack:F1e,Tiled1DPixiTrack:_j,TiledPixiTrack:Bm,TopAxisTrack:QRe,Track:$p,ValueIntervalTrack:L1e,VerticalRule:AWe,VerticalTiled1DPixiTrack:ORe,VerticalTrack:aXe,ViewportTracker2D:_1e,ViewportTracker2DPixi:gEt,ViewportTrackerHorizontal:U1e,ViewportTrackerVertical:Q1e},SUt={ContextMenuItem:og,DataFetcher:Jk,LruCache:lXe},wUt={ChromosomeInfo:qs,SearchField:d0},VUt={DataFetcher:Jk,GBKDataFetcher:DRe,LocalDataFetcher:FRe,getDataFetcher:j5t},m2={chromosomes:wUt,libraries:BUt,tracks:vUt,dataFetchers:VUt,factories:SUt,services:JAt,utils:HVt,configs:A9e,VERSION:cXe},BF={"track-renderer":"_track-renderer_11dwb_1","track-renderer-element":"_track-renderer-element_11dwb_5","track-renderer-events":"_track-renderer-events_11dwb_6"};function RUt(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function Uae(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function f2(g){return f2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},f2(g)}const{getDataFetcher:KUt}=m2.dataFetchers,xUt=100;let r$=function(g){TUt(I,g);var e=NUt(I);function I(i){var n;if(RUt(this,I),n=e.call(this,i),n.dragging=!1,n.element=null,n.eventTracker=null,n.eventTrackerOld=null,n.closing=!1,n.yPositionOffset=0,n.xPositionOffset=0,n.scrollTop=0,n.scrollTimeout=null,n.activeTransitions=0,n.zoomTransform=Fi,n.windowScrolledBound=n.windowScrolled.bind(Fo(n)),n.zoomStartedBound=n.zoomStarted.bind(Fo(n)),n.zoomedBound=n.zoomed.bind(Fo(n)),n.zoomEndedBound=n.zoomEnded.bind(Fo(n)),n.uid=dg.nice(),n.viewUid=n.props.uid,n.availableForPlugins={...m2,services:{...m2.services,pubSub:n.props.pubSub,pixiRenderer:n.props.pixiRenderer}},n.mounted=!1,n.emptyZoomBehavior=Oz(),n.currentProps=i,n.prevPropsStr="",n.zoomBehavior=Oz().filter(C=>!(C.target.classList.contains("no-zoom")||C.target.classList.contains("react-resizable-handle"))).on("start",n.zoomStartedBound).on("zoom",n.zoomedBound).on("end",n.zoomEndedBound),n.zoomTransform=Fi,n.prevZoomTransform=Fi,n.initialXDomain=[0,1],n.initialYDomain=[0,1],n.xDomainLimits=[-Number.MAX_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],n.yDomainLimits=[-Number.MAX_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],n.zoomLimits=[0,Number.MAX_SAFE_INTEGER],n.prevCenterX=n.currentProps.paddingLeft+n.currentProps.leftWidth+n.currentProps.centerWidth/2,n.prevCenterY=n.currentProps.paddingTop+n.currentProps.topHeight+n.currentProps.centerHeight/2,n.cumCenterXOffset=0,n.cumCenterYOffset=0,n.setUpInitialScales(n.currentProps.initialXDomain,n.currentProps.initialYDomain,n.currentProps.xDomainLimits,n.currentProps.yDomainLimits,n.currentProps.zoomLimits),n.setUpScales(),n.trackDefObjects={},n.metaTracks={},n.pubSubs=[],window.higlassTracksByType)for(const C in window.higlassTracksByType)$g[C]=window.higlassTracksByType[C].config;return n.boundForwardEvent=n.forwardEvent.bind(Fo(n)),n.boundScrollEvent=n.scrollEvent.bind(Fo(n)),n.boundForwardContextMenu=n.forwardContextMenu.bind(Fo(n)),n.dispatchEventBound=n.dispatchEvent.bind(Fo(n)),n.zoomToDataPosHandlerBound=n.zoomToDataPosHandler.bind(Fo(n)),n.onScrollHandlerBound=n.onScrollHandler.bind(Fo(n)),n.elementPos={height:0,width:0,left:0,top:0},n.elementSelection=null,n}return WUt(I,[{key:"xScale",get:function(){if(!this._xScale)throw new Error("xScale is not defined");return this._xScale}},{key:"yScale",get:function(){if(!this._yScale)throw new Error("yScale is not defined");return this._yScale}},{key:"UNSAFE_componentWillMount",value:function(){this.pubSubs=[],this.pubSubs.push(this.props.pubSub.subscribe("scroll",this.windowScrolledBound)),this.pubSubs.push(this.props.pubSub.subscribe("app.event",this.dispatchEventBound)),this.pubSubs.push(this.props.pubSub.subscribe("zoomToDataPos",this.zoomToDataPosHandlerBound)),this.pubSubs.push(this.props.pubSub.subscribe("app.scroll",this.onScrollHandlerBound))}},{key:"componentDidMount",value:function(){if(!this.element)throw new Error("Component did not mount, this.element is not defined.");if(this.elementPos=this.element.getBoundingClientRect(),this.elementSelection=pg(this.element),this.pStage=new Ct.PIXI.Graphics,this.pMask=new Ct.PIXI.Graphics,this.pOutline=new Ct.PIXI.Graphics,this.pBackground=new Ct.PIXI.Graphics,this.pStage.addChild(this.pMask),this.pStage.addChild(this.pOutline),this.currentProps.pixiStage.addChild(this.pStage),this.pStage.mask=this.pMask,this.props.isRangeSelection||this.addZoom(),!this.currentProps.svgElement||!this.currentProps.canvasElement)return;this.svgElement=this.currentProps.svgElement,this.syncTrackObjects(this.currentProps.positionedTracks),this.syncMetaTracks(this.currentProps.metaTracks),this.currentProps.setCentersFunction(this.setCenter.bind(this)),this.currentProps.registerDraggingChangedListener(this.draggingChanged.bind(this)),this.draggingChanged(!0),this.addEventTracker();const n=[[this.xScale(this.xDomainLimits[0]),this.yScale(this.yDomainLimits[0])],[this.xScale(this.xDomainLimits[1]),this.yScale(this.yDomainLimits[1])]],C=this.svgElement.getBoundingClientRect(),r=[[Math.max(n[0][0],0),Math.max(n[0][1],0)],[Math.min(n[1][0],C.width),Math.min(n[1][1],C.height)]];this.zoomBehavior.extent(r).translateExtent(n).scaleExtent(this.zoomLimits)}},{key:"UNSAFE_componentWillReceiveProps",value:function(n){if(!n.svgElement||!n.canvasElement)return;const C=this.updatablePropsToString(n);if(this.currentProps=n,this.prevPropsStr===C)return;this.setBackground();for(const s in this.trackDefObjects){const a=this.trackDefObjects[s].trackObject;a.delayDrawing=!0}this.prevPropsStr=C,this.setUpInitialScales(n.initialXDomain,n.initialYDomain,n.xDomainLimits,n.yDomainLimits,n.zoomLimits),this.setUpScales(n.width!==this.props.width||n.height!==this.props.height),this.svgElement=n.svgElement;const r=[[this.xScale(this.xDomainLimits[0]),this.yScale(this.yDomainLimits[0])],[this.xScale(this.xDomainLimits[1]),this.yScale(this.yDomainLimits[1])]],o=this.svgElement.getBoundingClientRect(),A=[[Math.max(r[0][0],0),Math.max(r[0][1],0)],[Math.min(r[1][0],o.width),Math.min(r[1][1],o.height)]];this.zoomBehavior.extent(A).translateExtent(r).scaleExtent(this.zoomLimits),this.syncTrackObjects(n.positionedTracks),this.syncMetaTracks(n.metaTracks);for(const s of n.positionedTracks){const a=s.track.options,l=this.trackDefObjects[s.track.uid].trackObject;if(l.rerender(a),nW(s.track)){const c={};for(const u of s.track.contents)c[u.uid]=u;for(const u in l.createdTracks)l.createdTracks[u].rerender(c[u].options)}}this.props.onNewTilesLoaded();for(const s in this.trackDefObjects){const a=this.trackDefObjects[s].trackObject;a.delayDrawing=!1,a.draw()}}},{key:"componentDidUpdate",value:function(n){(this.props.initialXDomain[0]!==n.initialXDomain[0]||this.props.initialXDomain[1]!==n.initialXDomain[1]||this.props.initialYDomain[0]!==n.initialYDomain[0]||this.props.initialYDomain[1]!==n.initialYDomain[1])&&this.element&&(this.element.__zoom=Fi),n.isRangeSelection!==this.props.isRangeSelection&&(this.props.isRangeSelection?this.removeZoom():this.addZoom()),n.zoomable!==this.props.zoomable&&(this.props.zoomable?this.addZoom():this.removeZoom()),this.addEventTracker()}},{key:"componentWillUnmount",value:function(){var n,C;this.mounted=!1,this.removeTracks(Object.keys(this.trackDefObjects)),this.removeMetaTracks(Object.keys(this.metaTracks)),this.currentProps.removeDraggingChangedListener(this.draggingChanged),this.pStage&&this.currentProps.pixiStage.removeChild(this.pStage),(n=this.pMask)==null||n.destroy(!0),(C=this.pStage)==null||C.destroy(!0),this.pubSubs.forEach(r=>this.props.pubSub.unsubscribe(r)),this.pubSubs=[],this.removeEventTracker()}},{key:"dispatchEvent",value:function(n){n.sourceUid===this.uid&&n.type!=="contextmenu"&&this.element&&J9(n,this.element)}},{key:"isWithin",value:function(n,C){const r=n>=this.elementPos.left&&n<=this.elementPos.width+this.elementPos.left,o=C>=this.elementPos.top&&C<=this.elementPos.height+this.elementPos.top;return r&&o}},{key:"zoomToDataPosHandler",value:function({pos:n,animateTime:C}){this.zoomToDataPos(...n,C)}},{key:"addZoom",value:function(){!this.elementSelection||!this.currentProps.zoomable||(this.elementSelection.call(this.zoomBehavior),this.zoomBehavior.transform(this.elementSelection,this.zoomTransform))}},{key:"removeZoom",value:function(){this.elementSelection&&(this.zoomEnded(),this.elementSelection.on(".zoom",null))}},{key:"setMask",value:function(){var n,C,r,o;(n=this.pMask)==null||n.clear(),(C=this.pMask)==null||C.beginFill(),(r=this.pMask)==null||r.drawRect(this.xPositionOffset,this.yPositionOffset,this.currentProps.width,this.currentProps.height),(o=this.pMask)==null||o.endFill()}},{key:"setBackground",value:function(){var n,C,r,o,A;const s=this.props.theme===II?"black":"white",a=zt(((n=this.currentProps.viewOptions)==null?void 0:n.backgroundColor)??s);(C=this.pBackground)==null||C.clear(),(r=this.pBackground)==null||r.beginFill(a),(o=this.pBackground)==null||o.drawRect(this.xPositionOffset,this.yPositionOffset,this.currentProps.width,this.currentProps.height),(A=this.pBackground)==null||A.endFill()}},{key:"windowScrolled",value:function(){this.removeZoom(),this.scrollTimeout&&clearTimeout(this.scrollTimeout),this.scrollTimeout=setTimeout(()=>{this.addZoom()},xUt)}},{key:"setUpInitialScales",value:function(n=[0,1],C=[0,1],r=[-Number.MAX_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],o=[-Number.MAX_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],A=[0,Number.MAX_SAFE_INTEGER]){A[0]=A[0]===null?0:A[0],A[1]=A[1]===null?1/0:A[1];const s=n[1]-n[0],a=(C[0]+C[1])/2;if(C[0]=a-s/2,C[1]=a+s/2,n[0]===this.initialXDomain[0]&&n[1]===this.initialXDomain[1]&&C[0]===this.initialYDomain[0]&&C[1]===this.initialYDomain[1]&&r[0]===this.xDomainLimits[0]&&r[1]===this.xDomainLimits[1]&&o[0]===this.yDomainLimits[0]&&o[1]===this.yDomainLimits[1]&&A[0]===this.zoomLimits[0]&&A[1]===this.zoomLimits[1])return;this.initialXDomain=n,this.initialYDomain=C,this.xDomainLimits=r,this.yDomainLimits=o,this.zoomLimits=A,this.zoomTransform=Fi,this.prevZoomTransform=Fi,this.cumCenterYOffset=0,this.cumCenterXOffset=0,this.drawableToDomainX=Cg().domain([this.currentProps.paddingLeft+this.currentProps.leftWidth,this.currentProps.paddingLeft+this.currentProps.leftWidth+this.currentProps.centerWidth]).range([n[0],n[1]]);let l,c;this.currentProps.centerWidth===0?(l=this.currentProps.paddingTop+this.currentProps.topHeight,c=this.currentProps.paddingTop+this.currentProps.topHeight+this.currentProps.centerHeight):(l=this.currentProps.paddingTop+this.currentProps.topHeight+this.currentProps.centerHeight/2-this.currentProps.centerWidth/2,c=this.currentProps.paddingTop+this.currentProps.topHeight+this.currentProps.centerHeight/2+this.currentProps.centerWidth/2),this.drawableToDomainY=Cg().domain([l,c]).range([C[0],C[1]]),this.prevCenterX=this.currentProps.paddingLeft+this.currentProps.leftWidth+this.currentProps.centerWidth/2,this.prevCenterY=this.currentProps.paddingTop+this.currentProps.topHeight+this.currentProps.centerHeight/2}},{key:"updatablePropsToString",value:function(n){return JSON.stringify({positionedTracks:n.positionedTracks,initialXDomain:n.initialXDomain,initialYDomain:n.initialYDomain,width:n.width,height:n.height,paddingLeft:n.paddingLeft,paddingTop:n.paddingTop,leftWidth:n.leftWidth,topHeight:n.topHeight,dragging:n.dragging,viewOptions:n.viewOptions})}},{key:"draggingChanged",value:function(n){this.dragging=n,this.timedUpdatePositionAndDimensions()}},{key:"setUpScales",value:function(n=!1){const C=this.currentProps.paddingLeft+this.currentProps.leftWidth+this.currentProps.centerWidth/2,r=this.currentProps.paddingTop+this.currentProps.topHeight+this.currentProps.centerHeight/2;if(!this.drawableToDomainX||!this.drawableToDomainY)return;const o=(this.drawableToDomainX(C)-this.drawableToDomainX(this.prevCenterX))/this.zoomTransform.k,A=(this.drawableToDomainY(r)-this.drawableToDomainY(this.prevCenterY))/this.zoomTransform.k;this.cumCenterYOffset+=A,this.cumCenterXOffset+=o,this.prevCenterY=r,this.prevCenterX=C;const s=[this.drawableToDomainX(0)-this.cumCenterXOffset,this.drawableToDomainX(this.currentProps.width)-this.cumCenterXOffset],a=[this.drawableToDomainY(0)-this.cumCenterYOffset,this.drawableToDomainY(this.currentProps.height)-this.cumCenterYOffset];this._xScale=Cg().domain(s).range([0,this.currentProps.width]),this._yScale=Cg().domain(a).range([0,this.currentProps.height]);for(const l in this.trackDefObjects)this.trackDefObjects[l].trackObject.refScalesChanged(this.xScale,this.yScale);this.applyZoomTransform(n)}},{key:"getTrackDef",value:function(n){const C=xr(this.trackDefObjects);for(const[,{trackDef:r,trackObject:o}]of C){if(o===n)return r.track;if(nW(r.track)){for(const A of r.track.contents)if(o.createdTracks[A.uid]===n)return A}}return null}},{key:"getTrackObject",value:function(n){const C=xr(this.trackDefObjects);for(let r=0;ro.uid));this.addMetaTracks(n.filter(o=>!this.metaTracks[o.uid])),this.updateMetaTracks(n.filter(o=>this.metaTracks[o.uid])),this.removeMetaTracks(C.filter(o=>!r.has(o)))}},{key:"syncTrackObjects",value:function(n){this.prevTrackDefinitions=JSON.stringify(n);const C={};for(let l=0;l!r.has(l))),s=new Set([...r].filter(l=>!o.has(l))),a=new Set([...o].filter(l=>r.has(l)));this.updateExistingTrackDefs([...a].map(l=>C[l])),this.addNewTracks([...A].map(l=>C[l])),this.updateExistingTrackDefs([...A].map(l=>C[l])),this.removeTracks([...s])}},{key:"addMetaTracks",value:function(n){n.filter(C=>!this.metaTracks[C.uid]).forEach(C=>{this.metaTracks[C.uid]={trackDef:C,trackObject:this.createMetaTrack(C)}})}},{key:"addNewTracks",value:function(n){if(this.currentProps.pixiStage){for(let C=0;C{this.metaTracks[C].trackObject.remove(),this.metaTracks[C]=void 0,delete this.metaTracks[C]})}},{key:"removeTracks",value:function(n){for(let C=0;C{const p=Fi.translate(h,m).scale(c);this.zoomTransform=p,this.elementSelection&&this.emptyZoomBehavior.transform(this.elementSelection,p),f=this.applyZoomTransform(o)};if(A&&this.elementSelection){let p=this.elementSelection;this.activeTransitions+=1,document.hidden||(p=p.transition().duration(A)),p.call(this.zoomBehavior.transform,Fi.translate(h,m).scale(c)).on("end",()=>{b(),this.activeTransitions-=1})}else b();return f}},{key:"valueScaleMove",value:function(n){if(this.zoomStartPos){for(const C of this.getTracksAtPosition(...this.zoomStartPos))C.movedY(n);this.zoomStartTransform&&(this.zoomTransform=this.zoomStartTransform)}}},{key:"valueScaleZoom",value:function(n,C){if(!LAt(n.sourceEvent))return;const r=n.sourceEvent.deltaY,o=n.sourceEvent.deltaMode,s=((l,c)=>l*(c?120:1)/500)(r,o),a=Og(n.sourceEvent,this.props.canvasElement);for(const l of this.getTracksAtPosition(...a)){const c=C==="1d-horizontal"?a[1]-l.position[1]:a[0]-l.position[0];l.zoomedY(c,2**s)}this.zoomStartTransform&&(this.zoomTransform=this.zoomStartTransform)}},{key:"zoomed",value:function(n){var C;let r=null;if(this.zoomStartPos){const A=this.getTracksAtPosition(...this.zoomStartPos);if(A.length){const s=A[0],a=this.getTrackDef(s);if(!a)return;(C=$g[a.type])!=null&&C.orientation&&(r=$g[a.type].orientation),s instanceof Goe&&(r="1d-vertical")}}if(r&&n.sourceEvent){if(n.shiftKey||this.valueScaleZooming){if(n.sourceEvent.deltaY!==void 0){this.valueScaleZoom(n,r);return}r==="1d-horizontal"?this.valueScaleMove(n.sourceEvent.movementY):r==="1d-vertical"&&this.valueScaleMove(n.sourceEvent.movementX)}r==="1d-horizontal"&&n.sourceEvent.movementY?this.valueScaleMove(n.sourceEvent.movementY):r==="1d-vertical"&&n.sourceEvent.movementX&&this.valueScaleMove(n.sourceEvent.movementX)}this.zoomTransform=this.currentProps.zoomable?n.transform:Fi,this.prevZoomTransform.k!==this.zoomTransform.k||(r==="1d-horizontal"?this.zoomTransform=Fi.translate(this.zoomTransform.x,this.prevZoomTransform.y).scale(this.zoomTransform.k):r==="1d-vertical"&&(this.zoomTransform=Fi.translate(this.prevZoomTransform.x,this.zoomTransform.y).scale(this.zoomTransform.k)),this.element&&(this.element.__zoom=this.zoomTransform)),this.applyZoomTransform(!0),this.prevZoomTransform=this.zoomTransform,this.props.pubSub.publish("app.zoom",n),n.sourceEvent&&(n.sourceEvent.stopPropagation(),n.sourceEvent.preventDefault())}},{key:"getTracksAtPosition",value:function(n,C){const r=[];let o=[];for(const A in this.trackDefObjects){const s=this.trackDefObjects[A].trackObject;s.childTracks?o=o.concat(s.childTracks):o.push(s)}for(const A of o){const s=A.position[0]<=n&&n<=A.position[0]+A.dimensions[0],a=A.position[1]<=C&&C<=A.position[1]+A.dimensions[1];s&&a&&r.push(A)}return r}},{key:"zoomStarted",value:function(n){this.zooming=!0,n&&n.sourceEvent&&(this.zoomStartPos=Og(n.sourceEvent,this.props.canvasElement),n.sourceEvent.shiftKey&&(this.valueScaleZooming=!0)),this.zoomStartTransform=this.zoomTransform,this.props.pubSub.publish("app.zoomStart")}},{key:"zoomEnded",value:function(){this.zooming=!1,this.zoomStartPos=null,this.valueScaleZooming&&(this.valueScaleZooming=!1,this.element&&(this.element.__zoom=this.zoomStartTransform)),this.props.pubSub.publish("app.zoomEnd")}},{key:"applyZoomTransform",value:function(n=!0){const C=this.currentProps,r=C.paddingLeft+C.leftWidth,o=C.paddingTop+C.topHeight;if(!this.xScale||!this.yScale)return;this.zoomedXScale=this.zoomTransform.rescaleX(this.xScale),this.zoomedYScale=this.zoomTransform.rescaleY(this.yScale);const A=Cg().domain([r,r+C.centerWidth].map(this.zoomedXScale.invert)).range([0,C.centerWidth]),s=Cg().domain([o,o+C.centerHeight].map(this.zoomedYScale.invert)).range([0,C.centerHeight]);for(const a in this.trackDefObjects){const l=this.trackDefObjects[a].trackObject,c=this.trackDefObjects[a].trackDef;let u="unknown";if($g[c.track.type]&&(u=$g[c.track.type].orientation),u==="whole"){const d=Cg().domain([C.paddingLeft,C.width-C.paddingLeft].map(this.zoomedXScale.invert)).range([0,C.width-2*C.paddingLeft]),h=Cg().domain([C.paddingTop,C.height-C.paddingTop].map(this.zoomedYScale.invert)).range([0,C.height-2*C.paddingTop]);l.zoomed(d,h);continue}if(this.trackDefObjects[a].trackDef.track.position==="gallery"){const d=Cg().domain([C.paddingLeft+C.leftWidthNoGallery,C.paddingLeft+C.leftWidth+C.centerWidth+C.galleryDim].map(this.zoomedXScale.invert)).range([0,C.centerWidth+2*C.galleryDim]),h=Cg().domain([C.paddingTop+C.topHeightNoGallery,C.paddingTop+C.topHeight+C.centerHeight+C.galleryDim].map(this.zoomedYScale.invert)).range([0,C.centerHeight-2*C.galleryDim]);l.zoomed(d.copy(),h.copy(),this.zoomTransform.k);continue}l.zoomed(A.copy(),s.copy(),this.zoomTransform.k,this.zoomTransform.x+this.xPositionOffset,this.zoomTransform.y+this.yPositionOffset,C.paddingLeft+C.leftWidth,C.paddingTop+C.topHeight)}return this.currentXScale=A,this.currentYScale=s,n&&this.currentProps.onScalesChanged(A,s),[A,s]}},{key:"createMetaTrack",value:function(n){switch(n.type){default:{const C=this.props.pluginTracks[n.type];if(C!=null&&C.isMetaTrack){const r={getTrackObject:this.getTrackObject.bind(this),onNewTilesLoaded:()=>{this.currentProps.onNewTilesLoaded(n.uid)},definition:n};try{return new C.track(this.availableForPlugins,r,n.options)}catch(o){console.error("Plugin meta track",n.type,"failed to instantiate.",o)}}return console.warn(`Unknown meta track of type: ${n.type}`),new Poe(this.pStage,{name:"Unknown Track Type",type:n.type})}}}},{key:"createTrackObject",value:function(n){const C=this.createLocationAgnosticTrackObject(n);return(n.position==="left"||n.position==="right")&&$g[n.type].orientation==="1d-horizontal"?new Goe(C):C}},{key:"createLocationAgnosticTrackObject",value:function(n){let C=n.data;C||(C={server:qN(n.server),tilesetUid:n.tilesetUid}),n.coordSystem&&(C.coordSystem=n.coordSystem);const r=KUt(C,this.props.pubSub,this.props.pluginDataFetchers,this.availableForPlugins);if(!this.pStage||!this.svgElement)throw new Error("No PIXI stage or svg element");const o={id:n.uid,trackUid:n.uid,trackType:n.type,viewUid:this.viewUid,pubSub:this.props.pubSub,scene:this.pStage,dataConfig:C,dataFetcher:r,getLockGroupExtrema:()=>this.currentProps.getLockGroupExtrema(n.uid),handleTilesetInfoReceived:A=>{this.currentProps.onTilesetInfoReceived(n.uid,A)},animate:()=>{this.currentProps.onNewTilesLoaded(n.uid)},svgElement:this.svgElement,isValueScaleLocked:()=>this.currentProps.isValueScaleLocked(n.uid),onValueScaleChanged:()=>{this.currentProps.onValueScaleChanged(n.uid)},onTrackOptionsChanged:A=>{this.currentProps.onTrackOptionsChanged(n.uid,A)},onMouseMoveZoom:this.props.onMouseMoveZoom,chromInfoPath:n.chromInfoPath,isShowGlobalMousePosition:()=>this.props.isShowGlobalMousePosition,getTheme:()=>this.props.theme};switch(n.y&&(o.yPosition=n.y),n.x&&(o.xPosition=n.x),n.projectionXDomain&&(o.projectionXDomain=n.projectionXDomain),n.projectionYDomain&&(o.projectionYDomain=n.projectionYDomain),n.type){case"left-axis":return new jRe(o,n.options);case"top-axis":return new QRe(o,n.options);case"heatmap":return new Rw(o,n.options);case"multivec":case"vector-heatmap":case"horizontal-multivec":case"horizontal-vector-heatmap":case"vertical-multivec":case"vertical-vector-heatmap":return new X1e(o,n.options);case"1d-heatmap":case"horizontal-1d-heatmap":case"vertical-1d-heatmap":return new T1e(o,n.options);case"line":case"horizontal-line":case"vertical-line":return new cy(o,n.options);case"point":case"horizontal-point":case"vertical-point":return new W1e(o,n.options);case"bar":case"horizontal-bar":case"vertical-bar":return new I4(o,n.options);case"divergent-bar":case"horizontal-divergent-bar":case"vertical-divergent-bar":return new H1e(o,n.options);case"horizontal-1d-tiles":return new JRe(o,n.options);case"vertical-1d-tiles":return new LRe(o,n.options);case"2d-tiles":return new zRe(o,n.options);case"stacked-interval":case"top-stacked-interval":case"left-stacked-interval":return new N1e(o,n.options);case"viewport-projection-center":return n.registerViewportChanged&&n.removeViewportChanged&&n.setDomainsCallback?(o.registerViewportChanged=n.registerViewportChanged,o.removeViewportChanged=n.removeViewportChanged,o.setDomainsCallback=n.setDomainsCallback,new _1e(o,n.options)):new $p(o,{});case"viewport-projection-horizontal":return n.registerViewportChanged&&n.removeViewportChanged&&n.setDomainsCallback?(o.registerViewportChanged=n.registerViewportChanged,o.removeViewportChanged=n.removeViewportChanged,o.setDomainsCallback=n.setDomainsCallback,new U1e(o,n.options)):new $p(o,{});case"viewport-projection-vertical":return n.registerViewportChanged&&n.removeViewportChanged&&n.setDomainsCallback?(o.registerViewportChanged=n.registerViewportChanged,o.removeViewportChanged=n.removeViewportChanged,o.setDomainsCallback=n.setDomainsCallback,new Q1e(o,n.options)):new $p(o,{});case"gene-annotations":case"horizontal-gene-annotations":case"vertical-gene-annotations":return new k1e(o,n.options);case"2d-rectangle-domains":case"arrowhead-domains":return new Y1e(o,n.options);case"horizontal-1d-annotations":return new DP(o,n.options);case"vertical-1d-annotations":return new DP(o,n.options,!0);case"2d-annotations":return new x1e(o,n.options);case"linear-2d-rectangle-domains":case"horizontal-2d-rectangle-domains":case"vertical-2d-rectangle-domains":return new D1e(o,n.options);case"square-markers":return new F1e(o,n.options);case"combined":return o.tracks=n.contents,o.createTrackObject=this.createTrackObject.bind(this),new VQ(o);case"2d-chromosome-labels":return new E1e(o,n.options);case"horizontal-chromosome-grid":return o.orientation="1d-horizontal",new cG(o,n.options);case"vertical-chromosome-grid":return o.orientation="1d-vertical",new cG(o,n.options);case"2d-chromosome-grid":return new cG(o,n.options);case"chromosome-labels":case"horizontal-chromosome-labels":case"vertical-chromosome-labels":return new P1e(o,n.options);case"linear-heatmap":case"horizontal-heatmap":case"vertical-heatmap":return new J1e(o,n.options);case"2d-chromosome-annotations":return new M1e(o,n.options);case"1d-value-interval":case"horizontal-1d-value-interval":case"vertical-1d-value-interval":return new L1e(o,n.options);case"osm":case"osm-tiles":return new Xw(o,n.options);case"osm-2d-tile-ids":return new lWe(o,n.options);case"mapbox":case"mapbox-tiles":return new cWe(o,n.options);case"raster-tiles":return new uWe(o,n.options);case"bedlike":case"vertical-bedlike":return new V1e(o,n.options);case"overlay-track":return new R1e(o,n.options);case"overlay-chromosome-grid-track":return o.isOverlay=!0,new cG(o,n.options);case"horizontal-rule":return new IWe(o,n.options);case"vertical-rule":return new AWe(o,n.options);case"cross-rule":return o.x=n.x,o.y=n.y,new aWe(o,n.options);case"simple-svg":return new vm(o,n.options);case"empty":{const A=n.options;return new dC(o,A)}default:{const A=this.props.pluginTracks[n.type];if(A&&!A.isMetaTrack){o.AVAILABLE_FOR_PLUGINS=this.availableForPlugins,o.baseEl=this.baseEl,o.definition=n,n.registerViewportChanged&&n.removeViewportChanged&&n.setDomainsCallback&&(o.registerViewportChanged=n.registerViewportChanged,o.removeViewportChanged=n.removeViewportChanged,o.setDomainsCallback=n.setDomainsCallback);try{return new A.track(this.availableForPlugins,o,n.options)}catch(s){console.error("Plugin track",n.type,"failed to instantiate.",s)}}return console.warn("Unknown track type:",n.type),new Poe(o,{name:"Unknown Track Type",type:n.type})}}}},{key:"zoomToDataPos",value:function(n,C,r,o,A=3e3,s=null){const[a,l,c]=Zi(this.xScale.copy().domain([n,C]),this.yScale.copy().domain([r,o])),u=s?s(this.xScale,this.yScale):[this.xScale,this.yScale];this.setCenter(a,l,c,!1,A,u[0],u[1])}},{key:"forwardContextMenu",value:function(n){this.props.disableTrackMenu||n.altKey||(n.preventDefault(),setTimeout(()=>{this.props.pubSub.publish("contextmenu",n)},0))}},{key:"addEventTracker",value:function(){!this.eventTracker||this.eventTracker===this.eventTrackerOld||(this.eventTrackerOld||(this.eventTrackerOld=this.eventTracker),this.eventTracker=this.eventTrackerOld,this.eventTracker.addEventListener("click",this.boundForwardEvent),this.eventTracker.addEventListener("contextmenu",this.boundForwardContextMenu),this.eventTracker.addEventListener("dblclick",this.boundForwardEvent),this.eventTracker.addEventListener("wheel",this.boundForwardEvent),this.eventTracker.addEventListener("dragstart",this.boundForwardEvent),this.eventTracker.addEventListener("selectstart",this.boundForwardEvent),this.eventTracker.addEventListener("mouseover",this.boundForwardEvent),this.eventTracker.addEventListener("mouseenter",this.boundForwardEvent),this.eventTracker.addEventListener("mousedown",this.boundForwardEvent),this.eventTracker.addEventListener("mouseup",this.boundForwardEvent),this.eventTracker.addEventListener("mouseout",this.boundForwardEvent),this.eventTracker.addEventListener("mouseleave",this.boundForwardEvent),this.eventTracker.addEventListener("touchstart",this.boundForwardEvent),this.eventTracker.addEventListener("touchend",this.boundForwardEvent),this.eventTracker.addEventListener("touchmove",this.boundForwardEvent),this.eventTracker.addEventListener("touchcancel",this.boundForwardEvent),this.eventTracker.addEventListener("pointerover",this.boundForwardEvent),this.eventTracker.addEventListener("pointerenter",this.boundForwardEvent),this.eventTracker.addEventListener("pointerdown",this.boundForwardEvent),this.eventTracker.addEventListener("pointerup",this.boundForwardEvent),this.eventTracker.addEventListener("pointercancel",this.boundForwardEvent),this.eventTracker.addEventListener("pointerout",this.boundForwardEvent),this.eventTracker.addEventListener("pointerleave",this.boundForwardEvent),window.addEventListener("scroll",this.boundScrollEvent))}},{key:"removeEventTracker",value:function(){this.eventTracker&&(this.eventTracker.removeEventListener("click",this.boundForwardEvent),this.eventTracker.removeEventListener("contextmenu",this.boundForwardContextMenu),this.eventTracker.removeEventListener("dblclick",this.boundForwardEvent),this.eventTracker.removeEventListener("wheel",this.boundForwardEvent),this.eventTracker.removeEventListener("dragstart",this.boundForwardEvent),this.eventTracker.removeEventListener("selectstart",this.boundForwardEvent),this.eventTracker.removeEventListener("mouseover",this.boundForwardEvent),this.eventTracker.removeEventListener("mouseenter",this.boundForwardEvent),this.eventTracker.removeEventListener("mousedown",this.boundForwardEvent),this.eventTracker.removeEventListener("mouseup",this.boundForwardEvent),this.eventTracker.removeEventListener("mouseout",this.boundForwardEvent),this.eventTracker.removeEventListener("mouseleave",this.boundForwardEvent),this.eventTracker.removeEventListener("touchstart",this.boundForwardEvent),this.eventTracker.removeEventListener("touchend",this.boundForwardEvent),this.eventTracker.removeEventListener("touchcancel",this.boundForwardEvent),this.eventTracker.removeEventListener("pointerover",this.boundForwardEvent),this.eventTracker.removeEventListener("pointerenter",this.boundForwardEvent),this.eventTracker.removeEventListener("pointerdown",this.boundForwardEvent),this.eventTracker.removeEventListener("pointerup",this.boundForwardEvent),this.eventTracker.removeEventListener("pointercancel",this.boundForwardEvent),this.eventTracker.removeEventListener("pointerout",this.boundForwardEvent),this.eventTracker.removeEventListener("pointerleave",this.boundForwardEvent),window.removeEventListener("scroll",this.boundScrollEvent))}},{key:"scrollEvent",value:function(){this.element&&(this.elementPos=this.element.getBoundingClientRect())}},{key:"forwardEvent",value:function(n){n.sourceUid=this.uid,n.forwarded=!0,this.props.pubSub.publish("app.event",n)}},{key:"onScrollHandler",value:function(n){this.scrollTop=n}},{key:"render",value:function(){return N.createElement("div",{ref:n=>{this.baseEl=n},className:Tg("track-renderer-div",BF["track-renderer"]),style:{height:this.currentProps.height,width:this.currentProps.width}},N.createElement("div",{ref:n=>{this.element=n},className:Tg("track-renderer-element",BF["track-renderer-element"])}),N.createElement("div",{ref:n=>{this.eventTracker=n},className:Tg("track-renderer-events",BF["track-renderer-events"])},this.currentProps.children))}}]),I}(N.Component);r$.defaultProps={pluginDataFetchers:{},pluginTracks:{},canvasElement:null,centerHeight:0,centerWidth:0,children:[],galleryDim:0,height:0,initialXDomain:[],initialYDomain:[],isShowGlobalMousePosition:!1,isRangeSelection:!1,leftWidth:0,leftWidthNoGallery:0,paddingLeft:0,paddingTop:0,positionedTracks:[],topHeight:0,topHeightNoGallery:0,width:0,metaTracks:[]};r$.propTypes={canvasElement:L.object,centerHeight:L.number,centerWidth:L.number,children:L.array,disableTrackMenu:L.bool,galleryDim:L.number,height:L.number,initialXDomain:L.array,initialYDomain:L.array,isShowGlobalMousePosition:L.bool,isRangeSelection:L.bool,leftWidth:L.number,leftWidthNoGallery:L.number,paddingLeft:L.number,paddingTop:L.number,metaTracks:L.array,onMouseMoveZoom:L.func,onNewTilesLoaded:L.func.isRequired,onScalesChanged:L.func.isRequired,pixiRenderer:L.object.isRequired,pixiStage:L.object.isRequired,pluginDataFetchers:L.object,pluginTracks:L.object,positionedTracks:L.array,pubSub:L.object.isRequired,setCentersFunction:L.func,svgElement:L.object.isRequired,theme:L.symbol.isRequired,topHeight:L.number,topHeightNoGallery:L.number,viewOptions:L.object,width:L.number,xDomainLimits:L.array,yDomainLimits:L.array,valueScaleZoom:L.bool,zoomable:L.bool.isRequired,zoomDomain:L.array,uid:L.string,zoomLimits:L.array};const DUt=ry(ym(r$));var a9e={exports:{}};/*! react-checkbox-tree - v1.8.0 | 2022 */(function(g,e){/*! For license information please see index.browser.js.LICENSE.txt */(function(I,i){g.exports=i(N)})(self,I=>(()=>{var i={4184:(o,A)=>{var s;(function(){var a={}.hasOwnProperty;function l(){for(var c=[],u=0;u{var a=s(852)(s(5639),"DataView");o.exports=a},1989:(o,A,s)=>{var a=s(1789),l=s(401),c=s(7667),u=s(1327),d=s(1866);function h(m){var f=-1,b=m==null?0:m.length;for(this.clear();++f{var a=s(7040),l=s(4125),c=s(2117),u=s(7518),d=s(4705);function h(m){var f=-1,b=m==null?0:m.length;for(this.clear();++f{var a=s(852)(s(5639),"Map");o.exports=a},3369:(o,A,s)=>{var a=s(4785),l=s(1285),c=s(6e3),u=s(9916),d=s(5265);function h(m){var f=-1,b=m==null?0:m.length;for(this.clear();++f{var a=s(852)(s(5639),"Promise");o.exports=a},8525:(o,A,s)=>{var a=s(852)(s(5639),"Set");o.exports=a},8668:(o,A,s)=>{var a=s(3369),l=s(619),c=s(2385);function u(d){var h=-1,m=d==null?0:d.length;for(this.__data__=new a;++h{var a=s(8407),l=s(7465),c=s(3779),u=s(7599),d=s(4758),h=s(4309);function m(f){var b=this.__data__=new a(f);this.size=b.size}m.prototype.clear=l,m.prototype.delete=c,m.prototype.get=u,m.prototype.has=d,m.prototype.set=h,o.exports=m},2705:(o,A,s)=>{var a=s(5639).Symbol;o.exports=a},1149:(o,A,s)=>{var a=s(5639).Uint8Array;o.exports=a},577:(o,A,s)=>{var a=s(852)(s(5639),"WeakMap");o.exports=a},4963:o=>{o.exports=function(A,s){for(var a=-1,l=A==null?0:A.length,c=0,u=[];++a{var a=s(2545),l=s(5694),c=s(1469),u=s(4144),d=s(5776),h=s(6719),m=Object.prototype.hasOwnProperty;o.exports=function(f,b){var p=c(f),y=!p&&l(f),Z=!p&&!y&&u(f),v=!p&&!y&&!Z&&h(f),G=p||y||Z||v,B=G?a(f.length,String):[],w=B.length;for(var R in f)!b&&!m.call(f,R)||G&&(R=="length"||Z&&(R=="offset"||R=="parent")||v&&(R=="buffer"||R=="byteLength"||R=="byteOffset")||d(R,w))||B.push(R);return B}},2488:o=>{o.exports=function(A,s){for(var a=-1,l=s.length,c=A.length;++a{o.exports=function(A,s){for(var a=-1,l=A==null?0:A.length;++a{var a=s(7813);o.exports=function(l,c){for(var u=l.length;u--;)if(a(l[u][0],c))return u;return-1}},8866:(o,A,s)=>{var a=s(2488),l=s(1469);o.exports=function(c,u,d){var h=u(c);return l(c)?h:a(h,d(c))}},4239:(o,A,s)=>{var a=s(2705),l=s(9607),c=s(2333),u=a?a.toStringTag:void 0;o.exports=function(d){return d==null?d===void 0?"[object Undefined]":"[object Null]":u&&u in Object(d)?l(d):c(d)}},9454:(o,A,s)=>{var a=s(4239),l=s(7005);o.exports=function(c){return l(c)&&a(c)=="[object Arguments]"}},939:(o,A,s)=>{var a=s(2492),l=s(7005);o.exports=function c(u,d,h,m,f){return u===d||(u==null||d==null||!l(u)&&!l(d)?u!=u&&d!=d:a(u,d,h,m,c,f))}},2492:(o,A,s)=>{var a=s(6384),l=s(7114),c=s(8351),u=s(6096),d=s(4160),h=s(1469),m=s(4144),f=s(6719),b="[object Arguments]",p="[object Array]",y="[object Object]",Z=Object.prototype.hasOwnProperty;o.exports=function(v,G,B,w,R,S){var X=h(v),W=h(G),V=X?p:d(v),H=W?p:d(G),D=(V=V==b?y:V)==y,Y=(H=H==b?y:H)==y,F=V==H;if(F&&m(v)){if(!m(G))return!1;X=!0,D=!1}if(F&&!D)return S||(S=new a),X||f(v)?l(v,G,B,w,R,S):c(v,G,V,B,w,R,S);if(!(1&B)){var _=D&&Z.call(v,"__wrapped__"),J=Y&&Z.call(G,"__wrapped__");if(_||J){var te=_?v.value():v,q=J?G.value():G;return S||(S=new a),R(te,q,B,w,S)}}return!!F&&(S||(S=new a),u(v,G,B,w,R,S))}},8458:(o,A,s)=>{var a=s(3560),l=s(5346),c=s(3218),u=s(346),d=/^\[object .+?Constructor\]$/,h=Function.prototype,m=Object.prototype,f=h.toString,b=m.hasOwnProperty,p=RegExp("^"+f.call(b).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");o.exports=function(y){return!(!c(y)||l(y))&&(a(y)?p:d).test(u(y))}},8749:(o,A,s)=>{var a=s(4239),l=s(1780),c=s(7005),u={};u["[object Float32Array]"]=u["[object Float64Array]"]=u["[object Int8Array]"]=u["[object Int16Array]"]=u["[object Int32Array]"]=u["[object Uint8Array]"]=u["[object Uint8ClampedArray]"]=u["[object Uint16Array]"]=u["[object Uint32Array]"]=!0,u["[object Arguments]"]=u["[object Array]"]=u["[object ArrayBuffer]"]=u["[object Boolean]"]=u["[object DataView]"]=u["[object Date]"]=u["[object Error]"]=u["[object Function]"]=u["[object Map]"]=u["[object Number]"]=u["[object Object]"]=u["[object RegExp]"]=u["[object Set]"]=u["[object String]"]=u["[object WeakMap]"]=!1,o.exports=function(d){return c(d)&&l(d.length)&&!!u[a(d)]}},280:(o,A,s)=>{var a=s(5726),l=s(6916),c=Object.prototype.hasOwnProperty;o.exports=function(u){if(!a(u))return l(u);var d=[];for(var h in Object(u))c.call(u,h)&&h!="constructor"&&d.push(h);return d}},2545:o=>{o.exports=function(A,s){for(var a=-1,l=Array(A);++a{o.exports=function(A){return function(s){return A(s)}}},4757:o=>{o.exports=function(A,s){return A.has(s)}},4429:(o,A,s)=>{var a=s(5639)["__core-js_shared__"];o.exports=a},7114:(o,A,s)=>{var a=s(8668),l=s(2908),c=s(4757);o.exports=function(u,d,h,m,f,b){var p=1&h,y=u.length,Z=d.length;if(y!=Z&&!(p&&Z>y))return!1;var v=b.get(u),G=b.get(d);if(v&&G)return v==d&&G==u;var B=-1,w=!0,R=2&h?new a:void 0;for(b.set(u,d),b.set(d,u);++B{var a=s(2705),l=s(1149),c=s(7813),u=s(7114),d=s(8776),h=s(1814),m=a?a.prototype:void 0,f=m?m.valueOf:void 0;o.exports=function(b,p,y,Z,v,G,B){switch(y){case"[object DataView]":if(b.byteLength!=p.byteLength||b.byteOffset!=p.byteOffset)return!1;b=b.buffer,p=p.buffer;case"[object ArrayBuffer]":return!(b.byteLength!=p.byteLength||!G(new l(b),new l(p)));case"[object Boolean]":case"[object Date]":case"[object Number]":return c(+b,+p);case"[object Error]":return b.name==p.name&&b.message==p.message;case"[object RegExp]":case"[object String]":return b==p+"";case"[object Map]":var w=d;case"[object Set]":var R=1&Z;if(w||(w=h),b.size!=p.size&&!R)return!1;var S=B.get(b);if(S)return S==p;Z|=2,B.set(b,p);var X=u(w(b),w(p),Z,v,G,B);return B.delete(b),X;case"[object Symbol]":if(f)return f.call(b)==f.call(p)}return!1}},6096:(o,A,s)=>{var a=s(8234),l=Object.prototype.hasOwnProperty;o.exports=function(c,u,d,h,m,f){var b=1&d,p=a(c),y=p.length;if(y!=a(u).length&&!b)return!1;for(var Z=y;Z--;){var v=p[Z];if(!(b?v in u:l.call(u,v)))return!1}var G=f.get(c),B=f.get(u);if(G&&B)return G==u&&B==c;var w=!0;f.set(c,u),f.set(u,c);for(var R=b;++Z{var a=typeof s.g=="object"&&s.g&&s.g.Object===Object&&s.g;o.exports=a},8234:(o,A,s)=>{var a=s(8866),l=s(9551),c=s(3674);o.exports=function(u){return a(u,c,l)}},5050:(o,A,s)=>{var a=s(7019);o.exports=function(l,c){var u=l.__data__;return a(c)?u[typeof c=="string"?"string":"hash"]:u.map}},852:(o,A,s)=>{var a=s(8458),l=s(7801);o.exports=function(c,u){var d=l(c,u);return a(d)?d:void 0}},9607:(o,A,s)=>{var a=s(2705),l=Object.prototype,c=l.hasOwnProperty,u=l.toString,d=a?a.toStringTag:void 0;o.exports=function(h){var m=c.call(h,d),f=h[d];try{h[d]=void 0;var b=!0}catch{}var p=u.call(h);return b&&(m?h[d]=f:delete h[d]),p}},9551:(o,A,s)=>{var a=s(4963),l=s(479),c=Object.prototype.propertyIsEnumerable,u=Object.getOwnPropertySymbols,d=u?function(h){return h==null?[]:(h=Object(h),a(u(h),function(m){return c.call(h,m)}))}:l;o.exports=d},4160:(o,A,s)=>{var a=s(8552),l=s(7071),c=s(3818),u=s(8525),d=s(577),h=s(4239),m=s(346),f="[object Map]",b="[object Promise]",p="[object Set]",y="[object WeakMap]",Z="[object DataView]",v=m(a),G=m(l),B=m(c),w=m(u),R=m(d),S=h;(a&&S(new a(new ArrayBuffer(1)))!=Z||l&&S(new l)!=f||c&&S(c.resolve())!=b||u&&S(new u)!=p||d&&S(new d)!=y)&&(S=function(X){var W=h(X),V=W=="[object Object]"?X.constructor:void 0,H=V?m(V):"";if(H)switch(H){case v:return Z;case G:return f;case B:return b;case w:return p;case R:return y}return W}),o.exports=S},7801:o=>{o.exports=function(A,s){return A==null?void 0:A[s]}},1789:(o,A,s)=>{var a=s(4536);o.exports=function(){this.__data__=a?a(null):{},this.size=0}},401:o=>{o.exports=function(A){var s=this.has(A)&&delete this.__data__[A];return this.size-=s?1:0,s}},7667:(o,A,s)=>{var a=s(4536),l=Object.prototype.hasOwnProperty;o.exports=function(c){var u=this.__data__;if(a){var d=u[c];return d==="__lodash_hash_undefined__"?void 0:d}return l.call(u,c)?u[c]:void 0}},1327:(o,A,s)=>{var a=s(4536),l=Object.prototype.hasOwnProperty;o.exports=function(c){var u=this.__data__;return a?u[c]!==void 0:l.call(u,c)}},1866:(o,A,s)=>{var a=s(4536);o.exports=function(l,c){var u=this.__data__;return this.size+=this.has(l)?0:1,u[l]=a&&c===void 0?"__lodash_hash_undefined__":c,this}},5776:o=>{var A=/^(?:0|[1-9]\d*)$/;o.exports=function(s,a){var l=typeof s;return!!(a=a??9007199254740991)&&(l=="number"||l!="symbol"&&A.test(s))&&s>-1&&s%1==0&&s{o.exports=function(A){var s=typeof A;return s=="string"||s=="number"||s=="symbol"||s=="boolean"?A!=="__proto__":A===null}},5346:(o,A,s)=>{var a,l=s(4429),c=(a=/[^.]+$/.exec(l&&l.keys&&l.keys.IE_PROTO||""))?"Symbol(src)_1."+a:"";o.exports=function(u){return!!c&&c in u}},5726:o=>{var A=Object.prototype;o.exports=function(s){var a=s&&s.constructor;return s===(typeof a=="function"&&a.prototype||A)}},7040:o=>{o.exports=function(){this.__data__=[],this.size=0}},4125:(o,A,s)=>{var a=s(8470),l=Array.prototype.splice;o.exports=function(c){var u=this.__data__,d=a(u,c);return!(d<0||(d==u.length-1?u.pop():l.call(u,d,1),--this.size,0))}},2117:(o,A,s)=>{var a=s(8470);o.exports=function(l){var c=this.__data__,u=a(c,l);return u<0?void 0:c[u][1]}},7518:(o,A,s)=>{var a=s(8470);o.exports=function(l){return a(this.__data__,l)>-1}},4705:(o,A,s)=>{var a=s(8470);o.exports=function(l,c){var u=this.__data__,d=a(u,l);return d<0?(++this.size,u.push([l,c])):u[d][1]=c,this}},4785:(o,A,s)=>{var a=s(1989),l=s(8407),c=s(7071);o.exports=function(){this.size=0,this.__data__={hash:new a,map:new(c||l),string:new a}}},1285:(o,A,s)=>{var a=s(5050);o.exports=function(l){var c=a(this,l).delete(l);return this.size-=c?1:0,c}},6e3:(o,A,s)=>{var a=s(5050);o.exports=function(l){return a(this,l).get(l)}},9916:(o,A,s)=>{var a=s(5050);o.exports=function(l){return a(this,l).has(l)}},5265:(o,A,s)=>{var a=s(5050);o.exports=function(l,c){var u=a(this,l),d=u.size;return u.set(l,c),this.size+=u.size==d?0:1,this}},8776:o=>{o.exports=function(A){var s=-1,a=Array(A.size);return A.forEach(function(l,c){a[++s]=[c,l]}),a}},4536:(o,A,s)=>{var a=s(852)(Object,"create");o.exports=a},6916:(o,A,s)=>{var a=s(5569)(Object.keys,Object);o.exports=a},1167:(o,A,s)=>{o=s.nmd(o);var a=s(1957),l=A&&!A.nodeType&&A,c=l&&o&&!o.nodeType&&o,u=c&&c.exports===l&&a.process,d=function(){try{return c&&c.require&&c.require("util").types||u&&u.binding&&u.binding("util")}catch{}}();o.exports=d},2333:o=>{var A=Object.prototype.toString;o.exports=function(s){return A.call(s)}},5569:o=>{o.exports=function(A,s){return function(a){return A(s(a))}}},5639:(o,A,s)=>{var a=s(1957),l=typeof self=="object"&&self&&self.Object===Object&&self,c=a||l||Function("return this")();o.exports=c},619:o=>{o.exports=function(A){return this.__data__.set(A,"__lodash_hash_undefined__"),this}},2385:o=>{o.exports=function(A){return this.__data__.has(A)}},1814:o=>{o.exports=function(A){var s=-1,a=Array(A.size);return A.forEach(function(l){a[++s]=l}),a}},7465:(o,A,s)=>{var a=s(8407);o.exports=function(){this.__data__=new a,this.size=0}},3779:o=>{o.exports=function(A){var s=this.__data__,a=s.delete(A);return this.size=s.size,a}},7599:o=>{o.exports=function(A){return this.__data__.get(A)}},4758:o=>{o.exports=function(A){return this.__data__.has(A)}},4309:(o,A,s)=>{var a=s(8407),l=s(7071),c=s(3369);o.exports=function(u,d){var h=this.__data__;if(h instanceof a){var m=h.__data__;if(!l||m.length<199)return m.push([u,d]),this.size=++h.size,this;h=this.__data__=new c(m)}return h.set(u,d),this.size=h.size,this}},346:o=>{var A=Function.prototype.toString;o.exports=function(s){if(s!=null){try{return A.call(s)}catch{}try{return s+""}catch{}}return""}},7813:o=>{o.exports=function(A,s){return A===s||A!=A&&s!=s}},5694:(o,A,s)=>{var a=s(9454),l=s(7005),c=Object.prototype,u=c.hasOwnProperty,d=c.propertyIsEnumerable,h=a(function(){return arguments}())?a:function(m){return l(m)&&u.call(m,"callee")&&!d.call(m,"callee")};o.exports=h},1469:o=>{var A=Array.isArray;o.exports=A},8612:(o,A,s)=>{var a=s(3560),l=s(1780);o.exports=function(c){return c!=null&&l(c.length)&&!a(c)}},4144:(o,A,s)=>{o=s.nmd(o);var a=s(5639),l=s(5062),c=A&&!A.nodeType&&A,u=c&&o&&!o.nodeType&&o,d=u&&u.exports===c?a.Buffer:void 0,h=(d?d.isBuffer:void 0)||l;o.exports=h},8446:(o,A,s)=>{var a=s(939);o.exports=function(l,c){return a(l,c)}},3560:(o,A,s)=>{var a=s(4239),l=s(3218);o.exports=function(c){if(!l(c))return!1;var u=a(c);return u=="[object Function]"||u=="[object GeneratorFunction]"||u=="[object AsyncFunction]"||u=="[object Proxy]"}},1780:o=>{o.exports=function(A){return typeof A=="number"&&A>-1&&A%1==0&&A<=9007199254740991}},3218:o=>{o.exports=function(A){var s=typeof A;return A!=null&&(s=="object"||s=="function")}},7005:o=>{o.exports=function(A){return A!=null&&typeof A=="object"}},6719:(o,A,s)=>{var a=s(8749),l=s(1717),c=s(1167),u=c&&c.isTypedArray,d=u?l(u):a;o.exports=d},3674:(o,A,s)=>{var a=s(4636),l=s(280),c=s(8612);o.exports=function(u){return c(u)?a(u):l(u)}},8306:(o,A,s)=>{var a=s(3369);function l(c,u){if(typeof c!="function"||u!=null&&typeof u!="function")throw new TypeError("Expected a function");var d=function(){var h=arguments,m=u?u.apply(this,h):h[0],f=d.cache;if(f.has(m))return f.get(m);var b=c.apply(this,h);return d.cache=f.set(m,b)||f,b};return d.cache=new(l.Cache||a),d}l.Cache=a,o.exports=l},479:o=>{o.exports=function(){return[]}},5062:o=>{o.exports=function(){return!1}},2703:(o,A,s)=>{var a=s(414);function l(){}function c(){}c.resetWarningCache=l,o.exports=function(){function u(m,f,b,p,y,Z){if(Z!==a){var v=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw v.name="Invariant Violation",v}}function d(){return u}u.isRequired=u;var h={array:u,bigint:u,bool:u,func:u,number:u,object:u,string:u,symbol:u,any:u,arrayOf:d,element:u,elementType:u,instanceOf:d,node:u,objectOf:d,oneOf:d,oneOfType:d,shape:d,exact:d,checkPropTypes:c,resetWarningCache:l};return h.PropTypes=h,h}},5697:(o,A,s)=>{o.exports=s(2703)()},414:o=>{o.exports="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"},9787:o=>{o.exports=I}},n={};function C(o){var A=n[o];if(A!==void 0)return A.exports;var s=n[o]={id:o,loaded:!1,exports:{}};return i[o](s,s.exports,C),s.loaded=!0,s.exports}C.n=o=>{var A=o&&o.__esModule?()=>o.default:()=>o;return C.d(A,{a:A}),A},C.d=(o,A)=>{for(var s in A)C.o(A,s)&&!C.o(o,s)&&Object.defineProperty(o,s,{enumerable:!0,get:A[s]})},C.g=function(){if(typeof globalThis=="object")return globalThis;try{return this||new Function("return this")()}catch{if(typeof window=="object")return window}}(),C.o=(o,A)=>Object.prototype.hasOwnProperty.call(o,A),C.r=o=>{typeof Symbol<"u"&&Symbol.toStringTag&&Object.defineProperty(o,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(o,"__esModule",{value:!0})},C.nmd=o=>(o.paths=[],o.children||(o.children=[]),o);var r={};return(()=>{C.r(r),C.d(r,{default:()=>Ne,expandNodesToLevel:()=>me});var o=C(4184),A=C.n(o),s=C(8446),a=C.n(s),l=C(8306),c=C.n(l);let u=(ue=21)=>crypto.getRandomValues(new Uint8Array(ue)).reduce((se,re)=>se+((re&=63)<36?re.toString(36):re<62?(re-26).toString(36).toUpperCase():re>62?"-":"_"),"");var d=C(5697),h=C.n(d),m=C(9787),f=C.n(m);function b(ue){return b=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(se){return typeof se}:function(se){return se&&typeof Symbol=="function"&&se.constructor===Symbol&&se!==Symbol.prototype?"symbol":typeof se},b(ue)}var p=["children","title"];function y(){return y=Object.assign?Object.assign.bind():function(ue){for(var se=1;se"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}(),function(){var Fe,He=w(oe);if(Se){var De=w(this).constructor;Fe=Reflect.construct(He,arguments,De)}else Fe=He.apply(this,arguments);return B(this,Fe)});function Ye(){return Z(this,Ye),Ke.apply(this,arguments)}return se=Ye,(re=[{key:"render",value:function(){var Fe=this.props,He=Fe.children,De=Fe.title,P=function(x,U){if(x==null)return{};var ce,de,Pe=function(ct,bt){if(ct==null)return{};var Ft,dt,Xt={},Ot=Object.keys(ct);for(dt=0;dt=0||(Xt[Ft]=ct[Ft]);return Xt}(x,U);if(Object.getOwnPropertySymbols){var Je=Object.getOwnPropertySymbols(x);for(de=0;de=0||Object.prototype.propertyIsEnumerable.call(x,ce)&&(Pe[ce]=x[ce])}return Pe}(Fe,p);return f().createElement("button",y({"aria-label":De,title:De,type:"button"},P),He)}}])&&v(se.prototype,re),Object.defineProperty(se,"prototype",{writable:!1}),Ye}(f().PureComponent);R(S,"propTypes",{children:h().node.isRequired,title:h().string}),R(S,"defaultProps",{title:null});const X=S,W={ALL:"all",PARENT:"parent",LEAF:"leaf"};function V(ue){this.message=ue,this.stack=Error().stack}V.prototype=Object.create(Error.prototype),V.prototype.name="CheckboxTreeError";const H=V;function D(ue,se){var re=Object.keys(ue);if(Object.getOwnPropertySymbols){var oe=Object.getOwnPropertySymbols(ue);se&&(oe=oe.filter(function(Se){return Object.getOwnPropertyDescriptor(ue,Se).enumerable})),re.push.apply(re,oe)}return re}function Y(ue,se,re){return se in ue?Object.defineProperty(ue,se,{value:re,enumerable:!0,configurable:!0,writable:!0}):ue[se]=re,ue}function F(ue,se){if(!(ue instanceof se))throw new TypeError("Cannot call a class as a function")}function _(ue,se){for(var re=0;re1&&arguments[1]!==void 0?arguments[1]:{};F(this,ue),this.props=oe,this.flatNodes=Se}var se,re;return se=ue,re=[{key:"setProps",value:function(oe){this.props=oe}},{key:"clone",value:function(){var oe=this,Se={};return Object.keys(this.flatNodes).forEach(function(Ke){var Ye=oe.flatNodes[Ke];Se[Ke]=function(Fe){for(var He=1;He1&&arguments[1]!==void 0?arguments[1]:{},Ye=arguments.length>2&&arguments[2]!==void 0?arguments[2]:0;if(Array.isArray(oe)&&oe.length!==0){var Fe=this.props,He=Fe.disabled,De=Fe.noCascade;oe.forEach(function(P,x){var U=Se.nodeHasChildren(P);if(Se.flatNodes[P.value]!==void 0)throw new H("Duplicate value '".concat(P.value,"' detected. All node values must be unique."));Se.flatNodes[P.value]={label:P.label,value:P.value,children:P.children,parent:Ke,isChild:Ke.value!==void 0,isParent:U,isLeaf:!U,showCheckbox:P.showCheckbox===void 0||P.showCheckbox,disabled:Se.getDisabledState(P,Ke,He,De),treeDepth:Ye,index:x},Se.flattenNodes(P.children,P,Ye+1)})}}},{key:"nodeHasChildren",value:function(oe){return Array.isArray(oe.children)}},{key:"getDisabledState",value:function(oe,Se,Ke,Ye){return!!Ke||!(Ye||!Se.disabled)||!!oe.disabled}},{key:"deserializeLists",value:function(oe){var Se=this,Ke=["checked","expanded"];Object.keys(this.flatNodes).forEach(function(Ye){Ke.forEach(function(Fe){Se.flatNodes[Ye][Fe]=!1})}),Ke.forEach(function(Ye){oe[Ye].forEach(function(Fe){Se.flatNodes[Fe]!==void 0&&(Se.flatNodes[Fe][Ye]=!0)})})}},{key:"serializeList",value:function(oe){var Se=this,Ke=[];return Object.keys(this.flatNodes).forEach(function(Ye){Se.flatNodes[Ye][oe]&&Ke.push(Ye)}),Ke}},{key:"expandAllNodes",value:function(oe){var Se=this;return Object.keys(this.flatNodes).forEach(function(Ke){Se.flatNodes[Ke].isParent&&(Se.flatNodes[Ke].expanded=oe)}),this}},{key:"toggleChecked",value:function(oe,Se,Ke,Ye){var Fe=this,He=!(arguments.length>4&&arguments[4]!==void 0)||arguments[4],De=this.flatNodes[oe.value],P=[J.PARENT,J.ALL].indexOf(Ke)>-1,x=[J.LEAF,J.ALL].indexOf(Ke)>-1;if(De.isLeaf||Ye){if(oe.disabled)return this;this.toggleNode(oe.value,"checked",Se)}else(P||De.children.length===0)&&this.toggleNode(oe.value,"checked",Se),x&&De.children.forEach(function(U){Fe.toggleChecked(U,Se,Ke,Ye,!1)});return He&&!Ye&&De.isChild&&P&&this.toggleParentStatus(De.parent,Ke),this}},{key:"toggleParentStatus",value:function(oe,Se){var Ke=this.flatNodes[oe.value];Ke.isChild?(Se===J.ALL&&this.toggleNode(oe.value,"checked",this.isEveryChildChecked(Ke)),this.toggleParentStatus(Ke.parent,Se)):this.toggleNode(oe.value,"checked",this.isEveryChildChecked(Ke))}},{key:"isEveryChildChecked",value:function(oe){var Se=this;return oe.children.every(function(Ke){return Se.getNode(Ke.value).checked})}},{key:"toggleNode",value:function(oe,Se,Ke){return this.flatNodes[oe][Se]=Ke,this}}],re&&_(se.prototype,re),Object.defineProperty(se,"prototype",{writable:!1}),ue}();function q(ue){return q=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(se){return typeof se}:function(se){return se&&typeof Symbol=="function"&&se.constructor===Symbol&&se!==Symbol.prototype?"symbol":typeof se},q(ue)}function $(){return $=Object.assign?Object.assign.bind():function(ue){for(var se=1;se"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}(),function(){var Fe,He=Ce(oe);if(Se){var De=Ce(this).constructor;Fe=Reflect.construct(He,arguments,De)}else Fe=He.apply(this,arguments);return fe(this,Fe)});function Ye(){return ee(this,Ye),Ke.apply(this,arguments)}return se=Ye,re=[{key:"componentDidMount",value:function(){this.updateDeterminateProperty()}},{key:"componentDidUpdate",value:function(){this.updateDeterminateProperty()}},{key:"updateDeterminateProperty",value:function(){var Fe=this.props.indeterminate;this.checkbox.indeterminate=Fe}},{key:"render",value:function(){var Fe=this,He=function(De){for(var P=1;P"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}(),function(){var Fe,He=At(oe);if(Se){var De=At(this).constructor;Fe=Reflect.construct(He,arguments,De)}else Fe=He.apply(this,arguments);return Ue(this,Fe)});function Ye(Fe){var He;return function(De,P){if(!(De instanceof P))throw new TypeError("Cannot call a class as a function")}(this,Ye),(He=Ke.call(this,Fe)).onCheck=He.onCheck.bind(_e(He)),He.onCheckboxKeyPress=He.onCheckboxKeyPress.bind(_e(He)),He.onCheckboxKeyUp=He.onCheckboxKeyUp.bind(_e(He)),He.onClick=He.onClick.bind(_e(He)),He.onExpand=He.onExpand.bind(_e(He)),He}return se=Ye,(re=[{key:"onCheck",value:function(){var Fe=this.props,He=Fe.value;(0,Fe.onCheck)({value:He,checked:this.getCheckState({toggle:!0})})}},{key:"onCheckboxKeyPress",value:function(Fe){Fe.which===32&&Fe.preventDefault()}},{key:"onCheckboxKeyUp",value:function(Fe){var He=Fe.keyCode;[13,32].includes(He)&&this.onCheck()}},{key:"onClick",value:function(){var Fe=this.props,He=Fe.expandOnClick,De=Fe.isParent,P=Fe.value,x=Fe.onClick;De&&He&&this.onExpand(),x({value:P,checked:this.getCheckState({toggle:!1})})}},{key:"onExpand",value:function(){var Fe=this.props,He=Fe.expanded,De=Fe.value;(0,Fe.onExpand)({value:De,expanded:!He})}},{key:"getCheckState",value:function(Fe){var He=Fe.toggle,De=this.props,P=De.checked,x=De.optimisticToggle;return!(P!==0||!He)||P===1&&!He||P===2&&x}},{key:"renderCollapseButton",value:function(){var Fe=this.props,He=Fe.expandDisabled,De=Fe.isLeaf,P=Fe.lang;return De?f().createElement("span",{className:"rct-collapse"},f().createElement("span",{className:"rct-icon"})):f().createElement(X,{className:"rct-collapse rct-collapse-btn",disabled:He,title:P.toggle,onClick:this.onExpand},this.renderCollapseIcon())}},{key:"renderCollapseIcon",value:function(){var Fe=this.props,He=Fe.expanded,De=Fe.icons,P=De.expandClose,x=De.expandOpen;return He?x:P}},{key:"renderCheckboxIcon",value:function(){var Fe=this.props,He=Fe.checked,De=Fe.icons,P=De.uncheck,x=De.check,U=De.halfCheck;return He===0?P:He===1?x:U}},{key:"renderNodeIcon",value:function(){var Fe=this.props,He=Fe.expanded,De=Fe.icon,P=Fe.icons,x=P.leaf,U=P.parentClose,ce=P.parentOpen,de=Fe.isLeaf;return De!==null?De:de?x:He?ce:U}},{key:"renderBareLabel",value:function(Fe){var He=this.props,De=He.onClick,P=He.title,x=De!==null;return f().createElement("span",{className:"rct-bare-label",title:P},x?f().createElement("span",{className:"rct-node-clickable",onClick:this.onClick,onKeyPress:this.onClick,role:"button",tabIndex:0},Fe):Fe)}},{key:"renderCheckboxLabel",value:function(Fe){var He=this.props,De=He.checked,P=He.disabled,x=He.title,U=He.treeId,ce=He.value,de=He.onClick!==null,Pe="".concat(U,"-").concat(String(ce).split(" ").join("_")),Je=[f().createElement("label",{key:0,htmlFor:Pe,title:x},f().createElement(ve,{checked:De===1,disabled:P,id:Pe,indeterminate:De===2,onClick:this.onCheck,onChange:function(){}}),f().createElement("span",{"aria-checked":De===1,"aria-disabled":P,className:"rct-checkbox",role:"checkbox",tabIndex:0,onKeyPress:this.onCheckboxKeyPress,onKeyUp:this.onCheckboxKeyUp},this.renderCheckboxIcon()),de?null:Fe)];return de&&Je.push(f().createElement("span",{key:1,className:"rct-node-clickable",onClick:this.onClick,onKeyPress:this.onClick,role:"link",tabIndex:0},Fe)),Je}},{key:"renderLabel",value:function(){var Fe=this.props,He=Fe.label,De=Fe.showCheckbox,P=[Fe.showNodeIcon?f().createElement("span",{key:0,className:"rct-node-icon"},this.renderNodeIcon()):null,f().createElement("span",{key:1,className:"rct-title"},He)];return De?this.renderCheckboxLabel(P):this.renderBareLabel(P)}},{key:"renderChildren",value:function(){return this.props.expanded?this.props.children:null}},{key:"render",value:function(){var Fe=this.props,He=Fe.className,De=Fe.disabled,P=Fe.expanded,x=Fe.isLeaf,U=A()({"rct-node":!0,"rct-node-leaf":x,"rct-node-parent":!x,"rct-node-expanded":!x&&P,"rct-node-collapsed":!x&&!P,"rct-disabled":De},He);return f().createElement("li",{className:U},f().createElement("span",{className:"rct-text"},this.renderCollapseButton(),this.renderLabel()),this.renderChildren())}}])&&ze(se.prototype,re),Object.defineProperty(se,"prototype",{writable:!1}),Ye}(f().PureComponent);wt(rt,"propTypes",{checked:h().number.isRequired,disabled:h().bool.isRequired,expandDisabled:h().bool.isRequired,expanded:h().bool.isRequired,icons:ke.isRequired,isLeaf:h().bool.isRequired,isParent:h().bool.isRequired,label:h().node.isRequired,lang:Xe.isRequired,optimisticToggle:h().bool.isRequired,showNodeIcon:h().bool.isRequired,treeId:h().string.isRequired,value:h().oneOfType([h().string,h().number]).isRequired,onCheck:h().func.isRequired,onExpand:h().func.isRequired,children:h().node,className:h().string,expandOnClick:h().bool,icon:h().node,showCheckbox:h().bool,title:h().string,onClick:h().func}),wt(rt,"defaultProps",{children:null,className:null,expandOnClick:!1,icon:null,showCheckbox:!0,title:null,onClick:function(){}});const Te=rt,le=h().oneOfType([h().arrayOf(h().string),h().arrayOf(h().number)]);function ye(ue,se){var re=Object.keys(ue);if(Object.getOwnPropertySymbols){var oe=Object.getOwnPropertySymbols(ue);se&&(oe=oe.filter(function(Se){return Object.getOwnPropertyDescriptor(ue,Se).enumerable})),re.push.apply(re,oe)}return re}function We(ue){for(var se=1;se"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}(),function(){var He,De=ut(Se);if(Ke){var P=ut(this).constructor;He=Reflect.construct(De,arguments,P)}else He=De.apply(this,arguments);return mt(this,He)});function Fe(He){var De;(function(x,U){if(!(x instanceof U))throw new TypeError("Cannot call a class as a function")})(this,Fe),De=Ye.call(this,He);var P=new te(He);return P.flattenNodes(He.nodes),P.deserializeLists({checked:He.checked,expanded:He.expanded}),De.state={id:He.id||"rct-".concat(u()),model:P,prevProps:He},De.onCheck=De.onCheck.bind(St(De)),De.onExpand=De.onExpand.bind(St(De)),De.onNodeClick=De.onNodeClick.bind(St(De)),De.onExpandAll=De.onExpandAll.bind(St(De)),De.onCollapseAll=De.onCollapseAll.bind(St(De)),De.combineMemorized=c()(function(x,U){return we(we({},x),U)}).bind(St(De)),De}return se=Fe,re=[{key:"onCheck",value:function(He){var De=this.props,P=De.checkModel,x=De.noCascade,U=De.onCheck,ce=this.state.model.clone(),de=ce.getNode(He.value);ce.toggleChecked(He,He.checked,P,x),U(ce.serializeList("checked"),we(we({},de),He))}},{key:"onExpand",value:function(He){var De=this.props.onExpand,P=this.state.model.clone(),x=P.getNode(He.value);P.toggleNode(He.value,"expanded",He.expanded),De(P.serializeList("expanded"),we(we({},x),He))}},{key:"onNodeClick",value:function(He){(0,this.props.onClick)(we(we({},this.state.model.getNode(He.value)),He))}},{key:"onExpandAll",value:function(){this.expandAllNodes()}},{key:"onCollapseAll",value:function(){this.expandAllNodes(!1)}},{key:"expandAllNodes",value:function(){var He=!(arguments.length>0&&arguments[0]!==void 0)||arguments[0],De=this.props.onExpand;De(this.state.model.clone().expandAllNodes(He).serializeList("expanded"))}},{key:"determineShallowCheckState",value:function(He,De){var P=this.state.model.getNode(He.value);return P.isLeaf||De||He.children.length===0?P.checked?1:0:this.isEveryChildChecked(He)?1:this.isSomeChildChecked(He)?2:0}},{key:"isEveryChildChecked",value:function(He){var De=this;return He.children.every(function(P){return De.state.model.getNode(P.value).checkState===1})}},{key:"isSomeChildChecked",value:function(He){var De=this;return He.children.some(function(P){return De.state.model.getNode(P.value).checkState>0})}},{key:"renderTreeNodes",value:function(He){var De=this,P=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},x=this.props,U=x.expandDisabled,ce=x.expandOnClick,de=x.icons,Pe=x.lang,Je=x.noCascade,ct=x.onClick,bt=x.onlyLeafCheckboxes,Ft=x.optimisticToggle,dt=x.showNodeTitle,Xt=x.showNodeIcon,Ot=this.state,ot=Ot.id,Nt=Ot.model,Ut=Fe.defaultProps.icons,Pt=He.map(function(Xg){var eI=Xg.value,et=Nt.getNode(Xg.value),yt=et.isParent?De.renderTreeNodes(Xg.children,Xg):null;et.checkState=De.determineShallowCheckState(Xg,Je);var qt=bt?et.isLeaf:et.showCheckbox;return!P.value||Nt.getNode(P.value).expanded?f().createElement(Te,{key:eI,checked:et.checkState,className:Xg.className,disabled:et.disabled,expandDisabled:U,expandOnClick:ce,expanded:et.expanded,icon:Xg.icon,icons:De.combineMemorized(Ut,de),label:Xg.label,lang:Pe,optimisticToggle:Ft,isLeaf:et.isLeaf,isParent:et.isParent,showCheckbox:qt,showNodeIcon:Xt,title:dt?Xg.title||Xg.label:Xg.title,treeId:ot,value:Xg.value,onCheck:De.onCheck,onClick:ct&&De.onNodeClick,onExpand:De.onExpand},yt):null});return f().createElement("ol",null,Pt)}},{key:"renderExpandAll",value:function(){var He=this.props,De=He.icons,P=De.expandAll,x=De.collapseAll,U=He.lang;return He.showExpandAll?f().createElement("div",{className:"rct-options"},f().createElement(X,{className:"rct-option rct-option-expand-all",title:U.expandAll,onClick:this.onExpandAll},P),f().createElement(X,{className:"rct-option rct-option-collapse-all",title:U.collapseAll,onClick:this.onCollapseAll},x)):null}},{key:"renderHiddenInput",value:function(){var He=this.props,De=He.name,P=He.nameAsArray;return De===void 0?null:P?this.renderArrayHiddenInput():this.renderJoinedHiddenInput()}},{key:"renderArrayHiddenInput",value:function(){var He=this.props,De=He.checked,P=He.name;return De.map(function(x){var U="".concat(P,"[]");return f().createElement("input",{key:x,name:U,type:"hidden",value:x})})}},{key:"renderJoinedHiddenInput",value:function(){var He=this.props,De=He.checked,P=He.name,x=De.join(",");return f().createElement("input",{name:P,type:"hidden",value:x})}},{key:"render",value:function(){var He,De=this.props,P=De.direction,x=De.disabled,U=De.iconsClass,ce=De.nodes,de=De.nativeCheckboxes,Pe=this.state.id,Je=this.renderTreeNodes(ce),ct=A()((Yt(He={"react-checkbox-tree":!0,"rct-disabled":x},"rct-icons-".concat(U),!0),Yt(He,"rct-native-display",de),Yt(He,"rct-direction-rtl",P==="rtl"),He));return f().createElement("div",{className:ct,id:Pe},this.renderExpandAll(),this.renderHiddenInput(),Je)}}],oe=[{key:"getDerivedStateFromProps",value:function(He,De){var P=De.model,x=De.prevProps,U=He.disabled,ce=He.id,de=He.nodes,Pe=we(we({},De),{},{prevProps:He});return P.setProps(He),a()(x.nodes,de)&&x.disabled===U||(P.reset(),P.flattenNodes(de)),ce!==null&&(Pe=we(we({},Pe),{},{id:ce})),P.deserializeLists({checked:He.checked,expanded:He.expanded}),Pe}}],re&&xe(se.prototype,re),oe&&xe(se,oe),Object.defineProperty(se,"prototype",{writable:!1}),Fe}(f().Component);function E(ue){return function(se){if(Array.isArray(se))return O(se)}(ue)||function(se){if(typeof Symbol<"u"&&se[Symbol.iterator]!=null||se["@@iterator"]!=null)return Array.from(se)}(ue)||function(se,re){if(se){if(typeof se=="string")return O(se,re);var oe=Object.prototype.toString.call(se).slice(8,-1);return oe==="Object"&&se.constructor&&(oe=se.constructor.name),oe==="Map"||oe==="Set"?Array.from(se):oe==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(oe)?O(se,re):void 0}}(ue)||function(){throw new TypeError(`Invalid attempt to spread non-iterable instance. -In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}()}function O(ue,se){(se==null||se>ue.length)&&(se=ue.length);for(var re=0,oe=new Array(se);re2&&arguments[2]!==void 0?arguments[2]:0;if(re>se)return[];var oe=[];return ue.forEach(function(Se){Se.children&&(oe=[].concat(E(oe),[Se.value],E(me(Se.children,se,re+1))))}),oe}Yt(ie,"propTypes",{nodes:h().arrayOf(k).isRequired,checkModel:h().oneOf([W.LEAF,W.ALL]),checked:le,direction:h().string,disabled:h().bool,expandDisabled:h().bool,expandOnClick:h().bool,expanded:le,icons:ke,iconsClass:h().string,id:h().string,lang:Xe,name:h().string,nameAsArray:h().bool,nativeCheckboxes:h().bool,noCascade:h().bool,onlyLeafCheckboxes:h().bool,optimisticToggle:h().bool,showExpandAll:h().bool,showNodeIcon:h().bool,showNodeTitle:h().bool,onCheck:h().func,onClick:h().func,onExpand:h().func}),Yt(ie,"defaultProps",{checkModel:W.LEAF,checked:[],direction:"ltr",disabled:!1,expandDisabled:!1,expandOnClick:!1,expanded:[],icons:{check:f().createElement("span",{className:"rct-icon rct-icon-check"}),uncheck:f().createElement("span",{className:"rct-icon rct-icon-uncheck"}),halfCheck:f().createElement("span",{className:"rct-icon rct-icon-half-check"}),expandClose:f().createElement("span",{className:"rct-icon rct-icon-expand-close"}),expandOpen:f().createElement("span",{className:"rct-icon rct-icon-expand-open"}),expandAll:f().createElement("span",{className:"rct-icon rct-icon-expand-all"}),collapseAll:f().createElement("span",{className:"rct-icon rct-icon-collapse-all"}),parentClose:f().createElement("span",{className:"rct-icon rct-icon-parent-close"}),parentOpen:f().createElement("span",{className:"rct-icon rct-icon-parent-open"}),leaf:f().createElement("span",{className:"rct-icon rct-icon-leaf"})},iconsClass:"fa4",id:null,lang:{collapseAll:"Collapse all",expandAll:"Expand all",toggle:"Toggle"},name:void 0,nameAsArray:!1,nativeCheckboxes:!1,noCascade:!1,onlyLeafCheckboxes:!1,optimisticToggle:!0,showExpandAll:!1,showNodeIcon:!0,showNodeTitle:!1,onCheck:function(){},onClick:null,onExpand:function(){}});const Ne=ie})(),r})())})(a9e);var FUt=a9e.exports;const EUt=FC(FUt);function MUt(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function Qae(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function p2(g){return p2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},p2(g)}let s9e=function(g){OUt(I,g);var e=LUt(I);function I(i){var n;MUt(this,I),n=e.call(this,i),n.localTracks=dh.filter(A=>A.local&&!A.hidden).map(A=>{const s={...A};return s.datatype=A.datatype[0],s}),n.augmentedTracksInfo=dh,window.higlassTracksByType&&Object.keys(window.higlassTracksByType).forEach(A=>{n.augmentedTracksInfo.push(window.higlassTracksByType[A].config)}),i.datatype?n.localTracks=n.localTracks.filter(A=>A.datatype[0]===i.datatype):n.localTracks=n.localTracks.filter(A=>A.orientation===n.props.orientation),n.localTracks.forEach(A=>{A.uuid=dg.nice()});const C=n.prepareNewEntries("",n.localTracks,{}),r=Object.keys(C),o=r.length?[r[0]]:null;return n.mounted=!1,n.state={selectedUuid:o,options:C,filter:"",checked:[],expanded:[]},n.requestTilesetLists(),n}return zUt(I,[{key:"componentDidMount",value:function(){this.mounted=!0,this.requestTilesetLists(),this.searchBox.focus()}},{key:"componentWillUnmount",value:function(){this.mounted=!1}},{key:"prepareNewEntries",value:function(n,C,r){const o=r;return C.map(s=>({...s,server:n,tilesetUid:s.uuid,serverUidKey:this.serverUidKey(n,s.uuid),datatype:s.datatype,name:s.name,uid:dg.nice()})).forEach(s=>{o[s.serverUidKey]=s}),o}},{key:"serverUidKey",value:function(n,C){return`${n}/${C}`}},{key:"requestTilesetLists",value:function(){let n=null;if(this.props.datatype?n=`dt=${this.props.datatype}`:n=[...new Set([].concat(...this.augmentedTracksInfo.filter(r=>r.datatype).filter(r=>r.orientation===this.props.orientation||this.props.orientation==="1d-vertical"&&r.orientation==="1d-horizontal").map(r=>r.datatype)))].map(r=>`dt=${r}`).join("&"),!this.props.trackSourceServers){console.warn("No track source servers specified in the viewconf");return}this.props.trackSourceServers.forEach(C=>{vt.json(`${C}/tilesets/?limit=10000&${n}`,(r,o)=>{if(r)console.error("ERROR:",r);else{const A=this.prepareNewEntries(C,o.results,this.state.options),s=Object.keys(A);let{selectedUuid:a}=this.state;if(!a){a=s.length?[s[0]]:null;const l=this.state.options[a[0]];this.props.selectedTilesetChanged([l])}this.mounted&&this.setState({selectedUuid:a,options:A})}},this.props.pubSub)})}},{key:"handleOptionDoubleClick",value:function(n){const C=this.state.options[n.target.value];this.props.onDoubleClick(C)}},{key:"handleSelectedOptions",value:function(n){const C=[],r=[];for(let o=0;os.label.toLowerCase().localeCompare(a.label.toLowerCase(),"en")),o.push(r[A]));return o.sort((A,s)=>A.label.toLowerCase().localeCompare(s.label.toLowerCase(),"en")),o}},{key:"handleChecked",value:function(n){this.handleSelectedOptions(n),this.setState({checked:n})}},{key:"handleExpanded",value:function(n){this.setState({expanded:n})}},{key:"render",value:function(){const n=[];for(const s in this.state.options)n.push(this.state.options[s]);const C=this.partitionByGroup(this.state.options,this.state.filter),r={width:15,height:15,top:2,right:2,position:"relative"},o=JSON.parse(JSON.stringify(r));o.opacity=.5;const A=N.createElement("form",{onSubmit:s=>{s.preventDefault()}},N.createElement("div",{className:"tileset-finder-search-bar"},N.createElement("span",{className:"tileset-finder-label"},"Select tileset:"),N.createElement("input",{ref:s=>{this.searchBox=s},className:"tileset-finder-search-box",onChange:this.handleSearchChange.bind(this),placeholder:"Search Term",type:"text"})),N.createElement("div",{className:"tileset-finder-checkbox-tree"},N.createElement(EUt,{checked:this.state.checked,expanded:this.state.expanded,icons:{uncheck:N.createElement("svg",{style:r},N.createElement("use",{xlinkHref:"#square_o"})),check:N.createElement("svg",{style:r},N.createElement("use",{xlinkHref:"#check_square_o"})),halfCheck:N.createElement("svg",{style:o},N.createElement("use",{xlinkHref:"#check_square_o"})),leaf:N.createElement("svg",{style:r},N.createElement("use",{xlinkHref:"#file_o"})),expandClose:N.createElement("svg",{style:r},N.createElement("use",{xlinkHref:"#chevron_right"})),expandOpen:N.createElement("svg",{style:r},N.createElement("use",{xlinkHref:"#chevron_down"})),parentClose:N.createElement("svg",{style:r},N.createElement("use",{xlinkHref:"#folder_o"})),parentOpen:N.createElement("svg",{style:r},N.createElement("use",{xlinkHref:"#folder_open_o"}))},nodes:C,onCheck:this.handleChecked.bind(this),onExpand:this.handleExpanded.bind(this)})));return N.createElement("div",null,A)}}]),I}(N.Component);s9e.propTypes={datatype:L.string,orientation:L.string,onDoubleClick:L.func,pubSub:L.object.isRequired,selectedTilesetChanged:L.func,trackSourceServers:L.array};const jUt=ry(s9e);function $Ut(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function jae(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function b2(g){return b2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},b2(g)}let l9e=function(g){g7t(I,g);var e=I7t(I);function I(i){var n;return $Ut(this,I),n=e.call(this,i),n.DATATYPE_TO_TRACK_TYPE=fQ(n.props.orientation),n.AVAILABLE_TRACK_TYPES=z9(n.props.datatypes,n.props.orientation),n.state={selectedPlotType:n.AVAILABLE_TRACK_TYPES[0]},n}return qUt(I,[{key:"UNSAFE_componentWillReceiveProps",value:function(n){if(this.AVAILABLE_TRACK_TYPES=z9(n.datatypes,this.props.orientation),!!this.AVAILABLE_TRACK_TYPES&&n.allTracksSameDatatype&&this.AVAILABLE_TRACK_TYPES.length>0&&!this.AVAILABLE_TRACK_TYPES.includes(this.state.selectedPlotType)){const C=yQ(n.datatypes[0][0],this.props.position,this.AVAILABLE_TRACK_TYPES);this.handlePlotTypeSelected(C)}}},{key:"handlePlotTypeSelected",value:function(n){this.setState({selectedPlotType:n}),this.props.onPlotTypeSelected(n.type)}},{key:"render",value:function(){let n="No plot types available for track";const C={};return dh.forEach(r=>{C[r.type]=r}),this.AVAILABLE_TRACK_TYPES&&(n=this.AVAILABLE_TRACK_TYPES.sort((r,o)=>r.type{const o=C[r.type].thumbnail,A=this.state.selectedPlotType.type===r.type?"plot-type-item plot-type-selected":"plot-type-item",s=C[r.type].thumbnail?N.createElement("div",{className:"track-thumbnail",dangerouslySetInnerHTML:{__html:o.outerHTML}}):N.createElement("div",{className:"track-thumbnail"},N.createElement("svg",{height:20,width:30}));return N.createElement("li",{key:r.type,className:A,onClick:a=>{this.setState({selectedPlotType:r}),this.props.onPlotTypeSelected(r.type)},style:{listStyle:"none",paddingLeft:5,paddingBottom:0}},s,N.createElement("span",{style:{verticalAlign:"middle"}},r.type))})),N.createElement("div",null,n.length>0&&this.props.allTracksSameDatatype&&N.createElement("div",{className:"plot-type-container"},n),!this.props.allTracksSameDatatype&&N.createElement("div",{className:"plot-type-container-empty"},"Datasets with multiple datatypes chosen. They will be added with their default track types."))}}]),I}(N.Component);l9e.propTypes={allTracksSameDatatype:L.bool,datatypes:L.array,orientation:L.string,onPlotTypeSelected:L.func,position:L.string};function r7t(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function $ae(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function y2(g){return y2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},y2(g)}let Z2=function(g){s7t(I,g);var e=l7t(I);function I(i){var n;return r7t(this,I),n=e.call(this,i),n.options={},n.state={selectedTilesets:[{datatype:"none"}],allTracksSameDatatype:!0},n.handleSubmitBound=n.handleSubmit.bind(MW(n)),n.handleTilesetPickerDoubleClickBound=n.handleTilesetPickerDoubleClick.bind(MW(n)),n.selectedTilesetsChangedBound=n.selectedTilesetsChanged.bind(MW(n)),n}return o7t(I,[{key:"getOrientation",value:function(n){let C=null;return n==="top"||n==="bottom"?C="1d-horizontal":n==="left"||n==="right"?C="1d-vertical":C="2d",C}},{key:"handleSubmit",value:function(n){n&&n.preventDefault(),this.props.onTracksChosen(this.state.selectedTilesets,this.props.position,this.props.host)}},{key:"handleTilesetPickerDoubleClick",value:function(n){this.selectedTilesetsChanged([n]),this.props.onTracksChosen(this.state.selectedTilesets,this.props.position,this.props.host)}},{key:"handleOptionsChanged",value:function(n){this.options=n}},{key:"handlePlotTypeSelected",value:function(n){const{selectedTilesets:C}=this.state;for(const r of C)r.type=n;this.selectedPlotType=n,this.setState({selectedTilesets:C})}},{key:"selectedTilesetsChanged",value:function(n){let C=null;n.length===0?C=[{datatype:"none"}]:C=n;let r=!0;const o=C[0].datatype;for(const A of C)A.datatype!==o&&(r=!1);if(r)for(const A of C)A.type=this.selectedPlotType;else for(const A of C){let s=[A.datatype];const a=this.getOrientation(this.props.position);A.filetype==="cooler"&&(s=[A.datatype,"chromsizes"]);const l=z9([s],a),c=yQ(s[0],this.props.position,l);A.type=c.type}this.setState({selectedTilesets:C,allTracksSameDatatype:r})}},{key:"render",value:function(){const n=this.getOrientation(this.props.position),C=N.createElement("div",null,N.createElement(jUt,{ref:r=>{this.tilesetFinder=r},datatype:this.props.datatype,onDoubleClick:this.handleTilesetPickerDoubleClick.bind(this),onTracksChosen:r=>this.props.onTracksChosen(r,this.props.position),orientation:n,selectedTilesetChanged:this.selectedTilesetsChanged.bind(this),trackSourceServers:this.props.trackSourceServers}));return N.createElement(Yw,{maxHeight:!0,okayTitle:"Submit",onCancel:this.props.onCancel,onOkay:this.handleSubmitBound,title:"Add Track"},N.createElement(N.Fragment,null,C,N.createElement(l9e,{ref:r=>{this.plotTypeChooser=r},allTracksSameDatatype:this.state.allTracksSameDatatype,datatypes:this.state.selectedTilesets.map(r=>r.filetype==="cooler"?[r.datatype,"chromsizes"]:[r.datatype]),onPlotTypeSelected:this.handlePlotTypeSelected.bind(this),orientation:n,position:this.props.position})))}}]),I}(N.Component);Z2.defaultProps={position:"top"};Z2.propTypes={datatype:L.string,host:L.string,onCancel:L.func.isRequired,onTracksChosen:L.func.isRequired,position:L.string,trackSourceServers:L.array.isRequired};function oO(){return oO=Object.assign?Object.assign.bind():function(g){for(var e=1;e"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function G2(g){return G2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},G2(g)}let o$=function(g){p7t(I,g);var e=b7t(I);function I(){return d7t(this,I),e.apply(this,arguments)}return h7t(I,[{key:"render",value:function(){const n=[];return this.props.children.forEach((C,r)=>{const o=`customTrackDialog_${r}`;n.push(N.createElement(C,oO({key:o},this.props.bodyProps[r])))}),N.createElement(Yw,{maxHeight:!0,okayOnly:!0,okayTitle:"Close",onCancel:this.props.onCancel,onOkay:this.props.onCancel,title:this.props.title},n)}}]),I}(N.PureComponent);o$.defaultProps={};o$.propTypes={onCancel:L.func.isRequired,title:L.string,bodyProps:L.array,children:L.array};function B7t(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function ese(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function B2(g){return B2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},B2(g)}const tse=20;let Ru=function(g){V7t(I,g);var e=R7t(I);function I(i){var n;return B7t(this,I),n=e.call(this,i),n.adjusted=!1,n.state={orientation:n.props.orientation?n.props.orientation:"right",left:n.props.position.left,top:n.props.position.top,submenuShown:null},n}return v7t(I,[{key:"componentDidMount",value:function(){this.updateOrientation()}},{key:"UNSAFE_componentWillReceiveProps",value:function(n){this.adjusted=!1,this.setState({left:n.position.left,top:n.position.top})}},{key:"componentDidUpdate",value:function(){this.updateOrientation()}},{key:"handleItemMouseEnterWithRect",value:function(n,C){this.setState({submenuShown:C,submenuSourceBbox:n})}},{key:"handleItemMouseEnter",value:function(n,C){this.handleItemMouseEnterWithRect(n.currentTarget.getBoundingClientRect(),C)}},{key:"handleMouseLeave",value:function(){}},{key:"handleOtherMouseEnter",value:function(){this.setState({submenuShown:null})}},{key:"updateOrientation",value:function(){if(this.adjusted)return;this.adjusted=!0,this.divDom=QI.findDOMNode(this.div);const n=this.divDom.getBoundingClientRect(),C=this.props.parentBbox?this.props.parentBbox:{top:this.props.position.top,left:this.props.position.left,width:0,height:0};let r=this.state.orientation,o=C.top;if(C.top+n.height>window.innerHeight&&(C.top-n.height>0?o=C.top-n.height+tse:(o=C.top-n.height+tse,o-=o+n.height-window.innerHeight)),this.state.orientation==="left"){let A=C.left-n.width;A<0&&(C.left+C.width+n.width>window.innerWidth?A=0:(A=C.left+C.width,r="right")),this.setState({left:A,top:o,orientation:r})}else{let A=C.left+C.width;C.left+C.width+n.width>window.innerWidth&&(C.left-n.width<0?(A=0,r="right"):(A=C.left-n.width,r="left")),this.setState({left:A,top:o,orientation:r})}}},{key:"render",value:function(){const n=this.state.left?{left:this.state.left}:{right:this.state.right},C={top:this.state.top},r=Object.assign(n,C);return N.createElement("div",{ref:o=>{this.div=o},className:Tg("context-menu-item",eg["context-menu"],{[eg["context-menu-dark"]]:this.props.theme===II}),style:r},this.props.children)}}]),I}(N.Component);Ru.propTypes={children:L.node,orientation:L.string,parentBbox:L.object,position:L.object,theme:L.symbol.isRequired};function T7t(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function gse(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function v2(g){return v2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},v2(g)}let lO=function(g){K7t(I,g);var e=x7t(I);function I(){return T7t(this,I),e.apply(this,arguments)}return N7t(I,[{key:"getSubmenu",value:function(){if(this.state.submenuShown){const n=this.state.submenuSourceBbox,C=this.state.orientation==="left"?{left:this.state.left,top:n.top}:{left:this.state.left+n.width+7,top:n.top},r=this.state.submenuShown;return N.createElement(I,{menuItems:r.children,orientation:this.state.orientation,parentBbox:n,position:C,theme:this.props.theme})}return N.createElement("div",null)}},{key:"componentWillUnmount",value:function(){}},{key:"render",value:function(){const n=[];for(const C in this.props.menuItems){const r=this.props.menuItems[C];n.push(N.createElement(og,{key:C,onClick:r.handler?r.handler:()=>null,onMouseEnter:r.children?o=>this.handleItemMouseEnter(o,r):this.handleOtherMouseEnter.bind(this),onMouseLeave:this.handleMouseLeave},r.name,r.children&&N.createElement("svg",{className:eg["play-icon"]},N.createElement("use",{xlinkHref:"#play"}))))}return N.createElement("div",{ref:C=>{this.div=C},className:Tg(eg["context-menu"],{[eg["context-menu-dark"]]:this.props.theme===II}),style:{left:this.state.left,top:this.state.top}},n,this.getSubmenu())}}]),I}(Ru);function M7t(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function Ise(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function S2(g){return S2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},S2(g)}let j7t=function(g){O7t(I,g);var e=L7t(I);function I(){return M7t(this,I),e.apply(this,arguments)}return z7t(I,[{key:"getConfigureSeriesMenu",value:function(n,C,r){const o={},A=window.higlassTracksByType&&window.higlassTracksByType[r.type]&&window.higlassTracksByType[r.type].config&&window.higlassTracksByType[r.type].config.optionsInfo;if(A)for(const s of Object.keys(A))nn[s]=A[s];if(!$g[r.type]||!$g[r.type].availableOptions)return null;for(const s of $g[r.type].availableOptions)if(s in nn){if(o[s]={name:nn[s].name},nn[s].generateOptions){const a=nn[s].generateOptions(r);o[s].children||(o[s].children={});for(const l of a){const c={name:l.name,value:l.value,handler:()=>{r.options[s]=l.value,this.props.onTrackOptionsChanged(r.uid,r.options),this.props.closeMenu()}};o[s].children[l.value]=c}}if(nn[s].inlineOptions)for(const a in nn[s].inlineOptions){const l=nn[s].inlineOptions[a];o[s].children||(o[s].children={});const c={name:l.name,value:l.value};l.componentPickers&&l.componentPickers[r.type]?c.handler=()=>{this.props.onConfigureTrack(r,l.componentPickers[r.type]),this.props.closeMenu()}:c.handler=()=>{r.options[s]=l.value,this.props.onTrackOptionsChanged(r.uid,r.options),this.props.closeMenu()},o[s].children[a]=c}else nn[s].componentPickers&&nn[s].componentPickers[r.type]&&(o[s].handler=()=>{this.props.onConfigureTrack(r,nn[s].componentPickers[r.type]),this.props.closeMenu()})}return N.createElement(lO,{key:"config-series-menu",closeMenu:this.props.closeMenu,menuItems:o,orientation:this.state.orientation,parentBbox:C,position:n,theme:this.props.theme})}},{key:"getTrackTypeItems",value:function(n,C,r){window.higlassTracksByType&&Object.keys(window.higlassTracksByType).forEach(l=>{$g[l]=window.higlassTracksByType[l].config});let{datatype:o}=r,A=null;r.type in $g&&(o||(o=$g[r.type].datatype[0]),{orientation:A}=$g[r.type]);const s=Object.values($g).filter(l=>l.datatype).filter(l=>l.orientation).filter(l=>l.datatype.includes(o)).filter(l=>l.orientation===A).map(l=>l.type),a={};for(let l=0;l{this.props.onChangeTrackType(r.uid,s[l])}};return N.createElement(lO,{key:"track-type-items",closeMenu:this.props.closeMenu,menuItems:a,orientation:this.state.orientation,parentBbox:C,position:n,theme:this.props.theme})}},{key:"getSubmenu",value:function(){if(this.state.submenuShown){const n=this.state.submenuSourceBbox,C=this.state.orientation==="left"?{left:this.state.left,top:n.top}:{left:this.state.left+n.width+7,top:n.top},r=this.state.submenuShown,o=r.value;return r.option==="track-type"?this.getTrackTypeItems(C,n,o):this.getConfigureSeriesMenu(C,n,o)}return N.createElement("div",null)}},{key:"getDivideByMenuItem",value:function(){if(this.props.series.data&&this.props.series.data.type==="divided"){const n={tilesetUid:this.props.series.data.children[0].tilesetUid,server:this.props.series.data.children[0].server};return N.createElement(og,{className:eg["context-menu-item"],onClick:()=>this.props.onChangeTrackData(this.props.series.uid,n),onMouseEnter:C=>this.handleOtherMouseEnter(C)},N.createElement("span",{className:eg["context-menu-span"]},"Remove divisor"))}return N.createElement(og,{className:eg["context-menu-item"],onClick:()=>this.props.onAddDivisor(this.props.series),onMouseEnter:n=>this.handleOtherMouseEnter(n)},N.createElement("span",{className:eg["context-menu-span"]},"Divide by"))}},{key:"componentWillUnmount",value:function(){}},{key:"render",value:function(){let n=null;$g[this.props.series.type]&&$g[this.props.series.type].exportable&&(n=N.createElement(og,{className:eg["context-menu-item"],onClick:()=>this.props.onExportData(this.props.hostTrack.uid,this.props.track.uid),onMouseEnter:r=>this.handleOtherMouseEnter(r)},N.createElement("span",{className:eg["context-menu-span"]},"Export Data")));const C=this.props.onAddSeries?N.createElement(og,{className:eg["context-menu-item"],onClick:()=>{this.props.onCloseTrack(this.props.series.uid),this.props.onAddSeries(this.props.hostTrack.uid)},onMouseEnter:r=>this.handleOtherMouseEnter(r)},N.createElement("span",{className:eg["context-menu-span"]},"Replace Series")):null;return N.createElement("div",{ref:r=>{this.div=r},className:Tg(eg["context-menu"],{[eg["context-menu-dark"]]:this.props.theme===II}),"data-menu-type":"SeriesListMenu",onMouseLeave:this.props.handleMouseLeave,style:{left:this.state.left,top:this.state.top}},N.createElement(og,{onClick:()=>{},onMouseEnter:r=>this.handleItemMouseEnter(r,{option:"configure-series",value:this.props.track}),onMouseLeave:r=>this.handleMouseLeave(r)},"Configure Series",N.createElement("svg",{className:eg["play-icon"]},N.createElement("use",{xlinkHref:"#play"}))),N.createElement(og,{className:eg["context-menu-item"],onClick:()=>{},onMouseEnter:r=>this.handleItemMouseEnter(r,{option:"track-type",value:this.props.track}),onMouseLeave:r=>this.handleMouseLeave(r)},N.createElement("span",{className:eg["context-menu-span"]},"Track Type",N.createElement("svg",{className:eg["play-icon"]},N.createElement("use",{xlinkHref:"#play"})))),n,this.getDivideByMenuItem(),N.createElement(og,{className:eg["context-menu-item"],onClick:this.props.onCloseTrack,onMouseEnter:r=>this.handleOtherMouseEnter(r)},N.createElement("span",{className:eg["context-menu-span"]},"Close Series")),C,this.getSubmenu())}}]),I}(Ru);const c9e=g=>{let e=[];for(const I of g)I.contents?e=e.concat(I.contents):e.push(I);return e},A$=(g,e,I,i)=>g?(window.higlassTracksByType&&Object.keys(window.higlassTracksByType).forEach(n=>{$g[n]=window.higlassTracksByType[n].config}),c9e(g).map(n=>{const C=$g[n.type]?$g[n.type].thumbnail:null,r=C?N.createElement("div",{className:eg["context-menu-icon"],dangerouslySetInnerHTML:{__html:C.outerHTML}}):N.createElement("div",{className:eg["context-menu-icon"]},N.createElement("svg",null));return N.createElement(og,{key:n.uid,className:eg["context-menu-item"],onClick:()=>{i&&i(n.uid)},onMouseEnter:o=>{e&&e(o,n)},onMouseLeave:o=>{I&&I(o)}},r,N.createElement("span",{className:eg["context-menu-span"]},n.options&&n.options.name&&n.options.name.length?n.options.name:n.type,e&&I?N.createElement("svg",{className:eg["play-icon"]},N.createElement("use",{xlinkHref:"#play"})):null))})):null;function $7t(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function ise(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function w2(g){return w2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},w2(g)}const u9e=eY(g=>function(e){gQt(i,e);var I=IQt(i);function i(){return $7t(this,i),I.apply(this,arguments)}return q7t(i,[{key:"getSubmenu",value:function(){if(this.state.submenuShown){const C=this.state.submenuSourceBbox;let r=null;this.state.orientation==="left"?r={left:this.state.left,top:C.top}:r={left:this.state.left+C.width+7,top:C.top};const A=c9e(this.props.tracks).filter(a=>a.uid===this.state.submenuShown.uid)[0],s=A&&A.position!=="whole";return N.createElement(j7t,{key:`series-list-menu-${A.uid}`,ref:a=>{this.seriesListMenu=a},closeMenu:this.props.closeMenu,hostTrack:this.props.tracks[0],onAddDivisor:this.props.onAddDivisor,onAddSeries:s?this.props.onAddSeries:null,onChangeTrackData:this.props.onChangeTrackData,onChangeTrackType:this.props.onChangeTrackType,onCloseTrack:()=>this.props.onCloseTrack(this.state.submenuShown.uid),onConfigureTrack:this.props.onConfigureTrack,onDivideSeries:this.props.onDivideSeries,onExportData:this.props.onExportData,onLockScales:this.props.onLockScales,onTrackOptionsChanged:this.props.onTrackOptionsChanged,orientation:this.state.orientation,parentBbox:C,position:r,series:this.state.submenuShown,theme:this.props.theme,track:A,trackOrientation:this.props.trackOrientation,trackSourceServers:this.props.trackSourceServers})}return N.createElement("div",null)}}]),i}(g));function rQt(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function nse(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function v0(g){return v0=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},v0(g)}let mQt=function(g){lQt(I,g);var e=cQt(I);function I(i){var n;return rQt(this,I),n=e.call(this,i),n.seriesRefs={},n.seriesListMenu=null,n}return oQt(I,[{key:"componentDidMount",value:function(){zW(v0(I.prototype),"componentDidMount",this).call(this)}},{key:"render",value:function(){return N.createElement("div",{ref:n=>{this.div=n},className:Tg(eg["context-menu"],{[eg["context-menu-dark"]]:this.props.theme===II}),"data-menu-type":"ConfigTrackMenu",style:{left:this.state.left,top:this.state.top}},A$(this.props.tracks,this.handleItemMouseEnter.bind(this),this.handleMouseLeave.bind(this),null),N.createElement("hr",{className:eg["context-menu-hr"]}),N.createElement(og,{contextMenu:this,onClick:()=>this.props.onLockValueScale(this.props.tracks[0].uid),onMouseEnter:n=>this.handleOtherMouseEnter(n)},"Lock Value Scale With"),N.createElement(og,{contextMenu:this,onClick:()=>this.props.onUnlockValueScale(this.props.tracks[0].uid),onMouseEnter:n=>this.handleOtherMouseEnter(n)},"Unlock Value Scale"),N.createElement("hr",{className:eg["context-menu-hr"]}),N.createElement(og,{contextMenu:this,onClick:()=>this.props.onAddSeries(this.props.tracks[0].uid),onMouseEnter:n=>this.handleOtherMouseEnter(n)},"Add Series"),N.createElement(og,{onClick:()=>this.props.onCloseTrack(this.props.tracks[0].uid)},"Close Track"),N.createElement(og,{onClick:()=>{this.props.onReplaceTrack(this.props.tracks[0].uid,this.props.trackOrientation)}},"Replace Track"),this.getSubmenu())}}]),I}(uy(Ru).with(u9e));function d9e(g){return N.createElement("div",null,A$(g.tracks,null,null,g.onCloseTrack),N.createElement("hr",{className:eg["context-menu-hr"]}),N.createElement(og,{onClick:()=>g.onCloseTrack(g.tracks[0].uid)},"Close all series"))}d9e.propTypes={onCloseTrack:L.func.isRequired,tracks:L.array.isRequired};function fQt(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function Cse(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function V2(g){return V2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},V2(g)}let $c=function(g){ZQt(I,g);var e=GQt(I);function I(i){var n;return fQt(this,I),n=e.call(this,i),n.clickHandlerBound=n.clickHandler.bind(PW(n)),n.contextMenuHandlerBound=n.contextMenuHandler.bind(PW(n)),n.resizeHandlerBound=n.resizeHandler.bind(PW(n)),n}return pQt(I,[{key:"componentDidMount",value:function(){this.popup=document.createElement("div"),document.body.appendChild(this.popup),this.popup.style.zIndex=99,this.popup.style.position="absolute",this.popup.className="hg-popup",document.addEventListener("click",this.clickHandlerBound,!0),document.addEventListener("contextmenu",this.contextMenuHandlerBound,!0),window.addEventListener("resize",this.resizeHandlerBound,!0),this._renderLayer()}},{key:"componentDidUpdate",value:function(){this._renderLayer()}},{key:"componentWillUnmount",value:function(){document.removeEventListener("click",this.clickHandlerBound,!0),document.removeEventListener("contextmenu",this.contextMenuHandlerBound,!0),window.removeEventListener("resize",this.resizeHandlerBound,!0),QI.unmountComponentAtNode(this.popup),document.body.removeChild(this.popup)}},{key:"_renderLayer",value:function(){QI.render(this.props.children,this.popup)}},{key:"clickHandler",value:function(n){this.popup.contains(n.target)||this.props.onMenuClosed&&this.props.onMenuClosed(n)}},{key:"contextMenuHandler",value:function(n){n.altKey||(n.preventDefault(),this.clickHandler(n))}},{key:"resizeHandler",value:function(){this.props.onMenuClosed(null)}},{key:"render",value:function(){return N.createElement("div",null)}}]),I}(N.Component);$c.defaultProps={onMenuClosed:jGe};$c.propTypes={children:L.node.isRequired,onMenuClosed:L.func};const SQt=fGe(g=>N.createElement(aXe,{className:g.className,controlAlignLeft:g.controlAlignLeft,editable:g.editable,handleConfigTrack:g.handleConfigTrack,handleResizeTrack:g.handleResizeTrack,height:g.height,item:g.item,onAddSeries:g.onAddSeries,onCloseTrack:g.onCloseTrack,onCloseTrackMenuOpened:g.onCloseTrackMenuOpened,onConfigTrackMenuOpened:g.onConfigTrackMenuOpened,resizeHandles:g.resizeHandles,uid:g.uid,width:g.width})),wQt={"vertical-tiled-plot":"_vertical-tiled-plot_f3ho8_1"};function VQt(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function rse(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function R2(g){return R2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},R2(g)}function ose(g){return g&&g.sourceEvent}let fO=function(g){HQt(I,g);var e=TQt(I);function I(i){var n;return VQt(this,I),n=e.call(this,i),n.brushBehavior=nw().on("start",n.brushStarted.bind(JW(n))).on("brush",n.brushed.bind(JW(n))).on("end",n.brushedEnded.bind(JW(n))),n}return RQt(I,[{key:"componentDidMount",value:function(){this.props.isRangeSelectionActive&&this.addBrush()}},{key:"shouldComponentUpdate",value:function(n,C){if(this.rangeSelectionTriggered)return this.rangeSelectionTriggered=!1,this.rangeSelectionTriggeredEnd&&this.props.rangeSelection!==n.rangeSelection&&this.moveBrush(n.rangeSelection[0]?n.rangeSelection[0]:null,!0),this.rangeSelectionTriggeredEnd=!1,this.state!==C;if(this.props.rangeSelection!==n.rangeSelection){const r=this.props.is1dRangeSelection?0:1;return this.moveBrush(n.rangeSelection[r]?n.rangeSelection[r]:null,n.rangeSelectionEnd),this.state!==C}return!0}},{key:"componentDidUpdate",value:function(){this.props.isRangeSelectionActive?this.addBrush():this.removeBrush()}},{key:"addBrush",value:function(){!this.brushEl||this.brushElAddedBefore===this.brushEl||(this.brushElAddedBefore&&this.brushElAddedBefore.on(".brush",null),this.brushEl.call(this.brushBehavior),this.brushElAddedBefore=this.brushEl,_p(this.brushEl,Lo["track-range-selection-group-brush-selection"]))}},{key:"brushed",value:function(n){const C=this.rangeSelectionMoved;this.rangeSelectionMoved=!1,!(!ose(n)||!this.props.onRangeSelection||C)&&(this.rangeSelectionTriggered=!0,this.props.onRangeSelection(n.selection))}},{key:"brushStarted",value:function(n){!ose(n)||!n.selection||this.props.onRangeSelectionStart()}},{key:"brushedEnded",value:function(n){if(!this.props.is1dRangeSelection)return;const C=this.rangeSelectionMovedEnd;this.rangeSelectionMovedEnd=!1,n.selection&&n.sourceEvent&&this.props.onRangeSelection&&!C&&(this.rangeSelectionTriggered=!0,this.rangeSelectionTriggeredEnd=!0,this.props.onRangeSelectionEnd(n.selection)),n.selection||(this.rangeSelectionTriggered=!0,this.props.onRangeSelectionReset())}},{key:"moveBrush",value:function(n,C=!1){if(!this.brushEl)return;const r=n?[this.props.scale(n[0]),this.props.scale(n[1])]:null;this.rangeSelectionMoved=!0,this.rangeSelectionMovedEnd=!0,C?this.brushEl.transition().call(this.brushBehavior.move,r):this.brushEl.call(this.brushBehavior.move,r)}},{key:"removeBrush",value:function(){this.brushElAddedBefore&&(this.brushElAddedBefore.call(this.brushBehavior.move,null),this.brushElAddedBefore.on(".brush",null),this.brushElAddedBefore=void 0,this.props.onRangeSelectionReset())}},{key:"render",value:function(){const n=this.props.tracks.map(o=>o.width).reduce(sc,0),C=this.props.tracks.map(o=>L0(o)).reduce(ow,!1),r=Lo[this.props.isRangeSelectionActive?"track-range-selection-active":"track-range-selection"];return N.createElement("div",{className:wQt["vertical-tiled-plot"]},C&&N.createElement("svg",{ref:o=>{this.brushEl=pg(o)},className:r,style:{height:this.props.height,width:n},xmlns:"http://www.w3.org/2000/svg"}),N.createElement(iY,{axis:"x",className:Tg(_o.list,_o.stylizedList,_o.horizontalList),component:AXe,editable:this.props.editable,handleConfigTrack:this.props.handleConfigTrack,handleResizeTrack:this.props.handleResizeTrack,height:this.props.height,helperClass:_o.stylizedHelper,itemClass:Tg(_o.stylizedItem,_o.horizontalItem),itemControlAlignLeft:this.props.tracksControlAlignLeft,itemReactClass:SQt,items:this.props.tracks.map(o=>({configMenuVisible:o.uid===this.props.configTrackMenuId,uid:o.uid||dg.nice(),height:this.props.height,width:o.width,value:o.value})),onAddSeries:this.props.onAddSeries,onCloseTrack:this.props.onCloseTrack,onCloseTrackMenuOpened:this.props.onCloseTrackMenuOpened,onConfigTrackMenuOpened:this.props.onConfigTrackMenuOpened,onSortEnd:this.props.handleSortEnd,referenceAncestor:this.props.referenceAncestor,resizeHandles:this.props.resizeHandles,useDragHandle:!0,width:n}))}}]),I}(N.Component);fO.propTypes={configTrackMenuId:L.string,editable:L.bool,handleConfigTrack:L.func,handleResizeTrack:L.func,handleSortEnd:L.func,is1dRangeSelection:L.bool,isRangeSelectionActive:L.bool,height:L.number,onAddSeries:L.func,onCloseTrack:L.func,onCloseTrackMenuOpened:L.func,onConfigTrackMenuOpened:L.func,onRangeSelection:L.func,onRangeSelectionEnd:L.func,onRangeSelectionReset:L.func,onRangeSelectionStart:L.func,rangeSelection:L.array,rangeSelectionEnd:L.bool,referenceAncestor:L.func,resizeHandles:L.object,scale:L.func,tracks:L.array,tracksControlAlignLeft:L.bool};function YQt(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function Ase(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function W2(g){return W2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},W2(g)}let h9e=function(g){FQt(I,g);var e=EQt(I);function I(){return YQt(this,I),e.apply(this,arguments)}return KQt(I,[{key:"render",value:function(){const n=A$(this.props.tracks,this.handleItemMouseEnter.bind(this),this.handleMouseLeave.bind(this)),C=this.props.customItems?N.Children.map(this.props.customItems,r=>N.cloneElement(r,{onMouseEnter:o=>{this.handleOtherMouseEnter(o)}})):null;return N.createElement("div",{ref:r=>{this.div=r},className:Tg(eg["context-menu"],{[eg["context-menu-dark"]]:this.props.theme===II}),"data-menu-type":"ViewContextMenu",style:{left:this.state.left,top:this.state.top}},C,C&&N.createElement("hr",{className:eg["context-menu-hr"]}),n,n&&N.createElement("hr",{className:eg["context-menu-hr"]}),N.createElement(og,{onClick:()=>this.props.onAddTrack({type:"horizontal-rule",y:this.props.coords[1],position:"whole"}),onMouseEnter:r=>this.handleOtherMouseEnter(r)},"Add Horizontal Rule"),N.createElement(og,{onClick:()=>this.props.onAddTrack({type:"vertical-rule",x:this.props.coords[0],position:"whole"}),onMouseEnter:r=>this.handleOtherMouseEnter(r)},"Add Vertical Rule"),N.createElement(og,{onClick:()=>this.props.onAddTrack({type:"cross-rule",x:this.props.coords[0],y:this.props.coords[1],position:"whole"}),onMouseEnter:r=>this.handleOtherMouseEnter(r)},"Add Cross Rule"),N.createElement("hr",{className:eg["context-menu-hr"]}),this.hasMatrixTrack(this.props.tracks)&&N.createElement(og,{onClick:this.handleAddHorizontalSection.bind(this),onMouseEnter:r=>this.handleOtherMouseEnter(r)},"Add Horizontal Cross Section"),this.hasMatrixTrack(this.props.tracks)&&N.createElement(og,{onClick:this.handleAddVerticalSection.bind(this),onMouseEnter:r=>this.handleOtherMouseEnter(r)},"Add Vertical Cross Section"),this.getSubmenu())}},{key:"hasMatrixTrack",value:function(n){return CW(this.props.tracks).filter(r=>r.type==="heatmap").length>0}},{key:"handleAddHorizontalSection",value:function(){const C=CW(this.props.tracks).filter(r=>r.type==="heatmap")[0];this.props.onAddTrack({type:"horizontal-rule",y:this.props.coords[1],position:"whole"}),this.props.onAddTrack({data:{type:"horizontal-section",server:C.server,tilesetUid:C.tilesetUid,slicePos:this.props.coords[1]},options:{valueScaling:"log"},type:"horizontal-bar",height:30,position:"top"})}},{key:"handleAddVerticalSection",value:function(){const C=CW(this.props.tracks).filter(r=>r.type==="heatmap")[0];this.props.onAddTrack({type:"vertical-rule",x:this.props.coords[0],position:"whole"}),this.props.onAddTrack({data:{type:"vertical-section",server:C.server,tilesetUid:C.tilesetUid,slicePos:this.props.coords[0]},options:{valueScaling:"log"},type:"vertical-bar",height:30,position:"left"})}}]),I}(uy(Ru).with(u9e));h9e.propTypes={coords:L.array,customItems:L.array};function JQt(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function ase(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function X2(g){return X2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},X2(g)}let a$=function(g){UQt(I,g);var e=QQt(I);function I(i){var n;JQt(this,I),n=e.call(this,i),n.closing=!1;const{tracks:C}=n.props;return n.canvasElement=null,n.tracksByUidInit={},[...n.props.tracks.top||[],...n.props.tracks.right||[],...n.props.tracks.bottom||[],...n.props.tracks.left||[],...n.props.tracks.gallery||[],...n.props.tracks.center||[]].forEach(r=>{r.type==="combined"?r.contents.forEach(o=>{n.tracksByUidInit[o.uid]=!1}):n.tracksByUidInit[r.uid]=!1}),n.xScale=null,n.yScale=null,n.addUidsToTracks(C),n.trackToReplace=null,n.trackRenderer=null,n.configTrackMenu=null,n.state={sizeMeasured:!1,height:10,width:10,tracks:C,init:!1,addTrackPosition:null,customDialog:null,mouseOverOverlayUid:null,forceUpdate:0,rangeSelection:[null,null],rangeSelectionEnd:!1,chromInfo:null,defaultChromSizes:null,contextMenuCustomItems:null,contextMenuPosition:null,addDivisorDialog:null},n.reset=!0,window.higlassTracksByType&&Object.keys(window.higlassTracksByType).forEach(r=>{$g[r]=window.higlassTracksByType[r].config}),n.topHeight=0,n.bottomHeight=0,n.leftWidth=0,n.rightWidth=0,n.centerHeight=0,n.centerWidth=0,n.dragTimeout=null,n.previousPropsStr="",n.contextMenuHandlerBound=n.contextMenuHandler.bind(tn(n)),n.handleNoTrackAddedBound=n.handleNoTrackAdded.bind(tn(n)),n.handleTracksAddedBound=n.handleTracksAdded.bind(tn(n)),n.closeMenusBound=n.closeMenus.bind(tn(n)),n.handleAddDivisorBound=n.handleAddDivisor.bind(tn(n)),n.handleAddSeriesBound=n.handleAddSeries.bind(tn(n)),n.handleChangeTrackDataBound=n.handleChangeTrackData.bind(tn(n)),n.handleChangeTrackTypeBound=n.handleChangeTrackType.bind(tn(n)),n.handleCloseTrackBound=n.handleCloseTrack.bind(tn(n)),n.handleConfigureTrackBound=n.handleConfigureTrack.bind(tn(n)),n.handleExportTrackDataBound=n.handleExportTrackData.bind(tn(n)),n.handleLockValueScaleBound=n.handleLockValueScale.bind(tn(n)),n.handleReplaceTrackBound=n.handleReplaceTrack.bind(tn(n)),n.handleTrackOptionsChangedBound=n.handleTrackOptionsChanged.bind(tn(n)),n.handleUnlockValueScaleBound=n.handleUnlockValueScale.bind(tn(n)),n.onAddTrack=n.handleAddTrack.bind(tn(n)),n}return OQt(I,[{key:"waitForDOMAttachment",value:function(n){if(!this.mounted)return;const C=QI.findDOMNode(this);document.body.contains(C)?n():requestAnimationFrame(()=>this.waitForDOMAttachment(n))}},{key:"componentDidMount",value:function(){this.mounted=!0,this.element=QI.findDOMNode(this),this.canvasElement=QI.findDOMNode(this.props.canvasElement),this.waitForDOMAttachment(()=>{N9.ElementQueries.listen(),this.resizeSensor=new N9.ResizeSensor(this.element.parentNode,this.measureSize.bind(this)),this.measureSize()}),this.addEventListeners(),this.pubSubs=[],this.pubSubs.push(this.props.pubSub.subscribe("contextmenu",this.contextMenuHandlerBound))}},{key:"UNSAFE_componentWillReceiveProps",value:function(n){this.addUidsToTracks(n.tracks),this.setState({tracks:n.tracks})}},{key:"shouldComponentUpdate",value:function(n,C){const r=this.previousPropsStr,o=this.updatablePropsToString(n),A=JSON.stringify(this.state),s=JSON.stringify(C),a=r!==o||A!==s||this.props.chooseTrackHandler!==n.chooseTrackHandler||this.props.customDialog!==n.customDialog;a&&(this.previousPropsStr=o);const l=this.numTracks;return this.numTracks=0,os(this.props.tracks,()=>this.numTracks++),this.reset=this.reset||l===0&&this.numTracks>0,this.numTracks||(this.tracksByUidInit={}),a}},{key:"UNSAFE_componentWillUpdate",value:function(){}},{key:"componentDidUpdate",value:function(n,C){if(C.rangeSelection!==this.state.rangeSelection){let r=[null,null];this.state.defaultChromSizes&&this.state.rangeSelection.every(o=>o&&o.length)&&(r=this.state.rangeSelection.map(o=>P9(...o,this.state.defaultChromSizes))),this.props.onRangeSelection({dataRange:this.state.rangeSelection,genomicRange:r})}if(this.state.customDialog||this.props.customDialog){const r=this.state.customDialog||this.props.customDialog;if(r.length>0){const o=[],A=[];r.forEach(s=>{o.push(s.bodyComponent),A.push(s.bodyProps)}),this.props.modal.open(N.createElement(o$,{children:o,bodyProps:A,onCancel:this.props.closeCustomDialog,title:r[0].title}))}}if(n.tracks.center,this.props.tracks.center,(this.state.addTrackPosition||this.props.addTrackPosition)&&this.props.modal.open(N.createElement(Z2,{host:this.state.addTrackHost,onCancel:this.handleNoTrackAddedBound,onTracksChosen:this.handleTracksAddedBound,position:this.state.addTrackPosition||this.props.addTrackPosition,trackSourceServers:this.props.trackSourceServers})),this.state.addDivisorDialog){const r=this.state.addDivisorDialog;this.props.modal.open(N.createElement(Z2,{datatype:$g[r.type].datatype[0],host:this.state.addTrackHost,onCancel:()=>{this.setState({addDivisorDialog:null})},onTracksChosen:o=>{this.handleDivisorChosen(r,o)},trackSourceServers:this.props.trackSourceServers}))}}},{key:"componentWillUnmount",value:function(){this.closing=!0,this.removeEventListeners(),this.pubSubs.forEach(n=>this.props.pubSub.unsubscribe(n))}},{key:"addUidsToTracks",value:function(n){Object.keys(n).forEach(C=>{n[C].forEach(r=>{r.uid=r.uid||dg.nice()})})}},{key:"contextMenuHandler",value:function(n){if(!this.divTiledPlot)return;const C=this.divTiledPlot.getBoundingClientRect();if(!RQ(n.clientX,n.clientY,C.left,C.left+C.width,C.top,C.top+C.height))return;const o=[n.clientX,n.clientY],A=Og(n,this.divTiledPlot),s=this.trackRenderer.zoomedXScale.invert(A[0]),a=this.trackRenderer.zoomedYScale.invert(A[1]);let l=null;n.hgCustomItems&&(l=n.hgCustomItems.map(c=>N.createElement(og,{key:c.key,onClick:c.onClick},c.text))),this.setState({contextMenuCustomItems:l,contextMenuPosition:{left:o[0],top:o[1],canvasLeft:A[0]+this.trackRenderer.xPositionOffset,canvasTop:A[1]+this.trackRenderer.yPositionOffset},contextMenuDataX:s,contextMenuDataY:a})}},{key:"measureSize",value:function(){this.element.clientWidth>0&&this.element.clientHeight>0&&this.setState({sizeMeasured:!0,width:this.element.clientWidth,height:this.element.clientHeight})}},{key:"handleTrackOptionsChanged",value:function(n,C){return this.props.onTrackOptionsChanged(n,C)}},{key:"handleScalesChanged",value:function(n,C){this.xScale=n,this.yScale=C,this.props.onScalesChanged(n,C)}},{key:"handleTilesetInfoReceived",value:function(n,C){const r=gr(this.props.tracks,n);if(!r){console.warn("Strange, track not found:",n);return}this.tracksByUidInit[r.uid]=!0,this.checkAllTilesetInfoReceived(),r.options||(r.options={}),r.name=C.name,r.maxWidth=C.max_width,r.transforms=C.transforms,r.aggregationModes=C.aggregation_modes,r.header=C.header,r.binsPerDimension=C.bins_per_dimension,C.resolutions?(r.maxZoom=C.resolutions.length-1,r.resolutions=C.resolutions):r.maxZoom=C.max_zoom,r.coordSystem=C.coordSystem,r.datatype=C.datatype}},{key:"checkAllTilesetInfoReceived",value:function(){if(this.state.init&&!this.reset||!this.trackRenderer||!this.props.zoomToDataExtentOnInit())return;const n=Object.keys(this.trackRenderer.trackDefObjects).map(r=>{const o=this.trackRenderer.trackDefObjects[r].trackObject;return o.childTracks?o.childTracks:o}).reduce((r,o)=>r.concat(o),[]).filter(({tilesetInfo:r})=>typeof r<"u"&&r!==!0),C=Object.values(this.tracksByUidInit).filter(r=>r).length;n.length===C&&(this.setState({init:!0}),this.reset=!1,this.handleZoomToData())}},{key:"handleOverlayMouseEnter",value:function(n){this.setState({mouseOverOverlayUid:n})}},{key:"handleOverlayMouseLeave",value:function(n){n===this.state.mouseOverOverlayUid&&this.setState({mouseOverOverlayUid:null})}},{key:"handleTrackPositionChosen",value:function(n){this.setState({mouseOverOverlayUid:null}),this.props.chooseTrackHandler(n.track.uid)}},{key:"handleNoTrackAdded",value:function(){this.trackToReplace=null,this.props.onNoTrackAdded(),this.setState({addTrackPosition:null,addTrackHost:null})}},{key:"handleAddDivisor",value:function(n){this.setState({addDivisorDialog:n})}},{key:"handleDivisorChosen",value:function(n,C){this.setState({addDivisorDialog:null});const r=n.data?{server:n.data.server,tilesetUid:n.data.tilesetUid}:{server:n.server,tilesetUid:n.tilesetUid},o={server:C[0].server,tilesetUid:C[0].uuid};this.handleChangeTrackData(n.uid,{type:"divided",children:[r,o]})}},{key:"handleDivideSeries",value:function(n){}},{key:"handleAddSeries",value:function(n){const C=gB(this.props.tracks,n),r=gr(this.props.tracks,n);this.setState({addTrackPosition:C,addTrackHost:r})}},{key:"handleReplaceTrack",value:function(n,C){this.trackToReplace=n,this.handleAddTrack(C)}},{key:"handleAddTrack",value:function(n){this.setState({addTrackPosition:n,addTrackHost:null})}},{key:"handleResizeTrack",value:function(n,C,r){const{tracks:o}=this.state;for(const A in o){const a=o[A].filter(l=>l.uid===n);a.length>0&&(a[0].width=C,a[0].height=r)}this.setState({tracks:o,forceUpdate:Math.random()}),this.props.onResizeTrack()}},{key:"closeMenus",value:function(){this.setState({closeTrackMenuId:null,configTrackMenuId:null,contextMenuPosition:null,contextMenuCustomItems:null})}},{key:"handleLockValueScale",value:function(n){this.closeMenus(),this.props.onLockValueScale(n)}},{key:"handleUnlockValueScale",value:function(n){this.closeMenus(),this.props.onUnlockValueScale(n)}},{key:"handleCloseTrack",value:function(n){this.closeMenus(),this.props.onCloseTrack(n)}},{key:"handleChangeTrackType",value:function(n,C){this.closeMenus(),this.props.onChangeTrackType(n,C)}},{key:"handleChangeTrackData",value:function(n,C){this.closeMenus(),this.props.onChangeTrackData(n,C)}},{key:"handleTracksAdded",value:function(n,C,r){return this.trackToReplace&&(this.handleCloseTrack(this.trackToReplace),this.trackToReplace=null),this.props.onTracksAdded(n,C,r),this.setState({addTrackPosition:null,addTrackHost:null}),n}},{key:"handleCloseTrackMenuOpened",value:function(n,C){this.setState({closeTrackMenuId:n,closeTrackMenuLocation:C})}},{key:"handleCloseContextMenu",value:function(){this.setState({contextMenuCustomItems:null,contextMenuPosition:null,contextMenuDataX:null,contextMenuDataY:null})}},{key:"handleCloseTrackMenuClosed",value:function(){this.setState({closeTrackMenuId:null})}},{key:"handleConfigTrackMenuOpened",value:function(n,C){this.closeMenus(),this.setState({configTrackMenuId:n,configTrackMenuLocation:C})}},{key:"handleConfigureTrack",value:function(n,C){this.setState({configTrackMenuId:null,trackOptions:{track:n,configComponent:C}}),this.closeMenus()}},{key:"handleSortEnd",value:function(n){this.setState(C=>{const r=C.tracks,o={};for(let A=0;A{C[r]&&C[r].forEach(o=>{o.contents&&o.contents.forEach(A=>{A.position=r}),o.position=r,n.push({track:o,location:r})})}),n}},{key:"calculateTrackPosition",value:function(n,C){let r=this.props.paddingTop,o=this.props.paddingBottom,A=this.props.paddingLeft,s=this.props.paddingRight,a=this.centerWidth,l=n.height,c=0,u=0;switch(C){case"top":A+=this.leftWidth;for(let d=0;dr.includes&&r.includes.length).map(r=>{const o=r.type?`overlay-${r.type}-track`:"overlay-track",A={...r,uid:r.uid||dg.nice(),includes:r.includes,type:o,options:Object.assign(r.options,{orientationsAndPositions:r.includes.map(s=>{const a=gr(this.props.tracks,s);if(!a)return console.warn(`OverlayTrack included uid (${s}) not found in the track list`),null;const l=gB(this.props.tracks,a.uid);let c;if((l==="top"||l==="bottom")&&(c="1d-horizontal"),(l==="left"||l==="right")&&(c="1d-vertical"),l==="center"&&(c="2d"),!c)return console.warn("Only top, bottom, left, right, or center tracks can be overlaid at the moment"),null;const u=n.filter(h=>h.track.uid===s);if(!u.length)return null;const d={left:u[0].left-this.props.paddingLeft,top:u[0].top-this.props.paddingTop,width:u[0].width,height:u[0].height};return{orientation:c,position:d}}).filter(s=>s)})};return{top:this.props.paddingTop,left:this.props.paddingLeft,width:this.leftWidth+this.centerWidth+this.rightWidth,height:this.topHeight+this.centerHeight+this.bottomHeight+this.props.marginTop+this.props.marginBottom,track:A}}):[]}},{key:"positionedTracks",value:function(){return this.createTracksAndLocations().map(({track:C,location:r})=>this.calculateTrackPosition(C,r))}},{key:"createTrackPositionTexts",value:function(){const n=this.positionedTracks();return this.createTracksAndLocations(),n.map(r=>{const{track:o}=r;return N.createElement("div",{key:o.uid,style:{left:r.left,top:r.top,width:r.width,height:r.height,position:"absolute"}},o.uid.slice(0,2))})}},{key:"handleExportTrackData",value:function(n,C){const r=gr(this.props.tracks,C);let o=null;n!==C?o=this.trackRenderer.trackDefObjects[n].trackObject.createdTracks[r.uid]:{trackObject:o}=this.trackRenderer.trackDefObjects[n],o.exportData(),this.closeMenus()}},{key:"listTracksAtPosition",value:function(n,C,r=!1){const o=[];if(!this.trackRenderer)return[];for(const A in this.trackRenderer.trackDefObjects){const s=this.trackRenderer.trackDefObjects[A].trackObject;if(s.respondsToPosition(n,C))if(r){if(this.props.tracks.center)if(this.props.tracks.center.contents)for(let a=0;ao[d]&&(o[d]=u.tilesetInfo.max_pos[d]);const s=this.trackRenderer.currentProps.paddingLeft+this.trackRenderer.currentProps.leftWidth;let a=[s,s+this.trackRenderer.currentProps.centerWidth].map(this.trackRenderer.zoomTransform.rescaleX(this.trackRenderer.xScale).invert);const l=this.trackRenderer.currentProps.paddingTop+this.trackRenderer.currentProps.topHeight;let c=[l,l+this.trackRenderer.currentProps.centerHeight].map(this.trackRenderer.zoomTransform.rescaleY(this.trackRenderer.yScale).invert);this.trackRenderer.zoomTransform.k=1,this.trackRenderer.zoomTransform.x=0,this.trackRenderer.zoomTransform.y=0,this.trackRenderer.applyZoomTransform(),r[0]Number.MIN_SAFE_INTEGER&&(a=[r[0],o[0]]),r[1]Number.MIN_SAFE_INTEGER&&(c=[r[1],o[1]]),this.props.onDataDomainChanged(a,c)}},{key:"resetViewport",value:function(){this.trackRenderer.zoomTransform.k=1,this.trackRenderer.zoomTransform.x=0,this.trackRenderer.zoomTransform.y=0,this.trackRenderer.applyZoomTransform(),this.props.onDataDomainChanged(this.props.initialXDomain,this.props.initialYDomain)}},{key:"updatablePropsToString",value:function(n){return JSON.stringify({tracks:n.tracks,overlays:n.overlays,viewOptions:n.viewOptions,uid:n.uid,addTrackPosition:n.addTrackPosition,editable:n.editable,marginTop:n.marginTop,marginBottom:n.marginBottom,marginLeft:n.marginLeft,marginRight:n.marginRight,paddingTop:n.paddingTop,paddingBottom:n.paddingBottom,paddingLeft:n.paddingLeft,paddingRight:n.paddingRight,mouseTool:n.mouseTool,initialXDomain:n.initialXDomain,initialYDomain:n.initialYDomain,trackSourceServers:n.trackSourceServers,zoomable:n.zoomable,draggingHappening:n.draggingHappening})}},{key:"getXYScales",value:function(){this.trackRenderer&&(this.xScale=this.trackRenderer.currentXScale,this.yScale=this.trackRenderer.currentYScale)}},{key:"rangeViewToDataLoci",value:function(n,C){return C?[parseInt(C.invert(n[0]),10),parseInt(C.invert(n[1]),10)]:[null,null]}},{key:"rangeSelectionResetHandler",value:function(){this.state.rangeSelectionMaster&&this.setState({is1dRangeSelection:null,rangeSelection:[null,null],rangeSelectionMaster:null,rangeSelectionEnd:!1})}},{key:"rangeSelection1dEndHandler",value:function(n){(!this.xScale||!this.yScale)&&this.getXYScales();const C=n==="x"?this.xScale:this.yScale;return r=>{this.setState(o=>{const A=o.is1dRangeSelection?[null,null]:o.rangeSelection.slice(),s=!this.state.is1dRangeSelection&&n==="y"?1:0;let a=this.rangeViewToDataLoci(r,C);const l=a[1]-a[0];if(this.props.rangeSelection1dSize[0]>l){const c=a[0]+l/2;a=[c-this.props.rangeSelection1dSize[0]/2,c+this.props.rangeSelection1dSize[0]/2]}else if(this.props.rangeSelection1dSize[1]Math.round(c))),{rangeSelection:A,rangeSelectionEnd:!0}})}}},{key:"rangeSelection1dHandler",value:function(n){(!this.xScale||!this.yScale)&&this.getXYScales();const C=n==="x"?this.xScale:this.yScale;return r=>{this.setState(o=>{const A=o.is1dRangeSelection?[null,null]:o.rangeSelection.slice(),s=!o.is1dRangeSelection&&n==="y"?1:0;return A[s]=this.rangeViewToDataLoci(r,C),{rangeSelection:A,rangeSelectionEnd:!1}})}}},{key:"rangeSelection1dStartHandler",value:function(){this.state.rangeSelectionMaster||this.setState({is1dRangeSelection:!0,rangeSelectionMaster:!0,rangeSelectionEnd:!1})}},{key:"rangeSelection2dHandler",value:function(n){(!this.xScale||!this.yScale)&&this.getXYScales(),this.setState({rangeSelection:[this.rangeViewToDataLoci(n[0],this.xScale),this.rangeViewToDataLoci(n[1],this.yScale)],rangeSelectionEnd:!1})}},{key:"rangeSelection2dStartHandler",value:function(){this.state.rangeSelectionMaster||this.setState({is1dRangeSelection:!1,rangeSelectionMaster:!0,rangeSelectionEnd:!1})}},{key:"rangeSelection2dEndHandler",value:function(n){(!this.xScale||!this.yScale)&&this.getXYScales();const C=this.rangeViewToDataLoci(n[0],this.xScale),r=this.rangeViewToDataLoci(n[1],this.yScale);let o=[C,r];const A=C[1]-C[0],s=r[1]-r[0],a=[A,s];o.forEach((l,c)=>{if(this.props.rangeSelection1dSize[0]>a[c]){const u=l[0]+Math.round(a[c]/2);l[0]=u-this.props.rangeSelection1dSize[0]/2,l[1]=u+this.props.rangeSelection1dSize[0]/2}else if(this.props.rangeSelection1dSize[1]l.map(c=>Math.round(c)))),this.setState({rangeSelection:o,rangeSelectionEnd:!0})}},{key:"getContextMenu",value:function(){if(this.state.contextMenuPosition){const n=this.listTracksAtPosition(this.state.contextMenuPosition.canvasLeft,this.state.contextMenuPosition.canvasTop);return N.createElement($c,{onMenuClosed:this.closeMenusBound},N.createElement(h9e,{closeMenu:this.closeMenusBound,coords:[this.state.contextMenuDataX,this.state.contextMenuDataY],customItems:this.state.contextMenuCustomItems,onAddDivisor:this.handleAddDivisorBound,onAddSeries:this.handleAddSeriesBound,onAddTrack:C=>{this.props.onTracksAdded([C],C.position,null),this.handleCloseContextMenu()},onChangeTrackData:this.handleChangeTrackDataBound,onChangeTrackType:this.handleChangeTrackTypeBound,onCloseTrack:this.handleCloseTrackBound,onConfigureTrack:this.handleConfigureTrackBound,onExportData:this.handleExportTrackDataBound,onLockValueScale:this.handleLockValueScaleBound,onReplaceTrack:this.handleReplaceTrackBound,onTrackOptionsChanged:this.handleTrackOptionsChangedBound,onUnlockValueScale:this.handleUnlockValueScaleBound,orientation:"right",position:this.state.contextMenuPosition,theme:this.props.theme,tracks:n,trackSourceServers:this.props.trackSourceServers}))}return null}},{key:"getIdealizedTrackPositionsOverlay",value:function(){const n=this.props.draggingHappening,C=n.datatype;if(!(C in Ev)&&!n.defaultTracks){console.warn("unknown data type:",n.higlassTrack);return}const r={"1d-horizontal":["top","bottom","left","right"],"2d":["center"],"1d-vertical":["left","right"]},o=Ev[C]||{};if(n.defaultTracks)for(const S of n.defaultTracks)if(!$g[S])console.warn("unknown track type",S);else for(const X of r[$g[S].orientation])o[X]=S;const A=new Set(["top","left","right","center","bottom"].filter(S=>S in this.state.tracks&&this.state.tracks[S].length)),s="top"in o,a="left"in o,l="right"in o,c="bottom"in o,u="center"in o,d="center"in o||A.has("left")||A.has("right")||A.has("center"),h="top"in o,m="bottom"in o&&d,f="left"in o&&d,b="right"in o&&d,p=Object.keys(o).length&&("center"in o||d),y=N.createElement("div",{style:{flexGrow:1}}),Z=N.cloneElement(y),v=N.createElement("div",{style:{display:"flex",flexGrow:1}},h&&(p||f)?y:null,N.createElement(TR,{defaultTrackType:o.top,draggingHappening:this.props.draggingHappening,enabled:s,onTrackDropped:S=>this.handleTracksAdded([S],"top"),style:{border:"1px solid black",flexGrow:1}}),h&&(p||f)?Z:null),G=N.createElement("div",{style:{display:"flex",flexGrow:1}},h&&(p||f)?y:null,N.createElement(TR,{defaultTrackType:o.bottom,draggingHappening:this.props.draggingHappening,enabled:c,onTrackDropped:S=>this.handleTracksAdded([S],"bottom"),style:{border:"1px solid black",flexGrow:1}}),h&&(p||f)?Z:null),B=N.createElement(TR,{defaultTrackType:o.left,draggingHappening:this.props.draggingHappening,enabled:a,onTrackDropped:S=>this.handleTracksAdded([S],"left"),style:{border:"1px solid black",flexGrow:1}}),w=N.createElement(TR,{defaultTrackType:o.center,draggingHappening:this.props.draggingHappening,enabled:u,onTrackDropped:S=>this.handleTracksAdded([S],"center"),position:"center",style:{border:"1px solid black",flexGrow:1}}),R=N.cloneElement(B,{defaultTrackType:o.right,enabled:l,onTrackDropped:S=>this.handleTracksAdded([S],"right")});return N.createElement("div",{style:{position:"absolute",left:"0px",top:"0px",width:this.state.width,height:this.state.height}},N.createElement("div",{style:{position:"absolute",width:this.state.width,height:this.state.height,background:"white",opacity:.4}}),N.createElement("div",{style:{width:this.state.width,height:this.state.height,position:"absolute",display:"flex",flexDirection:"column"}},h?v:null,d&&N.createElement("div",{style:{display:"flex",height:h||m?"40%":"100%",width:"100%"}},f?B:null,p?w:null,b?R:null),m?G:null))}},{key:"render",value:function(){this.galleryDim=this.props.tracks.gallery?this.props.tracks.gallery.map(p=>p.height).reduce(sc,0):0,this.topHeightNoGallery=this.props.tracks.top.map(p=>p.height).reduce(sc,0),this.topHeight=this.topHeightNoGallery+this.galleryDim,this.bottomHeightNoGallery=this.props.tracks.bottom.map(p=>p.height).reduce(sc,0),this.bottomHeight=this.bottomHeightNoGallery+this.galleryDim,this.leftWidthNoGallery=this.props.tracks.left.map(p=>p.width).reduce(sc,0),this.leftWidth=this.leftWidthNoGallery+this.galleryDim,this.rightWidthNoGallery=this.props.tracks.right.map(p=>p.width).reduce(sc,0),this.rightWidth=this.rightWidthNoGallery+this.galleryDim;const n=this.props.paddingTop+this.props.paddingBottom,C=this.props.paddingLeft+this.props.paddingRight;this.centerHeight=Math.max(0,this.state.height-this.topHeight-this.bottomHeight-n),this.centerWidth=Math.max(0,this.state.width-this.leftWidth-this.rightWidth-C);const r="none",o=N.createElement("div",{className:"top-track-container",style:{left:this.leftWidth+this.props.paddingLeft,top:this.props.paddingTop,width:this.centerWidth,height:this.topHeightNoGallery,outline:r,position:"absolute"}},N.createElement(o2,{configTrackMenuId:this.state.configTrackMenuId,editable:this.props.editable,handleConfigTrack:this.handleConfigTrackMenuOpened.bind(this),handleResizeTrack:this.handleResizeTrack.bind(this),handleSortEnd:this.handleSortEnd.bind(this),is1dRangeSelection:this.state.is1dRangeSelection,isRangeSelectionActive:this.props.mouseTool===Jr,onAddSeries:this.handleAddSeries.bind(this),onCloseTrack:this.handleCloseTrack.bind(this),onCloseTrackMenuOpened:this.handleCloseTrackMenuOpened.bind(this),onConfigTrackMenuOpened:this.handleConfigTrackMenuOpened.bind(this),onRangeSelection:this.rangeSelection1dHandler("x").bind(this),onRangeSelectionEnd:this.rangeSelection1dEndHandler("x").bind(this),onRangeSelectionReset:this.rangeSelectionResetHandler.bind(this),onRangeSelectionStart:this.rangeSelection1dStartHandler.bind(this),rangeSelection:this.state.rangeSelection,rangeSelectionEnd:this.state.rangeSelectionEnd,resizeHandles:new Set(["bottom"]),scale:this.xScale,tracks:this.props.tracks.top,width:this.centerWidth})),A=N.createElement("div",{className:"left-track-container",style:{left:this.props.paddingLeft,top:this.topHeight+this.props.paddingTop,width:this.leftWidthNoGallery,height:this.centerHeight,outline:r,position:"absolute"}},N.createElement(fO,{configTrackMenuId:this.state.configTrackMenuId,editable:this.props.editable,handleConfigTrack:this.handleConfigTrackMenuOpened.bind(this),handleResizeTrack:this.handleResizeTrack.bind(this),handleSortEnd:this.handleSortEnd.bind(this),height:this.centerHeight,is1dRangeSelection:this.state.is1dRangeSelection,isRangeSelectionActive:this.props.mouseTool===Jr,onAddSeries:this.handleAddSeries.bind(this),onCloseTrack:this.handleCloseTrack.bind(this),onCloseTrackMenuOpened:this.handleCloseTrackMenuOpened.bind(this),onConfigTrackMenuOpened:this.handleConfigTrackMenuOpened.bind(this),onRangeSelection:this.rangeSelection1dHandler("y").bind(this),onRangeSelectionEnd:this.rangeSelection1dEndHandler("y").bind(this),onRangeSelectionReset:this.rangeSelectionResetHandler.bind(this),onRangeSelectionStart:this.rangeSelection1dStartHandler.bind(this),rangeSelection:this.state.rangeSelection,rangeSelectionEnd:this.state.rangeSelectionEnd,resizeHandles:new Set(["right"]),scale:this.yScale,tracks:this.props.tracks.left})),s=N.createElement("div",{className:"right-track-container",style:{right:this.props.paddingRight,top:this.topHeight+this.props.paddingTop,width:this.rightWidthNoGallery,height:this.centerHeight,outline:r,position:"absolute"}},N.createElement(fO,{configTrackMenuId:this.state.configTrackMenuId,editable:this.props.editable,handleConfigTrack:this.handleConfigTrackMenuOpened.bind(this),handleResizeTrack:this.handleResizeTrack.bind(this),handleSortEnd:this.handleSortEnd.bind(this),height:this.centerHeight,is1dRangeSelection:this.state.is1dRangeSelection,isRangeSelectionActive:this.props.mouseTool===Jr,onAddSeries:this.handleAddSeries.bind(this),onCloseTrack:this.handleCloseTrack.bind(this),onCloseTrackMenuOpened:this.handleCloseTrackMenuOpened.bind(this),onConfigTrackMenuOpened:this.handleConfigTrackMenuOpened.bind(this),onRangeSelection:this.rangeSelection1dHandler("y").bind(this),onRangeSelectionEnd:this.rangeSelection1dEndHandler("y").bind(this),onRangeSelectionReset:this.rangeSelectionResetHandler.bind(this),onRangeSelectionStart:this.rangeSelection1dStartHandler.bind(this),rangeSelection:this.state.rangeSelection,rangeSelectionEnd:this.state.rangeSelectionEnd,resizeHandles:new Set(["left"]),scale:this.yScale,tracks:this.props.tracks.right,tracksControlAlignLeft:!0})),a=N.createElement("div",{className:"bottom-track-container",style:{left:this.leftWidth+this.props.paddingLeft,bottom:this.props.paddingBottom,width:this.centerWidth,height:this.bottomHeightNoGallery,outline:r,position:"absolute"}},N.createElement(o2,{configTrackMenuId:this.state.configTrackMenuId,editable:this.props.editable,handleConfigTrack:this.handleConfigTrackMenuOpened.bind(this),handleResizeTrack:this.handleResizeTrack.bind(this),handleSortEnd:this.handleSortEnd.bind(this),is1dRangeSelection:this.state.is1dRangeSelection,isRangeSelectionActive:this.props.mouseTool===Jr,onAddSeries:this.handleAddSeries.bind(this),onCloseTrack:this.handleCloseTrack.bind(this),onCloseTrackMenuOpened:this.handleCloseTrackMenuOpened.bind(this),onConfigTrackMenuOpened:this.handleConfigTrackMenuOpened.bind(this),onRangeSelection:this.rangeSelection1dHandler("x").bind(this),onRangeSelectionEnd:this.rangeSelection1dEndHandler("x").bind(this),onRangeSelectionReset:this.rangeSelectionResetHandler.bind(this),onRangeSelectionStart:this.rangeSelection1dStartHandler.bind(this),rangeSelection:this.state.rangeSelection,rangeSelectionEnd:this.state.rangeSelectionEnd,resizeHandles:new Set(["top"]),scale:this.xScale,tracks:this.props.tracks.bottom,width:this.centerWidth})),l=N.createElement("div",{key:"galleryTracksDiv",className:"gallery-track-container",style:{left:this.leftWidthNoGallery+this.props.paddingLeft,top:this.topHeightNoGallery+this.props.paddingTop,width:this.centerWidth+2*this.galleryDim,height:this.centerHeight+2*this.galleryDim,outline:r,position:"absolute"}},N.createElement(QVe,{configTrackMenuId:this.state.configTrackMenuId,editable:this.props.editable,height:this.centerHeight+2*this.galleryDim,onAddSeries:this.handleAddSeries.bind(this),onCloseTrack:this.handleCloseTrack.bind(this),onCloseTrackMenuOpened:this.handleCloseTrackMenuOpened.bind(this),onConfigTrackMenuOpened:this.handleConfigTrackMenuOpened.bind(this),tracks:this.props.tracks.gallery,width:this.centerWidth+2*this.galleryDim}));let c=N.createElement("div",{className:["center-track-container",_z["center-track-container"]].join(" "),style:{left:this.leftWidth+this.props.paddingLeft,top:this.topHeight+this.props.paddingTop,width:this.centerWidth,height:this.bottomHeight,outline:r}});this.props.tracks.center.length&&(c=N.createElement("div",{className:["center-track-container",_z["center-track-container"]].join(" "),style:{left:this.leftWidth+this.props.paddingLeft,top:this.topHeight+this.props.paddingTop,width:this.centerWidth,height:this.centerHeight,outline:r}},N.createElement(xj,{configTrackMenuId:this.state.configTrackMenuId,editable:this.props.editable,height:this.centerHeight,is1dRangeSelection:this.state.is1dRangeSelection,isRangeSelectionActive:this.props.mouseTool===Jr,onAddSeries:this.handleAddSeries.bind(this),onCloseTrackMenuOpened:this.handleCloseTrackMenuOpened.bind(this),onConfigTrackMenuOpened:this.handleConfigTrackMenuOpened.bind(this),onRangeSelectionReset:this.rangeSelectionResetHandler.bind(this),onRangeSelectionStart:this.rangeSelection2dStartHandler.bind(this),onRangeSelectionX:this.rangeSelection1dHandler("x").bind(this),onRangeSelectionXEnd:this.rangeSelection1dEndHandler("x").bind(this),onRangeSelectionXY:this.rangeSelection2dHandler.bind(this),onRangeSelectionXYEnd:this.rangeSelection2dEndHandler.bind(this),onRangeSelectionY:this.rangeSelection1dHandler("y").bind(this),onRangeSelectionYEnd:this.rangeSelection1dEndHandler("y").bind(this),rangeSelection:this.state.rangeSelection,rangeSelectionEnd:this.state.rangeSelectionEnd,scaleX:this.xScale,scaleY:this.yScale,tracks:this.props.tracks.center,uid:this.props.tracks.center[0].uid,width:this.centerWidth}))),this.createTrackPositionTexts();let u=this.positionedTracks();u=u.concat(this.overlayTracks(u));let d=null;this.state.sizeMeasured&&(d=N.createElement(DUt,{ref:p=>{this.trackRenderer=p,this.checkAllTilesetInfoReceived()},canvasElement:this.canvasElement,centerHeight:this.centerHeight,centerWidth:this.centerWidth,disableTrackMenu:this.props.disableTrackMenu,dragging:this.props.dragging,galleryDim:this.galleryDim,getLockGroupExtrema:this.props.getLockGroupExtrema,height:this.state.height,initialXDomain:this.props.initialXDomain,initialYDomain:this.props.initialYDomain,isRangeSelection:this.props.mouseTool===Jr,isShowGlobalMousePosition:this.props.isShowGlobalMousePosition,isValueScaleLocked:this.props.isValueScaleLocked,leftWidth:this.leftWidth,leftWidthNoGallery:this.leftWidthNoGallery,metaTracks:this.props.metaTracks,onMouseMoveZoom:this.props.onMouseMoveZoom,onNewTilesLoaded:this.props.onNewTilesLoaded,onScalesChanged:this.handleScalesChanged.bind(this),onTilesetInfoReceived:this.handleTilesetInfoReceived.bind(this),onTrackOptionsChanged:this.handleTrackOptionsChanged.bind(this),onValueScaleChanged:this.props.onValueScaleChanged,paddingLeft:this.props.paddingLeft,paddingTop:this.props.paddingTop,pixiRenderer:this.props.pixiRenderer,pixiStage:this.props.pixiStage,pluginDataFetchers:this.props.pluginDataFetchers,pluginTracks:this.props.pluginTracks,positionedTracks:u,registerDraggingChangedListener:this.props.registerDraggingChangedListener,removeDraggingChangedListener:this.props.removeDraggingChangedListener,setCentersFunction:this.props.setCentersFunction,svgElement:this.props.svgElement,topHeight:this.topHeight,topHeightNoGallery:this.topHeightNoGallery,uid:this.props.uid,viewOptions:this.props.viewOptions,width:this.state.width,xDomainLimits:this.props.xDomainLimits,yDomainLimits:this.props.yDomainLimits,zoomable:this.props.zoomable,zoomLimits:this.props.zoomLimits},o,A,s,a,l,c));let h=null,m=null;this.state.configTrackMenuId&&(h=N.createElement($c,{onMenuClosed:this.closeMenusBound},N.createElement(mQt,{ref:p=>{this.configTrackMenu=p},closeMenu:this.closeMenusBound,onAddDivisor:this.handleAddDivisorBound,onAddSeries:this.handleAddSeriesBound,onAddTrack:this.handleAddTrackBound,onChangeTrackType:this.handleChangeTrackTypeBound,onCloseTrack:this.handleCloseTrackBound,onConfigureTrack:this.handleConfigureTrackBound,onExportData:this.handleExportTrackDataBound,onLockValueScale:this.handleLockValueScaleBound,onReplaceTrack:this.handleReplaceTrackBound,onTrackOptionsChanged:this.handleTrackOptionsChangedBound,onUnlockValueScale:this.handleUnlockValueScaleBound,position:this.state.configTrackMenuLocation,theme:this.props.theme,trackOrientation:gB(this.props.tracks,this.state.configTrackMenuId),tracks:[gr(this.props.tracks,this.state.configTrackMenuId)]}))),this.state.closeTrackMenuId&&(m=N.createElement($c,{onMenuClosed:this.handleCloseTrackMenuClosed.bind(this)},N.createElement(Ru,{position:this.state.closeTrackMenuLocation,theme:this.props.theme},N.createElement(d9e,{onCloseTrack:this.handleCloseTrack.bind(this),tracks:[gr(this.props.tracks,this.state.closeTrackMenuId)]}))));let f=null;this.props.chooseTrackHandler&&(f=u.filter(p=>p.track.position!=="whole").map(p=>{let y="transparent",Z="none";return this.state.mouseOverOverlayUid===p.track.uid&&(y="yellow",Z="1px solid black"),N.createElement("div",{key:p.track.uid,className:"tiled-plot-track-overlay",onClick:()=>this.handleTrackPositionChosen(p),onDragEnter:v=>{this.handleOverlayMouseEnter(p.track.uid),v.preventDefault()},onDragLeave:()=>this.handleOverlayMouseLeave(p.track.uid),onDragOver:v=>v.preventDefault(),onDrop:()=>this.handleTrackPositionChosen(p),onMouseEnter:()=>this.handleOverlayMouseEnter(p.track.uid),onMouseLeave:()=>this.handleOverlayMouseLeave(p.track.uid),style:{position:"absolute",left:p.left,top:p.top,width:p.width,height:p.height,background:y,opacity:.4,border:Z,zIndex:1}})}));let b=null;if(this.xScale&&this.yScale&&this.props.editable&&this.state.trackOptions){const p=this.state.trackOptions.configComponent,y=this.state.trackOptions.track;b=N.createElement(p,{track:y,xScale:this.xScale,yScale:this.yScale,onCancel:()=>{this.setState({trackOptions:null})},onTrackOptionsChanged:Z=>Z,onSubmit:Z=>{this.handleTrackOptionsChanged(this.state.trackOptions.track.uid,Z),this.setState({trackOptions:null})}})}return N.createElement("div",{ref:p=>{this.divTiledPlot=p},className:["tiled-plot-div",_o["tiled-plot"]].join(" "),style:{marginBottom:this.props.marginBottom,marginLeft:this.props.marginLeft,marginRight:this.props.marginRight,marginTop:this.props.marginTop}},d,f,h,m,b,this.getContextMenu(),this.props.draggingHappening&&this.getIdealizedTrackPositionsOverlay())}},{key:"addEventListeners",value:function(){this.eventListeners=[],this.eventListeners.forEach(n=>document.addEventListener(n.name,n.callback,!1))}},{key:"removeEventListeners",value:function(){this.eventListeners.forEach(n=>document.removeEventListener(n.name,n.callback))}}]),I}(N.Component);a$.defaultProps={isShowGlobalMousePosition:!1,pluginDataFetchers:{},pluginTracks:{},metaTracks:[],zoomable:!0};a$.propTypes={addTrackPosition:L.string,canvasElement:L.object,chooseTrackHandler:L.func,chromInfoPath:L.string,customDialog:L.array,closeCustomDialog:L.func,disableTrackMenu:L.bool,dragging:L.bool,draggingHappening:L.bool,editable:L.bool,getLockGroupExtrema:L.func,initialXDomain:L.array,initialYDomain:L.array,isShowGlobalMousePosition:L.bool,isValueScaleLocked:L.func,marginBottom:L.number.isRequired,marginLeft:L.number.isRequired,marginRight:L.number.isRequired,marginTop:L.number.isRequired,paddingBottom:L.number.isRequired,paddingLeft:L.number.isRequired,paddingRight:L.number.isRequired,paddingTop:L.number.isRequired,metaTracks:L.array,modal:L.object,mouseTool:L.string,onCloseTrack:L.func,onChangeTrackData:L.func,onChangeTrackType:L.func,onDataDomainChanged:L.func,onLockValueScale:L.func,onMouseMoveZoom:L.func,onNewTilesLoaded:L.func,onNoTrackAdded:L.func,onRangeSelection:L.func.isRequired,onScalesChanged:L.func,onTrackOptionsChanged:L.func,onTrackPositionChosen:L.func,onTracksAdded:L.func,onUnlockValueScale:L.func,onValueScaleChanged:L.func,onResizeTrack:L.func,overlays:L.array,openModal:L.func,pixiRenderer:L.object,pixiStage:L.object,pluginDataFetchers:L.object,pluginTracks:L.object,pubSub:L.object.isRequired,rangeSelection1dSize:L.array,rangeSelectionToInt:L.bool,registerDraggingChangedListener:L.func,removeDraggingChangedListener:L.func,setCentersFunction:L.func,svgElement:L.object,theme:L.symbol.isRequired,tracks:L.object,trackSourceServers:L.array,uid:L.string,viewOptions:L.object,xDomainLimits:L.array,yDomainLimits:L.array,zoomable:L.bool,zoomLimits:L.array,zoomToDataExtentOnInit:L.func};const qQt=ry(CY(ym(a$)));var ejt=Object.assign||function(g){for(var e=1;e"u"?"undefined":tjt(e))==="object"){for(var n in e)e.hasOwnProperty(n)&&ab(g,n,e[n]);return}if(typeof i<"u"){typeof i=="number"&&(i+="px"),g.style[e]=i;return}return Mh(g,e)}s$(["width","height"],function(g){var e=g.charAt(0).toUpperCase()+g.slice(1);la["outer"+e]=function(i,n){return i&&lse(i,g,n?sjt:BO)};var I=g==="width"?["Left","Right"]:["Top","Bottom"];la[g]=function(i,n){if(n!==void 0){if(i){Mh(i);var C=p9e(i);return C&&(n+=BG(i,["padding","border"],I)),ab(i,g,n)}return}return i&&lse(i,g,GO)}});function ujt(g,e){ab(g,"position")==="static"&&(g.style.position="relative");var I=f9e(g),i={},n=void 0,C=void 0;for(C in e)e.hasOwnProperty(C)&&(n=parseFloat(ab(g,C))||0,i[C]=n+e[C]-I[C]);ab(g,i)}var djt=ejt({getWindow:function(e){var I=e.ownerDocument||e;return I.defaultView||I.parentWindow},offset:function(e,I){if(typeof I<"u")ujt(e,I);else return f9e(e)},isWindow:OW,each:s$,css:ab,clone:function(e){var I={};for(var i in e)e.hasOwnProperty(i)&&(I[i]=e[i]);var n=e.overflow;if(n)for(var i in e)e.hasOwnProperty(i)&&(I.overflow[i]=e.overflow[i]);return I},scrollLeft:function(e,I){if(OW(e)){if(I===void 0)return yO(e);window.scrollTo(I,ZO(e))}else{if(I===void 0)return e.scrollLeft;e.scrollLeft=I}},scrollTop:function(e,I){if(OW(e)){if(I===void 0)return ZO(e);window.scrollTo(yO(e),I)}else{if(I===void 0)return e.scrollTop;e.scrollTop=I}},viewportWidth:0,viewportHeight:0},la),iI=djt;function hjt(g,e,I){I=I||{},e.nodeType===9&&(e=iI.getWindow(e));var i=I.allowHorizontalScroll,n=I.onlyScrollIfNeeded,C=I.alignWithTop,r=I.alignWithLeft,o=I.offsetTop||0,A=I.offsetLeft||0,s=I.offsetBottom||0,a=I.offsetRight||0;i=i===void 0?!0:i;var l=iI.isWindow(e),c=iI.offset(g),u=iI.outerHeight(g),d=iI.outerWidth(g),h=void 0,m=void 0,f=void 0,b=void 0,p=void 0,y=void 0,Z=void 0,v=void 0,G=void 0,B=void 0;l?(Z=e,B=iI.height(Z),G=iI.width(Z),v={left:iI.scrollLeft(Z),top:iI.scrollTop(Z)},p={left:c.left-v.left-A,top:c.top-v.top-o},y={left:c.left+d-(v.left+G)+a,top:c.top+u-(v.top+B)+s},b=v):(h=iI.offset(e),m=e.clientHeight,f=e.clientWidth,b={left:e.scrollLeft,top:e.scrollTop},p={left:c.left-(h.left+(parseFloat(iI.css(e,"borderLeftWidth"))||0))-A,top:c.top-(h.top+(parseFloat(iI.css(e,"borderTopWidth"))||0))-o},y={left:c.left+d-(h.left+f+(parseFloat(iI.css(e,"borderRightWidth"))||0))+a,top:c.top+u-(h.top+m+(parseFloat(iI.css(e,"borderBottomWidth"))||0))+s}),p.top<0||y.top>0?C===!0?iI.scrollTop(e,b.top+p.top):C===!1?iI.scrollTop(e,b.top+y.top):p.top<0?iI.scrollTop(e,b.top+p.top):iI.scrollTop(e,b.top+y.top):n||(C=C===void 0?!0:!!C,C?iI.scrollTop(e,b.top+p.top):iI.scrollTop(e,b.top+y.top)),i&&(p.left<0||y.left>0?r===!0?iI.scrollLeft(e,b.left+p.left):r===!1?iI.scrollLeft(e,b.left+y.left):p.left<0?iI.scrollLeft(e,b.left+p.left):iI.scrollLeft(e,b.left+y.left):n||(r=r===void 0?!0:!!r,r?iI.scrollLeft(e,b.left+p.left):iI.scrollLeft(e,b.left+y.left)))}var mjt=hjt,fjt=mjt;const pjt=FC(fjt);function H2(){return H2=Object.assign?Object.assign.bind():function(g){for(var e=1;e"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function T2(g){return T2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},T2(g)}const GZ=[];let l$=function(g){Bjt(I,g);var e=vjt(I);function I(i){var n;return bjt(this,I),n=e.call(this,i),n.state={highlightedIndex:null,menuTop:0,menuLeft:0,menuWidth:0,isOpen:!1},n.keyDownHandlers={ArrowDown(C){C.preventDefault();const r=this.getFilteredItems().length;if(!r)return;const{highlightedIndex:o}=this.state,A=o===null||o===r-1?0:o+1;this._performAutoCompleteOnKeyUp=!0,this.setState({highlightedIndex:A,isOpen:!0})},ArrowUp(C){C.preventDefault();const r=this.getFilteredItems().length;if(!r)return;const{highlightedIndex:o}=this.state,A=o===0||o===null?r-1:o-1;this._performAutoCompleteOnKeyUp=!0,this.setState({highlightedIndex:A,isOpen:!0})},Enter(C){if(this.state.isOpen!==!1)if(this.state.highlightedIndex===null)this.setState({isOpen:!1},()=>{this.inputEl.select()});else{C.preventDefault();const r=this.getFilteredItems()[this.state.highlightedIndex],o=this.props.getItemValue(r);this.setState({isOpen:!1,highlightedIndex:null},()=>{this.inputEl.setSelectionRange(o.length,o.length),this.props.onSelect(o,r)})}},Escape(){this.setState({highlightedIndex:null,isOpen:!1})}},n}return yjt(I,[{key:"getInitialState",value:function(){return{isOpen:!1,highlightedIndex:null}}},{key:"UNSAFE_componentWillMount",value:function(){this._ignoreBlur=!1,this._performAutoCompleteOnUpdate=!1,this._performAutoCompleteOnKeyUp=!1}},{key:"UNSAFE_componentWillReceiveProps",value:function(n){this._performAutoCompleteOnUpdate=!0,(this.props.items!==n.items||this.state.highlightedIndex>=n.items.length)&&this.setState({highlightedIndex:null})}},{key:"componentDidUpdate",value:function(n,C){this.state.isOpen===!0&&C.isOpen===!1&&this.setMenuPositions(),this.state.isOpen&&this._performAutoCompleteOnUpdate&&(this._performAutoCompleteOnUpdate=!1,this.maybeAutoCompleteText()),this.maybeScrollItemIntoView(),C.isOpen!==this.state.isOpen&&this.props.onMenuVisibilityChange(this.state.isOpen,this.inputEl)}},{key:"maybeScrollItemIntoView",value:function(){if(this.state.isOpen===!0&&this.state.highlightedIndex!==null){const n=this.refs[`item-${this.state.highlightedIndex}`],C=this.refs.menu;n&&pjt(Fs.findDOMNode(n),Fs.findDOMNode(C),{onlyScrollIfNeeded:!0})}}},{key:"handleKeyDown",value:function(n){this.keyDownHandlers[n.key]?this.keyDownHandlers[n.key].call(this,n):this.setState({highlightedIndex:null,isOpen:!0})}},{key:"handleChange",value:function(n){this._performAutoCompleteOnKeyUp=!0,this.props.onChange(n,n.target.value)}},{key:"handleKeyUp",value:function(){this._performAutoCompleteOnKeyUp&&(this._performAutoCompleteOnKeyUp=!1,this.maybeAutoCompleteText())}},{key:"getFilteredItems",value:function(){let n=this.props.items;return this.props.shouldItemRender&&(n=n.filter(C=>this.props.shouldItemRender(C,this.props.value))),this.props.sortItems&&n.sort((C,r)=>this.props.sortItems(C,r,this.props.value)),n}},{key:"maybeAutoCompleteText",value:function(){if(!this.props.autoHighlight||this.props.value==="")return;const{highlightedIndex:n}=this.state,C=this.getFilteredItems();if(C.length===0)return;const r=n!==null?C[n]:C[0];this.props.getItemValue(r).toLowerCase().indexOf(this.props.value.toLowerCase())===0&&n===null&&this.setState({highlightedIndex:0})}},{key:"setMenuPositions",value:function(){const n=this.inputEl,C=n.getBoundingClientRect(),r=globalThis.window.getComputedStyle(n),o=parseInt(r.marginBottom,10)||0,A=parseInt(r.marginLeft,10)||0,s=parseInt(r.marginRight,10)||0;this.setState({menuTop:C.bottom+o,menuLeft:C.left+A,menuWidth:C.width+A+s})}},{key:"highlightItemFromMouse",value:function(n){this.setState({highlightedIndex:n})}},{key:"selectItemFromMouse",value:function(n){const C=this.props.getItemValue(n);this.setState({isOpen:!1,highlightedIndex:null},()=>{this.props.onSelect(C,n),this.inputEl.focus()})}},{key:"setIgnoreBlur",value:function(n){this._ignoreBlur=n}},{key:"renderMenu",value:function(){const n=this.getFilteredItems().map((o,A)=>{const s=this.props.renderItem(o,this.state.highlightedIndex===A,{cursor:"default"});return N.cloneElement(s,{onMouseDown:()=>this.setIgnoreBlur(!0),onMouseEnter:()=>this.highlightItemFromMouse(A),onClick:()=>this.selectItemFromMouse(o),ref:`item-${A}`})}),C={left:this.state.menuLeft,top:this.state.menuTop,minWidth:this.state.menuWidth};if(!n.length)return null;const r=this.props.renderMenu(n,this.props.value,C);return N.cloneElement(r,{ref:"menu"})}},{key:"handleInputBlur",value:function(){this.props.onFocus&&this.props.onFocus(),!this._ignoreBlur&&this.setState({isOpen:!1,highlightedIndex:null})}},{key:"handleInputFocus",value:function(){if(this.props.onFocus&&this.props.onFocus(!0),this._ignoreBlur){this.setIgnoreBlur(!1);return}this._ignoreClick=!0,this.setState({isOpen:!0})}},{key:"isInputFocused",value:function(){return this.inputEl.ownerDocument&&this.inputEl===this.inputEl.ownerDocument.activeElement}},{key:"handleInputClick",value:function(){this.isInputFocused()&&this.state.isOpen===!1?this.setState({isOpen:!0}):this.state.highlightedIndex!==null&&!this._ignoreClick&&this.selectItemFromMouse(this.getFilteredItems()[this.state.highlightedIndex]),this._ignoreClick=!1}},{key:"composeEventHandlers",value:function(n,C){return C?r=>{n(r),C(r)}:n}},{key:"render",value:function(){this.props.debug&&GZ.push({id:GZ.length,state:this.state});const{inputProps:n}=this.props;return N.createElement("div",H2({style:{...this.props.wrapperStyle}},this.props.wrapperProps),N.createElement("input",H2({},n,{ref:C=>{this.inputEl=C},"aria-autocomplete":"list",autoComplete:"off",onBlur:this.composeEventHandlers(this.handleInputBlur.bind(this),n.onBlur&&n.onBlur.bind(this)),onChange:this.handleChange.bind(this),onClick:this.composeEventHandlers(this.handleInputClick.bind(this),n.onClick&&n.onClick.bind(this)),onFocus:this.composeEventHandlers(this.handleInputFocus.bind(this),n.onFocus&&n.onFocus.bind(this)),onKeyDown:this.composeEventHandlers(this.handleKeyDown.bind(this),n.onKeyDown&&n.onKeyDown.bind(this)),onKeyUp:this.composeEventHandlers(this.handleKeyUp.bind(this),n.onKeyUp&&n.onKeyUp.bind(this)),role:"combobox",value:this.props.value})),("open"in this.props?this.props.open:this.state.isOpen)&&this.renderMenu(),this.props.debug&&N.createElement("pre",{style:{marginLeft:300}},JSON.stringify(GZ.slice(GZ.length-5,GZ.length),null,2)))}}]),I}(N.Component);l$.defaultProps={value:"",wrapperProps:{},wrapperStyle:{display:"inline-block"},inputProps:{},onChange(){},onSelect(){},renderMenu(g,e,I){return N.createElement("div",{style:{...I,...this.menuStyle}},g)},shouldItemRender(){return!0},menuStyle:{borderRadius:"3px",boxShadow:"0 2px 12px rgba(0, 0, 0, 0.1)",background:"rgba(255, 255, 255, 0.9)",padding:"2px 0",fontSize:"90%",position:"fixed",overflow:"auto",maxHeight:"50%"},autoHighlight:!0,onMenuVisibilityChange(){}};l$.propTypes={autoHighlight:L.bool,debug:L.bool,getItemValue:L.func.isRequired,inputProps:L.object,items:L.array,menuStyle:L.object,onChange:L.func,onFocus:L.func,onMenuVisibilityChange:L.func,onSelect:L.func,open:L.bool,renderItem:L.func.isRequired,renderMenu:L.func,shouldItemRender:L.func,sortItems:L.func,value:L.any,wrapperProps:L.object,wrapperStyle:L.object};const Rjt="_btn_1l2sx_95",cf={"genome-position-search":"_genome-position-search_1l2sx_1","genome-position-search-focus":"_genome-position-search-focus_1l2sx_2","genome-position-search-bar":"_genome-position-search-bar_1l2sx_16","genome-position-search-dark":"_genome-position-search-dark_1l2sx_34","genome-position-search-bar-button":"_genome-position-search-bar-button_1l2sx_38","genome-position-search-bar-button-focus":"_genome-position-search-bar-button-focus_1l2sx_39","genome-position-search-bar-icon":"_genome-position-search-bar-icon_1l2sx_62","genome-position-search-bar-icon-focus":"_genome-position-search-bar-icon-focus_1l2sx_63","genome-position-search-bar-suggestions":"_genome-position-search-bar-suggestions_1l2sx_83",btn:Rjt,"btn-sm":"_btn-sm_1l2sx_116","btn-default":"_btn-default_1l2sx_122"};function Wjt(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function use(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function N2(g){return N2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},N2(g)}let y9e=function(g){Njt(I,g);var e=kjt(I);function I(i){var n;return Wjt(this,I),n=e.call(this,i),n.mounted=!1,n.uid=dg.nice(),n.chromInfo=null,n.searchField=null,n.autocompleteMenu=null,n.xScale=null,n.yScale=null,n.prevParts=[],n.props.registerViewportChangedListener(n.scalesChanged.bind(b9e(n))),n.menuPosition={left:0,top:0},n.positionText="chr4:190,998,876-191,000,255",n.state={genes:[],isFocused:!1,autocompleteServer:n.props.autocompleteServer,autocompleteId:n.props.autocompleteId,availableAssemblies:[],selectedAssembly:null},n.styles={item:{padding:"2px 6px",cursor:"default"},highlightedItem:{color:"white",background:"hsl(200, 50%, 50%)",padding:"2px 6px",cursor:"default"},menu:{border:"solid 1px #ccc"}},n.availableAutocompletes={},n.props.autocompleteId&&(n.availableAutocompletes[n.props.chromInfoId]=new Set([{server:n.props.autocompleteServer,acId:n.props.autocompleteId}])),n.availableChromSizes={},n}return Xjt(I,[{key:"componentDidMount",value:function(){this.mounted=!0,pg(this.autocompleteMenu.inputEl).on("keypress",this.autocompleteKeyPress.bind(this)),this.findAvailableAutocompleteSources(),this.findAvailableChromSizes(),this.props.chromInfoPath&&(this.searchPosition=!0,qs(this.props.chromInfoPath,n=>{if(!n){this.searchPosition=null;return}this.chromInfo=n,this.searchField=new d0(this.chromInfo),this.setPositionText()})),this.setPositionText()}},{key:"componentWillUnmount",value:function(){this.mounted=!1,this.props.removeViewportChangedListener()}},{key:"onAutocompleteChange",value:function(n,C){this.positionText=C,this.setState({value:C,loading:!0}),this.changedPart=null;const r=C.split(/ /);let o=0;const A=[];let s=!1;for(let a=0;a{if(l)this.setState({loading:!1,genes:[]});else if(this.changedPart>0&&!s){const u=`${this.state.autocompleteServer}/suggest/?d=${this.state.autocompleteId}&ac=${A[this.changedPart-1].toLowerCase()}-${A[this.changedPart].toLowerCase()}`;vt.json(u,(d,h)=>{d?this.setState({loading:!1,genes:c}):this.setState({loading:!1,genes:h.concat(c)})},this.props.pubSub)}else this.setState({loading:!1,genes:c})},this.props.pubSub)}}},{key:"setAvailableAssemblies",value:function(){const n=new Set(Nr(this.availableChromSizes)),C=new Set([...n]);this.gpsbForm&&this.setState({availableAssemblies:[...C]})}},{key:"setSelectedAssembly",value:function(n){if(!this.mounted||!this.availableChromSizes[n])return;const C=[...this.availableChromSizes[n]][0];this.setState({autocompleteServer:C.server});const{server:r}=C;if(this.availableAutocompletes[n]){const o=[...this.availableAutocompletes[n]][0].acId;this.props.onSelectedAssemblyChanged(n,o,r),this.gpsbForm&&this.setState({autocompleteId:o})}else this.props.onSelectedAssemblyChanged(n,null,r),this.gpsbForm&&this.setState({autocompleteId:null});this.fetchChromInfo(C.uuid,C.server)}},{key:"setPositionText",value:function(){if(!this.mounted||!this.searchField)return;const n=this.searchField.scalesToPositionText(this.xScale,this.yScale,this.props.twoD);this.prevParts=n.split(/[ -]/),this.gpsbForm&&(this.positionText=n,this.origPositionText=n,this.autocompleteMenu.inputEl.value=n)}},{key:"scalesChanged",value:function(n,C){this.xScale=n,this.yScale=C,this.setPositionText()}},{key:"findAvailableChromSizes",value:function(){this.props.trackSourceServers&&this.props.trackSourceServers.forEach(n=>{vt.json(`${n}/available-chrom-sizes/`,(C,r)=>{C?console.error(C):(r.results.forEach(o=>{o.coordSystem in this.availableChromSizes||(this.availableChromSizes[o.coordSystem]=new Set),this.availableChromSizes[o.coordSystem].add({server:n,uuid:o.uuid}),this.setAvailableAssemblies()}),this.searchField||this.fetchChromInfo(this.props.chromInfoId in this.availableChromSizes?[...this.availableChromSizes[this.props.chromInfoId]][0].uuid:this.props.chromInfoId,this.props.chromInfoId in this.availableChromSizes?[...this.availableChromSizes[this.props.chromInfoId]][0].server:this.props.chromInfoServer))},this.props.pubSub)})}},{key:"findAvailableAutocompleteSources",value:function(){this.props.trackSourceServers&&this.props.trackSourceServers.forEach(n=>{vt.json(`${n}/tilesets/?limit=100&dt=gene-annotation`,(C,r)=>{C?console.error(C):(r.results.forEach(o=>{o.coordSystem in this.availableAutocompletes||(this.availableAutocompletes[o.coordSystem]=new Set),this.availableAutocompletes[o.coordSystem].add({server:n,acId:o.uuid}),this.setAvailableAssemblies()}),this.state.autocompleteId||this.gpsbForm&&this.availableAutocompletes[this.props.chromInfoId]&&this.setState({autocompleteId:[...this.availableAutocompletes[this.props.chromInfoId]][0].acId}))},this.props.pubSub)})}},{key:"fetchChromInfo",value:function(n,C){qs(`${C}/chrom-sizes/?id=${n}`,r=>{r&&(vt.json(`${C}/tileset_info/?d=${n}`,(o,A)=>{o||this.gpsbForm&&this.setState({selectedAssembly:A[n].coordSystem})},this.props.pubSub),this.chromInfo=r,this.searchField=new d0(this.chromInfo),this.setPositionText())},this.props.pubSub)}},{key:"autocompleteKeyPress",value:function(n){n.keyCode===13&&this.buttonClick()}},{key:"genePositionToSearchBarText",value:function(n){}},{key:"replaceGenesWithLoadedPositions",value:function(n){const C=this.positionText,r=C.split(" ");let o=!1;for(let s=0;sl;){const d=a.slice(l,c).join("-");if(n[d.toLowerCase()]){const h=n[d.toLowerCase()],m=Math.floor((h.txEnd-h.txStart)/4);l===0&&c{if(o){const A={};for(let a=0;aconsole.error(o))}},{key:"buttonClick",value:function(){this.setState({genes:[]}),this.replaceGenesWithPositions(n=>{const C=this.positionText;if(this.searchField!==null){const r=this.searchField.searchPosition(C),o=r[0];let A=r[1];if(!o){this.setPositionText();return}if(o&&(Number.isNaN(+o[0])||Number.isNaN(+o[1]))||A&&(Number.isNaN(+A[0])||Number.isNaN(+A[1])))return;A||(A=o);const s=this.xScale.copy().domain(o),a=this.yScale.copy().domain(A),[l,c,u]=Zi(s,a);n&&this.props.onGeneSearch({geneSymbol:n,range:o,centerX:l,centerY:c}),this.props.setCenters(l,c,u,wGe)}})}},{key:"searchFieldSubmit",value:function(){this.buttonClick()}},{key:"pathJoin",value:function(n,C){const r=C||"/",o=new RegExp(`${r}{1,}`,"g");return n.join(r).replace(o,r)}},{key:"geneSelected",value:function(n,C){const r=this.positionText.split(" ");let o=this.changedPart;for(let A=0;As.length-1)o-=s.length;else{if(s[o]=C.geneName,a.length===2&&o>0&&s[o-1].toLowerCase()===a[0].toLowerCase()){const l=s.slice(0,o-1);l.push(a.join("-")),oN.createElement("option",{key:C,value:C},C));return N.createElement("div",{ref:C=>{this.gpsbForm=C},className:Tg({[cf["genome-position-search-focus"]]:this.state.isFocused,[cf["genome-position-search"]]:!this.state.isFocused,[cf["genome-position-search-dark"]]:this.props.theme===II})},!this.props.hideAvailableAssemblies&&N.createElement("select",{ref:C=>{this.assemblyPickButton=C},className:cf["genome-position-search-bar-button"],id:this.uid,onChange:this.handleAssemblySelectEvt.bind(this),value:this.state.selectedAssembly||void 0},n),N.createElement(l$,{ref:C=>{this.autocompleteMenu=C},getItemValue:C=>C.geneName,inputProps:{className:cf["genome-position-search-bar"],title:"Current location: enter a symbol or location to change the position of the current view"},items:this.state.genes,menuStyle:{position:"absolute",left:this.menuPosition.left,top:this.menuPosition.top,border:"1px solid black"},onChange:this.onAutocompleteChange.bind(this),onFocus:this.focusHandler.bind(this),onMenuVisibilityChange:this.handleMenuVisibilityChange.bind(this),onSelect:(C,r)=>this.geneSelected(C,r),onSubmit:this.searchFieldSubmit.bind(this),renderItem:(C,r)=>N.createElement("div",{key:C.refseqid,id:C.refseqid,style:r?this.styles.highlightedItem:this.styles.item},C.geneName),renderMenu:this.handleRenderMenu.bind(this),value:this.state.selectedAssembly?this.positionText:"No valid assembly selected",wrapperStyle:{width:"100%"}}),N.createElement(NGe,{onClick:this.buttonClick.bind(this),theStyle:"multitrack-header-icon"}))}}]),I}(N.Component);y9e.propTypes={autocompleteId:L.string,autocompleteServer:L.string,chromInfoId:L.string,chromInfoServer:L.string,chromInfoPath:L.string,hideAvailableAssemblies:L.bool,isFocused:L.bool,pubSub:L.object,onFocus:L.func,onGeneSearch:L.func,onSelectedAssemblyChanged:L.func,registerViewportChangedListener:L.func,removeViewportChangedListener:L.func,setCenters:L.func,theme:L.symbol.isRequired,trackSourceServers:L.array,twoD:L.bool};const xjt=ry(ym(y9e)),Djt={"export-link-dialog-wrapper":"_export-link-dialog-wrapper_p9gxw_1"};function Fjt(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function dse(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function k2(g){return k2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},k2(g)}let c$=function(g){Pjt(I,g);var e=Jjt(I);function I(){return Fjt(this,I),e.apply(this,arguments)}return Ejt(I,[{key:"render",value:function(){return N.createElement(Yw,{okayOnly:!0,okayTitle:"Done",onOkay:this.props.onDone,title:"Share view link"},N.createElement("div",{className:Djt["export-link-dialog-wrapper"]},N.createElement("input",{ref:n=>{n&&(this.input=n,n.focus(),n.select())},onClick:n=>{n.target.select()},placeholder:"Generating the link...",readOnly:!0,value:this.props.url}),N.createElement(ks,{onClick:n=>{this.input.select(),document.execCommand("copy")}},"Copy")))}}]),I}(N.Component);c$.defaultProps={onDone:()=>{},url:""};c$.propTypes={onDone:L.func,url:L.string};function Ujt(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function hse(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function Y2(g){return Y2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},Y2(g)}let Z9e=function(g){qjt(I,g);var e=e4t(I);function I(i){var n;return Ujt(this,I),n=e.call(this,i),n.state={submenuShown:!1},n}return Qjt(I,[{key:"getConfigureViewMenu",value:function(n,C){const r=["backgroundColor"],o={},A={};for(const s of r)if(s in Object.keys(nn)&&(o[s]={name:nn[s].name},nn[s].inlineOptions))for(const a in nn[s].inlineOptions){const l=nn[s].inlineOptions[a];o[s].children||(o[s].children={});const c={name:l.name,value:l.value};c.handler=()=>{A[s]=l.value,this.props.onOptionsChanged(A)},o[s].children[a]=c}return N.createElement(lO,{key:"config-series-menu",closeMenu:this.props.closeMenu,menuItems:o,orientation:this.state.orientation,parentBbox:C,position:n,theme:this.props.theme})}},{key:"getSubmenu",value:function(){if(this.state.submenuShown){const n=this.state.submenuSourceBbox,C=this.state.orientation==="left"?{left:this.state.left,top:n.top}:{left:this.state.left+n.width+7,top:n.top};return this.state.submenuShown.option==="options"?this.getConfigureViewMenu(C,n):N.createElement("div",null)}return N.createElement("div",null)}},{key:"render",value:function(){return N.createElement("div",{ref:n=>{this.div=n},className:Tg(eg["context-menu"],{[eg["context-menu-dark"]]:this.props.theme===II}),"data-menu-type":"ConfigViewMenu",style:{left:this.state.left,top:this.state.top}},N.createElement(og,{onClick:n=>this.props.onTogglePositionSearchBox(n)},"Toggle position search box"),N.createElement("hr",{className:eg["context-menu-hr"]}),N.createElement(og,{onClick:n=>this.props.onZoomToData(n)},"Zoom to data extent"),N.createElement(og,{onClick:n=>this.props.onClearView(n)},"Clear View"),N.createElement("hr",{className:eg["context-menu-hr"]}),N.createElement(og,{onClick:n=>this.props.onYankZoom(n)},"Take zoom from"),N.createElement(og,{onClick:n=>this.props.onYankLocation(n)},"Take location from"),N.createElement(og,{onClick:n=>this.props.onYankZoomAndLocation(n)},"Take zoom and location from"),N.createElement("hr",{className:eg["context-menu-hr"]}),N.createElement(og,{onClick:this.props.onLockZoom},"Lock zoom with"),N.createElement(og,{onClick:this.props.onLockLocation},"Lock location with"),N.createElement(og,{onClick:this.props.onLockZoomAndLocation},"Lock zoom and location with"),N.createElement("hr",{className:eg["context-menu-hr"]}),N.createElement(og,{onClick:this.props.onTakeAndLockZoomAndLocation},"Take and lock zoom and location with"),N.createElement("hr",{className:eg["context-menu-hr"]}),N.createElement(og,{onClick:n=>this.props.onUnlockZoom(n)},"Unlock zoom"),N.createElement(og,{onClick:n=>this.props.onUnlockLocation(n)},"Unlock location"),N.createElement(og,{onClick:n=>this.props.onUnlockZoomAndLocation(n)},"Unlock zoom and location"),N.createElement("hr",{className:eg["context-menu-hr"]}),N.createElement(og,{onClick:n=>this.props.onProjectViewport(n)},"Show this viewport on"),N.createElement("hr",{className:eg["context-menu-hr"]}),N.createElement(og,{onClick:n=>this.props.onEditViewConfig(n)},"Edit view config"),N.createElement("hr",{className:eg["context-menu-hr"]}),N.createElement(og,{onClick:()=>this.props.onExportSVG()},"Export views as SVG"),N.createElement(og,{onClick:()=>this.props.onExportPNG()},"Export views as PNG"),N.createElement(og,{onClick:()=>this.props.onExportViewAsJSON()},"Export views as JSON"),N.createElement(og,{onClick:()=>this.props.onExportViewAsLink()},"Export views as Link"),this.getSubmenu())}}]),I}(Ru);Z9e.propTypes={onEditViewConfig:L.func.isRequired,onExportSVG:L.func,onExportPNG:L.func,onExportViewAsJSON:L.func,onExportViewAsLink:L.func,onLockLocation:L.func,onLockZoom:L.func,onLockZoomAndLocation:L.func,onProjectViewport:L.func,onTakeAndLockZoomAndLocation:L.func,onTogglePositionSearchBox:L.func,onUnlockLocation:L.func,onUnlockZoom:L.func,onUnlockZoomAndLocation:L.func,onYankLocation:L.func,onYankZoom:L.func,onYankZoomAndLocation:L.func,onZoomToData:L.func,theme:L.symbol};const Rr={"add-track-position-table":"_add-track-position-table_wdy5w_1","add-track-position-table-dark":"_add-track-position-table-dark_wdy5w_7","add-track-position-other":"_add-track-position-other_wdy5w_11","add-track-position-top-center":"_add-track-position-top-center_wdy5w_15","add-track-position-middle-left":"_add-track-position-middle-left_wdy5w_30","add-track-position-middle-right":"_add-track-position-middle-right_wdy5w_45","add-track-position-middle-middle":"_add-track-position-middle-middle_wdy5w_60","add-track-position-bottom-middle":"_add-track-position-bottom-middle_wdy5w_71","add-track-position-span":"_add-track-position-span_wdy5w_86"};function G9e(g){return N.createElement("div",null,N.createElement("div",{className:Rr["add-track-position-span"]},"Add Track..."),N.createElement("table",{className:Tg(Rr["add-track-position-table"],{[Rr["add-track-position-table-dark"]]:g.theme===II})},N.createElement("tbody",null,N.createElement("tr",{style:{height:"30px"}},N.createElement("td",{"aria-hidden":"true",className:Rr["add-track-position-other"]}),N.createElement("td",{className:Rr["add-track-position-top-center"],onClick:()=>g.onTrackPositionChosen("top")},"top"),N.createElement("td",{"aria-hidden":"true",className:Rr["add-track-position-other"]})),N.createElement("tr",{style:{height:"80px"}},N.createElement("td",{className:Rr["add-track-position-middle-left"],onClick:()=>g.onTrackPositionChosen("left")},"left"),N.createElement("td",{className:Rr["add-track-position-middle-middle"],onClick:()=>g.onTrackPositionChosen("center")},"center"),N.createElement("td",{className:Rr["add-track-position-middle-right"],onClick:()=>g.onTrackPositionChosen("right")},"right")),N.createElement("tr",{style:{height:"30px"}},N.createElement("td",{"aria-hidden":"true",className:Rr["add-track-position-other"]}),N.createElement("td",{className:Rr["add-track-position-bottom-middle"],onClick:()=>g.onTrackPositionChosen("bottom")},"bottom"),N.createElement("td",{"aria-hidden":"true",className:Rr["add-track-position-other"]})))))}G9e.propTypes={onTrackPositionChosen:L.func.isRequired,theme:L.symbol.isRequired};const i4t=ym(G9e);function n4t(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function mse(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function K2(g){return K2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},K2(g)}let u$=function(g){A4t(I,g);var e=a4t(I);function I(i){var n;return n4t(this,I),n=e.call(this,i),n.configImg=null,n.plusImg=null,n.state={addTrackPositionMenuUid:null,addTrackPositionMenuPosition:null,configMenuUid:null,configMenuPosition:null,isFocused:!1,width:-1},n.handleTrackPositionChosenBound=n.handleTrackPositionChosen.bind(B9e(n)),n}return C4t(I,[{key:"componentDidMount",value:function(){this.setState({width:this.el.clientWidth})}},{key:"checkWidth",value:function(){const n=this.el.clientWidth;n!==this.state.width&&this.setState({width:n})}},{key:"handleConfigMenuOpened",value:function(n){this.setState({configMenuUid:n,configMenuPosition:this.configImg.getBoundingClientRect()})}},{key:"handleAddTrackPositionMenuOpened",value:function(n){this.setState({addTrackPositionMenuUid:n,addTrackPositionMenuPosition:this.plusImg.getBoundingClientRect()})}},{key:"handleTrackPositionChosen",value:function(n){this.props.onTrackPositionChosen(n),this.setState({addTrackPositionMenuUid:null,addTrackPositionMenuPosition:null})}},{key:"render",value:function(){let n=null,C=null;this.state.addTrackPositionMenuPosition&&(C=N.createElement($c,{onMenuClosed:()=>{this.setState({addTrackPositionMenuUid:null,addTrackPositionMenuPosition:null})}},N.createElement(Ru,{orientation:"left",position:this.state.addTrackPositionMenuPosition,theme:this.props.theme},N.createElement(i4t,{onTrackPositionChosen:this.handleTrackPositionChosenBound})))),this.state.configMenuUid&&(n=N.createElement($c,{onMenuClosed:()=>this.setState({configMenuUid:null})},N.createElement(Z9e,{onClearView:()=>{this.setState({configMenuUid:null}),this.props.onClearView()},onEditViewConfig:()=>{this.setState({configMenuUid:null}),this.props.onEditViewConfig(this.state.configMenuUid)},onExportPNG:()=>{this.setState({configMenuUid:null}),this.props.onExportPNG()},onExportSVG:()=>{this.setState({configMenuUid:null}),this.props.onExportSVG()},onExportViewAsJSON:()=>{this.setState({configMenuUid:null}),this.props.onExportViewsAsJSON()},onExportViewAsLink:()=>{this.setState({configMenuUid:null}),this.props.onExportViewsAsLink()},onLockLocation:()=>{this.setState({configMenuUid:null}),this.props.onLockLocation(this.state.configMenuUid)},onLockZoom:()=>{this.setState({configMenuUid:null}),this.props.onLockZoom(this.state.configMenuUid)},onLockZoomAndLocation:()=>{this.setState({configMenuUid:null}),this.props.onLockZoomAndLocation(this.state.configMenuUid)},onOptionsChanged:s=>{this.props.onViewOptionsChanged(s),this.setState({configMenuUid:null})},onProjectViewport:()=>{this.setState({configMenuUid:null}),this.props.onProjectViewport(this.state.configMenuUid)},onTakeAndLockZoomAndLocation:()=>{this.setState({configMenuUid:null}),this.props.onTakeAndLockZoomAndLocation(this.state.configMenuUid)},onTogglePositionSearchBox:()=>{this.setState({configMenuUid:null}),this.props.onTogglePositionSearchBox(this.state.configMenuUid)},onUnlockLocation:()=>{this.setState({configMenuUid:null}),this.props.onUnlockLocation(this.state.configMenuUid)},onUnlockZoom:()=>{this.setState({configMenuUid:null}),this.props.onUnlockZoom(this.state.configMenuUid)},onUnlockZoomAndLocation:()=>{this.setState({configMenuUid:null}),this.props.onUnlockZoomAndLocation(this.state.configMenuUid)},onYankLocation:()=>{this.setState({configMenuUid:null}),this.props.onYankLocation(this.state.configMenuUid)},onYankZoom:()=>{this.setState({configMenuUid:null}),this.props.onYankZoom(this.state.configMenuUid)},onYankZoomAndLocation:()=>{this.setState({configMenuUid:null}),this.props.onYankZoomAndLocation(this.state.configMenuUid)},onZoomToData:()=>{this.setState({configMenuUid:null}),this.props.onZoomToData(this.state.configMenuUid)},orientation:"left",position:this.state.configMenuPosition,theme:this.props.theme})));const r=this.props.getGenomePositionSearchBox(this.state.isFocused,s=>{this.setState({isFocused:s})}),o=Tg(this.state.isFocused?Tr["multitrack-header-focus"]:Tr["multitrack-header"],{[Tr["multitrack-header-dark"]]:this.props.theme===II}),A=this.state.width<=VGe?Tr["multitrack-header-icon-squeazed"]:Tr["multitrack-header-icon"];return N.createElement("div",{ref:s=>{this.el=s},className:o},N.createElement("div",{className:Tr["multitrack-header-left"]},this.props.mouseTool===Jr&&N.createElement("svg",{className:Tg(Tr["mouse-tool-selection"],A),title:"Selection tool active"},N.createElement("use",{xlinkHref:"#select"})),N.createElement("div",{className:Tr["multitrack-header-grabber"],title:"Drag to move the view"},N.createElement("div",null),N.createElement("div",null),N.createElement("div",null)),this.state.width>RGe&&N.createElement("div",{className:Tr["multitrack-header-search"]},this.props.isGenomePositionSearchBoxVisible&&r)),N.createElement("nav",{className:Tr["multitrack-header-nav-list"]},N.createElement("svg",{className:A,onClick:this.props.onAddView},N.createElement("title",null,"Add new view (clone this view)"),N.createElement("use",{xlinkHref:"#copy"})),N.createElement("svg",{ref:s=>{this.configImg=s},className:A,onClick:()=>this.handleConfigMenuOpened(this.props.viewUid)},N.createElement("title",null,"Configure this view"),N.createElement("use",{xlinkHref:"#cog"})),N.createElement("svg",{ref:s=>{this.plusImg=s},className:A,onClick:()=>this.handleAddTrackPositionMenuOpened(this.props.viewUid)},N.createElement("title",null,"Add Track"),N.createElement("use",{xlinkHref:"#plus"})),N.createElement("svg",{className:A,onClick:this.props.onCloseView},N.createElement("title",null,"Close View"),N.createElement("use",{xlinkHref:"#cross"}))),n,C)}}]),I}(N.Component);u$.defaultProps={isGenomePositionSearchBoxVisible:!1};u$.propTypes={getGenomePositionSearchBox:L.func.isRequired,isGenomePositionSearchBoxVisible:L.bool,mouseTool:L.string.isRequired,onAddView:L.func.isRequired,onClearView:L.func.isRequired,onCloseView:L.func.isRequired,onEditViewConfig:L.func.isRequired,onExportSVG:L.func.isRequired,onExportPNG:L.func.isRequired,onExportViewsAsJSON:L.func.isRequired,onExportViewsAsLink:L.func.isRequired,onLockLocation:L.func.isRequired,onLockZoom:L.func.isRequired,onLockZoomAndLocation:L.func.isRequired,onProjectViewport:L.func.isRequired,onTakeAndLockZoomAndLocation:L.func.isRequired,onTogglePositionSearchBox:L.func.isRequired,onTrackPositionChosen:L.func.isRequired,onUnlockLocation:L.func.isRequired,onUnlockZoom:L.func.isRequired,onUnlockZoomAndLocation:L.func.isRequired,onViewOptionsChanged:L.func.isRequired,onYankLocation:L.func.isRequired,onYankZoom:L.func.isRequired,onYankZoomAndLocation:L.func.isRequired,onZoomToData:L.func.isRequired,theme:L.symbol.isRequired,viewUid:L.string.isRequired};const c4t=ym(u$);var v9e={};Object.defineProperty(v9e,"__esModule",{value:!0});var Yl=Object.assign||function(g){for(var e=1;e=0||Object.prototype.hasOwnProperty.call(g,i)&&(I[i]=g[i]);return I}function f4t(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function fse(g,e){if(!g)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e&&(typeof e=="object"||typeof e=="function")?e:g}function p4t(g,e){if(typeof e!="function"&&e!==null)throw new TypeError("Super expression must either be null or a function, not "+typeof e);g.prototype=Object.create(e&&e.prototype,{constructor:{value:g,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(g,e):g.__proto__=e)}var b4t=13,y4t=9,Z4t=8,G4t=89,g1=90,B4t=77,pse=57,bse=219,yse=222,Zse=192,v4t=27,Gse=100,S4t=3e3,w4t="navigator"in globalThis&&/Win/i.test(navigator.platform),wF="navigator"in globalThis&&/(Mac|iPhone|iPod|iPad)/i.test(navigator.platform),LW="npm__react-simple-code-editor__textarea",V4t=` + `),N.createElement("div",{style:a.white,className:"saturation-white"},N.createElement("div",{style:a.black,className:"saturation-black"}),N.createElement("div",{style:a.pointer},this.props.pointer?N.createElement(this.props.pointer,this.props):N.createElement("div",{style:a.circle}))))}}]),g}(Ie.PureComponent||Ie.Component);function lUt(e,g){var I=oC(e)?VWe:wWe;return I(e,uWe(g))}function v2(e){"@babel/helpers - typeof";return v2=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(g){return typeof g}:function(g){return g&&typeof Symbol=="function"&&g.constructor===Symbol&&g!==Symbol.prototype?"symbol":typeof g},v2(e)}var cUt=/^\s+/,uUt=/\s+$/;function Nt(e,g){if(e=e||"",g=g||{},e instanceof Nt)return e;if(!(this instanceof Nt))return new Nt(e,g);var I=dUt(e);this._originalInput=e,this._r=I.r,this._g=I.g,this._b=I.b,this._a=I.a,this._roundA=Math.round(100*this._a)/100,this._format=g.format||I.format,this._gradientType=g.gradientType,this._r<1&&(this._r=Math.round(this._r)),this._g<1&&(this._g=Math.round(this._g)),this._b<1&&(this._b=Math.round(this._b)),this._ok=I.ok}Nt.prototype={isDark:function(){return this.getBrightness()<128},isLight:function(){return!this.isDark()},isValid:function(){return this._ok},getOriginalInput:function(){return this._originalInput},getFormat:function(){return this._format},getAlpha:function(){return this._a},getBrightness:function(){var g=this.toRgb();return(g.r*299+g.g*587+g.b*114)/1e3},getLuminance:function(){var g=this.toRgb(),I,i,n,C,r,o;return I=g.r/255,i=g.g/255,n=g.b/255,I<=.03928?C=I/12.92:C=Math.pow((I+.055)/1.055,2.4),i<=.03928?r=i/12.92:r=Math.pow((i+.055)/1.055,2.4),n<=.03928?o=n/12.92:o=Math.pow((n+.055)/1.055,2.4),.2126*C+.7152*r+.0722*o},setAlpha:function(g){return this._a=PWe(g),this._roundA=Math.round(100*this._a)/100,this},toHsv:function(){var g=OAe(this._r,this._g,this._b);return{h:g.h*360,s:g.s,v:g.v,a:this._a}},toHsvString:function(){var g=OAe(this._r,this._g,this._b),I=Math.round(g.h*360),i=Math.round(g.s*100),n=Math.round(g.v*100);return this._a==1?"hsv("+I+", "+i+"%, "+n+"%)":"hsva("+I+", "+i+"%, "+n+"%, "+this._roundA+")"},toHsl:function(){var g=JAe(this._r,this._g,this._b);return{h:g.h*360,s:g.s,l:g.l,a:this._a}},toHslString:function(){var g=JAe(this._r,this._g,this._b),I=Math.round(g.h*360),i=Math.round(g.s*100),n=Math.round(g.l*100);return this._a==1?"hsl("+I+", "+i+"%, "+n+"%)":"hsla("+I+", "+i+"%, "+n+"%, "+this._roundA+")"},toHex:function(g){return _Ae(this._r,this._g,this._b,g)},toHexString:function(g){return"#"+this.toHex(g)},toHex8:function(g){return pUt(this._r,this._g,this._b,this._a,g)},toHex8String:function(g){return"#"+this.toHex8(g)},toRgb:function(){return{r:Math.round(this._r),g:Math.round(this._g),b:Math.round(this._b),a:this._a}},toRgbString:function(){return this._a==1?"rgb("+Math.round(this._r)+", "+Math.round(this._g)+", "+Math.round(this._b)+")":"rgba("+Math.round(this._r)+", "+Math.round(this._g)+", "+Math.round(this._b)+", "+this._roundA+")"},toPercentageRgb:function(){return{r:Math.round(wI(this._r,255)*100)+"%",g:Math.round(wI(this._g,255)*100)+"%",b:Math.round(wI(this._b,255)*100)+"%",a:this._a}},toPercentageRgbString:function(){return this._a==1?"rgb("+Math.round(wI(this._r,255)*100)+"%, "+Math.round(wI(this._g,255)*100)+"%, "+Math.round(wI(this._b,255)*100)+"%)":"rgba("+Math.round(wI(this._r,255)*100)+"%, "+Math.round(wI(this._g,255)*100)+"%, "+Math.round(wI(this._b,255)*100)+"%, "+this._roundA+")"},toName:function(){return this._a===0?"transparent":this._a<1?!1:XUt[_Ae(this._r,this._g,this._b,!0)]||!1},toFilter:function(g){var I="#"+LAe(this._r,this._g,this._b,this._a),i=I,n=this._gradientType?"GradientType = 1, ":"";if(g){var C=Nt(g);i="#"+LAe(C._r,C._g,C._b,C._a)}return"progid:DXImageTransform.Microsoft.gradient("+n+"startColorstr="+I+",endColorstr="+i+")"},toString:function(g){var I=!!g;g=g||this._format;var i=!1,n=this._a<1&&this._a>=0,C=!I&&n&&(g==="hex"||g==="hex6"||g==="hex3"||g==="hex4"||g==="hex8"||g==="name");return C?g==="name"&&this._a===0?this.toName():this.toRgbString():(g==="rgb"&&(i=this.toRgbString()),g==="prgb"&&(i=this.toPercentageRgbString()),(g==="hex"||g==="hex6")&&(i=this.toHexString()),g==="hex3"&&(i=this.toHexString(!0)),g==="hex4"&&(i=this.toHex8String(!0)),g==="hex8"&&(i=this.toHex8String()),g==="name"&&(i=this.toName()),g==="hsl"&&(i=this.toHslString()),g==="hsv"&&(i=this.toHsvString()),i||this.toHexString())},clone:function(){return Nt(this.toString())},_applyModification:function(g,I){var i=g.apply(null,[this].concat([].slice.call(I)));return this._r=i._r,this._g=i._g,this._b=i._b,this.setAlpha(i._a),this},lighten:function(){return this._applyModification(GUt,arguments)},brighten:function(){return this._applyModification(vUt,arguments)},darken:function(){return this._applyModification(BUt,arguments)},desaturate:function(){return this._applyModification(bUt,arguments)},saturate:function(){return this._applyModification(yUt,arguments)},greyscale:function(){return this._applyModification(ZUt,arguments)},spin:function(){return this._applyModification(SUt,arguments)},_applyCombination:function(g,I){return g.apply(null,[this].concat([].slice.call(I)))},analogous:function(){return this._applyCombination(RUt,arguments)},complement:function(){return this._applyCombination(wUt,arguments)},monochromatic:function(){return this._applyCombination(WUt,arguments)},splitcomplement:function(){return this._applyCombination(VUt,arguments)},triad:function(){return this._applyCombination(UAe,[3])},tetrad:function(){return this._applyCombination(UAe,[4])}};Nt.fromRatio=function(e,g){if(v2(e)=="object"){var I={};for(var i in e)e.hasOwnProperty(i)&&(i==="a"?I[i]=e[i]:I[i]=LZ(e[i]));e=I}return Nt(e,g)};function dUt(e){var g={r:0,g:0,b:0},I=1,i=null,n=null,C=null,r=!1,o=!1;return typeof e=="string"&&(e=kUt(e)),v2(e)=="object"&&(xa(e.r)&&xa(e.g)&&xa(e.b)?(g=hUt(e.r,e.g,e.b),r=!0,o=String(e.r).substr(-1)==="%"?"prgb":"rgb"):xa(e.h)&&xa(e.s)&&xa(e.v)?(i=LZ(e.s),n=LZ(e.v),g=fUt(e.h,i,n),r=!0,o="hsv"):xa(e.h)&&xa(e.s)&&xa(e.l)&&(i=LZ(e.s),C=LZ(e.l),g=mUt(e.h,i,C),r=!0,o="hsl"),e.hasOwnProperty("a")&&(I=e.a)),I=PWe(I),{ok:r,format:e.format||o,r:Math.min(255,Math.max(g.r,0)),g:Math.min(255,Math.max(g.g,0)),b:Math.min(255,Math.max(g.b,0)),a:I}}function hUt(e,g,I){return{r:wI(e,255)*255,g:wI(g,255)*255,b:wI(I,255)*255}}function JAe(e,g,I){e=wI(e,255),g=wI(g,255),I=wI(I,255);var i=Math.max(e,g,I),n=Math.min(e,g,I),C,r,o=(i+n)/2;if(i==n)C=r=0;else{var A=i-n;switch(r=o>.5?A/(2-i-n):A/(i+n),i){case e:C=(g-I)/A+(g1&&(l-=1),l<1/6?s+(a-s)*6*l:l<1/2?a:l<2/3?s+(a-s)*(2/3-l)*6:s}if(g===0)i=n=C=I;else{var o=I<.5?I*(1+g):I+g-I*g,A=2*I-o;i=r(A,o,e+1/3),n=r(A,o,e),C=r(A,o,e-1/3)}return{r:i*255,g:n*255,b:C*255}}function OAe(e,g,I){e=wI(e,255),g=wI(g,255),I=wI(I,255);var i=Math.max(e,g,I),n=Math.min(e,g,I),C,r,o=i,A=i-n;if(r=i===0?0:A/i,i==n)C=0;else{switch(i){case e:C=(g-I)/A+(g>1)+720)%360;--g;)i.h=(i.h+n)%360,C.push(Nt(i));return C}function WUt(e,g){g=g||6;for(var I=Nt(e).toHsv(),i=I.h,n=I.s,C=I.v,r=[],o=1/g;g--;)r.push(Nt({h:i,s:n,v:C})),C=(C+o)%1;return r}Nt.mix=function(e,g,I){I=I===0?0:I||50;var i=Nt(e).toRgb(),n=Nt(g).toRgb(),C=I/100,r={r:(n.r-i.r)*C+i.r,g:(n.g-i.g)*C+i.g,b:(n.b-i.b)*C+i.b,a:(n.a-i.a)*C+i.a};return Nt(r)};Nt.readability=function(e,g){var I=Nt(e),i=Nt(g);return(Math.max(I.getLuminance(),i.getLuminance())+.05)/(Math.min(I.getLuminance(),i.getLuminance())+.05)};Nt.isReadable=function(e,g,I){var i=Nt.readability(e,g),n,C;switch(C=!1,n=YUt(I),n.level+n.size){case"AAsmall":case"AAAlarge":C=i>=4.5;break;case"AAlarge":C=i>=3;break;case"AAAsmall":C=i>=7;break}return C};Nt.mostReadable=function(e,g,I){var i=null,n=0,C,r,o,A;I=I||{},r=I.includeFallbackColors,o=I.level,A=I.size;for(var s=0;sn&&(n=C,i=Nt(g[s]));return Nt.isReadable(e,i,{level:o,size:A})||!r?i:(I.includeFallbackColors=!1,Nt.mostReadable(e,["#fff","#000"],I))};var pJ=Nt.names={aliceblue:"f0f8ff",antiquewhite:"faebd7",aqua:"0ff",aquamarine:"7fffd4",azure:"f0ffff",beige:"f5f5dc",bisque:"ffe4c4",black:"000",blanchedalmond:"ffebcd",blue:"00f",blueviolet:"8a2be2",brown:"a52a2a",burlywood:"deb887",burntsienna:"ea7e5d",cadetblue:"5f9ea0",chartreuse:"7fff00",chocolate:"d2691e",coral:"ff7f50",cornflowerblue:"6495ed",cornsilk:"fff8dc",crimson:"dc143c",cyan:"0ff",darkblue:"00008b",darkcyan:"008b8b",darkgoldenrod:"b8860b",darkgray:"a9a9a9",darkgreen:"006400",darkgrey:"a9a9a9",darkkhaki:"bdb76b",darkmagenta:"8b008b",darkolivegreen:"556b2f",darkorange:"ff8c00",darkorchid:"9932cc",darkred:"8b0000",darksalmon:"e9967a",darkseagreen:"8fbc8f",darkslateblue:"483d8b",darkslategray:"2f4f4f",darkslategrey:"2f4f4f",darkturquoise:"00ced1",darkviolet:"9400d3",deeppink:"ff1493",deepskyblue:"00bfff",dimgray:"696969",dimgrey:"696969",dodgerblue:"1e90ff",firebrick:"b22222",floralwhite:"fffaf0",forestgreen:"228b22",fuchsia:"f0f",gainsboro:"dcdcdc",ghostwhite:"f8f8ff",gold:"ffd700",goldenrod:"daa520",gray:"808080",green:"008000",greenyellow:"adff2f",grey:"808080",honeydew:"f0fff0",hotpink:"ff69b4",indianred:"cd5c5c",indigo:"4b0082",ivory:"fffff0",khaki:"f0e68c",lavender:"e6e6fa",lavenderblush:"fff0f5",lawngreen:"7cfc00",lemonchiffon:"fffacd",lightblue:"add8e6",lightcoral:"f08080",lightcyan:"e0ffff",lightgoldenrodyellow:"fafad2",lightgray:"d3d3d3",lightgreen:"90ee90",lightgrey:"d3d3d3",lightpink:"ffb6c1",lightsalmon:"ffa07a",lightseagreen:"20b2aa",lightskyblue:"87cefa",lightslategray:"789",lightslategrey:"789",lightsteelblue:"b0c4de",lightyellow:"ffffe0",lime:"0f0",limegreen:"32cd32",linen:"faf0e6",magenta:"f0f",maroon:"800000",mediumaquamarine:"66cdaa",mediumblue:"0000cd",mediumorchid:"ba55d3",mediumpurple:"9370db",mediumseagreen:"3cb371",mediumslateblue:"7b68ee",mediumspringgreen:"00fa9a",mediumturquoise:"48d1cc",mediumvioletred:"c71585",midnightblue:"191970",mintcream:"f5fffa",mistyrose:"ffe4e1",moccasin:"ffe4b5",navajowhite:"ffdead",navy:"000080",oldlace:"fdf5e6",olive:"808000",olivedrab:"6b8e23",orange:"ffa500",orangered:"ff4500",orchid:"da70d6",palegoldenrod:"eee8aa",palegreen:"98fb98",paleturquoise:"afeeee",palevioletred:"db7093",papayawhip:"ffefd5",peachpuff:"ffdab9",peru:"cd853f",pink:"ffc0cb",plum:"dda0dd",powderblue:"b0e0e6",purple:"800080",rebeccapurple:"663399",red:"f00",rosybrown:"bc8f8f",royalblue:"4169e1",saddlebrown:"8b4513",salmon:"fa8072",sandybrown:"f4a460",seagreen:"2e8b57",seashell:"fff5ee",sienna:"a0522d",silver:"c0c0c0",skyblue:"87ceeb",slateblue:"6a5acd",slategray:"708090",slategrey:"708090",snow:"fffafa",springgreen:"00ff7f",steelblue:"4682b4",tan:"d2b48c",teal:"008080",thistle:"d8bfd8",tomato:"ff6347",turquoise:"40e0d0",violet:"ee82ee",wheat:"f5deb3",white:"fff",whitesmoke:"f5f5f5",yellow:"ff0",yellowgreen:"9acd32"},XUt=Nt.hexNames=HUt(pJ);function HUt(e){var g={};for(var I in e)e.hasOwnProperty(I)&&(g[e[I]]=I);return g}function PWe(e){return e=parseFloat(e),(isNaN(e)||e<0||e>1)&&(e=1),e}function wI(e,g){TUt(e)&&(e="100%");var I=NUt(e);return e=Math.min(g,Math.max(0,parseFloat(e))),I&&(e=parseInt(e*g,10)/100),Math.abs(e-g)<1e-6?1:e%g/parseFloat(g)}function Zk(e){return Math.min(1,Math.max(0,e))}function OC(e){return parseInt(e,16)}function TUt(e){return typeof e=="string"&&e.indexOf(".")!=-1&&parseFloat(e)===1}function NUt(e){return typeof e=="string"&&e.indexOf("%")!=-1}function Uo(e){return e.length==1?"0"+e:""+e}function LZ(e){return e<=1&&(e=e*100+"%"),e}function JWe(e){return Math.round(parseFloat(e)*255).toString(16)}function QAe(e){return OC(e)/255}var Ho=function(){var e="[-\\+]?\\d+%?",g="[-\\+]?\\d*\\.\\d+%?",I="(?:"+g+")|(?:"+e+")",i="[\\s|\\(]+("+I+")[,|\\s]+("+I+")[,|\\s]+("+I+")\\s*\\)?",n="[\\s|\\(]+("+I+")[,|\\s]+("+I+")[,|\\s]+("+I+")[,|\\s]+("+I+")\\s*\\)?";return{CSS_UNIT:new RegExp(I),rgb:new RegExp("rgb"+i),rgba:new RegExp("rgba"+n),hsl:new RegExp("hsl"+i),hsla:new RegExp("hsla"+n),hsv:new RegExp("hsv"+i),hsva:new RegExp("hsva"+n),hex3:/^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,hex6:/^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/,hex4:/^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,hex8:/^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/}}();function xa(e){return!!Ho.CSS_UNIT.exec(e)}function kUt(e){e=e.replace(cUt,"").replace(uUt,"").toLowerCase();var g=!1;if(pJ[e])e=pJ[e],g=!0;else if(e=="transparent")return{r:0,g:0,b:0,a:0,format:"name"};var I;return(I=Ho.rgb.exec(e))?{r:I[1],g:I[2],b:I[3]}:(I=Ho.rgba.exec(e))?{r:I[1],g:I[2],b:I[3],a:I[4]}:(I=Ho.hsl.exec(e))?{h:I[1],s:I[2],l:I[3]}:(I=Ho.hsla.exec(e))?{h:I[1],s:I[2],l:I[3],a:I[4]}:(I=Ho.hsv.exec(e))?{h:I[1],s:I[2],v:I[3]}:(I=Ho.hsva.exec(e))?{h:I[1],s:I[2],v:I[3],a:I[4]}:(I=Ho.hex8.exec(e))?{r:OC(I[1]),g:OC(I[2]),b:OC(I[3]),a:QAe(I[4]),format:g?"name":"hex8"}:(I=Ho.hex6.exec(e))?{r:OC(I[1]),g:OC(I[2]),b:OC(I[3]),format:g?"name":"hex"}:(I=Ho.hex4.exec(e))?{r:OC(I[1]+""+I[1]),g:OC(I[2]+""+I[2]),b:OC(I[3]+""+I[3]),a:QAe(I[4]+""+I[4]),format:g?"name":"hex8"}:(I=Ho.hex3.exec(e))?{r:OC(I[1]+""+I[1]),g:OC(I[2]+""+I[2]),b:OC(I[3]+""+I[3]),format:g?"name":"hex"}:!1}function YUt(e){var g,I;return e=e||{level:"AA",size:"small"},g=(e.level||"AA").toUpperCase(),I=(e.size||"small").toLowerCase(),g!=="AA"&&g!=="AAA"&&(g="AA"),I!=="small"&&I!=="large"&&(I="small"),{level:g,size:I}}var jAe=function(g){var I=["r","g","b","a","h","s","l","v"],i=0,n=0;return lUt(I,function(C){if(g[C]&&(i+=1,isNaN(g[C])||(n+=1),C==="s"||C==="l")){var r=/^\d+%$/;r.test(g[C])&&(n+=1)}}),i===n?g:!1},UZ=function(g,I){var i=g.hex?Nt(g.hex):Nt(g),n=i.toHsl(),C=i.toHsv(),r=i.toRgb(),o=i.toHex();n.s===0&&(n.h=I||0,C.h=I||0);var A=o==="000000"&&r.a===0;return{hsl:n,hex:A?"transparent":"#"+o,rgb:r,hsv:C,oldHue:g.h||I||n.h,source:g.source}},ru=function(g){if(g==="transparent")return!0;var I=String(g).charAt(0)==="#"?1:0;return g.length!==4+I&&g.length<7+I&&Nt(g).isValid()},c4=function(g){if(!g)return"#fff";var I=UZ(g);if(I.hex==="transparent")return"rgba(0,0,0,0.4)";var i=(I.rgb.r*299+I.rgb.g*587+I.rgb.b*114)/1e3;return i>=128?"#000":"#fff"},Tx=function(g,I){var i=g.replace("°","");return Nt(I+" ("+i+")")._ok},iZ=Object.assign||function(e){for(var g=1;g1&&arguments[1]!==void 0?arguments[1]:"span";return function(i){PUt(n,i);function n(){var C,r,o,A;zUt(this,n);for(var s=arguments.length,a=Array(s),l=0;l=0||Object.prototype.hasOwnProperty.call(e,i)&&(I[i]=e[i]);return I}var vR=24,t7t=LWe.default=function(e){var g=e.fill,I=g===void 0?"currentColor":g,i=e.width,n=i===void 0?vR:i,C=e.height,r=C===void 0?vR:C,o=e.style,A=o===void 0?{}:o,s=e7t(e,["fill","width","height","style"]);return gae.default.createElement("svg",tae({viewBox:"0 0 "+vR+" "+vR,style:tae({fill:I,width:n,height:r},A)},s),gae.default.createElement("path",{d:"M12,18.17L8.83,15L7.42,16.41L12,21L16.59,16.41L15.17,15M12,5.83L15.17,9L16.58,7.59L12,3L7.41,7.59L8.83,9L12,5.83Z"}))},g7t=function(){function e(g,I){for(var i=0;i1&&(n.a=1),i.props.onChange({h:i.props.hsl.h,s:i.props.hsl.s,l:i.props.hsl.l,a:Math.round(n.a*100)/100,source:"rgb"},C)):(n.h||n.s||n.l)&&(typeof n.s=="string"&&n.s.includes("%")&&(n.s=n.s.replace("%","")),typeof n.l=="string"&&n.l.includes("%")&&(n.l=n.l.replace("%","")),n.s==1?n.s=.01:n.l==1&&(n.l=.01),i.props.onChange({h:n.h||i.props.hsl.h,s:Number(eae(n.s)?i.props.hsl.s:n.s),l:Number(eae(n.l)?i.props.hsl.l:n.l),source:"hsl"},C))},i.showHighlight=function(n){n.currentTarget.style.background="#eee"},i.hideHighlight=function(n){n.currentTarget.style.background="transparent"},I.hsl.a!==1&&I.view==="hex"?i.state={view:"rgb"}:i.state={view:I.view},i}return g7t(g,[{key:"render",value:function(){var i=this,n=Qt({default:{wrap:{paddingTop:"16px",display:"flex"},fields:{flex:"1",display:"flex",marginLeft:"-6px"},field:{paddingLeft:"6px",width:"100%"},alpha:{paddingLeft:"6px",width:"100%"},toggle:{width:"32px",textAlign:"right",position:"relative"},icon:{marginRight:"-4px",marginTop:"12px",cursor:"pointer",position:"relative"},iconHighlight:{position:"absolute",width:"24px",height:"28px",background:"#eee",borderRadius:"4px",top:"10px",left:"12px",display:"none"},input:{fontSize:"11px",color:"#333",width:"100%",borderRadius:"2px",border:"none",boxShadow:"inset 0 0 0 1px #dadada",height:"21px",textAlign:"center"},label:{textTransform:"uppercase",fontSize:"11px",lineHeight:"11px",color:"#969696",textAlign:"center",display:"block",marginTop:"12px"},svg:{fill:"#333",width:"24px",height:"24px",border:"1px transparent solid",borderRadius:"5px"}},disableAlpha:{alpha:{display:"none"}}},this.props,this.state),C=void 0;return this.state.view==="hex"?C=N.createElement("div",{style:n.fields,className:"flexbox-fix"},N.createElement("div",{style:n.field},N.createElement(Gg,{style:{input:n.input,label:n.label},label:"hex",value:this.props.hex,onChange:this.handleChange}))):this.state.view==="rgb"?C=N.createElement("div",{style:n.fields,className:"flexbox-fix"},N.createElement("div",{style:n.field},N.createElement(Gg,{style:{input:n.input,label:n.label},label:"r",value:this.props.rgb.r,onChange:this.handleChange})),N.createElement("div",{style:n.field},N.createElement(Gg,{style:{input:n.input,label:n.label},label:"g",value:this.props.rgb.g,onChange:this.handleChange})),N.createElement("div",{style:n.field},N.createElement(Gg,{style:{input:n.input,label:n.label},label:"b",value:this.props.rgb.b,onChange:this.handleChange})),N.createElement("div",{style:n.alpha},N.createElement(Gg,{style:{input:n.input,label:n.label},label:"a",value:this.props.rgb.a,arrowOffset:.01,onChange:this.handleChange}))):this.state.view==="hsl"&&(C=N.createElement("div",{style:n.fields,className:"flexbox-fix"},N.createElement("div",{style:n.field},N.createElement(Gg,{style:{input:n.input,label:n.label},label:"h",value:Math.round(this.props.hsl.h),onChange:this.handleChange})),N.createElement("div",{style:n.field},N.createElement(Gg,{style:{input:n.input,label:n.label},label:"s",value:Math.round(this.props.hsl.s*100)+"%",onChange:this.handleChange})),N.createElement("div",{style:n.field},N.createElement(Gg,{style:{input:n.input,label:n.label},label:"l",value:Math.round(this.props.hsl.l*100)+"%",onChange:this.handleChange})),N.createElement("div",{style:n.alpha},N.createElement(Gg,{style:{input:n.input,label:n.label},label:"a",value:this.props.hsl.a,arrowOffset:.01,onChange:this.handleChange})))),N.createElement("div",{style:n.wrap,className:"flexbox-fix"},C,N.createElement("div",{style:n.toggle},N.createElement("div",{style:n.icon,onClick:this.toggleViews,ref:function(o){return i.icon=o}},N.createElement(t7t,{style:n.svg,onMouseOver:this.showHighlight,onMouseEnter:this.showHighlight,onMouseOut:this.hideHighlight}))))}}],[{key:"getDerivedStateFromProps",value:function(i,n){return i.hsl.a!==1&&n.view==="hex"?{view:"rgb"}:null}}]),g}(N.Component);UWe.defaultProps={view:"hex"};var Iae=function(){var g=Qt({default:{picker:{width:"12px",height:"12px",borderRadius:"6px",transform:"translate(-6px, -1px)",backgroundColor:"rgb(248, 248, 248)",boxShadow:"0 1px 4px 0 rgba(0, 0, 0, 0.37)"}}});return N.createElement("div",{style:g.picker})},C7t=function(){var g=Qt({default:{picker:{width:"12px",height:"12px",borderRadius:"6px",boxShadow:"inset 0 0 0 1px #fff",transform:"translate(-6px, -6px)"}}});return N.createElement("div",{style:g.picker})},h4=function(g){var I=g.width,i=g.onChange,n=g.disableAlpha,C=g.rgb,r=g.hsl,o=g.hsv,A=g.hex,s=g.renderers,a=g.styles,l=a===void 0?{}:a,c=g.className,u=c===void 0?"":c,d=g.defaultView,h=Qt(FC({default:{picker:{width:I,background:"#fff",borderRadius:"2px",boxShadow:"0 0 2px rgba(0,0,0,.3), 0 4px 8px rgba(0,0,0,.3)",boxSizing:"initial",fontFamily:"Menlo"},saturation:{width:"100%",paddingBottom:"55%",position:"relative",borderRadius:"2px 2px 0 0",overflow:"hidden"},Saturation:{radius:"2px 2px 0 0"},body:{padding:"16px 16px 12px"},controls:{display:"flex"},color:{width:"32px"},swatch:{marginTop:"6px",width:"16px",height:"16px",borderRadius:"8px",position:"relative",overflow:"hidden"},active:{absolute:"0px 0px 0px 0px",borderRadius:"8px",boxShadow:"inset 0 0 0 1px rgba(0,0,0,.1)",background:"rgba("+C.r+", "+C.g+", "+C.b+", "+C.a+")",zIndex:"2"},toggles:{flex:"1"},hue:{height:"10px",position:"relative",marginBottom:"8px"},Hue:{radius:"2px"},alpha:{height:"10px",position:"relative"},Alpha:{radius:"2px"}},disableAlpha:{color:{width:"22px"},alpha:{display:"none"},hue:{marginBottom:"0px"},swatch:{width:"10px",height:"10px",marginTop:"0px"}}},l),{disableAlpha:n});return N.createElement("div",{style:h.picker,className:"chrome-picker "+u},N.createElement("div",{style:h.saturation},N.createElement(yk,{style:h.Saturation,hsl:r,hsv:o,pointer:C7t,onChange:i})),N.createElement("div",{style:h.body},N.createElement("div",{style:h.controls,className:"flexbox-fix"},N.createElement("div",{style:h.color},N.createElement("div",{style:h.swatch},N.createElement("div",{style:h.active}),N.createElement(q0,{renderers:s}))),N.createElement("div",{style:h.toggles},N.createElement("div",{style:h.hue},N.createElement(ey,{style:h.Hue,hsl:r,pointer:Iae,onChange:i})),N.createElement("div",{style:h.alpha},N.createElement(l4,{style:h.Alpha,rgb:C,hsl:r,pointer:Iae,renderers:s,onChange:i})))),N.createElement(UWe,{rgb:C,hsl:r,hex:A,view:d,onChange:i,disableAlpha:n})))};h4.propTypes={width:L.oneOfType([L.string,L.number]),disableAlpha:L.bool,styles:L.object,defaultView:L.oneOf(["hex","rgb","hsl"])};h4.defaultProps={width:225,disableAlpha:!1,styles:{}};EC(h4);var r7t=function(g){var I=g.color,i=g.onClick,n=i===void 0?function(){}:i,C=g.onSwatchHover,r=g.active,o=Qt({default:{color:{background:I,width:"15px",height:"15px",float:"left",marginRight:"5px",marginBottom:"5px",position:"relative",cursor:"pointer"},dot:{absolute:"5px 5px 5px 5px",background:c4(I),borderRadius:"50%",opacity:"0"}},active:{dot:{opacity:"1"}},"color-#FFFFFF":{color:{boxShadow:"inset 0 0 0 1px #ddd"},dot:{background:"#000"}},transparent:{dot:{background:"#000"}}},{active:r,"color-#FFFFFF":I==="#FFFFFF",transparent:I==="transparent"});return N.createElement(lm,{style:o.color,color:I,onClick:n,onHover:C,focusStyle:{boxShadow:"0 0 4px "+I}},N.createElement("div",{style:o.dot}))},o7t=function(g){var I=g.hex,i=g.rgb,n=g.onChange,C=Qt({default:{fields:{display:"flex",paddingBottom:"6px",paddingRight:"5px",position:"relative"},active:{position:"absolute",top:"6px",left:"5px",height:"9px",width:"9px",background:I},HEXwrap:{flex:"6",position:"relative"},HEXinput:{width:"80%",padding:"0px",paddingLeft:"20%",border:"none",outline:"none",background:"none",fontSize:"12px",color:"#333",height:"16px"},HEXlabel:{display:"none"},RGBwrap:{flex:"3",position:"relative"},RGBinput:{width:"70%",padding:"0px",paddingLeft:"30%",border:"none",outline:"none",background:"none",fontSize:"12px",color:"#333",height:"16px"},RGBlabel:{position:"absolute",top:"3px",left:"0px",lineHeight:"16px",textTransform:"uppercase",fontSize:"12px",color:"#999"}}}),r=function(A,s){A.r||A.g||A.b?n({r:A.r||i.r,g:A.g||i.g,b:A.b||i.b,source:"rgb"},s):n({hex:A.hex,source:"hex"},s)};return N.createElement("div",{style:C.fields,className:"flexbox-fix"},N.createElement("div",{style:C.active}),N.createElement(Gg,{style:{wrap:C.HEXwrap,input:C.HEXinput,label:C.HEXlabel},label:"hex",value:I,onChange:r}),N.createElement(Gg,{style:{wrap:C.RGBwrap,input:C.RGBinput,label:C.RGBlabel},label:"r",value:i.r,onChange:r}),N.createElement(Gg,{style:{wrap:C.RGBwrap,input:C.RGBinput,label:C.RGBlabel},label:"g",value:i.g,onChange:r}),N.createElement(Gg,{style:{wrap:C.RGBwrap,input:C.RGBinput,label:C.RGBlabel},label:"b",value:i.b,onChange:r}))},m4=function(g){var I=g.onChange,i=g.onSwatchHover,n=g.colors,C=g.hex,r=g.rgb,o=g.styles,A=o===void 0?{}:o,s=g.className,a=s===void 0?"":s,l=Qt(FC({default:{Compact:{background:"#f6f6f6",radius:"4px"},compact:{paddingTop:"5px",paddingLeft:"5px",boxSizing:"initial",width:"240px"},clear:{clear:"both"}}},A)),c=function(d,h){d.hex?ru(d.hex)&&I({hex:d.hex,source:"hex"},h):I(d,h)};return N.createElement(cw,{style:l.Compact,styles:A},N.createElement("div",{style:l.compact,className:"compact-picker "+a},N.createElement("div",null,Cu(n,function(u){return N.createElement(r7t,{key:u,color:u,active:u.toLowerCase()===C,onClick:c,onSwatchHover:i})}),N.createElement("div",{style:l.clear})),N.createElement(o7t,{hex:C,rgb:r,onChange:c})))};m4.propTypes={colors:L.arrayOf(L.string),styles:L.object};m4.defaultProps={colors:["#4D4D4D","#999999","#FFFFFF","#F44E3B","#FE9200","#FCDC00","#DBDF00","#A4DD00","#68CCCA","#73D8FF","#AEA1FF","#FDA1FF","#333333","#808080","#cccccc","#D33115","#E27300","#FCC400","#B0BC00","#68BC00","#16A5A5","#009CE0","#7B64FF","#FA28FF","#000000","#666666","#B3B3B3","#9F0500","#C45100","#FB9E00","#808900","#194D33","#0C797D","#0062B1","#653294","#AB149E"],styles:{}};EC(m4);var A7t=function(g){var I=g.hover,i=g.color,n=g.onClick,C=g.onSwatchHover,r={position:"relative",zIndex:"2",outline:"2px solid #fff",boxShadow:"0 0 5px 2px rgba(0,0,0,0.25)"},o=Qt({default:{swatch:{width:"25px",height:"25px",fontSize:"0"}},hover:{swatch:r}},{hover:I});return N.createElement("div",{style:o.swatch},N.createElement(lm,{color:i,onClick:n,onHover:C,focusStyle:r}))};const a7t=s4(A7t);var f4=function(g){var I=g.width,i=g.colors,n=g.onChange,C=g.onSwatchHover,r=g.triangle,o=g.styles,A=o===void 0?{}:o,s=g.className,a=s===void 0?"":s,l=Qt(FC({default:{card:{width:I,background:"#fff",border:"1px solid rgba(0,0,0,0.2)",boxShadow:"0 3px 12px rgba(0,0,0,0.15)",borderRadius:"4px",position:"relative",padding:"5px",display:"flex",flexWrap:"wrap"},triangle:{position:"absolute",border:"7px solid transparent",borderBottomColor:"#fff"},triangleShadow:{position:"absolute",border:"8px solid transparent",borderBottomColor:"rgba(0,0,0,0.15)"}},"hide-triangle":{triangle:{display:"none"},triangleShadow:{display:"none"}},"top-left-triangle":{triangle:{top:"-14px",left:"10px"},triangleShadow:{top:"-16px",left:"9px"}},"top-right-triangle":{triangle:{top:"-14px",right:"10px"},triangleShadow:{top:"-16px",right:"9px"}},"bottom-left-triangle":{triangle:{top:"35px",left:"10px",transform:"rotate(180deg)"},triangleShadow:{top:"37px",left:"9px",transform:"rotate(180deg)"}},"bottom-right-triangle":{triangle:{top:"35px",right:"10px",transform:"rotate(180deg)"},triangleShadow:{top:"37px",right:"9px",transform:"rotate(180deg)"}}},A),{"hide-triangle":r==="hide","top-left-triangle":r==="top-left","top-right-triangle":r==="top-right","bottom-left-triangle":r==="bottom-left","bottom-right-triangle":r==="bottom-right"}),c=function(d,h){return n({hex:d,source:"hex"},h)};return N.createElement("div",{style:l.card,className:"github-picker "+a},N.createElement("div",{style:l.triangleShadow}),N.createElement("div",{style:l.triangle}),Cu(i,function(u){return N.createElement(a7t,{color:u,key:u,onClick:c,onSwatchHover:C})}))};f4.propTypes={width:L.oneOfType([L.string,L.number]),colors:L.arrayOf(L.string),triangle:L.oneOf(["hide","top-left","top-right","bottom-left","bottom-right"]),styles:L.object};f4.defaultProps={width:200,colors:["#B80000","#DB3E00","#FCCB00","#008B02","#006B76","#1273DE","#004DCF","#5300EB","#EB9694","#FAD0C3","#FEF3BD","#C1E1C5","#BEDADC","#C4DEF6","#BED3F3","#D4C4FB"],triangle:"top-left",styles:{}};EC(f4);var s7t=function(g){var I=g.direction,i=Qt({default:{picker:{width:"18px",height:"18px",borderRadius:"50%",transform:"translate(-9px, -1px)",backgroundColor:"rgb(248, 248, 248)",boxShadow:"0 1px 4px 0 rgba(0, 0, 0, 0.37)"}},vertical:{picker:{transform:"translate(-3px, -9px)"}}},{vertical:I==="vertical"});return N.createElement("div",{style:i.picker})},l7t=Object.assign||function(e){for(var g=1;g.5});return N.createElement("div",{style:i.picker})},h7t=function(){var g=Qt({default:{triangle:{width:0,height:0,borderStyle:"solid",borderWidth:"4px 0 4px 6px",borderColor:"transparent transparent transparent #fff",position:"absolute",top:"1px",left:"1px"},triangleBorder:{width:0,height:0,borderStyle:"solid",borderWidth:"5px 0 5px 8px",borderColor:"transparent transparent transparent #555"},left:{Extend:"triangleBorder",transform:"translate(-13px, -4px)"},leftInside:{Extend:"triangle",transform:"translate(-8px, -5px)"},right:{Extend:"triangleBorder",transform:"translate(20px, -14px) rotate(180deg)"},rightInside:{Extend:"triangle",transform:"translate(-8px, -5px)"}}});return N.createElement("div",{style:g.pointer},N.createElement("div",{style:g.left},N.createElement("div",{style:g.leftInside})),N.createElement("div",{style:g.right},N.createElement("div",{style:g.rightInside})))},iae=function(g){var I=g.onClick,i=g.label,n=g.children,C=g.active,r=Qt({default:{button:{backgroundImage:"linear-gradient(-180deg, #FFFFFF 0%, #E6E6E6 100%)",border:"1px solid #878787",borderRadius:"2px",height:"20px",boxShadow:"0 1px 0 0 #EAEAEA",fontSize:"14px",color:"#000",lineHeight:"20px",textAlign:"center",marginBottom:"10px",cursor:"pointer"}},active:{button:{boxShadow:"0 0 0 1px #878787"}}},{active:C});return N.createElement("div",{style:r.button,onClick:I},i||n)},m7t=function(g){var I=g.rgb,i=g.currentColor,n=Qt({default:{swatches:{border:"1px solid #B3B3B3",borderBottom:"1px solid #F0F0F0",marginBottom:"2px",marginTop:"1px"},new:{height:"34px",background:"rgb("+I.r+","+I.g+", "+I.b+")",boxShadow:"inset 1px 0 0 #000, inset -1px 0 0 #000, inset 0 1px 0 #000"},current:{height:"34px",background:i,boxShadow:"inset 1px 0 0 #000, inset -1px 0 0 #000, inset 0 -1px 0 #000"},label:{fontSize:"14px",color:"#000",textAlign:"center"}}});return N.createElement("div",null,N.createElement("div",{style:n.label},"new"),N.createElement("div",{style:n.swatches},N.createElement("div",{style:n.new}),N.createElement("div",{style:n.current})),N.createElement("div",{style:n.label},"current"))},f7t=function(){function e(g,I){for(var i=0;i100&&(a.a=100),a.a/=100,I({h:n.h,s:n.s,l:n.l,a:a.a,source:"rgb"},l))};return N.createElement("div",{style:o.fields,className:"flexbox-fix"},N.createElement("div",{style:o.double},N.createElement(Gg,{style:{input:o.input,label:o.label},label:"hex",value:C.replace("#",""),onChange:A})),N.createElement("div",{style:o.single},N.createElement(Gg,{style:{input:o.input,label:o.label},label:"r",value:i.r,onChange:A,dragLabel:"true",dragMax:"255"})),N.createElement("div",{style:o.single},N.createElement(Gg,{style:{input:o.input,label:o.label},label:"g",value:i.g,onChange:A,dragLabel:"true",dragMax:"255"})),N.createElement("div",{style:o.single},N.createElement(Gg,{style:{input:o.input,label:o.label},label:"b",value:i.b,onChange:A,dragLabel:"true",dragMax:"255"})),N.createElement("div",{style:o.alpha},N.createElement(Gg,{style:{input:o.input,label:o.label},label:"a",value:Math.round(i.a*100),onChange:A,dragLabel:"true",dragMax:"100"})))},G7t=Object.assign||function(e){for(var g=1;g=0||Object.prototype.hasOwnProperty.call(e,i)&&(I[i]=e[i]);return I}var BR=24,X7t=jWe.default=function(e){var g=e.fill,I=g===void 0?"currentColor":g,i=e.width,n=i===void 0?BR:i,C=e.height,r=C===void 0?BR:C,o=e.style,A=o===void 0?{}:o,s=W7t(e,["fill","width","height","style"]);return Cae.default.createElement("svg",nae({viewBox:"0 0 "+BR+" "+BR,style:nae({fill:I,width:n,height:r},A)},s),Cae.default.createElement("path",{d:"M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"}))},H7t=function(g){var I=g.color,i=g.onClick,n=i===void 0?function(){}:i,C=g.onSwatchHover,r=g.first,o=g.last,A=g.active,s=Qt({default:{color:{width:"40px",height:"24px",cursor:"pointer",background:I,marginBottom:"1px"},check:{color:c4(I),marginLeft:"8px",display:"none"}},first:{color:{overflow:"hidden",borderRadius:"2px 2px 0 0"}},last:{color:{overflow:"hidden",borderRadius:"0 0 2px 2px"}},active:{check:{display:"block"}},"color-#FFFFFF":{color:{boxShadow:"inset 0 0 0 1px #ddd"},check:{color:"#333"}},transparent:{check:{color:"#333"}}},{first:r,last:o,active:A,"color-#FFFFFF":I==="#FFFFFF",transparent:I==="transparent"});return N.createElement(lm,{color:I,style:s.color,onClick:n,onHover:C,focusStyle:{boxShadow:"0 0 4px "+I}},N.createElement("div",{style:s.check},N.createElement(X7t,null)))},T7t=function(g){var I=g.onClick,i=g.onSwatchHover,n=g.group,C=g.active,r=Qt({default:{group:{paddingBottom:"10px",width:"40px",float:"left",marginRight:"10px"}}});return N.createElement("div",{style:r.group},Cu(n,function(o,A){return N.createElement(H7t,{key:o,color:o,active:o.toLowerCase()===C,first:A===0,last:A===n.length-1,onClick:I,onSwatchHover:i})}))},G4=function(g){var I=g.width,i=g.height,n=g.onChange,C=g.onSwatchHover,r=g.colors,o=g.hex,A=g.styles,s=A===void 0?{}:A,a=g.className,l=a===void 0?"":a,c=Qt(FC({default:{picker:{width:I,height:i},overflow:{height:i,overflowY:"scroll"},body:{padding:"16px 0 6px 16px"},clear:{clear:"both"}}},s)),u=function(h,m){return n({hex:h,source:"hex"},m)};return N.createElement("div",{style:c.picker,className:"swatches-picker "+l},N.createElement(cw,null,N.createElement("div",{style:c.overflow},N.createElement("div",{style:c.body},Cu(r,function(d){return N.createElement(T7t,{key:d.toString(),group:d,active:o,onClick:u,onSwatchHover:C})}),N.createElement("div",{style:c.clear})))))};G4.propTypes={width:L.oneOfType([L.string,L.number]),height:L.oneOfType([L.string,L.number]),colors:L.arrayOf(L.arrayOf(L.string)),styles:L.object};G4.defaultProps={width:320,height:240,colors:[[cf[900],cf[700],cf[500],cf[300],cf[100]],[uf[900],uf[700],uf[500],uf[300],uf[100]],[df[900],df[700],df[500],df[300],df[100]],[hf[900],hf[700],hf[500],hf[300],hf[100]],[mf[900],mf[700],mf[500],mf[300],mf[100]],[ff[900],ff[700],ff[500],ff[300],ff[100]],[pf[900],pf[700],pf[500],pf[300],pf[100]],[bf[900],bf[700],bf[500],bf[300],bf[100]],[yf[900],yf[700],yf[500],yf[300],yf[100]],["#194D33",QZ[700],QZ[500],QZ[300],QZ[100]],[Zf[900],Zf[700],Zf[500],Zf[300],Zf[100]],[Gf[900],Gf[700],Gf[500],Gf[300],Gf[100]],[vf[900],vf[700],vf[500],vf[300],vf[100]],[Bf[900],Bf[700],Bf[500],Bf[300],Bf[100]],[Sf[900],Sf[700],Sf[500],Sf[300],Sf[100]],[wf[900],wf[700],wf[500],wf[300],wf[100]],[Vf[900],Vf[700],Vf[500],Vf[300],Vf[100]],[Rf[900],Rf[700],Rf[500],Rf[300],Rf[100]],["#000000","#525252","#969696","#D9D9D9","#FFFFFF"]],styles:{}};EC(G4);var v4=function(g){var I=g.onChange,i=g.onSwatchHover,n=g.hex,C=g.colors,r=g.width,o=g.triangle,A=g.styles,s=A===void 0?{}:A,a=g.className,l=a===void 0?"":a,c=Qt(FC({default:{card:{width:r,background:"#fff",border:"0 solid rgba(0,0,0,0.25)",boxShadow:"0 1px 4px rgba(0,0,0,0.25)",borderRadius:"4px",position:"relative"},body:{padding:"15px 9px 9px 15px"},label:{fontSize:"18px",color:"#fff"},triangle:{width:"0px",height:"0px",borderStyle:"solid",borderWidth:"0 9px 10px 9px",borderColor:"transparent transparent #fff transparent",position:"absolute"},triangleShadow:{width:"0px",height:"0px",borderStyle:"solid",borderWidth:"0 9px 10px 9px",borderColor:"transparent transparent rgba(0,0,0,.1) transparent",position:"absolute"},hash:{background:"#F0F0F0",height:"30px",width:"30px",borderRadius:"4px 0 0 4px",float:"left",color:"#98A1A4",display:"flex",alignItems:"center",justifyContent:"center"},input:{width:"100px",fontSize:"14px",color:"#666",border:"0px",outline:"none",height:"28px",boxShadow:"inset 0 0 0 1px #F0F0F0",boxSizing:"content-box",borderRadius:"0 4px 4px 0",float:"left",paddingLeft:"8px"},swatch:{width:"30px",height:"30px",float:"left",borderRadius:"4px",margin:"0 6px 6px 0"},clear:{clear:"both"}},"hide-triangle":{triangle:{display:"none"},triangleShadow:{display:"none"}},"top-left-triangle":{triangle:{top:"-10px",left:"12px"},triangleShadow:{top:"-11px",left:"12px"}},"top-right-triangle":{triangle:{top:"-10px",right:"12px"},triangleShadow:{top:"-11px",right:"12px"}}},s),{"hide-triangle":o==="hide","top-left-triangle":o==="top-left","top-right-triangle":o==="top-right"}),u=function(h,m){ru(h)&&I({hex:h,source:"hex"},m)};return N.createElement("div",{style:c.card,className:"twitter-picker "+l},N.createElement("div",{style:c.triangleShadow}),N.createElement("div",{style:c.triangle}),N.createElement("div",{style:c.body},Cu(C,function(d,h){return N.createElement(lm,{key:h,color:d,hex:d,style:c.swatch,onClick:u,onHover:i,focusStyle:{boxShadow:"0 0 4px "+d}})}),N.createElement("div",{style:c.hash},"#"),N.createElement(Gg,{label:null,style:{input:c.input},value:n.replace("#",""),onChange:u}),N.createElement("div",{style:c.clear})))};v4.propTypes={width:L.oneOfType([L.string,L.number]),triangle:L.oneOf(["hide","top-left","top-right"]),colors:L.arrayOf(L.string),styles:L.object};v4.defaultProps={width:276,colors:["#FF6900","#FCB900","#7BDCB5","#00D084","#8ED1FC","#0693E3","#ABB8C3","#EB144C","#F78DA7","#9900EF"],triangle:"top-left",styles:{}};EC(v4);var B4=function(g){var I=Qt({default:{picker:{width:"20px",height:"20px",borderRadius:"22px",border:"2px #fff solid",transform:"translate(-12px, -13px)",background:"hsl("+Math.round(g.hsl.h)+", "+Math.round(g.hsl.s*100)+"%, "+Math.round(g.hsl.l*100)+"%)"}}});return N.createElement("div",{style:I.picker})};B4.propTypes={hsl:L.shape({h:L.number,s:L.number,l:L.number,a:L.number})};B4.defaultProps={hsl:{a:1,h:249.94,l:.2,s:.5}};var S4=function(g){var I=Qt({default:{picker:{width:"20px",height:"20px",borderRadius:"22px",transform:"translate(-10px, -7px)",background:"hsl("+Math.round(g.hsl.h)+", 100%, 50%)",border:"2px white solid"}}});return N.createElement("div",{style:I.picker})};S4.propTypes={hsl:L.shape({h:L.number,s:L.number,l:L.number,a:L.number})};S4.defaultProps={hsl:{a:1,h:249.94,l:.2,s:.5}};var N7t=function(g){var I=g.onChange,i=g.rgb,n=g.hsl,C=g.hex,r=g.hsv,o=function(u,d){if(u.hex)ru(u.hex)&&I({hex:u.hex,source:"hex"},d);else if(u.rgb){var h=u.rgb.split(",");Tx(u.rgb,"rgb")&&I({r:h[0],g:h[1],b:h[2],a:1,source:"rgb"},d)}else if(u.hsv){var m=u.hsv.split(",");Tx(u.hsv,"hsv")&&(m[2]=m[2].replace("%",""),m[1]=m[1].replace("%",""),m[0]=m[0].replace("°",""),m[1]==1?m[1]=.01:m[2]==1&&(m[2]=.01),I({h:Number(m[0]),s:Number(m[1]),v:Number(m[2]),source:"hsv"},d))}else if(u.hsl){var f=u.hsl.split(",");Tx(u.hsl,"hsl")&&(f[2]=f[2].replace("%",""),f[1]=f[1].replace("%",""),f[0]=f[0].replace("°",""),l[1]==1?l[1]=.01:l[2]==1&&(l[2]=.01),I({h:Number(f[0]),s:Number(f[1]),v:Number(f[2]),source:"hsl"},d))}},A=Qt({default:{wrap:{display:"flex",height:"100px",marginTop:"4px"},fields:{width:"100%"},column:{paddingTop:"10px",display:"flex",justifyContent:"space-between"},double:{padding:"0px 4.4px",boxSizing:"border-box"},input:{width:"100%",height:"38px",boxSizing:"border-box",padding:"4px 10% 3px",textAlign:"center",border:"1px solid #dadce0",fontSize:"11px",textTransform:"lowercase",borderRadius:"5px",outline:"none",fontFamily:"Roboto,Arial,sans-serif"},input2:{height:"38px",width:"100%",border:"1px solid #dadce0",boxSizing:"border-box",fontSize:"11px",textTransform:"lowercase",borderRadius:"5px",outline:"none",paddingLeft:"10px",fontFamily:"Roboto,Arial,sans-serif"},label:{textAlign:"center",fontSize:"12px",background:"#fff",position:"absolute",textTransform:"uppercase",color:"#3c4043",width:"35px",top:"-6px",left:"0",right:"0",marginLeft:"auto",marginRight:"auto",fontFamily:"Roboto,Arial,sans-serif"},label2:{left:"10px",textAlign:"center",fontSize:"12px",background:"#fff",position:"absolute",textTransform:"uppercase",color:"#3c4043",width:"32px",top:"-6px",fontFamily:"Roboto,Arial,sans-serif"},single:{flexGrow:"1",margin:"0px 4.4px"}}}),s=i.r+", "+i.g+", "+i.b,a=Math.round(n.h)+"°, "+Math.round(n.s*100)+"%, "+Math.round(n.l*100)+"%",l=Math.round(r.h)+"°, "+Math.round(r.s*100)+"%, "+Math.round(r.v*100)+"%";return N.createElement("div",{style:A.wrap,className:"flexbox-fix"},N.createElement("div",{style:A.fields},N.createElement("div",{style:A.double},N.createElement(Gg,{style:{input:A.input,label:A.label},label:"hex",value:C,onChange:o})),N.createElement("div",{style:A.column},N.createElement("div",{style:A.single},N.createElement(Gg,{style:{input:A.input2,label:A.label2},label:"rgb",value:s,onChange:o})),N.createElement("div",{style:A.single},N.createElement(Gg,{style:{input:A.input2,label:A.label2},label:"hsv",value:l,onChange:o})),N.createElement("div",{style:A.single},N.createElement(Gg,{style:{input:A.input2,label:A.label2},label:"hsl",value:a,onChange:o})))))},w4=function(g){var I=g.width,i=g.onChange,n=g.rgb,C=g.hsl,r=g.hsv,o=g.hex,A=g.header,s=g.styles,a=s===void 0?{}:s,l=g.className,c=l===void 0?"":l,u=Qt(FC({default:{picker:{width:I,background:"#fff",border:"1px solid #dfe1e5",boxSizing:"initial",display:"flex",flexWrap:"wrap",borderRadius:"8px 8px 0px 0px"},head:{height:"57px",width:"100%",paddingTop:"16px",paddingBottom:"16px",paddingLeft:"16px",fontSize:"20px",boxSizing:"border-box",fontFamily:"Roboto-Regular,HelveticaNeue,Arial,sans-serif"},saturation:{width:"70%",padding:"0px",position:"relative",overflow:"hidden"},swatch:{width:"30%",height:"228px",padding:"0px",background:"rgba("+n.r+", "+n.g+", "+n.b+", 1)",position:"relative",overflow:"hidden"},body:{margin:"auto",width:"95%"},controls:{display:"flex",boxSizing:"border-box",height:"52px",paddingTop:"22px"},color:{width:"32px"},hue:{height:"8px",position:"relative",margin:"0px 16px 0px 16px",width:"100%"},Hue:{radius:"2px"}}},a));return N.createElement("div",{style:u.picker,className:"google-picker "+c},N.createElement("div",{style:u.head},A),N.createElement("div",{style:u.swatch}),N.createElement("div",{style:u.saturation},N.createElement(yk,{hsl:C,hsv:r,pointer:B4,onChange:i})),N.createElement("div",{style:u.body},N.createElement("div",{style:u.controls,className:"flexbox-fix"},N.createElement("div",{style:u.hue},N.createElement(ey,{style:u.Hue,hsl:C,radius:"4px",pointer:S4,onChange:i}))),N.createElement(N7t,{rgb:n,hsl:C,hex:o,hsv:r,onChange:i})))};w4.propTypes={width:L.oneOfType([L.string,L.number]),styles:L.object,header:L.string};w4.defaultProps={width:652,styles:{},header:"Color picker"};EC(w4);function k7t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function rae(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function B2(e){return B2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},B2(e)}let $We=function(e){x7t(I,e);var g=F7t(I);function I(i){var n;k7t(this,I),n=g.call(this,i);const C=db(i.color);return n.state={displayColorPicker:!1,color:{r:C.r,g:C.g,b:C.b,a:C.opacity}},n}return Y7t(I,[{key:"handleClick",value:function(){this.setState(n=>({displayColorPicker:!n.displayColorPicker}))}},{key:"handleClose",value:function(){this.setState({displayColorPicker:!1})}},{key:"handleChange",value:function(n){const C=n.rgb,r=`rgba(${C.r},${C.g},${C.b},${C.a})`;this.props.onChange(r),this.setState({color:n.rgb})}},{key:"render",value:function(){const n=Qt({default:{color:{width:"32px",height:"14px",borderRadius:"2px",background:`rgba(${this.state.color.r}, ${this.state.color.g}, ${this.state.color.b}, ${this.state.color.a})`},swatch:{padding:"5px",background:"#fff",cursor:"pointer",borderRadius:"1px"},popover:{position:"absolute",zIndex:"2"},cover:{position:"fixed",top:"0px",right:"0px",bottom:"0px",left:"0px"}}});return N.createElement("div",null,N.createElement("div",{onClick:this.handleClick.bind(this),style:n.swatch},N.createElement("div",{style:n.color})),this.state.displayColorPicker?N.createElement("div",{style:n.popover},N.createElement("div",{onClick:this.handleClose.bind(this),style:n.cover}),N.createElement(B7t,{color:this.state.color,onChange:this.handleChange.bind(this)})):null)}}]),I}(N.Component);$We.propTypes={color:L.string,onChange:L.func};function P7t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function oae(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function S2(e){return S2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},S2(e)}let ZJ=function(e){L7t(I,e);var g=U7t(I);function I(i){var n;return P7t(this,I),n=g.call(this,i),n.state={colors:i.track.options.colorRange.slice()},n}return J7t(I,[{key:"handleColorsChanged",value:function(n){this.setState({colors:n})}},{key:"handleSubmit",value:function(){const n=this.props.track.options;n.colorRange=this.state.colors,this.props.onSubmit(this.props.track.options)}},{key:"handleAddColor",value:function(){this.setState(n=>({colors:n.colors.concat(n.colors[n.colors.length-1])}))}},{key:"handleRemoveColor",value:function(n){this.setState(C=>({colors:C.colors.slice(0,n).concat(C.colors.slice(n+1))}))}},{key:"render",value:function(){const n=JSON.parse(JSON.stringify(this.props.track)),C=Object.assign(n,{options:{colorRange:this.state.colors}}),r={editable:!1,zoomFixed:!0,views:[{uid:`hmo-${this.props.track.uid}`,initialXDomain:this.props.xScale?this.props.xScale.domain():[0,1],initialYDomain:this.props.yScale?this.props.yScale.domain():[0,1],tracks:{center:[C]},layout:{x:0,y:0,h:12,w:12,i:`hmo-${this.props.track.id}`}}]},o=this.state.colors.map((s,a)=>{const l=this.state.colors.length>2&&a===this.state.colors.length-1?N.createElement("div",{onClick:()=>this.handleRemoveColor(a),style:{background:"white",position:"absolute",top:0,right:0,opacity:1,width:14,height:14,borderRadius:2,cursor:"pointer"}},N.createElement("svg",{height:"10px",style:{position:"absolute",top:2,right:2,opacity:.5,width:10,height:10}},N.createElement("use",{xlinkHref:"#cross"}))):null;return N.createElement("div",{key:`l${a}`,style:{borderRadius:"1px",boxShadow:"0 0 0 1px #E5E5E5",position:"relative",outline:"none"}},l,N.createElement($We,{key:a,color:this.state.colors[a],onChange:c=>{this.setState(u=>{const d=u.colors.slice();return d[a]=c,{colors:d}},()=>{this.handleColorsChanged(this.state.colors)})}}))}).reverse(),A=this.state.colors.length<10?N.createElement("div",{onClick:this.handleAddColor.bind(this),style:{position:"relative",outline:"none",height:"25px",padding:"5px",background:"#fff",borderRadius:"1px",boxShadow:"0 0 0 1px #E5E5E5",cursor:"pointer"}},N.createElement("div",{style:{textAlign:"center",width:"32px",height:"14px"}},N.createElement("svg",{height:"100%",style:{opacity:.5,margin:"auto",display:"block"},width:"10px"},N.createElement("use",{xlinkHref:"#plus"})))):null;return N.createElement(Iw,{okayTitle:"Submit",onCancel:this.props.onCancel,onOkay:this.handleSubmit.bind(this),title:"Custom Color Map"},N.createElement("table",{className:"table-track-options"},N.createElement("thead",null),N.createElement("tbody",{style:{verticalAlign:"top"}},N.createElement("tr",null,N.createElement("td",{className:"td-track-options"},N.createElement("table",null,N.createElement("tbody",null,N.createElement("tr",null,N.createElement("td",{className:"td-track-options"},"Preview")),N.createElement("tr",null,N.createElement("td",{className:"td-track-options"},N.createElement("div",{style:{width:200}},N.createElement(gy,{options:{bounded:!1},viewConfig:r}))))))),N.createElement("td",{className:"td-track-options"},N.createElement("table",null,N.createElement("tbody",null,N.createElement("tr",null,N.createElement("td",{className:"td-track-options"},"Colors")),N.createElement("tr",null,N.createElement("td",{className:"td-track-options"},A,N.createElement("div",{style:{position:"relative"}},o))))))))))}}]),I}(N.Component);ZJ.propTypes={handleCancel:L.func,onCancel:L.func,onSubmit:L.func,track:L.object,xScale:L.object,yScale:L.object};const Aae=e=>{if(!e.header)return[];const g=e.header.split(" "),I=[];for(let i=0;ie.reduce((i,n)=>(i[n]={name:`${n*I}${g}`,value:n},i),{}),PC={yes:{name:"Yes",value:!0},no:{name:"No",value:!1}},HI={black:{name:"Black",value:"black"},blue:{name:"Blue",value:"blue"},brown:{name:"Brown",value:"brown"},cyan:{name:"Cyan",value:"cyan"},green:{name:"Green",value:"green"},grey:{name:"Grey",value:"grey"},orange:{name:"Orange",value:"orange"},purple:{name:"Purple",value:"purple"},turquoise:{name:"Turquoise",value:"turquoise"},red:{name:"Red",value:"red"},white:{name:"White",value:"white"}},q7t={use_stroke:{name:"Glyph color",value:"[glyph-color]"}},jZ=I0([1,2,3,5,8,13,21]),eQt=Object.assign(jZ,{none:{name:"none",value:"none"}}),SR=I0([0,2,4,8,16,32,64,128,256]),pl=I0([0,.2,.4,.6,.8,1],"%",100),tQt=I0([.2,.4,.6,.8,1],"%",100),In={axisLabelFormatting:{name:"Axis Label Formatting",inlineOptions:{normal:{name:"normal",value:"normal"},scientific:{name:"scientific",value:"scientific"}}},flipDiagonal:{name:"Flip Across Diagonal",inlineOptions:{none:{name:"No",value:"none"},yes:{name:"Yes",value:"yes"},copy:{name:"Copy",value:"copy"}}},heatmapValueScaling:{name:"Value Scaling",inlineOptions:{linear:{name:"Linear",value:"linear"},log:{name:"Log",value:"log"}}},valueScaling:{name:"Value Scaling",inlineOptions:{linear:{name:"Linear",value:"linear"},log:{name:"Log",value:"log"}}},extent:{name:"Extent",inlineOptions:{full:{name:"Full",value:"full"},upperRight:{name:"Upper Right",value:"upper-right"},lowerLeft:{name:"Lower Left",value:"lower-left"}}},labelLeftMargin:{name:"Label Left Margin",inlineOptions:SR},labelRightMargin:{name:"Label Right Margin",inlineOptions:SR},labelTopMargin:{name:"Label Top Margin",inlineOptions:SR},labelBottomMargin:{name:"Label Bottom Margin",inlineOptions:SR},labelShowResolution:{name:"Label Show Resolution",inlineOptions:PC},labelShowAssembly:{name:"Label Show Assembly",inlineOptions:PC},lineStrokeWidth:{name:"Stroke Width",inlineOptions:jZ},strokeWidth:{name:"Stroke Width",inlineOptions:jZ},trackBorderWidth:{name:"Track Border Width",inlineOptions:jZ},separatePlusMinusStrands:{name:"Separate +/- strands",inlineOptions:PC},sortLargestOnTop:{name:"Sort Largest On Top",inlineOptions:PC},showTexts:{name:"Show texts",inlineOptions:PC},staggered:{name:"Staggered",inlineOptions:PC},minSquareSize:{name:"Minimum size",inlineOptions:eQt},pointSize:{name:"Point Size",inlineOptions:jZ},pointColor:{name:"Point Color",inlineOptions:HI},trackBorderColor:{name:"Track Border Color",inlineOptions:HI},backgroundColor:{name:"Background Color",inlineOptions:{white:{name:"White",value:"white"},lightGrey:{name:"Light Grey",value:"#eeeeee"},grey:{name:"Grey",value:"#cccccc"},black:{name:"Black",value:"black"},transparent:{name:"Transparent",value:"transparent"}}},colorScale:{name:"Color Scale",inlineOptions:{epilogos:{name:"Epilogos",values:["#FF0000","#FF4500","#32CD32","#008000","#006400","#C2E105","#FFFF00","#66CDAA","#8A91D0","#CD5C5C","#E9967A","#BDB76B","#808080","#C0C0C0","#FFFFFF"]},category10:{name:"D3 Category10",values:["#1F77B4","#FF7F0E","#2CA02C","#D62728","#9467BD","#8C564B","#E377C2","#7F7F7F","#BCBD22","#17BECF"]}}},minusStrandColor:{name:"- Strand Color",inlineOptions:HI},plusStrandColor:{name:"+ Strand Color",inlineOptions:HI},lineStrokeColor:{name:"Stroke color",inlineOptions:HI},projectionStrokeColor:{name:"Stroke color",inlineOptions:HI},projectionFillColor:{name:"Fill color",inlineOptions:HI},stroke:{name:"Stroke Color",inlineOptions:HI},strokeColor:{name:"Stroke color",inlineOptions:HI},fill:{name:"Fill Color",inlineOptions:HI},color:{name:"Color",inlineOptions:HI},fontColor:{name:"Font color",inlineOptions:HI},fillColor:{name:"Fill color",inlineOptions:HI},barFillColor:{name:"Fill color",inlineOptions:HI},barFillColorTop:{name:"Top Fill color",inlineOptions:HI},barFillColorBottom:{name:"Bottom Fill color",inlineOptions:HI},barOpacity:{name:"Bar opacity",inlineOptions:pl},zeroLineVisible:{name:"Zero line visible",inlineOptions:PC},zeroLineColor:{name:"Zero line color",inlineOptions:HI},zeroLineOpacity:{name:"Zero line opacity",inlineOptions:tQt},fillOpacity:{name:"Fill Opacity",inlineOptions:pl},strokeOpacity:{name:"Stroke Opacity",inlineOptions:pl},strokePos:{name:"Stroke Position",inlineOptions:{aroundInner:{name:"Around Inner",value:"around"},aroundCenter:{name:"Around Center",value:null},hidden:{name:"Hidden",value:"hidden"},top:{name:"Top",value:"top"},right:{name:"Right",value:"right"},bottom:{name:"Bottom",value:"bottom"},left:{name:"Left",value:"left"}}},barBorder:{name:"Bar border",inlineOptions:PC},scaledHeight:{name:"Scaled height",inlineOptions:PC},rectangleDomainStrokeColor:{name:"Stroke color",inlineOptions:HI},rectangleDomainFillColor:{name:"Fill color",inlineOptions:HI},rectangleDomainFillOpacity:{name:"Fill opacity",inlineOptions:pl},rectangleDomainOpacity:{name:"Opacity",inlineOptions:pl},mapboxStyle:{name:"Map style",inlineOptions:{streets:{name:"streets",value:"mapbox.streets"},light:{name:"light",value:"mapbox.light"},dark:{name:"dark",value:"mapbox.dark"},satellite:{name:"satellite",value:"mapbox.satellite"},"streets-satellite":{name:"streets-satellite",value:"mapbox.streets-satellite"},wheatpaste:{name:"wheatpaste",value:"mapbox.wheatpaste"},"streets-basic":{name:"streets-basic",value:"mapbox.streets-basic"},comic:{name:"comic",value:"mapbox.comic"},outdoors:{name:"outdoors",value:"mapbox.outdoors"},"run-bike-hike":{name:"run-bike-hike",value:"mapbox.run-bike-hike"},pencil:{name:"pencil",value:"mapbox.pencil"},pirates:{name:"pirates",value:"mapbox.pirates"},emerald:{name:"emerald",value:"mapbox.emerald"},"high-contrast":{name:"high-contrast",value:"mapbox.high-contrast"}}},oneDHeatmapFlipped:{name:"Flip Heatmap",inlineOptions:{yes:{name:"Yes",value:"yes"},no:{name:"No",value:null}}},showMousePosition:{name:"Show Mouse Position",inlineOptions:PC},showTooltip:{name:"Show Tooltip",inlineOptions:PC},fontSize:{name:"Font Size",inlineOptions:I0([8,9,10,11,12,14,16,18,24],"px")},tickPositions:{name:"Tick Positions",inlineOptions:{even:{name:"Even",value:"even"},ends:{name:"Ends",value:"ends"}}},tickFormat:{name:"Tick Format",inlineOptions:{plain:{name:"Plain",value:"plain"},si:{name:"SI",value:"si"}}},colorEncoding:{name:"Color Encode Annotations",inlineOptions:{none:{name:"None",value:null},itemRgb:{name:"itemRgb",value:"itemRgb"}},generateOptions:Aae},fontIsAligned:{name:"Left-Align Font",inlineOptions:PC},axisPositionHorizontal:{name:"Axis Position",inlineOptions:{left:{name:"Left",value:"left"},outsideLeft:{name:"Outside left",value:"outsideLeft"},right:{name:"Right",value:"right"},outsideRight:{name:"Outside right",value:"outsideRight"},hidden:{name:"Hidden",value:null}}},axisPositionVertical:{name:"Axis Position",inlineOptions:{top:{name:"Top",value:"top"},outsideTop:{name:"Outside top",value:"outsideTop"},bottom:{name:"Bottom",value:"bottom"},outsideBottom:{name:"Outside bottom",value:"outsideBottom"},hidden:{name:"Hidden",value:null}}},axisMargin:{name:"Axis Margin",inlineOptions:I0([0,10,20,30,40,50,100,200,400],"px")},colorbarPosition:{name:"Colorbar Position",inlineOptions:{topLeft:{name:"Top Left",value:"topLeft"},topRight:{name:"Top Right",value:"topRight"},bottomLeft:{name:"Bottom Left",value:"bottomLeft"},bottomRight:{name:"Bottom Right",value:"bottomRight"},hidden:{name:"Hidden",value:null}}},colorbarBackgroundColor:{name:"Colorbar Background Color",inlineOptions:HI},colorbarBackgroundOpacity:{name:"Colorbar Background Opacity",inlineOptions:pl},colorbarLabelsPosition:{name:"Colorbar Labels Position",inlineOptions:{inside:{name:"Inside",value:"inside"},outside:{name:"Outside",value:"outside"}}},labelColor:{name:"Label Color",inlineOptions:{...HI,...q7t}},labelPosition:{name:"Label Position",inlineOptions:{ol:{name:"Outer left",value:"outerLeft"},or:{name:"Outer right",value:"outerRight"},ot:{name:"Outer top",value:"outerTop"},ob:{name:"Outer bottom",value:"outerBottom"},tl:{name:"Top left",value:"topLeft"},tr:{name:"Top right",value:"topRight"},bl:{name:"Bottom left",value:"bottomLeft"},br:{name:"Bottom right",value:"bottomRight"},hidden:{name:"Hidden",value:"hidden"}}},labelTextOpacity:{name:"Label Text Opacity",inlineOptions:pl},geneAnnotationHeight:{name:"Gene Annotation Height",inlineOptions:{8:{name:"8px",value:8},10:{name:"10px",value:10},12:{name:"12px",value:12},16:{name:"16px",value:16}}},annotationHeight:{name:"Annotation Height",inlineOptions:{5:{name:"5px",value:5},8:{name:"8px",value:8},10:{name:"10px",value:10},12:{name:"12px",value:12},16:{name:"16px",value:16},20:{name:"20px",value:20},scaled:{name:"scaled",value:"scaled"}}},maxAnnotationHeight:{name:"Max Annotation Height",inlineOptions:{5:{name:"5px",value:5},8:{name:"8px",value:8},10:{name:"10px",value:10},12:{name:"12px",value:12},16:{name:"16px",value:16},20:{name:"20px",value:20},none:{name:"none",value:null}}},annotationStyle:{name:"Annotation Style",inlineOptions:{box:{name:"Box",value:"box"},segment:{name:"Segment",value:"segment"}}},geneLabelPosition:{name:"Gene Label Position",inlineOptions:{inside:{name:"Inside",value:"inside"},outside:{name:"Outside",value:"outside"}}},geneStrandSpacing:{name:"Gene Strand Spacing",inlineOptions:{2:{name:"2px",value:2},4:{name:"4px",value:4},8:{name:"8px",value:8}}},labelBackgroundColor:{name:"Label Background Color",inlineOptions:HI},labelBackgroundOpacity:{name:"Label Background Opacity",inlineOptions:pl},viewResolution:{name:"View Resolution",inlineOptions:{high:{name:"High",value:384},medium:{name:"Medium",value:1024},low:{name:"Low",value:2048}}},colorRange:{name:"Color map",inlineOptions:{afmhot:{name:"afmhot",value:["rgba(0,0,0,1.0)","rgba(128,0,0,1.0)","rgba(256,129,1,1.0)","rgba(256,256,129,1.0)","rgba(256,256,256,1.0)"]},fall:{name:"fall",value:["white","rgba(245,166,35,1.0)","rgba(208,2,27,1.0)","black"]},hot:{name:"hot",value:["rgba(10,0,0,1.0)","rgba(179,0,0,1.0)","rgba(256,91,0,1.0)","rgba(256,256,6,1.0)","rgba(256,256,256,1.0)"]},jet:{name:"jet",value:["rgba(0,0,128,1.0)","rgba(0,129,256,1.0)","rgba(125,256,122,1.0)","rgba(256,148,0,1.0)","rgba(128,0,0,1.0)"]},bwr:{name:"bwr",value:["rgba(0,0,256,1.0)","rgba(128,128,256,1.0)","rgba(256,254,254,1.0)","rgba(256,126,126,1.0)","rgba(256,0,0,1.0)"]},cubehelix:{name:"cubehelix",value:["rgba(0,0,0,1.0)","rgba(21,83,76,1.0)","rgba(162,121,74,1.0)","rgba(199,180,238,1.0)","rgba(256,256,256,1.0)"]},rainbow:{name:"rainbow",value:["rgba(128,0,256,1.0)","rgba(0,181,236,1.0)","rgba(129,255,180,1.0)","rgba(256,179,96,1.0)","rgba(256,0,0,1.0)"]},gray:{name:"greys",value:["rgba(255,255,255,1)","rgba(0,0,0,1)"]},red:{name:"White to red",value:["rgba(255,255,255,1)","rgba(255,0,0,1)"]},green:{name:"White to green",value:["rgba(255,255,255,1)","rgba(0,255,0,1)"]},blue:{name:"White to blue",value:["rgba(255,255,255,1)","rgba(0,0,255,1)"]},custard:{name:"custard",value:["#FFFFFF","#F8E71C","rgba(245,166,35,1)","rgba(0,0,0,1)"]},magma:{name:"magma",value:["rgba(0,0,3,1)","rgba(0,0,4,1)","rgba(0,0,6,1)","rgba(1,0,7,1)","rgba(1,1,9,1)","rgba(1,1,11,1)","rgba(2,2,13,1)","rgba(2,2,15,1)","rgba(3,3,17,1)","rgba(4,3,19,1)","rgba(4,4,21,1)","rgba(5,4,23,1)","rgba(6,5,25,1)","rgba(7,5,27,1)","rgba(8,6,29,1)","rgba(9,7,32,1)","rgba(10,7,34,1)","rgba(11,8,36,1)","rgba(12,9,38,1)","rgba(13,10,40,1)","rgba(14,10,42,1)","rgba(15,11,45,1)","rgba(16,12,47,1)","rgba(17,12,49,1)","rgba(19,13,51,1)","rgba(20,13,54,1)","rgba(21,14,56,1)","rgba(22,14,58,1)","rgba(23,15,61,1)","rgba(25,15,63,1)","rgba(26,16,66,1)","rgba(27,16,68,1)","rgba(28,16,70,1)","rgba(30,17,73,1)","rgba(31,17,75,1)","rgba(33,17,78,1)","rgba(34,17,80,1)","rgba(36,17,83,1)","rgba(37,17,85,1)","rgba(39,17,87,1)","rgba(40,17,90,1)","rgba(42,17,92,1)","rgba(43,17,94,1)","rgba(45,17,97,1)","rgba(47,16,99,1)","rgba(49,16,101,1)","rgba(50,16,103,1)","rgba(52,16,105,1)","rgba(54,15,107,1)","rgba(55,15,108,1)","rgba(57,15,110,1)","rgba(59,15,112,1)","rgba(61,15,113,1)","rgba(62,15,114,1)","rgba(64,15,116,1)","rgba(66,15,117,1)","rgba(67,15,118,1)","rgba(69,15,119,1)","rgba(71,15,120,1)","rgba(72,16,120,1)","rgba(74,16,121,1)","rgba(76,16,122,1)","rgba(77,17,123,1)","rgba(79,17,123,1)","rgba(81,18,124,1)","rgba(82,18,124,1)","rgba(84,19,125,1)","rgba(85,20,125,1)","rgba(87,20,126,1)","rgba(88,21,126,1)","rgba(90,21,126,1)","rgba(92,22,127,1)","rgba(93,23,127,1)","rgba(95,23,127,1)","rgba(96,24,128,1)","rgba(98,25,128,1)","rgba(99,25,128,1)","rgba(101,26,128,1)","rgba(103,26,128,1)","rgba(104,27,129,1)","rgba(106,28,129,1)","rgba(107,28,129,1)","rgba(109,29,129,1)","rgba(110,30,129,1)","rgba(112,30,129,1)","rgba(113,31,129,1)","rgba(115,32,129,1)","rgba(117,32,129,1)","rgba(118,33,129,1)","rgba(120,33,129,1)","rgba(121,34,130,1)","rgba(123,35,130,1)","rgba(124,35,130,1)","rgba(126,36,130,1)","rgba(128,36,130,1)","rgba(129,37,129,1)","rgba(131,37,129,1)","rgba(132,38,129,1)","rgba(134,39,129,1)","rgba(136,39,129,1)","rgba(137,40,129,1)","rgba(139,40,129,1)","rgba(140,41,129,1)","rgba(142,41,129,1)","rgba(144,42,129,1)","rgba(145,42,129,1)","rgba(147,43,128,1)","rgba(148,43,128,1)","rgba(150,44,128,1)","rgba(152,44,128,1)","rgba(153,45,128,1)","rgba(155,46,127,1)","rgba(157,46,127,1)","rgba(158,47,127,1)","rgba(160,47,127,1)","rgba(161,48,126,1)","rgba(163,48,126,1)","rgba(165,49,126,1)","rgba(166,49,125,1)","rgba(168,50,125,1)","rgba(170,50,125,1)","rgba(171,51,124,1)","rgba(173,51,124,1)","rgba(175,52,123,1)","rgba(176,52,123,1)","rgba(178,53,123,1)","rgba(180,53,122,1)","rgba(181,54,122,1)","rgba(183,55,121,1)","rgba(185,55,121,1)","rgba(186,56,120,1)","rgba(188,56,120,1)","rgba(189,57,119,1)","rgba(191,57,118,1)","rgba(193,58,118,1)","rgba(194,59,117,1)","rgba(196,59,117,1)","rgba(198,60,116,1)","rgba(199,61,115,1)","rgba(201,61,115,1)","rgba(202,62,114,1)","rgba(204,63,113,1)","rgba(206,63,113,1)","rgba(207,64,112,1)","rgba(209,65,111,1)","rgba(210,66,110,1)","rgba(212,67,110,1)","rgba(213,67,109,1)","rgba(215,68,108,1)","rgba(216,69,107,1)","rgba(218,70,107,1)","rgba(219,71,106,1)","rgba(221,72,105,1)","rgba(222,73,104,1)","rgba(223,74,103,1)","rgba(225,75,103,1)","rgba(226,76,102,1)","rgba(227,78,101,1)","rgba(229,79,100,1)","rgba(230,80,100,1)","rgba(231,81,99,1)","rgba(232,83,98,1)","rgba(233,84,97,1)","rgba(234,85,97,1)","rgba(236,87,96,1)","rgba(237,88,95,1)","rgba(238,90,95,1)","rgba(239,91,94,1)","rgba(239,93,94,1)","rgba(240,95,93,1)","rgba(241,96,93,1)","rgba(242,98,93,1)","rgba(243,100,92,1)","rgba(243,101,92,1)","rgba(244,103,92,1)","rgba(245,105,92,1)","rgba(246,107,92,1)","rgba(246,108,92,1)","rgba(247,110,92,1)","rgba(247,112,92,1)","rgba(248,114,92,1)","rgba(248,116,92,1)","rgba(249,118,92,1)","rgba(249,120,92,1)","rgba(250,121,93,1)","rgba(250,123,93,1)","rgba(250,125,94,1)","rgba(251,127,94,1)","rgba(251,129,95,1)","rgba(251,131,95,1)","rgba(252,133,96,1)","rgba(252,135,97,1)","rgba(252,137,97,1)","rgba(252,139,98,1)","rgba(253,140,99,1)","rgba(253,142,100,1)","rgba(253,144,101,1)","rgba(253,146,102,1)","rgba(253,148,103,1)","rgba(254,150,104,1)","rgba(254,152,105,1)","rgba(254,154,106,1)","rgba(254,156,107,1)","rgba(254,157,108,1)","rgba(254,159,109,1)","rgba(254,161,110,1)","rgba(254,163,111,1)","rgba(254,165,112,1)","rgba(255,167,114,1)","rgba(255,169,115,1)","rgba(255,171,116,1)","rgba(255,172,118,1)","rgba(255,174,119,1)","rgba(255,176,120,1)","rgba(255,178,122,1)","rgba(255,180,123,1)","rgba(255,182,124,1)","rgba(255,184,126,1)","rgba(255,185,127,1)","rgba(255,187,129,1)","rgba(255,189,130,1)","rgba(255,191,132,1)","rgba(255,193,133,1)","rgba(255,195,135,1)","rgba(255,197,136,1)","rgba(255,198,138,1)","rgba(255,200,140,1)","rgba(255,202,141,1)","rgba(255,204,143,1)","rgba(254,206,144,1)","rgba(254,208,146,1)","rgba(254,209,148,1)","rgba(254,211,149,1)","rgba(254,213,151,1)","rgba(254,215,153,1)","rgba(254,217,155,1)","rgba(254,219,156,1)","rgba(254,220,158,1)","rgba(254,222,160,1)","rgba(254,224,162,1)","rgba(254,226,163,1)","rgba(253,228,165,1)","rgba(253,230,167,1)","rgba(253,231,169,1)","rgba(253,233,171,1)","rgba(253,235,172,1)","rgba(253,237,174,1)","rgba(253,239,176,1)","rgba(253,241,178,1)","rgba(253,242,180,1)","rgba(253,244,182,1)","rgba(253,246,184,1)","rgba(252,248,186,1)","rgba(252,250,188,1)","rgba(252,251,189,1)","rgba(252,253,191,1)"]},viridis:{name:"viridis",value:["rgba(68,1,84,1)","rgba(68,2,85,1)","rgba(69,3,87,1)","rgba(69,5,88,1)","rgba(69,6,90,1)","rgba(70,8,91,1)","rgba(70,9,93,1)","rgba(70,11,94,1)","rgba(70,12,96,1)","rgba(71,14,97,1)","rgba(71,15,98,1)","rgba(71,17,100,1)","rgba(71,18,101,1)","rgba(71,20,102,1)","rgba(72,21,104,1)","rgba(72,22,105,1)","rgba(72,24,106,1)","rgba(72,25,108,1)","rgba(72,26,109,1)","rgba(72,28,110,1)","rgba(72,29,111,1)","rgba(72,30,112,1)","rgba(72,32,113,1)","rgba(72,33,115,1)","rgba(72,34,116,1)","rgba(72,36,117,1)","rgba(72,37,118,1)","rgba(72,38,119,1)","rgba(72,39,120,1)","rgba(71,41,121,1)","rgba(71,42,121,1)","rgba(71,43,122,1)","rgba(71,44,123,1)","rgba(71,46,124,1)","rgba(70,47,125,1)","rgba(70,48,126,1)","rgba(70,49,126,1)","rgba(70,51,127,1)","rgba(69,52,128,1)","rgba(69,53,129,1)","rgba(69,54,129,1)","rgba(68,56,130,1)","rgba(68,57,131,1)","rgba(68,58,131,1)","rgba(67,59,132,1)","rgba(67,60,132,1)","rgba(67,62,133,1)","rgba(66,63,133,1)","rgba(66,64,134,1)","rgba(65,65,134,1)","rgba(65,66,135,1)","rgba(65,67,135,1)","rgba(64,69,136,1)","rgba(64,70,136,1)","rgba(63,71,136,1)","rgba(63,72,137,1)","rgba(62,73,137,1)","rgba(62,74,137,1)","rgba(61,75,138,1)","rgba(61,77,138,1)","rgba(60,78,138,1)","rgba(60,79,138,1)","rgba(59,80,139,1)","rgba(59,81,139,1)","rgba(58,82,139,1)","rgba(58,83,139,1)","rgba(57,84,140,1)","rgba(57,85,140,1)","rgba(56,86,140,1)","rgba(56,87,140,1)","rgba(55,88,140,1)","rgba(55,89,140,1)","rgba(54,91,141,1)","rgba(54,92,141,1)","rgba(53,93,141,1)","rgba(53,94,141,1)","rgba(52,95,141,1)","rgba(52,96,141,1)","rgba(51,97,141,1)","rgba(51,98,141,1)","rgba(51,99,141,1)","rgba(50,100,142,1)","rgba(50,101,142,1)","rgba(49,102,142,1)","rgba(49,103,142,1)","rgba(48,104,142,1)","rgba(48,105,142,1)","rgba(47,106,142,1)","rgba(47,107,142,1)","rgba(47,108,142,1)","rgba(46,109,142,1)","rgba(46,110,142,1)","rgba(45,111,142,1)","rgba(45,112,142,1)","rgba(45,112,142,1)","rgba(44,113,142,1)","rgba(44,114,142,1)","rgba(43,115,142,1)","rgba(43,116,142,1)","rgba(43,117,142,1)","rgba(42,118,142,1)","rgba(42,119,142,1)","rgba(41,120,142,1)","rgba(41,121,142,1)","rgba(41,122,142,1)","rgba(40,123,142,1)","rgba(40,124,142,1)","rgba(40,125,142,1)","rgba(39,126,142,1)","rgba(39,127,142,1)","rgba(38,128,142,1)","rgba(38,129,142,1)","rgba(38,130,142,1)","rgba(37,131,142,1)","rgba(37,131,142,1)","rgba(37,132,142,1)","rgba(36,133,142,1)","rgba(36,134,142,1)","rgba(35,135,142,1)","rgba(35,136,142,1)","rgba(35,137,142,1)","rgba(34,138,141,1)","rgba(34,139,141,1)","rgba(34,140,141,1)","rgba(33,141,141,1)","rgba(33,142,141,1)","rgba(33,143,141,1)","rgba(32,144,141,1)","rgba(32,145,140,1)","rgba(32,146,140,1)","rgba(32,147,140,1)","rgba(31,147,140,1)","rgba(31,148,140,1)","rgba(31,149,139,1)","rgba(31,150,139,1)","rgba(31,151,139,1)","rgba(30,152,139,1)","rgba(30,153,138,1)","rgba(30,154,138,1)","rgba(30,155,138,1)","rgba(30,156,137,1)","rgba(30,157,137,1)","rgba(30,158,137,1)","rgba(30,159,136,1)","rgba(30,160,136,1)","rgba(31,161,136,1)","rgba(31,162,135,1)","rgba(31,163,135,1)","rgba(31,163,134,1)","rgba(32,164,134,1)","rgba(32,165,134,1)","rgba(33,166,133,1)","rgba(33,167,133,1)","rgba(34,168,132,1)","rgba(35,169,131,1)","rgba(35,170,131,1)","rgba(36,171,130,1)","rgba(37,172,130,1)","rgba(38,173,129,1)","rgba(39,174,129,1)","rgba(40,175,128,1)","rgba(41,175,127,1)","rgba(42,176,127,1)","rgba(43,177,126,1)","rgba(44,178,125,1)","rgba(46,179,124,1)","rgba(47,180,124,1)","rgba(48,181,123,1)","rgba(50,182,122,1)","rgba(51,183,121,1)","rgba(53,183,121,1)","rgba(54,184,120,1)","rgba(56,185,119,1)","rgba(57,186,118,1)","rgba(59,187,117,1)","rgba(61,188,116,1)","rgba(62,189,115,1)","rgba(64,190,114,1)","rgba(66,190,113,1)","rgba(68,191,112,1)","rgba(70,192,111,1)","rgba(72,193,110,1)","rgba(73,194,109,1)","rgba(75,194,108,1)","rgba(77,195,107,1)","rgba(79,196,106,1)","rgba(81,197,105,1)","rgba(83,198,104,1)","rgba(85,198,102,1)","rgba(88,199,101,1)","rgba(90,200,100,1)","rgba(92,201,99,1)","rgba(94,201,98,1)","rgba(96,202,96,1)","rgba(98,203,95,1)","rgba(101,204,94,1)","rgba(103,204,92,1)","rgba(105,205,91,1)","rgba(108,206,90,1)","rgba(110,206,88,1)","rgba(112,207,87,1)","rgba(115,208,85,1)","rgba(117,208,84,1)","rgba(119,209,82,1)","rgba(122,210,81,1)","rgba(124,210,79,1)","rgba(127,211,78,1)","rgba(129,212,76,1)","rgba(132,212,75,1)","rgba(134,213,73,1)","rgba(137,213,72,1)","rgba(139,214,70,1)","rgba(142,215,68,1)","rgba(144,215,67,1)","rgba(147,216,65,1)","rgba(149,216,63,1)","rgba(152,217,62,1)","rgba(155,217,60,1)","rgba(157,218,58,1)","rgba(160,218,57,1)","rgba(163,219,55,1)","rgba(165,219,53,1)","rgba(168,220,51,1)","rgba(171,220,50,1)","rgba(173,221,48,1)","rgba(176,221,46,1)","rgba(179,221,45,1)","rgba(181,222,43,1)","rgba(184,222,41,1)","rgba(187,223,39,1)","rgba(189,223,38,1)","rgba(192,223,36,1)","rgba(195,224,35,1)","rgba(197,224,33,1)","rgba(200,225,32,1)","rgba(203,225,30,1)","rgba(205,225,29,1)","rgba(208,226,28,1)","rgba(211,226,27,1)","rgba(213,226,26,1)","rgba(216,227,25,1)","rgba(219,227,24,1)","rgba(221,227,24,1)","rgba(224,228,24,1)","rgba(226,228,24,1)","rgba(229,228,24,1)","rgba(232,229,25,1)","rgba(234,229,25,1)","rgba(237,229,26,1)","rgba(239,230,27,1)","rgba(242,230,28,1)","rgba(244,230,30,1)","rgba(247,230,31,1)","rgba(249,231,33,1)","rgba(251,231,35,1)","rgba(254,231,36,1)"]},custom:{name:"Custom...",componentPickers:{heatmap:ZJ,"horizontal-heatmap":ZJ}}}},align:{name:"Align",inlineOptions:{white:{name:"Top",value:"top"},lightGrey:{name:"Bottom",value:"bottom"}}},colorRangeGradient:{name:"Color Gradient",inlineOptions:PC},dataTransform:{name:"Transforms",inlineOptions:{default:{name:"Default",value:"default"},None:{name:"None",value:"None"}},generateOptions:e=>{const g=[];if(e.transforms)for(const I of e.transforms)g.push({name:I.name,value:I.value});return g}},aggregationMode:{name:"Aggregation Mode",inlineOptions:{},generateOptions:e=>{const g=[];return e.aggregationModes?Object.values(e.aggregationModes).forEach(({name:I,value:i})=>{g.push({name:I,value:i})}):g.push({name:"Default",value:"default"}),g}},maxZoom:{name:"Zoom limit",inlineOptions:{none:{name:"None",value:null}},generateOptions:e=>{if(e.maxZoom){const g=[];for(let I=0;I<=e.maxZoom;I++){const{maxWidth:i,binsPerDimension:n,maxZoom:C}=e;let r=1,o=1;if(e.resolutions){const l=e.resolutions.map(c=>+c).sort((c,u)=>u-c);[r]=l,o=l[I]}else o=e.maxWidth/(2**I*e.binsPerDimension),r=i/(2**C*n);const A=S0(r,o),a=Oh(`.${A}`,o)(o);g.push({name:a,value:I.toString()})}return g}return[]}},valueColumn:{name:"Value column",inlineOptions:{none:{name:"None",value:null}},generateOptions:Aae},zeroValueColor:{name:"Zero Value Color",inlineOptions:HI}},qWe={...Zat,IS_TRACK_RANGE_SELECTABLE:V0,OPTIONS_INFO:In},gQt={d3Array:lgt,d3Axis:dHt,d3Brush:oAt,d3Color:Sgt,d3Drag:Frt,d3Dsv:Jat,d3Format:eIt,d3Geo:zFt,d3Queue:LFt,d3Request:uEt,d3Scale:Rit,d3Selection:stt,d3Transition:ERt,d3Zoom:LRt,PIXI:qWe.GLOBALS.PIXI,mix:U0,slugid:Ag},IQt={Annotations1dTrack:iP,Annotations2dTrack:VRe,ArrowheadDomainsTrack:SRe,BarTrack:vj,BedLikeTrack:fRe,CNVIntervalTrack:vRe,Chromosome2DAnnotations:HRe,Chromosome2DLabels:XRe,ChromosomeGrid:EZ,CombinedTrack:U7,CrossRule:e1e,DivergentBarTrack:ZRe,HeatmapTiledPixiTrack:QS,Horizontal1dHeatmapTrack:GRe,Horizontal2DDomainsTrack:RRe,HorizontalChromosomeLabels:NRe,HorizontalGeneAnnotationsTrack:BRe,HorizontalHeatmapTrack:kRe,HorizontalLine1DPixiTrack:L0,HorizontalMultivecTrack:yRe,HorizontalPoint1DPixiTrack:bRe,HorizontalRule:_Re,HorizontalTiled1DPixiTrack:O0,HorizontalTiledPlot:f2,HorizontalTrack:$1e,Id2DTiledPixiTrack:TVe,IdHorizontal1DTiledPixiTrack:kVe,IdVertical1DTiledPixiTrack:KVe,LeftAxisTrack:EVe,MapboxTilesTrack:I1e,MoveableTrack:ck,OSMTileIdsTrack:g1e,OSMTilesTrack:$S,OverlayTrack:pRe,PixiTrack:lC,RasterTilesTrack:i1e,SVGTrack:om,SquareMarkersTrack:WRe,Tiled1DPixiTrack:dj,TiledPixiTrack:rm,TopAxisTrack:FVe,Track:Rp,ValueIntervalTrack:KRe,VerticalRule:qRe,VerticalTiled1DPixiTrack:YVe,VerticalTrack:eWe,ViewportTracker2D:DRe,ViewportTracker2DPixi:NMt,ViewportTrackerHorizontal:xRe,ViewportTrackerVertical:FRe},iQt={ContextMenuItem:tg,DataFetcher:qN,LruCache:gWe},nQt={ChromosomeInfo:xs,SearchField:Lb},CQt={DataFetcher:qN,GBKDataFetcher:RVe,LocalDataFetcher:WVe,getDataFetcher:Rxt},w2={chromosomes:nQt,libraries:gQt,tracks:IQt,dataFetchers:CQt,factories:iQt,services:Gst,utils:a1t,configs:qWe,VERSION:IWe},Nx={"track-renderer":"_track-renderer_11dwb_1","track-renderer-element":"_track-renderer-element_11dwb_5","track-renderer-events":"_track-renderer-events_11dwb_6"};function rQt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function aae(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function V2(e){return V2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},V2(e)}const{getDataFetcher:dQt}=w2.dataFetchers,hQt=100;let V4=function(e){sQt(I,e);var g=lQt(I);function I(i){var n;if(rQt(this,I),n=g.call(this,i),n.dragging=!1,n.element=null,n.eventTracker=null,n.eventTrackerOld=null,n.closing=!1,n.yPositionOffset=0,n.xPositionOffset=0,n.scrollTop=0,n.scrollTimeout=null,n.activeTransitions=0,n.zoomTransform=Fi,n.windowScrolledBound=n.windowScrolled.bind(To(n)),n.zoomStartedBound=n.zoomStarted.bind(To(n)),n.zoomedBound=n.zoomed.bind(To(n)),n.zoomEndedBound=n.zoomEnded.bind(To(n)),n.uid=Ag.nice(),n.viewUid=n.props.uid,n.availableForPlugins={...w2,services:{...w2.services,pubSub:n.props.pubSub,pixiRenderer:n.props.pixiRenderer}},n.mounted=!1,n.emptyZoomBehavior=sz(),n.currentProps=i,n.prevPropsStr="",n.zoomBehavior=sz().filter(C=>!(C.target.classList.contains("no-zoom")||C.target.classList.contains("react-resizable-handle"))).on("start",n.zoomStartedBound).on("zoom",n.zoomedBound).on("end",n.zoomEndedBound),n.zoomTransform=Fi,n.prevZoomTransform=Fi,n.initialXDomain=[0,1],n.initialYDomain=[0,1],n.xDomainLimits=[-Number.MAX_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],n.yDomainLimits=[-Number.MAX_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],n.zoomLimits=[0,Number.MAX_SAFE_INTEGER],n.prevCenterX=n.currentProps.paddingLeft+n.currentProps.leftWidth+n.currentProps.centerWidth/2,n.prevCenterY=n.currentProps.paddingTop+n.currentProps.topHeight+n.currentProps.centerHeight/2,n.cumCenterXOffset=0,n.cumCenterYOffset=0,n.setUpInitialScales(n.currentProps.initialXDomain,n.currentProps.initialYDomain,n.currentProps.xDomainLimits,n.currentProps.yDomainLimits,n.currentProps.zoomLimits),n.setUpScales(),n.trackDefObjects={},n.metaTracks={},n.pubSubs=[],window.higlassTracksByType)for(const C in window.higlassTracksByType)Lg[C]=window.higlassTracksByType[C].config;return n.boundForwardEvent=n.forwardEvent.bind(To(n)),n.boundScrollEvent=n.scrollEvent.bind(To(n)),n.boundForwardContextMenu=n.forwardContextMenu.bind(To(n)),n.dispatchEventBound=n.dispatchEvent.bind(To(n)),n.zoomToDataPosHandlerBound=n.zoomToDataPosHandler.bind(To(n)),n.onScrollHandlerBound=n.onScrollHandler.bind(To(n)),n.elementPos={height:0,width:0,left:0,top:0},n.elementSelection=null,n}return oQt(I,[{key:"xScale",get:function(){if(!this._xScale)throw new Error("xScale is not defined");return this._xScale}},{key:"yScale",get:function(){if(!this._yScale)throw new Error("yScale is not defined");return this._yScale}},{key:"UNSAFE_componentWillMount",value:function(){this.pubSubs=[],this.pubSubs.push(this.props.pubSub.subscribe("scroll",this.windowScrolledBound)),this.pubSubs.push(this.props.pubSub.subscribe("app.event",this.dispatchEventBound)),this.pubSubs.push(this.props.pubSub.subscribe("zoomToDataPos",this.zoomToDataPosHandlerBound)),this.pubSubs.push(this.props.pubSub.subscribe("app.scroll",this.onScrollHandlerBound))}},{key:"componentDidMount",value:function(){if(!this.element)throw new Error("Component did not mount, this.element is not defined.");if(this.elementPos=this.element.getBoundingClientRect(),this.elementSelection=cg(this.element),this.pStage=new rt.PIXI.Graphics,this.pMask=new rt.PIXI.Graphics,this.pOutline=new rt.PIXI.Graphics,this.pBackground=new rt.PIXI.Graphics,this.pStage.addChild(this.pMask),this.pStage.addChild(this.pOutline),this.currentProps.pixiStage.addChild(this.pStage),this.pStage.mask=this.pMask,this.props.isRangeSelection||this.addZoom(),!this.currentProps.svgElement||!this.currentProps.canvasElement)return;this.svgElement=this.currentProps.svgElement,this.syncTrackObjects(this.currentProps.positionedTracks),this.syncMetaTracks(this.currentProps.metaTracks),this.currentProps.setCentersFunction(this.setCenter.bind(this)),this.currentProps.registerDraggingChangedListener(this.draggingChanged.bind(this)),this.draggingChanged(!0),this.addEventTracker();const n=[[this.xScale(this.xDomainLimits[0]),this.yScale(this.yDomainLimits[0])],[this.xScale(this.xDomainLimits[1]),this.yScale(this.yDomainLimits[1])]],C=this.svgElement.getBoundingClientRect(),r=[[Math.max(n[0][0],0),Math.max(n[0][1],0)],[Math.min(n[1][0],C.width),Math.min(n[1][1],C.height)]];this.zoomBehavior.extent(r).translateExtent(n).scaleExtent(this.zoomLimits)}},{key:"UNSAFE_componentWillReceiveProps",value:function(n){if(!n.svgElement||!n.canvasElement)return;const C=this.updatablePropsToString(n);if(this.currentProps=n,this.prevPropsStr===C)return;this.setBackground();for(const s in this.trackDefObjects){const a=this.trackDefObjects[s].trackObject;a.delayDrawing=!0}this.prevPropsStr=C,this.setUpInitialScales(n.initialXDomain,n.initialYDomain,n.xDomainLimits,n.yDomainLimits,n.zoomLimits),this.setUpScales(n.width!==this.props.width||n.height!==this.props.height),this.svgElement=n.svgElement;const r=[[this.xScale(this.xDomainLimits[0]),this.yScale(this.yDomainLimits[0])],[this.xScale(this.xDomainLimits[1]),this.yScale(this.yDomainLimits[1])]],o=this.svgElement.getBoundingClientRect(),A=[[Math.max(r[0][0],0),Math.max(r[0][1],0)],[Math.min(r[1][0],o.width),Math.min(r[1][1],o.height)]];this.zoomBehavior.extent(A).translateExtent(r).scaleExtent(this.zoomLimits),this.syncTrackObjects(n.positionedTracks),this.syncMetaTracks(n.metaTracks);for(const s of n.positionedTracks){const a=s.track.options,l=this.trackDefObjects[s.track.uid].trackObject;if(l.rerender(a),v1(s.track)){const c={};for(const u of s.track.contents)c[u.uid]=u;for(const u in l.createdTracks)l.createdTracks[u].rerender(c[u].options)}}this.props.onNewTilesLoaded();for(const s in this.trackDefObjects){const a=this.trackDefObjects[s].trackObject;a.delayDrawing=!1,a.draw()}}},{key:"componentDidUpdate",value:function(n){(this.props.initialXDomain[0]!==n.initialXDomain[0]||this.props.initialXDomain[1]!==n.initialXDomain[1]||this.props.initialYDomain[0]!==n.initialYDomain[0]||this.props.initialYDomain[1]!==n.initialYDomain[1])&&this.element&&(this.element.__zoom=Fi),n.isRangeSelection!==this.props.isRangeSelection&&(this.props.isRangeSelection?this.removeZoom():this.addZoom()),n.zoomable!==this.props.zoomable&&(this.props.zoomable?this.addZoom():this.removeZoom()),this.addEventTracker()}},{key:"componentWillUnmount",value:function(){var n,C;this.mounted=!1,this.removeTracks(Object.keys(this.trackDefObjects)),this.removeMetaTracks(Object.keys(this.metaTracks)),this.currentProps.removeDraggingChangedListener(this.draggingChanged),this.pStage&&this.currentProps.pixiStage.removeChild(this.pStage),(n=this.pMask)==null||n.destroy(!0),(C=this.pStage)==null||C.destroy(!0),this.pubSubs.forEach(r=>this.props.pubSub.unsubscribe(r)),this.pubSubs=[],this.removeEventTracker()}},{key:"dispatchEvent",value:function(n){n.sourceUid===this.uid&&n.type!=="contextmenu"&&this.element&&t9(n,this.element)}},{key:"isWithin",value:function(n,C){const r=n>=this.elementPos.left&&n<=this.elementPos.width+this.elementPos.left,o=C>=this.elementPos.top&&C<=this.elementPos.height+this.elementPos.top;return r&&o}},{key:"zoomToDataPosHandler",value:function({pos:n,animateTime:C}){this.zoomToDataPos(...n,C)}},{key:"addZoom",value:function(){!this.elementSelection||!this.currentProps.zoomable||(this.elementSelection.call(this.zoomBehavior),this.zoomBehavior.transform(this.elementSelection,this.zoomTransform))}},{key:"removeZoom",value:function(){this.elementSelection&&(this.zoomEnded(),this.elementSelection.on(".zoom",null))}},{key:"setMask",value:function(){var n,C,r,o;(n=this.pMask)==null||n.clear(),(C=this.pMask)==null||C.beginFill(),(r=this.pMask)==null||r.drawRect(this.xPositionOffset,this.yPositionOffset,this.currentProps.width,this.currentProps.height),(o=this.pMask)==null||o.endFill()}},{key:"setBackground",value:function(){var n,C,r,o,A;const s=this.props.theme===qg?"black":"white",a=Kt(((n=this.currentProps.viewOptions)==null?void 0:n.backgroundColor)??s);(C=this.pBackground)==null||C.clear(),(r=this.pBackground)==null||r.beginFill(a),(o=this.pBackground)==null||o.drawRect(this.xPositionOffset,this.yPositionOffset,this.currentProps.width,this.currentProps.height),(A=this.pBackground)==null||A.endFill()}},{key:"windowScrolled",value:function(){this.removeZoom(),this.scrollTimeout&&clearTimeout(this.scrollTimeout),this.scrollTimeout=setTimeout(()=>{this.addZoom()},hQt)}},{key:"setUpInitialScales",value:function(n=[0,1],C=[0,1],r=[-Number.MAX_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],o=[-Number.MAX_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],A=[0,Number.MAX_SAFE_INTEGER]){A[0]=A[0]===null?0:A[0],A[1]=A[1]===null?1/0:A[1];const s=n[1]-n[0],a=(C[0]+C[1])/2;if(C[0]=a-s/2,C[1]=a+s/2,n[0]===this.initialXDomain[0]&&n[1]===this.initialXDomain[1]&&C[0]===this.initialYDomain[0]&&C[1]===this.initialYDomain[1]&&r[0]===this.xDomainLimits[0]&&r[1]===this.xDomainLimits[1]&&o[0]===this.yDomainLimits[0]&&o[1]===this.yDomainLimits[1]&&A[0]===this.zoomLimits[0]&&A[1]===this.zoomLimits[1])return;this.initialXDomain=n,this.initialYDomain=C,this.xDomainLimits=r,this.yDomainLimits=o,this.zoomLimits=A,this.zoomTransform=Fi,this.prevZoomTransform=Fi,this.cumCenterYOffset=0,this.cumCenterXOffset=0,this.drawableToDomainX=qt().domain([this.currentProps.paddingLeft+this.currentProps.leftWidth,this.currentProps.paddingLeft+this.currentProps.leftWidth+this.currentProps.centerWidth]).range([n[0],n[1]]);let l,c;this.currentProps.centerWidth===0?(l=this.currentProps.paddingTop+this.currentProps.topHeight,c=this.currentProps.paddingTop+this.currentProps.topHeight+this.currentProps.centerHeight):(l=this.currentProps.paddingTop+this.currentProps.topHeight+this.currentProps.centerHeight/2-this.currentProps.centerWidth/2,c=this.currentProps.paddingTop+this.currentProps.topHeight+this.currentProps.centerHeight/2+this.currentProps.centerWidth/2),this.drawableToDomainY=qt().domain([l,c]).range([C[0],C[1]]),this.prevCenterX=this.currentProps.paddingLeft+this.currentProps.leftWidth+this.currentProps.centerWidth/2,this.prevCenterY=this.currentProps.paddingTop+this.currentProps.topHeight+this.currentProps.centerHeight/2}},{key:"updatablePropsToString",value:function(n){return JSON.stringify({positionedTracks:n.positionedTracks,initialXDomain:n.initialXDomain,initialYDomain:n.initialYDomain,width:n.width,height:n.height,paddingLeft:n.paddingLeft,paddingTop:n.paddingTop,leftWidth:n.leftWidth,topHeight:n.topHeight,dragging:n.dragging,viewOptions:n.viewOptions})}},{key:"draggingChanged",value:function(n){this.dragging=n,this.timedUpdatePositionAndDimensions()}},{key:"setUpScales",value:function(n=!1){const C=this.currentProps.paddingLeft+this.currentProps.leftWidth+this.currentProps.centerWidth/2,r=this.currentProps.paddingTop+this.currentProps.topHeight+this.currentProps.centerHeight/2;if(!this.drawableToDomainX||!this.drawableToDomainY)return;const o=(this.drawableToDomainX(C)-this.drawableToDomainX(this.prevCenterX))/this.zoomTransform.k,A=(this.drawableToDomainY(r)-this.drawableToDomainY(this.prevCenterY))/this.zoomTransform.k;this.cumCenterYOffset+=A,this.cumCenterXOffset+=o,this.prevCenterY=r,this.prevCenterX=C;const s=[this.drawableToDomainX(0)-this.cumCenterXOffset,this.drawableToDomainX(this.currentProps.width)-this.cumCenterXOffset],a=[this.drawableToDomainY(0)-this.cumCenterYOffset,this.drawableToDomainY(this.currentProps.height)-this.cumCenterYOffset];this._xScale=qt().domain(s).range([0,this.currentProps.width]),this._yScale=qt().domain(a).range([0,this.currentProps.height]);for(const l in this.trackDefObjects)this.trackDefObjects[l].trackObject.refScalesChanged(this.xScale,this.yScale);this.applyZoomTransform(n)}},{key:"getTrackDef",value:function(n){const C=Rr(this.trackDefObjects);for(const[,{trackDef:r,trackObject:o}]of C){if(o===n)return r.track;if(v1(r.track)){for(const A of r.track.contents)if(o.createdTracks[A.uid]===n)return A}}return null}},{key:"getTrackObject",value:function(n){const C=Rr(this.trackDefObjects);for(let r=0;ro.uid));this.addMetaTracks(n.filter(o=>!this.metaTracks[o.uid])),this.updateMetaTracks(n.filter(o=>this.metaTracks[o.uid])),this.removeMetaTracks(C.filter(o=>!r.has(o)))}},{key:"syncTrackObjects",value:function(n){this.prevTrackDefinitions=JSON.stringify(n);const C={};for(let l=0;l!r.has(l))),s=new Set([...r].filter(l=>!o.has(l))),a=new Set([...o].filter(l=>r.has(l)));this.updateExistingTrackDefs([...a].map(l=>C[l])),this.addNewTracks([...A].map(l=>C[l])),this.updateExistingTrackDefs([...A].map(l=>C[l])),this.removeTracks([...s])}},{key:"addMetaTracks",value:function(n){n.filter(C=>!this.metaTracks[C.uid]).forEach(C=>{this.metaTracks[C.uid]={trackDef:C,trackObject:this.createMetaTrack(C)}})}},{key:"addNewTracks",value:function(n){if(this.currentProps.pixiStage){for(let C=0;C{this.metaTracks[C].trackObject.remove(),this.metaTracks[C]=void 0,delete this.metaTracks[C]})}},{key:"removeTracks",value:function(n){for(let C=0;C{const p=Fi.translate(h,m).scale(c);this.zoomTransform=p,this.elementSelection&&this.emptyZoomBehavior.transform(this.elementSelection,p),f=this.applyZoomTransform(o)};if(A&&this.elementSelection){let p=this.elementSelection;this.activeTransitions+=1,document.hidden||(p=p.transition().duration(A)),p.call(this.zoomBehavior.transform,Fi.translate(h,m).scale(c)).on("end",()=>{b(),this.activeTransitions-=1})}else b();return f}},{key:"valueScaleMove",value:function(n){if(this.zoomStartPos){for(const C of this.getTracksAtPosition(...this.zoomStartPos))C.movedY(n);this.zoomStartTransform&&(this.zoomTransform=this.zoomStartTransform)}}},{key:"valueScaleZoom",value:function(n,C){if(!Bst(n.sourceEvent))return;const r=n.sourceEvent.deltaY,o=n.sourceEvent.deltaMode,s=((l,c)=>l*(c?120:1)/500)(r,o),a=Eg(n.sourceEvent,this.props.canvasElement);for(const l of this.getTracksAtPosition(...a)){const c=C==="1d-horizontal"?a[1]-l.position[1]:a[0]-l.position[0];l.zoomedY(c,2**s)}this.zoomStartTransform&&(this.zoomTransform=this.zoomStartTransform)}},{key:"zoomed",value:function(n){var C;let r=null;if(this.zoomStartPos){const A=this.getTracksAtPosition(...this.zoomStartPos);if(A.length){const s=A[0],a=this.getTrackDef(s);if(!a)return;(C=Lg[a.type])!=null&&C.orientation&&(r=Lg[a.type].orientation),s instanceof Dre&&(r="1d-vertical")}}if(r&&n.sourceEvent){if(n.shiftKey||this.valueScaleZooming){if(n.sourceEvent.deltaY!==void 0){this.valueScaleZoom(n,r);return}r==="1d-horizontal"?this.valueScaleMove(n.sourceEvent.movementY):r==="1d-vertical"&&this.valueScaleMove(n.sourceEvent.movementX)}r==="1d-horizontal"&&n.sourceEvent.movementY?this.valueScaleMove(n.sourceEvent.movementY):r==="1d-vertical"&&n.sourceEvent.movementX&&this.valueScaleMove(n.sourceEvent.movementX)}this.zoomTransform=this.currentProps.zoomable?n.transform:Fi,this.prevZoomTransform.k!==this.zoomTransform.k||(r==="1d-horizontal"?this.zoomTransform=Fi.translate(this.zoomTransform.x,this.prevZoomTransform.y).scale(this.zoomTransform.k):r==="1d-vertical"&&(this.zoomTransform=Fi.translate(this.prevZoomTransform.x,this.zoomTransform.y).scale(this.zoomTransform.k)),this.element&&(this.element.__zoom=this.zoomTransform)),this.applyZoomTransform(!0),this.prevZoomTransform=this.zoomTransform,this.props.pubSub.publish("app.zoom",n),n.sourceEvent&&(n.sourceEvent.stopPropagation(),n.sourceEvent.preventDefault())}},{key:"getTracksAtPosition",value:function(n,C){const r=[];let o=[];for(const A in this.trackDefObjects){const s=this.trackDefObjects[A].trackObject;s.childTracks?o=o.concat(s.childTracks):o.push(s)}for(const A of o){const s=A.position[0]<=n&&n<=A.position[0]+A.dimensions[0],a=A.position[1]<=C&&C<=A.position[1]+A.dimensions[1];s&&a&&r.push(A)}return r}},{key:"zoomStarted",value:function(n){this.zooming=!0,n&&n.sourceEvent&&(this.zoomStartPos=Eg(n.sourceEvent,this.props.canvasElement),n.sourceEvent.shiftKey&&(this.valueScaleZooming=!0)),this.zoomStartTransform=this.zoomTransform,this.props.pubSub.publish("app.zoomStart")}},{key:"zoomEnded",value:function(){this.zooming=!1,this.zoomStartPos=null,this.valueScaleZooming&&(this.valueScaleZooming=!1,this.element&&(this.element.__zoom=this.zoomStartTransform)),this.props.pubSub.publish("app.zoomEnd")}},{key:"applyZoomTransform",value:function(n=!0){const C=this.currentProps,r=C.paddingLeft+C.leftWidth,o=C.paddingTop+C.topHeight;if(!this.xScale||!this.yScale)return;this.zoomedXScale=this.zoomTransform.rescaleX(this.xScale),this.zoomedYScale=this.zoomTransform.rescaleY(this.yScale);const A=qt().domain([r,r+C.centerWidth].map(this.zoomedXScale.invert)).range([0,C.centerWidth]),s=qt().domain([o,o+C.centerHeight].map(this.zoomedYScale.invert)).range([0,C.centerHeight]);for(const a in this.trackDefObjects){const l=this.trackDefObjects[a].trackObject,c=this.trackDefObjects[a].trackDef;let u="unknown";if(Lg[c.track.type]&&(u=Lg[c.track.type].orientation),u==="whole"){const d=qt().domain([C.paddingLeft,C.width-C.paddingLeft].map(this.zoomedXScale.invert)).range([0,C.width-2*C.paddingLeft]),h=qt().domain([C.paddingTop,C.height-C.paddingTop].map(this.zoomedYScale.invert)).range([0,C.height-2*C.paddingTop]);l.zoomed(d,h);continue}if(this.trackDefObjects[a].trackDef.track.position==="gallery"){const d=qt().domain([C.paddingLeft+C.leftWidthNoGallery,C.paddingLeft+C.leftWidth+C.centerWidth+C.galleryDim].map(this.zoomedXScale.invert)).range([0,C.centerWidth+2*C.galleryDim]),h=qt().domain([C.paddingTop+C.topHeightNoGallery,C.paddingTop+C.topHeight+C.centerHeight+C.galleryDim].map(this.zoomedYScale.invert)).range([0,C.centerHeight-2*C.galleryDim]);l.zoomed(d.copy(),h.copy(),this.zoomTransform.k);continue}l.zoomed(A.copy(),s.copy(),this.zoomTransform.k,this.zoomTransform.x+this.xPositionOffset,this.zoomTransform.y+this.yPositionOffset,C.paddingLeft+C.leftWidth,C.paddingTop+C.topHeight)}return this.currentXScale=A,this.currentYScale=s,n&&this.currentProps.onScalesChanged(A,s),[A,s]}},{key:"createMetaTrack",value:function(n){switch(n.type){default:{const C=this.props.pluginTracks[n.type];if(C!=null&&C.isMetaTrack){const r={getTrackObject:this.getTrackObject.bind(this),onNewTilesLoaded:()=>{this.currentProps.onNewTilesLoaded(n.uid)},definition:n};try{return new C.track(this.availableForPlugins,r,n.options)}catch(o){console.error("Plugin meta track",n.type,"failed to instantiate.",o)}}return console.warn(`Unknown meta track of type: ${n.type}`),new noe(this.pStage,{name:"Unknown Track Type",type:n.type})}}}},{key:"createTrackObject",value:function(n){const C=this.createLocationAgnosticTrackObject(n);return(n.position==="left"||n.position==="right")&&Lg[n.type].orientation==="1d-horizontal"?new Dre(C):C}},{key:"createLocationAgnosticTrackObject",value:function(n){let C=n.data;C||(C={server:rN(n.server),tilesetUid:n.tilesetUid}),n.coordSystem&&(C.coordSystem=n.coordSystem);const r=dQt(C,this.props.pubSub,this.props.pluginDataFetchers,this.availableForPlugins);if(!this.pStage||!this.svgElement)throw new Error("No PIXI stage or svg element");const o={id:n.uid,trackUid:n.uid,trackType:n.type,viewUid:this.viewUid,pubSub:this.props.pubSub,scene:this.pStage,dataConfig:C,dataFetcher:r,getLockGroupExtrema:()=>this.currentProps.getLockGroupExtrema(n.uid),handleTilesetInfoReceived:A=>{this.currentProps.onTilesetInfoReceived(n.uid,A)},animate:()=>{this.currentProps.onNewTilesLoaded(n.uid)},svgElement:this.svgElement,isValueScaleLocked:()=>this.currentProps.isValueScaleLocked(n.uid),onValueScaleChanged:()=>{this.currentProps.onValueScaleChanged(n.uid)},onTrackOptionsChanged:A=>{this.currentProps.onTrackOptionsChanged(n.uid,A)},onMouseMoveZoom:this.props.onMouseMoveZoom,chromInfoPath:n.chromInfoPath,isShowGlobalMousePosition:()=>this.props.isShowGlobalMousePosition,getTheme:()=>this.props.theme};switch(n.y&&(o.yPosition=n.y),n.x&&(o.xPosition=n.x),n.projectionXDomain&&(o.projectionXDomain=n.projectionXDomain),n.projectionYDomain&&(o.projectionYDomain=n.projectionYDomain),n.type){case"left-axis":return new EVe(o,n.options);case"top-axis":return new FVe(o,n.options);case"heatmap":return new QS(o,n.options);case"multivec":case"vector-heatmap":case"horizontal-multivec":case"horizontal-vector-heatmap":case"vertical-multivec":case"vertical-vector-heatmap":return new yRe(o,n.options);case"1d-heatmap":case"horizontal-1d-heatmap":case"vertical-1d-heatmap":return new GRe(o,n.options);case"line":case"horizontal-line":case"vertical-line":return new L0(o,n.options);case"point":case"horizontal-point":case"vertical-point":return new bRe(o,n.options);case"bar":case"horizontal-bar":case"vertical-bar":return new vj(o,n.options);case"divergent-bar":case"horizontal-divergent-bar":case"vertical-divergent-bar":return new ZRe(o,n.options);case"horizontal-1d-tiles":return new kVe(o,n.options);case"vertical-1d-tiles":return new KVe(o,n.options);case"2d-tiles":return new TVe(o,n.options);case"stacked-interval":case"top-stacked-interval":case"left-stacked-interval":return new vRe(o,n.options);case"viewport-projection-center":return n.registerViewportChanged&&n.removeViewportChanged&&n.setDomainsCallback?(o.registerViewportChanged=n.registerViewportChanged,o.removeViewportChanged=n.removeViewportChanged,o.setDomainsCallback=n.setDomainsCallback,new DRe(o,n.options)):new Rp(o,{});case"viewport-projection-horizontal":return n.registerViewportChanged&&n.removeViewportChanged&&n.setDomainsCallback?(o.registerViewportChanged=n.registerViewportChanged,o.removeViewportChanged=n.removeViewportChanged,o.setDomainsCallback=n.setDomainsCallback,new xRe(o,n.options)):new Rp(o,{});case"viewport-projection-vertical":return n.registerViewportChanged&&n.removeViewportChanged&&n.setDomainsCallback?(o.registerViewportChanged=n.registerViewportChanged,o.removeViewportChanged=n.removeViewportChanged,o.setDomainsCallback=n.setDomainsCallback,new FRe(o,n.options)):new Rp(o,{});case"gene-annotations":case"horizontal-gene-annotations":case"vertical-gene-annotations":return new BRe(o,n.options);case"2d-rectangle-domains":case"arrowhead-domains":return new SRe(o,n.options);case"horizontal-1d-annotations":return new iP(o,n.options);case"vertical-1d-annotations":return new iP(o,n.options,!0);case"2d-annotations":return new VRe(o,n.options);case"linear-2d-rectangle-domains":case"horizontal-2d-rectangle-domains":case"vertical-2d-rectangle-domains":return new RRe(o,n.options);case"square-markers":return new WRe(o,n.options);case"combined":return o.tracks=n.contents,o.createTrackObject=this.createTrackObject.bind(this),new U7(o);case"2d-chromosome-labels":return new XRe(o,n.options);case"horizontal-chromosome-grid":return o.orientation="1d-horizontal",new EZ(o,n.options);case"vertical-chromosome-grid":return o.orientation="1d-vertical",new EZ(o,n.options);case"2d-chromosome-grid":return new EZ(o,n.options);case"chromosome-labels":case"horizontal-chromosome-labels":case"vertical-chromosome-labels":return new NRe(o,n.options);case"linear-heatmap":case"horizontal-heatmap":case"vertical-heatmap":return new kRe(o,n.options);case"2d-chromosome-annotations":return new HRe(o,n.options);case"1d-value-interval":case"horizontal-1d-value-interval":case"vertical-1d-value-interval":return new KRe(o,n.options);case"osm":case"osm-tiles":return new $S(o,n.options);case"osm-2d-tile-ids":return new g1e(o,n.options);case"mapbox":case"mapbox-tiles":return new I1e(o,n.options);case"raster-tiles":return new i1e(o,n.options);case"bedlike":case"vertical-bedlike":return new fRe(o,n.options);case"overlay-track":return new pRe(o,n.options);case"overlay-chromosome-grid-track":return o.isOverlay=!0,new EZ(o,n.options);case"horizontal-rule":return new _Re(o,n.options);case"vertical-rule":return new qRe(o,n.options);case"cross-rule":return o.x=n.x,o.y=n.y,new e1e(o,n.options);case"simple-svg":return new om(o,n.options);case"empty":{const A=n.options;return new lC(o,A)}default:{const A=this.props.pluginTracks[n.type];if(A&&!A.isMetaTrack){o.AVAILABLE_FOR_PLUGINS=this.availableForPlugins,o.baseEl=this.baseEl,o.definition=n,n.registerViewportChanged&&n.removeViewportChanged&&n.setDomainsCallback&&(o.registerViewportChanged=n.registerViewportChanged,o.removeViewportChanged=n.removeViewportChanged,o.setDomainsCallback=n.setDomainsCallback);try{return new A.track(this.availableForPlugins,o,n.options)}catch(s){console.error("Plugin track",n.type,"failed to instantiate.",s)}}return console.warn("Unknown track type:",n.type),new noe(o,{name:"Unknown Track Type",type:n.type})}}}},{key:"zoomToDataPos",value:function(n,C,r,o,A=3e3,s=null){const[a,l,c]=yi(this.xScale.copy().domain([n,C]),this.yScale.copy().domain([r,o])),u=s?s(this.xScale,this.yScale):[this.xScale,this.yScale];this.setCenter(a,l,c,!1,A,u[0],u[1])}},{key:"forwardContextMenu",value:function(n){this.props.disableTrackMenu||n.altKey||(n.preventDefault(),setTimeout(()=>{this.props.pubSub.publish("contextmenu",n)},0))}},{key:"addEventTracker",value:function(){!this.eventTracker||this.eventTracker===this.eventTrackerOld||(this.eventTrackerOld||(this.eventTrackerOld=this.eventTracker),this.eventTracker=this.eventTrackerOld,this.eventTracker.addEventListener("click",this.boundForwardEvent),this.eventTracker.addEventListener("contextmenu",this.boundForwardContextMenu),this.eventTracker.addEventListener("dblclick",this.boundForwardEvent),this.eventTracker.addEventListener("wheel",this.boundForwardEvent),this.eventTracker.addEventListener("dragstart",this.boundForwardEvent),this.eventTracker.addEventListener("selectstart",this.boundForwardEvent),this.eventTracker.addEventListener("mouseover",this.boundForwardEvent),this.eventTracker.addEventListener("mouseenter",this.boundForwardEvent),this.eventTracker.addEventListener("mousedown",this.boundForwardEvent),this.eventTracker.addEventListener("mouseup",this.boundForwardEvent),this.eventTracker.addEventListener("mouseout",this.boundForwardEvent),this.eventTracker.addEventListener("mouseleave",this.boundForwardEvent),this.eventTracker.addEventListener("touchstart",this.boundForwardEvent),this.eventTracker.addEventListener("touchend",this.boundForwardEvent),this.eventTracker.addEventListener("touchmove",this.boundForwardEvent),this.eventTracker.addEventListener("touchcancel",this.boundForwardEvent),this.eventTracker.addEventListener("pointerover",this.boundForwardEvent),this.eventTracker.addEventListener("pointerenter",this.boundForwardEvent),this.eventTracker.addEventListener("pointerdown",this.boundForwardEvent),this.eventTracker.addEventListener("pointerup",this.boundForwardEvent),this.eventTracker.addEventListener("pointercancel",this.boundForwardEvent),this.eventTracker.addEventListener("pointerout",this.boundForwardEvent),this.eventTracker.addEventListener("pointerleave",this.boundForwardEvent),window.addEventListener("scroll",this.boundScrollEvent))}},{key:"removeEventTracker",value:function(){this.eventTracker&&(this.eventTracker.removeEventListener("click",this.boundForwardEvent),this.eventTracker.removeEventListener("contextmenu",this.boundForwardContextMenu),this.eventTracker.removeEventListener("dblclick",this.boundForwardEvent),this.eventTracker.removeEventListener("wheel",this.boundForwardEvent),this.eventTracker.removeEventListener("dragstart",this.boundForwardEvent),this.eventTracker.removeEventListener("selectstart",this.boundForwardEvent),this.eventTracker.removeEventListener("mouseover",this.boundForwardEvent),this.eventTracker.removeEventListener("mouseenter",this.boundForwardEvent),this.eventTracker.removeEventListener("mousedown",this.boundForwardEvent),this.eventTracker.removeEventListener("mouseup",this.boundForwardEvent),this.eventTracker.removeEventListener("mouseout",this.boundForwardEvent),this.eventTracker.removeEventListener("mouseleave",this.boundForwardEvent),this.eventTracker.removeEventListener("touchstart",this.boundForwardEvent),this.eventTracker.removeEventListener("touchend",this.boundForwardEvent),this.eventTracker.removeEventListener("touchcancel",this.boundForwardEvent),this.eventTracker.removeEventListener("pointerover",this.boundForwardEvent),this.eventTracker.removeEventListener("pointerenter",this.boundForwardEvent),this.eventTracker.removeEventListener("pointerdown",this.boundForwardEvent),this.eventTracker.removeEventListener("pointerup",this.boundForwardEvent),this.eventTracker.removeEventListener("pointercancel",this.boundForwardEvent),this.eventTracker.removeEventListener("pointerout",this.boundForwardEvent),this.eventTracker.removeEventListener("pointerleave",this.boundForwardEvent),window.removeEventListener("scroll",this.boundScrollEvent))}},{key:"scrollEvent",value:function(){this.element&&(this.elementPos=this.element.getBoundingClientRect())}},{key:"forwardEvent",value:function(n){n.sourceUid=this.uid,n.forwarded=!0,this.props.pubSub.publish("app.event",n)}},{key:"onScrollHandler",value:function(n){this.scrollTop=n}},{key:"render",value:function(){return N.createElement("div",{ref:n=>{this.baseEl=n},className:Vg("track-renderer-div",Nx["track-renderer"]),style:{height:this.currentProps.height,width:this.currentProps.width}},N.createElement("div",{ref:n=>{this.element=n},className:Vg("track-renderer-element",Nx["track-renderer-element"])}),N.createElement("div",{ref:n=>{this.eventTracker=n},className:Vg("track-renderer-events",Nx["track-renderer-events"])},this.currentProps.children))}}]),I}(N.Component);V4.defaultProps={pluginDataFetchers:{},pluginTracks:{},canvasElement:null,centerHeight:0,centerWidth:0,children:[],galleryDim:0,height:0,initialXDomain:[],initialYDomain:[],isShowGlobalMousePosition:!1,isRangeSelection:!1,leftWidth:0,leftWidthNoGallery:0,paddingLeft:0,paddingTop:0,positionedTracks:[],topHeight:0,topHeightNoGallery:0,width:0,metaTracks:[]};V4.propTypes={canvasElement:L.object,centerHeight:L.number,centerWidth:L.number,children:L.array,disableTrackMenu:L.bool,galleryDim:L.number,height:L.number,initialXDomain:L.array,initialYDomain:L.array,isShowGlobalMousePosition:L.bool,isRangeSelection:L.bool,leftWidth:L.number,leftWidthNoGallery:L.number,paddingLeft:L.number,paddingTop:L.number,metaTracks:L.array,onMouseMoveZoom:L.func,onNewTilesLoaded:L.func.isRequired,onScalesChanged:L.func.isRequired,pixiRenderer:L.object.isRequired,pixiStage:L.object.isRequired,pluginDataFetchers:L.object,pluginTracks:L.object,positionedTracks:L.array,pubSub:L.object.isRequired,setCentersFunction:L.func,svgElement:L.object.isRequired,theme:L.symbol.isRequired,topHeight:L.number,topHeightNoGallery:L.number,viewOptions:L.object,width:L.number,xDomainLimits:L.array,yDomainLimits:L.array,valueScaleZoom:L.bool,zoomable:L.bool.isRequired,zoomDomain:L.array,uid:L.string,zoomLimits:L.array};const mQt=M0(im(V4));var eXe={exports:{}};/*! react-checkbox-tree - v1.8.0 | 2022 */(function(e,g){/*! For license information please see index.browser.js.LICENSE.txt */(function(I,i){e.exports=i(N)})(self,I=>(()=>{var i={4184:(o,A)=>{var s;(function(){var a={}.hasOwnProperty;function l(){for(var c=[],u=0;u{var a=s(852)(s(5639),"DataView");o.exports=a},1989:(o,A,s)=>{var a=s(1789),l=s(401),c=s(7667),u=s(1327),d=s(1866);function h(m){var f=-1,b=m==null?0:m.length;for(this.clear();++f{var a=s(7040),l=s(4125),c=s(2117),u=s(7518),d=s(4705);function h(m){var f=-1,b=m==null?0:m.length;for(this.clear();++f{var a=s(852)(s(5639),"Map");o.exports=a},3369:(o,A,s)=>{var a=s(4785),l=s(1285),c=s(6e3),u=s(9916),d=s(5265);function h(m){var f=-1,b=m==null?0:m.length;for(this.clear();++f{var a=s(852)(s(5639),"Promise");o.exports=a},8525:(o,A,s)=>{var a=s(852)(s(5639),"Set");o.exports=a},8668:(o,A,s)=>{var a=s(3369),l=s(619),c=s(2385);function u(d){var h=-1,m=d==null?0:d.length;for(this.__data__=new a;++h{var a=s(8407),l=s(7465),c=s(3779),u=s(7599),d=s(4758),h=s(4309);function m(f){var b=this.__data__=new a(f);this.size=b.size}m.prototype.clear=l,m.prototype.delete=c,m.prototype.get=u,m.prototype.has=d,m.prototype.set=h,o.exports=m},2705:(o,A,s)=>{var a=s(5639).Symbol;o.exports=a},1149:(o,A,s)=>{var a=s(5639).Uint8Array;o.exports=a},577:(o,A,s)=>{var a=s(852)(s(5639),"WeakMap");o.exports=a},4963:o=>{o.exports=function(A,s){for(var a=-1,l=A==null?0:A.length,c=0,u=[];++a{var a=s(2545),l=s(5694),c=s(1469),u=s(4144),d=s(5776),h=s(6719),m=Object.prototype.hasOwnProperty;o.exports=function(f,b){var p=c(f),y=!p&&l(f),Z=!p&&!y&&u(f),B=!p&&!y&&!Z&&h(f),G=p||y||Z||B,v=G?a(f.length,String):[],w=v.length;for(var V in f)!b&&!m.call(f,V)||G&&(V=="length"||Z&&(V=="offset"||V=="parent")||B&&(V=="buffer"||V=="byteLength"||V=="byteOffset")||d(V,w))||v.push(V);return v}},2488:o=>{o.exports=function(A,s){for(var a=-1,l=s.length,c=A.length;++a{o.exports=function(A,s){for(var a=-1,l=A==null?0:A.length;++a{var a=s(7813);o.exports=function(l,c){for(var u=l.length;u--;)if(a(l[u][0],c))return u;return-1}},8866:(o,A,s)=>{var a=s(2488),l=s(1469);o.exports=function(c,u,d){var h=u(c);return l(c)?h:a(h,d(c))}},4239:(o,A,s)=>{var a=s(2705),l=s(9607),c=s(2333),u=a?a.toStringTag:void 0;o.exports=function(d){return d==null?d===void 0?"[object Undefined]":"[object Null]":u&&u in Object(d)?l(d):c(d)}},9454:(o,A,s)=>{var a=s(4239),l=s(7005);o.exports=function(c){return l(c)&&a(c)=="[object Arguments]"}},939:(o,A,s)=>{var a=s(2492),l=s(7005);o.exports=function c(u,d,h,m,f){return u===d||(u==null||d==null||!l(u)&&!l(d)?u!=u&&d!=d:a(u,d,h,m,c,f))}},2492:(o,A,s)=>{var a=s(6384),l=s(7114),c=s(8351),u=s(6096),d=s(4160),h=s(1469),m=s(4144),f=s(6719),b="[object Arguments]",p="[object Array]",y="[object Object]",Z=Object.prototype.hasOwnProperty;o.exports=function(B,G,v,w,V,S){var X=h(B),W=h(G),R=X?p:d(B),H=W?p:d(G),Y=(R=R==b?y:R)==y,D=(H=H==b?y:H)==y,E=R==H;if(E&&m(B)){if(!m(G))return!1;X=!0,Y=!1}if(E&&!Y)return S||(S=new a),X||f(B)?l(B,G,v,w,V,S):c(B,G,R,v,w,V,S);if(!(1&v)){var O=Y&&Z.call(B,"__wrapped__"),J=D&&Z.call(G,"__wrapped__");if(O||J){var ee=O?B.value():B,q=J?G.value():G;return S||(S=new a),V(ee,q,v,w,S)}}return!!E&&(S||(S=new a),u(B,G,v,w,V,S))}},8458:(o,A,s)=>{var a=s(3560),l=s(5346),c=s(3218),u=s(346),d=/^\[object .+?Constructor\]$/,h=Function.prototype,m=Object.prototype,f=h.toString,b=m.hasOwnProperty,p=RegExp("^"+f.call(b).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");o.exports=function(y){return!(!c(y)||l(y))&&(a(y)?p:d).test(u(y))}},8749:(o,A,s)=>{var a=s(4239),l=s(1780),c=s(7005),u={};u["[object Float32Array]"]=u["[object Float64Array]"]=u["[object Int8Array]"]=u["[object Int16Array]"]=u["[object Int32Array]"]=u["[object Uint8Array]"]=u["[object Uint8ClampedArray]"]=u["[object Uint16Array]"]=u["[object Uint32Array]"]=!0,u["[object Arguments]"]=u["[object Array]"]=u["[object ArrayBuffer]"]=u["[object Boolean]"]=u["[object DataView]"]=u["[object Date]"]=u["[object Error]"]=u["[object Function]"]=u["[object Map]"]=u["[object Number]"]=u["[object Object]"]=u["[object RegExp]"]=u["[object Set]"]=u["[object String]"]=u["[object WeakMap]"]=!1,o.exports=function(d){return c(d)&&l(d.length)&&!!u[a(d)]}},280:(o,A,s)=>{var a=s(5726),l=s(6916),c=Object.prototype.hasOwnProperty;o.exports=function(u){if(!a(u))return l(u);var d=[];for(var h in Object(u))c.call(u,h)&&h!="constructor"&&d.push(h);return d}},2545:o=>{o.exports=function(A,s){for(var a=-1,l=Array(A);++a{o.exports=function(A){return function(s){return A(s)}}},4757:o=>{o.exports=function(A,s){return A.has(s)}},4429:(o,A,s)=>{var a=s(5639)["__core-js_shared__"];o.exports=a},7114:(o,A,s)=>{var a=s(8668),l=s(2908),c=s(4757);o.exports=function(u,d,h,m,f,b){var p=1&h,y=u.length,Z=d.length;if(y!=Z&&!(p&&Z>y))return!1;var B=b.get(u),G=b.get(d);if(B&&G)return B==d&&G==u;var v=-1,w=!0,V=2&h?new a:void 0;for(b.set(u,d),b.set(d,u);++v{var a=s(2705),l=s(1149),c=s(7813),u=s(7114),d=s(8776),h=s(1814),m=a?a.prototype:void 0,f=m?m.valueOf:void 0;o.exports=function(b,p,y,Z,B,G,v){switch(y){case"[object DataView]":if(b.byteLength!=p.byteLength||b.byteOffset!=p.byteOffset)return!1;b=b.buffer,p=p.buffer;case"[object ArrayBuffer]":return!(b.byteLength!=p.byteLength||!G(new l(b),new l(p)));case"[object Boolean]":case"[object Date]":case"[object Number]":return c(+b,+p);case"[object Error]":return b.name==p.name&&b.message==p.message;case"[object RegExp]":case"[object String]":return b==p+"";case"[object Map]":var w=d;case"[object Set]":var V=1&Z;if(w||(w=h),b.size!=p.size&&!V)return!1;var S=v.get(b);if(S)return S==p;Z|=2,v.set(b,p);var X=u(w(b),w(p),Z,B,G,v);return v.delete(b),X;case"[object Symbol]":if(f)return f.call(b)==f.call(p)}return!1}},6096:(o,A,s)=>{var a=s(8234),l=Object.prototype.hasOwnProperty;o.exports=function(c,u,d,h,m,f){var b=1&d,p=a(c),y=p.length;if(y!=a(u).length&&!b)return!1;for(var Z=y;Z--;){var B=p[Z];if(!(b?B in u:l.call(u,B)))return!1}var G=f.get(c),v=f.get(u);if(G&&v)return G==u&&v==c;var w=!0;f.set(c,u),f.set(u,c);for(var V=b;++Z{var a=typeof s.g=="object"&&s.g&&s.g.Object===Object&&s.g;o.exports=a},8234:(o,A,s)=>{var a=s(8866),l=s(9551),c=s(3674);o.exports=function(u){return a(u,c,l)}},5050:(o,A,s)=>{var a=s(7019);o.exports=function(l,c){var u=l.__data__;return a(c)?u[typeof c=="string"?"string":"hash"]:u.map}},852:(o,A,s)=>{var a=s(8458),l=s(7801);o.exports=function(c,u){var d=l(c,u);return a(d)?d:void 0}},9607:(o,A,s)=>{var a=s(2705),l=Object.prototype,c=l.hasOwnProperty,u=l.toString,d=a?a.toStringTag:void 0;o.exports=function(h){var m=c.call(h,d),f=h[d];try{h[d]=void 0;var b=!0}catch{}var p=u.call(h);return b&&(m?h[d]=f:delete h[d]),p}},9551:(o,A,s)=>{var a=s(4963),l=s(479),c=Object.prototype.propertyIsEnumerable,u=Object.getOwnPropertySymbols,d=u?function(h){return h==null?[]:(h=Object(h),a(u(h),function(m){return c.call(h,m)}))}:l;o.exports=d},4160:(o,A,s)=>{var a=s(8552),l=s(7071),c=s(3818),u=s(8525),d=s(577),h=s(4239),m=s(346),f="[object Map]",b="[object Promise]",p="[object Set]",y="[object WeakMap]",Z="[object DataView]",B=m(a),G=m(l),v=m(c),w=m(u),V=m(d),S=h;(a&&S(new a(new ArrayBuffer(1)))!=Z||l&&S(new l)!=f||c&&S(c.resolve())!=b||u&&S(new u)!=p||d&&S(new d)!=y)&&(S=function(X){var W=h(X),R=W=="[object Object]"?X.constructor:void 0,H=R?m(R):"";if(H)switch(H){case B:return Z;case G:return f;case v:return b;case w:return p;case V:return y}return W}),o.exports=S},7801:o=>{o.exports=function(A,s){return A==null?void 0:A[s]}},1789:(o,A,s)=>{var a=s(4536);o.exports=function(){this.__data__=a?a(null):{},this.size=0}},401:o=>{o.exports=function(A){var s=this.has(A)&&delete this.__data__[A];return this.size-=s?1:0,s}},7667:(o,A,s)=>{var a=s(4536),l=Object.prototype.hasOwnProperty;o.exports=function(c){var u=this.__data__;if(a){var d=u[c];return d==="__lodash_hash_undefined__"?void 0:d}return l.call(u,c)?u[c]:void 0}},1327:(o,A,s)=>{var a=s(4536),l=Object.prototype.hasOwnProperty;o.exports=function(c){var u=this.__data__;return a?u[c]!==void 0:l.call(u,c)}},1866:(o,A,s)=>{var a=s(4536);o.exports=function(l,c){var u=this.__data__;return this.size+=this.has(l)?0:1,u[l]=a&&c===void 0?"__lodash_hash_undefined__":c,this}},5776:o=>{var A=/^(?:0|[1-9]\d*)$/;o.exports=function(s,a){var l=typeof s;return!!(a=a??9007199254740991)&&(l=="number"||l!="symbol"&&A.test(s))&&s>-1&&s%1==0&&s{o.exports=function(A){var s=typeof A;return s=="string"||s=="number"||s=="symbol"||s=="boolean"?A!=="__proto__":A===null}},5346:(o,A,s)=>{var a,l=s(4429),c=(a=/[^.]+$/.exec(l&&l.keys&&l.keys.IE_PROTO||""))?"Symbol(src)_1."+a:"";o.exports=function(u){return!!c&&c in u}},5726:o=>{var A=Object.prototype;o.exports=function(s){var a=s&&s.constructor;return s===(typeof a=="function"&&a.prototype||A)}},7040:o=>{o.exports=function(){this.__data__=[],this.size=0}},4125:(o,A,s)=>{var a=s(8470),l=Array.prototype.splice;o.exports=function(c){var u=this.__data__,d=a(u,c);return!(d<0||(d==u.length-1?u.pop():l.call(u,d,1),--this.size,0))}},2117:(o,A,s)=>{var a=s(8470);o.exports=function(l){var c=this.__data__,u=a(c,l);return u<0?void 0:c[u][1]}},7518:(o,A,s)=>{var a=s(8470);o.exports=function(l){return a(this.__data__,l)>-1}},4705:(o,A,s)=>{var a=s(8470);o.exports=function(l,c){var u=this.__data__,d=a(u,l);return d<0?(++this.size,u.push([l,c])):u[d][1]=c,this}},4785:(o,A,s)=>{var a=s(1989),l=s(8407),c=s(7071);o.exports=function(){this.size=0,this.__data__={hash:new a,map:new(c||l),string:new a}}},1285:(o,A,s)=>{var a=s(5050);o.exports=function(l){var c=a(this,l).delete(l);return this.size-=c?1:0,c}},6e3:(o,A,s)=>{var a=s(5050);o.exports=function(l){return a(this,l).get(l)}},9916:(o,A,s)=>{var a=s(5050);o.exports=function(l){return a(this,l).has(l)}},5265:(o,A,s)=>{var a=s(5050);o.exports=function(l,c){var u=a(this,l),d=u.size;return u.set(l,c),this.size+=u.size==d?0:1,this}},8776:o=>{o.exports=function(A){var s=-1,a=Array(A.size);return A.forEach(function(l,c){a[++s]=[c,l]}),a}},4536:(o,A,s)=>{var a=s(852)(Object,"create");o.exports=a},6916:(o,A,s)=>{var a=s(5569)(Object.keys,Object);o.exports=a},1167:(o,A,s)=>{o=s.nmd(o);var a=s(1957),l=A&&!A.nodeType&&A,c=l&&o&&!o.nodeType&&o,u=c&&c.exports===l&&a.process,d=function(){try{return c&&c.require&&c.require("util").types||u&&u.binding&&u.binding("util")}catch{}}();o.exports=d},2333:o=>{var A=Object.prototype.toString;o.exports=function(s){return A.call(s)}},5569:o=>{o.exports=function(A,s){return function(a){return A(s(a))}}},5639:(o,A,s)=>{var a=s(1957),l=typeof self=="object"&&self&&self.Object===Object&&self,c=a||l||Function("return this")();o.exports=c},619:o=>{o.exports=function(A){return this.__data__.set(A,"__lodash_hash_undefined__"),this}},2385:o=>{o.exports=function(A){return this.__data__.has(A)}},1814:o=>{o.exports=function(A){var s=-1,a=Array(A.size);return A.forEach(function(l){a[++s]=l}),a}},7465:(o,A,s)=>{var a=s(8407);o.exports=function(){this.__data__=new a,this.size=0}},3779:o=>{o.exports=function(A){var s=this.__data__,a=s.delete(A);return this.size=s.size,a}},7599:o=>{o.exports=function(A){return this.__data__.get(A)}},4758:o=>{o.exports=function(A){return this.__data__.has(A)}},4309:(o,A,s)=>{var a=s(8407),l=s(7071),c=s(3369);o.exports=function(u,d){var h=this.__data__;if(h instanceof a){var m=h.__data__;if(!l||m.length<199)return m.push([u,d]),this.size=++h.size,this;h=this.__data__=new c(m)}return h.set(u,d),this.size=h.size,this}},346:o=>{var A=Function.prototype.toString;o.exports=function(s){if(s!=null){try{return A.call(s)}catch{}try{return s+""}catch{}}return""}},7813:o=>{o.exports=function(A,s){return A===s||A!=A&&s!=s}},5694:(o,A,s)=>{var a=s(9454),l=s(7005),c=Object.prototype,u=c.hasOwnProperty,d=c.propertyIsEnumerable,h=a(function(){return arguments}())?a:function(m){return l(m)&&u.call(m,"callee")&&!d.call(m,"callee")};o.exports=h},1469:o=>{var A=Array.isArray;o.exports=A},8612:(o,A,s)=>{var a=s(3560),l=s(1780);o.exports=function(c){return c!=null&&l(c.length)&&!a(c)}},4144:(o,A,s)=>{o=s.nmd(o);var a=s(5639),l=s(5062),c=A&&!A.nodeType&&A,u=c&&o&&!o.nodeType&&o,d=u&&u.exports===c?a.Buffer:void 0,h=(d?d.isBuffer:void 0)||l;o.exports=h},8446:(o,A,s)=>{var a=s(939);o.exports=function(l,c){return a(l,c)}},3560:(o,A,s)=>{var a=s(4239),l=s(3218);o.exports=function(c){if(!l(c))return!1;var u=a(c);return u=="[object Function]"||u=="[object GeneratorFunction]"||u=="[object AsyncFunction]"||u=="[object Proxy]"}},1780:o=>{o.exports=function(A){return typeof A=="number"&&A>-1&&A%1==0&&A<=9007199254740991}},3218:o=>{o.exports=function(A){var s=typeof A;return A!=null&&(s=="object"||s=="function")}},7005:o=>{o.exports=function(A){return A!=null&&typeof A=="object"}},6719:(o,A,s)=>{var a=s(8749),l=s(1717),c=s(1167),u=c&&c.isTypedArray,d=u?l(u):a;o.exports=d},3674:(o,A,s)=>{var a=s(4636),l=s(280),c=s(8612);o.exports=function(u){return c(u)?a(u):l(u)}},8306:(o,A,s)=>{var a=s(3369);function l(c,u){if(typeof c!="function"||u!=null&&typeof u!="function")throw new TypeError("Expected a function");var d=function(){var h=arguments,m=u?u.apply(this,h):h[0],f=d.cache;if(f.has(m))return f.get(m);var b=c.apply(this,h);return d.cache=f.set(m,b)||f,b};return d.cache=new(l.Cache||a),d}l.Cache=a,o.exports=l},479:o=>{o.exports=function(){return[]}},5062:o=>{o.exports=function(){return!1}},2703:(o,A,s)=>{var a=s(414);function l(){}function c(){}c.resetWarningCache=l,o.exports=function(){function u(m,f,b,p,y,Z){if(Z!==a){var B=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw B.name="Invariant Violation",B}}function d(){return u}u.isRequired=u;var h={array:u,bigint:u,bool:u,func:u,number:u,object:u,string:u,symbol:u,any:u,arrayOf:d,element:u,elementType:u,instanceOf:d,node:u,objectOf:d,oneOf:d,oneOfType:d,shape:d,exact:d,checkPropTypes:c,resetWarningCache:l};return h.PropTypes=h,h}},5697:(o,A,s)=>{o.exports=s(2703)()},414:o=>{o.exports="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"},9787:o=>{o.exports=I}},n={};function C(o){var A=n[o];if(A!==void 0)return A.exports;var s=n[o]={id:o,loaded:!1,exports:{}};return i[o](s,s.exports,C),s.loaded=!0,s.exports}C.n=o=>{var A=o&&o.__esModule?()=>o.default:()=>o;return C.d(A,{a:A}),A},C.d=(o,A)=>{for(var s in A)C.o(A,s)&&!C.o(o,s)&&Object.defineProperty(o,s,{enumerable:!0,get:A[s]})},C.g=function(){if(typeof globalThis=="object")return globalThis;try{return this||new Function("return this")()}catch{if(typeof window=="object")return window}}(),C.o=(o,A)=>Object.prototype.hasOwnProperty.call(o,A),C.r=o=>{typeof Symbol<"u"&&Symbol.toStringTag&&Object.defineProperty(o,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(o,"__esModule",{value:!0})},C.nmd=o=>(o.paths=[],o.children||(o.children=[]),o);var r={};return(()=>{C.r(r),C.d(r,{default:()=>ke,expandNodesToLevel:()=>fe});var o=C(4184),A=C.n(o),s=C(8446),a=C.n(s),l=C(8306),c=C.n(l);let u=(ue=21)=>crypto.getRandomValues(new Uint8Array(ue)).reduce((le,re)=>le+((re&=63)<36?re.toString(36):re<62?(re-26).toString(36).toUpperCase():re>62?"-":"_"),"");var d=C(5697),h=C.n(d),m=C(9787),f=C.n(m);function b(ue){return b=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(le){return typeof le}:function(le){return le&&typeof Symbol=="function"&&le.constructor===Symbol&&le!==Symbol.prototype?"symbol":typeof le},b(ue)}var p=["children","title"];function y(){return y=Object.assign?Object.assign.bind():function(ue){for(var le=1;le"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}(),function(){var Ee,He=w(oe);if(we){var xe=w(this).constructor;Ee=Reflect.construct(He,arguments,xe)}else Ee=He.apply(this,arguments);return v(this,Ee)});function Ye(){return Z(this,Ye),Ke.apply(this,arguments)}return le=Ye,(re=[{key:"render",value:function(){var Ee=this.props,He=Ee.children,xe=Ee.title,P=function(x,Q){if(x==null)return{};var ce,de,Je=function(lt,pt){if(lt==null)return{};var kt,ut,Vt={},Ft=Object.keys(lt);for(ut=0;ut=0||(Vt[kt]=lt[kt]);return Vt}(x,Q);if(Object.getOwnPropertySymbols){var Oe=Object.getOwnPropertySymbols(x);for(de=0;de=0||Object.prototype.propertyIsEnumerable.call(x,ce)&&(Je[ce]=x[ce])}return Je}(Ee,p);return f().createElement("button",y({"aria-label":xe,title:xe,type:"button"},P),He)}}])&&B(le.prototype,re),Object.defineProperty(le,"prototype",{writable:!1}),Ye}(f().PureComponent);V(S,"propTypes",{children:h().node.isRequired,title:h().string}),V(S,"defaultProps",{title:null});const X=S,W={ALL:"all",PARENT:"parent",LEAF:"leaf"};function R(ue){this.message=ue,this.stack=Error().stack}R.prototype=Object.create(Error.prototype),R.prototype.name="CheckboxTreeError";const H=R;function Y(ue,le){var re=Object.keys(ue);if(Object.getOwnPropertySymbols){var oe=Object.getOwnPropertySymbols(ue);le&&(oe=oe.filter(function(we){return Object.getOwnPropertyDescriptor(ue,we).enumerable})),re.push.apply(re,oe)}return re}function D(ue,le,re){return le in ue?Object.defineProperty(ue,le,{value:re,enumerable:!0,configurable:!0,writable:!0}):ue[le]=re,ue}function E(ue,le){if(!(ue instanceof le))throw new TypeError("Cannot call a class as a function")}function O(ue,le){for(var re=0;re1&&arguments[1]!==void 0?arguments[1]:{};E(this,ue),this.props=oe,this.flatNodes=we}var le,re;return le=ue,re=[{key:"setProps",value:function(oe){this.props=oe}},{key:"clone",value:function(){var oe=this,we={};return Object.keys(this.flatNodes).forEach(function(Ke){var Ye=oe.flatNodes[Ke];we[Ke]=function(Ee){for(var He=1;He1&&arguments[1]!==void 0?arguments[1]:{},Ye=arguments.length>2&&arguments[2]!==void 0?arguments[2]:0;if(Array.isArray(oe)&&oe.length!==0){var Ee=this.props,He=Ee.disabled,xe=Ee.noCascade;oe.forEach(function(P,x){var Q=we.nodeHasChildren(P);if(we.flatNodes[P.value]!==void 0)throw new H("Duplicate value '".concat(P.value,"' detected. All node values must be unique."));we.flatNodes[P.value]={label:P.label,value:P.value,children:P.children,parent:Ke,isChild:Ke.value!==void 0,isParent:Q,isLeaf:!Q,showCheckbox:P.showCheckbox===void 0||P.showCheckbox,disabled:we.getDisabledState(P,Ke,He,xe),treeDepth:Ye,index:x},we.flattenNodes(P.children,P,Ye+1)})}}},{key:"nodeHasChildren",value:function(oe){return Array.isArray(oe.children)}},{key:"getDisabledState",value:function(oe,we,Ke,Ye){return!!Ke||!(Ye||!we.disabled)||!!oe.disabled}},{key:"deserializeLists",value:function(oe){var we=this,Ke=["checked","expanded"];Object.keys(this.flatNodes).forEach(function(Ye){Ke.forEach(function(Ee){we.flatNodes[Ye][Ee]=!1})}),Ke.forEach(function(Ye){oe[Ye].forEach(function(Ee){we.flatNodes[Ee]!==void 0&&(we.flatNodes[Ee][Ye]=!0)})})}},{key:"serializeList",value:function(oe){var we=this,Ke=[];return Object.keys(this.flatNodes).forEach(function(Ye){we.flatNodes[Ye][oe]&&Ke.push(Ye)}),Ke}},{key:"expandAllNodes",value:function(oe){var we=this;return Object.keys(this.flatNodes).forEach(function(Ke){we.flatNodes[Ke].isParent&&(we.flatNodes[Ke].expanded=oe)}),this}},{key:"toggleChecked",value:function(oe,we,Ke,Ye){var Ee=this,He=!(arguments.length>4&&arguments[4]!==void 0)||arguments[4],xe=this.flatNodes[oe.value],P=[J.PARENT,J.ALL].indexOf(Ke)>-1,x=[J.LEAF,J.ALL].indexOf(Ke)>-1;if(xe.isLeaf||Ye){if(oe.disabled)return this;this.toggleNode(oe.value,"checked",we)}else(P||xe.children.length===0)&&this.toggleNode(oe.value,"checked",we),x&&xe.children.forEach(function(Q){Ee.toggleChecked(Q,we,Ke,Ye,!1)});return He&&!Ye&&xe.isChild&&P&&this.toggleParentStatus(xe.parent,Ke),this}},{key:"toggleParentStatus",value:function(oe,we){var Ke=this.flatNodes[oe.value];Ke.isChild?(we===J.ALL&&this.toggleNode(oe.value,"checked",this.isEveryChildChecked(Ke)),this.toggleParentStatus(Ke.parent,we)):this.toggleNode(oe.value,"checked",this.isEveryChildChecked(Ke))}},{key:"isEveryChildChecked",value:function(oe){var we=this;return oe.children.every(function(Ke){return we.getNode(Ke.value).checked})}},{key:"toggleNode",value:function(oe,we,Ke){return this.flatNodes[oe][we]=Ke,this}}],re&&O(le.prototype,re),Object.defineProperty(le,"prototype",{writable:!1}),ue}();function q(ue){return q=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(le){return typeof le}:function(le){return le&&typeof Symbol=="function"&&le.constructor===Symbol&&le!==Symbol.prototype?"symbol":typeof le},q(ue)}function $(){return $=Object.assign?Object.assign.bind():function(ue){for(var le=1;le"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}(),function(){var Ee,He=Ce(oe);if(we){var xe=Ce(this).constructor;Ee=Reflect.construct(He,arguments,xe)}else Ee=He.apply(this,arguments);return me(this,Ee)});function Ye(){return te(this,Ye),Ke.apply(this,arguments)}return le=Ye,re=[{key:"componentDidMount",value:function(){this.updateDeterminateProperty()}},{key:"componentDidUpdate",value:function(){this.updateDeterminateProperty()}},{key:"updateDeterminateProperty",value:function(){var Ee=this.props.indeterminate;this.checkbox.indeterminate=Ee}},{key:"render",value:function(){var Ee=this,He=function(xe){for(var P=1;P"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}(),function(){var Ee,He=ot(oe);if(we){var xe=ot(this).constructor;Ee=Reflect.construct(He,arguments,xe)}else Ee=He.apply(this,arguments);return Ue(this,Ee)});function Ye(Ee){var He;return function(xe,P){if(!(xe instanceof P))throw new TypeError("Cannot call a class as a function")}(this,Ye),(He=Ke.call(this,Ee)).onCheck=He.onCheck.bind(_e(He)),He.onCheckboxKeyPress=He.onCheckboxKeyPress.bind(_e(He)),He.onCheckboxKeyUp=He.onCheckboxKeyUp.bind(_e(He)),He.onClick=He.onClick.bind(_e(He)),He.onExpand=He.onExpand.bind(_e(He)),He}return le=Ye,(re=[{key:"onCheck",value:function(){var Ee=this.props,He=Ee.value;(0,Ee.onCheck)({value:He,checked:this.getCheckState({toggle:!0})})}},{key:"onCheckboxKeyPress",value:function(Ee){Ee.which===32&&Ee.preventDefault()}},{key:"onCheckboxKeyUp",value:function(Ee){var He=Ee.keyCode;[13,32].includes(He)&&this.onCheck()}},{key:"onClick",value:function(){var Ee=this.props,He=Ee.expandOnClick,xe=Ee.isParent,P=Ee.value,x=Ee.onClick;xe&&He&&this.onExpand(),x({value:P,checked:this.getCheckState({toggle:!1})})}},{key:"onExpand",value:function(){var Ee=this.props,He=Ee.expanded,xe=Ee.value;(0,Ee.onExpand)({value:xe,expanded:!He})}},{key:"getCheckState",value:function(Ee){var He=Ee.toggle,xe=this.props,P=xe.checked,x=xe.optimisticToggle;return!(P!==0||!He)||P===1&&!He||P===2&&x}},{key:"renderCollapseButton",value:function(){var Ee=this.props,He=Ee.expandDisabled,xe=Ee.isLeaf,P=Ee.lang;return xe?f().createElement("span",{className:"rct-collapse"},f().createElement("span",{className:"rct-icon"})):f().createElement(X,{className:"rct-collapse rct-collapse-btn",disabled:He,title:P.toggle,onClick:this.onExpand},this.renderCollapseIcon())}},{key:"renderCollapseIcon",value:function(){var Ee=this.props,He=Ee.expanded,xe=Ee.icons,P=xe.expandClose,x=xe.expandOpen;return He?x:P}},{key:"renderCheckboxIcon",value:function(){var Ee=this.props,He=Ee.checked,xe=Ee.icons,P=xe.uncheck,x=xe.check,Q=xe.halfCheck;return He===0?P:He===1?x:Q}},{key:"renderNodeIcon",value:function(){var Ee=this.props,He=Ee.expanded,xe=Ee.icon,P=Ee.icons,x=P.leaf,Q=P.parentClose,ce=P.parentOpen,de=Ee.isLeaf;return xe!==null?xe:de?x:He?ce:Q}},{key:"renderBareLabel",value:function(Ee){var He=this.props,xe=He.onClick,P=He.title,x=xe!==null;return f().createElement("span",{className:"rct-bare-label",title:P},x?f().createElement("span",{className:"rct-node-clickable",onClick:this.onClick,onKeyPress:this.onClick,role:"button",tabIndex:0},Ee):Ee)}},{key:"renderCheckboxLabel",value:function(Ee){var He=this.props,xe=He.checked,P=He.disabled,x=He.title,Q=He.treeId,ce=He.value,de=He.onClick!==null,Je="".concat(Q,"-").concat(String(ce).split(" ").join("_")),Oe=[f().createElement("label",{key:0,htmlFor:Je,title:x},f().createElement(Be,{checked:xe===1,disabled:P,id:Je,indeterminate:xe===2,onClick:this.onCheck,onChange:function(){}}),f().createElement("span",{"aria-checked":xe===1,"aria-disabled":P,className:"rct-checkbox",role:"checkbox",tabIndex:0,onKeyPress:this.onCheckboxKeyPress,onKeyUp:this.onCheckboxKeyUp},this.renderCheckboxIcon()),de?null:Ee)];return de&&Oe.push(f().createElement("span",{key:1,className:"rct-node-clickable",onClick:this.onClick,onKeyPress:this.onClick,role:"link",tabIndex:0},Ee)),Oe}},{key:"renderLabel",value:function(){var Ee=this.props,He=Ee.label,xe=Ee.showCheckbox,P=[Ee.showNodeIcon?f().createElement("span",{key:0,className:"rct-node-icon"},this.renderNodeIcon()):null,f().createElement("span",{key:1,className:"rct-title"},He)];return xe?this.renderCheckboxLabel(P):this.renderBareLabel(P)}},{key:"renderChildren",value:function(){return this.props.expanded?this.props.children:null}},{key:"render",value:function(){var Ee=this.props,He=Ee.className,xe=Ee.disabled,P=Ee.expanded,x=Ee.isLeaf,Q=A()({"rct-node":!0,"rct-node-leaf":x,"rct-node-parent":!x,"rct-node-expanded":!x&&P,"rct-node-collapsed":!x&&!P,"rct-disabled":xe},He);return f().createElement("li",{className:Q},f().createElement("span",{className:"rct-text"},this.renderCollapseButton(),this.renderLabel()),this.renderChildren())}}])&&ze(le.prototype,re),Object.defineProperty(le,"prototype",{writable:!1}),Ye}(f().PureComponent);Zt(nt,"propTypes",{checked:h().number.isRequired,disabled:h().bool.isRequired,expandDisabled:h().bool.isRequired,expanded:h().bool.isRequired,icons:Ne.isRequired,isLeaf:h().bool.isRequired,isParent:h().bool.isRequired,label:h().node.isRequired,lang:Se.isRequired,optimisticToggle:h().bool.isRequired,showNodeIcon:h().bool.isRequired,treeId:h().string.isRequired,value:h().oneOfType([h().string,h().number]).isRequired,onCheck:h().func.isRequired,onExpand:h().func.isRequired,children:h().node,className:h().string,expandOnClick:h().bool,icon:h().node,showCheckbox:h().bool,title:h().string,onClick:h().func}),Zt(nt,"defaultProps",{children:null,className:null,expandOnClick:!1,icon:null,showCheckbox:!0,title:null,onClick:function(){}});const Te=nt,se=h().oneOfType([h().arrayOf(h().string),h().arrayOf(h().number)]);function ye(ue,le){var re=Object.keys(ue);if(Object.getOwnPropertySymbols){var oe=Object.getOwnPropertySymbols(ue);le&&(oe=oe.filter(function(we){return Object.getOwnPropertyDescriptor(ue,we).enumerable})),re.push.apply(re,oe)}return re}function Xe(ue){for(var le=1;le"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}(),function(){var He,xe=ct(we);if(Ke){var P=ct(this).constructor;He=Reflect.construct(xe,arguments,P)}else He=xe.apply(this,arguments);return mt(this,He)});function Ee(He){var xe;(function(x,Q){if(!(x instanceof Q))throw new TypeError("Cannot call a class as a function")})(this,Ee),xe=Ye.call(this,He);var P=new ee(He);return P.flattenNodes(He.nodes),P.deserializeLists({checked:He.checked,expanded:He.expanded}),xe.state={id:He.id||"rct-".concat(u()),model:P,prevProps:He},xe.onCheck=xe.onCheck.bind(vt(xe)),xe.onExpand=xe.onExpand.bind(vt(xe)),xe.onNodeClick=xe.onNodeClick.bind(vt(xe)),xe.onExpandAll=xe.onExpandAll.bind(vt(xe)),xe.onCollapseAll=xe.onCollapseAll.bind(vt(xe)),xe.combineMemorized=c()(function(x,Q){return Ve(Ve({},x),Q)}).bind(vt(xe)),xe}return le=Ee,re=[{key:"onCheck",value:function(He){var xe=this.props,P=xe.checkModel,x=xe.noCascade,Q=xe.onCheck,ce=this.state.model.clone(),de=ce.getNode(He.value);ce.toggleChecked(He,He.checked,P,x),Q(ce.serializeList("checked"),Ve(Ve({},de),He))}},{key:"onExpand",value:function(He){var xe=this.props.onExpand,P=this.state.model.clone(),x=P.getNode(He.value);P.toggleNode(He.value,"expanded",He.expanded),xe(P.serializeList("expanded"),Ve(Ve({},x),He))}},{key:"onNodeClick",value:function(He){(0,this.props.onClick)(Ve(Ve({},this.state.model.getNode(He.value)),He))}},{key:"onExpandAll",value:function(){this.expandAllNodes()}},{key:"onCollapseAll",value:function(){this.expandAllNodes(!1)}},{key:"expandAllNodes",value:function(){var He=!(arguments.length>0&&arguments[0]!==void 0)||arguments[0],xe=this.props.onExpand;xe(this.state.model.clone().expandAllNodes(He).serializeList("expanded"))}},{key:"determineShallowCheckState",value:function(He,xe){var P=this.state.model.getNode(He.value);return P.isLeaf||xe||He.children.length===0?P.checked?1:0:this.isEveryChildChecked(He)?1:this.isSomeChildChecked(He)?2:0}},{key:"isEveryChildChecked",value:function(He){var xe=this;return He.children.every(function(P){return xe.state.model.getNode(P.value).checkState===1})}},{key:"isSomeChildChecked",value:function(He){var xe=this;return He.children.some(function(P){return xe.state.model.getNode(P.value).checkState>0})}},{key:"renderTreeNodes",value:function(He){var xe=this,P=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},x=this.props,Q=x.expandDisabled,ce=x.expandOnClick,de=x.icons,Je=x.lang,Oe=x.noCascade,lt=x.onClick,pt=x.onlyLeafCheckboxes,kt=x.optimisticToggle,ut=x.showNodeTitle,Vt=x.showNodeIcon,Ft=this.state,At=Ft.id,Xt=Ft.model,Pt=Ee.defaultProps.icons,Dt=He.map(function(Sg){var Qg=Sg.value,et=Xt.getNode(Sg.value),bt=et.isParent?xe.renderTreeNodes(Sg.children,Sg):null;et.checkState=xe.determineShallowCheckState(Sg,Oe);var Lt=pt?et.isLeaf:et.showCheckbox;return!P.value||Xt.getNode(P.value).expanded?f().createElement(Te,{key:Qg,checked:et.checkState,className:Sg.className,disabled:et.disabled,expandDisabled:Q,expandOnClick:ce,expanded:et.expanded,icon:Sg.icon,icons:xe.combineMemorized(Pt,de),label:Sg.label,lang:Je,optimisticToggle:kt,isLeaf:et.isLeaf,isParent:et.isParent,showCheckbox:Lt,showNodeIcon:Vt,title:ut?Sg.title||Sg.label:Sg.title,treeId:At,value:Sg.value,onCheck:xe.onCheck,onClick:lt&&xe.onNodeClick,onExpand:xe.onExpand},bt):null});return f().createElement("ol",null,Dt)}},{key:"renderExpandAll",value:function(){var He=this.props,xe=He.icons,P=xe.expandAll,x=xe.collapseAll,Q=He.lang;return He.showExpandAll?f().createElement("div",{className:"rct-options"},f().createElement(X,{className:"rct-option rct-option-expand-all",title:Q.expandAll,onClick:this.onExpandAll},P),f().createElement(X,{className:"rct-option rct-option-collapse-all",title:Q.collapseAll,onClick:this.onCollapseAll},x)):null}},{key:"renderHiddenInput",value:function(){var He=this.props,xe=He.name,P=He.nameAsArray;return xe===void 0?null:P?this.renderArrayHiddenInput():this.renderJoinedHiddenInput()}},{key:"renderArrayHiddenInput",value:function(){var He=this.props,xe=He.checked,P=He.name;return xe.map(function(x){var Q="".concat(P,"[]");return f().createElement("input",{key:x,name:Q,type:"hidden",value:x})})}},{key:"renderJoinedHiddenInput",value:function(){var He=this.props,xe=He.checked,P=He.name,x=xe.join(",");return f().createElement("input",{name:P,type:"hidden",value:x})}},{key:"render",value:function(){var He,xe=this.props,P=xe.direction,x=xe.disabled,Q=xe.iconsClass,ce=xe.nodes,de=xe.nativeCheckboxes,Je=this.state.id,Oe=this.renderTreeNodes(ce),lt=A()((Ht(He={"react-checkbox-tree":!0,"rct-disabled":x},"rct-icons-".concat(Q),!0),Ht(He,"rct-native-display",de),Ht(He,"rct-direction-rtl",P==="rtl"),He));return f().createElement("div",{className:lt,id:Je},this.renderExpandAll(),this.renderHiddenInput(),Oe)}}],oe=[{key:"getDerivedStateFromProps",value:function(He,xe){var P=xe.model,x=xe.prevProps,Q=He.disabled,ce=He.id,de=He.nodes,Je=Ve(Ve({},xe),{},{prevProps:He});return P.setProps(He),a()(x.nodes,de)&&x.disabled===Q||(P.reset(),P.flattenNodes(de)),ce!==null&&(Je=Ve(Ve({},Je),{},{id:ce})),P.deserializeLists({checked:He.checked,expanded:He.expanded}),Je}}],re&&De(le.prototype,re),oe&&De(le,oe),Object.defineProperty(le,"prototype",{writable:!1}),Ee}(f().Component);function F(ue){return function(le){if(Array.isArray(le))return _(le)}(ue)||function(le){if(typeof Symbol<"u"&&le[Symbol.iterator]!=null||le["@@iterator"]!=null)return Array.from(le)}(ue)||function(le,re){if(le){if(typeof le=="string")return _(le,re);var oe=Object.prototype.toString.call(le).slice(8,-1);return oe==="Object"&&le.constructor&&(oe=le.constructor.name),oe==="Map"||oe==="Set"?Array.from(le):oe==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(oe)?_(le,re):void 0}}(ue)||function(){throw new TypeError(`Invalid attempt to spread non-iterable instance. +In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}()}function _(ue,le){(le==null||le>ue.length)&&(le=ue.length);for(var re=0,oe=new Array(le);re2&&arguments[2]!==void 0?arguments[2]:0;if(re>le)return[];var oe=[];return ue.forEach(function(we){we.children&&(oe=[].concat(F(oe),[we.value],F(fe(we.children,le,re+1))))}),oe}Ht(ne,"propTypes",{nodes:h().arrayOf(k).isRequired,checkModel:h().oneOf([W.LEAF,W.ALL]),checked:se,direction:h().string,disabled:h().bool,expandDisabled:h().bool,expandOnClick:h().bool,expanded:se,icons:Ne,iconsClass:h().string,id:h().string,lang:Se,name:h().string,nameAsArray:h().bool,nativeCheckboxes:h().bool,noCascade:h().bool,onlyLeafCheckboxes:h().bool,optimisticToggle:h().bool,showExpandAll:h().bool,showNodeIcon:h().bool,showNodeTitle:h().bool,onCheck:h().func,onClick:h().func,onExpand:h().func}),Ht(ne,"defaultProps",{checkModel:W.LEAF,checked:[],direction:"ltr",disabled:!1,expandDisabled:!1,expandOnClick:!1,expanded:[],icons:{check:f().createElement("span",{className:"rct-icon rct-icon-check"}),uncheck:f().createElement("span",{className:"rct-icon rct-icon-uncheck"}),halfCheck:f().createElement("span",{className:"rct-icon rct-icon-half-check"}),expandClose:f().createElement("span",{className:"rct-icon rct-icon-expand-close"}),expandOpen:f().createElement("span",{className:"rct-icon rct-icon-expand-open"}),expandAll:f().createElement("span",{className:"rct-icon rct-icon-expand-all"}),collapseAll:f().createElement("span",{className:"rct-icon rct-icon-collapse-all"}),parentClose:f().createElement("span",{className:"rct-icon rct-icon-parent-close"}),parentOpen:f().createElement("span",{className:"rct-icon rct-icon-parent-open"}),leaf:f().createElement("span",{className:"rct-icon rct-icon-leaf"})},iconsClass:"fa4",id:null,lang:{collapseAll:"Collapse all",expandAll:"Expand all",toggle:"Toggle"},name:void 0,nameAsArray:!1,nativeCheckboxes:!1,noCascade:!1,onlyLeafCheckboxes:!1,optimisticToggle:!0,showExpandAll:!1,showNodeIcon:!0,showNodeTitle:!1,onCheck:function(){},onClick:null,onExpand:function(){}});const ke=ne})(),r})())})(eXe);var fQt=eXe.exports;const pQt=DC(fQt);function bQt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function sae(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function R2(e){return R2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},R2(e)}let tXe=function(e){vQt(I,e);var g=BQt(I);function I(i){var n;bQt(this,I),n=g.call(this,i),n.localTracks=qd.filter(A=>A.local&&!A.hidden).map(A=>{const s={...A};return s.datatype=A.datatype[0],s}),n.augmentedTracksInfo=qd,window.higlassTracksByType&&Object.keys(window.higlassTracksByType).forEach(A=>{n.augmentedTracksInfo.push(window.higlassTracksByType[A].config)}),i.datatype?n.localTracks=n.localTracks.filter(A=>A.datatype[0]===i.datatype):n.localTracks=n.localTracks.filter(A=>A.orientation===n.props.orientation),n.localTracks.forEach(A=>{A.uuid=Ag.nice()});const C=n.prepareNewEntries("",n.localTracks,{}),r=Object.keys(C),o=r.length?[r[0]]:null;return n.mounted=!1,n.state={selectedUuid:o,options:C,filter:"",checked:[],expanded:[]},n.requestTilesetLists(),n}return yQt(I,[{key:"componentDidMount",value:function(){this.mounted=!0,this.requestTilesetLists(),this.searchBox.focus()}},{key:"componentWillUnmount",value:function(){this.mounted=!1}},{key:"prepareNewEntries",value:function(n,C,r){const o=r;return C.map(s=>({...s,server:n,tilesetUid:s.uuid,serverUidKey:this.serverUidKey(n,s.uuid),datatype:s.datatype,name:s.name,uid:Ag.nice()})).forEach(s=>{o[s.serverUidKey]=s}),o}},{key:"serverUidKey",value:function(n,C){return`${n}/${C}`}},{key:"requestTilesetLists",value:function(){let n=null;if(this.props.datatype?n=`dt=${this.props.datatype}`:n=[...new Set([].concat(...this.augmentedTracksInfo.filter(r=>r.datatype).filter(r=>r.orientation===this.props.orientation||this.props.orientation==="1d-vertical"&&r.orientation==="1d-horizontal").map(r=>r.datatype)))].map(r=>`dt=${r}`).join("&"),!this.props.trackSourceServers){console.warn("No track source servers specified in the viewconf");return}this.props.trackSourceServers.forEach(C=>{Gt.json(`${C}/tilesets/?limit=10000&${n}`,(r,o)=>{if(r)console.error("ERROR:",r);else{const A=this.prepareNewEntries(C,o.results,this.state.options),s=Object.keys(A);let{selectedUuid:a}=this.state;if(!a){a=s.length?[s[0]]:null;const l=this.state.options[a[0]];this.props.selectedTilesetChanged([l])}this.mounted&&this.setState({selectedUuid:a,options:A})}},this.props.pubSub)})}},{key:"handleOptionDoubleClick",value:function(n){const C=this.state.options[n.target.value];this.props.onDoubleClick(C)}},{key:"handleSelectedOptions",value:function(n){const C=[],r=[];for(let o=0;os.label.toLowerCase().localeCompare(a.label.toLowerCase(),"en")),o.push(r[A]));return o.sort((A,s)=>A.label.toLowerCase().localeCompare(s.label.toLowerCase(),"en")),o}},{key:"handleChecked",value:function(n){this.handleSelectedOptions(n),this.setState({checked:n})}},{key:"handleExpanded",value:function(n){this.setState({expanded:n})}},{key:"render",value:function(){const n=[];for(const s in this.state.options)n.push(this.state.options[s]);const C=this.partitionByGroup(this.state.options,this.state.filter),r={width:15,height:15,top:2,right:2,position:"relative"},o=JSON.parse(JSON.stringify(r));o.opacity=.5;const A=N.createElement("form",{onSubmit:s=>{s.preventDefault()}},N.createElement("div",{className:"tileset-finder-search-bar"},N.createElement("span",{className:"tileset-finder-label"},"Select tileset:"),N.createElement("input",{ref:s=>{this.searchBox=s},className:"tileset-finder-search-box",onChange:this.handleSearchChange.bind(this),placeholder:"Search Term",type:"text"})),N.createElement("div",{className:"tileset-finder-checkbox-tree"},N.createElement(pQt,{checked:this.state.checked,expanded:this.state.expanded,icons:{uncheck:N.createElement("svg",{style:r},N.createElement("use",{xlinkHref:"#square_o"})),check:N.createElement("svg",{style:r},N.createElement("use",{xlinkHref:"#check_square_o"})),halfCheck:N.createElement("svg",{style:o},N.createElement("use",{xlinkHref:"#check_square_o"})),leaf:N.createElement("svg",{style:r},N.createElement("use",{xlinkHref:"#file_o"})),expandClose:N.createElement("svg",{style:r},N.createElement("use",{xlinkHref:"#chevron_right"})),expandOpen:N.createElement("svg",{style:r},N.createElement("use",{xlinkHref:"#chevron_down"})),parentClose:N.createElement("svg",{style:r},N.createElement("use",{xlinkHref:"#folder_o"})),parentOpen:N.createElement("svg",{style:r},N.createElement("use",{xlinkHref:"#folder_open_o"}))},nodes:C,onCheck:this.handleChecked.bind(this),onExpand:this.handleExpanded.bind(this)})));return N.createElement("div",null,A)}}]),I}(N.Component);tXe.propTypes={datatype:L.string,orientation:L.string,onDoubleClick:L.func,pubSub:L.object.isRequired,selectedTilesetChanged:L.func,trackSourceServers:L.array};const RQt=M0(tXe);function WQt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function lae(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function W2(e){return W2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},W2(e)}let gXe=function(e){NQt(I,e);var g=kQt(I);function I(i){var n;return WQt(this,I),n=g.call(this,i),n.DATATYPE_TO_TRACK_TYPE=x7(n.props.orientation),n.AVAILABLE_TRACK_TYPES=qX(n.props.datatypes,n.props.orientation),n.state={selectedPlotType:n.AVAILABLE_TRACK_TYPES[0]},n}return XQt(I,[{key:"UNSAFE_componentWillReceiveProps",value:function(n){if(this.AVAILABLE_TRACK_TYPES=qX(n.datatypes,this.props.orientation),!!this.AVAILABLE_TRACK_TYPES&&n.allTracksSameDatatype&&this.AVAILABLE_TRACK_TYPES.length>0&&!this.AVAILABLE_TRACK_TYPES.includes(this.state.selectedPlotType)){const C=M7(n.datatypes[0][0],this.props.position,this.AVAILABLE_TRACK_TYPES);this.handlePlotTypeSelected(C)}}},{key:"handlePlotTypeSelected",value:function(n){this.setState({selectedPlotType:n}),this.props.onPlotTypeSelected(n.type)}},{key:"render",value:function(){let n="No plot types available for track";const C={};return qd.forEach(r=>{C[r.type]=r}),this.AVAILABLE_TRACK_TYPES&&(n=this.AVAILABLE_TRACK_TYPES.sort((r,o)=>r.type{const o=C[r.type].thumbnail,A=this.state.selectedPlotType.type===r.type?"plot-type-item plot-type-selected":"plot-type-item",s=C[r.type].thumbnail?N.createElement("div",{className:"track-thumbnail",dangerouslySetInnerHTML:{__html:o.outerHTML}}):N.createElement("div",{className:"track-thumbnail"},N.createElement("svg",{height:20,width:30}));return N.createElement("li",{key:r.type,className:A,onClick:a=>{this.setState({selectedPlotType:r}),this.props.onPlotTypeSelected(r.type)},style:{listStyle:"none",paddingLeft:5,paddingBottom:0}},s,N.createElement("span",{style:{verticalAlign:"middle"}},r.type))})),N.createElement("div",null,n.length>0&&this.props.allTracksSameDatatype&&N.createElement("div",{className:"plot-type-container"},n),!this.props.allTracksSameDatatype&&N.createElement("div",{className:"plot-type-container-empty"},"Datasets with multiple datatypes chosen. They will be added with their default track types."))}}]),I}(N.Component);gXe.propTypes={allTracksSameDatatype:L.bool,datatypes:L.array,orientation:L.string,onPlotTypeSelected:L.func,position:L.string};function xQt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function cae(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function X2(e){return X2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},X2(e)}let H2=function(e){zQt(I,e);var g=PQt(I);function I(i){var n;return xQt(this,I),n=g.call(this,i),n.options={},n.state={selectedTilesets:[{datatype:"none"}],allTracksSameDatatype:!0},n.handleSubmitBound=n.handleSubmit.bind(rW(n)),n.handleTilesetPickerDoubleClickBound=n.handleTilesetPickerDoubleClick.bind(rW(n)),n.selectedTilesetsChangedBound=n.selectedTilesetsChanged.bind(rW(n)),n}return FQt(I,[{key:"getOrientation",value:function(n){let C=null;return n==="top"||n==="bottom"?C="1d-horizontal":n==="left"||n==="right"?C="1d-vertical":C="2d",C}},{key:"handleSubmit",value:function(n){n&&n.preventDefault(),this.props.onTracksChosen(this.state.selectedTilesets,this.props.position,this.props.host)}},{key:"handleTilesetPickerDoubleClick",value:function(n){this.selectedTilesetsChanged([n]),this.props.onTracksChosen(this.state.selectedTilesets,this.props.position,this.props.host)}},{key:"handleOptionsChanged",value:function(n){this.options=n}},{key:"handlePlotTypeSelected",value:function(n){const{selectedTilesets:C}=this.state;for(const r of C)r.type=n;this.selectedPlotType=n,this.setState({selectedTilesets:C})}},{key:"selectedTilesetsChanged",value:function(n){let C=null;n.length===0?C=[{datatype:"none"}]:C=n;let r=!0;const o=C[0].datatype;for(const A of C)A.datatype!==o&&(r=!1);if(r)for(const A of C)A.type=this.selectedPlotType;else for(const A of C){let s=[A.datatype];const a=this.getOrientation(this.props.position);A.filetype==="cooler"&&(s=[A.datatype,"chromsizes"]);const l=qX([s],a),c=M7(s[0],this.props.position,l);A.type=c.type}this.setState({selectedTilesets:C,allTracksSameDatatype:r})}},{key:"render",value:function(){const n=this.getOrientation(this.props.position),C=N.createElement("div",null,N.createElement(RQt,{ref:r=>{this.tilesetFinder=r},datatype:this.props.datatype,onDoubleClick:this.handleTilesetPickerDoubleClick.bind(this),onTracksChosen:r=>this.props.onTracksChosen(r,this.props.position),orientation:n,selectedTilesetChanged:this.selectedTilesetsChanged.bind(this),trackSourceServers:this.props.trackSourceServers}));return N.createElement(Iw,{maxHeight:!0,okayTitle:"Submit",onCancel:this.props.onCancel,onOkay:this.handleSubmitBound,title:"Add Track"},N.createElement(N.Fragment,null,C,N.createElement(gXe,{ref:r=>{this.plotTypeChooser=r},allTracksSameDatatype:this.state.allTracksSameDatatype,datatypes:this.state.selectedTilesets.map(r=>r.filetype==="cooler"?[r.datatype,"chromsizes"]:[r.datatype]),onPlotTypeSelected:this.handlePlotTypeSelected.bind(this),orientation:n,position:this.props.position})))}}]),I}(N.Component);H2.defaultProps={position:"top"};H2.propTypes={datatype:L.string,host:L.string,onCancel:L.func.isRequired,onTracksChosen:L.func.isRequired,position:L.string,trackSourceServers:L.array.isRequired};function wJ(){return wJ=Object.assign?Object.assign.bind():function(e){for(var g=1;g"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function T2(e){return T2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},T2(e)}let R4=function(e){jQt(I,e);var g=$Qt(I);function I(){return _Qt(this,I),g.apply(this,arguments)}return LQt(I,[{key:"render",value:function(){const n=[];return this.props.children.forEach((C,r)=>{const o=`customTrackDialog_${r}`;n.push(N.createElement(C,wJ({key:o},this.props.bodyProps[r])))}),N.createElement(Iw,{maxHeight:!0,okayOnly:!0,okayTitle:"Close",onCancel:this.props.onCancel,onOkay:this.props.onCancel,title:this.props.title},n)}}]),I}(N.PureComponent);R4.defaultProps={};R4.propTypes={onCancel:L.func.isRequired,title:L.string,bodyProps:L.array,children:L.array};function gjt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function dae(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function N2(e){return N2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},N2(e)}const hae=20;let ou=function(e){Cjt(I,e);var g=rjt(I);function I(i){var n;return gjt(this,I),n=g.call(this,i),n.adjusted=!1,n.state={orientation:n.props.orientation?n.props.orientation:"right",left:n.props.position.left,top:n.props.position.top,submenuShown:null},n}return Ijt(I,[{key:"componentDidMount",value:function(){this.updateOrientation()}},{key:"UNSAFE_componentWillReceiveProps",value:function(n){this.adjusted=!1,this.setState({left:n.position.left,top:n.position.top})}},{key:"componentDidUpdate",value:function(){this.updateOrientation()}},{key:"handleItemMouseEnterWithRect",value:function(n,C){this.setState({submenuShown:C,submenuSourceBbox:n})}},{key:"handleItemMouseEnter",value:function(n,C){this.handleItemMouseEnterWithRect(n.currentTarget.getBoundingClientRect(),C)}},{key:"handleMouseLeave",value:function(){}},{key:"handleOtherMouseEnter",value:function(){this.setState({submenuShown:null})}},{key:"updateOrientation",value:function(){if(this.adjusted)return;this.adjusted=!0,this.divDom=UI.findDOMNode(this.div);const n=this.divDom.getBoundingClientRect(),C=this.props.parentBbox?this.props.parentBbox:{top:this.props.position.top,left:this.props.position.left,width:0,height:0};let r=this.state.orientation,o=C.top;if(C.top+n.height>window.innerHeight&&(C.top-n.height>0?o=C.top-n.height+hae:(o=C.top-n.height+hae,o-=o+n.height-window.innerHeight)),this.state.orientation==="left"){let A=C.left-n.width;A<0&&(C.left+C.width+n.width>window.innerWidth?A=0:(A=C.left+C.width,r="right")),this.setState({left:A,top:o,orientation:r})}else{let A=C.left+C.width;C.left+C.width+n.width>window.innerWidth&&(C.left-n.width<0?(A=0,r="right"):(A=C.left-n.width,r="left")),this.setState({left:A,top:o,orientation:r})}}},{key:"render",value:function(){const n=this.state.left?{left:this.state.left}:{right:this.state.right},C={top:this.state.top},r=Object.assign(n,C);return N.createElement("div",{ref:o=>{this.div=o},className:Vg("context-menu-item",Ut["context-menu"],{[Ut["context-menu-dark"]]:this.props.theme===qg}),style:r},this.props.children)}}]),I}(N.Component);ou.propTypes={children:L.node,orientation:L.string,parentBbox:L.object,position:L.object,theme:L.symbol.isRequired};function sjt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function mae(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function k2(e){return k2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},k2(e)}let XJ=function(e){djt(I,e);var g=hjt(I);function I(){return sjt(this,I),g.apply(this,arguments)}return ljt(I,[{key:"getSubmenu",value:function(){if(this.state.submenuShown){const n=this.state.submenuSourceBbox,C=this.state.orientation==="left"?{left:this.state.left,top:n.top}:{left:this.state.left+n.width+7,top:n.top},r=this.state.submenuShown;return N.createElement(I,{menuItems:r.children,orientation:this.state.orientation,parentBbox:n,position:C,theme:this.props.theme})}return N.createElement("div",null)}},{key:"componentWillUnmount",value:function(){}},{key:"render",value:function(){const n=[];for(const C in this.props.menuItems){const r=this.props.menuItems[C];n.push(N.createElement(tg,{key:C,onClick:r.handler?r.handler:()=>null,onMouseEnter:r.children?o=>this.handleItemMouseEnter(o,r):this.handleOtherMouseEnter.bind(this),onMouseLeave:this.handleMouseLeave},r.name,r.children&&N.createElement("svg",{className:Ut["play-icon"]},N.createElement("use",{xlinkHref:"#play"}))))}return N.createElement("div",{ref:C=>{this.div=C},className:Vg(Ut["context-menu"],{[Ut["context-menu-dark"]]:this.props.theme===qg}),style:{left:this.state.left,top:this.state.top}},n,this.getSubmenu())}}]),I}(ou);function bjt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function fae(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function Y2(e){return Y2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},Y2(e)}let Rjt=function(e){vjt(I,e);var g=Bjt(I);function I(){return bjt(this,I),g.apply(this,arguments)}return yjt(I,[{key:"getConfigureSeriesMenu",value:function(n,C,r){const o={},A=window.higlassTracksByType&&window.higlassTracksByType[r.type]&&window.higlassTracksByType[r.type].config&&window.higlassTracksByType[r.type].config.optionsInfo;if(A)for(const s of Object.keys(A))In[s]=A[s];if(!Lg[r.type]||!Lg[r.type].availableOptions)return null;for(const s of Lg[r.type].availableOptions)if(s in In){if(o[s]={name:In[s].name},In[s].generateOptions){const a=In[s].generateOptions(r);o[s].children||(o[s].children={});for(const l of a){const c={name:l.name,value:l.value,handler:()=>{r.options[s]=l.value,this.props.onTrackOptionsChanged(r.uid,r.options),this.props.closeMenu()}};o[s].children[l.value]=c}}if(In[s].inlineOptions)for(const a in In[s].inlineOptions){const l=In[s].inlineOptions[a];o[s].children||(o[s].children={});const c={name:l.name,value:l.value};l.componentPickers&&l.componentPickers[r.type]?c.handler=()=>{this.props.onConfigureTrack(r,l.componentPickers[r.type]),this.props.closeMenu()}:c.handler=()=>{r.options[s]=l.value,this.props.onTrackOptionsChanged(r.uid,r.options),this.props.closeMenu()},o[s].children[a]=c}else In[s].componentPickers&&In[s].componentPickers[r.type]&&(o[s].handler=()=>{this.props.onConfigureTrack(r,In[s].componentPickers[r.type]),this.props.closeMenu()})}return N.createElement(XJ,{key:"config-series-menu",closeMenu:this.props.closeMenu,menuItems:o,orientation:this.state.orientation,parentBbox:C,position:n,theme:this.props.theme})}},{key:"getTrackTypeItems",value:function(n,C,r){window.higlassTracksByType&&Object.keys(window.higlassTracksByType).forEach(l=>{Lg[l]=window.higlassTracksByType[l].config});let{datatype:o}=r,A=null;r.type in Lg&&(o||(o=Lg[r.type].datatype[0]),{orientation:A}=Lg[r.type]);const s=Object.values(Lg).filter(l=>l.datatype).filter(l=>l.orientation).filter(l=>l.datatype.includes(o)).filter(l=>l.orientation===A).map(l=>l.type),a={};for(let l=0;l{this.props.onChangeTrackType(r.uid,s[l])}};return N.createElement(XJ,{key:"track-type-items",closeMenu:this.props.closeMenu,menuItems:a,orientation:this.state.orientation,parentBbox:C,position:n,theme:this.props.theme})}},{key:"getSubmenu",value:function(){if(this.state.submenuShown){const n=this.state.submenuSourceBbox,C=this.state.orientation==="left"?{left:this.state.left,top:n.top}:{left:this.state.left+n.width+7,top:n.top},r=this.state.submenuShown,o=r.value;return r.option==="track-type"?this.getTrackTypeItems(C,n,o):this.getConfigureSeriesMenu(C,n,o)}return N.createElement("div",null)}},{key:"getDivideByMenuItem",value:function(){if(this.props.series.data&&this.props.series.data.type==="divided"){const n={tilesetUid:this.props.series.data.children[0].tilesetUid,server:this.props.series.data.children[0].server};return N.createElement(tg,{className:Ut["context-menu-item"],onClick:()=>this.props.onChangeTrackData(this.props.series.uid,n),onMouseEnter:C=>this.handleOtherMouseEnter(C)},N.createElement("span",{className:Ut["context-menu-span"]},"Remove divisor"))}return N.createElement(tg,{className:Ut["context-menu-item"],onClick:()=>this.props.onAddDivisor(this.props.series),onMouseEnter:n=>this.handleOtherMouseEnter(n)},N.createElement("span",{className:Ut["context-menu-span"]},"Divide by"))}},{key:"componentWillUnmount",value:function(){}},{key:"render",value:function(){let n=null;Lg[this.props.series.type]&&Lg[this.props.series.type].exportable&&(n=N.createElement(tg,{className:Ut["context-menu-item"],onClick:()=>this.props.onExportData(this.props.hostTrack.uid,this.props.track.uid),onMouseEnter:r=>this.handleOtherMouseEnter(r)},N.createElement("span",{className:Ut["context-menu-span"]},"Export Data")));const C=this.props.onAddSeries?N.createElement(tg,{className:Ut["context-menu-item"],onClick:()=>{this.props.onCloseTrack(this.props.series.uid),this.props.onAddSeries(this.props.hostTrack.uid)},onMouseEnter:r=>this.handleOtherMouseEnter(r)},N.createElement("span",{className:Ut["context-menu-span"]},"Replace Series")):null;return N.createElement("div",{ref:r=>{this.div=r},className:Vg(Ut["context-menu"],{[Ut["context-menu-dark"]]:this.props.theme===qg}),"data-menu-type":"SeriesListMenu",onMouseLeave:this.props.handleMouseLeave,style:{left:this.state.left,top:this.state.top}},N.createElement(tg,{onClick:()=>{},onMouseEnter:r=>this.handleItemMouseEnter(r,{option:"configure-series",value:this.props.track}),onMouseLeave:r=>this.handleMouseLeave(r)},"Configure Series",N.createElement("svg",{className:Ut["play-icon"]},N.createElement("use",{xlinkHref:"#play"}))),N.createElement(tg,{className:Ut["context-menu-item"],onClick:()=>{},onMouseEnter:r=>this.handleItemMouseEnter(r,{option:"track-type",value:this.props.track}),onMouseLeave:r=>this.handleMouseLeave(r)},N.createElement("span",{className:Ut["context-menu-span"]},"Track Type",N.createElement("svg",{className:Ut["play-icon"]},N.createElement("use",{xlinkHref:"#play"})))),n,this.getDivideByMenuItem(),N.createElement(tg,{className:Ut["context-menu-item"],onClick:this.props.onCloseTrack,onMouseEnter:r=>this.handleOtherMouseEnter(r)},N.createElement("span",{className:Ut["context-menu-span"]},"Close Series")),C,this.getSubmenu())}}]),I}(ou);const IXe=e=>{let g=[];for(const I of e)I.contents?g=g.concat(I.contents):g.push(I);return g},W4=(e,g,I,i)=>e?(window.higlassTracksByType&&Object.keys(window.higlassTracksByType).forEach(n=>{Lg[n]=window.higlassTracksByType[n].config}),IXe(e).map(n=>{const C=Lg[n.type]?Lg[n.type].thumbnail:null,r=C?N.createElement("div",{className:Ut["context-menu-icon"],dangerouslySetInnerHTML:{__html:C.outerHTML}}):N.createElement("div",{className:Ut["context-menu-icon"]},N.createElement("svg",null));return N.createElement(tg,{key:n.uid,className:Ut["context-menu-item"],onClick:()=>{i&&i(n.uid)},onMouseEnter:o=>{g&&g(o,n)},onMouseLeave:o=>{I&&I(o)}},r,N.createElement("span",{className:Ut["context-menu-span"]},n.options&&n.options.name&&n.options.name.length?n.options.name:n.type,g&&I?N.createElement("svg",{className:Ut["play-icon"]},N.createElement("use",{xlinkHref:"#play"})):null))})):null;function Wjt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function pae(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function K2(e){return K2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},K2(e)}const iXe=ok(e=>function(g){Njt(i,g);var I=kjt(i);function i(){return Wjt(this,i),I.apply(this,arguments)}return Xjt(i,[{key:"getSubmenu",value:function(){if(this.state.submenuShown){const C=this.state.submenuSourceBbox;let r=null;this.state.orientation==="left"?r={left:this.state.left,top:C.top}:r={left:this.state.left+C.width+7,top:C.top};const A=IXe(this.props.tracks).filter(a=>a.uid===this.state.submenuShown.uid)[0],s=A&&A.position!=="whole";return N.createElement(Rjt,{key:`series-list-menu-${A.uid}`,ref:a=>{this.seriesListMenu=a},closeMenu:this.props.closeMenu,hostTrack:this.props.tracks[0],onAddDivisor:this.props.onAddDivisor,onAddSeries:s?this.props.onAddSeries:null,onChangeTrackData:this.props.onChangeTrackData,onChangeTrackType:this.props.onChangeTrackType,onCloseTrack:()=>this.props.onCloseTrack(this.state.submenuShown.uid),onConfigureTrack:this.props.onConfigureTrack,onDivideSeries:this.props.onDivideSeries,onExportData:this.props.onExportData,onLockScales:this.props.onLockScales,onTrackOptionsChanged:this.props.onTrackOptionsChanged,orientation:this.state.orientation,parentBbox:C,position:r,series:this.state.submenuShown,theme:this.props.theme,track:A,trackOrientation:this.props.trackOrientation,trackSourceServers:this.props.trackSourceServers})}return N.createElement("div",null)}}]),i}(e));function xjt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function bae(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function i0(e){return i0=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},i0(e)}let Ujt=function(e){Pjt(I,e);var g=Jjt(I);function I(i){var n;return xjt(this,I),n=g.call(this,i),n.seriesRefs={},n.seriesListMenu=null,n}return Fjt(I,[{key:"componentDidMount",value:function(){oW(i0(I.prototype),"componentDidMount",this).call(this)}},{key:"render",value:function(){return N.createElement("div",{ref:n=>{this.div=n},className:Vg(Ut["context-menu"],{[Ut["context-menu-dark"]]:this.props.theme===qg}),"data-menu-type":"ConfigTrackMenu",style:{left:this.state.left,top:this.state.top}},W4(this.props.tracks,this.handleItemMouseEnter.bind(this),this.handleMouseLeave.bind(this),null),N.createElement("hr",{className:Ut["context-menu-hr"]}),N.createElement(tg,{contextMenu:this,onClick:()=>this.props.onLockValueScale(this.props.tracks[0].uid),onMouseEnter:n=>this.handleOtherMouseEnter(n)},"Lock Value Scale With"),N.createElement(tg,{contextMenu:this,onClick:()=>this.props.onUnlockValueScale(this.props.tracks[0].uid),onMouseEnter:n=>this.handleOtherMouseEnter(n)},"Unlock Value Scale"),N.createElement("hr",{className:Ut["context-menu-hr"]}),N.createElement(tg,{contextMenu:this,onClick:()=>this.props.onAddSeries(this.props.tracks[0].uid),onMouseEnter:n=>this.handleOtherMouseEnter(n)},"Add Series"),N.createElement(tg,{onClick:()=>this.props.onCloseTrack(this.props.tracks[0].uid)},"Close Track"),N.createElement(tg,{onClick:()=>{this.props.onReplaceTrack(this.props.tracks[0].uid,this.props.trackOrientation)}},"Replace Track"),this.getSubmenu())}}]),I}(U0(ou).with(iXe));function nXe(e){return N.createElement("div",null,W4(e.tracks,null,null,e.onCloseTrack),N.createElement("hr",{className:Ut["context-menu-hr"]}),N.createElement(tg,{onClick:()=>e.onCloseTrack(e.tracks[0].uid)},"Close all series"))}nXe.propTypes={onCloseTrack:L.func.isRequired,tracks:L.array.isRequired};function Qjt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function yae(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function D2(e){return D2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},D2(e)}let Xc=function(e){e4t(I,e);var g=t4t(I);function I(i){var n;return Qjt(this,I),n=g.call(this,i),n.clickHandlerBound=n.clickHandler.bind(AW(n)),n.contextMenuHandlerBound=n.contextMenuHandler.bind(AW(n)),n.resizeHandlerBound=n.resizeHandler.bind(AW(n)),n}return jjt(I,[{key:"componentDidMount",value:function(){this.popup=document.createElement("div"),document.body.appendChild(this.popup),this.popup.style.zIndex=99,this.popup.style.position="absolute",this.popup.className="hg-popup",document.addEventListener("click",this.clickHandlerBound,!0),document.addEventListener("contextmenu",this.contextMenuHandlerBound,!0),window.addEventListener("resize",this.resizeHandlerBound,!0),this._renderLayer()}},{key:"componentDidUpdate",value:function(){this._renderLayer()}},{key:"componentWillUnmount",value:function(){document.removeEventListener("click",this.clickHandlerBound,!0),document.removeEventListener("contextmenu",this.contextMenuHandlerBound,!0),window.removeEventListener("resize",this.resizeHandlerBound,!0),UI.unmountComponentAtNode(this.popup),document.body.removeChild(this.popup)}},{key:"_renderLayer",value:function(){UI.render(this.props.children,this.popup)}},{key:"clickHandler",value:function(n){this.popup.contains(n.target)||this.props.onMenuClosed&&this.props.onMenuClosed(n)}},{key:"contextMenuHandler",value:function(n){n.altKey||(n.preventDefault(),this.clickHandler(n))}},{key:"resizeHandler",value:function(){this.props.onMenuClosed(null)}},{key:"render",value:function(){return N.createElement("div",null)}}]),I}(N.Component);Xc.defaultProps={onMenuClosed:EZe};Xc.propTypes={children:L.node.isRequired,onMenuClosed:L.func};const i4t=oZe(e=>N.createElement(eWe,{className:e.className,controlAlignLeft:e.controlAlignLeft,editable:e.editable,handleConfigTrack:e.handleConfigTrack,handleResizeTrack:e.handleResizeTrack,height:e.height,item:e.item,onAddSeries:e.onAddSeries,onCloseTrack:e.onCloseTrack,onCloseTrackMenuOpened:e.onCloseTrackMenuOpened,onConfigTrackMenuOpened:e.onConfigTrackMenuOpened,resizeHandles:e.resizeHandles,uid:e.uid,width:e.width})),n4t={"vertical-tiled-plot":"_vertical-tiled-plot_f3ho8_1"};function C4t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function Zae(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function x2(e){return x2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},x2(e)}function Gae(e){return e&&e.sourceEvent}let KJ=function(e){a4t(I,e);var g=s4t(I);function I(i){var n;return C4t(this,I),n=g.call(this,i),n.brushBehavior=SS().on("start",n.brushStarted.bind(aW(n))).on("brush",n.brushed.bind(aW(n))).on("end",n.brushedEnded.bind(aW(n))),n}return r4t(I,[{key:"componentDidMount",value:function(){this.props.isRangeSelectionActive&&this.addBrush()}},{key:"shouldComponentUpdate",value:function(n,C){if(this.rangeSelectionTriggered)return this.rangeSelectionTriggered=!1,this.rangeSelectionTriggeredEnd&&this.props.rangeSelection!==n.rangeSelection&&this.moveBrush(n.rangeSelection[0]?n.rangeSelection[0]:null,!0),this.rangeSelectionTriggeredEnd=!1,this.state!==C;if(this.props.rangeSelection!==n.rangeSelection){const r=this.props.is1dRangeSelection?0:1;return this.moveBrush(n.rangeSelection[r]?n.rangeSelection[r]:null,n.rangeSelectionEnd),this.state!==C}return!0}},{key:"componentDidUpdate",value:function(){this.props.isRangeSelectionActive?this.addBrush():this.removeBrush()}},{key:"addBrush",value:function(){!this.brushEl||this.brushElAddedBefore===this.brushEl||(this.brushElAddedBefore&&this.brushElAddedBefore.on(".brush",null),this.brushEl.call(this.brushBehavior),this.brushElAddedBefore=this.brushEl,Bp(this.brushEl,Fo["track-range-selection-group-brush-selection"]))}},{key:"brushed",value:function(n){const C=this.rangeSelectionMoved;this.rangeSelectionMoved=!1,!(!Gae(n)||!this.props.onRangeSelection||C)&&(this.rangeSelectionTriggered=!0,this.props.onRangeSelection(n.selection))}},{key:"brushStarted",value:function(n){!Gae(n)||!n.selection||this.props.onRangeSelectionStart()}},{key:"brushedEnded",value:function(n){if(!this.props.is1dRangeSelection)return;const C=this.rangeSelectionMovedEnd;this.rangeSelectionMovedEnd=!1,n.selection&&n.sourceEvent&&this.props.onRangeSelection&&!C&&(this.rangeSelectionTriggered=!0,this.rangeSelectionTriggeredEnd=!0,this.props.onRangeSelectionEnd(n.selection)),n.selection||(this.rangeSelectionTriggered=!0,this.props.onRangeSelectionReset())}},{key:"moveBrush",value:function(n,C=!1){if(!this.brushEl)return;const r=n?[this.props.scale(n[0]),this.props.scale(n[1])]:null;this.rangeSelectionMoved=!0,this.rangeSelectionMovedEnd=!0,C?this.brushEl.transition().call(this.brushBehavior.move,r):this.brushEl.call(this.brushBehavior.move,r)}},{key:"removeBrush",value:function(){this.brushElAddedBefore&&(this.brushElAddedBefore.call(this.brushBehavior.move,null),this.brushElAddedBefore.on(".brush",null),this.brushElAddedBefore=void 0,this.props.onRangeSelectionReset())}},{key:"render",value:function(){const n=this.props.tracks.map(o=>o.width).reduce(Pl,0),C=this.props.tracks.map(o=>V0(o)).reduce(RS,!1),r=Fo[this.props.isRangeSelectionActive?"track-range-selection-active":"track-range-selection"];return N.createElement("div",{className:n4t["vertical-tiled-plot"]},C&&N.createElement("svg",{ref:o=>{this.brushEl=cg(o)},className:r,style:{height:this.props.height,width:n},xmlns:"http://www.w3.org/2000/svg"}),N.createElement(lk,{axis:"x",className:Vg(Eo.list,Eo.stylizedList,Eo.horizontalList),component:q1e,editable:this.props.editable,handleConfigTrack:this.props.handleConfigTrack,handleResizeTrack:this.props.handleResizeTrack,height:this.props.height,helperClass:Eo.stylizedHelper,itemClass:Vg(Eo.stylizedItem,Eo.horizontalItem),itemControlAlignLeft:this.props.tracksControlAlignLeft,itemReactClass:i4t,items:this.props.tracks.map(o=>({configMenuVisible:o.uid===this.props.configTrackMenuId,uid:o.uid||Ag.nice(),height:this.props.height,width:o.width,value:o.value})),onAddSeries:this.props.onAddSeries,onCloseTrack:this.props.onCloseTrack,onCloseTrackMenuOpened:this.props.onCloseTrackMenuOpened,onConfigTrackMenuOpened:this.props.onConfigTrackMenuOpened,onSortEnd:this.props.handleSortEnd,referenceAncestor:this.props.referenceAncestor,resizeHandles:this.props.resizeHandles,useDragHandle:!0,width:n}))}}]),I}(N.Component);KJ.propTypes={configTrackMenuId:L.string,editable:L.bool,handleConfigTrack:L.func,handleResizeTrack:L.func,handleSortEnd:L.func,is1dRangeSelection:L.bool,isRangeSelectionActive:L.bool,height:L.number,onAddSeries:L.func,onCloseTrack:L.func,onCloseTrackMenuOpened:L.func,onConfigTrackMenuOpened:L.func,onRangeSelection:L.func,onRangeSelectionEnd:L.func,onRangeSelectionReset:L.func,onRangeSelectionStart:L.func,rangeSelection:L.array,rangeSelectionEnd:L.bool,referenceAncestor:L.func,resizeHandles:L.object,scale:L.func,tracks:L.array,tracksControlAlignLeft:L.bool};function u4t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function vae(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function F2(e){return F2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},F2(e)}let CXe=function(e){f4t(I,e);var g=p4t(I);function I(){return u4t(this,I),g.apply(this,arguments)}return d4t(I,[{key:"render",value:function(){const n=W4(this.props.tracks,this.handleItemMouseEnter.bind(this),this.handleMouseLeave.bind(this)),C=this.props.customItems?N.Children.map(this.props.customItems,r=>N.cloneElement(r,{onMouseEnter:o=>{this.handleOtherMouseEnter(o)}})):null;return N.createElement("div",{ref:r=>{this.div=r},className:Vg(Ut["context-menu"],{[Ut["context-menu-dark"]]:this.props.theme===qg}),"data-menu-type":"ViewContextMenu",style:{left:this.state.left,top:this.state.top}},C,C&&N.createElement("hr",{className:Ut["context-menu-hr"]}),n,n&&N.createElement("hr",{className:Ut["context-menu-hr"]}),N.createElement(tg,{onClick:()=>this.props.onAddTrack({type:"horizontal-rule",y:this.props.coords[1],position:"whole"}),onMouseEnter:r=>this.handleOtherMouseEnter(r)},"Add Horizontal Rule"),N.createElement(tg,{onClick:()=>this.props.onAddTrack({type:"vertical-rule",x:this.props.coords[0],position:"whole"}),onMouseEnter:r=>this.handleOtherMouseEnter(r)},"Add Vertical Rule"),N.createElement(tg,{onClick:()=>this.props.onAddTrack({type:"cross-rule",x:this.props.coords[0],y:this.props.coords[1],position:"whole"}),onMouseEnter:r=>this.handleOtherMouseEnter(r)},"Add Cross Rule"),N.createElement("hr",{className:Ut["context-menu-hr"]}),this.hasMatrixTrack(this.props.tracks)&&N.createElement(tg,{onClick:this.handleAddHorizontalSection.bind(this),onMouseEnter:r=>this.handleOtherMouseEnter(r)},"Add Horizontal Cross Section"),this.hasMatrixTrack(this.props.tracks)&&N.createElement(tg,{onClick:this.handleAddVerticalSection.bind(this),onMouseEnter:r=>this.handleOtherMouseEnter(r)},"Add Vertical Cross Section"),this.getSubmenu())}},{key:"hasMatrixTrack",value:function(n){return B1(this.props.tracks).filter(r=>r.type==="heatmap").length>0}},{key:"handleAddHorizontalSection",value:function(){const C=B1(this.props.tracks).filter(r=>r.type==="heatmap")[0];this.props.onAddTrack({type:"horizontal-rule",y:this.props.coords[1],position:"whole"}),this.props.onAddTrack({data:{type:"horizontal-section",server:C.server,tilesetUid:C.tilesetUid,slicePos:this.props.coords[1]},options:{valueScaling:"log"},type:"horizontal-bar",height:30,position:"top"})}},{key:"handleAddVerticalSection",value:function(){const C=B1(this.props.tracks).filter(r=>r.type==="heatmap")[0];this.props.onAddTrack({type:"vertical-rule",x:this.props.coords[0],position:"whole"}),this.props.onAddTrack({data:{type:"vertical-section",server:C.server,tilesetUid:C.tilesetUid,slicePos:this.props.coords[0]},options:{valueScaling:"log"},type:"vertical-bar",height:30,position:"left"})}}]),I}(U0(ou).with(iXe));CXe.propTypes={coords:L.array,customItems:L.array};function G4t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function Bae(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function E2(e){return E2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},E2(e)}let X4=function(e){w4t(I,e);var g=V4t(I);function I(i){var n;G4t(this,I),n=g.call(this,i),n.closing=!1;const{tracks:C}=n.props;return n.canvasElement=null,n.tracksByUidInit={},[...n.props.tracks.top||[],...n.props.tracks.right||[],...n.props.tracks.bottom||[],...n.props.tracks.left||[],...n.props.tracks.gallery||[],...n.props.tracks.center||[]].forEach(r=>{r.type==="combined"?r.contents.forEach(o=>{n.tracksByUidInit[o.uid]=!1}):n.tracksByUidInit[r.uid]=!1}),n.xScale=null,n.yScale=null,n.addUidsToTracks(C),n.trackToReplace=null,n.trackRenderer=null,n.configTrackMenu=null,n.state={sizeMeasured:!1,height:10,width:10,tracks:C,init:!1,addTrackPosition:null,customDialog:null,mouseOverOverlayUid:null,forceUpdate:0,rangeSelection:[null,null],rangeSelectionEnd:!1,chromInfo:null,defaultChromSizes:null,contextMenuCustomItems:null,contextMenuPosition:null,addDivisorDialog:null},n.reset=!0,window.higlassTracksByType&&Object.keys(window.higlassTracksByType).forEach(r=>{Lg[r]=window.higlassTracksByType[r].config}),n.topHeight=0,n.bottomHeight=0,n.leftWidth=0,n.rightWidth=0,n.centerHeight=0,n.centerWidth=0,n.dragTimeout=null,n.previousPropsStr="",n.contextMenuHandlerBound=n.contextMenuHandler.bind(en(n)),n.handleNoTrackAddedBound=n.handleNoTrackAdded.bind(en(n)),n.handleTracksAddedBound=n.handleTracksAdded.bind(en(n)),n.closeMenusBound=n.closeMenus.bind(en(n)),n.handleAddDivisorBound=n.handleAddDivisor.bind(en(n)),n.handleAddSeriesBound=n.handleAddSeries.bind(en(n)),n.handleChangeTrackDataBound=n.handleChangeTrackData.bind(en(n)),n.handleChangeTrackTypeBound=n.handleChangeTrackType.bind(en(n)),n.handleCloseTrackBound=n.handleCloseTrack.bind(en(n)),n.handleConfigureTrackBound=n.handleConfigureTrack.bind(en(n)),n.handleExportTrackDataBound=n.handleExportTrackData.bind(en(n)),n.handleLockValueScaleBound=n.handleLockValueScale.bind(en(n)),n.handleReplaceTrackBound=n.handleReplaceTrack.bind(en(n)),n.handleTrackOptionsChangedBound=n.handleTrackOptionsChanged.bind(en(n)),n.handleUnlockValueScaleBound=n.handleUnlockValueScale.bind(en(n)),n.onAddTrack=n.handleAddTrack.bind(en(n)),n}return v4t(I,[{key:"waitForDOMAttachment",value:function(n){if(!this.mounted)return;const C=UI.findDOMNode(this);document.body.contains(C)?n():requestAnimationFrame(()=>this.waitForDOMAttachment(n))}},{key:"componentDidMount",value:function(){this.mounted=!0,this.element=UI.findDOMNode(this),this.canvasElement=UI.findDOMNode(this.props.canvasElement),this.waitForDOMAttachment(()=>{PX.ElementQueries.listen(),this.resizeSensor=new PX.ResizeSensor(this.element.parentNode,this.measureSize.bind(this)),this.measureSize()}),this.addEventListeners(),this.pubSubs=[],this.pubSubs.push(this.props.pubSub.subscribe("contextmenu",this.contextMenuHandlerBound))}},{key:"UNSAFE_componentWillReceiveProps",value:function(n){this.addUidsToTracks(n.tracks),this.setState({tracks:n.tracks})}},{key:"shouldComponentUpdate",value:function(n,C){const r=this.previousPropsStr,o=this.updatablePropsToString(n),A=JSON.stringify(this.state),s=JSON.stringify(C),a=r!==o||A!==s||this.props.chooseTrackHandler!==n.chooseTrackHandler||this.props.customDialog!==n.customDialog;a&&(this.previousPropsStr=o);const l=this.numTracks;return this.numTracks=0,Qa(this.props.tracks,()=>this.numTracks++),this.reset=this.reset||l===0&&this.numTracks>0,this.numTracks||(this.tracksByUidInit={}),a}},{key:"UNSAFE_componentWillUpdate",value:function(){}},{key:"componentDidUpdate",value:function(n,C){if(C.rangeSelection!==this.state.rangeSelection){let r=[null,null];this.state.defaultChromSizes&&this.state.rangeSelection.every(o=>o&&o.length)&&(r=this.state.rangeSelection.map(o=>e9(...o,this.state.defaultChromSizes))),this.props.onRangeSelection({dataRange:this.state.rangeSelection,genomicRange:r})}if(this.state.customDialog||this.props.customDialog){const r=this.state.customDialog||this.props.customDialog;if(r.length>0){const o=[],A=[];r.forEach(s=>{o.push(s.bodyComponent),A.push(s.bodyProps)}),this.props.modal.open(N.createElement(R4,{children:o,bodyProps:A,onCancel:this.props.closeCustomDialog,title:r[0].title}))}}if(n.tracks.center,this.props.tracks.center,(this.state.addTrackPosition||this.props.addTrackPosition)&&this.props.modal.open(N.createElement(H2,{host:this.state.addTrackHost,onCancel:this.handleNoTrackAddedBound,onTracksChosen:this.handleTracksAddedBound,position:this.state.addTrackPosition||this.props.addTrackPosition,trackSourceServers:this.props.trackSourceServers})),this.state.addDivisorDialog){const r=this.state.addDivisorDialog;this.props.modal.open(N.createElement(H2,{datatype:Lg[r.type].datatype[0],host:this.state.addTrackHost,onCancel:()=>{this.setState({addDivisorDialog:null})},onTracksChosen:o=>{this.handleDivisorChosen(r,o)},trackSourceServers:this.props.trackSourceServers}))}}},{key:"componentWillUnmount",value:function(){this.closing=!0,this.removeEventListeners(),this.pubSubs.forEach(n=>this.props.pubSub.unsubscribe(n))}},{key:"addUidsToTracks",value:function(n){Object.keys(n).forEach(C=>{n[C].forEach(r=>{r.uid=r.uid||Ag.nice()})})}},{key:"contextMenuHandler",value:function(n){if(!this.divTiledPlot)return;const C=this.divTiledPlot.getBoundingClientRect();if(!Q7(n.clientX,n.clientY,C.left,C.left+C.width,C.top,C.top+C.height))return;const o=[n.clientX,n.clientY],A=Eg(n,this.divTiledPlot),s=this.trackRenderer.zoomedXScale.invert(A[0]),a=this.trackRenderer.zoomedYScale.invert(A[1]);let l=null;n.hgCustomItems&&(l=n.hgCustomItems.map(c=>N.createElement(tg,{key:c.key,onClick:c.onClick},c.text))),this.setState({contextMenuCustomItems:l,contextMenuPosition:{left:o[0],top:o[1],canvasLeft:A[0]+this.trackRenderer.xPositionOffset,canvasTop:A[1]+this.trackRenderer.yPositionOffset},contextMenuDataX:s,contextMenuDataY:a})}},{key:"measureSize",value:function(){this.element.clientWidth>0&&this.element.clientHeight>0&&this.setState({sizeMeasured:!0,width:this.element.clientWidth,height:this.element.clientHeight})}},{key:"handleTrackOptionsChanged",value:function(n,C){return this.props.onTrackOptionsChanged(n,C)}},{key:"handleScalesChanged",value:function(n,C){this.xScale=n,this.yScale=C,this.props.onScalesChanged(n,C)}},{key:"handleTilesetInfoReceived",value:function(n,C){const r=jC(this.props.tracks,n);if(!r){console.warn("Strange, track not found:",n);return}this.tracksByUidInit[r.uid]=!0,this.checkAllTilesetInfoReceived(),r.options||(r.options={}),r.name=C.name,r.maxWidth=C.max_width,r.transforms=C.transforms,r.aggregationModes=C.aggregation_modes,r.header=C.header,r.binsPerDimension=C.bins_per_dimension,C.resolutions?(r.maxZoom=C.resolutions.length-1,r.resolutions=C.resolutions):r.maxZoom=C.max_zoom,r.coordSystem=C.coordSystem,r.datatype=C.datatype}},{key:"checkAllTilesetInfoReceived",value:function(){if(this.state.init&&!this.reset||!this.trackRenderer||!this.props.zoomToDataExtentOnInit())return;const n=Object.keys(this.trackRenderer.trackDefObjects).map(r=>{const o=this.trackRenderer.trackDefObjects[r].trackObject;return o.childTracks?o.childTracks:o}).reduce((r,o)=>r.concat(o),[]).filter(({tilesetInfo:r})=>typeof r<"u"&&r!==!0),C=Object.values(this.tracksByUidInit).filter(r=>r).length;n.length===C&&(this.setState({init:!0}),this.reset=!1,this.handleZoomToData())}},{key:"handleOverlayMouseEnter",value:function(n){this.setState({mouseOverOverlayUid:n})}},{key:"handleOverlayMouseLeave",value:function(n){n===this.state.mouseOverOverlayUid&&this.setState({mouseOverOverlayUid:null})}},{key:"handleTrackPositionChosen",value:function(n){this.setState({mouseOverOverlayUid:null}),this.props.chooseTrackHandler(n.track.uid)}},{key:"handleNoTrackAdded",value:function(){this.trackToReplace=null,this.props.onNoTrackAdded(),this.setState({addTrackPosition:null,addTrackHost:null})}},{key:"handleAddDivisor",value:function(n){this.setState({addDivisorDialog:n})}},{key:"handleDivisorChosen",value:function(n,C){this.setState({addDivisorDialog:null});const r=n.data?{server:n.data.server,tilesetUid:n.data.tilesetUid}:{server:n.server,tilesetUid:n.tilesetUid},o={server:C[0].server,tilesetUid:C[0].uuid};this.handleChangeTrackData(n.uid,{type:"divided",children:[r,o]})}},{key:"handleDivideSeries",value:function(n){}},{key:"handleAddSeries",value:function(n){const C=WG(this.props.tracks,n),r=jC(this.props.tracks,n);this.setState({addTrackPosition:C,addTrackHost:r})}},{key:"handleReplaceTrack",value:function(n,C){this.trackToReplace=n,this.handleAddTrack(C)}},{key:"handleAddTrack",value:function(n){this.setState({addTrackPosition:n,addTrackHost:null})}},{key:"handleResizeTrack",value:function(n,C,r){const{tracks:o}=this.state;for(const A in o){const a=o[A].filter(l=>l.uid===n);a.length>0&&(a[0].width=C,a[0].height=r)}this.setState({tracks:o,forceUpdate:Math.random()}),this.props.onResizeTrack()}},{key:"closeMenus",value:function(){this.setState({closeTrackMenuId:null,configTrackMenuId:null,contextMenuPosition:null,contextMenuCustomItems:null})}},{key:"handleLockValueScale",value:function(n){this.closeMenus(),this.props.onLockValueScale(n)}},{key:"handleUnlockValueScale",value:function(n){this.closeMenus(),this.props.onUnlockValueScale(n)}},{key:"handleCloseTrack",value:function(n){this.closeMenus(),this.props.onCloseTrack(n)}},{key:"handleChangeTrackType",value:function(n,C){this.closeMenus(),this.props.onChangeTrackType(n,C)}},{key:"handleChangeTrackData",value:function(n,C){this.closeMenus(),this.props.onChangeTrackData(n,C)}},{key:"handleTracksAdded",value:function(n,C,r){return this.trackToReplace&&(this.handleCloseTrack(this.trackToReplace),this.trackToReplace=null),this.props.onTracksAdded(n,C,r),this.setState({addTrackPosition:null,addTrackHost:null}),n}},{key:"handleCloseTrackMenuOpened",value:function(n,C){this.setState({closeTrackMenuId:n,closeTrackMenuLocation:C})}},{key:"handleCloseContextMenu",value:function(){this.setState({contextMenuCustomItems:null,contextMenuPosition:null,contextMenuDataX:null,contextMenuDataY:null})}},{key:"handleCloseTrackMenuClosed",value:function(){this.setState({closeTrackMenuId:null})}},{key:"handleConfigTrackMenuOpened",value:function(n,C){this.closeMenus(),this.setState({configTrackMenuId:n,configTrackMenuLocation:C})}},{key:"handleConfigureTrack",value:function(n,C){this.setState({configTrackMenuId:null,trackOptions:{track:n,configComponent:C}}),this.closeMenus()}},{key:"handleSortEnd",value:function(n){this.setState(C=>{const r=C.tracks,o={};for(let A=0;A{C[r]&&C[r].forEach(o=>{o.contents&&o.contents.forEach(A=>{A.position=r}),o.position=r,n.push({track:o,location:r})})}),n}},{key:"calculateTrackPosition",value:function(n,C){let r=this.props.paddingTop,o=this.props.paddingBottom,A=this.props.paddingLeft,s=this.props.paddingRight,a=this.centerWidth,l=n.height,c=0,u=0;switch(C){case"top":A+=this.leftWidth;for(let d=0;dr.includes&&r.includes.length).map(r=>{const o=r.type?`overlay-${r.type}-track`:"overlay-track",A={...r,uid:r.uid||Ag.nice(),includes:r.includes,type:o,options:Object.assign(r.options,{orientationsAndPositions:r.includes.map(s=>{const a=jC(this.props.tracks,s);if(!a)return console.warn(`OverlayTrack included uid (${s}) not found in the track list`),null;const l=WG(this.props.tracks,a.uid);let c;if((l==="top"||l==="bottom")&&(c="1d-horizontal"),(l==="left"||l==="right")&&(c="1d-vertical"),l==="center"&&(c="2d"),!c)return console.warn("Only top, bottom, left, right, or center tracks can be overlaid at the moment"),null;const u=n.filter(h=>h.track.uid===s);if(!u.length)return null;const d={left:u[0].left-this.props.paddingLeft,top:u[0].top-this.props.paddingTop,width:u[0].width,height:u[0].height};return{orientation:c,position:d}}).filter(s=>s)})};return{top:this.props.paddingTop,left:this.props.paddingLeft,width:this.leftWidth+this.centerWidth+this.rightWidth,height:this.topHeight+this.centerHeight+this.bottomHeight+this.props.marginTop+this.props.marginBottom,track:A}}):[]}},{key:"positionedTracks",value:function(){return this.createTracksAndLocations().map(({track:C,location:r})=>this.calculateTrackPosition(C,r))}},{key:"createTrackPositionTexts",value:function(){const n=this.positionedTracks();return this.createTracksAndLocations(),n.map(r=>{const{track:o}=r;return N.createElement("div",{key:o.uid,style:{left:r.left,top:r.top,width:r.width,height:r.height,position:"absolute"}},o.uid.slice(0,2))})}},{key:"handleExportTrackData",value:function(n,C){const r=jC(this.props.tracks,C);let o=null;n!==C?o=this.trackRenderer.trackDefObjects[n].trackObject.createdTracks[r.uid]:{trackObject:o}=this.trackRenderer.trackDefObjects[n],o.exportData(),this.closeMenus()}},{key:"listTracksAtPosition",value:function(n,C,r=!1){const o=[];if(!this.trackRenderer)return[];for(const A in this.trackRenderer.trackDefObjects){const s=this.trackRenderer.trackDefObjects[A].trackObject;if(s.respondsToPosition(n,C))if(r){if(this.props.tracks.center)if(this.props.tracks.center.contents)for(let a=0;ao[d]&&(o[d]=u.tilesetInfo.max_pos[d]);const s=this.trackRenderer.currentProps.paddingLeft+this.trackRenderer.currentProps.leftWidth;let a=[s,s+this.trackRenderer.currentProps.centerWidth].map(this.trackRenderer.zoomTransform.rescaleX(this.trackRenderer.xScale).invert);const l=this.trackRenderer.currentProps.paddingTop+this.trackRenderer.currentProps.topHeight;let c=[l,l+this.trackRenderer.currentProps.centerHeight].map(this.trackRenderer.zoomTransform.rescaleY(this.trackRenderer.yScale).invert);this.trackRenderer.zoomTransform.k=1,this.trackRenderer.zoomTransform.x=0,this.trackRenderer.zoomTransform.y=0,this.trackRenderer.applyZoomTransform(),r[0]Number.MIN_SAFE_INTEGER&&(a=[r[0],o[0]]),r[1]Number.MIN_SAFE_INTEGER&&(c=[r[1],o[1]]),this.props.onDataDomainChanged(a,c)}},{key:"resetViewport",value:function(){this.trackRenderer.zoomTransform.k=1,this.trackRenderer.zoomTransform.x=0,this.trackRenderer.zoomTransform.y=0,this.trackRenderer.applyZoomTransform(),this.props.onDataDomainChanged(this.props.initialXDomain,this.props.initialYDomain)}},{key:"updatablePropsToString",value:function(n){return JSON.stringify({tracks:n.tracks,overlays:n.overlays,viewOptions:n.viewOptions,uid:n.uid,addTrackPosition:n.addTrackPosition,editable:n.editable,marginTop:n.marginTop,marginBottom:n.marginBottom,marginLeft:n.marginLeft,marginRight:n.marginRight,paddingTop:n.paddingTop,paddingBottom:n.paddingBottom,paddingLeft:n.paddingLeft,paddingRight:n.paddingRight,mouseTool:n.mouseTool,initialXDomain:n.initialXDomain,initialYDomain:n.initialYDomain,trackSourceServers:n.trackSourceServers,zoomable:n.zoomable,draggingHappening:n.draggingHappening})}},{key:"getXYScales",value:function(){this.trackRenderer&&(this.xScale=this.trackRenderer.currentXScale,this.yScale=this.trackRenderer.currentYScale)}},{key:"rangeViewToDataLoci",value:function(n,C){return C?[parseInt(C.invert(n[0]),10),parseInt(C.invert(n[1]),10)]:[null,null]}},{key:"rangeSelectionResetHandler",value:function(){this.state.rangeSelectionMaster&&this.setState({is1dRangeSelection:null,rangeSelection:[null,null],rangeSelectionMaster:null,rangeSelectionEnd:!1})}},{key:"rangeSelection1dEndHandler",value:function(n){(!this.xScale||!this.yScale)&&this.getXYScales();const C=n==="x"?this.xScale:this.yScale;return r=>{this.setState(o=>{const A=o.is1dRangeSelection?[null,null]:o.rangeSelection.slice(),s=!this.state.is1dRangeSelection&&n==="y"?1:0;let a=this.rangeViewToDataLoci(r,C);const l=a[1]-a[0];if(this.props.rangeSelection1dSize[0]>l){const c=a[0]+l/2;a=[c-this.props.rangeSelection1dSize[0]/2,c+this.props.rangeSelection1dSize[0]/2]}else if(this.props.rangeSelection1dSize[1]Math.round(c))),{rangeSelection:A,rangeSelectionEnd:!0}})}}},{key:"rangeSelection1dHandler",value:function(n){(!this.xScale||!this.yScale)&&this.getXYScales();const C=n==="x"?this.xScale:this.yScale;return r=>{this.setState(o=>{const A=o.is1dRangeSelection?[null,null]:o.rangeSelection.slice(),s=!o.is1dRangeSelection&&n==="y"?1:0;return A[s]=this.rangeViewToDataLoci(r,C),{rangeSelection:A,rangeSelectionEnd:!1}})}}},{key:"rangeSelection1dStartHandler",value:function(){this.state.rangeSelectionMaster||this.setState({is1dRangeSelection:!0,rangeSelectionMaster:!0,rangeSelectionEnd:!1})}},{key:"rangeSelection2dHandler",value:function(n){(!this.xScale||!this.yScale)&&this.getXYScales(),this.setState({rangeSelection:[this.rangeViewToDataLoci(n[0],this.xScale),this.rangeViewToDataLoci(n[1],this.yScale)],rangeSelectionEnd:!1})}},{key:"rangeSelection2dStartHandler",value:function(){this.state.rangeSelectionMaster||this.setState({is1dRangeSelection:!1,rangeSelectionMaster:!0,rangeSelectionEnd:!1})}},{key:"rangeSelection2dEndHandler",value:function(n){(!this.xScale||!this.yScale)&&this.getXYScales();const C=this.rangeViewToDataLoci(n[0],this.xScale),r=this.rangeViewToDataLoci(n[1],this.yScale);let o=[C,r];const A=C[1]-C[0],s=r[1]-r[0],a=[A,s];o.forEach((l,c)=>{if(this.props.rangeSelection1dSize[0]>a[c]){const u=l[0]+Math.round(a[c]/2);l[0]=u-this.props.rangeSelection1dSize[0]/2,l[1]=u+this.props.rangeSelection1dSize[0]/2}else if(this.props.rangeSelection1dSize[1]l.map(c=>Math.round(c)))),this.setState({rangeSelection:o,rangeSelectionEnd:!0})}},{key:"getContextMenu",value:function(){if(this.state.contextMenuPosition){const n=this.listTracksAtPosition(this.state.contextMenuPosition.canvasLeft,this.state.contextMenuPosition.canvasTop);return N.createElement(Xc,{onMenuClosed:this.closeMenusBound},N.createElement(CXe,{closeMenu:this.closeMenusBound,coords:[this.state.contextMenuDataX,this.state.contextMenuDataY],customItems:this.state.contextMenuCustomItems,onAddDivisor:this.handleAddDivisorBound,onAddSeries:this.handleAddSeriesBound,onAddTrack:C=>{this.props.onTracksAdded([C],C.position,null),this.handleCloseContextMenu()},onChangeTrackData:this.handleChangeTrackDataBound,onChangeTrackType:this.handleChangeTrackTypeBound,onCloseTrack:this.handleCloseTrackBound,onConfigureTrack:this.handleConfigureTrackBound,onExportData:this.handleExportTrackDataBound,onLockValueScale:this.handleLockValueScaleBound,onReplaceTrack:this.handleReplaceTrackBound,onTrackOptionsChanged:this.handleTrackOptionsChangedBound,onUnlockValueScale:this.handleUnlockValueScaleBound,orientation:"right",position:this.state.contextMenuPosition,theme:this.props.theme,tracks:n,trackSourceServers:this.props.trackSourceServers}))}return null}},{key:"getIdealizedTrackPositionsOverlay",value:function(){const n=this.props.draggingHappening,C=n.datatype;if(!(C in dB)&&!n.defaultTracks){console.warn("unknown data type:",n.higlassTrack);return}const r={"1d-horizontal":["top","bottom","left","right"],"2d":["center"],"1d-vertical":["left","right"]},o=dB[C]||{};if(n.defaultTracks)for(const S of n.defaultTracks)if(!Lg[S])console.warn("unknown track type",S);else for(const X of r[Lg[S].orientation])o[X]=S;const A=new Set(["top","left","right","center","bottom"].filter(S=>S in this.state.tracks&&this.state.tracks[S].length)),s="top"in o,a="left"in o,l="right"in o,c="bottom"in o,u="center"in o,d="center"in o||A.has("left")||A.has("right")||A.has("center"),h="top"in o,m="bottom"in o&&d,f="left"in o&&d,b="right"in o&&d,p=Object.keys(o).length&&("center"in o||d),y=N.createElement("div",{style:{flexGrow:1}}),Z=N.cloneElement(y),B=N.createElement("div",{style:{display:"flex",flexGrow:1}},h&&(p||f)?y:null,N.createElement(iR,{defaultTrackType:o.top,draggingHappening:this.props.draggingHappening,enabled:s,onTrackDropped:S=>this.handleTracksAdded([S],"top"),style:{border:"1px solid black",flexGrow:1}}),h&&(p||f)?Z:null),G=N.createElement("div",{style:{display:"flex",flexGrow:1}},h&&(p||f)?y:null,N.createElement(iR,{defaultTrackType:o.bottom,draggingHappening:this.props.draggingHappening,enabled:c,onTrackDropped:S=>this.handleTracksAdded([S],"bottom"),style:{border:"1px solid black",flexGrow:1}}),h&&(p||f)?Z:null),v=N.createElement(iR,{defaultTrackType:o.left,draggingHappening:this.props.draggingHappening,enabled:a,onTrackDropped:S=>this.handleTracksAdded([S],"left"),style:{border:"1px solid black",flexGrow:1}}),w=N.createElement(iR,{defaultTrackType:o.center,draggingHappening:this.props.draggingHappening,enabled:u,onTrackDropped:S=>this.handleTracksAdded([S],"center"),position:"center",style:{border:"1px solid black",flexGrow:1}}),V=N.cloneElement(v,{defaultTrackType:o.right,enabled:l,onTrackDropped:S=>this.handleTracksAdded([S],"right")});return N.createElement("div",{style:{position:"absolute",left:"0px",top:"0px",width:this.state.width,height:this.state.height}},N.createElement("div",{style:{position:"absolute",width:this.state.width,height:this.state.height,background:"white",opacity:.4}}),N.createElement("div",{style:{width:this.state.width,height:this.state.height,position:"absolute",display:"flex",flexDirection:"column"}},h?B:null,d&&N.createElement("div",{style:{display:"flex",height:h||m?"40%":"100%",width:"100%"}},f?v:null,p?w:null,b?V:null),m?G:null))}},{key:"render",value:function(){this.galleryDim=this.props.tracks.gallery?this.props.tracks.gallery.map(p=>p.height).reduce(Pl,0):0,this.topHeightNoGallery=this.props.tracks.top.map(p=>p.height).reduce(Pl,0),this.topHeight=this.topHeightNoGallery+this.galleryDim,this.bottomHeightNoGallery=this.props.tracks.bottom.map(p=>p.height).reduce(Pl,0),this.bottomHeight=this.bottomHeightNoGallery+this.galleryDim,this.leftWidthNoGallery=this.props.tracks.left.map(p=>p.width).reduce(Pl,0),this.leftWidth=this.leftWidthNoGallery+this.galleryDim,this.rightWidthNoGallery=this.props.tracks.right.map(p=>p.width).reduce(Pl,0),this.rightWidth=this.rightWidthNoGallery+this.galleryDim;const n=this.props.paddingTop+this.props.paddingBottom,C=this.props.paddingLeft+this.props.paddingRight;this.centerHeight=Math.max(0,this.state.height-this.topHeight-this.bottomHeight-n),this.centerWidth=Math.max(0,this.state.width-this.leftWidth-this.rightWidth-C);const r="none",o=N.createElement("div",{className:"top-track-container",style:{left:this.leftWidth+this.props.paddingLeft,top:this.props.paddingTop,width:this.centerWidth,height:this.topHeightNoGallery,outline:r,position:"absolute"}},N.createElement(f2,{configTrackMenuId:this.state.configTrackMenuId,editable:this.props.editable,handleConfigTrack:this.handleConfigTrackMenuOpened.bind(this),handleResizeTrack:this.handleResizeTrack.bind(this),handleSortEnd:this.handleSortEnd.bind(this),is1dRangeSelection:this.state.is1dRangeSelection,isRangeSelectionActive:this.props.mouseTool===Dr,onAddSeries:this.handleAddSeries.bind(this),onCloseTrack:this.handleCloseTrack.bind(this),onCloseTrackMenuOpened:this.handleCloseTrackMenuOpened.bind(this),onConfigTrackMenuOpened:this.handleConfigTrackMenuOpened.bind(this),onRangeSelection:this.rangeSelection1dHandler("x").bind(this),onRangeSelectionEnd:this.rangeSelection1dEndHandler("x").bind(this),onRangeSelectionReset:this.rangeSelectionResetHandler.bind(this),onRangeSelectionStart:this.rangeSelection1dStartHandler.bind(this),rangeSelection:this.state.rangeSelection,rangeSelectionEnd:this.state.rangeSelectionEnd,resizeHandles:new Set(["bottom"]),scale:this.xScale,tracks:this.props.tracks.top,width:this.centerWidth})),A=N.createElement("div",{className:"left-track-container",style:{left:this.props.paddingLeft,top:this.topHeight+this.props.paddingTop,width:this.leftWidthNoGallery,height:this.centerHeight,outline:r,position:"absolute"}},N.createElement(KJ,{configTrackMenuId:this.state.configTrackMenuId,editable:this.props.editable,handleConfigTrack:this.handleConfigTrackMenuOpened.bind(this),handleResizeTrack:this.handleResizeTrack.bind(this),handleSortEnd:this.handleSortEnd.bind(this),height:this.centerHeight,is1dRangeSelection:this.state.is1dRangeSelection,isRangeSelectionActive:this.props.mouseTool===Dr,onAddSeries:this.handleAddSeries.bind(this),onCloseTrack:this.handleCloseTrack.bind(this),onCloseTrackMenuOpened:this.handleCloseTrackMenuOpened.bind(this),onConfigTrackMenuOpened:this.handleConfigTrackMenuOpened.bind(this),onRangeSelection:this.rangeSelection1dHandler("y").bind(this),onRangeSelectionEnd:this.rangeSelection1dEndHandler("y").bind(this),onRangeSelectionReset:this.rangeSelectionResetHandler.bind(this),onRangeSelectionStart:this.rangeSelection1dStartHandler.bind(this),rangeSelection:this.state.rangeSelection,rangeSelectionEnd:this.state.rangeSelectionEnd,resizeHandles:new Set(["right"]),scale:this.yScale,tracks:this.props.tracks.left})),s=N.createElement("div",{className:"right-track-container",style:{right:this.props.paddingRight,top:this.topHeight+this.props.paddingTop,width:this.rightWidthNoGallery,height:this.centerHeight,outline:r,position:"absolute"}},N.createElement(KJ,{configTrackMenuId:this.state.configTrackMenuId,editable:this.props.editable,handleConfigTrack:this.handleConfigTrackMenuOpened.bind(this),handleResizeTrack:this.handleResizeTrack.bind(this),handleSortEnd:this.handleSortEnd.bind(this),height:this.centerHeight,is1dRangeSelection:this.state.is1dRangeSelection,isRangeSelectionActive:this.props.mouseTool===Dr,onAddSeries:this.handleAddSeries.bind(this),onCloseTrack:this.handleCloseTrack.bind(this),onCloseTrackMenuOpened:this.handleCloseTrackMenuOpened.bind(this),onConfigTrackMenuOpened:this.handleConfigTrackMenuOpened.bind(this),onRangeSelection:this.rangeSelection1dHandler("y").bind(this),onRangeSelectionEnd:this.rangeSelection1dEndHandler("y").bind(this),onRangeSelectionReset:this.rangeSelectionResetHandler.bind(this),onRangeSelectionStart:this.rangeSelection1dStartHandler.bind(this),rangeSelection:this.state.rangeSelection,rangeSelectionEnd:this.state.rangeSelectionEnd,resizeHandles:new Set(["left"]),scale:this.yScale,tracks:this.props.tracks.right,tracksControlAlignLeft:!0})),a=N.createElement("div",{className:"bottom-track-container",style:{left:this.leftWidth+this.props.paddingLeft,bottom:this.props.paddingBottom,width:this.centerWidth,height:this.bottomHeightNoGallery,outline:r,position:"absolute"}},N.createElement(f2,{configTrackMenuId:this.state.configTrackMenuId,editable:this.props.editable,handleConfigTrack:this.handleConfigTrackMenuOpened.bind(this),handleResizeTrack:this.handleResizeTrack.bind(this),handleSortEnd:this.handleSortEnd.bind(this),is1dRangeSelection:this.state.is1dRangeSelection,isRangeSelectionActive:this.props.mouseTool===Dr,onAddSeries:this.handleAddSeries.bind(this),onCloseTrack:this.handleCloseTrack.bind(this),onCloseTrackMenuOpened:this.handleCloseTrackMenuOpened.bind(this),onConfigTrackMenuOpened:this.handleConfigTrackMenuOpened.bind(this),onRangeSelection:this.rangeSelection1dHandler("x").bind(this),onRangeSelectionEnd:this.rangeSelection1dEndHandler("x").bind(this),onRangeSelectionReset:this.rangeSelectionResetHandler.bind(this),onRangeSelectionStart:this.rangeSelection1dStartHandler.bind(this),rangeSelection:this.state.rangeSelection,rangeSelectionEnd:this.state.rangeSelectionEnd,resizeHandles:new Set(["top"]),scale:this.xScale,tracks:this.props.tracks.bottom,width:this.centerWidth})),l=N.createElement("div",{key:"galleryTracksDiv",className:"gallery-track-container",style:{left:this.leftWidthNoGallery+this.props.paddingLeft,top:this.topHeightNoGallery+this.props.paddingTop,width:this.centerWidth+2*this.galleryDim,height:this.centerHeight+2*this.galleryDim,outline:r,position:"absolute"}},N.createElement(Fwe,{configTrackMenuId:this.state.configTrackMenuId,editable:this.props.editable,height:this.centerHeight+2*this.galleryDim,onAddSeries:this.handleAddSeries.bind(this),onCloseTrack:this.handleCloseTrack.bind(this),onCloseTrackMenuOpened:this.handleCloseTrackMenuOpened.bind(this),onConfigTrackMenuOpened:this.handleConfigTrackMenuOpened.bind(this),tracks:this.props.tracks.gallery,width:this.centerWidth+2*this.galleryDim}));let c=N.createElement("div",{className:["center-track-container",cz["center-track-container"]].join(" "),style:{left:this.leftWidth+this.props.paddingLeft,top:this.topHeight+this.props.paddingTop,width:this.centerWidth,height:this.bottomHeight,outline:r}});this.props.tracks.center.length&&(c=N.createElement("div",{className:["center-track-container",cz["center-track-container"]].join(" "),style:{left:this.leftWidth+this.props.paddingLeft,top:this.topHeight+this.props.paddingTop,width:this.centerWidth,height:this.centerHeight,outline:r}},N.createElement(nj,{configTrackMenuId:this.state.configTrackMenuId,editable:this.props.editable,height:this.centerHeight,is1dRangeSelection:this.state.is1dRangeSelection,isRangeSelectionActive:this.props.mouseTool===Dr,onAddSeries:this.handleAddSeries.bind(this),onCloseTrackMenuOpened:this.handleCloseTrackMenuOpened.bind(this),onConfigTrackMenuOpened:this.handleConfigTrackMenuOpened.bind(this),onRangeSelectionReset:this.rangeSelectionResetHandler.bind(this),onRangeSelectionStart:this.rangeSelection2dStartHandler.bind(this),onRangeSelectionX:this.rangeSelection1dHandler("x").bind(this),onRangeSelectionXEnd:this.rangeSelection1dEndHandler("x").bind(this),onRangeSelectionXY:this.rangeSelection2dHandler.bind(this),onRangeSelectionXYEnd:this.rangeSelection2dEndHandler.bind(this),onRangeSelectionY:this.rangeSelection1dHandler("y").bind(this),onRangeSelectionYEnd:this.rangeSelection1dEndHandler("y").bind(this),rangeSelection:this.state.rangeSelection,rangeSelectionEnd:this.state.rangeSelectionEnd,scaleX:this.xScale,scaleY:this.yScale,tracks:this.props.tracks.center,uid:this.props.tracks.center[0].uid,width:this.centerWidth}))),this.createTrackPositionTexts();let u=this.positionedTracks();u=u.concat(this.overlayTracks(u));let d=null;this.state.sizeMeasured&&(d=N.createElement(mQt,{ref:p=>{this.trackRenderer=p,this.checkAllTilesetInfoReceived()},canvasElement:this.canvasElement,centerHeight:this.centerHeight,centerWidth:this.centerWidth,disableTrackMenu:this.props.disableTrackMenu,dragging:this.props.dragging,galleryDim:this.galleryDim,getLockGroupExtrema:this.props.getLockGroupExtrema,height:this.state.height,initialXDomain:this.props.initialXDomain,initialYDomain:this.props.initialYDomain,isRangeSelection:this.props.mouseTool===Dr,isShowGlobalMousePosition:this.props.isShowGlobalMousePosition,isValueScaleLocked:this.props.isValueScaleLocked,leftWidth:this.leftWidth,leftWidthNoGallery:this.leftWidthNoGallery,metaTracks:this.props.metaTracks,onMouseMoveZoom:this.props.onMouseMoveZoom,onNewTilesLoaded:this.props.onNewTilesLoaded,onScalesChanged:this.handleScalesChanged.bind(this),onTilesetInfoReceived:this.handleTilesetInfoReceived.bind(this),onTrackOptionsChanged:this.handleTrackOptionsChanged.bind(this),onValueScaleChanged:this.props.onValueScaleChanged,paddingLeft:this.props.paddingLeft,paddingTop:this.props.paddingTop,pixiRenderer:this.props.pixiRenderer,pixiStage:this.props.pixiStage,pluginDataFetchers:this.props.pluginDataFetchers,pluginTracks:this.props.pluginTracks,positionedTracks:u,registerDraggingChangedListener:this.props.registerDraggingChangedListener,removeDraggingChangedListener:this.props.removeDraggingChangedListener,setCentersFunction:this.props.setCentersFunction,svgElement:this.props.svgElement,topHeight:this.topHeight,topHeightNoGallery:this.topHeightNoGallery,uid:this.props.uid,viewOptions:this.props.viewOptions,width:this.state.width,xDomainLimits:this.props.xDomainLimits,yDomainLimits:this.props.yDomainLimits,zoomable:this.props.zoomable,zoomLimits:this.props.zoomLimits},o,A,s,a,l,c));let h=null,m=null;this.state.configTrackMenuId&&(h=N.createElement(Xc,{onMenuClosed:this.closeMenusBound},N.createElement(Ujt,{ref:p=>{this.configTrackMenu=p},closeMenu:this.closeMenusBound,onAddDivisor:this.handleAddDivisorBound,onAddSeries:this.handleAddSeriesBound,onAddTrack:this.handleAddTrackBound,onChangeTrackType:this.handleChangeTrackTypeBound,onCloseTrack:this.handleCloseTrackBound,onConfigureTrack:this.handleConfigureTrackBound,onExportData:this.handleExportTrackDataBound,onLockValueScale:this.handleLockValueScaleBound,onReplaceTrack:this.handleReplaceTrackBound,onTrackOptionsChanged:this.handleTrackOptionsChangedBound,onUnlockValueScale:this.handleUnlockValueScaleBound,position:this.state.configTrackMenuLocation,theme:this.props.theme,trackOrientation:WG(this.props.tracks,this.state.configTrackMenuId),tracks:[jC(this.props.tracks,this.state.configTrackMenuId)]}))),this.state.closeTrackMenuId&&(m=N.createElement(Xc,{onMenuClosed:this.handleCloseTrackMenuClosed.bind(this)},N.createElement(ou,{position:this.state.closeTrackMenuLocation,theme:this.props.theme},N.createElement(nXe,{onCloseTrack:this.handleCloseTrack.bind(this),tracks:[jC(this.props.tracks,this.state.closeTrackMenuId)]}))));let f=null;this.props.chooseTrackHandler&&(f=u.filter(p=>p.track.position!=="whole").map(p=>{let y="transparent",Z="none";return this.state.mouseOverOverlayUid===p.track.uid&&(y="yellow",Z="1px solid black"),N.createElement("div",{key:p.track.uid,className:"tiled-plot-track-overlay",onClick:()=>this.handleTrackPositionChosen(p),onDragEnter:B=>{this.handleOverlayMouseEnter(p.track.uid),B.preventDefault()},onDragLeave:()=>this.handleOverlayMouseLeave(p.track.uid),onDragOver:B=>B.preventDefault(),onDrop:()=>this.handleTrackPositionChosen(p),onMouseEnter:()=>this.handleOverlayMouseEnter(p.track.uid),onMouseLeave:()=>this.handleOverlayMouseLeave(p.track.uid),style:{position:"absolute",left:p.left,top:p.top,width:p.width,height:p.height,background:y,opacity:.4,border:Z,zIndex:1}})}));let b=null;if(this.xScale&&this.yScale&&this.props.editable&&this.state.trackOptions){const p=this.state.trackOptions.configComponent,y=this.state.trackOptions.track;b=N.createElement(p,{track:y,xScale:this.xScale,yScale:this.yScale,onCancel:()=>{this.setState({trackOptions:null})},onTrackOptionsChanged:Z=>Z,onSubmit:Z=>{this.handleTrackOptionsChanged(this.state.trackOptions.track.uid,Z),this.setState({trackOptions:null})}})}return N.createElement("div",{ref:p=>{this.divTiledPlot=p},className:["tiled-plot-div",Eo["tiled-plot"]].join(" "),style:{marginBottom:this.props.marginBottom,marginLeft:this.props.marginLeft,marginRight:this.props.marginRight,marginTop:this.props.marginTop}},d,f,h,m,b,this.getContextMenu(),this.props.draggingHappening&&this.getIdealizedTrackPositionsOverlay())}},{key:"addEventListeners",value:function(){this.eventListeners=[],this.eventListeners.forEach(n=>document.addEventListener(n.name,n.callback,!1))}},{key:"removeEventListeners",value:function(){this.eventListeners.forEach(n=>document.removeEventListener(n.name,n.callback))}}]),I}(N.Component);X4.defaultProps={isShowGlobalMousePosition:!1,pluginDataFetchers:{},pluginTracks:{},metaTracks:[],zoomable:!0};X4.propTypes={addTrackPosition:L.string,canvasElement:L.object,chooseTrackHandler:L.func,chromInfoPath:L.string,customDialog:L.array,closeCustomDialog:L.func,disableTrackMenu:L.bool,dragging:L.bool,draggingHappening:L.bool,editable:L.bool,getLockGroupExtrema:L.func,initialXDomain:L.array,initialYDomain:L.array,isShowGlobalMousePosition:L.bool,isValueScaleLocked:L.func,marginBottom:L.number.isRequired,marginLeft:L.number.isRequired,marginRight:L.number.isRequired,marginTop:L.number.isRequired,paddingBottom:L.number.isRequired,paddingLeft:L.number.isRequired,paddingRight:L.number.isRequired,paddingTop:L.number.isRequired,metaTracks:L.array,modal:L.object,mouseTool:L.string,onCloseTrack:L.func,onChangeTrackData:L.func,onChangeTrackType:L.func,onDataDomainChanged:L.func,onLockValueScale:L.func,onMouseMoveZoom:L.func,onNewTilesLoaded:L.func,onNoTrackAdded:L.func,onRangeSelection:L.func.isRequired,onScalesChanged:L.func,onTrackOptionsChanged:L.func,onTrackPositionChosen:L.func,onTracksAdded:L.func,onUnlockValueScale:L.func,onValueScaleChanged:L.func,onResizeTrack:L.func,overlays:L.array,openModal:L.func,pixiRenderer:L.object,pixiStage:L.object,pluginDataFetchers:L.object,pluginTracks:L.object,pubSub:L.object.isRequired,rangeSelection1dSize:L.array,rangeSelectionToInt:L.bool,registerDraggingChangedListener:L.func,removeDraggingChangedListener:L.func,setCentersFunction:L.func,svgElement:L.object,theme:L.symbol.isRequired,tracks:L.object,trackSourceServers:L.array,uid:L.string,viewOptions:L.object,xDomainLimits:L.array,yDomainLimits:L.array,zoomable:L.bool,zoomLimits:L.array,zoomToDataExtentOnInit:L.func};const X4t=M0(uk(im(X4)));var H4t=Object.assign||function(e){for(var g=1;g"u"?"undefined":T4t(g))==="object"){for(var n in g)g.hasOwnProperty(n)&&Ep(e,n,g[n]);return}if(typeof i<"u"){typeof i=="number"&&(i+="px"),e.style[g]=i;return}return Sh(e,g)}H4(["width","height"],function(e){var g=e.charAt(0).toUpperCase()+e.slice(1);ea["outer"+g]=function(i,n){return i&&wae(i,e,n?z4t:zJ)};var I=e==="width"?["Left","Right"]:["Top","Bottom"];ea[e]=function(i,n){if(n!==void 0){if(i){Sh(i);var C=AXe(i);return C&&(n+=$Z(i,["padding","border"],I)),Ep(i,e,n)}return}return i&&wae(i,e,MJ)}});function O4t(e,g){Ep(e,"position")==="static"&&(e.style.position="relative");var I=oXe(e),i={},n=void 0,C=void 0;for(C in g)g.hasOwnProperty(C)&&(n=parseFloat(Ep(e,C))||0,i[C]=n+g[C]-I[C]);Ep(e,i)}var _4t=H4t({getWindow:function(g){var I=g.ownerDocument||g;return I.defaultView||I.parentWindow},offset:function(g,I){if(typeof I<"u")O4t(g,I);else return oXe(g)},isWindow:sW,each:H4,css:Ep,clone:function(g){var I={};for(var i in g)g.hasOwnProperty(i)&&(I[i]=g[i]);var n=g.overflow;if(n)for(var i in g)g.hasOwnProperty(i)&&(I.overflow[i]=g.overflow[i]);return I},scrollLeft:function(g,I){if(sW(g)){if(I===void 0)return FJ(g);window.scrollTo(I,EJ(g))}else{if(I===void 0)return g.scrollLeft;g.scrollLeft=I}},scrollTop:function(g,I){if(sW(g)){if(I===void 0)return EJ(g);window.scrollTo(FJ(g),I)}else{if(I===void 0)return g.scrollTop;g.scrollTop=I}},viewportWidth:0,viewportHeight:0},ea),eI=_4t;function L4t(e,g,I){I=I||{},g.nodeType===9&&(g=eI.getWindow(g));var i=I.allowHorizontalScroll,n=I.onlyScrollIfNeeded,C=I.alignWithTop,r=I.alignWithLeft,o=I.offsetTop||0,A=I.offsetLeft||0,s=I.offsetBottom||0,a=I.offsetRight||0;i=i===void 0?!0:i;var l=eI.isWindow(g),c=eI.offset(e),u=eI.outerHeight(e),d=eI.outerWidth(e),h=void 0,m=void 0,f=void 0,b=void 0,p=void 0,y=void 0,Z=void 0,B=void 0,G=void 0,v=void 0;l?(Z=g,v=eI.height(Z),G=eI.width(Z),B={left:eI.scrollLeft(Z),top:eI.scrollTop(Z)},p={left:c.left-B.left-A,top:c.top-B.top-o},y={left:c.left+d-(B.left+G)+a,top:c.top+u-(B.top+v)+s},b=B):(h=eI.offset(g),m=g.clientHeight,f=g.clientWidth,b={left:g.scrollLeft,top:g.scrollTop},p={left:c.left-(h.left+(parseFloat(eI.css(g,"borderLeftWidth"))||0))-A,top:c.top-(h.top+(parseFloat(eI.css(g,"borderTopWidth"))||0))-o},y={left:c.left+d-(h.left+f+(parseFloat(eI.css(g,"borderRightWidth"))||0))+a,top:c.top+u-(h.top+m+(parseFloat(eI.css(g,"borderBottomWidth"))||0))+s}),p.top<0||y.top>0?C===!0?eI.scrollTop(g,b.top+p.top):C===!1?eI.scrollTop(g,b.top+y.top):p.top<0?eI.scrollTop(g,b.top+p.top):eI.scrollTop(g,b.top+y.top):n||(C=C===void 0?!0:!!C,C?eI.scrollTop(g,b.top+p.top):eI.scrollTop(g,b.top+y.top)),i&&(p.left<0||y.left>0?r===!0?eI.scrollLeft(g,b.left+p.left):r===!1?eI.scrollLeft(g,b.left+y.left):p.left<0?eI.scrollLeft(g,b.left+p.left):eI.scrollLeft(g,b.left+y.left):n||(r=r===void 0?!0:!!r,r?eI.scrollLeft(g,b.left+p.left):eI.scrollLeft(g,b.left+y.left)))}var U4t=L4t,Q4t=U4t;const j4t=DC(Q4t);function M2(){return M2=Object.assign?Object.assign.bind():function(e){for(var g=1;g"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function z2(e){return z2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},z2(e)}const CZ=[];let T4=function(e){g$t(I,e);var g=I$t(I);function I(i){var n;return $4t(this,I),n=g.call(this,i),n.state={highlightedIndex:null,menuTop:0,menuLeft:0,menuWidth:0,isOpen:!1},n.keyDownHandlers={ArrowDown(C){C.preventDefault();const r=this.getFilteredItems().length;if(!r)return;const{highlightedIndex:o}=this.state,A=o===null||o===r-1?0:o+1;this._performAutoCompleteOnKeyUp=!0,this.setState({highlightedIndex:A,isOpen:!0})},ArrowUp(C){C.preventDefault();const r=this.getFilteredItems().length;if(!r)return;const{highlightedIndex:o}=this.state,A=o===0||o===null?r-1:o-1;this._performAutoCompleteOnKeyUp=!0,this.setState({highlightedIndex:A,isOpen:!0})},Enter(C){if(this.state.isOpen!==!1)if(this.state.highlightedIndex===null)this.setState({isOpen:!1},()=>{this.inputEl.select()});else{C.preventDefault();const r=this.getFilteredItems()[this.state.highlightedIndex],o=this.props.getItemValue(r);this.setState({isOpen:!1,highlightedIndex:null},()=>{this.inputEl.setSelectionRange(o.length,o.length),this.props.onSelect(o,r)})}},Escape(){this.setState({highlightedIndex:null,isOpen:!1})}},n}return q4t(I,[{key:"getInitialState",value:function(){return{isOpen:!1,highlightedIndex:null}}},{key:"UNSAFE_componentWillMount",value:function(){this._ignoreBlur=!1,this._performAutoCompleteOnUpdate=!1,this._performAutoCompleteOnKeyUp=!1}},{key:"UNSAFE_componentWillReceiveProps",value:function(n){this._performAutoCompleteOnUpdate=!0,(this.props.items!==n.items||this.state.highlightedIndex>=n.items.length)&&this.setState({highlightedIndex:null})}},{key:"componentDidUpdate",value:function(n,C){this.state.isOpen===!0&&C.isOpen===!1&&this.setMenuPositions(),this.state.isOpen&&this._performAutoCompleteOnUpdate&&(this._performAutoCompleteOnUpdate=!1,this.maybeAutoCompleteText()),this.maybeScrollItemIntoView(),C.isOpen!==this.state.isOpen&&this.props.onMenuVisibilityChange(this.state.isOpen,this.inputEl)}},{key:"maybeScrollItemIntoView",value:function(){if(this.state.isOpen===!0&&this.state.highlightedIndex!==null){const n=this.refs[`item-${this.state.highlightedIndex}`],C=this.refs.menu;n&&j4t(Rs.findDOMNode(n),Rs.findDOMNode(C),{onlyScrollIfNeeded:!0})}}},{key:"handleKeyDown",value:function(n){this.keyDownHandlers[n.key]?this.keyDownHandlers[n.key].call(this,n):this.setState({highlightedIndex:null,isOpen:!0})}},{key:"handleChange",value:function(n){this._performAutoCompleteOnKeyUp=!0,this.props.onChange(n,n.target.value)}},{key:"handleKeyUp",value:function(){this._performAutoCompleteOnKeyUp&&(this._performAutoCompleteOnKeyUp=!1,this.maybeAutoCompleteText())}},{key:"getFilteredItems",value:function(){let n=this.props.items;return this.props.shouldItemRender&&(n=n.filter(C=>this.props.shouldItemRender(C,this.props.value))),this.props.sortItems&&n.sort((C,r)=>this.props.sortItems(C,r,this.props.value)),n}},{key:"maybeAutoCompleteText",value:function(){if(!this.props.autoHighlight||this.props.value==="")return;const{highlightedIndex:n}=this.state,C=this.getFilteredItems();if(C.length===0)return;const r=n!==null?C[n]:C[0];this.props.getItemValue(r).toLowerCase().indexOf(this.props.value.toLowerCase())===0&&n===null&&this.setState({highlightedIndex:0})}},{key:"setMenuPositions",value:function(){const n=this.inputEl,C=n.getBoundingClientRect(),r=globalThis.window.getComputedStyle(n),o=parseInt(r.marginBottom,10)||0,A=parseInt(r.marginLeft,10)||0,s=parseInt(r.marginRight,10)||0;this.setState({menuTop:C.bottom+o,menuLeft:C.left+A,menuWidth:C.width+A+s})}},{key:"highlightItemFromMouse",value:function(n){this.setState({highlightedIndex:n})}},{key:"selectItemFromMouse",value:function(n){const C=this.props.getItemValue(n);this.setState({isOpen:!1,highlightedIndex:null},()=>{this.props.onSelect(C,n),this.inputEl.focus()})}},{key:"setIgnoreBlur",value:function(n){this._ignoreBlur=n}},{key:"renderMenu",value:function(){const n=this.getFilteredItems().map((o,A)=>{const s=this.props.renderItem(o,this.state.highlightedIndex===A,{cursor:"default"});return N.cloneElement(s,{onMouseDown:()=>this.setIgnoreBlur(!0),onMouseEnter:()=>this.highlightItemFromMouse(A),onClick:()=>this.selectItemFromMouse(o),ref:`item-${A}`})}),C={left:this.state.menuLeft,top:this.state.menuTop,minWidth:this.state.menuWidth};if(!n.length)return null;const r=this.props.renderMenu(n,this.props.value,C);return N.cloneElement(r,{ref:"menu"})}},{key:"handleInputBlur",value:function(){this.props.onFocus&&this.props.onFocus(),!this._ignoreBlur&&this.setState({isOpen:!1,highlightedIndex:null})}},{key:"handleInputFocus",value:function(){if(this.props.onFocus&&this.props.onFocus(!0),this._ignoreBlur){this.setIgnoreBlur(!1);return}this._ignoreClick=!0,this.setState({isOpen:!0})}},{key:"isInputFocused",value:function(){return this.inputEl.ownerDocument&&this.inputEl===this.inputEl.ownerDocument.activeElement}},{key:"handleInputClick",value:function(){this.isInputFocused()&&this.state.isOpen===!1?this.setState({isOpen:!0}):this.state.highlightedIndex!==null&&!this._ignoreClick&&this.selectItemFromMouse(this.getFilteredItems()[this.state.highlightedIndex]),this._ignoreClick=!1}},{key:"composeEventHandlers",value:function(n,C){return C?r=>{n(r),C(r)}:n}},{key:"render",value:function(){this.props.debug&&CZ.push({id:CZ.length,state:this.state});const{inputProps:n}=this.props;return N.createElement("div",M2({style:{...this.props.wrapperStyle}},this.props.wrapperProps),N.createElement("input",M2({},n,{ref:C=>{this.inputEl=C},"aria-autocomplete":"list",autoComplete:"off",onBlur:this.composeEventHandlers(this.handleInputBlur.bind(this),n.onBlur&&n.onBlur.bind(this)),onChange:this.handleChange.bind(this),onClick:this.composeEventHandlers(this.handleInputClick.bind(this),n.onClick&&n.onClick.bind(this)),onFocus:this.composeEventHandlers(this.handleInputFocus.bind(this),n.onFocus&&n.onFocus.bind(this)),onKeyDown:this.composeEventHandlers(this.handleKeyDown.bind(this),n.onKeyDown&&n.onKeyDown.bind(this)),onKeyUp:this.composeEventHandlers(this.handleKeyUp.bind(this),n.onKeyUp&&n.onKeyUp.bind(this)),role:"combobox",value:this.props.value})),("open"in this.props?this.props.open:this.state.isOpen)&&this.renderMenu(),this.props.debug&&N.createElement("pre",{style:{marginLeft:300}},JSON.stringify(CZ.slice(CZ.length-5,CZ.length),null,2)))}}]),I}(N.Component);T4.defaultProps={value:"",wrapperProps:{},wrapperStyle:{display:"inline-block"},inputProps:{},onChange(){},onSelect(){},renderMenu(e,g,I){return N.createElement("div",{style:{...I,...this.menuStyle}},e)},shouldItemRender(){return!0},menuStyle:{borderRadius:"3px",boxShadow:"0 2px 12px rgba(0, 0, 0, 0.1)",background:"rgba(255, 255, 255, 0.9)",padding:"2px 0",fontSize:"90%",position:"fixed",overflow:"auto",maxHeight:"50%"},autoHighlight:!0,onMenuVisibilityChange(){}};T4.propTypes={autoHighlight:L.bool,debug:L.bool,getItemValue:L.func.isRequired,inputProps:L.object,items:L.array,menuStyle:L.object,onChange:L.func,onFocus:L.func,onMenuVisibilityChange:L.func,onSelect:L.func,open:L.bool,renderItem:L.func.isRequired,renderMenu:L.func,shouldItemRender:L.func,sortItems:L.func,value:L.any,wrapperProps:L.object,wrapperStyle:L.object};const r$t="_btn_1l2sx_95",Um={"genome-position-search":"_genome-position-search_1l2sx_1","genome-position-search-focus":"_genome-position-search-focus_1l2sx_2","genome-position-search-bar":"_genome-position-search-bar_1l2sx_16","genome-position-search-dark":"_genome-position-search-dark_1l2sx_34","genome-position-search-bar-button":"_genome-position-search-bar-button_1l2sx_38","genome-position-search-bar-button-focus":"_genome-position-search-bar-button-focus_1l2sx_39","genome-position-search-bar-icon":"_genome-position-search-bar-icon_1l2sx_62","genome-position-search-bar-icon-focus":"_genome-position-search-bar-icon-focus_1l2sx_63","genome-position-search-bar-suggestions":"_genome-position-search-bar-suggestions_1l2sx_83",btn:r$t,"btn-sm":"_btn-sm_1l2sx_116","btn-default":"_btn-default_1l2sx_122"};function o$t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function Rae(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function P2(e){return P2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},P2(e)}let sXe=function(e){l$t(I,e);var g=c$t(I);function I(i){var n;return o$t(this,I),n=g.call(this,i),n.mounted=!1,n.uid=Ag.nice(),n.chromInfo=null,n.searchField=null,n.autocompleteMenu=null,n.xScale=null,n.yScale=null,n.prevParts=[],n.props.registerViewportChangedListener(n.scalesChanged.bind(aXe(n))),n.menuPosition={left:0,top:0},n.positionText="chr4:190,998,876-191,000,255",n.state={genes:[],isFocused:!1,autocompleteServer:n.props.autocompleteServer,autocompleteId:n.props.autocompleteId,availableAssemblies:[],selectedAssembly:null},n.styles={item:{padding:"2px 6px",cursor:"default"},highlightedItem:{color:"white",background:"hsl(200, 50%, 50%)",padding:"2px 6px",cursor:"default"},menu:{border:"solid 1px #ccc"}},n.availableAutocompletes={},n.props.autocompleteId&&(n.availableAutocompletes[n.props.chromInfoId]=new Set([{server:n.props.autocompleteServer,acId:n.props.autocompleteId}])),n.availableChromSizes={},n}return A$t(I,[{key:"componentDidMount",value:function(){this.mounted=!0,cg(this.autocompleteMenu.inputEl).on("keypress",this.autocompleteKeyPress.bind(this)),this.findAvailableAutocompleteSources(),this.findAvailableChromSizes(),this.props.chromInfoPath&&(this.searchPosition=!0,xs(this.props.chromInfoPath,n=>{if(!n){this.searchPosition=null;return}this.chromInfo=n,this.searchField=new Lb(this.chromInfo),this.setPositionText()})),this.setPositionText()}},{key:"componentWillUnmount",value:function(){this.mounted=!1,this.props.removeViewportChangedListener()}},{key:"onAutocompleteChange",value:function(n,C){this.positionText=C,this.setState({value:C,loading:!0}),this.changedPart=null;const r=C.split(/ /);let o=0;const A=[];let s=!1;for(let a=0;a{if(l)this.setState({loading:!1,genes:[]});else if(this.changedPart>0&&!s){const u=`${this.state.autocompleteServer}/suggest/?d=${this.state.autocompleteId}&ac=${A[this.changedPart-1].toLowerCase()}-${A[this.changedPart].toLowerCase()}`;Gt.json(u,(d,h)=>{d?this.setState({loading:!1,genes:c}):this.setState({loading:!1,genes:h.concat(c)})},this.props.pubSub)}else this.setState({loading:!1,genes:c})},this.props.pubSub)}}},{key:"setAvailableAssemblies",value:function(){const n=new Set(Br(this.availableChromSizes)),C=new Set([...n]);this.gpsbForm&&this.setState({availableAssemblies:[...C]})}},{key:"setSelectedAssembly",value:function(n){if(!this.mounted||!this.availableChromSizes[n])return;const C=[...this.availableChromSizes[n]][0];this.setState({autocompleteServer:C.server});const{server:r}=C;if(this.availableAutocompletes[n]){const o=[...this.availableAutocompletes[n]][0].acId;this.props.onSelectedAssemblyChanged(n,o,r),this.gpsbForm&&this.setState({autocompleteId:o})}else this.props.onSelectedAssemblyChanged(n,null,r),this.gpsbForm&&this.setState({autocompleteId:null});this.fetchChromInfo(C.uuid,C.server)}},{key:"setPositionText",value:function(){if(!this.mounted||!this.searchField)return;const n=this.searchField.scalesToPositionText(this.xScale,this.yScale,this.props.twoD);this.prevParts=n.split(/[ -]/),this.gpsbForm&&(this.positionText=n,this.origPositionText=n,this.autocompleteMenu.inputEl.value=n)}},{key:"scalesChanged",value:function(n,C){this.xScale=n,this.yScale=C,this.setPositionText()}},{key:"findAvailableChromSizes",value:function(){this.props.trackSourceServers&&this.props.trackSourceServers.forEach(n=>{Gt.json(`${n}/available-chrom-sizes/`,(C,r)=>{C?console.error(C):(r.results.forEach(o=>{o.coordSystem in this.availableChromSizes||(this.availableChromSizes[o.coordSystem]=new Set),this.availableChromSizes[o.coordSystem].add({server:n,uuid:o.uuid}),this.setAvailableAssemblies()}),this.searchField||this.fetchChromInfo(this.props.chromInfoId in this.availableChromSizes?[...this.availableChromSizes[this.props.chromInfoId]][0].uuid:this.props.chromInfoId,this.props.chromInfoId in this.availableChromSizes?[...this.availableChromSizes[this.props.chromInfoId]][0].server:this.props.chromInfoServer))},this.props.pubSub)})}},{key:"findAvailableAutocompleteSources",value:function(){this.props.trackSourceServers&&this.props.trackSourceServers.forEach(n=>{Gt.json(`${n}/tilesets/?limit=100&dt=gene-annotation`,(C,r)=>{C?console.error(C):(r.results.forEach(o=>{o.coordSystem in this.availableAutocompletes||(this.availableAutocompletes[o.coordSystem]=new Set),this.availableAutocompletes[o.coordSystem].add({server:n,acId:o.uuid}),this.setAvailableAssemblies()}),this.state.autocompleteId||this.gpsbForm&&this.availableAutocompletes[this.props.chromInfoId]&&this.setState({autocompleteId:[...this.availableAutocompletes[this.props.chromInfoId]][0].acId}))},this.props.pubSub)})}},{key:"fetchChromInfo",value:function(n,C){xs(`${C}/chrom-sizes/?id=${n}`,r=>{r&&(Gt.json(`${C}/tileset_info/?d=${n}`,(o,A)=>{o||this.gpsbForm&&this.setState({selectedAssembly:A[n].coordSystem})},this.props.pubSub),this.chromInfo=r,this.searchField=new Lb(this.chromInfo),this.setPositionText())},this.props.pubSub)}},{key:"autocompleteKeyPress",value:function(n){n.keyCode===13&&this.buttonClick()}},{key:"genePositionToSearchBarText",value:function(n){}},{key:"replaceGenesWithLoadedPositions",value:function(n){const C=this.positionText,r=C.split(" ");let o=!1;for(let s=0;sl;){const d=a.slice(l,c).join("-");if(n[d.toLowerCase()]){const h=n[d.toLowerCase()],m=Math.floor((h.txEnd-h.txStart)/4);l===0&&c{if(o){const A={};for(let a=0;aconsole.error(o))}},{key:"buttonClick",value:function(){this.setState({genes:[]}),this.replaceGenesWithPositions(n=>{const C=this.positionText;if(this.searchField!==null){const r=this.searchField.searchPosition(C),o=r[0];let A=r[1];if(!o){this.setPositionText();return}if(o&&(Number.isNaN(+o[0])||Number.isNaN(+o[1]))||A&&(Number.isNaN(+A[0])||Number.isNaN(+A[1])))return;A||(A=o);const s=this.xScale.copy().domain(o),a=this.yScale.copy().domain(A),[l,c,u]=yi(s,a);n&&this.props.onGeneSearch({geneSymbol:n,range:o,centerX:l,centerY:c}),this.props.setCenters(l,c,u,mZe)}})}},{key:"searchFieldSubmit",value:function(){this.buttonClick()}},{key:"pathJoin",value:function(n,C){const r=C||"/",o=new RegExp(`${r}{1,}`,"g");return n.join(r).replace(o,r)}},{key:"geneSelected",value:function(n,C){const r=this.positionText.split(" ");let o=this.changedPart;for(let A=0;As.length-1)o-=s.length;else{if(s[o]=C.geneName,a.length===2&&o>0&&s[o-1].toLowerCase()===a[0].toLowerCase()){const l=s.slice(0,o-1);l.push(a.join("-")),oN.createElement("option",{key:C,value:C},C));return N.createElement("div",{ref:C=>{this.gpsbForm=C},className:Vg({[Um["genome-position-search-focus"]]:this.state.isFocused,[Um["genome-position-search"]]:!this.state.isFocused,[Um["genome-position-search-dark"]]:this.props.theme===qg})},!this.props.hideAvailableAssemblies&&N.createElement("select",{ref:C=>{this.assemblyPickButton=C},className:Um["genome-position-search-bar-button"],id:this.uid,onChange:this.handleAssemblySelectEvt.bind(this),value:this.state.selectedAssembly||void 0},n),N.createElement(T4,{ref:C=>{this.autocompleteMenu=C},getItemValue:C=>C.geneName,inputProps:{className:Um["genome-position-search-bar"],title:"Current location: enter a symbol or location to change the position of the current view"},items:this.state.genes,menuStyle:{position:"absolute",left:this.menuPosition.left,top:this.menuPosition.top,border:"1px solid black"},onChange:this.onAutocompleteChange.bind(this),onFocus:this.focusHandler.bind(this),onMenuVisibilityChange:this.handleMenuVisibilityChange.bind(this),onSelect:(C,r)=>this.geneSelected(C,r),onSubmit:this.searchFieldSubmit.bind(this),renderItem:(C,r)=>N.createElement("div",{key:C.refseqid,id:C.refseqid,style:r?this.styles.highlightedItem:this.styles.item},C.geneName),renderMenu:this.handleRenderMenu.bind(this),value:this.state.selectedAssembly?this.positionText:"No valid assembly selected",wrapperStyle:{width:"100%"}}),N.createElement(vZe,{onClick:this.buttonClick.bind(this),theStyle:"multitrack-header-icon"}))}}]),I}(N.Component);sXe.propTypes={autocompleteId:L.string,autocompleteServer:L.string,chromInfoId:L.string,chromInfoServer:L.string,chromInfoPath:L.string,hideAvailableAssemblies:L.bool,isFocused:L.bool,pubSub:L.object,onFocus:L.func,onGeneSearch:L.func,onSelectedAssemblyChanged:L.func,registerViewportChangedListener:L.func,removeViewportChangedListener:L.func,setCenters:L.func,theme:L.symbol.isRequired,trackSourceServers:L.array,twoD:L.bool};const h$t=M0(im(sXe)),m$t={"export-link-dialog-wrapper":"_export-link-dialog-wrapper_p9gxw_1"};function f$t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function Wae(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function J2(e){return J2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},J2(e)}let N4=function(e){Z$t(I,e);var g=G$t(I);function I(){return f$t(this,I),g.apply(this,arguments)}return p$t(I,[{key:"render",value:function(){return N.createElement(Iw,{okayOnly:!0,okayTitle:"Done",onOkay:this.props.onDone,title:"Share view link"},N.createElement("div",{className:m$t["export-link-dialog-wrapper"]},N.createElement("input",{ref:n=>{n&&(this.input=n,n.focus(),n.select())},onClick:n=>{n.target.select()},placeholder:"Generating the link...",readOnly:!0,value:this.props.url}),N.createElement(vs,{onClick:n=>{this.input.select(),document.execCommand("copy")}},"Copy")))}}]),I}(N.Component);N4.defaultProps={onDone:()=>{},url:""};N4.propTypes={onDone:L.func,url:L.string};function w$t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function Xae(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function O2(e){return O2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},O2(e)}let lXe=function(e){X$t(I,e);var g=H$t(I);function I(i){var n;return w$t(this,I),n=g.call(this,i),n.state={submenuShown:!1},n}return V$t(I,[{key:"getConfigureViewMenu",value:function(n,C){const r=["backgroundColor"],o={},A={};for(const s of r)if(s in Object.keys(In)&&(o[s]={name:In[s].name},In[s].inlineOptions))for(const a in In[s].inlineOptions){const l=In[s].inlineOptions[a];o[s].children||(o[s].children={});const c={name:l.name,value:l.value};c.handler=()=>{A[s]=l.value,this.props.onOptionsChanged(A)},o[s].children[a]=c}return N.createElement(XJ,{key:"config-series-menu",closeMenu:this.props.closeMenu,menuItems:o,orientation:this.state.orientation,parentBbox:C,position:n,theme:this.props.theme})}},{key:"getSubmenu",value:function(){if(this.state.submenuShown){const n=this.state.submenuSourceBbox,C=this.state.orientation==="left"?{left:this.state.left,top:n.top}:{left:this.state.left+n.width+7,top:n.top};return this.state.submenuShown.option==="options"?this.getConfigureViewMenu(C,n):N.createElement("div",null)}return N.createElement("div",null)}},{key:"render",value:function(){return N.createElement("div",{ref:n=>{this.div=n},className:Vg(Ut["context-menu"],{[Ut["context-menu-dark"]]:this.props.theme===qg}),"data-menu-type":"ConfigViewMenu",style:{left:this.state.left,top:this.state.top}},N.createElement(tg,{onClick:n=>this.props.onTogglePositionSearchBox(n)},"Toggle position search box"),N.createElement("hr",{className:Ut["context-menu-hr"]}),N.createElement(tg,{onClick:n=>this.props.onZoomToData(n)},"Zoom to data extent"),N.createElement(tg,{onClick:n=>this.props.onClearView(n)},"Clear View"),N.createElement("hr",{className:Ut["context-menu-hr"]}),N.createElement(tg,{onClick:n=>this.props.onYankZoom(n)},"Take zoom from"),N.createElement(tg,{onClick:n=>this.props.onYankLocation(n)},"Take location from"),N.createElement(tg,{onClick:n=>this.props.onYankZoomAndLocation(n)},"Take zoom and location from"),N.createElement("hr",{className:Ut["context-menu-hr"]}),N.createElement(tg,{onClick:this.props.onLockZoom},"Lock zoom with"),N.createElement(tg,{onClick:this.props.onLockLocation},"Lock location with"),N.createElement(tg,{onClick:this.props.onLockZoomAndLocation},"Lock zoom and location with"),N.createElement("hr",{className:Ut["context-menu-hr"]}),N.createElement(tg,{onClick:this.props.onTakeAndLockZoomAndLocation},"Take and lock zoom and location with"),N.createElement("hr",{className:Ut["context-menu-hr"]}),N.createElement(tg,{onClick:n=>this.props.onUnlockZoom(n)},"Unlock zoom"),N.createElement(tg,{onClick:n=>this.props.onUnlockLocation(n)},"Unlock location"),N.createElement(tg,{onClick:n=>this.props.onUnlockZoomAndLocation(n)},"Unlock zoom and location"),N.createElement("hr",{className:Ut["context-menu-hr"]}),N.createElement(tg,{onClick:n=>this.props.onProjectViewport(n)},"Show this viewport on"),N.createElement("hr",{className:Ut["context-menu-hr"]}),N.createElement(tg,{onClick:n=>this.props.onEditViewConfig(n)},"Edit view config"),N.createElement("hr",{className:Ut["context-menu-hr"]}),N.createElement(tg,{onClick:()=>this.props.onExportSVG()},"Export views as SVG"),N.createElement(tg,{onClick:()=>this.props.onExportPNG()},"Export views as PNG"),N.createElement(tg,{onClick:()=>this.props.onExportViewAsJSON()},"Export views as JSON"),N.createElement(tg,{onClick:()=>this.props.onExportViewAsLink()},"Export views as Link"),this.getSubmenu())}}]),I}(ou);lXe.propTypes={onEditViewConfig:L.func.isRequired,onExportSVG:L.func,onExportPNG:L.func,onExportViewAsJSON:L.func,onExportViewAsLink:L.func,onLockLocation:L.func,onLockZoom:L.func,onLockZoomAndLocation:L.func,onProjectViewport:L.func,onTakeAndLockZoomAndLocation:L.func,onTogglePositionSearchBox:L.func,onUnlockLocation:L.func,onUnlockZoom:L.func,onUnlockZoomAndLocation:L.func,onYankLocation:L.func,onYankZoom:L.func,onYankZoomAndLocation:L.func,onZoomToData:L.func,theme:L.symbol};const yr={"add-track-position-table":"_add-track-position-table_wdy5w_1","add-track-position-table-dark":"_add-track-position-table-dark_wdy5w_7","add-track-position-other":"_add-track-position-other_wdy5w_11","add-track-position-top-center":"_add-track-position-top-center_wdy5w_15","add-track-position-middle-left":"_add-track-position-middle-left_wdy5w_30","add-track-position-middle-right":"_add-track-position-middle-right_wdy5w_45","add-track-position-middle-middle":"_add-track-position-middle-middle_wdy5w_60","add-track-position-bottom-middle":"_add-track-position-bottom-middle_wdy5w_71","add-track-position-span":"_add-track-position-span_wdy5w_86"};function cXe(e){return N.createElement("div",null,N.createElement("div",{className:yr["add-track-position-span"]},"Add Track..."),N.createElement("table",{className:Vg(yr["add-track-position-table"],{[yr["add-track-position-table-dark"]]:e.theme===qg})},N.createElement("tbody",null,N.createElement("tr",{style:{height:"30px"}},N.createElement("td",{"aria-hidden":"true",className:yr["add-track-position-other"]}),N.createElement("td",{className:yr["add-track-position-top-center"],onClick:()=>e.onTrackPositionChosen("top")},"top"),N.createElement("td",{"aria-hidden":"true",className:yr["add-track-position-other"]})),N.createElement("tr",{style:{height:"80px"}},N.createElement("td",{className:yr["add-track-position-middle-left"],onClick:()=>e.onTrackPositionChosen("left")},"left"),N.createElement("td",{className:yr["add-track-position-middle-middle"],onClick:()=>e.onTrackPositionChosen("center")},"center"),N.createElement("td",{className:yr["add-track-position-middle-right"],onClick:()=>e.onTrackPositionChosen("right")},"right")),N.createElement("tr",{style:{height:"30px"}},N.createElement("td",{"aria-hidden":"true",className:yr["add-track-position-other"]}),N.createElement("td",{className:yr["add-track-position-bottom-middle"],onClick:()=>e.onTrackPositionChosen("bottom")},"bottom"),N.createElement("td",{"aria-hidden":"true",className:yr["add-track-position-other"]})))))}cXe.propTypes={onTrackPositionChosen:L.func.isRequired,theme:L.symbol.isRequired};const Y$t=im(cXe);function K$t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function Hae(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function _2(e){return _2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},_2(e)}let k4=function(e){E$t(I,e);var g=M$t(I);function I(i){var n;return K$t(this,I),n=g.call(this,i),n.configImg=null,n.plusImg=null,n.state={addTrackPositionMenuUid:null,addTrackPositionMenuPosition:null,configMenuUid:null,configMenuPosition:null,isFocused:!1,width:-1},n.handleTrackPositionChosenBound=n.handleTrackPositionChosen.bind(uXe(n)),n}return D$t(I,[{key:"componentDidMount",value:function(){this.setState({width:this.el.clientWidth})}},{key:"checkWidth",value:function(){const n=this.el.clientWidth;n!==this.state.width&&this.setState({width:n})}},{key:"handleConfigMenuOpened",value:function(n){this.setState({configMenuUid:n,configMenuPosition:this.configImg.getBoundingClientRect()})}},{key:"handleAddTrackPositionMenuOpened",value:function(n){this.setState({addTrackPositionMenuUid:n,addTrackPositionMenuPosition:this.plusImg.getBoundingClientRect()})}},{key:"handleTrackPositionChosen",value:function(n){this.props.onTrackPositionChosen(n),this.setState({addTrackPositionMenuUid:null,addTrackPositionMenuPosition:null})}},{key:"render",value:function(){let n=null,C=null;this.state.addTrackPositionMenuPosition&&(C=N.createElement(Xc,{onMenuClosed:()=>{this.setState({addTrackPositionMenuUid:null,addTrackPositionMenuPosition:null})}},N.createElement(ou,{orientation:"left",position:this.state.addTrackPositionMenuPosition,theme:this.props.theme},N.createElement(Y$t,{onTrackPositionChosen:this.handleTrackPositionChosenBound})))),this.state.configMenuUid&&(n=N.createElement(Xc,{onMenuClosed:()=>this.setState({configMenuUid:null})},N.createElement(lXe,{onClearView:()=>{this.setState({configMenuUid:null}),this.props.onClearView()},onEditViewConfig:()=>{this.setState({configMenuUid:null}),this.props.onEditViewConfig(this.state.configMenuUid)},onExportPNG:()=>{this.setState({configMenuUid:null}),this.props.onExportPNG()},onExportSVG:()=>{this.setState({configMenuUid:null}),this.props.onExportSVG()},onExportViewAsJSON:()=>{this.setState({configMenuUid:null}),this.props.onExportViewsAsJSON()},onExportViewAsLink:()=>{this.setState({configMenuUid:null}),this.props.onExportViewsAsLink()},onLockLocation:()=>{this.setState({configMenuUid:null}),this.props.onLockLocation(this.state.configMenuUid)},onLockZoom:()=>{this.setState({configMenuUid:null}),this.props.onLockZoom(this.state.configMenuUid)},onLockZoomAndLocation:()=>{this.setState({configMenuUid:null}),this.props.onLockZoomAndLocation(this.state.configMenuUid)},onOptionsChanged:s=>{this.props.onViewOptionsChanged(s),this.setState({configMenuUid:null})},onProjectViewport:()=>{this.setState({configMenuUid:null}),this.props.onProjectViewport(this.state.configMenuUid)},onTakeAndLockZoomAndLocation:()=>{this.setState({configMenuUid:null}),this.props.onTakeAndLockZoomAndLocation(this.state.configMenuUid)},onTogglePositionSearchBox:()=>{this.setState({configMenuUid:null}),this.props.onTogglePositionSearchBox(this.state.configMenuUid)},onUnlockLocation:()=>{this.setState({configMenuUid:null}),this.props.onUnlockLocation(this.state.configMenuUid)},onUnlockZoom:()=>{this.setState({configMenuUid:null}),this.props.onUnlockZoom(this.state.configMenuUid)},onUnlockZoomAndLocation:()=>{this.setState({configMenuUid:null}),this.props.onUnlockZoomAndLocation(this.state.configMenuUid)},onYankLocation:()=>{this.setState({configMenuUid:null}),this.props.onYankLocation(this.state.configMenuUid)},onYankZoom:()=>{this.setState({configMenuUid:null}),this.props.onYankZoom(this.state.configMenuUid)},onYankZoomAndLocation:()=>{this.setState({configMenuUid:null}),this.props.onYankZoomAndLocation(this.state.configMenuUid)},onZoomToData:()=>{this.setState({configMenuUid:null}),this.props.onZoomToData(this.state.configMenuUid)},orientation:"left",position:this.state.configMenuPosition,theme:this.props.theme})));const r=this.props.getGenomePositionSearchBox(this.state.isFocused,s=>{this.setState({isFocused:s})}),o=Vg(this.state.isFocused?vr["multitrack-header-focus"]:vr["multitrack-header"],{[vr["multitrack-header-dark"]]:this.props.theme===qg}),A=this.state.width<=fZe?vr["multitrack-header-icon-squeazed"]:vr["multitrack-header-icon"];return N.createElement("div",{ref:s=>{this.el=s},className:o},N.createElement("div",{className:vr["multitrack-header-left"]},this.props.mouseTool===Dr&&N.createElement("svg",{className:Vg(vr["mouse-tool-selection"],A),title:"Selection tool active"},N.createElement("use",{xlinkHref:"#select"})),N.createElement("div",{className:vr["multitrack-header-grabber"],title:"Drag to move the view"},N.createElement("div",null),N.createElement("div",null),N.createElement("div",null)),this.state.width>pZe&&N.createElement("div",{className:vr["multitrack-header-search"]},this.props.isGenomePositionSearchBoxVisible&&r)),N.createElement("nav",{className:vr["multitrack-header-nav-list"]},N.createElement("svg",{className:A,onClick:this.props.onAddView},N.createElement("title",null,"Add new view (clone this view)"),N.createElement("use",{xlinkHref:"#copy"})),N.createElement("svg",{ref:s=>{this.configImg=s},className:A,onClick:()=>this.handleConfigMenuOpened(this.props.viewUid)},N.createElement("title",null,"Configure this view"),N.createElement("use",{xlinkHref:"#cog"})),N.createElement("svg",{ref:s=>{this.plusImg=s},className:A,onClick:()=>this.handleAddTrackPositionMenuOpened(this.props.viewUid)},N.createElement("title",null,"Add Track"),N.createElement("use",{xlinkHref:"#plus"})),N.createElement("svg",{className:A,onClick:this.props.onCloseView},N.createElement("title",null,"Close View"),N.createElement("use",{xlinkHref:"#cross"}))),n,C)}}]),I}(N.Component);k4.defaultProps={isGenomePositionSearchBoxVisible:!1};k4.propTypes={getGenomePositionSearchBox:L.func.isRequired,isGenomePositionSearchBoxVisible:L.bool,mouseTool:L.string.isRequired,onAddView:L.func.isRequired,onClearView:L.func.isRequired,onCloseView:L.func.isRequired,onEditViewConfig:L.func.isRequired,onExportSVG:L.func.isRequired,onExportPNG:L.func.isRequired,onExportViewsAsJSON:L.func.isRequired,onExportViewsAsLink:L.func.isRequired,onLockLocation:L.func.isRequired,onLockZoom:L.func.isRequired,onLockZoomAndLocation:L.func.isRequired,onProjectViewport:L.func.isRequired,onTakeAndLockZoomAndLocation:L.func.isRequired,onTogglePositionSearchBox:L.func.isRequired,onTrackPositionChosen:L.func.isRequired,onUnlockLocation:L.func.isRequired,onUnlockZoom:L.func.isRequired,onUnlockZoomAndLocation:L.func.isRequired,onViewOptionsChanged:L.func.isRequired,onYankLocation:L.func.isRequired,onYankZoom:L.func.isRequired,onYankZoomAndLocation:L.func.isRequired,onZoomToData:L.func.isRequired,theme:L.symbol.isRequired,viewUid:L.string.isRequired};const J$t=im(k4);var dXe={};Object.defineProperty(dXe,"__esModule",{value:!0});var bl=Object.assign||function(e){for(var g=1;g=0||Object.prototype.hasOwnProperty.call(e,i)&&(I[i]=e[i]);return I}function Q$t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function Tae(e,g){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return g&&(typeof g=="object"||typeof g=="function")?g:e}function j$t(e,g){if(typeof g!="function"&&g!==null)throw new TypeError("Super expression must either be null or a function, not "+typeof g);e.prototype=Object.create(g&&g.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),g&&(Object.setPrototypeOf?Object.setPrototypeOf(e,g):e.__proto__=g)}var $$t=13,q$t=9,e8t=8,t8t=89,wR=90,g8t=77,Nae=57,kae=219,Yae=222,Kae=192,I8t=27,Dae=100,i8t=3e3,n8t="navigator"in globalThis&&/Win/i.test(navigator.platform),Kx="navigator"in globalThis&&/(Mac|iPhone|iPod|iPad)/i.test(navigator.platform),lW="npm__react-simple-code-editor__textarea",C8t=` /** * Reset the text fill color so that placeholder is visible */ -.`+LW+`:empty { +.`+lW+`:empty { -webkit-text-fill-color: inherit !important; } @@ -1541,36 +1940,36 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho * So we use 'color: transparent' to make the text transparent on IE * Unlike other browsers, it doesn't affect caret color in IE */ - .`+LW+` { + .`+lW+` { color: transparent !important; } - .`+LW+`::selection { + .`+lW+`::selection { background-color: #accef7 !important; color: transparent !important; } } -`,S9e=function(g){p4t(e,g);function e(){var I,i,n,C;f4t(this,e);for(var r=arguments.length,o=Array(r),A=0;A1&&arguments[1]!==void 0?arguments[1]:!1,l=n._history,c=l.stack,u=l.offset;if(c.length&&u>-1){n._history.stack=c.slice(0,u+1);var d=n._history.stack.length;if(d>Gse){var h=d-Gse;n._history.stack=c.slice(h,d),n._history.offset=Math.max(n._history.offset-h,0)}}var m=Date.now();if(a){var f=n._history.stack[n._history.offset];if(f&&m-f.timestamp=Z&&$<=v&&q.startsWith(p)?q.substring(p.length):q}).join(` -`);if(m!==G){var B=y[Z];n._applyEdits({value:G,selectionStart:B.startsWith(p)?f-p.length:f,selectionEnd:b-(m.length-G.length)})}}else if(f!==b){var w=n._getLines(m,f),R=w.length-1,S=n._getLines(m,b).length-1,X=w[R];n._applyEdits({value:m.split(` -`).map(function(q,$){return $>=R&&$<=S?p+q:q}).join(` -`),selectionStart:/\S/.test(X)?f+p.length:f,selectionEnd:b+p.length*(S-R+1)})}else{var W=f+p.length;n._applyEdits({value:m.substring(0,f)+p+m.substring(b),selectionStart:W,selectionEnd:W})}else if(s.keyCode===Z4t){var V=f!==b,H=m.substring(0,f);if(H.endsWith(p)&&!V){s.preventDefault();var D=f-p.length;n._applyEdits({value:m.substring(0,f-p.length)+m.substring(b),selectionStart:D,selectionEnd:D})}}else if(s.keyCode===b4t){if(f===b){var Y=n._getLines(m,f).pop(),F=Y.match(/^\s+/);if(F&&F[0]){s.preventDefault();var _=` -`+F[0],J=f+_.length;n._applyEdits({value:m.substring(0,f)+_+m.substring(b),selectionStart:J,selectionEnd:J})}}}else if(s.keyCode===pse||s.keyCode===bse||s.keyCode===yse||s.keyCode===Zse){var te=void 0;s.keyCode===pse&&s.shiftKey?te=["(",")"]:s.keyCode===bse?s.shiftKey?te=["{","}"]:te=["[","]"]:s.keyCode===yse?s.shiftKey?te=['"','"']:te=["'","'"]:s.keyCode===Zse&&!s.shiftKey&&(te=["`","`"]),f!==b&&te&&(s.preventDefault(),n._applyEdits({value:m.substring(0,f)+te[0]+m.substring(f,b)+te[1]+m.substring(b),selectionStart:f,selectionEnd:b+2}))}else(wF?s.metaKey&&s.keyCode===g1:s.ctrlKey&&s.keyCode===g1)&&!s.shiftKey&&!s.altKey?(s.preventDefault(),n._undoEdit()):(wF?s.metaKey&&s.keyCode===g1&&s.shiftKey:w4t?s.ctrlKey&&s.keyCode===G4t:s.ctrlKey&&s.keyCode===g1&&s.shiftKey)&&!s.altKey?(s.preventDefault(),n._redoEdit()):s.keyCode===B4t&&s.ctrlKey&&(!wF||s.shiftKey)&&(s.preventDefault(),n.setState(function(q){return{capture:!q.capture}}))}},n._handleChange=function(s){var a=s.target,l=a.value,c=a.selectionStart,u=a.selectionEnd;n._recordChange({value:l,selectionStart:c,selectionEnd:u},!0),n.props.onValueChange(l)},n._history={stack:[],offset:-1},i),fse(n,C)}return u4t(e,[{key:"componentDidMount",value:function(){this._recordCurrentState()}},{key:"render",value:function(){var i=this,n=this.props,C=n.value,r=n.style,o=n.padding,A=n.highlight,s=n.textareaId,a=n.autoFocus,l=n.disabled,c=n.form,u=n.maxLength,d=n.minLength,h=n.name,m=n.placeholder,f=n.readOnly,b=n.required,p=n.onClick,y=n.onFocus,Z=n.onBlur,v=n.onKeyUp;n.onKeyDown,n.onValueChange,n.tabSize,n.insertSpaces,n.ignoreTabKey;var G=m4t(n,["value","style","padding","highlight","textareaId","autoFocus","disabled","form","maxLength","minLength","name","placeholder","readOnly","required","onClick","onFocus","onBlur","onKeyUp","onKeyDown","onValueChange","tabSize","insertSpaces","ignoreTabKey"]),B={paddingTop:o,paddingRight:o,paddingBottom:o,paddingLeft:o},w=A(C);return BZ.createElement("div",Yl({},G,{style:Yl({},vZ.container,r)}),BZ.createElement("textarea",{ref:function(S){return i._input=S},style:Yl({},vZ.editor,vZ.textarea,B),className:LW,id:s,value:C,onChange:this._handleChange,onKeyDown:this._handleKeyDown,onClick:p,onKeyUp:v,onFocus:y,onBlur:Z,disabled:l,form:c,maxLength:u,minLength:d,name:h,placeholder:m,readOnly:f,required:b,autoFocus:a,autoCapitalize:"off",autoComplete:"off",autoCorrect:"off",spellCheck:!1,"data-gramm":!1}),BZ.createElement("pre",Yl({"aria-hidden":"true",style:Yl({},vZ.editor,vZ.highlight,B)},typeof w=="string"?{dangerouslySetInnerHTML:{__html:w+"
"}}:{children:w})),BZ.createElement("style",{type:"text/css",dangerouslySetInnerHTML:{__html:V4t}}))}},{key:"session",get:function(){return{history:this._history}},set:function(i){this._history=i.history}}]),e}(BZ.Component);S9e.defaultProps={tabSize:2,insertSpaces:!0,ignoreTabKey:!1,padding:0};var R4t=v9e.default=S9e,vZ={container:{position:"relative",textAlign:"left",boxSizing:"border-box",padding:0,overflow:"hidden"},textarea:{position:"absolute",top:0,left:0,height:"100%",width:"100%",resize:"none",color:"inherit",overflow:"hidden",MozOsxFontSmoothing:"grayscale",WebkitFontSmoothing:"antialiased",WebkitTextFillColor:"transparent"},highlight:{position:"relative",pointerEvents:"none"},editor:{margin:0,border:0,background:"none",boxSizing:"inherit",display:"inherit",fontFamily:"inherit",fontSize:"inherit",fontStyle:"inherit",fontVariantLigatures:"inherit",fontWeight:"inherit",letterSpacing:"inherit",lineHeight:"inherit",tabSize:"inherit",textIndent:"inherit",textRendering:"inherit",textTransform:"inherit",whiteSpace:"pre-wrap",wordBreak:"keep-all",overflowWrap:"break-word"}},w9e={exports:{}};(function(g){var e=typeof window<"u"?window:typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope?self:{};/** +`,hXe=function(e){j$t(g,e);function g(){var I,i,n,C;Q$t(this,g);for(var r=arguments.length,o=Array(r),A=0;A1&&arguments[1]!==void 0?arguments[1]:!1,l=n._history,c=l.stack,u=l.offset;if(c.length&&u>-1){n._history.stack=c.slice(0,u+1);var d=n._history.stack.length;if(d>Dae){var h=d-Dae;n._history.stack=c.slice(h,d),n._history.offset=Math.max(n._history.offset-h,0)}}var m=Date.now();if(a){var f=n._history.stack[n._history.offset];if(f&&m-f.timestamp=Z&&$<=B&&q.startsWith(p)?q.substring(p.length):q}).join(` +`);if(m!==G){var v=y[Z];n._applyEdits({value:G,selectionStart:v.startsWith(p)?f-p.length:f,selectionEnd:b-(m.length-G.length)})}}else if(f!==b){var w=n._getLines(m,f),V=w.length-1,S=n._getLines(m,b).length-1,X=w[V];n._applyEdits({value:m.split(` +`).map(function(q,$){return $>=V&&$<=S?p+q:q}).join(` +`),selectionStart:/\S/.test(X)?f+p.length:f,selectionEnd:b+p.length*(S-V+1)})}else{var W=f+p.length;n._applyEdits({value:m.substring(0,f)+p+m.substring(b),selectionStart:W,selectionEnd:W})}else if(s.keyCode===e8t){var R=f!==b,H=m.substring(0,f);if(H.endsWith(p)&&!R){s.preventDefault();var Y=f-p.length;n._applyEdits({value:m.substring(0,f-p.length)+m.substring(b),selectionStart:Y,selectionEnd:Y})}}else if(s.keyCode===$$t){if(f===b){var D=n._getLines(m,f).pop(),E=D.match(/^\s+/);if(E&&E[0]){s.preventDefault();var O=` +`+E[0],J=f+O.length;n._applyEdits({value:m.substring(0,f)+O+m.substring(b),selectionStart:J,selectionEnd:J})}}}else if(s.keyCode===Nae||s.keyCode===kae||s.keyCode===Yae||s.keyCode===Kae){var ee=void 0;s.keyCode===Nae&&s.shiftKey?ee=["(",")"]:s.keyCode===kae?s.shiftKey?ee=["{","}"]:ee=["[","]"]:s.keyCode===Yae?s.shiftKey?ee=['"','"']:ee=["'","'"]:s.keyCode===Kae&&!s.shiftKey&&(ee=["`","`"]),f!==b&&ee&&(s.preventDefault(),n._applyEdits({value:m.substring(0,f)+ee[0]+m.substring(f,b)+ee[1]+m.substring(b),selectionStart:f,selectionEnd:b+2}))}else(Kx?s.metaKey&&s.keyCode===wR:s.ctrlKey&&s.keyCode===wR)&&!s.shiftKey&&!s.altKey?(s.preventDefault(),n._undoEdit()):(Kx?s.metaKey&&s.keyCode===wR&&s.shiftKey:n8t?s.ctrlKey&&s.keyCode===t8t:s.ctrlKey&&s.keyCode===wR&&s.shiftKey)&&!s.altKey?(s.preventDefault(),n._redoEdit()):s.keyCode===g8t&&s.ctrlKey&&(!Kx||s.shiftKey)&&(s.preventDefault(),n.setState(function(q){return{capture:!q.capture}}))}},n._handleChange=function(s){var a=s.target,l=a.value,c=a.selectionStart,u=a.selectionEnd;n._recordChange({value:l,selectionStart:c,selectionEnd:u},!0),n.props.onValueChange(l)},n._history={stack:[],offset:-1},i),Tae(n,C)}return O$t(g,[{key:"componentDidMount",value:function(){this._recordCurrentState()}},{key:"render",value:function(){var i=this,n=this.props,C=n.value,r=n.style,o=n.padding,A=n.highlight,s=n.textareaId,a=n.autoFocus,l=n.disabled,c=n.form,u=n.maxLength,d=n.minLength,h=n.name,m=n.placeholder,f=n.readOnly,b=n.required,p=n.onClick,y=n.onFocus,Z=n.onBlur,B=n.onKeyUp;n.onKeyDown,n.onValueChange,n.tabSize,n.insertSpaces,n.ignoreTabKey;var G=U$t(n,["value","style","padding","highlight","textareaId","autoFocus","disabled","form","maxLength","minLength","name","placeholder","readOnly","required","onClick","onFocus","onBlur","onKeyUp","onKeyDown","onValueChange","tabSize","insertSpaces","ignoreTabKey"]),v={paddingTop:o,paddingRight:o,paddingBottom:o,paddingLeft:o},w=A(C);return rZ.createElement("div",bl({},G,{style:bl({},oZ.container,r)}),rZ.createElement("textarea",{ref:function(S){return i._input=S},style:bl({},oZ.editor,oZ.textarea,v),className:lW,id:s,value:C,onChange:this._handleChange,onKeyDown:this._handleKeyDown,onClick:p,onKeyUp:B,onFocus:y,onBlur:Z,disabled:l,form:c,maxLength:u,minLength:d,name:h,placeholder:m,readOnly:f,required:b,autoFocus:a,autoCapitalize:"off",autoComplete:"off",autoCorrect:"off",spellCheck:!1,"data-gramm":!1}),rZ.createElement("pre",bl({"aria-hidden":"true",style:bl({},oZ.editor,oZ.highlight,v)},typeof w=="string"?{dangerouslySetInnerHTML:{__html:w+"
"}}:{children:w})),rZ.createElement("style",{type:"text/css",dangerouslySetInnerHTML:{__html:C8t}}))}},{key:"session",get:function(){return{history:this._history}},set:function(i){this._history=i.history}}]),g}(rZ.Component);hXe.defaultProps={tabSize:2,insertSpaces:!0,ignoreTabKey:!1,padding:0};var r8t=dXe.default=hXe,oZ={container:{position:"relative",textAlign:"left",boxSizing:"border-box",padding:0,overflow:"hidden"},textarea:{position:"absolute",top:0,left:0,height:"100%",width:"100%",resize:"none",color:"inherit",overflow:"hidden",MozOsxFontSmoothing:"grayscale",WebkitFontSmoothing:"antialiased",WebkitTextFillColor:"transparent"},highlight:{position:"relative",pointerEvents:"none"},editor:{margin:0,border:0,background:"none",boxSizing:"inherit",display:"inherit",fontFamily:"inherit",fontSize:"inherit",fontStyle:"inherit",fontVariantLigatures:"inherit",fontWeight:"inherit",letterSpacing:"inherit",lineHeight:"inherit",tabSize:"inherit",textIndent:"inherit",textRendering:"inherit",textTransform:"inherit",whiteSpace:"pre-wrap",wordBreak:"keep-all",overflowWrap:"break-word"}},mXe={exports:{}};(function(e){var g=typeof window<"u"?window:typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope?self:{};/** * Prism: Lightweight, robust, elegant syntax highlighting * * @license MIT * @author Lea Verou * @namespace * @public - */var I=function(i){var n=/(?:^|\s)lang(?:uage)?-([\w-]+)(?=\s|$)/i,C=0,r={},o={manual:i.Prism&&i.Prism.manual,disableWorkerMessageHandler:i.Prism&&i.Prism.disableWorkerMessageHandler,util:{encode:function b(p){return p instanceof A?new A(p.type,b(p.content),p.alias):Array.isArray(p)?p.map(b):p.replace(/&/g,"&").replace(/"u")return null;if("currentScript"in document&&1<2)return document.currentScript;try{throw new Error}catch(Z){var b=(/at [^(\r\n]*\((.*):[^:]+:[^:]+\)$/i.exec(Z.stack)||[])[1];if(b){var p=document.getElementsByTagName("script");for(var y in p)if(p[y].src==b)return p[y]}return null}},isActive:function(b,p,y){for(var Z="no-"+p;b;){var v=b.classList;if(v.contains(p))return!0;if(v.contains(Z))return!1;b=b.parentElement}return!!y}},languages:{plain:r,plaintext:r,text:r,txt:r,extend:function(b,p){var y=o.util.clone(o.languages[b]);for(var Z in p)y[Z]=p[Z];return y},insertBefore:function(b,p,y,Z){Z=Z||o.languages;var v=Z[b],G={};for(var B in v)if(v.hasOwnProperty(B)){if(B==p)for(var w in y)y.hasOwnProperty(w)&&(G[w]=y[w]);y.hasOwnProperty(B)||(G[B]=v[B])}var R=Z[b];return Z[b]=G,o.languages.DFS(o.languages,function(S,X){X===R&&S!=b&&(this[S]=G)}),G},DFS:function b(p,y,Z,v){v=v||{};var G=o.util.objId;for(var B in p)if(p.hasOwnProperty(B)){y.call(p,B,p[B],Z||B);var w=p[B],R=o.util.type(w);R==="Object"&&!v[G(w)]?(v[G(w)]=!0,b(w,y,null,v)):R==="Array"&&!v[G(w)]&&(v[G(w)]=!0,b(w,y,B,v))}}},plugins:{},highlightAll:function(b,p){o.highlightAllUnder(document,b,p)},highlightAllUnder:function(b,p,y){var Z={callback:y,container:b,selector:'code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code'};o.hooks.run("before-highlightall",Z),Z.elements=Array.prototype.slice.apply(Z.container.querySelectorAll(Z.selector)),o.hooks.run("before-all-elements-highlight",Z);for(var v=0,G;G=Z.elements[v++];)o.highlightElement(G,p===!0,Z.callback)},highlightElement:function(b,p,y){var Z=o.util.getLanguage(b),v=o.languages[Z];o.util.setLanguage(b,Z);var G=b.parentElement;G&&G.nodeName.toLowerCase()==="pre"&&o.util.setLanguage(G,Z);var B=b.textContent,w={element:b,language:Z,grammar:v,code:B};function R(X){w.highlightedCode=X,o.hooks.run("before-insert",w),w.element.innerHTML=w.highlightedCode,o.hooks.run("after-highlight",w),o.hooks.run("complete",w),y&&y.call(w.element)}if(o.hooks.run("before-sanity-check",w),G=w.element.parentElement,G&&G.nodeName.toLowerCase()==="pre"&&!G.hasAttribute("tabindex")&&G.setAttribute("tabindex","0"),!w.code){o.hooks.run("complete",w),y&&y.call(w.element);return}if(o.hooks.run("before-highlight",w),!w.grammar){R(o.util.encode(w.code));return}if(p&&i.Worker){var S=new Worker(o.filename);S.onmessage=function(X){R(X.data)},S.postMessage(JSON.stringify({language:w.language,code:w.code,immediateClose:!0}))}else R(o.highlight(w.code,w.grammar,w.language))},highlight:function(b,p,y){var Z={code:b,grammar:p,language:y};if(o.hooks.run("before-tokenize",Z),!Z.grammar)throw new Error('The language "'+Z.language+'" has no grammar.');return Z.tokens=o.tokenize(Z.code,Z.grammar),o.hooks.run("after-tokenize",Z),A.stringify(o.util.encode(Z.tokens),Z.language)},tokenize:function(b,p){var y=p.rest;if(y){for(var Z in y)p[Z]=y[Z];delete p.rest}var v=new l;return c(v,v.head,b),a(b,v,p,v.head,0),d(v)},hooks:{all:{},add:function(b,p){var y=o.hooks.all;y[b]=y[b]||[],y[b].push(p)},run:function(b,p){var y=o.hooks.all[b];if(!(!y||!y.length))for(var Z=0,v;v=y[Z++];)v(p)}},Token:A};i.Prism=o;function A(b,p,y,Z){this.type=b,this.content=p,this.alias=y,this.length=(Z||"").length|0}A.stringify=function b(p,y){if(typeof p=="string")return p;if(Array.isArray(p)){var Z="";return p.forEach(function(R){Z+=b(R,y)}),Z}var v={type:p.type,content:b(p.content,y),tag:"span",classes:["token",p.type],attributes:{},language:y},G=p.alias;G&&(Array.isArray(G)?Array.prototype.push.apply(v.classes,G):v.classes.push(G)),o.hooks.run("wrap",v);var B="";for(var w in v.attributes)B+=" "+w+'="'+(v.attributes[w]||"").replace(/"/g,""")+'"';return"<"+v.tag+' class="'+v.classes.join(" ")+'"'+B+">"+v.content+""};function s(b,p,y,Z){b.lastIndex=p;var v=b.exec(y);if(v&&Z&&v[1]){var G=v[1].length;v.index+=G,v[0]=v[0].slice(G)}return v}function a(b,p,y,Z,v,G){for(var B in y)if(!(!y.hasOwnProperty(B)||!y[B])){var w=y[B];w=Array.isArray(w)?w:[w];for(var R=0;R=G.reach);_+=F.value.length,F=F.next){var J=F.value;if(p.length>b.length)return;if(!(J instanceof A)){var te=1,q;if(V){if(q=s(Y,_,b,W),!q||q.index>=b.length)break;var Q=q.index,$=q.index+q[0].length,j=_;for(j+=F.value.length;Q>=j;)F=F.next,j+=F.value.length;if(j-=F.value.length,_=j,F.value instanceof A)continue;for(var ee=F;ee!==p.tail&&(j<$||typeof ee.value=="string");ee=ee.next)te++,j+=ee.value.length;te--,J=b.slice(_,j),q.index-=_}else if(q=s(Y,0,J,W),!q)continue;var Q=q.index,ne=q[0],fe=J.slice(0,Q),Ce=J.slice(Q+ne.length),Ze=_+J.length;G&&Ze>G.reach&&(G.reach=Ze);var Ge=F.prev;fe&&(Ge=c(p,Ge,fe),_+=fe.length),u(p,Ge,te);var ve=new A(B,X?o.tokenize(ne,X):ne,H,ne);if(F=c(p,Ge,ve),Ce&&c(p,F,Ce),te>1){var ke={cause:B+","+R,reach:Ze};a(b,p,y,F.prev,_,ke),G&&ke.reach>G.reach&&(G.reach=ke.reach)}}}}}}function l(){var b={value:null,prev:null,next:null},p={value:null,prev:b,next:null};b.next=p,this.head=b,this.tail=p,this.length=0}function c(b,p,y){var Z=p.next,v={value:y,prev:p,next:Z};return p.next=v,Z.prev=v,b.length++,v}function u(b,p,y){for(var Z=p.next,v=0;v1){x[0]=x[0].slice(0,-1);for(var ce=x.length-1,de=1;de= 0x80 (not a basic code point)","invalid-input":"Invalid input"},S=h-m,X=Math.floor,W=String.fromCharCode;function V(P){throw new RangeError(R[P])}function H(P,x){for(var U=[],ce=P.length;ce--;)U[ce]=x(P[ce]);return U}function D(P,x){var U=P.split("@"),ce="";U.length>1&&(ce=U[0]+"@",P=U[1]),P=P.replace(w,".");var de=P.split("."),Pe=H(de,x).join(".");return ce+Pe}function Y(P){for(var x=[],U=0,ce=P.length;U=55296&&de<=56319&&U>1,x+=X(x/U);x>S*f>>1;de+=h)x=X(x/S);return X(de+(S+1)*x/(x+b))},q=function(x){var U=[],ce=x.length,de=0,Pe=Z,Je=y,ct=x.lastIndexOf(v);ct<0&&(ct=0);for(var bt=0;bt=128&&V("not-basic"),U.push(x.charCodeAt(bt));for(var Ft=ct>0?ct+1:0;Ft=ce&&V("invalid-input");var ot=_(x.charCodeAt(Ft++));(ot>=h||ot>X((d-de)/Xt))&&V("overflow"),de+=ot*Xt;var Nt=Ot<=Je?m:Ot>=Je+f?f:Ot-Je;if(otX(d/Ut)&&V("overflow"),Xt*=Ut}var Pt=U.length+1;Je=te(de-dt,Pt,dt==0),X(de/Pt)>d-Pe&&V("overflow"),Pe+=X(de/Pt),de%=Pt,U.splice(de++,0,Pe)}return String.fromCodePoint.apply(String,U)},$=function(x){var U=[];x=Y(x);var ce=x.length,de=Z,Pe=0,Je=y,ct=!0,bt=!1,Ft=void 0;try{for(var dt=x[Symbol.iterator](),Xt;!(ct=(Xt=dt.next()).done);ct=!0){var Ot=Xt.value;Ot<128&&U.push(W(Ot))}}catch(hC){bt=!0,Ft=hC}finally{try{!ct&&dt.return&&dt.return()}finally{if(bt)throw Ft}}var ot=U.length,Nt=ot;for(ot&&U.push(v);Nt=de&&qtX((d-Pe)/Et)&&V("overflow"),Pe+=(Ut-de)*Et,de=Ut;var Tt=!0,ig=!1,jt=void 0;try{for(var Ig=x[Symbol.iterator](),cg;!(Tt=(cg=Ig.next()).done);Tt=!0){var Hg=cg.value;if(Hgd&&V("overflow"),Hg==de){for(var bg=Pe,zI=h;;zI+=h){var Qi=zI<=Je?m:zI>=Je+f?f:zI-Je;if(bg>6|192).toString(16).toUpperCase()+"%"+(x&63|128).toString(16).toUpperCase():U="%"+(x>>12|224).toString(16).toUpperCase()+"%"+(x>>6&63|128).toString(16).toUpperCase()+"%"+(x&63|128).toString(16).toUpperCase(),U}function Ce(P){for(var x="",U=0,ce=P.length;U=194&&de<224){if(ce-U>=6){var Pe=parseInt(P.substr(U+4,2),16);x+=String.fromCharCode((de&31)<<6|Pe&63)}else x+=P.substr(U,6);U+=6}else if(de>=224){if(ce-U>=9){var Je=parseInt(P.substr(U+4,2),16),ct=parseInt(P.substr(U+7,2),16);x+=String.fromCharCode((de&15)<<12|(Je&63)<<6|ct&63)}else x+=P.substr(U,9);U+=9}else x+=P.substr(U,3),U+=3}return x}function Ze(P,x){function U(ce){var de=Ce(ce);return de.match(x.UNRESERVED)?de:ce}return P.scheme&&(P.scheme=String(P.scheme).replace(x.PCT_ENCODED,U).toLowerCase().replace(x.NOT_SCHEME,"")),P.userinfo!==void 0&&(P.userinfo=String(P.userinfo).replace(x.PCT_ENCODED,U).replace(x.NOT_USERINFO,fe).replace(x.PCT_ENCODED,r)),P.host!==void 0&&(P.host=String(P.host).replace(x.PCT_ENCODED,U).toLowerCase().replace(x.NOT_HOST,fe).replace(x.PCT_ENCODED,r)),P.path!==void 0&&(P.path=String(P.path).replace(x.PCT_ENCODED,U).replace(P.scheme?x.NOT_PATH:x.NOT_PATH_NOSCHEME,fe).replace(x.PCT_ENCODED,r)),P.query!==void 0&&(P.query=String(P.query).replace(x.PCT_ENCODED,U).replace(x.NOT_QUERY,fe).replace(x.PCT_ENCODED,r)),P.fragment!==void 0&&(P.fragment=String(P.fragment).replace(x.PCT_ENCODED,U).replace(x.NOT_FRAGMENT,fe).replace(x.PCT_ENCODED,r)),P}function Ge(P){return P.replace(/^0*(.*)/,"$1")||"0"}function ve(P,x){var U=P.match(x.IPV4ADDRESS)||[],ce=c(U,2),de=ce[1];return de?de.split(".").map(Ge).join("."):P}function ke(P,x){var U=P.match(x.IPV6ADDRESS)||[],ce=c(U,3),de=ce[1],Pe=ce[2];if(de){for(var Je=de.toLowerCase().split("::").reverse(),ct=c(Je,2),bt=ct[0],Ft=ct[1],dt=Ft?Ft.split(":").map(Ge):[],Xt=bt.split(":").map(Ge),Ot=x.IPV4ADDRESS.test(Xt[Xt.length-1]),ot=Ot?7:8,Nt=Xt.length-ot,Ut=Array(ot),Pt=0;Pt1){var yt=Ut.slice(0,eI.index),qt=Ut.slice(eI.index+eI.length);et=yt.join(":")+"::"+qt.join(":")}else et=Ut.join(":");return Pe&&(et+="%"+Pe),et}else return P}var Xe=/^(?:([^:\/?#]+):)?(?:\/\/((?:([^\/?#@]*)@)?(\[[^\/?#\]]+\]|[^\/?#:]*)(?:\:(\d*))?))?([^?#]*)(?:\?([^#]*))?(?:#((?:.|\n|\r)*))?/i,Oe="".match(/(){0}/)[1]===void 0;function ze(P){var x=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},U={},ce=x.iri!==!1?l:a;x.reference==="suffix"&&(P=(x.scheme?x.scheme+":":"")+"//"+P);var de=P.match(Xe);if(de){Oe?(U.scheme=de[1],U.userinfo=de[3],U.host=de[4],U.port=parseInt(de[5],10),U.path=de[6]||"",U.query=de[7],U.fragment=de[8],isNaN(U.port)&&(U.port=de[5])):(U.scheme=de[1]||void 0,U.userinfo=P.indexOf("@")!==-1?de[3]:void 0,U.host=P.indexOf("//")!==-1?de[4]:void 0,U.port=parseInt(de[5],10),U.path=de[6]||"",U.query=P.indexOf("?")!==-1?de[7]:void 0,U.fragment=P.indexOf("#")!==-1?de[8]:void 0,isNaN(U.port)&&(U.port=P.match(/\/\/(?:.|\n)*\:(?:\/|\?|\#|$)/)?de[4]:void 0)),U.host&&(U.host=ke(ve(U.host,ce),ce)),U.scheme===void 0&&U.userinfo===void 0&&U.host===void 0&&U.port===void 0&&!U.path&&U.query===void 0?U.reference="same-document":U.scheme===void 0?U.reference="relative":U.fragment===void 0?U.reference="absolute":U.reference="uri",x.reference&&x.reference!=="suffix"&&x.reference!==U.reference&&(U.error=U.error||"URI is not a "+x.reference+" reference.");var Pe=ne[(x.scheme||U.scheme||"").toLowerCase()];if(!x.unicodeSupport&&(!Pe||!Pe.unicodeSupport)){if(U.host&&(x.domainHost||Pe&&Pe.domainHost))try{U.host=Q.toASCII(U.host.replace(ce.PCT_ENCODED,Ce).toLowerCase())}catch(Je){U.error=U.error||"Host's domain name can not be converted to ASCII via punycode: "+Je}Ze(U,a)}else Ze(U,ce);Pe&&Pe.parse&&Pe.parse(U,x)}else U.error=U.error||"URI can not be parsed.";return U}function Me(P,x){var U=x.iri!==!1?l:a,ce=[];return P.userinfo!==void 0&&(ce.push(P.userinfo),ce.push("@")),P.host!==void 0&&ce.push(ke(ve(String(P.host),U),U).replace(U.IPV6ADDRESS,function(de,Pe,Je){return"["+Pe+(Je?"%25"+Je:"")+"]"})),(typeof P.port=="number"||typeof P.port=="string")&&(ce.push(":"),ce.push(String(P.port))),ce.length?ce.join(""):void 0}var Ue=/^\.\.?\//,_e=/^\/\.(\/|$)/,At=/^\/\.\.(\/|$)/,wt=/^\/?(?:.|\n)*?(?=\/|$)/;function rt(P){for(var x=[];P.length;)if(P.match(Ue))P=P.replace(Ue,"");else if(P.match(_e))P=P.replace(_e,"/");else if(P.match(At))P=P.replace(At,"/"),x.pop();else if(P==="."||P==="..")P="";else{var U=P.match(wt);if(U){var ce=U[0];P=P.slice(ce.length),x.push(ce)}else throw new Error("Unexpected dot segment condition")}return x.join("")}function Te(P){var x=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},U=x.iri?l:a,ce=[],de=ne[(x.scheme||P.scheme||"").toLowerCase()];if(de&&de.serialize&&de.serialize(P,x),P.host&&!U.IPV6ADDRESS.test(P.host)){if(x.domainHost||de&&de.domainHost)try{P.host=x.iri?Q.toUnicode(P.host):Q.toASCII(P.host.replace(U.PCT_ENCODED,Ce).toLowerCase())}catch(ct){P.error=P.error||"Host's domain name can not be converted to "+(x.iri?"Unicode":"ASCII")+" via punycode: "+ct}}Ze(P,U),x.reference!=="suffix"&&P.scheme&&(ce.push(P.scheme),ce.push(":"));var Pe=Me(P,x);if(Pe!==void 0&&(x.reference!=="suffix"&&ce.push("//"),ce.push(Pe),P.path&&P.path.charAt(0)!=="/"&&ce.push("/")),P.path!==void 0){var Je=P.path;!x.absolutePath&&(!de||!de.absolutePath)&&(Je=rt(Je)),Pe===void 0&&(Je=Je.replace(/^\/\//,"/%2F")),ce.push(Je)}return P.query!==void 0&&(ce.push("?"),ce.push(P.query)),P.fragment!==void 0&&(ce.push("#"),ce.push(P.fragment)),ce.join("")}function le(P,x){var U=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},ce=arguments[3],de={};return ce||(P=ze(Te(P,U),U),x=ze(Te(x,U),U)),U=U||{},!U.tolerant&&x.scheme?(de.scheme=x.scheme,de.userinfo=x.userinfo,de.host=x.host,de.port=x.port,de.path=rt(x.path||""),de.query=x.query):(x.userinfo!==void 0||x.host!==void 0||x.port!==void 0?(de.userinfo=x.userinfo,de.host=x.host,de.port=x.port,de.path=rt(x.path||""),de.query=x.query):(x.path?(x.path.charAt(0)==="/"?de.path=rt(x.path):((P.userinfo!==void 0||P.host!==void 0||P.port!==void 0)&&!P.path?de.path="/"+x.path:P.path?de.path=P.path.slice(0,P.path.lastIndexOf("/")+1)+x.path:de.path=x.path,de.path=rt(de.path)),de.query=x.query):(de.path=P.path,x.query!==void 0?de.query=x.query:de.query=P.query),de.userinfo=P.userinfo,de.host=P.host,de.port=P.port),de.scheme=P.scheme),de.fragment=x.fragment,de}function ye(P,x,U){var ce=A({scheme:"null"},U);return Te(le(ze(P,ce),ze(x,ce),ce,!0),ce)}function We(P,x){return typeof P=="string"?P=Te(ze(P,x),x):C(P)==="object"&&(P=ze(Te(P,x),x)),P}function K(P,x,U){return typeof P=="string"?P=Te(ze(P,U),U):C(P)==="object"&&(P=Te(P,U)),typeof x=="string"?x=Te(ze(x,U),U):C(x)==="object"&&(x=Te(x,U)),P===x}function T(P,x){return P&&P.toString().replace(!x||!x.iri?a.ESCAPE:l.ESCAPE,fe)}function k(P,x){return P&&P.toString().replace(!x||!x.iri?a.PCT_ENCODED:l.PCT_ENCODED,Ce)}var ge={scheme:"http",domainHost:!0,parse:function(x,U){return x.host||(x.error=x.error||"HTTP URIs must have a host."),x},serialize:function(x,U){var ce=String(x.scheme).toLowerCase()==="https";return(x.port===(ce?443:80)||x.port==="")&&(x.port=void 0),x.path||(x.path="/"),x}},he={scheme:"https",domainHost:ge.domainHost,parse:ge.parse,serialize:ge.serialize};function we(P){return typeof P.secure=="boolean"?P.secure:String(P.scheme).toLowerCase()==="wss"}var xe={scheme:"ws",domainHost:!0,parse:function(x,U){var ce=x;return ce.secure=we(ce),ce.resourceName=(ce.path||"/")+(ce.query?"?"+ce.query:""),ce.path=void 0,ce.query=void 0,ce},serialize:function(x,U){if((x.port===(we(x)?443:80)||x.port==="")&&(x.port=void 0),typeof x.secure=="boolean"&&(x.scheme=x.secure?"wss":"ws",x.secure=void 0),x.resourceName){var ce=x.resourceName.split("?"),de=c(ce,2),Pe=de[0],Je=de[1];x.path=Pe&&Pe!=="/"?Pe:void 0,x.query=Je,x.resourceName=void 0}return x.fragment=void 0,x}},qe={scheme:"wss",domainHost:xe.domainHost,parse:xe.parse,serialize:xe.serialize},mt={},St="[A-Za-z0-9\\-\\.\\_\\~\\xA0-\\u200D\\u2010-\\u2029\\u202F-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF]",ut="[0-9A-Fa-f]",Yt=n(n("%[EFef]"+ut+"%"+ut+ut+"%"+ut+ut)+"|"+n("%[89A-Fa-f]"+ut+"%"+ut+ut)+"|"+n("%"+ut+ut)),ie="[A-Za-z0-9\\!\\$\\%\\'\\*\\+\\-\\^\\_\\`\\{\\|\\}\\~]",E="[\\!\\$\\%\\'\\(\\)\\*\\+\\,\\-\\.0-9\\<\\>A-Z\\x5E-\\x7E]",O=i(E,'[\\"\\\\]'),me="[\\!\\$\\'\\(\\)\\*\\+\\,\\;\\:\\@]",Ne=new RegExp(St,"g"),ue=new RegExp(Yt,"g"),se=new RegExp(i("[^]",ie,"[\\.]",'[\\"]',O),"g"),re=new RegExp(i("[^]",St,me),"g"),oe=re;function Se(P){var x=Ce(P);return x.match(Ne)?x:P}var Ke={scheme:"mailto",parse:function(x,U){var ce=x,de=ce.to=ce.path?ce.path.split(","):[];if(ce.path=void 0,ce.query){for(var Pe=!1,Je={},ct=ce.query.split("&"),bt=0,Ft=ct.length;bt=55296&&C<=56319&&n=e)throw new Error("Cannot access property/index "+i+" levels up, current level is "+e);return I[e-i]}if(i>e)throw new Error("Cannot access data "+i+" levels up, current level is "+e);if(C="data"+(e-i||""),!n)return C}for(var o=C,A=n.split("/"),s=0;s=0?{index:i,compiling:!0}:(i=this._compilations.length,this._compilations[i]={schema:g,root:e,baseId:I},{index:i,compiling:!1})}function l$t(g,e,I){var i=Y9e.call(this,g,e,I);i>=0&&this._compilations.splice(i,1)}function Y9e(g,e,I){for(var i=0;i%\\^`{|}]|%[0-9a-f]{2})|\{[+#./;?&=,!@|]?(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?(?:,(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?)*\})*$/i,F9e=/^(?:(?:http[s\u017F]?|ftp):\/\/)(?:(?:[\0-\x08\x0E-\x1F!-\x9F\xA1-\u167F\u1681-\u1FFF\u200B-\u2027\u202A-\u202E\u2030-\u205E\u2060-\u2FFF\u3001-\uD7FF\uE000-\uFEFE\uFF00-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+(?::(?:[\0-\x08\x0E-\x1F!-\x9F\xA1-\u167F\u1681-\u1FFF\u200B-\u2027\u202A-\u202E\u2030-\u205E\u2060-\u2FFF\u3001-\uD7FF\uE000-\uFEFE\uFF00-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*)?@)?(?:(?!10(?:\.[0-9]{1,3}){3})(?!127(?:\.[0-9]{1,3}){3})(?!169\.254(?:\.[0-9]{1,3}){2})(?!192\.168(?:\.[0-9]{1,3}){2})(?!172\.(?:1[6-9]|2[0-9]|3[01])(?:\.[0-9]{1,3}){2})(?:[1-9][0-9]?|1[0-9][0-9]|2[01][0-9]|22[0-3])(?:\.(?:1?[0-9]{1,2}|2[0-4][0-9]|25[0-5])){2}(?:\.(?:[1-9][0-9]?|1[0-9][0-9]|2[0-4][0-9]|25[0-4]))|(?:(?:(?:[0-9a-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+-)*(?:[0-9a-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+)(?:\.(?:(?:[0-9a-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+-)*(?:[0-9a-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+)*(?:\.(?:(?:[a-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]){2,})))(?::[0-9]{2,5})?(?:\/(?:[\0-\x08\x0E-\x1F!-\x9F\xA1-\u167F\u1681-\u1FFF\u200B-\u2027\u202A-\u202E\u2030-\u205E\u2060-\u2FFF\u3001-\uD7FF\uE000-\uFEFE\uFF00-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*)?$/i,E9e=/^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i,M9e=/^(?:\/(?:[^~/]|~0|~1)*)*$/,z9e=/^#(?:\/(?:[a-z0-9_\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i,P9e=/^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/,B$t=fY;function fY(g){return g=g=="full"?"full":"fast",f$t.copy(fY[g])}fY.fast={date:/^\d\d\d\d-[0-1]\d-[0-3]\d$/,time:/^(?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d(?::?\d\d)?)?$/i,"date-time":/^\d\d\d\d-[0-1]\d-[0-3]\d[t\s](?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d(?::?\d\d)?)$/i,uri:/^(?:[a-z][a-z0-9+\-.]*:)(?:\/?\/)?[^\s]*$/i,"uri-reference":/^(?:(?:[a-z][a-z0-9+\-.]*:)?\/?\/)?(?:[^\\\s#][^\s#]*)?(?:#[^\\\s]*)?$/i,"uri-template":D9e,url:F9e,email:/^[a-z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*$/i,hostname:x9e,ipv4:/^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/,ipv6:/^\s*(?:(?:(?:[0-9a-f]{1,4}:){7}(?:[0-9a-f]{1,4}|:))|(?:(?:[0-9a-f]{1,4}:){6}(?::[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(?:(?:[0-9a-f]{1,4}:){5}(?:(?:(?::[0-9a-f]{1,4}){1,2})|:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(?:(?:[0-9a-f]{1,4}:){4}(?:(?:(?::[0-9a-f]{1,4}){1,3})|(?:(?::[0-9a-f]{1,4})?:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){3}(?:(?:(?::[0-9a-f]{1,4}){1,4})|(?:(?::[0-9a-f]{1,4}){0,2}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){2}(?:(?:(?::[0-9a-f]{1,4}){1,5})|(?:(?::[0-9a-f]{1,4}){0,3}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){1}(?:(?:(?::[0-9a-f]{1,4}){1,6})|(?:(?::[0-9a-f]{1,4}){0,4}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?::(?:(?:(?::[0-9a-f]{1,4}){1,7})|(?:(?::[0-9a-f]{1,4}){0,5}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(?:%.+)?\s*$/i,regex:L9e,uuid:E9e,"json-pointer":M9e,"json-pointer-uri-fragment":z9e,"relative-json-pointer":P9e};fY.full={date:J9e,time:O9e,"date-time":w$t,uri:R$t,"uri-reference":G$t,"uri-template":D9e,url:F9e,email:/^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i,hostname:x9e,ipv4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::(?:(?:(?::[0-9a-f]{1,4}){1,7})|(?:(?::[0-9a-f]{1,4}){0,5}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(?:%.+)?\s*$/i,regex:L9e,uuid:E9e,"json-pointer":M9e,"json-pointer-uri-fragment":z9e,"relative-json-pointer":P9e};function v$t(g){return g%4===0&&(g%100!==0||g%400===0)}function J9e(g){var e=g.match(p$t);if(!e)return!1;var I=+e[1],i=+e[2],n=+e[3];return i>=1&&i<=12&&n>=1&&n<=(i==2&&v$t(I)?29:b$t[i])}function O9e(g,e){var I=g.match(y$t);if(!I)return!1;var i=I[1],n=I[2],C=I[3],r=I[5];return(i<=23&&n<=59&&C<=59||i==23&&n==59&&C==60)&&(!e||r)}var S$t=/t|\s/i;function w$t(g){var e=g.split(S$t);return e.length==2&&J9e(e[0])&&O9e(e[1],!0)}var V$t=/\/|:/;function R$t(g){return V$t.test(g)&&Z$t.test(g)}var W$t=/[^\\]\\Z/;function L9e(g){if(W$t.test(g))return!1;try{return new RegExp(g),!0}catch{return!1}}var X$t=function(e,I,i){var n=" ",C=e.level,r=e.dataLevel,o=e.schema[I],A=e.errSchemaPath+"/"+I,s=!e.opts.allErrors,a="data"+(r||""),l="valid"+C,c,u;if(o=="#"||o=="#/")e.isRoot?(c=e.async,u="validate"):(c=e.root.schema.$async===!0,u="root.refVal[0]");else{var d=e.resolveRef(e.baseId,o,e.isRoot);if(d===void 0){var h=e.MissingRefError.message(e.baseId,o);if(e.opts.missingRefs=="fail"){e.logger.error(h);var m=m||[];m.push(n),n="",e.createErrors!==!1?(n+=" { keyword: '$ref' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(A)+" , params: { ref: '"+e.util.escapeQuotes(o)+"' } ",e.opts.messages!==!1&&(n+=" , message: 'can\\'t resolve reference "+e.util.escapeQuotes(o)+"' "),e.opts.verbose&&(n+=" , schema: "+e.util.toQuotedString(o)+" , parentSchema: validate.schema"+e.schemaPath+" , data: "+a+" "),n+=" } "):n+=" {} ";var f=n;n=m.pop(),!e.compositeRule&&s?e.async?n+=" throw new ValidationError(["+f+"]); ":n+=" validate.errors = ["+f+"]; return false; ":n+=" var err = "+f+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",s&&(n+=" if (false) { ")}else if(e.opts.missingRefs=="ignore")e.logger.warn(h),s&&(n+=" if (true) { ");else throw new e.MissingRefError(e.baseId,o,h)}else if(d.inline){var b=e.util.copy(e);b.level++;var p="valid"+b.level;b.schema=d.schema,b.schemaPath="",b.errSchemaPath=o;var y=e.validate(b).replace(/validate\.schema/g,d.code);n+=" "+y+" ",s&&(n+=" if ("+p+") { ")}else c=d.$async===!0||e.async&&d.$async!==!1,u=d.code}if(u){var m=m||[];m.push(n),n="",e.opts.passContext?n+=" "+u+".call(this, ":n+=" "+u+"( ",n+=" "+a+", (dataPath || '')",e.errorPath!='""'&&(n+=" + "+e.errorPath);var Z=r?"data"+(r-1||""):"parentData",v=r?e.dataPathArr[r]:"parentDataProperty";n+=" , "+Z+" , "+v+", rootData) ";var G=n;if(n=m.pop(),c){if(!e.async)throw new Error("async schema referenced by sync schema");s&&(n+=" var "+l+"; "),n+=" try { await "+G+"; ",s&&(n+=" "+l+" = true; "),n+=" } catch (e) { if (!(e instanceof ValidationError)) throw e; if (vErrors === null) vErrors = e.errors; else vErrors = vErrors.concat(e.errors); errors = vErrors.length; ",s&&(n+=" "+l+" = false; "),n+=" } ",s&&(n+=" if ("+l+") { ")}else n+=" if (!"+G+") { if (vErrors === null) vErrors = "+u+".errors; else vErrors = vErrors.concat("+u+".errors); errors = vErrors.length; } ",s&&(n+=" else { ")}return n},H$t=function(e,I,i){var n=" ",C=e.schema[I],r=e.schemaPath+e.util.getProperty(I),o=e.errSchemaPath+"/"+I,A=!e.opts.allErrors,s=e.util.copy(e),a="";s.level++;var l="valid"+s.level,c=s.baseId,u=!0,d=C;if(d)for(var h,m=-1,f=d.length-1;m0||h===!1:e.util.schemaHasRules(h,e.RULES.all))&&(u=!1,s.schema=h,s.schemaPath=r+"["+m+"]",s.errSchemaPath=o+"/"+m,n+=" "+e.validate(s)+" ",s.baseId=c,A&&(n+=" if ("+l+") { ",a+="}"));return A&&(u?n+=" if (true) { ":n+=" "+a.slice(0,-1)+" "),n},T$t=function(e,I,i){var n=" ",C=e.level,r=e.dataLevel,o=e.schema[I],A=e.schemaPath+e.util.getProperty(I),s=e.errSchemaPath+"/"+I,a=!e.opts.allErrors,l="data"+(r||""),c="valid"+C,u="errs__"+C,d=e.util.copy(e),h="";d.level++;var m="valid"+d.level,f=o.every(function(B){return e.opts.strictKeywords?typeof B=="object"&&Object.keys(B).length>0||B===!1:e.util.schemaHasRules(B,e.RULES.all)});if(f){var b=d.baseId;n+=" var "+u+" = errors; var "+c+" = false; ";var p=e.compositeRule;e.compositeRule=d.compositeRule=!0;var y=o;if(y)for(var Z,v=-1,G=y.length-1;v0||o===!1:e.util.schemaHasRules(o,e.RULES.all);if(n+="var "+u+" = errors;var "+c+";",Z){var v=e.compositeRule;e.compositeRule=d.compositeRule=!0,d.schema=o,d.schemaPath=A,d.errSchemaPath=s,n+=" var "+m+" = false; for (var "+f+" = 0; "+f+" < "+l+".length; "+f+"++) { ",d.errorPath=e.util.getPathExpr(e.errorPath,f,e.opts.jsonPointers,!0);var G=l+"["+f+"]";d.dataPathArr[b]=f;var B=e.validate(d);d.baseId=y,e.util.varOccurences(B,p)<2?n+=" "+e.util.varReplace(B,p,G)+" ":n+=" var "+p+" = "+G+"; "+B+" ",n+=" if ("+m+") break; } ",e.compositeRule=d.compositeRule=v,n+=" "+h+" if (!"+m+") {"}else n+=" if ("+l+".length == 0) {";var w=w||[];w.push(n),n="",e.createErrors!==!1?(n+=" { keyword: 'contains' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(s)+" , params: {} ",e.opts.messages!==!1&&(n+=" , message: 'should contain a valid item' "),e.opts.verbose&&(n+=" , schema: validate.schema"+A+" , parentSchema: validate.schema"+e.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ";var R=n;return n=w.pop(),!e.compositeRule&&a?e.async?n+=" throw new ValidationError(["+R+"]); ":n+=" validate.errors = ["+R+"]; return false; ":n+=" var err = "+R+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",n+=" } else { ",Z&&(n+=" errors = "+u+"; if (vErrors !== null) { if ("+u+") vErrors.length = "+u+"; else vErrors = null; } "),e.opts.allErrors&&(n+=" } "),n},K$t=function(e,I,i){var n=" ",C=e.level,r=e.dataLevel,o=e.schema[I],A=e.schemaPath+e.util.getProperty(I),s=e.errSchemaPath+"/"+I,a=!e.opts.allErrors,l="data"+(r||""),c="errs__"+C,u=e.util.copy(e),d="";u.level++;var h="valid"+u.level,m={},f={},b=e.opts.ownProperties;for(v in o)if(v!="__proto__"){var p=o[v],y=Array.isArray(p)?f:m;y[v]=p}n+="var "+c+" = errors;";var Z=e.errorPath;n+="var missing"+C+";";for(var v in f)if(y=f[v],y.length){if(n+=" if ( "+l+e.util.getProperty(v)+" !== undefined ",b&&(n+=" && Object.prototype.hasOwnProperty.call("+l+", '"+e.util.escapeQuotes(v)+"') "),a){n+=" && ( ";var G=y;if(G)for(var B,w=-1,R=G.length-1;w0||p===!1:e.util.schemaHasRules(p,e.RULES.all))&&(n+=" "+h+" = true; if ( "+l+e.util.getProperty(v)+" !== undefined ",b&&(n+=" && Object.prototype.hasOwnProperty.call("+l+", '"+e.util.escapeQuotes(v)+"') "),n+=") { ",u.schema=p,u.schemaPath=A+e.util.getProperty(v),u.errSchemaPath=s+"/"+e.util.escapeFragment(v),n+=" "+e.validate(u)+" ",u.baseId=J,n+=" } ",a&&(n+=" if ("+h+") { ",d+="}"))}return a&&(n+=" "+d+" if ("+c+" == errors) {"),n},x$t=function(e,I,i){var n=" ",C=e.level,r=e.dataLevel,o=e.schema[I],A=e.schemaPath+e.util.getProperty(I),s=e.errSchemaPath+"/"+I,a=!e.opts.allErrors,l="data"+(r||""),c="valid"+C,u=e.opts.$data&&o&&o.$data;u&&(n+=" var schema"+C+" = "+e.util.getData(o.$data,r,e.dataPathArr)+"; ");var d="i"+C,h="schema"+C;u||(n+=" var "+h+" = validate.schema"+A+";"),n+="var "+c+";",u&&(n+=" if (schema"+C+" === undefined) "+c+" = true; else if (!Array.isArray(schema"+C+")) "+c+" = false; else {"),n+=""+c+" = false;for (var "+d+"=0; "+d+"<"+h+".length; "+d+"++) if (equal("+l+", "+h+"["+d+"])) { "+c+" = true; break; }",u&&(n+=" } "),n+=" if (!"+c+") { ";var m=m||[];m.push(n),n="",e.createErrors!==!1?(n+=" { keyword: 'enum' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(s)+" , params: { allowedValues: schema"+C+" } ",e.opts.messages!==!1&&(n+=" , message: 'should be equal to one of the allowed values' "),e.opts.verbose&&(n+=" , schema: validate.schema"+A+" , parentSchema: validate.schema"+e.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ";var f=n;return n=m.pop(),!e.compositeRule&&a?e.async?n+=" throw new ValidationError(["+f+"]); ":n+=" validate.errors = ["+f+"]; return false; ":n+=" var err = "+f+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",n+=" }",a&&(n+=" else { "),n},D$t=function(e,I,i){var n=" ",C=e.level,r=e.dataLevel,o=e.schema[I],A=e.schemaPath+e.util.getProperty(I),s=e.errSchemaPath+"/"+I,a=!e.opts.allErrors,l="data"+(r||"");if(e.opts.format===!1)return a&&(n+=" if (true) { "),n;var c=e.opts.$data&&o&&o.$data,u;c?(n+=" var schema"+C+" = "+e.util.getData(o.$data,r,e.dataPathArr)+"; ",u="schema"+C):u=o;var d=e.opts.unknownFormats,h=Array.isArray(d);if(c){var m="format"+C,f="isObject"+C,b="formatType"+C;n+=" var "+m+" = formats["+u+"]; var "+f+" = typeof "+m+" == 'object' && !("+m+" instanceof RegExp) && "+m+".validate; var "+b+" = "+f+" && "+m+".type || 'string'; if ("+f+") { ",e.async&&(n+=" var async"+C+" = "+m+".async; "),n+=" "+m+" = "+m+".validate; } if ( ",c&&(n+=" ("+u+" !== undefined && typeof "+u+" != 'string') || "),n+=" (",d!="ignore"&&(n+=" ("+u+" && !"+m+" ",h&&(n+=" && self._opts.unknownFormats.indexOf("+u+") == -1 "),n+=") || "),n+=" ("+m+" && "+b+" == '"+i+"' && !(typeof "+m+" == 'function' ? ",e.async?n+=" (async"+C+" ? await "+m+"("+l+") : "+m+"("+l+")) ":n+=" "+m+"("+l+") ",n+=" : "+m+".test("+l+"))))) {"}else{var m=e.formats[o];if(!m){if(d=="ignore")return e.logger.warn('unknown format "'+o+'" ignored in schema at path "'+e.errSchemaPath+'"'),a&&(n+=" if (true) { "),n;if(h&&d.indexOf(o)>=0)return a&&(n+=" if (true) { "),n;throw new Error('unknown format "'+o+'" is used in schema at path "'+e.errSchemaPath+'"')}var f=typeof m=="object"&&!(m instanceof RegExp)&&m.validate,b=f&&m.type||"string";if(f){var p=m.async===!0;m=m.validate}if(b!=i)return a&&(n+=" if (true) { "),n;if(p){if(!e.async)throw new Error("async format in sync schema");var y="formats"+e.util.getProperty(o)+".validate";n+=" if (!(await "+y+"("+l+"))) { "}else{n+=" if (! ";var y="formats"+e.util.getProperty(o);f&&(y+=".validate"),typeof m=="function"?n+=" "+y+"("+l+") ":n+=" "+y+".test("+l+") ",n+=") { "}}var Z=Z||[];Z.push(n),n="",e.createErrors!==!1?(n+=" { keyword: 'format' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(s)+" , params: { format: ",c?n+=""+u:n+=""+e.util.toQuotedString(o),n+=" } ",e.opts.messages!==!1&&(n+=` , message: 'should match format "`,c?n+="' + "+u+" + '":n+=""+e.util.escapeQuotes(o),n+=`"' `),e.opts.verbose&&(n+=" , schema: ",c?n+="validate.schema"+A:n+=""+e.util.toQuotedString(o),n+=" , parentSchema: validate.schema"+e.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ";var v=n;return n=Z.pop(),!e.compositeRule&&a?e.async?n+=" throw new ValidationError(["+v+"]); ":n+=" validate.errors = ["+v+"]; return false; ":n+=" var err = "+v+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",n+=" } ",a&&(n+=" else { "),n},F$t=function(e,I,i){var n=" ",C=e.level,r=e.dataLevel,o=e.schema[I],A=e.schemaPath+e.util.getProperty(I),s=e.errSchemaPath+"/"+I,a=!e.opts.allErrors,l="data"+(r||""),c="valid"+C,u="errs__"+C,d=e.util.copy(e);d.level++;var h="valid"+d.level,m=e.schema.then,f=e.schema.else,b=m!==void 0&&(e.opts.strictKeywords?typeof m=="object"&&Object.keys(m).length>0||m===!1:e.util.schemaHasRules(m,e.RULES.all)),p=f!==void 0&&(e.opts.strictKeywords?typeof f=="object"&&Object.keys(f).length>0||f===!1:e.util.schemaHasRules(f,e.RULES.all)),y=d.baseId;if(b||p){var Z;d.createErrors=!1,d.schema=o,d.schemaPath=A,d.errSchemaPath=s,n+=" var "+u+" = errors; var "+c+" = true; ";var v=e.compositeRule;e.compositeRule=d.compositeRule=!0,n+=" "+e.validate(d)+" ",d.baseId=y,d.createErrors=!0,n+=" errors = "+u+"; if (vErrors !== null) { if ("+u+") vErrors.length = "+u+"; else vErrors = null; } ",e.compositeRule=d.compositeRule=v,b?(n+=" if ("+h+") { ",d.schema=e.schema.then,d.schemaPath=e.schemaPath+".then",d.errSchemaPath=e.errSchemaPath+"/then",n+=" "+e.validate(d)+" ",d.baseId=y,n+=" "+c+" = "+h+"; ",b&&p?(Z="ifClause"+C,n+=" var "+Z+" = 'then'; "):Z="'then'",n+=" } ",p&&(n+=" else { ")):n+=" if (!"+h+") { ",p&&(d.schema=e.schema.else,d.schemaPath=e.schemaPath+".else",d.errSchemaPath=e.errSchemaPath+"/else",n+=" "+e.validate(d)+" ",d.baseId=y,n+=" "+c+" = "+h+"; ",b&&p?(Z="ifClause"+C,n+=" var "+Z+" = 'else'; "):Z="'else'",n+=" } "),n+=" if (!"+c+") { var err = ",e.createErrors!==!1?(n+=" { keyword: 'if' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(s)+" , params: { failingKeyword: "+Z+" } ",e.opts.messages!==!1&&(n+=` , message: 'should match "' + `+Z+` + '" schema' `),e.opts.verbose&&(n+=" , schema: validate.schema"+A+" , parentSchema: validate.schema"+e.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ",n+="; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",!e.compositeRule&&a&&(e.async?n+=" throw new ValidationError(vErrors); ":n+=" validate.errors = vErrors; return false; "),n+=" } ",a&&(n+=" else { ")}else a&&(n+=" if (true) { ");return n},E$t=function(e,I,i){var n=" ",C=e.level,r=e.dataLevel,o=e.schema[I],A=e.schemaPath+e.util.getProperty(I),s=e.errSchemaPath+"/"+I,a=!e.opts.allErrors,l="data"+(r||""),c="valid"+C,u="errs__"+C,d=e.util.copy(e),h="";d.level++;var m="valid"+d.level,f="i"+C,b=d.dataLevel=e.dataLevel+1,p="data"+b,y=e.baseId;if(n+="var "+u+" = errors;var "+c+";",Array.isArray(o)){var Z=e.schema.additionalItems;if(Z===!1){n+=" "+c+" = "+l+".length <= "+o.length+"; ";var v=s;s=e.errSchemaPath+"/additionalItems",n+=" if (!"+c+") { ";var G=G||[];G.push(n),n="",e.createErrors!==!1?(n+=" { keyword: 'additionalItems' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(s)+" , params: { limit: "+o.length+" } ",e.opts.messages!==!1&&(n+=" , message: 'should NOT have more than "+o.length+" items' "),e.opts.verbose&&(n+=" , schema: false , parentSchema: validate.schema"+e.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ";var B=n;n=G.pop(),!e.compositeRule&&a?e.async?n+=" throw new ValidationError(["+B+"]); ":n+=" validate.errors = ["+B+"]; return false; ":n+=" var err = "+B+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",n+=" } ",s=v,a&&(h+="}",n+=" else { ")}var w=o;if(w){for(var R,S=-1,X=w.length-1;S0||R===!1:e.util.schemaHasRules(R,e.RULES.all)){n+=" "+m+" = true; if ("+l+".length > "+S+") { ";var W=l+"["+S+"]";d.schema=R,d.schemaPath=A+"["+S+"]",d.errSchemaPath=s+"/"+S,d.errorPath=e.util.getPathExpr(e.errorPath,S,e.opts.jsonPointers,!0),d.dataPathArr[b]=S;var V=e.validate(d);d.baseId=y,e.util.varOccurences(V,p)<2?n+=" "+e.util.varReplace(V,p,W)+" ":n+=" var "+p+" = "+W+"; "+V+" ",n+=" } ",a&&(n+=" if ("+m+") { ",h+="}")}}if(typeof Z=="object"&&(e.opts.strictKeywords?typeof Z=="object"&&Object.keys(Z).length>0||Z===!1:e.util.schemaHasRules(Z,e.RULES.all))){d.schema=Z,d.schemaPath=e.schemaPath+".additionalItems",d.errSchemaPath=e.errSchemaPath+"/additionalItems",n+=" "+m+" = true; if ("+l+".length > "+o.length+") { for (var "+f+" = "+o.length+"; "+f+" < "+l+".length; "+f+"++) { ",d.errorPath=e.util.getPathExpr(e.errorPath,f,e.opts.jsonPointers,!0);var W=l+"["+f+"]";d.dataPathArr[b]=f;var V=e.validate(d);d.baseId=y,e.util.varOccurences(V,p)<2?n+=" "+e.util.varReplace(V,p,W)+" ":n+=" var "+p+" = "+W+"; "+V+" ",a&&(n+=" if (!"+m+") break; "),n+=" } } ",a&&(n+=" if ("+m+") { ",h+="}")}}else if(e.opts.strictKeywords?typeof o=="object"&&Object.keys(o).length>0||o===!1:e.util.schemaHasRules(o,e.RULES.all)){d.schema=o,d.schemaPath=A,d.errSchemaPath=s,n+=" for (var "+f+" = 0; "+f+" < "+l+".length; "+f+"++) { ",d.errorPath=e.util.getPathExpr(e.errorPath,f,e.opts.jsonPointers,!0);var W=l+"["+f+"]";d.dataPathArr[b]=f;var V=e.validate(d);d.baseId=y,e.util.varOccurences(V,p)<2?n+=" "+e.util.varReplace(V,p,W)+" ":n+=" var "+p+" = "+W+"; "+V+" ",a&&(n+=" if (!"+m+") break; "),n+=" }"}return a&&(n+=" "+h+" if ("+u+" == errors) {"),n},Rse=function(e,I,i){var n=" ",C=e.level,r=e.dataLevel,o=e.schema[I],A=e.schemaPath+e.util.getProperty(I),s=e.errSchemaPath+"/"+I,a=!e.opts.allErrors,y,l="data"+(r||""),c=e.opts.$data&&o&&o.$data,u;c?(n+=" var schema"+C+" = "+e.util.getData(o.$data,r,e.dataPathArr)+"; ",u="schema"+C):u=o;var d=I=="maximum",h=d?"exclusiveMaximum":"exclusiveMinimum",m=e.schema[h],f=e.opts.$data&&m&&m.$data,b=d?"<":">",p=d?">":"<",y=void 0;if(!(c||typeof o=="number"||o===void 0))throw new Error(I+" must be number");if(!(f||m===void 0||typeof m=="number"||typeof m=="boolean"))throw new Error(h+" must be number or boolean");if(f){var Z=e.util.getData(m.$data,r,e.dataPathArr),v="exclusive"+C,G="exclType"+C,B="exclIsNumber"+C,w="op"+C,R="' + "+w+" + '";n+=" var schemaExcl"+C+" = "+Z+"; ",Z="schemaExcl"+C,n+=" var "+v+"; var "+G+" = typeof "+Z+"; if ("+G+" != 'boolean' && "+G+" != 'undefined' && "+G+" != 'number') { ";var y=h,S=S||[];S.push(n),n="",e.createErrors!==!1?(n+=" { keyword: '"+(y||"_exclusiveLimit")+"' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(s)+" , params: {} ",e.opts.messages!==!1&&(n+=" , message: '"+h+" should be boolean' "),e.opts.verbose&&(n+=" , schema: validate.schema"+A+" , parentSchema: validate.schema"+e.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ";var X=n;n=S.pop(),!e.compositeRule&&a?e.async?n+=" throw new ValidationError(["+X+"]); ":n+=" validate.errors = ["+X+"]; return false; ":n+=" var err = "+X+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",n+=" } else if ( ",c&&(n+=" ("+u+" !== undefined && typeof "+u+" != 'number') || "),n+=" "+G+" == 'number' ? ( ("+v+" = "+u+" === undefined || "+Z+" "+b+"= "+u+") ? "+l+" "+p+"= "+Z+" : "+l+" "+p+" "+u+" ) : ( ("+v+" = "+Z+" === true) ? "+l+" "+p+"= "+u+" : "+l+" "+p+" "+u+" ) || "+l+" !== "+l+") { var op"+C+" = "+v+" ? '"+b+"' : '"+b+"='; ",o===void 0&&(y=h,s=e.errSchemaPath+"/"+h,u=Z,c=f)}else{var B=typeof m=="number",R=b;if(B&&c){var w="'"+R+"'";n+=" if ( ",c&&(n+=" ("+u+" !== undefined && typeof "+u+" != 'number') || "),n+=" ( "+u+" === undefined || "+m+" "+b+"= "+u+" ? "+l+" "+p+"= "+m+" : "+l+" "+p+" "+u+" ) || "+l+" !== "+l+") { "}else{B&&o===void 0?(v=!0,y=h,s=e.errSchemaPath+"/"+h,u=m,p+="="):(B&&(u=Math[d?"min":"max"](m,o)),m===(B?u:!0)?(v=!0,y=h,s=e.errSchemaPath+"/"+h,p+="="):(v=!1,R+="="));var w="'"+R+"'";n+=" if ( ",c&&(n+=" ("+u+" !== undefined && typeof "+u+" != 'number') || "),n+=" "+l+" "+p+" "+u+" || "+l+" !== "+l+") { "}}y=y||I;var S=S||[];S.push(n),n="",e.createErrors!==!1?(n+=" { keyword: '"+(y||"_limit")+"' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(s)+" , params: { comparison: "+w+", limit: "+u+", exclusive: "+v+" } ",e.opts.messages!==!1&&(n+=" , message: 'should be "+R+" ",c?n+="' + "+u:n+=""+u+"'"),e.opts.verbose&&(n+=" , schema: ",c?n+="validate.schema"+A:n+=""+o,n+=" , parentSchema: validate.schema"+e.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ";var X=n;return n=S.pop(),!e.compositeRule&&a?e.async?n+=" throw new ValidationError(["+X+"]); ":n+=" validate.errors = ["+X+"]; return false; ":n+=" var err = "+X+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",n+=" } ",a&&(n+=" else { "),n},Wse=function(e,I,i){var n=" ",C=e.level,r=e.dataLevel,o=e.schema[I],A=e.schemaPath+e.util.getProperty(I),s=e.errSchemaPath+"/"+I,a=!e.opts.allErrors,h,l="data"+(r||""),c=e.opts.$data&&o&&o.$data,u;if(c?(n+=" var schema"+C+" = "+e.util.getData(o.$data,r,e.dataPathArr)+"; ",u="schema"+C):u=o,!(c||typeof o=="number"))throw new Error(I+" must be number");var d=I=="maxItems"?">":"<";n+="if ( ",c&&(n+=" ("+u+" !== undefined && typeof "+u+" != 'number') || "),n+=" "+l+".length "+d+" "+u+") { ";var h=I,m=m||[];m.push(n),n="",e.createErrors!==!1?(n+=" { keyword: '"+(h||"_limitItems")+"' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(s)+" , params: { limit: "+u+" } ",e.opts.messages!==!1&&(n+=" , message: 'should NOT have ",I=="maxItems"?n+="more":n+="fewer",n+=" than ",c?n+="' + "+u+" + '":n+=""+o,n+=" items' "),e.opts.verbose&&(n+=" , schema: ",c?n+="validate.schema"+A:n+=""+o,n+=" , parentSchema: validate.schema"+e.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ";var f=n;return n=m.pop(),!e.compositeRule&&a?e.async?n+=" throw new ValidationError(["+f+"]); ":n+=" validate.errors = ["+f+"]; return false; ":n+=" var err = "+f+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",n+="} ",a&&(n+=" else { "),n},Xse=function(e,I,i){var n=" ",C=e.level,r=e.dataLevel,o=e.schema[I],A=e.schemaPath+e.util.getProperty(I),s=e.errSchemaPath+"/"+I,a=!e.opts.allErrors,h,l="data"+(r||""),c=e.opts.$data&&o&&o.$data,u;if(c?(n+=" var schema"+C+" = "+e.util.getData(o.$data,r,e.dataPathArr)+"; ",u="schema"+C):u=o,!(c||typeof o=="number"))throw new Error(I+" must be number");var d=I=="maxLength"?">":"<";n+="if ( ",c&&(n+=" ("+u+" !== undefined && typeof "+u+" != 'number') || "),e.opts.unicode===!1?n+=" "+l+".length ":n+=" ucs2length("+l+") ",n+=" "+d+" "+u+") { ";var h=I,m=m||[];m.push(n),n="",e.createErrors!==!1?(n+=" { keyword: '"+(h||"_limitLength")+"' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(s)+" , params: { limit: "+u+" } ",e.opts.messages!==!1&&(n+=" , message: 'should NOT be ",I=="maxLength"?n+="longer":n+="shorter",n+=" than ",c?n+="' + "+u+" + '":n+=""+o,n+=" characters' "),e.opts.verbose&&(n+=" , schema: ",c?n+="validate.schema"+A:n+=""+o,n+=" , parentSchema: validate.schema"+e.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ";var f=n;return n=m.pop(),!e.compositeRule&&a?e.async?n+=" throw new ValidationError(["+f+"]); ":n+=" validate.errors = ["+f+"]; return false; ":n+=" var err = "+f+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",n+="} ",a&&(n+=" else { "),n},Hse=function(e,I,i){var n=" ",C=e.level,r=e.dataLevel,o=e.schema[I],A=e.schemaPath+e.util.getProperty(I),s=e.errSchemaPath+"/"+I,a=!e.opts.allErrors,h,l="data"+(r||""),c=e.opts.$data&&o&&o.$data,u;if(c?(n+=" var schema"+C+" = "+e.util.getData(o.$data,r,e.dataPathArr)+"; ",u="schema"+C):u=o,!(c||typeof o=="number"))throw new Error(I+" must be number");var d=I=="maxProperties"?">":"<";n+="if ( ",c&&(n+=" ("+u+" !== undefined && typeof "+u+" != 'number') || "),n+=" Object.keys("+l+").length "+d+" "+u+") { ";var h=I,m=m||[];m.push(n),n="",e.createErrors!==!1?(n+=" { keyword: '"+(h||"_limitProperties")+"' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(s)+" , params: { limit: "+u+" } ",e.opts.messages!==!1&&(n+=" , message: 'should NOT have ",I=="maxProperties"?n+="more":n+="fewer",n+=" than ",c?n+="' + "+u+" + '":n+=""+o,n+=" properties' "),e.opts.verbose&&(n+=" , schema: ",c?n+="validate.schema"+A:n+=""+o,n+=" , parentSchema: validate.schema"+e.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ";var f=n;return n=m.pop(),!e.compositeRule&&a?e.async?n+=" throw new ValidationError(["+f+"]); ":n+=" validate.errors = ["+f+"]; return false; ":n+=" var err = "+f+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",n+="} ",a&&(n+=" else { "),n},M$t=function(e,I,i){var n=" ",C=e.level,r=e.dataLevel,o=e.schema[I],A=e.schemaPath+e.util.getProperty(I),s=e.errSchemaPath+"/"+I,a=!e.opts.allErrors,l="data"+(r||""),c=e.opts.$data&&o&&o.$data,u;if(c?(n+=" var schema"+C+" = "+e.util.getData(o.$data,r,e.dataPathArr)+"; ",u="schema"+C):u=o,!(c||typeof o=="number"))throw new Error(I+" must be number");n+="var division"+C+";if (",c&&(n+=" "+u+" !== undefined && ( typeof "+u+" != 'number' || "),n+=" (division"+C+" = "+l+" / "+u+", ",e.opts.multipleOfPrecision?n+=" Math.abs(Math.round(division"+C+") - division"+C+") > 1e-"+e.opts.multipleOfPrecision+" ":n+=" division"+C+" !== parseInt(division"+C+") ",n+=" ) ",c&&(n+=" ) "),n+=" ) { ";var d=d||[];d.push(n),n="",e.createErrors!==!1?(n+=" { keyword: 'multipleOf' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(s)+" , params: { multipleOf: "+u+" } ",e.opts.messages!==!1&&(n+=" , message: 'should be multiple of ",c?n+="' + "+u:n+=""+u+"'"),e.opts.verbose&&(n+=" , schema: ",c?n+="validate.schema"+A:n+=""+o,n+=" , parentSchema: validate.schema"+e.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ";var h=n;return n=d.pop(),!e.compositeRule&&a?e.async?n+=" throw new ValidationError(["+h+"]); ":n+=" validate.errors = ["+h+"]; return false; ":n+=" var err = "+h+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",n+="} ",a&&(n+=" else { "),n},z$t=function(e,I,i){var n=" ",C=e.level,r=e.dataLevel,o=e.schema[I],A=e.schemaPath+e.util.getProperty(I),s=e.errSchemaPath+"/"+I,a=!e.opts.allErrors,l="data"+(r||""),c="errs__"+C,u=e.util.copy(e);u.level++;var d="valid"+u.level;if(e.opts.strictKeywords?typeof o=="object"&&Object.keys(o).length>0||o===!1:e.util.schemaHasRules(o,e.RULES.all)){u.schema=o,u.schemaPath=A,u.errSchemaPath=s,n+=" var "+c+" = errors; ";var h=e.compositeRule;e.compositeRule=u.compositeRule=!0,u.createErrors=!1;var m;u.opts.allErrors&&(m=u.opts.allErrors,u.opts.allErrors=!1),n+=" "+e.validate(u)+" ",u.createErrors=!0,m&&(u.opts.allErrors=m),e.compositeRule=u.compositeRule=h,n+=" if ("+d+") { ";var f=f||[];f.push(n),n="",e.createErrors!==!1?(n+=" { keyword: 'not' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(s)+" , params: {} ",e.opts.messages!==!1&&(n+=" , message: 'should NOT be valid' "),e.opts.verbose&&(n+=" , schema: validate.schema"+A+" , parentSchema: validate.schema"+e.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ";var b=n;n=f.pop(),!e.compositeRule&&a?e.async?n+=" throw new ValidationError(["+b+"]); ":n+=" validate.errors = ["+b+"]; return false; ":n+=" var err = "+b+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",n+=" } else { errors = "+c+"; if (vErrors !== null) { if ("+c+") vErrors.length = "+c+"; else vErrors = null; } ",e.opts.allErrors&&(n+=" } ")}else n+=" var err = ",e.createErrors!==!1?(n+=" { keyword: 'not' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(s)+" , params: {} ",e.opts.messages!==!1&&(n+=" , message: 'should NOT be valid' "),e.opts.verbose&&(n+=" , schema: validate.schema"+A+" , parentSchema: validate.schema"+e.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ",n+="; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",a&&(n+=" if (false) { ");return n},P$t=function(e,I,i){var n=" ",C=e.level,r=e.dataLevel,o=e.schema[I],A=e.schemaPath+e.util.getProperty(I),s=e.errSchemaPath+"/"+I,a=!e.opts.allErrors,l="data"+(r||""),c="valid"+C,u="errs__"+C,d=e.util.copy(e),h="";d.level++;var m="valid"+d.level,f=d.baseId,b="prevValid"+C,p="passingSchemas"+C;n+="var "+u+" = errors , "+b+" = false , "+c+" = false , "+p+" = null; ";var y=e.compositeRule;e.compositeRule=d.compositeRule=!0;var Z=o;if(Z)for(var v,G=-1,B=Z.length-1;G0||v===!1:e.util.schemaHasRules(v,e.RULES.all))?(d.schema=v,d.schemaPath=A+"["+G+"]",d.errSchemaPath=s+"/"+G,n+=" "+e.validate(d)+" ",d.baseId=f):n+=" var "+m+" = true; ",G&&(n+=" if ("+m+" && "+b+") { "+c+" = false; "+p+" = ["+p+", "+G+"]; } else { ",h+="}"),n+=" if ("+m+") { "+c+" = "+b+" = true; "+p+" = "+G+"; }";return e.compositeRule=d.compositeRule=y,n+=""+h+"if (!"+c+") { var err = ",e.createErrors!==!1?(n+=" { keyword: 'oneOf' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(s)+" , params: { passingSchemas: "+p+" } ",e.opts.messages!==!1&&(n+=" , message: 'should match exactly one schema in oneOf' "),e.opts.verbose&&(n+=" , schema: validate.schema"+A+" , parentSchema: validate.schema"+e.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ",n+="; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",!e.compositeRule&&a&&(e.async?n+=" throw new ValidationError(vErrors); ":n+=" validate.errors = vErrors; return false; "),n+="} else { errors = "+u+"; if (vErrors !== null) { if ("+u+") vErrors.length = "+u+"; else vErrors = null; }",e.opts.allErrors&&(n+=" } "),n},J$t=function(e,I,i){var n=" ",C=e.level,r=e.dataLevel,o=e.schema[I],A=e.schemaPath+e.util.getProperty(I),s=e.errSchemaPath+"/"+I,a=!e.opts.allErrors,l="data"+(r||""),c=e.opts.$data&&o&&o.$data,u;c?(n+=" var schema"+C+" = "+e.util.getData(o.$data,r,e.dataPathArr)+"; ",u="schema"+C):u=o;var d=c?"(new RegExp("+u+"))":e.usePattern(o);n+="if ( ",c&&(n+=" ("+u+" !== undefined && typeof "+u+" != 'string') || "),n+=" !"+d+".test("+l+") ) { ";var h=h||[];h.push(n),n="",e.createErrors!==!1?(n+=" { keyword: 'pattern' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(s)+" , params: { pattern: ",c?n+=""+u:n+=""+e.util.toQuotedString(o),n+=" } ",e.opts.messages!==!1&&(n+=` , message: 'should match pattern "`,c?n+="' + "+u+" + '":n+=""+e.util.escapeQuotes(o),n+=`"' `),e.opts.verbose&&(n+=" , schema: ",c?n+="validate.schema"+A:n+=""+e.util.toQuotedString(o),n+=" , parentSchema: validate.schema"+e.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ";var m=n;return n=h.pop(),!e.compositeRule&&a?e.async?n+=" throw new ValidationError(["+m+"]); ":n+=" validate.errors = ["+m+"]; return false; ":n+=" var err = "+m+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",n+="} ",a&&(n+=" else { "),n},O$t=function(e,I,i){var n=" ",C=e.level,r=e.dataLevel,o=e.schema[I],A=e.schemaPath+e.util.getProperty(I),s=e.errSchemaPath+"/"+I,a=!e.opts.allErrors,l="data"+(r||""),c="errs__"+C,u=e.util.copy(e),d="";u.level++;var h="valid"+u.level,m="key"+C,f="idx"+C,b=u.dataLevel=e.dataLevel+1,p="data"+b,y="dataProperties"+C,Z=Object.keys(o||{}).filter(F),v=e.schema.patternProperties||{},G=Object.keys(v).filter(F),B=e.schema.additionalProperties,w=Z.length||G.length,R=B===!1,S=typeof B=="object"&&Object.keys(B).length,X=e.opts.removeAdditional,W=R||S||X,V=e.opts.ownProperties,H=e.baseId,D=e.schema.required;if(D&&!(e.opts.$data&&D.$data)&&D.length8)n+=" || validate.schema"+A+".hasOwnProperty("+m+") ";else{var _=Z;if(_)for(var J,te=-1,q=_.length-1;te0||_e===!1:e.util.schemaHasRules(_e,e.RULES.all)){var At=e.util.getProperty(J),ke=l+At,wt=Oe&&_e.default!==void 0;u.schema=_e,u.schemaPath=A+At,u.errSchemaPath=s+"/"+e.util.escapeFragment(J),u.errorPath=e.util.getPath(e.errorPath,J,e.opts.jsonPointers),u.dataPathArr[b]=e.util.toQuotedString(J);var Xe=e.validate(u);if(u.baseId=H,e.util.varOccurences(Xe,p)<2){Xe=e.util.varReplace(Xe,p,ke);var rt=ke}else{var rt=p;n+=" var "+p+" = "+ke+"; "}if(wt)n+=" "+Xe+" ";else{if(Y&&Y[J]){n+=" if ( "+rt+" === undefined ",V&&(n+=" || ! Object.prototype.hasOwnProperty.call("+l+", '"+e.util.escapeQuotes(J)+"') "),n+=") { "+h+" = false; ";var ne=e.errorPath,Ce=s,Te=e.util.escapeQuotes(J);e.opts._errorDataPathProperty&&(e.errorPath=e.util.getPath(ne,J,e.opts.jsonPointers)),s=e.errSchemaPath+"/required";var Ze=Ze||[];Ze.push(n),n="",e.createErrors!==!1?(n+=" { keyword: 'required' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(s)+" , params: { missingProperty: '"+Te+"' } ",e.opts.messages!==!1&&(n+=" , message: '",e.opts._errorDataPathProperty?n+="is a required property":n+="should have required property \\'"+Te+"\\'",n+="' "),e.opts.verbose&&(n+=" , schema: validate.schema"+A+" , parentSchema: validate.schema"+e.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ";var Ge=n;n=Ze.pop(),!e.compositeRule&&a?e.async?n+=" throw new ValidationError(["+Ge+"]); ":n+=" validate.errors = ["+Ge+"]; return false; ":n+=" var err = "+Ge+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",s=Ce,e.errorPath=ne,n+=" } else { "}else a?(n+=" if ( "+rt+" === undefined ",V&&(n+=" || ! Object.prototype.hasOwnProperty.call("+l+", '"+e.util.escapeQuotes(J)+"') "),n+=") { "+h+" = true; } else { "):(n+=" if ("+rt+" !== undefined ",V&&(n+=" && Object.prototype.hasOwnProperty.call("+l+", '"+e.util.escapeQuotes(J)+"') "),n+=" ) { ");n+=" "+Xe+" } "}}a&&(n+=" if ("+h+") { ",d+="}")}}if(G.length){var le=G;if(le)for(var j,ye=-1,We=le.length-1;ye0||_e===!1:e.util.schemaHasRules(_e,e.RULES.all)){u.schema=_e,u.schemaPath=e.schemaPath+".patternProperties"+e.util.getProperty(j),u.errSchemaPath=e.errSchemaPath+"/patternProperties/"+e.util.escapeFragment(j),V?n+=" "+y+" = "+y+" || Object.keys("+l+"); for (var "+f+"=0; "+f+"<"+y+".length; "+f+"++) { var "+m+" = "+y+"["+f+"]; ":n+=" for (var "+m+" in "+l+") { ",n+=" if ("+e.usePattern(j)+".test("+m+")) { ",u.errorPath=e.util.getPathExpr(e.errorPath,m,e.opts.jsonPointers);var ke=l+"["+m+"]";u.dataPathArr[b]=m;var Xe=e.validate(u);u.baseId=H,e.util.varOccurences(Xe,p)<2?n+=" "+e.util.varReplace(Xe,p,ke)+" ":n+=" var "+p+" = "+ke+"; "+Xe+" ",a&&(n+=" if (!"+h+") break; "),n+=" } ",a&&(n+=" else "+h+" = true; "),n+=" } ",a&&(n+=" if ("+h+") { ",d+="}")}}}return a&&(n+=" "+d+" if ("+c+" == errors) {"),n},L$t=function(e,I,i){var n=" ",C=e.level,r=e.dataLevel,o=e.schema[I],A=e.schemaPath+e.util.getProperty(I),s=e.errSchemaPath+"/"+I,a=!e.opts.allErrors,l="data"+(r||""),c="errs__"+C,u=e.util.copy(e),d="";u.level++;var h="valid"+u.level;if(n+="var "+c+" = errors;",e.opts.strictKeywords?typeof o=="object"&&Object.keys(o).length>0||o===!1:e.util.schemaHasRules(o,e.RULES.all)){u.schema=o,u.schemaPath=A,u.errSchemaPath=s;var m="key"+C,f="idx"+C,b="i"+C,p="' + "+m+" + '",y=u.dataLevel=e.dataLevel+1,Z="data"+y,v="dataProperties"+C,G=e.opts.ownProperties,B=e.baseId;G&&(n+=" var "+v+" = undefined; "),G?n+=" "+v+" = "+v+" || Object.keys("+l+"); for (var "+f+"=0; "+f+"<"+v+".length; "+f+"++) { var "+m+" = "+v+"["+f+"]; ":n+=" for (var "+m+" in "+l+") { ",n+=" var startErrs"+C+" = errors; ";var w=m,R=e.compositeRule;e.compositeRule=u.compositeRule=!0;var S=e.validate(u);u.baseId=B,e.util.varOccurences(S,Z)<2?n+=" "+e.util.varReplace(S,Z,w)+" ":n+=" var "+Z+" = "+w+"; "+S+" ",e.compositeRule=u.compositeRule=R,n+=" if (!"+h+") { for (var "+b+"=startErrs"+C+"; "+b+"0||y===!1:e.util.schemaHasRules(y,e.RULES.all))||(h[h.length]=f)}}else var h=o;if(u||h.length){var Z=e.errorPath,v=u||h.length>=e.opts.loopRequired,G=e.opts.ownProperties;if(a)if(n+=" var missing"+C+"; ",v){u||(n+=" var "+d+" = validate.schema"+A+"; ");var B="i"+C,w="schema"+C+"["+B+"]",R="' + "+w+" + '";e.opts._errorDataPathProperty&&(e.errorPath=e.util.getPathExpr(Z,w,e.opts.jsonPointers)),n+=" var "+c+" = true; ",u&&(n+=" if (schema"+C+" === undefined) "+c+" = true; else if (!Array.isArray(schema"+C+")) "+c+" = false; else {"),n+=" for (var "+B+" = 0; "+B+" < "+d+".length; "+B+"++) { "+c+" = "+l+"["+d+"["+B+"]] !== undefined ",G&&(n+=" && Object.prototype.hasOwnProperty.call("+l+", "+d+"["+B+"]) "),n+="; if (!"+c+") break; } ",u&&(n+=" } "),n+=" if (!"+c+") { ";var S=S||[];S.push(n),n="",e.createErrors!==!1?(n+=" { keyword: 'required' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(s)+" , params: { missingProperty: '"+R+"' } ",e.opts.messages!==!1&&(n+=" , message: '",e.opts._errorDataPathProperty?n+="is a required property":n+="should have required property \\'"+R+"\\'",n+="' "),e.opts.verbose&&(n+=" , schema: validate.schema"+A+" , parentSchema: validate.schema"+e.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ";var X=n;n=S.pop(),!e.compositeRule&&a?e.async?n+=" throw new ValidationError(["+X+"]); ":n+=" validate.errors = ["+X+"]; return false; ":n+=" var err = "+X+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",n+=" } else { "}else{n+=" if ( ";var W=h;if(W)for(var V,B=-1,H=W.length-1;B 1) { ";var h=e.schema.items&&e.schema.items.type,m=Array.isArray(h);if(!h||h=="object"||h=="array"||m&&(h.indexOf("object")>=0||h.indexOf("array")>=0))n+=" outer: for (;i--;) { for (j = i; j--;) { if (equal("+l+"[i], "+l+"[j])) { "+c+" = false; break outer; } } } ";else{n+=" var itemIndices = {}, item; for (;i--;) { var item = "+l+"[i]; ";var f="checkDataType"+(m?"s":"");n+=" if ("+e.util[f](h,"item",e.opts.strictNumbers,!0)+") continue; ",m&&(n+=` if (typeof item == 'string') item = '"' + item; `),n+=" if (typeof itemIndices[item] == 'number') { "+c+" = false; j = itemIndices[item]; break; } itemIndices[item] = i; } "}n+=" } ",u&&(n+=" } "),n+=" if (!"+c+") { ";var b=b||[];b.push(n),n="",e.createErrors!==!1?(n+=" { keyword: 'uniqueItems' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(s)+" , params: { i: i, j: j } ",e.opts.messages!==!1&&(n+=" , message: 'should NOT have duplicate items (items ## ' + j + ' and ' + i + ' are identical)' "),e.opts.verbose&&(n+=" , schema: ",u?n+="validate.schema"+A:n+=""+o,n+=" , parentSchema: validate.schema"+e.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ";var p=n;n=b.pop(),!e.compositeRule&&a?e.async?n+=" throw new ValidationError(["+p+"]); ":n+=" validate.errors = ["+p+"]; return false; ":n+=" var err = "+p+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",n+=" } ",a&&(n+=" else { ")}else a&&(n+=" if (true) { ");return n},Q$t={$ref:X$t,allOf:H$t,anyOf:T$t,$comment:N$t,const:k$t,contains:Y$t,dependencies:K$t,enum:x$t,format:D$t,if:F$t,items:E$t,maximum:Rse,minimum:Rse,maxItems:Wse,minItems:Wse,maxLength:Xse,minLength:Xse,maxProperties:Hse,minProperties:Hse,multipleOf:M$t,not:z$t,oneOf:P$t,pattern:J$t,properties:O$t,propertyNames:L$t,required:_$t,uniqueItems:U$t,validate:N9e},Tse=Q$t,RF=by.toHash,j$t=function(){var e=[{type:"number",rules:[{maximum:["exclusiveMaximum"]},{minimum:["exclusiveMinimum"]},"multipleOf","format"]},{type:"string",rules:["maxLength","minLength","pattern","format"]},{type:"array",rules:["maxItems","minItems","items","contains","uniqueItems"]},{type:"object",rules:["maxProperties","minProperties","required","dependencies","propertyNames",{properties:["additionalProperties","patternProperties"]}]},{rules:["$ref","const","enum","not","anyOf","oneOf","allOf","if"]}],I=["type","$comment"],i=["$schema","$id","id","$data","$async","title","description","default","definitions","examples","readOnly","writeOnly","contentMediaType","contentEncoding","additionalItems","then","else"],n=["number","integer","string","array","object","boolean","null"];return e.all=RF(I),e.types=RF(n),e.forEach(function(C){C.rules=C.rules.map(function(r){var o;if(typeof r=="object"){var A=Object.keys(r)[0];o=r[A],r=A,o.forEach(function(a){I.push(a),e.all[a]=!0})}I.push(r);var s=e.all[r]={keyword:r,code:Tse[r],implements:o};return s}),e.all.$comment={keyword:"$comment",code:Tse.$comment},C.type&&(e.types[C.type]=C)}),e.keywords=RF(I.concat(i)),e.custom={},e},Nse=["multipleOf","maximum","exclusiveMaximum","minimum","exclusiveMinimum","maxLength","minLength","pattern","additionalItems","maxItems","minItems","uniqueItems","maxProperties","minProperties","required","additionalProperties","enum","format","const"],$$t=function(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function z2(g){return z2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},z2(g)}let nHe=function(g){u6t(I,g);var e=d6t(I);function I(i){var n;return a6t(this,I),n=e.call(this,i),n.state={code:i.viewConfig,hide:!1,showLog:!1,logMsgs:n.getLogMsgs(i.viewConfig)},n.handleChangeBound=n.handleChange.bind(Ul(n)),n.handleKeyDownBound=n.handleKeyDown.bind(Ul(n)),n.handleKeyUpBound=n.handleKeyUp.bind(Ul(n)),n.handleSubmitBound=n.handleSubmit.bind(Ul(n)),n.hideBound=n.hide.bind(Ul(n)),n.showBound=n.show.bind(Ul(n)),n.toggleLogBound=n.toggleLog.bind(Ul(n)),n.pubSubs=[],n.pubSubs.push(n.props.pubSub.subscribe("keydown",n.handleKeyDownBound)),n.pubSubs.push(n.props.pubSub.subscribe("keyup",n.handleKeyUpBound)),n}return s6t(I,[{key:"componentDidMount",value:async function(){this.editor&&(this.editor._input.focus(),this.editor._input.setSelectionRange(0,0),await WQ(0),this.editorWrap&&(this.editorWrap.scrollTop=0))}},{key:"componentWillUnmount",value:function(){this.pubSubs.forEach(n=>this.props.pubSub.unsubscribe(n)),this.pubSubs=[]}},{key:"handleChange",value:function(n){const C=this.getLogMsgs(n);this.setState({code:n,logMsgs:C})}},{key:"handleKeyDown",value:function(n){n.key==="s"&&(n.ctrlKey||n.metaKey)&&(n.preventDefault(),this.props.onChange(this.state.code)),n.key==="Enter"&&(n.ctrlKey||n.metaKey)&&(n.preventDefault(),this.props.onChange(this.state.code),this.props.modal.close())}},{key:"handleKeyUp",value:function(n){this.setState({hide:!1}),n.key==="Escape"&&(n.preventDefault(),this.props.modal.close(),this.props.onCancel())}},{key:"handleSubmit",value:function(n){n&&n.preventDefault(),this.props.onSave(this.state.code)}},{key:"getLogMsgs",value:function(n){const C=[];let r;try{r=JSON.parse(n)}catch(s){return console.warn(s),C.push({type:"Error",msg:s.toString()}),C}const o=new IHe().compile(iHe);return o(r)||(console.warn("Invalid viewconf"),C.push({type:"Warning",msg:"Invalid viewconf"})),o.errors&&(console.warn(JSON.stringify(o.errors,null,2)),o.errors.forEach(s=>{C.push({type:"Warning",msg:JSON.stringify(s,null,2)})})),C.length===0&&C.push({type:"Success",msg:"No error or warnings"}),C}},{key:"hide",value:function(){this.setState({hide:!0})}},{key:"show",value:function(){this.setState({hide:!1})}},{key:"hideLog",value:function(){this.setState({showLog:!1})}},{key:"showLog",value:function(){this.setState({showLog:!0})}},{key:"toggleLog",value:function(){this.state.showLog?this.hideLog():this.showLog()}},{key:"render",value:function(){const n=this.state.logMsgs.map((C,r)=>{const o=`${r}-${C.msg}`;return N.createElement("tr",{key:o},N.createElement("td",{className:Tg(Lu.title,Lu[C.type])},`[${r}] ${C.type}`),N.createElement("td",null,N.createElement("pre",null,C.msg)))});return N.createElement(Yw,{cancelShortcut:"ESC",cancelTitle:"Discard Changes",hide:this.state.hide,maxHeight:!0,okayShortcut:"⌘+Enter",okayTitle:"Save and Close",onCancel:this.props.onCancel,onOkay:this.handleSubmitBound,title:"Edit View Config"},N.createElement(N.Fragment,null,N.createElement("header",{className:Lu["view-config-editor-header"]},N.createElement(ks,{onBlur:this.showBound,onMouseDown:this.hideBound,onMouseOut:this.showBound,onMouseUp:this.showBound},"Hide While Mousedown"),N.createElement(ks,{onClick:()=>{this.props.onChange(this.state.code)},shortcut:"⌘+S"},"Save")),N.createElement("div",{ref:C=>{this.editorWrap=C},className:Lu["view-config-editor"]},N.createElement(R4t,{ref:C=>{this.editor=C},highlight:C=>Bse.highlight(C,Bse.languages.json),onValueChange:this.handleChangeBound,padding:10,style:{fontFamily:'"Fira code", "Fira Mono", monospace',fontSize:"inherit"},value:this.state.code})),N.createElement("div",{className:Lu["view-config-log"],style:{height:this.state.showLog?"50%":"30px"}},N.createElement("div",{className:Lu["view-config-log-header"],onClick:()=>this.toggleLogBound()},`Log Messages (${this.state.logMsgs.filter(C=>C.type!=="Success").length})`),N.createElement("div",{className:Lu["view-config-log-msg"],style:{padding:this.state.showLog?"10px":0}},N.createElement("table",null,N.createElement("tbody",null,n))))))}}]),I}(N.Component);nHe.propTypes={modal:L.object.isRequired,onCancel:L.func.isRequired,onChange:L.func.isRequired,onSave:L.func.isRequired,pubSub:L.object.isRequired,viewConfig:L.string.isRequired};const f6t=ry(CY(nHe));function p6t(g,e,I,i){const n=g.append("symbol").attr("id",e).attr("viewBox",i);I.forEach(C=>n.append("path").attr("d",C).attr("fill","currentColor"))}const b6t=g=>{g.setState(g.state)},y6t=function(e,I){const i=e;let n=[];const C=JN(),r=()=>{n.forEach(o=>I.unsubscribe(o)),n=[]};return{destroy:r,publish:C.publish,stack:C.stack,public:{get version(){return cXe},setBroadcastMousePositionGlobally(o=!1){i.setBroadcastMousePositionGlobally(o)},setShowGlobalMousePosition(o=!1){i.setShowGlobalMousePosition(o)},setGlobalMousePosition(o=!1){i.setBroadcastMousePositionGlobally(o),i.setShowGlobalMousePosition(o)},setAuthHeader(o){zv(o),i.reload()},getAuthHeader(){return zv()},getComponent(){return i},reload(o){let A;o?A=o.flatMap(s=>typeof s=="string"?i.iterateOverTracksInView(s):s):A=i.iterateOverTracks();for(const{viewId:s,trackId:a}of A){const l=i.getTrackObject(s,a);for(const c of l.childTracks||[l])c.fetchedTiles&&(c.removeTiles(Object.keys(c.fetchedTiles)),c.fetching.clear(),c.refreshTiles()),c.rerender(c.options,!0)}},destroy(){r(),QI.unmountComponentAtNode(i.topDiv.parentNode)},setRangeSelectionToInt(){i.setState({rangeSelectionToInt:!0})},setRangeSelectionToFloat(){i.setState({rangeSelectionToInt:!1})},setRangeSelection1dSize(o=0,A=1/0){i.setState({rangeSelection1dSize:[o,A]})},setViewConfig(o,A=!1){const s=i.processViewConfig(o);return new Promise(l=>{this.requestsInFlight=0,n.push(I.subscribe("requestSent",()=>{this.requestsInFlight+=1})),n.push(I.subscribe("requestReceived",()=>{this.requestsInFlight-=1,this.requestsInFlight===0&&l()})),i.setState({viewConfig:o,views:s},()=>{A&&l()})})},getViewConfig(){return i.getViewsAsJson()},validateViewConfig(o,{verbose:A=!1}={}){const s=new IHe().compile(iHe),a=s(o);return A&&s.errors&&console.warn(JSON.stringify(s.errors,null,2)),a},getMinMaxValue(o,A,s=!1,a=!1){return i.getMinMaxValue(o,A,s,a)},shareViewConfigAsLink(o){return i.handleExportViewsAsLink(o,!0)},showAvailableTrackPositions(o){i.setState({draggingHappening:o})},hideAvailableTrackPositions(){i.setState({draggingHappening:null})},showTrackChooser(o){i.setState({chooseTrackHandler:(...A)=>{i.setState({chooseTrackHandler:null}),o(...A)}})},hideTrackChooser(){this.setState({chooseTrackHandler:null})},setTrackValueScaleLimits(o,A,s,a){i.setTrackValueScaleLimits(o,A,s,a)},setDarkTheme(o){console.warn('`setDarkTheme(true)` is deprecated. Please use `setTheme("dark")`.');const A=o?"dark":"light";i.setTheme(A)},setTheme(o){console.warn("Please note that theming is still in beta!"),i.setTheme(o)},zoomTo(o,A,s,a,l,c=0){i.zoomTo(o,A,s,a,l,c)},zoomToGene(o,A,s=0,a=0){i.zoomToGene(o,A,s,a)},suggestGene(o,A,s){return i.suggestGene(o,A,s)},zoomToDataExtent(o){i.handleZoomToData(o)},resetViewport(o){i.resetViewport(o)},activateTool(o){switch(o){case"select":i.setMouseTool(Jr);break;default:i.setMouseTool(F9);break}},exportAsPngBlobPromise(){return i.createPNGBlobPromise()},exportAsSvg(){return i.createSVGString()},exportAsViewConfString(){return i.getViewsAsString()},getRangeSelection(){return i.rangeSelection},getLocation(o){const A=o?i.xScales[o]&&i.yScales[o]&&o:Object.values(i.tiledPlots)[0]&&Object.values(i.tiledPlots)[0].props.uid;return A?{xDomain:i.xScales[A].domain(),yDomain:i.yScales[A].domain(),xRange:i.xScales[A].range(),yRange:i.yScales[A].range()}:"Please provide a valid view UUID sweetheart 😙"},getTrackObject(o,A){let s=o,a=A;return A||(s=Object.values(i.state.views)[0].uid,a=o),NQ(i,s,a)},option(o,A){if(typeof A>"u")return i.props.options[o];switch(o){case"sizeMode":i.props.options[o]=A,b6t(i);break;default:console.warn(`This option "${o}" is either unknown or not settable.`)}},off(o,A,s){const a=typeof A=="object"?A.callback:A;switch(o){case"click":C.unsubscribe("click",a);break;case"cursorLocation":C.unsubscribe("cursorLocation",a);break;case"location":i.offLocationChange(s,A);break;case"mouseMoveZoom":C.unsubscribe("mouseMoveZoom",a);break;case"wheel":C.unsubscribe("wheel",a);break;case"rangeSelection":C.unsubscribe("rangeSelection",a);break;case"viewConfig":i.offViewChange(A);break;case"createSVG":i.offPostCreateSVG();break;case"geneSearch":C.unsubscribe("geneSearch",a);break}},on(o,A,s,a){switch(o){case"click":return C.subscribe("click",A);case"cursorLocation":return C.subscribe("cursorLocation",A);case"location":return i.onLocationChange(s,A,a);case"mouseMoveZoom":return C.subscribe("mouseMoveZoom",A);case"wheel":return C.subscribe("wheel",A);case"rangeSelection":return C.subscribe("rangeSelection",A);case"viewConfig":return i.onViewChange(A);case"createSVG":return i.onPostCreateSVG(A);case"geneSearch":return C.subscribe("geneSearch",A);default:return}}}}},Z6t="_higlass_1uoq8_1",uf={higlass:Z6t,"higlass-dark-theme":"_higlass-dark-theme_1uoq8_5","higlass-container-overflow":"_higlass-container-overflow_1uoq8_9","higlass-scroll-container-overflow":"_higlass-scroll-container-overflow_1uoq8_10","higlass-scroll-container-scroll":"_higlass-scroll-container-scroll_1uoq8_11","higlass-canvas":"_higlass-canvas_1uoq8_28","higlass-drawing-surface":"_higlass-drawing-surface_1uoq8_34","higlass-svg":"_higlass-svg_1uoq8_38","tiled-area":"_tiled-area_1uoq8_47","track-mouseover-menu":"_track-mouseover-menu_1uoq8_52"};function G6t(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function xse(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function P2(g){return P2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},P2(g)}const Dse=12,X6t=12,H6t=20,T6t="default",Fse="bounded",Ese="overflow",SZ="scroll";let yy=function(g){w6t(I,g);var e=V6t(I);function I(i){var n;G6t(this,I),n=e.call(this,i),iBe(N.version)<15.6&&console.warn("HiGlass requires React v15.6 or higher. Current version: ",N.version),n.pubSub=JN(),n.domEvent=EGe(n.pubSub),n.pubSubs=[],n.minHorizontalHeight=20,n.minVerticalWidth=20,n.resizeSensor=null,n.uid=dg.nice(),n.tiledPlots={},n.genomePositionSearchBoxes={},n.xScales={},n.yScales={},n.projectionXDomains={},n.projectionYDomains={},n.topDiv=null,n.zoomToDataExtentOnInit=new Set,n.viewTrackUidsToCombinedUid={},n.combinedUidToViewTrack={},n.scalesChangedListeners={},n.draggingChangedListeners={},n.valueScalesChangedListeners={},n.zoomLocks={},n.locationLocks={},n.locationLocksAxisWise={x:{},y:{}},n.valueScaleLocks={},n.prevAuthToken=i.options.authToken,n.setCenters={},n.plusImg={},n.configImg={},Ct.PIXI=i.options&&i.options.PIXI||Bpe,n.viewMarginTop=+i.options.viewMarginTop>=0?+i.options.viewMarginTop:$Z,n.viewMarginBottom=+i.options.viewMarginBottom>=0?+i.options.viewMarginBottom:$Z,n.viewMarginLeft=+i.options.viewMarginLeft>=0?+i.options.viewMarginLeft:$Z,n.viewMarginRight=+i.options.viewMarginRight>=0?+i.options.viewMarginRight:$Z,n.viewPaddingTop=+i.options.viewPaddingTop>=0?+i.options.viewPaddingTop:qZ,n.viewPaddingBottom=+i.options.viewPaddingBottom>=0?+i.options.viewPaddingBottom:qZ,n.viewPaddingLeft=+i.options.viewPaddingLeft>=0?+i.options.viewPaddingLeft:qZ,n.viewPaddingRight=+i.options.viewPaddingRight>=0?+i.options.viewPaddingRight:qZ,n.genomePositionSearchBox=null,n.viewHeaders={},n.boundRefreshView=()=>{n.refreshView(eG)},n.unsetOnLocationChange=[],n.setTheme(i.options.theme,i.options.isDarkTheme),n.viewconfLoaded=!1;const{viewConfig:C}=n.props,r=n.loadIfRemoteViewConfig(n.props.viewConfig);i.options.authToken&&zv(i.options.authToken),n.pixiRoot=new Ct.PIXI.Container,n.pixiRoot.interactive=!0,n.pixiStage=new Ct.PIXI.Container,n.pixiStage.interactive=!0,n.pixiRoot.addChild(n.pixiStage),n.pixiMask=new Ct.PIXI.Graphics,n.pixiRoot.addChild(n.pixiMask),n.pixiStage.mask=n.pixiMask,n.element=null,n.scrollTop=0;let o=F9;if(n.props.options)switch(n.props.options.mouseTool){case Jr:o=Jr;break}n.props.options.pluginTracks&&(window.higlassTracksByType=Object.assign(window.higlassTracksByType||{},n.props.options.pluginTracks));const A={};try{window.higlassTracksByType&&Object.entries(window.higlassTracksByType).forEach(([h,m])=>{A[h]=m})}catch{console.warn("Broken config of a plugin track")}n.props.options.pluginDataFetchers&&(window.higlassDataFetchersByType=Object.assign(window.higlassDataFetchersByType||{},n.props.options.pluginDataFetchers));const s=window.higlassDataFetchersByType,a=n.props.options.pixelPreciseMarginPadding?1:30;n.mounted=!1,n.pluginTracks=A,n.pluginDataFetchers=s,n.state={currentBreakpoint:"lg",width:0,height:0,rowHeight:a,svgElement:null,canvasElement:null,customDialog:null,views:r,viewConfig:C,addTrackPositionMenuPosition:null,typedEditable:void 0,mouseOverOverlayUid:null,mouseTool:o,isDarkTheme:!1,rangeSelection1dSize:[0,1/0],rangeSelectionToInt:!1,modal:null},n.attachedToDOM=!1;const{public:l,destroy:c,publish:u,stack:d}=y6t(tI(n),n.pubSub);return n.api=l,n.apiDestroy=c,n.apiPublish=u,n.apiStack=d,n.viewChangeListener=[],n.triggerViewChangeDb=bQ(n.triggerViewChange.bind(tI(n)),250),n.pubSubs=[],n.rangeSelection=[null,null],n.prevMouseHoverTrack=null,n.zooming=!1,n.appClickHandlerBound=n.appClickHandler.bind(tI(n)),n.canvasClickHandlerBound=n.canvasClickHandler.bind(tI(n)),n.keyDownHandlerBound=n.keyDownHandler.bind(tI(n)),n.keyUpHandlerBound=n.keyUpHandler.bind(tI(n)),n.resizeHandlerBound=n.resizeHandler.bind(tI(n)),n.resizeHandlerBound=n.resizeHandler.bind(tI(n)),n.dispatchEventBound=n.dispatchEvent.bind(tI(n)),n.animateOnMouseMoveHandlerBound=n.animateOnMouseMoveHandler.bind(tI(n)),n.zoomStartHandlerBound=n.zoomStartHandler.bind(tI(n)),n.zoomEndHandlerBound=n.zoomEndHandler.bind(tI(n)),n.zoomHandlerBound=n.zoomHandler.bind(tI(n)),n.trackDroppedHandlerBound=n.trackDroppedHandler.bind(tI(n)),n.trackDimensionsModifiedHandlerBound=n.trackDimensionsModifiedHandler.bind(tI(n)),n.animateBound=n.animate.bind(tI(n)),n.animateOnGlobalEventBound=n.animateOnGlobalEvent.bind(tI(n)),n.requestReceivedHandlerBound=n.requestReceivedHandler.bind(tI(n)),n.wheelHandlerBound=n.wheelHandler.bind(tI(n)),n.mouseMoveHandlerBound=n.mouseMoveHandler.bind(tI(n)),n.onMouseLeaveHandlerBound=n.onMouseLeaveHandler.bind(tI(n)),n.onBlurHandlerBound=n.onBlurHandler.bind(tI(n)),n.openModalBound=n.openModal.bind(tI(n)),n.closeModalBound=n.closeModal.bind(tI(n)),n.handleEditViewConfigBound=n.handleEditViewConfig.bind(tI(n)),n.onScrollHandlerBound=n.onScrollHandler.bind(tI(n)),n.typedText="",n.typedTextTimeout=null,n.modal={open:n.openModalBound,close:n.closeModalBound},n.setBroadcastMousePositionGlobally(n.props.options.broadcastMousePositionGlobally||n.props.options.globalMousePosition),n.setShowGlobalMousePosition(n.props.options.showGlobalMousePosition||n.props.options.globalMousePosition),n}return B6t(I,[{key:"UNSAFE_componentWillMount",value:function(){this.domEvent.register("keydown",document),this.domEvent.register("keyup",document),this.domEvent.register("scroll",document),this.domEvent.register("resize",window),this.domEvent.register("orientationchange",window),this.domEvent.register("wheel",window),this.domEvent.register("mousedown",window,!0),this.domEvent.register("mouseup",window,!0),this.domEvent.register("click",window,!0),this.domEvent.register("mousemove",window),this.domEvent.register("touchmove",window),this.domEvent.register("touchstart",window),this.domEvent.register("touchend",window),this.domEvent.register("touchcancel",window),this.domEvent.register("blur",window),this.pubSubs.push(this.pubSub.subscribe("app.click",this.appClickHandlerBound),this.pubSub.subscribe("blur",this.onBlurHandlerBound),this.pubSub.subscribe("keydown",this.keyDownHandlerBound),this.pubSub.subscribe("keyup",this.keyUpHandlerBound),this.pubSub.subscribe("resize",this.resizeHandlerBound),this.pubSub.subscribe("wheel",this.wheelHandlerBound),this.pubSub.subscribe("orientationchange",this.resizeHandlerBound),this.pubSub.subscribe("app.event",this.dispatchEventBound),this.pubSub.subscribe("app.animateOnMouseMove",this.animateOnMouseMoveHandlerBound),this.pubSub.subscribe("trackDropped",this.trackDroppedHandlerBound),this.pubSub.subscribe("trackDimensionsModified",this.trackDimensionsModifiedHandlerBound),this.pubSub.subscribe("app.zoomStart",this.zoomStartHandlerBound),this.pubSub.subscribe("app.zoomEnd",this.zoomEndHandlerBound),this.pubSub.subscribe("app.zoom",this.zoomHandlerBound),this.pubSub.subscribe("requestReceived",this.requestReceivedHandlerBound)),this.props.getApi&&this.props.getApi(this.api)}},{key:"sizeMode",get:function(){return typeof this.props.options.sizeMode>"u"?this.props.options.bounded?"bounded":T6t:this.props.options.sizeMode}},{key:"setBroadcastMousePositionGlobally",value:function(n=!1){this.isBroadcastMousePositionGlobally=n}},{key:"setShowGlobalMousePosition",value:function(n=!1){if(this.isShowGlobalMousePosition=n,this.isShowGlobalMousePosition&&!this.globalMousePositionListener&&(this.globalMousePositionListener=eB.subscribe("higlass.mouseMove",this.animateOnGlobalEventBound),this.pubSubs.push(this.globalMousePositionListener)),this.isShowGlobalMousePosition&&!this.globalMousePositionListener){const C=this.pubSubs.findIndex(r=>r===this.globalMousePositionListener);eB.unsubscribe(this.globalMousePositionListener),C>=0&&this.pubSubs.splice(C,1),this.globalMousePositionListener=void 0}}},{key:"zoomStartHandler",value:function(){this.hideHoverMenu(),this.zooming=!0}},{key:"zoomEndHandler",value:function(){this.zooming=!1}},{key:"zoomHandler",value:function(n){n.sourceEvent&&this.mouseMoveHandler(n.sourceEvent)}},{key:"waitForDOMAttachment",value:function(n){if(!this.mounted)return;const C=QI.findDOMNode(this);document.body.contains(C)?n():requestAnimationFrame(()=>this.waitForDOMAttachment(n))}},{key:"componentDidMount",value:function(){this.mounted=!0,this.element=QI.findDOMNode(this),window.addEventListener("focus",this.boundRefreshView),Object.values(this.state.views).forEach(o=>{this.adjustLayoutToTrackSizes(o),o.layout?o.layout.i=o.uid:o.layout=this.generateViewLayout(o)});const n={width:this.state.width,height:this.state.height,view:this.canvasElement,antialias:!0,transparent:!0,resolution:2,autoResize:!0},C=parseInt(ofe[0],10);C===4?(console.warn("Deprecation warning: please update Pixi.js to version 5 or above!"),this.props.options.renderer==="canvas"?this.pixiRenderer=new Ct.PIXI.CanvasRenderer(n):this.pixiRenderer=new Ct.PIXI.WebGLRenderer(n)):(C<4&&console.warn("Deprecation warning: please update Pixi.js to version 5 or above! This version of Pixi.js is unsupported. Good luck 🤞"),this.props.options.renderer==="canvas"?this.pixiRenderer=new Ct.PIXI.CanvasRenderer(n):this.pixiRenderer=new Ct.PIXI.Renderer(n)),this.fitPixiToParentContainer(),this.setState({svgElement:this.svgElement,canvasElement:this.canvasElement}),this.waitForDOMAttachment(()=>{N9.ElementQueries.listen(),this.resizeSensor=new N9.ResizeSensor(this.element.parentNode,this.updateAfterResize.bind(this)),this.updateAfterResize()}),this.handleDragStart(),this.handleDragStop(),this.animate();const r=pg(this.element).append("svg").style("display","none");Vot.forEach(o=>p6t(r,o.id,o.paths,o.viewBox))}},{key:"getTrackObject",value:function(n,C){return this.tiledPlots[n].trackRenderer.getTrackObject(C)}},{key:"getTrackRenderer",value:function(n){return this.tiledPlots[n].trackRenderer}},{key:"loadIfRemoteViewConfig",value:function(n){let C={};return typeof n=="string"?vt.json(n,(r,o)=>{n=o,this.setState({views:this.processViewConfig(JSON.parse(JSON.stringify(o))),viewConfig:o}),this.unsetOnLocationChange.forEach(({viewId:A,callback:s,callbackId:a})=>{this.onLocationChange(A,s,a)})},this.pubSub):(C=this.processViewConfig(JSON.parse(JSON.stringify(n))),this.mounted&&this.setState({viewConfig:n})),C}},{key:"UNSAFE_componentWillReceiveProps",value:function(n){const C=this.loadIfRemoteViewConfig(n.viewConfig);if(n.options.authToken!==this.prevAuthToken){zv(n.options.authToken);for(const r of this.iterateOverViews()){const o=this.getTrackRenderer(r),A=JSON.parse(o.prevTrackDefinitions);o.syncTrackObjects([]),o.syncTrackObjects(A)}this.prevAuthToken=n.options.authToken}for(const r of Pg(C))this.adjustLayoutToTrackSizes(r);this.setState({views:C})}},{key:"UNSAFE_componentWillUpdate",value:function(){this.pixiRenderer.render(this.pixiRoot)}},{key:"componentDidUpdate",value:function(){this.setTheme(this.props.options.theme,this.props.options.isDarkTheme),this.animate(),this.triggerViewChangeDb()}},{key:"componentWillUnmount",value:function(){this.mounted=!1,this.pixiStage.destroy(!1),this.pixiStage=null,this.pixiRenderer.destroy(!0),this.pixiRenderer=null,window.removeEventListener("focus",this.boundRefreshView),this.resizeSensor&&this.resizeSensor.detach(),this.domEvent.unregister("keydown",document),this.domEvent.unregister("keyup",document),this.domEvent.unregister("scroll",document),this.domEvent.unregister("wheel",window),this.domEvent.unregister("mousedown",window),this.domEvent.unregister("mouseup",window),this.domEvent.unregister("click",window),this.domEvent.unregister("mousemove",window),this.domEvent.unregister("touchmove",window),this.domEvent.unregister("touchstart",window),this.domEvent.unregister("touchend",window),this.domEvent.unregister("touchcancel",window),this.pubSubs.forEach(n=>this.pubSub.unsubscribe(n)),this.pubSubs=[],this.apiDestroy()}},{key:"setTheme",value:function(n=this.props.options.theme,C=this.props.options.isDarkTheme){if(typeof C<"u")console.warn("The option `isDarkTheme` is deprecated. Please use `theme` instead."),this.theme=C?"dark":"light";else switch(n){case"dark":this.theme=II;break;case"light":case void 0:this.theme=M9;break;default:console.warn(`Unknown theme "${n}". Using light theme.`),this.theme=M9;break}}},{key:"dispatchEvent",value:function(n){this.canvasElement&&J9(n,this.canvasElement)}},{key:"trackDroppedHandler",value:function(){this.setState({draggingHappening:null})}},{key:"requestReceivedHandler",value:function(){!this.viewconfLoaded&&Mv===0&&(this.viewconfLoaded=!0,this.props.options.onViewConfLoaded&&this.props.options.onViewConfLoaded())}},{key:"animateOnMouseMoveHandler",value:function(n){n&&!this.animateOnMouseMove&&this.pubSubs.push(this.pubSub.subscribe("app.mouseMove",this.animateBound)),this.animateOnMouseMove=n}},{key:"fitPixiToParentContainer",value:function(){if(!this.element||!this.element.parentNode){console.warn("No parentNode:",this.element);return}const n=this.element.parentNode.clientWidth,C=this.element.parentNode.clientHeight;this.pixiMask.beginFill(16777215).drawRect(0,0,n,C).endFill(),this.pixiRenderer.resize(n,C),this.pixiRenderer.view.style.width=`${n}px`,this.pixiRenderer.view.style.height=`${C}px`,this.pixiRenderer.render(this.pixiRoot)}},{key:"addDefaultTrackOptions",value:function(n){const C=this.getTrackInfo(n.type);if(!C)return;typeof n.options>"u"&&(n.options={});const r=n.options?n.options:{};if(this.props.options.defaultTrackOptions){if(this.props.options.defaultTrackOptions.trackSpecific&&this.props.options.defaultTrackOptions.trackSpecific[n.type]){const o=this.props.options.defaultTrackOptions.trackSpecific[n.type];for(const A in o)n.options[A]=typeof n.options[A]<"u"?n.options[A]:JSON.parse(JSON.stringify(o[A]))}if(this.props.options.defaultTrackOptions.all){const o=this.props.options.defaultTrackOptions.all;for(const A in o)n.options[A]=typeof n.options[A]<"u"?n.options[A]:JSON.parse(JSON.stringify(o[A]))}}if(C.defaultOptions){const o=C.defaultOptionsByTheme&&C.defaultOptionsByTheme[this.theme]?C.defaultOptionsByTheme[this.theme]:{},A={...C.defaultOptions,...o};if(!n.options)n.options=JSON.parse(JSON.stringify(A));else for(const s in A)n.options[s]=typeof n.options[s]<"u"?n.options[s]:JSON.parse(JSON.stringify(A[s]))}else n.options=r}},{key:"toggleTypedEditable",value:function(){this.setState({typedEditable:!this.isEditable()})}},{key:"typedTextHandler",value:function(n){if(!this.props.options.cheatCodesEnabled)return;this.typedText=this.typedText.concat(n.key),this.typedText.endsWith("hgedit")&&(this.toggleTypedEditable(),this.typedText="");const C=750;this.typedTextTimeout&&clearTimeout(this.typedTextTimeout),this.typedTextTimeout=setTimeout(()=>{this.typedText=""},C)}},{key:"keyDownHandler",value:function(n){this.typedTextHandler(n),this.props.options.rangeSelectionOnAlt&&n.key==="Alt"&&this.setState({mouseTool:Jr})}},{key:"keyUpHandler",value:function(n){this.props.options.rangeSelectionOnAlt&&n.key==="Alt"&&this.setState({mouseTool:F9})}},{key:"openModal",value:function(n){this.setState({modal:N.cloneElement(n,{ref:C=>{this.modalRef=C}})})}},{key:"closeModal",value:function(){this.modalRef=null,this.setState({modal:null})}},{key:"handleEditViewConfig",value:function(){const{viewConfig:n}=this.state;this.setState({viewConfigTmp:n}),this.openModal(N.createElement(f6t,{onCancel:()=>{const{viewConfigTmp:C}=this.state,r=this.processViewConfig(C);for(const o of Pg(r))this.adjustLayoutToTrackSizes(o);this.setState({views:r,viewConfig:C,viewConfigTmp:null})},onChange:C=>{const r=JSON.parse(C),o=this.processViewConfig(r);for(const A of Pg(o))this.adjustLayoutToTrackSizes(A);this.setState({views:o,viewConfig:r})},onSave:C=>{const r=JSON.parse(C),o=this.processViewConfig(r);for(const A of Pg(o))this.adjustLayoutToTrackSizes(A);this.setState({views:o,viewConfig:r,viewConfigTmp:null})},viewConfig:this.getViewsAsString()}))}},{key:"animate",value:function(){this.isRequestingAnimationFrame||(this.isRequestingAnimationFrame=!0,requestAnimationFrame(()=>{this.pixiRenderer&&(this.pixiRenderer.render(this.pixiRoot),this.isRequestingAnimationFrame=!1)}))}},{key:"animateOnGlobalEvent",value:function({sourceUid:n}={}){n!==this.uid&&this.animateOnMouseMove&&this.animate()}},{key:"measureSize",value:function(){const[n,C]=JGe(this.element);n>0&&C>0&&this.setState({sizeMeasured:!0,width:n,height:C})}},{key:"updateAfterResize",value:function(){this.measureSize(),this.updateRowHeight(),this.fitPixiToParentContainer(),this.refreshView(eG),this.resizeHandler()}},{key:"onBreakpointChange",value:function(n){this.setState({currentBreakpoint:n})}},{key:"handleOverlayMouseEnter",value:function(n){this.setState({mouseOverOverlayUid:n})}},{key:"handleOverlayMouseLeave",value:function(){this.setState({mouseOverOverlayUid:null})}},{key:"handleLockLocation",value:function(n){this.setState({chooseViewHandler:C=>this.handleLocationLockChosen(n,C),mouseOverOverlayUid:n})}},{key:"isEditable",value:function(){return this.state.typedEditable!==void 0?this.state.typedEditable:!this.props.options||!("editable"in this.props.options)?this.state.viewConfig.editable:this.props.options.editable&&this.state.viewConfig.editable}},{key:"isTrackMenuDisabled",value:function(){return this.props.options&&(this.props.options.editable===!1||this.props.options.tracksEditable===!1)?!0:this.state.viewConfig&&(this.state.viewConfig.tracksEditable===!1||this.state.viewConfig.editable===!1)}},{key:"isViewHeaderDisabled",value:function(){return this.props.options&&(this.props.options.editable===!1||this.props.options.viewEditable===!1)?!0:this.state.viewConfig&&(this.state.viewConfig.viewEditable===!1||this.state.viewConfig.editable===!1)}},{key:"iterateOverViews",value:function(){const n=[];for(const C in Object.keys(this.state.views))n.push(C);return n}},{key:"iterateOverTracksInView",value:function(n){const C=[],{tracks:r}=this.state.views[n];for(const o in r)for(const A of r[o])if(A.type==="combined"&&A.contents)for(const s of A.contents)C.push({viewId:n,trackId:s.uid,track:s});else C.push({viewId:n,trackId:A.uid,track:A});return C}},{key:"iterateOverTracks",value:function(){const n=[];for(const C in this.state.views){const{tracks:r}=this.state.views[C];for(const o in r)for(const A of r[o])if(A.type==="combined"&&A.contents)for(const s of A.contents)n.push({viewId:C,trackId:s.uid,track:s});else n.push({viewId:C,trackId:A.uid,track:A})}return n}},{key:"setMouseTool",value:function(n){this.setState({mouseTool:n})}},{key:"isValueScaleLocked",value:function(n,C){const r=this.combineViewAndTrackUid(n,C);return this.state.views[n]?!!this.valueScaleLocks[r]:!1}},{key:"getLockGroupExtrema",value:function(n,C){const r=this.combineViewAndTrackUid(n,C);if(!this.state.views[n]||!this.valueScaleLocks[r])return null;const o=this.valueScaleLocks[r],A=Object.values(o).filter(u=>this.tiledPlots[u.view]).map(u=>this.tiledPlots[u.view].trackRenderer.getTrackObject(u.track)).filter(u=>u).map(u=>u.originalTrack===void 0?u:u.originalTrack),s=A.filter(u=>u.minRawValue&&u.maxRawValue).map(u=>o.ignoreOffScreenValues?u.minVisibleValue(!0):u.minVisibleValueInTiles(!0)),a=A.filter(u=>u.minRawValue&&u.maxRawValue).map(u=>o.ignoreOffScreenValues?u.maxVisibleValue(!0):u.maxVisibleValueInTiles(!0));if(s.length===0||s.filter(u=>u===null||u===1/0).length>0||a.length===0||a.filter(u=>u===null||u===-1/0).length>0)return null;const l=Math.min(...s),c=Math.max(...a);return[l,c]}},{key:"syncValueScales",value:function(n,C){const r=this.combineViewAndTrackUid(n,C);if(!this.state.views[n])return;const o=gr(this.state.views[n].tracks,C);if(this.valueScaleLocks[r]){const A=this.valueScaleLocks[r],s=Object.values(A).filter(d=>this.tiledPlots[d.view]).map(d=>this.tiledPlots[d.view].trackRenderer.getTrackObject(d.track)).filter(d=>d).map(d=>d.originalTrack===void 0?d:d.originalTrack),a=this.getLockGroupExtrema(n,C);if(a===null)return;const l=a[0],c=a[1],u=1e-6;for(const d of s){if(d.minValue&&d.minValue(l),d.maxValue&&d.maxValue(c),!d.valueScale)continue;const h=Math.abs(d.minValue()-d.valueScale.domain()[0])>u||Math.abs(d.maxValue()-d.valueScale.domain()[1])>u,m=o.options&&d.options&&typeof o.options.scaleStartPercent<"u"&&typeof o.options.scaleEndPercent<"u"&&(Math.abs(d.options.scaleStartPercent-o.options.scaleStartPercent)>u||Math.abs(d.options.scaleEndPercent-o.options.scaleEndPercent)>u);d.continuousScaling&&!h&&!m||(d.valueScale.domain([l,c]),d.prevValueScale=d.valueScale.copy(),m&&(d.options.scaleStartPercent=o.options.scaleStartPercent,d.options.scaleEndPercent=o.options.scaleEndPercent),d.rerender(d.options,!0))}}}},{key:"handleNewTilesLoaded",value:function(n,C){this.animate()}},{key:"notifyDragChangedListeners",value:function(n){Pg(this.draggingChangedListeners).forEach(C=>{Pg(C).forEach(r=>r(n))})}},{key:"addDraggingChangedListener",value:function(n,C,r){this.draggingChangedListeners.hasOwnProperty(n)||(this.draggingChangedListeners[n]={}),this.draggingChangedListeners[n][C]=r,r(!0),r(!1)}},{key:"removeDraggingChangedListener",value:function(n,C){if(this.draggingChangedListeners.hasOwnProperty(n)){const r=this.draggingChangedListeners[n];r.hasOwnProperty(C)&&(r[C](!1),delete r[C])}}},{key:"addScalesChangedListener",value:function(n,C,r){this.scalesChangedListeners[n]||(this.scalesChangedListeners[n]={}),this.scalesChangedListeners[n][C]=r,!(!this.xScales[n]||!this.yScales[n])&&r(this.xScales[n],this.yScales[n])}},{key:"removeScalesChangedListener",value:function(n,C){if(this.scalesChangedListeners[n]){const r=this.scalesChangedListeners[n];r[C]&&delete r[C]}}},{key:"createSVG",value:function(){const n=document.createElement("svg");n.setAttribute("xmlns:xlink","http://www.w3.org/1999/xlink"),n.setAttribute("xmlns","http://www.w3.org/2000/svg"),n.setAttribute("version","1.1");for(const C of Pg(this.tiledPlots))if(C){for(const r of Pg(C.trackRenderer.trackDefObjects))if(r.trackObject.exportSVG){const o=r.trackObject.exportSVG();o&&n.appendChild(o[0])}}return n.setAttribute("width",this.canvasElement.style.width),n.setAttribute("height",this.canvasElement.style.height),this.postCreateSVGCallback?this.postCreateSVGCallback(n):n}},{key:"createSVGString",value:function(){const n=this.createSVG();let C=Fnt.xml(new window.XMLSerializer().serializeToString(n));return C=C.replace(/ + */var I=function(i){var n=/(?:^|\s)lang(?:uage)?-([\w-]+)(?=\s|$)/i,C=0,r={},o={manual:i.Prism&&i.Prism.manual,disableWorkerMessageHandler:i.Prism&&i.Prism.disableWorkerMessageHandler,util:{encode:function b(p){return p instanceof A?new A(p.type,b(p.content),p.alias):Array.isArray(p)?p.map(b):p.replace(/&/g,"&").replace(/"u")return null;if("currentScript"in document&&1<2)return document.currentScript;try{throw new Error}catch(Z){var b=(/at [^(\r\n]*\((.*):[^:]+:[^:]+\)$/i.exec(Z.stack)||[])[1];if(b){var p=document.getElementsByTagName("script");for(var y in p)if(p[y].src==b)return p[y]}return null}},isActive:function(b,p,y){for(var Z="no-"+p;b;){var B=b.classList;if(B.contains(p))return!0;if(B.contains(Z))return!1;b=b.parentElement}return!!y}},languages:{plain:r,plaintext:r,text:r,txt:r,extend:function(b,p){var y=o.util.clone(o.languages[b]);for(var Z in p)y[Z]=p[Z];return y},insertBefore:function(b,p,y,Z){Z=Z||o.languages;var B=Z[b],G={};for(var v in B)if(B.hasOwnProperty(v)){if(v==p)for(var w in y)y.hasOwnProperty(w)&&(G[w]=y[w]);y.hasOwnProperty(v)||(G[v]=B[v])}var V=Z[b];return Z[b]=G,o.languages.DFS(o.languages,function(S,X){X===V&&S!=b&&(this[S]=G)}),G},DFS:function b(p,y,Z,B){B=B||{};var G=o.util.objId;for(var v in p)if(p.hasOwnProperty(v)){y.call(p,v,p[v],Z||v);var w=p[v],V=o.util.type(w);V==="Object"&&!B[G(w)]?(B[G(w)]=!0,b(w,y,null,B)):V==="Array"&&!B[G(w)]&&(B[G(w)]=!0,b(w,y,v,B))}}},plugins:{},highlightAll:function(b,p){o.highlightAllUnder(document,b,p)},highlightAllUnder:function(b,p,y){var Z={callback:y,container:b,selector:'code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code'};o.hooks.run("before-highlightall",Z),Z.elements=Array.prototype.slice.apply(Z.container.querySelectorAll(Z.selector)),o.hooks.run("before-all-elements-highlight",Z);for(var B=0,G;G=Z.elements[B++];)o.highlightElement(G,p===!0,Z.callback)},highlightElement:function(b,p,y){var Z=o.util.getLanguage(b),B=o.languages[Z];o.util.setLanguage(b,Z);var G=b.parentElement;G&&G.nodeName.toLowerCase()==="pre"&&o.util.setLanguage(G,Z);var v=b.textContent,w={element:b,language:Z,grammar:B,code:v};function V(X){w.highlightedCode=X,o.hooks.run("before-insert",w),w.element.innerHTML=w.highlightedCode,o.hooks.run("after-highlight",w),o.hooks.run("complete",w),y&&y.call(w.element)}if(o.hooks.run("before-sanity-check",w),G=w.element.parentElement,G&&G.nodeName.toLowerCase()==="pre"&&!G.hasAttribute("tabindex")&&G.setAttribute("tabindex","0"),!w.code){o.hooks.run("complete",w),y&&y.call(w.element);return}if(o.hooks.run("before-highlight",w),!w.grammar){V(o.util.encode(w.code));return}if(p&&i.Worker){var S=new Worker(o.filename);S.onmessage=function(X){V(X.data)},S.postMessage(JSON.stringify({language:w.language,code:w.code,immediateClose:!0}))}else V(o.highlight(w.code,w.grammar,w.language))},highlight:function(b,p,y){var Z={code:b,grammar:p,language:y};if(o.hooks.run("before-tokenize",Z),!Z.grammar)throw new Error('The language "'+Z.language+'" has no grammar.');return Z.tokens=o.tokenize(Z.code,Z.grammar),o.hooks.run("after-tokenize",Z),A.stringify(o.util.encode(Z.tokens),Z.language)},tokenize:function(b,p){var y=p.rest;if(y){for(var Z in y)p[Z]=y[Z];delete p.rest}var B=new l;return c(B,B.head,b),a(b,B,p,B.head,0),d(B)},hooks:{all:{},add:function(b,p){var y=o.hooks.all;y[b]=y[b]||[],y[b].push(p)},run:function(b,p){var y=o.hooks.all[b];if(!(!y||!y.length))for(var Z=0,B;B=y[Z++];)B(p)}},Token:A};i.Prism=o;function A(b,p,y,Z){this.type=b,this.content=p,this.alias=y,this.length=(Z||"").length|0}A.stringify=function b(p,y){if(typeof p=="string")return p;if(Array.isArray(p)){var Z="";return p.forEach(function(V){Z+=b(V,y)}),Z}var B={type:p.type,content:b(p.content,y),tag:"span",classes:["token",p.type],attributes:{},language:y},G=p.alias;G&&(Array.isArray(G)?Array.prototype.push.apply(B.classes,G):B.classes.push(G)),o.hooks.run("wrap",B);var v="";for(var w in B.attributes)v+=" "+w+'="'+(B.attributes[w]||"").replace(/"/g,""")+'"';return"<"+B.tag+' class="'+B.classes.join(" ")+'"'+v+">"+B.content+""};function s(b,p,y,Z){b.lastIndex=p;var B=b.exec(y);if(B&&Z&&B[1]){var G=B[1].length;B.index+=G,B[0]=B[0].slice(G)}return B}function a(b,p,y,Z,B,G){for(var v in y)if(!(!y.hasOwnProperty(v)||!y[v])){var w=y[v];w=Array.isArray(w)?w:[w];for(var V=0;V=G.reach);O+=E.value.length,E=E.next){var J=E.value;if(p.length>b.length)return;if(!(J instanceof A)){var ee=1,q;if(R){if(q=s(D,O,b,W),!q||q.index>=b.length)break;var U=q.index,$=q.index+q[0].length,j=O;for(j+=E.value.length;U>=j;)E=E.next,j+=E.value.length;if(j-=E.value.length,O=j,E.value instanceof A)continue;for(var te=E;te!==p.tail&&(j<$||typeof te.value=="string");te=te.next)ee++,j+=te.value.length;ee--,J=b.slice(O,j),q.index-=O}else if(q=s(D,0,J,W),!q)continue;var U=q.index,ie=q[0],me=J.slice(0,U),Ce=J.slice(U+ie.length),Ze=O+J.length;G&&Ze>G.reach&&(G.reach=Ze);var Ge=E.prev;me&&(Ge=c(p,Ge,me),O+=me.length),u(p,Ge,ee);var Be=new A(v,X?o.tokenize(ie,X):ie,H,ie);if(E=c(p,Ge,Be),Ce&&c(p,E,Ce),ee>1){var Ne={cause:v+","+V,reach:Ze};a(b,p,y,E.prev,O,Ne),G&&Ne.reach>G.reach&&(G.reach=Ne.reach)}}}}}}function l(){var b={value:null,prev:null,next:null},p={value:null,prev:b,next:null};b.next=p,this.head=b,this.tail=p,this.length=0}function c(b,p,y){var Z=p.next,B={value:y,prev:p,next:Z};return p.next=B,Z.prev=B,b.length++,B}function u(b,p,y){for(var Z=p.next,B=0;B1){x[0]=x[0].slice(0,-1);for(var ce=x.length-1,de=1;de= 0x80 (not a basic code point)","invalid-input":"Invalid input"},S=h-m,X=Math.floor,W=String.fromCharCode;function R(P){throw new RangeError(V[P])}function H(P,x){for(var Q=[],ce=P.length;ce--;)Q[ce]=x(P[ce]);return Q}function Y(P,x){var Q=P.split("@"),ce="";Q.length>1&&(ce=Q[0]+"@",P=Q[1]),P=P.replace(w,".");var de=P.split("."),Je=H(de,x).join(".");return ce+Je}function D(P){for(var x=[],Q=0,ce=P.length;Q=55296&&de<=56319&&Q>1,x+=X(x/Q);x>S*f>>1;de+=h)x=X(x/S);return X(de+(S+1)*x/(x+b))},q=function(x){var Q=[],ce=x.length,de=0,Je=Z,Oe=y,lt=x.lastIndexOf(B);lt<0&&(lt=0);for(var pt=0;pt=128&&R("not-basic"),Q.push(x.charCodeAt(pt));for(var kt=lt>0?lt+1:0;kt=ce&&R("invalid-input");var At=O(x.charCodeAt(kt++));(At>=h||At>X((d-de)/Vt))&&R("overflow"),de+=At*Vt;var Xt=Ft<=Oe?m:Ft>=Oe+f?f:Ft-Oe;if(AtX(d/Pt)&&R("overflow"),Vt*=Pt}var Dt=Q.length+1;Oe=ee(de-ut,Dt,ut==0),X(de/Dt)>d-Je&&R("overflow"),Je+=X(de/Dt),de%=Dt,Q.splice(de++,0,Je)}return String.fromCodePoint.apply(String,Q)},$=function(x){var Q=[];x=D(x);var ce=x.length,de=Z,Je=0,Oe=y,lt=!0,pt=!1,kt=void 0;try{for(var ut=x[Symbol.iterator](),Vt;!(lt=(Vt=ut.next()).done);lt=!0){var Ft=Vt.value;Ft<128&&Q.push(W(Ft))}}catch(cC){pt=!0,kt=cC}finally{try{!lt&&ut.return&&ut.return()}finally{if(pt)throw kt}}var At=Q.length,Xt=At;for(At&&Q.push(B);Xt=de&&LtX((d-Je)/Yt)&&R("overflow"),Je+=(Pt-de)*Yt,de=Pt;var Wt=!0,$t=!1,_t=void 0;try{for(var jt=x[Symbol.iterator](),rg;!(Wt=(rg=jt.next()).done);Wt=!0){var wg=rg.value;if(wgd&&R("overflow"),wg==de){for(var ug=Je,MI=h;;MI+=h){var Ui=MI<=Oe?m:MI>=Oe+f?f:MI-Oe;if(ug>6|192).toString(16).toUpperCase()+"%"+(x&63|128).toString(16).toUpperCase():Q="%"+(x>>12|224).toString(16).toUpperCase()+"%"+(x>>6&63|128).toString(16).toUpperCase()+"%"+(x&63|128).toString(16).toUpperCase(),Q}function Ce(P){for(var x="",Q=0,ce=P.length;Q=194&&de<224){if(ce-Q>=6){var Je=parseInt(P.substr(Q+4,2),16);x+=String.fromCharCode((de&31)<<6|Je&63)}else x+=P.substr(Q,6);Q+=6}else if(de>=224){if(ce-Q>=9){var Oe=parseInt(P.substr(Q+4,2),16),lt=parseInt(P.substr(Q+7,2),16);x+=String.fromCharCode((de&15)<<12|(Oe&63)<<6|lt&63)}else x+=P.substr(Q,9);Q+=9}else x+=P.substr(Q,3),Q+=3}return x}function Ze(P,x){function Q(ce){var de=Ce(ce);return de.match(x.UNRESERVED)?de:ce}return P.scheme&&(P.scheme=String(P.scheme).replace(x.PCT_ENCODED,Q).toLowerCase().replace(x.NOT_SCHEME,"")),P.userinfo!==void 0&&(P.userinfo=String(P.userinfo).replace(x.PCT_ENCODED,Q).replace(x.NOT_USERINFO,me).replace(x.PCT_ENCODED,r)),P.host!==void 0&&(P.host=String(P.host).replace(x.PCT_ENCODED,Q).toLowerCase().replace(x.NOT_HOST,me).replace(x.PCT_ENCODED,r)),P.path!==void 0&&(P.path=String(P.path).replace(x.PCT_ENCODED,Q).replace(P.scheme?x.NOT_PATH:x.NOT_PATH_NOSCHEME,me).replace(x.PCT_ENCODED,r)),P.query!==void 0&&(P.query=String(P.query).replace(x.PCT_ENCODED,Q).replace(x.NOT_QUERY,me).replace(x.PCT_ENCODED,r)),P.fragment!==void 0&&(P.fragment=String(P.fragment).replace(x.PCT_ENCODED,Q).replace(x.NOT_FRAGMENT,me).replace(x.PCT_ENCODED,r)),P}function Ge(P){return P.replace(/^0*(.*)/,"$1")||"0"}function Be(P,x){var Q=P.match(x.IPV4ADDRESS)||[],ce=c(Q,2),de=ce[1];return de?de.split(".").map(Ge).join("."):P}function Ne(P,x){var Q=P.match(x.IPV6ADDRESS)||[],ce=c(Q,3),de=ce[1],Je=ce[2];if(de){for(var Oe=de.toLowerCase().split("::").reverse(),lt=c(Oe,2),pt=lt[0],kt=lt[1],ut=kt?kt.split(":").map(Ge):[],Vt=pt.split(":").map(Ge),Ft=x.IPV4ADDRESS.test(Vt[Vt.length-1]),At=Ft?7:8,Xt=Vt.length-At,Pt=Array(At),Dt=0;Dt1){var bt=Pt.slice(0,Qg.index),Lt=Pt.slice(Qg.index+Qg.length);et=bt.join(":")+"::"+Lt.join(":")}else et=Pt.join(":");return Je&&(et+="%"+Je),et}else return P}var Se=/^(?:([^:\/?#]+):)?(?:\/\/((?:([^\/?#@]*)@)?(\[[^\/?#\]]+\]|[^\/?#:]*)(?:\:(\d*))?))?([^?#]*)(?:\?([^#]*))?(?:#((?:.|\n|\r)*))?/i,Pe="".match(/(){0}/)[1]===void 0;function ze(P){var x=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},Q={},ce=x.iri!==!1?l:a;x.reference==="suffix"&&(P=(x.scheme?x.scheme+":":"")+"//"+P);var de=P.match(Se);if(de){Pe?(Q.scheme=de[1],Q.userinfo=de[3],Q.host=de[4],Q.port=parseInt(de[5],10),Q.path=de[6]||"",Q.query=de[7],Q.fragment=de[8],isNaN(Q.port)&&(Q.port=de[5])):(Q.scheme=de[1]||void 0,Q.userinfo=P.indexOf("@")!==-1?de[3]:void 0,Q.host=P.indexOf("//")!==-1?de[4]:void 0,Q.port=parseInt(de[5],10),Q.path=de[6]||"",Q.query=P.indexOf("?")!==-1?de[7]:void 0,Q.fragment=P.indexOf("#")!==-1?de[8]:void 0,isNaN(Q.port)&&(Q.port=P.match(/\/\/(?:.|\n)*\:(?:\/|\?|\#|$)/)?de[4]:void 0)),Q.host&&(Q.host=Ne(Be(Q.host,ce),ce)),Q.scheme===void 0&&Q.userinfo===void 0&&Q.host===void 0&&Q.port===void 0&&!Q.path&&Q.query===void 0?Q.reference="same-document":Q.scheme===void 0?Q.reference="relative":Q.fragment===void 0?Q.reference="absolute":Q.reference="uri",x.reference&&x.reference!=="suffix"&&x.reference!==Q.reference&&(Q.error=Q.error||"URI is not a "+x.reference+" reference.");var Je=ie[(x.scheme||Q.scheme||"").toLowerCase()];if(!x.unicodeSupport&&(!Je||!Je.unicodeSupport)){if(Q.host&&(x.domainHost||Je&&Je.domainHost))try{Q.host=U.toASCII(Q.host.replace(ce.PCT_ENCODED,Ce).toLowerCase())}catch(Oe){Q.error=Q.error||"Host's domain name can not be converted to ASCII via punycode: "+Oe}Ze(Q,a)}else Ze(Q,ce);Je&&Je.parse&&Je.parse(Q,x)}else Q.error=Q.error||"URI can not be parsed.";return Q}function Fe(P,x){var Q=x.iri!==!1?l:a,ce=[];return P.userinfo!==void 0&&(ce.push(P.userinfo),ce.push("@")),P.host!==void 0&&ce.push(Ne(Be(String(P.host),Q),Q).replace(Q.IPV6ADDRESS,function(de,Je,Oe){return"["+Je+(Oe?"%25"+Oe:"")+"]"})),(typeof P.port=="number"||typeof P.port=="string")&&(ce.push(":"),ce.push(String(P.port))),ce.length?ce.join(""):void 0}var Ue=/^\.\.?\//,_e=/^\/\.(\/|$)/,ot=/^\/\.\.(\/|$)/,Zt=/^\/?(?:.|\n)*?(?=\/|$)/;function nt(P){for(var x=[];P.length;)if(P.match(Ue))P=P.replace(Ue,"");else if(P.match(_e))P=P.replace(_e,"/");else if(P.match(ot))P=P.replace(ot,"/"),x.pop();else if(P==="."||P==="..")P="";else{var Q=P.match(Zt);if(Q){var ce=Q[0];P=P.slice(ce.length),x.push(ce)}else throw new Error("Unexpected dot segment condition")}return x.join("")}function Te(P){var x=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},Q=x.iri?l:a,ce=[],de=ie[(x.scheme||P.scheme||"").toLowerCase()];if(de&&de.serialize&&de.serialize(P,x),P.host&&!Q.IPV6ADDRESS.test(P.host)){if(x.domainHost||de&&de.domainHost)try{P.host=x.iri?U.toUnicode(P.host):U.toASCII(P.host.replace(Q.PCT_ENCODED,Ce).toLowerCase())}catch(lt){P.error=P.error||"Host's domain name can not be converted to "+(x.iri?"Unicode":"ASCII")+" via punycode: "+lt}}Ze(P,Q),x.reference!=="suffix"&&P.scheme&&(ce.push(P.scheme),ce.push(":"));var Je=Fe(P,x);if(Je!==void 0&&(x.reference!=="suffix"&&ce.push("//"),ce.push(Je),P.path&&P.path.charAt(0)!=="/"&&ce.push("/")),P.path!==void 0){var Oe=P.path;!x.absolutePath&&(!de||!de.absolutePath)&&(Oe=nt(Oe)),Je===void 0&&(Oe=Oe.replace(/^\/\//,"/%2F")),ce.push(Oe)}return P.query!==void 0&&(ce.push("?"),ce.push(P.query)),P.fragment!==void 0&&(ce.push("#"),ce.push(P.fragment)),ce.join("")}function se(P,x){var Q=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},ce=arguments[3],de={};return ce||(P=ze(Te(P,Q),Q),x=ze(Te(x,Q),Q)),Q=Q||{},!Q.tolerant&&x.scheme?(de.scheme=x.scheme,de.userinfo=x.userinfo,de.host=x.host,de.port=x.port,de.path=nt(x.path||""),de.query=x.query):(x.userinfo!==void 0||x.host!==void 0||x.port!==void 0?(de.userinfo=x.userinfo,de.host=x.host,de.port=x.port,de.path=nt(x.path||""),de.query=x.query):(x.path?(x.path.charAt(0)==="/"?de.path=nt(x.path):((P.userinfo!==void 0||P.host!==void 0||P.port!==void 0)&&!P.path?de.path="/"+x.path:P.path?de.path=P.path.slice(0,P.path.lastIndexOf("/")+1)+x.path:de.path=x.path,de.path=nt(de.path)),de.query=x.query):(de.path=P.path,x.query!==void 0?de.query=x.query:de.query=P.query),de.userinfo=P.userinfo,de.host=P.host,de.port=P.port),de.scheme=P.scheme),de.fragment=x.fragment,de}function ye(P,x,Q){var ce=A({scheme:"null"},Q);return Te(se(ze(P,ce),ze(x,ce),ce,!0),ce)}function Xe(P,x){return typeof P=="string"?P=Te(ze(P,x),x):C(P)==="object"&&(P=ze(Te(P,x),x)),P}function K(P,x,Q){return typeof P=="string"?P=Te(ze(P,Q),Q):C(P)==="object"&&(P=Te(P,Q)),typeof x=="string"?x=Te(ze(x,Q),Q):C(x)==="object"&&(x=Te(x,Q)),P===x}function T(P,x){return P&&P.toString().replace(!x||!x.iri?a.ESCAPE:l.ESCAPE,me)}function k(P,x){return P&&P.toString().replace(!x||!x.iri?a.PCT_ENCODED:l.PCT_ENCODED,Ce)}var ge={scheme:"http",domainHost:!0,parse:function(x,Q){return x.host||(x.error=x.error||"HTTP URIs must have a host."),x},serialize:function(x,Q){var ce=String(x.scheme).toLowerCase()==="https";return(x.port===(ce?443:80)||x.port==="")&&(x.port=void 0),x.path||(x.path="/"),x}},he={scheme:"https",domainHost:ge.domainHost,parse:ge.parse,serialize:ge.serialize};function Ve(P){return typeof P.secure=="boolean"?P.secure:String(P.scheme).toLowerCase()==="wss"}var De={scheme:"ws",domainHost:!0,parse:function(x,Q){var ce=x;return ce.secure=Ve(ce),ce.resourceName=(ce.path||"/")+(ce.query?"?"+ce.query:""),ce.path=void 0,ce.query=void 0,ce},serialize:function(x,Q){if((x.port===(Ve(x)?443:80)||x.port==="")&&(x.port=void 0),typeof x.secure=="boolean"&&(x.scheme=x.secure?"wss":"ws",x.secure=void 0),x.resourceName){var ce=x.resourceName.split("?"),de=c(ce,2),Je=de[0],Oe=de[1];x.path=Je&&Je!=="/"?Je:void 0,x.query=Oe,x.resourceName=void 0}return x.fragment=void 0,x}},qe={scheme:"wss",domainHost:De.domainHost,parse:De.parse,serialize:De.serialize},mt={},vt="[A-Za-z0-9\\-\\.\\_\\~\\xA0-\\u200D\\u2010-\\u2029\\u202F-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF]",ct="[0-9A-Fa-f]",Ht=n(n("%[EFef]"+ct+"%"+ct+ct+"%"+ct+ct)+"|"+n("%[89A-Fa-f]"+ct+"%"+ct+ct)+"|"+n("%"+ct+ct)),ne="[A-Za-z0-9\\!\\$\\%\\'\\*\\+\\-\\^\\_\\`\\{\\|\\}\\~]",F="[\\!\\$\\%\\'\\(\\)\\*\\+\\,\\-\\.0-9\\<\\>A-Z\\x5E-\\x7E]",_=i(F,'[\\"\\\\]'),fe="[\\!\\$\\'\\(\\)\\*\\+\\,\\;\\:\\@]",ke=new RegExp(vt,"g"),ue=new RegExp(Ht,"g"),le=new RegExp(i("[^]",ne,"[\\.]",'[\\"]',_),"g"),re=new RegExp(i("[^]",vt,fe),"g"),oe=re;function we(P){var x=Ce(P);return x.match(ke)?x:P}var Ke={scheme:"mailto",parse:function(x,Q){var ce=x,de=ce.to=ce.path?ce.path.split(","):[];if(ce.path=void 0,ce.query){for(var Je=!1,Oe={},lt=ce.query.split("&"),pt=0,kt=lt.length;pt=55296&&C<=56319&&n=g)throw new Error("Cannot access property/index "+i+" levels up, current level is "+g);return I[g-i]}if(i>g)throw new Error("Cannot access data "+i+" levels up, current level is "+g);if(C="data"+(g-i||""),!n)return C}for(var o=C,A=n.split("/"),s=0;s=0?{index:i,compiling:!0}:(i=this._compilations.length,this._compilations[i]={schema:e,root:g,baseId:I},{index:i,compiling:!1})}function P8t(e,g,I){var i=SXe.call(this,e,g,I);i>=0&&this._compilations.splice(i,1)}function SXe(e,g,I){for(var i=0;i%\\^`{|}]|%[0-9a-f]{2})|\{[+#./;?&=,!@|]?(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?(?:,(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?)*\})*$/i,WXe=/^(?:(?:http[s\u017F]?|ftp):\/\/)(?:(?:[\0-\x08\x0E-\x1F!-\x9F\xA1-\u167F\u1681-\u1FFF\u200B-\u2027\u202A-\u202E\u2030-\u205E\u2060-\u2FFF\u3001-\uD7FF\uE000-\uFEFE\uFF00-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+(?::(?:[\0-\x08\x0E-\x1F!-\x9F\xA1-\u167F\u1681-\u1FFF\u200B-\u2027\u202A-\u202E\u2030-\u205E\u2060-\u2FFF\u3001-\uD7FF\uE000-\uFEFE\uFF00-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*)?@)?(?:(?!10(?:\.[0-9]{1,3}){3})(?!127(?:\.[0-9]{1,3}){3})(?!169\.254(?:\.[0-9]{1,3}){2})(?!192\.168(?:\.[0-9]{1,3}){2})(?!172\.(?:1[6-9]|2[0-9]|3[01])(?:\.[0-9]{1,3}){2})(?:[1-9][0-9]?|1[0-9][0-9]|2[01][0-9]|22[0-3])(?:\.(?:1?[0-9]{1,2}|2[0-4][0-9]|25[0-5])){2}(?:\.(?:[1-9][0-9]?|1[0-9][0-9]|2[0-4][0-9]|25[0-4]))|(?:(?:(?:[0-9a-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+-)*(?:[0-9a-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+)(?:\.(?:(?:[0-9a-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+-)*(?:[0-9a-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+)*(?:\.(?:(?:[a-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]){2,})))(?::[0-9]{2,5})?(?:\/(?:[\0-\x08\x0E-\x1F!-\x9F\xA1-\u167F\u1681-\u1FFF\u200B-\u2027\u202A-\u202E\u2030-\u205E\u2060-\u2FFF\u3001-\uD7FF\uE000-\uFEFE\uFF00-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*)?$/i,XXe=/^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i,HXe=/^(?:\/(?:[^~/]|~0|~1)*)*$/,TXe=/^#(?:\/(?:[a-z0-9_\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i,NXe=/^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/,g6t=Sk;function Sk(e){return e=e=="full"?"full":"fast",Q8t.copy(Sk[e])}Sk.fast={date:/^\d\d\d\d-[0-1]\d-[0-3]\d$/,time:/^(?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d(?::?\d\d)?)?$/i,"date-time":/^\d\d\d\d-[0-1]\d-[0-3]\d[t\s](?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d(?::?\d\d)?)$/i,uri:/^(?:[a-z][a-z0-9+\-.]*:)(?:\/?\/)?[^\s]*$/i,"uri-reference":/^(?:(?:[a-z][a-z0-9+\-.]*:)?\/?\/)?(?:[^\\\s#][^\s#]*)?(?:#[^\\\s]*)?$/i,"uri-template":RXe,url:WXe,email:/^[a-z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*$/i,hostname:VXe,ipv4:/^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/,ipv6:/^\s*(?:(?:(?:[0-9a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(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(?:%.+)?\s*$/i,regex:KXe,uuid:XXe,"json-pointer":HXe,"json-pointer-uri-fragment":TXe,"relative-json-pointer":NXe};Sk.full={date:kXe,time:YXe,"date-time":n6t,uri:r6t,"uri-reference":t6t,"uri-template":RXe,url:WXe,email:/^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i,hostname:VXe,ipv4:/^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/,ipv6:/^\s*(?:(?:(?:[0-9a-f]{1,4}:){7}(?:[0-9a-f]{1,4}|:))|(?:(?:[0-9a-f]{1,4}:){6}(?::[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(?:(?:[0-9a-f]{1,4}:){5}(?:(?:(?::[0-9a-f]{1,4}){1,2})|:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(?:(?:[0-9a-f]{1,4}:){4}(?:(?:(?::[0-9a-f]{1,4}){1,3})|(?:(?::[0-9a-f]{1,4})?:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){3}(?:(?:(?::[0-9a-f]{1,4}){1,4})|(?:(?::[0-9a-f]{1,4}){0,2}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){2}(?:(?:(?::[0-9a-f]{1,4}){1,5})|(?:(?::[0-9a-f]{1,4}){0,3}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){1}(?:(?:(?::[0-9a-f]{1,4}){1,6})|(?:(?::[0-9a-f]{1,4}){0,4}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?::(?:(?:(?::[0-9a-f]{1,4}){1,7})|(?:(?::[0-9a-f]{1,4}){0,5}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(?:%.+)?\s*$/i,regex:KXe,uuid:XXe,"json-pointer":HXe,"json-pointer-uri-fragment":TXe,"relative-json-pointer":NXe};function I6t(e){return e%4===0&&(e%100!==0||e%400===0)}function kXe(e){var g=e.match(j8t);if(!g)return!1;var I=+g[1],i=+g[2],n=+g[3];return i>=1&&i<=12&&n>=1&&n<=(i==2&&I6t(I)?29:$8t[i])}function YXe(e,g){var I=e.match(q8t);if(!I)return!1;var i=I[1],n=I[2],C=I[3],r=I[5];return(i<=23&&n<=59&&C<=59||i==23&&n==59&&C==60)&&(!g||r)}var i6t=/t|\s/i;function n6t(e){var g=e.split(i6t);return g.length==2&&kXe(g[0])&&YXe(g[1],!0)}var C6t=/\/|:/;function r6t(e){return C6t.test(e)&&e6t.test(e)}var o6t=/[^\\]\\Z/;function KXe(e){if(o6t.test(e))return!1;try{return new RegExp(e),!0}catch{return!1}}var A6t=function(g,I,i){var n=" ",C=g.level,r=g.dataLevel,o=g.schema[I],A=g.errSchemaPath+"/"+I,s=!g.opts.allErrors,a="data"+(r||""),l="valid"+C,c,u;if(o=="#"||o=="#/")g.isRoot?(c=g.async,u="validate"):(c=g.root.schema.$async===!0,u="root.refVal[0]");else{var d=g.resolveRef(g.baseId,o,g.isRoot);if(d===void 0){var h=g.MissingRefError.message(g.baseId,o);if(g.opts.missingRefs=="fail"){g.logger.error(h);var m=m||[];m.push(n),n="",g.createErrors!==!1?(n+=" { keyword: '$ref' , dataPath: (dataPath || '') + "+g.errorPath+" , schemaPath: "+g.util.toQuotedString(A)+" , params: { ref: '"+g.util.escapeQuotes(o)+"' } ",g.opts.messages!==!1&&(n+=" , message: 'can\\'t resolve reference "+g.util.escapeQuotes(o)+"' "),g.opts.verbose&&(n+=" , schema: "+g.util.toQuotedString(o)+" , parentSchema: validate.schema"+g.schemaPath+" , data: "+a+" "),n+=" } "):n+=" {} ";var f=n;n=m.pop(),!g.compositeRule&&s?g.async?n+=" throw new ValidationError(["+f+"]); ":n+=" validate.errors = ["+f+"]; return false; ":n+=" var err = "+f+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",s&&(n+=" if (false) { ")}else if(g.opts.missingRefs=="ignore")g.logger.warn(h),s&&(n+=" if (true) { ");else throw new g.MissingRefError(g.baseId,o,h)}else if(d.inline){var b=g.util.copy(g);b.level++;var p="valid"+b.level;b.schema=d.schema,b.schemaPath="",b.errSchemaPath=o;var y=g.validate(b).replace(/validate\.schema/g,d.code);n+=" "+y+" ",s&&(n+=" if ("+p+") { ")}else c=d.$async===!0||g.async&&d.$async!==!1,u=d.code}if(u){var m=m||[];m.push(n),n="",g.opts.passContext?n+=" "+u+".call(this, ":n+=" "+u+"( ",n+=" "+a+", (dataPath || '')",g.errorPath!='""'&&(n+=" + "+g.errorPath);var Z=r?"data"+(r-1||""):"parentData",B=r?g.dataPathArr[r]:"parentDataProperty";n+=" , "+Z+" , "+B+", rootData) ";var G=n;if(n=m.pop(),c){if(!g.async)throw new Error("async schema referenced by sync schema");s&&(n+=" var "+l+"; "),n+=" try { await "+G+"; ",s&&(n+=" "+l+" = true; "),n+=" } catch (e) { if (!(e instanceof ValidationError)) throw e; if (vErrors === null) vErrors = e.errors; else vErrors = vErrors.concat(e.errors); errors = vErrors.length; ",s&&(n+=" "+l+" = false; "),n+=" } ",s&&(n+=" if ("+l+") { ")}else n+=" if (!"+G+") { if (vErrors === null) vErrors = "+u+".errors; else vErrors = vErrors.concat("+u+".errors); errors = vErrors.length; } ",s&&(n+=" else { ")}return n},a6t=function(g,I,i){var n=" ",C=g.schema[I],r=g.schemaPath+g.util.getProperty(I),o=g.errSchemaPath+"/"+I,A=!g.opts.allErrors,s=g.util.copy(g),a="";s.level++;var l="valid"+s.level,c=s.baseId,u=!0,d=C;if(d)for(var h,m=-1,f=d.length-1;m0||h===!1:g.util.schemaHasRules(h,g.RULES.all))&&(u=!1,s.schema=h,s.schemaPath=r+"["+m+"]",s.errSchemaPath=o+"/"+m,n+=" "+g.validate(s)+" ",s.baseId=c,A&&(n+=" if ("+l+") { ",a+="}"));return A&&(u?n+=" if (true) { ":n+=" "+a.slice(0,-1)+" "),n},s6t=function(g,I,i){var n=" ",C=g.level,r=g.dataLevel,o=g.schema[I],A=g.schemaPath+g.util.getProperty(I),s=g.errSchemaPath+"/"+I,a=!g.opts.allErrors,l="data"+(r||""),c="valid"+C,u="errs__"+C,d=g.util.copy(g),h="";d.level++;var m="valid"+d.level,f=o.every(function(v){return g.opts.strictKeywords?typeof v=="object"&&Object.keys(v).length>0||v===!1:g.util.schemaHasRules(v,g.RULES.all)});if(f){var b=d.baseId;n+=" var "+u+" = errors; var "+c+" = false; ";var p=g.compositeRule;g.compositeRule=d.compositeRule=!0;var y=o;if(y)for(var Z,B=-1,G=y.length-1;B0||o===!1:g.util.schemaHasRules(o,g.RULES.all);if(n+="var "+u+" = errors;var "+c+";",Z){var B=g.compositeRule;g.compositeRule=d.compositeRule=!0,d.schema=o,d.schemaPath=A,d.errSchemaPath=s,n+=" var "+m+" = false; for (var "+f+" = 0; "+f+" < "+l+".length; "+f+"++) { ",d.errorPath=g.util.getPathExpr(g.errorPath,f,g.opts.jsonPointers,!0);var G=l+"["+f+"]";d.dataPathArr[b]=f;var v=g.validate(d);d.baseId=y,g.util.varOccurences(v,p)<2?n+=" "+g.util.varReplace(v,p,G)+" ":n+=" var "+p+" = "+G+"; "+v+" ",n+=" if ("+m+") break; } ",g.compositeRule=d.compositeRule=B,n+=" "+h+" if (!"+m+") {"}else n+=" if ("+l+".length == 0) {";var w=w||[];w.push(n),n="",g.createErrors!==!1?(n+=" { keyword: 'contains' , dataPath: (dataPath || '') + "+g.errorPath+" , schemaPath: "+g.util.toQuotedString(s)+" , params: {} ",g.opts.messages!==!1&&(n+=" , message: 'should contain a valid item' "),g.opts.verbose&&(n+=" , schema: validate.schema"+A+" , parentSchema: validate.schema"+g.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ";var V=n;return n=w.pop(),!g.compositeRule&&a?g.async?n+=" throw new ValidationError(["+V+"]); ":n+=" validate.errors = ["+V+"]; return false; ":n+=" var err = "+V+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",n+=" } else { ",Z&&(n+=" errors = "+u+"; if (vErrors !== null) { if ("+u+") vErrors.length = "+u+"; else vErrors = null; } "),g.opts.allErrors&&(n+=" } "),n},d6t=function(g,I,i){var n=" ",C=g.level,r=g.dataLevel,o=g.schema[I],A=g.schemaPath+g.util.getProperty(I),s=g.errSchemaPath+"/"+I,a=!g.opts.allErrors,l="data"+(r||""),c="errs__"+C,u=g.util.copy(g),d="";u.level++;var h="valid"+u.level,m={},f={},b=g.opts.ownProperties;for(B in o)if(B!="__proto__"){var p=o[B],y=Array.isArray(p)?f:m;y[B]=p}n+="var "+c+" = errors;";var Z=g.errorPath;n+="var missing"+C+";";for(var B in f)if(y=f[B],y.length){if(n+=" if ( "+l+g.util.getProperty(B)+" !== undefined ",b&&(n+=" && Object.prototype.hasOwnProperty.call("+l+", '"+g.util.escapeQuotes(B)+"') "),a){n+=" && ( ";var G=y;if(G)for(var v,w=-1,V=G.length-1;w0||p===!1:g.util.schemaHasRules(p,g.RULES.all))&&(n+=" "+h+" = true; if ( "+l+g.util.getProperty(B)+" !== undefined ",b&&(n+=" && Object.prototype.hasOwnProperty.call("+l+", '"+g.util.escapeQuotes(B)+"') "),n+=") { ",u.schema=p,u.schemaPath=A+g.util.getProperty(B),u.errSchemaPath=s+"/"+g.util.escapeFragment(B),n+=" "+g.validate(u)+" ",u.baseId=J,n+=" } ",a&&(n+=" if ("+h+") { ",d+="}"))}return a&&(n+=" "+d+" if ("+c+" == errors) {"),n},h6t=function(g,I,i){var n=" ",C=g.level,r=g.dataLevel,o=g.schema[I],A=g.schemaPath+g.util.getProperty(I),s=g.errSchemaPath+"/"+I,a=!g.opts.allErrors,l="data"+(r||""),c="valid"+C,u=g.opts.$data&&o&&o.$data;u&&(n+=" var schema"+C+" = "+g.util.getData(o.$data,r,g.dataPathArr)+"; ");var d="i"+C,h="schema"+C;u||(n+=" var "+h+" = validate.schema"+A+";"),n+="var "+c+";",u&&(n+=" if (schema"+C+" === undefined) "+c+" = true; else if (!Array.isArray(schema"+C+")) "+c+" = false; else {"),n+=""+c+" = false;for (var "+d+"=0; "+d+"<"+h+".length; "+d+"++) if (equal("+l+", "+h+"["+d+"])) { "+c+" = true; break; }",u&&(n+=" } "),n+=" if (!"+c+") { ";var m=m||[];m.push(n),n="",g.createErrors!==!1?(n+=" { keyword: 'enum' , dataPath: (dataPath || '') + "+g.errorPath+" , schemaPath: "+g.util.toQuotedString(s)+" , params: { allowedValues: schema"+C+" } ",g.opts.messages!==!1&&(n+=" , message: 'should be equal to one of the allowed values' "),g.opts.verbose&&(n+=" , schema: validate.schema"+A+" , parentSchema: validate.schema"+g.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ";var f=n;return n=m.pop(),!g.compositeRule&&a?g.async?n+=" throw new ValidationError(["+f+"]); ":n+=" validate.errors = ["+f+"]; return false; ":n+=" var err = "+f+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",n+=" }",a&&(n+=" else { "),n},m6t=function(g,I,i){var n=" ",C=g.level,r=g.dataLevel,o=g.schema[I],A=g.schemaPath+g.util.getProperty(I),s=g.errSchemaPath+"/"+I,a=!g.opts.allErrors,l="data"+(r||"");if(g.opts.format===!1)return a&&(n+=" if (true) { "),n;var c=g.opts.$data&&o&&o.$data,u;c?(n+=" var schema"+C+" = "+g.util.getData(o.$data,r,g.dataPathArr)+"; ",u="schema"+C):u=o;var d=g.opts.unknownFormats,h=Array.isArray(d);if(c){var m="format"+C,f="isObject"+C,b="formatType"+C;n+=" var "+m+" = formats["+u+"]; var "+f+" = typeof "+m+" == 'object' && !("+m+" instanceof RegExp) && "+m+".validate; var "+b+" = "+f+" && "+m+".type || 'string'; if ("+f+") { ",g.async&&(n+=" var async"+C+" = "+m+".async; "),n+=" "+m+" = "+m+".validate; } if ( ",c&&(n+=" ("+u+" !== undefined && typeof "+u+" != 'string') || "),n+=" (",d!="ignore"&&(n+=" ("+u+" && !"+m+" ",h&&(n+=" && self._opts.unknownFormats.indexOf("+u+") == -1 "),n+=") || "),n+=" ("+m+" && "+b+" == '"+i+"' && !(typeof "+m+" == 'function' ? ",g.async?n+=" (async"+C+" ? await "+m+"("+l+") : "+m+"("+l+")) ":n+=" "+m+"("+l+") ",n+=" : "+m+".test("+l+"))))) {"}else{var m=g.formats[o];if(!m){if(d=="ignore")return g.logger.warn('unknown format "'+o+'" ignored in schema at path "'+g.errSchemaPath+'"'),a&&(n+=" if (true) { "),n;if(h&&d.indexOf(o)>=0)return a&&(n+=" if (true) { "),n;throw new Error('unknown format "'+o+'" is used in schema at path "'+g.errSchemaPath+'"')}var f=typeof m=="object"&&!(m instanceof RegExp)&&m.validate,b=f&&m.type||"string";if(f){var p=m.async===!0;m=m.validate}if(b!=i)return a&&(n+=" if (true) { "),n;if(p){if(!g.async)throw new Error("async format in sync schema");var y="formats"+g.util.getProperty(o)+".validate";n+=" if (!(await "+y+"("+l+"))) { "}else{n+=" if (! ";var y="formats"+g.util.getProperty(o);f&&(y+=".validate"),typeof m=="function"?n+=" "+y+"("+l+") ":n+=" "+y+".test("+l+") ",n+=") { "}}var Z=Z||[];Z.push(n),n="",g.createErrors!==!1?(n+=" { keyword: 'format' , dataPath: (dataPath || '') + "+g.errorPath+" , schemaPath: "+g.util.toQuotedString(s)+" , params: { format: ",c?n+=""+u:n+=""+g.util.toQuotedString(o),n+=" } ",g.opts.messages!==!1&&(n+=` , message: 'should match format "`,c?n+="' + "+u+" + '":n+=""+g.util.escapeQuotes(o),n+=`"' `),g.opts.verbose&&(n+=" , schema: ",c?n+="validate.schema"+A:n+=""+g.util.toQuotedString(o),n+=" , parentSchema: validate.schema"+g.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ";var B=n;return n=Z.pop(),!g.compositeRule&&a?g.async?n+=" throw new ValidationError(["+B+"]); ":n+=" validate.errors = ["+B+"]; return false; ":n+=" var err = "+B+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",n+=" } ",a&&(n+=" else { "),n},f6t=function(g,I,i){var n=" ",C=g.level,r=g.dataLevel,o=g.schema[I],A=g.schemaPath+g.util.getProperty(I),s=g.errSchemaPath+"/"+I,a=!g.opts.allErrors,l="data"+(r||""),c="valid"+C,u="errs__"+C,d=g.util.copy(g);d.level++;var h="valid"+d.level,m=g.schema.then,f=g.schema.else,b=m!==void 0&&(g.opts.strictKeywords?typeof m=="object"&&Object.keys(m).length>0||m===!1:g.util.schemaHasRules(m,g.RULES.all)),p=f!==void 0&&(g.opts.strictKeywords?typeof f=="object"&&Object.keys(f).length>0||f===!1:g.util.schemaHasRules(f,g.RULES.all)),y=d.baseId;if(b||p){var Z;d.createErrors=!1,d.schema=o,d.schemaPath=A,d.errSchemaPath=s,n+=" var "+u+" = errors; var "+c+" = true; ";var B=g.compositeRule;g.compositeRule=d.compositeRule=!0,n+=" "+g.validate(d)+" ",d.baseId=y,d.createErrors=!0,n+=" errors = "+u+"; if (vErrors !== null) { if ("+u+") vErrors.length = "+u+"; else vErrors = null; } ",g.compositeRule=d.compositeRule=B,b?(n+=" if ("+h+") { ",d.schema=g.schema.then,d.schemaPath=g.schemaPath+".then",d.errSchemaPath=g.errSchemaPath+"/then",n+=" "+g.validate(d)+" ",d.baseId=y,n+=" "+c+" = "+h+"; ",b&&p?(Z="ifClause"+C,n+=" var "+Z+" = 'then'; "):Z="'then'",n+=" } ",p&&(n+=" else { ")):n+=" if (!"+h+") { ",p&&(d.schema=g.schema.else,d.schemaPath=g.schemaPath+".else",d.errSchemaPath=g.errSchemaPath+"/else",n+=" "+g.validate(d)+" ",d.baseId=y,n+=" "+c+" = "+h+"; ",b&&p?(Z="ifClause"+C,n+=" var "+Z+" = 'else'; "):Z="'else'",n+=" } "),n+=" if (!"+c+") { var err = ",g.createErrors!==!1?(n+=" { keyword: 'if' , dataPath: (dataPath || '') + "+g.errorPath+" , schemaPath: "+g.util.toQuotedString(s)+" , params: { failingKeyword: "+Z+" } ",g.opts.messages!==!1&&(n+=` , message: 'should match "' + `+Z+` + '" schema' `),g.opts.verbose&&(n+=" , schema: validate.schema"+A+" , parentSchema: validate.schema"+g.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ",n+="; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",!g.compositeRule&&a&&(g.async?n+=" throw new ValidationError(vErrors); ":n+=" validate.errors = vErrors; return false; "),n+=" } ",a&&(n+=" else { ")}else a&&(n+=" if (true) { ");return n},p6t=function(g,I,i){var n=" ",C=g.level,r=g.dataLevel,o=g.schema[I],A=g.schemaPath+g.util.getProperty(I),s=g.errSchemaPath+"/"+I,a=!g.opts.allErrors,l="data"+(r||""),c="valid"+C,u="errs__"+C,d=g.util.copy(g),h="";d.level++;var m="valid"+d.level,f="i"+C,b=d.dataLevel=g.dataLevel+1,p="data"+b,y=g.baseId;if(n+="var "+u+" = errors;var "+c+";",Array.isArray(o)){var Z=g.schema.additionalItems;if(Z===!1){n+=" "+c+" = "+l+".length <= "+o.length+"; ";var B=s;s=g.errSchemaPath+"/additionalItems",n+=" if (!"+c+") { ";var G=G||[];G.push(n),n="",g.createErrors!==!1?(n+=" { keyword: 'additionalItems' , dataPath: (dataPath || '') + "+g.errorPath+" , schemaPath: "+g.util.toQuotedString(s)+" , params: { limit: "+o.length+" } ",g.opts.messages!==!1&&(n+=" , message: 'should NOT have more than "+o.length+" items' "),g.opts.verbose&&(n+=" , schema: false , parentSchema: validate.schema"+g.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ";var v=n;n=G.pop(),!g.compositeRule&&a?g.async?n+=" throw new ValidationError(["+v+"]); ":n+=" validate.errors = ["+v+"]; return false; ":n+=" var err = "+v+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",n+=" } ",s=B,a&&(h+="}",n+=" else { ")}var w=o;if(w){for(var V,S=-1,X=w.length-1;S0||V===!1:g.util.schemaHasRules(V,g.RULES.all)){n+=" "+m+" = true; if ("+l+".length > "+S+") { ";var W=l+"["+S+"]";d.schema=V,d.schemaPath=A+"["+S+"]",d.errSchemaPath=s+"/"+S,d.errorPath=g.util.getPathExpr(g.errorPath,S,g.opts.jsonPointers,!0),d.dataPathArr[b]=S;var R=g.validate(d);d.baseId=y,g.util.varOccurences(R,p)<2?n+=" "+g.util.varReplace(R,p,W)+" ":n+=" var "+p+" = "+W+"; "+R+" ",n+=" } ",a&&(n+=" if ("+m+") { ",h+="}")}}if(typeof Z=="object"&&(g.opts.strictKeywords?typeof Z=="object"&&Object.keys(Z).length>0||Z===!1:g.util.schemaHasRules(Z,g.RULES.all))){d.schema=Z,d.schemaPath=g.schemaPath+".additionalItems",d.errSchemaPath=g.errSchemaPath+"/additionalItems",n+=" "+m+" = true; if ("+l+".length > "+o.length+") { for (var "+f+" = "+o.length+"; "+f+" < "+l+".length; "+f+"++) { ",d.errorPath=g.util.getPathExpr(g.errorPath,f,g.opts.jsonPointers,!0);var W=l+"["+f+"]";d.dataPathArr[b]=f;var R=g.validate(d);d.baseId=y,g.util.varOccurences(R,p)<2?n+=" "+g.util.varReplace(R,p,W)+" ":n+=" var "+p+" = "+W+"; "+R+" ",a&&(n+=" if (!"+m+") break; "),n+=" } } ",a&&(n+=" if ("+m+") { ",h+="}")}}else if(g.opts.strictKeywords?typeof o=="object"&&Object.keys(o).length>0||o===!1:g.util.schemaHasRules(o,g.RULES.all)){d.schema=o,d.schemaPath=A,d.errSchemaPath=s,n+=" for (var "+f+" = 0; "+f+" < "+l+".length; "+f+"++) { ",d.errorPath=g.util.getPathExpr(g.errorPath,f,g.opts.jsonPointers,!0);var W=l+"["+f+"]";d.dataPathArr[b]=f;var R=g.validate(d);d.baseId=y,g.util.varOccurences(R,p)<2?n+=" "+g.util.varReplace(R,p,W)+" ":n+=" var "+p+" = "+W+"; "+R+" ",a&&(n+=" if (!"+m+") break; "),n+=" }"}return a&&(n+=" "+h+" if ("+u+" == errors) {"),n},Pae=function(g,I,i){var n=" ",C=g.level,r=g.dataLevel,o=g.schema[I],A=g.schemaPath+g.util.getProperty(I),s=g.errSchemaPath+"/"+I,a=!g.opts.allErrors,y,l="data"+(r||""),c=g.opts.$data&&o&&o.$data,u;c?(n+=" var schema"+C+" = "+g.util.getData(o.$data,r,g.dataPathArr)+"; ",u="schema"+C):u=o;var d=I=="maximum",h=d?"exclusiveMaximum":"exclusiveMinimum",m=g.schema[h],f=g.opts.$data&&m&&m.$data,b=d?"<":">",p=d?">":"<",y=void 0;if(!(c||typeof o=="number"||o===void 0))throw new Error(I+" must be number");if(!(f||m===void 0||typeof m=="number"||typeof m=="boolean"))throw new Error(h+" must be number or boolean");if(f){var Z=g.util.getData(m.$data,r,g.dataPathArr),B="exclusive"+C,G="exclType"+C,v="exclIsNumber"+C,w="op"+C,V="' + "+w+" + '";n+=" var schemaExcl"+C+" = "+Z+"; ",Z="schemaExcl"+C,n+=" var "+B+"; var "+G+" = typeof "+Z+"; if ("+G+" != 'boolean' && "+G+" != 'undefined' && "+G+" != 'number') { ";var y=h,S=S||[];S.push(n),n="",g.createErrors!==!1?(n+=" { keyword: '"+(y||"_exclusiveLimit")+"' , dataPath: (dataPath || '') + "+g.errorPath+" , schemaPath: "+g.util.toQuotedString(s)+" , params: {} ",g.opts.messages!==!1&&(n+=" , message: '"+h+" should be boolean' "),g.opts.verbose&&(n+=" , schema: validate.schema"+A+" , parentSchema: validate.schema"+g.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ";var X=n;n=S.pop(),!g.compositeRule&&a?g.async?n+=" throw new ValidationError(["+X+"]); ":n+=" validate.errors = ["+X+"]; return false; ":n+=" var err = "+X+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",n+=" } else if ( ",c&&(n+=" ("+u+" !== undefined && typeof "+u+" != 'number') || "),n+=" "+G+" == 'number' ? ( ("+B+" = "+u+" === undefined || "+Z+" "+b+"= "+u+") ? "+l+" "+p+"= "+Z+" : "+l+" "+p+" "+u+" ) : ( ("+B+" = "+Z+" === true) ? "+l+" "+p+"= "+u+" : "+l+" "+p+" "+u+" ) || "+l+" !== "+l+") { var op"+C+" = "+B+" ? '"+b+"' : '"+b+"='; ",o===void 0&&(y=h,s=g.errSchemaPath+"/"+h,u=Z,c=f)}else{var v=typeof m=="number",V=b;if(v&&c){var w="'"+V+"'";n+=" if ( ",c&&(n+=" ("+u+" !== undefined && typeof "+u+" != 'number') || "),n+=" ( "+u+" === undefined || "+m+" "+b+"= "+u+" ? "+l+" "+p+"= "+m+" : "+l+" "+p+" "+u+" ) || "+l+" !== "+l+") { "}else{v&&o===void 0?(B=!0,y=h,s=g.errSchemaPath+"/"+h,u=m,p+="="):(v&&(u=Math[d?"min":"max"](m,o)),m===(v?u:!0)?(B=!0,y=h,s=g.errSchemaPath+"/"+h,p+="="):(B=!1,V+="="));var w="'"+V+"'";n+=" if ( ",c&&(n+=" ("+u+" !== undefined && typeof "+u+" != 'number') || "),n+=" "+l+" "+p+" "+u+" || "+l+" !== "+l+") { "}}y=y||I;var S=S||[];S.push(n),n="",g.createErrors!==!1?(n+=" { keyword: '"+(y||"_limit")+"' , dataPath: (dataPath || '') + "+g.errorPath+" , schemaPath: "+g.util.toQuotedString(s)+" , params: { comparison: "+w+", limit: "+u+", exclusive: "+B+" } ",g.opts.messages!==!1&&(n+=" , message: 'should be "+V+" ",c?n+="' + "+u:n+=""+u+"'"),g.opts.verbose&&(n+=" , schema: ",c?n+="validate.schema"+A:n+=""+o,n+=" , parentSchema: validate.schema"+g.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ";var X=n;return n=S.pop(),!g.compositeRule&&a?g.async?n+=" throw new ValidationError(["+X+"]); ":n+=" validate.errors = ["+X+"]; return false; ":n+=" var err = "+X+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",n+=" } ",a&&(n+=" else { "),n},Jae=function(g,I,i){var n=" ",C=g.level,r=g.dataLevel,o=g.schema[I],A=g.schemaPath+g.util.getProperty(I),s=g.errSchemaPath+"/"+I,a=!g.opts.allErrors,h,l="data"+(r||""),c=g.opts.$data&&o&&o.$data,u;if(c?(n+=" var schema"+C+" = "+g.util.getData(o.$data,r,g.dataPathArr)+"; ",u="schema"+C):u=o,!(c||typeof o=="number"))throw new Error(I+" must be number");var d=I=="maxItems"?">":"<";n+="if ( ",c&&(n+=" ("+u+" !== undefined && typeof "+u+" != 'number') || "),n+=" "+l+".length "+d+" "+u+") { ";var h=I,m=m||[];m.push(n),n="",g.createErrors!==!1?(n+=" { keyword: '"+(h||"_limitItems")+"' , dataPath: (dataPath || '') + "+g.errorPath+" , schemaPath: "+g.util.toQuotedString(s)+" , params: { limit: "+u+" } ",g.opts.messages!==!1&&(n+=" , message: 'should NOT have ",I=="maxItems"?n+="more":n+="fewer",n+=" than ",c?n+="' + "+u+" + '":n+=""+o,n+=" items' "),g.opts.verbose&&(n+=" , schema: ",c?n+="validate.schema"+A:n+=""+o,n+=" , parentSchema: validate.schema"+g.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ";var f=n;return n=m.pop(),!g.compositeRule&&a?g.async?n+=" throw new ValidationError(["+f+"]); ":n+=" validate.errors = ["+f+"]; return false; ":n+=" var err = "+f+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",n+="} ",a&&(n+=" else { "),n},Oae=function(g,I,i){var n=" ",C=g.level,r=g.dataLevel,o=g.schema[I],A=g.schemaPath+g.util.getProperty(I),s=g.errSchemaPath+"/"+I,a=!g.opts.allErrors,h,l="data"+(r||""),c=g.opts.$data&&o&&o.$data,u;if(c?(n+=" var schema"+C+" = "+g.util.getData(o.$data,r,g.dataPathArr)+"; ",u="schema"+C):u=o,!(c||typeof o=="number"))throw new Error(I+" must be number");var d=I=="maxLength"?">":"<";n+="if ( ",c&&(n+=" ("+u+" !== undefined && typeof "+u+" != 'number') || "),g.opts.unicode===!1?n+=" "+l+".length ":n+=" ucs2length("+l+") ",n+=" "+d+" "+u+") { ";var h=I,m=m||[];m.push(n),n="",g.createErrors!==!1?(n+=" { keyword: '"+(h||"_limitLength")+"' , dataPath: (dataPath || '') + "+g.errorPath+" , schemaPath: "+g.util.toQuotedString(s)+" , params: { limit: "+u+" } ",g.opts.messages!==!1&&(n+=" , message: 'should NOT be ",I=="maxLength"?n+="longer":n+="shorter",n+=" than ",c?n+="' + "+u+" + '":n+=""+o,n+=" characters' "),g.opts.verbose&&(n+=" , schema: ",c?n+="validate.schema"+A:n+=""+o,n+=" , parentSchema: validate.schema"+g.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ";var f=n;return n=m.pop(),!g.compositeRule&&a?g.async?n+=" throw new ValidationError(["+f+"]); ":n+=" validate.errors = ["+f+"]; return false; ":n+=" var err = "+f+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",n+="} ",a&&(n+=" else { "),n},_ae=function(g,I,i){var n=" ",C=g.level,r=g.dataLevel,o=g.schema[I],A=g.schemaPath+g.util.getProperty(I),s=g.errSchemaPath+"/"+I,a=!g.opts.allErrors,h,l="data"+(r||""),c=g.opts.$data&&o&&o.$data,u;if(c?(n+=" var schema"+C+" = "+g.util.getData(o.$data,r,g.dataPathArr)+"; ",u="schema"+C):u=o,!(c||typeof o=="number"))throw new Error(I+" must be number");var d=I=="maxProperties"?">":"<";n+="if ( ",c&&(n+=" ("+u+" !== undefined && typeof "+u+" != 'number') || "),n+=" Object.keys("+l+").length "+d+" "+u+") { ";var h=I,m=m||[];m.push(n),n="",g.createErrors!==!1?(n+=" { keyword: '"+(h||"_limitProperties")+"' , dataPath: (dataPath || '') + "+g.errorPath+" , schemaPath: "+g.util.toQuotedString(s)+" , params: { limit: "+u+" } ",g.opts.messages!==!1&&(n+=" , message: 'should NOT have ",I=="maxProperties"?n+="more":n+="fewer",n+=" than ",c?n+="' + "+u+" + '":n+=""+o,n+=" properties' "),g.opts.verbose&&(n+=" , schema: ",c?n+="validate.schema"+A:n+=""+o,n+=" , parentSchema: validate.schema"+g.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ";var f=n;return n=m.pop(),!g.compositeRule&&a?g.async?n+=" throw new ValidationError(["+f+"]); ":n+=" validate.errors = ["+f+"]; return false; ":n+=" var err = "+f+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",n+="} ",a&&(n+=" else { "),n},b6t=function(g,I,i){var n=" ",C=g.level,r=g.dataLevel,o=g.schema[I],A=g.schemaPath+g.util.getProperty(I),s=g.errSchemaPath+"/"+I,a=!g.opts.allErrors,l="data"+(r||""),c=g.opts.$data&&o&&o.$data,u;if(c?(n+=" var schema"+C+" = "+g.util.getData(o.$data,r,g.dataPathArr)+"; ",u="schema"+C):u=o,!(c||typeof o=="number"))throw new Error(I+" must be number");n+="var division"+C+";if (",c&&(n+=" "+u+" !== undefined && ( typeof "+u+" != 'number' || "),n+=" (division"+C+" = "+l+" / "+u+", ",g.opts.multipleOfPrecision?n+=" Math.abs(Math.round(division"+C+") - division"+C+") > 1e-"+g.opts.multipleOfPrecision+" ":n+=" division"+C+" !== parseInt(division"+C+") ",n+=" ) ",c&&(n+=" ) "),n+=" ) { ";var d=d||[];d.push(n),n="",g.createErrors!==!1?(n+=" { keyword: 'multipleOf' , dataPath: (dataPath || '') + "+g.errorPath+" , schemaPath: "+g.util.toQuotedString(s)+" , params: { multipleOf: "+u+" } ",g.opts.messages!==!1&&(n+=" , message: 'should be multiple of ",c?n+="' + "+u:n+=""+u+"'"),g.opts.verbose&&(n+=" , schema: ",c?n+="validate.schema"+A:n+=""+o,n+=" , parentSchema: validate.schema"+g.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ";var h=n;return n=d.pop(),!g.compositeRule&&a?g.async?n+=" throw new ValidationError(["+h+"]); ":n+=" validate.errors = ["+h+"]; return false; ":n+=" var err = "+h+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",n+="} ",a&&(n+=" else { "),n},y6t=function(g,I,i){var n=" ",C=g.level,r=g.dataLevel,o=g.schema[I],A=g.schemaPath+g.util.getProperty(I),s=g.errSchemaPath+"/"+I,a=!g.opts.allErrors,l="data"+(r||""),c="errs__"+C,u=g.util.copy(g);u.level++;var d="valid"+u.level;if(g.opts.strictKeywords?typeof o=="object"&&Object.keys(o).length>0||o===!1:g.util.schemaHasRules(o,g.RULES.all)){u.schema=o,u.schemaPath=A,u.errSchemaPath=s,n+=" var "+c+" = errors; ";var h=g.compositeRule;g.compositeRule=u.compositeRule=!0,u.createErrors=!1;var m;u.opts.allErrors&&(m=u.opts.allErrors,u.opts.allErrors=!1),n+=" "+g.validate(u)+" ",u.createErrors=!0,m&&(u.opts.allErrors=m),g.compositeRule=u.compositeRule=h,n+=" if ("+d+") { ";var f=f||[];f.push(n),n="",g.createErrors!==!1?(n+=" { keyword: 'not' , dataPath: (dataPath || '') + "+g.errorPath+" , schemaPath: "+g.util.toQuotedString(s)+" , params: {} ",g.opts.messages!==!1&&(n+=" , message: 'should NOT be valid' "),g.opts.verbose&&(n+=" , schema: validate.schema"+A+" , parentSchema: validate.schema"+g.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ";var b=n;n=f.pop(),!g.compositeRule&&a?g.async?n+=" throw new ValidationError(["+b+"]); ":n+=" validate.errors = ["+b+"]; return false; ":n+=" var err = "+b+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",n+=" } else { errors = "+c+"; if (vErrors !== null) { if ("+c+") vErrors.length = "+c+"; else vErrors = null; } ",g.opts.allErrors&&(n+=" } ")}else n+=" var err = ",g.createErrors!==!1?(n+=" { keyword: 'not' , dataPath: (dataPath || '') + "+g.errorPath+" , schemaPath: "+g.util.toQuotedString(s)+" , params: {} ",g.opts.messages!==!1&&(n+=" , message: 'should NOT be valid' "),g.opts.verbose&&(n+=" , schema: validate.schema"+A+" , parentSchema: validate.schema"+g.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ",n+="; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",a&&(n+=" if (false) { ");return n},Z6t=function(g,I,i){var n=" ",C=g.level,r=g.dataLevel,o=g.schema[I],A=g.schemaPath+g.util.getProperty(I),s=g.errSchemaPath+"/"+I,a=!g.opts.allErrors,l="data"+(r||""),c="valid"+C,u="errs__"+C,d=g.util.copy(g),h="";d.level++;var m="valid"+d.level,f=d.baseId,b="prevValid"+C,p="passingSchemas"+C;n+="var "+u+" = errors , "+b+" = false , "+c+" = false , "+p+" = null; ";var y=g.compositeRule;g.compositeRule=d.compositeRule=!0;var Z=o;if(Z)for(var B,G=-1,v=Z.length-1;G0||B===!1:g.util.schemaHasRules(B,g.RULES.all))?(d.schema=B,d.schemaPath=A+"["+G+"]",d.errSchemaPath=s+"/"+G,n+=" "+g.validate(d)+" ",d.baseId=f):n+=" var "+m+" = true; ",G&&(n+=" if ("+m+" && "+b+") { "+c+" = false; "+p+" = ["+p+", "+G+"]; } else { ",h+="}"),n+=" if ("+m+") { "+c+" = "+b+" = true; "+p+" = "+G+"; }";return g.compositeRule=d.compositeRule=y,n+=""+h+"if (!"+c+") { var err = ",g.createErrors!==!1?(n+=" { keyword: 'oneOf' , dataPath: (dataPath || '') + "+g.errorPath+" , schemaPath: "+g.util.toQuotedString(s)+" , params: { passingSchemas: "+p+" } ",g.opts.messages!==!1&&(n+=" , message: 'should match exactly one schema in oneOf' "),g.opts.verbose&&(n+=" , schema: validate.schema"+A+" , parentSchema: validate.schema"+g.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ",n+="; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",!g.compositeRule&&a&&(g.async?n+=" throw new ValidationError(vErrors); ":n+=" validate.errors = vErrors; return false; "),n+="} else { errors = "+u+"; if (vErrors !== null) { if ("+u+") vErrors.length = "+u+"; else vErrors = null; }",g.opts.allErrors&&(n+=" } "),n},G6t=function(g,I,i){var n=" ",C=g.level,r=g.dataLevel,o=g.schema[I],A=g.schemaPath+g.util.getProperty(I),s=g.errSchemaPath+"/"+I,a=!g.opts.allErrors,l="data"+(r||""),c=g.opts.$data&&o&&o.$data,u;c?(n+=" var schema"+C+" = "+g.util.getData(o.$data,r,g.dataPathArr)+"; ",u="schema"+C):u=o;var d=c?"(new RegExp("+u+"))":g.usePattern(o);n+="if ( ",c&&(n+=" ("+u+" !== undefined && typeof "+u+" != 'string') || "),n+=" !"+d+".test("+l+") ) { ";var h=h||[];h.push(n),n="",g.createErrors!==!1?(n+=" { keyword: 'pattern' , dataPath: (dataPath || '') + "+g.errorPath+" , schemaPath: "+g.util.toQuotedString(s)+" , params: { pattern: ",c?n+=""+u:n+=""+g.util.toQuotedString(o),n+=" } ",g.opts.messages!==!1&&(n+=` , message: 'should match pattern "`,c?n+="' + "+u+" + '":n+=""+g.util.escapeQuotes(o),n+=`"' `),g.opts.verbose&&(n+=" , schema: ",c?n+="validate.schema"+A:n+=""+g.util.toQuotedString(o),n+=" , parentSchema: validate.schema"+g.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ";var m=n;return n=h.pop(),!g.compositeRule&&a?g.async?n+=" throw new ValidationError(["+m+"]); ":n+=" validate.errors = ["+m+"]; return false; ":n+=" var err = "+m+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",n+="} ",a&&(n+=" else { "),n},v6t=function(g,I,i){var n=" ",C=g.level,r=g.dataLevel,o=g.schema[I],A=g.schemaPath+g.util.getProperty(I),s=g.errSchemaPath+"/"+I,a=!g.opts.allErrors,l="data"+(r||""),c="errs__"+C,u=g.util.copy(g),d="";u.level++;var h="valid"+u.level,m="key"+C,f="idx"+C,b=u.dataLevel=g.dataLevel+1,p="data"+b,y="dataProperties"+C,Z=Object.keys(o||{}).filter(E),B=g.schema.patternProperties||{},G=Object.keys(B).filter(E),v=g.schema.additionalProperties,w=Z.length||G.length,V=v===!1,S=typeof v=="object"&&Object.keys(v).length,X=g.opts.removeAdditional,W=V||S||X,R=g.opts.ownProperties,H=g.baseId,Y=g.schema.required;if(Y&&!(g.opts.$data&&Y.$data)&&Y.length8)n+=" || validate.schema"+A+".hasOwnProperty("+m+") ";else{var O=Z;if(O)for(var J,ee=-1,q=O.length-1;ee0||_e===!1:g.util.schemaHasRules(_e,g.RULES.all)){var ot=g.util.getProperty(J),Ne=l+ot,Zt=Pe&&_e.default!==void 0;u.schema=_e,u.schemaPath=A+ot,u.errSchemaPath=s+"/"+g.util.escapeFragment(J),u.errorPath=g.util.getPath(g.errorPath,J,g.opts.jsonPointers),u.dataPathArr[b]=g.util.toQuotedString(J);var Se=g.validate(u);if(u.baseId=H,g.util.varOccurences(Se,p)<2){Se=g.util.varReplace(Se,p,Ne);var nt=Ne}else{var nt=p;n+=" var "+p+" = "+Ne+"; "}if(Zt)n+=" "+Se+" ";else{if(D&&D[J]){n+=" if ( "+nt+" === undefined ",R&&(n+=" || ! Object.prototype.hasOwnProperty.call("+l+", '"+g.util.escapeQuotes(J)+"') "),n+=") { "+h+" = false; ";var ie=g.errorPath,Ce=s,Te=g.util.escapeQuotes(J);g.opts._errorDataPathProperty&&(g.errorPath=g.util.getPath(ie,J,g.opts.jsonPointers)),s=g.errSchemaPath+"/required";var Ze=Ze||[];Ze.push(n),n="",g.createErrors!==!1?(n+=" { keyword: 'required' , dataPath: (dataPath || '') + "+g.errorPath+" , schemaPath: "+g.util.toQuotedString(s)+" , params: { missingProperty: '"+Te+"' } ",g.opts.messages!==!1&&(n+=" , message: '",g.opts._errorDataPathProperty?n+="is a required property":n+="should have required property \\'"+Te+"\\'",n+="' "),g.opts.verbose&&(n+=" , schema: validate.schema"+A+" , parentSchema: validate.schema"+g.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ";var Ge=n;n=Ze.pop(),!g.compositeRule&&a?g.async?n+=" throw new ValidationError(["+Ge+"]); ":n+=" validate.errors = ["+Ge+"]; return false; ":n+=" var err = "+Ge+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",s=Ce,g.errorPath=ie,n+=" } else { "}else a?(n+=" if ( "+nt+" === undefined ",R&&(n+=" || ! Object.prototype.hasOwnProperty.call("+l+", '"+g.util.escapeQuotes(J)+"') "),n+=") { "+h+" = true; } else { "):(n+=" if ("+nt+" !== undefined ",R&&(n+=" && Object.prototype.hasOwnProperty.call("+l+", '"+g.util.escapeQuotes(J)+"') "),n+=" ) { ");n+=" "+Se+" } "}}a&&(n+=" if ("+h+") { ",d+="}")}}if(G.length){var se=G;if(se)for(var j,ye=-1,Xe=se.length-1;ye0||_e===!1:g.util.schemaHasRules(_e,g.RULES.all)){u.schema=_e,u.schemaPath=g.schemaPath+".patternProperties"+g.util.getProperty(j),u.errSchemaPath=g.errSchemaPath+"/patternProperties/"+g.util.escapeFragment(j),R?n+=" "+y+" = "+y+" || Object.keys("+l+"); for (var "+f+"=0; "+f+"<"+y+".length; "+f+"++) { var "+m+" = "+y+"["+f+"]; ":n+=" for (var "+m+" in "+l+") { ",n+=" if ("+g.usePattern(j)+".test("+m+")) { ",u.errorPath=g.util.getPathExpr(g.errorPath,m,g.opts.jsonPointers);var Ne=l+"["+m+"]";u.dataPathArr[b]=m;var Se=g.validate(u);u.baseId=H,g.util.varOccurences(Se,p)<2?n+=" "+g.util.varReplace(Se,p,Ne)+" ":n+=" var "+p+" = "+Ne+"; "+Se+" ",a&&(n+=" if (!"+h+") break; "),n+=" } ",a&&(n+=" else "+h+" = true; "),n+=" } ",a&&(n+=" if ("+h+") { ",d+="}")}}}return a&&(n+=" "+d+" if ("+c+" == errors) {"),n},B6t=function(g,I,i){var n=" ",C=g.level,r=g.dataLevel,o=g.schema[I],A=g.schemaPath+g.util.getProperty(I),s=g.errSchemaPath+"/"+I,a=!g.opts.allErrors,l="data"+(r||""),c="errs__"+C,u=g.util.copy(g),d="";u.level++;var h="valid"+u.level;if(n+="var "+c+" = errors;",g.opts.strictKeywords?typeof o=="object"&&Object.keys(o).length>0||o===!1:g.util.schemaHasRules(o,g.RULES.all)){u.schema=o,u.schemaPath=A,u.errSchemaPath=s;var m="key"+C,f="idx"+C,b="i"+C,p="' + "+m+" + '",y=u.dataLevel=g.dataLevel+1,Z="data"+y,B="dataProperties"+C,G=g.opts.ownProperties,v=g.baseId;G&&(n+=" var "+B+" = undefined; "),G?n+=" "+B+" = "+B+" || Object.keys("+l+"); for (var "+f+"=0; "+f+"<"+B+".length; "+f+"++) { var "+m+" = "+B+"["+f+"]; ":n+=" for (var "+m+" in "+l+") { ",n+=" var startErrs"+C+" = errors; ";var w=m,V=g.compositeRule;g.compositeRule=u.compositeRule=!0;var S=g.validate(u);u.baseId=v,g.util.varOccurences(S,Z)<2?n+=" "+g.util.varReplace(S,Z,w)+" ":n+=" var "+Z+" = "+w+"; "+S+" ",g.compositeRule=u.compositeRule=V,n+=" if (!"+h+") { for (var "+b+"=startErrs"+C+"; "+b+"0||y===!1:g.util.schemaHasRules(y,g.RULES.all))||(h[h.length]=f)}}else var h=o;if(u||h.length){var Z=g.errorPath,B=u||h.length>=g.opts.loopRequired,G=g.opts.ownProperties;if(a)if(n+=" var missing"+C+"; ",B){u||(n+=" var "+d+" = validate.schema"+A+"; ");var v="i"+C,w="schema"+C+"["+v+"]",V="' + "+w+" + '";g.opts._errorDataPathProperty&&(g.errorPath=g.util.getPathExpr(Z,w,g.opts.jsonPointers)),n+=" var "+c+" = true; ",u&&(n+=" if (schema"+C+" === undefined) "+c+" = true; else if (!Array.isArray(schema"+C+")) "+c+" = false; else {"),n+=" for (var "+v+" = 0; "+v+" < "+d+".length; "+v+"++) { "+c+" = "+l+"["+d+"["+v+"]] !== undefined ",G&&(n+=" && Object.prototype.hasOwnProperty.call("+l+", "+d+"["+v+"]) "),n+="; if (!"+c+") break; } ",u&&(n+=" } "),n+=" if (!"+c+") { ";var S=S||[];S.push(n),n="",g.createErrors!==!1?(n+=" { keyword: 'required' , dataPath: (dataPath || '') + "+g.errorPath+" , schemaPath: "+g.util.toQuotedString(s)+" , params: { missingProperty: '"+V+"' } ",g.opts.messages!==!1&&(n+=" , message: '",g.opts._errorDataPathProperty?n+="is a required property":n+="should have required property \\'"+V+"\\'",n+="' "),g.opts.verbose&&(n+=" , schema: validate.schema"+A+" , parentSchema: validate.schema"+g.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ";var X=n;n=S.pop(),!g.compositeRule&&a?g.async?n+=" throw new ValidationError(["+X+"]); ":n+=" validate.errors = ["+X+"]; return false; ":n+=" var err = "+X+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",n+=" } else { "}else{n+=" if ( ";var W=h;if(W)for(var R,v=-1,H=W.length-1;v 1) { ";var h=g.schema.items&&g.schema.items.type,m=Array.isArray(h);if(!h||h=="object"||h=="array"||m&&(h.indexOf("object")>=0||h.indexOf("array")>=0))n+=" outer: for (;i--;) { for (j = i; j--;) { if (equal("+l+"[i], "+l+"[j])) { "+c+" = false; break outer; } } } ";else{n+=" var itemIndices = {}, item; for (;i--;) { var item = "+l+"[i]; ";var f="checkDataType"+(m?"s":"");n+=" if ("+g.util[f](h,"item",g.opts.strictNumbers,!0)+") continue; ",m&&(n+=` if (typeof item == 'string') item = '"' + item; `),n+=" if (typeof itemIndices[item] == 'number') { "+c+" = false; j = itemIndices[item]; break; } itemIndices[item] = i; } "}n+=" } ",u&&(n+=" } "),n+=" if (!"+c+") { ";var b=b||[];b.push(n),n="",g.createErrors!==!1?(n+=" { keyword: 'uniqueItems' , dataPath: (dataPath || '') + "+g.errorPath+" , schemaPath: "+g.util.toQuotedString(s)+" , params: { i: i, j: j } ",g.opts.messages!==!1&&(n+=" , message: 'should NOT have duplicate items (items ## ' + j + ' and ' + i + ' are identical)' "),g.opts.verbose&&(n+=" , schema: ",u?n+="validate.schema"+A:n+=""+o,n+=" , parentSchema: validate.schema"+g.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ";var p=n;n=b.pop(),!g.compositeRule&&a?g.async?n+=" throw new ValidationError(["+p+"]); ":n+=" validate.errors = ["+p+"]; return false; ":n+=" var err = "+p+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",n+=" } ",a&&(n+=" else { ")}else a&&(n+=" if (true) { ");return n},V6t={$ref:A6t,allOf:a6t,anyOf:s6t,$comment:l6t,const:c6t,contains:u6t,dependencies:d6t,enum:h6t,format:m6t,if:f6t,items:p6t,maximum:Pae,minimum:Pae,maxItems:Jae,minItems:Jae,maxLength:Oae,minLength:Oae,maxProperties:_ae,minProperties:_ae,multipleOf:b6t,not:y6t,oneOf:Z6t,pattern:G6t,properties:v6t,propertyNames:B6t,required:S6t,uniqueItems:w6t,validate:vXe},Lae=V6t,xx=ty.toHash,R6t=function(){var g=[{type:"number",rules:[{maximum:["exclusiveMaximum"]},{minimum:["exclusiveMinimum"]},"multipleOf","format"]},{type:"string",rules:["maxLength","minLength","pattern","format"]},{type:"array",rules:["maxItems","minItems","items","contains","uniqueItems"]},{type:"object",rules:["maxProperties","minProperties","required","dependencies","propertyNames",{properties:["additionalProperties","patternProperties"]}]},{rules:["$ref","const","enum","not","anyOf","oneOf","allOf","if"]}],I=["type","$comment"],i=["$schema","$id","id","$data","$async","title","description","default","definitions","examples","readOnly","writeOnly","contentMediaType","contentEncoding","additionalItems","then","else"],n=["number","integer","string","array","object","boolean","null"];return g.all=xx(I),g.types=xx(n),g.forEach(function(C){C.rules=C.rules.map(function(r){var o;if(typeof r=="object"){var A=Object.keys(r)[0];o=r[A],r=A,o.forEach(function(a){I.push(a),g.all[a]=!0})}I.push(r);var s=g.all[r]={keyword:r,code:Lae[r],implements:o};return s}),g.all.$comment={keyword:"$comment",code:Lae.$comment},C.type&&(g.types[C.type]=C)}),g.keywords=xx(I.concat(i)),g.custom={},g},Uae=["multipleOf","maximum","exclusiveMaximum","minimum","exclusiveMinimum","maxLength","minLength","pattern","additionalItems","maxItems","minItems","uniqueItems","maxProperties","minProperties","required","additionalProperties","enum","format","const"],W6t=function(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function q2(e){return q2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},q2(e)}let UXe=function(e){Oqt(I,e);var g=_qt(I);function I(i){var n;return Mqt(this,I),n=g.call(this,i),n.state={code:i.viewConfig,hide:!1,showLog:!1,logMsgs:n.getLogMsgs(i.viewConfig)},n.handleChangeBound=n.handleChange.bind(Hl(n)),n.handleKeyDownBound=n.handleKeyDown.bind(Hl(n)),n.handleKeyUpBound=n.handleKeyUp.bind(Hl(n)),n.handleSubmitBound=n.handleSubmit.bind(Hl(n)),n.hideBound=n.hide.bind(Hl(n)),n.showBound=n.show.bind(Hl(n)),n.toggleLogBound=n.toggleLog.bind(Hl(n)),n.pubSubs=[],n.pubSubs.push(n.props.pubSub.subscribe("keydown",n.handleKeyDownBound)),n.pubSubs.push(n.props.pubSub.subscribe("keyup",n.handleKeyUpBound)),n}return zqt(I,[{key:"componentDidMount",value:async function(){this.editor&&(this.editor._input.focus(),this.editor._input.setSelectionRange(0,0),await j7(0),this.editorWrap&&(this.editorWrap.scrollTop=0))}},{key:"componentWillUnmount",value:function(){this.pubSubs.forEach(n=>this.props.pubSub.unsubscribe(n)),this.pubSubs=[]}},{key:"handleChange",value:function(n){const C=this.getLogMsgs(n);this.setState({code:n,logMsgs:C})}},{key:"handleKeyDown",value:function(n){n.key==="s"&&(n.ctrlKey||n.metaKey)&&(n.preventDefault(),this.props.onChange(this.state.code)),n.key==="Enter"&&(n.ctrlKey||n.metaKey)&&(n.preventDefault(),this.props.onChange(this.state.code),this.props.modal.close())}},{key:"handleKeyUp",value:function(n){this.setState({hide:!1}),n.key==="Escape"&&(n.preventDefault(),this.props.modal.close(),this.props.onCancel())}},{key:"handleSubmit",value:function(n){n&&n.preventDefault(),this.props.onSave(this.state.code)}},{key:"getLogMsgs",value:function(n){const C=[];let r;try{r=JSON.parse(n)}catch(s){return console.warn(s),C.push({type:"Error",msg:s.toString()}),C}const o=new _Xe().compile(LXe);return o(r)||(console.warn("Invalid viewconf"),C.push({type:"Warning",msg:"Invalid viewconf"})),o.errors&&(console.warn(JSON.stringify(o.errors,null,2)),o.errors.forEach(s=>{C.push({type:"Warning",msg:JSON.stringify(s,null,2)})})),C.length===0&&C.push({type:"Success",msg:"No error or warnings"}),C}},{key:"hide",value:function(){this.setState({hide:!0})}},{key:"show",value:function(){this.setState({hide:!1})}},{key:"hideLog",value:function(){this.setState({showLog:!1})}},{key:"showLog",value:function(){this.setState({showLog:!0})}},{key:"toggleLog",value:function(){this.state.showLog?this.hideLog():this.showLog()}},{key:"render",value:function(){const n=this.state.logMsgs.map((C,r)=>{const o=`${r}-${C.msg}`;return N.createElement("tr",{key:o},N.createElement("td",{className:Vg(Vu.title,Vu[C.type])},`[${r}] ${C.type}`),N.createElement("td",null,N.createElement("pre",null,C.msg)))});return N.createElement(Iw,{cancelShortcut:"ESC",cancelTitle:"Discard Changes",hide:this.state.hide,maxHeight:!0,okayShortcut:"⌘+Enter",okayTitle:"Save and Close",onCancel:this.props.onCancel,onOkay:this.handleSubmitBound,title:"Edit View Config"},N.createElement(N.Fragment,null,N.createElement("header",{className:Vu["view-config-editor-header"]},N.createElement(vs,{onBlur:this.showBound,onMouseDown:this.hideBound,onMouseOut:this.showBound,onMouseUp:this.showBound},"Hide While Mousedown"),N.createElement(vs,{onClick:()=>{this.props.onChange(this.state.code)},shortcut:"⌘+S"},"Save")),N.createElement("div",{ref:C=>{this.editorWrap=C},className:Vu["view-config-editor"]},N.createElement(r8t,{ref:C=>{this.editor=C},highlight:C=>xae.highlight(C,xae.languages.json),onValueChange:this.handleChangeBound,padding:10,style:{fontFamily:'"Fira code", "Fira Mono", monospace',fontSize:"inherit"},value:this.state.code})),N.createElement("div",{className:Vu["view-config-log"],style:{height:this.state.showLog?"50%":"30px"}},N.createElement("div",{className:Vu["view-config-log-header"],onClick:()=>this.toggleLogBound()},`Log Messages (${this.state.logMsgs.filter(C=>C.type!=="Success").length})`),N.createElement("div",{className:Vu["view-config-log-msg"],style:{padding:this.state.showLog?"10px":0}},N.createElement("table",null,N.createElement("tbody",null,n))))))}}]),I}(N.Component);UXe.propTypes={modal:L.object.isRequired,onCancel:L.func.isRequired,onChange:L.func.isRequired,onSave:L.func.isRequired,pubSub:L.object.isRequired,viewConfig:L.string.isRequired};const Qqt=M0(uk(UXe));function jqt(e,g,I,i){const n=e.append("symbol").attr("id",g).attr("viewBox",i);I.forEach(C=>n.append("path").attr("d",C).attr("fill","currentColor"))}const $qt=e=>{e.setState(e.state)},qqt=function(g,I){const i=g;let n=[];const C=qT(),r=()=>{n.forEach(o=>I.unsubscribe(o)),n=[]};return{destroy:r,publish:C.publish,stack:C.stack,public:{get version(){return IWe},setBroadcastMousePositionGlobally(o=!1){i.setBroadcastMousePositionGlobally(o)},setShowGlobalMousePosition(o=!1){i.setShowGlobalMousePosition(o)},setGlobalMousePosition(o=!1){i.setBroadcastMousePositionGlobally(o),i.setShowGlobalMousePosition(o)},setAuthHeader(o){mB(o),i.reload()},getAuthHeader(){return mB()},getComponent(){return i},reload(o){let A;o?A=o.flatMap(s=>typeof s=="string"?i.iterateOverTracksInView(s):s):A=i.iterateOverTracks();for(const{viewId:s,trackId:a}of A){const l=i.getTrackObject(s,a);for(const c of l.childTracks||[l])c.fetchedTiles&&(c.removeTiles(Object.keys(c.fetchedTiles)),c.fetching.clear(),c.refreshTiles()),c.rerender(c.options,!0)}},destroy(){r(),UI.unmountComponentAtNode(i.topDiv.parentNode)},setRangeSelectionToInt(){i.setState({rangeSelectionToInt:!0})},setRangeSelectionToFloat(){i.setState({rangeSelectionToInt:!1})},setRangeSelection1dSize(o=0,A=1/0){i.setState({rangeSelection1dSize:[o,A]})},setViewConfig(o,A=!1){const s=i.processViewConfig(o);return new Promise(l=>{this.requestsInFlight=0,n.push(I.subscribe("requestSent",()=>{this.requestsInFlight+=1})),n.push(I.subscribe("requestReceived",()=>{this.requestsInFlight-=1,this.requestsInFlight===0&&l()})),i.setState({viewConfig:o,views:s},()=>{A&&l()})})},getViewConfig(){return i.getViewsAsJson()},validateViewConfig(o,{verbose:A=!1}={}){const s=new _Xe().compile(LXe),a=s(o);return A&&s.errors&&console.warn(JSON.stringify(s.errors,null,2)),a},getMinMaxValue(o,A,s=!1,a=!1){return i.getMinMaxValue(o,A,s,a)},shareViewConfigAsLink(o){return i.handleExportViewsAsLink(o,!0)},showAvailableTrackPositions(o){i.setState({draggingHappening:o})},hideAvailableTrackPositions(){i.setState({draggingHappening:null})},showTrackChooser(o){i.setState({chooseTrackHandler:(...A)=>{i.setState({chooseTrackHandler:null}),o(...A)}})},hideTrackChooser(){this.setState({chooseTrackHandler:null})},setTrackValueScaleLimits(o,A,s,a){i.setTrackValueScaleLimits(o,A,s,a)},setDarkTheme(o){console.warn('`setDarkTheme(true)` is deprecated. Please use `setTheme("dark")`.');const A=o?"dark":"light";i.setTheme(A)},setTheme(o){console.warn("Please note that theming is still in beta!"),i.setTheme(o)},zoomTo(o,A,s,a,l,c=0){i.zoomTo(o,A,s,a,l,c)},zoomToGene(o,A,s=0,a=0){i.zoomToGene(o,A,s,a)},suggestGene(o,A,s){return i.suggestGene(o,A,s)},zoomToDataExtent(o){i.handleZoomToData(o)},resetViewport(o){i.resetViewport(o)},activateTool(o){switch(o){case"select":i.setMouseTool(Dr);break;default:i.setMouseTool(QX);break}},exportAsPngBlobPromise(){return i.createPNGBlobPromise()},exportAsSvg(){return i.createSVGString()},exportAsViewConfString(){return i.getViewsAsString()},getRangeSelection(){return i.rangeSelection},getLocation(o){const A=o?i.xScales[o]&&i.yScales[o]&&o:Object.values(i.tiledPlots)[0]&&Object.values(i.tiledPlots)[0].props.uid;return A?{xDomain:i.xScales[A].domain(),yDomain:i.yScales[A].domain(),xRange:i.xScales[A].range(),yRange:i.yScales[A].range()}:"Please provide a valid view UUID sweetheart 😙"},getTrackObject(o,A){let s=o,a=A;return A||(s=Object.values(i.state.views)[0].uid,a=o),tQ(i,s,a)},option(o,A){if(typeof A>"u")return i.props.options[o];switch(o){case"sizeMode":i.props.options[o]=A,$qt(i);break;default:console.warn(`This option "${o}" is either unknown or not settable.`)}},off(o,A,s){const a=typeof A=="object"?A.callback:A;switch(o){case"click":C.unsubscribe("click",a);break;case"cursorLocation":C.unsubscribe("cursorLocation",a);break;case"location":i.offLocationChange(s,A);break;case"mouseMoveZoom":C.unsubscribe("mouseMoveZoom",a);break;case"wheel":C.unsubscribe("wheel",a);break;case"rangeSelection":C.unsubscribe("rangeSelection",a);break;case"viewConfig":i.offViewChange(A);break;case"createSVG":i.offPostCreateSVG();break;case"geneSearch":C.unsubscribe("geneSearch",a);break}},on(o,A,s,a){switch(o){case"click":return C.subscribe("click",A);case"cursorLocation":return C.subscribe("cursorLocation",A);case"location":return i.onLocationChange(s,A,a);case"mouseMoveZoom":return C.subscribe("mouseMoveZoom",A);case"wheel":return C.subscribe("wheel",A);case"rangeSelection":return C.subscribe("rangeSelection",A);case"viewConfig":return i.onViewChange(A);case"createSVG":return i.onPostCreateSVG(A);case"geneSearch":return C.subscribe("geneSearch",A);default:return}}}}},eeg="_higlass_1uoq8_1",Qm={higlass:eeg,"higlass-dark-theme":"_higlass-dark-theme_1uoq8_5","higlass-container-overflow":"_higlass-container-overflow_1uoq8_9","higlass-scroll-container-overflow":"_higlass-scroll-container-overflow_1uoq8_10","higlass-scroll-container-scroll":"_higlass-scroll-container-scroll_1uoq8_11","higlass-canvas":"_higlass-canvas_1uoq8_28","higlass-drawing-surface":"_higlass-drawing-surface_1uoq8_34","higlass-svg":"_higlass-svg_1uoq8_38","tiled-area":"_tiled-area_1uoq8_47","track-mouseover-menu":"_track-mouseover-menu_1uoq8_52"};function teg(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function qae(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function eH(e){return eH=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},eH(e)}const ese=12,Aeg=12,aeg=20,seg="default",tse="bounded",gse="overflow",AZ="scroll";let gy=function(e){neg(I,e);var g=Ceg(I);function I(i){var n;teg(this,I),n=g.call(this,i),LZe(N.version)<15.6&&console.warn("HiGlass requires React v15.6 or higher. Current version: ",N.version),n.pubSub=qT(),n.domEvent=XZe(n.pubSub),n.pubSubs=[],n.minHorizontalHeight=20,n.minVerticalWidth=20,n.resizeSensor=null,n.uid=Ag.nice(),n.tiledPlots={},n.genomePositionSearchBoxes={},n.xScales={},n.yScales={},n.projectionXDomains={},n.projectionYDomains={},n.topDiv=null,n.zoomToDataExtentOnInit=new Set,n.viewTrackUidsToCombinedUid={},n.combinedUidToViewTrack={},n.scalesChangedListeners={},n.draggingChangedListeners={},n.valueScalesChangedListeners={},n.zoomLocks={},n.locationLocks={},n.locationLocksAxisWise={x:{},y:{}},n.valueScaleLocks={},n.prevAuthToken=i.options.authToken,n.setCenters={},n.plusImg={},n.configImg={},rt.PIXI=i.options&&i.options.PIXI||ufe,n.viewMarginTop=+i.options.viewMarginTop>=0?+i.options.viewMarginTop:SZ,n.viewMarginBottom=+i.options.viewMarginBottom>=0?+i.options.viewMarginBottom:SZ,n.viewMarginLeft=+i.options.viewMarginLeft>=0?+i.options.viewMarginLeft:SZ,n.viewMarginRight=+i.options.viewMarginRight>=0?+i.options.viewMarginRight:SZ,n.viewPaddingTop=+i.options.viewPaddingTop>=0?+i.options.viewPaddingTop:wZ,n.viewPaddingBottom=+i.options.viewPaddingBottom>=0?+i.options.viewPaddingBottom:wZ,n.viewPaddingLeft=+i.options.viewPaddingLeft>=0?+i.options.viewPaddingLeft:wZ,n.viewPaddingRight=+i.options.viewPaddingRight>=0?+i.options.viewPaddingRight:wZ,n.genomePositionSearchBox=null,n.viewHeaders={},n.boundRefreshView=()=>{n.refreshView(VZ)},n.unsetOnLocationChange=[],n.setTheme(i.options.theme,i.options.isDarkTheme),n.viewconfLoaded=!1;const{viewConfig:C}=n.props,r=n.loadIfRemoteViewConfig(n.props.viewConfig);i.options.authToken&&mB(i.options.authToken),n.pixiRoot=new rt.PIXI.Container,n.pixiRoot.interactive=!0,n.pixiStage=new rt.PIXI.Container,n.pixiStage.interactive=!0,n.pixiRoot.addChild(n.pixiStage),n.pixiMask=new rt.PIXI.Graphics,n.pixiRoot.addChild(n.pixiMask),n.pixiStage.mask=n.pixiMask,n.element=null,n.scrollTop=0;let o=QX;if(n.props.options)switch(n.props.options.mouseTool){case Dr:o=Dr;break}n.props.options.pluginTracks&&(window.higlassTracksByType=Object.assign(window.higlassTracksByType||{},n.props.options.pluginTracks));const A={};try{window.higlassTracksByType&&Object.entries(window.higlassTracksByType).forEach(([h,m])=>{A[h]=m})}catch{console.warn("Broken config of a plugin track")}n.props.options.pluginDataFetchers&&(window.higlassDataFetchersByType=Object.assign(window.higlassDataFetchersByType||{},n.props.options.pluginDataFetchers));const s=window.higlassDataFetchersByType,a=n.props.options.pixelPreciseMarginPadding?1:30;n.mounted=!1,n.pluginTracks=A,n.pluginDataFetchers=s,n.state={currentBreakpoint:"lg",width:0,height:0,rowHeight:a,svgElement:null,canvasElement:null,customDialog:null,views:r,viewConfig:C,addTrackPositionMenuPosition:null,typedEditable:void 0,mouseOverOverlayUid:null,mouseTool:o,isDarkTheme:!1,rangeSelection1dSize:[0,1/0],rangeSelectionToInt:!1,modal:null},n.attachedToDOM=!1;const{public:l,destroy:c,publish:u,stack:d}=qqt(jg(n),n.pubSub);return n.api=l,n.apiDestroy=c,n.apiPublish=u,n.apiStack=d,n.viewChangeListener=[],n.triggerViewChangeDb=E7(n.triggerViewChange.bind(jg(n)),250),n.pubSubs=[],n.rangeSelection=[null,null],n.prevMouseHoverTrack=null,n.zooming=!1,n.appClickHandlerBound=n.appClickHandler.bind(jg(n)),n.canvasClickHandlerBound=n.canvasClickHandler.bind(jg(n)),n.keyDownHandlerBound=n.keyDownHandler.bind(jg(n)),n.keyUpHandlerBound=n.keyUpHandler.bind(jg(n)),n.resizeHandlerBound=n.resizeHandler.bind(jg(n)),n.resizeHandlerBound=n.resizeHandler.bind(jg(n)),n.dispatchEventBound=n.dispatchEvent.bind(jg(n)),n.animateOnMouseMoveHandlerBound=n.animateOnMouseMoveHandler.bind(jg(n)),n.zoomStartHandlerBound=n.zoomStartHandler.bind(jg(n)),n.zoomEndHandlerBound=n.zoomEndHandler.bind(jg(n)),n.zoomHandlerBound=n.zoomHandler.bind(jg(n)),n.trackDroppedHandlerBound=n.trackDroppedHandler.bind(jg(n)),n.trackDimensionsModifiedHandlerBound=n.trackDimensionsModifiedHandler.bind(jg(n)),n.animateBound=n.animate.bind(jg(n)),n.animateOnGlobalEventBound=n.animateOnGlobalEvent.bind(jg(n)),n.requestReceivedHandlerBound=n.requestReceivedHandler.bind(jg(n)),n.wheelHandlerBound=n.wheelHandler.bind(jg(n)),n.mouseMoveHandlerBound=n.mouseMoveHandler.bind(jg(n)),n.onMouseLeaveHandlerBound=n.onMouseLeaveHandler.bind(jg(n)),n.onBlurHandlerBound=n.onBlurHandler.bind(jg(n)),n.openModalBound=n.openModal.bind(jg(n)),n.closeModalBound=n.closeModal.bind(jg(n)),n.handleEditViewConfigBound=n.handleEditViewConfig.bind(jg(n)),n.onScrollHandlerBound=n.onScrollHandler.bind(jg(n)),n.typedText="",n.typedTextTimeout=null,n.modal={open:n.openModalBound,close:n.closeModalBound},n.setBroadcastMousePositionGlobally(n.props.options.broadcastMousePositionGlobally||n.props.options.globalMousePosition),n.setShowGlobalMousePosition(n.props.options.showGlobalMousePosition||n.props.options.globalMousePosition),n}return geg(I,[{key:"UNSAFE_componentWillMount",value:function(){this.domEvent.register("keydown",document),this.domEvent.register("keyup",document),this.domEvent.register("scroll",document),this.domEvent.register("resize",window),this.domEvent.register("orientationchange",window),this.domEvent.register("wheel",window),this.domEvent.register("mousedown",window,!0),this.domEvent.register("mouseup",window,!0),this.domEvent.register("click",window,!0),this.domEvent.register("mousemove",window),this.domEvent.register("touchmove",window),this.domEvent.register("touchstart",window),this.domEvent.register("touchend",window),this.domEvent.register("touchcancel",window),this.domEvent.register("blur",window),this.pubSubs.push(this.pubSub.subscribe("app.click",this.appClickHandlerBound),this.pubSub.subscribe("blur",this.onBlurHandlerBound),this.pubSub.subscribe("keydown",this.keyDownHandlerBound),this.pubSub.subscribe("keyup",this.keyUpHandlerBound),this.pubSub.subscribe("resize",this.resizeHandlerBound),this.pubSub.subscribe("wheel",this.wheelHandlerBound),this.pubSub.subscribe("orientationchange",this.resizeHandlerBound),this.pubSub.subscribe("app.event",this.dispatchEventBound),this.pubSub.subscribe("app.animateOnMouseMove",this.animateOnMouseMoveHandlerBound),this.pubSub.subscribe("trackDropped",this.trackDroppedHandlerBound),this.pubSub.subscribe("trackDimensionsModified",this.trackDimensionsModifiedHandlerBound),this.pubSub.subscribe("app.zoomStart",this.zoomStartHandlerBound),this.pubSub.subscribe("app.zoomEnd",this.zoomEndHandlerBound),this.pubSub.subscribe("app.zoom",this.zoomHandlerBound),this.pubSub.subscribe("requestReceived",this.requestReceivedHandlerBound)),this.props.getApi&&this.props.getApi(this.api)}},{key:"sizeMode",get:function(){return typeof this.props.options.sizeMode>"u"?this.props.options.bounded?"bounded":seg:this.props.options.sizeMode}},{key:"setBroadcastMousePositionGlobally",value:function(n=!1){this.isBroadcastMousePositionGlobally=n}},{key:"setShowGlobalMousePosition",value:function(n=!1){if(this.isShowGlobalMousePosition=n,this.isShowGlobalMousePosition&&!this.globalMousePositionListener&&(this.globalMousePositionListener=VG.subscribe("higlass.mouseMove",this.animateOnGlobalEventBound),this.pubSubs.push(this.globalMousePositionListener)),this.isShowGlobalMousePosition&&!this.globalMousePositionListener){const C=this.pubSubs.findIndex(r=>r===this.globalMousePositionListener);VG.unsubscribe(this.globalMousePositionListener),C>=0&&this.pubSubs.splice(C,1),this.globalMousePositionListener=void 0}}},{key:"zoomStartHandler",value:function(){this.hideHoverMenu(),this.zooming=!0}},{key:"zoomEndHandler",value:function(){this.zooming=!1}},{key:"zoomHandler",value:function(n){n.sourceEvent&&this.mouseMoveHandler(n.sourceEvent)}},{key:"waitForDOMAttachment",value:function(n){if(!this.mounted)return;const C=UI.findDOMNode(this);document.body.contains(C)?n():requestAnimationFrame(()=>this.waitForDOMAttachment(n))}},{key:"componentDidMount",value:function(){this.mounted=!0,this.element=UI.findDOMNode(this),window.addEventListener("focus",this.boundRefreshView),Object.values(this.state.views).forEach(o=>{this.adjustLayoutToTrackSizes(o),o.layout?o.layout.i=o.uid:o.layout=this.generateViewLayout(o)});const n={width:this.state.width,height:this.state.height,view:this.canvasElement,antialias:!0,transparent:!0,resolution:2,autoResize:!0},C=parseInt(pme[0],10);C===4?(console.warn("Deprecation warning: please update Pixi.js to version 5 or above!"),this.props.options.renderer==="canvas"?this.pixiRenderer=new rt.PIXI.CanvasRenderer(n):this.pixiRenderer=new rt.PIXI.WebGLRenderer(n)):(C<4&&console.warn("Deprecation warning: please update Pixi.js to version 5 or above! This version of Pixi.js is unsupported. Good luck 🤞"),this.props.options.renderer==="canvas"?this.pixiRenderer=new rt.PIXI.CanvasRenderer(n):this.pixiRenderer=new rt.PIXI.Renderer(n)),this.fitPixiToParentContainer(),this.setState({svgElement:this.svgElement,canvasElement:this.canvasElement}),this.waitForDOMAttachment(()=>{PX.ElementQueries.listen(),this.resizeSensor=new PX.ResizeSensor(this.element.parentNode,this.updateAfterResize.bind(this)),this.updateAfterResize()}),this.handleDragStart(),this.handleDragStop(),this.animate();const r=cg(this.element).append("svg").style("display","none");Cat.forEach(o=>jqt(r,o.id,o.paths,o.viewBox))}},{key:"getTrackObject",value:function(n,C){return this.tiledPlots[n].trackRenderer.getTrackObject(C)}},{key:"getTrackRenderer",value:function(n){return this.tiledPlots[n].trackRenderer}},{key:"loadIfRemoteViewConfig",value:function(n){let C={};return typeof n=="string"?Gt.json(n,(r,o)=>{n=o,this.setState({views:this.processViewConfig(JSON.parse(JSON.stringify(o))),viewConfig:o}),this.unsetOnLocationChange.forEach(({viewId:A,callback:s,callbackId:a})=>{this.onLocationChange(A,s,a)})},this.pubSub):(C=this.processViewConfig(JSON.parse(JSON.stringify(n))),this.mounted&&this.setState({viewConfig:n})),C}},{key:"UNSAFE_componentWillReceiveProps",value:function(n){const C=this.loadIfRemoteViewConfig(n.viewConfig);if(n.options.authToken!==this.prevAuthToken){mB(n.options.authToken);for(const r of this.iterateOverViews()){const o=this.getTrackRenderer(r),A=JSON.parse(o.prevTrackDefinitions);o.syncTrackObjects([]),o.syncTrackObjects(A)}this.prevAuthToken=n.options.authToken}for(const r of xg(C))this.adjustLayoutToTrackSizes(r);this.setState({views:C})}},{key:"UNSAFE_componentWillUpdate",value:function(){this.pixiRenderer.render(this.pixiRoot)}},{key:"componentDidUpdate",value:function(){this.setTheme(this.props.options.theme,this.props.options.isDarkTheme),this.animate(),this.triggerViewChangeDb()}},{key:"componentWillUnmount",value:function(){this.mounted=!1,this.pixiStage.destroy(!1),this.pixiStage=null,this.pixiRenderer.destroy(!0),this.pixiRenderer=null,window.removeEventListener("focus",this.boundRefreshView),this.resizeSensor&&this.resizeSensor.detach(),this.domEvent.unregister("keydown",document),this.domEvent.unregister("keyup",document),this.domEvent.unregister("scroll",document),this.domEvent.unregister("wheel",window),this.domEvent.unregister("mousedown",window),this.domEvent.unregister("mouseup",window),this.domEvent.unregister("click",window),this.domEvent.unregister("mousemove",window),this.domEvent.unregister("touchmove",window),this.domEvent.unregister("touchstart",window),this.domEvent.unregister("touchend",window),this.domEvent.unregister("touchcancel",window),this.pubSubs.forEach(n=>this.pubSub.unsubscribe(n)),this.pubSubs=[],this.apiDestroy()}},{key:"setTheme",value:function(n=this.props.options.theme,C=this.props.options.isDarkTheme){if(typeof C<"u")console.warn("The option `isDarkTheme` is deprecated. Please use `theme` instead."),this.theme=C?"dark":"light";else switch(n){case"dark":this.theme=qg;break;case"light":case void 0:this.theme=$X;break;default:console.warn(`Unknown theme "${n}". Using light theme.`),this.theme=$X;break}}},{key:"dispatchEvent",value:function(n){this.canvasElement&&t9(n,this.canvasElement)}},{key:"trackDroppedHandler",value:function(){this.setState({draggingHappening:null})}},{key:"requestReceivedHandler",value:function(){!this.viewconfLoaded&&hB===0&&(this.viewconfLoaded=!0,this.props.options.onViewConfLoaded&&this.props.options.onViewConfLoaded())}},{key:"animateOnMouseMoveHandler",value:function(n){n&&!this.animateOnMouseMove&&this.pubSubs.push(this.pubSub.subscribe("app.mouseMove",this.animateBound)),this.animateOnMouseMove=n}},{key:"fitPixiToParentContainer",value:function(){if(!this.element||!this.element.parentNode){console.warn("No parentNode:",this.element);return}const n=this.element.parentNode.clientWidth,C=this.element.parentNode.clientHeight;this.pixiMask.beginFill(16777215).drawRect(0,0,n,C).endFill(),this.pixiRenderer.resize(n,C),this.pixiRenderer.view.style.width=`${n}px`,this.pixiRenderer.view.style.height=`${C}px`,this.pixiRenderer.render(this.pixiRoot)}},{key:"addDefaultTrackOptions",value:function(n){const C=this.getTrackInfo(n.type);if(!C)return;typeof n.options>"u"&&(n.options={});const r=n.options?n.options:{};if(this.props.options.defaultTrackOptions){if(this.props.options.defaultTrackOptions.trackSpecific&&this.props.options.defaultTrackOptions.trackSpecific[n.type]){const o=this.props.options.defaultTrackOptions.trackSpecific[n.type];for(const A in o)n.options[A]=typeof n.options[A]<"u"?n.options[A]:JSON.parse(JSON.stringify(o[A]))}if(this.props.options.defaultTrackOptions.all){const o=this.props.options.defaultTrackOptions.all;for(const A in o)n.options[A]=typeof n.options[A]<"u"?n.options[A]:JSON.parse(JSON.stringify(o[A]))}}if(C.defaultOptions){const o=C.defaultOptionsByTheme&&C.defaultOptionsByTheme[this.theme]?C.defaultOptionsByTheme[this.theme]:{},A={...C.defaultOptions,...o};if(!n.options)n.options=JSON.parse(JSON.stringify(A));else for(const s in A)n.options[s]=typeof n.options[s]<"u"?n.options[s]:JSON.parse(JSON.stringify(A[s]))}else n.options=r}},{key:"toggleTypedEditable",value:function(){this.setState({typedEditable:!this.isEditable()})}},{key:"typedTextHandler",value:function(n){if(!this.props.options.cheatCodesEnabled)return;this.typedText=this.typedText.concat(n.key),this.typedText.endsWith("hgedit")&&(this.toggleTypedEditable(),this.typedText="");const C=750;this.typedTextTimeout&&clearTimeout(this.typedTextTimeout),this.typedTextTimeout=setTimeout(()=>{this.typedText=""},C)}},{key:"keyDownHandler",value:function(n){this.typedTextHandler(n),this.props.options.rangeSelectionOnAlt&&n.key==="Alt"&&this.setState({mouseTool:Dr})}},{key:"keyUpHandler",value:function(n){this.props.options.rangeSelectionOnAlt&&n.key==="Alt"&&this.setState({mouseTool:QX})}},{key:"openModal",value:function(n){this.setState({modal:N.cloneElement(n,{ref:C=>{this.modalRef=C}})})}},{key:"closeModal",value:function(){this.modalRef=null,this.setState({modal:null})}},{key:"handleEditViewConfig",value:function(){const{viewConfig:n}=this.state;this.setState({viewConfigTmp:n}),this.openModal(N.createElement(Qqt,{onCancel:()=>{const{viewConfigTmp:C}=this.state,r=this.processViewConfig(C);for(const o of xg(r))this.adjustLayoutToTrackSizes(o);this.setState({views:r,viewConfig:C,viewConfigTmp:null})},onChange:C=>{const r=JSON.parse(C),o=this.processViewConfig(r);for(const A of xg(o))this.adjustLayoutToTrackSizes(A);this.setState({views:o,viewConfig:r})},onSave:C=>{const r=JSON.parse(C),o=this.processViewConfig(r);for(const A of xg(o))this.adjustLayoutToTrackSizes(A);this.setState({views:o,viewConfig:r,viewConfigTmp:null})},viewConfig:this.getViewsAsString()}))}},{key:"animate",value:function(){this.isRequestingAnimationFrame||(this.isRequestingAnimationFrame=!0,requestAnimationFrame(()=>{this.pixiRenderer&&(this.pixiRenderer.render(this.pixiRoot),this.isRequestingAnimationFrame=!1)}))}},{key:"animateOnGlobalEvent",value:function({sourceUid:n}={}){n!==this.uid&&this.animateOnMouseMove&&this.animate()}},{key:"measureSize",value:function(){const[n,C]=kZe(this.element);n>0&&C>0&&this.setState({sizeMeasured:!0,width:n,height:C})}},{key:"updateAfterResize",value:function(){this.measureSize(),this.updateRowHeight(),this.fitPixiToParentContainer(),this.refreshView(VZ),this.resizeHandler()}},{key:"onBreakpointChange",value:function(n){this.setState({currentBreakpoint:n})}},{key:"handleOverlayMouseEnter",value:function(n){this.setState({mouseOverOverlayUid:n})}},{key:"handleOverlayMouseLeave",value:function(){this.setState({mouseOverOverlayUid:null})}},{key:"handleLockLocation",value:function(n){this.setState({chooseViewHandler:C=>this.handleLocationLockChosen(n,C),mouseOverOverlayUid:n})}},{key:"isEditable",value:function(){return this.state.typedEditable!==void 0?this.state.typedEditable:!this.props.options||!("editable"in this.props.options)?this.state.viewConfig.editable:this.props.options.editable&&this.state.viewConfig.editable}},{key:"isTrackMenuDisabled",value:function(){return this.props.options&&(this.props.options.editable===!1||this.props.options.tracksEditable===!1)?!0:this.state.viewConfig&&(this.state.viewConfig.tracksEditable===!1||this.state.viewConfig.editable===!1)}},{key:"isViewHeaderDisabled",value:function(){return this.props.options&&(this.props.options.editable===!1||this.props.options.viewEditable===!1)?!0:this.state.viewConfig&&(this.state.viewConfig.viewEditable===!1||this.state.viewConfig.editable===!1)}},{key:"iterateOverViews",value:function(){const n=[];for(const C in Object.keys(this.state.views))n.push(C);return n}},{key:"iterateOverTracksInView",value:function(n){const C=[],{tracks:r}=this.state.views[n];for(const o in r)for(const A of r[o])if(A.type==="combined"&&A.contents)for(const s of A.contents)C.push({viewId:n,trackId:s.uid,track:s});else C.push({viewId:n,trackId:A.uid,track:A});return C}},{key:"iterateOverTracks",value:function(){const n=[];for(const C in this.state.views){const{tracks:r}=this.state.views[C];for(const o in r)for(const A of r[o])if(A.type==="combined"&&A.contents)for(const s of A.contents)n.push({viewId:C,trackId:s.uid,track:s});else n.push({viewId:C,trackId:A.uid,track:A})}return n}},{key:"setMouseTool",value:function(n){this.setState({mouseTool:n})}},{key:"isValueScaleLocked",value:function(n,C){const r=this.combineViewAndTrackUid(n,C);return this.state.views[n]?!!this.valueScaleLocks[r]:!1}},{key:"getLockGroupExtrema",value:function(n,C){const r=this.combineViewAndTrackUid(n,C);if(!this.state.views[n]||!this.valueScaleLocks[r])return null;const o=this.valueScaleLocks[r],A=Object.values(o).filter(u=>this.tiledPlots[u.view]).map(u=>this.tiledPlots[u.view].trackRenderer.getTrackObject(u.track)).filter(u=>u).map(u=>u.originalTrack===void 0?u:u.originalTrack),s=A.filter(u=>u.minRawValue&&u.maxRawValue).map(u=>o.ignoreOffScreenValues?u.minVisibleValue(!0):u.minVisibleValueInTiles(!0)),a=A.filter(u=>u.minRawValue&&u.maxRawValue).map(u=>o.ignoreOffScreenValues?u.maxVisibleValue(!0):u.maxVisibleValueInTiles(!0));if(s.length===0||s.filter(u=>u===null||u===1/0).length>0||a.length===0||a.filter(u=>u===null||u===-1/0).length>0)return null;const l=Math.min(...s),c=Math.max(...a);return[l,c]}},{key:"syncValueScales",value:function(n,C){const r=this.combineViewAndTrackUid(n,C);if(!this.state.views[n])return;const o=jC(this.state.views[n].tracks,C);if(this.valueScaleLocks[r]){const A=this.valueScaleLocks[r],s=Object.values(A).filter(d=>this.tiledPlots[d.view]).map(d=>this.tiledPlots[d.view].trackRenderer.getTrackObject(d.track)).filter(d=>d).map(d=>d.originalTrack===void 0?d:d.originalTrack),a=this.getLockGroupExtrema(n,C);if(a===null)return;const l=a[0],c=a[1],u=1e-6;for(const d of s){if(d.minValue&&d.minValue(l),d.maxValue&&d.maxValue(c),!d.valueScale)continue;const h=Math.abs(d.minValue()-d.valueScale.domain()[0])>u||Math.abs(d.maxValue()-d.valueScale.domain()[1])>u,m=o.options&&d.options&&typeof o.options.scaleStartPercent<"u"&&typeof o.options.scaleEndPercent<"u"&&(Math.abs(d.options.scaleStartPercent-o.options.scaleStartPercent)>u||Math.abs(d.options.scaleEndPercent-o.options.scaleEndPercent)>u);d.continuousScaling&&!h&&!m||(d.valueScale.domain([l,c]),d.prevValueScale=d.valueScale.copy(),m&&(d.options.scaleStartPercent=o.options.scaleStartPercent,d.options.scaleEndPercent=o.options.scaleEndPercent),d.rerender(d.options,!0))}}}},{key:"handleNewTilesLoaded",value:function(n,C){this.animate()}},{key:"notifyDragChangedListeners",value:function(n){xg(this.draggingChangedListeners).forEach(C=>{xg(C).forEach(r=>r(n))})}},{key:"addDraggingChangedListener",value:function(n,C,r){this.draggingChangedListeners.hasOwnProperty(n)||(this.draggingChangedListeners[n]={}),this.draggingChangedListeners[n][C]=r,r(!0),r(!1)}},{key:"removeDraggingChangedListener",value:function(n,C){if(this.draggingChangedListeners.hasOwnProperty(n)){const r=this.draggingChangedListeners[n];r.hasOwnProperty(C)&&(r[C](!1),delete r[C])}}},{key:"addScalesChangedListener",value:function(n,C,r){this.scalesChangedListeners[n]||(this.scalesChangedListeners[n]={}),this.scalesChangedListeners[n][C]=r,!(!this.xScales[n]||!this.yScales[n])&&r(this.xScales[n],this.yScales[n])}},{key:"removeScalesChangedListener",value:function(n,C){if(this.scalesChangedListeners[n]){const r=this.scalesChangedListeners[n];r[C]&&delete r[C]}}},{key:"createSVG",value:function(){const n=document.createElement("svg");n.setAttribute("xmlns:xlink","http://www.w3.org/1999/xlink"),n.setAttribute("xmlns","http://www.w3.org/2000/svg"),n.setAttribute("version","1.1");for(const C of xg(this.tiledPlots))if(C){for(const r of xg(C.trackRenderer.trackDefObjects))if(r.trackObject.exportSVG){const o=r.trackObject.exportSVG();o&&n.appendChild(o[0])}}return n.setAttribute("width",this.canvasElement.style.width),n.setAttribute("height",this.canvasElement.style.height),this.postCreateSVGCallback?this.postCreateSVGCallback(n):n}},{key:"createSVGString",value:function(){const n=this.createSVG();let C=frt.xml(new window.XMLSerializer().serializeToString(n));return C=C.replace(/ -${C}`}},{key:"handleExportSVG",value:function(){tB("export.svg",new Blob([this.createSVGString()],{type:"image/svg+xml"}))}},{key:"offPostCreateSVG",value:function(){this.postCreateSVGCallback=null}},{key:"onPostCreateSVG",value:function(n){this.postCreateSVGCallback=n}},{key:"createPNGBlobPromise",value:function(){return new Promise(n=>{const C=this.createSVGString(),r=new Image(this.canvasElement.width,this.canvasElement.height);r.src=`data:image/svg+xml;base64,${btoa(C)}`,r.onload=()=>{const o=document.createElement("canvas");o.width=this.canvasElement.width/2,o.height=this.canvasElement.height/2,o.getContext("2d").drawImage(r,0,0),o.toBlob(A=>{n(A)})}})}},{key:"handleExportPNG",value:function(){this.createPNGBlobPromise().then(n=>{tB("export.png",n)})}},{key:"handleScalesChanged",value:function(n,C,r,o=!0){if(this.xScales[n]=C,this.yScales[n]=r,o&&n in this.scalesChangedListeners&&Pg(this.scalesChangedListeners[n]).forEach(A=>{A(C,r)}),this.zoomLocks[n]){const A=this.zoomLocks[n],s=xr(A),[a,l,c]=Zi(this.xScales[n],this.yScales[n]);for(let u=0;u{G(Z,v)})}}if(this.locationLocks[n]){const A=this.locationLocks[n],s=xr(A),[a,l,c]=Zi(this.xScales[n],this.yScales[n]);for(let u=0;u{w(G,B)})}}if(this.locationLocksAxisWise.x[n]){const A=this.locationLocksAxisWise.x[n].lock,s=xr(A),a=this.locationLocksAxisWise.x[n].axis!=="x",[l,c,u]=Zi(this.xScales[n],this.yScales[n]);for(let d=0;d{B(v,G)})}}if(this.locationLocksAxisWise.y[n]){const A=this.locationLocksAxisWise.y[n].lock,s=xr(A),a=this.locationLocksAxisWise.y[n].axis!=="y",[l,c,u]=Zi(this.xScales[n],this.yScales[n]);for(let d=0;d{B(v,G)})}}this.animate(),this.triggerViewChangeDb()}},{key:"handleProjectViewport",value:function(n){this.setState({chooseTrackHandler:(C,r)=>this.handleViewportProjected(n,C,r)})}},{key:"handleZoomToData",value:function(n){if(n&&!this.tiledPlots[n])throw new Error(`View uid ${n} does not exist in the current viewConfig`);n?this.tiledPlots[n].handleZoomToData():Object.values(this.tiledPlots).forEach(C=>C.handleZoomToData())}},{key:"resetViewport",value:function(n){if(n&&!this.tiledPlots[n])throw new Error(`View uid ${n} does not exist in the current viewConfig`);n?this.tiledPlots[n].resetViewport():Object.values(this.tiledPlots).forEach(C=>C.resetViewport())}},{key:"handleYankFunction",value:function(n,C){this.setState({chooseViewHandler:r=>C(n,r),mouseOverOverlayUid:n})}},{key:"handleUnlock",value:function(n,C){const r=C[n],o=Nr(r);if(o.length===2){delete C[o[0]],delete C[o[1]];return}C[n]&&C[n][n]&&delete C[n][n],C[n]&&delete C[n]}},{key:"viewScalesLockData",value:function(n){return!this.xScales[n]||!this.yScales[n]?(console.warn("View scale lock doesn't correspond to existing uid: ",n),null):Zi(this.xScales[n],this.yScales[n])}},{key:"addLock",value:function(n,C,r,o){let A=[],s=[];r[n]?A=xr(r[n]).filter(c=>o(c[0])).map(c=>[c[0],o(c[0])]):A=[[n,o.bind(this)(n)]],r[C]?s=xr(r[C]).filter(c=>o.bind(this)(c[0])).map(c=>[c[0],o.bind(this)(c[0])]):s=[[C,o.bind(this)(C)]];const a=A.concat(s),l=KGe(a);a.forEach(c=>{r[c[0]]=l})}},{key:"handleLocationLockChosen",value:function(n,C){if(n===C){this.setState({chooseViewHandler:null});return}this.addLock(n,C,this.locationLocks,this.viewScalesLockData.bind(this)),this.setState({chooseViewHandler:null})}},{key:"handleZoomLockChosen",value:function(n,C){if(n===C){this.setState({chooseViewHandler:null});return}this.addLock(n,C,this.zoomLocks,this.viewScalesLockData.bind(this)),this.setState({chooseViewHandler:null})}},{key:"handleViewportProjected",value:function(n,C,r){let o=null;if(n===C)console.warn("A view can not show its own viewport.");else{const A=gr(this.state.views[C].tracks,r),s=gB(this.state.views[C].tracks,r);o=dg.nice();const l={uid:o,type:`viewport-projection-${{top:"horizontal",bottom:"horizontal",center:"center",left:"vertical",right:"vertical"}[s]}`,fromViewUid:n};this.addCallbacks(C,l),this.handleTrackAdded(C,l,s,A)}return this.setState({chooseTrackHandler:null}),o}},{key:"handleLocationYanked",value:function(n,C){const r=this.xScales[C],o=this.yScales[C],A=this.xScales[n],s=this.yScales[n],[a,l,c]=Zi(A,s),[u,d,h]=Zi(r,o);this.setCenters[n](u,d,c,!0),this.setState({chooseViewHandler:null})}},{key:"handleZoomYanked",value:function(n,C){const r=this.xScales[C],o=this.yScales[C],A=this.xScales[n],s=this.yScales[n],[a,l,c]=Zi(A,s),[u,d,h]=Zi(r,o);this.setCenters[n](a,l,h,!0),this.setState({chooseViewHandler:null})}},{key:"handleTrackPositionChosen",value:function(n,C){this.setState({addTrackPosition:C,addTrackPositionView:n})}},{key:"updateRowHeight",value:function(){if(!this.props.options||this.sizeMode!==Fse||this.props.options.pixelPreciseMarginPadding)return;const n=this.element.parentNode.clientHeight;let C=0;for(const l of Pg(this.state.views))C=Math.max(C,l.layout.y+l.layout.h);this.handleDragStart(),this.handleDragStop();const o=(this.isEditable()?10:0)*C-1,s=(n-o)/C,a=Math.floor(s);this.setState({rowHeight:a})}},{key:"handleLayoutChange",value:function(n){this.element&&(n.forEach(C=>{const r=this.state.views[C.i];r&&(r.layout.x=C.x,r.layout.y=C.y,r.layout.w=C.w,r.layout.h=C.h,r.layout.i=C.i)}),this.updateRowHeight(),this.refreshView(eG))}},{key:"clearDragTimeout",value:function(){this.dragTimeout&&(clearTimeout(this.dragTimeout),this.dragTimeout=null)}},{key:"getTrackInfo",value:function(n){if($g[n])return $g[n];if(this.pluginTracks&&this.pluginTracks[n])return this.pluginTracks[n].config;if(window.higlassTracksByType&&window.higlassTracksByType[n])return window.higlassTracksByType[n].config;console.warn("Track type not found:",n,"(check app/scripts/config/ for a list of defined track types)")}},{key:"forceRefreshView",value:function(){this.setState(this.state)}},{key:"refreshView",value:function(n=SGe){this.clearDragTimeout(),this.notifyDragChangedListeners(!0),this.clearDragTimeout(),this.dragTimeout=setTimeout(()=>{this.notifyDragChangedListeners(!1)},n)}},{key:"handleDragStart",value:function(){this.clearDragTimeout(),this.notifyDragChangedListeners(!0)}},{key:"handleDragStop",value:function(){this.clearDragTimeout(),this.dragTimeout=setTimeout(()=>{this.notifyDragChangedListeners(!1)},eG)}},{key:"resizeHandler",value:function(){jN(this.viewHeaders).filter(n=>n).forEach(n=>n.checkWidth())}},{key:"calculateViewDimensions",value:function(n){let s=this.viewMarginTop+this.viewMarginBottom+this.viewPaddingTop+this.viewPaddingBottom,a=this.viewMarginLeft+this.viewMarginRight+this.viewPaddingLeft+this.viewPaddingRight,l=0;l+=10;const c=20;if(n.tracks.top)for(let v=0;v0||n.tracks.right&&n.tracks.right.length>0||n.tracks.center&&n.tracks.center.length>0)&&(l+=c);let u=0;if(n.tracks.left)for(let v=0;v0){if(!n.tracks.center[0].contents||n.tracks.center[0].contents.length>0){let v=null,G=null;if(n.tracks.center[0].contents)for(const B of n.tracks.center[0].contents)v=Math.max(v,B.height?B.height:100),G=Math.max(G,B.width?B.width:100);else v=n.tracks.center[0].height?n.tracks.center[0].height:100,G=n.tracks.center[0].width?n.tracks.center[0].width:100;s+=v,a+=G}}else(n.tracks.top&&Pg(n.tracks.top).length>1||n.tracks.bottom&&Pg(n.tracks.bottom).length>1)&&(n.tracks.left&&Pg(n.tracks.left).length||n.tracks.right&&Pg(n.tracks.right).length)&&(f=100,m=100);h>m?s+=h:s+=m;let b=0,p=0,y=0,Z=0;return"top"in n.tracks&&(b=n.tracks.top.map(v=>v.height?v.height:20).reduce((v,G)=>v+G,0)),"bottom"in n.tracks&&(p=n.tracks.bottom.map(v=>v.height?v.height:20).reduce((v,G)=>v+G,0)),"left"in n.tracks&&(y=n.tracks.left.map(v=>v.width?v.width:0).reduce((v,G)=>v+G,0)),"right"in n.tracks&&(Z=n.tracks.right.map(v=>v.width?v.width:0).reduce((v,G)=>v+G,0)),{totalWidth:a,totalHeight:s,topHeight:b,bottomHeight:p,leftWidth:y,rightWidth:Z,centerWidth:f,centerHeight:m,minNecessaryHeight:l}}},{key:"calculateZoomLimits",value:function(n,C){const r=[0,1/0],o=n.zoomLimits||[1,null],A=C[1]-C[0];if(o.length!==2)return r;if(o[0]!==null&&o[0]>0){const s=A/o[0];r[1]=Math.max(s,1),s<1&&console.warn(`Invalid zoom limits. Lower limit set to ${A}`)}if(o[1]!==null&&o[1]>o[0]){const s=A/o[1];r[0]=Math.min(s,1),s>1&&console.warn(`Invalid zoom limits. Upper limit set to ${A}`)}return r}},{key:"generateViewLayout",value:function(n){let C=null;return"layout"in n?{layout:C}=n.layout:C={x:0,y:0,w:Dse,h:X6t},C}},{key:"handleClearView",value:function(n){const{views:C}=this.state;C[n].tracks.top=[],C[n].tracks.bottom=[],C[n].tracks.center=[],C[n].tracks.left=[],C[n].tracks.right=[],C[n].tracks.whole=[],this.setState({views:C})}},{key:"handleCloseView",value:function(n){Pg(this.state.views).length!==1&&(this.handleUnlock(n,this.zoomLocks),this.setState(C=>(delete C.views[n],{views:this.removeInvalidTracks(C.views)})))}},{key:"handleSeriesAdded",value:function(n,C,r,o){const{tracks:A}=this.state.views[n];if(o.type==="combined")o.contents.push(C),C.type==="heatmap"&&this.compatibilityfyStackedHeatmaps(C,o);else{const s={type:"combined",uid:dg.nice(),height:o.height,width:o.width,contents:[o,C]},a=A[r];for(let l=0;l({views:s.views}))}},{key:"handleNoTrackAdded",value:function(){this.state.addTrackPosition&&this.setState({addTrackPosition:null})}},{key:"handleTracksAdded",value:function(n,C,r,o){this.storeTrackSizes(n);for(const A of C)this.handleTrackAdded(n,A,r,o)}},{key:"handleChangeTrackType",value:function(n,C,r){const o=this.state.views[n],A=gr(o.tracks,C),s=A.uid;A.uid=dg.nice(),A.type=r;const a=A.uid;this.updateTrackLocks(n,s,a),this.setState(l=>({views:l.views}))}},{key:"handleChangeTrackData",value:function(n,C,r){const o=this.state.views[n],A=gr(o.tracks,C);A.uid=dg.nice(),A.data=r,this.setState(s=>({views:s.views}))}},{key:"handleTrackAdded",value:function(n,C,r,o=null){if(this.addDefaultTrackOptions(C),C.uid||(C.uid=dg.nice()),C.contents)for(const l of C.contents)this.addDefaultTrackOptions(l);if(this.state.addTrackPosition&&this.setState({addTrackPosition:null}),o)return this.handleSeriesAdded(n,C,r,o),null;C.position=r;const A=this.getTrackInfo(C.type);C.width=A.defaultWidth||A.defaultOptions&&A.defaultOptions.minWidth||this.minVerticalWidth,C.height=A.defaultHeight||A.defaultOptions&&A.defaultOptions.minHeight||this.minHorizontalHeight;const{tracks:s}=this.state.views[n];let a=0;if(os(s,()=>a++),r==="left"||r==="top")s[r].unshift(C);else if(r==="center")if(s.center.length===0){const l={uid:dg.nice(),type:"combined",contents:[C]};s.center=[l]}else if(s.center[0].type==="combined")s.center[0].contents.push(C),C.type==="heatmap"&&this.compatibilityfyStackedHeatmaps(C,s.center[0]);else{const l={uid:dg.nice(),type:"combined",contents:[s.center[0],C]};s.center=[l],C.type==="heatmap"&&this.compatibilityfyStackedHeatmaps(C,l)}else s[r]||(s[r]=[]),s[r].push(C);return this.adjustLayoutToTrackSizes(this.state.views[n]),Object.keys(this.state.views).length===1&&a===0&&(this.handleZoomToData(n),this.zoomToDataExtentOnInit.add(n)),C}},{key:"compatibilityfyStackedHeatmaps",value:function(n,C){let r;C.contents.some(A=>(r=A,A.type==="heatmap"))&&(n.options.backgroundColor="transparent",n.options.showTooltip=r.options.showTooltip,n.options.showMousePosition=r.options.showMousePosition,n.options.mousePositionColor=r.options.mousePositionColor)}},{key:"storeTrackSizes",value:function(n){os(this.state.views[n].tracks,C=>{const r=this.tiledPlots[n].trackRenderer.getTrackObject(C.uid);r&&([C.width,C.height]=r.dimensions)})}},{key:"adjustLayoutToTrackSizes",value:function(n){if(!n.layout)return;const C=this.isEditable();let r=0;C&&(r+=H6t);const{totalHeight:o}=this.calculateViewDimensions(n);r+=o;const A=this.isEditable()?10:0;r+=A;const s=this.state.rowHeight+A;this.sizeMode!==Fse&&(n.layout.h=Math.ceil(r/s))}},{key:"handleCloseTrack",value:function(n,C){const{tracks:r}=this.state.views[n];this.handleUnlockValueScale(n,C);for(const o in r){const A=r[o],s=A.filter(a=>a.uid!==C);s.length===A.length?s.filter(l=>l.type==="combined").forEach(l=>{l.contents=l.contents.filter(c=>c.uid!==C)}):r[o]=s}return this.storeTrackSizes(n),this.adjustLayoutToTrackSizes(this.state.views[n]),this.setState(o=>({views:o.views})),this.state.views}},{key:"handleLockValueScale",value:function(n,C){this.setState({chooseTrackHandler:(r,o)=>this.handleValueScaleLocked(n,C,r,o)})}},{key:"combineViewAndTrackUid",value:function(n,C){const r=`${n}.${C}`;if(this.combinedUidToViewTrack[r]={view:n,track:C},this.viewTrackUidsToCombinedUid[n]){if(this.viewTrackUidsToCombinedUid[C])return this.viewTrackUidsToCombinedUid[n][C];this.viewTrackUidsToCombinedUid[n][C]=r}else this.viewTrackUidsToCombinedUid[n]={},this.viewTrackUidsToCombinedUid[n][C]=r;return r}},{key:"updateTrackLocks",value:function(n,C,r){const o=this.combineViewAndTrackUid(n,C),A=this.combineViewAndTrackUid(n,r);if(this.valueScaleLocks[o]){const s=this.valueScaleLocks[o];this.valueScaleLocks[A]=s,delete this.valueScaleLocks[o]}for(const s in this.valueScaleLocks)if(this.valueScaleLocks[s][o]){const a=this.valueScaleLocks[s][o];this.valueScaleLocks[s][A]=a,a.track=r,delete this.valueScaleLocks[s][o]}}},{key:"handleUnlockValueScale",value:function(n,C){if(this.tiledPlots[n].trackRenderer.getTrackObject(C).createdTracks){const r=Nr(this.tiledPlots[n].trackRenderer.getTrackObject(C).createdTracks);for(const o of r)this.handleUnlock(this.combineViewAndTrackUid(n,o),this.valueScaleLocks)}else this.handleUnlock(this.combineViewAndTrackUid(n,C),this.valueScaleLocks)}},{key:"handleValueScaleLocked",value:function(n,C,r,o){if(this.tiledPlots[n].trackRenderer.getTrackObject(C).createdTracks){const a=Nr(this.tiledPlots[n].trackRenderer.getTrackObject(C).createdTracks);for(const l of a)this.handleValueScaleLocked(n,l,r,o);return}if(this.tiledPlots[r].trackRenderer.getTrackObject(o).createdTracks){const a=Nr(this.tiledPlots[r].trackRenderer.getTrackObject(o).createdTracks);for(const l of a)this.handleValueScaleLocked(n,C,r,l);return}const A=this.combineViewAndTrackUid(n,C),s=this.combineViewAndTrackUid(r,o);this.addLock(A,s,this.valueScaleLocks,a=>this.combinedUidToViewTrack[a]),this.syncValueScales(n,C),this.setState({chooseTrackHandler:null})}},{key:"addCallbacks",value:function(n,C){const r=this.getTrackInfo(C.type);if(C.type==="viewport-projection-center"||C.type==="viewport-projection-horizontal"||C.type==="viewport-projection-vertical"||r&&r.projection){const o=C.fromViewUid;C.registerViewportChanged=(A,s)=>this.addScalesChangedListener(o,A,s),C.removeViewportChanged=A=>this.removeScalesChangedListener(o,A),C.setDomainsCallback=(A,s)=>{if(!o){this.projectionXDomains[n]||(this.projectionXDomains[n]={}),this.projectionYDomains[n]||(this.projectionYDomains[n]={}),(C.type==="viewport-projection-horizontal"||C.type==="viewport-projection-center")&&(this.projectionXDomains[n][C.uid]=A),(C.type==="viewport-projection-vertical"||C.type==="viewport-projection-center")&&(this.projectionYDomains[n][C.uid]=s),this.triggerViewChangeDb();return}const a=Cg().domain(A).range(this.xScales[o].range()),l=Cg().domain(s).range(this.yScales[o].range()),[c,u,d]=Zi(a,l);this.setCenters[o](c,u,d,!1);let h=!1,m=!1;n in this.zoomLocks&&(h=o in this.zoomLocks[n]),h&&this.handleUnlock(n,this.zoomLocks),n in this.locationLocks&&(m=o in this.locationLocks[n]),m&&this.handleUnlock(n,this.locationLocks),this.handleScalesChanged(o,a,l,!0),h&&this.addLock(n,o,this.zoomLocks,this.viewScalesLockData),m&&this.addLock(n,o,this.locationLocks,this.viewScalesLockData)}}}},{key:"validateLocks",value:function(n){const C=[];for(const r of Nr(n))(!n[r]||!n[r][r])&&C.push(r);for(const r of C)n[r]&&(console.warn(`View ${r} not present in lock group. Removing...`),this.handleUnlock(r,n),delete n[r])}},{key:"deserializeLocationLocks",value:function(n){if(this.locationLocks={},n.locationLocks)for(const C of Nr(n.locationLocks.locksByViewUid))if(typeof n.locationLocks.locksByViewUid[C]!="object")this.locationLocks[C]=n.locationLocks.locksDict[n.locationLocks.locksByViewUid[C]];else{if("x"in n.locationLocks.locksByViewUid[C]){const r=n.locationLocks.locksDict[n.locationLocks.locksByViewUid[C].x.lock];this.locationLocksAxisWise.x[C]={lock:r,axis:n.locationLocks.locksByViewUid[C].x.axis}}if("y"in n.locationLocks.locksByViewUid[C]){const r=n.locationLocks.locksDict[n.locationLocks.locksByViewUid[C].y.lock];this.locationLocksAxisWise.y[C]={lock:r,axis:n.locationLocks.locksByViewUid[C].y.axis}}}this.validateLocks(this.locationLocks)}},{key:"deserializeZoomLocks",value:function(n){if(this.zoomLocks={},n.zoomLocks)for(const C of Nr(n.zoomLocks.locksByViewUid))this.zoomLocks[C]=n.zoomLocks.locksDict[n.zoomLocks.locksByViewUid[C]];this.validateLocks(this.zoomLocks)}},{key:"deserializeValueScaleLocks",value:function(n){if(this.valueScaleLocks={},n.valueScaleLocks)for(const C of Nr(n.valueScaleLocks.locksByViewUid))this.valueScaleLocks[C]=n.valueScaleLocks.locksDict[n.valueScaleLocks.locksByViewUid[C]]}},{key:"serializeLocks",value:function(n){const C={},r={};for(const o of Nr(n)){let A=n[o]&&n[o].uid;A||(A=dg.nice()),n[o].uid=A,C[A]=n[o],r[o]=n[o].uid}return{locksByViewUid:r,locksDict:C}}},{key:"getViewsAsJson",value:function(){const n=JSON.parse(JSON.stringify(this.state.viewConfig));return n.views=Object.values(this.state.views).map(C=>{const r=JSON.parse(JSON.stringify(C));return os(r.tracks,o=>{if(o.server){const A=eCt(o.server,{});if(!A.hostname.length){const s=window.location.host,{protocol:a}=window.location,l=`${a}//${s}${A.pathname}`;o.server=l}}(o.type==="viewport-projection-center"||o.type==="viewport-projection-horizontal")&&this.projectionXDomains[C.uid]&&this.projectionXDomains[C.uid][o.uid]&&(o.projectionXDomain=this.projectionXDomains[C.uid][o.uid]),(o.type==="viewport-projection-center"||o.type==="viewport-projection-vertical")&&this.projectionYDomains[C.uid]&&this.projectionYDomains[C.uid][o.uid]&&(o.projectionYDomain=this.projectionYDomains[C.uid][o.uid]),delete o.name,delete o.position,delete o.header,delete o.description,delete o.created,delete o.project,delete o.project_name,delete o.serverUidKey,delete o.uuid,delete o.private,delete o.maxZoom,delete o.coordSystem,delete o.coordSystem2,delete o.datatype,delete o.maxWidth,delete o.datafile,delete o.binsPerDimension,delete o.resolutions,delete o.aggregationModes}),r.uid=C.uid,r.initialXDomain=this.xScales[C.uid].domain(),r.initialYDomain=this.yScales[C.uid].domain(),delete r.layout.i,r}),n.zoomLocks=this.serializeLocks(this.zoomLocks),n.locationLocks=this.serializeLocks(this.locationLocks),n.valueScaleLocks=this.serializeLocks(this.valueScaleLocks),n}},{key:"getViewsAsString",value:function(){return JSON.stringify(this.getViewsAsJson(),null,2)}},{key:"handleExportViewAsJSON",value:function(){const n=this.getViewsAsString();tB("viewconf.json",n)}},{key:"handleExportViewsAsLink",value:function(n=this.state.viewConfig.exportViewUrl,C=!1){const r=new URL(n,window.location.origin),o=fetch(n,{method:"POST",headers:{Accept:"application/json, text/plain, */*","Content-Type":"application/json","X-Requested-With":"XMLHttpRequest"},body:`{"viewconf":${this.getViewsAsString()}}`,credentials:"same-origin"}).then(A=>{if(!A.ok)throw A;return A.json()}).catch(A=>{console.warn("err:",A)}).then(A=>({id:A.uid,url:`${r.origin}/l/?d=${A.uid}`}));return C||o.then(A=>{this.openModal(N.createElement(c$,{onDone:()=>{this.closeModalBound()},url:A.url}))}).catch(A=>console.error("Exporting view config as link failed:",A)),o}},{key:"handleDataDomainChanged",value:function(n,C,r){const{views:o}=this.state;if(o[n].initialXDomain=C,o[n].initialYDomain=r,this.xScales[n]=Cg().domain(C),this.yScales[n]=Cg().domain(r),this.zoomLocks[n]){const A=this.zoomLocks[n],s=xr(A);for(let a=0;aDse)return!1;const a=Pg(this.state.views);for(let l=0;lc&&Cu)return!1}return!0}},{key:"handleAddView",value:function(n){const C=Pg(this.state.views),r=n,o=[];n.layout.w===12&&(n.layout.w=6);for(let a=0;a{const c=a[1]-l[1];return c===0?a[0]-l[0]:c});const A=JSON.stringify(r),s=JSON.parse(A);s.initialXDomain=this.xScales[s.uid].domain(),s.initialYDomain=this.yScales[s.uid].domain(),[[s.layout.x,s.layout.y]]=o,s.uid=dg.nice(),s.layout.i=s.uid,os(s.tracks,a=>{this.addCallbacks(s.uid,a)}),this.setState(a=>{const l=JSON.parse(JSON.stringify(a.views));return l[s.uid]=s,{views:l}})}},{key:"handleSelectedAssemblyChanged",value:function(n,C,r,o){const{views:A}=this.state;A[n].genomePositionSearchBox.chromInfoId=C,A[n].genomePositionSearchBox.autocompleteId=r,A[n].genomePositionSearchBox.autocompleteServer=o}},{key:"createGenomePostionSearchBoxEntry",value:function(n,C){let r=n;const o={autocompleteServer:tz,chromInfoServer:tz,visible:!1};return r||(r=JSON.parse(JSON.stringify(o))),r.autocompleteServer||(r.autocompleteServer=o.autocompleteServer),r.chromInfoId||(r.chromInfoId=C),r.chromInfoServer||(r.chromInfoServer=o.chromInfoServer),r.visible||(r.visible=!1),r}},{key:"handleTogglePositionSearchBox",value:function(n){const C=this.state.views[n];C.genomePositionSearchBoxVisible=!C.genomePositionSearchBoxVisible;const r={};os(C.tracks,s=>{s.coordSystem&&(r[s.coordSystem]||(r[s.coordSystem]=0),r[s.coordSystem]+=1)});const o=xr(r).sort((s,a)=>a[1]-s[1]);let A="hg19";o.length&&(A=o[0][0]),C.genomePositionSearchBox=this.createGenomePostionSearchBoxEntry(C.genomePositionSearchBox,A),C.genomePositionSearchBox.visible=!C.genomePositionSearchBox.visible,this.refreshView(),this.setState({configMenuUid:null})}},{key:"handleTrackOptionsChanged",value:function(n,C,r){const o=this.state.views[n],A=gr(o.tracks,C);A&&(A.options=Object.assign(A.options,r),this.mounted&&(this.setState(s=>({views:s.views})),this.adjustSplitHeatmapTrackOptions(A,r,o.tracks,n)))}},{key:"adjustSplitHeatmapTrackOptions",value:function(n,C,r,o){n.type==="heatmap"&&(C.extent==="upper-right"&&r.center[0].type==="combined"&&r.center[0].contents.length>1&&r.center[0].contents.some(A=>{if(A.type==="heatmap"&&A.uid!==n.uid&&A.options.extent!=="lower-left"){const s={...A.options,extent:"lower-left",labelPosition:"bottomLeft",colorbarPosition:"bottomLeft"},a={...C,labelPosition:"topRight",colorbarPosition:"topRight"};return this.handleTrackOptionsChanged(o,A.uid,s),this.handleTrackOptionsChanged(o,n.uid,a),!0}return!1}),C.extent==="lower-left"&&C.extent==="lower-left"&&r.center[0].type==="combined"&&r.center[0].contents.length>1&&r.center[0].contents.some(A=>{if(A.type==="heatmap"&&A.uid!==n.uid&&A.options.extent!=="upper-right"){const s={...A.options,extent:"upper-right",labelPosition:"topRight",colorbarPosition:"topRight"},a={...C,labelPosition:"bottomLeft",colorbarPosition:"bottomLeft"};return this.handleTrackOptionsChanged(o,A.uid,s),this.handleTrackOptionsChanged(o,n.uid,a),!0}return!1}))}},{key:"handleViewOptionsChanged",value:function(n,C){const r=this.state.views[n];r&&(r.options=Object.assign(r.options||{},C),this.mounted&&this.setState(o=>({views:o.views})))}},{key:"isTrackValid",value:function(n,C){return!(n.type==="viewport-projection-center"&&!C.has(n.fromViewUid))}},{key:"removeInvalidTracks",value:function(n){const C=new Set(Nr(n));for(const r of Pg(n))for(const o of["left","top","center","right","bottom"])r.tracks&&r.tracks.hasOwnProperty(o)&&(r.tracks[o]=r.tracks[o].filter(A=>this.isTrackValid(A,C)),r.tracks[o].forEach(A=>{A.type==="combined"&&(A.contents=A.contents.filter(s=>this.isTrackValid(s,C)))}));return n}},{key:"processViewConfig",value:function(n){let{views:C}=n,r={};return(!n.views||n.views.length===0)&&(console.warn("No views provided in viewConfig"),C=[{editable:!0,tracks:{}}]),C.forEach(o=>{o.tracks&&xGe(o.tracks),o.uid||(o.uid=dg.nice()),r[o.uid]=o,this.zoomToDataExtentOnInit.has(o.uid)&&this.zoomToDataExtentOnInit.delete(o.uid),o.initialXDomain?(o.initialXDomain[0]=+o.initialXDomain[0],o.initialXDomain[1]=+o.initialXDomain[1]):(o.initialXDomain=[0,100],this.zoomToDataExtentOnInit.add(o.uid)),o.initialYDomain?(o.initialXDomain[0]=+o.initialXDomain[0],o.initialXDomain[1]=+o.initialXDomain[1]):o.initialYDomain=[o.initialXDomain[0],o.initialXDomain[1]],this.xScales[o.uid]||(this.xScales[o.uid]=Cg().domain(o.initialXDomain)),this.yScales[o.uid]||(this.yScales[o.uid]=Cg().domain(o.initialYDomain)),os(o.tracks,A=>{if(A.uid||(A.uid=dg.nice()),this.addCallbacks(o.uid,A),this.addDefaultTrackOptions(A),A.contents)for(const s of A.contents)this.addDefaultTrackOptions(s)}),o.layout?o.layout.i=o.uid:o.layout=this.generateViewLayout(o)}),this.deserializeZoomLocks(n),this.deserializeLocationLocks(n),this.deserializeValueScaleLocks(n),r=this.removeInvalidTracks(r),r}},{key:"handleWindowFocused",value:function(){}},{key:"rangeSelectionHandler",value:function(n){this.rangeSelection=n,this.apiPublish("rangeSelection",n)}},{key:"offViewChange",value:function(n){this.viewChangeListener.splice(n,1)}},{key:"onViewChange",value:function(n){return this.viewChangeListener.push(n)-1}},{key:"triggerViewChange",value:function(){this.viewChangeListener.forEach(n=>n(this.getViewsAsString()))}},{key:"getGenomeLocation",value:function(n){return BQ.get(this.state.views[n].chromInfoPath).then(C=>nBe(this.xScales[n],this.yScales[n],C))}},{key:"offLocationChange",value:function(n,C){this.removeScalesChangedListener(n,C)}},{key:"zoomTo",value:function(n,C,r,o,A,s){if(!(n in this.setCenters))throw Error(`Invalid viewUid. Current uuids: ${Object.keys(this.setCenters).join(",")}`);if(Number.isNaN(+C)||Number.isNaN(+r)){const u=[C,r].join(", ");console.warn([`Invalid coordinates (${u}). All coordinates need to be numbers +${C}`}},{key:"handleExportSVG",value:function(){RG("export.svg",new Blob([this.createSVGString()],{type:"image/svg+xml"}))}},{key:"offPostCreateSVG",value:function(){this.postCreateSVGCallback=null}},{key:"onPostCreateSVG",value:function(n){this.postCreateSVGCallback=n}},{key:"createPNGBlobPromise",value:function(){return new Promise(n=>{const C=this.createSVGString(),r=new Image(this.canvasElement.width,this.canvasElement.height);r.src=`data:image/svg+xml;base64,${btoa(C)}`,r.onload=()=>{const o=document.createElement("canvas");o.width=this.canvasElement.width/2,o.height=this.canvasElement.height/2,o.getContext("2d").drawImage(r,0,0),o.toBlob(A=>{n(A)})}})}},{key:"handleExportPNG",value:function(){this.createPNGBlobPromise().then(n=>{RG("export.png",n)})}},{key:"handleScalesChanged",value:function(n,C,r,o=!0){if(this.xScales[n]=C,this.yScales[n]=r,o&&n in this.scalesChangedListeners&&xg(this.scalesChangedListeners[n]).forEach(A=>{A(C,r)}),this.zoomLocks[n]){const A=this.zoomLocks[n],s=Rr(A),[a,l,c]=yi(this.xScales[n],this.yScales[n]);for(let u=0;u{G(Z,B)})}}if(this.locationLocks[n]){const A=this.locationLocks[n],s=Rr(A),[a,l,c]=yi(this.xScales[n],this.yScales[n]);for(let u=0;u{w(G,v)})}}if(this.locationLocksAxisWise.x[n]){const A=this.locationLocksAxisWise.x[n].lock,s=Rr(A),a=this.locationLocksAxisWise.x[n].axis!=="x",[l,c,u]=yi(this.xScales[n],this.yScales[n]);for(let d=0;d{v(B,G)})}}if(this.locationLocksAxisWise.y[n]){const A=this.locationLocksAxisWise.y[n].lock,s=Rr(A),a=this.locationLocksAxisWise.y[n].axis!=="y",[l,c,u]=yi(this.xScales[n],this.yScales[n]);for(let d=0;d{v(B,G)})}}this.animate(),this.triggerViewChangeDb()}},{key:"handleProjectViewport",value:function(n){this.setState({chooseTrackHandler:(C,r)=>this.handleViewportProjected(n,C,r)})}},{key:"handleZoomToData",value:function(n){if(n&&!this.tiledPlots[n])throw new Error(`View uid ${n} does not exist in the current viewConfig`);n?this.tiledPlots[n].handleZoomToData():Object.values(this.tiledPlots).forEach(C=>C.handleZoomToData())}},{key:"resetViewport",value:function(n){if(n&&!this.tiledPlots[n])throw new Error(`View uid ${n} does not exist in the current viewConfig`);n?this.tiledPlots[n].resetViewport():Object.values(this.tiledPlots).forEach(C=>C.resetViewport())}},{key:"handleYankFunction",value:function(n,C){this.setState({chooseViewHandler:r=>C(n,r),mouseOverOverlayUid:n})}},{key:"handleUnlock",value:function(n,C){const r=C[n],o=Br(r);if(o.length===2){delete C[o[0]],delete C[o[1]];return}C[n]&&C[n][n]&&delete C[n][n],C[n]&&delete C[n]}},{key:"viewScalesLockData",value:function(n){return!this.xScales[n]||!this.yScales[n]?(console.warn("View scale lock doesn't correspond to existing uid: ",n),null):yi(this.xScales[n],this.yScales[n])}},{key:"addLock",value:function(n,C,r,o){let A=[],s=[];r[n]?A=Rr(r[n]).filter(c=>o(c[0])).map(c=>[c[0],o(c[0])]):A=[[n,o.bind(this)(n)]],r[C]?s=Rr(r[C]).filter(c=>o.bind(this)(c[0])).map(c=>[c[0],o.bind(this)(c[0])]):s=[[C,o.bind(this)(C)]];const a=A.concat(s),l=wZe(a);a.forEach(c=>{r[c[0]]=l})}},{key:"handleLocationLockChosen",value:function(n,C){if(n===C){this.setState({chooseViewHandler:null});return}this.addLock(n,C,this.locationLocks,this.viewScalesLockData.bind(this)),this.setState({chooseViewHandler:null})}},{key:"handleZoomLockChosen",value:function(n,C){if(n===C){this.setState({chooseViewHandler:null});return}this.addLock(n,C,this.zoomLocks,this.viewScalesLockData.bind(this)),this.setState({chooseViewHandler:null})}},{key:"handleViewportProjected",value:function(n,C,r){let o=null;if(n===C)console.warn("A view can not show its own viewport.");else{const A=jC(this.state.views[C].tracks,r),s=WG(this.state.views[C].tracks,r);o=Ag.nice();const l={uid:o,type:`viewport-projection-${{top:"horizontal",bottom:"horizontal",center:"center",left:"vertical",right:"vertical"}[s]}`,fromViewUid:n};this.addCallbacks(C,l),this.handleTrackAdded(C,l,s,A)}return this.setState({chooseTrackHandler:null}),o}},{key:"handleLocationYanked",value:function(n,C){const r=this.xScales[C],o=this.yScales[C],A=this.xScales[n],s=this.yScales[n],[a,l,c]=yi(A,s),[u,d,h]=yi(r,o);this.setCenters[n](u,d,c,!0),this.setState({chooseViewHandler:null})}},{key:"handleZoomYanked",value:function(n,C){const r=this.xScales[C],o=this.yScales[C],A=this.xScales[n],s=this.yScales[n],[a,l,c]=yi(A,s),[u,d,h]=yi(r,o);this.setCenters[n](a,l,h,!0),this.setState({chooseViewHandler:null})}},{key:"handleTrackPositionChosen",value:function(n,C){this.setState({addTrackPosition:C,addTrackPositionView:n})}},{key:"updateRowHeight",value:function(){if(!this.props.options||this.sizeMode!==tse||this.props.options.pixelPreciseMarginPadding)return;const n=this.element.parentNode.clientHeight;let C=0;for(const l of xg(this.state.views))C=Math.max(C,l.layout.y+l.layout.h);this.handleDragStart(),this.handleDragStop();const o=(this.isEditable()?10:0)*C-1,s=(n-o)/C,a=Math.floor(s);this.setState({rowHeight:a})}},{key:"handleLayoutChange",value:function(n){this.element&&(n.forEach(C=>{const r=this.state.views[C.i];r&&(r.layout.x=C.x,r.layout.y=C.y,r.layout.w=C.w,r.layout.h=C.h,r.layout.i=C.i)}),this.updateRowHeight(),this.refreshView(VZ))}},{key:"clearDragTimeout",value:function(){this.dragTimeout&&(clearTimeout(this.dragTimeout),this.dragTimeout=null)}},{key:"getTrackInfo",value:function(n){if(Lg[n])return Lg[n];if(this.pluginTracks&&this.pluginTracks[n])return this.pluginTracks[n].config;if(window.higlassTracksByType&&window.higlassTracksByType[n])return window.higlassTracksByType[n].config;console.warn("Track type not found:",n,"(check app/scripts/config/ for a list of defined track types)")}},{key:"forceRefreshView",value:function(){this.setState(this.state)}},{key:"refreshView",value:function(n=hZe){this.clearDragTimeout(),this.notifyDragChangedListeners(!0),this.clearDragTimeout(),this.dragTimeout=setTimeout(()=>{this.notifyDragChangedListeners(!1)},n)}},{key:"handleDragStart",value:function(){this.clearDragTimeout(),this.notifyDragChangedListeners(!0)}},{key:"handleDragStop",value:function(){this.clearDragTimeout(),this.dragTimeout=setTimeout(()=>{this.notifyDragChangedListeners(!1)},VZ)}},{key:"resizeHandler",value:function(){nN(this.viewHeaders).filter(n=>n).forEach(n=>n.checkWidth())}},{key:"calculateViewDimensions",value:function(n){let s=this.viewMarginTop+this.viewMarginBottom+this.viewPaddingTop+this.viewPaddingBottom,a=this.viewMarginLeft+this.viewMarginRight+this.viewPaddingLeft+this.viewPaddingRight,l=0;l+=10;const c=20;if(n.tracks.top)for(let B=0;B0||n.tracks.right&&n.tracks.right.length>0||n.tracks.center&&n.tracks.center.length>0)&&(l+=c);let u=0;if(n.tracks.left)for(let B=0;B0){if(!n.tracks.center[0].contents||n.tracks.center[0].contents.length>0){let B=null,G=null;if(n.tracks.center[0].contents)for(const v of n.tracks.center[0].contents)B=Math.max(B,v.height?v.height:100),G=Math.max(G,v.width?v.width:100);else B=n.tracks.center[0].height?n.tracks.center[0].height:100,G=n.tracks.center[0].width?n.tracks.center[0].width:100;s+=B,a+=G}}else(n.tracks.top&&xg(n.tracks.top).length>1||n.tracks.bottom&&xg(n.tracks.bottom).length>1)&&(n.tracks.left&&xg(n.tracks.left).length||n.tracks.right&&xg(n.tracks.right).length)&&(f=100,m=100);h>m?s+=h:s+=m;let b=0,p=0,y=0,Z=0;return"top"in n.tracks&&(b=n.tracks.top.map(B=>B.height?B.height:20).reduce((B,G)=>B+G,0)),"bottom"in n.tracks&&(p=n.tracks.bottom.map(B=>B.height?B.height:20).reduce((B,G)=>B+G,0)),"left"in n.tracks&&(y=n.tracks.left.map(B=>B.width?B.width:0).reduce((B,G)=>B+G,0)),"right"in n.tracks&&(Z=n.tracks.right.map(B=>B.width?B.width:0).reduce((B,G)=>B+G,0)),{totalWidth:a,totalHeight:s,topHeight:b,bottomHeight:p,leftWidth:y,rightWidth:Z,centerWidth:f,centerHeight:m,minNecessaryHeight:l}}},{key:"calculateZoomLimits",value:function(n,C){const r=[0,1/0],o=n.zoomLimits||[1,null],A=C[1]-C[0];if(o.length!==2)return r;if(o[0]!==null&&o[0]>0){const s=A/o[0];r[1]=Math.max(s,1),s<1&&console.warn(`Invalid zoom limits. Lower limit set to ${A}`)}if(o[1]!==null&&o[1]>o[0]){const s=A/o[1];r[0]=Math.min(s,1),s>1&&console.warn(`Invalid zoom limits. Upper limit set to ${A}`)}return r}},{key:"generateViewLayout",value:function(n){let C=null;return"layout"in n?{layout:C}=n.layout:C={x:0,y:0,w:ese,h:Aeg},C}},{key:"handleClearView",value:function(n){const{views:C}=this.state;C[n].tracks.top=[],C[n].tracks.bottom=[],C[n].tracks.center=[],C[n].tracks.left=[],C[n].tracks.right=[],C[n].tracks.whole=[],this.setState({views:C})}},{key:"handleCloseView",value:function(n){xg(this.state.views).length!==1&&(this.handleUnlock(n,this.zoomLocks),this.setState(C=>(delete C.views[n],{views:this.removeInvalidTracks(C.views)})))}},{key:"handleSeriesAdded",value:function(n,C,r,o){const{tracks:A}=this.state.views[n];if(o.type==="combined")o.contents.push(C),C.type==="heatmap"&&this.compatibilityfyStackedHeatmaps(C,o);else{const s={type:"combined",uid:Ag.nice(),height:o.height,width:o.width,contents:[o,C]},a=A[r];for(let l=0;l({views:s.views}))}},{key:"handleNoTrackAdded",value:function(){this.state.addTrackPosition&&this.setState({addTrackPosition:null})}},{key:"handleTracksAdded",value:function(n,C,r,o){this.storeTrackSizes(n);for(const A of C)this.handleTrackAdded(n,A,r,o)}},{key:"handleChangeTrackType",value:function(n,C,r){const o=this.state.views[n],A=jC(o.tracks,C),s=A.uid;A.uid=Ag.nice(),A.type=r;const a=A.uid;this.updateTrackLocks(n,s,a),this.setState(l=>({views:l.views}))}},{key:"handleChangeTrackData",value:function(n,C,r){const o=this.state.views[n],A=jC(o.tracks,C);A.uid=Ag.nice(),A.data=r,this.setState(s=>({views:s.views}))}},{key:"handleTrackAdded",value:function(n,C,r,o=null){if(this.addDefaultTrackOptions(C),C.uid||(C.uid=Ag.nice()),C.contents)for(const l of C.contents)this.addDefaultTrackOptions(l);if(this.state.addTrackPosition&&this.setState({addTrackPosition:null}),o)return this.handleSeriesAdded(n,C,r,o),null;C.position=r;const A=this.getTrackInfo(C.type);C.width=A.defaultWidth||A.defaultOptions&&A.defaultOptions.minWidth||this.minVerticalWidth,C.height=A.defaultHeight||A.defaultOptions&&A.defaultOptions.minHeight||this.minHorizontalHeight;const{tracks:s}=this.state.views[n];let a=0;if(Qa(s,()=>a++),r==="left"||r==="top")s[r].unshift(C);else if(r==="center")if(s.center.length===0){const l={uid:Ag.nice(),type:"combined",contents:[C]};s.center=[l]}else if(s.center[0].type==="combined")s.center[0].contents.push(C),C.type==="heatmap"&&this.compatibilityfyStackedHeatmaps(C,s.center[0]);else{const l={uid:Ag.nice(),type:"combined",contents:[s.center[0],C]};s.center=[l],C.type==="heatmap"&&this.compatibilityfyStackedHeatmaps(C,l)}else s[r]||(s[r]=[]),s[r].push(C);return this.adjustLayoutToTrackSizes(this.state.views[n]),Object.keys(this.state.views).length===1&&a===0&&(this.handleZoomToData(n),this.zoomToDataExtentOnInit.add(n)),C}},{key:"compatibilityfyStackedHeatmaps",value:function(n,C){let r;C.contents.some(A=>(r=A,A.type==="heatmap"))&&(n.options.backgroundColor="transparent",n.options.showTooltip=r.options.showTooltip,n.options.showMousePosition=r.options.showMousePosition,n.options.mousePositionColor=r.options.mousePositionColor)}},{key:"storeTrackSizes",value:function(n){Qa(this.state.views[n].tracks,C=>{const r=this.tiledPlots[n].trackRenderer.getTrackObject(C.uid);r&&([C.width,C.height]=r.dimensions)})}},{key:"adjustLayoutToTrackSizes",value:function(n){if(!n.layout)return;const C=this.isEditable();let r=0;C&&(r+=aeg);const{totalHeight:o}=this.calculateViewDimensions(n);r+=o;const A=this.isEditable()?10:0;r+=A;const s=this.state.rowHeight+A;this.sizeMode!==tse&&(n.layout.h=Math.ceil(r/s))}},{key:"handleCloseTrack",value:function(n,C){const{tracks:r}=this.state.views[n];this.handleUnlockValueScale(n,C);for(const o in r){const A=r[o],s=A.filter(a=>a.uid!==C);s.length===A.length?s.filter(l=>l.type==="combined").forEach(l=>{l.contents=l.contents.filter(c=>c.uid!==C)}):r[o]=s}return this.storeTrackSizes(n),this.adjustLayoutToTrackSizes(this.state.views[n]),this.setState(o=>({views:o.views})),this.state.views}},{key:"handleLockValueScale",value:function(n,C){this.setState({chooseTrackHandler:(r,o)=>this.handleValueScaleLocked(n,C,r,o)})}},{key:"combineViewAndTrackUid",value:function(n,C){const r=`${n}.${C}`;if(this.combinedUidToViewTrack[r]={view:n,track:C},this.viewTrackUidsToCombinedUid[n]){if(this.viewTrackUidsToCombinedUid[C])return this.viewTrackUidsToCombinedUid[n][C];this.viewTrackUidsToCombinedUid[n][C]=r}else this.viewTrackUidsToCombinedUid[n]={},this.viewTrackUidsToCombinedUid[n][C]=r;return r}},{key:"updateTrackLocks",value:function(n,C,r){const o=this.combineViewAndTrackUid(n,C),A=this.combineViewAndTrackUid(n,r);if(this.valueScaleLocks[o]){const s=this.valueScaleLocks[o];this.valueScaleLocks[A]=s,delete this.valueScaleLocks[o]}for(const s in this.valueScaleLocks)if(this.valueScaleLocks[s][o]){const a=this.valueScaleLocks[s][o];this.valueScaleLocks[s][A]=a,a.track=r,delete this.valueScaleLocks[s][o]}}},{key:"handleUnlockValueScale",value:function(n,C){if(this.tiledPlots[n].trackRenderer.getTrackObject(C).createdTracks){const r=Br(this.tiledPlots[n].trackRenderer.getTrackObject(C).createdTracks);for(const o of r)this.handleUnlock(this.combineViewAndTrackUid(n,o),this.valueScaleLocks)}else this.handleUnlock(this.combineViewAndTrackUid(n,C),this.valueScaleLocks)}},{key:"handleValueScaleLocked",value:function(n,C,r,o){if(this.tiledPlots[n].trackRenderer.getTrackObject(C).createdTracks){const a=Br(this.tiledPlots[n].trackRenderer.getTrackObject(C).createdTracks);for(const l of a)this.handleValueScaleLocked(n,l,r,o);return}if(this.tiledPlots[r].trackRenderer.getTrackObject(o).createdTracks){const a=Br(this.tiledPlots[r].trackRenderer.getTrackObject(o).createdTracks);for(const l of a)this.handleValueScaleLocked(n,C,r,l);return}const A=this.combineViewAndTrackUid(n,C),s=this.combineViewAndTrackUid(r,o);this.addLock(A,s,this.valueScaleLocks,a=>this.combinedUidToViewTrack[a]),this.syncValueScales(n,C),this.setState({chooseTrackHandler:null})}},{key:"addCallbacks",value:function(n,C){const r=this.getTrackInfo(C.type);if(C.type==="viewport-projection-center"||C.type==="viewport-projection-horizontal"||C.type==="viewport-projection-vertical"||r&&r.projection){const o=C.fromViewUid;C.registerViewportChanged=(A,s)=>this.addScalesChangedListener(o,A,s),C.removeViewportChanged=A=>this.removeScalesChangedListener(o,A),C.setDomainsCallback=(A,s)=>{if(!o){this.projectionXDomains[n]||(this.projectionXDomains[n]={}),this.projectionYDomains[n]||(this.projectionYDomains[n]={}),(C.type==="viewport-projection-horizontal"||C.type==="viewport-projection-center")&&(this.projectionXDomains[n][C.uid]=A),(C.type==="viewport-projection-vertical"||C.type==="viewport-projection-center")&&(this.projectionYDomains[n][C.uid]=s),this.triggerViewChangeDb();return}const a=qt().domain(A).range(this.xScales[o].range()),l=qt().domain(s).range(this.yScales[o].range()),[c,u,d]=yi(a,l);this.setCenters[o](c,u,d,!1);let h=!1,m=!1;n in this.zoomLocks&&(h=o in this.zoomLocks[n]),h&&this.handleUnlock(n,this.zoomLocks),n in this.locationLocks&&(m=o in this.locationLocks[n]),m&&this.handleUnlock(n,this.locationLocks),this.handleScalesChanged(o,a,l,!0),h&&this.addLock(n,o,this.zoomLocks,this.viewScalesLockData),m&&this.addLock(n,o,this.locationLocks,this.viewScalesLockData)}}}},{key:"validateLocks",value:function(n){const C=[];for(const r of Br(n))(!n[r]||!n[r][r])&&C.push(r);for(const r of C)n[r]&&(console.warn(`View ${r} not present in lock group. Removing...`),this.handleUnlock(r,n),delete n[r])}},{key:"deserializeLocationLocks",value:function(n){if(this.locationLocks={},n.locationLocks)for(const C of Br(n.locationLocks.locksByViewUid))if(typeof n.locationLocks.locksByViewUid[C]!="object")this.locationLocks[C]=n.locationLocks.locksDict[n.locationLocks.locksByViewUid[C]];else{if("x"in n.locationLocks.locksByViewUid[C]){const r=n.locationLocks.locksDict[n.locationLocks.locksByViewUid[C].x.lock];this.locationLocksAxisWise.x[C]={lock:r,axis:n.locationLocks.locksByViewUid[C].x.axis}}if("y"in n.locationLocks.locksByViewUid[C]){const r=n.locationLocks.locksDict[n.locationLocks.locksByViewUid[C].y.lock];this.locationLocksAxisWise.y[C]={lock:r,axis:n.locationLocks.locksByViewUid[C].y.axis}}}this.validateLocks(this.locationLocks)}},{key:"deserializeZoomLocks",value:function(n){if(this.zoomLocks={},n.zoomLocks)for(const C of Br(n.zoomLocks.locksByViewUid))this.zoomLocks[C]=n.zoomLocks.locksDict[n.zoomLocks.locksByViewUid[C]];this.validateLocks(this.zoomLocks)}},{key:"deserializeValueScaleLocks",value:function(n){if(this.valueScaleLocks={},n.valueScaleLocks)for(const C of Br(n.valueScaleLocks.locksByViewUid))this.valueScaleLocks[C]=n.valueScaleLocks.locksDict[n.valueScaleLocks.locksByViewUid[C]]}},{key:"serializeLocks",value:function(n){const C={},r={};for(const o of Br(n)){let A=n[o]&&n[o].uid;A||(A=Ag.nice()),n[o].uid=A,C[A]=n[o],r[o]=n[o].uid}return{locksByViewUid:r,locksDict:C}}},{key:"getViewsAsJson",value:function(){const n=JSON.parse(JSON.stringify(this.state.viewConfig));return n.views=Object.values(this.state.views).map(C=>{const r=JSON.parse(JSON.stringify(C));return Qa(r.tracks,o=>{if(o.server){const A=Hrt(o.server,{});if(!A.hostname.length){const s=window.location.host,{protocol:a}=window.location,l=`${a}//${s}${A.pathname}`;o.server=l}}(o.type==="viewport-projection-center"||o.type==="viewport-projection-horizontal")&&this.projectionXDomains[C.uid]&&this.projectionXDomains[C.uid][o.uid]&&(o.projectionXDomain=this.projectionXDomains[C.uid][o.uid]),(o.type==="viewport-projection-center"||o.type==="viewport-projection-vertical")&&this.projectionYDomains[C.uid]&&this.projectionYDomains[C.uid][o.uid]&&(o.projectionYDomain=this.projectionYDomains[C.uid][o.uid]),delete o.name,delete o.position,delete o.header,delete o.description,delete o.created,delete o.project,delete o.project_name,delete o.serverUidKey,delete o.uuid,delete o.private,delete o.maxZoom,delete o.coordSystem,delete o.coordSystem2,delete o.datatype,delete o.maxWidth,delete o.datafile,delete o.binsPerDimension,delete o.resolutions,delete o.aggregationModes}),r.uid=C.uid,r.initialXDomain=this.xScales[C.uid].domain(),r.initialYDomain=this.yScales[C.uid].domain(),delete r.layout.i,r}),n.zoomLocks=this.serializeLocks(this.zoomLocks),n.locationLocks=this.serializeLocks(this.locationLocks),n.valueScaleLocks=this.serializeLocks(this.valueScaleLocks),n}},{key:"getViewsAsString",value:function(){return JSON.stringify(this.getViewsAsJson(),null,2)}},{key:"handleExportViewAsJSON",value:function(){const n=this.getViewsAsString();RG("viewconf.json",n)}},{key:"handleExportViewsAsLink",value:function(n=this.state.viewConfig.exportViewUrl,C=!1){const r=new URL(n,window.location.origin),o=fetch(n,{method:"POST",headers:{Accept:"application/json, text/plain, */*","Content-Type":"application/json","X-Requested-With":"XMLHttpRequest"},body:`{"viewconf":${this.getViewsAsString()}}`,credentials:"same-origin"}).then(A=>{if(!A.ok)throw A;return A.json()}).catch(A=>{console.warn("err:",A)}).then(A=>({id:A.uid,url:`${r.origin}/l/?d=${A.uid}`}));return C||o.then(A=>{this.openModal(N.createElement(N4,{onDone:()=>{this.closeModalBound()},url:A.url}))}).catch(A=>console.error("Exporting view config as link failed:",A)),o}},{key:"handleDataDomainChanged",value:function(n,C,r){const{views:o}=this.state;if(o[n].initialXDomain=C,o[n].initialYDomain=r,this.xScales[n]=qt().domain(C),this.yScales[n]=qt().domain(r),this.zoomLocks[n]){const A=this.zoomLocks[n],s=Rr(A);for(let a=0;aese)return!1;const a=xg(this.state.views);for(let l=0;lc&&Cu)return!1}return!0}},{key:"handleAddView",value:function(n){const C=xg(this.state.views),r=n,o=[];n.layout.w===12&&(n.layout.w=6);for(let a=0;a{const c=a[1]-l[1];return c===0?a[0]-l[0]:c});const A=JSON.stringify(r),s=JSON.parse(A);s.initialXDomain=this.xScales[s.uid].domain(),s.initialYDomain=this.yScales[s.uid].domain(),[[s.layout.x,s.layout.y]]=o,s.uid=Ag.nice(),s.layout.i=s.uid,Qa(s.tracks,a=>{this.addCallbacks(s.uid,a)}),this.setState(a=>{const l=JSON.parse(JSON.stringify(a.views));return l[s.uid]=s,{views:l}})}},{key:"handleSelectedAssemblyChanged",value:function(n,C,r,o){const{views:A}=this.state;A[n].genomePositionSearchBox.chromInfoId=C,A[n].genomePositionSearchBox.autocompleteId=r,A[n].genomePositionSearchBox.autocompleteServer=o}},{key:"createGenomePostionSearchBoxEntry",value:function(n,C){let r=n;const o={autocompleteServer:b3,chromInfoServer:b3,visible:!1};return r||(r=JSON.parse(JSON.stringify(o))),r.autocompleteServer||(r.autocompleteServer=o.autocompleteServer),r.chromInfoId||(r.chromInfoId=C),r.chromInfoServer||(r.chromInfoServer=o.chromInfoServer),r.visible||(r.visible=!1),r}},{key:"handleTogglePositionSearchBox",value:function(n){const C=this.state.views[n];C.genomePositionSearchBoxVisible=!C.genomePositionSearchBoxVisible;const r={};Qa(C.tracks,s=>{s.coordSystem&&(r[s.coordSystem]||(r[s.coordSystem]=0),r[s.coordSystem]+=1)});const o=Rr(r).sort((s,a)=>a[1]-s[1]);let A="hg19";o.length&&(A=o[0][0]),C.genomePositionSearchBox=this.createGenomePostionSearchBoxEntry(C.genomePositionSearchBox,A),C.genomePositionSearchBox.visible=!C.genomePositionSearchBox.visible,this.refreshView(),this.setState({configMenuUid:null})}},{key:"handleTrackOptionsChanged",value:function(n,C,r){const o=this.state.views[n],A=jC(o.tracks,C);A&&(A.options=Object.assign(A.options,r),this.mounted&&(this.setState(s=>({views:s.views})),this.adjustSplitHeatmapTrackOptions(A,r,o.tracks,n)))}},{key:"adjustSplitHeatmapTrackOptions",value:function(n,C,r,o){n.type==="heatmap"&&(C.extent==="upper-right"&&r.center[0].type==="combined"&&r.center[0].contents.length>1&&r.center[0].contents.some(A=>{if(A.type==="heatmap"&&A.uid!==n.uid&&A.options.extent!=="lower-left"){const s={...A.options,extent:"lower-left",labelPosition:"bottomLeft",colorbarPosition:"bottomLeft"},a={...C,labelPosition:"topRight",colorbarPosition:"topRight"};return this.handleTrackOptionsChanged(o,A.uid,s),this.handleTrackOptionsChanged(o,n.uid,a),!0}return!1}),C.extent==="lower-left"&&C.extent==="lower-left"&&r.center[0].type==="combined"&&r.center[0].contents.length>1&&r.center[0].contents.some(A=>{if(A.type==="heatmap"&&A.uid!==n.uid&&A.options.extent!=="upper-right"){const s={...A.options,extent:"upper-right",labelPosition:"topRight",colorbarPosition:"topRight"},a={...C,labelPosition:"bottomLeft",colorbarPosition:"bottomLeft"};return this.handleTrackOptionsChanged(o,A.uid,s),this.handleTrackOptionsChanged(o,n.uid,a),!0}return!1}))}},{key:"handleViewOptionsChanged",value:function(n,C){const r=this.state.views[n];r&&(r.options=Object.assign(r.options||{},C),this.mounted&&this.setState(o=>({views:o.views})))}},{key:"isTrackValid",value:function(n,C){return!(n.type==="viewport-projection-center"&&!C.has(n.fromViewUid))}},{key:"removeInvalidTracks",value:function(n){const C=new Set(Br(n));for(const r of xg(n))for(const o of["left","top","center","right","bottom"])r.tracks&&r.tracks.hasOwnProperty(o)&&(r.tracks[o]=r.tracks[o].filter(A=>this.isTrackValid(A,C)),r.tracks[o].forEach(A=>{A.type==="combined"&&(A.contents=A.contents.filter(s=>this.isTrackValid(s,C)))}));return n}},{key:"processViewConfig",value:function(n){let{views:C}=n,r={};return(!n.views||n.views.length===0)&&(console.warn("No views provided in viewConfig"),C=[{editable:!0,tracks:{}}]),C.forEach(o=>{o.tracks&&VZe(o.tracks),o.uid||(o.uid=Ag.nice()),r[o.uid]=o,this.zoomToDataExtentOnInit.has(o.uid)&&this.zoomToDataExtentOnInit.delete(o.uid),o.initialXDomain?(o.initialXDomain[0]=+o.initialXDomain[0],o.initialXDomain[1]=+o.initialXDomain[1]):(o.initialXDomain=[0,100],this.zoomToDataExtentOnInit.add(o.uid)),o.initialYDomain?(o.initialXDomain[0]=+o.initialXDomain[0],o.initialXDomain[1]=+o.initialXDomain[1]):o.initialYDomain=[o.initialXDomain[0],o.initialXDomain[1]],this.xScales[o.uid]||(this.xScales[o.uid]=qt().domain(o.initialXDomain)),this.yScales[o.uid]||(this.yScales[o.uid]=qt().domain(o.initialYDomain)),Qa(o.tracks,A=>{if(A.uid||(A.uid=Ag.nice()),this.addCallbacks(o.uid,A),this.addDefaultTrackOptions(A),A.contents)for(const s of A.contents)this.addDefaultTrackOptions(s)}),o.layout?o.layout.i=o.uid:o.layout=this.generateViewLayout(o)}),this.deserializeZoomLocks(n),this.deserializeLocationLocks(n),this.deserializeValueScaleLocks(n),r=this.removeInvalidTracks(r),r}},{key:"handleWindowFocused",value:function(){}},{key:"rangeSelectionHandler",value:function(n){this.rangeSelection=n,this.apiPublish("rangeSelection",n)}},{key:"offViewChange",value:function(n){this.viewChangeListener.splice(n,1)}},{key:"onViewChange",value:function(n){return this.viewChangeListener.push(n)-1}},{key:"triggerViewChange",value:function(){this.viewChangeListener.forEach(n=>n(this.getViewsAsString()))}},{key:"getGenomeLocation",value:function(n){return J7.get(this.state.views[n].chromInfoPath).then(C=>UZe(this.xScales[n],this.yScales[n],C))}},{key:"offLocationChange",value:function(n,C){this.removeScalesChangedListener(n,C)}},{key:"zoomTo",value:function(n,C,r,o,A,s){if(!(n in this.setCenters))throw Error(`Invalid viewUid. Current uuids: ${Object.keys(this.setCenters).join(",")}`);if(Number.isNaN(+C)||Number.isNaN(+r)){const u=[C,r].join(", ");console.warn([`Invalid coordinates (${u}). All coordinates need to be numbers and should represent absolute coordinates (not chromosome - coordinates).`].join(" "));return}(Number.isNaN(+o)||Number.isNaN(+A)||o===null||A===null)&&(o=C,A=r);const[a,l,c]=Zi(this.xScales[n].copy().domain([C,r]),this.yScales[n].copy().domain([o,A]));this.setCenters[n](a,l,c,!1,s)}},{key:"zoomToGene",value:function(n,C,r,o){if(!(n in this.setCenters))throw Error(`Invalid viewUid. Current uuids: ${Object.keys(this.setCenters).join(",")}`);if(!this.state.views[n].genomePositionSearchBox||!this.state.views[n].genomePositionSearchBox.autocompleteServer||!this.state.views[n].genomePositionSearchBox.autocompleteId||!this.state.views[n].chromInfoPath){console.warn("Please set chromInfoPath, autocompleteServer, and autocompleteId to use the zoomToGene API");return}this.suggestGene(n,C,A=>{if(A){const s=A.find(a=>a.geneName.toLowerCase()===C.toLowerCase());if(s){const{chr:a,txStart:l,txEnd:c}=s;qs(this.state.views[n].chromInfoPath,u=>{const d=u.chrToAbs([a,l])-r,h=u.chrToAbs([a,c])+r,[m,f,b]=Zi(this.xScales[n].copy().domain([d,h]),this.yScales[n].copy().domain([d,h]));this.setCenters[n](m,f,b,!1,o)},this.pubSub)}else console.warn(`Couldn't find the gene symbol: ${C}`)}})}},{key:"suggestGene",value:function(n,C,r){if(!(n in this.setCenters))throw Error(`Invalid viewUid. Current uuids: ${Object.keys(this.setCenters).join(",")}`);if(!this.state.views[n].genomePositionSearchBox||!this.state.views[n].genomePositionSearchBox.autocompleteServer||!this.state.views[n].genomePositionSearchBox.autocompleteId){console.warn("Please set autocompleteServer and autocompleteId to use the suggestGene API");return}const o=this.state.views[n].genomePositionSearchBox.autocompleteServer,A=this.state.views[n].genomePositionSearchBox.autocompleteId,s=`${o}/suggest/?d=${A}&ac=${C.toLowerCase()}`;vt.json(s,tA,this.pubSub).then(a=>{r(a)}).catch(a=>console.error(a))}},{key:"onLocationChange",value:function(n,C,r){const o=Object.keys(this.state.views);if(!o.length)return this.unsetOnLocationChange.push({viewId:n,callback:C,callbackId:r}),null;if(n=typeof n>"u"&&o.length===1?o[0]:n,typeof n>"u"||o.indexOf(n)===-1)return console.error("onLocationChange either missing a viewId or passed an invalid viewId: ",n),null;const A=this.state.views[n],s=(l,c)=>{C({xDomain:l.domain(),yDomain:c.domain(),xRange:l.range(),yRange:c.range()})};let a=1;return this.scalesChangedListeners[A.uid]&&(a=Object.keys(this.scalesChangedListeners[A.uid]).filter(l=>l.indexOf(tG)===0).map(l=>parseInt(l.slice(tG.length+1),10)).reduce((l,c)=>Math.max(l,c),0)+1),this.addScalesChangedListener(A.uid,`${tG}.${a}`,s),r&&r(`${tG}.${a}`),a}},{key:"getTiledPlotAtPosition",value:function(n,C){let r;const o=Pg(this.state.views);for(let A=0;A=c&&n<=d,m=C>=l&&C<=u;if(h&&m){r=s;break}}return r}},{key:"mouseMoveHandler",value:function(n){if(!this.topDiv||this.state.modal)return;const C=n.clientX,r=n.clientY,o=Og(n,this.topDiv);o[1]+=this.scrollTop;const A=this.getTiledPlotAtPosition(C,r),s=A?A.listTracksAtPosition(o[0],o[1],!0).map(h=>h.originalTrack||h):[],a=s.find(h=>!h.isAugmentationTrack),l=a?[o[0]-a.position[0],o[1]-a.position[1]]:o;let c=-1,u=-1;a&&(c=a.flipText?a._xScale.invert(l[1]):a._xScale.invert(l[0]),u=a.is2d?a._yScale.invert(l[1]):c);const d={x:o[0],y:o[1],relTrackX:a&&a.flipText?l[1]:l[0],relTrackY:a&&a.flipText?l[0]:l[1],dataX:c,dataY:u,isFrom2dTrack:!!(a&&a.is2d),isFromVerticalTrack:!!(a&&a.flipText),track:a,origEvt:n,sourceUid:this.uid,hoveredTracks:s,noHoveredTracks:s.length===0};if(this.pubSub.publish("app.mouseMove",d),this.isBroadcastMousePositionGlobally){const h={...d};h.origEvt=void 0,h.track=void 0,h.hoveredTracks=void 0,delete h.origEvt,delete h.track,delete h.hoveredTracks,eB.publish("higlass.mouseMove",h)}this.apiPublish("cursorLocation",{absX:C,absY:r,relX:d.x,relY:d.y,relTrackX:d.relTrackX,relTrackY:d.relTrackY,dataX:d.dataX,dataY:d.dataY,isFrom2dTrack:d.isFrom2dTrack,isFromVerticalTrack:d.isFromVerticalTrack}),this.showHoverMenu(d)}},{key:"getMinMaxValue",value:function(n,C,r,o){const A=gG(this.tiledPlots,n,C);if(!A){console.warn(`Track with ID: ${C} not found!`);return}if(!A.minVisibleValueInTiles||!A.maxVisibleValueInTiles){console.warn(`Track ${C} doesn't support the retrieval of min or max values.`);return}return r&&A.getAggregatedVisibleValue?[A.getAggregatedVisibleValue("min"),A.getAggregatedVisibleValue("max")]:[A.minVisibleValueInTiles(o),A.maxVisibleValueInTiles(o)]}},{key:"showHoverMenu",value:function(n){const C=n.track&&n.track.getMouseOverHtml?n.track.getMouseOverHtml(n.relTrackX,n.relTrackY):"";if(n.track!==this.prevMouseHoverTrack&&this.prevMouseHoverTrack&&this.prevMouseHoverTrack.stopHover&&this.prevMouseHoverTrack.stopHover(),this.prevMouseHoverTrack=n.track,this.zooming)return;const r=C&&C.length?[1]:[];let o=pg("body").selectAll(".track-mouseover-menu").data(r);o.exit().remove(),o.enter().append("div").classed("track-mouseover-menu",!0).classed(uf["track-mouseover-menu"],!0),o=pg("body").selectAll(".track-mouseover-menu");const A=Og(n.origEvt,pg("body").node()),s=[A[0]-window.scrollX,A[1]-window.scrollY];if(o.style("left",`${s[0]}px`).style("top",`${s[1]}px`),!o.node())return;const a=o.node().getBoundingClientRect();a.x+a.width>window.innerWidth&&o.style("left",`${s[0]-a.width}px`),a.y+a.height>window.innerHeight&&o.style("top",`${s[1]-a.height}px`),o.html(C)}},{key:"hideHoverMenu",value:function(){pg("body").selectAll(".track-mouseover-menu").remove()}},{key:"closeCustomDialog",value:function(){this.setState(n=>({customDialog:null}))}},{key:"appClickHandler",value:function(n){this.apiPublish("click",n)}},{key:"canvasClickHandler",value:function(n){const C=n.nativeEvent||n,r=C.clientX,o=C.clientY,A=this.getTiledPlotAtPosition(r,o),s=Og(C,this.topDiv);s[1]+=this.scrollTop;const a=A?A.listTracksAtPosition(s[0],s[1],!0).map(f=>f.originalTrack||f):[],l=a.find(f=>!f.isAugmentationTrack),c=l?[s[0]-l.position[0],s[1]-l.position[1]]:s,u=l&&l.flipText?c[1]:c[0],d=l&&l.flipText?c[0]:c[1];for(const f of this.iterateOverTracks()){const b=gG(this.tiledPlots,f.viewId,f.trackId);b.respondsToPosition(s[0],s[1])||b.clickOutside()}const h=[];for(const f of a)if(f.childTracks){for(const b of f.childTracks)h.push({trackUid:b.context.trackUid,viewUid:b.context.viewUid,trackType:b.context.trackType,data:b.click(u,d,n)});h.push({trackUid:f.context.trackUid,viewUid:f.context.viewUid,trackType:f.context.trackType,data:{type:"generic",event:n}})}else h.push({trackUid:f.context.trackUid,viewUid:f.context.viewUid,trackType:f.context.trackType,data:f.click(u,d,n)});const m=[];h.forEach((f,b)=>{const p=gG(this.tiledPlots,f.viewUid,f.trackUid);if(typeof p.clickDialog=="function"){const y=p.clickDialog();y&&m.push(y)}}),m.length>0&&this.setState(f=>({customDialog:m})),this.pubSub.publish("app.click",h)}},{key:"mouseMoveZoomHandler",value:function(n){this.apiPublish("mouseMoveZoom",n)}},{key:"geneSearchHandler",value:function(n){this.apiPublish("geneSearch",n)}},{key:"mouseDownHandler",value:function(n){}},{key:"onScrollHandler",value:function(){this.props.options.sizeMode===SZ&&(this.scrollTop=this.scrollContainer.scrollTop,this.pixiStage.y=-this.scrollTop,this.pubSub.publish("app.scroll",this.scrollTop),this.animate())}},{key:"setTrackValueScaleLimits",value:function(n,C,r,o){const A=gG(this.tiledPlots,n,C);if(!A){console.warn(`Could't find track: ${C}`);return}A.setFixedValueScaleMin&&A.setFixedValueScaleMax?(A.setFixedValueScaleMin(r),A.setFixedValueScaleMax(o),A.rerender(A.options,!0),A.animate()):console.warn("Track doesn't support fixed value scales.")}},{key:"setChromInfo",value:function(n,C){qs(n,r=>{this.chromInfo=r,C()},this.pubSub)}},{key:"onMouseLeaveHandler",value:function(){this.pubSub.publish("app.mouseLeave"),this.hideHoverMenu(),this.animate()}},{key:"onBlurHandler",value:function(){this.animate()}},{key:"isZoomFixed",value:function(n){return this.props.zoomFixed||this.props.options.zoomFixed||this.state.viewConfig.zoomFixed||this.props.options.sizeMode===SZ||n&&n.zoomFixed}},{key:"trackDimensionsModifiedHandler",value:function(n){const C=this.state.views[n.viewId];if(!C)return;const r=gr(C.tracks,n.trackId);r&&(n.height!==void 0&&(r.height=n.height),n.width!==void 0&&(r.width=n.width),this.adjustLayoutToTrackSizes(C),this.setState(o=>({views:o.views})))}},{key:"wheelHandler",value:function(n){if(this.state.modal||this.props.options.sizeMode===SZ)return;const C=n.nativeEvent||n,r=n.target===this.canvasElement;if(!UGe(C.target,this.topDiv)||this.isZoomFixed())return;const o=C.clientX,A=C.clientY,s=this.getTiledPlotAtPosition(o,A);if(this.apiStack.wheel&&this.apiStack.wheel.length>0){const a=Og(C,this.topDiv);a[1]+=this.scrollTop;const l=s?s.listTracksAtPosition(a[0],a[1],!0).map(h=>h.originalTrack||h):[],c=l.find(h=>!h.isAugmentationTrack),u=c?[a[0]-c.position[0],a[1]-c.position[1]]:a,d={x:a[0],y:a[1],relTrackX:c&&c.flipText?u[1]:u[0],relTrackY:c&&c.flipText?u[0]:u[1],track:c,origEvt:C,sourceUid:this.uid,hoveredTracks:l,noHoveredTracks:l.length===0};this.apiPublish("wheel",d)}if(C.forwarded||r){n.stopPropagation(),n.preventDefault();return}if(n.preventDefault(),s){const{trackRenderer:a}=s;C.forwarded=!0,C&&(J9(C,a.eventTracker),C.preventDefault())}}},{key:"render",value:function(){this.tiledAreasDivs={},this.tiledAreas=N.createElement("div",{className:uf["tiled-area"]}),this.mounted&&(this.tiledAreas=Pg(this.state.views).map(a=>{const l=a.uid===this.state.addTrackPositionMenuUid?this.state.addTrackPositionMenuPosition:null;let c=null;if(this.state.chooseViewHandler){let m="transparent";this.state.mouseOverOverlayUid===a.uid&&(m="green"),c=N.createElement("div",{className:"tiled-plot-overlay",onClick:()=>this.state.chooseViewHandler(a.uid),onMouseEnter:()=>this.handleOverlayMouseEnter(a.uid),onMouseLeave:()=>this.handleOverlayMouseLeave(a.uid),onMouseMove:()=>this.handleOverlayMouseEnter(a.uid),style:{position:"absolute",width:"100%",height:"100%",background:m,opacity:.3,zIndex:1}})}const u=N.createElement(qQt,{key:`tp${a.uid}`,ref:m=>{this.tiledPlots[a.uid]=m},addTrackPosition:this.state.addTrackPositionView===a.uid?this.state.addTrackPosition:null,addTrackPositionMenuPosition:l,canvasElement:this.state.canvasElement,chooseTrackHandler:this.state.chooseTrackHandler?m=>this.state.chooseTrackHandler(a.uid,m):null,customDialog:this.state.customDialog,closeCustomDialog:()=>this.closeCustomDialog(),chromInfoPath:a.chromInfoPath,disableTrackMenu:this.isTrackMenuDisabled(),draggingHappening:this.state.draggingHappening!==null,editable:this.isEditable(),getLockGroupExtrema:m=>this.getLockGroupExtrema(a.uid,m),initialXDomain:a.initialXDomain,initialYDomain:a.initialYDomain,isShowGlobalMousePosition:this.isShowGlobalMousePosition,isValueScaleLocked:m=>this.isValueScaleLocked(a.uid,m),marginBottom:this.viewMarginBottom,marginLeft:this.viewMarginLeft,marginRight:this.viewMarginRight,marginTop:this.viewMarginTop,metaTracks:a.metaTracks,mouseTool:this.state.mouseTool,onChangeTrackData:(m,f)=>this.handleChangeTrackData(a.uid,m,f),onChangeTrackType:(m,f)=>this.handleChangeTrackType(a.uid,m,f),onCloseTrack:m=>this.handleCloseTrack(a.uid,m),onDataDomainChanged:(m,f)=>this.handleDataDomainChanged(a.uid,m,f),onLockValueScale:m=>this.handleLockValueScale(a.uid,m),onMouseMoveZoom:this.mouseMoveZoomHandler.bind(this),onNewTilesLoaded:m=>this.handleNewTilesLoaded(a.uid,m),onNoTrackAdded:this.handleNoTrackAdded.bind(this),onRangeSelection:this.rangeSelectionHandler.bind(this),onResizeTrack:this.triggerViewChangeDb,onScalesChanged:(m,f)=>this.handleScalesChanged(a.uid,m,f),onTrackOptionsChanged:(m,f)=>this.handleTrackOptionsChanged(a.uid,m,f),onTrackPositionChosen:this.handleTrackPositionChosen.bind(this),onTracksAdded:(m,f,b)=>this.handleTracksAdded(a.uid,m,f,b),onUnlockValueScale:m=>this.handleUnlockValueScale(a.uid,m),onValueScaleChanged:m=>this.syncValueScales(a.uid,m),overlays:a.overlays,paddingBottom:this.viewPaddingBottom,paddingLeft:this.viewPaddingLeft,paddingRight:this.viewPaddingRight,paddingTop:this.viewPaddingTop,pixiRenderer:this.pixiRenderer,pixiStage:this.pixiStage,pluginDataFetchers:this.pluginDataFetchers,pluginTracks:this.pluginTracks,rangeSelection1dSize:this.state.rangeSelection1dSize,rangeSelectionToInt:this.state.rangeSelectionToInt,registerDraggingChangedListener:m=>this.addDraggingChangedListener(a.uid,a.uid,m),removeDraggingChangedListener:m=>this.removeDraggingChangedListener(a.uid,a.uid,m),setCentersFunction:m=>{this.setCenters[a.uid]=m},svgElement:this.state.svgElement,tracks:a.tracks,trackSourceServers:this.state.viewConfig.trackSourceServers,uid:a.uid,verticalMargin:this.verticalMargin,viewOptions:a.options,xDomainLimits:a.xDomainLimits,yDomainLimits:a.yDomainLimits,zoomable:!this.isZoomFixed(a),zoomLimits:this.calculateZoomLimits(a,a.initialXDomain),zoomToDataExtentOnInit:()=>this.zoomToDataExtentOnInit.has(a.uid)}),d=(m,f)=>a.genomePositionSearchBox?N.createElement(xjt,{key:`gpsb${a.uid}`,ref:b=>{this.genomePositionSearchBoxes[a.uid]=b},autocompleteId:a.genomePositionSearchBox.autocompleteId,autocompleteServer:a.genomePositionSearchBox.autocompleteServer,chromInfoId:a.genomePositionSearchBox.chromInfoId,chromInfoPath:a.genomePositionSearchBox.chromInfoPath,chromInfoServer:a.genomePositionSearchBox.chromInfoServer,hideAvailableAssemblies:a.genomePositionSearchBox.hideAvailableAssemblies,isFocused:m,onFocus:f,onGeneSearch:this.geneSearchHandler.bind(this),onSelectedAssemblyChanged:(b,p,y)=>this.handleSelectedAssemblyChanged(a.uid,b,p,y),registerViewportChangedListener:b=>this.addScalesChangedListener(a.uid,a.uid,b),removeViewportChangedListener:()=>this.removeScalesChangedListener(a.uid,a.uid),setCenters:(b,p,y,Z)=>this.setCenters[a.uid](b,p,y,!1,Z),trackSourceServers:this.state.viewConfig.trackSourceServers,twoD:!!(a.tracks.left.length||a.tracks.right.length||a.tracks.center.length)}):null,h=this.isEditable()&&!this.isViewHeaderDisabled()&&!this.state.viewConfig.hideHeader?N.createElement(c4t,{ref:m=>{this.viewHeaders[a.uid]=m},getGenomePositionSearchBox:d,isGenomePositionSearchBoxVisible:a.genomePositionSearchBox&&a.genomePositionSearchBox.visible,mouseTool:this.state.mouseTool,onAddView:()=>this.handleAddView(a),onClearView:()=>this.handleClearView(a.uid),onCloseView:()=>this.handleCloseView(a.uid),onEditViewConfig:this.handleEditViewConfigBound,onExportPNG:this.handleExportPNG.bind(this),onExportSVG:this.handleExportSVG.bind(this),onExportViewsAsJSON:this.handleExportViewAsJSON.bind(this),onExportViewsAsLink:this.handleExportViewsAsLink.bind(this),onLockLocation:m=>this.handleYankFunction(m,this.handleLocationLockChosen.bind(this)),onLockZoom:m=>this.handleYankFunction(m,this.handleZoomLockChosen.bind(this)),onLockZoomAndLocation:m=>this.handleYankFunction(m,(f,b)=>{this.handleZoomLockChosen(f,b),this.handleLocationLockChosen(f,b)}),onProjectViewport:this.handleProjectViewport.bind(this),onTakeAndLockZoomAndLocation:m=>{this.handleYankFunction(m,(f,b)=>{this.handleZoomYanked(f,b),this.handleLocationYanked(f,b),this.handleZoomLockChosen(f,b),this.handleLocationLockChosen(f,b)})},onTogglePositionSearchBox:this.handleTogglePositionSearchBox.bind(this),onTrackPositionChosen:m=>this.handleTrackPositionChosen(a.uid,m),onUnlockLocation:m=>this.handleUnlock(m,this.locationLocks),onUnlockZoom:m=>this.handleUnlock(m,this.zoomLocks),onUnlockZoomAndLocation:m=>{this.handleUnlock(m,this.zoomLocks),this.handleUnlock(m,this.locationLocks)},onViewOptionsChanged:m=>this.handleViewOptionsChanged(a.uid,m),onYankLocation:m=>this.handleYankFunction(m,this.handleLocationYanked.bind(this)),onYankZoom:m=>this.handleYankFunction(m,this.handleZoomYanked.bind(this)),onYankZoomAndLocation:m=>this.handleYankFunction(m,(f,b)=>{this.handleZoomYanked(f,b),this.handleLocationYanked(f,b)}),onZoomToData:m=>this.handleZoomToData(m),viewUid:a.uid}):null;return N.createElement("div",{key:a.uid,ref:m=>{this.tiledAreasDivs[a.uid]=m},className:uf["tiled-area"]},h,u,c)}));let n=this.mounted?Object.values(this.state.views).filter(a=>a.layout).map(a=>a.layout):[];n=JSON.parse(JSON.stringify(n));const C=this.isEditable()?GGe:0,r=this.isEditable()?BGe:0,o=+this.props.options.containerPaddingX>=0?+this.props.options.containerPaddingX:C,A=+this.props.options.containerPaddingY>=0?+this.props.options.containerPaddingY:r,s=N.createElement(knt,{ref:a=>{this.gridLayout=a},cols:12,containerPadding:[o,A],draggableHandle:`.${Tr["multitrack-header-grabber"]}`,isDraggable:this.isEditable(),isResizable:this.isEditable(),layout:n,margin:this.isEditable()?[10,10]:[0,0],measureBeforeMount:!1,onBreakpointChange:this.onBreakpointChange.bind(this),onDragStart:this.handleDragStart.bind(this),onDragStop:this.handleDragStop.bind(this),onLayoutChange:this.handleLayoutChange.bind(this),onResize:this.resizeHandler.bind(this),rowHeight:this.state.rowHeight,useCSSTransforms:this.mounted,verticalCompact:this.state.viewConfig.compactLayout,width:this.state.width},this.tiledAreas);return N.createElement("div",{key:this.uid,ref:a=>{this.topDiv=a},className:Tg("higlass",{"higlass-dark-theme":this.theme===II,"higlass-container-overflow":this.props.options.sizeMode===Ese||this.props.options.sizeMode===SZ}),onMouseLeave:this.onMouseLeaveHandlerBound,onMouseMove:this.mouseMoveHandlerBound},N.createElement(PVt,{value:this.pubSub},N.createElement(mEt,{value:this.modal},N.createElement(TVt,{value:this.theme},this.state.modal,N.createElement("canvas",{key:this.uid,ref:a=>{this.canvasElement=a},onClick:this.canvasClickHandlerBound,className:uf["higlass-canvas"]}),N.createElement("div",{ref:a=>{this.scrollContainer=a},className:Tg("higlass-scroll-container",{"higlass-scroll-container-overflow":this.props.options.sizeMode===Ese,"higlass-scroll-container-scroll":this.props.options.sizeMode===SZ}),onScroll:this.onScrollHandlerBound},N.createElement("div",{ref:a=>{this.divDrawingSurface=a},className:Tg("higlass-drawing-surface",uf["higlass-drawing-surface"])},s),N.createElement("svg",{ref:a=>{this.svgElement=a},className:uf["higlass-svg"],style:{position:"absolute",width:"100%",height:"100%",left:0,top:0,pointerEvents:"none"}}))))))}}]),I}(N.Component);yy.defaultProps={options:{},zoomFixed:!1,compactLayout:!0};yy.propTypes={getApi:L.func,options:L.object,viewConfig:L.oneOfType([L.string,L.object]).isRequired,zoomFixed:L.bool,compactLayout:L.bool};function N6t(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function Mse(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function J2(g){return J2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},J2(g)}const z6t=(g,[e,I,i,n],C)=>{C.options.colorbarPosition||(C.options.colorbarPosition="hidden"),C.options.labelPosition||(C.options.labelPosition="hidden");const r="arbitary-id",A=O6t(g,{editable:!1,zoomFixed:!1,views:[{uid:r,initialXDomain:[e,I],initialYDomain:[i,n],tracks:{center:[C]},layout:{w:12,h:12,x:0,y:0,moved:!1,static:!1}}]},{sizeMode:"bounded"});return{id:r,hgApi:A}};let P6t=function(g){x6t(I,g);var e=D6t(I);function I(i){var n;return N6t(this,I),n=e.call(this,i),n.id=`id-${Math.random()}`,n}return k6t(I,[{key:"componentDidMount",value:function(){this.initTrackViewer()}},{key:"shouldComponentUpdate",value:function(n){const{x:C,y:r,width:o,height:A}=n;return this.zoomTo(C,r,o,A),!1}},{key:"initTrackViewer",value:function(){const{trackConfig:n,x:C,y:r,width:o,height:A}=this.props,s=document.getElementById(this.id),{id:a,hgApi:l}=z6t(s,[C,C+o,r,r+A],n);this.viewUid=a,this.viewer=l}},{key:"zoomTo",value:function(n,C,r,o){this.viewer.zoomTo(this.viewUid,n,n+r,C,C+o)}},{key:"render",value:function(){return N.createElement("div",{id:this.id,style:{height:"100%",width:"100%"}})}}]),I}(N.Component);P6t.propTypes={trackConfig:L.object,width:L.number,height:L.number,x:L.number,y:L.number};const J6t=(g,e,I)=>{const i=N.createRef();return QI.render(N.createElement(yy,{ref:i,options:I||{},viewConfig:e}),g),i.current},O6t=(g,e,I)=>J6t(g,e,I).api;var CHe={exports:{}};(function(g,e){(function(I,i){g.exports=i()})(typeof window<"u"?window:ZI,function(){if(typeof window>"u")return null;var I=typeof window<"u"&&window.Math==Math?window:typeof self<"u"&&self.Math==Math?self:Function("return this")(),i=I.requestAnimationFrame||I.mozRequestAnimationFrame||I.webkitRequestAnimationFrame||function(a){return I.setTimeout(a,20)},n=I.cancelAnimationFrame||I.mozCancelAnimationFrame||I.webkitCancelAnimationFrame||function(a){I.clearTimeout(a)};function C(a,l){var c=Object.prototype.toString.call(a),u=c==="[object Array]"||c==="[object NodeList]"||c==="[object HTMLCollection]"||c==="[object Object]"||typeof jQuery<"u"&&a instanceof jQuery||typeof Elements<"u"&&a instanceof Elements,d=0,h=a.length;if(u)for(;d=X&&(H+=R.value),R.mode==="max"&&W<=X&&(H+=R.value),V[D]||(V[D]=""),H&&(" "+V[D]+" ").indexOf(" "+H+" ")===-1&&(V[D]+=" "+H));for(var F in Y)Y.hasOwnProperty(F)&&(V[Y[F]]?this.element.setAttribute(Y[F],V[Y[F]].substr(1)):this.element.removeAttribute(Y[F]))}}function c(G,B){G.elementQueriesSetupInformation||(G.elementQueriesSetupInformation=new l(G,B)),G.elementQueriesSensor||(G.elementQueriesSensor=new I(G,function(){G.elementQueriesSetupInformation.call()}))}function u(G,B,w,R){if(typeof r[G]>"u"){r[G]=[];var S=o.length;C.innerHTML+=` + coordinates).`].join(" "));return}(Number.isNaN(+o)||Number.isNaN(+A)||o===null||A===null)&&(o=C,A=r);const[a,l,c]=yi(this.xScales[n].copy().domain([C,r]),this.yScales[n].copy().domain([o,A]));this.setCenters[n](a,l,c,!1,s)}},{key:"zoomToGene",value:function(n,C,r,o){if(!(n in this.setCenters))throw Error(`Invalid viewUid. Current uuids: ${Object.keys(this.setCenters).join(",")}`);if(!this.state.views[n].genomePositionSearchBox||!this.state.views[n].genomePositionSearchBox.autocompleteServer||!this.state.views[n].genomePositionSearchBox.autocompleteId||!this.state.views[n].chromInfoPath){console.warn("Please set chromInfoPath, autocompleteServer, and autocompleteId to use the zoomToGene API");return}this.suggestGene(n,C,A=>{if(A){const s=A.find(a=>a.geneName.toLowerCase()===C.toLowerCase());if(s){const{chr:a,txStart:l,txEnd:c}=s;xs(this.state.views[n].chromInfoPath,u=>{const d=u.chrToAbs([a,l])-r,h=u.chrToAbs([a,c])+r,[m,f,b]=yi(this.xScales[n].copy().domain([d,h]),this.yScales[n].copy().domain([d,h]));this.setCenters[n](m,f,b,!1,o)},this.pubSub)}else console.warn(`Couldn't find the gene symbol: ${C}`)}})}},{key:"suggestGene",value:function(n,C,r){if(!(n in this.setCenters))throw Error(`Invalid viewUid. Current uuids: ${Object.keys(this.setCenters).join(",")}`);if(!this.state.views[n].genomePositionSearchBox||!this.state.views[n].genomePositionSearchBox.autocompleteServer||!this.state.views[n].genomePositionSearchBox.autocompleteId){console.warn("Please set autocompleteServer and autocompleteId to use the suggestGene API");return}const o=this.state.views[n].genomePositionSearchBox.autocompleteServer,A=this.state.views[n].genomePositionSearchBox.autocompleteId,s=`${o}/suggest/?d=${A}&ac=${C.toLowerCase()}`;Gt.json(s,_o,this.pubSub).then(a=>{r(a)}).catch(a=>console.error(a))}},{key:"onLocationChange",value:function(n,C,r){const o=Object.keys(this.state.views);if(!o.length)return this.unsetOnLocationChange.push({viewId:n,callback:C,callbackId:r}),null;if(n=typeof n>"u"&&o.length===1?o[0]:n,typeof n>"u"||o.indexOf(n)===-1)return console.error("onLocationChange either missing a viewId or passed an invalid viewId: ",n),null;const A=this.state.views[n],s=(l,c)=>{C({xDomain:l.domain(),yDomain:c.domain(),xRange:l.range(),yRange:c.range()})};let a=1;return this.scalesChangedListeners[A.uid]&&(a=Object.keys(this.scalesChangedListeners[A.uid]).filter(l=>l.indexOf(RZ)===0).map(l=>parseInt(l.slice(RZ.length+1),10)).reduce((l,c)=>Math.max(l,c),0)+1),this.addScalesChangedListener(A.uid,`${RZ}.${a}`,s),r&&r(`${RZ}.${a}`),a}},{key:"getTiledPlotAtPosition",value:function(n,C){let r;const o=xg(this.state.views);for(let A=0;A=c&&n<=d,m=C>=l&&C<=u;if(h&&m){r=s;break}}return r}},{key:"mouseMoveHandler",value:function(n){if(!this.topDiv||this.state.modal)return;const C=n.clientX,r=n.clientY,o=Eg(n,this.topDiv);o[1]+=this.scrollTop;const A=this.getTiledPlotAtPosition(C,r),s=A?A.listTracksAtPosition(o[0],o[1],!0).map(h=>h.originalTrack||h):[],a=s.find(h=>!h.isAugmentationTrack),l=a?[o[0]-a.position[0],o[1]-a.position[1]]:o;let c=-1,u=-1;a&&(c=a.flipText?a._xScale.invert(l[1]):a._xScale.invert(l[0]),u=a.is2d?a._yScale.invert(l[1]):c);const d={x:o[0],y:o[1],relTrackX:a&&a.flipText?l[1]:l[0],relTrackY:a&&a.flipText?l[0]:l[1],dataX:c,dataY:u,isFrom2dTrack:!!(a&&a.is2d),isFromVerticalTrack:!!(a&&a.flipText),track:a,origEvt:n,sourceUid:this.uid,hoveredTracks:s,noHoveredTracks:s.length===0};if(this.pubSub.publish("app.mouseMove",d),this.isBroadcastMousePositionGlobally){const h={...d};h.origEvt=void 0,h.track=void 0,h.hoveredTracks=void 0,delete h.origEvt,delete h.track,delete h.hoveredTracks,VG.publish("higlass.mouseMove",h)}this.apiPublish("cursorLocation",{absX:C,absY:r,relX:d.x,relY:d.y,relTrackX:d.relTrackX,relTrackY:d.relTrackY,dataX:d.dataX,dataY:d.dataY,isFrom2dTrack:d.isFrom2dTrack,isFromVerticalTrack:d.isFromVerticalTrack}),this.showHoverMenu(d)}},{key:"getMinMaxValue",value:function(n,C,r,o){const A=WZ(this.tiledPlots,n,C);if(!A){console.warn(`Track with ID: ${C} not found!`);return}if(!A.minVisibleValueInTiles||!A.maxVisibleValueInTiles){console.warn(`Track ${C} doesn't support the retrieval of min or max values.`);return}return r&&A.getAggregatedVisibleValue?[A.getAggregatedVisibleValue("min"),A.getAggregatedVisibleValue("max")]:[A.minVisibleValueInTiles(o),A.maxVisibleValueInTiles(o)]}},{key:"showHoverMenu",value:function(n){const C=n.track&&n.track.getMouseOverHtml?n.track.getMouseOverHtml(n.relTrackX,n.relTrackY):"";if(n.track!==this.prevMouseHoverTrack&&this.prevMouseHoverTrack&&this.prevMouseHoverTrack.stopHover&&this.prevMouseHoverTrack.stopHover(),this.prevMouseHoverTrack=n.track,this.zooming)return;const r=C&&C.length?[1]:[];let o=cg("body").selectAll(".track-mouseover-menu").data(r);o.exit().remove(),o.enter().append("div").classed("track-mouseover-menu",!0).classed(Qm["track-mouseover-menu"],!0),o=cg("body").selectAll(".track-mouseover-menu");const A=Eg(n.origEvt,cg("body").node()),s=[A[0]-window.scrollX,A[1]-window.scrollY];if(o.style("left",`${s[0]}px`).style("top",`${s[1]}px`),!o.node())return;const a=o.node().getBoundingClientRect();a.x+a.width>window.innerWidth&&o.style("left",`${s[0]-a.width}px`),a.y+a.height>window.innerHeight&&o.style("top",`${s[1]-a.height}px`),o.html(C)}},{key:"hideHoverMenu",value:function(){cg("body").selectAll(".track-mouseover-menu").remove()}},{key:"closeCustomDialog",value:function(){this.setState(n=>({customDialog:null}))}},{key:"appClickHandler",value:function(n){this.apiPublish("click",n)}},{key:"canvasClickHandler",value:function(n){const C=n.nativeEvent||n,r=C.clientX,o=C.clientY,A=this.getTiledPlotAtPosition(r,o),s=Eg(C,this.topDiv);s[1]+=this.scrollTop;const a=A?A.listTracksAtPosition(s[0],s[1],!0).map(f=>f.originalTrack||f):[],l=a.find(f=>!f.isAugmentationTrack),c=l?[s[0]-l.position[0],s[1]-l.position[1]]:s,u=l&&l.flipText?c[1]:c[0],d=l&&l.flipText?c[0]:c[1];for(const f of this.iterateOverTracks()){const b=WZ(this.tiledPlots,f.viewId,f.trackId);b.respondsToPosition(s[0],s[1])||b.clickOutside()}const h=[];for(const f of a)if(f.childTracks){for(const b of f.childTracks)h.push({trackUid:b.context.trackUid,viewUid:b.context.viewUid,trackType:b.context.trackType,data:b.click(u,d,n)});h.push({trackUid:f.context.trackUid,viewUid:f.context.viewUid,trackType:f.context.trackType,data:{type:"generic",event:n}})}else h.push({trackUid:f.context.trackUid,viewUid:f.context.viewUid,trackType:f.context.trackType,data:f.click(u,d,n)});const m=[];h.forEach((f,b)=>{const p=WZ(this.tiledPlots,f.viewUid,f.trackUid);if(typeof p.clickDialog=="function"){const y=p.clickDialog();y&&m.push(y)}}),m.length>0&&this.setState(f=>({customDialog:m})),this.pubSub.publish("app.click",h)}},{key:"mouseMoveZoomHandler",value:function(n){this.apiPublish("mouseMoveZoom",n)}},{key:"geneSearchHandler",value:function(n){this.apiPublish("geneSearch",n)}},{key:"mouseDownHandler",value:function(n){}},{key:"onScrollHandler",value:function(){this.props.options.sizeMode===AZ&&(this.scrollTop=this.scrollContainer.scrollTop,this.pixiStage.y=-this.scrollTop,this.pubSub.publish("app.scroll",this.scrollTop),this.animate())}},{key:"setTrackValueScaleLimits",value:function(n,C,r,o){const A=WZ(this.tiledPlots,n,C);if(!A){console.warn(`Could't find track: ${C}`);return}A.setFixedValueScaleMin&&A.setFixedValueScaleMax?(A.setFixedValueScaleMin(r),A.setFixedValueScaleMax(o),A.rerender(A.options,!0),A.animate()):console.warn("Track doesn't support fixed value scales.")}},{key:"setChromInfo",value:function(n,C){xs(n,r=>{this.chromInfo=r,C()},this.pubSub)}},{key:"onMouseLeaveHandler",value:function(){this.pubSub.publish("app.mouseLeave"),this.hideHoverMenu(),this.animate()}},{key:"onBlurHandler",value:function(){this.animate()}},{key:"isZoomFixed",value:function(n){return this.props.zoomFixed||this.props.options.zoomFixed||this.state.viewConfig.zoomFixed||this.props.options.sizeMode===AZ||n&&n.zoomFixed}},{key:"trackDimensionsModifiedHandler",value:function(n){const C=this.state.views[n.viewId];if(!C)return;const r=jC(C.tracks,n.trackId);r&&(n.height!==void 0&&(r.height=n.height),n.width!==void 0&&(r.width=n.width),this.adjustLayoutToTrackSizes(C),this.setState(o=>({views:o.views})))}},{key:"wheelHandler",value:function(n){if(this.state.modal||this.props.options.sizeMode===AZ)return;const C=n.nativeEvent||n,r=n.target===this.canvasElement;if(!xZe(C.target,this.topDiv)||this.isZoomFixed())return;const o=C.clientX,A=C.clientY,s=this.getTiledPlotAtPosition(o,A);if(this.apiStack.wheel&&this.apiStack.wheel.length>0){const a=Eg(C,this.topDiv);a[1]+=this.scrollTop;const l=s?s.listTracksAtPosition(a[0],a[1],!0).map(h=>h.originalTrack||h):[],c=l.find(h=>!h.isAugmentationTrack),u=c?[a[0]-c.position[0],a[1]-c.position[1]]:a,d={x:a[0],y:a[1],relTrackX:c&&c.flipText?u[1]:u[0],relTrackY:c&&c.flipText?u[0]:u[1],track:c,origEvt:C,sourceUid:this.uid,hoveredTracks:l,noHoveredTracks:l.length===0};this.apiPublish("wheel",d)}if(C.forwarded||r){n.stopPropagation(),n.preventDefault();return}if(n.preventDefault(),s){const{trackRenderer:a}=s;C.forwarded=!0,C&&(t9(C,a.eventTracker),C.preventDefault())}}},{key:"render",value:function(){this.tiledAreasDivs={},this.tiledAreas=N.createElement("div",{className:Qm["tiled-area"]}),this.mounted&&(this.tiledAreas=xg(this.state.views).map(a=>{const l=a.uid===this.state.addTrackPositionMenuUid?this.state.addTrackPositionMenuPosition:null;let c=null;if(this.state.chooseViewHandler){let m="transparent";this.state.mouseOverOverlayUid===a.uid&&(m="green"),c=N.createElement("div",{className:"tiled-plot-overlay",onClick:()=>this.state.chooseViewHandler(a.uid),onMouseEnter:()=>this.handleOverlayMouseEnter(a.uid),onMouseLeave:()=>this.handleOverlayMouseLeave(a.uid),onMouseMove:()=>this.handleOverlayMouseEnter(a.uid),style:{position:"absolute",width:"100%",height:"100%",background:m,opacity:.3,zIndex:1}})}const u=N.createElement(X4t,{key:`tp${a.uid}`,ref:m=>{this.tiledPlots[a.uid]=m},addTrackPosition:this.state.addTrackPositionView===a.uid?this.state.addTrackPosition:null,addTrackPositionMenuPosition:l,canvasElement:this.state.canvasElement,chooseTrackHandler:this.state.chooseTrackHandler?m=>this.state.chooseTrackHandler(a.uid,m):null,customDialog:this.state.customDialog,closeCustomDialog:()=>this.closeCustomDialog(),chromInfoPath:a.chromInfoPath,disableTrackMenu:this.isTrackMenuDisabled(),draggingHappening:this.state.draggingHappening!==null,editable:this.isEditable(),getLockGroupExtrema:m=>this.getLockGroupExtrema(a.uid,m),initialXDomain:a.initialXDomain,initialYDomain:a.initialYDomain,isShowGlobalMousePosition:this.isShowGlobalMousePosition,isValueScaleLocked:m=>this.isValueScaleLocked(a.uid,m),marginBottom:this.viewMarginBottom,marginLeft:this.viewMarginLeft,marginRight:this.viewMarginRight,marginTop:this.viewMarginTop,metaTracks:a.metaTracks,mouseTool:this.state.mouseTool,onChangeTrackData:(m,f)=>this.handleChangeTrackData(a.uid,m,f),onChangeTrackType:(m,f)=>this.handleChangeTrackType(a.uid,m,f),onCloseTrack:m=>this.handleCloseTrack(a.uid,m),onDataDomainChanged:(m,f)=>this.handleDataDomainChanged(a.uid,m,f),onLockValueScale:m=>this.handleLockValueScale(a.uid,m),onMouseMoveZoom:this.mouseMoveZoomHandler.bind(this),onNewTilesLoaded:m=>this.handleNewTilesLoaded(a.uid,m),onNoTrackAdded:this.handleNoTrackAdded.bind(this),onRangeSelection:this.rangeSelectionHandler.bind(this),onResizeTrack:this.triggerViewChangeDb,onScalesChanged:(m,f)=>this.handleScalesChanged(a.uid,m,f),onTrackOptionsChanged:(m,f)=>this.handleTrackOptionsChanged(a.uid,m,f),onTrackPositionChosen:this.handleTrackPositionChosen.bind(this),onTracksAdded:(m,f,b)=>this.handleTracksAdded(a.uid,m,f,b),onUnlockValueScale:m=>this.handleUnlockValueScale(a.uid,m),onValueScaleChanged:m=>this.syncValueScales(a.uid,m),overlays:a.overlays,paddingBottom:this.viewPaddingBottom,paddingLeft:this.viewPaddingLeft,paddingRight:this.viewPaddingRight,paddingTop:this.viewPaddingTop,pixiRenderer:this.pixiRenderer,pixiStage:this.pixiStage,pluginDataFetchers:this.pluginDataFetchers,pluginTracks:this.pluginTracks,rangeSelection1dSize:this.state.rangeSelection1dSize,rangeSelectionToInt:this.state.rangeSelectionToInt,registerDraggingChangedListener:m=>this.addDraggingChangedListener(a.uid,a.uid,m),removeDraggingChangedListener:m=>this.removeDraggingChangedListener(a.uid,a.uid,m),setCentersFunction:m=>{this.setCenters[a.uid]=m},svgElement:this.state.svgElement,tracks:a.tracks,trackSourceServers:this.state.viewConfig.trackSourceServers,uid:a.uid,verticalMargin:this.verticalMargin,viewOptions:a.options,xDomainLimits:a.xDomainLimits,yDomainLimits:a.yDomainLimits,zoomable:!this.isZoomFixed(a),zoomLimits:this.calculateZoomLimits(a,a.initialXDomain),zoomToDataExtentOnInit:()=>this.zoomToDataExtentOnInit.has(a.uid)}),d=(m,f)=>a.genomePositionSearchBox?N.createElement(h$t,{key:`gpsb${a.uid}`,ref:b=>{this.genomePositionSearchBoxes[a.uid]=b},autocompleteId:a.genomePositionSearchBox.autocompleteId,autocompleteServer:a.genomePositionSearchBox.autocompleteServer,chromInfoId:a.genomePositionSearchBox.chromInfoId,chromInfoPath:a.genomePositionSearchBox.chromInfoPath,chromInfoServer:a.genomePositionSearchBox.chromInfoServer,hideAvailableAssemblies:a.genomePositionSearchBox.hideAvailableAssemblies,isFocused:m,onFocus:f,onGeneSearch:this.geneSearchHandler.bind(this),onSelectedAssemblyChanged:(b,p,y)=>this.handleSelectedAssemblyChanged(a.uid,b,p,y),registerViewportChangedListener:b=>this.addScalesChangedListener(a.uid,a.uid,b),removeViewportChangedListener:()=>this.removeScalesChangedListener(a.uid,a.uid),setCenters:(b,p,y,Z)=>this.setCenters[a.uid](b,p,y,!1,Z),trackSourceServers:this.state.viewConfig.trackSourceServers,twoD:!!(a.tracks.left.length||a.tracks.right.length||a.tracks.center.length)}):null,h=this.isEditable()&&!this.isViewHeaderDisabled()&&!this.state.viewConfig.hideHeader?N.createElement(J$t,{ref:m=>{this.viewHeaders[a.uid]=m},getGenomePositionSearchBox:d,isGenomePositionSearchBoxVisible:a.genomePositionSearchBox&&a.genomePositionSearchBox.visible,mouseTool:this.state.mouseTool,onAddView:()=>this.handleAddView(a),onClearView:()=>this.handleClearView(a.uid),onCloseView:()=>this.handleCloseView(a.uid),onEditViewConfig:this.handleEditViewConfigBound,onExportPNG:this.handleExportPNG.bind(this),onExportSVG:this.handleExportSVG.bind(this),onExportViewsAsJSON:this.handleExportViewAsJSON.bind(this),onExportViewsAsLink:this.handleExportViewsAsLink.bind(this),onLockLocation:m=>this.handleYankFunction(m,this.handleLocationLockChosen.bind(this)),onLockZoom:m=>this.handleYankFunction(m,this.handleZoomLockChosen.bind(this)),onLockZoomAndLocation:m=>this.handleYankFunction(m,(f,b)=>{this.handleZoomLockChosen(f,b),this.handleLocationLockChosen(f,b)}),onProjectViewport:this.handleProjectViewport.bind(this),onTakeAndLockZoomAndLocation:m=>{this.handleYankFunction(m,(f,b)=>{this.handleZoomYanked(f,b),this.handleLocationYanked(f,b),this.handleZoomLockChosen(f,b),this.handleLocationLockChosen(f,b)})},onTogglePositionSearchBox:this.handleTogglePositionSearchBox.bind(this),onTrackPositionChosen:m=>this.handleTrackPositionChosen(a.uid,m),onUnlockLocation:m=>this.handleUnlock(m,this.locationLocks),onUnlockZoom:m=>this.handleUnlock(m,this.zoomLocks),onUnlockZoomAndLocation:m=>{this.handleUnlock(m,this.zoomLocks),this.handleUnlock(m,this.locationLocks)},onViewOptionsChanged:m=>this.handleViewOptionsChanged(a.uid,m),onYankLocation:m=>this.handleYankFunction(m,this.handleLocationYanked.bind(this)),onYankZoom:m=>this.handleYankFunction(m,this.handleZoomYanked.bind(this)),onYankZoomAndLocation:m=>this.handleYankFunction(m,(f,b)=>{this.handleZoomYanked(f,b),this.handleLocationYanked(f,b)}),onZoomToData:m=>this.handleZoomToData(m),viewUid:a.uid}):null;return N.createElement("div",{key:a.uid,ref:m=>{this.tiledAreasDivs[a.uid]=m},className:Qm["tiled-area"]},h,u,c)}));let n=this.mounted?Object.values(this.state.views).filter(a=>a.layout).map(a=>a.layout):[];n=JSON.parse(JSON.stringify(n));const C=this.isEditable()?cZe:0,r=this.isEditable()?uZe:0,o=+this.props.options.containerPaddingX>=0?+this.props.options.containerPaddingX:C,A=+this.props.options.containerPaddingY>=0?+this.props.options.containerPaddingY:r,s=N.createElement(crt,{ref:a=>{this.gridLayout=a},cols:12,containerPadding:[o,A],draggableHandle:`.${vr["multitrack-header-grabber"]}`,isDraggable:this.isEditable(),isResizable:this.isEditable(),layout:n,margin:this.isEditable()?[10,10]:[0,0],measureBeforeMount:!1,onBreakpointChange:this.onBreakpointChange.bind(this),onDragStart:this.handleDragStart.bind(this),onDragStop:this.handleDragStop.bind(this),onLayoutChange:this.handleLayoutChange.bind(this),onResize:this.resizeHandler.bind(this),rowHeight:this.state.rowHeight,useCSSTransforms:this.mounted,verticalCompact:this.state.viewConfig.compactLayout,width:this.state.width},this.tiledAreas);return N.createElement("div",{key:this.uid,ref:a=>{this.topDiv=a},className:Vg("higlass",{"higlass-dark-theme":this.theme===qg,"higlass-container-overflow":this.props.options.sizeMode===gse||this.props.options.sizeMode===AZ}),onMouseLeave:this.onMouseLeaveHandlerBound,onMouseMove:this.mouseMoveHandlerBound},N.createElement(Z1t,{value:this.pubSub},N.createElement(UMt,{value:this.modal},N.createElement(s1t,{value:this.theme},this.state.modal,N.createElement("canvas",{key:this.uid,ref:a=>{this.canvasElement=a},onClick:this.canvasClickHandlerBound,className:Qm["higlass-canvas"]}),N.createElement("div",{ref:a=>{this.scrollContainer=a},className:Vg("higlass-scroll-container",{"higlass-scroll-container-overflow":this.props.options.sizeMode===gse,"higlass-scroll-container-scroll":this.props.options.sizeMode===AZ}),onScroll:this.onScrollHandlerBound},N.createElement("div",{ref:a=>{this.divDrawingSurface=a},className:Vg("higlass-drawing-surface",Qm["higlass-drawing-surface"])},s),N.createElement("svg",{ref:a=>{this.svgElement=a},className:Qm["higlass-svg"],style:{position:"absolute",width:"100%",height:"100%",left:0,top:0,pointerEvents:"none"}}))))))}}]),I}(N.Component);gy.defaultProps={options:{},zoomFixed:!1,compactLayout:!0};gy.propTypes={getApi:L.func,options:L.object,viewConfig:L.oneOfType([L.string,L.object]).isRequired,zoomFixed:L.bool,compactLayout:L.bool};function leg(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function Ise(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function tH(e){return tH=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},tH(e)}const yeg=(e,[g,I,i,n],C)=>{C.options.colorbarPosition||(C.options.colorbarPosition="hidden"),C.options.labelPosition||(C.options.labelPosition="hidden");const r="arbitary-id",A=veg(e,{editable:!1,zoomFixed:!1,views:[{uid:r,initialXDomain:[g,I],initialYDomain:[i,n],tracks:{center:[C]},layout:{w:12,h:12,x:0,y:0,moved:!1,static:!1}}]},{sizeMode:"bounded"});return{id:r,hgApi:A}};let Zeg=function(e){heg(I,e);var g=meg(I);function I(i){var n;return leg(this,I),n=g.call(this,i),n.id=`id-${Math.random()}`,n}return ceg(I,[{key:"componentDidMount",value:function(){this.initTrackViewer()}},{key:"shouldComponentUpdate",value:function(n){const{x:C,y:r,width:o,height:A}=n;return this.zoomTo(C,r,o,A),!1}},{key:"initTrackViewer",value:function(){const{trackConfig:n,x:C,y:r,width:o,height:A}=this.props,s=document.getElementById(this.id),{id:a,hgApi:l}=yeg(s,[C,C+o,r,r+A],n);this.viewUid=a,this.viewer=l}},{key:"zoomTo",value:function(n,C,r,o){this.viewer.zoomTo(this.viewUid,n,n+r,C,C+o)}},{key:"render",value:function(){return N.createElement("div",{id:this.id,style:{height:"100%",width:"100%"}})}}]),I}(N.Component);Zeg.propTypes={trackConfig:L.object,width:L.number,height:L.number,x:L.number,y:L.number};const Geg=(e,g,I)=>{const i=N.createRef();return UI.render(N.createElement(gy,{ref:i,options:I||{},viewConfig:g}),e),i.current},veg=(e,g,I)=>Geg(e,g,I).api;var QXe={exports:{}};(function(e,g){(function(I,i){e.exports=i()})(typeof window<"u"?window:bI,function(){if(typeof window>"u")return null;var I=typeof window<"u"&&window.Math==Math?window:typeof self<"u"&&self.Math==Math?self:Function("return this")(),i=I.requestAnimationFrame||I.mozRequestAnimationFrame||I.webkitRequestAnimationFrame||function(a){return I.setTimeout(a,20)},n=I.cancelAnimationFrame||I.mozCancelAnimationFrame||I.webkitCancelAnimationFrame||function(a){I.clearTimeout(a)};function C(a,l){var c=Object.prototype.toString.call(a),u=c==="[object Array]"||c==="[object NodeList]"||c==="[object HTMLCollection]"||c==="[object Object]"||typeof jQuery<"u"&&a instanceof jQuery||typeof Elements<"u"&&a instanceof Elements,d=0,h=a.length;if(u)for(;d=X&&(H+=V.value),V.mode==="max"&&W<=X&&(H+=V.value),R[Y]||(R[Y]=""),H&&(" "+R[Y]+" ").indexOf(" "+H+" ")===-1&&(R[Y]+=" "+H));for(var E in D)D.hasOwnProperty(E)&&(R[D[E]]?this.element.setAttribute(D[E],R[D[E]].substr(1)):this.element.removeAttribute(D[E]))}}function c(G,v){G.elementQueriesSetupInformation||(G.elementQueriesSetupInformation=new l(G,v)),G.elementQueriesSensor||(G.elementQueriesSensor=new I(G,function(){G.elementQueriesSetupInformation.call()}))}function u(G,v,w,V){if(typeof r[G]>"u"){r[G]=[];var S=o.length;C.innerHTML+=` `+G+" {animation: 0.1s element-queries;}",C.innerHTML+=` -`+G+" > .resize-sensor {min-width: "+S+"px;}",o.push(G)}r[G].push({mode:B,property:w,value:R})}function d(G){var B;if(document.querySelectorAll&&(B=G?G.querySelectorAll.bind(G):document.querySelectorAll.bind(document)),!B&&typeof $$<"u"&&(B=$$),!B&&typeof jQuery<"u"&&(B=jQuery),!B)throw"No document.querySelectorAll, jQuery or Mootools's $$ found.";return B}function h(G){var B=d(G);for(var w in r)if(r.hasOwnProperty(w))for(var R=B(w,G),S=0,X=R.length;Sw[J].minWidth&&(_=J);if(_||(_=S),X!==_)if(W[_])B[X].style.display="none",B[_].style.display="block",X=_;else{var te=new Image;te.onload=function(){B[_].src=R[_],B[X].style.display="none",B[_].style.display="block",W[_]=!0,X=_},te.src=R[_]}else B[_].src=R[_]}G.resizeSensorInstance=new I(G,F),F()}function f(){for(var G=d(),B=G("[data-responsive-image],[responsive-image]"),w=0,R=B.length;w img, [data-responsive-image] {overflow: hidden; padding: 0; } [responsive-image] > img, [data-responsive-image] > img {width: 100%;}",C.innerHTML+=` -@keyframes element-queries { 0% { visibility: inherit; } }`,document.getElementsByTagName("head")[0].appendChild(C),v=!0);for(var B=0,w=document.styleSheets.length;Be in g?_6t(g,e,{enumerable:!0,configurable:!0,writable:!0,value:I}):g[e]=I,nt=(g,e,I)=>(U6t(g,typeof e!="symbol"?e+"":e,I),I),B$=(g,e,I)=>{if(!e.has(g))throw TypeError("Cannot "+I)},Jt=(g,e,I)=>(B$(g,e,"read from private field"),I?I.call(g):e.get(g)),Zg=(g,e,I)=>{if(e.has(g))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(g):e.set(g,I)},wC=(g,e,I,i)=>(B$(g,e,"write to private field"),i?i.call(g,I):e.set(g,I),I),wI=(g,e,I)=>(B$(g,e,"access private method"),I),vG,cS,uS,_d,O2,L2,EO,AHe,v$,aHe,_2,MO,zO,sHe,PO,lHe,JO,cHe,ts;const Q6t="#/definitions/GoslingSpec",j6t="http://json-schema.org/draft-07/schema#",$6t={Aggregate:{enum:["max","min","mean","bin","count"],type:"string"},Assembly:{anyOf:[{const:"hg38",type:"string"},{const:"hg19",type:"string"},{const:"hg18",type:"string"},{const:"hg17",type:"string"},{const:"hg16",type:"string"},{const:"mm10",type:"string"},{const:"mm9",type:"string"},{const:"unknown",type:"string"},{$ref:"#/definitions/ChromSizes"}]},AxisPosition:{enum:["none","top","bottom","left","right"],type:"string"},BamData:{additionalProperties:!1,description:"Binary Alignment Map (BAM) is the comprehensive raw data of genome sequencing; it consists of the lossless, compressed binary representation of the Sequence Alignment Map-files.",properties:{extractJunction:{description:"Determine whether to extract exon-to-exon junctions. __Default__: `false`",type:"boolean"},indexUrl:{description:"URL link to the index file of the BAM file",type:"string"},junctionMinCoverage:{description:"Determine the threshold of coverage when extracting exon-to-exon junctions. __Default__: `1`",type:"number"},loadMates:{description:"Load mates that are located in the same chromosome. __Default__: `false`",type:"boolean"},maxInsertSize:{description:"Determines the threshold of insert sizes for determining the structural variants. __Default__: `5000`",type:"number"},type:{const:"bam",type:"string"},url:{description:"URL link to the BAM data file",type:"string"}},required:["type","url","indexUrl"],type:"object"},BedData:{additionalProperties:!1,description:"BED file format",properties:{customFields:{description:"An array of strings, where each string is the name of a non-standard field in the BED file. If there are `n` custom fields, we assume that the last `n` columns of the BED file correspond to the custom fields.",items:{type:"string"},type:"array"},indexUrl:{description:"Specify the URL address of the data file index.",type:"string"},sampleLength:{description:"Specify the number of rows loaded from the URL.\n\n__Default:__ `1000`",type:"number"},type:{const:"bed",type:"string"},url:{description:"Specify the URL address of the data file.",type:"string"}},required:["type","url","indexUrl"],type:"object"},BeddbData:{additionalProperties:!1,description:"Regular BED or similar files can be pre-aggregated for the scalable data exploration. Find our more about this format at [HiGlass Docs](https://docs.higlass.io/data_preparation.html#bed-files).",properties:{exonIntervalFields:{description:"experimental",items:[{additionalProperties:!1,properties:{index:{type:"number"},name:{type:"string"}},required:["index","name"],type:"object"},{additionalProperties:!1,properties:{index:{type:"number"},name:{type:"string"}},required:["index","name"],type:"object"}],maxItems:2,minItems:2,type:"array"},genomicFields:{description:"Specify the name of genomic data fields.",items:{additionalProperties:!1,properties:{index:{type:"number"},name:{type:"string"}},required:["index","name"],type:"object"},type:"array"},type:{const:"beddb",type:"string"},url:{description:"Specify the URL address of the data file.",type:"string"},valueFields:{description:"Specify the column indexes, field names, and field types.",items:{additionalProperties:!1,properties:{index:{type:"number"},name:{type:"string"},type:{enum:["nominal","quantitative"],type:"string"}},required:["index","name","type"],type:"object"},type:"array"}},required:["type","url","genomicFields"],type:"object"},BigWigData:{additionalProperties:!1,properties:{aggregation:{$ref:"#/definitions/BinAggregate",description:'Determine aggregation function to apply within bins. __Default__: `"mean"`'},binSize:{description:"Binning the genomic interval in tiles (unit size: 256).",type:"number"},column:{description:'Assign a field name of the middle position of genomic intervals. __Default__: `"position"`',type:"string"},end:{description:'Assign a field name of the end position of genomic intervals. __Default__: `"end"`',type:"string"},start:{description:'Assign a field name of the start position of genomic intervals. __Default__: `"start"`',type:"string"},type:{const:"bigwig",type:"string"},url:{description:"Specify the URL address of the data file.",type:"string"},value:{description:'Assign a field name of quantitative values. __Default__: `"value"`',type:"string"}},required:["type","url"],type:"object"},BinAggregate:{enum:["mean","sum"],type:"string"},Channel:{anyOf:[{$ref:"#/definitions/ChannelDeep"},{$ref:"#/definitions/ChannelValue"}]},ChannelDeep:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/Y"},{$ref:"#/definitions/Row"},{$ref:"#/definitions/Color"},{$ref:"#/definitions/Size"},{$ref:"#/definitions/Stroke"},{$ref:"#/definitions/StrokeWidth"},{$ref:"#/definitions/Opacity"},{$ref:"#/definitions/Text"}]},ChannelValue:{additionalProperties:!1,properties:{value:{description:"Assign a constant value for a visual channel.",type:["number","string"]}},required:["value"],type:"object"},ChromSizes:{description:'Custom chromosome sizes, e.g., [["foo", 1000], ["bar", 300], ["baz", 240]]',items:{items:[{type:"string"},{type:"number"}],maxItems:2,minItems:2,type:"array"},type:"array"},Color:{additionalProperties:!1,properties:{domain:{$ref:"#/definitions/ValueExtent",description:"Values of the data"},field:{description:"Name of the data field",type:"string"},legend:{description:"Whether to display legend. __Default__: `false`",type:"boolean"},range:{$ref:"#/definitions/Range",description:"Determine the colors that should be bound to data value. Default properties are determined considering the field type."},scale:{enum:["linear","log"],type:"string"},scaleOffset:{description:"Whether to use offset of the domain proportionally. This is bound to brushes on the color legend. __Default__: `[0, 1]`",items:{type:"number"},maxItems:2,minItems:2,type:"array"},title:{description:"Title of the legend. __Default__: `undefined`",type:"string"},type:{description:"Specify the data type",enum:["quantitative","nominal"],type:"string"}},type:"object"},CoverageTransform:{additionalProperties:!1,description:"Aggregate rows and calculate coverage",properties:{endField:{type:"string"},groupField:{description:"The name of a nominal field to group rows by in prior to piling-up",type:"string"},newField:{type:"string"},startField:{type:"string"},type:{const:"coverage",type:"string"}},required:["type","startField","endField"],type:"object"},CsvData:{additionalProperties:!1,description:'Any small enough tabular data files, such as tsv, csv, BED, BEDPE, and GFF, can be loaded using "csv" data specification.',properties:{chromosomeField:{description:"Specify the name of chromosome data fields.",type:"string"},chromosomePrefix:{description:'Specify the chromosome prefix if chromosomes are denoted using a prefix besides "chr" or a number',type:"string"},genomicFields:{description:"Specify the name of genomic data fields.",items:{type:"string"},type:"array"},genomicFieldsToConvert:{description:"experimental",items:{additionalProperties:!1,properties:{chromosomeField:{type:"string"},genomicFields:{items:{type:"string"},type:"array"}},required:["chromosomeField","genomicFields"],type:"object"},type:"array"},headerNames:{description:"Specify the names of data fields if a CSV file does not contain a header.",items:{type:"string"},type:"array"},longToWideId:{description:"experimental",type:"string"},sampleLength:{description:"Specify the number of rows loaded from the URL.\n\n__Default:__ `1000`",type:"number"},separator:{description:"Specify file separator, __Default:__ ','",type:"string"},type:{const:"csv",type:"string"},url:{description:"Specify the URL address of the data file.",type:"string"}},required:["type","url"],type:"object"},DataDeep:{anyOf:[{$ref:"#/definitions/JsonData"},{$ref:"#/definitions/CsvData"},{$ref:"#/definitions/BedData"},{$ref:"#/definitions/BigWigData"},{$ref:"#/definitions/MultivecData"},{$ref:"#/definitions/BeddbData"},{$ref:"#/definitions/VectorData"},{$ref:"#/definitions/MatrixData"},{$ref:"#/definitions/BamData"},{$ref:"#/definitions/VcfData"},{$ref:"#/definitions/GffData"}]},DataTrack:{additionalProperties:!1,description:"Partial specification of `BasicSingleTrack` to use default visual encoding predefined by data type.",properties:{_assignedHeight:{type:"number"},_assignedWidth:{description:"Internal: Used for responsive spec",type:"number"},_invalidTrack:{description:"internal",type:"boolean"},_renderingId:{description:"internal",type:"string"},assembly:{$ref:"#/definitions/Assembly",description:'A string that specifies the genome builds to use. Currently support `"hg38"`, `"hg19"`, `"hg18"`, `"hg17"`, `"hg16"`, `"mm10"`, `"mm9"`, and `"unknown"`.\n\n__Note:__: with `"unknown"` assembly, genomic axes do not show chrN: in labels.'},centerRadius:{description:"Proportion of the radius of the center white space.\n\n__Default:__ `0.3`",type:"number"},data:{$ref:"#/definitions/DataDeep"},endAngle:{description:'Specify the end angle (in the range of [0, 360]) of circular tracks (`{"layout": "circular"}`).',type:"number"},height:{description:"Specify the track height in pixels.",type:"number"},id:{description:"Assigned to `uid` in a HiGlass view config, used for API and caching.",type:"string"},innerRadius:{description:'Specify the inner radius of tracks when (`{"layout": "circular"}`).',type:"number"},layout:{$ref:"#/definitions/Layout",description:"Specify the layout type of all tracks."},linkingId:{description:"Specify an ID for [linking multiple views](http://gosling-lang.org/docs/user-interaction#linking-views)",type:"string"},orientation:{$ref:"#/definitions/Orientation",description:"Specify the orientation."},outerRadius:{description:'Specify the outer radius of tracks when `{"layout": "circular"}`.',type:"number"},overlayOnPreviousTrack:{type:"boolean"},prerelease:{additionalProperties:!1,description:"internal",type:"object"},spacing:{description:"The size of the gap (1) between tracks, (2) between views, and (3) of the origin of circular tracks. The effect of this property depends on where on the spec you specify the `spacing`.\n\nIn a linear layout, this value is used in pixels, while in a circular layout, this value is used relative to the height of the tracks or views.",type:"number"},startAngle:{description:'Specify the start angle (in the range of [0, 360]) of circular tracks (`{"layout": "circular"}`).',type:"number"},static:{description:"Whether to disable [Zooming and Panning](http://gosling-lang.org/docs/user-interaction#zooming-and-panning), __Default:__ `false`.",type:"boolean"},style:{$ref:"#/definitions/Style",description:"Define the [style](http://gosling-lang.org/docs/visual-channel#style-related-properties) of multive views. Will be overwritten by the style of children elements (e.g., view, track)."},subtitle:{type:"string"},title:{description:"If defined, will show the textual label on the left-top corner of a track.",type:"string"},width:{description:"Specify the track width in pixels.",type:"number"},xAxis:{$ref:"#/definitions/AxisPosition",description:"not supported"},xDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic x-axis"},xOffset:{description:"Specify the x offset of views in the unit of pixels",type:"number"},yDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic y-axis"},yOffset:{description:"Specify the y offset of views in the unit of pixels",type:"number"},zoomLimits:{$ref:"#/definitions/ZoomLimits"}},required:["data"],type:"object"},DataTransform:{anyOf:[{$ref:"#/definitions/FilterTransform"},{$ref:"#/definitions/StrConcatTransform"},{$ref:"#/definitions/StrReplaceTransform"},{$ref:"#/definitions/LogTransform"},{$ref:"#/definitions/DisplaceTransform"},{$ref:"#/definitions/ExonSplitTransform"},{$ref:"#/definitions/GenomicLengthTransform"},{$ref:"#/definitions/SvTypeTransform"},{$ref:"#/definitions/CoverageTransform"},{$ref:"#/definitions/JsonParseTransform"}]},Datum:{additionalProperties:{type:["number","string"]},description:"Values in the form of JSON.",type:"object"},DisplaceTransform:{additionalProperties:!1,properties:{boundingBox:{additionalProperties:!1,properties:{endField:{description:"The name of a quantitative field that represents the end position.",type:"string"},groupField:{description:"The name of a nominal field to group rows by in prior to piling-up.",type:"string"},isPaddingBP:{description:"Whether to consider `padding` as the bp length.",type:"boolean"},padding:{description:"The padding around visual lements. Either px or bp",type:"number"},startField:{description:"The name of a quantitative field that represents the start position.",type:"string"}},required:["startField","endField"],type:"object"},maxRows:{description:"Specify maximum rows to be generated (default has no limit).",type:"number"},method:{$ref:"#/definitions/DisplacementType",description:"A string that specifies the type of displacement."},newField:{type:"string"},type:{const:"displace",type:"string"}},required:["type","boundingBox","method","newField"],type:"object"},Displacement:{additionalProperties:!1,properties:{padding:{type:"number"},type:{$ref:"#/definitions/DisplacementType"}},required:["type"],type:"object"},DisplacementType:{enum:["pile","spread"],type:"string"},DomainChr:{additionalProperties:!1,properties:{chromosome:{type:"string"}},required:["chromosome"],type:"object"},DomainChrInterval:{additionalProperties:!1,properties:{chromosome:{description:"If specified, only showing a certain interval in a chromosome.",type:"string"},interval:{items:{type:"number"},maxItems:2,minItems:2,type:"array"}},required:["chromosome","interval"],type:"object"},DomainInterval:{additionalProperties:!1,properties:{interval:{description:"Show a certain interval within entire chromosome",items:{type:"number"},maxItems:2,minItems:2,type:"array"}},required:["interval"],type:"object"},DummyTrack:{additionalProperties:!1,description:"A placeholder track. In contrast to other tracks, this track does not display any data. Instead it provides empty space for third party tools to display their data on top of.",properties:{_invalidTrack:{description:"internal",type:"boolean"},assembly:{const:"unknown",description:"No assemblies can be associated with a dummy track",type:"string"},height:{description:"Specify the track height in pixels.",type:"number"},id:{description:"Assigned to `uid` in a HiGlass view config, used for API and caching.",type:"string"},layout:{const:"linear",description:"Only linear layout are supported at this time",type:"string"},orientation:{$ref:"#/definitions/Orientation",description:"Specify the orientation."},overlayOnPreviousTrack:{type:"boolean"},static:{const:!0,description:"Whether to disable [Zooming and Panning](http://gosling-lang.org/docs/user-interaction#zooming-and-panning), __Default:__ `false`.",type:"boolean"},style:{$ref:"#/definitions/DummyTrackStyle",description:"Defines how the track is styled"},title:{description:"Text that gets shown on the DummyTrack",type:"string"},type:{const:"dummy-track",description:"Used to specify the dummy track",type:"string"},width:{description:"Specify the track width in pixels.",type:"number"},zoomLimits:{description:"Unused property for DummyTrack",items:{type:"null"},maxItems:2,minItems:2,type:"array"}},required:["type"],type:"object"},DummyTrackStyle:{additionalProperties:!1,properties:{background:{description:"Background color of the track",type:"string"},outline:{description:"Color of the outline of the track",type:"string"},textFontSize:{description:"Specify the font size of the title",type:"number"},textFontWeight:{description:"Specify the font weight of the title.",enum:["bold","normal"],type:"string"},textStroke:{description:"Specify the stroke color of title.",type:"string"},textStrokeWidth:{description:"Specify the stroke width of the title.",type:"number"}},type:"object"},EventStyle:{additionalProperties:!1,description:"The styles defined here will be applied to the target marks of mouse events, such as a point mark after the user clicks on it.",properties:{arrange:{description:"Show event effects behind or in front of marks.",enum:["behind","front"],type:"string"},color:{description:"color of the marks when mouse events are triggered",type:"string"},opacity:{description:"opacity of the marks when mouse events are triggered",type:"number"},stroke:{description:"stroke color of the marks when mouse events are triggered",type:"string"},strokeOpacity:{type:"number"},strokeWidth:{description:"stroke width of the marks when mouse events are triggered",type:"number"}},type:"object"},ExonSplitTransform:{additionalProperties:!1,properties:{fields:{items:{additionalProperties:!1,properties:{chrField:{type:"string"},field:{type:"string"},newField:{type:"string"},type:{$ref:"#/definitions/FieldType"}},required:["field","type","newField","chrField"],type:"object"},type:"array"},flag:{additionalProperties:!1,properties:{field:{type:"string"},value:{type:["number","string"]}},required:["field","value"],type:"object"},separator:{type:"string"},type:{const:"exonSplit",type:"string"}},required:["type","separator","flag","fields"],type:"object"},FieldType:{enum:["genomic","nominal","quantitative"],type:"string"},FilterTransform:{anyOf:[{$ref:"#/definitions/OneOfFilter"},{$ref:"#/definitions/RangeFilter"},{$ref:"#/definitions/IncludeFilter"}]},GenomicDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}]},GenomicLengthTransform:{additionalProperties:!1,description:"Calculate genomic length using two genomic fields",properties:{endField:{type:"string"},newField:{type:"string"},startField:{type:"string"},type:{const:"genomicLength",type:"string"}},required:["type","startField","endField","newField"],type:"object"},GffData:{additionalProperties:!1,description:"Generic Feature Format Version 3 (GFF3) format data. It parses files that follow the [GFF3 specification](https://github.com/The-Sequence-Ontology/Specifications/blob/master/gff3.md).",properties:{attributesToFields:{description:'Specifies which attributes to include as a fields. GFF files have an "attributes" column which contains a list of attributes which are each tag-value pairs (`tag=value`). This option allows for specific attributes to be accessible as a field. For example, if you have an attribute called "gene_name" and you want label features on your track using those values, you can use this option so that you can use `"field": "gene_name"` in the schema.\n\nIf there is a single `value` corresponding to the `tag`, Gosling will parse that value as a string. If there are multiple `value`s corresponding to a `tag`, Gosling will parse it as a comma-separated list string. If a feature does not have a particular attribute, then the attribute value will be set to the `defaultValue`.',items:{additionalProperties:!1,properties:{attribute:{type:"string"},defaultValue:{type:"string"}},required:["attribute","defaultValue"],type:"object"},type:"array"},indexUrl:{description:"URL link to the tabix index file",type:"string"},sampleLength:{description:"The maximum number of samples to be shown on the track. Samples are uniformly randomly selected so that this threshold is not exceeded. __Default:__ `1000`",type:"number"},type:{const:"gff",type:"string"},url:{description:"URL link to the GFF file",type:"string"}},required:["type","url","indexUrl"],type:"object"},GoslingSpec:{anyOf:[{additionalProperties:!1,properties:{_assignedHeight:{type:"number"},_assignedWidth:{description:"Internal: Used for responsive spec",type:"number"},_invalidTrack:{description:"internal",type:"boolean"},_renderingId:{description:"internal",type:"string"},alignment:{const:"overlay",type:"string"},assembly:{$ref:"#/definitions/Assembly",description:'A string that specifies the genome builds to use. Currently support `"hg38"`, `"hg19"`, `"hg18"`, `"hg17"`, `"hg16"`, `"mm10"`, `"mm9"`, and `"unknown"`.\n\n__Note:__: with `"unknown"` assembly, genomic axes do not show chrN: in labels.'},baselineY:{type:"number"},centerRadius:{description:"Proportion of the radius of the center white space.\n\n__Default:__ `0.3`",type:"number"},color:{anyOf:[{$ref:"#/definitions/Color"},{$ref:"#/definitions/ChannelValue"}]},data:{$ref:"#/definitions/DataDeep"},dataTransform:{items:{$ref:"#/definitions/DataTransform"},type:"array"},description:{type:"string"},displacement:{$ref:"#/definitions/Displacement"},endAngle:{description:'Specify the end angle (in the range of [0, 360]) of circular tracks (`{"layout": "circular"}`).',type:"number"},experimental:{additionalProperties:!1,properties:{mouseEvents:{anyOf:[{type:"boolean"},{$ref:"#/definitions/MouseEventsDeep"}]},performanceMode:{default:!1,description:"Render visual marks with less smooth curves to increase rendering performance. Only supported for `elliptical` `linkStyle` `withinLink` currently.",type:"boolean"}},type:"object"},flipY:{type:"boolean"},height:{description:"Specify the track height in pixels.",type:"number"},id:{description:"The ID of a view that is maintained for the use of JS API functions, e.g., positions of a view",type:"string"},innerRadius:{description:'Specify the inner radius of tracks when (`{"layout": "circular"}`).',type:"number"},layout:{$ref:"#/definitions/Layout",description:"Specify the layout type of all tracks."},linkingId:{description:"Specify an ID for [linking multiple views](http://gosling-lang.org/docs/user-interaction#linking-views)",type:"string"},mark:{$ref:"#/definitions/Mark"},opacity:{anyOf:[{$ref:"#/definitions/Opacity"},{$ref:"#/definitions/ChannelValue"}]},orientation:{$ref:"#/definitions/Orientation",description:"Specify the orientation."},outerRadius:{description:'Specify the outer radius of tracks when `{"layout": "circular"}`.',type:"number"},overlayOnPreviousTrack:{type:"boolean"},overrideTemplate:{type:"boolean"},prerelease:{additionalProperties:!1,description:"internal",type:"object"},responsiveSize:{$ref:"#/definitions/ResponsiveSize",description:"Determine whether to make the size of `GoslingComponent` bound to its parent element. __Default__: `false`"},responsiveSpec:{items:{additionalProperties:!1,properties:{selectivity:{items:{$ref:"#/definitions/SelectivityCondition"},type:"array"},spec:{additionalProperties:!1,properties:{_assignedHeight:{type:"number"},_assignedWidth:{description:"Internal: Used for responsive spec",type:"number"},_invalidTrack:{description:"internal",type:"boolean"},_renderingId:{description:"internal",type:"string"},alignment:{enum:["overlay","stack"],type:"string"},assembly:{$ref:"#/definitions/Assembly",description:'A string that specifies the genome builds to use. Currently support `"hg38"`, `"hg19"`, `"hg18"`, `"hg17"`, `"hg16"`, `"mm10"`, `"mm9"`, and `"unknown"`.\n\n__Note:__: with `"unknown"` assembly, genomic axes do not show chrN: in labels.'},baselineY:{type:"number"},centerRadius:{description:"Proportion of the radius of the center white space.\n\n__Default:__ `0.3`",type:"number"},color:{anyOf:[{$ref:"#/definitions/Color"},{$ref:"#/definitions/ChannelValue"}]},data:{$ref:"#/definitions/DataDeep"},dataTransform:{items:{$ref:"#/definitions/DataTransform"},type:"array"},displacement:{$ref:"#/definitions/Displacement"},endAngle:{description:'Specify the end angle (in the range of [0, 360]) of circular tracks (`{"layout": "circular"}`).',type:"number"},experimental:{additionalProperties:!1,properties:{mouseEvents:{anyOf:[{type:"boolean"},{$ref:"#/definitions/MouseEventsDeep"}]},performanceMode:{default:!1,description:"Render visual marks with less smooth curves to increase rendering performance. Only supported for `elliptical` `linkStyle` `withinLink` currently.",type:"boolean"}},type:"object"},flipY:{type:"boolean"},height:{description:"Specify the track height in pixels.",type:"number"},id:{description:"The ID of a view that is maintained for the use of JS API functions, e.g., positions of a view",type:"string"},innerRadius:{description:'Specify the inner radius of tracks when (`{"layout": "circular"}`).',type:"number"},layout:{$ref:"#/definitions/Layout",description:"Specify the layout type of all tracks."},linkingId:{description:"Specify an ID for [linking multiple views](http://gosling-lang.org/docs/user-interaction#linking-views)",type:"string"},mark:{$ref:"#/definitions/Mark"},opacity:{anyOf:[{$ref:"#/definitions/Opacity"},{$ref:"#/definitions/ChannelValue"}]},orientation:{$ref:"#/definitions/Orientation",description:"Specify the orientation."},outerRadius:{description:'Specify the outer radius of tracks when `{"layout": "circular"}`.',type:"number"},overlayOnPreviousTrack:{type:"boolean"},overrideTemplate:{type:"boolean"},prerelease:{additionalProperties:!1,description:"internal",type:"object"},row:{anyOf:[{$ref:"#/definitions/Row"},{$ref:"#/definitions/ChannelValue"}]},size:{anyOf:[{$ref:"#/definitions/Size"},{$ref:"#/definitions/ChannelValue"}]},spacing:{description:"The size of the gap (1) between tracks, (2) between views, and (3) of the origin of circular tracks. The effect of this property depends on where on the spec you specify the `spacing`.\n\nIn a linear layout, this value is used in pixels, while in a circular layout, this value is used relative to the height of the tracks or views.",type:"number"},startAngle:{description:'Specify the start angle (in the range of [0, 360]) of circular tracks (`{"layout": "circular"}`).',type:"number"},static:{description:"Whether to disable [Zooming and Panning](http://gosling-lang.org/docs/user-interaction#zooming-and-panning), __Default:__ `false`.",type:"boolean"},stretch:{type:"boolean"},stroke:{anyOf:[{$ref:"#/definitions/Stroke"},{$ref:"#/definitions/ChannelValue"}]},strokeWidth:{anyOf:[{$ref:"#/definitions/StrokeWidth"},{$ref:"#/definitions/ChannelValue"}]},style:{$ref:"#/definitions/Style",description:"Define the [style](http://gosling-lang.org/docs/visual-channel#style-related-properties) of multive views. Will be overwritten by the style of children elements (e.g., view, track)."},subtitle:{type:"string"},text:{anyOf:[{$ref:"#/definitions/Text"},{$ref:"#/definitions/ChannelValue"}]},title:{description:"If defined, will show the textual label on the left-top corner of a track.",type:"string"},tooltip:{items:{$ref:"#/definitions/Tooltip"},type:"array"},tracks:{anyOf:[{items:{$ref:"#/definitions/PartialTrack"},type:"array"},{items:{anyOf:[{$ref:"#/definitions/PartialTrack"},{$ref:"#/definitions/OverlaidTracks"}]},type:"array"}]},visibility:{items:{$ref:"#/definitions/VisibilityCondition"},type:"array"},width:{description:"Specify the track width in pixels.",type:"number"},x:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},x1:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},x1e:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},xAxis:{$ref:"#/definitions/AxisPosition",description:"not supported"},xDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic x-axis"},xOffset:{description:"Specify the x offset of views in the unit of pixels",type:"number"},xe:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},y:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},y1:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},y1e:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},yDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic y-axis"},yOffset:{description:"Specify the y offset of views in the unit of pixels",type:"number"},ye:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},zoomLimits:{$ref:"#/definitions/ZoomLimits"}},type:"object"}},required:["spec","selectivity"],type:"object"},type:"array"},row:{anyOf:[{$ref:"#/definitions/Row"},{$ref:"#/definitions/ChannelValue"}]},size:{anyOf:[{$ref:"#/definitions/Size"},{$ref:"#/definitions/ChannelValue"}]},spacing:{description:"The size of the gap (1) between tracks, (2) between views, and (3) of the origin of circular tracks. The effect of this property depends on where on the spec you specify the `spacing`.\n\nIn a linear layout, this value is used in pixels, while in a circular layout, this value is used relative to the height of the tracks or views.",type:"number"},startAngle:{description:'Specify the start angle (in the range of [0, 360]) of circular tracks (`{"layout": "circular"}`).',type:"number"},static:{description:"Whether to disable [Zooming and Panning](http://gosling-lang.org/docs/user-interaction#zooming-and-panning), __Default:__ `false`.",type:"boolean"},stretch:{type:"boolean"},stroke:{anyOf:[{$ref:"#/definitions/Stroke"},{$ref:"#/definitions/ChannelValue"}]},strokeWidth:{anyOf:[{$ref:"#/definitions/StrokeWidth"},{$ref:"#/definitions/ChannelValue"}]},style:{$ref:"#/definitions/Style",description:"Define the [style](http://gosling-lang.org/docs/visual-channel#style-related-properties) of multive views. Will be overwritten by the style of children elements (e.g., view, track)."},subtitle:{type:"string"},text:{anyOf:[{$ref:"#/definitions/Text"},{$ref:"#/definitions/ChannelValue"}]},title:{description:"If defined, will show the textual label on the left-top corner of a track.",type:"string"},tooltip:{items:{$ref:"#/definitions/Tooltip"},type:"array"},tracks:{items:{$ref:"#/definitions/PartialTrack"},type:"array"},visibility:{items:{$ref:"#/definitions/VisibilityCondition"},type:"array"},width:{description:"Specify the track width in pixels.",type:"number"},x:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},x1:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},x1e:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},xAxis:{$ref:"#/definitions/AxisPosition",description:"not supported"},xDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic x-axis"},xOffset:{description:"Specify the x offset of views in the unit of pixels",type:"number"},xe:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},y:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},y1:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},y1e:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},yDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic y-axis"},yOffset:{description:"Specify the y offset of views in the unit of pixels",type:"number"},ye:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},zoomLimits:{$ref:"#/definitions/ZoomLimits"}},required:["alignment","tracks"],type:"object"},{additionalProperties:!1,properties:{_assignedHeight:{type:"number"},_assignedWidth:{description:"Internal: Used for responsive spec",type:"number"},_invalidTrack:{description:"internal",type:"boolean"},_renderingId:{description:"internal",type:"string"},alignment:{const:"stack",type:"string"},assembly:{$ref:"#/definitions/Assembly",description:'A string that specifies the genome builds to use. Currently support `"hg38"`, `"hg19"`, `"hg18"`, `"hg17"`, `"hg16"`, `"mm10"`, `"mm9"`, and `"unknown"`.\n\n__Note:__: with `"unknown"` assembly, genomic axes do not show chrN: in labels.'},baselineY:{type:"number"},centerRadius:{description:"Proportion of the radius of the center white space.\n\n__Default:__ `0.3`",type:"number"},color:{anyOf:[{$ref:"#/definitions/Color"},{$ref:"#/definitions/ChannelValue"}]},data:{$ref:"#/definitions/DataDeep"},dataTransform:{items:{$ref:"#/definitions/DataTransform"},type:"array"},description:{type:"string"},displacement:{$ref:"#/definitions/Displacement"},endAngle:{description:'Specify the end angle (in the range of [0, 360]) of circular tracks (`{"layout": "circular"}`).',type:"number"},experimental:{additionalProperties:!1,properties:{mouseEvents:{anyOf:[{type:"boolean"},{$ref:"#/definitions/MouseEventsDeep"}]},performanceMode:{default:!1,description:"Render visual marks with less smooth curves to increase rendering performance. Only supported for `elliptical` `linkStyle` `withinLink` currently.",type:"boolean"}},type:"object"},flipY:{type:"boolean"},height:{description:"Specify the track height in pixels.",type:"number"},id:{description:"The ID of a view that is maintained for the use of JS API functions, e.g., positions of a view",type:"string"},innerRadius:{description:'Specify the inner radius of tracks when (`{"layout": "circular"}`).',type:"number"},layout:{$ref:"#/definitions/Layout",description:"Specify the layout type of all tracks."},linkingId:{description:"Specify an ID for [linking multiple views](http://gosling-lang.org/docs/user-interaction#linking-views)",type:"string"},mark:{$ref:"#/definitions/Mark"},opacity:{anyOf:[{$ref:"#/definitions/Opacity"},{$ref:"#/definitions/ChannelValue"}]},orientation:{$ref:"#/definitions/Orientation",description:"Specify the orientation."},outerRadius:{description:'Specify the outer radius of tracks when `{"layout": "circular"}`.',type:"number"},overlayOnPreviousTrack:{type:"boolean"},overrideTemplate:{type:"boolean"},prerelease:{additionalProperties:!1,description:"internal",type:"object"},responsiveSize:{$ref:"#/definitions/ResponsiveSize",description:"Determine whether to make the size of `GoslingComponent` bound to its parent element. __Default__: `false`"},responsiveSpec:{items:{additionalProperties:!1,properties:{selectivity:{items:{$ref:"#/definitions/SelectivityCondition"},type:"array"},spec:{additionalProperties:!1,properties:{_assignedHeight:{type:"number"},_assignedWidth:{description:"Internal: Used for responsive spec",type:"number"},_invalidTrack:{description:"internal",type:"boolean"},_renderingId:{description:"internal",type:"string"},alignment:{enum:["overlay","stack"],type:"string"},assembly:{$ref:"#/definitions/Assembly",description:'A string that specifies the genome builds to use. Currently support `"hg38"`, `"hg19"`, `"hg18"`, `"hg17"`, `"hg16"`, `"mm10"`, `"mm9"`, and `"unknown"`.\n\n__Note:__: with `"unknown"` assembly, genomic axes do not show chrN: in labels.'},baselineY:{type:"number"},centerRadius:{description:"Proportion of the radius of the center white space.\n\n__Default:__ `0.3`",type:"number"},color:{anyOf:[{$ref:"#/definitions/Color"},{$ref:"#/definitions/ChannelValue"}]},data:{$ref:"#/definitions/DataDeep"},dataTransform:{items:{$ref:"#/definitions/DataTransform"},type:"array"},displacement:{$ref:"#/definitions/Displacement"},endAngle:{description:'Specify the end angle (in the range of [0, 360]) of circular tracks (`{"layout": "circular"}`).',type:"number"},experimental:{additionalProperties:!1,properties:{mouseEvents:{anyOf:[{type:"boolean"},{$ref:"#/definitions/MouseEventsDeep"}]},performanceMode:{default:!1,description:"Render visual marks with less smooth curves to increase rendering performance. Only supported for `elliptical` `linkStyle` `withinLink` currently.",type:"boolean"}},type:"object"},flipY:{type:"boolean"},height:{description:"Specify the track height in pixels.",type:"number"},id:{description:"The ID of a view that is maintained for the use of JS API functions, e.g., positions of a view",type:"string"},innerRadius:{description:'Specify the inner radius of tracks when (`{"layout": "circular"}`).',type:"number"},layout:{$ref:"#/definitions/Layout",description:"Specify the layout type of all tracks."},linkingId:{description:"Specify an ID for [linking multiple views](http://gosling-lang.org/docs/user-interaction#linking-views)",type:"string"},mark:{$ref:"#/definitions/Mark"},opacity:{anyOf:[{$ref:"#/definitions/Opacity"},{$ref:"#/definitions/ChannelValue"}]},orientation:{$ref:"#/definitions/Orientation",description:"Specify the orientation."},outerRadius:{description:'Specify the outer radius of tracks when `{"layout": "circular"}`.',type:"number"},overlayOnPreviousTrack:{type:"boolean"},overrideTemplate:{type:"boolean"},prerelease:{additionalProperties:!1,description:"internal",type:"object"},row:{anyOf:[{$ref:"#/definitions/Row"},{$ref:"#/definitions/ChannelValue"}]},size:{anyOf:[{$ref:"#/definitions/Size"},{$ref:"#/definitions/ChannelValue"}]},spacing:{description:"The size of the gap (1) between tracks, (2) between views, and (3) of the origin of circular tracks. The effect of this property depends on where on the spec you specify the `spacing`.\n\nIn a linear layout, this value is used in pixels, while in a circular layout, this value is used relative to the height of the tracks or views.",type:"number"},startAngle:{description:'Specify the start angle (in the range of [0, 360]) of circular tracks (`{"layout": "circular"}`).',type:"number"},static:{description:"Whether to disable [Zooming and Panning](http://gosling-lang.org/docs/user-interaction#zooming-and-panning), __Default:__ `false`.",type:"boolean"},stretch:{type:"boolean"},stroke:{anyOf:[{$ref:"#/definitions/Stroke"},{$ref:"#/definitions/ChannelValue"}]},strokeWidth:{anyOf:[{$ref:"#/definitions/StrokeWidth"},{$ref:"#/definitions/ChannelValue"}]},style:{$ref:"#/definitions/Style",description:"Define the [style](http://gosling-lang.org/docs/visual-channel#style-related-properties) of multive views. Will be overwritten by the style of children elements (e.g., view, track)."},subtitle:{type:"string"},text:{anyOf:[{$ref:"#/definitions/Text"},{$ref:"#/definitions/ChannelValue"}]},title:{description:"If defined, will show the textual label on the left-top corner of a track.",type:"string"},tooltip:{items:{$ref:"#/definitions/Tooltip"},type:"array"},tracks:{anyOf:[{items:{$ref:"#/definitions/PartialTrack"},type:"array"},{items:{anyOf:[{$ref:"#/definitions/PartialTrack"},{$ref:"#/definitions/OverlaidTracks"}]},type:"array"}]},visibility:{items:{$ref:"#/definitions/VisibilityCondition"},type:"array"},width:{description:"Specify the track width in pixels.",type:"number"},x:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},x1:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},x1e:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},xAxis:{$ref:"#/definitions/AxisPosition",description:"not supported"},xDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic x-axis"},xOffset:{description:"Specify the x offset of views in the unit of pixels",type:"number"},xe:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},y:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},y1:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},y1e:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},yDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic y-axis"},yOffset:{description:"Specify the y offset of views in the unit of pixels",type:"number"},ye:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},zoomLimits:{$ref:"#/definitions/ZoomLimits"}},type:"object"}},required:["spec","selectivity"],type:"object"},type:"array"},row:{anyOf:[{$ref:"#/definitions/Row"},{$ref:"#/definitions/ChannelValue"}]},size:{anyOf:[{$ref:"#/definitions/Size"},{$ref:"#/definitions/ChannelValue"}]},spacing:{description:"The size of the gap (1) between tracks, (2) between views, and (3) of the origin of circular tracks. The effect of this property depends on where on the spec you specify the `spacing`.\n\nIn a linear layout, this value is used in pixels, while in a circular layout, this value is used relative to the height of the tracks or views.",type:"number"},startAngle:{description:'Specify the start angle (in the range of [0, 360]) of circular tracks (`{"layout": "circular"}`).',type:"number"},static:{description:"Whether to disable [Zooming and Panning](http://gosling-lang.org/docs/user-interaction#zooming-and-panning), __Default:__ `false`.",type:"boolean"},stretch:{type:"boolean"},stroke:{anyOf:[{$ref:"#/definitions/Stroke"},{$ref:"#/definitions/ChannelValue"}]},strokeWidth:{anyOf:[{$ref:"#/definitions/StrokeWidth"},{$ref:"#/definitions/ChannelValue"}]},style:{$ref:"#/definitions/Style",description:"Define the [style](http://gosling-lang.org/docs/visual-channel#style-related-properties) of multive views. Will be overwritten by the style of children elements (e.g., view, track)."},subtitle:{type:"string"},text:{anyOf:[{$ref:"#/definitions/Text"},{$ref:"#/definitions/ChannelValue"}]},title:{description:"If defined, will show the textual label on the left-top corner of a track.",type:"string"},tooltip:{items:{$ref:"#/definitions/Tooltip"},type:"array"},tracks:{items:{anyOf:[{$ref:"#/definitions/PartialTrack"},{$ref:"#/definitions/OverlaidTracks"}]},type:"array"},visibility:{items:{$ref:"#/definitions/VisibilityCondition"},type:"array"},width:{description:"Specify the track width in pixels.",type:"number"},x:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},x1:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},x1e:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},xAxis:{$ref:"#/definitions/AxisPosition",description:"not supported"},xDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic x-axis"},xOffset:{description:"Specify the x offset of views in the unit of pixels",type:"number"},xe:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},y:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},y1:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},y1e:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},yDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic y-axis"},yOffset:{description:"Specify the y offset of views in the unit of pixels",type:"number"},ye:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},zoomLimits:{$ref:"#/definitions/ZoomLimits"}},required:["tracks"],type:"object"},{additionalProperties:!1,properties:{_assignedHeight:{type:"number"},_assignedWidth:{description:"Internal: Used for responsive spec",type:"number"},assembly:{$ref:"#/definitions/Assembly",description:'A string that specifies the genome builds to use. Currently support `"hg38"`, `"hg19"`, `"hg18"`, `"hg17"`, `"hg16"`, `"mm10"`, `"mm9"`, and `"unknown"`.\n\n__Note:__: with `"unknown"` assembly, genomic axes do not show chrN: in labels.'},centerRadius:{description:"Proportion of the radius of the center white space.\n\n__Default:__ `0.3`",type:"number"},description:{type:"string"},id:{description:"The ID of a view that is maintained for the use of JS API functions, e.g., positions of a view",type:"string"},layout:{$ref:"#/definitions/Layout",description:"Specify the layout type of all tracks."},linkingId:{description:"Specify an ID for [linking multiple views](http://gosling-lang.org/docs/user-interaction#linking-views)",type:"string"},orientation:{$ref:"#/definitions/Orientation",description:"Specify the orientation."},responsiveSize:{$ref:"#/definitions/ResponsiveSize",description:"Determine whether to make the size of `GoslingComponent` bound to its parent element. __Default__: `false`"},responsiveSpec:{items:{additionalProperties:!1,properties:{selectivity:{items:{$ref:"#/definitions/SelectivityCondition"},type:"array"},spec:{additionalProperties:!1,properties:{_assignedHeight:{type:"number"},_assignedWidth:{description:"Internal: Used for responsive spec",type:"number"},_invalidTrack:{description:"internal",type:"boolean"},_renderingId:{description:"internal",type:"string"},alignment:{enum:["overlay","stack"],type:"string"},assembly:{$ref:"#/definitions/Assembly",description:'A string that specifies the genome builds to use. Currently support `"hg38"`, `"hg19"`, `"hg18"`, `"hg17"`, `"hg16"`, `"mm10"`, `"mm9"`, and `"unknown"`.\n\n__Note:__: with `"unknown"` assembly, genomic axes do not show chrN: in labels.'},baselineY:{type:"number"},centerRadius:{description:"Proportion of the radius of the center white space.\n\n__Default:__ `0.3`",type:"number"},color:{anyOf:[{$ref:"#/definitions/Color"},{$ref:"#/definitions/ChannelValue"}]},data:{$ref:"#/definitions/DataDeep"},dataTransform:{items:{$ref:"#/definitions/DataTransform"},type:"array"},displacement:{$ref:"#/definitions/Displacement"},endAngle:{description:'Specify the end angle (in the range of [0, 360]) of circular tracks (`{"layout": "circular"}`).',type:"number"},experimental:{additionalProperties:!1,properties:{mouseEvents:{anyOf:[{type:"boolean"},{$ref:"#/definitions/MouseEventsDeep"}]},performanceMode:{default:!1,description:"Render visual marks with less smooth curves to increase rendering performance. Only supported for `elliptical` `linkStyle` `withinLink` currently.",type:"boolean"}},type:"object"},flipY:{type:"boolean"},height:{description:"Specify the track height in pixels.",type:"number"},id:{description:"The ID of a view that is maintained for the use of JS API functions, e.g., positions of a view",type:"string"},innerRadius:{description:'Specify the inner radius of tracks when (`{"layout": "circular"}`).',type:"number"},layout:{$ref:"#/definitions/Layout",description:"Specify the layout type of all tracks."},linkingId:{description:"Specify an ID for [linking multiple views](http://gosling-lang.org/docs/user-interaction#linking-views)",type:"string"},mark:{$ref:"#/definitions/Mark"},opacity:{anyOf:[{$ref:"#/definitions/Opacity"},{$ref:"#/definitions/ChannelValue"}]},orientation:{$ref:"#/definitions/Orientation",description:"Specify the orientation."},outerRadius:{description:'Specify the outer radius of tracks when `{"layout": "circular"}`.',type:"number"},overlayOnPreviousTrack:{type:"boolean"},overrideTemplate:{type:"boolean"},prerelease:{additionalProperties:!1,description:"internal",type:"object"},row:{anyOf:[{$ref:"#/definitions/Row"},{$ref:"#/definitions/ChannelValue"}]},size:{anyOf:[{$ref:"#/definitions/Size"},{$ref:"#/definitions/ChannelValue"}]},spacing:{description:"The size of the gap (1) between tracks, (2) between views, and (3) of the origin of circular tracks. The effect of this property depends on where on the spec you specify the `spacing`.\n\nIn a linear layout, this value is used in pixels, while in a circular layout, this value is used relative to the height of the tracks or views.",type:"number"},startAngle:{description:'Specify the start angle (in the range of [0, 360]) of circular tracks (`{"layout": "circular"}`).',type:"number"},static:{description:"Whether to disable [Zooming and Panning](http://gosling-lang.org/docs/user-interaction#zooming-and-panning), __Default:__ `false`.",type:"boolean"},stretch:{type:"boolean"},stroke:{anyOf:[{$ref:"#/definitions/Stroke"},{$ref:"#/definitions/ChannelValue"}]},strokeWidth:{anyOf:[{$ref:"#/definitions/StrokeWidth"},{$ref:"#/definitions/ChannelValue"}]},style:{$ref:"#/definitions/Style",description:"Define the [style](http://gosling-lang.org/docs/visual-channel#style-related-properties) of multive views. Will be overwritten by the style of children elements (e.g., view, track)."},subtitle:{type:"string"},text:{anyOf:[{$ref:"#/definitions/Text"},{$ref:"#/definitions/ChannelValue"}]},title:{description:"If defined, will show the textual label on the left-top corner of a track.",type:"string"},tooltip:{items:{$ref:"#/definitions/Tooltip"},type:"array"},tracks:{anyOf:[{items:{$ref:"#/definitions/PartialTrack"},type:"array"},{items:{anyOf:[{$ref:"#/definitions/PartialTrack"},{$ref:"#/definitions/OverlaidTracks"}]},type:"array"}]},visibility:{items:{$ref:"#/definitions/VisibilityCondition"},type:"array"},width:{description:"Specify the track width in pixels.",type:"number"},x:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},x1:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},x1e:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},xAxis:{$ref:"#/definitions/AxisPosition",description:"not supported"},xDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic x-axis"},xOffset:{description:"Specify the x offset of views in the unit of pixels",type:"number"},xe:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},y:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},y1:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},y1e:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},yDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic y-axis"},yOffset:{description:"Specify the y offset of views in the unit of pixels",type:"number"},ye:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},zoomLimits:{$ref:"#/definitions/ZoomLimits"}},type:"object"}},required:["spec","selectivity"],type:"object"},type:"array"},spacing:{description:"The size of the gap (1) between tracks, (2) between views, and (3) of the origin of circular tracks. The effect of this property depends on where on the spec you specify the `spacing`.\n\nIn a linear layout, this value is used in pixels, while in a circular layout, this value is used relative to the height of the tracks or views.",type:"number"},static:{description:"Whether to disable [Zooming and Panning](http://gosling-lang.org/docs/user-interaction#zooming-and-panning), __Default:__ `false`.",type:"boolean"},style:{$ref:"#/definitions/Style",description:"Define the [style](http://gosling-lang.org/docs/visual-channel#style-related-properties) of multive views. Will be overwritten by the style of children elements (e.g., view, track)."},subtitle:{type:"string"},title:{type:"string"},tracks:{items:{$ref:"#/definitions/Track"},type:"array"},xAxis:{$ref:"#/definitions/AxisPosition",description:"not supported"},xDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic x-axis"},xOffset:{description:"Specify the x offset of views in the unit of pixels",type:"number"},yDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic y-axis"},yOffset:{description:"Specify the y offset of views in the unit of pixels",type:"number"},zoomLimits:{$ref:"#/definitions/ZoomLimits"}},required:["tracks"],type:"object"},{additionalProperties:!1,properties:{_assignedHeight:{type:"number"},_assignedWidth:{description:"Internal: Used for responsive spec",type:"number"},arrangement:{description:"Specify how multiple views are arranged.",enum:["parallel","serial","horizontal","vertical"],type:"string"},assembly:{$ref:"#/definitions/Assembly",description:'A string that specifies the genome builds to use. Currently support `"hg38"`, `"hg19"`, `"hg18"`, `"hg17"`, `"hg16"`, `"mm10"`, `"mm9"`, and `"unknown"`.\n\n__Note:__: with `"unknown"` assembly, genomic axes do not show chrN: in labels.'},centerRadius:{description:"Proportion of the radius of the center white space.\n\n__Default:__ `0.3`",type:"number"},description:{type:"string"},id:{description:"The ID of a view that is maintained for the use of JS API functions, e.g., positions of a view",type:"string"},layout:{$ref:"#/definitions/Layout",description:"Specify the layout type of all tracks."},linkingId:{description:"Specify an ID for [linking multiple views](http://gosling-lang.org/docs/user-interaction#linking-views)",type:"string"},orientation:{$ref:"#/definitions/Orientation",description:"Specify the orientation."},responsiveSize:{$ref:"#/definitions/ResponsiveSize",description:"Determine whether to make the size of `GoslingComponent` bound to its parent element. __Default__: `false`"},responsiveSpec:{items:{additionalProperties:!1,properties:{selectivity:{items:{$ref:"#/definitions/SelectivityCondition"},type:"array"},spec:{additionalProperties:!1,properties:{_assignedHeight:{type:"number"},_assignedWidth:{description:"Internal: Used for responsive spec",type:"number"},arrangement:{description:"Specify how multiple views are arranged.",enum:["parallel","serial","horizontal","vertical"],type:"string"},assembly:{$ref:"#/definitions/Assembly",description:'A string that specifies the genome builds to use. Currently support `"hg38"`, `"hg19"`, `"hg18"`, `"hg17"`, `"hg16"`, `"mm10"`, `"mm9"`, and `"unknown"`.\n\n__Note:__: with `"unknown"` assembly, genomic axes do not show chrN: in labels.'},centerRadius:{description:"Proportion of the radius of the center white space.\n\n__Default:__ `0.3`",type:"number"},id:{description:"The ID of a view that is maintained for the use of JS API functions, e.g., positions of a view",type:"string"},layout:{$ref:"#/definitions/Layout",description:"Specify the layout type of all tracks."},linkingId:{description:"Specify an ID for [linking multiple views](http://gosling-lang.org/docs/user-interaction#linking-views)",type:"string"},orientation:{$ref:"#/definitions/Orientation",description:"Specify the orientation."},spacing:{description:"The size of the gap (1) between tracks, (2) between views, and (3) of the origin of circular tracks. The effect of this property depends on where on the spec you specify the `spacing`.\n\nIn a linear layout, this value is used in pixels, while in a circular layout, this value is used relative to the height of the tracks or views.",type:"number"},static:{description:"Whether to disable [Zooming and Panning](http://gosling-lang.org/docs/user-interaction#zooming-and-panning), __Default:__ `false`.",type:"boolean"},style:{$ref:"#/definitions/Style",description:"Define the [style](http://gosling-lang.org/docs/visual-channel#style-related-properties) of multive views. Will be overwritten by the style of children elements (e.g., view, track)."},views:{description:"An array of view specifications",items:{anyOf:[{$ref:"#/definitions/SingleView"},{$ref:"#/definitions/MultipleViews"}]},type:"array"},xAxis:{$ref:"#/definitions/AxisPosition",description:"not supported"},xDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic x-axis"},xOffset:{description:"Specify the x offset of views in the unit of pixels",type:"number"},yDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic y-axis"},yOffset:{description:"Specify the y offset of views in the unit of pixels",type:"number"},zoomLimits:{$ref:"#/definitions/ZoomLimits"}},type:"object"}},required:["spec","selectivity"],type:"object"},type:"array"},spacing:{description:"The size of the gap (1) between tracks, (2) between views, and (3) of the origin of circular tracks. The effect of this property depends on where on the spec you specify the `spacing`.\n\nIn a linear layout, this value is used in pixels, while in a circular layout, this value is used relative to the height of the tracks or views.",type:"number"},static:{description:"Whether to disable [Zooming and Panning](http://gosling-lang.org/docs/user-interaction#zooming-and-panning), __Default:__ `false`.",type:"boolean"},style:{$ref:"#/definitions/Style",description:"Define the [style](http://gosling-lang.org/docs/visual-channel#style-related-properties) of multive views. Will be overwritten by the style of children elements (e.g., view, track)."},subtitle:{type:"string"},title:{type:"string"},views:{description:"An array of view specifications",items:{anyOf:[{$ref:"#/definitions/SingleView"},{$ref:"#/definitions/MultipleViews"}]},type:"array"},xAxis:{$ref:"#/definitions/AxisPosition",description:"not supported"},xDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic x-axis"},xOffset:{description:"Specify the x offset of views in the unit of pixels",type:"number"},yDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic y-axis"},yOffset:{description:"Specify the y offset of views in the unit of pixels",type:"number"},zoomLimits:{$ref:"#/definitions/ZoomLimits"}},required:["views"],type:"object"}]},IncludeFilter:{additionalProperties:!1,properties:{field:{description:"A filter is applied based on the values of the specified data field",type:"string"},include:{description:"Check whether the value includes a substring.",type:"string"},not:{description:'when `{"not": true}`, apply a NOT logical operation to the filter.\n\n__Default:__ `false`',type:"boolean"},type:{const:"filter",type:"string"}},required:["field","include","type"],type:"object"},JsonData:{additionalProperties:!1,description:"The JSON data format allows users to include data directly in the Gosling's JSON specification.",properties:{chromosomeField:{description:"Specify the name of chromosome data fields.",type:"string"},genomicFields:{description:"Specify the name of genomic data fields.",items:{type:"string"},type:"array"},genomicFieldsToConvert:{description:"experimental",items:{additionalProperties:!1,properties:{chromosomeField:{type:"string"},genomicFields:{items:{type:"string"},type:"array"}},required:["chromosomeField","genomicFields"],type:"object"},type:"array"},sampleLength:{description:"Specify the number of rows loaded from the URL.\n\n__Default:__ `1000`",type:"number"},type:{const:"json",description:"Define data type.",type:"string"},values:{description:"Values in the form of JSON.",items:{$ref:"#/definitions/Datum"},type:"array"}},required:["type","values"],type:"object"},JsonParseTransform:{additionalProperties:!1,description:"Parse JSON Object Array and append vertically",properties:{baseGenomicField:{description:"Base genomic position when parsing relative position.",type:"string"},field:{description:"The field that contains the JSON object array.",type:"string"},genomicField:{description:"Relative genomic position to parse.",type:"string"},genomicLengthField:{description:"Length of genomic interval.",type:"string"},type:{const:"subjson",type:"string"}},required:["type","field","baseGenomicField","genomicField","genomicLengthField"],type:"object"},Layout:{enum:["linear","circular"],type:"string"},LogBase:{anyOf:[{type:"number"},{const:"e",type:"string"}]},LogTransform:{additionalProperties:!1,properties:{base:{$ref:"#/definitions/LogBase",description:"If not specified, 10 is used."},field:{type:"string"},newField:{description:"If specified, store transformed values in a new field.",type:"string"},type:{const:"log",type:"string"}},required:["type","field"],type:"object"},LogicalOperation:{enum:["less-than","lt","LT","greater-than","gt","GT","less-than-or-equal-to","ltet","LTET","greater-than-or-equal-to","gtet","GTET"],type:"string"},Mark:{enum:["point","line","area","bar","rect","text","withinLink","betweenLink","rule","triangleLeft","triangleRight","triangleBottom","brush","header"],type:"string"},MatrixData:{additionalProperties:!1,properties:{binSize:{description:"Determine the number of nearby cells to aggregate. __Default__: `1`",type:"number"},column:{description:"The name of the first genomic field. __Default__: `x`",type:"string"},row:{description:"The name of the first genomic field. __Default__: `y`",type:"string"},type:{const:"matrix",type:"string"},url:{description:"URL link to the matrix data file",type:"string"},value:{description:"The name of the value field. __Default__: `value`",type:"string"}},required:["type","url"],type:"object"},MouseEventsDeep:{additionalProperties:!1,description:"Options for determining mouse events in detail, e.g., turning on specific events only",properties:{click:{description:"Whether to enable click events.",type:"boolean"},enableMouseOverOnMultipleMarks:{description:"Determine whether all marks underneath the mouse point should be affected by mouse over. __Default__: `false`",type:"boolean"},groupMarksByField:{description:"Group marks using keys in a data field. This affects how a set of marks are highlighted/selected by interaction. __Default__: `undefined`",type:"string"},mouseOver:{description:"Whether to enable mouseover events.",type:"boolean"},rangeSelect:{description:"Whether to send range selection events.",type:"boolean"}},type:"object"},MultipleViews:{additionalProperties:!1,properties:{_assignedHeight:{type:"number"},_assignedWidth:{description:"Internal: Used for responsive spec",type:"number"},arrangement:{description:"Specify how multiple views are arranged.",enum:["parallel","serial","horizontal","vertical"],type:"string"},assembly:{$ref:"#/definitions/Assembly",description:'A string that specifies the genome builds to use. Currently support `"hg38"`, `"hg19"`, `"hg18"`, `"hg17"`, `"hg16"`, `"mm10"`, `"mm9"`, and `"unknown"`.\n\n__Note:__: with `"unknown"` assembly, genomic axes do not show chrN: in labels.'},centerRadius:{description:"Proportion of the radius of the center white space.\n\n__Default:__ `0.3`",type:"number"},id:{description:"The ID of a view that is maintained for the use of JS API functions, e.g., positions of a view",type:"string"},layout:{$ref:"#/definitions/Layout",description:"Specify the layout type of all tracks."},linkingId:{description:"Specify an ID for [linking multiple views](http://gosling-lang.org/docs/user-interaction#linking-views)",type:"string"},orientation:{$ref:"#/definitions/Orientation",description:"Specify the orientation."},spacing:{description:"The size of the gap (1) between tracks, (2) between views, and (3) of the origin of circular tracks. The effect of this property depends on where on the spec you specify the `spacing`.\n\nIn a linear layout, this value is used in pixels, while in a circular layout, this value is used relative to the height of the tracks or views.",type:"number"},static:{description:"Whether to disable [Zooming and Panning](http://gosling-lang.org/docs/user-interaction#zooming-and-panning), __Default:__ `false`.",type:"boolean"},style:{$ref:"#/definitions/Style",description:"Define the [style](http://gosling-lang.org/docs/visual-channel#style-related-properties) of multive views. Will be overwritten by the style of children elements (e.g., view, track)."},views:{description:"An array of view specifications",items:{anyOf:[{$ref:"#/definitions/SingleView"},{$ref:"#/definitions/MultipleViews"}]},type:"array"},xAxis:{$ref:"#/definitions/AxisPosition",description:"not supported"},xDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic x-axis"},xOffset:{description:"Specify the x offset of views in the unit of pixels",type:"number"},yDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic y-axis"},yOffset:{description:"Specify the y offset of views in the unit of pixels",type:"number"},zoomLimits:{$ref:"#/definitions/ZoomLimits"}},required:["views"],type:"object"},MultivecData:{additionalProperties:!1,description:'Two-dimensional quantitative values, one axis for genomic coordinate and the other for different samples, can be converted into HiGlass\' `"multivec"` data. For example, multiple BigWig files can be converted into a single multivec file. You can also convert sequence data (FASTA) into this format where rows will be different nucleotide bases (e.g., A, T, G, C) and quantitative values represent the frequency. Find out more about this format at [HiGlass Docs](https://docs.higlass.io/data_preparation.html#multivec-files).',properties:{aggregation:{$ref:"#/definitions/BinAggregate",description:'Determine aggregation function to apply within bins. __Default__: `"mean"`'},binSize:{description:"Binning the genomic interval in tiles (unit size: 256).",type:"number"},categories:{description:"assign names of individual samples.",items:{type:"string"},type:"array"},column:{description:'Assign a field name of the middle position of genomic intervals. __Default__: `"position"`',type:"string"},end:{description:'Assign a field name of the end position of genomic intervals. __Default__: `"end"`',type:"string"},row:{description:'Assign a field name of samples. __Default__: `"category"`',type:"string"},start:{description:'Assign a field name of the start position of genomic intervals. __Default__: `"start"`',type:"string"},type:{const:"multivec",type:"string"},url:{description:"Specify the URL address of the data file.",type:"string"},value:{description:'Assign a field name of quantitative values. __Default__: `"value"`',type:"string"}},required:["type","url"],type:"object"},OneOfFilter:{additionalProperties:!1,properties:{field:{description:"A filter is applied based on the values of the specified data field",type:"string"},not:{description:'when `{"not": true}`, apply a NOT logical operation to the filter.\n\n__Default:__ `false`',type:"boolean"},oneOf:{description:"Check whether the value is an element in the provided list.",items:{type:["string","number","null"]},type:"array"},type:{const:"filter",type:"string"}},required:["field","oneOf","type"],type:"object"},Opacity:{additionalProperties:!1,properties:{domain:{$ref:"#/definitions/ValueExtent",description:"Values of the data"},field:{description:"Name of the data field",type:"string"},range:{$ref:"#/definitions/ValueExtent",description:"Ranges of visual channel values"},type:{description:"Specify the data type",enum:["quantitative","nominal"],type:"string"}},type:"object"},Orientation:{enum:["horizontal","vertical"],type:"string"},OverlaidTrack:{additionalProperties:!1,description:"Superposing multiple tracks.",properties:{_assignedHeight:{type:"number"},_assignedWidth:{description:"Internal: Used for responsive spec",type:"number"},_invalidTrack:{description:"internal",type:"boolean"},_overlay:{items:{additionalProperties:!1,properties:{_assignedHeight:{type:"number"},_assignedWidth:{description:"Internal: Used for responsive spec",type:"number"},_invalidTrack:{description:"internal",type:"boolean"},_renderingId:{description:"internal",type:"string"},assembly:{$ref:"#/definitions/Assembly",description:'A string that specifies the genome builds to use. Currently support `"hg38"`, `"hg19"`, `"hg18"`, `"hg17"`, `"hg16"`, `"mm10"`, `"mm9"`, and `"unknown"`.\n\n__Note:__: with `"unknown"` assembly, genomic axes do not show chrN: in labels.'},baselineY:{type:"number"},centerRadius:{description:"Proportion of the radius of the center white space.\n\n__Default:__ `0.3`",type:"number"},color:{anyOf:[{$ref:"#/definitions/Color"},{$ref:"#/definitions/ChannelValue"}]},data:{$ref:"#/definitions/DataDeep"},dataTransform:{items:{$ref:"#/definitions/DataTransform"},type:"array"},displacement:{$ref:"#/definitions/Displacement"},endAngle:{description:'Specify the end angle (in the range of [0, 360]) of circular tracks (`{"layout": "circular"}`).',type:"number"},experimental:{additionalProperties:!1,properties:{mouseEvents:{anyOf:[{type:"boolean"},{$ref:"#/definitions/MouseEventsDeep"}]},performanceMode:{default:!1,description:"Render visual marks with less smooth curves to increase rendering performance. Only supported for `elliptical` `linkStyle` `withinLink` currently.",type:"boolean"}},type:"object"},flipY:{type:"boolean"},id:{description:"Assigned to `uid` in a HiGlass view config, used for API and caching.",type:"string"},innerRadius:{description:'Specify the inner radius of tracks when (`{"layout": "circular"}`).',type:"number"},linkingId:{description:"Specify an ID for [linking multiple views](http://gosling-lang.org/docs/user-interaction#linking-views)",type:"string"},mark:{$ref:"#/definitions/Mark"},opacity:{anyOf:[{$ref:"#/definitions/Opacity"},{$ref:"#/definitions/ChannelValue"}]},orientation:{$ref:"#/definitions/Orientation",description:"Specify the orientation."},outerRadius:{description:'Specify the outer radius of tracks when `{"layout": "circular"}`.',type:"number"},overlayOnPreviousTrack:{type:"boolean"},overrideTemplate:{type:"boolean"},prerelease:{additionalProperties:!1,description:"internal",type:"object"},row:{anyOf:[{$ref:"#/definitions/Row"},{$ref:"#/definitions/ChannelValue"}]},size:{anyOf:[{$ref:"#/definitions/Size"},{$ref:"#/definitions/ChannelValue"}]},spacing:{description:"The size of the gap (1) between tracks, (2) between views, and (3) of the origin of circular tracks. The effect of this property depends on where on the spec you specify the `spacing`.\n\nIn a linear layout, this value is used in pixels, while in a circular layout, this value is used relative to the height of the tracks or views.",type:"number"},startAngle:{description:'Specify the start angle (in the range of [0, 360]) of circular tracks (`{"layout": "circular"}`).',type:"number"},static:{description:"Whether to disable [Zooming and Panning](http://gosling-lang.org/docs/user-interaction#zooming-and-panning), __Default:__ `false`.",type:"boolean"},stretch:{type:"boolean"},stroke:{anyOf:[{$ref:"#/definitions/Stroke"},{$ref:"#/definitions/ChannelValue"}]},strokeWidth:{anyOf:[{$ref:"#/definitions/StrokeWidth"},{$ref:"#/definitions/ChannelValue"}]},style:{$ref:"#/definitions/Style",description:"Define the [style](http://gosling-lang.org/docs/visual-channel#style-related-properties) of multive views. Will be overwritten by the style of children elements (e.g., view, track)."},text:{anyOf:[{$ref:"#/definitions/Text"},{$ref:"#/definitions/ChannelValue"}]},tooltip:{items:{$ref:"#/definitions/Tooltip"},type:"array"},visibility:{items:{$ref:"#/definitions/VisibilityCondition"},type:"array"},x:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},x1:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},x1e:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},xAxis:{$ref:"#/definitions/AxisPosition",description:"not supported"},xDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic x-axis"},xOffset:{description:"Specify the x offset of views in the unit of pixels",type:"number"},xe:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},y:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},y1:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},y1e:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},yDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic y-axis"},yOffset:{description:"Specify the y offset of views in the unit of pixels",type:"number"},ye:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},zoomLimits:{$ref:"#/definitions/ZoomLimits"}},type:"object"},type:"array"},_renderingId:{description:"internal",type:"string"},assembly:{$ref:"#/definitions/Assembly",description:'A string that specifies the genome builds to use. Currently support `"hg38"`, `"hg19"`, `"hg18"`, `"hg17"`, `"hg16"`, `"mm10"`, `"mm9"`, and `"unknown"`.\n\n__Note:__: with `"unknown"` assembly, genomic axes do not show chrN: in labels.'},baselineY:{type:"number"},centerRadius:{description:"Proportion of the radius of the center white space.\n\n__Default:__ `0.3`",type:"number"},color:{anyOf:[{$ref:"#/definitions/Color"},{$ref:"#/definitions/ChannelValue"}]},data:{$ref:"#/definitions/DataDeep"},dataTransform:{items:{$ref:"#/definitions/DataTransform"},type:"array"},displacement:{$ref:"#/definitions/Displacement"},endAngle:{description:'Specify the end angle (in the range of [0, 360]) of circular tracks (`{"layout": "circular"}`).',type:"number"},experimental:{additionalProperties:!1,properties:{mouseEvents:{anyOf:[{type:"boolean"},{$ref:"#/definitions/MouseEventsDeep"}]},performanceMode:{default:!1,description:"Render visual marks with less smooth curves to increase rendering performance. Only supported for `elliptical` `linkStyle` `withinLink` currently.",type:"boolean"}},type:"object"},flipY:{type:"boolean"},height:{description:"Specify the track height in pixels.",type:"number"},id:{description:"Assigned to `uid` in a HiGlass view config, used for API and caching.",type:"string"},innerRadius:{description:'Specify the inner radius of tracks when (`{"layout": "circular"}`).',type:"number"},layout:{$ref:"#/definitions/Layout",description:"Specify the layout type of all tracks."},linkingId:{description:"Specify an ID for [linking multiple views](http://gosling-lang.org/docs/user-interaction#linking-views)",type:"string"},mark:{$ref:"#/definitions/Mark"},opacity:{anyOf:[{$ref:"#/definitions/Opacity"},{$ref:"#/definitions/ChannelValue"}]},orientation:{$ref:"#/definitions/Orientation",description:"Specify the orientation."},outerRadius:{description:'Specify the outer radius of tracks when `{"layout": "circular"}`.',type:"number"},overlayOnPreviousTrack:{type:"boolean"},overrideTemplate:{type:"boolean"},prerelease:{additionalProperties:!1,description:"internal",type:"object"},row:{anyOf:[{$ref:"#/definitions/Row"},{$ref:"#/definitions/ChannelValue"}]},size:{anyOf:[{$ref:"#/definitions/Size"},{$ref:"#/definitions/ChannelValue"}]},spacing:{description:"The size of the gap (1) between tracks, (2) between views, and (3) of the origin of circular tracks. The effect of this property depends on where on the spec you specify the `spacing`.\n\nIn a linear layout, this value is used in pixels, while in a circular layout, this value is used relative to the height of the tracks or views.",type:"number"},startAngle:{description:'Specify the start angle (in the range of [0, 360]) of circular tracks (`{"layout": "circular"}`).',type:"number"},static:{description:"Whether to disable [Zooming and Panning](http://gosling-lang.org/docs/user-interaction#zooming-and-panning), __Default:__ `false`.",type:"boolean"},stretch:{type:"boolean"},stroke:{anyOf:[{$ref:"#/definitions/Stroke"},{$ref:"#/definitions/ChannelValue"}]},strokeWidth:{anyOf:[{$ref:"#/definitions/StrokeWidth"},{$ref:"#/definitions/ChannelValue"}]},style:{$ref:"#/definitions/Style",description:"Define the [style](http://gosling-lang.org/docs/visual-channel#style-related-properties) of multive views. Will be overwritten by the style of children elements (e.g., view, track)."},subtitle:{type:"string"},text:{anyOf:[{$ref:"#/definitions/Text"},{$ref:"#/definitions/ChannelValue"}]},title:{description:"If defined, will show the textual label on the left-top corner of a track.",type:"string"},tooltip:{items:{$ref:"#/definitions/Tooltip"},type:"array"},visibility:{items:{$ref:"#/definitions/VisibilityCondition"},type:"array"},width:{description:"Specify the track width in pixels.",type:"number"},x:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},x1:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},x1e:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},xAxis:{$ref:"#/definitions/AxisPosition",description:"not supported"},xDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic x-axis"},xOffset:{description:"Specify the x offset of views in the unit of pixels",type:"number"},xe:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},y:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},y1:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},y1e:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},yDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic y-axis"},yOffset:{description:"Specify the y offset of views in the unit of pixels",type:"number"},ye:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},zoomLimits:{$ref:"#/definitions/ZoomLimits"}},required:["_overlay"],type:"object"},OverlaidTracks:{additionalProperties:!1,properties:{_assignedHeight:{type:"number"},_assignedWidth:{description:"Internal: Used for responsive spec",type:"number"},_invalidTrack:{description:"internal",type:"boolean"},_renderingId:{description:"internal",type:"string"},alignment:{const:"overlay",type:"string"},assembly:{$ref:"#/definitions/Assembly",description:'A string that specifies the genome builds to use. Currently support `"hg38"`, `"hg19"`, `"hg18"`, `"hg17"`, `"hg16"`, `"mm10"`, `"mm9"`, and `"unknown"`.\n\n__Note:__: with `"unknown"` assembly, genomic axes do not show chrN: in labels.'},baselineY:{type:"number"},centerRadius:{description:"Proportion of the radius of the center white space.\n\n__Default:__ `0.3`",type:"number"},color:{anyOf:[{$ref:"#/definitions/Color"},{$ref:"#/definitions/ChannelValue"}]},data:{$ref:"#/definitions/DataDeep"},dataTransform:{items:{$ref:"#/definitions/DataTransform"},type:"array"},displacement:{$ref:"#/definitions/Displacement"},endAngle:{description:'Specify the end angle (in the range of [0, 360]) of circular tracks (`{"layout": "circular"}`).',type:"number"},experimental:{additionalProperties:!1,properties:{mouseEvents:{anyOf:[{type:"boolean"},{$ref:"#/definitions/MouseEventsDeep"}]},performanceMode:{default:!1,description:"Render visual marks with less smooth curves to increase rendering performance. Only supported for `elliptical` `linkStyle` `withinLink` currently.",type:"boolean"}},type:"object"},flipY:{type:"boolean"},height:{description:"Specify the track height in pixels.",type:"number"},id:{description:"The ID of a view that is maintained for the use of JS API functions, e.g., positions of a view",type:"string"},innerRadius:{description:'Specify the inner radius of tracks when (`{"layout": "circular"}`).',type:"number"},layout:{$ref:"#/definitions/Layout",description:"Specify the layout type of all tracks."},linkingId:{description:"Specify an ID for [linking multiple views](http://gosling-lang.org/docs/user-interaction#linking-views)",type:"string"},mark:{$ref:"#/definitions/Mark"},opacity:{anyOf:[{$ref:"#/definitions/Opacity"},{$ref:"#/definitions/ChannelValue"}]},orientation:{$ref:"#/definitions/Orientation",description:"Specify the orientation."},outerRadius:{description:'Specify the outer radius of tracks when `{"layout": "circular"}`.',type:"number"},overlayOnPreviousTrack:{type:"boolean"},overrideTemplate:{type:"boolean"},prerelease:{additionalProperties:!1,description:"internal",type:"object"},row:{anyOf:[{$ref:"#/definitions/Row"},{$ref:"#/definitions/ChannelValue"}]},size:{anyOf:[{$ref:"#/definitions/Size"},{$ref:"#/definitions/ChannelValue"}]},spacing:{description:"The size of the gap (1) between tracks, (2) between views, and (3) of the origin of circular tracks. The effect of this property depends on where on the spec you specify the `spacing`.\n\nIn a linear layout, this value is used in pixels, while in a circular layout, this value is used relative to the height of the tracks or views.",type:"number"},startAngle:{description:'Specify the start angle (in the range of [0, 360]) of circular tracks (`{"layout": "circular"}`).',type:"number"},static:{description:"Whether to disable [Zooming and Panning](http://gosling-lang.org/docs/user-interaction#zooming-and-panning), __Default:__ `false`.",type:"boolean"},stretch:{type:"boolean"},stroke:{anyOf:[{$ref:"#/definitions/Stroke"},{$ref:"#/definitions/ChannelValue"}]},strokeWidth:{anyOf:[{$ref:"#/definitions/StrokeWidth"},{$ref:"#/definitions/ChannelValue"}]},style:{$ref:"#/definitions/Style",description:"Define the [style](http://gosling-lang.org/docs/visual-channel#style-related-properties) of multive views. Will be overwritten by the style of children elements (e.g., view, track)."},subtitle:{type:"string"},text:{anyOf:[{$ref:"#/definitions/Text"},{$ref:"#/definitions/ChannelValue"}]},title:{description:"If defined, will show the textual label on the left-top corner of a track.",type:"string"},tooltip:{items:{$ref:"#/definitions/Tooltip"},type:"array"},tracks:{items:{$ref:"#/definitions/PartialTrack"},type:"array"},visibility:{items:{$ref:"#/definitions/VisibilityCondition"},type:"array"},width:{description:"Specify the track width in pixels.",type:"number"},x:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},x1:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},x1e:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},xAxis:{$ref:"#/definitions/AxisPosition",description:"not supported"},xDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic x-axis"},xOffset:{description:"Specify the x offset of views in the unit of pixels",type:"number"},xe:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},y:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},y1:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},y1e:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},yDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic y-axis"},yOffset:{description:"Specify the y offset of views in the unit of pixels",type:"number"},ye:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},zoomLimits:{$ref:"#/definitions/ZoomLimits"}},required:["alignment","tracks"],type:"object"},PartialTrack:{additionalProperties:!1,properties:{_assignedHeight:{type:"number"},_assignedWidth:{description:"Internal: Used for responsive spec",type:"number"},_invalidTrack:{description:"internal",type:"boolean"},_overlay:{items:{additionalProperties:!1,properties:{_assignedHeight:{type:"number"},_assignedWidth:{description:"Internal: Used for responsive spec",type:"number"},_invalidTrack:{description:"internal",type:"boolean"},_renderingId:{description:"internal",type:"string"},assembly:{$ref:"#/definitions/Assembly",description:'A string that specifies the genome builds to use. Currently support `"hg38"`, `"hg19"`, `"hg18"`, `"hg17"`, `"hg16"`, `"mm10"`, `"mm9"`, and `"unknown"`.\n\n__Note:__: with `"unknown"` assembly, genomic axes do not show chrN: in labels.'},baselineY:{type:"number"},centerRadius:{description:"Proportion of the radius of the center white space.\n\n__Default:__ `0.3`",type:"number"},color:{anyOf:[{$ref:"#/definitions/Color"},{$ref:"#/definitions/ChannelValue"}]},data:{$ref:"#/definitions/DataDeep"},dataTransform:{items:{$ref:"#/definitions/DataTransform"},type:"array"},displacement:{$ref:"#/definitions/Displacement"},endAngle:{description:'Specify the end angle (in the range of [0, 360]) of circular tracks (`{"layout": "circular"}`).',type:"number"},experimental:{additionalProperties:!1,properties:{mouseEvents:{anyOf:[{type:"boolean"},{$ref:"#/definitions/MouseEventsDeep"}]},performanceMode:{default:!1,description:"Render visual marks with less smooth curves to increase rendering performance. Only supported for `elliptical` `linkStyle` `withinLink` currently.",type:"boolean"}},type:"object"},flipY:{type:"boolean"},id:{description:"Assigned to `uid` in a HiGlass view config, used for API and caching.",type:"string"},innerRadius:{description:'Specify the inner radius of tracks when (`{"layout": "circular"}`).',type:"number"},linkingId:{description:"Specify an ID for [linking multiple views](http://gosling-lang.org/docs/user-interaction#linking-views)",type:"string"},mark:{$ref:"#/definitions/Mark"},opacity:{anyOf:[{$ref:"#/definitions/Opacity"},{$ref:"#/definitions/ChannelValue"}]},orientation:{$ref:"#/definitions/Orientation",description:"Specify the orientation."},outerRadius:{description:'Specify the outer radius of tracks when `{"layout": "circular"}`.',type:"number"},overlayOnPreviousTrack:{type:"boolean"},overrideTemplate:{type:"boolean"},prerelease:{additionalProperties:!1,description:"internal",type:"object"},row:{anyOf:[{$ref:"#/definitions/Row"},{$ref:"#/definitions/ChannelValue"}]},size:{anyOf:[{$ref:"#/definitions/Size"},{$ref:"#/definitions/ChannelValue"}]},spacing:{description:"The size of the gap (1) between tracks, (2) between views, and (3) of the origin of circular tracks. The effect of this property depends on where on the spec you specify the `spacing`.\n\nIn a linear layout, this value is used in pixels, while in a circular layout, this value is used relative to the height of the tracks or views.",type:"number"},startAngle:{description:'Specify the start angle (in the range of [0, 360]) of circular tracks (`{"layout": "circular"}`).',type:"number"},static:{description:"Whether to disable [Zooming and Panning](http://gosling-lang.org/docs/user-interaction#zooming-and-panning), __Default:__ `false`.",type:"boolean"},stretch:{type:"boolean"},stroke:{anyOf:[{$ref:"#/definitions/Stroke"},{$ref:"#/definitions/ChannelValue"}]},strokeWidth:{anyOf:[{$ref:"#/definitions/StrokeWidth"},{$ref:"#/definitions/ChannelValue"}]},style:{$ref:"#/definitions/Style",description:"Define the [style](http://gosling-lang.org/docs/visual-channel#style-related-properties) of multive views. Will be overwritten by the style of children elements (e.g., view, track)."},text:{anyOf:[{$ref:"#/definitions/Text"},{$ref:"#/definitions/ChannelValue"}]},tooltip:{items:{$ref:"#/definitions/Tooltip"},type:"array"},visibility:{items:{$ref:"#/definitions/VisibilityCondition"},type:"array"},x:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},x1:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},x1e:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},xAxis:{$ref:"#/definitions/AxisPosition",description:"not supported"},xDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic x-axis"},xOffset:{description:"Specify the x offset of views in the unit of pixels",type:"number"},xe:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},y:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},y1:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},y1e:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},yDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic y-axis"},yOffset:{description:"Specify the y offset of views in the unit of pixels",type:"number"},ye:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},zoomLimits:{$ref:"#/definitions/ZoomLimits"}},type:"object"},type:"array"},_renderingId:{description:"internal",type:"string"},assembly:{anyOf:[{$ref:"#/definitions/Assembly",description:'A string that specifies the genome builds to use. Currently support `"hg38"`, `"hg19"`, `"hg18"`, `"hg17"`, `"hg16"`, `"mm10"`, `"mm9"`, and `"unknown"`.\n\n__Note:__: with `"unknown"` assembly, genomic axes do not show chrN: in labels.'},{const:"unknown",description:"No assemblies can be associated with a dummy track",type:"string"}],description:'A string that specifies the genome builds to use. Currently support `"hg38"`, `"hg19"`, `"hg18"`, `"hg17"`, `"hg16"`, `"mm10"`, `"mm9"`, and `"unknown"`.\n\n__Note:__: with `"unknown"` assembly, genomic axes do not show chrN: in labels.'},baselineY:{type:"number"},centerRadius:{description:"Proportion of the radius of the center white space.\n\n__Default:__ `0.3`",type:"number"},color:{anyOf:[{$ref:"#/definitions/Color"},{$ref:"#/definitions/ChannelValue"}]},data:{$ref:"#/definitions/DataDeep"},dataTransform:{items:{$ref:"#/definitions/DataTransform"},type:"array"},displacement:{$ref:"#/definitions/Displacement"},encoding:{additionalProperties:{$ref:"#/definitions/Channel"},type:"object"},endAngle:{description:'Specify the end angle (in the range of [0, 360]) of circular tracks (`{"layout": "circular"}`).',type:"number"},experimental:{additionalProperties:!1,properties:{mouseEvents:{anyOf:[{type:"boolean"},{$ref:"#/definitions/MouseEventsDeep"}]},performanceMode:{default:!1,description:"Render visual marks with less smooth curves to increase rendering performance. Only supported for `elliptical` `linkStyle` `withinLink` currently.",type:"boolean"}},type:"object"},flipY:{type:"boolean"},height:{description:"Specify the track height in pixels.",type:"number"},id:{description:"Assigned to `uid` in a HiGlass view config, used for API and caching.",type:"string"},innerRadius:{description:'Specify the inner radius of tracks when (`{"layout": "circular"}`).',type:"number"},layout:{anyOf:[{$ref:"#/definitions/Layout",description:"Specify the layout type of all tracks."},{const:"linear",description:"Only linear layout are supported at this time",type:"string"}],description:"Specify the layout type of all tracks."},linkingId:{description:"Specify an ID for [linking multiple views](http://gosling-lang.org/docs/user-interaction#linking-views)",type:"string"},mark:{$ref:"#/definitions/Mark"},opacity:{anyOf:[{$ref:"#/definitions/Opacity"},{$ref:"#/definitions/ChannelValue"}]},orientation:{$ref:"#/definitions/Orientation",description:"Specify the orientation."},outerRadius:{description:'Specify the outer radius of tracks when `{"layout": "circular"}`.',type:"number"},overlayOnPreviousTrack:{type:"boolean"},overrideTemplate:{type:"boolean"},prerelease:{additionalProperties:!1,description:"internal",type:"object"},row:{anyOf:[{$ref:"#/definitions/Row"},{$ref:"#/definitions/ChannelValue"}]},size:{anyOf:[{$ref:"#/definitions/Size"},{$ref:"#/definitions/ChannelValue"}]},spacing:{description:"The size of the gap (1) between tracks, (2) between views, and (3) of the origin of circular tracks. The effect of this property depends on where on the spec you specify the `spacing`.\n\nIn a linear layout, this value is used in pixels, while in a circular layout, this value is used relative to the height of the tracks or views.",type:"number"},startAngle:{description:'Specify the start angle (in the range of [0, 360]) of circular tracks (`{"layout": "circular"}`).',type:"number"},static:{anyOf:[{description:"Whether to disable [Zooming and Panning](http://gosling-lang.org/docs/user-interaction#zooming-and-panning), __Default:__ `false`.",type:"boolean"},{const:!0,description:"Whether to disable [Zooming and Panning](http://gosling-lang.org/docs/user-interaction#zooming-and-panning), __Default:__ `false`.",type:"boolean"}],description:"Whether to disable [Zooming and Panning](http://gosling-lang.org/docs/user-interaction#zooming-and-panning), __Default:__ `false`."},stretch:{type:"boolean"},stroke:{anyOf:[{$ref:"#/definitions/Stroke"},{$ref:"#/definitions/ChannelValue"}]},strokeWidth:{anyOf:[{$ref:"#/definitions/StrokeWidth"},{$ref:"#/definitions/ChannelValue"}]},style:{anyOf:[{$ref:"#/definitions/Style",description:"Define the [style](http://gosling-lang.org/docs/visual-channel#style-related-properties) of multive views. Will be overwritten by the style of children elements (e.g., view, track)."},{$ref:"#/definitions/DummyTrackStyle",description:"Defines how the track is styled"}],description:"Define the [style](http://gosling-lang.org/docs/visual-channel#style-related-properties) of multive views. Will be overwritten by the style of children elements (e.g., view, track)."},subtitle:{type:"string"},template:{type:"string"},text:{anyOf:[{$ref:"#/definitions/Text"},{$ref:"#/definitions/ChannelValue"}]},title:{description:"If defined, will show the textual label on the left-top corner of a track.",type:"string"},tooltip:{items:{$ref:"#/definitions/Tooltip"},type:"array"},type:{const:"dummy-track",description:"Used to specify the dummy track",type:"string"},visibility:{items:{$ref:"#/definitions/VisibilityCondition"},type:"array"},width:{description:"Specify the track width in pixels.",type:"number"},x:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},x1:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},x1e:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},xAxis:{$ref:"#/definitions/AxisPosition",description:"not supported"},xDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic x-axis"},xOffset:{description:"Specify the x offset of views in the unit of pixels",type:"number"},xe:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},y:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},y1:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},y1e:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},yDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic y-axis"},yOffset:{description:"Specify the y offset of views in the unit of pixels",type:"number"},ye:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},zoomLimits:{anyOf:[{$ref:"#/definitions/ZoomLimits"},{description:"Unused property for DummyTrack",items:{type:"null"},maxItems:2,minItems:2,type:"array"}]}},type:"object"},PredefinedColors:{enum:["viridis","grey","spectral","warm","cividis","bupu","rdbu","hot","pink"],type:"string"},Range:{anyOf:[{$ref:"#/definitions/ValueExtent"},{$ref:"#/definitions/PredefinedColors"}]},RangeFilter:{additionalProperties:!1,properties:{field:{description:"A filter is applied based on the values of the specified data field",type:"string"},inRange:{description:"Check whether the value is in a number range.",items:{type:"number"},type:"array"},not:{description:'when `{"not": true}`, apply a NOT logical operation to the filter.\n\n__Default:__ `false`',type:"boolean"},type:{const:"filter",type:"string"}},required:["field","inRange","type"],type:"object"},ResponsiveSize:{anyOf:[{type:"boolean"},{additionalProperties:!1,properties:{height:{type:"boolean"},width:{type:"boolean"}},type:"object"}]},Row:{additionalProperties:!1,properties:{clip:{description:"Clip row when the actual y value exceeds the max value of the y scale. Used only for bar marks at the moment. __Default__: `true`",type:"boolean"},domain:{$ref:"#/definitions/ValueExtent",description:"Values of the data"},field:{description:"Name of the data field",type:"string"},grid:{description:"Whether to display grid. __Default__: `false`",type:"boolean"},legend:{description:"Whether to display legend. __Default__: `false`",type:"boolean"},padding:{description:"Determines the size of inner white spaces on the top and bottom of individiual rows. __Default__: `0`",type:"number"},range:{$ref:"#/definitions/ValueExtent",description:"Determine the start and end position of rendering area of this track along vertical axis. __Default__: `[0, height]`"},type:{const:"nominal",description:"Specify the data type",type:"string"}},type:"object"},SelectivityCondition:{additionalProperties:!1,properties:{measure:{enum:["width","height","aspectRatio"],type:"string"},operation:{$ref:"#/definitions/LogicalOperation"},target:{description:"Does the condition applied to the visualization itself or its container? __Default__: `'self'`",enum:["self","container"],type:"string"},threshold:{description:"Threshold in the unit of pixels.",type:"number"}},required:["operation","measure","threshold"],type:"object"},SingleTrack:{additionalProperties:!1,properties:{_assignedHeight:{type:"number"},_assignedWidth:{description:"Internal: Used for responsive spec",type:"number"},_invalidTrack:{description:"internal",type:"boolean"},_renderingId:{description:"internal",type:"string"},assembly:{$ref:"#/definitions/Assembly",description:'A string that specifies the genome builds to use. Currently support `"hg38"`, `"hg19"`, `"hg18"`, `"hg17"`, `"hg16"`, `"mm10"`, `"mm9"`, and `"unknown"`.\n\n__Note:__: with `"unknown"` assembly, genomic axes do not show chrN: in labels.'},baselineY:{type:"number"},centerRadius:{description:"Proportion of the radius of the center white space.\n\n__Default:__ `0.3`",type:"number"},color:{anyOf:[{$ref:"#/definitions/Color"},{$ref:"#/definitions/ChannelValue"}]},data:{$ref:"#/definitions/DataDeep"},dataTransform:{items:{$ref:"#/definitions/DataTransform"},type:"array"},displacement:{$ref:"#/definitions/Displacement"},endAngle:{description:'Specify the end angle (in the range of [0, 360]) of circular tracks (`{"layout": "circular"}`).',type:"number"},experimental:{additionalProperties:!1,properties:{mouseEvents:{anyOf:[{type:"boolean"},{$ref:"#/definitions/MouseEventsDeep"}]},performanceMode:{default:!1,description:"Render visual marks with less smooth curves to increase rendering performance. Only supported for `elliptical` `linkStyle` `withinLink` currently.",type:"boolean"}},type:"object"},flipY:{type:"boolean"},height:{description:"Specify the track height in pixels.",type:"number"},id:{description:"Assigned to `uid` in a HiGlass view config, used for API and caching.",type:"string"},innerRadius:{description:'Specify the inner radius of tracks when (`{"layout": "circular"}`).',type:"number"},layout:{$ref:"#/definitions/Layout",description:"Specify the layout type of all tracks."},linkingId:{description:"Specify an ID for [linking multiple views](http://gosling-lang.org/docs/user-interaction#linking-views)",type:"string"},mark:{$ref:"#/definitions/Mark"},opacity:{anyOf:[{$ref:"#/definitions/Opacity"},{$ref:"#/definitions/ChannelValue"}]},orientation:{$ref:"#/definitions/Orientation",description:"Specify the orientation."},outerRadius:{description:'Specify the outer radius of tracks when `{"layout": "circular"}`.',type:"number"},overlayOnPreviousTrack:{type:"boolean"},overrideTemplate:{type:"boolean"},prerelease:{additionalProperties:!1,description:"internal",type:"object"},row:{anyOf:[{$ref:"#/definitions/Row"},{$ref:"#/definitions/ChannelValue"}]},size:{anyOf:[{$ref:"#/definitions/Size"},{$ref:"#/definitions/ChannelValue"}]},spacing:{description:"The size of the gap (1) between tracks, (2) between views, and (3) of the origin of circular tracks. The effect of this property depends on where on the spec you specify the `spacing`.\n\nIn a linear layout, this value is used in pixels, while in a circular layout, this value is used relative to the height of the tracks or views.",type:"number"},startAngle:{description:'Specify the start angle (in the range of [0, 360]) of circular tracks (`{"layout": "circular"}`).',type:"number"},static:{description:"Whether to disable [Zooming and Panning](http://gosling-lang.org/docs/user-interaction#zooming-and-panning), __Default:__ `false`.",type:"boolean"},stretch:{type:"boolean"},stroke:{anyOf:[{$ref:"#/definitions/Stroke"},{$ref:"#/definitions/ChannelValue"}]},strokeWidth:{anyOf:[{$ref:"#/definitions/StrokeWidth"},{$ref:"#/definitions/ChannelValue"}]},style:{$ref:"#/definitions/Style",description:"Define the [style](http://gosling-lang.org/docs/visual-channel#style-related-properties) of multive views. Will be overwritten by the style of children elements (e.g., view, track)."},subtitle:{type:"string"},text:{anyOf:[{$ref:"#/definitions/Text"},{$ref:"#/definitions/ChannelValue"}]},title:{description:"If defined, will show the textual label on the left-top corner of a track.",type:"string"},tooltip:{items:{$ref:"#/definitions/Tooltip"},type:"array"},visibility:{items:{$ref:"#/definitions/VisibilityCondition"},type:"array"},width:{description:"Specify the track width in pixels.",type:"number"},x:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},x1:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},x1e:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},xAxis:{$ref:"#/definitions/AxisPosition",description:"not supported"},xDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic x-axis"},xOffset:{description:"Specify the x offset of views in the unit of pixels",type:"number"},xe:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},y:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},y1:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},y1e:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},yDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic y-axis"},yOffset:{description:"Specify the y offset of views in the unit of pixels",type:"number"},ye:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},zoomLimits:{$ref:"#/definitions/ZoomLimits"}},required:["data","mark"],type:"object"},SingleView:{anyOf:[{additionalProperties:!1,properties:{_assignedHeight:{type:"number"},_assignedWidth:{description:"Internal: Used for responsive spec",type:"number"},_invalidTrack:{description:"internal",type:"boolean"},_renderingId:{description:"internal",type:"string"},alignment:{const:"overlay",type:"string"},assembly:{$ref:"#/definitions/Assembly",description:'A string that specifies the genome builds to use. Currently support `"hg38"`, `"hg19"`, `"hg18"`, `"hg17"`, `"hg16"`, `"mm10"`, `"mm9"`, and `"unknown"`.\n\n__Note:__: with `"unknown"` assembly, genomic axes do not show chrN: in labels.'},baselineY:{type:"number"},centerRadius:{description:"Proportion of the radius of the center white space.\n\n__Default:__ `0.3`",type:"number"},color:{anyOf:[{$ref:"#/definitions/Color"},{$ref:"#/definitions/ChannelValue"}]},data:{$ref:"#/definitions/DataDeep"},dataTransform:{items:{$ref:"#/definitions/DataTransform"},type:"array"},displacement:{$ref:"#/definitions/Displacement"},endAngle:{description:'Specify the end angle (in the range of [0, 360]) of circular tracks (`{"layout": "circular"}`).',type:"number"},experimental:{additionalProperties:!1,properties:{mouseEvents:{anyOf:[{type:"boolean"},{$ref:"#/definitions/MouseEventsDeep"}]},performanceMode:{default:!1,description:"Render visual marks with less smooth curves to increase rendering performance. Only supported for `elliptical` `linkStyle` `withinLink` currently.",type:"boolean"}},type:"object"},flipY:{type:"boolean"},height:{description:"Specify the track height in pixels.",type:"number"},id:{description:"The ID of a view that is maintained for the use of JS API functions, e.g., positions of a view",type:"string"},innerRadius:{description:'Specify the inner radius of tracks when (`{"layout": "circular"}`).',type:"number"},layout:{$ref:"#/definitions/Layout",description:"Specify the layout type of all tracks."},linkingId:{description:"Specify an ID for [linking multiple views](http://gosling-lang.org/docs/user-interaction#linking-views)",type:"string"},mark:{$ref:"#/definitions/Mark"},opacity:{anyOf:[{$ref:"#/definitions/Opacity"},{$ref:"#/definitions/ChannelValue"}]},orientation:{$ref:"#/definitions/Orientation",description:"Specify the orientation."},outerRadius:{description:'Specify the outer radius of tracks when `{"layout": "circular"}`.',type:"number"},overlayOnPreviousTrack:{type:"boolean"},overrideTemplate:{type:"boolean"},prerelease:{additionalProperties:!1,description:"internal",type:"object"},responsiveSpec:{items:{additionalProperties:!1,properties:{selectivity:{items:{$ref:"#/definitions/SelectivityCondition"},type:"array"},spec:{additionalProperties:!1,properties:{_assignedHeight:{type:"number"},_assignedWidth:{description:"Internal: Used for responsive spec",type:"number"},_invalidTrack:{description:"internal",type:"boolean"},_renderingId:{description:"internal",type:"string"},alignment:{enum:["overlay","stack"],type:"string"},assembly:{$ref:"#/definitions/Assembly",description:'A string that specifies the genome builds to use. Currently support `"hg38"`, `"hg19"`, `"hg18"`, `"hg17"`, `"hg16"`, `"mm10"`, `"mm9"`, and `"unknown"`.\n\n__Note:__: with `"unknown"` assembly, genomic axes do not show chrN: in labels.'},baselineY:{type:"number"},centerRadius:{description:"Proportion of the radius of the center white space.\n\n__Default:__ `0.3`",type:"number"},color:{anyOf:[{$ref:"#/definitions/Color"},{$ref:"#/definitions/ChannelValue"}]},data:{$ref:"#/definitions/DataDeep"},dataTransform:{items:{$ref:"#/definitions/DataTransform"},type:"array"},displacement:{$ref:"#/definitions/Displacement"},endAngle:{description:'Specify the end angle (in the range of [0, 360]) of circular tracks (`{"layout": "circular"}`).',type:"number"},experimental:{additionalProperties:!1,properties:{mouseEvents:{anyOf:[{type:"boolean"},{$ref:"#/definitions/MouseEventsDeep"}]},performanceMode:{default:!1,description:"Render visual marks with less smooth curves to increase rendering performance. Only supported for `elliptical` `linkStyle` `withinLink` currently.",type:"boolean"}},type:"object"},flipY:{type:"boolean"},height:{description:"Specify the track height in pixels.",type:"number"},id:{description:"The ID of a view that is maintained for the use of JS API functions, e.g., positions of a view",type:"string"},innerRadius:{description:'Specify the inner radius of tracks when (`{"layout": "circular"}`).',type:"number"},layout:{$ref:"#/definitions/Layout",description:"Specify the layout type of all tracks."},linkingId:{description:"Specify an ID for [linking multiple views](http://gosling-lang.org/docs/user-interaction#linking-views)",type:"string"},mark:{$ref:"#/definitions/Mark"},opacity:{anyOf:[{$ref:"#/definitions/Opacity"},{$ref:"#/definitions/ChannelValue"}]},orientation:{$ref:"#/definitions/Orientation",description:"Specify the orientation."},outerRadius:{description:'Specify the outer radius of tracks when `{"layout": "circular"}`.',type:"number"},overlayOnPreviousTrack:{type:"boolean"},overrideTemplate:{type:"boolean"},prerelease:{additionalProperties:!1,description:"internal",type:"object"},row:{anyOf:[{$ref:"#/definitions/Row"},{$ref:"#/definitions/ChannelValue"}]},size:{anyOf:[{$ref:"#/definitions/Size"},{$ref:"#/definitions/ChannelValue"}]},spacing:{description:"The size of the gap (1) between tracks, (2) between views, and (3) of the origin of circular tracks. The effect of this property depends on where on the spec you specify the `spacing`.\n\nIn a linear layout, this value is used in pixels, while in a circular layout, this value is used relative to the height of the tracks or views.",type:"number"},startAngle:{description:'Specify the start angle (in the range of [0, 360]) of circular tracks (`{"layout": "circular"}`).',type:"number"},static:{description:"Whether to disable [Zooming and Panning](http://gosling-lang.org/docs/user-interaction#zooming-and-panning), __Default:__ `false`.",type:"boolean"},stretch:{type:"boolean"},stroke:{anyOf:[{$ref:"#/definitions/Stroke"},{$ref:"#/definitions/ChannelValue"}]},strokeWidth:{anyOf:[{$ref:"#/definitions/StrokeWidth"},{$ref:"#/definitions/ChannelValue"}]},style:{$ref:"#/definitions/Style",description:"Define the [style](http://gosling-lang.org/docs/visual-channel#style-related-properties) of multive views. Will be overwritten by the style of children elements (e.g., view, track)."},subtitle:{type:"string"},text:{anyOf:[{$ref:"#/definitions/Text"},{$ref:"#/definitions/ChannelValue"}]},title:{description:"If defined, will show the textual label on the left-top corner of a track.",type:"string"},tooltip:{items:{$ref:"#/definitions/Tooltip"},type:"array"},tracks:{anyOf:[{items:{$ref:"#/definitions/PartialTrack"},type:"array"},{items:{anyOf:[{$ref:"#/definitions/PartialTrack"},{$ref:"#/definitions/OverlaidTracks"}]},type:"array"}]},visibility:{items:{$ref:"#/definitions/VisibilityCondition"},type:"array"},width:{description:"Specify the track width in pixels.",type:"number"},x:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},x1:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},x1e:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},xAxis:{$ref:"#/definitions/AxisPosition",description:"not supported"},xDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic x-axis"},xOffset:{description:"Specify the x offset of views in the unit of pixels",type:"number"},xe:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},y:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},y1:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},y1e:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},yDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic y-axis"},yOffset:{description:"Specify the y offset of views in the unit of pixels",type:"number"},ye:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},zoomLimits:{$ref:"#/definitions/ZoomLimits"}},type:"object"}},required:["spec","selectivity"],type:"object"},type:"array"},row:{anyOf:[{$ref:"#/definitions/Row"},{$ref:"#/definitions/ChannelValue"}]},size:{anyOf:[{$ref:"#/definitions/Size"},{$ref:"#/definitions/ChannelValue"}]},spacing:{description:"The size of the gap (1) between tracks, (2) between views, and (3) of the origin of circular tracks. The effect of this property depends on where on the spec you specify the `spacing`.\n\nIn a linear layout, this value is used in pixels, while in a circular layout, this value is used relative to the height of the tracks or views.",type:"number"},startAngle:{description:'Specify the start angle (in the range of [0, 360]) of circular tracks (`{"layout": "circular"}`).',type:"number"},static:{description:"Whether to disable [Zooming and Panning](http://gosling-lang.org/docs/user-interaction#zooming-and-panning), __Default:__ `false`.",type:"boolean"},stretch:{type:"boolean"},stroke:{anyOf:[{$ref:"#/definitions/Stroke"},{$ref:"#/definitions/ChannelValue"}]},strokeWidth:{anyOf:[{$ref:"#/definitions/StrokeWidth"},{$ref:"#/definitions/ChannelValue"}]},style:{$ref:"#/definitions/Style",description:"Define the [style](http://gosling-lang.org/docs/visual-channel#style-related-properties) of multive views. Will be overwritten by the style of children elements (e.g., view, track)."},subtitle:{type:"string"},text:{anyOf:[{$ref:"#/definitions/Text"},{$ref:"#/definitions/ChannelValue"}]},title:{description:"If defined, will show the textual label on the left-top corner of a track.",type:"string"},tooltip:{items:{$ref:"#/definitions/Tooltip"},type:"array"},tracks:{items:{$ref:"#/definitions/PartialTrack"},type:"array"},visibility:{items:{$ref:"#/definitions/VisibilityCondition"},type:"array"},width:{description:"Specify the track width in pixels.",type:"number"},x:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},x1:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},x1e:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},xAxis:{$ref:"#/definitions/AxisPosition",description:"not supported"},xDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic x-axis"},xOffset:{description:"Specify the x offset of views in the unit of pixels",type:"number"},xe:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},y:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},y1:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},y1e:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},yDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic y-axis"},yOffset:{description:"Specify the y offset of views in the unit of pixels",type:"number"},ye:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},zoomLimits:{$ref:"#/definitions/ZoomLimits"}},required:["alignment","tracks"],type:"object"},{additionalProperties:!1,properties:{_assignedHeight:{type:"number"},_assignedWidth:{description:"Internal: Used for responsive spec",type:"number"},_invalidTrack:{description:"internal",type:"boolean"},_renderingId:{description:"internal",type:"string"},alignment:{const:"stack",type:"string"},assembly:{$ref:"#/definitions/Assembly",description:'A string that specifies the genome builds to use. Currently support `"hg38"`, `"hg19"`, `"hg18"`, `"hg17"`, `"hg16"`, `"mm10"`, `"mm9"`, and `"unknown"`.\n\n__Note:__: with `"unknown"` assembly, genomic axes do not show chrN: in labels.'},baselineY:{type:"number"},centerRadius:{description:"Proportion of the radius of the center white space.\n\n__Default:__ `0.3`",type:"number"},color:{anyOf:[{$ref:"#/definitions/Color"},{$ref:"#/definitions/ChannelValue"}]},data:{$ref:"#/definitions/DataDeep"},dataTransform:{items:{$ref:"#/definitions/DataTransform"},type:"array"},displacement:{$ref:"#/definitions/Displacement"},endAngle:{description:'Specify the end angle (in the range of [0, 360]) of circular tracks (`{"layout": "circular"}`).',type:"number"},experimental:{additionalProperties:!1,properties:{mouseEvents:{anyOf:[{type:"boolean"},{$ref:"#/definitions/MouseEventsDeep"}]},performanceMode:{default:!1,description:"Render visual marks with less smooth curves to increase rendering performance. Only supported for `elliptical` `linkStyle` `withinLink` currently.",type:"boolean"}},type:"object"},flipY:{type:"boolean"},height:{description:"Specify the track height in pixels.",type:"number"},id:{description:"The ID of a view that is maintained for the use of JS API functions, e.g., positions of a view",type:"string"},innerRadius:{description:'Specify the inner radius of tracks when (`{"layout": "circular"}`).',type:"number"},layout:{$ref:"#/definitions/Layout",description:"Specify the layout type of all tracks."},linkingId:{description:"Specify an ID for [linking multiple views](http://gosling-lang.org/docs/user-interaction#linking-views)",type:"string"},mark:{$ref:"#/definitions/Mark"},opacity:{anyOf:[{$ref:"#/definitions/Opacity"},{$ref:"#/definitions/ChannelValue"}]},orientation:{$ref:"#/definitions/Orientation",description:"Specify the orientation."},outerRadius:{description:'Specify the outer radius of tracks when `{"layout": "circular"}`.',type:"number"},overlayOnPreviousTrack:{type:"boolean"},overrideTemplate:{type:"boolean"},prerelease:{additionalProperties:!1,description:"internal",type:"object"},responsiveSpec:{items:{additionalProperties:!1,properties:{selectivity:{items:{$ref:"#/definitions/SelectivityCondition"},type:"array"},spec:{additionalProperties:!1,properties:{_assignedHeight:{type:"number"},_assignedWidth:{description:"Internal: Used for responsive spec",type:"number"},_invalidTrack:{description:"internal",type:"boolean"},_renderingId:{description:"internal",type:"string"},alignment:{enum:["overlay","stack"],type:"string"},assembly:{$ref:"#/definitions/Assembly",description:'A string that specifies the genome builds to use. Currently support `"hg38"`, `"hg19"`, `"hg18"`, `"hg17"`, `"hg16"`, `"mm10"`, `"mm9"`, and `"unknown"`.\n\n__Note:__: with `"unknown"` assembly, genomic axes do not show chrN: in labels.'},baselineY:{type:"number"},centerRadius:{description:"Proportion of the radius of the center white space.\n\n__Default:__ `0.3`",type:"number"},color:{anyOf:[{$ref:"#/definitions/Color"},{$ref:"#/definitions/ChannelValue"}]},data:{$ref:"#/definitions/DataDeep"},dataTransform:{items:{$ref:"#/definitions/DataTransform"},type:"array"},displacement:{$ref:"#/definitions/Displacement"},endAngle:{description:'Specify the end angle (in the range of [0, 360]) of circular tracks (`{"layout": "circular"}`).',type:"number"},experimental:{additionalProperties:!1,properties:{mouseEvents:{anyOf:[{type:"boolean"},{$ref:"#/definitions/MouseEventsDeep"}]},performanceMode:{default:!1,description:"Render visual marks with less smooth curves to increase rendering performance. Only supported for `elliptical` `linkStyle` `withinLink` currently.",type:"boolean"}},type:"object"},flipY:{type:"boolean"},height:{description:"Specify the track height in pixels.",type:"number"},id:{description:"The ID of a view that is maintained for the use of JS API functions, e.g., positions of a view",type:"string"},innerRadius:{description:'Specify the inner radius of tracks when (`{"layout": "circular"}`).',type:"number"},layout:{$ref:"#/definitions/Layout",description:"Specify the layout type of all tracks."},linkingId:{description:"Specify an ID for [linking multiple views](http://gosling-lang.org/docs/user-interaction#linking-views)",type:"string"},mark:{$ref:"#/definitions/Mark"},opacity:{anyOf:[{$ref:"#/definitions/Opacity"},{$ref:"#/definitions/ChannelValue"}]},orientation:{$ref:"#/definitions/Orientation",description:"Specify the orientation."},outerRadius:{description:'Specify the outer radius of tracks when `{"layout": "circular"}`.',type:"number"},overlayOnPreviousTrack:{type:"boolean"},overrideTemplate:{type:"boolean"},prerelease:{additionalProperties:!1,description:"internal",type:"object"},row:{anyOf:[{$ref:"#/definitions/Row"},{$ref:"#/definitions/ChannelValue"}]},size:{anyOf:[{$ref:"#/definitions/Size"},{$ref:"#/definitions/ChannelValue"}]},spacing:{description:"The size of the gap (1) between tracks, (2) between views, and (3) of the origin of circular tracks. The effect of this property depends on where on the spec you specify the `spacing`.\n\nIn a linear layout, this value is used in pixels, while in a circular layout, this value is used relative to the height of the tracks or views.",type:"number"},startAngle:{description:'Specify the start angle (in the range of [0, 360]) of circular tracks (`{"layout": "circular"}`).',type:"number"},static:{description:"Whether to disable [Zooming and Panning](http://gosling-lang.org/docs/user-interaction#zooming-and-panning), __Default:__ `false`.",type:"boolean"},stretch:{type:"boolean"},stroke:{anyOf:[{$ref:"#/definitions/Stroke"},{$ref:"#/definitions/ChannelValue"}]},strokeWidth:{anyOf:[{$ref:"#/definitions/StrokeWidth"},{$ref:"#/definitions/ChannelValue"}]},style:{$ref:"#/definitions/Style",description:"Define the [style](http://gosling-lang.org/docs/visual-channel#style-related-properties) of multive views. Will be overwritten by the style of children elements (e.g., view, track)."},subtitle:{type:"string"},text:{anyOf:[{$ref:"#/definitions/Text"},{$ref:"#/definitions/ChannelValue"}]},title:{description:"If defined, will show the textual label on the left-top corner of a track.",type:"string"},tooltip:{items:{$ref:"#/definitions/Tooltip"},type:"array"},tracks:{anyOf:[{items:{$ref:"#/definitions/PartialTrack"},type:"array"},{items:{anyOf:[{$ref:"#/definitions/PartialTrack"},{$ref:"#/definitions/OverlaidTracks"}]},type:"array"}]},visibility:{items:{$ref:"#/definitions/VisibilityCondition"},type:"array"},width:{description:"Specify the track width in pixels.",type:"number"},x:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},x1:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},x1e:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},xAxis:{$ref:"#/definitions/AxisPosition",description:"not supported"},xDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic x-axis"},xOffset:{description:"Specify the x offset of views in the unit of pixels",type:"number"},xe:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},y:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},y1:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},y1e:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},yDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic y-axis"},yOffset:{description:"Specify the y offset of views in the unit of pixels",type:"number"},ye:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},zoomLimits:{$ref:"#/definitions/ZoomLimits"}},type:"object"}},required:["spec","selectivity"],type:"object"},type:"array"},row:{anyOf:[{$ref:"#/definitions/Row"},{$ref:"#/definitions/ChannelValue"}]},size:{anyOf:[{$ref:"#/definitions/Size"},{$ref:"#/definitions/ChannelValue"}]},spacing:{description:"The size of the gap (1) between tracks, (2) between views, and (3) of the origin of circular tracks. The effect of this property depends on where on the spec you specify the `spacing`.\n\nIn a linear layout, this value is used in pixels, while in a circular layout, this value is used relative to the height of the tracks or views.",type:"number"},startAngle:{description:'Specify the start angle (in the range of [0, 360]) of circular tracks (`{"layout": "circular"}`).',type:"number"},static:{description:"Whether to disable [Zooming and Panning](http://gosling-lang.org/docs/user-interaction#zooming-and-panning), __Default:__ `false`.",type:"boolean"},stretch:{type:"boolean"},stroke:{anyOf:[{$ref:"#/definitions/Stroke"},{$ref:"#/definitions/ChannelValue"}]},strokeWidth:{anyOf:[{$ref:"#/definitions/StrokeWidth"},{$ref:"#/definitions/ChannelValue"}]},style:{$ref:"#/definitions/Style",description:"Define the [style](http://gosling-lang.org/docs/visual-channel#style-related-properties) of multive views. Will be overwritten by the style of children elements (e.g., view, track)."},subtitle:{type:"string"},text:{anyOf:[{$ref:"#/definitions/Text"},{$ref:"#/definitions/ChannelValue"}]},title:{description:"If defined, will show the textual label on the left-top corner of a track.",type:"string"},tooltip:{items:{$ref:"#/definitions/Tooltip"},type:"array"},tracks:{items:{anyOf:[{$ref:"#/definitions/PartialTrack"},{$ref:"#/definitions/OverlaidTracks"}]},type:"array"},visibility:{items:{$ref:"#/definitions/VisibilityCondition"},type:"array"},width:{description:"Specify the track width in pixels.",type:"number"},x:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},x1:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},x1e:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},xAxis:{$ref:"#/definitions/AxisPosition",description:"not supported"},xDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic x-axis"},xOffset:{description:"Specify the x offset of views in the unit of pixels",type:"number"},xe:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},y:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},y1:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},y1e:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},yDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic y-axis"},yOffset:{description:"Specify the y offset of views in the unit of pixels",type:"number"},ye:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},zoomLimits:{$ref:"#/definitions/ZoomLimits"}},required:["tracks"],type:"object"},{additionalProperties:!1,properties:{_assignedHeight:{type:"number"},_assignedWidth:{description:"Internal: Used for responsive spec",type:"number"},assembly:{$ref:"#/definitions/Assembly",description:'A string that specifies the genome builds to use. Currently support `"hg38"`, `"hg19"`, `"hg18"`, `"hg17"`, `"hg16"`, `"mm10"`, `"mm9"`, and `"unknown"`.\n\n__Note:__: with `"unknown"` assembly, genomic axes do not show chrN: in labels.'},centerRadius:{description:"Proportion of the radius of the center white space.\n\n__Default:__ `0.3`",type:"number"},id:{description:"The ID of a view that is maintained for the use of JS API functions, e.g., positions of a view",type:"string"},layout:{$ref:"#/definitions/Layout",description:"Specify the layout type of all tracks."},linkingId:{description:"Specify an ID for [linking multiple views](http://gosling-lang.org/docs/user-interaction#linking-views)",type:"string"},orientation:{$ref:"#/definitions/Orientation",description:"Specify the orientation."},responsiveSpec:{items:{additionalProperties:!1,properties:{selectivity:{items:{$ref:"#/definitions/SelectivityCondition"},type:"array"},spec:{additionalProperties:!1,properties:{_assignedHeight:{type:"number"},_assignedWidth:{description:"Internal: Used for responsive spec",type:"number"},_invalidTrack:{description:"internal",type:"boolean"},_renderingId:{description:"internal",type:"string"},alignment:{enum:["overlay","stack"],type:"string"},assembly:{$ref:"#/definitions/Assembly",description:'A string that specifies the genome builds to use. Currently support `"hg38"`, `"hg19"`, `"hg18"`, `"hg17"`, `"hg16"`, `"mm10"`, `"mm9"`, and `"unknown"`.\n\n__Note:__: with `"unknown"` assembly, genomic axes do not show chrN: in labels.'},baselineY:{type:"number"},centerRadius:{description:"Proportion of the radius of the center white space.\n\n__Default:__ `0.3`",type:"number"},color:{anyOf:[{$ref:"#/definitions/Color"},{$ref:"#/definitions/ChannelValue"}]},data:{$ref:"#/definitions/DataDeep"},dataTransform:{items:{$ref:"#/definitions/DataTransform"},type:"array"},displacement:{$ref:"#/definitions/Displacement"},endAngle:{description:'Specify the end angle (in the range of [0, 360]) of circular tracks (`{"layout": "circular"}`).',type:"number"},experimental:{additionalProperties:!1,properties:{mouseEvents:{anyOf:[{type:"boolean"},{$ref:"#/definitions/MouseEventsDeep"}]},performanceMode:{default:!1,description:"Render visual marks with less smooth curves to increase rendering performance. Only supported for `elliptical` `linkStyle` `withinLink` currently.",type:"boolean"}},type:"object"},flipY:{type:"boolean"},height:{description:"Specify the track height in pixels.",type:"number"},id:{description:"The ID of a view that is maintained for the use of JS API functions, e.g., positions of a view",type:"string"},innerRadius:{description:'Specify the inner radius of tracks when (`{"layout": "circular"}`).',type:"number"},layout:{$ref:"#/definitions/Layout",description:"Specify the layout type of all tracks."},linkingId:{description:"Specify an ID for [linking multiple views](http://gosling-lang.org/docs/user-interaction#linking-views)",type:"string"},mark:{$ref:"#/definitions/Mark"},opacity:{anyOf:[{$ref:"#/definitions/Opacity"},{$ref:"#/definitions/ChannelValue"}]},orientation:{$ref:"#/definitions/Orientation",description:"Specify the orientation."},outerRadius:{description:'Specify the outer radius of tracks when `{"layout": "circular"}`.',type:"number"},overlayOnPreviousTrack:{type:"boolean"},overrideTemplate:{type:"boolean"},prerelease:{additionalProperties:!1,description:"internal",type:"object"},row:{anyOf:[{$ref:"#/definitions/Row"},{$ref:"#/definitions/ChannelValue"}]},size:{anyOf:[{$ref:"#/definitions/Size"},{$ref:"#/definitions/ChannelValue"}]},spacing:{description:"The size of the gap (1) between tracks, (2) between views, and (3) of the origin of circular tracks. The effect of this property depends on where on the spec you specify the `spacing`.\n\nIn a linear layout, this value is used in pixels, while in a circular layout, this value is used relative to the height of the tracks or views.",type:"number"},startAngle:{description:'Specify the start angle (in the range of [0, 360]) of circular tracks (`{"layout": "circular"}`).',type:"number"},static:{description:"Whether to disable [Zooming and Panning](http://gosling-lang.org/docs/user-interaction#zooming-and-panning), __Default:__ `false`.",type:"boolean"},stretch:{type:"boolean"},stroke:{anyOf:[{$ref:"#/definitions/Stroke"},{$ref:"#/definitions/ChannelValue"}]},strokeWidth:{anyOf:[{$ref:"#/definitions/StrokeWidth"},{$ref:"#/definitions/ChannelValue"}]},style:{$ref:"#/definitions/Style",description:"Define the [style](http://gosling-lang.org/docs/visual-channel#style-related-properties) of multive views. Will be overwritten by the style of children elements (e.g., view, track)."},subtitle:{type:"string"},text:{anyOf:[{$ref:"#/definitions/Text"},{$ref:"#/definitions/ChannelValue"}]},title:{description:"If defined, will show the textual label on the left-top corner of a track.",type:"string"},tooltip:{items:{$ref:"#/definitions/Tooltip"},type:"array"},tracks:{anyOf:[{items:{$ref:"#/definitions/PartialTrack"},type:"array"},{items:{anyOf:[{$ref:"#/definitions/PartialTrack"},{$ref:"#/definitions/OverlaidTracks"}]},type:"array"}]},visibility:{items:{$ref:"#/definitions/VisibilityCondition"},type:"array"},width:{description:"Specify the track width in pixels.",type:"number"},x:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},x1:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},x1e:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},xAxis:{$ref:"#/definitions/AxisPosition",description:"not supported"},xDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic x-axis"},xOffset:{description:"Specify the x offset of views in the unit of pixels",type:"number"},xe:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},y:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},y1:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},y1e:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},yDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic y-axis"},yOffset:{description:"Specify the y offset of views in the unit of pixels",type:"number"},ye:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},zoomLimits:{$ref:"#/definitions/ZoomLimits"}},type:"object"}},required:["spec","selectivity"],type:"object"},type:"array"},spacing:{description:"The size of the gap (1) between tracks, (2) between views, and (3) of the origin of circular tracks. The effect of this property depends on where on the spec you specify the `spacing`.\n\nIn a linear layout, this value is used in pixels, while in a circular layout, this value is used relative to the height of the tracks or views.",type:"number"},static:{description:"Whether to disable [Zooming and Panning](http://gosling-lang.org/docs/user-interaction#zooming-and-panning), __Default:__ `false`.",type:"boolean"},style:{$ref:"#/definitions/Style",description:"Define the [style](http://gosling-lang.org/docs/visual-channel#style-related-properties) of multive views. Will be overwritten by the style of children elements (e.g., view, track)."},tracks:{items:{$ref:"#/definitions/Track"},type:"array"},xAxis:{$ref:"#/definitions/AxisPosition",description:"not supported"},xDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic x-axis"},xOffset:{description:"Specify the x offset of views in the unit of pixels",type:"number"},yDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic y-axis"},yOffset:{description:"Specify the y offset of views in the unit of pixels",type:"number"},zoomLimits:{$ref:"#/definitions/ZoomLimits"}},required:["tracks"],type:"object"}]},Size:{additionalProperties:!1,properties:{domain:{$ref:"#/definitions/ValueExtent",description:"Values of the data"},field:{description:"Name of the data field",type:"string"},legend:{description:"not supported: Whether to display legend. __Default__: `false`",type:"boolean"},range:{$ref:"#/definitions/ValueExtent",description:"Ranges of visual channel values"},type:{description:"Specify the data type",enum:["quantitative","nominal"],type:"string"}},type:"object"},SizeVisibilityCondition:{additionalProperties:!1,properties:{conditionPadding:{description:"Specify the buffer size (in pixel) of width or height when calculating the visibility.\n\n__Default__: `0`",type:"number"},measure:{description:"Specify which aspect of the `target` will be compared to the `threshold`.",enum:["width","height"],type:"string"},operation:{$ref:"#/definitions/LogicalOperation",description:`A string that specifies the logical operation to conduct between \`threshold\` and the \`measure\` of \`target\`. Support +`+G+" > .resize-sensor {min-width: "+S+"px;}",o.push(G)}r[G].push({mode:v,property:w,value:V})}function d(G){var v;if(document.querySelectorAll&&(v=G?G.querySelectorAll.bind(G):document.querySelectorAll.bind(document)),!v&&typeof $$<"u"&&(v=$$),!v&&typeof jQuery<"u"&&(v=jQuery),!v)throw"No document.querySelectorAll, jQuery or Mootools's $$ found.";return v}function h(G){var v=d(G);for(var w in r)if(r.hasOwnProperty(w))for(var V=v(w,G),S=0,X=V.length;Sw[J].minWidth&&(O=J);if(O||(O=S),X!==O)if(W[O])v[X].style.display="none",v[O].style.display="block",X=O;else{var ee=new Image;ee.onload=function(){v[O].src=V[O],v[X].style.display="none",v[O].style.display="block",W[O]=!0,X=O},ee.src=V[O]}else v[O].src=V[O]}G.resizeSensorInstance=new I(G,E),E()}function f(){for(var G=d(),v=G("[data-responsive-image],[responsive-image]"),w=0,V=v.length;w img, [data-responsive-image] {overflow: hidden; padding: 0; } [responsive-image] > img, [data-responsive-image] > img {width: 100%;}",C.innerHTML+=` +@keyframes element-queries { 0% { visibility: inherit; } }`,document.getElementsByTagName("head")[0].appendChild(C),B=!0);for(var v=0,w=document.styleSheets.length;vg in e?Seg(e,g,{enumerable:!0,configurable:!0,writable:!0,value:I}):e[g]=I,Ct=(e,g,I)=>(weg(e,typeof g!="symbol"?g+"":g,I),I),J4=(e,g,I)=>{if(!g.has(e))throw TypeError("Cannot "+I)},xt=(e,g,I)=>(J4(e,g,"read from private field"),I?I.call(e):g.get(e)),hg=(e,g,I)=>{if(g.has(e))throw TypeError("Cannot add the same private member more than once");g instanceof WeakSet?g.add(e):g.set(e,I)},vC=(e,g,I,i)=>(J4(e,g,"write to private field"),i?i.call(e,I):g.set(e,I),I),BI=(e,g,I)=>(J4(e,g,"access private method"),I),qZ,EB,MB,Rd,gH,IH,CO,qXe,O4,e9e,iH,rO,oO,t9e,AO,g9e,aO,I9e,Pa;const Veg="#/definitions/GoslingSpec",Reg="http://json-schema.org/draft-07/schema#",Weg={Aggregate:{enum:["max","min","mean","bin","count"],type:"string"},Assembly:{anyOf:[{const:"hg38",type:"string"},{const:"hg19",type:"string"},{const:"hg18",type:"string"},{const:"hg17",type:"string"},{const:"hg16",type:"string"},{const:"mm10",type:"string"},{const:"mm9",type:"string"},{const:"unknown",type:"string"},{$ref:"#/definitions/ChromSizes"}]},AxisPosition:{enum:["none","top","bottom","left","right"],type:"string"},BamData:{additionalProperties:!1,description:"Binary Alignment Map (BAM) is the comprehensive raw data of genome sequencing; it consists of the lossless, compressed binary representation of the Sequence Alignment Map-files.",properties:{extractJunction:{description:"Determine whether to extract exon-to-exon junctions. __Default__: `false`",type:"boolean"},indexUrl:{description:"URL link to the index file of the BAM file",type:"string"},junctionMinCoverage:{description:"Determine the threshold of coverage when extracting exon-to-exon junctions. __Default__: `1`",type:"number"},loadMates:{description:"Load mates that are located in the same chromosome. __Default__: `false`",type:"boolean"},maxInsertSize:{description:"Determines the threshold of insert sizes for determining the structural variants. __Default__: `5000`",type:"number"},type:{const:"bam",type:"string"},url:{description:"URL link to the BAM data file",type:"string"}},required:["type","url","indexUrl"],type:"object"},BedData:{additionalProperties:!1,description:"BED file format",properties:{customFields:{description:"An array of strings, where each string is the name of a non-standard field in the BED file. If there are `n` custom fields, we assume that the last `n` columns of the BED file correspond to the custom fields.",items:{type:"string"},type:"array"},indexUrl:{description:"Specify the URL address of the data file index.",type:"string"},sampleLength:{description:"Specify the number of rows loaded from the URL.\n\n__Default:__ `1000`",type:"number"},type:{const:"bed",type:"string"},url:{description:"Specify the URL address of the data file.",type:"string"}},required:["type","url","indexUrl"],type:"object"},BeddbData:{additionalProperties:!1,description:"Regular BED or similar files can be pre-aggregated for the scalable data exploration. Find our more about this format at [HiGlass Docs](https://docs.higlass.io/data_preparation.html#bed-files).",properties:{exonIntervalFields:{description:"experimental",items:[{additionalProperties:!1,properties:{index:{type:"number"},name:{type:"string"}},required:["index","name"],type:"object"},{additionalProperties:!1,properties:{index:{type:"number"},name:{type:"string"}},required:["index","name"],type:"object"}],maxItems:2,minItems:2,type:"array"},genomicFields:{description:"Specify the name of genomic data fields.",items:{additionalProperties:!1,properties:{index:{type:"number"},name:{type:"string"}},required:["index","name"],type:"object"},type:"array"},type:{const:"beddb",type:"string"},url:{description:"Specify the URL address of the data file.",type:"string"},valueFields:{description:"Specify the column indexes, field names, and field types.",items:{additionalProperties:!1,properties:{index:{type:"number"},name:{type:"string"},type:{enum:["nominal","quantitative"],type:"string"}},required:["index","name","type"],type:"object"},type:"array"}},required:["type","url","genomicFields"],type:"object"},BigWigData:{additionalProperties:!1,properties:{aggregation:{$ref:"#/definitions/BinAggregate",description:'Determine aggregation function to apply within bins. __Default__: `"mean"`'},binSize:{description:"Binning the genomic interval in tiles (unit size: 256).",type:"number"},column:{description:'Assign a field name of the middle position of genomic intervals. __Default__: `"position"`',type:"string"},end:{description:'Assign a field name of the end position of genomic intervals. __Default__: `"end"`',type:"string"},start:{description:'Assign a field name of the start position of genomic intervals. __Default__: `"start"`',type:"string"},type:{const:"bigwig",type:"string"},url:{description:"Specify the URL address of the data file.",type:"string"},value:{description:'Assign a field name of quantitative values. __Default__: `"value"`',type:"string"}},required:["type","url"],type:"object"},BinAggregate:{enum:["mean","sum"],type:"string"},Channel:{anyOf:[{$ref:"#/definitions/ChannelDeep"},{$ref:"#/definitions/ChannelValue"}]},ChannelDeep:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/Y"},{$ref:"#/definitions/Row"},{$ref:"#/definitions/Color"},{$ref:"#/definitions/Size"},{$ref:"#/definitions/Stroke"},{$ref:"#/definitions/StrokeWidth"},{$ref:"#/definitions/Opacity"},{$ref:"#/definitions/Text"}]},ChannelValue:{additionalProperties:!1,properties:{value:{description:"Assign a constant value for a visual channel.",type:["number","string"]}},required:["value"],type:"object"},ChromSizes:{description:'Custom chromosome sizes, e.g., [["foo", 1000], ["bar", 300], ["baz", 240]]',items:{items:[{type:"string"},{type:"number"}],maxItems:2,minItems:2,type:"array"},type:"array"},Color:{additionalProperties:!1,properties:{domain:{$ref:"#/definitions/ValueExtent",description:"Values of the data"},field:{description:"Name of the data field",type:"string"},legend:{description:"Whether to display legend. __Default__: `false`",type:"boolean"},range:{$ref:"#/definitions/Range",description:"Determine the colors that should be bound to data value. Default properties are determined considering the field type."},scale:{enum:["linear","log"],type:"string"},scaleOffset:{description:"Whether to use offset of the domain proportionally. This is bound to brushes on the color legend. __Default__: `[0, 1]`",items:{type:"number"},maxItems:2,minItems:2,type:"array"},title:{description:"Title of the legend. __Default__: `undefined`",type:"string"},type:{description:"Specify the data type",enum:["quantitative","nominal"],type:"string"}},type:"object"},CoverageTransform:{additionalProperties:!1,description:"Aggregate rows and calculate coverage",properties:{endField:{type:"string"},groupField:{description:"The name of a nominal field to group rows by in prior to piling-up",type:"string"},newField:{type:"string"},startField:{type:"string"},type:{const:"coverage",type:"string"}},required:["type","startField","endField"],type:"object"},CsvData:{additionalProperties:!1,description:'Any small enough tabular data files, such as tsv, csv, BED, BEDPE, and GFF, can be loaded using "csv" data specification.',properties:{chromosomeField:{description:"Specify the name of chromosome data fields.",type:"string"},chromosomePrefix:{description:'Specify the chromosome prefix if chromosomes are denoted using a prefix besides "chr" or a number',type:"string"},genomicFields:{description:"Specify the name of genomic data fields.",items:{type:"string"},type:"array"},genomicFieldsToConvert:{description:"experimental",items:{additionalProperties:!1,properties:{chromosomeField:{type:"string"},genomicFields:{items:{type:"string"},type:"array"}},required:["chromosomeField","genomicFields"],type:"object"},type:"array"},headerNames:{description:"Specify the names of data fields if a CSV file does not contain a header.",items:{type:"string"},type:"array"},longToWideId:{description:"experimental",type:"string"},sampleLength:{description:"Specify the number of rows loaded from the URL.\n\n__Default:__ `1000`",type:"number"},separator:{description:"Specify file separator, __Default:__ ','",type:"string"},type:{const:"csv",type:"string"},url:{description:"Specify the URL address of the data file.",type:"string"}},required:["type","url"],type:"object"},DataDeep:{anyOf:[{$ref:"#/definitions/JsonData"},{$ref:"#/definitions/CsvData"},{$ref:"#/definitions/BedData"},{$ref:"#/definitions/BigWigData"},{$ref:"#/definitions/MultivecData"},{$ref:"#/definitions/BeddbData"},{$ref:"#/definitions/VectorData"},{$ref:"#/definitions/MatrixData"},{$ref:"#/definitions/BamData"},{$ref:"#/definitions/VcfData"},{$ref:"#/definitions/GffData"}]},DataTrack:{additionalProperties:!1,description:"Partial specification of `BasicSingleTrack` to use default visual encoding predefined by data type.",properties:{_assignedHeight:{type:"number"},_assignedWidth:{description:"Internal: Used for responsive spec",type:"number"},_invalidTrack:{description:"internal",type:"boolean"},_renderingId:{description:"internal",type:"string"},assembly:{$ref:"#/definitions/Assembly",description:'A string that specifies the genome builds to use. Currently support `"hg38"`, `"hg19"`, `"hg18"`, `"hg17"`, `"hg16"`, `"mm10"`, `"mm9"`, and `"unknown"`.\n\n__Note:__: with `"unknown"` assembly, genomic axes do not show chrN: in labels.'},centerRadius:{description:"Proportion of the radius of the center white space.\n\n__Default:__ `0.3`",type:"number"},data:{$ref:"#/definitions/DataDeep"},endAngle:{description:'Specify the end angle (in the range of [0, 360]) of circular tracks (`{"layout": "circular"}`).',type:"number"},height:{description:"Specify the track height in pixels.",type:"number"},id:{description:"Assigned to `uid` in a HiGlass view config, used for API and caching.",type:"string"},innerRadius:{description:'Specify the inner radius of tracks when (`{"layout": "circular"}`).',type:"number"},layout:{$ref:"#/definitions/Layout",description:"Specify the layout type of all tracks."},linkingId:{description:"Specify an ID for [linking multiple views](http://gosling-lang.org/docs/user-interaction#linking-views)",type:"string"},orientation:{$ref:"#/definitions/Orientation",description:"Specify the orientation."},outerRadius:{description:'Specify the outer radius of tracks when `{"layout": "circular"}`.',type:"number"},overlayOnPreviousTrack:{type:"boolean"},prerelease:{additionalProperties:!1,description:"internal",type:"object"},spacing:{description:"The size of the gap (1) between tracks, (2) between views, and (3) of the origin of circular tracks. The effect of this property depends on where on the spec you specify the `spacing`.\n\nIn a linear layout, this value is used in pixels, while in a circular layout, this value is used relative to the height of the tracks or views.",type:"number"},startAngle:{description:'Specify the start angle (in the range of [0, 360]) of circular tracks (`{"layout": "circular"}`).',type:"number"},static:{description:"Whether to disable [Zooming and Panning](http://gosling-lang.org/docs/user-interaction#zooming-and-panning), __Default:__ `false`.",type:"boolean"},style:{$ref:"#/definitions/Style",description:"Define the [style](http://gosling-lang.org/docs/visual-channel#style-related-properties) of multive views. Will be overwritten by the style of children elements (e.g., view, track)."},subtitle:{type:"string"},title:{description:"If defined, will show the textual label on the left-top corner of a track.",type:"string"},width:{description:"Specify the track width in pixels.",type:"number"},xAxis:{$ref:"#/definitions/AxisPosition",description:"not supported"},xDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic x-axis"},xOffset:{description:"Specify the x offset of views in the unit of pixels",type:"number"},yDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic y-axis"},yOffset:{description:"Specify the y offset of views in the unit of pixels",type:"number"},zoomLimits:{$ref:"#/definitions/ZoomLimits"}},required:["data"],type:"object"},DataTransform:{anyOf:[{$ref:"#/definitions/FilterTransform"},{$ref:"#/definitions/StrConcatTransform"},{$ref:"#/definitions/StrReplaceTransform"},{$ref:"#/definitions/LogTransform"},{$ref:"#/definitions/DisplaceTransform"},{$ref:"#/definitions/ExonSplitTransform"},{$ref:"#/definitions/GenomicLengthTransform"},{$ref:"#/definitions/SvTypeTransform"},{$ref:"#/definitions/CoverageTransform"},{$ref:"#/definitions/JsonParseTransform"}]},Datum:{additionalProperties:{type:["number","string"]},description:"Values in the form of JSON.",type:"object"},DisplaceTransform:{additionalProperties:!1,properties:{boundingBox:{additionalProperties:!1,properties:{endField:{description:"The name of a quantitative field that represents the end position.",type:"string"},groupField:{description:"The name of a nominal field to group rows by in prior to piling-up.",type:"string"},isPaddingBP:{description:"Whether to consider `padding` as the bp length.",type:"boolean"},padding:{description:"The padding around visual lements. Either px or bp",type:"number"},startField:{description:"The name of a quantitative field that represents the start position.",type:"string"}},required:["startField","endField"],type:"object"},maxRows:{description:"Specify maximum rows to be generated (default has no limit).",type:"number"},method:{$ref:"#/definitions/DisplacementType",description:"A string that specifies the type of displacement."},newField:{type:"string"},type:{const:"displace",type:"string"}},required:["type","boundingBox","method","newField"],type:"object"},Displacement:{additionalProperties:!1,properties:{padding:{type:"number"},type:{$ref:"#/definitions/DisplacementType"}},required:["type"],type:"object"},DisplacementType:{enum:["pile","spread"],type:"string"},DomainChr:{additionalProperties:!1,properties:{chromosome:{type:"string"}},required:["chromosome"],type:"object"},DomainChrInterval:{additionalProperties:!1,properties:{chromosome:{description:"If specified, only showing a certain interval in a chromosome.",type:"string"},interval:{items:{type:"number"},maxItems:2,minItems:2,type:"array"}},required:["chromosome","interval"],type:"object"},DomainInterval:{additionalProperties:!1,properties:{interval:{description:"Show a certain interval within entire chromosome",items:{type:"number"},maxItems:2,minItems:2,type:"array"}},required:["interval"],type:"object"},DummyTrack:{additionalProperties:!1,description:"A placeholder track. In contrast to other tracks, this track does not display any data. Instead it provides empty space for third party tools to display their data on top of.",properties:{_invalidTrack:{description:"internal",type:"boolean"},assembly:{const:"unknown",description:"No assemblies can be associated with a dummy track",type:"string"},height:{description:"Specify the track height in pixels.",type:"number"},id:{description:"Assigned to `uid` in a HiGlass view config, used for API and caching.",type:"string"},layout:{const:"linear",description:"Only linear layout are supported at this time",type:"string"},orientation:{$ref:"#/definitions/Orientation",description:"Specify the orientation."},overlayOnPreviousTrack:{type:"boolean"},static:{const:!0,description:"Whether to disable [Zooming and Panning](http://gosling-lang.org/docs/user-interaction#zooming-and-panning), __Default:__ `false`.",type:"boolean"},style:{$ref:"#/definitions/DummyTrackStyle",description:"Defines how the track is styled"},title:{description:"Text that gets shown on the DummyTrack",type:"string"},type:{const:"dummy-track",description:"Used to specify the dummy track",type:"string"},width:{description:"Specify the track width in pixels.",type:"number"},zoomLimits:{description:"Unused property for DummyTrack",items:{type:"null"},maxItems:2,minItems:2,type:"array"}},required:["type"],type:"object"},DummyTrackStyle:{additionalProperties:!1,properties:{background:{description:"Background color of the track",type:"string"},outline:{description:"Color of the outline of the track",type:"string"},textFontSize:{description:"Specify the font size of the title",type:"number"},textFontWeight:{description:"Specify the font weight of the title.",enum:["bold","normal"],type:"string"},textStroke:{description:"Specify the stroke color of title.",type:"string"},textStrokeWidth:{description:"Specify the stroke width of the title.",type:"number"}},type:"object"},EventStyle:{additionalProperties:!1,description:"The styles defined here will be applied to the target marks of mouse events, such as a point mark after the user clicks on it.",properties:{arrange:{description:"Show event effects behind or in front of marks.",enum:["behind","front"],type:"string"},color:{description:"color of the marks when mouse events are triggered",type:"string"},opacity:{description:"opacity of the marks when mouse events are triggered",type:"number"},stroke:{description:"stroke color of the marks when mouse events are triggered",type:"string"},strokeOpacity:{type:"number"},strokeWidth:{description:"stroke width of the marks when mouse events are triggered",type:"number"}},type:"object"},ExonSplitTransform:{additionalProperties:!1,properties:{fields:{items:{additionalProperties:!1,properties:{chrField:{type:"string"},field:{type:"string"},newField:{type:"string"},type:{$ref:"#/definitions/FieldType"}},required:["field","type","newField","chrField"],type:"object"},type:"array"},flag:{additionalProperties:!1,properties:{field:{type:"string"},value:{type:["number","string"]}},required:["field","value"],type:"object"},separator:{type:"string"},type:{const:"exonSplit",type:"string"}},required:["type","separator","flag","fields"],type:"object"},FieldType:{enum:["genomic","nominal","quantitative"],type:"string"},FilterTransform:{anyOf:[{$ref:"#/definitions/OneOfFilter"},{$ref:"#/definitions/RangeFilter"},{$ref:"#/definitions/IncludeFilter"}]},GenomicDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}]},GenomicLengthTransform:{additionalProperties:!1,description:"Calculate genomic length using two genomic fields",properties:{endField:{type:"string"},newField:{type:"string"},startField:{type:"string"},type:{const:"genomicLength",type:"string"}},required:["type","startField","endField","newField"],type:"object"},GffData:{additionalProperties:!1,description:"Generic Feature Format Version 3 (GFF3) format data. It parses files that follow the [GFF3 specification](https://github.com/The-Sequence-Ontology/Specifications/blob/master/gff3.md).",properties:{attributesToFields:{description:'Specifies which attributes to include as a fields. GFF files have an "attributes" column which contains a list of attributes which are each tag-value pairs (`tag=value`). This option allows for specific attributes to be accessible as a field. For example, if you have an attribute called "gene_name" and you want label features on your track using those values, you can use this option so that you can use `"field": "gene_name"` in the schema.\n\nIf there is a single `value` corresponding to the `tag`, Gosling will parse that value as a string. If there are multiple `value`s corresponding to a `tag`, Gosling will parse it as a comma-separated list string. If a feature does not have a particular attribute, then the attribute value will be set to the `defaultValue`.',items:{additionalProperties:!1,properties:{attribute:{type:"string"},defaultValue:{type:"string"}},required:["attribute","defaultValue"],type:"object"},type:"array"},indexUrl:{description:"URL link to the tabix index file",type:"string"},sampleLength:{description:"The maximum number of samples to be shown on the track. Samples are uniformly randomly selected so that this threshold is not exceeded. __Default:__ `1000`",type:"number"},type:{const:"gff",type:"string"},url:{description:"URL link to the GFF file",type:"string"}},required:["type","url","indexUrl"],type:"object"},GoslingSpec:{anyOf:[{additionalProperties:!1,properties:{_assignedHeight:{type:"number"},_assignedWidth:{description:"Internal: Used for responsive spec",type:"number"},_invalidTrack:{description:"internal",type:"boolean"},_renderingId:{description:"internal",type:"string"},alignment:{const:"overlay",type:"string"},assembly:{$ref:"#/definitions/Assembly",description:'A string that specifies the genome builds to use. Currently support `"hg38"`, `"hg19"`, `"hg18"`, `"hg17"`, `"hg16"`, `"mm10"`, `"mm9"`, and `"unknown"`.\n\n__Note:__: with `"unknown"` assembly, genomic axes do not show chrN: in labels.'},baselineY:{type:"number"},centerRadius:{description:"Proportion of the radius of the center white space.\n\n__Default:__ `0.3`",type:"number"},color:{anyOf:[{$ref:"#/definitions/Color"},{$ref:"#/definitions/ChannelValue"}]},data:{$ref:"#/definitions/DataDeep"},dataTransform:{items:{$ref:"#/definitions/DataTransform"},type:"array"},description:{type:"string"},displacement:{$ref:"#/definitions/Displacement"},endAngle:{description:'Specify the end angle (in the range of [0, 360]) of circular tracks (`{"layout": "circular"}`).',type:"number"},experimental:{additionalProperties:!1,properties:{mouseEvents:{anyOf:[{type:"boolean"},{$ref:"#/definitions/MouseEventsDeep"}]},performanceMode:{default:!1,description:"Render visual marks with less smooth curves to increase rendering performance. Only supported for `elliptical` `linkStyle` `withinLink` currently.",type:"boolean"}},type:"object"},flipY:{type:"boolean"},height:{description:"Specify the track height in pixels.",type:"number"},id:{description:"The ID of a view that is maintained for the use of JS API functions, e.g., positions of a view",type:"string"},innerRadius:{description:'Specify the inner radius of tracks when (`{"layout": "circular"}`).',type:"number"},layout:{$ref:"#/definitions/Layout",description:"Specify the layout type of all tracks."},linkingId:{description:"Specify an ID for [linking multiple views](http://gosling-lang.org/docs/user-interaction#linking-views)",type:"string"},mark:{$ref:"#/definitions/Mark"},opacity:{anyOf:[{$ref:"#/definitions/Opacity"},{$ref:"#/definitions/ChannelValue"}]},orientation:{$ref:"#/definitions/Orientation",description:"Specify the orientation."},outerRadius:{description:'Specify the outer radius of tracks when `{"layout": "circular"}`.',type:"number"},overlayOnPreviousTrack:{type:"boolean"},overrideTemplate:{type:"boolean"},prerelease:{additionalProperties:!1,description:"internal",type:"object"},responsiveSize:{$ref:"#/definitions/ResponsiveSize",description:"Determine whether to make the size of `GoslingComponent` bound to its parent element. __Default__: `false`"},responsiveSpec:{items:{additionalProperties:!1,properties:{selectivity:{items:{$ref:"#/definitions/SelectivityCondition"},type:"array"},spec:{additionalProperties:!1,properties:{_assignedHeight:{type:"number"},_assignedWidth:{description:"Internal: Used for responsive spec",type:"number"},_invalidTrack:{description:"internal",type:"boolean"},_renderingId:{description:"internal",type:"string"},alignment:{enum:["overlay","stack"],type:"string"},assembly:{$ref:"#/definitions/Assembly",description:'A string that specifies the genome builds to use. Currently support `"hg38"`, `"hg19"`, `"hg18"`, `"hg17"`, `"hg16"`, `"mm10"`, `"mm9"`, and `"unknown"`.\n\n__Note:__: with `"unknown"` assembly, genomic axes do not show chrN: in labels.'},baselineY:{type:"number"},centerRadius:{description:"Proportion of the radius of the center white space.\n\n__Default:__ `0.3`",type:"number"},color:{anyOf:[{$ref:"#/definitions/Color"},{$ref:"#/definitions/ChannelValue"}]},data:{$ref:"#/definitions/DataDeep"},dataTransform:{items:{$ref:"#/definitions/DataTransform"},type:"array"},displacement:{$ref:"#/definitions/Displacement"},endAngle:{description:'Specify the end angle (in the range of [0, 360]) of circular tracks (`{"layout": "circular"}`).',type:"number"},experimental:{additionalProperties:!1,properties:{mouseEvents:{anyOf:[{type:"boolean"},{$ref:"#/definitions/MouseEventsDeep"}]},performanceMode:{default:!1,description:"Render visual marks with less smooth curves to increase rendering performance. Only supported for `elliptical` `linkStyle` `withinLink` currently.",type:"boolean"}},type:"object"},flipY:{type:"boolean"},height:{description:"Specify the track height in pixels.",type:"number"},id:{description:"The ID of a view that is maintained for the use of JS API functions, e.g., positions of a view",type:"string"},innerRadius:{description:'Specify the inner radius of tracks when (`{"layout": "circular"}`).',type:"number"},layout:{$ref:"#/definitions/Layout",description:"Specify the layout type of all tracks."},linkingId:{description:"Specify an ID for [linking multiple views](http://gosling-lang.org/docs/user-interaction#linking-views)",type:"string"},mark:{$ref:"#/definitions/Mark"},opacity:{anyOf:[{$ref:"#/definitions/Opacity"},{$ref:"#/definitions/ChannelValue"}]},orientation:{$ref:"#/definitions/Orientation",description:"Specify the orientation."},outerRadius:{description:'Specify the outer radius of tracks when `{"layout": "circular"}`.',type:"number"},overlayOnPreviousTrack:{type:"boolean"},overrideTemplate:{type:"boolean"},prerelease:{additionalProperties:!1,description:"internal",type:"object"},row:{anyOf:[{$ref:"#/definitions/Row"},{$ref:"#/definitions/ChannelValue"}]},size:{anyOf:[{$ref:"#/definitions/Size"},{$ref:"#/definitions/ChannelValue"}]},spacing:{description:"The size of the gap (1) between tracks, (2) between views, and (3) of the origin of circular tracks. The effect of this property depends on where on the spec you specify the `spacing`.\n\nIn a linear layout, this value is used in pixels, while in a circular layout, this value is used relative to the height of the tracks or views.",type:"number"},startAngle:{description:'Specify the start angle (in the range of [0, 360]) of circular tracks (`{"layout": "circular"}`).',type:"number"},static:{description:"Whether to disable [Zooming and Panning](http://gosling-lang.org/docs/user-interaction#zooming-and-panning), __Default:__ `false`.",type:"boolean"},stretch:{type:"boolean"},stroke:{anyOf:[{$ref:"#/definitions/Stroke"},{$ref:"#/definitions/ChannelValue"}]},strokeWidth:{anyOf:[{$ref:"#/definitions/StrokeWidth"},{$ref:"#/definitions/ChannelValue"}]},style:{$ref:"#/definitions/Style",description:"Define the [style](http://gosling-lang.org/docs/visual-channel#style-related-properties) of multive views. Will be overwritten by the style of children elements (e.g., view, track)."},subtitle:{type:"string"},text:{anyOf:[{$ref:"#/definitions/Text"},{$ref:"#/definitions/ChannelValue"}]},title:{description:"If defined, will show the textual label on the left-top corner of a track.",type:"string"},tooltip:{items:{$ref:"#/definitions/Tooltip"},type:"array"},tracks:{anyOf:[{items:{$ref:"#/definitions/PartialTrack"},type:"array"},{items:{anyOf:[{$ref:"#/definitions/PartialTrack"},{$ref:"#/definitions/OverlaidTracks"}]},type:"array"}]},visibility:{items:{$ref:"#/definitions/VisibilityCondition"},type:"array"},width:{description:"Specify the track width in pixels.",type:"number"},x:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},x1:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},x1e:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},xAxis:{$ref:"#/definitions/AxisPosition",description:"not supported"},xDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic x-axis"},xOffset:{description:"Specify the x offset of views in the unit of pixels",type:"number"},xe:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},y:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},y1:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},y1e:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},yDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic y-axis"},yOffset:{description:"Specify the y offset of views in the unit of pixels",type:"number"},ye:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},zoomLimits:{$ref:"#/definitions/ZoomLimits"}},type:"object"}},required:["spec","selectivity"],type:"object"},type:"array"},row:{anyOf:[{$ref:"#/definitions/Row"},{$ref:"#/definitions/ChannelValue"}]},size:{anyOf:[{$ref:"#/definitions/Size"},{$ref:"#/definitions/ChannelValue"}]},spacing:{description:"The size of the gap (1) between tracks, (2) between views, and (3) of the origin of circular tracks. The effect of this property depends on where on the spec you specify the `spacing`.\n\nIn a linear layout, this value is used in pixels, while in a circular layout, this value is used relative to the height of the tracks or views.",type:"number"},startAngle:{description:'Specify the start angle (in the range of [0, 360]) of circular tracks (`{"layout": "circular"}`).',type:"number"},static:{description:"Whether to disable [Zooming and Panning](http://gosling-lang.org/docs/user-interaction#zooming-and-panning), __Default:__ `false`.",type:"boolean"},stretch:{type:"boolean"},stroke:{anyOf:[{$ref:"#/definitions/Stroke"},{$ref:"#/definitions/ChannelValue"}]},strokeWidth:{anyOf:[{$ref:"#/definitions/StrokeWidth"},{$ref:"#/definitions/ChannelValue"}]},style:{$ref:"#/definitions/Style",description:"Define the [style](http://gosling-lang.org/docs/visual-channel#style-related-properties) of multive views. Will be overwritten by the style of children elements (e.g., view, track)."},subtitle:{type:"string"},text:{anyOf:[{$ref:"#/definitions/Text"},{$ref:"#/definitions/ChannelValue"}]},title:{description:"If defined, will show the textual label on the left-top corner of a track.",type:"string"},tooltip:{items:{$ref:"#/definitions/Tooltip"},type:"array"},tracks:{items:{$ref:"#/definitions/PartialTrack"},type:"array"},visibility:{items:{$ref:"#/definitions/VisibilityCondition"},type:"array"},width:{description:"Specify the track width in pixels.",type:"number"},x:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},x1:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},x1e:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},xAxis:{$ref:"#/definitions/AxisPosition",description:"not supported"},xDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic x-axis"},xOffset:{description:"Specify the x offset of views in the unit of pixels",type:"number"},xe:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},y:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},y1:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},y1e:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},yDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic y-axis"},yOffset:{description:"Specify the y offset of views in the unit of pixels",type:"number"},ye:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},zoomLimits:{$ref:"#/definitions/ZoomLimits"}},required:["alignment","tracks"],type:"object"},{additionalProperties:!1,properties:{_assignedHeight:{type:"number"},_assignedWidth:{description:"Internal: Used for responsive spec",type:"number"},_invalidTrack:{description:"internal",type:"boolean"},_renderingId:{description:"internal",type:"string"},alignment:{const:"stack",type:"string"},assembly:{$ref:"#/definitions/Assembly",description:'A string that specifies the genome builds to use. Currently support `"hg38"`, `"hg19"`, `"hg18"`, `"hg17"`, `"hg16"`, `"mm10"`, `"mm9"`, and `"unknown"`.\n\n__Note:__: with `"unknown"` assembly, genomic axes do not show chrN: in labels.'},baselineY:{type:"number"},centerRadius:{description:"Proportion of the radius of the center white space.\n\n__Default:__ `0.3`",type:"number"},color:{anyOf:[{$ref:"#/definitions/Color"},{$ref:"#/definitions/ChannelValue"}]},data:{$ref:"#/definitions/DataDeep"},dataTransform:{items:{$ref:"#/definitions/DataTransform"},type:"array"},description:{type:"string"},displacement:{$ref:"#/definitions/Displacement"},endAngle:{description:'Specify the end angle (in the range of [0, 360]) of circular tracks (`{"layout": "circular"}`).',type:"number"},experimental:{additionalProperties:!1,properties:{mouseEvents:{anyOf:[{type:"boolean"},{$ref:"#/definitions/MouseEventsDeep"}]},performanceMode:{default:!1,description:"Render visual marks with less smooth curves to increase rendering performance. Only supported for `elliptical` `linkStyle` `withinLink` currently.",type:"boolean"}},type:"object"},flipY:{type:"boolean"},height:{description:"Specify the track height in pixels.",type:"number"},id:{description:"The ID of a view that is maintained for the use of JS API functions, e.g., positions of a view",type:"string"},innerRadius:{description:'Specify the inner radius of tracks when (`{"layout": "circular"}`).',type:"number"},layout:{$ref:"#/definitions/Layout",description:"Specify the layout type of all tracks."},linkingId:{description:"Specify an ID for [linking multiple views](http://gosling-lang.org/docs/user-interaction#linking-views)",type:"string"},mark:{$ref:"#/definitions/Mark"},opacity:{anyOf:[{$ref:"#/definitions/Opacity"},{$ref:"#/definitions/ChannelValue"}]},orientation:{$ref:"#/definitions/Orientation",description:"Specify the orientation."},outerRadius:{description:'Specify the outer radius of tracks when `{"layout": "circular"}`.',type:"number"},overlayOnPreviousTrack:{type:"boolean"},overrideTemplate:{type:"boolean"},prerelease:{additionalProperties:!1,description:"internal",type:"object"},responsiveSize:{$ref:"#/definitions/ResponsiveSize",description:"Determine whether to make the size of `GoslingComponent` bound to its parent element. __Default__: `false`"},responsiveSpec:{items:{additionalProperties:!1,properties:{selectivity:{items:{$ref:"#/definitions/SelectivityCondition"},type:"array"},spec:{additionalProperties:!1,properties:{_assignedHeight:{type:"number"},_assignedWidth:{description:"Internal: Used for responsive spec",type:"number"},_invalidTrack:{description:"internal",type:"boolean"},_renderingId:{description:"internal",type:"string"},alignment:{enum:["overlay","stack"],type:"string"},assembly:{$ref:"#/definitions/Assembly",description:'A string that specifies the genome builds to use. Currently support `"hg38"`, `"hg19"`, `"hg18"`, `"hg17"`, `"hg16"`, `"mm10"`, `"mm9"`, and `"unknown"`.\n\n__Note:__: with `"unknown"` assembly, genomic axes do not show chrN: in labels.'},baselineY:{type:"number"},centerRadius:{description:"Proportion of the radius of the center white space.\n\n__Default:__ `0.3`",type:"number"},color:{anyOf:[{$ref:"#/definitions/Color"},{$ref:"#/definitions/ChannelValue"}]},data:{$ref:"#/definitions/DataDeep"},dataTransform:{items:{$ref:"#/definitions/DataTransform"},type:"array"},displacement:{$ref:"#/definitions/Displacement"},endAngle:{description:'Specify the end angle (in the range of [0, 360]) of circular tracks (`{"layout": "circular"}`).',type:"number"},experimental:{additionalProperties:!1,properties:{mouseEvents:{anyOf:[{type:"boolean"},{$ref:"#/definitions/MouseEventsDeep"}]},performanceMode:{default:!1,description:"Render visual marks with less smooth curves to increase rendering performance. Only supported for `elliptical` `linkStyle` `withinLink` currently.",type:"boolean"}},type:"object"},flipY:{type:"boolean"},height:{description:"Specify the track height in pixels.",type:"number"},id:{description:"The ID of a view that is maintained for the use of JS API functions, e.g., positions of a view",type:"string"},innerRadius:{description:'Specify the inner radius of tracks when (`{"layout": "circular"}`).',type:"number"},layout:{$ref:"#/definitions/Layout",description:"Specify the layout type of all tracks."},linkingId:{description:"Specify an ID for [linking multiple views](http://gosling-lang.org/docs/user-interaction#linking-views)",type:"string"},mark:{$ref:"#/definitions/Mark"},opacity:{anyOf:[{$ref:"#/definitions/Opacity"},{$ref:"#/definitions/ChannelValue"}]},orientation:{$ref:"#/definitions/Orientation",description:"Specify the orientation."},outerRadius:{description:'Specify the outer radius of tracks when `{"layout": "circular"}`.',type:"number"},overlayOnPreviousTrack:{type:"boolean"},overrideTemplate:{type:"boolean"},prerelease:{additionalProperties:!1,description:"internal",type:"object"},row:{anyOf:[{$ref:"#/definitions/Row"},{$ref:"#/definitions/ChannelValue"}]},size:{anyOf:[{$ref:"#/definitions/Size"},{$ref:"#/definitions/ChannelValue"}]},spacing:{description:"The size of the gap (1) between tracks, (2) between views, and (3) of the origin of circular tracks. The effect of this property depends on where on the spec you specify the `spacing`.\n\nIn a linear layout, this value is used in pixels, while in a circular layout, this value is used relative to the height of the tracks or views.",type:"number"},startAngle:{description:'Specify the start angle (in the range of [0, 360]) of circular tracks (`{"layout": "circular"}`).',type:"number"},static:{description:"Whether to disable [Zooming and Panning](http://gosling-lang.org/docs/user-interaction#zooming-and-panning), __Default:__ `false`.",type:"boolean"},stretch:{type:"boolean"},stroke:{anyOf:[{$ref:"#/definitions/Stroke"},{$ref:"#/definitions/ChannelValue"}]},strokeWidth:{anyOf:[{$ref:"#/definitions/StrokeWidth"},{$ref:"#/definitions/ChannelValue"}]},style:{$ref:"#/definitions/Style",description:"Define the [style](http://gosling-lang.org/docs/visual-channel#style-related-properties) of multive views. Will be overwritten by the style of children elements (e.g., view, track)."},subtitle:{type:"string"},text:{anyOf:[{$ref:"#/definitions/Text"},{$ref:"#/definitions/ChannelValue"}]},title:{description:"If defined, will show the textual label on the left-top corner of a track.",type:"string"},tooltip:{items:{$ref:"#/definitions/Tooltip"},type:"array"},tracks:{anyOf:[{items:{$ref:"#/definitions/PartialTrack"},type:"array"},{items:{anyOf:[{$ref:"#/definitions/PartialTrack"},{$ref:"#/definitions/OverlaidTracks"}]},type:"array"}]},visibility:{items:{$ref:"#/definitions/VisibilityCondition"},type:"array"},width:{description:"Specify the track width in pixels.",type:"number"},x:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},x1:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},x1e:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},xAxis:{$ref:"#/definitions/AxisPosition",description:"not supported"},xDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic x-axis"},xOffset:{description:"Specify the x offset of views in the unit of pixels",type:"number"},xe:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},y:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},y1:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},y1e:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},yDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic y-axis"},yOffset:{description:"Specify the y offset of views in the unit of pixels",type:"number"},ye:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},zoomLimits:{$ref:"#/definitions/ZoomLimits"}},type:"object"}},required:["spec","selectivity"],type:"object"},type:"array"},row:{anyOf:[{$ref:"#/definitions/Row"},{$ref:"#/definitions/ChannelValue"}]},size:{anyOf:[{$ref:"#/definitions/Size"},{$ref:"#/definitions/ChannelValue"}]},spacing:{description:"The size of the gap (1) between tracks, (2) between views, and (3) of the origin of circular tracks. The effect of this property depends on where on the spec you specify the `spacing`.\n\nIn a linear layout, this value is used in pixels, while in a circular layout, this value is used relative to the height of the tracks or views.",type:"number"},startAngle:{description:'Specify the start angle (in the range of [0, 360]) of circular tracks (`{"layout": "circular"}`).',type:"number"},static:{description:"Whether to disable [Zooming and Panning](http://gosling-lang.org/docs/user-interaction#zooming-and-panning), __Default:__ `false`.",type:"boolean"},stretch:{type:"boolean"},stroke:{anyOf:[{$ref:"#/definitions/Stroke"},{$ref:"#/definitions/ChannelValue"}]},strokeWidth:{anyOf:[{$ref:"#/definitions/StrokeWidth"},{$ref:"#/definitions/ChannelValue"}]},style:{$ref:"#/definitions/Style",description:"Define the [style](http://gosling-lang.org/docs/visual-channel#style-related-properties) of multive views. Will be overwritten by the style of children elements (e.g., view, track)."},subtitle:{type:"string"},text:{anyOf:[{$ref:"#/definitions/Text"},{$ref:"#/definitions/ChannelValue"}]},title:{description:"If defined, will show the textual label on the left-top corner of a track.",type:"string"},tooltip:{items:{$ref:"#/definitions/Tooltip"},type:"array"},tracks:{items:{anyOf:[{$ref:"#/definitions/PartialTrack"},{$ref:"#/definitions/OverlaidTracks"}]},type:"array"},visibility:{items:{$ref:"#/definitions/VisibilityCondition"},type:"array"},width:{description:"Specify the track width in pixels.",type:"number"},x:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},x1:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},x1e:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},xAxis:{$ref:"#/definitions/AxisPosition",description:"not supported"},xDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic x-axis"},xOffset:{description:"Specify the x offset of views in the unit of pixels",type:"number"},xe:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},y:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},y1:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},y1e:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},yDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic y-axis"},yOffset:{description:"Specify the y offset of views in the unit of pixels",type:"number"},ye:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},zoomLimits:{$ref:"#/definitions/ZoomLimits"}},required:["tracks"],type:"object"},{additionalProperties:!1,properties:{_assignedHeight:{type:"number"},_assignedWidth:{description:"Internal: Used for responsive spec",type:"number"},assembly:{$ref:"#/definitions/Assembly",description:'A string that specifies the genome builds to use. Currently support `"hg38"`, `"hg19"`, `"hg18"`, `"hg17"`, `"hg16"`, `"mm10"`, `"mm9"`, and `"unknown"`.\n\n__Note:__: with `"unknown"` assembly, genomic axes do not show chrN: in labels.'},centerRadius:{description:"Proportion of the radius of the center white space.\n\n__Default:__ `0.3`",type:"number"},description:{type:"string"},id:{description:"The ID of a view that is maintained for the use of JS API functions, e.g., positions of a view",type:"string"},layout:{$ref:"#/definitions/Layout",description:"Specify the layout type of all tracks."},linkingId:{description:"Specify an ID for [linking multiple views](http://gosling-lang.org/docs/user-interaction#linking-views)",type:"string"},orientation:{$ref:"#/definitions/Orientation",description:"Specify the orientation."},responsiveSize:{$ref:"#/definitions/ResponsiveSize",description:"Determine whether to make the size of `GoslingComponent` bound to its parent element. __Default__: `false`"},responsiveSpec:{items:{additionalProperties:!1,properties:{selectivity:{items:{$ref:"#/definitions/SelectivityCondition"},type:"array"},spec:{additionalProperties:!1,properties:{_assignedHeight:{type:"number"},_assignedWidth:{description:"Internal: Used for responsive spec",type:"number"},_invalidTrack:{description:"internal",type:"boolean"},_renderingId:{description:"internal",type:"string"},alignment:{enum:["overlay","stack"],type:"string"},assembly:{$ref:"#/definitions/Assembly",description:'A string that specifies the genome builds to use. Currently support `"hg38"`, `"hg19"`, `"hg18"`, `"hg17"`, `"hg16"`, `"mm10"`, `"mm9"`, and `"unknown"`.\n\n__Note:__: with `"unknown"` assembly, genomic axes do not show chrN: in labels.'},baselineY:{type:"number"},centerRadius:{description:"Proportion of the radius of the center white space.\n\n__Default:__ `0.3`",type:"number"},color:{anyOf:[{$ref:"#/definitions/Color"},{$ref:"#/definitions/ChannelValue"}]},data:{$ref:"#/definitions/DataDeep"},dataTransform:{items:{$ref:"#/definitions/DataTransform"},type:"array"},displacement:{$ref:"#/definitions/Displacement"},endAngle:{description:'Specify the end angle (in the range of [0, 360]) of circular tracks (`{"layout": "circular"}`).',type:"number"},experimental:{additionalProperties:!1,properties:{mouseEvents:{anyOf:[{type:"boolean"},{$ref:"#/definitions/MouseEventsDeep"}]},performanceMode:{default:!1,description:"Render visual marks with less smooth curves to increase rendering performance. Only supported for `elliptical` `linkStyle` `withinLink` currently.",type:"boolean"}},type:"object"},flipY:{type:"boolean"},height:{description:"Specify the track height in pixels.",type:"number"},id:{description:"The ID of a view that is maintained for the use of JS API functions, e.g., positions of a view",type:"string"},innerRadius:{description:'Specify the inner radius of tracks when (`{"layout": "circular"}`).',type:"number"},layout:{$ref:"#/definitions/Layout",description:"Specify the layout type of all tracks."},linkingId:{description:"Specify an ID for [linking multiple views](http://gosling-lang.org/docs/user-interaction#linking-views)",type:"string"},mark:{$ref:"#/definitions/Mark"},opacity:{anyOf:[{$ref:"#/definitions/Opacity"},{$ref:"#/definitions/ChannelValue"}]},orientation:{$ref:"#/definitions/Orientation",description:"Specify the orientation."},outerRadius:{description:'Specify the outer radius of tracks when `{"layout": "circular"}`.',type:"number"},overlayOnPreviousTrack:{type:"boolean"},overrideTemplate:{type:"boolean"},prerelease:{additionalProperties:!1,description:"internal",type:"object"},row:{anyOf:[{$ref:"#/definitions/Row"},{$ref:"#/definitions/ChannelValue"}]},size:{anyOf:[{$ref:"#/definitions/Size"},{$ref:"#/definitions/ChannelValue"}]},spacing:{description:"The size of the gap (1) between tracks, (2) between views, and (3) of the origin of circular tracks. The effect of this property depends on where on the spec you specify the `spacing`.\n\nIn a linear layout, this value is used in pixels, while in a circular layout, this value is used relative to the height of the tracks or views.",type:"number"},startAngle:{description:'Specify the start angle (in the range of [0, 360]) of circular tracks (`{"layout": "circular"}`).',type:"number"},static:{description:"Whether to disable [Zooming and Panning](http://gosling-lang.org/docs/user-interaction#zooming-and-panning), __Default:__ `false`.",type:"boolean"},stretch:{type:"boolean"},stroke:{anyOf:[{$ref:"#/definitions/Stroke"},{$ref:"#/definitions/ChannelValue"}]},strokeWidth:{anyOf:[{$ref:"#/definitions/StrokeWidth"},{$ref:"#/definitions/ChannelValue"}]},style:{$ref:"#/definitions/Style",description:"Define the [style](http://gosling-lang.org/docs/visual-channel#style-related-properties) of multive views. Will be overwritten by the style of children elements (e.g., view, track)."},subtitle:{type:"string"},text:{anyOf:[{$ref:"#/definitions/Text"},{$ref:"#/definitions/ChannelValue"}]},title:{description:"If defined, will show the textual label on the left-top corner of a track.",type:"string"},tooltip:{items:{$ref:"#/definitions/Tooltip"},type:"array"},tracks:{anyOf:[{items:{$ref:"#/definitions/PartialTrack"},type:"array"},{items:{anyOf:[{$ref:"#/definitions/PartialTrack"},{$ref:"#/definitions/OverlaidTracks"}]},type:"array"}]},visibility:{items:{$ref:"#/definitions/VisibilityCondition"},type:"array"},width:{description:"Specify the track width in pixels.",type:"number"},x:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},x1:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},x1e:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},xAxis:{$ref:"#/definitions/AxisPosition",description:"not supported"},xDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic x-axis"},xOffset:{description:"Specify the x offset of views in the unit of pixels",type:"number"},xe:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},y:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},y1:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},y1e:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},yDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic y-axis"},yOffset:{description:"Specify the y offset of views in the unit of pixels",type:"number"},ye:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},zoomLimits:{$ref:"#/definitions/ZoomLimits"}},type:"object"}},required:["spec","selectivity"],type:"object"},type:"array"},spacing:{description:"The size of the gap (1) between tracks, (2) between views, and (3) of the origin of circular tracks. The effect of this property depends on where on the spec you specify the `spacing`.\n\nIn a linear layout, this value is used in pixels, while in a circular layout, this value is used relative to the height of the tracks or views.",type:"number"},static:{description:"Whether to disable [Zooming and Panning](http://gosling-lang.org/docs/user-interaction#zooming-and-panning), __Default:__ `false`.",type:"boolean"},style:{$ref:"#/definitions/Style",description:"Define the [style](http://gosling-lang.org/docs/visual-channel#style-related-properties) of multive views. Will be overwritten by the style of children elements (e.g., view, track)."},subtitle:{type:"string"},title:{type:"string"},tracks:{items:{$ref:"#/definitions/Track"},type:"array"},xAxis:{$ref:"#/definitions/AxisPosition",description:"not supported"},xDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic x-axis"},xOffset:{description:"Specify the x offset of views in the unit of pixels",type:"number"},yDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic y-axis"},yOffset:{description:"Specify the y offset of views in the unit of pixels",type:"number"},zoomLimits:{$ref:"#/definitions/ZoomLimits"}},required:["tracks"],type:"object"},{additionalProperties:!1,properties:{_assignedHeight:{type:"number"},_assignedWidth:{description:"Internal: Used for responsive spec",type:"number"},arrangement:{description:"Specify how multiple views are arranged.",enum:["parallel","serial","horizontal","vertical"],type:"string"},assembly:{$ref:"#/definitions/Assembly",description:'A string that specifies the genome builds to use. Currently support `"hg38"`, `"hg19"`, `"hg18"`, `"hg17"`, `"hg16"`, `"mm10"`, `"mm9"`, and `"unknown"`.\n\n__Note:__: with `"unknown"` assembly, genomic axes do not show chrN: in labels.'},centerRadius:{description:"Proportion of the radius of the center white space.\n\n__Default:__ `0.3`",type:"number"},description:{type:"string"},id:{description:"The ID of a view that is maintained for the use of JS API functions, e.g., positions of a view",type:"string"},layout:{$ref:"#/definitions/Layout",description:"Specify the layout type of all tracks."},linkingId:{description:"Specify an ID for [linking multiple views](http://gosling-lang.org/docs/user-interaction#linking-views)",type:"string"},orientation:{$ref:"#/definitions/Orientation",description:"Specify the orientation."},responsiveSize:{$ref:"#/definitions/ResponsiveSize",description:"Determine whether to make the size of `GoslingComponent` bound to its parent element. __Default__: `false`"},responsiveSpec:{items:{additionalProperties:!1,properties:{selectivity:{items:{$ref:"#/definitions/SelectivityCondition"},type:"array"},spec:{additionalProperties:!1,properties:{_assignedHeight:{type:"number"},_assignedWidth:{description:"Internal: Used for responsive spec",type:"number"},arrangement:{description:"Specify how multiple views are arranged.",enum:["parallel","serial","horizontal","vertical"],type:"string"},assembly:{$ref:"#/definitions/Assembly",description:'A string that specifies the genome builds to use. Currently support `"hg38"`, `"hg19"`, `"hg18"`, `"hg17"`, `"hg16"`, `"mm10"`, `"mm9"`, and `"unknown"`.\n\n__Note:__: with `"unknown"` assembly, genomic axes do not show chrN: in labels.'},centerRadius:{description:"Proportion of the radius of the center white space.\n\n__Default:__ `0.3`",type:"number"},id:{description:"The ID of a view that is maintained for the use of JS API functions, e.g., positions of a view",type:"string"},layout:{$ref:"#/definitions/Layout",description:"Specify the layout type of all tracks."},linkingId:{description:"Specify an ID for [linking multiple views](http://gosling-lang.org/docs/user-interaction#linking-views)",type:"string"},orientation:{$ref:"#/definitions/Orientation",description:"Specify the orientation."},spacing:{description:"The size of the gap (1) between tracks, (2) between views, and (3) of the origin of circular tracks. The effect of this property depends on where on the spec you specify the `spacing`.\n\nIn a linear layout, this value is used in pixels, while in a circular layout, this value is used relative to the height of the tracks or views.",type:"number"},static:{description:"Whether to disable [Zooming and Panning](http://gosling-lang.org/docs/user-interaction#zooming-and-panning), __Default:__ `false`.",type:"boolean"},style:{$ref:"#/definitions/Style",description:"Define the [style](http://gosling-lang.org/docs/visual-channel#style-related-properties) of multive views. Will be overwritten by the style of children elements (e.g., view, track)."},views:{description:"An array of view specifications",items:{anyOf:[{$ref:"#/definitions/SingleView"},{$ref:"#/definitions/MultipleViews"}]},type:"array"},xAxis:{$ref:"#/definitions/AxisPosition",description:"not supported"},xDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic x-axis"},xOffset:{description:"Specify the x offset of views in the unit of pixels",type:"number"},yDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic y-axis"},yOffset:{description:"Specify the y offset of views in the unit of pixels",type:"number"},zoomLimits:{$ref:"#/definitions/ZoomLimits"}},type:"object"}},required:["spec","selectivity"],type:"object"},type:"array"},spacing:{description:"The size of the gap (1) between tracks, (2) between views, and (3) of the origin of circular tracks. The effect of this property depends on where on the spec you specify the `spacing`.\n\nIn a linear layout, this value is used in pixels, while in a circular layout, this value is used relative to the height of the tracks or views.",type:"number"},static:{description:"Whether to disable [Zooming and Panning](http://gosling-lang.org/docs/user-interaction#zooming-and-panning), __Default:__ `false`.",type:"boolean"},style:{$ref:"#/definitions/Style",description:"Define the [style](http://gosling-lang.org/docs/visual-channel#style-related-properties) of multive views. Will be overwritten by the style of children elements (e.g., view, track)."},subtitle:{type:"string"},title:{type:"string"},views:{description:"An array of view specifications",items:{anyOf:[{$ref:"#/definitions/SingleView"},{$ref:"#/definitions/MultipleViews"}]},type:"array"},xAxis:{$ref:"#/definitions/AxisPosition",description:"not supported"},xDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic x-axis"},xOffset:{description:"Specify the x offset of views in the unit of pixels",type:"number"},yDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic y-axis"},yOffset:{description:"Specify the y offset of views in the unit of pixels",type:"number"},zoomLimits:{$ref:"#/definitions/ZoomLimits"}},required:["views"],type:"object"}]},IncludeFilter:{additionalProperties:!1,properties:{field:{description:"A filter is applied based on the values of the specified data field",type:"string"},include:{description:"Check whether the value includes a substring.",type:"string"},not:{description:'when `{"not": true}`, apply a NOT logical operation to the filter.\n\n__Default:__ `false`',type:"boolean"},type:{const:"filter",type:"string"}},required:["field","include","type"],type:"object"},JsonData:{additionalProperties:!1,description:"The JSON data format allows users to include data directly in the Gosling's JSON specification.",properties:{chromosomeField:{description:"Specify the name of chromosome data fields.",type:"string"},genomicFields:{description:"Specify the name of genomic data fields.",items:{type:"string"},type:"array"},genomicFieldsToConvert:{description:"experimental",items:{additionalProperties:!1,properties:{chromosomeField:{type:"string"},genomicFields:{items:{type:"string"},type:"array"}},required:["chromosomeField","genomicFields"],type:"object"},type:"array"},sampleLength:{description:"Specify the number of rows loaded from the URL.\n\n__Default:__ `1000`",type:"number"},type:{const:"json",description:"Define data type.",type:"string"},values:{description:"Values in the form of JSON.",items:{$ref:"#/definitions/Datum"},type:"array"}},required:["type","values"],type:"object"},JsonParseTransform:{additionalProperties:!1,description:"Parse JSON Object Array and append vertically",properties:{baseGenomicField:{description:"Base genomic position when parsing relative position.",type:"string"},field:{description:"The field that contains the JSON object array.",type:"string"},genomicField:{description:"Relative genomic position to parse.",type:"string"},genomicLengthField:{description:"Length of genomic interval.",type:"string"},type:{const:"subjson",type:"string"}},required:["type","field","baseGenomicField","genomicField","genomicLengthField"],type:"object"},Layout:{enum:["linear","circular"],type:"string"},LogBase:{anyOf:[{type:"number"},{const:"e",type:"string"}]},LogTransform:{additionalProperties:!1,properties:{base:{$ref:"#/definitions/LogBase",description:"If not specified, 10 is used."},field:{type:"string"},newField:{description:"If specified, store transformed values in a new field.",type:"string"},type:{const:"log",type:"string"}},required:["type","field"],type:"object"},LogicalOperation:{enum:["less-than","lt","LT","greater-than","gt","GT","less-than-or-equal-to","ltet","LTET","greater-than-or-equal-to","gtet","GTET"],type:"string"},Mark:{enum:["point","line","area","bar","rect","text","withinLink","betweenLink","rule","triangleLeft","triangleRight","triangleBottom","brush","header"],type:"string"},MatrixData:{additionalProperties:!1,properties:{binSize:{description:"Determine the number of nearby cells to aggregate. __Default__: `1`",type:"number"},column:{description:"The name of the first genomic field. __Default__: `x`",type:"string"},row:{description:"The name of the first genomic field. __Default__: `y`",type:"string"},type:{const:"matrix",type:"string"},url:{description:"URL link to the matrix data file",type:"string"},value:{description:"The name of the value field. __Default__: `value`",type:"string"}},required:["type","url"],type:"object"},MouseEventsDeep:{additionalProperties:!1,description:"Options for determining mouse events in detail, e.g., turning on specific events only",properties:{click:{description:"Whether to enable click events.",type:"boolean"},enableMouseOverOnMultipleMarks:{description:"Determine whether all marks underneath the mouse point should be affected by mouse over. __Default__: `false`",type:"boolean"},groupMarksByField:{description:"Group marks using keys in a data field. This affects how a set of marks are highlighted/selected by interaction. __Default__: `undefined`",type:"string"},mouseOver:{description:"Whether to enable mouseover events.",type:"boolean"},rangeSelect:{description:"Whether to send range selection events.",type:"boolean"}},type:"object"},MultipleViews:{additionalProperties:!1,properties:{_assignedHeight:{type:"number"},_assignedWidth:{description:"Internal: Used for responsive spec",type:"number"},arrangement:{description:"Specify how multiple views are arranged.",enum:["parallel","serial","horizontal","vertical"],type:"string"},assembly:{$ref:"#/definitions/Assembly",description:'A string that specifies the genome builds to use. Currently support `"hg38"`, `"hg19"`, `"hg18"`, `"hg17"`, `"hg16"`, `"mm10"`, `"mm9"`, and `"unknown"`.\n\n__Note:__: with `"unknown"` assembly, genomic axes do not show chrN: in labels.'},centerRadius:{description:"Proportion of the radius of the center white space.\n\n__Default:__ `0.3`",type:"number"},id:{description:"The ID of a view that is maintained for the use of JS API functions, e.g., positions of a view",type:"string"},layout:{$ref:"#/definitions/Layout",description:"Specify the layout type of all tracks."},linkingId:{description:"Specify an ID for [linking multiple views](http://gosling-lang.org/docs/user-interaction#linking-views)",type:"string"},orientation:{$ref:"#/definitions/Orientation",description:"Specify the orientation."},spacing:{description:"The size of the gap (1) between tracks, (2) between views, and (3) of the origin of circular tracks. The effect of this property depends on where on the spec you specify the `spacing`.\n\nIn a linear layout, this value is used in pixels, while in a circular layout, this value is used relative to the height of the tracks or views.",type:"number"},static:{description:"Whether to disable [Zooming and Panning](http://gosling-lang.org/docs/user-interaction#zooming-and-panning), __Default:__ `false`.",type:"boolean"},style:{$ref:"#/definitions/Style",description:"Define the [style](http://gosling-lang.org/docs/visual-channel#style-related-properties) of multive views. Will be overwritten by the style of children elements (e.g., view, track)."},views:{description:"An array of view specifications",items:{anyOf:[{$ref:"#/definitions/SingleView"},{$ref:"#/definitions/MultipleViews"}]},type:"array"},xAxis:{$ref:"#/definitions/AxisPosition",description:"not supported"},xDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic x-axis"},xOffset:{description:"Specify the x offset of views in the unit of pixels",type:"number"},yDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic y-axis"},yOffset:{description:"Specify the y offset of views in the unit of pixels",type:"number"},zoomLimits:{$ref:"#/definitions/ZoomLimits"}},required:["views"],type:"object"},MultivecData:{additionalProperties:!1,description:'Two-dimensional quantitative values, one axis for genomic coordinate and the other for different samples, can be converted into HiGlass\' `"multivec"` data. For example, multiple BigWig files can be converted into a single multivec file. You can also convert sequence data (FASTA) into this format where rows will be different nucleotide bases (e.g., A, T, G, C) and quantitative values represent the frequency. Find out more about this format at [HiGlass Docs](https://docs.higlass.io/data_preparation.html#multivec-files).',properties:{aggregation:{$ref:"#/definitions/BinAggregate",description:'Determine aggregation function to apply within bins. __Default__: `"mean"`'},binSize:{description:"Binning the genomic interval in tiles (unit size: 256).",type:"number"},categories:{description:"assign names of individual samples.",items:{type:"string"},type:"array"},column:{description:'Assign a field name of the middle position of genomic intervals. __Default__: `"position"`',type:"string"},end:{description:'Assign a field name of the end position of genomic intervals. __Default__: `"end"`',type:"string"},row:{description:'Assign a field name of samples. __Default__: `"category"`',type:"string"},start:{description:'Assign a field name of the start position of genomic intervals. __Default__: `"start"`',type:"string"},type:{const:"multivec",type:"string"},url:{description:"Specify the URL address of the data file.",type:"string"},value:{description:'Assign a field name of quantitative values. __Default__: `"value"`',type:"string"}},required:["type","url"],type:"object"},OneOfFilter:{additionalProperties:!1,properties:{field:{description:"A filter is applied based on the values of the specified data field",type:"string"},not:{description:'when `{"not": true}`, apply a NOT logical operation to the filter.\n\n__Default:__ `false`',type:"boolean"},oneOf:{description:"Check whether the value is an element in the provided list.",items:{type:["string","number","null"]},type:"array"},type:{const:"filter",type:"string"}},required:["field","oneOf","type"],type:"object"},Opacity:{additionalProperties:!1,properties:{domain:{$ref:"#/definitions/ValueExtent",description:"Values of the data"},field:{description:"Name of the data field",type:"string"},range:{$ref:"#/definitions/ValueExtent",description:"Ranges of visual channel values"},type:{description:"Specify the data type",enum:["quantitative","nominal"],type:"string"}},type:"object"},Orientation:{enum:["horizontal","vertical"],type:"string"},OverlaidTrack:{additionalProperties:!1,description:"Superposing multiple tracks.",properties:{_assignedHeight:{type:"number"},_assignedWidth:{description:"Internal: Used for responsive spec",type:"number"},_invalidTrack:{description:"internal",type:"boolean"},_overlay:{items:{additionalProperties:!1,properties:{_assignedHeight:{type:"number"},_assignedWidth:{description:"Internal: Used for responsive spec",type:"number"},_invalidTrack:{description:"internal",type:"boolean"},_renderingId:{description:"internal",type:"string"},assembly:{$ref:"#/definitions/Assembly",description:'A string that specifies the genome builds to use. Currently support `"hg38"`, `"hg19"`, `"hg18"`, `"hg17"`, `"hg16"`, `"mm10"`, `"mm9"`, and `"unknown"`.\n\n__Note:__: with `"unknown"` assembly, genomic axes do not show chrN: in labels.'},baselineY:{type:"number"},centerRadius:{description:"Proportion of the radius of the center white space.\n\n__Default:__ `0.3`",type:"number"},color:{anyOf:[{$ref:"#/definitions/Color"},{$ref:"#/definitions/ChannelValue"}]},data:{$ref:"#/definitions/DataDeep"},dataTransform:{items:{$ref:"#/definitions/DataTransform"},type:"array"},displacement:{$ref:"#/definitions/Displacement"},endAngle:{description:'Specify the end angle (in the range of [0, 360]) of circular tracks (`{"layout": "circular"}`).',type:"number"},experimental:{additionalProperties:!1,properties:{mouseEvents:{anyOf:[{type:"boolean"},{$ref:"#/definitions/MouseEventsDeep"}]},performanceMode:{default:!1,description:"Render visual marks with less smooth curves to increase rendering performance. Only supported for `elliptical` `linkStyle` `withinLink` currently.",type:"boolean"}},type:"object"},flipY:{type:"boolean"},id:{description:"Assigned to `uid` in a HiGlass view config, used for API and caching.",type:"string"},innerRadius:{description:'Specify the inner radius of tracks when (`{"layout": "circular"}`).',type:"number"},linkingId:{description:"Specify an ID for [linking multiple views](http://gosling-lang.org/docs/user-interaction#linking-views)",type:"string"},mark:{$ref:"#/definitions/Mark"},opacity:{anyOf:[{$ref:"#/definitions/Opacity"},{$ref:"#/definitions/ChannelValue"}]},orientation:{$ref:"#/definitions/Orientation",description:"Specify the orientation."},outerRadius:{description:'Specify the outer radius of tracks when `{"layout": "circular"}`.',type:"number"},overlayOnPreviousTrack:{type:"boolean"},overrideTemplate:{type:"boolean"},prerelease:{additionalProperties:!1,description:"internal",type:"object"},row:{anyOf:[{$ref:"#/definitions/Row"},{$ref:"#/definitions/ChannelValue"}]},size:{anyOf:[{$ref:"#/definitions/Size"},{$ref:"#/definitions/ChannelValue"}]},spacing:{description:"The size of the gap (1) between tracks, (2) between views, and (3) of the origin of circular tracks. The effect of this property depends on where on the spec you specify the `spacing`.\n\nIn a linear layout, this value is used in pixels, while in a circular layout, this value is used relative to the height of the tracks or views.",type:"number"},startAngle:{description:'Specify the start angle (in the range of [0, 360]) of circular tracks (`{"layout": "circular"}`).',type:"number"},static:{description:"Whether to disable [Zooming and Panning](http://gosling-lang.org/docs/user-interaction#zooming-and-panning), __Default:__ `false`.",type:"boolean"},stretch:{type:"boolean"},stroke:{anyOf:[{$ref:"#/definitions/Stroke"},{$ref:"#/definitions/ChannelValue"}]},strokeWidth:{anyOf:[{$ref:"#/definitions/StrokeWidth"},{$ref:"#/definitions/ChannelValue"}]},style:{$ref:"#/definitions/Style",description:"Define the [style](http://gosling-lang.org/docs/visual-channel#style-related-properties) of multive views. Will be overwritten by the style of children elements (e.g., view, track)."},text:{anyOf:[{$ref:"#/definitions/Text"},{$ref:"#/definitions/ChannelValue"}]},tooltip:{items:{$ref:"#/definitions/Tooltip"},type:"array"},visibility:{items:{$ref:"#/definitions/VisibilityCondition"},type:"array"},x:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},x1:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},x1e:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},xAxis:{$ref:"#/definitions/AxisPosition",description:"not supported"},xDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic x-axis"},xOffset:{description:"Specify the x offset of views in the unit of pixels",type:"number"},xe:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},y:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},y1:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},y1e:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},yDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic y-axis"},yOffset:{description:"Specify the y offset of views in the unit of pixels",type:"number"},ye:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},zoomLimits:{$ref:"#/definitions/ZoomLimits"}},type:"object"},type:"array"},_renderingId:{description:"internal",type:"string"},assembly:{$ref:"#/definitions/Assembly",description:'A string that specifies the genome builds to use. Currently support `"hg38"`, `"hg19"`, `"hg18"`, `"hg17"`, `"hg16"`, `"mm10"`, `"mm9"`, and `"unknown"`.\n\n__Note:__: with `"unknown"` assembly, genomic axes do not show chrN: in labels.'},baselineY:{type:"number"},centerRadius:{description:"Proportion of the radius of the center white space.\n\n__Default:__ `0.3`",type:"number"},color:{anyOf:[{$ref:"#/definitions/Color"},{$ref:"#/definitions/ChannelValue"}]},data:{$ref:"#/definitions/DataDeep"},dataTransform:{items:{$ref:"#/definitions/DataTransform"},type:"array"},displacement:{$ref:"#/definitions/Displacement"},endAngle:{description:'Specify the end angle (in the range of [0, 360]) of circular tracks (`{"layout": "circular"}`).',type:"number"},experimental:{additionalProperties:!1,properties:{mouseEvents:{anyOf:[{type:"boolean"},{$ref:"#/definitions/MouseEventsDeep"}]},performanceMode:{default:!1,description:"Render visual marks with less smooth curves to increase rendering performance. Only supported for `elliptical` `linkStyle` `withinLink` currently.",type:"boolean"}},type:"object"},flipY:{type:"boolean"},height:{description:"Specify the track height in pixels.",type:"number"},id:{description:"Assigned to `uid` in a HiGlass view config, used for API and caching.",type:"string"},innerRadius:{description:'Specify the inner radius of tracks when (`{"layout": "circular"}`).',type:"number"},layout:{$ref:"#/definitions/Layout",description:"Specify the layout type of all tracks."},linkingId:{description:"Specify an ID for [linking multiple views](http://gosling-lang.org/docs/user-interaction#linking-views)",type:"string"},mark:{$ref:"#/definitions/Mark"},opacity:{anyOf:[{$ref:"#/definitions/Opacity"},{$ref:"#/definitions/ChannelValue"}]},orientation:{$ref:"#/definitions/Orientation",description:"Specify the orientation."},outerRadius:{description:'Specify the outer radius of tracks when `{"layout": "circular"}`.',type:"number"},overlayOnPreviousTrack:{type:"boolean"},overrideTemplate:{type:"boolean"},prerelease:{additionalProperties:!1,description:"internal",type:"object"},row:{anyOf:[{$ref:"#/definitions/Row"},{$ref:"#/definitions/ChannelValue"}]},size:{anyOf:[{$ref:"#/definitions/Size"},{$ref:"#/definitions/ChannelValue"}]},spacing:{description:"The size of the gap (1) between tracks, (2) between views, and (3) of the origin of circular tracks. The effect of this property depends on where on the spec you specify the `spacing`.\n\nIn a linear layout, this value is used in pixels, while in a circular layout, this value is used relative to the height of the tracks or views.",type:"number"},startAngle:{description:'Specify the start angle (in the range of [0, 360]) of circular tracks (`{"layout": "circular"}`).',type:"number"},static:{description:"Whether to disable [Zooming and Panning](http://gosling-lang.org/docs/user-interaction#zooming-and-panning), __Default:__ `false`.",type:"boolean"},stretch:{type:"boolean"},stroke:{anyOf:[{$ref:"#/definitions/Stroke"},{$ref:"#/definitions/ChannelValue"}]},strokeWidth:{anyOf:[{$ref:"#/definitions/StrokeWidth"},{$ref:"#/definitions/ChannelValue"}]},style:{$ref:"#/definitions/Style",description:"Define the [style](http://gosling-lang.org/docs/visual-channel#style-related-properties) of multive views. Will be overwritten by the style of children elements (e.g., view, track)."},subtitle:{type:"string"},text:{anyOf:[{$ref:"#/definitions/Text"},{$ref:"#/definitions/ChannelValue"}]},title:{description:"If defined, will show the textual label on the left-top corner of a track.",type:"string"},tooltip:{items:{$ref:"#/definitions/Tooltip"},type:"array"},visibility:{items:{$ref:"#/definitions/VisibilityCondition"},type:"array"},width:{description:"Specify the track width in pixels.",type:"number"},x:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},x1:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},x1e:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},xAxis:{$ref:"#/definitions/AxisPosition",description:"not supported"},xDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic x-axis"},xOffset:{description:"Specify the x offset of views in the unit of pixels",type:"number"},xe:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},y:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},y1:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},y1e:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},yDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic y-axis"},yOffset:{description:"Specify the y offset of views in the unit of pixels",type:"number"},ye:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},zoomLimits:{$ref:"#/definitions/ZoomLimits"}},required:["_overlay"],type:"object"},OverlaidTracks:{additionalProperties:!1,properties:{_assignedHeight:{type:"number"},_assignedWidth:{description:"Internal: Used for responsive spec",type:"number"},_invalidTrack:{description:"internal",type:"boolean"},_renderingId:{description:"internal",type:"string"},alignment:{const:"overlay",type:"string"},assembly:{$ref:"#/definitions/Assembly",description:'A string that specifies the genome builds to use. Currently support `"hg38"`, `"hg19"`, `"hg18"`, `"hg17"`, `"hg16"`, `"mm10"`, `"mm9"`, and `"unknown"`.\n\n__Note:__: with `"unknown"` assembly, genomic axes do not show chrN: in labels.'},baselineY:{type:"number"},centerRadius:{description:"Proportion of the radius of the center white space.\n\n__Default:__ `0.3`",type:"number"},color:{anyOf:[{$ref:"#/definitions/Color"},{$ref:"#/definitions/ChannelValue"}]},data:{$ref:"#/definitions/DataDeep"},dataTransform:{items:{$ref:"#/definitions/DataTransform"},type:"array"},displacement:{$ref:"#/definitions/Displacement"},endAngle:{description:'Specify the end angle (in the range of [0, 360]) of circular tracks (`{"layout": "circular"}`).',type:"number"},experimental:{additionalProperties:!1,properties:{mouseEvents:{anyOf:[{type:"boolean"},{$ref:"#/definitions/MouseEventsDeep"}]},performanceMode:{default:!1,description:"Render visual marks with less smooth curves to increase rendering performance. Only supported for `elliptical` `linkStyle` `withinLink` currently.",type:"boolean"}},type:"object"},flipY:{type:"boolean"},height:{description:"Specify the track height in pixels.",type:"number"},id:{description:"The ID of a view that is maintained for the use of JS API functions, e.g., positions of a view",type:"string"},innerRadius:{description:'Specify the inner radius of tracks when (`{"layout": "circular"}`).',type:"number"},layout:{$ref:"#/definitions/Layout",description:"Specify the layout type of all tracks."},linkingId:{description:"Specify an ID for [linking multiple views](http://gosling-lang.org/docs/user-interaction#linking-views)",type:"string"},mark:{$ref:"#/definitions/Mark"},opacity:{anyOf:[{$ref:"#/definitions/Opacity"},{$ref:"#/definitions/ChannelValue"}]},orientation:{$ref:"#/definitions/Orientation",description:"Specify the orientation."},outerRadius:{description:'Specify the outer radius of tracks when `{"layout": "circular"}`.',type:"number"},overlayOnPreviousTrack:{type:"boolean"},overrideTemplate:{type:"boolean"},prerelease:{additionalProperties:!1,description:"internal",type:"object"},row:{anyOf:[{$ref:"#/definitions/Row"},{$ref:"#/definitions/ChannelValue"}]},size:{anyOf:[{$ref:"#/definitions/Size"},{$ref:"#/definitions/ChannelValue"}]},spacing:{description:"The size of the gap (1) between tracks, (2) between views, and (3) of the origin of circular tracks. The effect of this property depends on where on the spec you specify the `spacing`.\n\nIn a linear layout, this value is used in pixels, while in a circular layout, this value is used relative to the height of the tracks or views.",type:"number"},startAngle:{description:'Specify the start angle (in the range of [0, 360]) of circular tracks (`{"layout": "circular"}`).',type:"number"},static:{description:"Whether to disable [Zooming and Panning](http://gosling-lang.org/docs/user-interaction#zooming-and-panning), __Default:__ `false`.",type:"boolean"},stretch:{type:"boolean"},stroke:{anyOf:[{$ref:"#/definitions/Stroke"},{$ref:"#/definitions/ChannelValue"}]},strokeWidth:{anyOf:[{$ref:"#/definitions/StrokeWidth"},{$ref:"#/definitions/ChannelValue"}]},style:{$ref:"#/definitions/Style",description:"Define the [style](http://gosling-lang.org/docs/visual-channel#style-related-properties) of multive views. Will be overwritten by the style of children elements (e.g., view, track)."},subtitle:{type:"string"},text:{anyOf:[{$ref:"#/definitions/Text"},{$ref:"#/definitions/ChannelValue"}]},title:{description:"If defined, will show the textual label on the left-top corner of a track.",type:"string"},tooltip:{items:{$ref:"#/definitions/Tooltip"},type:"array"},tracks:{items:{$ref:"#/definitions/PartialTrack"},type:"array"},visibility:{items:{$ref:"#/definitions/VisibilityCondition"},type:"array"},width:{description:"Specify the track width in pixels.",type:"number"},x:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},x1:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},x1e:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},xAxis:{$ref:"#/definitions/AxisPosition",description:"not supported"},xDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic x-axis"},xOffset:{description:"Specify the x offset of views in the unit of pixels",type:"number"},xe:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},y:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},y1:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},y1e:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},yDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic y-axis"},yOffset:{description:"Specify the y offset of views in the unit of pixels",type:"number"},ye:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},zoomLimits:{$ref:"#/definitions/ZoomLimits"}},required:["alignment","tracks"],type:"object"},PartialTrack:{additionalProperties:!1,properties:{_assignedHeight:{type:"number"},_assignedWidth:{description:"Internal: Used for responsive spec",type:"number"},_invalidTrack:{description:"internal",type:"boolean"},_overlay:{items:{additionalProperties:!1,properties:{_assignedHeight:{type:"number"},_assignedWidth:{description:"Internal: Used for responsive spec",type:"number"},_invalidTrack:{description:"internal",type:"boolean"},_renderingId:{description:"internal",type:"string"},assembly:{$ref:"#/definitions/Assembly",description:'A string that specifies the genome builds to use. Currently support `"hg38"`, `"hg19"`, `"hg18"`, `"hg17"`, `"hg16"`, `"mm10"`, `"mm9"`, and `"unknown"`.\n\n__Note:__: with `"unknown"` assembly, genomic axes do not show chrN: in labels.'},baselineY:{type:"number"},centerRadius:{description:"Proportion of the radius of the center white space.\n\n__Default:__ `0.3`",type:"number"},color:{anyOf:[{$ref:"#/definitions/Color"},{$ref:"#/definitions/ChannelValue"}]},data:{$ref:"#/definitions/DataDeep"},dataTransform:{items:{$ref:"#/definitions/DataTransform"},type:"array"},displacement:{$ref:"#/definitions/Displacement"},endAngle:{description:'Specify the end angle (in the range of [0, 360]) of circular tracks (`{"layout": "circular"}`).',type:"number"},experimental:{additionalProperties:!1,properties:{mouseEvents:{anyOf:[{type:"boolean"},{$ref:"#/definitions/MouseEventsDeep"}]},performanceMode:{default:!1,description:"Render visual marks with less smooth curves to increase rendering performance. Only supported for `elliptical` `linkStyle` `withinLink` currently.",type:"boolean"}},type:"object"},flipY:{type:"boolean"},id:{description:"Assigned to `uid` in a HiGlass view config, used for API and caching.",type:"string"},innerRadius:{description:'Specify the inner radius of tracks when (`{"layout": "circular"}`).',type:"number"},linkingId:{description:"Specify an ID for [linking multiple views](http://gosling-lang.org/docs/user-interaction#linking-views)",type:"string"},mark:{$ref:"#/definitions/Mark"},opacity:{anyOf:[{$ref:"#/definitions/Opacity"},{$ref:"#/definitions/ChannelValue"}]},orientation:{$ref:"#/definitions/Orientation",description:"Specify the orientation."},outerRadius:{description:'Specify the outer radius of tracks when `{"layout": "circular"}`.',type:"number"},overlayOnPreviousTrack:{type:"boolean"},overrideTemplate:{type:"boolean"},prerelease:{additionalProperties:!1,description:"internal",type:"object"},row:{anyOf:[{$ref:"#/definitions/Row"},{$ref:"#/definitions/ChannelValue"}]},size:{anyOf:[{$ref:"#/definitions/Size"},{$ref:"#/definitions/ChannelValue"}]},spacing:{description:"The size of the gap (1) between tracks, (2) between views, and (3) of the origin of circular tracks. The effect of this property depends on where on the spec you specify the `spacing`.\n\nIn a linear layout, this value is used in pixels, while in a circular layout, this value is used relative to the height of the tracks or views.",type:"number"},startAngle:{description:'Specify the start angle (in the range of [0, 360]) of circular tracks (`{"layout": "circular"}`).',type:"number"},static:{description:"Whether to disable [Zooming and Panning](http://gosling-lang.org/docs/user-interaction#zooming-and-panning), __Default:__ `false`.",type:"boolean"},stretch:{type:"boolean"},stroke:{anyOf:[{$ref:"#/definitions/Stroke"},{$ref:"#/definitions/ChannelValue"}]},strokeWidth:{anyOf:[{$ref:"#/definitions/StrokeWidth"},{$ref:"#/definitions/ChannelValue"}]},style:{$ref:"#/definitions/Style",description:"Define the [style](http://gosling-lang.org/docs/visual-channel#style-related-properties) of multive views. Will be overwritten by the style of children elements (e.g., view, track)."},text:{anyOf:[{$ref:"#/definitions/Text"},{$ref:"#/definitions/ChannelValue"}]},tooltip:{items:{$ref:"#/definitions/Tooltip"},type:"array"},visibility:{items:{$ref:"#/definitions/VisibilityCondition"},type:"array"},x:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},x1:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},x1e:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},xAxis:{$ref:"#/definitions/AxisPosition",description:"not supported"},xDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic x-axis"},xOffset:{description:"Specify the x offset of views in the unit of pixels",type:"number"},xe:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},y:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},y1:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},y1e:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},yDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic y-axis"},yOffset:{description:"Specify the y offset of views in the unit of pixels",type:"number"},ye:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},zoomLimits:{$ref:"#/definitions/ZoomLimits"}},type:"object"},type:"array"},_renderingId:{description:"internal",type:"string"},assembly:{anyOf:[{$ref:"#/definitions/Assembly",description:'A string that specifies the genome builds to use. Currently support `"hg38"`, `"hg19"`, `"hg18"`, `"hg17"`, `"hg16"`, `"mm10"`, `"mm9"`, and `"unknown"`.\n\n__Note:__: with `"unknown"` assembly, genomic axes do not show chrN: in labels.'},{const:"unknown",description:"No assemblies can be associated with a dummy track",type:"string"}],description:'A string that specifies the genome builds to use. Currently support `"hg38"`, `"hg19"`, `"hg18"`, `"hg17"`, `"hg16"`, `"mm10"`, `"mm9"`, and `"unknown"`.\n\n__Note:__: with `"unknown"` assembly, genomic axes do not show chrN: in labels.'},baselineY:{type:"number"},centerRadius:{description:"Proportion of the radius of the center white space.\n\n__Default:__ `0.3`",type:"number"},color:{anyOf:[{$ref:"#/definitions/Color"},{$ref:"#/definitions/ChannelValue"}]},data:{$ref:"#/definitions/DataDeep"},dataTransform:{items:{$ref:"#/definitions/DataTransform"},type:"array"},displacement:{$ref:"#/definitions/Displacement"},encoding:{additionalProperties:{$ref:"#/definitions/Channel"},type:"object"},endAngle:{description:'Specify the end angle (in the range of [0, 360]) of circular tracks (`{"layout": "circular"}`).',type:"number"},experimental:{additionalProperties:!1,properties:{mouseEvents:{anyOf:[{type:"boolean"},{$ref:"#/definitions/MouseEventsDeep"}]},performanceMode:{default:!1,description:"Render visual marks with less smooth curves to increase rendering performance. Only supported for `elliptical` `linkStyle` `withinLink` currently.",type:"boolean"}},type:"object"},flipY:{type:"boolean"},height:{description:"Specify the track height in pixels.",type:"number"},id:{description:"Assigned to `uid` in a HiGlass view config, used for API and caching.",type:"string"},innerRadius:{description:'Specify the inner radius of tracks when (`{"layout": "circular"}`).',type:"number"},layout:{anyOf:[{$ref:"#/definitions/Layout",description:"Specify the layout type of all tracks."},{const:"linear",description:"Only linear layout are supported at this time",type:"string"}],description:"Specify the layout type of all tracks."},linkingId:{description:"Specify an ID for [linking multiple views](http://gosling-lang.org/docs/user-interaction#linking-views)",type:"string"},mark:{$ref:"#/definitions/Mark"},opacity:{anyOf:[{$ref:"#/definitions/Opacity"},{$ref:"#/definitions/ChannelValue"}]},orientation:{$ref:"#/definitions/Orientation",description:"Specify the orientation."},outerRadius:{description:'Specify the outer radius of tracks when `{"layout": "circular"}`.',type:"number"},overlayOnPreviousTrack:{type:"boolean"},overrideTemplate:{type:"boolean"},prerelease:{additionalProperties:!1,description:"internal",type:"object"},row:{anyOf:[{$ref:"#/definitions/Row"},{$ref:"#/definitions/ChannelValue"}]},size:{anyOf:[{$ref:"#/definitions/Size"},{$ref:"#/definitions/ChannelValue"}]},spacing:{description:"The size of the gap (1) between tracks, (2) between views, and (3) of the origin of circular tracks. The effect of this property depends on where on the spec you specify the `spacing`.\n\nIn a linear layout, this value is used in pixels, while in a circular layout, this value is used relative to the height of the tracks or views.",type:"number"},startAngle:{description:'Specify the start angle (in the range of [0, 360]) of circular tracks (`{"layout": "circular"}`).',type:"number"},static:{anyOf:[{description:"Whether to disable [Zooming and Panning](http://gosling-lang.org/docs/user-interaction#zooming-and-panning), __Default:__ `false`.",type:"boolean"},{const:!0,description:"Whether to disable [Zooming and Panning](http://gosling-lang.org/docs/user-interaction#zooming-and-panning), __Default:__ `false`.",type:"boolean"}],description:"Whether to disable [Zooming and Panning](http://gosling-lang.org/docs/user-interaction#zooming-and-panning), __Default:__ `false`."},stretch:{type:"boolean"},stroke:{anyOf:[{$ref:"#/definitions/Stroke"},{$ref:"#/definitions/ChannelValue"}]},strokeWidth:{anyOf:[{$ref:"#/definitions/StrokeWidth"},{$ref:"#/definitions/ChannelValue"}]},style:{anyOf:[{$ref:"#/definitions/Style",description:"Define the [style](http://gosling-lang.org/docs/visual-channel#style-related-properties) of multive views. Will be overwritten by the style of children elements (e.g., view, track)."},{$ref:"#/definitions/DummyTrackStyle",description:"Defines how the track is styled"}],description:"Define the [style](http://gosling-lang.org/docs/visual-channel#style-related-properties) of multive views. Will be overwritten by the style of children elements (e.g., view, track)."},subtitle:{type:"string"},template:{type:"string"},text:{anyOf:[{$ref:"#/definitions/Text"},{$ref:"#/definitions/ChannelValue"}]},title:{description:"If defined, will show the textual label on the left-top corner of a track.",type:"string"},tooltip:{items:{$ref:"#/definitions/Tooltip"},type:"array"},type:{const:"dummy-track",description:"Used to specify the dummy track",type:"string"},visibility:{items:{$ref:"#/definitions/VisibilityCondition"},type:"array"},width:{description:"Specify the track width in pixels.",type:"number"},x:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},x1:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},x1e:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},xAxis:{$ref:"#/definitions/AxisPosition",description:"not supported"},xDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic x-axis"},xOffset:{description:"Specify the x offset of views in the unit of pixels",type:"number"},xe:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},y:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},y1:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},y1e:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},yDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic y-axis"},yOffset:{description:"Specify the y offset of views in the unit of pixels",type:"number"},ye:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},zoomLimits:{anyOf:[{$ref:"#/definitions/ZoomLimits"},{description:"Unused property for DummyTrack",items:{type:"null"},maxItems:2,minItems:2,type:"array"}]}},type:"object"},PredefinedColors:{enum:["viridis","grey","spectral","warm","cividis","bupu","rdbu","hot","pink"],type:"string"},Range:{anyOf:[{$ref:"#/definitions/ValueExtent"},{$ref:"#/definitions/PredefinedColors"}]},RangeFilter:{additionalProperties:!1,properties:{field:{description:"A filter is applied based on the values of the specified data field",type:"string"},inRange:{description:"Check whether the value is in a number range.",items:{type:"number"},type:"array"},not:{description:'when `{"not": true}`, apply a NOT logical operation to the filter.\n\n__Default:__ `false`',type:"boolean"},type:{const:"filter",type:"string"}},required:["field","inRange","type"],type:"object"},ResponsiveSize:{anyOf:[{type:"boolean"},{additionalProperties:!1,properties:{height:{type:"boolean"},width:{type:"boolean"}},type:"object"}]},Row:{additionalProperties:!1,properties:{clip:{description:"Clip row when the actual y value exceeds the max value of the y scale. Used only for bar marks at the moment. __Default__: `true`",type:"boolean"},domain:{$ref:"#/definitions/ValueExtent",description:"Values of the data"},field:{description:"Name of the data field",type:"string"},grid:{description:"Whether to display grid. __Default__: `false`",type:"boolean"},legend:{description:"Whether to display legend. __Default__: `false`",type:"boolean"},padding:{description:"Determines the size of inner white spaces on the top and bottom of individiual rows. __Default__: `0`",type:"number"},range:{$ref:"#/definitions/ValueExtent",description:"Determine the start and end position of rendering area of this track along vertical axis. __Default__: `[0, height]`"},type:{const:"nominal",description:"Specify the data type",type:"string"}},type:"object"},SelectivityCondition:{additionalProperties:!1,properties:{measure:{enum:["width","height","aspectRatio"],type:"string"},operation:{$ref:"#/definitions/LogicalOperation"},target:{description:"Does the condition applied to the visualization itself or its container? __Default__: `'self'`",enum:["self","container"],type:"string"},threshold:{description:"Threshold in the unit of pixels.",type:"number"}},required:["operation","measure","threshold"],type:"object"},SingleTrack:{additionalProperties:!1,properties:{_assignedHeight:{type:"number"},_assignedWidth:{description:"Internal: Used for responsive spec",type:"number"},_invalidTrack:{description:"internal",type:"boolean"},_renderingId:{description:"internal",type:"string"},assembly:{$ref:"#/definitions/Assembly",description:'A string that specifies the genome builds to use. Currently support `"hg38"`, `"hg19"`, `"hg18"`, `"hg17"`, `"hg16"`, `"mm10"`, `"mm9"`, and `"unknown"`.\n\n__Note:__: with `"unknown"` assembly, genomic axes do not show chrN: in labels.'},baselineY:{type:"number"},centerRadius:{description:"Proportion of the radius of the center white space.\n\n__Default:__ `0.3`",type:"number"},color:{anyOf:[{$ref:"#/definitions/Color"},{$ref:"#/definitions/ChannelValue"}]},data:{$ref:"#/definitions/DataDeep"},dataTransform:{items:{$ref:"#/definitions/DataTransform"},type:"array"},displacement:{$ref:"#/definitions/Displacement"},endAngle:{description:'Specify the end angle (in the range of [0, 360]) of circular tracks (`{"layout": "circular"}`).',type:"number"},experimental:{additionalProperties:!1,properties:{mouseEvents:{anyOf:[{type:"boolean"},{$ref:"#/definitions/MouseEventsDeep"}]},performanceMode:{default:!1,description:"Render visual marks with less smooth curves to increase rendering performance. Only supported for `elliptical` `linkStyle` `withinLink` currently.",type:"boolean"}},type:"object"},flipY:{type:"boolean"},height:{description:"Specify the track height in pixels.",type:"number"},id:{description:"Assigned to `uid` in a HiGlass view config, used for API and caching.",type:"string"},innerRadius:{description:'Specify the inner radius of tracks when (`{"layout": "circular"}`).',type:"number"},layout:{$ref:"#/definitions/Layout",description:"Specify the layout type of all tracks."},linkingId:{description:"Specify an ID for [linking multiple views](http://gosling-lang.org/docs/user-interaction#linking-views)",type:"string"},mark:{$ref:"#/definitions/Mark"},opacity:{anyOf:[{$ref:"#/definitions/Opacity"},{$ref:"#/definitions/ChannelValue"}]},orientation:{$ref:"#/definitions/Orientation",description:"Specify the orientation."},outerRadius:{description:'Specify the outer radius of tracks when `{"layout": "circular"}`.',type:"number"},overlayOnPreviousTrack:{type:"boolean"},overrideTemplate:{type:"boolean"},prerelease:{additionalProperties:!1,description:"internal",type:"object"},row:{anyOf:[{$ref:"#/definitions/Row"},{$ref:"#/definitions/ChannelValue"}]},size:{anyOf:[{$ref:"#/definitions/Size"},{$ref:"#/definitions/ChannelValue"}]},spacing:{description:"The size of the gap (1) between tracks, (2) between views, and (3) of the origin of circular tracks. The effect of this property depends on where on the spec you specify the `spacing`.\n\nIn a linear layout, this value is used in pixels, while in a circular layout, this value is used relative to the height of the tracks or views.",type:"number"},startAngle:{description:'Specify the start angle (in the range of [0, 360]) of circular tracks (`{"layout": "circular"}`).',type:"number"},static:{description:"Whether to disable [Zooming and Panning](http://gosling-lang.org/docs/user-interaction#zooming-and-panning), __Default:__ `false`.",type:"boolean"},stretch:{type:"boolean"},stroke:{anyOf:[{$ref:"#/definitions/Stroke"},{$ref:"#/definitions/ChannelValue"}]},strokeWidth:{anyOf:[{$ref:"#/definitions/StrokeWidth"},{$ref:"#/definitions/ChannelValue"}]},style:{$ref:"#/definitions/Style",description:"Define the [style](http://gosling-lang.org/docs/visual-channel#style-related-properties) of multive views. Will be overwritten by the style of children elements (e.g., view, track)."},subtitle:{type:"string"},text:{anyOf:[{$ref:"#/definitions/Text"},{$ref:"#/definitions/ChannelValue"}]},title:{description:"If defined, will show the textual label on the left-top corner of a track.",type:"string"},tooltip:{items:{$ref:"#/definitions/Tooltip"},type:"array"},visibility:{items:{$ref:"#/definitions/VisibilityCondition"},type:"array"},width:{description:"Specify the track width in pixels.",type:"number"},x:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},x1:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},x1e:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},xAxis:{$ref:"#/definitions/AxisPosition",description:"not supported"},xDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic x-axis"},xOffset:{description:"Specify the x offset of views in the unit of pixels",type:"number"},xe:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},y:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},y1:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},y1e:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},yDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic y-axis"},yOffset:{description:"Specify the y offset of views in the unit of pixels",type:"number"},ye:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},zoomLimits:{$ref:"#/definitions/ZoomLimits"}},required:["data","mark"],type:"object"},SingleView:{anyOf:[{additionalProperties:!1,properties:{_assignedHeight:{type:"number"},_assignedWidth:{description:"Internal: Used for responsive spec",type:"number"},_invalidTrack:{description:"internal",type:"boolean"},_renderingId:{description:"internal",type:"string"},alignment:{const:"overlay",type:"string"},assembly:{$ref:"#/definitions/Assembly",description:'A string that specifies the genome builds to use. Currently support `"hg38"`, `"hg19"`, `"hg18"`, `"hg17"`, `"hg16"`, `"mm10"`, `"mm9"`, and `"unknown"`.\n\n__Note:__: with `"unknown"` assembly, genomic axes do not show chrN: in labels.'},baselineY:{type:"number"},centerRadius:{description:"Proportion of the radius of the center white space.\n\n__Default:__ `0.3`",type:"number"},color:{anyOf:[{$ref:"#/definitions/Color"},{$ref:"#/definitions/ChannelValue"}]},data:{$ref:"#/definitions/DataDeep"},dataTransform:{items:{$ref:"#/definitions/DataTransform"},type:"array"},displacement:{$ref:"#/definitions/Displacement"},endAngle:{description:'Specify the end angle (in the range of [0, 360]) of circular tracks (`{"layout": "circular"}`).',type:"number"},experimental:{additionalProperties:!1,properties:{mouseEvents:{anyOf:[{type:"boolean"},{$ref:"#/definitions/MouseEventsDeep"}]},performanceMode:{default:!1,description:"Render visual marks with less smooth curves to increase rendering performance. Only supported for `elliptical` `linkStyle` `withinLink` currently.",type:"boolean"}},type:"object"},flipY:{type:"boolean"},height:{description:"Specify the track height in pixels.",type:"number"},id:{description:"The ID of a view that is maintained for the use of JS API functions, e.g., positions of a view",type:"string"},innerRadius:{description:'Specify the inner radius of tracks when (`{"layout": "circular"}`).',type:"number"},layout:{$ref:"#/definitions/Layout",description:"Specify the layout type of all tracks."},linkingId:{description:"Specify an ID for [linking multiple views](http://gosling-lang.org/docs/user-interaction#linking-views)",type:"string"},mark:{$ref:"#/definitions/Mark"},opacity:{anyOf:[{$ref:"#/definitions/Opacity"},{$ref:"#/definitions/ChannelValue"}]},orientation:{$ref:"#/definitions/Orientation",description:"Specify the orientation."},outerRadius:{description:'Specify the outer radius of tracks when `{"layout": "circular"}`.',type:"number"},overlayOnPreviousTrack:{type:"boolean"},overrideTemplate:{type:"boolean"},prerelease:{additionalProperties:!1,description:"internal",type:"object"},responsiveSpec:{items:{additionalProperties:!1,properties:{selectivity:{items:{$ref:"#/definitions/SelectivityCondition"},type:"array"},spec:{additionalProperties:!1,properties:{_assignedHeight:{type:"number"},_assignedWidth:{description:"Internal: Used for responsive spec",type:"number"},_invalidTrack:{description:"internal",type:"boolean"},_renderingId:{description:"internal",type:"string"},alignment:{enum:["overlay","stack"],type:"string"},assembly:{$ref:"#/definitions/Assembly",description:'A string that specifies the genome builds to use. Currently support `"hg38"`, `"hg19"`, `"hg18"`, `"hg17"`, `"hg16"`, `"mm10"`, `"mm9"`, and `"unknown"`.\n\n__Note:__: with `"unknown"` assembly, genomic axes do not show chrN: in labels.'},baselineY:{type:"number"},centerRadius:{description:"Proportion of the radius of the center white space.\n\n__Default:__ `0.3`",type:"number"},color:{anyOf:[{$ref:"#/definitions/Color"},{$ref:"#/definitions/ChannelValue"}]},data:{$ref:"#/definitions/DataDeep"},dataTransform:{items:{$ref:"#/definitions/DataTransform"},type:"array"},displacement:{$ref:"#/definitions/Displacement"},endAngle:{description:'Specify the end angle (in the range of [0, 360]) of circular tracks (`{"layout": "circular"}`).',type:"number"},experimental:{additionalProperties:!1,properties:{mouseEvents:{anyOf:[{type:"boolean"},{$ref:"#/definitions/MouseEventsDeep"}]},performanceMode:{default:!1,description:"Render visual marks with less smooth curves to increase rendering performance. Only supported for `elliptical` `linkStyle` `withinLink` currently.",type:"boolean"}},type:"object"},flipY:{type:"boolean"},height:{description:"Specify the track height in pixels.",type:"number"},id:{description:"The ID of a view that is maintained for the use of JS API functions, e.g., positions of a view",type:"string"},innerRadius:{description:'Specify the inner radius of tracks when (`{"layout": "circular"}`).',type:"number"},layout:{$ref:"#/definitions/Layout",description:"Specify the layout type of all tracks."},linkingId:{description:"Specify an ID for [linking multiple views](http://gosling-lang.org/docs/user-interaction#linking-views)",type:"string"},mark:{$ref:"#/definitions/Mark"},opacity:{anyOf:[{$ref:"#/definitions/Opacity"},{$ref:"#/definitions/ChannelValue"}]},orientation:{$ref:"#/definitions/Orientation",description:"Specify the orientation."},outerRadius:{description:'Specify the outer radius of tracks when `{"layout": "circular"}`.',type:"number"},overlayOnPreviousTrack:{type:"boolean"},overrideTemplate:{type:"boolean"},prerelease:{additionalProperties:!1,description:"internal",type:"object"},row:{anyOf:[{$ref:"#/definitions/Row"},{$ref:"#/definitions/ChannelValue"}]},size:{anyOf:[{$ref:"#/definitions/Size"},{$ref:"#/definitions/ChannelValue"}]},spacing:{description:"The size of the gap (1) between tracks, (2) between views, and (3) of the origin of circular tracks. The effect of this property depends on where on the spec you specify the `spacing`.\n\nIn a linear layout, this value is used in pixels, while in a circular layout, this value is used relative to the height of the tracks or views.",type:"number"},startAngle:{description:'Specify the start angle (in the range of [0, 360]) of circular tracks (`{"layout": "circular"}`).',type:"number"},static:{description:"Whether to disable [Zooming and Panning](http://gosling-lang.org/docs/user-interaction#zooming-and-panning), __Default:__ `false`.",type:"boolean"},stretch:{type:"boolean"},stroke:{anyOf:[{$ref:"#/definitions/Stroke"},{$ref:"#/definitions/ChannelValue"}]},strokeWidth:{anyOf:[{$ref:"#/definitions/StrokeWidth"},{$ref:"#/definitions/ChannelValue"}]},style:{$ref:"#/definitions/Style",description:"Define the [style](http://gosling-lang.org/docs/visual-channel#style-related-properties) of multive views. Will be overwritten by the style of children elements (e.g., view, track)."},subtitle:{type:"string"},text:{anyOf:[{$ref:"#/definitions/Text"},{$ref:"#/definitions/ChannelValue"}]},title:{description:"If defined, will show the textual label on the left-top corner of a track.",type:"string"},tooltip:{items:{$ref:"#/definitions/Tooltip"},type:"array"},tracks:{anyOf:[{items:{$ref:"#/definitions/PartialTrack"},type:"array"},{items:{anyOf:[{$ref:"#/definitions/PartialTrack"},{$ref:"#/definitions/OverlaidTracks"}]},type:"array"}]},visibility:{items:{$ref:"#/definitions/VisibilityCondition"},type:"array"},width:{description:"Specify the track width in pixels.",type:"number"},x:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},x1:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},x1e:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},xAxis:{$ref:"#/definitions/AxisPosition",description:"not supported"},xDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic x-axis"},xOffset:{description:"Specify the x offset of views in the unit of pixels",type:"number"},xe:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},y:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},y1:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},y1e:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},yDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic y-axis"},yOffset:{description:"Specify the y offset of views in the unit of pixels",type:"number"},ye:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},zoomLimits:{$ref:"#/definitions/ZoomLimits"}},type:"object"}},required:["spec","selectivity"],type:"object"},type:"array"},row:{anyOf:[{$ref:"#/definitions/Row"},{$ref:"#/definitions/ChannelValue"}]},size:{anyOf:[{$ref:"#/definitions/Size"},{$ref:"#/definitions/ChannelValue"}]},spacing:{description:"The size of the gap (1) between tracks, (2) between views, and (3) of the origin of circular tracks. The effect of this property depends on where on the spec you specify the `spacing`.\n\nIn a linear layout, this value is used in pixels, while in a circular layout, this value is used relative to the height of the tracks or views.",type:"number"},startAngle:{description:'Specify the start angle (in the range of [0, 360]) of circular tracks (`{"layout": "circular"}`).',type:"number"},static:{description:"Whether to disable [Zooming and Panning](http://gosling-lang.org/docs/user-interaction#zooming-and-panning), __Default:__ `false`.",type:"boolean"},stretch:{type:"boolean"},stroke:{anyOf:[{$ref:"#/definitions/Stroke"},{$ref:"#/definitions/ChannelValue"}]},strokeWidth:{anyOf:[{$ref:"#/definitions/StrokeWidth"},{$ref:"#/definitions/ChannelValue"}]},style:{$ref:"#/definitions/Style",description:"Define the [style](http://gosling-lang.org/docs/visual-channel#style-related-properties) of multive views. Will be overwritten by the style of children elements (e.g., view, track)."},subtitle:{type:"string"},text:{anyOf:[{$ref:"#/definitions/Text"},{$ref:"#/definitions/ChannelValue"}]},title:{description:"If defined, will show the textual label on the left-top corner of a track.",type:"string"},tooltip:{items:{$ref:"#/definitions/Tooltip"},type:"array"},tracks:{items:{$ref:"#/definitions/PartialTrack"},type:"array"},visibility:{items:{$ref:"#/definitions/VisibilityCondition"},type:"array"},width:{description:"Specify the track width in pixels.",type:"number"},x:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},x1:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},x1e:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},xAxis:{$ref:"#/definitions/AxisPosition",description:"not supported"},xDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic x-axis"},xOffset:{description:"Specify the x offset of views in the unit of pixels",type:"number"},xe:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},y:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},y1:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},y1e:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},yDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic y-axis"},yOffset:{description:"Specify the y offset of views in the unit of pixels",type:"number"},ye:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},zoomLimits:{$ref:"#/definitions/ZoomLimits"}},required:["alignment","tracks"],type:"object"},{additionalProperties:!1,properties:{_assignedHeight:{type:"number"},_assignedWidth:{description:"Internal: Used for responsive spec",type:"number"},_invalidTrack:{description:"internal",type:"boolean"},_renderingId:{description:"internal",type:"string"},alignment:{const:"stack",type:"string"},assembly:{$ref:"#/definitions/Assembly",description:'A string that specifies the genome builds to use. Currently support `"hg38"`, `"hg19"`, `"hg18"`, `"hg17"`, `"hg16"`, `"mm10"`, `"mm9"`, and `"unknown"`.\n\n__Note:__: with `"unknown"` assembly, genomic axes do not show chrN: in labels.'},baselineY:{type:"number"},centerRadius:{description:"Proportion of the radius of the center white space.\n\n__Default:__ `0.3`",type:"number"},color:{anyOf:[{$ref:"#/definitions/Color"},{$ref:"#/definitions/ChannelValue"}]},data:{$ref:"#/definitions/DataDeep"},dataTransform:{items:{$ref:"#/definitions/DataTransform"},type:"array"},displacement:{$ref:"#/definitions/Displacement"},endAngle:{description:'Specify the end angle (in the range of [0, 360]) of circular tracks (`{"layout": "circular"}`).',type:"number"},experimental:{additionalProperties:!1,properties:{mouseEvents:{anyOf:[{type:"boolean"},{$ref:"#/definitions/MouseEventsDeep"}]},performanceMode:{default:!1,description:"Render visual marks with less smooth curves to increase rendering performance. Only supported for `elliptical` `linkStyle` `withinLink` currently.",type:"boolean"}},type:"object"},flipY:{type:"boolean"},height:{description:"Specify the track height in pixels.",type:"number"},id:{description:"The ID of a view that is maintained for the use of JS API functions, e.g., positions of a view",type:"string"},innerRadius:{description:'Specify the inner radius of tracks when (`{"layout": "circular"}`).',type:"number"},layout:{$ref:"#/definitions/Layout",description:"Specify the layout type of all tracks."},linkingId:{description:"Specify an ID for [linking multiple views](http://gosling-lang.org/docs/user-interaction#linking-views)",type:"string"},mark:{$ref:"#/definitions/Mark"},opacity:{anyOf:[{$ref:"#/definitions/Opacity"},{$ref:"#/definitions/ChannelValue"}]},orientation:{$ref:"#/definitions/Orientation",description:"Specify the orientation."},outerRadius:{description:'Specify the outer radius of tracks when `{"layout": "circular"}`.',type:"number"},overlayOnPreviousTrack:{type:"boolean"},overrideTemplate:{type:"boolean"},prerelease:{additionalProperties:!1,description:"internal",type:"object"},responsiveSpec:{items:{additionalProperties:!1,properties:{selectivity:{items:{$ref:"#/definitions/SelectivityCondition"},type:"array"},spec:{additionalProperties:!1,properties:{_assignedHeight:{type:"number"},_assignedWidth:{description:"Internal: Used for responsive spec",type:"number"},_invalidTrack:{description:"internal",type:"boolean"},_renderingId:{description:"internal",type:"string"},alignment:{enum:["overlay","stack"],type:"string"},assembly:{$ref:"#/definitions/Assembly",description:'A string that specifies the genome builds to use. Currently support `"hg38"`, `"hg19"`, `"hg18"`, `"hg17"`, `"hg16"`, `"mm10"`, `"mm9"`, and `"unknown"`.\n\n__Note:__: with `"unknown"` assembly, genomic axes do not show chrN: in labels.'},baselineY:{type:"number"},centerRadius:{description:"Proportion of the radius of the center white space.\n\n__Default:__ `0.3`",type:"number"},color:{anyOf:[{$ref:"#/definitions/Color"},{$ref:"#/definitions/ChannelValue"}]},data:{$ref:"#/definitions/DataDeep"},dataTransform:{items:{$ref:"#/definitions/DataTransform"},type:"array"},displacement:{$ref:"#/definitions/Displacement"},endAngle:{description:'Specify the end angle (in the range of [0, 360]) of circular tracks (`{"layout": "circular"}`).',type:"number"},experimental:{additionalProperties:!1,properties:{mouseEvents:{anyOf:[{type:"boolean"},{$ref:"#/definitions/MouseEventsDeep"}]},performanceMode:{default:!1,description:"Render visual marks with less smooth curves to increase rendering performance. Only supported for `elliptical` `linkStyle` `withinLink` currently.",type:"boolean"}},type:"object"},flipY:{type:"boolean"},height:{description:"Specify the track height in pixels.",type:"number"},id:{description:"The ID of a view that is maintained for the use of JS API functions, e.g., positions of a view",type:"string"},innerRadius:{description:'Specify the inner radius of tracks when (`{"layout": "circular"}`).',type:"number"},layout:{$ref:"#/definitions/Layout",description:"Specify the layout type of all tracks."},linkingId:{description:"Specify an ID for [linking multiple views](http://gosling-lang.org/docs/user-interaction#linking-views)",type:"string"},mark:{$ref:"#/definitions/Mark"},opacity:{anyOf:[{$ref:"#/definitions/Opacity"},{$ref:"#/definitions/ChannelValue"}]},orientation:{$ref:"#/definitions/Orientation",description:"Specify the orientation."},outerRadius:{description:'Specify the outer radius of tracks when `{"layout": "circular"}`.',type:"number"},overlayOnPreviousTrack:{type:"boolean"},overrideTemplate:{type:"boolean"},prerelease:{additionalProperties:!1,description:"internal",type:"object"},row:{anyOf:[{$ref:"#/definitions/Row"},{$ref:"#/definitions/ChannelValue"}]},size:{anyOf:[{$ref:"#/definitions/Size"},{$ref:"#/definitions/ChannelValue"}]},spacing:{description:"The size of the gap (1) between tracks, (2) between views, and (3) of the origin of circular tracks. The effect of this property depends on where on the spec you specify the `spacing`.\n\nIn a linear layout, this value is used in pixels, while in a circular layout, this value is used relative to the height of the tracks or views.",type:"number"},startAngle:{description:'Specify the start angle (in the range of [0, 360]) of circular tracks (`{"layout": "circular"}`).',type:"number"},static:{description:"Whether to disable [Zooming and Panning](http://gosling-lang.org/docs/user-interaction#zooming-and-panning), __Default:__ `false`.",type:"boolean"},stretch:{type:"boolean"},stroke:{anyOf:[{$ref:"#/definitions/Stroke"},{$ref:"#/definitions/ChannelValue"}]},strokeWidth:{anyOf:[{$ref:"#/definitions/StrokeWidth"},{$ref:"#/definitions/ChannelValue"}]},style:{$ref:"#/definitions/Style",description:"Define the [style](http://gosling-lang.org/docs/visual-channel#style-related-properties) of multive views. Will be overwritten by the style of children elements (e.g., view, track)."},subtitle:{type:"string"},text:{anyOf:[{$ref:"#/definitions/Text"},{$ref:"#/definitions/ChannelValue"}]},title:{description:"If defined, will show the textual label on the left-top corner of a track.",type:"string"},tooltip:{items:{$ref:"#/definitions/Tooltip"},type:"array"},tracks:{anyOf:[{items:{$ref:"#/definitions/PartialTrack"},type:"array"},{items:{anyOf:[{$ref:"#/definitions/PartialTrack"},{$ref:"#/definitions/OverlaidTracks"}]},type:"array"}]},visibility:{items:{$ref:"#/definitions/VisibilityCondition"},type:"array"},width:{description:"Specify the track width in pixels.",type:"number"},x:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},x1:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},x1e:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},xAxis:{$ref:"#/definitions/AxisPosition",description:"not supported"},xDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic x-axis"},xOffset:{description:"Specify the x offset of views in the unit of pixels",type:"number"},xe:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},y:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},y1:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},y1e:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},yDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic y-axis"},yOffset:{description:"Specify the y offset of views in the unit of pixels",type:"number"},ye:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},zoomLimits:{$ref:"#/definitions/ZoomLimits"}},type:"object"}},required:["spec","selectivity"],type:"object"},type:"array"},row:{anyOf:[{$ref:"#/definitions/Row"},{$ref:"#/definitions/ChannelValue"}]},size:{anyOf:[{$ref:"#/definitions/Size"},{$ref:"#/definitions/ChannelValue"}]},spacing:{description:"The size of the gap (1) between tracks, (2) between views, and (3) of the origin of circular tracks. The effect of this property depends on where on the spec you specify the `spacing`.\n\nIn a linear layout, this value is used in pixels, while in a circular layout, this value is used relative to the height of the tracks or views.",type:"number"},startAngle:{description:'Specify the start angle (in the range of [0, 360]) of circular tracks (`{"layout": "circular"}`).',type:"number"},static:{description:"Whether to disable [Zooming and Panning](http://gosling-lang.org/docs/user-interaction#zooming-and-panning), __Default:__ `false`.",type:"boolean"},stretch:{type:"boolean"},stroke:{anyOf:[{$ref:"#/definitions/Stroke"},{$ref:"#/definitions/ChannelValue"}]},strokeWidth:{anyOf:[{$ref:"#/definitions/StrokeWidth"},{$ref:"#/definitions/ChannelValue"}]},style:{$ref:"#/definitions/Style",description:"Define the [style](http://gosling-lang.org/docs/visual-channel#style-related-properties) of multive views. Will be overwritten by the style of children elements (e.g., view, track)."},subtitle:{type:"string"},text:{anyOf:[{$ref:"#/definitions/Text"},{$ref:"#/definitions/ChannelValue"}]},title:{description:"If defined, will show the textual label on the left-top corner of a track.",type:"string"},tooltip:{items:{$ref:"#/definitions/Tooltip"},type:"array"},tracks:{items:{anyOf:[{$ref:"#/definitions/PartialTrack"},{$ref:"#/definitions/OverlaidTracks"}]},type:"array"},visibility:{items:{$ref:"#/definitions/VisibilityCondition"},type:"array"},width:{description:"Specify the track width in pixels.",type:"number"},x:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},x1:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},x1e:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},xAxis:{$ref:"#/definitions/AxisPosition",description:"not supported"},xDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic x-axis"},xOffset:{description:"Specify the x offset of views in the unit of pixels",type:"number"},xe:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},y:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},y1:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},y1e:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},yDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic y-axis"},yOffset:{description:"Specify the y offset of views in the unit of pixels",type:"number"},ye:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},zoomLimits:{$ref:"#/definitions/ZoomLimits"}},required:["tracks"],type:"object"},{additionalProperties:!1,properties:{_assignedHeight:{type:"number"},_assignedWidth:{description:"Internal: Used for responsive spec",type:"number"},assembly:{$ref:"#/definitions/Assembly",description:'A string that specifies the genome builds to use. Currently support `"hg38"`, `"hg19"`, `"hg18"`, `"hg17"`, `"hg16"`, `"mm10"`, `"mm9"`, and `"unknown"`.\n\n__Note:__: with `"unknown"` assembly, genomic axes do not show chrN: in labels.'},centerRadius:{description:"Proportion of the radius of the center white space.\n\n__Default:__ `0.3`",type:"number"},id:{description:"The ID of a view that is maintained for the use of JS API functions, e.g., positions of a view",type:"string"},layout:{$ref:"#/definitions/Layout",description:"Specify the layout type of all tracks."},linkingId:{description:"Specify an ID for [linking multiple views](http://gosling-lang.org/docs/user-interaction#linking-views)",type:"string"},orientation:{$ref:"#/definitions/Orientation",description:"Specify the orientation."},responsiveSpec:{items:{additionalProperties:!1,properties:{selectivity:{items:{$ref:"#/definitions/SelectivityCondition"},type:"array"},spec:{additionalProperties:!1,properties:{_assignedHeight:{type:"number"},_assignedWidth:{description:"Internal: Used for responsive spec",type:"number"},_invalidTrack:{description:"internal",type:"boolean"},_renderingId:{description:"internal",type:"string"},alignment:{enum:["overlay","stack"],type:"string"},assembly:{$ref:"#/definitions/Assembly",description:'A string that specifies the genome builds to use. Currently support `"hg38"`, `"hg19"`, `"hg18"`, `"hg17"`, `"hg16"`, `"mm10"`, `"mm9"`, and `"unknown"`.\n\n__Note:__: with `"unknown"` assembly, genomic axes do not show chrN: in labels.'},baselineY:{type:"number"},centerRadius:{description:"Proportion of the radius of the center white space.\n\n__Default:__ `0.3`",type:"number"},color:{anyOf:[{$ref:"#/definitions/Color"},{$ref:"#/definitions/ChannelValue"}]},data:{$ref:"#/definitions/DataDeep"},dataTransform:{items:{$ref:"#/definitions/DataTransform"},type:"array"},displacement:{$ref:"#/definitions/Displacement"},endAngle:{description:'Specify the end angle (in the range of [0, 360]) of circular tracks (`{"layout": "circular"}`).',type:"number"},experimental:{additionalProperties:!1,properties:{mouseEvents:{anyOf:[{type:"boolean"},{$ref:"#/definitions/MouseEventsDeep"}]},performanceMode:{default:!1,description:"Render visual marks with less smooth curves to increase rendering performance. Only supported for `elliptical` `linkStyle` `withinLink` currently.",type:"boolean"}},type:"object"},flipY:{type:"boolean"},height:{description:"Specify the track height in pixels.",type:"number"},id:{description:"The ID of a view that is maintained for the use of JS API functions, e.g., positions of a view",type:"string"},innerRadius:{description:'Specify the inner radius of tracks when (`{"layout": "circular"}`).',type:"number"},layout:{$ref:"#/definitions/Layout",description:"Specify the layout type of all tracks."},linkingId:{description:"Specify an ID for [linking multiple views](http://gosling-lang.org/docs/user-interaction#linking-views)",type:"string"},mark:{$ref:"#/definitions/Mark"},opacity:{anyOf:[{$ref:"#/definitions/Opacity"},{$ref:"#/definitions/ChannelValue"}]},orientation:{$ref:"#/definitions/Orientation",description:"Specify the orientation."},outerRadius:{description:'Specify the outer radius of tracks when `{"layout": "circular"}`.',type:"number"},overlayOnPreviousTrack:{type:"boolean"},overrideTemplate:{type:"boolean"},prerelease:{additionalProperties:!1,description:"internal",type:"object"},row:{anyOf:[{$ref:"#/definitions/Row"},{$ref:"#/definitions/ChannelValue"}]},size:{anyOf:[{$ref:"#/definitions/Size"},{$ref:"#/definitions/ChannelValue"}]},spacing:{description:"The size of the gap (1) between tracks, (2) between views, and (3) of the origin of circular tracks. The effect of this property depends on where on the spec you specify the `spacing`.\n\nIn a linear layout, this value is used in pixels, while in a circular layout, this value is used relative to the height of the tracks or views.",type:"number"},startAngle:{description:'Specify the start angle (in the range of [0, 360]) of circular tracks (`{"layout": "circular"}`).',type:"number"},static:{description:"Whether to disable [Zooming and Panning](http://gosling-lang.org/docs/user-interaction#zooming-and-panning), __Default:__ `false`.",type:"boolean"},stretch:{type:"boolean"},stroke:{anyOf:[{$ref:"#/definitions/Stroke"},{$ref:"#/definitions/ChannelValue"}]},strokeWidth:{anyOf:[{$ref:"#/definitions/StrokeWidth"},{$ref:"#/definitions/ChannelValue"}]},style:{$ref:"#/definitions/Style",description:"Define the [style](http://gosling-lang.org/docs/visual-channel#style-related-properties) of multive views. Will be overwritten by the style of children elements (e.g., view, track)."},subtitle:{type:"string"},text:{anyOf:[{$ref:"#/definitions/Text"},{$ref:"#/definitions/ChannelValue"}]},title:{description:"If defined, will show the textual label on the left-top corner of a track.",type:"string"},tooltip:{items:{$ref:"#/definitions/Tooltip"},type:"array"},tracks:{anyOf:[{items:{$ref:"#/definitions/PartialTrack"},type:"array"},{items:{anyOf:[{$ref:"#/definitions/PartialTrack"},{$ref:"#/definitions/OverlaidTracks"}]},type:"array"}]},visibility:{items:{$ref:"#/definitions/VisibilityCondition"},type:"array"},width:{description:"Specify the track width in pixels.",type:"number"},x:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},x1:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},x1e:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},xAxis:{$ref:"#/definitions/AxisPosition",description:"not supported"},xDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic x-axis"},xOffset:{description:"Specify the x offset of views in the unit of pixels",type:"number"},xe:{anyOf:[{$ref:"#/definitions/X"},{$ref:"#/definitions/ChannelValue"}]},y:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},y1:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},y1e:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},yDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic y-axis"},yOffset:{description:"Specify the y offset of views in the unit of pixels",type:"number"},ye:{anyOf:[{$ref:"#/definitions/Y"},{$ref:"#/definitions/ChannelValue"}]},zoomLimits:{$ref:"#/definitions/ZoomLimits"}},type:"object"}},required:["spec","selectivity"],type:"object"},type:"array"},spacing:{description:"The size of the gap (1) between tracks, (2) between views, and (3) of the origin of circular tracks. The effect of this property depends on where on the spec you specify the `spacing`.\n\nIn a linear layout, this value is used in pixels, while in a circular layout, this value is used relative to the height of the tracks or views.",type:"number"},static:{description:"Whether to disable [Zooming and Panning](http://gosling-lang.org/docs/user-interaction#zooming-and-panning), __Default:__ `false`.",type:"boolean"},style:{$ref:"#/definitions/Style",description:"Define the [style](http://gosling-lang.org/docs/visual-channel#style-related-properties) of multive views. Will be overwritten by the style of children elements (e.g., view, track)."},tracks:{items:{$ref:"#/definitions/Track"},type:"array"},xAxis:{$ref:"#/definitions/AxisPosition",description:"not supported"},xDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic x-axis"},xOffset:{description:"Specify the x offset of views in the unit of pixels",type:"number"},yDomain:{anyOf:[{$ref:"#/definitions/DomainInterval"},{$ref:"#/definitions/DomainChrInterval"},{$ref:"#/definitions/DomainChr"}],description:"Specify the visible region of genomic y-axis"},yOffset:{description:"Specify the y offset of views in the unit of pixels",type:"number"},zoomLimits:{$ref:"#/definitions/ZoomLimits"}},required:["tracks"],type:"object"}]},Size:{additionalProperties:!1,properties:{domain:{$ref:"#/definitions/ValueExtent",description:"Values of the data"},field:{description:"Name of the data field",type:"string"},legend:{description:"not supported: Whether to display legend. __Default__: `false`",type:"boolean"},range:{$ref:"#/definitions/ValueExtent",description:"Ranges of visual channel values"},type:{description:"Specify the data type",enum:["quantitative","nominal"],type:"string"}},type:"object"},SizeVisibilityCondition:{additionalProperties:!1,properties:{conditionPadding:{description:"Specify the buffer size (in pixel) of width or height when calculating the visibility.\n\n__Default__: `0`",type:"number"},measure:{description:"Specify which aspect of the `target` will be compared to the `threshold`.",enum:["width","height"],type:"string"},operation:{$ref:"#/definitions/LogicalOperation",description:`A string that specifies the logical operation to conduct between \`threshold\` and the \`measure\` of \`target\`. Support - greater than : "greater-than", "gt", "GT" @@ -1586,11 +1985,11 @@ ${C}`}},{key:"handleExportSVG",value:function(){tB("export.svg",new Blob([this.c - greater than or equal to : "greater-than-or-equal-to", "gtet", "GTET" -- less than or equal to : "less-than-or-equal-to", "ltet", "LTET"`},target:{description:"Target specifies the object that you want to compare with the threshold.",enum:["track","mark"],type:"string"},threshold:{description:"Set a threshold in the unit of base pairs (bp)",type:"number"},transitionPadding:{description:"Specify the buffer size (in pixel) of width or height for smooth transition.\n\n__Default__: `0`",type:"number"}},required:["measure","operation","target","threshold"],type:"object"},ZoomLimits:{items:{type:["number","null"]},maxItems:2,minItems:2,type:"array"}},q6t={$ref:Q6t,$schema:j6t,definitions:$6t};function eqt(g){return uHe(q6t,g)}function uHe(g,e,I=!1){const i=new u4e({extendRefs:!0}).compile(g),n=i(e);let C="",r="";return i.errors&&(r=JSON.stringify(i.errors,null,2),I||console.warn(r),C="⚠️ Some properties are incorrectly used."),{state:n?"success":"warn",message:C,details:r}}function dHe(g){let e=!0;const I=[];return F0(g).forEach(n=>{!S$(n)&&n.mark!=="brush"&&n.mark!=="rule"&&(I.push("genomic type is not encoded to either a x- or y- axis"),e=!1);const C=n.color;n.mark==="line"&<(C)&&C.type==="quantitative"&&(I.push("`line` mark cannot be used with `quantitative` value"),e=!1)}),{valid:e,errorMessages:I}}function S$(g){let e;return["x","y","xe","ye","x1","y1","x1e","y1e"].reverse().forEach(I=>{const i=g[I];lt(i)&&i.type==="genomic"&&(e=i)}),e}function hHe(g){let e;return["x","xe","y","ye","x1","y1","x1e","y1e"].reverse().forEach(I=>{const i=g[I];lt(i)&&i.type==="genomic"&&(e=I)}),e}const tqt=[{name:"gene",channels:[{name:"startPosition",type:"genomic",required:!0},{name:"endPosition",type:"genomic",required:!0},{name:"strandColor",type:"nominal",required:!0},{name:"strandRow",type:"nominal",required:!0},{name:"opacity",type:"value",required:!1},{name:"geneHeight",type:"value",required:!1},{name:"geneLabel",type:"nominal",required:!0},{name:"geneLabelColor",type:"nominal",required:!0},{name:"geneLabelFontSize",type:"value",required:!1},{name:"geneLabelStroke",type:"value",required:!1},{name:"geneLabelStrokeThickness",type:"value",required:!1},{name:"geneLabelOpacity",type:"value",required:!1},{name:"type",type:"nominal",required:!0}],mapping:[{dataTransform:[{type:"filter",base:"type",oneOf:["gene"]},{type:"filter",base:"strandColor",oneOf:["-"]}],mark:"triangleLeft",x:{base:"startPosition",type:"genomic"},size:{base:"geneHeight",value:12},row:{base:"strandRow",type:"nominal",domain:["+","-"]},color:{base:"strandColor",type:"nominal",domain:["+","-"],range:["blue","red"]},opacity:{base:"opacity",value:.4},style:{align:"right"}},{dataTransform:[{type:"filter",base:"type",oneOf:["gene"]},{type:"filter",base:"strandColor",oneOf:["+"]}],mark:"triangleRight",x:{base:"endPosition",type:"genomic"},size:{base:"geneHeight",value:12},row:{base:"strandRow",type:"nominal",domain:["+","-"]},color:{base:"strandColor",type:"nominal",domain:["+","-"],range:["blue","red"]},opacity:{base:"opacity",value:.4},style:{align:"left"}},{dataTransform:[{type:"filter",base:"type",oneOf:["exon"]}],mark:"rect",x:{base:"startPosition",type:"genomic"},xe:{base:"endPosition",type:"genomic"},size:{base:"geneHeight",value:12},row:{base:"strandRow",type:"nominal",domain:["+","-"]},color:{base:"strandColor",type:"nominal",domain:["+","-"],range:["blue","red"]},opacity:{base:"opacity",value:.4}},{dataTransform:[{type:"filter",base:"type",oneOf:["gene"]},{type:"filter",base:"strandColor",oneOf:["+"]}],mark:"rect",x:{base:"startPosition",type:"genomic"},xe:{base:"endPosition",type:"genomic"},row:{base:"strandRow",type:"nominal",domain:["+","-"]},color:{base:"strandColor",type:"nominal",domain:["+","-"],range:["blue","red"]},opacity:{base:"opacity",value:.4},size:{value:3}},{dataTransform:[{type:"filter",base:"type",oneOf:["gene"]},{type:"filter",base:"strandColor",oneOf:["-"]}],mark:"rect",x:{base:"startPosition",type:"genomic"},xe:{base:"endPosition",type:"genomic"},row:{base:"strandRow",type:"nominal",domain:["+","-"]},color:{base:"strandColor",type:"nominal",domain:["+","-"],range:["blue","red"]},opacity:{base:"opacity",value:.4},size:{value:3}},{dataTransform:[{type:"filter",base:"type",oneOf:["gene"]}],mark:"text",text:{base:"geneLabel",type:"nominal"},x:{base:"startPosition",type:"genomic"},xe:{base:"endPosition",type:"genomic"},row:{base:"strandRow",type:"nominal",domain:["+","-"]},color:{base:"geneLabelColor",type:"nominal",domain:["+","-"],range:["blue","red"]},opacity:{base:"opacity",value:1},size:{base:"geneLabelFontSize",value:18},stroke:{base:"geneLabelStroke",value:"white"},strokeWidth:{base:"geneLabelStrokeThickness",value:2},visibility:[{operation:"less-than",measure:"width",threshold:"|xe-x|",transitionPadding:10,target:"mark"}]}]},{name:"ideogram",channels:[{name:"startPosition",type:"genomic",required:!0},{name:"endPosition",type:"genomic",required:!0},{name:"chrHeight",type:"value",required:!1},{name:"name",type:"nominal",required:!0},{name:"stainBackgroundColor",type:"nominal",required:!0},{name:"stainLabelColor",type:"nominal",required:!0},{name:"stainStroke",type:"value",required:!1},{name:"stainStrokeWidth",type:"value",required:!1}],mapping:[{mark:"rect",dataTransform:[{type:"filter",base:"stainBackgroundColor",oneOf:["acen"],not:!0}],color:{base:"stainBackgroundColor",type:"nominal",domain:["gneg","gpos25","gpos50","gpos75","gpos100","gvar","acen"],range:["white","lightgray","gray","gray","black","#7B9CC8","#DC4542"]},size:{base:"chrHeight",value:18},x:{base:"startPosition",type:"genomic"},xe:{base:"endPosition",type:"genomic"},stroke:{base:"stainStroke",value:"gray"},strokeWidth:{base:"stainStrokeWidth",value:.3}},{mark:"triangleRight",dataTransform:[{type:"filter",base:"stainBackgroundColor",oneOf:["acen"]},{type:"filter",base:"name",include:"q"}],color:{base:"stainBackgroundColor",type:"nominal",domain:["gneg","gpos25","gpos50","gpos75","gpos100","gvar","acen"],range:["white","lightgray","gray","gray","black","#7B9CC8","#DC4542"]},size:{base:"chrHeight",value:18},x:{base:"startPosition",type:"genomic"},xe:{base:"endPosition",type:"genomic"},stroke:{base:"stainStroke",value:"gray"},strokeWidth:{base:"stainStrokeWidth",value:.3}},{mark:"triangleLeft",dataTransform:[{type:"filter",base:"stainBackgroundColor",oneOf:["acen"]},{type:"filter",base:"name",include:"p"}],color:{base:"stainBackgroundColor",type:"nominal",domain:["gneg","gpos25","gpos50","gpos75","gpos100","gvar","acen"],range:["white","lightgray","gray","gray","black","#7B9CC8","#DC4542"]},size:{base:"chrHeight",value:18},x:{base:"startPosition",type:"genomic"},xe:{base:"endPosition",type:"genomic"},stroke:{base:"stainStroke",value:"gray"},strokeWidth:{base:"stainStrokeWidth",value:.3}},{mark:"text",dataTransform:[{type:"filter",base:"stainLabelColor",oneOf:["acen"],not:!0}],color:{base:"stainLabelColor",type:"nominal",domain:["gneg","gpos25","gpos50","gpos75","gpos100","gvar"],range:["black","black","black","black","white","black"]},text:{base:"name",type:"nominal"},x:{base:"startPosition",type:"genomic"},xe:{base:"endPosition",type:"genomic"},visibility:[{operation:"less-than",measure:"width",threshold:"|xe-x|",transitionPadding:10,target:"mark"}]}]},{name:"sequence",channels:[{name:"startPosition",type:"genomic",required:!0},{name:"endPosition",type:"genomic",required:!0},{name:"barLength",type:"quantitative",required:!0},{name:"baseBackground",type:"nominal",required:!0},{name:"baseLabelColor",type:"nominal",required:!0},{name:"baseLabelFontSize",type:"value",required:!1}],mapping:[{mark:"bar",x:{base:"startPosition",type:"genomic"},xe:{base:"endPosition",type:"genomic"},y:{base:"barLength",type:"quantitative",axis:"none"},color:{base:"baseBackground",type:"nominal",domain:["A","T","G","C"]}},{dataTransform:[{type:"filter",base:"barLength",oneOf:[0],not:!0}],mark:"text",x:{base:"startPosition",type:"genomic"},xe:{base:"endPosition",type:"genomic"},color:{base:"baseLabelColor",type:"nominal",domain:["A","T","G","C"],range:["white"]},text:{base:"baseBackground",type:"nominal"},size:{base:"baseLabelFontSize",value:18},visibility:[{operation:"less-than",measure:"width",threshold:"|xe-x|",transitionPadding:30,target:"mark"},{operation:"LT",measure:"zoomLevel",threshold:10,target:"track"}]}]}];function gqt(g,e){s9(g,(I,i,n)=>{var C,r;if(!N7e(I))return;const{template:o}=I,A=e.find(c=>c.name===o);if(!A){I._invalidTrack=!0,console.warn(`There is no track template named '${o}'`);return}let s=!0;if(A.channels.forEach(c=>{c.required&&(!I.encoding||!(c.name in I.encoding))&&(s=!1,console.warn(`A template spec ('${o}') does not contain a required channel, ${c.name}`))}),!s){I._invalidTrack=!0;return}const a=JSON.parse(JSON.stringify(I));"encoding"in a&&delete a.encoding;const l={...a,alignment:"overlay",tracks:[],width:(C=I.width)!=null?C:100,height:(r=I.height)!=null?r:100};A.mapping.forEach(c=>{const u={data:I.data,mark:c.mark},{dataTransform:d}=c;d&&d.map(m=>{const f=m.base;f&&I.encoding&&f in I.encoding&&"field"in I.encoding[f]&&(delete m.base,m.field=I.encoding[f].field)});const h=I.encoding;h?Object.keys(c).filter(m=>m!=="mark").forEach(m=>{const f=JSON.parse(JSON.stringify(c[m]));if("base"in f){const b=f.base;if(b in h){const p=JSON.parse(JSON.stringify(h[b]));delete f.base;const y=Object.assign(f,JSON.parse(JSON.stringify(p)));u[m]=y}else delete f.base,u[m]=f}else u[m]=f}):Object.keys(c).filter(m=>m!=="mark").forEach(m=>{const f=JSON.parse(JSON.stringify(c[m]));"base"in f&&delete f.base,u[m]=f}),l.tracks.push(u)}),n[i]=l})}const Pse=["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],Bo={color:Pse[0],size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:Pse,quantitativeSizeRange:[2,6]},Iqt={base:"light",root:{background:"white",titleColor:"black",titleBackgroundColor:"transparent",titleFontSize:18,titleFontFamily:"Arial",titleAlign:"left",titleFontWeight:"bold",subtitleColor:"gray",subtitleBackgroundColor:"transparent",subtitleFontSize:16,subtitleFontFamily:"Arial",subtitleFontWeight:"normal",subtitleAlign:"left",showMousePosition:!0,mousePositionColor:"#000000"},track:{background:"transparent",alternatingBackground:"transparent",titleColor:"black",titleBackground:"white",titleFontSize:24,titleAlign:"left",outline:"black",outlineWidth:1},legend:{position:"top",background:"white",backgroundOpacity:.7,labelColor:"black",labelFontSize:12,labelFontWeight:"normal",labelFontFamily:"Arial",backgroundStroke:"#DBDBDB",tickColor:"black"},axis:{tickColor:"black",labelColor:"black",labelMargin:5,labelExcludeChrPrefix:!1,labelFontSize:12,labelFontWeight:"normal",labelFontFamily:"Arial",baselineColor:"black",gridColor:"#E3E3E3",gridStrokeWidth:1,gridStrokeType:"solid",gridStrokeDash:[4,4]},markCommon:{...Bo},point:{...Bo,size:3},rect:{...Bo},triangle:{...Bo},area:{...Bo},line:{...Bo},bar:{...Bo},rule:{...Bo,strokeWidth:1},link:{...Bo,strokeWidth:1},text:{...Bo,textAnchor:"middle",textFontWeight:"normal"},brush:{...Bo,color:"gray",opacity:.3,stroke:"black",strokeWidth:1}},Jse=["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],iqt={color:Jse[0],size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:Jse,quantitativeSizeRange:[2,6]},vo={...iqt,stroke:"white"},nqt={base:"dark",root:{background:"black",titleColor:"white",titleBackgroundColor:"transparent",titleFontSize:18,titleFontFamily:"Arial",titleAlign:"middle",titleFontWeight:"bold",subtitleColor:"lightgray",subtitleBackgroundColor:"transparent",subtitleFontSize:16,subtitleFontFamily:"Arial",subtitleAlign:"middle",subtitleFontWeight:"normal",showMousePosition:!0,mousePositionColor:"#FFFFFF"},track:{background:"transparent",alternatingBackground:"transparent",titleColor:"white",titleBackground:"black",titleFontSize:18,titleAlign:"left",outline:"white",outlineWidth:1},legend:{position:"right",background:"black",backgroundOpacity:.7,labelColor:"white",labelFontSize:12,labelFontWeight:"normal",labelFontFamily:"Arial",backgroundStroke:"#DBDBDB",tickColor:"white"},axis:{tickColor:"white",labelMargin:5,labelExcludeChrPrefix:!1,labelColor:"white",labelFontSize:10,labelFontWeight:"normal",labelFontFamily:"Arial",baselineColor:"white",gridColor:"gray",gridStrokeWidth:1,gridStrokeType:"solid",gridStrokeDash:[4,4]},markCommon:{...vo},point:{...vo,size:3},rect:{...vo},triangle:{...vo},area:{...vo},line:{...vo},bar:{...vo},rule:{...vo,strokeWidth:1},link:{...vo,strokeWidth:1},text:{...vo,textAnchor:"middle",textFontWeight:"normal"},brush:{...vo,color:"lightgray",opacity:.3,stroke:"white",strokeWidth:1}},Ose=["#D19000","#008F67","#005F96","#B86E97","#B55100","#4793BF","#C9C03"],So={color:Ose[0],size:1,stroke:"#3C3C3C",strokeWidth:0,opacity:1,nominalColorRange:Ose,quantitativeSizeRange:[2,6]},Cqt={base:"warm",root:{background:"#FFF8E8",titleColor:"#3C3C3C",subtitleColor:"gray",showMousePosition:!0,mousePositionColor:"#3C3C3C"},track:{titleColor:"#3C3C3C",titleBackground:"#FFF8E8",outline:"#3C3C3C",outlineWidth:1},legend:{background:"#FFF8E8",backgroundOpacity:.7,labelColor:"#3C3C3C",backgroundStroke:"#3C3C3C",tickColor:"3C3C3C"},axis:{tickColor:"#3C3C3C",labelColor:"#3C3C3C",baselineColor:"#3C3C3C",gridColor:"#E3E3E3",gridStrokeWidth:1},markCommon:{...So},point:{...So,size:3},rect:{...So},triangle:{...So},area:{...So},line:{...So},bar:{...So},rule:{...So,strokeWidth:1},link:{...So,strokeWidth:1},text:{...So,textAnchor:"middle",textFontWeight:"normal"},brush:{...So,color:"lightgray",opacity:.3,stroke:"#3C3C3C",strokeWidth:1}},Lse=["#F66A62","#05B230","#5692FF","#D764D6","#86E9D4","#6E6AD7","#FFFB00"],wo={color:Lse[0],size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:Lse,quantitativeSizeRange:[2,6]},rqt={base:"ggplot",root:{background:"white",titleColor:"black",titleFontSize:18,titleFontFamily:"Helvetica",titleAlign:"middle",titleFontWeight:"bold",titleBackgroundColor:"white",subtitleColor:"gray",subtitleFontSize:14,subtitleFontFamily:"Helvetica",subtitleAlign:"middle",subtitleFontWeight:"light",subtitleBackgroundColor:"white",showMousePosition:!0,mousePositionColor:"black"},track:{background:"#e8e8e8",alternatingBackground:"#d1d1d1",titleColor:"black",titleBackground:"white",outline:"black",outlineWidth:2},legend:{position:"right",background:"#e8e8e8",backgroundOpacity:1,labelColor:"black",backgroundStroke:"#e8e8e8",tickColor:"white"},axis:{tickColor:"white",labelColor:"black",baselineColor:"#e8e8e8",gridColor:"white",gridStrokeWidth:2},markCommon:{...wo},point:{...wo,size:3},rect:{...wo},triangle:{...wo},area:{...wo},line:{...wo},bar:{...wo},rule:{...wo,strokeWidth:1},link:{...wo,strokeWidth:1},text:{...wo,textAnchor:"middle",textFontWeight:"bold"},brush:{...wo,color:"black",opacity:.3,stroke:"black",strokeWidth:1}},_se=["#37E649","#ED2D44","#AEAFEA","#EBAEAE","#CE7B3D","#8743E0","#5233F0"],Vo={color:_se[0],size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:_se,quantitativeSizeRange:[2,6]},oqt={base:"igv",root:{background:"white",titleColor:"white",titleAlign:"left",titleFontWeight:"bold",titleBackgroundColor:"#5f5f5f",subtitleColor:"#3b3b3b",subtitleAlign:"left",subtitleFontWeight:"bold",subtitleBackgroundColor:"#c4c4c4",showMousePosition:!0,mousePositionColor:"black"},track:{background:"white",alternatingBackground:"#e8e8e8",titleColor:"white",titleBackground:"#5F5F5F",outline:"#5F5F5F",outlineWidth:1},legend:{position:"top",background:"white",backgroundOpacity:1,labelColor:"black",backgroundStroke:"black",tickColor:"black"},axis:{tickColor:"black",labelColor:"black",baselineColor:"white",gridColor:"transparent",gridStrokeWidth:0},markCommon:{...Vo},point:{...Vo,size:3},rect:{...Vo},triangle:{...Vo},area:{...Vo},line:{...Vo},bar:{...Vo},rule:{...Vo,strokeWidth:1},link:{...Vo,strokeWidth:1},text:{...Vo,textAnchor:"middle",textFontWeight:"bold"},brush:{...Vo,color:"white",opacity:.3,stroke:"black",strokeWidth:1}},Use=["#CD9B1D","#8A668B","#40E0D0","#FF6969","#666666","#FAC902","#FE0000","#CC96CD","#D9D9D9"],Ro={color:Use[0],size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:Use,quantitativeSizeRange:[2,6]},Aqt={base:"ensembl",root:{background:"white",titleColor:"#494949",titleFontSize:24,titleFontFamily:"GGX88",titleAlign:"left",titleFontWeight:"bold",titleBackgroundColor:"white",subtitleColor:"white",subtitleFontSize:19,subtitleFontFamily:"GGX88",subtitleAlign:"left",subtitleFontWeight:"normal",subtitleBackgroundColor:"#7B8BAF",mousePositionColor:"#FE0000",showMousePosition:!0},track:{background:"white",alternatingBackground:"#fffdf7",titleColor:"black",titleBackground:"white",titleAlign:"left",outline:"#7B8BAF",outlineWidth:2},legend:{tickColor:"black",labelColor:"black",labelFontWeight:"normal",labelFontFamily:"GGX88",background:"white",backgroundOpacity:2,backgroundStroke:"lightgray"},axis:{tickColor:"black",labelColor:"black",labelFontFamily:"GGX88",baselineColor:"black",gridColor:"#7B8BAF",gridStrokeWidth:2},markCommon:{...Ro},point:{...Ro,size:3},rect:{...Ro},triangle:{...Ro},area:{...Ro},line:{...Ro},bar:{...Ro},rule:{...Ro,strokeWidth:1},link:{...Ro,strokeWidth:1},text:{...Ro,textAnchor:"middle",textFontWeight:"normal"},brush:{...Ro,color:"gray",opacity:.3,stroke:"black",strokeWidth:1}},Qse=["#3A62FE","#F85353","#3A62FE","#F85353","#DCA326","#03BF06","#BABABA"],Wo={color:Qse[0],size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:Qse,quantitativeSizeRange:[2,6]},aqt={base:"jbrowse",root:{background:"white",titleColor:"white",titleFontSize:20,titleFontFamily:"Roboto",titleAlign:"middle",titleFontWeight:"normal",titleBackgroundColor:"#0b243f",subtitleColor:"white",subtitleFontSize:18,subtitleFontFamily:"Roboto",subtitleAlign:"middle",subtitleFontWeight:"normal",subtitleBackgroundColor:"#732162",showMousePosition:!0,mousePositionColor:"#000000"},track:{background:"white",alternatingBackground:"white",titleAlign:"middle",titleColor:"white",titleBackground:"#0B243F",outline:"black",outlineWidth:1},legend:{position:"top",background:"white",backgroundOpacity:.7,labelColor:"#DCA326",labelFontWeight:"bold",labelFontFamily:"Roboto",backgroundStroke:"#black",tickColor:"black"},axis:{tickColor:"black",labelColor:"#DCA326",labelFontWeight:"bold",labelFontFamily:"Roboto",baselineColor:"black",gridColor:"#c5d5d9",gridStrokeWidth:1},markCommon:{...Wo},point:{...Wo,size:3},rect:{...Wo},triangle:{...Wo},area:{...Wo},line:{...Wo},bar:{...Wo},rule:{...Wo,strokeWidth:1},link:{...Wo,strokeWidth:1},text:{...Wo,textAnchor:"middle",textFontWeight:"normal"},brush:{...Wo,color:"#c5d5d9",opacity:.3,stroke:"black",strokeWidth:1}},jse=["#3A5FCD","#FFA54E","#8FBC8F","#B6709B","#EE6A50","#CCB79E","#DADA8F","#00CDCC","#EED5D2","#CD8EDD","#9ACD31","#D1BEA8","#FFB6C0"],Xo={color:jse[0],size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:jse,quantitativeSizeRange:[2,6]},sqt={base:"ucsc",root:{background:"white",titleColor:"white",titleFontSize:22,titleAlign:"middle",titleFontWeight:"bold",titleBackgroundColor:"#00457c",subtitleColor:"black",subtitleAlign:"middle",subtitleFontWeight:"bold",subtitleBackgroundColor:"white",showMousePosition:!0,mousePositionColor:"#FE0000"},track:{background:"white",alternatingBackground:"#e3f7fc",titleColor:"#3A5FCD",titleBackground:"white",outline:"black",outlineWidth:1},legend:{position:"top",background:"white",backgroundOpacity:.7,labelColor:"black",labelFontWeight:"bold",backgroundStroke:"#DBDBDB",tickColor:"black"},axis:{tickColor:"black",labelColor:"#3A5FCD",labelFontWeight:"bold",baselineColor:"black",gridColor:"#E3E3E3",gridStrokeWidth:1},markCommon:{...Xo},point:{...Xo,size:3},rect:{...Xo},triangle:{...Xo},area:{...Xo},line:{...Xo},bar:{...Xo},rule:{...Xo,strokeWidth:1},link:{...Xo,strokeWidth:1},text:{...Xo,textAnchor:"middle",textFontWeight:"normal"},brush:{...Xo,color:"gray",opacity:.3,stroke:"black",strokeWidth:1}},$se=["#6E12AC","#15C250","#E70FB1","#FF8E55","#A3B8F3","#DE5E59","#77AAAA","#F5CCCA"],Ho={color:$se[0],size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:$se,quantitativeSizeRange:[2,6]},lqt={base:"washu",root:{background:"white",titleColor:"gray",titleAlign:"left",titleFontWeight:"normal",titleBackgroundColor:"white",subtitleColor:"lightgray",subtitleAlign:"left",subtitleFontWeight:"light",subtitleBackgroundColor:"white",showMousePosition:!0,mousePositionColor:"#000000"},track:{background:"white",titleColor:"gray",titleBackground:"white",titleAlign:"left",outline:"gray",outlineWidth:1},legend:{background:"white",backgroundOpacity:.5,labelColor:"gray",labelFontWeight:"light",backgroundStroke:"#DBDBDB",tickColor:"gray"},axis:{tickColor:"lightgray",labelColor:"gray",labelFontWeight:"light",baselineColor:"gray",gridColor:"transparent",gridStrokeWidth:0},markCommon:{...Ho},point:{...Ho,size:3},rect:{...Ho},triangle:{...Ho},area:{...Ho},line:{...Ho},bar:{...Ho},rule:{...Ho,strokeWidth:1},link:{...Ho,strokeWidth:1},text:{...Ho,textAnchor:"middle",textFontWeight:"normal"},brush:{...Ho,color:"gray",opacity:.3,stroke:"gray",strokeWidth:1}},qse=["#ED7D31","#4472C4","#FFC207","#76AE4F","#9E480E","#A5A5A5","#4472C4","#264378","#76AE4F","#5B9CD5"],To={color:qse[0],size:1,stroke:"#5A5A5A",strokeWidth:0,opacity:1,nominalColorRange:qse,quantitativeSizeRange:[2,6]},cqt={base:"excel",root:{background:"white",titleColor:"#5A5A5A",titleFontSize:30,titleFontFamily:"Calibri",titleAlign:"middle",titleFontWeight:"bold",titleBackgroundColor:"white",subtitleColor:"#5A5A5A",subtitleFontSize:22,subtitleFontFamily:"Calibri",subtitleAlign:"middle",subtitleFontWeight:"bold",subtitleBackgroundColor:"white",showMousePosition:!0,mousePositionColor:"#000000"},track:{background:"white",alternatingBackground:"#f5f5f5",titleColor:"#5A5A5A",titleBackground:"white",outline:"#5A5A5A",outlineWidth:1},legend:{position:"right",tickColor:"#5A5A5A",labelColor:"#5A5A5A",labelFontSize:12,labelFontWeight:"bold",labelFontFamily:"Calibri",background:"white",backgroundOpacity:.7,backgroundStroke:"#5A5A5A"},axis:{tickColor:"#5A5A5A",labelColor:"#5A5A5A",labelFontFamily:"Calibri",baselineColor:"#5A5A5A",gridColor:"#5A5A5A",gridStrokeWidth:1},markCommon:{...To},point:{...To,size:3},rect:{...To},triangle:{...To},area:{...To},line:{...To},bar:{...To},rule:{...To,strokeWidth:1},link:{...To,strokeWidth:1},text:{...To,textAnchor:"middle",textFontWeight:"normal"},brush:{...To,color:"#5A5A5A",opacity:.3,stroke:"#5A5A5A",strokeWidth:1}},ele=["#4185f4","#DB4437","#F4B400","#0D9D58","#AA30C3","#FF6E02","#CBC74C"],No={color:ele[0],size:2,stroke:"black",strokeWidth:.3,opacity:1,nominalColorRange:ele,quantitativeSizeRange:[2,6]},uqt={base:"google",root:{background:"white",titleColor:"#454545",titleFontSize:20,titleFontFamily:"Arial",titleAlign:"left",titleFontWeight:"normal",titleBackgroundColor:"white",subtitleColor:"#7d7d7d",subtitleFontSize:16,subtitleFontFamily:"Arial",subtitleAlign:"left",subtitleFontWeight:"light",subtitleBackgroundColor:"white",showMousePosition:!0,mousePositionColor:"#000000"},track:{background:"white",alternatingBackground:"#f5f5f5",titleColor:"#e8e8e8",titleBackground:"white",titleFontSize:12,titleAlign:"left",outline:"black",outlineWidth:1},legend:{position:"right",background:"white",backgroundOpacity:1,labelColor:"black",labelFontSize:12,labelFontWeight:"normal",labelFontFamily:"Arial",backgroundStroke:"black",tickColor:"black"},axis:{labelFontSize:12,labelFontWeight:"normal",labelFontFamily:"Arial",tickColor:"black",labelColor:"black",baselineColor:"black",gridColor:"black",gridStrokeWidth:1},markCommon:{...No},point:{...No,size:3},rect:{...No},triangle:{...No},area:{...No},line:{...No},bar:{...No},rule:{...No,strokeWidth:1},link:{...No,strokeWidth:1},text:{...No,textAnchor:"middle",textFontWeight:"normal"},brush:{...No,color:"#999999",opacity:.3,stroke:"black",strokeWidth:.7}},OO={light:Iqt,dark:nqt,warm:Cqt,ggplot:rqt,igv:oqt,ensembl:Aqt,jbrowse:aqt,ucsc:sqt,washu:lqt,excel:cqt,google:uqt};function LO(g){return Object.keys(OO).indexOf(g)!==-1}function SG(g){return LO(g)?OO[g]:OO.light}function w$(g,e){var I;function i(...n){if(!new.target)throw new Error('Uncaught TypeError: Class constructor cannot be invoked without "new"');return e(...n)}return i.config={...g,availableOptions:Object.keys((I=g.defaultOptions)!=null?I:{})},i}const dqt=200,hqt=6,mqt=2,mHe=7829367,fqt=' ',pqt={type:"axis-track",datatype:["multivec","epilogos"],local:!1,orientation:"1d-horizontal",thumbnail:new DOMParser().parseFromString(fqt,"text/xml").documentElement,defaultOptions:{innerRadius:340,outerRadius:310,startAngle:0,endAngle:360,width:700,height:700,layout:"linear",labelMargin:5,excludeChrPrefix:!1,labelPosition:"none",labelColor:"black",labelTextOpacity:.4,trackBorderWidth:0,trackBorderColor:"black",tickPositions:"even",fontSize:12,fontFamily:"sans-serif",fontWeight:"normal",color:"#808080",stroke:"#ffffff",backgroundColor:"transparent",showMousePosition:!1,tickColor:mHe}},bqt=(g,e,I)=>{const{absToChr:i,colorToHex:n,pixiTextToSvg:C,svgLine:r,showMousePosition:o}=g.utils;function A(a,l){return Object.assign(new g.libraries.PIXI.Text(a,l),{hashValue:Math.random()})}class s extends g.tracks.PixiTrack{constructor(){super(e,I),nt(this,"allTexts"),nt(this,"searchField"),nt(this,"chromInfo"),nt(this,"dataConfig"),nt(this,"pTicksCircular"),nt(this,"pTicks"),nt(this,"gTicks"),nt(this,"tickTexts"),nt(this,"isShowGlobalMousePosition"),nt(this,"pixiTextConfig"),nt(this,"stroke"),nt(this,"tickWidth"),nt(this,"tickHeight"),nt(this,"tickTextSeparation"),nt(this,"tickColor"),nt(this,"animate"),nt(this,"hideMousePosition"),nt(this,"gBoundTicks"),nt(this,"leftBoundTick"),nt(this,"rightBoundTick"),nt(this,"is2d"),nt(this,"texts");const{dataConfig:l,animate:c,chromInfoPath:u,isShowGlobalMousePosition:d}=e;this.searchField=null,this.dataConfig=l,this.allTexts=[],this.pTicksCircular=new g.libraries.PIXI.Graphics,this.pTicks=new g.libraries.PIXI.Graphics,this.pMain.addChild(this.pTicks),this.pMain.addChild(this.pTicksCircular),this.gTicks={},this.tickTexts={},this.options=I,this.isShowGlobalMousePosition=d,this.pixiTextConfig=Os({size:+this.options.fontSize,fontFamily:this.options.fontFamily,fontWeight:this.options.fontWeight,color:this.options.color,stroke:this.options.stroke,strokeThickness:2}),this.stroke=n(this.pixiTextConfig.stroke),this.tickWidth=dqt,this.tickHeight=hqt,this.tickTextSeparation=mqt,this.tickColor=n(this.options.tickColor),this.animate=c,this.pubSubs=[],this.options.showMousePosition&&!this.hideMousePosition&&(this.hideMousePosition=o(this,this.is2d,this.isShowGlobalMousePosition()));let h=u;h||(h=`${l.server}/chrom-sizes/?id=${l.tilesetUid}`);const m=this.options.assembly,f={},b={...yI(m).size},p=[];Object.keys(yI(m).size).forEach(y=>{f[y]={chr:y,pos:yI(m).size[y]}}),Object.keys(yI(m).interval).forEach(y=>{p.push({chr:y,pos:yI(m).interval[y][0]})}),this.chromInfo={chrPositions:f,chromLengths:b,cumPositions:p},this.rerender(this.options,!0),this.draw(),this.animate()}initBoundsTicks(){this.pTicks&&(this.pMain.removeChild(this.pTicks),this.pTicks=null),this.gBoundTicks||(this.gBoundTicks=new g.libraries.PIXI.Graphics,this.leftBoundTick=A("",this.pixiTextConfig),this.rightBoundTick=A("",this.pixiTextConfig),this.gBoundTicks.addChild(this.leftBoundTick),this.gBoundTicks.addChild(this.rightBoundTick),this.pMain.addChild(this.gBoundTicks)),this.texts=[]}initChromLabels(){this.chromInfo&&(this.gBoundTicks&&(this.pMain.removeChild(this.gBoundTicks),this.gBoundTicks=void 0),this.pTicks||(this.pTicks=new g.libraries.PIXI.Graphics,this.pMain.addChild(this.pTicks)),this.texts=[],this.pTicks.removeChildren(),this.chromInfo.cumPositions.forEach(l=>{var c,u,d;const h=l.chr;this.gTicks[h]=new g.libraries.PIXI.Graphics,this.tickTexts[h]||(this.tickTexts[h]=[]);const m=this.options.excludeChrPrefix?h.replace("chr",""):h,f=A(m,this.pixiTextConfig);(c=this.pTicks)==null||c.addChild(f),(u=this.pTicks)==null||u.addChild(this.gTicks[h]),(d=this.texts)==null||d.push(f)}))}rerender(l,c){const u=JSON.stringify(l);!c&&u===this.prevOptions||(this.prevOptions=u,this.options=l,this.pixiTextConfig.fontSize=+this.options.fontSize?`${+this.options.fontSize}px`:this.pixiTextConfig.fontSize,this.pixiTextConfig.fill=this.options.color||this.pixiTextConfig.fill,this.pixiTextConfig.stroke=this.options.stroke||this.pixiTextConfig.stroke,this.stroke=n(this.pixiTextConfig.stroke),this.tickColor=this.options.tickColor?n(this.options.tickColor):mHe,this.options.tickPositions==="ends"&&this.options.layout!=="circular"?this.initBoundsTicks():this.initChromLabels(),super.rerender(l,c),this.options.showMousePosition&&!this.hideMousePosition&&(this.hideMousePosition=o(this,this.is2d,this.isShowGlobalMousePosition())),!this.options.showMousePosition&&this.hideMousePosition&&(this.hideMousePosition(),this.hideMousePosition=void 0))}formatTick(l){if(isNaN(l))return"null";const c=this._xScale.domain(),u=c[1]-c[0],d=r$e(l,u),h=u0e(","),m=d0e(`,.${d}`,u);let f=h;return this.options.tickFormat==="si"?f=m:this.options.tickFormat==="plain"?f=h:this.options.tickPositions==="ends"&&(f=m),f(l)}drawBoundsTicks(l,c){if(!this.gBoundTicks||!this.leftBoundTick||!this.rightBoundTick)return;const u=this.gBoundTicks;u.clear(),u.lineStyle(1,0);const d=this.options.reverseOrientation?0:this.dimensions[1],h=this.options.reverseOrientation?this.tickHeight:this.dimensions[1]-this.tickHeight;u.moveTo(1,d),u.lineTo(1,h),u.moveTo(this.dimensions[0]-1,d),u.lineTo(this.dimensions[0]-1,h),this.leftBoundTick.x=0,this.leftBoundTick.y=this.options.reverseOrientation?h+this.tickTextSeparation:h-this.tickTextSeparation,this.leftBoundTick.text=this.options.assembly==="unknown"?`${this.formatTick(l[1])}`:`${l[0]}: ${this.formatTick(l[1])}`,this.leftBoundTick.anchor.y=this.options.reverseOrientation?0:1,this.rightBoundTick.x=this.dimensions[0],this.rightBoundTick.text=this.options.assembly==="unknown"?`${this.formatTick(c[1])}`:`${c[0]}: ${this.formatTick(c[1])}`,this.rightBoundTick.y=this.options.reverseOrientation?h+this.tickTextSeparation:h-this.tickTextSeparation,this.rightBoundTick.anchor.y=this.options.reverseOrientation?0:1,this.rightBoundTick.anchor.x=1,this.flipText&&(this.leftBoundTick.scale.x=-1,this.leftBoundTick.anchor.x=1,this.rightBoundTick.scale.x=-1,this.rightBoundTick.anchor.x=0),this.leftBoundTick.tickLine=[1,this.dimensions[1],1,this.dimensions[1]-this.tickHeight],this.rightBoundTick.tickLine=[this.dimensions[0]-1,this.dimensions[1],this.dimensions[0]-1,this.dimensions[1]-this.tickHeight],this.tickTexts={},this.tickTexts.all=[this.leftBoundTick,this.rightBoundTick]}drawTicks(l){const c=this.gTicks[l.chr];c.visible=!0,c.clear();const u=+this.chromInfo.chromLengths[l.chr],d=Math.max(this._xScale(l.pos),0),h=Math.min(this._xScale(l.pos+u),this.dimensions[0]),m=(h-d)/this.tickWidth,b=nh().domain([Math.max(1,this._xScale.invert(0)-l.pos),Math.min(u,this._xScale.invert(this.dimensions[0])-l.pos)]).range([d,h]).ticks(m).filter(B=>Number.isInteger(B)),p=this.tickTexts[l.chr],y=this.tickHeight,Z=0;let v=y+this.tickTextSeparation;for(this.options.reverseOrientation&&(v=this.dimensions[1]-v);p.lengthb.length;){const B=p.pop();this.gTicks[l.chr].removeChild(B)}let G=0;for(;Gu){const V=R-u;R=u,w-=V}const S=[],X=b+G.height/2+3;for(let V=R;V>=w;V-=B/10){const H=Lt(V,u,X,u/2,d/2,h,m);S.push(new g.libraries.PIXI.Point(H.x,H.y))}return S.length===0?void 0:(l.updateText(),new g.libraries.PIXI.SimpleRope(l.texture,S))}draw(){if(this.allTexts=[],!this.texts)return;const l=i(this._xScale.domain()[0],this.chromInfo),c=i(this._xScale.domain()[1],this.chromInfo);if(!l||!c){console.warn("Empty chromInfo:",this.dataConfig,this.chromInfo);return}if(this.options.tickPositions==="ends"&&this.options.layout!=="circular"){if(!this.gBoundTicks)return;this.gBoundTicks.visible=!0,this.drawBoundsTicks(l,c);return}if(!this.pTicks)return;const u=this.options.layout==="circular";for(let h=0;h{this.tickTexts[h]&&this.tickTexts[h].forEach(m=>{m.visible=!1})}),this.pTicksCircular.removeChildren();for(let h=l[3];h<=c[3];h++){const m=this.chromInfo.cumPositions[h],f=m.pos+this.chromInfo.chromLengths[m.chr]/2,b=this._xScale(f),p=this.texts[h];p.anchor.x=.5,p.anchor.y=u?.5:this.options.reverseOrientation?0:1;let y;u?(y=this.addCurvedText(p,b),y&&this.pTicksCircular.addChild(y)):(p.x=b,p.y=this.dimensions[1]-d),p.updateTransform(),this.flipText&&(p.scale.x=-1);const Z=this.drawTicks(m);u?Z>0&&y&&this.pTicksCircular.removeChild(y):p.visible=Z<=0,this.allTexts.push({importance:p.hashValue,text:p,rope:y})}this.hideOverlaps(this.allTexts)}hideOverlaps(l){const c=new L4e;l.sort((u,d)=>d.importance-u.importance).forEach(({text:u,rope:d})=>{u.updateTransform();const h=u.getBounds(),m=this.options.labelMargin,f={minX:h.x-m,minY:h.y-m,maxX:h.x+h.width+m*2,maxY:h.y+h.height+m*2};m<0||!c.collides(f)?c.insert(f):(u.visible=!1,this.options.layout==="circular"&&d&&this.pTicksCircular.removeChild(d))})}setPosition(l){super.setPosition(l),[this.pMain.position.x,this.pMain.position.y]=this.position}zoomed(l,c){[...l.domain(),...c.domain()].filter(d=>isNaN(d)).length===0&&(this.xScale(l),this.yScale(c),this.draw())}exportSVG(){let l=null,c=null;super.exportSVG?[c,l]=super.exportSVG():(c=document.createElement("g"),l=c),c.setAttribute("class","chromosome-labels");const u=document.createElement("g");return l.appendChild(u),u.setAttribute("transform",`translate(${this.position[0]},${this.position[1]})`),this.allTexts.filter(d=>d.text.visible).forEach(d=>{const h=C(d.text);u.appendChild(h)}),Object.values(this.tickTexts).forEach(d=>{d.filter(h=>h.visible).forEach(h=>{if(!h.tickLine)return;let m=C(h);u.appendChild(m),m=r(h.x,this.options.reverseOrientation?0:this.dimensions[1],h.x,this.options.reverseOrientation?this.tickHeight:this.dimensions[1]-this.tickHeight,1,this.tickColor);const f=document.createElement("line");f.setAttribute("x1",String(h.tickLine[0])),f.setAttribute("y1",String(h.tickLine[1])),f.setAttribute("x2",String(h.tickLine[2])),f.setAttribute("y2",String(h.tickLine[3])),f.setAttribute("style","stroke: grey"),u.appendChild(m),u.appendChild(f)})}),[c,l]}}return new s},tle=w$(pqt,bqt);function _O(g,...e){if(!new.target)throw new Error('Uncaught TypeError: Class constructor cannot be invoked without "new"');class I extends g.tracks.SVGTrack{constructor(n){var C,r;super(...n),nt(this,"circularBrushData"),nt(this,"prevExtent");const[o,A]=n,{registerViewportChanged:s,removeViewportChanged:a,setDomainsCallback:l}=o;this.uid=on(),this.options=A,this.hasFromView=!o.projectionXDomain,this.removeViewportChanged=a,this.setDomainsCallback=l,this.viewportXDomain=this.hasFromView?null:o.projectionXDomain,this.viewportYDomain=this.hasFromView?null:[0,0],this.prevExtent=[0,0],this.RR=.02;const c=[0,Math.PI*1.7];this.circularBrushData=this.getBrushData(c),this.brush=f$e().innerRadius((C=this.options.innerRadius)!=null?C:100).outerRadius((r=this.options.outerRadius)!=null?r:200),this.gBrush=this.gMain.append("g").attr("id",`brush-${this.uid}`).selectAll(".brush").data(this.circularBrushData).enter().append("path").attr("class","brush").attr("d",this.brush).attr("fill",this.options.projectionFillColor).attr("stroke",this.options.projectionStrokeColor).attr("fill-opacity",u=>u.type==="brush"?this.options.projectionFillOpacity:0).attr("stroke-opacity",u=>u.type==="brush"?this.options.projectionStrokeOpacity:0).attr("stroke-width",this.options.strokeWidth).style("pointer-events","all").style("cursor",u=>u.cursor).call(this.dragged()),s(this.uid,this.viewportChanged.bind(this)),this.draw()}getBrushData(n){return[{type:"brush",startAngle:n[0],endAngle:n[1],cursor:"grab"},{type:"start",startAngle:n[0],endAngle:n[0]+this.RR,cursor:"move"},{type:"end",startAngle:n[1]-this.RR,endAngle:n[1],cursor:"move"}]}cropExtent(n){let[C,r]=n,o=0;for(;(C>Math.PI*2||r>Math.PI*2||C<0||r<0)&&!(o++>10);)C>Math.PI*2||r>Math.PI*2?(C-=Math.PI*2,r-=Math.PI*2):(C<0||r<0)&&(C+=Math.PI*2,r+=Math.PI*2);return[C,r].sort((A,s)=>A-s)}updateBrush(n){let[C,r]=n;if(C<=$i&&r<=$i||C>=Math.PI*2-$i&&r>=Math.PI*2-$i){this.gBrush.attr("visibility","hidden");return}C<$i&&(C=$i),C>Math.PI*2-$i&&(C=Math.PI*2-$i),r<$i&&(r=$i),r>Math.PI*2-$i&&(r=Math.PI*2-$i),this.circularBrushData=this.getBrushData(n),this.gBrush.data(this.circularBrushData).attr("d",this.brush).attr("visibility","visible")}dragged(){const n=r=>{this.startEvent=r.sourceEvent,this.prevExtent=[this.circularBrushData[0].startAngle,this.circularBrushData[0].endAngle]},C=(r,o)=>{const[A,s]=this.position,[a,l]=this.dimensions,c=r.sourceEvent,u=this.startEvent.layerX-A,d=this.startEvent.layerY-s,h=c.layerX-A,m=c.layerY-s,f=Math.atan2(u-a/2,d-l/2)-Math.atan2(h-a/2,m-l/2);let[b,p]=this.prevExtent;if(o.type==="brush"){if(b=b+f,p=p+f,b<$i||Math.PI*2-$iR?(p+=w,b+=w):(b-=R,p-=R)}}else o.type==="start"?b=b+f:o.type==="end"&&(p=p+f);if([b,p]=this.cropExtent([b,p]),!this._xScale||!this._yScale)return;const y=(this.options.endAngle-this.options.startAngle)/360,Z=b-this.options.startAngle/360*Math.PI*2,v=p-this.options.startAngle/360*Math.PI*2,G=[this._xScale.invert(a-a*v/(Math.PI*2*y)),this._xScale.invert(a-a*Z/(Math.PI*2*y))],B=this.viewportYDomain;this.hasFromView||(this.viewportXDomain=G),this.setDomainsCallback(G,B),this.updateBrush([b,p])};return g.libraries.d3Drag.drag().on("start",n).on("drag",C)}draw(){if(!this._xScale||!this.yScale||!this.viewportXDomain||!this.viewportYDomain)return;const n=this._xScale(this.viewportXDomain[0]),C=this._xScale(this.viewportXDomain[1]),[r]=this.dimensions;let o=qg(n,r,this.options.startAngle,this.options.endAngle)+Math.PI/2,A=qg(C,r,this.options.startAngle,this.options.endAngle)+Math.PI/2;[A,o]=this.cropExtent([A,o]),this.updateBrush([A,o])}viewportChanged(n,C){const r=n.domain(),o=C.domain();this.viewportXDomain=r,this.viewportYDomain=o,this.draw()}remove(){this.removeViewportChanged(this.uid),super.remove()}rerender(){}zoomed(n,C){this.xScale(n),this.yScale(C),this.draw()}setPosition(n){super.setPosition(n),this.draw()}setDimensions(n){super.setDimensions(n),this.gBrush.attr("transform",`translate(${n[0]/2},${n[1]/2})`),this.draw()}}return new I(e)}const yqt=' ';_O.config={type:"brush-track",datatype:["projection"],local:!1,projection:!0,orientation:"2d",thumbnail:new DOMParser().parseFromString(yqt,"text/xml").documentElement,availableOptions:["innerRadius","outerRadius","startAngle","endAngle","axisPositionHorizontal","projectionFillColor","projectionStrokeColor","projectionFillOpacity","projectionStrokeOpacity","strokeWidth"],defaultOptions:{innerRadius:100,outerRadius:200,startAngle:0,endAngle:360,axisPositionHorizontal:"left",projectionFillColor:"#777",projectionStrokeColor:"#777",projectionFillOpacity:.3,projectionStrokeOpacity:.7,strokeWidth:1}};const gle=3,Zqt={color:"#777",stroke:"#777",strokeWidth:1,strokeOpacity:.7,opacity:.3};class Gqt{constructor(e,I,i={}){nt(this,"brushSelection"),nt(this,"style"),nt(this,"range"),nt(this,"data"),nt(this,"startEvent"),nt(this,"prevExtent"),nt(this,"offset"),nt(this,"size"),nt(this,"externals"),nt(this,"emitter"),this.emitter=p$e(),this.range=null,this.prevExtent=[0,0],this.data=this.rangeToData(0,0),this.offset=[0,0],this.size=0,this.externals={d3Selection:I.d3Selection,d3Drag:I.d3Drag},this.style=Object.assign({},Zqt,i),this.brushSelection=e.selectAll(".genomic-range-brush").data(this.data).enter().append("rect").attr("class","genomic-range-brush").call(this.onDrag())}getRange(){return this.range}setSize(e){return this.size=e,this}setOffset(e,I){return this.offset=[e,I],this}updateRange(e){return e?(this.range=[Math.min(...e),Math.max(...e)],this.data=this.rangeToData(...this.range)):this.range=null,this}drawBrush(e=!1){const[I,i]=this.offset,n=this.size,C=r=>Math.abs(r.end-r.start);return this.brushSelection.data(this.data).attr("transform",r=>`translate(${I+r.start}, ${i+1})`).attr("width",r=>`${C(r)}px`).attr("height",`${n-2}px`).attr("fill",this.style.color).attr("stroke",this.style.stroke).attr("stroke-width",`${this.style.strokeWidth}px`).attr("fill-opacity",r=>r.type==="body"?this.style.opacity:0).attr("stroke-opacity",r=>r.type==="body"?this.style.strokeOpacity:0).attr("cursor",r=>r.cursor),this.emitter.emit("brush",this.getRange(),e),this}enable(){return this.brushSelection.attr("pointer-events","all"),this}disable(){return this.brushSelection.attr("pointer-events","none"),this}visible(){return this.brushSelection.attr("visibility","visible"),this}hidden(){return this.brushSelection.attr("visibility","hidden"),this}clear(){return this.updateRange(null).drawBrush().hidden().disable(),this}remove(){return this.brushSelection.remove(),this}rangeToData(e,I){return[{type:"body",cursor:"grab",start:e,end:I},{type:"start",cursor:"ew-resize",start:e-gle,end:e},{type:"end",cursor:"ew-resize",start:I,end:I+gle}]}onDrag(){const e=i=>{this.startEvent=i.sourceEvent,this.prevExtent=this.range},I=(i,n)=>{var C;const r=i.sourceEvent.layerX-this.startEvent.layerX;let[o,A]=(C=this.prevExtent)!=null?C:[0,0];n.type==="body"?(o+=r,A+=r):n.type==="start"?o+=r:n.type==="end"&&(A+=r),this.updateRange([o,A]).drawBrush()};return this.externals.d3Drag.drag().on("start",e).on("drag",I)}on(e,I){this.emitter.on(e,I)}}const Bqt=([g,e],[I,i],[n,C],[r,o])=>{const A=Math.sqrt((g-I)**2+(e-i)**2);if(AMath.sqrt((g-I)**2+(e-i)**2)g<=I&&I<=e,Sqt=(g,e,I=5)=>UO(g,e-I)&&UO(g,e+I),wqt=(g,e)=>e.filter((I,i)=>i%2===0).every(I=>UO(g,I)),Vqt=([g,e],I,i=5)=>{let n,C,r,o,A=!1;for(let s=0;s0?h=Math.sqrt((e-o)**2+(g-r)**2):d<0?h=Math.sqrt((e-C)**2+(g-n)**2):h=Math.abs(a[0]*c[1]-a[1]*c[0])/Math.sqrt(a[0]**2+a[1]**2),h{let i,n,C,r,o=!1;for(let A=0,s=I.length-2;Ae!=r>e&&g<(C-i)*(e-n)/(r-n)+i&&(o=!o),s=A;return o};class Wqt{constructor(){nt(this,"data"),this.data=[]}size(){return this.data.length}addPolygonBasedEvent(e,I){this.data.push({uid:on(),type:"polygon",value:e,polygon:I})}addPointBasedEvent(e,I){this.data.push({uid:on(),type:"point",value:e,polygon:I})}addLineBasedEvent(e,I){this.data.push({uid:on(),type:"line",value:e,polygon:I})}clear(){this.data=[]}find(e,I,i=!1){const n=Array.from(this.data);return i&&n.reverse(),n.find(C=>this.isMouseWithin(C,e,I))}findAll(e,I,i=!1){const n=Array.from(this.data);return i&&n.reverse(),n.filter(C=>this.isMouseWithin(C,e,I))}getSiblings(e,I){const i=[],n=Array.from(new Set(e.map(C=>C.uid)));return e.forEach(C=>{const r=C.value[I];r&&i.push(...this.data.filter(o=>o.value[I]===r&&n.indexOf(o.uid)===-1))}),i}isMouseWithin(e,I,i){switch(e.type){case"point":return vqt([I,i],e.polygon);case"line":return Vqt([I,i],e.polygon);case"polygon":default:return Rqt([I,i],e.polygon)}}findAllWithinRange(e,I,i=!1){const n=Array.from(this.data);return i&&n.reverse(),n.filter(C=>this.isWithinRange(C,e,I))}isWithinRange(e,I,i){switch(e.type){case"point":return Sqt([I,i],e.polygon[0],e.polygon[2]);case"line":case"polygon":default:return wqt([I,i],e.polygon)}}}const fHe="KCgpID0+IHsKICB2YXIgX19jcmVhdGUgPSBPYmplY3QuY3JlYXRlOwogIHZhciBfX2RlZlByb3AgPSBPYmplY3QuZGVmaW5lUHJvcGVydHk7CiAgdmFyIF9fZ2V0T3duUHJvcERlc2MgPSBPYmplY3QuZ2V0T3duUHJvcGVydHlEZXNjcmlwdG9yOwogIHZhciBfX2dldE93blByb3BOYW1lcyA9IE9iamVjdC5nZXRPd25Qcm9wZXJ0eU5hbWVzOwogIHZhciBfX2dldFByb3RvT2YgPSBPYmplY3QuZ2V0UHJvdG90eXBlT2Y7CiAgdmFyIF9faGFzT3duUHJvcCA9IE9iamVjdC5wcm90b3R5cGUuaGFzT3duUHJvcGVydHk7CiAgdmFyIF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AgICAgIGlmIChwbGFjZUhvbGRlcnNMZW4gPT09IDIpIHsKICAgICAgICAgIHRtcCA9IHJldkxvb2t1cFtiNjQuY2hhckNvZGVBdChpMildIDw8IDIgfCByZXZMb29rdXBbYjY0LmNoYXJDb2RlQXQoaTIgKyAxKV0gPj4gNDsKICAgICAgICAgIGFycltjdXJCeXRlKytdID0gdG1wICYgMjU1OwogICAgICAgIH0KICAgICAgICBpZiAocGxhY2VIb2xkZXJzTGVuID09PSAxKSB7CiAgICAgICAgICB0bXAgPSByZXZMb29rdXBbYjY0LmNoYXJDb2RlQXQoaTIpXSA8PCAxMCB8IHJldkxvb2t1cFtiNjQuY2hhckNvZGVBdChpMiArIDEpXSA8PCA0IHwgcmV2TG9va3VwW2I2NC5jaGFyQ29kZUF0KGkyICsgMildID4+IDI7CiAgICAgICAgICBhcnJbY3VyQnl0ZSsrXSA9IHRtcCA+PiA4ICYgMjU1OwogICAgICAgICAgYXJyW2N1ckJ5dGUrK10gPSB0bXAgJiAyNTU7CiAgICAgICAgfQogICAgICAgIHJldHVybiBhcnI7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gdHJpcGxldFRvQmFzZTY0KG51bSkgewogICAgICAgIHJldHVybiBsb29rdXBbbnVtID4+IDE4ICYgNjNdICsgbG9va3VwW251bSA+PiAxMiAmIDYzXSArIGxvb2t1cFtudW0gPj4gNiAmIDYzXSArIGxvb2t1cFtudW0gJiA2M107CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZW5jb2RlQ2h1bmsodWludDgsIHN0YXJ0LCBlbmQpIHsKICAgICAgICB2YXIgdG1wOwogICAgICAgIHZhciBvdXRwdXQgPSBbXTsKICAgICAgICBmb3IgKHZhciBpMiA9IHN0YXJ0OyBpMiA8IGVuZDsgaTIgKz0gMykgewogICAgICAgICAgdG1wID0gKHVpbnQ4W2kyXSA8PCAxNiAmIDE2NzExNjgwKSArICh1aW50OFtpMiArIDFdIDw8IDggJiA2NTI4MCkgKyAodWludDhbaTIgKyA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Qml0cyArPSBtTGVuOwogICAgICAgIGZvciAoOyBuQml0cyA+IDA7IG0gPSBtICogMjU2ICsgYnVmZmVyW29mZnNldCArIGldLCBpICs9IGQsIG5CaXRzIC09IDgpIHsKICAgICAgICB9CiAgICAgICAgaWYgKGUgPT09IDApIHsKICAgICAgICAgIGUgPSAxIC0gZUJpYXM7CiAgICAgICAgfSBlbHNlIGlmIChlID09PSBlTWF4KSB7CiAgICAgICAgICByZXR1cm4gbSA/IE5hTiA6IChzID8gLTEgOiAxKSAqIEluZmluaXR5OwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBtID0gbSArIE1hdGgucG93KDIsIG1MZW4pOwogICAgICAgICAgZSA9IGUgLSBlQmlhczsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIChzID8gLTEgOiAxKSAqIG0gKiBNYXRoLnBvdygyLCBlIC0gbUxlbik7CiAgICAgIH07CiAgICAgIGV4cG9ydHMud3JpdGUgPSBmdW5jdGlvbihidWZmZXIsIHZhbHVlLCBvZmZzZXQsIGlzTEUsIG1MZW4sIG5CeXRlcykgewogICAgICAgIHZhciBlLCBtLCBjOwogICAgICAgIHZhciBlTGVuID0gbkJ5dGVzICogOCAtIG1MZW4gLSAxOwogICAgICAgIHZhciBlTWF4ID0gKDEgPDwgZUxlbikgLSAxOwogICAgICAgIHZhciBlQmlhcyA9IGVNYXggPj4gMTsKICAgICAgICB2YXIgcnQgPSBtTGVuID09PSAyMyA/IE1hdGgucG93KDIsIC0yNCkgLSBNYXRoLnBvdygyLCAtNzcpIDogMDsKICAgICAgICB2YXIgaSA9IGlzTEUgPyAwIDogbkJ5dGVzIC0gMTsKICAgICAgICB2YXIgZCA9IGlzTEUgPyAxIDogLTE7CiAgICAgICAgdmFyIHMgPSB2YWx1ZSA8IDAgfHwgdmFsdWUgPT09IDAgJiYgMSAvIHZhbHVlIDwgMCA/IDEgOiAwOwogICAgICAgIHZhbHVlID0gTWF0aC5hYnModmFsdWUpOwogICAgICAgIGlmIChpc05hTih2YWx1ZSkgfHwgdmFsdWUgPT09IEluZmluaXR5KSB7CiAgICAgICAgICBtID0gaXNOYU4odmFsdWUpID8gMSA6IDA7CiAgICAgICAgICBlID0gZU1heDsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgZSA9IE1hdGguZmxvb3IoTWF0aC5sb2codmFsdWUpIC8gTWF0aC5MTjIpOwogICAgICAgICAgaWYgKHZhbHVlICogKGMgPSBNYXRoLnBvdygyLCAtZSkpIDwgMSkgewogICAgICAgICAgICBlLS07CiAgICAgICAgICAgIGMgKj0gMjsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChlICsgZUJpYXMgPj0gMSkgewogICAgICAgICAgICB2YWx1ZSArPSBydCAvIGM7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICB2YWx1ZSArPSBydCAqIE1hdGgucG93KDIsIDEgLSBlQmlhcyk7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAodmFsdWUgKiBjID49IDIpIHsKICAgICAgICAgICAgZSsrOwogICAgICAgICAgICBjIC89IDI7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoZSArIGVCaWFzID49IGVNYXgpIHsKICAgICAgICAgICAgbSA9IDA7CiAgICAgICAgICAgIGUgPSBlTWF4OwogICAgICAgICAgfSBlbHNlIGlmIChlICsgZUJpYXMgPj0gMSkgewogICAgICAgICAgICBtID0gKHZhbHVlICogYyAtIDEpICogTWF0aC5wb3coMiwgbUxlbik7CiAgICAgICAgICAgIGUgPSBlICsgZUJpYXM7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBtID0gdmFsdWUgKiBNYXRoLnBvdygyLCBlQmlhcyAtIDEpICogTWF0aC5wb3coMiwgbUxlbik7CiAgICAgICAgICAgIGUgPSAwOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBmb3IgKDsgbUxlbiA+PSA4OyBidWZmZXJbb2Zmc2V0ICsgaV0gPSBtICYgMjU1LCBpICs9IGQsIG0gLz0gMjU2LCBtTGVu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bnVtZXJhYmxlOiB0cnVlLAogICAgICAgIGdldDogZnVuY3Rpb24oKSB7CiAgICAgICAgICBpZiAoIUJ1ZmZlcjguaXNCdWZmZXIodGhpcykpCiAgICAgICAgICAgIHJldHVybiB2b2lkIDA7CiAgICAgICAgICByZXR1cm4gdGhpcy5idWZmZXI7CiAgICAgICAgfQogICAgICB9KTsKICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KEJ1ZmZlcjgucHJvdG90eXBlLCAib2Zmc2V0IiwgewogICAgICAgIGVudW1lcmFibGU6IHRydWUsCiAgICAgICAgZ2V0OiBmdW5jdGlvbigpIHsKICAgICAgICAgIGlmICghQnVmZmVyOC5pc0J1ZmZlcih0aGlzKSkKICAgICAgICAgICAgcmV0dXJuIHZvaWQgMDsKICAgICAgICAgIHJldHVybiB0aGlzLmJ5dGVPZmZzZXQ7CiAgICAgICAgfQogICAgICB9KTsKICAgICAgZnVuY3Rpb24gY3JlYXRlQnVmZmVyKGxlbmd0aCkgewogICAgICAgIGlmIChsZW5ndGggPiBLX01BWF9MRU5HVEgpIHsKICAgICAgICAgIHRocm93IG5ldyBSYW5nZUVycm9yKCdUaGUgdmFsdWUgIicgKyBsZW5ndGggKyAnIiBpcyBpbnZhbGlkIGZvciBvcHRpb24gInNpemUiJyk7CiAgICAgICAgfQogICAgICAgIGNvbnN0IGJ1ZiA9IG5ldyBVaW50OEFycmF5KGxlbmd0aCk7CiAgICAgICAgT2JqZWN0LnNldFByb3RvdHlwZU9mKGJ1ZiwgQnVmZmVyOC5wcm90b3R5cGUpOwogICAgICAgIHJldHVybiBidWY7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gQnVmZmVyOChhcmcsIGVuY29kaW5nT3JPZmZzZXQsIGxlbmd0aCkgewogICAgICAgIGlmICh0eXBlb2YgYXJnID09PSAibnVtYmVyIikgewogICAgICAgICAgaWYgKHR5cGVvZiBlbmNvZGluZ09yT2Zmc2V0ID09PSAic3RyaW5nIikgewogICAgICAgICAgICB0a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IGJ1ZjsKICAgICAgfQogICAgICBmdW5jdGlvbiBmcm9tT2JqZWN0KG9iaikgewogICAgICAgIGlmIChCdWZmZXI4LmlzQnVmZmVyKG9iaikpIHsKICAgICAgICAgIGNvbnN0IGxlbiA9IGNoZWNrZWQob2JqLmxlbmd0aCkgfCAwOwogICAgICAgICAgY29uc3QgYnVmID0gY3JlYXRlQnVmZmVyKGxlbik7CiAgICAgICAgICBpZiAoYnVmLmxlbmd0aCA9PT0gMCkgewogICAgICAgICAgICByZXR1cm4gYnVmOwogICAgICAgICAgfQogICAgICAgICAgb2JqLmNvcHkoYnVmLCAwLCAwLCBsZW4pOwogICAgICAgICAgcmV0dXJuIGJ1ZjsKICAgICAgICB9CiAgICAgICAgaWYgKG9iai5sZW5ndGggIT09IHZvaWQgMCkgewogICAgICAgICAgaWYgKHR5cGVvZiBvYmoubGVuZ3RoICE9PSAibnVtYmVyIiB8fCBudW1iZXJJc05hTihvYmoubGVuZ3RoKSkgewogICAgICAgICAgICByZXR1cm4gY3JlYXRlQnVmZmVyKDApOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIGZyb21BcnJheUxpa2Uob2JqKTsKICAgICAgICB9CiAgICAgICAgaWYgKG9iai50eXBlID09PSAiQnVmZmVyIiAmJiBBcnJheS5pc0FycmF5KG9iai5kYXRhKSkgewogICAgICAgICAgcmV0dXJuIGZyb21BcnJheUxpa2Uob2JqLmRhdGEpOwogICAgICAgIH0KICAgICAgfQogICAgICBmdW5jdGlvbiBjaGVja2VkKGxlbmd0aCkgewogICAgICAgIGlmIChsZW5ndGggPj0gS19NQVhfTEVOR1RIKSB7CiAgICAgICAgICB0aHJvdyBuZXcgUmFuZ2VFcnJvcigiQXR0ZW1wdCB0byBhbGxvY2F0ZSBCdWZmZXIgbGFyZ2VyIHRoYW4gbWF4aW11bSBzaXplOiAweCIgKyBLX01BWF9MRU5HVEgudG9TdHJpbmcoMTYpICsgIiBieXRlcyIpOwogICAgICAgIH0KICAgICAgICByZXR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gPSBNYXRoLm1pbih4LCB5KTsgaSA8IGxlbjsgKytpKSB7CiAgICAgICAgICBpZiAoYVtpXSAhPT0gYltpXSkgewogICAgICAgICAgICB4ID0gYVtpXTsKICAgICAgICAgICAgeSA9IGJbaV07CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAoeCA8IHkpCiAgICAgICAgICByZXR1cm4gLTE7CiAgICAgICAgaWYgKHkgPCB4KQogICAgICAgICAgcmV0dXJuIDE7CiAgICAgICAgcmV0dXJuIDA7CiAgICAgIH07CiAgICAgIEJ1ZmZlcjguaXNFbmNvZGluZyA9IGZ1bmN0aW9uIGlzRW5jb2RpbmcoZW5jb2RpbmcpIHsKICAgICAgICBzd2l0Y2ggKFN0cmluZyhlbmNvZGluZykudG9Mb3dlckNhc2UoKSkgewogICAgICAgICAgY2FzZSAiaGV4IjoKICAgICAgICAgIGNhc2UgInV0ZjgiOgogICAgICAgICAgY2FzZSAidXRmLTgiOgogICAgICAgICAgY2FzZSAiYXNjaWkiOgogICAgICAgICAgY2FzZSAibGF0aW4xIjoKICAgICAgICAgIGNhc2UgImJpbmFyeSI6CiAgICAgICAgICBjYXNlICJiYXNlNjQiOgogICAgICAgICAgY2FzZSAidWNzMiI6CiAgICAgICAgICBjYXNlICJ1Y3MtMiI6CiAgICAgICAgICBjYXNlICJ1dGYxNmxlIjoKICAgICAgICAgIGNhc2UgInV0Zi0xNmxlIjoKICAgICAgICAgICAgcmV0dXJuIHRydWU7CiAgICAgICAgICBkZWZhdWx0OgogICAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgfQogICAgICB9OwogICAgICBCdWZmZXI4LmNvbmNhdCA9IGZ1bmN0aW9uIGNvbmNhdChsaXN0LCBsZW5ndGgpIHsKICAgICAgICBpZiAoIUFycmF5LmlzQXJyYXkobGlzdCkpIHsKICAgICAgICAgIHRocm93IG5ldyBUeXBlRXJyb3IoJyJsaXN0IiBhcmd1bWVudCBtdXN0IGJlIGFuIEFycmF5IG9mIEJ1ZmZlcnMnKTsKICAgICAgICB9CiAgICAgICAgaWYgKGxpc3QubGVuZ3RoID09PSAwKSB7CiAgICAgICAgICByZXR1cm4gQnVmZmVyOC5hbGxvYygwKTsKICAgICAgICB9CiAgICAgICAgbGV0IGk7CiAgICAgICAgaWYgKGxlbmd0aCA9PT0gdm9pZCAwKSB7CiAgICAgICAgICBsZW5ndGggPSAwOwogICAgICAgICAgZm9yIChpID0gMDsgaSA8IGxpc3QubGVuZ3RoOyArK2kpIHsKICAgICAgICAgICAgbGVuZ3RoICs9IGxpc3RbaV0ubGVuZ3RoOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBjb25zdCBidWZmZXIgPSBCdWZmZXI4LmFsbG9jVW5zYWZlKGxlbmd0aCk7CiAgICAgICAgbGV0IHBvcyA9IDA7CiAgICAgICAgZm9yIChpID0gMDsgaSA8IGxpc3QubGVuZ3RoOyArK2kpIHsKICAgICAgICAgIGxldCBidWYgPSBsaXN0W2ldOwogICAgICAgICAgaWYgKGlzSW5zdGFuY2UoYnVmLCBVaW50OEFycmF5KSkgewogICAgICAgICAgICBpZiAocG9zICsgYnVmLmxlbmd0aCA+IGJ1ZmZlci5sZW5ndGgpIHsKICAgICAgICAgICAgICBpZiAoIUJ1ZmZlcjguaXNCdWZmZXIoYnVmKSkKICAgICAgICAgICAgICAgIGJ1ZiA9IEJ1ZmZlcjguZnJvbShidWYpOwogICAgICAgICAgICAgIGJ1Zi5jb3B5KGJ1ZmZlciwgcG9zKTsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICBVaW50OEFycmF5LnByb3RvdHlwZS5zZXQuY2FsbChidWZmZXIsIGJ1ZiwgcG9zKTsKICAgICAgICAgICAgfQogICAgICAgICAgfSBlbHNlIGlmICghQnVmZmVyOC5pc0J1ZmZlcihidWYpKSB7CiAgICAgICAgICAgIHRocm93IG5ldyBUeXBlRXJyb3IoJyJsaXN0IiBhcmd1bWVud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ICAgICAgIHN3aXRjaCAoZW5jb2RpbmcpIHsKICAgICAgICAgICAgY2FzZSAiYXNjaWkiOgogICAgICAgICAgICBjYXNlICJsYXRpbjEiOgogICAgICAgICAgICBjYXNlICJiaW5hcnkiOgogICAgICAgICAgICAgIHJldHVybiBsZW47CiAgICAgICAgICAgIGNhc2UgInV0ZjgiOgogICAgICAgICAgICBjYXNlICJ1dGYtOCI6CiAgICAgICAgICAgICAgcmV0dXJuIHV0ZjhUb0J5dGVzKHN0cmluZykubGVuZ3RoOwogICAgICAgICAgICBjYXNlICJ1Y3MyIjoKICAgICAgICAgICAgY2FzZSAidWNzLTIiOgogICAgICAgICAgICBjYXNlICJ1dGYxNmxlIjoKICAgICAgICAgICAgY2FzZSAidXRmLTE2bGUiOgogICAgICAgICAgICAgIHJldHVybiBsZW4gKiAyOwogICAgICAgICAgICBjYXNlICJoZXgiOgogICAgICAgICAgICAgIHJldHVybiBsZW4gPj4+IDE7CiAgICAgICAgICAgIGNhc2UgImJhc2U2NCI6CiAgICAgICAgICAgICAgcmV0dXJuIGJhc2U2NFRvQnl0ZXMoc3RyaW5nKS5sZW5ndGg7CiAgICAgICAgICAgIGRlZmF1bHQ6CiAgICAgICAgICAgICAgaWYgKGxvd2VyZWRDYXNlKSB7CiAgICAgICAgICAgICAgICByZXR1cm4gbXVzdE1hdGNoID8gLTEgOiB1dGY4VG9CeXRlcyhzdHJpbmcpLmxlbmd0aDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgZW5jb2RpbmcgPSAoIiIgKyBlbmNvZGluZykudG9Mb3dlckNhc2UoKTsKICAgICAgICAgICAgICBsb3dlcmVkQ2FzZSA9IHRydWU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9CiAgICAgIEJ1ZmZlcjguYnl0ZUxlbmd0aCA9IGJ5dGVMZW5ndGg7CiAgICAgIGZ1bmN0aW9uIHNsb3dUb1N0cmluZyhlbmNvZGluZywgc3RhcnQsIGVuZCkgewogICAgICAgIGxldCBsb3dlcmVkQ2FzZSA9IGZhbHNlOwogICAgICAgIGlmIChzdGFydCA9PT0gdm9pZCAwIHx8IHN0YXJ0IDwgMCkgewogICAgICAgICAgc3RhcnQgPSAwOwogICAgICAgIH0KICAgICAgICBpZiAoc3RhcnQgPiB0aGlzLmxlbmd0aCkgewogICAgICAgICAgcmV0dXJuICIiOwogICAgICAgIH0KICAgICAgICBpZiAoZW5kID09PSB2b2lkIDAgfHwgZW5kID4gdGhpcy5sZW5ndGgpIHsKICAgICAgICAgIGVuZCA9IHRoaXMubGVuZ3RoOwogICAgICAgIH0KICAgICAgICBpZiAoZW5kIDw9IDApIHsKICAgICAgICAgIHJldHVybiAiIjsKICAgICAgICB9CiAgICAgICAgZW5kID4+Pj0gMDsKICAgICAgICBzdGFydCA+Pj49IDA7CiAgICAgICAgaWYgKGVuZCA8PSBzdGFydCkgewogICAgICAgICAgcmV0dXJuICIiOwogICAgICAgIH0KICAgICAgICBpZiAoIWVuY29kaW5nKQogICAgICAgICAgZW5jb2RpbmcgPSAidXRmOCI7CiAgICAgICAgd2hpbGUgKHRydWUpIHsKICAgICAgICAgIHN3aXRjaCAoZW5jb2RpbmcpIHsKICAgICAgICAgICAgY2FzZSAiaGV4IjoKICAgICAgICAgICAgICByZXR1cm4gaGV4U2xpY2UodGhpcywgc3RhcnQsIGVuZCk7CiAgICAgICAgICAgIGNhc2UgInV0ZjgiOgogICAgICAgICAgICBjYXNlICJ1dGYtOCI6CiAgICAgICAgICAgICAgcmV0dXJuIHV0ZjhTbGljZSh0aGlzLCBzdGFydCwgZW5kKTsKICAgICAgICAgICAgY2FzZSAiYXNjaWkiOgogICAgICAgICAgICAgIHJldHVybiBhc2NpaVNsaWNlKHRoaXMsIHN0YXJ0LCBlbmQpOwogICAgICAgICAgICBjYXNlICJsYXRpbjEiOgogICAgICAgICAgICBjYXNlICJiaW5hcnkiOgogICAgICAgICAgICAgIHJldHVybiBsYXRpbjFTbGljZSh0aGlzLCBzdGFydCwgZW5kKTsKICAgICAgICAgICAgY2FzZSAiYmFzZTY0IjoKICAgICAgICAgICAgICByZXR1cm4gYmFzZTY0U2xpY2UodGhpcywgc3RhcnQsIGVuZCk7CiAgICAgICAgICAgIGNhc2UgInVjczIiOgogICAgICAgICAgICBjYXNlICJ1Y3MtMiI6CiAgICAgICAgICAgIGNhc2UgInV0ZjE2bGUiOgogICAgICAgICAgICBjYXNlICJ1dGYtMTZsZSI6CiAgICAgICAgICAgICAgcmV0dXJuIHV0ZjE2bGVTbGljZSh0aGlzLCBzdGFydCwgZW5kKTsKICAgICAgICAgICAgZGVmYXVsdDoKICAgICAgICAgICAgICBpZiAobG93ZXJlZENhc2UpCiAgICAgICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCJVbmtub3duIGVuY29kaW5nOiAiICsgZW5jb2RpbmcpOwogICAgICAgICAgICAgIGVuY29kaW5nID0gKGVuY29kaW5nICsgIiIpLnRvTG93ZXJDYXNlKCk7CiAgICAgICAgICAgICAgbG93ZXJlZENhc2UgPSB0cnVlOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgICBCdWZmZXI4LnByb3RvdHlwZS5faXNCdWZmZXIgPSB0cnVlOwogICAgICBmdW5jdGlvbiBzd2FwKGIsIG4sIG0pIHsKICAgICAgICBjb25zdCBpID0gYltuXTsKICAgICAgICBiW25dID0gYlttXTsKICAgICAgICBiW21dID0gaTsKICAgICAgfQogICAgICBCdWZmZXI4LnByb3RvdHlwZS5zd2FwMTYgPSBmdW5jdGlvbiBzd2FwMTYoKSB7CiAgICAgICAgY29uc3QgbGVuID0gdGhpcy5sZW5ndGg7CiAgICAgICAgaWYgKGxlbiAlIDIgIT09IDApIHsKICAgICAgICAgIHRocm93IG5ldyBSYW5nZUVycm9yKCJCdWZmZXIgc2l6ZSBtdXN0IGJlIGEgbXVsdGlwbGUgb2YgMTYtYml0cyIpOwogICAgICAgIH0KICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IGxlbjsgaSArPSAyKSB7CiAgICAgICAgICBzd2FwKHRoaXMsIGksIGkgKyAxKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHRoaXM7CiAgICAgIH07CiAgICAgIEJ1ZmZlcjgucHJvdG90eXBlLnN3YXAzMiA9IGZ1bmN0aW9uIHN3YXAzMigpIHsKICAgICAgICBjb25zdCBsZW4gPSB0aGlzLmxlbmd0aDsKICAgICAgICBpZiAobGVuICUgNCAhPT0gMCkgewogICAgICAgICAgdGhyb3cgbmV3IFJhbmdlRXJyb3IoIkJ1ZmZlciBzaXplIG11c3QgYmUgYSBtdWx0aXBsZSBvZiAzMi1iaXRzIik7CiAgICAgICAgfQogICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgbGVuOyBpICs9IDQpIHsKICAgICAgICAgIHN3YXAodGhpcywgaSwgaSArIDMpOwogICAgICAgICAgc3dhcCh0aGlzLCBpICsgMSwgaSArIDIpOwogICAgICAgIH0KICAgICAgICByZXR1cm4gdGhpczsKICAgICAgfTsKICAgICAgQnVmZmVyOC5wcm90b3R5cGUuc3dhcDY0ID0gZnVuY3Rpb24gc3dhcDY0KCkgewogICAgICAgIGNvbnN0IGxlbiA9IHRoaXMubGVuZ3RoOwogICAgICAgIGlmIChsZW4gJSA4ICE9PSAwKSB7CiAgICAgICAgICB0aHJvdyBuZXcgUmFuZ2VFcnJvcigiQnVmZmVyIHNpemUgbXVzdCBiZSBhIG11bHRpcGxlIG9mIDY0LWJpdHMiKTsKICAgICAgICB9CiAgICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCBsZW47IGkgKz0gOCkgewogICAgICAgICAgc3dhcCh0aGlzLCBpLCBpICsgNyk7CiAgICAgICAgICBzd2FwKHRoaXMsIGkgKyAxLCBpICsgNik7CiAgICAgICAgICBzd2FwKHRoaXMsIGkgKyAyLCBpICsgNSk7CiAgICAgICAgICBzd2FwKHRoaXMsIGkgKyAzLCBpICsgNCk7CiAgICAgICAgfQogICAgICAgIHJldHVybiB0aGlzOwogICAgICB9OwogICAgICBCdWZmZXI4LnByb3RvdHlwZS50b1N0cmluZyA9IGZ1bmN0aW9uIHRvU3RyaW5nKCkgewogICAgICAgIGNvbnN0IGxlbmd0aCA9IHRoaXMubGVuZ3RoOwogICAgICAgIGlmIChsZW5ndGggPT09IDApCiAgICAgICAgICByZXR1cm4gIiI7CiAgICAgICAgaWYgKGFyZ3VtZW50cy5sZW5ndGggPT09IDApCiAgICAgICAgICByZXR1cm4gdXRmOFNsaWNlKHRoaXMsIDAsIGxlbmd0aCk7CiAgICAgICAgcmV0dXJuIHNsb3dUb1N0cmluZy5hcHBseSh0aGlzLCBhcmd1bWVudHMpOwogICAgICB9OwogICAgICBCdWZmZXI4LnByb3RvdHlwZS50b0xvY2FsZVN0cmluZyA9IEJ1ZmZlcjgucHJvdG90eXBlLnRvU3RyaW5nOwogICAgICBCdWZmZXI4LnByb3RvdHlwZS5lcXVhbHMgPSBmdW5jdGlvbiBlcXVhbHMoYikgewogICAgICAgIGlmICghQnVmZmVyOC5pc0J1ZmZlcihiKSkKICAgICAgICAgIHRocm93IG5ldyBUeXBlRXJyb3IoIkFyZ3VtZW50IG11c3QgYmUgYSBCdWZmZXIiKTsKICAgICAgICBpZiAodGhpcyA9PT0gYikKICAgICAgICAgIHJldHVybiB0cnVlOwogICAgICAgIHJldHVybiBCdWZmZXI4LmNvbXBhcmUodGhpcywgYikgPT09IDA7CiAgICAgIH07CiAgICAgIEJ1ZmZlcjgucHJvdG90eXBlLmluc3BlY3QgPSBmdW5jdGlvbiBpbnNwZWN0KCkgewogICAgICAgIGxldCBzdHIgPSAiIjsKICAgICAgICBjb25zdCBtYXggPSBleHBvcnRzLklOU1BFQ1RfTUFYX0JZVEVTOwogICAgICAgIHN0ciA9IHRoaXMudG9TdHJpbmcoImhleCIsIDAsIG1heCkucmVwbGFjZSgvKC57Mn0pL2csICIkMSAiKS50cmltKCk7CiAgICAgICAgaWYgKHRoaXMubGVuZ3RoID4gbWF4KQogICAgICAgICAgc3Ry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7CiAgICAgICAgICAgIHggPSB0aGlzQ29weVtpXTsKICAgICAgICAgICAgeSA9IHRhcmdldENvcHlbaV07CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAoeCA8IHkpCiAgICAgICAgICByZXR1cm4gLTE7CiAgICAgICAgaWYgKHkgPCB4KQogICAgICAgICAgcmV0dXJuIDE7CiAgICAgICAgcmV0dXJuIDA7CiAgICAgIH07CiAgICAgIGZ1bmN0aW9uIGJpZGlyZWN0aW9uYWxJbmRleE9mKGJ1ZmZlciwgdmFsLCBieXRlT2Zmc2V0LCBlbmNvZGluZywgZGlyKSB7CiAgICAgICAgaWYgKGJ1ZmZlci5sZW5ndGggPT09IDApCiAgICAgICAgICByZXR1cm4gLTE7CiAgICAgICAgaWYgKHR5cGVvZiBieXRlT2Zmc2V0ID09PSAic3RyaW5nIikgewogICAgICAgICAgZW5jb2RpbmcgPSBieXRlT2Zmc2V0OwogICAgICAgICAgYnl0ZU9mZnNldCA9IDA7CiAgICAgICAgfSBlbHNlIGlmIChieXRlT2Zmc2V0ID4gMjE0NzQ4MzY0NykgewogICAgICAgICAgYnl0ZU9mZnNldCA9IDIxNDc0ODM2NDc7CiAgICAgICAgfSBlbHNlIGlmIChieXRlT2Zmc2V0IDwgLTIxNDc0ODM2NDgpIHsKICAgICAgICAgIGJ5dGVPZmZzZXQgPSAtMjE0NzQ4MzY0ODsKICAgICAgICB9CiAgICAgICAgYnl0ZU9mZnNldCA9ICtieXRlT2Zmc2V0OwogICAgICAgIGlmIChudW1iZXJJc05hTihieXRlT2Zmc2V0KSkgewogICAgICAgICAgYnl0ZU9mZnNldCA9IGRpciA/IDAgOiBidWZmZXIubGVuZ3RoIC0gMTsKICAgICAgICB9CiAgICAgICAgaWYgKGJ5dGVPZmZzZXQgPCAwKQogICAgICAgICAgYnl0ZU9mZnNldCA9IGJ1ZmZlci5sZW5ndGggKyBieXRlT2Zmc2V0OwogICAgICAgIGlmIChieXRlT2Zmc2V0ID49IGJ1ZmZlci5sZW5ndGgpIHsKICAgICAgICAgIGlmIChkaXIpCiAgICAgICAgICAgIHJldHVybiAtMTsKICAgICAgICAgIGVsc2UKICAgICAgICAgICAgYnl0ZU9mZnNldCA9IGJ1ZmZlci5sZW5ndGggLSAxOwogICAgICAgIH0gZWxzZSBpZiAoYnl0ZU9mZnNldCA8IDApIHsKICAgICAgICAgIGlmIChkaXIpCiAgICAgICAgICAgIGJ5dGVPZmZzZXQgPSAwOwogICAgICAgICAgZWxzZQogICAgICAgICAgICByZXR1cm4gLTE7CiAgICAgICAgfQogICAgICAgIGlmICh0eXBlb2YgdmFsID09PSAic3RyaW5nIikgewogICAgICAgICAgdmFsID0gQnVmZmVyOC5mcm9tKHZhbCwgZW5jb2RpbmcpOwogICAgICAgIH0KICAgICAgICBpZiAoQnVmZmVyOC5pc0J1ZmZlcih2YWwpKSB7CiAgICAgICAgICBpZiAodmFsLmxlbmd0aCA9PT0gMCkgewogICAgICAgICAgICByZXR1cm4gLTE7CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gYXJyYXlJbmRleE9mKGJ1ZmZlciwgdmFsLCBieXRlT2Zmc2V0LCBlbmNvZGluZywgZGlyKTsKICAgICAgICB9IGVsc2UgaWYgKHR5cGVvZiB2YWwgPT09ICJudW1iZXIiKSB7CiAgICAgICAgICB2YWwgPSB2YWwgJiAyNTU7CiAgICAgICAgICBpZiAodHlwZW9mIFVpbnQ4QXJyYXkucHJvdG90eXBlLmluZGV4T2YgPT09ICJmdW5jdGlvbiIpIHsKICAgICAgICAgICAgaWYgKGRpcikgewogICAgICAgICAgICAgIHJldHVybiBVaW50OEFycmF5LnByb3RvdHlwZS5pbmRleE9mLmNhbGwoYnVmZmVyLCB2YWwsIGJ5dGVPZmZzZXQpOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHJldHVybiBVaW50OEFycmF5LnByb3RvdHlwZS5sYXN0SW5kZXhPZi5jYWxsKGJ1ZmZlciwgdmFsLCBieXRlT2Zmc2V0KTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIGFycmF5SW5kZXhPZihidWZmZXIsIFt2YWxdLCBieXRlT2Zmc2V0LCBlbmNvZGluZywgZGlyKTsKICAgICAgICB9CiAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcigidmFsIG11c3QgYmUgc3RyaW5nLCBudW1iZXIgb3IgQnVmZmVyIik7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gYXJyYXlJbmRleE9mKGFyciwgdmFsLCBieXRlT2Zmc2V0LCBlbmNvZGluZywgZGlyKSB7CiAgICAgICAgbGV0IGluZGV4U2l6ZSA9IDE7CiAgICAgICAgbGV0IGFyckxlbmd0aCA9IGFyci5sZW5ndGg7CiAgICAgICAgbGV0IHZhbExlbmd0aCA9IHZhbC5sZW5ndGg7CiAgICAgICAgaWYgKGVuY29kaW5nICE9PSB2b2lkIDApIHsKICAgICAgICAgIGVuY29kaW5nID0gU3RyaW5nKGVuY29kaW5nKS50b0xvd2VyQ2FzZSgpOwogICAgICAgICAgaWYgKGVuY29kaW5nID09PSAidWNzMiIgfHwgZW5jb2RpbmcgPT09ICJ1Y3MtMiIgfHwgZW5jb2RpbmcgPT09ICJ1dGYxNmxlIiB8fCBlbmNvZGluZyA9PT0gInV0Zi0xNmxlIikgewogICAgICAgICAgICBpZiAoYXJyLmxlbmd0aCA8IDIgfHwgdmFsLmxlbmd0aCA8IDIpIHsKICAgICAgICAgICAgICByZXR1cm4gLTE7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaW5kZXhTaXplID0gMjsKICAgICAgICAgICAgYXJyTGVuZ3RoIC89IDI7CiAgICAgICAgICAgIHZhbExlbmd0aCAvPSAyOwogICAgICAgICAgICBieXRlT2Zmc2V0IC89IDI7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIHJlYWQoYnVmLCBpMikgewogICAgICAgICAgaWYgKGluZGV4U2l6ZSA9PT0gMSkgewogICAgICAgICAgICByZXR1cm4gYnVmW2kyXTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHJldHVybiBidWYucmVhZFVJbnQxNkJFKGkyICogaW5kZXhTaXplKTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgbGV0IGk7CiAgICAgICAgaWYgKGRpcikgewogICAgICAgICAgbGV0IGZvdW5kSW5kZXggPSAtMTsKICAgICAgICAgIGZvciAoaSA9IGJ5dGVPZmZzZXQ7IGkgPCBhcnJMZW5ndGg7IGkrKykgewogICAgICAgICAgICBpZiAocmVhZChhcnIsIGkpID09PSByZWFkKHZhbCwgZm91bmRJbmRleCA9PT0gLTEgPyAwIDogaSAtIGZvdW5kSW5kZXgpKSB7CiAgICAgICAgICAgICAgaWYgKGZvdW5kSW5kZXggPT09IC0xKQogICAgICAgICAgICAgICAgZm91bmRJbmRleCA9IGk7CiAgICAgICAgICAgICAgaWYgKGkgLSBmb3VuZEluZGV4ICsgMSA9PT0gdmFsTGVuZ3RoKQogICAgICAgICAgICAgICAgcmV0dXJuIGZvdW5kSW5kZXggKiBpbmRleFNpemU7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgaWYgKGZvdW5kSW5kZXggIT09IC0xKQogICAgICAgICAgICAgICAgaSAtPSBpIC0gZm91bmRJbmRleDsKICAgICAgICAgICAgICBmb3VuZEluZGV4ID0gLTE7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9IGVsc2UgewogICAgICAgICAgaWYgKGJ5dGVPZmZzZXQgKyB2YWxMZW5ndGggPiBhcnJMZW5ndGgpCiAgICAgICAgICAgIGJ5dGVPZmZzZXQgPSBhcnJMZW5ndGggLSB2YWxMZW5ndGg7CiAgICAgICAgICBmb3IgKGkgPSBieXRlT2Zmc2V0OyBpID49IDA7IGktLSkgewogICAgICAgICAgICBsZXQgZm91bmQgPSB0cnVlOwogICAgICAgICAgICBmb3IgKGx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mZnNldCkgfHwgMDsKICAgICAgICBjb25zdCByZW1haW5pbmcgPSBidWYubGVuZ3RoIC0gb2Zmc2V0OwogICAgICAgIGlmICghbGVuZ3RoKSB7CiAgICAgICAgICBsZW5ndGggPSByZW1haW5pbmc7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIGxlbmd0aCA9IE51bWJlcihsZW5ndGgpOwogICAgICAgICAgaWYgKGxlbmd0aCA+IHJlbWFpbmluZykgewogICAgICAgICAgICBsZW5ndGggPSByZW1haW5pbmc7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGNvbnN0IHN0ckxlbiA9IHN0cmluZy5sZW5ndGg7CiAgICAgICAgaWYgKGxlbmd0aCA+IHN0ckxlbiAvIDIpIHsKICAgICAgICAgIGxlbmd0aCA9IHN0ckxlbiAvIDI7CiAgICAgICAgfQogICAgICAgIGxldCBpOwogICAgICAgIGZvciAoaSA9IDA7IGkgPCBsZW5ndGg7ICsraSkgewogICAgICAgICAgY29uc3QgcGFyc2VkID0gcGFyc2VJbnQoc3RyaW5nLnN1YnN0cihpICogMiwgMiksIDE2KTsKICAgICAgICAgIGlmIChudW1iZXJJc05hTihwYXJzZWQpKQogICAgICAgICAgICByZXR1cm4gaTsKICAgICAgICAgIGJ1ZltvZmZzZXQgKyBpXSA9IHBhcnNlZDsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIGk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gdXRmOFdyaXRlKGJ1Ziwgc3RyaW5nLCBvZmZzZXQsIGxlbmd0aCkgewogICAgICAgIHJldHVybiBibGl0QnVmZmVyKHV0ZjhUb0J5dGVzKHN0cmluZywgYnVmLmxlbmd0aCAtIG9mZnNldCksIGJ1Ziwgb2Zmc2V0LCBsZW5ndGgpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGFzY2lpV3JpdGUoYnVmLCBzdHJpbmcsIG9mZnNldCwgbGVuZ3RoKSB7CiAgICAgICAgcmV0dXJuIGJsaXRCdWZ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gICBjYXNlICJ1dGY4IjoKICAgICAgICAgICAgY2FzZSAidXRmLTgiOgogICAgICAgICAgICAgIHJldHVybiB1dGY4V3JpdGUodGhpcywgc3RyaW5nLCBvZmZzZXQsIGxlbmd0aCk7CiAgICAgICAgICAgIGNhc2UgImFzY2lpIjoKICAgICAgICAgICAgY2FzZSAibGF0aW4xIjoKICAgICAgICAgICAgY2FzZSAiYmluYXJ5IjoKICAgICAgICAgICAgICByZXR1cm4gYXNjaWlXcml0ZSh0aGlzLCBzdHJpbmcsIG9mZnNldCwgbGVuZ3RoKTsKICAgICAgICAgICAgY2FzZSAiYmFzZTY0IjoKICAgICAgICAgICAgICByZXR1cm4gYmFzZTY0V3JpdGUodGhpcywgc3RyaW5nLCBvZmZzZXQsIGxlbmd0aCk7CiAgICAgICAgICAgIGNhc2UgInVjczIiOgogICAgICAgICAgICBjYXNlICJ1Y3MtMiI6CiAgICAgICAgICAgIGNhc2UgInV0ZjE2bGUiOgogICAgICAgICAgICBjYXNlICJ1dGYtMTZsZSI6CiAgICAgICAgICAgICAgcmV0dXJuIHVjczJXcml0ZSh0aGlzLCBzdHJpbmcsIG9mZnNldCwgbGVuZ3RoKTsKICAgICAgICAgICAgZGVmYXVsdDoKICAgICAgICAgICAgICBpZiAobG93ZXJlZENhc2UpCiAgICAgICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCJVbmtub3duIGVuY29kaW5nOiAiICsgZW5jb2RpbmcpOwogICAgICAgICAgICAgIGVuY29kaW5nID0gKCIiICsgZW5jb2RpbmcpLnRvTG93ZXJDYXNlKCk7CiAgICAgICAgICAgICAgbG93ZXJlZENhc2UgPSB0cnVlOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfTsKICAgICAgQnVmZmVyOC5wcm90b3R5cGUudG9KU09OID0gZnVuY3Rpb24gdG9KU09OKCkgewogICAgICAgIHJldHVybiB7CiAgICAgICAgICB0eXBlOiAiQnVmZmVyIiwKICAgICAgICAgIGRhdGE6IEFycm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zdEJ5dGUgPCAxMjgpIHsKICAgICAgICAgICAgICAgICAgY29kZVBvaW50ID0gZmlyc3RCeXRlOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgY2FzZSAyOgogICAgICAgICAgICAgICAgc2Vjb25kQnl0ZSA9IGJ1ZltpICsgMV07CiAgICAgICAgICAgICAgICBpZiAoKHNlY29uZEJ5dGUgJiAxOTIpID09PSAxMjgpIHsKICAgICAgICAgICAgICAgICAgdGVtcENvZGVQb2ludCA9IChmaXJzdEJ5dGUgJiAzMSkgPDwgNiB8IHNlY29uZEJ5dGUgJiA2MzsKICAgICAgICAgICAgICAgICAgaWYgKHRlbXBDb2RlUG9pbnQgPiAxMjcpIHsKICAgICAgICAgICAgICAgICAgICBjb2RlUG9pbnQgPSB0ZW1wQ29kZVBvaW50OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICBjYXNlIDM6CiAgICAgICAgICAgICAgICBzZWNvbmRCeXRlID0gYnVmW2kgKyAxXTsKICAgICAgICAgICAgICAgIHRoaXJkQnl0ZSA9IGJ1ZltpICsgMl07CiAgICAgICAgICAgICAgICBpZiAoKHNlY29uZEJ5dGUgJiAxOTIpID09PSAxMjggJiYgKHRoaXJkQnl0ZSAmIDE5MikgPT09IDEyOCkgewogICAgICAgICAgICAgICAgICB0ZW1wQ29kZVBvaW50ID0gKGZpcnN0Qnl0ZSAmIDE1KSA8PCAxMiB8IChzZWNvbmRCeXRlICYgNjMpIDw8IDYgfCB0aGlyZEJ5dGUgJiA2MzsKICAgICAgICAgICAgICAgICAgaWYgKHRlbXBDb2RlUG9pbnQgPiAyMDQ3ICYmICh0ZW1wQ29kZVBvaW50IDwgNTUyOTYgfHwgdGVtcENvZGVQb2ludCA+IDU3MzQzKSkgewogICAgICAgICAgICAgICAgICAgIGNvZGVQb2ludCA9IHRlbXBDb2RlUG9pbnQ7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgIGNhc2UgNDoKICAgICAgICAgICAgICAgIHNlY29uZEJ5dGUgPSBidWZbaSArIDFdOwogICAgICAgICAgICAgICAgdGhpcmRCeXRlID0gYnVmW2kgKyAyXTsKICAgICAgICAgICAgICAgIGZvdXJ0aEJ5dGUgPSBidWZbaSArIDNdOwogICAgICAgICAgICAgICAgaWYgKChzZWNvbmRCeXRlICYgMTkyKSA9PT0gMTI4ICYmICh0aGlyZEJ5dGUgJiAxOTIpID09PSAxMjggJiYgKGZvdXJ0aEJ5dGUgJiAxOTIpID09PSAxMjgpIHsKICAgICAgICAgICAgICAgICAgdGVtcENvZGVQb2ludCA9IChmaXJzdEJ5dGUgJiAxNSkgPDwgMTggfCAoc2Vjb25kQnl0ZSAmIDYzKSA8PCAxMiB8ICh0aGlyZEJ5dGUgJiA2MykgPDwgNiB8IGZvdXJ0aEJ5dGUgJiA2MzsKICAgICAgICAgICAgICAgICAgaWYgKHRlbXBDb2RlUG9pbnQgPiA2NTUzNSAmJiB0ZW1wQ29kZVBvaW50IDwgMTExNDExMikgewogICAgICAgICAgICAgICAgICAgIGNvZGVQb2ludCA9IHRlbXBDb2RlUG9pbnQ7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgaWYgKGNvZGVQb2ludCA9PT0gbnVsbCkgewogICAgICAgICAgICBjb2RlUG9pbnQgPSA2NTUzMzsKICAgICAgICAgICAgYnl0ZXNQZXJTZXF1ZW5jZSA9IDE7CiAgICAgICAgICB9IGVsc2UgaWYgKGNvZGVQb2ludCA+IDY1NTM1KSB7CiAgICAgICAgICAgIGNvZGVQb2ludCAtPSA2NTUzNjsKICAgICAgICAgICAgcmVzLnB1c2goY29kZVBvaW50ID4+PiAxMCAmIDEwMjMgfCA1NTI5Nik7CiAgICAgICAgICAgIGNvZGVQb2ludCA9IDU2MzIwIHwgY29kZVBvaW50ICYgMTAyMzsKICAgICAgICAgIH0KICAgICAgICAgIHJlcy5wdXNoKGNvZGVQb2ludCk7CiAgICAgICAgICBpICs9IGJ5dGVzUGVyU2VxdWVuY2U7CiAgICAgICAgfQogICAgICAgIHJldHVybiBkZWNvZGVDb2RlUG9pbnRzQXJyYXkocmVzKTsKICAgICAgfQogICAgICB2YXIgTUFYX0FSR1VNRU5UU19MRU5HVEggPSA0MDk2OwogICAgICBmdW5jdGlvbiBkZWNvZGVDb2RlUG9pbnRzQXJyYXkoY29kZVBvaW50cykgewogICAgICAgIGNvbnN0IGxlbiA9IGNvZGVQb2ludHMubGVuZ3RoOwogICAgICAgIGlmIChsZW4gPD0gTUFYX0FSR1VNRU5UU19MRU5HVEgpIHsKICAgICAgICAgIHJldHVybiBTdHJpbmcuZnJvbUNoYXJDb2RlLmFwcGx5KFN0cmluZywgY29kZVBvaW50cyk7CiAgICAgICAgfQogICAgICAgIGxldCByZXMgPSAiIjsKICAgICAgICBsZXQgaSA9IDA7CiAgICAgICAgd2hpbGUgKGkgPCBsZW4pIHsKICAgICAgICAgIHJlcyArPSBTdHJpbmcuZnJvbUNoYXJDb2RlLmFwcGx5KFN0cmluZywgY29kZVBvaW50cy5zbGljZShpLCBpICs9IE1BWF9BUkdVTUVOVFNfTEVOR1RIKSk7CiAgICAgICAgfQogICAgICAgIHJldHVybiByZXM7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gYXNjaWlTbGljZShidWYsIHN0YXJ0LCBlbmQpIHsKICAgICAgICBsZXQgcmV0ID0gIiI7CiAgICAgICAgZW5kID0gTWF0aC5taW4oYnVmLmxlbmd0aCwgZW5kKTsKICAgICAgICBmb3IgKGxldCBpID0gc3RhcnQ7IGkgPCBlbmQ7ICsraSkgewogICAgICAgICAgcmV0ICs9IFN0cmluZy5mcm9tQ2hhckNvZGUoYnVmW2ldICYgMTI3KTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHJldDsKICAgICAgfQogICAgICBmdW5jdGlvbiBsYXRpbjFTbGljZShidWYsIHN0YXJ0LCBlbmQpIHsKICAgICAgICBsZXQgcmV0ID0gIiI7CiAgICAgICAgZW5kID0gTWF0aC5taW4oYnVmLmxlbmd0aCwgZW5kKTsKICAgICAgICBmb3IgKGxldCBpID0gc3RhcnQ7IGkgPCBlbmQ7ICsraSkgewogICAgICAgICAgcmV0ICs9IFN0cmluZy5mcm9tQ2hhckNvZGUoYnVmW2ldKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHJldDsKICAgICAgfQogICAgICBmdW5jdGlvbiBoZXhTbGljZShidWYsIHN0YXJ0LCBlbmQpIHsKICAgICAgICBjb25zdCBsZW4gPSBidWYubGVuZ3RoOwogICAgICAgIGlmICghc3RhcnQgfHwgc3RhcnQgPCAwKQogICAgICAgICAgc3RhcnQgPSAwOwogICAgICAgIGlmICghZW5kIHx8IGVuZCA8IDAgfHwgZW5kID4gbGVuKQogICAgICAgICAgZW5kID0gbGVuOwogICAgICAgIGxldCBvdXQgPSAiIjsKICAgICAgICBmb3IgKGxldCBpID0gc3RhcnQ7IGkgPCBlbmQ7ICsraSkgewogICAgICAgICAgb3V0ICs9IGhleFNsaWNlTG9va3VwVGFibGVbYnVmW2ldXTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIG91dDsKICAgICAgfQogICAgICBmdW5jdGlvbiB1dGYxNmxlU2xpY2UoYnVmLCBzdGFydCwgZW5kKSB7CiAgICAgICAgY29uc3QgYnl0ZXMgPSBidWYuc2xpY2Uoc3RhcnQsIGVuZCk7CiAgICAgICAgbGV0IHJlcyA9ICIiOwogICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgYnl0ZXMubGVuZ3RoIC0gMTsgaSArPSAyKSB7CiAgICAgICAgICByZXMgKz0gU3RyaW5nLmZyb21DaGFyQ29kZShieXRlc1tpXSArIGJ5dGVzW2kgKyAxXSAqIDI1Nik7CiAg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wgZW5jb2RpbmcpIHsKICAgICAgICBpZiAodHlwZW9mIHZhbCA9PT0gInN0cmluZyIpIHsKICAgICAgICAgIGlmICh0eXBlb2Ygc3RhcnQgPT09ICJzdHJpbmciKSB7CiAgICAgICAgICAgIGVuY29kaW5nID0gc3RhcnQ7CiAgICAgICAgICAgIHN0YXJ0ID0gMDsKICAgICAgICAgICAgZW5kID0gdGhpcy5sZW5ndGg7CiAgICAgICAgICB9IGVsc2UgaWYgKHR5cGVvZiBlbmQgPT09ICJzdHJpbmciKSB7CiAgICAgICAgICAgIGVuY29kaW5nID0gZW5kOwogICAgICAgICAgICBlbmQgPSB0aGlzLmxlbmd0aDsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChlbmNvZGluZyAhPT0gdm9pZCAwICYmIHR5cGVvZiBlbmNvZGluZyAhPT0gInN0cmluZyIpIHsKICAgICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcigiZW5jb2RpbmcgbXVzdCBiZSBhIHN0cmluZyIpOwogICAgICAgICAgfQogICAgICAgICAgaWYgKHR5cGVvZiBlbmNvZGluZyA9PT0gInN0cmluZyIgJiYgIUJ1ZmZlcjguaXNFbmNvZGluZyhlbmNvZGluZykpIHsKICAgICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcigiVW5rbm93biBlbmNvZGluZzogIiArIGVuY29kaW5nKTsKICAgICAgICAgIH0KICAgICAgICAgIGlmICh2YWwubGVuZ3RoID09PSAxKSB7CiAgICAgICAgICAgIGNvbnN0IGNvZGUgPSB2YWwuY2hhckNvZGVBdCgwKTsKICAgICAgICAgICAgaWYgKGVuY29kaW5nID09PSAidXRmOCIgJiYgY29kZSA8IDEyOCB8fCBlbmNvZGluZyA9PT0gImxhdGluMSIpIHsKICAgICAgICAgICAgICB2YWwgPSBjb2RlOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfSBlbHNlIGlmICh0eXBlb2YgdmFsID09PSAibnVtYmVyIikgewogICAgICAgICAgdmFsID0gdmFsICYgMjU1OwogICAgICAgIH0gZWxzZSBpZiAodHlwZW9mIHZhbCA9PT0gImJvb2xlYW4iKSB7CiAgICAgICAgICB2YWwgPSBOdW1iZXIodmFsKTsKICAgICAgICB9CiAgICAgICAgaWYgKHN0YXJ0IDwgMCB8fCB0aGlzLmxlbmd0aCA8IHN0YXJ0IHx8IHRoaXMubGVuZ3RoIDwgZW5kKSB7CiAgICAgICAgICB0aHJvdyBuZXcgUmFuZ2VFcnJvcigiT3V0IG9mIHJhbmdlIGluZGV4Iik7CiAgICAgICAgfQogICAgICAgIGlmIChlbmQgPD0gc3RhcnQpIHsKICAgICAgICAgIHJldHVybiB0aGlzOwogICAgICAgIH0KICAgICAgICBzdGFydCA9IHN0YXJ0ID4+PiAwOwogICAgICAgIGVuZCA9IGVuZCA9PT0gdm9pZCAwID8gdGhpcy5sZW5ndGggOiBlbmQgPj4+IDA7CiAgICAgICAgaWYgKCF2YWwpCiAgICAgICAgICB2YWwgPSAwOwogICAgICAgIGxldCBpOwogICAgICAgIGlmICh0eXBlb2YgdmFsID09PSAibnVtYmVyIikgewogICAgICAgICAgZm9yIChpID0gc3RhcnQ7IGkgPCBlbmQ7ICsraSkgewogICAgICAgICAgICB0aGlzW2ldID0gdmFsOwogICAgICAgICAgfQogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBjb25zdCBieXRlcyA9IEJ1ZmZlcjguaXNCdWZmZXIodmFsKSA/IHZhbCA6IEJ1ZmZlcjguZnJvbSh2YWwsIGVuY29kaW5nKTsKICAgICAgICAgIGNvbnN0IGxlbiA9IGJ5dGVzLmxlbmd0aDsKICAgICAgICAgIGlmIChsZW4gPT09IDApIHsKICAgICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcignVGhlIHZhbHVlICInICsgdmFsICsgJyIgaXMgaW52YWxpZCBmb3IgYXJndW1lbnQgInZhbHVlIicpOwogICAgICAgICAgfQogICAgICAgICAgZm9yIChpID0gMDsgaSA8IGVuZCAtIHN0YXJ0OyArK2kpIHsKICAgICAgICAgICAgdGhpc1tpICsgc3RhcnRdID0gYnl0ZXNbaSAlIGxlbl07CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiB0aGlzOwogICAgICB9OwogICAgICB2YXIgZXJyb3JzID0ge307CiAgICAgIGZ1bmN0aW9uIEUoc3ltLCBnZXRNZXNzYWdlLCBCYXNlKSB7CiAgICAgICAgZXJyb3JzW3N5bV0gPSBjbGFzcyBOb2RlRXJyb3IgZXh0ZW5kcyBCYXNlIHsKICAgICAgICAgIGNvbnN0cnVjdG9yKCkgewogICAgICAgICAgICBzdXBlcigpOwogICAgICAgICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkodGhpcywgIm1lc3NhZ2UiLCB7CiAgICAgICAgICAgICAgdmFsdWU6IGdldE1lc3NhZ2UuYXBwbHkodGhpcywgYXJndW1lbnRzKSwKICAgICAgICAgICAgICB3cml0YWJsZTogdHJ1ZSwKICAgICAgICAgICAgICBjb25maWd1cmFibGU6IHRydWUKICAgICAgICAgICAgfSk7CiAgICAgICAgICAgIHRoaXMubmFtZSA9IGAke3RoaXMubmFtZX0gWyR7c3ltfV1gOwogICAgICAgICAgICB0aGlzLnN0YWNrOwogICAgICAgICAgICBkZWxldGUgdGhpcy5uYW1lOwogICAgICAgICAgfQogICAgICAgICAgZ2V0IGNvZGUoKSB7CiAgICAgICAgICAgIHJldHVybiBzeW07CiAgICAgICAgICB9CiAgICAgICAgICBzZXQgY29kZSh2YWx1ZSkgewogICAgICAgICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkodGhpcywgImNvZGUiLCB7CiAgICAgICAgICAgICAgY29uZmlndXJhYmxlOiB0cnVlLAogICAgICAgICAgICAgIGVudW1lcmFibGU6IHRydWUsCiAgICAgICAgICAgICAgdmFsdWUsCiAgICAgICAgICAgICAgd3JpdGFibGU6IHRydWUKICAgICAgICAgICAgfSk7CiAgICAgICAgICB9CiAgICAgICAgICB0b1N0cmluZygpIHsKIC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CiAgICAgIH0KICAgICAgZnVuY3Rpb24gdXRmOFRvQnl0ZXMoc3RyaW5nLCB1bml0cykgewogICAgICAgIHVuaXRzID0gdW5pdHMgfHwgSW5maW5pdHk7CiAgICAgICAgbGV0IGNvZGVQb2ludDsKICAgICAgICBjb25zdCBsZW5ndGggPSBzdHJpbmcubGVuZ3RoOwogICAgICAgIGxldCBsZWFkU3Vycm9nYXRlID0gbnVsbDsKICAgICAgICBjb25zdCBieXRlcyA9IFtdOwogICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgbGVuZ3RoOyArK2kpIHsKICAgICAgICAgIGNvZGVQb2ludCA9IHN0cmluZy5jaGFyQ29kZUF0KGkpOwogICAgICAgICAgaWYgKGNvZGVQb2ludCA+IDU1Mjk1ICYmIGNvZGVQb2ludCA8IDU3MzQ0KSB7CiAgICAgICAgICAgIGlmICghbGVhZFN1cnJvZ2F0ZSkgewogICAgICAgICAgICAgIGlmIChjb2RlUG9pbnQgPiA1NjMxOSkgewogICAgICAgICAgICAgICAgaWYgKCh1bml0cyAtPSAzKSA+IC0xKQogICAgICAgICAgICAgICAgICBieXRlcy5wdXNoKDIzOSwgMTkxLCAxODkpOwogICAgICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICAgICAgfSBlbHNlIGlmIChpICsgMSA9PT0gbGVuZ3RoKSB7CiAgICAgICAgICAgICAgICBpZiAoKHVuaXRzIC09IDMpID4gLTEpCiAgICAgICAgICAgICAgICAgIGJ5dGVzLnB1c2goMjM5LCAxOTEsIDE4OSk7CiAgICAgICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgbGVhZFN1cnJvZ2F0ZSA9IGNvZGVQb2ludDsKICAgICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoY29kZVBvaW50IDwgNTYzMjApIHsKICAgICAgICAgICAgICBpZiAoKHVuaXRzIC09IDMpID4gLTEpCiAgICAgICAgICAgICAgICBieXRlcy5wdXNoKDIzOSwgMTkxLCAxODkpOwogICAgICAgICAgICAgIGxlYWRTdXJyb2dhdGUgPSBjb2RlUG9pbnQ7CiAgICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgY29kZVBvaW50ID0gKGxlYWRTdXJyb2dhdGUgLSA1NTI5NiA8PCAxMCB8IGNvZGVQb2ludCAtIDU2MzIwKSArIDY1NTM2OwogICAgICAgICAgfSBlbHNlIGlmIChsZWFkU3Vycm9nYXRlKSB7CiAgICAgICAgICAgIGlmICgodW5pdHMgLT0gMykgPiAtMSkKICAgICAgICAgICAgICBieXRlcy5wdXNoKDIzOSwgMTkxLCAxODkpOwogICAgICAgICAgfQogICAgICAgICAgbGVhZFN1cnJvZ2F0ZSA9IG51bGw7CiAgICAgICAgICBpZiAoY29kZVBvaW50IDwgMTI4KSB7CiAgICAgICAgICAgIGlmICgodW5pdHMgLT0gMSkgPCAwKQogICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICBieXRlcy5wdXNoKGNvZGVQb2ludCk7CiAgICAgICAgICB9IGVsc2UgaWYgKGNvZGVQb2ludCA8IDIwNDgpIHsKICAgICAgICAgICAgaWYgKCh1bml0cyAtPSAyKSA8IDApCiAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIGJ5dGVzLnB1c2goY29kZVBvaW50ID4+IDYgfCAxOTIsIGNvZGVQb2ludCAmIDYzIHwgMTI4KTsKICAgICAgICAgIH0gZWxzZSBpZiAoY29kZVBvaW50IDwgNjU1MzYpIHsKICAgICAgICAgICAgaWYgKCh1bml0cyAtPSAzKSA8IDApCiAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIGJ5dGVzLnB1c2goY29kZVBvaW50ID4+IDEyIHwgMjI0LCBjb2RlUG9pbnQgPj4gNiAmIDYzIHwgMTI4LCBjb2RlUG9pbnQgJiA2MyB8IDEyOCk7CiAgICAgICAgICB9IGVsc2UgaWYgKGNvZGVQb2ludCA8IDExMTQxMTIpIHsKICAgICAgICAgICAgaWYgKCh1bml0cyAtPSA0KSA8IDApCiAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIGJ5dGVzLnB1c2goY29kZVBvaW50ID4+IDE4IHwgMjQwLCBjb2RlUG9pbnQgPj4gMTIgJiA2MyB8IDEyOCwgY29kZVBvaW50ID4+IDYgJiA2MyB8IDEyOCwgY29kZVBvaW50ICYgNjMgfCAxMjgpOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgdGhyb3cgbmV3IEVycm9yKCJJbnZhbGlkIGNvZGUgcG9pbnQiKTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIGJ5dGVzOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGFzY2lpVG9CeXRlcyhzdHIpIHsKICAgICAgICBjb25zdCBieXRlQXJyYXkgPSBbXTsKICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IHN0ci5sZW5ndGg7ICsraSkgewogICAgICAgICAgYnl0ZUFycmF5LnB1c2goc3RyLmNoYXJDb2RlQXQoaSkgJiAyNTUpOwogICAgICAgIH0KICAgICAgICByZXR1cm4gYnl0ZUFycmF5OwogICAgICB9CiAgICAgIGZ1bmN0aW9uIHV0ZjE2bGVUb0J5dGVzKHN0ciwgdW5pdHMpIHsKICAgICAgICBsZXQgYywgaGksIGxvOwogICAgICAgIGNvbnN0IGJ5dGVBcnJheSA9IFtdOwogICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgc3RyLmxlbmd0aDsgKytpKSB7CiAgICAgICAgICBpZiAoKHVuaXRzIC09IDIpIDwgMCkKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICBjID0gc3RyLmNoYXJDb2RlQXQoaSk7CiAgICAgICAgICBoaSA9IGMgPj4gODsKICAgICAgICAgIGxvID0gYyAlIDI1NjsKICAgICAgICAgIGJ5dGVBcnJheS5wdXNoKGxvKTsKICAgICAgICAgIGJ5dGVBcn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hwb3J0cy5leHRlbmRTZXJpYWxpemVyID0gdm9pZCAwOwogICAgICBmdW5jdGlvbiBleHRlbmRTZXJpYWxpemVyKGV4dGVuZCwgaW1wbGVtZW50YXRpb24pIHsKICAgICAgICBjb25zdCBmYWxsYmFja0Rlc2VyaWFsaXplciA9IGV4dGVuZC5kZXNlcmlhbGl6ZS5iaW5kKGV4dGVuZCk7CiAgICAgICAgY29uc3QgZmFsbGJhY2tTZXJpYWxpemVyID0gZXh0ZW5kLnNlcmlhbGl6ZS5iaW5kKGV4dGVuZCk7CiAgICAgICAgcmV0dXJuIHsKICAgICAgICAgIGRlc2VyaWFsaXplKG1lc3NhZ2UpIHsKICAgICAgICAgICAgcmV0dXJuIGltcGxlbWVudGF0aW9uLmRlc2VyaWFsaXplKG1lc3NhZ2UsIGZhbGxiYWNrRGVzZXJpYWxpemVyKTsKICAgICAgICAgIH0sCiAgICAgICAgICBzZXJpYWxpemUoaW5wdXQpIHsKICAgICAgICAgICAgcmV0dXJuIGltcGxlbWVudGF0aW9uLnNlcmlhbGl6ZShpbnB1dCwgZmFsbGJhY2tTZXJpYWxpemVyKTsKICAgICAgICAgIH0KICAgICAgICB9OwogICAgICB9CiAgICAgIGV4cG9ydHMuZXh0ZW5kU2VyaWFsaXplciA9IGV4dGVuZFNlcmlhbGl6ZXI7CiAgICAgIHZhciBEZWZhdWx0RXJyb3JTZXJpYWxpemVyID0gewogICAgICAgIGRlc2VyaWFsaXplKG1lc3NhZ2UpIHsKICAgICAgICAgIHJldHVybiBPYmplY3QuYXNzaWduKEVycm9yKG1lc3NhZ2UubWVzc2FnZSksIHsKICAgICAgICAgICAgbmFtZTogbWVzc2FnZS5uYW1lLAogICAgICAgICAgICBzdGFjazogbWVzc2FnZS5zdGFjawogICAgICAgICAgfSk7CiAgICAgICAgfSwKICAgICAgICBzZXJpYWxpemUoZXJyb3IpIHsKICAgICAgICAgIHJldHVybiB7CiAgICAgICAgICAgIF9fZXJyb3JfbWFya2VyOiAiJCRlcnJvciIsCiAgICAgICAgICAgIG1lc3NhZ2U6IGVycm9yLm1lc3NhZ2UsCiAgICAgICAgICAgIG5hbWU6IGVycm9yLm5hbWUsCiAgICAgICAgICAgIHN0YWNrOiBlcnJvci5zdGFjawogICAgICAgICAgfTsKICAgICAgICB9CiAgICAgIH07CiAgICAgIHZhciBpc1NlcmlhbGl6ZWRFcnJvciA9ICh0aGluZykgPT4gdGhpbmcgJiYgdHlwZW9mIHRoaW5nID09PSAib2JqZWN0IiAmJiAiX19lcnJvcl9tYXJrZXIiIGluIHRoaW5nICYmIHRoaW5nLl9fZXJyb3JfbWFya2VyID09PSAiJCRlcnJvciI7CiAgICAgIGV4cG9ydHMuRGVmYXVsdFNlcmlhbGl6ZXIgPSB7CiAgICAgICAgZGVzZXJpYWxpemUobWVzc2FnZSkgewogICAgICAgICAgaWYgKGlzU2VyaWFsaXplZEVycm9yKG1lc3NhZ2UpKSB7CiAgICAgICAgICAgIHJldHVybiBEZWZhdWx0RXJyb3JTZXJpYWxpemVyLmRlc2VyaWFsaXplKG1lc3NhZ2UpOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcmV0dXJuIG1lc3NhZ2U7CiAgICAgICAgICB9CiAgICAgICAgfSwKICAgICAgICBzZXJpYWxpemUoaW5wdXQpIHsKICAgICAgICAgIGlmIChpbnB1dCBpbnN0YW5jZW9mIEVycm9yKSB7CiAgICAgICAgICAgIHJldHVybiBEZWZhdWx0RXJyb3JTZXJpYWxpemVyLnNlcmlhbGl6ZShpbnB1dCk7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICByZXR1cm4gaW5wdXQ7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9OwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vdGhyZWFkc0AxLjcuMC9ub2RlX21vZHVsZXMvdGhyZWFkcy9kaXN0L2NvbW1vbi5qcwogIHZhciByZXF1aXJlX2NvbW1vbiA9IF9fY29tbW9uSlMo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1bmN0aW9uIGZ1bGZpbGxlZCh2YWx1ZSkgewogICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgIHN0ZXAoZ2VuZXJhdG9yLm5leHQodmFsdWUpKTsKICAgICAgICAgICAgfSBjYXRjaCAoZSkgewogICAgICAgICAgICAgIHJlamVjdChlKTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgZnVuY3Rpb24gcmVqZWN0ZWQodmFsdWUpIHsKICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICBzdGVwKGdlbmVyYXRvclsidGhyb3ciXSh2YWx1ZSkpOwogICAgICAgICAgICB9IGNhdGNoIChlKSB7CiAgICAgICAgICAgICAgcmVqZWN0KGUpOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBmdW5jdGlvbiBzdGVwKHJlc3VsdCkgewogICAgICAgICAgICByZXN1bHQuZG9uZSA/IHJlc29sdmUocmVzdWx0LnZhbHVlKSA6IGFkb3B0KHJlc3VsdC52YWx1ZSkudGhlbihmdWxmaWxsZWQsIHJlamVjdGVkKTsKICAgICAgICAgIH0KICAgICAgICAgIHN0ZXAoKGdlbmVyYXRvciA9IGdlbmVyYXRvci5hcHBseSh0aGlzQXJnLCBfYXJndW1lbnRzIHx8IFtdKSkubmV4dCgpKTsKICAgICAgICB9KTsKICAgICAgfTsKICAgICAgdmFyIF9faW1wb3J0RGVmYXVsdCA9IGV4cG9ydHMgJiYgZXhwb3J0cy5fX2ltcG9ydERlZmF1bHQgfHwgZnVuY3Rpb24obW9kKSB7CiAgICAgICAgcmV0dXJuIG1vZCAmJiBtb2QuX19lc01vZHVsZSA/IG1vZCA6IHsgImRlZmF1bHQiOiBtb2QgfTsKICAgICAgfTsKICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KGV4cG9ydHMsICJfX2VzTW9kdWxlIiwgeyB2YWx1ZTogdHJ1ZSB9KTsKICAgICAgZXhwb3J0cy5leHBvc2UgPSBleHBvcnRzLmlzV29ya2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PYnNlcnZhYmxlKHN5bmNSZXN1bHQpKSB7CiAgICAgICAgICAgIGNvbnN0IHN1YnNjcmlwdGlvbiA9IHN5bmNSZXN1bHQuc3Vic2NyaWJlKCh2YWx1ZSkgPT4gcG9zdEpvYlJlc3VsdE1lc3NhZ2Uoam9iVUlELCBmYWxzZSwgY29tbW9uXzEuc2VyaWFsaXplKHZhbHVlKSksIChlcnJvcikgPT4gewogICAgICAgICAgICAgIHBvc3RKb2JFcnJvck1lc3NhZ2Uoam9iVUlELCBjb21tb25fMS5zZXJpYWxpemUoZXJyb3IpKTsKICAgICAgICAgICAgICBhY3RpdmVTdWJzY3JpcHRpb25zLmRlbGV0ZShqb2JVSUQpOwogICAgICAgICAgICB9LCAoKSA9PiB7CiAgICAgICAgICAgICAgcG9zdEpvYlJlc3VsdE1lc3NhZ2Uoam9iVUlELCB0cnVlKTsKICAgICAgICAgICAgICBhY3RpdmVTdWJzY3JpcHRpb25zLmRlbGV0ZShqb2JVSUQpOwogICAgICAgICAgICB9KTsKICAgICAgICAgICAgYWN0aXZlU3Vic2NyaXB0aW9ucy5zZXQoam9iVUlELCBzdWJzY3JpcHRpb24pOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICBjb25zdCByZXN1bHQgPSB5aWVsZCBzeW5jUmVzdWx0OwogICAgICAgICAgICAgIHBvc3RKb2JSZXN1bHRNZXNzYWdlKGpvYlVJRCwgdHJ1ZSwgY29tbW9uXzEuc2VyaWFsaXplKHJlc3VsdCkpOwogICAgICAgICAgICB9IGNhdGNoIChlcnJvcikgewogICAgICAgICAgICAgIHBvc3RKb2JFcnJvck1lc3NhZ2Uoam9iVUlELCBjb21tb25fMS5zZXJpYWxpemUoZXJyb3IpKTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0pOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGV4cG9zZTIoZXhwb3NlZCkgewogICAgICAgIGlmICghaW1wbGVtZ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gKGVycm9yKSA9PiB7CiAgICAgICAgICBzZXRUaW1lb3V0KCgpID0+IHBvc3RVbmNhdWdodEVycm9yTWVzc2FnZShlcnJvciksIDI1MCk7CiAgICAgICAgfSk7CiAgICAgICAgcHJvY2Vzcy5vbigidW5oYW5kbGVkUmVqZWN0aW9uIiwgKGVycm9yKSA9PiB7CiAgICAgICAgICBpZiAoZXJyb3IgJiYgdHlwZW9mIGVycm9yLm1lc3NhZ2UgPT09ICJzdHJpbmciKSB7CiAgICAgICAgICAgIHNldFRpbWVvdXQoKCkgPT4gcG9zdFVuY2F1Z2h0RXJyb3JNZXNzYWdlKGVycm9yKSwgMjUwKTsKICAgICAgICAgIH0KICAgICAgICB9KTsKICAgICAgfQogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vbG9uZ0A0LjAuMC9ub2RlX21vZHVsZXMvbG9uZy9zcmMvbG9uZy5qcwogIHZhciByZXF1aXJlX2xvbmcgPSBfX2NvbW1vbkpTKHsKICAgICJub2RlX21vZHVsZXMvLnBucG0vbG9uZ0A0LjAuMC9ub2RlX21vZHVsZXMvbG9uZy9zcmMvbG9uZy5qcyIoZXhwb3J0cywgbW9kdWxlKSB7CiAgICAgIGluaXRfYnVmZmVyX3NoaW0oKTsKICAgICAgbW9kdWxlLmV4cG9ydHMgPSBMb25nNDsKICAgICAgdmFyIHdhc20gPSBudWxsOwogICAgICB0cnkgewogICAgICAgIHdhc20gPSBuZXcgV2ViQXNzZW1ibHkuSW5zdGFuY2UobmV3IFdlYkFzc2VtYmx5Lk1vZHVsZShuZXcgVWludDhBcnJheShbCiAgICAgICAgICAwLAogICAgICAgICAgOTcsCiAgICAgICAgICAxMTUsCiAgICAgICAgICAxMDksCiAgICAgICAgICAxLAogICAgICAgICAgMCwKICAgICAgICAgIDAsCiAgICAgICAgICAwLAogICAgICAgICAgMSwKICAgICAgICAgIDEzLAogICAgICAgICAgMiwKICAgICAgICAgIDk2LAogICAgICAgICAgMCwKICAgICAgICAgIDEsCiAgICAgICAgICAxMjcsCiAgICAgICAgICA5NiwKICAgICAgICAgIDQsCiAgICAgICAgICAxMjcsCiAgICAgICAgICAxMjcsCiAgICAgICAgICAxMjcsCiAgICAgICAgICAxMjcsCiAgICAgICAgICAxLAogICAgICAgICAgMTI3LAogICAgICAgICAgMywKICAgICAgICAgIDcsCiAgICAgICAgICA2LAogICAgICAgICAgMCwKICAgICAgICAgIDEsCiAgICAgICAgICAxLAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICAxLAogICAgICAgICAgNiwKICAgICAgICAgIDYsCiAgICAgICAgICAxLAogICAgICAgICAgMTI3LAogICAgICAgICAgMSwKICAgICAgICAgIDY1LAogICAgICAgICAgMCwKICAgICAgICAgIDExLAogICAgICAgICAgNywKICAgICAgICAgIDUwLAogICAgICAgICAgNiwKICAgICAgICAgIDMsCiAgICAgICAgICAxMDksCiAgICAgICAgICAxMTcsCiAgICAgICAgICAxMDgsCiAgICAgICAgICAwLAogICAgICAgICAgMSwKICAgICAgICAgIDUsCiAgICAgICAgICAxMDAsCiAgICAgICAgICAxMDUsCiAgICAgICAgICAxMTgsCiAgICAgICAgICA5NSwKICAgICAgICAgIDExNSwKICAgICAgICAgIDAsCiAgICAgICAgICAyLAogICAgICAgICAgNSwKICAgICAgICAgIDEwMCwKICAgICAgICAgIDEwNSwKICAgICAgICAgIDExOCwKICAgICAgICAgIDk1LAogICAgICAgICAgMTE3LAogICAgICAgICAgMCwKICAgICAgICAgIDMsCiAgICAgICAgICA1LAogICAgICAgICAgMTE0LAogICAgICAgICAgMTAxLAogICAgICAgICAgMTA5LAogICAgICAgICAgOTUsCiAgICAgICAgICAxMTUsCiAgICAgICAgICAwLAogICAgICAgICAgNCwKICAgICAgICAgIDUsCiAgICAgICAgICAxMTQsCiAgICAgICAgICAxMDEsCiAgICAgICAgICAxMDksCiAgICAgICAgICA5NSwKICAgICAgICAgIDExNywKICAgICAgICAgIDAsCiAgICAgICAgICA1LAogICAgICAgICAgOCwKICAgICAgICAgIDEwMywKICAgICAgICAgIDEwMSwKICAgICAgICAgIDExNiwKICAgICAgICAgIDk1LAogICAgICAgICAgMTA0LAogICAgICAgICAgMTA1LAogICAgICAgICAgMTAzLAogICAgICAgICAgMTA0LAogICAgICAgICAgMCwKICAgICAgICAgIDAsCiAgICAgICAgICAxMCwKICAgICAgICAgIDE5MSwKICAgICAgICAgIDEsCiAgICAgICAgICA2LAogICAgICAgICAgNCwKICAgICAgICAgIDAsCiAgICAgICAgICAzNSwKICAgICAgICAgIDAsCiAgICAgICAgICAxMSwKICAgICAgICAgIDM2LAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICAxMjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDAsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMzIsCiAgICAgICAgICAyLAogICAgICAgICAgMTczLAogICAgICAgICAgMzIsCiAgICAgICAgICAzLAogICAgICAgICAgMTczLAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNCwKICAgICAgICAgIDEzMiwKICAgICAgICAgIDEyNiwKICAgICAgICAgIDM0LAogICAgICAgICAgNCwKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzUsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAzNiwKICAgICAgICAgIDAsCiAgICAgICAgICAzMiwKICAgICAgICAgIDQsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAxMSwKICAgICAgICAgIDM2LAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICAxMjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDAsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMzIsCiAgICAgICAgICAyLAogICAgICAgICAgMTczLAogICAgICAgICAgMzIsCiAgICAgICAgICAzLAogICAgICAgICAgMTczLAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNCwKICAgICAgICAgIDEzMiwKICAgICAgICAgIDEyNywKICAgICAgICAgIDM0LAogICAgICAgICAgNCwKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzUsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAzNiwKICAgICAgICAgIDAsCiAgICAgICAgICAzMiwKICAgICAgICAgIDQsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAxMSwKICAgICAgICAgIDM2LAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICAxMjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDAsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMzIsCiAgICAgICAgICAyLAogICAgICAgICAgMTczLAogICAgICAgICAgMzIsCiAgICAgICAgICAzLAogICAgICAgICAgMTczLAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNCwKICAgICAgICAgIDEzMiwKICAgICAgICAgIDEyOCwKICAgICAgICAgIDM0LAogICAgICAgICAgNCwKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzUsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAzNiwKICAgICAgICAgIDAsCiAgICAgICAgICAzMiwKICAgICAgICAgIDQsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAxMSwKICAgICAgICAgIDM2LAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICAxMjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDAsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMzIsCiAgICAgICAgICAyLAogICAgICAgICAgMTczLAogICAgICAgICAgMzIsCiAgICAgICAgICAzLAogICAgICAgICAgMTczLAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNCwKICAgICAgICAgIDEzMiwKICAgICAgICAgIDEyOSwKICAgICAgICAgIDM0LAogICAgICAgICAgNCwKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzUsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAzNiwKICAgICAgICAgIDAsCiAgICAgICAgICAzMiwKICAgICAgICAgIDQsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAxMSwKICAgICAgICAgIDM2LAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICAxMjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDAsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMzIsCiAgICAgICAgICAyLAogICAgICAgICAgMTczLAogICAgICAgICAgMzIsCiAgICAgICAgICAzLAogICAgICAgICAgMTczLAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNCwKICAgICAgICAgIDEzMiwKICAgICAgICAgIDEzMCwKICAgICAgICAgIDM0LAogICAgICAgICAgNCwKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzUsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAzNiwKICAgICAgICAgIDAsCiAgICAgICAgICAzMiwKICAgICAgICAgIDQsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAxMQogICAgICAgIF0pKSwge30pLmV4cG9ydHM7CiAgICAgIH0gY2F0Y2ggKGUpIHsKICAgICAgfQogICAgICBmdW5jdGlvbiBMb25nNChsb3csIGhpZ2gsIHVuc2lnbmVkKSB7CiAgICAgICAgdGhpcy5sb3cgPSBsb3cgfCAwOwogICAgICAgIHRoaXMuaGlnaCA9IGhpZ2ggfCAwOwogICAgICAgIHRoaXMudW5zaWduZWQgPSAhIXVuc2lnbmVkOwogICAgICB9CiAgICAgIExvbmc0LnByb3RvdHlwZS5fX2lzTG9uZ19fOwogICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkoTG9uZzQucHJvdG90eXBlLCAiX19pc0xvbmdfXyIsIHsgdmFsdWU6IHRydWUgfSk7CiAgICAgIGZ1bmN0aW9uIGlzTG9uZyhvYmopIHsKICAgICAgICByZXR1cm4gKG9iaiAmJiBvYmpbIl9faXNMb25nX18iXSkgPT09IHRydWU7CiAgICAgIH0KICAgICAgTG9uZzQuaXNMb25nID0gaXNMb25nOwogICAgICB2YXIgSU5UX0NBQ0hFID0ge307CiAgICAgIHZhciBVSU5UX0NBQ0hFID0ge307CiAgICAgIGZ1bmN0aW9uIGZyb21JbnQodmFsdWUsIHVuc2lnbmVkKSB7CiAgICAgICAgdmFyIG9iaiwgY2FjaGVkT2JqLCBjYWNoZTsKICAgICAgICBpZiAodW5zaWduZWQpIHsKICAgICAgICAgIHZhbHVlID4+Pj0gMDsKICAgICAgICAgIGlmIChjYWNoZSA9IDAgPD0gdmFsdWUgJiYgdmFsdWUgPCAyNTYpIHsKICAgICAgICAgICAgY2FjaGVkT2JqID0gVUlOVF9DQUNIRVt2YWx1ZV07CiAgICAgICAgICAgIGlmIChjYWNoZWRPYmopCiAgICAgICAgICAgICAgcmV0dXJuIGNhY2hlZE9iajsKICAgICAgICAgIH0KICAgICAgICAgIG9iaiA9IGZyb21CaXRzKHZhbHVlLCAodmFsdWUgfCAwKSA8IDAgPyAtMSA6IDAsIHRydWUpOwogICAgICAgICAgaWYgKGNhY2hlKQogICAgICAgICAgICBVSU5UX0NBQ0hFW3ZhbHVlXSA9IG9iajsKICAgICAgICAgIHJldHVybiBvYmo7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIHZhbHVlIHw9IDA7CiAgICAgICAgICBpZiAoY2FjaGUgPSAtMTI4IDw9IHZhbHVlICYmIHZhbHVlIDwgMTI4KSB7CiAgICAgICAgICAgIGNhY2hlZE9iaiA9IElOVF9DQUNIRVt2YWx1ZV07CiAgICAgICAgICAgIGlmIChjYWNoZWRPYmopCiAgICAgICAgICAgICAgcmV0dXJuIGNhY2hlZE9iajsKICAgICAgICAgIH0KICAgICAgICAgIG9iaiA9IGZyb21CaXRzKHZhbHVlLCB2YWx1ZSA8IDAgPyAtMSA6IDAsIGZhbHNlKTsKICAgICAgICAgIGlmIChjYWNoZSkKICAgICAgICAgICAgSU5UX0NBQ0hFW3ZhbHVlXSA9IG9iajsKICAgICAgICAgIHJldHVybiBvYmo7CiAgICAgICAgfQogICAgICB9CiAgICAgIExvbmc0LmZyb21JbnQgPSBmcm9tSW50OwogICAgICBmdW5jdGlvbiBmcm9tTnVtYmVyKHZhbHVlLCB1bnNpZ25lZCkgewogICAgICAgIGlmIChpc05hTih2YWx1ZSkpCiAgICAgICAgICByZXR1cm4gdW5zaWduZWQgPyBVWkVSTyA6IFpFUk87CiAgICAgICAgaWYgKHVuc2lnbmVkKSB7CiAgICAgICAgICBpZiAodmFsdWUgPCAwKQogICAgICAgICAgICByZXR1cm4gVVpFUk87CiAgICAgICAgICBpZiAodmFsdWUgPj0gVFdPX1BXUl82NF9EQkwpCiAgICAgICAgICAgIHJldHVybiBNQVhfVU5TSUdORURfVkFMVUU7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIGlmICh2YWx1ZSA8PSAtVFdPX1BXUl82M19EQkwpCiAgICAgICAgICAgIHJldHVybiBNSU5fVkFMVUU7CiAgICAgICAgICBpZiAodmFsdWUgKyAxID49IFRXT19QV1JfNjNfREJMKQogICAgICAgICAgICByZXR1cm4gTUFYX1ZBTFVFOwogICAgICAgIH0KICAgICAgICBpZiAodmFsdWUgPCAwKQogICAgICAgICAgcmV0dXJuIGZyb21OdW1iZXIoLXZhbHVlLCB1bnNpZ25lZCkubmVnKCk7CiAgICAgICAgcmV0dXJuIGZyb21CaXRzKHZhbHVlICUgVFdPX1BXUl8zMl9EQkwgfCAwLCB2YWx1ZSAvIFRXT19QV1JfMzJfREJMIHwgMCwgdW5zaWduZWQpOwogICAgICB9CiAgICAgIExvbmc0LmZyb21OdW1iZXIgPSBmcm9tTnVtYmVyOwogICAgICBmdW5jdGlvbiBmcm9tQml0cyhsb3dCaXRzLCBoaWdoQml0cywgdW5zaWduZWQpIHsKICAgICAgICByZXR1cm4gbmV3IExvbmc0KGxvd0JpdHMsIGhpZ2hCaXRzLCB1bnNpZ25lZCk7CiAgICAgIH0KICAgICAgTG9uZzQuZnJvbUJpdHMgPSBmcm9tQml0czsKICAgICAgdmFyIHBvd19kYmwgPSBNYXRoLnBvdzsKICAgICAgZnVuY3Rpb24gZnJvbVN0cmluZyhzdHIsIHVuc2lnbmVkLCByYWRpeCkgewogICAgICAgIGlmIChzdHIubGVuZ3RoID09PSAwKQogICAgICAgICAgdGhyb3cgRXJyb3IoImVtcHR5IHN0cmluZyIpOwogICAgICAgIGlmIChzdHIgPT09ICJOYU4iIHx8IHN0ciA9PT0gIkluZmluaXR5IiB8fCBzdHIgPT09ICIrSW5maW5pdHkiIHx8IHN0ciA9PT0gIi1JbmZpbml0eSIpCiAgICAgICAgICByZXR1cm4gWkVSTzsKICAgICAgICBpZiAodHlwZW9mIHVuc2lnbmVkID09PSAibnVtYmVyIikgewogICAgICAgICAgcmFkaXggPSB1bnNpZ25lZCwgdW5zaWduZWQgPSBmYWxzZTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgdW5zaWduZWQgPSAhIXVuc2lnbmVkOwogICAgICAgIH0KICAgICAgICByYWRpeCA9IHJhZGl4IHx8IDEwOwogICAgICAgIGlmIChyYWRpeCA8IDIgfHwgMzYgPCByYWRpeCkKICAgICAgICAgIHRocm93IFJhbmdlRXJyb3IoInJhZGl4Iik7CiAgICAgICAgdmFyIHA7CiAgICAgICAgaWYgKChwID0gc3RyLmluZGV4T2YoIi0iKSkgPiAwKQogICAgICAgICAgdGhyb3cgRXJyb3IoImludGVyaW9yIGh5cGhlbiIpOwogICAgICAgIGVsc2UgaWYgKHAgPT09IDApIHsKICAgICAgICAgIHJldHVybiBmcm9tU3RyaW5nKHN0ci5zdWJzdHJpbmcoMSksIHVuc2lnbmVkLCByYWRpeCkubmVnKCk7CiAgICAgICAgfQogICAgICAgIHZhciByYWRpeFRvUG93ZXIgPSBmcm9tTnVtYmVyKHBvd19kYmwocmFkaXgsIDgpKTsKICAgICAgICB2YXIgcmVzdWx0ID0gWkVSTzsKICAgICAgICBmb3IgKHZhciBpID0gMDsgaSA8IHN0ci5sZW5ndGg7IGkgKz0gOCkgewogICAgICAgICAgdmFyIHNpemUgPSBNYXRoLm1pbig4LCBzdHIubGVuZ3RoIC0gaSksIHZhbHVlID0gcGFyc2VJbnQoc3RyLnN1YnN0cmluZyhpLCBpICsgc2l6ZSksIHJhZGl4KTsKICAgICAgICAgIGlmIChzaXplIDwgOCkgewogICAgICAgICAgICB2YXIgcG93ZXIgPSBmcm9tTnVtYmVyKHBvd19kYmwocmFkaXgsIHNpemUpKTsKICAgICAgICAgICAgcmVzdWx0ID0gcmVzdWx0Lm11bChwb3dlcikuYWRkKGZyb21OdW1iZXIodmFsdWUpKTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHJlc3VsdCA9IHJlc3VsdC5tdWwocmFkaXhUb1Bvd2VyKTsKICAgICAgICAgICAgcmVzdWx0ID0gcmVzdWx0LmFkZChmcm9tTnVtYmVyKH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2ggPj4+IDApICogVFdPX1BXUl8zMl9EQkwgKyAodGhpcy5sb3cgPj4+IDApOwogICAgICAgIHJldHVybiB0aGlzLmhpZ2ggKiBUV09fUFdSXzMyX0RCTCArICh0aGlzLmxvdyA+Pj4gMCk7CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUudG9TdHJpbmcgPSBmdW5jdGlvbiB0b1N0cmluZyhyYWRpeCkgewogICAgICAgIHJhZGl4ID0gcmFkaXggfHwgMTA7CiAgICAgICAgaWYgKHJhZGl4IDwgMiB8fCAzNiA8IHJhZGl4KQogICAgICAgICAgdGhyb3cgUmFuZ2VFcnJvcigicmFkaXgiKTsKICAgICAgICBpZiAodGhpcy5pc1plcm8oKSkKICAgICAgICAgIHJldHVybiAiMCI7CiAgICAgICAgaWYgKHRoaXMuaXNOZWdhdGl2ZSgpKSB7CiAgICAgICAgICBpZiAodGhpcy5lcShNSU5fVkFMVUUpKSB7CiAgICAgICAgICAgIHZhciByYWRpeExvbmcgPSBmcm9tTnVtYmVyKHJhZGl4KSwgZGl2ID0gdGhpcy5kaXYocmFkaXhMb25nKSwgcmVtMSA9IGRpdi5tdWwocmFkaXhMb25nKS5zdWIodGhpcyk7CiAgICAgICAgICAgIHJldHVybiBkaXYudG9TdHJpbmcocmFkaXgpICsgcmVtMS50b0ludCgpLnRvU3RyaW5nKHJhZGl4KTsKICAgICAgICAgIH0gZWxzZQogICAgICAgICAgICByZXR1cm4gIi0iICsgdGhpcy5uZWcoKS50b1N0cmluZyhyYWRpeCk7CiAgICAgICAgfQogICAgICAgIHZhciByYWRpeFRvUG93ZXIgPSBmcm9tTnVtYmVyKHBvd19kYmwocmFkaXgsIDYpLCB0aGlzLnVuc2lnbmVkKSwgcmVtID0gdGhpczsKICAgICAgICB2YXIgcmVzdWx0ID0gIiI7CiAgICAgICAgd2hpbGUgKHRydWUpIHsKICAgICAgICAgIHZhciByZW1EaXYgPSByZW0uZGl2KHJhZGl4VG9Qb3dlciksIGludHZhbCA9IHJlbS5zdWIocmVtRGl2Lm11bChyYWRpeFRvUG93ZXIpKS50b0ludCgpID4+PiAwLCBkaWdpdHMgPSBpbnR2YWwudG9TdHJpbmcocmFkaXgpOwogICAgICAgICAgcmVtID0gcmVtRGl2OwogICAgICAgICAgaWYgKHJlbS5pc1plcm8oKSkKICAgICAgICAgICAgcmV0dXJuIGRpZ2l0cyArIHJlc3VsdDsKICAgICAgICAgIGVsc2UgewogICAgICAgICAgICB3aGlsZSAoZGlnaXRzLmxlbmd0aCA8IDYpCiAgICAgICAgICAgICAgZGlnaXRzID0gIjAiICsgZGlnaXRzOwogICAgICAgICAgICByZXN1bHQgPSAiIiArIGRpZ2l0cyArIHJlc3VsdDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUuZ2V0SGlnaEJpdHMgPSBmdW5jdGlvbiBnZXRIaWdoQml0cygpIHsKICAgICAgICByZXR1cm4gdGhpcy5oaWdoOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLmdldEhpZ2hCaXRzVW5zaWduZWQgPSBmdW5jdGlvbiBnZXRIaWdoQml0c1Vuc2lnbmVkKCkgewogICAgICAgIHJldHVybiB0aGlzLmhpZ2ggPj4+IDA7CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUuZ2V0TG93Qml0cyA9IGZ1bmN0aW9uIGdldExvd0JpdHMoKSB7CiAgICAgICAgcmV0dXJuIHRoaXMubG93OwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLmdldExvd0JpdHNVbnNpZ25lZCA9IGZ1bmN0aW9uIGdldExvd0JpdHNVbnNpZ25lZCgpIHsKICAgICAgICByZXR1cm4gdGhpcy5sb3cgPj4+IDA7CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUuZ2V0TnVtQml0c0FicyA9IGZ1bmN0aW9uIGdldE51bUJpdHNBYnMoKSB7CiAgICAgICAgaWYgKHRoaXMuaXNOZWdhdGl2ZSgpKQogICAgICAgICAgcmV0dXJuIHRoaXMuZXEoTUlOX1ZBTFVFKSA/IDY0IDogdGhpcy5uZWcoKS5nZXROdW1CaXRzQWJzKCk7CiAgICAgICAgdmFyIHZhbCA9IHRoaXMuaGlnaCAhPSAwID8gdGhpcy5oaWdoIDogdGhpcy5sb3c7CiAgICAgICAgZm9yICh2YXIgYml0ID0gMzE7IGJpdCA+IDA7IGJpdC0tKQogICAgICAgICAgaWYgKCh2YWwgJiAxIDw8IGJpdCkgIT0gMCkKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgcmV0dXJuIHRoaXMuaGlnaCAhPSAwID8gYml0ICsgMzMgOiBiaXQgKyAxOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLmlzWmVybyA9IGZ1bmN0aW9uIGlzWmVybygpIHsKICAgICAgICByZXR1cm4gdGhpcy5oaWdoID09PSAwICYmIHRoaXMubG93ID09PSAwOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLmVxeiA9IExvbmdQcm90b3R5cGUuaXNaZXJvOwogICAgICBMb25nUHJvdG90eXBlLmlzTmVnYXRpdmUgPSBmdW5jdGlvbiBpc05lZ2F0aXZlKCkgewogICAgICAgIHJldHVybiAhdGhpcy51bnNpZ25lZCAmJiB0aGlzLmhpZ2ggPCAwOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLmlzUG9zaXRpdmUgPSBmdW5jdGlvbiBpc1Bvc2l0aXZlKCkgewogICAgICAgIHJldHVybiB0aGlzLnVuc2lnbmVkIHx8IHRoaXMuaGlnaCA+PSAwOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLmlzT2RkID0gZnVuY3Rpb24gaXNPZGQoKSB7CiAgICAgICAgcmV0dXJuICh0aGlzLmxvdyAmIDEpID09PSAxOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLmlzRXZlbiA9IGZ1bmN0aW9uIGlzRXZlbigpIHsKICAgICAgICByZXR1cm4gKHRoaXMubG93ICYgMSkgPT09IDA7CiA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ogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLmx0ZSA9IExvbmdQcm90b3R5cGUubGVzc1RoYW5PckVxdWFsOwogICAgICBMb25nUHJvdG90eXBlLmxlID0gTG9uZ1Byb3RvdHlwZS5sZXNzVGhhbk9yRXF1YWw7CiAgICAgIExvbmdQcm90b3R5cGUuZ3JlYXRlclRoYW4gPSBmdW5jdGlvbiBncmVhdGVyVGhhbihvdGhlcikgewogICAgICAgIHJldHVybiB0aGlzLmNvbXAob3RoZXIpID4gMDsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS5ndCA9IExvbmdQcm90b3R5cGUuZ3JlYXRlclRoYW47CiAgICAgIExvbmdQcm90b3R5cGUuZ3JlYXRlclRoYW5PckVxdWFsID0gZnVuY3Rpb24gZ3JlYXRlclRoYW5PckVxdWFsKG90aGVyKSB7CiAgICAgICAgcmV0dXJuIHRoaXMuY29tcChvdGhlcikgPj0gMDsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS5ndGUgPSBMb25nUHJvdG90eXBlLmdyZWF0ZXJUaGFuT3JFcXVhbDsKICAgICAgTG9uZ1Byb3RvdHlwZS5nZSA9IExvbmdQcm90b3R5cGUuZ3JlYXRlclRoYW5PckVxdWFsOwogICAgICBMb25nUHJvdG90eXBlLmNvbXBhcmUgPSBmdW5jdGlvbiBjb21wYXJlKG90aGVyKSB7CiAgICAgICAgaWYgKCFpc0xvbmcob3RoZXIpKQogICAgICAgICAgb3RoZXIgPSBmcm9tVmFsdWUob3RoZXIpOwogICAgICAgIGlmICh0aGlzLmVxKG90aGVyKSkKICAgICAgICAgIHJldHVybiAwOwogICAgICAgIHZhciB0aGlzTmVnID0gdGhpcy5pc05lZ2F0aXZlKCksIG90aGVyTmVnID0gb3RoZXIuaXNOZWdhdGl2ZSgpOwogICAgICAgIGlmICh0aGlzTmVnICYmICFvdGhlck5lZykKICAgICAgICAgIHJldHVybiAtMTsKICAgICAgICBpZiAoIXRoaXNOZWcgJi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KQogICAgICAgICAgcmV0dXJuIFpFUk87CiAgICAgICAgaWYgKCFpc0xvbmcobXVsdGlwbGllcikpCiAgICAgICAgICBtdWx0aXBsaWVyID0gZnJvbVZhbHVlKG11bHRpcGxpZXIpOwogICAgICAgIGlmICh3YXNtKSB7CiAgICAgICAgICB2YXIgbG93ID0gd2FzbS5tdWwodGhpcy5sb3csIHRoaXMuaGlnaCwgbXVsdGlwbGllci5sb3csIG11bHRpcGxpZXIuaGlnaCk7CiAgICAgICAgICByZXR1cm4gZnJvbUJpdHMobG93LCB3YXNtLmdldF9oaWdoKCksIHRoaXMudW5zaWduZWQpOwogICAgICAgIH0KICAgICAgICBpZiAobXVsdGlwbGllci5pc1plcm8oKSkKICAgICAgICAgIHJldHVybiBaRVJPOwogICAgICAgIGlmICh0aGlzLmVxKE1JTl9WQUxVRSkpCiAgICAgICAgICByZXR1cm4gbXVsdGlwbGllci5pc09kZCgpID8gTUlOX1ZBTFVFIDogWkVSTzsKICAgICAgICBpZiAobXVsdGlwbGllci5lcShNSU5fVkFMVUUpKQogICAgICAgICAgcmV0dXJuIHRoaXMuaXNPZGQoKSA/IE1JTl9WQUxVRSA6IFpFUk87CiAgICAgICAgaWYgKHRoaXMuaXNOZWdhdGl2ZSgpKSB7CiAgICAgICAgICBpZiAobXVsdGlwbGllci5pc05lZ2F0aXZlKCkpCiAgICAgICAgICAgIHJldHVybiB0aGlzLm5lZygpLm11bChtdWx0aXBsaWVyLm5lZygpKTsKICAgICAgICAgIGVsc2UKICAgICAgICAgICAgcmV0dXJuIHRoaXMubmVnKCkubXVsKG11bHRpcGxpZXIpLm5lZygpOwogICAgICAgIH0gZWxzZSBpZiAobXVsdGlwbGllci5pc05lZ2F0aXZlKCkpCiAgICAgICAgICByZXR1cm4gdGhpcy5tdWwobXVsdGlwbGllci5uZWcoKSkubmVnKCk7CiAgICAgICAgaWYgKHRoaXMubHQoVFdPX1BXUl8yNCkgJiYgbXVsdGlwbGllci5sdChUV09fUFdSXzI0KS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ICs9IGEwMCAqIGIzMjsKICAgICAgICBjNDggKz0gYzMyID4+PiAxNjsKICAgICAgICBjMzIgJj0gNjU1MzU7CiAgICAgICAgYzQ4ICs9IGE0OCAqIGIwMCArIGEzMiAqIGIxNiArIGExNiAqIGIzMiArIGEwMCAqIGI0ODsKICAgICAgICBjNDggJj0gNjU1MzU7CiAgICAgICAgcmV0dXJuIGZyb21CaXRzKGMxNiA8PCAxNiB8IGMwMCwgYzQ4IDw8IDE2IHwgYzMyLCB0aGlzLnVuc2lnbmVkKTsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS5tdWwgPSBMb25nUHJvdG90eXBlLm11bHRpcGx5OwogICAgICBMb25nUHJvdG90eXBlLmRpdmlkZSA9IGZ1bmN0aW9uIGRpdmlkZShkaXZpc29yKSB7CiAgICAgICAgaWYgKCFpc0xvbmcoZGl2aXNvcikpCiAgICAgICAgICBkaXZpc29yID0gZnJvbVZhbHVlKGRpdmlzb3IpOwogICAgICAgIGlmIChkaXZpc29yLmlzWmVybygpKQogICAgICAgICAgdGhyb3cgRXJyb3IoImRpdmlzaW9uIGJ5IHplcm8iKTsKICAgICAgICBpZiAod2FzbSkgewogICAgICAgICAgaWYgKCF0aGlzLnVuc2lnbmVkICYmIHRoaXMuaGlnaCA9PT0gLTIxNDc0ODM2NDggJiYgZGl2aXNvci5sb3cgPT09IC0xICYmIGRpdmlzb3IuaGlnaCA9PT0gLTEpIHsKICAgICAgICAgICAgcmV0dXJuIHRoaXM7CiAgICAgICAgICB9CiAgICAgICAgICB2YXIgbG93ID0gKHRoaXMudW5zaWduZWQgPyB3YXNtLmRpdl91IDogd2FzbS5kaXZfcykodGhpcy5sb3csIHRoaXMuaGlnaCwgZGl2aXNvci5sb3csIGRpdmlzb3IuaGlnaCk7CiAgICAgICAgICByZXR1cm4gZnJvbUJpdHMobG93LCB3YXNtLmdldF9oaWdoKCksIHRoaXMudW5zaWduZWQpOwogICAgICAgIH0KICAgICAgICBpZiAodGhpcy5pc1plcm8oKSkKICAgICAgICAgIHJldHVybiB0aGlzLnVuc2lnbmVkID8gVVpFUk8gOiBaRVJPOwogICAgICAgIHZhciBhcHByb3gsIHJlbSwgcmVzOwogICAgICAgIGlmICghdGhpcy51bnNpZ25lZCkgewogICAgICAgICAgaWYgKHRoaXMuZXEoTUlOX1ZBTFVFKSkgewogICAgICAgICAgICBpZiAoZGl2aXNvci5lcShPTkUpIHx8IGRpdmlzb3IuZXEoTkVHX09ORSkpCiAgICAgICAgICAgICAgcmV0dXJuIE1JTl9WQUxVRTsKICAgICAgICAgICAgZWxzZSBpZiAoZGl2aXNvci5lcShNSU5fVkFMVUUpKQogICAgICAgICAgICAgIHJldHVybiBPTkU7CiAgICAgICAgICAgIGVsc2UgewogICAgICAgICAgICAgIHZhciBoYWxmVGhpcyA9IHRoaXMuc2hyKDEpOwogICAgICAgICAgICAgIGFwcHJveCA9IGhhbGZUaGlzLmRpdihkaXZpc29yKS5zaGwoMSk7CiAgICAgICAgICAgICAgaWYgKGFwcHJveC5lcShaRVJPKSkgewogICAgICAgICAgICAgICAgcmV0dXJuIGRpdmlzb3IuaXNOZWdhdGl2ZSgpID8gT05FIDogTkVHX09ORTsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgcmVtID0gdGhpcy5zdWIoZGl2aXNvci5tdWwoYXBwcm94KSk7CiAgICAgICAgICAgICAgICByZXMgPSBhcHByb3guYWRkKHJlbS5kaXYoZGl2aXNvcikpOwogICAgICAgICAgICAgICAgcmV0dXJuIHJlczsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSBpZiAoZGl2aXNvci5lcShNSU5fVkFMVUUpKQogICAgICAgICAgICByZXR1cm4gdGhpcy51bnNpZ25lZCA/IFVaRVJPIDogWkVSTzsKICAgICAgICAgIGlmICh0aGlzLmlzTmVnYXRpdmUoKSkgewogICAgICAgICAgICBpZiAoZGl2aXNvci5pc05lZ2F0aXZlKCkpCiAgICAgICAgICAgICAgcmV0dXJuIHRoaXMubmVnKCkuZGl2KGRpdmlzb3IubmVnKCkpOwogICAgICAgICAgICByZXR1cm4gdGhpcy5uZWcoKS5kaXYoZGl2aXNvcikubmVnKCk7CiAgICAgICAgICB9IGVsc2UgaWYgKGRpdmlzb3IuaXNOZWdhdGl2ZSgpKQogICAgICAgICAgICByZXR1cm4gdGhpcy5kaXYoZGl2aXNvci5uZWcoKSkubmVnKCk7CiAgICAgICAgICByZXMgPSBaRVJPOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBpZiAoIWRpdmlzb3IudW5zaWduZWQpCiAgICAgICAgICAgIGRpdmlzb3IgPSBkaXZpc29yLnRvVW5zaWduZWQoKTsKICAgICAgICAgIGlmIChkaXZpc29yLmd0KHRoaXMpKQogICAgICAgICAgICByZXR1cm4gVVpFUk87CiAgICAgICAgICBpZiAoZGl2aXNvci5ndCh0aGlzLnNocnUoMSkpKQogICAgICAgICAgICByZXR1cm4gVU9ORTsKICAgICAgICAgIHJlcyA9IFVaRVJPOwogICAgICAgIH0KICAgICAgICByZW0gPSB0aGlzOwogICAgICAgIHdoaWxlIChyZW0uZ3RlKGRpdmlzb3IpKSB7CiAgICAgICAgICBhcHByb3ggPSBNYXRoLm1heCgxLCBNYXRoLmZsb29yKHJlbS50b051bWJlcigpIC8gZGl2aXNvci50b051bWJlcigpKSk7CiAgICAgICAgICB2YXIgbG9nMiA9IE1hdGguY2VpbChNYXRoLmxvZyhhcHByb3gpIC8gTWF0aC5MTjIpLCBkZWx0YSA9IGxvZzIgPD0gNDggPyAxIDogcG93X2RibCgyLCBsb2cyIC0gNDgpLCBhcHByb3hSZXMgPSBmcm9tTnVtYmVyKGFwcHJveCksIGFwcHJveFJlbSA9IGFwcHJveFJlcy5tdWwoZGl2aXNvcik7CiAgICAgICAgICB3aGlsZSAoYXBwcm94UmVtLmlzTmVnYXRpdmUoKSB8fCBhcHByb3hSZW0uZ3QocmVtKSkgewogICAgICAgICAgICBhcHBy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87CiAgICAgIExvbmdQcm90b3R5cGUubm90ID0gZnVuY3Rpb24gbm90KCkgewogICAgICAgIHJldHVybiBmcm9tQml0cyh+dGhpcy5sb3csIH50aGlzLmhpZ2gsIHRoaXMudW5zaWduZWQpOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLmFuZCA9IGZ1bmN0aW9uIGFuZChvdGhlcikgewogICAgICAgIGlmICghaXNMb25nKG90aGVyKSkKICAgICAgICAgIG90aGVyID0gZnJvbVZhbHVlKG90aGVyKTsKICAgICAgICByZXR1cm4gZnJvbUJpdHModGhpcy5sb3cgJiBvdGhlci5sb3csIHRoaXMuaGlnaCAmIG90aGVyLmhpZ2gsIHRoaXMudW5zaWduZWQpOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLm9yID0gZnVuY3Rpb24gb3Iob3RoZXIpIHsKICAgICAgICBpZiAoIWlzTG9uZyhvdGhlcikpCiAgICAgICAgICBvdGhlciA9IGZyb21WYWx1ZShvdGhlcik7CiAgICAgICAgcmV0dXJuIGZyb21CaXRzKHRoaXMubG93IHwgb3RoZXIubG93LCB0aGlzLmhpZ2ggfCBvdGhlci5oaWdoLCB0aGlzLnVuc2lnbmVkKTsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS54b3IgPSBmdW5jdGlvbiB4b3Iob3RoZXIpIHsKICAgICAgICBpZiAoIWlzTG9uZyhvdGhlcikpCiAgICAgICAgICBvdGhlciA9IGZyb21WYWx1ZShvdGhlcik7CiAgICAgICAgcmV0dXJuIGZyb21CaXRzKHRoaXMubG93IF4gb3RoZXIubG93LCB0aGlzLmhpZ2ggXiBvdGhlci5oaWdoLCB0aGlzLnVuc2lnbmVkKTsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS5zaGlmdExlZnQgPSBmdW5jdGlvbiBzaGlmdExlZnQobnVtQml0cykgewogICAgICAgIGlmIChpc0xvbmcobnVtQml0cykpCiAgICAgICAgICBudW1CaXRzID0gbnVtQml0cy50b0ludCgpOwogICAgICAgIGlmICgobnVtQml0cyAmPSA2MykgPT09IDApCiAgICAgICAgICByZXR1cm4gdGhpczsKICAgICAgICBlbHNlIGlmIChudW1CaXRzIDwgMzIpCiAgICAgICAgICByZXR1cm4gZnJvbUJpdHModGhpcy5sb3cgPDwgbnVtQml0cywgdGhpcy5oaWdoIDw8IG51bUJpdHMgfCB0aGlzLmxvdyA+Pj4gMzIgLSBudW1CaXRzLCB0aGlzLnVuc2lnbmVkKTsKICAgICAgICBlbHNlCiAgICAgICAgICByZXR1cm4gZnJvbUJpdHMoMCwgdGhpcy5sb3cgPDwgbnVtQml0cyAtIDMyLCB0aGlzLnVuc2lnbmVkKTsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS5zaGwgPSBMb25nUHJvdG90eXBlLnNoaWZ0TGVmdDsKICAgICAgTG9uZ1Byb3RvdHlwZS5zaGlmdFJpZ2h0ID0gZnVuY3Rpb24gc2hpZnRSaWdodChudW1CaXRzKSB7CiAgICAgICAgaWYgKGlzTG9uZyhudW1CaXRzKSkKICAgICAgICAgIG51bUJpdHMgPSBudW1CaXRzLnRvSW50KCk7CiAgICAgICAgaWYgKChudW1CaXRzICY9IDYzKSA9PT0gMCkKICAgICAgICAgIHJldHVybiB0aGlzOwogICAgICAgIGVsc2UgaWYgKG51bUJpdHMgPCAzMikKICAgICAgICAgIHJldHVybiBmcm9tQml0cyh0aGlzLmxvdyA+Pj4gbnVtQml0cyB8IHRoaXMuaGlnaCA8PCAzMiAtIG51bUJpdHMsIHRoaXMuaGlnaCA+PiBudW1CaXRzLCB0aGlzLnVuc2lnbmVkKTsKICAgICAgICBlbHNlCiAgICAgICAgICByZXR1cm4gZnJvbUJpdHModGhpcy5oaWdoID4+IG51bUJpdHMgLSAzMiwgdGhpcy5oaWdoID49IDAgPyAwIDogLTEsIHRoaXMudW5zaWduZWQpOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLnNociA9IExvbmdQcm90b3R5cGUuc2hpZnRSaWdodDsKICAgICAgTG9uZ1Byb3RvdHlwZS5zaGlmdFJpZ2h0VW5zaWduZWQgPSBmdW5jdGlvbiBzaGlmdFJpZ2h0VW5zaWduZWQobnVtQml0cykgewogICAgICAgIGlmIChpc0xvbmcobnVtQml0cykpCiAgICAgICAgICBudW1CaXRzID0gbnVtQml0cy50b0ludCgpOwogICAgICAgIG51bUJpdHMgJj0gNjM7CiAgICAgICAgaWYgKG51bUJpdHMgPT09IDApCiAgICAgICAgICByZXR1cm4gdGhpczsKICAgICAgICBlbHNlIHsKICAgICAgICAgIHZhciBoaWdoID0gdGhpcy5oaWdoOwogICAgICAgICAgaWYgKG51bUJpdHMgPCAzMikgewogICAgICAgICAgICB2YXIgbG93ID0gdGhpcy5sb3c7CiAgICAgICAgICAgIHJldHVybiBmcm9tQml0cyhsb3cgPj4+IG51bUJpdHMgfCBoaWdoIDw8IDMyIC0gbnVtQml0cywgaGlnaCA+Pj4gbnVtQml0cywgdGhpcy51bnNpZ25lZCk7CiAgICAgICAgICB9IGVsc2UgaWYgKG51bUJpdHMgPT09IDMyKQogICAgICAgICAgICByZXR1cm4gZnJvbUJpdHMoaGlnaCwgMCwgdGhpcy51bnNpZ25lZCk7CiAgICAgICAgICBlbHNlCiAgICAgICAgICAgIHJldHVybiBmcm9tQml0cyhoaWdoID4+PiBudW1CaXRzIC0gMzIsIDAsIHRoaXMudW5zaWduZWQpOwogICAgICAgIH0KICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS5zaHJ1ID0gTG9uZ1Byb3RvdHlwZS5zaGlmdFJpZ2h0VW5zaWduZWQ7CiAgICAgIExvbmdQcm90b3R5cGUuc2hyX3UgPSBMb25nUHJvdG90eXBlLnNoaWZ0UmlnaHRVbnNpZ25lZDsKICAgICAgTG9uZ1Byb3RvdHlwZS50b1NpZ25lZCA9IGZ1bmN0aW9uIHRvU2lnbmVkKCkgewogICAgICAgIGlmICghdGhpcy51bnNpZ25lZCkKICAgICAgICAgIHJldHVybiB0aGlzOwogICAgICAgIHJldHVybiBmcm9tQml0cyh0aGlzLmxvdywgdGhpcy5oaWdoLCBmYWxzZSk7CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUudG9VbnNpZ25lZCA9IGZ1bmN0aW9uIHRvVW5zaWduZWQoKSB7CiAgICAgICAgaWYgKHRoaXMudW5zaWduZWQpCiAgICAgICAgICByZXR1cm4gdGhpczsKICAgICAgICByZXR1cm4gZnJvbUJpdHModGhpcy5sb3csIHRoaXMuaGlnaCwgdHJ1ZSk7CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUudG9CeXRlcyA9IGZ1bmN0aW9uIHRvQnl0ZXMobGUpIHsKICAgICAgICByZXR1cm4gbGUgPyB0aGlzLnRvQnl0ZXNMRSgpIDogdGhpcy50b0J5dGVzQkUoKTsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS50b0J5dGVzTEUgPSBmdW5jdGlvbiB0b0J5dGVzTEUoKSB7CiAgICAgICAgdmFyIGhpID0gdGhpcy5oaWdoLCBsbyA9IHRoaXMubG93OwogICAgICAgIHJldHVybiBbCiAgICAgICAgICBsbyAmIDI1NSwKICAgICAgICAgIGxvID4+PiA4ICYgMjU1LAogICAgICAgICAgbG8gPj4+IDE2ICYgMjU1LAogICAgICAgICAgbG8gPj4+IDI0LAogICAgICAgICAgaGkgJiAyNTUsCiAgICAgICAgICBoaSA+Pj4gOCAmIDI1NSwKICAgICAgICAgIGhpID4+PiAxNiAmIDI1NSwKICAgICAgICAgIGhpID4+PiAyNAogICAgICAgIF07CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUudG9CeXRlc0JFID0gZnVuY3Rpb24gdG9CeXRlc0JFKCkgewogICAgICAgIHZhciBoaSA9IHRoaXMuaGlnaCwgbG8gPSB0aGlzLmxvdzsKICAgICAgICByZXR1cm4gWwogICAgICAgICAgaGkgPj4+IDI0LAogICAgICAgICAgaGkgPj4+IDE2ICYgMjU1LAogICAgICAgICAgaG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HJvdG90eXBlLnNsaWNlLmNhbGwoYXJndW1lbnRzLCAxKTsKICAgICAgICB3aGlsZSAoc291cmNlcy5sZW5ndGgpIHsKICAgICAgICAgIHZhciBzb3VyY2UgPSBzb3VyY2VzLnNoaWZ0KCk7CiAgICAgICAgICBpZiAoIXNvdXJjZSkgewogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgIH0KICAgICAgICAgIGlmICh0eXBlb2Ygc291cmNlICE9PSAib2JqZWN0IikgewogICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKHNvdXJjZSArICJtdXN0IGJlIG5vbi1vYmplY3QiKTsKICAgICAgICAgIH0KICAgICAgICAgIGZvciAodmFyIHAgaW4gc291cmNlKSB7CiAgICAgICAgICAgIGlmIChfaGFzKHNvdXJjZSwgcCkpIHsKICAgICAgICAgICAgICBvYmpbcF0gPSBzb3VyY2VbcF07CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIG9iajsKICAgICAgfTsKICAgICAgZXhwb3J0cy5zaHJpbmtCdWYgPSBmdW5jdGlvbihidWYsIHNpemUpIHsKICAgICAgICBpZiAoYnVmLmxlbmd0aCA9PT0gc2l6ZSkgewogICAgICAgICAgcmV0dXJuIGJ1ZjsKICAgICAgICB9CiAgICAgICAgaWYgKGJ1Zi5zdWJhcnJheSkgewogICAgICAgICAgcmV0dXJuIGJ1Zi5zdWJhcnJheSgwLCBzaXplKTsKICAgICAgICB9CiAgICAgICAgYnVmLmxlbmd0aCA9IHNpemU7CiAgICAgICAgcmV0dXJuIGJ1ZjsKICAgICAgfTsKICAgICAgdmFyIGZuVHlwZWQgPSB7CiAgICAgICAgYXJyYXlTZXQ6IGZ1bmN0aW9uKGRlc3QsIHNyYywgc3JjX29mZnMsIGxlbiwgZGVzdF9vZmZzKSB7CiAgICAgICAgICBpZiAoc3JjLnN1YmFycmF5ICYmIGRlc3Quc3ViYXJyYXkpIHsKICAgICAgICAgICAgZGVzdC5zZXQoc3JjLnN1YmFycmF5KHNyY19vZmZzLCBzcmNfb2ZmcyArIGxlbiksIGRlc3Rfb2Zmcyk7CiAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgIH0KICAgICAgICAgIGZvciAodmFyIGkgPSAwOyBpIDwgbGVuOyBpKyspIHsKICAgICAgICAgICAgZGVzdFtkZXN0X29mZnMgKyBpXSA9IHNyY1tzcmNfb2ZmcyArIGldOwogICAgICAgICAgfQogICAgICAgIH0sCiAgICAgICAgZmxhdHRlbkNodW5rczogZnVuY3Rpb24oY2h1bmtzKSB7CiAgICAgICAgICB2YXIgaSwgbCwgbGVuLCBwb3MsIGNodW5rLCByZXN1bHQ7CiAgICAgICAgICBsZW4gPSAwOwogICAgICAgICAgZm9yIChpID0gMCwgbCA9IGNodW5rcy5sZW5ndGg7IGkgPCBsOyBpKyspIHsKICAgICAgICAgICAgbGVuICs9IGNodW5rc1tpXS5sZW5ndGg7CiAgICAgICAgICB9CiAgICAgICAgICByZXN1bHQgPSBuZXcgVWludDhBcnJheShsZW4pOwogICAgICAgICAgcG9zID0gMDsKICAgICAgICAgIGZvciAoaSA9IDAsIGwgPSBjaHVua3MubGVuZ3RoOyBpIDwgbDsgaSsrKSB7CiAgICAgICAgICAgIGNodW5rID0gY2h1bmtzW2ldOwogICAgICAgICAgICByZXN1bHQuc2V0KGNodW5rLCBwb3MpOwogICAgICAgICAgICBwb3MgKz0gY2h1bmsubGVuZ3RoOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIHJlc3VsdDsKICAgICAgICB9CiAgICAgIH07CiAgICAgIHZhciBmblVudHlwZWQgPSB7CiAgICAgICAgYXJyYXlTZXQ6IGZ1bmN0aW9uKGRlc3QsIHNyYywgc3JjX29mZnMsIGxlbiwgZGVzdF9vZmZzKSB7CiAgICAgICAgICBmb3IgKHZhciBpID0gMDsgaSA8IGxlbjsgaSsrKSB7CiAgICAgICAgICAgIGRlc3RbZGVzdF9vZmZzICsgaV0gPSBzcmNbc3JjX29mZnMgKyBpXTsKICAgICAgICAgIH0KICAgICAgICB9LAogICAgICAgIGZsYXR0ZW5DaHVua3M6IGZ1bmN0aW9uKGNodW5rcykgewogICAgICAgICAgcmV0dXJuIFtdLmNvbmNhdC5hcHBseShbXSwgY2h1bmtzKTsKICAgICAgICB9CiAgICAgIH07CiAgICAgIGV4cG9ydHMuc2V0VHlwZWQgPSBmdW5jdGlvbihvbikgewogICAgICAgIGlmIChvbikgewogICAgICAgICAgZXhwb3J0cy5CdWY4ID0gVWludDhBcnJheTsKICAgICAgICAgIGV4cG9ydHMuQnVmMTYgPSBVaW50MTZBcnJheTsKICAgICAgICAgIGV4cG9ydHMuQnVmMzIgPSBJbnQzMkFycmF5OwogICAgICAgICAgZXhwb3J0cy5hc3NpZ24oZXhwb3J0cywgZm5UeXBlZCk7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIGV4cG9ydHMuQnVmOCA9IEFycmF5OwogICAgICAgICAgZXhwb3J0cy5CdWYxNiA9IEFycmF5OwogICAgICAgICAgZXhwb3J0cy5CdWYzMiA9IEFycmF5OwogICAgICAgICAgZXhwb3J0cy5hc3NpZ24oZXhwb3J0cywgZm5VbnR5cGVkKTsKICAgICAgICB9CiAgICAgIH07CiAgICAgIGV4cG9ydHMuc2V0VHlwZWQoVFlQRURfT0spOwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvdHJlZXMuanMKICB2YXIgcmVxdWlyZV90cmVlcyA9IF9fY29tbW9uSlMoewogICAgIm5vZGVfbW9kdWxlcy8ucG5wbS9wYWtvQDEuMC4xMS9ub2RlX21vZHVsZXMvcGFrby9saWIvemxpYi90cmVlcy5qcyIoZXhwb3J0cykgewogICAgICBpbml0X2J1ZmZlcl9zaGltKCk7CiAgICAgICJ1c2Ugc3RyaWN0IjsKICAgICAgdmFyIHV0aWxzID0gcmVxdWlyZV9jb21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UsIGxlbmd0aCkgewogICAgICAgIGlmIChzLmJpX3ZhbGlkID4gQnVmX3NpemUgLSBsZW5ndGgpIHsKICAgICAgICAgIHMuYmlfYnVmIHw9IHZhbHVlIDw8IHMuYmlfdmFsaWQgJiA2NTUzNTsKICAgICAgICAgIHB1dF9zaG9ydChzLCBzLmJpX2J1Zik7CiAgICAgICAgICBzLmJpX2J1ZiA9IHZhbHVlID4+IEJ1Zl9zaXplIC0gcy5iaV92YWxpZDsKICAgICAgICAgIHMuYmlfdmFsaWQgKz0gbGVuZ3RoIC0gQnVmX3NpemU7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIHMuYmlfYnVmIHw9IHZhbHVlIDw8IHMuYmlfdmFsaWQgJiA2NTUzNTsKICAgICAgICAgIHMuYmlfdmFsaWQgKz0gbGVuZ3RoOwogICAgICAgIH0KICAgICAgfQogICAgICBmdW5jdGlvbiBzZW5kX2NvZGUocywgYywgdHJlZSkgewogICAgICAgIHNlbmRfYml0cyhzLCB0cmVlW2MgKiAyXSwgdHJlZVtjICogMiArIDFdKTsKICAgICAgfQogICAgICBmdW5jdGlvbiBiaV9yZXZlcnNlKGNvZGUsIGxlbikgewogICAgICAgIHZhciByZXMgPSAwOwogICAgICAgIGRvIHsKICAgICAgICAgIHJlcyB8PSBjb2RlICYgMTsKICAgICAgICAgIGNvZGUgPj4+PSAxOwogICAgICAgICAgcmVzIDw8PSAxOwogICAgICAgIH0gd2hpbGUgKC0tbGVuID4gMCk7CiAgICAgICAgcmV0dXJuIHJlcyA+Pj4gMTsKICAgICAgfQogICAgICBmdW5jdGlvbiBiaV9mbHVzaChzKSB7CiAgICAgICAgaWYgKHMuYmlfdmFsaWQgPT09IDE2KSB7CiAgICAgICAgICBwdXRfc2hvcnQocywgcy5iaV9idWYpOwogICAgICAgICAgcy5iaV9idWYgPSAwOwogICAgICAgICAgcy5iaV92YWxpZCA9IDA7CiAgICAgICAgfSBlbHNlIGlmIChzLmJpX3ZhbGlkID49IDgpIHsKICAgICAgICAgIHMucGVuZGluZ19idWZbcy5wZW5kaW5nKytdID0gcy5iaV9idWYgJiAyNTU7CiAgICAgICAgICBzLmJpX2J1ZiA+Pj0gODsKICAgICAgICAgIHMuYmlfdmFsaWQgLT0gODsKICAgICAgICB9CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZ2VuX2JpdGxlbihzLCBkZXNjKSB7CiAgICAgICAgdmFyIHRyZWUgPSBkZXNjLmR5bl90cmVlOwogICAgICAgIHZhciBtYXhfY29kZSA9IGRlc2MubWF4X2NvZGU7CiAgICAgICAgdmFyIHN0cmVlID0gZGVzYy5zdGF0X2Rlc2Muc3RhdGljX3RyZWU7CiAgICAgICAgdmFyIGhhc19zdHJlZSA9IGRlc2Muc3RhdF9kZXNjLmhhc19zdHJlZTsKICAgICAgICB2YXIgZXh0cmEgPSBkZXNjLnN0YXRfZGVzYy5leHRyYV9iaXRzOwogICAgICAgIHZhciBiYXNlID0gZGVzYy5zdGF0X2Rlc2MuZXh0cmFfYmFzZTsKICAgICAgICB2YXIgbWF4X2xlbmd0aCA9IGRlc2Muc3RhdF9kZXNjLm1heF9sZW5ndGg7CiAgICAgICAgdmFyIGg7CiAgICAgICAgdmFyIG4sIG07CiAgICAgICAgdmFyIGJpdHM7CiAgICAgICAgdmFyIHhiaXRzOwogICAgICAgIHZhciBmOwogICAgICAgIHZhciBvdmVyZmxvdyA9IDA7CiAgICAgICAgZm9yIChiaXRzID0gMDsgYml0cyA8PSBNQVhfQklUUzsgYml0cysrKSB7CiAgICAgICAgICBzLmJsX2NvdW50W2JpdHNdID0gMDsKICAgICAgICB9CiAgICAgICAgdHJlZVtzLmhlYXBbcy5oZWFwX21heF0gKiAyICsgMV0gPSAwOwogICAgICAgIGZvciAoaCA9IHMuaGVhcF9tYXggKyAxOyBoIDwgSEVBUF9TSVpFOyBoKyspIHsKICAgICAgICAgIG4gPSBzLmhlYXBbaF07CiAgICAgICAgICBiaXRzID0gdHJlZVt0cmVlW24gKiAyICsgMV0gKiAyICsgMV0gKyAxOwogICAgICAgICAgaWYgKGJpdHMgPiBtYXhfbGVuZ3RoKSB7CiAgICAgICAgICAgIGJpdHMgPSBtYXhfbGVuZ3RoOwogICAgICAgICAgICBvdmVyZmxvdysrOwogICAgICAgICAgfQogICAgICAgICAgdHJlZVtuICogMiArIDFdID0gYml0czsKICAgICAgICAgIGlmIChuID4gbWF4X2NvZGUpIHsKICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICB9CiAgICAgICAgICBzLmJsX2NvdW50W2JpdHNdKys7CiAgICAgICAgICB4Yml0cyA9IDA7CiAgICAgICAgICBpZiAobiA+PSBiYXNlKSB7CiAgICAgICAgICAgIHhiaXRzID0gZXh0cmFbbiAtIGJhc2VdOwogICAgICAgICAgfQogICAgICAgICAgZiA9IHRyZWVbbiAqIDJdOwogICAgICAgICAgcy5vcHRfbGVuICs9IGYgKiAoYml0cyArIHhiaXRzKTsKICAgICAgICAgIGlmIChoYXNfc3RyZWUpIHsKICAgICAgICAgICAgcy5zdGF0aWNfbGVuICs9IGYgKiAoc3RyZWVbbiAqIDIgKyAxXSArIHhiaXRzKTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKG92ZXJmbG93ID09PSAwKSB7CiAgICAgICAgICByZXR1cm47CiAgICAgICAgfQogICAgICAgIGRvIHsKICAgICAgICAgIGJpdHMgPSBtYXhfbGVuZ3RoIC0gMTsKICAgICAgICAgIHdoaWxlIChzLmJsX2NvdW50W2JpdHNdID09PSAwKSB7CiAgICAgICAgICAgIGJpdHMtLTsKICAgICAgICAgIH0KICAgICAgICAgIHMuYmxfY291bnRbYml0c10tLTsKICAgICAgICAgIHMuYmxfY291bnRbYml0cyArIDFdICs9IDI7CiAgICAgICAgICBzLmJsX2NvdW50W21heF9sZW5ndGhdLS07CiAgICAgICAgICBvdmVyZmxvdyAtPSAyOwogICAgICAgIH0gd2hpbGUgKG92ZXJmbG93ID4gMCk7CiAgICAgICAgZm9yIChiaXRzID0gbWF4X2xlbmd0aDsgYml0cyAhPT0gMDsgYml0cy0tKSB7CiAgICAgICAgICBuID0gcy5ibF9jb3VudFtiaXRzXTsKICAgICAgICAgIHdoaWxlIChuICE9PSAwKSB7CiAgICAgICAgICAgIG0gPSBzLmhlYXBbLS1oXTsKICAgICAgICAgICAgaWYgKG0gPiBtYXhfY29kZSkgewogICAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmICh0cmVlW20gKiAyICsgMV0gIT09IGJpdHMpIHsKICAgICAgICAgICAgICBzLm9wdF9sZW4gKz0gKGJpdHMgLSB0cmVlW20gKiAyICsgMV0pICogdHJlZVttICogMl07CiAgICAgICAgICAgICAgdHJlZVttICogMiArIDFdID0gYml0czsKICAgICAgICAgICAgfQogICAgICAgICAgICBuLS07CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9CiAgICAgIGZ1bmN0aW9uIGdlbl9jb2Rlcyh0cmVlLCBtYXhfY29kZSwgYmxfY291bnQpIHsKICAgICAgICB2YXIgbmV4dF9jb2RlID0gbmV3IEFycmF5KE1BWF9CSVRTICsgMSk7CiAgICAgICAgdmFyIGNvZGUgPSAwOwogICAgICAgIHZhciBiaXRzOwogICAgICAgIHZhciBuOwogICAgICAgIGZvciAoYml0cyA9IDE7IGJpdHMgPD0gTUFYX0JJVFM7IGJpdHMrKykgewogICAgICAgICAgbmV4dF9jb2RlW2JpdHNdID0gY29kZSA9IGNvZGUgKyBibF9jb3VudFtiaXRzIC0gMV0gPDwgMTsKICAgICAgICB9CiAgICAgICAgZm9yIChuID0gMDsgbiA8PSBtYXhfY29kZTsgbisrKSB7CiAgICAgICAgICB2YXIgbGVuID0gdHJlZVtuICogMiArIDFdOwogICAgICAgICAgaWYgKGxlbiA9PT0gMCkgewogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgIH0KICAgICAgICAgIHRyZWVbbiAqIDJdID0gYmlfcmV2ZXJzZShuZXh0X2NvZGVbbGVuXSsrLCBsZW4pOwogICAgICAgIH0KICAgICAgfQogICAgICBmdW5jdGlvbiB0cl9zdGF0aWNfaW5pdCgpIHsKICAgICAgICB2YXIgbjsKICAgICAgICB2YXIgYml0czsKICAgICAgICB2YXIgbGVuZ3RoOwogICAgICAgIHZhciBjb2RlOwogICAgICAgIHZhciBkaXN0OwogICAgICAgIHZhciBibF9jb3VudCA9IG5ldyBBcnJheShNQVhfQklUUyArIDEpOwogICAgICAgIGxlbmd0aCA9IDA7CiAgICAgICAgZm9yIChjb2RlID0gMDsgY29kZSA8IExFTkdUSF9DT0RFUyAtIDE7IGNvZGUrKykgewogICAgICAgICAgYmFzZV9sZW5ndGhbY29kZV0gPSBsZW5ndGg7CiAgICAgICAgICBmb3IgKG4gPSAwOyBuIDwgMSA8PCBleHRyYV9sYml0c1tjb2RlXTsgbisrKSB7CiAgICAgICAgICAgIF9sZW5ndGhfY29kZVtsZW5ndGgrK10gPSBjb2RlOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBfbGVuZ3RoX2NvZGVbbGVuZ3RoIC0gMV0gPSBjb2RlOwogICAgICAgIGRpc3QgPSAwOwogICAgICAgIGZvciAoY29kZSA9IDA7IGNvZGUgPCAxNjsgY29kZSsrKSB7CiAgICAgICAgICBiYXNlX2Rpc3RbY29kZV0gPSBkaXN0OwogICAgICAgICAgZm9yIChuID0gMDsgbiA8IDEgPDwgZXh0cmFfZGJpdHNbY29kZV07IG4rKykgewogICAgICAgICAgICBfZGlzdF9jb2RlW2Rpc3QrK10gPSBjb2RlOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBkaXN0ID4+PSA3OwogICAgICAgIGZvciAoOyBjb2RlIDwgRF9DT0RFUzsgY29kZSsrKSB7CiAgICAgICAgICBiYXNlX2Rpc3RbY29kZV0gPSBkaXN0IDw8IDc7CiAgICAgICAgICBmb3IgKG4gPSAwOyBuIDwgMSA8PCBleHRyYV9kYml0c1tjb2RlXSAtIDc7IG4rKykgewogICAgICAgICAgICBfZGlzdF9jb2RlWzI1NiArIGRpc3QrK10gPSBjb2RlOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBmb3IgKGJpdHMgPSAwOyBiaXRzIDw9IE1BWF9CSVRTOyBiaXRzKyspIHsKICAgICAgICAgIGJsX2NvdW50W2JpdHNdID0gMDsKICAgICAgICB9CiAgICAgICAgbiA9IDA7CiAgICAgICAgd2hpbGUgKG4gPD0gMTQzKSB7CiAgICAgICAgICBzdGF0aWNfbHRyZWVbbiAqIDIgKyAxXSA9IDg7CiAgICAgICAgICBuKys7CiAgICAgICAgICBibF9jb3VudFs4XSsrOwogICAgICAgIH0KICAgICAgICB3aGlsZSAobiA8PSAyNTUpIHsKICAgICAgICAgIHN0YXRpY19sdHJlZVtuICogMiArIDFdID0gOTsKICAgICAgICAgIG4rKzsKICAgICAgICAgIGJsX2NvdW50WzldKys7CiAgICAgICAgfQogICAgICAgIHdoaWxlIChuIDw9IDI3OSkgewogICAgICAgICAgc3RhdGljX2x0cmVlW24gKiAyICsgMV0gPSA3OwogICAgICAgICAgbisrOwogICAgICAgICAgYmxfY291bnRbN10rKzsKICAgICAgICB9CiAgICAgICAgd2hpbGUgKG4gPD0gMjg3KSB7CiAgICAgICAgICBzdGF0aWNfbHRyZWVbbiAqIDIgKyAxXSA9IDg7CiAgICAgICAgICBuKys7CiAgICAgICAgICBibF9jb3VudFs4XSsrOwogICAgICAgIH0KICAgICAgICBnZW5fY29kZXMoc3RhdGljX2x0cmVlLCBMX0NPREVTICsgMSwgYmxfY291bnQpOwogICAgICAgIGZvciAobiA9IDA7IG4gPCBEX0NPREVTOyBuKyspIHsKICAgICAgICAgIHN0YXRpY19kdHJlZVtuICogMiArIDFdID0gNTsKICAgICAgICAgIHN0YXRpY19kdHJlZVtuICogMl0gPSBiaV9yZXZlcnNlKG4sIDUpOwogICAgICAgIH0KICAgICAgICBzdGF0aWNfbF9kZXNjID0gbmV3IFN0YXRpY1RyZWVEZXNjKHN0YXRpY19sdHJlZSwgZXh0cmFfbGJpdHMsIExJVEVSQUxTICsgMSwgTF9DT0RFUywgTUFYX0JJVFMpOwogICAgICAgIHN0YXRpY19kX2Rlc2MgPSBuZXcgU3RhdGljVHJlZURlc2Moc3RhdGljX2R0cmVlLCBleHRyYV9kYml0cywgMCwgRF9DT0RFUywgTUFYX0JJVFMpOwogICAgICAgIHN0YXRpY19ibF9kZXNjID0gbmV3IFN0YXRpY1RyZWVEZXNjKG5ldyBBcnJheSgwKSwgZXh0cmFfYmxiaXRzLCAwLCBCTF9DT0RFUywgTUFYX0JMX0JJVFMpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGluaXRfYmxvY2socykgewogICAgICAgIHZhciBuOwogICAgICAgIGZvciAobiA9IDA7IG4gPCBMX0NPREVTOyBuKyspIHsKICAgICAgICAgIHMuZHluX2x0cmVlW24gKiAyXSA9IDA7CiAgICAgICAgfQogICAgICAgIGZvciAobiA9IDA7IG4gPCBEX0NPREVTOyBuKyspIHsKICAgICAgICAgIHMuZHluX2R0cmVlW24gKiAyXSA9IDA7CiAgICAgICAgfQogICAgICAgIGZvciAobiA9IDA7IG4gPCBCTF9DT0RFUzsgbisrKSB7CiAgICAgICAgICBzLmJsX3RyZWVbbiAqIDJdID0gMDsKICAgICAgICB9CiAgICAgICAgcy5keW5fbHRyZWVbRU5EX0JMT0NLICogMl0gPSAxOwogICAgICAgIHMub3B0X2xlbiA9IHMuc3RhdGljX2xlbiA9IDA7CiAgICAgICAgcy5sYXN0X2xpdCA9IHMubWF0Y2hlcyA9IDA7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gYmlfd2luZHVwKHMpIHsKICAgICAgICBpZiAocy5iaV92YWxpZCA+IDgpIHsKICAgICAgICAgIHB1dF9zaG9ydChzLCBzLmJpX2J1Zik7CiAgICAgICAgfSBlbHNlIGlmIChzLmJpX3ZhbGlkID4gMCkgewogICAgICAgICAgcy5wZW5kaW5nX2J1ZltzLnBlbmRpbmcrK10gPSBzLmJpX2J1ZjsKICAgICAgICB9CiAgICAgICAgcy5iaV9idWYgPSAwOwogICAgICAgIHMuYmlfdmFsaWQgPSAwOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGNvcHlfYmxvY2socywgYnVmLCBsZW4sIGhlYWRlcikgewogICAgICAgIGJpX3dpbmR1cChzKTsKICAgICAgICBpZiAoaGVhZGVyKSB7CiAgICAgICAgICBwdXRfc2hvcnQocywgbGVuKTsKICAgICAgICAgIHB1dF9zaG9ydChzLCB+bGVuKTsKICAgICAgICB9CiAgICAgICAgdXRpbHMuYXJyYXlTZXQocy5wZW5kaW5nX2J1Ziwgcy53aW5kb3csIGJ1ZiwgbGVuLCBzLnBlbmRpbmcpOwogICAgICAgIHMucGVuZGluZyArPSBsZW47CiAgICAgIH0KICAgICAgZnVuY3Rpb24gc21hbGxlcih0cmVlLCBuLCBtLCBkZXB0aCkgewogICAgICAgIHZhciBfbjIgPSBuICogMjsKICAgICAgICB2YXIgX20yID0gbSAqIDI7CiAgICAgICAgcmV0dXJuIHRyZWVbX24yXSA8IHRyZWVbX20yXSB8fCB0cmVlW19uMl0gPT09IHRyZWVbX20yXSAmJiBkZXB0aFtuXSA8PSBkZXB0aFttXTsKICAgICAgfQogICAgICBmdW5jdGlvbiBwcWRvd25oZWFwKHMsIHRyZWUsIGspIHsKICAgICAgICB2YXIgdiA9IHMuaGVhcFtrXTsKICAgICAgICB2YXIgaiA9IGsgPDwgMTsKICAgICAgICB3aGlsZSAoaiA8PSBzLmhlYXBfbGVuKSB7CiAgICAgICAgICBpZiAoaiA8IHMuaGVhcF9sZW4gJiYgc21hbGxlcih0cmVlLCBzLmhlYXBbaiArIDFdLCBzLmhlYXBbal0sIHMuZGVwdGgpKSB7CiAgICAgICAgICAgIGorKzsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChzbWFsbGVyKHRyZWUsIHYsIHMuaGVhcFtqXSwgcy5kZXB0aCkpIHsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICB9CiAgICAgICAgICBzLmhlYXBba10gPSBzLmhlYXBbal07CiAgICAgICAgICBrID0gajsKICAgICAgICAgIGogPDw9IDE7CiAgICAgICAgfQogICAgICAgIHMuaGVhcFtrXSA9IHY7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gY29tcHJlc3NfYmxvY2socywgbHRyZWUsIGR0cmVlKSB7CiAgICAgICAgdmFyIGRpc3Q7CiAgICAgICAgdmFyIGxjOwogICAgICAgIHZhciBseCA9IDA7CiAgICAgICAgdmFyIGNvZGU7CiAgICAgICAgdmFyIGV4dHJhOwogICAgICAgIGlmIChzLmxhc3RfbGl0ICE9PSAwKSB7CiAgICAgICAgICBkbyB7CiAgICAgICAgICAgIGRpc3QgPSBzLnBlbmRpbmdfYnVmW3MuZF9idWYgKyBseCAqIDJdIDw8IDggfCBzLnBlbmRpbmdfYnVmW3MuZF9idWYgKyBseCAqIDIgKyAxXTsKICAgICAgICAgICAgbGMgPSBzLnBlbmRpbmdfYnVmW3MubF9idWYgKyBseF07CiAgICAgICAgICAgIGx4Kys7CiAgICAgICAgICAgIGlmIChkaXN0ID09PSAwKSB7CiAgICAgICAgICAgICAgc2VuZF9jb2RlKHMsIGxjLCBsdHJlZSk7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgY29kZSA9IF9sZW5ndGhfY29kZVtsY107CiAgICAgICAgICAgICAgc2VuZF9jb2RlKHMsIGNvZGUgKyBMSVRFUkFMUyArIDEsIGx0cmVlKTsKICAgICAgICAgICAgICBleHRyYSA9IGV4dHJhX2xiaXRzW2NvZGVdOwogICAgICAgICAgICAgIGlmIChleHRyYSAhPT0gMCkgewogICAgICAgICAgICAgICAgbGMgLT0gYmFzZV9sZW5ndGhbY29kZV07CiAgICAgICAgICAgICAgICBzZW5kX2JpdHMocywgbGMsIGV4dHJhKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgZGlzdC0tOwogICAgICAgICAgICAgIGNvZGUgPSBkX2NvZGUoZGlzdCk7CiAgICAgICAgICAgICAgc2VuZF9jb2RlKHMsIGNvZGUsIGR0cmVlKTsKICAgICAgICAgICAgICBleHRyYSA9IGV4dHJhX2RiaXRzW2NvZGVdOwogICAgICAgICAgICAgIGlmIChleHRyYSAhPT0gMCkgewogICAgICAgICAgICAgICAgZGlzdCAtPSBiYXNlX2Rpc3RbY29kZV07CiAgICAgICAgICAgICAgICBzZW5kX2JpdHMocywgZGlzdCwgZXh0cmEpOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgfSB3aGlsZSAobHggPCBzLmxhc3RfbGl0KTsKICAgICAgICB9CiAgICAgICAgc2VuZF9jb2RlKHMsIEVORF9CTE9DSywgbHRyZWUpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGJ1aWxkX3RyZWUocywgZGVzYykgewogICAgICAgIHZhciB0cmVlID0gZGVzYy5keW5fdHJlZTsKICAgICAgICB2YXIgc3RyZWUgPSBkZXNjLnN0YXRfZGVzYy5zdGF0aWNfdHJlZTsKICAgICAgICB2YXIgaGFzX3N0cmVlID0gZGVzYy5zdGF0X2Rlc2MuaGFzX3N0cmVlOwogICAgICAgIHZhciBlbGVtcyA9IGRlc2Muc3RhdF9kZXNjLmVsZW1zOwogICAgICAgIHZhciBuLCBtOwogICAgICAgIHZhciBtYXhfY29kZSA9IC0xOwogICAgICAgIHZhciBub2RlOwogICAgICAgIHMuaGVhcF9sZW4gPSAwOwogICAgICAgIHMuaGVhcF9tYXggPSBIRUFQX1NJWkU7CiAgICAgICAgZm9yIChuID0gMDsgbiA8IGVsZW1zOyBuKyspIHsKICAgICAgICAgIGlmICh0cmVlW24gKiAyXSAhPT0gMCkgewogICAgICAgICAgICBzLmhlYXBbKytzLmhlYXBfbGVuXSA9IG1heF9jb2RlID0gbjsKICAgICAgICAgICAgcy5kZXB0aFtuXSA9IDA7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICB0cmVlW24gKiAyICsgMV0gPSAwOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICB3aGlsZSAocy5oZWFwX2xlbiA8IDIpIHsKICAgICAgICAgIG5vZGUgPSBzLmhlYXBbKytzLmhlYXBfbGVuXSA9IG1heF9jb2RlIDwgMiA/ICsrbWF4X2NvZGUgOiAwOwogICAgICAgICAgdHJlZVtub2RlICogMl0gPSAxOwogICAgICAgICAgcy5kZXB0aFtub2RlXSA9IDA7CiAgICAgICAgICBzLm9wdF9sZW4tLTsKICAgICAgICAgIGlmIChoYXNfc3RyZWUpIHsKICAgICAgICAgICAgcy5zdGF0aWNfbGVuIC09IHN0cmVlW25vZGUgKiAyICsgMV07CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGRlc2MubWF4X2NvZGUgPSBtYXhfY29kZTsKICAgICAgICBmb3IgKG4gPSBzLmhlYXBfbGVuID4+IDE7IG4gPj0gMTsgbi0tKSB7CiAgICAgICAgICBwcWRvd25oZWFwKHMsIHRyZWUsIG4pOwogICAgICAgIH0KICAgICAgICBub2RlID0gZWxlbXM7CiAgICAgICAgZG8gewogICAgICAgICAgbiA9IHMuaGVhcFsxXTsKICAgICAgICAgIHMuaGVhcFsxXSA9IHMuaGVhcFtzLmhlYXBfbGVuLS1dOwogICAgICAgICAgcHFkb3duaGVhcChzLCB0cmVlLCAxKTsKICAgICAgICAgIG0gPSBzLmhlYXBbMV07CiAgICAgICAgICBzLmhlYXBbLS1zLmhlYXBfbWF4XSA9IG47CiAgICAgICAgICBzLmhlYXBbLS1zLmhlYXBfbWF4XSA9IG07CiAgICAgICAgICB0cmVlW25vZGUgKiAyXSA9IHRyZWVbbiAqIDJdICsgdHJlZVttICogMl07CiAgICAgICAgICBzLmRlcHRoW25vZGVdID0gKHMuZGVwdGhbbl0gPj0gcy5kZXB0aFttXSA/IHMuZGVwdGhbbl0gOiBzLmRlcHRoW21dKSArIDE7CiAgICAgICAgICB0cmVlW24gKiAyICsgMV0gPSB0cmVlW20gKiAyICsgMV0gPSBub2RlOwogICAgICAgICAgcy5oZWFwWzFdID0gbm9kZSsrOwogICAgICAgICAgcHFkb3duaGVhcChzLCB0cmVlLCAxKTsKICAgICAgICB9IHdoaWxlIChzLmhlYXBfbGVuID49IDIpOwogICAgICAgIHMuaGVhcFstLXMuaGVhcF9tYXhdID0gcy5oZWFwWzFdOwogICAgICAgIGdlbl9iaXRsZW4ocywgZGVzYyk7CiAgICAgICAgZ2VuX2NvZGVzKHRyZWUsIG1heF9jb2RlLCBzLmJsX2NvdW50KTsKICAgICAgfQogICAgICBmdW5jdGlvbiBzY2FuX3RyZWUocywgdHJlZSwgbWF4X2NvZGUpIHsKICAgICAgICB2YXIgbjsKICAgICAgICB2YXIgcHJldmxlbiA9IC0xOwogICAgICAgIHZhciBjdXJsZW47CiAgICAgICAgdmFyIG5leHRsZW4gPSB0cmVlWzAgKiAyICsgMV07CiAgICAgICAgdmFyIGNvdW50ID0gMDsKICAgICAgICB2YXIgbWF4X2NvdW50ID0gNzsKICAgICAgICB2YXIgbWluX2NvdW50ID0gNDsKICAgICAgICBpZiAobmV4dGxlbiA9PT0gMCkgewogICAgICAgICAgbWF4X2NvdW50ID0gMTM4OwogICAgICAgICAgbWluX2NvdW50ID0gMzsKICAgICAgICB9CiAgICAgICAgdHJlZVsobWF4X2NvZGUgKyAxKSAqIDIgKyAxXSA9IDY1NTM1OwogICAgICAgIGZvciAobiA9IDA7IG4gPD0gbWF4X2NvZGU7IG4rKykgewogICAgICAgICAgY3VybGVuID0gbmV4dGxlbjsKICAgICAgICAgIG5leHRsZW4gPSB0cmVlWyhuICsgMSkgKiAyICsgMV07CiAgICAgICAgICBpZiAoKytjb3VudCA8IG1heF9jb3VudCAmJiBjdXJsZW4gPT09IG5leHRsZW4pIHsKICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICB9IGVsc2UgaWYgKGNvdW50IDwgbWluX2NvdW50KSB7CiAgICAgICAgICAgIHMuYmxfdHJlZVtjdXJsZW4gKiAyXSArPSBjb3VudDsKICAgICAgICAgIH0gZWxzZSBpZiAoY3VybGVuICE9PSAwKSB7CiAgICAgICAgICAgIGlmIChjdXJsZW4gIT09IHByZXZsZW4pIHsKICAgICAgICAgICAgICBzLmJsX3RyZWVbY3VybGVuICogMl0rKzsKICAgICAgICAgICAgfQogICAgICAgICAgICBzLmJsX3RyZWVbUkVQXzNfNiAqIDJdKys7CiAgICAgICAgICB9IGVsc2UgaWYgKGNvdW50IDw9IDEwKSB7CiAgICAgICAgICAgIHMuYmxfdHJlZVtSRVBaXzNfMTAgKiAyXSsrOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcy5ibF90cmVlW1JFUFpfMTFfMTM4ICogMl0rKzsKICAgICAgICAgIH0KICAgICAgICAgIGNvdW50ID0gMDsKICAgICAgICAgIHByZXZsZW4gPSBjdXJsZW47CiAgICAgICAgICBpZiAobmV4dGxlbiA9PT0gMCkgewogICAgICAgICAgICBtYXhfY291bnQgPSAxMzg7CiAgICAgICAgICAgIG1pbl9jb3VudCA9IDM7CiAgICAgICAgICB9IGVsc2UgaWYgKGN1cmxlbiA9PT0gbmV4dGxlbikgewogICAgICAgICAgICBtYXhfY291bnQgPSA2OwogICAgICAgICAgICBtaW5fY291bnQgPSAzOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgbWF4X2NvdW50ID0gNzsKICAgICAgICAgICAgbWluX2NvdW50ID0gNDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgICAgZnVuY3Rpb24gc2VuZF90cmVlKHMsIHRyZWUsIG1heF9jb2RlKSB7CiAgICAgICAgdmFyIG47CiAgICAgICAgdmFyIHByZXZsZW4gPSAtMTsKICAgICAgICB2YXIgY3VybGVuOwogICAgICAgIHZhciBuZXh0bGVuID0gdHJlZVswICogMiArIDFdOwogICAgICAgIHZhciBjb3VudCA9IDA7CiAgICAgICAgdmFyIG1heF9jb3VudCA9IDc7CiAgICAgICAgdmFyIG1pbl9jb3VudCA9IDQ7CiAgICAgICAgaWYgKG5leHRsZW4gPT09IDApIHsKICAgICAgICAgIG1heF9jb3VudCA9IDEzODsKICAgICAgICAgIG1pbl9jb3VudCA9IDM7CiAgICAgICAgfQogICAgICAgIGZvciAobiA9IDA7IG4gPD0gbWF4X2NvZGU7IG4rKykgewogICAgICAgICAgY3VybGVuID0gbmV4dGxlbjsKICAgICAgICAgIG5leHRsZW4gPSB0cmVlWyhuICsgMSkgKiAyICsgMV07CiAgICAgICAgICBpZiAoKytjb3VudCA8IG1heF9jb3VudCAmJiBjdXJsZW4gPT09IG5leHRsZW4pIHsKICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICB9IGVsc2UgaWYgKGNvdW50IDwgbWluX2NvdW50KSB7CiAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICBzZW5kX2NvZGUocywgY3VybGVuLCBzLmJsX3RyZWUpOwogICAgICAgICAgICB9IHdoaWxlICgtLWNvdW50ICE9PSAwKTsKICAgICAgICAgIH0gZWxzZSBpZiAoY3VybGVuICE9PSAwKSB7CiAgICAgICAgICAgIGlmIChjdXJsZW4gIT09IHByZXZsZW4pIHsKICAgICAgICAgICAgICBzZW5kX2NvZGUocywgY3VybGVuLCBzLmJsX3RyZWUpOwogICAgICAgICAgICAgIGNvdW50LS07CiAgICAgICAgICAgIH0KICAgICAgICAgICAgc2VuZF9jb2RlKHMsIFJFUF8zXzYsIHMuYmxfdHJlZSk7CiAgICAgICAgICAgIHNlbmRfYml0cyhzLCBjb3VudCAtIDMsIDIpOwogICAgICAgICAgfSBlbHNlIGlmIChjb3VudCA8PSAxMCkgewogICAgICAgICAgICBzZW5kX2NvZGUocywgUkVQWl8zXzEwLCBzLmJsX3RyZWUpOwogICAgICAgICAgICBzZW5kX2JpdHMocywgY291bnQgLSAzLCAzKTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHNlbmRfY29kZShzLCBSRVBaXzExXzEzOCwgcy5ibF90cmVlKTsKICAgICAgICAgICAgc2VuZF9iaXRzKHMsIGNvdW50IC0gMTEsIDcpOwogICAgICAgICAgfQogICAgICAgICAgY291bnQgPSAwOwogICAgICAgICAgcHJldmxlbiA9IGN1cmxlbjsKICAgICAgICAgIGlmIChuZXh0bGVuID09PSAwKSB7CiAgICAgICAgICAgIG1heF9jb3VudCA9IDEzODsKICAgICAgICAgICAgbWluX2NvdW50ID0gMzsKICAgICAgICAgIH0gZWxzZSBpZiAoY3VybGVuID09PSBuZXh0bGVuKSB7CiAgICAgICAgICAgIG1heF9jb3VudCA9IDY7CiAgICAgICAgICAgIG1pbl9jb3VudCA9IDM7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBtYXhfY291bnQgPSA3OwogICAgICAgICAgICBtaW5fY291bnQgPSA0OwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgICBmdW5jdGlvbiBidWlsZF9ibF90cmVlKHMpIHsKICAgICAgICB2YXIgbWF4X2JsaW5kZXg7CiAgICAgICAgc2Nhbl90cmVlKHMsIHMuZHluX2x0cmVlLCBzLmxfZGVzYy5tYXhfY29kZSk7CiAgICAgICAgc2Nhbl90cmVlKHMsIHMuZHluX2R0cmVlLCBzLmRfZGVzYy5tYXhfY29kZSk7CiAgICAgICAgYnVpbGRfdHJlZShzLCBzLmJsX2Rlc2MpOwogICAgICAgIGZvciAobWF4X2JsaW5kZXggPSBCTF9DT0RFUyAtIDE7IG1heF9ibGluZGV4ID49IDM7IG1heF9ibGluZGV4LS0pIHsKICAgICAgICAgIGlmIChzLmJsX3RyZWVbYmxfb3JkZXJbbWF4X2JsaW5kZXhdICogMiArIDFdICE9PSAwKSB7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBzLm9wdF9sZW4gKz0gMyAqIChtYXhfYmxpbmRleCArIDEpICsgNSArIDUgKyA0OwogICAgICAgIHJldHVybiBtYXhfYmxpbmRleDsKICAgICAgfQogICAgICBmdW5jdGlvbiBzZW5kX2FsbF90cmVlcyhzLCBsY29kZXMsIGRjb2RlcywgYmxjb2RlcykgewogICAgICAgIHZhciByYW5rOwogICAgICAgIHNlbmRfYml0cyhzLCBsY29kZXMgLSAyNTcsIDUpOwogICAgICAgIHNlbmRfYml0cyhzLCBkY29kZXMgLSAxLCA1KTsKICAgICAgICBzZW5kX2JpdHMocywgYmxjb2RlcyAtIDQsIDQpOwogICAgICAgIGZvciAocmFuayA9IDA7IHJhbmsgPCBibGNvZGVzOyByYW5rKyspIHsKICAgICAgICAgIHNlbmRfYml0cyhzLCBzLmJsX3RyZWVbYmxfb3JkZXJbcmFua10gKiAyICsgMV0sIDMpOwogICAgICAgIH0KICAgICAgICBzZW5kX3RyZWUocywgcy5keW5fbHRyZWUsIGxjb2RlcyAtIDEpOwogICAgICAgIHNlbmRfdHJlZShzLCBzLmR5bl9kdHJlZSwgZGNvZGVzIC0gMSk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZGV0ZWN0X2RhdGFfdHlwZShzKSB7CiAgICAgICAgdmFyIGJsYWNrX21hc2sgPSA0MDkzNjI0NDQ3OwogICAgICAgIHZhciBuOwogICAgICAgIGZvciAobiA9IDA7IG4gPD0gMzE7IG4rKywgYmxhY2tfbWFzayA+Pj49IDEpIHsKICAgICAgICAgIGlmIChibGFja19tYXNrICYgMSAmJiBzLmR5bl9sdHJlZVtuICogMl0gIT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIFpfQklOQVJZOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAocy5keW5fbHRyZWVbOSAqIDJdICE9PSAwIHx8IHMuZHluX2x0cmVlWzEwICogMl0gIT09IDAgfHwgcy5keW5fbHRyZWVbMTMgKiAyXSAhPT0gMCkgewogICAgICAgICAgcmV0dXJuIFpfVEVYVDsKICAgICAgICB9CiAgICAgICAgZm9yIChuID0gMzI7IG4gPCBMSVRFUkFMUzsgbisrKSB7CiAgICAgICAgICBpZiAocy5keW5fbHRyZWVbbiAqIDJdICE9PSAwKSB7CiAgICAgICAgICAgIHJldHVybiBaX1RFWFQ7CiAgICAgICAgICB9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HMxIHwgMDsKICAgICAgICAgIH0gd2hpbGUgKC0tbik7CiAgICAgICAgICBzMSAlPSA2NTUyMTsKICAgICAgICAgIHMyICU9IDY1NTIxOwogICAgICAgIH0KICAgICAgICByZXR1cm4gczEgfCBzMiA8PCAxNiB8IDA7CiAgICAgIH0KICAgICAgbW9kdWxlLmV4cG9ydHMgPSBhZGxlcjMyOwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvY3JjMzIuanMKICB2YXIgcmVxdWlyZV9jcmMzMiA9IF9fY29tbW9uSlMoewogICAgIm5vZGVfbW9kdWxlcy8ucG5wbS9wYWtvQDEuMC4xMS9ub2RlX21vZHVsZXMvcGFrby9saWIvemxpYi9jcmMzMi5qcyIoZXhwb3J0cywgbW9kdWxlKSB7CiAgICAgIGluaXRfYnVmZmVyX3NoaW0oKTsKICAgICAgInVzZSBzdHJpY3QiOwogICAgICBmdW5jdGlvbiBtYWtlVGFibGUoKSB7CiAgICAgICAgdmFyIGMsIHRhYmxlID0gW107CiAgICAgICAgZm9yICh2YXIgbiA9IDA7IG4gPCAyNTY7IG4rKykgewogICAgICAgICAgYyA9IG47CiAgICAgICAgICBmb3IgKHZhciBrID0gMDsgayA8IDg7IGsrKykgewogICAgICAgICAgICBjID0gYyAmIDEgPyAzOTg4MjkyMzg0IF4gYyA+Pj4gMSA6IGMgPj4+IDE7CiAgICAgICAgICB9CiAgICAgICAgICB0YWJsZVtuXSA9IGM7CiAgICAgICAgfQogICAgICAgIHJldHVybiB0YWJsZTsKICAgICAgfQogICAgICB2YXIgY3JjVGFibGUgPSBtYWtlVGFibGUoKTsKICAgICAgZnVuY3Rpb24gY3JjMzIyKGNyYywgYnVmLCBsZW4sIHBvcykgewogICAgICAgIHZhciB0ID0gY3JjVGFibGUsIGVuZCA9IHBvcyArIGxlbjsKICAgICAgICBjcmMgXj0gLTE7CiAgICAgICAgZm9yICh2YXIgaSA9IHBvczsgaSA8IGVuZDsgaSsrKSB7CiAgICAgICAgICBjcmMgPSBjcmMgPj4+IDggXiB0WyhjcmMgXiBidWZbaV0pICYgMjU1XTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIGNyYyBeIC0xOwogICAgICB9CiAgICAgIG1vZHVsZS5leHBvcnRzID0gY3JjMzIyOwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvbWVzc2FnZXMuanMKICB2YXIgcmVxdWlyZV9tZXNzYWdlczIgPSBfX2NvbW1vbkpTKHsKICAgICJub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvbWVzc2FnZXMuanMiKGV4cG9ydHMsIG1vZHVsZSkgewogICAgICBpbml0X2J1ZmZlcl9zaGltKCk7CiAgICAgICJ1c2Ugc3RyaWN0IjsKICAgICAgbW9kdWxlLmV4cG9ydHMgPSB7CiAgICAgICAgMjogIm5lZWQgZGljdGlvbmFyeSIsCiAgICAgICAgMTogInN0cmVhbSBlbmQiLAogICAgICAgIDA6ICIiLAogICAgICAgICItMSI6ICJmaWxlIGVycm9yIiwKICAgICAgICAiLTIiOiAic3RyZWFtIGVycm9yIiwKICAgICAgICAiLTMiOiAiZGF0YSBlcnJvciIsCiAgICAgICAgIi00IjogImluc3VmZmljaWVudCBtZW1vcnkiLAogICAgICAgICItNSI6ICJidWZmZXIgZXJyb3IiLAogICAgICAgICItNiI6ICJpbmNvbXBhdGlibGUgdmVyc2lvbiIKICAgICAgfTsKICAgIH0KICB9KTsKCiAgLy8gbm9kZV9tb2R1bGVzLy5wbnBtL3Bha29AMS4wLjExL25vZGVfbW9kdWxlcy9wYWtvL2xpYi96bGliL2RlZmxhdGUuanMKICB2YXIgcmVxdWlyZV9kZWZsYXRlID0gX19jb21tb25KUyh7CiAgICA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mFyIE1BWF9XQklUUyA9IDE1OwogICAgICB2YXIgREVGX01FTV9MRVZFTCA9IDg7CiAgICAgIHZhciBMRU5HVEhfQ09ERVMgPSAyOTsKICAgICAgdmFyIExJVEVSQUxTID0gMjU2OwogICAgICB2YXIgTF9DT0RFUyA9IExJVEVSQUxTICsgMSArIExFTkdUSF9DT0RFUzsKICAgICAgdmFyIERfQ09ERVMgPSAzMDsKICAgICAgdmFyIEJMX0NPREVTID0gMTk7CiAgICAgIHZhciBIRUFQX1NJWkUgPSAyICogTF9DT0RFUyArIDE7CiAgICAgIHZhciBNQVhfQklUUyA9IDE1OwogICAgICB2YXIgTUlOX01BVENIID0gMzsKICAgICAgdmFyIE1BWF9NQVRDSCA9IDI1ODsKICAgICAgdmFyIE1JTl9MT09LQUhFQUQgPSBNQVhfTUFUQ0ggKyBNSU5fTUFUQ0ggKyAxOwogICAgICB2YXIgUFJFU0VUX0RJQ1QgPSAzMjsKICAgICAgdmFyIElOSVRfU1RBVEUgPSA0MjsKICAgICAgdmFyIEVYVFJBX1NUQVRFID0gNjk7CiAgICAgIHZhciBOQU1FX1NUQVRFID0gNzM7CiAgICAgIHZhciBDT01NRU5UX1NUQVRFID0gOTE7CiAgICAgIHZhciBIQ1JDX1NUQVRFID0gMTAzOwogICAgICB2YXIgQlVTWV9TVEFURSA9IDExMzsKICAgICAgdmFyIEZJTklTSF9TVEFURSA9IDY2NjsKICAgICAgdmFyIEJTX05FRURfTU9SRSA9IDE7CiAgICAgIHZhciBCU19CTE9DS19ET05FID0gMjsKICAgICAgdmFyIEJTX0ZJTklTSF9TVEFSVEVEID0gMzsKICAgICAgdmFyIEJTX0ZJTklTSF9ET05FID0gNDsKICAgICAgdmFyIE9TX0NPREUgPSAzOwogICAgICBmdW5jdGlvbiBlcnIoc3RybSwgZXJyb3JDb2RlKSB7CiAgICAgICAgc3RybS5tc2cgPSBtc2dbZXJyb3JDb2RlXTsKICAgICAgICByZXR1cm4gZXJyb3JDb2RlOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIHJhbmsoZikgewogICAgICAgIHJldHVybiAoZiA8PCAxKSAtIChmID4gNCA/IDkgOiAwKTsKICAgICAgfQogICAgICBmdW5jdGlvbiB6ZXJvKGJ1ZikgewogICAgICAgIHZhciBsZW4gPSBidWYubGVuZ3RoOwogICAgICAgIHdoaWxlICgtLWxlbiA+PSAwKSB7CiAgICAgICAgICBidWZbbGVuXSA9IDA7CiAgICAgICAgfQogICAgICB9CiAgICAgIGZ1bmN0aW9uIGZsdXNoX3BlbmRpbmcoc3RybSkgewogICAgICAgIHZhciBzID0gc3RybS5zdGF0ZTsKICAgICAgICB2YXIgbGVuID0gcy5wZW5kaW5nOwogICAgICAgIGlmIChsZW4gPiBzdHJtLmF2YWlsX291dCkgewogICAgICAgICAgbGVuID0gc3RybS5hdmFpbF9vdXQ7CiAgICAgICAgfQogICAgICAgIGlmIChsZW4gPT09IDApIHsKICAgICAgICAgIHJldHVybjsKICAgICAgICB9CiAgICAgICAgdXRpbHMuYXJyYXlTZXQoc3RybS5vdXRwdXQsIHMucGVuZGluZ19idWYsIHMucGVuZGluZ19vdXQsIGxlbiwgc3RybS5uZXh0X291dCk7CiAgICAgICAgc3RybS5uZXh0X291dCArPSBsZW47CiAgICAgICAgcy5wZW5kaW5nX291dCArPSBsZW47CiAgICAgICAgc3RybS50b3RhbF9vdXQgKz0gbGVuOwogICAgICAgIHN0cm0uYXZhaWxfb3V0IC09IGxlbjsKICAgICAgICBzLnBlbmRpbmcgLT0gbGVuOwogICAgICAgIGlmIChzLnBlbmRpbmcgPT09IDApIHsKICAgICAgICAgIHMucGVuZGluZ19vdXQgPSAwOwogICAgICAgIH0KICAgICAgfQogICAgICBmdW5jdGlvbiBmbHVzaF9ibG9ja19vbmx5KHMsIGxhc3QpIHsKICAgICAgICB0cmVlcy5fdHJfZmx1c2hfYmxvY2socywgcy5ibG9ja19zdGFydCA+PSAwID8gcy5ibG9ja19zdGFydCA6IC0xLCBzLnN0cnN0YXJ0IC0gcy5ibG9ja19zdGFydCwgbGFzdCk7CiAgICAgICAgcy5ibG9ja19zdGFydCA9IHMuc3Ryc3RhcnQ7CiAgICAgICAgZmx1c2hfcGVuZGluZyhzLnN0cm0pOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIHB1dF9ieXRlKHMsIGIpIHsKICAgICAgICBzLnBlbmRpbmdfYnVmW3MucGVuZGluZysrXSA9IGI7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gcHV0U2hvcnRNU0IocywgYikgewogICAgICAgIHMucGVuZGluZ19idWZbcy5wZW5kaW5nKytdID0gYiA+Pj4gOCAmIDI1NTsKICAgICAgICBzLnBlbmRpbmdfYnVmW3MucGVuZGluZysrXSA9IGIgJiAyNTU7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gcmVhZF9idWYoc3RybSwgYnVmLCBzdGFydCwgc2l6ZSkgewogICAgICAgIHZhciBsZW4gPSBzdHJtLmF2YWlsX2luOwogICAgICAgIGlmIChsZW4gPiBzaXplKSB7CiAgICAgICAgICBsZW4gPSBzaXplOwogICAgICAgIH0KICAgICAgICBpZiAobGVuID09PSAwKSB7CiAgICAgICAgICByZXR1cm4gMDsKICAgICAgICB9CiAgICAgICAgc3RybS5hdmFpbF9pbiAtPSBsZW47CiAgICAgICAgdXRpbHMuYXJyYXlTZXQoYnVmLCBzdHJtLmlucHV0LCBzdHJtLm5leHRfaW4sIGxlbiwgc3RhcnQpOwogICAgICAgIGlmIChzdHJtLnN0YXRlLndyYXAgPT09IDEpIHsKICAgICAgICAgIHN0cm0uYWRsZXIgPSBhZGxlcjMyKHN0cm0uYWRsZXIsIGJ1ZiwgbGVuLCBzdGFydCk7CiAgICAgICAgfSBlbHNlIGlmIChzdHJtLnN0YXRlLndyYXAgPT09IDIpIHsKICAgICAgICAgIHN0cm0uYWRsZXIgPSBjcmMzMjIoc3RybS5hZGxlciwgYnVmLCBsZW4sIHN0YXJ0KTsKICAgICAgICB9CiAgICAgICAgc3RybS5uZXh0X2luICs9IGxlbjsKICAgICAgICBzdHJtLnRvdGFsX2luICs9IGxlbjsKICAgICAgICByZXR1cm4gbGVuOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGxvbmdlc3RfbWF0Y2gocywgY3VyX21hdGNoKSB7CiAgICAgICAgdmFyIGNoYWluX2xlbmd0aCA9IHMubWF4X2NoYWluX2xlbmd0aDsKICAgICAgICB2YXIgc2NhbiA9IHMuc3Ryc3RhcnQ7CiAgICAgICAgdmFyIG1hdGNoOwogICAgICAgIHZhciBsZW47CiAgICAgICAgdmFyIGJlc3RfbGVuID0gcy5wcmV2X2xlbmd0aDsKICAgICAgICB2YXIgbmljZV9tYXRjaCA9IHMubmljZV9tYXRjaDsKICAgICAgICB2YXIgbGltaXQgPSBzLnN0cnN0YXJ0ID4gcy53X3NpemUgLSBNSU5fTE9PS0FIRUFEID8gcy5zdHJzdGFydCAtIChzLndfc2l6ZSAtIE1JTl9MT09LQUhFQUQpIDogMDsKICAgICAgICB2YXIgX3dpbiA9IHMud2luZG93OwogICAgICAgIHZhciB3bWFzayA9IHMud19tYXNrOwogICAgICAgIHZhciBwcmV2ID0gcy5wcmV2OwogICAgICAgIHZhciBzdHJlbmQgPSBzLnN0cnN0YXJ0ICsgTUFYX01BVENIOwogICAgICAgIHZhciBzY2FuX2VuZDEgPSBfd2luW3NjYW4gKyBiZXN0X2xlbiAtIDFdOwogICAgICAgIHZhciBzY2FuX2VuZCA9IF93aW5bc2NhbiArIGJlc3RfbGVuXTsKICAgICAgICBpZiAocy5wcmV2X2xlbmd0aCA+PSBzLmdvb2RfbWF0Y2gpIHsKICAgICAgICAgIGNoYWluX2xlbmd0aCA+Pj0gMjsKICAgICAgICB9CiAgICAgICAgaWYgKG5pY2VfbWF0Y2ggPiBzLmxvb2thaGVhZCkgewogICAgICAgICAgbmljZV9tYXRjaCA9IHMubG9va2FoZWFkOwogICAgICAgIH0KICAgICAgICBkbyB7CiAgICAgICAgICBtYXRjaCA9IGN1cl9tYXRjaDsKICAgICAgICAgIGlmIChfd2luW21hdGNoICsgYmVzdF9sZW5dICE9PSBzY2FuX2VuZCB8fCBfd2luW21hdGNoICsgYmVzdF9sZW4gLSAxXSAhPT0gc2Nhbl9lbmQxIHx8IF93aW5bbWF0Y2hdICE9PSBfd2luW3NjYW5dIHx8IF93aW5bKyttYXRjaF0gIT09IF93aW5bc2NhbiArIDFdKSB7CiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgfQogICAgICAgICAgc2NhbiArPSAyOwogICAgICAgICAgbWF0Y2grKzsKICAgICAgICAgIGRvIHsKICAgICAgICAgIH0gd2hpbGUgKF93aW5bKytzY2FuXSA9PT0gX3dpblsrK21hdGNoXSAmJiBfd2luWysrc2Nhbl0gPT09IF93aW5bKyttYXRjaF0gJiYgX3dpblsrK3NjYW5dID09PSBfd2luWysrbWF0Y2hdICYmIF93aW5bKytzY2FuXSA9PT0gX3dpblsrK21hdGNoXSAmJiBfd2luWysrc2Nhbl0gPT09IF93aW5bKyttYXRjaF0gJiYgX3dpblsrK3NjYW5dID09PSBfd2luWysrbWF0Y2hdICYmIF93aW5bKytzY2FuXSA9PT0gX3dpblsrK21hdGNoXSAmJiBfd2luWysrc2Nhbl0gPT09IF93aW5bKyttYXRjaF0gJiYgc2NhbiA8IHN0cmVuZCk7CiAgICAgICAgICBsZW4gPSBNQVhfTUFUQ0ggLSAoc3RyZW5kIC0gc2Nhbik7CiAgICAgICAgICBzY2FuID0gc3RyZW5kIC0gTUFYX01BVENIOwogICAgICAgICAgaWYgKGxlbiA+IGJlc3RfbGVuKSB7CiAgICAgICAgICAgIHMubWF0Y2hfc3RhcnQgPSBjdXJfbWF0Y2g7CiAgICAgICAgICAgIGJlc3RfbGVuID0gbGVuOwogICAgICAgICAgICBpZiAobGVuID49IG5pY2VfbWF0Y2gpIHsKICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgICBzY2FuX2VuZDEgPSBfd2luW3NjYW4gKyBiZXN0X2xlbiAtIDFdOwogICAgICAgICAgICBzY2FuX2VuZCA9IF93aW5bc2NhbiArIGJlc3RfbGVuXTsKICAgICAgICAgIH0KICAgICAgICB9IHdoaWxlICgoY3VyX21hdGNoID0gcHJldltjdXJfbWF0Y2ggJiB3bWFza10pID4gbGltaXQgJiYgLS1jaGFpbl9sZW5ndGggIT09IDApOwogICAgICAgIGlmIChiZXN0X2xlbiA8PSBzLmxvb2thaGVhZCkgewogICAgICAgICAgcmV0dXJuIGJlc3RfbGVuOwogICAgICAgIH0KICAgICAgICByZXR1cm4gcy5sb29rYWhlYWQ7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZmlsbF93aW5kb3cocykgewogICAgICAgIHZhciBfd19zaXplID0gcy53X3NpemU7CiAgICAgICAgdmFyIHAsIG4sIG0sIG1vcmUsIHN0cjsKICAgICAgICBkbyB7CiAgICAgICAgICBtb3JlID0gcy53aW5kb3dfc2l6ZSAtIHMubG9va2FoZWFkIC0gcy5zdHJzdGFydDsKICAgICAgICAgIGlmIChzLnN0cnN0YXJ0ID49IF93X3NpemUgKyAoX3dfc2l6ZSAtIE1JTl9MT09LQUhFQUQpKSB7CiAgICAgICAgICAgIHV0aWxzLmFycmF5U2V0KHMud2luZG93LCBzLndpbmRvdywgX3dfc2l6ZSwgX3dfc2l6ZSwgMCk7CiAgICAgICAgICAgIHMubWF0Y2hfc3RhcnQgLT0gX3dfc2l6ZTsKICAgICAgICAgICAgcy5zdHJzdGFydCAtPSBfd19zaXplOwogICAgICAgICAgICBzLmJsb2NrX3N0YXJ0IC09IF93X3NpemU7CiAgICAgICAgICAgIG4gPSBzLmhhc2hfc2l6ZTsKICAgICAgICAgICAgcCA9IG47CiAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICBtID0gcy5oZWFkWy0tcF07CiAgICAgICAgICAgICAgcy5oZWFkW3BdID0gbSA+PSBfd19zaXplID8gbSAtIF93X3NpemUgOiAwOwogICAgICAgICAgICB9IHdoaWxlICgtLW4pOwogICAgICAgICAgICBuID0gX3dfc2l6ZTsKICAgICAgICAgICAgcCA9IG47CiAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICBtID0gcy5wcmV2Wy0tcF07CiAgICAgICAgICAgICAgcy5wcmV2W3BdID0gbSA+PSBfd19zaXplID8gbSAtIF93X3NpemUgOiAwOwogICAgICAgICAgICB9IHdoaWxlICgtLW4pOwogICAgICAgICAgICBtb3JlICs9IF93X3NpemU7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX2luID09PSAwKSB7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgICAgbiA9IHJlYWRfYnVmKHMuc3RybSwgcy53aW5kb3csIHMuc3Ryc3RhcnQgKyBzLmxvb2thaGVhZCwgbW9yZSk7CiAgICAgICAgICBzLmxvb2thaGVhZCArPSBuOwogICAgICAgICAgaWYgKHMubG9va2FoZWFkICsgcy5pbnNlcnQgPj0gTUlOX01BVENIKSB7CiAgICAgICAgICAgIHN0ciA9IHMuc3Ryc3RhcnQgLSBzLmluc2VydDsKICAgICAgICAgICAgcy5pbnNfaCA9IHMud2luZG93W3N0cl07CiAgICAgICAgICAgIHMuaW5zX2ggPSAocy5pbnNfaCA8PCBzLmhhc2hfc2hpZnQgXiBzLndpbmRvd1tzdHIgKyAxXSkgJiBzLmhhc2hfbWFzazsKICAgICAgICAgICAgd2hpbGUgKHMuaW5zZXJ0KSB7CiAgICAgICAgICAgICAgcy5pbnNfaCA9IChzLmluc19oIDw8IHMuaGFzaF9zaGlmdCBeIHMud2luZG93W3N0ciArIE1JTl9NQVRDSCAtIDFdKSAmIHMuaGFzaF9tYXNrOwogICAgICAgICAgICAgIHMucHJldltzdHIgJiBzLndfbWFza10gPSBzLmhlYWRbcy5pbnNfaF07CiAgICAgICAgICAgICAgcy5oZWFkW3MuaW5zX2hdID0gc3RyOwogICAgICAgICAgICAgIHN0cisrOwogICAgICAgICAgICAgIHMuaW5zZXJ0LS07CiAgICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkICsgcy5pbnNlcnQgPCBNSU5fTUFUQ0gpIHsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0gd2hpbGUgKHMubG9va2FoZWFkIDwgTUlOX0xPT0tBSEVBRCAmJiBzLnN0cm0uYXZhaWxfaW4gIT09IDApOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGRlZmxhdGVfc3RvcmVkKHMsIGZsdXNoKSB7CiAgICAgICAgdmFyIG1heF9ibG9ja19zaXplID0gNjU1MzU7CiAgICAgICAgaWYgKG1heF9ibG9ja19zaXplID4gcy5wZW5kaW5nX2J1Zl9zaXplIC0gNSkgewogICAgICAgICAgbWF4X2Jsb2NrX3NpemUgPSBzLnBlbmRpbmdfYnVmX3NpemUgLSA1OwogICAgICAgIH0KICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA8PSAxKSB7CiAgICAgICAgICAgIGZpbGxfd2luZG93KHMpOwogICAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPT09IDAgJiYgZmx1c2ggPT09IFpfTk9fRkxVU0gpIHsKICAgICAgICAgICAgICByZXR1cm4gQlNfTkVFRF9NT1JFOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA9PT0gMCkgewogICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBzLnN0cnN0YXJ0ICs9IHMubG9va2FoZWFkOwogICAgICAgICAgcy5sb29rYWhlYWQgPSAwOwogICAgICAgICAgdmFyIG1heF9zdGFydCA9IHMuYmxvY2tfc3RhcnQgKyBtYXhfYmxvY2tfc2l6ZTsKICAgICAgICAgIGlmIChzLnN0cnN0YXJ0ID09PSAwIHx8IHMuc3Ryc3RhcnQgPj0gbWF4X3N0YXJ0KSB7CiAgICAgICAgICAgIHMubG9va2FoZWFkID0gcy5zdHJzdGFydCAtIG1heF9zdGFydDsKICAgICAgICAgICAgcy5zdHJzdGFydCA9IG1heF9zdGFydDsKICAgICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCBmYWxzZSk7CiAgICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgaWYgKHMuc3Ryc3RhcnQgLSBzLmJsb2NrX3N0YXJ0ID49IHMud19zaXplIC0gTUlOX0xPT0tBSEVBRCkgewogICAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIGZhbHNlKTsKICAgICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgICByZXR1cm4gQlNfTkVFRF9NT1JFOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHMuaW5zZXJ0ID0gMDsKICAgICAgICBpZiAoZmx1c2ggPT09IFpfRklOSVNIKSB7CiAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIHRydWUpOwogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIEJTX0ZJTklTSF9TVEFSVEVEOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIEJTX0ZJTklTSF9ET05FOwogICAgICAgIH0KICAgICAgICBpZiAocy5zdHJzdGFydCA+IHMuYmxvY2tfc3RhcnQpIHsKICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgZmFsc2UpOwogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgfQogICAgICBmdW5jdGlvbiBkZWZsYXRlX2Zhc3QocywgZmx1c2gpIHsKICAgICAgICB2YXIgaGFzaF9oZWFkOwogICAgICAgIHZhciBiZmx1c2g7CiAgICAgICAgZm9yICg7IDsgKSB7CiAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPCBNSU5fTE9PS0FIRUFEKSB7CiAgICAgICAgICAgIGZpbGxfd2luZG93KHMpOwogICAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPCBNSU5fTE9PS0FIRUFEICYmIGZsdXNoID09PSBaX05PX0ZMVVNIKSB7CiAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPT09IDApIHsKICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgaGFzaF9oZWFkID0gMDsKICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA+PSBNSU5fTUFUQ0gpIHsKICAgICAgICAgICAgcy5pbnNfaCA9IChzLmluc19oIDw8IHMuaGFzaF9zaGlmdCBeIHMud2luZG93W3Muc3Ryc3RhcnQgKyBNSU5fTUFUQ0ggLSAxXSkgJiBzLmhhc2hfbWFzazsKICAgICAgICAgICAgaGFzaF9oZWFkID0gcy5wcmV2W3Muc3Ryc3RhcnQgJiBzLndfbWFza10gPSBzLmhlYWRbcy5pbnNfaF07CiAgICAgICAgICAgIHMuaGVhZFtzLmluc19oXSA9IHMuc3Ryc3RhcnQ7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoaGFzaF9oZWFkICE9PSAwICYmIHMuc3Ryc3RhcnQgLSBoYXNoX2hlYWQgPD0gcy53X3NpemUgLSBNSU5fTE9PS0FIRUFEKSB7CiAgICAgICAgICAgIHMubWF0Y2hfbGVuZ3RoID0gbG9uZ2VzdF9tYXRjaChzLCBoYXNoX2hlYWQpOwogICAgICAgICAgfQogICAgICAgICAgaWYgKHMubWF0Y2hfbGVuZ3RoID49IE1JTl9NQVRDSCkgewogICAgICAgICAgICBiZmx1c2ggPSB0cmVlcy5fdHJfdGFsbHkocywgcy5zdHJzdGFydCAtIHMubWF0Y2hfc3RhcnQsIHMubWF0Y2hfbGVuZ3RoIC0gTUlOX01BVENIKTsKICAgICAgICAgICAgcy5sb29rYWhlYWQgLT0gcy5tYXRjaF9sZW5ndGg7CiAgICAgICAgICAgIGlmIChzLm1hdGNoX2xlbmd0aCA8PSBzLm1heF9sYXp5X21hdGNoICYmIHMubG9va2FoZWFkID49IE1JTl9NQVRDSCkgewogICAgICAgICAgICAgIHMubWF0Y2hfbGVuZ3RoLS07CiAgICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgICAgcy5zdHJzdGFydCsrOwogICAgICAgICAgICAgICAgcy5pbnNfaCA9IChzLmluc19oIDw8IHMuaGFzaF9zaGlmdCBeIHMud2luZG93W3Muc3Ryc3RhcnQgKyBNSU5fTUFUQ0ggLSAxXSkgJiBzLmhhc2hfbWFzazsKICAgICAgICAgICAgICAgIGhhc2hfaGVhZCA9IHMucHJldltzLnN0cnN0YXJ0ICYgcy53X21hc2tdID0gcy5oZWFkW3MuaW5zX2hdOwogICAgICAgICAgICAgICAgcy5oZWFkW3MuaW5zX2hdID0gcy5zdHJzdGFydDsKICAgICAgICAgICAgICB9IHdoaWxlICgtLXMubWF0Y2hfbGVuZ3RoICE9PSAwKTsKICAgICAgICAgICAgICBzLnN0cnN0YXJ0Kys7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgcy5zdHJzdGFydCArPSBzLm1hdGNoX2xlbmd0aDsKICAgICAgICAgICAgICBzLm1hdGNoX2xlbmd0aCA9IDA7CiAgICAgICAgICAgICAgcy5pbnNfaCA9IHMud2luZG93W3Muc3Ryc3RhcnRdOwogICAgICAgICAgICAgIHMuaW5zX2ggPSAocy5pbnNfaCA8PCBzLmhhc2hfc2hpZnQgXiBzLndpbmRvd1tzLnN0cnN0YXJ0ICsgMV0pICYgcy5oYXNoX21hc2s7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGJmbHVzaCA9IHRyZWVzLl90cl90YWxseShzLCAwLCBzLndpbmRvd1tzLnN0cnN0YXJ0XSk7CiAgICAgICAgICAgIHMubG9va2FoZWFkLS07CiAgICAgICAgICAgIHMuc3Ryc3RhcnQrKzsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChiZmx1c2gpIHsKICAgICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCBmYWxzZSk7CiAgICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBzLmluc2VydCA9IHMuc3Ryc3RhcnQgPCBNSU5fTUFUQ0ggLSAxID8gcy5zdHJzdGFydCA6IE1JTl9NQVRDSCAtIDE7CiAgICAgICAgaWYgKGZsdXNoID09PSBaX0ZJTklTSCkgewogICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCB0cnVlKTsKICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgIHJldHVybiBCU19GSU5JU0hfU1RBUlRFRDsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBCU19GSU5JU0hfRE9ORTsKICAgICAgICB9CiAgICAgICAgaWYgKHMubGFzdF9saXQpIHsKICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgZmFsc2UpOwogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIEJTX0JMT0NLX0RPTkU7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZGVmbGF0ZV9zbG93KHMsIGZsdXNoKSB7CiAgICAgICAgdmFyIGhhc2hfaGVhZDsKICAgICAgICB2YXIgYmZsdXNoOwogICAgICAgIHZhciBtYXhfaW5zZXJ0OwogICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgaWYgKHMubG9va2FoZWFkIDwgTUlOX0xPT0tBSEVBRCkgewogICAgICAgICAgICBmaWxsX3dpbmRvdyhzKTsKICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkIDwgTUlOX0xPT0tBSEVBRCAmJiBmbHVzaCA9PT0gWl9OT19GTFVTSCkgewogICAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkID09PSAwKSB7CiAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGhhc2hfaGVhZCA9IDA7CiAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPj0gTUlOX01BVENIKSB7CiAgICAgICAgICAgIHMuaW5zX2ggPSAocy5pbnNfaCA8PCBzLmhhc2hfc2hpZnQgXiBzLndpbmRvd1tzLnN0cnN0YXJ0ICsgTUlOX01BVENIIC0gMV0pICYgcy5oYXNoX21hc2s7CiAgICAgICAgICAgIGhhc2hfaGVhZCA9IHMucHJldltzLnN0cnN0YXJ0ICYgcy53X21hc2tdID0gcy5oZWFkW3MuaW5zX2hdOwogICAgICAgICAgICBzLmhlYWRbcy5pbnNfaF0gPSBzLnN0cnN0YXJ0OwogICAgICAgICAgfQogICAgICAgICAgcy5wcmV2X2xlbmd0aCA9IHMubWF0Y2hfbGVuZ3RoOwogICAgICAgICAgcy5wcmV2X21hdGNoID0gcy5tYXRjaF9zdGFydDsKICAgICAgICAgIHMubWF0Y2hfbGVuZ3RoID0gTUlOX01BVENIIC0gMTsKICAgICAgICAgIGlmIChoYXNoX2hlYWQgIT09IDAgJiYgcy5wcmV2X2xlbmd0aCA8IHMubWF4X2xhenlf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Ghhc2hfaGVhZCA9IHMucHJldltzLnN0cnN0YXJ0ICYgcy53X21hc2tdID0gcy5oZWFkW3MuaW5zX2hdOwogICAgICAgICAgICAgICAgcy5oZWFkW3MuaW5zX2hdID0gcy5zdHJzdGFydDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0gd2hpbGUgKC0tcy5wcmV2X2xlbmd0aCAhPT0gMCk7CiAgICAgICAgICAgIHMubWF0Y2hfYXZhaWxhYmxlID0gMDsKICAgICAgICAgICAgcy5tYXRjaF9sZW5ndGggPSBNSU5fTUFUQ0ggLSAxOwogICAgICAgICAgICBzLnN0cnN0YXJ0Kys7CiAgICAgICAgICAgIGlmIChiZmx1c2gpIHsKICAgICAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIGZhbHNlKTsKICAgICAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSBpZiAocy5tYXRjaF9hdmFpbGFibGUpIHsKICAgICAgICAgICAgYmZsdXNoID0gdHJlZXMuX3RyX3RhbGx5KHMsIDAsIHMud2luZG93W3Muc3Ryc3RhcnQgLSAxXSk7CiAgICAgICAgICAgIGlmIChiZmx1c2gpIHsKICAgICAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIGZhbHNlKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBzLnN0cnN0YXJ0Kys7CiAgICAgICAgICAgIHMubG9va2FoZWFkLS07CiAgICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgfQogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcy5tYXRjaF9hdmFpbGFibGUgPSAxOwogICAgICAgICAgICBzLnN0cnN0YXJ0Kys7CiAgICAgICAgICAgIHMubG9va2FoZWFkLS07CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChzLm1hdGNoX2F2YWlsYWJsZSkgewogICAgICAgICAgYmZsdXNoID0gdHJlZXMuX3RyX3RhbGx5KHMsIDAsIHMud2luZG93W3Muc3Ryc3RhcnQgLSAxXSk7CiAgICAgICAgICBzLm1hdGNoX2F2YWlsYWJsZSA9IDA7CiAgICAgICAgfQogICAgICAgIHMuaW5zZXJ0ID0gcy5zdHJzdGFydCA8IE1JTl9NQVRDSCAtIDEgPyBzLnN0cnN0YXJ0IDogTUlOX01BVENIIC0gMTsKICAgICAgICBpZiAoZmx1c2ggPT09IFpfRklOSVNIKSB7CiAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIHRydWUpOwogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIEJTX0ZJTklTSF9TVEFSVEVEOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIEJTX0ZJTklTSF9ET05FOwogICAgICAgIH0KICAgICAgICBpZiAocy5sYXN0X2xpdCkgewogICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCBmYWxzZSk7CiAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICByZXR1cm4gQlNfTkVFRF9NT1JFOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gQlNfQkxPQ0tfRE9ORTsKICAgICAgfQogICAgICBmdW5jdGlvbiBkZWZsYXRlX3JsZShzLCBmbHVzaCkgewogICAgICAgIHZhciBiZmx1c2g7CiAgICAgICAgdmFyIHByZXY7CiAgICAgICAgdmFyIHNjYW4sIHN0cmVuZDsKICAgICAgICB2YXIgX3dpbiA9IHMud2luZG93OwogICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgaWYgKHMubG9va2FoZWFkIDw9IE1BWF9NQVRDSCkgewogICAgICAgICAgICBmaWxsX3dpbmRvdyhzKTsKICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkIDw9IE1BWF9NQVRDSCAmJiBmbHVzaCA9PT0gWl9OT19GTFVTSCkgewogICAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkID09PSAwKSB7CiAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIHMubWF0Y2hfbGVuZ3RoID0gMDsKICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA+PSBNSU5fTUFUQ0ggJiYgcy5zdHJzdGFydCA+IDApIHsKICAgICAgICAgICAgc2NhbiA9IHMuc3Ryc3RhcnQgLSAxOwogICAgICAgICAgICBwcmV2ID0gX3dpbltzY2FuXTsKICAgICAgICAgICAgaWYgKHByZXYgPT09IF93aW5bKytzY2FuXSAmJiBwcmV2ID09PSBfd2luWysrc2Nhbl0gJiYgcHJldiA9PT0gX3dpblsrK3NjYW5dKSB7CiAgICAgICAgICAgICAgc3RyZW5kID0gcy5zdHJzdGFydCArIE1BWF9NQVRDSDsKICAgICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgfSB3aGlsZSAocHJldiA9PT0gX3dpblsrK3NjYW5dICYmIHByZXYgPT09IF93aW5bKytzY2FuXSAmJiBwcmV2ID09PSBfd2luWysrc2Nhbl0gJiYgcHJldiA9PT0gX3dpblsrK3NjYW5dICYmIHByZXYgPT09IF93aW5bKytzY2FuXSAmJiBwcmV2ID09PSBfd2luWysrc2Nhbl0gJiYgcHJldiA9PT0gX3dpblsrK3NjYW5dICYmIHByZXYgPT09IF93aW5bKytzY2FuXSAmJiBzY2FuIDwgc3RyZW5kKTsKICAgICAgICAgICAgICBzLm1hdGNoX2xlbmd0aCA9IE1BWF9NQVRDSCAtIChzdHJlbmQgLSBzY2FuKTsKICAgICAgICAgICAgICBpZiAocy5tYXRjaF9sZW5ndGggPiBzLmxvb2thaGVhZCkgewogICAgICAgICAgICAgICAgcy5tYXRjaF9sZW5ndGggPSBzLmxvb2thaGVhZDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGlmIChzLm1hdGNoX2xlbmd0aCA+PSBNSU5fTUFUQ0gpIHsKICAgICAgICAgICAgYmZsdXNoID0gdHJlZXMuX3RyX3RhbGx5KHMsIDEsIHMubWF0Y2hfbGVuZ3RoIC0gTUlOX01BVENIKTsKICAgICAgICAgICAgcy5sb29rYWhlYWQgLT0gcy5tYXRjaF9sZW5ndGg7CiAgICAgICAgICAgIHMuc3Ryc3RhcnQgKz0gcy5tYXRjaF9sZW5ndGg7CiAgICAgICAgICAgIHMubWF0Y2hfbGVuZ3RoID0gMDsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGJmbHVzaCA9IHRyZWVzLl90cl90YWxseShzLCAwLCBzLndpbmRvd1tzLnN0cnN0YXJ0XSk7CiAgICAgICAgICAgIHMubG9va2FoZWFkLS07CiAgICAgICAgICAgIHMuc3Ryc3RhcnQrKzsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChiZmx1c2gpIHsKICAgICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCBmYWxzZSk7CiAgICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBzLmluc2VydCA9IDA7CiAgICAgICAgaWYgKGZsdXNoID09PSBaX0ZJTklTSCkgewogICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCB0cnVlKTsKICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgIHJldHVybiBCU19GSU5JU0hfU1RBUlRFRDsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBCU19GSU5JU0hfRE9ORTsKICAgICAgICB9CiAgICAgICAgaWYgKHMubGFzdF9saXQpIHsKICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgZmFsc2UpOwogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIEJTX0JMT0NLX0RPTkU7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZGVmbGF0ZV9odWZmKHMsIGZsdXNoKSB7CiAgICAgICAgdmFyIGJmbHVzaDsKICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA9PT0gMCkgewogICAgICAgICAgICBmaWxsX3dpbmRvdyhzKTsKICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkID09PSAwKSB7CiAgICAgICAgICAgICAgaWYgKGZsdXNoID09PSBaX05PX0ZMVVNIKSB7CiAgICAgICAgICAgICAgICByZXR1cm4gQlNfTkVFRF9NT1JFOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgcy5tYXRjaF9sZW5ndGggPSAwOwogICAgICAgICAgYmZsdXNoID0gdHJlZXMuX3RyX3RhbGx5KHMsIDAsIHMud2luZG93W3Muc3Ryc3RhcnRdKTsKICAgICAgICAgIHMubG9va2FoZWFkLS07CiAgICAgICAgICBzLnN0cnN0YXJ0Kys7CiAgICAgICAgICBpZiAoYmZsdXNoKSB7CiAgICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgZmFsc2UpOwogICAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcy5pbnNlcnQgPSAwOwogICAgICAgIGlmIChmbHVzaCA9PT0gWl9GSU5JU0gpIHsKICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgdHJ1ZSk7CiAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICByZXR1cm4gQlNfRklOSVNIX1NUQVJURUQ7CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gQlNfRklOSVNIX0RPTkU7CiAgICAgICAgfQogICAgICAgIGlmIChzLmxhc3RfbGl0KSB7CiAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIGZhbHNlKTsKICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiBCU19CTE9DS19ET05FOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIENvbmZpZyhnb29kX2xlbmd0aCwgbWF4X2xhenksIG5pY2VfbGVuZ3RoLCBtYXhfY2hhaW4sIGZ1bmMpIHsKICAgICAgICB0aGlzLmdvb2RfbGVuZ3RoID0gZ29vZF9sZW5ndGg7CiAgICAgICAgdGhpcy5tYXhfbGF6eSA9IG1heF9sYXp5OwogICAgICAgIHRoaXMubmljZV9sZW5ndGggPSBuaWNlX2xlbmd0aDsKICAgICAgICB0aGlzLm1heF9jaGFpbiA9IG1heF9jaGFpbjsKICAgICAgICB0aGlzLmZ1bmMgPSBmdW5jOwogICAgICB9CiAgICAgIHZhciBjb25maWd1cmF0aW9uX3RhYmxlOwogICAgICBjb25maWd1cmF0aW9uX3RhYmxlID0gWwogICAgICAgIG5ldyBDb25maWcoMCwgMCwgMCwgMCwgZGVmbGF0ZV9zdG9yZWQpLAogICAgICAgIG5ldyBDb25maWcoNCwgNCwgOCwgNCwgZGVmbGF0ZV9mYXN0KSwKICAgICAgICBuZXcgQ29uZmlnK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5zZXJ0ID0gMDsKICAgICAgICBzLm1hdGNoX2xlbmd0aCA9IHMucHJldl9sZW5ndGggPSBNSU5fTUFUQ0ggLSAxOwogICAgICAgIHMubWF0Y2hfYXZhaWxhYmxlID0gMDsKICAgICAgICBzLmluc19oID0gMDsKICAgICAgfQogICAgICBmdW5jdGlvbiBEZWZsYXRlU3RhdGUoKSB7CiAgICAgICAgdGhpcy5zdHJtID0gbnVsbDsKICAgICAgICB0aGlzLnN0YXR1cyA9IDA7CiAgICAgICAgdGhpcy5wZW5kaW5nX2J1ZiA9IG51bGw7CiAgICAgICAgdGhpcy5wZW5kaW5nX2J1Zl9zaXplID0gMDsKICAgICAgICB0aGlzLnBlbmRpbmdfb3V0ID0gMDsKICAgICAgICB0aGlzLnBlbmRpbmcgPSAwOwogICAgICAgIHRoaXMud3JhcCA9IDA7CiAgICAgICAgdGhpcy5nemhlYWQgPSBudWxsOwogICAgICAgIHRoaXMuZ3ppbmRleCA9IDA7CiAgICAgICAgdGhpcy5tZXRob2QgPSBaX0RFRkxBVEVEOwogICAgICAgIHRoaXMubGFzdF9mbHVzaCA9IC0xOwogICAgICAgIHRoaXMud19zaXplID0gMDsKICAgICAgICB0aGlzLndfYml0cyA9IDA7CiAgICAgICAgdGhpcy53X21hc2sgPSAwOwogICAgICAgIHRoaXMud2luZG93ID0gbnVsbDsKICAgICAgICB0aGlzLndpbmRvd19zaXplID0gMDsKICAgICAgICB0aGlzLnByZXYgPSBudWxsOwogICAgICAgIHRoaXMuaGVhZCA9IG51bGw7CiAgICAgICAgdGhpcy5pbnNfaCA9IDA7CiAgICAgICAgdGhpcy5oYXNoX3NpemUgPSAwOwogICAgICAgIHRoaXMuaGFzaF9iaXRzID0gMDsKICAgICAgICB0aGlzLmhhc2hfbWFzayA9IDA7CiAgICAgICAgdGhpcy5oYXNoX3NoaWZ0ID0gMDsKICAgICAgICB0aGlzLmJsb2NrX3N0YXJ0ID0gMDsKICAgICAgICB0aGlzLm1hdGNoX2xlbmd0aCA9IDA7CiAgICAgICAgdGhpcy5wcmV2X21hdGNoID0gMDsKICAgICAgICB0aGlzLm1hdGNoX2F2YWlsYWJsZSA9IDA7CiAgICAgICAgdGhpcy5zdHJzdGFydCA9IDA7CiAgICAgICAgdGhpcy5tYXRjaF9zdGFydCA9IDA7CiAgICAgICAgdGhpcy5sb29rYWhlYWQgPSAwOwogICAgICAgIHRoaXMucHJldl9sZW5ndGggPSAwOwogICAgICAgIHRoaXMubWF4X2NoYWluX2xlbmd0aCA9IDA7CiAgICAgICAgdGhpcy5tYXhfbGF6eV9tYXRjaCA9IDA7CiAgICAgICAgdGhpcy5sZXZlbCA9IDA7CiAgICAgICAgdGhpcy5zdHJhdGVneSA9IDA7CiAgICAgICAgdGhpcy5nb29kX21hdGNoID0gMDsKICAgICAgICB0aGlzLm5pY2VfbWF0Y2ggPSAwOwogICAgICAgIHRoaXMuZHluX2x0cmVlID0gbmV3IHV0aWxzLkJ1ZjE2KEhFQVBfU0laRSAqIDIpOwogICAgICAgIHRoaXMuZHluX2R0cmVlID0gbmV3IHV0aWxzLkJ1ZjE2KCgyICogRF9DT0RFUyArIDEpICogMik7CiAgICAgICAgdGhpcy5ibF90cmVlID0gbmV3IHV0aWxzLkJ1ZjE2KCgyICogQkxfQ09ERVMgKyAxKSAqIDIpOwogICAgICAgIHplcm8odGhpcy5keW5fbHRyZWUpOwogICAgICAgIHplcm8odGhpcy5keW5fZHRyZWUpOwogICAgICAgIHplcm8odGhpcy5ibF90cmVlKTsKICAgICAgICB0aGlzLmxfZGVzYyA9IG51bGw7CiAgICAgICAgdGhpcy5kX2Rlc2MgPSBudWxsOwogICAgICAgIHRoaXMuYmxfZGVzYyA9IG51bGw7CiAgICAgICAgdGhpcy5ibF9jb3VudCA9IG5ldyB1dGlscy5CdWYxNihNQVhfQklUUyArIDEpOwogICAgICAgIHRoaXMuaGVhcCA9IG5ldyB1dGlscy5CdWYxNigyICogTF9DT0RFUyArIDEpOwogICAgICAgIHplcm8odGhpcy5oZWFwKTsKICAgICAgICB0aGlzLmhlYXBfbGVuID0gMDsKICAgICAgICB0aGlzLmhlYXBfbWF4ID0gMDsKICAgICAgICB0aGlzLmRlcHRoID0gbmV3IHV0aWxzLkJ1ZjE2KDIgKiBMX0NPREVTICsgMSk7CiAgICAgICAgemVybyh0aGlzLmRlcHRoKTsKICAgICAgICB0aGlzLmxfYnVmID0gMDsKICAgICAgICB0aGlzLmxpdF9idWZzaXplID0gMDsKICAgICAgICB0aGlzLmxhc3RfbGl0ID0gMDsKICAgICAgICB0aGlzLmRfYnVmID0gMDsKICAgICAgICB0aGlzLm9wdF9sZW4gPSAwOwogICAgICAgIHRoaXMuc3RhdGljX2xlbiA9IDA7CiAgICAgICAgdGhpcy5tYXRjaGVzID0gMDsKICAgICAgICB0aGlzLmluc2VydCA9IDA7CiAgICAgICAgdGhpcy5iaV9idWYgPSAwOwogICAgICAgIHRoaXMuYmlfdmFsaWQgPSAwOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGRlZmxhdGVSZXNldEtlZXAoc3RybSkgewogICAgICAgIHZhciBzOwogICAgICAgIGlmICghc3RybSB8fCAhc3RybS5zdGF0ZSkgewogICAgICAgICAgcmV0dXJuIGVycihzdHJtLCBaX1NUUkVBTV9FUlJPUik7CiAgICAgICAgfQogICAgICAgIHN0cm0udG90YWxfaW4gPSBzdHJtLnRvdGFsX291dCA9IDA7CiAgICAgICAgc3RybS5kYXRhX3R5cGUgPSBaX1VOS05PV047CiAgICAgICAgcyA9IHN0cm0uc3RhdGU7CiAgICAgICAgcy5wZW5kaW5nID0gMDsKICAgICAgICBzLnBlbmRpbmdfb3V0ID0gMDsKICAgICAgICBpZiAocy53cmFwIDwgMCkgewogICAgICAgICAgcy53cmFwID0gLXMud3JhcDsKICAgICAgICB9CiAgICAgICAgcy5zdGF0dXMgPSBzLndyYXAgPyBJTklUX1NUQVRFIDogQlVTWV9TVEFURTsKICAgICAgICBzdHJtLmFkbGVyID0gcy53cmFwID09PSAyID8gMCA6IDE7CiAgICAgICAgcy5sYXN0X2ZsdXNoID0gWl9OT19GTFVTSDsKICAgICAgICB0cmVlcy5fdHJfaW5pdChzKTsKICAgICAgICByZXR1cm4gWl9PSzsKICAgICAgfQogICAgICBmdW5jdGlvbiBkZWZsYXRlUmVzZXQoc3RybSkgewogICAgICAgIHZhciByZXQgPSBkZWZsYXRlUmVzZXRLZWVwKHN0cm0pOwogICAgICAgIGlmIChyZXQgPT09IFpfT0spIHsKICAgICAgICAgIGxtX2luaXQoc3RybS5zdGF0ZSk7CiAgICAgICAgfQogICAgICAgIHJldHVybiByZXQ7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZGVmbGF0ZVNldEhlYWRlcihzdHJtLCBoZWFkKSB7CiAgICAgICAgaWYgKCFzdHJtIHx8ICFzdHJtLnN0YXRlKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIGlmIChzdHJtLnN0YXRlLndyYXAgIT09IDIpIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgc3RybS5zdGF0ZS5nemhlYWQgPSBoZWFkOwogICAgICAgIHJldHVybiBaX09LOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGRlZmxhdGVJbml0MihzdHJtLCBsZXZlbCwgbWV0aG9kLCB3aW5kb3dCaXRzLCBtZW1MZXZlbCwgc3RyYXRlZ3kpIHsKICAgICAgICBpZiAoIXN0cm0pIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgdmFyIHdyYXAgPSAxOwogICAgICAgIGlmIChsZXZlbCA9PT0gWl9ERUZBVUxUX0NPTVBSRVNTSU9OKSB7CiAgICAgICAgICBsZXZlbCA9IDY7CiAgICAgICAgfQogICAgICAgIGlmICh3aW5kb3dCaXRzIDwgMCkgewogICAgICAgICAgd3JhcCA9IDA7CiAgICAgICAgICB3aW5kb3dCaXRzID0gLXdpbmRvd0JpdHM7CiAgICAgICAgfSBlbHNlIGlmICh3aW5kb3dCaXRzID4gMTUpIHsKICAgICAgICAgIHdyYXAgPSAyOwogICAgICAgICAgd2luZG93Qml0cyAtPSAxNjsKICAgICAgICB9CiAgICAgICAgaWYgKG1lbUxldmVsIDwgMSB8fCBtZW1MZXZlbCA+IE1BWF9NRU1fTEVWRUwgfHwgbWV0aG9kICE9PSBaX0RFRkxBVEVEIHx8IHdpbmRvd0JpdHMgPCA4IHx8IHdpbmRvd0JpdHMgPiAxNSB8fCBsZXZlbCA8IDAgfHwgbGV2ZWwgPiA5IHx8IHN0cmF0ZWd5IDwgMCB8fCBzdHJhdGVneSA+IFpfRklYRUQpIHsKICAgICAgICAgIHJldHVybiBlcnIoc3RybSwgWl9TVFJFQU1fRVJST1IpOwogICAgICAgIH0KICAgICAgICBpZiAod2luZG93Qml0cyA9PT0gOCkgewogICAgICAgICAgd2luZG93Qml0cyA9IDk7CiAgICAgICAgfQogICAgICAgIHZhciBzID0gbmV3IERlZmxhdGVTdGF0ZSgpOwogICAgICAgIHN0cm0uc3RhdGUgPSBzOwogICAgICAgIHMuc3RybSA9IHN0cm07CiAgICAgICAgcy53cmFwID0gd3JhcDsKICAgICAgICBzLmd6aGVhZCA9IG51bGw7CiAgICAgICAgcy53X2JpdHMgPSB3aW5kb3dCaXRzOwogICAgICAgIHMud19zaXplID0gMSA8PCBzLndfYml0czsKICAgICAgICBzLndfbWFzayA9IHMud19zaXplIC0gMTsKICAgICAgICBzLmhhc2hfYml0cyA9IG1lbUxldmVsICsgNzsKICAgICAgICBzLmhhc2hfc2l6ZSA9IDEgPDwgcy5oYXNoX2JpdHM7CiAgICAgICAgcy5oYXNoX21hc2sgPSBzLmhhc2hfc2l6ZSAtIDE7CiAgICAgICAgcy5oYXNoX3NoaWZ0ID0gfn4oKHMuaGFzaF9iaXRzICsgTUlOX01BVENIIC0gMSkgLyBNSU5fTUFUQ0gpOwogICAgICAgIHMud2luZ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1fRVJST1IpIDogWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIHMgPSBzdHJtLnN0YXRlOwogICAgICAgIGlmICghc3RybS5vdXRwdXQgfHwgIXN0cm0uaW5wdXQgJiYgc3RybS5hdmFpbF9pbiAhPT0gMCB8fCBzLnN0YXR1cyA9PT0gRklOSVNIX1NUQVRFICYmIGZsdXNoICE9PSBaX0ZJTklTSCkgewogICAgICAgICAgcmV0dXJuIGVycihzdHJtLCBzdHJtLmF2YWlsX291dCA9PT0gMCA/IFpfQlVGX0VSUk9SIDogWl9TVFJFQU1fRVJST1IpOwogICAgICAgIH0KICAgICAgICBzLnN0cm0gPSBzdHJtOwogICAgICAgIG9sZF9mbHVzaCA9IHMubGFzdF9mbHVzaDsKICAgICAgICBzLmxhc3RfZmx1c2ggPSBmbHVzaDsKICAgICAgICBpZiAocy5zdGF0dXMgPT09IElOSVRfU1RBVEUpIHsKICAgICAgICAgIGlmIChzLndyYXAgPT09IDIpIHsKICAgICAgICAgICAgc3RybS5hZGxlciA9IDA7CiAgICAgICAgICAgIHB1dF9ieXRlKHMsIDMxKTsKICAgICAgICAgICAgcHV0X2J5dGUocywgMTM5KTsKICAgICAgICAgICAgcHV0X2J5dGUocywgOCk7CiAgICAgICAgICAgIGlmICghcy5nemhlYWQpIHsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCAwKTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCAwKTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCAwKTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCAwKTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCAwKTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCBzLmxldmVsID09PSA5ID8gMiA6IHMuc3RyYXRlZ3kgPj0gWl9IVUZGTUFOX09OTFkgfHwgcy5sZXZlbCA8IDIgPyA0IDogMCk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgT1NfQ09ERSk7CiAgICAgICAgICAgICAgcy5zdGF0dXMgPSBCVVNZX1NUQVRFOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHB1dF9ieXRlKHMsIChzLmd6aGVhZC50ZXh0ID8gMSA6IDApICsgKHMuZ3poZWFkLmhjcmMgPyAyIDogMCkgKyAoIXMuZ3poZWFkLmV4dHJhID8gMCA6IDQpICsgKCFzLmd6aGVhZC5uYW1lID8gMCA6IDgpICsgKCFzLmd6aGVhZC5jb21tZW50ID8gMCA6IDE2KSk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgcy5nemhlYWQudGltZSAmIDI1NSk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgcy5nemhlYWQudGltZSA+PiA4ICYgMjU1KTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCBzLmd6aGVhZC50aW1lID4+IDE2ICYgMjU1KTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCBzLmd6aGVhZC50aW1lID4+IDI0ICYgMjU1KTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCBzLmxldmVsID09PSA5ID8gMiA6IHMuc3RyYXRlZ3kgPj0gWl9IVUZGTUFOX09OTFkgfHwgcy5sZXZlbCA8IDIgPyA0IDogMCk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgcy5nemhlYWQub3MgJiAyNTUpOwogICAgICAgICAgICAgIGlmIChzLmd6aGVhZC5leHRyYSAmJiBzLmd6aGVhZC5leHRyYS5sZW5ndGgpIHsKICAgICAgICAgICAgICAgIHB1dF9ieXRlKHMsIHMuZ3poZWFkLmV4dHJhLmxlbmd0aCAmIDI1NSk7CiAgICAgICAgICAgICAgICBwdXRfYnl0ZShzLCBzLmd6aGVhZC5leHRyYS5sZW5ndGggPj4gOCAmIDI1NSk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGlmIChzLmd6aGVhZC5oY3JjKSB7CiAgICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gY3JjMzIyKHN0cm0uYWRsZXIsIHMucGVuZGluZ19idWYsIHMucGVuZGluZywgMCk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIHMuZ3ppbmRleCA9IDA7CiAgICAgICAgICAgICAgcy5zdGF0dXMgPSBFWFRSQV9TVEFURTsKICAgICAgICAgICAgfQogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgdmFyIGhlYWRlciA9IFpfREVGTEFURUQgKyAocy53X2JpdHMgLSA4IDw8IDQpIDw8IDg7CiAgICAgICAgICAgIHZhciBsZXZlbF9mbGFncyA9IC0xOwogICAgICAgICAgICBpZiAocy5zdHJhdGVneSA+PSBaX0hVRkZNQU5fT05MWSB8fCBzLmxldmVsIDwgMikgewogICAgICAgICAgICAgIGxldmVsX2ZsYWdzID0gMDsKICAgICAgICAgICAgfSBlbHNlIGlmIChzLmxldmVsIDwgNikgewogICAgICAgICAgICAgIGxldmVsX2ZsYWdzID0gMTsKICAgICAgICAgICAgfSBlbHNlIGlmIChzLmxldmVsID09PSA2KSB7CiAgICAgICAgICAgICAgbGV2ZWxfZmxhZ3MgPSAyOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIGxldmVsX2ZsYWdzID0gMzsKICAgICAgICAgICAgfQogICAgICAgICAgICBoZWFkZXIgfD0gbGV2ZWxfZmxhZ3MgPDwgNjsKICAgICAgICAgICAgaWYgKHMuc3Ryc3RhcnQgIT09IDApIHsKICAgICAgICAgICAgICBoZWFkZXIgfD0gUFJFU0VUX0RJQ1Q7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaGVhZGVyICs9IDMxIC0gaGVhZGVyICUgMzE7CiAgICAgICAgICAgIHMuc3RhdHVzID0gQlVTWV9TVEFURTsKICAgICAgICAgICAgcHV0U2hvcnRNU0IocywgaGVhZGVyKTsKICAgICAgICAgICAgaWYgKHMuc3Ryc3RhcnQgIT09IDApIHsKICAgICAgICAgICAgICBwdXRTaG9ydE1TQihzLCBzdHJtLmFkbGVyID4+PiAxNik7CiAgICAgICAgICAgICAgcHV0U2hvcnRNU0Iocywgc3RybS5hZGxlciAmIDY1NTM1KTsKICAgICAgICAgICAgfQogICAgICAgICAgICBzdHJtLmFkbGVyID0gMTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKHMuc3RhdHVzID09PSBFWFRSQV9TVEFURSkgewogICAgICAgICAgaWYgKHMuZ3poZWFkLmV4dHJhKSB7CiAgICAgICAgICAgIGJlZyA9IHMucGVuZGluZzsKICAgICAgICAgICAgd2hpbGUgKHMuZ3ppbmRleCA8IChzLmd6aGVhZC5leHRyYS5sZW5ndGggJiA2NTUzNSkpIHsKICAgICAgICAgICAgICBpZiAocy5wZW5kaW5nID09PSBzLnBlbmRpbmdfYnVmX3NpemUpIHsKICAgICAgICAgICAgICAgIGlmIChzLmd6aGVhZC5oY3JjICYmIHMucGVuZGluZyA+IGJlZykgewogICAgICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gY3JjMzIyKHN0cm0uYWRsZXIsIHMucGVuZGluZ19idWYsIHMucGVuZGluZyAtIGJlZywgYmVnKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGZsdXNoX3BlbmRpbmcoc3RybSk7CiAgICAgICAgICAgICAgICBiZWcgPSBzLnBlbmRpbmc7CiAgICAgICAgICAgICAgICBpZiAocy5wZW5kaW5nID09PSBzLnBlbmRpbmdfYnVmX3NpemUpIHsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIHB1dF9ieXRlKHMsIHMuZ3poZWFkLmV4dHJhW3MuZ3ppbmRleF0gJiAyNTUpOwogICAgICAgICAgICAgIHMuZ3ppbmRleCsrOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzLmd6aGVhZC5oY3JjICYmIHMucGVuZGluZyA+IGJlZykgewogICAgICAgICAgICAgIHN0cm0uYWRsZXIgPSBjcmMzMjIoc3RybS5hZGxlciwgcy5wZW5kaW5nX2J1Ziwgcy5wZW5kaW5nIC0gYmVnLCBiZWcpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzLmd6aW5kZXggPT09IHMuZ3poZWFkLmV4dHJhLmxlbmd0aCkgewogICAgICAgICAgICAgIHMuZ3ppbmRleCA9IDA7CiAgICAgICAgICAgICAgcy5zdGF0dXMgPSBOQU1FX1NUQVRFOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBzLnN0YXR1cyA9IE5BTUVfU1RBVEU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChzLnN0YXR1cyA9PT0gTkFNRV9TVEFURSkgewogICAgICAgICAgaWYgKHMuZ3poZWFkLm5hbWUpIHsKICAgICAgICAgICAgYmVnID0gcy5wZW5kaW5nOwogICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgaWYgKHMucGVuZGluZyA9PT0gcy5wZW5kaW5nX2J1Zl9zaXplKSB7CiAgICAgICAgICAgICAgICBpZiAocy5nemhlYWQuaGNyYyAmJiBzLnBlbmRpbmcgPiBiZWcpIHsKICAgICAgICAgICAgICAgICAgc3RybS5hZGxlciA9IGNyYzMyMihzdHJtLmFkbGVyLCBzLnBlbmRpbmdfYnVmLCBzLnBlbmRpbmcgLSBiZWcsIGJlZyk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBmbHVzaF9wZW5kaW5nKHN0cm0pOwogICAgICAgICAgICAgICAgYmVnID0gcy5wZW5kaW5nOwogICAgICAgICAgICAgICAgaWYgKHMucGVuZGluZyA9PT0gcy5wZW5kaW5nX2J1Zl9zaXplKSB7CiAgICAgICAgICAgICAgICAgIHZhbCA9IDE7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBpZiAocy5nemluZGV4IDwgcy5nemhlYWQubmFtZS5sZW5ndGgpIHsKICAgICAgICAgICAgICAgIHZhbCA9IHMuZ3poZWFkLm5hbWUuY2hhckNvZGVBdChzLmd6aW5kZXgrKykgJiAyNTU7CiAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIHZhbCA9IDA7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIHB1dF9ieXRlKHMsIHZhbCk7CiAgICAgICAgICAgIH0gd2hpbGUgKHZhbCAhPT0gMCk7CiAgICAgICAgICAgIGlmIChzLmd6aGVhZC5oY3JjICYmIHMucGVuZGluZyA+IGJlZykgewogICAgICAgICAgICAgIHN0cm0uYWRsZXIgPSBjcmMzMjIoc3RybS5hZGxlciwgcy5wZW5kaW5nX2J1Ziwgcy5wZW5kaW5nIC0gYmVnLCBiZWcpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmICh2YWwgPT09IDApIHsKICAgICAgICAgICAgICBzLmd6aW5kZXggPSAwOwogICAgICAgICAgICAgIHMuc3RhdHVzID0gQ09NTUVOVF9TVEFURTsKICAgICAgICAgICAgfQogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcy5zdGF0dXMgPSBDT01NRU5UX1NUQVRFOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAocy5zdGF0dXMgPT09IENPTU1FTlRfU1RBVEUpIHsKICAgICAgICAgIGlmIChzLmd6aGVhZC5jb21tZW50KSB7CiAgICAgICAgICAgIGJlZyA9IHMucGVuZGluZzsKICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgIGlmIChzLnBlbmRpbmcgPT09IHMucGVuZGluZ19idWZfc2l6ZSkgewogICAgICAgICAgICAgICAgaWYgKHMuZ3poZWFkLmhjcmMgJiYgcy5wZW5kaW5nID4gYmVnKSB7CiAgICAgICAgICAgICAgICAgIHN0cm0uYWRsZXIgPSBjcmMzMjIoc3RybS5hZGxlciwgcy5wZW5kaW5nX2J1Ziwgcy5wZW5kaW5nIC0gYmVnLCBiZWcpOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgZmx1c2hfcGVuZGluZyhzdHJtKTsKICAgICAgICAgICAgICAgIGJlZyA9IHMucGVuZGluZzsKICAgICAgICAgICAgICAgIGlmIChzLnBlbmRpbmcgPT09IHMucGVuZGluZ19idWZfc2l6ZSkgewogICAgICAgICAgICAgICAgICB2YWwgPSAxOwogICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgaWYgKHMuZ3ppbmRleCA8IHMuZ3poZWFkLmNvbW1lbnQubGVuZ3RoKSB7CiAgICAgICAgICAgICAgICB2YWwgPSBzLmd6aGVhZC5jb21tZW50LmNoYXJDb2RlQXQocy5nemluZGV4KyspICYgMjU1OwogICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICB2YWwgPSAwOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBwdXRfYnl0ZShzLCB2YWwpOwogICAgICAgICAgICB9IHdoaWxlICh2YWwgIT09IDApOwogICAgICAgICAgICBpZiAocy5nemhlYWQuaGNyYyAmJiBzLnBlbmRpbmcgPiBiZWcpIHsKICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gY3JjMzIyKHN0cm0uYWRsZXIsIHMucGVuZGluZ19idWYsIHMucGVuZGluZyAtIGJlZywgYmVnKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAodmFsID09PSAwKSB7CiAgICAgICAgICAgICAgcy5zdGF0dXMgPSBIQ1JDX1NUQVRFOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBzLnN0YXR1cyA9IEhDUkNfU1RBVEU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChzLnN0YXR1cyA9PT0gSENSQ19TVEFURSkgewogICAgICAgICAgaWYgKHMuZ3poZWFkLmhjcmMpIHsKICAgICAgICAgICAgaWYgKHMucGVuZGluZyArIDIgPiBzLnBlbmRpbmdfYnVmX3NpemUpIHsKICAgICAgICAgICAgICBmbHVzaF9wZW5kaW5nKHN0cm0pOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzLnBlbmRpbmcgKyAyIDw9IHMucGVuZGluZ19idWZfc2l6ZSkgewogICAgICAgICAgICAgIHB1dF9ieXRlKHMsIHN0cm0uYWRsZXIgJiAyNTUpOwogICAgICAgICAgICAgIHB1dF9ieXRlKHMsIHN0cm0uYWRsZXIgPj4gOCAmIDI1NSk7CiAgICAgICAgICAgICAgc3RybS5hZGxlciA9IDA7CiAgICAgICAgICAgICAgcy5zdGF0dXMgPSBCVVNZX1NUQVRFOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBzLnN0YXR1cyA9IEJVU1lfU1RBVEU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChzLnBlbmRpbmcgIT09IDApIHsKICAgICAgICAgIGZsdXNoX3BlbmRpbmcoc3RybSk7CiAgICAgICAgICBpZiAoc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcy5sYXN0X2ZsdXNoID0gLTE7CiAgICAgICAgICAgIHJldHVybiBaX09LOwogICAgICAgICAgfQogICAgICAgIH0gZWxzZSBpZiAoc3RybS5hdmFpbF9pbiA9PT0gMCAmJiByYW5rKGZsdXNoKSA8PSByYW5rKG9sZF9mbHVzaCkgJiYgZmx1c2ggIT09IFpfRklOSVNIKSB7CiAgICAgICAgICByZXR1cm4gZXJyKHN0cm0sIFpfQlVGX0VSUk9SKTsKICAgICAgICB9CiAgICAgICAgaWYgKHMuc3RhdHVzID09PSBGSU5JU0hfU1RBVEUgJiYgc3RybS5hdmFpbF9pbiAhPT0gMCkgewogICAgICAgICAgcmV0dXJuIGVycihzdHJtLCBaX0JVRl9FUlJPUik7CiAgICAgICAgfQogICAgICAgIGlmIChzdHJtLmF2YWlsX2luICE9PSAwIHx8IHMubG9va2FoZWFkICE9PSAwIHx8IGZsdXNoICE9PSBaX05PX0ZMVVNIICYmIHM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thaGVhZCA9PT0gMCkgewogICAgICAgICAgICAgICAgICBzLnN0cnN0YXJ0ID0gMDsKICAgICAgICAgICAgICAgICAgcy5ibG9ja19zdGFydCA9IDA7CiAgICAgICAgICAgICAgICAgIHMuaW5zZXJ0ID0gMDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZmx1c2hfcGVuZGluZyhzdHJtKTsKICAgICAgICAgICAgaWYgKHN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgICAgcy5sYXN0X2ZsdXNoID0gLTE7CiAgICAgICAgICAgICAgcmV0dXJuIFpfT0s7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKGZsdXNoICE9PSBaX0ZJTklTSCkgewogICAgICAgICAgcmV0dXJuIFpfT0s7CiAgICAgICAgfQogICAgICAgIGlmIChzLndyYXAgPD0gMCkgewogICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VORDsKICAgICAgICB9CiAgICAgICAgaWYgKHMud3JhcCA9PT0gMikgewogICAgICAgICAgcHV0X2J5dGUocywgc3RybS5hZGxlciAmIDI1NSk7CiAgICAgICAgICBwdXRfYnl0ZShzLCBzdHJtLmFkbGVyID4+IDggJiAyNTUpOwogICAgICAgICAgcHV0X2J5dGUocywgc3RybS5hZGxlciA+PiAxNiAmIDI1NSk7CiAgICAgICAgICBwdXRfYnl0ZShzLCBzdHJtLmFkbGVyID4+IDI0ICYgMjU1KTsKICAgICAgICAgIHB1dF9ieXRlKHMsIHN0cm0udG90YWxfaW4gJiAyNTUpOwogICAgICAgICAgcHV0X2J5dGUocywgc3RybS50b3RhbF9pbiA+PiA4ICYgMjU1KTsKICAgICAgICAgIHB1dF9ieXRlKHMsIHN0cm0udG90YWxfaW4gPj4gMTYgJiAyNTUpOwogICAgICAgICAgcHV0X2J5dGUocywgc3RybS50b3RhbF9pbiA+PiAyNCAmIDI1NSk7Ci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b25hcnkpIHsKICAgICAgICB2YXIgZGljdExlbmd0aCA9IGRpY3Rpb25hcnkubGVuZ3RoOwogICAgICAgIHZhciBzOwogICAgICAgIHZhciBzdHIsIG47CiAgICAgICAgdmFyIHdyYXA7CiAgICAgICAgdmFyIGF2YWlsOwogICAgICAgIHZhciBuZXh0OwogICAgICAgIHZhciBpbnB1dDsKICAgICAgICB2YXIgdG1wRGljdDsKICAgICAgICBpZiAoIXN0cm0gfHwgIXN0cm0uc3RhdGUpIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgcyA9IHN0cm0uc3RhdGU7CiAgICAgICAgd3JhcCA9IHMud3JhcDsKICAgICAgICBpZiAod3JhcCA9PT0gMiB8fCB3cmFwID09PSAxICYmIHMuc3RhdHVzICE9PSBJTklUX1NUQVRFIHx8IHMubG9va2FoZWFkKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIGlmICh3cmFwID09PSAxKSB7CiAgICAgICAgICBzdHJtLmFkbGVyID0gYWRsZXIzMihzdHJtLmFkbGVyLCBkaWN0aW9uYXJ5LCBkaWN0TGVuZ3RoLCAwKTsKICAgICAgICB9CiAgICAgICAgcy53cmFwID0gMDsKICAgICAgICBpZiAoZGljdExlbmd0aCA+PSBzLndfc2l6ZSkgewogICAgICAgICAgaWYgKHdyYXAgPT09IDApIHsKICAgICAgICAgICAgemVybyhzLmhlYWQpOwogICAgICAgICAgICBzLnN0cnN0YXJ0ID0gMDsKICAgICAgICAgICAgcy5ibG9ja19zdGFydCA9IDA7CiAgICAgICAgICAgIHMuaW5zZXJ0ID0gMDsKICAgICAgICAgIH0KICAgICAgICAgIHRtcERpY3QgPSBuZXcgdXRpbHMuQnVmOChzLndfc2l6ZSk7CiAgICAgICAgICB1dGlscy5hcnJheVNldCh0bXBEaWN0LCBkaWN0aW9uYXJ5LCBkaWN0TGVuZ3RoIC0gcy53X3NpemUsIHMud19zaXplLCAwKTsKICAgICAgICAgIGRpY3Rpb25hcnkgPSB0bXBEaWN0OwogICAgICAgICAgZGljdExlbmd0aCA9IHMud19zaXplOwogICAgICAgIH0KICAgICAgICBhdmFpbCA9IHN0cm0uYXZhaWxfaW47CiAgICAgICAgbmV4dCA9IHN0cm0ubmV4dF9pbjsKICAgICAgICBpbnB1dCA9IHN0cm0uaW5wdXQ7CiAgICAgICAgc3RybS5hdmFpbF9pbiA9IGRpY3RMZW5ndGg7CiAgICAgICAgc3RybS5uZXh0X2luID0gMDsKICAgICAgICBzdHJtLmlucHV0ID0gZGljdGlvbmFyeTsKICAgICAgICBmaWxsX3dpbmRvdyhzKTsKICAgICAgICB3aGlsZSAocy5sb29rYWhlYWQgPj0gTUlOX01BVENIKSB7CiAgICAgICAgICBzdHIgPSBzLnN0cnN0YXJ0OwogICAgICAgICAgbiA9IHMubG9va2FoZWFkIC0gKE1JTl9NQVRDSCAtIDEpOwogICAgICAgICAgZG8gewogICAgICAgICAgICBzLmluc19oID0gKHMuaW5zX2ggPDwgcy5oYXNoX3NoaWZ0IF4gcy53aW5kb3dbc3RyICsgTUlOX01BVENIIC0gMV0pICYgcy5oYXNoX21hc2s7CiAgICAgICAgICAgIHMucHJldltzdHIgJiBzLndfbWFza10gPSBzLmhlYWRbcy5pbnNfaF07CiAgICAgICAgICAgIHMuaGVhZFtzLmluc19oXSA9IHN0cjsKICAgICAgICAgICAgc3RyKys7CiAgICAgICAgICB9IHdoaWxlICgtLW4pOwogICAgICAgICAgcy5zdHJzdGFydCA9IHN0cjsKICAgICAgICAgIHMubG9va2FoZWFkID0gTUlOX01BVENIIC0gMTsKICAgICAgICAgIGZpbGxfd2luZG93KHMpOwogICAgICAgIH0KICAgICAgICBzLnN0cnN0YXJ0ICs9IHMubG9va2FoZWFkOwogICAgICAgIHMuYmxvY2tfc3RhcnQgPSBzLnN0cnN0YXJ0OwogICAgICAgIHMuaW5zZXJ0ID0gcy5sb29rYWhlYWQ7C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ChtX3BvcyA9IDA7IG1fcG9zIDwgc3RyX2xlbjsgbV9wb3MrKykgewogICAgICAgICAgYyA9IHN0ci5jaGFyQ29kZUF0KG1fcG9zKTsKICAgICAgICAgIGlmICgoYyAmIDY0NTEyKSA9PT0gNTUyOTYgJiYgbV9wb3MgKyAxIDwgc3RyX2xlbikgewogICAgICAgICAgICBjMiA9IHN0ci5jaGFyQ29kZUF0KG1fcG9zICsgMSk7CiAgICAgICAgICAgIGlmICgoYzIgJiA2NDUxMikgPT09IDU2MzIwKSB7CiAgICAgICAgICAgICAgYyA9IDY1NTM2ICsgKGMgLSA1NTI5NiA8PCAxMCkgKyAoYzIgLSA1NjMyMCk7CiAgICAgICAgICAgICAgbV9wb3MrKzsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgYnVmX2xlbiArPSBjIDwgMTI4ID8gMSA6IGMgPCAyMDQ4ID8gMiA6IGMgPCA2NTUzNiA/IDMgOiA0OwogICAgICAgIH0KICAgICAgICBidWYgPSBuZXcgdXRpbHMuQnVmOChidWZfbGVuKTsKICAgICAgICBmb3IgKGkgPSAwLCBtX3BvcyA9IDA7IGkgPCBidWZfbGVuOyBtX3BvcysrKSB7CiAgICAgICAgICBjID0gc3RyLmNoYXJDb2RlQXQobV9wb3MpOwogICAgICAgICAgaWYgKChjICYgNjQ1MTIpID09PSA1NTI5NiAmJiBtX3BvcyArIDEgPCBzdHJfbGVuKSB7CiAgICAgICAgICAgIGMyID0gc3RyLmNoYXJDb2RlQXQobV9wb3MgKyAxKTsKICAgICAgICAgICAgaWYgKChjMiAmIDY0NTEyKSA9PT0gNTYzMjApIHsKICAgICAgICAgICAgICBjID0gNjU1MzYgKyAoYyAtIDU1Mjk2IDw8IDEwKSArIChjMiAtIDU2MzIwKTsKICAgICAgICAgICAgICBtX3BvcysrOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoYyA8IDEyOCkgewogICAgICAgICAgICBidWZbaSsrXSA9IGM7CiAgICAgICAgICB9IGVsc2UgaWYgKGMgPCAyMDQ4KSB7CiAgICAgICAgICAgIGJ1ZltpKytdID0gMTkyIHwgYyA+Pj4gNjsKICAgICAgICAgICAgYnVmW2krK10gPSAxMjggfCBjICYgNjM7CiAgICAgICAgICB9IGVsc2UgaWYgKGMgPCA2NTUzNikgewogICAgICAgICAgICBidWZbaSsrXSA9IDIyNCB8IGMgPj4+IDEyOwogICAgICAgICAgICBidWZbaSsrXSA9IDEyOCB8IGMgPj4+IDYgJiA2MzsKICAgICAgICAgICAgYnVmW2krK10gPSAxMjggfCBjICYgNjM7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBidWZbaSsrXSA9IDI0MCB8IGMgPj4+IDE4OwogICAgICAgICAgICBidWZbaSsrXSA9IDEyOCB8IGMgPj4+IDEyICYgNjM7CiAgICAgICAgICAgIGJ1ZltpKytdID0gMTI4IHwgYyA+Pj4gNiAmIDYzOwogICAgICAgICAgICBidWZbaSsrXSA9IDEyOCB8IGMgJiA2MzsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIGJ1ZjsKICAgICAgfTsKICAgICAgZnVuY3Rpb24gYnVmMmJpbnN0cmluZyhidWYsIGxlbikgewogICAgICAgIGlmIChsZW4gPCA2NTUzNCkgewogICAgICAgICAgaWYgKGJ1Zi5zdWJhcnJheSAmJiBTVFJfQVBQTFlfVUlBX09LIHx8ICFidWYuc3ViYXJyYXkgJiYgU1RSX0FQUExZX09LKSB7CiAgICAgICAgICAgIHJldHVybiBTdHJpbmcuZnJvbUNoYXJDb2RlLmFwcGx5KG51bGwsIHV0aWxzLnNocmlua0J1ZihidWYsIGxlbikpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICB2YXIgcmVzdWx0ID0gIiI7CiAgICAgICAgZm9yICh2YXIgaSA9IDA7IGkgPCBsZW47IGkrKykgewogICAgICAgICAgcmVzdWx0ICs9IFN0cmluZy5mcm9tQ2hhckNvZGUoYnVmW2ldKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHJlc3VsdDsKICAgICAgfQogICAgICBleHBvcnRzLmJ1ZjJiaW5zdHJpbmcgPSBmdW5jdGlvbihidWYpIHsKICAgICAgICByZXR1cm4gYnVmMmJpbnN0cmluZyhidWYsIGJ1Zi5sZW5ndGgpOwogICAgICB9OwogICAgICBleHBvcnRzLmJpbnN0cmluZzJidWYgPSBmdW5jdGlvbihzdHIpIHsKICAgICAgICB2YXIgYnVmID0gbmV3IHV0aWxzLkJ1Zjgoc3RyLmxlbmd0aCk7CiAgICAgICAgZm9yICh2YXIgaSA9IDAsIGxlbiA9IGJ1Zi5sZW5ndGg7IGkgPCBsZW47IGkrKykgewogICAgICAgICAgYnVmW2ldID0gc3RyLmNoYXJDb2RlQXQoaSk7CiAgICAgICAgfQogICAgICAgIHJldHVybiBidWY7CiAgICAgIH07CiAgICAgIGV4cG9ydHMuYnVmMnN0cmluZyA9IGZ1bmN0aW9uKGJ1ZiwgbWF4KSB7CiAgICAgICAgdmFyIGksIG91dCwgYywgY19sZW47CiAgICAgICAgdmFyIGxlbiA9IG1heCB8fCBidWYubGVuZ3RoOwogICAgICAgIHZhciB1dGYxNmJ1ZiA9IG5ldyBBcnJheShsZW4gKiAyKTsKICAgICAgICBmb3IgKG91dCA9IDAsIGkgPSAwOyBpIDwgbGVuOyApIHsKICAgICAgICAgIGMgPSBidWZbaSsrXTsKICAgICAgICAgIGlmIChjIDwgMTI4KSB7CiAgICAgICAgICAgIHV0ZjE2YnVmW291dCsrXSA9IGM7CiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgfQogICAgICAgICAgY19sZW4gPSBfdXRmOGxlbltjXTsKICAgICAgICAgIGlmIChjX2xlbiA+IDQpIHsKICAgICAgICAgICAgdXRmMTZidWZbb3V0KytdID0gNjU1MzM7CiAgICAgICAgICAgIGkgKz0gY19sZW4gLSAxOwogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgIH0KICAgICAgICAgIGMgJj0gY19sZW4gPT09IDIgPyAzMSA6IGNfbGVuID09PSAzID8gMTUgOiA3OwogICAgICAgICAgd2hpbGUgKGNfbGVuID4gMSAmJiBpIDwgbGVuKSB7CiAgICAgICAgICAgIGMgPSBjIDw8IDYgfCBidWZbaSsrXSAmIDYzOwogICAgICAgICAgICBjX2xlbi0tOwogICAgICAgICAgfQogICAgICAgICAgaWYgKGNfbGVuID4gMSkgewogICAgICAgICAgICB1dGYxNmJ1ZltvdXQrK10gPSA2NTUzMzsKICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoYyA8IDY1NTM2KSB7CiAgICAgICAgICAgIHV0ZjE2YnVmW291dCsrXSA9IGM7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBjIC09IDY1NTM2OwogICAgICAgICAgICB1dGYxNmJ1ZltvdXQrK10gPSA1NTI5NiB8IGMgPj4gMTAgJiAxMDIzOwogICAgICAgICAgICB1dGYxNmJ1ZltvdXQrK10gPSA1NjMyMCB8IGMgJiAxMDIzOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gYnVmMmJpbnN0cmluZyh1dGYxNmJ1Ziwgb3V0KTsKICAgICAgfTsKICAgICAgZXhwb3J0cy51dGY4Ym9yZGVyID0gZnVuY3Rpb24oYnVmLCBtYXgpIHsKICAgICAgICB2YXIgcG9zOwogICAgICAgIG1heCA9IG1heCB8fCBidWYubGVuZ3RoOwogICAgICAgIGlmIChtYXggPiBidWYubGVuZ3RoKSB7CiAgICAgICAgICBtYXggPSBidWYubGVuZ3RoOwogICAgICAgIH0KICAgICAgICBwb3MgPSBtYXggLSAxOwogICAgICAgIHdoaWxlIChwb3MgPj0gMCAmJiAoYnVmW3Bvc10gJiAxOTIpID09PSAxMjgpIHsKICAgICAgICAgIHBvcy0tOwogICAgICAgIH0KICAgICAgICBpZiAocG9zIDwgMCkgewogICAgICAgICAgcmV0dXJuIG1heDsKICAgICAgICB9CiAgICAgICAgaWY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tZXRob2Q6IFpfREVGTEFURUQsCiAgICAgICAgICBjaHVua1NpemU6IDE2Mzg0LAogICAgICAgICAgd2luZG93Qml0czogMTUsCiAgICAgICAgICBtZW1MZXZlbDogOCwKICAgICAgICAgIHN0cmF0ZWd5OiBaX0RFRkFVTFRfU1RSQVRFR1ksCiAgICAgICAgICB0bzogIiIKICAgICAgICB9LCBvcHRpb25zIHx8IHt9KTsKICAgICAgICB2YXIgb3B0ID0gdGhpcy5vcHRpb25zOwogICAgICAgIGlmIChvcHQucmF3ICYmIG9wdC53aW5kb3dCaXRzID4gMCkgewogICAgICAgICAgb3B0LndpbmRvd0JpdHMgPSAtb3B0LndpbmRvd0JpdHM7CiAgICAgICAgfSBlbHNlIGlmIChvcHQuZ3ppcCAmJiBvcHQud2luZG93Qml0cyA+IDAgJiYgb3B0LndpbmRvd0JpdHMgPCAxNikgewogICAgICAgICAgb3B0LndpbmRvd0JpdHMgKz0gMTY7CiAgICAgICAgfQogICAgICAgIHRoaXMuZXJyID0gMDsKICAgICAgICB0aGlzLm1zZyA9ICIiOwogICAgICAgIHRoaXMuZW5kZWQgPSBmYWxzZTsKICAgICAgICB0aGlzLmNodW5rcyA9IFtdOwogICAgICAgIHRoaXMuc3RybSA9IG5ldyBaU3RyZWFtKCk7CiAgICAgICAgdGhpcy5zdHJtLmF2YWlsX291dCA9IDA7CiAgICAgICAgdmFyIHN0YXR1cyA9IHpsaWJfZGVmbGF0ZS5kZWZsYXRlSW5pdDIodGhpcy5zdHJtLCBvcHQubGV2ZWwsIG9wdC5tZXRob2QsIG9wdC53aW5kb3dCaXRzLCBvcHQubWVtTGV2ZWwsIG9wdC5zdHJhdGVneSk7CiAgICAgICAgaWYgKHN0YXR1cyAhPT0gWl9PSykgewogICAgICAgICAgdGhyb3cgbmV3IEVycm9yKG1zZ1tzdGF0dXNdKTsKICAgICAgICB9CiAgICAgICAgaWYgKG9wdC5oZWFkZXIpIHsKICAgICAgICAgIHpsaWJfZGVmbGF0ZS5kZWZsYXRlU2V0SGVhZGVyKHRoaXMuc3RybSwgb3B0LmhlYWRlcik7CiAgICAgICAgfQogICAgICAgIGlmIChvcHQuZGljdGlvbmFyeSkgewogICAgICAgICAgdmFyIGRpY3Q7CiAgICAgICAgICBpZiAodHlwZW9mIG9wdC5kaWN0aW9uYXJ5ID09PSAic3RyaW5nIikgewogICAgICAgICAgICBkaWN0ID0gc3RyaW5ncy5zdHJpbmcyYnVmKG9wdC5kaWN0aW9uYXJ5KTsKICAgICAgICAgIH0gZWxzZSBpZiAodG9TdHJpbmcuY2FsbChvcHQuZGljdGlvbmFyeSkgPT09ICJbb2JqZWN0IEFycmF5QnVmZmVyXSIpIHsKICAgICAgICAgICAgZGljdCA9IG5ldyBVaW50OEFycmF5KG9wdC5kaWN0aW9uYXJ5KTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGRpY3QgPSBvcHQuZGljdGlvbmFyeTsKICAgICAgICAgIH0KICAgICAgICAgIHN0YXR1cyA9IHpsaWJfZGVmbGF0ZS5kZWZsYXRlU2V0RGljdGlvbmFyeSh0aGlzLnN0cm0sIGRpY3QpOwogICAgICAgICAgaWYgKHN0YXR1cyAhPT0gWl9PSykgewogICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IobXNnW3N0YXR1c10pOwogICAgICAgICAgfQogICAgICAgICAgdGhpcy5fZGljdF9zZXQgPSB0cnVlOwogICAgICAgIH0KICAgICAgfQogICAgICBEZWZsYXRlLnByb3RvdHlwZS5wdXNoID0gZnVuY3Rpb24oZGF0YSwgbW9kZSkgewogICAgICAgIHZhciBzdHJtID0gdGhpcy5zdHJtOwogICAgICAgIHZhciBjaHVua1NpemUgPSB0aGlzLm9wdGlvbnMuY2h1bmtTaXplOwogICAgICAgIHZhciBzdGF0dXMsIF9tb2RlOwogICAgICAgIGlmICh0aGlzLmVuZGVkKSB7CiAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgfQogICAgICAgIF9tb2RlID0gbW9kZSA9PT0gfn5tb2RlID8gbW9kZSA6IG1vZGUgPT09IHRydWUgPyBaX0ZJTklTSCA6IFpfTk9fRkxVU0g7CiAgICAgICAgaWYgKHR5cGVvZiBkYXRhID09PSAic3RyaW5nIikgewogICAgICAgICAgc3RybS5pbnB1dCA9IHN0cmluZ3Muc3RyaW5nMmJ1ZihkYXRhKTsKICAgICAgICB9IGVsc2UgaWYgKHRvU3RyaW5nLmNhbGwoZGF0YSkgPT09ICJbb2JqZWN0IEFycmF5QnVmZmVyXSIpIHsKICAgICAgICAgIHN0cm0uaW5wdXQgPSBuZXcgVWludDhBcnJheShkYXRhKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgc3RybS5pbnB1dCA9IGRhdGE7CiAgICAgICAgfQogICAgICAgIHN0cm0ubmV4dF9pbiA9IDA7CiAgICAgICAgc3RybS5hdmFpbF9pbiA9IHN0cm0uaW5wdXQubGVuZ3RoOwogICAgICAgIGRvIHsKICAgICAgICAgIGlmIChzdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICBzdHJtLm91dHB1dCA9IG5ldyB1dGlscy5CdWY4KGNodW5rU2l6ZSk7CiAgICAgICAgICAgIHN0cm0ubmV4dF9vdXQgPSAwOwogICAgICAgICAgICBzdHJtLmF2YWlsX291dCA9IGNodW5rU2l6ZTsKICAgICAgICAgIH0KICAgICAgICAgIHN0YXR1cyA9IHpsaWJfZGVmbGF0ZS5kZWZsYXRlKHN0cm0sIF9tb2RlKTsKICAgICAgICAgIGlmIChzdGF0dXMgIT09IFpfU1RSRUFNX0VORCAmJiBzdGF0dXMgIT09IFpfT0spIHsKICAgICAgICAgICAgdGhpcy5vbkVuZChzdGF0dXMpOwogICAgICAgICAgICB0aGlzLmVuZGVkID0gdHJ1ZTsKICAgICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICAgICAgfQogICAgICAgICAgaWYgKHN0cm0uYXZhaWxfb3V0ID09PSAwIHx8IHN0cm0uYXZhaWxfaW4gPT09IDAgJiYgKF9tb2RlID09PSBaX0ZJTklTSCB8fCBfbW9kZSA9PT0gWl9TWU5DX0ZMVVNIMikpIHsKICAgICAgICAgICAgaWYgKHRoaXMub3B0aW9ucy50byA9PT0gInN0cmluZyIpIHsKICAgICAgICAgICAgICB0aGlzLm9uRGF0YShzdHJpbmdzLmJ1ZjJiaW5zdHJpbmcodXRpbHMuc2hyaW5rQnVmKHN0cm0ub3V0cHV0LCBzdHJtLm5leHRfb3V0KSkpOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHRoaXMub25EYXRhKHV0aWxzLnNocmlua0J1ZihzdHJtLm91dHB1dCwgc3RybS5uZXh0X291dCkpOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfSB3aGlsZSAoKHN0cm0uYXZhaWxfaW4gPiAwIHx8IHN0cm0uYXZhaWxfb3V0ID09PSAwKSAmJiBzdGF0dXMgIT09IFpfU1RSRUFNX0VORCk7CiAgICAgICAgaWYgKF9tb2RlID09PSBaX0ZJTklTSCkgewogICAgICAgICAgc3RhdHVzID0gemxpYl9kZWZsYXRlLmRlZmxhdGVFbmQodGhpcy5zdHJtKTsKICAgICAgICAgIHRoaXMub25FbmQoc3RhdHVzKTsKICAgICAgICAgIHRoaXMuZW5kZWQgPSB0cnVlOwogICAgICAgICAgcmV0dXJuIHN0YXR1cyA9PT0gWl9PSzsKICAgICAgICB9CiAgICAgICAgaWYgKF9tb2RlID09PSBaX1NZTkNfRkxVU0gyKSB7CiAgICAgICAgICB0aGlzLm9uRW5kKFpfT0spOwogICAgICAgICAgc3RybS5hdmFpbF9vdXQgPSAwOwogICAgICAgICAgcmV0dXJuIHRydWU7CiAgICAgICAgfQogICAgICAgIHJldHVybiB0cnVlOwogICAgICB9OwogICAgICBEZWZsYXRlLnByb3RvdHlwZS5vbkRhdGEgPSBmdW5jdGlvbihjaHVuaykgewogICAgICAgIHRoaXMuY2h1bmtzLnB1c2goY2h1bmspOwogICAgICB9OwogICAgICBEZWZsYXRlLnByb3RvdHlwZS5vbkVuZCA9IGZ1bmN0aW9uKHN0YXR1cykgewogICAgICAgIGlmIChzdGF0dXMgPT09IFpfT0spIHsKICAgICAgICAgIGlmICh0aGlzLm9wdGlvbnMudG8gPT09ICJzdHJpbmciKSB7CiAgICAgICAgICAgIHRoaXMucmVzdWx0ID0gdGhpcy5jaHVua3Muam9pbigiIik7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICB0aGlzLnJlc3VsdCA9IHV0aWxzLmZsYXR0ZW5DaHVua3ModGhpcy5jaHVua3MpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICB0aGlzLmNodW5rcyA9IFtdOwogICAgICAgIHRoaXMuZXJyID0gc3RhdHVzOwogICAgICAgIHRoaXMubXNnID0gdGhpcy5zdHJtLm1zZzsKICAgICAgfTsKICAgICAgZnVuY3Rpb24gZGVmbGF0ZShpbnB1dCwgb3B0aW9ucykgewogICAgICAgIHZhciBkZWZsYXRvciA9IG5ldyBEZWZsYXRlKG9wdGlvbnMpOwogICAgICAgIGRlZmxhdG9yLnB1c2goaW5wdXQsIHRydWUpOwogICAgICAgIGlmIChkZWZsYXRvci5lcnIpIHsKICAgICAgICAgIHRocm93IGRlZmxhdG9yLm1zZyB8fCBtc2dbZGVmbGF0b3IuZXJyXTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIGRlZmxhdG9yLnJlc3VsdDsKICAgICAgfQogICAgICBmdW5jdGlvbiBkZWZsYXRlUmF3KGlucHV0LCBvcHRpb25zKSB7CiAgICAgICAgb3B0aW9ucyA9IG9wdGlvbnMgfHwge307CiAgICAgICAgb3B0aW9ucy5yYXcgPSB0cnVlOwogICAgICAgIHJldHVybiBkZWZsYXRlKGlucHV0LCBvcHRpb25zKTsKICAgICAgfQogICAgICBmdW5jdGlvbiBnemlwKGlucHV0LCBvcHRpb25zKSB7CiAgICAgICAgb3B0aW9ucyA9IG9wdGlvbnMgfHwge307CiAgICAgICAgb3B0aW9ucy5nemlwID0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2s7CiAgICAgICAgdmFyIGRtYXNrOwogICAgICAgIHZhciBoZXJlOwogICAgICAgIHZhciBvcDsKICAgICAgICB2YXIgbGVuOwogICAgICAgIHZhciBkaXN0OwogICAgICAgIHZhciBmcm9tOwogICAgICAgIHZhciBmcm9tX3NvdXJjZTsKICAgICAgICB2YXIgaW5wdXQsIG91dHB1dDsKICAgICAgICBzdGF0ZSA9IHN0cm0uc3RhdGU7CiAgICAgICAgX2luID0gc3RybS5uZXh0X2luOwogICAgICAgIGlucHV0ID0gc3RybS5pbnB1dDsKICAgICAgICBsYXN0ID0gX2luICsgKHN0cm0uYXZhaWxfaW4gLSA1KTsKICAgICAgICBfb3V0ID0gc3RybS5uZXh0X291dDsKICAgICAgICBvdXRwdXQgPSBzdHJtLm91dHB1dDsKICAgICAgICBiZWcgPSBfb3V0IC0gKHN0YXJ0IC0gc3RybS5hdmFpbF9vdXQpOwogICAgICAgIGVuZCA9IF9vdXQgKyAoc3RybS5hdmFpbF9vdXQgLSAyNTcpOwogICAgICAgIGRtYXggPSBzdGF0ZS5kbWF4OwogICAgICAgIHdzaXplID0gc3RhdGUud3NpemU7CiAgICAgICAgd2hhdmUgPSBzdGF0ZS53aGF2ZTsKICAgICAgICB3bmV4dCA9IHN0YXRlLnduZXh0OwogICAgICAgIHNfd2luZG93ID0gc3RhdGUud2luZG93OwogICAgICAgIGhvbGQgPSBzdGF0ZS5ob2xkOwogICAgICAgIGJpdHMgPSBzdGF0ZS5iaXRzOwogICAgICAgIGxjb2RlID0gc3RhdGUubGVuY29kZTsKICAgICAgICBkY29kZSA9IHN0YXRlLmRpc3Rjb2RlOwogICAgICAgIGxtYXNrID0gKDEgPDwgc3RhdGUubGVuYml0cykgLSAxOwogICAgICAgIGRtYXNrID0gKDEgPDwgc3RhdGUuZGlzdGJpdHMpIC0gMTsKICAgICAgICB0b3A6CiAgICAgICAgICBkbyB7CiAgICAgICAgICAgIGlmIChiaXRzIDwgMTUpIHsKICAgICAgICAgICAgICBob2xkICs9IGlucHV0W19pbisrXSA8PCBiaXRzOwogICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICBob2xkICs9IGlucHV0W19pbisrXSA8PCBiaXRzOwogICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgfQogICAgICAgICAgICBoZXJlID0gbGNvZGVbaG9sZCAmIGxtYXNrXTsKICAgICAgICAgICAgZG9sZW46CiAgICAgICAgICAgICAgZm9yICg7IDsgKSB7CiAgICAgICAgICAgICAgICBvcCA9IGhlcmUgPj4+IDI0OwogICAgICAgICAgICAgICAgaG9sZCA+Pj49IG9wOwogICAgICAgICAgICAgICAgYml0cyAtPSBvcDsKICAgICAgICAgICAgICAgIG9wID0gaGVyZSA+Pj4gMTYgJiAyNTU7CiAgICAgICAgICAgICAgICBpZiAob3AgPT09IDApIHsKICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBoZXJlICYgNjU1MzU7CiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKG9wICYgMTYpIHsKICAgICAgICAgICAgICAgICAgbGVuID0gaGVyZSAmIDY1NTM1OwogICAgICAgICAgICAgICAgICBvcCAmPSAxNTsKICAgICAgICAgICAgICAgICAgaWYgKG9wKSB7CiAgICAgICAgICAgICAgICAgICAgaWYgKGJpdHMgPCBvcCkgewogICAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtfaW4rK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgbGVuICs9IGhvbGQgJiAoMSA8PCBvcCkgLSAxOwogICAgICAgICAgICAgICAgICAgIGhvbGQgPj4+PSBvcDsKICAgICAgICAgICAgICAgICAgICBiaXRzIC09IG9wOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChiaXRzIDwgMTUpIHsKICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W19pbisrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W19pbisrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBoZXJlID0gZGNvZGVbaG9sZCAmIGRtYXNrXTsKICAgICAgICAgICAgICAgICAgZG9kaXN0OgogICAgICAgICAgICAgICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgICAgICAgICAgICAgb3AgPSBoZXJlID4+PiAyNDsKICAgICAgICAgICAgICAgICAgICAgIGhvbGQgPj4+PSBvcDsKICAgICAgICAgICAgICAgICAgICAgIGJpdHMgLT0gb3A7CiAgICAgICAgICAgICAgICAgICAgICBvcCA9IGhlcmUgPj4+IDE2ICYgMjU1OwogICAgICAgICAgICAgICAgICAgICAgaWYgKG9wICYgMTYpIHsKICAgICAgICAgICAgICAgICAgICAgICAgZGlzdCA9IGhlcmUgJiA2NTUzNTsKICAgICAgICAgICAgICAgICAgICAgICAgb3AgJj0gMTU7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChiaXRzIDwgb3ApIHsKICAgICAgICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W19pbisrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoYml0cyA8IG9wKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W19pbisrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICBkaXN0ICs9IGhvbGQgJiAoMSA8PCBvcCkgLSAxOwogICAgICAgICAgICAgICAgICAgICAgICBpZiAoZGlzdCA+IGRtYXgpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbnZhbGlkIGRpc3RhbmNlIHRvbyBmYXIgYmFjayI7CiAgICAgICAgICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgICAgICAgICBicmVhayB0b3A7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgaG9sZCA+Pj49IG9wOwogICAgICAgICAgICAgICAgICAgICAgICBiaXRzIC09IG9wOwogICAgICAgICAgICAgICAgICAgICAgICBvcCA9IF9vdXQgLSBiZWc7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChkaXN0ID4gb3ApIHsKICAgICAgICAgICAgICAgICAgICAgICAgICBvcCA9IGRpc3QgLSBvcDsKICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAob3AgPiB3aGF2ZSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHN0YXRlLnNhbmUpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW52YWxpZCBkaXN0YW5jZSB0b28gZmFyIGJhY2siOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBicmVhayB0b3A7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgIGZyb20gPSAwOwogICAgICAgICAgICAgICAgICAgICAgICAgIGZyb21fc291cmNlID0gc193aW5kb3c7CiAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHduZXh0ID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tICs9IHdzaXplIC0gb3A7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAob3AgPCBsZW4pIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbGVuIC09IG9wOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBzX3dpbmRvd1tmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IHdoaWxlICgtLW9wKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZnJvbSA9IF9vdXQgLSBkaXN0OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tX3NvdXJjZSA9IG91dHB1dDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKHduZXh0IDwgb3ApIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZyb20gKz0gd3NpemUgKyB3bmV4dCAtIG9wOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgb3AgLT0gd25leHQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAob3AgPCBsZW4pIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbGVuIC09IG9wOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBzX3dpbmRvd1tmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IHdoaWxlICgtLW9wKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZnJvbSA9IDA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmICh3bmV4dCA8IGxlbikgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG9wID0gd25leHQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbGVuIC09IG9wOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gc193aW5kb3dbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IHdoaWxlICgtLW9wKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tID0gX291dCAtIGRpc3Q7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZnJvbV9zb3VyY2UgPSBvdXRwdXQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgZnJvbSArPSB3bmV4dCAtIG9wOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKG9wIDwgbGVuKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxlbiAtPSBvcDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gc193aW5kb3dbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSB3aGlsZSAoLS1vcCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZyb20gPSBfb3V0IC0gZGlzdDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZnJvbV9zb3VyY2UgPSBvdXRwdXQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgIHdoaWxlIChsZW4gPiAyKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IGZyb21fc291cmNlW2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IGZyb21fc291cmNlW2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IGZyb21fc291cmNlW2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBsZW4gLT0gMzsKICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGxlbikgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBmcm9tX3NvdXJjZVtmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGxlbiA+IDEpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBmcm9tX3NvdXJjZVtmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tID0gX291dCAtIGRpc3Q7CiAgICAgICAgICAgICAgICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBvdXRwdXRbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gb3V0cHV0W2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IG91dHB1dFtmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgbGVuIC09IDM7CiAgICAgICAgICAgICAgICAgICAgICAgICAgfSB3aGlsZSAobGVuID4gMik7CiAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGxlbikgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBvdXRwdXRbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChsZW4gPiAxKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gb3V0cHV0W2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKChvcCAmIDY0KSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICBoZXJlID0gZGNvZGVbKGhlcmUgJiA2NTUzNSkgKyAoaG9sZCAmICgxIDw8IG9wKSAtIDEpXTsKICAgICAgICAgICAgICAgICAgICAgICAgY29udGludWUgZG9kaXN0OwogICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW52YWxpZCBkaXN0YW5jZSBjb2RlIjsKICAgICAgICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWsgdG9wOwogICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfSBlbHNlIGlmICgob3AgJiA2NCkgPT09IDApIHsKICAgICAgICAgICAgICAgICAgaGVyZSA9IGxjb2RlWyhoZXJlICYgNjU1MzUpICsgKGhvbGQgJiAoMSA8PCBvcCkgLSAxKV07CiAgICAgICAgICAgICAgICAgIGNvbnRpbnVlIGRvbGVuOwogICAgICAgICAgICAgICAgfSBlbHNlIGlmIChvcCAmIDMyKSB7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBUWVBFOwogICAgICAgICAgICAgICAgICBicmVhayB0b3A7CiAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbnZhbGlkIGxpdGVyYWwvbGVuZ3RoIGNvZGUiOwogICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEOwogICAgICAgICAgICAgICAgICBicmVhayB0b3A7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICB9CiAgICAgICAgICB9IHdoaWxlIChfaW4gPCBsYXN0ICYmIF9vdXQgPCBlbmQpOwogICAgICAgIGxlbiA9IGJpdHMgPj4gMzsKICAgICAgICBfaW4gLT0gbGVuOwogICAgICAgIGJpdHMgLT0gbGVuIDw8IDM7CiAgICAgICAgaG9sZCAmPSAoMSA8PCBiaXRzKSAtIDE7CiAgICAgICAgc3RybS5uZXh0X2luID0gX2luOwogICAgICAgIHN0cm0ubmV4dF9vdXQgPSBfb3V0OwogICAgICAgIHN0cm0uYXZhaWxfaW4gPSBfaW4gPCBsYXN0ID8gNSArIChsYXN0IC0gX2luKSA6IDUgLSAoX2luIC0gbGFzdCk7CiAgICAgICAgc3RybS5hdmFpbF9vdXQgPSBfb3V0IDwgZW5kID8gMjU3ICsgKGVuZCAtIF9vdXQpIDogMjU3IC0gKF9vdXQgLSBlbmQpOwogICAgICAgIHN0YXRlLmhvbGQgPSBob2xkOwogICAgICAgIHN0YXRlLmJpdHMgPSBiaXRzOwogICAgICAgIHJldHVybjsKICAgICAgfTsKICAgIH0KICB9KTsKCiAgLy8gbm9kZV9tb2R1bGVzLy5wbnBtL3Bha29AMS4wLjExL25vZGVfbW9kdWxlcy9wYWtvL2xpYi96bGliL2luZnRyZWVzLmpzCiAgdmFyIHJlcXVpcmVfaW5mdHJlZXMgPSBfX2NvbW1vbkpTKHsKICAgICJub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvaW5mdHJlZXMuanMiKGV4cG9ydHMsIG1vZHVsZSkgewogICAgICBpbml0X2J1ZmZlcl9zaGltKCk7CiAgICAgICJ1c2Ugc3RyaWN0IjsKICAgICAgdmFyIHV0aWxzID0gcmVxdWlyZV9jb21tb24yKCk7CiAgICAgIHZhciBNQVhCSVRTID0gMTU7CiAgICAgIHZhciBFTk9VR0hfTEVOUyA9IDg1MjsKICAgICAgdmFyIEVOT1VHSF9ESVNUUyA9IDU5MjsKICAgICAgdmFyIENPREVTID0gMDsKICAgICAgdmFyIExFTlMgPSAxOwogICAgICB2YXIgRElTVFMgPSAyOwogICAgICB2YXIgbGJhc2UgPSBbCiAgICAgICAgMywKICAgICAgICA0LAogICAgICAgIDUsCiAgICAgICAgNiwKICAgICAgICA3LAogICAgICAgIDgsCiAgICAgICAgOSwKICAgICAgICAxMCwKICAgICAgICAxMSwKICAgICAgICAxMywKICAgICAgICAxNSwKICAgICAgICAxNywKICAgICAgICAxOSwKICAgICAgICAyMywKICAgICAgICAyNywKICAgICAgICAzMSwKICAgICAgICAzNSwKICAgICAgICA0MywKICAgICAgICA1MSwKICAgICAgICA1OSwKICAgICAgICA2NywKICAgICAgICA4MywKICAgICAgICA5OSwKICAgICAgICAxMTUsCiAgICAgICAgMTMxLAogICAgICAgIDE2MywKICAgICAgICAxOTUsCiAgICAgICAgMjI3LAogICAgICAgIDI1OCwKICAgICAgICAwLAogICAgICAgIDAKICAgICAgXTsKICAgICAgdmFyIGxleHQgPSBbCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTcsCiAgICAgICAgMTcsCiAgICAgICAgMTcsCiAgICAgICAgMTcsCiAgICAgICAgMTgsCiAgICAgICAgMTgsCiAgICAgICAgMTgsCiAgICAgICAgMTgsCiAgICAgICAgMTksCiAgICAgICAgMTksCiAgICAgICAgMTksCiAgICAgICAgMTksCiAgICAgICAgMjAsCiAgICAgICAgMjAsCiAgICAgICAgMjAsCiAgICAgICAgMjAsCiAgICAgICAgMjEsCiAgICAgICAgMjEsCiAgICAgICAgMjEsCiAgICAgICAgMjEsCiAgICAgICAgMTYsCiAgICAgICAgNzIsCiAgICAgICAgNzgKICAgICAgXTsKICAgICAgdmFyIGRiYXNlID0gWwogICAgICAgIDEsCiAgICAgICAgMiwKICAgICAgICAzLAogICAgICAgIDQsCiAgICAgICAgNSwKICAgICAgICA3LAogICAgICAgIDksCiAgICAgICAgMTMsCiAgICAgICAgMTcsCiAgICAgICAgMjUsCiAgICAgICAgMzMsCiAgICAgICAgNDksCiAgICAgICAgNjUsCiAgICAgICAgOTcsCiAgICAgICAgMTI5LAogICAgICAgIDE5MywKICAgICAgICAyNTcsCiAgICAgICAgMzg1LAogICAgICAgIDUxMywKICAgICAgICA3NjksCiAgICAgICAgMTAyNSwKICAgICAgICAxNTM3LAogICAgICAgIDIwNDksCiAgICAgICAgMzA3MywKICAgICAgICA0MDk3LAogICAgICAgIDYxNDUsCiAgICAgICAgODE5MywKICAgICAgICAxMjI4OSwKICAgICAgICAxNjM4NSwKICAgICAgICAyNDU3NywKICAgICAgICAwLAogICAgICAgIDAKICAgICAgXTsKICAgICAgdmFyIGRleHQgPSBbCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTcsCiAgICAgICAgMTcsCiAgICAgICAgMTgsCiAgICAgICAgMTgsCiAgICAgICAgMTksCiAgICAgICAgMTksCiAgICAgICAgMjAsCiAgICAgICAgMjAsCiAgICAgICAgMjEsCiAgICAgICAgMjEsCiAgICAgICAgMjIsCiAgICAgICAgMjIsCiAgICAgICAgMjMsCiAgICAgICAgMjMsCiAgICAgICAgMjQsCiAgICAgICAgMjQsCiAgICAgICAgMjUsCiAgICAgICAgMjUsCiAgICAgICAgMjYsCiAgICAgICAgMjYsCiAgICAgICAgMjcsCiAgICAgICAgMjcsCiAgICAgICAgMjgsCiAgICAgICAgMjgsCiAgICAgICAgMjksCiAgICAgICAgMjksCiAgICAgICAgNjQsCiAgICAgICAgNjQKICAgICAgXTsKICAgICAgbW9kdWxlLmV4cG9ydHMgPSBmdW5jdGlvbiBpbmZsYXRlX3RhYmxlKHR5cGUsIGxlbnMsIGxlbnNfaW5kZXgsIGNvZGVzLCB0YWJsZSwgdGFibGVfaW5kZXgsIHdvcmssIG9wdHMpIHsKICAgICAgICB2YXIgYml0cyA9IG9wdHMuYml0czsKICAgICAgICB2YXIgbGVuID0gMDsKICAgICAgICB2YXIgc3ltID0gMDsKICAgICAgICB2YXIgbWluID0gMCwgbWF4ID0gMDsKICAgICAgICB2YXIgcm9vdCA9IDA7CiAgICAgICAgdmFyIGN1cnIgPSAwOwogICAgICAgIHZhciBkcm9wID0gMDsKICAgICAgICB2YXIgbGVmdCA9IDA7CiAgICAgICAgdmFyIHVzZWQgPSAwOwogICAgICAgIHZhciBodWZmID0gMDsKICAgICAgICB2YXIgaW5jcjsKICAgICAgICB2YXIgZmlsbDsKICAgICAgICB2YXIgbG93OwogICAgICAgIHZhciBtYXNrOwogICAgICAgIHZhciBuZXh0OwogICAgICAgIHZhciBiYXNlID0gbnVsbDsKICAgICAgICB2YXIgYmFzZV9pbmRleCA9IDA7CiAgICAgICAgdmFyIGVuZDsKICAgICAgICB2YXIgY291bnQgPSBuZXcgdXRpbHMuQnVmMTYoTUFYQklUUyArIDEpOwogICAgICAgIHZhciBvZmZzID0gbmV3IHV0aWxzLkJ1ZjE2KE1BWEJJVFMgKyAxKTsKICAgICAgICB2YXIgZXh0cmEgPSBudWxsOwogICAgICAgIHZhciBleHRyYV9pbmRleCA9IDA7CiAgICAgICAgdmFyIGhlcmVfYml0cywgaGVyZV9vcCwgaGVyZV92YWw7CiAgICAgICAgZm9yIChsZW4gPSAwOyBsZW4gPD0gTUFYQklUUzsgbGVuKyspIHsKICAgICAgICAgIGNvdW50W2xlbl0gPSAwOwogICAgICAgIH0KICAgICAgICBmb3IgKHN5bSA9IDA7IHN5bSA8IGNvZGVzOyBzeW0rKykgewogICAgICAgICAgY291bnRbbGVuc1tsZW5zX2luZGV4ICsgc3ltXV0rKzsKICAgICAgICB9CiAgICAgICAgcm9vdCA9IGJpdHM7CiAgICAgICAgZm9yIChtYXggPSBNQVhCSVRTOyBtYXggPj0gMTsgbWF4LS0pIHsKICAgICAgICAgIGlmIChjb3VudFttYXhdICE9PSAwKSB7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAocm9vdCA+IG1heCkgewogICAgICAgICAgcm9vdCA9IG1heDsKICAgICAgICB9CiAgICAgICAgaWYgKG1heCA9PT0gMCkgewogICAgICAgICAgdGFibGVbdGFibGVfaW5kZXgrK10gPSAxIDw8IDI0IHwgNjQgPDwgMTYgfCAwOwogICAgICAgICAgdGFibGVbdGFibGVfaW5kZXgrK10gPSAxIDw8IDI0IHwgNjQgPDwgMTYgfCAwOwogICAgICAgICAgb3B0cy5iaXRzID0gMTsKICAgICAgICAgIHJldHVybiAwOwogICAgICAgIH0KICAgICAgICBmb3IgKG1pbiA9IDE7IG1pbiA8IG1heDsgbWluKyspIHsKICAgICAgICAgIGlmIChjb3VudFttaW5dICE9PSAwKSB7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAocm9vdCA8IG1pbikgewogICAgICAgICAgcm9vdCA9IG1pbjsKICAgICAgICB9CiAgICAgICAgbGVmdCA9IDE7CiAgICAgICAgZm9yIChsZW4gPSAxOyBsZW4gPD0gTUFYQklUUzsgbGVuKyspIHsKICAgICAgICAgIGxlZnQgPDw9IDE7CiAgICAgICAgICBsZWZ0IC09IGNvdW50W2xlbl07CiAgICAgICAgICBpZiAobGVmdCA8IDApIHsKICAgICAgICAgICAgcmV0dXJuIC0xOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAobGVmdCA+IDAgJiYgKHR5cGUgPT09IENPREVTIHx8IG1heCAhPT0gMSkpIHsKICAgICAgICAgIHJldHVybiAtMTsKICAgICAgICB9CiAgICAgICAgb2Zmc1sxXSA9IDA7CiAgICAgICAgZm9yIChsZW4gPSAxOyBsZW4gPCBNQVhCSVRTOyBsZW4rKykgewogICAgICAgICAgb2Zmc1tsZW4gKyAxXSA9IG9mZnNbbGVuXSArIGNvdW50W2xlbl07CiAgICAgICAgfQogICAgICAgIGZvciAoc3ltID0gMDsgc3ltIDwgY29kZXM7IHN5bSsrKSB7CiAgICAgICAgICBpZiAobGVuc1tsZW5zX2luZGV4ICsgc3ltXSAhPT0gMCkgewogICAgICAgICAgICB3b3JrW29mZnNbbGVuc1tsZW5zX2luZGV4ICsgc3ltXV0rK10gPSBzeW07CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmICh0eXBlID09PSBDT0RFUykgewogICAgICAgICAgYmFzZSA9IGV4dHJhID0gd29yazsKICAgICAgICAgIGVuZCA9IDE5OwogICAgICAgIH0gZWxzZSBpZiAodHlwZSA9PT0gTEVOUykgewogICAgICAgICAgYmFzZSA9IGxiYXNlOwogICAgICAgICAgYmFzZV9pbmRleCAtPSAyNTc7CiAgICAgICAgICBleHRyYSA9IGxleHQ7CiAgICAgICAgICBleHRyYV9pbmRleCAtPSAyNTc7CiAgICAgICAgICBlbmQgPSAyNTY7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIGJhc2UgPSBkYmFzZTsKICAgICAgICAgIGV4dHJhID0gZGV4dDsKICAgICAgICAgIGVuZCA9IC0xOwogICAgICAgIH0KICAgICAgICBodWZmID0gMDsKICAgICAgICBzeW0gPSAwOwogICAgICAgIGxlbiA9IG1pbjsKICAgICAgICBuZXh0ID0gdGFibGVfaW5kZXg7CiAgICAgICAgY3VyciA9IHJvb3Q7CiAgICAgICAgZHJvcCA9IDA7CiAgICAgICAgbG93ID0gLTE7CiAgICAgICAgdXNlZCA9IDEgPDwgcm9vdDsKICAgICAgICBtYXNrID0gdXNlZCAtIDE7CiAgICAgICAgaWYgKHR5cGUgPT09IExFTlMgJiYgdXNlZCA+IEVOT1VHSF9MRU5TIHx8IHR5cGUgPT09IERJU1RTICYmIHVzZWQgPiBFTk9VR0hfRElTVFMpIHsKICAgICAgICAgIHJldHVybiAxOwogICAgICAgIH0KICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgIGhlcmVfYml0cyA9IGxlbiAtIGRyb3A7CiAgICAgICAgICBpZiAod29ya1tzeW1dIDwgZW5kKSB7CiAgICAgICAgICAgIGhlcmVfb3AgPSAwOwogICAgICAgICAgICBoZXJlX3ZhbCA9IHdvcmtbc3ltXTsKICAgICAgICAgIH0gZWxzZSBpZiAod29ya1tzeW1dID4gZW5kKSB7CiAgICAgICAgICAgIGhlcmVfb3AgPSBleHRyYVtleHRyYV9pbmRleCArIHdvcmtbc3ltXV07CiAgICAgICAgICAgIGhlcmVfdmFsID0gYmFzZVtiYXNlX2luZGV4ICsgd29ya1tzeW1dXTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGhlcmVfb3AgPSAzMiArIDY0OwogICAgICAgICAgICBoZXJlX3ZhbCA9IDA7CiAgICAgICAgICB9CiAgICAgICAgICBpbmNyID0gMSA8PCBsZW4gLSBkcm9wOwogICAgICAgICAgZmlsbCA9IDEgPDwgY3VycjsKICAgICAgICAgIG1pbiA9IGZpbGw7CiAgICAgICAgICBkbyB7CiAgICAgICAgICAgIGZpbGwgLT0gaW5jcjsKICAgICAgICAgICAgdGFibGVbbmV4dCArIChodWZmID4+IGRyb3ApICsgZmlsbF0gPSBoZXJlX2JpdHMgPDwgMjQgfCBoZXJlX29wIDw8IDE2IHwgaGVyZV92YWwgfCAwOwogICAgICAgICAgfSB3aGlsZSAoZmlsbCAhPT0gMCk7CiAgICAgICAgICBpbmNyID0gMSA8PCBsZW4gLSAxOwogICAgICAgICAgd2hpbGUgKGh1ZmYgJiBpbmNyKSB7CiAgICAgICAgICAgIGluY3IgPj49IDE7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoaW5jciAhPT0gMCkgewogICAgICAgICAgICBodWZmICY9IGluY3IgLSAxOwogICAgICAgICAgICBodWZmICs9IGluY3I7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBodWZmID0gMDsKICAgICAgICAgIH0KICAgICAgICAgIHN5bSsrOwogICAgICAgICAgaWYgKC0tY291bnRbbGVuXSA9PT0gMCkgewogICAgICAgICAgICBpZiAobGVuID09PSBtYXgpIHsKICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgICBsZW4gPSBsZW5zW2xlbnNfaW5kZXggKyB3b3JrW3N5bV1dOwogICAgICAgICAgfQogICAgICAgICAgaWYgKGxlbiA+IHJvb3QgJiYgKGh1ZmYgJiBtYXNrKSAhPT0gbG93KSB7CiAgICAgICAgICAgIGlmIChkcm9wID09PSAwKSB7CiAgICAgICAgICAgICAgZHJvcCA9IHJvb3Q7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgbmV4dCArPSBtaW47CiAgICAgICAgICAgIGN1cnIgPSBsZW4gLSBkcm9wOwogICAgICAgICAgICBsZWZ0ID0gMSA8PCBjdXJyOwogICAgICAgICAgICB3aGlsZSAoY3VyciArIGRyb3AgPCBtYXgpIHsKICAgICAgICAgICAgICBsZWZ0IC09IGNvdW50W2N1cnIgKyBkcm9wXTsKICAgICAgICAgICAgICBpZiAobGVmdCA8PSAwKSB7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgY3VycisrOwogICAgICAgICAgICAgIGxlZnQgPDw9IDE7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdXNlZCArPSAxIDw8IGN1cnI7CiAgICAgICAgICAgIGlmICh0eXBlID09PSBMRU5TICYmIHVzZWQgPiBFTk9VR0hfTEVOUyB8fCB0eXBlID09PSBESVNUUyAmJiB1c2VkID4gRU5PVUdIX0RJU1RTKSB7CiAgICAgICAgICAgICAgcmV0dXJuIDE7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgbG93ID0gaHVmZiAmIG1hc2s7CiAgICAgICAgICAgIHRhYmxlW2xvd10gPSByb290IDw8IDI0IHwgY3VyciA8PCAxNiB8IG5leHQgLSB0YWJsZV9pbmRleCB8IDA7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChodWZmICE9PSAwKSB7CiAgICAgICAgICB0YWJsZVtuZXh0ICsgaHVmZl0gPSBsZW4gLSBkcm9wIDw8IDI0IHwgNjQgPDwgMTYgfCAwOwogICAgICAgIH0KICAgICAgICBvcHRzLmJpdHMgPSByb290OwogICAgICAgIHJldHVybiAwOwogICAgICB9OwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvaW5mbGF0ZS5qcwogIHZhciByZXF1aXJlX2luZmxhdGUgPSBfX2NvbW1vbkpTKHsKICAgICJub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvaW5mbGF0ZS5qcyIoZXhwb3J0cykgewogICAgICBpbml0X2J1ZmZlcl9zaGltKCk7CiAgICAgICJ1c2Ugc3RyaWN0IjsKICAgICAgdmFyIHV0aWxzID0gcmVxdWlyZV9jb21tb24yKCk7CiAgICAgIHZhciBhZGxlcjMyID0gcmVxdWlyZV9hZGxlcjMyKCk7CiAgICAgIHZhciBjcmMzMjIgPSByZXF1aXJlX2NyYzMyKCk7CiAgICAgIHZhciBpbmZsYXRlX2Zhc3QgPSByZXF1aXJlX2luZmZhc3QoKTsKICAgICAgdmFyIGluZmxhdGVfdGFibGUgPSByZXF1aXJlX2luZnRyZWVzKCk7CiAgICAgIHZhciBDT0RFUyA9IDA7CiAgICAgIHZhciBMRU5TID0gMTsKICAgICAgdmFyIERJU1RTID0gMjsKICAgICAgdmFyIFpfRklOSVNIID0gNDsKICAgICAgdmFyIFpfQkxPQ0sgPSA1OwogICAgICB2YXIgWl9UUkVFUyA9IDY7CiAgICAgIHZhciBaX09LID0gMDsKICAgICAgdmFyIFpfU1RSRUFNX0VORCA9IDE7CiAgICAgIHZhciBaX05FRURfRElDVCA9IDI7CiAgICAgIHZhciBaX1NUUkVBTV9FUlJPUiA9IC0yOwogICAgICB2YXIgWl9EQVRBX0VSUk9SID0gLTM7CiAgICAgIHZhciBaX01FTV9FUlJPUiA9IC00OwogICAgICB2YXIgWl9CVUZfRVJST1IgPSAtNTsKICAgICAgdmFyIFpfREVGTEFURUQgPSA4OwogICAgICB2YXIgSEVBRCA9IDE7CiAgICAgIHZhciBGTEFHUyA9IDI7CiAgICAgIHZhciBUSU1FID0gMzsKICAgICAgdmFyIE9TID0gNDsKICAgICAgdmFyIEVYTEVOID0gNTsKICAgICAgdmFyIEVYVFJBID0gNjsKICAgICAgdmFyIE5BTUUgPSA3OwogICAgICB2YXIgQ09NTUVOVCA9IDg7CiAgICAgIHZhciBIQ1JDID0gOTsKICAgICAgdmFyIERJQ1RJRCA9IDEwOwogICAgICB2YXIgRElDVCA9IDExOwogICAgICB2YXIgVFlQRSA9IDEyOwogICAgICB2YXIgVFlQRURPID0gMTM7CiAgICAgIHZhciBTVE9SRUQgPSAxNDsKICAgICAgdmFyIENPUFlfID0gMTU7CiAgICAgIHZhciBDT1BZID0gMTY7CiAgICAgIHZhciBUQUJMRSA9IDE3OwogICAgICB2YXIgTEVOTEVOUyA9IDE4OwogICAgICB2YXIgQ09ERUxFTlMgPSAxOTsKICAgICAgdmFyIExFTl8gPSAyMDsKICAgICAgdmFyIExFTiA9IDIxOwogICAgICB2YXIgTEVORVhUID0gMjI7CiAgICAgIHZhciBESVNUID0gMjM7CiAgICAgIHZhciBESVNURVhUID0gMjQ7CiAgICAgIHZhciBNQVRDSCA9IDI1OwogICAgICB2YXIgTElUID0gMjY7CiAgICAgIHZhciBDSEVDSyA9IDI3OwogICAgICB2YXIgTEVOR1RIID0gMjg7CiAgICAgIHZhciBET05FID0gMjk7CiAgICAgIHZhciBCQUQgPSAzMDsKICAgICAgdmFyIE1FTSA9IDMxOwogICAgICB2YXIgU1lOQyA9IDMyOwogICAgICB2YXIgRU5PVUdIX0xFTlMgPSA4NTI7CiAgICAgIHZhciBFTk9VR0hfRElTVFMgPSA1OTI7CiAgICAgIHZhciBNQVhfV0JJVFMgPSAxNTsKICAgICAgdmFyIERFRl9XQklUUyA9IE1BWF9XQklUUzsKICAgICAgZnVuY3Rpb24genN3YXAzMihxKSB7CiAgICAgICAgcmV0dXJuIChxID4+PiAyNCAmIDI1NSkgKyAocSA+Pj4gOCAmIDY1MjgwKSArICgocSAmIDY1MjgwKSA8PCA4KSArICgocSAmIDI1NSkgPDwgMjQpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIEluZmxhdGVTdGF0ZSgpIHsKICAgICAgICB0aGlzLm1vZGUgPSAwOwogICAgICAgIHRoaXMubGFzdCA9IGZhbHNlOwogICAgICAgIHRoaXMud3JhcCA9IDA7CiAgICAgICAgdGhpcy5oYXZlZGljdCA9IGZhbHNlOwogICAgICAgIHRoaXMuZmxhZ3MgPSAwOwogICAgICAgIHRoaXMuZG1heCA9IDA7CiAgICAgICAgdGhpcy5jaGVjayA9IDA7CiAgICAgICAgdGhpcy50b3RhbCA9IDA7CiAgICAgICAgdGhpcy5oZWFkID0gbnVsbDsKICAgICAgICB0aGlzLndiaXRzID0gMDsKICAgICAgICB0aGlzLndzaXplID0gMDsKICAgICAgICB0aGlzLndoYXZlID0gMDsKICAgICAgICB0aGlzLnduZXh0ID0gMDsKICAgICAgICB0aGlzLndpbmRvdyA9IG51bGw7CiAgICAgICAgdGhpcy5ob2xkID0gMDsKICAgICAgICB0aGlzLmJpdHMgPSAwOwogICAgICAgIHRoaXMubGVuZ3RoID0gMDsKICAgICAgICB0aGlzLm9mZnNldCA9IDA7CiAgICAgICAgdGhpcy5leHRyYSA9IDA7CiAgICAgICAgdGhpcy5sZW5jb2RlID0gbnVsbDsKICAgICAgICB0aGlzLmRpc3Rjb2RlID0gbnVsbDsKICAgICAgICB0aGlzLmxlbmJpdHMgPSAwOwogICAgICAgIHRoaXMuZGlzdGJpdHMgPSAwOwogICAgICAgIHRoaXMubmNvZGUgPSAwOwogICAgICAgIHRoaXMubmxlbiA9IDA7CiAgICAgICAgdGhpcy5uZGlzdCA9IDA7CiAgICAgICAgdGhpcy5oYXZlID0gMDsKICAgICAgICB0aGlzLm5leHQgPSBudWxsOwogICAgICAgIHRoaXMubGVucyA9IG5ldyB1dGlscy5CdWYxNigzMjApOwogICAgICAgIHRoaXMud29yayA9IG5ldyB1dGlscy5CdWYxNigyODgpOwogICAgICAgIHRoaXMubGVuZHluID0gbnVsbDsKICAgICAgICB0aGlzLmRpc3RkeW4gPSBudWxsOwogICAgICAgIHRoaXMuc2FuZSA9IDA7CiAgICAgICAgdGhpcy5iYWNrID0gMDsKICAgICAgICB0aGlzLndhcyA9IDA7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gaW5mbGF0ZVJlc2V0S2VlcChzdHJtKSB7CiAgICAgICAgdmFyIHN0YXRlOwogICAgICAgIGlmICghc3RybSB8fCAhc3RybS5zdGF0ZSkgewogICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VSUk9SOwogICAgICAgIH0KICAgICAgICBzdGF0ZSA9IHN0cm0uc3RhdGU7CiAgICAgICAgc3RybS50b3RhbF9pbiA9IHN0cm0udG90YWxfb3V0ID0gc3RhdGUudG90YWwgPSAwOwogICAgICAgIHN0cm0ubXNnID0gIiI7CiAgICAgICAgaWYgKHN0YXRlLndyYXApIHsKICAgICAgICAgIHN0cm0uYWRsZXIgPSBzdGF0ZS53cmFwICYgMTsKICAgICAgICB9CiAgICAgICAgc3RhdGUubW9kZSA9IEhFQUQ7CiAgICAgICAgc3RhdGUubGFzdCA9IDA7CiAgICAgICAgc3RhdGUuaGF2ZWRpY3QgPSAwOwogICAgICAgIHN0YXRlLmRtYXggPSAzMjc2ODsKICAgICAgICBzdGF0ZS5oZWFkID0gbnVsbDsKICAgICAgICBzdGF0ZS5ob2xkID0gMDsKICAgICAgICBzdGF0ZS5iaXRzID0gMDsKICAgICAgICBzdGF0ZS5sZW5jb2RlID0gc3RhdGUubGVuZHluID0gb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ICAgICB3aW5kb3dCaXRzICY9IDE1OwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAod2luZG93Qml0cyAmJiAod2luZG93Qml0cyA8IDggfHwgd2luZG93Qml0cyA+IDE1KSkgewogICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VSUk9SOwogICAgICAgIH0KICAgICAgICBpZiAoc3RhdGUud2luZG93ICE9PSBudWxsICYmIHN0YXRlLndiaXRzICE9PSB3aW5kb3dCaXRzKSB7CiAgICAgICAgICBzdGF0ZS53aW5kb3cgPSBudWxsOwogICAgICAgIH0KICAgICAgICBzdGF0ZS53cmFwID0gd3JhcDsKICAgICAgICBzdGF0ZS53Yml0cyA9IHdpbmRvd0JpdHM7CiAgICAgICAgcmV0dXJuIGluZmxhdGVSZXNldChzdHJtKTsKICAgICAgfQogICAgICBmdW5jdGlvbiBpbmZsYXRlSW5pdDIoc3RybSwgd2luZG93Qml0cykgewogICAgICAgIHZhciByZXQ7CiAgICAgICAgdmFyIHN0YXRlOwogICAgICAgIGlmICghc3RybSkgewogICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VSUk9SOwogICAgICAgIH0KICAgICAgICBzdGF0ZSA9IG5ldyBJbmZsYXRlU3RhdGUoKTsKICAgICAgICBzdHJtLnN0YXRlID0gc3RhdGU7CiAgICAgICAgc3RhdGUud2luZG93ID0gbnVsbDsKICAgICAgICByZXQgPSBpbmZsYXRlUmVzZXQyKHN0cm0sIHdpbmRvd0JpdHMpOwogICAgICAgIGlmIChyZXQgIT09IFpfT0spIHsKICAgICAgICAgIHN0cm0uc3RhdGUgPSBudWxsOwogICAgICAgIH0KICAgICAgICByZXR1cm4gcmV0OwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGluZmxhdGVJbml0KHN0cm0pIHsKICAgICAgICByZXR1cm4gaW5mbGF0ZUluaXQyKHN0cm0sIERFRl9XQklUUyk7CiAgICAgIH0KICAgICAgdmFyIHZpcmdpbiA9IHRydWU7CiAgICAgIHZhciBsZW5maXg7CiAgICAgIHZhciBkaXN0Zml4OwogICAgICBmdW5jdGlvbiBmaXhlZHRhYmxlcyhzdGF0ZSkgewogICAgICAgIGlmICh2aXJnaW4pIHsKICAgICAgICAgIHZhciBzeW07CiAgICAgICAgICBsZW5maXggPSBuZXcgdXRpbHMuQnVmMzIoNTEyKTsKICAgICAgICAgIGRpc3RmaXggPSBuZXcgdXRpbHMuQnVmMzIoMzIpOwogICAgICAgICAgc3ltID0gMDsKICAgICAgICAgIHdoaWxlIChzeW0gPCAxNDQpIHsKICAgICAgICAgICAgc3RhdGUubGVuc1tzeW0rK10gPSA4OwogICAgICAgICAgfQogICAgICAgICAgd2hpbGUgKHN5bSA8IDI1NikgewogICAgICAgICAgICBzdGF0ZS5sZW5zW3N5bSsrXSA9IDk7CiAgICAgICAgICB9CiAgICAgICAgICB3aGlsZSAoc3ltIDwgMjgwKSB7CiAgICAgICAgICAgIHN0YXRlLmxlbnNbc3ltKytdID0gNzsKICAgICAgICAgIH0KICAgICAgICAgIHdoaWxlIChzeW0gPCAyODgpIHsKICAgICAgICAgICAgc3RhdGUubGVuc1tzeW0rK10gPSA4OwogICAgICAgICAgfQogICAgICAgICAgaW5mbGF0ZV90YWJsZShMRU5TLCBzdGF0ZS5sZW5zLCAwLCAyODgsIGxlbmZpeCwgMCwgc3RhdGUud29yaywgeyBiaXRzOiA5IH0pOwogICAgICAgICAgc3ltID0gMDsKICAgICAgICAgIHdoaWxlIChzeW0gPCAzMikgewogICAgICAgICAgICBzdGF0ZS5sZW5zW3N5bSsrXSA9IDU7CiAgICAgICAgICB9CiAgICAgICAgICBpbmZsYXRlX3RhYmxlKERJU1RTLCBzdGF0ZS5sZW5zLCAwLCAzMiwgZGlzdGZpeCwgMCwgc3RhdGUud29yaywgeyBiaXRzOiA1IH0pOwogICAgICAgICAgdmlyZ2luID0gZmFsc2U7CiAgICAgICAgfQogICAgICAgIHN0YXRlLmxlbmNvZGUgPSBsZW5maXg7CiAgICAgICAgc3RhdGUubGVuYml0cyA9IDk7CiAgICAgICAgc3RhdGUuZGlzdGNvZGUgPSBkaXN0Zml4OwogICAgICAgIHN0YXRlLmRpc3RiaXRzID0gNTsKICAgICAgfQogICAgICBmdW5jdGlvbiB1cGRhdGV3aW5kb3coc3RybSwgc3JjLCBlbmQsIGNvcHkpIHsKICAgICAgICB2YXIgZGlzdDsKICAgICAgICB2YXIgc3RhdGUgPSBzdHJtLnN0YXRlOwogICAgICAgIGlmIChzdGF0ZS53aW5kb3cgPT09IG51bGwpIHsKICAgICAgICAgIHN0YXRlLndzaXplID0gMSA8PCBzdGF0ZS53Yml0czsKICAgICAgICAgIHN0YXRlLnduZXh0ID0gMDsKICAgICAgICAgIHN0YXRlLndoYXZlID0gMDsKICAgICAgICAgIHN0YXRlLndpbmRvdyA9IG5ldyB1dGlscy5CdWY4KHN0YXRlLndzaXplKTsKICAgICAgICB9CiAgICAgICAgaWYgKGNvcHkgPj0gc3RhdGUud3NpemUpIHsKICAgICAgICAgIHV0aWxzLmFycmF5U2V0KHN0YXRlLndpbmRvdywgc3JjLCBlbmQgLSBzdGF0ZS53c2l6ZSwgc3RhdGUud3NpemUsIDApOwogICAgICAgICAgc3RhdGUud25leHQgPSAwOwogICAgICAgICAgc3RhdGUud2hhdmUgPSBzdGF0ZS53c2l6ZTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgZGlzdCA9IHN0YXRlLndzaXplIC0gc3RhdGUud25leHQ7CiAgICAgICAgICBpZiAoZGlzdCA+IGNvcHkpIHsKICAgICAgICAgICAgZGlzdCA9IGNvcHk7CiAgICAgICAgICB9CiAgICAgICAgICB1dGlscy5hcnJheVNldChzdGF0ZS53aW5kb3csIHNyYywgZW5kIC0gY29weSwgZGlzdCwgc3RhdGUud25leHQpOwogICAgICAgICAgY29weSAtPSBkaXN0OwogICAgICAgICAgaWYgKGNvcHkpIHsKICAgICAgICAgICAgdXRpbHMuYXJyYXlTZXQoc3RhdGUud2luZG93LCBzcmMsIGVuZCAtIGNvcHksIGNvcHksIDApOwogICAgICAgICAgICBzdGF0ZS53bmV4dCA9IGNvcHk7CiAgICAgICAgICAgIHN0YXRlLndoYXZlID0gc3RhdGUud3NpemU7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBzdGF0ZS53bmV4dCArPSBkaXN0OwogICAgICAgICAgICBpZiAoc3RhdGUud25leHQgPT09IHN0YXRlLndzaXplKSB7CiAgICAgICAgICAgICAgc3RhdGUud25leHQgPSAwOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzdGF0ZS53aGF2ZSA8IHN0YXRlLndzaXplKSB7CiAgICAgICAgICAgICAgc3RhdGUud2hhdmUgKz0gZGlzdDsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gMDsKICAgICAgfQogICAgICBmdW5jdGlvbiBpbmZsYXRlKHN0cm0sIGZsdXNoKSB7CiAgICAgICAgdmFyIHN0YXRlOwogICAgICAgIHZhciBpbnB1dCwgb3V0cHV0OwogICAgICAgIHZhciBuZXh0OwogICAgICAgIHZhciBwdXQ7CiAgICAgICAgdmFyIGhhdmUsIGxlZnQ7CiAgICAgICAgdmFyIGhvbGQ7CiAgICAgICAgdmFyIGJpdHM7CiAgICAgICAgdmFyIF9pbiwgX291dDsKICAgICAgICB2YXIgY29weTsKICAgICAgICB2YXIgZnJvbTsKICAgICAgICB2YXIgZnJvbV9zb3VyY2U7CiAgICAgICAgdmFyIGhlcmUgPSAwOwogICAgICAgIHZhciBoZXJlX2JpdHMsIGhlcmVfb3AsIGhlcmVfdmFsOwogICAgICAgIHZhciBsYXN0X2JpdHMsIGxhc3Rfb3AsIGxhc3RfdmFsOwogICAgICAgIHZhciBsZW47CiAgICAgICAgdmFyIHJldDsKICAgICAgICB2YXIgaGJ1ZiA9IG5ldyB1dGlscy5CdWY4KDQpOwogICAgICAgIHZhciBvcHRzOwogICAgICAgIHZhciBuOwogICAgICAgIHZhciBvcmRlciA9IFsxNiwgMTcsIDE4LCAwLCA4LCA3LCA5LCA2LCAxMCwgNSwgMTEsIDQsIDEyLCAzLCAxMywgMiwgMTQsIDEsIDE1XTsKICAgICAgICBpZiAoIXN0cm0gfHwgIXN0cm0uc3RhdGUgfHwgIXN0cm0ub3V0cHV0IHx8ICFzdHJtLmlucHV0ICYmIHN0cm0uYXZhaWxfaW4gIT09IDApIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgc3RhdGUgPSBzdHJtLnN0YXRlOwogICAgICAgIGlmIChzdGF0ZS5tb2RlID09PSBUWVBFKSB7CiAgICAgICAgICBzdGF0ZS5tb2RlID0gVFlQRURPOwogICAgICAgIH0KICAgICAgICBwdXQgPSBzdHJtLm5leHRfb3V0OwogICAgICAgIG91dHB1dCA9IHN0cm0ub3V0cHV0OwogICAgICAgIGxlZnQgPSBzdHJtLmF2YWlsX291dDsKICAgICAgICBuZXh0ID0gc3RybS5uZXh0X2luOwogICAgICAgIGlucHV0ID0gc3RybS5pbnB1dDsKICAgICAgICBoYXZlID0gc3RybS5hdmFpbF9pbjsKICAgICAgICBob2xkID0gc3RhdGUuaG9sZDsKICAgICAgICBiaXRzID0gc3RhdGUuYml0czsKICAgICAgICBfaW4gPSBoYXZlOwogICAgICAgIF9vdXQgPSBsZWZ0OwogICAgICAgIHJldCA9IFpfT0s7CiAgICAgICAgaW5mX2xlYXZlOgogICAgICAgICAgZm9yICg7IDsgKSB7CiAgICAgICAgICAgIHN3aXRjaCAoc3RhdGUubW9kZSkgewogICAgICAgICAgICAgIGNhc2UgSEVBRDoKICAgICAgICAgICAgICAgIGlmIChzdGF0ZS53cmFwID09PSAwKSB7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBUWVBFRE87CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCAxNikgewogICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUud3JhcCAmIDIgJiYgaG9sZCA9PT0gMzU2MTUpIHsKICAgICAgICAgICAgICAgICAgc3RhdGUuY2hlY2sgPSAwOwogICAgICAgICAgICAgICAgICBoYnVmWzBdID0gaG9sZCAmIDI1NTsKICAgICAgICAgICAgICAgICAgaGJ1ZlsxXSA9IGhvbGQgPj4+IDggJiAyNTU7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmNoZWNrID0gY3JjMzIyKHN0YXRlLmNoZWNrLCBoYnVmLCAyLCAwKTsKICAgICAgICAgICAgICAgICAgaG9sZCA9IDA7CiAgICAgICAgICAgICAgICAgIGJpdHMgPSAwOwogICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gRkxBR1M7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUuZmxhZ3MgPSAwOwogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmhlYWQpIHsKICAgICAgICAgICAgICAgICAgc3RhdGUuaGVhZC5kb25lID0gZmFsc2U7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoIShzdGF0ZS53cmFwICYgMSkgfHwgKCgoaG9sZCAmIDI1NSkgPDwgOCkgKyAoaG9sZCA+PiA4KSkgJSAzMSkgewogICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbmNvcnJlY3QgaGVhZGVyIGNoZWNrIjsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoKGhvbGQgJiAxNSkgIT09IFpfREVGTEFURUQpIHsKICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAidW5rbm93biBjb21wcmVzc2lvbiBtZXRob2QiOwogICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEOwogICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGhvbGQgPj4+PSA0OwogICAgICAgICAgICAgICAgYml0cyAtPSA0OwogICAgICAgICAgICAgICAgbGVuID0gKGhvbGQgJiAxNSkgKyA4OwogICAgICAgICAgICAgICAgaWYgKHN0YXRlLndiaXRzID09PSAwKSB7CiAgICAgICAgICAgICAgICAgIHN0YXRlLndiaXRzID0gbGVuOwogICAgICAgICAgICAgICAgfSBlbHNlIGlmIChsZW4gPiBzdGF0ZS53Yml0cykgewogICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbnZhbGlkIHdpbmRvdyBzaXplIjsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5kbWF4ID0gMSA8PCBsZW47CiAgICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gc3RhdGUuY2hlY2sgPSAxOwogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IGhvbGQgJiA1MTIgPyBESUNUSUQgOiBUWVBFOwogICAgICAgICAgICAgICAgaG9sZCA9IDA7CiAgICAgICAgICAgICAgICBiaXRzID0gMDsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgIGNhc2UgRkxBR1M6CiAgICAgICAgICAgICAgICB3aGlsZSAoYml0cyA8IDE2KSB7CiAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0YXRlLmZsYWdzID0gaG9sZDsKICAgICAgICAgICAgICAgIGlmICgoc3RhdGUuZmxhZ3MgJiAyNTUpICE9PSBaX0RFRkxBVEVEKSB7CiAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gInVua25vd24gY29tcHJlc3Npb24gbWV0aG9kIjsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuZmxhZ3MgJiA1NzM0NCkgewogICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJ1bmtub3duIGhlYWRlciBmbGFncyBzZXQiOwogICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEOwogICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5oZWFkKSB7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmhlYWQudGV4dCA9IGhvbGQgPj4gOCAmIDE7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuZmxhZ3MgJiA1MTIpIHsKICAgICAgICAgICAgICAgICAgaGJ1ZlswXSA9IGhvbGQgJiAyNTU7CiAgICAgICAgICAgICAgICAgIGhidWZbMV0gPSBob2xkID4+PiA4ICYgMjU1OwogICAgICAgICAgICAgICAgICBzdGF0ZS5jaGVjayA9IGNyYzMyMihzdGF0ZS5jaGVjaywgaGJ1ZiwgMiwgMCk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBob2xkID0gMDsKICAgICAgICAgICAgICAgIGJpdHMgPSAwOwogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IFRJTUU7CiAgICAgICAgICAgICAgY2FzZSBUSU1FOgogICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCAzMikgewogICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuaGVhZCkgewogICAgICAgICAgICAgICAgICBzdGF0ZS5oZWFkLnRpbWUgPSBob2xkOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmZsYWdzICYgNTEyKSB7CiAgICAgICAgICAgICAgICAgIGhidWZbMF0gPSBob2xkICYgMjU1OwogICAgICAgICAgICAgICAgICBoYnVmWzFdID0gaG9sZCA+Pj4gOCAmIDI1NTsKICAgICAgICAgICAgICAgICAgaGJ1ZlsyXSA9IGhvbGQgPj4+IDE2ICYgMjU1OwogICAgICAgICAgICAgICAgICBoYnVmWzNdID0gaG9sZCA+Pj4gMjQgJiAyNTU7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmNoZWNrID0gY3JjMzIyKHN0YXRlLmNoZWNrLCBoYnVmLCA0LCAwKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGhvbGQgPSAwOwogICAgICAgICAgICAgICAgYml0cyA9IDA7CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gT1M7CiAgICAgICAgICAgICAgY2FzZSBPUzoKICAgICAgICAgICAgICAgIHdoaWxlIChiaXRzIDwgMTYpIHsKICAgICAgICAgICAgICAgICAgaWYgKGhhdmUgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaGF2ZS0tOwogICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmhlYWQpIHsKICAgICAgICAgICAgICAgICAgc3RhdGUuaGVhZC54ZmxhZ3MgPSBob2xkICYgMjU1OwogICAgICAgICAgICAgICAgICBzdGF0ZS5oZWFkLm9zID0gaG9sZCA+PiA4OwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmZsYWdzICYgNTEyKSB7CiAgICAgICAgICAgICAgICAgIGhidWZbMF0gPSBob2xkICYgMjU1OwogICAgICAgICAgICAgICAgICBoYnVmWzFdID0gaG9sZCA+Pj4gOCAmIDI1NTsKICAgICAgICAgICAgICAgICAgc3RhdGUuY2hlY2sgPSBjcmMzMjIoc3RhdGUuY2hlY2ssIGhidWYsIDIsIDApOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaG9sZCA9IDA7CiAgICAgICAgICAgICAgICBiaXRzID0gMDsKICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBFWExFTjsKICAgICAgICAgICAgICBjYXNlIEVYTEVOOgogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmZsYWdzICYgMTAyNCkgewogICAgICAgICAgICAgICAgICB3aGlsZSAoYml0cyA8IDE2KSB7CiAgICAgICAgICAgICAgICAgICAgaWYgKGhhdmUgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgaGF2ZS0tOwogICAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBzdGF0ZS5sZW5ndGggPSBob2xkOwogICAgICAgICAgICAgICAgICBpZiAoc3RhdGUuaGVhZCkgewogICAgICAgICAgICAgICAgICAgIHN0YXRlLmhlYWQuZXh0cmFfbGVuID0gaG9sZDsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBpZiAoc3RhdGUuZmxhZ3MgJiA1MTIpIHsKICAgICAgICAgICAgICAgICAgICBoYnVmWzBdID0gaG9sZCAmIDI1NTsKICAgICAgICAgICAgICAgICAgICBoYnVmWzFdID0gaG9sZCA+Pj4gOCAmIDI1NTsKICAgICAgICAgICAgICAgICAgICBzdGF0ZS5jaGVjayA9IGNyYzMyMihzdGF0ZS5jaGVjaywgaGJ1ZiwgMiwgMCk7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaG9sZCA9IDA7CiAgICAgICAgICAgICAgICAgIGJpdHMgPSAwOwogICAgICAgICAgICAgICAgfSBlbHNlIGlmIChzdGF0ZS5oZWFkKSB7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmhlYWQuZXh0cmEgPSBudWxsOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEVYVFJBOwogICAgICAgICAgICAgIGNhc2UgRVhUUkE6CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuZmxhZ3MgJiAxMDI0KSB7CiAgICAgICAgICAgICAgICAgIGNvcHkgPSBzdGF0ZS5sZW5ndGg7CiAgICAgICAgICAgICAgICAgIGlmIChjb3B5ID4gaGF2ZSkgewogICAgICAgICAgICAgICAgICAgIGNvcHkgPSBoYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChjb3B5KSB7CiAgICAgICAgICAgICAgICAgICAgaWYgKHN0YXRlLmhlYWQpIHsKICAgICAgICAgICAgICAgICAgICAgIGxlbiA9IHN0YXRlLmhlYWQuZXh0cmFfbGVuIC0gc3RhdGUubGVuZ3RoOwogICAgICAgICAgICAgICAgICAgICAgaWYgKCFzdGF0ZS5oZWFkLmV4dHJhKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHN0YXRlLmhlYWQuZXh0cmEgPSBuZXcgQXJyYXkoc3RhdGUuaGVhZC5leHRyYV9sZW4pOwogICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgdXRpbHMuYXJyYXlTZXQoc3RhdGUuaGVhZC5leHRyYSwgaW5wdXQsIG5leHQsIGNvcHksIGxlbik7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5mbGFncyAmIDUxMikgewogICAgICAgICAgICAgICAgICAgICAgc3RhdGUuY2hlY2sgPSBjcmMzMjIoc3RhdGUuY2hlY2ssIGlucHV0LCBjb3B5LCBuZXh0KTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgaGF2ZSAtPSBjb3B5OwogICAgICAgICAgICAgICAgICAgIG5leHQgKz0gY29weTsKICAgICAgICAgICAgICAgICAgICBzdGF0ZS5sZW5ndGggLT0gY29weTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBpZiAoc3RhdGUubGVuZ3RoKSB7CiAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5sZW5ndGggPSAwOwogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IE5BTUU7CiAgICAgICAgICAgICAgY2FzZSBOQU1FOgogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmZsYWdzICYgMjA0OCkgewogICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBjb3B5ID0gMDsKICAgICAgICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgICAgICAgIGxlbiA9IGlucHV0W25leHQgKyBjb3B5KytdOwogICAgICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5oZWFkICYmIGxlbiAmJiBzdGF0ZS5sZW5ndGggPCA2NTUzNikgewogICAgICAgICAgICAgICAgICAgICAgc3RhdGUuaGVhZC5uYW1lICs9IFN0cmluZy5mcm9tQ2hhckNvZGUobGVuKTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIH0gd2hpbGUgKGxlbiAmJiBjb3B5IDwgaGF2ZSk7CiAgICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5mbGFncyAmIDUxMikgewogICAgICAgICAgICAgICAgICAgIHN0YXRlLmNoZWNrID0gY3JjMzIyKHN0YXRlLmNoZWNrLCBpbnB1dCwgY29weSwgbmV4dCk7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaGF2ZSAtPSBjb3B5OwogICAgICAgICAgICAgICAgICBuZXh0ICs9IGNvcHk7CiAgICAgICAgICAgICAgICAgIGlmIChsZW4pIHsKICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAoc3RhdGUuaGVhZCkgewogICAgICAgICAgICAgICAgICBzdGF0ZS5oZWFkLm5hbWUgPSBudWxsOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUubGVuZ3RoID0gMDsKICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBDT01NRU5UOwogICAgICAgICAgICAgIGNhc2UgQ09NTUVOVDoKICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5mbGFncyAmIDQwOTYpIHsKICAgICAgICAgICAgICAgICAgaWYgKGhhdmUgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgY29weSA9IDA7CiAgICAgICAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICAgICAgICBsZW4gPSBpbnB1dFtuZXh0ICsgY29weSsrXTsKICAgICAgICAgICAgICAgICAgICBpZiAoc3RhdGUuaGVhZCAmJiBsZW4gJiYgc3RhdGUubGVuZ3RoIDwgNjU1MzYpIHsKICAgICAgICAgICAgICAgICAgICAgIHN0YXRlLmhlYWQuY29tbWVudCArPSBTdHJpbmcuZnJvbUNoYXJDb2RlKGxlbik7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICB9IHdoaWxlIChsZW4gJiYgY29weSA8IGhhdmUpOwogICAgICAgICAgICAgICAgICBpZiAoc3RhdGUuZmxhZ3MgJiA1MTIpIHsKICAgICAgICAgICAgICAgICAgICBzdGF0ZS5jaGVjayA9IGNyYzMyMihzdGF0ZS5jaGVjaywgaW5wdXQsIGNvcHksIG5leHQpOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGhhdmUgLT0gY29weTsKICAgICAgICAgICAgICAgICAgbmV4dCArPSBjb3B5OwogICAgICAgICAgICAgICAgICBpZiAobGVuKSB7CiAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKHN0YXRlLmhlYWQpIHsKICAgICAgICAgICAgICAgICAgc3RhdGUuaGVhZC5jb21tZW50ID0gbnVsbDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBIQ1JDOwogICAgICAgICAgICAgIGNhc2UgSENSQzoKICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5mbGFncyAmIDUxMikgewogICAgICAgICAgICAgICAgICB3aGlsZSAoYml0cyA8IDE2KSB7CiAgICAgICAgICAgICAgICAgICAgaWYgKGhhdmUgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgaGF2ZS0tOwogICAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBpZiAoaG9sZCAhPT0gKHN0YXRlLmNoZWNrICYgNjU1MzUpKSB7CiAgICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaGVhZGVyIGNyYyBtaXNtYXRjaCI7CiAgICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBob2xkID0gMDsKICAgICAgICAgICAgICAgICAgYml0cyA9IDA7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuaGVhZCkgewogICAgICAgICAgICAgICAgICBzdGF0ZS5oZWFkLmhjcmMgPSBzdGF0ZS5mbGFncyA+PiA5ICYgMTsKICAgICAgICAgICAgICAgICAgc3RhdGUuaGVhZC5kb25lID0gdHJ1ZTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0cm0uYWRsZXIgPSBzdGF0ZS5jaGVjayA9IDA7CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gVFlQRTsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgIGNhc2UgRElDVElEOgogICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCAzMikgewogICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gc3RhdGUuY2hlY2sgPSB6c3dhcDMyKGhvbGQpOwogICAgICAgICAgICAgICAgaG9sZCA9IDA7CiAgICAgICAgICAgICAgICBiaXRzID0gMDsKICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBESUNUOwogICAgICAgICAgICAgIGNhc2UgRElDVDoKICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5oYXZlZGljdCA9PT0gMCkgewogICAgICAgICAgICAgICAgICBzdHJtLm5leHRfb3V0ID0gcHV0OwogICAgICAgICAgICAgICAgICBzdHJtLmF2YWlsX291dCA9IGxlZnQ7CiAgICAgICAgICAgICAgICAgIHN0cm0ubmV4dF9pbiA9IG5leHQ7CiAgICAgICAgICAgICAgICAgIHN0cm0uYXZhaWxfaW4gPSBoYXZlOwogICAgICAgICAgICAgICAgICBzdGF0ZS5ob2xkID0gaG9sZDsKICAgICAgICAgICAgICAgICAgc3RhdGUuYml0cyA9IGJpdHM7CiAgICAgICAgICAgICAgICAgIHJldHVybiBaX05FRURfRElDVDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0cm0uYWRsZXIgPSBzdGF0ZS5jaGVjayA9IDE7CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gVFlQRTsKICAgICAgICAgICAgICBjYXNlIFRZUEU6CiAgICAgICAgICAgICAgICBpZiAoZmx1c2ggPT09IFpfQkxPQ0sgfHwgZmx1c2ggPT09IFpfVFJFRVMpIHsKICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGNhc2UgVFlQRURPOgogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmxhc3QpIHsKICAgICAgICAgICAgICAgICAgaG9sZCA+Pj49IGJpdHMgJiA3OwogICAgICAgICAgICAgICAgICBiaXRzIC09IGJpdHMgJiA3OwogICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQ0hFQ0s7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCAzKSB7CiAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0YXRlLmxhc3QgPSBob2xkICYgMTsKICAgICAgICAgICAgICAgIGhvbGQgPj4+PSAxOwogICAgICAgICAgICAgICAgYml0cyAtPSAxOwogICAgICAgICAgICAgICAgc3dpdGNoIChob2xkICYgMykgewogICAgICAgICAgICAgICAgICBjYXNlIDA6CiAgICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IFNUT1JFRDsKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgY2FzZSAxOgogICAgICAgICAgICAgICAgICAgIGZpeGVkdGFibGVzKHN0YXRlKTsKICAgICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gTEVOXzsKICAgICAgICAgICAgICAgICAgICBpZiAoZmx1c2ggPT09IFpfVFJFRVMpIHsKICAgICAgICAgICAgICAgICAgICAgIGhvbGQgPj4+PSAyOwogICAgICAgICAgICAgICAgICAgICAgYml0cyAtPSAyOwogICAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgY2FzZSAyOgogICAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBUQUJMRTsKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgY2FzZSAzOgogICAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImludmFsaWQgYmxvY2sgdHlwZSI7CiAgICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGhvbGQgPj4+PSAyOwogICAgICAgICAgICAgICAgYml0cyAtPSAyOwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgY2FzZSBTVE9SRUQ6CiAgICAgICAgICAgICAgICBob2xkID4+Pj0gYml0cyAmIDc7CiAgICAgICAgICAgICAgICBiaXRzIC09IGJpdHMgJiA3OwogICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCAzMikgewogICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoKGhvbGQgJiA2NTUzNSkgIT09IChob2xkID4+PiAxNiBeIDY1NTM1KSkgewogICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbnZhbGlkIHN0b3JlZCBibG9jayBsZW5ndGhzIjsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5sZW5ndGggPSBob2xkICYgNjU1MzU7CiAgICAgICAgICAgICAgICBob2xkID0gMDsKICAgICAgICAgICAgICAgIGJpdHMgPSAwOwogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IENPUFlfOwogICAgICAgICAgICAgICAgaWYgKGZsdXNoID09PSBaX1RSRUVTKSB7CiAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBjYXNlIENPUFlfOgogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IENPUFk7CiAgICAgICAgICAgICAgY2FzZSBDT1BZOgogICAgICAgICAgICAgICAgY29weSA9IHN0YXRlLmxlbmd0aDsKICAgICAgICAgICAgICAgIGlmIChjb3B5KSB7CiAgICAgICAgICAgICAgICAgIGlmIChjb3B5ID4gaGF2ZSkgewogICAgICAgICAgICAgICAgICAgIGNvcHkgPSBoYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChjb3B5ID4gbGVmdCkgewogICAgICAgICAgICAgICAgICAgIGNvcHkgPSBsZWZ0OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChjb3B5ID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIHV0aWxzLmFycmF5U2V0KG91dHB1dCwgaW5wdXQsIG5leHQsIGNvcHksIHB1dCk7CiAgICAgICAgICAgICAgICAgIGhhdmUgLT0gY29weTsKICAgICAgICAgICAgICAgICAgbmV4dCArPSBjb3B5OwogICAgICAgICAgICAgICAgICBsZWZ0IC09IGNvcHk7CiAgICAgICAgICAgICAgICAgIHB1dCArPSBjb3B5OwogICAgICAgICAgICAgICAgICBzdGF0ZS5sZW5ndGggLT0gY29weTsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gVFlQRTsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgIGNhc2UgVEFCTEU6CiAgICAgICAgICAgICAgICB3aGlsZSAoYml0cyA8IDE0KSB7CiAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0YXRlLm5sZW4gPSAoaG9sZCAmIDMxKSArIDI1NzsKICAgICAgICAgICAgICAgIGhvbGQgPj4+PSA1OwogICAgICAgICAgICAgICAgYml0cyAtPSA1OwogICAgICAgICAgICAgICAgc3RhdGUubmRpc3QgPSAoaG9sZCAmIDMxKSArIDE7CiAgICAgICAgICAgICAgICBob2xkID4+Pj0gNTsKICAgICAgICAgICAgICAgIGJpdHMgLT0gNTsKICAgICAgICAgICAgICAgIHN0YXRlLm5jb2RlID0gKGhvbGQgJiAxNSkgKyA0OwogICAgICAgICAgICAgICAgaG9sZCA+Pj49IDQ7CiAgICAgICAgICAgICAgICBiaXRzIC09IDQ7CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUubmxlbiA+IDI4NiB8fCBzdGF0ZS5uZGlzdCA+IDMwKSB7CiAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gInRvbyBtYW55IGxlbmd0aCBvciBkaXN0YW5jZSBzeW1ib2xzIjsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5oYXZlID0gMDsKICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBMRU5MRU5TOwogICAgICAgICAgICAgIGNhc2UgTEVOTEVOUzoKICAgICAgICAgICAgICAgIHdoaWxlIChzdGF0ZS5oYXZlIDwgc3RhdGUubmNvZGUpIHsKICAgICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCAzKSB7CiAgICAgICAgICAgICAgICAgICAgaWYgKGhhdmUgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgaGF2ZS0tOwogICAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBzdGF0ZS5sZW5zW29yZGVyW3N0YXRlLmhhdmUrK11dID0gaG9sZCAmIDc7CiAgICAgICAgICAgICAgICAgIGhvbGQgPj4+PSAzOwogICAgICAgICAgICAgICAgICBiaXRzIC09IDM7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB3aGlsZSAoc3RhdGUuaGF2ZSA8IDE5KSB7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmxlbnNbb3JkZXJbc3RhdGUuaGF2ZSsrXV0gPSAwOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUubGVuY29kZSA9IHN0YXRlLmxlbmR5bjsKICAgICAgICAgICAgICAgIHN0YXRlLmxlbmJpdHMgPSA3OwogICAgICAgICAgICAgICAgb3B0cyA9IHsgYml0czogc3RhdGUubGVuYml0cyB9OwogICAgICAgICAgICAgICAgcmV0ID0gaW5mbGF0ZV90YWJsZShDT0RFUywgc3RhdGUubGVucywgMCwgMTksIHN0YXRlLmxlbmNvZGUsIDAsIHN0YXRlLndvcmssIG9wdHMpOwogICAgICAgICAgICAgICAgc3RhdGUubGVuYml0cyA9IG9wdHMuYml0czsKICAgICAgICAgICAgICAgIGlmIChyZXQpIHsKICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW52YWxpZCBjb2RlIGxlbmd0aHMgc2V0IjsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5oYXZlID0gMDsKICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBDT0RFTEVOUzsKICAgICAgICAgICAgICBjYXNlIENPREVMRU5TOgogICAgICAgICAgICAgICAgd2hpbGUgKHN0YXRlLmhhdmUgPCBzdGF0ZS5ubGVuICsgc3RhdGUubmRpc3QpIHsKICAgICAgICAgICAgICAgICAgZm9yICg7IDsgKSB7CiAgICAgICAgICAgICAgICAgICAgaGVyZSA9IHN0YXRlLmxlbmNvZGVbaG9sZCAmICgxIDw8IHN0YXRlLmxlbmJpdHMpIC0gMV07CiAgICAgICAgICAgICAgICAgICAgaGVyZV9iaXRzID0gaGVyZSA+Pj4gMjQ7CiAgICAgICAgICAgICAgICAgICAgaGVyZV9vcCA9IGhlcmUgPj4+IDE2ICYgMjU1OwogICAgICAgICAgICAgICAgICAgIGhlcmVfdmFsID0gaGVyZSAmIDY1NTM1OwogICAgICAgICAgICAgICAgICAgIGlmIChoZXJlX2JpdHMgPD0gYml0cykgewogICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaWYgKGhlcmVfdmFsIDwgMTYpIHsKICAgICAgICAgICAgICAgICAgICBob2xkID4+Pj0gaGVyZV9iaXRzOwogICAgICAgICAgICAgICAgICAgIGJpdHMgLT0gaGVyZV9iaXRzOwogICAgICAgICAgICAgICAgICAgIHN0YXRlLmxlbnNbc3RhdGUuaGF2ZSsrXSA9IGhlcmVfdmFsOwogICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgIGlmIChoZXJlX3ZhbCA9PT0gMTYpIHsKICAgICAgICAgICAgICAgICAgICAgIG4gPSBoZXJlX2JpdHMgKyAyOwogICAgICAgICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCBuKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgIGhvbGQgPj4+PSBoZXJlX2JpdHM7CiAgICAgICAgICAgICAgICAgICAgICBiaXRzIC09IGhlcmVfYml0czsKICAgICAgICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5oYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImludmFsaWQgYml0IGxlbmd0aCByZXBlYXQiOwogICAgICAgICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEOwogICAgICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgIGxlbiA9IHN0YXRlLmxlbnNbc3RhdGUuaGF2ZSAtIDFdOwogICAgICAgICAgICAgICAgICAgICAgY29weSA9IDMgKyAoaG9sZCAmIDMpOwogICAgICAgICAgICAgICAgICAgICAgaG9sZCA+Pj49IDI7CiAgICAgICAgICAgICAgICAgICAgICBiaXRzIC09IDI7CiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIGlmIChoZXJlX3ZhbCA9PT0gMTcpIHsKICAgICAgICAgICAgICAgICAgICAgIG4gPSBoZXJlX2JpdHMgKyAzOwogICAgICAgICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCBuKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgIGhvbGQgPj4+PSBoZXJlX2JpdHM7CiAgICAgICAgICAgICAgICAgICAgICBiaXRzIC09IGhlcmVfYml0czsKICAgICAgICAgICAgICAgICAgICAgIGxlbiA9IDA7CiAgICAgICAgICAgICAgICAgICAgICBjb3B5ID0gMyArIChob2xkICYgNyk7CiAgICAgICAgICAgICAgICAgICAgICBob2xkID4+Pj0gMzsKICAgICAgICAgICAgICAgICAgICAgIGJpdHMgLT0gMzsKICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgbiA9IGhlcmVfYml0cyArIDc7CiAgICAgICAgICAgICAgICAgICAgICB3aGlsZSAoYml0cyA8IG4pIHsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGhhdmUgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgaGF2ZS0tOwogICAgICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgaG9sZCA+Pj49IGhlcmVfYml0czsKICAgICAgICAgICAgICAgICAgICAgIGJpdHMgLT0gaGVyZV9iaXRzOwogICAgICAgICAgICAgICAgICAgICAgbGVuID0gMDsKICAgICAgICAgICAgICAgICAgICAgIGNvcHkgPSAxMSArIChob2xkICYgMTI3KTsKICAgICAgICAgICAgICAgICAgICAgIGhvbGQgPj4+PSA3OwogICAgICAgICAgICAgICAgICAgICAgYml0cyAtPSA3OwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBpZiAoc3RhdGUuaGF2ZSArIGNvcHkgPiBzdGF0ZS5ubGVuICsgc3RhdGUubmRpc3QpIHsKICAgICAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImludmFsaWQgYml0IGxlbmd0aCByZXBlYXQiOwogICAgICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICB3aGlsZSAoY29weS0tKSB7CiAgICAgICAgICAgICAgICAgICAgICBzdGF0ZS5sZW5zW3N0YXRlLmhhdmUrK10gPSBsZW47CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUubW9kZSA9PT0gQkFEKSB7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmxlbnNbMjU2XSA9PT0gMCkgewogICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbnZhbGlkIGNvZGUgLS0gbWlzc2luZyBlbmQtb2YtYmxvY2siOwogICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEOwogICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0YXRlLmxlbmJpdHMgPSA5OwogICAgICAgICAgICAgICAgb3B0cyA9IHsgYml0czogc3RhdGUubGVuYml0cyB9OwogICAgICAgICAgICAgICAgcmV0ID0gaW5mbGF0ZV90YWJsZShMRU5TLCBzdGF0ZS5sZW5zLCAwLCBzdGF0ZS5ubGVuLCBzdGF0ZS5sZW5jb2RlLCAwLCBzdGF0ZS53b3JrLCBvcHRzKTsKICAgICAgICAgICAgICAgIHN0YXRlLmxlbmJpdHMgPSBvcHRzLmJpdHM7CiAgICAgICAgICAgICAgICBpZiAocmV0KSB7CiAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImludmFsaWQgbGl0ZXJhbC9sZW5ndGhzIHNldCI7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUuZGlzdGJpdHMgPSA2OwogICAgICAgICAgICAgICAgc3RhdGUuZGlzdGNvZGUgPSBzdGF0ZS5kaXN0ZHluOwogICAgICAgICAgICAgICAgb3B0cyA9IHsgYml0czogc3RhdGUuZGlzdGJpdHMgfTsKICAgICAgICAgICAgICAgIHJldCA9IGluZmxhdGVfdGFibGUoRElTVFMsIHN0YXRlLmxlbnMsIHN0YXRlLm5sZW4sIHN0YXRlLm5kaXN0LCBzdGF0ZS5kaXN0Y29kZSwgMCwgc3RhdGUud29yaywgb3B0cyk7CiAgICAgICAgICAgICAgICBzdGF0ZS5kaXN0Yml0cyA9IG9wdHMuYml0czsKICAgICAgICAgICAgICAgIGlmIChyZXQpIHsKICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW52YWxpZCBkaXN0YW5jZXMgc2V0IjsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gTEVOXzsKICAgICAgICAgICAgICAgIGlmIChmbHVzaCA9PT0gWl9UUkVFUykgewogICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgY2FzZSBMRU5fOgogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IExFTjsKICAgICAgICAgICAgICBjYXNlIExFTjoKICAgICAgICAgICAgICAgIGlmIChoYXZlID49IDYgJiYgbGVmdCA+PSAyNTgpIHsKICAgICAgICAgICAgICAgICAgc3RybS5uZXh0X291dCA9IHB1dDsKICAgICAgICAgICAgICAgICAgc3RybS5hdmFpbF9vdXQgPSBsZWZ0OwogICAgICAgICAgICAgICAgICBzdHJtLm5leHRfaW4gPSBuZXh0OwogICAgICAgICAgICAgICAgICBzdHJtLmF2YWlsX2luID0gaGF2ZTsKICAgICAgICAgICAgICAgICAgc3RhdGUuaG9sZCA9IGhvbGQ7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmJpdHMgPSBiaXRzOwogICAgICAgICAgICAgICAgICBpbmZsYXRlX2Zhc3Qoc3RybSwgX291dCk7CiAgICAgICAgICAgICAgICAgIHB1dCA9IHN0cm0ubmV4dF9vdXQ7CiAgICAgICAgICAgICAgICAgIG91dHB1dCA9IHN0cm0ub3V0cHV0OwogICAgICAgICAgICAgICAgICBsZWZ0ID0gc3RybS5hdmFpbF9vdXQ7CiAgICAgICAgICAgICAgICAgIG5leHQgPSBzdHJtLm5leHRfaW47CiAgICAgICAgICAgICAgICAgIGlucHV0ID0gc3RybS5pbnB1dDsKICAgICAgICAgICAgICAgICAgaGF2ZSA9IHN0cm0uYXZhaWxfaW47CiAgICAgICAgICAgICAgICAgIGhvbGQgPSBzdGF0ZS5ob2xkOwogICAgICAgICAgICAgICAgICBiaXRzID0gc3RhdGUuYml0czsKICAgICAgICAgICAgICAgICAgaWYgKHN0YXRlLm1vZGUgPT09IFRZUEUpIHsKICAgICAgICAgICAgICAgICAgICBzdGF0ZS5iYWNrID0gLTE7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5iYWNrID0gMDsKICAgICAgICAgICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgICAgICAgICBoZXJlID0gc3RhdGUubGVuY29kZVtob2xkICYgKDEgPDwgc3RhdGUubGVuYml0cykgLSAxXTsKICAgICAgICAgICAgICAgICAgaGVyZV9iaXRzID0gaGVyZSA+Pj4gMjQ7CiAgICAgICAgICAgICAgICAgIGhlcmVfb3AgPSBoZXJlID4+PiAxNiAmIDI1NTsKICAgICAgICAgICAgICAgICAgaGVyZV92YWwgPSBoZXJlICYgNjU1MzU7CiAgICAgICAgICAgICAgICAgIGlmIChoZXJlX2JpdHMgPD0gYml0cykgewogICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmIChoZXJlX29wICYmIChoZXJlX29wICYgMjQwKSA9PT0gMCkgewogICAgICAgICAgICAgICAgICBsYXN0X2JpdHMgPSBoZXJlX2JpdHM7CiAgICAgICAgICAgICAgICAgIGxhc3Rfb3AgPSBoZXJlX29wOwogICAgICAgICAgICAgICAgICBsYXN0X3ZhbCA9IGhlcmVfdmFsOwogICAgICAgICAgICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgICAgICAgICAgICBoZXJlID0gc3RhdGUubGVuY29kZVtsYXN0X3ZhbCArICgoaG9sZCAmICgxIDw8IGxhc3RfYml0cyArIGxhc3Rfb3ApIC0gMSkgPj4gbGFzdF9iaXRzKV07CiAgICAgICAgICAgICAgICAgICAgaGVyZV9iaXRzID0gaGVyZSA+Pj4gMjQ7CiAgICAgICAgICAgICAgICAgICAgaGVyZV9vcCA9IGhlcmUgPj4+IDE2ICYgMjU1OwogICAgICAgICAgICAgICAgICAgIGhlcmVfdmFsID0gaGVyZSAmIDY1NTM1OwogICAgICAgICAgICAgICAgICAgIGlmIChsYXN0X2JpdHMgKyBoZXJlX2JpdHMgPD0gYml0cykgewogICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaG9sZCA+Pj49IGxhc3RfYml0czsKICAgICAgICAgICAgICAgICAgYml0cyAtPSBsYXN0X2JpdHM7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmJhY2sgKz0gbGFzdF9iaXRzOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaG9sZCA+Pj49IGhlcmVfYml0czsKICAgICAgICAgICAgICAgIGJpdHMgLT0gaGVyZV9iaXRzOwogICAgICAgICAgICAgICAgc3RhdGUuYmFjayArPSBoZXJlX2JpdHM7CiAgICAgICAgICAgICAgICBzdGF0ZS5sZW5ndGggPSBoZXJlX3ZhbDsKICAgICAgICAgICAgICAgIGlmIChoZXJlX29wID09PSAwKSB7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBMSVQ7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKGhlcmVfb3AgJiAzMikgewogICAgICAgICAgICAgICAgICBzdGF0ZS5iYWNrID0gLTE7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBUWVBFOwogICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmIChoZXJlX29wICYgNjQpIHsKICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW52YWxpZCBsaXRlcmFsL2xlbmd0aCBjb2RlIjsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5leHRyYSA9IGhlcmVfb3AgJiAxNTsKICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBMRU5FWFQ7CiAgICAgICAgICAgICAgY2FzZSBMRU5FWFQ6CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuZXh0cmEpIHsKICAgICAgICAgICAgICAgICAgbiA9IHN0YXRlLmV4dHJhOwogICAgICAgICAgICAgICAgICB3aGlsZSAoYml0cyA8IG4pIHsKICAgICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIHN0YXRlLmxlbmd0aCArPSBob2xkICYgKDEgPDwgc3RhdGUuZXh0cmEpIC0gMTsKICAgICAgICAgICAgICAgICAgaG9sZCA+Pj49IHN0YXRlLmV4dHJhOwogICAgICAgICAgICAgICAgICBiaXRzIC09IHN0YXRlLmV4dHJhOwogICAgICAgICAgICAgICAgICBzdGF0ZS5iYWNrICs9IHN0YXRlLmV4dHJhOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUud2FzID0gc3RhdGUubGVuZ3RoOwogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IERJU1Q7CiAgICAgICAgICAgICAgY2FzZSBESVNUOgogICAgICAgICAgICAgICAgZm9yICg7IDsgKSB7CiAgICAgICAgICAgICAgICAgIGhlcmUgPSBzdGF0ZS5kaXN0Y29kZVtob2xkICYgKDEgPDwgc3RhdGUuZGlzdGJpdHMpIC0gMV07CiAgICAgICAgICAgICAgICAgIGhlcmVfYml0cyA9IGhlcmUgPj4+IDI0OwogICAgICAgICAgICAgICAgICBoZXJlX29wID0gaGVyZSA+Pj4gMTYgJiAyNTU7CiAgICAgICAgICAgICAgICAgIGhlcmVfdmFsID0gaGVyZSAmIDY1NTM1OwogICAgICAgICAgICAgICAgICBpZiAoaGVyZV9iaXRzIDw9IGJpdHMpIHsKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoKGhlcmVfb3AgJiAyNDApID09PSAwKSB7CiAgICAgICAgICAgICAgICAgIGxhc3RfYml0cyA9IGhlcmVfYml0czsKICAgICAgICAgICAgICAgICAgbGFzdF9vcCA9IGhlcmVfb3A7CiAgICAgICAgICAgICAgICAgIGxhc3RfdmFsID0gaGVyZV92YWw7CiAgICAgICAgICAgICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgICAgICAgICAgIGhlcmUgPSBzdGF0ZS5kaXN0Y29kZVtsYXN0X3ZhbCArICgoaG9sZCAmICgxIDw8IGxhc3RfYml0cyArIGxhc3Rfb3ApIC0gMSkgPj4gbGFzdF9iaXRzKV07CiAgICAgICAgICAgICAgICAgICAgaGVyZV9iaXRzID0gaGVyZSA+Pj4gMjQ7CiAgICAgICAgICAgICAgICAgICAgaGVyZV9vcCA9IGhlcmUgPj4+IDE2ICYgMjU1OwogICAgICAgICAgICAgICAgICAgIGhlcmVfdmFsID0gaGVyZSAmIDY1NTM1OwogICAgICAgICAgICAgICAgICAgIGlmIChsYXN0X2JpdHMgKyBoZXJlX2JpdHMgPD0gYml0cykgewogICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaG9sZCA+Pj49IGxhc3RfYml0czsKICAgICAgICAgICAgICAgICAgYml0cyAtPSBsYXN0X2JpdHM7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmJhY2sgKz0gbGFzdF9iaXRzOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaG9sZCA+Pj49IGhlcmVfYml0czsKICAgICAgICAgICAgICAgIGJpdHMgLT0gaGVyZV9iaXRzOwogICAgICAgICAgICAgICAgc3RhdGUuYmFjayArPSBoZXJlX2JpdHM7CiAgICAgICAgICAgICAgICBpZiAoaGVyZV9vcCAmIDY0KSB7CiAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImludmFsaWQgZGlzdGFuY2UgY29kZSI7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUub2Zmc2V0ID0gaGVyZV92YWw7CiAgICAgICAgICAgICAgICBzdGF0ZS5leHRyYSA9IGhlcmVfb3AgJiAxNTsKICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBESVNURVhUOwogICAgICAgICAgICAgIGNhc2UgRElTVEVYVDoKICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5leHRyYSkgewogICAgICAgICAgICAgICAgICBuID0gc3RhdGUuZXh0cmE7CiAgICAgICAgICAgICAgICAgIHdoaWxlIChiaXRzIDwgbikgewogICAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgc3RhdGUub2Zmc2V0ICs9IGhvbGQgJiAoMSA8PCBzdGF0ZS5leHRyYSkgLSAxOwogICAgICAgICAgICAgICAgICBob2xkID4+Pj0gc3RhdGUuZXh0cmE7CiAgICAgICAgICAgICAgICAgIGJpdHMgLT0gc3RhdGUuZXh0cmE7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmJhY2sgKz0gc3RhdGUuZXh0cmE7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUub2Zmc2V0ID4gc3RhdGUuZG1heCkgewogICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbnZhbGlkIGRpc3RhbmNlIHRvbyBmYXIgYmFjayI7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IE1BVENIOwogICAgICAgICAgICAgIGNhc2UgTUFUQ0g6CiAgICAgICAgICAgICAgICBpZiAobGVmdCA9PT0gMCkgewogICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBjb3B5ID0gX291dCAtIGxlZnQ7CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUub2Zmc2V0ID4gY29weSkgewogICAgICAgICAgICAgICAgICBjb3B5ID0gc3RhdGUub2Zmc2V0IC0gY29weTsKICAgICAgICAgICAgICAgICAgaWYgKGNvcHkgPiBzdGF0ZS53aGF2ZSkgewogICAgICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5zYW5lKSB7CiAgICAgICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbnZhbGlkIGRpc3RhbmNlIHRvbyBmYXIgYmFjayI7CiAgICAgICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEOwogICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChjb3B5ID4gc3RhdGUud25leHQpIHsKICAgICAgICAgICAgICAgICAgICBjb3B5IC09IHN0YXRlLnduZXh0OwogICAgICAgICAgICAgICAgICAgIGZyb20gPSBzdGF0ZS53c2l6ZSAtIGNvcHk7CiAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgZnJvbSA9IHN0YXRlLnduZXh0IC0gY29weTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBpZiAoY29weSA+IHN0YXRlLmxlbmd0aCkgewogICAgICAgICAgICAgICAgICAgIGNvcHkgPSBzdGF0ZS5sZW5ndGg7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgZnJvbV9zb3VyY2UgPSBzdGF0ZS53aW5kb3c7CiAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICBmcm9tX3NvdXJjZSA9IG91dHB1dDsKICAgICAgICAgICAgICAgICAgZnJvbSA9IHB1dCAtIHN0YXRlLm9mZnNldDsKICAgICAgICAgICAgICAgICAgY29weSA9IHN0YXRlLmxlbmd0aDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmIChjb3B5ID4gbGVmdCkgewogICAgICAgICAgICAgICAgICBjb3B5ID0gbGVmdDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGxlZnQgLT0gY29weTsKICAgICAgICAgICAgICAgIHN0YXRlLmxlbmd0aCAtPSBjb3B5OwogICAgICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgICAgICBvdXRwdXRbcHV0KytdID0gZnJvbV9zb3VyY2VbZnJvbSsrXTsKICAgICAgICAgICAgICAgIH0gd2hpbGUgKC0tY29weSk7CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUubGVuZ3RoID09PSAwKSB7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBMRU47CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICBjYXNlIExJVDoKICAgICAgICAgICAgICAgIGlmIChsZWZ0ID09PSAwKSB7CiAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIG91dHB1dFtwdXQrK10gPSBzdGF0ZS5sZW5ndGg7CiAgICAgICAgICAgICAgICBsZWZ0LS07CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gTEVOOwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgY2FzZSBDSEVDSzoKICAgICAgICAgICAgICAgIGlmIChzdGF0ZS53cmFwKSB7CiAgICAgICAgICAgICAgICAgIHdoaWxlIChiaXRzIDwgMzIpIHsKICAgICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgICAgaG9sZCB8PSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIF9vdXQgLT0gbGVmdDsKICAgICAgICAgICAgICAgICAgc3RybS50b3RhbF9vdXQgKz0gX291dDsKICAgICAgICAgICAgICAgICAgc3RhdGUudG90YWwgKz0gX291dDsKICAgICAgICAgICAgICAgICAgaWYgKF9vdXQpIHsKICAgICAgICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gc3RhdGUuY2hlY2sgPSBzdGF0ZS5mbGFncyA/IGNyYzMyMihzdGF0ZS5jaGVjaywgb3V0cHV0LCBfb3V0LCBwdXQgLSBfb3V0KSA6IGFkbGVyMzIoc3RhdGUuY2hlY2ssIG91dHB1dCwgX291dCwgcHV0IC0gX291dCk7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgX291dCA9IGxlZnQ7CiAgICAgICAgICAgICAgICAgIGlmICgoc3RhdGUuZmxhZ3MgPyBob2xkIDogenN3YXAzMihob2xkKSkgIT09IHN0YXRlLmNoZWNrKSB7CiAgICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW5jb3JyZWN0IGRhdGEgY2hlY2siOwogICAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaG9sZCA9IDA7CiAgICAgICAgICAgICAgICAgIGJpdHMgPSAwOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IExFTkdUSDsKICAgICAgICAgICAgICBjYXNlIExFTkdUSDoKICAgICAgICAgICAgICAgIGlmIChzdGF0ZS53cmFwICYmIHN0YXRlLmZsYWdzKSB7CiAgICAgICAgICAgICAgICAgIHdoaWxlIChiaXRzIDwgMzIpIHsKICAgICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChob2xkICE9PSAoc3RhdGUudG90YWwgJiA0Mjk0OTY3Mjk1KSkgewogICAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImluY29ycmVjdCBsZW5ndGggY2hlY2siOwogICAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaG9sZCA9IDA7CiAgICAgICAgICAgICAgICAgIGJpdHMgPSAwOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IERPTkU7CiAgICAgICAgICAgICAgY2FzZSBET05FOgogICAgICAgICAgICAgICAgcmV0ID0gWl9TVFJFQU1fRU5EOwogICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgIGNhc2UgQkFEOgogICAgICAgICAgICAgICAgcmV0ID0gWl9EQVRBX0VSUk9SOwogICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgIGNhc2UgTUVNOgogICAgICAgICAgICAgICAgcmV0dXJuIFpfTUVNX0VSUk9SOwogICAgICAgICAgICAgIGNhc2UgU1lOQzoKICAgICAgICAgICAgICBkZWZhdWx0OgogICAgICAgICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VSUk9SOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgc3RybS5uZXh0X291dCA9IHB1dDsKICAgICAgICBzdHJtLmF2YWlsX291dCA9IGxlZnQ7CiAgICAgICAgc3RybS5uZXh0X2luID0gbmV4dDsKICAgICAgICBzdHJtLmF2YWlsX2luID0gaGF2ZTsKICAgICAgICBzdGF0ZS5ob2xkID0gaG9sZDsKICAgICAgICBzdGF0ZS5iaXRzID0gYml0czsKICAgICAgICBpZiAoc3RhdGUud3NpemUgfHwgX291dCAhPT0gc3RybS5hdmFpbF9vdXQgJiYgc3RhdGUubW9kZSA8IEJBRCAmJiAoc3RhdGUubW9kZSA8IENIRUNLIHx8IGZsdXNoICE9PSBaX0ZJTklTSCkpIHsKICAgICAgICAgIGlmICh1cGRhdGV3aW5kb3coc3RybSwgc3RybS5vdXRwdXQsIHN0cm0ubmV4dF9vdXQsIF9vdXQgLSBzdHJtLmF2YWlsX291dCkpIHsKICAgICAgICAgICAgc3RhdGUubW9kZSA9IE1FTTsKICAgICAgICAgICAgcmV0dXJuIFpfTUVNX0VSUk9SOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBfaW4gLT0gc3RybS5hdmFpbF9pbjsKICAgICAgICBfb3V0IC09IHN0cm0uYXZhaWxfb3V0OwogICAgICAgIHN0cm0udG90YWxfaW4gKz0gX2luOwogICAgICAgIHN0cm0udG90YWxfb3V0ICs9IF9vdXQ7CiAgICAgICAgc3RhdGUudG90YWwgKz0gX291dDsKICAgICAgICBpZiAoc3RhdGUud3JhcCAmJiBfb3V0KSB7CiAgICAgICAgICBzdHJtLmFkbGVyID0gc3RhdGUuY2hlY2sgPSBzdGF0ZS5mbGFncyA/IGNyYzMyMihzdGF0ZS5jaGVjaywgb3V0cHV0LCBfb3V0LCBzdHJtLm5leHRfb3V0IC0gX291dCkgOiBhZGxlcjMyKHN0YXRlLmNoZWNrLCBvdXRwdXQsIF9vdXQsIHN0cm0ubmV4dF9vdXQgLSBfb3V0KTsKICAgICAgICB9CiAgICAgICAgc3RybS5kYXRhX3R5cGUgPSBzdGF0ZS5iaXRzICsgKHN0YXRlLmxhc3QgPyA2NCA6IDApICsgKHN0YXRlLm1vZGUgPT09IFRZUEUgPyAxMjggOiAwKSArIChzdGF0ZS5tb2RlID09PSBMRU5fIHx8IHN0YXRlLm1vZGUgPT09IENPUFlfID8gMjU2IDogMCk7CiAgICAgICAgaWYgKChfaW4gPT09IDAgJiYgX291dCA9PT0gMCB8fCBmbHVzaCA9PT0gWl9GSU5JU0gpICYmIHJldCA9PT0gWl9PSykgewogICAgICAgICAgcmV0ID0gWl9CVUZfRVJST1I7CiAgICAgICAgfQogICAgICAgIHJldHVybiByZXQ7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gaW5mbGF0ZUVuZChzdHJtKSB7CiAgICAgICAgaWYgKCFzdHJtIHx8ICFzdHJtLnN0YXRlKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIHZhciBzdGF0ZSA9IHN0cm0uc3RhdGU7CiAgICAgICAgaWYgKHN0YXRlLndpbmRvdykgewogICAgICAgICAgc3RhdGUud2luZG93ID0gbnVsbDsKICAgICAgICB9CiAgICAgICAgc3RybS5zdGF0ZSA9IG51bGw7CiAgICAgICAgcmV0dXJuIFpfT0s7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gaW5mbGF0ZUdldEhlYWRlcihzdHJtLCBoZWFkKSB7CiAgICAgICAgdmFyIHN0YXRlOwogICAgICAgIGlmICghc3RybSB8fCAhc3RybS5zdGF0ZSkgewogICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VSUk9SOwogICAgICAgIH0KICAgICAgICBzdGF0ZSA9IHN0cm0uc3RhdGU7CiAgICAgICAgaWYgKChzdGF0ZS53cmFwICYgMikgPT09IDApIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgc3RhdGUuaGVhZCA9IGhlYWQ7CiAgICAgICAgaGVhZC5kb25lID0gZmFsc2U7CiAgICAgICAgcmV0dXJuIFpfT0s7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gaW5mbGF0ZVNldERpY3Rpb25hcnkoc3RybSwgZGljdGlvbmFyeSkgewogICAgICAgIHZhciBkaWN0TGVuZ3RoID0gZGljdGlvbmFyeS5sZW5ndGg7CiAgICAgICAgdmFyIHN0YXRlOwogICAgICAgIHZhciBkaWN0aWQ7CiAgICAgICAgdmFyIHJldDsKICAgICAgICBpZiAoIXN0cm0gfHwgIXN0cm0uc3RhdGUpIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgc3RhdGUgPSBzdHJtLnN0YXRlOwogICAgICAgIGlmIChzdGF0ZS53cmFwICE9PSAwICYmIHN0YXRlLm1vZGUgIT09IERJQ1QpIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgaWYgKHN0YXRlLm1vZGUgPT09IERJQ1QpIHsKICAgICAgICAgIGRpY3RpZCA9IDE7CiAgICAgICAgICBkaWN0aWQgPSBhZGxlcjMyKGRpY3RpZCwgZGljdGlvbmFyeSwgZGljdExlbmd0aCwgMCk7CiAgICAgICAgICBpZiAoZGljdGlkICE9PSBzdGF0ZS5jaGVjaykgewogICAgICAgICAgICByZXR1cm4gWl9EQVRBX0VSUk9SOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXQgPSB1cGRhdGV3aW5kb3coc3RybSwgZGljdGlvbmFyeSwgZGljdExlbmd0aCwgZGljdExlbmd0aCk7CiAgICAgICAgaWYgKHJldCkgewogICAgICAgICAgc3RhdGUubW9kZSA9IE1FTTsKICAgICAgICAgIHJldHVybiBaX01FTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgc3RhdGUuaGF2ZWRpY3QgPSAxOwogICAgICAgIHJldHVybiBaX09LOwogICAgICB9CiAgICAgIGV4cG9ydHMuaW5mbGF0ZVJlc2V0ID0gaW5mbGF0ZVJlc2V0OwogICAgICBleHBvcnRzLmluZmxhdGVSZXNldDIgPSBpbmZsYXRlUmVzZXQyOwogICAgICBleHBvcnRzLmluZmxhdGVSZXNldEtlZXAgPSBpbmZsYXRlUmVzZXRLZWVwOwogICAgICBleHBvcnRzLmluZmxhdGVJbml0ID0gaW5mbGF0ZUluaXQ7CiAgICAgIGV4cG9ydHMuaW5mbGF0ZUluaXQyID0gaW5mbGF0ZUluaXQyOwogICAgICBleHBvcnRzLmluZmxhdGUgPSBpbmZsYXRlOwogICAgICBleHBvcnRzLmluZmxhdGVFbmQgPSBpbmZsYXRlRW5kOwogICAgICBleHBvcnRzLmluZmxhdGVH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X0JFU1RfQ09NUFJFU1NJT046IDksCiAgICAgICAgWl9ERUZBVUxUX0NPTVBSRVNTSU9OOiAtMSwKICAgICAgICBaX0ZJTFRFUkVEOiAxLAogICAgICAgIFpfSFVGRk1BTl9PTkxZOiAyLAogICAgICAgIFpfUkxFOiAzLAogICAgICAgIFpfRklYRUQ6IDQsCiAgICAgICAgWl9ERUZBVUxUX1NUUkFURUdZOiAwLAogICAgICAgIFpfQklOQVJZOiAwLAogICAgICAgIFpfVEVYVDogMSwKICAgICAgICBaX1VOS05PV046IDIsCiAgICAgICAgWl9ERUZMQVRFRDogOAogICAgICB9OwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvZ3poZWFkZXIuanMKICB2YXIgcmVxdWlyZV9nemhlYWRlciA9IF9fY29tbW9uSlMoewogICAgIm5vZGVfbW9kdWxlcy8ucG5wbS9wYWtvQDEuMC4xMS9ub2RlX21vZHVsZXMvcGFrby9saWIvemxpYi9nemhlYWRlci5qcyIoZXhwb3J0cywgbW9kdWxlKSB7CiAgICAgIGluaXRfYnVmZmVyX3NoaW0oKTsKICAgICAgInVzZSBzdHJpY3QiOwogICAgICBmdW5jdGlvbiBHWmhlYWRlcigpIHsKICAgICAgICB0aGlzLnRleHQgPSAwOwogICAgICAgIHRoaXMudGltZSA9IDA7CiAgICAgICAgdGhpcy54ZmxhZ3MgPSAwOwogICAgICAgIHRoaXMub3MgPSAwOwogICAgICAgIHRoaXMuZXh0cmEgPSBudWxsOwogICAgICAgIHRoaXMuZXh0cmFfbGVuID0gMDsKICAgICAgICB0aGlzLm5hbWUgPSAiIjsKICAgICAgICB0aGlzLmNvbW1lbnQgPSAiIjsKICAgICAgICB0aGlzLmhjcmMgPSAwOwogICAgICAgIHRoaXMuZG9uZSA9IGZhbHNlOwogICAgICB9CiAgICAgIG1vZHVsZS5leHBvcnRzID0gR1poZWFkZXI7Ci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5vcHRpb25zOwogICAgICAgIGlmIChvcHQucmF3ICYmIG9wdC53aW5kb3dCaXRzID49IDAgJiYgb3B0LndpbmRvd0JpdHMgPCAxNikgewogICAgICAgICAgb3B0LndpbmRvd0JpdHMgPSAtb3B0LndpbmRvd0JpdHM7CiAgICAgICAgICBpZiAob3B0LndpbmRvd0JpdHMgPT09IDApIHsKICAgICAgICAgICAgb3B0LndpbmRvd0JpdHMgPSAtMTU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChvcHQud2luZG93Qml0cyA+PSAwICYmIG9wdC53aW5kb3dCaXRzIDwgMTYgJiYgIShvcHRpb25zICYmIG9wdGlvbnMud2luZG93Qml0cykpIHsKICAgICAgICAgIG9wdC53aW5kb3dCaXRzICs9IDMyOwogICAgICAgIH0KICAgICAgICBpZiAob3B0LndpbmRvd0JpdHMgPiAxNSAmJiBvcHQud2luZG93Qml0cyA8IDQ4KSB7CiAgICAgICAgICBpZiAoKG9wdC53aW5kb3dCaXRzICYgMTUpID09PSAwKSB7CiAgICAgICAgICAgIG9wdC53aW5kb3dCaXRzIHw9IDE1OwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICB0aGlzLmVyciA9IDA7CiAgICAgICAgdGhpcy5tc2cgPSAiIjsKICAgICAgICB0aGlzLmVuZGVkID0gZmFsc2U7CiAgICAgICAgdGhpcy5jaHVua3MgPSBbXTsKICAgICAgICB0aGlzLnN0cm0gPSBuZXcgWlN0cmVhbSgpOwogICAgICAgIHRoaXMuc3RybS5hdmFpbF9vdXQgPSAwOwogICAgICAgIHZhciBzdGF0dXMgPSB6bGliX2luZmxhdGUuaW5mbGF0ZUluaXQyKHRoaXMuc3RybSwgb3B0LndpbmRvd0JpdHMpOwogICAgICAgIGlmIChzdGF0dXMgIT09IGMuWl9PSykgewogICAgICAgICAgdGhyb3cgbmV3IEVycm9yKG1zZ1tzdGF0dXNdKTsKICAgICAgICB9CiAgICAgICAgdGhpcy5oZWFkZXIgPSBuZXcgR1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CwgdGFpbCwgdXRmOHN0cjsKICAgICAgICB2YXIgYWxsb3dCdWZFcnJvciA9IGZhbHNlOwogICAgICAgIGlmICh0aGlzLmVuZGVkKSB7CiAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgfQogICAgICAgIF9tb2RlID0gbW9kZSA9PT0gfn5tb2RlID8gbW9kZSA6IG1vZGUgPT09IHRydWUgPyBjLlpfRklOSVNIIDogYy5aX05PX0ZMVVNIOwogICAgICAgIGlmICh0eXBlb2YgZGF0YSA9PT0gInN0cmluZyIpIHsKICAgICAgICAgIHN0cm0uaW5wdXQgPSBzdHJpbmdzLmJpbnN0cmluZzJidWYoZGF0YSk7CiAgICAgICAgfSBlbHNlIGlmICh0b1N0cmluZy5jYWxsKGRhdGEpID09PSAiW29iamVjdCBBcnJheUJ1ZmZlcl0iKSB7CiAgICAgICAgICBzdHJtLmlucHV0ID0gbmV3IFVpbnQ4QXJyYXkoZGF0YSk7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIHN0cm0uaW5wdXQgPSBkYXRhOwogICAgICAgIH0KICAgICAgICBzdHJtLm5leHRfaW4gPSAwOwogICAgICAgIHN0cm0uYXZhaWxfaW4gPSBzdHJtLmlucHV0Lmxlbmd0aDsKICAgICAgICBkbyB7CiAgICAgICAgICBpZiAoc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgc3RybS5vdXRwdXQgPSBuZXcgdXRpbHMuQnVmOChjaHVua1NpemUpOwogICAgICAgICAgICBzdHJtLm5leHRfb3V0ID0gMDsKICAgICAgICAgICAgc3RybS5hdmFpbF9vdXQgPSBjaHVua1NpemU7CiAgICAgICAgICB9CiAgICAgICAgICBzdGF0dXMgPSB6bGliX2luZmxhdGUuaW5mbGF0ZShzdHJtLCBjLlpfTk9fRkxVU0gpOwogICAgICAgICAgaWYgKHN0YXR1cyA9PT0gYy5aX05FRURfRElDVCAmJiBkaWN0aW9uYXJ5KSB7CiAgICAgICAgICAgIHN0YXR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S5uZXh0X291dCA9IHRhaWw7CiAgICAgICAgICAgICAgICBzdHJtLmF2YWlsX291dCA9IGNodW5rU2l6ZSAtIHRhaWw7CiAgICAgICAgICAgICAgICBpZiAodGFpbCkgewogICAgICAgICAgICAgICAgICB1dGlscy5hcnJheVNldChzdHJtLm91dHB1dCwgc3RybS5vdXRwdXQsIG5leHRfb3V0X3V0ZjgsIHRhaWwsIDApOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgdGhpcy5vbkRhdGEodXRmOHN0cik7CiAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIHRoaXMub25EYXRhKHV0aWxzLnNocmlua0J1ZihzdHJtLm91dHB1dCwgc3RybS5uZXh0X291dCkpOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgaWYgKHN0cm0uYXZhaWxfaW4gPT09IDAgJiYgc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgYWxsb3dCdWZFcnJvciA9IHRydWU7CiAgICAgICAgICB9CiAgICAgICAgfSB3aGlsZSAoKHN0cm0uYXZhaWxfaW4gPiAwIHx8IHN0cm0uYXZhaWxfb3V0ID09PSAwKSAmJiBzdGF0dXMgIT09IGMuWl9TVFJFQU1fRU5EKTsKICAgICAgICBpZiAoc3RhdHVzID09PSBjLlpfU1RSRUFNX0VORCkgewogICAgICAgICAgX21vZGUgPSBjLlpfRklOSVNIOwogICAgICAgIH0KICAgICAgICBpZiAoX21vZGUgPT09IGMuWl9GSU5JU0gpIHsKICAgICAgICAgIHN0YXR1cyA9IHpsaWJfaW5mbGF0ZS5pbmZsYXRlRW5kKHRoaXMuc3RybSk7CiAgICAgICAgICB0aGlzLm9uRW5kKHN0YXR1cyk7CiAgICAgICAgICB0aGlzLmVuZGVkID0gdHJ1ZTsKICAgICAgICAgIHJldHVybiBzdGF0dXMgPT09IGMuWl9PSzsKICAgICAgICB9CiAgICAgICAgaWYgKF9tb2RlID09PSBjLlpfU1lOQ19GTFVTSCkgewogICAgICAgICAgdGhpcy5vbkVuZChjLlpfT0spOwogICAgICAgICAgc3RybS5hdmFpbF9vdXQgPSAwOwogICAgICAgICAgcmV0dXJuIHRydWU7CiAgICAgICAgfQogICAgICAgIHJldHVybiB0cnVlOwogICAgICB9OwogICAgICBJbmZsYXRlMi5wcm90b3R5cGUub25EYXRhID0gZnVuY3Rpb24oY2h1bmspIHsKICAgICAgICB0aGlzLmNodW5rcy5wdXNoKGNodW5rKTsKICAgICAgfTsKICAgICAgSW5mbGF0ZTIucHJvdG90eXBlLm9uRW5kID0gZnVuY3Rpb24oc3RhdHVzKSB7CiAgICAgICAgaWYgKHN0YXR1cyA9PT0gYy5aX09LKSB7CiAgICAgICAgICBpZiAodGhpcy5vcHRpb25zLnRvID09PSAic3RyaW5nIikgewogICAgICAgICAgICB0aGlzLnJlc3VsdCA9IHRoaXMuY2h1bmtzLmpvaW4oIiIpOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgdGhpcy5yZXN1bHQgPSB1dGlscy5mbGF0dGVuQ2h1bmtzKHRoaXMuY2h1bmtzKTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgdGhpcy5jaHVua3MgPSBbXTsKICAgICAgICB0aGlzLmVyciA9IHN0YXR1czsKICAgICAgICB0aGlzLm1zZyA9IHRoaXMuc3RybS5tc2c7CiAgICAgIH07CiAgICAgIGZ1bmN0aW9uIGluZmxhdGUoaW5wdXQsIG9wdGlvbnMpIHsKICAgICAgICB2YXIgaW5mbGF0b3IgPSBuZXcgSW5mbGF0ZTIob3B0aW9ucyk7CiAgICAgICAgaW5mbGF0b3IucHVzaChpbnB1dCwgdHJ1ZSk7CiAgICAgICAgaWYgKGluZmxhdG9yLmVycikgewogICAgICAgICAgdGhyb3cgaW5mbGF0b3IubXNnIHx8IG1zZ1tpbmZsYXRvci5lcnJdOwogICAgICAgIH0KICAgICAgICByZXR1cm4gaW5mbGF0b3IucmVzdWx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yNjYzNiwKICAgICAgICAzMzU2MzM0ODcsCiAgICAgICAgMTY2MTM2NTQ2NSwKICAgICAgICA0MTk1MzAyNzU1LAogICAgICAgIDIzNjYxMTUzMTcsCiAgICAgICAgOTk3MDczMDk2LAogICAgICAgIDEyODE5NTM4ODYsCiAgICAgICAgMzU3OTg1NTMzMiwKICAgICAgICAyNzI0Njg4MjQyLAogICAgICAgIDEwMDY4ODgxNDUsCiAgICAgICAgMTI1ODYwNzY4NywKICAgICAgICAzNTI0MTAxNjI5LAogICAgICAgIDI3Njg5NDI0NDMsCiAgICAgICAgOTAxMDk3NzIyLAogICAgICAgIDExMTkwMDA2ODQsCiAgICAgICAgMzY4NjUxNzIwNiwKICAgICAgICAyODk4MDY1NzI4LAogICAgICAgIDg1MzA0NDQ1MSwKICAgICAgICAxMTcyMjY2MTAxLAogICAgICAgIDM3MDUwMTU3NTksCiAgICAgICAgMjg4MjYxNjY2NSwKICAgICAgICA2NTE3Njc5ODAsCiAgICAgICAgMTM3MzUwMzU0NiwKICAgICAgICAzMzY5NTU0MzA0LAogICAgICAgIDMyMTgxMDQ1OTgsCiAgICAgICAgNTY1NTA3MjUzLAogICAgICAgIDE0NTQ2MjE3MzEsCiAgICAgICAgMzQ4NTExMTcwNSwKICAgICAgICAzMDk5NDM2MzAzLAogICAgICAgIDY3MTI2Njk3NCwKICAgICAgICAxNTk0MTk4MDI0LAogICAgICAgIDMzMjI3MzA5MzAsCiAgICAgICAgMjk3MDM0NzgxMiwKICAgICAgICA3OTU4MzU1MjcsCiAgICAgICAgMTQ4MzIzMDIyNSwKICAgICAgICAzMjQ0MzY3Mjc1LAogICAgICAgIDMwNjAxNDk1NjUsCiAgICAgICAgMTk5NDE0NjE5MiwKICAgICAgICAzMTE1ODUzNCwKICAgICAgICAyNTYzOTA3NzcyLAogICAgICAgIDQwMjM3MTc5MzAsCiAgICAgICAgMTkwNzQ1OTQ2NSwKICAgICAgICAxMTI2MzcyMTUsCiAgICAgICAgMjY4MDE1MzI1MywKICAgICAgICAzOTA0NDI3MDU5LAogICAgICAgIDIwMTM3NzYyOTAsCiAgICAgICAgMjUxNzIyMDM2LAogICAgICAgIDI1MTcyMTUzNzQsCiAgICAgICAgMzc3NTgzMDA0MCwKICAgICAgICAyMTM3NjU2NzYzLAogICAgICAgIDE0MTM3NjgxMywKICAgICAgICAyNDM5Mjc3NzE5LAogICAgICAgIDM4NjUyNzEyOTcsCiAgICAgICAgMTgwMjE5NTQ0NCwKICAgICAgICA0NzY4NjQ4NjYsCiAgICAgICAgMjIzODAwMTM2OCwKICAgICAgICA0MDY2NTA4ODc4LAogICAgICAgIDE4MTIzNzA5MjUsCiAgICAgICAgNDUzMDkyNzMxLAogICAgICAgIDIxODE2MjUwMjUsCiAgICAgICAgNDExMTQ1MTIyMywKICAgICAgICAxNzA2MDg4OTAyLAogICAgICAgIDMxNDA0MjcwNCwKICAgICAgICAyMzQ0NTMyMjAyLAogICAgICAgIDQyNDAwMTc1MzIsCiAgICAgICAgMTY1ODY1ODI3MSwKICAgICAgICAzNjY2MTk5NzcsCiAgICAgICAgMjM2MjY3MDMyMywKICAgICAgICA0MjI0OTk0NDA1LAogICAgICAgIDEzMDM1MzU5NjAsCiAgICAgICAgOTg0OTYxNDg2LAogICAgICAgIDI3NDcwMDcwOTIsCiAgICAgICAgMzU2OTAzNzUzOCwKICAgICAgICAxMjU2MTcwODE3LAogICAgICAgIDEwMzc2MDQzMTEsCiAgICAgICAgMjc2NTIxMDczMywKICAgICAgICAzNTU0MDc5OTk1LAogICAgICAgIDExMzEwMTQ1MDYsCiAgICAgICAgODc5Njc5OTk2LAogICAgICAgIDI5MDkyNDM0NjIsCiAgICAgICAgMzY2Mzc3MTg1NiwKICAgICAgICAxMTQxMTI0NDY3LAogICAgICAgIDg1NTg0MjI3NywKICAgICAgICAyODUyODAxNjMxLAogICAgICAgIDM3MDg2NDg2NDksCiAgICAgICAgMTM0MjUzMzk0OCwKICAgICAgICA2NTQ0NTkzMDYsCiAgICAgICAgMzE4ODM5NjA0OCwKICAgICAgICAzMzczMDE1MTc0LAogICAgICAgIDE0NjY0Nzk5MDksCiAgICAgICAgNTQ0MTc5NjM1LAogICAgICAgIDMxMTA1MjM5MTMsCiAgICAgICAgMzQ2MjUyMjAxNSwKICAgICAgICAxNTkxNjcxMDU0LAogICAgICAgIDcwMjEzODc3NiwKICAgICAgICAyOTY2NDYwNDUwLAogICAgICAgIDMzNTI3OTk0MTIsCiAgICAgICAgMTUwNDkxODgwNywKICAgICAgICA3ODM1NTE4NzMsCiAgICAgICAgMzA4MjY0MDQ0MywKICAgICAgICAzMjMzNDQyOTg5LAogICAgICAgIDM5ODgyOTIzODQsCiAgICAgICAgMjU5NjI1NDY0NiwKICAgICAgICA2MjMxNzA2OCwKICAgICAgICAxOTU3ODEwODQyLAogICAgICAgIDM5Mzk4NDU5NDUsCiAgICAgICAgMjY0NzgxNjExMSwKICAgICAgICA4MTQ3MDk5NywKICAgICAgICAxOTQzODAzNTIzLAogICAgICAgIDM4MTQ5MTg5MzAsCiAgICAgICAgMjQ4OTU5NjgwNCwKICAgICAgICAyMjUyNzQ0MzAsCiAgICAgICAgMjA1Mzc5MDM3NiwKICAgICAgICAzODI2MTc1NzU1LAogICAgICAgIDI0NjY5MDYwMTMsCiAgICAgICAgMTY3ODE2NzQzLAogICAgICAgIDIwOTc2NTEzNzcsCiAgICAgICAgNDAyNzU1MjU4MCwKICAgICAgICAyMjY1NDkwMzg2LAogICAgICAgIDUwMzQ0NDA3MiwKICAgICAgICAxNzYyMDUwODE0LAogICAgICAgIDQxNTA0MTcyNDUsCiAgICAgICAgMjE1NDEyOTM1NSwKICAgICAgICA0MjY1MjIyMjUsCiAgICAgICAgMTg1MjUwNzg3OSwKICAgICAgICA0Mjc1MzEzNTI2LAogICAgICAgIDIzMTIzMTc5MjAsCiAgICAgICAgMjgyNzUzNjI2LAogICAgICAgIDE3NDI1NTU4NTIsCiAgICAgICAgNDE4OTcwODE0MywKICAgICAgICAyMzk0ODc3OTQ1LAogICAgICAgIDM5NzkxNzc2MywKICAgICAgICAxNjIyMTgzNjM3LAogICAgICAgIDM2MDQzOTA4ODgsCiAgICAgICAgMjcxNDg2NjU1OCwKICAgICAgICA5NTM3Mjk3MzIsCiAgICAgICAgMTM0MDA3NjYyNiwKICAgICAgICAzNTE4NzE5OTg1LAogICAgICAgIDI3OTczNjA5OTksCiAgICAgICAgMTA2ODgyODM4MSwKICAgICAgICAxMjE5NjM4ODU5LAogICAgICAgIDM2MjQ3NDE4NTAsCiAgICAgICAgMjkzNjY3NTE0OCwKICAgICAgICA5MDYxODU0NjIsCiAgICAgICAgMTA5MDgxMjUxMiwKICAgICAgICAzNzQ3NjcyMDAzLAogICAgICAgIDI4MjUzNzk2NjksCiAgICAgICAgODI5MzI5MTM1LAogICAgICAgIDExODEzMzUxNjEsCiAgICAgICAgMzQxMjE3NzgwNCwKICAgICAgICAzMTYwODM0ODQyLAogICAgICAgIDYyODA4NTQwOCwKICAgICAgICAxMzgyNjA1MzY2LAogICAgICAgIDM0MjMzNjkxMDksCiAgICAgICAgMzEzODA3ODQ2NywKICAgICAgICA1NzA1NjIyMzMsCiAgICAgICAgMTQyNjQwMDgxNSwKICAgICAgICAzMzE3MzE2NTQyLAogICAgICAgIDI5OTg3MzM2MDgsCiAgICAgICAgNzMzMjM5OTU0LAogICAgICAgIDE1NTUyNjE5NTYsCiAgICAgICAgMzI2ODkzNTU5MSwKICAgICAgICAzMDUwMzYwNjI1LAogICAgICAgIDc1MjQ1OTQwMywKICAgICAgICAxNTQxMzIwMjIxLAogICAgICAgIDI2MDcwNzE5MjAsCiAgICAgICAgMzk2NTk3MzAzMCwKICAgICAgICAxOTY5OTIyOTcyLAogICAgICAgIDQwNzM1NDk4LAogICAgICAgIDI2MTc4MzcyMjUsCiAgICAgICAgMzk0MzU3NzE1MSwKICAgICAgICAxOTEzMDg3ODc3LAogICAgICAgIDgzOTA4MzcxLAogICAgICAgIDI1MTIzNDE2MzQsCiAgICAgICAgMzgwMzc0MDY5MiwKICAgICAgICAyMDc1MjA4NjIyLAogICAgICAgIDIxMzI2MTExMiwKICAgICAgICAyNDYzMjcyNjAzLAogICAgICAgIDM4NTU5OTAyODUsCiAgICAgICAgMjA5NDg1NDA3MSwKICAgICAgICAxOTg5NTg4ODEsCiAgICAgICAgMjI2MjAyOTAxMiwKICAgICAgICA0MDU3MjYwNjEwLAogICAgICAgIDE3NTkzNTk5OTIsCiAgICAgICAgNTM0NDE0MTkwLAogICAgICAgIDIxNzY3MTg1NDEsCiAgICAgICAgNDEzOTMyOTExNSwKICAgICAgICAxODczODM2MDAxLAogICAgICAgIDQxNDY2NDU2NywKICAgICAgICAyMjgyMjQ4OTM0LAogICAgICAgIDQyNzkyMDAzNjgsCiAgICAgICAgMTcxMTY4NDU1NCwKICAgICAgICAyODUyODExMTYsCiAgICAgICAgMjQwNTgwMTcyNywKICAgICAgICA0MTY3MjE2NzQ1LAogICAgICAgIDE2MzQ0Njc3OTUsCiAgICAgICAgMzc2MjI5NzAxLAogICAgICAgIDI2ODUwNjc4OTYsCiAgICAgICAgMzYwODAwNzQwNiwKICAgICAgICAxMzA4OTE4NjEyLAogICAgICAgIDk1NjU0MzkzOCwKICAgICAgICAyODA4NTU1MTA1LAogICAgICAgIDM0OTU5NTgyNjMsCiAgICAgICAgMTIzMTYzNjMwMSwKICAgICAgICAxMDQ3NDI3MDM1LAogICAgICAgIDI5MzI5NTk4MTgsCiAgICAgICAgMzY1NDcwMzgzNiwKICAgICAgICAxMDg4MzU5MjcwLAogICAgICAgIDkzNjkxOGUzLAogICAgICAgIDI4NDc3MTQ4OTksCiAgICAgICAgMzczNjgzNzgyOSwKICAgICAgICAxMjAyOTAwODYzLAogICAgICAgIDgxNzIzMzg5NywKICAgICAgICAzMTgzMzQyMTA4LAogICAgICAgIDM0MDEyMzcxMzAsCiAgICAgICAgMTQwNDI3NzU1MiwKICAgICAgICA2MTU4MTgxNTAsCiAgICAgICAgMzEzNDIwNzQ5MywKICAgICAgICA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GJ1ZmZlciwgbnVtYmVyLCBvciBzdHJpbmcsIHJlY2VpdmVkICIgKyB0eXBlb2YgaW5wdXQpOwogICAgICAgIH0KICAgICAgfQogICAgICBmdW5jdGlvbiBidWZmZXJpemVJbnQobnVtKSB7CiAgICAgICAgdmFyIHRtcCA9IGVuc3VyZUJ1ZmZlcig0KTsKICAgICAgICB0bXAud3JpdGVJbnQzMkJFKG51bSwgMCk7CiAgICAgICAgcmV0dXJuIHRtcDsKICAgICAgfQogICAgICBmdW5jdGlvbiBfY3JjMzIoYnVmLCBwcmV2aW91cykgewogICAgICAgIGJ1ZiA9IGVuc3VyZUJ1ZmZlcihidWYpOwogICAgICAgIGlmIChCdWZmZXI4LmlzQnVmZmVyKHByZXZpb3VzKSkgewogICAgICAgICAgcHJldmlvdXMgPSBwcmV2aW91cy5yZWFkVUludDMyQkUoMCk7CiAgICAgICAgfQogICAgICAgIHZhciBjcmMgPSB+fnByZXZpb3VzIF4gLTE7CiAgICAgICAgZm9yICh2YXIgbiA9IDA7IG4gPCBidWYubGVuZ3RoOyBuKyspIHsKICAgICAgICAgIGNyYyA9IENSQ19UQUJMRVsoY3JjIF4gYnVmW25dKSAmIDI1NV0gXiBjcmMgPj4+IDg7CiAgICAgICAgfQogICAgICAgIHJldHVybiBjcmMgXiAtMTsKICAgICAgfQogICAgICBmdW5jdGlvbiBjcmMzMjIoKSB7CiAgICAgICAgcmV0dXJuIGJ1ZmZlcml6ZUludChfY3JjMzIuYXBwbHkobnVsbCwgYXJndW1lbnRzKSk7CiAgICAgIH0KICAgICAgY3JjMzIyLnNpZ25lZCA9IGZ1bmN0aW9uKCkgewogICAgICAgIHJldHVybiBfY3JjMzIuYXBwbHkobnVsbCwgYXJndW1lbnRzKTsKICAgICAgfTsKICAgICAgY3JjMzIyLnVuc2lnbmVkID0gZnVuY3Rpb24oKSB7CiAgICAgICAgcmV0dXJuIF9jcmMzMi5hcHBseShudWxsLCBhcmd1bWVudHMpID4+PiAwOwogICAgICB9Owog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HJvdG90eXBlLCBwcm90b1Byb3BzKTsKICAgICAgICBpZiAoc3RhdGljUHJvcHMpCiAgICAgICAgICBfZGVmaW5lUHJvcGVydGllcyhDb25zdHJ1Y3Rvciwgc3RhdGljUHJvcHMpOwogICAgICAgIE9iamVjdC5kZWZpbmVQcm9wZXJ0eShDb25zdHJ1Y3RvciwgInByb3RvdHlwZSIsIHsKICAgICAgICAgIHdyaXRhYmxlOiBmYWxzZQogICAgICAgIH0pOwogICAgICAgIHJldHVybiBDb25zdHJ1Y3RvcjsKICAgICAgfQogICAgICBmdW5jdGlvbiBfaW5oZXJpdHMoc3ViQ2xhc3MsIHN1cGVyQ2xhc3MpIHsKICAgICAgICBpZiAodHlwZW9mIHN1cGVyQ2xhc3MgIT09ICJmdW5jdGlvbiIgJiYgc3VwZXJDbGFzcyAhPT0gbnVsbCkgewogICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcigiU3VwZXIgZXhwcmVzc2lvbiBtdXN0IGVpdGhlciBiZSBudWxsIG9yIGEgZnVuY3Rpb24iKTsKICAgICAgICB9CiAgICAgICAgc3ViQ2xhc3MucHJvdG90eXBlID0gT2JqZWN0LmNyZWF0ZShzdXBlckNsYXNzICYmIHN1cGVyQ2xhc3MucHJvdG90eXBlLCB7CiAgICAgICAgICBjb25zdHJ1Y3RvcjogewogICAgICAgICAgICB2YWx1ZTogc3ViQ2xhc3MsCiAgICAgICAgICAgIHdyaXRhYmxlOiB0cnVlLAogICAgICAgICAgICBjb25maWd1cmFibGU6IHRydWUKICAgICAgICAgIH0KICAgICAgICB9KTsKICAgICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkoc3ViQ2xhc3MsICJwcm90b3R5cGUiLCB7CiAgICAgICAgICB3cml0YWJsZTogZmFsc2UKICAgICAgICB9KTsKICAgICAgICBpZiAoc3VwZXJDbGFzcykKICAgICAgICAgIF9zZXRQcm90b3R5cGVPZihzdWJDbGFzcywgc3VwZXJDbGFzcyk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gX2dldFByb3RvdHlwZU9mKG8pIHsKICAgICAgICBfZ2V0UHJvdG90eXBlT2YgPSBPYmplY3Quc2V0UHJvdG90eXBlT2YgPyBPYmplY3QuZ2V0UHJvdG90eXBlT2YuYmluZCgpIDogZnVuY3Rpb24gX2dldFByb3RvdHlwZU9mMihvMikgewogICAgICAgICAgcmV0dXJuIG8yLl9fcHJvdG9fXyB8fCBPYmplY3QuZ2V0UHJvdG90eXBlT2YobzIpOwogICAgICAgIH07CiAgICAgICAgcmV0dXJuIF9nZXRQcm90b3R5cGVPZihvKTsKICAgICAgfQogICAgICBmdW5jdGlvbiBfc2V0UHJvdG90eXBlT2YobywgcCkgewogICAgICAgIF9zZXRQcm90b3R5cGVPZiA9IE9iamVjdC5zZXRQcm90b3R5cGVPZiA/IE9iamVjdC5zZXRQcm90b3R5cGVPZi5iaW5kKCkgOiBmdW5jdGlvbiBfc2V0UHJvdG90eXBlT2YyKG8yLCBwMikgewogICAgICAgICAgbzIuX19wcm90b19fID0gcDI7CiAgICAgICAgICByZXR1cm4gbzI7CiAgICAgICAgfTsKICAgICAgICByZXR1cm4gX3NldFByb3RvdHlwZU9mKG8sIHApOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIF9pc05hdGl2ZVJlZmxlY3RDb25zdHJ1Y3QoKSB7CiAgICAgICAgaWYgKHR5cGVvZiBSZWZsZWN0ID09PSAidW5kZWZpbmVkIiB8fCAhUmVmbGVjdC5jb25zdHJ1Y3QpCiAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgaWYgKFJlZmxlY3QuY29uc3RydWN0LnNoYW0pCiAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgaWYgKHR5cGVvZiBQcm94eSA9PT0gImZ1bmN0aW9uIikKICAgICAgICAgIHJldHVybiB0cnVlOwogICAgICAgIHRyeSB7CiAgICAgICAgICBCb29sZWFuLnByb3RvdHlwZS52YWx1ZU9mLmNhbGwoUmVmbGVjdC5jb25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9jcmVhdGVTdXBlckludGVybmFsKCkgewogICAgICAgICAgdmFyIFN1cGVyID0gX2dldFByb3RvdHlwZU9mKERlcml2ZWQpLCByZXN1bHQ7CiAgICAgICAgICBpZiAoaGFzTmF0aXZlUmVmbGVjdENvbnN0cnVjdCkgewogICAgICAgICAgICB2YXIgTmV3VGFyZ2V0ID0gX2dldFByb3RvdHlwZU9mKHRoaXMpLmNvbnN0cnVjdG9yOwogICAgICAgICAgICByZXN1bHQgPSBSZWZsZWN0LmNvbnN0cnVjdChTdXBlciwgYXJndW1lbnRzLCBOZXdUYXJnZXQpOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcmVzdWx0ID0gU3VwZXIuYXBwbHkodGhpcywgYXJndW1lbnRzKTsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBfcG9zc2libGVDb25zdHJ1Y3RvclJldHVybih0aGlzLCByZXN1bHQpOwogICAgICAgIH07CiAgICAgIH0KICAgICAgZnVuY3Rpb24gX3N1cGVyUHJvcEJhc2Uob2JqZWN0LCBwcm9wZXJ0eSkgewogICAgICAgIHdoaWxlICghT2JqZWN0LnByb3RvdHlwZS5oYXNPd25Qcm9wZXJ0eS5jYWxsKG9iamVjdCwgcHJvcGVydHkpKSB7CiAgICAgICAgICBvYmplY3QgPSBfZ2V0UHJvdG90eXBlT2Yob2JqZWN0KTsKICAgICAgICAgIGlmIChvYmplY3QgPT09IG51bGwpCiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIH0KICAgICAgICByZXR1cm4gb2JqZWN0OwogICAgICB9CiAgICAgIGZ1bmN0aW9uIF9nZXQoKSB7CiAgICAgICAgaWYgKHR5cGVvZiBSZWZsZWN0ICE9PSAidW5kZWZpbmVkIiAmJiBSZWZsZWN0LmdldCkgewogICAgICAgICAgX2dldCA9IFJlZmxlY3QuZ2V0LmJpbmQoKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgX2dldCA9IGZ1bmN0aW9uIF9nZXQyKHRhcmdldCwgcHJvcGVydHksIHJlY2VpdmVyKSB7CiAgICAgICAgICAgIHZhciBiYXNlID0gX3N1cGVyUHJvcEJhc2UodGFyZ2V0LCBwcm9wZXJ0eSk7CiAgICAgICAgICAgIGlmICghYmFzZSkKICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgIHZhciBkZXNjID0gT2JqZWN0LmdldE93blByb3BlcnR5RGVzY3JpcHRvcihiYXNlLCBwcm9wZXJ0eSk7CiAgICAgICAgICAgIGlmIChkZXNjLmdldCkgewogICAgICAgICAgICAgIHJldHVybiBkZXNjLmdldC5jYWxsKGFyZ3VtZW50cy5sZW5ndGggPCAzID8gdGFyZ2V0IDogcmVjZWl2ZXIpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHJldHVybiBkZXNjLnZhbHVlOwogICAgICAgICAgfTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIF9nZXQuYXBwbHkodGhpcywgYXJndW1lbnRzKTsKICAgICAgfQogICAgICB2YXIgRW1pdHRlciA9IC8qIEBfX1BVUkVfXyAqLyBmdW5jdGlvbigpIHsKICAgICAgICBmdW5jdGlvbiBFbWl0dGVyMigpIHsKICAgICAgICAgIF9jbGFzc0NhbGxDaGVjayh0aGlzLCBFbWl0dGVyMik7CiAgICAgICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkodGhpcywgImxpc3RlbmVycyIsIHsKICAgICAgICAgICAgdmFsdWU6IHt9LAogICAgICAgICAgICB3cml0YWJsZTogdHJ1ZSwKICAgICAgICAgICAgY29uZmlndXJhYmxlOiB0cnVlCiAgICAgICAgICB9KTsKICAgICAgICB9CiAgICAgICAgX2NyZWF0ZUNsYXNzKEVtaXR0ZXIyLCBbewogICAgICAgICAga2V5OiAiYWRkRXZlbnRMaXN0ZW5lciIsCiAgICAgICAgICB2YWx1ZTogZnVuY3Rpb24gYWRkRXZlbnRMaXN0ZW5lcih0eXBlLCBjYWxsYmFjaywgb3B0aW9ucykgewogICAgICAgICAgICBpZiAoISh0eXBlIGluIHRoaXMubGlzdGVuZXJzKSkgewogICAgICAgICAgICAgIHRoaXMubGlzdGVuZXJzW3R5cGVdID0gW107CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdGhpcy5saXN0ZW5lcnNbdHlwZV0ucHVzaCh7CiAgICAgICAgICAgICAgY2FsbGJhY2ssCiAgICAgICAgICAgICAgb3B0aW9ucwogICAgICAgICAgICB9KTsKICAgICAgICAgIH0KICAgICAgICB9LCB7CiAgICAgICAgICBrZXk6ICJyZW1vdmVFdmVudExpc3RlbmVyIiwKICAgICAgICAgIHZhbHVlOiBmdW5jdGlvbiByZW1vdmVFdmVudExpc3RlbmVyKHR5cGUsIGNhbGxiYWNrKSB7CiAgICAgICAgICAgIGlmICghKHR5cGUgaW4gdGhpcy5saXN0ZW5lcnMpKSB7CiAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHZhciBzdGFjayA9IHRoaXMubGlzdGVuZXJzW3R5cGVdOwogICAgICAgICAgICBmb3IgKHZhciBpID0gMCwgbCA9IHN0YWNrLmxlbmd0aDsgaSA8IGw7IGkrKykgewogICAgICAgICAgICAgIGlmIChzdGFja1tpXS5jYWxsYmFjayA9PT0gY2FsbGJhY2spIHsKICAgICAgICAgICAgICAgIHN0YWNrLnNwbGljZShpLCAxKTsKICAgICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9LCB7CiAgICAgICAgICBrZXk6ICJkaXNwYXRjaEV2ZW50IiwKICAgICAgICAgIHZhbHVlOiBmdW5jdGlvbiBkaXNwYXRjaEV2ZW50KGV2ZW50KSB7CiAgICAgICAgICAgIGlmICghKGV2ZW50LnR5cGUgaW4gdGhpcy5saXN0ZW5lcnMpKSB7CiAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHZhciBzdGFjayA9IHRoaXMubGlzdGVuZXJzW2V2ZW50LnR5cGVdOwogICAgICAgICAgICB2YXIgc3RhY2tUb0NhbGwgPSBzdGFjay5zbGljZSgpOwogICAgICAgICAgICBmb3IgKHZhciBpID0gMCwgbCA9IHN0YWNrVG9DYWxsLmxlbmd0aDsgaSA8IGw7IGkrKykgewogICAgICAgICAgICAgIHZhciBsaXN0ZW5lciA9IHN0YWNrVG9DYWxsW2ldOwogICAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgICBsaXN0ZW5lci5jYWxsYmFjay5jYWxsKHRoaXMsIGV2ZW50KTsKICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7CiAgICAgICAgICAgICAgICBQcm9taXNlLnJlc29sdmUoKS50aGVuKGZ1bmN0aW9uKCkgewogICAgICAgICAgICAgICAgICB0aHJvdyBlOwogICAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGlmIChsaXN0ZW5lci5vcHRpb25zICYmIGxpc3RlbmVyLm9wdGlvbnMub25jZSkgewogICAgICAgICAgICAgICAgdGhpcy5yZW1vdmVFdmVudExpc3RlbmVyKGV2ZW50LnR5cGUsIGxpc3RlbmVyLmNhbGxiYWNrKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgcmV0dXJuICFldmVudC5kZWZhdWx0UHJldmVudGVkOwogICAgICAgICAgfQogICAgICAgIH1dKTsKICAgICAgICByZXR1cm4gRW1pdHRlcjI7CiAgICAgIH0oKTsKICAgICAgdmFyIEFib3J0U2lnbmFsID0gLyogQF9fUFVSRV9fICovIGZ1bmN0aW9uKF9FbWl0dGVyKSB7CiAgICAgICAgX2luaGVyaXRzKEFib3J0U2lnbmFsMiwgX0VtaXR0ZXIpOwogICAgICAgIHZhciBfc3VwZXIgPSBfY3JlYXRlU3VwZXIoQWJvcnRTaWduYWwyKTsKICAgICAgICBmdW5jdGlvbiBBYm9ydFNpZ25hbDIoKSB7CiAgICAgICAgICB2YXIgX3RoaXM7CiAgICAgICAgICBfY2xhc3NDYWxsQ2hlY2sodGhpcywgQWJvcnRTaWduYWwyKTsKICAgICAgICAgIF90aGlzID0gX3N1cGVyLmNhbGwodGhpcyk7CiAgICAgICAgICBpZiAoIV90aGlzLmxpc3RlbmVycykgewogICAgICAgICAgICBFbWl0dGVyLmNhbGwoX2Fzc2VydFRoaXNJbml0aWFsaXplZChfdGhpcykpOwogICAgICAgICAgfQogICAgICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KF9hc3NlcnRUaGlzSW5pdGlhbGl6ZWQoX3RoaXMpLCAiYWJvcnRlZCIsIHsKICAgICAgICAgICAgdmFsdWU6IGZhbHNlLAogICAgICAgICAgICB3cml0YWJsZTogdHJ1ZSwKICAgICAgICAgICAgY29uZmlndXJhYmxlOiB0cnVlCiAgICAgICAgICB9KTsKICAgICAgICAgIE9iamVjdC5kZWZpbmVQcm9wZXJ0eShfYXNzZXJ0VGhpc0luaXRpYWxpemVkKF90aGlzKSwgIm9uYWJvcnQiLCB7CiAgICAgICAgICAgIHZhbHVlOiBudWxsLAogICAgICAgICAgICB3cml0YWJsZTogdHJ1ZSwKICAgICAgICAgICAgY29uZmlndXJhYmxlOiB0cnVlCiAgICAgICAgICB9KTsKICAgICAgICAgIE9iamVjdC5kZWZpbmVQcm9wZXJ0eShfYXNzZXJ0VGhpc0luaXRpYWxpemVkKF90aGlzKSwgInJlYXNvbiIsIHsKICAgICAgICAgICAgdmFsdWU6IHZvaWQgMCwKICAgICAgICAgICAgd3JpdGFibGU6IHRydWUsCiAgICAgICAgICAgIGNvbmZpZ3VyYWJsZTogdHJ1ZQogICAgICAgICAgfSk7CiAgICAgICAgICByZXR1cm4gX3RoaXM7CiAgICAgICAgfQogICAgICAgIF9jcmVhdGVDbGFzcyhBYm9ydFNpZ25hbDIsIFt7CiAgICAgICAgICBrZXk6ICJ0b1N0cmluZyIsCiAgICAgICAgICB2YWx1ZTogZnVuY3Rpb24gdG9TdHJpbmcoKSB7CiAgICAgICAgICAgIHJldHVybiAiW29iamVjdCBBYm9ydFNpZ25hbF0iOwogICAgICAgICAgfQogICAgICAgIH0sIHsKICAgICAgICAgIGtleTogImRpc3BhdGNoRXZlbnQiLAogICAgICAgICAgdmFsdWU6IGZ1bmN0aW9uIGRpc3BhdGNoRXZlbnQoZXZlbnQpIHsKICAgICAgICAgICAgaWYgKGV2ZW50LnR5cGUgPT09ICJhYm9ydCIpIHsKICAgICAgICAgICAgICB0aGlzLmFib3J0ZWQgPSB0cnVlOwogICAgICAgICAgICAgIGlmICh0eXBlb2YgdGhpcy5vbmFib3J0ID09PSAiZnVuY3Rpb24iKSB7CiAgICAgICAgICAgICAgICB0aGlzLm9uYWJvcnQuY2FsbCh0aGlzLCBldmVudCk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIF9nZXQoX2dldFByb3RvdHlwZU9mKEFib3J0U2lnbmFsMi5wcm90b3R5cGUpLCAiZGlzcGF0Y2hFdmVudCIsIHRoaXMpLmNhbGwodGhpcywgZXZlbnQpOwogICAgICAgICAgfQogICAgICAgIH1dKTsKICAgICAgICByZXR1cm4gQWJvcnRTaWduYWwyOwogICAgICB9KEVtaXR0ZXIpOwogICAgICB2YXIgQWJvcnRDb250cm9sbGVyID0gLyogQF9fUFVSRV9fICovIGZ1bmN0aW9uKCkgewogICAgICAgIGZ1bmN0aW9uIEFib3J0Q29udHJvbGxlcjIoKSB7CiAgICAgICAgICBfY2xhc3NDYWxsQ2hlY2sodGhpcywgQWJvcnRDb250cm9sbGVyMik7CiAgICAgICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkodGhpcywgInNpZ25hbCIsIHsKICAgICAgICAgICAgdmFsdWU6IG5ldyBBYm9ydFNpZ25hbCgpLAogICAgICAgICAgICB3cml0YWJsZTogdHJ1ZSwKICAgICAgICAgICAgY29uZmlndXJhYmxlOiB0cnVlCiAgICAgICAgICB9KTsKICAgICAgICB9CiAgICAgICAgX2NyZWF0ZUNsYXNzKEFib3J0Q29udHJvbGxlcjIsIFt7CiAgICAgICAgICBrZXk6ICJhYm9ydCIsCiAgICAgICAgICB2YWx1ZTogZnVuY3Rpb24gYWJvcnQocmVhc29uKSB7CiAgICAgICAgICAgIHZhciBldmVudDsKICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICBldmVudCA9IG5ldyBFdmVudCgiYWJvcnQiKTsKICAgICAgICAgICAgfSBjYXRjaCAoZSkgewogICAgICAgICAgICAgIGlmICh0eXBlb2YgZG9jdW1lbnQgIT09ICJ1bmRlZmluZWQiKSB7CiAgICAgICAgICAgICAgICBpZiAoIWRvY3VtZW50LmNyZWF0ZUV2ZW50KSB7CiAgICAgICAgICAgICAgICAgIGV2ZW50ID0gZG9jdW1lbnQuY3JlYXRlRXZlbnRPYmplY3QoKTsKICAgICAgICAgICAgICAgICAgZXZlbnQudHlwZSA9ICJhYm9ydCI7CiAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICBldmVudCA9IGRvY3VtZW50LmNyZWF0ZUV2ZW50KCJFdmVudCIpOwogICAgICAgICAgICAgICAgICBldmVudC5pbml0RXZlbnQoImFib3J0IiwgZmFsc2UsIGZhbHNlKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgZXZlbnQgPSB7CiAgICAgICAgICAgICAgICAgIHR5cGU6ICJhYm9ydCIsCiAgICAgICAgICAgICAgICAgIGJ1YmJsZXM6IGZhbHNlLAogICAgICAgICAgICAgICAgICBjYW5jZWxhYmxlOiBmYWxzZQogICAgICAgICAgICAgICAgfTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdmFyIHNpZ25hbFJlYXNvbiA9IHJlYXNvbjsKICAgICAgICAgICAgaWYgKHNpZ25hbFJlYXNvbiA9PT0gdm9pZCAwKSB7CiAgICAgICAgICAgICAgaWYgKHR5cGVvZiBkb2N1bWVudCA9PT0gInVuZGVmaW5lZCIpIHsKICAgICAgICAgICAgICAgIHNpZ25hbFJlYXNvbiA9IG5ldyBFcnJvcigiVGhpcyBvcGVyYXRpb24gd2FzIGFib3J0ZWQiKTsKICAgICAgICAgICAgICAgIHNpZ25hbFJlYXNvbi5uYW1lID0gIkFib3J0RXJyb3IiOwogICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgICAgICBzaWduYWxSZWFzb24gPSBuZXcgRE9NRXhjZXB0aW9uKCJzaWduYWwgaXMgYWJvcnRlZCB3aXRob3V0IHJlYXNvbiIpOwogICAgICAgICAgICAgICAgfSBjYXRjaCAoZXJyKSB7CiAgICAgICAgICAgICAgICAgIHNpZ25hbFJlYXNvbiA9IG5ldyBFcnJvcigiVGhpcyBvcGVyYXRpb24gd2FzIGFib3J0ZWQiKTsKICAgICAgICAgICAgICAgICAgc2lnbmFsUmVhc29uLm5hbWUgPSAiQWJvcnRFcnJvciI7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIHRoaXMuc2lnbmFsLnJlYXNvbiA9IHNpZ25hbFJlYXNvbjsKICAgICAgICAgICAgdGhpcy5zaWduYWwuZGlzcGF0Y2hFdmVudChldmVudCk7CiAgICAgICAgICB9CiAgICAgICAgfSwgewogICAgICAgICAga2V5OiAidG9TdHJpbmciLAogICAgICAgICAgdmFsdWU6IGZ1bmN0aW9uIHRvU3RyaW5nKCkgewogICAgICAgICAgICByZXR1cm4gIltvYmplY3QgQWJvcnRDb250cm9sbGVyXSI7CiAgICAgICAgICB9CiAgICAgICAgfV0pOwogICAgICAgIHJldHVybiBBYm9ydENvbnRyb2xsZXIyOwogICAgICB9KCk7CiAgICAgIGlmICh0eXBlb2YgU3ltYm9sICE9PSAidW5kZWZpbmVkIiAmJiBTeW1ib2wudG9TdHJpbmdUYWcpIHsKICAgICAgICBBYm9ydENvbnRyb2xsZXIucHJvdG90eXBlW1N5bWJvbC50b1N0cmlu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B2YXIgc2lnbmFsOwogICAgICAgICAgICBpZiAoaW5pdDIgJiYgaW5pdDIuc2lnbmFsKSB7CiAgICAgICAgICAgICAgc2lnbmFsID0gaW5pdDIuc2lnbmFsOwogICAgICAgICAgICAgIGRlbGV0ZSBpbml0Mi5zaWduYWw7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdmFyIHJlcXVlc3QgPSBuZXcgTmF0aXZlUmVxdWVzdChpbnB1dCwgaW5pdDIpOwogICAgICAgICAgICBpZiAoc2lnbmFsKSB7CiAgICAgICAgICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KHJlcXVlc3QsICJzaWduYWwiLCB7CiAgICAgICAgICAgICAgICB3cml0YWJsZTogZmFsc2UsCiAgICAgICAgICAgICAgICBlbnVtZXJhYmxlOiBmYWxzZSwKICAgICAgICAgICAgICAgIGNvbmZpZ3VyYWJsZTogdHJ1ZSwKICAgICAgICAgICAgICAgIHZhbHVlOiBzaWduYWwKICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAgfQogICAgICAgICAgICByZXR1cm4gcmVxdWVzdDsKICAgICAgICAgIH07CiAgICAgICAgICBSZXF1ZXN0LnByb3RvdHlwZSA9IE5hdGl2ZVJlcXVlc3QucHJvdG90eXBlOwogICAgICAgIH0KICAgICAgICB2YXIgcmVhbEZldGNoID0gZmV0Y2gyOwogICAgICAgIHZhciBhYm9ydGFibGVGZXRjaCA9IGZ1bmN0aW9uIGFib3J0YWJsZUZldGNoMihpbnB1dCwgaW5pdDIpIHsKICAgICAgICAgIHZhciBzaWduYWwgPSBSZXF1ZXN0ICYmIFJlcXVlc3QucHJvdG90eXBlLmlzUHJvdG90eXBlT2YoaW5wdXQpID8gaW5wdXQuc2lnbmFsIDogaW5pdDIgPyBpbml0Mi5zaWduYWwgOiB2b2lkIDA7CiAgICAgICAgICBpZiAoc2lnbmFsKSB7CiAgICAgICAgICAgIHZhciBhYm9ydEVycm9yOwogICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgIGFib3J0RXJyb3IgPSBuZXcgRE9NRXhjZXB0aW9uKCJBYm9ydGVkIiwgIkFib3J0RXJyb3IiKTsKICAgICAgICAgICAgfSBjYXRjaCAoZXJyKSB7CiAgICAgICAgICAgICAgYWJvcnRFcnJvciA9IG5ldyBFcnJvcigiQWJvcnRlZCIpOwogICAgICAgICAgICAgIGFib3J0RXJyb3IubmFtZSA9ICJBYm9ydEVycm9yIjsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoc2lnbmFsLmFib3J0ZWQpIHsKICAgICAgICAgICAgICByZXR1cm4gUHJvbWlzZS5yZWplY3QoYWJvcnRFcnJvcik7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdmFyIGNhbmNlbGxhdGlvbiA9IG5ldyBQcm9taXNlKGZ1bmN0aW9uKF8sIHJlamVjdCkgewogICAgICAgICAgICAgIHNpZ25hbC5hZGRFdmVudExpc3RlbmVyKCJhYm9ydCIsIGZ1bmN0aW9uKCkgewogICAgICAgICAgICAgICAgcmV0dXJuIHJlamVjdChhYm9ydEVycm9yKTsKICAgICAgICAgICAgICB9LCB7CiAgICAgICAgICAgICAgICBvbmNlOiB0cnVlCiAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgIH0pOwogICAgICAgICAgICBpZiAoaW5pdDIgJiYgaW5pdDIuc2lnbmFsKSB7CiAgICAgICAgICAgICAgZGVsZXRlIGluaXQyLnNpZ25hbDsKICAgICAgICAgICAgfQogICAgICAgICAgICByZXR1cm4gUHJvbWlzZS5yYWNlKFtjYW5jZWxsYXRpb24sIHJlYWxGZXRjaChpbnB1dCwgaW5pdDIpXSk7CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gcmVhbEZldGNoKGlucHV0LCBpbml0Mik7CiAgICAgICAgfTsKICAgICAgICByZXR1cm4gewogICAgICAgICAgZmV0Y2g6IGFib3J0YWJsZUZldGNoLAogICAgICAgICAgUmVxdWVzdAogICAgICAgIH07CiAgICAgIH0KICAgICAgZXhwb3J0cy5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ICAgICAgICAgc2lnbmFsLmFkZEV2ZW50TGlzdGVuZXIoImFib3J0IiwgKCkgPT4gewogICAgICAgICAgICAgIHRoaXMuaGFuZGxlQWJvcnRlZChzaWduYWwpOwogICAgICAgICAgICB9KTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaGFuZGxlQWJvcnRlZChzaWduYWwpIHsKICAgICAgICAgIHRoaXMuc2lnbmFscy5kZWxldGUoc2lnbmFsKTsKICAgICAgICAgIGlmICh0aGlzLnNpZ25hbHMuc2l6ZSA9PT0gMCkgewogICAgICAgICAgICB0aGlzLmFib3J0Q29udHJvbGxlci5hYm9ydCgpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBnZXQgc2lnbmFsKCkgewogICAgICAgICAgcmV0dXJuIHRoaXMuYWJvcnRDb250cm9sbGVyLnNpZ25hbDsKICAgICAgICB9CiAgICAgICAgYWJvcnQoKSB7CiAgICAgICAgICB0aGlzLmFib3J0Q29udHJvbGxlci5hYm9ydCgpOwogICAgICAgIH0KICAgICAgfTsKICAgICAgZXhwb3J0cy5kZWZhdWx0ID0gQWdncmVnYXRlQWJvcnRDb250cm9sbGVyOwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vYWJvcnRhYmxlLXByb21pc2UtY2FjaGVAMS41LjAvbm9kZV9tb2R1bGVzL2Fib3J0YWJsZS1wcm9taXNlLWNhY2hlL2VzbS9BZ2dyZWdhdGVTdGF0dXNSZXBvcnRlci5qcwogIHZhciByZXF1aXJlX0FnZ3JlZ2F0ZVN0YXR1c1JlcG9ydGVyID0gX19jb21tb25KUyh7CiAgICAibm9kZV9tb2R1bGVzLy5wbnBtL2Fib3J0YWJsZS1wcm9taXNlLWNhY2hlQDEuNS4wL25vZGVfbW9kdWxlcy9hYm9ydGFibGUtcHJvbWlzZS1jYWNoZS9lc20vQWdncmVnYXRlU3RhdHVzUmVwb3J0ZXIuanMiKGV4cG9ydHMpIHsKICAgICAgaW5pdF9idWZm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BZ2dyZWdhdGVBYm9ydENvbnRyb2xsZXJfMS5kZWZhdWx0KCk7CiAgICAgICAgICBjb25zdCBzdGF0dXNSZXBvcnRlciA9IG5ldyBBZ2dyZWdhdGVTdGF0dXNSZXBvcnRlcl8xLmRlZmF1bHQoKTsKICAgICAgICAgIHN0YXR1c1JlcG9ydGVyLmFkZENhbGxiYWNrKHN0YXR1c0NhbGxiYWNrKTsKICAgICAgICAgIGNvbnN0IG5ld0VudHJ5ID0gewogICAgICAgICAgICBhYm9ydGVyLAogICAgICAgICAgICBwcm9taXNlOiB0aGlzLmZpbGxDYWxsYmFjayhkYXRhLCBhYm9ydGVyLnNpZ25hbCwgKG1lc3NhZ2UpID0+IHsKICAgICAgICAgICAgICBzdGF0dXNSZXBvcnRlci5jYWxsYmFjayhtZXNzYWdlKTsKICAgICAgICAgICAgfSksCiAgICAgICAgICAgIHNldHRsZWQ6IGZhbHNlLAogICAgICAgICAgICBzdGF0dXNSZXBvcnRlciwKICAgICAgICAgICAgZ2V0IGFib3J0ZWQoKSB7CiAgICAgICAgICAgICAgcmV0dXJuIHRoaXMuYWJvcnRlci5zaWduYWwuYWJvcnRlZDsKICAgICAgICAgICAgfQogICAgICAgICAgfTsKICAgICAgICAgIG5ld0VudHJ5LmFib3J0ZXIuYWRkU2lnbmFsKHNpZ25hbCk7CiAgICAgICAgICBuZXdFbnRyeS5hYm9ydGVyLnNpZ25hbC5hZGRFdmVudExpc3RlbmVyKCJhYm9ydCIsICgpID0+IHsKICAgICAgICAgICAgaWYgKCFuZXdFbnRyeS5zZXR0bGVkKSB7CiAgICAgICAgICAgICAgdGhpcy5ldmljdChrZXksIG5ld0VudHJ5KTsKICAgICAgICAgICAgfQogICAgICAgICAgfSk7CiAgICAgICAgICBuZXdFbnRyeS5wcm9taXNlLnRoZW4oKCkgPT4gewogICAgICAgICAgICBuZXdFbnRyeS5zZXR0bGVkID0gdHJ1ZTsKICAgICAgICAgIH0sICgpID0+IHsKICAgICAgICAgICAgbmV3RW50cnkuc2V0dGxlZCA9IHRydWU7CiAgICAgICAgICAgIHRoaXMuZXZpY3Qoa2V5LCBuZXdFbnRyeSk7CiAgICAgICAgICB9KS5jYXRjaCgoZSkgPT4gewogICAgICAgICAgICBjb25zb2xlLmVycm9yKGUpOwogICAgICAgICAgICB0aHJvdyBlOwogICAgICAgICAgfSk7CiAgICAgICAgICB0aGlzLmNhY2hlLnNldChrZXksIG5ld0VudHJ5KTsKICAgICAgICB9CiAgICAgICAgc3RhdGljIGNoZWNrU2luZ2xlUHJvbWlzZShwcm9taXNlLCBzaWduYWwpIHsKICAgICAgICAgIGZ1bmN0aW9uIGNoZWNrRm9yU2luZ2xlQWJvcnQoKSB7CiAgICAgICAgICAgIGlmIChzaWduYWwgJiYgc2lnbmFsLmFib3J0ZWQpIHsKICAgICAgICAgICAgICB0aHJvdyBPYmplY3QuYXNzaWduKG5ldyBFcnJvcigiYWJvcnRlZCIpLCB7IGNvZGU6ICJFUlJfQUJPUlRFRCIgfSk7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBwcm9taXNlLnRoZW4oKHJlc3VsdCkgPT4gewogICAgICAgICAgICBjaGVja0ZvclNpbmdsZUFib3J0KCk7CiAgICAgICAgICAgIHJldHVybiByZXN1bHQ7CiAgICAgICAgICB9LCAoZXJyb3IpID0+IHsKICAgICAgICAgICAgY2hlY2tGb3JTaW5nbGVBYm9ydCgpOwogICAgICAgICAgICB0aHJvdyBlcnJvcjsKICAgICAgICAgIH0pOwogICAgICAgIH0KICAgICAgICBoYXMoa2V5KSB7CiAgICAgICAgICByZXR1cm4gdGhpcy5jYWNoZS5oYXMoa2V5KTsKICAgICAgICB9CiAgICAgICAgZ2V0KGtleSwgZGF0YSwgc2lnbmFsLCBzdGF0dXNDYWxsYmFjaykgewogICAgICAgICAgaWYgKCFzaWduYWwgJiYgZGF0YSBpbnN0YW5jZW9mIGFib3J0Y29udHJvbGxlcl9wb255ZmlsbF8xLkFib3J0U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mdsZVByb21pc2UodGhpcy5jYWNoZS5nZXQoa2V5KS5wcm9taXNlLCBzaWduYWwpOwogICAgICAgIH0KICAgICAgICBkZWxldGUoa2V5KSB7CiAgICAgICAgICBjb25zdCBjYWNoZWRFbnRyeSA9IHRoaXMuY2FjaGUuZ2V0KGtleSk7CiAgICAgICAgICBpZiAoY2FjaGVkRW50cnkpIHsKICAgICAgICAgICAgaWYgKCFjYWNoZWRFbnRyeS5zZXR0bGVkKSB7CiAgICAgICAgICAgICAgY2FjaGVkRW50cnkuYWJvcnRlci5hYm9ydCgpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHRoaXMuY2FjaGUuZGVsZXRlKGtleSk7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGNsZWFyKCkgewogICAgICAgICAgY29uc3Qga2V5SXRlciA9IHRoaXMuY2FjaGUua2V5cygpOwogICAgICAgICAgbGV0IGRlbGV0ZUNvdW50ID0gMDsKICAgICAgICAgIGZvciAobGV0IHJlc3VsdCA9IGtleUl0ZXIubmV4dCgpOyAhcmVzdWx0LmRvbmU7IHJlc3VsdCA9IGtleUl0ZXIubmV4dCgpKSB7CiAgICAgICAgICAgIHRoaXMuZGVsZXRlKHJlc3VsdC52YWx1ZSk7CiAgICAgICAgICAgIGRlbGV0ZUNvdW50ICs9IDE7CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gZGVsZXRlQ291bnQ7CiAgICAgICAgfQogICAgICB9OwogICAgICBleHBvcnRzLmRlZmF1bHQgPSBBYm9ydGFibGVQcm9taXNlQ2FjaGUyOwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vYWJvcnRhYmxlLXByb21pc2UtY2FjaGVAMS41LjAvbm9kZV9tb2R1bGVzL2Fib3J0YWJsZS1wcm9taXNlLWNhY2hlL2VzbS9pbmRleC5qcwogIHZhciByZXF1aXJlX2VzbSA9IF9fY29tbW9uSlMoewogICAgIm5vZGVfbW9kdWxlcy8ucG5wbS9hYm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SkgewogICAgICAgICAgaWYgKCEob3B0aW9ucy5tYXhTaXplICYmIG9wdGlvbnMubWF4U2l6ZSA+IDApKSB7CiAgICAgICAgICAgIHRocm93IG5ldyBUeXBlRXJyb3IoImBtYXhTaXplYCBtdXN0IGJlIGEgbnVtYmVyIGdyZWF0ZXIgdGhhbiAwIik7CiAgICAgICAgICB9CiAgICAgICAgICB0aGlzLm1heFNpemUgPSBvcHRpb25zLm1heFNpemU7CiAgICAgICAgICB0aGlzLmNhY2hlID0gbmV3IE1hcCgpOwogICAgICAgICAgdGhpcy5vbGRDYWNoZSA9IG5ldyBNYXAoKTsKICAgICAgICAgIHRoaXMuX3NpemUgPSAwOwogICAgICAgIH0KICAgICAgICBfc2V0KGtleSwgdmFsdWUpIHsKICAgICAgICAgIHRoaXMuY2FjaGUuc2V0KGtleSwgdmFsdWUpOwogICAgICAgICAgdGhpcy5fc2l6ZSsrOwogICAgICAgICAgaWYgKHRoaXMuX3NpemUgPj0gdGhpcy5tYXhTaXplKSB7CiAgICAgICAgICAgIHRoaXMuX3NpemUgPSAwOwogICAgICAgICAgICB0aGlzLm9sZENhY2hlID0gdGhpcy5jYWNoZTsKICAgICAgICAgICAgdGhpcy5jYWNoZSA9IG5ldyBNYXAoKTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZ2V0KGtleSkgewogICAgICAgICAgaWYgKHRoaXMuY2FjaGUuaGFzKGtleSkpIHsKICAgICAgICAgICAgcmV0dXJuIHRoaXMuY2FjaGUuZ2V0KGtleSk7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAodGhpcy5vbGRDYWNoZS5oYXMoa2V5KSkgewogICAgICAgICAgICBjb25zdCB2YWx1ZSA9IHRoaXMub2xkQ2FjaGUuZ2V0KGtleSk7CiAgICAgICAgICAgIHRoaXMuX3NldChrZXksIHZhbHVlKTsKICAgICAgICAgICAgcmV0dXJuIHZhbHVlOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBzZXQoa2V5LCB2YWx1ZSkgewogICAgICAgICAgaWYgKHRoaXMuY2FjaGUuaGFzKGtleSkpIHsKICAgICAgICAgICAgdGhpcy5jYWNoZS5zZXQoa2V5LCB2YWx1ZSk7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICB0aGlzLl9zZXQoa2V5LCB2YWx1ZSk7CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gdGhpczsKICAgICAgICB9CiAgICAgICAgaGFzKGtleSkgewogICAgICAgICAgcmV0dXJuIHRoaXMuY2FjaGUuaGFzKGtleSkgfHwgdGhpcy5vbGRDYWNoZS5oYXMoa2V5KTsKICAgICAgICB9CiAgICAgICAgcGVlayhrZXkpIHsKICAgICAgICAgIGlmICh0aGlzLmNhY2hlLmhhcyhrZXkpKSB7CiAgICAgICAgICAgIHJldHVybiB0aGlzLmNhY2hlLmdldChrZXkpOwogICAgICAgICAgfQogICAgICAgICAgaWYgKHRoaXMub2xkQ2FjaGUuaGFzKGtleSkpIHsKICAgICAgICAgICAgcmV0dXJuIHRoaXMub2xkQ2FjaGUuZ2V0KGtleSk7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGRlbGV0ZShrZXkpIHsKICAgICAgICAgIGNvbnN0IGRlbGV0ZWQgPSB0aGlzLmNhY2hlLmRlbGV0ZShrZXkpOwogICAgICAgICAgaWYgKGRlbGV0ZWQpIHsKICAgICAgICAgICAgdGhpcy5fc2l6ZS0tOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIHRoaXMub2xkQ2FjaGUuZGVsZXRlKGtleSkgfHwgZGVsZXRlZDsKICAgICAgICB9CiAgICAgICAgY2xlYXIoKSB7CiAgICAgICAgICB0aGlzLmNhY2hlLmNsZWFyKCk7CiAgICAgICAgICB0aGlzLm9sZENhY2hlLmNsZWFyKCk7CiAgICAgICAgICB0aGlzLl9zaXplID0gMDsKICAgICAgICB9CiAgICAgICAgKmtleXMoKSB7CiAgICAgICAgICBmb3IgKGNvbnN0IFtrZXldIG9mIHRoaXMpIHsKICAgICAgICAgICAgeWllbGQga2V5OwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICAqdmFsdWVzKCkgewogICAgICAgICAgZm9yIChjb25zdCBbLCB2YWx1ZV0gb2YgdGhpcykgewogICAgICAgICAgICB5aWVsZCB2YWx1ZTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgKltTeW1ib2wuaXRlcmF0b3JdKCkgewogICAgICAgICAgZm9yIChjb25zdCBpdGVtIG9mIHRoaXMuY2FjaGUpIHsKICAgICAgICAgICAgeWllbGQgaXRlbTsKICAgICAgICAgIH0KICAgICAgICAgIGZvciAoY29uc3QgaXRlbSBvZiB0aGlzLm9sZENhY2hlKSB7CiAgICAgICAgICAgIGNvbnN0IFtrZXldID0gaXRlbTsKICAgICAgICAgICAgaWYgKCF0aGlzLmNhY2hlLmhhcyhrZXkpKSB7CiAgICAgICAgICAgICAgeWllbGQgaXRlbTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBnZXQgc2l6ZSgpIHsKICAgICAgICAgIGxldCBvbGRDYWNoZVNpemUgPSAwOwogICAgICAgICAgZm9yIChjb25zdCBrZXkgb2YgdGhpcy5vbGRDYWNoZS5rZXlzKCkpIHsKICAgICAgICAgICAgaWYgKCF0aGlzLmNhY2hlLmhhcyhrZXkpKSB7CiAgICAgICAgICAgICAgb2xkQ2FjaGVTaXplKys7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiB0aGlzLl9zaXplICsgb2xkQ2FjaGVTaXplOwogICAgICAgIH0KICAgICAgfTsKICAgICAgbW9kdWxlLmV4cG9ydHMgPSBRdWlja0xSVTM7CiAgICB9CiAgfSk7CgogIC8vIG5vZGVfbW9kdWxlcy8ucG5wbS9jcm9zcy1mZXRjaEAzLjEuOC9ub2RlX21vZHVsZXMvY3Jvc3MtZmV0Y2gvZGlzdC9icm93c2VyLXBvbHlmaWxsLmpzCiAgdmFyIHJlcXVpcmVfYnJvd3Nlcl9wb2x5ZmlsbCA9IF9fY29tbW9uSlMoewogICAgIm5vZGVfbW9kdWxlcy8ucG5wbS9jcm9zcy1mZXRjaEAzLjEuOC9ub2RlX21vZHVsZXMvY3Jvc3MtZmV0Y2gvZGlzdC9icm93c2VyLXBvbHlmaWxsLmpzIihleHBvcnRzKSB7CiAgICAgIGluaXRfYnVmZmVyX3NoaW0oKTsKICAgICAgKGZ1bmN0aW9uKHNlbGYyKSB7CiAgICAgICAgdmFyIGlycmVsZXZhbnQgPSBmdW5jdGlvbihleHBvcnRzMikgewogICAgICAgICAgdmFyIHN1cHBvcnQgPSB7CiAgICAgICAgICAgIHNlYXJjaFBhcmFtczogIlVSTFNlYXJjaFBhcmFtcyIgaW4gc2VsZjIsCiAgICAgICAgICAgIGl0ZXJhYmxlOiAiU3ltYm9sIiBpbiBzZWxmMiAmJiAiaXRlcmF0b3IiIGluIFN5bWJvbCwKICAgICAgICAgICAgYmxvYjogIkZpbGVSZWFkZXIiIGluIHNlbGYyICYmICJCbG9iIiBpbiBzZWxmMiAmJiBmdW5jdGlvbigpIHsKICAgICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgICAgbmV3IEJsb2IoKTsKICAgICAgICAgICAgICAgIHJldHVybiB0cnVlOwogICAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHsKICAgICAgICAgICAgICAgIHJldHVybiBmYWxzZTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0oKSwKICAgICAgICAgICAgZm9ybURhdGE6ICJGb3JtRGF0YSIgaW4gc2VsZjIsCiAgICAgICAgICAgIGFycmF5QnVmZmVyOiAiQXJyYXlCdWZmZXIiIGluIHNlbGYyCiAgICAgICAgICB9OwogICAgICAgICAgZnVuY3Rpb24gaXNEYXRhVmlldyhvYmopIHsKICAgICAgICAgICAgcmV0dXJuIG9iaiAmJiBEYXRhVmlldy5wcm90b3R5cGUuaXNQcm90b3R5cGVPZihvYmopOwogICAgICAgICAgfQogICAgICAgICAgaWYgKHN1cHBvcnQuYXJyYXlCdWZmZXIpIHsKICAgICAgICAgICAgdmFyIHZpZXdDbGFzc2VzID0gWwogICAgICAgICAgICAgICJbb2JqZWN0IEludDhBcnJheV0iLAogICAgICAgICAgICAgICJbb2JqZWN0IFVpbnQ4QXJyYXldIiwKICAgICAgICAgICAgICAiW29iamVjdCBVaW50OENsYW1wZWRBcnJheV0iLAogICAgICAgICAgICAgICJbb2JqZWN0IEludDE2QXJyYXldIiwKICAgICAgICAgICAgICAiW29iamVjdCBVaW50MTZBcnJheV0iLAogICAgICAgICAgICAgICJbb2JqZWN0IEludDMyQXJyYXldIiwKICAgICAgICAgICAgICAiW29iamVjdCBVaW50MzJBcnJheV0iLAogICAgICAgICAgICAgICJbb2JqZWN0IEZsb2F0MzJBcnJheV0iLAogICAgICAgICAgICAgICJbb2JqZWN0IEZsb2F0NjRBcnJheV0iCiAgICAgICAgICAgIF07CiAgICAgICAgICAgIHZhciBpc0FycmF5QnVmZmVyVmlldyA9IEFycmF5QnVmZmVyLmlzVmlldyB8fCBmdW5jdGlvbihvYmopIHsKICAgICAgICAgICAgICByZXR1cm4gb2JqICYmIHZpZXdDbGFzc2VzLmluZGV4T2YoT2JqZWN0LnByb3RvdHlwZS50b1N0cmluZy5jYWxsKG9iaikpID4gLTE7CiAgICAgICAgICAgIH07CiAgICAgICAgICB9CiAgICAgICAgICBmdW5jdGlvbiBub3JtYWxpemVOYW1lKG5hbWUpIHsKICAgICAgICAgICAgaWYgKHR5cGVvZiBuYW1lICE9PSAic3RyaW5nIikgewogICAgICAgICAgICAgIG5hbWUgPSBTdHJpbmcobmFtZSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKC9bXmEtejAtOVwtIyQlJicqKy5eX2B8fl0vaS50ZXN0KG5hbWUpKSB7CiAgICAgICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcigiSW52YWxpZCBjaGFyYWN0ZXIgaW4gaGVhZGVyIGZpZWxkIG5hbWUiKTsKICAgICAgICAgICAgfQogICAgICAgICAgICByZXR1cm4gbmFtZS50b0xvd2VyQ2FzZSgpOwogICAgICAgICAgfQogICAgICAgICAgZnVuY3Rpb24gbm9ybWFsaXplVmFsdWUodmFsdWUpIHsKICAgICAgICAgICAgaWYgKHR5cGVvZiB2YWx1ZSAhPT0gInN0cmluZyIpIHsKICAgICAgICAgICAgICB2YWx1ZSA9IFN0cmluZyh2YWx1ZSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgcmV0dXJuIHZhbHVlOwogICAgICAgICAgfQogICAgICAgICAgZnVuY3Rpb24gaXRlcmF0b3JGb3IoaXRlbXMpIHsKICAgICAgICAgICAgdmFyIGl0ZXJhdG9yID0gewogICAgICAgICAgICAgIG5leHQ6IGZ1bmN0aW9uKCkgewogICAgICAgICAgICAgICAgdmFyIHZhbHVlID0gaXRlbXMuc2hpZnQoKTsKICAgICAgICAgICAgICAgIHJldHVybiB7IGRvbmU6IHZhbHVlID09PSB2b2lkIDAsIHZhbHVlIH07CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9OwogICAgICAgICAgICBpZiAoc3VwcG9ydC5pdGVyYWJsZSkgewogICAgICAgICAgICAgIGl0ZXJhdG9yW1N5bWJvbC5pdGVyYXRvcl0gPSBmdW5jdGlvbigpIHsKICAgICAgICAgICAgICAgIHJldHVybiBpdGVyYXRvcjsKICAgICAgICAgICAgICB9OwogICAgICAgICAgICB9CiAgICAgICAgICAgIHJldHVybiBpdGVyYXRvcjsKICAgICAgICAgIH0KICAgICAgICAgIGZ1bmN0aW9uIEhlYWRlcnMoaGVhZGVycykgewogICAgICAgICAgICB0aGlzLm1hcCA9IHt9OwogICAgICAgICAgICBpZiAoaGVhZGVycyBpbnN0YW5jZW9mIEhlYWRlcnMpIHsKICAgICAgICAgICAgICBoZWFkZXJzLmZvckVhY2goZnVuY3Rpb24odmFsdWUsIG5hbWUpIHsKICAgICAgICAgICAgICAgIHRoaXMuYXBwZW5kKG5hbWUsIHZhbHVlKTsKICAgICAgICAgICAgICB9LCB0aGlzKTsKICAgICAgICAgICAgfSBlbHNlIGlmIChBcnJheS5pc0FycmF5KGhlYWRlcnMpKSB7CiAgICAgICAgICAgICAgaGVhZGVycy5mb3JFYWNoKGZ1bmN0aW9uKGhlYWRlcikgewogICAgICAgICAgICAgICAgdGhpcy5hcHBlbmQoaGVhZGVyWzBdLCBoZWFkZXJbMV0pOwogICAgICAgICAgICAgIH0sIHRoaXMpOwogICAgICAgICAgICB9IGVsc2UgaWYgKGhlYWRlcnMpIHsKICAgICAgICAgICAgICBPYmplY3QuZ2V0T3duUHJvcGVydHlOYW1lcyhoZWFkZXJzKS5mb3JFYWNoKGZ1bmN0aW9uKG5hbWUpIHsKICAgICAgICAgICAgICAgIHRoaXMuYXBwZW5kKG5hbWUsIGhlYWRlcnNbbmFtZV0pOwogICAgICAgICAgICAgIH0sIHRoaXMpOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBIZWFkZXJzLnByb3RvdHlwZS5hcHBlbmQgPSBmdW5jdGlvbihuYW1lLCB2YWx1ZSkgewogICAgICAgICAgICBuYW1lID0gbm9ybWFsaXplTmFtZShuYW1lKTsKICAgICAgICAgICAgdmFsdWUgPSBub3JtYWxpemVWYWx1ZSh2YWx1ZSk7CiAgICAgICAgICAgIHZhciBvbGRWYWx1ZSA9IHRoaXMubWFwW25hbWVdOwogICAgICAgICAgICB0aGlzLm1hcFtuYW1lXSA9IG9sZFZhbHVlID8gb2xkVmFsdWUgKyAiLCAiICsgdmFsdWUgOiB2YWx1ZTsKICAgICAgICAgIH07CiAgICAgICAgICBIZWFkZXJzLnByb3RvdHlwZVsiZGVsZXRlIl0gPSBmdW5jdGlvbihuYW1lKSB7CiAgICAgICAgICAgIGRlbGV0ZSB0aGlzLm1hcFtub3JtYWxpemVOYW1lKG5hbWUpXTsKICAgICAgICAgIH07CiAgICAgICAgICBIZWFkZXJzLnByb3RvdHlwZS5nZXQgPSBmdW5jdGlvbihuYW1lKSB7CiAgICAgICAgICAgIG5hbWUgPSBub3JtYWxpemVOYW1lKG5hbWUpOwogICAgICAgICAgICByZXR1cm4gdGhpcy5oYXMobmFtZSkgPyB0aGlzLm1hcFtuYW1lXSA6IG51bGw7CiAgICAgICAgICB9OwogICAgICAgICAgSGVhZGVycy5wcm90b3R5cGUuaGFzID0gZnVuY3Rpb24obmFtZSkgewogICAgICAgICAgICByZXR1cm4gdGhpcy5tYXAuaGFzT3duUHJvcGVydHkobm9ybWFsaXplTmFtZShuYW1lKSk7CiAgICAgICAgICB9OwogICAgICAgICAgSGVhZGVycy5wcm90b3R5cGUuc2V0ID0gZnVuY3Rpb24obmFtZSwgdmFsdWUpIHsKICAgICAgICAgICAgdGhpcy5tYXBbbm9ybWFsaXplTmFtZShuYW1lKV0gPSBub3JtYWxpemVWYWx1ZSh2YWx1ZSk7CiAgICAgICAgICB9OwogICAgICAgICAgSGVhZGVycy5wcm90b3R5cGUuZm9yRWFjaCA9IGZ1bmN0aW9uKGNhbGxiYWNrLCB0aGlzQXJnKSB7CiAgICAgICAgICAgIGZvciAodmFyIG5hbWUgaW4gdGhpcy5tYXApIHsKICAgICAgICAgICAgICBpZiAodGhpcy5tYXAuaGFzT3duUHJvcGVydHkobmFtZSkpIHsKICAgICAgICAgICAgICAgIGNhbGxiYWNrLmNhbGwodGhpc0FyZywgdGhpcy5tYXBbbmFtZV0sIG5hbWUsIHRoaXMpOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgfTsKICAgICAgICAgIEhlYWRlcnMucHJvdG90eXBlLmtleXMgPSBmdW5jdGlvbigpIHsKICAgICAgICAgICAgdmFyIGl0ZW1zID0gW107CiAgICAgICAgICAgIHRoaXMuZm9yRWFjaChmdW5jdGlvbih2YWx1ZSwgbmFtZSkgewogICAgICAgICAgICAgIGl0ZW1zLnB1c2gobmFtZSk7CiAgICAgICAgICAgIH0pOwogICAgICAgICAgICByZXR1cm4gaXRlcmF0b3JGb3IoaXRlbXMpOwogICAgICAgICAgfTsKICAgICAgICAgIEhlYWRlcnMucHJvdG90eXBlLnZhbHVlcyA9IGZ1bmN0aW9uKCkgewogICAgICAgICAgICB2YXIgaXRlbXMgPSBbXTsKICAgICAgICAgICAgdGhpcy5mb3JFYWNoKGZ1bmN0aW9uKHZhbHVlKSB7CiAgICAgICAgICAgICAgaXRlbXMucHVzaCh2YWx1ZSk7CiAgICAgICAgICAgIH0pOwogICAgICAgICAgICByZXR1cm4gaXRlcmF0b3JGb3IoaXRlbXMpOwogICAgICAgICAgfTsKICAgICAgICAgIEhlYWRlcnMucHJvdG90eXBlLmVudHJpZXMgPSBmdW5jdGlvbigpIHsKICAgICAgICAgICAgdmFyIGl0ZW1zID0gW107CiAgICAgICAgICAgIHRoaXMuZm9yRWFjaChmdW5jdGlvbih2YWx1ZSwgbmFtZSkgewogICAgICAgICAgICAgIGl0ZW1zLnB1c2goW25hbWUsIHZhbHVlXSk7CiAgICAgICAgICAgIH0pOwogICAgICAgICAgICByZXR1cm4gaXRlcmF0b3JGb3IoaXRlbXMpOwogICAgICAgICAgfTsKICAgICAgICAgIGlmIChzdXBwb3J0Lml0ZXJhYmxlKSB7CiAgICAgICAgICAgIEhlYWRlcnMucHJvdG90eXBlW1N5bWJvbC5pdGVyYXRvcl0gPSBIZWFkZXJzLnByb3RvdHlwZS5lbnRyaWVzOwogICAgICAgICAgfQogICAgICAgICAgZnVuY3Rpb24gY29uc3VtZWQoYm9keSkgewogICAgICAgICAgICBpZiAoYm9keS5ib2R5VXNlZCkgewogICAgICAgICAgICAgIHJldHVybiBQcm9taXNlLnJlamVjdChuZXcgVHlwZUVycm9yKCJBbHJlYWR5IHJlYWQiKSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgYm9keS5ib2R5VXNlZCA9IHRydWU7CiAgICAgICAgICB9CiAgICAgICAgICBmdW5jdGlvbiBmaWxlUmVhZGVyUmVhZHkocmVhZGVyKSB7CiAgICAgICAgICAgIHJldHVybiBuZXcgUHJvbWlzZShmdW5jdGlvbihyZXNvbHZlLCByZWplY3QpIHsKICAgICAgICAgICAgICByZWFkZXIub25sb2FkID0gZnVuY3Rpb24oKSB7CiAgICAgICAgICAgICAgICByZXNvbHZlKHJlYWRlci5yZXN1bHQpOwogICAgICAgICAgICAgIH07CiAgICAgICAgICAgICAgcmVhZGVyLm9uZXJyb3IgPSBmdW5jdGlvbigpIHsKICAgICAgICAgICAgICAgIHJlamVjdChyZWFkZXIuZXJyb3IpOwogICAgICAgICAgICAgIH07CiAgICAgICAgICAgIH0pOwogICAgICAgICAgfQogICAgICAgICAgZnVuY3Rpb24gcmVhZEJsb2JBc0FycmF5QnVmZmVyKGJsb2IpIHsKICAgICAgICAgICAgdmFyIHJlYWRlciA9IG5ldyBGaWxlUmVhZGVyKCk7CiAgICAgICAgICAgIHZhciBwcm9taXNlID0gZmlsZVJlYWRlclJlYWR5KHJlYWRlcik7CiAgICAgICAgICAgIHJlYWRlci5yZWFkQXNBcnJheUJ1ZmZlcihibG9iKTsKICAgICAgICAgICAgcmV0dXJuIHByb21pc2U7CiAgICAgICAgICB9CiAgICAgICAgICBmdW5jdGlvbiByZWFkQmxvYkFzVGV4dChibG9iKSB7CiAgICAgICAgICAgIHZhciByZWFkZXIgPSBuZXcgRmlsZVJlYWRlcigpOwogICAgICAgICAgICB2YXIgcHJvbWlzZSA9IGZpbGVSZWFkZXJSZWFkeShyZWFkZXIpOwogICAgICAgICAgICByZWFkZXIucmVhZEFzVGV4dChibG9iKTsKICAgICAgICAgICAgcmV0dXJuIHByb21pc2U7CiAgICAgICAgICB9CiAgICAgICAgICBmdW5jdGlvbiByZWFkQXJyYXlCdWZmZXJBc1RleHQoYnVmKSB7CiAgICAgICAgICAgIHZhciB2aWV3ID0gbmV3IFVpbnQ4QXJyYXkoYnVmKTsKICAgICAgICAgICAgdmFyIGNoYXJzID0gbmV3IEFycmF5KHZpZXcubGVuZ3RoKTsKICAgICAgICAgICAgZm9yICh2YXIgaSA9IDA7IGkgPCB2aWV3Lmxlbmd0aDsgaSsrKSB7CiAgICAgICAgICAgICAgY2hhcnNbaV0gPSBTdHJpbmcuZnJvbUNoYXJDb2RlKHZpZXdbaV0pOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHJldHVybiBjaGFycy5qb2luKCIiKTsKICAgICAgICAgIH0KICAgICAgICAgIGZ1bmN0aW9uIGJ1ZmZlckNsb25lKGJ1ZikgewogICAgICAgICAgICBpZiAoYnVmLnNsaWNlKSB7CiAgICAgICAgICAgICAgcmV0dXJuIGJ1Zi5zbGljZSgwKTsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICB2YXIgdmlldyA9IG5ldyBVaW50OEFycmF5KGJ1Zi5ieXRlTGVuZ3RoKTsKICAgICAgICAgICAgICB2aWV3LnNldChuZXcgVWludDhBcnJheShidWYpKTsKICAgICAgICAgICAgICByZXR1cm4gdmlldy5idWZmZXI7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGZ1bmN0aW9uIEJvZHkoKSB7CiAgICAgICAgICAgIHRoaXMuYm9keVVzZWQgPSBmYWxzZTsKICAgICAgICAgICAgdGhpcy5faW5pdEJvZHkgPSBmdW5jdGlvbihib2R5KSB7CiAgICAgICAgICAgICAgdGhpcy5fYm9keUluaXQgPSBib2R5OwogICAgICAgICAgICAgIGlmICghYm9keSkgewogICAgICAgICAgICAgICAgdGhpcy5fYm9keVRleHQgPSAiIjsKICAgICAgICAgICAgICB9IGVsc2UgaWYgKHR5cGVvZiBib2R5ID09PSAic3RyaW5nIikgewogICAgICAgICAgICAgICAgdGhpcy5fYm9keVRleHQgPSBib2R5OwogICAgICAgICAgICAgIH0gZWxzZSBpZiAoc3VwcG9ydC5ibG9iICYmIEJsb2IucHJvdG90eXBlLmlzUHJvdG90eXBlT2YoYm9keSkpIHsKICAgICAgICAgICAgICAgIHRoaXMuX2JvZHlCbG9iID0gYm9keTsKICAgICAgICAgICAgICB9IGVsc2UgaWYgKHN1cHBvcnQuZm9ybURhdGEgJiYgRm9ybURhdGEucHJvdG90eXBlLmlzUHJvdG90eXBlT2YoYm9keSkpIHsKICAgICAgICAgICAgICAgIHRoaXMuX2JvZHlGb3JtRGF0YSA9IGJvZHk7CiAgICAgICAgICAgICAgfSBlbHNlIGlmIChzdXBwb3J0LnNlYXJjaFBhcmFtcyAmJiBVUkxTZWFyY2hQYXJhbXMucHJvdG90eXBlLmlzUHJvdG90eXBlT2YoYm9keSkpIHsKICAgICAgICAgICAgICAgIHRoaXMuX2JvZHlUZXh0ID0gYm9keS50b1N0cmluZygpOwogICAgICAgICAgICAgIH0gZWxzZSBpZiAoc3VwcG9ydC5hcnJheUJ1ZmZlciAmJiBzdXBwb3J0LmJsb2IgJiYgaXNEYXRhVmlldyhib2R5KSkgewogICAgICAgICAgICAgICAgdGhpcy5fYm9keUFycmF5QnVmZmVyID0gYnVmZmVyQ2xvbmUoYm9keS5idWZmZXIpOwogICAgICAgICAgICAgICAgdGhpcy5fYm9keUluaXQgPSBuZXcgQmxvYihbdGhpcy5fYm9keUFycmF5QnVmZmVyXSk7CiAgICAgICAgICAgICAgfSBlbHNlIGlmIChzdXBwb3J0LmFycmF5QnVmZmVyICYmIChBcnJheUJ1ZmZlci5wcm90b3R5cGUuaXNQcm90b3R5cGVPZihib2R5KSB8fCBpc0FycmF5QnVmZmVyVmlldyhib2R5KSkpIHsKICAgICAgICAgICAgICAgIHRoaXMuX2JvZHlBcnJheUJ1ZmZlciA9IGJ1ZmZlckNsb25lKGJvZHkpOwogICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICB0aGlzLl9ib2R5VGV4dCA9IGJvZHkgPSBPYmplY3QucHJvdG90eXBlLnRvU3RyaW5nLmNhbGwoYm9keSk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGlmICghdGhpcy5oZWFkZXJzLmdldCgiY29udGVudC10eXBlIikpIHsKICAgICAgICAgICAgICAgIGlmICh0eXBlb2YgYm9keSA9PT0gInN0cmluZyIpIHsKICAgICAgICAgICAgICAgICAgdGhpcy5oZWFkZXJzLnNldCgiY29udGVudC10eXBlIiwgInRleHQvcGxhaW47Y2hhcnNldD1VVEYtOCIpOwogICAgICAgICAgICAgICAgfSBlbHNlIGlmICh0aGlzLl9ib2R5QmxvYiAmJiB0aGlzLl9ib2R5QmxvYi50eXBlKSB7CiAgICAgICAgICAgICAgICAgIHRoaXMuaGVhZGVycy5zZXQoImNvbnRlbnQtdHlwZSIsIHRoaXMuX2JvZHlCbG9iLnR5cGUpOwogICAgICAgICAgICAgICAgfSBlbHNlIGlmIChzdXBwb3J0LnNlYXJjaFBhcmFtcyAmJiBVUkxTZWFyY2hQYXJhbXMucHJvdG90eXBlLmlzUHJvdG90eXBlT2YoYm9keSkpIHsKICAgICAgICAgICAgICAgICAgdGhpcy5oZWFkZXJzLnNldCgiY29udGVudC10eXBlIiwgImFwcGxpY2F0aW9uL3gtd3d3LWZvcm0tdXJsZW5jb2RlZDtjaGFyc2V0PVVURi04Iik7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9OwogICAgICAgICAgICBpZiAoc3VwcG9ydC5ibG9iKSB7CiAgICAgICAgICAgICAgdGhpcy5ibG9iID0gZnVuY3Rpb24oKSB7CiAgICAgICAgICAgICAgICB2YXIgcmVqZWN0ZWQgPSBjb25zdW1lZCh0aGlzKTsKICAgICAgICAgICAgICAgIGlmIChyZWplY3RlZCkgewogICAgICAgICAgICAgICAgICByZXR1cm4gcmVqZWN0ZWQ7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAodGhpcy5fYm9keUJsb2IpIHsKICAgICAgICAgICAgICAgICAgcmV0dXJuIFByb21pc2UucmVzb2x2ZSh0aGlzLl9ib2R5QmxvYik7CiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKHRoaXMuX2JvZHlBcnJheUJ1ZmZlcikgewogICAgICAgICAgICAgICAgICByZXR1cm4gUHJvbWlzZS5yZXNvbHZlKG5ldyBCbG9iKFt0aGlzLl9ib2R5QXJyYXlCdWZmZXJdKSk7CiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKHRoaXMuX2JvZHlGb3JtRGF0YSkgewogICAgICAgICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IoImNvdWxkIG5vdCByZWFkIEZvcm1EYXRhIGJvZHkgYXMgYmxvYiIpOwogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgcmV0dXJuIFByb21pc2UucmVzb2x2ZShuZXcgQmxvYihbdGhpcy5fYm9keVRleHRdKSk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfTsKICAgICAgICAgICAgICB0aGlzLmFycmF5QnVmZmVyID0gZnVuY3Rpb24oKSB7CiAgICAgICAgICAgICAgICBpZiAodGhpcy5fYm9keUFycmF5QnVmZmVyKSB7CiAgICAgICAgICAgICAgICAgIHJldHVybiBjb25zdW1lZCh0aGlzKSB8fCBQcm9taXNlLnJlc29sdmUodGhpcy5fYm9keUFycmF5QnVmZmVyKTsKICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgIHJldHVybiB0aGlzLmJsb2IoKS50aGVuKHJlYWRCbG9iQXNBcnJheUJ1ZmZlcik7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfTsKICAgICAgICAgICAgfQogICAgICAgICAgICB0aGlzLnRleHQgPSBmdW5jdGlvbigpIHsKICAgICAgICAgICAgICB2YXIgcmVqZWN0ZWQgPSBjb25zdW1lZCh0aGlzKTsKICAgICAgICAgICAgICBpZiAocmVqZWN0ZWQpIHsKICAgICAgICAgICAgICAgIHJldHVybiByZWplY3RlZDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgaWYgKHRoaXMuX2JvZHlCbG9iKSB7CiAgICAgICAgICAgICAgICByZXR1cm4gcmVhZEJsb2JBc1RleHQodGhpcy5fYm9keUJsb2IpOwogICAgICAgICAgICAgIH0gZWxzZSBpZiAodGhpcy5fYm9keUFycmF5QnVmZmVyKSB7CiAgICAgICAgICAgICAgICByZXR1cm4gUHJvbWlzZS5yZXNvbHZlKHJlYWRBcnJheUJ1ZmZlckFzVGV4dCh0aGlzLl9ib2R5QXJyYXlCdWZmZXIpKTsKICAgICAgICAgICAgICB9IGVsc2UgaWYgKHRoaXMuX2JvZHlGb3JtRGF0YSkgewogICAgICAgICAgICAgICAgdGhyb3cgbmV3IEVycm9yKCJjb3VsZCBub3QgcmVhZCBGb3JtRGF0YSBib2R5IGFzIHRleHQiKTsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgcmV0dXJuIFByb21pc2UucmVzb2x2ZSh0aGlzLl9ib2R5VGV4dCk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9OwogICAgICAgICAgICBpZiAoc3VwcG9ydC5mb3JtRGF0YSkgewogICAgICAgICAgICAgIHRoaXMuZm9ybURhdGEgPSBmdW5jdGlvbigpIHsKICAgICAgICAgICAgICAgIHJldHVybiB0aGlzLnRleHQoKS50aGVuKGRlY29kZSk7CiAgICAgICAgICAgICAgfTsKICAgICAgICAgICAgfQogICAgICAgICAgICB0aGlzLmpzb24gPSBmdW5jdGlvbigpIHsKICAgICAgICAgICAgICByZXR1cm4gdGhpcy50ZXh0KCkudGhlbihKU09OLnBhcnNlKTsKICAgICAgICAgICAgfTsKICAgICAgICAgICAgcmV0dXJuIHRoaXM7CiAgICAgICAgICB9CiAgICAgICAgICB2YXIgbWV0aG9kcyA9IFsiREVMRVRFIiwgIkdFVCIsICJIRUFEIiwgIk9QVElPTlMiLCAiUE9TVCIsICJQVVQiXTsKICAgICAgICAgIGZ1bmN0aW9uIG5vcm1hbGl6ZU1ldGhvZChtZXRob2QpIHsKICAgICAgICAgICAgdmFyIHVwY2FzZWQgPSBtZXRob2QudG9VcHBlckNhc2UoKTsKICAgICAgICAgICAgcmV0dXJuIG1ldGhvZHMuaW5kZXhPZih1cGNhc2VkKSA+IC0xID8gdXBjYXNlZCA6IG1ldGhvZDsKICAgICAgICAgIH0KICAgICAgICAgIGZ1bmN0aW9uIFJlcXVlc3QoaW5wdXQsIG9wdGlvbnMpIHsKICAgICAgICAgICAgb3B0aW9ucyA9IG9wdGlvbnMgfHwge307CiAgICAgICAgICAgIHZhciBib2R5ID0gb3B0aW9ucy5ib2R5OwogICAgICAgICAgICBpZiAoaW5wdXQgaW5zdGFuY2VvZiBSZXF1ZXN0KSB7CiAgICAgICAgICAgICAgaWYgKGlucHV0LmJvZHlVc2VkKSB7CiAgICAgICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCJBbHJlYWR5IHJlYWQiKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgdGhpcy51cmwgPSBpbnB1dC51cmw7CiAgICAgICAgICAgICAgdGhpcy5jcmVkZW50aWFscyA9IGlucHV0LmNyZWRlbnRpYWxzOwogICAgICAgICAgICAgIGlmICghb3B0aW9ucy5oZWFkZXJzKSB7CiAgICAgICAgICAgICAgICB0aGlzLmhlYWRlcnMgPSBuZXcgSGVhZGVycyhpbnB1dC5oZWFkZXJzKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgdGhpcy5tZXRob2QgPSBpbnB1dC5tZXRob2Q7CiAgICAgICAgICAgICAgdGhpcy5tb2RlID0gaW5wdXQubW9kZTsKICAgICAgICAgICAgICB0aGlzLnNpZ25hbCA9IGlucHV0LnNpZ25hbDsKICAgICAgICAgICAgICBpZiAoIWJvZHkgJiYgaW5wdXQuX2JvZHlJbml0ICE9IG51bGwpIHsKICAgICAgICAgICAgICAgIGJvZHkgPSBpbnB1dC5fYm9keUluaXQ7CiAgICAgICAgICAgICAgICBpbnB1dC5ib2R5VXNlZCA9IHRydWU7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHRoaXMudXJsID0gU3RyaW5nKGlucHV0KTsKICAgICAgICAgICAgfQogICAgICAgICAgICB0aGlzLmNyZWRlbnRpYWxzID0gb3B0aW9ucy5jcmVkZW50aWFscyB8fCB0aGlzLmNyZWRlbnRpYWxzIHx8ICJzYW1lLW9yaWdpbiI7CiAgICAgICAgICAgIGlmIChvcHRpb25zLmhlYWRlcnMgfHwgIXRoaXMuaGVhZGVycykgewogICAgICAgICAgICAgIHRoaXMuaGVhZGVycyA9IG5ldyBIZWFkZXJzKG9wdGlvbnMuaGVhZGVycyk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdGhpcy5tZXRob2QgPSBub3JtYWxpemVNZXRob2Qob3B0aW9ucy5tZXRob2QgfHwgdGhpcy5tZXRob2QgfHwgIkdFVCIpOwogICAgICAgICAgICB0aGlzLm1vZGUgPSBvcHRpb25zLm1vZGUgfHwgdGhpcy5tb2RlIHx8IG51bGw7CiAgICAgICAgICAgIHRoaXMuc2lnbmFsID0gb3B0aW9ucy5zaWduYWwgfHwgdGhpcy5zaWduYWw7CiAgICAgICAgICAgIHRoaXMucmVmZXJyZXIgPSBudWxsOwogICAgICAgICAgICBpZiAoKHRoaXMubWV0aG9kID09PSAiR0VUIiB8fCB0aGlzLm1ldGhvZCA9PT0gIkhFQUQiKSAmJiBib2R5KSB7CiAgICAgICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcigiQm9keSBub3QgYWxsb3dlZCBmb3IgR0VUIG9yIEhFQUQgcmVxdWVzdHMiKTsKICAgICAgICAgICAgfQogICAgICAgICAgICB0aGlzLl9pbml0Qm9keShib2R5KTsKICAgICAgICAgIH0KICAgICAgICAgIFJlcXVlc3QucHJvdG90eXBlLmNsb25lID0gZnVuY3Rpb24oKSB7CiAgICAgICAgICAgIHJldHVybiBuZXcgUmVxdWVzdCh0aGlzLCB7IGJvZHk6IHRoaXMuX2JvZHlJbml0IH0pOwogICAgICAgICAgfTsKICAgICAgICAgIGZ1bmN0aW9uIGRlY29kZShib2R5KSB7CiAgICAgICAgICAgIHZhciBmb3JtID0gbmV3IEZvcm1EYXRhKCk7CiAgICAgICAgICAgIGJvZHkudHJpbSgpLnNwbGl0KCImIikuZm9yRWFjaChmdW5jdGlvbihieXRlcykgewogICAgICAgICAgICAgIGlmIChieXRlcykgewogICAgICAgICAgICAgICAgdmFyIHNwbGl0ID0gYnl0ZXMuc3BsaXQoIj0iKTsKICAgICAgICAgICAgICAgIHZhciBuYW1lID0gc3BsaXQuc2hpZnQoKS5yZXBsYWNlKC9cKy9nLCAiICIpOwogICAgICAgICAgICAgICAgdmFyIHZhbHVlID0gc3BsaXQuam9pbigiPSIpLnJlcGxhY2UoL1wrL2csICIgIik7CiAgICAgICAgICAgICAgICBmb3JtLmFwcGVuZChkZWNvZGVVUklDb21wb25lbnQobmFtZSksIGRlY29kZVVSSUNvbXBvbmVudCh2YWx1ZSkpOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfSk7CiAgICAgICAgICAgIHJldHVybiBmb3JtOwogICAgICAgICAgfQogICAgICAgICAgZnVuY3Rpb24gcGFyc2VIZWFkZXJzKHJhd0hlYWRlcnMpIHsKICAgICAgICAgICAgdmFyIGhlYWRlcnMgPSBuZXcgSGVhZGVycygpOwogICAgICAgICAgICB2YXIgcHJlUHJvY2Vzc2VkSGVhZGVycyA9IHJhd0hlYWRlcnMucmVwbGFjZSgvXHI/XG5bXHQgXSsvZywgIiAiKTsKICAgICAgICAgICAgcHJlUHJvY2Vzc2VkSGVhZGVycy5zcGxpdCgvXHI/XG4vKS5mb3JFYWNoKGZ1bmN0aW9uKGxpbmUpIHsKICAgICAgICAgICAgICB2YXIgcGFydHMgPSBsaW5lLnNwbGl0KCI6Iik7CiAgICAgICAgICAgICAgdmFyIGtleSA9IHBhcnRzLnNoaWZ0KCkudHJpbSgpOwogICAgICAgICAgICAgIGlmIChrZXkpIHsKICAgICAgICAgICAgICAgIHZhciB2YWx1ZSA9IHBhcnRzLmpvaW4oIjoiKS50cmltKCk7CiAgICAgICAgICAgICAgICBoZWFkZXJzLmFwcGVuZChrZXksIHZhbHVlKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0pOwogICAgICAgICAgICByZXR1cm4gaGVhZGVyczsKICAgICAgICAgIH0KICAgICAgICAgIEJvZHkuY2FsbChSZXF1ZXN0LnByb3RvdHlwZSk7CiAgICAgICAgICBmdW5jdGlvbiBSZXNwb25zZShib2R5SW5pdCwgb3B0aW9ucykgewogICAgICAgICAgICBpZiAoIW9wdGlvbnMpIHsKICAgICAgICAgICAgICBvcHRpb25zID0ge307CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdGhpcy50eXBlID0gImRlZmF1bHQiOwogICAgICAgICAgICB0aGlzLnN0YXR1cyA9IG9wdGlvbnMuc3RhdHVzID09PSB2b2lkIDAgPyAyMDAgOiBvcHRpb25zLnN0YXR1czsKICAgICAgICAgICAgdGhpcy5vayA9IHRoaXMuc3RhdHVzID49IDIwMCAmJiB0aGlzLnN0YXR1cyA8IDMwMDsKICAgICAgICAgICAgdGhpcy5zdGF0dXNUZXh0ID0gInN0YXR1c1RleHQiIGluIG9wdGlvbnMgPyBvcHRpb25zLnN0YXR1c1RleHQgOiAiT0siOwogICAgICAgICAgICB0aGlzLmhlYWRlcnMgPSBuZXcgSGVhZGVycyhvcHRpb25zLmhlYWRlcnMpOwogICAgICAgICAgICB0aGlzLnVybCA9IG9wdGlvbnMudXJsIHx8ICIiOwogICAgICAgICAgICB0aGlzLl9pbml0Qm9keShib2R5SW5pdCk7CiAgICAgICAgICB9CiAgICAgICAgICBCb2R5LmNhbGwoUmVzcG9uc2UucHJvdG90eXBlKTsKICAgICAgICAgIFJlc3BvbnNlLnByb3RvdHlwZS5jbG9uZSA9IGZ1bmN0aW9uKCkgewogICAgICAgICAgICByZXR1cm4gbmV3IFJlc3BvbnNlKHRoaXMuX2JvZHlJbml0LCB7CiAgICAgICAgICAgICAgc3RhdHVzOiB0aGlzLnN0YXR1cywKICAgICAgICAgICAgICBzdGF0dXNUZXh0OiB0aGlzLnN0YXR1c1RleHQsCiAgICAgICAgICAgICAgaGVhZGVyczogbmV3IEhlYWRlcnModGhpcy5oZWFkZXJzKSwKICAgICAgICAgICAgICB1cmw6IHRoaXMudXJsCiAgICAgICAgICAgIH0pOwogICAgICAgICAgfTsKICAgICAgICAgIFJlc3BvbnNlLmVycm9yID0gZnVuY3Rpb24oKSB7CiAgICAgICAgICAgIHZhciByZXNwb25zZSA9IG5ldyBSZXNwb25zZShudWxsLCB7IHN0YXR1czogMCwgc3RhdHVzVGV4dDogIiIgfSk7CiAgICAgICAgICAgIHJlc3BvbnNlLnR5cGUgPSAiZXJyb3IiOwogICAgICAgICAgICByZXR1cm4gcmVzcG9uc2U7CiAgICAgICAgICB9OwogICAgICAgICAgdmFyIHJlZGlyZWN0U3RhdHVzZXMgPSBbMzAxLCAzMDIsIDMwMywgMzA3LCAzMDhdOwogICAgICAgICAgUmVzcG9uc2UucmVkaXJlY3QgPSBmdW5jdGlvbih1cmwsIHN0YXR1cykgewogICAgICAgICAgICBpZiAocmVkaXJlY3RTdGF0dXNlcy5pbmRleE9mKHN0YXR1cykgPT09IC0xKSB7CiAgICAgICAgICAgICAgdGhyb3cgbmV3IFJhbmdlRXJyb3IoIkludmFsaWQgc3RhdHVzIGNvZGUiKTsKICAgICAgICAgICAgfQogICAgICAgICAgICByZXR1cm4gbmV3IFJlc3BvbnNlKG51bGwsIHsgc3RhdHVzLCBoZWFkZXJzOiB7IGxvY2F0aW9uOiB1cmwgfSB9KTsKICAgICAgICAgIH07CiAgICAgICAgICBleHBvcnRzMi5ET01FeGNlcHRpb24gPSBzZWxmMi5ET01FeGNlcHRpb247CiAgICAgICAgICB0cnkgewogICAgICAgICAgICBuZXcgZXhwb3J0czIuRE9NRXhjZXB0aW9uKCk7CiAgICAgICAgICB9IGNhdGNoIChlcnIpIHsKICAgICAgICAgICAgZXhwb3J0czIuRE9NRXhjZXB0aW9uID0gZnVuY3Rpb24obWVzc2FnZSwgbmFtZSkgewogICAgICAgICAgICAgIHRoaXMubWVzc2FnZSA9IG1lc3NhZ2U7CiAgICAgICAgICAgICAgdGhpcy5uYW1lID0gbmFtZTsKICAgICAgICAgICAgICB2YXIgZXJyb3IgPSBFcnJvcihtZXNzYWdlKTsKICAgICAgICAgICAgICB0aGlzLnN0YWNrID0gZXJyb3Iuc3RhY2s7CiAgICAgICAgICAgIH07CiAgICAgICAgICAgIGV4cG9ydHMyLkRPTUV4Y2VwdGlvbi5wcm90b3R5cGUgPSBPYmplY3QuY3JlYXRlKEVycm9yLnByb3RvdHlwZSk7CiAgICAgICAgICAgIGV4cG9ydHMyLkRPTUV4Y2VwdGlvbi5wcm90b3R5cGUuY29uc3RydWN0b3IgPSBleHBvcnRzMi5ET01FeGNlcHRpb247CiAgICAgICAgICB9CiAgICAgICAgICBmdW5jdGlvbiBmZXRjaDIoaW5wdXQsIGluaXQyKSB7CiAgICAgICAgICAgIHJldHVybiBuZXcgUHJvbWlzZShmdW5jdGlvbihyZXNvbHZlLCByZWplY3QpIHsKICAgICAgICAgICAgICB2YXIgcmVxdWVzdCA9IG5ldyBSZXF1ZXN0KGlucHV0LCBpbml0Mik7CiAgICAgICAgICAgICAgaWYgKHJlcXVlc3Quc2lnbmFsICYmIHJlcXVlc3Quc2lnbmFsLmFib3J0ZWQpIHsKICAgICAgICAgICAgICAgIHJldHVybiByZWplY3QobmV3IGV4cG9ydHMyLkRPTUV4Y2VwdGlvbigiQWJvcnRlZCIsICJBYm9ydEVycm9yIikpOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB2YXIgeGhyID0gbmV3IFhNTEh0dHBSZXF1ZXN0KCk7CiAgICAgICAgICAgICAgZnVuY3Rpb24gYWJvcnRYaHIoKSB7CiAgICAgICAgICAgICAgICB4aHIuYWJvcnQoKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgeGhyLm9ubG9hZCA9IGZ1bmN0aW9uKCkgewogICAgICAgICAgICAgICAgdmFyIG9wdGlvbnMgPSB7CiAgICAgICAgICAgICAgICAgIHN0YXR1czogeGhyLnN0YXR1cywKICAgICAgICAgICAgICAgICAgc3RhdHVzVGV4dDogeGhyLnN0YXR1c1RleHQsCiAgICAgICAgICAgICAgICAgIGhlYWRlcnM6IHBhcnNlSGVhZGVycyh4aHIuZ2V0QWxsUmVzcG9uc2VIZWFkZXJzKCkgfHwgIiIpCiAgICAgICAgICAgICAgICB9OwogICAgICAgICAgICAgICAgb3B0aW9ucy51cmwgPSAicmVzcG9uc2VVUkwiIGluIHhociA/IHhoci5yZXNwb25zZVVSTCA6IG9wdGlvbnMuaGVhZGVycy5nZXQoIlgtUmVxdWVzdC1VUkwiKTsKICAgICAgICAgICAgICAgIHZhciBib2R5ID0gInJlc3BvbnNlIiBpbiB4aHIgPyB4aHIucmVzcG9uc2UgOiB4aHIucmVzcG9uc2VUZXh0OwogICAgICAgICAgICAgICAgcmVzb2x2ZShuZXcgUmVzcG9uc2UoYm9keSwgb3B0aW9ucykpOwogICAgICAgICAgICAgIH07CiAgICAgICAgICAgICAgeGhyLm9uZXJyb3IgPSBmdW5jdGlvbigpIHsKICAgICAgICAgICAgICAgIHJlamVjdChuZXcgVHlwZUVycm9yKCJOZXR3b3JrIHJlcXVlc3QgZmFpbGVkIikpOwogICAgICAgICAgICAgIH07CiAgICAgICAgICAgICAgeGhyLm9udGltZW91dCA9IGZ1bmN0aW9uKCkgewogICAgICAgICAgICAgICAgcmVqZWN0KG5ldyBUeXBlRXJyb3IoIk5ldHdvcmsgcmVxdWVzdCBmYWlsZWQiKSk7CiAgICAgICAgICAgICAgfTsKICAgICAgICAgICAgICB4aHIub25hYm9ydCA9IGZ1bmN0aW9uKCkgewogICAgICAgICAgICAgICAgcmVqZWN0KG5ldyBleHBvcnRzMi5ET01FeGNlcHRpb24oIkFib3J0ZWQiLCAiQWJvcnRFcnJvciIpKTsKICAgICAgICAgICAgICB9OwogICAgICAgICAgICAgIHhoci5vcGVuKHJlcXVlc3QubWV0aG9kLCByZXF1ZXN0LnVybCwgdHJ1ZSk7CiAgICAgICAgICAgICAgaWYgKHJlcXVlc3QuY3JlZGVudGlhbHMgPT09ICJpbmNsdWRlIikgewogICAgICAgICAgICAgICAgeGhyLndpdGhDcmVkZW50aWFscyA9IHRydWU7CiAgICAgICAgICAgICAgfSBlbHNlIGlmIChyZXF1ZXN0LmNyZWRlbnRpYWxzID09PSAib21pdCIpIHsKICAgICAgICAgICAgICAgIHhoci53aXRoQ3JlZGVudGlhbHMgPSBmYWxzZTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgaWYgKCJyZXNwb25zZVR5cGUiIGluIHhociAmJiBzdXBwb3J0LmJsb2IpIHsKICAgICAgICAgICAgICAgIHhoci5yZXNwb25zZVR5cGUgPSAiYmxvYiI7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIHJlcXVlc3QuaGVhZGVycy5mb3JFYWNoKGZ1bmN0aW9uKHZhbHVlLCBuYW1lKSB7CiAgICAgICAgICAgICAgICB4aHIuc2V0UmVxdWVzdEhlYWRlcihuYW1lLCB2YWx1ZSk7CiAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgICAgaWYgKHJlcXVlc3Quc2lnbmFsKSB7CiAgICAgICAgICAgICAgICByZXF1ZXN0LnNpZ25hbC5hZGRFdmVudExpc3RlbmVyKCJhYm9ydCIsIGFib3J0WGhyKTsKICAgICAgICAgICAgICAgIHhoci5vbnJlYWR5c3RhdGVjaGFuZ2UgPSBmdW5jdGlvbigpIHsKICAgICAgICAgICAgICAgICAgaWYgKHhoci5yZWFkeVN0YXRlID09PSA0KSB7CiAgICAgICAgICAgICAgICAgICAgcmVxdWVzdC5zaWduYWwucmVtb3ZlRXZlbnRMaXN0ZW5lcigiYWJvcnQiLCBhYm9ydFhocik7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH07CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIHhoci5zZW5kKHR5cGVvZiByZXF1ZXN0Ll9ib2R5SW5pdCA9PT0gInVuZGVmaW5lZCIgPyBudWxsIDogcmVxdWVzdC5f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IGNodW5rMS5tYXh2LmJsb2NrUG9zaXRpb24gPCA2NWUzICYmIGNodW5rMi5tYXh2LmJsb2NrUG9zaXRpb24gLSBjaHVuazEubWludi5ibG9ja1Bvc2l0aW9uIDwgNWU2OwogIH0KICBmdW5jdGlvbiBtYWtlT3B0cyhvYmogPSB7fSkgewogICAgcmV0dXJuICJhYm9ydGVkIiBpbiBvYmogPyB7IHNpZ25hbDogb2JqIH0gOiBvYmo7CiAgfQogIGZ1bmN0aW9uIG9wdGltaXplQ2h1bmtzKGNodW5rcywgbG93ZXN0KSB7CiAgICBjb25zdCBtZXJnZWRDaHVua3MgPSBbXTsKICAgIGxldCBsYXN0Q2h1bmsgPSBudWxsOwogICAgaWYgKGNodW5rcy5sZW5ndGggPT09IDApIHsKICAgICAgcmV0dXJuIGNodW5rczsKICAgIH0KICAgIGNodW5rcy5zb3J0KChjMCwgYzEpID0+IHsKICAgICAgY29uc3QgZGlmID0gYzAubWludi5ibG9ja1Bvc2l0aW9uIC0gYzEubWludi5ibG9ja1Bvc2l0aW9uOwogICAgICBpZiAoZGlmICE9PSAwKSB7CiAgICAgICAgcmV0dXJuIGRpZjsKICAgICAgfSBlbHNlIHsKICAgICAgICByZXR1cm4gYzAubWludi5kYXRhUG9zaXRpb24gLSBjMS5taW52LmRhdGFQb3NpdGlvbjsKICAgICAgfQogICAgfSk7CiAgICBjaHVua3MuZm9yRWFjaCgoY2h1bmspID0+IHsKICAgICAgaWYgKCFsb3dlc3QgfHwgY2h1bmsubWF4di5jb21wYXJlVG8obG93ZXN0KSA+IDApIHsKICAgICAgICBpZiAobGFzdENodW5rID09PSBudWxsKSB7CiAgICAgICAgICBtZXJnZWRDaHVua3MucHVzaChjaHVuayk7CiAgICAgICAgICBsYXN0Q2h1bmsgPSBjaHVuazsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgaWYgKGNhbk1lcmdlQmxvY2tzKGxhc3RDaHVuaywgY2h1bmspKSB7CiAgICAgICAgICAgIGlmIChjaHVuay5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IGNvbnN0IGluZGV4ID0gcHJvbS5pbmRpY2VzW3JlZklkXTsKICAgICAgaWYgKCFpbmRleCkgewogICAgICAgIHJldHVybiAtMTsKICAgICAgfQogICAgICBjb25zdCByZXQgPSBpbmRleC5zdGF0cyB8fCB7fTsKICAgICAgcmV0dXJuIHJldC5saW5lQ291bnQgPT09IHZvaWQgMCA/IC0xIDogcmV0LmxpbmVDb3VudDsKICAgIH0KICAgIGZldGNoQmFpKG9wdHMgPSB7fSkgewogICAgICBpZiAoIXRoaXMuYmFpUCkgewogICAgICAgIHRoaXMuYmFpUCA9IHRoaXMuZmlsZWhhbmRsZS5yZWFkRmlsZShvcHRzKS5jYXRjaCgoZSkgPT4gewogICAgICAgICAgdGhpcy5iYWlQID0gdm9pZCAwOwogICAgICAgICAgdGhyb3cgZTsKICAgICAgICB9KTsKICAgICAgfQogICAgICByZXR1cm4gdGhpcy5iYWlQOwogICAgfQogICAgYXN5bmMgX3BhcnNlKCkgewogICAgICBjb25zdCBkYXRhID0geyBiYWk6IHRydWUsIG1heEJsb2NrU2l6ZTogMSA8PCAxNiB9OwogICAgICBjb25zdCBieXRlcyA9IGF3YWl0IHRoaXMuZmV0Y2hCYWkoKTsKICAgICAgaWYgKGJ5dGVzLnJlYWRVSW50MzJMRSgwKSAhPT0gQkFJX01BR0lDKSB7CiAgICAgICAgdGhyb3cgbmV3IEVycm9yKCJOb3QgYSBCQUkgZmlsZSIpOwogICAgICB9CiAgICAgIGRhdGEucmVmQ291bnQgPSBieXRlcy5yZWFkSW50MzJMRSg0KTsKICAgICAgY29uc3QgZGVwdGggPSA1OwogICAgICBjb25zdCBiaW5MaW1pdCA9ICgoMSA8PCAoZGVwdGggKyAxKSAqIDMpIC0gMSkgLyA3OwogICAgICBkYXRhLmluZGljZXMgPSBuZXcgQXJyYXkoZGF0YS5yZWZDb3VudCk7CiAgICAgIGxldCBjdXJyT2Zmc2V0ID0gODsKICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCBkYXRhLnJlZkNvdW50OyBpICs9IDEpIHsKICAgICAgICBjb25zdCBiaW5Db3VudCA9IGJ5dGVzLnJlYWRJbnQzMkxFKGN1cnJPZmZzZXQpOwogICAgICAgIGxldCBzdGF0czsKICAgICAgICBjdXJyT2Zmc2V0ICs9IDQ7CiAgICAgICAgY29uc3QgYmluSW5kZXggPSB7fTsKICAgICAgICBmb3IgKGxldCBqID0gMDsgaiA8IGJpbkNvdW50OyBqICs9IDEpIHsKICAgICAgICAgIGNvbnN0IGJpbiA9IGJ5dGVzLnJlYWRVSW50MzJMRShjdXJyT2Zmc2V0KTsKICAgICAgICAgIGN1cnJPZmZzZXQgKz0gNDsKICAgICAgICAgIGlmIChiaW4gPT09IGJpbkxpbWl0ICsgMSkgewogICAgICAgICAgICBjdXJyT2Zmc2V0ICs9IDQ7CiAgICAgICAgICAgIHN0YXRzID0gdGhpcy5wYXJzZVBzZXVkb0JpbihieXRlcywgY3Vyck9mZnNldCk7CiAgICAgICAgICAgIGN1cnJPZmZzZXQgKz0gMzI7CiAgICAgICAgICB9IGVsc2UgaWYgKGJpbiA+IGJpbkxpbWl0ICsgMSkgewogICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IoImJhaSBpbmRleCBjb250YWlucyB0b28gbWFueSBiaW5zLCBwbGVhc2UgdXNlIENTSSIpOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgY29uc3QgY2h1bmtDb3VudCA9IGJ5dGVzLnJlYWRJbnQzMkxFKGN1cnJPZmZzZXQpOwogICAgICAgICAgICBjdXJyT2Zmc2V0ICs9IDQ7CiAgICAgICAgICAgIGNvbnN0IGNodW5rcyA9IG5ldyBBcnJheShjaHVua0NvdW50KTsKICAgICAgICAgICAgZm9yIChsZXQgayA9IDA7IGsgPCBjaHVua0NvdW50OyBrICs9IDEpIHsKICAgICAgICAgICAgICBjb25zdCB1ID0gZnJvbUJ5dGVzKGJ5dGVzLCBjdXJyT2Zmc2V0KTsKICAgICAgICAgICAgICBjb25zdCB2ID0gZnJvbUJ5dGVzKGJ5dGVzLCBjdXJyT2Zmc2V0ICsgOCk7CiAgICAgICAgICAgICAgY3Vyck9mZnNldCArPSAxNjsKICAgICAgICAgICAgICB0aGlzLl9maW5kRmlyc3REYXRhKGRhdGEsIHUpOwogICAgICAgICAgICAgIGNodW5rc1trXSA9IG5ldyBDaHVuayh1LCB2LCBiaW4pOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGJpbkluZGV4W2Jpbl0gPSBjaHVua3M7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGNvbnN0IGxpbmVhckNvdW50ID0gYnl0ZXMucmVhZEludDMyTEUoY3Vyck9mZnNldCk7CiAgICAgICAgY3Vyck9mZnNldCArPSA0OwogICAgICAgIGNvbnN0IGxpbmVhckluZGV4ID0gbmV3IEFycmF5KGxpbmVhckNvdW50KTsKICAgICAgICBmb3IgKGxldCBrID0gMDsgayA8IGxpbmVhckNvdW50OyBrICs9IDEpIHsKICAgICAgICAgIGxpbmVhckluZGV4W2tdID0gZnJvbUJ5dGVzKGJ5dGVzLCBjdXJyT2Zmc2V0KTsKICAgICAgICAgIGN1cnJPZmZzZXQgKz0gODsKICAgICAgICAgIHRoaXMuX2ZpbmRGaXJzdERhdGEoZGF0YSwgbGluZWFySW5kZXhba10pOwogICAgICAgIH0KICAgICAgICBkYXRhLmluZGljZXNbaV0gPSB7IGJpbkluZGV4LCBsaW5lYXJJbmRleCwgc3RhdHMgfTsKICAgICAgfQogICAgICByZXR1cm4gZGF0YTsKICAgIH0KICAgIGFzeW5jIGluZGV4Q292KHNlcUlkLCBzdGFydCwgZW5kLCBvcHRzID0ge30pIHsKICAgICAgY29uc3QgdiA9IDE2Mzg0OwogICAgICBjb25zdCByYW5nZSA9IHN0YXJ0ICE9PSB2b2lkIDA7CiAgICAgIGNvbnN0IGluZGV4RGF0YSA9IGF3YWl0IHRoaXMucGFyc2Uob3B0cyk7CiAgICAgIGNvbnN0IHNlcUlkeCA9IGluZGV4RGF0YS5pbmRpY2VzW3NlcUlkXTsKICAgICAgaWYgKCFzZXFJZHgpIHsKICAgICAgICByZXR1cm4gW107CiAgICAgIH0KICAgICAgY29uc3QgeyBsaW5lYXJJbmRleCA9IFtdLCBzdGF0cyB9ID0gc2VxSWR4OwogICAgICBpZiAoIWxpbmVhckluZGV4Lmxlbmd0aCkgewogICAgICAgIHJldHVybiBbXTsKICAgICAgfQogICAgICBjb25zdCBlID0gZW5kICE9PSB2b2lkIDAgPyByb3VuZFVwKGVuZCwgdikgOiAobGluZWFySW5kZXgubGVuZ3RoIC0gMSkgKiB2OwogICAgICBjb25zdCBzID0gc3RhcnQgIT09IHZvaWQgMCA/IHJvdW5kRG93bihzdGFydCwgdikgOiAwOwogICAgICBsZXQgZGVwdGhzOwogICAgICBpZiAocmFuZ2UpIHsKICAgICAgICBkZXB0aHMgPSBuZXcgQXJyYXkoKGUgLSBzKSAvIHYpOwogICAgICB9IGVsc2UgewogICAgICAgIGRlcHRocyA9IG5ldyBBcnJheShsaW5lYXJJbmRleC5sZW5ndGggLSAxKTsKICAgICAgfQogICAgICBjb25zdCB0b3RhbFNpemUgPSBsaW5lYXJJbmRleFtsaW5lYXJJbmRleC5sZW5ndGggLSAxXS5ibG9ja1Bvc2l0aW9uOwogICAgICBpZiAoZSA+IChsaW5lYXJJbmRleC5sZW5ndGggLSAxKSAqIHYpIHsKICAgICAgICB0aHJvdyBuZXcgRXJyb3IoInF1ZXJ5IG91dHNpZGUgb2YgcmFuZ2Ugb2YgbGluZWFyIGluZGV4Iik7CiAgICAgIH0KICAgICAgbGV0IGN1cnJlbnRQb3MgPSBsaW5lYXJJbmRleFtzIC8gdl0uYmxvY2tQb3NpdGlvbjsKICAgICAgZm9yIChsZXQgaSA9IHMgLyB2LCBqID0gMDsgaSA8IGUgLyB2OyBpKyssIGorKykgewogICAgICAgIGRlcHRoc1tqXSA9IHsKICAgICAgICAgIHNjb3JlOiBsaW5lYXJJbmRleFtpICsgMV0uYmxvY2tQb3NpdGlvbiAtIGN1cnJlbnRQb3MsCiAgICAgICAgICBzdGFydDogaSAqIHYsCiAgICAgICAgICBlbmQ6IGkgKiB2ICsgdgogICAgICAgIH07CiAgICAgICAgY3VycmVudFBvcyA9IGxpbmVhckluZGV4W2kgKyAxXS5ibG9ja1Bvc2l0aW9uOwogICAgICB9CiAgICAgIHJldHVybiBkZXB0aHMubWFwKChkKSA9PiB7CiAgICAgICAgcmV0dXJuIHsgLi4uZCwgc2NvcmU6IGQuc2NvcmUgKiBzdGF0cy5saW5lQ291bnQgLyB0b3RhbFNpemUgfTsKICAgICAgfSk7CiAgICB9CiAgICByZWcyYmlucyhiZWcsIGVuZCkgewogICAgICBlbmQgLT0gMTsKICAgICAgcmV0dXJuIFsKICAgICAgICBbMCwgMF0sCiAgICAgICAgWzEgKyAoYmVnID4+IDI2KSwgMSArIChlbmQgPj4gMjYpXSwKICAgICAgICBbOSArIChiZWcgPj4gMjMpLCA5ICsgKGVuZCA+PiAyMyldLAogICAgICAgIFs3MyArIChiZWcgPj4gMjApLCA3MyArIChlbmQgPj4gMjApXSwKICAgICAgICBbNTg1ICsgKGJlZyA+PiAxNyksIDU4NSArIChlbmQgPj4gMTcpXSwKICAgICAgICBbNDY4MSArIChiZWcgPj4gMTQpLCA0NjgxICsgKGVuZCA+PiAxNCldCiAgICAgIF07CiAgICB9CiAgICBhc3luYyBibG9ja3NGb3JSYW5nZShyZWZJZCwgbWluLCBtYXgsIG9wdHMgPSB7fSkgewogICAgICBpZiAobWluIDwgMCkgewogICAgICAgIG1pbiA9IDA7CiAgICAgIH0KICAgICAgY29uc3QgaW5kZXhEYXRhID0gYXdhaXQgdGhpcy5wYXJzZShvcHRzKTsKICAgICAgaWYgKCFpbmRleERhdGEpIHsKICAgICAgICByZXR1cm4gW107CiAgICAgIH0KICAgICAgY29uc3QgYmEgPSBpbmRleERhdGEuaW5kaWNlc1tyZWZJZF07CiAgICAgIGlmICghYmEpIHsKICAgICAgICByZXR1cm4gW107CiAgICAgIH0KICAgICAgY29uc3Qgb3ZlcmxhcHBpbmdCaW5zID0gdGhpcy5yZWcyYmlucyhtaW4sIG1heCk7CiAgICAgIGNvbnN0IGNodW5rcyA9IFtdOwogICAgICBmb3IgKGNvbnN0IFtzdGFydCwgZW5kXSBvZiBvdmVybGFwcGluZ0JpbnMpIHsKICAgICAgICBmb3IgKGxldCBiaW4gPSBzdGFydDsgYmluIDw9IGVuZDsgYmluKyspIHsKICAgICAgICAgIGlmIChiYS5iaW5JbmRleFtiaW5dKSB7CiAgICAgICAgICAgIGNvbnN0IGJpbkNodW5rcyA9IGJhLmJpbkluZGV4W2Jpbl07CiAgICAgICAgICAgIGZvciAobGV0IGMgPSAwOyBjIDwgYmluQ2h1bmtzLmxlbmd0aDsgKytjKSB7CiAgICAgICAgICAgICAgY2h1bmtzLnB1c2gobmV3IENodW5rKGJpbkNodW5rc1tjXS5taW52LCBiaW5DaHVua3NbY10ubWF4diwgYmluKSk7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgICAgY29uc3QgbmludHYgPSBiYS5saW5lYXJJbmRleC5sZW5ndGg7CiAgICAgIGxldCBsb3dlc3QgPSBudWxsOwogICAgICBjb25zdCBtaW5MaW4gPSBNYXRoLm1pbihtaW4gPj4gMTQsIG5pbnR2IC0gMSk7CiAgICAgIGNvbnN0IG1heExpbiA9IE1hdGgubWluKG1heCA+PiAxNCwgbmludHYgLSAxKTsKICAgICAgZm9yIChsZXQgaSA9IG1pbkxpbjsgaSA8PSBtYXhMaW47ICsraSkgewogICAgICAgIGNvbnN0IHZwID0gYmEubGluZWFySW5kZXhbaV07CiAgICAgICAgaWYgKHZwKSB7CiAgICAgICAgICBpZiAoIWxvd2VzdCB8fCB2cC5jb21wYXJlVG8obG93ZXN0KSA8IDApIHsKICAgICAgICAgICAgbG93ZXN0ID0gdnA7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9CiAgICAgIHJldHVybiBvcHRpbWl6ZU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3ZlcnJpZGVzID0gb3B0cy5vdmVycmlkZXM7CiAgICAgIH0KICAgICAgdGhpcy5mZXRjaEltcGxlbWVudGF0aW9uID0gZmV0Y2gyOwogICAgfQogICAgYXN5bmMgZmV0Y2goaW5wdXQsIGluaXQyKSB7CiAgICAgIGxldCByZXNwb25zZTsKICAgICAgdHJ5IHsKICAgICAgICByZXNwb25zZSA9IGF3YWl0IHRoaXMuZmV0Y2hJbXBsZW1lbnRhdGlvbihpbnB1dCwgaW5pdDIpOwogICAgICB9IGNhdGNoIChlKSB7CiAgICAgICAgaWYgKGAke2V9YC5pbmNsdWRlcygiRmFpbGVkIHRvIGZldGNoIikpIHsKICAgICAgICAgIGNvbnNvbGUud2FybihgZ2VuZXJpYy1maWxlaGFuZGxlOiByZWZldGNoaW5nICR7aW5wdXR9IHRvIGF0dGVtcHQgdG8gd29yayBhcm91bmQgY2hyb21lIENPUlMgaGVhZGVyIGNhY2hpbmcgYnVnYCk7CiAgICAgICAgICByZXNwb25zZSA9IGF3YWl0IHRoaXMuZmV0Y2hJbXBsZW1lbnRhdGlvbihpbnB1dCwgewogICAgICAgICAgICAuLi5pbml0MiwKICAgICAgICAgICAgY2FjaGU6ICJyZWxvYWQiCiAgICAgICAgICB9KTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgdGhyb3cgZTsKICAgICAgICB9CiAgICAgIH0KICAgICAgcmV0dXJuIHJlc3BvbnNlOwogICAgfQogICAgYXN5bmMgcmVhZChidWZmZXIsIG9mZnNldCA9IDAsIGxlbmd0aCwgcG9zaXRpb24gPSAwLCBvcHRzID0ge30pIHsKICAgICAgY29uc3QgeyBoZWFkZXJzID0ge30sIHNpZ25hbCwgb3ZlcnJpZGVzID0ge30gfSA9IG9wdHM7CiAgICAgIGlmIChsZW5ndGggPCBJbmZpbml0eSkgewogICAgICAgIGhlYWRlcnMucmFuZ2UgPSBgYnl0ZXM9JHtwb3NpdGlvbn0tJHtwb3NpdGlvbiArIGxlbmd0aH1gOwogICAgIC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AgICAgY29uc3QgcmVzID0gcmVzcG9uc2UuaGVhZGVycy5nZXQoImNvbnRlbnQtcmFuZ2UiKTsKICAgICAgICBjb25zdCBzaXplTWF0Y2ggPSAvXC8oXGQrKSQvLmV4ZWMocmVzIHx8ICIiKTsKICAgICAgICBpZiAoc2l6ZU1hdGNoICYmIHNpemVNYXRjaFsxXSkgewogICAgICAgICAgdGhpcy5fc3RhdCA9IHsgc2l6ZTogcGFyc2VJbnQoc2l6ZU1hdGNoWzFdLCAxMCkgfTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHsgYnl0ZXNSZWFkOiBieXRlc0NvcGllZCwgYnVmZmVyIH07CiAgICAgIH0KICAgICAgaWYgKHJlc3BvbnNlLnN0YXR1cyA9PT0gMjAwKSB7CiAgICAgICAgdGhyb3cgbmV3IEVycm9yKCIke3RoaXMudXJsfSBmZXRjaCByZXR1cm5lZCBzdGF0dXMgMjAwLCBleHBlY3RlZCAyMDYiKTsKICAgICAgfQogICAgICB0aHJvdyBuZXcgRXJyb3IoYEhUVFAgJHtyZXNwb25zZS5zdGF0dXN9IGZldGNoaW5nICR7dGhpcy51cmx9YCk7CiAgICB9CiAgICBhc3luYyByZWFkRmlsZShvcHRpb25zID0ge30pIHsKICAgICAgbGV0IGVuY29kaW5nOwogICAgICBsZXQgb3B0czsKICAgICAgaWYgKHR5cGVvZiBvcHRpb25zID09PSAic3RyaW5nIikgewogICAgICAgIGVuY29kaW5nID0gb3B0aW9uczsKICAgICAgICBvcHRzID0ge307CiAgICAgIH0gZWxzZSB7CiAgICAgICAgZW5jb2RpbmcgPSBvcHRpb25zLmVuY29kaW5nOwogICAgICAgIG9wdHMgPSBvcHRpb25zOwogICAgICAgIGRlbGV0ZSBvcHRzLmVuY29kaW5nOwogICAgICB9CiAgICAgIGNvbnN0IHsgaGVhZGVycyA9IHt9LCBzaWduYWwsIG92ZXJyaWRlcyA9IHt9IH0gPSBvcHRzOwogICAgICBjb25zdCBhcmdzID0gewogICAgICAgIG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iAgICAgIGxldCBpID0gMDsKICAgICAgY29uc3QgY2h1bmtzID0gW107CiAgICAgIGxldCB0b3RhbFNpemUgPSAwOwogICAgICBsZXQgaW5mbGF0b3I7CiAgICAgIGRvIHsKICAgICAgICBjb25zdCByZW1haW5pbmdJbnB1dCA9IGlucHV0RGF0YS5zdWJhcnJheShwb3MpOwogICAgICAgIGluZmxhdG9yID0gbmV3IGltcG9ydF9wYWtvLkluZmxhdGUoKTsKICAgICAgICAoeyBzdHJtIH0gPSBpbmZsYXRvcik7CiAgICAgICAgaW5mbGF0b3IucHVzaChyZW1haW5pbmdJbnB1dCwgaW1wb3J0X3Bha28uWl9TWU5DX0ZMVVNIKTsKICAgICAgICBpZiAoaW5mbGF0b3IuZXJyKSB7CiAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IoaW5mbGF0b3IubXNnKTsKICAgICAgICB9CiAgICAgICAgcG9zICs9IHN0cm0ubmV4dF9pbjsKICAgICAgICBjaHVua3NbaV0gPSBpbmZsYXRvci5yZXN1bHQ7CiAgICAgICAgdG90YWxTaXplICs9IGNodW5rc1tpXS5sZW5ndGg7CiAgICAgICAgaSArPSAxOwogICAgICB9IHdoaWxlIChzdHJtLmF2YWlsX2luKTsKICAgICAgY29uc3QgcmVzdWx0ID0gbmV3IFVpbnQ4QXJyYXkodG90YWxTaXplKTsKICAgICAgZm9yIChsZXQgaTIgPSAwLCBvZmZzZXQgPSAwOyBpMiA8IGNodW5rcy5sZW5ndGg7IGkyKyspIHsKICAgICAgICByZXN1bHQuc2V0KGNodW5rc1tpMl0sIG9mZnNldCk7CiAgICAgICAgb2Zmc2V0ICs9IGNodW5rc1tpMl0ubGVuZ3RoOwogICAgICB9CiAgICAgIHJldHVybiBpbXBvcnRfYnVmZmVyNC5CdWZmZXIuZnJvbShyZXN1bHQpOwogICAgfSBjYXRjaCAoZSkgewogICAgICBpZiAoYCR7ZX1gLm1hdGNoKC9pbmNvcnJlY3QgaGVhZGVyIGNoZWNrLykpIHsKICAgICAgICB0aHJvdyBuZXcgRXJyb3IoInByb2JsZW0gZGVjb21wcmVzc2luZyBibG9jazogaW5jb3JyZWN0IGd6aXAgaGVhZGVyIGNoZWNrIik7CiAgICAgIH0KICAgICAgdGhyb3cgZTsKICAgIH0KICB9CiAgYXN5bmMgZnVuY3Rpb24gdW56aXBDaHVua1NsaWNlKGlucHV0RGF0YSwgY2h1bmspIHsKICAgIHRyeSB7CiAgICAgIGxldCBzdHJtOwogICAgICBjb25zdCB7IG1pbnYsIG1heHYgfSA9IGNodW5rOwogICAgICBsZXQgY3BvcyA9IG1pbnYuYmxvY2tQb3NpdGlvbjsKICAgICAgbGV0IGRwb3MgPSBtaW52LmRhdGFQb3NpdGlvbjsKICAgICAgY29uc3QgY2h1bmtzID0gW107CiAgICAgIGNvbnN0IGNwb3NpdGlvbnMgPSBbXTsKICAgICAgY29uc3QgZHBvc2l0aW9ucyA9IFtdOwogICAgICBsZXQgdG90YWxTaXplID0gMDsKICAgICAgbGV0IGkgPSAwOwogICAgICBkbyB7CiAgICAgICAgY29uc3QgcmVtYWluaW5nSW5wdXQgPSBpbnB1dERhdGEuc3ViYXJyYXkoY3BvcyAtIG1pbnYuYmxvY2tQb3NpdGlvbik7CiAgICAgICAgY29uc3QgaW5mbGF0b3IgPSBuZXcgaW1wb3J0X3Bha28uSW5mbGF0ZSgpOwogICAgICAgICh7IHN0cm0gfSA9IGluZmxhdG9yKTsKICAgICAgICBpbmZsYXRvci5wdXNoKHJlbWFpbmluZ0lucHV0LCBpbXBvcnRfcGFrby5aX1NZTkNfRkxVU0gpOwogICAgICAgIGlmIChpbmZsYXRvci5lcnIpIHsKICAgICAgICAgIHRocm93IG5ldyBFcnJvcihpbmZsYXRvci5tc2cpOwogICAgICAgIH0KICAgICAgICBjb25zdCBidWZmZXIyID0gaW5mbGF0b3IucmVzdWx0OwogICAgICAgIGNodW5rcy5wdXNoKGJ1ZmZlcjIpOwogICAgICAgIGxldCBsZW4gPSBidWZmZXIyLmxlbmd0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wgYml0cykgewogICAgcmV0dXJuIE1hdGguZmxvb3IobnVtIC8gMiAqKiBiaXRzKTsKICB9CiAgdmFyIENTSSA9IGNsYXNzIGV4dGVuZHMgSW5kZXhGaWxlIHsKICAgIGNvbnN0cnVjdG9yKGFyZ3MpIHsKICAgICAgc3VwZXIoYXJncyk7CiAgICAgIHRoaXMubWF4QmluTnVtYmVyID0gMDsKICAgICAgdGhpcy5kZXB0aCA9IDA7CiAgICAgIHRoaXMubWluU2hpZnQgPSAwOwogICAgfQogICAgYXN5bmMgbGluZUNvdW50KHJlZklkKSB7CiAgICAgIGNvbnN0IGluZGV4RGF0YSA9IGF3YWl0IHRoaXMucGFyc2UoKTsKICAgICAgaWYgKCFpbmRleERhdGEpIHsKICAgICAgICByZXR1cm4gLTE7CiAgICAgIH0KICAgICAgY29uc3QgaWR4ID0gaW5kZXhEYXRhLmluZGljZXNbcmVmSWRdOwogICAgICBpZiAoIWlkeCkgewogICAgICAgIHJldHVybiAtMTsKICAgICAgfQogICAgICBjb25zdCB7IHN0YXRzIH0gPSBpbmRleERhdGEuaW5kaWNlc1tyZWZJZF07CiAgICAgIGlmIChzdGF0cykgewogICAgICAgIHJldHVybiBzdGF0cy5saW5lQ291bnQ7CiAgICAgIH0KICAgICAgcmV0dXJuIC0xOwogICAgfQogICAgYXN5bmMgaW5kZXhDb3YoKSB7CiAgICAgIHJldHVybiBbXTsKICAgIH0KICAgIHBhcnNlQXV4RGF0YShieXRlcywgb2Zmc2V0LCBhdXhMZW5ndGgpIHsKICAgICAgaWYgKGF1eExlbmd0aCA8IDMwKSB7CiAgICAgICAgcmV0dXJuIHt9OwogICAgICB9CiAgICAgIGNvbnN0IGRhdGEgPSB7fTsKICAgICAgZGF0YS5mb3JtYXRGbGFncyA9IGJ5dGVzLnJlYWRJbnQzMkxFKG9mZnNldCk7CiAgICAgIGRhdGEuY29vcmRpbmF0ZVR5cGUgPSBkYXRhLmZvcm1hdEZsYWdzICYgNjU1MzYgPyAiemVyby1iY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0czsKICAgICAgICBmb3IgKGxldCBqID0gMDsgaiA8IGJpbkNvdW50OyBqICs9IDEpIHsKICAgICAgICAgIGNvbnN0IGJpbiA9IGJ5dGVzLnJlYWRVSW50MzJMRShjdXJyT2Zmc2V0KTsKICAgICAgICAgIGlmIChiaW4gPiB0aGlzLm1heEJpbk51bWJlcikgewogICAgICAgICAgICBzdGF0cyA9IHRoaXMucGFyc2VQc2V1ZG9CaW4oYnl0ZXMsIGN1cnJPZmZzZXQgKyA0KTsKICAgICAgICAgICAgY3Vyck9mZnNldCArPSA0ICsgOCArIDQgKyAxNiArIDE2OwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgY29uc3QgbG9mZnNldCA9IGZyb21CeXRlcyhieXRlcywgY3Vyck9mZnNldCArIDQpOwogICAgICAgICAgICB0aGlzLl9maW5kRmlyc3REYXRhKGRhdGEsIGxvZmZzZXQpOwogICAgICAgICAgICBjb25zdCBjaHVua0NvdW50ID0gYnl0ZXMucmVhZEludDMyTEUoY3Vyck9mZnNldCArIDEyKTsKICAgICAgICAgICAgY3Vyck9mZnNldCArPSAxNjsKICAgICAgICAgICAgY29uc3QgY2h1bmtzID0gbmV3IEFycmF5KGNodW5rQ291bnQpOwogICAgICAgICAgICBmb3IgKGxldCBrID0gMDsgayA8IGNodW5rQ291bnQ7IGsgKz0gMSkgewogICAgICAgICAgICAgIGNvbnN0IHUgPSBmcm9tQnl0ZXMoYnl0ZXMsIGN1cnJPZmZzZXQpOwogICAgICAgICAgICAgIGNvbnN0IHYgPSBmcm9tQnl0ZXMoYnl0ZXMsIGN1cnJPZmZzZXQgKyA4KTsKICAgICAgICAgICAgICBjdXJyT2Zmc2V0ICs9IDE2OwogICAgICAgICAgICAgIGNodW5rc1trXSA9IG5ldyBDaHVuayh1LCB2LCBiaW4pOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGJpbkluZGV4W2Jpbl0gPSBjaHVua3M7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGRh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AgICAgZm9yIChsZXQgYyA9IDA7IGMgPCBiaW5DaHVua3MubGVuZ3RoOyArK2MpIHsKICAgICAgICAgICAgICBjaHVua3MucHVzaChuZXcgQ2h1bmsoYmluQ2h1bmtzW2NdLm1pbnYsIGJpbkNodW5rc1tjXS5tYXh2LCBiaW4pKTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgICByZXR1cm4gb3B0aW1pemVDaHVua3MoY2h1bmtzLCBuZXcgVmlydHVhbE9mZnNldCgwLCAwKSk7CiAgICB9CiAgICByZWcyYmlucyhiZWcsIGVuZCkgewogICAgICBiZWcgLT0gMTsKICAgICAgaWYgKGJlZyA8IDEpIHsKICAgICAgICBiZWcgPSAxOwogICAgICB9CiAgICAgIGlmIChlbmQgPiAyICoqIDUwKSB7CiAgICAgICAgZW5kID0gMiAqKiAzNDsKICAgICAgfQogICAgICBlbmQgLT0gMTsKICAgICAgbGV0IGwgPSAwOwogICAgICBsZXQgdCA9IDA7CiAgICAgIGxldCBzID0gdGhpcy5taW5TaGlmdCArIHRoaXMuZGVwdGggKiAzOwogICAgICBjb25zdCBiaW5zID0gW107CiAgICAgIGZvciAoOyBsIDw9IHRoaXMuZGVwdGg7IHMgLT0gMywgdCArPSBsc2hpZnQoMSwgbCAqIDMpLCBsICs9IDEpIHsKICAgICAgICBjb25zdCBiID0gdCArIHJzaGlmdChiZWcsIHMpOwogICAgICAgIGNvbnN0IGUgPSB0ICsgcnNoaWZ0KGVuZCwgcyk7CiAgICAgICAgaWYgKGUgLSBiICsgYmlucy5sZW5ndGggPiB0aGlzLm1heEJpbk51bWJlcikgewogICAgICAgICAgdGhyb3cgbmV3IEVycm9yKGBxdWVyeSAke2JlZ30tJHtlbmR9IGlzIHRvbyBsYXJnZSBmb3IgY3VycmVudCBiaW5uaW5nIHNjaGVtZSAoc2hpZnQgJHt0aGlzLm1pblNoaWZ0fSwgZGVwdGggJHt0aGlzLmRlcHRofSksIHRyeSBhIHNtYW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zaXRpb24iLCAicGFpcl9vcmllbnRhdGlvbiIpOwogICAgICB9CiAgICAgIHRhZ3MgPSB0YWdzLmNvbmNhdCh0aGlzLl90YWdMaXN0IHx8IFtdKTsKICAgICAgT2JqZWN0LmtleXModGhpcy5kYXRhKS5mb3JFYWNoKChrKSA9PiB7CiAgICAgICAgaWYgKGtbMF0gIT09ICJfIiAmJiBrICE9PSAibmV4dF9zZXFfaWQiKSB7CiAgICAgICAgICB0YWdzLnB1c2goayk7CiAgICAgICAgfQogICAgICB9KTsKICAgICAgY29uc3Qgc2VlbiA9IHt9OwogICAgICByZXR1cm4gdGFncy5maWx0ZXIoKHQpID0+IHsKICAgICAgICBpZiAodCBpbiB0aGlzLmRhdGEgJiYgdGhpcy5kYXRhW3RdID09PSB2b2lkIDAgfHwgdCA9PT0gIkNHIiB8fCB0ID09PSAiY2ciKSB7CiAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgfQogICAgICAgIGNvbnN0IGx0ID0gdC50b0xvd2VyQ2FzZSgpOwogICAgICAgIGNvbnN0IHMgPSBzZWVuW2x0XTsKICAgICAgICBzZWVuW2x0XSA9IHRydWU7CiAgICAgICAgcmV0dXJuICFzOwogICAgICB9KTsKICAgIH0KICAgIHBhcmVudCgpIHsKICAgICAgcmV0dXJuIHZvaWQgMDsKICAgIH0KICAgIGNoaWxkcmVuKCkgewogICAgICByZXR1cm4gdGhpcy5nZXQoInN1YmZlYXR1cmVzIik7CiAgICB9CiAgICBpZCgpIHsKICAgICAgcmV0dXJuIHRoaXMuX2lkOwogICAgfQogICAgbXEoKSB7CiAgICAgIGNvbnN0IG1xID0gKHRoaXMuZ2V0KCJfYmluX21xX25sIikgJiA2NTI4MCkgPj4gODsKICAgICAgcmV0dXJuIG1xID09PSAyNTUgPyB2b2lkIDAgOiBtcTsKICAgIH0KICAgIHNjb3JlKCkgewogICAgICByZXR1cm4gdGhpcy5nZXQoIm1xIik7CiAgICB9CiAgICBxdWFsKCkgewogICAgICB2YX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lYWs7CiAgICAgICAgICBjYXNlICJpIjoKICAgICAgICAgICAgdmFsdWUgPSBieXRlQXJyYXkucmVhZEludDMyTEUocCk7CiAgICAgICAgICAgIHAgKz0gNDsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICBjYXNlICJJIjoKICAgICAgICAgICAgdmFsdWUgPSBieXRlQXJyYXkucmVhZFVJbnQzMkxFKHApOwogICAgICAgICAgICBwICs9IDQ7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgY2FzZSAiYyI6CiAgICAgICAgICAgIHZhbHVlID0gYnl0ZUFycmF5LnJlYWRJbnQ4KHApOwogICAgICAgICAgICBwICs9IDE7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgY2FzZSAiQyI6CiAgICAgICAgICAgIHZhbHVlID0gYnl0ZUFycmF5LnJlYWRVSW50OChwKTsKICAgICAgICAgICAgcCArPSAxOwogICAgICAgICAgICBicmVhazsKICAgICAgICAgIGNhc2UgInMiOgogICAgICAgICAgICB2YWx1ZSA9IGJ5dGVBcnJheS5yZWFkSW50MTZMRShwKTsKICAgICAgICAgICAgcCArPSAyOwogICAgICAgICAgICBicmVhazsKICAgICAgICAgIGNhc2UgIlMiOgogICAgICAgICAgICB2YWx1ZSA9IGJ5dGVBcnJheS5yZWFkVUludDE2TEUocCk7CiAgICAgICAgICAgIHAgKz0gMjsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICBjYXNlICJmIjoKICAgICAgICAgICAgdmFsdWUgPSBieXRlQXJyYXkucmVhZEZsb2F0TEUocCk7CiAgICAgICAgICAgIHAgKz0gNDsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICBjYXNlICJaIjoKICAgICAgICAgIGNhc2UgIkgiOgogICAgICAgICAgICB2YWx1ZSA9ICIiOwogICAgICAgICAgICB3aGlsZSAocCA8PSBibG9ja0VuZCkgewogICAgICAgICAgICAgIGNvbnN0IGNjID0gYnl0ZUFycmF5W3ArK107CiAgICAgICAgICAgICAgaWYgKGNjID09PSAwKSB7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgdmFsdWUgKz0gU3RyaW5nLmZyb21DaGFyQ29kZShjYyk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgY2FzZSAiQiI6IHsKICAgICAgICAgICAgdmFsdWUgPSAiIjsKICAgICAgICAgICAgY29uc3QgY2MgPSBieXRlQXJyYXlbcCsrXTsKICAgICAgICAgICAgY29uc3QgQnR5cGUgPSBTdHJpbmcuZnJvbUNoYXJDb2RlKGNjKTsKICAgICAgICAgICAgY29uc3QgbGltaXQgPSBieXRlQXJyYXkucmVhZEludDMyTEUocCk7CiAgICAgICAgICAgIHAgKz0gNDsKICAgICAgICAgICAgaWYgKEJ0eXBlID09PSAiaSIpIHsKICAgICAgICAgICAgICBpZiAodGFnID09PSAiQ0ciKSB7CiAgICAgICAgICAgICAgICBmb3IgKGxldCBrID0gMDsgayA8IGxpbWl0OyBrKyspIHsKICAgICAgICAgICAgICAgICAgY29uc3QgY2lnb3AgPSBieXRlQXJyYXkucmVhZEludDMyTEUocCk7CiAgICAgICAgICAgICAgICAgIGNvbnN0IGxvcCA9IGNpZ29wID4+IDQ7CiAgICAgICAgICAgICAgICAgIGNvbnN0IG9wID0gQ0lHQVJfREVDT0RFUltjaWdvcCAmIDE1XTsKICAgICAgICAgICAgICAgICAgdmFsdWUgKz0gbG9wICsgb3A7CiAgICAgICAgICAgICAgICAgIHAgKz0gNDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgZm9yIChsZXQgayA9IDA7IGsgPCBsaW1pdDsgaysrKSB7CiAgICAgICAgICAgICAgICAgIHZhbHVlICs9IGJ5dGVBcnJheS5yZWFkSW50MzJMRShwKTsKICAgICAgICAgICAgICAgICAgaWYgKGsgKyAxIDwgbGltaXQpIHsKICAgICAgICAgICAgICAgICAgICB2YWx1ZSArPSAiLCI7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgcCArPSA0OwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoQnR5cGUgPT09ICJJIikgewogICAgICAgICAgICAgIGlmICh0YWcgPT09ICJDRyIpIHsKICAgICAgICAgICAgICAgIGZvciAobGV0IGsgPSAwOyBrIDwgbGltaXQ7IGsrKykgewogICAgICAgICAgICAgICAgICBjb25zdCBjaWdvcCA9IGJ5dGVBcnJheS5yZWFkVUludDMyTEUocCk7CiAgICAgICAgICAgICAgICAgIGNvbnN0IGxvcCA9IGNpZ29wID4+IDQ7CiAgICAgICAgICAgICAgICAgIGNvbnN0IG9wID0gQ0lHQVJfREVDT0RFUltjaWdvcCAmIDE1XTsKICAgICAgICAgICAgICAgICAgdmFsdWUgKz0gbG9wICsgb3A7CiAgICAgICAgICAgICAgICAgIHAgKz0gNDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgZm9yIChsZXQgayA9IDA7IGsgPCBsaW1pdDsgaysrKSB7CiAgICAgICAgICAgICAgICAgIHZhbHVlICs9IGJ5dGVBcnJheS5yZWFkVUludDMyTEUocCk7CiAgICAgICAgICAgICAgICAgIGlmIChrICsgMSA8IGxpbWl0KSB7CiAgICAgICAgICAgICAgICAgICAgdmFsdWUgKz0gIiwiOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIHAgKz0gNDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKEJ0eXBlID09PSAicyIpIHsKICAgICAgICAgICAgICBmb3IgKGxldCBrID0gMDsgayA8IGxpbWl0OyBrKyspIHsKICAgICAgICAgICAgICAgIHZhbHVlICs9IGJ5dGVBcnJheS5yZWFkSW50MTZMRShwKTsKICAgICAgICAgICAgICAgIGlmIChrICsgMSA8IGxpbWl0KSB7CiAgICAgICAgICAgICAgICAgIHZhbHVlICs9ICIsIjsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHAgKz0gMjsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKEJ0eXBlID09PSAiUyIpIHsKICAgICAgICAgICAgICBmb3IgKGxldCBrID0gMDsgayA8IGxpbWl0OyBrKyspIHsKICAgICAgICAgICAgICAgIHZhbHVlICs9IGJ5dGVBcnJheS5yZWFkVUludDE2TEUocCk7CiAgICAgICAgICAgICAgICBpZiAoayArIDEgPCBsaW1pdCkgewogICAgICAgICAgICAgICAgICB2YWx1ZSArPSAiLCI7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBwICs9IDI7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChCdHlwZSA9PT0gImMiKSB7CiAgICAgICAgICAgICAgZm9yIChsZXQgayA9IDA7IGsgPCBsaW1pdDsgaysrKSB7CiAgICAgICAgICAgICAgICB2YWx1ZSArPSBieXRlQXJyYXkucmVhZEludDgocCk7CiAgICAgICAgICAgICAgICBpZiAoayArIDEgPCBsaW1pdCkgewogICAgICAgICAgICAgICAgICB2YWx1ZSArPSAiLCI7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBwICs9IDE7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChCdHlwZSA9PT0gIkMiKSB7CiAgICAgICAgICAgICAgZm9yIChsZXQgayA9IDA7IGsgPCBsaW1pdDsgaysrKSB7CiAgICAgICAgICAgICAgICB2YWx1ZSArPSBieXRlQXJyYXkucmVhZFVJbnQ4KHApOwogICAgICAgICAgICAgICAgaWYgKGsgKyAxIDwgbGltaXQpIHsKICAgICAgICAgICAgICAgICAgdmFsdWUgKz0gIiwiOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgcCArPSAxOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoQnR5cGUgPT09ICJmIikgewogICAgICAgICAgICAgIGZvciAobGV0IGsgPSAwOyBrIDwgbGltaXQ7IGsrKykgewogICAgICAgICAgICAgICAgdmFsdWUgKz0gYnl0ZUFycmF5LnJlYWRGbG9hdExFKHApOwogICAgICAgICAgICAgICAgaWYgKGsgKyAxIDwgbGltaXQpIHsKICAgICAgICAgICAgICAgICAgdmFsdWUgKz0gIiwiOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgcCArPSA0OwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBicmVhazsKICAgICAgICAgIH0KICAgICAgICAgIGRlZmF1bHQ6CiAgICAgICAgICAgIGNvbnNvbGUud2FybihgVW5rbm93biBCQU0gdGFnIHR5cGUgJyR7dHlwZX0nLCB0YWdzIG1heSBiZSBpbmNvbXBsZXRlYCk7CiAgICAgICAgICAgIHZhbHVlID0gdm9pZCAwOwogICAgICAgICAgICBwID0gYmxvY2tFbmQ7CiAgICAgICAgfQogICAgICAgIHRoaXMuX3RhZ09mZnNldCA9IHA7CiAgICAgICAgdGhpcy5fdGFnTGlzdC5wdXNoKHRhZyk7CiAgICAgICAgaWYgKGxjVGFnID09PSB0YWdOYW1lKSB7CiAgICAgICAgICByZXR1cm4gdmFsdWU7CiAgICAgICAgfQogICAgICAgIHRoaXMuZGF0YVtsY1RhZ10gPSB2YWx1ZTsKICAgICAgfQogICAgICB0aGlzLl9hbGxUYWdzUGFyc2VkID0gdHJ1ZTsKICAgICAgcmV0dXJuIHZvaWQgMDsKICAgIH0KICAgIF9wYXJzZUFsbFRhZ3MoKSB7CiAgICAgIHRoaXMuX3BhcnNlVGFnKCIiKTsKICAgIH0KICAgIF9wYXJzZUNpZ2FyKGNpZ2FyKSB7CiAgICAgIHJldHVybiBjaWdhci5tYXRjaCgvXGQrXEQvZykubWF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ICAgY2lnb3AgPSBieXRlQXJyYXkucmVhZEludDMyTEUocCk7CiAgICAgICAgbG9wID0gY2lnb3AgPj4gNDsKICAgICAgICBvcCA9IENJR0FSX0RFQ09ERVJbY2lnb3AgJiAxNV07CiAgICAgICAgaWYgKG9wICE9PSAiTiIpIHsKICAgICAgICAgIGNvbnNvbGUud2FybigiQ0cgdGFnIHdpdGggbm8gTiB0YWciKTsKICAgICAgICB9CiAgICAgICAgdGhpcy5kYXRhLmxlbmd0aF9vbl9yZWYgPSBsb3A7CiAgICAgICAgcmV0dXJuIHRoaXMuZ2V0KCJDRyIpOwogICAgICB9IGVsc2UgewogICAgICAgIGZvciAobGV0IGMgPSAwOyBjIDwgbnVtQ2lnYXJPcHM7ICsrYykgewogICAgICAgICAgY2lnb3AgPSBieXRlQXJyYXkucmVhZEludDMyTEUocCk7CiAgICAgICAgICBsb3AgPSBjaWdvcCA+PiA0OwogICAgICAgICAgb3AgPSBDSUdBUl9ERUNPREVSW2NpZ29wICYgMTVdOwogICAgICAgICAgY2lnYXIgKz0gbG9wICsgb3A7CiAgICAgICAgICBpZiAob3AgIT09ICJIIiAmJiBvcCAhPT0gIlMiICYmIG9wICE9PSAiSSIpIHsKICAgICAgICAgICAgbHJlZiArPSBsb3A7CiAgICAgICAgICB9CiAgICAgICAgICBwICs9IDQ7CiAgICAgICAgfQogICAgICAgIHRoaXMuZGF0YS5sZW5ndGhfb25fcmVmID0gbHJlZjsKICAgICAgICByZXR1cm4gY2lnYXI7CiAgICAgIH0KICAgIH0KICAgIF9mbGFncygpIHsKICAgIH0KICAgIGxlbmd0aF9vbl9yZWYoKSB7CiAgICAgIGlmICh0aGlzLmRhdGEubGVuZ3RoX29uX3JlZikgewogICAgICAgIHJldHVybiB0aGlzLmRhdGEubGVuZ3RoX29uX3JlZjsKICAgICAgfSBlbHNlIHsKICAgICAgICB0aGlzLmdldCgiY2lnYXIiKTsKICAgICAgICByZXR1cm4gdGhpcy5kYXRhLmxlbmd0aF9vbl9y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lvbigpIHsKICAgICAgaWYgKCF0aGlzLmlzU2VnbWVudFVubWFwcGVkKCkgJiYgIXRoaXMuaXNNYXRlVW5tYXBwZWQoKSAmJiB0aGlzLl9yZWZJRCA9PT0gdGhpcy5fbmV4dF9yZWZpZCgpKSB7CiAgICAgICAgY29uc3QgczEgPSB0aGlzLmlzUmV2ZXJzZUNvbXBsZW1lbnRlZCgpID8gIlIiIDogIkYiOwogICAgICAgIGNvbnN0IHMyID0gdGhpcy5pc01hdGVSZXZlcnNlQ29tcGxlbWVudGVkKCkgPyAiUiIgOiAiRiI7CiAgICAgICAgbGV0IG8xID0gIiAiOwogICAgICAgIGxldCBvMiA9ICIgIjsKICAgICAgICBpZiAodGhpcy5pc1JlYWQxKCkpIHsKICAgICAgICAgIG8xID0gIjEiOwogICAgICAgICAgbzIgPSAiMiI7CiAgICAgICAgfSBlbHNlIGlmICh0aGlzLmlzUmVhZDIoKSkgewogICAgICAgICAgbzEgPSAiMiI7CiAgICAgICAgICBvMiA9ICIxIjsKICAgICAgICB9CiAgICAgICAgY29uc3QgdG1wID0gW107CiAgICAgICAgY29uc3QgaXNpemUgPSB0aGlzLnRlbXBsYXRlX2xlbmd0aCgpOwogICAgICAgIGlmIChpc2l6ZSA+IDApIHsKICAgICAgICAgIHRtcFswXSA9IHMxOwogICAgICAgICAgdG1wWzFdID0gbzE7CiAgICAgICAgICB0bXBbMl0gPSBzMjsKICAgICAgICAgIHRtcFszXSA9IG8yOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICB0bXBbMl0gPSBzMTsKICAgICAgICAgIHRtcFszXSA9IG8xOwogICAgICAgICAgdG1wWzBdID0gczI7CiAgICAgICAgICB0bXBbMV0gPSBvMjsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHRtcC5qb2luKCIiKTsKICAgICAgfQogICAgICByZXR1cm4gbnVsbDsKICAgIH0KICAgIF9iaW5fbXFfbmwoKSB7CiAgICAgIHJldHVybiB0aGlzLmJ5dGVzLmJ5dGV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Wl0IG9mICR7dGhpcy5mZXRjaFNpemVMaW1pdC50b0xvY2FsZVN0cmluZygpfSBieXRlc2ApOwogICAgICB9CiAgICAgIHlpZWxkKiB0aGlzLl9mZXRjaENodW5rRmVhdHVyZXMoY2h1bmtzLCBjaHJJZCwgbWluLCBtYXgsIG9wdHMpOwogICAgfQogICAgYXN5bmMgKl9mZXRjaENodW5rRmVhdHVyZXMoY2h1bmtzLCBjaHJJZCwgbWluLCBtYXgsIG9wdHMpIHsKICAgICAgY29uc3QgeyB2aWV3QXNQYWlycyA9IGZhbHNlIH0gPSBvcHRzOwogICAgICBjb25zdCBmZWF0cyA9IFtdOwogICAgICBsZXQgZG9uZSA9IGZhbHNlOwogICAgICBmb3IgKGxldCBpID0gMDsgaSA8IGNodW5rcy5sZW5ndGg7IGkrKykgewogICAgICAgIGNvbnN0IGMgPSBjaHVua3NbaV07CiAgICAgICAgY29uc3QgcmVjb3JkcyA9IGF3YWl0IHRoaXMuZmVhdHVyZUNhY2hlLmdldChjLnRvU3RyaW5nKCksIHsKICAgICAgICAgIGNodW5rOiBjLAogICAgICAgICAgb3B0cwogICAgICAgIH0sIG9wdHMuc2lnbmFsKTsKICAgICAgICBjb25zdCByZWNzID0gW107CiAgICAgICAgZm9yIChsZXQgaTIgPSAwOyBpMiA8IHJlY29yZHMubGVuZ3RoOyBpMiArPSAxKSB7CiAgICAgICAgICBjb25zdCBmZWF0dXJlID0gcmVjb3Jkc1tpMl07CiAgICAgICAgICBpZiAoZmVhdHVyZS5zZXFfaWQoKSA9PT0gY2hySWQpIHsKICAgICAgICAgICAgaWYgKGZlYXR1cmUuZ2V0KCJzdGFydCIpID49IG1heCkgewogICAgICAgICAgICAgIGRvbmUgPSB0cnVlOwogICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICB9IGVsc2UgaWYgKGZlYXR1cmUuZ2V0KCJlbmQiKSA+PSBtaW4pIHsKICAgICAgICAgICAgICByZWNzLnB1c2goZmVhdHVyZSk7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZmVhdHMucHVzaChyZWNzKTsKICAgICAgICB5aWVsZCByZWNzOwogICAgICAgIGlmIChkb25lKSB7CiAgICAgICAgICBicmVhazsKICAgICAgICB9CiAgICAgIH0KICAgICAgY2hlY2tBYm9ydFNpZ25hbChvcHRzLnNpZ25hbCk7CiAgICAgIGlmICh2aWV3QXNQYWlycykgewogICAgICAgIHlpZWxkIHRoaXMuZmV0Y2hQYWlycyhjaHJJZCwgZmVhdHMsIG9wdHMpOwogICAgICB9CiAgICB9CiAgICBhc3luYyBmZXRjaFBhaXJzKGNocklkLCBmZWF0cywgb3B0cykgewogICAgICBjb25zdCB7IHBhaXJBY3Jvc3NDaHIgPSBmYWxzZSwgbWF4SW5zZXJ0U2l6ZSA9IDJlNSB9ID0gb3B0czsKICAgICAgY29uc3QgdW5tYXRlZFBhaXJzID0ge307CiAgICAgIGNvbnN0IHJlYWRJZHMgPSB7fTsKICAgICAgZmVhdHMubWFwKChyZXQpID0+IHsKICAgICAgICBjb25zdCByZWFkTmFtZXMgPSB7fTsKICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IHJldC5sZW5ndGg7IGkrKykgewogICAgICAgICAgY29uc3QgbmFtZSA9IHJldFtpXS5uYW1lKCk7CiAgICAgICAgICBjb25zdCBpZCA9IHJldFtpXS5pZCgpOwogICAgICAgICAgaWYgKCFyZWFkTmFtZXNbbmFtZV0pIHsKICAgICAgICAgICAgcmVhZE5hbWVzW25hbWVdID0gMDsKICAgICAgICAgIH0KICAgICAgICAgIHJlYWROYW1lc1tuYW1lXSsrOwogICAgICAgICAgcmVhZElkc1tpZF0gPSAxOwogICAgICAgIH0KICAgICAgICAoMCwgaW1wb3J0X29iamVjdC5kZWZhdWx0KShyZWFkTmFtZXMpLmZvckVhY2goKFtrLCB2XSkgPT4gewogICAgICAgICAgaWYgKHYgPT09IDEpIHsKICAgICAgICAgICAgdW5tYXRlZFBhaXJzW2tdID0g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AgICBwb3MtLTsKICAgICAgICB9CiAgICAgICAgaWYgKGJsb2NrRW5kIDwgYmEubGVuZ3RoKSB7CiAgICAgICAgICBjb25zdCBmZWF0dXJlID0gbmV3IEJhbVJlY29yZCh7CiAgICAgICAgICAgIGJ5dGVzOiB7CiAgICAgICAgICAgICAgYnl0ZUFycmF5OiBiYSwKICAgICAgICAgICAgICBzdGFydDogYmxvY2tTdGFydCwKICAgICAgICAgICAgICBlbmQ6IGJsb2NrRW5kCiAgICAgICAgICAgIH0sCiAgICAgICAgICAgIGZpbGVPZmZzZXQ6IGNwb3NpdGlvbnMgPyBjcG9zaXRpb25zW3Bvc10gKiAoMSA8PCA4KSArIChibG9ja1N0YXJ0IC0gZHBvc2l0aW9uc1twb3NdKSArIGNodW5rLm1pbnYuZGF0YVBvc2l0aW9uICsgMSA6IGltcG9ydF9idWZmZXJfY3JjMzIuZGVmYXVsdC5zaWduZWQoYmEuc2xpY2UoYmxvY2tTdGFydCwgYmxvY2tFbmQpKQogICAgICAgICAgfSk7CiAgICAgICAgICBzaW5rLnB1c2goZmVhdHVyZSk7CiAgICAgICAgICBpZiAodGhpcy55aWVsZFRocmVhZFRpbWUgJiYgK0RhdGUubm93KCkgLSBsYXN0ID4gdGhpcy55aWVsZFRocmVhZFRpbWUpIHsKICAgICAgICAgICAgYXdhaXQgdGltZW91dCgxKTsKICAgICAgICAgICAgbGFzdCA9ICtEYXRlLm5vdygpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBibG9ja1N0YXJ0ID0gYmxvY2tFbmQgKyAxOwogICAgICB9CiAgICAgIHJldHVybiBzaW5rOwogICAgfQogICAgYXN5bmMgaGFzUmVmU2VxKHNlcU5hbWUpIHsKICAgICAgY29uc3QgcmVmSWQgPSB0aGlzLmNoclRvSW5kZXggJiYgdGhpcy5jaHJUb0luZGV4W3NlcU5hbWVdOwogICAgICByZXR1cm4gdGhpcy5pbmRleC5oYXNSZWZTZXEocmVmSWQpOwogICAgfQogICAgYXN5b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ENhY2hlKTsKICAgICAgICB0aGlzLm9sZENhY2hlID0gdGhpcy5jYWNoZTsKICAgICAgICB0aGlzLmNhY2hlID0gbmV3IE1hcCgpOwogICAgICB9CiAgICB9CiAgICBfbW92ZVRvUmVjZW50KGtleSwgaXRlbSkgewogICAgICB0aGlzLm9sZENhY2hlLmRlbGV0ZShrZXkpOwogICAgICB0aGlzLl9zZXQoa2V5LCBpdGVtKTsKICAgIH0KICAgICpfZW50cmllc0FzY2VuZGluZygpIHsKICAgICAgZm9yIChjb25zdCBpdGVtIG9mIHRoaXMub2xkQ2FjaGUpIHsKICAgICAgICBjb25zdCBba2V5LCB2YWx1ZV0gPSBpdGVtOwogICAgICAgIGlmICghdGhpcy5jYWNoZS5oYXMoa2V5KSkgewogICAgICAgICAgY29uc3QgZGVsZXRlZCA9IHRoaXMuX2RlbGV0ZUlmRXhwaXJlZChrZXksIHZhbHVlKTsKICAgICAgICAgIGlmIChkZWxldGVkID09PSBmYWxzZSkgewogICAgICAgICAgICB5aWVsZCBpdGVtOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgICBmb3IgKGNvbnN0IGl0ZW0gb2YgdGhpcy5jYWNoZSkgewogICAgICAgIGNvbnN0IFtrZXksIHZhbHVlXSA9IGl0ZW07CiAgICAgICAgY29uc3QgZGVsZXRlZCA9IHRoaXMuX2RlbGV0ZUlmRXhwaXJlZChrZXksIHZhbHVlKTsKICAgICAgICBpZiAoZGVsZXRlZCA9PT0gZmFsc2UpIHsKICAgICAgICAgIHlpZWxkIGl0ZW07CiAgICAgICAgfQogICAgICB9CiAgICB9CiAgICBnZXQoa2V5KSB7CiAgICAgIGlmICh0aGlzLmNhY2hlLmhhcyhrZXkpKSB7CiAgICAgICAgY29uc3QgaXRlbSA9IHRoaXMuY2FjaGUuZ2V0KGtleSk7CiAgICAgICAgcmV0dXJuIHRoaXMuX2dldEl0ZW1WYWx1ZShrZXksIGl0ZW0pOwogICAgICB9CiAgICAgIGlmICh0aGlzLm9sZENhY2hlLmhhcyhrZXkpKSB7CiAgICAgICAgY29uc3QgaXRlbSA9IHRoaXMub2xkQ2FjaGUuZ2V0KGtleSk7CiAgICAgICAgaWYgKHRoaXMuX2RlbGV0ZUlmRXhwaXJlZChrZXksIGl0ZW0pID09PSBmYWxzZSkgewogICAgICAgICAgdGhpcy5fbW92ZVRvUmVjZW50KGtleSwgaXRlbSk7CiAgICAgICAgICByZXR1cm4gaXRlbS52YWx1ZTsKICAgICAgICB9CiAgICAgIH0KICAgIH0KICAgIHNldChrZXksIHZhbHVlLCB7IG1heEFnZSA9IHRoaXMubWF4QWdlIH0gPSB7fSkgewogICAgICBjb25zdCBleHBpcnkgPSB0eXBlb2YgbWF4QWdlID09PSAibnVtYmVyIiAmJiBtYXhBZ2UgIT09IE51bWJlci5QT1NJVElWRV9JTkZJTklUWSA/IERhdGUubm93KCkgKyBtYXhBZ2UgOiB2b2lkIDA7CiAgICAgIGlmICh0aGlzLmNhY2hlLmhhcyhrZXkpKSB7CiAgICAgICAgdGhpcy5jYWNoZS5zZXQoa2V5LCB7CiAgICAgICAgICB2YWx1ZSwKICAgICAgICAgIGV4cGlyeQogICAgICAgIH0pOwogICAgICB9IGVsc2UgewogICAgICAgIHRoaXMuX3NldChrZXksIHsgdmFsdWUsIGV4cGlyeSB9KTsKICAgICAgfQogICAgICByZXR1cm4gdGhpczsKICAgIH0KICAgIGhhcyhrZXkpIHsKICAgICAgaWYgKHRoaXMuY2FjaGUuaGFzKGtleSkpIHsKICAgICAgICByZXR1cm4gIXRoaXMuX2RlbGV0ZUlmRXhwaXJlZChrZXksIHRoaXMuY2FjaGUuZ2V0KGtleSkpOwogICAgICB9CiAgICAgIGlmICh0aGlzLm9sZENhY2hlLmhhcyhrZXkpKSB7CiAgICAgICAgcmV0dXJuICF0aGlzLl9kZWxldGVJZkV4cGlyZWQoa2V5LCB0aGlzLm9sZENhY2hlLmdldChrZXkpKTsKICAgICAgfQogICAgICByZXR1cm4gZmFsc2U7CiAgICB9CiAgICBwZWVrKGtleSkgewogICAgICBpZiAodGhpcy5jYWNoZS5oYXMoa2V5KSkgewogICAgICAgIHJldHVybiB0aGlzLl9wZWVrKGtleSwgdGhpcy5jYWNoZSk7CiAgICAgIH0KICAgICAgaWYgKHRoaXMub2xkQ2FjaGUuaGFzKGtleSkpIHsKICAgICAgICByZXR1cm4gdGhpcy5fcGVlayhrZXksIHRoaXMub2xkQ2FjaGUpOwogICAgICB9CiAgICB9CiAgICBkZWxldGUoa2V5KSB7CiAgICAgIGNvbnN0IGRlbGV0ZWQgPSB0aGlzLmNhY2hlLmRlbGV0ZShrZXkpOwogICAgICBpZiAoZGVsZXRlZCkgewogICAgICAgIHRoaXMuX3NpemUtLTsKICAgICAgfQogICAgICByZXR1cm4gdGhpcy5vbGRDYWNoZS5kZWxldGUoa2V5KSB8fCBkZWxldGVkOwogICAgfQogICAgY2xlYXIoKSB7CiAgICAgIHRoaXMuY2FjaGUuY2xlYXIoKTsKICAgICAgdGhpcy5vbGRDYWNoZS5jbGVhcigpOwogICAgICB0aGlzLl9zaXplID0gMDsKICAgIH0KICAgIHJlc2l6ZShuZXdTaXplKSB7CiAgICAgIGlmICghKG5ld1NpemUgJiYgbmV3U2l6ZSA+IDApKSB7CiAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcigiYG1heFNpemVgIG11c3QgYmUgYSBudW1iZXIgZ3JlYXRlciB0aGFuIDAiKTsKICAgICAgfQogICAgICBjb25zdCBpdGVtcyA9IFsuLi50aGlzLl9lbnRyaWVzQXNjZW5kaW5nKCldOwogICAgICBjb25zdCByZW1vdmVDb3VudCA9IGl0ZW1zLmxlbmd0aCAtIG5ld1NpemU7CiAgICAgIGlmIChyZW1vdmVDb3VudCA8IDApIHsKICAgICAgICB0aGlzLmNhY2hlID0gbmV3IE1hcChpdGVtcyk7CiAgICAgICAgdGhpcy5vbGRDYWNoZSA9IG5ldyBNYXAoKTsKICAgICAgICB0aGlzLl9zaXplID0gaXRlbXMubGVuZ3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ZWxldGVJZkV4cGlyZWQoa2V5LCB2YWx1ZSk7CiAgICAgICAgICBpZiAoZGVsZXRlZCA9PT0gZmFsc2UpIHsKICAgICAgICAgICAgeWllbGQgW2tleSwgdmFsdWUudmFsdWVdOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgfQogICAgKmVudHJpZXNEZXNjZW5kaW5nKCkgewogICAgICBsZXQgaXRlbXMgPSBbLi4udGhpcy5jYWNoZV07CiAgICAgIGZvciAobGV0IGkgPSBpdGVtcy5sZW5ndGggLSAxOyBpID49IDA7IC0taSkgewogICAgICAgIGNvbnN0IGl0ZW0gPSBpdGVtc1tpXTsKICAgICAgICBjb25zdCBba2V5LCB2YWx1ZV0gPSBpdGVtOwogICAgICAgIGNvbnN0IGRlbGV0ZWQgPSB0aGlzLl9kZWxldGVJZkV4cGlyZWQoa2V5LCB2YWx1ZSk7CiAgICAgICAgaWYgKGRlbGV0ZWQgPT09IGZhbHNlKSB7CiAgICAgICAgICB5aWVsZCBba2V5LCB2YWx1ZS52YWx1ZV07CiAgICAgICAgfQogICAgICB9CiAgICAgIGl0ZW1zID0gWy4uLnRoaXMub2xkQ2FjaGVdOwogICAgICBmb3IgKGxldCBpID0gaXRlbXMubGVuZ3RoIC0gMTsgaSA+PSAwOyAtLWkpIHsKICAgICAgICBjb25zdCBpdGVtID0gaXRlbXNbaV07CiAgICAgICAgY29uc3QgW2tleSwgdmFsdWVdID0gaXRlbTsKICAgICAgICBpZiAoIXRoaXMuY2FjaGUuaGFzKGtleSkpIHsKICAgICAgICAgIGNvbnN0IGRlbGV0ZWQgPSB0aGlzLl9kZWxldGVJZkV4cGlyZWQoa2V5LCB2YWx1ZSk7CiAgICAgICAgICBpZiAoZGVsZXRlZCA9PT0gZmFsc2UpIHsKICAgICAgICAgICAgeWllbGQgW2tleSwgdmFsdWUudmFsdWVdOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgfQogICAgKmVudHJpZXNBc2NlbmRpbmcoKSB7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IGhpID0gbWlkOwogICAgICB9CiAgICAgIHJldHVybiBsbzsKICAgIH0KICAgIGZ1bmN0aW9uIHJpZ2h0KGEsIHgsIGxvLCBoaSkgewogICAgICBpZiAobG8gPT0gbnVsbCkKICAgICAgICBsbyA9IDA7CiAgICAgIGlmIChoaSA9PSBudWxsKQogICAgICAgIGhpID0gYS5sZW5ndGg7CiAgICAgIHdoaWxlIChsbyA8IGhpKSB7CiAgICAgICAgY29uc3QgbWlkID0gbG8gKyBoaSA+Pj4gMTsKICAgICAgICBpZiAoY29tcGFyZShhW21pZF0sIHgpID4gMCkKICAgICAgICAgIGhpID0gbWlkOwogICAgICAgIGVsc2UKICAgICAgICAgIGxvID0gbWlkICsgMTsKICAgICAgfQogICAgICByZXR1cm4gbG87CiAgICB9CiAgICBmdW5jdGlvbiBjZW50ZXIoYSwgeCwgbG8sIGhpKSB7CiAgICAgIGlmIChsbyA9PSBudWxsKQogICAgICAgIGxvID0gMDsKICAgICAgaWYgKGhpID09IG51bGwpCiAgICAgICAgaGkgPSBhLmxlbmd0aDsKICAgICAgY29uc3QgaSA9IGxlZnQoYSwgeCwgbG8sIGhpIC0gMSk7CiAgICAgIHJldHVybiBpID4gbG8gJiYgZGVsdGEoYVtpIC0gMV0sIHgpID4gLWRlbHRhKGFbaV0sIHgpID8gaSAtIDEgOiBpOwogICAgfQogICAgcmV0dXJuIHsgbGVmdCwgY2VudGVyLCByaWdodCB9OwogIH0KICBmdW5jdGlvbiBhc2NlbmRpbmdDb21wYXJhdG9yKGYpIHsKICAgIHJldHVybiAoZCwgeCkgPT4gYXNjZW5kaW5nX2RlZmF1bHQoZihkKSwgeCk7CiAgfQoKICAvLyBzcmMvZGF0YS1mZXRjaGVycy91dGlscy50cwogIHZhciBEYXRhU291cmNlID0gY2xhc3MgewogICAgY29uc3RydWN0b3IoZmlsZSwgY2hyb21TaXplcywgb3B0aW9ucykgewogICAgICB0aGlzLmZpbGUgPSBmaWxlOwogICAgICB0aGlzLm9wdGlvbn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bHNlIHsKICAgICAgICBjdXJyUG9zICs9IGN1cnJOdW07CiAgICAgICAgaWYgKHVzZUNvdW50cykgewogICAgICAgICAgc3Vic3RpdHV0aW9ucy5wdXNoKHsKICAgICAgICAgICAgbGVuZ3RoOiBjdXJyTnVtLAogICAgICAgICAgICB0eXBlOiBtZFN0cmluZ1tpXQogICAgICAgICAgfSk7CiAgICAgICAgfSBlbHNlIGlmIChkZWxldGlvbkVuY291bnRlcmVkKSB7CiAgICAgICAgICBiYW1TZXFTaGlmdCAtPSAxOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBzdWJzdGl0dXRpb25zLnB1c2goewogICAgICAgICAgICBwb3M6IGN1cnJQb3MsCiAgICAgICAgICAgIGJhc2U6IG1kU3RyaW5nW2ldLAogICAgICAgICAgICBsZW5ndGg6IDEsCiAgICAgICAgICAgIGJhbVNlcVNoaWZ0CiAgICAgICAgICB9KTsKICAgICAgICB9CiAgICAgICAgY3Vyck51bSA9IDA7CiAgICAgICAgY3VyclBvcyArPSAxOwogICAgICB9CiAgICB9CiAgICByZXR1cm4gc3Vic3RpdHV0aW9uczsKICB9CiAgZnVuY3Rpb24gZ2V0U3Vic3RpdHV0aW9ucyhzZWdtZW50LCBzZXEpIHsKICAgIGxldCBzdWJzdGl0dXRpb25zID0gW107CiAgICBsZXQgc29mdENsaXBwaW5nQXRSZWFkU3RhcnQgPSBudWxsOwogICAgaWYgKHNlZ21lbnQuY2lnYXIpIHsKICAgICAgY29uc3QgY2lnYXJTdWJzID0gcGFyc2VNRChzZWdtZW50LmNpZ2FyLCB0cnVlKTsKICAgICAgbGV0IGN1cnJQb3MgPSAwOwogICAgICBmb3IgKGNvbnN0IHN1YiBvZiBjaWdhclN1YnMpIHsKICAgICAgICBpZiAoc3ViLnR5cGUgPT09ICJYIikgewogICAgICAgICAgc3Vic3RpdHV0aW9ucy5wdXNoKHsKICAgICAgICAgICAgcG9zOiBjdXJyUG9zLAogICAgICAgICAgICBsZW5ndGg6IHN1Yi5sZW5ndGgsCiAgICAgICAgICAgIHR5cGU6ICJYIgogICAgICAgICAgfSk7CiAgICAgICAgICBjdXJyUG9zICs9IHN1Yi5sZW5ndGg7CiAgICAgICAgfSBlbHNlIGlmIChzdWIudHlwZSA9PT0gIkkiKSB7CiAgICAgICAgICBzdWJzdGl0dXRpb25zLnB1c2goewogICAgICAgICAgICBwb3M6IGN1cnJQb3MsCiAgICAgICAgICAgIGxlbmd0aDogc3ViLmxlbmd0aCwKICAgICAgICAgICAgdHlwZTogIkkiCiAgICAgICAgICB9KTsKICAgICAgICB9IGVsc2UgaWYgKHN1Yi50eXBlID09PSAiRCIpIHsKICAgICAgICAgIHN1YnN0aXR1dGlvbnMucHVzaCh7CiAgICAgICAgICAgIHBvczogY3VyclBvcywKICAgICAgICAgICAgbGVuZ3RoOiBzdWIubGVuZ3RoLAogICAgICAgICAgICB0eXBlOiAiRCIKICAgICAgICAgIH0pOwogICAgICAgICAgY3VyclBvcyArPSBzdWIubGVuZ3RoOwogICAgICAgIH0gZWxzZSBpZiAoc3ViLnR5cGUgPT09ICJOIikgewogICAgICAgICAgc3Vic3RpdHV0aW9ucy5wdXNoKHsKICAgICAgICAgICAgcG9zOiBjdXJyUG9zLAogICAgICAgICAgICBsZW5ndGg6IHN1Yi5sZW5ndGgsCiAgICAgICAgICAgIHR5cGU6ICJOIgogICAgICAgICAgfSk7CiAgICAgICAgICBjdXJyUG9zICs9IHN1Yi5sZW5ndGg7CiAgICAgICAgfSBlbHNlIGlmIChzdWIudHlwZSA9PT0gIj0iIHx8IHN1Yi50eXBlID09PSAiTSIpIHsKICAgICAgICAgIGN1cnJQb3MgKz0gc3ViLmxlbmd0aDsKICAgICAgICB9IGVsc2UgewogICAgICAgIH0KICAgICAgfQogICAgICBjb25zdCBmaXJzdFN1YiA9IGNpZ2FyU3Vic1swXTsKICAgICAgY29uc3QgbGFzdFN1YiA9IGNpZ2FyU3Vic1tjaWdhclN1YnMubGVuZ3RoIC0gMV07CiAgICAgIGlmIChmaXJzdFN1Yi50eXBlID09PSAiUyIpIHsKICAgICAgICBzb2Z0Q2xpcHBpbmdBdFJlYWRTdGFydCA9IGZpcnN0U3ViOwogICAgICAgIHN1YnN0aXR1dGlvbnMucHVzaCh7CiAgICAgICAgICBwb3M6IC1maXJzdFN1Yi5sZW5ndGgsCiAgICAgICAgICB0eXBlOiAiUyIsCiAgICAgICAgICBsZW5ndGg6IGZpcnN0U3ViLmxlbmd0aAogICAgICAgIH0pOwogICAgICB9CiAgICAgIGlmIChsYXN0U3ViLnR5cGUgPT09ICJTIikgewogICAgICAgIHN1YnN0aXR1dGlvbnMucHVzaCh7CiAgICAgICAgICBwb3M6IHNlZ21lbnQuZW5kIC0gc2VnbWVudC5zdGFydCwKICAgICAgICAgIGxlbmd0aDogbGFzdFN1Yi5sZW5ndGgsCiAgICAgICAgICB0eXBlOiAiUyIKICAgICAgICB9KTsKICAgICAgfQogICAgICBpZiAoZmlyc3RTdWIudHlwZSA9PT0gIkgiKSB7CiAgICAgICAgc3Vic3RpdHV0aW9ucy5wdXNoKHsKICAgICAgICAgIHBvczogLWZpcnN0U3ViLmxlbmd0aCwKICAgICAgICAgIHR5cGU6ICJIIiwKICAgICAgICAgIGxlbmd0aDogZmlyc3RTdWIubGVuZ3RoCiAgICAgICAgfSk7CiAgICAgIH0KICAgICAgaWYgKGxhc3RTdWIudHlwZSA9PT0gIkgiKSB7CiAgICAgICAgc3Vic3RpdHV0aW9ucy5wdXNoKHsKICAgICAgICAgIHBvczogc2VnbWVudC5lbmQgLSBzZWdtZW50LnN0YXJ0LAogICAgICAgICAgbGVuZ3RoOiBsYXN0U3ViLmxlbmd0aCwKICAgICAgICAgIHR5cGU6ICJIIgogICAgICAgIH0pOwogICAgICB9CiAgICB9CiAgICBpZiAoc2VnbWVudC5tZCkgewogICAgICBjb25zdCBtZFN1YnN0aXR1dGlvbnMgPSBwYXJzZU1EKHNlZ21lbnQubWQsIGZhbHNlKTsKICAgICAgbWRTdWJzdGl0dX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ICAgICAgICAgIHN2VHlwZSA9ICJub3JtYWwgcmVhZCI7CiAgICAgICAgfSBlbHNlIGlmIChsLnN0cmFuZCA9PT0gIisiICYmIHIuc3RyYW5kID09PSAiLSIpIHsKICAgICAgICAgIHN2VHlwZSA9ICJkZWxldGlvbiAoKy0pIjsKICAgICAgICB9IGVsc2UgaWYgKGwuc3RyYW5kID09PSAiKyIgJiYgci5zdHJhbmQgPT09ICIrIikgewogICAgICAgICAgc3ZUeXBlID0gImludmVyc2lvbiAoKyspIjsKICAgICAgICB9IGVsc2UgaWYgKGwuc3RyYW5kID09PSAiLSIgJiYgci5zdHJhbmQgPT09ICItIikgewogICAgICAgICAgc3ZUeXBlID0gImludmVyc2lvbiAoLS0pIjsKICAgICAgICB9IGVsc2UgaWYgKGwuc3RyYW5kID09PSAiLSIgJiYgci5zdHJhbmQgPT09ICIrIikgewogICAgICAgICAgc3ZUeXBlID0gImR1cGxpY2F0aW9uICgtKykiOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBzdlR5cGUgPSBgKCR7bC5zdHJhbmR9JHtyLnN0cmFuZH0pYDsKICAgICAgICB9CiAgICAgICAgW3JlYWQsIG1hdGVdLmZvckVhY2goKGQpID0+IHsKICAgICAgICAgIGQuZm91bmRNYXRlID0gdHJ1ZTsKICAgICAgICAgIGQuaW5zZXJ0U2l6ZSA9IGluc2VydFNpemU7CiAgICAgICAgICBkLmxhcmdlSW5zZXJ0U2l6ZSA9IGxhcmdlSW5zZXJ0U2l6ZTsKICAgICAgICAgIGQuc3ZUeXBlID0gc3ZUeXBlOwogICAgICAgICAgZC5udW1NYXRlcyA9IDI7CiAgICAgICAgfSk7CiAgICAgIH0gZWxzZSB7CiAgICAgICAgc2VnbWVudEdyb3VwLmZvckVhY2goKGQpID0+IHsKICAgICAgICAgIGQubWF0ZUlkcyA9IHNlZ21lbnRHcm91cC5maWx0ZXIoKG1hdGUpID0+IG1hdGUuaWQgIT09IGQuaWQpLm1hcCgobWF0ZSkgPT4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ZWxzZSB7CiAgICAgICAgICAgIGp1bmN0aW9ucy5wdXNoKHsgc3RhcnQ6IGRvbiwgZW5kOiBhY2MsIHNjb3JlOiAxIH0pOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfSk7CiAgICB9KTsKICAgIHJldHVybiBqdW5jdGlvbnMuZmlsdGVyKChkKSA9PiBkLnNjb3JlID49IG1pbkNvdmVyYWdlKTsKICB9OwogIHZhciB0aWxlRnVuY3Rpb25zID0gewogICAgaW5pdCwKICAgIHRpbGVzZXRJbmZvLAogICAgZmV0Y2hUaWxlc0RlYm91bmNlZCwKICAgIHRpbGUsCiAgICBnZXRUYWJ1bGFyRGF0YQogIH07CiAgZXhwb3NlKHRpbGVGdW5jdGlvbnMpOwp9KSgpOwovKiEKICogVGhlIGJ1ZmZlciBtb2R1bGUgZnJvbSBub2RlLmpzLCBmb3IgdGhlIGJyb3dzZXIuCiAqCiAqIEBhdXRob3IgICBGZXJvc3MgQWJvdWtoYWRpamVoIDxodHRwczovL2Zlcm9zcy5vcmc+CiAqIEBsaWNlbnNlICBNSVQKICovCi8qISBpZWVlNzU0LiBCU0QtMy1DbGF1c2UgTGljZW5zZS4gRmVyb3NzIEFib3VraGFkaWplaCA8aHR0cHM6Ly9mZXJvc3Mub3JnL29wZW5zb3VyY2U+ICovCg==",Ile=typeof window<"u"&&window.Blob&&new Blob([atob(fHe)],{type:"text/javascript;charset=utf-8"});function Xqt(){const g=Ile&&(window.URL||window.webkitURL).createObjectURL(Ile);try{return g?new Worker(g):new Worker("data:application/javascript;base64,"+fHe,{type:"module"})}finally{g&&(window.URL||window.webkitURL).revokeObjectURL(g)}}const Hqt=200;class U2{constructor(e,I){nt(this,"dataConfig",{}),nt(this,"uid"),nt(this,"fetchTimeout"),nt(this,"toFetch"),nt(this,"MAX_TILE_WIDTH",2e4),nt(this,"worker"),nt(this,"track"),this.uid=e.libraries.slugid.nice(),this.toFetch=new Set;const{url:i,indexUrl:n,assembly:C,...r}=I;this.worker=dN(new Xqt).then(async o=>{const A=Object.entries(yI(C).size);return await o.init(this.uid,{url:i,indexUrl:n},A,r),o})}async tilesetInfo(e){(await this.worker).tilesetInfo(this.uid).then(e)}fetchTilesDebounced(e,I){var i;const{toFetch:n}=this,C=I[0].split(".")[0],r=n.size?[...n][0].split(".")[0]:null;if(C!==r){for(const o of this.toFetch)(i=this.track)==null||i.fetching.delete(o);this.toFetch.clear()}I.forEach(o=>this.toFetch.add(o)),this.fetchTimeout&&clearTimeout(this.fetchTimeout),this.fetchTimeout=setTimeout(()=>{this.sendFetch(e,[...this.toFetch]),this.toFetch.clear()},Hqt)}async sendFetch(e,I){(await this.worker).fetchTilesDebounced(this.uid,I).then(e)}async getTabularData(e){const I=await(await this.worker).getTabularData(this.uid,e);return JSON.parse(new TextDecoder().decode(I))}}nt(U2,"config",{type:"bam"});const pHe="KCgpID0+IHsKICB2YXIgX19jcmVhdGUgPSBPYmplY3QuY3JlYXRlOwogIHZhciBfX2RlZlByb3AgPSBPYmplY3QuZGVmaW5lUHJvcGVydHk7CiAgdmFyIF9fZ2V0T3duUHJvcERlc2MgPSBPYmplY3QuZ2V0T3duUHJvcGVydHlEZXNjcmlwdG9yOwogIHZhciBfX2dldE93blByb3BOYW1lcyA9IE9iamVjdC5nZXRPd25Qcm9wZXJ0eU5hbWVzOwogIHZhciBfX2dldFByb3RvT2YgPSBPYmplY3QuZ2V0UHJvdG90eXBlT2Y7CiAgdmFyIF9faGFzT3duUHJvcCA9IE9iamVjdC5wcm90b3R5cGUuaGFzT3duUHJvcGVydHk7CiAgdmFyIF9fbWFya0FzTW9kdWxlID0gKHRhcmdldCkgPT4gX19kZWZQcm9wKHRhcmdldCwgIl9fZXNNb2R1bGUiLCB7IHZhbHVlOiB0cnVlIH0pOwogIHZhciBfX2VzbSA9IChmbiwgcmVzKSA9PiBmdW5jdGlvbiBfX2luaXQoKSB7CiAgICByZXR1cm4gZm4gJiYgKHJlcyA9ICgwLCBmbltPYmplY3Qua2V5cyhmbilbMF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rK10gPSB0bXAgJiAyNTU7CiAgICAgICAgfQogICAgICAgIGlmIChwbGFjZUhvbGRlcnNMZW4gPT09IDEpIHsKICAgICAgICAgIHRtcCA9IHJldkxvb2t1cFtiNjQuY2hhckNvZGVBdChpMildIDw8IDEwIHwgcmV2TG9va3VwW2I2NC5jaGFyQ29kZUF0KGkyICsgMSldIDw8IDQgfCByZXZMb29rdXBbYjY0LmNoYXJDb2RlQXQoaTIgKyAyKV0gPj4gMjsKICAgICAgICAgIGFycltjdXJCeXRlKytdID0gdG1wID4+IDggJiAyNTU7CiAgICAgICAgICBhcnJbY3VyQnl0ZSsrXSA9IHRtcCAmIDI1NTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIGFycjsKICAgICAgfQogICAgICBmdW5jdGlvbiB0cmlwbGV0VG9CYXNlNjQobnVtKSB7CiAgICAgICAgcmV0dXJuIGxvb2t1cFtudW0gPj4gMTggJiA2M10gKyBsb29rdXBbbnVtID4+IDEyICYgNjNdICsgbG9va3VwW251bSA+PiA2ICYgNjNdICsgbG9va3VwW251bSAmIDYzXTsKICAgICAgfQogICAgICBmdW5jdGlvbiBlbmNvZGVDaHVuayh1aW50OCwgc3RhcnQsIGVuZCkgewogICAgICAgIHZhciB0bXA7CiAgICAgICAgdmFyIG91dHB1dCA9IFtdOwogICAgICAgIGZvciAodmFyIGkyID0gc3RhcnQ7IGkyIDwgZW5kOyBpMiArPSAzKSB7CiAgICAgICAgICB0bXAgPSAodWludDhbaTJdIDw8IDE2ICYgMTY3MTE2ODApICsgKHVpbnQ4W2kyICsgMV0gPDwgOCAmIDY1MjgwKSArICh1aW50OFtpMiArIDJdICYgMjU1KTsKICAgICAgICAgIG91dHB1dC5wdXNoKHRyaXBsZXRUb0Jhc2U2NCh0bXApKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIG91dHB1dC5qb2luKCIiKTsKICAgICAgfQogICAgICBmdW5jdGlvbiBmcm9tQnl0ZUFycmF5KHVpbnQ4KSB7CiAgICAgIC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25KUyh7CiAgICAibm9kZV9tb2R1bGVzLy5wbnBtL2llZWU3NTRAMS4yLjEvbm9kZV9tb2R1bGVzL2llZWU3NTQvaW5kZXguanMiKGV4cG9ydHMyKSB7CiAgICAgIGluaXRfYnVmZmVyX3NoaW0oKTsKICAgICAgZXhwb3J0czIucmVhZCA9IGZ1bmN0aW9uKGJ1ZmZlciwgb2Zmc2V0LCBpc0xFLCBtTGVuLCBuQnl0ZXMpIHsKICAgICAgICB2YXIgZSwgbTsKICAgICAgICB2YXIgZUxlbiA9IG5CeXRlcyAqIDggLSBtTGVuIC0gMTsKICAgICAgICB2YXIgZU1heCA9ICgxIDw8IGVMZW4pIC0gMTsKICAgICAgICB2YXIgZUJpYXMgPSBlTWF4ID4+IDE7CiAgICAgICAgdmFyIG5CaXRzID0gLTc7CiAgICAgICAgdmFyIGkgPSBpc0xFID8gbkJ5dGVzIC0gMSA6IDA7CiAgICAgICAgdmFyIGQgPSBpc0xFID8gLTEgOiAxOwogICAgICAgIHZhciBzID0gYnVmZmVyW29mZnNldCArIGldOwogICAgICAgIGkgKz0gZDsKICAgICAgICBlID0gcyAmICgxIDw8IC1uQml0cykgLSAxOwogICAgICAgIHMgPj49IC1uQml0czsKICAgICAgICBuQml0cyArPSBlTGVuOwogICAgICAgIGZvciAoOyBuQml0cyA+IDA7IGUgPSBlICogMjU2ICsgYnVmZmVyW29mZnNldCArIGldLCBpICs9IGQsIG5CaXRzIC09IDgpIHsKICAgICAgICB9CiAgICAgICAgbSA9IGUgJiAoMSA8PCAtbkJpdHMpIC0gMTsKICAgICAgICBlID4+PSAtbkJpdHM7CiAgICAgICAgbkJpdHMgKz0gbUxlbjsKICAgICAgICBmb3IgKDsgbkJpdHMgPiAwOyBtID0gbSAqIDI1NiArIGJ1ZmZlcltvZmZzZXQgKyBpXSwgaSArPSBkLCBuQml0cyAtPSA4KSB7CiAgICAgICAgfQogICAgICAgIGlmIChlID09PSAwKSB7CiAgICAgICAgICBlID0gMSAtIGVCaWFz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YXRoLmxvZyh2YWx1ZSkgLyBNYXRoLkxOMik7CiAgICAgICAgICBpZiAodmFsdWUgKiAoYyA9IE1hdGgucG93KDIsIC1lKSkgPCAxKSB7CiAgICAgICAgICAgIGUtLTsKICAgICAgICAgICAgYyAqPSAyOwogICAgICAgICAgfQogICAgICAgICAgaWYgKGUgKyBlQmlhcyA+PSAxKSB7CiAgICAgICAgICAgIHZhbHVlICs9IHJ0IC8gYzsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHZhbHVlICs9IHJ0ICogTWF0aC5wb3coMiwgMSAtIGVCaWFzKTsKICAgICAgICAgIH0KICAgICAgICAgIGlmICh2YWx1ZSAqIGMgPj0gMikgewogICAgICAgICAgICBlKys7CiAgICAgICAgICAgIGMgLz0gMjsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChlICsgZUJpYXMgPj0gZU1heCkgewogICAgICAgICAgICBtID0gMDsKICAgICAgICAgICAgZSA9IGVNYXg7CiAgICAgICAgICB9IGVsc2UgaWYgKGUgKyBlQmlhcyA+PSAxKSB7CiAgICAgICAgICAgIG0gPSAodmFsdWUgKiBjIC0gMSkgKiBNYXRoLnBvdygyLCBtTGVuKTsKICAgICAgICAgICAgZSA9IGUgKyBlQmlhczsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIG0gPSB2YWx1ZSAqIE1hdGgucG93KDIsIGVCaWFzIC0gMSkgKiBNYXRoLnBvdygyLCBtTGVuKTsKICAgICAgICAgICAgZSA9IDA7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGZvciAoOyBtTGVuID49IDg7IGJ1ZmZlcltvZmZzZXQgKyBpXSA9IG0gJiAyNTUsIGkgKz0gZCwgbSAvPSAyNTYsIG1MZW4gLT0gOCkgewogICAgICAgIH0KICAgICAgICBlID0gZSA8PCBtTGVuIHwgbTsKICAgICAgICBlTGVuICs9IG1MZW47CiAgICAgICAgZm9yICg7IGVMZW4gPiAwOyBidWZmZXJbb2Zmc2V0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ydCgpOwogICAgICBpZiAoIUJ1ZmZlcjEwLlRZUEVEX0FSUkFZX1NVUFBPUlQgJiYgdHlwZW9mIGNvbnNvbGUgIT09ICJ1bmRlZmluZWQiICYmIHR5cGVvZiBjb25zb2xlLmVycm9yID09PSAiZnVuY3Rpb24iKSB7CiAgICAgICAgY29uc29sZS5lcnJvcigiVGhpcyBicm93c2VyIGxhY2tzIHR5cGVkIGFycmF5IChVaW50OEFycmF5KSBzdXBwb3J0IHdoaWNoIGlzIHJlcXVpcmVkIGJ5IGBidWZmZXJgIHY1LnguIFVzZSBgYnVmZmVyYCB2NC54IGlmIHlvdSByZXF1aXJlIG9sZCBicm93c2VyIHN1cHBvcnQuIik7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gdHlwZWRBcnJheVN1cHBvcnQoKSB7CiAgICAgICAgdHJ5IHsKICAgICAgICAgIGNvbnN0IGFyciA9IG5ldyBVaW50OEFycmF5KDEpOwogICAgICAgICAgY29uc3QgcHJvdG8gPSB7IGZvbzogZnVuY3Rpb24oKSB7CiAgICAgICAgICAgIHJldHVybiA0MjsKICAgICAgICAgIH0gfTsKICAgICAgICAgIE9iamVjdC5zZXRQcm90b3R5cGVPZihwcm90bywgVWludDhBcnJheS5wcm90b3R5cGUpOwogICAgICAgICAgT2JqZWN0LnNldFByb3RvdHlwZU9mKGFyciwgcHJvdG8pOwogICAgICAgICAgcmV0dXJuIGFyci5mb28oKSA9PT0gNDI7CiAgICAgICAgfSBjYXRjaCAoZSkgewogICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICAgIH0KICAgICAgfQogICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkoQnVmZmVyMTAucHJvdG90eXBlLCAicGFyZW50IiwgewogICAgICAgIGVudW1lcmFibGU6IHRydWUsCiAgICAgICAgZ2V0OiBmdW5jdGlvbigpIHsKICAgICAgICAgIGlmICghQnVmZmVyMTAuaXNCdWZmZXIodGhpcykpCiAgICAgICAgICAgIHJldHVybiB2b2lkIDA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gKGFbaV0gIT09IGJbaV0pIHsKICAgICAgICAgICAgeCA9IGFbaV07CiAgICAgICAgICAgIHkgPSBiW2ldOwogICAgICAgICAgICBicmVhazsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKHggPCB5KQogICAgICAgICAgcmV0dXJuIC0xOwogICAgICAgIGlmICh5IDwgeCkKICAgICAgICAgIHJldHVybiAxOwogICAgICAgIHJldHVybiAwOwogICAgICB9OwogICAgICBCdWZmZXIxMC5pc0VuY29kaW5nID0gZnVuY3Rpb24gaXNFbmNvZGluZyhlbmNvZGluZykgewogICAgICAgIHN3aXRjaCAoU3RyaW5nKGVuY29kaW5nKS50b0xvd2VyQ2FzZSgpKSB7CiAgICAgICAgICBjYXNlICJoZXgiOgogICAgICAgICAgY2FzZSAidXRmOCI6CiAgICAgICAgICBjYXNlICJ1dGYtOCI6CiAgICAgICAgICBjYXNlICJhc2NpaSI6CiAgICAgICAgICBjYXNlICJsYXRpbjEiOgogICAgICAgICAgY2FzZSAiYmluYXJ5IjoKICAgICAgICAgIGNhc2UgImJhc2U2NCI6CiAgICAgICAgICBjYXNlICJ1Y3MyIjoKICAgICAgICAgIGNhc2UgInVjcy0yIjoKICAgICAgICAgIGNhc2UgInV0ZjE2bGUiOgogICAgICAgICAgY2FzZSAidXRmLTE2bGUiOgogICAgICAgICAgICByZXR1cm4gdHJ1ZTsKICAgICAgICAgIGRlZmF1bHQ6CiAgICAgICAgICAgIHJldHVybiBmYWxzZTsKICAgICAgICB9CiAgICAgIH07CiAgICAgIEJ1ZmZlcjEwLmNvbmNhdCA9IGZ1bmN0aW9uIGNvbmNhdChsaXN0LCBsZW5ndGgpIHsKICAgICAgICBpZiAoIUFycmF5LmlzQXJyYXkobGlzdCkpIHsKICAgICAgICAgIHRocm93IG5ldyBUeXBlRXJyb3IoJyJsaXN0IiBhcmd1bWVudCBtdXN0IGJlIGFuIEFycmF5IG9mIEJ1ZmZlcnMnKTsKICAgICAgICB9CiAgICAgICAgaWYgKGxpc3QubGVuZ3RoID09PSAwKSB7CiAgICAgICAgICByZXR1cm4gQnVmZmVyMTAuYWxsb2MoMCk7CiAgICAgICAgfQogICAgICAgIGxldCBpOwogICAgICAgIGlmIChsZW5ndGggPT09IHZvaWQgMCkgewogICAgICAgICAgbGVuZ3RoID0gMDsKICAgICAgICAgIGZvciAoaSA9IDA7IGkgPCBsaXN0Lmxlbmd0aDsgKytpKSB7CiAgICAgICAgICAgIGxlbmd0aCArPSBsaXN0W2ldLmxlbmd0aDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgY29uc3QgYnVmZmVyID0gQnVmZmVyMTAuYWxsb2NVbnNhZmUobGVuZ3RoKTsKICAgICAgICBsZXQgcG9zID0gMDsKICAgICAgICBmb3IgKGkgPSAwOyBpIDwgbGlzdC5sZW5ndGg7ICsraSkgewogICAgICAgICAgbGV0IGJ1ZiA9IGxpc3RbaV07CiAgICAgICAgICBpZiAoaXNJbnN0YW5jZShidWYsIFVpbnQ4QXJyYXkpKSB7CiAgICAgICAgICAgIGlmIChwb3MgKyBidWYubGVuZ3RoID4gYnVmZmVyLmxlbmd0aCkgewogICAgICAgICAgICAgIGlmICghQnVmZmVyMTAuaXNCdWZmZXIoYnVmKSkKICAgICAgICAgICAgICAgIGJ1ZiA9IEJ1ZmZlcjEwLmZyb20oYnVmKTsKICAgICAgICAgICAgICBidWYuY29weShidWZmZXIsIHBvcyk7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgVWludDhBcnJheS5wcm90b3R5cGUuc2V0LmNhbGwoYnVmZmVyLCBidWYsIHBvcyk7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSBpZiAoIUJ1ZmZlcjEwLmlzQnVmZmVyKGJ1ZikpIHsKICAgICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcignImxpc3QiIGFyZ3VtZW50IG11c3QgYmUgYW4gQXJyYXkgb2YgQnVmZmVycycpOwogICAgICAgICAgfSBlbH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kiOgogICAgICAgICAgICBjYXNlICJsYXRpbjEiOgogICAgICAgICAgICBjYXNlICJiaW5hcnkiOgogICAgICAgICAgICAgIHJldHVybiBsZW47CiAgICAgICAgICAgIGNhc2UgInV0ZjgiOgogICAgICAgICAgICBjYXNlICJ1dGYtOCI6CiAgICAgICAgICAgICAgcmV0dXJuIHV0ZjhUb0J5dGVzKHN0cmluZykubGVuZ3RoOwogICAgICAgICAgICBjYXNlICJ1Y3MyIjoKICAgICAgICAgICAgY2FzZSAidWNzLTIiOgogICAgICAgICAgICBjYXNlICJ1dGYxNmxlIjoKICAgICAgICAgICAgY2FzZSAidXRmLTE2bGUiOgogICAgICAgICAgICAgIHJldHVybiBsZW4gKiAyOwogICAgICAgICAgICBjYXNlICJoZXgiOgogICAgICAgICAgICAgIHJldHVybiBsZW4gPj4+IDE7CiAgICAgICAgICAgIGNhc2UgImJhc2U2NCI6CiAgICAgICAgICAgICAgcmV0dXJuIGJhc2U2NFRvQnl0ZXMoc3RyaW5nKS5sZW5ndGg7CiAgICAgICAgICAgIGRlZmF1bHQ6CiAgICAgICAgICAgICAgaWYgKGxvd2VyZWRDYXNlKSB7CiAgICAgICAgICAgICAgICByZXR1cm4gbXVzdE1hdGNoID8gLTEgOiB1dGY4VG9CeXRlcyhzdHJpbmcpLmxlbmd0aDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgZW5jb2RpbmcgPSAoIiIgKyBlbmNvZGluZykudG9Mb3dlckNhc2UoKTsKICAgICAgICAgICAgICBsb3dlcmVkQ2FzZSA9IHRydWU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9CiAgICAgIEJ1ZmZlcjEwLmJ5dGVMZW5ndGggPSBieXRlTGVuZ3RoOwogICAgICBmdW5jdGlvbiBzbG93VG9TdHJpbmcoZW5jb2RpbmcsIHN0YXJ0LCBlbmQpIHsKICAgICAgICBsZXQgbG93ZXJlZENhc2UgPSBmYWxzZTsKICAgICAgICBpZiAoc3RhcnQgPT09IHZvaWQgMCB8fCBzdGFydCA8IDApIHsKICAgICAgICAgIHN0YXJ0ID0gMDsKICAgICAgICB9CiAgICAgICAgaWYgKHN0YXJ0ID4gdGhpcy5sZW5ndGgpIHsKICAgICAgICAgIHJldHVybiAiIjsKICAgICAgICB9CiAgICAgICAgaWYgKGVuZCA9PT0gdm9pZCAwIHx8IGVuZCA+IHRoaXMubGVuZ3RoKSB7CiAgICAgICAgICBlbmQgPSB0aGlzLmxlbmd0aDsKICAgICAgICB9CiAgICAgICAgaWYgKGVuZCA8PSAwKSB7CiAgICAgICAgICByZXR1cm4gIiI7CiAgICAgICAgfQogICAgICAgIGVuZCA+Pj49IDA7CiAgICAgICAgc3RhcnQgPj4+PSAwOwogICAgICAgIGlmIChlbmQgPD0gc3RhcnQpIHsKICAgICAgICAgIHJldHVybiAiIjsKICAgICAgICB9CiAgICAgICAgaWYgKCFlbmNvZGluZykKICAgICAgICAgIGVuY29kaW5nID0gInV0ZjgiOwogICAgICAgIHdoaWxlICh0cnVlKSB7CiAgICAgICAgICBzd2l0Y2ggKGVuY29kaW5nKSB7CiAgICAgICAgICAgIGNhc2UgImhleCI6CiAgICAgICAgICAgICAgcmV0dXJuIGhleFNsaWNlKHRoaXMsIHN0YXJ0LCBlbmQpOwogICAgICAgICAgICBjYXNlICJ1dGY4IjoKICAgICAgICAgICAgY2FzZSAidXRmLTgiOgogICAgICAgICAgICAgIHJldHVybiB1dGY4U2xpY2UodGhpcywgc3RhcnQsIGVuZCk7CiAgICAgICAgICAgIGNhc2UgImFzY2lpIjoKICAgICAgICAgICAgICByZXR1cm4gYXNjaWlTbGljZSh0aGlzLCBzdGFydCwgZW5kKTsKICAgICAgICAgICAgY2FzZSAibGF0aW4xIjoKICAgICAgICAgICAgY2FzZSAiYmluYXJ5IjoKICAgICAgICAgICAgICByZXR1cm4gbGF0aW4xU2xpY2UodGhpcywgc3RhcnQsIGVuZCk7CiAgICAgICAgICAgIGNhc2UgImJhc2U2NCI6CiAgICAgICAgICAgICAgcmV0dXJuIGJhc2U2NFNsaWNlKHRoaXMsIHN0YXJ0LCBlbmQpOwogICAgICAgICAgICBjYXNlICJ1Y3MyIjoKICAgICAgICAgICAgY2FzZSAidWNzLTIiOgogICAgICAgICAgICBjYXNlICJ1dGYxNmxlIjoKICAgICAgICAgICAgY2FzZSAidXRmLTE2bGUiOgogICAgICAgICAgICAgIHJldHVybiB1dGYxNmxlU2xpY2UodGhpcywgc3RhcnQsIGVuZCk7CiAgICAgICAgICAgIGRlZmF1bHQ6CiAgICAgICAgICAgICAgaWYgKGxvd2VyZWRDYXNlKQogICAgICAgICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcigiVW5rbm93biBlbmNvZGluZzogIiArIGVuY29kaW5nKTsKICAgICAgICAgICAgICBlbmNvZGluZyA9IChlbmNvZGluZyArICIiKS50b0xvd2VyQ2FzZSgpOwogICAgICAgICAgICAgIGxvd2VyZWRDYXNlID0gdHJ1ZTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgICAgQnVmZmVyMTAucHJvdG90eXBlLl9pc0J1ZmZlciA9IHRydWU7CiAgICAgIGZ1bmN0aW9uIHN3YXAoYiwgbiwgbSkgewogICAgICAgIGNvbnN0IGkgPSBiW25dOwogICAgICAgIGJbbl0gPSBiW21dOwogICAgICAgIGJbbV0gPSBpOwogICAgICB9CiAgICAgIEJ1ZmZlcjEwLnByb3RvdHlwZS5zd2FwMTYgPSBmdW5jdGlvbiBzd2FwMTYoKSB7CiAgICAgICAgY29uc3QgbGVuID0gdGhpcy5sZW5ndGg7CiAgICAgICAgaWYgKGxlbiAlIDIgIT09IDApIHsKICAgICAgICAgIHRocm93IG5ldyBSYW5nZUVycm9yKCJCdWZmZXIgc2l6ZSBtdXN0IGJlIGEgbXVsdGlwbGUgb2YgMTYtYml0cyIpOwogICAgICAgIH0KICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IGxlbjsgaSArPSAyKSB7CiAgICAgICAgICBzd2FwKHRoaXMs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7CiAgICAgICAgICAgIHggPSB0aGlzQ29weVtpXTsKICAgICAgICAgICAgeSA9IHRhcmdldENvcHlbaV07CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAoeCA8IHkpCiAgICAgICAgICByZXR1cm4gLTE7CiAgICAgICAgaWYgKHkgPCB4KQogICAgICAgICAgcmV0dXJuIDE7CiAgICAgICAgcmV0dXJuIDA7CiAgICAgIH07CiAgICAgIGZ1bmN0aW9uIGJpZGlyZWN0aW9uYWxJbmRleE9mKGJ1ZmZlciwgdmFsLCBieXRlT2Zmc2V0LCBlbmNvZGluZywgZGlyKSB7CiAgICAgICAgaWYgKGJ1ZmZlci5sZW5ndGggPT09IDApCiAgICAgICAgICByZXR1cm4gLTE7CiAgICAgICAgaWYgKHR5cGVvZiBieXRlT2Zmc2V0ID09PSAic3RyaW5nIikgewogICAgICAgICAgZW5jb2RpbmcgPSBieXRlT2Zmc2V0OwogICAgICAgICAgYnl0ZU9mZnNldCA9IDA7CiAgICAgICAgfSBlbHNlIGlmIChieXRlT2Zmc2V0ID4gMjE0NzQ4MzY0NykgewogICAgICAgICAgYnl0ZU9mZnNldCA9IDIxNDc0ODM2NDc7CiAgICAgICAgfSBlbHNlIGlmIChieXRlT2Zmc2V0IDwgLTIxNDc0ODM2NDgpIHsKICAgICAgICAgIGJ5dGVPZmZzZXQgPSAtMjE0NzQ4MzY0ODsKICAgICAgICB9CiAgICAgICAgYnl0ZU9mZnNldCA9ICtieXRlT2Zmc2V0OwogICAgICAgIGlmIChudW1iZXJJc05hTihieXRlT2Zmc2V0KSkgewogICAgICAgICAgYnl0ZU9mZnNldCA9IGRpciA/IDAgOiBidWZmZXIubGVuZ3RoIC0gMTsKICAgICAgICB9CiAgICAgICAgaWYgKGJ5dGVPZmZzZXQgPCAwKQogICAgICAgICAgYnl0ZU9mZnNldCA9IGJ1ZmZlci5sZW5ndGggKyBieXRlT2Zmc2V0OwogICAgICAgIGlmIChieXRlT2Zmc2V0ID49IGJ1ZmZlci5sZW5ndGgpIHsKICAgICAgICAgIGlmIChkaXIpCiAgICAgICAgICAgIHJldHVybiAtMTsKICAgICAgICAgIGVsc2UKICAgICAgICAgICAgYnl0ZU9mZnNldCA9IGJ1ZmZlci5sZW5ndGggLSAxOwogICAgICAgIH0gZWxzZSBpZiAoYnl0ZU9mZnNldCA8IDApIHsKICAgICAgICAgIGlmIChkaXIpCiAgICAgICAgICAgIGJ5dGVPZmZzZXQgPSAwOwogICAgICAgICAgZWxzZQogICAgICAgICAgICByZXR1cm4gLTE7CiAgICAgICAgfQogICAgICAgIGlmICh0eXBlb2YgdmFsID09PSAic3RyaW5nIikgewogICAgICAgICAgdmFsID0gQnVmZmVyMTAuZnJvbSh2YWwsIGVuY29kaW5nKTsKICAgICAgICB9CiAgICAgICAgaWYgKEJ1ZmZlcjEwLmlzQnVmZmVyKHZhbCkpIHsKICAgICAgICAgIGlmICh2YWwubGVuZ3RoID09PSAwKSB7CiAgICAgICAgICAgIHJldHVybiAtMTsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBhcnJheUluZGV4T2YoYnVmZmVyLCB2YWwsIGJ5dGVPZmZzZXQsIGVuY29kaW5nLCBkaXIpOwogICAgICAgIH0gZWxzZSBpZiAodHlwZW9mIHZhbCA9PT0gIm51bWJlciIpIHsKICAgICAgICAgIHZhbCA9IHZhbCAmIDI1NTsKICAgICAgICAgIGlmICh0eXBlb2YgVWludDhBcnJheS5wcm90b3R5cGUuaW5kZXhPZiA9PT0gImZ1bmN0aW9uIikgewogICAgICAgICAgICBpZiAoZGlyKSB7CiAgICAgICAgICAgICAgcmV0dXJuIFVpbnQ4QXJyYXkucHJvdG90eXBlLmluZGV4T2YuY2FsbChidWZmZXIsIHZhbCwgYnl0ZU9mZnNldCk7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgcmV0dXJuIFVpbnQ4QXJyYXkucHJvdG90eXBlLmxhc3RJbmRleE9mLmN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ICAgICAgICBpZiAoaW5kZXhTaXplID09PSAxKSB7CiAgICAgICAgICAgIHJldHVybiBidWZbaTJdOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcmV0dXJuIGJ1Zi5yZWFkVUludDE2QkUoaTIgKiBpbmRleFNpemUpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBsZXQgaTsKICAgICAgICBpZiAoZGlyKSB7CiAgICAgICAgICBsZXQgZm91bmRJbmRleCA9IC0xOwogICAgICAgICAgZm9yIChpID0gYnl0ZU9mZnNldDsgaSA8IGFyckxlbmd0aDsgaSsrKSB7CiAgICAgICAgICAgIGlmIChyZWFkKGFyciwgaSkgPT09IHJlYWQodmFsLCBmb3VuZEluZGV4ID09PSAtMSA/IDAgOiBpIC0gZm91bmRJbmRleCkpIHsKICAgICAgICAgICAgICBpZiAoZm91bmRJbmRleCA9PT0gLTEpCiAgICAgICAgICAgICAgICBmb3VuZEluZGV4ID0gaTsKICAgICAgICAgICAgICBpZiAoaSAtIGZvdW5kSW5kZXggKyAxID09PSB2YWxMZW5ndGgpCiAgICAgICAgICAgICAgICByZXR1cm4gZm91bmRJbmRleCAqIGluZGV4U2l6ZTsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICBpZiAoZm91bmRJbmRleCAhPT0gLTEpCiAgICAgICAgICAgICAgICBpIC09IGkgLSBmb3VuZEluZGV4OwogICAgICAgICAgICAgIGZvdW5kSW5kZXggPSAtMTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBpZiAoYnl0ZU9mZnNldCArIHZhbExlbmd0aCA+IGFyckxlbmd0aCkKICAgICAgICAgICAgYnl0ZU9mZnNldCA9IGFyckxlbmd0aCAtIHZhbExlbmd0aDsKICAgICAgICAgIGZvciAoaSA9IGJ5dGVPZmZzZXQ7IGkgPj0gMDsgaS0tKSB7CiAgICAgICAgICAgIGxldCBmb3VuZCA9IHRydWU7CiAgICAgICA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zZXQgPSBOdW1iZXIob2Zmc2V0KSB8fCAwOwogICAgICAgIGNvbnN0IHJlbWFpbmluZyA9IGJ1Zi5sZW5ndGggLSBvZmZzZXQ7CiAgICAgICAgaWYgKCFsZW5ndGgpIHsKICAgICAgICAgIGxlbmd0aCA9IHJlbWFpbmluZzsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgbGVuZ3RoID0gTnVtYmVyKGxlbmd0aCk7CiAgICAgICAgICBpZiAobGVuZ3RoID4gcmVtYWluaW5nKSB7CiAgICAgICAgICAgIGxlbmd0aCA9IHJlbWFpbmluZzsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgY29uc3Qgc3RyTGVuID0gc3RyaW5nLmxlbmd0aDsKICAgICAgICBpZiAobGVuZ3RoID4gc3RyTGVuIC8gMikgewogICAgICAgICAgbGVuZ3RoID0gc3RyTGVuIC8gMjsKICAgICAgICB9CiAgICAgICAgbGV0IGk7CiAgICAgICAgZm9yIChpID0gMDsgaSA8IGxlbmd0aDsgKytpKSB7CiAgICAgICAgICBjb25zdCBwYXJzZWQgPSBwYXJzZUludChzdHJpbmcuc3Vic3RyKGkgKiAyLCAyKSwgMTYpOwogICAgICAgICAgaWYgKG51bWJlcklzTmFOKHBhcnNlZCkpCiAgICAgICAgICAgIHJldHVybiBpOwogICAgICAgICAgYnVmW29mZnNldCArIGldID0gcGFyc2VkOwogICAgICAgIH0KICAgICAgICByZXR1cm4gaTsKICAgICAgfQogICAgICBmdW5jdGlvbiB1dGY4V3JpdGUoYnVmLCBzdHJpbmcsIG9mZnNldCwgbGVuZ3RoKSB7CiAgICAgICAgcmV0dXJuIGJsaXRCdWZmZXIodXRmOFRvQnl0ZXMoc3RyaW5nLCBidWYubGVuZ3RoIC0gb2Zmc2V0KSwgYnVmLCBvZmZzZXQsIGxlbmd0aCk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gYXNjaWlXcml0ZShidWYsIHN0cmluZywgb2Zmc2V0LCBsZW5ndGgpIHsKICAgIC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c2V0LCBsZW5ndGgpOwogICAgICAgICAgICBjYXNlICJ1dGY4IjoKICAgICAgICAgICAgY2FzZSAidXRmLTgiOgogICAgICAgICAgICAgIHJldHVybiB1dGY4V3JpdGUodGhpcywgc3RyaW5nLCBvZmZzZXQsIGxlbmd0aCk7CiAgICAgICAgICAgIGNhc2UgImFzY2lpIjoKICAgICAgICAgICAgY2FzZSAibGF0aW4xIjoKICAgICAgICAgICAgY2FzZSAiYmluYXJ5IjoKICAgICAgICAgICAgICByZXR1cm4gYXNjaWlXcml0ZSh0aGlzLCBzdHJpbmcsIG9mZnNldCwgbGVuZ3RoKTsKICAgICAgICAgICAgY2FzZSAiYmFzZTY0IjoKICAgICAgICAgICAgICByZXR1cm4gYmFzZTY0V3JpdGUodGhpcywgc3RyaW5nLCBvZmZzZXQsIGxlbmd0aCk7CiAgICAgICAgICAgIGNhc2UgInVjczIiOgogICAgICAgICAgICBjYXNlICJ1Y3MtMiI6CiAgICAgICAgICAgIGNhc2UgInV0ZjE2bGUiOgogICAgICAgICAgICBjYXNlICJ1dGYtMTZsZSI6CiAgICAgICAgICAgICAgcmV0dXJuIHVjczJXcml0ZSh0aGlzLCBzdHJpbmcsIG9mZnNldCwgbGVuZ3RoKTsKICAgICAgICAgICAgZGVmYXVsdDoKICAgICAgICAgICAgICBpZiAobG93ZXJlZENhc2UpCiAgICAgICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCJVbmtub3duIGVuY29kaW5nOiAiICsgZW5jb2RpbmcpOwogICAgICAgICAgICAgIGVuY29kaW5nID0gKCIiICsgZW5jb2RpbmcpLnRvTG93ZXJDYXNlKCk7CiAgICAgICAgICAgICAgbG93ZXJlZENhc2UgPSB0cnVlOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfTsKICAgICAgQnVmZmVyMTAucHJvdG90eXBlLnRvSlNPTiA9IGZ1bmN0aW9uIHRvSlNPTigpIHsKICAgICAgICByZXR1cm4gewogICAgICAgICAgdHlwZTogIkJ1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gICAgICAgICAgICBpZiAoZmlyc3RCeXRlIDwgMTI4KSB7CiAgICAgICAgICAgICAgICAgIGNvZGVQb2ludCA9IGZpcnN0Qnl0ZTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgIGNhc2UgMjoKICAgICAgICAgICAgICAgIHNlY29uZEJ5dGUgPSBidWZbaSArIDFdOwogICAgICAgICAgICAgICAgaWYgKChzZWNvbmRCeXRlICYgMTkyKSA9PT0gMTI4KSB7CiAgICAgICAgICAgICAgICAgIHRlbXBDb2RlUG9pbnQgPSAoZmlyc3RCeXRlICYgMzEpIDw8IDYgfCBzZWNvbmRCeXRlICYgNjM7CiAgICAgICAgICAgICAgICAgIGlmICh0ZW1wQ29kZVBvaW50ID4gMTI3KSB7CiAgICAgICAgICAgICAgICAgICAgY29kZVBvaW50ID0gdGVtcENvZGVQb2ludDsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgY2FzZSAzOgogICAgICAgICAgICAgICAgc2Vjb25kQnl0ZSA9IGJ1ZltpICsgMV07CiAgICAgICAgICAgICAgICB0aGlyZEJ5dGUgPSBidWZbaSArIDJdOwogICAgICAgICAgICAgICAgaWYgKChzZWNvbmRCeXRlICYgMTkyKSA9PT0gMTI4ICYmICh0aGlyZEJ5dGUgJiAxOTIpID09PSAxMjgpIHsKICAgICAgICAgICAgICAgICAgdGVtcENvZGVQb2ludCA9IChmaXJzdEJ5dGUgJiAxNSkgPDwgMTIgfCAoc2Vjb25kQnl0ZSAmIDYzKSA8PCA2IHwgdGhpcmRCeXRlICYgNjM7CiAgICAgICAgICAgICAgICAgIGlmICh0ZW1wQ29kZVBvaW50ID4gMjA0NyAmJiAodGVtcENvZGVQb2ludCA8IDU1Mjk2IHx8IHRlbXBDb2RlUG9pbnQgPiA1NzM0MykpIHsKICAgICAgICAgICAgICAgICAgICBjb2RlUG9pbnQgPSB0ZW1wQ29kZVBvaW50OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICBjYXNlIDQ6CiAgICAgICAgICAgICAgICBzZWNvbmRCeXRlID0gYnVmW2kgKyAxXTsKICAgICAgICAgICAgICAgIHRoaXJkQnl0ZSA9IGJ1ZltpICsgMl07CiAgICAgICAgICAgICAgICBmb3VydGhCeXRlID0gYnVmW2kgKyAzXTsKICAgICAgICAgICAgICAgIGlmICgoc2Vjb25kQnl0ZSAmIDE5MikgPT09IDEyOCAmJiAodGhpcmRCeXRlICYgMTkyKSA9PT0gMTI4ICYmIChmb3VydGhCeXRlICYgMTkyKSA9PT0gMTI4KSB7CiAgICAgICAgICAgICAgICAgIHRlbXBDb2RlUG9pbnQgPSAoZmlyc3RCeXRlICYgMTUpIDw8IDE4IHwgKHNlY29uZEJ5dGUgJiA2MykgPDwgMTIgfCAodGhpcmRCeXRlICYgNjMpIDw8IDYgfCBmb3VydGhCeXRlICYgNjM7CiAgICAgICAgICAgICAgICAgIGlmICh0ZW1wQ29kZVBvaW50ID4gNjU1MzUgJiYgdGVtcENvZGVQb2ludCA8IDExMTQxMTIpIHsKICAgICAgICAgICAgICAgICAgICBjb2RlUG9pbnQgPSB0ZW1wQ29kZVBvaW50OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGlmIChjb2RlUG9pbnQgPT09IG51bGwpIHsKICAgICAgICAgICAgY29kZVBvaW50ID0gNjU1MzM7CiAgICAgICAgICAgIGJ5dGVzUGVyU2VxdWVuY2UgPSAxOwogICAgICAgICAgfSBlbHNlIGlmIChjb2RlUG9pbnQgPiA2NTUzNSkgewogICAgICAgICAgICBjb2RlUG9pbnQgLT0gNjU1MzY7CiAgICAgICAgICAgIHJlcy5wdXNoKGNvZGVQb2ludCA+Pj4gMTAgJiAxMD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nl0ZXNbaV0gKyBieXRlc1tpICsgMV0gKiAyNTYpOwogICAgICAgIH0KICAgICAgICByZXR1cm4gcmVzOwogICAgICB9CiAgICAgIEJ1ZmZlcjEwLnByb3RvdHlwZS5zbGljZSA9IGZ1bmN0aW9uIHNsaWNlKHN0YXJ0LCBlbmQpIHsKICAgICAgICBjb25zdCBsZW4gPSB0aGlzLmxlbmd0aDsKICAgICAgICBzdGFydCA9IH5+c3RhcnQ7CiAgICAgICAgZW5kID0gZW5kID09PSB2b2lkIDAgPyBsZW4gOiB+fmVuZDsKICAgICAgICBpZiAoc3RhcnQgPCAwKSB7CiAgICAgICAgICBzdGFydCArPSBsZW47CiAgICAgICAgICBpZiAoc3RhcnQgPCAwKQogICAgICAgICAgICBzdGFydCA9IDA7CiAgICAgICAgfSBlbHNlIGlmIChzdGFydCA+IGxlbikgewogICAgICAgICAgc3RhcnQgPSBsZW47CiAgICAgICAgfQogICAgICAgIGlmIChlbmQgPCAwKSB7CiAgICAgICAgICBlbmQgKz0gbGVuOwogICAgICAgICAgaWYgKGVuZCA8IDApCiAgICAgICAgICAgIGVuZCA9IDA7CiAgICAgICAgfSBlbHNlIGlmIChlbmQgPiBsZW4pIHsKICAgICAgICAgIGVuZCA9IGxlbjsKICAgICAgICB9CiAgICAgICAgaWYgKGVuZCA8IHN0YXJ0KQogICAgICAgICAgZW5kID0gc3RhcnQ7CiAgICAgICAgY29uc3QgbmV3QnVmID0gdGhpcy5zdWJhcnJheShzdGFydCwgZW5kKTsKICAgICAgICBPYmplY3Quc2V0UHJvdG90eXBlT2YobmV3QnVmLCBCdWZmZXIxMC5wcm90b3R5cGUpOwogICAgICAgIHJldHVybiBuZXdCdWY7CiAgICAgIH07CiAgICAgIGZ1bmN0aW9uIGNoZWNrT2Zmc2V0KG9mZnNldCwgZXh0LCBsZW5ndGgpIHsKICAgICAgICBpZiAob2Zmc2V0ICUgMSAhPT0gMCB8fCBvZmZzZXQgPCAwKQogICAgICAgICAgdGhyb3cgbmV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ICAgICBidWZbb2Zmc2V0KytdID0gbG87CiAgICAgICAgbG8gPSBsbyA+PiA4OwogICAgICAgIGJ1ZltvZmZzZXQrK10gPSBsbzsKICAgICAgICBsbyA9IGxvID4+IDg7CiAgICAgICAgYnVmW29mZnNldCsrXSA9IGxvOwogICAgICAgIGxvID0gbG8gPj4gODsKICAgICAgICBidWZbb2Zmc2V0KytdID0gbG87CiAgICAgICAgbGV0IGhpID0gTnVtYmVyKHZhbHVlID4+IEJpZ0ludCgzMikgJiBCaWdJbnQoNDI5NDk2NzI5NSkpOwogICAgICAgIGJ1ZltvZmZzZXQrK10gPSBoaTsKICAgICAgICBoaSA9IGhpID4+IDg7CiAgICAgICAgYnVmW29mZnNldCsrXSA9IGhpOwogICAgICAgIGhpID0gaGkgPj4gODsKICAgICAgICBidWZbb2Zmc2V0KytdID0gaGk7CiAgICAgICAgaGkgPSBoaSA+PiA4OwogICAgICAgIGJ1ZltvZmZzZXQrK10gPSBoaTsKICAgICAgICByZXR1cm4gb2Zmc2V0OwogICAgICB9CiAgICAgIGZ1bmN0aW9uIHdydEJpZ1VJbnQ2NEJFKGJ1ZiwgdmFsdWUsIG9mZnNldCwgbWluLCBtYXgpIHsKICAgICAgICBjaGVja0ludEJJKHZhbHVlLCBtaW4sIG1heCwgYnVmLCBvZmZzZXQsIDcpOwogICAgICAgIGxldCBsbyA9IE51bWJlcih2YWx1ZSAmIEJpZ0ludCg0Mjk0OTY3Mjk1KSk7CiAgICAgICAgYnVmW29mZnNldCArIDddID0gbG87CiAgICAgICAgbG8gPSBsbyA+PiA4OwogICAgICAgIGJ1ZltvZmZzZXQgKyA2XSA9IGxvOwogICAgICAgIGxvID0gbG8gPj4gODsKICAgICAgICBidWZbb2Zmc2V0ICsgNV0gPSBsbzsKICAgICAgICBsbyA9IGxvID4+IDg7CiAgICAgICAgYnVmW29mZnNldCArIDRdID0gbG87CiAgICAgICAgbGV0IGhpID0gTnVtYmVyKHZhbHVlID4+IEJpZ0ludCgzMikgJi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ICB9OwogICAgICBCdWZmZXIxMC5wcm90b3R5cGUuZmlsbCA9IGZ1bmN0aW9uIGZpbGwodmFsLCBzdGFydCwgZW5kLCBlbmNvZGluZykgewogICAgICAgIGlmICh0eXBlb2YgdmFsID09PSAic3RyaW5nIikgewogICAgICAgICAgaWYgKHR5cGVvZiBzdGFydCA9PT0gInN0cmluZyIpIHsKICAgICAgICAgICAgZW5jb2RpbmcgPSBzdGFydDsKICAgICAgICAgICAgc3RhcnQgPSAwOwogICAgICAgICAgICBlbmQgPSB0aGlzLmxlbmd0aDsKICAgICAgICAgIH0gZWxzZSBpZiAodHlwZW9mIGVuZCA9PT0gInN0cmluZyIpIHsKICAgICAgICAgICAgZW5jb2RpbmcgPSBlbmQ7CiAgICAgICAgICAgIGVuZCA9IHRoaXMubGVuZ3RoOwogICAgICAgICAgfQogICAgICAgICAgaWYgKGVuY29kaW5nICE9PSB2b2lkIDAgJiYgdHlwZW9mIGVuY29kaW5nICE9PSAic3RyaW5nIikgewogICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCJlbmNvZGluZyBtdXN0IGJlIGEgc3RyaW5nIik7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAodHlwZW9mIGVuY29kaW5nID09PSAic3RyaW5nIiAmJiAhQnVmZmVyMTAuaXNFbmNvZGluZyhlbmNvZGluZykpIHsKICAgICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcigiVW5rbm93biBlbmNvZGluZzogIiArIGVuY29kaW5nKTsKICAgICAgICAgIH0KICAgICAgICAgIGlmICh2YWwubGVuZ3RoID09PSAxKSB7CiAgICAgICAgICAgIGNvbnN0IGNvZGUgPSB2YWwuY2hhckNvZGVBdCgwKTsKICAgICAgICAgICAgaWYgKGVuY29kaW5nID09PSAidXRmOCIgJiYgY29kZSA8IDEyOCB8fCBlbmNvZGluZyA9PT0gImxhdGluMSIpIHsKICAgICAgICAgICAgICB2YWwgPSBjb2RlOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfSBlbHNlIGlmICh0eXBlb2YgdmFsID09PSAibnVtYmVyIikgewogICAgICAgICAgdmFsID0gdmFsICYgMjU1OwogICAgICAgIH0gZWxzZSBpZiAodHlwZW9mIHZhbCA9PT0gImJvb2xlYW4iKSB7CiAgICAgICAgICB2YWwgPSBOdW1iZXIodmFsKTsKICAgICAgICB9CiAgICAgICAgaWYgKHN0YXJ0IDwgMCB8fCB0aGlzLmxlbmd0aCA8IHN0YXJ0IHx8IHRoaXMubGVuZ3RoIDwgZW5kKSB7CiAgICAgICAgICB0aHJvdyBuZXcgUmFuZ2VFcnJvcigiT3V0IG9mIHJhbmdlIGluZGV4Iik7CiAgICAgICAgfQogICAgICAgIGlmIChlbmQgPD0gc3RhcnQpIHsKICAgICAgICAgIHJldHVybiB0aGlzOwogICAgICAgIH0KICAgICAgICBzdGFydCA9IHN0YXJ0ID4+PiAwOwogICAgICAgIGVuZCA9IGVuZCA9PT0gdm9pZCAwID8gdGhpcy5sZW5ndGggOiBlbmQgPj4+IDA7CiAgICAgICAgaWYgKCF2YWwpCiAgICAgICAgICB2YWwgPSAwOwogICAgICAgIGxldCBpOwogICAgICAgIGlmICh0eXBlb2YgdmFsID09PSAibnVtYmVyIikgewogICAgICAgICAgZm9yIChpID0gc3RhcnQ7IGkgPCBlbmQ7ICsraSkgewogICAgICAgICAgICB0aGlzW2ldID0gdmFsOwogICAgICAgICAgfQogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBjb25zdCBieXRlcyA9IEJ1ZmZlcjEwLmlzQnVmZmVyKHZhbCkgPyB2YWwgOiBCdWZmZXIxMC5mcm9tKHZhbCwgZW5jb2RpbmcpOwogICAgICAgICAgY29uc3QgbGVuID0gYnl0ZXMubGVuZ3RoOwogICAgICAgICAgaWYgKGxlbiA9PT0gMCkgewogICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCdUaGUgdmFsdWUgIicgKyB2YWwgKyAnIiBpcyBpbnZhbGlkIGZvciBhcmd1bWVudCAidmFsdWUiJyk7CiAgICAgICAgICB9CiAgICAgICAgICBmb3IgKGkgPSAwOyBpIDwgZW5kIC0gc3RhcnQ7ICsraSkgewogICAgICAgICAgICB0aGlzW2kgKyBzdGFydF0gPSBieXRlc1tpICUgbGVuXTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIHRoaXM7CiAgICAgIH07CiAgICAgIHZhciBlcnJvcnMgPSB7fTsKICAgICAgZnVuY3Rpb24gRShzeW0sIGdldE1lc3NhZ2UsIEJhc2UpIHsKICAgICAgICBlcnJvcnNbc3ltXSA9IGNsYXNzIE5vZGVFcnJvciBleHRlbmRzIEJhc2UgewogICAgICAgICAgY29uc3RydWN0b3IoKSB7CiAgICAgICAgICAgIHN1cGVyKCk7CiAgICAgICAgICAgIE9iamVjdC5kZWZpbmVQcm9wZXJ0eSh0aGlzLCAibWVzc2FnZSIsIHsKICAgICAgICAgICAgICB2YWx1ZTogZ2V0TWVzc2FnZS5hcHBseSh0aGlzLCBhcmd1bWVudHMpLAogICAgICAgICAgICAgIHdyaXRhYmxlOiB0cnVlLAogICAgICAgICAgICAgIGNvbmZpZ3VyYWJsZTogdHJ1ZQogICAgICAgICAgICB9KTsKICAgICAgICAgICAgdGhpcy5uYW1lID0gYCR7dGhpcy5uYW1lfSBbJHtzeW19XWA7CiAgICAgICAgICAgIHRoaXMuc3RhY2s7CiAgICAgICAgICAgIGRlbGV0ZSB0aGlzLm5hbWU7CiAgICAgICAgICB9CiAgICAgICAgICBnZXQgY29kZSgpIHsKICAgICAgICAgICAgcmV0dXJuIHN5bTsKICAgICAgICAgIH0KICAgICAgICAgIHNldCBjb2RlKHZhbHVlKSB7CiAgICAgICAgICAgIE9iamVjdC5kZWZpbmVQcm9wZXJ0eSh0aGlzLCAiY29kZSIsIHsKICAgICAgICAgICAgICBjb25maWd1cmFibGU6IHRydWUsCiAgICAgICAgICAgICAgZW51bWVyYWJsZTogdHJ1ZSwKICAgICAgICAgICA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ZSAoc3RyLmxlbmd0aCAlIDQgIT09IDApIHsKICAgICAgICAgIHN0ciA9IHN0ciArICI9IjsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHN0cjsKICAgICAgfQogICAgICBmdW5jdGlvbiB1dGY4VG9CeXRlcyhzdHJpbmcsIHVuaXRzKSB7CiAgICAgICAgdW5pdHMgPSB1bml0cyB8fCBJbmZpbml0eTsKICAgICAgICBsZXQgY29kZVBvaW50OwogICAgICAgIGNvbnN0IGxlbmd0aCA9IHN0cmluZy5sZW5ndGg7CiAgICAgICAgbGV0IGxlYWRTdXJyb2dhdGUgPSBudWxsOwogICAgICAgIGNvbnN0IGJ5dGVzID0gW107CiAgICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCBsZW5ndGg7ICsraSkgewogICAgICAgICAgY29kZVBvaW50ID0gc3RyaW5nLmNoYXJDb2RlQXQoaSk7CiAgICAgICAgICBpZiAoY29kZVBvaW50ID4gNTUyOTUgJiYgY29kZVBvaW50IDwgNTczNDQpIHsKICAgICAgICAgICAgaWYgKCFsZWFkU3Vycm9nYXRlKSB7CiAgICAgICAgICAgICAgaWYgKGNvZGVQb2ludCA+IDU2MzE5KSB7CiAgICAgICAgICAgICAgICBpZiAoKHVuaXRzIC09IDMpID4gLTEpCiAgICAgICAgICAgICAgICAgIGJ5dGVzLnB1c2goMjM5LCAxOTEsIDE4OSk7CiAgICAgICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgICAgICB9IGVsc2UgaWYgKGkgKyAxID09PSBsZW5ndGgpIHsKICAgICAgICAgICAgICAgIGlmICgodW5pdHMgLT0gMykgPiAtMSkKICAgICAgICAgICAgICAgICAgYnl0ZXMucHVzaCgyMzksIDE5MSwgMTg5KTsKICAgICAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBsZWFkU3Vycm9nYXRlID0gY29kZVBvaW50OwogICAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChjb2RlUG9pbnQgPCA1NjMyMCkgewogICAgICAgICAgICAgIGlmICgodW5pdHMgLT0gMykgPiAtMSkKICAgICAgICAgICAgICAgIGJ5dGVzLnB1c2goMjM5LCAxOTEsIDE4OSk7CiAgICAgICAgICAgICAgbGVhZFN1cnJvZ2F0ZSA9IGNvZGVQb2ludDsKICAgICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgICAgfQogICAgICAgICAgICBjb2RlUG9pbnQgPSAobGVhZFN1cnJvZ2F0ZSAtIDU1Mjk2IDw8IDEwIHwgY29kZVBvaW50IC0gNTYzMjApICsgNjU1MzY7CiAgICAgICAgICB9IGVsc2UgaWYgKGxlYWRTdXJyb2dhdGUpIHsKICAgICAgICAgICAgaWYgKCh1bml0cyAtPSAzKSA+IC0xKQogICAgICAgICAgICAgIGJ5dGVzLnB1c2goMjM5LCAxOTEsIDE4OSk7CiAgICAgICAgICB9CiAgICAgICAgICBsZWFkU3Vycm9nYXRlID0gbnVsbDsKICAgICAgICAgIGlmIChjb2RlUG9pbnQgPCAxMjgpIHsKICAgICAgICAgICAgaWYgKCh1bml0cyAtPSAxKSA8IDApCiAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIGJ5dGVzLnB1c2goY29kZVBvaW50KTsKICAgICAgICAgIH0gZWxzZSBpZiAoY29kZVBvaW50IDwgMjA0OCkgewogICAgICAgICAgICBpZiAoKHVuaXRzIC09IDIpIDwgMCkKICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgYnl0ZXMucHVzaChjb2RlUG9pbnQgPj4gNiB8IDE5MiwgY29kZVBvaW50ICYgNjMgfCAxMjgpOwogICAgICAgICAgfSBlbHNlIGlmIChjb2RlUG9pbnQgPCA2NTUzNikgewogICAgICAgICAgICBpZiAoKHVuaXRzIC09IDMpIDwgMCkKICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgYnl0ZXMucHVzaChjb2RlUG9pbnQgPj4gMTIgfCAyMjQsIGNvZGVQb2ludCA+PiA2ICYgNjMgfCAxMjgsIGNvZGVQb2ludCAmIDYzIHwgMTI4KTsKICAgICAgICAgIH0gZWxzZSBpZiAoY29kZVBvaW50IDwgMTExNDExMikgewogICAgICAgICAgICBpZiAoKHVuaXRzIC09IDQpIDwgMCkKICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgYnl0ZXMucHVzaChjb2RlUG9pbnQgPj4gMTggfCAyNDAsIGNvZGVQb2ludCA+PiAxMiAmIDYzIHwgMTI4LCBjb2RlUG9pbnQgPj4gNiAmIDYzIHwgMTI4LCBjb2RlUG9pbnQgJiA2MyB8IDEyOCk7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IoIkludmFsaWQgY29kZSBwb2ludCIpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gYnl0ZXM7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gYXNjaWlUb0J5dGVzKHN0cikgewogICAgICAgIGNvbnN0IGJ5dGVBcnJheSA9IFtdOwogICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgc3RyLmxlbmd0aDsgKytpKSB7CiAgICAgICAgICBieXRlQXJyYXkucHVzaChzdHIuY2hhckNvZGVBdChpKSAmIDI1NSk7CiAgICAgICAgfQogICAgICAgIHJldHVybiBieXRlQXJyYXk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gdXRmMTZsZVRvQnl0ZXMoc3RyLCB1bml0cykgewogICAgICAgIGxldCBjLCBoaSwgbG87CiAgICAgICAgY29uc3QgYnl0ZUFycmF5ID0gW107CiAgICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCBzdHIubGVuZ3RoOyArK2kpIHsKICAgICAgICAgIGlmICgodW5pdHMgLT0gMikgPCAwKQogICAgICAgICAgICBicmVhazsKICAgICAgICAgIGMgPSBzdHIuY2hhckNvZGVBdChpKTsKICAgICAgICAgIGhpID0gYyA+PiA4OwogICAgICAgICAgbG8gPSBjICUgMjU2OwogICAgICAgICAgYnl0ZUFycmF5LnB1c2gobG8pOwogICAgICAgICAgYnl0ZUFycmF5LnB1c2goaGkpOwogICAgICAgIH0KICAgICAgICByZXR1cm4gYnl0ZUFycmF5OwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGJhc2U2NFRvQnl0ZXMoc3RyKSB7CiAgICAgICAgcmV0dXJuIGJhc2U2NC50b0J5dGVBcnJheShiYXNlNjRjbGVhbihzdHIpKTsKICAgICAgfQogICAgICBmdW5jdGlvbiBibGl0QnVmZmVyKHNyYywgZHN0LCBvZmZzZXQsIGxlbmd0aCkgewogICAgICAgIGxldCBpOwogICAgICAgIGZvciAoaSA9IDA7IGkgPCBsZW5ndGg7ICsraSkgewogICAgICAgICAgaWYgKGkgKyBvZmZzZXQgPj0gZHN0Lmxlbmd0aCB8fCBpID49IHNyYy5sZW5ndGgpCiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgZHN0W2kgKyBvZmZzZXRdID0gc3JjW2ldOwogICAgICAgIH0KICAgICAgICByZXR1cm4gaTsKICAgICAgfQogICAgICBmdW5jdGlvbiBpc0luc3RhbmNlKG9iaiwgdHlwZSkgewogICAgICAgIHJldHVybiBvYmogaW5zdGFuY2VvZiB0eXBlIHx8IG9iaiAhPSBudWxsICYmIG9iai5jb25zdHJ1Y3RvciAhPSBudWxsICYmIG9iai5jb25zdHJ1Y3Rvci5uYW1lICE9IG51bGwgJiYgb2JqLmNvbnN0cnVjdG9yLm5hbWUgPT09IHR5cGUubmFtZTsKICAgICAgfQogICAgICBmdW5jdGlvbiBudW1iZXJJc05hTihvYmopIHsKICAgICAgICByZXR1cm4gb2JqICE9PSBvYmo7CiAgICAgIH0KICAgICAgdmFyIGhleFNsaWNlTG9va3VwVGFibGUgPSBmdW5jdGlvbigpIHsKICAgICAgICBjb25zdCBhbHBoYWJldCA9ICIwMTIzNDU2Nzg5YWJjZGVmIjsKICAgICAgICBjb25zdCB0YWJsZSA9IG5ldyBB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GVDbGFzcyhDb25zdHJ1Y3RvciwgcHJvdG9Qcm9wcywgc3RhdGljUHJvcHMpIHsKICAgICAgICBpZiAocHJvdG9Qcm9wcykKICAgICAgICAgIF9kZWZpbmVQcm9wZXJ0aWVzKENvbnN0cnVjdG9yLnByb3RvdHlwZSwgcHJvdG9Qcm9wcyk7CiAgICAgICAgaWYgKHN0YXRpY1Byb3BzKQogICAgICAgICAgX2RlZmluZVByb3BlcnRpZXMoQ29uc3RydWN0b3IsIHN0YXRpY1Byb3BzKTsKICAgICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkoQ29uc3RydWN0b3IsICJwcm90b3R5cGUiLCB7CiAgICAgICAgICB3cml0YWJsZTogZmFsc2UKICAgICAgICB9KTsKICAgICAgICByZXR1cm4gQ29uc3RydWN0b3I7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gX2luaGVyaXRzKHN1YkNsYXNzLCBzdXBlckNsYXNzKSB7CiAgICAgICAgaWYgKHR5cGVvZiBzdXBlckNsYXNzICE9PSAiZnVuY3Rpb24iICYmIHN1cGVyQ2xhc3MgIT09IG51bGwpIHsKICAgICAgICAgIHRocm93IG5ldyBUeXBlRXJyb3IoIlN1cGVyIGV4cHJlc3Npb24gbXVzdCBlaXRoZXIgYmUgbnVsbCBvciBhIGZ1bmN0aW9uIik7CiAgICAgICAgfQogICAgICAgIHN1YkNsYXNzLnByb3RvdHlwZSA9IE9iamVjdC5jcmVhdGUoc3VwZXJDbGFzcyAmJiBzdXBlckNsYXNzLnByb3RvdHlwZSwgewogICAgICAgICAgY29uc3RydWN0b3I6IHsKICAgICAgICAgICAgdmFsdWU6IHN1YkNsYXNzLAogICAgICAgICAgICB3cml0YWJsZTogdHJ1ZSwKICAgICAgICAgICAgY29uZmlndXJhYmxlOiB0cnVlCiAgICAgICAgICB9CiAgICAgICAgfSk7CiAgICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KHN1YkNsYXNzLCAicHJvdG90eXBlIiwgewogICAgICAgICAg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XBlb2YgUHJveHkgPT09ICJmdW5jdGlvbiIpCiAgICAgICAgICByZXR1cm4gdHJ1ZTsKICAgICAgICB0cnkgewogICAgICAgICAgQm9vbGVhbi5wcm90b3R5cGUudmFsdWVPZi5jYWxsKFJlZmxlY3QuY29uc3RydWN0KEJvb2xlYW4sIFtdLCBmdW5jdGlvbigpIHsKICAgICAgICAgIH0pKTsKICAgICAgICAgIHJldHVybiB0cnVlOwogICAgICAgIH0gY2F0Y2ggKGUpIHsKICAgICAgICAgIHJldHVybiBmYWxzZTsKICAgICAgICB9CiAgICAgIH0KICAgICAgZnVuY3Rpb24gX2Fzc2VydFRoaXNJbml0aWFsaXplZChzZWxmMikgewogICAgICAgIGlmIChzZWxmMiA9PT0gdm9pZCAwKSB7CiAgICAgICAgICB0aHJvdyBuZXcgUmVmZXJlbmNlRXJyb3IoInRoaXMgaGFzbid0IGJlZW4gaW5pdGlhbGlzZWQgLSBzdXBlcigpIGhhc24ndCBiZWVuIGNhbGxlZCIpOwogICAgICAgIH0KICAgICAgICByZXR1cm4gc2VsZjI7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gX3Bvc3NpYmxlQ29uc3RydWN0b3JSZXR1cm4oc2VsZjIsIGNhbGwpIHsKICAgICAgICBpZiAoY2FsbCAmJiAodHlwZW9mIGNhbGwgPT09ICJvYmplY3QiIHx8IHR5cGVvZiBjYWxsID09PSAiZnVuY3Rpb24iKSkgewogICAgICAgICAgcmV0dXJuIGNhbGw7CiAgICAgICAgfSBlbHNlIGlmIChjYWxsICE9PSB2b2lkIDApIHsKICAgICAgICAgIHRocm93IG5ldyBUeXBlRXJyb3IoIkRlcml2ZWQgY29uc3RydWN0b3JzIG1heSBvbmx5IHJldHVybiBvYmplY3Qgb3IgdW5kZWZpbmVkIik7CiAgICAgICAgfQogICAgICAgIHJldHVybiBfYXNzZXJ0VGhpc0luaXRpYWxpemVkKHNlbGYyKTsKICAgICAgfQogICAgICBmdW5jdGlvbiBfY3JlYXRlU3VwZXIoRGVyaXZlZCkgewogICAgICAgIHZhciBoYXNOYXRpdmVSZWZsZWN0Q29uc3RydWN0ID0gX2lzTmF0aXZlUmVmbGVjdENvbnN0cnVjdCgpOwogICAgICAgIHJldHVybiBmdW5jdGlvbiBfY3JlYXRlU3VwZXJJbnRlcm5hbCgpIHsKICAgICAgICAgIHZhciBTdXBlciA9IF9nZXRQcm90b3R5cGVPZihEZXJpdmVkKSwgcmVzdWx0OwogICAgICAgICAgaWYgKGhhc05hdGl2ZVJlZmxlY3RDb25zdHJ1Y3QpIHsKICAgICAgICAgICAgdmFyIE5ld1RhcmdldCA9IF9nZXRQcm90b3R5cGVPZih0aGlzKS5jb25zdHJ1Y3RvcjsKICAgICAgICAgICAgcmVzdWx0ID0gUmVmbGVjdC5jb25zdHJ1Y3QoU3VwZXIsIGFyZ3VtZW50cywgTmV3VGFyZ2V0KTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHJlc3VsdCA9IFN1cGVyLmFwcGx5KHRoaXMsIGFyZ3VtZW50cyk7CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gX3Bvc3NpYmxlQ29uc3RydWN0b3JSZXR1cm4odGhpcywgcmVzdWx0KTsKICAgICAgICB9OwogICAgICB9CiAgICAgIGZ1bmN0aW9uIF9zdXBlclByb3BCYXNlKG9iamVjdCwgcHJvcGVydHkpIHsKICAgICAgICB3aGlsZSAoIU9iamVjdC5wcm90b3R5cGUuaGFzT3duUHJvcGVydHkuY2FsbChvYmplY3QsIHByb3BlcnR5KSkgewogICAgICAgICAgb2JqZWN0ID0gX2dldFByb3RvdHlwZU9mKG9iamVjdCk7CiAgICAgICAgICBpZiAob2JqZWN0ID09PSBudWxsKQogICAgICAgICAgICBicmVhazsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIG9iamVjdDsKICAgICAgfQogICAgICBmdW5jdGlvbiBfZ2V0KCkgewogICAgICAgIGlmICh0eXBlb2YgUmVmbGVjdCAhPT0gInVuZGVmaW5lZCIgJiYgUmVmbGVjdC5nZXQpIHsKICAgICAgICAgIF9nZXQgPSBSZWZsZWN0LmdldC5iaW5kKCk7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIF9nZXQgPSBmdW5jdGlvbiBfZ2V0Mih0YXJnZXQsIHByb3BlcnR5LCByZWNlaXZlcikgewogICAgICAgICAgICB2YXIgYmFzZSA9IF9zdXBlclByb3BCYXNlKHRhcmdldCwgcHJvcGVydHkpOwogICAgICAgICAgICBpZiAoIWJhc2UpCiAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICB2YXIgZGVzYyA9IE9iamVjdC5nZXRPd25Qcm9wZXJ0eURlc2NyaXB0b3IoYmFzZSwgcHJvcGVydHkpOwogICAgICAgICAgICBpZiAoZGVzYy5nZXQpIHsKICAgICAgICAgICAgICByZXR1cm4gZGVzYy5nZXQuY2FsbChhcmd1bWVudHMubGVuZ3RoIDwgMyA/IHRhcmdldCA6IHJlY2VpdmVyKTsKICAgICAgICAgICAgfQogICAgICAgICAgICByZXR1cm4gZGVzYy52YWx1ZTsKICAgICAgICAgIH07CiAgICAgICAgfQogICAgICAgIHJldHVybiBfZ2V0LmFwcGx5KHRoaXMsIGFyZ3VtZW50cyk7CiAgICAgIH0KICAgICAgdmFyIEVtaXR0ZXIgPSAvKiBAX19QVVJFX18gKi8gZnVuY3Rpb24oKSB7CiAgICAgICAgZnVuY3Rpb24gRW1pdHRlcjIoKSB7CiAgICAgICAgICBfY2xhc3NDYWxsQ2hlY2sodGhpcywgRW1pdHRlcjIpOwogICAgICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KHRoaXMsICJsaXN0ZW5lcnMiLCB7CiAgICAgICAgICAgIHZhbHVlOiB7fSwKICAgICAgICAgICAgd3JpdGFibGU6IHRydWUsCiAgICAgICAgICAgIGNvbmZpZ3VyYWJsZTogdHJ1ZQogICAgICAgICAgfSk7CiAgICAgICAgfQogICAgICAgIF9jcmVhdGVDbGFzcyhFbWl0dGVyMiwgW3sKICAgICAgICAgIGtleTogImFkZEV2ZW50TGlzdGVuZXIiLAogICAgICAgICAgdmFsdWU6IGZ1bmN0aW9uIGFkZEV2ZW50TGlzdGVuZXIodHlwZSwgY2FsbGJhY2ssIG9wdGlvbnMpIHsKICAgICAgICAgICAgaWYgKCEodHlwZSBpbiB0aGlzLmxpc3RlbmVycykpIHsKICAgICAgICAgICAgICB0aGlzLmxpc3RlbmVyc1t0eXBlXSA9IFtdOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHRoaXMubGlzdGVuZXJzW3R5cGVdLnB1c2goewogICAgICAgICAgICAgIGNhbGxiYWNrLAogICAgICAgICAgICAgIG9wdGlvbnMKICAgICAgICAgICAgfSk7CiAgICAgICAgICB9CiAgICAgICAgfSwgewogICAgICAgICAga2V5OiAicmVtb3ZlRXZlbnRMaXN0ZW5lciIsCiAgICAgICAgICB2YWx1ZTogZnVuY3Rpb24gcmVtb3ZlRXZlbnRMaXN0ZW5lcih0eXBlLCBjYWxsYmFjaykgewogICAgICAgICAgICBpZiAoISh0eXBlIGluIHRoaXMubGlzdGVuZXJzKSkgewogICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgfQogICAgICAgICAgICB2YXIgc3RhY2sgPSB0aGlzLmxpc3RlbmVyc1t0eXBlXTsKICAgICAgICAgICAgZm9yICh2YXIgaSA9IDAsIGwgPSBzdGFjay5sZW5ndGg7IGkgPCBsOyBpKyspIHsKICAgICAgICAgICAgICBpZiAoc3RhY2tbaV0uY2FsbGJhY2sgPT09IGNhbGxiYWNrKSB7CiAgICAgICAgICAgICAgICBzdGFjay5zcGxpY2UoaSwgMSk7CiAgICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfSwgewogICAgICAgICAga2V5OiAiZGlzcGF0Y2hFdmVudCIsCiAgICAgICAgICB2YWx1ZTogZnVuY3Rpb24gZGlzcGF0Y2hFdmVudChldmVudCkgewogICAgICAgICAgICBpZiAoIShldmVudC50eXBlIGluIHRoaXMubGlzdGVuZXJzKSkgewogICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgfQogICAgICAgICAgICB2YXIgc3RhY2sgPSB0aGlzLmxpc3RlbmVyc1tldmVudC50eXBlXTsKICAgICAgICAgICAgdmFyIHN0YWNrVG9DYWxsID0gc3RhY2suc2xpY2UoKTsKICAgICAgICAgICAgZm9yICh2YXIgaSA9IDAsIGwgPSBzdGFja1RvQ2FsbC5sZW5ndGg7IGkgPCBsOyBpKyspIHsKICAgICAgICAgICAgICB2YXIgbGlzdGVuZXIgPSBzdGFja1RvQ2FsbFtpXTsKICAgICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgICAgbGlzdGVuZXIuY2FsbGJhY2suY2FsbCh0aGlzLCBldmVudCk7CiAgICAgICAgICAgICAgfSBjYXRjaCAoZSkgewogICAgICAgICAgICAgICAgUHJvbWlzZS5yZXNvbHZlKCkudGhlbihmdW5jdGlvbigpIHsKICAgICAgICAgICAgICAgICAgdGhyb3cgZTsKICAgICAgICAgICAgICAgIH0pOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBpZiAobGlzdGVuZXIub3B0aW9ucyAmJiBsaXN0ZW5lci5vcHRpb25zLm9uY2UpIHsKICAgICAgICAgICAgICAgIHRoaXMucmVtb3ZlRXZlbnRMaXN0ZW5lcihldmVudC50eXBlLCBsaXN0ZW5lci5jYWxsYmFjayk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIHJldHVybiAhZXZlbnQuZGVmYXVsdFByZXZlbnRlZDsKICAgICAgICAgIH0KICAgICAgICB9XSk7CiAgICAgICAgcmV0dXJuIEVtaXR0ZXIyOwogICAgICB9KCk7CiAgICAgIHZhciBBYm9ydFNpZ25hbCA9IC8qIEBfX1BVUkVfXyAqLyBmdW5jdGlvbihfRW1pdHRlcikgewogICAgICAgIF9pbmhlcml0cyhBYm9ydFNpZ25hbDIsIF9FbWl0dGVyKTsKICAgICAgICB2YXIgX3N1cGVyID0gX2NyZWF0ZVN1cGVyKEFib3J0U2lnbmFsMik7CiAgICAgICAgZnVuY3Rpb24gQWJvcnRTaWduYWwyKCkgewogICAgICAgICAgdmFyIF90aGlzOwogICAgICAgICAgX2NsYXNzQ2FsbENoZWNrKHRoaXMsIEFib3J0U2lnbmFsMik7CiAgICAgICAgICBfdGhpcyA9IF9zdXBlci5jYWxsKHRoaXMpOwogICAgICAgICAgaWYgKCFfdGhpcy5saXN0ZW5lcnMpIHsKICAgICAgICAgICAgRW1pdHRlci5jYWxsKF9hc3NlcnRUaGlzSW5pdGlhbGl6ZWQoX3RoaXMpKTsKICAgICAgICAgIH0KICAgICAgICAgIE9iamVjdC5kZWZpbmVQcm9wZXJ0eShfYXNzZXJ0VGhpc0luaXRpYWxpemVkKF90aGlzKSwgImFib3J0ZWQiLCB7CiAgICAgICAgICAgIHZhbHVlOiBmYWxzZSwKICAgICAgICAgICAgd3JpdGFibGU6IHRydWUsCiAgICAgICAgICAgIGNvbmZpZ3VyYWJsZTogdHJ1ZQogICAgICAgICAgfSk7CiAgICAgICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkoX2Fzc2VydFRoaXNJbml0aWFsaXplZChfdGhpcyksICJvbmFib3J0IiwgewogICAgICAgICAgICB2YWx1ZTogbnVsbCwKICAgICAgICAgICAgd3JpdGFibGU6IHRydWUsCiAgICAgICAgICAgIGNvbmZpZ3VyYWJsZTogdHJ1ZQogICAgICAgICAgfSk7CiAgICAgICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkoX2Fzc2VydFRoaXNJbml0aWFsaXplZChfdGhpcyksICJyZWFzb24iLCB7CiAgICAgICAgICAgIHZhbHVlOiB2b2lkIDAsCiAgICAgICAgICAgIHdyaXRhYmxlOiB0cnVlLAogICAgICAgICAgICBjb25maWd1cmFibGU6IHRydWUKICAgICAgICAgIH0pOwogICAgICAgICAgcmV0dXJuIF90aGlzOwogICAgICAgIH0KICAgICAgICBfY3JlYXRlQ2xhc3MoQWJvcnRTaWduYWwyLCBbewogICAgICAgICAga2V5OiAidG9TdHJpbmciLAogICAgICAgICAgdmFsdWU6IGZ1bmN0aW9uIHRvU3RyaW5nKCkgewogICAgICAgICAgICByZXR1cm4gIltvYmplY3QgQWJvcnRTaWduYWxdIjsKICAgICAgICAgIH0KICAgICAgICB9LCB7CiAgICAgICAgICBrZXk6ICJkaXNwYXRjaEV2ZW50IiwKICAgICAgICAgIHZhbHVlOiBmdW5jdGlvbiBkaXNwYXRjaEV2ZW50KGV2ZW50KSB7CiAgICAgICAgICAgIGlmIChldmVudC50eXBlID09PSAiYWJvcnQiKSB7CiAgICAgICAgICAgICAgdGhpcy5hYm9ydGVkID0gdHJ1ZTsKICAgICAgICAgICAgICBpZiAodHlwZW9mIHRoaXMub25hYm9ydCA9PT0gImZ1bmN0aW9uIikgewogICAgICAgICAgICAgICAgdGhpcy5vbmFib3J0LmNhbGwodGhpcywgZXZlbnQpOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBfZ2V0KF9nZXRQcm90b3R5cGVPZihBYm9ydFNpZ25hbDIucHJvdG90eXBlKSwgImRpc3BhdGNoRXZlbnQiLCB0aGlzKS5jYWxsKHRoaXMsIGV2ZW50KTsKICAgICAgICAgIH0KICAgICAgICB9XSk7CiAgICAgICAgcmV0dXJuIEFib3J0U2lnbmFsMjsKICAgICAgfShFbWl0dGVyKTsKICAgICAgdmFyIEFib3J0Q29udHJvbGxlciA9IC8qIEBfX1BVUkVfXyAqLyBmdW5jdGlvbigpIHsKICAgICAgICBmdW5jdGlvbiBBYm9ydENvbnRyb2xsZXIyKCkgewogICAgICAgICAgX2NsYXNzQ2FsbENoZWNrKHRoaXMsIEFib3J0Q29udHJvbGxlcjIpOwogICAgICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KHRoaXMsICJzaWduYWwiLCB7CiAgICAgICAgICAgIHZhbHVlOiBuZXcgQWJvcnRTaWduYWwoKSwKICAgICAgICAgICAgd3JpdGFibGU6IHRydWUsCiAgICAgICAgICAgIGNvbmZpZ3VyYWJsZTogdHJ1ZQogICAgICAgICAgfSk7CiAgICAgICAgfQogICAgICAgIF9jcmVhdGVDbGFzcyhBYm9ydENvbnRyb2xsZXIyLCBbewogICAgICAgICAga2V5OiAiYWJvcnQiLAogICAgICAgICAgdmFsdWU6IGZ1bmN0aW9uIGFib3J0KHJlYXNvbikgewogICAgICAgICAgICB2YXIgZXZlbnQ7CiAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgZXZlbnQgPSBuZXcgRXZlbnQoImFib3J0Iik7CiAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHsKICAgICAgICAgICAgICBpZiAodHlwZW9mIGRvY3VtZW50ICE9PSAidW5kZWZpbmVkIikgewogICAgICAgICAgICAgICAgaWYgKCFkb2N1bWVudC5jcmVhdGVFdmVudCkgewogICAgICAgICAgICAgICAgICBldmVudCA9IGRvY3VtZW50LmNyZWF0ZUV2ZW50T2JqZWN0KCk7CiAgICAgICAgICAgICAgICAgIGV2ZW50LnR5cGUgPSAiYWJvcnQiOwogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgZXZlbnQgPSBkb2N1bWVudC5jcmVhdGVFdmVudCgiRXZlbnQiKTsKICAgICAgICAgICAgICAgICAgZXZlbnQuaW5pdEV2ZW50KCJhYm9ydCIsIGZhbHNlLCBmYWxzZSk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIGV2ZW50ID0gewogICAgICAgICAgICAgICAgICB0eXBlOiAiYWJvcnQiLAogICAgICAgICAgICAgICAgICBidWJibGVzOiBmYWxzZSwKICAgICAgICAgICAgICAgICAgY2FuY2VsYWJsZTogZmFsc2UKICAgICAgICAgICAgICAgIH07CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIHZhciBzaWduYWxSZWFzb24gPSByZWFzb247CiAgICAgICAgICAgIGlmIChzaWduYWxSZWFzb24gPT09IHZvaWQgMCkgewogICAgICAgICAgICAgIGlmICh0eXBlb2YgZG9jdW1lbnQgPT09ICJ1bmRlZmluZWQiKSB7CiAgICAgICAgICAgICAgICBzaWduYWxSZWFzb24gPSBuZXcgRXJyb3IoIlRoaXMgb3BlcmF0aW9uIHdhcyBhYm9ydGVkIik7CiAgICAgICAgICAgICAgICBzaWduYWxSZWFzb24ubmFtZSA9ICJBYm9ydEVycm9yIjsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICAgICAgc2lnbmFsUmVhc29uID0gbmV3IERPTUV4Y2VwdGlvbigic2lnbmFsIGlzIGFib3J0ZWQgd2l0aG91dCByZWFzb24iKTsKICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGVycikgewogICAgICAgICAgICAgICAgICBzaWduYWxSZWFzb24gPSBuZXcgRXJyb3IoIlRoaXMgb3BlcmF0aW9uIHdhcyBhYm9ydGVkIik7CiAgICAgICAgICAgICAgICAgIHNpZ25hbFJlYXNvbi5uYW1lID0gIkFib3J0RXJyb3IiOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICB0aGlzLnNpZ25hbC5yZWFzb24gPSBzaWduYWxSZWFzb247CiAgICAgICAgICAgIHRoaXMuc2lnbmFsLmRpc3BhdGNoRXZlbnQoZXZlbnQpOwogICAgICAgICAgfQogICAgICAgIH0sIHsKICAgICAgICAgIGtleTogInRvU3RyaW5nIiwKICAgICAgICAgIHZhbHVlOiBmdW5jdGlvbiB0b1N0cmluZygpIHsKICAgICAgICAgICAgcmV0dXJuICJbb2JqZWN0IEFib3J0Q29udHJvbGxlcl0iOwogICAgICAgICAgfQogICAgICAgIH1dKTsKICAgICAgICByZXR1cm4gQWJvcnRDb250cm9sbGVyMjsKICAgICAgfSgpOwogICAgICBpZiAodHlw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IHsKICAgICAgICAgIFJlcXVlc3QgPSBmdW5jdGlvbiBSZXF1ZXN0MihpbnB1dCwgaW5pdDIpIHsKICAgICAgICAgICAgdmFyIHNpZ25hbDsKICAgICAgICAgICAgaWYgKGluaXQyICYmIGluaXQyLnNpZ25hbCkgewogICAgICAgICAgICAgIHNpZ25hbCA9IGluaXQyLnNpZ25hbDsKICAgICAgICAgICAgICBkZWxldGUgaW5pdDIuc2lnbmFsOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHZhciByZXF1ZXN0ID0gbmV3IE5hdGl2ZVJlcXVlc3QoaW5wdXQsIGluaXQyKTsKICAgICAgICAgICAgaWYgKHNpZ25hbCkgewogICAgICAgICAgICAgIE9iamVjdC5kZWZpbmVQcm9wZXJ0eShyZXF1ZXN0LCAic2lnbmFsIiwgewogICAgICAgICAgICAgICAgd3JpdGFibGU6IGZhbHNlLAogICAgICAgICAgICAgICAgZW51bWVyYWJsZTogZmFsc2UsCiAgICAgICAgICAgICAgICBjb25maWd1cmFibGU6IHRydWUsCiAgICAgICAgICAgICAgICB2YWx1ZTogc2lnbmFsCiAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgcmV0dXJuIHJlcXVlc3Q7CiAgICAgICAgICB9OwogICAgICAgICAgUmVxdWVzdC5wcm90b3R5cGUgPSBOYXRpdmVSZXF1ZXN0LnByb3RvdHlwZTsKICAgICAgICB9CiAgICAgICAgdmFyIHJlYWxGZXRjaCA9IGZldGNoOwogICAgICAgIHZhciBhYm9ydGFibGVGZXRjaCA9IGZ1bmN0aW9uIGFib3J0YWJsZUZldGNoMihpbnB1dCwgaW5pdDIpIHsKICAgICAgICAgIHZhciBzaWduYWwgPSBSZXF1ZXN0ICYmIFJlcXVlc3QucHJvdG90eXBlLmlzUHJvdG90eXBlT2YoaW5wdXQpID8gaW5wdXQuc2lnbmFsIDogaW5pdDIgPyBpbml0Mi5zaWduYWwgOiB2b2lkIDA7CiAgICAgICAgICBpZiAoc2lnbmFsKSB7CiAgICAgICAgICAgIHZhciBhYm9ydEVycm9yOwogICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgIGFib3J0RXJyb3IgPSBuZXcgRE9NRXhjZXB0aW9uKCJBYm9ydGVkIiwgIkFib3J0RXJyb3IiKTsKICAgICAgICAgICAgfSBjYXRjaCAoZXJyKSB7CiAgICAgICAgICAgICAgYWJvcnRFcnJvciA9IG5ldyBFcnJvcigiQWJvcnRlZCIpOwogICAgICAgICAgICAgIGFib3J0RXJyb3IubmFtZSA9ICJBYm9ydEVycm9yIjsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoc2lnbmFsLmFib3J0ZWQpIHsKICAgICAgICAgICAgICByZXR1cm4gUHJvbWlzZS5yZWplY3QoYWJvcnRFcnJvcik7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdmFyIGNhbmNlbGxhdGlvbiA9IG5ldyBQcm9taXNlKGZ1bmN0aW9uKF8sIHJlamVjdCkgewogICAgICAgICAgICAgIHNpZ25hbC5hZGRFdmVudExpc3RlbmVyKCJhYm9ydCIsIGZ1bmN0aW9uKCkgewogICAgICAgICAgICAgICAgcmV0dXJuIHJlamVjdChhYm9ydEVycm9yKTsKICAgICAgICAgICAgICB9LCB7CiAgICAgICAgICAgICAgICBvbmNlOiB0cnVlCiAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgIH0pOwogICAgICAgICAgICBpZiAoaW5pdDIgJiYgaW5pdDIuc2lnbmFsKSB7CiAgICAgICAgICAgICAgZGVsZXRlIGluaXQyLnNpZ25hbDsKICAgICAgICAgICAgfQogICAgICAgICAgICByZXR1cm4gUHJvbWlzZS5yYWNlKFtjYW5jZWxsYXRpb24sIHJlYWxGZXRjaChpbnB1dCwgaW5pdDIpXSk7CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gcmVhbEZldGNoKGlucHV0LCBpbml0Mik7CiAgICAgICAgfTsKICAgICAgICByZXR1cm4gewogICAgICAgICAgZmV0Y2g6IG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AgICB9IGVsc2UgaWYgKHR5cGVvZiBzaWduYWwuYWRkRXZlbnRMaXN0ZW5lciA9PT0gImZ1bmN0aW9uIikgewogICAgICAgICAgICBzaWduYWwuYWRkRXZlbnRMaXN0ZW5lcigiYWJvcnQiLCAoKSA9PiB7CiAgICAgICAgICAgICAgdGhpcy5oYW5kbGVBYm9ydGVkKHNpZ25hbCk7CiAgICAgICAgICAgIH0pOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBoYW5kbGVBYm9ydGVkKHNpZ25hbCkgewogICAgICAgICAgdGhpcy5zaWduYWxzLmRlbGV0ZShzaWduYWwpOwogICAgICAgICAgaWYgKHRoaXMuc2lnbmFscy5zaXplID09PSAwKSB7CiAgICAgICAgICAgIHRoaXMuYWJvcnRDb250cm9sbGVyLmFib3J0KCk7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGdldCBzaWduYWwoKSB7CiAgICAgICAgICByZXR1cm4gdGhpcy5hYm9ydENvbnRyb2xsZXIuc2lnbmFsOwogICAgICAgIH0KICAgICAgICBhYm9ydCgpIHsKICAgICAgICAgIHRoaXMuYWJvcnRDb250cm9sbGVyLmFib3J0KCk7CiAgICAgICAgfQogICAgICB9OwogICAgICBleHBvcnRzMi5kZWZhdWx0ID0gQWdncmVnYXRlQWJvcnRDb250cm9sbGVyOwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vYWJvcnRhYmxlLXByb21pc2UtY2FjaGVAMS41LjAvbm9kZV9tb2R1bGVzL2Fib3J0YWJsZS1wcm9taXNlLWNhY2hlL2VzbS9BZ2dyZWdhdGVTdGF0dXNSZXBvcnRlci5qcwogIHZhciByZXF1aXJlX0FnZ3JlZ2F0ZVN0YXR1c1JlcG9ydGVyID0gX19jb21tb25KUyh7CiAgICAibm9kZV9tb2R1bGVzLy5wbnBtL2Fib3J0YWJsZS1wcm9taXNlLWNhY2hlQDEuNS4wL25vZGVfbW9kdWxlcy9hYm9ydGFibGUtcHJvb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AgICAgICAgZmlsbChrZXksIGRhdGEsIHNpZ25hbCwgc3RhdHVzQ2FsbGJhY2spIHsKICAgICAgICAgIGNvbnN0IGFib3J0ZXIgPSBuZXcgQWdncmVnYXRlQWJvcnRDb250cm9sbGVyXzEuZGVmYXVsdCgpOwogICAgICAgICAgY29uc3Qgc3RhdHVzUmVwb3J0ZXIgPSBuZXcgQWdncmVnYXRlU3RhdHVzUmVwb3J0ZXJfMS5kZWZhdWx0KCk7CiAgICAgICAgICBzdGF0dXNSZXBvcnRlci5hZGRDYWxsYmFjayhzdGF0dXNDYWxsYmFjayk7CiAgICAgICAgICBjb25zdCBuZXdFbnRyeSA9IHsKICAgICAgICAgICAgYWJvcnRlciwKICAgICAgICAgICAgcHJvbWlzZTogdGhpcy5maWxsQ2FsbGJhY2soZGF0YSwgYWJvcnRlci5zaWduYWwsIChtZXNzYWdlKSA9PiB7CiAgICAgICAgICAgICAgc3RhdHVzUmVwb3J0ZXIuY2FsbGJhY2sobWVzc2FnZSk7CiAgICAgICAgICAgIH0pLAogICAgICAgICAgICBzZXR0bGVkOiBmYWxzZSwKICAgICAgICAgICAgc3RhdHVzUmVwb3J0ZXIsCiAgICAgICAgICAgIGdldCBhYm9ydGVkKCkgewogICAgICAgICAgICAgIHJldHVybiB0aGlzLmFib3J0ZXIuc2lnbmFsLmFib3J0ZWQ7CiAgICAgICAgICAgIH0KICAgICAgICAgIH07CiAgICAgICAgICBuZXdFbnRyeS5hYm9ydGVyLmFkZFNpZ25hbChzaWduYWwpOwogICAgICAgICAgbmV3RW50cnkuYWJvcnRlci5zaWduYWwuYWRkRXZlbnRMaXN0ZW5lcigiYWJvcnQiLCAoKSA9PiB7CiAgICAgICAgICAgIGlmICghbmV3RW50cnkuc2V0dGxlZCkgewogICAgICAgICAgICAgIHRoaXMuZXZpY3Qoa2V5LCBuZXdFbnRyeSk7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0pOwogICAgICAgICAgbmV3RW50cnkucHJvbWlzZS50aGVuKCgpID0+IHsKICAgICAgICAgICAgbmV3RW50cnkuc2V0dGxlZCA9IHRydWU7CiAgICAgICAgICB9LCAoKSA9PiB7CiAgICAgICAgICAgIG5ld0VudHJ5LnNldHRsZWQgPSB0cnVlOwogICAgICAgICAgICB0aGlzLmV2aWN0KGtleSwgbmV3RW50cnkpOwogICAgICAgICAgfSkuY2F0Y2goKGUpID0+IHsKICAgICAgICAgICAgY29uc29sZS5lcnJvcihlKTsKICAgICAgICAgICAgdGhyb3cgZTsKICAgICAgICAgIH0pOwogICAgICAgICAgdGhpcy5jYWNoZS5zZXQoa2V5LCBuZXdFbnRyeSk7CiAgICAgICAgfQogICAgICAgIHN0YXRpYyBjaGVja1NpbmdsZVByb21pc2UocHJvbWlzZSwgc2lnbmFsKSB7CiAgICAgICAgICBmdW5jdGlvbiBjaGVja0ZvclNpbmdsZUFib3J0KCkgewogICAgICAgICAgICBpZiAoc2lnbmFsICYmIHNpZ25hbC5hYm9ydGVkKSB7CiAgICAgICAgICAgICAgdGhyb3cgT2JqZWN0LmFzc2lnbihuZXcgRXJyb3IoImFib3J0ZWQiKSwgeyBjb2RlOiAiRVJSX0FCT1JURUQiIH0pOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gcHJvbWlzZS50aGVuKChyZXN1bHQpID0+IHsKICAgICAgICAgICAgY2hlY2tGb3JTaW5nbGVBYm9ydCgpOwogICAgICAgICAgICByZXR1cm4gcmVzdWx0OwogICAgICAgICAgfSwgKGVycm9yKSA9PiB7CiAgICAgICAgICAgIGNoZWNrRm9yU2luZ2xlQWJvcnQoKTsKICAgICAgICAgICAgdGhyb3cgZXJyb3I7CiAgICAgICAgICB9KTsKICAgICAgICB9CiAgICAgICAgaGFzKGtleSkgewogICAgICAgICAgcmV0dXJuIHRoaXMuY2FjaGUuaGFzKGtleSk7CiAgICAgICAgfQogICAgICAgIGdldChrZXksIGRhdGEsIHNpZ25hbCwgc3RhdHVzQ2FsbGJhY2spIHsK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bCwgc3RhdHVzQ2FsbGJhY2spOwogICAgICAgICAgcmV0dXJuIEFib3J0YWJsZVByb21pc2VDYWNoZTIuY2hlY2tTaW5nbGVQcm9taXNlKHRoaXMuY2FjaGUuZ2V0KGtleSkucHJvbWlzZSwgc2lnbmFsKTsKICAgICAgICB9CiAgICAgICAgZGVsZXRlKGtleSkgewogICAgICAgICAgY29uc3QgY2FjaGVkRW50cnkgPSB0aGlzLmNhY2hlLmdldChrZXkpOwogICAgICAgICAgaWYgKGNhY2hlZEVudHJ5KSB7CiAgICAgICAgICAgIGlmICghY2FjaGVkRW50cnkuc2V0dGxlZCkgewogICAgICAgICAgICAgIGNhY2hlZEVudHJ5LmFib3J0ZXIuYWJvcnQoKTsKICAgICAgICAgICAgfQogICAgICAgICAgICB0aGlzLmNhY2hlLmRlbGV0ZShrZXkpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBjbGVhcigpIHsKICAgICAgICAgIGNvbnN0IGtleUl0ZXIgPSB0aGlzLmNhY2hlLmtleXMoKTsKICAgICAgICAgIGxldCBkZWxldGVDb3VudCA9IDA7CiAgICAgICAgICBmb3IgKGxldCByZXN1bHQgPSBrZXlJdGVyLm5leHQoKTsgIXJlc3VsdC5kb25lOyByZXN1bHQgPSBrZXlJdGVyLm5leHQoKSkgewogICAgICAgICAgICB0aGlzLmRlbGV0ZShyZXN1bHQudmFsdWUpOwogICAgICAgICAgICBkZWxldGVDb3VudCArPSAxOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIGRlbGV0ZUNvdW50OwogICAgICAgIH0KICAgICAgfTsKICAgICAgZXhwb3J0czIuZGVmYXVsdCA9IEFib3J0YWJsZVByb21pc2VDYWNoZTI7CiAgICB9CiAgfSk7CgogIC8vIG5vZGVfbW9kdWxlcy8ucG5wbS9hYm9ydGFibGUtcHJvbWlzZS1jYWNoZUAxLjUuMC9ub2RlX21vZHVsZXMvYWJvcnRhYmxlLXByb21pc2UtY2FjaGUvZXNtL2luZGV4Lmpz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pY3QiOwogICAgICB2YXIgUXVpY2tMUlUgPSBjbGFzcyB7CiAgICAgICAgY29uc3RydWN0b3Iob3B0aW9ucyA9IHt9KSB7CiAgICAgICAgICBpZiAoIShvcHRpb25zLm1heFNpemUgJiYgb3B0aW9ucy5tYXhTaXplID4gMCkpIHsKICAgICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcigiYG1heFNpemVgIG11c3QgYmUgYSBudW1iZXIgZ3JlYXRlciB0aGFuIDAiKTsKICAgICAgICAgIH0KICAgICAgICAgIHRoaXMubWF4U2l6ZSA9IG9wdGlvbnMubWF4U2l6ZTsKICAgICAgICAgIHRoaXMuY2FjaGUgPSBuZXcgTWFwKCk7CiAgICAgICAgICB0aGlzLm9sZENhY2hlID0gbmV3IE1hcCgpOwogICAgICAgICAgdGhpcy5fc2l6ZSA9IDA7CiAgICAgICAgfQogICAgICAgIF9zZXQoa2V5LCB2YWx1ZSkgewogICAgICAgICAgdGhpcy5jYWNoZS5zZXQoa2V5LCB2YWx1ZSk7CiAgICAgICAgICB0aGlzLl9zaXplKys7CiAgICAgICAgICBpZiAodGhpcy5fc2l6ZSA+PSB0aGlzLm1heFNpemUpIHsKICAgICAgICAgICAgdGhpcy5fc2l6ZSA9IDA7CiAgICAgICAgICAgIHRoaXMub2xkQ2FjaGUgPSB0aGlzLmNhY2hlOwogICAgICAgICAgICB0aGlzLmNhY2hlID0gbmV3IE1hcCgpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBnZXQoa2V5KSB7CiAgICAgICAgICBpZiAodGhpcy5jYWNoZS5oYXMoa2V5KSkgewogICAgICAgICAgICByZXR1cm4gdGhpcy5jYWNoZS5nZXQoa2V5KTsKICAgICAgICAgIH0KICAgICAgICAgIGlmICh0aGlzLm9sZENhY2hlLmhhcyhrZXkpKSB7CiAgICAgICAgICAgIGNvbnN0IHZhbHVlID0gdGhpcy5vbGRDYWNoZS5nZXQoa2V5KTsKICAgICAgICAgICAgdGhpcy5vbGRDYWNoZS5kZWxldGUoa2V5KTsKICAgICAgICAgICAgdGhpcy5fc2V0KGtleSwgdmFsdWUpOwogICAgICAgICAgICByZXR1cm4gdmFsdWU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHNldChrZXksIHZhbHVlKSB7CiAgICAgICAgICBpZiAodGhpcy5jYWNoZS5oYXMoa2V5KSkgewogICAgICAgICAgICB0aGlzLmNhY2hlLnNldChrZXksIHZhbHVlKTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHRoaXMuX3NldChrZXksIHZhbHVlKTsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiB0aGlzOwogICAgICAgIH0KICAgICAgICBoYXMoa2V5KSB7CiAgICAgICAgICByZXR1cm4gdGhpcy5jYWNoZS5oYXMoa2V5KSB8fCB0aGlzLm9sZENhY2hlLmhhcyhrZXkpOwogICAgICAgIH0KICAgICAgICBwZWVrKGtleSkgewogICAgICAgICAgaWYgKHRoaXMuY2FjaGUuaGFzKGtleSkpIHsKICAgICAgICAgICAgcmV0dXJuIHRoaXMuY2FjaGUuZ2V0KGtleSk7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAodGhpcy5vbGRDYWNoZS5oYXMoa2V5KSkgewogICAgICAgICAgICByZXR1cm4gdGhpcy5vbGRDYWNoZS5nZXQoa2V5KTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZGVsZXRlKGtleSkgewogICAgICAgICAgY29uc3QgZGVsZXRlZCA9IHRoaXMuY2FjaGUuZGVsZXRlKGtleSk7CiAgICAgICAgICBpZiAoZGVsZXRlZCkgewogICAgICAgICAgICB0aGlzLl9zaXplLS07CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gdGhpcy5vbGRDYWNoZS5kZWxldGUoa2V5KSB8fCBkZWxldGVkOwogICAgICAgIH0KICAgICAgICBjbGVhcigpIHsKICAgICAgICAgIHRoaXMuY2FjaGUuY2xlYXIoKTsKICAgICAgICAgIHRoaXMub2xkQ2FjaGUuY2xlYXIoKTsKICAgICAgICAgIHRoaXMuX3NpemUgPSAwOwogICAgICAgIH0KICAgICAgICAqa2V5cygpIHsKICAgICAgICAgIGZvciAoY29uc3QgW2tleV0gb2YgdGhpcykgewogICAgICAgICAgICB5aWVsZCBrZXk7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgICp2YWx1ZXMoKSB7CiAgICAgICAgICBmb3IgKGNvbnN0IFssIHZhbHVlXSBvZiB0aGlzKSB7CiAgICAgICAgICAgIHlpZWxkIHZhbHVlOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICAqW1N5bWJvbC5pdGVyYXRvcl0oKSB7CiAgICAgICAgICBmb3IgKGNvbnN0IGl0ZW0gb2YgdGhpcy5jYWNoZSkgewogICAgICAgICAgICB5aWVsZCBpdGVtOwogICAgICAgICAgfQogICAgICAgICAgZm9yIChjb25zdCBpdGVtIG9mIHRoaXMub2xkQ2FjaGUpIHsKICAgICAgICAgICAgY29uc3QgW2tleV0gPSBpdGVtOwogICAgICAgICAgICBpZiAoIXRoaXMuY2FjaGUuaGFzKGtleSkpIHsKICAgICAgICAgICAgICB5aWVsZCBpdGVtOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGdldCBzaXplKCkgewogICAgICAgICAgbGV0IG9sZENhY2hlU2l6ZSA9IDA7CiAgICAgICAgICBmb3IgKGNvbnN0IGtleSBvZiB0aGlzLm9sZENhY2hlLmtleXMoKSkgewogICAgICAgICAgICBpZiAoIXRoaXMuY2FjaGUuaGFzKGtleSkpIHsKICAgICAgICAgICAgICBvbGRDYWNoZVNpemUrKzsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIHRoaXMuX3NpemUgKyBvbGRDYWNoZVNpemU7CiAgICAgICAgfQogICAgICB9OwogICAgICBtb2R1bGUyLmV4cG9ydHMgPSBRdWlja0xSVTsKICAgIH0KICB9KTsKCiAgLy8gKGRpc2FibGVkKTpub2RlX21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ZS5zbGljZS5jYWxsKGFyZ3VtZW50cywgMSk7CiAgICAgICAgd2hpbGUgKHNvdXJjZXMubGVuZ3RoKSB7CiAgICAgICAgICB2YXIgc291cmNlID0gc291cmNlcy5zaGlmdCgpOwogICAgICAgICAgaWYgKCFzb3VyY2UpIHsKICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAodHlwZW9mIHNvdXJjZSAhPT0gIm9iamVjdCIpIHsKICAgICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcihzb3VyY2UgKyAibXVzdCBiZSBub24tb2JqZWN0Iik7CiAgICAgICAgICB9CiAgICAgICAgICBmb3IgKHZhciBwIGluIHNvdXJjZSkgewogICAgICAgICAgICBpZiAoX2hhcyhzb3VyY2UsIHApKSB7CiAgICAgICAgICAgICAgb2JqW3BdID0gc291cmNlW3BdOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiBvYmo7CiAgICAgIH07CiAgICAgIGV4cG9ydHMyLnNocmlua0J1ZiA9IGZ1bmN0aW9uKGJ1Ziwgc2l6ZSkgewogICAgICAgIGlmIChidWYubGVuZ3RoID09PSBzaXplKSB7CiAgICAgICAgICByZXR1cm4gYnVmOwogICAgICAgIH0KICAgICAgICBpZiAoYnVmLnN1YmFycmF5KSB7CiAgICAgICAgICByZXR1cm4gYnVmLnN1YmFycmF5KDAsIHNpemUpOwogICAgICAgIH0KICAgICAgICBidWYubGVuZ3RoID0gc2l6ZTsKICAgICAgICByZXR1cm4gYnVmOwogICAgICB9OwogICAgICB2YXIgZm5UeXBlZCA9IHsKICAgICAgICBhcnJheVNldDogZnVuY3Rpb24oZGVzdCwgc3JjLCBzcmNfb2ZmcywgbGVuLCBkZXN0X29mZnMpIHsKICAgICAgICAgIGlmIChzcmMuc3ViYXJyYXkgJiYgZGVzdC5zdWJhcnJheSkgewogICAgICAgICAgICBkZXN0LnNldChzcmMuc3ViYXJyYXkoc3JjX29mZnMsIHNyY19vZmZzICsgbGVuKSwgZGVzdF9vZmZzKTsKICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgfQogICAgICAgICAgZm9yICh2YXIgaSA9IDA7IGkgPCBsZW47IGkrKykgewogICAgICAgICAgICBkZXN0W2Rlc3Rfb2ZmcyArIGldID0gc3JjW3NyY19vZmZzICsgaV07CiAgICAgICAgICB9CiAgICAgICAgfSwKICAgICAgICBmbGF0dGVuQ2h1bmtzOiBmdW5jdGlvbihjaHVua3MpIHsKICAgICAgICAgIHZhciBpLCBsLCBsZW4sIHBvcywgY2h1bmssIHJlc3VsdDsKICAgICAgICAgIGxlbiA9IDA7CiAgICAgICAgICBmb3IgKGkgPSAwLCBsID0gY2h1bmtzLmxlbmd0aDsgaSA8IGw7IGkrKykgewogICAgICAgICAgICBsZW4gKz0gY2h1bmtzW2ldLmxlbmd0aDsKICAgICAgICAgIH0KICAgICAgICAgIHJlc3VsdCA9IG5ldyBVaW50OEFycmF5KGxlbik7CiAgICAgICAgICBwb3MgPSAwOwogICAgICAgICAgZm9yIChpID0gMCwgbCA9IGNodW5rcy5sZW5ndGg7IGkgPCBsOyBpKyspIHsKICAgICAgICAgICAgY2h1bmsgPSBjaHVua3NbaV07CiAgICAgICAgICAgIHJlc3VsdC5zZXQoY2h1bmssIHBvcyk7CiAgICAgICAgICAgIHBvcyArPSBjaHVuay5sZW5ndGg7CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gcmVzdWx0OwogICAgICAgIH0KICAgICAgfTsKICAgICAgdmFyIGZuVW50eXBlZCA9IHsKICAgICAgICBhcnJheVNldDogZnVuY3Rpb24oZGVzdCwgc3JjLCBzcmNfb2ZmcywgbGVuLCBkZXN0X29mZnMpIHsKICAgICAgICAgIGZvciAodmFyIGkgPSAwOyBpIDwgbGVuOyBpKyspIHsKICAgICAgICAgICAgZGVzdFtkZXN0X29mZnMgKyBpXSA9IHNyY1tzcmNfb2ZmcyArIGldOwogICAgICAgICAgfQogICAgICAgIH0sCiAgICAgICAgZmxhdHRlbkNodW5rczogZnVuY3Rpb24oY2h1bmtzKSB7CiAgICAgICAgICByZXR1cm4gW10uY29uY2F0LmFwcGx5KFtdLCBjaHVua3MpOwogICAgICAgIH0KICAgICAgfTsKICAgICAgZXhwb3J0czIuc2V0VHlwZWQgPSBmdW5jdGlvbihvbikgewogICAgICAgIGlmIChvbikgewogICAgICAgICAgZXhwb3J0czIuQnVmOCA9IFVpbnQ4QXJyYXk7CiAgICAgICAgICBleHBvcnRzMi5CdWYxNiA9IFVpbnQxNkFycmF5OwogICAgICAgICAgZXhwb3J0czIuQnVmMzIgPSBJbnQzMkFycmF5OwogICAgICAgICAgZXhwb3J0czIuYXNzaWduKGV4cG9ydHMyLCBmblR5cGVkKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgZXhwb3J0czIuQnVmOCA9IEFycmF5OwogICAgICAgICAgZXhwb3J0czIuQnVmMTYgPSBBcnJheTsKICAgICAgICAgIGV4cG9ydHMyLkJ1ZjMyID0gQXJyYXk7CiAgICAgICAgICBleHBvcnRzMi5hc3NpZ24oZXhwb3J0czIsIGZuVW50eXBlZCk7CiAgICAgICAgfQogICAgICB9OwogICAgICBleHBvcnRzMi5zZXRUeXBlZChUWVBFRF9PSyk7CiAgICB9CiAgfSk7CgogIC8vIG5vZGVfbW9kdWxlcy8ucG5wbS9wYWtvQDEuMC4xMS9ub2RlX21vZHVsZXMvcGFrby9saWIvemxpYi90cmVlcy5qcwogIHZhciByZXF1aXJlX3RyZWVzID0gX19jb21tb25KUyh7CiAgICAibm9kZV9tb2R1bGVzLy5wbnBtL3Bha29AMS4wLjExL25vZGVfbW9kdWxlcy9wYWtvL2xpYi96bGliL3RyZWVzLmpzIihleHBvcnRzMikgewogICAgICBpbml0X2J1ZmZlcl9zaGltKCk7CiAgICAgICJ1c2Ugc3RyaWN0IjsKICAgICAgdmFyIHV0aWxzID0gcmVxdWlyZV9jb21tb24oKTsKICAgICAgdmFyIFpfRklYRUQgPS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IDIgKyAxXSArIDE7CiAgICAgICAgICBpZiAoYml0cyA+IG1heF9sZW5ndGgpIHsKICAgICAgICAgICAgYml0cyA9IG1heF9sZW5ndGg7CiAgICAgICAgICAgIG92ZXJmbG93Kys7CiAgICAgICAgICB9CiAgICAgICAgICB0cmVlW24gKiAyICsgMV0gPSBiaXRzOwogICAgICAgICAgaWYgKG4gPiBtYXhfY29kZSkgewogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgIH0KICAgICAgICAgIHMuYmxfY291bnRbYml0c10rKzsKICAgICAgICAgIHhiaXRzID0gMDsKICAgICAgICAgIGlmIChuID49IGJhc2UpIHsKICAgICAgICAgICAgeGJpdHMgPSBleHRyYVtuIC0gYmFzZV07CiAgICAgICAgICB9CiAgICAgICAgICBmID0gdHJlZVtuICogMl07CiAgICAgICAgICBzLm9wdF9sZW4gKz0gZiAqIChiaXRzICsgeGJpdHMpOwogICAgICAgICAgaWYgKGhhc19zdHJlZSkgewogICAgICAgICAgICBzLnN0YXRpY19sZW4gKz0gZiAqIChzdHJlZVtuICogMiArIDFdICsgeGJpdHMpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAob3ZlcmZsb3cgPT09IDApIHsKICAgICAgICAgIHJldHVybjsKICAgICAgICB9CiAgICAgICAgZG8gewogICAgICAgICAgYml0cyA9IG1heF9sZW5ndGggLSAxOwogICAgICAgICAgd2hpbGUgKHMuYmxfY291bnRbYml0c10gPT09IDApIHsKICAgICAgICAgICAgYml0cy0tOwogICAgICAgICAgfQogICAgICAgICAgcy5ibF9jb3VudFtiaXRzXS0tOwogICAgICAgICAgcy5ibF9jb3VudFtiaXRzICsgMV0gKz0gMjsKICAgICAgICAgIHMuYmxfY291bnRbbWF4X2xlbmd0aF0tLTsKICAgICAgICAgIG92ZXJmbG93IC09IDI7CiAgICAgICAgfSB3aGlsZSAob3ZlcmZsb3cgPiAwKTsKICAgICAgICBmb3IgKGJpdHMgPSBtYXhfbGVuZ3RoOyBiaXRzICE9PSAwOyBiaXRzLS0pIHsKICAgICAgICAgIG4gPSBzLmJsX2NvdW50W2JpdHNdOwogICAgICAgICAgd2hpbGUgKG4gIT09IDApIHsKICAgICAgICAgICAgbSA9IHMuaGVhcFstLWhdOwogICAgICAgICAgICBpZiAobSA+IG1heF9jb2RlKSB7CiAgICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHRyZWVbbSAqIDIgKyAxXSAhPT0gYml0cykgewogICAgICAgICAgICAgIHMub3B0X2xlbiArPSAoYml0cyAtIHRyZWVbbSAqIDIgKyAxXSkgKiB0cmVlW20gKiAyXTsKICAgICAgICAgICAgICB0cmVlW20gKiAyICsgMV0gPSBiaXRzOwogICAgICAgICAgICB9CiAgICAgICAgICAgIG4tLTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZ2VuX2NvZGVzKHRyZWUsIG1heF9jb2RlLCBibF9jb3VudCkgewogICAgICAgIHZhciBuZXh0X2NvZGUgPSBuZXcgQXJyYXkoTUFYX0JJVFMgKyAxKTsKICAgICAgICB2YXIgY29kZSA9IDA7CiAgICAgICAgdmFyIGJpdHM7CiAgICAgICAgdmFyIG47CiAgICAgICAgZm9yIChiaXRzID0gMTsgYml0cyA8PSBNQVhfQklUUzsgYml0cysrKSB7CiAgICAgICAgICBuZXh0X2NvZGVbYml0c10gPSBjb2RlID0gY29kZSArIGJsX2NvdW50W2JpdHMgLSAxXSA8PCAxOwogICAgICAgIH0KICAgICAgICBmb3IgKG4gPSAwOyBuIDw9IG1heF9jb2RlOyBuKyspIHsKICAgICAgICAgIHZhciBsZW4gPSB0cmVlW24gKiAyICsgMV07CiAgICAgICAgICBpZiAobGVuID09PSAwKSB7CiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgfQogICAgICAgICAgdHJlZVtuICogMl0gPSBiaV9yZXZlcnNlKG5leHRfY29kZVtsZW5dKyssIGxlbik7CiAgICAgICAg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ICAgIF9kaXN0X2NvZGVbMjU2ICsgZGlzdCsrXSA9IGNvZGU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGZvciAoYml0cyA9IDA7IGJpdHMgPD0gTUFYX0JJVFM7IGJpdHMrKykgewogICAgICAgICAgYmxfY291bnRbYml0c10gPSAwOwogICAgICAgIH0KICAgICAgICBuID0gMDsKICAgICAgICB3aGlsZSAobiA8PSAxNDMpIHsKICAgICAgICAgIHN0YXRpY19sdHJlZVtuICogMiArIDFdID0gODsKICAgICAgICAgIG4rKzsKICAgICAgICAgIGJsX2NvdW50WzhdKys7CiAgICAgICAgfQogICAgICAgIHdoaWxlIChuIDw9IDI1NSkgewogICAgICAgICAgc3RhdGljX2x0cmVlW24gKiAyICsgMV0gPSA5OwogICAgICAgICAgbisrOwogICAgICAgICAgYmxfY291bnRbOV0rKzsKICAgICAgICB9CiAgICAgICAgd2hpbGUgKG4gPD0gMjc5KSB7CiAgICAgICAgICBzdGF0aWNfbHRyZWVbbiAqIDIgKyAxXSA9IDc7CiAgICAgICAgICBuKys7CiAgICAgICAgICBibF9jb3VudFs3XSsrOwogICAgICAgIH0KICAgICAgICB3aGlsZSAobiA8PSAyODcpIHsKICAgICAgICAgIHN0YXRpY19sdHJlZVtuICogMiArIDFdID0gODsKICAgICAgICAgIG4rKzsKICAgICAgICAgIGJsX2NvdW50WzhdKys7CiAgICAgICAgfQogICAgICAgIGdlbl9jb2RlcyhzdGF0aWNfbHRyZWUsIExfQ09ERVMgKyAxLCBibF9jb3VudCk7CiAgICAgICAgZm9yIChuID0gMDsgbiA8IERfQ09ERVM7IG4rKykgewogICAgICAgICAgc3RhdGljX2R0cmVlW24gKiAyICsgMV0gPSA1OwogICAgICAgICAgc3RhdGljX2R0cmVlW24gKiAyXSA9IGJpX3JldmVyc2UobiwgNSk7CiAgICAgICAgfQogICAgICAgIHN0YXRpY19sX2Rlc2MgPSBuZXcgU3RhdGljVHJlZURlc2Moc3RhdGljX2x0cmVlLCBleHRyYV9sYml0cywgTElURVJBTFMgKyAxLCBMX0NPREVTLCBNQVhfQklUUyk7CiAgICAgICAgc3RhdGljX2RfZGVzYyA9IG5ldyBTdGF0aWNUcmVlRGVzYyhzdGF0aWNfZHRyZWUsIGV4dHJhX2RiaXRzLCAwLCBEX0NPREVTLCBNQVhfQklUUyk7CiAgICAgICAgc3RhdGljX2JsX2Rlc2MgPSBuZXcgU3RhdGljVHJlZURlc2MobmV3IEFycmF5KDApLCBleHRyYV9ibGJpdHMsIDAsIEJMX0NPREVTLCBNQVhfQkxfQklUUyk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gaW5pdF9ibG9jayhzKSB7CiAgICAgICAgdmFyIG47CiAgICAgICAgZm9yIChuID0gMDsgbiA8IExfQ09ERVM7IG4rKykgewogICAgICAgICAgcy5keW5fbHRyZWVbbiAqIDJdID0gMDsKICAgICAgICB9CiAgICAgICAgZm9yIChuID0gMDsgbiA8IERfQ09ERVM7IG4rKykgewogICAgICAgICAgcy5keW5fZHRyZWVbbiAqIDJdID0gMDsKICAgICAgICB9CiAgICAgICAgZm9yIChuID0gMDsgbiA8IEJMX0NPREVTOyBuKyspIHsKICAgICAgICAgIHMuYmxfdHJlZVtuICogMl0gPSAwOwogICAgICAgIH0KICAgICAgICBzLmR5bl9sdHJlZVtFTkRfQkxPQ0sgKiAyXSA9IDE7CiAgICAgICAgcy5vcHRfbGVuID0gcy5zdGF0aWNfbGVuID0gMDsKICAgICAgICBzLmxhc3RfbGl0ID0gcy5tYXRjaGVzID0gMDsKICAgICAgfQogICAgICBmdW5jdGlvbiBiaV93aW5kdXAocykgewogICAgICAgIGlmIChzLmJpX3ZhbGlkID4gOCkgewogICAgICAgICAgcHV0X3Nob3J0KHMsIHMuYmlfYnVmKTsKICAgICAgICB9IGVsc2UgaWYgKHMuYmlfdmFsaWQgPiAwKSB7CiAgICAgICAgICBzLnBlbmRpbmdfYnVmW3MucGVuZGluZysrXSA9IHMuYmlfYnVmOwogICAgICAgIH0KICAgICAgICBzLmJpX2J1ZiA9IDA7CiAgICAgICAgcy5iaV92YWxpZCA9IDA7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gY29weV9ibG9jayhzLCBidWYsIGxlbiwgaGVhZGVyKSB7CiAgICAgICAgYmlfd2luZHVwKHMpOwogICAgICAgIGlmIChoZWFkZXIpIHsKICAgICAgICAgIHB1dF9zaG9ydChzLCBsZW4pOwogICAgICAgICAgcHV0X3Nob3J0KHMsIH5sZW4pOwogICAgICAgIH0KICAgICAgICB1dGlscy5hcnJheVNldChzLnBlbmRpbmdfYnVmLCBzLndpbmRvdywgYnVmLCBsZW4sIHMucGVuZGluZyk7CiAgICAgICAgcy5wZW5kaW5nICs9IGxlbjsKICAgICAgfQogICAgICBmdW5jdGlvbiBzbWFsbGVyKHRyZWUsIG4sIG0sIGRlcHRoKSB7CiAgICAgICAgdmFyIF9uMiA9IG4gKiAyOwogICAgICAgIHZhciBfbTIgPSBtICogMjsKICAgICAgICByZXR1cm4gdHJlZVtfbjJdIDwgdHJlZVtfbTJdIHx8IHRyZWVbX24yXSA9PT0gdHJlZVtfbTJdICYmIGRlcHRoW25dIDw9IGRlcHRoW21dOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIHBxZG93bmhlYXAocywgdHJlZSwgaykgewogICAgICAgIHZhciB2ID0gcy5oZWFwW2tdOwogICAgICAgIHZhciBqID0gayA8PCAxOwogICAgICAgIHdoaWxlIChqIDw9IHMuaGVhcF9sZW4pIHsKICAgICAgICAgIGlmIChqIDwgcy5oZWFwX2xlbiAmJiBzbWFsbGVyKHRyZWUsIHMuaGVhcFtqICsgMV0sIHMuaGVhcFtqXSwgcy5kZXB0aCkpIHsKICAgICAgICAgICAgaisrOwogICAgICAgICAgfQogICAgICAgICAgaWYgKHNtYWxsZXIodHJlZSwgdiwgcy5oZWFwW2pdLCBzLmRlcHRoKSkgewogICAgICAgICAgICBicmVhazsKICAgICAgICAgIH0KICAgICAgICAgIHMuaGVhcFtrXSA9IHMuaGVhcFtqXTsKICAgICAgICAgIGsgPSBqOwogICAgICAgICAgaiA8PD0gMTsKICAgICAgICB9CiAgICAgICAgcy5oZWFwW2tdID0gdjsKICAgICAgfQogICAgICBmdW5jdGlvbiBjb21wcmVzc19ibG9jayhzLCBsdHJlZSwgZHRyZWUpIHsKICAgICAgICB2YXIgZGlzdDsKICAgICAgICB2YXIgbGM7CiAgICAgICAgdmFyIGx4ID0gMDsKICAgICAgICB2YXIgY29kZTsKICAgICAgICB2YXIgZXh0cmE7CiAgICAgICAgaWYgKHMubGFzdF9saXQgIT09IDApIHsKICAgICAgICAgIGRvIHsKICAgICAgICAgICAgZGlzdCA9IHMucGVuZGluZ19idWZbcy5kX2J1ZiArIGx4ICogMl0gPDwgOCB8IHMucGVuZGluZ19idWZbcy5kX2J1ZiArIGx4ICogMiArIDFdOwogICAgICAgICAgICBsYyA9IHMucGVuZGluZ19idWZbcy5sX2J1ZiArIGx4XTsKICAgICAgICAgICAgbHgrKzsKICAgICAgICAgICAgaWYgKGRpc3QgPT09IDApIHsKICAgICAgICAgICAgICBzZW5kX2NvZGUocywgbGMsIGx0cmVlKTsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICBjb2RlID0gX2xlbmd0aF9jb2RlW2xjXTsKICAgICAgICAgICAgICBzZW5kX2NvZGUocywgY29kZSArIExJVEVSQUxTICsgMSwgbHRyZWUpOwogICAgICAgICAgICAgIGV4dHJhID0gZXh0cmFfbGJpdHNbY29kZV07CiAgICAgICAgICAgICAgaWYgKGV4dHJhICE9PSAwKSB7CiAgICAgICAgICAgICAgICBsYyAtPSBiYXNlX2xlbmd0aFtjb2RlXTsKICAgICAgICAgICAgICAgIHNlbmRfYml0cyhzLCBsYywgZXh0cmEpOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBkaXN0LS07CiAgICAgICAgICAgICAgY29kZSA9IGRfY29kZShkaXN0KTsKICAgICAgICAgICAgICBzZW5kX2NvZGUocywgY29kZSwgZHRyZWUpOwogICAgICAgICAgICAgIGV4dHJhID0gZXh0cmFfZGJpdHNbY29kZV07CiAgICAgICAgICAgICAgaWYgKGV4dHJhICE9PSAwKSB7CiAgICAgICAgICAgICAgICBkaXN0IC09IGJhc2VfZGlzdFtjb2RlXTsKICAgICAgICAgICAgICAgIHNlbmRfYml0cyhzLCBkaXN0LCBleHRyYSk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICB9IHdoaWxlIChseCA8IHMubGFzdF9saXQpOwogICAgICAgIH0KICAgICAgICBzZW5kX2NvZGUocywgRU5EX0JMT0NLLCBsdHJlZSk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gYnVpbGRfdHJlZShzLCBkZXNjKSB7CiAgICAgICAgdmFyIHRyZWUgPSBkZXNjLmR5bl90cmVlOwogICAgICAgIHZhciBzdHJlZSA9IGRlc2Muc3RhdF9kZXNjLnN0YXRpY190cmVlOwogICAgICAgIHZhciBoYXNfc3RyZWUgPSBkZXNjLnN0YXRfZGVzYy5oYXNfc3RyZWU7CiAgICAgICAgdmFyIGVsZW1zID0gZGVzYy5zdGF0X2Rlc2MuZWxlbXM7CiAgICAgICAgdmFyIG4sIG07CiAgICAgICAgdmFyIG1heF9jb2RlID0gLTE7CiAgICAgICAgdmFyIG5vZGU7CiAgICAgICAgcy5oZWFwX2xlbiA9IDA7CiAgICAgICAgcy5oZWFwX21heCA9IEhFQVBfU0laRTsKICAgICAgICBmb3IgKG4gPSAwOyBuIDwgZWxlbXM7IG4rKykgewogICAgICAgICAgaWYgKHRyZWVbbiAqIDJdICE9PSAwKSB7CiAgICAgICAgICAgIHMuaGVhcFsrK3MuaGVhcF9sZW5dID0gbWF4X2NvZGUgPSBuOwogICAgICAgICAgICBzLmRlcHRoW25dID0gMDsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHRyZWVbbiAqIDIgKyAxXSA9IDA7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHdoaWxlIChzLmhlYXBfbGVuIDwgMikgewogICAgICAgICAgbm9kZSA9IHMuaGVhcFsrK3MuaGVhcF9sZW5dID0gbWF4X2NvZGUgPCAyID8gKyttYXhfY29kZSA6IDA7CiAgICAgICAgICB0cmVlW25vZGUgKiAyXSA9IDE7CiAgICAgICAgICBzLmRlcHRoW25vZGVdID0gMDsKICAgICAgICAgIHMub3B0X2xlbi0tOwogICAgICAgICAgaWYgKGhhc19zdHJlZSkgewogICAgICAgICAgICBzLnN0YXRpY19sZW4gLT0gc3RyZWVbbm9kZSAqIDIgKyAxXTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZGVzYy5tYXhfY29kZSA9IG1heF9jb2RlOwogICAgICAgIGZvciAobiA9IHMuaGVhcF9sZW4gPj4gMTsgbiA+PSAxOyBuLS0pIHsKICAgICAgICAgIHBxZG93bmhlYXAocywgdHJlZSwgbik7CiAgICAgICAgfQogICAgICAgIG5vZGUgPSBlbGVtczsKICAgICAgICBkbyB7CiAgICAgICAgICBuID0gcy5oZWFwWzFdOwogICAgICAgICAgcy5oZWFwWzFdID0gcy5oZWFwW3MuaGVhcF9sZW4tLV07CiAgICAgICAgICBwcWRvd25oZWFwKHMsIHRyZWUsIDEpOwogICAgICAgICAgbSA9IHMuaGVhcFsxXTsKICAgICAgICAgIHMuaGVhcFstLXMuaGVhcF9tYXhdID0gbjsKICAgICAgICAgIHMuaGVhcFstLXMuaGVhcF9tYXhdID0gbTsKICAgICAgICAgIHRyZWVbbm9kZSAqIDJdID0gdHJlZVtuICogMl0gKyB0cmVlW20gKiAyXTsKICAgICAgICAgIHMuZGVwdGhbbm9kZV0gPSAocy5kZXB0aFtuXSA+PSBzLmRlcHRoW21dID8gcy5kZXB0aFtuXSA6IHMuZGVwdGhbbV0pICsgMTsKICAgICAgICAgIHRyZWVbbiAqIDIgKyAxXSA9IHRyZWVbbSAqIDIgKyAxXSA9IG5vZGU7CiAgICAgICAgICBzLmhlYXBbMV0gPSBub2RlKys7CiAgICAgICAgICBwcWRvd25oZWFwKHMsIHRyZWUsIDEpOwogICAgICAgIH0gd2hpbGUgKHMuaGVhcF9sZW4gPj0gMik7CiAgICAgICAgcy5oZWFwWy0tcy5oZWFwX21heF0gPSBzLmhlYXBbMV07CiAgICAgICAgZ2VuX2JpdGxlbihzLCBkZXNjKTsKICAgICAgICBnZW5fY29kZXModHJlZSwgbWF4X2NvZGUsIHMuYmxfY291bnQpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIHNjYW5fdHJlZShzLCB0cmVlLCBtYXhfY29kZSkgewogICAgICAgIHZhciBuOwogICAgICAgIHZhciBwcmV2bGVuID0gLTE7CiAgICAgICAgdmFyIGN1cmxlbjsKICAgICAgICB2YXIgbmV4dGxlbiA9IHRyZWVbMCAqIDIgKyAxXTsKICAgICAgICB2YXIgY291bnQgPSAwOwogICAgICAgIHZhciBtYXhfY291bnQgPSA3OwogICAgICAgIHZhciBtaW5fY291bnQgPSA0OwogICAgICAgIGlmIChuZXh0bGVuID09PSAwKSB7CiAgICAgICAgICBtYXhfY291bnQgPSAxMzg7CiAgICAgICAgICBtaW5fY291bnQgPSAzOwogICAgICAgIH0KICAgICAgICB0cmVlWyhtYXhfY29kZSArIDEpICogMiArIDFdID0gNjU1MzU7CiAgICAgICAgZm9yIChuID0gMDsgbiA8PSBtYXhfY29kZTsgbisrKSB7CiAgICAgICAgICBjdXJsZW4gPSBuZXh0bGVuOwogICAgICAgICAgbmV4dGxlbiA9IHRyZWVbKG4gKyAxKSAqIDIgKyAxXTsKICAgICAgICAgIGlmICgrK2NvdW50IDwgbWF4X2NvdW50ICYmIGN1cmxlbiA9PT0gbmV4dGxlbikgewogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgIH0gZWxzZSBpZiAoY291bnQgPCBtaW5fY291bnQpIHsKICAgICAgICAgICAgcy5ibF90cmVlW2N1cmxlbiAqIDJdICs9IGNvdW50OwogICAgICAgICAgfSBlbHNlIGlmIChjdXJsZW4gIT09IDApIHsKICAgICAgICAgICAgaWYgKGN1cmxlbiAhPT0gcHJldmxlbikgewogICAgICAgICAgICAgIHMuYmxfdHJlZVtjdXJsZW4gKiAyXSsrOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHMuYmxfdHJlZVtSRVBfM182ICogMl0rKzsKICAgICAgICAgIH0gZWxzZSBpZiAoY291bnQgPD0gMTApIHsKICAgICAgICAgICAgcy5ibF90cmVlW1JFUFpfM18xMCAqIDJdKys7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBzLmJsX3RyZWVbUkVQWl8xMV8xMzggKiAyXSsrOwogICAgICAgICAgfQogICAgICAgICAgY291bnQgPSAwOwogICAgICAgICAgcHJldmxlbiA9IGN1cmxlbjsKICAgICAgICAgIGlmIChuZXh0bGVuID09PSAwKSB7CiAgICAgICAgICAgIG1heF9jb3VudCA9IDEzODsKICAgICAgICAgICAgbWluX2NvdW50ID0gMzsKICAgICAgICAgIH0gZWxzZSBpZiAoY3VybGVuID09PSBuZXh0bGVuKSB7CiAgICAgICAgICAgIG1heF9jb3VudCA9IDY7CiAgICAgICAgICAgIG1pbl9jb3VudCA9IDM7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBtYXhfY291bnQgPSA3OwogICAgICAgICAgICBtaW5fY291bnQgPSA0OwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgICBmdW5jdGlvbiBzZW5kX3RyZWUocywgdHJlZSwgbWF4X2NvZGUpIHsKICAgICAgICB2YXIgbjsKICAgICAgICB2YXIgcHJldmxlbiA9IC0xOwogICAgICAgIHZhciBjdXJsZW47CiAgICAgICAgdmFyIG5leHRsZW4gPSB0cmVlWzAgKiAyICsgMV07CiAgICAgICAgdmFyIGNvdW50ID0gMDsKICAgICAgICB2YXIgbWF4X2NvdW50ID0gNzsKICAgICAgICB2YXIgbWluX2NvdW50ID0gNDsKICAgICAgICBpZiAobmV4dGxlbiA9PT0gMCkgewogICAgICAgICAgbWF4X2NvdW50ID0gMTM4OwogICAgICAgICAgbWluX2NvdW50ID0gMzsKICAgICAgICB9CiAgICAgICAgZm9yIChuID0gMDsgbiA8PSBtYXhfY29kZTsgbisrKSB7CiAgICAgICAgICBjdXJsZW4gPSBuZXh0bGVuOwogICAgICAgICAgbmV4dGxlbiA9IHRyZWVbKG4gKyAxKSAqIDIgKyAxXTsKICAgICAgICAgIGlmICgrK2NvdW50IDwgbWF4X2NvdW50ICYmIGN1cmxlbiA9PT0gbmV4dGxlbikgewogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgIH0gZWxzZSBpZiAoY291bnQgPCBtaW5fY291bnQpIHsKICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgIHNlbmRfY29kZShzLCBjdXJsZW4sIHMuYmxfdHJlZSk7CiAgICAgICAgICAgIH0gd2hpbGUgKC0tY291bnQgIT09IDApOwogICAgICAgICAgfSBlbHNlIGlmIChjdXJsZW4gIT09IDApIHsKICAgICAgICAgICAgaWYgKGN1cmxlbiAhPT0gcHJldmxlbikgewogICAgICAgICAgICAgIHNlbmRfY29kZShzLCBjdXJsZW4sIHMuYmxfdHJlZSk7CiAgICAgICAgICAgICAgY291bnQtLTsKICAgICAgICAgICAgfQogICAgICAgICAgICBzZW5kX2NvZGUocywgUkVQXzNfNiwgcy5ibF90cmVlKTsKICAgICAgICAgICAgc2VuZF9iaXRzKHMsIGNvdW50IC0gMywgMik7CiAgICAgICAgICB9IGVsc2UgaWYgKGNvdW50IDw9IDEwKSB7CiAgICAgICAgICAgIHNlbmRfY29kZShzLCBSRVBaXzNfMTAsIHMuYmxfdHJlZSk7CiAgICAgICAgICAgIHNlbmRfYml0cyhzLCBjb3VudCAtIDMsIDMpOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgc2VuZF9jb2RlKHMsIFJFUFpfMTFfMTM4LCBzLmJsX3RyZWUpOwogICAgICAgICAgICBzZW5kX2JpdHMocywgY291bnQgLSAxMSwgNyk7CiAgICAgICAgICB9CiAgICAgICAgICBjb3VudCA9IDA7CiAgICAgICAgICBwcmV2bGVuID0gY3VybGVuOwogICAgICAgICAgaWYgKG5leHRsZW4gPT09IDApIHsKICAgICAgICAgICAgbWF4X2NvdW50ID0gMTM4OwogICAgICAgICAgICBtaW5fY291bnQgPSAzOwogICAgICAgICAgfSBlbHNlIGlmIChjdXJsZW4gPT09IG5leHRsZW4pIHsKICAgICAgICAgICAgbWF4X2NvdW50ID0gNjsKICAgICAgICAgICAgbWluX2NvdW50ID0gMzsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIG1heF9jb3VudCA9IDc7CiAgICAgICAgICAgIG1pbl9jb3VudCA9IDQ7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9CiAgICAgIGZ1bmN0aW9uIGJ1aWxkX2JsX3RyZWUocykgewogICAgICAgIHZhciBtYXhfYmxpbmRleDsKICAgICAgICBzY2FuX3RyZWUocywgcy5keW5fbHRyZWUsIHMubF9kZXNjLm1heF9jb2RlKTsKICAgICAgICBzY2FuX3RyZWUocywgcy5keW5fZHRyZWUsIHMuZF9kZXNjLm1heF9jb2RlKTsKICAgICAgICBidWlsZF90cmVlKHMsIHMuYmxfZGVzYyk7CiAgICAgICAgZm9yIChtYXhfYmxpbmRleCA9IEJMX0NPREVTIC0gMTsgbWF4X2JsaW5kZXggPj0gMzsgbWF4X2JsaW5kZXgtLSkgewogICAgICAgICAgaWYgKHMuYmxfdHJlZVtibF9vcmRlclttYXhfYmxpbmRleF0gKiAyICsgMV0gIT09IDApIHsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHMub3B0X2xlbiArPSAzICogKG1heF9ibGluZGV4ICsgMSkgKyA1ICsgNSArIDQ7CiAgICAgICAgcmV0dXJuIG1heF9ibGluZGV4OwogICAgICB9CiAgICAgIGZ1bmN0aW9uIHNlbmRfYWxsX3RyZWVzKHMsIGxjb2RlcywgZGNvZGVzLCBibGNvZGVzKSB7CiAgICAgICAgdmFyIHJhbms7CiAgICAgICAgc2VuZF9iaXRzKHMsIGxjb2RlcyAtIDI1NywgNSk7CiAgICAgICAgc2VuZF9iaXRzKHMsIGRjb2RlcyAtIDEsIDUpOwogICAgICAgIHNlbmRfYml0cyhzLCBibGNvZGVzIC0gNCwgNCk7CiAgICAgICAgZm9yIChyYW5rID0gMDsgcmFuayA8IGJsY29kZXM7IHJhbmsrKykgewogICAgICAgICAgc2VuZF9iaXRzKHMsIHMuYmxfdHJlZVtibF9vcmRlcltyYW5rXSAqIDIgKyAxXSwgMyk7CiAgICAgICAgfQogICAgICAgIHNlbmRfdHJlZShzLCBzLmR5bl9sdHJlZSwgbGNvZGVzIC0gMSk7CiAgICAgICAgc2VuZF90cmVlKHMsIHMuZHluX2R0cmVlLCBkY29kZXMgLSAxKTsKICAgICAgfQogICAgICBmdW5jdGlvbiBkZXRlY3RfZGF0YV90eXBlKHMpIHsKICAgICAgICB2YXIgYmxhY2tfbWFzayA9IDQwOTM2MjQ0NDc7CiAgICAgICAgdmFyIG47CiAgICAgICAgZm9yIChuID0gMDsgbiA8PSAzMTsgbisrLCBibGFja19tYXNrID4+Pj0gMSkgewogICAgICAgICAgaWYgKGJsYWNrX21hc2sgJiAxICYmIHMuZHluX2x0cmVlW24gKiAyXSAhPT0gMCkgewogICAgICAgICAgICByZXR1cm4gWl9CSU5BUlk7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChzLmR5bl9sdHJlZVs5ICogMl0gIT09IDAgfHwgcy5keW5fbHRyZWVbMTAgKiAyXSAhPT0gMCB8fCBzLmR5bl9sdHJlZVsxMyAqIDJdICE9PSAwKSB7CiAgICAgICAgICByZXR1cm4gWl9URVhUOwogICAgICAgIH0KICAgICAgICBmb3IgKG4gPSAzMjsgbiA8IExJVEVSQUxTOyBuKyspIHsKICAgICAgICAgIGlmIChzLmR5bl9sdHJlZVtuICogMl0gIT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIFpfVEVYVDsKICAgICAgICAgIH0KICAgICAgICB9C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ziwgc3RvcmVkX2xlbiwgbGFzdCkgewogICAgICAgIHZhciBvcHRfbGVuYiwgc3RhdGljX2xlbmI7CiAgICAgICAgdmFyIG1heF9ibGluZGV4ID0gMDsKICAgICAgICBpZiAocy5sZXZlbCA+IDApIHsKICAgICAgICAgIGlmIChzLnN0cm0uZGF0YV90eXBlID09PSBaX1VOS05PV04pIHsKICAgICAgICAgICAgcy5zdHJtLmRhdGFfdHlwZSA9IGRldGVjdF9kYXRhX3R5cGUocyk7CiAgICAgICAgICB9CiAgICAgICAgICBidWlsZF90cmVlKHMsIHMubF9kZXNjKTsKICAgICAgICAgIGJ1aWxkX3RyZWUocywgcy5kX2Rlc2MpOwogICAgICAgICAgbWF4X2JsaW5kZXggPSBidWlsZF9ibF90cmVlKHMpOwogICAgICAgICAgb3B0X2xlbmIgPSBzLm9wdF9sZW4gKyAzICsgNyA+Pj4gMzsKICAgICAgICAgIHN0YXRpY19sZW5iID0gcy5zdGF0aWNfbGVuICsgMyArIDcgPj4+IDM7CiAgICAgICAgICBpZiAoc3RhdGljX2xlbmIgPD0gb3B0X2xlbmIpIHsKICAgICAgICAgICAgb3B0X2xlbmIgPSBzdGF0aWNfbGVuYjsKICAgICAgICAgIH0KICAgICAgICB9IGVsc2UgewogICAgICAgICAgb3B0X2xlbmIgPSBzdGF0aWNfbGVuYiA9IHN0b3JlZF9sZW4gKyA1OwogICAgICAgIH0KICAgICAgICBpZiAoc3RvcmVkX2xlbiArIDQgPD0gb3B0X2xlbmIgJiYgYnVmICE9PSAtMSkgewogICAgICAgICAgX3RyX3N0b3JlZF9ibG9jayhzLCBidWYsIHN0b3JlZF9sZW4sIGxhc3QpOwogICAgICAgIH0gZWxzZSBpZiAocy5zdHJhdGVneSA9PT0gWl9GSVhFRCB8fCBzdGF0aWNfbGVuYiA9PT0gb3B0X2xlbmIpIHsKICAgICAgICAgIHNlbmRfYml0cyhzLCAoU1RBVElDX1RSRUVTIDw8IDEpICsgKGxhc3QgPyAxIDogMCksIDMpOwogICAgICAgICAgY29tcHJlc3NfYmxvY2socywgc3RhdGljX2x0cmVlLCBzdGF0aWNfZHRyZWUpOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBzZW5kX2JpdHMocywgKERZTl9UUkVFUyA8PCAxKSArIChsYXN0ID8gMSA6IDApLCAzKTsKICAgICAgICAgIHNlbmRfYWxsX3RyZWVzKHMsIHMubF9kZXNjLm1heF9jb2RlICsgMSwgcy5kX2Rlc2MubWF4X2NvZGUgKyAxLCBtYXhfYmxpbmRleCArIDEpOwogICAgICAgICAgY29tcHJlc3NfYmxvY2socywgcy5keW5fbHRyZWUsIHMuZHluX2R0cmVlKTsKICAgICAgICB9CiAgICAgICAgaW5pdF9ibG9jayhzKTsKICAgICAgICBpZiAobGFzdCkgewogICAgICAgICAgYmlfd2luZHVwKHMpOwogICAgICAgIH0KICAgICAgfQogICAgICBmdW5jdGlvbiBfdHJfdGFsbHkocywgZGlzdCwgbGMpIHsKICAgICAgICBzLnBlbmRpbmdfYnVmW3MuZF9idWYgKyBzLmxhc3RfbGl0ICogMl0gPSBkaXN0ID4+PiA4ICYgMjU1OwogICAgICAgIHMucGVuZGluZ19idWZbcy5kX2J1ZiArIHMubGFzdF9saXQgKiAyICsgMV0gPSBkaXN0ICYgMjU1OwogICAgICAgIHMucGVuZGluZ19idWZbcy5sX2J1ZiArIHMubGFzdF9saXRdID0gbGMgJiAyNTU7CiAgICAgICAgcy5sYXN0X2xpdCsrOwogICAgICAgIGlmIChkaXN0ID09PSAwKSB7CiAgICAgICAgICBzLmR5bl9sdHJlZVtsYyAqIDJdKys7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIHMubWF0Y2hlcysrOwogICAgICAgICAgZGlzdC0tOwogICAgICAgICAgcy5keW5fbHRyZWVbKF9sZW5ndGhfY29kZVtsY10gKyBMSVRFUkFMUyArIDEpICogMl0rKzsKICAgICAgICAgIHMuZHluX2R0cmVlW2RfY29kZShkaXN0KSAqIDJdKys7CiAgICAgICAg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bGUgKC0tbik7CiAgICAgICAgICBzMSAlPSA2NTUyMTsKICAgICAgICAgIHMyICU9IDY1NTIxOwogICAgICAgIH0KICAgICAgICByZXR1cm4gczEgfCBzMiA8PCAxNiB8IDA7CiAgICAgIH0KICAgICAgbW9kdWxlMi5leHBvcnRzID0gYWRsZXIzMjsKICAgIH0KICB9KTsKCiAgLy8gbm9kZV9tb2R1bGVzLy5wbnBtL3Bha29AMS4wLjExL25vZGVfbW9kdWxlcy9wYWtvL2xpYi96bGliL2NyYzMyLmpzCiAgdmFyIHJlcXVpcmVfY3JjMzIgPSBfX2NvbW1vbkpTKHsKICAgICJub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvY3JjMzIuanMiKGV4cG9ydHMyLCBtb2R1bGUyKSB7CiAgICAgIGluaXRfYnVmZmVyX3NoaW0oKTsKICAgICAgInVzZSBzdHJpY3QiOwogICAgICBmdW5jdGlvbiBtYWtlVGFibGUoKSB7CiAgICAgICAgdmFyIGMsIHRhYmxlID0gW107CiAgICAgICAgZm9yICh2YXIgbiA9IDA7IG4gPCAyNTY7IG4rKykgewogICAgICAgICAgYyA9IG47CiAgICAgICAgICBmb3IgKHZhciBrID0gMDsgayA8IDg7IGsrKykgewogICAgICAgICAgICBjID0gYyAmIDEgPyAzOTg4MjkyMzg0IF4gYyA+Pj4gMSA6IGMgPj4+IDE7CiAgICAgICAgICB9CiAgICAgICAgICB0YWJsZVtuXSA9IGM7CiAgICAgICAgfQogICAgICAgIHJldHVybiB0YWJsZTsKICAgICAgfQogICAgICB2YXIgY3JjVGFibGUgPSBtYWtlVGFibGUoKTsKICAgICAgZnVuY3Rpb24gY3JjMzIoY3JjLCBidWYsIGxlbiwgcG9zKSB7CiAgICAgICAgdmFyIHQgPSBjcmNUYWJsZSwgZW5kID0gcG9zICsgbGVuOwogICAgICAgIGNyYyBePSAtMTsKICAgICAgICBmb3IgKHZhciBpID0gcG9zOy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FYX1dCSVRTID0gMTU7CiAgICAgIHZhciBERUZfTUVNX0xFVkVMID0gODsKICAgICAgdmFyIExFTkdUSF9DT0RFUyA9IDI5OwogICAgICB2YXIgTElURVJBTFMgPSAyNTY7CiAgICAgIHZhciBMX0NPREVTID0gTElURVJBTFMgKyAxICsgTEVOR1RIX0NPREVTOwogICAgICB2YXIgRF9DT0RFUyA9IDMwOwogICAgICB2YXIgQkxfQ09ERVMgPSAxOTsKICAgICAgdmFyIEhFQVBfU0laRSA9IDIgKiBMX0NPREVTICsgMTsKICAgICAgdmFyIE1BWF9CSVRTID0gMTU7CiAgICAgIHZhciBNSU5fTUFUQ0ggPSAzOwogICAgICB2YXIgTUFYX01BVENIID0gMjU4OwogICAgICB2YXIgTUlOX0xPT0tBSEVBRCA9IE1BWF9NQVRDSCArIE1JTl9NQVRDSCArIDE7CiAgICAgIHZhciBQUkVTRVRfRElDVCA9IDMyOwogICAgICB2YXIgSU5JVF9TVEFURSA9IDQyOwogICAgICB2YXIgRVhUUkFfU1RBVEUgPSA2OTsKICAgICAgdmFyIE5BTUVfU1RBVEUgPSA3MzsKICAgICAgdmFyIENPTU1FTlRfU1RBVEUgPSA5MTsKICAgICAgdmFyIEhDUkNfU1RBVEUgPSAxMDM7CiAgICAgIHZhciBCVVNZX1NUQVRFID0gMTEzOwogICAgICB2YXIgRklOSVNIX1NUQVRFID0gNjY2OwogICAgICB2YXIgQlNfTkVFRF9NT1JFID0gMTsKICAgICAgdmFyIEJTX0JMT0NLX0RPTkUgPSAyOwogICAgICB2YXIgQlNfRklOSVNIX1NUQVJURUQgPSAzOwogICAgICB2YXIgQlNfRklOSVNIX0RPTkUgPSA0OwogICAgICB2YXIgT1NfQ09ERSA9IDM7CiAgICAgIGZ1bmN0aW9uIGVycihzdHJtLCBlcnJvckNvZGUpIHsKICAgICAgICBzdHJtLm1zZyA9IG1zZ1tlcnJvckNvZGVdOwogICAgICAgIHJldHVybiBlcnJvckNvZGU7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gcmFuayhmKSB7CiAgICAgICAgcmV0dXJuIChmIDw8IDEpIC0gKGYgPiA0ID8gOSA6IDApOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIHplcm8oYnVmKSB7CiAgICAgICAgdmFyIGxlbiA9IGJ1Zi5sZW5ndGg7CiAgICAgICAgd2hpbGUgKC0tbGVuID49IDApIHsKICAgICAgICAgIGJ1ZltsZW5dID0gMDsKICAgICAgICB9CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZmx1c2hfcGVuZGluZyhzdHJtKSB7CiAgICAgICAgdmFyIHMgPSBzdHJtLnN0YXRlOwogICAgICAgIHZhciBsZW4gPSBzLnBlbmRpbmc7CiAgICAgICAgaWYgKGxlbiA+IHN0cm0uYXZhaWxfb3V0KSB7CiAgICAgICAgICBsZW4gPSBzdHJtLmF2YWlsX291dDsKICAgICAgICB9CiAgICAgICAgaWYgKGxlbiA9PT0gMCkgewogICAgICAgICAgcmV0dXJuOwogICAgICAgIH0KICAgICAgICB1dGlscy5hcnJheVNldChzdHJtLm91dHB1dCwgcy5wZW5kaW5nX2J1Ziwgcy5wZW5kaW5nX291dCwgbGVuLCBzdHJtLm5leHRfb3V0KTsKICAgICAgICBzdHJtLm5leHRfb3V0ICs9IGxlbjsKICAgICAgICBzLnBlbmRpbmdfb3V0ICs9IGxlbjsKICAgICAgICBzdHJtLnRvdGFsX291dCArPSBsZW47CiAgICAgICAgc3RybS5hdmFpbF9vdXQgLT0gbGVuOwogICAgICAgIHMucGVuZGluZyAtPSBsZW47CiAgICAgICAgaWYgKHMucGVuZGluZyA9PT0gMCkgewogICAgICAgICAgcy5wZW5kaW5nX291dCA9IDA7CiAgICAgICAgfQogICAgICB9CiAgICAgIGZ1bmN0aW9uIGZsdXNoX2Jsb2NrX29ubHkocywgbGFzdCkgewogICAgICAgIHRyZWVzLl90cl9mbHVzaF9ibG9jayhzLCBzLmJsb2NrX3N0YXJ0ID49IDAgPyBzLmJsb2NrX3N0YXJ0IDogLTEsIHMuc3Ryc3RhcnQgLSBzLmJsb2NrX3N0YXJ0LCBsYXN0KTsKICAgICAgICBzLmJsb2NrX3N0YXJ0ID0gcy5zdHJzdGFydDsKICAgICAgICBmbHVzaF9wZW5kaW5nKHMuc3RybSk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gcHV0X2J5dGUocywgYikgewogICAgICAgIHMucGVuZGluZ19idWZbcy5wZW5kaW5nKytdID0gYjsKICAgICAgfQogICAgICBmdW5jdGlvbiBwdXRTaG9ydE1TQihzLCBiKSB7CiAgICAgICAgcy5wZW5kaW5nX2J1ZltzLnBlbmRpbmcrK10gPSBiID4+PiA4ICYgMjU1OwogICAgICAgIHMucGVuZGluZ19idWZbcy5wZW5kaW5nKytdID0gYiAmIDI1NTsKICAgICAgfQogICAgICBmdW5jdGlvbiByZWFkX2J1ZihzdHJtLCBidWYsIHN0YXJ0LCBzaXplKSB7CiAgICAgICAgdmFyIGxlbiA9IHN0cm0uYXZhaWxfaW47CiAgICAgICAgaWYgKGxlbiA+IHNpemUpIHsKICAgICAgICAgIGxlbiA9IHNpemU7CiAgICAgICAgfQogICAgICAgIGlmIChsZW4gPT09IDApIHsKICAgICAgICAgIHJldHVybiAwOwogICAgICAgIH0KICAgICAgICBzdHJtLmF2YWlsX2luIC09IGxlbjsKICAgICAgICB1dGlscy5hcnJheVNldChidWYsIHN0cm0uaW5wdXQsIHN0cm0ubmV4dF9pbiwgbGVuLCBzdGFydCk7CiAgICAgICAgaWYgKHN0cm0uc3RhdGUud3JhcCA9PT0gMSkgewogICAgICAgICAgc3RybS5hZGxlciA9IGFkbGVyMzIoc3RybS5hZGxlciwgYnVmLCBsZW4sIHN0YXJ0KTsKICAgICAgICB9IGVsc2UgaWYgKHN0cm0uc3RhdGUud3JhcCA9PT0gMikgewogICAgICAgICAgc3RybS5hZGxlciA9IGNyYzMyKHN0cm0uYWRsZXIsIGJ1ZiwgbGVuLCBzdGFydCk7CiAgICAgICAgfQogICAgICAgIHN0cm0ubmV4dF9pbiArPSBsZW47CiAgICAgICAgc3RybS50b3RhbF9pbiArPSBsZW47CiAgICAgICAgcmV0dXJuIGxlbjsKICAgICAgfQogICAgICBmdW5jdGlvbiBsb25nZXN0X21hdGNoKHMsIGN1cl9tYXRjaCkgewogICAgICAgIHZhciBjaGFpbl9sZW5ndGggPSBzLm1heF9jaGFpbl9sZW5ndGg7CiAgICAgICAgdmFyIHNjYW4gPSBzLnN0cnN0YXJ0OwogICAgICAgIHZhciBtYXRjaDsKICAgICAgICB2YXIgbGVuOwogICAgICAgIHZhciBiZXN0X2xlbiA9IHMucHJldl9sZW5ndGg7CiAgICAgICAgdmFyIG5pY2VfbWF0Y2ggPSBzLm5pY2VfbWF0Y2g7CiAgICAgICAgdmFyIGxpbWl0ID0gcy5zdHJzdGFydCA+IHMud19zaXplIC0gTUlOX0xPT0tBSEVBRCA/IHMuc3Ryc3RhcnQgLSAocy53X3NpemUgLSBNSU5fTE9PS0FIRUFEKSA6IDA7CiAgICAgICAgdmFyIF93aW4gPSBzLndpbmRvdzsKICAgICAgICB2YXIgd21hc2sgPSBzLndfbWFzazsKICAgICAgICB2YXIgcHJldiA9IHMucHJldjsKICAgICAgICB2YXIgc3RyZW5kID0gcy5zdHJzdGFydCArIE1BWF9NQVRDSDsKICAgICAgICB2YXIgc2Nhbl9lbmQxID0gX3dpbltzY2FuICsgYmVzdF9sZW4gLSAxXTsKICAgICAgICB2YXIgc2Nhbl9lbmQgPSBfd2luW3NjYW4gKyBiZXN0X2xlbl07CiAgICAgICAgaWYgKHMucHJldl9sZW5ndGggPj0gcy5nb29kX21hdGNoKSB7CiAgICAgICAgICBjaGFpbl9sZW5ndGggPj49IDI7CiAgICAgICAgfQogICAgICAgIGlmIChuaWNlX21hdGNoID4gcy5sb29rYWhlYWQpIHsKICAgICAgICAgIG5pY2VfbWF0Y2ggPSBzLmxvb2thaGVhZDsKICAgICAgICB9CiAgICAgICAgZG8gewogICAgICAgICAgbWF0Y2ggPSBjdXJfbWF0Y2g7CiAgICAgICAgICBpZiAoX3dpblttYXRjaCArIGJlc3RfbGVuXSAhPT0gc2Nhbl9lbmQgfHwgX3dpblttYXRjaCArIGJlc3RfbGVuIC0gMV0gIT09IHNjYW5fZW5kMSB8fCBfd2luW21hdGNoXSAhPT0gX3dpbltzY2FuXSB8fCBfd2luWysrbWF0Y2hdICE9PSBfd2luW3NjYW4gKyAxXSkgewogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgIH0KICAgICAgICAgIHNjYW4gKz0gMjsKICAgICAgICAgIG1hdGNoKys7CiAgICAgICAgICBkbyB7CiAgICAgICAgICB9IHdoaWxlIChfd2luWysrc2Nhbl0gPT09IF93aW5bKyttYXRjaF0gJiYgX3dpblsrK3NjYW5dID09PSBfd2luWysrbWF0Y2hdICYmIF93aW5bKytzY2FuXSA9PT0gX3dpblsrK21hdGNoXSAmJiBfd2luWysrc2Nhbl0gPT09IF93aW5bKyttYXRjaF0gJiYgX3dpblsrK3NjYW5dID09PSBfd2luWysrbWF0Y2hdICYmIF93aW5bKytzY2FuXSA9PT0gX3dpblsrK21hdGNoXSAmJiBfd2luWysrc2Nhbl0gPT09IF93aW5bKyttYXRjaF0gJiYgX3dpblsrK3NjYW5dID09PSBfd2luWysrbWF0Y2hdICYmIHNjYW4gPCBzdHJlbmQpOwogICAgICAgICAgbGVuID0gTUFYX01BVENIIC0gKHN0cmVuZCAtIHNjYW4pOwogICAgICAgICAgc2NhbiA9IHN0cmVuZCAtIE1BWF9NQVRDSDsKICAgICAgICAgIGlmIChsZW4gPiBiZXN0X2xlbikgewogICAgICAgICAgICBzLm1hdGNoX3N0YXJ0ID0gY3VyX21hdGNoOwogICAgICAgICAgICBiZXN0X2xlbiA9IGxlbjsKICAgICAgICAgICAgaWYgKGxlbiA+PSBuaWNlX21hdGNoKSB7CiAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgc2Nhbl9lbmQxID0gX3dpbltzY2FuICsgYmVzdF9sZW4gLSAxXTsKICAgICAgICAgICAgc2Nhbl9lbmQgPSBfd2luW3NjYW4gKyBiZXN0X2xlbl07CiAgICAgICAgICB9CiAgICAgICAgfSB3aGlsZSAoKGN1cl9tYXRjaCA9IHByZXZbY3VyX21hdGNoICYgd21hc2tdKSA+IGxpbWl0ICYmIC0tY2hhaW5fbGVuZ3RoICE9PSAwKTsKICAgICAgICBpZiAoYmVzdF9sZW4gPD0gcy5sb29rYWhlYWQpIHsKICAgICAgICAgIHJldHVybiBiZXN0X2xlbjsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHMubG9va2FoZWFkOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGZpbGxfd2luZG93KHMpIHsKICAgICAgICB2YXIgX3dfc2l6ZSA9IHMud19zaXplOwogICAgICAgIHZhciBwLCBuLCBtLCBtb3JlLCBzdHI7CiAgICAgICAgZG8gewogICAgICAgICAgbW9yZSA9IHMud2luZG93X3NpemUgLSBzLmxvb2thaGVhZCAtIHMuc3Ryc3RhcnQ7CiAgICAgICAgICBpZiAocy5zdHJzdGFydCA+PSBfd19zaXplICsgKF93X3NpemUgLSBNSU5fTE9PS0FIRUFEKSkgewogICAgICAgICAgICB1dGlscy5hcnJheVNldChzLndpbmRvdywgcy53aW5kb3csIF93X3NpemUsIF93X3NpemUsIDApOwogICAgICAgICAgICBzLm1hdGNoX3N0YXJ0IC09IF93X3NpemU7CiAgICAgICAgICAgIHMuc3Ryc3RhcnQgLT0gX3dfc2l6ZTsKICAgICAgICAgICAgcy5ibG9ja19zdGFydCAtPSBfd19zaXplOwogICAgICAgICAgICBuID0gcy5oYXNoX3NpemU7CiAgICAgICAgICAgIHAgPSBuOwogICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgbSA9IHMuaGVhZFstLXBdOwogICAgICAgICAgICAgIHMuaGVhZFtwXSA9IG0gPj0gX3dfc2l6ZSA/IG0gLSBfd19zaXplIDogMDsKICAgICAgICAgICAgfSB3aGlsZSAoLS1uKTsKICAgICAgICAgICAgbiA9IF93X3NpemU7CiAgICAgICAgICAgIHAgPSBuOwogICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgbSA9IHMucHJldlstLXBdOwogICAgICAgICAgICAgIHMucHJldltwXSA9IG0gPj0gX3dfc2l6ZSA/IG0gLSBfd19zaXplIDogMDsKICAgICAgICAgICAgfSB3aGlsZSAoLS1uKTsKICAgICAgICAgICAgbW9yZSArPSBfd19zaXplOwogICAgICAgICAgfQogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9pbiA9PT0gMCkgewogICAgICAgICAgICBicmVhazsKICAgICAgICAgIH0KICAgICAgICAgIG4gPSByZWFkX2J1ZihzLnN0cm0sIHMud2luZG93LCBzLnN0cnN0YXJ0ICsgcy5sb29rYWhlYWQsIG1vcmUpOwogICAgICAgICAgcy5sb29rYWhlYWQgKz0gbjsKICAgICAgICAgIGlmIChzLmxvb2thaGVhZCArIHMuaW5zZXJ0ID49IE1JTl9NQVRDSCkgewogICAgICAgICAgICBzdHIgPSBzLnN0cnN0YXJ0IC0gcy5pbnNlcnQ7CiAgICAgICAgICAgIHMuaW5zX2ggPSBzLndpbmRvd1tzdHJdOwogICAgICAgICAgICBzLmluc19oID0gKHMuaW5zX2ggPDwgcy5oYXNoX3NoaWZ0IF4gcy53aW5kb3dbc3RyICsgMV0pICYgcy5oYXNoX21hc2s7CiAgICAgICAgICAgIHdoaWxlIChzLmluc2VydCkgewogICAgICAgICAgICAgIHMuaW5zX2ggPSAocy5pbnNfaCA8PCBzLmhhc2hfc2hpZnQgXiBzLndpbmRvd1tzdHIgKyBNSU5fTUFUQ0ggLSAxXSkgJiBzLmhhc2hfbWFzazsKICAgICAgICAgICAgICBzLnByZXZbc3RyICYgcy53X21hc2tdID0gcy5oZWFkW3MuaW5zX2hdOwogICAgICAgICAgICAgIHMuaGVhZFtzLmluc19oXSA9IHN0cjsKICAgICAgICAgICAgICBzdHIrKzsKICAgICAgICAgICAgICBzLmluc2VydC0tOwogICAgICAgICAgICAgIGlmIChzLmxvb2thaGVhZCArIHMuaW5zZXJ0IDwgTUlOX01BVENIKSB7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9IHdoaWxlIChzLmxvb2thaGVhZCA8IE1JTl9MT09LQUhFQUQgJiYgcy5zdHJtLmF2YWlsX2luICE9PSAwKTsKICAgICAgfQogICAgICBmdW5jdGlvbiBkZWZsYXRlX3N0b3JlZChzLCBmbHVzaCkgewogICAgICAgIHZhciBtYXhfYmxvY2tfc2l6ZSA9IDY1NTM1OwogICAgICAgIGlmIChtYXhfYmxvY2tfc2l6ZSA+IHMucGVuZGluZ19idWZfc2l6ZSAtIDUpIHsKICAgICAgICAgIG1heF9ibG9ja19zaXplID0gcy5wZW5kaW5nX2J1Zl9zaXplIC0gNTsKICAgICAgICB9CiAgICAgICAgZm9yICg7IDsgKSB7CiAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPD0gMSkgewogICAgICAgICAgICBmaWxsX3dpbmRvdyhzKTsKICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkID09PSAwICYmIGZsdXNoID09PSBaX05PX0ZMVVNIKSB7CiAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPT09IDApIHsKICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgcy5zdHJzdGFydCArPSBzLmxvb2thaGVhZDsKICAgICAgICAgIHMubG9va2FoZWFkID0gMDsKICAgICAgICAgIHZhciBtYXhfc3RhcnQgPSBzLmJsb2NrX3N0YXJ0ICsgbWF4X2Jsb2NrX3NpemU7CiAgICAgICAgICBpZiAocy5zdHJzdGFydCA9PT0gMCB8fCBzLnN0cnN0YXJ0ID49IG1heF9zdGFydCkgewogICAgICAgICAgICBzLmxvb2thaGVhZCA9IHMuc3Ryc3RhcnQgLSBtYXhfc3RhcnQ7CiAgICAgICAgICAgIHMuc3Ryc3RhcnQgPSBtYXhfc3RhcnQ7CiAgICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgZmFsc2UpOwogICAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGlmIChzLnN0cnN0YXJ0IC0gcy5ibG9ja19zdGFydCA+PSBzLndfc2l6ZSAtIE1JTl9MT09LQUhFQUQpIHsKICAgICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCBmYWxzZSk7CiAgICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBzLmluc2VydCA9IDA7CiAgICAgICAgaWYgKGZsdXNoID09PSBaX0ZJTklTSCkgewogICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCB0cnVlKTsKICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgIHJldHVybiBCU19GSU5JU0hfU1RBUlRFRDsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBCU19GSU5JU0hfRE9ORTsKICAgICAgICB9CiAgICAgICAgaWYgKHMuc3Ryc3RhcnQgPiBzLmJsb2NrX3N0YXJ0KSB7CiAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIGZhbHNlKTsKICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZGVmbGF0ZV9mYXN0KHMsIGZsdXNoKSB7CiAgICAgICAgdmFyIGhhc2hfaGVhZDsKICAgICAgICB2YXIgYmZsdXNoOwogICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgaWYgKHMubG9va2FoZWFkIDwgTUlOX0xPT0tBSEVBRCkgewogICAgICAgICAgICBmaWxsX3dpbmRvdyhzKTsKICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkIDwgTUlOX0xPT0tBSEVBRCAmJiBmbHVzaCA9PT0gWl9OT19GTFVTSCkgewogICAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkID09PSAwKSB7CiAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGhhc2hfaGVhZCA9IDA7CiAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPj0gTUlOX01BVENIKSB7CiAgICAgICAgICAgIHMuaW5zX2ggPSAocy5pbnNfaCA8PCBzLmhhc2hfc2hpZnQgXiBzLndpbmRvd1tzLnN0cnN0YXJ0ICsgTUlOX01BVENIIC0gMV0pICYgcy5oYXNoX21hc2s7CiAgICAgICAgICAgIGhhc2hfaGVhZCA9IHMucHJldltzLnN0cnN0YXJ0ICYgcy53X21hc2tdID0gcy5oZWFkW3MuaW5zX2hdOwogICAgICAgICAgICBzLmhlYWRbcy5pbnNfaF0gPSBzLnN0cnN0YXJ0OwogICAgICAgICAgfQogICAgICAgICAgaWYgKGhhc2hfaGVhZCAhPT0gMCAmJiBzLnN0cnN0YXJ0IC0gaGFzaF9oZWFkIDw9IHMud19zaXplIC0gTUlOX0xPT0tBSEVBRCkgewogICAgICAgICAgICBzLm1hdGNoX2xlbmd0aCA9IGxvbmdlc3RfbWF0Y2gocywgaGFzaF9oZWFkKTsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChzLm1hdGNo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bcy5zdHJzdGFydCArIDFdKSAmIHMuaGFzaF9tYXNrOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBiZmx1c2ggPSB0cmVlcy5fdHJfdGFsbHkocywgMCwgcy53aW5kb3dbcy5zdHJzdGFydF0pOwogICAgICAgICAgICBzLmxvb2thaGVhZC0tOwogICAgICAgICAgICBzLnN0cnN0YXJ0Kys7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoYmZsdXNoKSB7CiAgICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgZmFsc2UpOwogICAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcy5pbnNlcnQgPSBzLnN0cnN0YXJ0IDwgTUlOX01BVENIIC0gMSA/IHMuc3Ryc3RhcnQgOiBNSU5fTUFUQ0ggLSAxOwogICAgICAgIGlmIChmbHVzaCA9PT0gWl9GSU5JU0gpIHsKICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgdHJ1ZSk7CiAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICByZXR1cm4gQlNfRklOSVNIX1NUQVJURUQ7CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gQlNfRklOSVNIX0RPTkU7CiAgICAgICAgfQogICAgICAgIGlmIChzLmxhc3RfbGl0KSB7CiAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIGZhbHNlKTsKICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiBCU19CTE9DS19ET05FOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGRlZmxhdGVfc2xvdyhzLCBmbHVzaCkgewogICAgICAgIHZhciBoYXNoX2hlYWQ7CiAgICAgICAgdmFyIGJmbHVzaDsKICAgICAgICB2YXIgbWF4X2luc2VydDsKICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA8IE1JTl9MT09LQUhFQUQpIHsKICAgICAgICAgICAgZmlsbF93aW5kb3cocyk7CiAgICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA8IE1JTl9MT09LQUhFQUQgJiYgZmx1c2ggPT09IFpfTk9fRkxVU0gpIHsKICAgICAgICAgICAgICByZXR1cm4gQlNfTkVFRF9NT1JFOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA9PT0gMCkgewogICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBoYXNoX2hlYWQgPSAwOwogICAgICAgICAgaWYgKHMubG9va2FoZWFkID49IE1JTl9NQVRDSCkgewogICAgICAgICAgICBzLmluc19oID0gKHMuaW5zX2ggPDwgcy5oYXNoX3NoaWZ0IF4gcy53aW5kb3dbcy5zdHJzdGFydCArIE1JTl9NQVRDSCAtIDFdKSAmIHMuaGFzaF9tYXNrOwogICAgICAgICAgICBoYXNoX2hlYWQgPSBzLnByZXZbcy5zdHJzdGFydCAmIHMud19tYXNrXSA9IHMuaGVhZFtzLmluc19oXTsKICAgICAgICAgICAgcy5oZWFkW3MuaW5zX2hdID0gcy5zdHJzdGFydDsKICAgICAgICAgIH0KICAgICAgICAgIHMucHJldl9sZW5ndGggPSBzLm1hdGNoX2xlbmd0aDsKICAgICAgICAgIHMucHJldl9tYXRjaCA9IHMubWF0Y2hfc3RhcnQ7CiAgICAgICAgICBzLm1hdGNoX2xlbmd0aCA9IE1JTl9NQVRDSCAtIDE7CiAgICAgICAgICBpZiAoaGFzaF9oZWFkICE9PSAwICYmIHMucHJldl9sZW5ndGggPCBzLm1heF9sYXp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ICAgICAgICAgICBoYXNoX2hlYWQgPSBzLnByZXZbcy5zdHJzdGFydCAmIHMud19tYXNrXSA9IHMuaGVhZFtzLmluc19oXTsKICAgICAgICAgICAgICAgIHMuaGVhZFtzLmluc19oXSA9IHMuc3Ryc3RhcnQ7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9IHdoaWxlICgtLXMucHJldl9sZW5ndGggIT09IDApOwogICAgICAgICAgICBzLm1hdGNoX2F2YWlsYWJsZSA9IDA7CiAgICAgICAgICAgIHMubWF0Y2hfbGVuZ3RoID0gTUlOX01BVENIIC0gMTsKICAgICAgICAgICAgcy5zdHJzdGFydCsrOwogICAgICAgICAgICBpZiAoYmZsdXNoKSB7CiAgICAgICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCBmYWxzZSk7CiAgICAgICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgaWYgKHMubWF0Y2hfYXZhaWxhYmxlKSB7CiAgICAgICAgICAgIGJmbHVzaCA9IHRyZWVzLl90cl90YWxseShzLCAwLCBzLndpbmRvd1tzLnN0cnN0YXJ0IC0gMV0pOwogICAgICAgICAgICBpZiAoYmZsdXNoKSB7CiAgICAgICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCBmYWxzZSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgcy5zdHJzdGFydCsrOwogICAgICAgICAgICBzLmxvb2thaGVhZC0tOwogICAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHMubWF0Y2hfYXZhaWxhYmxlID0gMTsKICAgICAgICAgICAgcy5zdHJzdGFydCsrOwogICAgICAgICAgICBzLmxvb2thaGVhZC0tOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAocy5tYXRjaF9hdmFpbGFibGUpIHsKICAgICAgICAgIGJmbHVzaCA9IHRyZWVzLl90cl90YWxseShzLCAwLCBzLndpbmRvd1tzLnN0cnN0YXJ0IC0gMV0pOwogICAgICAgICAgcy5tYXRjaF9hdmFpbGFibGUgPSAwOwogICAgICAgIH0KICAgICAgICBzLmluc2VydCA9IHMuc3Ryc3RhcnQgPCBNSU5fTUFUQ0ggLSAxID8gcy5zdHJzdGFydCA6IE1JTl9NQVRDSCAtIDE7CiAgICAgICAgaWYgKGZsdXNoID09PSBaX0ZJTklTSCkgewogICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCB0cnVlKTsKICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgIHJldHVybiBCU19GSU5JU0hfU1RBUlRFRDsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBCU19GSU5JU0hfRE9ORTsKICAgICAgICB9CiAgICAgICAgaWYgKHMubGFzdF9saXQpIHsKICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgZmFsc2UpOwogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIEJTX0JMT0NLX0RPTkU7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZGVmbGF0ZV9ybGUocywgZmx1c2gpIHsKICAgICAgICB2YXIgYmZsdXNoOwogICAgICAgIHZhciBwcmV2OwogICAgICAgIHZhciBzY2FuLCBzdHJlbmQ7CiAgICAgICAgdmFyIF93aW4gPSBzLndpbmRvdzsKICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA8PSBNQVhfTUFUQ0gpIHsKICAgICAgICAgICAgZmlsbF93aW5kb3cocyk7CiAgICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA8PSBNQVhfTUFUQ0ggJiYgZmx1c2ggPT09IFpfTk9fRkxVU0gpIHsKICAgICAgICAgICAgICByZXR1cm4gQlNfTkVFRF9NT1JFOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA9PT0gMCkgewogICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBzLm1hdGNoX2xlbmd0aCA9IDA7CiAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPj0gTUlOX01BVENIICYmIHMuc3Ryc3RhcnQgPiAwKSB7CiAgICAgICAgICAgIHNjYW4gPSBzLnN0cnN0YXJ0IC0gMTsKICAgICAgICAgICAgcHJldiA9IF93aW5bc2Nhbl07CiAgICAgICAgICAgIGlmIChwcmV2ID09PSBfd2luWysrc2Nhbl0gJiYgcHJldiA9PT0gX3dpblsrK3NjYW5dICYmIHByZXYgPT09IF93aW5bKytzY2FuXSkgewogICAgICAgICAgICAgIHN0cmVuZCA9IHMuc3Ryc3RhcnQgKyBNQVhfTUFUQ0g7CiAgICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgIH0gd2hpbGUgKHByZXYgPT09IF93aW5bKytzY2FuXSAmJiBwcmV2ID09PSBfd2luWysrc2Nhbl0gJiYgcHJldiA9PT0gX3dpblsrK3NjYW5dICYmIHByZXYgPT09IF93aW5bKytzY2FuXSAmJiBwcmV2ID09PSBfd2luWysrc2Nhbl0gJiYgcHJldiA9PT0gX3dpblsrK3NjYW5dICYmIHByZXYgPT09IF93aW5bKytzY2FuXSAmJiBwcmV2ID09PSBfd2luWysrc2Nhbl0gJiYgc2NhbiA8IHN0cmVuZCk7CiAgICAgICAgICAgICAgcy5tYXRjaF9sZW5ndGggPSBNQVhfTUFUQ0ggLSAoc3RyZW5kIC0gc2Nhbik7CiAgICAgICAgICAgICAgaWYgKHMubWF0Y2hfbGVuZ3RoID4gcy5sb29rYWhlYWQpIHsKICAgICAgICAgICAgICAgIHMubWF0Y2hfbGVuZ3RoID0gcy5sb29rYWhlYWQ7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBpZiAocy5tYXRjaF9sZW5ndGggPj0gTUlOX01BVENIKSB7CiAgICAgICAgICAgIGJmbHVzaCA9IHRyZWVzLl90cl90YWxseShzLCAxLCBzLm1hdGNoX2xlbmd0aCAtIE1JTl9NQVRDSCk7CiAgICAgICAgICAgIHMubG9va2FoZWFkIC09IHMubWF0Y2hfbGVuZ3RoOwogICAgICAgICAgICBzLnN0cnN0YXJ0ICs9IHMubWF0Y2hfbGVuZ3RoOwogICAgICAgICAgICBzLm1hdGNoX2xlbmd0aCA9IDA7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBiZmx1c2ggPSB0cmVlcy5fdHJfdGFsbHkocywgMCwgcy53aW5kb3dbcy5zdHJzdGFydF0pOwogICAgICAgICAgICBzLmxvb2thaGVhZC0tOwogICAgICAgICAgICBzLnN0cnN0YXJ0Kys7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoYmZsdXNoKSB7CiAgICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgZmFsc2UpOwogICAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcy5pbnNlcnQgPSAwOwogICAgICAgIGlmIChmbHVzaCA9PT0gWl9GSU5JU0gpIHsKICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgdHJ1ZSk7CiAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICByZXR1cm4gQlNfRklOSVNIX1NUQVJURUQ7CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gQlNfRklOSVNIX0RPTkU7CiAgICAgICAgfQogICAgICAgIGlmIChzLmxhc3RfbGl0KSB7CiAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIGZhbHNlKTsKICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiBCU19CTE9DS19ET05FOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGRlZmxhdGVfaHVmZihzLCBmbHVzaCkgewogICAgICAgIHZhciBiZmx1c2g7CiAgICAgICAgZm9yICg7IDsgKSB7CiAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPT09IDApIHsKICAgICAgICAgICAgZmlsbF93aW5kb3cocyk7CiAgICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA9PT0gMCkgewogICAgICAgICAgICAgIGlmIChmbHVzaCA9PT0gWl9OT19GTFVTSCkgewogICAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIHMubWF0Y2hfbGVuZ3RoID0gMDsKICAgICAgICAgIGJmbHVzaCA9IHRyZWVzLl90cl90YWxseShzLCAwLCBzLndpbmRvd1tzLnN0cnN0YXJ0XSk7CiAgICAgICAgICBzLmxvb2thaGVhZC0tOwogICAgICAgICAgcy5zdHJzdGFydCsrOwogICAgICAgICAgaWYgKGJmbHVzaCkgewogICAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIGZhbHNlKTsKICAgICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgICByZXR1cm4gQlNfTkVFRF9NT1JFOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHMuaW5zZXJ0ID0gMDsKICAgICAgICBpZiAoZmx1c2ggPT09IFpfRklOSVNIKSB7CiAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIHRydWUpOwogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIEJTX0ZJTklTSF9TVEFSVEVEOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIEJTX0ZJTklTSF9ET05FOwogICAgICAgIH0KICAgICAgICBpZiAocy5sYXN0X2xpdCkgewogICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCBmYWxzZSk7CiAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICByZXR1cm4gQlNfTkVFRF9NT1JFOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gQlNfQkxPQ0tfRE9ORTsKICAgICAgfQogICAgICBmdW5jdGlvbiBDb25maWcoZ29vZF9sZW5ndGgsIG1heF9sYXp5LCBuaWNlX2xlbmd0aCwgbWF4X2NoYWluLCBmdW5jKSB7CiAgICAgICAgdGhpcy5nb29kX2xlbmd0aCA9IGdvb2RfbGVuZ3RoOwogICAgICAgIHRoaXMubWF4X2xhenkgPSBtYXhfbGF6eTsKICAgICAgICB0aGlzLm5pY2VfbGVuZ3RoID0gbmljZV9sZW5ndGg7CiAgICAgICAgdGhpcy5tYXhfY2hhaW4gPSBtYXhfY2hhaW47CiAgICAgICAgdGhpcy5mdW5jID0gZnVuYzsKICAgICAgfQogICAgICB2YXIgY29uZmlndXJhdGlvbl90YWJsZTsKICAgICAgY29uZmlndXJhdGlvbl90YWJsZSA9IFsKICAgICAgICBuZXcgQ29uZmlnKDAsIDAsIDAsIDAsIGRlZmxhdGVfc3RvcmVkKSwKICAgICAgICBuZXcgQ29uZmlnKDQsIDQsIDgsIDQsIGRlZmxhdGVfZmFzdCksCiAgICAgICAgbmV3IENvbmZpZyg0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ICAgICBzLmluc2VydCA9IDA7CiAgICAgICAgcy5tYXRjaF9sZW5ndGggPSBzLnByZXZfbGVuZ3RoID0gTUlOX01BVENIIC0gMTsKICAgICAgICBzLm1hdGNoX2F2YWlsYWJsZSA9IDA7CiAgICAgICAgcy5pbnNfaCA9IDA7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gRGVmbGF0ZVN0YXRlKCkgewogICAgICAgIHRoaXMuc3RybSA9IG51bGw7CiAgICAgICAgdGhpcy5zdGF0dXMgPSAwOwogICAgICAgIHRoaXMucGVuZGluZ19idWYgPSBudWxsOwogICAgICAgIHRoaXMucGVuZGluZ19idWZfc2l6ZSA9IDA7CiAgICAgICAgdGhpcy5wZW5kaW5nX291dCA9IDA7CiAgICAgICAgdGhpcy5wZW5kaW5nID0gMDsKICAgICAgICB0aGlzLndyYXAgPSAwOwogICAgICAgIHRoaXMuZ3poZWFkID0gbnVsbDsKICAgICAgICB0aGlzLmd6aW5kZXggPSAwOwogICAgICAgIHRoaXMubWV0aG9kID0gWl9ERUZMQVRFRDsKICAgICAgICB0aGlzLmxhc3RfZmx1c2ggPSAtMTsKICAgICAgICB0aGlzLndfc2l6ZSA9IDA7CiAgICAgICAgdGhpcy53X2JpdHMgPSAwOwogICAgICAgIHRoaXMud19tYXNrID0gMDsKICAgICAgICB0aGlzLndpbmRvdyA9IG51bGw7CiAgICAgICAgdGhpcy53aW5kb3dfc2l6ZSA9IDA7CiAgICAgICAgdGhpcy5wcmV2ID0gbnVsbDsKICAgICAgICB0aGlzLmhlYWQgPSBudWxsOwogICAgICAgIHRoaXMuaW5zX2ggPSAwOwogICAgICAgIHRoaXMuaGFzaF9zaXplID0gMDsKICAgICAgICB0aGlzLmhhc2hfYml0cyA9IDA7CiAgICAgICAgdGhpcy5oYXNoX21hc2sgPSAwOwogICAgICAgIHRoaXMuaGFzaF9zaGlmdCA9IDA7CiAgICAgICAgdGhpcy5ibG9ja19zdGFydCA9IDA7CiAgICAgICAgdGhpcy5tYXRja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sKICAgICAgICB6ZXJvKHRoaXMuaGVhcCk7CiAgICAgICAgdGhpcy5oZWFwX2xlbiA9IDA7CiAgICAgICAgdGhpcy5oZWFwX21heCA9IDA7CiAgICAgICAgdGhpcy5kZXB0aCA9IG5ldyB1dGlscy5CdWYxNigyICogTF9DT0RFUyArIDEpOwogICAgICAgIHplcm8odGhpcy5kZXB0aCk7CiAgICAgICAgdGhpcy5sX2J1ZiA9IDA7CiAgICAgICAgdGhpcy5saXRfYnVmc2l6ZSA9IDA7CiAgICAgICAgdGhpcy5sYXN0X2xpdCA9IDA7CiAgICAgICAgdGhpcy5kX2J1ZiA9IDA7CiAgICAgICAgdGhpcy5vcHRfbGVuID0gMDsKICAgICAgICB0aGlzLnN0YXRpY19sZW4gPSAwOwogICAgICAgIHRoaXMubWF0Y2hlcyA9IDA7CiAgICAgICAgdGhpcy5pbnNlcnQgPSAwOwogICAgICAgIHRoaXMuYmlfYnVmID0gMDsKICAgICAgICB0aGlzLmJpX3ZhbGlkID0gMDsKICAgICAgfQogICAgICBmdW5jdGlvbiBkZWZsYXRlUmVzZXRLZWVwKHN0cm0pIHsKICAgICAgICB2YXIgczsKICAgICAgICBpZiAoIXN0cm0gfHwgIXN0cm0uc3RhdGUpIHsKICAgICAgICAgIHJldHVybiBlcnIoc3RybSwgWl9TVFJFQU1fRVJST1IpOwogICAgICAgIH0KICAgICAgICBzdHJtLnRvdGFsX2luID0gc3RybS50b3RhbF9vdXQgPSAwOwogICAgICAgIHN0cm0uZGF0YV90eXBlID0gWl9VTktOT1dOOwogICAgICAgIHMgPSBzdHJtLnN0YXRlOwogICAgICAgIHMucGVuZGluZyA9IDA7CiAgICAgICAgcy5wZW5kaW5nX291dCA9IDA7CiAgICAgICAgaWYgKHMud3JhcCA8IDApIHsKICAgICAgICAgIHMud3JhcCA9IC1zLndyYXA7CiAgICAgICAgfQogICAgICAgIHMuc3RhdHVzID0gcy53cmFwID8gSU5JVF9TVEFURSA6IEJVU1lfU1RBVEU7CiAgICAgICAgc3RybS5hZGxlciA9IHMud3JhcCA9PT0gMiA/IDAgOiAxOwogICAgICAgIHMubGFzdF9mbHVzaCA9IFpfTk9fRkxVU0g7CiAgICAgICAgdHJlZXMuX3RyX2luaXQocyk7CiAgICAgICAgcmV0dXJuIFpfT0s7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZGVmbGF0ZVJlc2V0KHN0cm0pIHsKICAgICAgICB2YXIgcmV0ID0gZGVmbGF0ZVJlc2V0S2VlcChzdHJtKTsKICAgICAgICBpZiAocmV0ID09PSBaX09LKSB7CiAgICAgICAgICBsbV9pbml0KHN0cm0uc3RhdGUpOwogICAgICAgIH0KICAgICAgICByZXR1cm4gcmV0OwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGRlZmxhdGVTZXRIZWFkZXIoc3RybSwgaGVhZCkgewogICAgICAgIGlmICghc3RybSB8fCAhc3RybS5zdGF0ZSkgewogICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VSUk9SOwogICAgICAgIH0KICAgICAgICBpZiAoc3RybS5zdGF0ZS53cmFwICE9PSAyKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIHN0cm0uc3RhdGUuZ3poZWFkID0gaGVhZDsKICAgICAgICByZXR1cm4gWl9PSzsKICAgICAgfQogICAgICBmdW5jdGlvbiBkZWZsYXRlSW5pdDIoc3RybSwgbGV2ZWwsIG1ldGhvZCwgd2luZG93Qml0cywgbWVtTGV2ZWwsIHN0cmF0ZWd5KSB7CiAgICAgICAgaWYgKCFzdHJtKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIHZhciB3cmFwID0gMTsKICAgICAgICBpZiAobGV2ZWwgPT09IFpfREVGQVVMVF9DT01QUkVTU0lPTikgewogICAgICAgICAgbGV2ZWwgPSA2OwogICAgICAgIH0KICAgICAgICBpZiAod2luZG93Qml0cyA8IDApIHsKICAgICA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BzdHJtID8gZXJyKHN0cm0sIFpfU1RSRUFNX0VSUk9SKSA6IFpfU1RSRUFNX0VSUk9SOwogICAgICAgIH0KICAgICAgICBzID0gc3RybS5zdGF0ZTsKICAgICAgICBpZiAoIXN0cm0ub3V0cHV0IHx8ICFzdHJtLmlucHV0ICYmIHN0cm0uYXZhaWxfaW4gIT09IDAgfHwgcy5zdGF0dXMgPT09IEZJTklTSF9TVEFURSAmJiBmbHVzaCAhPT0gWl9GSU5JU0gpIHsKICAgICAgICAgIHJldHVybiBlcnIoc3RybSwgc3RybS5hdmFpbF9vdXQgPT09IDAgPyBaX0JVRl9FUlJPUiA6IFpfU1RSRUFNX0VSUk9SKTsKICAgICAgICB9CiAgICAgICAgcy5zdHJtID0gc3RybTsKICAgICAgICBvbGRfZmx1c2ggPSBzLmxhc3RfZmx1c2g7CiAgICAgICAgcy5sYXN0X2ZsdXNoID0gZmx1c2g7CiAgICAgICAgaWYgKHMuc3RhdHVzID09PSBJTklUX1NUQVRFKSB7CiAgICAgICAgICBpZiAocy53cmFwID09PSAyKSB7CiAgICAgICAgICAgIHN0cm0uYWRsZXIgPSAwOwogICAgICAgICAgICBwdXRfYnl0ZShzLCAzMSk7CiAgICAgICAgICAgIHB1dF9ieXRlKHMsIDEzOSk7CiAgICAgICAgICAgIHB1dF9ieXRlKHMsIDgpOwogICAgICAgICAgICBpZiAoIXMuZ3poZWFkKSB7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgMCk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgMCk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgMCk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgMCk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgMCk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgcy5sZXZlbCA9PT0gOSA/IDIgOiBzLnN0cmF0ZWd5ID49IFpfSFVGRk1BTl9PTkxZIHx8IHMubGV2ZWwgPCAyID8gNCA6IDApOwogICAgICAgICAgICAgIHB1dF9ieXRlKHMsIE9TX0NPREUpOwogICAgICAgICAgICAgIHMuc3RhdHVzID0gQlVTWV9TVEFURTsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCAocy5nemhlYWQudGV4dCA/IDEgOiAwKSArIChzLmd6aGVhZC5oY3JjID8gMiA6IDApICsgKCFzLmd6aGVhZC5leHRyYSA/IDAgOiA0KSArICghcy5nemhlYWQubmFtZSA/IDAgOiA4KSArICghcy5nemhlYWQuY29tbWVudCA/IDAgOiAxNikpOwogICAgICAgICAgICAgIHB1dF9ieXRlKHMsIHMuZ3poZWFkLnRpbWUgJiAyNTUpOwogICAgICAgICAgICAgIHB1dF9ieXRlKHMsIHMuZ3poZWFkLnRpbWUgPj4gOCAmIDI1NSk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgcy5nemhlYWQudGltZSA+PiAxNiAmIDI1NSk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgcy5nemhlYWQudGltZSA+PiAyNCAmIDI1NSk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgcy5sZXZlbCA9PT0gOSA/IDIgOiBzLnN0cmF0ZWd5ID49IFpfSFVGRk1BTl9PTkxZIHx8IHMubGV2ZWwgPCAyID8gNCA6IDApOwogICAgICAgICAgICAgIHB1dF9ieXRlKHMsIHMuZ3poZWFkLm9zICYgMjU1KTsKICAgICAgICAgICAgICBpZiAocy5nemhlYWQuZXh0cmEgJiYgcy5nemhlYWQuZXh0cmEubGVuZ3RoKSB7CiAgICAgICAgICAgICAgICBwdXRfYnl0ZShzLCBzLmd6aGVhZC5leHRyYS5sZW5ndGggJiAyNTUpOwogICAgICAgICAgICAgICAgcHV0X2J5dGUocywgcy5nemhlYWQuZXh0cmEubGVuZ3RoID4+IDggJiAyNTUpOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBpZiAocy5nemhlYWQuaGNyYykgewogICAgICAgICAgICAgICAgc3RybS5hZGxlciA9IGNyYzMyKHN0cm0uYWRsZXIsIHMucGVuZGluZ19idWYsIHMucGVuZGluZywgMCk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIHMuZ3ppbmRleCA9IDA7CiAgICAgICAgICAgICAgcy5zdGF0dXMgPSBFWFRSQV9TVEFURTsKICAgICAgICAgICAgfQogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgdmFyIGhlYWRlciA9IFpfREVGTEFURUQgKyAocy53X2JpdHMgLSA4IDw8IDQpIDw8IDg7CiAgICAgICAgICAgIHZhciBsZXZlbF9mbGFncyA9IC0xOwogICAgICAgICAgICBpZiAocy5zdHJhdGVneSA+PSBaX0hVRkZNQU5fT05MWSB8fCBzLmxldmVsIDwgMikgewogICAgICAgICAgICAgIGxldmVsX2ZsYWdzID0gMDsKICAgICAgICAgICAgfSBlbHNlIGlmIChzLmxldmVsIDwgNikgewogICAgICAgICAgICAgIGxldmVsX2ZsYWdzID0gMTsKICAgICAgICAgICAgfSBlbHNlIGlmIChzLmxldmVsID09PSA2KSB7CiAgICAgICAgICAgICAgbGV2ZWxfZmxhZ3MgPSAyOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIGxldmVsX2ZsYWdzID0gMzsKICAgICAgICAgICAgfQogICAgICAgICAgICBoZWFkZXIgfD0gbGV2ZWxfZmxhZ3MgPDwgNjsKICAgICAgICAgICAgaWYgKHMuc3Ryc3RhcnQgIT09IDApIHsKICAgICAgICAgICAgICBoZWFkZXIgfD0gUFJFU0VUX0RJQ1Q7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaGVhZGVyICs9IDMxIC0gaGVhZGVyICUgMzE7CiAgICAgICAgICAgIHMuc3RhdHVzID0gQlVTWV9TVEFURTsKICAgICAgICAgICAgcHV0U2hvcnRNU0IocywgaGVhZGVyKTsKICAgICAgICAgICAgaWYgKHMuc3Ryc3RhcnQgIT09IDApIHsKICAgICAgICAgICAgICBwdXRTaG9ydE1TQihzLCBzdHJtLmFkbGVyID4+PiAxNik7CiAgICAgICAgICAgICAgcHV0U2hvcnRNU0Iocywgc3RybS5hZGxlciAmIDY1NTM1KTsKICAgICAgICAgICAgfQogICAgICAgICAgICBzdHJtLmFkbGVyID0gMTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKHMuc3RhdHVzID09PSBFWFRSQV9TVEFURSkgewogICAgICAgICAgaWYgKHMuZ3poZWFkLmV4dHJhKSB7CiAgICAgICAgICAgIGJlZyA9IHMucGVuZGluZzsKICAgICAgICAgICAgd2hpbGUgKHMuZ3ppbmRleCA8IChzLmd6aGVhZC5leHRyYS5sZW5ndGggJiA2NTUzNSkpIHsKICAgICAgICAgICAgICBpZiAocy5wZW5kaW5nID09PSBzLnBlbmRpbmdfYnVmX3NpemUpIHsKICAgICAgICAgICAgICAgIGlmIChzLmd6aGVhZC5oY3JjICYmIHMucGVuZGluZyA+IGJlZykgewogICAgICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gY3JjMzIoc3RybS5hZGxlciwgcy5wZW5kaW5nX2J1Ziwgcy5wZW5kaW5nIC0gYmVnLCBiZWcpOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgZmx1c2hfcGVuZGluZyhzdHJtKTsKICAgICAgICAgICAgICAgIGJlZyA9IHMucGVuZGluZzsKICAgICAgICAgICAgICAgIGlmIChzLnBlbmRpbmcgPT09IHMucGVuZGluZ19idWZfc2l6ZSkgewogICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgcy5nemhlYWQuZXh0cmFbcy5nemluZGV4XSAmIDI1NSk7CiAgICAgICAgICAgICAgcy5nemluZGV4Kys7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHMuZ3poZWFkLmhjcmMgJiYgcy5wZW5kaW5nID4gYmVnKSB7CiAgICAgICAgICAgICAgc3RybS5hZGxlciA9IGNyYzMyKHN0cm0uYWRsZXIsIHMucGVuZGluZ19idWYsIHMucGVuZGluZyAtIGJlZywgYmVnKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAocy5nemluZGV4ID09PSBzLmd6aGVhZC5leHRyYS5sZW5ndGgpIHsKICAgICAgICAgICAgICBzLmd6aW5kZXggPSAwOwogICAgICAgICAgICAgIHMuc3RhdHVzID0gTkFNRV9TVEFURTsKICAgICAgICAgICAgfQogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcy5zdGF0dXMgPSBOQU1FX1NUQVRFOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAocy5zdGF0dXMgPT09IE5BTUVfU1RBVEUpIHsKICAgICAgICAgIGlmIChzLmd6aGVhZC5uYW1lKSB7CiAgICAgICAgICAgIGJlZyA9IHMucGVuZGluZzsKICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgIGlmIChzLnBlbmRpbmcgPT09IHMucGVuZGluZ19idWZfc2l6ZSkgewogICAgICAgICAgICAgICAgaWYgKHMuZ3poZWFkLmhjcmMgJiYgcy5wZW5kaW5nID4gYmVnKSB7CiAgICAgICAgICAgICAgICAgIHN0cm0uYWRsZXIgPSBjcmMzMihzdHJtLmFkbGVyLCBzLnBlbmRpbmdfYnVmLCBzLnBlbmRpbmcgLSBiZWcsIGJlZyk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBmbHVzaF9wZW5kaW5nKHN0cm0pOwogICAgICAgICAgICAgICAgYmVnID0gcy5wZW5kaW5nOwogICAgICAgICAgICAgICAgaWYgKHMucGVuZGluZyA9PT0gcy5wZW5kaW5nX2J1Zl9zaXplKSB7CiAgICAgICAgICAgICAgICAgIHZhbCA9IDE7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBpZiAocy5nemluZGV4IDwgcy5nemhlYWQubmFtZS5sZW5ndGgpIHsKICAgICAgICAgICAgICAgIHZhbCA9IHMuZ3poZWFkLm5hbWUuY2hhckNvZGVBdChzLmd6aW5kZXgrKykgJiAyNTU7CiAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIHZhbCA9IDA7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIHB1dF9ieXRlKHMsIHZhbCk7CiAgICAgICAgICAgIH0gd2hpbGUgKHZhbCAhPT0gMCk7CiAgICAgICAgICAgIGlmIChzLmd6aGVhZC5oY3JjICYmIHMucGVuZGluZyA+IGJlZykgewogICAgICAgICAgICAgIHN0cm0uYWRsZXIgPSBjcmMzMihzdHJtLmFkbGVyLCBzLnBlbmRpbmdfYnVmLCBzLnBlbmRpbmcgLSBiZWcsIGJlZyk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHZhbCA9PT0gMCkgewogICAgICAgICAgICAgIHMuZ3ppbmRleCA9IDA7CiAgICAgICAgICAgICAgcy5zdGF0dXMgPSBDT01NRU5UX1NUQVRFOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBzLnN0YXR1cyA9IENPTU1FTlRfU1RBVEU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChzLnN0YXR1cyA9PT0gQ09NTUVOVF9TVEFURSkgewogICAgICAgICAgaWYgKHMuZ3poZWFkLmNvbW1lbnQpIHsKICAgICAgICAgICAgYmVnID0gcy5wZW5kaW5nOwogICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgaWYgKHMucGVuZGluZyA9PT0gcy5wZW5kaW5nX2J1Zl9zaXplKSB7CiAgICAgICAgICAgICAgICBpZiAocy5nemhlYWQuaGNyYyAmJiBzLnBlbmRpbmcgPiBiZWcpIHsKICAgICAgICAgICAgICAgICAgc3RybS5hZGxlciA9IGNyYzMyKHN0cm0uYWRsZXIsIHMucGVuZGluZ19idWYsIHMucGVuZGluZyAtIGJlZywgYmVnKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGZsdXNoX3BlbmRpbmcoc3RybSk7CiAgICAgICAgICAgICAgICBiZWcgPSBzLnBlbmRpbmc7CiAgICAgICAgICAgICAgICBpZiAocy5wZW5kaW5nID09PSBzLnBlbmRpbmdfYnVmX3NpemUpIHsKICAgICAgICAgICAgICAgICAgdmFsID0gMTsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGlmIChzLmd6aW5kZXggPCBzLmd6aGVhZC5jb21tZW50Lmxlbmd0aCkgewogICAgICAgICAgICAgICAgdmFsID0gcy5nemhlYWQuY29tbWVudC5jaGFyQ29kZUF0KHMuZ3ppbmRleCsrKSAmIDI1NTsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgdmFsID0gMDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgdmFsKTsKICAgICAgICAgICAgfSB3aGlsZSAodmFsICE9PSAwKTsKICAgICAgICAgICAgaWYgKHMuZ3poZWFkLmhjcmMgJiYgcy5wZW5kaW5nID4gYmVnKSB7CiAgICAgICAgICAgICAgc3RybS5hZGxlciA9IGNyYzMyKHN0cm0uYWRsZXIsIHMucGVuZGluZ19idWYsIHMucGVuZGluZyAtIGJlZywgYmVnKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAodmFsID09PSAwKSB7CiAgICAgICAgICAgICAgcy5zdGF0dXMgPSBIQ1JDX1NUQVRFOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBzLnN0YXR1cyA9IEhDUkNfU1RBVEU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChzLnN0YXR1cyA9PT0gSENSQ19TVEFURSkgewogICAgICAgICAgaWYgKHMuZ3poZWFkLmhjcmMpIHsKICAgICAgICAgICAgaWYgKHMucGVuZGluZyArIDIgPiBzLnBlbmRpbmdfYnVmX3NpemUpIHsKICAgICAgICAgICAgICBmbHVzaF9wZW5kaW5nKHN0cm0pOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzLnBlbmRpbmcgKyAyIDw9IHMucGVuZGluZ19idWZfc2l6ZSkgewogICAgICAgICAgICAgIHB1dF9ieXRlKHMsIHN0cm0uYWRsZXIgJiAyNTUpOwogICAgICAgICAgICAgIHB1dF9ieXRlKHMsIHN0cm0uYWRsZXIgPj4gOCAmIDI1NSk7CiAgICAgICAgICAgICAgc3RybS5hZGxlciA9IDA7CiAgICAgICAgICAgICAgcy5zdGF0dXMgPSBCVVNZX1NUQVRFOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBzLnN0YXR1cyA9IEJVU1lfU1RBVEU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChzLnBlbmRpbmcgIT09IDApIHsKICAgICAgICAgIGZsdXNoX3BlbmRpbmcoc3RybSk7CiAgICAgICAgICBpZiAoc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcy5sYXN0X2ZsdXNoID0gLTE7CiAgICAgICAgICAgIHJldHVybiBaX09LOwogICAgICAgICAgfQogICAgICAgIH0gZWxzZSBpZiAoc3RybS5hdmFpbF9pbiA9PT0gMCAmJiByYW5rKGZsdXNoKSA8PSByYW5rKG9sZF9mbHVzaCkgJiYgZmx1c2ggIT09IFpfRklOSVNIKSB7CiAgICAgICAgICByZXR1cm4gZXJyKHN0cm0sIFpfQlVGX0VSUk9SKTsKICAgICAgICB9CiAgICAgICAgaWYgKHMuc3RhdHVzID09PSBGSU5JU0hfU1RBVEUgJiYgc3RybS5hdmFpbF9pbiAhPT0gMCkgewogICAgICAgICAgcmV0dXJuIGVycihzdHJtLCBaX0JVRl9FUlJPUik7CiAgICAgICAgfQogICAgICAgIGlmIChzdHJtLmF2YWlsX2luICE9PSAwIHx8IHMubG9va2FoZWFkICE9PSAwIHx8IGZsdXNoICE9PSBaX05PX0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GlmIChzLmxvb2thaGVhZCA9PT0gMCkgewogICAgICAgICAgICAgICAgICBzLnN0cnN0YXJ0ID0gMDsKICAgICAgICAgICAgICAgICAgcy5ibG9ja19zdGFydCA9IDA7CiAgICAgICAgICAgICAgICAgIHMuaW5zZXJ0ID0gMDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZmx1c2hfcGVuZGluZyhzdHJtKTsKICAgICAgICAgICAgaWYgKHN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgICAgcy5sYXN0X2ZsdXNoID0gLTE7CiAgICAgICAgICAgICAgcmV0dXJuIFpfT0s7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKGZsdXNoICE9PSBaX0ZJTklTSCkgewogICAgICAgICAgcmV0dXJuIFpfT0s7CiAgICAgICAgfQogICAgICAgIGlmIChzLndyYXAgPD0gMCkgewogICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VORDsKICAgICAgICB9CiAgICAgICAgaWYgKHMud3JhcCA9PT0gMikgewogICAgICAgICAgcHV0X2J5dGUocywgc3RybS5hZGxlciAmIDI1NSk7CiAgICAgICAgICBwdXRfYnl0ZShzLCBzdHJtLmFkbGVyID4+IDggJiAyNTUpOwogICAgICAgICAgcHV0X2J5dGUocywgc3RybS5hZGxlciA+PiAxNiAmIDI1NSk7CiAgICAgICAgICBwdXRfYnl0ZShzLCBzdHJtLmFkbGVyID4+IDI0ICYgMjU1KTsKICAgICAgICAgIHB1dF9ieXRlKHMsIHN0cm0udG90YWxfaW4gJiAyNTUpOwogICAgICAgICAgcHV0X2J5dGUocywgc3RybS50b3RhbF9pbiA+PiA4ICYgMjU1KTsKICAgICAgICAgIHB1dF9ieXRlKHMsIHN0cm0udG90YWxfaW4gPj4gMTYgJiAyNTUpOwogICAgICAgICAgcHV0X2J5dGUocywgc3RybS50b3RhbF9pbiA+PiAyNC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m0sIGRpY3Rpb25hcnkpIHsKICAgICAgICB2YXIgZGljdExlbmd0aCA9IGRpY3Rpb25hcnkubGVuZ3RoOwogICAgICAgIHZhciBzOwogICAgICAgIHZhciBzdHIsIG47CiAgICAgICAgdmFyIHdyYXA7CiAgICAgICAgdmFyIGF2YWlsOwogICAgICAgIHZhciBuZXh0OwogICAgICAgIHZhciBpbnB1dDsKICAgICAgICB2YXIgdG1wRGljdDsKICAgICAgICBpZiAoIXN0cm0gfHwgIXN0cm0uc3RhdGUpIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgcyA9IHN0cm0uc3RhdGU7CiAgICAgICAgd3JhcCA9IHMud3JhcDsKICAgICAgICBpZiAod3JhcCA9PT0gMiB8fCB3cmFwID09PSAxICYmIHMuc3RhdHVzICE9PSBJTklUX1NUQVRFIHx8IHMubG9va2FoZWFkKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIGlmICh3cmFwID09PSAxKSB7CiAgICAgICAgICBzdHJtLmFkbGVyID0gYWRsZXIzMihzdHJtLmFkbGVyLCBkaWN0aW9uYXJ5LCBkaWN0TGVuZ3RoLCAwKTsKICAgICAgICB9CiAgICAgICAgcy53cmFwID0gMDsKICAgICAgICBpZiAoZGljdExlbmd0aCA+PSBzLndfc2l6ZSkgewogICAgICAgICAgaWYgKHdyYXAgPT09IDApIHsKICAgICAgICAgICAgemVybyhzLmhlYWQpOwogICAgICAgICAgICBzLnN0cnN0YXJ0ID0gMDsKICAgICAgICAgICAgcy5ibG9ja19zdGFydCA9IDA7CiAgICAgICAgICAgIHMuaW5zZXJ0ID0gMDsKICAgICAgICAgIH0KICAgICAgICAgIHRtcERpY3QgPSBuZXcgdXRpbHMuQnVmOChzLndfc2l6ZSk7CiAgICAgICAgICB1dGlscy5hcnJheVNldCh0bXBEaWN0LCBkaWN0aW9uYXJ5LCBkaWN0TGVuZ3RoIC0gcy53X3NpemUsIHMud19zaXplLCAwKTsKICAgICAgICAgIGRpY3Rpb25hcnkgPSB0bXBEaWN0OwogICAgICAgICAgZGljdExlbmd0aCA9IHMud19zaXplOwogICAgICAgIH0KICAgICAgICBhdmFpbCA9IHN0cm0uYXZhaWxfaW47CiAgICAgICAgbmV4dCA9IHN0cm0ubmV4dF9pbjsKICAgICAgICBpbnB1dCA9IHN0cm0uaW5wdXQ7CiAgICAgICAgc3RybS5hdmFpbF9pbiA9IGRpY3RMZW5ndGg7CiAgICAgICAgc3RybS5uZXh0X2luID0gMDsKICAgICAgICBzdHJtLmlucHV0ID0gZGljdGlvbmFyeTsKICAgICAgICBmaWxsX3dpbmRvdyhzKTsKICAgICAgICB3aGlsZSAocy5sb29rYWhlYWQgPj0gTUlOX01BVENIKSB7CiAgICAgICAgICBzdHIgPSBzLnN0cnN0YXJ0OwogICAgICAgICAgbiA9IHMubG9va2FoZWFkIC0gKE1JTl9NQVRDSCAtIDEpOwogICAgICAgICAgZG8gewogICAgICAgICAgICBzLmluc19oID0gKHMuaW5zX2ggPDwgcy5oYXNoX3NoaWZ0IF4gcy53aW5kb3dbc3RyICsgTUlOX01BVENIIC0gMV0pICYgcy5oYXNoX21hc2s7CiAgICAgICAgICAgIHMucHJldltzdHIgJiBzLndfbWFza10gPSBzLmhlYWRbcy5pbnNfaF07CiAgICAgICAgICAgIHMuaGVhZFtzLmluc19oXSA9IHN0cjsKICAgICAgICAgICAgc3RyKys7CiAgICAgICAgICB9IHdoaWxlICgtLW4pOwogICAgICAgICAgcy5zdHJzdGFydCA9IHN0cjsKICAgICAgICAgIHMubG9va2FoZWFkID0gTUlOX01BVENIIC0gMTsKICAgICAgICAgIGZpbGxfd2luZG93KHMpOwogICAgICAgIH0KICAgICAgICBzLnN0cnN0YXJ0ICs9IHMubG9va2FoZWFkOwogICAgICAgIHMuYmxvY2tfc3RhcnQgPSBzLnN0cnN0YXJ0OwogICAgICAgIHMuaW5zZXJ0ID0gcy5sb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9sZW4gPSAwOwogICAgICAgIGZvciAobV9wb3MgPSAwOyBtX3BvcyA8IHN0cl9sZW47IG1fcG9zKyspIHsKICAgICAgICAgIGMgPSBzdHIuY2hhckNvZGVBdChtX3Bvcyk7CiAgICAgICAgICBpZiAoKGMgJiA2NDUxMikgPT09IDU1Mjk2ICYmIG1fcG9zICsgMSA8IHN0cl9sZW4pIHsKICAgICAgICAgICAgYzIgPSBzdHIuY2hhckNvZGVBdChtX3BvcyArIDEpOwogICAgICAgICAgICBpZiAoKGMyICYgNjQ1MTIpID09PSA1NjMyMCkgewogICAgICAgICAgICAgIGMgPSA2NTUzNiArIChjIC0gNTUyOTYgPDwgMTApICsgKGMyIC0gNTYzMjApOwogICAgICAgICAgICAgIG1fcG9zKys7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGJ1Zl9sZW4gKz0gYyA8IDEyOCA/IDEgOiBjIDwgMjA0OCA/IDIgOiBjIDwgNjU1MzYgPyAzIDogNDsKICAgICAgICB9CiAgICAgICAgYnVmID0gbmV3IHV0aWxzLkJ1ZjgoYnVmX2xlbik7CiAgICAgICAgZm9yIChpID0gMCwgbV9wb3MgPSAwOyBpIDwgYnVmX2xlbjsgbV9wb3MrKykgewogICAgICAgICAgYyA9IHN0ci5jaGFyQ29kZUF0KG1fcG9zKTsKICAgICAgICAgIGlmICgoYyAmIDY0NTEyKSA9PT0gNTUyOTYgJiYgbV9wb3MgKyAxIDwgc3RyX2xlbikgewogICAgICAgICAgICBjMiA9IHN0ci5jaGFyQ29kZUF0KG1fcG9zICsgMSk7CiAgICAgICAgICAgIGlmICgoYzIgJiA2NDUxMikgPT09IDU2MzIwKSB7CiAgICAgICAgICAgICAgYyA9IDY1NTM2ICsgKGMgLSA1NTI5NiA8PCAxMCkgKyAoYzIgLSA1NjMyMCk7CiAgICAgICAgICAgICAgbV9wb3MrKzsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgaWYgKGMgPCAxMjgpIHsKICAgICAgICAgICAgYnVmW2krK10gPSBjOwogICAgICAgICAgfSBlbHNlIGlmIChjIDwgMjA0OCkgewogICAgICAgICAgICBidWZbaSsrXSA9IDE5MiB8IGMgPj4+IDY7CiAgICAgICAgICAgIGJ1ZltpKytdID0gMTI4IHwgYyAmIDYzOwogICAgICAgICAgfSBlbHNlIGlmIChjIDwgNjU1MzYpIHsKICAgICAgICAgICAgYnVmW2krK10gPSAyMjQgfCBjID4+PiAxMjsKICAgICAgICAgICAgYnVmW2krK10gPSAxMjggfCBjID4+PiA2ICYgNjM7CiAgICAgICAgICAgIGJ1ZltpKytdID0gMTI4IHwgYyAmIDYzOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgYnVmW2krK10gPSAyNDAgfCBjID4+PiAxODsKICAgICAgICAgICAgYnVmW2krK10gPSAxMjggfCBjID4+PiAxMiAmIDYzOwogICAgICAgICAgICBidWZbaSsrXSA9IDEyOCB8IGMgPj4+IDYgJiA2MzsKICAgICAgICAgICAgYnVmW2krK10gPSAxMjggfCBjICYgNjM7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiBidWY7CiAgICAgIH07CiAgICAgIGZ1bmN0aW9uIGJ1ZjJiaW5zdHJpbmcoYnVmLCBsZW4pIHsKICAgICAgICBpZiAobGVuIDwgNjU1MzQpIHsKICAgICAgICAgIGlmIChidWYuc3ViYXJyYXkgJiYgU1RSX0FQUExZX1VJQV9PSyB8fCAhYnVmLnN1YmFycmF5ICYmIFNUUl9BUFBMWV9PSykgewogICAgICAgICAgICByZXR1cm4gU3RyaW5nLmZyb21DaGFyQ29kZS5hcHBseShudWxsLCB1dGlscy5zaHJpbmtCdWYoYnVmLCBsZW4pKTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgdmFyIHJlc3VsdCA9ICIiOwogICAgICAgIGZvciAodmFyIGkgPSAwOyBpIDwgbGVuOyBpKyspIHsKICAgICAgICAgIHJlc3VsdCArPSBTdHJpbmcuZnJvbUNoYXJDb2RlKGJ1ZltpXSk7CiAgICAgICAgfQogICAgICAgIHJldHVybiByZXN1bHQ7CiAgICAgIH0KICAgICAgZXhwb3J0czIuYnVmMmJpbnN0cmluZyA9IGZ1bmN0aW9uKGJ1ZikgewogICAgICAgIHJldHVybiBidWYyYmluc3RyaW5nKGJ1ZiwgYnVmLmxlbmd0aCk7CiAgICAgIH07CiAgICAgIGV4cG9ydHMyLmJpbnN0cmluZzJidWYgPSBmdW5jdGlvbihzdHIpIHsKICAgICAgICB2YXIgYnVmID0gbmV3IHV0aWxzLkJ1Zjgoc3RyLmxlbmd0aCk7CiAgICAgICAgZm9yICh2YXIgaSA9IDAsIGxlbiA9IGJ1Zi5sZW5ndGg7IGkgPCBsZW47IGkrKykgewogICAgICAgICAgYnVmW2ldID0gc3RyLmNoYXJDb2RlQXQoaSk7CiAgICAgICAgfQogICAgICAgIHJldHVybiBidWY7CiAgICAgIH07CiAgICAgIGV4cG9ydHMyLmJ1ZjJzdHJpbmcgPSBmdW5jdGlvbihidWYsIG1heCkgewogICAgICAgIHZhciBpLCBvdXQsIGMsIGNfbGVuOwogICAgICAgIHZhciBsZW4gPSBtYXggfHwgYnVmLmxlbmd0aDsKICAgICAgICB2YXIgdXRmMTZidWYgPSBuZXcgQXJyYXkobGVuICogMik7CiAgICAgICAgZm9yIChvdXQgPSAwLCBpID0gMDsgaSA8IGxlbjsgKSB7CiAgICAgICAgICBjID0gYnVmW2krK107CiAgICAgICAgICBpZiAoYyA8IDEyOCkgewogICAgICAgICAgICB1dGYxNmJ1ZltvdXQrK10gPSBjOwogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgIH0KICAgICAgICAgIGNfbGVuID0gX3V0ZjhsZW5bY107CiAgICAgICAgICBpZiAoY19sZW4gPiA0KSB7CiAgICAgICAgICAgIHV0ZjE2YnVmW291dCsrXSA9IDY1NTMzOwogICAgICAgICAgICBpICs9IGNfbGVuIC0gMTsKICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICB9CiAgICAgICAgICBjICY9IGNfbGVuID09PSAyID8gMzEgOiBjX2xlbiA9PT0gMyA/IDE1IDogNzsKICAgICAgICAgIHdoaWxlIChjX2xlbiA+IDEgJiYgaSA8IGxlbikgewogICAgICAgICAgICBjID0gYyA8PCA2IHwgYnVmW2krK10gJiA2MzsKICAgICAgICAgICAgY19sZW4tLTsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChjX2xlbiA+IDEpIHsKICAgICAgICAgICAgdXRmMTZidWZbb3V0KytdID0gNjU1MzM7CiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgfQogICAgICAgICAgaWYgKGMgPCA2NTUzNikgewogICAgICAgICAgICB1dGYxNmJ1ZltvdXQrK10gPSBjOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgYyAtPSA2NTUzNjsKICAgICAgICAgICAgdXRmMTZidWZbb3V0KytdID0gNTUyOTYgfCBjID4+IDEwICYgMTAyMzsKICAgICAgICAgICAgdXRmMTZidWZbb3V0KytdID0gNTYzMjAgfCBjICYgMTAyMzsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIGJ1ZjJiaW5zdHJpbmcodXRmMTZidWYsIG91dCk7CiAgICAgIH07CiAgICAgIGV4cG9ydHMyLnV0Zjhib3JkZXIgPSBmdW5jdGlvbihidWYsIG1heCkgewogICAgICAgIHZhciBwb3M7CiAgICAgICAgbWF4ID0gbWF4IHx8IGJ1Zi5sZW5ndGg7CiAgICAgICAgaWYgKG1heCA+IGJ1Zi5sZW5ndGgpIHsKICAgICAgICAgIG1heCA9IGJ1Zi5sZW5ndGg7CiAgICAgICAgfQogICAgICAgIHBvcyA9IG1heCAtIDE7CiAgICAgICAgd2hpbGUgKHBvcyA+PSAwICYmIChidWZbcG9zXSAmIDE5MikgPT09IDEyOCkgewogICAgICAgICAgcG9zLS07CiAgICAgICAgfQogICAgICAgIGlmIChwb3MgPCAwKSB7CiAgICAgICAgICByZXR1cm4gbWF4OwogICAgICAgIH0KICAgICAgICBpZiAocG9zID09PSAwKSB7CiAgICAgICAgICByZXR1cm4gbWF4OwogICAgICAgIH0KICAgICAgICByZXR1cm4gcG9zICsgX3V0ZjhsZW5bYnVmW3Bvc11dID4gbWF4ID8gcG9zIDogbWF4OwogICAgICB9OwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvenN0cmVhbS5qcwogIHZhciByZXF1aXJlX3pzdHJlYW0gPSBfX2NvbW1vbkpTKHsKICAgICJub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvenN0cmVhbS5qcyIoZXhwb3J0czIsIG1vZHVsZTIpIHsKICAgICAgaW5pdF9idWZmZXJfc2hpbSgpOwogICAgICAidXNlIHN0cmljdCI7CiAgICAgIGZ1bmN0aW9uIFpTdHJlYW0oKSB7CiAgICAgICAgdGhpcy5pbnB1dCA9IG51bGw7CiAgICAgICAgdGhpcy5uZXh0X2luID0gMDsKICAgICAgICB0aGlzLmF2YWlsX2luID0gMDsKICAgICAgICB0aGlzLnRvdGFsX2luID0gMDsKICAgICAgICB0aGlzLm91dHB1dCA9IG51bGw7CiAgICAgICAgdGhpcy5uZXh0X291dCA9IDA7CiAgICAgICAgdGhpcy5hdmFpbF9vdXQgPSAwOwogICAgICAgIHRoaXMudG90YWxfb3V0ID0gMDsKICAgICAgICB0aGlzLm1zZyA9ICIiOwogICAgICAgIHRoaXMuc3RhdGUgPSBudWxsOwogICAgICAgIHRoaXMuZGF0YV90eXBlID0gMjsKICAgICAgICB0aGlzLmFkbGVyID0gMDsKICAgICAgfQogICAgICBtb2R1bGUyLmV4cG9ydHMgPSBaU3RyZWFtOwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28v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SRVNTSU9OLAogICAgICAgICAgbWV0aG9kOiBaX0RFRkxBVEVELAogICAgICAgICAgY2h1bmtTaXplOiAxNjM4NCwKICAgICAgICAgIHdpbmRvd0JpdHM6IDE1LAogICAgICAgICAgbWVtTGV2ZWw6IDgsCiAgICAgICAgICBzdHJhdGVneTogWl9ERUZBVUxUX1NUUkFURUdZLAogICAgICAgICAgdG86ICIiCiAgICAgICAgfSwgb3B0aW9ucyB8fCB7fSk7CiAgICAgICAgdmFyIG9wdCA9IHRoaXMub3B0aW9uczsKICAgICAgICBpZiAob3B0LnJhdyAmJiBvcHQud2luZG93Qml0cyA+IDApIHsKICAgICAgICAgIG9wdC53aW5kb3dCaXRzID0gLW9wdC53aW5kb3dCaXRzOwogICAgICAgIH0gZWxzZSBpZiAob3B0Lmd6aXAgJiYgb3B0LndpbmRvd0JpdHMgPiAwICYmIG9wdC53aW5kb3dCaXRzIDwgMTYpIHsKICAgICAgICAgIG9wdC53aW5kb3dCaXRzICs9IDE2OwogICAgICAgIH0KICAgICAgICB0aGlzLmVyciA9IDA7CiAgICAgICAgdGhpcy5tc2cgPSAiIjsKICAgICAgICB0aGlzLmVuZGVkID0gZmFsc2U7CiAgICAgICAgdGhpcy5jaHVua3MgPSBbXTsKICAgICAgICB0aGlzLnN0cm0gPSBuZXcgWlN0cmVhbSgpOwogICAgICAgIHRoaXMuc3RybS5hdmFpbF9vdXQgPSAwOwogICAgICAgIHZhciBzdGF0dXMgPSB6bGliX2RlZmxhdGUuZGVmbGF0ZUluaXQyKHRoaXMuc3RybSwgb3B0LmxldmVsLCBvcHQubWV0aG9kLCBvcHQud2luZG93Qml0cywgb3B0Lm1lbUxldmVsLCBvcHQuc3RyYXRlZ3kpOwogICAgICAgIGlmIChzdGF0dXMgIT09IFpfT0spIHsKICAgICAgICAgIHRocm93IG5ldyBFcnJvcihtc2dbc3RhdHVzXSk7CiAgICAgICAgfQogICAgICAgIGlmIChvcHQuaGVhZGVyKSB7CiAgICAgICAgICB6bGliX2RlZmxhdGUuZGVmbGF0ZVNldEhlYWRlcih0aGlzLnN0cm0sIG9wdC5oZWFkZXIpOwogICAgICAgIH0KICAgICAgICBpZiAob3B0LmRpY3Rpb25hcnkpIHsKICAgICAgICAgIHZhciBkaWN0OwogICAgICAgICAgaWYgKHR5cGVvZiBvcHQuZGljdGlvbmFyeSA9PT0gInN0cmluZyIpIHsKICAgICAgICAgICAgZGljdCA9IHN0cmluZ3Muc3RyaW5nMmJ1ZihvcHQuZGljdGlvbmFyeSk7CiAgICAgICAgICB9IGVsc2UgaWYgKHRvU3RyaW5nLmNhbGwob3B0LmRpY3Rpb25hcnkpID09PSAiW29iamVjdCBBcnJheUJ1ZmZlcl0iKSB7CiAgICAgICAgICAgIGRpY3QgPSBuZXcgVWludDhBcnJheShvcHQuZGljdGlvbmFyeSk7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBkaWN0ID0gb3B0LmRpY3Rpb25hcnk7CiAgICAgICAgICB9CiAgICAgICAgICBzdGF0dXMgPSB6bGliX2RlZmxhdGUuZGVmbGF0ZVNldERpY3Rpb25hcnkodGhpcy5zdHJtLCBkaWN0KTsKICAgICAgICAgIGlmIChzdGF0dXMgIT09IFpfT0spIHsKICAgICAgICAgICAgdGhyb3cgbmV3IEVycm9yKG1zZ1tzdGF0dXNdKTsKICAgICAgICAgIH0KICAgICAgICAgIHRoaXMuX2RpY3Rfc2V0ID0gdHJ1ZTsKICAgICAgICB9CiAgICAgIH0KICAgICAgRGVmbGF0ZS5wcm90b3R5cGUucHVzaCA9IGZ1bmN0aW9uKGRhdGEsIG1vZGUpIHsKICAgICAgICB2YXIgc3RybSA9IHRoaXMuc3RybTsKICAgICAgICB2YXIgY2h1bmtTaXplID0gdGhpcy5vcHRpb25zLmNodW5rU2l6ZTsKICAgICAgICB2YXIgc3RhdHVzLCBfbW9kZTsKICAgICAgICBpZiAodGhpcy5lbmRlZCkgewogICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICAgIH0KICAgICAgICBfbW9kZSA9IG1vZGUgPT09IH5+bW9kZSA/IG1vZGUgOiBtb2RlID09PSB0cnVlID8gWl9GSU5JU0ggOiBaX05PX0ZMVVNIOwogICAgICAgIGlmICh0eXBlb2YgZGF0YSA9PT0gInN0cmluZyIpIHsKICAgICAgICAgIHN0cm0uaW5wdXQgPSBzdHJpbmdzLnN0cmluZzJidWYoZGF0YSk7CiAgICAgICAgfSBlbHNlIGlmICh0b1N0cmluZy5jYWxsKGRhdGEpID09PSAiW29iamVjdCBBcnJheUJ1ZmZlcl0iKSB7CiAgICAgICAgICBzdHJtLmlucHV0ID0gbmV3IFVpbnQ4QXJyYXkoZGF0YSk7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIHN0cm0uaW5wdXQgPSBkYXRhOwogICAgICAgIH0KICAgICAgICBzdHJtLm5leHRfaW4gPSAwOwogICAgICAgIHN0cm0uYXZhaWxfaW4gPSBzdHJtLmlucHV0Lmxlbmd0aDsKICAgICAgICBkbyB7CiAgICAgICAgICBpZiAoc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgc3RybS5vdXRwdXQgPSBuZXcgdXRpbHMuQnVmOChjaHVua1NpemUpOwogICAgICAgICAgICBzdHJtLm5leHRfb3V0ID0gMDsKICAgICAgICAgICAgc3RybS5hdmFpbF9vdXQgPSBjaHVua1NpemU7CiAgICAgICAgICB9CiAgICAgICAgICBzdGF0dXMgPSB6bGliX2RlZmxhdGUuZGVmbGF0ZShzdHJtLCBfbW9kZSk7CiAgICAgICAgICBpZiAoc3RhdHVzICE9PSBaX1NUUkVBTV9FTkQgJiYgc3RhdHVzICE9PSBaX09LKSB7CiAgICAgICAgICAgIHRoaXMub25FbmQoc3RhdHVzKTsKICAgICAgICAgICAgdGhpcy5lbmRlZCA9IHRydWU7CiAgICAgICAgICAgIHJldHVybiBmYWxzZTsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChzdHJtLmF2YWlsX291dCA9PT0gMCB8fCBzdHJtLmF2YWlsX2luID09PSAwICYmIChfbW9kZSA9PT0gWl9GSU5JU0ggfHwgX21vZGUgPT09IFpfU1lOQ19GTFVTSDIpKSB7CiAgICAgICAgICAgIGlmICh0aGlzLm9wdGlvbnMudG8gPT09ICJzdHJpbmciKSB7CiAgICAgICAgICAgICAgdGhpcy5vbkRhdGEoc3RyaW5ncy5idWYyYmluc3RyaW5nKHV0aWxzLnNocmlua0J1ZihzdHJtLm91dHB1dCwgc3RybS5uZXh0X291dCkpKTsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICB0aGlzLm9uRGF0YSh1dGlscy5zaHJpbmtCdWYoc3RybS5vdXRwdXQsIHN0cm0ubmV4dF9vdXQpKTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0gd2hpbGUgKChzdHJtLmF2YWlsX2luID4gMCB8fCBzdHJtLmF2YWlsX291dCA9PT0gMCkgJiYgc3RhdHVzICE9PSBaX1NUUkVBTV9FTkQpOwogICAgICAgIGlmIChfbW9kZSA9PT0gWl9GSU5JU0gpIHsKICAgICAgICAgIHN0YXR1cyA9IHpsaWJfZGVmbGF0ZS5kZWZsYXRlRW5kKHRoaXMuc3RybSk7CiAgICAgICAgICB0aGlzLm9uRW5kKHN0YXR1cyk7CiAgICAgICAgICB0aGlzLmVuZGVkID0gdHJ1ZTsKICAgICAgICAgIHJldHVybiBzdGF0dXMgPT09IFpfT0s7CiAgICAgICAgfQogICAgICAgIGlmIChfbW9kZSA9PT0gWl9TWU5DX0ZMVVNIMikgewogICAgICAgICAgdGhpcy5vbkVuZChaX09LKTsKICAgICAgICAgIHN0cm0uYXZhaWxfb3V0ID0gMDsKICAgICAgICAgIHJldHVybiB0cnVlOwogICAgICAgIH0KICAgICAgICByZXR1cm4gdHJ1ZTsKICAgICAgfTsKICAgICAgRGVmbGF0ZS5wcm90b3R5cGUub25EYXRhID0gZnVuY3Rpb24oY2h1bmspIHsKICAgICAgICB0aGlzLmNodW5rcy5wdXNoKGNodW5rKTsKICAgICAgfTsKICAgICAgRGVmbGF0ZS5wcm90b3R5cGUub25FbmQgPSBmdW5jdGlvbihzdGF0dXMpIHsKICAgICAgICBpZiAoc3RhdHVzID09PSBaX09LKSB7CiAgICAgICAgICBpZiAodGhpcy5vcHRpb25zLnRvID09PSAic3RyaW5nIikgewogICAgICAgICAgICB0aGlzLnJlc3VsdCA9IHRoaXMuY2h1bmtzLmpvaW4oIiIpOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgdGhpcy5yZXN1bHQgPSB1dGlscy5mbGF0dGVuQ2h1bmtzKHRoaXMuY2h1bmtzKTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgdGhpcy5jaHVua3MgPSBbXTsKICAgICAgICB0aGlzLmVyciA9IHN0YXR1czsKICAgICAgICB0aGlzLm1zZyA9IHRoaXMuc3RybS5tc2c7CiAgICAgIH07CiAgICAgIGZ1bmN0aW9uIGRlZmxhdGUoaW5wdXQsIG9wdGlvbnMpIHsKICAgICAgICB2YXIgZGVmbGF0b3IgPSBuZXcgRGVmbGF0ZShvcHRpb25zKTsKICAgICAgICBkZWZsYXRvci5wdXNoKGlucHV0LCB0cnVlKTsKICAgICAgICBpZiAoZGVmbGF0b3IuZXJyKSB7CiAgICAgICAgICB0aHJvdyBkZWZsYXRvci5tc2cgfHwgbXNnW2RlZmxhdG9yLmVycl07CiAgICAgICAgfQogICAgICAgIHJldHVybiBkZWZsYXRvci5yZXN1bHQ7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZGVmbGF0ZVJhdyhpbnB1dCwgb3B0aW9ucykgewogICAgICAgIG9wdGlvbnMgPSBvcHRpb25zIHx8IHt9OwogICAgICAgIG9wdGlvbnMucmF3ID0gdHJ1ZTsKICAgICAgICByZXR1cm4gZGVmbGF0ZShpbnB1dCwgb3B0aW9ucyk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZ3ppcChpbnB1dCwgb3B0aW9ucykgewogICAgICAgIG9wdGlvbnM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AgICAgICB2YXIgbGNvZGU7CiAgICAgICAgdmFyIGRjb2RlOwogICAgICAgIHZhciBsbWFzazsKICAgICAgICB2YXIgZG1hc2s7CiAgICAgICAgdmFyIGhlcmU7CiAgICAgICAgdmFyIG9wOwogICAgICAgIHZhciBsZW47CiAgICAgICAgdmFyIGRpc3Q7CiAgICAgICAgdmFyIGZyb207CiAgICAgICAgdmFyIGZyb21fc291cmNlOwogICAgICAgIHZhciBpbnB1dCwgb3V0cHV0OwogICAgICAgIHN0YXRlID0gc3RybS5zdGF0ZTsKICAgICAgICBfaW4gPSBzdHJtLm5leHRfaW47CiAgICAgICAgaW5wdXQgPSBzdHJtLmlucHV0OwogICAgICAgIGxhc3QgPSBfaW4gKyAoc3RybS5hdmFpbF9pbiAtIDUpOwogICAgICAgIF9vdXQgPSBzdHJtLm5leHRfb3V0OwogICAgICAgIG91dHB1dCA9IHN0cm0ub3V0cHV0OwogICAgICAgIGJlZyA9IF9vdXQgLSAoc3RhcnQgLSBzdHJtLmF2YWlsX291dCk7CiAgICAgICAgZW5kID0gX291dCArIChzdHJtLmF2YWlsX291dCAtIDI1Nyk7CiAgICAgICAgZG1heCA9IHN0YXRlLmRtYXg7CiAgICAgICAgd3NpemUgPSBzdGF0ZS53c2l6ZTsKICAgICAgICB3aGF2ZSA9IHN0YXRlLndoYXZlOwogICAgICAgIHduZXh0ID0gc3RhdGUud25leHQ7CiAgICAgICAgc193aW5kb3cgPSBzdGF0ZS53aW5kb3c7CiAgICAgICAgaG9sZCA9IHN0YXRlLmhvbGQ7CiAgICAgICAgYml0cyA9IHN0YXRlLmJpdHM7CiAgICAgICAgbGNvZGUgPSBzdGF0ZS5sZW5jb2RlOwogICAgICAgIGRjb2RlID0gc3RhdGUuZGlzdGNvZGU7CiAgICAgICAgbG1hc2sgPSAoMSA8PCBzdGF0ZS5sZW5iaXRzKSAtIDE7CiAgICAgICAgZG1hc2sgPSAoMSA8PCBzdGF0ZS5kaXN0Yml0cykgLSAxOwogICAgICAgIHRvcDoKICAgICAgICAgIGRvIHsKICAgICAgICAgICAgaWYgKGJpdHMgPCAxNSkgewogICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbX2luKytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbX2luKytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICB9CiAgICAgICAgICAgIGhlcmUgPSBsY29kZVtob2xkICYgbG1hc2tdOwogICAgICAgICAgICBkb2xlbjoKICAgICAgICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgICAgICAgIG9wID0gaGVyZSA+Pj4gMjQ7CiAgICAgICAgICAgICAgICBob2xkID4+Pj0gb3A7CiAgICAgICAgICAgICAgICBiaXRzIC09IG9wOwogICAgICAgICAgICAgICAgb3AgPSBoZXJlID4+PiAxNiAmIDI1NTsKICAgICAgICAgICAgICAgIGlmIChvcCA9PT0gMCkgewogICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IGhlcmUgJiA2NTUzNTsKICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAob3AgJiAxNikgewogICAgICAgICAgICAgICAgICBsZW4gPSBoZXJlICYgNjU1MzU7CiAgICAgICAgICAgICAgICAgIG9wICY9IDE1OwogICAgICAgICAgICAgICAgICBpZiAob3ApIHsKICAgICAgICAgICAgICAgICAgICBpZiAoYml0cyA8IG9wKSB7CiAgICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W19pbisrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBsZW4gKz0gaG9sZCAmICgxIDw8IG9wKSAtIDE7CiAgICAgICAgICAgICAgICAgICAgaG9sZCA+Pj49IG9wOwogICAgICAgICAgICAgICAgICAgIGJpdHMgLT0gb3A7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaWYgKGJpdHMgPCAxNSkgewogICAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbX2luKytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbX2luKytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGhlcmUgPSBkY29kZVtob2xkICYgZG1hc2tdOwogICAgICAgICAgICAgICAgICBkb2Rpc3Q6CiAgICAgICAgICAgICAgICAgICAgZm9yICg7IDsgKSB7CiAgICAgICAgICAgICAgICAgICAgICBvcCA9IGhlcmUgPj4+IDI0OwogICAgICAgICAgICAgICAgICAgICAgaG9sZCA+Pj49IG9wOwogICAgICAgICAgICAgICAgICAgICAgYml0cyAtPSBvcDsKICAgICAgICAgICAgICAgICAgICAgIG9wID0gaGVyZSA+Pj4gMTYgJiAyNTU7CiAgICAgICAgICAgICAgICAgICAgICBpZiAob3AgJiAxNikgewogICAgICAgICAgICAgICAgICAgICAgICBkaXN0ID0gaGVyZSAmIDY1NTM1OwogICAgICAgICAgICAgICAgICAgICAgICBvcCAmPSAxNTsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGJpdHMgPCBvcCkgewogICAgICAgICAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbX2luKytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChiaXRzIDwgb3ApIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbX2luKytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIGRpc3QgKz0gaG9sZCAmICgxIDw8IG9wKSAtIDE7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChkaXN0ID4gZG1heCkgewogICAgICAgICAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImludmFsaWQgZGlzdGFuY2UgdG9vIGZhciBiYWNrIjsKICAgICAgICAgICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEOwogICAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrIHRvcDsKICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICBob2xkID4+Pj0gb3A7CiAgICAgICAgICAgICAgICAgICAgICAgIGJpdHMgLT0gb3A7CiAgICAgICAgICAgICAgICAgICAgICAgIG9wID0gX291dCAtIGJlZzsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGRpc3QgPiBvcCkgewogICAgICAgICAgICAgICAgICAgICAgICAgIG9wID0gZGlzdCAtIG9wOwogICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChvcCA+IHdoYXZlKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoc3RhdGUuc2FuZSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbnZhbGlkIGRpc3RhbmNlIHRvbyBmYXIgYmFjayI7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrIHRvcDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgZnJvbSA9IDA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgZnJvbV9zb3VyY2UgPSBzX3dpbmRvdzsKICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAod25leHQgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZyb20gKz0gd3NpemUgLSBvcDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChvcCA8IGxlbikgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBsZW4gLT0gb3A7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IHNfd2luZG93W2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gd2hpbGUgKC0tb3ApOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tID0gX291dCAtIGRpc3Q7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZyb21fc291cmNlID0gb3V0cHV0OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAod25leHQgPCBvcCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgZnJvbSArPSB3c2l6ZSArIHduZXh0IC0gb3A7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBvcCAtPSB3bmV4dDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChvcCA8IGxlbikgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBsZW4gLT0gb3A7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IHNfd2luZG93W2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gd2hpbGUgKC0tb3ApOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tID0gMDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHduZXh0IDwgbGVuKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgb3AgPSB3bmV4dDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBsZW4gLT0gb3A7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBzX3dpbmRvd1tmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gd2hpbGUgKC0tb3ApOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZyb20gPSBfb3V0IC0gZGlzdDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tX3NvdXJjZSA9IG91dHB1dDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tICs9IHduZXh0IC0gb3A7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAob3AgPCBsZW4pIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbGVuIC09IG9wOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBzX3dpbmRvd1tmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IHdoaWxlICgtLW9wKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZnJvbSA9IF9vdXQgLSBkaXN0OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tX3NvdXJjZSA9IG91dHB1dDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgd2hpbGUgKGxlbiA+IDIpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gZnJvbV9zb3VyY2VbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gZnJvbV9zb3VyY2VbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gZnJvbV9zb3VyY2VbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxlbiAtPSAzOwogICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAobGVuKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IGZyb21fc291cmNlW2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAobGVuID4gMSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IGZyb21fc291cmNlW2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgIGZyb20gPSBfb3V0IC0gZGlzdDsKICAgICAgICAgICAgICAgICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IG91dHB1dFtmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBvdXRwdXRbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gb3V0cHV0W2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBsZW4gLT0gMzsKICAgICAgICAgICAgICAgICAgICAgICAgICB9IHdoaWxlIChsZW4gPiAyKTsKICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAobGVuKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IG91dHB1dFtmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGxlbiA+IDEpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBvdXRwdXRbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAoKG9wICYgNjQpID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGhlcmUgPSBkY29kZVsoaGVyZSAmIDY1NTM1KSArIChob2xkICYgKDEgPDwgb3ApIC0gMSldOwogICAgICAgICAgICAgICAgICAgICAgICBjb250aW51ZSBkb2Rpc3Q7CiAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbnZhbGlkIGRpc3RhbmNlIGNvZGUiOwogICAgICAgICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEOwogICAgICAgICAgICAgICAgICAgICAgICBicmVhayB0b3A7CiAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKChvcCAmIDY0KSA9PT0gMCkgewogICAgICAgICAgICAgICAgICBoZXJlID0gbGNvZGVbKGhlcmUgJiA2NTUzNSkgKyAoaG9sZCAmICgxIDw8IG9wKSAtIDEpXTsKICAgICAgICAgICAgICAgICAgY29udGludWUgZG9sZW47CiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKG9wICYgMzIpIHsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IFRZUEU7CiAgICAgICAgICAgICAgICAgIGJyZWFrIHRvcDsKICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImludmFsaWQgbGl0ZXJhbC9sZW5ndGggY29kZSI7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgIGJyZWFrIHRvcDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgIH0KICAgICAgICAgIH0gd2hpbGUgKF9pbiA8IGxhc3QgJiYgX291dCA8IGVuZCk7CiAgICAgICAgbGVuID0gYml0cyA+PiAzOwogICAgICAgIF9pbiAtPSBsZW47CiAgICAgICAgYml0cyAtPSBsZW4gPDwgMzsKICAgICAgICBob2xkICY9ICgxIDw8IGJpdHMpIC0gMTsKICAgICAgICBzdHJtLm5leHRfaW4gPSBfaW47CiAgICAgICAgc3RybS5uZXh0X291dCA9IF9vdXQ7CiAgICAgICAgc3RybS5hdmFpbF9pbiA9IF9pbiA8IGxhc3QgPyA1ICsgKGxhc3QgLSBfaW4pIDogNSAtIChfaW4gLSBsYXN0KTsKICAgICAgICBzdHJtLmF2YWlsX291dCA9IF9vdXQgPCBlbmQgPyAyNTcgKyAoZW5kIC0gX291dCkgOiAyNTcgLSAoX291dCAtIGVuZCk7CiAgICAgICAgc3RhdGUuaG9sZCA9IGhvbGQ7CiAgICAgICAgc3RhdGUuYml0cyA9IGJpdHM7CiAgICAgICAgcmV0dXJuOwogICAgICB9OwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvaW5mdHJlZXMuanMKICB2YXIgcmVxdWlyZV9pbmZ0cmVlcyA9IF9fY29tbW9uSlMoewogICAgIm5vZGVfbW9kdWxlcy8ucG5wbS9wYWtvQDEuMC4xMS9ub2RlX21vZHVsZXMvcGFrby9saWIvemxpYi9pbmZ0cmVlcy5qcyIoZXhwb3J0czIsIG1vZHVsZTIpIHsKICAgICAgaW5pdF9idWZmZXJfc2hpbSgpOwogICAgICAidXNlIHN0cmljdCI7CiAgICAgIHZhciB1dGlscyA9IHJlcXVpcmVfY29tbW9uKCk7CiAgICAgIHZhciBNQVhCSVRTID0gMTU7CiAgICAgIHZhciBFTk9VR0hfTEVOUyA9IDg1MjsKICAgICAgdmFyIEVOT1VHSF9ESVNUUyA9IDU5MjsKICAgICAgdmFyIENPREVTID0gMDsKICAgICAgdmFyIExFTlMgPSAxOwogICAgICB2YXIgRElTVFMgPSAyOwogICAgICB2YXIgbGJhc2UgPSBbCiAgICAgICAgMywKICAgICAgICA0LAogICAgICAgIDUsCiAgICAgICAgNiwKICAgICAgICA3LAogICAgICAgIDgsCiAgICAgICAgOSwKICAgICAgICAxMCwKICAgICAgICAxMSwKICAgICAgICAxMywKICAgICAgICAxNSwKICAgICAgICAxNywKICAgICAgICAxOSwKICAgICAgICAyMywKICAgICAgICAyNywKICAgICAgICAzMSwKICAgICAgICAzNSwKICAgICAgICA0MywKICAgICAgICA1MSwKICAgICAgICA1OSwKICAgICAgICA2NywKICAgICAgICA4MywKICAgICAgICA5OSwKICAgICAgICAxMTUsCiAgICAgICAgMTMxLAogICAgICAgIDE2MywKICAgICAgICAxOTUsCiAgICAgICAgMjI3LAogICAgICAgIDI1OCwKICAgICAgICAwLAogICAgICAgIDAKICAgICAgXTsKICAgICAgdmFyIGxleHQgPSBbCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTcsCiAgICAgICAgMTcsCiAgICAgICAgMTcsCiAgICAgICAgMTcsCiAgICAgICAgMTgsCiAgICAgICAgMTgsCiAgICAgICAgMTgsCiAgICAgICAgMTgsCiAgICAgICAgMTksCiAgICAgICAgMTksCiAgICAgICAgMTksCiAgICAgICAgMTksCiAgICAgICAgMjAsCiAgICAgICAgMjAsCiAgICAgICAgMjAsCiAgICAgICAgMjAsCiAgICAgICAgMjEsCiAgICAgICAgMjEsCiAgICAgICAgMjEsCiAgICAgICAgMjEsCiAgICAgICAgMTYsCiAgICAgICAgNzIsCiAgICAgICAgNzgKICAgICAgXTsKICAgICAgdmFyIGRiYXNlID0gWwogICAgICAgIDEsCiAgICAgICAgMiwKICAgICAgICAzLAogICAgICAgIDQsCiAgICAgICAgNSwKICAgICAgICA3LAogICAgICAgIDksCiAgICAgICAgMTMsCiAgICAgICAgMTcsCiAgICAgICAgMjUsCiAgICAgICAgMzMsCiAgICAgICAgNDksCiAgICAgICAgNjUsCiAgICAgICAgOTcsCiAgICAgICAgMTI5LAogICAgICAgIDE5MywKICAgICAgICAyNTcsCiAgICAgICAgMzg1LAogICAgICAgIDUxMywKICAgICAgICA3NjksCiAgICAgICAgMTAyNSwKICAgICAgICAxNTM3LAogICAgICAgIDIwNDksCiAgICAgICAgMzA3MywKICAgICAgICA0MDk3LAogICAgICAgIDYxNDUsCiAgICAgICAgODE5MywKICAgICAgICAxMjI4OSwKICAgICAgICAxNjM4NSwKICAgICAgICAyNDU3NywKICAgICAgICAwLAogICAgICAgIDAKICAgICAgXTsKICAgICAgdmFyIGRleHQgPSBbCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTcsCiAgICAgICAgMTcsCiAgICAgICAgMTgsCiAgICAgICAgMTgsCiAgICAgICAgMTksCiAgICAgICAgMTksCiAgICAgICAgMjAsCiAgICAgICAgMjAsCiAgICAgICAgMjEsCiAgICAgICAgMjEsCiAgICAgICAgMjIsCiAgICAgICAgMjIsCiAgICAgICAgMjMsCiAgICAgICAgMjMsCiAgICAgICAgMjQsCiAgICAgICAgMjQsCiAgICAgICAgMjUsCiAgICAgICAgMjUsCiAgICAgICAgMjYsCiAgICAgICAgMjYsCiAgICAgICAgMjcsCiAgICAgICAgMjcsCiAgICAgICAgMjgsCiAgICAgICAgMjgsCiAgICAgICAgMjksCiAgICAgICAgMjksCiAgICAgICAgNjQsCiAgICAgICAgNjQKICAgICAgXTsKICAgICAgbW9kdWxlMi5leHBvcnRzID0gZnVuY3Rpb24gaW5mbGF0ZV90YWJsZSh0eXBlLCBsZW5zLCBsZW5zX2luZGV4LCBjb2RlcywgdGFibGUsIHRhYmxlX2luZGV4LCB3b3JrLCBvcHRzKSB7CiAgICAgICAgdmFyIGJpdHMgPSBvcHRzLmJpdHM7CiAgICAgICAgdmFyIGxlbiA9IDA7CiAgICAgICAgdmFyIHN5bSA9IDA7CiAgICAgICAgdmFyIG1pbiA9IDAsIG1heCA9IDA7CiAgICAgICAgdmFyIHJvb3QyID0gMDsKICAgICAgICB2YXIgY3VyciA9IDA7CiAgICAgICAgdmFyIGRyb3AgPSAwOwogICAgICAgIHZhciBsZWZ0ID0gMDsKICAgICAgICB2YXIgdXNlZCA9IDA7CiAgICAgICAgdmFyIGh1ZmYgPSAwOwogICAgICAgIHZhciBpbmNyOwogICAgICAgIHZhciBmaWxsOwogICAgICAgIHZhciBsb3c7CiAgICAgICAgdmFyIG1hc2s7CiAgICAgICAgdmFyIG5leHQ7CiAgICAgICAgdmFyIGJhc2UgPSBudWxsOwogICAgICAgIHZhciBiYXNlX2luZGV4ID0gMDsKICAgICAgICB2YXIgZW5kOwogICAgICAgIHZhciBjb3VudCA9IG5ldyB1dGlscy5CdWYxNihNQVhCSVRTICsgMSk7CiAgICAgICAgdmFyIG9mZnMgPSBuZXcgdXRpbHMuQnVmMTYoTUFYQklUUyArIDEpOwogICAgICAgIHZhciBleHRyYSA9IG51bGw7CiAgICAgICAgdmFyIGV4dHJhX2luZGV4ID0gMDsKICAgICAgICB2YXIgaGVyZV9iaXRzLCBoZXJlX29wLCBoZXJlX3ZhbDsKICAgICAgICBmb3IgKGxlbiA9IDA7IGxlbiA8PSBNQVhCSVRTOyBsZW4rKykgewogICAgICAgICAgY291bnRbbGVuXSA9IDA7CiAgICAgICAgfQogICAgICAgIGZvciAoc3ltID0gMDsgc3ltIDwgY29kZXM7IHN5bSsrKSB7CiAgICAgICAgICBjb3VudFtsZW5zW2xlbnNfaW5kZXggKyBzeW1dXSsrOwogICAgICAgIH0KICAgICAgICByb290MiA9IGJpdHM7CiAgICAgICAgZm9yIChtYXggPSBNQVhCSVRTOyBtYXggPj0gMTsgbWF4LS0pIHsKICAgICAgICAgIGlmIChjb3VudFttYXhdICE9PSAwKSB7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAocm9vdDIgPiBtYXgpIHsKICAgICAgICAgIHJvb3QyID0gbWF4OwogICAgICAgIH0KICAgICAgICBpZiAobWF4ID09PSAwKSB7CiAgICAgICAgICB0YWJsZVt0YWJsZV9pbmRleCsrXSA9IDEgPDwgMjQgfCA2NCA8PCAxNiB8IDA7CiAgICAgICAgICB0YWJsZVt0YWJsZV9pbmRleCsrXSA9IDEgPDwgMjQgfCA2NCA8PCAxNiB8IDA7CiAgICAgICAgICBvcHRzLmJpdHMgPSAxOwogICAgICAgICAgcmV0dXJuIDA7CiAgICAgICAgfQogICAgICAgIGZvciAobWluID0gMTsgbWluIDwgbWF4OyBtaW4rKykgewogICAgICAgICAgaWYgKGNvdW50W21pbl0gIT09IDApIHsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChyb290MiA8IG1pbikgewogICAgICAgICAgcm9vdDIgPSBtaW47CiAgICAgICAgfQogICAgICAgIGxlZnQgPSAxOwogICAgICAgIGZvciAobGVuID0gMTsgbGVuIDw9IE1BWEJJVFM7IGxlbisrKSB7CiAgICAgICAgICBsZWZ0IDw8PSAxOwogICAgICAgICAgbGVmdCAtPSBjb3VudFtsZW5dOwogICAgICAgICAgaWYgKGxlZnQgPCAwKSB7CiAgICAgICAgICAgIHJldHVybiAtMTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKGxlZnQgPiAwICYmICh0eXBlID09PSBDT0RFUyB8fCBtYXggIT09IDEpKSB7CiAgICAgICAgICByZXR1cm4gLTE7CiAgICAgICAgfQogICAgICAgIG9mZnNbMV0gPSAwOwogICAgICAgIGZvciAobGVuID0gMTsgbGVuIDwgTUFYQklUUzsgbGVuKyspIHsKICAgICAgICAgIG9mZnNbbGVuICsgMV0gPSBvZmZzW2xlbl0gKyBjb3VudFtsZW5dOwogICAgICAgIH0KICAgICAgICBmb3IgKHN5bSA9IDA7IHN5bSA8IGNvZGVzOyBzeW0rKykgewogICAgICAgICAgaWYgKGxlbnNbbGVuc19pbmRleCArIHN5bV0gIT09IDApIHsKICAgICAgICAgICAgd29ya1tvZmZzW2xlbnNbbGVuc19pbmRleCArIHN5bV1dKytdID0gc3ltOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAodHlwZSA9PT0gQ09ERVMpIHsKICAgICAgICAgIGJhc2UgPSBleHRyYSA9IHdvcms7CiAgICAgICAgICBlbmQgPSAxOTsKICAgICAgICB9IGVsc2UgaWYgKHR5cGUgPT09IExFTlMpIHsKICAgICAgICAgIGJhc2UgPSBsYmFzZTsKICAgICAgICAgIGJhc2VfaW5kZXggLT0gMjU3OwogICAgICAgICAgZXh0cmEgPSBsZXh0OwogICAgICAgICAgZXh0cmFfaW5kZXggLT0gMjU3OwogICAgICAgICAgZW5kID0gMjU2OwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBiYXNlID0gZGJhc2U7CiAgICAgICAgICBleHRyYSA9IGRleHQ7CiAgICAgICAgICBlbmQgPSAtMTsKICAgICAgICB9CiAgICAgICAgaHVmZiA9IDA7CiAgICAgICAgc3ltID0gMDsKICAgICAgICBsZW4gPSBtaW47CiAgICAgICAgbmV4dCA9IHRhYmxlX2luZGV4OwogICAgICAgIGN1cnIgPSByb290MjsKICAgICAgICBkcm9wID0gMDsKICAgICAgICBsb3cgPSAtMTsKICAgICAgICB1c2VkID0gMSA8PCByb290MjsKICAgICAgICBtYXNrID0gdXNlZCAtIDE7CiAgICAgICAgaWYgKHR5cGUgPT09IExFTlMgJiYgdXNlZCA+IEVOT1VHSF9MRU5TIHx8IHR5cGUgPT09IERJU1RTICYmIHVzZWQgPiBFTk9VR0hfRElTVFMpIHsKICAgICAgICAgIHJldHVybiAxOwogICAgICAgIH0KICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgIGhlcmVfYml0cyA9IGxlbiAtIGRyb3A7CiAgICAgICAgICBpZiAod29ya1tzeW1dIDwgZW5kKSB7CiAgICAgICAgICAgIGhlcmVfb3AgPSAwOwogICAgICAgICAgICBoZXJlX3ZhbCA9IHdvcmtbc3ltXTsKICAgICAgICAgIH0gZWxzZSBpZiAod29ya1tzeW1dID4gZW5kKSB7CiAgICAgICAgICAgIGhlcmVfb3AgPSBleHRyYVtleHRyYV9pbmRleCArIHdvcmtbc3ltXV07CiAgICAgICAgICAgIGhlcmVfdmFsID0gYmFzZVtiYXNlX2luZGV4ICsgd29ya1tzeW1dXTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGhlcmVfb3AgPSAzMiArIDY0OwogICAgICAgICAgICBoZXJlX3ZhbCA9IDA7CiAgICAgICAgICB9CiAgICAgICAgICBpbmNyID0gMSA8PCBsZW4gLSBkcm9wOwogICAgICAgICAgZmlsbCA9IDEgPDwgY3VycjsKICAgICAgICAgIG1pbiA9IGZpbGw7CiAgICAgICAgICBkbyB7CiAgICAgICAgICAgIGZpbGwgLT0gaW5jcjsKICAgICAgICAgICAgdGFibGVbbmV4dCArIChodWZmID4+IGRyb3ApICsgZmlsbF0gPSBoZXJlX2JpdHMgPDwgMjQgfCBoZXJlX29wIDw8IDE2IHwgaGVyZV92YWwgfCAwOwogICAgICAgICAgfSB3aGlsZSAoZmlsbCAhPT0gMCk7CiAgICAgICAgICBpbmNyID0gMSA8PCBsZW4gLSAxOwogICAgICAgICAgd2hpbGUgKGh1ZmYgJiBpbmNyKSB7CiAgICAgICAgICAgIGluY3IgPj49IDE7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoaW5jciAhPT0gMCkgewogICAgICAgICAgICBodWZmICY9IGluY3IgLSAxOwogICAgICAgICAgICBodWZmICs9IGluY3I7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBodWZmID0gMDsKICAgICAgICAgIH0KICAgICAgICAgIHN5bSsrOwogICAgICAgICAgaWYgKC0tY291bnRbbGVuXSA9PT0gMCkgewogICAgICAgICAgICBpZiAobGVuID09PSBtYXgpIHsKICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgICBsZW4gPSBsZW5zW2xlbnNfaW5kZXggKyB3b3JrW3N5bV1dOwogICAgICAgICAgfQogICAgICAgICAgaWYgKGxlbiA+IHJvb3QyICYmIChodWZmICYgbWFzaykgIT09IGxvdykgewogICAgICAgICAgICBpZiAoZHJvcCA9PT0gMCkgewogICAgICAgICAgICAgIGRyb3AgPSByb290MjsKICAgICAgICAgICAgfQogICAgICAgICAgICBuZXh0ICs9IG1pbjsKICAgICAgICAgICAgY3VyciA9IGxlbiAtIGRyb3A7CiAgICAgICAgICAgIGxlZnQgPSAxIDw8IGN1cnI7CiAgICAgICAgICAgIHdoaWxlIChjdXJyICsgZHJvcCA8IG1heCkgewogICAgICAgICAgICAgIGxlZnQgLT0gY291bnRbY3VyciArIGRyb3BdOwogICAgICAgICAgICAgIGlmIChsZWZ0IDw9IDApIHsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBjdXJyKys7CiAgICAgICAgICAgICAgbGVmdCA8PD0gMTsKICAgICAgICAgICAgfQogICAgICAgICAgICB1c2VkICs9IDEgPDwgY3VycjsKICAgICAgICAgICAgaWYgKHR5cGUgPT09IExFTlMgJiYgdXNlZCA+IEVOT1VHSF9MRU5TIHx8IHR5cGUgPT09IERJU1RTICYmIHVzZWQgPiBFTk9VR0hfRElTVFMpIHsKICAgICAgICAgICAgICByZXR1cm4gMTsKICAgICAgICAgICAgfQogICAgICAgICAgICBsb3cgPSBodWZmICYgbWFzazsKICAgICAgICAgICAgdGFibGVbbG93XSA9IHJvb3QyIDw8IDI0IHwgY3VyciA8PCAxNiB8IG5leHQgLSB0YWJsZV9pbmRleCB8IDA7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChodWZmICE9PSAwKSB7CiAgICAgICAgICB0YWJsZVtuZXh0ICsgaHVmZl0gPSBsZW4gLSBkcm9wIDw8IDI0IHwgNjQgPDwgMTYgfCAwOwogICAgICAgIH0KICAgICAgICBvcHRzLmJpdHMgPSByb290MjsKICAgICAgICByZXR1cm4gMDsKICAgICAgfTsKICAgIH0KICB9KTsKCiAgLy8gbm9kZV9tb2R1bGVzLy5wbnBtL3Bha29AMS4wLjExL25vZGVfbW9kdWxlcy9wYWtvL2xpYi96bGliL2luZmxhdGUuanMKICB2YXIgcmVxdWlyZV9pbmZsYXRlID0gX19jb21tb25KUyh7CiAgICAibm9kZV9tb2R1bGVzLy5wbnBtL3Bha29AMS4wLjExL25vZGVfbW9kdWxlcy9wYWtvL2xpYi96bGliL2luZmxhdGUuanMiKGV4cG9ydHMyKSB7CiAgICAgIGluaXRfYnVmZmVyX3NoaW0oKTsKICAgICAgInVzZSBzdHJpY3QiOwogICAgICB2YXIgdXRpbHMgPSByZXF1aXJlX2NvbW1vbigpOwogICAgICB2YXIgYWRsZXIzMiA9IHJlcXVpcmVfYWRsZXIzMigpOwogICAgICB2YXIgY3JjMzIgPSByZXF1aXJlX2NyYzMyKCk7CiAgICAgIHZhciBpbmZsYXRlX2Zhc3QgPSByZXF1aXJlX2luZmZhc3QoKTsKICAgICAgdmFyIGluZmxhdGVfdGFibGUgPSByZXF1aXJlX2luZnRyZWVzKCk7CiAgICAgIHZhciBDT0RFUyA9IDA7CiAgICAgIHZhciBMRU5TID0gMTsKICAgICAgdmFyIERJU1RTID0gMjsKICAgICAgdmFyIFpfRklOSVNIID0gNDsKICAgICAgdmFyIFpfQkxPQ0sgPSA1OwogICAgICB2YXIgWl9UUkVFUyA9IDY7CiAgICAgIHZhciBaX09LID0gMDsKICAgICAgdmFyIFpfU1RSRUFNX0VORCA9IDE7CiAgICAgIHZhciBaX05FRURfRElDVCA9IDI7CiAgICAgIHZhciBaX1NUUkVBTV9FUlJPUiA9IC0yOwogICAgICB2YXIgWl9EQVRBX0VSUk9SID0gLTM7CiAgICAgIHZhciBaX01FTV9FUlJPUiA9IC00OwogICAgICB2YXIgWl9CVUZfRVJST1IgPSAtNTsKICAgICAgdmFyIFpfREVGTEFURUQgPSA4OwogICAgICB2YXIgSEVBRCA9IDE7CiAgICAgIHZhciBGTEFHUyA9IDI7CiAgICAgIHZhciBUSU1FID0gMzsKICAgICAgdmFyIE9TID0gNDsKICAgICAgdmFyIEVYTEVOID0gNTsKICAgICAgdmFyIEVYVFJBID0gNjsKICAgICAgdmFyIE5BTUUgPSA3OwogICAgICB2YXIgQ09NTUVOVCA9IDg7CiAgICAgIHZhciBIQ1JDID0gOTsKICAgICAgdmFyIERJQ1RJRCA9IDEwOwogICAgICB2YXIgRElDVCA9IDExOwogICAgICB2YXIgVFlQRSA9IDEyOwogICAgICB2YXIgVFlQRURPID0gMTM7CiAgICAgIHZhciBTVE9SRUQgPSAxNDsKICAgICAgdmFyIENPUFlfID0gMTU7CiAgICAgIHZhciBDT1BZID0gMTY7CiAgICAgIHZhciBUQUJMRSA9IDE3OwogICAgICB2YXIgTEVOTEVOUyA9IDE4OwogICAgICB2YXIgQ09ERUxFTlMgPSAxOTsKICAgICAgdmFyIExFTl8gPSAyMDsKICAgICAgdmFyIExFTiA9IDIxOwogICAgICB2YXIgTEVORVhUID0gMjI7CiAgICAgIHZhciBESVNUID0gMjM7CiAgICAgIHZhciBESVNURVhUID0gMjQ7CiAgICAgIHZhciBNQVRDSCA9IDI1OwogICAgICB2YXIgTElUID0gMjY7CiAgICAgIHZhciBDSEVDSyA9IDI3OwogICAgICB2YXIgTEVOR1RIID0gMjg7CiAgICAgIHZhciBET05FID0gMjk7CiAgICAgIHZhciBCQUQgPSAzMDsKICAgICAgdmFyIE1FTSA9IDMxOwogICAgICB2YXIgU1lOQyA9IDMyOwogICAgICB2YXIgRU5PVUdIX0xFTlMgPSA4NTI7CiAgICAgIHZhciBFTk9VR0hfRElTVFMgPSA1OTI7CiAgICAgIHZhciBNQVhfV0JJVFMgPSAxNTsKICAgICAgdmFyIERFRl9XQklUUyA9IE1BWF9XQklUUzsKICAgICAgZnVuY3Rpb24genN3YXAzMihxKSB7CiAgICAgICAgcmV0dXJuIChxID4+PiAyNCAmIDI1NSkgKyAocSA+Pj4gOCAmIDY1MjgwKSArICgocSAmIDY1MjgwKSA8PCA4KSArICgocSAmIDI1NSkgPDwgMjQpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIEluZmxhdGVTdGF0ZSgpIHsKICAgICAgICB0aGlzLm1vZGUgPSAwOwogICAgICAgIHRoaXMubGFzdCA9IGZhbHNlOwogICAgICAgIHRoaXMud3JhcCA9IDA7CiAgICAgICAgdGhpcy5oYXZlZGljdCA9IGZhbHNlOwogICAgICAgIHRoaXMuZmxhZ3MgPSAwOwogICAgICAgIHRoaXMuZG1heCA9IDA7CiAgICAgICAgdGhpcy5jaGVjayA9IDA7CiAgICAgICAgdGhpcy50b3RhbCA9IDA7CiAgICAgICAgdGhpcy5oZWFkID0gbnVsbDsKICAgICAgICB0aGlzLndiaXRzID0gMDsKICAgICAgICB0aGlzLndzaXplID0gMDsKICAgICAgICB0aGlzLndoYXZlID0gMDsKICAgICAgICB0aGlzLnduZXh0ID0gMDsKICAgICAgICB0aGlzLndpbmRvdyA9IG51bGw7CiAgICAgICAgdGhpcy5ob2xkID0gMDsKICAgICAgICB0aGlzLmJpdHMgPSAwOwogICAgICAgIHRoaXMubGVuZ3RoID0gMDsKICAgICAgICB0aGlzLm9mZnNldCA9IDA7CiAgICAgICAgdGhpcy5leHRyYSA9IDA7CiAgICAgICAgdGhpcy5sZW5jb2RlID0gbnVsbDsKICAgICAgICB0aGlzLmRpc3Rjb2RlID0gbnVsbDsKICAgICAgICB0aGlzLmxlbmJpdHMgPSAwOwogICAgICAgIHRoaXMuZGlzdGJpdHMgPSAwOwogICAgICAgIHRoaXMubmNvZGUgPSAwOwogICAgICAgIHRoaXMubmxlbiA9IDA7CiAgICAgICAgdGhpcy5uZGlzdCA9IDA7CiAgICAgICAgdGhpcy5oYXZlID0gMDsKICAgICAgICB0aGlzLm5leHQgPSBudWxsOwogICAgICAgIHRoaXMubGVucyA9IG5ldyB1dGlscy5CdWYxNigzMjApOwogICAgICAgIHRoaXMud29yayA9IG5ldyB1dGlscy5CdWYxNigyODgpOwogICAgICAgIHRoaXMubGVuZHluID0gbnVsbDsKICAgICAgICB0aGlzLmRpc3RkeW4gPSBudWxsOwogICAgICAgIHRoaXMuc2FuZSA9IDA7CiAgICAgICAgdGhpcy5iYWNrID0gMDsKICAgICAgICB0aGlzLndhcyA9IDA7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gaW5mbGF0ZVJlc2V0S2VlcChzdHJtKSB7CiAgICAgICAgdmFyIHN0YXRlOwogICAgICAgIGlmICghc3RybSB8fCAhc3RybS5zdGF0ZSkgewogICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VSUk9SOwogICAgICAgIH0KICAgICAgICBzdGF0ZSA9IHN0cm0uc3RhdGU7CiAgICAgICAgc3RybS50b3RhbF9pbiA9IHN0cm0udG90YWxfb3V0ID0gc3RhdGUudG90YWwgPSAwOwogICAgICAgIHN0cm0ubXNnID0gIiI7CiAgICAgICAgaWYgKHN0YXRlLndyYXApIHsKICAgICAgICAgIHN0cm0uYWRsZXIgPSBzdGF0ZS53cmFwICYgMTsKICAgICAgICB9CiAgICAgICAgc3RhdGUubW9kZSA9IEhFQUQ7CiAgICAgICAgc3RhdGUubGFzdCA9IDA7CiAgICAgICAgc3RhdGUuaGF2ZWRpY3QgPSAwOwogICAgICAgIHN0YXRlLmRtYXggPSAzMjc2ODsKICAgICAgICBzdGF0ZS5oZWFkID0gbnVsbDsKICAgICAgICBzdGF0ZS5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AgICB3cmFwID0gKHdpbmRvd0JpdHMgPj4gNCkgKyAxOwogICAgICAgICAgaWYgKHdpbmRvd0JpdHMgPCA0OCkgewogICAgICAgICAgICB3aW5kb3dCaXRzICY9IDE1OwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAod2luZG93Qml0cyAmJiAod2luZG93Qml0cyA8IDggfHwgd2luZG93Qml0cyA+IDE1KSkgewogICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VSUk9SOwogICAgICAgIH0KICAgICAgICBpZiAoc3RhdGUud2luZG93ICE9PSBudWxsICYmIHN0YXRlLndiaXRzICE9PSB3aW5kb3dCaXRzKSB7CiAgICAgICAgICBzdGF0ZS53aW5kb3cgPSBudWxsOwogICAgICAgIH0KICAgICAgICBzdGF0ZS53cmFwID0gd3JhcDsKICAgICAgICBzdGF0ZS53Yml0cyA9IHdpbmRvd0JpdHM7CiAgICAgICAgcmV0dXJuIGluZmxhdGVSZXNldChzdHJtKTsKICAgICAgfQogICAgICBmdW5jdGlvbiBpbmZsYXRlSW5pdDIoc3RybSwgd2luZG93Qml0cykgewogICAgICAgIHZhciByZXQ7CiAgICAgICAgdmFyIHN0YXRlOwogICAgICAgIGlmICghc3RybSkgewogICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VSUk9SOwogICAgICAgIH0KICAgICAgICBzdGF0ZSA9IG5ldyBJbmZsYXRlU3RhdGUoKTsKICAgICAgICBzdHJtLnN0YXRlID0gc3RhdGU7CiAgICAgICAgc3RhdGUud2luZG93ID0gbnVsbDsKICAgICAgICByZXQgPSBpbmZsYXRlUmVzZXQyKHN0cm0sIHdpbmRvd0JpdHMpOwogICAgICAgIGlmIChyZXQgIT09IFpfT0spIHsKICAgICAgICAgIHN0cm0uc3RhdGUgPSBudWxsOwogICAgICAgIH0KICAgICAgICByZXR1cm4gcmV0OwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGluZmxhdGVJbml0KHN0cm0pIHsKICAgICAgICByZXR1cm4gaW5mbGF0ZUluaXQyKHN0cm0sIERFRl9XQklUUyk7CiAgICAgIH0KICAgICAgdmFyIHZpcmdpbiA9IHRydWU7CiAgICAgIHZhciBsZW5maXg7CiAgICAgIHZhciBkaXN0Zml4OwogICAgICBmdW5jdGlvbiBmaXhlZHRhYmxlcyhzdGF0ZSkgewogICAgICAgIGlmICh2aXJnaW4pIHsKICAgICAgICAgIHZhciBzeW07CiAgICAgICAgICBsZW5maXggPSBuZXcgdXRpbHMuQnVmMzIoNTEyKTsKICAgICAgICAgIGRpc3RmaXggPSBuZXcgdXRpbHMuQnVmMzIoMzIpOwogICAgICAgICAgc3ltID0gMDsKICAgICAgICAgIHdoaWxlIChzeW0gPCAxNDQpIHsKICAgICAgICAgICAgc3RhdGUubGVuc1tzeW0rK10gPSA4OwogICAgICAgICAgfQogICAgICAgICAgd2hpbGUgKHN5bSA8IDI1NikgewogICAgICAgICAgICBzdGF0ZS5sZW5zW3N5bSsrXSA9IDk7CiAgICAgICAgICB9CiAgICAgICAgICB3aGlsZSAoc3ltIDwgMjgwKSB7CiAgICAgICAgICAgIHN0YXRlLmxlbnNbc3ltKytdID0gNzsKICAgICAgICAgIH0KICAgICAgICAgIHdoaWxlIChzeW0gPCAyODgpIHsKICAgICAgICAgICAgc3RhdGUubGVuc1tzeW0rK10gPSA4OwogICAgICAgICAgfQogICAgICAgICAgaW5mbGF0ZV90YWJsZShMRU5TLCBzdGF0ZS5sZW5zLCAwLCAyODgsIGxlbmZpeCwgMCwgc3RhdGUud29yaywgeyBiaXRzOiA5IH0pOwogICAgICAgICAgc3ltID0gMDsKICAgICAgICAgIHdoaWxlIChzeW0gPCAzMikgewogICAgICAgICAgICBzdGF0ZS5sZW5zW3N5bSsrXSA9IDU7CiAgICAgICAgICB9CiAgICAgICAgICBpbmZsYXRlX3RhYmxlKERJU1RTLCBzdGF0ZS5sZW5zLCAwLCAzMiwgZGlzdGZpeCwgMCwgc3RhdGUud29yaywgeyBiaXRzOiA1IH0pOwogICAgICAgICAgdmlyZ2luID0gZmFsc2U7CiAgICAgICAgfQogICAgICAgIHN0YXRlLmxlbmNvZGUgPSBsZW5maXg7CiAgICAgICAgc3RhdGUubGVuYml0cyA9IDk7CiAgICAgICAgc3RhdGUuZGlzdGNvZGUgPSBkaXN0Zml4OwogICAgICAgIHN0YXRlLmRpc3RiaXRzID0gNTsKICAgICAgfQogICAgICBmdW5jdGlvbiB1cGRhdGV3aW5kb3coc3RybSwgc3JjLCBlbmQsIGNvcHkpIHsKICAgICAgICB2YXIgZGlzdDsKICAgICAgICB2YXIgc3RhdGUgPSBzdHJtLnN0YXRlOwogICAgICAgIGlmIChzdGF0ZS53aW5kb3cgPT09IG51bGwpIHsKICAgICAgICAgIHN0YXRlLndzaXplID0gMSA8PCBzdGF0ZS53Yml0czsKICAgICAgICAgIHN0YXRlLnduZXh0ID0gMDsKICAgICAgICAgIHN0YXRlLndoYXZlID0gMDsKICAgICAgICAgIHN0YXRlLndpbmRvdyA9IG5ldyB1dGlscy5CdWY4KHN0YXRlLndzaXplKTsKICAgICAgICB9CiAgICAgICAgaWYgKGNvcHkgPj0gc3RhdGUud3NpemUpIHsKICAgICAgICAgIHV0aWxzLmFycmF5U2V0KHN0YXRlLndpbmRvdywgc3JjLCBlbmQgLSBzdGF0ZS53c2l6ZSwgc3RhdGUud3NpemUsIDApOwogICAgICAgICAgc3RhdGUud25leHQgPSAwOwogICAgICAgICAgc3RhdGUud2hhdmUgPSBzdGF0ZS53c2l6ZTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgZGlzdCA9IHN0YXRlLndzaXplIC0gc3RhdGUud25leHQ7CiAgICAgICAgICBpZiAoZGlzdCA+IGNvcHkpIHsKICAgICAgICAgICAgZGlzdCA9IGNvcHk7CiAgICAgICAgICB9CiAgICAgICAgICB1dGlscy5hcnJheVNldChzdGF0ZS53aW5kb3csIHNyYywgZW5kIC0gY29weSwgZGlzdCwgc3RhdGUud25leHQpOwogICAgICAgICAgY29weSAtPSBkaXN0OwogICAgICAgICAgaWYgKGNvcHkpIHsKICAgICAgICAgICAgdXRpbHMuYXJyYXlTZXQoc3RhdGUud2luZG93LCBzcmMsIGVuZCAtIGNvcHksIGNvcHksIDApOwogICAgICAgICAgICBzdGF0ZS53bmV4dCA9IGNvcHk7CiAgICAgICAgICAgIHN0YXRlLndoYXZlID0gc3RhdGUud3NpemU7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBzdGF0ZS53bmV4dCArPSBkaXN0OwogICAgICAgICAgICBpZiAoc3RhdGUud25leHQgPT09IHN0YXRlLndzaXplKSB7CiAgICAgICAgICAgICAgc3RhdGUud25leHQgPSAwOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzdGF0ZS53aGF2ZSA8IHN0YXRlLndzaXplKSB7CiAgICAgICAgICAgICAgc3RhdGUud2hhdmUgKz0gZGlzdDsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gMDsKICAgICAgfQogICAgICBmdW5jdGlvbiBpbmZsYXRlKHN0cm0sIGZsdXNoKSB7CiAgICAgICAgdmFyIHN0YXRlOwogICAgICAgIHZhciBpbnB1dCwgb3V0cHV0OwogICAgICAgIHZhciBuZXh0OwogICAgICAgIHZhciBwdXQ7CiAgICAgICAgdmFyIGhhdmUsIGxlZnQ7CiAgICAgICAgdmFyIGhvbGQ7CiAgICAgICAgdmFyIGJpdHM7CiAgICAgICAgdmFyIF9pbiwgX291dDsKICAgICAgICB2YXIgY29weTsKICAgICAgICB2YXIgZnJvbTsKICAgICAgICB2YXIgZnJvbV9zb3VyY2U7CiAgICAgICAgdmFyIGhlcmUgPSAwOwogICAgICAgIHZhciBoZXJlX2JpdHMsIGhlcmVfb3AsIGhlcmVfdmFsOwogICAgICAgIHZhciBsYXN0X2JpdHMsIGxhc3Rfb3AsIGxhc3RfdmFsOwogICAgICAgIHZhciBsZW47CiAgICAgICAgdmFyIHJldDsKICAgICAgICB2YXIgaGJ1ZiA9IG5ldyB1dGlscy5CdWY4KDQpOwogICAgICAgIHZhciBvcHRzOwogICAgICAgIHZhciBuOwogICAgICAgIHZhciBvcmRlciA9IFsxNiwgMTcsIDE4LCAwLCA4LCA3LCA5LCA2LCAxMCwgNSwgMTEsIDQsIDEyLCAzLCAxMywgMiwgMTQsIDEsIDE1XTsKICAgICAgICBpZiAoIXN0cm0gfHwgIXN0cm0uc3RhdGUgfHwgIXN0cm0ub3V0cHV0IHx8ICFzdHJtLmlucHV0ICYmIHN0cm0uYXZhaWxfaW4gIT09IDApIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgc3RhdGUgPSBzdHJtLnN0YXRlOwogICAgICAgIGlmIChzdGF0ZS5tb2RlID09PSBUWVBFKSB7CiAgICAgICAgICBzdGF0ZS5tb2RlID0gVFlQRURPOwogICAgICAgIH0KICAgICAgICBwdXQgPSBzdHJtLm5leHRfb3V0OwogICAgICAgIG91dHB1dCA9IHN0cm0ub3V0cHV0OwogICAgICAgIGxlZnQgPSBzdHJtLmF2YWlsX291dDsKICAgICAgICBuZXh0ID0gc3RybS5uZXh0X2luOwogICAgICAgIGlucHV0ID0gc3RybS5pbnB1dDsKICAgICAgICBoYXZlID0gc3RybS5hdmFpbF9pbjsKICAgICAgICBob2xkID0gc3RhdGUuaG9sZDsKICAgICAgICBiaXRzID0gc3RhdGUuYml0czsKICAgICAgICBfaW4gPSBoYXZlOwogICAgICAgIF9vdXQgPSBsZWZ0OwogICAgICAgIHJldCA9IFpfT0s7CiAgICAgICAgaW5mX2xlYXZlOgogICAgICAgICAgZm9yICg7IDsgKSB7CiAgICAgICAgICAgIHN3aXRjaCAoc3RhdGUubW9kZSkgewogICAgICAgICAgICAgIGNhc2UgSEVBRDoKICAgICAgICAgICAgICAgIGlmIChzdGF0ZS53cmFwID09PSAwKSB7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBUWVBFRE87CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCAxNikgewogICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUud3JhcCAmIDIgJiYgaG9sZCA9PT0gMzU2MTUpIHsKICAgICAgICAgICAgICAgICAgc3RhdGUuY2hlY2sgPSAwOwogICAgICAgICAgICAgICAgICBoYnVmWzBdID0gaG9sZCAmIDI1NTsKICAgICAgICAgICAgICAgICAgaGJ1ZlsxXSA9IGhvbGQgPj4+IDggJiAyNTU7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmNoZWNrID0gY3JjMzIoc3RhdGUuY2hlY2ssIGhidWYsIDIsIDApOwogICAgICAgICAgICAgICAgICBob2xkID0gMDsKICAgICAgICAgICAgICAgICAgYml0cyA9IDA7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBGTEFHUzsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5mbGFncyA9IDA7CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuaGVhZCkgewogICAgICAgICAgICAgICAgICBzdGF0ZS5oZWFkLmRvbmUgPSBmYWxzZTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmICghKHN0YXRlLndyYXAgJiAxKSB8fCAoKChob2xkICYgMjU1KSA8PCA4KSArIChob2xkID4+IDgpKSAlIDMxKSB7CiAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImluY29ycmVjdCBoZWFkZXIgY2hlY2siOwogICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEOwogICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmICgoaG9sZCAmIDE1KSAhPT0gWl9ERUZMQVRFRCkgewogICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJ1bmtub3duIGNvbXByZXNzaW9uIG1ldGhvZCI7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaG9sZCA+Pj49IDQ7CiAgICAgICAgICAgICAgICBiaXRzIC09IDQ7CiAgICAgICAgICAgICAgICBsZW4gPSAoaG9sZCAmIDE1KSArIDg7CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUud2JpdHMgPT09IDApIHsKICAgICAgICAgICAgICAgICAgc3RhdGUud2JpdHMgPSBsZW47CiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKGxlbiA+IHN0YXRlLndiaXRzKSB7CiAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImludmFsaWQgd2luZG93IHNpemUiOwogICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEOwogICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0YXRlLmRtYXggPSAxIDw8IGxlbjsKICAgICAgICAgICAgICAgIHN0cm0uYWRsZXIgPSBzdGF0ZS5jaGVjayA9IDE7CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gaG9sZCAmIDUxMiA/IERJQ1RJRCA6IFRZUEU7CiAgICAgICAgICAgICAgICBob2xkID0gMDsKICAgICAgICAgICAgICAgIGJpdHMgPSAwOwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgY2FzZSBGTEFHUzoKICAgICAgICAgICAgICAgIHdoaWxlIChiaXRzIDwgMTYpIHsKICAgICAgICAgICAgICAgICAgaWYgKGhhdmUgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaGF2ZS0tOwogICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUuZmxhZ3MgPSBob2xkOwogICAgICAgICAgICAgICAgaWYgKChzdGF0ZS5mbGFncyAmIDI1NSkgIT09IFpfREVGTEFURUQpIHsKICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAidW5rbm93biBjb21wcmVzc2lvbiBtZXRob2QiOwogICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEOwogICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5mbGFncyAmIDU3MzQ0KSB7CiAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gInVua25vd24gaGVhZGVyIGZsYWdzIHNldCI7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmhlYWQpIHsKICAgICAgICAgICAgICAgICAgc3RhdGUuaGVhZC50ZXh0ID0gaG9sZCA+PiA4ICYgMTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5mbGFncyAmIDUxMikgewogICAgICAgICAgICAgICAgICBoYnVmWzBdID0gaG9sZCAmIDI1NTsKICAgICAgICAgICAgICAgICAgaGJ1ZlsxXSA9IGhvbGQgPj4+IDggJiAyNTU7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmNoZWNrID0gY3JjMzIoc3RhdGUuY2hlY2ssIGhidWYsIDIsIDApOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaG9sZCA9IDA7CiAgICAgICAgICAgICAgICBiaXRzID0gMDsKICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBUSU1FOwogICAgICAgICAgICAgIGNhc2UgVElNRToKICAgICAgICAgICAgICAgIHdoaWxlIChiaXRzIDwgMzIpIHsKICAgICAgICAgICAgICAgICAgaWYgKGhhdmUgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaGF2ZS0tOwogICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmhlYWQpIHsKICAgICAgICAgICAgICAgICAgc3RhdGUuaGVhZC50aW1lID0gaG9sZDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5mbGFncyAmIDUxMikgewogICAgICAgICAgICAgICAgICBoYnVmWzBdID0gaG9sZCAmIDI1NTsKICAgICAgICAgICAgICAgICAgaGJ1ZlsxXSA9IGhvbGQgPj4+IDggJiAyNTU7CiAgICAgICAgICAgICAgICAgIGhidWZbMl0gPSBob2xkID4+PiAxNiAmIDI1NTsKICAgICAgICAgICAgICAgICAgaGJ1ZlszXSA9IGhvbGQgPj4+IDI0ICYgMjU1OwogICAgICAgICAgICAgICAgICBzdGF0ZS5jaGVjayA9IGNyYzMyKHN0YXRlLmNoZWNrLCBoYnVmLCA0LCAwKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGhvbGQgPSAwOwogICAgICAgICAgICAgICAgYml0cyA9IDA7CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gT1M7CiAgICAgICAgICAgICAgY2FzZSBPUzoKICAgICAgICAgICAgICAgIHdoaWxlIChiaXRzIDwgMTYpIHsKICAgICAgICAgICAgICAgICAgaWYgKGhhdmUgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaGF2ZS0tOwogICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmhlYWQpIHsKICAgICAgICAgICAgICAgICAgc3RhdGUuaGVhZC54ZmxhZ3MgPSBob2xkICYgMjU1OwogICAgICAgICAgICAgICAgICBzdGF0ZS5oZWFkLm9zID0gaG9sZCA+PiA4OwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmZsYWdzICYgNTEyKSB7CiAgICAgICAgICAgICAgICAgIGhidWZbMF0gPSBob2xkICYgMjU1OwogICAgICAgICAgICAgICAgICBoYnVmWzFdID0gaG9sZCA+Pj4gOCAmIDI1NTsKICAgICAgICAgICAgICAgICAgc3RhdGUuY2hlY2sgPSBjcmMzMihzdGF0ZS5jaGVjaywgaGJ1ZiwgMiwgMCk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBob2xkID0gMDsKICAgICAgICAgICAgICAgIGJpdHMgPSAwOwogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEVYTEVOOwogICAgICAgICAgICAgIGNhc2UgRVhMRU46CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuZmxhZ3MgJiAxMDI0KSB7CiAgICAgICAgICAgICAgICAgIHdoaWxlIChiaXRzIDwgMTYpIHsKICAgICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIHN0YXRlLmxlbmd0aCA9IGhvbGQ7CiAgICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5oZWFkKSB7CiAgICAgICAgICAgICAgICAgICAgc3RhdGUuaGVhZC5leHRyYV9sZW4gPSBob2xkOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5mbGFncyAmIDUxMikgewogICAgICAgICAgICAgICAgICAgIGhidWZbMF0gPSBob2xkICYgMjU1OwogICAgICAgICAgICAgICAgICAgIGhidWZbMV0gPSBob2xkID4+PiA4ICYgMjU1OwogICAgICAgICAgICAgICAgICAgIHN0YXRlLmNoZWNrID0gY3JjMzIoc3RhdGUuY2hlY2ssIGhidWYsIDIsIDApOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGhvbGQgPSAwOwogICAgICAgICAgICAgICAgICBiaXRzID0gMDsKICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAoc3RhdGUuaGVhZCkgewogICAgICAgICAgICAgICAgICBzdGF0ZS5oZWFkLmV4dHJhID0gbnVsbDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBFWFRSQTsKICAgICAgICAgICAgICBjYXNlIEVYVFJBOgogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmZsYWdzICYgMTAyNCkgewogICAgICAgICAgICAgICAgICBjb3B5ID0gc3RhdGUubGVuZ3RoOwogICAgICAgICAgICAgICAgICBpZiAoY29weSA+IGhhdmUpIHsKICAgICAgICAgICAgICAgICAgICBjb3B5ID0gaGF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBpZiAoY29weSkgewogICAgICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5oZWFkKSB7CiAgICAgICAgICAgICAgICAgICAgICBsZW4gPSBzdGF0ZS5oZWFkLmV4dHJhX2xlbiAtIHN0YXRlLmxlbmd0aDsKICAgICAgICAgICAgICAgICAgICAgIGlmICghc3RhdGUuaGVhZC5leHRyYSkgewogICAgICAgICAgICAgICAgICAgICAgICBzdGF0ZS5oZWFkLmV4dHJhID0gbmV3IEFycmF5KHN0YXRlLmhlYWQuZXh0cmFfbGVuKTsKICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgIHV0aWxzLmFycmF5U2V0KHN0YXRlLmhlYWQuZXh0cmEsIGlucHV0LCBuZXh0LCBjb3B5LCBsZW4pOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBpZiAoc3RhdGUuZmxhZ3MgJiA1MTIpIHsKICAgICAgICAgICAgICAgICAgICAgIHN0YXRlLmNoZWNrID0gY3JjMzIoc3RhdGUuY2hlY2ssIGlucHV0LCBjb3B5LCBuZXh0KTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgaGF2ZSAtPSBjb3B5OwogICAgICAgICAgICAgICAgICAgIG5leHQgKz0gY29weTsKICAgICAgICAgICAgICAgICAgICBzdGF0ZS5sZW5ndGggLT0gY29weTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBpZiAoc3RhdGUubGVuZ3RoKSB7CiAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5sZW5ndGggPSAwOwogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IE5BTUU7CiAgICAgICAgICAgICAgY2FzZSBOQU1FOgogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmZsYWdzICYgMjA0OCkgewogICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBjb3B5ID0gMDsKICAgICAgICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgICAgICAgIGxlbiA9IGlucHV0W25leHQgKyBjb3B5KytdOwogICAgICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5oZWFkICYmIGxlbiAmJiBzdGF0ZS5sZW5ndGggPCA2NTUzNikgewogICAgICAgICAgICAgICAgICAgICAgc3RhdGUuaGVhZC5uYW1lICs9IFN0cmluZy5mcm9tQ2hhckNvZGUobGVuKTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIH0gd2hpbGUgKGxlbiAmJiBjb3B5IDwgaGF2ZSk7CiAgICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5mbGFncyAmIDUxMikgewogICAgICAgICAgICAgICAgICAgIHN0YXRlLmNoZWNrID0gY3JjMzIoc3RhdGUuY2hlY2ssIGlucHV0LCBjb3B5LCBuZXh0KTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBoYXZlIC09IGNvcHk7CiAgICAgICAgICAgICAgICAgIG5leHQgKz0gY29weTsKICAgICAgICAgICAgICAgICAgaWYgKGxlbikgewogICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfSBlbHNlIGlmIChzdGF0ZS5oZWFkKSB7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmhlYWQubmFtZSA9IG51bGw7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5sZW5ndGggPSAwOwogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IENPTU1FTlQ7CiAgICAgICAgICAgICAgY2FzZSBDT01NRU5UOgogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmZsYWdzICYgNDA5NikgewogICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBjb3B5ID0gMDsKICAgICAgICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgICAgICAgIGxlbiA9IGlucHV0W25leHQgKyBjb3B5KytdOwogICAgICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5oZWFkICYmIGxlbiAmJiBzdGF0ZS5sZW5ndGggPCA2NTUzNikgewogICAgICAgICAgICAgICAgICAgICAgc3RhdGUuaGVhZC5jb21tZW50ICs9IFN0cmluZy5mcm9tQ2hhckNvZGUobGVuKTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIH0gd2hpbGUgKGxlbiAmJiBjb3B5IDwgaGF2ZSk7CiAgICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5mbGFncyAmIDUxMikgewogICAgICAgICAgICAgICAgICAgIHN0YXRlLmNoZWNrID0gY3JjMzIoc3RhdGUuY2hlY2ssIGlucHV0LCBjb3B5LCBuZXh0KTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBoYXZlIC09IGNvcHk7CiAgICAgICAgICAgICAgICAgIG5leHQgKz0gY29weTsKICAgICAgICAgICAgICAgICAgaWYgKGxlbikgewogICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfSBlbHNlIGlmIChzdGF0ZS5oZWFkKSB7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmhlYWQuY29tbWVudCA9IG51bGw7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gSENSQzsKICAgICAgICAgICAgICBjYXNlIEhDUkM6CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuZmxhZ3MgJiA1MTIpIHsKICAgICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCAxNikgewogICAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaWYgKGhvbGQgIT09IChzdGF0ZS5jaGVjayAmIDY1NTM1KSkgewogICAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImhlYWRlciBjcmMgbWlzbWF0Y2giOwogICAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaG9sZCA9IDA7CiAgICAgICAgICAgICAgICAgIGJpdHMgPSAwOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmhlYWQpIHsKICAgICAgICAgICAgICAgICAgc3RhdGUuaGVhZC5oY3JjID0gc3RhdGUuZmxhZ3MgPj4gOSAmIDE7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmhlYWQuZG9uZSA9IHRydWU7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gc3RhdGUuY2hlY2sgPSAwOwogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IFRZUEU7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICBjYXNlIERJQ1RJRDoKICAgICAgICAgICAgICAgIHdoaWxlIChiaXRzIDwgMzIpIHsKICAgICAgICAgICAgICAgICAgaWYgKGhhdmUgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaGF2ZS0tOwogICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RybS5hZGxlciA9IHN0YXRlLmNoZWNrID0genN3YXAzMihob2xkKTsKICAgICAgICAgICAgICAgIGhvbGQgPSAwOwogICAgICAgICAgICAgICAgYml0cyA9IDA7CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gRElDVDsKICAgICAgICAgICAgICBjYXNlIERJQ1Q6CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuaGF2ZWRpY3QgPT09IDApIHsKICAgICAgICAgICAgICAgICAgc3RybS5uZXh0X291dCA9IHB1dDsKICAgICAgICAgICAgICAgICAgc3RybS5hdmFpbF9vdXQgPSBsZWZ0OwogICAgICAgICAgICAgICAgICBzdHJtLm5leHRfaW4gPSBuZXh0OwogICAgICAgICAgICAgICAgICBzdHJtLmF2YWlsX2luID0gaGF2ZTsKICAgICAgICAgICAgICAgICAgc3RhdGUuaG9sZCA9IGhvbGQ7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmJpdHMgPSBiaXRzOwogICAgICAgICAgICAgICAgICByZXR1cm4gWl9ORUVEX0RJQ1Q7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gc3RhdGUuY2hlY2sgPSAxOwogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IFRZUEU7CiAgICAgICAgICAgICAgY2FzZSBUWVBFOgogICAgICAgICAgICAgICAgaWYgKGZsdXNoID09PSBaX0JMT0NLIHx8IGZsdXNoID09PSBaX1RSRUVTKSB7CiAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBjYXNlIFRZUEVETzoKICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5sYXN0KSB7CiAgICAgICAgICAgICAgICAgIGhvbGQgPj4+PSBiaXRzICYgNzsKICAgICAgICAgICAgICAgICAgYml0cyAtPSBiaXRzICYgNzsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IENIRUNLOwogICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHdoaWxlIChiaXRzIDwgMykgewogICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5sYXN0ID0gaG9sZCAmIDE7CiAgICAgICAgICAgICAgICBob2xkID4+Pj0gMTsKICAgICAgICAgICAgICAgIGJpdHMgLT0gMTsKICAgICAgICAgICAgICAgIHN3aXRjaCAoaG9sZCAmIDMpIHsKICAgICAgICAgICAgICAgICAgY2FzZSAwOgogICAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBTVE9SRUQ7CiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgIGNhc2UgMToKICAgICAgICAgICAgICAgICAgICBmaXhlZHRhYmxlcyhzdGF0ZSk7CiAgICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IExFTl87CiAgICAgICAgICAgICAgICAgICAgaWYgKGZsdXNoID09PSBaX1RSRUVTKSB7CiAgICAgICAgICAgICAgICAgICAgICBob2xkID4+Pj0gMjsKICAgICAgICAgICAgICAgICAgICAgIGJpdHMgLT0gMjsKICAgICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgIGNhc2UgMjoKICAgICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gVEFCTEU7CiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgIGNhc2UgMzoKICAgICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbnZhbGlkIGJsb2NrIHR5cGUiOwogICAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBob2xkID4+Pj0gMjsKICAgICAgICAgICAgICAgIGJpdHMgLT0gMjsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgIGNhc2UgU1RPUkVEOgogICAgICAgICAgICAgICAgaG9sZCA+Pj49IGJpdHMgJiA3OwogICAgICAgICAgICAgICAgYml0cyAtPSBiaXRzICYgNzsKICAgICAgICAgICAgICAgIHdoaWxlIChiaXRzIDwgMzIpIHsKICAgICAgICAgICAgICAgICAgaWYgKGhhdmUgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaGF2ZS0tOwogICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKChob2xkICYgNjU1MzUpICE9PSAoaG9sZCA+Pj4gMTYgXiA2NTUzNSkpIHsKICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW52YWxpZCBzdG9yZWQgYmxvY2sgbGVuZ3RocyI7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUubGVuZ3RoID0gaG9sZCAmIDY1NTM1OwogICAgICAgICAgICAgICAgaG9sZCA9IDA7CiAgICAgICAgICAgICAgICBiaXRzID0gMDsKICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBDT1BZXzsKICAgICAgICAgICAgICAgIGlmIChmbHVzaCA9PT0gWl9UUkVFUykgewogICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgY2FzZSBDT1BZXzoKICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBDT1BZOwogICAgICAgICAgICAgIGNhc2UgQ09QWToKICAgICAgICAgICAgICAgIGNvcHkgPSBzdGF0ZS5sZW5ndGg7CiAgICAgICAgICAgICAgICBpZiAoY29weSkgewogICAgICAgICAgICAgICAgICBpZiAoY29weSA+IGhhdmUpIHsKICAgICAgICAgICAgICAgICAgICBjb3B5ID0gaGF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBpZiAoY29weSA+IGxlZnQpIHsKICAgICAgICAgICAgICAgICAgICBjb3B5ID0gbGVmdDsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBpZiAoY29weSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICB1dGlscy5hcnJheVNldChvdXRwdXQsIGlucHV0LCBuZXh0LCBjb3B5LCBwdXQpOwogICAgICAgICAgICAgICAgICBoYXZlIC09IGNvcHk7CiAgICAgICAgICAgICAgICAgIG5leHQgKz0gY29weTsKICAgICAgICAgICAgICAgICAgbGVmdCAtPSBjb3B5OwogICAgICAgICAgICAgICAgICBwdXQgKz0gY29weTsKICAgICAgICAgICAgICAgICAgc3RhdGUubGVuZ3RoIC09IGNvcHk7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IFRZUEU7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICBjYXNlIFRBQkxFOgogICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCAxNCkgewogICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5ubGVuID0gKGhvbGQgJiAzMSkgKyAyNTc7CiAgICAgICAgICAgICAgICBob2xkID4+Pj0gNTsKICAgICAgICAgICAgICAgIGJpdHMgLT0gNTsKICAgICAgICAgICAgICAgIHN0YXRlLm5kaXN0ID0gKGhvbGQgJiAzMSkgKyAxOwogICAgICAgICAgICAgICAgaG9sZCA+Pj49IDU7CiAgICAgICAgICAgICAgICBiaXRzIC09IDU7CiAgICAgICAgICAgICAgICBzdGF0ZS5uY29kZSA9IChob2xkICYgMTUpICsgNDsKICAgICAgICAgICAgICAgIGhvbGQgPj4+PSA0OwogICAgICAgICAgICAgICAgYml0cyAtPSA0OwogICAgICAgICAgICAgICAgaWYgKHN0YXRlLm5sZW4gPiAyODYgfHwgc3RhdGUubmRpc3QgPiAzMCkgewogICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJ0b28gbWFueSBsZW5ndGggb3IgZGlzdGFuY2Ugc3ltYm9scyI7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUuaGF2ZSA9IDA7CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gTEVOTEVOUzsKICAgICAgICAgICAgICBjYXNlIExFTkxFTlM6CiAgICAgICAgICAgICAgICB3aGlsZSAoc3RhdGUuaGF2ZSA8IHN0YXRlLm5jb2RlKSB7CiAgICAgICAgICAgICAgICAgIHdoaWxlIChiaXRzIDwgMykgewogICAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgc3RhdGUubGVuc1tvcmRlcltzdGF0ZS5oYXZlKytdXSA9IGhvbGQgJiA3OwogICAgICAgICAgICAgICAgICBob2xkID4+Pj0gMzsKICAgICAgICAgICAgICAgICAgYml0cyAtPSAzOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgd2hpbGUgKHN0YXRlLmhhdmUgPCAxOSkgewogICAgICAgICAgICAgICAgICBzdGF0ZS5sZW5zW29yZGVyW3N0YXRlLmhhdmUrK11dID0gMDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0YXRlLmxlbmNvZGUgPSBzdGF0ZS5sZW5keW47CiAgICAgICAgICAgICAgICBzdGF0ZS5sZW5iaXRzID0gNzsKICAgICAgICAgICAgICAgIG9wdHMgPSB7IGJpdHM6IHN0YXRlLmxlbmJpdHMgfTsKICAgICAgICAgICAgICAgIHJldCA9IGluZmxhdGVfdGFibGUoQ09ERVMsIHN0YXRlLmxlbnMsIDAsIDE5LCBzdGF0ZS5sZW5jb2RlLCAwLCBzdGF0ZS53b3JrLCBvcHRzKTsKICAgICAgICAgICAgICAgIHN0YXRlLmxlbmJpdHMgPSBvcHRzLmJpdHM7CiAgICAgICAgICAgICAgICBpZiAocmV0KSB7CiAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImludmFsaWQgY29kZSBsZW5ndGhzIHNldCI7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUuaGF2ZSA9IDA7CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQ09ERUxFTlM7CiAgICAgICAgICAgICAgY2FzZSBDT0RFTEVOUzoKICAgICAgICAgICAgICAgIHdoaWxlIChzdGF0ZS5oYXZlIDwgc3RhdGUubmxlbiArIHN0YXRlLm5kaXN0KSB7CiAgICAgICAgICAgICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgICAgICAgICAgIGhlcmUgPSBzdGF0ZS5sZW5jb2RlW2hvbGQgJiAoMSA8PCBzdGF0ZS5sZW5iaXRzKSAtIDFdOwogICAgICAgICAgICAgICAgICAgIGhlcmVfYml0cyA9IGhlcmUgPj4+IDI0OwogICAgICAgICAgICAgICAgICAgIGhlcmVfb3AgPSBoZXJlID4+PiAxNiAmIDI1NTsKICAgICAgICAgICAgICAgICAgICBoZXJlX3ZhbCA9IGhlcmUgJiA2NTUzNTsKICAgICAgICAgICAgICAgICAgICBpZiAoaGVyZV9iaXRzIDw9IGJpdHMpIHsKICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChoZXJlX3ZhbCA8IDE2KSB7CiAgICAgICAgICAgICAgICAgICAgaG9sZCA+Pj49IGhlcmVfYml0czsKICAgICAgICAgICAgICAgICAgICBiaXRzIC09IGhlcmVfYml0czsKICAgICAgICAgICAgICAgICAgICBzdGF0ZS5sZW5zW3N0YXRlLmhhdmUrK10gPSBoZXJlX3ZhbDsKICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICBpZiAoaGVyZV92YWwgPT09IDE2KSB7CiAgICAgICAgICAgICAgICAgICAgICBuID0gaGVyZV9iaXRzICsgMjsKICAgICAgICAgICAgICAgICAgICAgIHdoaWxlIChiaXRzIDwgbikgewogICAgICAgICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICBob2xkID4+Pj0gaGVyZV9iaXRzOwogICAgICAgICAgICAgICAgICAgICAgYml0cyAtPSBoZXJlX2JpdHM7CiAgICAgICAgICAgICAgICAgICAgICBpZiAoc3RhdGUuaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbnZhbGlkIGJpdCBsZW5ndGggcmVwZWF0IjsKICAgICAgICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICBsZW4gPSBzdGF0ZS5sZW5zW3N0YXRlLmhhdmUgLSAxXTsKICAgICAgICAgICAgICAgICAgICAgIGNvcHkgPSAzICsgKGhvbGQgJiAzKTsKICAgICAgICAgICAgICAgICAgICAgIGhvbGQgPj4+PSAyOwogICAgICAgICAgICAgICAgICAgICAgYml0cyAtPSAyOwogICAgICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAoaGVyZV92YWwgPT09IDE3KSB7CiAgICAgICAgICAgICAgICAgICAgICBuID0gaGVyZV9iaXRzICsgMzsKICAgICAgICAgICAgICAgICAgICAgIHdoaWxlIChiaXRzIDwgbikgewogICAgICAgICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICBob2xkID4+Pj0gaGVyZV9iaXRzOwogICAgICAgICAgICAgICAgICAgICAgYml0cyAtPSBoZXJlX2JpdHM7CiAgICAgICAgICAgICAgICAgICAgICBsZW4gPSAwOwogICAgICAgICAgICAgICAgICAgICAgY29weSA9IDMgKyAoaG9sZCAmIDcpOwogICAgICAgICAgICAgICAgICAgICAgaG9sZCA+Pj49IDM7CiAgICAgICAgICAgICAgICAgICAgICBiaXRzIC09IDM7CiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgIG4gPSBoZXJlX2JpdHMgKyA3OwogICAgICAgICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCBuKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgIGhvbGQgPj4+PSBoZXJlX2JpdHM7CiAgICAgICAgICAgICAgICAgICAgICBiaXRzIC09IGhlcmVfYml0czsKICAgICAgICAgICAgICAgICAgICAgIGxlbiA9IDA7CiAgICAgICAgICAgICAgICAgICAgICBjb3B5ID0gMTEgKyAoaG9sZCAmIDEyNyk7CiAgICAgICAgICAgICAgICAgICAgICBob2xkID4+Pj0gNzsKICAgICAgICAgICAgICAgICAgICAgIGJpdHMgLT0gNzsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgaWYgKHN0YXRlLmhhdmUgKyBjb3B5ID4gc3RhdGUubmxlbiArIHN0YXRlLm5kaXN0KSB7CiAgICAgICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbnZhbGlkIGJpdCBsZW5ndGggcmVwZWF0IjsKICAgICAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgd2hpbGUgKGNvcHktLSkgewogICAgICAgICAgICAgICAgICAgICAgc3RhdGUubGVuc1tzdGF0ZS5oYXZlKytdID0gbGVuOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKHN0YXRlLm1vZGUgPT09IEJBRCkgewogICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5sZW5zWzI1Nl0gPT09IDApIHsKICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW52YWxpZCBjb2RlIC0tIG1pc3NpbmcgZW5kLW9mLWJsb2NrIjsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5sZW5iaXRzID0gOTsKICAgICAgICAgICAgICAgIG9wdHMgPSB7IGJpdHM6IHN0YXRlLmxlbmJpdHMgfTsKICAgICAgICAgICAgICAgIHJldCA9IGluZmxhdGVfdGFibGUoTEVOUywgc3RhdGUubGVucywgMCwgc3RhdGUubmxlbiwgc3RhdGUubGVuY29kZSwgMCwgc3RhdGUud29yaywgb3B0cyk7CiAgICAgICAgICAgICAgICBzdGF0ZS5sZW5iaXRzID0gb3B0cy5iaXRzOwogICAgICAgICAgICAgICAgaWYgKHJldCkgewogICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbnZhbGlkIGxpdGVyYWwvbGVuZ3RocyBzZXQiOwogICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEOwogICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0YXRlLmRpc3RiaXRzID0gNjsKICAgICAgICAgICAgICAgIHN0YXRlLmRpc3Rjb2RlID0gc3RhdGUuZGlzdGR5bjsKICAgICAgICAgICAgICAgIG9wdHMgPSB7IGJpdHM6IHN0YXRlLmRpc3RiaXRzIH07CiAgICAgICAgICAgICAgICByZXQgPSBpbmZsYXRlX3RhYmxlKERJU1RTLCBzdGF0ZS5sZW5zLCBzdGF0ZS5ubGVuLCBzdGF0ZS5uZGlzdCwgc3RhdGUuZGlzdGNvZGUsIDAsIHN0YXRlLndvcmssIG9wdHMpOwogICAgICAgICAgICAgICAgc3RhdGUuZGlzdGJpdHMgPSBvcHRzLmJpdHM7CiAgICAgICAgICAgICAgICBpZiAocmV0KSB7CiAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImludmFsaWQgZGlzdGFuY2VzIHNldCI7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IExFTl87CiAgICAgICAgICAgICAgICBpZiAoZmx1c2ggPT09IFpfVFJFRVMpIHsKICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGNhc2UgTEVOXzoKICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBMRU47CiAgICAgICAgICAgICAgY2FzZSBMRU46CiAgICAgICAgICAgICAgICBpZiAoaGF2ZSA+PSA2ICYmIGxlZnQgPj0gMjU4KSB7CiAgICAgICAgICAgICAgICAgIHN0cm0ubmV4dF9vdXQgPSBwdXQ7CiAgICAgICAgICAgICAgICAgIHN0cm0uYXZhaWxfb3V0ID0gbGVmdDsKICAgICAgICAgICAgICAgICAgc3RybS5uZXh0X2luID0gbmV4dDsKICAgICAgICAgICAgICAgICAgc3RybS5hdmFpbF9pbiA9IGhhdmU7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmhvbGQgPSBob2xkOwogICAgICAgICAgICAgICAgICBzdGF0ZS5iaXRzID0gYml0czsKICAgICAgICAgICAgICAgICAgaW5mbGF0ZV9mYXN0KHN0cm0sIF9vdXQpOwogICAgICAgICAgICAgICAgICBwdXQgPSBzdHJtLm5leHRfb3V0OwogICAgICAgICAgICAgICAgICBvdXRwdXQgPSBzdHJtLm91dHB1dDsKICAgICAgICAgICAgICAgICAgbGVmdCA9IHN0cm0uYXZhaWxfb3V0OwogICAgICAgICAgICAgICAgICBuZXh0ID0gc3RybS5uZXh0X2luOwogICAgICAgICAgICAgICAgICBpbnB1dCA9IHN0cm0uaW5wdXQ7CiAgICAgICAgICAgICAgICAgIGhhdmUgPSBzdHJtLmF2YWlsX2luOwogICAgICAgICAgICAgICAgICBob2xkID0gc3RhdGUuaG9sZDsKICAgICAgICAgICAgICAgICAgYml0cyA9IHN0YXRlLmJpdHM7CiAgICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5tb2RlID09PSBUWVBFKSB7CiAgICAgICAgICAgICAgICAgICAgc3RhdGUuYmFjayA9IC0xOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUuYmFjayA9IDA7CiAgICAgICAgICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgICAgICAgICAgaGVyZSA9IHN0YXRlLmxlbmNvZGVbaG9sZCAmICgxIDw8IHN0YXRlLmxlbmJpdHMpIC0gMV07CiAgICAgICAgICAgICAgICAgIGhlcmVfYml0cyA9IGhlcmUgPj4+IDI0OwogICAgICAgICAgICAgICAgICBoZXJlX29wID0gaGVyZSA+Pj4gMTYgJiAyNTU7CiAgICAgICAgICAgICAgICAgIGhlcmVfdmFsID0gaGVyZSAmIDY1NTM1OwogICAgICAgICAgICAgICAgICBpZiAoaGVyZV9iaXRzIDw9IGJpdHMpIHsKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoaGVyZV9vcCAmJiAoaGVyZV9vcCAmIDI0MCkgPT09IDApIHsKICAgICAgICAgICAgICAgICAgbGFzdF9iaXRzID0gaGVyZV9iaXRzOwogICAgICAgICAgICAgICAgICBsYXN0X29wID0gaGVyZV9vcDsKICAgICAgICAgICAgICAgICAgbGFzdF92YWwgPSBoZXJlX3ZhbDsKICAgICAgICAgICAgICAgICAgZm9yICg7IDsgKSB7CiAgICAgICAgICAgICAgICAgICAgaGVyZSA9IHN0YXRlLmxlbmNvZGVbbGFzdF92YWwgKyAoKGhvbGQgJiAoMSA8PCBsYXN0X2JpdHMgKyBsYXN0X29wKSAtIDEpID4+IGxhc3RfYml0cyldOwogICAgICAgICAgICAgICAgICAgIGhlcmVfYml0cyA9IGhlcmUgPj4+IDI0OwogICAgICAgICAgICAgICAgICAgIGhlcmVfb3AgPSBoZXJlID4+PiAxNiAmIDI1NTsKICAgICAgICAgICAgICAgICAgICBoZXJlX3ZhbCA9IGhlcmUgJiA2NTUzNTsKICAgICAgICAgICAgICAgICAgICBpZiAobGFzdF9iaXRzICsgaGVyZV9iaXRzIDw9IGJpdHMpIHsKICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGhvbGQgPj4+PSBsYXN0X2JpdHM7CiAgICAgICAgICAgICAgICAgIGJpdHMgLT0gbGFzdF9iaXRzOwogICAgICAgICAgICAgICAgICBzdGF0ZS5iYWNrICs9IGxhc3RfYml0czsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGhvbGQgPj4+PSBoZXJlX2JpdHM7CiAgICAgICAgICAgICAgICBiaXRzIC09IGhlcmVfYml0czsKICAgICAgICAgICAgICAgIHN0YXRlLmJhY2sgKz0gaGVyZV9iaXRzOwogICAgICAgICAgICAgICAgc3RhdGUubGVuZ3RoID0gaGVyZV92YWw7CiAgICAgICAgICAgICAgICBpZiAoaGVyZV9vcCA9PT0gMCkgewogICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gTElUOwogICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmIChoZXJlX29wICYgMzIpIHsKICAgICAgICAgICAgICAgICAgc3RhdGUuYmFjayA9IC0xOwogICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gVFlQRTsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoaGVyZV9vcCAmIDY0KSB7CiAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImludmFsaWQgbGl0ZXJhbC9sZW5ndGggY29kZSI7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUuZXh0cmEgPSBoZXJlX29wICYgMTU7CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gTEVORVhUOwogICAgICAgICAgICAgIGNhc2UgTEVORVhUOgogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmV4dHJhKSB7CiAgICAgICAgICAgICAgICAgIG4gPSBzdGF0ZS5leHRyYTsKICAgICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCBuKSB7CiAgICAgICAgICAgICAgICAgICAgaWYgKGhhdmUgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgaGF2ZS0tOwogICAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBzdGF0ZS5sZW5ndGggKz0gaG9sZCAmICgxIDw8IHN0YXRlLmV4dHJhKSAtIDE7CiAgICAgICAgICAgICAgICAgIGhvbGQgPj4+PSBzdGF0ZS5leHRyYTsKICAgICAgICAgICAgICAgICAgYml0cyAtPSBzdGF0ZS5leHRyYTsKICAgICAgICAgICAgICAgICAgc3RhdGUuYmFjayArPSBzdGF0ZS5leHRyYTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0YXRlLndhcyA9IHN0YXRlLmxlbmd0aDsKICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBESVNUOwogICAgICAgICAgICAgIGNhc2UgRElTVDoKICAgICAgICAgICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgICAgICAgICBoZXJlID0gc3RhdGUuZGlzdGNvZGVbaG9sZCAmICgxIDw8IHN0YXRlLmRpc3RiaXRzKSAtIDFdOwogICAgICAgICAgICAgICAgICBoZXJlX2JpdHMgPSBoZXJlID4+PiAyNDsKICAgICAgICAgICAgICAgICAgaGVyZV9vcCA9IGhlcmUgPj4+IDE2ICYgMjU1OwogICAgICAgICAgICAgICAgICBoZXJlX3ZhbCA9IGhlcmUgJiA2NTUzNTsKICAgICAgICAgICAgICAgICAgaWYgKGhlcmVfYml0cyA8PSBiaXRzKSB7CiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaWYgKGhhdmUgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaGF2ZS0tOwogICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKChoZXJlX29wICYgMjQwKSA9PT0gMCkgewogICAgICAgICAgICAgICAgICBsYXN0X2JpdHMgPSBoZXJlX2JpdHM7CiAgICAgICAgICAgICAgICAgIGxhc3Rfb3AgPSBoZXJlX29wOwogICAgICAgICAgICAgICAgICBsYXN0X3ZhbCA9IGhlcmVfdmFsOwogICAgICAgICAgICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgICAgICAgICAgICBoZXJlID0gc3RhdGUuZGlzdGNvZGVbbGFzdF92YWwgKyAoKGhvbGQgJiAoMSA8PCBsYXN0X2JpdHMgKyBsYXN0X29wKSAtIDEpID4+IGxhc3RfYml0cyldOwogICAgICAgICAgICAgICAgICAgIGhlcmVfYml0cyA9IGhlcmUgPj4+IDI0OwogICAgICAgICAgICAgICAgICAgIGhlcmVfb3AgPSBoZXJlID4+PiAxNiAmIDI1NTsKICAgICAgICAgICAgICAgICAgICBoZXJlX3ZhbCA9IGhlcmUgJiA2NTUzNTsKICAgICAgICAgICAgICAgICAgICBpZiAobGFzdF9iaXRzICsgaGVyZV9iaXRzIDw9IGJpdHMpIHsKICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGhvbGQgPj4+PSBsYXN0X2JpdHM7CiAgICAgICAgICAgICAgICAgIGJpdHMgLT0gbGFzdF9iaXRzOwogICAgICAgICAgICAgICAgICBzdGF0ZS5iYWNrICs9IGxhc3RfYml0czsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGhvbGQgPj4+PSBoZXJlX2JpdHM7CiAgICAgICAgICAgICAgICBiaXRzIC09IGhlcmVfYml0czsKICAgICAgICAgICAgICAgIHN0YXRlLmJhY2sgKz0gaGVyZV9iaXRzOwogICAgICAgICAgICAgICAgaWYgKGhlcmVfb3AgJiA2NCkgewogICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbnZhbGlkIGRpc3RhbmNlIGNvZGUiOwogICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEOwogICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0YXRlLm9mZnNldCA9IGhlcmVfdmFsOwogICAgICAgICAgICAgICAgc3RhdGUuZXh0cmEgPSBoZXJlX29wICYgMTU7CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gRElTVEVYVDsKICAgICAgICAgICAgICBjYXNlIERJU1RFWFQ6CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuZXh0cmEpIHsKICAgICAgICAgICAgICAgICAgbiA9IHN0YXRlLmV4dHJhOwogICAgICAgICAgICAgICAgICB3aGlsZSAoYml0cyA8IG4pIHsKICAgICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIHN0YXRlLm9mZnNldCArPSBob2xkICYgKDEgPDwgc3RhdGUuZXh0cmEpIC0gMTsKICAgICAgICAgICAgICAgICAgaG9sZCA+Pj49IHN0YXRlLmV4dHJhOwogICAgICAgICAgICAgICAgICBiaXRzIC09IHN0YXRlLmV4dHJhOwogICAgICAgICAgICAgICAgICBzdGF0ZS5iYWNrICs9IHN0YXRlLmV4dHJhOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKHN0YXRlLm9mZnNldCA+IHN0YXRlLmRtYXgpIHsKICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW52YWxpZCBkaXN0YW5jZSB0b28gZmFyIGJhY2siOwogICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEOwogICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBNQVRDSDsKICAgICAgICAgICAgICBjYXNlIE1BVENIOgogICAgICAgICAgICAgICAgaWYgKGxlZnQgPT09IDApIHsKICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgY29weSA9IF9vdXQgLSBsZWZ0OwogICAgICAgICAgICAgICAgaWYgKHN0YXRlLm9mZnNldCA+IGNvcHkpIHsKICAgICAgICAgICAgICAgICAgY29weSA9IHN0YXRlLm9mZnNldCAtIGNvcHk7CiAgICAgICAgICAgICAgICAgIGlmIChjb3B5ID4gc3RhdGUud2hhdmUpIHsKICAgICAgICAgICAgICAgICAgICBpZiAoc3RhdGUuc2FuZSkgewogICAgICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW52YWxpZCBkaXN0YW5jZSB0b28gZmFyIGJhY2siOwogICAgICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBpZiAoY29weSA+IHN0YXRlLnduZXh0KSB7CiAgICAgICAgICAgICAgICAgICAgY29weSAtPSBzdGF0ZS53bmV4dDsKICAgICAgICAgICAgICAgICAgICBmcm9tID0gc3RhdGUud3NpemUgLSBjb3B5OwogICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgIGZyb20gPSBzdGF0ZS53bmV4dCAtIGNvcHk7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaWYgKGNvcHkgPiBzdGF0ZS5sZW5ndGgpIHsKICAgICAgICAgICAgICAgICAgICBjb3B5ID0gc3RhdGUubGVuZ3RoOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGZyb21fc291cmNlID0gc3RhdGUud2luZG93OwogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgZnJvbV9zb3VyY2UgPSBvdXRwdXQ7CiAgICAgICAgICAgICAgICAgIGZyb20gPSBwdXQgLSBzdGF0ZS5vZmZzZXQ7CiAgICAgICAgICAgICAgICAgIGNvcHkgPSBzdGF0ZS5sZW5ndGg7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoY29weSA+IGxlZnQpIHsKICAgICAgICAgICAgICAgICAgY29weSA9IGxlZnQ7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBsZWZ0IC09IGNvcHk7CiAgICAgICAgICAgICAgICBzdGF0ZS5sZW5ndGggLT0gY29weTsKICAgICAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICAgICAgb3V0cHV0W3B1dCsrXSA9IGZyb21fc291cmNlW2Zyb20rK107CiAgICAgICAgICAgICAgICB9IHdoaWxlICgtLWNvcHkpOwogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmxlbmd0aCA9PT0gMCkgewogICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gTEVOOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgY2FzZSBMSVQ6CiAgICAgICAgICAgICAgICBpZiAobGVmdCA9PT0gMCkgewogICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBvdXRwdXRbcHV0KytdID0gc3RhdGUubGVuZ3RoOwogICAgICAgICAgICAgICAgbGVmdC0tOwogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IExFTjsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgIGNhc2UgQ0hFQ0s6CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUud3JhcCkgewogICAgICAgICAgICAgICAgICB3aGlsZSAoYml0cyA8IDMyKSB7CiAgICAgICAgICAgICAgICAgICAgaWYgKGhhdmUgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgaGF2ZS0tOwogICAgICAgICAgICAgICAgICAgIGhvbGQgfD0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBfb3V0IC09IGxlZnQ7CiAgICAgICAgICAgICAgICAgIHN0cm0udG90YWxfb3V0ICs9IF9vdXQ7CiAgICAgICAgICAgICAgICAgIHN0YXRlLnRvdGFsICs9IF9vdXQ7CiAgICAgICAgICAgICAgICAgIGlmIChfb3V0KSB7CiAgICAgICAgICAgICAgICAgICAgc3RybS5hZGxlciA9IHN0YXRlLmNoZWNrID0gc3RhdGUuZmxhZ3MgPyBjcmMzMihzdGF0ZS5jaGVjaywgb3V0cHV0LCBfb3V0LCBwdXQgLSBfb3V0KSA6IGFkbGVyMzIoc3RhdGUuY2hlY2ssIG91dHB1dCwgX291dCwgcHV0IC0gX291dCk7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgX291dCA9IGxlZnQ7CiAgICAgICAgICAgICAgICAgIGlmICgoc3RhdGUuZmxhZ3MgPyBob2xkIDogenN3YXAzMihob2xkKSkgIT09IHN0YXRlLmNoZWNrKSB7CiAgICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW5jb3JyZWN0IGRhdGEgY2hlY2siOwogICAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaG9sZCA9IDA7CiAgICAgICAgICAgICAgICAgIGJpdHMgPSAwOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IExFTkdUSDsKICAgICAgICAgICAgICBjYXNlIExFTkdUSDoKICAgICAgICAgICAgICAgIGlmIChzdGF0ZS53cmFwICYmIHN0YXRlLmZsYWdzKSB7CiAgICAgICAgICAgICAgICAgIHdoaWxlIChiaXRzIDwgMzIpIHsKICAgICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChob2xkICE9PSAoc3RhdGUudG90YWwgJiA0Mjk0OTY3Mjk1KSkgewogICAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImluY29ycmVjdCBsZW5ndGggY2hlY2siOwogICAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaG9sZCA9IDA7CiAgICAgICAgICAgICAgICAgIGJpdHMgPSAwOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IERPTkU7CiAgICAgICAgICAgICAgY2FzZSBET05FOgogICAgICAgICAgICAgICAgcmV0ID0gWl9TVFJFQU1fRU5EOwogICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgIGNhc2UgQkFEOgogICAgICAgICAgICAgICAgcmV0ID0gWl9EQVRBX0VSUk9SOwogICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgIGNhc2UgTUVNOgogICAgICAgICAgICAgICAgcmV0dXJuIFpfTUVNX0VSUk9SOwogICAgICAgICAgICAgIGNhc2UgU1lOQzoKICAgICAgICAgICAgICBkZWZhdWx0OgogICAgICAgICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VSUk9SOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgc3RybS5uZXh0X291dCA9IHB1dDsKICAgICAgICBzdHJtLmF2YWlsX291dCA9IGxlZnQ7CiAgICAgICAgc3RybS5uZXh0X2luID0gbmV4dDsKICAgICAgICBzdHJtLmF2YWlsX2luID0gaGF2ZTsKICAgICAgICBzdGF0ZS5ob2xkID0gaG9sZDsKICAgICAgICBzdGF0ZS5iaXRzID0gYml0czsKICAgICAgICBpZiAoc3RhdGUud3NpemUgfHwgX291dCAhPT0gc3RybS5hdmFpbF9vdXQgJiYgc3RhdGUubW9kZSA8IEJBRCAmJiAoc3RhdGUubW9k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B9CiAgICAgICAgcmV0dXJuIHJldDsKICAgICAgfQogICAgICBmdW5jdGlvbiBpbmZsYXRlRW5kKHN0cm0pIHsKICAgICAgICBpZiAoIXN0cm0gfHwgIXN0cm0uc3RhdGUpIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgdmFyIHN0YXRlID0gc3RybS5zdGF0ZTsKICAgICAgICBpZiAoc3RhdGUud2luZG93KSB7CiAgICAgICAgICBzdGF0ZS53aW5kb3cgPSBudWxsOwogICAgICAgIH0KICAgICAgICBzdHJtLnN0YXRlID0gbnVsbDsKICAgICAgICByZXR1cm4gWl9PSzsKICAgICAgfQogICAgICBmdW5jdGlvbiBpbmZsYXRlR2V0SGVhZGVyKHN0cm0sIGhlYWQpIHsKICAgICAgICB2YXIgc3RhdGU7CiAgICAgICAgaWYgKCFzdHJtIHx8ICFzdHJtLnN0YXRlKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIHN0YXRlID0gc3RybS5zdGF0ZTsKICAgICAgICBpZiAoKHN0YXRlLndyYXAgJiAyKSA9PT0gMCkgewogICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VSUk9SOwogICAgICAgIH0KICAgICAgICBzdGF0ZS5oZWFkID0gaGVhZDsKICAgICAgICBoZWFkLmRvbmUgPSBmYWxzZTsKICAgICAgICByZXR1cm4gWl9PSzsKICAgICAgfQogICAgICBmdW5jdGlvbiBpbmZsYXRlU2V0RGljdGlvbmFyeShzdHJtLCBkaWN0aW9uYXJ5KSB7CiAgICAgICAgdmFyIGRpY3RMZW5ndGggPSBkaWN0aW9uYXJ5Lmxlbmd0aDsKICAgICAgICB2YXIgc3RhdGU7CiAgICAgICAgdmFyIGRpY3RpZDsKICAgICAgICB2YXIgcmV0OwogICAgICAgIGlmICghc3RybSB8fCAhc3RybS5zdGF0ZSkgewogICAgICAgICAgcmV0dXJuIFpfU1RSRU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VSUk9SOiAtNSwKICAgICAgICBaX05PX0NPTVBSRVNTSU9OOiAwLAogICAgICAgIFpfQkVTVF9TUEVFRDogMSwKICAgICAgICBaX0JFU1RfQ09NUFJFU1NJT046IDksCiAgICAgICAgWl9ERUZBVUxUX0NPTVBSRVNTSU9OOiAtMSwKICAgICAgICBaX0ZJTFRFUkVEOiAxLAogICAgICAgIFpfSFVGRk1BTl9PTkxZOiAyLAogICAgICAgIFpfUkxFOiAzLAogICAgICAgIFpfRklYRUQ6IDQsCiAgICAgICAgWl9ERUZBVUxUX1NUUkFURUdZOiAwLAogICAgICAgIFpfQklOQVJZOiAwLAogICAgICAgIFpfVEVYVDogMSwKICAgICAgICBaX1VOS05PV046IDIsCiAgICAgICAgWl9ERUZMQVRFRDogOAogICAgICB9OwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvZ3poZWFkZXIuanMKICB2YXIgcmVxdWlyZV9nemhlYWRlciA9IF9fY29tbW9uSlMoewogICAgIm5vZGVfbW9kdWxlcy8ucG5wbS9wYWtvQDEuMC4xMS9ub2RlX21vZHVsZXMvcGFrby9saWIvemxpYi9nemhlYWRlci5qcyIoZXhwb3J0czIsIG1vZHVsZTIpIHsKICAgICAgaW5pdF9idWZmZXJfc2hpbSgpOwogICAgICAidXNlIHN0cmljdCI7CiAgICAgIGZ1bmN0aW9uIEdaaGVhZGVyKCkgewogICAgICAgIHRoaXMudGV4dCA9IDA7CiAgICAgICAgdGhpcy50aW1lID0gMDsKICAgICAgICB0aGlzLnhmbGFncyA9IDA7CiAgICAgICAgdGhpcy5vcyA9IDA7CiAgICAgICAgdGhpcy5leHRyYSA9IG51bGw7CiAgICAgICAgdGhpcy5leHRyYV9sZW4gPSAwOwogICAgICAgIHRoaXMubmFtZSA9ICIiOwogICAgICAgIHRoaXMuY29tbWVudCA9ICIiOwogICAgICAgIHRoaXMuaGNyYyA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qml0czogMCwKICAgICAgICAgIHRvOiAiIgogICAgICAgIH0sIG9wdGlvbnMgfHwge30pOwogICAgICAgIHZhciBvcHQgPSB0aGlzLm9wdGlvbnM7CiAgICAgICAgaWYgKG9wdC5yYXcgJiYgb3B0LndpbmRvd0JpdHMgPj0gMCAmJiBvcHQud2luZG93Qml0cyA8IDE2KSB7CiAgICAgICAgICBvcHQud2luZG93Qml0cyA9IC1vcHQud2luZG93Qml0czsKICAgICAgICAgIGlmIChvcHQud2luZG93Qml0cyA9PT0gMCkgewogICAgICAgICAgICBvcHQud2luZG93Qml0cyA9IC0xNTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKG9wdC53aW5kb3dCaXRzID49IDAgJiYgb3B0LndpbmRvd0JpdHMgPCAxNiAmJiAhKG9wdGlvbnMgJiYgb3B0aW9ucy53aW5kb3dCaXRzKSkgewogICAgICAgICAgb3B0LndpbmRvd0JpdHMgKz0gMzI7CiAgICAgICAgfQogICAgICAgIGlmIChvcHQud2luZG93Qml0cyA+IDE1ICYmIG9wdC53aW5kb3dCaXRzIDwgNDgpIHsKICAgICAgICAgIGlmICgob3B0LndpbmRvd0JpdHMgJiAxNSkgPT09IDApIHsKICAgICAgICAgICAgb3B0LndpbmRvd0JpdHMgfD0gMTU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHRoaXMuZXJyID0gMDsKICAgICAgICB0aGlzLm1zZyA9ICIiOwogICAgICAgIHRoaXMuZW5kZWQgPSBmYWxzZTsKICAgICAgICB0aGlzLmNodW5rcyA9IFtdOwogICAgICAgIHRoaXMuc3RybSA9IG5ldyBaU3RyZWFtKCk7CiAgICAgICAgdGhpcy5zdHJtLmF2YWlsX291dCA9IDA7CiAgICAgICAgdmFyIHN0YXR1cyA9IHpsaWJfaW5mbGF0ZS5pbmZsYXRlSW5pdDIodGhpcy5zdHJtLCBvcHQud2luZG93Qml0cyk7CiAgICAgICAgaWYgKHN0YXR1cyAhPT0gYy5aX09LKSB7CiAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IobXNnW3N0YXR1c10pOwogICAgICAgIH0KICAgICAgICB0aGlzLmhlYWRlciA9IG5ldyBHWmhlYWRlcigpOwogICAgICAgIHpsaWJfaW5mbGF0ZS5pbmZsYXRlR2V0SGVhZGVyKHRoaXMuc3RybSwgdGhpcy5oZWFkZXIpOwogICAgICAgIGlmIChvcHQuZGljdGlvbmFyeSkgewogICAgICAgICAgaWYgKHR5cGVvZiBvcHQuZGljdGlvbmFyeSA9PT0gInN0cmluZyIpIHsKICAgICAgICAgICAgb3B0LmRpY3Rpb25hcnkgPSBzdHJpbmdzLnN0cmluZzJidWYob3B0LmRpY3Rpb25hcnkpOwogICAgICAgICAgfSBlbHNlIGlmICh0b1N0cmluZy5jYWxsKG9wdC5kaWN0aW9uYXJ5KSA9PT0gIltvYmplY3QgQXJyYXlCdWZmZXJdIikgewogICAgICAgICAgICBvcHQuZGljdGlvbmFyeSA9IG5ldyBVaW50OEFycmF5KG9wdC5kaWN0aW9uYXJ5KTsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChvcHQucmF3KSB7CiAgICAgICAgICAgIHN0YXR1cyA9IHpsaWJfaW5mbGF0ZS5pbmZsYXRlU2V0RGljdGlvbmFyeSh0aGlzLnN0cm0sIG9wdC5kaWN0aW9uYXJ5KTsKICAgICAgICAgICAgaWYgKHN0YXR1cyAhPT0gYy5aX09LKSB7CiAgICAgICAgICAgICAgdGhyb3cgbmV3IEVycm9yKG1zZ1tzdGF0dXNdKTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgICBJbmZsYXRlMi5wcm90b3R5cGUucHVzaCA9IGZ1bmN0aW9uKGRhdGEsIG1vZGUpIHsKICAgICAgICB2YXIgc3RybSA9IHRoaXMuc3RybTsKICAgICAgICB2YXIgY2h1bmtTaXplID0gdGhpcy5vcHRpb25zLmNodW5rU2l6ZTsKICAgICAgICB2YXIgZGljdGlvbmFyeSA9IHRoaXMub3B0aW9ucy5kaWN0aW9uYXJ5OwogICAgICAgIHZhciBzdGF0dXMsIF9tb2RlOwogICAgICAgIHZhciBuZXh0X291dF91dGY4LCB0YWlsLCB1dGY4c3RyOwogICAgICAgIHZhciBhbGxvd0J1ZkVycm9yID0gZmFsc2U7CiAgICAgICAgaWYgKHRoaXMuZW5kZWQpIHsKICAgICAgICAgIHJldHVybiBmYWxzZTsKICAgICAgICB9CiAgICAgICAgX21vZGUgPSBtb2RlID09PSB+fm1vZGUgPyBtb2RlIDogbW9kZSA9PT0gdHJ1ZSA/IGMuWl9GSU5JU0ggOiBjLlpfTk9fRkxVU0g7CiAgICAgICAgaWYgKHR5cGVvZiBkYXRhID09PSAic3RyaW5nIikgewogICAgICAgICAgc3RybS5pbnB1dCA9IHN0cmluZ3MuYmluc3RyaW5nMmJ1ZihkYXRhKTsKICAgICAgICB9IGVsc2UgaWYgKHRvU3RyaW5nLmNhbGwoZGF0YSkgPT09ICJbb2JqZWN0IEFycmF5QnVmZmVyXSIpIHsKICAgICAgICAgIHN0cm0uaW5wdXQgPSBuZXcgVWludDhBcnJheShkYXRhKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgc3RybS5pbnB1dCA9IGRhdGE7CiAgICAgICAgfQogICAgICAgIHN0cm0ubmV4dF9pbiA9IDA7CiAgICAgICAgc3RybS5hdmFpbF9pbiA9IHN0cm0uaW5wdXQubGVuZ3RoOwogICAgICAgIGRvIHsKICAgICAgICAgIGlmIChzdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICBzdHJtLm91dHB1dCA9IG5ldyB1dGlscy5CdWY4KGNodW5rU2l6ZSk7CiAgICAgICAgICAgIHN0cm0ubmV4dF9vdXQgPSAwOwogICAgICAgICAgICBzdHJtLmF2YWlsX291dCA9IGNodW5rU2l6ZTsKICAgICAgICAgIH0KICAgICAgICAgIHN0YXR1cyA9IHpsaWJfaW5mbGF0ZS5pbmZsYXRlKHN0cm0sIGMuWl9OT19GTFVTSCk7CiAgICAgICAgICBpZiAoc3RhdHVzID09PSBjLlpfTkVFRF9ESUNUICYmIGRpY3Rpb25hcnkpIHsKICAgICAgICAgICAgc3RhdHVzID0gemxpYl9pbmZsYXRlLmluZmxhdGVTZXREaWN0aW9uYXJ5KHRoaXMuc3RybSwgZGljdGlvbmFyeSk7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoc3RhdHVzID09PSBjLlpfQlVGX0VSUk9SICYmIGFsbG93QnVmRXJyb3IgPT09IHRydWUpIHsKICAgICAgICAgICAgc3RhdHVzID0gYy5aX09LOwogICAgICAgICAgICBhbGxvd0J1ZkVycm9yID0gZmFsc2U7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoc3RhdHVzICE9PSBjLlpfU1RSRUFNX0VORCAmJiBzdGF0dXMgIT09IGMuWl9PSykgewogICAgICAgICAgICB0aGlzLm9uRW5kKHN0YXR1cyk7CiAgICAgICAgICAgIHRoaXMuZW5kZWQgPSB0cnVlOwogICAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoc3RybS5uZXh0X291dCkgewogICAgICAgICAgICBpZiAoc3RybS5hdmFpbF9vdXQgPT09IDAgfHwgc3RhdHVzID09PSBjLlpfU1RSRUFNX0VORCB8fCBzdHJtLmF2YWlsX2luID09PSAwICYmIChfbW9kZSA9PT0gYy5aX0ZJTklTSCB8fCBfbW9kZSA9PT0gYy5aX1NZTkNfRkxVU0gpKSB7CiAgICAgICAgICAgICAgaWYgKHRoaXMub3B0aW9ucy50byA9PT0gInN0cmluZyIpIHsKICAgICAgICAgICAgICAgIG5leHRfb3V0X3V0ZjggPSBzdHJpbmdzLnV0Zjhib3JkZXIoc3RybS5vdXRwdXQsIHN0cm0ubmV4dF9vdXQpOwogICAgICAgICAgICAgICAgdGFpbCA9IHN0cm0ubmV4dF9vdXQgLSBuZXh0X291dF91dGY4OwogICAgICAgICAgICAgICAgdXRmOHN0ciA9IHN0cmluZ3MuYnVmMnN0cmluZyhzdHJtLm91dHB1dCwgbmV4dF9vdXRfdXRmOCk7CiAgICAgICAgICAgICAgICBzdHJtLm5leHRfb3V0ID0gdGFpbDsKICAgICAgICAgICAgICAgIHN0cm0uYXZhaWxfb3V0ID0gY2h1bmtTaXplIC0gdGFpbDsKICAgICAgICAgICAgICAgIGlmICh0YWlsKSB7CiAgICAgICAgICAgICAgICAgIHV0aWxzLmFycmF5U2V0KHN0cm0ub3V0cHV0LCBzdHJtLm91dHB1dCwgbmV4dF9vdXRfdXRmOCwgdGFpbCwgMCk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB0aGlzLm9uRGF0YSh1dGY4c3RyKTsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgdGhpcy5vbkRhdGEodXRpbHMuc2hyaW5rQnVmKHN0cm0ub3V0cHV0LCBzdHJtLm5leHRfb3V0KSk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoc3RybS5hdmFpbF9pbiA9PT0gMCAmJiBzdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICBhbGxvd0J1ZkVycm9yID0gdHJ1ZTsKICAgICAgICAgIH0KICAgICAgICB9IHdoaWxlICgoc3RybS5hdmFpbF9pbiA+IDAgfHwgc3RybS5hdmFpbF9vdXQgPT09IDApICYmIHN0YXR1cyAhPT0gYy5aX1NUUkVBTV9FTkQpOwogICAgICAgIGlmIChzdGF0dXMgPT09IGMuWl9TVFJFQU1fRU5EKSB7CiAgICAgICAgICBfbW9kZSA9IGMuWl9GSU5JU0g7CiAgICAgICAgfQogICAgICAgIGlmIChfbW9kZSA9PT0gYy5aX0ZJTklTSCkgewogICAgICAgICAgc3RhdHVzID0gemxpYl9pbmZsYXRlLmluZmxhdGVFbmQodGhpcy5zdHJtKTsKICAgICAgICAgIHRoaXMub25FbmQoc3RhdHVzKTsKICAgICAgICAgIHRoaXMuZW5kZWQgPSB0cnVlOwogICAgICAgICAgcmV0dXJuIHN0YXR1cyA9PT0gYy5aX09LOwogICAgICAgIH0KICAgICAgICBpZiAoX21vZGUgPT09IGMuWl9TWU5DX0ZMVVNIKSB7CiAgICAgICAgICB0aGlzLm9uRW5kKGMuWl9PSyk7CiAgICAgICAgICBzdHJtLmF2YWlsX291dCA9IDA7CiAgICAgICAgICByZXR1cm4gdHJ1ZTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHRydWU7CiAgICAgIH07CiAgICAgIEluZmxhdGUyLnByb3RvdHlwZS5vbkRhdGEgPSBmdW5jdGlvbihjaHVuaykgewogICAgICAgIHRoaXMuY2h1bmtzLnB1c2goY2h1bmspOwogICAgICB9OwogICAgICBJbmZsYXRlMi5wcm90b3R5cGUub25FbmQgPSBmdW5jdGlvbihzdGF0dXMpIHsKICAgICAgICBpZiAoc3RhdHVzID09PSBjLlpfT0spIHsKICAgICAgICAgIGlmICh0aGlzLm9wdGlvbnMudG8gPT09ICJzdHJpbmciKSB7CiAgICAgICAgICAgIHRoaXMucmVzdWx0ID0gdGhpcy5jaHVua3Muam9pbigiIik7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICB0aGlzLnJlc3VsdCA9IHV0aWxzLmZsYXR0ZW5DaHVua3ModGhpcy5jaHVua3MpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICB0aGlzLmNodW5rcyA9IFtdOwogICAgICAgIHRoaXMuZXJyID0gc3RhdHVzOwogICAgICAgIHRoaXMubXNnID0gdGhpcy5zdHJtLm1zZzsKICAgICAgfTsKICAgICAgZnVuY3Rpb24gaW5mbGF0ZShpbnB1dCwgb3B0aW9ucykgewogICAgICAgIHZhciBpbmZsYXRvciA9IG5ldyBJbmZsYXRlMihvcHRpb25zKTsKICAgICAgICBpbmZsYXRvci5wdXNoKGlucHV0LCB0cnVlKTsKICAgICAgICBpZiAoaW5mbGF0b3IuZXJyKSB7CiAgICAgICAgICB0aHJvdyBpbmZsYXRvci5t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ZsYXRlLCBjb25zdGFudHMpOwogICAgICBtb2R1bGUyLmV4cG9ydHMgPSBwYWtvOwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vbG9uZ0A0LjAuMC9ub2RlX21vZHVsZXMvbG9uZy9zcmMvbG9uZy5qcwogIHZhciByZXF1aXJlX2xvbmcgPSBfX2NvbW1vbkpTKHsKICAgICJub2RlX21vZHVsZXMvLnBucG0vbG9uZ0A0LjAuMC9ub2RlX21vZHVsZXMvbG9uZy9zcmMvbG9uZy5qcyIoZXhwb3J0czIsIG1vZHVsZTIpIHsKICAgICAgaW5pdF9idWZmZXJfc2hpbSgpOwogICAgICBtb2R1bGUyLmV4cG9ydHMgPSBMb25nNDsKICAgICAgdmFyIHdhc20gPSBudWxsOwogICAgICB0cnkgewogICAgICAgIHdhc20gPSBuZXcgV2ViQXNzZW1ibHkuSW5zdGFuY2UobmV3IFdlYkFzc2VtYmx5Lk1vZHVsZShuZXcgVWludDhBcnJheShbCiAgICAgICAgICAwLAogICAgICAgICAgOTcsCiAgICAgICAgICAxMTUsCiAgICAgICAgICAxMDksCiAgICAgICAgICAxLAogICAgICAgICAgMCwKICAgICAgICAgIDAsCiAgICAgICAgICAwLAogICAgICAgICAgMSwKICAgICAgICAgIDEzLAogICAgICAgICAgMiwKICAgICAgICAgIDk2LAogICAgICAgICAgMCwKICAgICAgICAgIDEsCiAgICAgICAgICAxMjcsCiAgICAgICAgICA5NiwKICAgICAgICAgIDQsCiAgICAgICAgICAxMjcsCiAgICAgICAgICAxMjcsCiAgICAgICAgICAxMjcsCiAgICAgICAgICAxMjcsCiAgICAgICAgICAxLAogICAgICAgICAgMTI3LAogICAgICAgICAgMywKICAgICAgICAgIDcsCiAgICAgICAgICA2LAogICAgICAgICAgMCwKICAgICAgICAgIDEsCiAgICAgICAgICAxLAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICAxLAogICAgICAgICAgNiwKICAgICAgICAgIDYsCiAgICAgICAgICAxLAogICAgICAgICAgMTI3LAogICAgICAgICAgMSwKICAgICAgICAgIDY1LAogICAgICAgICAgMCwKICAgICAgICAgIDExLAogICAgICAgICAgNywKICAgICAgICAgIDUwLAogICAgICAgICAgNiwKICAgICAgICAgIDMsCiAgICAgICAgICAxMDksCiAgICAgICAgICAxMTcsCiAgICAgICAgICAxMDgsCiAgICAgICAgICAwLAogICAgICAgICAgMSwKICAgICAgICAgIDUsCiAgICAgICAgICAxMDAsCiAgICAgICAgICAxMDUsCiAgICAgICAgICAxMTgsCiAgICAgICAgICA5NSwKICAgICAgICAgIDExNSwKICAgICAgICAgIDAsCiAgICAgICAgICAyLAogICAgICAgICAgNSwKICAgICAgICAgIDEwMCwKICAgICAgICAgIDEwNSwKICAgICAgICAgIDExOCwKICAgICAgICAgIDk1LAogICAgICAgICAgMTE3LAogICAgICAgICAgMCwKICAgICAgICAgIDMsCiAgICAgICAgICA1LAogICAgICAgICAgMTE0LAogICAgICAgICAgMTAxLAogICAgICAgICAgMTA5LAogICAgICAgICAgOTUsCiAgICAgICAgICAxMTUsCiAgICAgICAgICAwLAogICAgICAgICAgNCwKICAgICAgICAgIDUsCiAgICAgICAgICAxMTQsCiAgICAgICAgICAxMDEsCiAgICAgICAgICAxMDksCiAgICAgICAgICA5NSwKICAgICAgICAgIDExNywKICAgICAgICAgIDAsCiAgICAgICAgICA1LAogICAgICAgICAgOCwKICAgICAgICAgIDEwMywKICAgICAgICAgIDEwMSwKICAgICAgICAgIDExNiwKICAgICAgICAgIDk1LAogICAgICAgICAgMTA0LAogICAgICAgICAgMTA1LAogICAgICAgICAgMTAzLAogICAgICAgICAgMTA0LAogICAgICAgICAgMCwKICAgICAgICAgIDAsCiAgICAgICAgICAxMCwKICAgICAgICAgIDE5MSwKICAgICAgICAgIDEsCiAgICAgICAgICA2LAogICAgICAgICAgNCwKICAgICAgICAgIDAsCiAgICAgICAgICAzNSwKICAgICAgICAgIDAsCiAgICAgICAgICAxMSwKICAgICAgICAgIDM2LAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICAxMjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDAsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMzIsCiAgICAgICAgICAyLAogICAgICAgICAgMTczLAogICAgICAgICAgMzIsCiAgICAgICAgICAzLAogICAgICAgICAgMTczLAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNCwKICAgICAgICAgIDEzMiwKICAgICAgICAgIDEyNiwKICAgICAgICAgIDM0LAogICAgICAgICAgNCwKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzUsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAzNiwKICAgICAgICAgIDAsCiAgICAgICAgICAzMiwKICAgICAgICAgIDQsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAxMSwKICAgICAgICAgIDM2LAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICAxMjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDAsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMzIsCiAgICAgICAgICAyLAogICAgICAgICAgMTczLAogICAgICAgICAgMzIsCiAgICAgICAgICAzLAogICAgICAgICAgMTczLAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNCwKICAgICAgICAgIDEzMiwKICAgICAgICAgIDEyNywKICAgICAgICAgIDM0LAogICAgICAgICAgNCwKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzUsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAzNiwKICAgICAgICAgIDAsCiAgICAgICAgICAzMiwKICAgICAgICAgIDQsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAxMSwKICAgICAgICAgIDM2LAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICAxMjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDAsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMzIsCiAgICAgICAgICAyLAogICAgICAgICAgMTczLAogICAgICAgICAgMzIsCiAgICAgICAgICAzLAogICAgICAgICAgMTczLAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNCwKICAgICAgICAgIDEzMiwKICAgICAgICAgIDEyOCwKICAgICAgICAgIDM0LAogICAgICAgICAgNCwKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzUsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAzNiwKICAgICAgICAgIDAsCiAgICAgICAgICAzMiwKICAgICAgICAgIDQsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAxMSwKICAgICAgICAgIDM2LAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICAxMjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDAsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMzIsCiAgICAgICAgICAyLAogICAgICAgICAgMTczLAogICAgICAgICAgMzIsCiAgICAgICAgICAzLAogICAgICAgICAgMTczLAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNCwKICAgICAgICAgIDEzMiwKICAgICAgICAgIDEyOSwKICAgICAgICAgIDM0LAogICAgICAgICAgNCwKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzUsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAzNiwKICAgICAgICAgIDAsCiAgICAgICAgICAzMiwKICAgICAgICAgIDQsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAxMSwKICAgICAgICAgIDM2LAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICAxMjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDAsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMzIsCiAgICAgICAgICAyLAogICAgICAgICAgMTczLAogICAgICAgICAgMzIsCiAgICAgICAgICAzLAogICAgICAgICAgMTczLAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNCwKICAgICAgICAgIDEzMiwKICAgICAgICAgIDEzMCwKICAgICAgICAgIDM0LAogICAgICAgICAgNCwKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzUsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAzNiwKICAgICAgICAgIDAsCiAgICAgICAgICAzMiwKICAgICAgICAgIDQsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAxMQogICAgICAgIF0pKSwge30pLmV4cG9ydHM7CiAgICAgIH0gY2F0Y2ggKGUpIHsKICAgICAgfQogICAgICBmdW5jdGlvbiBMb25nNChsb3csIGhpZ2gsIHVuc2lnbmVkKSB7CiAgICAgICAgdGhpcy5sb3cgPSBsb3cgfCAwOwogICAgICAgIHRoaXMuaGlnaCA9IGhpZ2ggfCAwOwogICAgICAgIHRoaXMudW5zaWduZWQgPSAhIXVuc2lnbmVkOwogICAgICB9CiAgICAgIExvbmc0LnByb3RvdHlwZS5fX2lzTG9uZ19fOwogICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkoTG9uZzQucHJvdG90eXBlLCAiX19pc0xvbmdfXyIsIHsgdmFsdWU6IHRydWUgfSk7CiAgICAgIGZ1bmN0aW9uIGlzTG9uZyhvYmopIHsKICAgICAgICByZXR1cm4gKG9iaiAmJiBvYmpbIl9faXNMb25nX18iXSkgPT09IHRydWU7CiAgICAgIH0KICAgICAgTG9uZzQuaXNMb25nID0gaXNMb25nOwogICAgICB2YXIgSU5UX0NBQ0hFID0ge307CiAgICAgIHZhciBVSU5UX0NBQ0hFID0ge307CiAgICAgIGZ1bmN0aW9uIGZyb21JbnQodmFsdWUsIHVuc2lnbmVkKSB7CiAgICAgICAgdmFyIG9iaiwgY2FjaGVkT2JqLCBjYWNoZTsKICAgICAgICBpZiAodW5zaWduZWQpIHsKICAgICAgICAgIHZhbHVlID4+Pj0gMDsKICAgICAgICAgIGlmIChjYWNoZSA9IDAgPD0gdmFsdWUgJiYgdmFsdWUgPCAyNTYpIHsKICAgICAgICAgICAgY2FjaGVkT2JqID0gVUlOVF9DQUNIRVt2YWx1ZV07CiAgICAgICAgICAgIGlmIChjYWNoZWRPYmopCiAgICAgICAgICAgICAgcmV0dXJuIGNhY2hlZE9iajsKICAgICAgICAgIH0KICAgICAgICAgIG9iaiA9IGZyb21CaXRzKHZhbHVlLCAodmFsdWUgfCAwKSA8IDAgPyAtMSA6IDAsIHRydWUpOwogICAgICAgICAgaWYgKGNhY2hlKQogICAgICAgICAgICBVSU5UX0NBQ0hFW3ZhbHVlXSA9IG9iajsKICAgICAgICAgIHJldHVybiBvYmo7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIHZhbHVlIHw9IDA7CiAgICAgICAgICBpZiAoY2FjaGUgPSAtMTI4IDw9IHZhbHVlICYmIHZhbHVlIDwgMTI4KSB7CiAgICAgICAgICAgIGNhY2hlZE9iaiA9IElOVF9DQUNIRVt2YWx1ZV07CiAgICAgICAgICAgIGlmIChjYWNoZWRPYmopCiAgICAgICAgICAgICAgcmV0dXJuIGNhY2hlZE9iajsKICAgICAgICAgIH0KICAgICAgICAgIG9iaiA9IGZyb21CaXRzKHZhbHVlLCB2YWx1ZSA8IDAgPyAtMSA6IDAsIGZhbHNlKTsKICAgICAgICAgIGlmIChjYWNoZSkKICAgICAgICAgICAgSU5UX0NBQ0hFW3ZhbHVlXSA9IG9iajsKICAgICAgICAgIHJldHVybiBvYmo7CiAgICAgICAgfQogICAgICB9CiAgICAgIExvbmc0LmZyb21JbnQgPSBmcm9tSW50OwogICAgICBmdW5jdGlvbiBmcm9tTnVtYmVyKHZhbHVlLCB1bnNpZ25lZCkgewogICAgICAgIGlmIChpc05hTih2YWx1ZSkpCiAgICAgICAgICByZXR1cm4gdW5zaWduZWQgPyBVWkVSTyA6IFpFUk87CiAgICAgICAgaWYgKHVuc2lnbmVkKSB7CiAgICAgICAgICBpZiAodmFsdWUgPCAwKQogICAgICAgICAgICByZXR1cm4gVVpFUk87CiAgICAgICAgICBpZiAodmFsdWUgPj0gVFdPX1BXUl82NF9EQkwpCiAgICAgICAgICAgIHJldHVybiBNQVhfVU5TSUdORURfVkFMVUU7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIGlmICh2YWx1ZSA8PSAtVFdPX1BXUl82M19EQkwpCiAgICAgICAgICAgIHJldHVybiBNSU5fVkFMVUU7CiAgICAgICAgICBpZiAodmFsdWUgKyAxID49IFRXT19QV1JfNjNfREJMKQogICAgICAgICAgICByZXR1cm4gTUFYX1ZBTFVFOwogICAgICAgIH0KICAgICAgICBpZiAodmFsdWUgPCAwKQogICAgICAgICAgcmV0dXJuIGZyb21OdW1iZXIoLXZhbHVlLCB1bnNpZ25lZCkubmVnKCk7CiAgICAgICAgcmV0dXJuIGZyb21CaXRzKHZhbHVlICUgVFdPX1BXUl8zMl9EQkwgfCAwLCB2YWx1ZSAvIFRXT19QV1JfMzJfREJMIHwgMCwgdW5zaWduZWQpOwogICAgICB9CiAgICAgIExvbmc0LmZyb21OdW1iZXIgPSBmcm9tTnVtYmVyOwogICAgICBmdW5jdGlvbiBmcm9tQml0cyhsb3dCaXRzLCBoaWdoQml0cywgdW5zaWduZWQpIHsKICAgICAgICByZXR1cm4gbmV3IExvbmc0KGxvd0JpdHMsIGhpZ2hCaXRzLCB1bnNpZ25lZCk7CiAgICAgIH0KICAgICAgTG9uZzQuZnJvbUJpdHMgPSBmcm9tQml0czsKICAgICAgdmFyIHBvd19kYmwgPSBNYXRoLnBvdzsKICAgICAgZnVuY3Rpb24gZnJvbVN0cmluZyhzdHIsIHVuc2lnbmVkLCByYWRpeCkgewogICAgICAgIGlmIChzdHIubGVuZ3RoID09PSAwKQogICAgICAgICAgdGhyb3cgRXJyb3IoImVtcHR5IHN0cmluZyIpOwogICAgICAgIGlmIChzdHIgPT09ICJOYU4iIHx8IHN0ciA9PT0gIkluZmluaXR5IiB8fCBzdHIgPT09ICIrSW5maW5pdHkiIHx8IHN0ciA9PT0gIi1JbmZpbml0eSIpCiAgICAgICAgICByZXR1cm4gWkVSTzsKICAgICAgICBpZiAodHlwZW9mIHVuc2lnbmVkID09PSAibnVtYmVyIikgewogICAgICAgICAgcmFkaXggPSB1bnNpZ25lZCwgdW5zaWduZWQgPSBmYWxzZTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgdW5zaWduZWQgPSAhIXVuc2lnbmVkOwogICAgICAgIH0KICAgICAgICByYWRpeCA9IHJhZGl4IHx8IDEwOwogICAgICAgIGlmIChyYWRpeCA8IDIgfHwgMzYgPCByYWRpeCkKICAgICAgICAgIHRocm93IFJhbmdlRXJyb3IoInJhZGl4Iik7CiAgICAgICAgdmFyIHA7CiAgICAgICAgaWYgKChwID0gc3RyLmluZGV4T2YoIi0iKSkgPiAwKQogICAgICAgICAgdGhyb3cgRXJyb3IoImludGVyaW9yIGh5cGhlbiIpOwogICAgICAgIGVsc2UgaWYg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iBmYWxzZTsKICAgICAgICByZXR1cm4gdGhpcy5oaWdoID09PSBvdGhlci5oaWdoICYmIHRoaXMubG93ID09PSBvdGhlci5sb3c7CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUuZXEgPSBMb25nUHJvdG90eXBlLmVxdWFsczsKICAgICAgTG9uZ1Byb3RvdHlwZS5ub3RFcXVhbHMgPSBmdW5jdGlvbiBub3RFcXVhbHMob3RoZXIpIHsKICAgICAgICByZXR1cm4gIXRoaXMuZXEob3RoZXIpOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLm5lcSA9IExvbmdQcm90b3R5cGUubm90RXF1YWxzOwogICAgICBMb25nUHJvdG90eXBlLm5lID0gTG9uZ1Byb3RvdHlwZS5ub3RFcXVhbHM7CiAgICAgIExvbmdQcm90b3R5cGUubGVzc1RoYW4gPSBmdW5jdGlvbiBsZXNzVGhhbihvdGhlcikgewogICAgICAgIHJldHVybiB0aGlzLmNvbXAob3RoZXIpIDwgMDsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS5sdCA9IExvbmdQcm90b3R5cGUubGVzc1RoYW47CiAgICAgIExvbmdQcm90b3R5cGUubGVzc1RoYW5PckVxdWFsID0gZnVuY3Rpb24gbGVzc1RoYW5PckVxdWFsKG90aGVyKSB7CiAgICAgICAgcmV0dXJuIHRoaXMuY29tcChvdGhlcikgPD0gMDsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS5sdGUgPSBMb25nUHJvdG90eXBlLmxlc3NUaGFuT3JFcXVhbDsKICAgICAgTG9uZ1Byb3RvdHlwZS5sZSA9IExvbmdQcm90b3R5cGUubGVzc1RoYW5PckVxdWFsOwogICAgICBMb25nUHJvdG90eXBlLmdyZWF0ZXJUaGFuID0gZnVuY3Rpb24gZ3JlYXRlclRoYW4ob3RoZXIpIHsKICAgICAgICByZXR1cm4gdGhpcy5jb21wKG90aGVyKSA+IDA7CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5c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sgYjE2OwogICAgICAgIGMzMiArPSBjMTYgPj4+IDE2OwogICAgICAgIGMxNiAmPSA2NTUzNTsKICAgICAgICBjMzIgKz0gYTMyICsgYjMyOwogICAgICAgIGM0OCArPSBjMzIgPj4+IDE2OwogICAgICAgIGMzMiAmPSA2NTUzNTsKICAgICAgICBjNDggKz0gYTQ4ICsgYjQ4OwogICAgICAgIGM0OCAmPSA2NTUzNTsKICAgICAgICByZXR1cm4gZnJvbUJpdHMoYzE2IDw8IDE2IHwgYzAwLCBjNDggPDwgMTYgfCBjMzIsIHRoaXMudW5zaWduZWQpOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLnN1YnRyYWN0ID0gZnVuY3Rpb24gc3VidHJhY3Qoc3VidHJhaGVuZCkgewogICAgICAgIGlmICghaXNMb25nKHN1YnRyYWhlbmQpKQogICAgICAgICAgc3VidHJhaGVuZCA9IGZyb21WYWx1ZShzdWJ0cmFoZW5kKTsKICAgICAgICByZXR1cm4gdGhpcy5hZGQoc3VidHJhaGVuZC5uZWcoKSk7CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUuc3ViID0gTG9uZ1Byb3RvdHlwZS5zdWJ0cmFjdDsKICAgICAgTG9uZ1Byb3RvdHlwZS5tdWx0aXBseSA9IGZ1bmN0aW9uIG11bHRpcGx5KG11bHRpcGxpZXIpIHsKICAgICAgICBpZiAodGhpcy5pc1plcm8oKSkKICAgICAgICAgIHJldHVybiBaRVJPOwogICAgICAgIGlmICghaXNMb25nKG11bHRpcGxpZXIpKQogICAgICAgICAgbXVsdGlwbGllciA9IGZyb21WYWx1ZShtdWx0aXBsaWVyKTsKICAgICAgICBpZiAod2FzbSkgewogICAgICAgICAgdmFyIGxvdyA9IHdhc20ubXVsKHRoaXMubG93LCB0aGlzLmhpZ2gsIG11bHRpcGxpZXIubG93LCBtdWx0aXBsaWVyLmhpZ2gpOwogICAgICAgICAgcmV0dXJuIGZyb21CaXRzKGxvdywgd2FzbS5nZXRfaGlnaCgp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CiAgICAgIExvbmdQcm90b3R5cGUubXVsID0gTG9uZ1Byb3RvdHlwZS5tdWx0aXBseTsKICAgICAgTG9uZ1Byb3RvdHlwZS5kaXZpZGUgPSBmdW5jdGlvbiBkaXZpZGUoZGl2aXNvcikgewogICAgICAgIGlmICghaXNMb25nKGRpdmlzb3IpKQogICAgICAgICAgZGl2aXNvciA9IGZyb21WYWx1ZShkaXZpc29yKTsKICAgICAgICBpZiAoZGl2aXNvci5pc1plcm8oKSkKICAgICAgICAgIHRocm93IEVycm9yKCJkaXZpc2lvbiBieSB6ZXJvIik7CiAgICAgICAgaWYgKHdhc20pIHsKICAgICAgICAgIGlmICghdGhpcy51bnNpZ25lZCAmJiB0aGlzLmhpZ2ggPT09IC0yMTQ3NDgzNjQ4ICYmIGRpdmlzb3IubG93ID09PSAtMSAmJiBkaXZpc29yLmhpZ2ggPT09IC0xKSB7CiAgICAgICAgICAgIHJldHVybiB0aGlzOwogICAgICAgICAgfQogICAgICAgICAgdmFyIGxvdyA9ICh0aGlzLnVuc2lnbmVkID8gd2FzbS5kaXZfdSA6IHdhc20uZGl2X3MpKHRoaXMubG93LCB0aGlzLmhpZ2gsIGRpdmlzb3IubG93LCBkaXZpc29yLmhpZ2gpOwogICAgICAgICAgcmV0dXJuIGZyb21CaXRzKGxvdywgd2FzbS5nZXRfaGlnaCgpLCB0aGlzLnVuc2lnbmVkKTsKICAgICAgICB9CiAgICAgICAgaWYgKHRoaXMuaXNaZXJvKCkpCiAgICAgICAgICByZXR1cm4gdGhpcy51bnNpZ25lZCA/IFVaRVJPIDogWkVSTzsKICAgICAgICB2YXIgYXBwcm94LCByZW0sIHJlczsKICAgICAgICBpZiAoIXRoaXMudW5zaWduZWQpIHsKICAgICAgICAgIGlmICh0aGlzLmVxKE1JTl9WQUxVRSkpIHsKICAgICAgICAgICAgaWYgKGRpdmlzb3IuZXEoT05FKSB8fCBkaXZpc29yLmVxKE5FR19PTkUpKQogICAgICAgICAgICAgIHJldHVybiBNSU5fVkFMVUU7CiAgICAgICAgICAgIGVsc2UgaWYgKGRpdmlzb3IuZXEoTUlOX1ZBTFVFKSkKICAgICAgICAgICAgICByZXR1cm4gT05FOwogICAgICAgICAgICBlbHNlIHsKICAgICAgICAgICAgICB2YXIgaGFsZlRoaXMgPSB0aGlzLnNocigxKTsKICAgICAgICAgICAgICBhcHByb3ggPSBoYWxmVGhpcy5kaXYoZGl2aXNvcikuc2hsKDEpOwogICAgICAgICAgICAgIGlmIChhcHByb3guZXEoWkVSTykpIHsKICAgICAgICAgICAgICAgIHJldHVybiBkaXZpc29yLmlzTmVnYXRpdmUoKSA/IE9ORSA6IE5FR19PTkU7CiAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIHJlbSA9IHRoaXMuc3ViKGRpdmlzb3IubXVsKGFwcHJveCkpOwogICAgICAgICAgICAgICAgcmVzID0gYXBwcm94LmFkZChyZW0uZGl2KGRpdmlzb3IpKTsKICAgICAgICAgICAgICAgIHJldHVybiByZXM7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgaWYgKGRpdmlzb3IuZXEoTUlOX1ZBTFVFKSkKICAgICAgICAgICAgcmV0dXJuIHRoaXMudW5zaWduZWQgPyBVWkVSTyA6IFpFUk87CiAgICAgICAgICBpZiAodGhpcy5pc05lZ2F0aXZlKCkpIHsKICAgICAgICAgICAgaWYgKGRpdmlzb3IuaXNOZWdhdGl2ZSgpKQogICAgICAgICAgICAgIHJldHVybiB0aGlzLm5lZygpLmRpdihkaXZpc29yLm5lZygpKTsKICAgICAgICAgICAgcmV0dXJuIHRoaXMubmVnKCkuZGl2KGRpdmlzb3IpLm5lZygpOwogICAgICAgICAgfSBlbHNlIGlmIChkaXZpc29yLmlzTmVnYXRpdmUoKSkKICAgICAgICAgICAgcmV0dXJuIHRoaXMuZGl2KGRpdmlzb3IubmVnKCkpLm5lZygpOwogICAgICAgICAgcmVzID0gWkVSTzsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgaWYgKCFkaXZpc29yLnVuc2lnbmVkKQogICAgICAgICAgICBkaXZpc29yID0gZGl2aXNvci50b1Vuc2lnbmVkKCk7CiAgICAgICAgICBpZiAoZGl2aXNvci5ndCh0aGlzKSkKICAgICAgICAgICAgcmV0dXJuIFVaRVJPOwogICAgICAgICAgaWYgKGRpdmlzb3IuZ3QodGhpcy5zaHJ1KDEpKSkKICAgICAgICAgICAgcmV0dXJuIFVPTkU7CiAgICAgICAgICByZXMgPSBVWkVSTzsKICAgICAgICB9CiAgICAgICAgcmVtID0gdGhpczsKICAgICAgICB3aGlsZSAocmVtLmd0ZShkaXZpc29yKSkgewogICAgICAgICAgYXBwcm94ID0gTWF0aC5tYXgoMSwgTWF0aC5mbG9vcihyZW0udG9OdW1iZXIoKSAvIGRpdmlzb3IudG9OdW1iZXIoKSkpOwogICAgICAgICAgdmFyIGxvZzIgPSBNYXRoLmNlaWwoTWF0aC5sb2coYXBwcm94KSAvIE1hdGguTE4yKSwgZGVsdGEgPSBsb2cyIDw9IDQ4ID8gMSA6IHBvd19kYmwoMiwgbG9nMiAtIDQ4KSwgYXBwcm94UmVzID0gZnJvbU51bWJlcihhcHByb3gpLCBhcHByb3hSZW0gPSBhcHByb3hSZXMubXVsKGRpdmlzb3IpOwogICAgICAgICAgd2hpbGUgKGFwcHJveFJlbS5pc05lZ2F0aXZlKCkgfHwgYXBwcm94UmVtLmd0KHJlbSkpIHsKICAgICAgICAgICAgYXBwcm94IC09IGRlbHRhOwogICAgICAgICAgICBhcHByb3hSZXMgPSBmcm9tTnVtYmVyKGFwcHJveCwgdGhpcy51bnNpZ25lZCk7CiAgICAgICAgICAgIGFwcHJveFJlbSA9IGFwcHJveFJlcy5tdWwoZGl2aXNvcik7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoYXBwcm94UmVzLmlzWmVybygpKQogICAgICAgICAgICBhcHByb3hSZXMgPSBPTkU7CiAgICAgICAgICByZXMgPSByZXMuYWRkKGFwcHJveFJlcyk7CiAgICAgICAgICByZW0gPSByZW0uc3ViKGFwcHJveFJlbSk7CiAgICAgICAgfQogICAgICAgIHJldHVybiByZXM7CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUuZGl2ID0gTG9uZ1Byb3RvdHlwZS5kaXZpZGU7CiAgICAgIExvbmdQcm90b3R5cGUubW9kdWxvID0gZnVuY3Rpb24gbW9kdWxvKGRpdmlzb3IpIHsKICAgICAgICBpZiAoIWlzTG9uZyhkaXZpc29yKSkKICAgICAgICAgIGRpdmlzb3IgPSBmcm9tVmFsdWUoZGl2aXNvcik7CiAgICAgICAgaWYgKHdhc20pIHsKICAgICAgICAgIHZhciBsb3cgPSAodGhpcy51bnNpZ25lZCA/IHdhc20ucmVtX3UgOiB3YXNtLnJlbV9zKSh0aGlzLmxvdywgdGhpcy5oaWdoLCBkaXZpc29yLmxvdywgZGl2aXNvci5oaWdoKTsKICAgICAgICAgIHJldHVybiBmcm9tQml0cyhsb3csIHdhc20uZ2V0X2hpZ2goKSwgdGhpcy51bnNpZ25lZCk7CiAgICAgICAgfQogICAgICAgIHJldHVybiB0aGlzLnN1Yih0aGlzLmRpdihkaXZpc29yKS5tdWwoZGl2aXNvcikpOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLm1vZCA9IExvbmdQcm90b3R5cGUubW9kdWxvOwogICAgICBMb25nUHJvdG90eXBlLnJlbSA9IExvbmdQcm90b3R5cGUubW9kdWxvOwogICAgICBMb25nUHJvdG90eXBlLm5vdCA9IGZ1bmN0aW9uIG5vdCgpIHsKICAgICAgICByZXR1cm4gZnJvbUJpdHMofnRoaXMubG93LCB+dGhpcy5oaWdoLCB0aGlzLnVuc2lnbmVkKTsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS5hbmQgPSBmdW5jdGlvbiBhbmQob3RoZXIpIHsKICAgICAgICBpZiAoIWlzTG9uZyhvdGhlcikpCiAgICAgICAgICBvdGhlciA9IGZyb21WYWx1ZShvdGhlc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AgICAgICAgZWxzZQogICAgICAgICAgcmV0dXJuIGZyb21CaXRzKDAsIHRoaXMubG93IDw8IG51bUJpdHMgLSAzMiwgdGhpcy51bnNpZ25lZCk7CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUuc2hsID0gTG9uZ1Byb3RvdHlwZS5zaGlmdExlZnQ7CiAgICAgIExvbmdQcm90b3R5cGUuc2hpZnRSaWdodCA9IGZ1bmN0aW9uIHNoaWZ0UmlnaHQobnVtQml0cykgewogICAgICAgIGlmIChpc0xvbmcobnVtQml0cykpCiAgICAgICAgICBudW1CaXRzID0gbnVtQml0cy50b0ludCgpOwogICAgICAgIGlmICgobnVtQml0cyAmPSA2MykgPT09IDApCiAgICAgICAgICByZXR1cm4gdGhpczsKICAgICAgICBlbHNlIGlmIChudW1CaXRzIDwgMzIpCiAgICAgICAgICByZXR1cm4gZnJvbUJpdHModGhpcy5sb3cgPj4+IG51bUJpdHMgfCB0aGlzLmhpZ2ggPDwgMzIgLSBudW1CaXRzLCB0aGlzLmhpZ2ggPj4gbnVtQml0cywgdGhpcy51bnNpZ25lZCk7CiAgICAgICAgZWxzZQogICAgICAgICAgcmV0dXJuIGZyb21CaXRzKHRoaXMuaGlnaCA+PiBudW1CaXRzIC0gMzIsIHRoaXMuaGlnaCA+PSAwID8gMCA6IC0xLCB0aGlzLnVuc2lnbmVkKTsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS5zaHIgPSBMb25nUHJvdG90eXBlLnNoaWZ0UmlnaHQ7CiAgICAgIExvbmdQcm90b3R5cGUuc2hpZnRSaWdodFVuc2lnbmVkID0gZnVuY3Rpb24gc2hpZnRSaWdodFVuc2lnbmVkKG51bUJpdHMpIHsKICAgICAgICBpZiAoaXNMb25nKG51bUJpdHMpKQogICAgICAgICAgbnVtQml0cyA9IG51bUJpdHMudG9JbnQoKTsKICAgICAgICBudW1CaXRzICY9IDYzOwogICAgICAgIGlmIChudW1CaXRzID09PSAwKQogICAgICAgICAgcmV0dXJuIHRoaXM7CiAgICAgICAgZWxzZSB7CiAgICAgICAgICB2YXIgaGlnaCA9IHRoaXMuaGlnaDsKICAgICAgICAgIGlmIChudW1CaXRzIDwgMzIpIHsKICAgICAgICAgICAgdmFyIGxvdyA9IHRoaXMubG93OwogICAgICAgICAgICByZXR1cm4gZnJvbUJpdHMobG93ID4+PiBudW1CaXRzIHwgaGlnaCA8PCAzMiAtIG51bUJpdHMsIGhpZ2ggPj4+IG51bUJpdHMsIHRoaXMudW5zaWduZWQpOwogICAgICAgICAgfSBlbHNlIGlmIChudW1CaXRzID09PSAzMikKICAgICAgICAgICAgcmV0dXJuIGZyb21CaXRzKGhpZ2gsIDAsIHRoaXMudW5zaWduZWQpOwogICAgICAgICAgZWxzZQogICAgICAgICAgICByZXR1cm4gZnJvbUJpdHMoaGlnaCA+Pj4gbnVtQml0cyAtIDMyLCAwLCB0aGlzLnVuc2lnbmVkKTsKICAgICAgICB9CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUuc2hydSA9IExvbmdQcm90b3R5cGUuc2hpZnRSaWdodFVuc2lnbmVkOwogICAgICBMb25nUHJvdG90eXBlLnNocl91ID0gTG9uZ1Byb3RvdHlwZS5zaGlmdFJpZ2h0VW5zaWduZWQ7CiAgICAgIExvbmdQcm90b3R5cGUudG9TaWduZWQgPSBmdW5jdGlvbiB0b1NpZ25lZCgpIHsKICAgICAgICBpZiAoIXRoaXMudW5zaWduZWQpCiAgICAgICAgICByZXR1cm4gdGhpczsKICAgICAgICByZXR1cm4gZnJvbUJpdHModGhpcy5sb3csIHRoaXMuaGlnaCwgZmFsc2UpOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLnRvVW5zaWduZWQgPSBmdW5jdGlvbiB0b1Vuc2lnbmVkKCkgewogICAgICAgIGlmICh0aGlzLnVuc2lnbmVkKQogICAgICAgICAgcmV0dXJuIHRoaXM7CiAgICAgICAgcmV0dXJuIGZyb21CaXRzKHRoaXMubG93LCB0aGlzLmhpZ2gsIHRydWUpOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLnRvQnl0ZXMgPSBmdW5jdGlvbiB0b0J5dGVzKGxlKSB7CiAgICAgICAgcmV0dXJuIGxlID8gdGhpcy50b0J5dGVzTEUoKSA6IHRoaXMudG9CeXRlc0JFKCk7CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUudG9CeXRlc0xFID0gZnVuY3Rpb24gdG9CeXRlc0xFKCkgewogICAgICAgIHZhciBoaSA9IHRoaXMuaGlnaCwgbG8gPSB0aGlzLmxvdzsKICAgICAgICByZXR1cm4gWwogICAgICAgICAgbG8gJiAyNTUsCiAgICAgICAgICBsbyA+Pj4gOCAmIDI1NSwKICAgICAgICAgIGxvID4+PiAxNiAmIDI1NSwKICAgICAgICAgIGxvID4+PiAyNCwKICAgICAgICAgIGhpICYgMjU1LAogICAgICAgICAgaGkgPj4+IDggJiAyNTUsCiAgICAgICAgICBoaSA+Pj4gMTYgJiAyNTUsCiAgICAgICAgICBoaSA+Pj4gMjQKICAgICAgICBdOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLnRvQnl0ZXNCRSA9IGZ1bmN0aW9uIHRvQnl0ZXNCRSgpIHsKICAgICAgICB2YXIgaGkgPSB0aGlzLmhpZ2gsIGxvID0gdGhpcy5sb3c7CiAgICAgICAgcmV0dXJuIFsKICAgICAgICAgIGhpID4+PiAyNCwKICAgICAgICAgIGhpID4+PiAxNiAmIDI1NSwKICAgICAgICAgIGhpID4+PiA4ICYgMjU1LAogICAgICAgICAgaGkgJiAyNTUsCiAgICAgICAgICBsbyA+Pj4gMjQsCiAgICAgICAgICBsbyA+Pj4gMTYgJiAyNTUsCiAgICAgICAgICBsbyA+Pj4gOCAmIDI1NSwKICAgICAgICAgIGxvICYgMjU1CiAgICAgICAgXTsKICAgICAgfTsKICAgICAgTG9uZzQuZnJvbUJ5dGVzID0gZnVuY3Rpb24gZnJvbUJ5dGVzMihieXRlcywgdW5zaWduZWQsIGx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HRTZXJpYWxpemVyID0gZXhwb3J0czIuZXh0ZW5kU2VyaWFsaXplciA9IHZvaWQgMDsKICAgICAgZnVuY3Rpb24gZXh0ZW5kU2VyaWFsaXplcihleHRlbmQsIGltcGxlbWVudGF0aW9uKSB7CiAgICAgICAgY29uc3QgZmFsbGJhY2tEZXNlcmlhbGl6ZXIgPSBleHRlbmQuZGVzZXJpYWxpemUuYmluZChleHRlbmQpOwogICAgICAgIGNvbnN0IGZhbGxiYWNrU2VyaWFsaXplciA9IGV4dGVuZC5zZXJpYWxpemUuYmluZChleHRlbmQpOwogICAgICAgIHJldHVybiB7CiAgICAgICAgICBkZXNlcmlhbGl6ZShtZXNzYWdlKSB7CiAgICAgICAgICAgIHJldHVybiBpbXBsZW1lbnRhdGlvbi5kZXNlcmlhbGl6ZShtZXNzYWdlLCBmYWxsYmFja0Rlc2VyaWFsaXplcik7CiAgICAgICAgICB9LAogICAgICAgICAgc2VyaWFsaXplKGlucHV0KSB7CiAgICAgICAgICAgIHJldHVybiBpbXBsZW1lbnRhdGlvbi5zZXJpYWxpemUoaW5wdXQsIGZhbGxiYWNrU2VyaWFsaXplcik7CiAgICAgICAgICB9CiAgICAgICAgfTsKICAgICAgfQogICAgICBleHBvcnRzMi5leHRlbmRTZXJpYWxpemVyID0gZXh0ZW5kU2VyaWFsaXplcjsKICAgICAgdmFyIERlZmF1bHRFcnJvclNlcmlhbGl6ZXIgPSB7CiAgICAgICAgZGVzZXJpYWxpemUobWVzc2FnZSkgewogICAgICAgICAgcmV0dXJuIE9iamVjdC5hc3NpZ24oRXJyb3IobWVzc2FnZS5tZXNzYWdlKSwgewogICAgICAgICAgICBuYW1lOiBtZXNzYWdlLm5hbWUsCiAgICAgICAgICAgIHN0YWNrOiBtZXNzYWdlLnN0YWNrCiAgICAgICAgICB9KTsKICAgICAgICB9LAogICAgICAgIHNlcmlhbGl6ZShlcnJvcikgewogICAgICAgICAgcmV0dXJuIHsKICAgICAgICAgICAgX19lcnJvcl9tYXJrZXI6ICIkJGVycm9yIiwKICAgICAgICAgICAgbWVzc2FnZTogZXJyb3IubWVzc2FnZSwKICAgICAgICAgICAgbmFtZTogZXJyb3IubmFtZSwKICAgICAgICAgICAgc3RhY2s6IGVycm9yLnN0YWNrCiAgICAgICAgICB9OwogICAgICAgIH0KICAgICAgfTsKICAgICAgdmFyIGlzU2VyaWFsaXplZEVycm9yID0gKHRoaW5nKSA9PiB0aGluZyAmJiB0eXBlb2YgdGhpbmcgPT09ICJvYmplY3QiICYmICJfX2Vycm9yX21hcmtlciIgaW4gdGhpbmcgJiYgdGhpbmcuX19lcnJvcl9tYXJrZXIgPT09ICIkJGVycm9yIjsKICAgICAgZXhwb3J0czIuRGVmYXVsdFNlcmlhbGl6ZXIgPSB7CiAgICAgICAgZGVzZXJpYWxpemUobWVzc2FnZSkgewogICAgICAgICAgaWYgKGlzU2VyaWFsaXplZEVycm9yKG1lc3NhZ2UpKSB7CiAgICAgICAgICAgIHJldHVybiBEZWZhdWx0RXJyb3JTZXJpYWxpemVyLmRlc2VyaWFsaXplKG1lc3NhZ2UpOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcmV0dXJuIG1lc3NhZ2U7CiAgICAgICAgICB9CiAgICAgICAgfSwKICAgICAgICBzZXJpYWxpemUoaW5wdXQpIHsKICAgICAgICAgIGlmIChpbnB1dCBpbnN0YW5jZW9mIEVycm9yKSB7CiAgICAgICAgICAgIHJldHVybiBEZWZhdWx0RXJyb3JTZXJpYWxpemVyLnNlcmlhbGl6ZShpbnB1dCk7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICByZXR1cm4gaW5wdXQ7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9OwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vdGhyZWFkc0AxLjcuMC9ub2RlX21vZHVsZXMvdGhyZWFkcy9kaXN0L2NvbW1vbi5qcwogIHZhciByZXF1aXJlX2NvbW1vbjIgPSBfX2NvbW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ihyZXNvbHZlLCByZWplY3QpIHsKICAgICAgICAgIGZ1bmN0aW9uIGZ1bGZpbGxlZCh2YWx1ZSkgewogICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgIHN0ZXAoZ2VuZXJhdG9yLm5leHQodmFsdWUpKTsKICAgICAgICAgICAgfSBjYXRjaCAoZSkgewogICAgICAgICAgICAgIHJlamVjdChlKTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgZnVuY3Rpb24gcmVqZWN0ZWQodmFsdWUpIHsKICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICBzdGVwKGdlbmVyYXRvclsidGhyb3ciXSh2YWx1ZSkpOwogICAgICAgICAgICB9IGNhdGNoIChlKSB7CiAgICAgICAgICAgICAgcmVqZWN0KGUpOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBmdW5jdGlvbiBzdGVwKHJlc3VsdCkgewogICAgICAgICAgICByZXN1bHQuZG9uZSA/IHJlc29sdmUocmVzdWx0LnZhbHVlKSA6IGFkb3B0KHJlc3VsdC52YWx1ZSkudGhlbihmdWxmaWxsZWQsIHJlamVjdGVkKTsKICAgICAgICAgIH0KICAgICAgICAgIHN0ZXAoKGdlbmVyYXRvciA9IGdlbmVyYXRvci5hcHBseSh0aGlzQXJnLCBfYXJndW1lbnRzIHx8IFtdKSkubmV4dCgpKTsKICAgICAgICB9KTsKICAgICAgfTsKICAgICAgdmFyIF9faW1wb3J0RGVmYXVsdCA9IGV4cG9ydHMyICYmIGV4cG9ydHMyLl9faW1wb3J0RGVmYXVsdCB8fCBmdW5jdGlvbihtb2QpIHsKICAgICAgICByZXR1cm4gbW9kICYmIG1vZC5fX2VzTW9kdWxlID8gbW9kIDogeyAiZGVmYXVsdCI6IG1vZCB9OwogICAgICB9OwogICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkoZXhwb3J0czIsICJfX2VzTW9kdWxlIiwgeyB2YWx1ZTogdHJ1ZSB9KTsKICAgICAgZXhw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A9IHsKICAgICAgICAgIHR5cGU6IG1lc3NhZ2VzXzEuV29ya2VyTWVzc2FnZVR5cGUuaW5pdCwKICAgICAgICAgIGV4cG9zZWQ6IHsKICAgICAgICAgICAgdHlwZTogImZ1bmN0aW9uIgogICAgICAgICAgfQogICAgICAgIH07CiAgICAgICAgaW1wbGVtZW50YXRpb25fMS5kZWZhdWx0LnBvc3RNZXNzYWdlVG9NYXN0ZXIoaW5pdE1lc3NhZ2UpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIHBvc3RNb2R1bGVJbml0TWVzc2FnZShtZXRob2ROYW1lcykgewogICAgICAgIGNvbnN0IGluaXRNZXNzYWdlID0gewogICAgICAgICAgdHlwZTogbWVzc2FnZXNfMS5Xb3JrZXJNZXNzYWdlVHlwZS5pbml0LAogICAgICAgICAgZXhwb3NlZDogewogICAgICAgICAgICB0eXBlOiAibW9kdWxlIiwKICAgICAgICAgICAgbWV0aG9kczogbWV0aG9kTmFtZXMKICAgICAgICAgIH0KICAgICAgICB9OwogICAgICAgIGltcGxlbWVudGF0aW9uXzEuZGVmYXVsdC5wb3N0TWVzc2FnZVRvTWFzdGVyKGluaXRNZXNzYWdlKTsKICAgICAgfQogICAgICBmdW5jdGlvbiBwb3N0Sm9iRXJyb3JNZXNzYWdlKHVpZCwgcmF3RXJyb3IpIHsKICAgICAgICBjb25zdCB7IHBheWxvYWQ6IGVycm9yLCB0cmFuc2ZlcmFibGVzIH0gPSBkZWNvbnN0cnVjdFRyYW5zZmVyKHJhd0Vycm9yKTsKICAgICAgICBjb25zdCBlcnJvck1lc3NhZ2UgPSB7CiAgICAgICAgICB0eXBlOiBtZXNzYWdlc18xLldvcmtlck1lc3NhZ2VUeXBlLmVycm9yLAogICAgICAgICAgdWlkLAogICAgICAgICAgZXJyb3I6IGNvbW1vbl8xLnNlcmlhbGl6ZShlcnJvcikKICAgICAgICB9OwogICAgICAgIGltcGxlbWVudGF0aW9uXzEuZGVmYXVsdC5wb3N0TWVzc2FnZVR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ICAgICAgICB9IGVsc2UgewogICAgICAgICAgdGhyb3cgZTsKICAgICAgICB9CiAgICAgIH0KICAgICAgcmV0dXJuIHJlc3BvbnNlOwogICAgfQogICAgYXN5bmMgcmVhZChidWZmZXIsIG9mZnNldCA9IDAsIGxlbmd0aCwgcG9zaXRpb24gPSAwLCBvcHRzID0ge30pIHsKICAgICAgY29uc3QgeyBoZWFkZXJzID0ge30sIHNpZ25hbCwgb3ZlcnJpZGVzID0ge30gfSA9IG9wdHM7CiAgICAgIGlmIChsZW5ndGggPCBJbmZpbml0eSkgewogICAgICAgIGhlYWRlcnMucmFuZ2UgPSBgYnl0ZXM9JHtwb3NpdGlvbn0tJHtwb3NpdGlvbiArIGxlbmd0aH1gOwogICAgICB9IGVsc2UgaWYgKGxlbmd0aCA9PT0gSW5maW5pdHkgJiYgcG9zaXRpb24gIT09IDApIHsKICAgICAgICBoZWFkZXJzLnJhbmdlID0gYGJ5dGVzPSR7cG9zaXRpb259LWA7CiAgICAgIH0KICAgICAgY29uc3QgYXJncyA9IHsKICAgICAgICAuLi50aGlzLmJhc2VPdmVycmlkZXMsCiAgICAgICAgLi4ub3ZlcnJpZGVzLAogICAgICAgIGhlYWRlcnM6IHsKICAgICAgICAgIC4uLmhlYWRlcnMsCiAgICAgICAgICAuLi5vdmVycmlkZXMuaGVhZGVycywKICAgICAgICAgIC4uLnRoaXMuYmFzZU92ZXJyaWRlcy5oZWFkZXJzCiAgICAgICAgfSwKICAgICAgICBtZXRob2Q6ICJHRVQiLAogICAgICAgIHJlZGlyZWN0OiAiZm9sbG93IiwKICAgICAgICBtb2RlOiAiY29ycyIsCiAgICAgICAgc2lnbmFsCiAgICAgIH07CiAgICAgIGNvbnN0IHJlc3BvbnNlID0gYXdhaXQgdGhpcy5mZXRjaCh0aGlzLnVybCwgYXJncyk7CiAgICAgIGlmICghcmVzcG9uc2Uub2spIHsKICAgICAgICB0aHJvdyBuZXcgRXJyb3IoYEhUVFAgJHtyZXNwb25zZS5zdGF0d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ICAgbGV0IGVuY29kaW5nOwogICAgICBsZXQgb3B0czsKICAgICAgaWYgKHR5cGVvZiBvcHRpb25zID09PSAic3RyaW5nIikgewogICAgICAgIGVuY29kaW5nID0gb3B0aW9uczsKICAgICAgICBvcHRzID0ge307CiAgICAgIH0gZWxzZSB7CiAgICAgICAgZW5jb2RpbmcgPSBvcHRpb25zLmVuY29kaW5nOwogICAgICAgIG9wdHMgPSBvcHRpb25zOwogICAgICAgIGRlbGV0ZSBvcHRzLmVuY29kaW5nOwogICAgICB9CiAgICAgIGNvbnN0IHsgaGVhZGVycyA9IHt9LCBzaWduYWwsIG92ZXJyaWRlcyA9IHt9IH0gPSBvcHRzOwogICAgICBjb25zdCBhcmdzID0gewogICAgICAgIGhlYWRlcnMsCiAgICAgICAgbWV0aG9kOiAiR0VUIiwKICAgICAgICByZWRpcmVjdDogImZvbGxvdyIsCiAgICAgICAgbW9kZTogImNvcnMiLAogICAgICAgIHNpZ25hbCwKICAgICAgICAuLi50aGlzLmJhc2VPdmVycmlkZXMsCiAgICAgICAgLi4ub3ZlcnJpZGVzCiAgICAgIH07CiAgICAgIGNvbnN0IHJlc3BvbnNlID0gYXdhaXQgdGhpcy5mZXRjaCh0aGlzLnVybCwgYXJncyk7CiAgICAgIGlmICghcmVzcG9uc2UpIHsKICAgICAgICB0aHJvdyBuZXcgRXJyb3IoImdlbmVyaWMtZmlsZWhhbmRsZSBmYWlsZWQgdG8gZmV0Y2giKTsKICAgICAgfQogICAgICBpZiAocmVzcG9uc2Uuc3RhdHVzICE9PSAyMDApIHsKICAgICAgICB0aHJvdyBPYmplY3QuYXNzaWduKG5ldyBFcnJvcihgSFRUUCAke3Jlc3BvbnNlLnN0YXR1c30gZmV0Y2hpbmcgJHt0aGlzLnVybH1gKSwgewogICAgICAgICAgc3RhdHVzOiByZXNwb25zZS5zdGF0dXMKICAgICAgICB9KTsKICAgICAgfQogICAgICBpZiAoZW5jb2RpbmcgPT09ICJ1dGY4IikgewogICAgICAgIHJldH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AgICAgY29uc3QgeyBtaW52LCBtYXh2IH0gPSBjaHVuazsKICAgICAgbGV0IGNwb3MgPSBtaW52LmJsb2NrUG9zaXRpb247CiAgICAgIGxldCBkcG9zID0gbWludi5kYXRhUG9zaXRpb247CiAgICAgIGNvbnN0IGNodW5rcyA9IFtdOwogICAgICBjb25zdCBjcG9zaXRpb25zID0gW107CiAgICAgIGNvbnN0IGRwb3NpdGlvbnMgPSBbXTsKICAgICAgbGV0IHRvdGFsU2l6ZSA9IDA7CiAgICAgIGxldCBpID0gMDsKICAgICAgZG8gewogICAgICAgIGNvbnN0IHJlbWFpbmluZ0lucHV0ID0gaW5wdXREYXRhLnN1YmFycmF5KGNwb3MgLSBtaW52LmJsb2NrUG9zaXRpb24pOwogICAgICAgIGNvbnN0IGluZmxhdG9yID0gbmV3IGltcG9ydF9wYWtvLkluZmxhdGUoKTsKICAgICAgICAoeyBzdHJtIH0gPSBpbmZsYXRvcik7CiAgICAgICAgaW5mbGF0b3IucHVzaChyZW1haW5pbmdJbnB1dCwgaW1wb3J0X3Bha28uWl9TWU5DX0ZMVVNIKTsKICAgICAgICBpZiAoaW5mbGF0b3IuZXJyKSB7CiAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IoaW5mbGF0b3IubXNnKTsKICAgICAgICB9CiAgICAgICAgY29uc3QgYnVmZmVyMiA9IGluZmxhdG9yLnJlc3VsdDsKICAgICAgICBjaHVua3MucHVzaChidWZmZXIyKTsKICAgICAgICBsZXQgbGVuID0gYnVmZmVyMi5sZW5ndGg7CiAgICAgICAgY3Bvc2l0aW9ucy5wdXNoKGNwb3MpOwogICAgICAgIGRwb3NpdGlvbnMucHVzaChkcG9zKTsKICAgICAgICBpZiAoY2h1bmtzLmxlbmd0aCA9PT0gMSAmJiBtaW52LmRhdGFQb3NpdGlvbikgewogICAgICAgICAgY2h1bmtzWzBdID0gY2h1bmtzWzBdLnN1YmFycmF5KG1pbnYuZGF0YVBvc2l0aW9uKTsKICAgICAgICAgIGxlbi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jsKICAgICAgfQogICAgfSk7CiAgICBjaHVua3MuZm9yRWFjaCgoY2h1bmspID0+IHsKICAgICAgaWYgKCFsb3dlc3QgfHwgY2h1bmsubWF4di5jb21wYXJlVG8obG93ZXN0KSA+IDApIHsKICAgICAgICBpZiAobGFzdENodW5rID09PSBudWxsKSB7CiAgICAgICAgICBtZXJnZWRDaHVua3MucHVzaChjaHVuayk7CiAgICAgICAgICBsYXN0Q2h1bmsgPSBjaHVuazsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgaWYgKGNhbk1lcmdlQmxvY2tzKGxhc3RDaHVuaywgY2h1bmspKSB7CiAgICAgICAgICAgIGlmIChjaHVuay5tYXh2LmNvbXBhcmVUbyhsYXN0Q2h1bmsubWF4dikgPiAwKSB7CiAgICAgICAgICAgICAgbGFzdENodW5rLm1heHYgPSBjaHVuay5tYXh2OwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBtZXJnZWRDaHVua3MucHVzaChjaHVuayk7CiAgICAgICAgICAgIGxhc3RDaHVuayA9IGNodW5rOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgfSk7CiAgICByZXR1cm4gbWVyZ2VkQ2h1bmtzOwogIH0KCiAgLy8gbm9kZV9tb2R1bGVzLy5wbnBtL0BnbW9kK3RhYml4QDEuNS4xMS9ub2RlX21vZHVsZXMvQGdtb2QvdGFiaXgvZXNtL3RiaS5qcwogIGluaXRfYnVmZmVyX3NoaW0oKTsKICB2YXIgaW1wb3J0X2xvbmcyID0gX190b01vZHVsZShyZXF1aXJlX2xvbmcoKSk7CgogIC8vIG5vZGVfbW9kdWxlcy8ucG5wbS9AZ21vZCt0YWJpeEAxLjUuMTEvbm9kZV9tb2R1bGVzL0BnbW9kL3RhYml4L2VzbS92aXJ0dWFsT2Zmc2V0LmpzCiAgaW5pdF9idWZmZXJfc2hpbSgpOwogIHZhciBWaXJ0dWFsT2Zmc2V0ID0gY2xhc3MgewogICAgY29uc3RydWN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bmFtZVNlY3Rpb25MZW5ndGg7CiAgICAgIGxldCBmaXJzdERhdGFMaW5lOwogICAgICBjb25zdCBpbmRpY2VzID0gbmV3IEFycmF5KHJlZkNvdW50KS5maWxsKDApLm1hcCgoKSA9PiB7CiAgICAgICAgY29uc3QgYmluQ291bnQgPSBieXRlcy5yZWFkSW50MzJMRShjdXJyT2Zmc2V0KTsKICAgICAgICBjdXJyT2Zmc2V0ICs9IDQ7CiAgICAgICAgY29uc3QgYmluSW5kZXggPSB7fTsKICAgICAgICBsZXQgc3RhdHM7CiAgICAgICAgZm9yIChsZXQgaiA9IDA7IGogPCBiaW5Db3VudDsgaiArPSAxKSB7CiAgICAgICAgICBjb25zdCBiaW4gPSBieXRlcy5yZWFkVUludDMyTEUoY3Vyck9mZnNldCk7CiAgICAgICAgICBjdXJyT2Zmc2V0ICs9IDQ7CiAgICAgICAgICBpZiAoYmluID4gbWF4QmluTnVtYmVyICsgMSkgewogICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IoInRhYml4IGluZGV4IGNvbnRhaW5zIHRvbyBtYW55IGJpbnMsIHBsZWFzZSB1c2UgYSBDU0kgaW5kZXgiKTsKICAgICAgICAgIH0gZWxzZSBpZiAoYmluID09PSBtYXhCaW5OdW1iZXIgKyAxKSB7CiAgICAgICAgICAgIGNvbnN0IGNodW5rQ291bnQgPSBieXRlcy5yZWFkSW50MzJMRShjdXJyT2Zmc2V0KTsKICAgICAgICAgICAgY3Vyck9mZnNldCArPSA0OwogICAgICAgICAgICBpZiAoY2h1bmtDb3VudCA9PT0gMikgewogICAgICAgICAgICAgIHN0YXRzID0gdGhpcy5wYXJzZVBzZXVkb0JpbihieXRlcywgY3Vyck9mZnNldCk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgY3Vyck9mZnNldCArPSAxNiAqIGNodW5rQ291bnQ7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBjb25zdCBjaHVua0NvdW50ID0gYnl0ZXMucmVhZEludDMyTEUoY3Vyck9mZnNldCk7CiAgICAgICAgICAgIGN1cnJPZmZzZXQgKz0gNDsKICAgICAgICAgICAgY29uc3QgY2h1bmtzID0gbmV3IEFycmF5KGNodW5rQ291bnQpOwogICAgICAgICAgICBmb3IgKGxldCBrID0gMDsgayA8IGNodW5rQ291bnQ7IGsgKz0gMSkgewogICAgICAgICAgICAgIGNvbnN0IHUgPSBmcm9tQnl0ZXMoYnl0ZXMsIGN1cnJPZmZzZXQpOwogICAgICAgICAgICAgIGNvbnN0IHYgPSBmcm9tQnl0ZXMoYnl0ZXMsIGN1cnJPZmZzZXQgKyA4KTsKICAgICAgICAgICAgICBjdXJyT2Zmc2V0ICs9IDE2OwogICAgICAgICAgICAgIGZpcnN0RGF0YUxpbmUgPSB0aGlzLl9maW5kRmlyc3REYXRhKGZpcnN0RGF0YUxpbmUsIHUpOwogICAgICAgICAgICAgIGNodW5rc1trXSA9IG5ldyBDaHVuayh1LCB2LCBiaW4pOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGJpbkluZGV4W2Jpbl0gPSBjaHVua3M7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGNvbnN0IGxpbmVhckNvdW50ID0gYnl0ZXMucmVhZEludDMyTEUoY3Vyck9mZnNldCk7CiAgICAgICAgY3Vyck9mZnNldCArPSA0OwogICAgICAgIGNvbnN0IGxpbmVhckluZGV4ID0gbmV3IEFycmF5KGxpbmVhckNvdW50KTsKICAgICAgICBmb3IgKGxldCBrID0gMDsgayA8IGxpbmVhckNvdW50OyBrICs9IDEpIHsKICAgICAgICAgIGxpbmVhckluZGV4W2tdID0gZnJvbUJ5dGVzKGJ5dGVzLCBjdXJyT2Zmc2V0KTsKICAgICAgICAgIGN1cnJPZmZzZXQgKz0gODsKICAgICAgICAgIGZpcnN0RGF0YUxpbmUgPSB0aGlzLl9maW5kRmlyc3REYXRhKGZpcnN0RGF0YUxpbmUsIGxpbmVhckluZGV4W2tdKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJ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4IiwgY3Vyck5hbWVTdGFydCwgaSk7CiAgICAgICAgICAgIHJlZk5hbWUgPSB0aGlzLnJlbmFtZVJlZlNlcShyZWZOYW1lKTsKICAgICAgICAgICAgcmVmSWRUb05hbWVbY3VyclJlZklkXSA9IHJlZk5hbWU7CiAgICAgICAgICAgIHJlZk5hbWVUb0lkW3JlZk5hbWVdID0gY3VyclJlZklkOwogICAgICAgICAgfQogICAgICAgICAgY3Vyck5hbWVTdGFydCA9IGkgKyAxOwogICAgICAgICAgY3VyclJlZklkICs9IDE7CiAgICAgICAgfQogICAgICB9CiAgICAgIHJldHVybiB7IHJlZk5hbWVUb0lkLCByZWZJZFRvTmFtZSB9OwogICAgfQogICAgYXN5bmMgYmxvY2tzRm9yUmFuZ2UocmVmTmFtZSwgbWluLCBtYXgsIG9wdHMgPSB7fSkgewogICAgICBpZiAobWluIDwgMCkgewogICAgICAgIG1pbiA9IDA7CiAgICAgIH0KICAgICAgY29uc3QgaW5kZXhEYXRhID0gYXdhaXQgdGhpcy5wYXJzZShvcHRzKTsKICAgICAgaWYgKCFpbmRleERhdGEpIHsKICAgICAgICByZXR1cm4gW107CiAgICAgIH0KICAgICAgY29uc3QgcmVmSWQgPSBpbmRleERhdGEucmVmTmFtZVRvSWRbcmVmTmFtZV07CiAgICAgIGNvbnN0IGJhID0gaW5kZXhEYXRhLmluZGljZXNbcmVmSWRdOwogICAgICBpZiAoIWJhKSB7CiAgICAgICAgcmV0dXJuIFtdOwogICAgICB9CiAgICAgIGNvbnN0IG1pbk9mZnNldCA9IGJhLmxpbmVhckluZGV4Lmxlbmd0aCA/IGJhLmxpbmVhckluZGV4W21pbiA+PiBUQURfTElEWF9TSElGVCA+PSBiYS5saW5lYXJJbmRleC5sZW5ndGggPyBiYS5saW5lYXJJbmRleC5sZW5ndGggLSAxIDogbWluID4+IFRBRF9MSURYX1NISUZUXSA6IG5ldyBWaXJ0dWFsT2Zmc2V0KDAsIDApOwogICAgICBpZiAoIW1pbk9mZnNldCkgewogICAgICAgIGNvbnNvbGUud2FybigicXVlcnlpbmcgb3V0c2lkZSBvZiBwb3NzaWJsZSB0YWJpeCByYW5nZSIpOwogICAgICB9CiAgICAgIGNvbnN0IG92ZXJsYXBwaW5nQmlucyA9IHJlZzJiaW5zKG1pbiwgbWF4KTsKICAgICAgY29uc3QgY2h1bmtzID0gW107CiAgICAgIGZvciAoY29uc3QgW3N0YXJ0LCBlbmRdIG9mIG92ZXJsYXBwaW5nQmlucykgewogICAgICAgIGZvciAobGV0IGJpbiA9IHN0YXJ0OyBiaW4gPD0gZW5kOyBiaW4rKykgewogICAgICAgICAgaWYgKGJhLmJpbkluZGV4W2Jpbl0pIHsKICAgICAgICAgICAgY29uc3QgYmluQ2h1bmtzID0gYmEuYmluSW5kZXhbYmluXTsKICAgICAgICAgICAgZm9yIChsZXQgYyA9IDA7IGMgPCBiaW5DaHVua3MubGVuZ3RoOyArK2MpIHsKICAgICAgICAgICAgICBjaHVua3MucHVzaChuZXcgQ2h1bmsoYmluQ2h1bmtzW2NdLm1pbnYsIGJpbkNodW5rc1tjXS5tYXh2LCBiaW4pKTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgICBjb25zdCBuaW50diA9IGJhLmxpbmVhckluZGV4Lmxlbmd0aDsKICAgICAgbGV0IGxvd2VzdCA9IG51bGw7CiAgICAgIGNvbnN0IG1pbkxpbiA9IE1hdGgubWluKG1pbiA+PiAxNCwgbmludHYgLSAxKTsKICAgICAgY29uc3QgbWF4TGluID0gTWF0aC5taW4obWF4ID4+IDE0LCBuaW50diAtIDEpOwogICAgICBmb3IgKGxldCBpID0gbWluTGluOyBpIDw9IG1heExpbjsgKytpKSB7CiAgICAgICAgY29uc3QgdnAgPSBiYS5saW5lYXJJbmRleFtpXTsKICAgICAgICBpZiAodnApIHsKICAgICAgICAgIGlmICghbG93ZXN0IHx8IHZwLmNvbXBhcmVUbyhsb3dlc3QpIDwgMCkgewogICAgICAgICAgICBsb3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oaXMucGFyc2VQc2V1ZG9CaW4oYnl0ZXMsIGN1cnJPZmZzZXQgKyA0KTsKICAgICAgICAgICAgY3Vyck9mZnNldCArPSA0ICsgOCArIDQgKyAxNiArIDE2OwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgY29uc3QgbG9mZnNldCA9IGZyb21CeXRlcyhieXRlcywgY3Vyck9mZnNldCArIDQpOwogICAgICAgICAgICBmaXJzdERhdGFMaW5lID0gdGhpcy5fZmluZEZpcnN0RGF0YShmaXJzdERhdGFMaW5lLCBsb2Zmc2V0KTsKICAgICAgICAgICAgY29uc3QgY2h1bmtDb3VudCA9IGJ5dGVzLnJlYWRJbnQzMkxFKGN1cnJPZmZzZXQgKyAxMik7CiAgICAgICAgICAgIGN1cnJPZmZzZXQgKz0gMTY7CiAgICAgICAgICAgIGNvbnN0IGNodW5rcyA9IG5ldyBBcnJheShjaHVua0NvdW50KTsKICAgICAgICAgICAgZm9yIChsZXQgayA9IDA7IGsgPCBjaHVua0NvdW50OyBrICs9IDEpIHsKICAgICAgICAgICAgICBjb25zdCB1ID0gZnJvbUJ5dGVzKGJ5dGVzLCBjdXJyT2Zmc2V0KTsKICAgICAgICAgICAgICBjb25zdCB2ID0gZnJvbUJ5dGVzKGJ5dGVzLCBjdXJyT2Zmc2V0ICsgOCk7CiAgICAgICAgICAgICAgY3Vyck9mZnNldCArPSAxNjsKICAgICAgICAgICAgICBjaHVua3Nba10gPSBuZXcgQ2h1bmsodSwgdiwgYmluKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBiaW5JbmRleFtiaW5dID0gY2h1bmtzOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4geyBiaW5JbmRleCwgc3RhdHMgfTsKICAgICAgfSk7CiAgICAgIHJldHVybiB7CiAgICAgICAgLi4uYXV4LAogICAgICAgIGNzaTogdHJ1ZSwKICAgICAgICByZWZDb3VudCwKICAgICAgICBtYXhCbG9ja1NpemU6IDEgPDwgMTYsCiAgICAgICAgZmlyc3REYXRhTGluZSwKICAgICAgICBjc2lWZXJzaW9uLAogICAgICAgIGluZGljZXMsCiAgICAgICAgZGVwdGg6IHRoaXMuZGVwdGgsCiAgICAgICAgbWF4QmluTnVtYmVyOiB0aGlzLm1heEJpbk51bWJlciwKICAgICAgICBtYXhSZWZMZW5ndGgKICAgICAgfTsKICAgIH0KICAgIHBhcnNlUHNldWRvQmluKGJ5dGVzLCBvZmZzZXQpIHsKICAgICAgY29uc3QgbGluZUNvdW50ID0gbG9uZ1RvTnVtYmVyKGltcG9ydF9sb25nMy5kZWZhdWx0LmZyb21CeXRlc0xFKGJ5dGVzLnNsaWNlKG9mZnNldCArIDI4LCBvZmZzZXQgKyAzNiksIHRydWUpKTsKICAgICAgcmV0dXJuIHsgbGluZUNvdW50IH07CiAgICB9CiAgICBhc3luYyBibG9ja3NGb3JSYW5nZShyZWZOYW1lLCBtaW4sIG1heCwgb3B0cyA9IHt9KSB7CiAgICAgIGlmIChtaW4gPCAwKSB7CiAgICAgICAgbWluID0gMDsKICAgICAgfQogICAgICBjb25zdCBpbmRleERhdGEgPSBhd2FpdCB0aGlzLnBhcnNlKG9wdHMpOwogICAgICBpZiAoIWluZGV4RGF0YSkgewogICAgICAgIHJldHVybiBbXTsKICAgICAgfQogICAgICBjb25zdCByZWZJZCA9IGluZGV4RGF0YS5yZWZOYW1lVG9JZFtyZWZOYW1lXTsKICAgICAgY29uc3QgYmEgPSBpbmRleERhdGEuaW5kaWNlc1tyZWZJZF07CiAgICAgIGlmICghYmEpIHsKICAgICAgICByZXR1cm4gW107CiAgICAgIH0KICAgICAgY29uc3Qgb3ZlcmxhcHBpbmdCaW5zID0gdGhpcy5yZWcyYmlucyhtaW4sIG1heCk7CiAgICAgIGNvbnN0IGNodW5rcyA9IFtdOwogICAgICBmb3IgKGNvbnN0IFtzdGFydCwgZW5kXSBvZiBvdmVybGFwcGluZ0JpbnMpIHsKICAgICAgICBmb3IgKGxldCBiaW4gPSBzdGFydDsgYmluIDw9IGVuZDsgYmluKyspIHsKICAgICAgICAgIGlmIChiYS5iaW5JbmRleFtiaW5dKSB7CiAgICAgICAgICAgIGNvbnN0IGJpbkNodW5rcyA9IGJhLmJpbkluZGV4W2Jpbl07CiAgICAgICAgICAgIGZvciAobGV0IGMgPSAwOyBjIDwgYmluQ2h1bmtzLmxlbmd0aDsgKytjKSB7CiAgICAgICAgICAgICAgY2h1bmtzLnB1c2gobmV3IENodW5rKGJpbkNodW5rc1tjXS5taW52LCBiaW5DaHVua3NbY10ubWF4diwgYmluKSk7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgICAgcmV0dXJuIG9wdGltaXplQ2h1bmtzKGNodW5rcywgbmV3IFZpcnR1YWxPZmZzZXQoMCwgMCkpOwogICAgfQogICAgcmVnMmJpbnMoYmVnLCBlbmQpIHsKICAgICAgYmVnIC09IDE7CiAgICAgIGlmIChiZWcgPCAxKSB7CiAgICAgICAgYmVnID0gMTsKICAgICAgfQogICAgICBpZiAoZW5kID4gMiAqKiA1MCkgewogICAgICAgIGVuZCA9IDIgKiogMzQ7CiAgICAgIH0KICAgICAgZW5kIC09IDE7CiAgICAgIGxldCBsID0gMDsKICAgICAgbGV0IHQgPSAwOwogICAgICBsZXQgcyA9IHRoaXMubWluU2hpZnQgKyB0aGlzLmRlcHRoICogMzsKICAgICAgY29uc3QgYmlucyA9IFtdOwogICAgICBmb3IgKDsgbCA8PSB0aGlzLmRlcHRoOyBzIC09IDMsIHQgKz0gbHNoaWZ0KDEsIGwgKiAzKSwgbCArPSAxKSB7CiAgICAgICAgY29uc3QgYiA9IHQgKyByc2hpZnQoYmVnLCBzKTsKICAgICAgICBjb25zdCBlID0gdCArIHJzaGlmdChlbmQsIHMpOwogICAgICAgIGlmIChlIC0gYiArIGJpbnMubGVuZ3RoID4gdGhpcy5tYXhCaW5OdW1iZXIpIHsKICAgICAgICAgIHRocm93IG5ldyBFcnJvcihgcXVlcnkgJHtiZWd9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ICAgICAgfSBlbHNlIHsKICAgICAgICBvcHRpb25zID0gb3B0czsKICAgICAgICBjYWxsYmFjayA9IG9wdHMubGluZUNhbGxiYWNrOwogICAgICB9CiAgICAgIGlmIChyZWZOYW1lID09PSB2b2lkIDApIHsKICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCJtdXN0IHByb3ZpZGUgYSByZWZlcmVuY2Ugc2VxdWVuY2UgbmFtZSIpOwogICAgICB9CiAgICAgIGlmICghY2FsbGJhY2spIHsKICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCJsaW5lIGNhbGxiYWNrIG11c3QgYmUgcHJvdmlkZWQiKTsKICAgICAgfQogICAgICBjb25zdCBtZXRhZGF0YSA9IGF3YWl0IHRoaXMuaW5kZXguZ2V0TWV0YWRhdGEob3B0aW9ucyk7CiAgICAgIGNoZWNrQWJvcnRTaWduYWwoc2lnbmFsKTsKICAgICAgaWYgKCFzdGFydCkgewogICAgICAgIHN0YXJ0ID0gMDsKICAgICAgfQogICAgICBpZiAoIWVuZCkgewogICAgICAgIGVuZCA9IG1ldGFkYXRhLm1heFJlZkxlbmd0aDsKICAgICAgfQogICAgICBpZiAoIShzdGFydCA8PSBlbmQpKSB7CiAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcigiaW52YWxpZCBzdGFydCBhbmQgZW5kIGNvb3JkaW5hdGVzLiBzdGFydCBtdXN0IGJlIGxlc3MgdGhhbiBvciBlcXVhbCB0byBlbmQiKTsKICAgICAgfQogICAgICBpZiAoc3RhcnQgPT09IGVuZCkgewogICAgICAgIHJldHVybjsKICAgICAgfQogICAgICBjb25zdCBjaHVua3MgPSBhd2FpdCB0aGlzLmluZGV4LmJsb2Nrc0ZvclJhbmdlKHJlZk5hbWUsIHN0YXJ0LCBlbmQsIG9wdGlvbnMpOwogICAgICBjaGVja0Fib3J0U2lnbmFsKHNpZ25hbCk7CiAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgY2h1bmtzLmxlbmd0aDsgaSArPSAxKSB7CiAgICAgICAgY29uc3Qgc2l6ZSA9IGNodW5rc1tpXS5mZXRjaGVkU2l6ZSgpOwogICAgICAgIGlmIChzaXplID4gdGhpcy5jaHVua1NpemVMaW1pdCkgewogICAgICAgICAgdGhyb3cgbmV3IEVycm9yKGBUb28gbXVjaCBkYXRhLiBDaHVuayBzaXplICR7c2l6ZS50b0xvY2FsZVN0cmluZygpfSBieXRlcyBleGNlZWRzIGNodW5rU2l6ZUxpbWl0IG9mICR7dGhpcy5jaHVua1NpemVMaW1pdC50b0xvY2FsZVN0cmluZygpfS5gKTsKICAgICAgICB9CiAgICAgIH0KICAgICAgbGV0IGxhc3QgPSBEYXRlLm5vdygpOwogICAgICBmb3IgKGxldCBjaHVua051bSA9IDA7IGNodW5rTnVtIDwgY2h1bmtzLmxlbmd0aDsgY2h1bmtOdW0gKz0gMSkgewogICAgICAgIGxldCBwcmV2aW91c1N0YXJ0Q29vcmRpbmF0ZTsKICAgICAgICBjb25zdCBjID0gY2h1bmtzW2NodW5rTnVtXTsKICAgICAgICBjb25zdCB7IGJ1ZmZlciwgY3Bvc2l0aW9ucywgZHBvc2l0aW9ucyB9ID0gYXdhaXQgdGhpcy5jaHVua0NhY2hlLmdldChjLnRvU3RyaW5nKCksIGMpOwogICAgICAgIGNoZWNrQWJvcnRTaWduYWwoc2lnbmFsKTsKICAgICAgICBsZXQgYmxvY2tTdGFydCA9IDA7CiAgICAgICAgbGV0IHBvcyA9IDA7CiAgICAgICAgd2hpbGUgKGJsb2NrU3RhcnQgPCBidWZmZXIubGVuZ3RoKSB7CiAgICAgICAgICBjb25zdCBuID0gYnVmZmVyLmluZGV4T2YoIlxuIiwgYmxvY2tTdGFydCk7CiAgICAgICAgICBpZiAobiA9PT0gLTEpIHsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICB9CiAgICAgICAgICBjb25zdCBiID0gYnVmZmVyLnNsaWNlKGJsb2NrU3RhcnQsIG4pOwogICAgICAgICAgY29uc3QgbG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ICAgIH0gZWxzZSBpZiAoc3RhcnRDb29yZGluYXRlICE9PSB2b2lkIDAgJiYgc3RhcnRDb29yZGluYXRlID49IGVuZCkgewogICAgICAgICAgICByZXR1cm47CiAgICAgICAgICB9CiAgICAgICAgICBpZiAodGhpcy55aWVsZFRpbWUgJiYgbGFzdCAtIERhdGUubm93KCkgPiB0aGlzLnlpZWxkVGltZSkgewogICAgICAgICAgICBsYXN0ID0gRGF0ZS5ub3coKTsKICAgICAgICAgICAgY2hlY2tBYm9ydFNpZ25hbChzaWduYWwpOwogICAgICAgICAgICBhd2FpdCB0aW1lb3V0KDEpOwogICAgICAgICAgfQogICAgICAgICAgYmxvY2tTdGFydCA9IG4gKyAxOwogICAgICAgIH0KICAgICAgfQogICAgfQogICAgYXN5bmMgZ2V0TWV0YWRhdGEob3B0cyA9IHt9KSB7CiAgICAgIHJldHVybiB0aGlzLmluZGV4LmdldE1ldGFkYXRhKG9wdHMpOwogICAgfQogICAgYXN5bmMgZ2V0SGVhZGVyQnVmZmVyKG9wdHMgPSB7fSkgewogICAgICBjb25zdCB7IGZpcnN0RGF0YUxpbmUsIG1ldGFDaGFyLCBtYXhCbG9ja1NpemUgfSA9IGF3YWl0IHRoaXMuZ2V0TWV0YWRhdGEob3B0cyk7CiAgICAgIGNoZWNrQWJvcnRTaWduYWwob3B0cy5zaWduYWwpOwogICAgICBjb25zdCBtYXhGZXRjaCA9ICgoZmlyc3REYXRhTGluZSA9PT0gbnVsbCB8fCBmaXJzdERhdGFMaW5lID09PSB2b2lkIDAgPyB2b2lkIDAgOiBmaXJzdERhdGFMaW5lLmJsb2NrUG9zaXRpb24pIHx8IDApICsgbWF4QmxvY2tTaXplOwogICAgICBsZXQgYnl0ZXMgPSBhd2FpdCB0aGlzLl9yZWFkUmVnaW9uKDAsIG1heEZldGNoLCBvcHRzKTsKICAgICAgY2hlY2tBYm9ydFNpZ25hbChvcHRzLnNpZ25hbCk7CiAgICAgIHRyeSB7CiAgICAgICAgYnl0ZXMg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EgPSBhd2FpdCB0aGlzLmdldE1ldGFkYXRhKG9wdHMpOwogICAgICByZXR1cm4gbWV0YWRhdGEucmVmSWRUb05hbWU7CiAgICB9CiAgICBjaGVja0xpbmUobWV0YWRhdGEsIHJlZ2lvblJlZk5hbWUsIHJlZ2lvblN0YXJ0LCByZWdpb25FbmQsIGxpbmUpIHsKICAgICAgY29uc3QgeyBjb2x1bW5OdW1iZXJzLCBtZXRhQ2hhciwgY29vcmRpbmF0ZVR5cGUsIGZvcm1hdCB9ID0gbWV0YWRhdGE7CiAgICAgIGlmIChsaW5lLmNoYXJBdCgwKSA9PT0gbWV0YUNoYXIpIHsKICAgICAgICByZXR1cm4geyBvdmVybGFwczogZmFsc2UgfTsKICAgICAgfQogICAgICBsZXQgeyByZWYsIHN0YXJ0LCBlbmQgfSA9IGNvbHVtbk51bWJlcnM7CiAgICAgIGlmICghcmVmKSB7CiAgICAgICAgcmVmID0gMDsKICAgICAgfQogICAgICBpZiAoIXN0YXJ0KSB7CiAgICAgICAgc3RhcnQgPSAwOwogICAgICB9CiAgICAgIGlmICghZW5kKSB7CiAgICAgICAgZW5kID0gMDsKICAgICAgfQogICAgICBpZiAoZm9ybWF0ID09PSAiVkNGIikgewogICAgICAgIGVuZCA9IDg7CiAgICAgIH0KICAgICAgY29uc3QgbWF4Q29sdW1uID0gTWF0aC5tYXgocmVmLCBzdGFydCwgZW5kKTsKICAgICAgbGV0IGN1cnJlbnRDb2x1bW5OdW1iZXIgPSAxOwogICAgICBsZXQgY3VycmVudENvbHVtblN0YXJ0ID0gMDsKICAgICAgbGV0IHJlZlNlcSA9ICIiOwogICAgICBsZXQgc3RhcnRDb29yZGluYXRlID0gLUluZmluaXR5OwogICAgICBmb3IgKGxldCBpID0gMDsgaSA8IGxpbmUubGVuZ3RoICsgMTsgaSArPSAxKSB7CiAgICAgICAgaWYgKGxpbmVbaV0gPT09ICIJIiB8fCBpID09PSBsaW5lLmxlbmd0aCkgewogICAgICAgICAgaWYgKGN1cnJlbnRDb2x1bW5OdW1iZXIgPT09IHJlZikgewogICAgICAgICAgICBpZiAodGhpcy5yZW5hbWVSZWZTZXEobGluZS5zbGljZShjdXJyZW50Q29sdW1uU3RhcnQsIGkpKSAhPT0gcmVnaW9uUmVmTmFtZSkgewogICAgICAgICAgICAgIHJldHVybiB7IG92ZXJsYXBzOiBmYWxzZSB9OwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgaWYgKGN1cnJlbnRDb2x1bW5OdW1iZXIgPT09IHN0YXJ0KSB7CiAgICAgICAgICAgIHN0YXJ0Q29vcmRpbmF0ZSA9IHBhcnNlSW50KGxpbmUuc2xpY2UoY3VycmVudENvbHVtblN0YXJ0LCBpKSwgMTApOwogICAgICAgICAgICBpZiAoY29vcmRpbmF0ZVR5cGUgPT09ICIxLWJhc2VkLWNsb3NlZCIpIHsKICAgICAgICAgICAgICBzdGFydENvb3JkaW5hdGUgLT0gMTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoc3RhcnRDb29yZGluYXRlID49IHJlZ2lvbkVuZCkgewogICAgICAgICAgICAgIHJldHVybiB7IHN0YXJ0Q29vcmRpbmF0ZSwgb3ZlcmxhcHM6IGZhbHNlIH07CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKGVuZCA9PT0gMCB8fCBlbmQgPT09IHN0YXJ0KSB7CiAgICAgICAgICAgICAgaWYgKHN0YXJ0Q29vcmRpbmF0ZSArIDEgPD0gcmVnaW9uU3RhcnQpIHsKICAgICAgICAgICAgICAgIHJldHVybiB7IHN0YXJ0Q29vcmRpbmF0ZSwgb3ZlcmxhcHM6IGZhbHNlIH07CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgaWYgKGZvcm1hdCA9PT0gIlZDRiIgJiYgY3VycmVudENvbHVtbk51bWJlciA9PT0gNCkgewogICAgICAgICAgICByZWZTZXEgPSBsaW5lLnNsaWNlKGN1cnJlbnRDb2x1bW5TdGFydCwgaSk7CiAgICAgICAgICB9IGVsc2UgaWYgKGN1cnJlbnRDb2x1bW5OdW1iZXIgPT09IGVuZCkgewogICAgICAgICAgICBsZXQgZW5kQ29vcmRpbmF0ZTsKICAgICAgICAgICAgaWYgKGZvcm1hdCA9PT0gIlZDRiIpIHsKICAgICAgICAgICAgICBlbmRDb29yZGluYXRlID0gdGhpcy5fZ2V0VmNmRW5kKHN0YXJ0Q29vcmRpbmF0ZSwgcmVmU2VxLCBsaW5lLnNsaWNlKGN1cnJlbnRDb2x1bW5TdGFydCwgaSkpOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIGVuZENvb3JkaW5hdGUgPSBwYXJzZUludChsaW5lLnNsaWNlKGN1cnJlbnRDb2x1bW5TdGFydCwgaSksIDEwKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoZW5kQ29vcmRpbmF0ZSA8PSByZWdpb25TdGFydCkgewogICAgICAgICAgICAgIHJldHVybiB7IG92ZXJsYXBzOiBmYWxzZSB9OwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBjdXJyZW50Q29sdW1uU3RhcnQgPSBpICsgMTsKICAgICAgICAgIGN1cnJlbnRDb2x1bW5OdW1iZXIgKz0gMTsKICAgICAgICAgIGlmIChjdXJyZW50Q29sdW1uTnVtYmVyID4gbWF4Q29sdW1uKSB7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgICByZXR1cm4geyBzdGFydENvb3JkaW5hdGUsIG92ZXJsYXBzOiB0cnVlIH07CiAgICB9CiAgICBfZ2V0VmNmRW5kKHN0YXJ0Q29vcmRpbmF0ZSwgcmVmU2VxLCBpbmZvKSB7CiAgICAgIGxldCBlbmRDb29yZGluYXRlID0gc3RhcnRDb29yZGluYXRlICsgcmVmU2VxLmxlbmd0aDsKICAgICAgY29uc3QgaXNUUkEgPSBpbmZvLmluZGV4T2YoIlNWVFlQRT1UUkEiKSAhPT0gLTE7CiAgICAgIGlmIChpbmZvWzBdICE9PSAiLiIgJiYgIWlzVFJBKSB7CiAgICAgICAgbGV0IHByZXZDaGFyID0gIjsiOwogICAgICAgIGZvciAobGV0IGogPSAwOyBqIDwgaW5mby5sZW5ndGg7IGogKz0gMSkgewogICAgICAgICAgaWYgKHByZXZDaGFyID09PSAiOyIgJiYgaW5mby5zbGljZShqLCBqICsgNCkgPT09ICJFTkQ9IikgewogICAgICAgICAgICBsZXQgdmFsdWVFbmQgPSBpbmZvLmluZGV4T2YoIjsiLCBqKTsKICAgICAgICAgICAgaWYgKHZhbHVlRW5kID09PSAtMSkgewogICAgICAgICAgICAgIHZhbHVlRW5kID0gaW5mby5sZW5ndGg7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZW5kQ29vcmRpbmF0ZSA9IHBhcnNlSW50KGluZm8uc2xpY2UoaiArIDQsIHZhbHVlRW5kKSwgMTApOwogICAgICAgICAgICBicmVhazsKICAgICAgICAgIH0KICAgICAgICAgIHByZXZDaGFyID0gaW5mb1tqXTsKICAgICAgICB9CiAgICAgIH0gZWxzZSBpZiAoaXNUUkEpIHsKICAgICAgICByZXR1cm4gc3RhcnRDb29yZGluYXRlICsgMTsKICAgICAgfQogICAgICByZXR1cm4gZW5kQ29vcmRpbmF0ZTsKICAgIH0KICAgIGFzeW5jIGxpbmVDb3VudChyZWZOYW1lLCBvcHRzID0ge30pIHsKICAgICAgcmV0dXJuIHRoaXMuaW5kZXgubGluZUNvdW50KHJlZk5hbWUsIG9wdHMpOwogICAgfQogICAgYXN5bmMgX3JlYWRSZWdpb24ocG9zLCBzaXplLCBvcHRzID0ge30pIHsKICAgICAgY29uc3QgYiA9IGltcG9ydF9idWZmZXI3LkJ1ZmZlci5hbGxvYyhzaXplKTsKICAgICAgY29uc3QgeyBieXRlc1JlYWQsIGJ1ZmZlciB9ID0gYXdhaXQgdGhpcy5maWxlaGFuZGxlLnJlYWQoYiwgMCwgc2l6ZSwgcG9zLCBvcHRzKTsKICAgICAgc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IKICAgICAgfSwKICAgICAgQlE6IHsKICAgICAgICBOdW1iZXI6IDEsCiAgICAgICAgVHlwZTogIkZsb2F0IiwKICAgICAgICBEZXNjcmlwdGlvbjogIlJNUyBiYXNlIHF1YWxpdHkiCiAgICAgIH0sCiAgICAgIENJR0FSOiB7CiAgICAgICAgTnVtYmVyOiAxLAogICAgICAgIFR5cGU6ICJGbG9hdCIsCiAgICAgICAgRGVzY3JpcHRpb246ICJDaWdhciBzdHJpbmcgZGVzY3JpYmluZyBob3cgdG8gYWxpZ24gYW4gYWx0ZXJuYXRlIGFsbGVsZSB0byB0aGUgcmVmZXJlbmNlIGFsbGVsZSIKICAgICAgfSwKICAgICAgREI6IHsKICAgICAgICBOdW1iZXI6IDAsCiAgICAgICAgVHlwZTogIkZsYWciLAogICAgICAgIERlc2NyaXB0aW9uOiAiZGJTTlAgbWVtYmVyc2hpcCIKICAgICAgfSwKICAgICAgRFA6IHsKICAgICAgICBOdW1iZXI6IDEsCiAgICAgICAgVHlwZTogIkludGVnZXIiLAogICAgICAgIERlc2NyaXB0aW9uOiAiY29tYmluZWQgZGVwdGggYWNyb3NzIHNhbXBsZXMiCiAgICAgIH0sCiAgICAgIEVORDogewogICAgICAgIE51bWJlcjogMSwKICAgICAgICBUeXBlOiAiSW50ZWdlciIsCiAgICAgICAgRGVzY3JpcHRpb246ICJFbmQgcG9zaXRpb24gKGZvciB1c2Ugd2l0aCBzeW1ib2xpYyBhbGxlbGVzKSIKICAgICAgfSwKICAgICAgSDI6IHsKICAgICAgICBOdW1iZXI6IDAsCiAgICAgICAgVHlwZTogIkZsYWciLAogICAgICAgIERlc2NyaXB0aW9uOiAiSGFwTWFwMiBtZW1iZXJzaGlwIgogICAgICB9LAogICAgICBIMzogewogICAgICAgIE51bWJlcjogMCwKICAgICAgICBUeXBlOiAiRmxhZyIsCiAgICAgICAgRGVzY3JpcHRpb246ICJIYXBNYXAzIG1lbWJlcnNoaXAiCiAgICAgIH0sCiAgICAgIE1ROiB7CiAgICAgICAgTnVtYmVyOiAxLAogICAgICAgIFR5cGU6IG51bGwsCiAgICAgICAgRGVzY3JpcHRpb246ICJSTVMgbWFwcGluZyBxdWFsaXR5IgogICAgICB9LAogICAgICBNUTA6IHsKICAgICAgICBOdW1iZXI6IDEsCiAgICAgICAgVHlwZTogIkludGVnZXIiLAogICAgICAgIERlc2NyaXB0aW9uOiAiTnVtYmVyIG9mIE1BUFEgPT0gMCByZWFkcyIKICAgICAgfSwKICAgICAgTlM6IHsKICAgICAgICBOdW1iZXI6IDEsCiAgICAgICAgVHlwZTogIkludGVnZXIiLAogICAgICAgIERlc2NyaXB0aW9uOiAiTnVtYmVyIG9mIHNhbXBsZXMgd2l0aCBkYXRhIgogICAgICB9LAogICAgICBTQjogewogICAgICAgIE51bWJlcjogNCwKICAgICAgICBUeXBlOiAiSW50ZWdlciIsCiAgICAgICAgRGVzY3JpcHRpb246ICJTdHJhbmQgYmlhcyIKICAgICAgfSwKICAgICAgU09NQVRJQzogewogICAgICAgIE51bWJlcjogMCwKICAgICAgICBUeXBlOiAiRmxhZyIsCiAgICAgICAgRGVzY3JpcHRpb246ICJTb21hdGljIG11dGF0aW9uIChmb3IgY2FuY2VyIGdlbm9taWNzKSIKICAgICAgfSwKICAgICAgVkFMSURBVEVEOiB7CiAgICAgICAgTnVtYmVyOiAwLAogICAgICAgIFR5cGU6ICJGbGFnIiwKICAgICAgICBEZXNjcmlwdGlvbjogIlZhbGlkYXRlZCBieSBmb2xsb3ctdXAgZXhwZXJpbWVudCIKICAgICAgfSwKICAgICAgIjEwMDBHIjogewogICAgICAgIE51bWJlcjogMCwKICAgICAgICBUeXBlOiAiRmxhZyIsCiAgICAgICAgRGVzY3JpcHRpb246ICIxMDAwIEdlbm9tZXMgbWVtYmVyc2hpcCIKICAgICAgfSwKICAgICAgSU1QUkVDSVNFOiB7CiAgICAgICAgTnVtYmVyOiAwLAogICAgICAgIFR5cGU6ICJGbGFnIiwKICAgICAgICBEZXNjcmlwdGlvbjogIkltcHJlY2lzZSBzdHJ1Y3R1cmFsIHZhcmlhdGlvbiIKICAgICAgfSwKICAgICAgTk9WRUw6IHsKICAgICAgICBOdW1iZXI6IDAsCiAgICAgICAgVHlwZTogIkZsYWciLAogICAgICAgIERlc2NyaXB0aW9uOiAiSW5kaWNhdGVzIGEgbm92ZWwgc3RydWN0dXJhbCB2YXJpYXRpb24iCiAgICAgIH0sCiAgICAgIFNWVFlQRTogewogICAgICAgIE51bWJlcjogMSwKICAgICAgICBUeXBlOiAiU3RyaW5nIiwKICAgICAgICBEZXNjcmlwdGlvbjogIlR5cGUgb2Ygc3RydWN0dXJhbCB2YXJpYW50IgogICAgICB9LAogICAgICBTVkxFTjogewogICAgICAgIE51bWJlcjogbnVsbCwKICAgICAgICBUeXBlOiAiSW50ZWdlciIsCiAgICAgICAgRGVzY3JpcHRpb246ICJEaWZmZXJlbmNlIGluIGxlbmd0aCBiZXR3ZWVuIFJFRiBhbmQgQUxUIGFsbGVsZXMiCiAgICAgIH0sCiAgICAgIENJUE9TOiB7CiAgICAgICAgTnVtYmVyOiAyLAogICAgICAgIFR5cGU6ICJJbnRlZ2VyIiwKICAgICAgICBEZXNjcmlwdGlvbjogIkNvbmZpZGVuY2UgaW50ZXJ2YWwgYXJvdW5kIFBPUyBmb3IgaW1wcmVjaXNlIHZhcmlhbnRzIgogICAgICB9LAogICAgICBDSUVORDogewogICAgICAgIE51bWJlcjogMiwKICAgICAgICBUeXBlOiAiSW50ZWdlciIsCiAgICAgICAgRGVzY3JpcHRpb246ICJDb25maWRlbmNlIGludGVydmFsIGFyb3VuZCBFTkQgZm9yIGltcHJlY2lzZSB2YXJpYW50cyIKICAgICAgfSwKICAgICAgSE9NTEVOOiB7CiAgICAgICAgVHlwZTogIkludGVnZXIiLAogICAgICAgIERlc2NyaXB0aW9uOiAiTGVuZ3RoIG9mIGJhc2UgcGFpciBpZGVudGljYWwgbWljcm8taG9tb2xvZ3kgYXQgZXZlbnQgYnJlYWtwb2ludHMiCiAgICAgIH0sCiAgICAgIEhPTVNFUTogewogICAgICAgIFR5cGU6ICJTdHJpbmciLAogICAgICAgIERlc2NyaXB0aW9uOiAiU2VxdWVuY2Ugb2YgYmFzZSBwYWlyIGlkZW50aWNhbCBtaWNyby1ob21vbG9neSBhdCBldmVudCBicmVha3BvaW50cyIKICAgICAgfSwKICAgICAgQktQVElEOiB7CiAgICAgICAgVHlwZTogIlN0cmluZyIsCiAgICAgICAgRGVzY3JpcHRpb246ICJJRCBvZiB0aGUgYXNzZW1ibGVkIGFsdGVybmF0ZSBhbGxlbGUgaW4gdGhlIGFzc2VtYmx5IGZpbGUiCiAgICAgIH0sCiAgICAgIE1FSU5GTzogewogICAgICAgIE51bWJlcjogNCwKICAgICAgICBUeXBlOiAiU3RyaW5nIiwKICAgICAgICBEZXNjcmlwdGlvbjogIk1vYmlsZSBlbGVtZW50IGluZm8gb2YgdGhlIGZvcm0gTkFNRSxTVEFSVCxFTkQsUE9MQVJJVFkiCiAgICAgIH0sCiAgICAgIE1FVFJBTlM6IHsKICAgICAgICBOdW1iZXI6IDQsCiAgICAgICAgVHlwZTogIlN0cmluZyIsCiAgICAgICAgRGVzY3JpcHRpb246ICJNb2JpbGUgZWxlbWVudCB0cmFuc2R1Y3Rpb24gaW5mbyBvZiB0aGUgZm9ybSBDSFIsU1RBUlQsRU5ELFBPTEFSSVRZIgogICAgICB9LAogICAgICBER1ZJRDogewogICAgICAgIE51bWJlcjogMSwKICAgICAgICBUeXBlOiAiU3RyaW5nIiwKICAgICAgICBEZXNjcmlwdGlvbjogIklEIG9mIHRoaXMgZWxlbWVudCBpbiBEYXRhYmFzZSBvZiBHZW5vbWljIFZhcmlhdGlvbiIKICAgICAgfSwKICAgICAgREJWQVJJRDogewogICAgICAgIE51bWJlcjogMSwKICAgICAgICBUeXBlOiAiU3RyaW5nIiwKICAgICAgICBEZXNjcmlwdGlvbjogIklEIG9mIHRoaXMgZWxlbWVudCBpbiBEQlZBUiIKICAgICAgfSwKICAgICAgREJSSVBJRDogewogICAgICAgIE51bWJlcjogMSwKICAgICAgICBUeXBlOiAiU3RyaW5nIiwKICAgICAgICBEZXNjcmlwdGlvbjogIklEIG9mIHRoaXMgZWxlbWVudCBpbiBEQlJJUCIKICAgICAgfSwKICAgICAgTUFURUlEOiB7CiAgICAgICAgTnVtYmVyOiBudWxsLAogICAgICAgIFR5cGU6ICJTdHJpbmciLAogICAgICAgIERlc2NyaXB0aW9uOiAiSUQgb2YgbWF0ZSBicmVha2VuZHMiCiAgICAgIH0sCiAgICAgIFBBUklEOiB7CiAgICAgICAgTnVtYmVyOiAxLAogICAgICAgIFR5cGU6ICJTdHJpbmciLAogICAgICAgIERlc2NyaXB0aW9uOiAiSUQgb2YgcGFydG5lciBicmVha2VuZCIKICAgICAgfSwKICAgICAgRVZFTlQ6IHsKICAgICAgICBOdW1iZXI6IDEsCiAgICAgICAgVHlwZTogIlN0cmluZyIsCiAgICAgICAgRGVzY3JpcHRpb246ICJJRCBvZiBldmVudCBhc3NvY2lhdGVkIHRvIGJyZWFrZW5kIgogICAgICB9LAogICAgICBDSUxFTjogewogICAgICAgIE51bWJlcjogMiwKICAgICAgICBUeXBlOiAiSW50ZWdlciIsCiAgICAgICAgRGVzY3JpcHRpb246ICJDb25maWRlbmNlIGludGVydmFsIGFyb3VuZCB0aGUgaW5zZXJ0ZWQgbWF0ZXJpYWwgYmV0d2VlbiBicmVha2VuZCIKICAgICAgfSwKICAgICAgRFBBREo6IHsgVHlwZTogIkludGVnZXIiLCBEZXNjcmlwdGlvbjogIlJlYWQgRGVwdGggb2YgYWRqYWNlbmN5IiB9LAogICAgICBDTjogewogICAgICAgIE51bWJlcjogMSwKICAgICAgICBUeXBlOiAiSW50ZWdlciIsCiAgICAgICAgRGVzY3JpcHRpb246ICJDb3B5IG51bWJlciBvZiBzZWdtZW50IGNvbnRhaW5pbmcgYnJlYWtlbmQiCiAgICAgIH0sCiAgICAgIENOQURKOiB7CiAgICAgICAgTnVtYmVyOiBudWxsLAogICAgICAgIFR5cGU6ICJJbnRlZ2VyIiwKICAgICAgICBEZXNjcmlwdGlvbjogIkNvcHkgbnVtYmVyIG9mIGFkamFjZW5jeSIKICAgICAgfSwKICAgICAgQ0lDTjogewogICAgICAgIE51bWJlcjogMiwKICAgICAgICBUeXBlOiAiSW50ZWdlciIsCiAgICAgICAgRGVzY3JpcHRpb246ICJDb25maWRlbmNlIGludGVydmFsIGFyb3VuZCBjb3B5IG51bWJlciBmb3IgdGhlIHNlZ21lbnQiCiAgICAgIH0sCiAgICAgIENJQ05BREo6IHsKICAgICAgICBOdW1iZXI6IG51bGwsCiAgICAgICAgVHlwZTogIkludGVnZXIiLAogICAgICAgIERlc2NyaXB0aW9uOiAiQ29uZmlkZW5jZSBpbnRlcnZhbCBhcm91bmQgY29weSBudW1iZXIgZm9yIHRoZSBhZGphY2VuY3kiCiAgICAgIH0KICAgIH0sCiAgICBHZW5vdHlwZUZpZWxkczogewogICAgICBBRDogewogICAgICAgIE51bWJlcjogIlIiLAogICAgICAgIFR5cGU6ICJJbnRlZ2VyIiwKICAgICAgICBEZXNjcmlwdGlvbjogIlJlYWQgZGVwdGggZm9yIGVhY2ggYWxsZWxlIgogICAgICB9LAogICAgICBBREY6IHsKICAgICAgICBOdW1iZXI6ICJSIiwKICAgICAgICBUeXBlOiAiSW50ZWdlciIsCiAgICAgICAgRGVzY3JpcHRpb246ICJSZWFkIGRlcHRoIGZvciBlYWNoIGFsbGVsZSBvbiB0aGUgZm9yd2FyZCBzdHJhbmQiCiAgICAgIH0sCiAgICAgIEFEUjogewogICAgICAgIE51bWJlcjogIlIiLAogICAgICAgIFR5cGU6ICJJbnRlZ2VyIiwKICAgICAgICBEZXNjcmlwdGlvbjogIlJlYWQgZGVwdGggZm9yIGVhY2ggYWxsZWxlIG9uIHRoZSByZXZlcnNlIHN0cmFuZCIKICAgICAgfSwKICAgICAgRFA6IHsKICAgICAgICBOdW1iZXI6IDEsCiAgICAgICAgVHlwZTogIkludGVnZXIiLAogICAgICAgIERlc2NyaXB0aW9uOiAiUmVhZCBkZXB0aCIKICAgICAgfSwKICAgICAgRUM6IHsKICAgICAgICBOdW1iZXI6ICJBIiwKICAgICAgICBUeXBlOiAiSW50ZWdlciIsCiAgICAgICAgRGVzY3JpcHRpb246ICJFeHBlY3RlZCBhbHRlcm5hdGUgYWxsZWxlIGNvdW50cyIKICAgICAgfSwKICAgICAgRlQ6IHsKICAgICAgICBOdW1iZXI6IDEsCiAgICAgICAgVHlwZTogIlN0cmluZyIsCiAgICAgICAgRGVzY3JpcHRpb246ICdGaWx0ZXIgaW5kaWNhdGluZyBpZiB0aGlzIGdlbm90eXBlIHdhcyAiY2FsbGVkIicKICAgICAgfSwKICAgICAgR0w6IHsKICAgICAgICBOdW1iZXI6ICJHIiwKICAgICAgICBUeXBlOiAiRmxvYXQiLAogICAgICAgIERlc2NyaXB0aW9uOiAiR2Vub3R5cGUgbGlrZWxpaG9vZHMiCiAgICAgIH0sCiAgICAgIEdQOiB7CiAgICAgICAgTnVtYmVyOiAiRyIsCiAgICAgICAgVHlwZTogIkZsb2F0IiwKICAgICAgICBEZXNjcmlwdGlvbjogIkdlbm90eXBlIHBvc3RlcmlvciBwcm9iYWJpbGl0aWVzIgogICAgICB9LAogICAgICBHUTogewogICAgICAgIE51bWJlcjogMSwKICAgICAgICBUeXBlOiAiSW50ZWdlciIsCiAgICAgICAgRGVzY3JpcHRpb246ICJDb25kaXRpb25hbCBnZW5vdHlwZSBxdWFsaXR5IgogICAgICB9LAogICAgICBHVDogewogICAgICAgIE51bWJlcjogMSwKICAgICAgICBUeXBlOiAiU3RyaW5nIiwKICAgICAgICBEZXNjcmlwdGlvbjogIkdlbm90eXBlIgogICAgICB9LAogICAgICBIUTogewogICAgICAgIE51bWJlcjogMiwKICAgICAgICBUeXBlOiAiSW50ZWdlciIsCiAgICAgICAgRGVzY3JpcHRpb246ICJIYXBsb3R5cGUgcXVhbGl0eSIKICAgICAgfSwKICAgICAgTVE6IHsKICAgICAgICBOdW1iZXI6IDEsCiAgICAgICAgVHlwZTogIkludGVnZXIiLAogICAgICAgIERlc2NyaXB0aW9uOiAiUk1TIG1hcHBpbmcgcXVhbGl0eSIKICAgICAgfSwKICAgICAgUEw6IHsKICAgICAgICBOdW1iZXI6ICJHIiwKICAgICAgICBUeXBlOiAiSW50ZWdlciIsCiAgICAgICAgRGVzY3JpcHRpb246ICJQaHJlZC1zY2FsZWQgZ2Vub3R5cGUgbGlrZWxpaG9vZHMgcm91bmRlZCB0byB0aGUgY2xvc2VzdCBpbnRlZ2VyIgogICAgICB9LAogICAgICBQUTogewogICAgICAgIE51bWJlcjogMSwKICAgICAgICBUeXBlOiAiSW50ZWdlciIsCiAgICAgICAgRGVzY3JpcHRpb246ICJQaGFzaW5nIHF1YWxpdHkiCiAgICAgIH0sCiAgICAgIFBTOiB7CiAgICAgICAgTnVtYmVyOiAxLAogICAgICAgIFR5cGU6ICJJbnRlZ2VyIiwKICAgICAgICBEZXNjcmlwdGlvbjogIlBoYXNlIHNldCIKICAgICAgfQogICAgfSwKICAgIEFsdFR5cGVzOiB7CiAgICAgIERFTDogewogICAgICAgIERlc2NyaXB0aW9uOiAiRGVsZXRpb24gcmVsYXRpdmUgdG8gdGhlIHJlZmVyZW5jZSIKICAgICAgfSwKICAgICAgSU5TOiB7CiAgICAgICAgRGVzY3JpcHRpb246ICJJbnNlcnRpb24gb2Ygbm92ZWwgc2VxdWVuY2UgcmVsYXRpdmUgdG8gdGhlIHJlZmVyZW5jZSIKICAgICAgfSwKICAgICAgRFVQOiB7CiAgICAgICAgRGVzY3JpcHRpb246ICJSZWdpb24gb2YgZWxldmF0ZWQgY29weSBudW1iZXIgcmVsYXRpdmUgdG8gdGhlIHJlZmVyZW5jZSIKICAgICAgfSwKICAgICAgSU5WOiB7CiAgICAgICAgRGVzY3JpcHRpb246ICJJbnZlcnNpb24gb2YgcmVmZXJlbmNlIHNlcXVlbmNlIgogICAgICB9LAogICAgICBDTlY6IHsKICAgICAgICBEZ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saW5lLnN0YXJ0c1dpdGgoIiMiKSkgewogICAgICAgICAgdGhyb3cgbmV3IEVycm9yKGBCYWQgbGluZSBpbiBoZWFkZXI6CiR7bGluZX1gKTsKICAgICAgICB9IGVsc2UgaWYgKGxpbmUuc3RhcnRzV2l0aCgiIyMiKSkgewogICAgICAgICAgdGhpcy5fcGFyc2VNZXRhZGF0YShsaW5lKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgbGFzdExpbmUgPSBsaW5lOwogICAgICAgIH0KICAgICAgfSk7CiAgICAgIGlmICghbGFzdExpbmUpIHsKICAgICAgICB0aHJvdyBuZXcgRXJyb3IoIk5vIGZvcm1hdCBsaW5lIGZvdW5kIGluIGhlYWRlciIpOwogICAgICB9CiAgICAgIGNvbnN0IGZpZWxkcyA9IGxhc3RMaW5lLnRyaW0oKS5zcGxpdCgiCSIpOwogICAgICBjb25zdCB0aGlzSGVhZGVyID0gZmllbGRzLnNsaWNlKDAsIDgpOwogICAgICBjb25zdCBjb3JyZWN0SGVhZGVyID0gWwogICAgICAgICIjQ0hST00iLAogICAgICAgICJQT1MiLAogICAgICAgICJJRCIsCiAgICAgICAgIlJFRiIsCiAgICAgICAgIkFMVCIsCiAgICAgICAgIlFVQUwiLAogICAgICAgICJGSUxURVIiLAogICAgICAgICJJTkZPIgogICAgICBdOwogICAgICBpZiAoZmllbGRzLmxlbmd0aCA8IDgpIHsKICAgICAgICB0aHJvdyBuZXcgRXJyb3IoYFZDRiBoZWFkZXIgbWlzc2luZyBjb2x1bW5zOgoke2xhc3RMaW5lfWApOwogICAgICB9IGVsc2UgaWYgKHRoaXNIZWFkZXIubGVuZ3RoICE9PSBjb3JyZWN0SGVhZGVyLmxlbmd0aCB8fCAhdGhpc0hlYWRlci5ldmVyeSgodmFsdWUsIGluZGV4KSA9PiB2YWx1ZSA9PT0gY29ycmVjdEhlYWRlcltpbmRleF0pKSB7CiAgICAgICAgdGhyb3cgbmV3IEVycm9yKGBWQ0YgY29sdW1uIGhlYW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ICAgICAgY29uc3QgZGF0YSA9IHt9OwogICAgICBsZXQgY3VycktleSA9ICIiOwogICAgICBsZXQgY3VyclZhbHVlID0gIiI7CiAgICAgIGxldCBzdGF0ZSA9IDE7CiAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgc3RyLmxlbmd0aDsgaSArPSAxKSB7CiAgICAgICAgaWYgKHN0YXRlID09PSAxKSB7CiAgICAgICAgICBpZiAoc3RyW2ldID09PSAiPSIpIHsKICAgICAgICAgICAgc3RhdGUgPSAyOwogICAgICAgICAgfSBlbHNlIGlmIChzdHJbaV0gIT09IHBhaXJTZXBhcmF0b3IpIHsKICAgICAgICAgICAgY3VycktleSArPSBzdHJbaV07CiAgICAgICAgICB9IGVsc2UgaWYgKGN1cnJWYWx1ZSA9PT0gIiIpIHsKICAgICAgICAgICAgZGF0YVtjdXJyS2V5XSA9IG51bGw7CiAgICAgICAgICAgIGN1cnJLZXkgPSAiIjsKICAgICAgICAgIH0KICAgICAgICB9IGVsc2UgaWYgKHN0YXRlID09PSAyKSB7CiAgICAgICAgICBpZiAoc3RyW2ldID09PSBwYWlyU2VwYXJhdG9yKSB7CiAgICAgICAgICAgIGRhdGFbY3VycktleV0gPSBjdXJyVmFsdWU7CiAgICAgICAgICAgIGN1cnJLZXkgPSAiIjsKICAgICAgICAgICAgY3VyclZhbHVlID0gIiI7CiAgICAgICAgICAgIHN0YXRlID0gMTsKICAgICAgICAgIH0gZWxzZSBpZiAoc3RyW2ldID09PSAnIicpIHsKICAgICAgICAgICAgc3RhdGUgPSAzOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgY3VyclZhbHVlICs9IHN0cltpXTsKICAgICAgICAgIH0KICAgICAgICB9IGVsc2UgaWYgKHN0YXRlID09PSAzKSB7CiAgICAgICAgICBpZiAoc3RyW2ldICE9PSAnIicpIHsKICAgICAgICAgICAgY3VyclZhbHVlICs9IHN0cltpXTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHN0YXRlID0gMjsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgICAgaWYgKHN0YXRlID09PSAyIHx8IHN0YXRlID09PSAzKSB7CiAgICAgICAgZGF0YVtjdXJyS2V5XSA9IGN1cnJWYWx1ZTsKICAgICAgfSBlbHNlIGlmIChzdGF0ZSA9PT0gMSkgewogICAgICAgIGRhdGFbY3VycktleV0gPSBudWxsOwogICAgICB9CiAgICAgIHJldHVybiBkYXRhOwogICAgfQogICAgcGFyc2VMaW5lKGxpbmUpIHsKICAgICAgbGluZSA9IGxpbmUudHJpbSgpOwogICAgICBpZiAoIWxpbmUubGVuZ3RoKSB7CiAgICAgICAgcmV0dXJuIHZvaWQgMDsKICAgICAgfQogICAgICBjb25zdCBwYXJzZXIgPSB0aGlzOwogICAgICBsZXQgY3VyckNoYXIgPSAwOwogICAgICBmb3IgKGxldCBjdXJyRmllbGQgPSAwOyBjdXJyQ2hhciA8IGxpbmUubGVuZ3RoOyBjdXJyQ2hhciArPSAxKSB7CiAgICAgICAgaWYgKGxpbmVbY3VyckNoYXJdID09PSAiCSIpIHsKICAgICAgICAgIGN1cnJGaWVsZCArPSAxOwogICAgICAgIH0KICAgICAgICBpZiAoY3VyckZpZWxkID09PSA5KSB7CiAgICAgICAgICBicmVhazsKICAgICAgICB9CiAgICAgIH0KICAgICAgY29uc3QgZmllbGRzID0gbGluZS5zdWJzdHIoMCwgY3VyckNoYXIpLnNwbGl0KCIJIik7CiAgICAgIGNvbnN0IHJlc3QgPSBsaW5lLnN1YnN0cihjdXJyQ2hhciArIDEpOwogICAgICBjb25zdCBbQ0hST00sIFBPUywgSUQsIFJFRiwgQUxULCBRVUFMLCBGSUxURVJdID0gZmllbGRzOwogICAgICBjb25zdCBjaHJvbSA9IENIUk9NOwogICAgICBjb25zdCBwb3MgPSArUE9TOwogICAgICBjb25zdCBpZCA9IElEID09PSAiLiIgPyBudWxsIDogSUQuc3BsaXQoIjsiKTsKICAgICAgY29uc3QgcmVmID0gUkVGOwog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09PSAiRmxvYXQiKSB7CiAgICAgICAgICAgIGl0ZW1zID0gaXRlbXMubWFwKCh2YWwpID0+IHsKICAgICAgICAgICAgICBpZiAodmFsID09PSBudWxsKSB7CiAgICAgICAgICAgICAgICByZXR1cm4gbnVsbDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgcmV0dXJuIE51bWJlcih2YWwpOwogICAgICAgICAgICB9KTsKICAgICAgICAgIH0gZWxzZSBpZiAoaXRlbVR5cGUgPT09ICJGbGFnIikgewogICAgICAgICAgICBpZiAoaW5mb1trZXldKSB7CiAgICAgICAgICAgICAgY29uc29sZS53YXJuKGBJbmZvIGZpZWxkICR7a2V5fSBpcyBhIEZsYWcgYW5kIHNob3VsZCBub3QgaGF2ZSBhIHZhbHVlIChnb3QgdmFsdWUgJHtpbmZvW2tleV19KWApOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIGl0ZW1zID0gdHJ1ZTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpbmZvW2tleV0gPSBpdGVtczsKICAgICAgfSk7CiAgICAgIGNvbnN0IHZhcmlhbnQgPSBuZXcgVmFyaWFudCh7CiAgICAgICAgQ0hST006IGNocm9tLAogICAgICAgIFBPUzogcG9zLAogICAgICAgIEFMVDogYWx0LAogICAgICAgIElORk86IGluZm8sCiAgICAgICAgUkVGOiByZWYsCiAgICAgICAgRklMVEVSOiBmaWx0ZXIgJiYgZmlsdGVyLmxlbmd0aCA9PT0gMSAmJiBmaWx0ZXJbMF0gPT09ICJQQVNTIiA/ICJQQVNTIiA6IGZpbHRlciwKICAgICAgICBJRDogaWQsCiAgICAgICAgUVVBTDogcXVhbAogICAgICB9KTsKICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KHZhcmlhbnQsICJTQU1QTEVTIiwgewogICAgICAgIGdldCgpIHsKICAgICAgICAgIGNvbnN0IHNhbXBsZXMgPSBwYXJzZXIuX3BhcnNlR2Vub3R5cGVzKGZ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aWQgKyAxOwogICAgICAgIGVsc2UKICAgICAgICAgIGhpID0gbWlkOwogICAgICB9CiAgICAgIHJldHVybiBsbzsKICAgIH0KICAgIGZ1bmN0aW9uIHJpZ2h0KGEsIHgsIGxvLCBoaSkgewogICAgICBpZiAobG8gPT0gbnVsbCkKICAgICAgICBsbyA9IDA7CiAgICAgIGlmIChoaSA9PSBudWxsKQogICAgICAgIGhpID0gYS5sZW5ndGg7CiAgICAgIHdoaWxlIChsbyA8IGhpKSB7CiAgICAgICAgY29uc3QgbWlkID0gbG8gKyBoaSA+Pj4gMTsKICAgICAgICBpZiAoY29tcGFyZShhW21pZF0sIHgpID4gMCkKICAgICAgICAgIGhpID0gbWlkOwogICAgICAgIGVsc2UKICAgICAgICAgIGxvID0gbWlkICsgMTsKICAgICAgfQogICAgICByZXR1cm4gbG87CiAgICB9CiAgICBmdW5jdGlvbiBjZW50ZXIoYSwgeCwgbG8sIGhpKSB7CiAgICAgIGlmIChsbyA9PSBudWxsKQogICAgICAgIGxvID0gMDsKICAgICAgaWYgKGhpID09IG51bGwpCiAgICAgICAgaGkgPSBhLmxlbmd0aDsKICAgICAgY29uc3QgaSA9IGxlZnQoYSwgeCwgbG8sIGhpIC0gMSk7CiAgICAgIHJldHVybiBpID4gbG8gJiYgZGVsdGEoYVtpIC0gMV0sIHgpID4gLWRlbHRhKGFbaV0sIHgpID8gaSAtIDEgOiBpOwogICAgfQogICAgcmV0dXJuIHsgbGVmdCwgY2VudGVyLCByaWdodCB9OwogIH0KICBmdW5jdGlvbiBhc2NlbmRpbmdDb21wYXJhdG9yKGYpIHsKICAgIHJldHVybiAoZCwgeCkgPT4gYXNjZW5kaW5nX2RlZmF1bHQoZihkKSwgeCk7CiAgfQoKICAvLyBzcmMvZGF0YS1mZXRjaGVycy91dGlscy50cwogIHZhciBEYXRhU291cmNlID0gY2xhc3MgewogICAgY29uc3RydWN0b3IoZmlsZSwgY2hyb21TaXplcywgb3B0aW9ucykgewogICAgICB0aGlzLmZpb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H1gOwogICAgICB9IGVsc2UgaWYgKGxlbmd0aCA9PT0gSW5maW5pdHkgJiYgcG9zaXRpb24gIT09IDApIHsKICAgICAgICBoZWFkZXJzLnJhbmdlID0gYGJ5dGVzPSR7cG9zaXRpb259LWA7CiAgICAgIH0KICAgICAgY29uc3QgYXJncyA9IHsKICAgICAgICAuLi50aGlzLmJhc2VPdmVycmlkZXMsCiAgICAgICAgLi4ub3ZlcnJpZGVzLAogICAgICAgIGhlYWRlcnM6IHsKICAgICAgICAgIC4uLmhlYWRlcnMsCiAgICAgICAgICAuLi5vdmVycmlkZXMuaGVhZGVycywKICAgICAgICAgIC4uLnRoaXMuYmFzZU92ZXJyaWRlcy5oZWFkZXJzCiAgICAgICAgfSwKICAgICAgICBtZXRob2Q6ICJHRVQiLAogICAgICAgIHJlZGlyZWN0OiAiZm9sbG93IiwKICAgICAgICBtb2RlOiAiY29ycyIsCiAgICAgICAgc2lnbmFsCiAgICAgIH07CiAgICAgIGNvbnN0IHJlc3BvbnNlID0gYXdhaXQgdGhpcy5mZXRjaCh0aGlzLnVybCwgYXJncyk7CiAgICAgIGlmICghcmVzcG9uc2Uub2spIHsKICAgICAgICB0aHJvdyBuZXcgRXJyb3IoYEhUVFAgJHtyZXNwb25zZS5zdGF0dXN9ICR7cmVzcG9uc2Uuc3RhdHVzVGV4dH0gJHt0aGlzLnVybH1gKTsKICAgICAgfQogICAgICBpZiAocmVzcG9uc2Uuc3RhdHVzID09PSAyMDAgfHwgcmVzcG9uc2Uuc3RhdHVzID09PSAyMDYpIHsKICAgICAgICBjb25zdCByZXNwb25zZURhdGEgPSBhd2FpdCB0aGlzLmdldEJ1ZmZlckZyb21SZXNwb25zZShyZXNwb25zZSk7CiAgICAgICAgY29uc3QgYnl0ZXNDb3BpZWQgPSByZXNwb25zZURhdGEuY29weShidWZmZXIsIG9mZnNldCwgMCwgTWF0aC5taW4obGVuZ3RoLCByZXNwb25zZURhdGEubGVuZ3RoKSk7CiAgICAgICAgY29uc3Qg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IkNHIjoKICAgICAgY2FzZSAiR0MiOgogICAgICAgIHJldHVybiAiQz5HIjsKICAgICAgY2FzZSAiQ1QiOgogICAgICBjYXNlICJHQSI6CiAgICAgICAgcmV0dXJuICJDPlQiOwogICAgICBjYXNlICJUQSI6CiAgICAgIGNhc2UgIkFUIjoKICAgICAgICByZXR1cm4gIlQ+QSI7CiAgICAgIGNhc2UgIlRDIjoKICAgICAgY2FzZSAiQUciOgogICAgICAgIHJldHVybiAiVD5DIjsKICAgICAgY2FzZSAiVEciOgogICAgICBjYXNlICJBQyI6CiAgICAgICAgcmV0dXJuICJUPkciOwogICAgICBkZWZhdWx0OgogICAgICAgIHJldHVybiAidW5rbm93biI7CiAgICB9CiAgfTsKICBmdW5jdGlvbiByZWNvcmRUb1RpbGUodmNmUmVjb3JkLCBjaHJQb3MsIHByZXZBYnNQb3MpIHsKICAgIGNvbnN0IGFic1BvcyA9IGNoclBvcyArIHZjZlJlY29yZC5QT1MgKyAxOwogICAgbGV0IEFMVDsKICAgIGlmIChBcnJheS5pc0FycmF5KHZjZlJlY29yZC5BTFQpICYmIHZjZlJlY29yZC5BTFQubGVuZ3RoID4gMCkgewogICAgICBBTFQgPSB2Y2ZSZWNvcmQuQUxUWzBdOwogICAgfQogICAgY29uc3QgRElTVFBSRVYgPSAhcHJldkFic1BvcyA/IG51bGwgOiBhYnNQb3MgLSBwcmV2QWJzUG9zOwogICAgY29uc3QgRElTVFBSRVZMT0dFID0gIXByZXZBYnNQb3MgPyBudWxsIDogTWF0aC5sb2coYWJzUG9zIC0gcHJldkFic1Bvcyk7CiAgICBjb25zdCBNVVRUWVBFID0gZ2V0TXV0YXRpb25UeXBlKHZjZlJlY29yZC5SRUYsIEFMVCk7CiAgICBjb25zdCBTVUJUWVBFID0gZ2V0U3Vic3RpdHV0aW9uVHlwZSh2Y2ZSZWNvcmQuUkVGLCBBTFQpOwogICAgY29uc3QgUE9TRU5EID0gYWJzUG9zICsgdmNmUmVjb3JkLlJFRi5sZW5ndGg7CiAgICBjb25zdCBkYXRhID0gewogICAgICAuLi52Y2ZSZWNvcmQsCiAgICAgIEFMVCwKICAgICAgTVVUVFlQRSwKICAgICAgU1VCVFlQRSwKICAgICAgSU5GTzogSlNPTi5zdHJpbmdpZnkodmNmUmVjb3JkLklORk8pLAogICAgICBPUklHSU5BTFBPUzogdmNmUmVjb3JkLlBPUywKICAgICAgUE9TOiBhYnNQb3MsCiAgICAgIFBPU0VORCwKICAgICAgRElTVFBSRVYsCiAgICAgIERJU1RQUkVWTE9HRQogICAgfTsKICAgIE9iamVjdC5rZXlzKHZjZlJlY29yZC5JTkZPKS5mb3JFYWNoKChrZXkpID0+IHsKICAgICAgY29uc3QgdmFsID0gdmNmUmVjb3JkLklORk9ba2V5XTsKICAgICAgaWYgKEFycmF5LmlzQXJyYXkodmFsKSkgewogICAgICAgIGRhdGFba2V5XSA9IHZhbC5qb2luKCIsICIpOwogICAgICB9IGVsc2UgewogICAgICAgIGRhdGFba2V5XSA9IHZhbDsKICAgICAgfQogICAgfSk7CiAgICByZXR1cm4gZGF0YTsKICB9CgogIC8vIHNyYy9kYXRhLWZldGNoZXJzL3ZjZi92Y2Ytd29ya2VyLnRzP3dvcmtlciZpbmxpbmU/d29ya2VyX2ZpbGUKICB2YXIgdmNmRmlsZXMgPSBuZXcgTWFwKCk7CiAgdmFyIFZjZkZpbGUgPSBjbGFzcyB7CiAgICBjb25zdHJ1Y3Rvcih0YmksIHVpZCkgewogICAgICB0aGlzLnRiaSA9IHRiaTsKICAgICAgdGhpcy4jdWlkID0gdWlkOwogICAgfQogICAgI3BhcnNlcjsKICAgICN1aWQ7CiAgICBzdGF0aWMgZnJvbVVybCh1cmwsIGluZGV4VXJsLCB1aWQsIHVybEZldGNoT3B0aW9ucywgaW5kZXhVcmxGZXRjaE9wdGlvbnMpIHsKICAgICAgY29uc3QgdGJpID0gbmV3IFRhYml4SW5kZXhlZEZpbGUoewogICAgICAgIGZpbGVoYW5kbGU6IG5ldyBSZW1vdG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0UG9zLCBlbmRQb3M7CiAgICAgICAgaWYgKGNocm9tU3RhcnQgPiBjdXJNaW5YIHx8IGN1ck1pblggPj0gY2hyb21FbmQpIHsKICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgIH0KICAgICAgICBsZXQgcHJldlBPUzsKICAgICAgICBjb25zdCB0aWxlc1Byb21pc2UgPSBuZXcgUHJvbWlzZSgocmVzb2x2ZSkgPT4gewogICAgICAgICAgY29uc3QgdGlsZXMgPSBbXTsKICAgICAgICAgIGNvbnN0IGxpbmVDYWxsYmFjayA9IChsaW5lKSA9PiB7CiAgICAgICAgICAgIGNvbnN0IHZjZlJlY29yZCA9IHBhcnNlci5wYXJzZUxpbmUobGluZSk7CiAgICAgICAgICAgIGNvbnN0IHZjZlRpbGUgPSByZWNvcmRUb1RpbGUodmNmUmVjb3JkLCBjaHJvbVN0YXJ0LCBwcmV2UE9TKTsKICAgICAgICAgICAgcHJldlBPUyA9IHZjZlRpbGUuUE9TOwogICAgICAgICAgICB0aWxlcy5wdXNoKHZjZlRpbGUpOwogICAgICAgICAgfTsKICAgICAgICAgIGlmIChtYXhYID4gY2hyb21FbmQpIHsKICAgICAgICAgICAgc3RhcnRQb3MgPSBjdXJNaW5YIC0gY2hyb21TdGFydDsKICAgICAgICAgICAgZW5kUG9zID0gY2hyb21FbmQgLSBjaHJvbVN0YXJ0OwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgc3RhcnRQb3MgPSBNYXRoLmZsb29yKGN1ck1pblggLSBjaHJvbVN0YXJ0KTsKICAgICAgICAgICAgZW5kUG9zID0gTWF0aC5jZWlsKG1heFggLSBjaHJvbVN0YXJ0KTsKICAgICAgICAgIH0KICAgICAgICAgIHNvdXJjZS5maWxlLnRiaS5nZXRMaW5lcyhjaHJvbU5hbWUsIHN0YXJ0UG9zLCBlbmRQb3MsIGxpbmVDYWxsYmFjaykudGhlbigoKSA9PiB7CiAgICAgICAgICAgIHJlc29sdmUodGlsZXMpOwogICAgICAgICA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rhc2ggKEN1c3RvbSBCdWlsZCkgPGh0dHBzOi8vbG9kYXNoLmNvbS8+CiAqIEJ1aWxkOiBgbG9kYXNoIG1vZHVsYXJpemUgZXhwb3J0cz0iZXMiIC1vIC4vYAogKiBDb3B5cmlnaHQgT3BlbkpTIEZvdW5kYXRpb24gYW5kIG90aGVyIGNvbnRyaWJ1dG9ycyA8aHR0cHM6Ly9vcGVuanNmLm9yZy8+CiAqIFJlbGVhc2VkIHVuZGVyIE1JVCBsaWNlbnNlIDxodHRwczovL2xvZGFzaC5jb20vbGljZW5zZT4KICogQmFzZWQgb24gVW5kZXJzY29yZS5qcyAxLjguMyA8aHR0cDovL3VuZGVyc2NvcmVqcy5vcmcvTElDRU5TRT4KICogQ29weXJpZ2h0IEplcmVteSBBc2hrZW5hcywgRG9jdW1lbnRDbG91ZCBhbmQgSW52ZXN0aWdhdGl2ZSBSZXBvcnRlcnMgJiBFZGl0b3JzCiAqLwo=",ile=typeof window<"u"&&window.Blob&&new Blob([atob(pHe)],{type:"text/javascript;charset=utf-8"});function Tqt(){const g=ile&&(window.URL||window.webkitURL).createObjectURL(ile);try{return g?new Worker(g):new Worker("data:application/javascript;base64,"+pHe,{type:"module"})}finally{g&&(window.URL||window.webkitURL).revokeObjectURL(g)}}const Nqt=200;class bHe{constructor(e,I){nt(this,"dataConfig",{}),nt(this,"uid"),nt(this,"prevRequestTime"),nt(this,"track"),nt(this,"toFetch"),nt(this,"fetchTimeout"),nt(this,"worker"),this.uid=e.libraries.slugid.nice(),this.prevRequestTime=0,this.toFetch=new Set;const{url:i,indexUrl:n,assembly:C,...r}=I;this.worker=dN(new Tqt).then(async o=>{const A=Object.entries(yI(C).size);return await o.init(this.uid,{url:i,indexUrl:n},A,r),o})}async tilesetInfo(e){(await this.worker).tilesetInfo(this.uid).then(e)}fetchTilesDebounced(e,I){this.track.drawLoadingCue(),I.forEach(i=>this.toFetch.add(i)),this.fetchTimeout&&clearTimeout(this.fetchTimeout),this.fetchTimeout=setTimeout(()=>{this.sendFetch(e,[...this.toFetch]),this.toFetch.clear()},Nqt)}async sendFetch(e,I){(await this.worker).fetchTilesDebounced(this.uid,I).then(e)}async getTabularData(e){const I=await(await this.worker).getTabularData(this.uid,e);return JSON.parse(new TextDecoder().decode(I))}}nt(bHe,"config",{type:"vcf"});const bY=BigInt(32);function kqt(g,e,I){const i=+!!I,n=+!I;return BigInt(g.getInt32(e,I)*n+g.getInt32(e+4,I)*i)<>bY),C=Number(I&BigInt(4294967295));i?(g.setInt32(e+4,n,i),g.setUint32(e,C,i)):(g.setInt32(e,n,i),g.setUint32(e+4,C,i))}function xqt(g,e,I,i){const n=Number(I>>bY),C=Number(I&BigInt(4294967295));i?(g.setUint32(e+4,n,i),g.setUint32(e,C,i)):(g.setUint32(e,n,i),g.setUint32(e+4,C,i))}"getBigInt64"in DataView||(DataView.prototype.getBigInt64=function(g,e){return kqt(this,g,e)});"getBigUint64"in DataView||(DataView.prototype.getBigUint64=function(g,e){return Yqt(this,g,e)});"setBigInt64"in DataView||(DataView.prototype.setBigInt64=function(g,e,I){Kqt(this,g,e,I)});"setBigUint64"in DataView||(DataView.prototype.setBigUint64=function(g,e,I){xqt(this,g,e,I)});class Dqt{constructor(e,I){this.code="",this.scopes=[["vars"]],this.bitFields=[],this.tmpVariableCount=0,this.references=new Map,this.imports=[],this.reverseImports=new Map,this.useContextVariables=!1,this.importPath=e,this.useContextVariables=I}generateVariable(e){const I=[...this.scopes[this.scopes.length-1]];return e&&I.push(e),I.join(".")}generateOption(e){switch(typeof e){case"number":return e.toString();case"string":return this.generateVariable(e);case"function":return`${this.addImport(e)}.call(${this.generateVariable()}, vars)`}}generateError(e){this.pushCode(`throw new Error(${e});`)}generateTmpVariable(){return"$tmp"+this.tmpVariableCount++}pushCode(e){this.code+=e+` -`}pushPath(e){e&&this.scopes[this.scopes.length-1].push(e)}popPath(e){e&&this.scopes[this.scopes.length-1].pop()}pushScope(e){this.scopes.push([e])}popScope(){this.scopes.pop()}addImport(e){if(!this.importPath)return`(${e})`;let I=this.reverseImports.get(e);return I||(I=this.imports.push(e)-1,this.reverseImports.set(e,I)),`${this.importPath}[${I}]`}addReference(e){this.references.has(e)||this.references.set(e,{resolved:!1,requested:!1})}markResolved(e){const I=this.references.get(e);I&&(I.resolved=!0)}markRequested(e){e.forEach(I=>{const i=this.references.get(I);i&&(i.requested=!0)})}getUnresolvedReferences(){return Array.from(this.references).filter(([e,I])=>!I.resolved&&!I.requested).map(([e,I])=>e)}}const ko=new Map,_u="___parser_",Yo={uint8:1,uint16le:2,uint16be:2,uint32le:4,uint32be:4,int8:1,int16le:2,int16be:2,int32le:4,int32be:4,int64be:8,int64le:8,uint64be:8,uint64le:8,floatle:4,floatbe:4,doublele:8,doublebe:8},C1={uint8:"Uint8",uint16le:"Uint16",uint16be:"Uint16",uint32le:"Uint32",uint32be:"Uint32",int8:"Int8",int16le:"Int16",int16be:"Int16",int32le:"Int32",int32be:"Int32",int64be:"BigInt64",int64le:"BigInt64",uint64be:"BigUint64",uint64le:"BigUint64",floatle:"Float32",floatbe:"Float32",doublele:"Float64",doublebe:"Float64"},r1={uint8:!1,uint16le:!0,uint16be:!1,uint32le:!0,uint32be:!1,int8:!1,int16le:!0,int16be:!1,int32le:!0,int32be:!1,int64be:!1,int64le:!0,uint64be:!1,uint64le:!0,floatle:!0,floatbe:!1,doublele:!0,doublebe:!1};class Kg{constructor(){this.varName="",this.type="",this.options={},this.endian="be",this.useContextVariables=!1}static start(){return new Kg}primitiveGenerateN(e,I){const i=C1[e],n=r1[e];I.pushCode(`${I.generateVariable(this.varName)} = dataView.get${i}(offset, ${n});`),I.pushCode(`offset += ${Yo[e]};`)}primitiveN(e,I,i){return this.setNextParser(e,I,i)}useThisEndian(e){return e+this.endian.toLowerCase()}uint8(e,I={}){return this.primitiveN("uint8",e,I)}uint16(e,I={}){return this.primitiveN(this.useThisEndian("uint16"),e,I)}uint16le(e,I={}){return this.primitiveN("uint16le",e,I)}uint16be(e,I={}){return this.primitiveN("uint16be",e,I)}uint32(e,I={}){return this.primitiveN(this.useThisEndian("uint32"),e,I)}uint32le(e,I={}){return this.primitiveN("uint32le",e,I)}uint32be(e,I={}){return this.primitiveN("uint32be",e,I)}int8(e,I={}){return this.primitiveN("int8",e,I)}int16(e,I={}){return this.primitiveN(this.useThisEndian("int16"),e,I)}int16le(e,I={}){return this.primitiveN("int16le",e,I)}int16be(e,I={}){return this.primitiveN("int16be",e,I)}int32(e,I={}){return this.primitiveN(this.useThisEndian("int32"),e,I)}int32le(e,I={}){return this.primitiveN("int32le",e,I)}int32be(e,I={}){return this.primitiveN("int32be",e,I)}bigIntVersionCheck(){if(!DataView.prototype.getBigInt64)throw new Error("BigInt64 is unsupported on this runtime")}int64(e,I={}){return this.bigIntVersionCheck(),this.primitiveN(this.useThisEndian("int64"),e,I)}int64be(e,I={}){return this.bigIntVersionCheck(),this.primitiveN("int64be",e,I)}int64le(e,I={}){return this.bigIntVersionCheck(),this.primitiveN("int64le",e,I)}uint64(e,I={}){return this.bigIntVersionCheck(),this.primitiveN(this.useThisEndian("uint64"),e,I)}uint64be(e,I={}){return this.bigIntVersionCheck(),this.primitiveN("uint64be",e,I)}uint64le(e,I={}){return this.bigIntVersionCheck(),this.primitiveN("uint64le",e,I)}floatle(e,I={}){return this.primitiveN("floatle",e,I)}floatbe(e,I={}){return this.primitiveN("floatbe",e,I)}doublele(e,I={}){return this.primitiveN("doublele",e,I)}doublebe(e,I={}){return this.primitiveN("doublebe",e,I)}bitN(e,I,i){return i.length=e,this.setNextParser("bit",I,i)}bit1(e,I={}){return this.bitN(1,e,I)}bit2(e,I={}){return this.bitN(2,e,I)}bit3(e,I={}){return this.bitN(3,e,I)}bit4(e,I={}){return this.bitN(4,e,I)}bit5(e,I={}){return this.bitN(5,e,I)}bit6(e,I={}){return this.bitN(6,e,I)}bit7(e,I={}){return this.bitN(7,e,I)}bit8(e,I={}){return this.bitN(8,e,I)}bit9(e,I={}){return this.bitN(9,e,I)}bit10(e,I={}){return this.bitN(10,e,I)}bit11(e,I={}){return this.bitN(11,e,I)}bit12(e,I={}){return this.bitN(12,e,I)}bit13(e,I={}){return this.bitN(13,e,I)}bit14(e,I={}){return this.bitN(14,e,I)}bit15(e,I={}){return this.bitN(15,e,I)}bit16(e,I={}){return this.bitN(16,e,I)}bit17(e,I={}){return this.bitN(17,e,I)}bit18(e,I={}){return this.bitN(18,e,I)}bit19(e,I={}){return this.bitN(19,e,I)}bit20(e,I={}){return this.bitN(20,e,I)}bit21(e,I={}){return this.bitN(21,e,I)}bit22(e,I={}){return this.bitN(22,e,I)}bit23(e,I={}){return this.bitN(23,e,I)}bit24(e,I={}){return this.bitN(24,e,I)}bit25(e,I={}){return this.bitN(25,e,I)}bit26(e,I={}){return this.bitN(26,e,I)}bit27(e,I={}){return this.bitN(27,e,I)}bit28(e,I={}){return this.bitN(28,e,I)}bit29(e,I={}){return this.bitN(29,e,I)}bit30(e,I={}){return this.bitN(30,e,I)}bit31(e,I={}){return this.bitN(31,e,I)}bit32(e,I={}){return this.bitN(32,e,I)}namely(e){return ko.set(e,this),this.alias=e,this}skip(e,I={}){return this.seek(e,I)}seek(e,I={}){if(I.assert)throw new Error("assert option on seek is not allowed.");return this.setNextParser("seek","",{length:e})}string(e,I){if(!I.zeroTerminated&&!I.length&&!I.greedy)throw new Error("One of length, zeroTerminated, or greedy must be defined for string.");if((I.zeroTerminated||I.length)&&I.greedy)throw new Error("greedy is mutually exclusive with length and zeroTerminated for string.");if(I.stripNull&&!(I.length||I.greedy))throw new Error("length or greedy must be defined if stripNull is enabled.");return I.encoding=I.encoding||"utf8",this.setNextParser("string",e,I)}buffer(e,I){if(!I.length&&!I.readUntil)throw new Error("length or readUntil must be defined for buffer.");return this.setNextParser("buffer",e,I)}wrapped(e,I){if(typeof I!="object"&&typeof e=="object"&&(I=e,e=""),!I||!I.wrapper||!I.type)throw new Error("Both wrapper and type must be defined for wrapped.");if(!I.length&&!I.readUntil)throw new Error("length or readUntil must be defined for wrapped.");return this.setNextParser("wrapper",e,I)}array(e,I){if(!I.readUntil&&!I.length&&!I.lengthInBytes)throw new Error("One of readUntil, length and lengthInBytes must be defined for array.");if(!I.type)throw new Error("type is required for array.");if(typeof I.type=="string"&&!ko.has(I.type)&&!(I.type in Yo))throw new Error(`Array element type "${I.type}" is unkown.`);return this.setNextParser("array",e,I)}choice(e,I){if(typeof I!="object"&&typeof e=="object"&&(I=e,e=""),!I)throw new Error("tag and choices are are required for choice.");if(!I.tag)throw new Error("tag is requird for choice.");if(!I.choices)throw new Error("choices is required for choice.");for(const i in I.choices){const n=parseInt(i,10),C=I.choices[n];if(isNaN(n))throw new Error(`Choice key "${i}" is not a number.`);if(typeof C=="string"&&!ko.has(C)&&!(C in Yo))throw new Error(`Choice type "${C}" is unkown.`)}return this.setNextParser("choice",e,I)}nest(e,I){if(typeof I!="object"&&typeof e=="object"&&(I=e,e=""),!I||!I.type)throw new Error("type is required for nest.");if(!(I.type instanceof Kg)&&!ko.has(I.type))throw new Error("type must be a known parser name or a Parser object.");if(!(I.type instanceof Kg)&&!e)throw new Error("type must be a Parser object if the variable name is omitted.");return this.setNextParser("nest",e,I)}pointer(e,I){if(!I.offset)throw new Error("offset is required for pointer.");if(!I.type)throw new Error("type is required for pointer.");if(typeof I.type=="string"&&!(I.type in Yo)&&!ko.has(I.type))throw new Error(`Pointer type "${I.type}" is unkown.`);return this.setNextParser("pointer",e,I)}saveOffset(e,I={}){return this.setNextParser("saveOffset",e,I)}endianness(e){switch(e.toLowerCase()){case"little":this.endian="le";break;case"big":this.endian="be";break;default:throw new Error('endianness must be one of "little" or "big"')}return this}endianess(e){return this.endianness(e)}useContextVars(e=!0){return this.useContextVariables=e,this}create(e){if(!(e instanceof Function))throw new Error("Constructor must be a Function object.");return this.constructorFn=e,this}getContext(e){const I=new Dqt(e,this.useContextVariables);return I.pushCode("var dataView = new DataView(buffer.buffer, buffer.byteOffset, buffer.length);"),this.alias?(this.addAliasedCode(I),I.pushCode(`return ${_u+this.alias}(0).result;`)):this.addRawCode(I),I}getCode(){const e="imports";return this.getContext(e).code}addRawCode(e){e.pushCode("var offset = 0;"),e.pushCode(`var vars = ${this.constructorFn?"new constructorFn()":"{}"};`),e.pushCode("vars.$parent = null;"),e.pushCode("vars.$root = vars;"),this.generate(e),this.resolveReferences(e),e.pushCode("delete vars.$parent;"),e.pushCode("delete vars.$root;"),e.pushCode("return vars;")}addAliasedCode(e){return e.pushCode(`function ${_u+this.alias}(offset, context) {`),e.pushCode(`var vars = ${this.constructorFn?"new constructorFn()":"{}"};`),e.pushCode("var ctx = Object.assign({$parent: null, $root: vars}, context || {});"),e.pushCode("vars = Object.assign(vars, ctx);"),this.generate(e),e.markResolved(this.alias),this.resolveReferences(e),e.pushCode("Object.keys(ctx).forEach(function (item) { delete vars[item]; });"),e.pushCode("return { offset: offset, result: vars };"),e.pushCode("}"),e}resolveReferences(e){const I=e.getUnresolvedReferences();e.markRequested(I),I.forEach(i=>{var n;(n=ko.get(i))===null||n===void 0||n.addAliasedCode(e)})}compile(){const e="imports",I=this.getContext(e);this.compiled=new Function(e,"TextDecoder",`return function (buffer, constructorFn) { ${I.code} };`)(I.imports,TextDecoder)}sizeOf(){let e=NaN;if(Object.keys(Yo).indexOf(this.type)>=0)e=Yo[this.type];else if(this.type==="string"&&typeof this.options.length=="number")e=this.options.length;else if(this.type==="buffer"&&typeof this.options.length=="number")e=this.options.length;else if(this.type==="array"&&typeof this.options.length=="number"){let I=NaN;typeof this.options.type=="string"?I=Yo[this.options.type]:this.options.type instanceof Kg&&(I=this.options.type.sizeOf()),e=this.options.length*I}else this.type==="seek"?e=this.options.length:this.type==="nest"?e=this.options.type.sizeOf():this.type||(e=0);return this.next&&(e+=this.next.sizeOf()),e}parse(e){return this.compiled||this.compile(),this.compiled(e,this.constructorFn)}setNextParser(e,I,i){const n=new Kg;return n.type=e,n.varName=I,n.options=i,n.endian=this.endian,this.head?this.head.next=n:this.next=n,this.head=n,this}generate(e){if(this.type){switch(this.type){case"uint8":case"uint16le":case"uint16be":case"uint32le":case"uint32be":case"int8":case"int16le":case"int16be":case"int32le":case"int32be":case"int64be":case"int64le":case"uint64be":case"uint64le":case"floatle":case"floatbe":case"doublele":case"doublebe":this.primitiveGenerateN(this.type,e);break;case"bit":this.generateBit(e);break;case"string":this.generateString(e);break;case"buffer":this.generateBuffer(e);break;case"seek":this.generateSeek(e);break;case"nest":this.generateNest(e);break;case"array":this.generateArray(e);break;case"choice":this.generateChoice(e);break;case"pointer":this.generatePointer(e);break;case"saveOffset":this.generateSaveOffset(e);break;case"wrapper":this.generateWrapper(e);break}this.type!=="bit"&&this.generateAssert(e)}const I=e.generateVariable(this.varName);return this.options.formatter&&this.type!=="bit"&&this.generateFormatter(e,I,this.options.formatter),this.generateNext(e)}generateAssert(e){if(!this.options.assert)return;const I=e.generateVariable(this.varName);switch(typeof this.options.assert){case"function":{const i=e.addImport(this.options.assert);e.pushCode(`if (!${i}.call(vars, ${I})) {`)}break;case"number":e.pushCode(`if (${this.options.assert} !== ${I}) {`);break;case"string":e.pushCode(`if (${JSON.stringify(this.options.assert)} !== ${I}) {`);break;default:throw new Error("assert option must be a string, number or a function.")}e.generateError(`"Assertion error: ${I} is " + ${JSON.stringify(this.options.assert.toString())}`),e.pushCode("}")}generateNext(e){return this.next&&(e=this.next.generate(e)),e}generateBit(e){const I=JSON.parse(JSON.stringify(this));if(I.options=this.options,I.generateAssert=this.generateAssert.bind(this),I.generateFormatter=this.generateFormatter.bind(this),I.varName=e.generateVariable(I.varName),e.bitFields.push(I),!this.next||this.next&&["bit","nest"].indexOf(this.next.type)<0){const i=e.generateTmpVariable();e.pushCode(`var ${i} = 0;`);const n=(a=0)=>{let l=0;for(let c=a;c32)break;l+=u}return l},C=a=>(a<=8?(e.pushCode(`${i} = dataView.getUint8(offset);`),a=8):a<=16?(e.pushCode(`${i} = dataView.getUint16(offset);`),a=16):a<=24?(e.pushCode(`${i} = (dataView.getUint16(offset) << 8) | dataView.getUint8(offset + 2);`),a=24):(e.pushCode(`${i} = dataView.getUint32(offset);`),a=32),e.pushCode(`offset += ${a/8};`),a);let r=0;const o=this.endian==="be";let A=0,s=0;e.bitFields.forEach((a,l)=>{let c=a.options.length;if(c>s){if(s){const h=-1>>>32-s;e.pushCode(`${a.varName} = (${i} & 0x${h.toString(16)}) << ${c-s};`),c-=s}r=0,s=A=C(n(l)-s)}const u=o?A-r-c:r,d=-1>>>32-c;e.pushCode(`${a.varName} ${c> ${u} & 0x${d.toString(16)};`),a.options.length===32&&e.pushCode(`${a.varName} >>>= 0`),a.options.assert&&a.generateAssert(e),a.options.formatter&&a.generateFormatter(e,a.varName,a.options.formatter),r+=c,s-=c}),e.bitFields=[]}}generateSeek(e){const I=e.generateOption(this.options.length);e.pushCode(`offset += ${I};`)}generateString(e){const I=e.generateVariable(this.varName),i=e.generateTmpVariable(),n=this.options.encoding,C=n.toLowerCase()==="hex",r='b => b.toString(16).padStart(2, "0")';if(this.options.length&&this.options.zeroTerminated){const o=this.options.length;e.pushCode(`var ${i} = offset;`),e.pushCode(`while(dataView.getUint8(offset++) !== 0 && offset - ${i} < ${o});`);const A=`offset - ${i} < ${o} ? offset - 1 : offset`;e.pushCode(C?`${I} = Array.from(buffer.subarray(${i}, ${A}), ${r}).join('');`:`${I} = new TextDecoder('${n}').decode(buffer.subarray(${i}, ${A}));`)}else if(this.options.length){const o=e.generateOption(this.options.length);e.pushCode(C?`${I} = Array.from(buffer.subarray(offset, offset + ${o}), ${r}).join('');`:`${I} = new TextDecoder('${n}').decode(buffer.subarray(offset, offset + ${o}));`),e.pushCode(`offset += ${o};`)}else this.options.zeroTerminated?(e.pushCode(`var ${i} = offset;`),e.pushCode("while(dataView.getUint8(offset++) !== 0);"),e.pushCode(C?`${I} = Array.from(buffer.subarray(${i}, offset - 1), ${r}).join('');`:`${I} = new TextDecoder('${n}').decode(buffer.subarray(${i}, offset - 1));`)):this.options.greedy&&(e.pushCode(`var ${i} = offset;`),e.pushCode("while(buffer.length > offset++);"),e.pushCode(C?`${I} = Array.from(buffer.subarray(${i}, offset), ${r}).join('');`:`${I} = new TextDecoder('${n}').decode(buffer.subarray(${i}, offset));`));this.options.stripNull&&e.pushCode(`${I} = ${I}.replace(/\\x00+$/g, '')`)}generateBuffer(e){const I=e.generateVariable(this.varName);if(typeof this.options.readUntil=="function"){const i=this.options.readUntil,n=e.generateTmpVariable(),C=e.generateTmpVariable();e.pushCode(`var ${n} = offset;`),e.pushCode(`var ${C} = 0;`),e.pushCode("while (offset < buffer.length) {"),e.pushCode(`${C} = dataView.getUint8(offset);`);const r=e.addImport(i);e.pushCode(`if (${r}.call(${e.generateVariable()}, ${C}, buffer.subarray(offset))) break;`),e.pushCode("offset += 1;"),e.pushCode("}"),e.pushCode(`${I} = buffer.subarray(${n}, offset);`)}else if(this.options.readUntil==="eof")e.pushCode(`${I} = buffer.subarray(offset);`);else{const i=e.generateOption(this.options.length);e.pushCode(`${I} = buffer.subarray(offset, offset + ${i});`),e.pushCode(`offset += ${i};`)}this.options.clone&&e.pushCode(`${I} = buffer.constructor.from(${I});`)}generateArray(e){const I=e.generateOption(this.options.length),i=e.generateOption(this.options.lengthInBytes),n=this.options.type,C=e.generateTmpVariable(),r=e.generateVariable(this.varName),o=e.generateTmpVariable(),A=this.options.key,s=typeof A=="string";if(s?e.pushCode(`${r} = {};`):e.pushCode(`${r} = [];`),typeof this.options.readUntil=="function"?e.pushCode("do {"):this.options.readUntil==="eof"?e.pushCode(`for (var ${C} = 0; offset < buffer.length; ${C}++) {`):i!==void 0?e.pushCode(`for (var ${C} = offset + ${i}; offset < ${C}; ) {`):e.pushCode(`for (var ${C} = ${I}; ${C} > 0; ${C}--) {`),typeof n=="string")if(ko.get(n)){const a=e.generateTmpVariable();if(e.pushCode(`var ${a} = ${_u+n}(offset, {`),e.useContextVariables){const l=e.generateVariable();e.pushCode(`$parent: ${l},`),e.pushCode(`$root: ${l}.$root,`),!this.options.readUntil&&i===void 0&&e.pushCode(`$index: ${I} - ${C},`)}e.pushCode("});"),e.pushCode(`var ${o} = ${a}.result; offset = ${a}.offset;`),n!==this.alias&&e.addReference(n)}else{const a=C1[n],l=r1[n];e.pushCode(`var ${o} = dataView.get${a}(offset, ${l});`),e.pushCode(`offset += ${Yo[n]};`)}else if(n instanceof Kg){e.pushCode(`var ${o} = {};`);const a=e.generateVariable();e.pushScope(o),e.useContextVariables&&(e.pushCode(`${o}.$parent = ${a};`),e.pushCode(`${o}.$root = ${a}.$root;`),!this.options.readUntil&&i===void 0&&e.pushCode(`${o}.$index = ${I} - ${C};`)),n.generate(e),e.useContextVariables&&(e.pushCode(`delete ${o}.$parent;`),e.pushCode(`delete ${o}.$root;`),e.pushCode(`delete ${o}.$index;`)),e.popScope()}if(s?e.pushCode(`${r}[${o}.${A}] = ${o};`):e.pushCode(`${r}.push(${o});`),e.pushCode("}"),typeof this.options.readUntil=="function"){const a=this.options.readUntil,l=e.addImport(a);e.pushCode(`while (!${l}.call(${e.generateVariable()}, ${o}, buffer.subarray(offset)));`)}}generateChoiceCase(e,I,i){if(typeof i=="string"){const n=e.generateVariable(this.varName);if(ko.has(i)){const C=e.generateTmpVariable();e.pushCode(`var ${C} = ${_u+i}(offset, {`),e.useContextVariables&&(e.pushCode(`$parent: ${n}.$parent,`),e.pushCode(`$root: ${n}.$root,`)),e.pushCode("});"),e.pushCode(`${n} = ${C}.result; offset = ${C}.offset;`),i!==this.alias&&e.addReference(i)}else{const C=C1[i],r=r1[i];e.pushCode(`${n} = dataView.get${C}(offset, ${r});`),e.pushCode(`offset += ${Yo[i]}`)}}else i instanceof Kg&&(e.pushPath(I),i.generate(e),e.popPath(I))}generateChoice(e){const I=e.generateOption(this.options.tag),i=e.generateVariable(this.varName);if(this.varName&&(e.pushCode(`${i} = {};`),e.useContextVariables)){const n=e.generateVariable();e.pushCode(`${i}.$parent = ${n};`),e.pushCode(`${i}.$root = ${n}.$root;`)}e.pushCode(`switch(${I}) {`);for(const n in this.options.choices){const C=parseInt(n,10),r=this.options.choices[C];e.pushCode(`case ${C}:`),this.generateChoiceCase(e,this.varName,r),e.pushCode("break;")}e.pushCode("default:"),this.options.defaultChoice?this.generateChoiceCase(e,this.varName,this.options.defaultChoice):e.generateError(`"Met undefined tag value " + ${I} + " at choice"`),e.pushCode("}"),this.varName&&e.useContextVariables&&(e.pushCode(`delete ${i}.$parent;`),e.pushCode(`delete ${i}.$root;`))}generateNest(e){const I=e.generateVariable(this.varName);if(this.options.type instanceof Kg){if(this.varName&&(e.pushCode(`${I} = {};`),e.useContextVariables)){const i=e.generateVariable();e.pushCode(`${I}.$parent = ${i};`),e.pushCode(`${I}.$root = ${i}.$root;`)}e.pushPath(this.varName),this.options.type.generate(e),e.popPath(this.varName),this.varName&&e.useContextVariables&&e.useContextVariables&&(e.pushCode(`delete ${I}.$parent;`),e.pushCode(`delete ${I}.$root;`))}else if(ko.has(this.options.type)){const i=e.generateTmpVariable();if(e.pushCode(`var ${i} = ${_u+this.options.type}(offset, {`),e.useContextVariables){const n=e.generateVariable();e.pushCode(`$parent: ${n},`),e.pushCode(`$root: ${n}.$root,`)}e.pushCode("});"),e.pushCode(`${I} = ${i}.result; offset = ${i}.offset;`),this.options.type!==this.alias&&e.addReference(this.options.type)}}generateWrapper(e){const I=e.generateVariable(this.varName),i=e.generateTmpVariable();if(typeof this.options.readUntil=="function"){const A=this.options.readUntil,s=e.generateTmpVariable(),a=e.generateTmpVariable();e.pushCode(`var ${s} = offset;`),e.pushCode(`var ${a} = 0;`),e.pushCode("while (offset < buffer.length) {"),e.pushCode(`${a} = dataView.getUint8(offset);`);const l=e.addImport(A);e.pushCode(`if (${l}.call(${e.generateVariable()}, ${a}, buffer.subarray(offset))) break;`),e.pushCode("offset += 1;"),e.pushCode("}"),e.pushCode(`${i} = buffer.subarray(${s}, offset);`)}else if(this.options.readUntil==="eof")e.pushCode(`${i} = buffer.subarray(offset);`);else{const A=e.generateOption(this.options.length);e.pushCode(`${i} = buffer.subarray(offset, offset + ${A});`),e.pushCode(`offset += ${A};`)}this.options.clone&&e.pushCode(`${i} = buffer.constructor.from(${i});`);const n=e.generateTmpVariable(),C=e.generateTmpVariable(),r=e.generateTmpVariable(),o=e.addImport(this.options.wrapper);if(e.pushCode(`${i} = ${o}.call(this, ${i}).subarray(0);`),e.pushCode(`var ${n} = buffer;`),e.pushCode(`var ${C} = offset;`),e.pushCode(`var ${r} = dataView;`),e.pushCode(`buffer = ${i};`),e.pushCode("offset = 0;"),e.pushCode("dataView = new DataView(buffer.buffer, buffer.byteOffset, buffer.length);"),this.options.type instanceof Kg)this.varName&&e.pushCode(`${I} = {};`),e.pushPath(this.varName),this.options.type.generate(e),e.popPath(this.varName);else if(ko.has(this.options.type)){const A=e.generateTmpVariable();e.pushCode(`var ${A} = ${_u+this.options.type}(0);`),e.pushCode(`${I} = ${A}.result;`),this.options.type!==this.alias&&e.addReference(this.options.type)}e.pushCode(`buffer = ${n};`),e.pushCode(`dataView = ${r};`),e.pushCode(`offset = ${C};`)}generateFormatter(e,I,i){if(typeof i=="function"){const n=e.addImport(i);e.pushCode(`${I} = ${n}.call(${e.generateVariable()}, ${I});`)}}generatePointer(e){const I=this.options.type,i=e.generateOption(this.options.offset),n=e.generateTmpVariable(),C=e.generateVariable(this.varName);if(e.pushCode(`var ${n} = offset;`),e.pushCode(`offset = ${i};`),this.options.type instanceof Kg){if(e.pushCode(`${C} = {};`),e.useContextVariables){const r=e.generateVariable();e.pushCode(`${C}.$parent = ${r};`),e.pushCode(`${C}.$root = ${r}.$root;`)}e.pushPath(this.varName),this.options.type.generate(e),e.popPath(this.varName),e.useContextVariables&&(e.pushCode(`delete ${C}.$parent;`),e.pushCode(`delete ${C}.$root;`))}else if(ko.has(this.options.type)){const r=e.generateTmpVariable();if(e.pushCode(`var ${r} = ${_u+this.options.type}(offset, {`),e.useContextVariables){const o=e.generateVariable();e.pushCode(`$parent: ${o},`),e.pushCode(`$root: ${o}.$root,`)}e.pushCode("});"),e.pushCode(`${C} = ${r}.result; offset = ${r}.offset;`),this.options.type!==this.alias&&e.addReference(this.options.type)}else if(Object.keys(Yo).indexOf(this.options.type)>=0){const r=C1[I],o=r1[I];e.pushCode(`${C} = dataView.get${r}(offset, ${o});`),e.pushCode(`offset += ${Yo[I]};`)}e.pushCode(`offset = ${n};`)}generateSaveOffset(e){const I=e.generateVariable(this.varName);e.pushCode(`${I} = offset`)}}var yHe={},V$={},zh={},_w={};Object.defineProperty(_w,"__esModule",{value:!0});function R$(g,e){if(!(g instanceof e))throw new TypeError("Cannot call a class as a function")}function nle(g,e){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function wG(g){if(g===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return g}function Mqt(g,e){if(e&&(typeof e=="object"||typeof e=="function"))return e;if(e!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return wG(g)}function zqt(g){var e=Eqt();return function(){var i=S0(g),n;if(e){var C=S0(this).constructor;n=Reflect.construct(i,arguments,C)}else n=i.apply(this,arguments);return Mqt(this,n)}}function Pqt(g,e){for(;!Object.prototype.hasOwnProperty.call(g,e)&&(g=S0(g),g!==null););return g}function UW(){return typeof Reflect<"u"&&Reflect.get?UW=Reflect.get.bind():UW=function(e,I,i){var n=Pqt(e,I);if(n){var C=Object.getOwnPropertyDescriptor(n,I);return C.get?C.get.call(arguments.length<3?e:i):C.value}},UW.apply(this,arguments)}var Cle=function(){function g(){R$(this,g),Object.defineProperty(this,"listeners",{value:{},writable:!0,configurable:!0})}return W$(g,[{key:"addEventListener",value:function(I,i,n){I in this.listeners||(this.listeners[I]=[]),this.listeners[I].push({callback:i,options:n})}},{key:"removeEventListener",value:function(I,i){if(I in this.listeners){for(var n=this.listeners[I],C=0,r=n.length;C"u")n=new Error("This operation was aborted"),n.name="AbortError";else try{n=new DOMException("signal is aborted without reason")}catch{n=new Error("This operation was aborted"),n.name="AbortError"}this.signal.reason=n,this.signal.dispatchEvent(i)}},{key:"toString",value:function(){return"[object AbortController]"}}]),g}();typeof Symbol<"u"&&Symbol.toStringTag&&(ZHe.prototype[Symbol.toStringTag]="AbortController",X$.prototype[Symbol.toStringTag]="AbortSignal");function Jqt(g){return g.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL?(console.log("__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL=true is set, will force install polyfill"),!0):typeof g.Request=="function"&&!g.Request.prototype.hasOwnProperty("signal")||!g.AbortController}function Oqt(g){typeof g=="function"&&(g={fetch:g});var e=g,I=e.fetch,i=e.Request,n=i===void 0?I.Request:i,C=e.AbortController,r=e.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL,o=r===void 0?!1:r;if(!Jqt({fetch:I,Request:n,AbortController:C,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:o}))return{fetch:I,Request:A};var A=n;(A&&!A.prototype.hasOwnProperty("signal")||o)&&(A=function(c,u){var d;u&&u.signal&&(d=u.signal,delete u.signal);var h=new n(c,u);return d&&Object.defineProperty(h,"signal",{writable:!1,enumerable:!1,configurable:!0,value:d}),h},A.prototype=n.prototype);var s=I,a=function(c,u){var d=A&&A.prototype.isPrototypeOf(c)?c.signal:u?u.signal:void 0;if(d){var h;try{h=new DOMException("Aborted","AbortError")}catch{h=new Error("Aborted"),h.name="AbortError"}if(d.aborted)return Promise.reject(h);var m=new Promise(function(f,b){d.addEventListener("abort",function(){return b(h)},{once:!0})});return u&&u.signal&&delete u.signal,Promise.race([m,s(c,u)])}return s(c,u)};return{fetch:a,Request:A}}_w.AbortController=ZHe;_w.AbortSignal=X$;_w.abortableFetch=Oqt;Object.defineProperty(zh,"__esModule",{value:!0});zh.AbortSignal=zh.AbortController=void 0;const GHe=_w;var Q2=function(){if(typeof self<"u")return self;if(typeof window<"u")return window;if(typeof oh<"u")return oh;throw new Error("unable to locate global object")};let Lqt=typeof Q2().AbortController>"u"?GHe.AbortController:Q2().AbortController;zh.AbortController=Lqt;let _qt=typeof Q2().AbortController>"u"?GHe.AbortSignal:Q2().AbortSignal;zh.AbortSignal=_qt;var H$={};Object.defineProperty(H$,"__esModule",{value:!0});const Uqt=zh;class Qqt{}class jqt{constructor(){this.signals=new Set,this.abortController=new Uqt.AbortController}addSignal(e=new Qqt){if(this.signal.aborted)throw new Error("cannot add a signal, already aborted!");this.signals.add(e),e.aborted?this.handleAborted(e):typeof e.addEventListener=="function"&&e.addEventListener("abort",()=>{this.handleAborted(e)})}handleAborted(e){this.signals.delete(e),this.signals.size===0&&this.abortController.abort()}get signal(){return this.abortController.signal}abort(){this.abortController.abort()}}H$.default=jqt;var T$={};Object.defineProperty(T$,"__esModule",{value:!0});class $qt{constructor(){this.callbacks=new Set}addCallback(e=()=>{}){this.callbacks.add(e),e(this.currentMessage)}callback(e){this.currentMessage=e,this.callbacks.forEach(I=>{I(e)})}}T$.default=$qt;var BHe=oh&&oh.__importDefault||function(g){return g&&g.__esModule?g:{default:g}};Object.defineProperty(V$,"__esModule",{value:!0});const qqt=zh,eeg=BHe(H$),teg=BHe(T$);class j2{constructor({fill:e,cache:I}){if(typeof e!="function")throw new TypeError("must pass a fill function");if(typeof I!="object")throw new TypeError("must pass a cache object");if(typeof I.get!="function"||typeof I.set!="function"||typeof I.delete!="function")throw new TypeError("cache must implement get(key), set(key, val), and and delete(key)");this.cache=I,this.fillCallback=e}static isAbortException(e){return e.name==="AbortError"||e.code==="ERR_ABORTED"||e.message==="AbortError: aborted"||e.message==="Error: aborted"}evict(e,I){this.cache.get(e)===I&&this.cache.delete(e)}fill(e,I,i,n){const C=new eeg.default,r=new teg.default;r.addCallback(n);const o={aborter:C,promise:this.fillCallback(I,C.signal,A=>{r.callback(A)}),settled:!1,statusReporter:r,get aborted(){return this.aborter.signal.aborted}};o.aborter.addSignal(i),o.aborter.signal.addEventListener("abort",()=>{o.settled||this.evict(e,o)}),o.promise.then(()=>{o.settled=!0},()=>{o.settled=!0,this.evict(e,o)}).catch(A=>{throw console.error(A),A}),this.cache.set(e,o)}static checkSinglePromise(e,I){function i(){if(I&&I.aborted)throw Object.assign(new Error("aborted"),{code:"ERR_ABORTED"})}return e.then(n=>(i(),n),n=>{throw i(),n})}has(e){return this.cache.has(e)}get(e,I,i,n){if(!i&&I instanceof qqt.AbortSignal)throw new TypeError("second get argument appears to be an AbortSignal, perhaps you meant to pass `null` for the fill data?");const C=this.cache.get(e);return C?C.aborted&&!C.settled?(this.evict(e,C),this.get(e,I,i,n)):C.settled?C.promise:(C.aborter.addSignal(i),C.statusReporter.addCallback(n),j2.checkSinglePromise(C.promise,i)):(this.fill(e,I,i,n),j2.checkSinglePromise(this.cache.get(e).promise,i))}delete(e){const I=this.cache.get(e);I&&(I.settled||I.aborter.abort(),this.cache.delete(e))}clear(){const e=this.cache.keys();let I=0;for(let i=e.next();!i.done;i=e.next())this.delete(i.value),I+=1;return I}}V$.default=j2;var geg=oh&&oh.__importDefault||function(g){return g&&g.__esModule?g:{default:g}};Object.defineProperty(yHe,"__esModule",{value:!0});const Ieg=geg(V$);var ieg=yHe.default=Ieg.default;class fc{constructor(e,I){this.ranges=arguments.length===2?[{min:e,max:I}]:0 in e?Object.assign({},e):[e]}min(){return this.ranges[0].min}max(){return this.ranges[this.ranges.length-1].max}contains(e){for(let I=0;I=e)return!0}return!1}isContiguous(){return this.ranges.length>1}getRanges(){return this.ranges.map(e=>new fc(e.min,e.max))}toString(){return this.ranges.map(e=>`[${e.min}-${e.max}]`).join(",")}union(e){const I=this.getRanges().concat(e.getRanges()).sort(this.rangeOrder),i=[];let n=I[0];for(let C=1;Cn.max()+1?(i.push(n),n=r):r.max()>n.max()&&(n=new fc(n.min(),r.max()))}return i.push(n),i.length===1?i[0]:new fc(i)}intersection(e){let I=this,i=e;const n=this.ranges(),C=i.ranges(),r=n.length,o=C.length;let A=0,s=0;const a=[];for(;A=l&&a.push(new fc(l,c)),I.max()>i.max()?s+=1:A+=1}if(a.length===0)throw new Error("found range of length 0");return a.length===1?a[0]:new fc(a)}coverage(){let e=0;const I=this.ranges();for(let i=0;in.min()?1:i.max()i.max()?1:0}}function Zy(g){let e=g.length;for(;--e>=0;)g[e]=0}const neg=3,Ceg=258,vHe=29,reg=256,oeg=reg+1+vHe,SHe=30,Aeg=512,aeg=new Array((oeg+2)*2);Zy(aeg);const seg=new Array(SHe*2);Zy(seg);const leg=new Array(Aeg);Zy(leg);const ceg=new Array(Ceg-neg+1);Zy(ceg);const ueg=new Array(vHe);Zy(ueg);const deg=new Array(SHe);Zy(deg);const heg=(g,e,I,i)=>{let n=g&65535|0,C=g>>>16&65535|0,r=0;for(;I!==0;){r=I>2e3?2e3:I,I-=r;do n=n+e[i++]|0,C=C+n|0;while(--r);n%=65521,C%=65521}return n|C<<16|0};var jO=heg;const meg=()=>{let g,e=[];for(var I=0;I<256;I++){g=I;for(var i=0;i<8;i++)g=g&1?3988292384^g>>>1:g>>>1;e[I]=g}return e},feg=new Uint32Array(meg()),peg=(g,e,I,i)=>{const n=feg,C=i+I;g^=-1;for(let r=i;r>>8^n[(g^e[r])&255];return g^-1};var kA=peg,$O={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"},N$={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8};const beg=(g,e)=>Object.prototype.hasOwnProperty.call(g,e);var yeg=function(g){const e=Array.prototype.slice.call(arguments,1);for(;e.length;){const I=e.shift();if(I){if(typeof I!="object")throw new TypeError(I+"must be non-object");for(const i in I)beg(I,i)&&(g[i]=I[i])}}return g},Zeg=g=>{let e=0;for(let i=0,n=g.length;i=252?6:g>=248?5:g>=240?4:g>=224?3:g>=192?2:1;dS[254]=dS[254]=1;var Geg=g=>{if(typeof TextEncoder=="function"&&TextEncoder.prototype.encode)return new TextEncoder().encode(g);let e,I,i,n,C,r=g.length,o=0;for(n=0;n>>6,e[C++]=128|I&63):I<65536?(e[C++]=224|I>>>12,e[C++]=128|I>>>6&63,e[C++]=128|I&63):(e[C++]=240|I>>>18,e[C++]=128|I>>>12&63,e[C++]=128|I>>>6&63,e[C++]=128|I&63);return e};const Beg=(g,e)=>{if(e<65534&&g.subarray&&VHe)return String.fromCharCode.apply(null,g.length===e?g:g.subarray(0,e));let I="";for(let i=0;i{const I=e||g.length;if(typeof TextDecoder=="function"&&TextDecoder.prototype.decode)return new TextDecoder().decode(g.subarray(0,e));let i,n;const C=new Array(I*2);for(n=0,i=0;i4){C[n++]=65533,i+=o-1;continue}for(r&=o===2?31:o===3?15:7;o>1&&i1){C[n++]=65533;continue}r<65536?C[n++]=r:(r-=65536,C[n++]=55296|r>>10&1023,C[n++]=56320|r&1023)}return Beg(C,n)},Seg=(g,e)=>{e=e||g.length,e>g.length&&(e=g.length);let I=e-1;for(;I>=0&&(g[I]&192)===128;)I--;return I<0||I===0?e:I+dS[g[I]]>e?I:e},qO={string2buf:Geg,buf2string:veg,utf8border:Seg};function weg(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0}var Veg=weg;const o1=16209,Reg=16191;var Weg=function(e,I){let i,n,C,r,o,A,s,a,l,c,u,d,h,m,f,b,p,y,Z,v,G,B,w,R;const S=e.state;i=e.next_in,w=e.input,n=i+(e.avail_in-5),C=e.next_out,R=e.output,r=C-(I-e.avail_out),o=C+(e.avail_out-257),A=S.dmax,s=S.wsize,a=S.whave,l=S.wnext,c=S.window,u=S.hold,d=S.bits,h=S.lencode,m=S.distcode,f=(1<>>24,u>>>=y,d-=y,y=p>>>16&255,y===0)R[C++]=p&65535;else if(y&16){Z=p&65535,y&=15,y&&(d>>=y,d-=y),d<15&&(u+=w[i++]<>>24,u>>>=y,d-=y,y=p>>>16&255,y&16){if(v=p&65535,y&=15,dA){e.msg="invalid distance too far back",S.mode=o1;break e}if(u>>>=y,d-=y,y=C-r,v>y){if(y=v-y,y>a&&S.sane){e.msg="invalid distance too far back",S.mode=o1;break e}if(G=0,B=c,l===0){if(G+=s-y,y2;)R[C++]=B[G++],R[C++]=B[G++],R[C++]=B[G++],Z-=3;Z&&(R[C++]=B[G++],Z>1&&(R[C++]=B[G++]))}else{G=C-v;do R[C++]=R[G++],R[C++]=R[G++],R[C++]=R[G++],Z-=3;while(Z>2);Z&&(R[C++]=R[G++],Z>1&&(R[C++]=R[G++]))}}else if(y&64){e.msg="invalid distance code",S.mode=o1;break e}else{p=m[(p&65535)+(u&(1<>3,i-=Z,d-=Z<<3,u&=(1<{const A=o.bits;let s=0,a=0,l=0,c=0,u=0,d=0,h=0,m=0,f=0,b=0,p,y,Z,v,G,B=null,w;const R=new Uint16Array(df+1),S=new Uint16Array(df+1);let X=null,W,V,H;for(s=0;s<=df;s++)R[s]=0;for(a=0;a=1&&R[c]===0;c--);if(u>c&&(u=c),c===0)return n[C++]=1<<24|64<<16|0,n[C++]=1<<24|64<<16|0,o.bits=1,0;for(l=1;l0&&(g===Ale||c!==1))return-1;for(S[1]=0,s=1;srle||g===ale&&f>ole)return 1;for(;;){W=s-h,r[a]+1=w?(V=X[r[a]-w],H=B[r[a]-w]):(V=32+64,H=0),p=1<>h)+y]=W<<24|V<<16|H|0;while(y!==0);for(p=1<>=1;if(p!==0?(b&=p-1,b+=p):b=0,a++,--R[s]===0){if(s===c)break;s=e[I+r[a]]}if(s>u&&(b&v)!==Z){for(h===0&&(h=u),G+=l,d=s-h,m=1<rle||g===ale&&f>ole)return 1;Z=b&v,n[Z]=u<<24|d<<16|G-C|0}}return b!==0&&(n[G+b]=s-h<<24|64<<16|0),o.bits=u,0};var PB=keg;const Yeg=0,RHe=1,WHe=2,{Z_FINISH:sle,Z_BLOCK:Keg,Z_TREES:A1,Z_OK:Ph,Z_STREAM_END:xeg,Z_NEED_DICT:Deg,Z_STREAM_ERROR:ao,Z_DATA_ERROR:XHe,Z_MEM_ERROR:HHe,Z_BUF_ERROR:Feg,Z_DEFLATED:lle}=N$,yY=16180,cle=16181,ule=16182,dle=16183,hle=16184,mle=16185,fle=16186,ple=16187,ble=16188,yle=16189,$2=16190,Qa=16191,HF=16192,Zle=16193,TF=16194,Gle=16195,Ble=16196,vle=16197,Sle=16198,a1=16199,s1=16200,wle=16201,Vle=16202,Rle=16203,Wle=16204,Xle=16205,NF=16206,Hle=16207,Tle=16208,vI=16209,THe=16210,NHe=16211,Eeg=852,Meg=592,zeg=15,Peg=zeg,Nle=g=>(g>>>24&255)+(g>>>8&65280)+((g&65280)<<8)+((g&255)<<24);function Jeg(){this.strm=null,this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Uint16Array(320),this.work=new Uint16Array(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}const Wm=g=>{if(!g)return 1;const e=g.state;return!e||e.strm!==g||e.modeNHe?1:0},kHe=g=>{if(Wm(g))return ao;const e=g.state;return g.total_in=g.total_out=e.total=0,g.msg="",e.wrap&&(g.adler=e.wrap&1),e.mode=yY,e.last=0,e.havedict=0,e.flags=-1,e.dmax=32768,e.head=null,e.hold=0,e.bits=0,e.lencode=e.lendyn=new Int32Array(Eeg),e.distcode=e.distdyn=new Int32Array(Meg),e.sane=1,e.back=-1,Ph},YHe=g=>{if(Wm(g))return ao;const e=g.state;return e.wsize=0,e.whave=0,e.wnext=0,kHe(g)},KHe=(g,e)=>{let I;if(Wm(g))return ao;const i=g.state;return e<0?(I=0,e=-e):(I=(e>>4)+5,e<48&&(e&=15)),e&&(e<8||e>15)?ao:(i.window!==null&&i.wbits!==e&&(i.window=null),i.wrap=I,i.wbits=e,YHe(g))},xHe=(g,e)=>{if(!g)return ao;const I=new Jeg;g.state=I,I.strm=g,I.window=null,I.mode=yY;const i=KHe(g,e);return i!==Ph&&(g.state=null),i},Oeg=g=>xHe(g,Peg);let kle=!0,kF,YF;const Leg=g=>{if(kle){kF=new Int32Array(512),YF=new Int32Array(32);let e=0;for(;e<144;)g.lens[e++]=8;for(;e<256;)g.lens[e++]=9;for(;e<280;)g.lens[e++]=7;for(;e<288;)g.lens[e++]=8;for(PB(RHe,g.lens,0,288,kF,0,g.work,{bits:9}),e=0;e<32;)g.lens[e++]=5;PB(WHe,g.lens,0,32,YF,0,g.work,{bits:5}),kle=!1}g.lencode=kF,g.lenbits=9,g.distcode=YF,g.distbits=5},DHe=(g,e,I,i)=>{let n;const C=g.state;return C.window===null&&(C.wsize=1<=C.wsize?(C.window.set(e.subarray(I-C.wsize,I),0),C.wnext=0,C.whave=C.wsize):(n=C.wsize-C.wnext,n>i&&(n=i),C.window.set(e.subarray(I-i,I-i+n),C.wnext),i-=n,i?(C.window.set(e.subarray(I-i,I),0),C.wnext=i,C.whave=C.wsize):(C.wnext+=n,C.wnext===C.wsize&&(C.wnext=0),C.whave{let I,i,n,C,r,o,A,s,a,l,c,u,d,h,m=0,f,b,p,y,Z,v,G,B;const w=new Uint8Array(4);let R,S;const X=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);if(Wm(g)||!g.output||!g.input&&g.avail_in!==0)return ao;I=g.state,I.mode===Qa&&(I.mode=HF),r=g.next_out,n=g.output,A=g.avail_out,C=g.next_in,i=g.input,o=g.avail_in,s=I.hold,a=I.bits,l=o,c=A,B=Ph;e:for(;;)switch(I.mode){case yY:if(I.wrap===0){I.mode=HF;break}for(;a<16;){if(o===0)break e;o--,s+=i[C++]<>>8&255,I.check=kA(I.check,w,2,0),s=0,a=0,I.mode=cle;break}if(I.head&&(I.head.done=!1),!(I.wrap&1)||(((s&255)<<8)+(s>>8))%31){g.msg="incorrect header check",I.mode=vI;break}if((s&15)!==lle){g.msg="unknown compression method",I.mode=vI;break}if(s>>>=4,a-=4,G=(s&15)+8,I.wbits===0&&(I.wbits=G),G>15||G>I.wbits){g.msg="invalid window size",I.mode=vI;break}I.dmax=1<>8&1),I.flags&512&&I.wrap&4&&(w[0]=s&255,w[1]=s>>>8&255,I.check=kA(I.check,w,2,0)),s=0,a=0,I.mode=ule;case ule:for(;a<32;){if(o===0)break e;o--,s+=i[C++]<>>8&255,w[2]=s>>>16&255,w[3]=s>>>24&255,I.check=kA(I.check,w,4,0)),s=0,a=0,I.mode=dle;case dle:for(;a<16;){if(o===0)break e;o--,s+=i[C++]<>8),I.flags&512&&I.wrap&4&&(w[0]=s&255,w[1]=s>>>8&255,I.check=kA(I.check,w,2,0)),s=0,a=0,I.mode=hle;case hle:if(I.flags&1024){for(;a<16;){if(o===0)break e;o--,s+=i[C++]<>>8&255,I.check=kA(I.check,w,2,0)),s=0,a=0}else I.head&&(I.head.extra=null);I.mode=mle;case mle:if(I.flags&1024&&(u=I.length,u>o&&(u=o),u&&(I.head&&(G=I.head.extra_len-I.length,I.head.extra||(I.head.extra=new Uint8Array(I.head.extra_len)),I.head.extra.set(i.subarray(C,C+u),G)),I.flags&512&&I.wrap&4&&(I.check=kA(I.check,i,u,C)),o-=u,C+=u,I.length-=u),I.length))break e;I.length=0,I.mode=fle;case fle:if(I.flags&2048){if(o===0)break e;u=0;do G=i[C+u++],I.head&&G&&I.length<65536&&(I.head.name+=String.fromCharCode(G));while(G&&u>9&1,I.head.done=!0),g.adler=I.check=0,I.mode=Qa;break;case yle:for(;a<32;){if(o===0)break e;o--,s+=i[C++]<>>=a&7,a-=a&7,I.mode=NF;break}for(;a<3;){if(o===0)break e;o--,s+=i[C++]<>>=1,a-=1,s&3){case 0:I.mode=Zle;break;case 1:if(Leg(I),I.mode=a1,e===A1){s>>>=2,a-=2;break e}break;case 2:I.mode=Ble;break;case 3:g.msg="invalid block type",I.mode=vI}s>>>=2,a-=2;break;case Zle:for(s>>>=a&7,a-=a&7;a<32;){if(o===0)break e;o--,s+=i[C++]<>>16^65535)){g.msg="invalid stored block lengths",I.mode=vI;break}if(I.length=s&65535,s=0,a=0,I.mode=TF,e===A1)break e;case TF:I.mode=Gle;case Gle:if(u=I.length,u){if(u>o&&(u=o),u>A&&(u=A),u===0)break e;n.set(i.subarray(C,C+u),r),o-=u,C+=u,A-=u,r+=u,I.length-=u;break}I.mode=Qa;break;case Ble:for(;a<14;){if(o===0)break e;o--,s+=i[C++]<>>=5,a-=5,I.ndist=(s&31)+1,s>>>=5,a-=5,I.ncode=(s&15)+4,s>>>=4,a-=4,I.nlen>286||I.ndist>30){g.msg="too many length or distance symbols",I.mode=vI;break}I.have=0,I.mode=vle;case vle:for(;I.have>>=3,a-=3}for(;I.have<19;)I.lens[X[I.have++]]=0;if(I.lencode=I.lendyn,I.lenbits=7,R={bits:I.lenbits},B=PB(Yeg,I.lens,0,19,I.lencode,0,I.work,R),I.lenbits=R.bits,B){g.msg="invalid code lengths set",I.mode=vI;break}I.have=0,I.mode=Sle;case Sle:for(;I.have>>24,b=m>>>16&255,p=m&65535,!(f<=a);){if(o===0)break e;o--,s+=i[C++]<>>=f,a-=f,I.lens[I.have++]=p;else{if(p===16){for(S=f+2;a>>=f,a-=f,I.have===0){g.msg="invalid bit length repeat",I.mode=vI;break}G=I.lens[I.have-1],u=3+(s&3),s>>>=2,a-=2}else if(p===17){for(S=f+3;a>>=f,a-=f,G=0,u=3+(s&7),s>>>=3,a-=3}else{for(S=f+7;a>>=f,a-=f,G=0,u=11+(s&127),s>>>=7,a-=7}if(I.have+u>I.nlen+I.ndist){g.msg="invalid bit length repeat",I.mode=vI;break}for(;u--;)I.lens[I.have++]=G}}if(I.mode===vI)break;if(I.lens[256]===0){g.msg="invalid code -- missing end-of-block",I.mode=vI;break}if(I.lenbits=9,R={bits:I.lenbits},B=PB(RHe,I.lens,0,I.nlen,I.lencode,0,I.work,R),I.lenbits=R.bits,B){g.msg="invalid literal/lengths set",I.mode=vI;break}if(I.distbits=6,I.distcode=I.distdyn,R={bits:I.distbits},B=PB(WHe,I.lens,I.nlen,I.ndist,I.distcode,0,I.work,R),I.distbits=R.bits,B){g.msg="invalid distances set",I.mode=vI;break}if(I.mode=a1,e===A1)break e;case a1:I.mode=s1;case s1:if(o>=6&&A>=258){g.next_out=r,g.avail_out=A,g.next_in=C,g.avail_in=o,I.hold=s,I.bits=a,Weg(g,c),r=g.next_out,n=g.output,A=g.avail_out,C=g.next_in,i=g.input,o=g.avail_in,s=I.hold,a=I.bits,I.mode===Qa&&(I.back=-1);break}for(I.back=0;m=I.lencode[s&(1<>>24,b=m>>>16&255,p=m&65535,!(f<=a);){if(o===0)break e;o--,s+=i[C++]<>y)],f=m>>>24,b=m>>>16&255,p=m&65535,!(y+f<=a);){if(o===0)break e;o--,s+=i[C++]<>>=y,a-=y,I.back+=y}if(s>>>=f,a-=f,I.back+=f,I.length=p,b===0){I.mode=Xle;break}if(b&32){I.back=-1,I.mode=Qa;break}if(b&64){g.msg="invalid literal/length code",I.mode=vI;break}I.extra=b&15,I.mode=wle;case wle:if(I.extra){for(S=I.extra;a>>=I.extra,a-=I.extra,I.back+=I.extra}I.was=I.length,I.mode=Vle;case Vle:for(;m=I.distcode[s&(1<>>24,b=m>>>16&255,p=m&65535,!(f<=a);){if(o===0)break e;o--,s+=i[C++]<>y)],f=m>>>24,b=m>>>16&255,p=m&65535,!(y+f<=a);){if(o===0)break e;o--,s+=i[C++]<>>=y,a-=y,I.back+=y}if(s>>>=f,a-=f,I.back+=f,b&64){g.msg="invalid distance code",I.mode=vI;break}I.offset=p,I.extra=b&15,I.mode=Rle;case Rle:if(I.extra){for(S=I.extra;a>>=I.extra,a-=I.extra,I.back+=I.extra}if(I.offset>I.dmax){g.msg="invalid distance too far back",I.mode=vI;break}I.mode=Wle;case Wle:if(A===0)break e;if(u=c-A,I.offset>u){if(u=I.offset-u,u>I.whave&&I.sane){g.msg="invalid distance too far back",I.mode=vI;break}u>I.wnext?(u-=I.wnext,d=I.wsize-u):d=I.wnext-u,u>I.length&&(u=I.length),h=I.window}else h=n,d=r-I.offset,u=I.length;u>A&&(u=A),A-=u,I.length-=u;do n[r++]=h[d++];while(--u);I.length===0&&(I.mode=s1);break;case Xle:if(A===0)break e;n[r++]=I.length,A--,I.mode=s1;break;case NF:if(I.wrap){for(;a<32;){if(o===0)break e;o--,s|=i[C++]<{if(Wm(g))return ao;let e=g.state;return e.window&&(e.window=null),g.state=null,Ph},Qeg=(g,e)=>{if(Wm(g))return ao;const I=g.state;return I.wrap&2?(I.head=e,e.done=!1,Ph):ao},jeg=(g,e)=>{const I=e.length;let i,n,C;return Wm(g)||(i=g.state,i.wrap!==0&&i.mode!==$2)?ao:i.mode===$2&&(n=1,n=jO(n,e,I,0),n!==i.check)?XHe:(C=DHe(g,e,I,I),C?(i.mode=THe,HHe):(i.havedict=1,Ph))};var $eg=YHe,qeg=KHe,etg=kHe,ttg=Oeg,gtg=xHe,Itg=_eg,itg=Ueg,ntg=Qeg,Ctg=jeg,rtg="pako inflate (from Nodeca project)",cs={inflateReset:$eg,inflateReset2:qeg,inflateResetKeep:etg,inflateInit:ttg,inflateInit2:gtg,inflate:Itg,inflateEnd:itg,inflateGetHeader:ntg,inflateSetDictionary:Ctg,inflateInfo:rtg};function otg(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1}var Atg=otg;const FHe=Object.prototype.toString,{Z_NO_FLUSH:atg,Z_FINISH:stg,Z_OK:hS,Z_STREAM_END:KF,Z_NEED_DICT:xF,Z_STREAM_ERROR:ltg,Z_DATA_ERROR:Yle,Z_MEM_ERROR:ctg}=N$;function Uw(g){this.options=wHe.assign({chunkSize:1024*64,windowBits:15,to:""},g||{});const e=this.options;e.raw&&e.windowBits>=0&&e.windowBits<16&&(e.windowBits=-e.windowBits,e.windowBits===0&&(e.windowBits=-15)),e.windowBits>=0&&e.windowBits<16&&!(g&&g.windowBits)&&(e.windowBits+=32),e.windowBits>15&&e.windowBits<48&&(e.windowBits&15||(e.windowBits|=15)),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new Veg,this.strm.avail_out=0;let I=cs.inflateInit2(this.strm,e.windowBits);if(I!==hS)throw new Error($O[I]);if(this.header=new Atg,cs.inflateGetHeader(this.strm,this.header),e.dictionary&&(typeof e.dictionary=="string"?e.dictionary=qO.string2buf(e.dictionary):FHe.call(e.dictionary)==="[object ArrayBuffer]"&&(e.dictionary=new Uint8Array(e.dictionary)),e.raw&&(I=cs.inflateSetDictionary(this.strm,e.dictionary),I!==hS)))throw new Error($O[I])}Uw.prototype.push=function(g,e){const I=this.strm,i=this.options.chunkSize,n=this.options.dictionary;let C,r,o;if(this.ended)return!1;for(e===~~e?r=e:r=e===!0?stg:atg,FHe.call(g)==="[object ArrayBuffer]"?I.input=new Uint8Array(g):I.input=g,I.next_in=0,I.avail_in=I.input.length;;){for(I.avail_out===0&&(I.output=new Uint8Array(i),I.next_out=0,I.avail_out=i),C=cs.inflate(I,r),C===xF&&n&&(C=cs.inflateSetDictionary(I,n),C===hS?C=cs.inflate(I,r):C===Yle&&(C=xF));I.avail_in>0&&C===KF&&I.state.wrap>0&&g[I.next_in]!==0;)cs.inflateReset(I),C=cs.inflate(I,r);switch(C){case ltg:case Yle:case xF:case ctg:return this.onEnd(C),this.ended=!0,!1}if(o=I.avail_out,I.next_out&&(I.avail_out===0||C===KF))if(this.options.to==="string"){let A=qO.utf8border(I.output,I.next_out),s=I.next_out-A,a=qO.buf2string(I.output,A);I.next_out=s,I.avail_out=i-s,s&&I.output.set(I.output.subarray(A,A+s),0),this.onData(a)}else this.onData(I.output.length===I.next_out?I.output:I.output.subarray(0,I.next_out));if(!(C===hS&&o===0)){if(C===KF)return C=cs.inflateEnd(this.strm),this.onEnd(C),this.ended=!0,!0;if(I.avail_in===0)break}}return!0};Uw.prototype.onData=function(g){this.chunks.push(g)};Uw.prototype.onEnd=function(g){g===hS&&(this.options.to==="string"?this.result=this.chunks.join(""):this.result=wHe.flattenChunks(this.chunks)),this.chunks=[],this.err=g,this.msg=this.strm.msg};function k$(g,e){const I=new Uw(e);if(I.push(g),I.err)throw I.msg||$O[I.err];return I.result}function utg(g,e){return e=e||{},e.raw=!0,k$(g,e)}var dtg=Uw,htg=k$,mtg=utg,ftg=k$,ptg=N$,btg={Inflate:dtg,inflate:htg,inflateRaw:mtg,ungzip:ftg,constants:ptg};const{Inflate:cug,inflate:uug,inflateRaw:ytg,ungzip:dug}=btg;var Ztg=ytg;function Gtg(g){return Ztg(g.subarray(2))}class Btg extends Error{constructor(e){super(e),this.code="ERR_ABORTED"}}function vtg(g){g.sort((n,C)=>Number(n.offset)-Number(C.offset));const e=[];let I,i;for(let n=0;n=I}function Rtg(g){const e=g?"big":"little",I=new Kg().endianess(e).uint32("chromId").uint32("start").uint32("end").uint32("validCnt").floatle("minScore").floatle("maxScore").floatle("sumData").floatle("sumSqData").saveOffset("offset"),i=new Kg().endianess(e).uint8("isLeaf").skip(1).uint16("cnt").choice({tag:"isLeaf",choices:{1:new Kg().endianess(e).array("blocksToFetch",{length:"cnt",type:new Kg().endianess(e).uint32("startChrom").uint32("startBase").uint32("endChrom").uint32("endBase").uint64("blockOffset").uint64("blockSize").saveOffset("offset")}),0:new Kg().array("recurOffsets",{length:"cnt",type:new Kg().endianess(e).uint32("startChrom").uint32("startBase").uint32("endChrom").uint32("endBase").uint64("blockOffset").saveOffset("offset")})}}),n=new Kg().endianess(e).uint32("chromId").int32("start").int32("end").string("rest",{zeroTerminated:!0}).saveOffset("offset");return{bigWigParser:new Kg().endianess(e).skip(4).int32("blockStart").skip(4).uint32("itemStep").uint32("itemSpan").uint8("blockType").skip(1).uint16("itemCount").choice({tag:"blockType",choices:{[Vtg]:new Kg().array("items",{length:"itemCount",type:new Kg().floatle("score")}),[wtg]:new Kg().array("items",{length:"itemCount",type:new Kg().endianess(e).int32("start").floatle("score")}),[Stg]:new Kg().array("items",{length:"itemCount",type:new Kg().endianess(e).int32("start").int32("end").floatle("score")})}}),bigBedParser:n,summaryParser:I,leafParser:i}}class EHe{constructor(e,I,i,n,C,r){if(this.bbi=e,this.refsByName=I,this.cirTreeOffset=i,this.isBigEndian=n,this.isCompressed=C,this.blockType=r,this.featureCache=new ieg({cache:new E8e({maxSize:1e3}),fill:async(A,s)=>{const a=Number(A.length),l=Number(A.offset),{buffer:c}=await this.bbi.read(rh.Buffer.alloc(a),0,a,l,{signal:s});return c}}),!(i>=0))throw new Error("invalid cirTreeOffset!");const o=Rtg(n);this.leafParser=o.leafParser,this.bigBedParser=o.bigBedParser}async readWigData(e,I,i,n,C){try{const{refsByName:r,bbi:o,cirTreeOffset:A,isBigEndian:s}=this,a=r[e];a===void 0&&n.complete();const l={chrId:a,start:I,end:i};this.cirTreePromise||(this.cirTreePromise=o.read(rh.Buffer.alloc(48),0,48,Number(A),C));const{buffer:c}=await this.cirTreePromise,u=s?c.readUInt32BE(4):c.readUInt32LE(4);let d=[],h=0;const m=(y,Z,v)=>{try{const G=y.subarray(Z),B=this.leafParser.parse(G);if(B.blocksToFetch&&(d=d.concat(B.blocksToFetch.filter(f).map(w=>({offset:w.blockOffset,length:w.blockSize})))),B.recurOffsets){const w=B.recurOffsets.filter(f).map(R=>Number(R.blockOffset));w.length>0&&p(w,v+1)}}catch(G){n.error(G)}},f=y=>{const{startChrom:Z,startBase:v,endChrom:G,endBase:B}=y;return(Za||G===a&&B>=I)},b=async(y,Z,v)=>{try{const G=Z.max()-Z.min(),B=Z.min(),w=await this.featureCache.get(`${G}_${B}`,{length:G,offset:B},C.signal);for(let R=0;R{try{h+=y.length;const v=4+Number(u)*32;let G=new fc(y[0],y[0]+v);for(let B=1;Bb(y,B,Z))}catch(v){n.error(v)}};return p([Number(A)+48],1)}catch(r){n.error(r)}}parseSummaryBlock(e,I,i){const n=[];let C=I;const r=new DataView(e.buffer,e.byteOffset,e.length);for(;CDF(o.start,o.end,n.start,n.end)):C}parseBigWigBlock(e,I,i){const n=e.subarray(I),C=new DataView(n.buffer,n.byteOffset,n.length);let r=0;r+=4;const o=C.getInt32(r,!0);r+=8;const A=C.getUint32(r,!0);r+=4;const s=C.getUint32(r,!0);r+=4;const a=C.getUint8(r);r+=2;const l=C.getUint16(r,!0);r+=2;const c=new Array(l);switch(a){case 1:for(let u=0;uDF(u.start,u.end,i.start,i.end)):c}async readFeatures(e,I,i={}){try{const{blockType:n,isCompressed:C}=this,{signal:r,request:o}=i,A=vtg(I);l1(r),await Promise.all(A.map(async s=>{l1(r);const{length:a,offset:l}=s,c=await this.featureCache.get(`${a}_${l}`,s,r);s.blocks.forEach(u=>{l1(r);let d=Number(u.offset)-Number(s.offset),h=c;switch(C&&(h=Gtg(c.subarray(d)),d=0),l1(r),n){case"summary":e.next(this.parseSummaryBlock(h,d,o));break;case"bigwig":e.next(this.parseBigWigBlock(h,d,o));break;case"bigbed":e.next(this.parseBigBedBlock(h,d,Number(u.offset)*256,o));break;default:console.warn(`Don't know what to do with ${n}`)}})})),e.complete()}catch(n){e.error(n)}}}var eL=function(g,e){return eL=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(I,i){I.__proto__=i}||function(I,i){for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&(I[n]=i[n])},eL(g,e)};function Y$(g,e){if(typeof e!="function"&&e!==null)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");eL(g,e);function I(){this.constructor=g}g.prototype=e===null?Object.create(e):(I.prototype=e.prototype,new I)}function Kle(g){var e=typeof Symbol=="function"&&Symbol.iterator,I=e&&g[e],i=0;if(I)return I.call(g);if(g&&typeof g.length=="number")return{next:function(){return g&&i>=g.length&&(g=void 0),{value:g&&g[i++],done:!g}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function tL(g,e){var I=typeof Symbol=="function"&&g[Symbol.iterator];if(!I)return g;var i=I.call(g),n,C=[],r;try{for(;(e===void 0||e-- >0)&&!(n=i.next()).done;)C.push(n.value)}catch(o){r={error:o}}finally{try{n&&!n.done&&(I=i.return)&&I.call(i)}finally{if(r)throw r.error}}return C}function gL(g,e,I){if(I||arguments.length===2)for(var i=0,n=e.length,C;i{!_4(n)&&n.mark!=="brush"&&n.mark!=="rule"&&(I.push("genomic type is not encoded to either a x- or y- axis"),g=!1);const C=n.color;n.mark==="line"&&st(C)&&C.type==="quantitative"&&(I.push("`line` mark cannot be used with `quantitative` value"),g=!1)}),{valid:g,errorMessages:I}}function _4(e){let g;return["x","y","xe","ye","x1","y1","x1e","y1e"].reverse().forEach(I=>{const i=e[I];st(i)&&i.type==="genomic"&&(g=i)}),g}function C9e(e){let g;return["x","xe","y","ye","x1","y1","x1e","y1e"].reverse().forEach(I=>{const i=e[I];st(i)&&i.type==="genomic"&&(g=I)}),g}const Teg=[{name:"gene",channels:[{name:"startPosition",type:"genomic",required:!0},{name:"endPosition",type:"genomic",required:!0},{name:"strandColor",type:"nominal",required:!0},{name:"strandRow",type:"nominal",required:!0},{name:"opacity",type:"value",required:!1},{name:"geneHeight",type:"value",required:!1},{name:"geneLabel",type:"nominal",required:!0},{name:"geneLabelColor",type:"nominal",required:!0},{name:"geneLabelFontSize",type:"value",required:!1},{name:"geneLabelStroke",type:"value",required:!1},{name:"geneLabelStrokeThickness",type:"value",required:!1},{name:"geneLabelOpacity",type:"value",required:!1},{name:"type",type:"nominal",required:!0}],mapping:[{dataTransform:[{type:"filter",base:"type",oneOf:["gene"]},{type:"filter",base:"strandColor",oneOf:["-"]}],mark:"triangleLeft",x:{base:"startPosition",type:"genomic"},size:{base:"geneHeight",value:12},row:{base:"strandRow",type:"nominal",domain:["+","-"]},color:{base:"strandColor",type:"nominal",domain:["+","-"],range:["blue","red"]},opacity:{base:"opacity",value:.4},style:{align:"right"}},{dataTransform:[{type:"filter",base:"type",oneOf:["gene"]},{type:"filter",base:"strandColor",oneOf:["+"]}],mark:"triangleRight",x:{base:"endPosition",type:"genomic"},size:{base:"geneHeight",value:12},row:{base:"strandRow",type:"nominal",domain:["+","-"]},color:{base:"strandColor",type:"nominal",domain:["+","-"],range:["blue","red"]},opacity:{base:"opacity",value:.4},style:{align:"left"}},{dataTransform:[{type:"filter",base:"type",oneOf:["exon"]}],mark:"rect",x:{base:"startPosition",type:"genomic"},xe:{base:"endPosition",type:"genomic"},size:{base:"geneHeight",value:12},row:{base:"strandRow",type:"nominal",domain:["+","-"]},color:{base:"strandColor",type:"nominal",domain:["+","-"],range:["blue","red"]},opacity:{base:"opacity",value:.4}},{dataTransform:[{type:"filter",base:"type",oneOf:["gene"]},{type:"filter",base:"strandColor",oneOf:["+"]}],mark:"rect",x:{base:"startPosition",type:"genomic"},xe:{base:"endPosition",type:"genomic"},row:{base:"strandRow",type:"nominal",domain:["+","-"]},color:{base:"strandColor",type:"nominal",domain:["+","-"],range:["blue","red"]},opacity:{base:"opacity",value:.4},size:{value:3}},{dataTransform:[{type:"filter",base:"type",oneOf:["gene"]},{type:"filter",base:"strandColor",oneOf:["-"]}],mark:"rect",x:{base:"startPosition",type:"genomic"},xe:{base:"endPosition",type:"genomic"},row:{base:"strandRow",type:"nominal",domain:["+","-"]},color:{base:"strandColor",type:"nominal",domain:["+","-"],range:["blue","red"]},opacity:{base:"opacity",value:.4},size:{value:3}},{dataTransform:[{type:"filter",base:"type",oneOf:["gene"]}],mark:"text",text:{base:"geneLabel",type:"nominal"},x:{base:"startPosition",type:"genomic"},xe:{base:"endPosition",type:"genomic"},row:{base:"strandRow",type:"nominal",domain:["+","-"]},color:{base:"geneLabelColor",type:"nominal",domain:["+","-"],range:["blue","red"]},opacity:{base:"opacity",value:1},size:{base:"geneLabelFontSize",value:18},stroke:{base:"geneLabelStroke",value:"white"},strokeWidth:{base:"geneLabelStrokeThickness",value:2},visibility:[{operation:"less-than",measure:"width",threshold:"|xe-x|",transitionPadding:10,target:"mark"}]}]},{name:"ideogram",channels:[{name:"startPosition",type:"genomic",required:!0},{name:"endPosition",type:"genomic",required:!0},{name:"chrHeight",type:"value",required:!1},{name:"name",type:"nominal",required:!0},{name:"stainBackgroundColor",type:"nominal",required:!0},{name:"stainLabelColor",type:"nominal",required:!0},{name:"stainStroke",type:"value",required:!1},{name:"stainStrokeWidth",type:"value",required:!1}],mapping:[{mark:"rect",dataTransform:[{type:"filter",base:"stainBackgroundColor",oneOf:["acen"],not:!0}],color:{base:"stainBackgroundColor",type:"nominal",domain:["gneg","gpos25","gpos50","gpos75","gpos100","gvar","acen"],range:["white","lightgray","gray","gray","black","#7B9CC8","#DC4542"]},size:{base:"chrHeight",value:18},x:{base:"startPosition",type:"genomic"},xe:{base:"endPosition",type:"genomic"},stroke:{base:"stainStroke",value:"gray"},strokeWidth:{base:"stainStrokeWidth",value:.3}},{mark:"triangleRight",dataTransform:[{type:"filter",base:"stainBackgroundColor",oneOf:["acen"]},{type:"filter",base:"name",include:"q"}],color:{base:"stainBackgroundColor",type:"nominal",domain:["gneg","gpos25","gpos50","gpos75","gpos100","gvar","acen"],range:["white","lightgray","gray","gray","black","#7B9CC8","#DC4542"]},size:{base:"chrHeight",value:18},x:{base:"startPosition",type:"genomic"},xe:{base:"endPosition",type:"genomic"},stroke:{base:"stainStroke",value:"gray"},strokeWidth:{base:"stainStrokeWidth",value:.3}},{mark:"triangleLeft",dataTransform:[{type:"filter",base:"stainBackgroundColor",oneOf:["acen"]},{type:"filter",base:"name",include:"p"}],color:{base:"stainBackgroundColor",type:"nominal",domain:["gneg","gpos25","gpos50","gpos75","gpos100","gvar","acen"],range:["white","lightgray","gray","gray","black","#7B9CC8","#DC4542"]},size:{base:"chrHeight",value:18},x:{base:"startPosition",type:"genomic"},xe:{base:"endPosition",type:"genomic"},stroke:{base:"stainStroke",value:"gray"},strokeWidth:{base:"stainStrokeWidth",value:.3}},{mark:"text",dataTransform:[{type:"filter",base:"stainLabelColor",oneOf:["acen"],not:!0}],color:{base:"stainLabelColor",type:"nominal",domain:["gneg","gpos25","gpos50","gpos75","gpos100","gvar"],range:["black","black","black","black","white","black"]},text:{base:"name",type:"nominal"},x:{base:"startPosition",type:"genomic"},xe:{base:"endPosition",type:"genomic"},visibility:[{operation:"less-than",measure:"width",threshold:"|xe-x|",transitionPadding:10,target:"mark"}]}]},{name:"sequence",channels:[{name:"startPosition",type:"genomic",required:!0},{name:"endPosition",type:"genomic",required:!0},{name:"barLength",type:"quantitative",required:!0},{name:"baseBackground",type:"nominal",required:!0},{name:"baseLabelColor",type:"nominal",required:!0},{name:"baseLabelFontSize",type:"value",required:!1}],mapping:[{mark:"bar",x:{base:"startPosition",type:"genomic"},xe:{base:"endPosition",type:"genomic"},y:{base:"barLength",type:"quantitative",axis:"none"},color:{base:"baseBackground",type:"nominal",domain:["A","T","G","C"]}},{dataTransform:[{type:"filter",base:"barLength",oneOf:[0],not:!0}],mark:"text",x:{base:"startPosition",type:"genomic"},xe:{base:"endPosition",type:"genomic"},color:{base:"baseLabelColor",type:"nominal",domain:["A","T","G","C"],range:["white"]},text:{base:"baseBackground",type:"nominal"},size:{base:"baseLabelFontSize",value:18},visibility:[{operation:"less-than",measure:"width",threshold:"|xe-x|",transitionPadding:30,target:"mark"},{operation:"LT",measure:"zoomLevel",threshold:10,target:"track"}]}]}];function Neg(e,g){yX(e,(I,i,n)=>{var C,r;if(!lje(I))return;const{template:o}=I,A=g.find(c=>c.name===o);if(!A){I._invalidTrack=!0,console.warn(`There is no track template named '${o}'`);return}let s=!0;if(A.channels.forEach(c=>{c.required&&(!I.encoding||!(c.name in I.encoding))&&(s=!1,console.warn(`A template spec ('${o}') does not contain a required channel, ${c.name}`))}),!s){I._invalidTrack=!0;return}const a=JSON.parse(JSON.stringify(I));"encoding"in a&&delete a.encoding;const l={...a,alignment:"overlay",tracks:[],width:(C=I.width)!=null?C:100,height:(r=I.height)!=null?r:100};A.mapping.forEach(c=>{const u={data:I.data,mark:c.mark},{dataTransform:d}=c;d&&d.map(m=>{const f=m.base;f&&I.encoding&&f in I.encoding&&"field"in I.encoding[f]&&(delete m.base,m.field=I.encoding[f].field)});const h=I.encoding;h?Object.keys(c).filter(m=>m!=="mark").forEach(m=>{const f=JSON.parse(JSON.stringify(c[m]));if("base"in f){const b=f.base;if(b in h){const p=JSON.parse(JSON.stringify(h[b]));delete f.base;const y=Object.assign(f,JSON.parse(JSON.stringify(p)));u[m]=y}else delete f.base,u[m]=f}else u[m]=f}):Object.keys(c).filter(m=>m!=="mark").forEach(m=>{const f=JSON.parse(JSON.stringify(c[m]));"base"in f&&delete f.base,u[m]=f}),l.tracks.push(u)}),n[i]=l})}const nse=["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],fo={color:nse[0],size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:nse,quantitativeSizeRange:[2,6]},keg={base:"light",root:{background:"white",titleColor:"black",titleBackgroundColor:"transparent",titleFontSize:18,titleFontFamily:"Arial",titleAlign:"left",titleFontWeight:"bold",subtitleColor:"gray",subtitleBackgroundColor:"transparent",subtitleFontSize:16,subtitleFontFamily:"Arial",subtitleFontWeight:"normal",subtitleAlign:"left",showMousePosition:!0,mousePositionColor:"#000000"},track:{background:"transparent",alternatingBackground:"transparent",titleColor:"black",titleBackground:"white",titleFontSize:24,titleAlign:"left",outline:"black",outlineWidth:1},legend:{position:"top",background:"white",backgroundOpacity:.7,labelColor:"black",labelFontSize:12,labelFontWeight:"normal",labelFontFamily:"Arial",backgroundStroke:"#DBDBDB",tickColor:"black"},axis:{tickColor:"black",labelColor:"black",labelMargin:5,labelExcludeChrPrefix:!1,labelFontSize:12,labelFontWeight:"normal",labelFontFamily:"Arial",baselineColor:"black",gridColor:"#E3E3E3",gridStrokeWidth:1,gridStrokeType:"solid",gridStrokeDash:[4,4]},markCommon:{...fo},point:{...fo,size:3},rect:{...fo},triangle:{...fo},area:{...fo},line:{...fo},bar:{...fo},rule:{...fo,strokeWidth:1},link:{...fo,strokeWidth:1},text:{...fo,textAnchor:"middle",textFontWeight:"normal"},brush:{...fo,color:"gray",opacity:.3,stroke:"black",strokeWidth:1}},Cse=["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],Yeg={color:Cse[0],size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:Cse,quantitativeSizeRange:[2,6]},po={...Yeg,stroke:"white"},Keg={base:"dark",root:{background:"black",titleColor:"white",titleBackgroundColor:"transparent",titleFontSize:18,titleFontFamily:"Arial",titleAlign:"middle",titleFontWeight:"bold",subtitleColor:"lightgray",subtitleBackgroundColor:"transparent",subtitleFontSize:16,subtitleFontFamily:"Arial",subtitleAlign:"middle",subtitleFontWeight:"normal",showMousePosition:!0,mousePositionColor:"#FFFFFF"},track:{background:"transparent",alternatingBackground:"transparent",titleColor:"white",titleBackground:"black",titleFontSize:18,titleAlign:"left",outline:"white",outlineWidth:1},legend:{position:"right",background:"black",backgroundOpacity:.7,labelColor:"white",labelFontSize:12,labelFontWeight:"normal",labelFontFamily:"Arial",backgroundStroke:"#DBDBDB",tickColor:"white"},axis:{tickColor:"white",labelMargin:5,labelExcludeChrPrefix:!1,labelColor:"white",labelFontSize:10,labelFontWeight:"normal",labelFontFamily:"Arial",baselineColor:"white",gridColor:"gray",gridStrokeWidth:1,gridStrokeType:"solid",gridStrokeDash:[4,4]},markCommon:{...po},point:{...po,size:3},rect:{...po},triangle:{...po},area:{...po},line:{...po},bar:{...po},rule:{...po,strokeWidth:1},link:{...po,strokeWidth:1},text:{...po,textAnchor:"middle",textFontWeight:"normal"},brush:{...po,color:"lightgray",opacity:.3,stroke:"white",strokeWidth:1}},rse=["#D19000","#008F67","#005F96","#B86E97","#B55100","#4793BF","#C9C03"],bo={color:rse[0],size:1,stroke:"#3C3C3C",strokeWidth:0,opacity:1,nominalColorRange:rse,quantitativeSizeRange:[2,6]},Deg={base:"warm",root:{background:"#FFF8E8",titleColor:"#3C3C3C",subtitleColor:"gray",showMousePosition:!0,mousePositionColor:"#3C3C3C"},track:{titleColor:"#3C3C3C",titleBackground:"#FFF8E8",outline:"#3C3C3C",outlineWidth:1},legend:{background:"#FFF8E8",backgroundOpacity:.7,labelColor:"#3C3C3C",backgroundStroke:"#3C3C3C",tickColor:"3C3C3C"},axis:{tickColor:"#3C3C3C",labelColor:"#3C3C3C",baselineColor:"#3C3C3C",gridColor:"#E3E3E3",gridStrokeWidth:1},markCommon:{...bo},point:{...bo,size:3},rect:{...bo},triangle:{...bo},area:{...bo},line:{...bo},bar:{...bo},rule:{...bo,strokeWidth:1},link:{...bo,strokeWidth:1},text:{...bo,textAnchor:"middle",textFontWeight:"normal"},brush:{...bo,color:"lightgray",opacity:.3,stroke:"#3C3C3C",strokeWidth:1}},ose=["#F66A62","#05B230","#5692FF","#D764D6","#86E9D4","#6E6AD7","#FFFB00"],yo={color:ose[0],size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:ose,quantitativeSizeRange:[2,6]},xeg={base:"ggplot",root:{background:"white",titleColor:"black",titleFontSize:18,titleFontFamily:"Helvetica",titleAlign:"middle",titleFontWeight:"bold",titleBackgroundColor:"white",subtitleColor:"gray",subtitleFontSize:14,subtitleFontFamily:"Helvetica",subtitleAlign:"middle",subtitleFontWeight:"light",subtitleBackgroundColor:"white",showMousePosition:!0,mousePositionColor:"black"},track:{background:"#e8e8e8",alternatingBackground:"#d1d1d1",titleColor:"black",titleBackground:"white",outline:"black",outlineWidth:2},legend:{position:"right",background:"#e8e8e8",backgroundOpacity:1,labelColor:"black",backgroundStroke:"#e8e8e8",tickColor:"white"},axis:{tickColor:"white",labelColor:"black",baselineColor:"#e8e8e8",gridColor:"white",gridStrokeWidth:2},markCommon:{...yo},point:{...yo,size:3},rect:{...yo},triangle:{...yo},area:{...yo},line:{...yo},bar:{...yo},rule:{...yo,strokeWidth:1},link:{...yo,strokeWidth:1},text:{...yo,textAnchor:"middle",textFontWeight:"bold"},brush:{...yo,color:"black",opacity:.3,stroke:"black",strokeWidth:1}},Ase=["#37E649","#ED2D44","#AEAFEA","#EBAEAE","#CE7B3D","#8743E0","#5233F0"],Zo={color:Ase[0],size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:Ase,quantitativeSizeRange:[2,6]},Feg={base:"igv",root:{background:"white",titleColor:"white",titleAlign:"left",titleFontWeight:"bold",titleBackgroundColor:"#5f5f5f",subtitleColor:"#3b3b3b",subtitleAlign:"left",subtitleFontWeight:"bold",subtitleBackgroundColor:"#c4c4c4",showMousePosition:!0,mousePositionColor:"black"},track:{background:"white",alternatingBackground:"#e8e8e8",titleColor:"white",titleBackground:"#5F5F5F",outline:"#5F5F5F",outlineWidth:1},legend:{position:"top",background:"white",backgroundOpacity:1,labelColor:"black",backgroundStroke:"black",tickColor:"black"},axis:{tickColor:"black",labelColor:"black",baselineColor:"white",gridColor:"transparent",gridStrokeWidth:0},markCommon:{...Zo},point:{...Zo,size:3},rect:{...Zo},triangle:{...Zo},area:{...Zo},line:{...Zo},bar:{...Zo},rule:{...Zo,strokeWidth:1},link:{...Zo,strokeWidth:1},text:{...Zo,textAnchor:"middle",textFontWeight:"bold"},brush:{...Zo,color:"white",opacity:.3,stroke:"black",strokeWidth:1}},ase=["#CD9B1D","#8A668B","#40E0D0","#FF6969","#666666","#FAC902","#FE0000","#CC96CD","#D9D9D9"],Go={color:ase[0],size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:ase,quantitativeSizeRange:[2,6]},Eeg={base:"ensembl",root:{background:"white",titleColor:"#494949",titleFontSize:24,titleFontFamily:"GGX88",titleAlign:"left",titleFontWeight:"bold",titleBackgroundColor:"white",subtitleColor:"white",subtitleFontSize:19,subtitleFontFamily:"GGX88",subtitleAlign:"left",subtitleFontWeight:"normal",subtitleBackgroundColor:"#7B8BAF",mousePositionColor:"#FE0000",showMousePosition:!0},track:{background:"white",alternatingBackground:"#fffdf7",titleColor:"black",titleBackground:"white",titleAlign:"left",outline:"#7B8BAF",outlineWidth:2},legend:{tickColor:"black",labelColor:"black",labelFontWeight:"normal",labelFontFamily:"GGX88",background:"white",backgroundOpacity:2,backgroundStroke:"lightgray"},axis:{tickColor:"black",labelColor:"black",labelFontFamily:"GGX88",baselineColor:"black",gridColor:"#7B8BAF",gridStrokeWidth:2},markCommon:{...Go},point:{...Go,size:3},rect:{...Go},triangle:{...Go},area:{...Go},line:{...Go},bar:{...Go},rule:{...Go,strokeWidth:1},link:{...Go,strokeWidth:1},text:{...Go,textAnchor:"middle",textFontWeight:"normal"},brush:{...Go,color:"gray",opacity:.3,stroke:"black",strokeWidth:1}},sse=["#3A62FE","#F85353","#3A62FE","#F85353","#DCA326","#03BF06","#BABABA"],vo={color:sse[0],size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:sse,quantitativeSizeRange:[2,6]},Meg={base:"jbrowse",root:{background:"white",titleColor:"white",titleFontSize:20,titleFontFamily:"Roboto",titleAlign:"middle",titleFontWeight:"normal",titleBackgroundColor:"#0b243f",subtitleColor:"white",subtitleFontSize:18,subtitleFontFamily:"Roboto",subtitleAlign:"middle",subtitleFontWeight:"normal",subtitleBackgroundColor:"#732162",showMousePosition:!0,mousePositionColor:"#000000"},track:{background:"white",alternatingBackground:"white",titleAlign:"middle",titleColor:"white",titleBackground:"#0B243F",outline:"black",outlineWidth:1},legend:{position:"top",background:"white",backgroundOpacity:.7,labelColor:"#DCA326",labelFontWeight:"bold",labelFontFamily:"Roboto",backgroundStroke:"#black",tickColor:"black"},axis:{tickColor:"black",labelColor:"#DCA326",labelFontWeight:"bold",labelFontFamily:"Roboto",baselineColor:"black",gridColor:"#c5d5d9",gridStrokeWidth:1},markCommon:{...vo},point:{...vo,size:3},rect:{...vo},triangle:{...vo},area:{...vo},line:{...vo},bar:{...vo},rule:{...vo,strokeWidth:1},link:{...vo,strokeWidth:1},text:{...vo,textAnchor:"middle",textFontWeight:"normal"},brush:{...vo,color:"#c5d5d9",opacity:.3,stroke:"black",strokeWidth:1}},lse=["#3A5FCD","#FFA54E","#8FBC8F","#B6709B","#EE6A50","#CCB79E","#DADA8F","#00CDCC","#EED5D2","#CD8EDD","#9ACD31","#D1BEA8","#FFB6C0"],Bo={color:lse[0],size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:lse,quantitativeSizeRange:[2,6]},zeg={base:"ucsc",root:{background:"white",titleColor:"white",titleFontSize:22,titleAlign:"middle",titleFontWeight:"bold",titleBackgroundColor:"#00457c",subtitleColor:"black",subtitleAlign:"middle",subtitleFontWeight:"bold",subtitleBackgroundColor:"white",showMousePosition:!0,mousePositionColor:"#FE0000"},track:{background:"white",alternatingBackground:"#e3f7fc",titleColor:"#3A5FCD",titleBackground:"white",outline:"black",outlineWidth:1},legend:{position:"top",background:"white",backgroundOpacity:.7,labelColor:"black",labelFontWeight:"bold",backgroundStroke:"#DBDBDB",tickColor:"black"},axis:{tickColor:"black",labelColor:"#3A5FCD",labelFontWeight:"bold",baselineColor:"black",gridColor:"#E3E3E3",gridStrokeWidth:1},markCommon:{...Bo},point:{...Bo,size:3},rect:{...Bo},triangle:{...Bo},area:{...Bo},line:{...Bo},bar:{...Bo},rule:{...Bo,strokeWidth:1},link:{...Bo,strokeWidth:1},text:{...Bo,textAnchor:"middle",textFontWeight:"normal"},brush:{...Bo,color:"gray",opacity:.3,stroke:"black",strokeWidth:1}},cse=["#6E12AC","#15C250","#E70FB1","#FF8E55","#A3B8F3","#DE5E59","#77AAAA","#F5CCCA"],So={color:cse[0],size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:cse,quantitativeSizeRange:[2,6]},Peg={base:"washu",root:{background:"white",titleColor:"gray",titleAlign:"left",titleFontWeight:"normal",titleBackgroundColor:"white",subtitleColor:"lightgray",subtitleAlign:"left",subtitleFontWeight:"light",subtitleBackgroundColor:"white",showMousePosition:!0,mousePositionColor:"#000000"},track:{background:"white",titleColor:"gray",titleBackground:"white",titleAlign:"left",outline:"gray",outlineWidth:1},legend:{background:"white",backgroundOpacity:.5,labelColor:"gray",labelFontWeight:"light",backgroundStroke:"#DBDBDB",tickColor:"gray"},axis:{tickColor:"lightgray",labelColor:"gray",labelFontWeight:"light",baselineColor:"gray",gridColor:"transparent",gridStrokeWidth:0},markCommon:{...So},point:{...So,size:3},rect:{...So},triangle:{...So},area:{...So},line:{...So},bar:{...So},rule:{...So,strokeWidth:1},link:{...So,strokeWidth:1},text:{...So,textAnchor:"middle",textFontWeight:"normal"},brush:{...So,color:"gray",opacity:.3,stroke:"gray",strokeWidth:1}},use=["#ED7D31","#4472C4","#FFC207","#76AE4F","#9E480E","#A5A5A5","#4472C4","#264378","#76AE4F","#5B9CD5"],wo={color:use[0],size:1,stroke:"#5A5A5A",strokeWidth:0,opacity:1,nominalColorRange:use,quantitativeSizeRange:[2,6]},Jeg={base:"excel",root:{background:"white",titleColor:"#5A5A5A",titleFontSize:30,titleFontFamily:"Calibri",titleAlign:"middle",titleFontWeight:"bold",titleBackgroundColor:"white",subtitleColor:"#5A5A5A",subtitleFontSize:22,subtitleFontFamily:"Calibri",subtitleAlign:"middle",subtitleFontWeight:"bold",subtitleBackgroundColor:"white",showMousePosition:!0,mousePositionColor:"#000000"},track:{background:"white",alternatingBackground:"#f5f5f5",titleColor:"#5A5A5A",titleBackground:"white",outline:"#5A5A5A",outlineWidth:1},legend:{position:"right",tickColor:"#5A5A5A",labelColor:"#5A5A5A",labelFontSize:12,labelFontWeight:"bold",labelFontFamily:"Calibri",background:"white",backgroundOpacity:.7,backgroundStroke:"#5A5A5A"},axis:{tickColor:"#5A5A5A",labelColor:"#5A5A5A",labelFontFamily:"Calibri",baselineColor:"#5A5A5A",gridColor:"#5A5A5A",gridStrokeWidth:1},markCommon:{...wo},point:{...wo,size:3},rect:{...wo},triangle:{...wo},area:{...wo},line:{...wo},bar:{...wo},rule:{...wo,strokeWidth:1},link:{...wo,strokeWidth:1},text:{...wo,textAnchor:"middle",textFontWeight:"normal"},brush:{...wo,color:"#5A5A5A",opacity:.3,stroke:"#5A5A5A",strokeWidth:1}},dse=["#4185f4","#DB4437","#F4B400","#0D9D58","#AA30C3","#FF6E02","#CBC74C"],Vo={color:dse[0],size:2,stroke:"black",strokeWidth:.3,opacity:1,nominalColorRange:dse,quantitativeSizeRange:[2,6]},Oeg={base:"google",root:{background:"white",titleColor:"#454545",titleFontSize:20,titleFontFamily:"Arial",titleAlign:"left",titleFontWeight:"normal",titleBackgroundColor:"white",subtitleColor:"#7d7d7d",subtitleFontSize:16,subtitleFontFamily:"Arial",subtitleAlign:"left",subtitleFontWeight:"light",subtitleBackgroundColor:"white",showMousePosition:!0,mousePositionColor:"#000000"},track:{background:"white",alternatingBackground:"#f5f5f5",titleColor:"#e8e8e8",titleBackground:"white",titleFontSize:12,titleAlign:"left",outline:"black",outlineWidth:1},legend:{position:"right",background:"white",backgroundOpacity:1,labelColor:"black",labelFontSize:12,labelFontWeight:"normal",labelFontFamily:"Arial",backgroundStroke:"black",tickColor:"black"},axis:{labelFontSize:12,labelFontWeight:"normal",labelFontFamily:"Arial",tickColor:"black",labelColor:"black",baselineColor:"black",gridColor:"black",gridStrokeWidth:1},markCommon:{...Vo},point:{...Vo,size:3},rect:{...Vo},triangle:{...Vo},area:{...Vo},line:{...Vo},bar:{...Vo},rule:{...Vo,strokeWidth:1},link:{...Vo,strokeWidth:1},text:{...Vo,textAnchor:"middle",textFontWeight:"normal"},brush:{...Vo,color:"#999999",opacity:.3,stroke:"black",strokeWidth:.7}},sO={light:keg,dark:Keg,warm:Deg,ggplot:xeg,igv:Feg,ensembl:Eeg,jbrowse:Meg,ucsc:zeg,washu:Peg,excel:Jeg,google:Oeg};function lO(e){return Object.keys(sO).indexOf(e)!==-1}function eG(e){return lO(e)?sO[e]:sO.light}function L4(e,g){var I;function i(...n){if(!new.target)throw new Error('Uncaught TypeError: Class constructor cannot be invoked without "new"');return g(...n)}return i.config={...e,availableOptions:Object.keys((I=e.defaultOptions)!=null?I:{})},i}const _eg=200,Leg=6,Ueg=2,r9e=7829367,Qeg=' ',jeg={type:"axis-track",datatype:["multivec","epilogos"],local:!1,orientation:"1d-horizontal",thumbnail:new DOMParser().parseFromString(Qeg,"text/xml").documentElement,defaultOptions:{innerRadius:340,outerRadius:310,startAngle:0,endAngle:360,width:700,height:700,layout:"linear",labelMargin:5,excludeChrPrefix:!1,labelPosition:"none",labelColor:"black",labelTextOpacity:.4,trackBorderWidth:0,trackBorderColor:"black",tickPositions:"even",fontSize:12,fontFamily:"sans-serif",fontWeight:"normal",color:"#808080",stroke:"#ffffff",backgroundColor:"transparent",showMousePosition:!1,tickColor:r9e}},$eg=(e,g,I)=>{const{absToChr:i,colorToHex:n,pixiTextToSvg:C,svgLine:r,showMousePosition:o}=e.utils;function A(a,l){return Object.assign(new e.libraries.PIXI.Text(a,l),{hashValue:Math.random()})}class s extends e.tracks.PixiTrack{constructor(){super(g,I),Ct(this,"allTexts"),Ct(this,"searchField"),Ct(this,"chromInfo"),Ct(this,"dataConfig"),Ct(this,"pTicksCircular"),Ct(this,"pTicks"),Ct(this,"gTicks"),Ct(this,"tickTexts"),Ct(this,"isShowGlobalMousePosition"),Ct(this,"pixiTextConfig"),Ct(this,"stroke"),Ct(this,"tickWidth"),Ct(this,"tickHeight"),Ct(this,"tickTextSeparation"),Ct(this,"tickColor"),Ct(this,"animate"),Ct(this,"hideMousePosition"),Ct(this,"gBoundTicks"),Ct(this,"leftBoundTick"),Ct(this,"rightBoundTick"),Ct(this,"is2d"),Ct(this,"texts");const{dataConfig:l,animate:c,chromInfoPath:u,isShowGlobalMousePosition:d}=g;this.searchField=null,this.dataConfig=l,this.allTexts=[],this.pTicksCircular=new e.libraries.PIXI.Graphics,this.pTicks=new e.libraries.PIXI.Graphics,this.pMain.addChild(this.pTicks),this.pMain.addChild(this.pTicksCircular),this.gTicks={},this.tickTexts={},this.options=I,this.isShowGlobalMousePosition=d,this.pixiTextConfig=Hs({size:+this.options.fontSize,fontFamily:this.options.fontFamily,fontWeight:this.options.fontWeight,color:this.options.color,stroke:this.options.stroke,strokeThickness:2}),this.stroke=n(this.pixiTextConfig.stroke),this.tickWidth=_eg,this.tickHeight=Leg,this.tickTextSeparation=Ueg,this.tickColor=n(this.options.tickColor),this.animate=c,this.pubSubs=[],this.options.showMousePosition&&!this.hideMousePosition&&(this.hideMousePosition=o(this,this.is2d,this.isShowGlobalMousePosition()));let h=u;h||(h=`${l.server}/chrom-sizes/?id=${l.tilesetUid}`);const m=this.options.assembly,f={},b={...pI(m).size},p=[];Object.keys(pI(m).size).forEach(y=>{f[y]={chr:y,pos:pI(m).size[y]}}),Object.keys(pI(m).interval).forEach(y=>{p.push({chr:y,pos:pI(m).interval[y][0]})}),this.chromInfo={chrPositions:f,chromLengths:b,cumPositions:p},this.rerender(this.options,!0),this.draw(),this.animate()}initBoundsTicks(){this.pTicks&&(this.pMain.removeChild(this.pTicks),this.pTicks=null),this.gBoundTicks||(this.gBoundTicks=new e.libraries.PIXI.Graphics,this.leftBoundTick=A("",this.pixiTextConfig),this.rightBoundTick=A("",this.pixiTextConfig),this.gBoundTicks.addChild(this.leftBoundTick),this.gBoundTicks.addChild(this.rightBoundTick),this.pMain.addChild(this.gBoundTicks)),this.texts=[]}initChromLabels(){this.chromInfo&&(this.gBoundTicks&&(this.pMain.removeChild(this.gBoundTicks),this.gBoundTicks=void 0),this.pTicks||(this.pTicks=new e.libraries.PIXI.Graphics,this.pMain.addChild(this.pTicks)),this.texts=[],this.pTicks.removeChildren(),this.chromInfo.cumPositions.forEach(l=>{var c,u,d;const h=l.chr;this.gTicks[h]=new e.libraries.PIXI.Graphics,this.tickTexts[h]||(this.tickTexts[h]=[]);const m=this.options.excludeChrPrefix?h.replace("chr",""):h,f=A(m,this.pixiTextConfig);(c=this.pTicks)==null||c.addChild(f),(u=this.pTicks)==null||u.addChild(this.gTicks[h]),(d=this.texts)==null||d.push(f)}))}rerender(l,c){const u=JSON.stringify(l);!c&&u===this.prevOptions||(this.prevOptions=u,this.options=l,this.pixiTextConfig.fontSize=+this.options.fontSize?`${+this.options.fontSize}px`:this.pixiTextConfig.fontSize,this.pixiTextConfig.fill=this.options.color||this.pixiTextConfig.fill,this.pixiTextConfig.stroke=this.options.stroke||this.pixiTextConfig.stroke,this.stroke=n(this.pixiTextConfig.stroke),this.tickColor=this.options.tickColor?n(this.options.tickColor):r9e,this.options.tickPositions==="ends"&&this.options.layout!=="circular"?this.initBoundsTicks():this.initChromLabels(),super.rerender(l,c),this.options.showMousePosition&&!this.hideMousePosition&&(this.hideMousePosition=o(this,this.is2d,this.isShowGlobalMousePosition())),!this.options.showMousePosition&&this.hideMousePosition&&(this.hideMousePosition(),this.hideMousePosition=void 0))}formatTick(l){if(isNaN(l))return"null";const c=this._xScale.domain(),u=c[1]-c[0],d=x8e(l,u),h=ibe(","),m=nbe(`,.${d}`,u);let f=h;return this.options.tickFormat==="si"?f=m:this.options.tickFormat==="plain"?f=h:this.options.tickPositions==="ends"&&(f=m),f(l)}drawBoundsTicks(l,c){if(!this.gBoundTicks||!this.leftBoundTick||!this.rightBoundTick)return;const u=this.gBoundTicks;u.clear(),u.lineStyle(1,0);const d=this.options.reverseOrientation?0:this.dimensions[1],h=this.options.reverseOrientation?this.tickHeight:this.dimensions[1]-this.tickHeight;u.moveTo(1,d),u.lineTo(1,h),u.moveTo(this.dimensions[0]-1,d),u.lineTo(this.dimensions[0]-1,h),this.leftBoundTick.x=0,this.leftBoundTick.y=this.options.reverseOrientation?h+this.tickTextSeparation:h-this.tickTextSeparation,this.leftBoundTick.text=this.options.assembly==="unknown"?`${this.formatTick(l[1])}`:`${l[0]}: ${this.formatTick(l[1])}`,this.leftBoundTick.anchor.y=this.options.reverseOrientation?0:1,this.rightBoundTick.x=this.dimensions[0],this.rightBoundTick.text=this.options.assembly==="unknown"?`${this.formatTick(c[1])}`:`${c[0]}: ${this.formatTick(c[1])}`,this.rightBoundTick.y=this.options.reverseOrientation?h+this.tickTextSeparation:h-this.tickTextSeparation,this.rightBoundTick.anchor.y=this.options.reverseOrientation?0:1,this.rightBoundTick.anchor.x=1,this.flipText&&(this.leftBoundTick.scale.x=-1,this.leftBoundTick.anchor.x=1,this.rightBoundTick.scale.x=-1,this.rightBoundTick.anchor.x=0),this.leftBoundTick.tickLine=[1,this.dimensions[1],1,this.dimensions[1]-this.tickHeight],this.rightBoundTick.tickLine=[this.dimensions[0]-1,this.dimensions[1],this.dimensions[0]-1,this.dimensions[1]-this.tickHeight],this.tickTexts={},this.tickTexts.all=[this.leftBoundTick,this.rightBoundTick]}drawTicks(l){const c=this.gTicks[l.chr];c.visible=!0,c.clear();const u=+this.chromInfo.chromLengths[l.chr],d=Math.max(this._xScale(l.pos),0),h=Math.min(this._xScale(l.pos+u),this.dimensions[0]),m=(h-d)/this.tickWidth,b=zd().domain([Math.max(1,this._xScale.invert(0)-l.pos),Math.min(u,this._xScale.invert(this.dimensions[0])-l.pos)]).range([d,h]).ticks(m).filter(v=>Number.isInteger(v)),p=this.tickTexts[l.chr],y=this.tickHeight,Z=0;let B=y+this.tickTextSeparation;for(this.options.reverseOrientation&&(B=this.dimensions[1]-B);p.lengthb.length;){const v=p.pop();this.gTicks[l.chr].removeChild(v)}let G=0;for(;Gu){const R=V-u;V=u,w-=R}const S=[],X=b+G.height/2+3;for(let R=V;R>=w;R-=v/10){const H=Mt(R,u,X,u/2,d/2,h,m);S.push(new e.libraries.PIXI.Point(H.x,H.y))}return S.length===0?void 0:(l.updateText(),new e.libraries.PIXI.SimpleRope(l.texture,S))}draw(){if(this.allTexts=[],!this.texts)return;const l=i(this._xScale.domain()[0],this.chromInfo),c=i(this._xScale.domain()[1],this.chromInfo);if(!l||!c){console.warn("Empty chromInfo:",this.dataConfig,this.chromInfo);return}if(this.options.tickPositions==="ends"&&this.options.layout!=="circular"){if(!this.gBoundTicks)return;this.gBoundTicks.visible=!0,this.drawBoundsTicks(l,c);return}if(!this.pTicks)return;const u=this.options.layout==="circular";for(let h=0;h{this.tickTexts[h]&&this.tickTexts[h].forEach(m=>{m.visible=!1})}),this.pTicksCircular.removeChildren();for(let h=l[3];h<=c[3];h++){const m=this.chromInfo.cumPositions[h],f=m.pos+this.chromInfo.chromLengths[m.chr]/2,b=this._xScale(f),p=this.texts[h];p.anchor.x=.5,p.anchor.y=u?.5:this.options.reverseOrientation?0:1;let y;u?(y=this.addCurvedText(p,b),y&&this.pTicksCircular.addChild(y)):(p.x=b,p.y=this.dimensions[1]-d),p.updateTransform(),this.flipText&&(p.scale.x=-1);const Z=this.drawTicks(m);u?Z>0&&y&&this.pTicksCircular.removeChild(y):p.visible=Z<=0,this.allTexts.push({importance:p.hashValue,text:p,rope:y})}this.hideOverlaps(this.allTexts)}hideOverlaps(l){const c=new B8e;l.sort((u,d)=>d.importance-u.importance).forEach(({text:u,rope:d})=>{u.updateTransform();const h=u.getBounds(),m=this.options.labelMargin,f={minX:h.x-m,minY:h.y-m,maxX:h.x+h.width+m*2,maxY:h.y+h.height+m*2};m<0||!c.collides(f)?c.insert(f):(u.visible=!1,this.options.layout==="circular"&&d&&this.pTicksCircular.removeChild(d))})}setPosition(l){super.setPosition(l),[this.pMain.position.x,this.pMain.position.y]=this.position}zoomed(l,c){[...l.domain(),...c.domain()].filter(d=>isNaN(d)).length===0&&(this.xScale(l),this.yScale(c),this.draw())}exportSVG(){let l=null,c=null;super.exportSVG?[c,l]=super.exportSVG():(c=document.createElement("g"),l=c),c.setAttribute("class","chromosome-labels");const u=document.createElement("g");return l.appendChild(u),u.setAttribute("transform",`translate(${this.position[0]},${this.position[1]})`),this.allTexts.filter(d=>d.text.visible).forEach(d=>{const h=C(d.text);u.appendChild(h)}),Object.values(this.tickTexts).forEach(d=>{d.filter(h=>h.visible).forEach(h=>{if(!h.tickLine)return;let m=C(h);u.appendChild(m),m=r(h.x,this.options.reverseOrientation?0:this.dimensions[1],h.x,this.options.reverseOrientation?this.tickHeight:this.dimensions[1]-this.tickHeight,1,this.tickColor);const f=document.createElement("line");f.setAttribute("x1",String(h.tickLine[0])),f.setAttribute("y1",String(h.tickLine[1])),f.setAttribute("x2",String(h.tickLine[2])),f.setAttribute("y2",String(h.tickLine[3])),f.setAttribute("style","stroke: grey"),u.appendChild(m),u.appendChild(f)})}),[c,l]}}return new s},hse=L4(jeg,$eg);function cO(e,...g){if(!new.target)throw new Error('Uncaught TypeError: Class constructor cannot be invoked without "new"');class I extends e.tracks.SVGTrack{constructor(n){var C,r;super(...n),Ct(this,"circularBrushData"),Ct(this,"prevExtent");const[o,A]=n,{registerViewportChanged:s,removeViewportChanged:a,setDomainsCallback:l}=o;this.uid=rn(),this.options=A,this.hasFromView=!o.projectionXDomain,this.removeViewportChanged=a,this.setDomainsCallback=l,this.viewportXDomain=this.hasFromView?null:o.projectionXDomain,this.viewportYDomain=this.hasFromView?null:[0,0],this.prevExtent=[0,0],this.RR=.02;const c=[0,Math.PI*1.7];this.circularBrushData=this.getBrushData(c),this.brush=Q8e().innerRadius((C=this.options.innerRadius)!=null?C:100).outerRadius((r=this.options.outerRadius)!=null?r:200),this.gBrush=this.gMain.append("g").attr("id",`brush-${this.uid}`).selectAll(".brush").data(this.circularBrushData).enter().append("path").attr("class","brush").attr("d",this.brush).attr("fill",this.options.projectionFillColor).attr("stroke",this.options.projectionStrokeColor).attr("fill-opacity",u=>u.type==="brush"?this.options.projectionFillOpacity:0).attr("stroke-opacity",u=>u.type==="brush"?this.options.projectionStrokeOpacity:0).attr("stroke-width",this.options.strokeWidth).style("pointer-events","all").style("cursor",u=>u.cursor).call(this.dragged()),s(this.uid,this.viewportChanged.bind(this)),this.draw()}getBrushData(n){return[{type:"brush",startAngle:n[0],endAngle:n[1],cursor:"grab"},{type:"start",startAngle:n[0],endAngle:n[0]+this.RR,cursor:"move"},{type:"end",startAngle:n[1]-this.RR,endAngle:n[1],cursor:"move"}]}cropExtent(n){let[C,r]=n,o=0;for(;(C>Math.PI*2||r>Math.PI*2||C<0||r<0)&&!(o++>10);)C>Math.PI*2||r>Math.PI*2?(C-=Math.PI*2,r-=Math.PI*2):(C<0||r<0)&&(C+=Math.PI*2,r+=Math.PI*2);return[C,r].sort((A,s)=>A-s)}updateBrush(n){let[C,r]=n;if(C<=ji&&r<=ji||C>=Math.PI*2-ji&&r>=Math.PI*2-ji){this.gBrush.attr("visibility","hidden");return}CMath.PI*2-ji&&(C=Math.PI*2-ji),rMath.PI*2-ji&&(r=Math.PI*2-ji),this.circularBrushData=this.getBrushData(n),this.gBrush.data(this.circularBrushData).attr("d",this.brush).attr("visibility","visible")}dragged(){const n=r=>{this.startEvent=r.sourceEvent,this.prevExtent=[this.circularBrushData[0].startAngle,this.circularBrushData[0].endAngle]},C=(r,o)=>{const[A,s]=this.position,[a,l]=this.dimensions,c=r.sourceEvent,u=this.startEvent.layerX-A,d=this.startEvent.layerY-s,h=c.layerX-A,m=c.layerY-s,f=Math.atan2(u-a/2,d-l/2)-Math.atan2(h-a/2,m-l/2);let[b,p]=this.prevExtent;if(o.type==="brush"){if(b=b+f,p=p+f,bV?(p+=w,b+=w):(b-=V,p-=V)}}else o.type==="start"?b=b+f:o.type==="end"&&(p=p+f);if([b,p]=this.cropExtent([b,p]),!this._xScale||!this._yScale)return;const y=(this.options.endAngle-this.options.startAngle)/360,Z=b-this.options.startAngle/360*Math.PI*2,B=p-this.options.startAngle/360*Math.PI*2,G=[this._xScale.invert(a-a*B/(Math.PI*2*y)),this._xScale.invert(a-a*Z/(Math.PI*2*y))],v=this.viewportYDomain;this.hasFromView||(this.viewportXDomain=G),this.setDomainsCallback(G,v),this.updateBrush([b,p])};return e.libraries.d3Drag.drag().on("start",n).on("drag",C)}draw(){if(!this._xScale||!this.yScale||!this.viewportXDomain||!this.viewportYDomain)return;const n=this._xScale(this.viewportXDomain[0]),C=this._xScale(this.viewportXDomain[1]),[r]=this.dimensions;let o=Ug(n,r,this.options.startAngle,this.options.endAngle)+Math.PI/2,A=Ug(C,r,this.options.startAngle,this.options.endAngle)+Math.PI/2;[A,o]=this.cropExtent([A,o]),this.updateBrush([A,o])}viewportChanged(n,C){const r=n.domain(),o=C.domain();this.viewportXDomain=r,this.viewportYDomain=o,this.draw()}remove(){this.removeViewportChanged(this.uid),super.remove()}rerender(){}zoomed(n,C){this.xScale(n),this.yScale(C),this.draw()}setPosition(n){super.setPosition(n),this.draw()}setDimensions(n){super.setDimensions(n),this.gBrush.attr("transform",`translate(${n[0]/2},${n[1]/2})`),this.draw()}}return new I(g)}const qeg=' ';cO.config={type:"brush-track",datatype:["projection"],local:!1,projection:!0,orientation:"2d",thumbnail:new DOMParser().parseFromString(qeg,"text/xml").documentElement,availableOptions:["innerRadius","outerRadius","startAngle","endAngle","axisPositionHorizontal","projectionFillColor","projectionStrokeColor","projectionFillOpacity","projectionStrokeOpacity","strokeWidth"],defaultOptions:{innerRadius:100,outerRadius:200,startAngle:0,endAngle:360,axisPositionHorizontal:"left",projectionFillColor:"#777",projectionStrokeColor:"#777",projectionFillOpacity:.3,projectionStrokeOpacity:.7,strokeWidth:1}};const mse=3,etg={color:"#777",stroke:"#777",strokeWidth:1,strokeOpacity:.7,opacity:.3};class ttg{constructor(g,I,i={}){Ct(this,"brushSelection"),Ct(this,"style"),Ct(this,"range"),Ct(this,"data"),Ct(this,"startEvent"),Ct(this,"prevExtent"),Ct(this,"offset"),Ct(this,"size"),Ct(this,"externals"),Ct(this,"emitter"),this.emitter=j8e(),this.range=null,this.prevExtent=[0,0],this.data=this.rangeToData(0,0),this.offset=[0,0],this.size=0,this.externals={d3Selection:I.d3Selection,d3Drag:I.d3Drag},this.style=Object.assign({},etg,i),this.brushSelection=g.selectAll(".genomic-range-brush").data(this.data).enter().append("rect").attr("class","genomic-range-brush").call(this.onDrag())}getRange(){return this.range}setSize(g){return this.size=g,this}setOffset(g,I){return this.offset=[g,I],this}updateRange(g){return g?(this.range=[Math.min(...g),Math.max(...g)],this.data=this.rangeToData(...this.range)):this.range=null,this}drawBrush(g=!1){const[I,i]=this.offset,n=this.size,C=r=>Math.abs(r.end-r.start);return this.brushSelection.data(this.data).attr("transform",r=>`translate(${I+r.start}, ${i+1})`).attr("width",r=>`${C(r)}px`).attr("height",`${n-2}px`).attr("fill",this.style.color).attr("stroke",this.style.stroke).attr("stroke-width",`${this.style.strokeWidth}px`).attr("fill-opacity",r=>r.type==="body"?this.style.opacity:0).attr("stroke-opacity",r=>r.type==="body"?this.style.strokeOpacity:0).attr("cursor",r=>r.cursor),this.emitter.emit("brush",this.getRange(),g),this}enable(){return this.brushSelection.attr("pointer-events","all"),this}disable(){return this.brushSelection.attr("pointer-events","none"),this}visible(){return this.brushSelection.attr("visibility","visible"),this}hidden(){return this.brushSelection.attr("visibility","hidden"),this}clear(){return this.updateRange(null).drawBrush().hidden().disable(),this}remove(){return this.brushSelection.remove(),this}rangeToData(g,I){return[{type:"body",cursor:"grab",start:g,end:I},{type:"start",cursor:"ew-resize",start:g-mse,end:g},{type:"end",cursor:"ew-resize",start:I,end:I+mse}]}onDrag(){const g=i=>{this.startEvent=i.sourceEvent,this.prevExtent=this.range},I=(i,n)=>{var C;const r=i.sourceEvent.layerX-this.startEvent.layerX;let[o,A]=(C=this.prevExtent)!=null?C:[0,0];n.type==="body"?(o+=r,A+=r):n.type==="start"?o+=r:n.type==="end"&&(A+=r),this.updateRange([o,A]).drawBrush()};return this.externals.d3Drag.drag().on("start",g).on("drag",I)}on(g,I){this.emitter.on(g,I)}}const gtg=([e,g],[I,i],[n,C],[r,o])=>{const A=Math.sqrt((e-I)**2+(g-i)**2);if(AMath.sqrt((e-I)**2+(g-i)**2)e<=I&&I<=g,itg=(e,g,I=5)=>uO(e,g-I)&&uO(e,g+I),ntg=(e,g)=>g.filter((I,i)=>i%2===0).every(I=>uO(e,I)),Ctg=([e,g],I,i=5)=>{let n,C,r,o,A=!1;for(let s=0;s0?h=Math.sqrt((g-o)**2+(e-r)**2):d<0?h=Math.sqrt((g-C)**2+(e-n)**2):h=Math.abs(a[0]*c[1]-a[1]*c[0])/Math.sqrt(a[0]**2+a[1]**2),h{let i,n,C,r,o=!1;for(let A=0,s=I.length-2;Ag!=r>g&&e<(C-i)*(g-n)/(r-n)+i&&(o=!o),s=A;return o};class otg{constructor(){Ct(this,"data"),this.data=[]}size(){return this.data.length}addPolygonBasedEvent(g,I){this.data.push({uid:rn(),type:"polygon",value:g,polygon:I})}addPointBasedEvent(g,I){this.data.push({uid:rn(),type:"point",value:g,polygon:I})}addLineBasedEvent(g,I){this.data.push({uid:rn(),type:"line",value:g,polygon:I})}clear(){this.data=[]}find(g,I,i=!1){const n=Array.from(this.data);return i&&n.reverse(),n.find(C=>this.isMouseWithin(C,g,I))}findAll(g,I,i=!1){const n=Array.from(this.data);return i&&n.reverse(),n.filter(C=>this.isMouseWithin(C,g,I))}getSiblings(g,I){const i=[],n=Array.from(new Set(g.map(C=>C.uid)));return g.forEach(C=>{const r=C.value[I];r&&i.push(...this.data.filter(o=>o.value[I]===r&&n.indexOf(o.uid)===-1))}),i}isMouseWithin(g,I,i){switch(g.type){case"point":return Itg([I,i],g.polygon);case"line":return Ctg([I,i],g.polygon);case"polygon":default:return rtg([I,i],g.polygon)}}findAllWithinRange(g,I,i=!1){const n=Array.from(this.data);return i&&n.reverse(),n.filter(C=>this.isWithinRange(C,g,I))}isWithinRange(g,I,i){switch(g.type){case"point":return itg([I,i],g.polygon[0],g.polygon[2]);case"line":case"polygon":default:return ntg([I,i],g.polygon)}}}const o9e="KCgpID0+IHsKICB2YXIgX19jcmVhdGUgPSBPYmplY3QuY3JlYXRlOwogIHZhciBfX2RlZlByb3AgPSBPYmplY3QuZGVmaW5lUHJvcGVydHk7CiAgdmFyIF9fZ2V0T3duUHJvcERlc2MgPSBPYmplY3QuZ2V0T3duUHJ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XRzOwogICAgICAgIG5CaXRzICs9IGVMZW47CiAgICAgICAgZm9yICg7IG5CaXRzID4gMDsgZSA9IGUgKiAyNTYgKyBidWZmZXJbb2Zmc2V0ICsgaV0sIGkgKz0gZCwgbkJpdHMgLT0gOCkgewogICAgICAgIH0KICAgICAgICBtID0gZSAmICgxIDw8IC1uQml0cykgLSAxOwogICAgICAgIGUgPj49IC1uQml0czsKICAgICAgICBuQml0cyArPSBtTGVuOwogICAgICAgIGZvciAoOyBuQml0cyA+IDA7IG0gPSBtICogMjU2ICsgYnVmZmVyW29mZnNldCArIGldLCBpICs9IGQsIG5CaXRzIC09IDgpIHsKICAgICAgICB9CiAgICAgICAgaWYgKGUgPT09IDApIHsKICAgICAgICAgIGUgPSAxIC0gZUJpYXM7CiAgICAgICAgfSBlbHNlIGlmIChlID09PSBlTWF4KSB7CiAgICAgICAgICByZXR1cm4gbSA/IE5hTiA6IChzID8gLTEgOiAxKSAqIEluZmluaXR5OwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBtID0gbSArIE1hdGgucG93KDIsIG1MZW4pOwogICAgICAgICAgZSA9IGUgLSBlQmlhczsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIChzID8gLTEgOiAxKSAqIG0gKiBNYXRoLnBvdygyLCBlIC0gbUxlbik7CiAgICAgIH07CiAgICAgIGV4cG9ydHMud3JpdGUgPSBmdW5jdGlvbihidWZmZXIsIHZhbHVlLCBvZmZzZXQsIGlzTEUsIG1MZW4sIG5CeXRlcykgewogICAgICAgIHZhciBlLCBtLCBjOwogICAgICAgIHZhciBlTGVuID0gbkJ5dGVzICogOCAtIG1MZW4gLSAxOwogICAgICAgIHZhciBlTWF4ID0gKDEgPDwgZUxlbikgLSAxOwogICAgICAgIHZhciBlQmlhcyA9IGVNYXggPj4gMTsKICAgICAgICB2YXIgcnQgPSBtTGVuID09PSAyMyA/IE1hdGgucG93KDIsIC0yNCkgLSBNYXRoLnBvdygyLCAtNzcpIDogMDsKICAgICAgICB2YXIgaSA9IGlzTEUgPyAwIDogbkJ5dGVzIC0gMTsKICAgICAgICB2YXIgZCA9IGlzTEUgPyAxIDogLTE7CiAgICAgICAgdmFyIHMgPSB2YWx1ZSA8IDAgfHwgdmFsdWUgPT09IDAgJiYgMSAvIHZhbHVlIDwgMCA/IDEgOiAwOwogICAgICAgIHZhbHVlID0gTWF0aC5hYnModmFsdWUpOwogICAgICAgIGlmIChpc05hTih2YWx1ZSkgfHwgdmFsdWUgPT09IEluZmluaXR5KSB7CiAgICAgICAgICBtID0gaXNOYU4odmFsdWUpID8gMSA6IDA7CiAgICAgICAgICBlID0gZU1heDsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgZSA9IE1hdGguZmxvb3IoTWF0aC5sb2codmFsdWUpIC8gTWF0aC5MTjIpOwogICAgICAgICAgaWYgKHZhbHVlICogKGMgPSBNYXRoLnBvdygyLCAtZSkpIDwgMSkgewogICAgICAgICAgICBlLS07CiAgICAgICAgICAgIGMgKj0gMjsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChlICsgZUJpYXMgPj0gMSkgewogICAgICAgICAgICB2YWx1ZSArPSBydCAvIGM7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICB2YWx1ZSArPSBydCAqIE1hdGgucG93KDIsIDEgLSBlQmlhcyk7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAodmFsdWUgKiBjID49IDIpIHsKICAgICAgICAgICAgZSsrOwogICAgICAgICAgICBjIC89IDI7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoZSArIGVCaWFzID49IGVNYXgpIHsKICAgICAgICAgICAgbSA9IDA7CiAgICAgICAgICAgIGUgPSBlTWF4OwogICAgICAgICAgfSBlbHNlIGlmIChlICsgZUJpYXMgPj0gMSkgewogICAgICAgICAgICBtID0gKHZhbHVlICogYyAtIDEpICogTWF0aC5wb3coMiwgbUxlbik7CiAgICAgICAgICAgIGUgPSBlICsgZUJpYXM7CiAgICAgICAgICB9IGVsc2UgewogICAgICA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eXBlT2YoYXJyLCBwcm90byk7CiAgICAgICAgICByZXR1cm4gYXJyLmZvbygpID09PSA0MjsKICAgICAgICB9IGNhdGNoIChlKSB7CiAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgfQogICAgICB9CiAgICAgIE9iamVjdC5kZWZpbmVQcm9wZXJ0eShCdWZmZXI4LnByb3RvdHlwZSwgInBhcmVudCIsIHsKICAgICAgICBlbnVtZXJhYmxlOiB0cnVlLAogICAgICAgIGdldDogZnVuY3Rpb24oKSB7CiAgICAgICAgICBpZiAoIUJ1ZmZlcjguaXNCdWZmZXIodGhpcykpCiAgICAgICAgICAgIHJldHVybiB2b2lkIDA7CiAgICAgICAgICByZXR1cm4gdGhpcy5idWZmZXI7CiAgICAgICAgfQogICAgICB9KTsKICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KEJ1ZmZlcjgucHJvdG90eXBlLCAib2Zmc2V0IiwgewogICAgICAgIGVudW1lcmFibGU6IHRydWUsCiAgICAgICAgZ2V0OiBmdW5jdGlvbigpIHsKICAgICAgICAgIGlmICghQnVmZmVyOC5pc0J1ZmZlcih0aGlzKSkKICAgICAgICAgICAgcmV0dXJuIHZvaWQgMDsKICAgICAgICAgIHJldHVybiB0aGlzLmJ5dGVPZmZzZXQ7CiAgICAgICAgfQogICAgICB9KTsKICAgICAgZnVuY3Rpb24gY3JlYXRlQnVmZmVyKGxlbmd0aCkgewogICAgICAgIGlmIChsZW5ndGggPiBLX01BWF9MRU5HVEgpIHsKICAgICAgICAgIHRocm93IG5ldyBSYW5nZUVycm9yKCdUaGUgdmFsdWUgIicgKyBsZW5ndGggKyAnIiBpcyBpbnZhbGlkIGZvciBvcHRpb24gInNpemUiJyk7CiAgICAgICAgfQogICAgICAgIGNvbnN0IGJ1ZiA9IG5ldyBVaW50OEFycmF5KGxlbmd0aCk7CiAgICAgICAgT2JqZWN0LnNldFByb3RvdHlwZU9mKGJ1ZiwgQnVmZmVyOC5wcm90b3R5cGUpOwogICA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JheShhcnJheSwgYnl0ZU9mZnNldCk7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIGJ1ZiA9IG5ldyBVaW50OEFycmF5KGFycmF5LCBieXRlT2Zmc2V0LCBsZW5ndGgpOwogICAgICAgIH0KICAgICAgICBPYmplY3Quc2V0UHJvdG90eXBlT2YoYnVmLCBCdWZmZXI4LnByb3RvdHlwZSk7CiAgICAgICAgcmV0dXJuIGJ1ZjsKICAgICAgfQogICAgICBmdW5jdGlvbiBmcm9tT2JqZWN0KG9iaikgewogICAgICAgIGlmIChCdWZmZXI4LmlzQnVmZmVyKG9iaikpIHsKICAgICAgICAgIGNvbnN0IGxlbiA9IGNoZWNrZWQob2JqLmxlbmd0aCkgfCAwOwogICAgICAgICAgY29uc3QgYnVmID0gY3JlYXRlQnVmZmVyKGxlbik7CiAgICAgICAgICBpZiAoYnVmLmxlbmd0aCA9PT0gMCkgewogICAgICAgICAgICByZXR1cm4gYnVmOwogICAgICAgICAgfQogICAgICAgICAgb2JqLmNvcHkoYnVmLCAwLCAwLCBsZW4pOwogICAgICAgICAgcmV0dXJuIGJ1ZjsKICAgICAgICB9CiAgICAgICAgaWYgKG9iai5sZW5ndGggIT09IHZvaWQgMCkgewogICAgICAgICAgaWYgKHR5cGVvZiBvYmoubGVuZ3RoICE9PSAibnVtYmVyIiB8fCBudW1iZXJJc05hTihvYmoubGVuZ3RoKSkgewogICAgICAgICAgICByZXR1cm4gY3JlYXRlQnVmZmVyKDApOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIGZyb21BcnJheUxpa2Uob2JqKTsKICAgICAgICB9CiAgICAgICAgaWYgKG9iai50eXBlID09PSAiQnVmZmVyIiAmJiBBcnJheS5pc0FycmF5KG9iai5kYXRhKSkgewogICAgICAgICAgcmV0dXJuIGZyb21BcnJheUxpa2Uob2JqLmRhdGEpOwogICAgICAgIH0KICAgICAgfQogICAgICBmdW5jdGlvbiBjaGVja2VkKGxlbmd0aCkgewogICAgICAgIGlmIChs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3VtZW50cyBtdXN0IGJlIG9uZSBvZiB0eXBlIEJ1ZmZlciBvciBVaW50OEFycmF5Jyk7CiAgICAgICAgfQogICAgICAgIGlmIChhID09PSBiKQogICAgICAgICAgcmV0dXJuIDA7CiAgICAgICAgbGV0IHggPSBhLmxlbmd0aDsKICAgICAgICBsZXQgeSA9IGIubGVuZ3RoOwogICAgICAgIGZvciAobGV0IGkgPSAwLCBsZW4gPSBNYXRoLm1pbih4LCB5KTsgaSA8IGxlbjsgKytpKSB7CiAgICAgICAgICBpZiAoYVtpXSAhPT0gYltpXSkgewogICAgICAgICAgICB4ID0gYVtpXTsKICAgICAgICAgICAgeSA9IGJbaV07CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAoeCA8IHkpCiAgICAgICAgICByZXR1cm4gLTE7CiAgICAgICAgaWYgKHkgPCB4KQogICAgICAgICAgcmV0dXJuIDE7CiAgICAgICAgcmV0dXJuIDA7CiAgICAgIH07CiAgICAgIEJ1ZmZlcjguaXNFbmNvZGluZyA9IGZ1bmN0aW9uIGlzRW5jb2RpbmcoZW5jb2RpbmcpIHsKICAgICAgICBzd2l0Y2ggKFN0cmluZyhlbmNvZGluZykudG9Mb3dlckNhc2UoKSkgewogICAgICAgICAgY2FzZSAiaGV4IjoKICAgICAgICAgIGNhc2UgInV0ZjgiOgogICAgICAgICAgY2FzZSAidXRmLTgiOgogICAgICAgICAgY2FzZSAiYXNjaWkiOgogICAgICAgICAgY2FzZSAibGF0aW4xIjoKICAgICAgICAgIGNhc2UgImJpbmFyeSI6CiAgICAgICAgICBjYXNlICJiYXNlNjQiOgogICAgICAgICAgY2FzZSAidWNzMiI6CiAgICAgICAgICBjYXNlICJ1Y3MtMiI6CiAgICAgICAgICBjYXNlICJ1dGYxNmxlIjoKICAgICAgICAgIGNhc2UgInV0Zi0xNmxlIjoKICAgICAgICAgICAgcmV0dXJuIHRydWU7CiAgICAgICAgICBkZWZhdWx0OgogICAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgfQogICAgICB9OwogICAgICBCdWZmZXI4LmNvbmNhdCA9IGZ1bmN0aW9uIGNvbmNhdChsaXN0LCBsZW5ndGgpIHsKICAgICAgICBpZiAoIUFycmF5LmlzQXJyYXkobGlzdCkpIHsKICAgICAgICAgIHRocm93IG5ldyBUeXBlRXJyb3IoJyJsaXN0IiBhcmd1bWVudCBtdXN0IGJlIGFuIEFycmF5IG9mIEJ1ZmZlcnMnKTsKICAgICAgICB9CiAgICAgICAgaWYgKGxpc3QubGVuZ3RoID09PSAwKSB7CiAgICAgICAgICByZXR1cm4gQnVmZmVyOC5hbGxvYygwKTsKICAgICAgICB9CiAgICAgICAgbGV0IGk7CiAgICAgICAgaWYgKGxlbmd0aCA9PT0gdm9pZCAwKSB7CiAgICAgICAgICBsZW5ndGggPSAwOwogICAgICAgICAgZm9yIChpID0gMDsgaSA8IGxpc3QubGVuZ3RoOyArK2kpIHsKICAgICAgICAgICAgbGVuZ3RoICs9IGxpc3RbaV0ubGVuZ3RoOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBjb25zdCBidWZmZXIgPSBCdWZmZXI4LmFsbG9jVW5zYWZlKGxlbmd0aCk7CiAgICAgICAgbGV0IHBvcyA9IDA7CiAgICAgICAgZm9yIChpID0gMDsgaSA8IGxpc3QubGVuZ3RoOyArK2kpIHsKICAgICAgICAgIGxldCBidWYgPSBsaXN0W2ldOwogICAgICAgICAgaWYgKGlzSW5zdGFuY2UoYnVmLCBVaW50OEFycmF5KSkgewogICAgICAgICAgICBpZiAocG9zICsgYnVmLmxlbmd0aCA+IGJ1ZmZlci5sZW5ndGgpIHsKICAgICAgICAgICAgICBpZiAoIUJ1ZmZlcjguaXNCdWZmZXIoYnVmKSkKICAgICAgICAgICAgICAgIGJ1ZiA9IEJ1ZmZlcjguZnJvbShidWYpOwogICAgICAgICAgICAgIGJ1Zi5jb3B5KGJ1ZmZlciwgcG9zKTsKICAgICAgICAgIC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GNvbnN0IG11c3RNYXRjaCA9IGFyZ3VtZW50cy5sZW5ndGggPiAyICYmIGFyZ3VtZW50c1syXSA9PT0gdHJ1ZTsKICAgICAgICBpZiAoIW11c3RNYXRjaCAmJiBsZW4gPT09IDApCiAgICAgICAgICByZXR1cm4gMDsKICAgICAgICBsZXQgbG93ZXJlZENhc2UgPSBmYWxzZTsKICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgIHN3aXRjaCAoZW5jb2RpbmcpIHsKICAgICAgICAgICAgY2FzZSAiYXNjaWkiOgogICAgICAgICAgICBjYXNlICJsYXRpbjEiOgogICAgICAgICAgICBjYXNlICJiaW5hcnkiOgogICAgICAgICAgICAgIHJldHVybiBsZW47CiAgICAgICAgICAgIGNhc2UgInV0ZjgiOgogICAgICAgICAgICBjYXNlICJ1dGYtOCI6CiAgICAgICAgICAgICAgcmV0dXJuIHV0ZjhUb0J5dGVzKHN0cmluZykubGVuZ3RoOwogICAgICAgICAgICBjYXNlICJ1Y3MyIjoKICAgICAgICAgICAgY2FzZSAidWNzLTIiOgogICAgICAgICAgICBjYXNlICJ1dGYxNmxlIjoKICAgICAgICAgICAgY2FzZSAidXRmLTE2bGUiOgogICAgICAgICAgICAgIHJldHVybiBsZW4gKiAyOwogICAgICAgICAgICBjYXNlICJoZXgiOgogICAgICAgICAgICAgIHJldHVybiBsZW4gPj4+IDE7CiAgICAgICAgICAgIGNhc2UgImJhc2U2NCI6CiAgICAgICAgICAgICAgcmV0dXJuIGJhc2U2NFRvQnl0ZXMoc3RyaW5nKS5sZW5ndGg7CiAgICAgICAgICAgIGRlZmF1bHQ6CiAgICAgICAgICAgICAgaWYgKGxvd2VyZWRDYXNlKSB7CiAgICAgICAgICAgICAgICByZXR1cm4gbXVzdE1hdGNoID8gLTEgOiB1dGY4VG9CeXRlcyhzdHJpbmcpLmxlbmd0aDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgZW5jb2RpbmcgPSAoIiIgKyBlbmNvZGluZykudG9Mb3dlckNhc2UoKTsKICAgICAgICAgICAgICBsb3dlcmVkQ2FzZSA9IHRydWU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9CiAgICAgIEJ1ZmZlcjguYnl0ZUxlbmd0aCA9IGJ5dGVMZW5ndGg7CiAgICAgIGZ1bmN0aW9uIHNsb3dUb1N0cmluZyhlbmNvZGluZywgc3RhcnQsIGVuZCkgewogICAgICAgIGxldCBsb3dlcmVkQ2FzZSA9IGZhbHNlOwogICAgICAgIGlmIChzdGFydCA9PT0gdm9pZCAwIHx8IHN0YXJ0IDwgMCkgewogICAgICAgICAgc3RhcnQgPSAwOwogICAgICAgIH0KICAgICAgICBpZiAoc3RhcnQgPiB0aGlzLmxlbmd0aCkgewogICAgICAgICAgcmV0dXJuICIiOwogICAgICAgIH0KICAgICAgICBpZiAoZW5kID09PSB2b2lkIDAgfHwgZW5kID4gdGhpcy5sZW5ndGgpIHsKICAgICAgICAgIGVuZCA9IHRoaXMubGVuZ3RoOwogICAgICAgIH0KICAgICAgICBpZiAoZW5kIDw9IDApIHsKICAgICAgICAgIHJldHVybiAiIjsKICAgICAgICB9CiAgICAgICAgZW5kID4+Pj0gMDsKICAgICAgICBzdGFydCA+Pj49IDA7CiAgICAgICAgaWYgKGVuZCA8PSBzdGFydCkgewogICAgICAgICAgcmV0dXJuICIiOwogICAgICAgIH0KICAgICAgICBpZiAoIWVuY29kaW5nKQogICAgICAgICAgZW5jb2RpbmcgPSAidXRmOCI7CiAgICAgICAgd2hpbGUgKHRydWUpIHsKICAgICAgICAgIHN3aXRjaCAoZW5jb2RpbmcpIHsKICAgICAgICAgICAgY2FzZSAiaGV4IjoKICAgICAgICAgICAgICByZXR1cm4gaGV4U2xpY2UodGhpcywgc3RhcnQsIGVuZCk7CiAgICAgICAgICAgIGNhc2UgInV0ZjgiOgogICAgICAgICAgICBjYXNlICJ1dGYtOCI6CiAgICAgICAgICAgICAgcmV0dXJuIHV0ZjhTbGljZSh0aGlzLCBzdGFydCwgZW5kKTsKICAgICAgICAgICAgY2FzZSAiYXNjaWkiOgogICAgICAgICAgICAgIHJldHVybiBhc2NpaVNsaWNlKHRoaXMsIHN0YXJ0LCBlbmQpOwogICAgICAgICAgICBjYXNlICJsYXRpbjEiOgogICAgICAgICAgICBjYXNlICJiaW5hcnkiOgogICAgICAgICAgICAgIHJldHVybiBsYXRpbjFTbGljZSh0aGlzLCBzdGFydCwgZW5kKTsKICAgICAgICAgICAgY2FzZSAiYmFzZTY0IjoKICAgICAgICAgICAgICByZXR1cm4gYmFzZTY0U2xpY2UodGhpcywgc3RhcnQsIGVuZCk7CiAgICAgICAgICAgIGNhc2UgInVjczIiOgogICAgICAgICAgICBjYXNlICJ1Y3MtMiI6CiAgICAgICAgICAgIGNhc2UgInV0ZjE2bGUiOgogICAgICAgICAgICBjYXNlICJ1dGYtMTZsZSI6CiAgICAgICAgICAgICAgcmV0dXJuIHV0ZjE2bGVTbGljZSh0aGlzLCBzdGFydCwgZW5kKTsKICAgICAgICAgICAgZGVmYXVsdDoKICAgICAgICAgICAgICBpZiAobG93ZXJlZENhc2UpCiAgICAgICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCJVbmtub3duIGVuY29kaW5nOiAiICsgZW5jb2RpbmcpOwogICAgICAgICAgICAgIGVuY29kaW5nID0gKGVuY29kaW5nICsgIiIpLnRvTG93ZXJDYXNlKCk7CiAgICAgICAgICAgICAgbG93ZXJlZENhc2UgPSB0cnVlOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgICBCdWZmZXI4LnByb3RvdHlwZS5faXNCdWZmZXIgPSB0cnVlOwogICAgICBmdW5jdGlvbiBzd2FwKGIsIG4sIG0pIHsKICAgICAgICBjb25zdCBpID0gYltuXTsKICAgICAgICBiW25dID0gYlttXTsKICAgICAgICBiW21dID0gaTsKICAgICAgfQogICAgICBCdWZmZXI4LnByb3RvdHlwZS5zd2FwMTYgPSBmdW5jdGlvbiBzd2FwMTYoKSB7CiAgICAgIC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IGkgKz0gOCkgewogICAgICAgICAgc3dhcCh0aGlzLCBpLCBpICsgNyk7CiAgICAgICAgICBzd2FwKHRoaXMsIGkgKyAxLCBpICsgNik7CiAgICAgICAgICBzd2FwKHRoaXMsIGkgKyAyLCBpICsgNSk7CiAgICAgICAgICBzd2FwKHRoaXMsIGkgKyAzLCBpICsgNCk7CiAgICAgICAgfQogICAgICAgIHJldHVybiB0aGlzOwogICAgICB9OwogICAgICBCdWZmZXI4LnByb3RvdHlwZS50b1N0cmluZyA9IGZ1bmN0aW9uIHRvU3RyaW5nKCkgewogICAgICAgIGNvbnN0IGxlbmd0aCA9IHRoaXMubGVuZ3RoOwogICAgICAgIGlmIChsZW5ndGggPT09IDApCiAgICAgICAgICByZXR1cm4gIiI7CiAgICAgICAgaWYgKGFyZ3VtZW50cy5sZW5ndGggPT09IDApCiAgICAgICAgICByZXR1cm4gdXRmOFNsaWNlKHRoaXMsIDAsIGxlbmd0aCk7CiAgICAgICAgcmV0dXJuIHNsb3dUb1N0cmluZy5hcHBseSh0aGlzLCBhcmd1bWVudHMpOwogICAgICB9OwogICAgICBCdWZmZXI4LnByb3RvdHlwZS50b0xvY2FsZVN0cmluZyA9IEJ1ZmZlcjgucHJvdG90eXBlLnRvU3RyaW5nOwogICAgICBCdWZmZXI4LnByb3RvdHlwZS5lcXVhbHMgPSBmdW5jdGlvbiBlcXVhbHMoYikgewogICAgICAgIGlmICghQnVmZmVyOC5pc0J1ZmZlcihiKSkKICAgICAgICAgIHRocm93IG5ldyBUeXBlRXJyb3IoIkFyZ3VtZW50IG11c3QgYmUgYSBCdWZmZXIiKTsKICAgICAgICBpZiAodGhpcyA9PT0gYikKICAgICAgICAgIHJldHVybiB0cnVlOwogICAgICAgIHJldHVybiBCdWZmZXI4LmNvbXBhcmUodGhpcywgYikgPT09IDA7CiAgICAgIH07CiAgICAgIEJ1ZmZlcjgucHJvdG90eXBlLmluc3BlY3QgPSBmdW5jdGlvbiBpbnNwZWN0KCkgewogICAgICAg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AgICAgICBpZiAoZW5kID09PSB2b2lkIDApIHsKICAgICAgICAgIGVuZCA9IHRhcmdldCA/IHRhcmdldC5sZW5ndGggOiAwOwogICAgICAgIH0KICAgICAgICBpZiAodGhpc1N0YXJ0ID09PSB2b2lkIDApIHsKICAgICAgICAgIHRoaXNTdGFydCA9IDA7CiAgICAgICAgfQogICAgICAgIGlmICh0aGlzRW5kID09PSB2b2lkIDApIHsKICAgICAgICAgIHRoaXNFbmQgPSB0aGlzLmxlbmd0aDsKICAgICAgICB9CiAgICAgICAgaWYgKHN0YXJ0IDwgMCB8fCBlbmQgPiB0YXJnZXQubGVuZ3RoIHx8IHRoaXNTdGFydCA8IDAgfHwgdGhpc0VuZCA+IHRoaXMubGVuZ3RoKSB7CiAgICAgICAgICB0aHJvdyBuZXcgUmFuZ2VFcnJvcigib3V0IG9mIHJhbmdlIGluZGV4Iik7CiAgICAgICAgfQogICAgICAgIGlmICh0aGlzU3RhcnQgPj0gdGhpc0VuZCAmJiBzdGFydCA+PSBlbmQpIHsKICAgICAgICAgIHJldHVybiAwOwogICAgICAgIH0KICAgICAgICBpZiAodGhpc1N0YXJ0ID49IHRoaXNFbmQpIHsKICAgICAgICAgIHJldHVybiAtMTsKICAgICAgICB9CiAgICAgICAgaWYgKHN0YXJ0ID49IGVuZCkgewogICAgICAgICAgcmV0dXJuIDE7CiAgICAgICAgfQogICAgICAgIHN0YXJ0ID4+Pj0gMDsKICAgICAgICBlbmQgPj4+PSAwOwogICAgICAgIHRoaXNTdGFydCA+Pj49IDA7CiAgICAgICAgdGhpc0VuZCA+Pj49IDA7CiAgICAgICAgaWYgKHRoaXMgPT09IHRhcmdldCkKICAgICAgICAgIHJldHVybiAwOwogICAgICAgIGxldCB4ID0gdGhpc0VuZCAtIHRoaXNTdGFydDsKICAgICAgICBsZXQgeSA9IGVuZCAtIHN0YXJ0OwogICAgICAgIGNvbnN0IGxlbiA9IE1hdGgubWluKHgsIHkpOwogICAgICAgIGNvbnN0IHRoaXNDb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1iZXJJc05hTihieXRlT2Zmc2V0KSkgewogICAgICAgICAgYnl0ZU9mZnNldCA9IGRpciA/IDAgOiBidWZmZXIubGVuZ3RoIC0gMTsKICAgICAgICB9CiAgICAgICAgaWYgKGJ5dGVPZmZzZXQgPCAwKQogICAgICAgICAgYnl0ZU9mZnNldCA9IGJ1ZmZlci5sZW5ndGggKyBieXRlT2Zmc2V0OwogICAgICAgIGlmIChieXRlT2Zmc2V0ID49IGJ1ZmZlci5sZW5ndGgpIHsKICAgICAgICAgIGlmIChkaXIpCiAgICAgICAgICAgIHJldHVybiAtMTsKICAgICAgICAgIGVsc2UKICAgICAgICAgICAgYnl0ZU9mZnNldCA9IGJ1ZmZlci5sZW5ndGggLSAxOwogICAgICAgIH0gZWxzZSBpZiAoYnl0ZU9mZnNldCA8IDApIHsKICAgICAgICAgIGlmIChkaXIpCiAgICAgICAgICAgIGJ5dGVPZmZzZXQgPSAwOwogICAgICAgICAgZWxzZQogICAgICAgICAgICByZXR1cm4gLTE7CiAgICAgICAgfQogICAgICAgIGlmICh0eXBlb2YgdmFsID09PSAic3RyaW5nIikgewogICAgICAgICAgdmFsID0gQnVmZmVyOC5mcm9tKHZhbCwgZW5jb2RpbmcpOwogICAgICAgIH0KICAgICAgICBpZiAoQnVmZmVyOC5pc0J1ZmZlcih2YWwpKSB7CiAgICAgICAgICBpZiAodmFsLmxlbmd0aCA9PT0gMCkgewogICAgICAgICAgICByZXR1cm4gLTE7CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gYXJyYXlJbmRleE9mKGJ1ZmZlciwgdmFsLCBieXRlT2Zmc2V0LCBlbmNvZGluZywgZGlyKTsKICAgICAgICB9IGVsc2UgaWYgKHR5cGVvZiB2YWwgPT09ICJudW1iZXIiKSB7CiAgICAgICAgICB2YWwgPSB2YWwgJiAyNTU7CiAgICAgICAgICBpZiAodHlwZW9mIFVpbnQ4QXJyYXkucHJvdG90eXBlLmluZGV4T2YgPT09ICJmdW5jdGlvbiIpIHsKICAgICAgICAgICAgaWYgKGRpcikgewogICAgICAgICAgICAgIHJldHVybiBVaW50OEFycmF5LnByb3RvdHlwZS5pbmRleE9mLmNhbGwoYnVmZmVyLCB2YWwsIGJ5dGVPZmZzZXQpOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHJldHVybiBVaW50OEFycmF5LnByb3RvdHlwZS5sYXN0SW5kZXhPZi5jYWxsKGJ1ZmZlciwgdmFsLCBieXRlT2Zmc2V0KTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIGFycmF5SW5kZXhPZihidWZmZXIsIFt2YWxdLCBieXRlT2Zmc2V0LCBlbmNvZGluZywgZGlyKTsKICAgICAgICB9CiAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcigidmFsIG11c3QgYmUgc3RyaW5nLCBudW1iZXIgb3IgQnVmZmVyIik7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gYXJyYXlJbmRleE9mKGFyciwgdmFsLCBieXRlT2Zmc2V0LCBlbmNvZGluZywgZGlyKSB7CiAgICAgICAgbGV0IGluZGV4U2l6ZSA9IDE7CiAgICAgICAgbGV0IGFyckxlbmd0aCA9IGFyci5sZW5ndGg7CiAgICAgICAgbGV0IHZhbExlbmd0aCA9IHZhbC5sZW5ndGg7CiAgICAgICAgaWYgKGVuY29kaW5nICE9PSB2b2lkIDApIHsKICAgICAgICAgIGVuY29kaW5nID0gU3RyaW5nKGVuY29kaW5nKS50b0xvd2VyQ2FzZSgpOwogICAgICAgICAgaWYgKGVuY29kaW5nID09PSAidWNzMiIgfHwgZW5jb2RpbmcgPT09ICJ1Y3MtMiIgfHwgZW5jb2RpbmcgPT09ICJ1dGYxNmxlIiB8fCBlbmNvZGluZyA9PT0gInV0Zi0xNmxlIikgewogICAgICAgICAgICBpZiAoYXJyLmxlbmd0aCA8IDIgfHwgdmFsLmxlbmd0aCA8IDIpIHsKICAgICAgICAgICAgICByZXR1cm4gLTE7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaW5kZXhTaXplID0gMjsKICAgICAgICAgICAgYXJyTGVuZ3RoIC89IDI7CiAgICAgICAgICAgIHZhbExlbmd0aCAvPSAyOwogICAgICAgICAgICBieXRlT2Zmc2V0IC89IDI7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIHJlYWQoYnVmLCBpMikgewogICAgICAgICAgaWYgKGluZGV4U2l6ZSA9PT0gMSkgewogICAgICAgICAgICByZXR1cm4gYnVmW2kyXTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHJldHVybiBidWYucmVhZFVJbnQxNkJFKGkyICogaW5kZXhTaXplKTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgbGV0IGk7CiAgICAgICAgaWYgKGRpcikgewogICAgICAgICAgbGV0IGZvdW5kSW5kZXggPSAtMTsKICAgICAgICAgIGZvciAoaSA9IGJ5dGVPZmZzZXQ7IGkgPCBhcnJMZW5ndGg7IGkrKykgewogICAgICAgICAgICBpZiAocmVhZChhcnIsIGkpID09PSByZWFkKHZhbCwgZm91bmRJbmRleCA9PT0gLTEgPyAwIDogaSAtIGZvdW5kSW5kZXgpKSB7CiAgICAgICAgICAgICAgaWYgKGZvdW5kSW5kZXggPT09IC0xKQogICAgICAgICAgICAgICAgZm91bmRJbmRleCA9IGk7CiAgICAgICAgICAgICAgaWYgKGkgLSBmb3VuZEluZGV4ICsgMSA9PT0gdmFsTGVuZ3RoKQogICAgICAgICAgICAgICAgcmV0dXJuIGZvdW5kSW5kZXggKiBpbmRleFNpemU7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgaWYgKGZvdW5kSW5kZXggIT09IC0xKQogICAgICAgICAgICAgICAgaSAtPSBpIC0gZm91bmRJbmRleDsKICAgICAgICAgICAgICBmb3VuZEluZGV4ID0gLTE7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9IGVsc2UgewogICAgICAgICAgaWYgKGJ5dGVPZmZzZXQgKyB2YWxMZW5ndGggPiBhcnJMZW5ndGgpCiAgICAgICAgICAgIGJ5dGVPZmZzZXQgPSBhcnJMZW5ndGggLSB2YWxMZW5ndGg7CiAgICAgICAgICBmb3IgKGkgPSBieXRlT2Zmc2V0OyBpID49IDA7IGktLSkgewogICAgICAgICAgICBsZXQgZm91bmQgPSB0cnVlOwogICAgICAgICAgICBmb3IgKGxldCBqID0gMDsgaiA8IHZhbExlbmd0aDsgaisrKSB7CiAgICAgICAgICAgICAgaWYgKHJlYWQoYXJyLCBpICsgaikgIT09IHJlYWQodmFsLCBqKSkgewogICAgICAgICAgICAgICAgZm91bmQgPSBmYWxzZTsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoZm91bmQpCiAgICAgICAgICAgICAgcmV0dXJuIGk7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiAtMTsKICAgICAgfQogICAgICBCdWZmZXI4LnByb3RvdHlwZS5pbmNsdWRlcyA9IGZ1bmN0aW9uIGluY2x1ZGVzKHZhbCwgYnl0ZU9mZnNldCwgZW5jb2RpbmcpIHsKICAgICAgICByZXR1cm4gdGhpcy5pbmRleE9mKHZhbCwgYnl0ZU9mZnNldCwgZW5jb2RpbmcpICE9PSAtMTsKICAgICAgfTsKICAgICAgQnVmZmVyOC5wcm90b3R5cGUuaW5kZXhPZiA9IGZ1bmN0aW9uIGluZGV4T2YodmFsLCBieXRlT2Zmc2V0LCBlbmNvZGluZykgewogICAgICAgIHJldHVybiBiaWRpcmVjdGlvbmFsSW5kZXhPZih0aGlzLCB2YWwsIGJ5dGVPZmZzZXQsIGVuY29kaW5nLCB0cnVlKTsKICAgICAgfTsKICAgICAgQnVmZmVyOC5wcm90b3R5cGUubGFzdEluZGV4T2YgPSBmdW5jdGlvbiBsYXN0SW5kZXhPZih2YWwsIGJ5dGVPZmZzZXQsIGVuY29kaW5nKSB7CiAgICAgICAgcmV0dXJuIGJpZGlyZWN0aW9uYWxJbmRleE9mKHRoaXMsIHZhbCwgYnl0ZU9mZnNldCwgZW5jb2RpbmcsIGZhbHNlKTsKICAgICAgfTsKICAgICAgZnVuY3Rpb24gaGV4V3JpdGUoYnVmLCBzdHJpbmcsIG9mZnNldCwgbGVuZ3RoKSB7CiAgICAgICAgb2Zmc2V0ID0gTnVtYmVyKG9mZnNldCkgfHwgMDsKICAgICAgICBjb25zdCByZW1haW5pbmcgPSBidWYubGVuZ3RoIC0gb2Zmc2V0OwogICAgICAgIGlmICghbGVuZ3RoKSB7CiAgICAgICAgICBsZW5ndGggPSByZW1haW5pbmc7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIGxlbmd0aCA9IE51bWJlcihsZW5ndGgpOwogICAgICAgICAgaWYgKGxlbmd0aCA+IHJlbWFpbmluZykgewogICAgICAgICAgICBsZW5ndGggPSByZW1haW5pbmc7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGNvbnN0IHN0ckxlbiA9IHN0cmluZy5sZW5ndGg7CiAgICAgICAgaWYgKGxlbmd0aCA+IHN0ckxlbiAvIDIpIHsKICAgICAgICAgIGxlbmd0aCA9IHN0ckxlbiAvIDI7CiAgICAgICAgfQogICAgICAgIGxldCBpOwogICAgICAgIGZvciAoaSA9IDA7IGkgPCBsZW5ndGg7ICsraSkgewogICAgICAgICAgY29uc3QgcGFyc2VkID0gcGFyc2VJbnQoc3RyaW5nLnN1YnN0cihpICogMiwgMiksIDE2KTsKICAgICAgICAgIGlmIChudW1iZXJJc05hTihwYXJzZWQpKQogICAgICAgICAgICByZXR1cm4gaTsKICAgICAgICAgIGJ1ZltvZmZzZXQgKyBpXSA9IHBhcnNlZDsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIGk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gdXRmOFdyaXRlKGJ1Ziwgc3RyaW5nLCBvZmZzZXQsIGxlbmd0aCkgewogICAgICAgI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CI7CiAgICAgICAgbGV0IGxvd2VyZWRDYXNlID0gZmFsc2U7CiAgICAgICAgZm9yICg7IDsgKSB7CiAgICAgICAgICBzd2l0Y2ggKGVuY29kaW5nKSB7CiAgICAgICAgICAgIGNhc2UgImhleCI6CiAgICAgICAgICAgICAgcmV0dXJuIGhleFdyaXRlKHRoaXMsIHN0cmluZywgb2Zmc2V0LCBsZW5ndGgpOwogICAgICAgICAgICBjYXNlICJ1dGY4IjoKICAgICAgICAgICAgY2FzZSAidXRmLTgiOgogICAgICAgICAgICAgIHJldHVybiB1dGY4V3JpdGUodGhpcywgc3RyaW5nLCBvZmZzZXQsIGxlbmd0aCk7CiAgICAgICAgICAgIGNhc2UgImFzY2lpIjoKICAgICAgICAgICAgY2FzZSAibGF0aW4xIjoKICAgICAgICAgICAgY2FzZSAiYmluYXJ5IjoKICAgICAgICAgICAgICByZXR1cm4gYXNjaWlXcml0ZSh0aGlzLCBzdHJpbmcsIG9mZnNldCwgbGVuZ3RoKTsKICAgICAgICAgICAgY2FzZSAiYmFzZTY0IjoKICAgICAgICAgICAgICByZXR1cm4gYmFzZTY0V3JpdGUodGhpcywgc3RyaW5nLCBvZmZzZXQsIGxlbmd0aCk7CiAgICAgICAgICAgIGNhc2UgInVjczIiOgogICAgICAgICAgICBjYXNlICJ1Y3MtMiI6CiAgICAgICAgICAgIGNhc2UgInV0ZjE2bGUiOgogICAgICAgICAgICBjYXNlICJ1dGYtMTZsZSI6CiAgICAgICAgICAgICAgcmV0dXJuIHVjczJXcml0ZSh0aGlzLCBzdHJpbmcsIG9mZnNldCwgbGVuZ3RoKTsKICAgICAgICAgICAgZGVmYXVsdDoKICAgICAgICAgICAgICBpZiAobG93ZXJlZENhc2UpCiAgICAgICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCJVbmtub3duIGVuY29kaW5nOiAiICsgZW5jb2RpbmcpOwogICAgICAgICAgICAgIGVuY29kaW5nID0gKCIiICsgZW5jb2RpbmcpLnRvTG93ZX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zUGVyU2VxdWVuY2UgPD0gZW5kKSB7CiAgICAgICAgICAgIGxldCBzZWNvbmRCeXRlLCB0aGlyZEJ5dGUsIGZvdXJ0aEJ5dGUsIHRlbXBDb2RlUG9pbnQ7CiAgICAgICAgICAgIHN3aXRjaCAoYnl0ZXNQZXJTZXF1ZW5jZSkgewogICAgICAgICAgICAgIGNhc2UgMToKICAgICAgICAgICAgICAgIGlmIChmaXJzdEJ5dGUgPCAxMjgpIHsKICAgICAgICAgICAgICAgICAgY29kZVBvaW50ID0gZmlyc3RCeXRlOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgY2FzZSAyOgogICAgICAgICAgICAgICAgc2Vjb25kQnl0ZSA9IGJ1ZltpICsgMV07CiAgICAgICAgICAgICAgICBpZiAoKHNlY29uZEJ5dGUgJiAxOTIpID09PSAxMjgpIHsKICAgICAgICAgICAgICAgICAgdGVtcENvZGVQb2ludCA9IChmaXJzdEJ5dGUgJiAzMSkgPDwgNiB8IHNlY29uZEJ5dGUgJiA2MzsKICAgICAgICAgICAgICAgICAgaWYgKHRlbXBDb2RlUG9pbnQgPiAxMjcpIHsKICAgICAgICAgICAgICAgICAgICBjb2RlUG9pbnQgPSB0ZW1wQ29kZVBvaW50OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICBjYXNlIDM6CiAgICAgICAgICAgICAgICBzZWNvbmRCeXRlID0gYnVmW2kgKyAxXTsKICAgICAgICAgICAgICAgIHRoaXJkQnl0ZSA9IGJ1ZltpICsgMl07CiAgICAgICAgICAgICAgICBpZiAoKHNlY29uZEJ5dGUgJiAxOTIpID09PSAxMjggJiYgKHRoaXJkQnl0ZSAmIDE5MikgPT09IDEyOCkgewogICAgICAgICAgICAgICAgICB0ZW1wQ29kZVBvaW50ID0gKGZpcnN0Qnl0ZSAmIDE1KSA8PCAxMiB8IChzZWNvbmRCeXRlICYgNjMpIDw8IDYgfCB0aGlyZEJ5dGUgJiA2MzsKICAgICAgICAgICAgICAgICAgaWYgKHRlbXBDb2RlUG9pbnQgPiAyMDQ3ICYmICh0ZW1wQ29kZVBvaW50IDwgNTUyOTYgfHwgdGVtcENvZGVQb2ludCA+IDU3MzQzKSkgewogICAgICAgICAgICAgICAgICAgIGNvZGVQb2ludCA9IHRlbXBDb2RlUG9pbnQ7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgIGNhc2UgNDoKICAgICAgICAgICAgICAgIHNlY29uZEJ5dGUgPSBidWZbaSArIDFdOwogICAgICAgICAgICAgICAgdGhpcmRCeXRlID0gYnVmW2kgKyAyXTsKICAgICAgICAgICAgICAgIGZvdXJ0aEJ5dGUgPSBidWZbaSArIDNdOwogICAgICAgICAgICAgICAgaWYgKChzZWNvbmRCeXRlICYgMTkyKSA9PT0gMTI4ICYmICh0aGlyZEJ5dGUgJiAxOTIpID09PSAxMjggJiYgKGZvdXJ0aEJ5dGUgJiAxOTIpID09PSAxMjgpIHsKICAgICAgICAgICAgICAgICAgdGVtcENvZGVQb2ludCA9IChmaXJzdEJ5dGUgJiAxNSkgPDwgMTggfCAoc2Vjb25kQnl0ZSAmIDYzKSA8PCAxMiB8ICh0aGlyZEJ5dGUgJiA2MykgPDwgNiB8IGZvdXJ0aEJ5dGUgJiA2MzsKICAgICAgICAgICAgICAgICAgaWYgKHRlbXBDb2RlUG9pbnQgPiA2NTUzNSAmJiB0ZW1wQ29kZVBvaW50IDwgMTExNDExMikgewogICAgICAgICAgICAgICAgICAgIGNvZGVQb2ludCA9IHRlbXBDb2RlUG9pbnQ7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgaWYgKGNvZGVQb2ludCA9PT0gbnVsbCkgewogICAgICAgICAgICBjb2RlUG9pbnQgPSA2NTUzMzsKICAgICAgICAgICAgYnl0ZXNQZXJTZXF1ZW5jZSA9IDE7CiAgICAgICAgICB9IGVsc2UgaWYgKGNvZGVQb2ludCA+IDY1NTM1KSB7CiAgICAgICAgICAgIGNvZGVQb2ludCAtPSA2NTUzNjsKICAgICAgICAgICAgcmVzLnB1c2goY29kZVBvaW50ID4+PiAxMCAmIDEwMjMgfCA1NTI5Nik7CiAgICAgICAgICAgIGNvZGVQb2ludCA9IDU2MzIwIHwgY29kZVBvaW50ICYgMTAyMzsKICAgICAgICAgIH0KICAgICAgICAgIHJlcy5wdXNoKGNvZGVQb2ludCk7CiAgICAgICAgICBpICs9IGJ5dGVzUGVyU2VxdWVuY2U7CiAgICAgICAgfQogICAgICAgIHJldHVybiBkZWNvZGVDb2RlUG9pbnRzQXJyYXkocmVzKTsKICAgICAgfQogICAgICB2YXIgTUFYX0FSR1VNRU5UU19MRU5HVEggPSA0MDk2OwogICAgICBmdW5jdGlvbiBkZWNvZGVDb2RlUG9pbnRzQXJyYXkoY29kZVBvaW50cykgewogICAgICAgIGNvbnN0IGxlbiA9IGNvZGVQb2ludHMubGVuZ3RoOwogICAgICAgIGlmIChsZW4gPD0gTUFYX0FSR1VNRU5UU19MRU5HVEgpIHsKICAgICAgICAgIHJldHVybiBTdHJpbmcuZnJvbUNoYXJDb2RlLmFwcGx5KFN0cmluZywgY29kZVBvaW50cyk7CiAgICAgICAgfQogICAgICAgIGxldCByZXMgPSAiIjsKICAgICAgICBsZXQgaSA9IDA7CiAgICAgICAgd2hpbGUgKGkgPCBsZW4pIHsKICAgICAgICAgIHJlcyArPSBTdHJpbmcuZnJvbUNoYXJDb2RlLmFwcGx5KFN0cmluZywgY29kZVBvaW50cy5zbGljZShpLCBpICs9IE1BWF9BUkdVTUVOVFNfTEVOR1RIKSk7CiAgICAgICAgfQogICAgICAgIHJldHVybiByZXM7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gYXNjaWlTbGljZShidWYsIHN0YXJ0LCBlbmQpIHsKICAgICAgICBsZXQgcmV0ID0gIiI7CiAgICAgICAgZW5kID0gTWF0aC5taW4oYnVmLmxlbmd0aCwgZW5kKTsKICAgICAgICBmb3IgKGxldCBpID0gc3RhcnQ7IGkgPCBlbmQ7ICsraSkgewogICAgICAgICAgcmV0ICs9IFN0cmluZy5mcm9tQ2hhckNvZGUoYnVmW2ldICYgMTI3KTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHJldDsKICAgICAgfQogICAgICBmdW5jdGlvbiBsYXRpbjFTbGljZShidWYsIHN0YXJ0LCBlbmQpIHsKICAgICAgICBsZXQgcmV0ID0gIiI7CiAgICAgICAgZW5kID0gTWF0aC5taW4oYnVmLmxlbmd0aCwgZW5kKTsKICAgICAgICBmb3IgKGxldCBpID0gc3RhcnQ7IGkgPCBlbmQ7ICsraSkgewogICAgICAgICAgcmV0ICs9IFN0cmluZy5mcm9tQ2hhckNvZGUoYnVmW2ldKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHJldDsKICAgICAgfQogICAgICBmdW5jdGlvbiBoZXhTbGljZShidWYsIHN0YXJ0LCBlbmQpIHsKICAgICAgICBjb25zdCBsZW4gPSBidWYubGVuZ3RoOwogICAgICAgIGlmICghc3RhcnQgfHwgc3RhcnQgPCAwKQogICAgICAgICAgc3RhcnQgPSAwOwogICAgICAgIGlmICghZW5kIHx8IGVuZCA8IDAgfHwgZW5kID4gbGVuKQogICAgICAgICAgZW5kID0gbGVuOwogICAgICAgIGxldCBvdXQgPSAiIjsKICAgICAgICBmb3IgKGxldCBpID0gc3RhcnQ7IGkgPCBlbmQ7ICsraSkgewogICAgICAgICAgb3V0ICs9IGhleFNsaWNlTG9va3VwVGFibGVbYnVmW2ldXTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIG91dDsKICAgICAgfQogICAgICBmdW5jdGlvbiB1dGYxNmxlU2xpY2UoYnVmLCBzdGFydCwgZW5kKSB7CiAgICAgICAgY29uc3QgYnl0ZXMg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AgICAgICBpZiAoZW5kID4gMCAmJiBlbmQgPCBzdGFydCkKICAgICAgICAgIGVuZCA9IHN0YXJ0OwogICAgICAgIGlmIChlbmQgPT09IHN0YXJ0KQogICAgICAgICAgcmV0dXJuIDA7CiAgICAgICAgaWYgKHRhcmdldC5sZW5ndGggPT09IDAgfHwgdGhpcy5sZW5ndGggPT09IDApCiAgICAgICAgICByZXR1cm4gMDsKICAgICAgICBpZiAodGFyZ2V0U3RhcnQgPCAwKSB7CiAgICAgICAgICB0aHJvdyBuZXcgUmFuZ2VFcnJvcigidGFyZ2V0U3RhcnQgb3V0IG9mIGJvdW5kcyIpOwogICAgICAgIH0KICAgICAgICBpZiAoc3RhcnQgPCAwIHx8IHN0YXJ0ID49IHRoaXMubGVuZ3RoKQogICAgICAgICAgdGhyb3cgbmV3IFJhbmdlRXJyb3IoIkluZGV4IG91dCBvZiByYW5nZSIpOwogICAgICAgIGlmIChlbmQgPCAwKQogICAgICAgICAgdGhyb3cgbmV3IFJhbmdlRXJyb3IoInNvdXJjZUVuZCBvdXQgb2YgYm91bmRzIik7CiAgICAgICAgaWYgKGVuZCA+IHRoaXMubGVuZ3RoKQogICAgICAgICAgZW5kID0gdGhpcy5sZW5ndGg7CiAgICAgICAgaWYgKHRhcmdldC5sZW5ndGggLSB0YXJnZXRTdGFydCA8IGVuZCAtIHN0YXJ0KSB7CiAgICAgICAgICBlbmQgPSB0YXJnZXQubGVuZ3RoIC0gdGFyZ2V0U3RhcnQgKyBzdGFydDsKICAgICAgICB9CiAgICAgICAgY29uc3QgbGVuID0gZW5kIC0gc3RhcnQ7CiAgICAgICAgaWYgKHRoaXMgPT09IHRhcmdldCAmJiB0eXBlb2YgVWludDhBcnJheS5wcm90b3R5cGUuY29weVdpdGhpbiA9PT0gImZ1bmN0aW9uIikgewogICAgICAgICAgdGhpcy5jb3B5V2l0aGluKHRhcmdldFN0YXJ0LCBzdGFydCwgZW5kKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgVWludDhBcnJheS5wcm90b3R5cGUuc2V0LmNhbGwodGFyZ2V0LCB0aGlzLnN1YmFycmF5KHN0YXJ0LCBlbmQpLCB0YXJnZXRTdGFydCk7CiAgICAgICAgfQogICAgICAgIHJldHVybiBsZW47CiAgICAgIH07CiAgICAgIEJ1ZmZlcjgucHJvdG90eXBlLmZpbGwgPSBmdW5jdGlvbiBmaWxsKHZhbCwgc3RhcnQsIGVuZCwgZW5jb2RpbmcpIHsKICAgICAgICBpZiAodHlwZW9mIHZhbCA9PT0gInN0cmluZyIpIHsKICAgICAgICAgIGlmICh0eXBlb2Ygc3RhcnQgPT09ICJzdHJpbmciKSB7CiAgICAgICAgICAgIGVuY29kaW5nID0gc3RhcnQ7CiAgICAgICAgICAgIHN0YXJ0ID0gMDsKICAgICAgICAgICAgZW5kID0gdGhpcy5sZW5ndGg7CiAgICAgICAgICB9IGVsc2UgaWYgKHR5cGVvZiBlbmQgPT09ICJzdHJpbmciKSB7CiAgICAgICAgICAgIGVuY29kaW5nID0gZW5kOwogICAgICAgICAgICBlbmQgPSB0aGlzLmxlbmd0aDsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChlbmNvZGluZyAhPT0gdm9pZCAwICYmIHR5cGVvZiBlbmNvZGluZyAhPT0gInN0cmluZyIpIHsKICAgICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcigiZW5jb2RpbmcgbXVzdCBiZSBhIHN0cmluZyIpOwogICAgICAgICAgfQogICAgICAgICAgaWYgKHR5cGVvZiBlbmNvZGluZyA9PT0gInN0cmluZyIgJiYgIUJ1ZmZlcjguaXNFbmNvZGluZyhlbmNvZGluZykpIHsKICAgICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcigiVW5rbm93biBlbmNvZGluZzogIiArIGVuY29kaW5nKTsKICAgICAgICAgIH0KICAgICAgICAgIGlmICh2YWwubGVuZ3RoID09PSAxKSB7CiAgICAgICAgICAgIGNvbnN0IGNvZGUgPSB2YWwuY2hhckNvZGVBdCgwKTsKICAgICAgICAgICAgaWYgKGVuY29kaW5nID09PSAidXRmOCIgJiYgY29kZSA8IDEyOCB8fCBlbmNvZGluZyA9PT0gImxhdGluMSIpIHsKICAgICAgICAgICAgICB2YWwgPSBjb2RlOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfSBlbHNlIGlmICh0eXBlb2YgdmFsID09PSAibnVtYmVyIikgewogICAgICAgICAgdmFsID0gdmFsICYgMjU1OwogICAgICAgIH0gZWxzZSBpZiAodHlwZW9mIHZhbCA9PT0gImJvb2xlYW4iKSB7CiAgICAgICAgICB2YWwgPSBOdW1iZXIodmFsKTsKICAgICAgICB9CiAgICAgICAgaWYgKHN0YXJ0IDwgMCB8fCB0aGlzLmxlbmd0aCA8IHN0YXJ0IHx8IHRoaXMubGVuZ3RoIDwgZW5kKSB7CiAgICAgICAgICB0aHJvdyBuZXcgUmFuZ2VFcnJvcigiT3V0IG9mIHJhbmdlIGluZGV4Iik7CiAgICAgICAgfQogICAgICAgIGlmIChlbmQgPD0gc3RhcnQpIHsKICAgICAgICAgIHJldHVybiB0aGlzOwogICAgICAgIH0KICAgICAgICBzdGFydCA9IHN0YXJ0ID4+PiAwOwogICAgICAgIGVuZCA9IGVuZCA9PT0gdm9pZCAwID8gdGhpcy5sZW5ndGggOiBlbmQgPj4+IDA7CiAgICAgICAgaWYgKCF2YWwpCiAgICAgICAgICB2YWwgPSAwOwogICAgICAgIGxldCBpOwogICAgICAgIGlmICh0eXBlb2YgdmFsID09PSAibnVtYmVyIikgewogICAgICAgICAgZm9yIChpID0gc3RhcnQ7IGkgPCBlbmQ7ICsraSkgewogICAgICAgICAgICB0aGlzW2ldID0gdmFsOwogICAgICAgICAgfQogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBjb25zdCBieXRlcyA9IEJ1ZmZlcjguaXNCdWZmZXIodmFsKSA/IHZhbCA6IEJ1ZmZlcjguZnJvbSh2YWwsIGVuY29kaW5nKTsKICAgICAgICAgIGNvbnN0IGxlbiA9IGJ5dGVzLmxlbmd0aDsKICAgICAgICAgIGlmIChsZW4gPT09IDApIHsKICAgICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcignVGhlIHZhbHVlICInICsgdmFsICsgJyIgaXMgaW52YWxpZCBmb3IgYXJndW1lbnQgInZhbHVlIicpOwogICAgICAgICAgfQogICAgICAgICAgZm9yIChpID0gMDsgaSA8IGVuZCAtIHN0YXJ0OyArK2kpIHsKICAgICAgICAgICAgdGhpc1tpICsgc3RhcnRdID0gYnl0ZXNbaSAlIGxlbl07CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiB0aGlzOwogICAgICB9OwogICAgICB2YXIgZXJyb3JzID0ge307CiAgICAgIGZ1bmN0aW9uIEUoc3ltLCBnZXRNZXNzYWdlLCBCYXNlKSB7CiAgICAgICAgZXJyb3JzW3N5bV0gPSBjbGFzcyBOb2RlRXJyb3IgZXh0ZW5kcyBCYXNlIHsKICAgICAgICAgIGNvbnN0cnVjdG9yKCkgewogICAgICAgICAgICBzdXBlcigpOwogICAgICAgICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkodGhpcywgIm1lc3NhZ2UiLCB7CiAgICAgICAgICAgICAgdmFsdWU6IGdldE1lc3NhZ2UuYXBwbHkodGhpcywgYXJndW1lbnRzKSwKICAgICAgICAgICAgICB3cml0YWJsZTogdHJ1ZSwKICAgICAgICAgICAgICBjb25maWd1cmFibGU6IHRydWUKICAgICAgICAgICAgfSk7CiAgICAgICAgICAgIHRoaXMubmFtZSA9IGAke3RoaXMubmFtZX0gWyR7c3ltfV1gOwogICAgICAgICAgICB0aGlzLnN0YWNrOwogICAgICAgICAgICBkZWxldGUgdGhpcy5uYW1lOwogICAgICAgICAgfQogICAgICAgICAgZ2V0IGNvZGUoKSB7CiAgICAgICAgICAgIHJldHVybiBzeW07CiAgICAgICAgICB9CiAgICAgICAgICBzZXQgY29kZSh2YWx1ZSkgewogICAgICAgICAgICBPYmplY3QuZGVmaW5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SgpLnJlcGxhY2UoSU5WQUxJRF9CQVNFNjRfUkUsICIiKTsKICAgICAgICBpZiAoc3RyLmxlbmd0aCA8IDIpCiAgICAgICAgICByZXR1cm4gIiI7CiAgICAgICAgd2hpbGUgKHN0ci5sZW5ndGggJSA0ICE9PSAwKSB7CiAgICAgICAgICBzdHIgPSBzdHIgKyAiPSI7CiAgICAgICAgfQogICAgICAgIHJldHVybiBzdHI7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gdXRmOFRvQnl0ZXMoc3RyaW5nLCB1bml0cykgewogICAgICAgIHVuaXRzID0gdW5pdHMgfHwgSW5maW5pdHk7CiAgICAgICAgbGV0IGNvZGVQb2ludDsKICAgICAgICBjb25zdCBsZW5ndGggPSBzdHJpbmcubGVuZ3RoOwogICAgICAgIGxldCBsZWFkU3Vycm9nYXRlID0gbnVsbDsKICAgICAgICBjb25zdCBieXRlcyA9IFtdOwogICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgbGVuZ3RoOyArK2kpIHsKICAgICAgICAgIGNvZGVQb2ludCA9IHN0cmluZy5jaGFyQ29kZUF0KGkpOwogICAgICAgICAgaWYgKGNvZGVQb2ludCA+IDU1Mjk1ICYmIGNvZGVQb2ludCA8IDU3MzQ0KSB7CiAgICAgICAgICAgIGlmICghbGVhZFN1cnJvZ2F0ZSkgewogICAgICAgICAgICAgIGlmIChjb2RlUG9pbnQgPiA1NjMxOSkgewogICAgICAgICAgICAgICAgaWYgKCh1bml0cyAtPSAzKSA+IC0xKQogICAgICAgICAgICAgICAgICBieXRlcy5wdXNoKDIzOSwgMTkxLCAxODkpOwogICAgICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICAgICAgfSBlbHNlIGlmIChpICsgMSA9PT0gbGVuZ3RoKSB7CiAgICAgICAgICAgICAgICBpZiAoKHVuaXRzIC09IDMpID4gLTEpCiAgICAgICAgICAgICAgICAgIGJ5dGVzLnB1c2goMjM5LCAxOTEsIDE4OSk7CiAgICAgICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgbGVhZFN1cnJvZ2F0ZSA9IGNvZGVQb2ludDsKICAgICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoY29kZVBvaW50IDwgNTYzMjApIHsKICAgICAgICAgICAgICBpZiAoKHVuaXRzIC09IDMpID4gLTEpCiAgICAgICAgICAgICAgICBieXRlcy5wdXNoKDIzOSwgMTkxLCAxODkpOwogICAgICAgICAgICAgIGxlYWRTdXJyb2dhdGUgPSBjb2RlUG9pbnQ7CiAgICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgY29kZVBvaW50ID0gKGxlYWRTdXJyb2dhdGUgLSA1NTI5NiA8PCAxMCB8IGNvZGVQb2ludCAtIDU2MzIwKSArIDY1NTM2OwogICAgICAgICAgfSBlbHNlIGlmIChsZWFkU3Vycm9nYXRlKSB7CiAgICAgICAgICAgIGlmICgodW5pdHMgLT0gMykgPiAtMSkKICAgICAgICAgICAgICBieXRlcy5wdXNoKDIzOSwgMTkxLCAxODkpOwogICAgICAgICAgfQogICAgICAgICAgbGVhZFN1cnJvZ2F0ZSA9IG51bGw7CiAgICAgICAgICBpZiAoY29kZVBvaW50IDwgMTI4KSB7CiAgICAgICAgICAgIGlmICgodW5pdHMgLT0gMSkgPCAwKQogICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICBieXRlcy5wdXNoKGNvZGVQb2ludCk7CiAgICAgICAgICB9IGVsc2UgaWYgKGNvZGVQb2ludCA8IDIwNDgpIHsKICAgICAgICAgICAgaWYgKCh1bml0cyAtPSAyKSA8IDApCiAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIGJ5dGVzLnB1c2goY29kZVBvaW50ID4+IDYgfCAxOTIsIGNvZGVQb2ludCAmIDYzIHwgMTI4KTsKICAgICAgICAgIH0gZWxzZSBpZiAoY29kZVBvaW50IDwgNjU1MzYpIHsKIC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1lc3NhZ2UubWVzc2FnZSksIHsKICAgICAgICAgICAgbmFtZTogbWVzc2FnZS5uYW1lLAogICAgICAgICAgICBzdGFjazogbWVzc2FnZS5zdGFjawogICAgICAgICAgfSk7CiAgICAgICAgfSwKICAgICAgICBzZXJpYWxpemUoZXJyb3IpIHsKICAgICAgICAgIHJldHVybiB7CiAgICAgICAgICAgIF9fZXJyb3JfbWFya2VyOiAiJCRlcnJvciIsCiAgICAgICAgICAgIG1lc3NhZ2U6IGVycm9yLm1lc3NhZ2UsCiAgICAgICAgICAgIG5hbWU6IGVycm9yLm5hbWUsCiAgICAgICAgICAgIHN0YWNrOiBlcnJvci5zdGFjawogICAgICAgICAgfTsKICAgICAgICB9CiAgICAgIH07CiAgICAgIHZhciBpc1NlcmlhbGl6ZWRFcnJvciA9ICh0aGluZykgPT4gdGhpbmcgJiYgdHlwZW9mIHRoaW5nID09PSAib2JqZWN0IiAmJiAiX19lcnJvcl9tYXJrZXIiIGluIHRoaW5nICYmIHRoaW5nLl9fZXJyb3JfbWFya2VyID09PSAiJCRlcnJvciI7CiAgICAgIGV4cG9ydHMuRGVmYXVsdFNlcmlhbGl6ZXIgPSB7CiAgICAgICAgZGVzZXJpYWxpemUobWVzc2FnZSkgewogICAgICAgICAgaWYgKGlzU2VyaWFsaXplZEVycm9yKG1lc3NhZ2UpKSB7CiAgICAgICAgICAgIHJldHVybiBEZWZhdWx0RXJyb3JTZXJpYWxpemVyLmRlc2VyaWFsaXplKG1lc3NhZ2UpOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcmV0dXJuIG1lc3NhZ2U7CiAgICAgICAgICB9CiAgICAgICAgfSwKICAgICAgICBzZXJpYWxpemUoaW5wdXQpIHsKICAgICAgICAgIGlmIChpbnB1dCBpbnN0YW5jZW9mIEVycm9yKSB7CiAgICAgICAgICAgIHJldHVybiBEZWZhdWx0RXJyb3JTZXJpYWxpemVyLnNlcmlhbGl6ZShpbnB1dCk7CiAgICAgICAgICB9IGVs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YW5jZW9mIFAgPyB2YWx1ZSA6IG5ldyBQKGZ1bmN0aW9uKHJlc29sdmUpIHsKICAgICAgICAgICAgcmVzb2x2ZSh2YWx1ZSk7CiAgICAgICAgICB9KTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIG5ldyAoUCB8fCAoUCA9IFByb21pc2UpKShmdW5jdGlvbihyZXNvbHZlLCByZWplY3QpIHsKICAgICAgICAgIGZ1bmN0aW9uIGZ1bGZpbGxlZCh2YWx1ZSkgewogICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgIHN0ZXAoZ2VuZXJhdG9yLm5leHQodmFsdWUpKTsKICAgICAgICAgICAgfSBjYXRjaCAoZSkgewogICAgICAgICAgICAgIHJlamVjdChlKTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgZnVuY3Rpb24gcmVqZWN0ZWQodmFsdWUpIHsKICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICBzdGVwKGdlbmVyYXRvclsidGhyb3ciXSh2YWx1ZSkpOwogICAgICAgICAgICB9IGNhdGNoIChlKSB7CiAgICAgICAgICAgICAgcmVqZWN0KGUpOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBmdW5jdGlvbiBzdGVwKHJlc3VsdCkgewogICAgICAgICAgICByZXN1bHQuZG9uZSA/IHJlc29sdmUocmVzdWx0LnZhbHVlKSA6IGFkb3B0KHJlc3VsdC52YWx1ZSkudGhlbihmdWxmaWxsZWQsIHJlamVjdGVkKTsKICAgICAgICAgIH0KICAgICAgICAgIHN0ZXAoKGdlbmVyYXRvciA9IGdlbmVyYXRvci5hcHBseSh0aGlzQXJnLCBfYXJndW1lbnRzIHx8IFtdKSkubmV4dCgpKTsKICAgICAgICB9KTsKICAgICAgfTsKICAgICAgdmFyIF9faW1wb3J0RGVmYXVsdCA9IGV4cG9ydHMgJiYgZXhwb3J0cy5fX2ltcG9ydERlZmF1bHQgfHwgZnVuY3Rpb24obW9kKSB7CiAgICAgICA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pIHsKICAgICAgICAgICAgY29uc3Qgam9iVUlEID0gbWVzc2FnZURhdGEudWlkOwogICAgICAgICAgICBjb25zdCBzdWJzY3JpcHRpb24gPSBhY3RpdmVTdWJzY3JpcHRpb25zLmdldChqb2JVSUQpOwogICAgICAgICAgICBpZiAoc3Vic2NyaXB0aW9uKSB7CiAgICAgICAgICAgICAgc3Vic2NyaXB0aW9uLnVuc3Vic2NyaWJlKCk7CiAgICAgICAgICAgICAgYWN0aXZlU3Vic2NyaXB0aW9ucy5kZWxldGUoam9iVUlEKTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0pOwogICAgICB9CiAgICAgIGV4cG9ydHMuZXhwb3NlID0gZXhwb3NlMjsKICAgICAgaWYgKHR5cGVvZiBzZWxmICE9PSAidW5kZWZpbmVkIiAmJiB0eXBlb2Ygc2VsZi5hZGRFdmVudExpc3RlbmVyID09PSAiZnVuY3Rpb24iICYmIGltcGxlbWVudGF0aW9uXzEuZGVmYXVsdC5pc1dvcmtlclJ1bnRpbWUoKSkgewogICAgICAgIHNlbGYuYWRkRXZlbnRMaXN0ZW5lcigiZXJyb3IiLCAoZXZlbnQpID0+IHsKICAgICAgICAgIHNldFRpbWVvdXQoKCkgPT4gcG9zdFVuY2F1Z2h0RXJyb3JNZXNzYWdlKGV2ZW50LmVycm9yIHx8IGV2ZW50KSwgMjUwKTsKICAgICAgICB9KTsKICAgICAgICBzZWxmLmFkZEV2ZW50TGlzdGVuZXIoInVuaGFuZGxlZHJlamVjdGlvbiIsIChldmVudCkgPT4gewogICAgICAgICAgY29uc3QgZXJyb3IgPSBldmVudC5yZWFzb247CiAgICAgICAgICBpZiAoZXJyb3IgJiYgdHlwZW9mIGVycm9yLm1lc3NhZ2UgPT09ICJzdHJpbmciKSB7CiAgICAgICAgICAgIHNldFRpbWVvdXQoKCkgPT4gcG9zdFVuY2F1Z2h0RXJyb3JNZXNzYWdlKGVycm9yKSwgMjUwKTsKICAgICAgICAgIH0KICAgICAgICB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sZShuZXcgVWludDhBcnJheShbCiAgICAgICAgICAwLAogICAgICAgICAgOTcsCiAgICAgICAgICAxMTUsCiAgICAgICAgICAxMDksCiAgICAgICAgICAxLAogICAgICAgICAgMCwKICAgICAgICAgIDAsCiAgICAgICAgICAwLAogICAgICAgICAgMSwKICAgICAgICAgIDEzLAogICAgICAgICAgMiwKICAgICAgICAgIDk2LAogICAgICAgICAgMCwKICAgICAgICAgIDEsCiAgICAgICAgICAxMjcsCiAgICAgICAgICA5NiwKICAgICAgICAgIDQsCiAgICAgICAgICAxMjcsCiAgICAgICAgICAxMjcsCiAgICAgICAgICAxMjcsCiAgICAgICAgICAxMjcsCiAgICAgICAgICAxLAogICAgICAgICAgMTI3LAogICAgICAgICAgMywKICAgICAgICAgIDcsCiAgICAgICAgICA2LAogICAgICAgICAgMCwKICAgICAgICAgIDEsCiAgICAgICAgICAxLAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICAxLAogICAgICAgICAgNiwKICAgICAgICAgIDYsCiAgICAgICAgICAxLAogICAgICAgICAgMTI3LAogICAgICAgICAgMSwKICAgICAgICAgIDY1LAogICAgICAgICAgMCwKICAgICAgICAgIDExLAogICAgICAgICAgNywKICAgICAgICAgIDUwLAogICAgICAgICAgNiwKICAgICAgICAgIDMsCiAgICAgICAgICAxMDksCiAgICAgICAgICAxMTcsCiAgICAgICAgICAxMDgsCiAgICAgICAgICAwLAogICAgICAgICAgMSwKICAgICAgICAgIDUsCiAgICAgICAgICAxMDAsCiAgICAgICAgICAxMDUsCiAgICAgICAgICAxMTgsCiAgICAgICAgICA5NSwKICAgICAgICAgIDExNSwKICAgICAgICAgIDAsCiAgICAgICAgICAyLAogICAgICAgICAgNSwKICAgICAgICAgIDEwMCwKICAgICAgICAgIDEwNSwKICAgICAgICAgIDExOCwKICAgICAgICAgIDk1LAogICAgICAgICAgMTE3LAogICAgICAgICAgMCwKICAgICAgICAgIDMsCiAgICAgICAgICA1LAogICAgICAgICAgMTE0LAogICAgICAgICAgMTAxLAogICAgICAgICAgMTA5LAogICAgICAgICAgOTUsCiAgICAgICAgICAxMTUsCiAgICAgICAgICAwLAogICAgICAgICAgNCwKICAgICAgICAgIDUsCiAgICAgICAgICAxMTQsCiAgICAgICAgICAxMDEsCiAgICAgICAgICAxMDksCiAgICAgICAgICA5NSwKICAgICAgICAgIDExNywKICAgICAgICAgIDAsCiAgICAgICAgICA1LAogICAgICAgICAgOCwKICAgICAgICAgIDEwMywKICAgICAgICAgIDEwMSwKICAgICAgICAgIDExNiwKICAgICAgICAgIDk1LAogICAgICAgICAgMTA0LAogICAgICAgICAgMTA1LAogICAgICAgICAgMTAzLAogICAgICAgICAgMTA0LAogICAgICAgICAgMCwKICAgICAgICAgIDAsCiAgICAgICAgICAxMCwKICAgICAgICAgIDE5MSwKICAgICAgICAgIDEsCiAgICAgICAgICA2LAogICAgICAgICAgNCwKICAgICAgICAgIDAsCiAgICAgICAgICAzNSwKICAgICAgICAgIDAsCiAgICAgICAgICAxMSwKICAgICAgICAgIDM2LAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICAxMjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDAsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMzIsCiAgICAgICAgICAyLAogICAgICAgICAgMTczLAogICAgICAgICAgMzIsCiAgICAgICAgICAzLAogICAgICAgICAgMTczLAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNCwKICAgICAgICAgIDEzMiwKICAgICAgICAgIDEyNiwKICAgICAgICAgIDM0LAogICAgICAgICAgNCwKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzUsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAzNiwKICAgICAgICAgIDAsCiAgICAgICAgICAzMiwKICAgICAgICAgIDQsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAxMSwKICAgICAgICAgIDM2LAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICAxMjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDAsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMzIsCiAgICAgICAgICAyLAogICAgICAgICAgMTczLAogICAgICAgICAgMzIsCiAgICAgICAgICAzLAogICAgICAgICAgMTczLAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNCwKICAgICAgICAgIDEzMiwKICAgICAgICAgIDEyNywKICAgICAgICAgIDM0LAogICAgICAgICAgNCwKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzUsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAzNiwKICAgICAgICAgIDAsCiAgICAgICAgICAzMiwKICAgICAgICAgIDQsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAxMSwKICAgICAgICAgIDM2LAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICAxMjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDAsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMzIsCiAgICAgICAgICAyLAogICAgICAgICAgMTczLAogICAgICAgICAgMzIsCiAgICAgICAgICAzLAogICAgICAgICAgMTczLAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNCwKICAgICAgICAgIDEzMiwKICAgICAgICAgIDEyOCwKICAgICAgICAgIDM0LAogICAgICAgICAgNCwKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzUsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAzNiwKICAgICAgICAgIDAsCiAgICAgICAgICAzMiwKICAgICAgICAgIDQsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAxMSwKICAgICAgICAgIDM2LAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICAxMjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDAsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMzIsCiAgICAgICAgICAyLAogICAgICAgICAgMTczLAogICAgICAgICAgMzIsCiAgICAgICAgICAzLAogICAgICAgICAgMTczLAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNCwKICAgICAgICAgIDEzMiwKICAgICAgICAgIDEyOSwKICAgICAgICAgIDM0LAogICAgICAgICAgNCwKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzUsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAzNiwKICAgICAgICAgIDAsCiAgICAgICAgICAzMiwKICAgICAgICAgIDQsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAxMSwKICAgICAgICAgIDM2LAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICAxMjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDAsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMzIsCiAgICAgICAgICAyLAogICAgICAgICAgMTczLAogICAgICAgICAgMzIsCiAgICAgICAgICAzLAogICAgICAgICAgMTczLAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNCwKICAgICAgICAgIDEzMiwKICAgICAgICAgIDEzMCwKICAgICAgICAgIDM0LAogICAgICAgICAgNCwKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzUsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAzNiwKICAgICAgICAgIDAsCiAgICAgICAgICAzMiwKICAgICAgICAgIDQsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAxMQogICAgICAgIF0pKSwge30pLmV4cG9ydHM7CiAgICAgIH0gY2F0Y2ggKGUpIHsKICAgICAgfQogICAgICBmdW5jdGlvbiBMb25nNChsb3csIGhpZ2gsIHVuc2lnbmVkKSB7CiAgICAgICAgdGhpcy5sb3cgPSBsb3cgfCAwOwogICAgICAgIHRoaXMuaGlnaCA9IGhpZ2ggfCAwOwogICAgICAgIHRoaXMudW5zaWduZWQgPSAhIXVuc2lnbmVkOwogICAgICB9CiAgICAgIExvbmc0LnByb3RvdHlwZS5fX2lzTG9uZ19fOwogICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkoTG9uZzQucHJvdG90eXBlLCAiX19pc0xvbmdfXyIsIHsgdmFsdWU6IHRydWUgfSk7CiAgICAgIGZ1bmN0aW9uIGlzTG9uZyhvYmopIHsKICAgICAgICByZXR1cm4gKG9iaiAmJiBvYmpbIl9faXNMb25nX18iXSkgPT09IHRydWU7CiAgICAgIH0KICAgICAgTG9uZzQuaXNMb25nID0gaXNMb25nOwogICAgICB2YXIgSU5UX0NBQ0hFID0ge307CiAgICAgIHZhciBVSU5UX0NBQ0hFID0ge307CiAgICAgIGZ1bmN0aW9uIGZyb21JbnQodmFsdWUsIHVuc2lnbmVkKSB7CiAgICAgICAgdmFyIG9iaiwgY2FjaGVkT2JqLCBjYWNoZTsKICAgICAgICBpZiAodW5zaWduZWQpIHsKICAgICAgICAgIHZhbHVlID4+Pj0gMDsKICAgICAgICAgIGlmIChjYWNoZSA9IDAgPD0gdmFsdWUgJiYgdmFsdWUgPCAyNTYpIHsKICAgICAgICAgICAgY2FjaGVkT2JqID0gVUlOVF9DQUNIRVt2YWx1ZV07CiAgICAgICAgICAgIGlmIChjYWNoZWRPYmopCiAgICAgICAgICAgICAgcmV0dXJuIGNhY2hlZE9iajsKICAgICAgICAgIH0KICAgICAgICAgIG9iaiA9IGZyb21CaXRzKHZhbHVlLCAodmFsdWUgfCAwKSA8IDAgPyAtMSA6IDAsIHRydWUpOwogICAgICAgICAgaWYgKGNhY2hlKQogICAgICAgICAgICBVSU5UX0NBQ0hFW3ZhbHVlXSA9IG9iajsKICAgICAgICAgIHJldHVybiBvYmo7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIHZhbHVlIHw9IDA7CiAgICAgICAgICBpZiAoY2FjaGUgPSAtMTI4IDw9IHZhbHVlICYmIHZhbHVlIDwgMTI4KSB7CiAgICAgICAgICAgIGNhY2hlZE9iaiA9IElOVF9DQUNIRVt2YWx1ZV07CiAgICAgICAgICAgIGlmIChjYWNoZWRPYmopCiAgICAgICAgICAgICAgcmV0dXJuIGNhY2hlZE9iajsKICAgICAgICAgIH0KICAgICAgICAgIG9iaiA9IGZyb21CaXRzKHZhbHVlLCB2YWx1ZSA8IDAgPyAtMSA6IDAsIGZhbHNlKTsKICAgICAgICAgIGlmIChjYWNoZSkKICAgICAgICAgICAgSU5UX0NBQ0hFW3ZhbHVlXSA9IG9iajsKICAgICAgICAgIHJldHVybiBvYmo7CiAgICAgICAgfQogICAgICB9CiAgICAgIExvbmc0LmZyb21JbnQgPSBmcm9tSW50OwogICAgICBmdW5jdGlvbiBmcm9tTnVtYmVyKHZhbHVlLCB1bnNpZ25lZCkgewogICAgICAgIGlmIChpc05hTih2YWx1ZSkpCiAgICAgICAgICByZXR1cm4gdW5zaWduZWQgPyBVWkVSTyA6IFpFUk87CiAgICAgICAgaWYgKHVuc2lnbmVkKSB7CiAgICAgICAgICBpZiAodmFsdWUgPCAwKQogICAgICAgICAgICByZXR1cm4gVVpFUk87CiAgICAgICAgICBpZiAodmFsdWUgPj0gVFdPX1BXUl82NF9EQkwpCiAgICAgICAgICAgIHJldHVybiBNQVhfVU5TSUdORURfVkFMVUU7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIGlmICh2YWx1ZSA8PSAtVFdPX1BXUl82M19EQkwpCiAgICAgICAgICAgIHJldHVybiBNSU5fVkFMVUU7CiAgICAgICAgICBpZiAodmFsdWUgKyAxID49IFRXT19QV1JfNjNfREJMKQogICAgICAgICAgICByZXR1cm4gTUFYX1ZBTFVFOwogICAgICAgIH0KICAgICAgICBpZiAodmFsdWUgPCAwKQogICAgICAgICAgcmV0dXJuIGZyb21OdW1iZXIoLXZhbHVlLCB1bnNpZ25lZCkubmVnKCk7CiAgICAgICAgcmV0dXJuIGZyb21CaXRzKHZhbHVlICUgVFdPX1BXUl8zMl9EQkwgfCAwLCB2YWx1ZSAvIFRXT19QV1JfMzJfREJMIHwgMCwgdW5zaWduZWQpOwogICAgICB9CiAgICAgIExvbmc0LmZyb21OdW1iZXIgPSBmcm9tTnVtYmVyOwogICAgICBmdW5jdGlvbiBmcm9tQml0cyhsb3dCaXRzLCBoaWdoQml0cywgdW5zaWduZWQpIHsKICAgICAgICByZXR1cm4gbmV3IExvbmc0KGxvd0JpdHMsIGhpZ2hCaXRzLCB1bnNpZ25lZCk7CiAgICAgIH0KICAgICAgTG9uZzQuZnJvbUJpdHMgPSBmcm9tQml0czsKICAgICAgdmFyIHBvd19kYmwgPSBNYXRoLnBvdzsKICAgICAgZnVuY3Rpb24gZnJvbVN0cmluZyhzdHIsIHVuc2lnbmVkLCByYWRpeCkgewogICAgICAgIGlmIChzdHIubGVuZ3RoID09PSAwKQogICAgICAgICAgdGhyb3cgRXJyb3IoImVtcHR5IHN0cmluZyIpOwogICAgICAgIGlmIChzdHIgPT09ICJOYU4iIHx8IHN0ciA9PT0gIkluZmluaXR5IiB8fCBzdHIgPT09ICIrSW5maW5pdHkiIHx8IHN0ciA9PT0gIi1JbmZpbml0eSIpCiAgICAgICAgICByZXR1cm4gWkVSTzsKICAgICAgICBpZiAodHlwZW9mIHVuc2lnbmVkID09PSAibnVtYmVyIikgewogICAgICAgICAgcmFkaXggPSB1bnNpZ25lZCwgdW5zaWduZWQgPSBmYWxzZTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgdW5zaWduZWQgPSAhIXVuc2lnbmVkOwogICAgICAgIH0KICAgICAgICByYWRpeCA9IHJhZGl4IHx8IDEwOwogICAgICAgIGlmIChyYWRpeCA8IDIgfHwgMzYgPCByYWRpeCkKICAgICAgICAgIHRocm93IFJhbmdlRXJyb3IoInJhZGl4Iik7CiAgICAgICAgdmFyIHA7CiAgICAgICAgaWYgKChwID0gc3RyLmluZGV4T2YoIi0iKSkgPiAwKQogICAgICAgICAgdGhyb3cgRXJyb3IoImludGVyaW9yIGh5cGhlbiIpOwogICAgICAgIGVsc2UgaWYgKHAgPT09IDApIHsKICAgICAgICAgIHJldHVybiBmcm9tU3RyaW5nKHN0ci5zdWJzdHJpbmcoMSksIHVuc2lnbmVkLCByYWRpeCkubmVnKCk7CiAgICAgICAgfQogICAgICAgIHZhciByYWRpeFRvUG93ZXIgPSBmcm9tTnVtYmVyKHBvd19kYmwocmFkaXgsIDgpKTsKICAgICAgICB2YXIgcmVzdWx0ID0gWkVSTzsKICAgICAgICBmb3IgKHZhciBpID0gMDsgaSA8IHN0ci5sZW5ndGg7IGkgKz0gOCkgewogICAgICAgICAgdmFyIHNpemUgPSBNYXRoLm1pbig4LCBzdHIubGVuZ3RoIC0gaSksIHZhbHVlID0gcGFyc2VJbnQoc3RyLnN1YnN0cmluZyhpLCBpICsgc2l6ZSksIHJhZGl4KTsKICAgICAgICAgIGlmIChzaXplIDwgOCkgewogICAgICAgICAgICB2YXIgcG93ZXIgPSBmcm9tTnVtYmVyKHBvd19kYmwocmFkaXgsIHNp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vSW50KCkgewogICAgICAgIHJldHVybiB0aGlzLnVuc2lnbmVkID8gdGhpcy5sb3cgPj4+IDAgOiB0aGlzLmxvdzsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS50b051bWJlciA9IGZ1bmN0aW9uIHRvTnVtYmVyKCkgewogICAgICAgIGlmICh0aGlzLnVuc2lnbmVkKQogICAgICAgICAgcmV0dXJuICh0aGlzLmhpZ2ggPj4+IDApICogVFdPX1BXUl8zMl9EQkwgKyAodGhpcy5sb3cgPj4+IDApOwogICAgICAgIHJldHVybiB0aGlzLmhpZ2ggKiBUV09fUFdSXzMyX0RCTCArICh0aGlzLmxvdyA+Pj4gMCk7CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUudG9TdHJpbmcgPSBmdW5jdGlvbiB0b1N0cmluZyhyYWRpeCkgewogICAgICAgIHJhZGl4ID0gcmFkaXggfHwgMTA7CiAgICAgICAgaWYgKHJhZGl4IDwgMiB8fCAzNiA8IHJhZGl4KQogICAgICAgICAgdGhyb3cgUmFuZ2VFcnJvcigicmFkaXgiKTsKICAgICAgICBpZiAodGhpcy5pc1plcm8oKSkKICAgICAgICAgIHJldHVybiAiMCI7CiAgICAgICAgaWYgKHRoaXMuaXNOZWdhdGl2ZSgpKSB7CiAgICAgICAgICBpZiAodGhpcy5lcShNSU5fVkFMVUUpKSB7CiAgICAgICAgICAgIHZhciByYWRpeExvbmcgPSBmcm9tTnVtYmVyKHJhZGl4KSwgZGl2ID0gdGhpcy5kaXYocmFkaXhMb25nKSwgcmVtMSA9IGRpdi5tdWwocmFkaXhMb25nKS5zdWIodGhpcyk7CiAgICAgICAgICAgIHJldHVybiBkaXYudG9TdHJpbmcocmFkaXgpICsgcmVtMS50b0ludCgpLnRvU3RyaW5nKHJhZGl4KTsKICAgICAgICAgIH0gZWxzZQogICAgICAgICAgICByZXR1cm4gIi0iICsgdGhpcy5uZWcoKS50b1N0cmluZyhyYWRpeCk7CiAgICAgICAgfQogICAgICAgIHZhciByYWRpeFRvUG93ZXIgPSBmcm9tTnVtYmVyKHBvd19kYmwocmFkaXgsIDYpLCB0aGlzLnVuc2lnbmVkKSwgcmVtID0gdGhpczsKICAgICAgICB2YXIgcmVzdWx0ID0gIiI7CiAgICAgICAgd2hpbGUgKHRydWUpIHsKICAgICAgICAgIHZhciByZW1EaXYgPSByZW0uZGl2KHJhZGl4VG9Qb3dlciksIGludHZhbCA9IHJlbS5zdWIocmVtRGl2Lm11bChyYWRpeFRvUG93ZXIpKS50b0ludCgpID4+PiAwLCBkaWdpdHMgPSBpbnR2YWwudG9TdHJpbmcocmFkaXgpOwogICAgICAgICAgcmVtID0gcmVtRGl2OwogICAgICAgICAgaWYgKHJlbS5pc1plcm8oKSkKICAgICAgICAgICAgcmV0dXJuIGRpZ2l0cyArIHJlc3VsdDsKICAgICAgICAgIGVsc2UgewogICAgICAgICAgICB3aGlsZSAoZGlnaXRzLmxlbmd0aCA8IDYpCiAgICAgICAgICAgICAgZGlnaXRzID0gIjAiICsgZGlnaXRzOwogICAgICAgICAgICByZXN1bHQgPSAiIiArIGRpZ2l0cyArIHJlc3VsdDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUuZ2V0SGlnaEJpdHMgPSBmdW5jdGlvbiBnZXRIaWdoQml0cygpIHsKICAgICAgICByZXR1cm4gdGhpcy5oaWdoOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLmdldEhpZ2hCaXRzVW5zaWduZWQgPSBmdW5jdGlvbiBnZXRIaWdoQml0c1Vuc2lnbmVkKCkgewogICAgICAgIHJldHVybiB0aGlzLmhpZ2ggPj4+IDA7CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUuZ2V0TG93Qml0cyA9IGZ1bmN0aW9uIGdldExvd0JpdHMoKSB7CiAgICAgICAgcmV0dXJuIHRoaXMubG93OwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLmdldExvd0JpdHNVbnNpZ25l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JldHVybiB0aGlzLmFkZChzdWJ0cmFoZW5kLm5lZygpKTsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS5zdWIgPSBMb25nUHJvdG90eXBlLnN1YnRyYWN0OwogICAgICBMb25nUHJvdG90eXBlLm11bHRpcGx5ID0gZnVuY3Rpb24gbXVsdGlwbHkobXVsdGlwbGllcikgewogICAgICAgIGlmICh0aGlzLmlzWmVybygpKQogICAgICAgICAgcmV0dXJuIFpFUk87CiAgICAgICAgaWYgKCFpc0xvbmcobXVsdGlwbGllcikpCiAgICAgICAgICBtdWx0aXBsaWVyID0gZnJvbVZhbHVlKG11bHRpcGxpZXIpOwogICAgICAgIGlmICh3YXNtKSB7CiAgICAgICAgICB2YXIgbG93ID0gd2FzbS5tdWwodGhpcy5sb3csIHRoaXMuaGlnaCwgbXVsdGlwbGllci5sb3csIG11bHRpcGxpZXIuaGlnaCk7CiAgICAgICAgICByZXR1cm4gZnJvbUJpdHMobG93LCB3YXNtLmdldF9oaWdoKCksIHRoaXMudW5zaWduZWQpOwogICAgICAgIH0KICAgICAgICBpZiAobXVsdGlwbGllci5pc1plcm8oKSkKICAgICAgICAgIHJldHVybiBaRVJPOwogICAgICAgIGlmICh0aGlzLmVxKE1JTl9WQUxVRSkpCiAgICAgICAgICByZXR1cm4gbXVsdGlwbGllci5pc09kZCgpID8gTUlOX1ZBTFVFIDogWkVSTzsKICAgICAgICBpZiAobXVsdGlwbGllci5lcShNSU5fVkFMVUUpKQogICAgICAgICAgcmV0dXJuIHRoaXMuaXNPZGQoKSA/IE1JTl9WQUxVRSA6IFpFUk87CiAgICAgICAgaWYgKHRoaXMuaXNOZWdhdGl2ZSgpKSB7CiAgICAgICAgICBpZiAobXVsdGlwbGllci5pc05lZ2F0aXZlKCkpCiAgICAgICAgICAgIHJldHVybiB0aGlzLm5lZygpLm11bChtdWx0aXBsaWVyLm5lZygpKTsKICAgICAgICAgIGVsc2UKICAgICAgICAgICAgcmV0dXJuIHRoaXMubmVn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sKICAgICAgICBjMTYgJj0gNjU1MzU7CiAgICAgICAgYzMyICs9IGEzMiAqIGIwMDsKICAgICAgICBjNDggKz0gYzMyID4+PiAxNjsKICAgICAgICBjMzIgJj0gNjU1MzU7CiAgICAgICAgYzMyICs9IGExNiAqIGIxNjsKICAgICAgICBjNDggKz0gYzMyID4+PiAxNjsKICAgICAgICBjMzIgJj0gNjU1MzU7CiAgICAgICAgYzMyICs9IGEwMCAqIGIzMjsKICAgICAgICBjNDggKz0gYzMyID4+PiAxNjsKICAgICAgICBjMzIgJj0gNjU1MzU7CiAgICAgICAgYzQ4ICs9IGE0OCAqIGIwMCArIGEzMiAqIGIxNiArIGExNiAqIGIzMiArIGEwMCAqIGI0ODsKICAgICAgICBjNDggJj0gNjU1MzU7CiAgICAgICAgcmV0dXJuIGZyb21CaXRzKGMxNiA8PCAxNiB8IGMwMCwgYzQ4IDw8IDE2IHwgYzMyLCB0aGlzLnVuc2lnbmVkKTsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS5tdWwgPSBMb25nUHJvdG90eXBlLm11bHRpcGx5OwogICAgICBMb25nUHJvdG90eXBlLmRpdmlkZSA9IGZ1bmN0aW9uIGRpdmlkZShkaXZpc29yKSB7CiAgICAgICAgaWYgKCFpc0xvbmcoZGl2aXNvcikpCiAgICAgICAgICBkaXZpc29yID0gZnJvbVZhbHVlKGRpdmlzb3IpOwogICAgICAgIGlmIChkaXZpc29yLmlzWmVybygpKQogICAgICAgICAgdGhyb3cgRXJyb3IoImRpdmlzaW9uIGJ5IHplcm8iKTsKICAgICAgICBpZiAod2FzbSkgewogICAgICAgICAgaWYgKCF0aGlzLnVuc2lnbmVkICYmIHRoaXMuaGlnaCA9PT0gLTIxNDc0ODM2NDggJiYgZGl2aXNvci5sb3cgPT09IC0xICYmIGRpdmlzb3IuaGlnaCA9PT0gLTEpIHsKICAgICAgICAgICAgcmV0dXJuIHRoaXM7CiAgICAgICAgICB9CiAgICAgICAgICB2YXIgbG93ID0gKHRoaXMudW5zaWduZWQgPyB3YXNtLmRpdl91IDogd2FzbS5kaXZfcykodGhpcy5sb3csIHRoaXMuaGlnaCwgZGl2aXNvci5sb3csIGRpdmlzb3IuaGlnaCk7CiAgICAgICAgICByZXR1cm4gZnJvbUJpdHMobG93LCB3YXNtLmdldF9oaWdoKCksIHRoaXMudW5zaWduZWQpOwogICAgICAgIH0KICAgICAgICBpZiAodGhpcy5pc1plcm8oKSkKICAgICAgICAgIHJldHVybiB0aGlzLnVuc2lnbmVkID8gVVpFUk8gOiBaRVJPOwogICAgICAgIHZhciBhcHByb3gsIHJlbSwgcmVzOwogICAgICAgIGlmICghdGhpcy51bnNpZ25lZCkgewogICAgICAgICAgaWYgKHRoaXMuZXEoTUlOX1ZBTFVFKSkgewogICAgICAgICAgICBpZiAoZGl2aXNvci5lcShPTkUpIHx8IGRpdmlzb3IuZXEoTkVHX09ORSkpCiAgICAgICAgICAgICAgcmV0dXJuIE1JTl9WQUxVRTsKICAgICAgICAgICAgZWxzZSBpZiAoZGl2aXNvci5lcShNSU5fVkFMVUUpKQogICAgICAgICAgICAgIHJldHVybiBPTkU7CiAgICAgICAgICAgIGVsc2UgewogICAgICAgICAgICAgIHZhciBoYWxmVGhpcyA9IHRoaXMuc2hyKDEpOwogICAgICAgICAgICAgIGFwcHJveCA9IGhhbGZUaGlzLmRpdihkaXZpc29yKS5zaGwoMSk7CiAgICAgICAgICAgICAgaWYgKGFwcHJveC5lcShaRVJPKSkgewogICAgICAgICAgICAgICAgcmV0dXJuIGRpdmlzb3IuaXNOZWdhdGl2ZSgpID8gT05FIDogTkVHX09ORTsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgcmVtID0gdGhpcy5zdWIoZGl2aXNvci5tdWwoYXBwcm94KSk7CiAgICAgICAgICAgICAgICByZXMgPSBhcHByb3guYWRkKHJlbS5kaXYoZGl2aXNvcikpOwogICAgICAgICAgICAgICAgcmV0dXJuIHJlczsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSBpZiAoZGl2aXNvci5lcShNSU5fVkFMVUUpKQogICAgICAgICAgICByZXR1cm4gdGhpcy51bnNpZ25lZCA/IFVaRVJPIDogWkVSTzsKICAgICAgICAgIGlmICh0aGlzLmlzTmVnYXRpdmUoKSkgewogICAgICAgICAgICBpZiAoZGl2aXNvci5pc05lZ2F0aXZlKCkpCiAgICAgICAgICAgICAgcmV0dXJuIHRoaXMubmVnKCkuZGl2KGRpdmlzb3IubmVnKCkpOwogICAgICAgICAgICByZXR1cm4gdGhpcy5uZWcoKS5kaXYoZGl2aXNvcikubmVnKCk7CiAgICAgICAgICB9IGVsc2UgaWYgKGRpdmlzb3IuaXNOZWdhdGl2ZSgpKQogICAgICAgICAgICByZXR1cm4gdGhpcy5kaXYoZGl2aXNvci5uZWcoKSkubmVnKCk7CiAgICAgICAgICByZXMgPSBaRVJPOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBpZiAoIWRpdmlzb3IudW5zaWduZWQpCiAgICAgICAgICAgIGRpdmlzb3IgPSBkaXZpc29yLnRvVW5zaWduZWQoKTsKICAgICAgICAgIGlmIChkaXZpc29yLmd0KHRoaXMpKQogICAgICAgICAgICByZXR1cm4gVVpFUk87CiAgICAgICAgICBpZiAoZGl2aXNvci5ndCh0aGlzLnNocnUoMSkpKQogICAgICAgICAgICByZXR1cm4gVU9ORTsKICAgICAgICAgIHJlcyA9IFVaRVJPOwogICAgICAgIH0KICAgICAgICByZW0gPSB0aGlzOwogICAgICAgIHdoaWxlIChyZW0uZ3RlKGRpdmlzb3IpKSB7CiAgICAgICAgICBhcHByb3ggPSBNYXRoLm1heCgxLCBNYXRoLmZsb29yKHJlbS50b051bWJlcigpIC8gZGl2aXNvci50b051bWJlcigpKSk7CiAgICAgICAgICB2YXIgbG9nMiA9IE1hdGguY2VpbChNYXRoLmxvZyhhcHByb3gpIC8gTWF0aC5MTjIpLCBkZWx0YSA9IGxvZzIgPD0gNDggPyAxIDogcG93X2RibCgyLCBsb2cyIC0gNDgpLCBhcHByb3hSZXMgPSBmcm9tTnVtYmVyKGFwcHJveCksIGFwcHJveFJlbSA9IGFwcHJveFJlcy5tdWwoZGl2aXNvcik7CiAgICAgICAgICB3aGlsZSAoYXBwcm94UmVtLmlzTmVnYXRpdmUoKSB8fCBhcHByb3hSZW0uZ3QocmVtKSkgewogICAgICAgICAgICBhcHByb3ggLT0gZGVsdGE7CiAgICAgICAgICAgIGFwcHJveFJlcyA9IGZyb21OdW1iZXIoYXBwcm94LCB0aGlzLnVuc2lnbmVkKTsKICAgICAgICAgICAgYXBwcm94UmVtID0gYXBwcm94UmVzLm11bChkaXZpc29yKTsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChhcHByb3hSZXMuaXNaZXJvKCkpCiAgICAgICAgICAgIGFwcHJveFJlcyA9IE9ORTsKICAgICAgICAgIHJlcyA9IHJlcy5hZGQoYXBwcm94UmVzKTsKICAgICAgICAgIHJlbSA9IHJlbS5zdWIoYXBwcm94UmVtKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHJlczsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS5kaXYgPSBMb25nUHJvdG90eXBlLmRpdmlkZTsKICAgICAgTG9uZ1Byb3RvdHlwZS5tb2R1bG8gPSBmdW5jdGlvbiBtb2R1bG8oZGl2aXNvcikgewogICAgICAgIGlmICghaXNMb25nKGRpdmlzb3IpKQogICAgICAgICAgZGl2aXNvciA9IGZyb21WYWx1ZShkaXZpc29yKTsKICAgICAgICBpZiAod2FzbSkgewogICAgICAgICAgdmFyIGxvdyA9ICh0aGlzLnVuc2lnbmVkID8gd2FzbS5yZW1fdSA6IHdhc20ucmVtX3MpKHRoaXMubG93LCB0aGlzLmhpZ2gsIGRpdmlzb3IubG93LCBkaXZpc29yLmhpZ2gpOwogICAgICAgICAgcmV0dXJuIGZyb21CaXRzKGxvdywgd2FzbS5nZXRfaGlnaCgpLCB0aGlzLnVuc2lnbmVkKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHRoaXMuc3ViKHRoaXMuZGl2KGRpdmlzb3IpLm11bChkaXZpc29yKSk7CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUubW9kID0gTG9uZ1Byb3RvdHlwZS5tb2R1bG87CiAgICAgIExvbmdQcm90b3R5cGUucmVtID0gTG9uZ1Byb3RvdHlwZS5tb2R1bG87CiAgICAgIExvbmdQcm90b3R5cGUubm90ID0gZnVuY3Rpb24gbm90KCkgewogICAgICAgIHJldHVybiBmcm9tQml0cyh+dGhpcy5sb3csIH50aGlzLmhpZ2gsIHRoaXMudW5zaWduZWQpOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLmFuZCA9IGZ1bmN0aW9uIGFuZChvdGhlcikgewogICAgICAgIGlmICghaXNMb25nKG90aGVyKSkKICAgICAgICAgIG90aGVyID0gZnJvbVZhbHVlKG90aGVyKTsKICAgICAgICByZXR1cm4gZnJvbUJpdHModGhpcy5sb3cgJiBvdGhlci5sb3csIHRoaXMuaGlnaCAmIG90aGVyLmhpZ2gsIHRoaXMudW5zaWduZWQpOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLm9yID0gZnVuY3Rpb24gb3Iob3RoZXIpIHsKICAgICAgICBpZiAoIWlzTG9uZyhvdGhlcikpCiAgICAgICAgICBvdGhlciA9IGZyb21WYWx1ZShvdGhlcik7CiAgICAgICAgcmV0dXJuIGZyb21CaXRzKHRoaXMubG93IHwgb3RoZXIubG93LCB0aGlzLmhpZ2ggfCBvdGhlci5oaWdoLCB0aGlzLnVuc2lnbmVkKTsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS54b3IgPSBmdW5jdGlvbiB4b3Iob3RoZXIpIHsKICAgICAgICBpZiAoIWlzTG9uZyhvdGhlcikpCiAgICAgICAgICBvdGhlciA9IGZyb21WYWx1ZShvdGhlcik7CiAgICAgICAgcmV0dXJuIGZyb21CaXRzKHRoaXMubG93IF4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udW1CaXRzLCB0aGlzLnVuc2lnbmVkKTsKICAgICAgICBlbHNlCiAgICAgICAgICByZXR1cm4gZnJvbUJpdHModGhpcy5oaWdoID4+IG51bUJpdHMgLSAzMiwgdGhpcy5oaWdoID49IDAgPyAwIDogLTEsIHRoaXMudW5zaWduZWQpOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLnNociA9IExvbmdQcm90b3R5cGUuc2hpZnRSaWdodDsKICAgICAgTG9uZ1Byb3RvdHlwZS5zaGlmdFJpZ2h0VW5zaWduZWQgPSBmdW5jdGlvbiBzaGlmdFJpZ2h0VW5zaWduZWQobnVtQml0cykgewogICAgICAgIGlmIChpc0xvbmcobnVtQml0cykpCiAgICAgICAgICBudW1CaXRzID0gbnVtQml0cy50b0ludCgpOwogICAgICAgIG51bUJpdHMgJj0gNjM7CiAgICAgICAgaWYgKG51bUJpdHMgPT09IDApCiAgICAgICAgICByZXR1cm4gdGhpczsKICAgICAgICBlbHNlIHsKICAgICAgICAgIHZhciBoaWdoID0gdGhpcy5oaWdoOwogICAgICAgICAgaWYgKG51bUJpdHMgPCAzMikgewogICAgICAgICAgICB2YXIgbG93ID0gdGhpcy5sb3c7CiAgICAgICAgICAgIHJldHVybiBmcm9tQml0cyhsb3cgPj4+IG51bUJpdHMgfCBoaWdoIDw8IDMyIC0gbnVtQml0cywgaGlnaCA+Pj4gbnVtQml0cywgdGhpcy51bnNpZ25lZCk7CiAgICAgICAgICB9IGVsc2UgaWYgKG51bUJpdHMgPT09IDMyKQogICAgICAgICAgICByZXR1cm4gZnJvbUJpdHMoaGlnaCwgMCwgdGhpcy51bnNpZ25lZCk7CiAgICAgICAgICBlbHNlCiAgICAgICAgICAgIHJldHVybiBmcm9tQml0cyhoaWdoID4+PiBudW1CaXRzIC0gMzIsIDAsIHRoaXMudW5zaWduZWQpOwogICAgICAgIH0KICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS5zaHJ1ID0gTG9uZ1Byb3RvdHlwZS5zaGlm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aW5lZCI7CiAgICAgIGZ1bmN0aW9uIF9oYXMob2JqLCBrZXkpIHsKICAgICAgICByZXR1cm4gT2JqZWN0LnByb3RvdHlwZS5oYXNPd25Qcm9wZXJ0eS5jYWxsKG9iaiwga2V5KTsKICAgICAgfQogICAgICBleHBvcnRzLmFzc2lnbiA9IGZ1bmN0aW9uKG9iaikgewogICAgICAgIHZhciBzb3VyY2VzID0gQXJyYXkucHJvdG90eXBlLnNsaWNlLmNhbGwoYXJndW1lbnRzLCAxKTsKICAgICAgICB3aGlsZSAoc291cmNlcy5sZW5ndGgpIHsKICAgICAgICAgIHZhciBzb3VyY2UgPSBzb3VyY2VzLnNoaWZ0KCk7CiAgICAgICAgICBpZiAoIXNvdXJjZSkgewogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgIH0KICAgICAgICAgIGlmICh0eXBlb2Ygc291cmNlICE9PSAib2JqZWN0IikgewogICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKHNvdXJjZSArICJtdXN0IGJlIG5vbi1vYmplY3QiKTsKICAgICAgICAgIH0KICAgICAgICAgIGZvciAodmFyIHAgaW4gc291cmNlKSB7CiAgICAgICAgICAgIGlmIChfaGFzKHNvdXJjZSwgcCkpIHsKICAgICAgICAgICAgICBvYmpbcF0gPSBzb3VyY2VbcF07CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIG9iajsKICAgICAgfTsKICAgICAgZXhwb3J0cy5zaHJpbmtCdWYgPSBmdW5jdGlvbihidWYsIHNpemUpIHsKICAgICAgICBpZiAoYnVmLmxlbmd0aCA9PT0gc2l6ZSkgewogICAgICAgICAgcmV0dXJuIGJ1ZjsKICAgICAgICB9CiAgICAgICAgaWYgKGJ1Zi5zdWJhcnJheSkgewogICAgICAgICAgcmV0dXJuIGJ1Zi5zdWJhcnJheSgwLCBzaXplKTsKICAgICAgICB9CiAgICAgICAgYnVmLmxlbmd0aCA9IHNpemU7CiAgICAgICAgcmV0dXJuIGJ1ZjsKICAgICAgfTsKICAgICAgdmFyIGZuVHlwZWQgPSB7CiAgICAgICAgYXJyYXlTZXQ6IGZ1bmN0aW9uKGRlc3QsIHNyYywgc3JjX29mZnMsIGxlbiwgZGVzdF9vZmZzKSB7CiAgICAgICAgICBpZiAoc3JjLnN1YmFycmF5ICYmIGRlc3Quc3ViYXJyYXkpIHsKICAgICAgICAgICAgZGVzdC5zZXQoc3JjLnN1YmFycmF5KHNyY19vZmZzLCBzcmNfb2ZmcyArIGxlbiksIGRlc3Rfb2Zmcyk7CiAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgIH0KICAgICAgICAgIGZvciAodmFyIGkgPSAwOyBpIDwgbGVuOyBpKyspIHsKICAgICAgICAgICAgZGVzdFtkZXN0X29mZnMgKyBpXSA9IHNyY1tzcmNfb2ZmcyArIGldOwogICAgICAgICAgfQogICAgICAgIH0sCiAgICAgICAgZmxhdHRlbkNodW5rczogZnVuY3Rpb24oY2h1bmtzKSB7CiAgICAgICAgICB2YXIgaSwgbCwgbGVuLCBwb3MsIGNodW5rLCByZXN1bHQ7CiAgICAgICAgICBsZW4gPSAwOwogICAgICAgICAgZm9yIChpID0gMCwgbCA9IGNodW5rcy5sZW5ndGg7IGkgPCBsOyBpKyspIHsKICAgICAgICAgICAgbGVuICs9IGNodW5rc1tpXS5sZW5ndGg7CiAgICAgICAgICB9CiAgICAgICAgICByZXN1bHQgPSBuZXcgVWludDhBcnJheShsZW4pOwogICAgICAgICAgcG9zID0gMDsKICAgICAgICAgIGZvciAoaSA9IDAsIGwgPSBjaHVua3MubGVuZ3RoOyBpIDwgbDsgaSsrKSB7CiAgICAgICAgICAgIGNodW5rID0gY2h1bmtzW2ldOwogICAgICAgICAgICByZXN1bHQuc2V0KGNodW5rLCBwb3MpOwogICAgICAgICAgICBwb3MgKz0gY2h1bmsubGVuZ3RoOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIHJlc3VsdDsKICAgICAgICB9CiAgICAgIH07CiAgICAgIHZhciBmblVudHlwZWQgPSB7CiAgICAgICAgYXJyYXlTZXQ6IGZ1bmN0aW9uKGRlc3QsIHNyYywgc3JjX29mZnMsIGxlbiwgZGVzdF9vZmZzKSB7CiAgICAgICAgICBmb3IgKHZhciBpID0gMDsgaSA8IGxlbjsgaSsrKSB7CiAgICAgICAgICAgIGRlc3RbZGVzdF9vZmZzICsgaV0gPSBzcmNbc3JjX29mZnMgKyBpXTsKICAgICAgICAgIH0KICAgICAgICB9LAogICAgICAgIGZsYXR0ZW5DaHVua3M6IGZ1bmN0aW9uKGNodW5rcykgewogICAgICAgICAgcmV0dXJuIFtdLmNvbmNhdC5hcHBseShbXSwgY2h1bmtzKTsKICAgICAgICB9CiAgICAgIH07CiAgICAgIGV4cG9ydHMuc2V0VHlwZWQgPSBmdW5jdGlvbihvbikgewogICAgICAgIGlmIChvbikgewogICAgICAgICAgZXhwb3J0cy5CdWY4ID0gVWludDhBcnJheTsKICAgICAgICAgIGV4cG9ydHMuQnVmMTYgPSBVaW50MTZBcnJheTsKICAgICAgICAgIGV4cG9ydHMuQnVmMzIgPSBJbnQzMkFycmF5OwogICAgICAgICAgZXhwb3J0cy5hc3NpZ24oZXhwb3J0cywgZm5UeXBlZCk7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIGV4cG9ydHMuQnVmOCA9IEFycmF5OwogICAgICAgICAgZXhwb3J0cy5CdWYxNiA9IEFycmF5OwogICAgICAgICAgZXhwb3J0cy5CdWYzMiA9IEFycmF5OwogICAgICAgICAgZXhwb3J0cy5hc3NpZ24oZXhwb3J0cywgZm5VbnR5cGVkKTsKICAgICAgICB9CiAgICAgIH07CiAgICAgIGV4cG9ydHMuc2V0VHlwZWQoVFlQRURfT0spOwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvdHJlZXMuanMKICB2YXIgcmVxdWlyZV90cm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ogICAgICBmdW5jdGlvbiBiaV9mbHVzaChzKSB7CiAgICAgICAgaWYgKHMuYmlfdmFsaWQgPT09IDE2KSB7CiAgICAgICAgICBwdXRfc2hvcnQocywgcy5iaV9idWYpOwogICAgICAgICAgcy5iaV9idWYgPSAwOwogICAgICAgICAgcy5iaV92YWxpZCA9IDA7CiAgICAgICAgfSBlbHNlIGlmIChzLmJpX3ZhbGlkID49IDgpIHsKICAgICAgICAgIHMucGVuZGluZ19idWZbcy5wZW5kaW5nKytdID0gcy5iaV9idWYgJiAyNTU7CiAgICAgICAgICBzLmJpX2J1ZiA+Pj0gODsKICAgICAgICAgIHMuYmlfdmFsaWQgLT0gODsKICAgICAgICB9CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZ2VuX2JpdGxlbihzLCBkZXNjKSB7CiAgICAgICAgdmFyIHRyZWUgPSBkZXNjLmR5bl90cmVlOwogICAgICAgIHZhciBtYXhfY29kZSA9IGRlc2MubWF4X2NvZGU7CiAgICAgICAgdmFyIHN0cmVlID0gZGVzYy5zdGF0X2Rlc2Muc3RhdGljX3RyZWU7CiAgICAgICAgdmFyIGhhc19zdHJlZSA9IGRlc2Muc3RhdF9kZXNjLmhhc19zdHJlZTsKICAgICAgICB2YXIgZXh0cmEgPSBkZXNjLnN0YXRfZGVzYy5leHRyYV9iaXRzOwogICAgICAgIHZhciBiYXNlID0gZGVzYy5zdGF0X2Rlc2MuZXh0cmFfYmFzZTsKICAgICAgICB2YXIgbWF4X2xlbmd0aCA9IGRlc2Muc3RhdF9kZXNjLm1heF9sZW5ndGg7CiAgICAgICAgdmFyIGg7CiAgICAgICAgdmFyIG4sIG07CiAgICAgICAgdmFyIGJpdHM7CiAgICAgICAgdmFyIHhiaXRzOwogICAgICAgIHZhciBmOwogICAgICAgIHZhciBvdmVyZmxvdyA9IDA7CiAgICAgICAgZm9yIChiaXRzID0gMDsgYml0cyA8PSBNQVhfQklUUzsgYml0cysrKSB7CiAgICAgICAgICBzLmJsX2NvdW50W2JpdHNdID0gMDsKICAgICAgICB9CiAgICAgICAgdHJlZVtzLmhlYXBbcy5oZWFwX21heF0gKiAyICsgMV0gPSAwOwogICAgICAgIGZvciAoaCA9IHMuaGVhcF9tYXggKyAxOyBoIDwgSEVBUF9TSVpFOyBoKyspIHsKICAgICAgICAgIG4gPSBzLmhlYXBbaF07CiAgICAgICAgICBiaXRzID0gdHJlZVt0cmVlW24gKiAyICsgMV0gKiAyICsgMV0gKyAxOwogICAgICAgICAgaWYgKGJpdHMgPiBtYXhfbGVuZ3RoKSB7CiAgICAgICAgICAgIGJpdHMgPSBtYXhfbGVuZ3RoOwogICAgICAgICAgICBvdmVyZmxvdysrOwogICAgICAgICAgfQogICAgICAgICAgdHJlZVtuICogMiArIDFdID0gYml0czsKICAgICAgICAgIGlmIChuID4gbWF4X2NvZGUpIHsKICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICB9CiAgICAgICAgICBzLmJsX2NvdW50W2JpdHNdKys7CiAgICAgICAgICB4Yml0cyA9IDA7CiAgICAgICAgICBpZiAobiA+PSBiYXNlKSB7CiAgICAgICAgICAgIHhiaXRzID0gZXh0cmFbbiAtIGJhc2VdOwogICAgICAgICAgfQogICAgICAgICAgZiA9IHRyZWVbbiAqIDJdOwogICAgICAgICAgcy5vcHRfbGVuICs9IGYgKiAoYml0cyArIHhiaXRzKTsKICAgICAgICAgIGlmIChoYXNfc3RyZWUpIHsKICAgICAgICAgICAgcy5zdGF0aWNfbGVuICs9IGYgKiAoc3RyZWVbbiAqIDIgKyAxXSArIHhiaXRzKTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKG92ZXJmbG93ID09PSAwKSB7CiAgICAgICAgICByZXR1cm47CiAgICAgICAgfQogICAgICAgIGRvIHsKICAgICAgICAgIGJpdHMgPSBtYXhfbGVuZ3RoIC0gMTsKICAgICAgICAgIHdoaWxlIChzLmJsX2NvdW50W2JpdHNdID09PSAwKSB7CiAgICAgICAgICAgIGJpdHMtLTsKICAgICAgICAgIH0KICAgICAgICAgIHMuYmxfY291bnRbYml0c10tLTsKICAgICAgICAgIHMuYmxfY291bnRbYml0cyArIDFdICs9IDI7CiAgICAgICAgICBzLmJsX2NvdW50W21heF9sZW5ndGhdLS07CiAgICAgICAgICBvdmVyZmxvdyAtPSAyOwogICAgICAgIH0gd2hpbGUgKG92ZXJmbG93ID4gMCk7CiAgICAgICAgZm9yIChiaXRzID0gbWF4X2xlbmd0aDsgYml0cyAhPT0gMDsgYml0cy0tKSB7CiAgICAgICAgICBuID0gcy5ibF9jb3VudFtiaXRzXTsKICAgICAgICAgIHdoaWxlIChuICE9PSAwKSB7CiAgICAgICAgICAgIG0gPSBzLmhlYXBbLS1oXTsKICAgICAgICAgICAgaWYgKG0gPiBtYXhfY29kZSkgewogICAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmICh0cmVlW20gKiAyICsgMV0gIT09IGJpdHMpIHsKICAgICAgICAgICAgICBzLm9wdF9sZW4gKz0gKGJpdHMgLSB0cmVlW20gKiAyICsgMV0pICogdHJlZVttICogMl07CiAgICAgICAgICAgICAgdHJlZVttICogMiArIDFdID0gYml0czsKICAgICAgICAgICAgfQogICAgICAgICAgICBuLS07CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9CiAgICAgIGZ1bmN0aW9uIGdlbl9jb2Rlcyh0cmVlLCBtYXhfY29kZSwgYmxfY291bnQpIHsKICAgICAgICB2YXIgbmV4dF9jb2RlID0gbmV3IEFycmF5KE1BWF9CSVRTICsgMSk7CiAgICAgICAgdmFyIGNvZGUgPSAwOwogICAgICAgIHZhciBiaXRzOwogICAgICAgIHZhciBuOwogICAgICAgIGZvciAoYml0cyA9IDE7IGJpdHMgPD0gTUFYX0JJVFM7IGJpdHMrKykgewogICAgICAgICAgbmV4dF9jb2RlW2JpdHNdID0gY29kZSA9IGNvZGUgKyBibF9jb3VudFtiaXRzIC0gMV0gPDwgMTsKICAgICAgICB9CiAgICAgICAgZm9yIChuID0gMDsgbiA8PSBtYXhfY29kZTsgbisrKSB7CiAgICAgICAgICB2YXIgbGVuID0gdHJlZVtuICogMiArIDFdOwogICAgICAgICAgaWYgKGxlbiA9PT0gMCkgewogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgIH0KICAgICAgICAgIHRyZWVbbiAqIDJdID0gYmlfcmV2ZXJzZShuZXh0X2NvZGVbbGVuXSsrLCBsZW4pOwogICAgICAgIH0KICAgICAgfQogICAgICBmdW5jdGlvbiB0cl9zdGF0aWNfaW5pdCgpIHsKICAgICAgICB2YXIgbjsKICAgICAgICB2YXIgYml0czsKICAgICAgICB2YXIgbGVuZ3RoOwogICAgICAgIHZhciBjb2RlOwogICAgICAgIHZhciBkaXN0OwogICAgICAgIHZhciBibF9jb3VudCA9IG5ldyBBcnJheShNQVhfQklUUyArIDEpOwogICAgICAgIGxlbmd0aCA9IDA7CiAgICAgICAgZm9yIChjb2RlID0gMDsgY29kZSA8IExFTkdUSF9DT0RFUyAtIDE7IGNvZGUrKykgewogICAgICAgICAgYmFzZV9sZW5ndGhbY29kZV0gPSBsZW5ndGg7CiAgICAgICAgICBmb3IgKG4gPSAwOyBuIDwgMSA8PCBleHRyYV9sYml0c1tjb2RlXTsgbisrKSB7CiAgICAgICAgICAgIF9sZW5ndGhfY29kZVtsZW5ndGgrK10gPSBjb2RlOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBfbGVuZ3RoX2NvZGVbbGVuZ3RoIC0gMV0gPSBjb2RlOwogICAgICAgIGRpc3QgPSAwOwogICAgICAgIGZvciAoY29kZSA9IDA7IGNvZGUgPCAxNjsgY29kZSsrKSB7CiAgICAgICAgICBiYXNlX2Rpc3RbY29kZV0gPSBkaXN0OwogICAgICAgICAgZm9yIChuID0gMDsgbiA8IDEgPDwgZXh0cmFfZGJpdHNbY29kZV07IG4rKykgewogICAgICAgICAgICBfZGlzdF9jb2RlW2Rpc3QrK10gPSBjb2RlOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBkaXN0ID4+PSA3OwogICAgICAgIGZvciAoOyBjb2RlIDwgRF9DT0RFUzsgY29kZSsrKSB7CiAgICAgICAgICBiYXNlX2Rpc3RbY29kZV0gPSBkaXN0IDw8IDc7CiAgICAgICAgICBmb3IgKG4gPSAwOyBuIDwgMSA8PCBleHRyYV9kYml0c1tjb2RlXSAtIDc7IG4rKykgewogICAgICAgICAgICBfZGlzdF9jb2RlWzI1NiArIGRpc3QrK10gPSBjb2RlOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBmb3IgKGJpdHMgPSAwOyBiaXRzIDw9IE1BWF9CSVRTOyBiaXRzKyspIHsKICAgICAgICAgIGJsX2NvdW50W2JpdHNdID0gMDsKICAgICAgICB9CiAgICAgICAgbiA9IDA7CiAgICAgICAgd2hpbGUgKG4gPD0gMTQzKSB7CiAgICAgICAgICBzdGF0aWNfbHRyZWVbbiAqIDIgKyAxXSA9IDg7CiAgICAgICAgICBuKys7CiAgICAgICAgICBibF9jb3VudFs4XSsrOwogICAgICAgIH0KICAgICAgICB3aGlsZSAobiA8PSAyNTUpIHsKICAgICAgICAgIHN0YXRpY19sdHJlZVtuICogMiArIDFdID0gOTsKICAgICAgICAgIG4rKzsKICAgICAgICAgIGJsX2NvdW50WzldKys7CiAgICAgICAgfQogICAgICAgIHdoaWxlIChuIDw9IDI3OSkgewogICAgICAgICAgc3RhdGljX2x0cmVlW24gKiAyICsgMV0gPSA3OwogICAgICAgICAgbisrOwogICAgICAgICAgYmxfY291bnRbN10rKzsKICAgICAgICB9CiAgICAgICAgd2hpbGUgKG4gPD0gMjg3KSB7CiAgICAgICAgICBzdGF0aWNfbHRyZWVbbiAqIDIgKyAxXSA9IDg7CiAgICAgICAgICBuKys7CiAgICAgICAgICBibF9jb3VudFs4XSsrOwogICAgICAgIH0KICAgICAgICBnZW5fY29kZXMoc3RhdGljX2x0cmVlLCBMX0NPREVTICsgMSwgYmxfY291bnQpOwogICAgICAgIGZvciAobiA9IDA7IG4gPCBEX0NPREVTOyBuKyspIHsKICAgICAgICAgIHN0YXRpY19kdHJlZVtuICogMiArIDFdID0gNTsKICAgICAgICAgIHN0YXRpY19kdHJlZVtuICogMl0gPSBiaV9yZXZlcnNlKG4sIDUpOwogICAgICAgIH0KICAgICAgICBzdGF0aWNfbF9kZXNjID0gbmV3IFN0YXRpY1RyZWVEZXNjKHN0YXRpY19sdHJlZSwgZXh0cmFfbGJpdHMsIExJVEVSQUxTICsgMSwgTF9DT0RFUywgTUFYX0JJVFMpOwogICAgICAgIHN0YXRpY19kX2Rlc2MgPSBuZXcgU3RhdGljVHJlZURlc2Moc3RhdGljX2R0cmVlLCBleHRyYV9kYml0cywgMCwgRF9DT0RFUywgTUFYX0JJVFMpOwogICAgICAgIHN0YXRpY19ibF9kZXNjID0gbmV3IFN0YXRpY1RyZWVEZXNjKG5ldyBBcnJheSgwKSwgZXh0cmFfYmxiaXRzLCAwLCBCTF9DT0RFUywgTUFYX0JMX0JJVFMpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGluaXRfYmxvY2socykgewogICAgICAgIHZhciBuOwogICAgICAgIGZvciAobiA9IDA7IG4gPCBMX0NPREVTOyBuKyspIHsKICAgICAgICAgIHMuZHluX2x0cmVlW24gKiAyXSA9IDA7CiAgICAgICAgfQogICAgICAgIGZvciAobiA9IDA7IG4gPCBEX0NPREVTOyBuKyspIHsKICAgICAgICAgIHMuZHluX2R0cmVlW24gKiAyXSA9IDA7CiAgICAgICAgfQogICAgICAgIGZvciAobiA9IDA7IG4gPCBCTF9DT0RFUzsgbisrKSB7CiAgICAgICAgICBzLmJsX3RyZWVbbiAqIDJdID0gMDsKICAgICAgICB9CiAgICAgICAgcy5keW5fbHRyZWVbRU5EX0JMT0NLICogMl0gPSAxOwogICAgICAgIHMub3B0X2xlbiA9IHMuc3RhdGljX2xlbiA9IDA7CiAgICAgICAgcy5sYXN0X2xpdCA9IHMubWF0Y2hlcyA9IDA7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gYmlfd2luZHVwKHMpIHsKICAgICAgICBpZiAocy5iaV92YWxpZCA+IDgpIHsKICAgICAgICAgIHB1dF9zaG9ydChzLCBzLmJpX2J1Zik7CiAgICAgICAgfSBlbHNlIGlmIChzLmJpX3ZhbGlkID4gMCkgewogICAgICAgICAgcy5wZW5kaW5nX2J1ZltzLnBlbmRpbmcrK10gPSBzLmJpX2J1ZjsKICAgICAgICB9CiAgICAgICAgcy5iaV9idWYgPSAwOwogICAgICAgIHMuYmlfdmFsaWQgPSAwOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGNvcHlfYmxvY2socywgYnVmLCBsZW4sIGhlYWRlcikgewogICAgICAgIGJpX3dpbmR1cChzKTsKICAgICAgICBpZiAoaGVhZGVyKSB7CiAgICAgICAgICBwdXRfc2hvcnQocywgbGVuKTsKICAgICAgICAgIHB1dF9zaG9ydChzLCB+bGVuKTsKICAgICAgICB9CiAgICAgICAgdXRpbHMuYXJyYXlTZXQocy5wZW5kaW5nX2J1Ziwgcy53aW5kb3csIGJ1ZiwgbGVuLCBzLnBlbmRpbmcpOwogICAgICAgIHMucGVuZGluZyArPSBsZW47CiAgICAgIH0KICAgICAgZnVuY3Rpb24gc21hbGxlcih0cmVlLCBuLCBtLCBkZXB0aCkgewogICAgICAgIHZhciBfbjIgPSBuICogMjsKICAgICAgICB2YXIgX20yID0gbSAqIDI7CiAgICAgICAgcmV0dXJuIHRyZWVbX24yXSA8IHRyZWVbX20yXSB8fCB0cmVlW19uMl0gPT09IHRyZWVbX20yXSAmJiBkZXB0aFtuXSA8PSBkZXB0aFttXTsKICAgICAgfQogICAgICBmdW5jdGlvbiBwcWRvd25oZWFwKHMsIHRyZWUsIGspIHsKICAgICAgICB2YXIgdiA9IHMuaGVhcFtrXTsKICAgICAgICB2YXIgaiA9IGsgPDwgMTsKICAgICAgICB3aGlsZSAoaiA8PSBzLmhlYXBfbGVuKSB7CiAgICAgICAgICBpZiAoaiA8IHMuaGVhcF9sZW4gJiYgc21hbGxlcih0cmVlLCBzLmhlYXBbaiArIDFdLCBzLmhlYXBbal0sIHMuZGVwdGgpKSB7CiAgICAgICAgICAgIGorKzsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChzbWFsbGVyKHRyZWUsIHYsIHMuaGVhcFtqXSwgcy5kZXB0aCkpIHsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICB9CiAgICAgICAgICBzLmhlYXBba10gPSBzLmhlYXBbal07CiAgICAgICAgICBrID0gajsKICAgICAgICAgIGogPDw9IDE7CiAgICAgICAgfQogICAgICAgIHMuaGVhcFtrXSA9IHY7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gY29tcHJlc3NfYmxvY2socywgbHRyZWUsIGR0cmVlKSB7CiAgICAgICAgdmFyIGRpc3Q7CiAgICAgICAgdmFyIGxjOwogICAgICAgIHZhciBseCA9IDA7CiAgICAgICAgdmFyIGNvZGU7CiAgICAgICAgdmFyIGV4dHJhOwogICAgICAgIGlmIChzLmxhc3RfbGl0ICE9PSAwKSB7CiAgICAgICAgICBkbyB7CiAgICAgICAgICAgIGRpc3QgPSBzLnBlbmRpbmdfYnVmW3MuZF9idWYgKyBseCAqIDJdIDw8IDggfCBzLnBlbmRpbmdfYnVmW3MuZF9idWYgKyBseCAqIDIgKyAxXTsKICAgICAgICAgICAgbGMgPSBzLnBlbmRpbmdfYnVmW3MubF9idWYgKyBseF07CiAgICAgICAgICAgIGx4Kys7CiAgICAgICAgICAgIGlmIChkaXN0ID09PSAwKSB7CiAgICAgICAgICAgICAgc2VuZF9jb2RlKHMsIGxjLCBsdHJlZSk7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgY29kZSA9IF9sZW5ndGhfY29kZVtsY107CiAgICAgICAgICAgICAgc2VuZF9jb2RlKHMsIGNvZGUgKyBMSVRFUkFMUyArIDEsIGx0cmVlKTsKICAgICAgICAgICAgICBleHRyYSA9IGV4dHJhX2xiaXRzW2NvZGVdOwogICAgICAgICAgICAgIGlmIChleHRyYSAhPT0gMCkgewogICAgICAgICAgICAgICAgbGMgLT0gYmFzZV9sZW5ndGhbY29kZV07CiAgICAgICAgICAgICAgICBzZW5kX2JpdHMocywgbGMsIGV4dHJhKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgZGlzdC0tOwogICAgICAgICAgICAgIGNvZGUgPSBkX2NvZGUoZGlzdCk7CiAgICAgICAgICAgICAgc2VuZF9jb2RlKHMsIGNvZGUsIGR0cmVlKTsKICAgICAgICAgICAgICBleHRyYSA9IGV4dHJhX2RiaXRzW2NvZGVdOwogICAgICAgICAgICAgIGlmIChleHRyYSAhPT0gMCkgewogICAgICAgICAgICAgICAgZGlzdCAtPSBiYXNlX2Rpc3RbY29kZV07CiAgICAgICAgICAgICAgICBzZW5kX2JpdHMocywgZGlzdCwgZXh0cmEpOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgfSB3aGlsZSAobHggPCBzLmxhc3RfbGl0KTsKICAgICAgICB9CiAgICAgICAgc2VuZF9jb2RlKHMsIEVORF9CTE9DSywgbHRyZWUpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGJ1aWxkX3RyZWUocywgZGVzYykgewogICAgICAgIHZhciB0cmVlID0gZGVzYy5keW5fdHJlZTsKICAgICAgICB2YXIgc3RyZWUgPSBkZXNjLnN0YXRfZGVzYy5zdGF0aWNfdHJlZTsKICAgICAgICB2YXIgaGFzX3N0cmVlID0gZGVzYy5zdGF0X2Rlc2MuaGFzX3N0cmVlOwogICAgICAgIHZhciBlbGVtcyA9IGRlc2Muc3RhdF9kZXNjLmVsZW1zOwogICAgICAgIHZhciBuLCBtOwogICAgICAgIHZhciBtYXhfY29kZSA9IC0xOwogICAgICAgIHZhciBub2RlOwogICAgICAgIHMuaGVhcF9sZW4gPSAwOwogICAgICAgIHMuaGVhcF9tYXggPSBIRUFQX1NJWkU7CiAgICAgICAgZm9yIChuID0gMDsgbiA8IGVsZW1zOyBuKyspIHsKICAgICAgICAgIGlmICh0cmVlW24gKiAyXSAhPT0gMCkgewogICAgICAgICAgICBzLmhlYXBbKytzLmhlYXBfbGVuXSA9IG1heF9jb2RlID0gbjsKICAgICAgICAgICAgcy5kZXB0aFtuXSA9IDA7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICB0cmVlW24gKiAyICsgMV0gPSAwOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICB3aGlsZSAocy5oZWFwX2xlbiA8IDIpIHsKICAgICAgICAgIG5vZGUgPSBzLmhlYXBbKytzLmhlYXBfbGVuXSA9IG1heF9jb2RlIDwgMiA/ICsrbWF4X2NvZGUgOiAwOwogICAgICAgICAgdHJlZVtub2RlICogMl0gPSAxOwogICAgICAgICAgcy5kZXB0aFtub2RlXSA9IDA7CiAgICAgICAgICBzLm9wdF9sZW4tLTsKICAgICAgICAgIGlmIChoYXNfc3RyZWUpIHsKICAgICAgICAgICAgcy5zdGF0aWNfbGVuIC09IHN0cmVlW25vZGUgKiAyICsgMV07CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGRlc2MubWF4X2NvZGUgPSBtYXhfY29kZTsKICAgICAgICBmb3IgKG4gPSBzLmhlYXBfbGVuID4+IDE7IG4gPj0gMTsgbi0tKSB7CiAgICAgICAgICBwcWRvd25oZWFwKHMsIHRyZWUsIG4pOwogICAgICAgIH0KICAgICAgICBub2RlID0gZWxlbXM7CiAgICAgICAgZG8gewogICAgICAgICAgbiA9IHMuaGVhcFsxXTsKICAgICAgICAgIHMuaGVhcFsxXSA9IHMuaGVhcFtzLmhlYXBfbGVuLS1dOwogICAgICAgICAgcHFkb3duaGVhcChzLCB0cmVlLCAxKTsKICAgICAgICAgIG0gPSBzLmhlYXBbMV07CiAgICAgICAgICBzLmhlYXBbLS1zLmhlYXBfbWF4XSA9IG47CiAgICAgICAgICBzLmhlYXBbLS1zLmhlYXBfbWF4XSA9IG07CiAgICAgICAgICB0cmVlW25vZGUgKiAyXSA9IHRyZWVbbiAqIDJdICsgdHJlZVttICogMl07CiAgICAgICAgICBzLmRlcHRoW25vZGVdID0gKHMuZGVwdGhbbl0gPj0gcy5kZXB0aFttXSA/IHMuZGVwdGhbbl0gOiBzLmRlcHRoW21dKSArIDE7CiAgICAgICAgICB0cmVlW24gKiAyICsgMV0gPSB0cmVlW20gKiAyICsgMV0gPSBub2RlOwogICAgICAgICAgcy5oZWFwWzFdID0gbm9kZSsrOwogICAgICAgICAgcHFkb3duaGVhcChzLCB0cmVlLCAxKTsKICAgICAgICB9IHdoaWxlIChzLmhlYXBfbGVuID49IDIpOwogICAgICAgIHMuaGVhcFstLXMuaGVhcF9tYXhdID0gcy5oZWFwWzFdOwogICAgICAgIGdlbl9iaXRsZW4ocywgZGVzYyk7CiAgICAgICAgZ2VuX2NvZGVzKHRyZWUsIG1heF9jb2RlLCBzLmJsX2NvdW50KTsKICAgICAgfQogICAgICBmdW5jdGlvbiBzY2FuX3RyZWUocywgdHJlZSwgbWF4X2NvZGUpIHsKICAgICAgICB2YXIgbjsKICAgICAgICB2YXIgcHJldmxlbiA9IC0xOwogICAgICAgIHZhciBjdXJsZW47CiAgICAgICAgdmFyIG5leHRsZW4gPSB0cmVlWzAgKiAyICsgMV07CiAgICAgICAgdmFyIGNvdW50ID0gMDsKICAgICAgICB2YXIgbWF4X2NvdW50ID0gNzsKICAgICAgICB2YXIgbWluX2NvdW50ID0gNDsKICAgICAgICBpZiAobmV4dGxlbiA9PT0gMCkgewogICAgICAgICAgbWF4X2NvdW50ID0gMTM4OwogICAgICAgICAgbWluX2NvdW50ID0gMzsKICAgICAgICB9CiAgICAgICAgdHJlZVsobWF4X2NvZGUgKyAxKSAqIDIgKyAxXSA9IDY1NTM1OwogICAgICAgIGZvciAobiA9IDA7IG4gPD0gbWF4X2NvZGU7IG4rKykgewogICAgICAgICAgY3VybGVuID0gbmV4dGxlbjsKICAgICAgICAgIG5leHRsZW4gPSB0cmVlWyhuICsgMSkgKiAyICsgMV07CiAgICAgICAgICBpZiAoKytjb3VudCA8IG1heF9jb3VudCAmJiBjdXJsZW4gPT09IG5leHRsZW4pIHsKICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICB9IGVsc2UgaWYgKGNvdW50IDwgbWluX2NvdW50KSB7CiAgICAgICAgICAgIHMuYmxfdHJlZVtjdXJsZW4gKiAyXSArPSBjb3VudDsKICAgICAgICAgIH0gZWxzZSBpZiAoY3VybGVuICE9PSAwKSB7CiAgICAgICAgICAgIGlmIChjdXJsZW4gIT09IHByZXZsZW4pIHsKICAgICAgICAgICAgICBzLmJsX3RyZWVbY3VybGVuICogMl0rKzsKICAgICAgICAgICAgfQogICAgICAgICAgICBzLmJsX3RyZWVbUkVQXzNfNiAqIDJdKys7CiAgICAgICAgICB9IGVsc2UgaWYgKGNvdW50IDw9IDEwKSB7CiAgICAgICAgICAgIHMuYmxfdHJlZVtSRVBaXzNfMTAgKiAyXSsrOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcy5ibF90cmVlW1JFUFpfMTFfMTM4ICogMl0rKzsKICAgICAgICAgIH0KICAgICAgICAgIGNvdW50ID0gMDsKICAgICAgICAgIHByZXZsZW4gPSBjdXJsZW47CiAgICAgICAgICBpZiAobmV4dGxlbiA9PT0gMCkgewogICAgICAgICAgICBtYXhfY291bnQgPSAxMzg7CiAgICAgICAgICAgIG1pbl9jb3VudCA9IDM7CiAgICAgICAgICB9IGVsc2UgaWYgKGN1cmxlbiA9PT0gbmV4dGxlbikgewogICAgICAgICAgICBtYXhfY291bnQgPSA2OwogICAgICAgICAgICBtaW5fY291bnQgPSAzOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgbWF4X2NvdW50ID0gNzsKICAgICAgICAgICAgbWluX2NvdW50ID0gNDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgICAgZnVuY3Rpb24gc2VuZF90cmVlKHMsIHRyZWUsIG1heF9jb2RlKSB7CiAgICAgICAgdmFyIG47CiAgICAgICAgdmFyIHByZXZsZW4gPSAtMTsKICAgICAgICB2YXIgY3VybGVuOwogICAgICAgIHZhciBuZXh0bGVuID0gdHJlZVswICogMiArIDFdOwogICAgICAgIHZhciBjb3VudCA9IDA7CiAgICAgICAgdmFyIG1heF9jb3VudCA9IDc7CiAgICAgICAgdmFyIG1pbl9jb3VudCA9IDQ7CiAgICAgICAgaWYgKG5leHRsZW4gPT09IDApIHsKICAgICAgICAgIG1heF9jb3VudCA9IDEzODsKICAgICAgICAgIG1pbl9jb3VudCA9IDM7CiAgICAgICAgfQogICAgICAgIGZvciAobiA9IDA7IG4gPD0gbWF4X2NvZGU7IG4rKykgewogICAgICAgICAgY3VybGVuID0gbmV4dGxlbjsKICAgICAgICAgIG5leHRsZW4gPSB0cmVlWyhuICsgMSkgKiAyICsgMV07CiAgICAgICAgICBpZiAoKytjb3VudCA8IG1heF9jb3VudCAmJiBjdXJsZW4gPT09IG5leHRsZW4pIHsKICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICB9IGVsc2UgaWYgKGNvdW50IDwgbWluX2NvdW50KSB7CiAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICBzZW5kX2NvZGUocywgY3VybGVuLCBzLmJsX3RyZWUpOwogICAgICAgICAgICB9IHdoaWxlICgtLWNvdW50ICE9PSAwKTsKICAgICAgICAgIH0gZWxzZSBpZiAoY3VybGVuICE9PSAwKSB7CiAgICAgICAgICAgIGlmIChjdXJsZW4gIT09IHByZXZsZW4pIHsKICAgICAgICAgICAgICBzZW5kX2NvZGUocywgY3VybGVuLCBzLmJsX3RyZWUpOwogICAgICAgICAgICAgIGNvdW50LS07CiAgICAgICAgICAgIH0KICAgICAgICAgICAgc2VuZF9jb2RlKHMsIFJFUF8zXzYsIHMuYmxfdHJlZSk7CiAgICAgICAgICAgIHNlbmRfYml0cyhzLCBjb3VudCAtIDMsIDIpOwogICAgICAgICAgfSBlbHNlIGlmIChjb3VudCA8PSAxMCkgewogICAgICAgICAgICBzZW5kX2NvZGUocywgUkVQWl8zXzEwLCBzLmJsX3RyZWUpOwogICAgICAgICAgICBzZW5kX2JpdHMocywgY291bnQgLSAzLCAzKTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHNlbmRfY29kZShzLCBSRVBaXzExXzEzOCwgcy5ibF90cmVlKTsKICAgICAgICAgICAgc2VuZF9iaXRzKHMsIGNvdW50IC0gMTEsIDcpOwogICAgICAgICAgfQogICAgICAgICAgY291bnQgPSAwOwogICAgICAgICAgcHJldmxlbiA9IGN1cmxlbjsKICAgICAgICAgIGlmIChuZXh0bGVuID09PSAwKSB7CiAgICAgICAgICAgIG1heF9jb3VudCA9IDEzODsKICAgICAgICAgICAgbWluX2NvdW50ID0gMzsKICAgICAgICAgIH0gZWxzZSBpZiAoY3VybGVuID09PSBuZXh0bGVuKSB7CiAgICAgICAgICAgIG1heF9jb3VudCA9IDY7CiAgICAgICAgICAgIG1pbl9jb3VudCA9IDM7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBtYXhfY291bnQgPSA3OwogICAgICAgICAgICBtaW5fY291bnQgPSA0OwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgICBmdW5jdGlvbiBidWlsZF9ibF90cmVlKHMpIHsKICAgICAgICB2YXIgbWF4X2JsaW5kZXg7CiAgICAgICAgc2Nhbl90cmVlKHMsIHMuZHluX2x0cmVlLCBzLmxfZGVzYy5tYXhfY29kZSk7CiAgICAgICAgc2Nhbl90cmVlKHMsIHMuZHluX2R0cmVlLCBzLmRfZGVzYy5tYXhfY29kZSk7CiAgICAgICAgYnVpbGRfdHJlZShzLCBzLmJsX2Rlc2MpOwogICAgICAgIGZvciAobWF4X2JsaW5kZXggPSBCTF9DT0RFUyAtIDE7IG1heF9ibGluZGV4ID49IDM7IG1heF9ibGluZGV4LS0pIHsKICAgICAgICAgIGlmIChzLmJsX3RyZWVbYmxfb3JkZXJbbWF4X2JsaW5kZXhdICogMiArIDFdICE9PSAwKSB7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBzLm9wdF9sZW4gKz0gMyAqIChtYXhfYmxpbmRleCArIDEpICsgNSArIDUgKyA0OwogICAgICAgIHJldHVybiBtYXhfYmxpbmRleDsKICAgICAgfQogICAgICBmdW5jdGlvbiBzZW5kX2FsbF90cmVlcyhzLCBsY29kZXMsIGRjb2RlcywgYmxjb2RlcykgewogICAgICAgIHZhciByYW5rOwogICAgICAgIHNlbmRfYml0cyhzLCBsY29kZXMgLSAyNTcsIDUpOwogICAgICAgIHNlbmRfYml0cyhzLCBkY29kZXMgLSAxLCA1KTsKICAgICAgICBzZW5kX2JpdHMocywgYmxjb2RlcyAtIDQsIDQpOwogICAgICAgIGZvciAocmFuayA9IDA7IHJhbmsgPCBibGNvZGVzOyByYW5rKyspIHsKICAgICAgICAgIHNlbmRfYml0cyhzLCBzLmJsX3RyZWVbYmxfb3JkZXJbcmFua10gKiAyICsgMV0sIDMpOwogICAgICAgIH0KICAgICAgICBzZW5kX3RyZWUocywgcy5keW5fbHRyZWUsIGxjb2RlcyAtIDEpOwogICAgICAgIHNlbmRfdHJlZShzLCBzLmR5bl9kdHJlZSwgZGNvZGVzIC0gMSk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZGV0ZWN0X2RhdGFfdHlwZShzKSB7CiAgICAgICAgdmFyIGJsYWNrX21hc2sgPSA0MDkzNjI0NDQ3OwogICAgICAgIHZhciBuOwogICAgICAgIGZvciAobiA9IDA7IG4gPD0gMzE7IG4rKywgYmxhY2tfbWFzayA+Pj49IDEpIHsKICAgICAgICAgIGlmIChibGFja19tYXNrICYgMSAmJiBzLmR5bl9sdHJlZVtuICogMl0gIT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIFpfQklOQVJZOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAocy5keW5fbHRyZWVbOSAqIDJdICE9PSAwIHx8IHMuZHluX2x0cmVlWzEwICogMl0gIT09IDAgfHwgcy5keW5fbHRyZWVbMTMgKiAyXSAhPT0gMCkgewogICAgICAgICAgcmV0dXJuIFpfVEVYVDsKICAgICAgICB9CiAgICAgICAgZm9yIChuID0gMzI7IG4gPCBMSVRFUkFMUzsgbisrKSB7CiAgICAgICAgICBpZiAocy5keW5fbHRyZWVbbiAqIDJdICE9PSAwKSB7CiAgICAgICAgICAgIHJldHVybiBaX1RFWFQ7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiBaX0JJTkFSWTsKICAgICAgfQogICAgICB2YXIgc3RhdGljX2luaXRfZG9uZSA9IGZhbHNlOwogICAgICBmdW5jdGlvbiBfdHJfaW5pdChzKSB7CiAgICAgICAgaWYgKCFzdGF0aWNfaW5pdF9kb25lKSB7CiAgICAgICAgICB0cl9zdGF0aWNfaW5pdCgpOwogICAgICAgICAgc3RhdGljX2luaXRfZG9uZSA9IHRydWU7CiAgICAgICAgfQogICAgICAgIHMubF9kZXNjID0gbmV3IFRyZWVEZXNjKHMuZHluX2x0cmVlLCBzdGF0aWNfbF9kZXNjKTsKICAgICAgICBzLmRfZGVzYyA9IG5ldyBUcmVlRGVzYyhzLmR5bl9kdHJlZSwgc3RhdGljX2RfZGVzYyk7CiAgICAgICAgcy5ibF9kZXNjID0gbmV3IFRyZWVEZXNjKHMuYmxfdHJlZSwgc3RhdGljX2JsX2Rlc2MpOwogICAgICAgIHMuYmlfYnVmID0gMDsKICAgICAgICBzLmJpX3ZhbGlkID0gMDsKICAgICAgICBpbml0X2Jsb2NrKHMpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIF90cl9zdG9yZWRfYmxvY2socywgYnVmLCBzdG9yZWRfbGVuLCBsYXN0KSB7CiAgICAgICAgc2VuZF9iaXRzKHMsIChTVE9SRURfQkxPQ0sgPDwgMSkgKyAobGFzdCA/IDEgOiAwKSwgMyk7CiAgICAgICAgY29weV9ibG9jayhzLCBidWYsIHN0b3JlZF9sZW4sIHRydWUpOwogICAgICB9CiAgICAgIGZ1bmN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ZXIgPj4+IDE2ICYgNjU1MzUgfCAwLCBuID0gMDsKICAgICAgICB3aGlsZSAobGVuICE9PSAwKSB7CiAgICAgICAgICBuID0gbGVuID4gMmUzID8gMmUzIDogbGVuOwogICAgICAgICAgbGVuIC09IG47CiAgICAgICAgICBkbyB7CiAgICAgICAgICAgIHMxID0gczEgKyBidWZbcG9zKytdIHwgMDsKICAgICAgICAgICAgczIgPSBzMiArIHMxIHwgMDsKICAgICAgICAgIH0gd2hpbGUgKC0tbik7CiAgICAgICAgICBzMSAlPSA2NTUyMTsKICAgICAgICAgIHMyICU9IDY1NTIxOwogICAgICAgIH0KICAgICAgICByZXR1cm4gczEgfCBzMiA8PCAxNiB8IDA7CiAgICAgIH0KICAgICAgbW9kdWxlLmV4cG9ydHMgPSBhZGxlcjMyOwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvY3JjMzIuanMKICB2YXIgcmVxdWlyZV9jcmMzMiA9IF9fY29tbW9uSlMoewogICAgIm5vZGVfbW9kdWxlcy8ucG5wbS9wYWtvQDEuMC4xMS9ub2RlX21vZHVsZXMvcGFrby9saWIvemxpYi9jcmMzMi5qcyIoZXhwb3J0cywgbW9kdWxlKSB7CiAgICAgIGluaXRfYnVmZmVyX3NoaW0oKTsKICAgICAgInVzZSBzdHJpY3QiOwogICAgICBmdW5jdGlvbiBtYWtlVGFibGUoKSB7CiAgICAgICAgdmFyIGMsIHRhYmxlID0gW107CiAgICAgICAgZm9yICh2YXIgbiA9IDA7IG4gPCAyNTY7IG4rKykgewogICAgICAgICAgYyA9IG47CiAgICAgICAgICBmb3IgKHZhciBrID0gMDsgayA8IDg7IGsrKykgewogICAgICAgICAgICBjID0gYyAmIDEgPyAzOTg4MjkyMzg0IF4gYyA+Pj4gMSA6IGMgPj4+IDE7CiAgICAgICAgICB9CiAgICAgICAgICB0YWJsZVtuXSA9IGM7CiAgICAgICAgfQogICAgICAgIHJldHVybiB0YWJsZTsKICAgICAgfQogICAgICB2YXIgY3JjVGFibGUgPSBtYWtlVGFibGUoKTsKICAgICAgZnVuY3Rpb24gY3JjMzIyKGNyYywgYnVmLCBsZW4sIHBvcykgewogICAgICAgIHZhciB0ID0gY3JjVGFibGUsIGVuZCA9IHBvcyArIGxlbjsKICAgICAgICBjcmMgXj0gLTE7CiAgICAgICAgZm9yICh2YXIgaSA9IHBvczsgaSA8IGVuZDsgaSsrKSB7CiAgICAgICAgICBjcmMgPSBjcmMgPj4+IDggXiB0WyhjcmMgXiBidWZbaV0pICYgMjU1XTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIGNyYyBeIC0xOwogICAgICB9CiAgICAgIG1vZHVsZS5leHBvcnRzID0gY3JjMzIyOwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvbWVzc2FnZXMuanMKICB2YXIgcmVxdWlyZV9tZXNzYWdlczIgPSBfX2NvbW1vbkpTKHsKICAgICJub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvbWVzc2FnZXMuanMiKGV4cG9ydHMsIG1vZHVsZSkgewogICAgICBpbml0X2J1ZmZlcl9zaGltKCk7CiAgICAgICJ1c2Ugc3RyaWN0IjsKICAgICAgbW9kdWxlLmV4cG9ydHMgPSB7CiAgICAgICAgMjogIm5lZWQgZGljdGlvbmFyeSIsCiAgICAgICAgMTogInN0cmVhbSBlbmQiLAogICAgICAgIDA6ICIiLAogICAgICAgICItMSI6ICJmaWxlIGVycm9yIiwKICAgICAgICAiLTIiOiAic3RyZWFtIGVycm9yIiwKICAgICAgICAiLTMiOiAiZGF0YSBlcnJvciIsCiAgICAgICAgIi00IjogImluc3VmZmljaWVudCBtZW1vcnkiLAogICAgICAgICItNSI6ICJidWZmZXIgZXJ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X0ZJTklTSF9TVEFSVEVEID0gMzsKICAgICAgdmFyIEJTX0ZJTklTSF9ET05FID0gNDsKICAgICAgdmFyIE9TX0NPREUgPSAzOwogICAgICBmdW5jdGlvbiBlcnIoc3RybSwgZXJyb3JDb2RlKSB7CiAgICAgICAgc3RybS5tc2cgPSBtc2dbZXJyb3JDb2RlXTsKICAgICAgICByZXR1cm4gZXJyb3JDb2RlOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIHJhbmsoZikgewogICAgICAgIHJldHVybiAoZiA8PCAxKSAtIChmID4gNCA/IDkgOiAwKTsKICAgICAgfQogICAgICBmdW5jdGlvbiB6ZXJvKGJ1ZikgewogICAgICAgIHZhciBsZW4gPSBidWYubGVuZ3RoOwogICAgICAgIHdoaWxlICgtLWxlbiA+PSAwKSB7CiAgICAgICAgICBidWZbbGVuXSA9IDA7CiAgICAgICAgfQogICAgICB9CiAgICAgIGZ1bmN0aW9uIGZsdXNoX3BlbmRpbmcoc3RybSkgewogICAgICAgIHZhciBzID0gc3RybS5zdGF0ZTsKICAgICAgICB2YXIgbGVuID0gcy5wZW5kaW5nOwogICAgICAgIGlmIChsZW4gPiBzdHJtLmF2YWlsX291dCkgewogICAgICAgICAgbGVuID0gc3RybS5hdmFpbF9vdXQ7CiAgICAgICAgfQogICAgICAgIGlmIChsZW4gPT09IDApIHsKICAgICAgICAgIHJldHVybjsKICAgICAgICB9CiAgICAgICAgdXRpbHMuYXJyYXlTZXQoc3RybS5vdXRwdXQsIHMucGVuZGluZ19idWYsIHMucGVuZGluZ19vdXQsIGxlbiwgc3RybS5uZXh0X291dCk7CiAgICAgICAgc3RybS5uZXh0X291dCArPSBsZW47CiAgICAgICAgcy5wZW5kaW5nX291dCArPSBsZW47CiAgICAgICAgc3RybS50b3RhbF9vdXQgKz0gbGVuOwogICAgICAgIHN0cm0uYXZhaWxfb3V0IC09IGxlbjsKICAgICAgICBzLnBlbmRpbmcgLT0gbGVuOwogICAgICAgIGlmIChzLnBlbmRpbmcgPT09IDApIHsKICAgICAgICAgIHMucGVuZGluZ19vdXQgPSAwOwogICAgICAgIH0KICAgICAgfQogICAgICBmdW5jdGlvbiBmbHVzaF9ibG9ja19vbmx5KHMsIGxhc3QpIHsKICAgICAgICB0cmVlcy5fdHJfZmx1c2hfYmxvY2socywgcy5ibG9ja19zdGFydCA+PSAwID8gcy5ibG9ja19zdGFydCA6IC0xLCBzLnN0cnN0YXJ0IC0gcy5ibG9ja19zdGFydCwgbGFzdCk7CiAgICAgICAgcy5ibG9ja19zdGFydCA9IHMuc3Ryc3RhcnQ7CiAgICAgICAgZmx1c2hfcGVuZGluZyhzLnN0cm0pOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIHB1dF9ieXRlKHMsIGIpIHsKICAgICAgICBzLnBlbmRpbmdfYnVmW3MucGVuZGluZysrXSA9IGI7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gcHV0U2hvcnRNU0IocywgYikgewogICAgICAgIHMucGVuZGluZ19idWZbcy5wZW5kaW5nKytdID0gYiA+Pj4gOCAmIDI1NTsKICAgICAgICBzLnBlbmRpbmdfYnVmW3MucGVuZGluZysrXSA9IGIgJiAyNTU7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gcmVhZF9idWYoc3RybSwgYnVmLCBzdGFydCwgc2l6ZSkgewogICAgICAgIHZhciBsZW4gPSBzdHJtLmF2YWlsX2luOwogICAgICAgIGlmIChsZW4gPiBzaXplKSB7CiAgICAgICAgICBsZW4gPSBzaXplOwogICAgICAgIH0KICAgICAgICBpZiAobGVuID09PSAwKSB7CiAgICAgICAgICByZXR1cm4gMDsKICAgICAgICB9CiAgICAgICAgc3RybS5hdmFpbF9pbiAtPSBsZW47CiAgICAgICAgdXRpbHMuYXJyYXlTZXQoYnVmLCBzdHJtLmlucHV0LCBzdHJtLm5leHRfaW4sIGxlbiwgc3RhcnQpOwogICAgICAgIGlmIChzdHJtLnN0YXRlLndyYXAgPT09IDEpIHsKICAgICAgICAgIHN0cm0uYWRsZX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mdvb2RfbWF0Y2gpIHsKICAgICAgICAgIGNoYWluX2xlbmd0aCA+Pj0gMjsKICAgICAgICB9CiAgICAgICAgaWYgKG5pY2VfbWF0Y2ggPiBzLmxvb2thaGVhZCkgewogICAgICAgICAgbmljZV9tYXRjaCA9IHMubG9va2FoZWFkOwogICAgICAgIH0KICAgICAgICBkbyB7CiAgICAgICAgICBtYXRjaCA9IGN1cl9tYXRjaDsKICAgICAgICAgIGlmIChfd2luW21hdGNoICsgYmVzdF9sZW5dICE9PSBzY2FuX2VuZCB8fCBfd2luW21hdGNoICsgYmVzdF9sZW4gLSAxXSAhPT0gc2Nhbl9lbmQxIHx8IF93aW5bbWF0Y2hdICE9PSBfd2luW3NjYW5dIHx8IF93aW5bKyttYXRjaF0gIT09IF93aW5bc2NhbiArIDFdKSB7CiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgfQogICAgICAgICAgc2NhbiArPSAyOwogICAgICAgICAgbWF0Y2grKzsKICAgICAgICAgIGRvIHsKICAgICAgICAgIH0gd2hpbGUgKF93aW5bKytzY2FuXSA9PT0gX3dpblsrK21hdGNoXSAmJiBfd2luWysrc2Nhbl0gPT09IF93aW5bKyttYXRjaF0gJiYgX3dpblsrK3NjYW5dID09PSBfd2luWysrbWF0Y2hdICYmIF93aW5bKytzY2FuXSA9PT0gX3dpblsrK21hdGNoXSAmJiBfd2luWysrc2Nhbl0gPT09IF93aW5bKyttYXRjaF0gJiYgX3dpblsrK3NjYW5dID09PSBfd2luWysrbWF0Y2hdICYmIF93aW5bKytzY2FuXSA9PT0gX3dpblsrK21hdGNoXSAmJiBfd2luWysrc2Nhbl0gPT09IF93aW5bKyttYXRjaF0gJiYgc2NhbiA8IHN0cmVuZCk7CiAgICAgICAgICBsZW4gPSBNQVhfTUFUQ0ggLSAoc3RyZW5kIC0gc2Nhbik7CiAgICAgICAgICBzY2FuID0gc3RyZW5kIC0gTUFYX01BVENIOwogICAgICAgICAgaWYgKGxlbiA+IGJlc3RfbGVuKSB7CiAgICAgICAgICAgIHMubWF0Y2hfc3RhcnQgPSBjdXJfbWF0Y2g7CiAgICAgICAgICAgIGJlc3RfbGVuID0gbGVuOwogICAgICAgICAgICBpZiAobGVuID49IG5pY2VfbWF0Y2gpIHsKICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgICBzY2FuX2VuZDEgPSBfd2luW3NjYW4gKyBiZXN0X2xlbiAtIDFdOwogICAgICAgICAgICBzY2FuX2VuZCA9IF93aW5bc2NhbiArIGJlc3RfbGVuXTsKICAgICAgICAgIH0KICAgICAgICB9IHdoaWxlICgoY3VyX21hdGNoID0gcHJldltjdXJfbWF0Y2ggJiB3bWFza10pID4gbGltaXQgJiYgLS1jaGFpbl9sZW5ndGggIT09IDApOwogICAgICAgIGlmIChiZXN0X2xlbiA8PSBzLmxvb2thaGVhZCkgewogICAgICAgICAgcmV0dXJuIGJlc3RfbGVuOwogICAgICAgIH0KICAgICAgICByZXR1cm4gcy5sb29rYWhlYWQ7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZmlsbF93aW5kb3cocykgewogICAgICAgIHZhciBfd19zaXplID0gcy53X3NpemU7CiAgICAgICAgdmFyIHAsIG4sIG0sIG1vcmUsIHN0cjsKICAgICAgICBkbyB7CiAgICAgICAgICBtb3JlID0gcy53aW5kb3dfc2l6ZSAtIHMubG9va2FoZWFkIC0gcy5zdHJzdGFydDsKICAgICAgICAgIGlmIChzLnN0cnN0YXJ0ID49IF93X3NpemUgKyAoX3dfc2l6ZSAtIE1JTl9MT09LQUhFQUQpKSB7CiAgICAgICAgICAgIHV0aWxzLmFycmF5U2V0KHMud2luZG93LCBzLndpbmRvdywgX3dfc2l6ZSwgX3dfc2l6ZSwgMCk7CiAgICAgICAgICAgIHMubWF0Y2hfc3RhcnQgLT0gX3dfc2l6ZTsKICAgICAgICAgICAgcy5zdHJzdGFydCAtPSBfd19zaXplOwogICAgICAgICAgICBzLmJsb2NrX3N0YXJ0IC09IF93X3NpemU7CiAgICAgICAgICAgIG4gPSBzLmhhc2hfc2l6ZTsKICAgICAgICAgICAgcCA9IG47CiAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICBtID0gcy5oZWFkWy0tcF07CiAgICAgICAgICAgICAgcy5oZWFkW3BdID0gbSA+PSBfd19zaXplID8gbSAtIF93X3NpemUgOiAwOwogICAgICAgICAgICB9IHdoaWxlICgtLW4pOwogICAgICAgICAgICBuID0gX3dfc2l6ZTsKICAgICAgICAgICAgcCA9IG47CiAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICBtID0gcy5wcmV2Wy0tcF07CiAgICAgICAgICAgICAgcy5wcmV2W3BdID0gbSA+PSBfd19zaXplID8gbSAtIF93X3NpemUgOiAwOwogICAgICAgICAgICB9IHdoaWxlICgtLW4pOwogICAgICAgICAgICBtb3JlICs9IF93X3NpemU7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX2luID09PSAwKSB7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgICAgbiA9IHJlYWRfYnVmKHMuc3RybSwgcy53aW5kb3csIHMuc3Ryc3RhcnQgKyBzLmxvb2thaGVhZCwgbW9yZSk7CiAgICAgICAgICBzLmxvb2thaGVhZCArPSBuOwogICAgICAgICAgaWYgKHMubG9va2FoZWFkICsgcy5pbnNlcnQgPj0gTUlOX01BVENIKSB7CiAgICAgICAgICAgIHN0ciA9IHMuc3Ryc3RhcnQgLSBzLmluc2VydDsKICAgICAgICAgICAgcy5pbnNfaCA9IHMud2luZG93W3N0cl07CiAgICAgICAgICAgIHMuaW5zX2ggPSAocy5pbnNfaCA8PCBzLmhhc2hfc2hpZnQgXiBzLndpbmRvd1tzdHIgKyAxXSkgJiBzLmhhc2hfbWFzazsKICAgICAgICAgICAgd2hpbGUgKHMuaW5zZXJ0KSB7CiAgICAgICAgICAgICAgcy5pbnNfaCA9IChzLmluc19oIDw8IHMuaGFzaF9zaGlmdCBeIHMud2luZG93W3N0ciArIE1JTl9NQVRDSCAtIDFdKSAmIHMuaGFzaF9tYXNrOwogICAgICAgICAgICAgIHMucHJldltzdHIgJiBzLndfbWFza10gPSBzLmhlYWRbcy5pbnNfaF07CiAgICAgICAgICAgICAgcy5oZWFkW3MuaW5zX2hdID0gc3RyOwogICAgICAgICAgICAgIHN0cisrOwogICAgICAgICAgICAgIHMuaW5zZXJ0LS07CiAgICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkICsgcy5pbnNlcnQgPCBNSU5fTUFUQ0gpIHsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0gd2hpbGUgKHMubG9va2FoZWFkIDwgTUlOX0xPT0tBSEVBRCAmJiBzLnN0cm0uYXZhaWxfaW4gIT09IDApOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGRlZmxhdGVfc3RvcmVkKHMsIGZsdXNoKSB7CiAgICAgICAgdmFyIG1heF9ibG9ja19zaXplID0gNjU1MzU7CiAgICAgICAgaWYgKG1heF9ibG9ja19zaXplID4gcy5wZW5kaW5nX2J1Zl9zaXplIC0gNSkgewogICAgICAgICAgbWF4X2Jsb2NrX3NpemUgPSBzLnBlbmRpbmdfYnVmX3NpemUgLSA1OwogICAgICAgIH0KICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA8PSAxKSB7CiAgICAgICAgICAgIGZpbGxfd2luZG93KHMpOwogICAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPT09IDAgJiYgZmx1c2ggPT09IFpfTk9fRkxVU0gpIHsKICAgICAgICAgICAgICByZXR1cm4gQlNfTkVFRF9NT1JFOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA9PT0gMCkgewogICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBzLnN0cnN0YXJ0ICs9IHMubG9va2FoZWFkOwogICAgICAgICAgcy5sb29rYWhlYWQgPSAwOwogICAgICAgICAgdmFyIG1heF9zdGFydCA9IHMuYmxvY2tfc3RhcnQgKyBtYXhfYmxvY2tfc2l6ZTsKICAgICAgICAgIGlmIChzLnN0cnN0YXJ0ID09PSAwIHx8IHMuc3Ryc3RhcnQgPj0gbWF4X3N0YXJ0KSB7CiAgICAgICAgICAgIHMubG9va2FoZWFkID0gcy5zdHJzdGFydCAtIG1heF9zdGFydDsKICAgICAgICAgICAgcy5zdHJzdGFydCA9IG1heF9zdGFydDsKICAgICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCBmYWxzZSk7CiAgICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgaWYgKHMuc3Ryc3RhcnQgLSBzLmJsb2NrX3N0YXJ0ID49IHMud19zaXplIC0gTUlOX0xPT0tBSEVBRCkgewogICAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIGZhbHNlKTsKICAgICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgICByZXR1cm4gQlNfTkVFRF9NT1JFOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHMuaW5zZXJ0ID0gMDsKICAgICAgICBpZiAoZmx1c2ggPT09IFpfRklOSVNIKSB7CiAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIHRydWUpOwogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIEJTX0ZJTklTSF9TVEFSVEVEOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIEJTX0ZJTklTSF9ET05FOwogICAgICAgIH0KICAgICAgICBpZiAocy5zdHJzdGFydCA+IHMuYmxvY2tfc3RhcnQpIHsKICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgZmFsc2UpOwogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgfQogICAgICBmdW5jdGlvbiBkZWZsYXRlX2Zhc3QocywgZmx1c2gpIHsKICAgICAgICB2YXIgaGFzaF9oZWFkOwogICAgICAgIHZhciBiZmx1c2g7CiAgICAgICAgZm9yICg7IDsgKSB7CiAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPCBNSU5fTE9PS0FIRUFEKSB7CiAgICAgICAgICAgIGZpbGxfd2luZG93KHMpOwogICAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPCBNSU5fTE9PS0FIRUFEICYmIGZsdXNoID09PSBaX05PX0ZMVVNIKSB7CiAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPT09IDApIHsKICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgaGFzaF9oZWFkID0gMDsKICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA+PSBNSU5fTUFUQ0gpIHsKICAgICAgICAgICAgcy5pbnNfaCA9IChzLmluc19oIDw8IHMuaGFzaF9zaGlmdCBeIHMud2luZG93W3Muc3Ryc3RhcnQgKyBNSU5fTUFUQ0ggLSAxXSkgJiBzLmhhc2hfbWFzazsKICAgICAgICAgICAgaGFzaF9oZWFkID0gcy5wcmV2W3Muc3Ryc3RhcnQgJiBzLndfbWFza10gPSBzLmhlYWRbcy5pbnNfaF07CiAgICAgICAgICAgIHMuaGVhZFtzLmluc19oXSA9IHMuc3Ryc3RhcnQ7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoaGFzaF9oZWFkICE9PSAwICYmIHMuc3Ryc3RhcnQgLSBoYXNoX2hlYWQgPD0gcy53X3NpemUgLSBNSU5fTE9PS0FIRUFEKSB7CiAgICAgICAgICAgIHMubWF0Y2hfbGVuZ3RoID0gbG9uZ2VzdF9tYXRjaChzLCBoYXNoX2hlYWQpOwogICAgICAgICAgfQogICAgICAgICAgaWYgKHMubWF0Y2hfbGVuZ3RoID49IE1JTl9NQVRDSCkgewogICAgICAgICAgICBiZmx1c2ggPSB0cmVlcy5fdHJfdGFsbHkocywgcy5zdHJzdGFydCAtIHMubWF0Y2hfc3RhcnQsIHMubWF0Y2hfbGVuZ3RoIC0gTUlOX01BVENIKTsKICAgICAgICAgICAgcy5sb29rYWhlYWQgLT0gcy5tYXRjaF9sZW5ndGg7CiAgICAgICAgICAgIGlmIChzLm1hdGNoX2xlbmd0aCA8PSBzLm1heF9sYXp5X21hdGNoICYmIHMubG9va2FoZWFkID49IE1JTl9NQVRDSCkgewogICAgICAgICAgICAgIHMubWF0Y2hfbGVuZ3RoLS07CiAgICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgICAgcy5zdHJzdGFydCsrOwogICAgICAgICAgICAgICAgcy5pbnNfaCA9IChzLmluc19oIDw8IHMuaGFzaF9zaGlmdCBeIHMud2luZG93W3Muc3Ryc3RhcnQgKyBNSU5fTUFUQ0ggLSAxXSkgJiBzLmhhc2hfbWFzazsKICAgICAgICAgICAgICAgIGhhc2hfaGVhZCA9IHMucHJldltzLnN0cnN0YXJ0ICYgcy53X21hc2tdID0gcy5oZWFkW3MuaW5zX2hdOwogICAgICAgICAgICAgICAgcy5oZWFkW3MuaW5zX2hdID0gcy5zdHJzdGFydDsKICAgICAgICAgICAgICB9IHdoaWxlICgtLXMubWF0Y2hfbGVuZ3RoICE9PSAwKTsKICAgICAgICAgICAgICBzLnN0cnN0YXJ0Kys7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgcy5zdHJzdGFydCArPSBzLm1hdGNoX2xlbmd0aDsKICAgICAgICAgICAgICBzLm1hdGNoX2xlbmd0aCA9IDA7CiAgICAgICAgICAgICAgcy5pbnNfaCA9IHMud2luZG93W3Muc3Ryc3RhcnRdOwogICAgICAgICAgICAgIHMuaW5zX2ggPSAocy5pbnNfaCA8PCBzLmhhc2hfc2hpZnQgXiBzLndpbmRvd1tzLnN0cnN0YXJ0ICsgMV0pICYgcy5oYXNoX21hc2s7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGJmbHVzaCA9IHRyZWVzLl90cl90YWxseShzLCAwLCBzLndpbmRvd1tzLnN0cnN0YXJ0XSk7CiAgICAgICAgICAgIHMubG9va2FoZWFkLS07CiAgICAgICAgICAgIHMuc3Ryc3RhcnQrKzsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChiZmx1c2gpIHsKICAgICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCBmYWxzZSk7CiAgICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBzLmluc2VydCA9IHMuc3Ryc3RhcnQgPCBNSU5fTUFUQ0ggLSAxID8gcy5zdHJzdGFydCA6IE1JTl9NQVRDSCAtIDE7CiAgICAgICAgaWYgKGZsdXNoID09PSBaX0ZJTklTSCkgewogICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCB0cnVlKTsKICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgIHJldHVybiBCU19GSU5JU0hfU1RBUlRFRDsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBCU19GSU5JU0hfRE9ORTsKICAgICAgICB9CiAgICAgICAgaWYgKHMubGFzdF9saXQpIHsKICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgZmFsc2UpOwogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIEJTX0JMT0NLX0RPTkU7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZGVmbGF0ZV9zbG93KHMsIGZsdXNoKSB7CiAgICAgICAgdmFyIGhhc2hfaGVhZDsKICAgICAgICB2YXIgYmZsdXNoOwogICAgICAgIHZhciBtYXhfaW5zZXJ0OwogICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgaWYgKHMubG9va2FoZWFkIDwgTUlOX0xPT0tBSEVBRCkgewogICAgICAgICAgICBmaWxsX3dpbmRvdyhzKTsKICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkIDwgTUlOX0xPT0tBSEVBRCAmJiBmbHVzaCA9PT0gWl9OT19GTFVTSCkgewogICAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkID09PSAwKSB7CiAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGhhc2hfaGVhZCA9IDA7CiAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPj0gTUlOX01BVENIKSB7CiAgICAgICAgICAgIHMuaW5zX2ggPSAocy5pbnNfaCA8PCBzLmhhc2hfc2hpZnQgXiBzLndpbmRvd1tzLnN0cnN0YXJ0ICsgTUlOX01BVENIIC0gMV0pICYgcy5oYXNoX21hc2s7CiAgICAgICAgICAgIGhhc2hfaGVhZCA9IHMucHJldltzLnN0cnN0YXJ0ICYgcy53X21hc2tdID0gcy5oZWFkW3MuaW5zX2hdOwogICAgICAgICAgICBzLmhlYWRbcy5pbnNfaF0gPSBzLnN0cnN0YXJ0OwogICAgICAgICAgfQogICAgICA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gICAgICAgICAgZG8gewogICAgICAgICAgICAgIGlmICgrK3Muc3Ryc3RhcnQgPD0gbWF4X2luc2VydCkgewogICAgICAgICAgICAgICAgcy5pbnNfaCA9IChzLmluc19oIDw8IHMuaGFzaF9zaGlmdCBeIHMud2luZG93W3Muc3Ryc3RhcnQgKyBNSU5fTUFUQ0ggLSAxXSkgJiBzLmhhc2hfbWFzazsKICAgICAgICAgICAgICAgIGhhc2hfaGVhZCA9IHMucHJldltzLnN0cnN0YXJ0ICYgcy53X21hc2tdID0gcy5oZWFkW3MuaW5zX2hdOwogICAgICAgICAgICAgICAgcy5oZWFkW3MuaW5zX2hdID0gcy5zdHJzdGFydDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0gd2hpbGUgKC0tcy5wcmV2X2xlbmd0aCAhPT0gMCk7CiAgICAgICAgICAgIHMubWF0Y2hfYXZhaWxhYmxlID0gMDsKICAgICAgICAgICAgcy5tYXRjaF9sZW5ndGggPSBNSU5fTUFUQ0ggLSAxOwogICAgICAgICAgICBzLnN0cnN0YXJ0Kys7CiAgICAgICAgICAgIGlmIChiZmx1c2gpIHsKICAgICAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIGZhbHNlKTsKICAgICAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSBpZiAocy5tYXRjaF9hdmFpbGFibGUpIHsKICAgICAgICAgICAgYmZsdXNoID0gdHJlZXMuX3RyX3RhbGx5KHMsIDAsIHMud2luZG93W3Muc3Ryc3RhcnQgLSAxXSk7CiAgICAgICAgICAgIGlmIChiZmx1c2gpIHsKICAgICAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIGZhbHNlKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBzLnN0cnN0YXJ0Kys7CiAgICAgICAgICAgIHMubG9va2FoZWFkLS07CiAgICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgfQogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcy5tYXRjaF9hdmFpbGFibGUgPSAxOwogICAgICAgICAgICBzLnN0cnN0YXJ0Kys7CiAgICAgICAgICAgIHMubG9va2FoZWFkLS07CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChzLm1hdGNoX2F2YWlsYWJsZSkgewogICAgICAgICAgYmZsdXNoID0gdHJlZXMuX3RyX3RhbGx5KHMsIDAsIHMud2luZG93W3Muc3Ryc3RhcnQgLSAxXSk7CiAgICAgICAgICBzLm1hdGNoX2F2YWlsYWJsZSA9IDA7CiAgICAgICAgfQogICAgICAgIHMuaW5zZXJ0ID0gcy5zdHJzdGFydCA8IE1JTl9NQVRDSCAtIDEgPyBzLnN0cnN0YXJ0IDogTUlOX01BVENIIC0gMTsKICAgICAgICBpZiAoZmx1c2ggPT09IFpfRklOSVNIKSB7CiAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIHRydWUpOwogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIEJTX0ZJTklTSF9TVEFSVEVEOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIEJTX0ZJTklTSF9ET05FOwogICAgICAgIH0KICAgICAgICBpZiAocy5sYXN0X2xpdCkgewogICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCBmYWxzZSk7CiAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICByZXR1cm4gQlNfTkVFRF9NT1JFOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gQlNfQkxPQ0tfRE9ORTsKICAgICAgfQogICAgICBmdW5jdGlvbiBkZWZsYXRlX3JsZShzLCBmbHVzaCkgewogICAgICAgIHZhciBiZmx1c2g7CiAgICAgICAgdmFyIHByZXY7CiAgICAgICAgdmFyIHNjYW4sIHN0cmVuZDsKICAgICAgICB2YXIgX3dpbiA9IHMud2luZG93OwogICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgaWYgKHMubG9va2FoZWFkIDw9IE1BWF9NQVRDSCkgewogICAgICAgICAgICBmaWxsX3dpbmRvdyhzKTsKICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkIDw9IE1BWF9NQVRDSCAmJiBmbHVzaCA9PT0gWl9OT19GTFVTSCkgewogICAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkID09PSAwKSB7CiAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIHMubWF0Y2hfbGVuZ3RoID0gMDsKICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA+PSBNSU5fTUFUQ0ggJiYgcy5zdHJzdGFydCA+IDApIHsKICAgICAgICAgICAgc2NhbiA9IHMuc3Ryc3RhcnQgLSAxOwogICAgICAgICAgICBwcmV2ID0gX3dpbltzY2FuXTsKICAgICAgICAgICAgaWYgKHByZXYgPT09IF93aW5bKytzY2FuXSAmJiBwcmV2ID09PSBfd2luWysrc2Nhbl0gJiYgcHJldiA9PT0gX3dpblsrK3NjYW5dKSB7CiAgICAgICAgICAgICAgc3RyZW5kID0gcy5zdHJzdGFydCArIE1BWF9NQVRDSDsKICAgICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgfSB3aGlsZSAocHJldiA9PT0gX3dpblsrK3NjYW5dICYmIHByZXYgPT09IF93aW5bKytzY2FuXSAmJiBwcmV2ID09PSBfd2luWysrc2Nhbl0gJiYgcHJldiA9PT0gX3dpblsrK3NjYW5dICYmIHByZXYgPT09IF93aW5bKytzY2FuXSAmJiBwcmV2ID09PSBfd2luWysrc2Nhbl0gJiYgcHJldiA9PT0gX3dpblsrK3NjYW5dICYmIHByZXYgPT09IF93aW5bKytzY2FuXSAmJiBzY2FuIDwgc3RyZW5kKTsKICAgICAgICAgICAgICBzLm1hdGNoX2xlbmd0aCA9IE1BWF9NQVRDSCAtIChzdHJlbmQgLSBzY2FuKTsKICAgICAgICAgICAgICBpZiAocy5tYXRjaF9sZW5ndGggPiBzLmxvb2thaGVhZCkgewogICAgICAgICAgICAgICAgcy5tYXRjaF9sZW5ndGggPSBzLmxvb2thaGVhZDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGlmIChzLm1hdGNoX2xlbmd0aCA+PSBNSU5fTUFUQ0gpIHsKICAgICAgICAgICAgYmZsdXNoID0gdHJlZXMuX3RyX3RhbGx5KHMsIDEsIHMubWF0Y2hfbGVuZ3RoIC0gTUlOX01BVENIKTsKICAgICAgICAgICAgcy5sb29rYWhlYWQgLT0gcy5tYXRjaF9sZW5ndGg7CiAgICAgICAgICAgIHMuc3Ryc3RhcnQgKz0gcy5tYXRjaF9sZW5ndGg7CiAgICAgICAgICAgIHMubWF0Y2hfbGVuZ3RoID0gMDsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGJmbHVzaCA9IHRyZWVzLl90cl90YWxseShzLCAwLCBzLndpbmRvd1tzLnN0cnN0YXJ0XSk7CiAgICAgICAgICAgIHMubG9va2FoZWFkLS07CiAgICAgICAgICAgIHMuc3Ryc3RhcnQrKzsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChiZmx1c2gpIHsKICAgICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCBmYWxzZSk7CiAgICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBzLmluc2VydCA9IDA7CiAgICAgICAgaWYgKGZsdXNoID09PSBaX0ZJTklTSCkgewogICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCB0cnVlKTsKICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgIHJldHVybiBCU19GSU5JU0hfU1RBUlRFRDsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBCU19GSU5JU0hfRE9ORTsKICAgICAgICB9CiAgICAgICAgaWYgKHMubGFzdF9saXQpIHsKICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgZmFsc2UpOwogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIEJTX0JMT0NLX0RPTkU7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZGVmbGF0ZV9odWZmKHMsIGZsdXNoKSB7CiAgICAgICAgdmFyIGJmbHVzaDsKICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA9PT0gMCkgewogICAgICAgICAgICBmaWxsX3dpbmRvdyhzKTsKICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkID09PSAwKSB7CiAgICAgICAgICAgICAgaWYgKGZsdXNoID09PSBaX05PX0ZMVVNIKSB7CiAgICAgICAgICAgICAgICByZXR1cm4gQlNfTkVFRF9NT1JFOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgcy5tYXRjaF9sZW5ndGggPSAwOwogICAgICAgICAgYmZsdXNoID0gdHJlZXMuX3RyX3RhbGx5KHMsIDAsIHMud2luZG93W3Muc3Ryc3RhcnRdKTsKICAgICAgICAgIHMubG9va2FoZWFkLS07CiAgICAgICAgICBzLnN0cnN0YXJ0Kys7CiAgICAgICAgICBpZiAoYmZsdXNoKSB7CiAgICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgZmFsc2UpOwogICAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcy5pbnNlcnQgPSAwOwogICAgICAgIGlmIChmbHVzaCA9PT0gWl9GSU5JU0gpIHsKICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgdHJ1ZSk7CiAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICByZXR1cm4gQlNfRklOSVNIX1NUQVJURUQ7CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gQlNfRklOSVNIX0RPTkU7CiAgICAgICAgfQogICAgICAgIGlmIChzLmxhc3RfbGl0KSB7CiAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIGZhbHNlKTsKICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiBCU19CTE9DS19ET05FOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIENvbmZpZyhnb29kX2xlbmd0aCwgbWF4X2xhenksIG5pY2VfbGVuZ3RoLCBtYXhfY2hhaW4sIGZ1bmMpIHsKICAgICAgICB0aGlzLmdvb2RfbGVuZ3RoID0gZ29vZF9sZW5ndGg7CiAgICAgICAgdGhpcy5tYXhfbGF6eSA9IG1heF9sYXp5OwogICAgICAgIHRoaXMubmljZV9sZW5ndGggPSBuaWNlX2xlbmd0aDsKICAgICAgICB0aGlzLm1heF9jaGFpbiA9IG1heF9jaGFpbjsKICAgICAgICB0aGlzLmZ1bmMgPSBmdW5jOwog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bcy5sZXZlbF0ubmljZV9sZW5ndGg7CiAgICAgICAgcy5tYXhfY2hhaW5fbGVuZ3RoID0gY29uZmlndXJhdGlvbl90YWJsZVtzLmxldmVsXS5tYXhfY2hhaW47CiAgICAgICAgcy5zdHJzdGFydCA9IDA7CiAgICAgICAgcy5ibG9ja19zdGFydCA9IDA7CiAgICAgICAgcy5sb29rYWhlYWQgPSAwOwogICAgICAgIHMuaW5zZXJ0ID0gMDsKICAgICAgICBzLm1hdGNoX2xlbmd0aCA9IHMucHJldl9sZW5ndGggPSBNSU5fTUFUQ0ggLSAxOwogICAgICAgIHMubWF0Y2hfYXZhaWxhYmxlID0gMDsKICAgICAgICBzLmluc19oID0gMDsKICAgICAgfQogICAgICBmdW5jdGlvbiBEZWZsYXRlU3RhdGUoKSB7CiAgICAgICAgdGhpcy5zdHJtID0gbnVsbDsKICAgICAgICB0aGlzLnN0YXR1cyA9IDA7CiAgICAgICAgdGhpcy5wZW5kaW5nX2J1ZiA9IG51bGw7CiAgICAgICAgdGhpcy5wZW5kaW5nX2J1Zl9zaXplID0gMDsKICAgICAgICB0aGlzLnBlbmRpbmdfb3V0ID0gMDsKICAgICAgICB0aGlzLnBlbmRpbmcgPSAwOwogICAgICAgIHRoaXMud3JhcCA9IDA7CiAgICAgICAgdGhpcy5nemhlYWQgPSBudWxsOwogICAgICAgIHRoaXMuZ3ppbmRleCA9IDA7CiAgICAgICAgdGhpcy5tZXRob2QgPSBaX0RFRkxBVEVEOwogICAgICAgIHRoaXMubGFzdF9mbHVzaCA9IC0xOwogICAgICAgIHRoaXMud19zaXplID0gMDsKICAgICAgICB0aGlzLndfYml0cyA9IDA7CiAgICAgICAgdGhpcy53X21hc2sgPSAwOwogICAgICAgIHRoaXMud2luZG93ID0gbnVsbDsKICAgICAgICB0aGlzLndpbmRvd19zaXplID0gMDsKICAgICAgICB0aGlzLnByZXYgPSBudWxsOwogICAgICAgIHRoaXMuaGVhZCA9IG51bGw7CiAgICAgICAgdGhpcy5pbn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gICAgICAgdGhpcy5kX2Rlc2MgPSBudWxsOwogICAgICAgIHRoaXMuYmxfZGVzYyA9IG51bGw7CiAgICAgICAgdGhpcy5ibF9jb3VudCA9IG5ldyB1dGlscy5CdWYxNihNQVhfQklUUyArIDEpOwogICAgICAgIHRoaXMuaGVhcCA9IG5ldyB1dGlscy5CdWYxNigyICogTF9DT0RFUyArIDEpOwogICAgICAgIHplcm8odGhpcy5oZWFwKTsKICAgICAgICB0aGlzLmhlYXBfbGVuID0gMDsKICAgICAgICB0aGlzLmhlYXBfbWF4ID0gMDsKICAgICAgICB0aGlzLmRlcHRoID0gbmV3IHV0aWxzLkJ1ZjE2KDIgKiBMX0NPREVTICsgMSk7CiAgICAgICAgemVybyh0aGlzLmRlcHRoKTsKICAgICAgICB0aGlzLmxfYnVmID0gMDsKICAgICAgICB0aGlzLmxpdF9idWZzaXplID0gMDsKICAgICAgICB0aGlzLmxhc3RfbGl0ID0gMDsKICAgICAgICB0aGlzLmRfYnVmID0gMDsKICAgICAgICB0aGlzLm9wdF9sZW4gPSAwOwogICAgICAgIHRoaXMuc3RhdGljX2xlbiA9IDA7CiAgICAgICAgdGhpcy5tYXRjaGVzID0gMDsKICAgICAgICB0aGlzLmluc2VydCA9IDA7CiAgICAgICAgdGhpcy5iaV9idWYgPSAwOwogICAgICAgIHRoaXMuYmlfdmFsaWQgPSAwOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGRlZmxhdGVSZXNldEtlZXAoc3RybSkgewogICAgICAgIHZhciBzOwogICAgICAgIGlmICghc3RybSB8fCAhc3RybS5zdGF0ZSkgewogICAgICAgICAgcmV0dXJuIGVycihzdHJtLCBaX1NUUkVBTV9FUlJPUik7CiAgICAgICAgfQogICAgICAgIHN0cm0udG90YWxfaW4gPSBzdHJtLnRvdGFsX291dCA9IDA7CiAgICAgICAgc3RybS5kYXRhX3R5cGUgPSBaX1VOS05PV047CiAgICAgICAgcyA9IHN0cm0uc3RhdGU7CiAgICAgICAgcy5wZW5kaW5nID0gMDsKICAgICAgICBzLnBlbmRpbmdfb3V0ID0gMDsKICAgICAgICBpZiAocy53cmFwIDwgMCkgewogICAgICAgICAgcy53cmFwID0gLXMud3JhcDsKICAgICAgICB9CiAgICAgICAgcy5zdGF0dXMgPSBzLndyYXAgPyBJTklUX1NUQVRFIDogQlVTWV9TVEFURTsKICAgICAgICBzdHJtLmFkbGVyID0gcy53cmFwID09PSAyID8gMCA6IDE7CiAgICAgICAgcy5sYXN0X2ZsdXNoID0gWl9OT19GTFVTSDsKICAgICAgICB0cmVlcy5fdHJfaW5pdChzKTsKICAgICAgICByZXR1cm4gWl9PSzsKICAgICAgfQogICAgICBmdW5jdGlvbiBkZWZsYXRlUmVzZXQoc3RybSkgewogICAgICAgIHZhciByZXQgPSBkZWZsYXRlUmVzZXRLZWVwKHN0cm0pOwogICAgICAgIGlmIChyZXQgPT09IFpfT0spIHsKICAgICAgICAgIGxtX2luaXQoc3RybS5zdGF0ZSk7CiAgICAgICAgfQogICAgICAgIHJldHVybiByZXQ7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZGVmbGF0ZVNldEhlYWRlcihzdHJtLCBoZWFkKSB7CiAgICAgICAgaWYgKCFzdHJtIHx8ICFzdHJtLnN0YXRlKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIGlmIChzdHJtLnN0YXRlLndyYXAgIT09IDIpIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgc3RybS5zdGF0ZS5nemhlYWQgPSBoZWFkOwogICAgICAgIHJldHVybiBaX09LOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGRlZmxhdGVJbml0MihzdHJtLCBsZXZlbCwgbWV0aG9kLCB3aW5kb3dCaXRzLCBtZW1MZXZlbCwgc3RyYXRlZ3kpIHsKICAgICAgICBpZiAoIXN0cm0pIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgdmFyIHdyYXAgPSAxOwogICAgICAgIGlmIChsZXZlbCA9PT0gWl9ERUZBVUxUX0NPTVBSRVNTSU9OKSB7CiAgICAgICAgICBsZXZlbCA9IDY7CiAgICAgICAgfQogICAgICAgIGlmICh3aW5kb3dCaXRzIDwgMCkgewogICAgICAgICAgd3JhcCA9IDA7CiAgICAgICAgICB3aW5kb3dCaXRzID0gLXdpbmRvd0JpdHM7CiAgICAgICAgfSBlbHNlIGlmICh3aW5kb3dCaXRzID4gMTUpIHsKICAgICAgICAgIHdyYXAgPSAyOwogICAgICAgICAgd2luZG93Qml0cyAtPSAxNjsKICAgICAgICB9CiAgICAgICAgaWYgKG1lbUxldmVsIDwgMSB8fCBtZW1MZXZlbCA+IE1BWF9NRU1fTEVWRUwgfHwgbWV0aG9kICE9PSBaX0RFRkxBVEVEIHx8IHdpbmRvd0JpdHMgPCA4IHx8IHdpbmRvd0JpdHMgPiAxNSB8fCBsZXZlbCA8IDAgfHwgbGV2ZWwgPiA5IHx8IHN0cmF0ZWd5IDwgMCB8fCBzdHJhdGVneSA+IFpfRklYRUQpIHsKICAgICAgICAgIHJldHVybiBlcnIoc3RybSwgWl9TVFJFQU1fRVJST1IpOwogICAgICAgIH0KICAgICAgICBpZiAod2luZG93Qml0cyA9PT0gOCkgewogICAgICAgICAgd2luZG93Qml0cyA9IDk7CiAgICAgICAgfQogICAgICAgIHZhciBzID0gbmV3IERlZmxhdGVTdGF0ZSgpOwogICAgICAgIHN0cm0uc3RhdGUgPSBzOwogICAgICAgIHMuc3RybSA9IHN0cm07CiAgICAgICAgcy53cmFwID0gd3JhcDsKICAgICAgICBzLmd6aGVhZCA9IG51bGw7CiAgICAgICAgcy53X2JpdHMgPSB3aW5kb3dCaXRzOwogICAgICAgIHMud19zaXplID0gMSA8PCBzLndfYml0czsKICAgICAgICBzLndfbWFzayA9IHMud19zaXplIC0gMTsKICAgICAgICBzLmhhc2hfYml0cyA9IG1lb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dGUoc3RybSwgZmx1c2gpIHsKICAgICAgICB2YXIgb2xkX2ZsdXNoLCBzOwogICAgICAgIHZhciBiZWcsIHZhbDsKICAgICAgICBpZiAoIXN0cm0gfHwgIXN0cm0uc3RhdGUgfHwgZmx1c2ggPiBaX0JMT0NLIHx8IGZsdXNoIDwgMCkgewogICAgICAgICAgcmV0dXJuIHN0cm0gPyBlcnIoc3RybSwgWl9TVFJFQU1fRVJST1IpIDogWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIHMgPSBzdHJtLnN0YXRlOwogICAgICAgIGlmICghc3RybS5vdXRwdXQgfHwgIXN0cm0uaW5wdXQgJiYgc3RybS5hdmFpbF9pbiAhPT0gMCB8fCBzLnN0YXR1cyA9PT0gRklOSVNIX1NUQVRFICYmIGZsdXNoICE9PSBaX0ZJTklTSCkgewogICAgICAgICAgcmV0dXJuIGVycihzdHJtLCBzdHJtLmF2YWlsX291dCA9PT0gMCA/IFpfQlVGX0VSUk9SIDogWl9TVFJFQU1fRVJST1IpOwogICAgICAgIH0KICAgICAgICBzLnN0cm0gPSBzdHJtOwogICAgICAgIG9sZF9mbHVzaCA9IHMubGFzdF9mbHVzaDsKICAgICAgICBzLmxhc3RfZmx1c2ggPSBmbHVzaDsKICAgICAgICBpZiAocy5zdGF0dXMgPT09IElOSVRfU1RBVEUpIHsKICAgICAgICAgIGlmIChzLndyYXAgPT09IDIpIHsKICAgICAgICAgICAgc3RybS5hZGxlciA9IDA7CiAgICAgICAgICAgIHB1dF9ieXRlKHMsIDMxKTsKICAgICAgICAgICAgcHV0X2J5dGUocywgMTM5KTsKICAgICAgICAgICAgcHV0X2J5dGUocywgOCk7CiAgICAgICAgICAgIGlmICghcy5nemhlYWQpIHsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCAwKTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCAwKTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCAwKTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCAwKTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCAwKTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCBzLmxldmVsID09PSA5ID8gMiA6IHMuc3RyYXRlZ3kgPj0gWl9IVUZGTUFOX09OTFkgfHwgcy5sZXZlbCA8IDIgPyA0IDogMCk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgT1NfQ09ERSk7CiAgICAgICAgICAgICAgcy5zdGF0dXMgPSBCVVNZX1NUQVRFOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHB1dF9ieXRlKHMsIChzLmd6aGVhZC50ZXh0ID8gMSA6IDApICsgKHMuZ3poZWFkLmhjcmMgPyAyIDogMCkgKyAoIXMuZ3poZWFkLmV4dHJhID8gMCA6IDQpICsgKCFzLmd6aGVhZC5uYW1lID8gMCA6IDgpICsgKCFzLmd6aGVhZC5jb21tZW50ID8gMCA6IDE2KSk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgcy5nemhlYWQudGltZSAmIDI1NSk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgcy5nemhlYWQudGltZSA+PiA4ICYgMjU1KTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCBzLmd6aGVhZC50aW1lID4+IDE2ICYgMjU1KTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCBzLmd6aGVhZC50aW1lID4+IDI0ICYgMjU1KTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCBzLmxldmVsID09PSA5ID8gMiA6IHMuc3RyYXRlZ3kgPj0gWl9IVUZGTUFOX09OTFkgfHwgcy5sZXZlbCA8IDIgPyA0IDogMCk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgcy5nemhlYWQub3MgJiAyNTUpOwogICAgICAgICAgICAgIGlmIChzLmd6aGVhZC5leHRyYSAmJiBzLmd6aGVhZC5leHRyYS5sZW5ndGgpIHsKICAgICAgICAgICAgICAgIHB1dF9ieXRlKHMsIHMuZ3poZWFkLmV4dHJhLmxlbmd0aCAmIDI1NSk7CiAgICAgICAgICAgICAgICBwdXRfYnl0ZShzLCBzLmd6aGVhZC5leHRyYS5sZW5ndGggPj4gOCAmIDI1NSk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGlmIChzLmd6aGVhZC5oY3JjKSB7CiAgICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gY3JjMzIyKHN0cm0uYWRsZXIsIHMucGVuZGluZ19idWYsIHMucGVuZGluZywgMCk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIHMuZ3ppbmRleCA9IDA7CiAgICAgICAgICAgICAgcy5zdGF0dXMgPSBFWFRSQV9TVEFURTsKICAgICAgICAgICAgfQogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgdmFyIGhlYWRlciA9IFpfREVGTEFURUQgKyAocy53X2JpdHMgLSA4IDw8IDQpIDw8IDg7CiAgICAgICAgICAgIHZhciBsZXZlbF9mbGFncyA9IC0xOwogICAgICAgICAgICBpZiAocy5zdHJhdGVneSA+PSBaX0hVRkZNQU5fT05MWSB8fCBzLmxldmVsIDwgMikgewogICAgICAgICAgICAgIGxldmVsX2ZsYWdzID0gMDsKICAgICAgICAgICAgfSBlbHNlIGlmIChzLmxldmVsIDwgNikgewogICAgICAgICAgICAgIGxldmVsX2ZsYWdzID0gMTsKICAgICAgICAgICAgfSBlbHNlIGlmIChzLmxldmVsID09PSA2KSB7CiAgICAgICAgICAgICAgbGV2ZWxfZmxhZ3MgPSAyOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIGxldmVsX2ZsYWdzID0gMzsKICAgICAgICAgICAgfQogICAgICAgICAgICBoZWFkZXIgfD0gbGV2ZWxfZmxhZ3MgPDwgNjsKICAgICAgICAgICAgaWYgKHMuc3Ryc3RhcnQgIT09IDApIHsKICAgICAgICAgICAgICBoZWFkZXIgfD0gUFJFU0VUX0RJQ1Q7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaGVhZGVyICs9IDMxIC0gaGVhZGVyICUgMzE7CiAgICAgICAgICAgIHMuc3RhdHVzID0gQlVTWV9TVEFURTsKICAgICAgICAgICAgcHV0U2hvcnRNU0IocywgaGVhZGVyKTsKICAgICAgICAgICAgaWYgKHMuc3Ryc3RhcnQgIT09IDApIHsKICAgICAgICAgICAgICBwdXRTaG9ydE1TQihzLCBzdHJtLmFkbGVyID4+PiAxNik7CiAgICAgICAgICAgICAgcHV0U2hvcnRNU0Iocywgc3RybS5hZGxlciAmIDY1NTM1KTsKICAgICAgICAgICAgfQogICAgICAgICAgICBzdHJtLmFkbGVyID0gMTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKHMuc3RhdHVzID09PSBFWFRSQV9TVEFURSkgewogICAgICAgICAgaWYgKHMuZ3poZWFkLmV4dHJhKSB7CiAgICAgICAgICAgIGJlZyA9IHMucGVuZGluZzsKICAgICAgICAgICAgd2hpbGUgKHMuZ3ppbmRleCA8IChzLmd6aGVhZC5leHRyYS5sZW5ndGggJiA2NTUzNSkpIHsKICAgICAgICAgICAgICBpZiAocy5wZW5kaW5nID09PSBzLnBlbmRpbmdfYnVmX3NpemUpIHsKICAgICAgICAgICAgICAgIGlmIChzLmd6aGVhZC5oY3JjICYmIHMucGVuZGluZyA+IGJlZykgewogICAgICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gY3JjMzIyKHN0cm0uYWRsZXIsIHMucGVuZGluZ19idWYsIHMucGVuZGluZyAtIGJlZywgYmVnKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGZsdXNoX3BlbmRpbmcoc3RybSk7CiAgICAgICAgICAgICAgICBiZWcgPSBzLnBlbmRpbmc7CiAgICAgICAgICAgICAgICBpZiAocy5wZW5kaW5nID09PSBzLnBlbmRpbmdfYnVmX3NpemUpIHsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIHB1dF9ieXRlKHMsIHMuZ3poZWFkLmV4dHJhW3MuZ3ppbmRleF0gJiAyNTUpOwogICAgICAgICAgICAgIHMuZ3ppbmRleCsrOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzLmd6aGVhZC5oY3JjICYmIHMucGVuZGluZyA+IGJlZykgewogICAgICAgICAgICAgIHN0cm0uYWRsZXIgPSBjcmMzMjIoc3RybS5hZGxlciwgcy5wZW5kaW5nX2J1Ziwgcy5wZW5kaW5nIC0gYmVnLCBiZWcpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzLmd6aW5kZXggPT09IHMuZ3poZWFkLmV4dHJhLmxlbmd0aCkgewogICAgICAgICAgICAgIHMuZ3ppbmRleCA9IDA7CiAgICAgICAgICAgICAgcy5zdGF0dXMgPSBOQU1FX1NUQVRFOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBzLnN0YXR1cyA9IE5BTUVfU1RBVEU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChzLnN0YXR1cyA9PT0gTkFNRV9TVEFURSkgewogICAgICAgICAgaWYgKHMuZ3poZWFkLm5hbWUpIHsKICAgICAgICAgICAgYmVnID0gcy5wZW5kaW5nOwogICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgaWYgKHMucGVuZGluZyA9PT0gcy5wZW5kaW5nX2J1Zl9zaXplKSB7CiAgICAgICAgICAgICAgICBpZiAocy5nemhlYWQuaGNyYyAmJiBzLnBlbmRpbmcgPiBiZWcpIHsKICAgICAgICAgICAgICAgICAgc3RybS5hZGxlciA9IGNyYzMyMihzdHJtLmFkbGVyLCBzLnBlbmRpbmdfYnVmLCBzLnBlbmRpbmcgLSBiZWcsIGJlZyk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBmbHVzaF9wZW5kaW5nKHN0cm0pOwogICAgICAgICAgICAgICAgYmVnID0gcy5wZW5kaW5nOwogICAgICAgICAgICAgICAgaWYgKHMucGVuZGluZyA9PT0gcy5wZW5kaW5nX2J1Zl9zaXplKSB7CiAgICAgICAgICAgICAgICAgIHZhbCA9IDE7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBpZiAocy5nemluZGV4IDwgcy5nemhlYWQubmFtZS5sZW5ndGgpIHsKICAgICAgICAgICAgICAgIHZhbCA9IHMuZ3poZWFkLm5hbWUuY2hhckNvZGVBdChzLmd6aW5kZXgrKykgJiAyNTU7CiAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIHZhbCA9IDA7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIHB1dF9ieXRlKHMsIHZhbCk7CiAgICAgICAgICAgIH0gd2hpbGUgKHZhbCAhPT0gMCk7CiAgICAgICAgICAgIGlmIChzLmd6aGVhZC5oY3JjICYmIHMucGVuZGluZyA+IGJlZykgewogICAgICAgICAgICAgIHN0cm0uYWRsZXIgPSBjcmMzMjIoc3RybS5hZGxlciwgcy5wZW5kaW5nX2J1Ziwgcy5wZW5kaW5nIC0gYmVnLCBiZWcpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmICh2YWwgPT09IDApIHsKICAgICAgICAgICAgICBzLmd6aW5kZXggPSAwOwogICAgICAgICAgICAgIHMuc3RhdHVzID0gQ09NTUVOVF9TVEFURTsKICAgICAgICAgICAgfQogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcy5zdGF0dXMgPSBDT01NRU5UX1NUQVRFOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAocy5zdGF0dXMgPT09IENPTU1FTlRfU1RBVEUpIHsKICAgICAgICAgIGlmIChzLmd6aGVhZC5jb21tZW50KSB7CiAgICAgICAgICAgIGJlZyA9IHMucGVuZGluZzsKICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgIGlmIChzLnBlbmRpbmcgPT09IHMucGVuZGluZ19idWZfc2l6ZSkgewogICAgICAgICAgICAgICAgaWYgKHMuZ3poZWFkLmhjcmMgJiYgcy5wZW5kaW5nID4gYmVnKSB7CiAgICAgICAgICAgICAgICAgIHN0cm0uYWRsZXIgPSBjcmMzMjIoc3RybS5hZGxlciwgcy5wZW5kaW5nX2J1Ziwgcy5wZW5kaW5nIC0gYmVnLCBiZWcpOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgZmx1c2hfcGVuZGluZyhzdHJtKTsKICAgICAgICAgICAgICAgIGJlZyA9IHMucGVuZGluZzsKICAgICAgICAgICAgICAgIGlmIChzLnBlbmRpbmcgPT09IHMucGVuZGluZ19idWZfc2l6ZSkgewogICAgICAgICAgICAgICAgICB2YWwgPSAxOwogICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgaWYgKHMuZ3ppbmRleCA8IHMuZ3poZWFkLmNvbW1lbnQubGVuZ3RoKSB7CiAgICAgICAgICAgICAgICB2YWwgPSBzLmd6aGVhZC5jb21tZW50LmNoYXJDb2RlQXQocy5nemluZGV4KyspICYgMjU1OwogICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICB2YWwgPSAwOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBwdXRfYnl0ZShzLCB2YWwpOwogICAgICAgICAgICB9IHdoaWxlICh2YWwgIT09IDApOwogICAgICAgICAgICBpZiAocy5nemhlYWQuaGNyYyAmJiBzLnBlbmRpbmcgPiBiZWcpIHsKICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gY3JjMzIyKHN0cm0uYWRsZXIsIHMucGVuZGluZ19idWYsIHMucGVuZGluZyAtIGJlZywgYmVnKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAodmFsID09PSAwKSB7CiAgICAgICAgICAgICAgcy5zdGF0dXMgPSBIQ1JDX1NUQVRFOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBzLnN0YXR1cyA9IEhDUkNfU1RBVEU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChzLnN0YXR1cyA9PT0gSENSQ19TVEFURSkgewogICAgICAgICAgaWYgKHMuZ3poZWFkLmhjcmMpIHsKICAgICAgICAgICAgaWYgKHMucGVuZGluZyArIDIgPiBzLnBlbmRpbmdfYnVmX3NpemUpIHsKICAgICAgICAgICAgICBmbHVzaF9wZW5kaW5nKHN0cm0pOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzLnBlbmRpbmcgKyAyIDw9IHMucGVuZGluZ19idWZfc2l6ZSkgewogICAgICAgICAgICAgIHB1dF9ieXRlKHMsIHN0cm0uYWRsZXIgJiAyNTUpOwogICAgICAgICAgICAgIHB1dF9ieXRlKHMsIHN0cm0uYWRsZXIgPj4gOCAmIDI1NSk7CiAgICAgICAgICAgICAgc3RybS5hZGxlciA9IDA7CiAgICAgICAgICAgICAgcy5zdGF0dXMgPSBCVVNZX1NUQVRFOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBzLnN0YXR1cyA9IEJVU1lfU1RBVEU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChzLnBlbmRpbmcgIT09IDApIHsKICAgICAgICAgIGZsdXNoX3BlbmRpbmcoc3RybSk7CiAgICAgICAgICBpZiAoc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcy5sYXN0X2ZsdXNoID0gLTE7CiAgICAgICAgICAgIHJldHVybiBaX09LOwogICAgICAgICAgfQogICAgICAgIH0gZWxzZSBpZiAoc3RybS5hdmFpbF9pbiA9PT0gMCAmJiByYW5rKGZsdXNoKSA8PSByYW5rKG9sZF9mbHVzaCkgJiYgZmx1c2ggIT09IFpfRklOSVNIKSB7CiAgICAgICAgICByZXR1cm4gZXJyKHN0cm0sIFpfQlVGX0VSUk9SKTsKICAgICAgICB9CiAgICAgICAgaWYgKHMuc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c2UgaWYgKGZsdXNoICE9PSBaX0JMT0NLKSB7CiAgICAgICAgICAgICAgdHJlZXMuX3RyX3N0b3JlZF9ibG9jayhzLCAwLCAwLCBmYWxzZSk7CiAgICAgICAgICAgICAgaWYgKGZsdXNoID09PSBaX0ZVTExfRkxVU0gpIHsKICAgICAgICAgICAgICAgIHplcm8ocy5oZWFkKTsKICAgICAgICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA9PT0gMCkgewogICAgICAgICAgICAgICAgICBzLnN0cnN0YXJ0ID0gMDsKICAgICAgICAgICAgICAgICAgcy5ibG9ja19zdGFydCA9IDA7CiAgICAgICAgICAgICAgICAgIHMuaW5zZXJ0ID0gMDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZmx1c2hfcGVuZGluZyhzdHJtKTsKICAgICAgICAgICAgaWYgKHN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgICAgcy5sYXN0X2ZsdXNoID0gLTE7CiAgICAgICAgICAgICAgcmV0dXJuIFpfT0s7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKGZsdXNoICE9PSBaX0ZJTklTSCkgewogICAgICAgICAgcmV0dXJuIFpfT0s7CiAgICAgICAgfQogICAgICAgIGlmIChzLndyYXAgPD0gMCkgewogICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VORDsKICAgICAgICB9CiAgICAgICAgaWYgKHMud3JhcCA9PT0gMikgewogICAgICAgICAgcHV0X2J5dGUocywgc3RybS5hZGxlciAmIDI1NSk7CiAgICAgICAgICBwdXRfYnl0ZShzLCBzdHJtLmFkbGVyID4+IDggJiAyNTUpOwogICAgICAgICAgcHV0X2J5dGUocywgc3RybS5hZGxlciA+PiAxNiAmIDI1NSk7CiAgICAgICAgICBwdXRfYnl0ZShzLCBzdHJtLmFkbGVyID4+IDI0ICYgMjU1KTsKICAgICAgICAgIHB1d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9TVFJFQU1fRVJST1IpOwogICAgICAgIH0KICAgICAgICBzdHJtLnN0YXRlID0gbnVsbDsKICAgICAgICByZXR1cm4gc3RhdHVzID09PSBCVVNZX1NUQVRFID8gZXJyKHN0cm0sIFpfREFUQV9FUlJPUikgOiBaX09LOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGRlZmxhdGVTZXREaWN0aW9uYXJ5KHN0cm0sIGRpY3Rpb25hcnkpIHsKICAgICAgICB2YXIgZGljdExlbmd0aCA9IGRpY3Rpb25hcnkubGVuZ3RoOwogICAgICAgIHZhciBzOwogICAgICAgIHZhciBzdHIsIG47CiAgICAgICAgdmFyIHdyYXA7CiAgICAgICAgdmFyIGF2YWlsOwogICAgICAgIHZhciBuZXh0OwogICAgICAgIHZhciBpbnB1dDsKICAgICAgICB2YXIgdG1wRGljdDsKICAgICAgICBpZiAoIXN0cm0gfHwgIXN0cm0uc3RhdGUpIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgcyA9IHN0cm0uc3RhdGU7CiAgICAgICAgd3JhcCA9IHMud3JhcDsKICAgICAgICBpZiAod3JhcCA9PT0gMiB8fCB3cmFwID09PSAxICYmIHMuc3RhdHVzICE9PSBJTklUX1NUQVRFIHx8IHMubG9va2FoZWFkKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIGlmICh3cmFwID09PSAxKSB7CiAgICAgICAgICBzdHJtLmFkbGVyID0gYWRsZXIzMihzdHJtLmFkbGVyLCBkaWN0aW9uYXJ5LCBkaWN0TGVuZ3RoLCAwKTsKICAgICAgICB9CiAgICAgICAgcy53cmFwID0gMDsKICAgICAgICBpZiAoZGljdExlbmd0aCA+PSBzLndfc2l6ZSkgewogICAgICAgICAgaWYgKHdyYXAgPT09IDApIHsKICAgICAgICAgICAgemVybyhzLmhlYWQpOwogICAgICAgICAgICBzLnN0cnN0YXJ0ID0gMDsKICAgICAgICAgICAgcy5ibG9ja19zdGFydCA9IDA7CiAgICAgICAgICAgIHMuaW5zZXJ0ID0gMDsKICAgICAgICAgIH0KICAgICAgICAgIHRtcERpY3QgPSBuZXcgdXRpbHMuQnVmOChzLndfc2l6ZSk7CiAgICAgICAgICB1dGlscy5hcnJheVNldCh0bXBEaWN0LCBkaWN0aW9uYXJ5LCBkaWN0TGVuZ3RoIC0gcy53X3NpemUsIHMud19zaXplLCAwKTsKICAgICAgICAgIGRpY3Rpb25hcnkgPSB0bXBEaWN0OwogICAgICAgICAgZGljdExlbmd0aCA9IHMud19zaXplOwogICAgICAgIH0KICAgICAgICBhdmFpbCA9IHN0cm0uYXZhaWxfaW47CiAgICAgICAgbmV4dCA9IHN0cm0ubmV4dF9pbjsKICAgICAgICBpbnB1dCA9IHN0cm0uaW5wdXQ7CiAgICAgICAgc3RybS5hdmFpbF9pbiA9IGRpY3RMZW5ndGg7CiAgICAgICAgc3RybS5uZXh0X2luID0gMDsKICAgICAgICBzdHJtLmlucHV0ID0gZGljdGlvbmFyeTsKICAgICAgICBmaWxsX3dpbmRvdyhzKTsKICAgICAgICB3aGlsZSAocy5sb29rYWhlYWQgPj0gTUlOX01BVENIKSB7CiAgICAgICAgICBzdHIgPSBzLnN0cnN0YXJ0OwogICAgICAgICAgbiA9IHMubG9va2FoZWFkIC0gKE1JTl9NQVRDSCAtIDEpOwogICAgICAgICAgZG8gewogICAgICAgICAgICBzLmluc19oID0gKHMuaW5zX2ggPDwgcy5oYXNoX3NoaWZ0IF4gcy53aW5kb3dbc3RyICsgTUlOX01BVENIIC0gMV0pICYgcy5oYXNoX21hc2s7CiAgICAgICAgICAgIHMucHJldltzdHIgJiBzLndfbWFza10gPSBzLmhlYWRbcy5pbnNfaF07CiAgICAgICAgICAgIHMuaGVhZFtzLmluc19oXSA9IHN0cjsKICAgICAgICAgICAgc3RyKys7CiAgICAgICAgICB9IHdoaWxlICgtLW4pOwogICAgICAgICAgcy5zdHJzdGFydCA9IHN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KChjMiAmIDY0NTEyKSA9PT0gNTYzMjApIHsKICAgICAgICAgICAgICBjID0gNjU1MzYgKyAoYyAtIDU1Mjk2IDw8IDEwKSArIChjMiAtIDU2MzIwKTsKICAgICAgICAgICAgICBtX3BvcysrOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoYyA8IDEyOCkgewogICAgICAgICAgICBidWZbaSsrXSA9IGM7CiAgICAgICAgICB9IGVsc2UgaWYgKGMgPCAyMDQ4KSB7CiAgICAgICAgICAgIGJ1ZltpKytdID0gMTkyIHwgYyA+Pj4gNjsKICAgICAgICAgICAgYnVmW2krK10gPSAxMjggfCBjICYgNjM7CiAgICAgICAgICB9IGVsc2UgaWYgKGMgPCA2NTUzNikgewogICAgICAgICAgICBidWZbaSsrXSA9IDIyNCB8IGMgPj4+IDEyOwogICAgICAgICAgICBidWZbaSsrXSA9IDEyOCB8IGMgPj4+IDYgJiA2MzsKICAgICAgICAgICAgYnVmW2krK10gPSAxMjggfCBjICYgNjM7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBidWZbaSsrXSA9IDI0MCB8IGMgPj4+IDE4OwogICAgICAgICAgICBidWZbaSsrXSA9IDEyOCB8IGMgPj4+IDEyICYgNjM7CiAgICAgICAgICAgIGJ1ZltpKytdID0gMTI4IHwgYyA+Pj4gNiAmIDYzOwogICAgICAgICAgICBidWZbaSsrXSA9IDEyOCB8IGMgJiA2MzsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIGJ1ZjsKICAgICAgfTsKICAgICAgZnVuY3Rpb24gYnVmMmJpbnN0cmluZyhidWYsIGxlbikgewogICAgICAgIGlmIChsZW4gPCA2NTUzNCkgewogICAgICAgICAgaWYgKGJ1Zi5zdWJhcnJheSAmJiBTVFJfQVBQTFlfVUlBX09LIHx8ICFidWYuc3ViYXJyYXkgJiYgU1RSX0FQUExZX09LKSB7CiAgICAgICAgICAgIHJldHVybiBTdHJpbmcuZnJvbUNoYXJDb2RlLmFwcGx5KG51bGwsIHV0aWxzLnNocmlua0J1ZihidWYsIGxlbikpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICB2YXIgcmVzdWx0ID0gIiI7CiAgICAgICAgZm9yICh2YXIgaSA9IDA7IGkgPCBsZW47IGkrKykgewogICAgICAgICAgcmVzdWx0ICs9IFN0cmluZy5mcm9tQ2hhckNvZGUoYnVmW2ldKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHJlc3VsdDsKICAgICAgfQogICAgICBleHBvcnRzLmJ1ZjJiaW5zdHJpbmcgPSBmdW5jdGlvbihidWYpIHsKICAgICAgICByZXR1cm4gYnVmMmJpbnN0cmluZyhidWYsIGJ1Zi5sZW5ndGgpOwogICAgICB9OwogICAgICBleHBvcnRzLmJpbnN0cmluZzJidWYgPSBmdW5jdGlvbihzdHIpIHsKICAgICAgICB2YXIgYnVmID0gbmV3IHV0aWxzLkJ1Zjgoc3RyLmxlbmd0aCk7CiAgICAgICAgZm9yICh2YXIgaSA9IDAsIGxlbiA9IGJ1Zi5sZW5ndGg7IGkgPCBsZW47IGkrKykgewogICAgICAgICAgYnVmW2ldID0gc3RyLmNoYXJDb2RlQXQoaSk7CiAgICAgICAgfQogICAgICAgIHJldHVybiBidWY7CiAgICAgIH07CiAgICAgIGV4cG9ydHMuYnVmMnN0cmluZyA9IGZ1bmN0aW9uKGJ1ZiwgbWF4KSB7CiAgICAgICAgdmFyIGksIG91dCwgYywgY19sZW47CiAgICAgICAgdmFyIGxlbiA9IG1heCB8fCBidWYubGVuZ3RoOwogICAgICAgIHZhciB1dGYxNmJ1ZiA9IG5ldyBBcnJheShsZW4gKiAyKTsKICAgICAgICBmb3IgKG91dCA9IDAsIGkgPSAwOyBpIDwgbGVuOyApIHsKICAgICAgICAgIGMgPSBidWZbaSsrXTsKICAgICAgICAgIGlmIChjIDwgMTI4KSB7CiAgICAgICAgICAgIHV0ZjE2YnVmW291dCsrXSA9IGM7CiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgfQogICAgICAgICAgY19sZW4gPSBfdXRmOGxlbltjXTsKICAgICAgICAgIGlmIChjX2xlbiA+IDQpIHsKICAgICAgICAgICAgdXRmMTZidWZbb3V0KytdID0gNjU1MzM7CiAgICAgICAgICAgIGkgKz0gY19sZW4gLSAxOwogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgIH0KICAgICAgICAgIGMgJj0gY19sZW4gPT09IDIgPyAzMSA6IGNfbGVuID09PSAzID8gMTUgOiA3OwogICAgICAgICAgd2hpbGUgKGNfbGVuID4gMSAmJiBpIDwgbGVuKSB7CiAgICAgICAgICAgIGMgPSBjIDw8IDYgfCBidWZbaSsrXSAmIDYzOwogICAgICAgICAgICBjX2xlbi0tOwogICAgICAgICAgfQogICAgICAgICAgaWYgKGNfbGVuID4gMSkgewogICAgICAgICAgICB1dGYxNmJ1ZltvdXQrK10gPSA2NTUzMzsKICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoYyA8IDY1NTM2KSB7CiAgICAgICAgICAgIHV0ZjE2YnVmW291dCsrXSA9IGM7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBjIC09IDY1NTM2OwogICAgICAgICAgICB1dGYxNmJ1ZltvdXQrK10gPSA1NTI5NiB8IGMgPj4gMTAgJiAxMDIzOwogICAgICAgICAgICB1dGYxNmJ1ZltvdXQrK10gPSA1NjMyMCB8IGMgJiAxMDIzOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gYnVmMmJpbnN0cmluZyh1dGYxNmJ1Ziwgb3V0KTsKICAgICAgfTsKICAgICAgZXhwb3J0cy51dGY4Ym9yZGVyID0gZnVuY3Rpb24oYnVmLCBtYXgpIHsKICAgICAgICB2YXIgcG9zOwogICAgICAgIG1heCA9IG1heCB8fCBidWYubGVuZ3RoOwogICAgICAgIGlmIChtYXggPiBidWYubGVuZ3RoKSB7CiAgICAgICAgICBtYXggPSBidWYubGVuZ3RoOwogICAgICAgIH0KICAgICAgICBwb3MgPSBtYXggLSAxOwogICAgICAgIHdoaWxlIChwb3MgPj0gMCAmJiAoYnVmW3Bvc10gJiAxOTIpID09PSAxMjgpIHsKICAgICAgICAgIHBvcy0tOwogICAgICAgIH0KICAgICAgICBpZiAocG9zIDwgMCkgewogICAgICAgICAgcmV0dXJuIG1heDsKICAgICAgICB9CiAgICAgICAgaWYgKHBvcyA9PT0gMCkgewogICAgICAgICAgcmV0dXJuIG1heDsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHBvcyArIF91dGY4bGVuW2J1Zltwb3NdXSA+IG1heCA/IHBvcyA6IG1heDsKICAgICAgfTsKICAgIH0KICB9KTsKCiAgLy8gbm9kZV9tb2R1bGVzLy5wbnBtL3Bha29AMS4wLjExL25vZGVfbW9kdWxlcy9wYWtvL2xpYi96bGliL3pzdHJlYW0uanMKICB2YXIgcmVxdWlyZV96c3RyZWFtID0gX19jb21tb25KUyh7CiAgICAibm9kZV9tb2R1bGVzLy5wbnBtL3Bha29AMS4wLjExL25vZGVfbW9kdWxlcy9wYWtvL2xpYi96bGliL3pzdHJlYW0uanMiKGV4cG9ydHMsIG1vZHVsZSkgewogICAgICBpbml0X2J1ZmZlcl9zaGltKCk7CiAgICAgICJ1c2Ugc3RyaWN0IjsKICAgICAgZnVuY3Rpb24gWlN0cmVhbSgpIHsKICAgICAgICB0aGlzLmlucHV0ID0gbnVsbDsKICAgICAgICB0aGlzLm5leHRfaW4gPSAwOwogICAgICAgIHRoaXMuYXZhaWxfaW4gPSAwOwogICAgICAgIHRoaXMudG90YWxfaW4gPSAwOwogICAgICAgIHRoaXMub3V0cHV0ID0gbnVsbDsKICAgICAgICB0aGlzLm5leHRfb3V0ID0gMDsKICAgICAgICB0aGlzLmF2YWlsX291dCA9IDA7CiAgICAgICAgdGhpcy50b3RhbF9vdXQgPSAwOwogICAgICAgIHRoaXMubXNnID0gIiI7CiAgICAgICAgdGhpcy5zdGF0ZSA9I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RlKG9wdGlvbnMpIHsKICAgICAgICBpZiAoISh0aGlzIGluc3RhbmNlb2YgRGVmbGF0ZSkpCiAgICAgICAgICByZXR1cm4gbmV3IERlZmxhdGUob3B0aW9ucyk7CiAgICAgICAgdGhpcy5vcHRpb25zID0gdXRpbHMuYXNzaWduKHsKICAgICAgICAgIGxldmVsOiBaX0RFRkFVTFRfQ09NUFJFU1NJT04sCiAgICAgICAgICBtZXRob2Q6IFpfREVGTEFURUQsCiAgICAgICAgICBjaHVua1NpemU6IDE2Mzg0LAogICAgICAgICAgd2luZG93Qml0czogMTUsCiAgICAgICAgICBtZW1MZXZlbDogOCwKICAgICAgICAgIHN0cmF0ZWd5OiBaX0RFRkFVTFRfU1RSQVRFR1ksCiAgICAgICAgICB0bzogIiIKICAgICAgICB9LCBvcHRpb25zIHx8IHt9KTsKICAgICAgICB2YXIgb3B0ID0gdGhpcy5vcHRpb25zOwogICAgICAgIGlmIChvcHQucmF3ICYmIG9wdC53aW5kb3dCaXRzID4gMCkgewogICAgICAgICAgb3B0LndpbmRvd0JpdHMgPSAtb3B0LndpbmRvd0JpdHM7CiAgICAgICAgfSBlbHNlIGlmIChvcHQuZ3ppcCAmJiBvcHQud2luZG93Qml0cyA+IDAgJiYgb3B0LndpbmRvd0JpdHMgPCAxNikgewogICAgICAgICAgb3B0LndpbmRvd0JpdHMgKz0gMTY7CiAgICAgICAgfQogICAgICAgIHRoaXMuZXJyID0gMDsKICAgICAgICB0aGlzLm1zZyA9ICIiOwogICAgICAgIHRoaXMuZW5kZWQgPSBmYWxzZTsKICAgICAgICB0aGlzLmNodW5rcyA9IFtdOwogICAgICAgIHRoaXMuc3RybSA9IG5ldyBaU3RyZWFtKCk7CiAgICAgICAgdGhpcy5zdHJtLmF2YWlsX291dCA9IDA7CiAgICAgICAgdmFyIHN0YXR1cyA9IHpsaWJfZGVmbGF0ZS5kZWZsYXRlSW5pdDIodGhpcy5zdHJtLCBvcHQubGV2ZWwsIG9wdC5tZXRob2QsIG9wdC53aW5kb3dCaXRzLCBvcHQubWVtTGV2ZWwsIG9wdC5zdHJhdGVneSk7CiAgICAgICAgaWYgKHN0YXR1cyAhPT0gWl9PSykgewogICAgICAgICAgdGhyb3cgbmV3IEVycm9yKG1zZ1tzdGF0dXNdKTsKICAgICAgICB9CiAgICAgICAgaWYgKG9wdC5oZWFkZXIpIHsKICAgICAgICAgIHpsaWJfZGVmbGF0ZS5kZWZsYXRlU2V0SGVhZGVyKHRoaXMuc3RybSwgb3B0LmhlYWRlcik7CiAgICAgICAgfQogICAgICAgIGlmIChvcHQuZGljdGlvbmFyeSkgewogICAgICAgICAgdmFyIGRpY3Q7CiAgICAgICAgICBpZiAodHlwZW9mIG9wdC5kaWN0aW9uYXJ5ID09PSAic3RyaW5nIikgewogICAgICAgICAgICBkaWN0ID0gc3RyaW5ncy5zdHJpbmcyYnVmKG9wdC5kaWN0aW9uYXJ5KTsKICAgICAgICAgIH0gZWxzZSBpZiAodG9TdHJpbmcuY2FsbChvcHQuZGljdGlvbmFyeSkgPT09ICJbb2JqZWN0IEFycmF5QnVmZmVyXSIpIHsKICAgICAgICAgICAgZGljdCA9IG5ldyBVaW50OEFycmF5KG9wdC5kaWN0aW9uYXJ5KTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGRpY3QgPSBvcHQuZGljdGlvbmFyeTsKICAgICAgICAgIH0KICAgICAgICAgIHN0YXR1cyA9IHpsaWJfZGVmbGF0ZS5kZWZsYXRlU2V0RGljdGlvbmFyeSh0aGlzLnN0cm0sIGRpY3QpOwogICAgICAgICAgaWYgKHN0YXR1cyAhPT0gWl9PSykgewogICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IobXNnW3N0YXR1c10pOwogICAgICAgICAgfQogICAgICAgICAgdGhpcy5fZGljdF9zZXQgPSB0cnVlOwogICAgICAgIH0KICAgICAgfQogICAgICBEZWZsYXRlLnByb3RvdHlwZS5wdXNoID0gZnVuY3Rpb24oZGF0YSwgbW9kZSkgewogICAgICAgIHZhciBzdHJtID0gdGhpcy5zdHJtOwogICAgICAgIHZhciBjaHVua1NpemUgPSB0aGlzLm9wdGlvbnMuY2h1bmtTaXplOwogICAgICAgIHZhciBzdGF0dXMsIF9tb2RlOwogICAgICAgIGlmICh0aGlzLmVuZGVkKSB7CiAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgfQogICAgICAgIF9tb2RlID0gbW9kZSA9PT0gfn5tb2RlID8gbW9kZSA6IG1vZGUgPT09IHRydWUgPyBaX0ZJTklTSCA6IFpfTk9fRkxVU0g7CiAgICAgICAgaWYgKHR5cGVvZiBkYXRhID09PSAic3RyaW5nIikgewogICAgICAgICAgc3RybS5pbnB1dCA9IHN0cmluZ3Muc3RyaW5nMmJ1ZihkYXRhKTsKICAgICAgICB9IGVsc2UgaWYgKHRvU3RyaW5nLmNhbGwoZGF0YSkgPT09ICJbb2JqZWN0IEFycmF5QnVmZmVyXSIpIHsKICAgICAgICAgIHN0cm0uaW5wdXQgPSBuZXcgVWludDhBcnJheShkYXRhKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgc3RybS5pbnB1dCA9IGRhdGE7CiAgICAgICAgfQogICAgICAgIHN0cm0ubmV4dF9pbiA9IDA7CiAgICAgICAgc3RybS5hdmFpbF9pbiA9IHN0cm0uaW5wdXQubGVuZ3RoOwogICAgICAgIGRvIHsKICAgICAgICAgIGlmIChzdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICBzdHJtLm91dHB1dCA9IG5ldyB1dGlscy5CdWY4KGNodW5rU2l6ZSk7CiAgICAgICAgICAgIHN0cm0ubmV4dF9vdXQgPSAwOwogICAgICAgICAgICBzdHJtLmF2YWlsX291dCA9IGNodW5rU2l6ZTsKICAgICAgICAgIH0KICAgICAgICAgIHN0YXR1cyA9IHpsaWJfZGVmbGF0ZS5kZWZsYXRlKHN0cm0sIF9tb2RlKTsKICAgICAgICAgIGlmIChzdGF0dXMgIT09IFpfU1RSRUFNX0VORCAmJiBzdGF0dXMgIT09IFpfT0spIHsKICAgICAgICAgICAgdGhpcy5vbkVuZChzdGF0dXMpOwogICAgICAgICAgICB0aGlzLmVuZGVkID0gdHJ1ZTsKICAgICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICAgICAgfQogICAgICAgICAgaWYgKHN0cm0uYXZhaWxfb3V0ID09PSAwIHx8IHN0cm0uYXZhaWxfaW4gPT09IDAgJiYgKF9tb2RlID09PSBaX0ZJTklTSCB8fCBfbW9kZSA9PT0gWl9TWU5DX0ZMVVNIMikpIHsKICAgICAgICAgICAgaWYgKHRoaXMub3B0aW9ucy50byA9PT0gInN0cmluZyIpIHsKICAgICAgICAgICAgICB0aGlzLm9uRGF0YShzdHJpbmdzLmJ1ZjJiaW5zdHJpbmcodXRpbHMuc2hyaW5rQnVmKHN0cm0ub3V0cHV0LCBzdHJtLm5leHRfb3V0KSkpOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHRoaXMub25EYXRhKHV0aWxzLnNocmlua0J1ZihzdHJtLm91dHB1dCwgc3RybS5uZXh0X291dCkpOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfSB3aGlsZSAoKHN0cm0uYXZhaWxfaW4gPiAwIHx8IHN0cm0uYXZhaWxfb3V0ID09PSAwKSAmJiBzdGF0dXMgIT09IFpfU1RSRUFNX0VORCk7CiAgICAgICAgaWYgKF9tb2RlID09PSBaX0ZJTklTSCkgewogICAgICAgICAgc3RhdHVzID0gemxpYl9kZWZsYXRlLmRlZmxhdGVFbmQodGhpcy5zdHJtKTsKICAgICAgICAgIHRoaXMub25FbmQoc3RhdHVzKTsKICAgICAgICAgIHRoaXMuZW5kZWQgPSB0cnVlOwogICAgICAgICAgcmV0dXJuIHN0YXR1cyA9PT0gWl9PSzsKICAgICAgICB9CiAgICAgICAgaWYgKF9tb2RlID09PSBaX1NZTkNfRkxVU0gyKSB7CiAgICAgICAgICB0aGlzLm9uRW5kKFpfT0spOwogICAgICAgICAgc3RybS5hdmFpbF9vdXQgPSAwOwogICAgICAgICAgcmV0dXJuIHRydWU7CiAgICAgICAgfQogICAgICAgIHJldHVybiB0cnVlOwogICAgICB9OwogICAgICBEZWZsYXRlLnByb3RvdHlwZS5vbkRhdGEgPSBmdW5jdGlvbihjaHVuaykgewogICAgICAgIHRoaXMuY2h1bmtzLnB1c2goY2h1bmspOwogICAgICB9OwogICAgICBEZWZsYXRlLnByb3RvdHlwZS5vbkVuZCA9IGZ1bmN0aW9uKHN0YXR1cykgewogICAgICAgIGlmIChzdGF0dXMgPT09IFpfT0spIHsKICAgICAgICAgIGlmICh0aGlzLm9wdGlvbnMudG8gPT09ICJzdHJpbmciKSB7CiAgICAgICAgICAgIHRoaXMucmVzdWx0ID0gdGhpcy5jaHVua3Muam9pbigiIik7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICB0aGlzLnJlc3VsdCA9IHV0aWxzLmZsYXR0ZW5DaHVua3ModGhpcy5jaHVua3MpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICB0aGlzLmNodW5rcyA9IFtdOwogICAgICAgIHRoaXMuZXJyID0gc3RhdHVzOwogICAgICAgIHRoaXMubXNnID0gdGhpcy5zdHJtLm1zZzsKICAgICAgfTsKICAgICAgZnVuY3Rpb24gZGVmbGF0ZShpbnB1dCwgb3B0aW9ucykgewogICAgICAgIHZhciBkZWZsYXRvciA9IG5ldyBEZWZsYXRlKG9wdGlvbnMpOwogICAgICAgIGRlZmxhdG9yLnB1c2goaW5wdXQsIHRydWUpOwogICAgICAgIGlmIChkZWZsYXRvci5lcnIpIHsKICAgICAgICAgIHRocm93IGRlZmxhdG9yLm1zZyB8fCBtc2dbZGVmbGF0b3IuZXJyXTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIGRlZmxhdG9yLnJlc3VsdDsKICAgICAgfQogICAgICBmdW5jdGlvbiBkZWZsYXRlUmF3KGlucHV0LCBvcHRpb25zKSB7CiAgICAgICAgb3B0aW9ucyA9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KICAgICAgICB2YXIgZG1heDsKICAgICAgICB2YXIgd3NpemU7CiAgICAgICAgdmFyIHdoYXZlOwogICAgICAgIHZhciB3bmV4dDsKICAgICAgICB2YXIgc193aW5kb3c7CiAgICAgICAgdmFyIGhvbGQ7CiAgICAgICAgdmFyIGJpdHM7CiAgICAgICAgdmFyIGxjb2RlOwogICAgICAgIHZhciBkY29kZTsKICAgICAgICB2YXIgbG1hc2s7CiAgICAgICAgdmFyIGRtYXNrOwogICAgICAgIHZhciBoZXJlOwogICAgICAgIHZhciBvcDsKICAgICAgICB2YXIgbGVuOwogICAgICAgIHZhciBkaXN0OwogICAgICAgIHZhciBmcm9tOwogICAgICAgIHZhciBmcm9tX3NvdXJjZTsKICAgICAgICB2YXIgaW5wdXQsIG91dHB1dDsKICAgICAgICBzdGF0ZSA9IHN0cm0uc3RhdGU7CiAgICAgICAgX2luID0gc3RybS5uZXh0X2luOwogICAgICAgIGlucHV0ID0gc3RybS5pbnB1dDsKICAgICAgICBsYXN0ID0gX2luICsgKHN0cm0uYXZhaWxfaW4gLSA1KTsKICAgICAgICBfb3V0ID0gc3RybS5uZXh0X291dDsKICAgICAgICBvdXRwdXQgPSBzdHJtLm91dHB1dDsKICAgICAgICBiZWcgPSBfb3V0IC0gKHN0YXJ0IC0gc3RybS5hdmFpbF9vdXQpOwogICAgICAgIGVuZCA9IF9vdXQgKyAoc3RybS5hdmFpbF9vdXQgLSAyNTcpOwogICAgICAgIGRtYXggPSBzdGF0ZS5kbWF4OwogICAgICAgIHdzaXplID0gc3RhdGUud3NpemU7CiAgICAgICAgd2hhdmUgPSBzdGF0ZS53aGF2ZTsKICAgICAgICB3bmV4dCA9IHN0YXRlLnduZXh0OwogICAgICAgIHNfd2luZG93ID0gc3RhdGUud2luZG93OwogICAgICAgIGhvbGQgPSBzdGF0ZS5ob2xkOwogICAgICAgIGJpdHMgPSBzdGF0ZS5iaXRzOwogICAgICAgIGxjb2RlID0gc3RhdGUubGVuY29kZTsKICAgICAgICBkY29kZSA9IHN0YXRlLmRpc3Rjb2RlOwogICAgICAgIGxtYXNrID0gKDEgPDwgc3RhdGUubGVuYml0cykgLSAxOwogICAgICAgIGRtYXNrID0gKDEgPDwgc3RhdGUuZGlzdGJpdHMpIC0gMTsKICAgICAgICB0b3A6CiAgICAgICAgICBkbyB7CiAgICAgICAgICAgIGlmIChiaXRzIDwgMTUpIHsKICAgICAgICAgICAgICBob2xkICs9IGlucHV0W19pbisrXSA8PCBiaXRzOwogICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICBob2xkICs9IGlucHV0W19pbisrXSA8PCBiaXRzOwogICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgfQogICAgICAgICAgICBoZXJlID0gbGNvZGVbaG9sZCAmIGxtYXNrXTsKICAgICAgICAgICAgZG9sZW46CiAgICAgICAgICAgICAgZm9yICg7IDsgKSB7CiAgICAgICAgICAgICAgICBvcCA9IGhlcmUgPj4+IDI0OwogICAgICAgICAgICAgICAgaG9sZCA+Pj49IG9wOwogICAgICAgICAgICAgICAgYml0cyAtPSBvcDsKICAgICAgICAgICAgICAgIG9wID0gaGVyZSA+Pj4gMTYgJiAyNTU7CiAgICAgICAgICAgICAgICBpZiAob3AgPT09IDApIHsKICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBoZXJlICYgNjU1MzU7CiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKG9wICYgMTYpIHsKICAgICAgICAgICAgICAgICAgbGVuID0gaGVyZSAmIDY1NTM1OwogICAgICAgICAgICAgICAgICBvcCAmPSAxNTsKICAgICAgICAgICAgICAgICAgaWYgKG9wKSB7CiAgICAgICAgICAgICAgICAgICAgaWYgKGJpdHMgPCBvcCkgewogICAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtfaW4rK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgbGVuICs9IGhvbGQgJiAoMSA8PCBvcCkgLSAxOwogICAgICAgICAgICAgICAgICAgIGhvbGQgPj4+PSBvcDsKICAgICAgICAgICAgICAgICAgICBiaXRzIC09IG9wOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChiaXRzIDwgMTUpIHsKICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W19pbisrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W19pbisrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBoZXJlID0gZGNvZGVbaG9sZCAmIGRtYXNrXTsKICAgICAgICAgICAgICAgICAgZG9kaXN0OgogICAgICAgICAgICAgICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgICAgICAgICAgICAgb3AgPSBoZXJlID4+PiAyNDsKICAgICAgICAgICAgICAgICAgICAgIGhvbGQgPj4+PSBvcDsKICAgICAgICAgICAgICAgICAgICAgIGJpdHMgLT0gb3A7CiAgICAgICAgICAgICAgICAgICAgICBvcCA9IGhlcmUgPj4+IDE2ICYgMjU1OwogICAgICAgICAgICAgICAgICAgICAgaWYgKG9wICYgMTYpIHsKICAgICAgICAgICAgICAgICAgICAgICAgZGlzdCA9IGhlcmUgJiA2NTUzNTsKICAgICAgICAgICAgICAgICAgICAgICAgb3AgJj0gMTU7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChiaXRzIDwgb3ApIHsKICAgICAgICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W19pbisrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoYml0cyA8IG9wKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W19pbisrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICBkaXN0ICs9IGhvbGQgJiAoMSA8PCBvcCkgLSAxOwogICAgICAgICAgICAgICAgICAgICAgICBpZiAoZGlzdCA+IGRtYXgpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbnZhbGlkIGRpc3RhbmNlIHRvbyBmYXIgYmFjayI7CiAgICAgICAgICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgICAgICAgICBicmVhayB0b3A7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgaG9sZCA+Pj49IG9wOwogICAgICAgICAgICAgICAgICAgICAgICBiaXRzIC09IG9wOwogICAgICAgICAgICAgICAgICAgICAgICBvcCA9IF9vdXQgLSBiZWc7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChkaXN0ID4gb3ApIHsKICAgICAgICAgICAgICAgICAgICAgICAgICBvcCA9IGRpc3QgLSBvcDsKICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAob3AgPiB3aGF2ZSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHN0YXRlLnNhbmUpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW52YWxpZCBkaXN0YW5jZSB0b28gZmFyIGJhY2siOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBicmVhayB0b3A7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgIGZyb20gPSAwOwogICAgICAgICAgICAgICAgICAgICAgICAgIGZyb21fc291cmNlID0gc193aW5kb3c7CiAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHduZXh0ID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tICs9IHdzaXplIC0gb3A7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAob3AgPCBsZW4pIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbGVuIC09IG9wOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBzX3dpbmRvd1tmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IHdoaWxlICgtLW9wKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZnJvbSA9IF9vdXQgLSBkaXN0OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tX3NvdXJjZSA9IG91dHB1dDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKHduZXh0IDwgb3ApIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZyb20gKz0gd3NpemUgKyB3bmV4dCAtIG9wOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgb3AgLT0gd25leHQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAob3AgPCBsZW4pIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbGVuIC09IG9wOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBzX3dpbmRvd1tmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IHdoaWxlICgtLW9wKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZnJvbSA9IDA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmICh3bmV4dCA8IGxlbikgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG9wID0gd25leHQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbGVuIC09IG9wOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gc193aW5kb3dbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IHdoaWxlICgtLW9wKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tID0gX291dCAtIGRpc3Q7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZnJvbV9zb3VyY2UgPSBvdXRwdXQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgZnJvbSArPSB3bmV4dCAtIG9wOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKG9wIDwgbGVuKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxlbiAtPSBvcDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gc193aW5kb3dbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSB3aGlsZSAoLS1vcCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZyb20gPSBfb3V0IC0gZGlzdDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZnJvbV9zb3VyY2UgPSBvdXRwdXQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgIHdoaWxlIChsZW4gPiAyKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IGZyb21fc291cmNlW2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IGZyb21fc291cmNlW2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IGZyb21fc291cmNlW2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBsZW4gLT0gMzsKICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGxlbikgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBmcm9tX3NvdXJjZVtmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGxlbiA+IDEpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBmcm9tX3NvdXJjZVtmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tID0gX291dCAtIGRpc3Q7CiAgICAgICAgICAgICAgICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBvdXRwdXRbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gb3V0cHV0W2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IG91dHB1dFtmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgbGVuIC09IDM7CiAgICAgICAgICAgICAgICAgICAgICAgICAgfSB3aGlsZSAobGVuID4gMik7CiAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGxlbikgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBvdXRwdXRbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChsZW4gPiAxKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gb3V0cHV0W2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKChvcCAmIDY0KSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICBoZXJlID0gZGNvZGVbKGhlcmUgJiA2NTUzNSkgKyAoaG9sZCAmICgxIDw8IG9wKSAtIDEpXTsKICAgICAgICAgICAgICAgICAgICAgICAgY29udGludWUgZG9kaXN0OwogICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW52YWxpZCBkaXN0YW5jZSBjb2RlIjsKICAgICAgICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWsgdG9wOwogICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfSBlbHNlIGlmICgob3AgJiA2NCkgPT09IDApIHsKICAgICAgICAgICAgICAgICAgaGVyZSA9IGxjb2RlWyhoZXJlICYgNjU1MzUpICsgKGhvbGQgJiAoMSA8PCBvcCkgLSAxKV07CiAgICAgICAgICAgICAgICAgIGNvbnRpbnVlIGRvbGVuOwogICAgICAgICAgICAgICAgfSBlbHNlIGlmIChvcCAmIDMyKSB7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBUWVBFOwogICAgICAgICAgICAgICAgICBicmVhayB0b3A7CiAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbnZhbGlkIGxpdGVyYWwvbGVuZ3RoIGNvZGUiOwogICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEOwogICAgICAgICAgICAgICAgICBicmVhayB0b3A7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICB9CiAgICAgICAgICB9IHdoaWxlIChfaW4gPCBsYXN0ICYmIF9vdXQgPCBlbmQpOwogICAgICAgIGxlbiA9IGJpdHMgPj4gMzsKICAgICAgICBfaW4gLT0gbGVuOwogICAgICAgIGJpdHMgLT0gbGVuIDw8IDM7CiAgICAgICAgaG9sZCAmPSAoMSA8PCBiaXRzKSAtIDE7CiAgICAgICAgc3RybS5uZXh0X2luID0gX2luOwogICAgICAgIHN0cm0ubmV4dF9vdXQgPSBfb3V0OwogICAgICAgIHN0cm0uYXZhaWxfaW4gPSBfaW4gPCBsYXN0ID8gNSArIChsYXN0IC0gX2luKSA6IDUgLSAoX2luIC0gbGFzdCk7CiAgICAgICAgc3RybS5hdmFpbF9vdXQgPSBfb3V0IDwgZW5kID8gMjU3ICsgKGVuZCAtIF9vdXQpIDogMjU3IC0gKF9vdXQgLSBlbmQpOwogICAgICAgIHN0YXRlLmhvbGQgPSBob2xkOwogICAgICAgIHN0YXRlLmJpdHMgPSBiaXRzOwogICAgICAgIHJldHVybjsKICAgICAgfTsKICAgIH0KICB9KTsKCiAgLy8gbm9kZV9tb2R1bGVzLy5wbnBtL3Bha29AMS4wLjExL25vZGVfbW9kdWxlcy9wYWtvL2xpYi96bGliL2luZnRyZWVzLmpzCiAgdmFyIHJlcXVpcmVfaW5mdHJlZXMgPSBfX2NvbW1vbkpTKHsKICAgICJub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvaW5mdHJlZXMuanMiKGV4cG9ydHMsIG1vZHVsZSkgewogICAgICBpbml0X2J1ZmZlcl9zaGltKCk7CiAgICAgICJ1c2Ugc3RyaWN0IjsKICAgICAgdmFyIHV0aWxzID0gcmVxdWlyZV9jb21tb24yKCk7CiAgICAgIHZhciBNQVhCSVRTID0gMTU7CiAgICAgIHZhciBFTk9VR0hfTEVOUyA9IDg1MjsKICAgICAgdmFyIEVOT1VHSF9ESVNUUyA9IDU5MjsKICAgICAgdmFyIENPREVTID0gMDsKICAgICAgdmFyIExFTlMgPSAxOwogICAgICB2YXIgRElTVFMgPSAyOwogICAgICB2YXIgbGJhc2UgPSBbCiAgICAgICAgMywKICAgICAgICA0LAogICAgICAgIDUsCiAgICAgICAgNiwKICAgICAgICA3LAogICAgICAgIDgsCiAgICAgICAgOSwKICAgICAgICAxMCwKICAgICAgICAxMSwKICAgICAgICAxMywKICAgICAgICAxNSwKICAgICAgICAxNywKICAgICAgICAxOSwKICAgICAgICAyMywKICAgICAgICAyNywKICAgICAgICAzMSwKICAgICAgICAzNSwKICAgICAgICA0MywKICAgICAgICA1MSwKICAgICAgICA1OSwKICAgICAgICA2NywKICAgICAgICA4MywKICAgICAgICA5OSwKICAgICAgICAxMTUsCiAgICAgICAgMTMxLAogICAgICAgIDE2MywKICAgICAgICAxOTUsCiAgICAgICAgMjI3LAogICAgICAgIDI1OCwKICAgICAgICAwLAogICAgICAgIDAKICAgICAgXTsKICAgICAgdmFyIGxleHQgPSBbCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTcsCiAgICAgICAgMTcsCiAgICAgICAgMTcsCiAgICAgICAgMTcsCiAgICAgICAgMTgsCiAgICAgICAgMTgsCiAgICAgICAgMTgsCiAgICAgICAgMTgsCiAgICAgICAgMTksCiAgICAgICAgMTksCiAgICAgICAgMTksCiAgICAgICAgMTksCiAgICAgICAgMjAsCiAgICAgICAgMjAsCiAgICAgICAgMjAsCiAgICAgICAgMjAsCiAgICAgICAgMjEsCiAgICAgICAgMjEsCiAgICAgICAgMjEsCiAgICAgICAgMjEsCiAgICAgICAgMTYsCiAgICAgICAgNzIsCiAgICAgICAgNzgKICAgICAgXTsKICAgICAgdmFyIGRiYXNlID0gWwogICAgICAgIDEsCiAgICAgICAgMiwKICAgICAgICAzLAogICAgICAgIDQsCiAgICAgICAgNSwKICAgICAgICA3LAogICAgICAgIDksCiAgICAgICAgMTMsCiAgICAgICAgMTcsCiAgICAgICAgMjUsCiAgICAgICAgMzMsCiAgICAgICAgNDksCiAgICAgICAgNjUsCiAgICAgICAgOTcsCiAgICAgICAgMTI5LAogICAgICAgIDE5MywKICAgICAgICAyNTcsCiAgICAgICAgMzg1LAogICAgICAgIDUxMywKICAgICAgICA3NjksCiAgICAgICAgMTAyNSwKICAgICAgICAxNTM3LAogICAgICAgIDIwNDksCiAgICAgICAgMzA3MywKICAgICAgICA0MDk3LAogICAgICAgIDYxNDUsCiAgICAgICAgODE5MywKICAgICAgICAxMjI4OSwKICAgICAgICAxNjM4NSwKICAgICAgICAyNDU3NywKICAgICAgICAwLAogICAgICAgIDAKICAgICAgXTsKICAgICAgdmFyIGRleHQgPSBbCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTcsCiAgICAgICAgMTcsCiAgICAgICAgMTgsCiAgICAgICAgMTgsCiAgICAgICAgMTksCiAgICAgICAgMTksCiAgICAgICAgMjAsCiAgICAgICAgMjAsCiAgICAgICAgMjEsCiAgICAgICAgMjEsCiAgICAgICAgMjIsCiAgICAgICAgMjIsCiAgICAgICAgMjMsCiAgICAgICAgMjMsCiAgICAgICAgMjQsCiAgICAgICAgMjQsCiAgICAgICAgMjUsCiAgICAgICAgMjUsCiAgICAgICAgMjYsCiAgICAgICAgMjYsCiAgICAgICAgMjcsCiAgICAgICAgMjcsCiAgICAgICAgMjgsCiAgICAgICAgMjgsCiAgICAgICAgMjksCiAgICAgICAgMjksCiAgICAgICAgNjQsCiAgICAgICAgNjQKICAgICAgXTsKICAgICAgbW9kdWxlLmV4cG9ydHMgPSBmdW5jdGlvbiBpbmZsYXRlX3RhYmxlKHR5cGUsIGxlbnMsIGxlbnNfaW5kZXgsIGNvZGVzLCB0YWJsZSwgdGFibGVfaW5kZXgsIHdvcmssIG9wdHMpIHsKICAgICAgICB2YXIgYml0cyA9IG9wdHMuYml0czsKICAgICAgICB2YXIgbGVuID0gMDsKICAgICAgICB2YXIgc3ltID0gMDsKICAgICAgICB2YXIgbWluID0gMCwgbWF4ID0gMDsKICAgICAgICB2YXIgcm9vdCA9IDA7CiAgICAgICAgdmFyIGN1cnIgPSAwOwogICAgICAgIHZhciBkcm9wID0gMDsKICAgICAgICB2YXIgbGVmdCA9IDA7CiAgICAgICAgdmFyIHVzZWQgPSAwOwogICAgICAgIHZhciBodWZmID0gMDsKICAgICAgICB2YXIgaW5jcjsKICAgICAgICB2YXIgZmlsbDsKICAgICAgICB2YXIgbG93OwogICAgICAgIHZhciBtYXNrOwogICAgICAgIHZhciBuZXh0OwogICAgICAgIHZhciBiYXNlID0gbnVsbDsKICAgICAgICB2YXIgYmFzZV9pbmRleCA9IDA7CiAgICAgICAgdmFyIGVuZDsKICAgICAgICB2YXIgY291bnQgPSBuZXcgdXRpbHMuQnVmMTYoTUFYQklUUyArIDEpOwogICAgICAgIHZhciBvZmZzID0gbmV3IHV0aWxzLkJ1ZjE2KE1BWEJJVFMgKyAxKTsKICAgICAgICB2YXIgZXh0cmEgPSBudWxsOwogICAgICAgIHZhciBleHRyYV9pbmRleCA9IDA7CiAgICAgICAgdmFyIGhlcmVfYml0cywgaGVyZV9vcCwgaGVyZV92YWw7CiAgICAgICAgZm9yIChsZW4gPSAwOyBsZW4gPD0gTUFYQklUUzsgbGVuKyspIHsKICAgICAgICAgIGNvdW50W2xlbl0gPSAwOwogICAgICAgIH0KICAgICAgICBmb3IgKHN5bSA9IDA7IHN5bSA8IGNvZGVzOyBzeW0rKykgewogICAgICAgICAgY291bnRbbGVuc1tsZW5zX2luZGV4ICsgc3ltXV0rKzsKICAgICAgICB9CiAgICAgICAgcm9vdCA9IGJpdHM7CiAgICAgICAgZm9yIChtYXggPSBNQVhCSVRTOyBtYXggPj0gMTsgbWF4LS0pIHsKICAgICAgICAgIGlmIChjb3VudFttYXhdICE9PSAwKSB7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAocm9vdCA+IG1heCkgewogICAgICAgICAgcm9vdCA9IG1heDsKICAgICAgICB9CiAgICAgICAgaWYgKG1heCA9PT0gMCkgewogICAgICAgICAgdGFibGVbdGFibGVfaW5kZXgrK10gPSAxIDw8IDI0IHwgNjQgPDwgMTYgfCAwOwogICAgICAgICAgdGFibGVbdGFibGVfaW5kZXgrK10gPSAxIDw8IDI0IHwgNjQgPDwgMTYgfCAwOwogICAgICAgICAgb3B0cy5iaXRzID0gMTsKICAgICAgICAgIHJldHVybiAwOwogICAgICAgIH0KICAgICAgICBmb3IgKG1pbiA9IDE7IG1pbiA8IG1heDsgbWluKyspIHsKICAgICAgICAgIGlmIChjb3VudFttaW5dICE9PSAwKSB7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAocm9vdCA8IG1pbikgewogICAgICAgICAgcm9vdCA9IG1pbjsKICAgICAgICB9CiAgICAgICAgbGVmdCA9IDE7CiAgICAgICAgZm9yIChsZW4gPSAxOyBsZW4gPD0gTUFYQklUUzsgbGVuKyspIHsKICAgICAgICAgIGxlZnQgPDw9IDE7CiAgICAgICAgICBsZWZ0IC09IGNvdW50W2xlbl07CiAgICAgICAgICBpZiAobGVmdCA8IDApIHsKICAgICAgICAgICAgcmV0dXJuIC0xOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAobGVmdCA+IDAgJiYgKHR5cGUgPT09IENPREVTIHx8IG1heCAhPT0gMSkpIHsKICAgICAgICAgIHJldHVybiAtMTsKICAgICAgICB9CiAgICAgICAgb2Zmc1sxXSA9IDA7CiAgICAgICAgZm9yIChsZW4gPSAxOyBsZW4gPCBNQVhCSVRTOyBsZW4rKykgewogICAgICAgICAgb2Zmc1tsZW4gKyAxXSA9IG9mZnNbbGVuXSArIGNvdW50W2xlbl07CiAgICAgICAgfQogICAgICAgIGZvciAoc3ltID0gMDsgc3ltIDwgY29kZXM7IHN5bSsrKSB7CiAgICAgICAgICBpZiAobGVuc1tsZW5zX2luZGV4ICsgc3ltXSAhPT0gMCkgewogICAgICAgICAgICB3b3JrW29mZnNbbGVuc1tsZW5zX2luZGV4ICsgc3ltXV0rK10gPSBzeW07CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmICh0eXBlID09PSBDT0RFUykgewogICAgICAgICAgYmFzZSA9IGV4dHJhID0gd29yazsKICAgICAgICAgIGVuZCA9IDE5OwogICAgICAgIH0gZWxzZSBpZiAodHlwZSA9PT0gTEVOUykgewogICAgICAgICAgYmFzZSA9IGxiYXNlOwogICAgICAgICAgYmFzZV9pbmRleCAtPSAyNTc7CiAgICAgICAgICBleHRyYSA9IGxleHQ7CiAgICAgICAgICBleHRyYV9pbmRleCAtPSAyNTc7CiAgICAgICAgICBlbmQgPSAyNTY7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIGJhc2UgPSBkYmFzZTsKICAgICAgICAgIGV4dHJhID0gZGV4dDsKICAgICAgICAgIGVuZCA9IC0xOwogICAgICAgIH0KICAgICAgICBodWZmID0gMDsKICAgICAgICBzeW0gPSAwOwogICAgICAgIGxlbiA9IG1pbjsKICAgICAgICBuZXh0ID0gdGFibGVfaW5kZXg7CiAgICAgICAgY3VyciA9IHJvb3Q7CiAgICAgICAgZHJvcCA9IDA7CiAgICAgICAgbG93ID0gLTE7CiAgICAgICAgdXNlZCA9IDEgPDwgcm9vdDsKICAgICAgICBtYXNrID0gdXNlZCAtIDE7CiAgICAgICAgaWYgKHR5cGUgPT09IExFTlMgJiYgdXNlZCA+IEVOT1VHSF9MRU5TIHx8IHR5cGUgPT09IERJU1RTICYmIHVzZWQgPiBFTk9VR0hfRElTVFMpIHsKICAgICAgICAgIHJldHVybiAxOwogICAgICAgIH0KICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgIGhlcmVfYml0cyA9IGxlbiAtIGRyb3A7CiAgICAgICAgICBpZiAod29ya1tzeW1dIDwgZW5kKSB7CiAgICAgICAgICAgIGhlcmVfb3AgPSAwOwogICAgICAgICAgICBoZXJlX3ZhbCA9IHdvcmtbc3ltXTsKICAgICAgICAgIH0gZWxzZSBpZiAod29ya1tzeW1dID4gZW5kKSB7CiAgICAgICAgICAgIGhlcmVfb3AgPSBleHRyYVtleHRyYV9pbmRleCArIHdvcmtbc3ltXV07CiAgICAgICAgICAgIGhlcmVfdmFsID0gYmFzZVtiYXNlX2luZGV4ICsgd29ya1tzeW1dXTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGhlcmVfb3AgPSAzMiArIDY0OwogICAgICAgICAgICBoZXJlX3ZhbCA9IDA7CiAgICAgICAgICB9CiAgICAgICAgICBpbmNyID0gMSA8PCBsZW4gLSBkcm9wOwogICAgICAgICAgZmlsbCA9IDEgPDwgY3VycjsKICAgICAgICAgIG1pbiA9IGZpbGw7CiAgICAgICAgICBkbyB7CiAgICAgICAgICAgIGZpbGwgLT0gaW5jcjsKICAgICAgICAgICAgdGFibGVbbmV4dCArIChodWZmID4+IGRyb3ApICsgZmlsbF0gPSBoZXJlX2JpdHMgPDwgMjQgfCBoZXJlX29wIDw8IDE2IHwgaGVyZV92YWwgfCAwOwogICAgICAgICAgfSB3aGlsZSAoZmlsbCAhPT0gMCk7CiAgICAgICAgICBpbmNyID0gMSA8PCBsZW4gLSAxOwogICAgICAgICAgd2hpbGUgKGh1ZmYgJiBpbmNyKSB7CiAgICAgICAgICAgIGluY3IgPj49IDE7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoaW5jciAhPT0gMCkgewogICAgICAgICAgICBodWZmICY9IGluY3IgLSAxOwogICAgICAgICAgICBodWZmICs9IGluY3I7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBodWZmID0gMDsKICAgICAgICAgIH0KICAgICAgICAgIHN5bSsrOwogICAgICAgICAgaWYgKC0tY291bnRbbGVuXSA9PT0gMCkgewogICAgICAgICAgICBpZiAobGVuID09PSBtYXgpIHsKICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgICBsZW4gPSBsZW5zW2xlbnNfaW5kZXggKyB3b3JrW3N5bV1dOwogICAgICAgICAgfQogICAgICAgICAgaWYgKGxlbiA+IHJvb3QgJiYgKGh1ZmYgJiBtYXNrKSAhPT0gbG93KSB7CiAgICAgICAgICAgIGlmIChkcm9wID09PSAwKSB7CiAgICAgICAgICAgICAgZHJvcCA9IHJvb3Q7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgbmV4dCArPSBtaW47CiAgICAgICAgICAgIGN1cnIgPSBsZW4gLSBkcm9wOwogICAgICAgICAgICBsZWZ0ID0gMSA8PCBjdXJyOwogICAgICAgICAgICB3aGlsZSAoY3VyciArIGRyb3AgPCBtYXgpIHsKICAgICAgICAgICAgICBsZWZ0IC09IGNvdW50W2N1cnIgKyBkcm9wXTsKICAgICAgICAgICAgICBpZiAobGVmdCA8PSAwKSB7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgY3VycisrOwogICAgICAgICAgICAgIGxlZnQgPDw9IDE7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdXNlZCArPSAxIDw8IGN1cnI7CiAgICAgICAgICAgIGlmICh0eXBlID09PSBMRU5TICYmIHVzZWQgPiBFTk9VR0hfTEVOUyB8fCB0eXBlID09PSBESVNUUyAmJiB1c2VkID4gRU5PVUdIX0RJU1RTKSB7CiAgICAgICAgICAgICAgcmV0dXJuIDE7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgbG93ID0gaHVmZiAmIG1hc2s7CiAgICAgICAgICAgIHRhYmxlW2xvd10gPSByb290IDw8IDI0IHwgY3VyciA8PCAxNiB8IG5leHQgLSB0YWJsZV9pbmRleCB8IDA7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChodWZmICE9PSAwKSB7CiAgICAgICAgICB0YWJsZVtuZXh0ICsgaHVmZl0gPSBsZW4gLSBkcm9wIDw8IDI0IHwgNjQgPDwgMTYgfCAwOwogICAgICAgIH0KICAgICAgICBvcHRzLmJpdHMgPSByb290OwogICAgICAgIHJldHVybiAwOwogICAgICB9OwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvaW5mbGF0ZS5qcwogIHZhciByZXF1aXJlX2luZmxhdGUgPSBfX2NvbW1vbkpTKHsKICAgICJub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvaW5mbGF0ZS5qcyIoZXhwb3J0cykgewogICAgICBpbml0X2J1ZmZlcl9zaGltKCk7CiAgICAgICJ1c2Ugc3RyaWN0IjsKICAgICAgdmFyIHV0aWxzID0gcmVxdWlyZV9jb21tb24yKCk7CiAgICAgIHZhciBhZGxlcjMyID0gcmVxdWlyZV9hZGxlcjMyKCk7CiAgICAgIHZhciBjcmMzMjIgPSByZXF1aXJlX2NyYzMyKCk7CiAgICAgIHZhciBpbmZsYXRlX2Zhc3QgPSByZXF1aXJlX2luZmZhc3QoKTsKICAgICAgdmFyIGluZmxhdGVfdGFibGUgPSByZXF1aXJlX2luZnRyZWVzKCk7CiAgICAgIHZhciBDT0RFUyA9IDA7CiAgICAgIHZhciBMRU5TID0gMTsKICAgICAgdmFyIERJU1RTID0gMjsKICAgICAgdmFyIFpfRklOSVNIID0gNDsKICAgICAgdmFyIFpfQkxPQ0sgPSA1OwogICAgICB2YXIgWl9UUkVFUyA9IDY7CiAgICAgIHZhciBaX09LID0gMDsKICAgICAgdmFyIFpfU1RSRUFNX0VORCA9IDE7CiAgICAgIHZhciBaX05FRURfRElDVCA9IDI7CiAgICAgIHZhciBaX1NUUkVBTV9FUlJPUiA9IC0yOwogICAgICB2YXIgWl9EQVRBX0VSUk9SID0gLTM7CiAgICAgIHZhciBaX01FTV9FUlJPUiA9IC00OwogICAgICB2YXIgWl9CVUZfRVJST1IgPSAtNTsKICAgICAgdmFyIFpfREVGTEFURUQgPSA4OwogICAgICB2YXIgSEVBRCA9IDE7CiAgICAgIHZhciBGTEFHUyA9IDI7CiAgICAgIHZhciBUSU1FID0gMzsKICAgICAgdmFyIE9TID0gNDsKICAgICAgdmFyIEVYTEVOID0gNTsKICAgICAgdmFyIEVYVFJBID0gNjsKICAgICAgdmFyIE5BTUUgPSA3OwogICAgICB2YXIgQ09NTUVOVCA9IDg7CiAgICAgIHZhciBIQ1JDID0gOTsKICAgICAgdmFyIERJQ1RJRCA9IDEwOwogICAgICB2YXIgRElDVCA9IDExOwogICAgICB2YXIgVFlQRSA9IDEyOwogICAgICB2YXIgVFlQRURPID0gMTM7CiAgICAgIHZhciBTVE9SRUQgPSAxNDsKICAgICAgdmFyIENPUFlfID0gMTU7CiAgICAgIHZhciBDT1BZID0gMTY7CiAgICAgIHZhciBUQUJMRSA9IDE3OwogICAgICB2YXIgTEVOTEVOUyA9IDE4OwogICAgICB2YXIgQ09ERUxFTlMgPSAxOTsKICAgICAgdmFyIExFTl8gPSAyMDsKICAgICAgdmFyIExFTiA9IDIxOwogICAgICB2YXIgTEVORVhUID0gMjI7CiAgICAgIHZhciBESVNUID0gMjM7CiAgICAgIHZhciBESVNURVhUID0gMjQ7CiAgICAgIHZhciBNQVRDSCA9IDI1OwogICAgICB2YXIgTElUID0gMjY7CiAgICAgIHZhciBDSEVDSyA9IDI3OwogICAgICB2YXIgTEVOR1RIID0gMjg7CiAgICAgIHZhciBET05FID0gMjk7CiAgICAgIHZhciBCQUQgPSAzMDsKICAgICAgdmFyIE1FTSA9IDMxOwogICAgICB2YXIgU1lOQyA9IDMyOwogICAgICB2YXIgRU5PVUdIX0xFTlMgPSA4NTI7CiAgICAgIHZhciBFTk9VR0hfRElTVFMgPSA1OTI7CiAgICAgIHZhciBNQVhfV0JJVFMgPSAxNTsKICAgICAgdmFyIERFRl9XQklUUyA9IE1BWF9XQklUUzsKICAgICAgZnVuY3Rpb24genN3YXAzMihxKSB7CiAgICAgICAgcmV0dXJuIChxID4+PiAyNCAmIDI1NSkgKyAocSA+Pj4gOCAmIDY1MjgwKSArICgocSAmIDY1MjgwKSA8PCA4KSArICgocSAmIDI1NSkgPDwgMjQpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIEluZmxhdGVTdGF0ZSgpIHsKICAgICAgICB0aGlzLm1vZGUgPSAwOwogICAgICAgIHRoaXMubGFzdCA9IGZhbHNlOwogICAgICAgIHRoaXMud3JhcCA9IDA7CiAgICAgICAgdGhpcy5oYXZlZGljdCA9IGZhbHNlOwogICAgICAgIHRoaXMuZmxhZ3MgPSAwOwogICAgICAgIHRoaXMuZG1heCA9IDA7CiAgICAgICAgdGhpcy5jaGVjayA9IDA7CiAgICAgICAgdGhpcy50b3RhbCA9IDA7CiAgICAgICAgdGhpcy5oZWFkID0gbnVsbDsKICAgICAgICB0aGlzLndiaXRzID0gMDsKICAgICAgICB0aGlzLndzaXplID0gMDsKICAgICAgICB0aGlzLndoYXZlID0gMDsKICAgICAgICB0aGlzLnduZXh0ID0gMDsKICAgICAgICB0aGlzLndpbmRvdyA9IG51bGw7CiAgICAgICAgdGhpcy5ob2xkID0gMDsKICAgICAgICB0aGlzLmJpdHMgPSAwOwogICAgICAgIHRoaXMubGVuZ3RoID0gMDsKICAgICAgICB0aGlzLm9mZnNldCA9IDA7CiAgICAgICAgdGhpcy5leHRyYSA9IDA7CiAgICAgICAgdGhpcy5sZW5jb2RlID0gbnVsbDsKICAgICAgICB0aGlzLmRpc3Rjb2RlID0gbnVsbDsKICAgICAgICB0aGlzLmxlbmJpdHMgPSAwOwogICAgICAgIHRoaXMuZGlzdGJpdHMgPSAwOwogICAgICAgIHRoaXMubmNvZGUgPSAwOwogICAgICAgIHRoaXMubmxlbiA9IDA7CiAgICAgICAgdGhpcy5uZGlzdCA9IDA7CiAgICAgICAgdGhpcy5oYXZlID0gMDsKICAgICAgICB0aGlzLm5leHQgPSBudWxsOwogICAgICAgIHRoaXMubGVucyA9IG5ldyB1dGlscy5CdWYxNigzMjApOwogICAgICAgIHRoaXMud29yayA9IG5ldyB1dGlscy5CdWYxNigyODgpOwogICAgICAgIHRoaXMubGVuZHluID0gbnVsbDsKICAgICAgICB0aGlzLmRpc3RkeW4gPSBudWxsOwogICAgICAgIHRoaXMuc2FuZSA9IDA7CiAgICAgICAgdGhpcy5iYWNrID0gMDsKICAgICAgICB0aGlzLndhcyA9IDA7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gaW5mbGF0ZVJlc2V0S2VlcChzdHJtKSB7CiAgICAgICAgdmFyIHN0YXRlOwogICAgICAgIGlmICghc3RybSB8fCAhc3RybS5zdGF0ZSkgewogICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VSUk9SOwogICAgICAgIH0KICAgICAgICBzdGF0ZSA9IHN0cm0uc3RhdGU7CiAgICAgICAgc3RybS50b3RhbF9pbiA9IHN0cm0udG90YWxfb3V0ID0gc3RhdGUudG90YWwgPSAwOwogICAgICAgIHN0cm0ubXNnID0gIiI7CiAgICAgICAgaWYgKHN0YXRlLndyYXApIHsKICAgICAgICAgIHN0cm0uYWRsZXIgPSBzdGF0ZS53cmFwICYgMTsKICAgICAgICB9CiAgICAgICAgc3RhdGUubW9kZSA9IEhFQUQ7CiAgICAgICAgc3RhdGUubGF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0ZTsKICAgICAgICBpZiAod2luZG93Qml0cyA8IDApIHsKICAgICAgICAgIHdyYXAgPSAwOwogICAgICAgICAgd2luZG93Qml0cyA9IC13aW5kb3dCaXRzOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICB3cmFwID0gKHdpbmRvd0JpdHMgPj4gNCkgKyAxOwogICAgICAgICAgaWYgKHdpbmRvd0JpdHMgPCA0OCkgewogICAgICAgICAgICB3aW5kb3dCaXRzICY9IDE1OwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAod2luZG93Qml0cyAmJiAod2luZG93Qml0cyA8IDggfHwgd2luZG93Qml0cyA+IDE1KSkgewogICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VSUk9SOwogICAgICAgIH0KICAgICAgICBpZiAoc3RhdGUud2luZG93ICE9PSBudWxsICYmIHN0YXRlLndiaXRzICE9PSB3aW5kb3dCaXRzKSB7CiAgICAgICAgICBzdGF0ZS53aW5kb3cgPSBudWxsOwogICAgICAgIH0KICAgICAgICBzdGF0ZS53cmFwID0gd3JhcDsKICAgICAgICBzdGF0ZS53Yml0cyA9IHdpbmRvd0JpdHM7CiAgICAgICAgcmV0dXJuIGluZmxhdGVSZXNldChzdHJtKTsKICAgICAgfQogICAgICBmdW5jdGlvbiBpbmZsYXRlSW5pdDIoc3RybSwgd2luZG93Qml0cykgewogICAgICAgIHZhciByZXQ7CiAgICAgICAgdmFyIHN0YXRlOwogICAgICAgIGlmICghc3RybSkgewogICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VSUk9SOwogICAgICAgIH0KICAgICAgICBzdGF0ZSA9IG5ldyBJbmZsYXRlU3RhdGUoKTsKICAgICAgICBzdHJtLnN0YXRlID0gc3RhdGU7CiAgICAgICAgc3RhdGUud2luZG93ID0gbnVsbDsKICAgICAgICByZXQgPSBpbmZsYXRlUmVzZXQyKHN0cm0sIHdpbmRvd0JpdHMpOwogICAgICAgIGlmIChyZXQgIT09IFpfT0spIHsKICAgICAgICAgIHN0cm0uc3RhdGUgPSBudWxsOwogICAgICAgIH0KICAgICAgICByZXR1cm4gcmV0OwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGluZmxhdGVJbml0KHN0cm0pIHsKICAgICAgICByZXR1cm4gaW5mbGF0ZUluaXQyKHN0cm0sIERFRl9XQklUUyk7CiAgICAgIH0KICAgICAgdmFyIHZpcmdpbiA9IHRydWU7CiAgICAgIHZhciBsZW5maXg7CiAgICAgIHZhciBkaXN0Zml4OwogICAgICBmdW5jdGlvbiBmaXhlZHRhYmxlcyhzdGF0ZSkgewogICAgICAgIGlmICh2aXJnaW4pIHsKICAgICAgICAgIHZhciBzeW07CiAgICAgICAgICBsZW5maXggPSBuZXcgdXRpbHMuQnVmMzIoNTEyKTsKICAgICAgICAgIGRpc3RmaXggPSBuZXcgdXRpbHMuQnVmMzIoMzIpOwogICAgICAgICAgc3ltID0gMDsKICAgICAgICAgIHdoaWxlIChzeW0gPCAxNDQpIHsKICAgICAgICAgICAgc3RhdGUubGVuc1tzeW0rK10gPSA4OwogICAgICAgICAgfQogICAgICAgICAgd2hpbGUgKHN5bSA8IDI1NikgewogICAgICAgICAgICBzdGF0ZS5sZW5zW3N5bSsrXSA9IDk7CiAgICAgICAgICB9CiAgICAgICAgICB3aGlsZSAoc3ltIDwgMjgwKSB7CiAgICAgICAgICAgIHN0YXRlLmxlbnNbc3ltKytdID0gNzsKICAgICAgICAgIH0KICAgICAgICAgIHdoaWxlIChzeW0gPCAyODgpIHsKICAgICAgICAgICAgc3RhdGUubGVuc1tzeW0rK10gPSA4OwogICAgICAgICAgfQogICAgICAgICAgaW5mbGF0ZV90YWJsZShMRU5TLCBzdGF0ZS5sZW5zLCAwLCAyODgsIGxlbmZpeCwgMCwgc3RhdGUud29yaywgeyBiaXRzOiA5IH0pOwogICAgICAgICAgc3ltID0gMDsKICAgICAgICAgIHdoaWxlIChzeW0gPCAzMikgewogICAgICAgICAgICBzdGF0ZS5sZW5zW3N5bSsrXSA9IDU7CiAgICAgICAgICB9CiAgICAgICAgICBpbmZsYXRlX3RhYmxlKERJU1RTLCBzdGF0ZS5sZW5zLCAwLCAzMiwgZGlzdGZpeCwgMCwgc3RhdGUud29yaywgeyBiaXRzOiA1IH0pOwogICAgICAgICAgdmlyZ2luID0gZmFsc2U7CiAgICAgICAgfQogICAgICAgIHN0YXRlLmxlbmNvZGUgPSBsZW5maXg7CiAgICAgICAgc3RhdGUubGVuYml0cyA9IDk7CiAgICAgICAgc3RhdGUuZGlzdGNvZGUgPSBkaXN0Zml4OwogICAgICAgIHN0YXRlLmRpc3RiaXRzID0gNTsKICAgICAgfQogICAgICBmdW5jdGlvbiB1cGRhdGV3aW5kb3coc3RybSwgc3JjLCBlbmQsIGNvcHkpIHsKICAgICAgICB2YXIgZGlzdDsKICAgICAgICB2YXIgc3RhdGUgPSBzdHJtLnN0YXRlOwogICAgICAgIGlmIChzdGF0ZS53aW5kb3cgPT09IG51bGwpIHsKICAgICAgICAgIHN0YXRlLndzaXplID0gMSA8PCBzdGF0ZS53Yml0czsKICAgICAgICAgIHN0YXRlLnduZXh0ID0gMDsKICAgICAgICAgIHN0YXRlLndoYXZlID0gMDsKICAgICAgICAgIHN0YXRlLndpbmRvdyA9IG5ldyB1dGlscy5CdWY4KHN0YXRlLndzaXplKTsKICAgICAgICB9CiAgICAgICAgaWYgKGNvcHkgPj0gc3RhdGUud3NpemUpIHsKICAgICAgICAgIHV0aWxzLmFycmF5U2V0KHN0YXRlLndpbmRvdywgc3JjLCBlbmQgLSBzdGF0ZS53c2l6ZSwgc3RhdGUud3NpemUsIDApOwogICAgICAgICAgc3RhdGUud25leHQgPSAwOwogICAgICAgICAgc3RhdGUud2hhdmUgPSBzdGF0ZS53c2l6ZTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgZGlzdCA9IHN0YXRlLndzaXplIC0gc3RhdGUud25leHQ7CiAgICAgICAgICBpZiAoZGlzdCA+IGNvcHkpIHsKICAgICAgICAgICAgZGlzdCA9IGNvcHk7CiAgICAgICAgICB9CiAgICAgICAgICB1dGlscy5hcnJheVNldChzdGF0ZS53aW5kb3csIHNyYywgZW5kIC0gY29weSwgZGlzdCwgc3RhdGUud25leHQpOwogICAgICAgICAgY29weSAtPSBkaXN0OwogICAgICAgICAgaWYgKGNvcHkpIHsKICAgICAgICAgICAgdXRpbHMuYXJyYXlTZXQoc3RhdGUud2luZG93LCBzcmMsIGVuZCAtIGNvcHksIGNvcHksIDApOwogICAgICAgICAgICBzdGF0ZS53bmV4dCA9IGNvcHk7CiAgICAgICAgICAgIHN0YXRlLndoYXZlID0gc3RhdGUud3NpemU7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBzdGF0ZS53bmV4dCArPSBkaXN0OwogICAgICAgICAgICBpZiAoc3RhdGUud25leHQgPT09IHN0YXRlLndzaXplKSB7CiAgICAgICAgICAgICAgc3RhdGUud25leHQgPSAwOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzdGF0ZS53aGF2ZSA8IHN0YXRlLndzaXplKSB7CiAgICAgICAgICAgICAgc3RhdGUud2hhdmUgKz0gZGlzdDsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gMDsKICAgICAgfQogICAgICBmdW5jdGlvbiBpbmZsYXRlKHN0cm0sIGZsdXNoKSB7CiAgICAgICAgdmFyIHN0YXRlOwogICAgICAgIHZhciBpbnB1dCwgb3V0cHV0OwogICAgICAgIHZhciBuZXh0OwogICAgICAgIHZhciBwdXQ7CiAgICAgICAgdmFyIGhhdmUsIGxlZnQ7CiAgICAgICAgdmFyIGhvbGQ7CiAgICAgICAgdmFyIGJpdHM7CiAgICAgICAgdmFyIF9pbiwgX291dDsKICAgICAgICB2YXIgY29weTsKICAgICAgICB2YXIgZnJvbTsKICAgICAgICB2YXIgZnJvbV9zb3VyY2U7CiAgICAgICAgdmFyIGhlcmUgPSAwOwogICAgICAgIHZhciBoZXJlX2JpdHMsIGhlcmVfb3AsIGhlcmVfdmFsOwogICAgICAgIHZhciBsYXN0X2JpdHMsIGxhc3Rfb3AsIGxhc3RfdmFsOwogICAgICAgIHZhciBsZW47CiAgICAgICAgdmFyIHJldDsKICAgICAgICB2YXIgaGJ1ZiA9IG5ldyB1dGlscy5CdWY4KDQpOwogICAgICAgIHZhciBvcHRzOwogICAgICAgIHZhciBuOwogICAgICAgIHZhciBvcmRlciA9IFsxNiwgMTcsIDE4LCAwLCA4LCA3LCA5LCA2LCAxMCwgNSwgMTEsIDQsIDEyLCAzLCAxMywgMiwgMTQsIDEsIDE1XTsKICAgICAgICBpZiAoIXN0cm0gfHwgIXN0cm0uc3RhdGUgfHwgIXN0cm0ub3V0cHV0IHx8ICFzdHJtLmlucHV0ICYmIHN0cm0uYXZhaWxfaW4gIT09IDApIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgc3RhdGUgPSBzdHJtLnN0YXRlOwogICAgICAgIGlmIChzdGF0ZS5tb2RlID09PSBUWVBFKSB7CiAgICAgICAgICBzdGF0ZS5tb2RlID0gVFlQRURPOwogICAgICAgIH0KICAgICAgICBwdXQgPSBzdHJtLm5leHRfb3V0OwogICAgICAgIG91dHB1dCA9IHN0cm0ub3V0cHV0OwogICAgICAgIGxlZnQgPSBzdHJtLmF2YWlsX291dDsKICAgICAgICBuZXh0ID0gc3RybS5uZXh0X2luOwogICAgICAgIGlucHV0ID0gc3RybS5pbnB1dDsKICAgICAgICBoYXZlID0gc3RybS5hdmFpbF9pbjsKICAgICAgICBob2xkID0gc3RhdGUuaG9sZDsKICAgICAgICBiaXRzID0gc3RhdGUuYml0czsKICAgICAgICBfaW4gPSBoYXZlOwogICAgICAgIF9vdXQgPSBsZWZ0OwogICAgICAgIHJldCA9IFpfT0s7CiAgICAgICAgaW5mX2xlYXZlOgogICAgICAgICAgZm9yICg7IDsgKSB7CiAgICAgICAgICAgIHN3aXRjaCAoc3RhdGUubW9kZSkgewogICAgICAgICAgICAgIGNhc2UgSEVBRDoKICAgICAgICAgICAgICAgIGlmIChzdGF0ZS53cmFwID09PSAwKSB7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBUWVBFRE87CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCAxNikgewogICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUud3JhcCAmIDIgJiYgaG9sZCA9PT0gMzU2MTUpIHsKICAgICAgICAgICAgICAgICAgc3RhdGUuY2hlY2sgPSAwOwogICAgICAgICAgICAgICAgICBoYnVmWzBdID0gaG9sZCAmIDI1NTsKICAgICAgICAgICAgICAgICAgaGJ1ZlsxXSA9IGhvbGQgPj4+IDggJiAyNTU7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmNoZWNrID0gY3JjMzIyKHN0YXRlLmNoZWNrLCBoYnVmLCAyLCAwKTsKICAgICAgICAgICAgICAgICAgaG9sZCA9IDA7CiAgICAgICAgICAgICAgICAgIGJpdHMgPSAwOwogICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gRkxBR1M7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUuZmxhZ3MgPSAwOwogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmhlYWQpIHsKICAgICAgICAgICAgICAgICAgc3RhdGUuaGVhZC5kb25lID0gZmFsc2U7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoIShzdGF0ZS53cmFwICYgMSkgfHwgKCgoaG9sZCAmIDI1NSkgPDwgOCkgKyAoaG9sZCA+PiA4KSkgJSAzMSkgewogICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbmNvcnJlY3QgaGVhZGVyIGNoZWNrIjsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoKGhvbGQgJiAxNSkgIT09IFpfREVGTEFURUQpIHsKICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAidW5rbm93biBjb21wcmVzc2lvbiBtZXRob2QiOwogICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEOwogICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGhvbGQgPj4+PSA0OwogICAgICAgICAgICAgICAgYml0cyAtPSA0OwogICAgICAgICAgICAgICAgbGVuID0gKGhvbGQgJiAxNSkgKyA4OwogICAgICAgICAgICAgICAgaWYgKHN0YXRlLndiaXRzID09PSAwKSB7CiAgICAgICAgICAgICAgICAgIHN0YXRlLndiaXRzID0gbGVuOwogICAgICAgICAgICAgICAgfSBlbHNlIGlmIChsZW4gPiBzdGF0ZS53Yml0cykgewogICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbnZhbGlkIHdpbmRvdyBzaXplIjsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5kbWF4ID0gMSA8PCBsZW47CiAgICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gc3RhdGUuY2hlY2sgPSAxOwogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IGhvbGQgJiA1MTIgPyBESUNUSUQgOiBUWVBFOwogICAgICAgICAgICAgICAgaG9sZCA9IDA7CiAgICAgICAgICAgICAgICBiaXRzID0gMDsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgIGNhc2UgRkxBR1M6CiAgICAgICAgICAgICAgICB3aGlsZSAoYml0cyA8IDE2KSB7CiAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0YXRlLmZsYWdzID0gaG9sZDsKICAgICAgICAgICAgICAgIGlmICgoc3RhdGUuZmxhZ3MgJiAyNTUpICE9PSBaX0RFRkxBVEVEKSB7CiAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gInVua25vd24gY29tcHJlc3Npb24gbWV0aG9kIjsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuZmxhZ3MgJiA1NzM0NCkgewogICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJ1bmtub3duIGhlYWRlciBmbGFncyBzZXQiOwogICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEOwogICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5oZWFkKSB7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmhlYWQudGV4dCA9IGhvbGQgPj4gOCAmIDE7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuZmxhZ3MgJiA1MTIpIHsKICAgICAgICAgICAgICAgICAgaGJ1ZlswXSA9IGhvbGQgJiAyNTU7CiAgICAgICAgICAgICAgICAgIGhidWZbMV0gPSBob2xkID4+PiA4ICYgMjU1OwogICAgICAgICAgICAgICAgICBzdGF0ZS5jaGVjayA9IGNyYzMyMihzdGF0ZS5jaGVjaywgaGJ1ZiwgMiwgMCk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBob2xkID0gMDsKICAgICAgICAgICAgICAgIGJpdHMgPSAwOwogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IFRJTUU7CiAgICAgICAgICAgICAgY2FzZSBUSU1FOgogICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCAzMikgewogICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuaGVhZCkgewogICAgICAgICAgICAgICAgICBzdGF0ZS5oZWFkLnRpbWUgPSBob2xkOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmZsYWdzICYgNTEyKSB7CiAgICAgICAgICAgICAgICAgIGhidWZbMF0gPSBob2xkICYgMjU1OwogICAgICAgICAgICAgICAgICBoYnVmWzFdID0gaG9sZCA+Pj4gOCAmIDI1NTsKICAgICAgICAgICAgICAgICAgaGJ1ZlsyXSA9IGhvbGQgPj4+IDE2ICYgMjU1OwogICAgICAgICAgICAgICAgICBoYnVmWzNdID0gaG9sZCA+Pj4gMjQgJiAyNTU7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmNoZWNrID0gY3JjMzIyKHN0YXRlLmNoZWNrLCBoYnVmLCA0LCAwKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGhvbGQgPSAwOwogICAgICAgICAgICAgICAgYml0cyA9IDA7CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gT1M7CiAgICAgICAgICAgICAgY2FzZSBPUzoKICAgICAgICAgICAgICAgIHdoaWxlIChiaXRzIDwgMTYpIHsKICAgICAgICAgICAgICAgICAgaWYgKGhhdmUgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaGF2ZS0tOwogICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmhlYWQpIHsKICAgICAgICAgICAgICAgICAgc3RhdGUuaGVhZC54ZmxhZ3MgPSBob2xkICYgMjU1OwogICAgICAgICAgICAgICAgICBzdGF0ZS5oZWFkLm9zID0gaG9sZCA+PiA4OwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmZsYWdzICYgNTEyKSB7CiAgICAgICAgICAgICAgICAgIGhidWZbMF0gPSBob2xkICYgMjU1OwogICAgICAgICAgICAgICAgICBoYnVmWzFdID0gaG9sZCA+Pj4gOCAmIDI1NTsKICAgICAgICAgICAgICAgICAgc3RhdGUuY2hlY2sgPSBjcmMzMjIoc3RhdGUuY2hlY2ssIGhidWYsIDIsIDApOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaG9sZCA9IDA7CiAgICAgICAgICAgICAgICBiaXRzID0gMDsKICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBFWExFTjsKICAgICAgICAgICAgICBjYXNlIEVYTEVOOgogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmZsYWdzICYgMTAyNCkgewogICAgICAgICAgICAgICAgICB3aGlsZSAoYml0cyA8IDE2KSB7CiAgICAgICAgICAgICAgICAgICAgaWYgKGhhdmUgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgaGF2ZS0tOwogICAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBzdGF0ZS5sZW5ndGggPSBob2xkOwogICAgICAgICAgICAgICAgICBpZiAoc3RhdGUuaGVhZCkgewogICAgICAgICAgICAgICAgICAgIHN0YXRlLmhlYWQuZXh0cmFfbGVuID0gaG9sZDsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBpZiAoc3RhdGUuZmxhZ3MgJiA1MTIpIHsKICAgICAgICAgICAgICAgICAgICBoYnVmWzBdID0gaG9sZCAmIDI1NTsKICAgICAgICAgICAgICAgICAgICBoYnVmWzFdID0gaG9sZCA+Pj4gOCAmIDI1NTsKICAgICAgICAgICAgICAgICAgICBzdGF0ZS5jaGVjayA9IGNyYzMyMihzdGF0ZS5jaGVjaywgaGJ1ZiwgMiwgMCk7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaG9sZCA9IDA7CiAgICAgICAgICAgICAgICAgIGJpdHMgPSAwOwogICAgICAgICAgICAgICAgfSBlbHNlIGlmIChzdGF0ZS5oZWFkKSB7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmhlYWQuZXh0cmEgPSBudWxsOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEVYVFJBOwogICAgICAgICAgICAgIGNhc2UgRVhUUkE6CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuZmxhZ3MgJiAxMDI0KSB7CiAgICAgICAgICAgICAgICAgIGNvcHkgPSBzdGF0ZS5sZW5ndGg7CiAgICAgICAgICAgICAgICAgIGlmIChjb3B5ID4gaGF2ZSkgewogICAgICAgICAgICAgICAgICAgIGNvcHkgPSBoYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChjb3B5KSB7CiAgICAgICAgICAgICAgICAgICAgaWYgKHN0YXRlLmhlYWQpIHsKICAgICAgICAgICAgICAgICAgICAgIGxlbiA9IHN0YXRlLmhlYWQuZXh0cmFfbGVuIC0gc3RhdGUubGVuZ3RoOwogICAgICAgICAgICAgICAgICAgICAgaWYgKCFzdGF0ZS5oZWFkLmV4dHJhKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHN0YXRlLmhlYWQuZXh0cmEgPSBuZXcgQXJyYXkoc3RhdGUuaGVhZC5leHRyYV9sZW4pOwogICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgdXRpbHMuYXJyYXlTZXQoc3RhdGUuaGVhZC5leHRyYSwgaW5wdXQsIG5leHQsIGNvcHksIGxlbik7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5mbGFncyAmIDUxMikgewogICAgICAgICAgICAgICAgICAgICAgc3RhdGUuY2hlY2sgPSBjcmMzMjIoc3RhdGUuY2hlY2ssIGlucHV0LCBjb3B5LCBuZXh0KTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgaGF2ZSAtPSBjb3B5OwogICAgICAgICAgICAgICAgICAgIG5leHQgKz0gY29weTsKICAgICAgICAgICAgICAgICAgICBzdGF0ZS5sZW5ndGggLT0gY29weTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBpZiAoc3RhdGUubGVuZ3RoKSB7CiAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5sZW5ndGggPSAwOwogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IE5BTUU7CiAgICAgICAgICAgICAgY2FzZSBOQU1FOgogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmZsYWdzICYgMjA0OCkgewogICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBjb3B5ID0gMDsKICAgICAgICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgICAgICAgIGxlbiA9IGlucHV0W25leHQgKyBjb3B5KytdOwogICAgICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5oZWFkICYmIGxlbiAmJiBzdGF0ZS5sZW5ndGggPCA2NTUzNikgewogICAgICAgICAgICAgICAgICAgICAgc3RhdGUuaGVhZC5uYW1lICs9IFN0cmluZy5mcm9tQ2hhckNvZGUobGVuKTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIH0gd2hpbGUgKGxlbiAmJiBjb3B5IDwgaGF2ZSk7CiAgICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5mbGFncyAmIDUxMikgewogICAgICAgICAgICAgICAgICAgIHN0YXRlLmNoZWNrID0gY3JjMzIyKHN0YXRlLmNoZWNrLCBpbnB1dCwgY29weSwgbmV4dCk7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaGF2ZSAtPSBjb3B5OwogICAgICAgICAgICAgICAgICBuZXh0ICs9IGNvcHk7CiAgICAgICAgICAgICAgICAgIGlmIChsZW4pIHsKICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAoc3RhdGUuaGVhZCkgewogICAgICAgICAgICAgICAgICBzdGF0ZS5oZWFkLm5hbWUgPSBudWxsOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUubGVuZ3RoID0gMDsKICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBDT01NRU5UOwogICAgICAgICAgICAgIGNhc2UgQ09NTUVOVDoKICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5mbGFncyAmIDQwOTYpIHsKICAgICAgICAgICAgICAgICAgaWYgKGhhdmUgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgY29weSA9IDA7CiAgICAgICAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICAgICAgICBsZW4gPSBpbnB1dFtuZXh0ICsgY29weSsrXTsKICAgICAgICAgICAgICAgICAgICBpZiAoc3RhdGUuaGVhZCAmJiBsZW4gJiYgc3RhdGUubGVuZ3RoIDwgNjU1MzYpIHsKICAgICAgICAgICAgICAgICAgICAgIHN0YXRlLmhlYWQuY29tbWVudCArPSBTdHJpbmcuZnJvbUNoYXJDb2RlKGxlbik7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICB9IHdoaWxlIChsZW4gJiYgY29weSA8IGhhdmUpOwogICAgICAgICAgICAgICAgICBpZiAoc3RhdGUuZmxhZ3MgJiA1MTIpIHsKICAgICAgICAgICAgICAgICAgICBzdGF0ZS5jaGVjayA9IGNyYzMyMihzdGF0ZS5jaGVjaywgaW5wdXQsIGNvcHksIG5leHQpOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGhhdmUgLT0gY29weTsKICAgICAgICAgICAgICAgICAgbmV4dCArPSBjb3B5OwogICAgICAgICAgICAgICAgICBpZiAobGVuKSB7CiAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKHN0YXRlLmhlYWQpIHsKICAgICAgICAgICAgICAgICAgc3RhdGUuaGVhZC5jb21tZW50ID0gbnVsbDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBIQ1JDOwogICAgICAgICAgICAgIGNhc2UgSENSQzoKICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5mbGFncyAmIDUxMikgewogICAgICAgICAgICAgICAgICB3aGlsZSAoYml0cyA8IDE2KSB7CiAgICAgICAgICAgICAgICAgICAgaWYgKGhhdmUgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgaGF2ZS0tOwogICAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBpZiAoaG9sZCAhPT0gKHN0YXRlLmNoZWNrICYgNjU1MzUpKSB7CiAgICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaGVhZGVyIGNyYyBtaXNtYXRjaCI7CiAgICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBob2xkID0gMDsKICAgICAgICAgICAgICAgICAgYml0cyA9IDA7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuaGVhZCkgewogICAgICAgICAgICAgICAgICBzdGF0ZS5oZWFkLmhjcmMgPSBzdGF0ZS5mbGFncyA+PiA5ICYgMTsKICAgICAgICAgICAgICAgICAgc3RhdGUuaGVhZC5kb25lID0gdHJ1ZTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0cm0uYWRsZXIgPSBzdGF0ZS5jaGVjayA9IDA7CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gVFlQRTsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgIGNhc2UgRElDVElEOgogICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCAzMikgewogICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gc3RhdGUuY2hlY2sgPSB6c3dhcDMyKGhvbGQpOwogICAgICAgICAgICAgICAgaG9sZCA9IDA7CiAgICAgICAgICAgICAgICBiaXRzID0gMDsKICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBESUNUOwogICAgICAgICAgICAgIGNhc2UgRElDVDoKICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5oYXZlZGljdCA9PT0gMCkgewogICAgICAgICAgICAgICAgICBzdHJtLm5leHRfb3V0ID0gcHV0OwogICAgICAgICAgICAgICAgICBzdHJtLmF2YWlsX291dCA9IGxlZnQ7CiAgICAgICAgICAgICAgICAgIHN0cm0ubmV4dF9pbiA9IG5leHQ7CiAgICAgICAgICAgICAgICAgIHN0cm0uYXZhaWxfaW4gPSBoYXZlOwogICAgICAgICAgICAgICAgICBzdGF0ZS5ob2xkID0gaG9sZDsKICAgICAgICAgICAgICAgICAgc3RhdGUuYml0cyA9IGJpdHM7CiAgICAgICAgICAgICAgICAgIHJldHVybiBaX05FRURfRElDVDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0cm0uYWRsZXIgPSBzdGF0ZS5jaGVjayA9IDE7CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gVFlQRTsKICAgICAgICAgICAgICBjYXNlIFRZUEU6CiAgICAgICAgICAgICAgICBpZiAoZmx1c2ggPT09IFpfQkxPQ0sgfHwgZmx1c2ggPT09IFpfVFJFRVMpIHsKICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGNhc2UgVFlQRURPOgogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmxhc3QpIHsKICAgICAgICAgICAgICAgICAgaG9sZCA+Pj49IGJpdHMgJiA3OwogICAgICAgICAgICAgICAgICBiaXRzIC09IGJpdHMgJiA3OwogICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQ0hFQ0s7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCAzKSB7CiAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0YXRlLmxhc3QgPSBob2xkICYgMTsKICAgICAgICAgICAgICAgIGhvbGQgPj4+PSAxOwogICAgICAgICAgICAgICAgYml0cyAtPSAxOwogICAgICAgICAgICAgICAgc3dpdGNoIChob2xkICYgMykgewogICAgICAgICAgICAgICAgICBjYXNlIDA6CiAgICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IFNUT1JFRDsKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgY2FzZSAxOgogICAgICAgICAgICAgICAgICAgIGZpeGVkdGFibGVzKHN0YXRlKTsKICAgICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gTEVOXzsKICAgICAgICAgICAgICAgICAgICBpZiAoZmx1c2ggPT09IFpfVFJFRVMpIHsKICAgICAgICAgICAgICAgICAgICAgIGhvbGQgPj4+PSAyOwogICAgICAgICAgICAgICAgICAgICAgYml0cyAtPSAyOwogICAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgY2FzZSAyOgogICAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBUQUJMRTsKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgY2FzZSAzOgogICAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImludmFsaWQgYmxvY2sgdHlwZSI7CiAgICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGhvbGQgPj4+PSAyOwogICAgICAgICAgICAgICAgYml0cyAtPSAyOwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgY2FzZSBTVE9SRUQ6CiAgICAgICAgICAgICAgICBob2xkID4+Pj0gYml0cyAmIDc7CiAgICAgICAgICAgICAgICBiaXRzIC09IGJpdHMgJiA3OwogICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCAzMikgewogICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoKGhvbGQgJiA2NTUzNSkgIT09IChob2xkID4+PiAxNiBeIDY1NTM1KSkgewogICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbnZhbGlkIHN0b3JlZCBibG9jayBsZW5ndGhzIjsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5sZW5ndGggPSBob2xkICYgNjU1MzU7CiAgICAgICAgICAgICAgICBob2xkID0gMDsKICAgICAgICAgICAgICAgIGJpdHMgPSAwOwogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IENPUFlfOwogICAgICAgICAgICAgICAgaWYgKGZsdXNoID09PSBaX1RSRUVTKSB7CiAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBjYXNlIENPUFlfOgogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IENPUFk7CiAgICAgICAgICAgICAgY2FzZSBDT1BZOgogICAgICAgICAgICAgICAgY29weSA9IHN0YXRlLmxlbmd0aDsKICAgICAgICAgICAgICAgIGlmIChjb3B5KSB7CiAgICAgICAgICAgICAgICAgIGlmIChjb3B5ID4gaGF2ZSkgewogICAgICAgICAgICAgICAgICAgIGNvcHkgPSBoYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChjb3B5ID4gbGVmdCkgewogICAgICAgICAgICAgICAgICAgIGNvcHkgPSBsZWZ0OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChjb3B5ID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIHV0aWxzLmFycmF5U2V0KG91dHB1dCwgaW5wdXQsIG5leHQsIGNvcHksIHB1dCk7CiAgICAgICAgICAgICAgICAgIGhhdmUgLT0gY29weTsKICAgICAgICAgICAgICAgICAgbmV4dCArPSBjb3B5OwogICAgICAgICAgICAgICAgICBsZWZ0IC09IGNvcHk7CiAgICAgICAgICAgICAgICAgIHB1dCArPSBjb3B5OwogICAgICAgICAgICAgICAgICBzdGF0ZS5sZW5ndGggLT0gY29weTsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gVFlQRTsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgIGNhc2UgVEFCTEU6CiAgICAgICAgICAgICAgICB3aGlsZSAoYml0cyA8IDE0KSB7CiAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0YXRlLm5sZW4gPSAoaG9sZCAmIDMxKSArIDI1NzsKICAgICAgICAgICAgICAgIGhvbGQgPj4+PSA1OwogICAgICAgICAgICAgICAgYml0cyAtPSA1OwogICAgICAgICAgICAgICAgc3RhdGUubmRpc3QgPSAoaG9sZCAmIDMxKSArIDE7CiAgICAgICAgICAgICAgICBob2xkID4+Pj0gNTsKICAgICAgICAgICAgICAgIGJpdHMgLT0gNTsKICAgICAgICAgICAgICAgIHN0YXRlLm5jb2RlID0gKGhvbGQgJiAxNSkgKyA0OwogICAgICAgICAgICAgICAgaG9sZCA+Pj49IDQ7CiAgICAgICAgICAgICAgICBiaXRzIC09IDQ7CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUubmxlbiA+IDI4NiB8fCBzdGF0ZS5uZGlzdCA+IDMwKSB7CiAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gInRvbyBtYW55IGxlbmd0aCBvciBkaXN0YW5jZSBzeW1ib2xzIjsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5oYXZlID0gMDsKICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBMRU5MRU5TOwogICAgICAgICAgICAgIGNhc2UgTEVOTEVOUzoKICAgICAgICAgICAgICAgIHdoaWxlIChzdGF0ZS5oYXZlIDwgc3RhdGUubmNvZGUpIHsKICAgICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCAzKSB7CiAgICAgICAgICAgICAgICAgICAgaWYgKGhhdmUgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgaGF2ZS0tOwogICAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBzdGF0ZS5sZW5zW29yZGVyW3N0YXRlLmhhdmUrK11dID0gaG9sZCAmIDc7CiAgICAgICAgICAgICAgICAgIGhvbGQgPj4+PSAzOwogICAgICAgICAgICAgICAgICBiaXRzIC09IDM7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB3aGlsZSAoc3RhdGUuaGF2ZSA8IDE5KSB7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmxlbnNbb3JkZXJbc3RhdGUuaGF2ZSsrXV0gPSAwOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUubGVuY29kZSA9IHN0YXRlLmxlbmR5bjsKICAgICAgICAgICAgICAgIHN0YXRlLmxlbmJpdHMgPSA3OwogICAgICAgICAgICAgICAgb3B0cyA9IHsgYml0czogc3RhdGUubGVuYml0cyB9OwogICAgICAgICAgICAgICAgcmV0ID0gaW5mbGF0ZV90YWJsZShDT0RFUywgc3RhdGUubGVucywgMCwgMTksIHN0YXRlLmxlbmNvZGUsIDAsIHN0YXRlLndvcmssIG9wdHMpOwogICAgICAgICAgICAgICAgc3RhdGUubGVuYml0cyA9IG9wdHMuYml0czsKICAgICAgICAgICAgICAgIGlmIChyZXQpIHsKICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW52YWxpZCBjb2RlIGxlbmd0aHMgc2V0IjsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5oYXZlID0gMDsKICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBDT0RFTEVOUzsKICAgICAgICAgICAgICBjYXNlIENPREVMRU5TOgogICAgICAgICAgICAgICAgd2hpbGUgKHN0YXRlLmhhdmUgPCBzdGF0ZS5ubGVuICsgc3RhdGUubmRpc3QpIHsKICAgICAgICAgICAgICAgICAgZm9yICg7IDsgKSB7CiAgICAgICAgICAgICAgICAgICAgaGVyZSA9IHN0YXRlLmxlbmNvZGVbaG9sZCAmICgxIDw8IHN0YXRlLmxlbmJpdHMpIC0gMV07CiAgICAgICAgICAgICAgICAgICAgaGVyZV9iaXRzID0gaGVyZSA+Pj4gMjQ7CiAgICAgICAgICAgICAgICAgICAgaGVyZV9vcCA9IGhlcmUgPj4+IDE2ICYgMjU1OwogICAgICAgICAgICAgICAgICAgIGhlcmVfdmFsID0gaGVyZSAmIDY1NTM1OwogICAgICAgICAgICAgICAgICAgIGlmIChoZXJlX2JpdHMgPD0gYml0cykgewogICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaWYgKGhlcmVfdmFsIDwgMTYpIHsKICAgICAgICAgICAgICAgICAgICBob2xkID4+Pj0gaGVyZV9iaXRzOwogICAgICAgICAgICAgICAgICAgIGJpdHMgLT0gaGVyZV9iaXRzOwogICAgICAgICAgICAgICAgICAgIHN0YXRlLmxlbnNbc3RhdGUuaGF2ZSsrXSA9IGhlcmVfdmFsOwogICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgIGlmIChoZXJlX3ZhbCA9PT0gMTYpIHsKICAgICAgICAgICAgICAgICAgICAgIG4gPSBoZXJlX2JpdHMgKyAyOwogICAgICAgICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCBuKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgIGhvbGQgPj4+PSBoZXJlX2JpdHM7CiAgICAgICAgICAgICAgICAgICAgICBiaXRzIC09IGhlcmVfYml0czsKICAgICAgICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5oYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImludmFsaWQgYml0IGxlbmd0aCByZXBlYXQiOwogICAgICAgICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEOwogICAgICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgIGxlbiA9IHN0YXRlLmxlbnNbc3RhdGUuaGF2ZSAtIDFdOwogICAgICAgICAgICAgICAgICAgICAgY29weSA9IDMgKyAoaG9sZCAmIDMpOwogICAgICAgICAgICAgICAgICAgICAgaG9sZCA+Pj49IDI7CiAgICAgICAgICAgICAgICAgICAgICBiaXRzIC09IDI7CiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIGlmIChoZXJlX3ZhbCA9PT0gMTcpIHsKICAgICAgICAgICAgICAgICAgICAgIG4gPSBoZXJlX2JpdHMgKyAzOwogICAgICAgICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCBuKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgIGhvbGQgPj4+PSBoZXJlX2JpdHM7CiAgICAgICAgICAgICAgICAgICAgICBiaXRzIC09IGhlcmVfYml0czsKICAgICAgICAgICAgICAgICAgICAgIGxlbiA9IDA7CiAgICAgICAgICAgICAgICAgICAgICBjb3B5ID0gMyArIChob2xkICYgNyk7CiAgICAgICAgICAgICAgICAgICAgICBob2xkID4+Pj0gMzsKICAgICAgICAgICAgICAgICAgICAgIGJpdHMgLT0gMzsKICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgbiA9IGhlcmVfYml0cyArIDc7CiAgICAgICAgICAgICAgICAgICAgICB3aGlsZSAoYml0cyA8IG4pIHsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGhhdmUgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgaGF2ZS0tOwogICAgICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgaG9sZCA+Pj49IGhlcmVfYml0czsKICAgICAgICAgICAgICAgICAgICAgIGJpdHMgLT0gaGVyZV9iaXRzOwogICAgICAgICAgICAgICAgICAgICAgbGVuID0gMDsKICAgICAgICAgICAgICAgICAgICAgIGNvcHkgPSAxMSArIChob2xkICYgMTI3KTsKICAgICAgICAgICAgICAgICAgICAgIGhvbGQgPj4+PSA3OwogICAgICAgICAgICAgICAgICAgICAgYml0cyAtPSA3OwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBpZiAoc3RhdGUuaGF2ZSArIGNvcHkgPiBzdGF0ZS5ubGVuICsgc3RhdGUubmRpc3QpIHsKICAgICAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImludmFsaWQgYml0IGxlbmd0aCByZXBlYXQiOwogICAgICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICB3aGlsZSAoY29weS0tKSB7CiAgICAgICAgICAgICAgICAgICAgICBzdGF0ZS5sZW5zW3N0YXRlLmhhdmUrK10gPSBsZW47CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUubW9kZSA9PT0gQkFEKSB7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmxlbnNbMjU2XSA9PT0gMCkgewogICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbnZhbGlkIGNvZGUgLS0gbWlzc2luZyBlbmQtb2YtYmxvY2siOwogICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEOwogICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0YXRlLmxlbmJpdHMgPSA5OwogICAgICAgICAgICAgICAgb3B0cyA9IHsgYml0czogc3RhdGUubGVuYml0cyB9OwogICAgICAgICAgICAgICAgcmV0ID0gaW5mbGF0ZV90YWJsZShMRU5TLCBzdGF0ZS5sZW5zLCAwLCBzdGF0ZS5ubGVuLCBzdGF0ZS5sZW5jb2RlLCAwLCBzdGF0ZS53b3JrLCBvcHRzKTsKICAgICAgICAgICAgICAgIHN0YXRlLmxlbmJpdHMgPSBvcHRzLmJpdHM7CiAgICAgICAgICAgICAgICBpZiAocmV0KSB7CiAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImludmFsaWQgbGl0ZXJhbC9sZW5ndGhzIHNldCI7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUuZGlzdGJpdHMgPSA2OwogICAgICAgICAgICAgICAgc3RhdGUuZGlzdGNvZGUgPSBzdGF0ZS5kaXN0ZHluOwogICAgICAgICAgICAgICAgb3B0cyA9IHsgYml0czogc3RhdGUuZGlzdGJpdHMgfTsKICAgICAgICAgICAgICAgIHJldCA9IGluZmxhdGVfdGFibGUoRElTVFMsIHN0YXRlLmxlbnMsIHN0YXRlLm5sZW4sIHN0YXRlLm5kaXN0LCBzdGF0ZS5kaXN0Y29kZSwgMCwgc3RhdGUud29yaywgb3B0cyk7CiAgICAgICAgICAgICAgICBzdGF0ZS5kaXN0Yml0cyA9IG9wdHMuYml0czsKICAgICAgICAgICAgICAgIGlmIChyZXQpIHsKICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW52YWxpZCBkaXN0YW5jZXMgc2V0IjsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gTEVOXzsKICAgICAgICAgICAgICAgIGlmIChmbHVzaCA9PT0gWl9UUkVFUykgewogICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgY2FzZSBMRU5fOgogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IExFTjsKICAgICAgICAgICAgICBjYXNlIExFTjoKICAgICAgICAgICAgICAgIGlmIChoYXZlID49IDYgJiYgbGVmdCA+PSAyNTgpIHsKICAgICAgICAgICAgICAgICAgc3RybS5uZXh0X291dCA9IHB1dDsKICAgICAgICAgICAgICAgICAgc3RybS5hdmFpbF9vdXQgPSBsZWZ0OwogICAgICAgICAgICAgICAgICBzdHJtLm5leHRfaW4gPSBuZXh0OwogICAgICAgICAgICAgICAgICBzdHJtLmF2YWlsX2luID0gaGF2ZTsKICAgICAgICAgICAgICAgICAgc3RhdGUuaG9sZCA9IGhvbGQ7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmJpdHMgPSBiaXRzOwogICAgICAgICAgICAgICAgICBpbmZsYXRlX2Zhc3Qoc3RybSwgX291dCk7CiAgICAgICAgICAgICAgICAgIHB1dCA9IHN0cm0ubmV4dF9vdXQ7CiAgICAgICAgICAgICAgICAgIG91dHB1dCA9IHN0cm0ub3V0cHV0OwogICAgICAgICAgICAgICAgICBsZWZ0ID0gc3RybS5hdmFpbF9vdXQ7CiAgICAgICAgICAgICAgICAgIG5leHQgPSBzdHJtLm5leHRfaW47CiAgICAgICAgICAgICAgICAgIGlucHV0ID0gc3RybS5pbnB1dDsKICAgICAgICAgICAgICAgICAgaGF2ZSA9IHN0cm0uYXZhaWxfaW47CiAgICAgICAgICAgICAgICAgIGhvbGQgPSBzdGF0ZS5ob2xkOwogICAgICAgICAgICAgICAgICBiaXRzID0gc3RhdGUuYml0czsKICAgICAgICAgICAgICAgICAgaWYgKHN0YXRlLm1vZGUgPT09IFRZUEUpIHsKICAgICAgICAgICAgICAgICAgICBzdGF0ZS5iYWNrID0gLTE7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5iYWNrID0gMDsKICAgICAgICAgICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgICAgICAgICBoZXJlID0gc3RhdGUubGVuY29kZVtob2xkICYgKDEgPDwgc3RhdGUubGVuYml0cykgLSAxXTsKICAgICAgICAgICAgICAgICAgaGVyZV9iaXRzID0gaGVyZSA+Pj4gMjQ7CiAgICAgICAgICAgICAgICAgIGhlcmVfb3AgPSBoZXJlID4+PiAxNiAmIDI1NTsKICAgICAgICAgICAgICAgICAgaGVyZV92YWwgPSBoZXJlICYgNjU1MzU7CiAgICAgICAgICAgICAgICAgIGlmIChoZXJlX2JpdHMgPD0gYml0cykgewogICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmIChoZXJlX29wICYmIChoZXJlX29wICYgMjQwKSA9PT0gMCkgewogICAgICAgICAgICAgICAgICBsYXN0X2JpdHMgPSBoZXJlX2JpdHM7CiAgICAgICAgICAgICAgICAgIGxhc3Rfb3AgPSBoZXJlX29wOwogICAgICAgICAgICAgICAgICBsYXN0X3ZhbCA9IGhlcmVfdmFsOwogICAgICAgICAgICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgICAgICAgICAgICBoZXJlID0gc3RhdGUubGVuY29kZVtsYXN0X3ZhbCArICgoaG9sZCAmICgxIDw8IGxhc3RfYml0cyArIGxhc3Rfb3ApIC0gMSkgPj4gbGFzdF9iaXRzKV07CiAgICAgICAgICAgICAgICAgICAgaGVyZV9iaXRzID0gaGVyZSA+Pj4gMjQ7CiAgICAgICAgICAgICAgICAgICAgaGVyZV9vcCA9IGhlcmUgPj4+IDE2ICYgMjU1OwogICAgICAgICAgICAgICAgICAgIGhlcmVfdmFsID0gaGVyZSAmIDY1NTM1OwogICAgICAgICAgICAgICAgICAgIGlmIChsYXN0X2JpdHMgKyBoZXJlX2JpdHMgPD0gYml0cykgewogICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaG9sZCA+Pj49IGxhc3RfYml0czsKICAgICAgICAgICAgICAgICAgYml0cyAtPSBsYXN0X2JpdHM7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmJhY2sgKz0gbGFzdF9iaXRzOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaG9sZCA+Pj49IGhlcmVfYml0czsKICAgICAgICAgICAgICAgIGJpdHMgLT0gaGVyZV9iaXRzOwogICAgICAgICAgICAgICAgc3RhdGUuYmFjayArPSBoZXJlX2JpdHM7CiAgICAgICAgICAgICAgICBzdGF0ZS5sZW5ndGggPSBoZXJlX3ZhbDsKICAgICAgICAgICAgICAgIGlmIChoZXJlX29wID09PSAwKSB7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBMSVQ7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKGhlcmVfb3AgJiAzMikgewogICAgICAgICAgICAgICAgICBzdGF0ZS5iYWNrID0gLTE7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBUWVBFOwogICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmIChoZXJlX29wICYgNjQpIHsKICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW52YWxpZCBsaXRlcmFsL2xlbmd0aCBjb2RlIjsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5leHRyYSA9IGhlcmVfb3AgJiAxNTsKICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBMRU5FWFQ7CiAgICAgICAgICAgICAgY2FzZSBMRU5FWFQ6CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuZXh0cmEpIHsKICAgICAgICAgICAgICAgICAgbiA9IHN0YXRlLmV4dHJhOwogICAgICAgICAgICAgICAgICB3aGlsZSAoYml0cyA8IG4pIHsKICAgICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIHN0YXRlLmxlbmd0aCArPSBob2xkICYgKDEgPDwgc3RhdGUuZXh0cmEpIC0gMTsKICAgICAgICAgICAgICAgICAgaG9sZCA+Pj49IHN0YXRlLmV4dHJhOwogICAgICAgICAgICAgICAgICBiaXRzIC09IHN0YXRlLmV4dHJhOwogICAgICAgICAgICAgICAgICBzdGF0ZS5iYWNrICs9IHN0YXRlLmV4dHJhOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUud2FzID0gc3RhdGUubGVuZ3RoOwogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IERJU1Q7CiAgICAgICAgICAgICAgY2FzZSBESVNUOgogICAgICAgICAgICAgICAgZm9yICg7IDsgKSB7CiAgICAgICAgICAgICAgICAgIGhlcmUgPSBzdGF0ZS5kaXN0Y29kZVtob2xkICYgKDEgPDwgc3RhdGUuZGlzdGJpdHMpIC0gMV07CiAgICAgICAgICAgICAgICAgIGhlcmVfYml0cyA9IGhlcmUgPj4+IDI0OwogICAgICAgICAgICAgICAgICBoZXJlX29wID0gaGVyZSA+Pj4gMTYgJiAyNTU7CiAgICAgICAgICAgICAgICAgIGhlcmVfdmFsID0gaGVyZSAmIDY1NTM1OwogICAgICAgICAgICAgICAgICBpZiAoaGVyZV9iaXRzIDw9IGJpdHMpIHsKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoKGhlcmVfb3AgJiAyNDApID09PSAwKSB7CiAgICAgICAgICAgICAgICAgIGxhc3RfYml0cyA9IGhlcmVfYml0czsKICAgICAgICAgICAgICAgICAgbGFzdF9vcCA9IGhlcmVfb3A7CiAgICAgICAgICAgICAgICAgIGxhc3RfdmFsID0gaGVyZV92YWw7CiAgICAgICAgICAgICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgICAgICAgICAgIGhlcmUgPSBzdGF0ZS5kaXN0Y29kZVtsYXN0X3ZhbCArICgoaG9sZCAmICgxIDw8IGxhc3RfYml0cyArIGxhc3Rfb3ApIC0gMSkgPj4gbGFzdF9iaXRzKV07CiAgICAgICAgICAgICAgICAgICAgaGVyZV9iaXRzID0gaGVyZSA+Pj4gMjQ7CiAgICAgICAgICAgICAgICAgICAgaGVyZV9vcCA9IGhlcmUgPj4+IDE2ICYgMjU1OwogICAgICAgICAgICAgICAgICAgIGhlcmVfdmFsID0gaGVyZSAmIDY1NTM1OwogICAgICAgICAgICAgICAgICAgIGlmIChsYXN0X2JpdHMgKyBoZXJlX2JpdHMgPD0gYml0cykgewogICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaG9sZCA+Pj49IGxhc3RfYml0czsKICAgICAgICAgICAgICAgICAgYml0cyAtPSBsYXN0X2JpdHM7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmJhY2sgKz0gbGFzdF9iaXRzOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaG9sZCA+Pj49IGhlcmVfYml0czsKICAgICAgICAgICAgICAgIGJpdHMgLT0gaGVyZV9iaXRzOwogICAgICAgICAgICAgICAgc3RhdGUuYmFjayArPSBoZXJlX2JpdHM7CiAgICAgICAgICAgICAgICBpZiAoaGVyZV9vcCAmIDY0KSB7CiAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImludmFsaWQgZGlzdGFuY2UgY29kZSI7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUub2Zmc2V0ID0gaGVyZV92YWw7CiAgICAgICAgICAgICAgICBzdGF0ZS5leHRyYSA9IGhlcmVfb3AgJiAxNTsKICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBESVNURVhUOwogICAgICAgICAgICAgIGNhc2UgRElTVEVYVDoKICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5leHRyYSkgewogICAgICAgICAgICAgICAgICBuID0gc3RhdGUuZXh0cmE7CiAgICAgICAgICAgICAgICAgIHdoaWxlIChiaXRzIDwgbikgewogICAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgc3RhdGUub2Zmc2V0ICs9IGhvbGQgJiAoMSA8PCBzdGF0ZS5leHRyYSkgLSAxOwogICAgICAgICAgICAgICAgICBob2xkID4+Pj0gc3RhdGUuZXh0cmE7CiAgICAgICAgICAgICAgICAgIGJpdHMgLT0gc3RhdGUuZXh0cmE7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmJhY2sgKz0gc3RhdGUuZXh0cmE7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUub2Zmc2V0ID4gc3RhdGUuZG1heCkgewogICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbnZhbGlkIGRpc3RhbmNlIHRvbyBmYXIgYmFjayI7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IE1BVENIOwogICAgICAgICAgICAgIGNhc2UgTUFUQ0g6CiAgICAgICAgICAgICAgICBpZiAobGVmdCA9PT0gMCkgewogICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBjb3B5ID0gX291dCAtIGxlZnQ7CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUub2Zmc2V0ID4gY29weSkgewogICAgICAgICAgICAgICAgICBjb3B5ID0gc3RhdGUub2Zmc2V0IC0gY29weTsKICAgICAgICAgICAgICAgICAgaWYgKGNvcHkgPiBzdGF0ZS53aGF2ZSkgewogICAgICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5zYW5lKSB7CiAgICAgICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbnZhbGlkIGRpc3RhbmNlIHRvbyBmYXIgYmFjayI7CiAgICAgICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEOwogICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChjb3B5ID4gc3RhdGUud25leHQpIHsKICAgICAgICAgICAgICAgICAgICBjb3B5IC09IHN0YXRlLnduZXh0OwogICAgICAgICAgICAgICAgICAgIGZyb20gPSBzdGF0ZS53c2l6ZSAtIGNvcHk7CiAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgZnJvbSA9IHN0YXRlLnduZXh0IC0gY29weTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBpZiAoY29weSA+IHN0YXRlLmxlbmd0aCkgewogICAgICAgICAgICAgICAgICAgIGNvcHkgPSBzdGF0ZS5sZW5ndGg7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgZnJvbV9zb3VyY2UgPSBzdGF0ZS53aW5kb3c7CiAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICBmcm9tX3NvdXJjZSA9IG91dHB1dDsKICAgICAgICAgICAgICAgICAgZnJvbSA9IHB1dCAtIHN0YXRlLm9mZnNldDsKICAgICAgICAgICAgICAgICAgY29weSA9IHN0YXRlLmxlbmd0aDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmIChjb3B5ID4gbGVmdCkgewogICAgICAgICAgICAgICAgICBjb3B5ID0gbGVmdDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGxlZnQgLT0gY29weTsKICAgICAgICAgICAgICAgIHN0YXRlLmxlbmd0aCAtPSBjb3B5OwogICAgICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgICAgICBvdXRwdXRbcHV0KytdID0gZnJvbV9zb3VyY2VbZnJvbSsrXTsKICAgICAgICAgICAgICAgIH0gd2hpbGUgKC0tY29weSk7CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUubGVuZ3RoID09PSAwKSB7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBMRU47CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICBjYXNlIExJVDoKICAgICAgICAgICAgICAgIGlmIChsZWZ0ID09PSAwKSB7CiAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIG91dHB1dFtwdXQrK10gPSBzdGF0ZS5sZW5ndGg7CiAgICAgICAgICAgICAgICBsZWZ0LS07CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gTEVOOwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgY2FzZSBDSEVDSzoKICAgICAgICAgICAgICAgIGlmIChzdGF0ZS53cmFwKSB7CiAgICAgICAgICAgICAgICAgIHdoaWxlIChiaXRzIDwgMzIpIHsKICAgICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgICAgaG9sZCB8PSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIF9vdXQgLT0gbGVmdDsKICAgICAgICAgICAgICAgICAgc3RybS50b3RhbF9vdXQgKz0gX291dDsKICAgICAgICAgICAgICAgICAgc3RhdGUudG90YWwgKz0gX291dDsKICAgICAgICAgICAgICAgICAgaWYgKF9vdXQpIHsKICAgICAgICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gc3RhdGUuY2hlY2sgPSBzdGF0ZS5mbGFncyA/IGNyYzMyMihzdGF0ZS5jaGVjaywgb3V0cHV0LCBfb3V0LCBwdXQgLSBfb3V0KSA6IGFkbGVyMzIoc3RhdGUuY2hlY2ssIG91dHB1dCwgX291dCwgcHV0IC0gX291dCk7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgX291dCA9IGxlZnQ7CiAgICAgICAgICAgICAgICAgIGlmICgoc3RhdGUuZmxhZ3MgPyBob2xkIDogenN3YXAzMihob2xkKSkgIT09IHN0YXRlLmNoZWNrKSB7CiAgICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW5jb3JyZWN0IGRhdGEgY2hlY2siOwogICAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaG9sZCA9IDA7CiAgICAgICAgICAgICAgICAgIGJpdHMgPSAwOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IExFTkdUSDsKICAgICAgICAgICAgICBjYXNlIExFTkdUSDoKICAgICAgICAgICAgICAgIGlmIChzdGF0ZS53cmFwICYmIHN0YXRlLmZsYWdzKSB7CiAgICAgICAgICAgICAgICAgIHdoaWxlIChiaXRzIDwgMzIpIHsKICAgICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChob2xkICE9PSAoc3RhdGUudG90YWwgJiA0Mjk0OTY3Mjk1KSkgewogICAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImluY29ycmVjdCBsZW5ndGggY2hlY2siOwogICAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaG9sZCA9IDA7CiAgICAgICAgICAgICAgICAgIGJpdHMgPSAwOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IERPTkU7CiAgICAgICAgICAgICAgY2FzZSBET05FOgogICAgICAgICAgICAgICAgcmV0ID0gWl9TVFJFQU1fRU5EOwogICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgIGNhc2UgQkFEOgogICAgICAgICAgICAgICAgcmV0ID0gWl9EQVRBX0VSUk9SOwogICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgIGNhc2UgTUVNOgogICAgICAgICAgICAgICAgcmV0dXJuIFpfTUVNX0VSUk9SOwogICAgICAgICAgICAgIGNhc2UgU1lOQzoKICAgICAgICAgICAgICBkZWZhdWx0OgogICAgICAgICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VSUk9SOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgc3RybS5uZXh0X291dCA9IHB1dDsKICAgICAgICBzdHJtLmF2YWlsX291dCA9IGxlZnQ7CiAgICAgICAgc3RybS5uZXh0X2luID0gbmV4dDsKICAgICAgICBzdHJtLmF2YWlsX2lu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N0YXRlLm1vZGUgPT09IENPUFlfID8gMjU2IDogMCk7CiAgICAgICAgaWYgKChfaW4gPT09IDAgJiYgX291dCA9PT0gMCB8fCBmbHVzaCA9PT0gWl9GSU5JU0gpICYmIHJldCA9PT0gWl9PSykgewogICAgICAgICAgcmV0ID0gWl9CVUZfRVJST1I7CiAgICAgICAgfQogICAgICAgIHJldHVybiByZXQ7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gaW5mbGF0ZUVuZChzdHJtKSB7CiAgICAgICAgaWYgKCFzdHJtIHx8ICFzdHJtLnN0YXRlKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIHZhciBzdGF0ZSA9IHN0cm0uc3RhdGU7CiAgICAgICAgaWYgKHN0YXRlLndpbmRvdykgewogICAgICAgICAgc3RhdGUud2luZG93ID0gbnVsbDsKICAgICAgICB9CiAgICAgICAgc3RybS5zdGF0ZSA9IG51bGw7CiAgICAgICAgcmV0dXJuIFpfT0s7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gaW5mbGF0ZUdldEhlYWRlcihzdHJtLCBoZWFkKSB7CiAgICAgICAgdmFyIHN0YXRlOwogICAgICAgIGlmICghc3RybSB8fCAhc3RybS5zdGF0ZSkgewogICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VSUk9SOwogICAgICAgIH0KICAgICAgICBzdGF0ZSA9IHN0cm0uc3RhdGU7CiAgICAgICAgaWYgKChzdGF0ZS53cmFwICYgMikgPT09IDApIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgc3RhdGUuaGVhZCA9IGhlYWQ7CiAgICAgICAgaGVhZC5kb25lID0gZmFsc2U7CiAgICAgICAgcmV0dXJuIFpfT0s7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gaW5mbGF0ZVNldERpY3Rpb25hcnkoc3RybSwgZGljdGlvbmFyeSkgewogICAgICAgIHZhciBkaWN0TGVuZ3RoID0gZGljdGlvbmFyeS5sZW5ndGg7CiAgICAgICAgdmFyIHN0YXRlOwogICAgICAgIHZhciBkaWN0aWQ7CiAgICAgICAgdmFyIHJldDsKICAgICAgICBpZiAoIXN0cm0gfHwgIXN0cm0uc3RhdGUpIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgc3RhdGUgPSBzdHJtLnN0YXRlOwogICAgICAgIGlmIChzdGF0ZS53cmFwICE9PSAwICYmIHN0YXRlLm1vZGUgIT09IERJQ1QpIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgaWYgKHN0YXRlLm1vZGUgPT09IERJQ1QpIHsKICAgICAgICAgIGRpY3RpZCA9IDE7CiAgICAgICAgICBkaWN0aWQgPSBhZGxlcjMyKGRpY3RpZCwgZGljdGlvbmFyeSwgZGljdExlbmd0aCwgMCk7CiAgICAgICAgICBpZiAoZGljdGlkICE9PSBzdGF0ZS5jaGVjaykgewogICAgICAgICAgICByZXR1cm4gWl9EQVRBX0VSUk9SOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXQgPSB1cGRhdGV3aW5kb3coc3RybSwgZGljdGlvbmFyeSwgZGljdExlbmd0aCwgZGljdExlbmd0aCk7CiAgICAgICAgaWYgKHJldCkgewogICAgICAgICAgc3RhdGUubW9kZSA9IE1FTTsKICAgICAgICAgIHJldHVybiBaX01FTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgc3RhdGUuaGF2ZWRpY3QgPSAxOwogICAgICAgIHJldHVybiBaX09LOwogICAgICB9CiAgICAgIGV4cG9ydHMuaW5mbGF0ZVJlc2V0ID0gaW5mbGF0ZVJlc2V0OwogICAgICBleHBvcnRzLmluZmxhdGVSZXNldDIgPSBpbmZsYXRlUmVzZXQyOwogICAgICBleHBvcnRzLmluZmxhdGVSZXNldEtlZXAgPSBpbmZsYXRlUmVzZXRLZWVw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ICAgIFpfTkVFRF9ESUNUOiAyLAogICAgICAgIFpfRVJSTk86IC0xLAogICAgICAgIFpfU1RSRUFNX0VSUk9SOiAtMiwKICAgICAgICBaX0RBVEFfRVJST1I6IC0zLAogICAgICAgIFpfQlVGX0VSUk9SOiAtNSwKICAgICAgICBaX05PX0NPTVBSRVNTSU9OOiAwLAogICAgICAgIFpfQkVTVF9TUEVFRDogMSwKICAgICAgICBaX0JFU1RfQ09NUFJFU1NJT046IDksCiAgICAgICAgWl9ERUZBVUxUX0NPTVBSRVNTSU9OOiAtMSwKICAgICAgICBaX0ZJTFRFUkVEOiAxLAogICAgICAgIFpfSFVGRk1BTl9PTkxZOiAyLAogICAgICAgIFpfUkxFOiAzLAogICAgICAgIFpfRklYRUQ6IDQsCiAgICAgICAgWl9ERUZBVUxUX1NUUkFURUdZOiAwLAogICAgICAgIFpfQklOQVJZOiAwLAogICAgICAgIFpfVEVYVDogMSwKICAgICAgICBaX1VOS05PV046IDIsCiAgICAgICAgWl9ERUZMQVRFRDogOAogICAgICB9OwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvZ3poZWFkZXIuanMKICB2YXIgcmVxdWlyZV9nemhlYWRlciA9IF9fY29tbW9uSlMoewogICAgIm5vZGVfbW9kdWxlcy8ucG5wbS9wYWtvQDEuMC4xMS9ub2RlX21vZHVsZXMvcGFrby9saWIvemxpYi9nemhlYWRlci5qcyIoZXhwb3J0cywgbW9kdWxlKSB7CiAgICAgIGluaXRfYnVmZmVyX3NoaW0oKTsKICAgICAgInVzZSBzdHJpY3QiOwogICAgICBmdW5jdGlvbiBHWmhlYWRlcigpIHsKICAgICAgICB0aGlzLnRleHQgPSAwOwogICAgICAgIHRoaXMudGltZSA9IDA7CiAgICAgICAgdGhpcy54ZmxhZ3MgPSAwOwogICAgICAgIHRoaXMub3MgPSAwOwogICAgICAgIHRoaXMuZXh0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JuIG5ldyBJbmZsYXRlMihvcHRpb25zKTsKICAgICAgICB0aGlzLm9wdGlvbnMgPSB1dGlscy5hc3NpZ24oewogICAgICAgICAgY2h1bmtTaXplOiAxNjM4NCwKICAgICAgICAgIHdpbmRvd0JpdHM6IDAsCiAgICAgICAgICB0bzogIiIKICAgICAgICB9LCBvcHRpb25zIHx8IHt9KTsKICAgICAgICB2YXIgb3B0ID0gdGhpcy5vcHRpb25zOwogICAgICAgIGlmIChvcHQucmF3ICYmIG9wdC53aW5kb3dCaXRzID49IDAgJiYgb3B0LndpbmRvd0JpdHMgPCAxNikgewogICAgICAgICAgb3B0LndpbmRvd0JpdHMgPSAtb3B0LndpbmRvd0JpdHM7CiAgICAgICAgICBpZiAob3B0LndpbmRvd0JpdHMgPT09IDApIHsKICAgICAgICAgICAgb3B0LndpbmRvd0JpdHMgPSAtMTU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChvcHQud2luZG93Qml0cyA+PSAwICYmIG9wdC53aW5kb3dCaXRzIDwgMTYgJiYgIShvcHRpb25zICYmIG9wdGlvbnMud2luZG93Qml0cykpIHsKICAgICAgICAgIG9wdC53aW5kb3dCaXRzICs9IDMyOwogICAgICAgIH0KICAgICAgICBpZiAob3B0LndpbmRvd0JpdHMgPiAxNSAmJiBvcHQud2luZG93Qml0cyA8IDQ4KSB7CiAgICAgICAgICBpZiAoKG9wdC53aW5kb3dCaXRzICYgMTUpID09PSAwKSB7CiAgICAgICAgICAgIG9wdC53aW5kb3dCaXRzIHw9IDE1OwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICB0aGlzLmVyciA9IDA7CiAgICAgICAgdGhpcy5tc2cgPSAiIjsKICAgICAgICB0aGlzLmVuZGVkID0gZmFsc2U7CiAgICAgICAgdGhpcy5jaHVua3MgPSBbXTsKICAgICAgICB0aGlzLnN0cm0gPSBuZXcgWlN0cmVhbSgpOwogICAgICAgIHRoaXMuc3RybS5hdmFpbF9vdXQgPSAwOwogICAgICAgIHZhciBzdGF0dXMgPSB6bGliX2luZmxhdGUuaW5mbGF0ZUluaXQyKHRoaXMuc3RybSwgb3B0LndpbmRvd0JpdHMpOwogICAgICAgIGlmIChzdGF0dXMgIT09IGMuWl9PSykgewogICAgICAgICAgdGhyb3cgbmV3IEVycm9yKG1zZ1tzdGF0dXNdKTsKICAgICAgICB9CiAgICAgICAgdGhpcy5oZWFkZXIgPSBuZXcgR1poZWFkZXIoKTsKICAgICAgICB6bGliX2luZmxhdGUuaW5mbGF0ZUdldEhlYWRlcih0aGlzLnN0cm0sIHRoaXMuaGVhZGVyKTsKICAgICAgICBpZiAob3B0LmRpY3Rpb25hcnkpIHsKICAgICAgICAgIGlmICh0eXBlb2Ygb3B0LmRpY3Rpb25hcnkgPT09ICJzdHJpbmciKSB7CiAgICAgICAgICAgIG9wdC5kaWN0aW9uYXJ5ID0gc3RyaW5ncy5zdHJpbmcyYnVmKG9wdC5kaWN0aW9uYXJ5KTsKICAgICAgICAgIH0gZWxzZSBpZiAodG9TdHJpbmcuY2FsbChvcHQuZGljdGlvbmFyeSkgPT09ICJbb2JqZWN0IEFycmF5QnVmZmVyXSIpIHsKICAgICAgICAgICAgb3B0LmRpY3Rpb25hcnkgPSBuZXcgVWludDhBcnJheShvcHQuZGljdGlvbmFyeSk7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAob3B0LnJhdykgewogICAgICAgICAgICBzdGF0dXMgPSB6bGliX2luZmxhdGUuaW5mbGF0ZVNldERpY3Rpb25hcnkodGhpcy5zdHJtLCBvcHQuZGljdGlvbmFyeSk7CiAgICAgICAgICAgIGlmIChzdGF0dXMgIT09IGMuWl9PSykgewogICAgICAgICAgICAgIHRocm93IG5ldyBFcnJvcihtc2dbc3RhdHVzXSk7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgICAgSW5mbGF0ZTIucHJvdG90eXBlLnB1c2ggPSBmdW5jdGlvbihkYXRhLCBtb2RlKSB7CiAgICA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HN0cm0ub3V0cHV0LCBzdHJtLm5leHRfb3V0KTsKICAgICAgICAgICAgICAgIHRhaWwgPSBzdHJtLm5leHRfb3V0IC0gbmV4dF9vdXRfdXRmODsKICAgICAgICAgICAgICAgIHV0ZjhzdHIgPSBzdHJpbmdzLmJ1ZjJzdHJpbmcoc3RybS5vdXRwdXQsIG5leHRfb3V0X3V0ZjgpOwogICAgICAgICAgICAgICAgc3RybS5uZXh0X291dCA9IHRhaWw7CiAgICAgICAgICAgICAgICBzdHJtLmF2YWlsX291dCA9IGNodW5rU2l6ZSAtIHRhaWw7CiAgICAgICAgICAgICAgICBpZiAodGFpbCkgewogICAgICAgICAgICAgICAgICB1dGlscy5hcnJheVNldChzdHJtLm91dHB1dCwgc3RybS5vdXRwdXQsIG5leHRfb3V0X3V0ZjgsIHRhaWwsIDApOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgdGhpcy5vbkRhdGEodXRmOHN0cik7CiAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIHRoaXMub25EYXRhKHV0aWxzLnNocmlua0J1ZihzdHJtLm91dHB1dCwgc3RybS5uZXh0X291dCkpOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgaWYgKHN0cm0uYXZhaWxfaW4gPT09IDAgJiYgc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgYWxsb3dCdWZFcnJvciA9IHRydWU7CiAgICAgICAgICB9CiAgICAgICAgfSB3aGlsZSAoKHN0cm0uYXZhaWxfaW4gPiAwIHx8IHN0cm0uYXZhaWxfb3V0ID09PSAwKSAmJiBzdGF0dXMgIT09IGMuWl9TVFJFQU1fRU5EKTsKICAgICAgICBpZiAoc3RhdHVzID09PSBjLlpfU1RSRUFNX0VORCkgewogICAgICAgICAgX21vZGUgPSBjLlpfRklOSVNIOwogICAgICAgIH0KICAgICAgICBpZiAoX21vZGUgPT09IGMuWl9GSU5JU0gpIHsKICAgICAgICAgIHN0YXR1cyA9IHpsaWJfaW5mbGF0ZS5pbmZsYXRlRW5kKHRoaXMuc3RybSk7CiAgICAgICAgICB0aGlzLm9uRW5kKHN0YXR1cyk7CiAgICAgICAgICB0aGlzLmVuZGVkID0gdHJ1ZTsKICAgICAgICAgIHJldHVybiBzdGF0dXMgPT09IGMuWl9PSzsKICAgICAgICB9CiAgICAgICAgaWYgKF9tb2RlID09PSBjLlpfU1lOQ19GTFVTSCkgewogICAgICAgICAgdGhpcy5vbkVuZChjLlpfT0spOwogICAgICAgICAgc3RybS5hdmFpbF9vdXQgPSAwOwogICAgICAgICAgcmV0dXJuIHRydWU7CiAgICAgICAgfQogICAgICAgIHJldHVybiB0cnVlOwogICAgICB9OwogICAgICBJbmZsYXRlMi5wcm90b3R5cGUub25EYXRhID0gZnVuY3Rpb24oY2h1bmspIHsKICAgICAgICB0aGlzLmNodW5rcy5wdXNoKGNodW5rKTsKICAgICAgfTsKICAgICAgSW5mbGF0ZTIucHJvdG90eXBlLm9uRW5kID0gZnVuY3Rpb24oc3RhdHVzKSB7CiAgICAgICAgaWYgKHN0YXR1cyA9PT0gYy5aX09LKSB7CiAgICAgICAgICBpZiAodGhpcy5vcHRpb25zLnRvID09PSAic3RyaW5nIikgewogICAgICAgICAgICB0aGlzLnJlc3VsdCA9IHRoaXMuY2h1bmtzLmpvaW4oIiIpOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgdGhpcy5yZXN1bHQgPSB1dGlscy5mbGF0dGVuQ2h1bmtzKHRoaXMuY2h1bmtzKTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgdGhpcy5jaHVua3MgPSBbXTsKICAgICAgICB0aGlzLmVyciA9IHN0YXR1czsKICAgICAgICB0aGlzLm1zZyA9IHRoaXMuc3RybS5tc2c7CiAgICAgIH07CiAgICAgIGZ1bmN0aW9uIGluZmxhdGUoaW5wdXQsIG9wdGlvbnMpIHsKICAgICAgICB2YXIgaW5mbGF0b3Ig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g5MDE2NjQ4LAogICAgICAgIDIyMjcwNjEyMTQsCiAgICAgICAgNDUwNTQ4ODYxLAogICAgICAgIDE4NDMyNTg2MDMsCiAgICAgICAgNDEwNzU4MDc1MywKICAgICAgICAyMjExNjc3NjM5LAogICAgICAgIDMyNTg4Mzk5MCwKICAgICAgICAxNjg0Nzc3MTUyLAogICAgICAgIDQyNTExMjIwNDIsCiAgICAgICAgMjMyMTkyNjYzNiwKICAgICAgICAzMzU2MzM0ODcsCiAgICAgICAgMTY2MTM2NTQ2NSwKICAgICAgICA0MTk1MzAyNzU1LAogICAgICAgIDIzNjYxMTUzMTcsCiAgICAgICAgOTk3MDczMDk2LAogICAgICAgIDEyODE5NTM4ODYsCiAgICAgICAgMzU3OTg1NTMzMiwKICAgICAgICAyNzI0Njg4MjQyLAogICAgICAgIDEwMDY4ODgxNDUsCiAgICAgICAgMTI1ODYwNzY4NywKICAgICAgICAzNTI0MTAxNjI5LAogICAgICAgIDI3Njg5NDI0NDMsCiAgICAgICAgOTAxMDk3NzIyLAogICAgICAgIDExMTkwMDA2ODQsCiAgICAgICAgMzY4NjUxNzIwNiwKICAgICAgICAyODk4MDY1NzI4LAogICAgICAgIDg1MzA0NDQ1MSwKICAgICAgICAxMTcyMjY2MTAxLAogICAgICAgIDM3MDUwMTU3NTksCiAgICAgICAgMjg4MjYxNjY2NSwKICAgICAgICA2NTE3Njc5ODAsCiAgICAgICAgMTM3MzUwMzU0NiwKICAgICAgICAzMzY5NTU0MzA0LAogICAgICAgIDMyMTgxMDQ1OTgsCiAgICAgICAgNTY1NTA3MjUzLAogICAgICAgIDE0NTQ2MjE3MzEsCiAgICAgICAgMzQ4NTExMTcwNSwKICAgICAgICAzMDk5NDM2MzAzLAogICAgICAgIDY3MTI2Njk3NCwKICAgICAgICAxNTk0MTk4MDI0LAogICAgICAgIDMzMjI3MzA5MzAsCiAgICAgICAgMjk3MDM0NzgxMiwKICAgICAgICA3OTU4MzU1MjcsCiAgICAgICAgMTQ4MzIzMDIyNSwKICAgICAgICAzMjQ0MzY3Mjc1LAogICAgICAgIDMwNjAxNDk1NjUsCiAgICAgICAgMTk5NDE0NjE5MiwKICAgICAgICAzMTE1ODUzNCwKICAgICAgICAyNTYzOTA3NzcyLAogICAgICAgIDQwMjM3MTc5MzAsCiAgICAgICAgMTkwNzQ1OTQ2NSwKICAgICAgICAxMTI2MzcyMTUsCiAgICAgICAgMjY4MDE1MzI1MywKICAgICAgICAzOTA0NDI3MDU5LAogICAgICAgIDIwMTM3NzYyOTAsCiAgICAgICAgMjUxNzIyMDM2LAogICAgICAgIDI1MTcyMTUzNzQsCiAgICAgICAgMzc3NTgzMDA0MCwKICAgICAgICAyMTM3NjU2NzYzLAogICAgICAgIDE0MTM3NjgxMywKICAgICAgICAyNDM5Mjc3NzE5LAogICAgICAgIDM4NjUyNzEyOTcsCiAgICAgICAgMTgwMjE5NTQ0NCwKICAgICAgICA0NzY4NjQ4NjYsCiAgICAgICAgMjIzODAwMTM2OCwKICAgICAgICA0MDY2NTA4ODc4LAogICAgICAgIDE4MTIzNzA5MjUsCiAgICAgICAgNDUzMDkyNzMxLAogICAgICAgIDIxODE2MjUwMjUsCiAgICAgICAgNDExMTQ1MTIyMywKICAgICAgICAxNzA2MDg4OTAyLAogICAgICAgIDMxNDA0MjcwNCwKICAgICAgICAyMzQ0NTMyMjAyLAogICAgICAgIDQyNDAwMTc1MzIsCiAgICAgICAgMTY1ODY1ODI3MSwKICAgICAgICAzNjY2MTk5NzcsCiAgICAgICAgMjM2MjY3MDMyMywKICAgICAgICA0MjI0OTk0NDA1LAogICAgICAgIDEzMDM1MzU5NjAsCiAgICAgICAgOTg0OTYxNDg2LAogICAgICAgIDI3NDcwMDcwOTIsCiAgICAgICAgMzU2OTAzNzUzOCwKICAgICAgICAxMjU2MTcwODE3LAogICAgICAgIDEwMzc2MDQzMTEsCiAgICAgICAgMjc2NTIxMDczMywKICAgICAgICAzNTU0MDc5OTk1LAogICAgICAgIDExMzEwMTQ1MDYsCiAgICAgICAgODc5Njc5OTk2LAogICAgICAgIDI5MDkyNDM0NjIsCiAgICAgICAgMzY2Mzc3MTg1NiwKICAgICAgICAxMTQxMTI0NDY3LAogICAgICAgIDg1NTg0MjI3NywKICAgICAgICAyODUyODAxNjMxLAogICAgICAgIDM3MDg2NDg2NDksCiAgICAgICAgMTM0MjUzMzk0OCwKICAgICAgICA2NTQ0NTkzMDYsCiAgICAgICAgMzE4ODM5NjA0OCwKICAgICAgICAzMzczMDE1MTc0LAogICAgICAgIDE0NjY0Nzk5MDksCiAgICAgICAgNTQ0MTc5NjM1LAogICAgICAgIDMxMTA1MjM5MTMsCiAgICAgICAgMzQ2MjUyMjAxNSwKICAgICAgICAxNTkxNjcxMDU0LAogICAgICAgIDcwMjEzODc3NiwKICAgICAgICAyOTY2NDYwNDUwLAogICAgICAgIDMzNTI3OTk0MTIsCiAgICAgICAgMTUwNDkxODgwNywKICAgICAgICA3ODM1NTE4NzMsCiAgICAgICAgMzA4MjY0MDQ0MywKICAgICAgICAzMjMzNDQyOTg5LAogICAgICAgIDM5ODgyOTIzODQsCiAgICAgICAgMjU5NjI1NDY0NiwKICAgICAgICA2MjMxNzA2OCwKICAgICAgICAxOTU3ODEwODQyLAogICAgICAgIDM5Mzk4NDU5NDUsCiAgICAgICAgMjY0NzgxNjExMSwKICAgICAgICA4MTQ3MDk5NywKICAgICAgICAxOTQzODAzNTIzLAogICAgICAgIDM4MTQ5MTg5MzAsCiAgICAgICAgMjQ4OTU5NjgwNCwKICAgICAgICAyMjUyNzQ0MzAsCiAgICAgICAgMjA1Mzc5MDM3NiwKICAgICAgICAzODI2MTc1NzU1LAogICAgICAgIDI0NjY5MDYwMTMsCiAgICAgICAgMTY3ODE2NzQzLAogICAgICAgIDIwOTc2NTEzNzcsCiAgICAgICAgNDAyNzU1MjU4MCwKICAgICAgICAyMjY1NDkwMzg2LAogICAgICAgIDUwMzQ0NDA3MiwKICAgICAgICAxNzYyMDUwODE0LAogICAgICAgIDQxNTA0MTcyNDUsCiAgICAgICAgMjE1NDEyOTM1NSwKICAgICAgICA0MjY1MjIyMjUsCiAgICAgICAgMTg1MjUwNzg3OSwKICAgICAgICA0Mjc1MzEzNTI2LAogICAgICAgIDIzMTIzMTc5MjAsCiAgICAgICAgMjgyNzUzNjI2LAogICAgICAgIDE3NDI1NTU4NTIsCiAgICAgICAgNDE4OTcwODE0MywKICAgICAgICAyMzk0ODc3OTQ1LAogICAgICAgIDM5NzkxNzc2MywKICAgICAgICAxNjIyMTgzNjM3LAogICAgICAgIDM2MDQzOTA4ODgsCiAgICAgICAgMjcxNDg2NjU1OCwKICAgICAgICA5NTM3Mjk3MzIsCiAgICAgICAgMTM0MDA3NjYyNiwKICAgICAgICAzNTE4NzE5OTg1LAogICAgICAgIDI3OTczNjA5OTksCiAgICAgICAgMTA2ODgyODM4MSwKICAgICAgICAxMjE5NjM4ODU5LAogICAgICAgIDM2MjQ3NDE4NTAsCiAgICAgICAgMjkzNjY3NTE0OCwKICAgICAgICA5MDYxODU0NjIsCiAgICAgICAgMTA5MDgxMjUxMiwKICAgICAgICAzNzQ3NjcyMDAzLAogICAgICAgIDI4MjUzNzk2NjksCiAgICAgICAgODI5MzI5MTM1LAogICAgICAgIDExODEzMzUxNjEsCiAgICAgICAgMzQxMjE3NzgwNCwKICAgICAgICAzMTYwODM0ODQyLAogICAgICAgIDYyODA4NTQwOCwKICAgICAgICAxMzgyNjA1MzY2LAogICAgICAgIDM0MjMzNjkxMDksCiAgICAgICAgMzEzODA3ODQ2NywKICAgICAgICA1NzA1NjIyMzMsCiAgICAgICAgMTQyNjQwMDgxNSwKICAgICAgICAzMzE3MzE2NTQyLAogICAgICAgIDI5OTg3MzM2MDgsCiAgICAgICAgNzMzMjM5OTU0LAogICAgICAgIDE1NTUyNjE5NTYsCiAgICAgICAgMzI2ODkzNTU5MSwKICAgICAgICAzMDUwMzYwNjI1LAogICAgICAgIDc1MjQ1OTQwMywKICAgICAgICAxNTQxMzIwMjIxLAogICAgICAgIDI2MDcwNzE5MjAsCiAgICAgICAgMzk2NTk3MzAzMCwKICAgICAgICAxOTY5OTIyOTcyLAogICAgICAgIDQwNzM1NDk4LAogICAgICAgIDI2MTc4MzcyMjUsCiAgICAgICAgMzk0MzU3NzE1MSwKICAgICAgICAxOTEzMDg3ODc3LAogICAgICAgIDgzOTA4MzcxLAogICAgICAgIDI1MTIzNDE2MzQsCiAgICAgICAgMzgwMzc0MDY5MiwKICAgICAgICAyMDc1MjA4NjIyLAogICAgICAgIDIxMzI2MTExMiwKICAgICAgICAyNDYzMjcyNjAzLAogICAgICAgIDM4NTU5OTAyODUsCiAgICAgICAgMjA5NDg1NDA3MSwKICAgICAgICAxOTg5NTg4ODEsCiAgICAgICAgMjI2MjAyOTAxMiwKICAgICAgICA0MDU3MjYwNjEwLAogICAgICAgIDE3NTkzNTk5OTIsCiAgICAgICAgNTM0NDE0MTkwLAogICAgICAgIDIxNzY3MTg1NDEsCiAgICAgICAgNDEzOTMyOTExNSwKICAgICAgICAxODczODM2MDAxLAogICAgICAgIDQxNDY2NDU2NywKICAgICAgICAyMjgyMjQ4OTM0LAogICAgICAgIDQyNzkyMDAzNjgsCiAgICAgICAgMTcxMTY4NDU1NCwKICAgICAgICAyODUyODExMTYsCiAgICAgICAgMjQwNTgwMTcyNywKICAgICAgICA0MTY3MjE2NzQ1LAogICAgICAgIDE2MzQ0Njc3OTUsCiAgICAgICAgMzc2MjI5NzAxLAogICAgICAgIDI2ODUwNjc4OTYsCiAgICAgICAgMzYwODAwNzQwNiwKICAgICAgICAxMzA4OTE4NjEyLAogICAgICAgIDk1NjU0MzkzOCwKICAgICAgICAyODA4NTU1MTA1LAogICAgICAgIDM0OTU5NTgyNjMsCiAgICAgICAgMTIzMTYzNjMwMSwKICAgICAgICAxMDQ3NDI3MDM1LAogICAgICAgIDI5MzI5NTk4MTgsCiAgICAgICAgMzY1NDcwMzgzNiwKICAgICAgICAxMDg4MzU5MjcwLAogICAgICAgIDkzNjkxOGUzLAog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jMzIyLnNpZ25lZCA9IGZ1bmN0aW9uKCkgewogICAgICAgIHJldHVybiBfY3JjMzIuYXBwbHkobnVsbCwgYXJndW1lbnRzKTsKICAgICAgfTsKICAgICAgY3JjMzIyLnVuc2lnbmVkID0gZnVuY3Rpb24oKSB7CiAgICAgICAgcmV0dXJuIF9jcmMzMi5hcHBseShudWxsLCBhcmd1bWVudHMpID4+PiAwOwogICAgICB9OwogICAgICBtb2R1bGUuZXhwb3J0cyA9IGNyYzMyMjsKICAgIH0KICB9KTsKCiAgLy8gbm9kZV9tb2R1bGVzLy5wbnBtL29iamVjdC5lbnRyaWVzLXBvbnlmaWxsQDEuMC4xL25vZGVfbW9kdWxlcy9vYmplY3QuZW50cmllcy1wb255ZmlsbC9lbnRyaWVzLmpzCiAgdmFyIHJlcXVpcmVfZW50cmllcyA9IF9fY29tbW9uSlMoewogICAgIm5vZGVfbW9kdWxlcy8ucG5wbS9vYmplY3QuZW50cmllcy1wb255ZmlsbEAxLjAuMS9ub2RlX21vZHVsZXMvb2JqZWN0LmVudHJpZXMtcG9ueWZpbGwvZW50cmllcy5qcyIoZXhwb3J0cywgbW9kdWxlKSB7CiAgICAgIGluaXRfYnVmZmVyX3NoaW0oKTsKICAgICAgInVzZSBzdHJpY3QiOwogICAgICB2YXIgaGFzID0gZnVuY3Rpb24ob2JqLCBwcm9wKSB7CiAgICAgICAgcmV0dXJuIE9iamVjdC5wcm90b3R5cGUuaGFzT3duUHJvcGVydHkuY2FsbChvYmosIHByb3ApOwogICAgICB9OwogICAgICB2YXIgaXNFbnVtZXJhYmxlID0gZnVuY3Rpb24ob2JqLCBwcm9wKSB7CiAgICAgICAgcmV0dXJuIE9iamVjdC5wcm90b3R5cGUucHJvcGVydHlJc0VudW1lcmFibGUuY2FsbChvYmosIHByb3ApOwogICAgICB9OwogICAgICBmdW5jdGlvbiBlbnRyaWVzMihvYmopIHsKICAgICAgICBpZiAob2JqID09IG51bGwpIHsKICAgICAgICAgIHRocm93IG5ldyBU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ICB9KTsKICAgICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkoc3ViQ2xhc3MsICJwcm90b3R5cGUiLCB7CiAgICAgICAgICB3cml0YWJsZTogZmFsc2UKICAgICAgICB9KTsKICAgICAgICBpZiAoc3VwZXJDbGFzcykKICAgICAgICAgIF9zZXRQcm90b3R5cGVPZihzdWJDbGFzcywgc3VwZXJDbGFzcyk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gX2dldFByb3RvdHlwZU9mKG8pIHsKICAgICAgICBfZ2V0UHJvdG90eXBlT2YgPSBPYmplY3Quc2V0UHJvdG90eXBlT2YgPyBPYmplY3QuZ2V0UHJvdG90eXBlT2YuYmluZCgpIDogZnVuY3Rpb24gX2dldFByb3RvdHlwZU9mMihvMikgewogICAgICAgICAgcmV0dXJuIG8yLl9fcHJvdG9fXyB8fCBPYmplY3QuZ2V0UHJvdG90eXBlT2YobzIpOwogICAgICAgIH07CiAgICAgICAgcmV0dXJuIF9nZXRQcm90b3R5cGVPZihvKTsKICAgICAgfQogICAgICBmdW5jdGlvbiBfc2V0UHJvdG90eXBlT2YobywgcCkgewogICAgICAgIF9zZXRQcm90b3R5cGVPZiA9IE9iamVjdC5zZXRQcm90b3R5cGVPZiA/IE9iamVjdC5zZXRQcm90b3R5cGVPZi5iaW5kKCkgOiBmdW5jdGlvbiBfc2V0UHJvdG90eXBlT2YyKG8yLCBwMikgewogICAgICAgICAgbzIuX19wcm90b19fID0gcDI7CiAgICAgICAgICByZXR1cm4gbzI7CiAgICAgICAgfTsKICAgICAgICByZXR1cm4gX3NldFByb3RvdHlwZU9mKG8sIHApOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIF9pc05hdGl2ZVJlZmxlY3RDb25zdHJ1Y3QoKSB7CiAgICAgICAgaWYgKHR5cGVvZiBSZWZsZWN0ID09PSAidW5kZWZpbmVkIiB8fCAhUmVmbGVjdC5jb25zdHJ1Y3QpCiAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgaWYgKFJlZmxlY3QuY29uc3RydWN0LnNoYW0pCiAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgaWYgKHR5cGVvZiBQcm94eSA9PT0gImZ1bmN0aW9uIikKICAgICAgICAgIHJldHVybiB0cnVlOwogICAgICAgIHRyeSB7CiAgICAgICAgICBCb29sZWFuLnByb3RvdHlwZS52YWx1ZU9mLmNhbGwoUmVmbGVjdC5jb25zdHJ1Y3QoQm9vbGVhbiwgW10sIGZ1bmN0aW9uKCkgewogICAgICAgICAgfSkpOwogICAgICAgICAgcmV0dXJuIHRydWU7CiAgICAgICAgfSBjYXRjaCAoZSkgewogICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICAgIH0KICAgICAgfQogICAgICBmdW5jdGlvbiBfYXNzZXJ0VGhpc0luaXRpYWxpemVkKHNlbGYyKSB7CiAgICAgICAgaWYgKHNlbGYyID09PSB2b2lkIDApIHsKICAgICAgICAgIHRocm93IG5ldyBSZWZlcmVuY2VFcnJvcigidGhpcyBoYXNuJ3QgYmVlbiBpbml0aWFsaXNlZCAtIHN1cGVyKCkgaGFzbid0IGJlZW4gY2FsbGVkIik7CiAgICAgICAgfQogICAgICAgIHJldHVybiBzZWxmMjsKICAgICAgfQogICAgICBmdW5jdGlvbiBfcG9zc2libGVDb25zdHJ1Y3RvclJldHVybihzZWxmMiwgY2FsbCkgewogICAgICAgIGlmIChjYWxsICYmICh0eXBlb2YgY2FsbCA9PT0gIm9iamVjdCIgfHwgdHlwZW9mIGNhbGwgPT09ICJmdW5jdGlvbiIpKSB7CiAgICAgICAgICByZXR1cm4gY2FsbDsKICAgICAgICB9IGVsc2UgaWYgKGNhbGwgIT09IHZvaWQgMCkgewogICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcigiRGVyaXZlZCBjb25zdHJ1Y3RvcnMgbWF5IG9ubHkgcmV0dXJuIG9iamVjdCBvciB1bmRlZmluZWQiKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIF9hc3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ICAgIGZ1bmN0aW9uIF9nZXQoKSB7CiAgICAgICAgaWYgKHR5cGVvZiBSZWZsZWN0ICE9PSAidW5kZWZpbmVkIiAmJiBSZWZsZWN0LmdldCkgewogICAgICAgICAgX2dldCA9IFJlZmxlY3QuZ2V0LmJpbmQoKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgX2dldCA9IGZ1bmN0aW9uIF9nZXQyKHRhcmdldCwgcHJvcGVydHksIHJlY2VpdmVyKSB7CiAgICAgICAgICAgIHZhciBiYXNlID0gX3N1cGVyUHJvcEJhc2UodGFyZ2V0LCBwcm9wZXJ0eSk7CiAgICAgICAgICAgIGlmICghYmFzZSkKICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgIHZhciBkZXNjID0gT2JqZWN0LmdldE93blByb3BlcnR5RGVzY3JpcHRvcihiYXNlLCBwcm9wZXJ0eSk7CiAgICAgICAgICAgIGlmIChkZXNjLmdldCkgewogICAgICAgICAgICAgIHJldHVybiBkZXNjLmdldC5jYWxsKGFyZ3VtZW50cy5sZW5ndGggPCAzID8gdGFyZ2V0IDogcmVjZWl2ZXIpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHJldHVybiBkZXNjLnZhbHVlOwogICAgICAgICAgfTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIF9nZXQuYXBwbHkodGhpcywgYXJndW1lbnRzKTsKICAgICAgfQogICAgICB2YXIgRW1pdHRlciA9IC8qIEBfX1BVUkVfXyAqLyBmdW5jdGlvbigpIHsKICAgICAgICBmdW5jdGlvbiBFbWl0dGVyMigpIHsKICAgICAgICAgIF9jbGFzc0NhbGxDaGVjayh0aGlzLCBFbWl0dGVyMik7CiAgICAgICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkodGhpcywgImxpc3RlbmVycyIsIHsKICAgICAgICAgICAgdmFsdWU6IHt9LAogICAgICAgICAgICB3cml0YWJsZTogdHJ1ZSwKICAgICAgICAgICAgY29uZmlndXJhYmxlOiB0cnVlCiAgICAgICAgICB9KTsKICAgICAgICB9CiAgICAgICAgX2NyZWF0ZUNsYXNzKEVtaXR0ZXIyLCBbewogICAgICAgICAga2V5OiAiYWRkRXZlbnRMaXN0ZW5lciIsCiAgICAgICAgICB2YWx1ZTogZnVuY3Rpb24gYWRkRXZlbnRMaXN0ZW5lcih0eXBlLCBjYWxsYmFjaywgb3B0aW9ucykgewogICAgICAgICAgICBpZiAoISh0eXBlIGluIHRoaXMubGlzdGVuZXJzKSkgewogICAgICAgICAgICAgIHRoaXMubGlzdGVuZXJzW3R5cGVdID0gW107CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdGhpcy5saXN0ZW5lcnNbdHlwZV0ucHVzaCh7CiAgICAgICAgICAgICAgY2FsbGJhY2ssCiAgICAgICAgICAgICAgb3B0aW9ucwogICAgICAgICAgICB9KTsKICAgICAgICAgIH0KICAgICAgICB9LCB7CiAgICAgICAgICBrZXk6ICJyZW1vdmVFdmVudExpc3RlbmVyIiwKICAgICAgICAgIHZhbHVlOiBmdW5jdGlvbiByZW1vdmVFdmVudExpc3RlbmVyKHR5cGUsIGNhbGxiYWNrKSB7CiAgICAgICAgICAgIGlmICghKHR5cGUgaW4gdGhpcy5saXN0ZW5lcnMpKSB7CiAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHZhciBzdGFjayA9IHRoaXMubGlzdGVuZXJzW3R5cGVdOwogICAgICAgICAgICBmb3IgKHZhciBpID0gMCwgbCA9IHN0YWNrLmxlbmd0aDsgaSA8IGw7IGkrKykgewogICAgICAgICAgICAgIGlmIChzdGFja1tpXS5jYWxsYmFjayA9PT0gY2FsbGJhY2spIHsKICAgICAgICAgICAgICAgIHN0YWNrLnNwbGljZShpLCAxKTsKICAgICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9LCB7CiAgICAgICAgICBrZXk6ICJkaXNwYXRjaEV2ZW50IiwKICAgICAgICAgIHZhbHVlOiBmdW5jdGlvbiBkaXNwYXRjaEV2ZW50KGV2ZW50KSB7CiAgICAgICAgICAgIGlmICghKGV2ZW50LnR5cGUgaW4gdGhpcy5saXN0ZW5lcnMpKSB7CiAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHZhciBzdGFjayA9IHRoaXMubGlzdGVuZXJzW2V2ZW50LnR5cGVdOwogICAgICAgICAgICB2YXIgc3RhY2tUb0NhbGwgPSBzdGFjay5zbGljZSgpOwogICAgICAgICAgICBmb3IgKHZhciBpID0gMCwgbCA9IHN0YWNrVG9DYWxsLmxlbmd0aDsgaSA8IGw7IGkrKykgewogICAgICAgICAgICAgIHZhciBsaXN0ZW5lciA9IHN0YWNrVG9DYWxsW2ldOwogICAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgICBsaXN0ZW5lci5jYWxsYmFjay5jYWxsKHRoaXMsIGV2ZW50KTsKICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7CiAgICAgICAgICAgICAgICBQcm9taXNlLnJlc29sdmUoKS50aGVuKGZ1bmN0aW9uKCkgewogICAgICAgICAgICAgICAgICB0aHJvdyBlOwogICAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGlmIChsaXN0ZW5lci5vcHRpb25zICYmIGxpc3RlbmVyLm9wdGlvbnMub25jZSkgewogICAgICAgICAgICAgICAgdGhpcy5yZW1vdmVFdmVudExpc3RlbmVyKGV2ZW50LnR5cGUsIGxpc3RlbmVyLmNhbGxiYWNrKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgcmV0dXJuICFldmVudC5kZWZhdWx0UHJldmVudGVkOwogICAgICAgICAgfQogICAgICAgIH1dKTsKICAgICAgICByZXR1cm4gRW1pdHRlcjI7CiAgICAgIH0oKTsKICAgICAgdmFyIEFib3J0U2lnbmFsID0gLyogQF9fUFVSRV9fICovIGZ1bmN0aW9uKF9FbWl0dGVyKSB7CiAgICAgICAgX2luaGVyaXRzKEFib3J0U2lnbmFsMiwgX0VtaXR0ZXIpOwogICAgICAgIHZhciBfc3VwZXIgPSBfY3JlYXRlU3VwZXIoQWJvcnRTaWduYWwyKTsKICAgICAgICBmdW5jdGlvbiBBYm9ydFNpZ25hbDIoKSB7CiAgICAgICAgICB2YXIgX3RoaXM7CiAgICAgICAgICBfY2xhc3NDYWxsQ2hlY2sodGhpcywgQWJvcnRTaWduYWwyKTsKICAgICAgICAgIF90aGlzID0gX3N1cGVyLmNhbGwodGhpcyk7CiAgICAgICAgICBpZiAoIV90aGlzLmxpc3RlbmVycykgewogICAgICAgICAgICBFbWl0dGVyLmNhbGwoX2Fzc2VydFRoaXNJbml0aWFsaXplZChfdGhpcykpOwogICAgICAgICAgfQogICAgICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KF9hc3NlcnRUaGlzSW5pdGlhbGl6ZWQoX3RoaXMpLCAiYWJvcnRlZCIsIHsKICAgICAgICAgICAgdmFsdWU6IGZhbHNlLAogICAgICAgICAgICB3cml0YWJsZTogdHJ1ZSwKICAgICAgICAgICAgY29uZmlndXJhYmxlOiB0cnVlCiAgICAgICAgICB9KTsKICAgICAgICAgIE9iamVjdC5kZWZpbmVQcm9wZXJ0eShfYXNzZXJ0VGhpc0luaXRpYWxpemVkKF90aGlzKSwgIm9uYWJvcnQiLCB7CiAgICAgICAgICAgIHZhbHVlOiBudWxsLAogICAgICAgICAgICB3cml0YWJsZTogdHJ1ZSwKICAgICAgICAgICAgY29uZmlndXJhYmxlOiB0cnVlCiAgICAgICAgICB9KTsKICAgICAgICAgIE9iamVjdC5kZWZpbmVQcm9wZXJ0eShfYXNzZXJ0VGhpc0luaXRpYWxpemVkKF90aGlzKSwgInJlYXNvbiIsIHsKICAgICAgICAgICAgdmFsdWU6IHZvaWQgMCwKICAgICAgICAgICAgd3JpdGFibGU6IHRydWUsCiAgICAgICAgICAgIGNvbmZpZ3VyYWJsZTogdHJ1ZQogICAgICAgICAgfSk7CiAgICAgICAgICByZXR1cm4gX3RoaXM7CiAgICAgICAgfQogICAgICAgIF9jcmVhdGVDbGFzcyhBYm9ydFNpZ25hbDIsIFt7CiAgICAgICAgICBrZXk6ICJ0b1N0cmluZyIsCiAgICAgICAgICB2YWx1ZTogZnVuY3Rpb24gdG9TdHJpbmcoKSB7CiAgICAgICAgICAgIHJldHVybiAiW29iamVjdCBBYm9ydFNpZ25hbF0iOwogICAgICAgICAgfQogICAgICAgIH0sIHsKICAgICAgICAgIGtleTogImRpc3BhdGNoRXZlbnQiLAogICAgICAgICAgdmFsdWU6IGZ1bmN0aW9uIGRpc3BhdGNoRXZlbnQoZXZlbnQpIHsKICAgICAgICAgICAgaWYgKGV2ZW50LnR5cGUgPT09ICJhYm9ydCIpIHsKICAgICAgICAgICAgICB0aGlzLmFib3J0ZWQgPSB0cnVlOwogICAgICAgICAgICAgIGlmICh0eXBlb2YgdGhpcy5vbmFib3J0ID09PSAiZnVuY3Rpb24iKSB7CiAgICAgICAgICAgICAgICB0aGlzLm9uYWJvcnQuY2FsbCh0aGlzLCBldmVudCk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIF9nZXQoX2dldFByb3RvdHlwZU9mKEFib3J0U2lnbmFsMi5wcm90b3R5cGUpLCAiZGlzcGF0Y2hFdmVudCIsIHRoaXMpLmNhbGwodGhpcywgZXZlbnQpOwogICAgICAgICAgfQogICAgICAgIH1dKTsKICAgICAgICByZXR1cm4gQWJvcnRTaWduYWwyOwogICAgICB9KEVtaXR0ZXIpOwogICAgICB2YXIgQWJvcnRDb250cm9sbGVyID0gLyogQF9fUFVSRV9fICovIGZ1bmN0aW9uKCkgewogICAgICAgIGZ1bmN0aW9uIEFib3J0Q29udHJvbGxlcjIoKSB7CiAgICAgICAgICBfY2xhc3NDYWxsQ2hlY2sodGhpcywgQWJvcnRDb250cm9sbGVyMik7CiAgICAgICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkodGhpcywgInNpZ25hbCIsIHsKICAgICAgICAgICAgdmFsdWU6IG5ldyBBYm9ydFNpZ25hbCgpLAogICAgICAgICAgICB3cml0YWJsZTogdHJ1ZSwKICAgICAgICAgICAgY29uZmlndXJhYmxlOiB0cnVlCiAgICAgICAgICB9KTsKICAgICAgICB9CiAgICAgICAgX2NyZWF0ZUNsYXNzKEFib3J0Q29udHJvbGxlcjIsIFt7CiAgICAgICAgICBrZXk6ICJhYm9ydCIsCiAgICAgICAgICB2YWx1ZTogZnVuY3Rpb24gYWJvcnQocmVhc29uKSB7CiAgICAgICAgICAgIHZhciBldmVudDsKICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICBldmVudCA9IG5ldyBFdmVudCgiYWJvcnQiKTsKICAgICAgICAgICAgfSBjYXRjaCAoZSkgewogICAgICAgICAgICAgIGlmICh0eXBlb2YgZG9jdW1lbnQgIT09ICJ1bmRlZmluZWQiKSB7CiAgICAgICAgICAgICAgICBpZiAoIWRvY3VtZW50LmNyZWF0ZUV2ZW50KSB7CiAgICAgICAgICAgICAgICAgIGV2ZW50ID0gZG9jdW1lbnQuY3JlYXRlRXZlbnRPYmplY3QoKTsKICAgICAgICAgICAgICAgICAgZXZlbnQudHlwZSA9ICJhYm9ydCI7CiAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICBldmVudCA9IGRvY3VtZW50LmNyZWF0ZUV2ZW50KCJFdmVudCIpOwogICAgICAgICAgICAgICAgICBldmVudC5pbml0RXZlbnQoImFib3J0IiwgZmFsc2UsIGZhbHNlKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgZXZlbnQgPSB7CiAgICAgICAgICAgICAgICAgIHR5cGU6ICJhYm9ydCIsCiAgICAgICAgICAgICAgICAgIGJ1YmJsZXM6IGZhbHNlLAogICAgICAgICAgICAgICAgICBjYW5jZWxhYmxlOiBmYWxzZQogICAgICAgICAgICAgICAgfTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdmFyIHNpZ25hbFJlYXNvbiA9IHJlYXNvbjsKICAgICAgICAgICAgaWYgKHNpZ25hbFJlYXNvbiA9PT0gdm9pZCAwKSB7CiAgICAgICAgICAgICAgaWYgKHR5cGVvZiBkb2N1bWVudCA9PT0gInVuZGVmaW5lZCIpIHsKICAgICAgICAgICAgICAgIHNpZ25hbFJlYXNvbiA9IG5ldyBFcnJvcigiVGhpcyBvcGVyYXRpb24gd2FzIGFib3J0ZWQiKTsKICAgICAgICAgICAgICAgIHNpZ25hbFJlYXNvbi5uYW1lID0gIkFib3J0RXJyb3IiOwogICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgICAgICBzaWduYWxSZWFzb24gPSBuZXcgRE9NRXhjZXB0aW9uKCJzaWduYWwgaXMgYWJvcnRlZCB3aXRob3V0IHJlYXNvbiIpOwogICAgICAgICAgICAgICAgfSBjYXRjaCAoZXJyKSB7CiAgICAgICAgICAgICAgICAgIHNpZ25hbFJlYXNvbiA9IG5ldyBFcnJvcigiVGhpcyBvcGVyYXRpb24gd2FzIGFib3J0ZWQiKTsKICAgICAgICAgICAgICAgICAgc2lnbmFsUmVhc29uLm5hbWUgPSAiQWJvcnRFcnJvciI7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIHRoaXMuc2lnbmFsLnJlYXNvbiA9IHNpZ25hbFJlYXNvbjsKICAgICAgICAgICAgdGhpcy5zaWduYWwuZGlzcGF0Y2hFdmVudChldmVudCk7CiAgICAgICAgICB9CiAgICAgICAgfSwgewogICAgICAgICAga2V5OiAidG9TdHJpbmciLAogICAgICAgICAgdmFsdWU6IGZ1bmN0aW9uIHRvU3RyaW5nKCkgewogICAgICAgICAgICByZXR1cm4gIltvYmplY3QgQWJvcnRDb250cm9sbGVyXSI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ICAgICAgIGlmIChSZXF1ZXN0ICYmICFSZXF1ZXN0LnByb3RvdHlwZS5oYXNPd25Qcm9wZXJ0eSgic2lnbmFsIikgfHwgX19GT1JDRV9JTlNUQUxMX0FCT1JUQ09OVFJPTExFUl9QT0xZRklMTCkgewogICAgICAgICAgUmVxdWVzdCA9IGZ1bmN0aW9uIFJlcXVlc3QyKGlucHV0LCBpbml0MikgewogICAgICAgICAgICB2YXIgc2lnbmFsOwogICAgICAgICAgICBpZiAoaW5pdDIgJiYgaW5pdDIuc2lnbmFsKSB7CiAgICAgICAgICAgICAgc2lnbmFsID0gaW5pdDIuc2lnbmFsOwogICAgICAgICAgICAgIGRlbGV0ZSBpbml0Mi5zaWduYWw7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdmFyIHJlcXVlc3QgPSBuZXcgTmF0aXZlUmVxdWVzdChpbnB1dCwgaW5pdDIpOwogICAgICAgICAgICBpZiAoc2lnbmFsKSB7CiAgICAgICAgICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KHJlcXVlc3QsICJzaWduYWwiLCB7CiAgICAgICAgICAgICAgICB3cml0YWJsZTogZmFsc2UsCiAgICAgICAgICAgICAgICBlbnVtZXJhYmxlOiBmYWxzZSwKICAgICAgICAgICAgICAgIGNvbmZpZ3VyYWJsZTogdHJ1ZSwKICAgICAgICAgICAgICAgIHZhbHVlOiBzaWduYWwKICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAgfQogICAgICAgICAgICByZXR1cm4gcmVxdWVzdDsKICAgICAgICAgIH07CiAgICAgICAgICBSZXF1ZXN0LnByb3RvdHlwZSA9IE5hdGl2ZVJlcXVlc3QucHJvdG90eXBlOwogICAgICAgIH0KICAgICAgICB2YXIgcmVhbEZldGNoID0gZmV0Y2gyOwogICAgICAgIHZhciBhYm9ydGFibGVGZXRjaCA9IGZ1bmN0aW9uIGFib3J0YWJsZUZldGNoMihpbnB1dCwgaW5pdDIpIHsKICAgICAgICAgIHZhciBzaWduYWwgPSBSZXF1ZXN0ICYmIFJlcXVlc3QucHJvdG90eXBlLmlzUHJvdG90eXBlT2YoaW5wdXQpID8gaW5wdXQuc2lnbmFsIDogaW5pdDIgPyBpbml0Mi5zaWduYWwgOiB2b2lkIDA7CiAgICAgICAgICBpZiAoc2lnbmFsKSB7CiAgICAgICAgICAgIHZhciBhYm9ydEVycm9yOwogICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgIGFib3J0RXJyb3IgPSBuZXcgRE9NRXhjZXB0aW9uKCJBYm9ydGVkIiwgIkFib3J0RXJyb3IiKTsKICAgICAgICAgICAgfSBjYXRjaCAoZXJyKSB7CiAgICAgICAgICAgICAgYWJvcnRFcnJvciA9IG5ldyBFcnJvcigiQWJvcnRlZCIpOwogICAgICAgICAgICAgIGFib3J0RXJyb3IubmFtZSA9ICJBYm9ydEVycm9yIjsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoc2lnbmFsLmFib3J0ZWQpIHsKICAgICAgICAgICAgICByZXR1cm4gUHJvbWlzZS5yZWplY3QoYWJvcnRFcnJvcik7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdmFyIGNhbmNlbGxhdGlvbiA9IG5ldyBQcm9taXNlKGZ1bmN0aW9uKF8sIHJlamVjdCkgewogICAgICAgICAgICAgIHNpZ25hbC5hZGRFdmVudExpc3RlbmVyKCJhYm9ydCIsIGZ1bmN0aW9uKCkgewogICAgICAgICAgICAgICAgcmV0dXJuIHJlamVjdChhYm9ydEVycm9yKTsKICAgICAgICAgICAgICB9LCB7CiAgICAgICAgICAgICAgICBvbmNlOiB0cnVlCiAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgIH0pOwogICAgICAgICAgICBpZiAoaW5pdDIgJiYgaW5pdDIuc2lnbmFsKSB7CiAgICAgICAgICAgICAgZGVsZXRlIGluaXQyLnNpZ25hbDsKICAgICAgICAgICAgfQogICAgICAgICAgICByZXR1cm4gUHJvbWlzZS5yYWNlKFtjYW5jZWxsYXRpb24sIHJlYWx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AgICAgICAgdGhpcy5zaWduYWxzLmFkZChzaWduYWwpOwogICAgICAgICAgaWYgKHNpZ25hbC5hYm9ydGVkKSB7CiAgICAgICAgICAgIHRoaXMuaGFuZGxlQWJvcnRlZChzaWduYWwpOwogICAgICAgICAgfSBlbHNlIGlmICh0eXBlb2Ygc2lnbmFsLmFkZEV2ZW50TGlzdGVuZXIgPT09ICJmdW5jdGlvbiIpIHsKICAgICAgICAgICAgc2lnbmFsLmFkZEV2ZW50TGlzdGVuZXIoImFib3J0IiwgKCkgPT4gewogICAgICAgICAgICAgIHRoaXMuaGFuZGxlQWJvcnRlZChzaWduYWwpOwogICAgICAgICAgICB9KTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaGFuZGxlQWJvcnRlZChzaWduYWwpIHsKICAgICAgICAgIHRoaXMuc2lnbmFscy5kZWxldGUoc2lnbmFsKTsKICAgICAgICAgIGlmICh0aGlzLnNpZ25hbHMuc2l6ZSA9PT0gMCkgewogICAgICAgICAgICB0aGlzLmFib3J0Q29udHJvbGxlci5hYm9ydCgpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBnZXQgc2lnbmFsKCkgewogICAgICAgICAgcmV0dXJuIHRoaXMuYWJvcnRDb250cm9sbGVyLnNpZ25hbDsKICAgICAgICB9CiAgICAgICAgYWJvcnQoKSB7CiAgICAgICAgICB0aGlzLmFib3J0Q29udHJvbGxlci5hYm9ydCgpOwogICAgICAgIH0KICAgICAgfTsKICAgICAgZXhwb3J0cy5kZWZhdWx0ID0gQWdncmVnYXRlQWJvcnRDb250cm9sbGVyOwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vYWJvcnRhYmxlLXByb21pc2UtY2FjaGVAMS41LjAvbm9kZV9tb2R1bGVzL2Fib3J0YWJsZS1wcm9taXNlLWNhY2hlL2VzbS9BZ2dyZWdhdGVTdGF0dXNSZXBvcnRlci5qcwogIHZhciByZXF1aXJlX0FnZ3JlZ2F0ZVN0YXR1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IHsKICAgICAgICAgIGlmICh0aGlzLmNhY2hlLmdldChrZXkpID09PSBlbnRyeSkgewogICAgICAgICAgICB0aGlzLmNhY2hlLmRlbGV0ZShrZXkpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBmaWxsKGtleSwgZGF0YSwgc2lnbmFsLCBzdGF0dXNDYWxsYmFjaykgewogICAgICAgICAgY29uc3QgYWJvcnRlciA9IG5ldyBBZ2dyZWdhdGVBYm9ydENvbnRyb2xsZXJfMS5kZWZhdWx0KCk7CiAgICAgICAgICBjb25zdCBzdGF0dXNSZXBvcnRlciA9IG5ldyBBZ2dyZWdhdGVTdGF0dXNSZXBvcnRlcl8xLmRlZmF1bHQoKTsKICAgICAgICAgIHN0YXR1c1JlcG9ydGVyLmFkZENhbGxiYWNrKHN0YXR1c0NhbGxiYWNrKTsKICAgICAgICAgIGNvbnN0IG5ld0VudHJ5ID0gewogICAgICAgICAgICBhYm9ydGVyLAogICAgICAgICAgICBwcm9taXNlOiB0aGlzLmZpbGxDYWxsYmFjayhkYXRhLCBhYm9ydGVyLnNpZ25hbCwgKG1lc3NhZ2UpID0+IHsKICAgICAgICAgICAgICBzdGF0dXNSZXBvcnRlci5jYWxsYmFjayhtZXNzYWdlKTsKICAgICAgICAgICAgfSksCiAgICAgICAgICAgIHNldHRsZWQ6IGZhbHNlLAogICAgICAgICAgICBzdGF0dXNSZXBvcnRlciwKICAgICAgICAgICAgZ2V0IGFib3J0ZWQoKSB7CiAgICAgICAgICAgICAgcmV0dXJuIHRoaXMuYWJvcnRlci5zaWduYWwuYWJvcnRlZDsKICAgICAgICAgICAgfQogICAgICAgICAgfTsKICAgICAgICAgIG5ld0VudHJ5LmFib3J0ZXIuYWRkU2lnbmFsKHNpZ25hbCk7CiAgICAgICAgICBuZXdFbnRyeS5hYm9ydGVyLnNpZ25hbC5hZGRFdmVudExpc3RlbmVyKCJhYm9ydCIsICgpID0+IHsKICAgICAgICAgICAgaWYgKCFuZXdFbnRyeS5zZXR0bGVkKSB7CiAgICAgICAgICAgICAgdGhpcy5ldmljdChrZXksIG5ld0VudHJ5KTsKICAgICAgICAgICAgfQogICAgICAgICAgfSk7CiAgICAgICAgICBuZXdFbnRyeS5wcm9taXNlLnRoZW4oKCkgPT4gewogICAgICAgICAgICBuZXdFbnRyeS5zZXR0bGVkID0gdHJ1ZTsKICAgICAgICAgIH0sICgpID0+IHsKICAgICAgICAgICAgbmV3RW50cnkuc2V0dGxlZCA9IHRydWU7CiAgICAgICAgICAgIHRoaXMuZXZpY3Qoa2V5LCBuZXdFbnRyeSk7CiAgICAgICAgICB9KS5jYXRjaCgoZSkgPT4gewogICAgICAgICAgICBjb25zb2xlLmVycm9yKGUpOwogICAgICAgICAgICB0aHJvdyBlOwogICAgICAgICAgfSk7CiAgICAgICAgICB0aGlzLmNhY2hlLnNldChrZXksIG5ld0VudHJ5KTsKICAgICAgICB9CiAgICAgICAgc3RhdGljIGNoZWNrU2luZ2xlUHJvbWlzZShwcm9taXNlLCBzaWduYWwpIHsKICAgICAgICAgIGZ1bmN0aW9uIGNoZWNrRm9yU2luZ2xlQWJvcnQoKSB7CiAgICAgICAgICAgIGlmIChzaWduYWwgJiYgc2lnbmFsLmFib3J0ZWQpIHsKICAgICAgICAgICAgICB0aHJvdyBPYmplY3QuYXNzaWduKG5ldyBFcnJvcigiYWJvcnRlZCIpLCB7IGNvZGU6ICJFUlJfQUJPUlRFRCIgfSk7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBwcm9taXNlLnRoZW4oKHJlc3VsdCkgPT4gewogICAgICAgICAgICBjaGVja0ZvclNpbmdsZUFib3J0KCk7CiAgICAgICAgICAgIHJldHVybiByZXN1bHQ7CiAgICAgICAgICB9LCAoZXJyb3IpID0+IHsKICAgICAgICAgICAgY2hlY2tGb3JTaW5nbGVBYm9ydCgpOwogICAgICAgICAgICB0aHJvdyBlcnJvcjsKICAgICAgICAgIH0pOwogICAgICAgIH0KICAgICAgICBoYXM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xlUHJvbWlzZUNhY2hlMi5jaGVja1NpbmdsZVByb21pc2UoY2FjaGVFbnRyeS5wcm9taXNlLCBzaWduYWwpOwogICAgICAgICAgfQogICAgICAgICAgdGhpcy5maWxsKGtleSwgZGF0YSwgc2lnbmFsLCBzdGF0dXNDYWxsYmFjayk7CiAgICAgICAgICByZXR1cm4gQWJvcnRhYmxlUHJvbWlzZUNhY2hlMi5jaGVja1NpbmdsZVByb21pc2UodGhpcy5jYWNoZS5nZXQoa2V5KS5wcm9taXNlLCBzaWduYWwpOwogICAgICAgIH0KICAgICAgICBkZWxldGUoa2V5KSB7CiAgICAgICAgICBjb25zdCBjYWNoZWRFbnRyeSA9IHRoaXMuY2FjaGUuZ2V0KGtleSk7CiAgICAgICAgICBpZiAoY2FjaGVkRW50cnkpIHsKICAgICAgICAgICAgaWYgKCFjYWNoZWRFbnRyeS5zZXR0bGVkKSB7CiAgICAgICAgICAgICAgY2FjaGVkRW50cnkuYWJvcnRlci5hYm9ydCgpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHRoaXMuY2FjaGUuZGVsZXRlKGtleSk7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGNsZWFyKCkgewogICAgICAgICAgY29uc3Qga2V5SXRlciA9IHRoaXMuY2FjaGUua2V5cygpOwogICAgICAgICAgbGV0IGRlbGV0ZUNvdW50ID0gMDsKICAgICAgICAgIGZvciAobGV0IHJlc3VsdCA9IGtleUl0ZXIubmV4dCgpOyAhcmVzdWx0LmRvbmU7IHJlc3VsdCA9IGtleUl0ZXIubmV4dCgpKSB7CiAgICAgICAgICAgIHRoaXMuZGVsZXRlKHJlc3VsdC52YWx1ZSk7CiAgICAgICAgICAgIGRlbGV0ZUNvdW50ICs9IDE7CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gZGVsZXRlQ291bnQ7CiAgICAgICAgfQogICAgICB9OwogICAgICBleHBvcnRzLmRlZmF1bHQgPSBBYm9ydGFibGVQcm9taXNlQ2FjaGUyO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bS9xdWljay1scnVAMi4wLjAvbm9kZV9tb2R1bGVzL3F1aWNrLWxydS9pbmRleC5qcyIoZXhwb3J0cywgbW9kdWxlKSB7CiAgICAgIGluaXRfYnVmZmVyX3NoaW0oKTsKICAgICAgInVzZSBzdHJpY3QiOwogICAgICB2YXIgUXVpY2tMUlUzID0gY2xhc3MgewogICAgICAgIGNvbnN0cnVjdG9yKG9wdGlvbnMgPSB7fSkgewogICAgICAgICAgaWYgKCEob3B0aW9ucy5tYXhTaXplICYmIG9wdGlvbnMubWF4U2l6ZSA+IDApKSB7CiAgICAgICAgICAgIHRocm93IG5ldyBUeXBlRXJyb3IoImBtYXhTaXplYCBtdXN0IGJlIGEgbnVtYmVyIGdyZWF0ZXIgdGhhbiAwIik7CiAgICAgICAgICB9CiAgICAgICAgICB0aGlzLm1heFNpemUgPSBvcHRpb25zLm1heFNpemU7CiAgICAgICAgICB0aGlzLmNhY2hlID0gbmV3IE1hcCgpOwogICAgICAgICAgdGhpcy5vbGRDYWNoZSA9IG5ldyBNYXAoKTsKICAgICAgICAgIHRoaXMuX3NpemUgPSAwOwogICAgICAgIH0KICAgICAgICBfc2V0KGtleSwgdmFsdWUpIHsKICAgICAgICAgIHRoaXMuY2FjaGUuc2V0KGtleSwgdmFsdWUpOwogICAgICAgICAgdGhpcy5fc2l6ZSsrOwogICAgICAgICAgaWYgKHRoaXMuX3NpemUgPj0gdGhpcy5tYXhTaXplKSB7CiAgICAgICAgICAgIHRoaXMuX3NpemUgPSAwOwogICAgICAgICAgICB0aGlzLm9sZENhY2hlID0gdGhpcy5jYWNoZTsKICAgICAgICAgICAgdGhpcy5jYWNoZSA9IG5ldyBNYXAoKTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZ2V0KGtleSkgewogICAgICAgICAgaWYgKHRoaXMuY2FjaGUuaGFzKGtleSkpIHsKICAgICAgICAgICAgcmV0dXJuIHRoaXMuY2FjaGUuZ2V0KGtleSk7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAodGhpcy5vbGRDYWNoZS5oYXMoa2V5KSkgewogICAgICAgICAgICBjb25zdCB2YWx1ZSA9IHRoaXMub2xkQ2FjaGUuZ2V0KGtleSk7CiAgICAgICAgICAgIHRoaXMuX3NldChrZXksIHZhbHVlKTsKICAgICAgICAgICAgcmV0dXJuIHZhbHVlOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBzZXQoa2V5LCB2YWx1ZSkgewogICAgICAgICAgaWYgKHRoaXMuY2FjaGUuaGFzKGtleSkpIHsKICAgICAgICAgICAgdGhpcy5jYWNoZS5zZXQoa2V5LCB2YWx1ZSk7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICB0aGlzLl9zZXQoa2V5LCB2YWx1ZSk7CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gdGhpczsKICAgICAgICB9CiAgICAgICAgaGFzKGtleSkgewogICAgICAgICAgcmV0dXJuIHRoaXMuY2FjaGUuaGFzKGtleSkgfHwgdGhpcy5vbGRDYWNoZS5oYXMoa2V5KTsKICAgICAgICB9CiAgICAgICAgcGVlayhrZXkpIHsKICAgICAgICAgIGlmICh0aGlzLmNhY2hlLmhhcyhrZXkpKSB7CiAgICAgICAgICAgIHJldHVybiB0aGlzLmNhY2hlLmdldChrZXkpOwogICAgICAgICAgfQogICAgICAgICAgaWYgKHRoaXMub2xkQ2FjaGUuaGFzKGtleSkpIHsKICAgICAgICAgICAgcmV0dXJuIHRoaXMub2xkQ2FjaGUuZ2V0KGtleSk7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGRlbGV0ZShrZXkpIHsKICAgICAgICAgIGNvbnN0IGRlbGV0ZWQgPSB0aGlzLmNhY2hlLmRlbGV0ZShrZXkpOwogICAgICAgICAgaWYgKGRlbGV0ZWQpIHsKICAgICAgICAgICAgdGhpcy5fc2l6ZS0tOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIHRoaXMub2xkQ2FjaGUuZGVsZXRlKGtleSkgfHwgZGVsZXRlZDsKICAgICAgICB9CiAgICAgICAgY2xlYXIoKSB7CiAgICAgICAgICB0aGlzLmNhY2hlLmNsZWFyKCk7CiAgICAgICAgICB0aGlzLm9sZENhY2hlLmNsZWFyKCk7CiAgICAgICAgICB0aGlzLl9zaXplID0gMDsKICAgICAgICB9CiAgICAgICAgKmtleXMoKSB7CiAgICAgICAgICBmb3IgKGNvbnN0IFtrZXldIG9mIHRoaXMpIHsKICAgICAgICAgICAgeWllbGQga2V5OwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICAqdmFsdWVzKCkgewogICAgICAgICAgZm9yIChjb25zdCBbLCB2YWx1ZV0gb2YgdGhpcykgewogICAgICAgICAgICB5aWVsZCB2YWx1ZTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgKltTeW1ib2wuaXRlcmF0b3JdKCkgewogICAgICAgICAgZm9yIChjb25zdCBpdGVtIG9mIHRoaXMuY2FjaGUpIHsKICAgICAgICAgICAgeWllbGQgaXRlbTsKICAgICAgICAgIH0KICAgICAgICAgIGZvciAoY29uc3QgaXRlbSBvZiB0aGlzLm9sZENhY2hlKSB7CiAgICAgICAgICAgIGNvbnN0IFtrZXldID0gaXRlbTsKICAgICAgICAgICAgaWYgKCF0aGlzLmNhY2hlLmhhcyhrZXkpKSB7CiAgICAgICAgICAgICAgeWllbGQgaXRlbTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBnZXQgc2l6ZSgpIHsKICAgICAgICAgIGxldCBvbGRDYWNoZVNpemUgPSAwOwogICAgICAgICAgZm9yIChjb25zdCBrZXkgb2YgdGhpcy5vbGRDYWNoZS5rZXlzKCkpIHsKICAgICAgICAgICAgaWYgKCF0aGlzLmNhY2hlLmhhcyhrZXkpKSB7CiAgICAgICAgICAgICAgb2xkQ2FjaGVTaXplKys7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiB0aGlzLl9zaXplICsgb2xkQ2FjaGVTaXpl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IsCiAgICAgICAgICAgIGFycmF5QnVmZmVyOiAiQXJyYXlCdWZmZXIiIGluIHNlbGYyCiAgICAgICAgICB9OwogICAgICAgICAgZnVuY3Rpb24gaXNEYXRhVmlldyhvYmopIHsKICAgICAgICAgICAgcmV0dXJuIG9iaiAmJiBEYXRhVmlldy5wcm90b3R5cGUuaXNQcm90b3R5cGVPZihvYmopOwogICAgICAgICAgfQogICAgICAgICAgaWYgKHN1cHBvcnQuYXJyYXlCdWZmZXIpIHsKICAgICAgICAgICAgdmFyIHZpZXdDbGFzc2VzID0gWwogICAgICAgICAgICAgICJbb2JqZWN0IEludDhBcnJheV0iLAogICAgICAgICAgICAgICJbb2JqZWN0IFVpbnQ4QXJyYXldIiwKICAgICAgICAgICAgICAiW29iamVjdCBVaW50OENsYW1wZWRBcnJheV0iLAogICAgICAgICAgICAgICJbb2JqZWN0IEludDE2QXJyYXldIiwKICAgICAgICAgICAgICAiW29iamVjdCBVaW50MTZBcnJheV0iLAogICAgICAgICAgICAgICJbb2JqZWN0IEludDMyQXJyYXldIiwKICAgICAgICAgICAgICAiW29iamVjdCBVaW50MzJBcnJheV0iLAogICAgICAgICAgICAgICJbb2JqZWN0IEZsb2F0MzJBcnJheV0iLAogICAgICAgICAgICAgICJbb2JqZWN0IEZsb2F0NjRBcnJheV0iCiAgICAgICAgICAgIF07CiAgICAgICAgICAgIHZhciBpc0FycmF5QnVmZmVyVmlldyA9IEFycmF5QnVmZmVyLmlzVmlldyB8fCBmdW5jdGlvbihvYmopIHsKICAgICAgICAgICAgICByZXR1cm4gb2JqICYmIHZpZXdDbGFzc2VzLmluZGV4T2YoT2JqZWN0LnByb3RvdHlwZS50b1N0cmluZy5jYWxsKG9iaikpID4gLTE7CiAgICAgICAgICAgIH07CiAgICAgICAgICB9CiAgICAgICAgICBmdW5jdGlvbiBub3JtYWxpemVOYW1lKG5hbWUpIHsKICAgICAgICAgICAgaWYgKHR5cGVvZiBuYW1lICE9PSAic3RyaW5nIikgewogICAgICAgICAgICAgIG5hbWUgPSBTdHJpbmcobmFtZSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKC9bXmEtejAtOVwtIyQlJicqKy5eX2B8fl0vaS50ZXN0KG5hbWUpKSB7CiAgICAgICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcigiSW52YWxpZCBjaGFyYWN0ZXIgaW4gaGVhZGVyIGZpZWxkIG5hbWUiKTsKICAgICAgICAgICAgfQogICAgICAgICAgICByZXR1cm4gbmFtZS50b0xvd2VyQ2FzZSgpOwogICAgICAgICAgfQogICAgICAgICAgZnVuY3Rpb24gbm9ybWFsaXplVmFsdWUodmFsdWUpIHsKICAgICAgICAgICAgaWYgKHR5cGVvZiB2YWx1ZSAhPT0gInN0cmluZyIpIHsKICAgICAgICAgICAgICB2YWx1ZSA9IFN0cmluZyh2YWx1ZSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgcmV0dXJuIHZhbHVlOwogICAgICAgICAgfQogICAgICAgICAgZnVuY3Rpb24gaXRlcmF0b3JGb3IoaXRlbXMpIHsKICAgICAgICAgICAgdmFyIGl0ZXJhdG9yID0gewogICAgICAgICAgICAgIG5leHQ6IGZ1bmN0aW9uKCkgewogICAgICAgICAgICAgICAgdmFyIHZhbHVlID0gaXRlbXMuc2hpZnQoKTsKICAgICAgICAgICAgICAgIHJldHVybiB7IGRvbmU6IHZhbHVlID09PSB2b2lkIDAsIHZhbHVlIH07CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9OwogICAgICAgICAgICBpZiAoc3VwcG9ydC5pdGVyYWJsZSkgewogICAgICAgICAgICAgIGl0ZXJhdG9yW1N5bWJvbC5pdGVyYXRvcl0gPSBmdW5jdGlvbigpIHsKICAgICAgICAgICAgICAgIHJldHVybiBpdGVyYXRvcjsKICAgICAgICAgICAgICB9OwogICAgICAgICAgICB9CiAgICAgICAgICAgIHJldHVybiBpdGVyYXRvcjsKICAgICAgICAgIH0KICAgICAgICAgIGZ1bmN0aW9uIEhlYWRlcnMoaGVhZGVycykgewogICAgICAgICAgICB0aGlzLm1hcCA9IHt9OwogICAgICAgICAgICBpZiAoaGVhZGVycyBpbnN0YW5jZW9mIEhlYWRlcnMpIHsKICAgICAgICAgICAgICBoZWFkZXJzLmZvckVhY2goZnVuY3Rpb24odmFsdWUsIG5hbWUpIHsKICAgICAgICAgICAgICAgIHRoaXMuYXBwZW5kKG5hbWUsIHZhbHVlKTsKICAgICAgICAgICAgICB9LCB0aGlzKTsKICAgICAgICAgICAgfSBlbHNlIGlmIChBcnJheS5pc0FycmF5KGhlYWRlcnMpKSB7CiAgICAgICAgICAgICAgaGVhZGVycy5mb3JFYWNoKGZ1bmN0aW9uKGhlYWRlcikgewogICAgICAgICAgICAgICAgdGhpcy5hcHBlbmQoaGVhZGVyWzBdLCBoZWFkZXJbMV0pOwogICAgICAgICAgICAgIH0sIHRoaXMpOwogICAgICAgICAgICB9IGVsc2UgaWYgKGhlYWRlcnMpIHsKICAgICAgICAgICAgICBPYmplY3QuZ2V0T3duUHJvcGVydHlOYW1lcyhoZWFkZXJzKS5mb3JFYWNoKGZ1bmN0aW9uKG5hbWUpIHsKICAgICAgICAgICAgICAgIHRoaXMuYXBwZW5kKG5hbWUsIGhlYWRlcnNbbmFtZV0pOwogICAgICAgICAgICAgIH0sIHRoaXMpOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBIZWFkZXJzLnByb3RvdHlwZS5hcHBlbmQgPSBmdW5jdGlvbihuYW1lLCB2YWx1ZSkgewogICAgICAgICAgICBuYW1lID0gbm9ybWFsaXplTmFtZShuYW1lKTsKICAgICAgICAgICAgdmFsdWUgPSBub3JtYWxpemVWYWx1ZSh2YWx1ZSk7CiAgICAgICAgICAgIHZhciBvbGRWYWx1ZSA9IHRoaXMubWFwW25hbWVdOwogICAgICAgICAgICB0aGlzLm1hcFtuYW1lXSA9IG9sZFZhbHVlID8gb2xkVmFsdWUgKyAiLCAiICsgdmFsdWUgOiB2YWx1ZTsKICAgICAgICAgIH07CiAgICAgICAgICBIZWFkZXJzLnByb3RvdHlwZVsiZGVsZXRlIl0gPSBmdW5jdGlvbihuYW1lKSB7CiAgICAgICAgICAgIGRlbGV0ZSB0aGlzLm1hcFtub3JtYWxpemVOYW1lKG5hbWUpXTsKICAgICAgICAgIH07CiAgICAgICAgICBIZWFkZXJzLnByb3RvdHlwZS5nZXQgPSBmdW5jdGlvbihuYW1lKSB7CiAgICAgICAgICAgIG5hbWUgPSBub3JtYWxpemVOYW1lKG5hbWUpOwogICAgICAgICAgICByZXR1cm4gdGhpcy5oYXMobmFtZSkgPyB0aGlzLm1hcFtuYW1lXSA6IG51bGw7CiAgICAgICAgICB9OwogICAgICAgICAgSGVhZGVycy5wcm90b3R5cGUuaGFzID0gZnVuY3Rpb24obmFtZSkgewogICAgICAgICAgICByZXR1cm4gdGhpcy5tYXAuaGFzT3duUHJvcGVydHkobm9ybWFsaXplTmFtZShuYW1lKSk7CiAgICAgICAgICB9OwogICAgICAgICAgSGVhZGVycy5wcm90b3R5cGUuc2V0ID0gZnVuY3Rpb24obmFtZSwgdmFsdWUpIHsKICAgICAgICAgICAgdGhpcy5tYXBbbm9ybWFsaXplTmFtZShuYW1lKV0gPSBub3JtYWxpemVWYWx1ZSh2YWx1ZSk7CiAgICAgICAgICB9OwogICAgICAgICAgSGVhZGVycy5wcm90b3R5cGUuZm9yRWFjaCA9IGZ1bmN0aW9uKGNhbGxiYWNrLCB0aGlzQXJnKSB7CiAgICAgICAgICAgIGZvciAodmFyIG5hbWUgaW4gdGhpcy5tYXApIHsKICAgICAgICAgICAgICBpZiAodGhpcy5tYXAuaGFzT3duUHJvcGVydHkobmFtZSkpIHsKICAgICAgICAgICAgICAgIGNhbGxiYWNrLmNhbGwodGhpc0FyZywgdGhpcy5tYXBbbmFtZV0sIG5hbWUsIHRoaXMpOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgfTsKICAgICAgICAgIEhlYWRlcnMucHJvdG90eXBlLmtleXMgPSBmdW5jdGlvbigpIHsKICAgICAgICAgICAgdmFyIGl0ZW1zID0gW107CiAgICAgICAgICAgIHRoaXMuZm9yRWFjaChmdW5jdGlvbih2YWx1ZSwgbmFtZSkgewogICAgICAgICAgICAgIGl0ZW1zLnB1c2gobmFtZSk7CiAgICAgICAgICAgIH0pOwogICAgICAgICAgICByZXR1cm4gaXRlcmF0b3JGb3IoaXRlbXMpOwogICAgICAgICAgfTsKICAgICAgICAgIEhlYWRlcnMucHJvdG90eXBlLnZhbHVlcyA9IGZ1bmN0aW9uKCkgewogICAgICAgICAgICB2YXIgaXRlbXMgPSBbXTsKICAgICAgICAgICAgdGhpcy5mb3JFYWNoKGZ1bmN0aW9uKHZhbHVlKSB7CiAgICAgICAgICAgICAgaXRlbXMucHVzaCh2YWx1ZSk7CiAgICAgICAgICAgIH0pOwogICAgICAgICAgICByZXR1cm4gaXRlcmF0b3JGb3IoaXRlbXMpOwogICAgICAgICAgfTsKICAgICAgICAgIEhlYWRlcnMucHJvdG90eXBlLmVudHJpZXMgPSBmdW5jdGlvbigpIHsKICAgICAgICAgICAgdmFyIGl0ZW1zID0gW107CiAgICAgICAgICAgIHRoaXMuZm9yRWFjaChmdW5jdGlvbih2YWx1ZSwgbmFtZSkgewogICAgICAgICAgICAgIGl0ZW1zLnB1c2goW25hbWUsIHZhbHVlXSk7CiAgICAgICAgICAgIH0pOwogICAgICAgICAgICByZXR1cm4gaXRlcmF0b3JGb3IoaXRlbXMpOwogICAgICAgICAgfTsKICAgICAgICAgIGlmIChzdXBwb3J0Lml0ZXJhYmxlKSB7CiAgICAgICAgICAgIEhlYWRlcnMucHJvdG90eXBlW1N5bWJvbC5pdGVyYXRvcl0gPSBIZWFkZXJzLnByb3RvdHlwZS5lbnRyaWVzOwogICAgICAgICAgfQogICAgICAgICAgZnVuY3Rpb24gY29uc3VtZWQoYm9keSkgewogICAgICAgICAgICBpZiAoYm9keS5ib2R5VXNlZCkgewogICAgICAgICAgICAgIHJldHVybiBQcm9taXNlLnJlamVjdChuZXcgVHlwZUVycm9yKCJBbHJlYWR5IHJlYWQiKSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgYm9keS5ib2R5VXNlZCA9IHRydWU7CiAgICAgICAgICB9CiAgICAgICAgICBmdW5jdGlvbiBmaWxlUmVhZGVyUmVhZHkocmVhZGVyKSB7CiAgICAgICAgICAgIHJldHVybiBuZXcgUHJvbWlzZShmdW5jdGlvbihyZXNvbHZlLCByZWplY3QpIHsKICAgICAgICAgICAgICByZWFkZXIub25sb2FkID0gZnVuY3Rpb24oKSB7CiAgICAgICAgICAgICAgICByZXNvbHZlKHJlYWRlci5yZXN1bHQpOwogICAgICAgICAgICAgIH07CiAgICAgICAgICAgICAgcmVhZGVyLm9uZXJyb3IgPSBmdW5jdGlvbigpIHsKICAgICAgICAgICAgICAgIHJlamVjdChyZWFkZXIuZXJyb3IpOwogICAgICAgICAgICAgIH07CiAgICAgICAgICAgIH0pOwogICAgICAgICAgfQogICAgICAgICAgZnVuY3Rpb24gcmVhZEJsb2JBc0FycmF5QnVmZmVyKGJsb2IpIHsKICAgICAgICAgICAgdmFyIHJlYWRlciA9IG5ldyBGaWxlUmVhZGVyKCk7CiAgICAgICAgICAgIHZhciBwcm9taXNlID0gZmlsZVJlYWRlclJlYWR5KHJlYWRlcik7CiAgICAgICAgICAgIHJlYWRlci5yZWFkQXNBcnJheUJ1ZmZlcihibG9iKTsKICAgICAgICAgICAgcmV0dXJuIHByb21pc2U7CiAgICAgICAgICB9CiAgICAgICAgICBmdW5jdGlvbiByZWFkQmxvYkFzVGV4dChibG9iKSB7CiAgICAgICAgICAgIHZhciByZWFkZXIgPSBuZXcgRmlsZVJlYWRlcigpOwogICAgICAgICAgICB2YXIgcHJvbWlzZSA9IGZpbGVSZWFkZXJSZWFkeShyZWFkZXIpOwogICAgICAgICAgICByZWFkZXIucmVhZEFzVGV4dChibG9iKTsKICAgICAgICAgICAgcmV0dXJuIHByb21pc2U7CiAgICAgICAgICB9CiAgICAgICAgICBmdW5jdGlvbiByZWFkQXJyYXlCdWZmZXJBc1RleHQoYnVmKSB7CiAgICAgICAgICAgIHZhciB2aWV3ID0gbmV3IFVpbnQ4QXJyYXkoYnVmKTsKICAgICAgICAgICAgdmFyIGNoYXJzID0gbmV3IEFycmF5KHZpZXcubGVuZ3RoKTsKICAgICAgICAgICAgZm9yICh2YXIgaSA9IDA7IGkgPCB2aWV3Lmxlbmd0aDsgaSsrKSB7CiAgICAgICAgICAgICAgY2hhcnNbaV0gPSBTdHJpbmcuZnJvbUNoYXJDb2RlKHZpZXdbaV0pOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHJldHVybiBjaGFycy5qb2luKCIiKTsKICAgICAgICAgIH0KICAgICAgICAgIGZ1bmN0aW9uIGJ1ZmZlckNsb25lKGJ1ZikgewogICAgICAgICAgICBpZiAoYnVmLnNsaWNlKSB7CiAgICAgICAgICAgICAgcmV0dXJuIGJ1Zi5zbGljZSgwKTsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICB2YXIgdmlldyA9IG5ldyBVaW50OEFycmF5KGJ1Zi5ieXRlTGVuZ3RoKTsKICAgICAgICAgICAgICB2aWV3LnNldChuZXcgVWludDhBcnJheShidWYpKTsKICAgICAgICAgICAgICByZXR1cm4gdmlldy5idWZmZXI7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGZ1bmN0aW9uIEJvZHkoKSB7CiAgICAgICAgICAgIHRoaXMuYm9keVVzZWQgPSBmYWxzZTsKICAgICAgICAgICAgdGhpcy5faW5pdEJvZHkgPSBmdW5jdGlvbihib2R5KSB7CiAgICAgICAgICAgICAgdGhpcy5fYm9keUluaXQgPSBib2R5OwogICAgICAgICAgICAgIGlmICghYm9keSkgewogICAgICAgICAgICAgICAgdGhpcy5fYm9keVRleHQgPSAiIjsKICAgICAgICAgICAgICB9IGVsc2UgaWYgKHR5cGVvZiBib2R5ID09PSAic3RyaW5nIikgewogICAgICAgICAgICAgICAgdGhpcy5fYm9keVRleHQgPSBib2R5OwogICAgICAgICAgICAgIH0gZWxzZSBpZiAoc3VwcG9ydC5ibG9iICYmIEJsb2IucHJvdG90eXBlLmlzUHJvdG90eXBlT2YoYm9keSkpIHsKICAgICAgICAgICAgICAgIHRoaXMuX2JvZHlCbG9iID0gYm9keTsKICAgICAgICAgICAgICB9IGVsc2UgaWYgKHN1cHBvcnQuZm9ybURhdGEgJiYgRm9ybURhdGEucHJvdG90eXBlLmlzUHJvdG90eXBlT2YoYm9keSkpIHsKICAgICAgICAgICAgICAgIHRoaXMuX2JvZHlGb3JtRGF0YSA9IGJvZHk7CiAgICAgICAgICAgICAgfSBlbHNlIGlmIChzdXBwb3J0LnNlYXJjaFBhcmFtcyAmJiBVUkxTZWFyY2hQYXJhbXMucHJvdG90eXBlLmlzUHJvdG90eXBlT2YoYm9keSkpIHsKICAgICAgICAgICAgICAgIHRoaXMuX2JvZHlUZXh0ID0gYm9keS50b1N0cmluZygpOwogICAgICAgICAgICAgIH0gZWxzZSBpZiAoc3VwcG9ydC5hcnJheUJ1ZmZlciAmJiBzdXBwb3J0LmJsb2IgJiYgaXNEYXRhVmlldyhib2R5KSkgewogICAgICAgICAgICAgICAgdGhpcy5fYm9keUFycmF5QnVmZmVyID0gYnVmZmVyQ2xvbmUoYm9keS5idWZmZXIpOwogICAgICAgICAgICAgICAgdGhpcy5fYm9keUluaXQgPSBuZXcgQmxvYihbdGhpcy5fYm9keUFycmF5QnVmZmVyXSk7CiAgICAgICAgICAgICAgfSBlbHNlIGlmIChzdXBwb3J0LmFycmF5QnVmZmVyICYmIChBcnJheUJ1ZmZlci5wcm90b3R5cGUuaXNQcm90b3R5cGVPZihib2R5KSB8fCBpc0FycmF5QnVmZmVyVmlldyhib2R5KSkpIHsKICAgICAgICAgICAgICAgIHRoaXMuX2JvZHlBcnJheUJ1ZmZlciA9IGJ1ZmZlckNsb25lKGJvZHkpOwogICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICB0aGlzLl9ib2R5VGV4dCA9IGJvZHkgPSBPYmplY3QucHJvdG90eXBlLnRvU3RyaW5nLmNhbGwoYm9keSk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGlmICghdGhpcy5oZWFkZXJzLmdldCgiY29udGVudC10eXBlIikpIHsKICAgICAgICAgICAgICAgIGlmICh0eXBlb2YgYm9keSA9PT0gInN0cmluZyIpIHsKICAgICAgICAgICAgICAgICAgdGhpcy5oZWFkZXJzLnNldCgiY29udGVudC10eXBlIiwgInRleHQvcGxhaW47Y2hhcnNldD1VVEYtOCIpOwogICAgICAgICAgICAgICAgfSBlbHNlIGlmICh0aGlzLl9ib2R5QmxvYiAmJiB0aGlzLl9ib2R5QmxvYi50eXBlKSB7CiAgICAgICAgICAgICAgICAgIHRoaXMuaGVhZGVycy5zZXQoImNvbnRlbnQtdHlwZSIsIHRoaXMuX2JvZHlCbG9iLnR5cGUpOwogICAgICAgICAgICAgICAgfSBlbHNlIGlmIChzdXBwb3J0LnNlYXJjaFBhcmFtcyAmJiBVUkxTZWFyY2hQYXJhbXMucHJvdG90eXBlLmlzUHJvdG90eXBlT2YoYm9keSkpIHsKICAgICAgICAgICAgICAgICAgdGhpcy5oZWFkZXJzLnNldCgiY29udGVudC10eXBlIiwgImFwcGxpY2F0aW9uL3gtd3d3LWZvcm0tdXJsZW5jb2RlZDtjaGFyc2V0PVVURi04Iik7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9OwogICAgICAgICAgICBpZiAoc3VwcG9ydC5ibG9iKSB7CiAgICAgICAgICAgICAgdGhpcy5ibG9iID0gZnVuY3Rpb24oKSB7CiAgICAgICAgICAgICAgICB2YXIgcmVqZWN0ZWQgPSBjb25zdW1lZCh0aGlzKTsKICAgICAgICAgICAgICAgIGlmIChyZWplY3RlZCkgewogICAgICAgICAgICAgICAgICByZXR1cm4gcmVqZWN0ZWQ7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAodGhpcy5fYm9keUJsb2IpIHsKICAgICAgICAgICAgICAgICAgcmV0dXJuIFByb21pc2UucmVzb2x2ZSh0aGlzLl9ib2R5QmxvYik7CiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKHRoaXMuX2JvZHlBcnJheUJ1ZmZlcikgewogICAgICAgICAgICAgICAgICByZXR1cm4gUHJvbWlzZS5yZXNvbHZlKG5ldyBCbG9iKFt0aGlzLl9ib2R5QXJyYXlCdWZmZXJdKSk7CiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKHRoaXMuX2JvZHlGb3JtRGF0YSkgewogICAgICAgICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IoImNvdWxkIG5vdCByZWFkIEZvcm1EYXRhIGJvZHkgYXMgYmxvYiIpOwogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgcmV0dXJuIFByb21pc2UucmVzb2x2ZShuZXcgQmxvYihbdGhpcy5fYm9keVRleHRdKSk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfTsKICAgICAgICAgICAgICB0aGlzLmFycmF5QnVmZmVyID0gZnVuY3Rpb24oKSB7CiAgICAgICAgICAgICAgICBpZiAodGhpcy5fYm9keUFycmF5QnVmZmVyKSB7CiAgICAgICAgICAgICAgICAgIHJldHVybiBjb25zdW1lZCh0aGlzKSB8fCBQcm9taXNlLnJlc29sdmUodGhpcy5fYm9keUFycmF5QnVmZmVyKTsKICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgIHJldHVybiB0aGlzLmJsb2IoKS50aGVuKHJlYWRCbG9iQXNBcnJheUJ1ZmZlcik7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfTsKICAgICAgICAgICAgfQogICAgICAgICAgICB0aGlzLnRleHQgPSBmdW5jdGlvbigpIHsKICAgICAgICAgICAgICB2YXIgcmVqZWN0ZWQgPSBjb25zdW1lZCh0aGlzKTsKICAgICAgICAgICAgICBpZiAocmVqZWN0ZWQpIHsKICAgICAgICAgICAgICAgIHJldHVybiByZWplY3RlZDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgaWYgKHRoaXMuX2JvZHlCbG9iKSB7CiAgICAgICAgICAgICAgICByZXR1cm4gcmVhZEJsb2JBc1RleHQodGhpcy5fYm9keUJsb2IpOwogICAgICAgICAgICAgIH0gZWxzZSBpZiAodGhpcy5fYm9keUFycmF5QnVmZmVyKSB7CiAgICAgICAgICAgICAgICByZXR1cm4gUHJvbWlzZS5yZXNvbHZlKHJlYWRBcnJheUJ1ZmZlckFzVGV4dCh0aGlzLl9ib2R5QXJyYXlCdWZmZXIpKTsKICAgICAgICAgICAgICB9IGVsc2UgaWYgKHRoaXMuX2JvZHlGb3JtRGF0YSkgewogICAgICAgICAgICAgICAgdGhyb3cgbmV3IEVycm9yKCJjb3VsZCBub3QgcmVhZCBGb3JtRGF0YSBib2R5IGFzIHRleHQiKTsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgcmV0dXJuIFByb21pc2UucmVzb2x2ZSh0aGlzLl9ib2R5VGV4dCk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9OwogICAgICAgICAgICBpZiAoc3VwcG9ydC5mb3JtRGF0YSkgewogICAgICAgICAgICAgIHRoaXMuZm9ybURhdGEgPSBmdW5jdGlvbigpIHsKICAgICAgICAgICAgICAgIHJldHVybiB0aGlzLnRleHQoKS50aGVuKGRlY29kZSk7CiAgICAgICAgICAgICAgfTsKICAgICAgICAgICAgfQogICAgICAgICAgICB0aGlzLmpzb24gPSBmdW5jdGlvbigpIHsKICAgICAgICAgICAgICByZXR1cm4gdGhpcy50ZXh0KCkudGhlbihKU09OLnBhcnNlKTsKICAgICAgICAgICAgfTsKICAgICAgICAgICAgcmV0dXJuIHRoaXM7CiAgICAgICAgICB9CiAgICAgICAgICB2YXIgbWV0aG9kcyA9IFsiREVMRVRFIiwgIkdFVCIsICJIRUFEIiwgIk9QVElPTlMiLCAiUE9TVCIsICJQVVQiXTsKICAgICAgICAgIGZ1bmN0aW9uIG5vcm1hbGl6ZU1ldGhvZChtZXRob2QpIHsKICAgICAgICAgICAgdmFyIHVwY2FzZWQgPSBtZXRob2QudG9VcHBlckNhc2UoKTsKICAgICAgICAgICAgcmV0dXJuIG1ldGhvZHMuaW5kZXhPZih1cGNhc2VkKSA+IC0xID8gdXBjYXNlZCA6IG1ldGhvZDsKICAgICAgICAgIH0KICAgICAgICAgIGZ1bmN0aW9uIFJlcXVlc3QoaW5wdXQsIG9wdGlvbnMpIHsKICAgICAgICAgICAgb3B0aW9ucyA9IG9wdGlvbnMgfHwge307CiAgICAgICAgICAgIHZhciBib2R5ID0gb3B0aW9ucy5ib2R5OwogICAgICAgICAgICBpZiAoaW5wdXQgaW5zdGFuY2VvZiBSZXF1ZXN0KSB7CiAgICAgICAgICAgICAgaWYgKGlucHV0LmJvZHlVc2VkKSB7CiAgICAgICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCJBbHJlYWR5IHJlYWQiKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgdGhpcy51cmwgPSBpbnB1dC51cmw7CiAgICAgICAgICAgICAgdGhpcy5jcmVkZW50aWFscyA9IGlucHV0LmNyZWRlbnRpYWxzOwogICAgICAgICAgICAgIGlmICghb3B0aW9ucy5oZWFkZXJzKSB7CiAgICAgICAgICAgICAgICB0aGlzLmhlYWRlcnMgPSBuZXcgSGVhZGVycyhpbnB1dC5oZWFkZXJzKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgdGhpcy5tZXRob2QgPSBpbnB1dC5tZXRob2Q7CiAgICAgICAgICAgICAgdGhpcy5tb2RlID0gaW5wdXQubW9kZTsKICAgICAgICAgICAgICB0aGlzLnNpZ25hbCA9IGlucHV0LnNpZ25hbDsKICAgICAgICAgICAgICBpZiAoIWJvZHkgJiYgaW5wdXQuX2JvZHlJbml0ICE9IG51bGwpIHsKICAgICAgICAgICAgICAgIGJvZHkgPSBpbnB1dC5fYm9keUluaXQ7CiAgICAgICAgICAgICAgICBpbnB1dC5ib2R5VXNlZCA9IHRydWU7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHRoaXMudXJsID0gU3RyaW5nKGlucHV0KTsKICAgICAgICAgICAgfQogICAgICAgICAgICB0aGlzLmNyZWRlbnRpYWxzID0gb3B0aW9ucy5jcmVkZW50aWFscyB8fCB0aGlzLmNyZWRlbnRpYWxzIHx8ICJzYW1lLW9yaWdpbiI7CiAgICAgICAgICAgIGlmIChvcHRpb25zLmhlYWRlcnMgfHwgIXRoaXMuaGVhZGVycykgewogICAgICAgICAgICAgIHRoaXMuaGVhZGVycyA9IG5ldyBIZWFkZXJzKG9wdGlvbnMuaGVhZGVycyk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdGhpcy5tZXRob2QgPSBub3JtYWxpemVNZXRob2Qob3B0aW9ucy5tZXRob2QgfHwgdGhpcy5tZXRob2QgfHwgIkdFVCIpOwogICAgICAgICAgICB0aGlzLm1vZGUgPSBvcHRpb25zLm1vZGUgfHwgdGhpcy5tb2RlIHx8IG51bGw7CiAgICAgICAgICAgIHRoaXMuc2lnbmFsID0gb3B0aW9ucy5zaWduYWwgfHwgdGhpcy5zaWduYWw7CiAgICAgICAgICAgIHRoaXMucmVmZXJyZXIgPSBudWxsOwogICAgICAgICAgICBpZiAoKHRoaXMubWV0aG9kID09PSAiR0VUIiB8fCB0aGlzLm1ldGhvZCA9PT0gIkhFQUQiKSAmJiBib2R5KSB7CiAgICAgICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcigiQm9keSBub3QgYWxsb3dlZCBmb3IgR0VUIG9yIEhFQUQgcmVxdWVzdHMiKTsKICAgICAgICAgICAgfQogICAgICAgICAgICB0aGlzLl9pbml0Qm9keShib2R5KTsKICAgICAgICAgIH0KICAgICAgICAgIFJlcXVlc3QucHJvdG90eXBlLmNsb25lID0gZnVuY3Rpb24oKSB7CiAgICAgICAgICAgIHJldHVybiBuZXcgUmVxdWVzdCh0aGlzLCB7IGJvZHk6IHRoaXMuX2JvZHlJbml0IH0pOwogICAgICAgICAgfTsKICAgICAgICAgIGZ1bmN0aW9uIGRlY29kZShib2R5KSB7CiAgICAgICAgICAgIHZhciBmb3JtID0gbmV3IEZvcm1EYXRhKCk7CiAgICAgICAgICAgIGJvZHkudHJpbSgpLnNwbGl0KCImIikuZm9yRWFjaChmdW5jdGlvbihieXRlcykgewogICAgICAgICAgICAgIGlmIChieXRlcykgewogICAgICAgICAgICAgICAgdmFyIHNwbGl0ID0gYnl0ZXMuc3BsaXQoIj0iKTsKICAgICAgICAgICAgICAgIHZhciBuYW1lID0gc3BsaXQuc2hpZnQoKS5yZXBsYWNlKC9cKy9nLCAiICIpOwogICAgICAgICAgICAgICAgdmFyIHZhbHVlID0gc3BsaXQuam9pbigiPSIpLnJlcGxhY2UoL1wrL2csICIgIik7CiAgICAgICAgICAgICAgICBmb3JtLmFwcGVuZChkZWNvZGVVUklDb21wb25lbnQobmFtZSksIGRlY29kZVVSSUNvbXBvbmVudCh2YWx1ZSkpOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfSk7CiAgICAgICAgICAgIHJldHVybiBmb3JtOwogICAgICAgICAgfQogICAgICAgICAgZnVuY3Rpb24gcGFyc2VIZWFkZXJzKHJhd0hlYWRlcnMpIHsKICAgICAgICAgICAgdmFyIGhlYWRlcnMgPSBuZXcgSGVhZGVycygpOwogICAgICAgICAgICB2YXIgcHJlUHJvY2Vzc2VkSGVhZGVycyA9IHJhd0hlYWRlcnMucmVwbGFjZSgvXHI/XG5bXHQgXSsvZywgIiAiKTsKICAgICAgICAgICAgcHJlUHJvY2Vzc2VkSGVhZGVycy5zcGxpdCgvXHI/XG4vKS5mb3JFYWNoKGZ1bmN0aW9uKGxpbmUpIHsKICAgICAgICAgICAgICB2YXIgcGFydHMgPSBsaW5lLnNwbGl0KCI6Iik7CiAgICAgICAgICAgICAgdmFyIGtleSA9IHBhcnRzLnNoaWZ0KCkudHJpbSgpOwogICAgICAgICAgICAgIGlmIChrZXkpIHsKICAgICAgICAgICAgICAgIHZhciB2YWx1ZSA9IHBhcnRzLmpvaW4oIjoiKS50cmltKCk7CiAgICAgICAgICAgICAgICBoZWFkZXJzLmFwcGVuZChrZXksIHZhbHVlKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0pOwogICAgICAgICAgICByZXR1cm4gaGVhZGVyczsKICAgICAgICAgIH0KICAgICAgICAgIEJvZHkuY2FsbChSZXF1ZXN0LnByb3RvdHlwZSk7CiAgICAgICAgICBmdW5jdGlvbiBSZXNwb25zZShib2R5SW5pdCwgb3B0aW9ucykgewogICAgICAgICAgICBpZiAoIW9wdGlvbnMpIHsKICAgICAgICAgICAgICBvcHRpb25zID0ge307CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdGhpcy50eXBlID0gImRlZmF1bHQiOwogICAgICAgICAgICB0aGlzLnN0YXR1cyA9IG9wdGlvbnMuc3RhdHVzID09PSB2b2lkIDAgPyAyMDAgOiBvcHRpb25zLnN0YXR1czsKICAgICAgICAgICAgdGhpcy5vayA9IHRoaXMuc3RhdHVzID49IDIwMCAmJiB0aGlzLnN0YXR1cyA8IDMwMDsKICAgICAgICAgICAgdGhpcy5zdGF0dXNUZXh0ID0gInN0YXR1c1RleHQiIGluIG9wdGlvbnMgPyBvcHRpb25zLnN0YXR1c1RleHQgOiAiT0siOwogICAgICAgICAgICB0aGlzLmhlYWRlcnMgPSBuZXcgSGVhZGVycyhvcHRpb25zLmhlYWRlcnMpOwogICAgICAgICAgICB0aGlzLnVybCA9IG9wdGlvbnMudXJsIHx8ICIiOwogICAgICAgICAgICB0aGlzLl9pbml0Qm9keShib2R5SW5pdCk7CiAgICAgICAgICB9CiAgICAgICAgICBCb2R5LmNhbGwoUmVzcG9uc2UucHJvdG90eXBlKTsKICAgICAgICAgIFJlc3BvbnNlLnByb3RvdHlwZS5jbG9uZSA9IGZ1bmN0aW9uKCkgewogICAgICAgICAgICByZXR1cm4gbmV3IFJlc3BvbnNlKHRoaXMuX2JvZHlJbml0LCB7CiAgICAgICAgICAgICAgc3RhdHVzOiB0aGlzLnN0YXR1cywKICAgICAgICAgICAgICBzdGF0dXNUZXh0OiB0aGlzLnN0YXR1c1RleHQsCiAgICAgICAgICAgICAgaGVhZGVyczogbmV3IEhlYWRlcnModGhpcy5oZWFkZXJzKSwKICAgICAgICAgICAgICB1cmw6IHRoaXMudXJsCiAgICAgICAgICAgIH0pOwogICAgICAgICAgfTsKICAgICAgICAgIFJlc3BvbnNlLmVycm9yID0gZnVuY3Rpb24oKSB7CiAgICAgICAgICAgIHZhciByZXNwb25zZSA9IG5ldyBSZXNwb25zZShudWxsLCB7IHN0YXR1czogMCwgc3RhdHVzVGV4dDogIiIgfSk7CiAgICAgICAgICAgIHJlc3BvbnNlLnR5cGUgPSAiZXJyb3IiOwogICAgICAgICAgICByZXR1cm4gcmVzcG9uc2U7CiAgICAgICAgICB9OwogICAgICAgICAgdmFyIHJlZGlyZWN0U3RhdHVzZXMgPSBbMzAxLCAzMDIsIDMwMywgMzA3LCAzMDhdOwogICAgICAgICAgUmVzcG9uc2UucmVkaXJlY3QgPSBmdW5jdGlvbih1cmwsIHN0YXR1cykgewogICAgICAgICAgICBpZiAocmVkaXJlY3RTdGF0dXNlcy5pbmRleE9mKHN0YXR1cykgPT09IC0xKSB7CiAgICAgICAgICAgICAgdGhyb3cgbmV3IFJhbmdlRXJyb3IoIkludmFsaWQgc3RhdHVzIGNvZGUiKTsKICAgICAgICAgICAgfQogICAgICAgICAgICByZXR1cm4gbmV3IFJlc3BvbnNlKG51bGwsIHsgc3RhdHVzLCBoZWFkZXJzOiB7IGxvY2F0aW9uOiB1cmwgfSB9KTsKICAgICAgICAgIH07CiAgICAgICAgICBleHBvcnRzMi5ET01FeGNlcHRpb24gPSBzZWxmMi5ET01FeGNlcHRpb247CiAgICAgICAgICB0cnkgewogICAgICAgICAgICBuZXcgZXhwb3J0czIuRE9NRXhjZXB0aW9uKCk7CiAgICAgICAgICB9IGNhdGNoIChlcnIpIHsKICAgICAgICAgICAgZXhwb3J0czIuRE9NRXhjZXB0aW9uID0gZnVuY3Rpb24obWVzc2FnZSwgbmFtZSkgewogICAgICAgICAgICAgIHRoaXMubWVzc2FnZSA9IG1lc3NhZ2U7CiAgICAgICAgICAgICAgdGhpcy5uYW1lID0gbmFtZTsKICAgICAgICAgICAgICB2YXIgZXJyb3IgPSBFcnJvcihtZXNzYWdlKTsKICAgICAgICAgICAgICB0aGlzLnN0YWNrID0gZXJyb3Iuc3RhY2s7CiAgICAgICAgICAgIH07CiAgICAgICAgICAgIGV4cG9ydHMyLkRPTUV4Y2VwdGlvbi5wcm90b3R5cGUgPSBPYmplY3QuY3JlYXRlKEVycm9yLnByb3RvdHlwZSk7CiAgICAgICAgICAgIGV4cG9ydHMyLkRPTUV4Y2VwdGlvbi5wcm90b3R5cGUuY29uc3RydWN0b3IgPSBleHBvcnRzMi5ET01FeGNlcHRpb247CiAgICAgICAgICB9CiAgICAgICAgICBmdW5jdGlvbiBmZXRjaDIoaW5wdXQsIGluaXQyKSB7CiAgICAgICAgICAgIHJldHVybiBuZXcgUHJvbWlzZShmdW5jdGlvbihyZXNvbHZlLCByZWplY3QpIHsKICAgICAgICAgICAgICB2YXIgcmVxdWVzdCA9IG5ldyBSZXF1ZXN0KGlucHV0LCBpbml0Mik7CiAgICAgICAgICAgICAgaWYgKHJlcXVlc3Quc2lnbmFsICYmIHJlcXVlc3Quc2lnbmFsLmFib3J0ZWQpIHsKICAgICAgICAgICAgICAgIHJldHVybiByZWplY3QobmV3IGV4cG9ydHMyLkRPTUV4Y2VwdGlvbigiQWJvcnRlZCIsICJBYm9ydEVycm9yIikpOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB2YXIgeGhyID0gbmV3IFhNTEh0dHBSZXF1ZXN0KCk7CiAgICAgICAgICAgICAgZnVuY3Rpb24gYWJvcnRYaHIoKSB7CiAgICAgICAgICAgICAgICB4aHIuYWJvcnQoKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgeGhyLm9ubG9hZCA9IGZ1bmN0aW9uKCkgewogICAgICAgICAgICAgICAgdmFyIG9wdGlvbnMgPSB7CiAgICAgICAgICAgICAgICAgIHN0YXR1czogeGhyLnN0YXR1cywKICAgICAgICAgICAgICAgICAgc3RhdHVzVGV4dDogeGhyLnN0YXR1c1RleHQsCiAgICAgICAgICAgICAgICAgIGhlYWRlcnM6IHBhcnNlSGVhZGVycyh4aHIuZ2V0QWxsUmVzcG9uc2VIZWFkZXJzKCkgfHwgIiIpCiAgICAgICAgICAgICAgICB9OwogICAgICAgICAgICAgICAgb3B0aW9ucy51cmwgPSAicmVzcG9uc2VVUkwiIGluIHhociA/IHhoci5yZXNwb25zZVVSTCA6IG9wdGlvbnMuaGVhZGVycy5nZXQoIlgtUmVxdWVzdC1VUkwiKTsKICAgICAgICAgICAgICAgIHZhciBib2R5ID0gInJlc3BvbnNlIiBpbiB4aHIgPyB4aHIucmVzcG9uc2UgOiB4aHIucmVzcG9uc2VUZXh0OwogICAgICAgICAgICAgICAgcmVzb2x2ZShuZXcgUmVzcG9uc2UoYm9keSwgb3B0aW9ucykpOwogICAgICAgICAgICAgIH07CiAgICAgICAgICAgICAgeGhyLm9uZXJyb3IgPSBmdW5jdGlvbigpIHsKICAgICAgICAgICAgICAgIHJlamVjdChuZXcgVHlwZUVycm9yKCJOZXR3b3JrIHJlcXVlc3QgZmFpbGVkIikpOwogICAgICAgICAgICAgIH07CiAgICAgICAgICAgICAgeGhyLm9udGltZW91dCA9IGZ1bmN0aW9uKCkgewogICAgICAgICAgICAgICAgcmVqZWN0KG5ldyBUeXBlRXJyb3IoIk5ldHdvcmsgcmVxdWVzdCBmYWlsZWQiKSk7CiAgICAgICAgICAgICAgfTsKICAgICAgICAgICAgICB4aHIub25hYm9ydCA9IGZ1bmN0aW9uKCkgewogICAgICAgICAgICAgICAgcmVqZWN0KG5ldyBleHBvcnRzMi5ET01FeGNlcHRpb24oIkFib3J0ZWQiLCAiQWJvcnRFcnJvciIpKTsKICAgICAgICAgICAgICB9OwogICAgICAgICAgICAgIHhoci5vcGVuKHJlcXVlc3QubWV0aG9kLCByZXF1ZXN0LnVybCwgdHJ1ZSk7CiAgICAgICAgICAgICAgaWYgKHJlcXVlc3QuY3JlZGVudGlhbHMgPT09ICJpbmNsdWRlIikgewogICAgICAgICAgICAgICAgeGhyLndpdGhDcmVkZW50aWFscyA9IHRydWU7CiAgICAgICAgICAgICAgfSBlbHNlIGlmIChyZXF1ZXN0LmNyZWRlbnRpYWxzID09PSAib21pdCIpIHsKICAgICAgICAgICAgICAgIHhoci53aXRoQ3JlZGVudGlhbHMgPSBmYWxzZTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgaWYgKCJyZXNwb25zZVR5cGUiIGluIHhociAmJiBzdXBwb3J0LmJsb2IpIHsKICAgICAgICAgICAgICAgIHhoci5yZXNwb25zZVR5cGUgPSAiYmxvYiI7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIHJlcXVlc3QuaGVhZGVycy5mb3JFYWNoKGZ1bmN0aW9uKHZhbHVlLCBuYW1lKSB7CiAgICAgICAgICAgICAgICB4aHIuc2V0UmVxdWVzdEhlYWRlcihuYW1lLCB2YWx1ZSk7CiAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgICAgaWYgKHJlcXVlc3Quc2lnbmFsKSB7CiAgICAgICAgICAgICAgICByZXF1ZXN0LnNpZ25hbC5hZGRFdmVudExpc3RlbmVyKCJhYm9ydCIsIGFib3J0WGhyKTsKICAgICAgICAgICAgICAgIHhoci5vbnJlYWR5c3RhdGVjaGFuZ2UgPSBmdW5jdGlvbigpIHsKICAgICAgICAgICAgICAgICAgaWYgKHhoci5yZWFkeVN0YXRlID09PSA0KSB7CiAgICAgICAgICAgICAgICAgICAgcmVxdWVzdC5zaWduYWwucmVtb3ZlRXZlbnRMaXN0ZW5lcigiYWJvcnQiLCBhYm9ydFhocik7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH07CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIHhoci5zZW5kKHR5cGVvZiByZXF1ZXN0Ll9ib2R5SW5pdCA9PT0gInVuZGVmaW5lZCIgPyBudWxsIDogcmVxdWVzdC5fYm9keUluaXQpOwogICAgICAgICAgICB9KTsKICAgICAgICAgIH0KICAgICAgICAgIGZldGNoMi5wb2x5ZmlsbCA9IHRydWU7CiAgICAgICAgICBpZiAoIXNlbGYyLmZldGNoKSB7CiAgICAgICAgICAgIHNlbGYyLmZldGNoID0gZmV0Y2gyOwogICAgICAgICAgICBzZWxmMi5IZWFkZXJzID0gSGVhZGVyczsKICAgICAgICAgICAgc2VsZjIuUmVxdWVzdCA9IFJlcXVlc3Q7CiAgICAgICAgICAgIHNlbGYyLlJlc3BvbnNlID0gUmVzcG9uc2U7CiAgICAgICAgICB9CiAgICAgICAgICBleHBvcnRzMi5IZWFkZXJzID0gSGVhZGVyczsKICAgICAgICAgIGV4cG9ydHMyLlJlcXVlc3QgPSBSZXF1ZXN0OwogICAgICAgICAgZXhwb3J0czIuUmVzcG9uc2UgPSBSZXNwb25zZTsKICAgICAgICAgIGV4cG9ydHMyLmZldGNoID0gZmV0Y2gyOwogICAgICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KGV4cG9ydHMyLCAiX19lc01vZHVsZSIsIHsgdmFsdWU6IHRydWUgfSk7CiAgICAgICAgICByZXR1cm4gZXhwb3J0czI7CiAgICAgICAgfSh7fSk7CiAgICAgIH0pKHR5cGVvZiBzZWxmICE9PSAidW5kZWZpbmVkIiA/IHNlbGYgOiBleHBvcnRzKTsKICAgIH0KICB9KTsKCiAgLy8gc3JjL2RhdGEtZmV0Y2hlcnMvYmFtL2JhbS13b3JrZXIudHM/d29ya2VyJmlubGluZT93b3JrZXJfZmlsZQogIGlu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KICAgICAgICBpZiAobGFzdENodW5rID09PSBudWxsKSB7CiAgICAgICAgICBtZXJnZWRDaHVua3MucHVzaChjaHVuayk7CiAgICAgICAgICBsYXN0Q2h1bmsgPSBjaHVuazsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgaWYgKGNhbk1lcmdlQmxvY2tzKGxhc3RDaHVuaywgY2h1bmspKSB7CiAgICAgICAgICAgIGlmIChjaHVuay5tYXh2LmNvbXBhcmVUbyhsYXN0Q2h1bmsubWF4dikgPiAwKSB7CiAgICAgICAgICAgICAgbGFzdENodW5rLm1heHYgPSBjaHVuay5tYXh2OwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBtZXJnZWRDaHVua3MucHVzaChjaHVuayk7CiAgICAgICAgICAgIGxhc3RDaHVuayA9IGNodW5rOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgfSk7CiAgICByZXR1cm4gbWVyZ2VkQ2h1bmtzOwogIH0KCiAgLy8gbm9kZV9tb2R1bGVzLy5wbnBtL0BnbW9kK2JhbUAxLjEuMTgvbm9kZV9tb2R1bGVzL0BnbW9kL2JhbS9lc20vYmFpLmpzCiAgdmFyIEJBSV9NQUdJQyA9IDIxNTc4MDUwOwogIGZ1bmN0aW9uIHJvdW5kRG93bihuLCBtdWx0aXBsZSkgewogICAgcmV0dXJuIG4gLSBuICUgbXVsdGlwbGU7CiAgfQogIGZ1bmN0aW9uIHJvdW5kVXAobiwgbXVsdGlwbGUpIHsKICAgIHJldHVybiBuIC0gbiAlIG11bHRpcGxlICsgbXVsdGlwbGU7CiAgfQogIHZhciBCQUkgPSBjbGFzcyBleHRlbmRzIEluZGV4RmlsZSB7CiAgICBwYXJzZVBzZXVkb0JpbihieXRlcywgb2Zmc2V0KSB7CiAgICAgIGNvbnN0IGxpbmVDb3VudCA9IGxvbmdUb051bWJlcihpbXBvcnRfbG9uZy5kZWZhdWx0LmZyb21CeXRlc0xFKEFycmF5LnByb3RvdHlwZS5zbGljZS5jYWxsKGJ5dGVzLCBvZmZzZXQgKyAxNiwgb2Zmc2V0ICsgMjQpLCB0cnVlKSk7CiAgICAgIHJldHVybiB7IGxpbmVDb3VudCB9OwogICAgfQogICAgYXN5bmMgbGluZUNvdW50KHJlZklkLCBvcHRzID0ge30pIHsKICAgICAgY29uc3QgcHJvbSA9IGF3YWl0IHRoaXMucGFyc2Uob3B0cyk7CiAgICAgIGNvbnN0IGluZGV4ID0gcHJvbS5pbmRpY2VzW3JlZklkXTsKICAgICAgaWYgKCFpbmRleCkgewogICAgICAgIHJldHVybiAtMTsKICAgICAgfQogICAgICBjb25zdCByZXQgPSBpbmRleC5zdGF0cyB8fCB7fTsKICAgICAgcmV0dXJuIHJldC5saW5lQ291bnQgPT09IHZvaWQgMCA/IC0xIDogcmV0LmxpbmVDb3VudDsKICAgIH0KICAgIGZldGNoQmFpKG9wdHMgPSB7fSkgewogICAgICBpZiAoIXRoaXMuYmFpUCkgewogICAgICAgIHRoaXMuYmFpUCA9IHRoaXMuZmlsZWhhbmRsZS5yZWFkRmlsZShvcHRzKS5jYXRjaCgoZSkgPT4gewogICAgICAgICAgdGhpcy5iYWlQID0gdm9pZCAwOwogICAgICAgICAgdGhyb3cgZTsKICAgICAgICB9KTsKICAgICAgfQogICAgICByZXR1cm4gdGhpcy5iYWlQOwogICAgfQogICAgYXN5bmMgX3BhcnNlKCkgewogICAgICBjb25zdCBkYXRhID0geyBiYWk6IHRydWUsIG1heEJsb2NrU2l6ZTogMSA8PCAxNiB9OwogICAgICBjb25zdCBieXRlcyA9IGF3YWl0IHRoaXMuZmV0Y2hCYWkoKTsKICAgICAgaWYgKGJ5dGVzLnJlYWRVSW50MzJMRSgwKSAhPT0gQkFJX01BR0lDKSB7CiAgICAgICAgdGhyb3cgbmV3IEVycm9yKCJOb3QgYSBCQUkgZmlsZSIpOwogICAgICB9CiAgICAgIGRhdGEucmVmQ291bnQgPSBieXRlcy5yZWFkSW50MzJMRSg0KTsKICAgICAgY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9IDQ7CiAgICAgICAgICAgIGNvbnN0IGNodW5rcyA9IG5ldyBBcnJheShjaHVua0NvdW50KTsKICAgICAgICAgICAgZm9yIChsZXQgayA9IDA7IGsgPCBjaHVua0NvdW50OyBrICs9IDEpIHsKICAgICAgICAgICAgICBjb25zdCB1ID0gZnJvbUJ5dGVzKGJ5dGVzLCBjdXJyT2Zmc2V0KTsKICAgICAgICAgICAgICBjb25zdCB2ID0gZnJvbUJ5dGVzKGJ5dGVzLCBjdXJyT2Zmc2V0ICsgOCk7CiAgICAgICAgICAgICAgY3Vyck9mZnNldCArPSAxNjsKICAgICAgICAgICAgICB0aGlzLl9maW5kRmlyc3REYXRhKGRhdGEsIHUpOwogICAgICAgICAgICAgIGNodW5rc1trXSA9IG5ldyBDaHVuayh1LCB2LCBiaW4pOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGJpbkluZGV4W2Jpbl0gPSBjaHVua3M7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGNvbnN0IGxpbmVhckNvdW50ID0gYnl0ZXMucmVhZEludDMyTEUoY3Vyck9mZnNldCk7CiAgICAgICAgY3Vyck9mZnNldCArPSA0OwogICAgICAgIGNvbnN0IGxpbmVhckluZGV4ID0gbmV3IEFycmF5KGxpbmVhckNvdW50KTsKICAgICAgICBmb3IgKGxldCBrID0gMDsgayA8IGxpbmVhckNvdW50OyBrICs9IDEpIHsKICAgICAgICAgIGxpbmVhckluZGV4W2tdID0gZnJvbUJ5dGVzKGJ5dGVzLCBjdXJyT2Zmc2V0KTsKICAgICAgICAgIGN1cnJPZmZzZXQgKz0gODsKICAgICAgICAgIHRoaXMuX2ZpbmRGaXJzdERhdGEoZGF0YSwgbGluZWFySW5kZXhba10pOwogICAgICAgIH0KICAgICAgICBkYXRhLmluZGljZXNbaV0gPSB7IGJpbkluZGV4LCBsaW5lYXJJbmRleCwgc3RhdHMgfTsKICAgICAgfQogICAgICByZXR1cm4gZGF0YTsKICAgIH0KICAgIGFzeW5jIGluZG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ICAgbGV0IGN1cnJlbnRQb3MgPSBsaW5lYXJJbmRleFtzIC8gdl0uYmxvY2tQb3NpdGlvbjsKICAgICAgZm9yIChsZXQgaSA9IHMgLyB2LCBqID0gMDsgaSA8IGUgLyB2OyBpKyssIGorKykgewogICAgICAgIGRlcHRoc1tqXSA9IHsKICAgICAgICAgIHNjb3JlOiBsaW5lYXJJbmRleFtpICsgMV0uYmxvY2tQb3NpdGlvbiAtIGN1cnJlbnRQb3MsCiAgICAgICAgICBzdGFydDogaSAqIHYsCiAgICAgICAgICBlbmQ6IGkgKiB2ICsgdgogICAgICAgIH07CiAgICAgICAgY3VycmVudFBvcyA9IGxpbmVhckluZGV4W2kgKyAxXS5ibG9ja1Bvc2l0aW9uOwogICAgICB9CiAgICAgIHJldHVybiBkZXB0aHMubWFwKChkKSA9PiB7CiAgICAgICAgcmV0dXJuIHsgLi4uZCwgc2NvcmU6IGQuc2NvcmUgKiBzdGF0cy5saW5lQ291bnQgLyB0b3RhbFNpemUgfTsKICAgICAgfSk7CiAgICB9CiAgICByZWcyYmlucyhiZWcsIGVuZCkgewogICAgICBlbmQgLT0gMTsKICAgICAgcmV0dXJuIFsKICAgICAgICBbMCwgMF0sCiAgICAgICAgWzEgKyAoYmVnID4+IDI2KSwgMSArIChlbmQgPj4gMjYpXSwKICAgICAgICBbOSArIChiZWcgPj4gMjMpLCA5ICsgKGVuZCA+PiAyMyldLAogICAgICAgIFs3MyArIChiZWcgPj4gMjApLCA3MyArIChlbmQgPj4gMjApXSwKICAgICAgICBbNTg1ICsgKGJlZyA+PiAxNyksIDU4NSArIChlbmQgPj4gMTcpXSwKICAgICAgICBbNDY4MSArIChiZWcgPj4gMTQpLCA0NjgxICsgKGVuZCA+PiAxNCldCiAgICAgIF07CiAgICB9CiAgICBhc3luYyBibG9ja3NGb3JSYW5nZShyZWZJZCwgbWluLCBtYXgsIG9wdHMgPSB7fSkgewogICAgICBpZiAobWluIDwgMCkgewogICAgICAgIG1pbiA9IDA7CiAgICAgIH0KICAgICAgY29uc3QgaW5kZXhEYXRhID0gYXdhaXQgdGhpcy5wYXJzZShvcHRzKTsKICAgICAgaWYgKCFpbmRleERhdGEpIHsKICAgICAgICByZXR1cm4gW107CiAgICAgIH0KICAgICAgY29uc3QgYmEgPSBpbmRleERhdGEuaW5kaWNlc1tyZWZJZF07CiAgICAgIGlmICghYmEpIHsKICAgICAgICByZXR1cm4gW107CiAgICAgIH0KICAgICAgY29uc3Qgb3ZlcmxhcHBpbmdCaW5zID0gdGhpcy5yZWcyYmlucyhtaW4sIG1heCk7CiAgICAgIGNvbnN0IGNodW5rcyA9IFtdOwogICAgICBmb3IgKGNvbnN0IFtzdGFydCwgZW5kXSBvZiBvdmVybGFwcGluZ0JpbnMpIHsKICAgICAgICBmb3IgKGxldCBiaW4gPSBzdGFydDsgYmluIDw9IGVuZDsgYmluKyspIHsKICAgICAgICAgIGlmIChiYS5iaW5JbmRleFtiaW5dKSB7CiAgICAgICAgICAgIGNvbnN0IGJpbkNodW5rcyA9IGJhLmJpbkluZGV4W2Jpbl07CiAgICAgICAgICAgIGZvciAobGV0IGMgPSAwOyBjIDwgYmluQ2h1bmtzLmxlbmd0aDsgKytjKSB7CiAgICAgICAgICAgICAgY2h1bmtzLnB1c2gobmV3IENodW5rKGJpbkNodW5rc1tjXS5taW52LCBiaW5DaHVua3NbY10ubWF4diwgYmluKSk7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgICAgY29uc3QgbmludHYgPSBiYS5saW5lYXJJbmRleC5sZW5ndGg7CiAgICAgIGxldCBsb3dlc3QgPSBudWxsOwogICAgICBjb25zdCBtaW5MaW4gPSBNYXRoLm1pbihtaW4gPj4gMTQsIG5pbnR2IC0gMSk7CiAgICAgIGNvbnN0IG1heExpbiA9IE1hdGgubWluKG1heCA+PiAxNCwgbmludHYgLSAxKTsKICAgICAgZm9yIChsZXQgaSA9IG1pbkxpbjsgaSA8PSBtYXhMaW47ICsraSkgew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sKICAgICAgICBjb25zdCByZXNwb25zZURhdGEgPSBhd2FpdCB0aGlzLmdldEJ1ZmZlckZyb21SZXNwb25zZShyZXNwb25zZSk7CiAgICAgICAgY29uc3QgYnl0ZXNDb3BpZWQgPSByZXNwb25zZURhdGEuY29weShidWZmZXIsIG9mZnNldCwgMCwgTWF0aC5taW4obGVuZ3RoLCByZXNwb25zZURhdGEubGVuZ3RoKSk7CiAgICAgICAgY29uc3QgcmVzID0gcmVzcG9uc2UuaGVhZGVycy5nZXQoImNvbnRlbnQtcmFuZ2UiKTsKICAgICAgICBjb25zdCBzaXplTWF0Y2ggPSAvXC8oXGQrKSQvLmV4ZWMocmVzIHx8ICIiKTsKICAgICAgICBpZiAoc2l6ZU1hdGNoICYmIHNpemVNYXRjaFsxXSkgewogICAgICAgICAgdGhpcy5fc3RhdCA9IHsgc2l6ZTogcGFyc2VJbnQoc2l6ZU1hdGNoWzFdLCAxMCkgfTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHsgYnl0ZXNSZWFkOiBieXRlc0NvcGllZCwgYnVmZmVyIH07CiAgICAgIH0KICAgICAgaWYgKHJlc3BvbnNlLnN0YXR1cyA9PT0gMjAwKSB7CiAgICAgICAgdGhyb3cgbmV3IEVycm9yKCIke3RoaXMudXJsfSBmZXRjaCByZXR1cm5lZCBzdGF0dXMgMjAwLCBleHBlY3RlZCAyMDYiKTsKICAgICAgfQogICAgICB0aHJvdyBuZXcgRXJyb3IoYEhUVFAgJHtyZXNwb25zZS5zdGF0dXN9IGZldGNoaW5nICR7dGhpcy51cmx9YCk7CiAgICB9CiAgICBhc3luYyByZWFkRmlsZShvcHRpb25zID0ge30pIHsKICAgICAgbGV0IGVuY29kaW5nOwogICAgICBsZXQgb3B0czsKICAgICAgaWYgKHR5cGVvZiBvcHRpb25zID09PSAic3RyaW5nIikgewogICAgICAgIGVuY29kaW5nID0gb3B0aW9uczsKICAgICAgICBvcHRzID0ge307CiAgICAgIH0gZWxzZSB7CiAgICAgICAgZW5jb2RpbmcgPSBvcHRpb25zLmVuY29kaW5nOwogICAgICAgIG9wdHMgPSBvcHRpb25zOwogICAgICAgIGRlbGV0ZSBvcHRzLmVuY29kaW5nOwogICAgICB9CiAgICAgIGNvbnN0IHsgaGVhZGVycyA9IHt9LCBzaWduYWwsIG92ZXJyaWRlcyA9IHt9IH0gPSBvcHRzOwogICAgICBjb25zdCBhcmdzID0gewogICAgICAgIGhlYWRlcnMsCiAgICAgICAgbWV0aG9kOiAiR0VUIiwKICAgICAgICByZWRpcmVjdDogImZvbGxvdyIsCiAgICAgICAgbW9kZTogImNvcnMiLAogICAgICAgIHNpZ25hbCwKICAgICAgICAuLi50aGlzLmJhc2VPdmVycmlkZXMsCiAgICAgICAgLi4ub3ZlcnJpZGVzCiAgICAgIH07CiAgICAgIGNvbnN0IHJlc3BvbnNlID0gYXdhaXQgdGhpcy5mZXRjaCh0aGlzLnVybCwgYXJncyk7CiAgICAgIGlmICghcmVzcG9uc2UpIHsKICAgICAgICB0aHJvdyBuZXcgRXJyb3IoImdlbmVyaWMtZmlsZWhhbmRsZSBmYWlsZWQgdG8gZmV0Y2giKTsKICAgICAgfQogICAgICBpZiAocmVzcG9uc2Uuc3RhdHVzICE9PSAyMDApIHsKICAgICAgICB0aHJvdyBPYmplY3QuYXNzaWduKG5ldyBFcnJvcihgSFRUUCAke3Jlc3BvbnNlLnN0YXR1c30gZmV0Y2hpbmcgJHt0aGlzLnVybH1gKSwgewogICAgICAgICAgc3RhdHVzOiByZXNwb25zZS5zdGF0dXMKICAgICAgICB9KTsKICAgICAgfQogICAgICBpZiAoZW5jb2RpbmcgPT09ICJ1dGY4IikgewogICAgICAgIHJldHVybiByZXNwb25zZS50ZXh0KCk7CiAgICAgIH0KICAgICAgaWYgKGVuY29kaW5nKSB7CiAgICAgICAgdGhyb3cgbmV3IEVycm9yKGB1bnN1cHBvcnRlZCBlbmNvZGluZzogJHtlbmNvZGluZ31gKTsKICAgICAgfQogICAgICByZXR1cm4gdGhp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ciBpbXBvcnRfYnVmZmVyNCA9IF9fdG9Nb2R1bGUocmVxdWlyZV9idWZmZXIoKSk7CiAgdmFyIGltcG9ydF9wYWtvID0gX190b01vZHVsZShyZXF1aXJlX3Bha28oKSk7CiAgYXN5bmMgZnVuY3Rpb24gdW56aXAoaW5wdXREYXRhKSB7CiAgICB0cnkgewogICAgICBsZXQgc3RybTsKICAgICAgbGV0IHBvcyA9IDA7CiAgICAgIGxldCBpID0gMDsKICAgICAgY29uc3QgY2h1bmtzID0gW107CiAgICAgIGxldCB0b3RhbFNpemUgPSAwOwogICAgICBsZXQgaW5mbGF0b3I7CiAgICAgIGRvIHsKICAgICAgICBjb25zdCByZW1haW5pbmdJbnB1dCA9IGlucHV0RGF0YS5zdWJhcnJheShwb3MpOwogICAgICAgIGluZmxhdG9yID0gbmV3IGltcG9ydF9wYWtvLkluZmxhdGUoKTsKICAgICAgICAoeyBzdHJtIH0gPSBpbmZsYXRvcik7CiAgICAgICAgaW5mbGF0b3IucHVzaChyZW1haW5pbmdJbnB1dCwgaW1wb3J0X3Bha28uWl9TWU5DX0ZMVVNIKTsKICAgICAgICBpZiAoaW5mbGF0b3IuZXJyKSB7CiAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IoaW5mbGF0b3IubXNnKTsKICAgICAgICB9CiAgICAgICAgcG9zICs9IHN0cm0ubmV4dF9pbjsKICAgICAgICBjaHVua3NbaV0gPSBpbmZsYXRvci5yZXN1bHQ7CiAgICAgICAgdG90YWxTaXplICs9IGNodW5rc1tpXS5sZW5ndGg7CiAgICAgICAgaSArPSAxOwogICAgICB9IHdoaWxlIChzdHJtLmF2YWlsX2luKTsKICAgICAgY29uc3QgcmVzdWx0ID0gbmV3IFVpbnQ4QXJyYXkodG90YWxTaXplKTsKICAgICAgZm9yIChsZXQgaTIgPSAwLCBvZmZzZXQgPSAwOyBpMiA8IGNodW5rcy5sZW5ndGg7IGkyKyspIHsKICAgICAgICByZXN1bHQuc2V0KGNodW5rc1tpMl0sIG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0gpOwogICAgICAgIGlmIChpbmZsYXRvci5lcnIpIHsKICAgICAgICAgIHRocm93IG5ldyBFcnJvcihpbmZsYXRvci5tc2cpOwogICAgICAgIH0KICAgICAgICBjb25zdCBidWZmZXIyID0gaW5mbGF0b3IucmVzdWx0OwogICAgICAgIGNodW5rcy5wdXNoKGJ1ZmZlcjIpOwogICAgICAgIGxldCBsZW4gPSBidWZmZXIyLmxlbmd0aDsKICAgICAgICBjcG9zaXRpb25zLnB1c2goY3Bvcyk7CiAgICAgICAgZHBvc2l0aW9ucy5wdXNoKGRwb3MpOwogICAgICAgIGlmIChjaHVua3MubGVuZ3RoID09PSAxICYmIG1pbnYuZGF0YVBvc2l0aW9uKSB7CiAgICAgICAgICBjaHVua3NbMF0gPSBjaHVua3NbMF0uc3ViYXJyYXkobWludi5kYXRhUG9zaXRpb24pOwogICAgICAgICAgbGVuID0gY2h1bmtzWzBdLmxlbmd0aDsKICAgICAgICB9CiAgICAgICAgY29uc3Qgb3JpZ0Nwb3MgPSBjcG9zOwogICAgICAgIGNwb3MgKz0gc3RybS5uZXh0X2luOwogICAgICAgIGRwb3MgKz0gbGVuOwogICAgICAgIGlmIChvcmlnQ3BvcyA+PSBtYXh2LmJsb2NrUG9zaXRpb24pIHsKICAgICAgICAgIGNodW5rc1tpXSA9IGNodW5rc1tpXS5zdWJhcnJheSgwLCBtYXh2LmJsb2NrUG9zaXRpb24gPT09IG1pbnYuYmxvY2tQb3NpdGlvbiA/IG1heHYuZGF0YVBvc2l0aW9uIC0gbWludi5kYXRhUG9zaXRpb24gKyAxIDogbWF4di5kYXRhUG9zaXRpb24gKyAxKTsKICAgICAgICAgIGNwb3NpdGlvbnMucHVzaChjcG9zKTsKICAgICAgICAgIGRwb3NpdGlvbnMucHVzaChkcG9zKTsKICAgICAgICAgIHRvdGFsU2l6ZSArPSBjaHVua3NbaV0ubGVuZ3RoOwogICAgICAgICAgYnJlYWs7CiAgICAgICAgfQogICAgICAgIHRvdGFsU2l6ZSArPS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ub2RlX21vZHVsZXMvQGdtb2QvYmFtL2VzbS9jc2kuanMKICB2YXIgQ1NJMV9NQUdJQyA9IDIxNTgyNjU5OwogIHZhciBDU0kyX01BR0lDID0gMzgzNTk4NzU7CiAgZnVuY3Rpb24gbHNoaWZ0KG51bSwgYml0cykgewogICAgcmV0dXJuIG51bSAqIDIgKiogYml0czsKICB9CiAgZnVuY3Rpb24gcnNoaWZ0KG51bSwgYml0cykgewogICAgcmV0dXJuIE1hdGguZmxvb3IobnVtIC8gMiAqKiBiaXRzKTsKICB9CiAgdmFyIENTSSA9IGNsYXNzIGV4dGVuZHMgSW5kZXhGaWxlIHsKICAgIGNvbnN0cnVjdG9yKGFyZ3MpIHsKICAgICAgc3VwZXIoYXJncyk7CiAgICAgIHRoaXMubWF4QmluTnVtYmVyID0gMDsKICAgICAgdGhpcy5kZXB0aCA9IDA7CiAgICAgIHRoaXMubWluU2hpZnQgPSAwOwogICAgfQogICAgYXN5bmMgbGluZUNvdW50KHJlZklkKSB7CiAgICAgIGNvbnN0IGluZGV4RGF0YSA9IGF3YWl0IHRoaXMucGFyc2UoKTsKICAgICAgaWYgKCFpbmRleERhdGEpIHsKICAgICAgICByZXR1cm4gLTE7CiAgICAgIH0KICAgICAgY29uc3QgaWR4ID0gaW5kZXhEYXRhLmluZGljZXNbcmVmSWRdOwogICAgICBpZiAoIWlkeCkgewogICAgICAgIHJldHVybiAtMTsKICAgICAgfQogICAgICBjb25zdCB7IHN0YXRzIH0gPSBpbmRleERhdGEuaW5kaWNlc1tyZWZJZF07CiAgICAgIGlmIChzdGF0cykgewogICAgICAgIHJldHVybiBzdGF0cy5saW5lQ291bnQ7CiAgICAgIH0KICAgICAgcmV0dXJuIC0xOwogICAgfQogICAgYXN5bmMgaW5kZXhDb3YoKSB7CiAgICAgIHJldHVybiBbXTsKICAgIH0KICAgIHBhcnNlQXV4RGF0YShieXRlcywgb2Zmc2V0LCBhdXhMZW5ndGgpIHsKICAgICAgaWYgKGF1eExlbmd0aC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aSArPSAxKSB7CiAgICAgICAgYXdhaXQgYWJvcnRCcmVha1BvaW50KG9wdHMuc2lnbmFsKTsKICAgICAgICBjb25zdCBiaW5Db3VudCA9IGJ5dGVzLnJlYWRJbnQzMkxFKGN1cnJPZmZzZXQpOwogICAgICAgIGN1cnJPZmZzZXQgKz0gNDsKICAgICAgICBjb25zdCBiaW5JbmRleCA9IHt9OwogICAgICAgIGxldCBzdGF0czsKICAgICAgICBmb3IgKGxldCBqID0gMDsgaiA8IGJpbkNvdW50OyBqICs9IDEpIHsKICAgICAgICAgIGNvbnN0IGJpbiA9IGJ5dGVzLnJlYWRVSW50MzJMRShjdXJyT2Zmc2V0KTsKICAgICAgICAgIGlmIChiaW4gPiB0aGlzLm1heEJpbk51bWJlcikgewogICAgICAgICAgICBzdGF0cyA9IHRoaXMucGFyc2VQc2V1ZG9CaW4oYnl0ZXMsIGN1cnJPZmZzZXQgKyA0KTsKICAgICAgICAgICAgY3Vyck9mZnNldCArPSA0ICsgOCArIDQgKyAxNiArIDE2OwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgY29uc3QgbG9mZnNldCA9IGZyb21CeXRlcyhieXRlcywgY3Vyck9mZnNldCArIDQpOwogICAgICAgICAgICB0aGlzLl9maW5kRmlyc3REYXRhKGRhdGEsIGxvZmZzZXQpOwogICAgICAgICAgICBjb25zdCBjaHVua0NvdW50ID0gYnl0ZXMucmVhZEludDMyTEUoY3Vyck9mZnNldCArIDEyKTsKICAgICAgICAgICAgY3Vyck9mZnNldCArPSAxNjsKICAgICAgICAgICAgY29uc3QgY2h1bmtzID0gbmV3IEFycmF5KGNodW5rQ291bnQpOwogICAgICAgICAgICBmb3IgKGxldCBrID0gMDsgayA8IGNodW5rQ291bnQ7IGsgKz0gMSkgewogICAgICAgICAgICAgIGNvbnN0IHUgPSBmcm9tQnl0ZXMoYnl0ZXMsIGN1cnJPZmZzZXQpOwogICAgICAgICAgICAgIGNvbnN0IHYgPSBmcm9tQnl0ZXMoYn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Y29uc3QgW3N0YXJ0LCBlbmRdIG9mIG92ZXJsYXBwaW5nQmlucykgewogICAgICAgIGZvciAobGV0IGJpbiA9IHN0YXJ0OyBiaW4gPD0gZW5kOyBiaW4rKykgewogICAgICAgICAgaWYgKGJhLmJpbkluZGV4W2Jpbl0pIHsKICAgICAgICAgICAgY29uc3QgYmluQ2h1bmtzID0gYmEuYmluSW5kZXhbYmluXTsKICAgICAgICAgICAgZm9yIChsZXQgYyA9IDA7IGMgPCBiaW5DaHVua3MubGVuZ3RoOyArK2MpIHsKICAgICAgICAgICAgICBjaHVua3MucHVzaChuZXcgQ2h1bmsoYmluQ2h1bmtzW2NdLm1pbnYsIGJpbkNodW5rc1tjXS5tYXh2LCBiaW4pKTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgICByZXR1cm4gb3B0aW1pemVDaHVua3MoY2h1bmtzLCBuZXcgVmlydHVhbE9mZnNldCgwLCAwKSk7CiAgICB9CiAgICByZWcyYmlucyhiZWcsIGVuZCkgewogICAgICBiZWcgLT0gMTsKICAgICAgaWYgKGJlZyA8IDEpIHsKICAgICAgICBiZWcgPSAxOwogICAgICB9CiAgICAgIGlmIChlbmQgPiAyICoqIDUwKSB7CiAgICAgICAgZW5kID0gMiAqKiAzNDsKICAgICAgfQogICAgICBlbmQgLT0gMTsKICAgICAgbGV0IGwgPSAwOwogICAgICBsZXQgdCA9IDA7CiAgICAgIGxldCBzID0gdGhpcy5taW5TaGlmdCArIHRoaXMuZGVwdGggKiAzOwogICAgICBjb25zdCBiaW5zID0gW107CiAgICAgIGZvciAoOyBsIDw9IHRoaXMuZGVwdGg7IHMgLT0gMywgdCArPSBsc2hpZnQoMSwgbCAqIDMpLCBsICs9IDEpIHsKICAgICAgICBjb25zdCBiID0gdCArIHJzaGlmdChiZWcsIHMpOwogICAgICAgIGNvbnN0IGUgPSB0ICsgcnNoaWZ0KGVuZCwgcyk7CiAgICAgICAgaWYgKGUgLSBiICsgYml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CA9IGJ5dGVBcnJheS5yZWFkSW50MzJMRShzdGFydCArIDQpOwogICAgICB0aGlzLmRhdGEuc3RhcnQgPSBieXRlQXJyYXkucmVhZEludDMyTEUoc3RhcnQgKyA4KTsKICAgICAgdGhpcy5mbGFncyA9IChieXRlQXJyYXkucmVhZEludDMyTEUoc3RhcnQgKyAxNikgJiA0Mjk0OTAxNzYwKSA+PiAxNjsKICAgIH0KICAgIGdldChmaWVsZCkgewogICAgICBpZiAodGhpc1tmaWVsZF0pIHsKICAgICAgICBpZiAodGhpcy5kYXRhW2ZpZWxkXSkgewogICAgICAgICAgcmV0dXJuIHRoaXMuZGF0YVtmaWVsZF07CiAgICAgICAgfQogICAgICAgIHRoaXMuZGF0YVtmaWVsZF0gPSB0aGlzW2ZpZWxkXSgpOwogICAgICAgIHJldHVybiB0aGlzLmRhdGFbZmllbGRdOwogICAgICB9CiAgICAgIHJldHVybiB0aGlzLl9nZXQoZmllbGQudG9Mb3dlckNhc2UoKSk7CiAgICB9CiAgICBlbmQoKSB7CiAgICAgIHJldHVybiB0aGlzLmdldCgic3RhcnQiKSArIHRoaXMuZ2V0KCJsZW5ndGhfb25fcmVmIik7CiAgICB9CiAgICBzZXFfaWQoKSB7CiAgICAgIHJldHVybiB0aGlzLl9yZWZJRDsKICAgIH0KICAgIF9nZXQoZmllbGQpIHsKICAgICAgaWYgKGZpZWxkIGluIHRoaXMuZGF0YSkgewogICAgICAgIHJldHVybiB0aGlzLmRhdGFbZmllbGRdOwogICAgICB9CiAgICAgIHRoaXMuZGF0YVtmaWVsZF0gPSB0aGlzLl9wYXJzZVRhZyhmaWVsZCk7CiAgICAgIHJldHVybiB0aGlzLmRhdGFbZmllbGRdOwogICAgfQogICAgX3RhZ3MoKSB7CiAgICAgIHRoaXMuX3BhcnNlQWxsVGFncygpOwogICAgICBsZXQgdGFncyA9IFsic2VxIl07CiAgICAgIGlmICghdGhpcy5pc1NlZ21lbnRVbm1hcHBlZCgpKSB7CiAgICAgICAgdGFnc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BcnJheVtwICsgMl0pOwogICAgICAgIHAgKz0gMzsKICAgICAgICBsZXQgdmFsdWU7CiAgICAgICAgc3dpdGNoICh0eXBlKSB7CiAgICAgICAgICBjYXNlICJBIjoKICAgICAgICAgICAgdmFsdWUgPSBTdHJpbmcuZnJvbUNoYXJDb2RlKGJ5dGVBcnJheVtwXSk7CiAgICAgICAgICAgIHAgKz0gMTsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICBjYXNlICJpIjoKICAgICAgICAgICAgdmFsdWUgPSBieXRlQXJyYXkucmVhZEludDMyTEUocCk7CiAgICAgICAgICAgIHAgKz0gNDsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICBjYXNlICJJIjoKICAgICAgICAgICAgdmFsdWUgPSBieXRlQXJyYXkucmVhZFVJbnQzMkxFKHApOwogICAgICAgICAgICBwICs9IDQ7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgY2FzZSAiYyI6CiAgICAgICAgICAgIHZhbHVlID0gYnl0ZUFycmF5LnJlYWRJbnQ4KHApOwogICAgICAgICAgICBwICs9IDE7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgY2FzZSAiQyI6CiAgICAgICAgICAgIHZhbHVlID0gYnl0ZUFycmF5LnJlYWRVSW50OChwKTsKICAgICAgICAgICAgcCArPSAxOwogICAgICAgICAgICBicmVhazsKICAgICAgICAgIGNhc2UgInMiOgogICAgICAgICAgICB2YWx1ZSA9IGJ5dGVBcnJheS5yZWFkSW50MTZMRShwKTsKICAgICAgICAgICAgcCArPSAyOwogICAgICAgICAgICBicmVhazsKICAgICAgICAgIGNhc2UgIlMiOgogICAgICAgICAgICB2YWx1ZSA9IGJ5dGVBcnJheS5yZWFkVUludDE2TEUocCk7CiAgICAgICAgICAgIHAgKz0gMjsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICBjYXNlICJmIjoKICAgICAgICAgICAgdmFsdWUgPSBieXRlQXJyYXkucmVhZEZsb2F0TEUocCk7CiAgICAgICAgICAgIHAgKz0gNDsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICBjYXNlICJaIjoKICAgICAgICAgIGNhc2UgIkgiOgogICAgICAgICAgICB2YWx1ZSA9ICIiOwogICAgICAgICAgICB3aGlsZSAocCA8PSBibG9ja0VuZCkgewogICAgICAgICAgICAgIGNvbnN0IGNjID0gYnl0ZUFycmF5W3ArK107CiAgICAgICAgICAgICAgaWYgKGNjID09PSAwKSB7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgdmFsdWUgKz0gU3RyaW5nLmZyb21DaGFyQ29kZShjYyk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgY2FzZSAiQiI6IHsKICAgICAgICAgICAgdmFsdWUgPSAiIjsKICAgICAgICAgICAgY29uc3QgY2MgPSBieXRlQXJyYXlbcCsrXTsKICAgICAgICAgICAgY29uc3QgQnR5cGUgPSBTdHJpbmcuZnJvbUNoYXJDb2RlKGNjKTsKICAgICAgICAgICAgY29uc3QgbGltaXQgPSBieXRlQXJyYXkucmVhZEludDMyTEUocCk7CiAgICAgICAgICAgIHAgKz0gNDsKICAgICAgICAgICAgaWYgKEJ0eXBlID09PSAiaSIpIHsKICAgICAgICAgICAgICBpZiAodGFnID09PSAiQ0ciKSB7CiAgICAgICAgICAgICAgICBmb3IgKGxldCBrID0gMDsgayA8IGxpbWl0OyBrKyspIHsKICAgICAgICAgICAgICAgICAgY29uc3QgY2lnb3AgPSBieXRlQXJyYXkucmVhZEludDMyTEUocCk7CiAgICAgICAgICAgICAgICAgIGNvbnN0IGxvcCA9IGNpZ29wID4+IDQ7CiAgICAgICAgICAgICAgICAgIGNvbnN0IG9wID0gQ0lHQVJfREVDT0RFUltjaWdvcCAmIDE1XTsKICAgICAgICAgICAgICAgICAgdmFsdWUgKz0gbG9wICsgb3A7CiAgICAgICAgICAgICAgICAgIHAgKz0gNDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgZm9yIChsZXQgayA9IDA7IGsgPCBsaW1pdDsgaysrKSB7CiAgICAgICAgICAgICAgICAgIHZhbHVlICs9IGJ5dGVBcnJheS5yZWFkSW50MzJMRShwKTsKICAgICAgICAgICAgICAgICAgaWYgKGsgKyAxIDwgbGltaXQpIHsKICAgICAgICAgICAgICAgICAgICB2YWx1ZSArPSAiLCI7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgcCArPSA0OwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoQnR5cGUgPT09ICJJIikgewogICAgICAgICAgICAgIGlmICh0YWcgPT09ICJDRyIpIHsKICAgICAgICAgICAgICAgIGZvciAobGV0IGsgPSAwOyBrIDwgbGltaXQ7IGsrKykgewogICAgICAgICAgICAgICAgICBjb25zdCBjaWdvcCA9IGJ5dGVBcnJheS5yZWFkVUludDMyTEUocCk7CiAgICAgICAgICAgICAgICAgIGNvbnN0IGxvcCA9IGNpZ29wID4+IDQ7CiAgICAgICAgICAgICAgICAgIGNvbnN0IG9wID0gQ0lHQVJfREVDT0RFUltjaWdvcCAmIDE1XTsKICAgICAgICAgICAgICAgICAgdmFsdWUgKz0gbG9wICsgb3A7CiAgICAgICAgICAgICAgICAgIHAgKz0gNDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgZm9yIChsZXQgayA9IDA7IGsgPCBsaW1pdDsgaysrKSB7CiAgICAgICAgICAgICAgICAgIHZhbHVlICs9IGJ5dGVBcnJheS5yZWFkVUludDMyTEUocCk7CiAgICAgICAgICAgICAgICAgIGlmIChrICsgMSA8IGxpbWl0KSB7CiAgICAgICAgICAgICAgICAgICAgdmFsdWUgKz0gIiwiOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIHAgKz0gNDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKEJ0eXBlID09PSAicyIpIHsKICAgICAgICAgICAgICBmb3IgKGxldCBrID0gMDsgayA8IGxpbWl0OyBrKyspIHsKICAgICAgICAgICAgICAgIHZhbHVlICs9IGJ5dGVBcnJheS5yZWFkSW50MTZMRShwKTsKICAgICAgICAgICAgICAgIGlmIChrICsgMSA8IGxpbWl0KSB7CiAgICAgICAgICAgICAgICAgIHZhbHVlICs9ICIsIjsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHAgKz0gMjsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKEJ0eXBlID09PSAiUyIpIHsKICAgICAgICAgICAgICBmb3IgKGxldCBrID0gMDsgayA8IGxpbWl0OyBrKyspIHsKICAgICAgICAgICAgICAgIHZhbHVlICs9IGJ5dGVBcnJheS5yZWFkVUludDE2TEUocCk7CiAgICAgICAgICAgICAgICBpZiAoayArIDEgPCBsaW1pdCkgewogICAgICAgICAgICAgICAgICB2YWx1ZSArPSAiLCI7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBwICs9IDI7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChCdHlwZSA9PT0gImMiKSB7CiAgICAgICAgICAgICAgZm9yIChsZXQgayA9IDA7IGsgPCBsaW1pdDsgaysrKSB7CiAgICAgICAgICAgICAgICB2YWx1ZSArPSBieXRlQXJyYXkucmVhZEludDgocCk7CiAgICAgICAgICAgICAgICBpZiAoayArIDEgPCBsaW1pdCkgewogICAgICAgICAgICAgICAgICB2YWx1ZSArPSAiLCI7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBwICs9IDE7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChCdHlwZSA9PT0gIkMiKSB7CiAgICAgICAgICAgICAgZm9yIChsZXQgayA9IDA7IGsgPCBsaW1pdDsgaysrKSB7CiAgICAgICAgICAgICAgICB2YWx1ZSArPSBieXRlQXJyYXkucmVhZFVJbnQ4KHApOwogICAgICAgICAgICAgICAgaWYgKGsgKyAxIDwgbGltaXQpIHsKICAgICAgICAgICAgICAgICAgdmFsdWUgKz0gIiwiOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgcCArPSAxOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoQnR5cGUgPT09ICJmIikgewogICAgICAgICAgICAgIGZvciAobGV0IGsgPSAwOyBrIDwgbGltaXQ7IGsrKykgewogICAgICAgICAgICAgICAgdmFsdWUgKz0gYnl0ZUFycmF5LnJlYWRGbG9hdExFKHApOwogICAgICAgICAgICAgICAgaWYgKGsgKyAxIDwgbGltaXQpIHsKICAgICAgICAgICAgICAgICAgdmFsdWUgKz0gIiwiOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgcCArPSA0OwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBicmVhazsKICAgICAgICAgIH0KICAgICAgICAgIGRlZmF1bHQ6CiAgICAgICAgICAgIGNvbnNvbGUud2FybihgVW5rbm93biBCQU0gdGFnIHR5cGUgJyR7dHlwZX0nLCB0YWdzIG1heSBiZSBpbmNvbXBsZXRlYCk7CiAgICAgICAgICAgIHZhbHVlID0gdm9pZCAwOwogICAgICAgICAgICBwID0gYmxvY2tFbmQ7CiAgICAgICAgfQogICAgICAgIHRoaXMuX3RhZ09mZnNldCA9IHA7CiAgICAgICAgdGhpcy5fdGFnTGlzdC5wdXNoKHRhZyk7CiAgICAgICAgaWYgKGxjVGFnID09PSB0YWdOYW1lKSB7CiAgICAgICAgICByZXR1cm4gdmFsdWU7CiAgICAgICAgfQogICAgICAgIHRoaXMuZGF0YVtsY1RhZ10gPSB2YWx1ZTsKICAgICAgfQogICAgICB0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MDsKICAgICAgbGV0IGNpZ29wID0gYnl0ZUFycmF5LnJlYWRJbnQzMkxFKHApOwogICAgICBsZXQgbG9wID0gY2lnb3AgPj4gNDsKICAgICAgbGV0IG9wID0gQ0lHQVJfREVDT0RFUltjaWdvcCAmIDE1XTsKICAgICAgaWYgKG9wID09PSAiUyIgJiYgbG9wID09PSBzZXFMZW4pIHsKICAgICAgICBwICs9IDQ7CiAgICAgICAgY2lnb3AgPSBieXRlQXJyYXkucmVhZEludDMyTEUocCk7CiAgICAgICAgbG9wID0gY2lnb3AgPj4gNDsKICAgICAgICBvcCA9IENJR0FSX0RFQ09ERVJbY2lnb3AgJiAxNV07CiAgICAgICAgaWYgKG9wICE9PSAiTiIpIHsKICAgICAgICAgIGNvbnNvbGUud2FybigiQ0cgdGFnIHdpdGggbm8gTiB0YWciKTsKICAgICAgICB9CiAgICAgICAgdGhpcy5kYXRhLmxlbmd0aF9vbl9yZWYgPSBsb3A7CiAgICAgICAgcmV0dXJuIHRoaXMuZ2V0KCJDRyIpOwogICAgICB9IGVsc2UgewogICAgICAgIGZvciAobGV0IGMgPSAwOyBjIDwgbnVtQ2lnYXJPcHM7ICsrYykgewogICAgICAgICAgY2lnb3AgPSBieXRlQXJyYXkucmVhZEludDMyTEUocCk7CiAgICAgICAgICBsb3AgPSBjaWdvcCA+PiA0OwogICAgICAgICAgb3AgPSBDSUdBUl9ERUNPREVSW2NpZ29wICYgMTVdOwogICAgICAgICAgY2lnYXIgKz0gbG9wICsgb3A7CiAgICAgICAgICBpZiAob3AgIT09ICJIIiAmJiBvcCAhPT0gIlMiICYmIG9wICE9PSAiSSIpIHsKICAgICAgICAgICAgbHJlZiArPSBsb3A7CiAgICAgICAgICB9CiAgICAgICAgICBwICs9IDQ7CiAgICAgICAgfQogICAgICAgIHRoaXMuZGF0YS5sZW5ndGhfb25fcmVmID0gbHJlZjsKICAgICAgICByZXR1cm4gY2lnYXI7CiAgICAgIH0KICAgIH0KICAgIF9mbGFncygpIHsKICAg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RFQ09ERVJbKHNiICYgMjQwKSA+PiA0XTsKICAgICAgICBpKys7CiAgICAgICAgaWYgKGkgPCBsZW4pIHsKICAgICAgICAgIGJ1ZiArPSBTRVFSRVRfREVDT0RFUltzYiAmIDE1XTsKICAgICAgICAgIGkrKzsKICAgICAgICB9CiAgICAgIH0KICAgICAgcmV0dXJuIGJ1ZjsKICAgIH0KICAgIGdldFBhaXJPcmllbnRhdGlvbigpIHsKICAgICAgaWYgKCF0aGlzLmlzU2VnbWVudFVubWFwcGVkKCkgJiYgIXRoaXMuaXNNYXRlVW5tYXBwZWQoKSAmJiB0aGlzLl9yZWZJRCA9PT0gdGhpcy5fbmV4dF9yZWZpZCgpKSB7CiAgICAgICAgY29uc3QgczEgPSB0aGlzLmlzUmV2ZXJzZUNvbXBsZW1lbnRlZCgpID8gIlIiIDogIkYiOwogICAgICAgIGNvbnN0IHMyID0gdGhpcy5pc01hdGVSZXZlcnNlQ29tcGxlbWVudGVkKCkgPyAiUiIgOiAiRiI7CiAgICAgICAgbGV0IG8xID0gIiAiOwogICAgICAgIGxldCBvMiA9ICIgIjsKICAgICAgICBpZiAodGhpcy5pc1JlYWQxKCkpIHsKICAgICAgICAgIG8xID0gIjEiOwogICAgICAgICAgbzIgPSAiMiI7CiAgICAgICAgfSBlbHNlIGlmICh0aGlzLmlzUmVhZDIoKSkgewogICAgICAgICAgbzEgPSAiMiI7CiAgICAgICAgICBvMiA9ICIxIjsKICAgICAgICB9CiAgICAgICAgY29uc3QgdG1wID0gW107CiAgICAgICAgY29uc3QgaXNpemUgPSB0aGlzLnRlbXBsYXRlX2xlbmd0aCgpOwogICAgICAgIGlmIChpc2l6ZSA+IDApIHsKICAgICAgICAgIHRtcFswXSA9IHMxOwogICAgICAgICAgdG1wWzFdID0gbzE7CiAgICAgICAgICB0bXBbMl0gPSBzMjsKICAgICAgICAgIHRtcFszXSA9IG8yOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICB0bXBbMl0gPSBzMTsKICAgICA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gICAgICAgICAgaWYgKGZlYXR1cmUuZ2V0KCJzdGFydCIpID49IG1heCkgewogICAgICAgICAgICAgIGRvbmUgPSB0cnVlOwogICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICB9IGVsc2UgaWYgKGZlYXR1cmUuZ2V0KCJlbmQiKSA+PSBtaW4pIHsKICAgICAgICAgICAgICByZWNzLnB1c2goZmVhdHVyZSk7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZmVhdHMucHVzaChyZWNzKTsKICAgICAgICB5aWVsZCByZWNzOwogICAgICAgIGlmIChkb25lKSB7CiAgICAgICAgICBicmVhazsKICAgICAgICB9CiAgICAgIH0KICAgICAgY2hlY2tBYm9ydFNpZ25hbChvcHRzLnNpZ25hbCk7CiAgICAgIGlmICh2aWV3QXNQYWlycykgewogICAgICAgIHlpZWxkIHRoaXMuZmV0Y2hQYWlycyhjaHJJZCwgZmVhdHMsIG9wdHMpOwogICAgICB9CiAgICB9CiAgICBhc3luYyBmZXRjaFBhaXJzKGNocklkLCBmZWF0cywgb3B0cykgewogICAgICBjb25zdCB7IHBhaXJBY3Jvc3NDaHIgPSBmYWxzZSwgbWF4SW5zZXJ0U2l6ZSA9IDJlNSB9ID0gb3B0czsKICAgICAgY29uc3QgdW5tYXRlZFBhaXJzID0ge307CiAgICAgIGNvbnN0IHJlYWRJZHMgPSB7fTsKICAgICAgZmVhdHMubWFwKChyZXQpID0+IHsKICAgICAgICBjb25zdCByZWFkTmFtZXMgPSB7fTsKICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IHJldC5sZW5ndGg7IGkrKykgewogICAgICAgICAgY29uc3QgbmFtZSA9IHJldFtpXS5uYW1lKCk7CiAgICAgICAgICBjb25zdCBpZCA9IHJldFtpXS5pZCgpOwogICAgICAgICAgaWYgKCFyZWFkTmFtZXNbbmFtZV0pIHsKICAgICAgICAgICAgcmVhZE5hbWVzW25hbWVdID0gMDsKICAgICAgICAgIH0KICAgICAgICAgIHJlYWROYW1lc1tuYW1lXSsrOwogICAgICAgICAgcmVhZElkc1tpZF0gPSAxOwogICAgICAgIH0KICAgICAgICAoMCwgaW1wb3J0X29iamVjdC5kZWZhdWx0KShyZWFkTmFtZXMpLmZvckVhY2goKFtrLCB2XSkgPT4gewogICAgICAgICAgaWYgKHYgPT09IDEpIHsKICAgICAgICAgICAgdW5tYXRlZFBhaXJzW2tdID0gdHJ1ZTsKICAgICAgICAgIH0KICAgICAgICB9KTsKICAgICAgfSk7CiAgICAgIGNvbnN0IG1hdGVQcm9taXNlcyA9IFtdOwogICAgICBmZWF0cy5tYXAoKHJldCkgPT4gewogICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgcmV0Lmxlbmd0aDsgaSsrKSB7CiAgICAgICAgICBjb25zdCBmID0gcmV0W2ldOwogICAgICAgICAgY29uc3QgbmFtZSA9IGYubmFtZSgpOwogICAgICAgICAgY29uc3Qgc3RhcnQgPSBmLmdldCgic3RhcnQiKTsKICAgICAgICAgIGNvbnN0IHBuZXh0ID0gZi5fbmV4dF9wb3MoKTsKICAgICAgICAgIGNvbnN0IHJuZXh0ID0gZi5fbmV4dF9yZWZpZCgpOwogICAgICAgICAgaWYgKHVubWF0ZWRQYWlyc1tuYW1lXSAmJiAocGFpckFjcm9zc0NociB8fCBybmV4dCA9PT0gY2hySWQgJiYgTWF0aC5hYnMoc3RhcnQgLSBwbmV4dCkgPCBtYXhJbnNlcnRTaXplKSkgewogICAgICAgICAgICBtYXRlUHJvbWlzZXMucHVzaCh0aGlzLmluZGV4LmJsb2Nrc0ZvclJhbmdlKHJuZXh0LCBwbmV4dCwgcG5leHQgKyAxLCBvcHRzKSk7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9KTsKICAgICAgY29uc3QgbWF0ZUNodW5rcyA9IGZsYXQoYXdhaXQgUHJvbWlzZS5hbGwobWF0ZVByb21pc2VzKSkuc29ydCgpLmZpbHRlcigoaXRlbSwgcG9zLCBhcnkpID0+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nQpOwogICAgICAgIGNvbnN0IGJsb2NrRW5kID0gYmxvY2tTdGFydCArIDQgKyBibG9ja1NpemUgLSAxOwogICAgICAgIGlmIChkcG9zaXRpb25zKSB7CiAgICAgICAgICB3aGlsZSAoYmxvY2tTdGFydCArIGNodW5rLm1pbnYuZGF0YVBvc2l0aW9uID49IGRwb3NpdGlvbnNbcG9zKytdKSB7CiAgICAgICAgICB9CiAgICAgICAgICBwb3MtLTsKICAgICAgICB9CiAgICAgICAgaWYgKGJsb2NrRW5kIDwgYmEubGVuZ3RoKSB7CiAgICAgICAgICBjb25zdCBmZWF0dXJlID0gbmV3IEJhbVJlY29yZCh7CiAgICAgICAgICAgIGJ5dGVzOiB7CiAgICAgICAgICAgICAgYnl0ZUFycmF5OiBiYSwKICAgICAgICAgICAgICBzdGFydDogYmxvY2tTdGFydCwKICAgICAgICAgICAgICBlbmQ6IGJsb2NrRW5kCiAgICAgICAgICAgIH0sCiAgICAgICAgICAgIGZpbGVPZmZzZXQ6IGNwb3NpdGlvbnMgPyBjcG9zaXRpb25zW3Bvc10gKiAoMSA8PCA4KSArIChibG9ja1N0YXJ0IC0gZHBvc2l0aW9uc1twb3NdKSArIGNodW5rLm1pbnYuZGF0YVBvc2l0aW9uICsgMSA6IGltcG9ydF9idWZmZXJfY3JjMzIuZGVmYXVsdC5zaWduZWQoYmEuc2xpY2UoYmxvY2tTdGFydCwgYmxvY2tFbmQpKQogICAgICAgICAgfSk7CiAgICAgICAgICBzaW5rLnB1c2goZmVhdHVyZSk7CiAgICAgICAgICBpZiAodGhpcy55aWVsZFRocmVhZFRpbWUgJiYgK0RhdGUubm93KCkgLSBsYXN0ID4gdGhpcy55aWVsZFRocmVhZFRpbWUpIHsKICAgICAgICAgICAgYXdhaXQgdGltZW91dCgxKTsKICAgICAgICAgICAgbGFzdCA9ICtEYXRlLm5vdygpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBibG9ja1N0YXJ0ID0gYmxvY2tFbmQgKyAxOwogICA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c2V0KGtleSwgdmFsdWUpIHsKICAgICAgdGhpcy5jYWNoZS5zZXQoa2V5LCB2YWx1ZSk7CiAgICAgIHRoaXMuX3NpemUrKzsKICAgICAgaWYgKHRoaXMuX3NpemUgPj0gdGhpcy5tYXhTaXplKSB7CiAgICAgICAgdGhpcy5fc2l6ZSA9IDA7CiAgICAgICAgdGhpcy5fZW1pdEV2aWN0aW9ucyh0aGlzLm9sZENhY2hlKTsKICAgICAgICB0aGlzLm9sZENhY2hlID0gdGhpcy5jYWNoZTsKICAgICAgICB0aGlzLmNhY2hlID0gbmV3IE1hcCgpOwogICAgICB9CiAgICB9CiAgICBfbW92ZVRvUmVjZW50KGtleSwgaXRlbSkgewogICAgICB0aGlzLm9sZENhY2hlLmRlbGV0ZShrZXkpOwogICAgICB0aGlzLl9zZXQoa2V5LCBpdGVtKTsKICAgIH0KICAgICpfZW50cmllc0FzY2VuZGluZygpIHsKICAgICAgZm9yIChjb25zdCBpdGVtIG9mIHRoaXMub2xkQ2FjaGUpIHsKICAgICAgICBjb25zdCBba2V5LCB2YWx1ZV0gPSBpdGVtOwogICAgICAgIGlmICghdGhpcy5jYWNoZS5oYXMoa2V5KSkgewogICAgICAgICAgY29uc3QgZGVsZXRlZCA9IHRoaXMuX2RlbGV0ZUlmRXhwaXJlZChrZXksIHZhbHVlKTsKICAgICAgICAgIGlmIChkZWxldGVkID09PSBmYWxzZSkgewogICAgICAgICAgICB5aWVsZCBpdGVtOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgICBmb3IgKGNvbnN0IGl0ZW0gb2YgdGhpcy5jYWNoZSkgewogICAgICAgIGNvbnN0IFtrZXksIHZhbHVlXSA9IGl0ZW07CiAgICAgICAgY29uc3QgZGVsZXRlZCA9IHRoaXMuX2RlbGV0ZUlmRXhwaXJlZChrZXksIHZhbHVlKTsKICAgICAgICBpZiAoZGVsZXRlZCA9PT0gZmFsc2UpIHsKICAgICAgICAgIHlpZWxkIGl0ZW07CiAgICAgICAg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mRXhwaXJlZChrZXksIHRoaXMuY2FjaGUuZ2V0KGtleSkpOwogICAgICB9CiAgICAgIGlmICh0aGlzLm9sZENhY2hlLmhhcyhrZXkpKSB7CiAgICAgICAgcmV0dXJuICF0aGlzLl9kZWxldGVJZkV4cGlyZWQoa2V5LCB0aGlzLm9sZENhY2hlLmdldChrZXkpKTsKICAgICAgfQogICAgICByZXR1cm4gZmFsc2U7CiAgICB9CiAgICBwZWVrKGtleSkgewogICAgICBpZiAodGhpcy5jYWNoZS5oYXMoa2V5KSkgewogICAgICAgIHJldHVybiB0aGlzLl9wZWVrKGtleSwgdGhpcy5jYWNoZSk7CiAgICAgIH0KICAgICAgaWYgKHRoaXMub2xkQ2FjaGUuaGFzKGtleSkpIHsKICAgICAgICByZXR1cm4gdGhpcy5fcGVlayhrZXksIHRoaXMub2xkQ2FjaGUpOwogICAgICB9CiAgICB9CiAgICBkZWxldGUoa2V5KSB7CiAgICAgIGNvbnN0IGRlbGV0ZWQgPSB0aGlzLmNhY2hlLmRlbGV0ZShrZXkpOwogICAgICBpZiAoZGVsZXRlZCkgewogICAgICAgIHRoaXMuX3NpemUtLTsKICAgICAgfQogICAgICByZXR1cm4gdGhpcy5vbGRDYWNoZS5kZWxldGUoa2V5KSB8fCBkZWxldGVkOwogICAgfQogICAgY2xlYXIoKSB7CiAgICAgIHRoaXMuY2FjaGUuY2xlYXIoKTsKICAgICAgdGhpcy5vbGRDYWNoZS5jbGVhcigpOwogICAgICB0aGlzLl9zaXplID0gMDsKICAgIH0KICAgIHJlc2l6ZShuZXdTaXplKSB7CiAgICAgIGlmICghKG5ld1NpemUgJiYgbmV3U2l6ZSA+IDApKSB7CiAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcigiYG1heFNpemVgIG11c3QgYmUgYSBudW1iZXIgZ3JlYXRlciB0aGFuIDAiKTsKICAgICAgfQogICAgICBjb25zdCBpdGVtcyA9IFsuLi50aGlzLl9lbnRyaWVzQXNjZW5kaW5nKCldOwogICAg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ICAgICAgaWYgKGhpID09IG51bGwpCiAgICAgICAgaGkgPSBhLmxlbmd0aDsKICAgICAgd2hpbGUgKGxvIDwgaGkpIHsKICAgICAgICBjb25zdCBtaWQgPSBsbyArIGhpID4+PiAxOwogICAgICAgIGlmIChjb21wYXJlKGFbbWlkXSwgeCkgPCAwKQogICAgICAgICAgbG8gPSBtaWQgKyAxOwogICAgICAgIGVsc2UKICAgICAgICAgIGhpID0gbWlkOwogICAgICB9CiAgICAgIHJldHVybiBsbzsKICAgIH0KICAgIGZ1bmN0aW9uIHJpZ2h0KGEsIHgsIGxvLCBoaSkgewogICAgICBpZiAobG8gPT0gbnVsbCkKICAgICAgICBsbyA9IDA7CiAgICAgIGlmIChoaSA9PSBudWxsKQogICAgICAgIGhpID0gYS5sZW5ndGg7CiAgICAgIHdoaWxlIChsbyA8IGhpKSB7CiAgICAgICAgY29uc3QgbWlkID0gbG8gKyBoaSA+Pj4gMTsKICAgICAgICBpZiAoY29tcGFyZShhW21pZF0sIHgpID4gMCkKICAgICAgICAgIGhpID0gbWlkOwogICAgICAgIGVsc2UKICAgICAgICAgIGxvID0gbWlkICsgMTsKICAgICAgfQogICAgICByZXR1cm4gbG87CiAgICB9CiAgICBmdW5jdGlvbiBjZW50ZXIoYSwgeCwgbG8sIGhpKSB7CiAgICAgIGlmIChsbyA9PSBudWxsKQogICAgICAgIGxvID0gMDsKICAgICAgaWYgKGhpID09IG51bGwpCiAgICAgICAgaGkgPSBhLmxlbmd0aDsKICAgICAgY29uc3QgaSA9IGxlZnQoYSwgeCwgbG8sIGhpIC0gMSk7CiAgICAgIHJldHVybiBpID4gbG8gJiYgZGVsdGEoYVtpIC0gMV0sIHgpID4gLWRlbHRhKGFbaV0sIHgpID8gaSAtIDEgOiBpOwogICAgfQogICAgcmV0dXJuIHsgbGVmdCwgY2VudGVyLCByaWdodCB9OwogIH0KICBmdW5jdGlvbiBhc2NlbmRpbmdDb21wYXJhdG9yKGYpIHsKICAgIHJldHVybiAoZCwge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9bMC05XS9nKSkgewogICAgICAgIGN1cnJOdW0gPSBjdXJyTnVtICogMTAgKyArbWRTdHJpbmdbaV07CiAgICAgICAgZGVsZXRpb25FbmNvdW50ZXJlZCA9IGZhbHNlOwogICAgICB9IGVsc2UgaWYgKG1kU3RyaW5nW2ldID09PSAiXiIpIHsKICAgICAgICBkZWxldGlvbkVuY291bnRlcmVkID0gdHJ1ZTsKICAgICAgfSBlbHNlIHsKICAgICAgICBjdXJyUG9zICs9IGN1cnJOdW07CiAgICAgICAgaWYgKHVzZUNvdW50cykgewogICAgICAgICAgc3Vic3RpdHV0aW9ucy5wdXNoKHsKICAgICAgICAgICAgbGVuZ3RoOiBjdXJyTnVtLAogICAgICAgICAgICB0eXBlOiBtZFN0cmluZ1tpXQogICAgICAgICAgfSk7CiAgICAgICAgfSBlbHNlIGlmIChkZWxldGlvbkVuY291bnRlcmVkKSB7CiAgICAgICAgICBiYW1TZXFTaGlmdCAtPSAxOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBzdWJzdGl0dXRpb25zLnB1c2goewogICAgICAgICAgICBwb3M6IGN1cnJQb3MsCiAgICAgICAgICAgIGJhc2U6IG1kU3RyaW5nW2ldLAogICAgICAgICAgICBsZW5ndGg6IDEsCiAgICAgICAgICAgIGJhbVNlcVNoaWZ0CiAgICAgICAgICB9KTsKICAgICAgICB9CiAgICAgICAgY3Vyck51bSA9IDA7CiAgICAgICAgY3VyclBvcyArPSAxOwogICAgICB9CiAgICB9CiAgICByZXR1cm4gc3Vic3RpdHV0aW9uczsKICB9CiAgZnVuY3Rpb24gZ2V0U3Vic3RpdHV0aW9ucyhzZWdtZW50LCBzZXEpIHsKICAgIGxldCBzdWJzdGl0dXRpb25zID0gW107CiAgICBsZXQgc29mdENsaXBwaW5nQXRSZWFkU3RhcnQgPSBudWxsOwogICAgaWYgKHNlZ21lbnQuY2lnYXIpIHsKICAgICAgY29uc3QgY2lnYXJTdWJzID0gcGFyc2VNRChzZWdtZW50LmNpZ2FyLCB0cnVlKTsKICAgICAgbGV0IGN1cnJQb3MgPSAwOwogICAgICBmb3IgKGNvbnN0IHN1YiBvZiBjaWdhclN1YnMpIHsKICAgICAgICBpZiAoc3ViLnR5cGUgPT09ICJYIikgewogICAgICAgICAgc3Vic3RpdHV0aW9ucy5wdXNoKHsKICAgICAgICAgICAgcG9zOiBjdXJyUG9zLAogICAgICAgICAgICBsZW5ndGg6IHN1Yi5sZW5ndGgsCiAgICAgICAgICAgIHR5cGU6ICJYIgogICAgICAgICAgfSk7CiAgICAgICAgICBjdXJyUG9zICs9IHN1Yi5sZW5ndGg7CiAgICAgICAgfSBlbHNlIGlmIChzdWIudHlwZSA9PT0gIkkiKSB7CiAgICAgICAgICBzdWJzdGl0dXRpb25zLnB1c2goewogICAgICAgICAgICBwb3M6IGN1cnJQb3MsCiAgICAgICAgICAgIGxlbmd0aDogc3ViLmxlbmd0aCwKICAgICAgICAgICAgdHlwZTogIkkiCiAgICAgICAgICB9KTsKICAgICAgICB9IGVsc2UgaWYgKHN1Yi50eXBlID09PSAiRCIpIHsKICAgICAgICAgIHN1YnN0aXR1dGlvbnMucHVzaCh7CiAgICAgICAgICAgIHBvczogY3VyclBvcywKICAgICAgICAgICAgbGVuZ3RoOiBzdWIubGVuZ3RoLAogICAgICAgICAgICB0eXBlOiAiRCIKICAgICAgICAgIH0pOwogICAgICAgICAgY3VyclBvcyArPSBzdWIubGVuZ3RoOwogICAgICAgIH0gZWxzZSBpZiAoc3ViLnR5cGUgPT09ICJOIikgewogICAgICAgICAgc3Vic3RpdHV0aW9ucy5wdXNoKHsKICAgICAgICAgICAgcG9zOiBjdXJyUG9zLAogICAgICAgICAgICBsZW5ndGg6IHN1Yi5sZW5ndGgsCiAgICAgICAgICAgIHR5cGU6ICJOIgogICAgICAgICAgfSk7CiAgICAgICAgICBjdXJyUG9zICs9IHN1Yi5sZW5ndGg7CiAgICAgICAgfSBlbHNlIGlmIChzdWIudHlwZSA9PT0gIj0iIHx8IHN1Yi50eXBlID09PSAiTSIpIHsKICAgICAgICAgIGN1cnJQb3MgKz0gc3ViLmxlbmd0aDsKICAgICAgICB9IGVsc2UgewogICAgICAgIH0KICAgICAgfQogICAgICBjb25zdCBmaXJzdFN1YiA9IGNpZ2FyU3Vic1swXTsKICAgICAgY29uc3QgbGFzdFN1YiA9IGNpZ2FyU3Vic1tjaWdhclN1YnMubGVuZ3RoIC0gMV07CiAgICAgIGlmIChmaXJzdFN1Yi50eXBlID09PSAiUyIpIHsKICAgICAgICBzb2Z0Q2xpcHBpbmdBdFJlYWRTdGFydCA9IGZpcnN0U3ViOwogICAgICAgIHN1YnN0aXR1dGlvbnMucHVzaCh7CiAgICAgICAgICBwb3M6IC1maXJzdFN1Yi5sZW5ndGgsCiAgICAgICAgICB0eXBlOiAiUyIsCiAgICAgICAgICBsZW5ndGg6IGZpcnN0U3ViLmxlbmd0aAogICAgICAgIH0pOwogICAgICB9CiAgICAgIGlmIChsYXN0U3ViLnR5cGUgPT09ICJTIikgewogICAgICAgIHN1YnN0aXR1dGlvbnMucHVzaCh7CiAgICAgICAgICBwb3M6IHNlZ21lbnQuZW5kIC0gc2VnbWVudC5zdGFydCwKICAgICAgICAgIGxlbmd0aDogbGFzdFN1Yi5sZW5ndGgsCiAgICAgICAgICB0eXBlOiAiUyIKICAgICAgICB9KTsKICAgICAgfQogICAgICBpZiAoZmlyc3RTdWIudHlwZSA9PT0gIkgiKSB7CiAgICAgICAgc3Vic3RpdHV0aW9ucy5wdXNoKHsKICAgICAgICAgIHBvczogLWZpcnN0U3ViLmxlbmd0aCwKICAgICAgICAgIHR5cGU6ICJIIiwKICAgICAgICAgIGxlbmd0aDogZmlyc3RTdWIubGVuZ3RoCiAgICAgICAgfSk7CiAgICAgIH0KICAgICAgaWYgKGxhc3RTdWIudHlwZSA9PT0gIkgiKSB7CiAgICAgICAgc3Vic3RpdHV0aW9ucy5wdXNoKHsKICAgICAgICAgIHBvczogc2VnbWVudC5lbmQgLSBzZWdtZW50LnN0YX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H0uJHt6fS4ke3h9YCwgdGlsZVZhbHVlcy5nZXQoYCR7dWlkfS4ke3p9LiR7eH1gKS5jb25jYXQobWFwcGVkUmVjb3JkcykpOwogICAgICAgICAgICByZXR1cm4gW107CiAgICAgICAgICB9KSk7CiAgICAgICAgICBicmVhazsKICAgICAgICB9CiAgICAgIH0KICAgIH0KICAgIHJldHVybiBQcm9taXNlLmFsbChyZWNvcmRQcm9taXNlcykudGhlbigodmFsdWVzKSA9PiB7CiAgICAgIHJldHVybiB2YWx1ZXMuZmxhdCgpOwogICAgfSk7CiAgfTsKICB2YXIgZmV0Y2hUaWxlc0RlYm91bmNlZCA9IGFzeW5jICh1aWQsIHRpbGVJZHMpID0+IHsKICAgIGNvbnN0IHRpbGVzID0ge307CiAgICBjb25zdCB2YWxpZFRpbGVJZHMgPSBbXTsKICAgIGNvbnN0IHRpbGVQcm9taXNlcyA9IFtdOwogICAgZm9yIChjb25zdCB0aWxlSWQgb2YgdGlsZUlkcykgewogICAgICBjb25zdCBwYXJ0cyA9IHRpbGVJZC5zcGxpdCgiLiIpOwogICAgICBjb25zdCB6ID0gcGFyc2VJbnQocGFydHNbMF0sIDEwKTsKICAgICAgY29uc3QgeCA9IHBhcnNlSW50KHBhcnRzWzFdLCAxMCk7CiAgICAgIGlmIChOdW1iZXIuaXNOYU4oeCkgfHwgTnVtYmVyLmlzTmFOKHopKSB7CiAgICAgICAgY29uc29sZS53YXJuKCJJbnZhbGlkIHRpbGUgem9vbSBvciBwb3NpdGlvbjoiLCB6LCB4KTsKICAgICAgICBjb250aW51ZTsKICAgICAgfQogICAgICB2YWxpZFRpbGVJZHMucHVzaCh0aWxlSWQpOwogICAgICB0aWxlUHJvbWlzZXMucHVzaCh0aWxlKHVpZCwgeiwgeCkpOwogICAgfQogICAgcmV0dXJuIFByb21pc2UuYWxsKHRpbGVQcm9taXNlcykudGhlbigodmFsdWVzKSA9PiB7CiAgICAgIHZhbHVlcy5mb3JFYWNoKChkLCBpKSA9PiB7CiA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uc3RhcnQpOwogICAgICAgIGNvbnN0IGluc2VydFNpemUgPSBNYXRoLm1heCgwLCArci5zdGFydCAtICtsLmVuZCk7CiAgICAgICAgY29uc3QgbGFyZ2VJbnNlcnRTaXplID0gaW5zZXJ0U2l6ZSA+PSBtYXhJbnNlcnRTaXplOwogICAgICAgIGxldCBzdlR5cGU7CiAgICAgICAgaWYgKCFsYXJnZUluc2VydFNpemUpIHsKICAgICAgICAgIHN2VHlwZSA9ICJub3JtYWwgcmVhZCI7CiAgICAgICAgfSBlbHNlIGlmIChsLnN0cmFuZCA9PT0gIisiICYmIHIuc3RyYW5kID09PSAiLSIpIHsKICAgICAgICAgIHN2VHlwZSA9ICJkZWxldGlvbiAoKy0pIjsKICAgICAgICB9IGVsc2UgaWYgKGwuc3RyYW5kID09PSAiKyIgJiYgci5zdHJhbmQgPT09ICIrIikgewogICAgICAgICAgc3ZUeXBlID0gImludmVyc2lvbiAoKyspIjsKICAgICAgICB9IGVsc2UgaWYgKGwuc3RyYW5kID09PSAiLSIgJiYgci5zdHJhbmQgPT09ICItIikgewogICAgICAgICAgc3ZUeXBlID0gImludmVyc2lvbiAoLS0pIjsKICAgICAgICB9IGVsc2UgaWYgKGwuc3RyYW5kID09PSAiLSIgJiYgci5zdHJhbmQgPT09ICIrIikgewogICAgICAgICAgc3ZUeXBlID0gImR1cGxpY2F0aW9uICgtKykiOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBzdlR5cGUgPSBgKCR7bC5zdHJhbmR9JHtyLnN0cmFuZH0pYDsKICAgICAgICB9CiAgICAgICAgW3JlYWQsIG1hdGVdLmZvckVhY2goKGQpID0+IHsKICAgICAgICAgIGQuZm91bmRNYXRlID0gdHJ1ZTsKICAgICAgICAgIGQuaW5zZXJ0U2l6ZSA9IGluc2VydFNpemU7CiAgICAgICAgICBkLmxhcmdlSW5zZXJ0U2l6ZSA9IGxhcmdlSW5zZXJ0U2l6ZTsKICAgICAgICAgIGQuc3ZUeXBlID0gc3ZUe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ChzZWdtZW50LnN0YXJ0IDwgZG9uICYmIGFjYyA8IHNlZ21lbnQuZW5kKSB7CiAgICAgICAgICBjb25zdCBqID0ganVuY3Rpb25zLmZpbmQoKGQpID0+IGQuc3RhcnQgPT09IGRvbiAmJiBkLmVuZCA9PT0gYWNjKTsKICAgICAgICAgIGlmIChqKSB7CiAgICAgICAgICAgIGouc2NvcmUgKz0gMTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGp1bmN0aW9ucy5wdXNoKHsgc3RhcnQ6IGRvbiwgZW5kOiBhY2MsIHNjb3JlOiAxIH0pOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfSk7CiAgICB9KTsKICAgIHJldHVybiBqdW5jdGlvbnMuZmlsdGVyKChkKSA9PiBkLnNjb3JlID49IG1pbkNvdmVyYWdlKTsKICB9OwogIHZhciB0aWxlRnVuY3Rpb25zID0gewogICAgaW5pdCwKICAgIHRpbGVzZXRJbmZvLAogICAgZmV0Y2hUaWxlc0RlYm91bmNlZCwKICAgIHRpbGUsCiAgICBnZXRUYWJ1bGFyRGF0YQogIH07CiAgZXhwb3NlKHRpbGVGdW5jdGlvbnMpOwp9KSgpOwovKiEKICogVGhlIGJ1ZmZlciBtb2R1bGUgZnJvbSBub2RlLmpzLCBmb3IgdGhlIGJyb3dzZXIuCiAqCiAqIEBhdXRob3IgICBGZXJvc3MgQWJvdWtoYWRpamVoIDxodHRwczovL2Zlcm9zcy5vcmc+CiAqIEBsaWNlbnNlICBNSVQKICovCi8qISBpZWVlNzU0LiBCU0QtMy1DbGF1c2UgTGljZW5zZS4gRmVyb3NzIEFib3VraGFkaWplaCA8aHR0cHM6Ly9mZXJvc3Mub3JnL29wZW5zb3VyY2U+ICovCg==",fse=typeof window<"u"&&window.Blob&&new Blob([atob(o9e)],{type:"text/javascript;charset=utf-8"});function Atg(){const e=fse&&(window.URL||window.webkitURL).createObjectURL(fse);try{return e?new Worker(e):new Worker("data:application/javascript;base64,"+o9e,{type:"module"})}finally{e&&(window.URL||window.webkitURL).revokeObjectURL(e)}}const atg=200;class nH{constructor(g,I){Ct(this,"dataConfig",{}),Ct(this,"uid"),Ct(this,"fetchTimeout"),Ct(this,"toFetch"),Ct(this,"MAX_TILE_WIDTH",2e4),Ct(this,"worker"),Ct(this,"track"),this.uid=g.libraries.slugid.nice(),this.toFetch=new Set;const{url:i,indexUrl:n,assembly:C,...r}=I;this.worker=GT(new Atg).then(async o=>{const A=Object.entries(pI(C).size);return await o.init(this.uid,{url:i,indexUrl:n},A,r),o})}async tilesetInfo(g){(await this.worker).tilesetInfo(this.uid).then(g)}fetchTilesDebounced(g,I){var i;const{toFetch:n}=this,C=I[0].split(".")[0],r=n.size?[...n][0].split(".")[0]:null;if(C!==r){for(const o of this.toFetch)(i=this.track)==null||i.fetching.delete(o);this.toFetch.clear()}I.forEach(o=>this.toFetch.add(o)),this.fetchTimeout&&clearTimeout(this.fetchTimeout),this.fetchTimeout=setTimeout(()=>{this.sendFetch(g,[...this.toFetch]),this.toFetch.clear()},atg)}async sendFetch(g,I){(await this.worker).fetchTilesDebounced(this.uid,I).then(g)}async getTabularData(g){const I=await(await this.worker).getTabularData(this.uid,g);return JSON.parse(new TextDecoder().decode(I))}}Ct(nH,"config",{type:"bam"});const A9e="KCgpID0+IHsKICB2YXIgX19jcmVhdGUgPSBPYmplY3QuY3JlYXRlOwogIHZhciBfX2RlZlByb3AgPSBPYmplY3QuZGVmaW5lUHJvcGVydHk7CiAgdmFyIF9fZ2V0T3duUHJvcERlc2MgPSBPYmplY3QuZ2V0T3duUHJvcGVydHlEZXNjcmlwdG9yOwogIHZhciBfX2dldE93blByb3BOYW1lcyA9IE9iamVjdC5nZXRPd25Qcm9wZXJ0eU5hbWVzOwogIHZhciBfX2dldFByb3RvT2YgPSBPYmplY3QuZ2V0UHJvdG90eXBlT2Y7CiAgdmFyIF9faGFzT3duUHJvcCA9IE9iamVjdC5wcm90b3R5cGUuaGFzT3duUHJvcGVydHk7CiAgdmFyIF9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srXSA9IHRtcCAmIDI1NTsKICAgICAgICB9CiAgICAgICAgaWYgKHBsYWNlSG9sZGVyc0xlbiA9PT0gMikgewogICAgICAgICAgdG1wID0gcmV2TG9va3VwW2I2NC5jaGFyQ29kZUF0KGkyKV0gPDwgMiB8IHJldkxvb2t1cFtiNjQuY2hhckNvZGVBdChpMiArIDEpXSA+PiA0OwogICAgICAgICAgYXJyW2N1ckJ5dGUrK10gPSB0bXAgJiAyNTU7CiAgICAgICAgfQogICAgICAgIGlmIChwbGFjZUhvbGRlcnNMZW4gPT09IDEpIHsKICAgICAgICAgIHRtcCA9IHJldkxvb2t1cFtiNjQuY2hhckNvZGVBdChpMildIDw8IDEwIHwgcmV2TG9va3VwW2I2NC5jaGFyQ29kZUF0KGkyICsgMSldIDw8IDQgfCByZXZMb29rdXBbYjY0LmNoYXJDb2RlQXQoaTIgKyAyKV0gPj4gMjsKICAgICAgICAgIGFycltjdXJCeXRlKytdID0gdG1wID4+IDggJiAyNTU7CiAgICAgICAgICBhcnJbY3VyQnl0ZSsrXSA9IHRtcCAmIDI1NTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIGFycjsKICAgICAgfQogICAgICBmdW5jdGlvbiB0cmlwbGV0VG9CYXNlNjQobnVtKSB7CiAgICAgICAgcmV0dXJuIGxvb2t1cFtudW0gPj4gMTggJiA2M10gKyBsb29rdXBbbnVtID4+IDEyICYgNjNdICsgbG9va3VwW251bSA+PiA2ICYgNjNdICsgbG9va3VwW251bSAmIDYzXTsKICAgICAgfQogICAgICBmdW5jdGlvbiBlbmNvZGVDaHVuayh1aW50OCwgc3RhcnQsIGVuZCkgewogICAgICAgIHZhciB0bXA7CiAgICAgICAgdmFyIG91dHB1dCA9IFtdOwogICAgICAgIGZvciAodmFyIGkyID0gc3RhcnQ7IGkyIDwgZW5kOyBpMiArPSAzKSB7CiAgICAgICAgICB0bXAgPSAodWludDhbaTJdIDw8IDE2ICYgMTY3MTE2ODApICsgKHVpbnQ4W2kyICsgMV0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ICAgdmFsdWUgPSBNYXRoLmFicyh2YWx1ZSk7CiAgICAgICAgaWYgKGlzTmFOKHZhbHVlKSB8fCB2YWx1ZSA9PT0gSW5maW5pdHkpIHsKICAgICAgICAgIG0gPSBpc05hTih2YWx1ZSkgPyAxIDogMDsKICAgICAgICAgIGUgPSBlTWF4OwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBlID0gTWF0aC5mbG9vcihNYXRoLmxvZyh2YWx1ZSkgLyBNYXRoLkxOMik7CiAgICAgICAgICBpZiAodmFsdWUgKiAoYyA9IE1hdGgucG93KDIsIC1lKSkgPCAxKSB7CiAgICAgICAgICAgIGUtLTsKICAgICAgICAgICAgYyAqPSAyOwogICAgICAgICAgfQogICAgICAgICAgaWYgKGUgKyBlQmlhcyA+PSAxKSB7CiAgICAgICAgICAgIHZhbHVlICs9IHJ0IC8gYzsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHZhbHVlICs9IHJ0ICogTWF0aC5wb3coMiwgMSAtIGVCaWFzKTsKICAgICAgICAgIH0KICAgICAgICAgIGlmICh2YWx1ZSAqIGMgPj0gMikgewogICAgICAgICAgICBlKys7CiAgICAgICAgICAgIGMgLz0gMjsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChlICsgZUJpYXMgPj0gZU1heCkgewogICAgICAgICAgICBtID0gMDsKICAgICAgICAgICAgZSA9IGVNYXg7CiAgICAgICAgICB9IGVsc2UgaWYgKGUgKyBlQmlhcyA+PSAxKSB7CiAgICAgICAgICAgIG0gPSAodmFsdWUgKiBjIC0gMSkgKiBNYXRoLnBvdygyLCBtTGVuKTsKICAgICAgICAgICAgZSA9IGUgKyBlQmlhczsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIG0gPSB2YWx1ZSAqIE1hdGgucG93KDIsIGVCaWFzIC0gMSkgKiBNYXRoLnBvdygyLCBtTGVuKTsKICAgICAgICAgICAgZSA9IDA7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgI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0KICAgICAgfQogICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkoQnVmZmVyMTAucHJvdG90eXBlLCAicGFyZW50IiwgewogICAgICAgIGVudW1lcmFibGU6IHRydWUsCiAgICAgICAgZ2V0OiBmdW5jdGlvbigpIHsKICAgICAgICAgIGlmICghQnVmZmVyMTAuaXNCdWZmZXIodGhpcykpCiAgICAgICAgICAgIHJldHVybiB2b2lkIDA7CiAgICAgICAgICByZXR1cm4gdGhpcy5idWZmZXI7CiAgICAgICAgfQogICAgICB9KTsKICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KEJ1ZmZlcjEwLnByb3RvdHlwZSwgIm9mZnNldCIsIHsKICAgICAgICBlbnVtZXJhYmxlOiB0cnVlLAogICAgICAgIGdldDogZnVuY3Rpb24oKSB7CiAgICAgICAgICBpZiAoIUJ1ZmZlcjEwLmlzQnVmZmVyKHRoaXMpKQogICAgICAgICAgICByZXR1cm4gdm9pZCAwOwogICAgICAgICAgcmV0dXJuIHRoaXMuYnl0ZU9mZnNldDsKICAgICAgICB9CiAgICAgIH0pOwogICAgICBmdW5jdGlvbiBjcmVhdGVCdWZmZXIobGVuZ3RoKSB7CiAgICAgICAgaWYgKGxlbmd0aCA+IEtfTUFYX0xFTkdUSCkgewogICAgICAgICAgdGhyb3cgbmV3IFJhbmdlRXJyb3IoJ1RoZSB2YWx1ZSAiJyArIGxlbmd0aCArICciIGlzIGludmFsaWQgZm9yIG9wdGlvbiAic2l6ZSInKTsKICAgICAgICB9CiAgICAgICAgY29uc3QgYnVmID0gbmV3IFVpbnQ4QXJyYXkobGVuZ3RoKTsKICAgICAgICBPYmplY3Quc2V0UHJvdG90eXBlT2YoYnVmLCBCdWZmZXIxMC5wcm90b3R5cGUpOwogICAgICAgIHJldHVybiBidWY7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gQnVmZmVyMTAoYXJnLCBlbmNvZGluZ09yT2Zmc2V0LCBsZW5ndGgpIHsKICAgICAgICBpZiAodHlwZW9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ludDhBcnJheScpOwogICAgICAgIH0KICAgICAgICBpZiAoYSA9PT0gYikKICAgICAgICAgIHJldHVybiAwOwogICAgICAgIGxldCB4ID0gYS5sZW5ndGg7CiAgICAgICAgbGV0IHkgPSBiLmxlbmd0aDsKICAgICAgICBmb3IgKGxldCBpID0gMCwgbGVuID0gTWF0aC5taW4oeCwgeSk7IGkgPCBsZW47ICsraSkgewogICAgICAgICAgaWYgKGFbaV0gIT09IGJbaV0pIHsKICAgICAgICAgICAgeCA9IGFbaV07CiAgICAgICAgICAgIHkgPSBiW2ldOwogICAgICAgICAgICBicmVhazsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKHggPCB5KQogICAgICAgICAgcmV0dXJuIC0xOwogICAgICAgIGlmICh5IDwgeCkKICAgICAgICAgIHJldHVybiAxOwogICAgICAgIHJldHVybiAwOwogICAgICB9OwogICAgICBCdWZmZXIxMC5pc0VuY29kaW5nID0gZnVuY3Rpb24gaXNFbmNvZGluZyhlbmNvZGluZykgewogICAgICAgIHN3aXRjaCAoU3RyaW5nKGVuY29kaW5nKS50b0xvd2VyQ2FzZSgpKSB7CiAgICAgICAgICBjYXNlICJoZXgiOgogICAgICAgICAgY2FzZSAidXRmOCI6CiAgICAgICAgICBjYXNlICJ1dGYtOCI6CiAgICAgICAgICBjYXNlICJhc2NpaSI6CiAgICAgICAgICBjYXNlICJsYXRpbjEiOgogICAgICAgICAgY2FzZSAiYmluYXJ5IjoKICAgICAgICAgIGNhc2UgImJhc2U2NCI6CiAgICAgICAgICBjYXNlICJ1Y3MyIjoKICAgICAgICAgIGNhc2UgInVjcy0yIjoKICAgICAgICAgIGNhc2UgInV0ZjE2bGUiOgogICAgICAgICAgY2FzZSAidXRmLTE2bGUiOgogICAgICAgICAgICByZXR1cm4gdHJ1ZTsKICAgICAgICAgIGRlZmF1bHQ6CiAgICAgICAgICAgIHJldHVybiBmYWxzZTsKICAgICAgICB9CiAgICAgIH07CiAgICAgIEJ1ZmZlcjEwLmNvbmNhdCA9IGZ1bmN0aW9uIGNvbmNhdChsaXN0LCBsZW5ndGgpIHsKICAgICAgICBpZiAoIUFycmF5LmlzQXJyYXkobGlzdCkpIHsKICAgICAgICAgIHRocm93IG5ldyBUeXBlRXJyb3IoJyJsaXN0IiBhcmd1bWVudCBtdXN0IGJlIGFuIEFycmF5IG9mIEJ1ZmZlcnMnKTsKICAgICAgICB9CiAgICAgICAgaWYgKGxpc3QubGVuZ3RoID09PSAwKSB7CiAgICAgICAgICByZXR1cm4gQnVmZmVyMTAuYWxsb2MoMCk7CiAgICAgICAgfQogICAgICAgIGxldCBpOwogICAgICAgIGlmIChsZW5ndGggPT09IHZvaWQgMCkgewogICAgICAgICAgbGVuZ3RoID0gMDsKICAgICAgICAgIGZvciAoaSA9IDA7IGkgPCBsaXN0Lmxlbmd0aDsgKytpKSB7CiAgICAgICAgICAgIGxlbmd0aCArPSBsaXN0W2ldLmxlbmd0aDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgY29uc3QgYnVmZmVyID0gQnVmZmVyMTAuYWxsb2NVbnNhZmUobGVuZ3RoKTsKICAgICAgICBsZXQgcG9zID0gMDsKICAgICAgICBmb3IgKGkgPSAwOyBpIDwgbGlzdC5sZW5ndGg7ICsraSkgewogICAgICAgICAgbGV0IGJ1ZiA9IGxpc3RbaV07CiAgICAgICAgICBpZiAoaXNJbnN0YW5jZShidWYsIFVpbnQ4QXJyYXkpKSB7CiAgICAgICAgICAgIGlmIChwb3MgKyBidWYubGVuZ3RoID4gYnVmZmVyLmxlbmd0aCkgewogICAgICAgICAgICAgIGlmICghQnVmZmVyMTAuaXNCdWZmZXIoYnVmKSkKICAgICAgICAgICAgICAgIGJ1ZiA9IEJ1ZmZlcjEwLmZyb20oYnVmKTsKICAgICAgICAgICAgICBidWYuY29weShidWZmZXIsIHBvcyk7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgVWludDhBcnJheS5wcm90b3R5cGUuc2V0LmNhbGw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ZW50c1syXSA9PT0gdHJ1ZTsKICAgICAgICBpZiAoIW11c3RNYXRjaCAmJiBsZW4gPT09IDApCiAgICAgICAgICByZXR1cm4gMDsKICAgICAgICBsZXQgbG93ZXJlZENhc2UgPSBmYWxzZTsKICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgIHN3aXRjaCAoZW5jb2RpbmcpIHsKICAgICAgICAgICAgY2FzZSAiYXNjaWkiOgogICAgICAgICAgICBjYXNlICJsYXRpbjEiOgogICAgICAgICAgICBjYXNlICJiaW5hcnkiOgogICAgICAgICAgICAgIHJldHVybiBsZW47CiAgICAgICAgICAgIGNhc2UgInV0ZjgiOgogICAgICAgICAgICBjYXNlICJ1dGYtOCI6CiAgICAgICAgICAgICAgcmV0dXJuIHV0ZjhUb0J5dGVzKHN0cmluZykubGVuZ3RoOwogICAgICAgICAgICBjYXNlICJ1Y3MyIjoKICAgICAgICAgICAgY2FzZSAidWNzLTIiOgogICAgICAgICAgICBjYXNlICJ1dGYxNmxlIjoKICAgICAgICAgICAgY2FzZSAidXRmLTE2bGUiOgogICAgICAgICAgICAgIHJldHVybiBsZW4gKiAyOwogICAgICAgICAgICBjYXNlICJoZXgiOgogICAgICAgICAgICAgIHJldHVybiBsZW4gPj4+IDE7CiAgICAgICAgICAgIGNhc2UgImJhc2U2NCI6CiAgICAgICAgICAgICAgcmV0dXJuIGJhc2U2NFRvQnl0ZXMoc3RyaW5nKS5sZW5ndGg7CiAgICAgICAgICAgIGRlZmF1bHQ6CiAgICAgICAgICAgICAgaWYgKGxvd2VyZWRDYXNlKSB7CiAgICAgICAgICAgICAgICByZXR1cm4gbXVzdE1hdGNoID8gLTEgOiB1dGY4VG9CeXRlcyhzdHJpbmcpLmxlbmd0aDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgZW5jb2RpbmcgPSAoIiIgKyBlbmNvZGluZykudG9Mb3dlckNhc2UoKTsKICAgICAgICAgICAgICBsb3dlcmVkQ2FzZSA9IHRydWU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9CiAgICAgIEJ1ZmZlcjEwLmJ5dGVMZW5ndGggPSBieXRlTGVuZ3RoOwogICAgICBmdW5jdGlvbiBzbG93VG9TdHJpbmcoZW5jb2RpbmcsIHN0YXJ0LCBlbmQpIHsKICAgICAgICBsZXQgbG93ZXJlZENhc2UgPSBmYWxzZTsKICAgICAgICBpZiAoc3RhcnQgPT09IHZvaWQgMCB8fCBzdGFydCA8IDApIHsKICAgICAgICAgIHN0YXJ0ID0gMDsKICAgICAgICB9CiAgICAgICAgaWYgKHN0YXJ0ID4gdGhpcy5sZW5ndGgpIHsKICAgICAgICAgIHJldHVybiAiIjsKICAgICAgICB9CiAgICAgICAgaWYgKGVuZCA9PT0gdm9pZCAwIHx8IGVuZCA+IHRoaXMubGVuZ3RoKSB7CiAgICAgICAgICBlbmQgPSB0aGlzLmxlbmd0aDsKICAgICAgICB9CiAgICAgICAgaWYgKGVuZCA8PSAwKSB7CiAgICAgICAgICByZXR1cm4gIiI7CiAgICAgICAgfQogICAgICAgIGVuZCA+Pj49IDA7CiAgICAgICAgc3RhcnQgPj4+PSAwOwogICAgICAgIGlmIChlbmQgPD0gc3RhcnQpIHsKICAgICAgICAgIHJldHVybiAiIjsKICAgICAgICB9CiAgICAgICAgaWYgKCFlbmNvZGluZykKICAgICAgICAgIGVuY29kaW5nID0gInV0ZjgiOwogICAgICAgIHdoaWxlICh0cnVlKSB7CiAgICAgICAgICBzd2l0Y2ggKGVuY29kaW5nKSB7CiAgICAgICAgICAgIGNhc2UgImhleCI6CiAgICAgICAgICAgICAgcmV0dXJuIGhleFNsaWNlKHRoaXMsIHN0YXJ0LCBlbmQpOwogICAgICAgICAgICBjYXNlICJ1dGY4IjoKICAgICAgICAgICAgY2FzZSAidXRmLTgiOgogICAgICAgICAgICAgIHJldHVybiB1dGY4U2xpY2UodGhpcywgc3RhcnQsIGVuZCk7CiAgICAgICAgICAgIGNhc2UgImFzY2lpIjoKICAgICAgICAgICAgICByZXR1cm4gYXNjaWlTbGljZSh0aGlzLCBzdGFydCwgZW5kKTsKICAgICAgICAgICAgY2FzZSAibGF0aW4xIjoKICAgICAgICAgICAgY2FzZSAiYmluYXJ5IjoKICAgICAgICAgICAgICByZXR1cm4gbGF0aW4xU2xpY2UodGhpcywgc3RhcnQsIGVuZCk7CiAgICAgICAgICAgIGNhc2UgImJhc2U2NCI6CiAgICAgICAgICAgICAgcmV0dXJuIGJhc2U2NFNsaWNlKHRoaXMsIHN0YXJ0LCBlbmQpOwogICAgICAgICAgICBjYXNlICJ1Y3MyIjoKICAgICAgICAgICAgY2FzZSAidWNzLTIiOgogICAgICAgICAgICBjYXNlICJ1dGYxNmxlIjoKICAgICAgICAgICAgY2FzZSAidXRmLTE2bGUiOgogICAgICAgICAgICAgIHJldHVybiB1dGYxNmxlU2xpY2UodGhpcywgc3RhcnQsIGVuZCk7CiAgICAgICAgICAgIGRlZmF1bHQ6CiAgICAgICAgICAgICAgaWYgKGxvd2VyZWRDYXNlKQogICAgICAgICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcigiVW5rbm93biBlbmNvZGluZzogIiArIGVuY29kaW5nKTsKICAgICAgICAgICAgICBlbmNvZGluZyA9IChlbmNvZGluZyArICIiKS50b0xvd2VyQ2FzZSgpOwogICAgICAgICAgICAgIGxvd2VyZWRDYXNlID0gdHJ1ZTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgICAgQnVmZmVyMTAucHJvdG90eXBlLl9pc0J1ZmZlciA9IHRydWU7CiAgICAgIGZ1bmN0aW9uIHN3YXAoYiwgbiwgbSkgewogICAgICAgIGNvbnN0IGkgPSBiW25dOwogICAgICAgIGJbbl0gPSBiW21dOwogICAgICAgIGJbbV0gPSBpOwogICAgICB9CiAgICAgIEJ1ZmZlcjEwLnByb3RvdHlwZS5zd2FwMTYgPSBmdW5jdGlvbiBzd2FwMTYoKSB7CiAgICAgICAgY29uc3QgbGVuID0gdGhpcy5sZW5ndGg7C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gICAgICBpZiAoZW5kID09PSB2b2lkIDApIHsKICAgICAgICAgIGVuZCA9IHRhcmdldCA/IHRhcmdldC5sZW5ndGggOiAwOwogICAgICAgIH0KICAgICAgICBpZiAodGhpc1N0YXJ0ID09PSB2b2lkIDApIHsKICAgICAgICAgIHRoaXNTdGFydCA9IDA7CiAgICAgICAgfQogICAgICAgIGlmICh0aGlzRW5kID09PSB2b2lkIDApIHsKICAgICAgICAgIHRoaXNFbmQgPSB0aGlzLmxlbmd0aDsKICAgICAgICB9CiAgICAgICAgaWYgKHN0YXJ0IDwgMCB8fCBlbmQgPiB0YXJnZXQubGVuZ3RoIHx8IHRoaXNTdGFydCA8IDAgfHwgdGhpc0VuZCA+IHRoaXMubGVuZ3RoKSB7CiAgICAgICAgICB0aHJvdyBuZXcgUmFuZ2VFcnJvcigib3V0IG9mIHJhbmdlIGluZGV4Iik7CiAgICAgICAgfQogICAgICAgIGlmICh0aGlzU3RhcnQgPj0gdGhpc0VuZCAmJiBzdGFydCA+PSBlbmQpIHsKICAgICAgICAgIHJldHVybiAwOwogICAgICAgIH0KICAgICAgICBpZiAodGhpc1N0YXJ0ID49IHRoaXNFbmQpIHsKICAgICAgICAgIHJldHVybiAtMTsKICAgICAgICB9CiAgICAgICAgaWYgKHN0YXJ0ID49IGVuZCkgewogICAgICAgICAgcmV0dXJuIDE7CiAgICAgICAgfQogICAgICAgIHN0YXJ0ID4+Pj0gMDsKICAgICAgICBlbmQgPj4+PSAwOwogICAgICAgIHRoaXNTdGFydCA+Pj49IDA7CiAgICAgICAgdGhpc0VuZCA+Pj49IDA7CiAgICAgICAgaWYgKHRoaXMgPT09IHRhcmdldCkKICAgICAgICAgIHJldHVybiAwOwogICAgICAgIGxldCB4ID0gdGhpc0VuZCAtIHRoaXNTdGFydDsKICAgICAgICBsZXQgeSA9IGVuZCAtIHN0YXJ0OwogICAgICAgIGNvbnN0IGxlbiA9IE1hdGgubWluKHgsIHkpOwogICAgICAgIGNvbnN0IHRoaXNDb3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iZXJJc05hTihieXRlT2Zmc2V0KSkgewogICAgICAgICAgYnl0ZU9mZnNldCA9IGRpciA/IDAgOiBidWZmZXIubGVuZ3RoIC0gMTsKICAgICAgICB9CiAgICAgICAgaWYgKGJ5dGVPZmZzZXQgPCAwKQogICAgICAgICAgYnl0ZU9mZnNldCA9IGJ1ZmZlci5sZW5ndGggKyBieXRlT2Zmc2V0OwogICAgICAgIGlmIChieXRlT2Zmc2V0ID49IGJ1ZmZlci5sZW5ndGgpIHsKICAgICAgICAgIGlmIChkaXIpCiAgICAgICAgICAgIHJldHVybiAtMTsKICAgICAgICAgIGVsc2UKICAgICAgICAgICAgYnl0ZU9mZnNldCA9IGJ1ZmZlci5sZW5ndGggLSAxOwogICAgICAgIH0gZWxzZSBpZiAoYnl0ZU9mZnNldCA8IDApIHsKICAgICAgICAgIGlmIChkaXIpCiAgICAgICAgICAgIGJ5dGVPZmZzZXQgPSAwOwogICAgICAgICAgZWxzZQogICAgICAgICAgICByZXR1cm4gLTE7CiAgICAgICAgfQogICAgICAgIGlmICh0eXBlb2YgdmFsID09PSAic3RyaW5nIikgewogICAgICAgICAgdmFsID0gQnVmZmVyMTAuZnJvbSh2YWwsIGVuY29kaW5nKTsKICAgICAgICB9CiAgICAgICAgaWYgKEJ1ZmZlcjEwLmlzQnVmZmVyKHZhbCkpIHsKICAgICAgICAgIGlmICh2YWwubGVuZ3RoID09PSAwKSB7CiAgICAgICAgICAgIHJldHVybiAtMTsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBhcnJheUluZGV4T2YoYnVmZmVyLCB2YWwsIGJ5dGVPZmZzZXQsIGVuY29kaW5nLCBkaXIpOwogICAgICAgIH0gZWxzZSBpZiAodHlwZW9mIHZhbCA9PT0gIm51bWJlciIpIHsKICAgICAgICAgIHZhbCA9IHZhbCAmIDI1NTsKICAgICAgICAgIGlmICh0eXBlb2YgVWludDhBcnJheS5wcm90b3R5cGUuaW5kZXhPZiA9PT0gImZ1bmN0aW9uIikgewogIC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AtMTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpbmRleFNpemUgPSAyOwogICAgICAgICAgICBhcnJMZW5ndGggLz0gMjsKICAgICAgICAgICAgdmFsTGVuZ3RoIC89IDI7CiAgICAgICAgICAgIGJ5dGVPZmZzZXQgLz0gMjsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZnVuY3Rpb24gcmVhZChidWYsIGkyKSB7CiAgICAgICAgICBpZiAoaW5kZXhTaXplID09PSAxKSB7CiAgICAgICAgICAgIHJldHVybiBidWZbaTJdOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcmV0dXJuIGJ1Zi5yZWFkVUludDE2QkUoaTIgKiBpbmRleFNpemUpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBsZXQgaTsKICAgICAgICBpZiAoZGlyKSB7CiAgICAgICAgICBsZXQgZm91bmRJbmRleCA9IC0xOwogICAgICAgICAgZm9yIChpID0gYnl0ZU9mZnNldDsgaSA8IGFyckxlbmd0aDsgaSsrKSB7CiAgICAgICAgICAgIGlmIChyZWFkKGFyciwgaSkgPT09IHJlYWQodmFsLCBmb3VuZEluZGV4ID09PSAtMSA/IDAgOiBpIC0gZm91bmRJbmRleCkpIHsKICAgICAgICAgICAgICBpZiAoZm91bmRJbmRleCA9PT0gLTEpCiAgICAgICAgICAgICAgICBmb3VuZEluZGV4ID0gaTsKICAgICAgICAgICAgICBpZiAoaSAtIGZvdW5kSW5kZXggKyAxID09PSB2YWxMZW5ndGgpCiAgICAgICAgICAgICAgICByZXR1cm4gZm91bmRJbmRleCAqIGluZGV4U2l6ZTsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICBpZiAoZm91bmRJbmRleCAhPT0gLTEpCiAgICAgICAgICAgICAgICBpIC09IGkgLSBmb3VuZEluZGV4OwogICAgICAgICAgICAgIGZvdW5kSW5kZXggPSAtMTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0gZWxzZSB7CiAgIC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CwgYnl0ZU9mZnNldCwgZW5jb2RpbmcpIHsKICAgICAgICByZXR1cm4gYmlkaXJlY3Rpb25hbEluZGV4T2YodGhpcywgdmFsLCBieXRlT2Zmc2V0LCBlbmNvZGluZywgZmFsc2UpOwogICAgICB9OwogICAgICBmdW5jdGlvbiBoZXhXcml0ZShidWYsIHN0cmluZywgb2Zmc2V0LCBsZW5ndGgpIHsKICAgICAgICBvZmZzZXQgPSBOdW1iZXIob2Zmc2V0KSB8fCAwOwogICAgICAgIGNvbnN0IHJlbWFpbmluZyA9IGJ1Zi5sZW5ndGggLSBvZmZzZXQ7CiAgICAgICAgaWYgKCFsZW5ndGgpIHsKICAgICAgICAgIGxlbmd0aCA9IHJlbWFpbmluZzsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgbGVuZ3RoID0gTnVtYmVyKGxlbmd0aCk7CiAgICAgICAgICBpZiAobGVuZ3RoID4gcmVtYWluaW5nKSB7CiAgICAgICAgICAgIGxlbmd0aCA9IHJlbWFpbmluZzsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgY29uc3Qgc3RyTGVuID0gc3RyaW5nLmxlbmd0aDsKICAgICAgICBpZiAobGVuZ3RoID4gc3RyTGVuIC8gMikgewogICAgICAgICAgbGVuZ3RoID0gc3RyTGVuIC8gMjsKICAgICAgICB9CiAgICAgICAgbGV0IGk7CiAgICAgICAgZm9yIChpID0gMDsgaSA8IGxlbmd0aDsgKytpKSB7CiAgICAgICAgICBjb25zdCBwYXJzZWQgPSBwYXJzZUludChzdHJpbmcuc3Vic3RyKGkgKiAyLCAyKSwgMTYpOwogICAgICAgICAgaWYgKG51bWJlcklzTmFOKHBhcnNlZCkpCiAgICAgICAgICAgIHJldHVybiBpOwogICAgICAgICAgYnVmW29mZnNldCArIGldID0gcGFyc2VkOwogICAgICAgIH0KICAgICAgICByZXR1cm4gaTsKICAgICAgfQogICAgICBmdW5jdGlvbiB1dGY4V3JpdGUoYnVmLCBzdHJpbmcsIG9mZnNldCwg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ICAgICAgZW5jb2RpbmcgPSAidXRmOCI7CiAgICAgICAgbGV0IGxvd2VyZWRDYXNlID0gZmFsc2U7CiAgICAgICAgZm9yICg7IDsgKSB7CiAgICAgICAgICBzd2l0Y2ggKGVuY29kaW5nKSB7CiAgICAgICAgICAgIGNhc2UgImhleCI6CiAgICAgICAgICAgICAgcmV0dXJuIGhleFdyaXRlKHRoaXMsIHN0cmluZywgb2Zmc2V0LCBsZW5ndGgpOwogICAgICAgICAgICBjYXNlICJ1dGY4IjoKICAgICAgICAgICAgY2FzZSAidXRmLTgiOgogICAgICAgICAgICAgIHJldHVybiB1dGY4V3JpdGUodGhpcywgc3RyaW5nLCBvZmZzZXQsIGxlbmd0aCk7CiAgICAgICAgICAgIGNhc2UgImFzY2lpIjoKICAgICAgICAgICAgY2FzZSAibGF0aW4xIjoKICAgICAgICAgICAgY2FzZSAiYmluYXJ5IjoKICAgICAgICAgICAgICByZXR1cm4gYXNjaWlXcml0ZSh0aGlzLCBzdHJpbmcsIG9mZnNldCwgbGVuZ3RoKTsKICAgICAgICAgICAgY2FzZSAiYmFzZTY0IjoKICAgICAgICAgICAgICByZXR1cm4gYmFzZTY0V3JpdGUodGhpcywgc3RyaW5nLCBvZmZzZXQsIGxlbmd0aCk7CiAgICAgICAgICAgIGNhc2UgInVjczIiOgogICAgICAgICAgICBjYXNlICJ1Y3MtMiI6CiAgICAgICAgICAgIGNhc2UgInV0ZjE2bGUiOgogICAgICAgICAgICBjYXNlICJ1dGYtMTZsZSI6CiAgICAgICAgICAgICAgcmV0dXJuIHVjczJXcml0ZSh0aGlzLCBzdHJpbmcsIG9mZnNldCwgbGVuZ3RoKTsKICAgICAgICAgICAgZGVmYXVsdDoKICAgICAgICAgICAgICBpZiAobG93ZXJlZENhc2UpCiAgICAgICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCJVbmtub3duIGVuY29kaW5nOiAiICsgZW5jb2RpbmcpOwogICAgICAgICAgICAgIGVuY29kaW5nID0gKCI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wogICAgICAgICAgaWYgKGkgKyBieXRlc1BlclNlcXVlbmNlIDw9IGVuZCkgewogICAgICAgICAgICBsZXQgc2Vjb25kQnl0ZSwgdGhpcmRCeXRlLCBmb3VydGhCeXRlLCB0ZW1wQ29kZVBvaW50OwogICAgICAgICAgICBzd2l0Y2ggKGJ5dGVzUGVyU2VxdWVuY2UpIHsKICAgICAgICAgICAgICBjYXNlIDE6CiAgICAgICAgICAgICAgICBpZiAoZmlyc3RCeXRlIDwgMTI4KSB7CiAgICAgICAgICAgICAgICAgIGNvZGVQb2ludCA9IGZpcnN0Qnl0ZTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgIGNhc2UgMjoKICAgICAgICAgICAgICAgIHNlY29uZEJ5dGUgPSBidWZbaSArIDFdOwogICAgICAgICAgICAgICAgaWYgKChzZWNvbmRCeXRlICYgMTkyKSA9PT0gMTI4KSB7CiAgICAgICAgICAgICAgICAgIHRlbXBDb2RlUG9pbnQgPSAoZmlyc3RCeXRlICYgMzEpIDw8IDYgfCBzZWNvbmRCeXRlICYgNjM7CiAgICAgICAgICAgICAgICAgIGlmICh0ZW1wQ29kZVBvaW50ID4gMTI3KSB7CiAgICAgICAgICAgICAgICAgICAgY29kZVBvaW50ID0gdGVtcENvZGVQb2ludDsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgY2FzZSAzOgogICAgICAgICAgICAgICAgc2Vjb25kQnl0ZSA9IGJ1ZltpICsgMV07CiAgICAgICAgICAgICAgICB0aGlyZEJ5dGUgPSBidWZbaSArIDJdOwogICAgICAgICAgICAgICAgaWYgKChzZWNvbmRCeXRlICYgMTkyKSA9PT0gMTI4ICYmICh0aGlyZEJ5dGUgJiAxOTIpID09PSAxMjgpIHsKICAgICAgICAgICAgICAgICAgdGVtcENvZGVQb2ludCA9IChmaXJzdEJ5dGUgJiAxNSkgPDwgMTIgfCAoc2Vjb25kQnl0ZSAmIDYzKSA8PCA2IHwgdGhpcmRCeXRlICYgNjM7CiAgICAgICAgICAgICAgICAgIGlmICh0ZW1wQ29kZVBvaW50ID4gMjA0NyAmJiAodGVtcENvZGVQb2ludCA8IDU1Mjk2IHx8IHRlbXBDb2RlUG9pbnQgPiA1NzM0MykpIHsKICAgICAgICAgICAgICAgICAgICBjb2RlUG9pbnQgPSB0ZW1wQ29kZVBvaW50OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICBjYXNlIDQ6CiAgICAgICAgICAgICAgICBzZWNvbmRCeXRlID0gYnVmW2kgKyAxXTsKICAgICAgICAgICAgICAgIHRoaXJkQnl0ZSA9IGJ1ZltpICsgMl07CiAgICAgICAgICAgICAgICBmb3VydGhCeXRlID0gYnVmW2kgKyAzXTsKICAgICAgICAgICAgICAgIGlmICgoc2Vjb25kQnl0ZSAmIDE5MikgPT09IDEyOCAmJiAodGhpcmRCeXRlICYgMTkyKSA9PT0gMTI4ICYmIChmb3VydGhCeXRlICYgMTkyKSA9PT0gMTI4KSB7CiAgICAgICAgICAgICAgICAgIHRlbXBDb2RlUG9pbnQgPSAoZmlyc3RCeXRlICYgMTUpIDw8IDE4IHwgKHNlY29uZEJ5dGUgJiA2MykgPDwgMTIgfCAodGhpcmRCeXRlICYgNjMpIDw8IDYgfCBmb3VydGhCeXRlICYgNjM7CiAgICAgICAgICAgICAgICAgIGlmICh0ZW1wQ29kZVBvaW50ID4gNjU1MzUgJiYgdGVtcENvZGVQb2ludCA8IDExMTQxMTIpIHsKICAgICAgICAgICAgICAgICAgICBjb2RlUG9pbnQgPSB0ZW1wQ29kZVBvaW50OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGlmIChjb2RlUG9pbnQgPT09IG51bGwpIHsKICAgICAgICAgICAgY29kZVBvaW50ID0gNjU1MzM7CiAgICAgICAgICAgIGJ5dGVzUGVyU2VxdWVuY2UgPSAxOwogICAgICAgICAgfSBlbHNlIGlmIChjb2RlUG9pbnQgPiA2NTUzNSkgewogICAgICAgICAgICBjb2RlUG9pbnQgLT0gNjU1MzY7CiAgICAgICAgICAgIHJlcy5wdXNoKGNvZGVQb2ludCA+Pj4gMTAgJiAxMDIzIHwgNTUyOTYpOwogICAgICAgICAgICBjb2RlUG9pbnQgPSA1NjMyMCB8IGNvZGVQb2ludCAmIDEwMjM7CiAgICAgICAgICB9CiAgICAgICAgICByZXMucHVzaChjb2RlUG9pbnQpOwogICAgICAgICAgaSArPSBieXRlc1BlclNlcXVlbmNlOwogICAgICAgIH0KICAgICAgICByZXR1cm4gZGVjb2RlQ29kZVBvaW50c0FycmF5KHJlcyk7CiAgICAgIH0KICAgICAgdmFyIE1BWF9BUkdVTUVOVFNfTEVOR1RIID0gNDA5NjsKICAgICAgZnVuY3Rpb24gZGVjb2RlQ29kZVBvaW50c0FycmF5KGNvZGVQb2ludHMpIHsKICAgICAgICBjb25zdCBsZW4gPSBjb2RlUG9pbnRzLmxlbmd0aDsKICAgICAgICBpZiAobGVuIDw9IE1BWF9BUkdVTUVOVFNfTEVOR1RIKSB7CiAgICAgICAgICByZXR1cm4gU3RyaW5nLmZyb21DaGFyQ29kZS5hcHBseShTdHJpbmcsIGNvZGVQb2ludHMpOwogICAgICAgIH0KICAgICAgICBsZXQgcmVzID0gIiI7CiAgICAgICAgbGV0IGkgPSAwOwogICAgICAgIHdoaWxlIChpIDwgbGVuKSB7CiAgICAgICAgICByZXMgKz0gU3RyaW5nLmZyb21DaGFyQ29kZS5hcHBseShTdHJpbmcsIGNvZGVQb2ludHMuc2xpY2UoaSwgaSArPSBNQVhfQVJHVU1FTlRTX0xFTkdUSCkpOwogICAgICAgIH0KICAgICAgICByZXR1cm4gcmVzOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGFzY2lpU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ziwgc3RhcnQsIGVuZCkgewogICAgICAgIGNvbnN0IGJ5dGVzID0gYnVmLnNsaWNlKHN0YXJ0LCBlbmQpOwogICAgICAgIGxldCByZXMgPSAiIjsKICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IGJ5dGVzLmxlbmd0aCAtIDE7IGkgKz0gMikgewogICAgICAgICAgcmVzICs9IFN0cmluZy5mcm9tQ2hhckNvZGUoYnl0ZXNbaV0gKyBieXRlc1tpICsgMV0gKiAyNTYpOwogICAgICAgIH0KICAgICAgICByZXR1cm4gcmVzOwogICAgICB9CiAgICAgIEJ1ZmZlcjEwLnByb3RvdHlwZS5zbGljZSA9IGZ1bmN0aW9uIHNsaWNlKHN0YXJ0LCBlbmQpIHsKICAgICAgICBjb25zdCBsZW4gPSB0aGlzLmxlbmd0aDsKICAgICAgICBzdGFydCA9IH5+c3RhcnQ7CiAgICAgICAgZW5kID0gZW5kID09PSB2b2lkIDAgPyBsZW4gOiB+fmVuZDsKICAgICAgICBpZiAoc3RhcnQgPCAwKSB7CiAgICAgICAgICBzdGFydCArPSBsZW47CiAgICAgICAgICBpZiAoc3RhcnQgPCAwKQogICAgICAgICAgICBzdGFydCA9IDA7CiAgICAgICAgfSBlbHNlIGlmIChzdGFydCA+IGxlbikgewogICAgICAgICAgc3RhcnQgPSBsZW47CiAgICAgICAgfQogICAgICAgIGlmIChlbmQgPCAwKSB7CiAgICAgICAgICBlbmQgKz0gbGVuOwogICAgICAgICAgaWYgKGVuZCA8IDApCiAgICAgICAgICAgIGVuZCA9IDA7CiAgICAgICAgfSBlbHNlIGlmIChlbmQgPiBsZW4pIHsKICAgICAgICAgIGVuZCA9IGxlbjsKICAgICAgICB9CiAgICAgICAgaWYgKGVuZCA8IHN0YXJ0KQogICAgICAgICAgZW5kID0gc3RhcnQ7CiAgICAgICAgY29uc3QgbmV3QnVmID0gdGhpcy5zdWJhcnJheShzdGFydCwgZW5kKTsKICAgICAgICBPYmplY3Quc2V0UHJvdG90eXBlT2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tvZmZzZXQgKyAtLWldICogbXVsOwogICAgICAgIH0KICAgICAgICBtdWwgKj0gMTI4OwogICAgICAgIGlmICh2YWwgPj0gbXVsKQogICAgICAgICAgdmFsIC09IE1hdGgucG93KDIsIDggKiBieXRlTGVuZ3RoMik7CiAgICAgICAgcmV0dXJuIHZhbDsKICAgICAgfTsKICAgICAgQnVmZmVyMTAucHJvdG90eXBlLnJlYWRJbnQ4ID0gZnVuY3Rpb24gcmVhZEludDgob2Zmc2V0LCBub0Fzc2VydCkgewogICAgICAgIG9mZnNldCA9IG9mZnNldCA+Pj4gMDsKICAgICAgICBpZiAoIW5vQXNzZXJ0KQogICAgICAgICAgY2hlY2tPZmZzZXQob2Zmc2V0LCAxLCB0aGlzLmxlbmd0aCk7CiAgICAgICAgaWYgKCEodGhpc1tvZmZzZXRdICYgMTI4KSkKICAgICAgICAgIHJldHVybiB0aGlzW29mZnNldF07CiAgICAgICAgcmV0dXJuICgyNTUgLSB0aGlzW29mZnNldF0gKyAxKSAqIC0xOwogICAgICB9OwogICAgICBCdWZmZXIxMC5wcm90b3R5cGUucmVhZEludDE2TEUgPSBmdW5jdGlvbiByZWFkSW50MTZMRShvZmZzZXQsIG5vQXNzZXJ0KSB7CiAgICAgICAgb2Zmc2V0ID0gb2Zmc2V0ID4+PiAwOwogICAgICAgIGlmICghbm9Bc3NlcnQpCiAgICAgICAgICBjaGVja09mZnNldChvZmZzZXQsIDIsIHRoaXMubGVuZ3RoKTsKICAgICAgICBjb25zdCB2YWwgPSB0aGlzW29mZnNldF0gfCB0aGlzW29mZnNldCArIDFdIDw8IDg7CiAgICAgICAgcmV0dXJuIHZhbCAmIDMyNzY4ID8gdmFsIHwgNDI5NDkwMTc2MCA6IHZhbDsKICAgICAgfTsKICAgICAgQnVmZmVyMTAucHJvdG90eXBlLnJlYWRJbnQxNkJFID0gZnVuY3Rpb24gcmVhZEludDE2QkUob2Zmc2V0LCBub0Fzc2VydCkgewogICAgICAgIG9mZnNldCA9IG9mZnN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aXMuY29weVdpdGhpbih0YXJnZXRTdGFydCwgc3RhcnQsIGVuZCk7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIFVpbnQ4QXJyYXkucHJvdG90eXBlLnNldC5jYWxsKHRhcmdldCwgdGhpcy5zdWJhcnJheShzdGFydCwgZW5kKSwgdGFyZ2V0U3RhcnQpOwogICAgICAgIH0KICAgICAgICByZXR1cm4gbGVuOwogICAgICB9OwogICAgICBCdWZmZXIxMC5wcm90b3R5cGUuZmlsbCA9IGZ1bmN0aW9uIGZpbGwodmFsLCBzdGFydCwgZW5kLCBlbmNvZGluZykgewogICAgICAgIGlmICh0eXBlb2YgdmFsID09PSAic3RyaW5nIikgewogICAgICAgICAgaWYgKHR5cGVvZiBzdGFydCA9PT0gInN0cmluZyIpIHsKICAgICAgICAgICAgZW5jb2RpbmcgPSBzdGFydDsKICAgICAgICAgICAgc3RhcnQgPSAwOwogICAgICAgICAgICBlbmQgPSB0aGlzLmxlbmd0aDsKICAgICAgICAgIH0gZWxzZSBpZiAodHlwZW9mIGVuZCA9PT0gInN0cmluZyIpIHsKICAgICAgICAgICAgZW5jb2RpbmcgPSBlbmQ7CiAgICAgICAgICAgIGVuZCA9IHRoaXMubGVuZ3RoOwogICAgICAgICAgfQogICAgICAgICAgaWYgKGVuY29kaW5nICE9PSB2b2lkIDAgJiYgdHlwZW9mIGVuY29kaW5nICE9PSAic3RyaW5nIikgewogICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCJlbmNvZGluZyBtdXN0IGJlIGEgc3RyaW5nIik7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAodHlwZW9mIGVuY29kaW5nID09PSAic3RyaW5nIiAmJiAhQnVmZmVyMTAuaXNFbmNvZGluZyhlbmNvZGluZykpIHsKICAgICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcigiVW5rbm93biBlbmNvZGluZzogIiArIGVuY29kaW5nKTsKICAgICAgICAgIH0KICAgICAgICAgIGlmICh2YWwubGVuZ3RoID09PSAxKSB7CiAgICAgICAgICAgIGNvbnN0IGNvZGUgPSB2YWwuY2hhckNvZGVBdCgwKTsKICAgICAgICAgICAgaWYgKGVuY29kaW5nID09PSAidXRmOCIgJiYgY29kZSA8IDEyOCB8fCBlbmNvZGluZyA9PT0gImxhdGluMSIpIHsKICAgICAgICAgICAgICB2YWwgPSBjb2RlOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfSBlbHNlIGlmICh0eXBlb2YgdmFsID09PSAibnVtYmVyIikgewogICAgICAgICAgdmFsID0gdmFsICYgMjU1OwogICAgICAgIH0gZWxzZSBpZiAodHlwZW9mIHZhbCA9PT0gImJvb2xlYW4iKSB7CiAgICAgICAgICB2YWwgPSBOdW1iZXIodmFsKTsKICAgICAgICB9CiAgICAgICAgaWYgKHN0YXJ0IDwgMCB8fCB0aGlzLmxlbmd0aCA8IHN0YXJ0IHx8IHRoaXMubGVuZ3RoIDwgZW5kKSB7CiAgICAgICAgICB0aHJvdyBuZXcgUmFuZ2VFcnJvcigiT3V0IG9mIHJhbmdlIGluZGV4Iik7CiAgICAgICAgfQogICAgICAgIGlmIChlbmQgPD0gc3RhcnQpIHsKICAgICAgICAgIHJldHVybiB0aGlzOwogICAgICAgIH0KICAgICAgICBzdGFydCA9IHN0YXJ0ID4+PiAwOwogICAgICAgIGVuZCA9IGVuZCA9PT0gdm9pZCAwID8gdGhpcy5sZW5ndGggOiBlbmQgPj4+IDA7CiAgICAgICAgaWYgKCF2YWwpCiAgICAgICAgICB2YWwgPSAwOwogICAgICAgIGxldCBpOwogICAgICAgIGlmICh0eXBlb2YgdmFsID09PSAibnVtYmVyIikgewogICAgICAgICAgZm9yIChpID0gc3RhcnQ7IGkgPCBlbmQ7ICsraSkgewogICAgICAgICAgICB0aGlzW2ldID0gdmFsOwogICAgICAgICAgfQogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBjb25zdCBieXRlcyA9IEJ1ZmZlcjEwLmlzQnVmZmVyKHZhbCkgPyB2YWwgOiBCdWZmZXIxMC5mcm9tKHZhbCwgZW5jb2RpbmcpOwogICAgICAgICAgY29uc3QgbGVuID0gYnl0ZXMubGVuZ3RoOwogICAgICAgICAgaWYgKGxlbiA9PT0gMCkgewogICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCdUaGUgdmFsdWUgIicgKyB2YWwgKyAnIiBpcyBpbnZhbGlkIGZvciBhcmd1bWVudCAidmFsdWUiJyk7CiAgICAgICAgICB9CiAgICAgICAgICBmb3IgKGkgPSAwOyBpIDwgZW5kIC0gc3RhcnQ7ICsraSkgewogICAgICAgICAgICB0aGlzW2kgKyBzdGFydF0gPSBieXRlc1tpICUgbGVuXTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIHRoaXM7CiAgICAgIH07CiAgICAgIHZhciBlcnJvcnMgPSB7fTsKICAgICAgZnVuY3Rpb24gRShzeW0sIGdldE1lc3NhZ2UsIEJhc2UpIHsKICAgICAgICBlcnJvcnNbc3ltXSA9IGNsYXNzIE5vZGVFcnJvciBleHRlbmRzIEJhc2UgewogICAgICAgICAgY29uc3RydWN0b3IoKSB7CiAgICAgICAgICAgIHN1cGVyKCk7CiAgICAgICAgICAgIE9iamVjdC5kZWZpbmVQcm9wZXJ0eSh0aGlzLCAibWVzc2FnZSIsIHsKICAgICAgICAgICAgICB2YWx1ZTogZ2V0TWVzc2FnZS5hcHBseSh0aGlzLCBhcmd1bWVudHMpLAogICAgICAgICAgICAgIHdyaXRhYmxlOiB0cnVlLAogICAgICAgICAgICAgIGNvbmZpZ3VyYWJsZTogdHJ1ZQogICAgICAgICAgICB9KTsKICAgICAgICAgICAgdGhpcy5uYW1lID0gYCR7dGhpcy5uYW1lfSBbJHtzeW19XWA7CiAgICAgICAgICAgIHRoaXMuc3RhY2s7CiAgICAgICAgICAgIGRlbGV0ZSB0aGlzLm5hbWU7CiAgICAgICAgICB9CiAgICAgICAgICBnZXQgY29kZSgpIHsKICAgICAgICAgICAgcmV0dXJuIHN5bTsKICAgICAgICAgIH0KICAgICAgICAgIHNldCBjb2RlKHZhbHVlKSB7CiAgICAgICAgICAgIE9iamVjdC5kZWZpbmVQcm9wZXJ0eSh0aGlzLCAiY29kZSIsIHsKICAgICAgICAgICAgICBjb25maWd1cmFibGU6IHRydWUsCiAgICAgICAgICAgICAgZW51bWVyYWJsZTogdHJ1ZSwKICAgICAgICAgICAgICB2YWx1ZSwKICAgICAgICAgICAgICB3cml0YWJsZTogdHJ1ZQogICAgICAgICAgICB9KTsKICAgICAgICAgIH0KICAgICAgICAgIHRvU3RyaW5nKCkgewogICAgICAgICAgICByZXR1cm4gYCR7dGhpcy5uYW1lfSBbJHtzeW19XTogJHt0aGlzLm1lc3NhZ2V9YDsKICAgICAgICAgIH0KICAgICAgICB9OwogICAgICB9CiAgICAgIEUoIkVSUl9CVUZGRVJfT1VUX09GX0JPVU5EUyIsIGZ1bmN0aW9uKG5hbWUpIHsKICAgICAgICBpZiAobmFtZSkgewogICAgICAgICAgcmV0dXJuIGAke25hbWV9IGlzIG91dHNpZGUgb2YgYnVmZmVyIGJvdW5kc2A7CiAgICAgICAgfQogICAgICAgIHJldHVybiAiQXR0ZW1wdCB0byBhY2Nlc3MgbWVtb3J5IG91dHNpZGUgYnVmZmVyIGJvdW5kcyI7CiAgICAgIH0sIFJhbmdlRXJyb3IpOwogICAgICBFKCJFUlJfSU5WQUxJRF9BUkdfVFlQRSIsIGZ1bmN0aW9uKG5hbWUsIGFjdHVhbCkgewogICAgICAgIHJldHVybiBgVGhlICIke25hbWV9IiBhcmd1bWVudCBtdXN0IGJlIG9mIHR5cGUgbnVtYmVyLiBSZWNlaXZlZCB0eXBlICR7dHlwZW9mIGFjdHVhbH1gOwogICAgICB9LCBUeXBlRXJyb3IpOwogICAgICBFKCJFUlJfT1VUX09GX1JBTkdFIiwgZnVuY3Rpb24oc3RyLCByYW5nZSwgaW5wdXQpIHsKICAgICAgICBsZXQgbXNnID0gYFRoZSB2Y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c2xpY2UoMCwgaSl9JHtyZXN9YDsKICAgICAgfQogICAgICBmdW5jdGlvbiBjaGVja0JvdW5kcyhidWYsIG9mZnNldCwgYnl0ZUxlbmd0aDIpIHsKICAgICAgICB2YWxpZGF0ZU51bWJlcihvZmZzZXQsICJvZmZzZXQiKTsKICAgICAgICBpZiAoYnVmW29mZnNldF0gPT09IHZvaWQgMCB8fCBidWZbb2Zmc2V0ICsgYnl0ZUxlbmd0aDJdID09PSB2b2lkIDApIHsKICAgICAgICAgIGJvdW5kc0Vycm9yKG9mZnNldCwgYnVmLmxlbmd0aCAtIChieXRlTGVuZ3RoMiArIDEpKTsKICAgICAgICB9CiAgICAgIH0KICAgICAgZnVuY3Rpb24gY2hlY2tJbnRCSSh2YWx1ZSwgbWluLCBtYXgsIGJ1Ziwgb2Zmc2V0LCBieXRlTGVuZ3RoMikgewogICAgICAgIGlmICh2YWx1ZSA+IG1heCB8fCB2YWx1ZSA8IG1pbikgewogICAgICAgICAgY29uc3QgbiA9IHR5cGVvZiBtaW4gPT09ICJiaWdpbnQiID8gIm4iIDogIiI7CiAgICAgICAgICBsZXQgcmFuZ2U7CiAgICAgICAgICBpZiAoYnl0ZUxlbmd0aDIgPiAzKSB7CiAgICAgICAgICAgIGlmIChtaW4gPT09IDAgfHwgbWluID09PSBCaWdJbnQoMCkpIHsKICAgICAgICAgICAgICByYW5nZSA9IGA+PSAwJHtufSBhbmQgPCAyJHtufSAqKiAkeyhieXRlTGVuZ3RoMiArIDEpICogOH0ke259YDsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICByYW5nZSA9IGA+PSAtKDIke259ICoqICR7KGJ5dGVMZW5ndGgyICsgMSkgKiA4IC0gMX0ke259KSBhbmQgPCAyICoqICR7KGJ5dGVMZW5ndGgyICsgMSkgKiA4IC0gMX0ke259YDsKICAgICAgICAgICAgfQogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcmFuZ2UgPSBgPj0gJHttaW59JHtufSBhbmQ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AgIGZ1bmN0aW9uIGJhc2U2NGNsZWFuKHN0cikgewogICAgICAgIHN0ciA9IHN0ci5zcGxpdCgiPSIpWzBdOwogICAgICAgIHN0ciA9IHN0ci50cmltKCkucmVwbGFjZShJTlZBTElEX0JBU0U2NF9SRSwgIiIpOwogICAgICAgIGlmIChzdHIubGVuZ3RoIDwgMikKICAgICAgICAgIHJldHVybiAiIjsKICAgICAgICB3aGlsZSAoc3RyLmxlbmd0aCAlIDQgIT09IDApIHsKICAgICAgICAgIHN0ciA9IHN0ciArICI9IjsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHN0cjsKICAgICAgfQogICAgICBmdW5jdGlvbiB1dGY4VG9CeXRlcyhzdHJpbmcsIHVuaXRzKSB7CiAgICAgICAgdW5pdHMgPSB1bml0cyB8fCBJbmZpbml0eTsKICAgICAgICBsZXQgY29kZVBvaW50OwogICAgICAgIGNvbnN0IGxlbmd0aCA9IHN0cmluZy5sZW5ndGg7CiAgICAgICAgbGV0IGxlYWRTdXJyb2dhdGUgPSBudWxsOwogICAgICAgIGNvbnN0IGJ5dGVzID0gW107CiAgICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCBsZW5ndGg7ICsraSkgewogICAgICAgICAgY29kZVBvaW50ID0gc3RyaW5nLmNoYXJDb2RlQXQoaSk7CiAgICAgICAgICBpZiAoY29kZVBvaW50ID4gNTUyOTUgJiYgY29kZVBvaW50IDwgNTczNDQpIHsKICAgICAgICAgICAgaWYgKCFsZWFkU3Vycm9nYXRlKSB7CiAgICAgICAgICAgICAgaWYgKGNvZGVQb2ludCA+IDU2MzE5KSB7CiAgICAgICAgICAgICAgICBpZiAoKHVuaXRzIC09IDMpID4gLTEpCiAgICAgICAgICAgICAgICAgIGJ5dGVzLnB1c2goMjM5LCAxOTEsIDE4OSk7CiAgICAgICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgICAgICB9IGVsc2UgaWYgKGkgKyAxID09PSBsZW5ndGgpIHsKICAgICAgICAgICAgICAgIGlmICgodW5pdHMgLT0gMykgPiAtMSkKICAgICAgICAgICAgICAgICAgYnl0ZXMucHVzaCgyMzksIDE5MSwgMTg5KTsKICAgICAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBsZWFkU3Vycm9nYXRlID0gY29kZVBvaW50OwogICAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChjb2RlUG9pbnQgPCA1NjMyMCkgewogICAgICAgICAgICAgIGlmICgodW5pdHMgLT0gMykgPiAtMSkKICAgICAgICAgICAgICAgIGJ5dGVzLnB1c2goMjM5LCAxOTEsIDE4OSk7CiAgICAgICAgICAgICAgbGVhZFN1cnJvZ2F0ZSA9IGNvZGVQb2ludDsKICAgICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgICAgfQogICAgICAgICAgICBjb2RlUG9pbnQgPSAobGVhZFN1cnJvZ2F0ZSAtIDU1Mjk2IDw8IDEwIHwgY29kZVBvaW50IC0gNTYzMjApICsgNjU1MzY7CiAgICAgICAgICB9IGVsc2UgaWYgKGxlYWRTdXJyb2dhdGUpIHsKICAgICAgICAgICAgaWYgKCh1bml0cyAtPSAzKSA+IC0xKQogICAgICAgICAgICAgIGJ5dGVzLnB1c2goMjM5LCAxOTEsIDE4OSk7CiAgICAgICAgICB9CiAgICAgICAgICBsZWFkU3Vycm9nYXRlID0gbnVsbDsKICAgICAgICAgIGlmIChjb2RlUG9pbnQgPCAxMjgpIHsKICAgICAgICAgICAgaWYgKCh1bml0cyAtPSAxKSA8IDApCiAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIGJ5dGVzLnB1c2goY29kZVBvaW50KTsKICAgICAgICAgIH0gZWxzZSBpZiAoY29kZVBvaW50IDwgMjA0OCkgewogICAgICAgICAgICBpZiAoKHVuaXRzIC09IDIpIDwgMCkKICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgYnl0ZXMucHVzaChjb2RlUG9pbnQgPj4gNiB8IDE5MiwgY29kZVBvaW50ICYgNjMgfCAxMjgpOwogICAgICAgICAgfSBlbHNlIGlmIChjb2RlUG9pbnQgPCA2NTUzNikgewogICAgICAgICAgICBpZiAoKHVuaXRzIC09IDMpIDwgMCkKICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgYnl0ZXMucHVzaChjb2RlUG9pbnQgPj4gMTIgfCAyMjQsIGNvZGVQb2ludCA+PiA2ICYgNjMgfCAxMjgsIGNvZGVQb2ludCAmIDYzIHwgMTI4KTsKICAgICAgICAgIH0gZWxzZSBpZiAoY29kZVBvaW50IDwgMTExNDExMikgewogICAgICAgICAgICBpZiAoKHVuaXRzIC09IDQpIDwgMCkKICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgYnl0ZXMucHVzaChjb2RlUG9pbnQgPj4gMTggfCAyNDAsIGNvZGVQb2ludCA+PiAxMiAmIDYzIHwgMTI4LCBjb2RlUG9pbnQgPj4gNiAmIDYzIHwgMTI4LCBjb2RlUG9pbnQgJiA2MyB8IDEyOCk7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IoIkludmFsaWQgY29kZSBwb2ludCIpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gYnl0ZXM7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gYXNjaWlUb0J5dGVzKHN0cikgewogICAgICAgIGNvbnN0IGJ5dGVBcnJheSA9IFtdOwogICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgc3RyLmxlbmd0aDsgKytpKSB7CiAgICAgICAgICBieXRlQXJyYXkucHVzaChzdHIuY2hhckNvZGVBdChpKSAmIDI1NSk7CiAgICAgICAgfQogICAgICAgIHJldHVybiBieXRlQXJyYXk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gdXRmMTZsZVRvQnl0ZXMoc3RyLCB1bml0cykgewogICAgICAgIGxldCBjLCBoaSwgbG87CiAgICAgICAgY29uc3QgYnl0ZUFycmF5ID0gW107CiAgICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCBzdHIubGVuZ3RoOyArK2kpIHsKICAgICAgICAgIGlmICgodW5pdHMgLT0gMikgPCAwKQogICAgICAgICAgICBicmVhazsKICAgICAgICAgIGMgPSBzdHIuY2hhckNvZGVBdChpKTsKICAgICAgICAgIGhpID0gYyA+PiA4OwogICAgICAgICAgbG8gPSBjICUgMjU2OwogICAgICAgICAgYnl0ZUFycmF5LnB1c2gobG8pOwogICAgICAgICAgYnl0ZUFycmF5LnB1c2goaGkpOwogICAgICAgIH0KICAgICAgICByZXR1cm4gYnl0ZUFycmF5OwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGJhc2U2NFRvQnl0ZXMoc3RyKSB7CiAgICAgICAgcmV0dXJuIGJhc2U2NC50b0J5dGVBcnJheShiYXNlNjRjbGVhbihzdHIpKTsKICAgICAgfQogICAgICBmdW5jdGlvbiBibGl0QnVmZmVyKHNyYywgZHN0LCBvZmZzZXQsIGxlbmd0aCkgewogICAgICAgIGxldCBpOwogICAgICAgIGZvciAoaSA9IDA7IGkgPCBsZW5ndGg7ICsraSkgewogICAgICAgICAgaWYgKGkgKyBvZmZzZXQgPj0gZHN0Lmxlbmd0aCB8fCBpID49IHNyYy5sZW5ndGgpCiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgZHN0W2kgKyBvZmZzZXRdID0gc3JjW2ldOwogICAgICAgIH0KICAgICAgICByZXR1cm4gaTsKICAgICAgfQogICAgICBmdW5jdGlvbiBpc0luc3RhbmNlKG9iaiwgdHlwZSkgewogICAgICAgIHJldHVybiBvYmogaW5zdGFuY2VvZiB0eXBlIHx8IG9iaiAhPSBudWxsICYmIG9iai5jb25zdHJ1Y3RvciAhPSBudWxsICYmIG9iai5jb25zdHJ1Y3Rvci5uYW1lICE9IG51bGwgJiYgb2JqLmNvbnN0cnVjdG9yLm5hbWUgPT09IHR5cGUubmFtZTsKICAgICAgfQogICAgICBmdW5jdGlvbiBudW1iZXJJc05hTihvYmopIHsKICAgICAgICByZXR1cm4gb2JqICE9PSBvYmo7CiAgICAgIH0KICAgICAgdmFyIGhleFNsaWNlTG9va3VwVGFibGUgPSBmdW5jdGlvbigpIHsKICAgICAgICBjb25zdCBhbHBoYWJldCA9ICIwMTIzNDU2Nzg5YWJjZGVmIjsKICAgICAgICBjb25zdCB0YWJsZSA9IG5ldyBBcnJheSgyNTYpOwogICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgMTY7ICsraSkgewogICAgICAgICAgY29uc3QgaTE2ID0gaSAqIDE2OwogICAgICAgICAgZm9yIChsZXQgaiA9IDA7IGogPCAxNjsgKytqKSB7CiAgICAgICAgICAgIHRhYmxlW2kxNiArIGpdID0gYWxwaGFiZXRbaV0gKyBhbHBoYWJldFtqXTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIHRhYmxlOwogICAgICB9KCk7CiAgICAgIGZ1bmN0aW9uIGRlZmluZUJpZ0ludE1ldGhvZChmbikgewogICAgICAgIHJldHVybiB0eXBlb2YgQmlnSW50ID09PSAidW5kZWZpbmVkIiA/IEJ1ZmZlckJpZ0ludE5vdERlZmluZWQgOiBmbjsKICAgICAgfQogICAgICBmdW5jdGlvbiBCdWZmZXJCaWdJbnROb3REZWZpbmVkKCkgewogICAgICAgIHRocm93IG5ldyBFcnJvcigiQmlnSW50IG5vdCBzdXBwb3J0ZWQiKTsKICAgICAgfQogICAgfQogIH0pOwoKICAvLyBzcmMvYWxpYXMvYnVmZmVyLXNoaW0uanMKICB2YXIgaW1wb3J0X2J1ZmZlcjsKICB2YXIgaW5pdF9idWZmZXJfc2hpbSA9IF9fZXNtKHsKICAgICJzcmMvYWxpYXMvYnVmZmVyLXNoaW0uanMiKCkgewogICAgICBpbXBvcnRfYnVmZmVyID0gX190b01vZHVsZShyZXF1aXJlX2J1ZmZlcigpKTsKICAgIH0KICB9KTsKCiAgLy8gbm9kZV9tb2R1bGVzLy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ydWN0b3I6IHsKICAgICAgICAgICAgdmFsdWU6IHN1YkNsYXNzLAogICAgICAgICAgICB3cml0YWJsZTogdHJ1ZSwKICAgICAgICAgICAgY29uZmlndXJhYmxlOiB0cnVlCiAgICAgICAgICB9CiAgICAgICAgfSk7CiAgICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KHN1YkNsYXNzLCAicHJvdG90eXBlIiwgewogICAgICAgICAgd3JpdGFibGU6IGZhbHNlCiAgICAgICAgfSk7CiAgICAgICAgaWYgKHN1cGVyQ2xhc3MpCiAgICAgICAgICBfc2V0UHJvdG90eXBlT2Yoc3ViQ2xhc3MsIHN1cGVyQ2xhc3MpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIF9nZXRQcm90b3R5cGVPZihvKSB7CiAgICAgICAgX2dldFByb3RvdHlwZU9mID0gT2JqZWN0LnNldFByb3RvdHlwZU9mID8gT2JqZWN0LmdldFByb3RvdHlwZU9mLmJpbmQoKSA6IGZ1bmN0aW9uIF9nZXRQcm90b3R5cGVPZjIobzIpIHsKICAgICAgICAgIHJldHVybiBvMi5fX3Byb3RvX18gfHwgT2JqZWN0LmdldFByb3RvdHlwZU9mKG8yKTsKICAgICAgICB9OwogICAgICAgIHJldHVybiBfZ2V0UHJvdG90eXBlT2Yobyk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gX3NldFByb3RvdHlwZU9mKG8sIHApIHsKICAgICAgICBfc2V0UHJvdG90eXBlT2YgPSBPYmplY3Quc2V0UHJvdG90eXBlT2YgPyBPYmplY3Quc2V0UHJvdG90eXBlT2YuYmluZCgpIDogZnVuY3Rpb24gX3NldFByb3RvdHlwZU9mMihvMiwgcDIpIHsKICAgICAgICAgIG8yLl9fcHJvdG9fXyA9IHAyOwogICAgICAgICAgcmV0dXJuIG8yOwogICAgICAgIH07CiAgICAgICAgcmV0dXJuIF9zZXRQcm90b3R5cGVPZihvLCBwKTsKICAgICAgfQogICAgICBmdW5jdGlvbiBfaXNOYXRpdmVSZWZsZWN0Q29uc3RydWN0KCkgewogICAgICAgIGlmICh0eXBlb2YgUmVmbGVjdCA9PT0gInVuZGVmaW5lZCIgfHwgIVJlZmxlY3QuY29uc3RydWN0KQogICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICAgIGlmIChSZWZsZWN0LmNvbnN0cnVjdC5zaGFtKQogICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICAgIGlmICh0eXBlb2YgUHJveHkgPT09ICJmdW5jdGlvbiIpCiAgICAgICAgICByZXR1cm4gdHJ1ZTsKICAgICAgICB0cnkgewogICAgICAgICAgQm9vbGVhbi5wcm90b3R5cGUudmFsdWVPZi5jYWxsKFJlZmxlY3QuY29uc3RydWN0KEJvb2xlYW4sIFtdLCBmdW5jdGlvbigpIHsKICAgICAgICAgIH0pKTsKICAgICAgICAgIHJldHVybiB0cnVlOwogICAgICAgIH0gY2F0Y2ggKGUpIHsKICAgICAgICAgIHJldHVybiBmYWxzZTsKICAgICAgICB9CiAgICAgIH0KICAgICAgZnVuY3Rpb24gX2Fzc2VydFRoaXNJbml0aWFsaXplZChzZWxmMikgewogICAgICAgIGlmIChzZWxmMiA9PT0gdm9pZCAwKSB7CiAgICAgICAgICB0aHJvdyBuZXcgUmVmZXJlbmNlRXJyb3IoInRoaXMgaGFzbid0IGJlZW4gaW5pdGlhbGlzZWQgLSBzdXBlcigpIGhhc24ndCBiZWVuIGNhbGxlZCIpOwogICAgICAgIH0KICAgICAgICByZXR1cm4gc2VsZjI7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gX3Bvc3NpYmxlQ29uc3RydWN0b3JSZXR1cm4oc2VsZjIsIGNhbGwpIHsKICAgICAgICBpZiAoY2FsbCAmJiAodHlwZW9mIGNhbGwgPT09ICJvYmplY3QiIHx8IHR5cGVvZiBjYWxsID09PSAiZnVuY3Rpb24iKSkgewogICAgICAgICAgcmV0dXJuIGNhbGw7CiAgICAgICAgfSBlbHNlIGlmIChjYWxsICE9PSB2b2lkIDApIHsKICA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WN0ID0gX2dldFByb3RvdHlwZU9mKG9iamVjdCk7CiAgICAgICAgICBpZiAob2JqZWN0ID09PSBudWxsKQogICAgICAgICAgICBicmVhazsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIG9iamVjdDsKICAgICAgfQogICAgICBmdW5jdGlvbiBfZ2V0KCkgewogICAgICAgIGlmICh0eXBlb2YgUmVmbGVjdCAhPT0gInVuZGVmaW5lZCIgJiYgUmVmbGVjdC5nZXQpIHsKICAgICAgICAgIF9nZXQgPSBSZWZsZWN0LmdldC5iaW5kKCk7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIF9nZXQgPSBmdW5jdGlvbiBfZ2V0Mih0YXJnZXQsIHByb3BlcnR5LCByZWNlaXZlcikgewogICAgICAgICAgICB2YXIgYmFzZSA9IF9zdXBlclByb3BCYXNlKHRhcmdldCwgcHJvcGVydHkpOwogICAgICAgICAgICBpZiAoIWJhc2UpCiAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICB2YXIgZGVzYyA9IE9iamVjdC5nZXRPd25Qcm9wZXJ0eURlc2NyaXB0b3IoYmFzZSwgcHJvcGVydHkpOwogICAgICAgICAgICBpZiAoZGVzYy5nZXQpIHsKICAgICAgICAgICAgICByZXR1cm4gZGVzYy5nZXQuY2FsbChhcmd1bWVudHMubGVuZ3RoIDwgMyA/IHRhcmdldCA6IHJlY2VpdmVyKTsKICAgICAgICAgICAgfQogICAgICAgICAgICByZXR1cm4gZGVzYy52YWx1ZTsKICAgICAgICAgIH07CiAgICAgICAgfQogICAgICAgIHJldHVybiBfZ2V0LmFwcGx5KHRoaXMsIGFyZ3VtZW50cyk7CiAgICAgIH0KICAgICAgdmFyIEVtaXR0ZXIgPSAvKiBAX19QVVJFX18gKi8gZnVuY3Rpb24oKSB7CiAgICAgICAgZnVuY3Rpb24gRW1pdHRlcjIoKSB7CiAgICAgICAgICBfY2xhc3NDYWxsQ2hlY2sodGhpcywgRW1pdHRlcjIpOwogICAgICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KHRoaXMsICJsaXN0ZW5lcnMiLCB7CiAgICAgICAgICAgIHZhbHVlOiB7fSwKICAgICAgICAgICAgd3JpdGFibGU6IHRydWUsCiAgICAgICAgICAgIGNvbmZpZ3VyYWJsZTogdHJ1ZQogICAgICAgICAgfSk7CiAgICAgICAgfQogICAgICAgIF9jcmVhdGVDbGFzcyhFbWl0dGVyMiwgW3sKICAgICAgICAgIGtleTogImFkZEV2ZW50TGlzdGVuZXIiLAogICAgICAgICAgdmFsdWU6IGZ1bmN0aW9uIGFkZEV2ZW50TGlzdGVuZXIodHlwZSwgY2FsbGJhY2ssIG9wdGlvbnMpIHsKICAgICAgICAgICAgaWYgKCEodHlwZSBpbiB0aGlzLmxpc3RlbmVycykpIHsKICAgICAgICAgICAgICB0aGlzLmxpc3RlbmVyc1t0eXBlXSA9IFtdOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHRoaXMubGlzdGVuZXJzW3R5cGVdLnB1c2goewogICAgICAgICAgICAgIGNhbGxiYWNrLAogICAgICAgICAgICAgIG9wdGlvbnMKICAgICAgICAgICAgfSk7CiAgICAgICAgICB9CiAgICAgICAgfSwgewogICAgICAgICAga2V5OiAicmVtb3ZlRXZlbnRMaXN0ZW5lciIsCiAgICAgICAgICB2YWx1ZTogZnVuY3Rpb24gcmVtb3ZlRXZlbnRMaXN0ZW5lcih0eXBlLCBjYWxsYmFjaykgewogICAgICAgICAgICBpZiAoISh0eXBlIGluIHRoaXMubGlzdGVuZXJzKSkgewogICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgfQogICAgICAgICAgICB2YXIgc3RhY2sgPSB0aGlzLmxpc3RlbmVyc1t0eXBlXTsKICAgICAgICAgICAgZm9yICh2YXIgaSA9IDAsIGwgPSBzdGFjay5sZW5ndGg7IGkgPCBsOyBpKyspIHsKICAgICAgICAgICAgICBpZiAoc3RhY2tbaV0uY2FsbGJhY2sgPT09IGNhbGxiYWNrKSB7CiAgICAgICAgICAgICAgICBzdGFjay5zcGxpY2UoaSwgMSk7CiAgICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfSwgewogICAgICAgICAga2V5OiAiZGlzcGF0Y2hFdmVudCIsCiAgICAgICAgICB2YWx1ZTogZnVuY3Rpb24gZGlzcGF0Y2hFdmVudChldmVudCkgewogICAgICAgICAgICBpZiAoIShldmVudC50eXBlIGluIHRoaXMubGlzdGVuZXJzKSkgewogICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgfQogICAgICAgICAgICB2YXIgc3RhY2sgPSB0aGlzLmxpc3RlbmVyc1tldmVudC50eXBlXTsKICAgICAgICAgICAgdmFyIHN0YWNrVG9DYWxsID0gc3RhY2suc2xpY2UoKTsKICAgICAgICAgICAgZm9yICh2YXIgaSA9IDAsIGwgPSBzdGFja1RvQ2FsbC5sZW5ndGg7IGkgPCBsOyBpKyspIHsKICAgICAgICAgICAgICB2YXIgbGlzdGVuZXIgPSBzdGFja1RvQ2FsbFtpXTsKICAgICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgICAgbGlzdGVuZXIuY2FsbGJhY2suY2FsbCh0aGlzLCBldmVudCk7CiAgICAgICAgICAgICAgfSBjYXRjaCAoZSkgewogICAgICAgICAgICAgICAgUHJvbWlzZS5yZXNvbHZlKCkudGhlbihmdW5jdGlvbigpIHsKICAgICAgICAgICAgICAgICAgdGhyb3cgZTsKICAgICAgICAgICAgICAgIH0pOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBpZiAobGlzdGVuZXIub3B0aW9ucyAmJiBsaXN0ZW5lci5vcHRpb25zLm9uY2UpIHsKICAgICAgICAgICAgICAgIHRoaXMucmVtb3ZlRXZlbnRMaXN0ZW5lcihldmVudC50eXBlLCBsaXN0ZW5lci5jYWxsYmFjayk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIHJldHVybiAhZXZlbnQuZGVmYXVsdFByZXZlbnRlZDsKICAgICAgICAgIH0KICAgICAgICB9XSk7CiAgICAgICAgcmV0dXJuIEVtaXR0ZXIyOwogICAgICB9KCk7CiAgICAgIHZhciBBYm9ydFNpZ25hbCA9IC8qIEBfX1BVUkVfXyAqLyBmdW5jdGlvbihfRW1pdHRlcikgewogICAgICAgIF9pbmhlcml0cyhBYm9ydFNpZ25hbDIsIF9FbWl0dGVyKTsKICAgICAgICB2YXIgX3N1cGVyID0gX2NyZWF0ZVN1cGVyKEFib3J0U2lnbmFsMik7CiAgICAgICAgZnVuY3Rpb24gQWJvcnRTaWduYWwyKCkgewogICAgICAgICAgdmFyIF90aGlzOwogICAgICAgICAgX2NsYXNzQ2FsbENoZWNrKHRoaXMsIEFib3J0U2lnbmFsMik7CiAgICAgICAgICBfdGhpcyA9IF9zdXBlci5jYWxsKHRoaXMpOwogICAgICAgICAgaWYgKCFfdGhpcy5saXN0ZW5lcnMpIHsKICAgICAgICAgICAgRW1pdHRlci5jYWxsKF9hc3NlcnRUaGlzSW5pdGlhbGl6ZWQoX3RoaXMpKTsKICAgICAgICAgIH0KICAgICAgICAgIE9iamVjdC5kZWZpbmVQcm9wZXJ0eShfYXNzZXJ0VGhpc0luaXRpYWxpemVkKF90aGlzKSwgImFib3J0ZWQiLCB7CiAgICAgICAgICAgIHZhbHVlOiBmYWxzZSwKICAgICAgICAgICAgd3JpdGFibGU6IHRydWUsCiAgICAgICAgICAgIGNvbmZpZ3VyYWJsZTogdHJ1ZQogICAgICAgICAgfSk7CiAgICAgICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkoX2Fzc2VydFRoaXNJbml0aWFsaXplZChfdGhpcyksICJvbmFib3J0IiwgewogICAgICAgICAgICB2YWx1ZTogbnVsbCwKICAgICAgICAgICAgd3JpdGFibGU6IHRydWUsCiAgICAgICAgICAgIGNvbmZpZ3VyYWJsZTogdHJ1ZQogICAgICAgICAgfSk7CiAgICAgICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkoX2Fzc2VydFRoaXNJbml0aWFsaXplZChfdGhpcyksICJyZWFzb24iLCB7CiAgICAgICAgICAgIHZhbHVlOiB2b2lkIDAsCiAgICAgICAgICAgIHdyaXRhYmxlOiB0cnVlLAogICAgICAgICAgICBjb25maWd1cmFibGU6IHRydWUKICAgICAgICAgIH0pOwogICAgICAgICAgcmV0dXJuIF90aGlzOwogICAgICAgIH0KICAgICAgICBfY3JlYXRlQ2xhc3MoQWJvcnRTaWduYWwyLCBbewogICAgICAgICAga2V5OiAidG9TdHJpbmciLAogICAgICAgICAgdmFsdWU6IGZ1bmN0aW9uIHRvU3RyaW5nKCkgewogICAgICAgICAgICByZXR1cm4gIltvYmplY3QgQWJvcnRTaWduYWxdIjsKICAgICAgICAgIH0KICAgICAgICB9LCB7CiAgICAgICAgICBrZXk6ICJkaXNwYXRjaEV2ZW50IiwKICAgICAgICAgIHZhbHVlOiBmdW5jdGlvbiBkaXNwYXRjaEV2ZW50KGV2ZW50KSB7CiAgICAgICAgICAgIGlmIChldmVudC50eXBlID09PSAiYWJvcnQiKSB7CiAgICAgICAgICAgICAgdGhpcy5hYm9ydGVkID0gdHJ1ZTsKICAgICAgICAgICAgICBpZiAodHlwZW9mIHRoaXMub25hYm9ydCA9PT0gImZ1bmN0aW9uIikgewogICAgICAgICAgICAgICAgdGhpcy5vbmFib3J0LmNhbGwodGhpcywgZXZlbnQpOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBfZ2V0KF9nZXRQcm90b3R5cGVPZihBYm9ydFNpZ25hbDIucHJvdG90eXBlKSwgImRpc3BhdGNoRXZlbnQiLCB0aGlzKS5jYWxsKHRoaXMsIGV2ZW50KTsKICAgICAgICAgIH0KICAgICAgICB9XSk7CiAgICAgICAgcmV0dXJuIEFib3J0U2lnbmFsMjsKICAgICAgfShFbWl0dGVyKTsKICAgICAgdmFyIEFib3J0Q29udHJvbGxlciA9IC8qIEBfX1BVUkVfXyAqLyBmdW5jdGlvbigpIHsKICAgICAgICBmdW5jdGlvbiBBYm9ydENvbnRyb2xsZXIyKCkgewogICAgICAgICAgX2NsYXNzQ2FsbENoZWNrKHRoaXMsIEFib3J0Q29udHJvbGxlcjIpOwogICAgICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KHRoaXMsICJzaWduYWwiLCB7CiAgICAgICAgICAgIHZhbHVlOiBuZXcgQWJvcnRTaWduYWwoKSwKICAgICAgICAgICAgd3JpdGFibGU6IHRydWUsCiAgICAgICAgICAgIGNvbmZpZ3VyYWJsZTogdHJ1ZQogICAgICAgICAgfSk7CiAgICAgICAgfQogICAgICAgIF9jcmVhdGVDbGFzcyhBYm9ydENvbnRyb2xsZXIyLCBbewogICAgICAgICAga2V5OiAiYWJvcnQiLAogICAgICAgICAgdmFsdWU6IGZ1bmN0aW9uIGFib3J0KHJlYXNvbikgewogICAgICAgICAgICB2YXIgZXZlbnQ7CiAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgZXZlbnQgPSBuZXcgRXZlbnQoImFib3J0Iik7CiAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHsKICAgICAgICAgICAgICBpZiAodHlwZW9mIGRvY3VtZW50ICE9PSAidW5kZWZpbmVkIikgewogICAgICAgICAgICAgICAgaWYgKCFkb2N1bWVudC5jcmVhdGVFdmVudCkgewogICAgICAgICAgICAgICAgICBldmVudCA9IGRvY3VtZW50LmNyZWF0ZUV2ZW50T2JqZWN0KCk7CiAgICAgICAgICAgICAgICAgIGV2ZW50LnR5cGUgPSAiYWJvcnQiOwogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgZXZlbnQgPSBkb2N1bWVudC5jcmVhdGVFdmVudCgiRXZlbnQiKTsKICAgICAgICAgICAgICAgICAgZXZlbnQuaW5pdEV2ZW50KCJhYm9ydCIsIGZhbHNlLCBmYWxzZSk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIGV2ZW50ID0gewogICAgICAgICAgICAgICAgICB0eXBlOiAiYWJvcnQiLAogICAgICAgICAgICAgICAgICBidWJibGVzOiBmYWxzZSwKICAgICAgICAgICAgICAgICAgY2FuY2VsYWJsZTogZmFsc2UKICAgICAgICAgICAgICAgIH07CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIHZhciBzaWduYWxSZWFzb24gPSByZWFzb247CiAgICAgICAgICAgIGlmIChzaWduYWxSZWFzb24gPT09IHZvaWQgMCkgewogICAgICAgICAgICAgIGlmICh0eXBlb2YgZG9jdW1lbnQgPT09ICJ1bmRlZmluZWQiKSB7CiAgICAgICAgICAgICAgICBzaWduYWxSZWFzb24gPSBuZXcgRXJyb3IoIlRoaXMgb3BlcmF0aW9uIHdhcyBhYm9ydGVkIik7CiAgICAgICAgICAgICAgICBzaWduYWxSZWFzb24ubmFtZSA9ICJBYm9ydEVycm9yIjsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICAgICAgc2lnbmFsUmVhc29uID0gbmV3IERPTUV4Y2VwdGlvbigic2lnbmFsIGlzIGFib3J0ZWQgd2l0aG91dCByZWFzb24iKTsKICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGVycikgewogICAgICAgICAgICAgICAgICBzaWduYWxSZWFzb24gPSBuZXcgRXJyb3IoIlRoaXMgb3BlcmF0aW9uIHdhcyBhYm9ydGVkIik7CiAgICAgICAgICAgICAgICAgIHNpZ25hbFJlYXNvbi5uYW1lID0gIkFib3J0RXJyb3IiOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICB0aGlzLnNpZ25hbC5yZWFzb24gPSBzaWduYWxSZWFzb247CiAgICAgICAgICAgIHRoaXMuc2lnbmFsLmRpc3BhdGNoRXZlbnQoZXZlbnQpOwogICAgICAgICAgfQogICAgICAgIH0sIHsKICAgICAg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Vlc3QKICAgICAgICAgIH07CiAgICAgICAgfQogICAgICAgIHZhciBSZXF1ZXN0ID0gTmF0aXZlUmVxdWVzdDsKICAgICAgICBpZiAoUmVxdWVzdCAmJiAhUmVxdWVzdC5wcm90b3R5cGUuaGFzT3duUHJvcGVydHkoInNpZ25hbCIpIHx8IF9fRk9SQ0VfSU5TVEFMTF9BQk9SVENPTlRST0xMRVJfUE9MWUZJTEwpIHsKICAgICAgICAgIFJlcXVlc3QgPSBmdW5jdGlvbiBSZXF1ZXN0MihpbnB1dCwgaW5pdDIpIHsKICAgICAgICAgICAgdmFyIHNpZ25hbDsKICAgICAgICAgICAgaWYgKGluaXQyICYmIGluaXQyLnNpZ25hbCkgewogICAgICAgICAgICAgIHNpZ25hbCA9IGluaXQyLnNpZ25hbDsKICAgICAgICAgICAgICBkZWxldGUgaW5pdDIuc2lnbmFsOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHZhciByZXF1ZXN0ID0gbmV3IE5hdGl2ZVJlcXVlc3QoaW5wdXQsIGluaXQyKTsKICAgICAgICAgICAgaWYgKHNpZ25hbCkgewogICAgICAgICAgICAgIE9iamVjdC5kZWZpbmVQcm9wZXJ0eShyZXF1ZXN0LCAic2lnbmFsIiwgewogICAgICAgICAgICAgICAgd3JpdGFibGU6IGZhbHNlLAogICAgICAgICAgICAgICAgZW51bWVyYWJsZTogZmFsc2UsCiAgICAgICAgICAgICAgICBjb25maWd1cmFibGU6IHRydWUsCiAgICAgICAgICAgICAgICB2YWx1ZTogc2lnbmFsCiAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgcmV0dXJuIHJlcXVlc3Q7CiAgICAgICAgICB9OwogICAgICAgICAgUmVxdWVzdC5wcm90b3R5cGUgPSBOYXRpdmVSZXF1ZXN0LnByb3RvdHlwZTsKICAgICAgICB9CiAgICAgICAgdmFyIHJlYWxGZXRjaCA9IGZldGNoOwogICAgICAgIHZhciBhYm9ydGFibGVGZXRjaCA9IGZ1bmN0aW9uIGFib3J0YWJsZUZldGNoMihpbnB1dCwgaW5pdDIpIHsKICAgICAgICAgIHZhciBzaWduYWwgPSBSZXF1ZXN0ICYmIFJlcXVlc3QucHJvdG90eXBlLmlzUHJvdG90eXBlT2YoaW5wdXQpID8gaW5wdXQuc2lnbmFsIDogaW5pdDIgPyBpbml0Mi5zaWduYWwgOiB2b2lkIDA7CiAgICAgICAgICBpZiAoc2lnbmFsKSB7CiAgICAgICAgICAgIHZhciBhYm9ydEVycm9yOwogICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgIGFib3J0RXJyb3IgPSBuZXcgRE9NRXhjZXB0aW9uKCJBYm9ydGVkIiwgIkFib3J0RXJyb3IiKTsKICAgICAgICAgICAgfSBjYXRjaCAoZXJyKSB7CiAgICAgICAgICAgICAgYWJvcnRFcnJvciA9IG5ldyBFcnJvcigiQWJvcnRlZCIpOwogICAgICAgICAgICAgIGFib3J0RXJyb3IubmFtZSA9ICJBYm9ydEVycm9yIjsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoc2lnbmFsLmFib3J0ZWQpIHsKICAgICAgICAgICAgICByZXR1cm4gUHJvbWlzZS5yZWplY3QoYWJvcnRFcnJvcik7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdmFyIGNhbmNlbGxhdGlvbiA9IG5ldyBQcm9taXNlKGZ1bmN0aW9uKF8sIHJlamVjdCkgewogICAgICAgICAgICAgIHNpZ25hbC5hZGRFdmVudExpc3RlbmVyKCJhYm9ydCIsIGZ1bmN0aW9uKCkgewogICAgICAgICAgICAgICAgcmV0dXJuIHJlamVjdChhYm9ydEVycm9yKTsKICAgICAgICAgICAgICB9LCB7CiAgICAgICAgICAgICAgICBvbmNlOiB0cnVlCiAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgIH0pOwogICAgICAgICAgICBpZiAoaW5pdDIgJiYgaW5pdDIuc2lnbmFsKSB7CiAgICAgICAgICAgICAgZGVsZXRlIGluaXQyLnNpZ25hbDsKIC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IEVycm9yKCJjYW5ub3QgYWRkIGEgc2lnbmFsLCBhbHJlYWR5IGFib3J0ZWQhIik7CiAgICAgICAgICB9CiAgICAgICAgICB0aGlzLnNpZ25hbHMuYWRkKHNpZ25hbCk7CiAgICAgICAgICBpZiAoc2lnbmFsLmFib3J0ZWQpIHsKICAgICAgICAgICAgdGhpcy5oYW5kbGVBYm9ydGVkKHNpZ25hbCk7CiAgICAgICAgICB9IGVsc2UgaWYgKHR5cGVvZiBzaWduYWwuYWRkRXZlbnRMaXN0ZW5lciA9PT0gImZ1bmN0aW9uIikgewogICAgICAgICAgICBzaWduYWwuYWRkRXZlbnRMaXN0ZW5lcigiYWJvcnQiLCAoKSA9PiB7CiAgICAgICAgICAgICAgdGhpcy5oYW5kbGVBYm9ydGVkKHNpZ25hbCk7CiAgICAgICAgICAgIH0pOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBoYW5kbGVBYm9ydGVkKHNpZ25hbCkgewogICAgICAgICAgdGhpcy5zaWduYWxzLmRlbGV0ZShzaWduYWwpOwogICAgICAgICAgaWYgKHRoaXMuc2lnbmFscy5zaXplID09PSAwKSB7CiAgICAgICAgICAgIHRoaXMuYWJvcnRDb250cm9sbGVyLmFib3J0KCk7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGdldCBzaWduYWwoKSB7CiAgICAgICAgICByZXR1cm4gdGhpcy5hYm9ydENvbnRyb2xsZXIuc2lnbmFsOwogICAgICAgIH0KICAgICAgICBhYm9ydCgpIHsKICAgICAgICAgIHRoaXMuYWJvcnRDb250cm9sbGVyLmFib3J0KCk7CiAgICAgICAgfQogICAgICB9OwogICAgICBleHBvcnRzMi5kZWZhdWx0ID0gQWdncmVnYXRlQWJvcnRDb250cm9sbGVyOwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vYWJvcnRhYmxlLXByb21pc2UtY2FjaGVAMS41LjAvbm9kZV9tb2R1bGVzL2Fib3J0YWJsZS1wcm9taXNlLWN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V4Y2VwdGlvbi5tZXNzYWdlID09PSAiRXJyb3I6IGFib3J0ZWQiOwogICAgICAgIH0KICAgICAgICBldmljdChrZXksIGVudHJ5KSB7CiAgICAgICAgICBpZiAodGhpcy5jYWNoZS5nZXQoa2V5KSA9PT0gZW50cnkpIHsKICAgICAgICAgICAgdGhpcy5jYWNoZS5kZWxldGUoa2V5KTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZmlsbChrZXksIGRhdGEsIHNpZ25hbCwgc3RhdHVzQ2FsbGJhY2spIHsKICAgICAgICAgIGNvbnN0IGFib3J0ZXIgPSBuZXcgQWdncmVnYXRlQWJvcnRDb250cm9sbGVyXzEuZGVmYXVsdCgpOwogICAgICAgICAgY29uc3Qgc3RhdHVzUmVwb3J0ZXIgPSBuZXcgQWdncmVnYXRlU3RhdHVzUmVwb3J0ZXJfMS5kZWZhdWx0KCk7CiAgICAgICAgICBzdGF0dXNSZXBvcnRlci5hZGRDYWxsYmFjayhzdGF0dXNDYWxsYmFjayk7CiAgICAgICAgICBjb25zdCBuZXdFbnRyeSA9IHsKICAgICAgICAgICAgYWJvcnRlciwKICAgICAgICAgICAgcHJvbWlzZTogdGhpcy5maWxsQ2FsbGJhY2soZGF0YSwgYWJvcnRlci5zaWduYWwsIChtZXNzYWdlKSA9PiB7CiAgICAgICAgICAgICAgc3RhdHVzUmVwb3J0ZXIuY2FsbGJhY2sobWVzc2FnZSk7CiAgICAgICAgICAgIH0pLAogICAgICAgICAgICBzZXR0bGVkOiBmYWxzZSwKICAgICAgICAgICAgc3RhdHVzUmVwb3J0ZXIsCiAgICAgICAgICAgIGdldCBhYm9ydGVkKCkgewogICAgICAgICAgICAgIHJldHVybiB0aGlzLmFib3J0ZXIuc2lnbmFsLmFib3J0ZWQ7CiAgICAgICAgICAgIH0KICAgICAgICAgIH07CiAgICAgICAgICBuZXdFbnRyeS5hYm9ydGVyLmFkZFNpZ25hbChzaWduYWwpOwogICAgICAgICAgbmV3RW50cnkuYWJvcnRlci5zaWduYWwuYWRkRXZlbnRMaXN0ZW5lcigiYWJvcnQiLCAoKSA9PiB7CiAgICAgICAgICAgIGlmICghbmV3RW50cnkuc2V0dGxlZCkgewogICAgICAgICAgICAgIHRoaXMuZXZpY3Qoa2V5LCBuZXdFbnRyeSk7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0pOwogICAgICAgICAgbmV3RW50cnkucHJvbWlzZS50aGVuKCgpID0+IHsKICAgICAgICAgICAgbmV3RW50cnkuc2V0dGxlZCA9IHRydWU7CiAgICAgICAgICB9LCAoKSA9PiB7CiAgICAgICAgICAgIG5ld0VudHJ5LnNldHRsZWQgPSB0cnVlOwogICAgICAgICAgICB0aGlzLmV2aWN0KGtleSwgbmV3RW50cnkpOwogICAgICAgICAgfSkuY2F0Y2goKGUpID0+IHsKICAgICAgICAgICAgY29uc29sZS5lcnJvcihlKTsKICAgICAgICAgICAgdGhyb3cgZTsKICAgICAgICAgIH0pOwogICAgICAgICAgdGhpcy5jYWNoZS5zZXQoa2V5LCBuZXdFbnRyeSk7CiAgICAgICAgfQogICAgICAgIHN0YXRpYyBjaGVja1NpbmdsZVByb21pc2UocHJvbWlzZSwgc2lnbmFsKSB7CiAgICAgICAgICBmdW5jdGlvbiBjaGVja0ZvclNpbmdsZUFib3J0KCkgewogICAgICAgICAgICBpZiAoc2lnbmFsICYmIHNpZ25hbC5hYm9ydGVkKSB7CiAgICAgICAgICAgICAgdGhyb3cgT2JqZWN0LmFzc2lnbihuZXcgRXJyb3IoImFib3J0ZWQiKSwgeyBjb2RlOiAiRVJSX0FCT1JURUQiIH0pOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gcHJvbWlzZS50aGVuKChyZXN1bHQpID0+IHsKICAgICAgICAgICAgY2hlY2tGb3JTaW5nbGVBYm9ydCgpOwogICAgICAgICAgICByZXR1cm4gcmVzdWx0OwogICAgICAgICAgfSwgKGVycm9yKSA9PiB7CiAgICAgICAgICAgIGNoZWNrRm9yU2luZ2xlQWJvcnQoKTsKICAgICAgICAgICAgdGhyb3cgZXJyb3I7CiAgICAgICAgICB9KTsKICAgICAgICB9CiAgICAgICAgaGFzKGtleSkgewogICAgICAgICAgcmV0dXJuIHRoaXMuY2FjaGUuaGFzKGtleSk7CiAgICAgICAgfQogICAgICAgIGdldChrZXksIGRhdGEsIHNpZ25hbCwgc3RhdHVzQ2FsbGJhY2spIHsKICAgICAgICAgIGlmICghc2lnbmFsICYmIGRhdGEgaW5zdGFuY2VvZiBhYm9ydGNvbnRyb2xsZXJfcG9ueWZpbGxfMS5BYm9ydFNpZ25hbCkgewogICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCJzZWNvbmQgZ2V0IGFyZ3VtZW50IGFwcGVhcnMgdG8gYmUgYW4gQWJvcnRTaWduYWwsIHBlcmhhcHMgeW91IG1lYW50IHRvIHBhc3MgYG51bGxgIGZvciB0aGUgZmlsbCBkYXRhPyIpOwogICAgICAgICAgfQogICAgICAgICAgY29uc3QgY2FjaGVFbnRyeSA9IHRoaXMuY2FjaGUuZ2V0KGtleSk7CiAgICAgICAgICBpZiAoY2FjaGVFbnRyeSkgewogICAgICAgICAgICBpZiAoY2FjaGVFbnRyeS5hYm9ydGVkICYmICFjYWNoZUVudHJ5LnNldHRsZWQpIHsKICAgICAgICAgICAgICB0aGlzLmV2aWN0KGtleSwgY2FjaGVFbnRyeSk7CiAgICAgICAgICAgICAgcmV0dXJuIHRoaXMuZ2V0KGtleSwgZGF0YSwgc2lnbmFsLCBzdGF0dXNDYWxsYmFjayk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKGNhY2hlRW50cnkuc2V0dGxlZCkgewogICAgICAgICAgICAgIHJldHVybiBjYWNoZUVudHJ5LnByb21pc2U7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgY2FjaGVFbnRyeS5hYm9ydGVyLmFkZFNpZ25hbChzaWduYWwpOwogICAgICAgICAgICBjYWNoZUVudHJ5LnN0YXR1c1JlcG9ydGVyLmFkZENhbGxiYWNrKHN0YXR1c0NhbGxiYWNrKTsKICAgICAgICAgICAgcmV0dXJuIEFib3J0YWJsZVByb21pc2VDYWNoZTIuY2hlY2tTaW5nbGVQcm9taXNlKGNhY2hlRW50cnkucHJvbWlzZSwgc2lnbmFsKTsKICAgICAgICAgIH0KICAgICAgICAgIHRoaXMuZmlsbChrZXksIGRhdGEsIHNpZ25hbCwgc3RhdHVzQ2FsbGJhY2spOwogICAgICAgICAgcmV0dXJuIEFib3J0YWJsZVByb21pc2VDYWNoZTIuY2hlY2tTaW5nbGVQcm9taXNlKHRoaXMuY2FjaGUuZ2V0KGtleSkucHJvbWlzZSwgc2lnbmFsKTsKICAgICAgICB9CiAgICAgICAgZGVsZXRlKGtleSkgewogICAgICAgICAgY29uc3QgY2FjaGVkRW50cnkgPSB0aGlzLmNhY2hlLmdldChrZXkpOwogICAgICAgICAgaWYgKGNhY2hlZEVudHJ5KSB7CiAgICAgICAgICAgIGlmICghY2FjaGVkRW50cnkuc2V0dGxlZCkgewogICAgICAgICAgICAgIGNhY2hlZEVudHJ5LmFib3J0ZXIuYWJvcnQoKTsKICAgICAgICAgICAgfQogICAgICAgICAgICB0aGlzLmNhY2hlLmRlbGV0ZShrZXkpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBjbGVhcigpIHsKICAgICAgICAgIGNvbnN0IGtleUl0ZXIgPSB0aGlzLmNhY2hlLmtleXMoKTsKICAgICAgICAgIGxldCBkZWxldGVDb3VudCA9IDA7CiAgICAgICAgICBmb3IgKGxldCByZXN1bHQgPSBrZXlJdGVyLm5leHQoKTsgIXJlc3VsdC5kb25lOyByZXN1bHQgPSBrZXlJdGVyLm5leHQoKSkgewogICAgICAgICAgICB0aGlzLmRlbGV0ZShyZXN1bHQudmFsdWUpOwogICAgICAgICAgICBkZWxldGVDb3VudCArPSAxOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIGRlbGV0ZUNvdW50OwogICAgICAgIH0K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ZXguanMKICB2YXIgcmVxdWlyZV9xdWlja19scnUgPSBfX2NvbW1vbkpTKHsKICAgICJub2RlX21vZHVsZXMvLnBucG0vcXVpY2stbHJ1QDQuMC4xL25vZGVfbW9kdWxlcy9xdWljay1scnUvaW5kZXguanMiKGV4cG9ydHMyLCBtb2R1bGUyKSB7CiAgICAgIGluaXRfYnVmZmVyX3NoaW0oKTsKICAgICAgInVzZSBzdHJpY3QiOwogICAgICB2YXIgUXVpY2tMUlUgPSBjbGFzcyB7CiAgICAgICAgY29uc3RydWN0b3Iob3B0aW9ucyA9IHt9KSB7CiAgICAgICAgICBpZiAoIShvcHRpb25zLm1heFNpemUgJiYgb3B0aW9ucy5tYXhTaXplID4gMCkpIHsKICAgICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcigiYG1heFNpemVgIG11c3QgYmUgYSBudW1iZXIgZ3JlYXRlciB0aGFuIDAiKTsKICAgICAgICAgIH0KICAgICAgICAgIHRoaXMubWF4U2l6ZSA9IG9wdGlvbnMubWF4U2l6ZTsKICAgICAgICAgIHRoaXMuY2FjaGUgPSBuZXcgTWFwKCk7CiAgICAgICAgICB0aGlzLm9sZENhY2hlID0gbmV3IE1hcCgpOwogICAgICAgICAgdGhpcy5fc2l6ZSA9IDA7CiAgICAgICAgfQogICAgICAgIF9zZXQoa2V5LCB2YWx1ZSkgewogICAgICAgICAgdGhpcy5jYWNoZS5zZXQoa2V5LCB2YWx1ZSk7CiAgICAgICAgICB0aGlzLl9zaXplKys7CiAgICAgICAgICBpZiAodGhpcy5fc2l6ZSA+PSB0aGlzLm1heFNpemUpIHsKICAgICAgICAgICAgdGhpcy5fc2l6ZSA9IDA7CiAgICAgICAgICAgIHRoaXMub2xkQ2FjaGUgPSB0aGlzLmNhY2hlOwogICAgICAgICAgICB0aGlzLmNhY2hlID0gbmV3IE1hcCgpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBnZXQoa2V5KSB7CiAgICAgICAgICBpZiAodGhpcy5jYWNoZS5oYXMoa2V5KSkgewogICAgICAgICAgICByZXR1cm4gdGhpcy5jYWNoZS5nZXQoa2V5KTsKICAgICAgICAgIH0KICAgICAgICAgIGlmICh0aGlzLm9sZENhY2hlLmhhcyhrZXkpKSB7CiAgICAgICAgICAgIGNvbnN0IHZhbHVlID0gdGhpcy5vbGRDYWNoZS5nZXQoa2V5KTsKICAgICAgICAgICAgdGhpcy5vbGRDYWNoZS5kZWxldGUoa2V5KTsKICAgICAgICAgICAgdGhpcy5fc2V0KGtleSwgdmFsdWUpOwogICAgICAgICAgICByZXR1cm4gdmFsdWU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHNldChrZXksIHZhbHVlKSB7CiAgICAgICAgICBpZiAodGhpcy5jYWNoZS5oYXMoa2V5KSkgewogICAgICAgICAgICB0aGlzLmNhY2hlLnNldChrZXksIHZhbHVlKTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHRoaXMuX3NldChrZXksIHZhbHVlKTsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiB0aGlzOwogICAgICAgIH0KICAgICAgICBoYXMoa2V5KSB7CiAgICAgICAgICByZXR1cm4gdGhpcy5jYWNoZS5oYXMoa2V5KSB8fCB0aGlzLm9sZENhY2hlLmhhcyhrZXkpOwogICAgICAgIH0KICAgICAgICBwZWVrKGtleSkgewogICAgICAgICAgaWYgKHRoaXMuY2FjaGUuaGFzKGtleSkpIHsKICAgICAgICAgICAgcmV0dXJuIHRoaXMuY2FjaGUuZ2V0KGtleSk7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAodGhpcy5vbGRDYWNoZS5oYXMoa2V5KSkgewogICAgICAgICAgICByZXR1cm4gdGhpcy5vbGRDYWNoZS5nZXQoa2V5KTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZGVsZXRlKGtleSkgewogICAgICAgICAgY29uc3QgZGVsZXRlZCA9IHRoaXMuY2FjaGUuZGVsZXRlKGtleSk7CiAgICAgICAgICBpZiAoZGVsZXRlZCkgewogICAgICAgICAgICB0aGlzLl9zaXplLS07CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gdGhpcy5vbGRDYWNoZS5kZWxldGUoa2V5KSB8fCBkZWxldGVkOwogICAgICAgIH0KICAgICAgICBjbGVhcigpIHsKICAgICAgICAgIHRoaXMuY2FjaGUuY2xlYXIoKTsKICAgICAgICAgIHRoaXMub2xkQ2FjaGUuY2xlYXIoKTsKICAgICAgICAgIHRoaXMuX3NpemUgPSAwOwogICAgICAgIH0KICAgICAgICAqa2V5cygpIHsKICAgICAgICAgIGZvciAoY29uc3QgW2tleV0gb2YgdGhpcykgewogICAgICAgICAgICB5aWVsZCBrZXk7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgICp2YWx1ZXMoKSB7CiAgICAgICAgICBmb3IgKGNvbnN0IFssIHZhbHVlXSBvZiB0aGlzKSB7CiAgICAgICAgICAgIHlpZWxkIHZhbHVlOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICAqW1N5bWJvbC5pdGVyYXRvcl0oKSB7CiAgICAgICAgICBmb3IgKGNvbnN0IGl0ZW0gb2YgdGhpcy5jYWNoZSkgewogICAgICAgICAgICB5aWVsZCBpdGVtOwogICAgICAgICAgfQogICAgICAgICAgZm9yIChjb25zdCBpdGVtIG9mIHRoaXMub2xkQ2FjaGUpIHsKICAgICAgICAgICAgY29uc3QgW2tleV0gPSBpdGVtOwogICAgICAgICAgICBpZiAoIXRoaXMuY2FjaGUuaGFzKGtleSkpIHsKICAgICAgICAgICAgICB5aWVsZCBpdGVtOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGdldCBzaXplKCkgewogICAgICAgICAgbGV0IG9sZENhY2hlU2l6ZSA9IDA7CiAgICAgICAgICBmb3IgKGNvbnN0IGtleSBvZiB0aGlzLm9sZENhY2hlLmtleXMoKSkgewogICAgICAgICAgICBpZiAoIXRoaXMuY2FjaGUuaGFzKGtleSkpIHsK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AgICAgIGZ1bmN0aW9uIF9oYXMob2JqLCBrZXkpIHsKICAgICAgICByZXR1cm4gT2JqZWN0LnByb3RvdHlwZS5oYXNPd25Qcm9wZXJ0eS5jYWxsKG9iaiwga2V5KTsKICAgICAgfQogICAgICBleHBvcnRzMi5hc3NpZ24gPSBmdW5jdGlvbihvYmopIHsKICAgICAgICB2YXIgc291cmNlcyA9IEFycmF5LnByb3RvdHlwZS5zbGljZS5jYWxsKGFyZ3VtZW50cywgMSk7CiAgICAgICAgd2hpbGUgKHNvdXJjZXMubGVuZ3RoKSB7CiAgICAgICAgICB2YXIgc291cmNlID0gc291cmNlcy5zaGlmdCgpOwogICAgICAgICAgaWYgKCFzb3VyY2UpIHsKICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAodHlwZW9mIHNvdXJjZSAhPT0gIm9iamVjdCIpIHsKICAgICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcihzb3VyY2UgKyAibXVzdCBiZSBub24tb2JqZWN0Iik7CiAgICAgICAgICB9CiAgICAgICAgICBmb3IgKHZhciBwIGluIHNvdXJjZSkgewogICAgICAgICAgICBpZiAoX2hhcyhzb3VyY2UsIHApKSB7CiAgICAgICAgICAgICAgb2JqW3BdID0gc291cmNlW3BdOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiBvYmo7CiAgICAgIH07CiAgICAgIGV4cG9ydHMyLnNocmlua0J1ZiA9IGZ1bmN0aW9uKGJ1Ziwgc2l6ZSkgewogICAgICAgIGlmIChidWYubGVuZ3RoID09PSBzaXplKSB7CiAgICAgICAgICByZXR1cm4gYnVmOwogICAgICAgIH0KICAgICAgICBpZiAoYnVmLnN1YmFycmF5KSB7CiAgICAgICAgICByZXR1cm4gYnVmLnN1YmFycmF5KDAsIHNpemUpOwogICAgICAgIH0KICAgICAgICBidWYubGVuZ3RoID0gc2l6ZTsKICAgICAgICByZXR1cm4gYnVmOwogICAgICB9OwogICAgICB2YXIgZm5UeXBlZCA9IHsKICAgICAgICBhcnJheVNldDogZnVuY3Rpb24oZGVzdCwgc3JjLCBzcmNfb2ZmcywgbGVuLCBkZXN0X29mZnMpIHsKICAgICAgICAgIGlmIChzcmMuc3ViYXJyYXkgJiYgZGVzdC5zdWJhcnJheSkgewogICAgICAgICAgICBkZXN0LnNldChzcmMuc3ViYXJyYXkoc3JjX29mZnMsIHNyY19vZmZzICsgbGVuKSwgZGVzdF9vZmZzKTsKICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgfQogICAgICAgICAgZm9yICh2YXIgaSA9IDA7IGkgPCBsZW47IGkrKykgewogICAgICAgICAgICBkZXN0W2Rlc3Rfb2ZmcyArIGldID0gc3JjW3NyY19vZmZzICsgaV07CiAgICAgICAgICB9CiAgICAgICAgfSwKICAgICAgICBmbGF0dGVuQ2h1bmtzOiBmdW5jdGlvbihjaHVua3MpIHsKICAgICAgICAgIHZhciBpLCBsLCBsZW4sIHBvcywgY2h1bmssIHJlc3VsdDsKICAgICAgICAgIGxlbiA9IDA7CiAgICAgICAgICBmb3IgKGkgPSAwLCBsID0gY2h1bmtzLmxlbmd0aDsgaSA8IGw7IGkrKykgewogICAgICAgICAgICBsZW4gKz0gY2h1bmtzW2ldLmxlbmd0aDsKICAgICAgICAgIH0KICAgICAgICAgIHJlc3VsdCA9IG5ldyBVaW50OEFycmF5KGxlbik7CiAgICAgICAgICBwb3MgPSAwOwogICAgICAgICAgZm9yIChpID0gMCwgbCA9IGNodW5rcy5sZW5ndGg7IGkgPCBsOyBpKyspIHsKICAgICAgICAgICAgY2h1bmsgPSBjaHVua3NbaV07CiAgICAgICAgICAgIHJlc3VsdC5zZXQoY2h1bmssIHBvcyk7CiAgICAgICAgICAgIHBvcyArPSBjaHVuay5sZW5ndGg7CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gcmVzdWx0OwogICAgICAgIH0KICAgICAgfTsKICAgICAgdmFyIGZuVW50eXBlZCA9IHsKICAgICAgICBhcnJheVNldDogZnVuY3Rpb24oZGVzdCwgc3JjLCBzcmNfb2ZmcywgbGVuLCBkZXN0X29mZnMpIHsKICAgICAgICAgIGZvciAodmFyIGkgPSAwOyBpIDwgbGVuOyBpKyspIHsKICAgICAgICAgICAgZGVzdFtkZXN0X29mZnMgKyBpXSA9IHNyY1tzcmNfb2ZmcyArIGldOwogICAgICAgICAgfQogICAgICAgIH0sCiAgICAgICAgZmxhdHRlbkNodW5rczogZnVuY3Rpb24oY2h1bmtzKSB7CiAgICAgICAgICByZXR1cm4gW10uY29uY2F0LmFwcGx5KFtdLCBjaHVua3MpOwogICAgICAgIH0KICAgICAgfTsKICAgICAgZXhwb3J0czIuc2V0VHlwZWQgPSBmdW5jdGlvbihvbikgewogICAgICAgIGlmIChvbikgewogICAgICAgICAgZXhwb3J0czIuQnVmOCA9IFVpbnQ4QXJyYXk7CiAgICAgICAgICBleHBvcnRzMi5CdWYxNiA9IFVpbnQxNkFycmF5OwogICAgICAgICAgZXhwb3J0czIuQnVmMzIgPSBJbnQzMkFycmF5OwogICAgICAgICAgZXhwb3J0czIuYXNzaWduKGV4cG9ydHMyLCBmblR5cGVkKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgZXhwb3J0czIuQnVmOCA9IEFycmF5OwogICAgICAgICAgZXhwb3J0czIuQnVmMTYgPSBBcnJheTsKICAgICAgICAgIGV4cG9ydHMyLkJ1ZjMyID0gQXJyYXk7CiAgICAgICAgICBleHBvcnRzMi5hc3NpZ24oZXhwb3J0czIsIGZuVW50eXBlZCk7CiAgICAgICAgfQogICAgICB9OwogICAgICBleHBvcnRzMi5zZXRUeXBlZChUWVBFRF9PSyk7CiAgICB9CiAgfSk7CgogIC8vIG5vZGVfbW9kdWxlcy8ucG5wbS9wYWtvQDEuMC4xMS9ub2RlX21vZHVsZXMvcGFrby9saWIvemxpYi90cmVlcy5qcwogIHZhciByZXF1aXJlX3RyZWVzID0gX19jb21tb25KUyh7CiAgICAibm9k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PSAwOwogICAgICAgIH0KICAgICAgICB0cmVlW3MuaGVhcFtzLmhlYXBfbWF4XSAqIDIgKyAxXSA9IDA7CiAgICAgICAgZm9yIChoID0gcy5oZWFwX21heCArIDE7IGggPCBIRUFQX1NJWkU7IGgrKykgewogICAgICAgICAgbiA9IHMuaGVhcFtoXTsKICAgICAgICAgIGJpdHMgPSB0cmVlW3RyZWVbbiAqIDIgKyAxXSAqIDIgKyAxXSArIDE7CiAgICAgICAgICBpZiAoYml0cyA+IG1heF9sZW5ndGgpIHsKICAgICAgICAgICAgYml0cyA9IG1heF9sZW5ndGg7CiAgICAgICAgICAgIG92ZXJmbG93Kys7CiAgICAgICAgICB9CiAgICAgICAgICB0cmVlW24gKiAyICsgMV0gPSBiaXRzOwogICAgICAgICAgaWYgKG4gPiBtYXhfY29kZSkgewogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgIH0KICAgICAgICAgIHMuYmxfY291bnRbYml0c10rKzsKICAgICAgICAgIHhiaXRzID0gMDsKICAgICAgICAgIGlmIChuID49IGJhc2UpIHsKICAgICAgICAgICAgeGJpdHMgPSBleHRyYVtuIC0gYmFzZV07CiAgICAgICAgICB9CiAgICAgICAgICBmID0gdHJlZVtuICogMl07CiAgICAgICAgICBzLm9wdF9sZW4gKz0gZiAqIChiaXRzICsgeGJpdHMpOwogICAgICAgICAgaWYgKGhhc19zdHJlZSkgewogICAgICAgICAgICBzLnN0YXRpY19sZW4gKz0gZiAqIChzdHJlZVtuICogMiArIDFdICsgeGJpdHMpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAob3ZlcmZsb3cgPT09IDApIHsKICAgICAgICAgIHJldHVybjsKICAgICAgICB9CiAgICAgICAgZG8gewogICAgICAgICAgYml0cyA9IG1heF9sZW5ndGggLSAxOwogICAgICAgICAgd2hpbGUgKHMuYmxfY291bnRbYml0c10gPT09IDApIHsKICAgICAgICAgICAgYml0cy0tOwogICAgICAgICAgfQogICAgICAgICAgcy5ibF9jb3VudFtiaXRzXS0tOwogICAgICAgICAgcy5ibF9jb3VudFtiaXRzICsgMV0gKz0gMjsKICAgICAgICAgIHMuYmxfY291bnRbbWF4X2xlbmd0aF0tLTsKICAgICAgICAgIG92ZXJmbG93IC09IDI7CiAgICAgICAgfSB3aGlsZSAob3ZlcmZsb3cgPiAwKTsKICAgICAgICBmb3IgKGJpdHMgPSBtYXhfbGVuZ3RoOyBiaXRzICE9PSAwOyBiaXRzLS0pIHsKICAgICAgICAgIG4gPSBzLmJsX2NvdW50W2JpdHNdOwogICAgICAgICAgd2hpbGUgKG4gIT09IDApIHsKICAgICAgICAgICAgbSA9IHMuaGVhcFstLWhdOwogICAgICAgICAgICBpZiAobSA+IG1heF9jb2RlKSB7CiAgICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHRyZWVbbSAqIDIgKyAxXSAhPT0gYml0cykgewogICAgICAgICAgICAgIHMub3B0X2xlbiArPSAoYml0cyAtIHRyZWVbbSAqIDIgKyAxXSkgKiB0cmVlW20gKiAyXTsKICAgICAgICAgICAgICB0cmVlW20gKiAyICsgMV0gPSBiaXRzOwogICAgICAgICAgICB9CiAgICAgICAgICAgIG4tLTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZ2VuX2NvZGVzKHRyZWUsIG1heF9jb2RlLCBibF9jb3VudCkgewogICAgICAgIHZhciBuZXh0X2NvZGUgPSBuZXcgQXJyYXkoTUFYX0JJVFMgKyAxKTsKICAgICAgICB2YXIgY29kZSA9IDA7CiAgICAgICAgdmFyIGJpdHM7CiAgICAgICAgdmFyIG47CiAgICAgICAgZm9yIChiaXRzID0gMTsgYml0cyA8PSBNQVhfQklUUzsgYml0cysrKSB7CiAgICAgICAgICBuZXh0X2NvZGVbYml0c10gPSBjb2RlID0gY29kZSArIGJsX2NvdW50W2JpdHMgLSAxXSA8PCAxOwogICAgICAgIH0KICAgICAgICBmb3IgKG4gPSAwOyBuIDw9IG1heF9jb2RlOyBuKyspIHsKICAgICAgICAgIHZhciBsZW4gPSB0cmVlW24gKiAyICsgMV07CiAgICAgICAgICBpZiAobGVuID09PSAwKSB7CiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgfQogICAgICAgICAgdHJlZVtuICogMl0gPSBiaV9yZXZlcnNlKG5leHRfY29kZVtsZW5dKyssIGxlbik7CiAgICAgICAgfQogICAgICB9CiAgICAgIGZ1bmN0aW9uIHRyX3N0YXRpY19pbml0KCkgewogICAgICAgIHZhciBuOwogICAgICAgIHZhciBiaXRzOwogICAgICAgIHZhciBsZW5ndGg7CiAgICAgICAgdmFyIGNvZGU7CiAgICAgICAgdmFyIGRpc3Q7CiAgICAgICAgdmFyIGJsX2NvdW50ID0gbmV3IEFycmF5KE1BWF9CSVRTICsgMSk7CiAgICAgICAgbGVuZ3RoID0gMDsKICAgICAgICBmb3IgKGNvZGUgPSAwOyBjb2RlIDwgTEVOR1RIX0NPREVTIC0gMTsgY29kZSsrKSB7CiAgICAgICAgICBiYXNlX2xlbmd0aFtjb2RlXSA9IGxlbmd0aDsKICAgICAgICAgIGZvciAobiA9IDA7IG4gPCAxIDw8IGV4dHJhX2xiaXRzW2NvZGVdOyBuKyspIHsKICAgICAgICAgICAgX2xlbmd0aF9jb2RlW2xlbmd0aCsrXSA9IGNvZGU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIF9sZW5ndGhfY29kZVtsZW5ndGggLSAxXSA9IGNvZGU7CiAgICAgICAgZGlzdCA9IDA7CiAgICAgICAgZm9yIChjb2RlID0gMDsgY29kZSA8IDE2OyBjb2RlKyspIHsKICAgICAgICAgIGJhc2VfZGlzdFtjb2RlXSA9IGRpc3Q7CiAgICAgICAgICBmb3IgKG4gPSAwOyBuIDwgMSA8PCBleHRyYV9kYml0c1tjb2RlXTsgbisrKSB7CiAgICAgICAgICAgIF9kaXN0X2NvZGVbZGlzdCsrXSA9IGNvZGU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGRpc3QgPj49IDc7CiAgICAgICAgZm9yICg7IGNvZGUgPCBEX0NPREVTOyBjb2RlKyspIHsKICAgICAgICAgIGJhc2VfZGlzdFtjb2RlXSA9IGRpc3QgPDwgNzsKICAgICAgICAgIGZvciAobiA9IDA7IG4gPCAxIDw8IGV4dHJhX2RiaXRzW2NvZGVdIC0gNzsgbisrKSB7CiAgICAgICAgICAgIF9kaXN0X2NvZGVbMjU2ICsgZGlzdCsrXSA9IGNvZGU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGZvciAoYml0cyA9IDA7IGJpdHMgPD0gTUFYX0JJVFM7IGJpdHMrKykgewogICAgICAgICAgYmxfY291bnRbYml0c10gPSAwOwogICAgICAgIH0KICAgICAgICBuID0gMDsKICAgICAgICB3aGlsZSAobiA8PSAxNDMpIHsKICAgICAgICAgIHN0YXRpY19sdHJlZVtuICogMiArIDFdID0gODsKICAgICAgICAgIG4rKzsKICAgICAgICAgIGJsX2NvdW50WzhdKys7CiAgICAgICAgfQogICAgICAgIHdoaWxlIChuIDw9IDI1NSkgewogICAgICAgICAgc3RhdGljX2x0cmVlW24gKiAyICsgMV0gPSA5OwogICAgICAgICAgbisrOwogICAgICAgICAgYmxfY291bnRbOV0rKzsKICAgICAgICB9CiAgICAgICAgd2hpbGUgKG4gPD0gMjc5KSB7CiAgICAgICAgICBzdGF0aWNfbHRyZWVbbiAqIDIgKyAxXSA9IDc7CiAgICAgICAgICBuKys7CiAgICAgICAgICBibF9jb3VudFs3XSsrOwogICAgICAgIH0KICAgICAgICB3aGlsZSAobiA8PSAyODcpIHsKICAgICAgICAgIHN0YXRpY19sdHJlZVtuICogMiArIDFdID0gODsKICAgICAgICAgIG4rKzsKICAgICAgICAgIGJsX2NvdW50WzhdKys7CiAgICAgICAgfQogICAgICAgIGdlbl9jb2RlcyhzdGF0aWNfbHRyZWUsIExfQ09ERVMgKyAxLCBibF9jb3VudCk7CiAgICAgICAgZm9yIChuID0gMDsgbiA8IERfQ09ERVM7IG4rKykgewogICAgICAgICAgc3RhdGljX2R0cmVlW24gKiAyICsgMV0gPSA1OwogICAgICAgICAgc3RhdGljX2R0cmVlW24gKiAyXSA9IGJpX3JldmVyc2UobiwgNSk7CiAgICAgICAgfQogICAgICAgIHN0YXRpY19sX2Rlc2MgPSBuZXcgU3RhdGljVHJlZURlc2Moc3RhdGljX2x0cmVlLCBleHRyYV9sYml0cywgTElURVJBTFMgKyAxLCBMX0NPREVTLCBNQVhfQklUUyk7CiAgICAgICAgc3RhdGljX2RfZGVzYyA9IG5ldyBTdGF0aWNUcmVlRGVzYyhzdGF0aWNfZHRyZWUsIGV4dHJhX2RiaXRzLCAwLCBEX0NPREVTLCBNQVhfQklUUyk7CiAgICAgICAgc3RhdGljX2JsX2Rlc2MgPSBuZXcgU3RhdGljVHJlZURlc2MobmV3IEFycmF5KDApLCBleHRyYV9ibGJpdHMsIDAsIEJMX0NPREVTLCBNQVhfQkxfQklUUyk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gaW5pdF9ibG9jayhzKSB7CiAgICAgICAgdmFyIG47CiAgICAgICAgZm9yIChuID0gMDsgbiA8IExfQ09ERVM7IG4rKykgewogICAgICAgICAgcy5keW5fbHRyZWVbbiAqIDJdID0gMDsKICAgICAgICB9CiAgICAgICAgZm9yIChuID0gMDsgbiA8IERfQ09ERVM7IG4rKykgewogICAgICAgICAgcy5keW5fZHRyZWVbbiAqIDJdID0gMDsKICAgICAgICB9CiAgICAgICAgZm9yIChuID0gMDsgbiA8IEJMX0NPREVTOyBuKyspIHsKICAgICAgICAgIHMuYmxfdHJlZVtuICogMl0gPSAwOwogICAgICAgIH0KICAgICAgICBzLmR5bl9sdHJlZVtFTkRfQkxPQ0sgKiAyXSA9IDE7CiAgICAgICAgcy5vcHRfbGVuID0gcy5zdGF0aWNfbGVuID0gMDsKICAgICAgICBzLmxhc3RfbGl0ID0gcy5tYXRjaGVzID0gMDsKICAgICAgfQogICAgICBmdW5jdGlvbiBiaV93aW5kdXAocykgewogICAgICAgIGlmIChzLmJpX3ZhbGlkID4gOCkgewogICAgICAgICAgcHV0X3Nob3J0KHMsIHMuYmlfYnVmKTsKICAgICAgICB9IGVsc2UgaWYgKHMuYmlfdmFsaWQgPiAwKSB7CiAgICAgICAgICBzLnBlbmRpbmdfYnVmW3MucGVuZGluZysrXSA9IHMuYmlfYnVmOwogICAgICAgIH0KICAgICAgICBzLmJpX2J1ZiA9IDA7CiAgICAgICAgcy5iaV92YWxpZCA9IDA7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gY29weV9ibG9jayhzLCBidWYsIGxlbiwgaGVhZGVyKSB7CiAgICAgICAgYmlfd2luZHVwKHMpOwogICAgICAgIGlmIChoZWFkZXIpIHsKICAgICAgICAgIHB1dF9zaG9ydChzLCBsZW4pOwogICAgICAgICAgcHV0X3Nob3J0KHMsIH5sZW4pOwogICAgICAgIH0KICAgICAgICB1dGlscy5hcnJheVNldChzLnBlbmRpbmdfYnVmLCBzLndpbmRvdywgYnVmLCBsZW4sIHMucGVuZGluZyk7CiAgICAgICAgcy5wZW5kaW5nICs9IGxlbjsKICAgICAgfQogICAgICBmdW5jdGlvbiBzbWFsbGVyKHRyZWUsIG4sIG0sIGRlcHRoKSB7CiAgICAgICAgdmFyIF9uMiA9IG4gKiAyOwogICAgICAgIHZhciBfbTIgPSBtICogMjsKICAgICAgICByZXR1cm4gdHJlZVtfbjJdIDwgdHJlZVtfbTJdIHx8IHRyZWVbX24yXSA9PT0gdHJlZVtfbTJdICYmIGRlcHRoW25dIDw9IGRlcHRoW21dOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIHBxZG93bmhlYXAocywgdHJlZSwgaykgewogICAgICAgIHZhciB2ID0gcy5oZWFwW2tdOwogICAgICAgIHZhciBqID0gayA8PCAxOwogICAgICAgIHdoaWxlIChqIDw9IHMuaGVhcF9sZW4pIHsKICAgICAgICAgIGlmIChqIDwgcy5oZWFwX2xlbiAmJiBzbWFsbGVyKHRyZWUsIHMuaGVhcFtqICsgMV0sIHMuaGVhcFtqXSwgcy5kZXB0aCkpIHsKICAgICAgICAgICAgaisrOwogICAgICAgICAgfQogICAgICAgICAgaWYgKHNtYWxsZXIodHJlZSwgdiwgcy5oZWFwW2pdLCBzLmRlcHRoKSkgewogICAgICAgICAgICBicmVhazsKICAgICAgICAgIH0KICAgICAgICAgIHMuaGVhcFtrXSA9IHMuaGVhcFtqXTsKICAgICAgICAgIGsgPSBqOwogICAgICAgICAgaiA8PD0gMTsKICAgICAgICB9CiAgICAgICAgcy5oZWFwW2tdID0gdjsKICAgICAgfQogICAgICBmdW5jdGlvbiBjb21wcmVzc19ibG9jayhzLCBsdHJlZSwgZHRyZWUpIHsKICAgICAgICB2YXIgZGlzdDsKICAgICAgICB2YXIgbGM7CiAgICAgICAgdmFyIGx4ID0gMDsKICAgICAgICB2YXIgY29kZTsKICAgICAgICB2YXIgZXh0cmE7CiAgICAgICAgaWYgKHMubGFzdF9saXQgIT09IDApIHsKICAgICAgICAgIGRvIHsKICAgICAgICAgICAgZGlzdCA9IHMucGVuZGluZ19idWZbcy5kX2J1ZiArIGx4ICogMl0gPDwgOCB8IHMucGVuZGluZ19idWZbcy5kX2J1ZiArIGx4ICogMiArIDFdOwogICAgICAgICAgICBsYyA9IHMucGVuZGluZ19idWZbcy5sX2J1ZiArIGx4XTsKICAgICAgICAgICAgbHgrKzsKICAgICAgICAgICAgaWYgKGRpc3QgPT09IDApIHsKICAgICAgICAgICAgICBzZW5kX2NvZGUocywgbGMsIGx0cmVlKTsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICBjb2RlID0gX2xlbmd0aF9jb2RlW2xjXTsKICAgICAgICAgICAgICBzZW5kX2NvZGUocywgY29kZSArIExJVEVSQUxTICsgMSwgbHRyZWUpOwogICAgICAgICAgICAgIGV4dHJhID0gZXh0cmFfbGJpdHNbY29kZV07CiAgICAgICAgICAgICAgaWYgKGV4dHJhICE9PSAwKSB7CiAgICAgICAgICAgICAgICBsYyAtPSBiYXNlX2xlbmd0aFtjb2RlXTsKICAgICAgICAgICAgICAgIHNlbmRfYml0cyhzLCBsYywgZXh0cmEpOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBkaXN0LS07CiAgICAgICAgICAgICAgY29kZSA9IGRfY29kZShkaXN0KTsKICAgICAgICAgICAgICBzZW5kX2NvZGUocywgY29kZSwgZHRyZWUpOwogICAgICAgICAgICAgIGV4dHJhID0gZXh0cmFfZGJpdHNbY29kZV07CiAgICAgICAgICAgICAgaWYgKGV4dHJhICE9PSAwKSB7CiAgICAgICAgICAgICAgICBkaXN0IC09IGJhc2VfZGlzdFtjb2RlXTsKICAgICAgICAgICAgICAgIHNlbmRfYml0cyhzLCBkaXN0LCBleHRyYSk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICB9IHdoaWxlIChseCA8IHMubGFzdF9saXQpOwogICAgICAgIH0KICAgICAgICBzZW5kX2NvZGUocywgRU5EX0JMT0NLLCBsdHJlZSk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gYnVpbGRfdHJlZShzLCBkZXNjKSB7CiAgICAgICAgdmFyIHRyZWUgPSBkZXNjLmR5bl90cmVlOwogICAgICAgIHZhciBzdHJlZSA9IGRlc2Muc3RhdF9kZXNjLnN0YXRpY190cmVlOwogICAgICAgIHZhciBoYXNfc3RyZWUgPSBkZXNjLnN0YXRfZGVzYy5oYXNfc3RyZWU7CiAgICAgICAgdmFyIGVsZW1zID0gZGVzYy5zdGF0X2Rlc2MuZWxlbXM7CiAgICAgICAgdmFyIG4sIG07CiAgICAgICAgdmFyIG1heF9jb2RlID0gLTE7CiAgICAgICAgdmFyIG5vZGU7CiAgICAgICAgcy5oZWFwX2xlbiA9IDA7CiAgICAgICAgcy5oZWFwX21heCA9IEhFQVBfU0laRTsKICAgICAgICBmb3IgKG4gPSAwOyBuIDwgZWxlbXM7IG4rKykgewogICAgICAgICAgaWYgKHRyZWVbbiAqIDJdICE9PSAwKSB7CiAgICAgICAgICAgIHMuaGVhcFsrK3MuaGVhcF9sZW5dID0gbWF4X2NvZGUgPSBuOwogICAgICAgICAgICBzLmRlcHRoW25dID0gMDsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHRyZWVbbiAqIDIgKyAxXSA9IDA7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHdoaWxlIChzLmhlYXBfbGVuIDwgMikgewogICAgICAgICAgbm9kZSA9IHMuaGVhcFsrK3MuaGVhcF9sZW5dID0gbWF4X2NvZGUgPCAyID8gKyttYXhfY29kZSA6IDA7CiAgICAgICAgICB0cmVlW25vZGUgKiAyXSA9IDE7CiAgICAgICAgICBzLmRlcHRoW25vZGVdID0gMDsKICAgICAgICAgIHMub3B0X2xlbi0tOwogICAgICAgICAgaWYgKGhhc19zdHJlZSkgewogICAgICAgICAgICBzLnN0YXRpY19sZW4gLT0gc3RyZWVbbm9kZSAqIDIgKyAxXTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZGVzYy5tYXhfY29kZSA9IG1heF9jb2RlOwogICAgICAgIGZvciAobiA9IHMuaGVhcF9sZW4gPj4gMTsgbiA+PSAxOyBuLS0pIHsKICAgICAgICAgIHBxZG93bmhlYXAocywgdHJlZSwgbik7CiAgICAgICAgfQogICAgICAgIG5vZGUgPSBlbGVtczsKICAgICAgICBkbyB7CiAgICAgICAgICBuID0gcy5oZWFwWzFdOwogICAgICAgICAgcy5oZWFwWzFdID0gcy5oZWFwW3MuaGVhcF9sZW4tLV07CiAgICAgICAgICBwcWRvd25oZWFwKHMsIHRyZWUsIDEpOwogICAgICAgICAgbSA9IHMuaGVhcFsxXTsKICAgICAgICAgIHMuaGVhcFstLXMuaGVhcF9tYXhdID0gbjsKICAgICAgICAgIHMuaGVhcFstLXMuaGVhcF9tYXhdID0gbTsKICAgICAgICAgIHRyZWVbbm9kZSAqIDJdID0gdHJlZVtuICogMl0gKyB0cmVlW20gKiAyXTsKICAgICAgICAgIHMuZGVwdGhbbm9kZV0gPSAocy5kZXB0aFtuXSA+PSBzLmRlcHRoW21dID8gcy5kZXB0aFtuXSA6IHMuZGVwdGhbbV0pICsgMTsKICAgICAgICAgIHRyZWVbbiAqIDIgKyAxXSA9IHRyZWVbbSAqIDIgKyAxXSA9IG5vZGU7CiAgICAgICAgICBzLmhlYXBbMV0gPSBub2RlKys7CiAgICAgICAgICBwcWRvd25oZWFwKHMsIHRyZWUsIDEpOwogICAgICAgIH0gd2hpbGUgKHMuaGVhcF9sZW4gPj0gMik7CiAgICAgICAgcy5oZWFwWy0tcy5oZWFwX21heF0gPSBzLmhlYXBbMV07CiAgICAgICAgZ2VuX2JpdGxlbihzLCBkZXNjKTsKICAgICAgICBnZW5fY29kZXModHJlZSwgbWF4X2NvZGUsIHMuYmxfY291bnQpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIHNjYW5fdHJlZShzLCB0cmVlLCBtYXhfY29kZSkgewogICAgICAgIHZhciBuOwogICAgICAgIHZhciBwcmV2bGVuID0gLTE7CiAgICAgICAgdmFyIGN1cmxlbjsKICAgICAgICB2YXIgbmV4dGxlbiA9IHRyZWVbMCAqIDIgKyAxXTsKICAgICAgICB2YXIgY291bnQgPSAwOwogICAgICAgIHZhciBtYXhfY291bnQgPSA3OwogICAgICAgIHZhciBtaW5fY291bnQgPSA0OwogICAgICAgIGlmIChuZXh0bGVuID09PSAwKSB7CiAgICAgICAgICBtYXhfY291bnQgPSAxMzg7CiAgICAgICAgICBtaW5fY291bnQgPSAzOwogICAgICAgIH0KICAgICAgICB0cmVlWyhtYXhfY29kZSArIDEpICogMiArIDFdID0gNjU1MzU7CiAgICAgICAgZm9yIChuID0gMDsgbiA8PSBtYXhfY29kZTsgbisrKSB7CiAgICAgICAgICBjdXJsZW4gPSBuZXh0bGVuOwogICAgICAgICAgbmV4dGxlbiA9IHRyZWVbKG4gKyAxKSAqIDIgKyAxXTsKICAgICAgICAgIGlmICgrK2NvdW50IDwgbWF4X2NvdW50ICYmIGN1cmxlbiA9PT0gbmV4dGxlbikgewogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgIH0gZWxzZSBpZiAoY291bnQgPCBtaW5fY291bnQpIHsKICAgICAgICAgICAgcy5ibF90cmVlW2N1cmxlbiAqIDJdICs9IGNvdW50OwogICAgICAgICAgfSBlbHNlIGlmIChjdXJsZW4gIT09IDApIHsKICAgICAgICAgICAgaWYgKGN1cmxlbiAhPT0gcHJldmxlbikgewogICAgICAgICAgICAgIHMuYmxfdHJlZVtjdXJsZW4gKiAyXSsrOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHMuYmxfdHJlZVtSRVBfM182ICogMl0rKzsKICAgICAgICAgIH0gZWxzZSBpZiAoY291bnQgPD0gMTApIHsKICAgICAgICAgICAgcy5ibF90cmVlW1JFUFpfM18xMCAqIDJdKys7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBzLmJsX3RyZWVbUkVQWl8xMV8xMzggKiAyXSsrOwogICAgICAgICAgfQogICAgICAgICAgY291bnQgPSAwOwogICAgICAgICAgcHJldmxlbiA9IGN1cmxlbjsKICAgICAgICAgIGlmIChuZXh0bGVuID09PSAwKSB7CiAgICAgICAgICAgIG1heF9jb3VudCA9IDEzODsKICAgICAgICAgICAgbWluX2NvdW50ID0gMzsKICAgICAgICAgIH0gZWxzZSBpZiAoY3VybGVuID09PSBuZXh0bGVuKSB7CiAgICAgICAgICAgIG1heF9jb3VudCA9IDY7CiAgICAgICAgICAgIG1pbl9jb3VudCA9IDM7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBtYXhfY291bnQgPSA3OwogICAgICAgICAgICBtaW5fY291bnQgPSA0OwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgICBmdW5jdGlvbiBzZW5kX3RyZWUocywgdHJlZSwgbWF4X2NvZGUpIHsKICAgICAgICB2YXIgbjsKICAgICAgICB2YXIgcHJldmxlbiA9IC0xOwogICAgICAgIHZhciBjdXJsZW47CiAgICAgICAgdmFyIG5leHRsZW4gPSB0cmVlWzAgKiAyICsgMV07CiAgICAgICAgdmFyIGNvdW50ID0gMDsKICAgICAgICB2YXIgbWF4X2NvdW50ID0gNzsKICAgICAgICB2YXIgbWluX2NvdW50ID0gNDsKICAgICAgICBpZiAobmV4dGxlbiA9PT0gMCkgewogICAgICAgICAgbWF4X2NvdW50ID0gMTM4OwogICAgICAgICAgbWluX2NvdW50ID0gMzsKICAgICAgICB9CiAgICAgICAgZm9yIChuID0gMDsgbiA8PSBtYXhfY29kZTsgbisrKSB7CiAgICAgICAgICBjdXJsZW4gPSBuZXh0bGVuOwogICAgICAgICAgbmV4dGxlbiA9IHRyZWVbKG4gKyAxKSAqIDIgKyAxXTsKICAgICAgICAgIGlmICgrK2NvdW50IDwgbWF4X2NvdW50ICYmIGN1cmxlbiA9PT0gbmV4dGxlbikgewogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgIH0gZWxzZSBpZiAoY291bnQgPCBtaW5fY291bnQpIHsKICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgIHNlbmRfY29kZShzLCBjdXJsZW4sIHMuYmxfdHJlZSk7CiAgICAgICAgICAgIH0gd2hpbGUgKC0tY291bnQgIT09IDApOwogICAgICAgICAgfSBlbHNlIGlmIChjdXJsZW4gIT09IDApIHsKICAgICAgICAgICAgaWYgKGN1cmxlbiAhPT0gcHJldmxlbikgewogICAgICAgICAgICAgIHNlbmRfY29kZShzLCBjdXJsZW4sIHMuYmxfdHJlZSk7CiAgICAgICAgICAgICAgY291bnQtLTsKICAgICAgICAgICAgfQogICAgICAgICAgICBzZW5kX2NvZGUocywgUkVQXzNfNiwgcy5ibF90cmVlKTsKICAgICAgICAgICAgc2VuZF9iaXRzKHMsIGNvdW50IC0gMywgMik7CiAgICAgICAgICB9IGVsc2UgaWYgKGNvdW50IDw9IDEwKSB7CiAgICAgICAgICAgIHNlbmRfY29kZShzLCBSRVBaXzNfMTAsIHMuYmxfdHJlZSk7CiAgICAgICAgICAgIHNlbmRfYml0cyhzLCBjb3VudCAtIDMsIDMpOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgc2VuZF9jb2RlKHMsIFJFUFpfMTFfMTM4LCBzLmJsX3RyZWUpOwogICAgICAgICAgICBzZW5kX2JpdHMocywgY291bnQgLSAxMSwgNyk7CiAgICAgICAgICB9CiAgICAgICAgICBjb3VudCA9IDA7CiAgICAgICAgICBwcmV2bGVuID0gY3VybGVuOwogICAgICAgICAgaWYgKG5leHRsZW4gPT09IDApIHsKICAgICAgICAgICAgbWF4X2NvdW50ID0gMTM4OwogICAgICAgICAgICBtaW5fY291bnQgPSAzOwogICAgICAgICAgfSBlbHNlIGlmIChjdXJsZW4gPT09IG5leHRsZW4pIHsKICAgICAgICAgICAgbWF4X2NvdW50ID0gNjsKICAgICAgICAgICAgbWluX2NvdW50ID0gMzsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIG1heF9jb3VudCA9IDc7CiAgICAgICAgICAgIG1pbl9jb3VudCA9IDQ7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9CiAgICAgIGZ1bmN0aW9uIGJ1aWxkX2JsX3RyZWUocykgewogICAgICAgIHZhciBtYXhfYmxpbmRleDsKICAgICAgICBzY2FuX3RyZWUocywgcy5keW5fbHRyZWUsIHMubF9kZXNjLm1heF9jb2RlKTsKICAgICAgICBzY2FuX3RyZWUocywgcy5keW5fZHRyZWUsIHMuZF9kZXNjLm1heF9jb2RlKTsKICAgICAgICBidWlsZF90cmVlKHMsIHMuYmxfZGVzYyk7CiAgICAgICAgZm9yIChtYXhfYmxpbmRleCA9IEJMX0NPREVTIC0gMTsgbWF4X2JsaW5kZXggPj0gMzsgbWF4X2JsaW5kZXgtLSkgewogICAgICAgICAgaWYgKHMuYmxfdHJlZVtibF9vcmRlclttYXhfYmxpbmRleF0gKiAyICsgMV0gIT09IDApIHsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHMub3B0X2xlbiArPSAzICogKG1heF9ibGluZGV4ICsgMSkgKyA1ICsgNSArIDQ7CiAgICAgICAgcmV0dXJuIG1heF9ibGluZGV4OwogICAgICB9CiAgICAgIGZ1bmN0aW9uIHNlbmRfYWxsX3RyZWVzKHMsIGxjb2RlcywgZGNvZGVzLCBibGNvZGVzKSB7CiAgICAgICAgdmFyIHJhbms7CiAgICAgICAgc2VuZF9iaXRzKHMsIGxjb2RlcyAtIDI1NywgNSk7CiAgICAgICAgc2VuZF9iaXRzKHMsIGRjb2RlcyAtIDEsIDUpOwogICAgICAgIHNlbmRfYml0cyhzLCBibGNvZGVzIC0gNCwgNCk7CiAgICAgICAgZm9yIChyYW5rID0gMDsgcmFuayA8IGJsY29kZXM7IHJhbmsrKykgewogICAgICAgICAgc2VuZF9iaXRzKHMsIHMuYmxfdHJlZVtibF9vcmRlcltyYW5rXSAqIDIgKyAxXSwgMyk7CiAgICAgICAgfQogICAgICAgIHNlbmRfdHJlZShzLCBzLmR5bl9sdHJlZSwgbGNvZGVzIC0gMSk7CiAgICAgICAgc2VuZF90cmVlKHMsIHMuZHluX2R0cmVlLCBkY29kZXMgLSAxKTsKICAgICAgfQogICAgICBmdW5jdGlvbiBkZXRlY3RfZGF0YV90eXBlKHMpIHsKICAgICAgICB2YXIgYmxhY2tfbWFzayA9IDQwOTM2MjQ0NDc7CiAgICAgICAgdmFyIG47CiAgICAgICAgZm9yIChuID0gMDsgbiA8PSAzMTsgbisrLCBibGFja19tYXNrID4+Pj0gMSkgewogICAgICAgICAgaWYgKGJsYWNrX21hc2sgJiAxICYmIHMuZHluX2x0cmVlW24gKiAyXSAhPT0gMCkgewogICAgICAgICAgICByZXR1cm4gWl9CSU5BUlk7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChzLmR5bl9sdHJlZVs5ICogMl0gIT09IDAgfHwgcy5keW5fbHRyZWVbMTAgKiAyXSAhPT0gMCB8fCBzLmR5bl9sdHJl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24gX3RyX2FsaWduKHMpIHsKICAgICAgICBzZW5kX2JpdHMocywgU1RBVElDX1RSRUVTIDw8IDEsIDMpOwogICAgICAgIHNlbmRfY29kZShzLCBFTkRfQkxPQ0ssIHN0YXRpY19sdHJlZSk7CiAgICAgICAgYmlfZmx1c2gocyk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gX3RyX2ZsdXNoX2Jsb2NrKHMsIGJ1Ziwgc3RvcmVkX2xlbiwgbGFzdCkgewogICAgICAgIHZhciBvcHRfbGVuYiwgc3RhdGljX2xlbmI7CiAgICAgICAgdmFyIG1heF9ibGluZGV4ID0gMDsKICAgICAgICBpZiAocy5sZXZlbCA+IDApIHsKICAgICAgICAgIGlmIChzLnN0cm0uZGF0YV90eXBlID09PSBaX1VOS05PV04pIHsKICAgICAgICAgICAgcy5zdHJtLmRhdGFfdHlwZSA9IGRldGVjdF9kYXRhX3R5cGUocyk7CiAgICAgICAgICB9CiAgICAgICAgICBidWlsZF90cmVlKHMsIHMubF9kZXNjKTsKICAgICAgICAgIGJ1aWxkX3RyZWUocywgcy5kX2Rlc2MpOwogICAgICAgICAgbWF4X2JsaW5kZXggPSBidWlsZF9ibF90cmVlKHMpOwogICAgICAgICAgb3B0X2xlbmIgPSBzLm9wdF9sZW4gKyAzICsgNyA+Pj4gMzsKICAgICAgICAgIHN0YXRpY19sZW5iID0gcy5zdGF0aWNfbGVuICsgMyArIDcgPj4+IDM7CiAgICAgICAgICBpZiAoc3RhdGljX2xlbmIgPD0gb3B0X2xlbmIpIHsKICAgICAgICAgICAgb3B0X2xlbmIgPSBzdGF0aWNfbGVuYjsKICAgICAgICAgIH0KICAgICAgICB9IGVsc2UgewogICAgICAgICAgb3B0X2xlbmIgPSBzdGF0aWNfbGVuYiA9IHN0b3JlZF9sZW4gKyA1OwogICAgICAgIH0KICAgICAgICBpZiAoc3RvcmVkX2xlbiArIDQgPD0gb3B0X2xlbmIgJiYgYnVmICE9PSAtMSkgewogICAgICAgICAgX3RyX3N0b3JlZF9ibG9jayhzLCBidWYsIHN0b3JlZF9sZW4sIGxhc3QpOwogICAgICAgIH0gZWxzZSBpZiAocy5zdHJhdGVneSA9PT0gWl9GSVhFRCB8fCBzdGF0aWNfbGVuYiA9PT0gb3B0X2xlbmIpIHsKICAgICAgICAgIHNlbmRfYml0cyhzLCAoU1RBVElDX1RSRUVTIDw8IDEpICsgKGxhc3QgPyAxIDogMCksIDMpOwogICAgICAgICAgY29tcHJlc3NfYmxvY2socywgc3RhdGljX2x0cmVlLCBzdGF0aWNfZHRyZWUpOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBzZW5kX2JpdHMocywgKERZTl9UUkVFUyA8PCAxKSArIChsYXN0ID8gMSA6IDApLCAzKTsKICAgICAgICAgIHNlbmRfYWxsX3RyZWVzKHMsIHMubF9kZXNjLm1heF9jb2RlICsgMSwgcy5kX2Rlc2MubWF4X2NvZGUgKyAxLCBtYXhfYmxpbmRleCArIDEpOwogICAgICAgICAgY29tcHJlc3NfYmxvY2socywgcy5keW5fbHRyZWUsIHMuZHluX2R0cmVlKTsKICAgICAgICB9CiAgICAgICAgaW5pdF9ibG9jayhzKTsKICAgICAgICBpZiAobGFzdCkgewogICAgICAgICAgYmlfd2luZHVwKHMpOwogICAgICAgIH0KICAgICAgfQogICAgICBmdW5jdGlvbiBfdHJfdGFsbHkocywgZGlzdCwgbGMpIHsKICAgICAgICBzLnBlbmRpbmdfYnVmW3MuZF9idWYgKyBzLmxhc3RfbGl0ICogMl0gPSBkaXN0ID4+PiA4ICYgMjU1OwogICAgICAgIHMucGVuZGluZ19idWZbcy5kX2J1ZiArIHMubGFzdF9saXQgKiAyICsgMV0gPSBkaXN0ICYgMjU1OwogICAgICAgIHMucGVuZGluZ19idWZbcy5sX2J1ZiArIHMubGFzdF9saXRdID0gbGMgJiAyNTU7CiAgICAgICAgcy5sYXN0X2xpdCsrOwogICAgICAgIGlmIChkaXN0ID09PSAwKSB7CiAgICAgICAgICBzLmR5bl9sdHJlZ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CBuID0gMDsKICAgICAgICB3aGlsZSAobGVuICE9PSAwKSB7CiAgICAgICAgICBuID0gbGVuID4gMmUzID8gMmUzIDogbGVuOwogICAgICAgICAgbGVuIC09IG47CiAgICAgICAgICBkbyB7CiAgICAgICAgICAgIHMxID0gczEgKyBidWZbcG9zKytdIHwgMDsKICAgICAgICAgICAgczIgPSBzMiArIHMxIHwgMDsKICAgICAgICAgIH0gd2hpbGUgKC0tbik7CiAgICAgICAgICBzMSAlPSA2NTUyMTsKICAgICAgICAgIHMyICU9IDY1NTIxOwogICAgICAgIH0KICAgICAgICByZXR1cm4gczEgfCBzMiA8PCAxNiB8IDA7CiAgICAgIH0KICAgICAgbW9kdWxlMi5leHBvcnRzID0gYWRsZXIzMjsKICAgIH0KICB9KTsKCiAgLy8gbm9kZV9tb2R1bGVzLy5wbnBtL3Bha29AMS4wLjExL25vZGVfbW9kdWxlcy9wYWtvL2xpYi96bGliL2NyYzMyLmpzCiAgdmFyIHJlcXVpcmVfY3JjMzIgPSBfX2NvbW1vbkpTKHsKICAgICJub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvY3JjMzIuanMiKGV4cG9ydHMyLCBtb2R1bGUyKSB7CiAgICAgIGluaXRfYnVmZmVyX3NoaW0oKTsKICAgICAgInVzZSBzdHJpY3QiOwogICAgICBmdW5jdGlvbiBtYWtlVGFibGUoKSB7CiAgICAgICAgdmFyIGMsIHRhYmxlID0gW107CiAgICAgICAgZm9yICh2YXIgbiA9IDA7IG4gPCAyNTY7IG4rKykgewogICAgICAgICAgYyA9IG47CiAgICAgICAgICBmb3IgKHZhciBrID0gMDsgayA8IDg7IGsrKykgewogICAgICAgICAgICBjID0gYyAmIDEgPyAzOTg4MjkyMzg0IF4gYyA+Pj4gMSA6IGMgPj4+IDE7CiAgICAgICAgICB9CiAgICAgICAgICB0YWJsZVtuXSA9IGM7CiAgICAgICAgfQogICAgICAgIHJldHVybi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9PTkxZID0gMjsKICAgICAgdmFyIFpfUkxFID0gMzsKICAgICAgdmFyIFpfRklYRUQgPSA0OwogICAgICB2YXIgWl9ERUZBVUxUX1NUUkFURUdZID0gMDsKICAgICAgdmFyIFpfVU5LTk9XTiA9IDI7CiAgICAgIHZhciBaX0RFRkxBVEVEID0gODsKICAgICAgdmFyIE1BWF9NRU1fTEVWRUwgPSA5OwogICAgICB2YXIgTUFYX1dCSVRTID0gMTU7CiAgICAgIHZhciBERUZfTUVNX0xFVkVMID0gODsKICAgICAgdmFyIExFTkdUSF9DT0RFUyA9IDI5OwogICAgICB2YXIgTElURVJBTFMgPSAyNTY7CiAgICAgIHZhciBMX0NPREVTID0gTElURVJBTFMgKyAxICsgTEVOR1RIX0NPREVTOwogICAgICB2YXIgRF9DT0RFUyA9IDMwOwogICAgICB2YXIgQkxfQ09ERVMgPSAxOTsKICAgICAgdmFyIEhFQVBfU0laRSA9IDIgKiBMX0NPREVTICsgMTsKICAgICAgdmFyIE1BWF9CSVRTID0gMTU7CiAgICAgIHZhciBNSU5fTUFUQ0ggPSAzOwogICAgICB2YXIgTUFYX01BVENIID0gMjU4OwogICAgICB2YXIgTUlOX0xPT0tBSEVBRCA9IE1BWF9NQVRDSCArIE1JTl9NQVRDSCArIDE7CiAgICAgIHZhciBQUkVTRVRfRElDVCA9IDMyOwogICAgICB2YXIgSU5JVF9TVEFURSA9IDQyOwogICAgICB2YXIgRVhUUkFfU1RBVEUgPSA2OTsKICAgICAgdmFyIE5BTUVfU1RBVEUgPSA3MzsKICAgICAgdmFyIENPTU1FTlRfU1RBVEUgPSA5MTsKICAgICAgdmFyIEhDUkNfU1RBVEUgPSAxMDM7CiAgICAgIHZhciBCVVNZX1NUQVRFID0gMTEzOwogICAgICB2YXIgRklOSVNIX1NUQVRFID0gNjY2OwogICAgICB2YXIgQlNfTkVFRF9NT1JFID0gMTsKICAgICAgdmFyIEJTX0JMT0NLX0RPTkUgPSAyOwogICAgICB2YXIgQlNfRklOSVNIX1NUQVJURUQgPSAzOwogICAgICB2YXIgQlNfRklOSVNIX0RPTkUgPSA0OwogICAgICB2YXIgT1NfQ09ERSA9IDM7CiAgICAgIGZ1bmN0aW9uIGVycihzdHJtLCBlcnJvckNvZGUpIHsKICAgICAgICBzdHJtLm1zZyA9IG1zZ1tlcnJvckNvZGVdOwogICAgICAgIHJldHVybiBlcnJvckNvZGU7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gcmFuayhmKSB7CiAgICAgICAgcmV0dXJuIChmIDw8IDEpIC0gKGYgPiA0ID8gOSA6IDApOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIHplcm8oYnVmKSB7CiAgICAgICAgdmFyIGxlbiA9IGJ1Zi5sZW5ndGg7CiAgICAgICAgd2hpbGUgKC0tbGVuID49IDApIHsKICAgICAgICAgIGJ1ZltsZW5dID0gMDsKICAgICAgICB9CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZmx1c2hfcGVuZGluZyhzdHJtKSB7CiAgICAgICAgdmFyIHMgPSBzdHJtLnN0YXRlOwogICAgICAgIHZhciBsZW4gPSBzLnBlbmRpbmc7CiAgICAgICAgaWYgKGxlbiA+IHN0cm0uYXZhaWxfb3V0KSB7CiAgICAgICAgICBsZW4gPSBzdHJtLmF2YWlsX291dDsKICAgICAgICB9CiAgICAgICAgaWYgKGxlbiA9PT0gMCkgewogICAgICAgICAgcmV0dXJuOwogICAgICAgIH0KICAgICAgICB1dGlscy5hcnJheVNldChzdHJtLm91dHB1dCwgcy5wZW5kaW5nX2J1Ziwgcy5wZW5kaW5nX291dCwgbGVuLCBzdHJtLm5leHRfb3V0KTsKICAgICAgICBzdHJtLm5leHRfb3V0ICs9IGxlbjsKICAgICAgICBzLnBlbmRpbmdfb3V0ICs9IGxlbjsKICAgICAgICBzdHJtLnRvdGFsX291dCArPSBsZW47CiAgICAgICAgc3RybS5hdmFpbF9vdXQgLT0gbGVuOwogICAgICAgIHMucGVuZGluZyAtPSBsZW47CiAgICAgICAgaWYgKHMucGVuZGluZyA9PT0gMCkgewogICAgICAgICAgcy5wZW5kaW5nX291dCA9IDA7CiAgICAgICAgfQogICAgICB9CiAgICAgIGZ1bmN0aW9uIGZsdXNoX2Jsb2NrX29ubHkocywgbGFzdCkgewogICAgICAgIHRyZWVzLl90cl9mbHVzaF9ibG9jayhzLCBzLmJsb2NrX3N0YXJ0ID49IDAgPyBzLmJsb2NrX3N0YXJ0IDogLTEsIHMuc3Ryc3RhcnQgLSBzLmJsb2NrX3N0YXJ0LCBsYXN0KTsKICAgICAgICBzLmJsb2NrX3N0YXJ0ID0gcy5zdHJzdGFydDsKICAgICAgICBmbHVzaF9wZW5kaW5nKHMuc3RybSk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gcHV0X2J5dGUocywgYikgewogICAgICAgIHMucGVuZGluZ19idWZbcy5wZW5kaW5nKytdID0gYjsKICAgICAgfQogICAgICBmdW5jdGlvbiBwdXRTaG9ydE1TQihzLCBiKSB7CiAgICAgICAgcy5wZW5kaW5nX2J1ZltzLnBlbmRpbmcrK10gPSBiID4+PiA4ICYgMjU1OwogICAgICAgIHMucGVuZGluZ19idWZbcy5wZW5kaW5nKytdID0gYiAmIDI1NTsKICAgICAgfQogICAgICBmdW5jdGlvbiByZWFkX2J1ZihzdHJtLCBidWYsIHN0YXJ0LCBzaXplKSB7CiAgICAgICAgdmFyIGxlbiA9IHN0cm0uYXZhaWxfaW47CiAgICAgICAgaWYgKGxlbiA+IHNpemUpIHsKICAgICAgICAgIGxlbiA9IHNpemU7CiAgICAgICAgfQogICAgICAgIGlmIChsZW4gPT09IDApIHsKICAgICAgICAgIHJldHVybiAwOwogICAgICAgIH0KICAgICAgICBzdHJtLmF2YWlsX2luIC09IGxlbjsKICAgICAgICB1dGlscy5hcnJheVNldChidWYsIHN0cm0uaW5wdXQsIHN0cm0ubmV4dF9pbiwgbGVuLCBzdGFydCk7CiAgICAgICAgaWYgKHN0cm0uc3RhdGUud3JhcCA9PT0gMSkgewogICAgICAgICA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ndGggPj0gcy5nb29kX21hdGNoKSB7CiAgICAgICAgICBjaGFpbl9sZW5ndGggPj49IDI7CiAgICAgICAgfQogICAgICAgIGlmIChuaWNlX21hdGNoID4gcy5sb29rYWhlYWQpIHsKICAgICAgICAgIG5pY2VfbWF0Y2ggPSBzLmxvb2thaGVhZDsKICAgICAgICB9CiAgICAgICAgZG8gewogICAgICAgICAgbWF0Y2ggPSBjdXJfbWF0Y2g7CiAgICAgICAgICBpZiAoX3dpblttYXRjaCArIGJlc3RfbGVuXSAhPT0gc2Nhbl9lbmQgfHwgX3dpblttYXRjaCArIGJlc3RfbGVuIC0gMV0gIT09IHNjYW5fZW5kMSB8fCBfd2luW21hdGNoXSAhPT0gX3dpbltzY2FuXSB8fCBfd2luWysrbWF0Y2hdICE9PSBfd2luW3NjYW4gKyAxXSkgewogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgIH0KICAgICAgICAgIHNjYW4gKz0gMjsKICAgICAgICAgIG1hdGNoKys7CiAgICAgICAgICBkbyB7CiAgICAgICAgICB9IHdoaWxlIChfd2luWysrc2Nhbl0gPT09IF93aW5bKyttYXRjaF0gJiYgX3dpblsrK3NjYW5dID09PSBfd2luWysrbWF0Y2hdICYmIF93aW5bKytzY2FuXSA9PT0gX3dpblsrK21hdGNoXSAmJiBfd2luWysrc2Nhbl0gPT09IF93aW5bKyttYXRjaF0gJiYgX3dpblsrK3NjYW5dID09PSBfd2luWysrbWF0Y2hdICYmIF93aW5bKytzY2FuXSA9PT0gX3dpblsrK21hdGNoXSAmJiBfd2luWysrc2Nhbl0gPT09IF93aW5bKyttYXRjaF0gJiYgX3dpblsrK3NjYW5dID09PSBfd2luWysrbWF0Y2hdICYmIHNjYW4gPCBzdHJlbmQpOwogICAgICAgICAgbGVuID0gTUFYX01BVENIIC0gKHN0cmVuZCAtIHNjYW4pOwogICAgICAgICAgc2NhbiA9IHN0cmVuZCAtIE1BWF9NQVRDSDsKICAgICAgICAgIGlmIChsZW4gPiBiZXN0X2xlbikgewogICAgICAgICAgICBzLm1hdGNoX3N0YXJ0ID0gY3VyX21hdGNoOwogICAgICAgICAgICBiZXN0X2xlbiA9IGxlbjsKICAgICAgICAgICAgaWYgKGxlbiA+PSBuaWNlX21hdGNoKSB7CiAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgc2Nhbl9lbmQxID0gX3dpbltzY2FuICsgYmVzdF9sZW4gLSAxXTsKICAgICAgICAgICAgc2Nhbl9lbmQgPSBfd2luW3NjYW4gKyBiZXN0X2xlbl07CiAgICAgICAgICB9CiAgICAgICAgfSB3aGlsZSAoKGN1cl9tYXRjaCA9IHByZXZbY3VyX21hdGNoICYgd21hc2tdKSA+IGxpbWl0ICYmIC0tY2hhaW5fbGVuZ3RoICE9PSAwKTsKICAgICAgICBpZiAoYmVzdF9sZW4gPD0gcy5sb29rYWhlYWQpIHsKICAgICAgICAgIHJldHVybiBiZXN0X2xlbjsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHMubG9va2FoZWFkOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGZpbGxfd2luZG93KHMpIHsKICAgICAgICB2YXIgX3dfc2l6ZSA9IHMud19zaXplOwogICAgICAgIHZhciBwLCBuLCBtLCBtb3JlLCBzdHI7CiAgICAgICAgZG8gewogICAgICAgICAgbW9yZSA9IHMud2luZG93X3NpemUgLSBzLmxvb2thaGVhZCAtIHMuc3Ryc3RhcnQ7CiAgICAgICAgICBpZiAocy5zdHJzdGFydCA+PSBfd19zaXplICsgKF93X3NpemUgLSBNSU5fTE9PS0FIRUFEKSkgewogICAgICAgICAgICB1dGlscy5hcnJheVNldChzLndpbmRvdywgcy53aW5kb3csIF93X3NpemUsIF93X3NpemUsIDApOwogICAgICAgICAgICBzLm1hdGNoX3N0YXJ0IC09IF93X3NpemU7CiAgICAgICAgICAgIHMuc3Ryc3RhcnQgLT0gX3dfc2l6ZTsKICAgICAgICAgICAgcy5ibG9ja19zdGFydCAtPSBfd19zaXplOwogICAgICAgICAgICBuID0gcy5oYXNoX3NpemU7CiAgICAgICAgICAgIHAgPSBuOwogICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgbSA9IHMuaGVhZFstLXBdOwogICAgICAgICAgICAgIHMuaGVhZFtwXSA9IG0gPj0gX3dfc2l6ZSA/IG0gLSBfd19zaXplIDogMDsKICAgICAgICAgICAgfSB3aGlsZSAoLS1uKTsKICAgICAgICAgICAgbiA9IF93X3NpemU7CiAgICAgICAgICAgIHAgPSBuOwogICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgbSA9IHMucHJldlstLXBdOwogICAgICAgICAgICAgIHMucHJldltwXSA9IG0gPj0gX3dfc2l6ZSA/IG0gLSBfd19zaXplIDogMDsKICAgICAgICAgICAgfSB3aGlsZSAoLS1uKTsKICAgICAgICAgICAgbW9yZSArPSBfd19zaXplOwogICAgICAgICAgfQogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9pbiA9PT0gMCkgewogICAgICAgICAgICBicmVhazsKICAgICAgICAgIH0KICAgICAgICAgIG4gPSByZWFkX2J1ZihzLnN0cm0sIHMud2luZG93LCBzLnN0cnN0YXJ0ICsgcy5sb29rYWhlYWQsIG1vcmUpOwogICAgICAgICAgcy5sb29rYWhlYWQgKz0gbjsKICAgICAgICAgIGlmIChzLmxvb2thaGVhZCArIHMuaW5zZXJ0ID49IE1JTl9NQVRDSCkgewogICAgICAgICAgICBzdHIgPSBzLnN0cnN0YXJ0IC0gcy5pbnNlcnQ7CiAgICAgICAgICAgIHMuaW5zX2ggPSBzLndpbmRvd1tzdHJdOwogICAgICAgICAgICBzLmluc19oID0gKHMuaW5zX2ggPDwgcy5oYXNoX3NoaWZ0IF4gcy53aW5kb3dbc3RyICsgMV0pICYgcy5oYXNoX21hc2s7CiAgICAgICAgICAgIHdoaWxlIChzLmluc2VydCkgewogICAgICAgICAgICAgIHMuaW5zX2ggPSAocy5pbnNfaCA8PCBzLmhhc2hfc2hpZnQgXiBzLndpbmRvd1tzdHIgKyBNSU5fTUFUQ0ggLSAxXSkgJiBzLmhhc2hfbWFzazsKICAgICAgICAgICAgICBzLnByZXZbc3RyICYgcy53X21hc2tdID0gcy5oZWFkW3MuaW5zX2hdOwogICAgICAgICAgICAgIHMuaGVhZFtzLmluc19oXSA9IHN0cjsKICAgICAgICAgICAgICBzdHIrKzsKICAgICAgICAgICAgICBzLmluc2VydC0tOwogICAgICAgICAgICAgIGlmIChzLmxvb2thaGVhZCArIHMuaW5zZXJ0IDwgTUlOX01BVENIKSB7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9IHdoaWxlIChzLmxvb2thaGVhZCA8IE1JTl9MT09LQUhFQUQgJiYgcy5zdHJtLmF2YWlsX2luICE9PSAwKTsKICAgICAgfQogICAgICBmdW5jdGlvbiBkZWZsYXRlX3N0b3JlZChzLCBmbHVzaCkgewogICAgICAgIHZhciBtYXhfYmxvY2tfc2l6ZSA9IDY1NTM1OwogICAgICAgIGlmIChtYXhfYmxvY2tfc2l6ZSA+IHMucGVuZGluZ19idWZfc2l6ZSAtIDUpIHsKICAgICAgICAgIG1heF9ibG9ja19zaXplID0gcy5wZW5kaW5nX2J1Zl9zaXplIC0gNTsKICAgICAgICB9CiAgICAgICAgZm9yICg7IDsgKSB7CiAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPD0gMSkgewogICAgICAgICAgICBmaWxsX3dpbmRvdyhzKTsKICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkID09PSAwICYmIGZsdXNoID09PSBaX05PX0ZMVVNIKSB7CiAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPT09IDApIHsKICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgcy5zdHJzdGFydCArPSBzLmxvb2thaGVhZDsKICAgICAgICAgIHMubG9va2FoZWFkID0gMDsKICAgICAgICAgIHZhciBtYXhfc3RhcnQgPSBzLmJsb2NrX3N0YXJ0ICsgbWF4X2Jsb2NrX3NpemU7CiAgICAgICAgICBpZiAocy5zdHJzdGFydCA9PT0gMCB8fCBzLnN0cnN0YXJ0ID49IG1heF9zdGFydCkgewogICAgICAgICAgICBzLmxvb2thaGVhZCA9IHMuc3Ryc3RhcnQgLSBtYXhfc3RhcnQ7CiAgICAgICAgICAgIHMuc3Ryc3RhcnQgPSBtYXhfc3RhcnQ7CiAgICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgZmFsc2UpOwogICAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGlmIChzLnN0cnN0YXJ0IC0gcy5ibG9ja19zdGFydCA+PSBzLndfc2l6ZSAtIE1JTl9MT09LQUhFQUQpIHsKICAgICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCBmYWxzZSk7CiAgICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBzLmluc2VydCA9IDA7CiAgICAgICAgaWYgKGZsdXNoID09PSBaX0ZJTklTSCkgewogICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCB0cnVlKTsKICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgIHJldHVybiBCU19GSU5JU0hfU1RBUlRFRDsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBCU19GSU5JU0hfRE9ORTsKICAgICAgICB9CiAgICAgICAgaWYgKHMuc3Ryc3RhcnQgPiBzLmJsb2NrX3N0YXJ0KSB7CiAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIGZhbHNlKTsKICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZGVmbGF0ZV9mYXN0KHMsIGZsdXNoKSB7CiAgICAgICAgdmFyIGhhc2hfaGVhZDsKICAgICAgICB2YXIgYmZsdXNoOwogICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgaWYgKHMubG9va2FoZWFkIDwgTUlOX0xPT0tBSEVBRCkgewogICAgICAgICAgICBmaWxsX3dpbmRvdyhzKTsKICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkIDwgTUlOX0xPT0tBSEVBRCAmJiBmbHVzaCA9PT0gWl9OT19GTFVTSCkgewogICAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkID09PSAwKSB7CiAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGhhc2hfaGVhZCA9IDA7CiAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPj0gTUlOX01BVENIKSB7CiAgICAgICAgICAgIHMuaW5zX2ggPSAocy5pbnNfaCA8PCBzLmhhc2hfc2hpZnQgXiBzLndpbmRvd1tzLnN0cnN0YXJ0ICsgTUlOX01BVENIIC0gMV0pICYgcy5oYXNoX21hc2s7CiAgICAgICAgICAgIGhhc2hfaGVhZCA9IHMucHJldltzLnN0cnN0YXJ0ICYgcy53X21hc2tdID0gcy5oZWFkW3MuaW5zX2hdOwogICAgICAgICAgICBzLmhlYWRbcy5pbnNfaF0gPSBzLnN0cnN0YXJ0OwogICAgICAgICAgfQog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gICAgICAgIHMuc3Ryc3RhcnQgKz0gcy5tYXRjaF9sZW5ndGg7CiAgICAgICAgICAgICAgcy5tYXRjaF9sZW5ndGggPSAwOwogICAgICAgICAgICAgIHMuaW5zX2ggPSBzLndpbmRvd1tzLnN0cnN0YXJ0XTsKICAgICAgICAgICAgICBzLmluc19oID0gKHMuaW5zX2ggPDwgcy5oYXNoX3NoaWZ0IF4gcy53aW5kb3dbcy5zdHJzdGFydCArIDFdKSAmIHMuaGFzaF9tYXNrOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBiZmx1c2ggPSB0cmVlcy5fdHJfdGFsbHkocywgMCwgcy53aW5kb3dbcy5zdHJzdGFydF0pOwogICAgICAgICAgICBzLmxvb2thaGVhZC0tOwogICAgICAgICAgICBzLnN0cnN0YXJ0Kys7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoYmZsdXNoKSB7CiAgICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgZmFsc2UpOwogICAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcy5pbnNlcnQgPSBzLnN0cnN0YXJ0IDwgTUlOX01BVENIIC0gMSA/IHMuc3Ryc3RhcnQgOiBNSU5fTUFUQ0ggLSAxOwogICAgICAgIGlmIChmbHVzaCA9PT0gWl9GSU5JU0gpIHsKICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgdHJ1ZSk7CiAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICByZXR1cm4gQlNfRklOSVNIX1NUQVJURUQ7CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gQlNfRklOSVNIX0RPTkU7CiAgICAgICAgfQogICAgICAgIGlmIChzLmxhc3RfbGl0KSB7CiAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIGZhbHNlKTsKICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiBCU19CTE9DS19ET05FOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGRlZmxhdGVfc2xvdyhzLCBmbHVzaCkgewogICAgICAgIHZhciBoYXNoX2hlYWQ7CiAgICAgICAgdmFyIGJmbHVzaDsKICAgICAgICB2YXIgbWF4X2luc2VydDsKICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA8IE1JTl9MT09LQUhFQUQpIHsKICAgICAgICAgICAgZmlsbF93aW5kb3cocyk7CiAgICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA8IE1JTl9MT09LQUhFQUQgJiYgZmx1c2ggPT09IFpfTk9fRkxVU0gpIHsKICAgICAgICAgICAgICByZXR1cm4gQlNfTkVFRF9NT1JFOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA9PT0gMCkgewogICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBoYXNoX2hlYWQgPSAwOwogICAgICAgICAgaWYgKHMubG9va2FoZWFkID49IE1JTl9NQVRDSCkgewogICAgICAgICAgICBzLmluc19oID0gKHMuaW5zX2ggPDwgcy5oYXNoX3NoaWZ0IF4gcy53aW5kb3dbcy5zdHJzdGFydCArIE1JTl9NQVRDSCAtIDFdKSAmIHMuaGFzaF9tYXNrOwogICAgICAgICAgICBoYXNoX2hlYWQgPSBzLnByZXZbcy5zdHJzdGFydCAmIHMud19tYXNrXSA9IHMuaGVhZFtzLmluc19oXTsKICAgICAgICAgICAgcy5oZWFkW3MuaW5zX2hdID0gcy5zdHJzdGFydDsKICAgICAgICAgIH0KICAgIC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7CiAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICBpZiAoKytzLnN0cnN0YXJ0IDw9IG1heF9pbnNlcnQpIHsKICAgICAgICAgICAgICAgIHMuaW5zX2ggPSAocy5pbnNfaCA8PCBzLmhhc2hfc2hpZnQgXiBzLndpbmRvd1tzLnN0cnN0YXJ0ICsgTUlOX01BVENIIC0gMV0pICYgcy5oYXNoX21hc2s7CiAgICAgICAgICAgICAgICBoYXNoX2hlYWQgPSBzLnByZXZbcy5zdHJzdGFydCAmIHMud19tYXNrXSA9IHMuaGVhZFtzLmluc19oXTsKICAgICAgICAgICAgICAgIHMuaGVhZFtzLmluc19oXSA9IHMuc3Ryc3RhcnQ7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9IHdoaWxlICgtLXMucHJldl9sZW5ndGggIT09IDApOwogICAgICAgICAgICBzLm1hdGNoX2F2YWlsYWJsZSA9IDA7CiAgICAgICAgICAgIHMubWF0Y2hfbGVuZ3RoID0gTUlOX01BVENIIC0gMTsKICAgICAgICAgICAgcy5zdHJzdGFydCsrOwogICAgICAgICAgICBpZiAoYmZsdXNoKSB7CiAgICAgICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCBmYWxzZSk7CiAgICAgICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgaWYgKHMubWF0Y2hfYXZhaWxhYmxlKSB7CiAgICAgICAgICAgIGJmbHVzaCA9IHRyZWVzLl90cl90YWxseShzLCAwLCBzLndpbmRvd1tzLnN0cnN0YXJ0IC0gMV0pOwogICAgICAgICAgICBpZiAoYmZsdXNoKSB7CiAgICAgICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCBmYWxzZSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgcy5zdHJzdGFydCsrOwogICAgICAgICAgICBzLmxvb2thaGVhZC0tOwogICAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHMubWF0Y2hfYXZhaWxhYmxlID0gMTsKICAgICAgICAgICAgcy5zdHJzdGFydCsrOwogICAgICAgICAgICBzLmxvb2thaGVhZC0tOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAocy5tYXRjaF9hdmFpbGFibGUpIHsKICAgICAgICAgIGJmbHVzaCA9IHRyZWVzLl90cl90YWxseShzLCAwLCBzLndpbmRvd1tzLnN0cnN0YXJ0IC0gMV0pOwogICAgICAgICAgcy5tYXRjaF9hdmFpbGFibGUgPSAwOwogICAgICAgIH0KICAgICAgICBzLmluc2VydCA9IHMuc3Ryc3RhcnQgPCBNSU5fTUFUQ0ggLSAxID8gcy5zdHJzdGFydCA6IE1JTl9NQVRDSCAtIDE7CiAgICAgICAgaWYgKGZsdXNoID09PSBaX0ZJTklTSCkgewogICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCB0cnVlKTsKICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgIHJldHVybiBCU19GSU5JU0hfU1RBUlRFRDsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBCU19GSU5JU0hfRE9ORTsKICAgICAgICB9CiAgICAgICAgaWYgKHMubGFzdF9saXQpIHsKICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgZmFsc2UpOwogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIEJTX0JMT0NLX0RPTkU7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZGVmbGF0ZV9ybGUocywgZmx1c2gpIHsKICAgICAgICB2YXIgYmZsdXNoOwogICAgICAgIHZhciBwcmV2OwogICAgICAgIHZhciBzY2FuLCBzdHJlbmQ7CiAgICAgICAgdmFyIF93aW4gPSBzLndpbmRvdzsKICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA8PSBNQVhfTUFUQ0gpIHsKICAgICAgICAgICAgZmlsbF93aW5kb3cocyk7CiAgICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA8PSBNQVhfTUFUQ0ggJiYgZmx1c2ggPT09IFpfTk9fRkxVU0gpIHsKICAgICAgICAgICAgICByZXR1cm4gQlNfTkVFRF9NT1JFOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA9PT0gMCkgewogICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBzLm1hdGNoX2xlbmd0aCA9IDA7CiAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPj0gTUlOX01BVENIICYmIHMuc3Ryc3RhcnQgPiAwKSB7CiAgICAgICAgICAgIHNjYW4gPSBzLnN0cnN0YXJ0IC0gMTsKICAgICAgICAgICAgcHJldiA9IF93aW5bc2Nhbl07CiAgICAgICAgICAgIGlmIChwcmV2ID09PSBfd2luWysrc2Nhbl0gJiYgcHJldiA9PT0gX3dpblsrK3NjYW5dICYmIHByZXYgPT09IF93aW5bKytzY2FuXSkgewogICAgICAgICAgICAgIHN0cmVuZCA9IHMuc3Ryc3RhcnQgKyBNQVhfTUFUQ0g7CiAgICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgIH0gd2hpbGUgKHByZXYgPT09IF93aW5bKytzY2FuXSAmJiBwcmV2ID09PSBfd2luWysrc2Nhbl0gJiYgcHJldiA9PT0gX3dpblsrK3NjYW5dICYmIHByZXYgPT09IF93aW5bKytzY2FuXSAmJiBwcmV2ID09PSBfd2luWysrc2Nhbl0gJiYgcHJldiA9PT0gX3dpblsrK3NjYW5dICYmIHByZXYgPT09IF93aW5bKytzY2FuXSAmJiBwcmV2ID09PSBfd2luWysrc2Nhbl0gJiYgc2NhbiA8IHN0cmVuZCk7CiAgICAgICAgICAgICAgcy5tYXRjaF9sZW5ndGggPSBNQVhfTUFUQ0ggLSAoc3RyZW5kIC0gc2Nhbik7CiAgICAgICAgICAgICAgaWYgKHMubWF0Y2hfbGVuZ3RoID4gcy5sb29rYWhlYWQpIHsKICAgICAgICAgICAgICAgIHMubWF0Y2hfbGVuZ3RoID0gcy5sb29rYWhlYWQ7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBpZiAocy5tYXRjaF9sZW5ndGggPj0gTUlOX01BVENIKSB7CiAgICAgICAgICAgIGJmbHVzaCA9IHRyZWVzLl90cl90YWxseShzLCAxLCBzLm1hdGNoX2xlbmd0aCAtIE1JTl9NQVRDSCk7CiAgICAgICAgICAgIHMubG9va2FoZWFkIC09IHMubWF0Y2hfbGVuZ3RoOwogICAgICAgICAgICBzLnN0cnN0YXJ0ICs9IHMubWF0Y2hfbGVuZ3RoOwogICAgICAgICAgICBzLm1hdGNoX2xlbmd0aCA9IDA7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBiZmx1c2ggPSB0cmVlcy5fdHJfdGFsbHkocywgMCwgcy53aW5kb3dbcy5zdHJzdGFydF0pOwogICAgICAgICAgICBzLmxvb2thaGVhZC0tOwogICAgICAgICAgICBzLnN0cnN0YXJ0Kys7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoYmZsdXNoKSB7CiAgICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgZmFsc2UpOwogICAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcy5pbnNlcnQgPSAwOwogICAgICAgIGlmIChmbHVzaCA9PT0gWl9GSU5JU0gpIHsKICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgdHJ1ZSk7CiAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICByZXR1cm4gQlNfRklOSVNIX1NUQVJURUQ7CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gQlNfRklOSVNIX0RPTkU7CiAgICAgICAgfQogICAgICAgIGlmIChzLmxhc3RfbGl0KSB7CiAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIGZhbHNlKTsKICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiBCU19CTE9DS19ET05FOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGRlZmxhdGVfaHVmZihzLCBmbHVzaCkgewogICAgICAgIHZhciBiZmx1c2g7CiAgICAgICAgZm9yICg7IDsgKSB7CiAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPT09IDApIHsKICAgICAgICAgICAgZmlsbF93aW5kb3cocyk7CiAgICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA9PT0gMCkgewogICAgICAgICAgICAgIGlmIChmbHVzaCA9PT0gWl9OT19GTFVTSCkgewogICAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIHMubWF0Y2hfbGVuZ3RoID0gMDsKICAgICAgICAgIGJmbHVzaCA9IHRyZWVzLl90cl90YWxseShzLCAwLCBzLndpbmRvd1tzLnN0cnN0YXJ0XSk7CiAgICAgICAgICBzLmxvb2thaGVhZC0tOwogICAgICAgICAgcy5zdHJzdGFydCsrOwogICAgICAgICAgaWYgKGJmbHVzaCkgewogICAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIGZhbHNlKTsKICAgICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgICByZXR1cm4gQlNfTkVFRF9NT1JFOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHMuaW5zZXJ0ID0gMDsKICAgICAgICBpZiAoZmx1c2ggPT09IFpfRklOSVNIKSB7CiAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIHRydWUpOwogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIEJTX0ZJTklTSF9TVEFSVEVEOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIEJTX0ZJTklTSF9ET05FOwogICAgICAgIH0KICAgICAgICBpZiAocy5sYXN0X2xpdCkgewogICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCBmYWxzZSk7CiAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICByZXR1cm4gQlNfTkVFRF9NT1JFOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gQlNfQkxPQ0tfRE9ORTsKICAgICAgfQogICAgICBmdW5jdGlvbiBDb25maWcoZ29vZF9sZW5ndGgsIG1heF9sYXp5LCBuaWNlX2xlbmd0aCwgbWF4X2NoYWluLCBmdW5jKSB7CiAgICAgICAgdGhpcy5nb29kX2xlbmd0aCA9IGdvb2RfbGVuZ3RoOwogICAgICAgIHRoaXMubWF4X2xhenkgPSBtYXhfbGF6eTsKICAgICAgICB0aGlzLm5pY2VfbGVuZ3RoID0gbmljZV9sZW5ndGg7CiAgICAgICAgdGhpcy5tYXhfY2hhaW4gPSBtYXhfY2hhaW47CiAgICAgICAgdGhpcy5mdW5jID0gZnVuYzsKICAgIC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3RhYmxlW3MubGV2ZWxdLm5pY2VfbGVuZ3RoOwogICAgICAgIHMubWF4X2NoYWluX2xlbmd0aCA9IGNvbmZpZ3VyYXRpb25fdGFibGVbcy5sZXZlbF0ubWF4X2NoYWluOwogICAgICAgIHMuc3Ryc3RhcnQgPSAwOwogICAgICAgIHMuYmxvY2tfc3RhcnQgPSAwOwogICAgICAgIHMubG9va2FoZWFkID0gMDsKICAgICAgICBzLmluc2VydCA9IDA7CiAgICAgICAgcy5tYXRjaF9sZW5ndGggPSBzLnByZXZfbGVuZ3RoID0gTUlOX01BVENIIC0gMTsKICAgICAgICBzLm1hdGNoX2F2YWlsYWJsZSA9IDA7CiAgICAgICAgcy5pbnNfaCA9IDA7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gRGVmbGF0ZVN0YXRlKCkgewogICAgICAgIHRoaXMuc3RybSA9IG51bGw7CiAgICAgICAgdGhpcy5zdGF0dXMgPSAwOwogICAgICAgIHRoaXMucGVuZGluZ19idWYgPSBudWxsOwogICAgICAgIHRoaXMucGVuZGluZ19idWZfc2l6ZSA9IDA7CiAgICAgICAgdGhpcy5wZW5kaW5nX291dCA9IDA7CiAgICAgICAgdGhpcy5wZW5kaW5nID0gMDsKICAgICAgICB0aGlzLndyYXAgPSAwOwogICAgICAgIHRoaXMuZ3poZWFkID0gbnVsbDsKICAgICAgICB0aGlzLmd6aW5kZXggPSAwOwogICAgICAgIHRoaXMubWV0aG9kID0gWl9ERUZMQVRFRDsKICAgICAgICB0aGlzLmxhc3RfZmx1c2ggPSAtMTsKICAgICAgICB0aGlzLndfc2l6ZSA9IDA7CiAgICAgICAgdGhpcy53X2JpdHMgPSAwOwogICAgICAgIHRoaXMud19tYXNrID0gMDsKICAgICAgICB0aGlzLndpbmRvdyA9IG51bGw7CiAgICAgICAgdGhpcy53aW5kb3dfc2l6ZSA9IDA7CiAgICAgICAgdGhpcy5wcmV2ID0gbnVsbDsKICAgICAgICB0aGlzLmhlYWQgPSBudWxsOwogICAgICA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PSBzdHJtLnN0YXRlOwogICAgICAgIHMucGVuZGluZyA9IDA7CiAgICAgICAgcy5wZW5kaW5nX291dCA9IDA7CiAgICAgICAgaWYgKHMud3JhcCA8IDApIHsKICAgICAgICAgIHMud3JhcCA9IC1zLndyYXA7CiAgICAgICAgfQogICAgICAgIHMuc3RhdHVzID0gcy53cmFwID8gSU5JVF9TVEFURSA6IEJVU1lfU1RBVEU7CiAgICAgICAgc3RybS5hZGxlciA9IHMud3JhcCA9PT0gMiA/IDAgOiAxOwogICAgICAgIHMubGFzdF9mbHVzaCA9IFpfTk9fRkxVU0g7CiAgICAgICAgdHJlZXMuX3RyX2luaXQocyk7CiAgICAgICAgcmV0dXJuIFpfT0s7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZGVmbGF0ZVJlc2V0KHN0cm0pIHsKICAgICAgICB2YXIgcmV0ID0gZGVmbGF0ZVJlc2V0S2VlcChzdHJtKTsKICAgICAgICBpZiAocmV0ID09PSBaX09LKSB7CiAgICAgICAgICBsbV9pbml0KHN0cm0uc3RhdGUpOwogICAgICAgIH0KICAgICAgICByZXR1cm4gcmV0OwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGRlZmxhdGVTZXRIZWFkZXIoc3RybSwgaGVhZCkgewogICAgICAgIGlmICghc3RybSB8fCAhc3RybS5zdGF0ZSkgewogICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VSUk9SOwogICAgICAgIH0KICAgICAgICBpZiAoc3RybS5zdGF0ZS53cmFwICE9PSAyKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIHN0cm0uc3RhdGUuZ3poZWFkID0gaGVhZDsKICAgICAgICByZXR1cm4gWl9PSzsKICAgICAgfQogICAgICBmdW5jdGlvbiBkZWZsYXRlSW5pdDIoc3RybSwgbGV2ZWwsIG1ldGhvZCwgd2luZG93Qml0cywgbWVtTGV2ZWwsIHN0cmF0ZWd5KSB7CiAgICAgICAgaWYgKCFzdHJtKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIHZhciB3cmFwID0gMTsKICAgICAgICBpZiAobGV2ZWwgPT09IFpfREVGQVVMVF9DT01QUkVTU0lPTikgewogICAgICAgICAgbGV2ZWwgPSA2OwogICAgICAgIH0KICAgICAgICBpZiAod2luZG93Qml0cyA8IDApIHsKICAgICAgICAgIHdyYXAgPSAwOwogICAgICAgICAgd2luZG93Qml0cyA9IC13aW5kb3dCaXRzOwogICAgICAgIH0gZWxzZSBpZiAod2luZG93Qml0cyA+IDE1KSB7CiAgICAgICAgICB3cmFwID0gMjsKICAgICAgICAgIHdpbmRvd0JpdHMgLT0gMTY7CiAgICAgICAgfQogICAgICAgIGlmIChtZW1MZXZlbCA8IDEgfHwgbWVtTGV2ZWwgPiBNQVhfTUVNX0xFVkVMIHx8IG1ldGhvZCAhPT0gWl9ERUZMQVRFRCB8fCB3aW5kb3dCaXRzIDwgOCB8fCB3aW5kb3dCaXRzID4gMTUgfHwgbGV2ZWwgPCAwIHx8IGxldmVsID4gOSB8fCBzdHJhdGVneSA8IDAgfHwgc3RyYXRlZ3kgPiBaX0ZJWEVEKSB7CiAgICAgICAgICByZXR1cm4gZXJyKHN0cm0sIFpfU1RSRUFNX0VSUk9SKTsKICAgICAgICB9CiAgICAgICAgaWYgKHdpbmRvd0JpdHMgPT09IDgpIHsKICAgICAgICAgIHdpbmRvd0JpdHMgPSA5OwogICAgICAgIH0KICAgICAgICB2YXIgcyA9IG5ldyBEZWZsYXRlU3RhdGUoKTsKICAgICAgICBzdHJtLnN0YXRlID0gczsKICAgICAgICBzLnN0cm0gPSBzdHJtOwogICAgICAgIHMud3JhcCA9IHdyYXA7CiAgICAgICAgcy5nemhlYWQgPSBudWxsOwogICAgICAgIHMud19iaXRzID0gd2luZG93Qml0czsKICAgICAgICBzLndfc2l6ZSA9IDEgPDwgcy53X2JpdHM7CiAgICAgICAgcy53X21hc2sgP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cHV0X2J5dGUocywgMCk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgMCk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgMCk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgcy5sZXZlbCA9PT0gOSA/IDIgOiBzLnN0cmF0ZWd5ID49IFpfSFVGRk1BTl9PTkxZIHx8IHMubGV2ZWwgPCAyID8gNCA6IDApOwogICAgICAgICAgICAgIHB1dF9ieXRlKHMsIE9TX0NPREUpOwogICAgICAgICAgICAgIHMuc3RhdHVzID0gQlVTWV9TVEFURTsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCAocy5nemhlYWQudGV4dCA/IDEgOiAwKSArIChzLmd6aGVhZC5oY3JjID8gMiA6IDApICsgKCFzLmd6aGVhZC5leHRyYSA/IDAgOiA0KSArICghcy5nemhlYWQubmFtZSA/IDAgOiA4KSArICghcy5nemhlYWQuY29tbWVudCA/IDAgOiAxNikpOwogICAgICAgICAgICAgIHB1dF9ieXRlKHMsIHMuZ3poZWFkLnRpbWUgJiAyNTUpOwogICAgICAgICAgICAgIHB1dF9ieXRlKHMsIHMuZ3poZWFkLnRpbWUgPj4gOCAmIDI1NSk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgcy5nemhlYWQudGltZSA+PiAxNiAmIDI1NSk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgcy5nemhlYWQudGltZSA+PiAyNCAmIDI1NSk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgcy5sZXZlbCA9PT0gOSA/IDIgOiBzLnN0cmF0ZWd5ID49IFpfSFVGRk1BTl9PTkxZIHx8IHMubGV2ZWwgPCAyID8gNCA6IDApOwogICAgICAgICAgICAgIHB1dF9ieXRlKHMsIHMuZ3poZWFkLm9zICYgMjU1KTsKICAgICAgICAgICAgICBpZiAocy5nemhlYWQuZXh0cmEgJiYgcy5nemhlYWQuZXh0cmEubGVuZ3RoKSB7CiAgICAgICAgICAgICAgICBwdXRfYnl0ZShzLCBzLmd6aGVhZC5leHRyYS5sZW5ndGggJiAyNTUpOwogICAgICAgICAgICAgICAgcHV0X2J5dGUocywgcy5nemhlYWQuZXh0cmEubGVuZ3RoID4+IDggJiAyNTUpOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBpZiAocy5nemhlYWQuaGNyYykgewogICAgICAgICAgICAgICAgc3RybS5hZGxlciA9IGNyYzMyKHN0cm0uYWRsZXIsIHMucGVuZGluZ19idWYsIHMucGVuZGluZywgMCk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIHMuZ3ppbmRleCA9IDA7CiAgICAgICAgICAgICAgcy5zdGF0dXMgPSBFWFRSQV9TVEFURTsKICAgICAgICAgICAgfQogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgdmFyIGhlYWRlciA9IFpfREVGTEFURUQgKyAocy53X2JpdHMgLSA4IDw8IDQpIDw8IDg7CiAgICAgICAgICAgIHZhciBsZXZlbF9mbGFncyA9IC0xOwogICAgICAgICAgICBpZiAocy5zdHJhdGVneSA+PSBaX0hVRkZNQU5fT05MWSB8fCBzLmxldmVsIDwgMikgewogICAgICAgICAgICAgIGxldmVsX2ZsYWdzID0gMDsKICAgICAgICAgICAgfSBlbHNlIGlmIChzLmxldmVsIDwgNikgewogICAgICAgICAgICAgIGxldmVsX2ZsYWdzID0gMTsKICAgICAgICAgICAgfSBlbHNlIGlmIChzLmxldmVsID09PSA2KSB7CiAgICAgICAgICAgICAgbGV2ZWxfZmxhZ3MgPSAyOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIGxldmVsX2ZsYWdzID0gMzsKICAgICAgICAgICAgfQogICAgICAgICAgICBoZWFkZXIgfD0gbGV2ZWxfZmxhZ3MgPDwgNjsKICAgICAgICAgICAgaWYgKHMuc3Ryc3RhcnQgIT09IDApIHsKICAgICAgICAgICAgICBoZWFkZXIgfD0gUFJFU0VUX0RJQ1Q7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaGVhZGVyICs9IDMxIC0gaGVhZGVyICUgMzE7CiAgICAgICAgICAgIHMuc3RhdHVzID0gQlVTWV9TVEFURTsKICAgICAgICAgICAgcHV0U2hvcnRNU0IocywgaGVhZGVyKTsKICAgICAgICAgICAgaWYgKHMuc3Ryc3RhcnQgIT09IDApIHsKICAgICAgICAgICAgICBwdXRTaG9ydE1TQihzLCBzdHJtLmFkbGVyID4+PiAxNik7CiAgICAgICAgICAgICAgcHV0U2hvcnRNU0Iocywgc3RybS5hZGxlciAmIDY1NTM1KTsKICAgICAgICAgICAgfQogICAgICAgICAgICBzdHJtLmFkbGVyID0gMTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKHMuc3RhdHVzID09PSBFWFRSQV9TVEFURSkgewogICAgICAgICAgaWYgKHMuZ3poZWFkLmV4dHJhKSB7CiAgICAgICAgICAgIGJlZyA9IHMucGVuZGluZzsKICAgICAgICAgICAgd2hpbGUgKHMuZ3ppbmRleCA8IChzLmd6aGVhZC5leHRyYS5sZW5ndGggJiA2NTUzNSkpIHsKICAgICAgICAgICAgICBpZiAocy5wZW5kaW5nID09PSBzLnBlbmRpbmdfYnVmX3NpemUpIHsKICAgICAgICAgICAgICAgIGlmIChzLmd6aGVhZC5oY3JjICYmIHMucGVuZGluZyA+IGJlZykgewogICAgICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gY3JjMzIoc3RybS5hZGxlciwgcy5wZW5kaW5nX2J1Ziwgcy5wZW5kaW5nIC0gYmVnLCBiZWcpOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgZmx1c2hfcGVuZGluZyhzdHJtKTsKICAgICAgICAgICAgICAgIGJlZyA9IHMucGVuZGluZzsKICAgICAgICAgICAgICAgIGlmIChzLnBlbmRpbmcgPT09IHMucGVuZGluZ19idWZfc2l6ZSkgewogICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgcy5nemhlYWQuZXh0cmFbcy5nemluZGV4XSAmIDI1NSk7CiAgICAgICAgICAgICAgcy5nemluZGV4Kys7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHMuZ3poZWFkLmhjcmMgJiYgcy5wZW5kaW5nID4gYmVnKSB7CiAgICAgICAgICAgICAgc3RybS5hZGxlciA9IGNyYzMyKHN0cm0uYWRsZXIsIHMucGVuZGluZ19idWYsIHMucGVuZGluZyAtIGJlZywgYmVnKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAocy5nemluZGV4ID09PSBzLmd6aGVhZC5leHRyYS5sZW5ndGgpIHsKICAgICAgICAgICAgICBzLmd6aW5kZXggPSAwOwogICAgICAgICAgICAgIHMuc3RhdHVzID0gTkFNRV9TVEFURTsKICAgICAgICAgICAgfQogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcy5zdGF0dXMgPSBOQU1FX1NUQVRFOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAocy5zdGF0dXMgPT09IE5BTUVfU1RBVEUpIHsKICAgICAgICAgIGlmIChzLmd6aGVhZC5uYW1lKSB7CiAgICAgICAgICAgIGJlZyA9IHMucGVuZGluZzsKICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgIGlmIChzLnBlbmRpbmcgPT09IHMucGVuZGluZ19idWZfc2l6ZSkgewogICAgICAgICAgICAgICAgaWYgKHMuZ3poZWFkLmhjcmMgJiYgcy5wZW5kaW5nID4gYmVnKSB7CiAgICAgICAgICAgICAgICAgIHN0cm0uYWRsZXIgPSBjcmMzMihzdHJtLmFkbGVyLCBzLnBlbmRpbmdfYnVmLCBzLnBlbmRpbmcgLSBiZWcsIGJlZyk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBmbHVzaF9wZW5kaW5nKHN0cm0pOwogICAgICAgICAgICAgICAgYmVnID0gcy5wZW5kaW5nOwogICAgICAgICAgICAgICAgaWYgKHMucGVuZGluZyA9PT0gcy5wZW5kaW5nX2J1Zl9zaXplKSB7CiAgICAgICAgICAgICAgICAgIHZhbCA9IDE7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBpZiAocy5nemluZGV4IDwgcy5nemhlYWQubmFtZS5sZW5ndGgpIHsKICAgICAgICAgICAgICAgIHZhbCA9IHMuZ3poZWFkLm5hbWUuY2hhckNvZGVBdChzLmd6aW5kZXgrKykgJiAyNTU7CiAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIHZhbCA9IDA7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIHB1dF9ieXRlKHMsIHZhbCk7CiAgICAgICAgICAgIH0gd2hpbGUgKHZhbCAhPT0gMCk7CiAgICAgICAgICAgIGlmIChzLmd6aGVhZC5oY3JjICYmIHMucGVuZGluZyA+IGJlZykgewogICAgICAgICAgICAgIHN0cm0uYWRsZXIgPSBjcmMzMihzdHJtLmFkbGVyLCBzLnBlbmRpbmdfYnVmLCBzLnBlbmRpbmcgLSBiZWcsIGJlZyk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHZhbCA9PT0gMCkgewogICAgICAgICAgICAgIHMuZ3ppbmRleCA9IDA7CiAgICAgICAgICAgICAgcy5zdGF0dXMgPSBDT01NRU5UX1NUQVRFOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBzLnN0YXR1cyA9IENPTU1FTlRfU1RBVEU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChzLnN0YXR1cyA9PT0gQ09NTUVOVF9TVEFURSkgewogICAgICAgICAgaWYgKHMuZ3poZWFkLmNvbW1lbnQpIHsKICAgICAgICAgICAgYmVnID0gcy5wZW5kaW5nOwogICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgaWYgKHMucGVuZGluZyA9PT0gcy5wZW5kaW5nX2J1Zl9zaXplKSB7CiAgICAgICAgICAgICAgICBpZiAocy5nemhlYWQuaGNyYyAmJiBzLnBlbmRpbmcgPiBiZWcpIHsKICAgICAgICAgICAgICAgICAgc3RybS5hZGxlciA9IGNyYzMyKHN0cm0uYWRsZXIsIHMucGVuZGluZ19idWYsIHMucGVuZGluZyAtIGJlZywgYmVnKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGZsdXNoX3BlbmRpbmcoc3RybSk7CiAgICAgICAgICAgICAgICBiZWcgPSBzLnBlbmRpbmc7CiAgICAgICAgICAgICAgICBpZiAocy5wZW5kaW5nID09PSBzLnBlbmRpbmdfYnVmX3NpemUpIHsKICAgICAgICAgICAgICAgICAgdmFsID0gMTsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGlmIChzLmd6aW5kZXggPCBzLmd6aGVhZC5jb21tZW50Lmxlbmd0aCkgewogICAgICAgICAgICAgICAgdmFsID0gcy5nemhlYWQuY29tbWVudC5jaGFyQ29kZUF0KHMuZ3ppbmRleCsrKSAmIDI1NTsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgdmFsID0gMDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgdmFsKTsKICAgICAgICAgICAgfSB3aGlsZSAodmFsICE9PSAwKTsKICAgICAgICAgICAgaWYgKHMuZ3poZWFkLmhjcmMgJiYgcy5wZW5kaW5nID4gYmVnKSB7CiAgICAgICAgICAgICAgc3RybS5hZGxlciA9IGNyYzMyKHN0cm0uYWRsZXIsIHMucGVuZGluZ19idWYsIHMucGVuZGluZyAtIGJlZywgYmVnKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAodmFsID09PSAwKSB7CiAgICAgICAgICAgICAgcy5zdGF0dXMgPSBIQ1JDX1NUQVRFOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBzLnN0YXR1cyA9IEhDUkNfU1RBVEU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChzLnN0YXR1cyA9PT0gSENSQ19TVEFURSkgewogICAgICAgICAgaWYgKHMuZ3poZWFkLmhjcmMpIHsKICAgICAgICAgICAgaWYgKHMucGVuZGluZyArIDIgPiBzLnBlbmRpbmdfYnVmX3NpemUpIHsKICAgICAgICAgICAgICBmbHVzaF9wZW5kaW5nKHN0cm0pOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzLnBlbmRpbmcgKyAyIDw9IHMucGVuZGluZ19idWZfc2l6ZSkgewogICAgICAgICAgICAgIHB1dF9ieXRlKHMsIHN0cm0uYWRsZXIgJiAyNTUpOwogICAgICAgICAgICAgIHB1dF9ieXRlKHMsIHN0cm0uYWRsZXIgPj4gOCAmIDI1NSk7CiAgICAgICAgICAgICAgc3RybS5hZGxlciA9IDA7CiAgICAgICAgICAgICAgcy5zdGF0dXMgPSBCVVNZX1NUQVRFOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBzLnN0YXR1cyA9IEJVU1lfU1RBVEU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChzLnBlbmRpbmcgIT09IDApIHsKICAgICAgICAgIGZsdXNoX3BlbmRpbmcoc3RybSk7CiAgICAgICAgICBpZiAoc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcy5sYXN0X2ZsdXNoID0gLTE7CiAgICAgICAgICAgIHJldHVybiBaX09LOwogICAgICAgICAgfQogICAgICAgIH0gZWxzZSBpZiAoc3RybS5hdmFpbF9pbiA9PT0gMCAmJiByYW5rKGZsdXNoKSA8PSByYW5rKG9sZF9mbHVzaCkgJiYgZmx1c2ggIT09IFpfRklOSVNIKSB7CiAgICAgICAgICByZXR1cm4gZXJyKHN0cm0sIFpfQlVGX0VSUk9SKTsKICAgICAgICB9CiAgICAgIC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gICAgICB9IGVsc2UgaWYgKGZsdXNoICE9PSBaX0JMT0NLKSB7CiAgICAgICAgICAgICAgdHJlZXMuX3RyX3N0b3JlZF9ibG9jayhzLCAwLCAwLCBmYWxzZSk7CiAgICAgICAgICAgICAgaWYgKGZsdXNoID09PSBaX0ZVTExfRkxVU0gpIHsKICAgICAgICAgICAgICAgIHplcm8ocy5oZWFkKTsKICAgICAgICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA9PT0gMCkgewogICAgICAgICAgICAgICAgICBzLnN0cnN0YXJ0ID0gMDsKICAgICAgICAgICAgICAgICAgcy5ibG9ja19zdGFydCA9IDA7CiAgICAgICAgICAgICAgICAgIHMuaW5zZXJ0ID0gMDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZmx1c2hfcGVuZGluZyhzdHJtKTsKICAgICAgICAgICAgaWYgKHN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgICAgcy5sYXN0X2ZsdXNoID0gLTE7CiAgICAgICAgICAgICAgcmV0dXJuIFpfT0s7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKGZsdXNoICE9PSBaX0ZJTklTSCkgewogICAgICAgICAgcmV0dXJuIFpfT0s7CiAgICAgICAgfQogICAgICAgIGlmIChzLndyYXAgPD0gMCkgewogICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VORDsKICAgICAgICB9CiAgICAgICAgaWYgKHMud3JhcCA9PT0gMikgewogICAgICAgICAgcHV0X2J5dGUocywgc3RybS5hZGxlciAmIDI1NSk7CiAgICAgICAgICBwdXRfYnl0ZShzLCBzdHJtLmFkbGVyID4+IDggJiAyNTUpOwogICAgICAgICAgcHV0X2J5dGUocywgc3RybS5hZGxlciA+PiAxNiAmIDI1NSk7CiAgICAgICAgICBwdXRfYnl0ZShzLCBzdHJtLmFkbGVyID4+IDI0ICYgMjU1KTsKICAg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Ioc3RybSwgWl9TVFJFQU1fRVJST1IpOwogICAgICAgIH0KICAgICAgICBzdHJtLnN0YXRlID0gbnVsbDsKICAgICAgICByZXR1cm4gc3RhdHVzID09PSBCVVNZX1NUQVRFID8gZXJyKHN0cm0sIFpfREFUQV9FUlJPUikgOiBaX09LOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGRlZmxhdGVTZXREaWN0aW9uYXJ5KHN0cm0sIGRpY3Rpb25hcnkpIHsKICAgICAgICB2YXIgZGljdExlbmd0aCA9IGRpY3Rpb25hcnkubGVuZ3RoOwogICAgICAgIHZhciBzOwogICAgICAgIHZhciBzdHIsIG47CiAgICAgICAgdmFyIHdyYXA7CiAgICAgICAgdmFyIGF2YWlsOwogICAgICAgIHZhciBuZXh0OwogICAgICAgIHZhciBpbnB1dDsKICAgICAgICB2YXIgdG1wRGljdDsKICAgICAgICBpZiAoIXN0cm0gfHwgIXN0cm0uc3RhdGUpIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgcyA9IHN0cm0uc3RhdGU7CiAgICAgICAgd3JhcCA9IHMud3JhcDsKICAgICAgICBpZiAod3JhcCA9PT0gMiB8fCB3cmFwID09PSAxICYmIHMuc3RhdHVzICE9PSBJTklUX1NUQVRFIHx8IHMubG9va2FoZWFkKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIGlmICh3cmFwID09PSAxKSB7CiAgICAgICAgICBzdHJtLmFkbGVyID0gYWRsZXIzMihzdHJtLmFkbGVyLCBkaWN0aW9uYXJ5LCBkaWN0TGVuZ3RoLCAwKTsKICAgICAgICB9CiAgICAgICAgcy53cmFwID0gMDsKICAgICAgICBpZiAoZGljdExlbmd0aCA+PSBzLndfc2l6ZSkgewogICAgICAgICAgaWYgKHdyYXAgPT09IDApIHsKICAgICAgICAgICAgemVybyhzLmhlYWQpOwogICAgICAgICAgICBzLnN0cnN0YXJ0ID0gMDsKICAgICAgICAgICAgcy5ibG9ja19zdGFydCA9IDA7CiAgICAgICAgICAgIHMuaW5zZXJ0ID0gMDsKICAgICAgICAgIH0KICAgICAgICAgIHRtcERpY3QgPSBuZXcgdXRpbHMuQnVmOChzLndfc2l6ZSk7CiAgICAgICAgICB1dGlscy5hcnJheVNldCh0bXBEaWN0LCBkaWN0aW9uYXJ5LCBkaWN0TGVuZ3RoIC0gcy53X3NpemUsIHMud19zaXplLCAwKTsKICAgICAgICAgIGRpY3Rpb25hcnkgPSB0bXBEaWN0OwogICAgICAgICAgZGljdExlbmd0aCA9IHMud19zaXplOwogICAgICAgIH0KICAgICAgICBhdmFpbCA9IHN0cm0uYXZhaWxfaW47CiAgICAgICAgbmV4dCA9IHN0cm0ubmV4dF9pbjsKICAgICAgICBpbnB1dCA9IHN0cm0uaW5wdXQ7CiAgICAgICAgc3RybS5hdmFpbF9pbiA9IGRpY3RMZW5ndGg7CiAgICAgICAgc3RybS5uZXh0X2luID0gMDsKICAgICAgICBzdHJtLmlucHV0ID0gZGljdGlvbmFyeTsKICAgICAgICBmaWxsX3dpbmRvdyhzKTsKICAgICAgICB3aGlsZSAocy5sb29rYWhlYWQgPj0gTUlOX01BVENIKSB7CiAgICAgICAgICBzdHIgPSBzLnN0cnN0YXJ0OwogICAgICAgICAgbiA9IHMubG9va2FoZWFkIC0gKE1JTl9NQVRDSCAtIDEpOwogICAgICAgICAgZG8gewogICAgICAgICAgICBzLmluc19oID0gKHMuaW5zX2ggPDwgcy5oYXNoX3NoaWZ0IF4gcy53aW5kb3dbc3RyICsgTUlOX01BVENIIC0gMV0pICYgcy5oYXNoX21hc2s7CiAgICAgICAgICAgIHMucHJldltzdHIgJiBzLndfbWFza10gPSBzLmhlYWRbcy5pbnNfaF07CiAgICAgICAgICAgIHMuaGVhZFtzLmluc19oXSA9IHN0cjsKICAgICAgICAgICAgc3RyKys7CiAgICAgICAgICB9IHdoaWxlICgtLW4pOwogICAgICAgICAgcy5zdHJ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gMSk7CiAgICAgICAgICAgIGlmICgoYzIgJiA2NDUxMikgPT09IDU2MzIwKSB7CiAgICAgICAgICAgICAgYyA9IDY1NTM2ICsgKGMgLSA1NTI5NiA8PCAxMCkgKyAoYzIgLSA1NjMyMCk7CiAgICAgICAgICAgICAgbV9wb3MrKzsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgaWYgKGMgPCAxMjgpIHsKICAgICAgICAgICAgYnVmW2krK10gPSBjOwogICAgICAgICAgfSBlbHNlIGlmIChjIDwgMjA0OCkgewogICAgICAgICAgICBidWZbaSsrXSA9IDE5MiB8IGMgPj4+IDY7CiAgICAgICAgICAgIGJ1ZltpKytdID0gMTI4IHwgYyAmIDYzOwogICAgICAgICAgfSBlbHNlIGlmIChjIDwgNjU1MzYpIHsKICAgICAgICAgICAgYnVmW2krK10gPSAyMjQgfCBjID4+PiAxMjsKICAgICAgICAgICAgYnVmW2krK10gPSAxMjggfCBjID4+PiA2ICYgNjM7CiAgICAgICAgICAgIGJ1ZltpKytdID0gMTI4IHwgYyAmIDYzOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgYnVmW2krK10gPSAyNDAgfCBjID4+PiAxODsKICAgICAgICAgICAgYnVmW2krK10gPSAxMjggfCBjID4+PiAxMiAmIDYzOwogICAgICAgICAgICBidWZbaSsrXSA9IDEyOCB8IGMgPj4+IDYgJiA2MzsKICAgICAgICAgICAgYnVmW2krK10gPSAxMjggfCBjICYgNjM7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiBidWY7CiAgICAgIH07CiAgICAgIGZ1bmN0aW9uIGJ1ZjJiaW5zdHJpbmcoYnVmLCBsZW4pIHsKICAgICAgICBpZiAobGVuIDwgNjU1MzQpIHsKICAgICAgICAgIGlmIChidWYuc3ViYXJyYXkgJiYgU1RSX0FQUExZX1VJQV9PSyB8fCAhYnVmLnN1YmFycmF5ICYmIFNUUl9BUFBMWV9PSykgewogICAgICAgICAgICByZXR1cm4gU3RyaW5nLmZyb21DaGFyQ29kZS5hcHBseShudWxsLCB1dGlscy5zaHJpbmtCdWYoYnVmLCBsZW4pKTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgdmFyIHJlc3VsdCA9ICIiOwogICAgICAgIGZvciAodmFyIGkgPSAwOyBpIDwgbGVuOyBpKyspIHsKICAgICAgICAgIHJlc3VsdCArPSBTdHJpbmcuZnJvbUNoYXJDb2RlKGJ1ZltpXSk7CiAgICAgICAgfQogICAgICAgIHJldHVybiByZXN1bHQ7CiAgICAgIH0KICAgICAgZXhwb3J0czIuYnVmMmJpbnN0cmluZyA9IGZ1bmN0aW9uKGJ1ZikgewogICAgICAgIHJldHVybiBidWYyYmluc3RyaW5nKGJ1ZiwgYnVmLmxlbmd0aCk7CiAgICAgIH07CiAgICAgIGV4cG9ydHMyLmJpbnN0cmluZzJidWYgPSBmdW5jdGlvbihzdHIpIHsKICAgICAgICB2YXIgYnVmID0gbmV3IHV0aWxzLkJ1Zjgoc3RyLmxlbmd0aCk7CiAgICAgICAgZm9yICh2YXIgaSA9IDAsIGxlbiA9IGJ1Zi5sZW5ndGg7IGkgPCBsZW47IGkrKykgewogICAgICAgICAgYnVmW2ldID0gc3RyLmNoYXJDb2RlQXQoaSk7CiAgICAgICAgfQogICAgICAgIHJldHVybiBidWY7CiAgICAgIH07CiAgICAgIGV4cG9ydHMyLmJ1ZjJzdHJpbmcgPSBmdW5jdGlvbihidWYsIG1heCkgewogICAgICAgIHZhciBpLCBvdXQsIGMsIGNfbGVuOwogICAgICAgIHZhciBsZW4gPSBtYXggfHwgYnVmLmxlbmd0aDsKICAgICAgICB2YXIgdXRmMTZidWYgPSBuZXcgQXJyYXkobGVuICogMik7CiAgICAgICAgZm9yIChvdXQgPSAwLCBpID0gMDsgaSA8IGxlbjsgKSB7CiAgICAgICAgICBjID0gYnVmW2krK107CiAgICAgICAgICBpZiAoYyA8IDEyOCkgewogICAgICAgICAgICB1dGYxNmJ1ZltvdXQrK10gPSBjOwogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgIH0KICAgICAgICAgIGNfbGVuID0gX3V0ZjhsZW5bY107CiAgICAgICAgICBpZiAoY19sZW4gPiA0KSB7CiAgICAgICAgICAgIHV0ZjE2YnVmW291dCsrXSA9IDY1NTMzOwogICAgICAgICAgICBpICs9IGNfbGVuIC0gMTsKICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICB9CiAgICAgICAgICBjICY9IGNfbGVuID09PSAyID8gMzEgOiBjX2xlbiA9PT0gMyA/IDE1IDogNzsKICAgICAgICAgIHdoaWxlIChjX2xlbiA+IDEgJiYgaSA8IGxlbikgewogICAgICAgICAgICBjID0gYyA8PCA2IHwgYnVmW2krK10gJiA2MzsKICAgICAgICAgICAgY19sZW4tLTsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChjX2xlbiA+IDEpIHsKICAgICAgICAgICAgdXRmMTZidWZbb3V0KytdID0gNjU1MzM7CiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgfQogICAgICAgICAgaWYgKGMgPCA2NTUzNikgewogICAgICAgICAgICB1dGYxNmJ1ZltvdXQrK10gPSBjOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgYyAtPSA2NTUzNjsKICAgICAgICAgICAgdXRmMTZidWZbb3V0KytdID0gNTUyOTYgfCBjID4+IDEwICYgMTAyMzsKICAgICAgICAgICAgdXRmMTZidWZbb3V0KytdID0gNTYzMjAgfCBjICYgMTAyMzsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIGJ1ZjJiaW5zdHJpbmcodXRmMTZidWYsIG91dCk7CiAgICAgIH07CiAgICAgIGV4cG9ydHMyLnV0Zjhib3JkZXIgPSBmdW5jdGlvbihidWYsIG1heCkgewogICAgICAgIHZhciBwb3M7CiAgICAgICAgbWF4ID0gbWF4IHx8IGJ1Zi5sZW5ndGg7CiAgICAgICAgaWYgKG1heCA+IGJ1Zi5sZW5ndGgpIHsKICAgICAgICAgIG1heCA9IGJ1Zi5sZW5ndGg7CiAgICAgICAgfQogICAgICAgIHBvcyA9IG1heCAtIDE7CiAgICAgICAgd2hpbGUgKHBvcyA+PSAwICYmIChidWZbcG9zXSAmIDE5MikgPT09IDEyOCkgewogICAgICAgICAgcG9zLS07CiAgICAgICAgfQogICAgICAgIGlmIChwb3MgPCAwKSB7CiAgICAgICAgICByZXR1cm4gbWF4OwogICAgICAgIH0KICAgICAgICBpZiAocG9zID09PSAwKSB7CiAgICAgICAgICByZXR1cm4gbWF4OwogICAgICAgIH0KICAgICAgICByZXR1cm4gcG9zICsgX3V0ZjhsZW5bYnVmW3Bvc11dID4gbWF4ID8gcG9zIDogbWF4OwogICAgICB9OwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvenN0cmVhbS5qcwogIHZhciByZXF1aXJlX3pzdHJlYW0gPSBfX2NvbW1vbkpTKHsKICAgICJub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvenN0cmVhbS5qcyIoZXhwb3J0czIsIG1vZHVsZTIpIHsKICAgICAgaW5pdF9idWZmZXJfc2hpbSgpOwogICAgICAidXNlIHN0cmljdCI7CiAgICAgIGZ1bmN0aW9uIFpTdHJlYW0oKSB7CiAgICAgICAgdGhpcy5pbnB1dCA9IG51bGw7CiAgICAgICAgdGhpcy5uZXh0X2luID0gMDsKICAgICAgICB0aGlzLmF2YWlsX2luID0gMDsKICAgICAgICB0aGlzLnRvdGFsX2luID0gMDsKICAgICAgICB0aGlzLm91dHB1dCA9IG51bGw7CiAgICAgICAgdGhpcy5uZXh0X291dCA9IDA7CiAgICAgICAgdGhpcy5hdmFpbF9vdXQgPSAwOwogICAgICAgIHRoaXMudG90YWxfb3V0ID0gMDsKICAgICAgICB0aGlzLm1zZyA9ICIiOwogICAgICAg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ZnVuY3Rpb24gRGVmbGF0ZShvcHRpb25zKSB7CiAgICAgICAgaWYgKCEodGhpcyBpbnN0YW5jZW9mIERlZmxhdGUpKQogICAgICAgICAgcmV0dXJuIG5ldyBEZWZsYXRlKG9wdGlvbnMpOwogICAgICAgIHRoaXMub3B0aW9ucyA9IHV0aWxzLmFzc2lnbih7CiAgICAgICAgICBsZXZlbDogWl9ERUZBVUxUX0NPTVBSRVNTSU9OLAogICAgICAgICAgbWV0aG9kOiBaX0RFRkxBVEVELAogICAgICAgICAgY2h1bmtTaXplOiAxNjM4NCwKICAgICAgICAgIHdpbmRvd0JpdHM6IDE1LAogICAgICAgICAgbWVtTGV2ZWw6IDgsCiAgICAgICAgICBzdHJhdGVneTogWl9ERUZBVUxUX1NUUkFURUdZLAogICAgICAgICAgdG86ICIiCiAgICAgICAgfSwgb3B0aW9ucyB8fCB7fSk7CiAgICAgICAgdmFyIG9wdCA9IHRoaXMub3B0aW9uczsKICAgICAgICBpZiAob3B0LnJhdyAmJiBvcHQud2luZG93Qml0cyA+IDApIHsKICAgICAgICAgIG9wdC53aW5kb3dCaXRzID0gLW9wdC53aW5kb3dCaXRzOwogICAgICAgIH0gZWxzZSBpZiAob3B0Lmd6aXAgJiYgb3B0LndpbmRvd0JpdHMgPiAwICYmIG9wdC53aW5kb3dCaXRzIDwgMTYpIHsKICAgICAgICAgIG9wdC53aW5kb3dCaXRzICs9IDE2OwogICAgICAgIH0KICAgICAgICB0aGlzLmVyciA9IDA7CiAgICAgICAgdGhpcy5tc2cgPSAiIjsKICAgICAgICB0aGlzLmVuZGVkID0gZmFsc2U7CiAgICAgICAgdGhpcy5jaHVua3MgPSBbXTsKICAgICAgICB0aGlzLnN0cm0gPSBuZXcgWlN0cmVhbSgpOwogICAgICAgIHRoaXMuc3RybS5hdmFpbF9vdXQgPSAwOwogICAgICAgIHZhciBzdGF0dXMgPSB6bGliX2RlZmxhdGUuZGVmbGF0ZUluaXQyKHRoaXMuc3RybSwgb3B0Lmxldm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KGRhdGEsIG1vZGUpIHsKICAgICAgICB2YXIgc3RybSA9IHRoaXMuc3RybTsKICAgICAgICB2YXIgY2h1bmtTaXplID0gdGhpcy5vcHRpb25zLmNodW5rU2l6ZTsKICAgICAgICB2YXIgc3RhdHVzLCBfbW9kZTsKICAgICAgICBpZiAodGhpcy5lbmRlZCkgewogICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICAgIH0KICAgICAgICBfbW9kZSA9IG1vZGUgPT09IH5+bW9kZSA/IG1vZGUgOiBtb2RlID09PSB0cnVlID8gWl9GSU5JU0ggOiBaX05PX0ZMVVNIOwogICAgICAgIGlmICh0eXBlb2YgZGF0YSA9PT0gInN0cmluZyIpIHsKICAgICAgICAgIHN0cm0uaW5wdXQgPSBzdHJpbmdzLnN0cmluZzJidWYoZGF0YSk7CiAgICAgICAgfSBlbHNlIGlmICh0b1N0cmluZy5jYWxsKGRhdGEpID09PSAiW29iamVjdCBBcnJheUJ1ZmZlcl0iKSB7CiAgICAgICAgICBzdHJtLmlucHV0ID0gbmV3IFVpbnQ4QXJyYXkoZGF0YSk7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIHN0cm0uaW5wdXQgPSBkYXRhOwogICAgICAgIH0KICAgICAgICBzdHJtLm5leHRfaW4gPSAwOwogICAgICAgIHN0cm0uYXZhaWxfaW4gPSBzdHJtLmlucHV0Lmxlbmd0aDsKICAgICAgICBkbyB7CiAgICAgICAgICBpZiAoc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgc3RybS5vdXRwdXQgPSBuZXcgdXRpbHMuQnVmOChjaHVua1NpemUpOwogICAgICAgICAgICBzdHJtLm5leHRfb3V0ID0gMDsKICAgICAgICAgICAgc3RybS5hdmFpbF9vdXQgPSBjaHVua1NpemU7CiAgICAgICAgICB9CiAgICAgICAgICBzdGF0dXMgPSB6bGliX2RlZmxhdGUuZGVmbGF0ZShzdHJtLCBfbW9kZSk7CiAgICAgICAgICBpZiAoc3RhdHVzICE9PSBaX1NUUkVBTV9FTkQgJiYgc3RhdHVzICE9PSBaX09LKSB7CiAgICAgICAgICAgIHRoaXMub25FbmQoc3RhdHVzKTsKICAgICAgICAgICAgdGhpcy5lbmRlZCA9IHRydWU7CiAgICAgICAgICAgIHJldHVybiBmYWxzZTsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChzdHJtLmF2YWlsX291dCA9PT0gMCB8fCBzdHJtLmF2YWlsX2luID09PSAwICYmIChfbW9kZSA9PT0gWl9GSU5JU0ggfHwgX21vZGUgPT09IFpfU1lOQ19GTFVTSDIpKSB7CiAgICAgICAgICAgIGlmICh0aGlzLm9wdGlvbnMudG8gPT09ICJzdHJpbmciKSB7CiAgICAgICAgICAgICAgdGhpcy5vbkRhdGEoc3RyaW5ncy5idWYyYmluc3RyaW5nKHV0aWxzLnNocmlua0J1ZihzdHJtLm91dHB1dCwgc3RybS5uZXh0X291dCkpKTsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICB0aGlzLm9uRGF0YSh1dGlscy5zaHJpbmtCdWYoc3RybS5vdXRwdXQsIHN0cm0ubmV4dF9vdXQpKTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0gd2hpbGUgKChzdHJtLmF2YWlsX2luID4gMCB8fCBzdHJtLmF2YWlsX291dCA9PT0gMCkgJiYgc3RhdHVzICE9PSBaX1NUUkVBTV9FTkQpOwogICAgICAgIGlmIChfbW9kZSA9PT0gWl9GSU5JU0gpIHsKICAgICAgICAgIHN0YXR1cyA9IHpsaWJfZGVmbGF0ZS5kZWZsYXRlRW5kKHRoaXMuc3RybSk7CiAgICAgICAgICB0aGlzLm9uRW5kKHN0YXR1cyk7CiAgICAgICAgICB0aGlzLmVuZGVkID0gdHJ1ZTsKICAgICAgICAgIHJldHVybiBzdGF0dXMgPT09IFpfT0s7CiAgICAgICAgfQogICAgICAgIGlmIChfbW9kZSA9PT0gWl9TWU5DX0ZMVVNIMikgewogICAgICAgICAgdGhpcy5vbkVuZChaX09LKTsKICAgICAgICAgIHN0cm0uYXZhaWxfb3V0ID0gMDsKICAgICAgICAgIHJldHVybiB0cnVlOwogICAgICAgIH0KICAgICAgICByZXR1cm4gdHJ1ZTsKICAgICAgfTsKICAgICAgRGVmbGF0ZS5wcm90b3R5cGUub25EYXRhID0gZnVuY3Rpb24oY2h1bmspIHsKICAgICAgICB0aGlzLmNodW5rcy5wdXNoKGNodW5rKTsKICAgICAgfTsKICAgICAgRGVmbGF0ZS5wcm90b3R5cGUub25FbmQgPSBmdW5jdGlvbihzdGF0dXMpIHsKICAgICAgICBpZiAoc3RhdHVzID09PSBaX09LKSB7CiAgICAgICAgICBpZiAodGhpcy5vcHRpb25zLnRvID09PSAic3RyaW5nIikgewogICAgICAgICAgICB0aGlzLnJlc3VsdCA9IHRoaXMuY2h1bmtzLmpvaW4oIiIpOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgdGhpcy5yZXN1bHQgPSB1dGlscy5mbGF0dGVuQ2h1bmtzKHRoaXMuY2h1bmtzKTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgdGhpcy5jaHVua3MgPSBbXTsKICAgICAgICB0aGlzLmVyciA9IHN0YXR1czsKICAgICAgICB0aGlzLm1zZyA9IHRoaXMuc3RybS5tc2c7CiAgICAgIH07CiAgICAgIGZ1bmN0aW9uIGRlZmxhdGUoaW5wdXQsIG9wdGlvbnMpIHsKICAgICAgICB2YXIgZGVmbGF0b3IgPSBuZXcgRGVmbGF0ZShvcHRpb25zKTsKICAgICAgICBkZWZsYXRvci5wdXNoKGlucHV0LCB0cnVlKTsKICAgICAgICBpZiAoZGVmbGF0b3IuZXJyKSB7CiAgICAgICAgICB0aHJvdyBkZWZsYXRvci5tc2cgfHwgbXNnW2RlZmxhdG9yLmVycl07CiAgICAgICAgfQogICAgICAgIHJldHVybiBkZWZsYXRvci5yZXN1bHQ7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZGVmbGF0ZVJhdyhpbn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iAgICAgICAgdmFyIF9vdXQ7CiAgICAgICAgdmFyIGJlZzsKICAgICAgICB2YXIgZW5kOwogICAgICAgIHZhciBkbWF4OwogICAgICAgIHZhciB3c2l6ZTsKICAgICAgICB2YXIgd2hhdmU7CiAgICAgICAgdmFyIHduZXh0OwogICAgICAgIHZhciBzX3dpbmRvdzsKICAgICAgICB2YXIgaG9sZDsKICAgICAgICB2YXIgYml0czsKICAgICAgICB2YXIgbGNvZGU7CiAgICAgICAgdmFyIGRjb2RlOwogICAgICAgIHZhciBsbWFzazsKICAgICAgICB2YXIgZG1hc2s7CiAgICAgICAgdmFyIGhlcmU7CiAgICAgICAgdmFyIG9wOwogICAgICAgIHZhciBsZW47CiAgICAgICAgdmFyIGRpc3Q7CiAgICAgICAgdmFyIGZyb207CiAgICAgICAgdmFyIGZyb21fc291cmNlOwogICAgICAgIHZhciBpbnB1dCwgb3V0cHV0OwogICAgICAgIHN0YXRlID0gc3RybS5zdGF0ZTsKICAgICAgICBfaW4gPSBzdHJtLm5leHRfaW47CiAgICAgICAgaW5wdXQgPSBzdHJtLmlucHV0OwogICAgICAgIGxhc3QgPSBfaW4gKyAoc3RybS5hdmFpbF9pbiAtIDUpOwogICAgICAgIF9vdXQgPSBzdHJtLm5leHRfb3V0OwogICAgICAgIG91dHB1dCA9IHN0cm0ub3V0cHV0OwogICAgICAgIGJlZyA9IF9vdXQgLSAoc3RhcnQgLSBzdHJtLmF2YWlsX291dCk7CiAgICAgICAgZW5kID0gX291dCArIChzdHJtLmF2YWlsX291dCAtIDI1Nyk7CiAgICAgICAgZG1heCA9IHN0YXRlLmRtYXg7CiAgICAgICAgd3NpemUgPSBzdGF0ZS53c2l6ZTsKICAgICAgICB3aGF2ZSA9IHN0YXRlLndoYXZlOwogICAgICAgIHduZXh0ID0gc3RhdGUud25leHQ7CiAgICAgICAgc193aW5kb3cgPSBzdGF0ZS53aW5kb3c7CiAgICAgICAgaG9sZCA9IHN0YXRlLmhvbGQ7CiAgICAgICAgYml0cyA9IHN0YXRlLmJpdHM7CiAgICAgICAgbGNvZGUgPSBzdGF0ZS5sZW5jb2RlOwogICAgICAgIGRjb2RlID0gc3RhdGUuZGlzdGNvZGU7CiAgICAgICAgbG1hc2sgPSAoMSA8PCBzdGF0ZS5sZW5iaXRzKSAtIDE7CiAgICAgICAgZG1hc2sgPSAoMSA8PCBzdGF0ZS5kaXN0Yml0cykgLSAxOwogICAgICAgIHRvcDoKICAgICAgICAgIGRvIHsKICAgICAgICAgICAgaWYgKGJpdHMgPCAxNSkgewogICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbX2luKytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbX2luKytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICB9CiAgICAgICAgICAgIGhlcmUgPSBsY29kZVtob2xkICYgbG1hc2tdOwogICAgICAgICAgICBkb2xlbjoKICAgICAgICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgICAgICAgIG9wID0gaGVyZSA+Pj4gMjQ7CiAgICAgICAgICAgICAgICBob2xkID4+Pj0gb3A7CiAgICAgICAgICAgICAgICBiaXRzIC09IG9wOwogICAgICAgICAgICAgICAgb3AgPSBoZXJlID4+PiAxNiAmIDI1NTsKICAgICAgICAgICAgICAgIGlmIChvcCA9PT0gMCkgewogICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IGhlcmUgJiA2NTUzNTsKICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAob3AgJiAxNikgewogICAgICAgICAgICAgICAgICBsZW4gPSBoZXJlICYgNjU1MzU7CiAgICAgICAgICAgICAgICAgIG9wICY9IDE1OwogICAgICAgICAgICAgICAgICBpZiAob3ApIHsKICAgICAgICAgICAgICAgICAgICBpZiAoYml0cyA8IG9wKSB7CiAgICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W19pbisrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBsZW4gKz0gaG9sZCAmICgxIDw8IG9wKSAtIDE7CiAgICAgICAgICAgICAgICAgICAgaG9sZCA+Pj49IG9wOwogICAgICAgICAgICAgICAgICAgIGJpdHMgLT0gb3A7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaWYgKGJpdHMgPCAxNSkgewogICAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbX2luKytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbX2luKytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGhlcmUgPSBkY29kZVtob2xkICYgZG1hc2tdOwogICAgICAgICAgICAgICAgICBkb2Rpc3Q6CiAgICAgICAgICAgICAgICAgICAgZm9yICg7IDsgKSB7CiAgICAgICAgICAgICAgICAgICAgICBvcCA9IGhlcmUgPj4+IDI0OwogICAgICAgICAgICAgICAgICAgICAgaG9sZCA+Pj49IG9wOwogICAgICAgICAgICAgICAgICAgICAgYml0cyAtPSBvcDsKICAgICAgICAgICAgICAgICAgICAgIG9wID0gaGVyZSA+Pj4gMTYgJiAyNTU7CiAgICAgICAgICAgICAgICAgICAgICBpZiAob3AgJiAxNikgewogICAgICAgICAgICAgICAgICAgICAgICBkaXN0ID0gaGVyZSAmIDY1NTM1OwogICAgICAgICAgICAgICAgICAgICAgICBvcCAmPSAxNTsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGJpdHMgPCBvcCkgewogICAgICAgICAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbX2luKytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChiaXRzIDwgb3ApIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbX2luKytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIGRpc3QgKz0gaG9sZCAmICgxIDw8IG9wKSAtIDE7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChkaXN0ID4gZG1heCkgewogICAgICAgICAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImludmFsaWQgZGlzdGFuY2UgdG9vIGZhciBiYWNrIjsKICAgICAgICAgICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEOwogICAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrIHRvcDsKICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICBob2xkID4+Pj0gb3A7CiAgICAgICAgICAgICAgICAgICAgICAgIGJpdHMgLT0gb3A7CiAgICAgICAgICAgICAgICAgICAgICAgIG9wID0gX291dCAtIGJlZzsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGRpc3QgPiBvcCkgewogICAgICAgICAgICAgICAgICAgICAgICAgIG9wID0gZGlzdCAtIG9wOwogICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChvcCA+IHdoYXZlKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoc3RhdGUuc2FuZSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbnZhbGlkIGRpc3RhbmNlIHRvbyBmYXIgYmFjayI7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrIHRvcDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgZnJvbSA9IDA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgZnJvbV9zb3VyY2UgPSBzX3dpbmRvdzsKICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAod25leHQgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZyb20gKz0gd3NpemUgLSBvcDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChvcCA8IGxlbikgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBsZW4gLT0gb3A7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IHNfd2luZG93W2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gd2hpbGUgKC0tb3ApOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tID0gX291dCAtIGRpc3Q7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZyb21fc291cmNlID0gb3V0cHV0OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAod25leHQgPCBvcCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgZnJvbSArPSB3c2l6ZSArIHduZXh0IC0gb3A7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBvcCAtPSB3bmV4dDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChvcCA8IGxlbikgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBsZW4gLT0gb3A7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IHNfd2luZG93W2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gd2hpbGUgKC0tb3ApOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tID0gMDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHduZXh0IDwgbGVuKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgb3AgPSB3bmV4dDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBsZW4gLT0gb3A7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBzX3dpbmRvd1tmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gd2hpbGUgKC0tb3ApOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZyb20gPSBfb3V0IC0gZGlzdDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tX3NvdXJjZSA9IG91dHB1dDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tICs9IHduZXh0IC0gb3A7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAob3AgPCBsZW4pIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbGVuIC09IG9wOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBzX3dpbmRvd1tmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IHdoaWxlICgtLW9wKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZnJvbSA9IF9vdXQgLSBkaXN0OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tX3NvdXJjZSA9IG91dHB1dDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgd2hpbGUgKGxlbiA+IDIpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gZnJvbV9zb3VyY2VbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gZnJvbV9zb3VyY2VbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gZnJvbV9zb3VyY2VbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxlbiAtPSAzOwogICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAobGVuKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IGZyb21fc291cmNlW2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAobGVuID4gMSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IGZyb21fc291cmNlW2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgIGZyb20gPSBfb3V0IC0gZGlzdDsKICAgICAgICAgICAgICAgICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IG91dHB1dFtmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBvdXRwdXRbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gb3V0cHV0W2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBsZW4gLT0gMzsKICAgICAgICAgICAgICAgICAgICAgICAgICB9IHdoaWxlIChsZW4gPiAyKTsKICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAobGVuKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IG91dHB1dFtmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGxlbiA+IDEpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBvdXRwdXRbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAoKG9wICYgNjQpID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGhlcmUgPSBkY29kZVsoaGVyZSAmIDY1NTM1KSArIChob2xkICYgKDEgPDwgb3ApIC0gMSldOwogICAgICAgICAgICAgICAgICAgICAgICBjb250aW51ZSBkb2Rpc3Q7CiAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbnZhbGlkIGRpc3RhbmNlIGNvZGUiOwogICAgICAgICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEOwogICAgICAgICAgICAgICAgICAgICAgICBicmVhayB0b3A7CiAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKChvcCAmIDY0KSA9PT0gMCkgewogICAgICAgICAgICAgICAgICBoZXJlID0gbGNvZGVbKGhlcmUgJiA2NTUzNSkgKyAoaG9sZCAmICgxIDw8IG9wKSAtIDEpXTsKICAgICAgICAgICAgICAgICAgY29udGludWUgZG9sZW47CiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKG9wICYgMzIpIHsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IFRZUEU7CiAgICAgICAgICAgICAgICAgIGJyZWFrIHRvcDsKICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImludmFsaWQgbGl0ZXJhbC9sZW5ndGggY29kZSI7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgIGJyZWFrIHRvcDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgIH0KICAgICAgICAgIH0gd2hpbGUgKF9pbiA8IGxhc3QgJiYgX291dCA8IGVuZCk7CiAgICAgICAgbGVuID0gYml0cyA+PiAzOwogICAgICAgIF9pbiAtPSBsZW47CiAgICAgICAgYml0cyAtPSBsZW4gPDwgMzsKICAgICAgICBob2xkICY9ICgxIDw8IGJpdHMpIC0gMTsKICAgICAgICBzdHJtLm5leHRfaW4gPSBfaW47CiAgICAgICAgc3RybS5uZXh0X291dCA9IF9vdXQ7CiAgICAgICAgc3RybS5hdmFpbF9pbiA9IF9pbiA8IGxhc3QgPyA1ICsgKGxhc3QgLSBfaW4pIDogNSAtIChfaW4gLSBsYXN0KTsKICAgICAgICBzdHJtLmF2YWlsX291dCA9IF9vdXQgPCBlbmQgPyAyNTcgKyAoZW5kIC0gX291dCkgOiAyNTcgLSAoX291dCAtIGVuZCk7CiAgICAgICAgc3RhdGUuaG9sZCA9IGhvbGQ7CiAgICAgICAgc3RhdGUuYml0cyA9IGJpdHM7CiAgICAgICAgcmV0dXJuOwogICAgICB9OwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvaW5mdHJlZXMuanMKICB2YXIgcmVxdWlyZV9pbmZ0cmVlcyA9IF9fY29tbW9uSlMoewogICAgIm5vZGVfbW9kdWxlcy8ucG5wbS9wYWtvQDEuMC4xMS9ub2RlX21vZHVsZXMvcGFrby9saWIvemxpYi9pbmZ0cmVlcy5qcyIoZXhwb3J0czIsIG1vZHVsZTIpIHsKICAgICAgaW5pdF9idWZmZXJfc2hpbSgpOwogICAgICAidXNlIHN0cmljdCI7CiAgICAgIHZhciB1dGlscyA9IHJlcXVpcmVfY29tbW9uKCk7CiAgICAgIHZhciBNQVhCSVRTID0gMTU7CiAgICAgIHZhciBFTk9VR0hfTEVOUyA9IDg1MjsKICAgICAgdmFyIEVOT1VHSF9ESVNUUyA9IDU5MjsKICAgICAgdmFyIENPREVTID0gMDsKICAgICAgdmFyIExFTlMgPSAxOwogICAgICB2YXIgRElTVFMgPSAyOwogICAgICB2YXIgbGJhc2UgPSBbCiAgICAgICAgMywKICAgICAgICA0LAogICAgICAgIDUsCiAgICAgICAgNiwKICAgICAgICA3LAogICAgICAgIDgsCiAgICAgICAgOSwKICAgICAgICAxMCwKICAgICAgICAxMSwKICAgICAgICAxMywKICAgICAgICAxNSwKICAgICAgICAxNywKICAgICAgICAxOSwKICAgICAgICAyMywKICAgICAgICAyNywKICAgICAgICAzMSwKICAgICAgICAzNSwKICAgICAgICA0MywKICAgICAgICA1MSwKICAgICAgICA1OSwKICAgICAgICA2NywKICAgICAgICA4MywKICAgICAgICA5OSwKICAgICAgICAxMTUsCiAgICAgICAgMTMxLAogICAgICAgIDE2MywKICAgICAgICAxOTUsCiAgICAgICAgMjI3LAogICAgICAgIDI1OCwKICAgICAgICAwLAogICAgICAgIDAKICAgICAgXTsKICAgICAgdmFyIGxleHQgPSBbCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTcsCiAgICAgICAgMTcsCiAgICAgICAgMTcsCiAgICAgICAgMTcsCiAgICAgICAgMTgsCiAgICAgICAgMTgsCiAgICAgICAgMTgsCiAgICAgICAgMTgsCiAgICAgICAgMTksCiAgICAgICAgMTksCiAgICAgICAgMTksCiAgICAgICAgMTksCiAgICAgICAgMjAsCiAgICAgICAgMjAsCiAgICAgICAgMjAsCiAgICAgICAgMjAsCiAgICAgICAgMjEsCiAgICAgICAgMjEsCiAgICAgICAgMjEsCiAgICAgICAgMjEsCiAgICAgICAgMTYsCiAgICAgICAgNzIsCiAgICAgICAgNzgKICAgICAgXTsKICAgICAgdmFyIGRiYXNlID0gWwogICAgICAgIDEsCiAgICAgICAgMiwKICAgICAgICAzLAogICAgICAgIDQsCiAgICAgICAgNSwKICAgICAgICA3LAogICAgICAgIDksCiAgICAgICAgMTMsCiAgICAgICAgMTcsCiAgICAgICAgMjUsCiAgICAgICAgMzMsCiAgICAgICAgNDksCiAgICAgICAgNjUsCiAgICAgICAgOTcsCiAgICAgICAgMTI5LAogICAgICAgIDE5MywKICAgICAgICAyNTcsCiAgICAgICAgMzg1LAogICAgICAgIDUxMywKICAgICAgICA3NjksCiAgICAgICAgMTAyNSwKICAgICAgICAxNTM3LAogICAgICAgIDIwNDksCiAgICAgICAgMzA3MywKICAgICAgICA0MDk3LAogICAgICAgIDYxNDUsCiAgICAgICAgODE5MywKICAgICAgICAxMjI4OSwKICAgICAgICAxNjM4NSwKICAgICAgICAyNDU3NywKICAgICAgICAwLAogICAgICAgIDAKICAgICAgXTsKICAgICAgdmFyIGRleHQgPSBbCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTcsCiAgICAgICAgMTcsCiAgICAgICAgMTgsCiAgICAgICAgMTgsCiAgICAgICAgMTksCiAgICAgICAgMTksCiAgICAgICAgMjAsCiAgICAgICAgMjAsCiAgICAgICAgMjEsCiAgICAgICAgMjEsCiAgICAgICAgMjIsCiAgICAgICAgMjIsCiAgICAgICAgMjMsCiAgICAgICAgMjMsCiAgICAgICAgMjQsCiAgICAgICAgMjQsCiAgICAgICAgMjUsCiAgICAgICAgMjUsCiAgICAgICAgMjYsCiAgICAgICAgMjYsCiAgICAgICAgMjcsCiAgICAgICAgMjcsCiAgICAgICAgMjgsCiAgICAgICAgMjgsCiAgICAgICAgMjksCiAgICAgICAgMjksCiAgICAgICAgNjQsCiAgICAgICAgNjQKICAgICAgXTsKICAgICAgbW9kdWxlMi5leHBvcnRzID0gZnVuY3Rpb24gaW5mbGF0ZV90YWJsZSh0eXBlLCBsZW5zLCBsZW5zX2luZGV4LCBjb2RlcywgdGFibGUsIHRhYmxlX2luZGV4LCB3b3JrLCBvcHRzKSB7CiAgICAgICAgdmFyIGJpdHMgPSBvcHRzLmJpdHM7CiAgICAgICAgdmFyIGxlbiA9IDA7CiAgICAgICAgdmFyIHN5bSA9IDA7CiAgICAgICAgdmFyIG1pbiA9IDAsIG1heCA9IDA7CiAgICAgICAgdmFyIHJvb3QyID0gMDsKICAgICAgICB2YXIgY3VyciA9IDA7CiAgICAgICAgdmFyIGRyb3AgPSAwOwogICAgICAgIHZhciBsZWZ0ID0gMDsKICAgICAgICB2YXIgdXNlZCA9IDA7CiAgICAgICAgdmFyIGh1ZmYgPSAwOwogICAgICAgIHZhciBpbmNyOwogICAgICAgIHZhciBmaWxsOwogICAgICAgIHZhciBsb3c7CiAgICAgICAgdmFyIG1hc2s7CiAgICAgICAgdmFyIG5leHQ7CiAgICAgICAgdmFyIGJhc2UgPSBudWxsOwogICAgICAgIHZhciBiYXNlX2luZGV4ID0gMDsKICAgICAgICB2YXIgZW5kOwogICAgICAgIHZhciBjb3VudCA9IG5ldyB1dGlscy5CdWYxNihNQVhCSVRTICsgMSk7CiAgICAgICAgdmFyIG9mZnMgPSBuZXcgdXRpbHMuQnVmMTYoTUFYQklUUyArIDEpOwogICAgICAgIHZhciBleHRyYSA9IG51bGw7CiAgICAgICAgdmFyIGV4dHJhX2luZGV4ID0gMDsKICAgICAgICB2YXIgaGVyZV9iaXRzLCBoZXJlX29wLCBoZXJlX3ZhbDsKICAgICAgICBmb3IgKGxlbiA9IDA7IGxlbiA8PSBNQVhCSVRTOyBsZW4rKykgewogICAgICAgICAgY291bnRbbGVuXSA9IDA7CiAgICAgICAgfQogICAgICAgIGZvciAoc3ltID0gMDsgc3ltIDwgY29kZXM7IHN5bSsrKSB7CiAgICAgICAgICBjb3VudFtsZW5zW2xlbnNfaW5kZXggKyBzeW1dXSsrOwogICAgICAgIH0KICAgICAgICByb290MiA9IGJpdHM7CiAgICAgICAgZm9yIChtYXggPSBNQVhCSVRTOyBtYXggPj0gMTsgbWF4LS0pIHsKICAgICAgICAgIGlmIChjb3VudFttYXhdICE9PSAwKSB7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAocm9vdDIgPiBtYXgpIHsKICAgICAgICAgIHJvb3QyID0gbWF4OwogICAgICAgIH0KICAgICAgICBpZiAobWF4ID09PSAwKSB7CiAgICAgICAgICB0YWJsZVt0YWJsZV9pbmRleCsrXSA9IDEgPDwgMjQgfCA2NCA8PCAxNiB8IDA7CiAgICAgICAgICB0YWJsZVt0YWJsZV9pbmRleCsrXSA9IDEgPDwgMjQgfCA2NCA8PCAxNiB8IDA7CiAgICAgICAgICBvcHRzLmJpdHMgPSAxOwogICAgICAgICAgcmV0dXJuIDA7CiAgICAgICAgfQogICAgICAgIGZvciAobWluID0gMTsgbWluIDwgbWF4OyBtaW4rKykgewogICAgICAgICAgaWYgKGNvdW50W21pbl0gIT09IDApIHsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChyb290MiA8IG1pbikgewogICAgICAgICAgcm9vdDIgPSBtaW47CiAgICAgICAgfQogICAgICAgIGxlZnQgPSAxOwogICAgICAgIGZvciAobGVuID0gMTsgbGVuIDw9IE1BWEJJVFM7IGxlbisrKSB7CiAgICAgICAgICBsZWZ0IDw8PSAxOwogICAgICAgICAgbGVmdCAtPSBjb3VudFtsZW5dOwogICAgICAgICAgaWYgKGxlZnQgPCAwKSB7CiAgICAgICAgICAgIHJldHVybiAtMTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKGxlZnQgPiAwICYmICh0eXBlID09PSBDT0RFUyB8fCBtYXggIT09IDEpKSB7CiAgICAgICAgICByZXR1cm4gLTE7CiAgICAgICAgfQogICAgICAgIG9mZnNbMV0gPSAwOwogICAgICAgIGZvciAobGVuID0gMTsgbGVuIDwgTUFYQklUUzsgbGVuKyspIHsKICAgICAgICAgIG9mZnNbbGVuICsgMV0gPSBvZmZzW2xlbl0gKyBjb3VudFtsZW5dOwogICAgICAgIH0KICAgICAgICBmb3IgKHN5bSA9IDA7IHN5bSA8IGNvZGVzOyBzeW0rKykgewogICAgICAgICAgaWYgKGxlbnNbbGVuc19pbmRleCArIHN5bV0gIT09IDApIHsKICAgICAgICAgICAgd29ya1tvZmZzW2xlbnNbbGVuc19pbmRleCArIHN5bV1dKytdID0gc3ltOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAodHlwZSA9PT0gQ09ERVMpIHsKICAgICAgICAgIGJhc2UgPSBleHRyYSA9IHdvcms7CiAgICAgICAgICBlbmQgPSAxOTsKICAgICAgICB9IGVsc2UgaWYgKHR5cGUgPT09IExFTlMpIHsKICAgICAgICAgIGJhc2UgPSBsYmFzZTsKICAgICAgICAgIGJhc2VfaW5kZXggLT0gMjU3OwogICAgICAgICAgZXh0cmEgPSBsZXh0OwogICAgICAgICAgZXh0cmFfaW5kZXggLT0gMjU3OwogICAgICAgICAgZW5kID0gMjU2OwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBiYXNlID0gZGJhc2U7CiAgICAgICAgICBleHRyYSA9IGRleHQ7CiAgICAgICAgICBlbmQgPSAtMTsKICAgICAgICB9CiAgICAgICAgaHVmZiA9IDA7CiAgICAgICAgc3ltID0gMDsKICAgICAgICBsZW4gPSBtaW47CiAgICAgICAgbmV4dCA9IHRhYmxlX2luZGV4OwogICAgICAgIGN1cnIgPSByb290MjsKICAgICAgICBkcm9wID0gMDsKICAgICAgICBsb3cgPSAtMTsKICAgICAgICB1c2VkID0gMSA8PCByb290MjsKICAgICAgICBtYXNrID0gdXNlZCAtIDE7CiAgICAgICAgaWYgKHR5cGUgPT09IExFTlMgJiYgdXNlZCA+IEVOT1VHSF9MRU5TIHx8IHR5cGUgPT09IERJU1RTICYmIHVzZWQgPiBFTk9VR0hfRElTVFMpIHsKICAgICAgICAgIHJldHVybiAxOwogICAgICAgIH0KICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgIGhlcmVfYml0cyA9IGxlbiAtIGRyb3A7CiAgICAgICAgICBpZiAod29ya1tzeW1dIDwgZW5kKSB7CiAgICAgICAgICAgIGhlcmVfb3AgPSAwOwogICAgICAgICAgICBoZXJlX3ZhbCA9IHdvcmtbc3ltXTsKICAgICAgICAgIH0gZWxzZSBpZiAod29ya1tzeW1dID4gZW5kKSB7CiAgICAgICAgICAgIGhlcmVfb3AgPSBleHRyYVtleHRyYV9pbmRleCArIHdvcmtbc3ltXV07CiAgICAgICAgICAgIGhlcmVfdmFsID0gYmFzZVtiYXNlX2luZGV4ICsgd29ya1tzeW1dXTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGhlcmVfb3AgPSAzMiArIDY0OwogICAgICAgICAgICBoZXJlX3ZhbCA9IDA7CiAgICAgICAgICB9CiAgICAgICAgICBpbmNyID0gMSA8PCBsZW4gLSBkcm9wOwogICAgICAgICAgZmlsbCA9IDEgPDwgY3VycjsKICAgICAgICAgIG1pbiA9IGZpbGw7CiAgICAgICAgICBkbyB7CiAgICAgICAgICAgIGZpbGwgLT0gaW5jcjsKICAgICAgICAgICAgdGFibGVbbmV4dCArIChodWZmID4+IGRyb3ApICsgZmlsbF0gPSBoZXJlX2JpdHMgPDwgMjQgfCBoZXJlX29wIDw8IDE2IHwgaGVyZV92YWwgfCAwOwogICAgICAgICAgfSB3aGlsZSAoZmlsbCAhPT0gMCk7CiAgICAgICAgICBpbmNyID0gMSA8PCBsZW4gLSAxOwogICAgICAgICAgd2hpbGUgKGh1ZmYgJiBpbmNyKSB7CiAgICAgICAgICAgIGluY3IgPj49IDE7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoaW5jciAhPT0gMCkgewogICAgICAgICAgICBodWZmICY9IGluY3IgLSAxOwogICAgICAgICAgICBodWZmICs9IGluY3I7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBodWZmID0gMDsKICAgICAgICAgIH0KICAgICAgICAgIHN5bSsrOwogICAgICAgICAgaWYgKC0tY291bnRbbGVuXSA9PT0gMCkgewogICAgICAgICAgICBpZiAobGVuID09PSBtYXgpIHsKICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgICBsZW4gPSBsZW5zW2xlbnNfaW5kZXggKyB3b3JrW3N5bV1dOwogICAgICAgICAgfQogICAgICAgICAgaWYgKGxlbiA+IHJvb3QyICYmIChodWZmICYgbWFzaykgIT09IGxvdykgewogICAgICAgICAgICBpZiAoZHJvcCA9PT0gMCkgewogICAgICAgICAgICAgIGRyb3AgPSByb290MjsKICAgICAgICAgICAgfQogICAgICAgICAgICBuZXh0ICs9IG1pbjsKICAgICAgICAgICAgY3VyciA9IGxlbiAtIGRyb3A7CiAgICAgICAgICAgIGxlZnQgPSAxIDw8IGN1cnI7CiAgICAgICAgICAgIHdoaWxlIChjdXJyICsgZHJvcCA8IG1heCkgewogICAgICAgICAgICAgIGxlZnQgLT0gY291bnRbY3VyciArIGRyb3BdOwogICAgICAgICAgICAgIGlmIChsZWZ0IDw9IDApIHsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBjdXJyKys7CiAgICAgICAgICAgICAgbGVmdCA8PD0gMTsKICAgICAgICAgICAgfQogICAgICAgICAgICB1c2VkICs9IDEgPDwgY3VycjsKICAgICAgICAgICAgaWYgKHR5cGUgPT09IExFTlMgJiYgdXNlZCA+IEVOT1VHSF9MRU5TIHx8IHR5cGUgPT09IERJU1RTICYmIHVzZWQgPiBFTk9VR0hfRElTVFMpIHsKICAgICAgICAgICAgICByZXR1cm4gMTsKICAgICAgICAgICAgfQogICAgICAgICAgICBsb3cgPSBodWZmICYgbWFzazsKICAgICAgICAgICAgdGFibGVbbG93XSA9IHJvb3QyIDw8IDI0IHwgY3VyciA8PCAxNiB8IG5leHQgLSB0YWJsZV9pbmRleCB8IDA7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChodWZmICE9PSAwKSB7CiAgICAgICAgICB0YWJsZVtuZXh0ICsgaHVmZl0gPSBsZW4gLSBkcm9wIDw8IDI0IHwgNjQgPDwgMTYgfCAwOwogICAgICAgIH0KICAgICAgICBvcHRzLmJpdHMgPSByb290MjsKICAgICAgICByZXR1cm4gMDsKICAgICAgfTsKICAgIH0KICB9KTsKCiAgLy8gbm9kZV9tb2R1bGVzLy5wbnBtL3Bha29AMS4wLjExL25vZGVfbW9kdWxlcy9wYWtvL2xpYi96bGliL2luZmxhdGUuanMKICB2YXIgcmVxdWlyZV9pbmZsYXRlID0gX19jb21tb25KUyh7CiAgICAibm9kZV9tb2R1bGVzLy5wbnBtL3Bha29AMS4wLjExL25vZGVfbW9kdWxlcy9wYWtvL2xpYi96bGliL2luZmxhdGUuanMiKGV4cG9ydHMyKSB7CiAgICAgIGluaXRfYnVmZmVyX3NoaW0oKTsKICAgICAgInVzZSBzdHJpY3QiOwogICAgICB2YXIgdXRpbHMgPSByZXF1aXJlX2NvbW1vbigpOwogICAgICB2YXIgYWRsZXIzMiA9IHJlcXVpcmVfYWRsZXIzMigpOwogICAgICB2YXIgY3JjMzIgPSByZXF1aXJlX2NyYzMyKCk7CiAgICAgIHZhciBpbmZsYXRlX2Zhc3QgPSByZXF1aXJlX2luZmZhc3QoKTsKICAgICAgdmFyIGluZmxhdGVfdGFibGUgPSByZXF1aXJlX2luZnRyZWVzKCk7CiAgICAgIHZhciBDT0RFUyA9IDA7CiAgICAgIHZhciBMRU5TID0gMTsKICAgICAgdmFyIERJU1RTID0gMjsKICAgICAgdmFyIFpfRklOSVNIID0gNDsKICAgICAgdmFyIFpfQkxPQ0sgPSA1OwogICAgICB2YXIgWl9UUkVFUyA9IDY7CiAgICAgIHZhciBaX09LID0gMDsKICAgICAgdmFyIFpfU1RSRUFNX0VORCA9IDE7CiAgICAgIHZhciBaX05FRURfRElDVCA9IDI7CiAgICAgIHZhciBaX1NUUkVBTV9FUlJPUiA9IC0yOwogICAgICB2YXIgWl9EQVRBX0VSUk9SID0gLTM7CiAgICAgIHZhciBaX01FTV9FUlJPUiA9IC00OwogICAgICB2YXIgWl9CVUZfRVJST1IgPSAtNTsKICAgICAgdmFyIFpfREVGTEFURUQgPSA4OwogICAgICB2YXIgSEVBRCA9IDE7CiAgICAgIHZhciBGTEFHUyA9IDI7CiAgICAgIHZhciBUSU1FID0gMzsKICAgICAgdmFyIE9TID0gNDsKICAgICAgdmFyIEVYTEVOID0gNTsKICAgICAgdmFyIEVYVFJBID0gNjsKICAgICAgdmFyIE5BTUUgPSA3OwogICAgICB2YXIgQ09NTUVOVCA9IDg7CiAgICAgIHZhciBIQ1JDID0gOTsKICAgICAgdmFyIERJQ1RJRCA9IDEwOwogICAgICB2YXIgRElDVCA9IDExOwogICAgICB2YXIgVFlQRSA9IDEyOwogICAgICB2YXIgVFlQRURPID0gMTM7CiAgICAgIHZhciBTVE9SRUQgPSAxNDsKICAgICAgdmFyIENPUFlfID0gMTU7CiAgICAgIHZhciBDT1BZID0gMTY7CiAgICAgIHZhciBUQUJMRSA9IDE3OwogICAgICB2YXIgTEVOTEVOUyA9IDE4OwogICAgICB2YXIgQ09ERUxFTlMgPSAxOTsKICAgICAgdmFyIExFTl8gPSAyMDsKICAgICAgdmFyIExFTiA9IDIxOwogICAgICB2YXIgTEVORVhUID0gMjI7CiAgICAgIHZhciBESVNUID0gMjM7CiAgICAgIHZhciBESVNURVhUID0gMjQ7CiAgICAgIHZhciBNQVRDSCA9IDI1OwogICAgICB2YXIgTElUID0gMjY7CiAgICAgIHZhciBDSEVDSyA9IDI3OwogICAgICB2YXIgTEVOR1RIID0gMjg7CiAgICAgIHZhciBET05FID0gMjk7CiAgICAgIHZhciBCQUQgPSAzMDsKICAgICAgdmFyIE1FTSA9IDMxOwogICAgICB2YXIgU1lOQyA9IDMyOwogICAgICB2YXIgRU5PVUdIX0xFTlMgPSA4NTI7CiAgICAgIHZhciBFTk9VR0hfRElTVFMgPSA1OTI7CiAgICAgIHZhciBNQVhfV0JJVFMgPSAxNTsKICAgICAgdmFyIERFRl9XQklUUyA9IE1BWF9XQklUUzsKICAgICAgZnVuY3Rpb24genN3YXAzMihxKSB7CiAgICAgICAgcmV0dXJuIChxID4+PiAyNCAmIDI1NSkgKyAocSA+Pj4gOCAmIDY1MjgwKSArICgocSAmIDY1MjgwKSA8PCA4KSArICgocSAmIDI1NSkgPDwgMjQpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIEluZmxhdGVTdGF0ZSgpIHsKICAgICAgICB0aGlzLm1vZGUgPSAwOwogICAgICAgIHRoaXMubGFzdCA9IGZhbHNlOwogICAgICAgIHRoaXMud3JhcCA9IDA7CiAgICAgICAgdGhpcy5oYXZlZGljdCA9IGZhbHNlOwogICAgICAgIHRoaXMuZmxhZ3MgPSAwOwogICAgICAgIHRoaXMuZG1heCA9IDA7CiAgICAgICAgdGhpcy5jaGVjayA9IDA7CiAgICAgICAgdGhpcy50b3RhbCA9IDA7CiAgICAgICAgdGhpcy5oZWFkID0gbnVsbDsKICAgICAgICB0aGlzLndiaXRzID0gMDsKICAgICAgICB0aGlzLndzaXplID0gMDsKICAgICAgICB0aGlzLndoYXZlID0gMDsKICAgICAgICB0aGlzLnduZXh0ID0gMDsKICAgICAgICB0aGlzLndpbmRvdyA9IG51bGw7CiAgICAgICAgdGhpcy5ob2xkID0gMDsKICAgICAgICB0aGlzLmJpdHMgPSAwOwogICAgICAgIHRoaXMubGVuZ3RoID0gMDsKICAgICAgICB0aGlzLm9mZnNldCA9IDA7CiAgICAgICAgdGhpcy5leHRyYSA9IDA7CiAgICAgICAgdGhpcy5sZW5jb2RlID0gbnVsbDsKICAgICAgICB0aGlzLmRpc3Rjb2RlID0gbnVsbDsKICAgICAgICB0aGlzLmxlbmJpdHMgPSAwOwogICAgICAgIHRoaXMuZGlzdGJpdHMgPSAwOwogICAgICAgIHRoaXMubmNvZGUgPSAwOwogICAgICAgIHRoaXMubmxlbiA9IDA7CiAgICAgICAgdGhpcy5uZGlzdCA9IDA7CiAgICAgICAgdGhpcy5oYXZlID0gMDsKICAgICAgICB0aGlzLm5leHQgPSBudWxsOwogICAgICAgIHRoaXMubGVucyA9IG5ldyB1dGlscy5CdWYxNigzMjApOwogICAgICAgIHRoaXMud29yayA9IG5ldyB1dGlscy5CdWYxNigyODgpOwogICAgICAgIHRoaXMubGVuZHluID0gbnVsbDsKICAgICAgICB0aGlzLmRpc3RkeW4gPSBudWxsOwogICAgICAgIHRoaXMuc2FuZSA9IDA7CiAgICAgICAgdGhpcy5iYWNrID0gMDsKICAgICAgICB0aGlzLndhcyA9IDA7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gaW5mbGF0ZVJlc2V0S2VlcChzdHJtKSB7CiAgICAgICAgdmFyIHN0YXRlOwogICAgICAgIGlmICghc3RybSB8fCAhc3RybS5zdGF0ZSkgewogICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VSUk9SOwogICAgICAgIH0KICAgICAgICBzdGF0ZSA9IHN0cm0uc3RhdGU7CiAgICAgICAgc3RybS50b3RhbF9pbiA9IHN0cm0udG90YWxfb3V0ID0gc3RhdGUudG90YWwgPSAwOwogICAgICAgIHN0cm0ubXNnID0gIiI7CiAgICAgICAgaWYgKHN0YXRlLndyYXApIHsKICAgICAgICAgIHN0cm0uYWRsZXI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YXRlKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIHN0YXRlID0gc3RybS5zdGF0ZTsKICAgICAgICBpZiAod2luZG93Qml0cyA8IDApIHsKICAgICAgICAgIHdyYXAgPSAwOwogICAgICAgICAgd2luZG93Qml0cyA9IC13aW5kb3dCaXRzOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICB3cmFwID0gKHdpbmRvd0JpdHMgPj4gNCkgKyAxOwogICAgICAgICAgaWYgKHdpbmRvd0JpdHMgPCA0OCkgewogICAgICAgICAgICB3aW5kb3dCaXRzICY9IDE1OwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAod2luZG93Qml0cyAmJiAod2luZG93Qml0cyA8IDggfHwgd2luZG93Qml0cyA+IDE1KSkgewogICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VSUk9SOwogICAgICAgIH0KICAgICAgICBpZiAoc3RhdGUud2luZG93ICE9PSBudWxsICYmIHN0YXRlLndiaXRzICE9PSB3aW5kb3dCaXRzKSB7CiAgICAgICAgICBzdGF0ZS53aW5kb3cgPSBudWxsOwogICAgICAgIH0KICAgICAgICBzdGF0ZS53cmFwID0gd3JhcDsKICAgICAgICBzdGF0ZS53Yml0cyA9IHdpbmRvd0JpdHM7CiAgICAgICAgcmV0dXJuIGluZmxhdGVSZXNldChzdHJtKTsKICAgICAgfQogICAgICBmdW5jdGlvbiBpbmZsYXRlSW5pdDIoc3RybSwgd2luZG93Qml0cykgewogICAgICAgIHZhciByZXQ7CiAgICAgICAgdmFyIHN0YXRlOwogICAgICAgIGlmICghc3RybSkgewogICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VSUk9SOwogICAgICAgIH0KICAgICAgICBzdGF0ZSA9IG5ldyBJbmZsYXRlU3RhdGUoKTsKICAgICAgICBzdHJtLnN0YXRlID0gc3RhdGU7CiAgICAgICAgc3RhdGUud2luZG93ID0gbnVsbDsKICAgICAgICByZXQgPSBpbmZsYXRlUmVzZXQyKHN0cm0sIHdpbmRvd0JpdHMpOwogICAgICAgIGlmIChyZXQgIT09IFpfT0spIHsKICAgICAgICAgIHN0cm0uc3RhdGUgPSBudWxsOwogICAgICAgIH0KICAgICAgICByZXR1cm4gcmV0OwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGluZmxhdGVJbml0KHN0cm0pIHsKICAgICAgICByZXR1cm4gaW5mbGF0ZUluaXQyKHN0cm0sIERFRl9XQklUUyk7CiAgICAgIH0KICAgICAgdmFyIHZpcmdpbiA9IHRydWU7CiAgICAgIHZhciBsZW5maXg7CiAgICAgIHZhciBkaXN0Zml4OwogICAgICBmdW5jdGlvbiBmaXhlZHRhYmxlcyhzdGF0ZSkgewogICAgICAgIGlmICh2aXJnaW4pIHsKICAgICAgICAgIHZhciBzeW07CiAgICAgICAgICBsZW5maXggPSBuZXcgdXRpbHMuQnVmMzIoNTEyKTsKICAgICAgICAgIGRpc3RmaXggPSBuZXcgdXRpbHMuQnVmMzIoMzIpOwogICAgICAgICAgc3ltID0gMDsKICAgICAgICAgIHdoaWxlIChzeW0gPCAxNDQpIHsKICAgICAgICAgICAgc3RhdGUubGVuc1tzeW0rK10gPSA4OwogICAgICAgICAgfQogICAgICAgICAgd2hpbGUgKHN5bSA8IDI1NikgewogICAgICAgICAgICBzdGF0ZS5sZW5zW3N5bSsrXSA9IDk7CiAgICAgICAgICB9CiAgICAgICAgICB3aGlsZSAoc3ltIDwgMjgwKSB7CiAgICAgICAgICAgIHN0YXRlLmxlbnNbc3ltKytdID0gNzsKICAgICAgICAgIH0KICAgICAgICAgIHdoaWxlIChzeW0gPCAyODgpIHsKICAgICAgICAgICAgc3RhdGUubGVuc1tzeW0rK10gPSA4OwogICAgICAgICAgfQogICAgICAgICAgaW5mbGF0ZV90YWJsZShMRU5TLCBzdGF0ZS5sZW5zLCAwLCAyODgsIGxlbmZpeCwgMCwgc3RhdGUud29yaywgeyBiaXRzOiA5IH0pOwogICAgICAgICAgc3ltID0gMDsKICAgICAgICAgIHdoaWxlIChzeW0gPCAzMikgewogICAgICAgICAgICBzdGF0ZS5sZW5zW3N5bSsrXSA9IDU7CiAgICAgICAgICB9CiAgICAgICAgICBpbmZsYXRlX3RhYmxlKERJU1RTLCBzdGF0ZS5sZW5zLCAwLCAzMiwgZGlzdGZpeCwgMCwgc3RhdGUud29yaywgeyBiaXRzOiA1IH0pOwogICAgICAgICAgdmlyZ2luID0gZmFsc2U7CiAgICAgICAgfQogICAgICAgIHN0YXRlLmxlbmNvZGUgPSBsZW5maXg7CiAgICAgICAgc3RhdGUubGVuYml0cyA9IDk7CiAgICAgICAgc3RhdGUuZGlzdGNvZGUgPSBkaXN0Zml4OwogICAgICAgIHN0YXRlLmRpc3RiaXRzID0gNTsKICAgICAgfQogICAgICBmdW5jdGlvbiB1cGRhdGV3aW5kb3coc3RybSwgc3JjLCBlbmQsIGNvcHkpIHsKICAgICAgICB2YXIgZGlzdDsKICAgICAgICB2YXIgc3RhdGUgPSBzdHJtLnN0YXRlOwogICAgICAgIGlmIChzdGF0ZS53aW5kb3cgPT09IG51bGwpIHsKICAgICAgICAgIHN0YXRlLndzaXplID0gMSA8PCBzdGF0ZS53Yml0czsKICAgICAgICAgIHN0YXRlLnduZXh0ID0gMDsKICAgICAgICAgIHN0YXRlLndoYXZlID0gMDsKICAgICAgICAgIHN0YXRlLndpbmRvdyA9IG5ldyB1dGlscy5CdWY4KHN0YXRlLndzaXplKTsKICAgICAgICB9CiAgICAgICAgaWYgKGNvcHkgPj0gc3RhdGUud3NpemUpIHsKICAgICAgICAgIHV0aWxzLmFycmF5U2V0KHN0YXRlLndpbmRvdywgc3JjLCBlbmQgLSBzdGF0ZS53c2l6ZSwgc3RhdGUud3NpemUsIDApOwogICAgICAgICAgc3RhdGUud25leHQgPSAwOwogICAgICAgICAgc3RhdGUud2hhdmUgPSBzdGF0ZS53c2l6ZTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgZGlzdCA9IHN0YXRlLndzaXplIC0gc3RhdGUud25leHQ7CiAgICAgICAgICBpZiAoZGlzdCA+IGNvcHkpIHsKICAgICAgICAgICAgZGlzdCA9IGNvcHk7CiAgICAgICAgICB9CiAgICAgICAgICB1dGlscy5hcnJheVNldChzdGF0ZS53aW5kb3csIHNyYywgZW5kIC0gY29weSwgZGlzdCwgc3RhdGUud25leHQpOwogICAgICAgICAgY29weSAtPSBkaXN0OwogICAgICAgICAgaWYgKGNvcHkpIHsKICAgICAgICAgICAgdXRpbHMuYXJyYXlTZXQoc3RhdGUud2luZG93LCBzcmMsIGVuZCAtIGNvcHksIGNvcHksIDApOwogICAgICAgICAgICBzdGF0ZS53bmV4dCA9IGNvcHk7CiAgICAgICAgICAgIHN0YXRlLndoYXZlID0gc3RhdGUud3NpemU7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBzdGF0ZS53bmV4dCArPSBkaXN0OwogICAgICAgICAgICBpZiAoc3RhdGUud25leHQgPT09IHN0YXRlLndzaXplKSB7CiAgICAgICAgICAgICAgc3RhdGUud25leHQgPSAwOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzdGF0ZS53aGF2ZSA8IHN0YXRlLndzaXplKSB7CiAgICAgICAgICAgICAgc3RhdGUud2hhdmUgKz0gZGlzdDsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gMDsKICAgICAgfQogICAgICBmdW5jdGlvbiBpbmZsYXRlKHN0cm0sIGZsdXNoKSB7CiAgICAgICAgdmFyIHN0YXRlOwogICAgICAgIHZhciBpbnB1dCwgb3V0cHV0OwogICAgICAgIHZhciBuZXh0OwogICAgICAgIHZhciBwdXQ7CiAgICAgICAgdmFyIGhhdmUsIGxlZnQ7CiAgICAgICAgdmFyIGhvbGQ7CiAgICAgICAgdmFyIGJpdHM7CiAgICAgICAgdmFyIF9pbiwgX291dDsKICAgICAgICB2YXIgY29weTsKICAgICAgICB2YXIgZnJvbTsKICAgICAgICB2YXIgZnJvbV9zb3VyY2U7CiAgICAgICAgdmFyIGhlcmUgPSAwOwogICAgICAgIHZhciBoZXJlX2JpdHMsIGhlcmVfb3AsIGhlcmVfdmFsOwogICAgICAgIHZhciBsYXN0X2JpdHMsIGxhc3Rfb3AsIGxhc3RfdmFsOwogICAgICAgIHZhciBsZW47CiAgICAgICAgdmFyIHJldDsKICAgICAgICB2YXIgaGJ1ZiA9IG5ldyB1dGlscy5CdWY4KDQpOwogICAgICAgIHZhciBvcHRzOwogICAgICAgIHZhciBuOwogICAgICAgIHZhciBvcmRlciA9IFsxNiwgMTcsIDE4LCAwLCA4LCA3LCA5LCA2LCAxMCwgNSwgMTEsIDQsIDEyLCAzLCAxMywgMiwgMTQsIDEsIDE1XTsKICAgICAgICBpZiAoIXN0cm0gfHwgIXN0cm0uc3RhdGUgfHwgIXN0cm0ub3V0cHV0IHx8ICFzdHJtLmlucHV0ICYmIHN0cm0uYXZhaWxfaW4gIT09IDApIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgc3RhdGUgPSBzdHJtLnN0YXRlOwogICAgICAgIGlmIChzdGF0ZS5tb2RlID09PSBUWVBFKSB7CiAgICAgICAgICBzdGF0ZS5tb2RlID0gVFlQRURPOwogICAgICAgIH0KICAgICAgICBwdXQgPSBzdHJtLm5leHRfb3V0OwogICAgICAgIG91dHB1dCA9IHN0cm0ub3V0cHV0OwogICAgICAgIGxlZnQgPSBzdHJtLmF2YWlsX291dDsKICAgICAgICBuZXh0ID0gc3RybS5uZXh0X2luOwogICAgICAgIGlucHV0ID0gc3RybS5pbnB1dDsKICAgICAgICBoYXZlID0gc3RybS5hdmFpbF9pbjsKICAgICAgICBob2xkID0gc3RhdGUuaG9sZDsKICAgICAgICBiaXRzID0gc3RhdGUuYml0czsKICAgICAgICBfaW4gPSBoYXZlOwogICAgICAgIF9vdXQgPSBsZWZ0OwogICAgICAgIHJldCA9IFpfT0s7CiAgICAgICAgaW5mX2xlYXZlOgogICAgICAgICAgZm9yICg7IDsgKSB7CiAgICAgICAgICAgIHN3aXRjaCAoc3RhdGUubW9kZSkgewogICAgICAgICAgICAgIGNhc2UgSEVBRDoKICAgICAgICAgICAgICAgIGlmIChzdGF0ZS53cmFwID09PSAwKSB7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBUWVBFRE87CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCAxNikgewogICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUud3JhcCAmIDIgJiYgaG9sZCA9PT0gMzU2MTUpIHsKICAgICAgICAgICAgICAgICAgc3RhdGUuY2hlY2sgPSAwOwogICAgICAgICAgICAgICAgICBoYnVmWzBdID0gaG9sZCAmIDI1NTsKICAgICAgICAgICAgICAgICAgaGJ1ZlsxXSA9IGhvbGQgPj4+IDggJiAyNTU7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmNoZWNrID0gY3JjMzIoc3RhdGUuY2hlY2ssIGhidWYsIDIsIDApOwogICAgICAgICAgICAgICAgICBob2xkID0gMDsKICAgICAgICAgICAgICAgICAgYml0cyA9IDA7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBGTEFHUzsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5mbGFncyA9IDA7CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuaGVhZCkgewogICAgICAgICAgICAgICAgICBzdGF0ZS5oZWFkLmRvbmUgPSBmYWxzZTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmICghKHN0YXRlLndyYXAgJiAxKSB8fCAoKChob2xkICYgMjU1KSA8PCA4KSArIChob2xkID4+IDgpKSAlIDMxKSB7CiAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImluY29ycmVjdCBoZWFkZXIgY2hlY2siOwogICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEOwogICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmICgoaG9sZCAmIDE1KSAhPT0gWl9ERUZMQVRFRCkgewogICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJ1bmtub3duIGNvbXByZXNzaW9uIG1ldGhvZCI7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaG9sZCA+Pj49IDQ7CiAgICAgICAgICAgICAgICBiaXRzIC09IDQ7CiAgICAgICAgICAgICAgICBsZW4gPSAoaG9sZCAmIDE1KSArIDg7CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUud2JpdHMgPT09IDApIHsKICAgICAgICAgICAgICAgICAgc3RhdGUud2JpdHMgPSBsZW47CiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKGxlbiA+IHN0YXRlLndiaXRzKSB7CiAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImludmFsaWQgd2luZG93IHNpemUiOwogICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEOwogICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0YXRlLmRtYXggPSAxIDw8IGxlbjsKICAgICAgICAgICAgICAgIHN0cm0uYWRsZXIgPSBzdGF0ZS5jaGVjayA9IDE7CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gaG9sZCAmIDUxMiA/IERJQ1RJRCA6IFRZUEU7CiAgICAgICAgICAgICAgICBob2xkID0gMDsKICAgICAgICAgICAgICAgIGJpdHMgPSAwOwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgY2FzZSBGTEFHUzoKICAgICAgICAgICAgICAgIHdoaWxlIChiaXRzIDwgMTYpIHsKICAgICAgICAgICAgICAgICAgaWYgKGhhdmUgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaGF2ZS0tOwogICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUuZmxhZ3MgPSBob2xkOwogICAgICAgICAgICAgICAgaWYgKChzdGF0ZS5mbGFncyAmIDI1NSkgIT09IFpfREVGTEFURUQpIHsKICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAidW5rbm93biBjb21wcmVzc2lvbiBtZXRob2QiOwogICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEOwogICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5mbGFncyAmIDU3MzQ0KSB7CiAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gInVua25vd24gaGVhZGVyIGZsYWdzIHNldCI7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmhlYWQpIHsKICAgICAgICAgICAgICAgICAgc3RhdGUuaGVhZC50ZXh0ID0gaG9sZCA+PiA4ICYgMTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5mbGFncyAmIDUxMikgewogICAgICAgICAgICAgICAgICBoYnVmWzBdID0gaG9sZCAmIDI1NTsKICAgICAgICAgICAgICAgICAgaGJ1ZlsxXSA9IGhvbGQgPj4+IDggJiAyNTU7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmNoZWNrID0gY3JjMzIoc3RhdGUuY2hlY2ssIGhidWYsIDIsIDApOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaG9sZCA9IDA7CiAgICAgICAgICAgICAgICBiaXRzID0gMDsKICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBUSU1FOwogICAgICAgICAgICAgIGNhc2UgVElNRToKICAgICAgICAgICAgICAgIHdoaWxlIChiaXRzIDwgMzIpIHsKICAgICAgICAgICAgICAgICAgaWYgKGhhdmUgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaGF2ZS0tOwogICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmhlYWQpIHsKICAgICAgICAgICAgICAgICAgc3RhdGUuaGVhZC50aW1lID0gaG9sZDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5mbGFncyAmIDUxMikgewogICAgICAgICAgICAgICAgICBoYnVmWzBdID0gaG9sZCAmIDI1NTsKICAgICAgICAgICAgICAgICAgaGJ1ZlsxXSA9IGhvbGQgPj4+IDggJiAyNTU7CiAgICAgICAgICAgICAgICAgIGhidWZbMl0gPSBob2xkID4+PiAxNiAmIDI1NTsKICAgICAgICAgICAgICAgICAgaGJ1ZlszXSA9IGhvbGQgPj4+IDI0ICYgMjU1OwogICAgICAgICAgICAgICAgICBzdGF0ZS5jaGVjayA9IGNyYzMyKHN0YXRlLmNoZWNrLCBoYnVmLCA0LCAwKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGhvbGQgPSAwOwogICAgICAgICAgICAgICAgYml0cyA9IDA7CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gT1M7CiAgICAgICAgICAgICAgY2FzZSBPUzoKICAgICAgICAgICAgICAgIHdoaWxlIChiaXRzIDwgMTYpIHsKICAgICAgICAgICAgICAgICAgaWYgKGhhdmUgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaGF2ZS0tOwogICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmhlYWQpIHsKICAgICAgICAgICAgICAgICAgc3RhdGUuaGVhZC54ZmxhZ3MgPSBob2xkICYgMjU1OwogICAgICAgICAgICAgICAgICBzdGF0ZS5oZWFkLm9zID0gaG9sZCA+PiA4OwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmZsYWdzICYgNTEyKSB7CiAgICAgICAgICAgICAgICAgIGhidWZbMF0gPSBob2xkICYgMjU1OwogICAgICAgICAgICAgICAgICBoYnVmWzFdID0gaG9sZCA+Pj4gOCAmIDI1NTsKICAgICAgICAgICAgICAgICAgc3RhdGUuY2hlY2sgPSBjcmMzMihzdGF0ZS5jaGVjaywgaGJ1ZiwgMiwgMCk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBob2xkID0gMDsKICAgICAgICAgICAgICAgIGJpdHMgPSAwOwogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEVYTEVOOwogICAgICAgICAgICAgIGNhc2UgRVhMRU46CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuZmxhZ3MgJiAxMDI0KSB7CiAgICAgICAgICAgICAgICAgIHdoaWxlIChiaXRzIDwgMTYpIHsKICAgICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIHN0YXRlLmxlbmd0aCA9IGhvbGQ7CiAgICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5oZWFkKSB7CiAgICAgICAgICAgICAgICAgICAgc3RhdGUuaGVhZC5leHRyYV9sZW4gPSBob2xkOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5mbGFncyAmIDUxMikgewogICAgICAgICAgICAgICAgICAgIGhidWZbMF0gPSBob2xkICYgMjU1OwogICAgICAgICAgICAgICAgICAgIGhidWZbMV0gPSBob2xkID4+PiA4ICYgMjU1OwogICAgICAgICAgICAgICAgICAgIHN0YXRlLmNoZWNrID0gY3JjMzIoc3RhdGUuY2hlY2ssIGhidWYsIDIsIDApOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGhvbGQgPSAwOwogICAgICAgICAgICAgICAgICBiaXRzID0gMDsKICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAoc3RhdGUuaGVhZCkgewogICAgICAgICAgICAgICAgICBzdGF0ZS5oZWFkLmV4dHJhID0gbnVsbDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBFWFRSQTsKICAgICAgICAgICAgICBjYXNlIEVYVFJBOgogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmZsYWdzICYgMTAyNCkgewogICAgICAgICAgICAgICAgICBjb3B5ID0gc3RhdGUubGVuZ3RoOwogICAgICAgICAgICAgICAgICBpZiAoY29weSA+IGhhdmUpIHsKICAgICAgICAgICAgICAgICAgICBjb3B5ID0gaGF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBpZiAoY29weSkgewogICAgICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5oZWFkKSB7CiAgICAgICAgICAgICAgICAgICAgICBsZW4gPSBzdGF0ZS5oZWFkLmV4dHJhX2xlbiAtIHN0YXRlLmxlbmd0aDsKICAgICAgICAgICAgICAgICAgICAgIGlmICghc3RhdGUuaGVhZC5leHRyYSkgewogICAgICAgICAgICAgICAgICAgICAgICBzdGF0ZS5oZWFkLmV4dHJhID0gbmV3IEFycmF5KHN0YXRlLmhlYWQuZXh0cmFfbGVuKTsKICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgIHV0aWxzLmFycmF5U2V0KHN0YXRlLmhlYWQuZXh0cmEsIGlucHV0LCBuZXh0LCBjb3B5LCBsZW4pOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBpZiAoc3RhdGUuZmxhZ3MgJiA1MTIpIHsKICAgICAgICAgICAgICAgICAgICAgIHN0YXRlLmNoZWNrID0gY3JjMzIoc3RhdGUuY2hlY2ssIGlucHV0LCBjb3B5LCBuZXh0KTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgaGF2ZSAtPSBjb3B5OwogICAgICAgICAgICAgICAgICAgIG5leHQgKz0gY29weTsKICAgICAgICAgICAgICAgICAgICBzdGF0ZS5sZW5ndGggLT0gY29weTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBpZiAoc3RhdGUubGVuZ3RoKSB7CiAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5sZW5ndGggPSAwOwogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IE5BTUU7CiAgICAgICAgICAgICAgY2FzZSBOQU1FOgogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmZsYWdzICYgMjA0OCkgewogICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBjb3B5ID0gMDsKICAgICAgICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgICAgICAgIGxlbiA9IGlucHV0W25leHQgKyBjb3B5KytdOwogICAgICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5oZWFkICYmIGxlbiAmJiBzdGF0ZS5sZW5ndGggPCA2NTUzNikgewogICAgICAgICAgICAgICAgICAgICAgc3RhdGUuaGVhZC5uYW1lICs9IFN0cmluZy5mcm9tQ2hhckNvZGUobGVuKTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIH0gd2hpbGUgKGxlbiAmJiBjb3B5IDwgaGF2ZSk7CiAgICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5mbGFncyAmIDUxMikgewogICAgICAgICAgICAgICAgICAgIHN0YXRlLmNoZWNrID0gY3JjMzIoc3RhdGUuY2hlY2ssIGlucHV0LCBjb3B5LCBuZXh0KTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBoYXZlIC09IGNvcHk7CiAgICAgICAgICAgICAgICAgIG5leHQgKz0gY29weTsKICAgICAgICAgICAgICAgICAgaWYgKGxlbikgewogICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfSBlbHNlIGlmIChzdGF0ZS5oZWFkKSB7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmhlYWQubmFtZSA9IG51bGw7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5sZW5ndGggPSAwOwogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IENPTU1FTlQ7CiAgICAgICAgICAgICAgY2FzZSBDT01NRU5UOgogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmZsYWdzICYgNDA5NikgewogICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBjb3B5ID0gMDsKICAgICAgICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgICAgICAgIGxlbiA9IGlucHV0W25leHQgKyBjb3B5KytdOwogICAgICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5oZWFkICYmIGxlbiAmJiBzdGF0ZS5sZW5ndGggPCA2NTUzNikgewogICAgICAgICAgICAgICAgICAgICAgc3RhdGUuaGVhZC5jb21tZW50ICs9IFN0cmluZy5mcm9tQ2hhckNvZGUobGVuKTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIH0gd2hpbGUgKGxlbiAmJiBjb3B5IDwgaGF2ZSk7CiAgICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5mbGFncyAmIDUxMikgewogICAgICAgICAgICAgICAgICAgIHN0YXRlLmNoZWNrID0gY3JjMzIoc3RhdGUuY2hlY2ssIGlucHV0LCBjb3B5LCBuZXh0KTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBoYXZlIC09IGNvcHk7CiAgICAgICAgICAgICAgICAgIG5leHQgKz0gY29weTsKICAgICAgICAgICAgICAgICAgaWYgKGxlbikgewogICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfSBlbHNlIGlmIChzdGF0ZS5oZWFkKSB7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmhlYWQuY29tbWVudCA9IG51bGw7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gSENSQzsKICAgICAgICAgICAgICBjYXNlIEhDUkM6CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuZmxhZ3MgJiA1MTIpIHsKICAgICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCAxNikgewogICAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaWYgKGhvbGQgIT09IChzdGF0ZS5jaGVjayAmIDY1NTM1KSkgewogICAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImhlYWRlciBjcmMgbWlzbWF0Y2giOwogICAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaG9sZCA9IDA7CiAgICAgICAgICAgICAgICAgIGJpdHMgPSAwOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmhlYWQpIHsKICAgICAgICAgICAgICAgICAgc3RhdGUuaGVhZC5oY3JjID0gc3RhdGUuZmxhZ3MgPj4gOSAmIDE7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmhlYWQuZG9uZSA9IHRydWU7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gc3RhdGUuY2hlY2sgPSAwOwogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IFRZUEU7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICBjYXNlIERJQ1RJRDoKICAgICAgICAgICAgICAgIHdoaWxlIChiaXRzIDwgMzIpIHsKICAgICAgICAgICAgICAgICAgaWYgKGhhdmUgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaGF2ZS0tOwogICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RybS5hZGxlciA9IHN0YXRlLmNoZWNrID0genN3YXAzMihob2xkKTsKICAgICAgICAgICAgICAgIGhvbGQgPSAwOwogICAgICAgICAgICAgICAgYml0cyA9IDA7CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gRElDVDsKICAgICAgICAgICAgICBjYXNlIERJQ1Q6CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuaGF2ZWRpY3QgPT09IDApIHsKICAgICAgICAgICAgICAgICAgc3RybS5uZXh0X291dCA9IHB1dDsKICAgICAgICAgICAgICAgICAgc3RybS5hdmFpbF9vdXQgPSBsZWZ0OwogICAgICAgICAgICAgICAgICBzdHJtLm5leHRfaW4gPSBuZXh0OwogICAgICAgICAgICAgICAgICBzdHJtLmF2YWlsX2luID0gaGF2ZTsKICAgICAgICAgICAgICAgICAgc3RhdGUuaG9sZCA9IGhvbGQ7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmJpdHMgPSBiaXRzOwogICAgICAgICAgICAgICAgICByZXR1cm4gWl9ORUVEX0RJQ1Q7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gc3RhdGUuY2hlY2sgPSAxOwogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IFRZUEU7CiAgICAgICAgICAgICAgY2FzZSBUWVBFOgogICAgICAgICAgICAgICAgaWYgKGZsdXNoID09PSBaX0JMT0NLIHx8IGZsdXNoID09PSBaX1RSRUVTKSB7CiAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBjYXNlIFRZUEVETzoKICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5sYXN0KSB7CiAgICAgICAgICAgICAgICAgIGhvbGQgPj4+PSBiaXRzICYgNzsKICAgICAgICAgICAgICAgICAgYml0cyAtPSBiaXRzICYgNzsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IENIRUNLOwogICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHdoaWxlIChiaXRzIDwgMykgewogICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5sYXN0ID0gaG9sZCAmIDE7CiAgICAgICAgICAgICAgICBob2xkID4+Pj0gMTsKICAgICAgICAgICAgICAgIGJpdHMgLT0gMTsKICAgICAgICAgICAgICAgIHN3aXRjaCAoaG9sZCAmIDMpIHsKICAgICAgICAgICAgICAgICAgY2FzZSAwOgogICAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBTVE9SRUQ7CiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgIGNhc2UgMToKICAgICAgICAgICAgICAgICAgICBmaXhlZHRhYmxlcyhzdGF0ZSk7CiAgICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IExFTl87CiAgICAgICAgICAgICAgICAgICAgaWYgKGZsdXNoID09PSBaX1RSRUVTKSB7CiAgICAgICAgICAgICAgICAgICAgICBob2xkID4+Pj0gMjsKICAgICAgICAgICAgICAgICAgICAgIGJpdHMgLT0gMjsKICAgICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgIGNhc2UgMjoKICAgICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gVEFCTEU7CiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgIGNhc2UgMzoKICAgICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbnZhbGlkIGJsb2NrIHR5cGUiOwogICAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBob2xkID4+Pj0gMjsKICAgICAgICAgICAgICAgIGJpdHMgLT0gMjsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgIGNhc2UgU1RPUkVEOgogICAgICAgICAgICAgICAgaG9sZCA+Pj49IGJpdHMgJiA3OwogICAgICAgICAgICAgICAgYml0cyAtPSBiaXRzICYgNzsKICAgICAgICAgICAgICAgIHdoaWxlIChiaXRzIDwgMzIpIHsKICAgICAgICAgICAgICAgICAgaWYgKGhhdmUgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaGF2ZS0tOwogICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKChob2xkICYgNjU1MzUpICE9PSAoaG9sZCA+Pj4gMTYgXiA2NTUzNSkpIHsKICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW52YWxpZCBzdG9yZWQgYmxvY2sgbGVuZ3RocyI7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUubGVuZ3RoID0gaG9sZCAmIDY1NTM1OwogICAgICAgICAgICAgICAgaG9sZCA9IDA7CiAgICAgICAgICAgICAgICBiaXRzID0gMDsKICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBDT1BZXzsKICAgICAgICAgICAgICAgIGlmIChmbHVzaCA9PT0gWl9UUkVFUykgewogICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgY2FzZSBDT1BZXzoKICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBDT1BZOwogICAgICAgICAgICAgIGNhc2UgQ09QWToKICAgICAgICAgICAgICAgIGNvcHkgPSBzdGF0ZS5sZW5ndGg7CiAgICAgICAgICAgICAgICBpZiAoY29weSkgewogICAgICAgICAgICAgICAgICBpZiAoY29weSA+IGhhdmUpIHsKICAgICAgICAgICAgICAgICAgICBjb3B5ID0gaGF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBpZiAoY29weSA+IGxlZnQpIHsKICAgICAgICAgICAgICAgICAgICBjb3B5ID0gbGVmdDsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBpZiAoY29weSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICB1dGlscy5hcnJheVNldChvdXRwdXQsIGlucHV0LCBuZXh0LCBjb3B5LCBwdXQpOwogICAgICAgICAgICAgICAgICBoYXZlIC09IGNvcHk7CiAgICAgICAgICAgICAgICAgIG5leHQgKz0gY29weTsKICAgICAgICAgICAgICAgICAgbGVmdCAtPSBjb3B5OwogICAgICAgICAgICAgICAgICBwdXQgKz0gY29weTsKICAgICAgICAgICAgICAgICAgc3RhdGUubGVuZ3RoIC09IGNvcHk7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IFRZUEU7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICBjYXNlIFRBQkxFOgogICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCAxNCkgewogICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5ubGVuID0gKGhvbGQgJiAzMSkgKyAyNTc7CiAgICAgICAgICAgICAgICBob2xkID4+Pj0gNTsKICAgICAgICAgICAgICAgIGJpdHMgLT0gNTsKICAgICAgICAgICAgICAgIHN0YXRlLm5kaXN0ID0gKGhvbGQgJiAzMSkgKyAxOwogICAgICAgICAgICAgICAgaG9sZCA+Pj49IDU7CiAgICAgICAgICAgICAgICBiaXRzIC09IDU7CiAgICAgICAgICAgICAgICBzdGF0ZS5uY29kZSA9IChob2xkICYgMTUpICsgNDsKICAgICAgICAgICAgICAgIGhvbGQgPj4+PSA0OwogICAgICAgICAgICAgICAgYml0cyAtPSA0OwogICAgICAgICAgICAgICAgaWYgKHN0YXRlLm5sZW4gPiAyODYgfHwgc3RhdGUubmRpc3QgPiAzMCkgewogICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJ0b28gbWFueSBsZW5ndGggb3IgZGlzdGFuY2Ugc3ltYm9scyI7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUuaGF2ZSA9IDA7CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gTEVOTEVOUzsKICAgICAgICAgICAgICBjYXNlIExFTkxFTlM6CiAgICAgICAgICAgICAgICB3aGlsZSAoc3RhdGUuaGF2ZSA8IHN0YXRlLm5jb2RlKSB7CiAgICAgICAgICAgICAgICAgIHdoaWxlIChiaXRzIDwgMykgewogICAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgc3RhdGUubGVuc1tvcmRlcltzdGF0ZS5oYXZlKytdXSA9IGhvbGQgJiA3OwogICAgICAgICAgICAgICAgICBob2xkID4+Pj0gMzsKICAgICAgICAgICAgICAgICAgYml0cyAtPSAzOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgd2hpbGUgKHN0YXRlLmhhdmUgPCAxOSkgewogICAgICAgICAgICAgICAgICBzdGF0ZS5sZW5zW29yZGVyW3N0YXRlLmhhdmUrK11dID0gMDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0YXRlLmxlbmNvZGUgPSBzdGF0ZS5sZW5keW47CiAgICAgICAgICAgICAgICBzdGF0ZS5sZW5iaXRzID0gNzsKICAgICAgICAgICAgICAgIG9wdHMgPSB7IGJpdHM6IHN0YXRlLmxlbmJpdHMgfTsKICAgICAgICAgICAgICAgIHJldCA9IGluZmxhdGVfdGFibGUoQ09ERVMsIHN0YXRlLmxlbnMsIDAsIDE5LCBzdGF0ZS5sZW5jb2RlLCAwLCBzdGF0ZS53b3JrLCBvcHRzKTsKICAgICAgICAgICAgICAgIHN0YXRlLmxlbmJpdHMgPSBvcHRzLmJpdHM7CiAgICAgICAgICAgICAgICBpZiAocmV0KSB7CiAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImludmFsaWQgY29kZSBsZW5ndGhzIHNldCI7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUuaGF2ZSA9IDA7CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQ09ERUxFTlM7CiAgICAgICAgICAgICAgY2FzZSBDT0RFTEVOUzoKICAgICAgICAgICAgICAgIHdoaWxlIChzdGF0ZS5oYXZlIDwgc3RhdGUubmxlbiArIHN0YXRlLm5kaXN0KSB7CiAgICAgICAgICAgICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgICAgICAgICAgIGhlcmUgPSBzdGF0ZS5sZW5jb2RlW2hvbGQgJiAoMSA8PCBzdGF0ZS5sZW5iaXRzKSAtIDFdOwogICAgICAgICAgICAgICAgICAgIGhlcmVfYml0cyA9IGhlcmUgPj4+IDI0OwogICAgICAgICAgICAgICAgICAgIGhlcmVfb3AgPSBoZXJlID4+PiAxNiAmIDI1NTsKICAgICAgICAgICAgICAgICAgICBoZXJlX3ZhbCA9IGhlcmUgJiA2NTUzNTsKICAgICAgICAgICAgICAgICAgICBpZiAoaGVyZV9iaXRzIDw9IGJpdHMpIHsKICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChoZXJlX3ZhbCA8IDE2KSB7CiAgICAgICAgICAgICAgICAgICAgaG9sZCA+Pj49IGhlcmVfYml0czsKICAgICAgICAgICAgICAgICAgICBiaXRzIC09IGhlcmVfYml0czsKICAgICAgICAgICAgICAgICAgICBzdGF0ZS5sZW5zW3N0YXRlLmhhdmUrK10gPSBoZXJlX3ZhbDsKICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICBpZiAoaGVyZV92YWwgPT09IDE2KSB7CiAgICAgICAgICAgICAgICAgICAgICBuID0gaGVyZV9iaXRzICsgMjsKICAgICAgICAgICAgICAgICAgICAgIHdoaWxlIChiaXRzIDwgbikgewogICAgICAgICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICBob2xkID4+Pj0gaGVyZV9iaXRzOwogICAgICAgICAgICAgICAgICAgICAgYml0cyAtPSBoZXJlX2JpdHM7CiAgICAgICAgICAgICAgICAgICAgICBpZiAoc3RhdGUuaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbnZhbGlkIGJpdCBsZW5ndGggcmVwZWF0IjsKICAgICAgICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICBsZW4gPSBzdGF0ZS5sZW5zW3N0YXRlLmhhdmUgLSAxXTsKICAgICAgICAgICAgICAgICAgICAgIGNvcHkgPSAzICsgKGhvbGQgJiAzKTsKICAgICAgICAgICAgICAgICAgICAgIGhvbGQgPj4+PSAyOwogICAgICAgICAgICAgICAgICAgICAgYml0cyAtPSAyOwogICAgICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAoaGVyZV92YWwgPT09IDE3KSB7CiAgICAgICAgICAgICAgICAgICAgICBuID0gaGVyZV9iaXRzICsgMzsKICAgICAgICAgICAgICAgICAgICAgIHdoaWxlIChiaXRzIDwgbikgewogICAgICAgICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICBob2xkID4+Pj0gaGVyZV9iaXRzOwogICAgICAgICAgICAgICAgICAgICAgYml0cyAtPSBoZXJlX2JpdHM7CiAgICAgICAgICAgICAgICAgICAgICBsZW4gPSAwOwogICAgICAgICAgICAgICAgICAgICAgY29weSA9IDMgKyAoaG9sZCAmIDcpOwogICAgICAgICAgICAgICAgICAgICAgaG9sZCA+Pj49IDM7CiAgICAgICAgICAgICAgICAgICAgICBiaXRzIC09IDM7CiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgIG4gPSBoZXJlX2JpdHMgKyA3OwogICAgICAgICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCBuKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgIGhvbGQgPj4+PSBoZXJlX2JpdHM7CiAgICAgICAgICAgICAgICAgICAgICBiaXRzIC09IGhlcmVfYml0czsKICAgICAgICAgICAgICAgICAgICAgIGxlbiA9IDA7CiAgICAgICAgICAgICAgICAgICAgICBjb3B5ID0gMTEgKyAoaG9sZCAmIDEyNyk7CiAgICAgICAgICAgICAgICAgICAgICBob2xkID4+Pj0gNzsKICAgICAgICAgICAgICAgICAgICAgIGJpdHMgLT0gNzsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgaWYgKHN0YXRlLmhhdmUgKyBjb3B5ID4gc3RhdGUubmxlbiArIHN0YXRlLm5kaXN0KSB7CiAgICAgICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbnZhbGlkIGJpdCBsZW5ndGggcmVwZWF0IjsKICAgICAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgd2hpbGUgKGNvcHktLSkgewogICAgICAgICAgICAgICAgICAgICAgc3RhdGUubGVuc1tzdGF0ZS5oYXZlKytdID0gbGVuOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKHN0YXRlLm1vZGUgPT09IEJBRCkgewogICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5sZW5zWzI1Nl0gPT09IDApIHsKICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW52YWxpZCBjb2RlIC0tIG1pc3NpbmcgZW5kLW9mLWJsb2NrIjsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5sZW5iaXRzID0gOTsKICAgICAgICAgICAgICAgIG9wdHMgPSB7IGJpdHM6IHN0YXRlLmxlbmJpdHMgfTsKICAgICAgICAgICAgICAgIHJldCA9IGluZmxhdGVfdGFibGUoTEVOUywgc3RhdGUubGVucywgMCwgc3RhdGUubmxlbiwgc3RhdGUubGVuY29kZSwgMCwgc3RhdGUud29yaywgb3B0cyk7CiAgICAgICAgICAgICAgICBzdGF0ZS5sZW5iaXRzID0gb3B0cy5iaXRzOwogICAgICAgICAgICAgICAgaWYgKHJldCkgewogICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbnZhbGlkIGxpdGVyYWwvbGVuZ3RocyBzZXQiOwogICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEOwogICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0YXRlLmRpc3RiaXRzID0gNjsKICAgICAgICAgICAgICAgIHN0YXRlLmRpc3Rjb2RlID0gc3RhdGUuZGlzdGR5bjsKICAgICAgICAgICAgICAgIG9wdHMgPSB7IGJpdHM6IHN0YXRlLmRpc3RiaXRzIH07CiAgICAgICAgICAgICAgICByZXQgPSBpbmZsYXRlX3RhYmxlKERJU1RTLCBzdGF0ZS5sZW5zLCBzdGF0ZS5ubGVuLCBzdGF0ZS5uZGlzdCwgc3RhdGUuZGlzdGNvZGUsIDAsIHN0YXRlLndvcmssIG9wdHMpOwogICAgICAgICAgICAgICAgc3RhdGUuZGlzdGJpdHMgPSBvcHRzLmJpdHM7CiAgICAgICAgICAgICAgICBpZiAocmV0KSB7CiAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImludmFsaWQgZGlzdGFuY2VzIHNldCI7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IExFTl87CiAgICAgICAgICAgICAgICBpZiAoZmx1c2ggPT09IFpfVFJFRVMpIHsKICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGNhc2UgTEVOXzoKICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBMRU47CiAgICAgICAgICAgICAgY2FzZSBMRU46CiAgICAgICAgICAgICAgICBpZiAoaGF2ZSA+PSA2ICYmIGxlZnQgPj0gMjU4KSB7CiAgICAgICAgICAgICAgICAgIHN0cm0ubmV4dF9vdXQgPSBwdXQ7CiAgICAgICAgICAgICAgICAgIHN0cm0uYXZhaWxfb3V0ID0gbGVmdDsKICAgICAgICAgICAgICAgICAgc3RybS5uZXh0X2luID0gbmV4dDsKICAgICAgICAgICAgICAgICAgc3RybS5hdmFpbF9pbiA9IGhhdmU7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmhvbGQgPSBob2xkOwogICAgICAgICAgICAgICAgICBzdGF0ZS5iaXRzID0gYml0czsKICAgICAgICAgICAgICAgICAgaW5mbGF0ZV9mYXN0KHN0cm0sIF9vdXQpOwogICAgICAgICAgICAgICAgICBwdXQgPSBzdHJtLm5leHRfb3V0OwogICAgICAgICAgICAgICAgICBvdXRwdXQgPSBzdHJtLm91dHB1dDsKICAgICAgICAgICAgICAgICAgbGVmdCA9IHN0cm0uYXZhaWxfb3V0OwogICAgICAgICAgICAgICAgICBuZXh0ID0gc3RybS5uZXh0X2luOwogICAgICAgICAgICAgICAgICBpbnB1dCA9IHN0cm0uaW5wdXQ7CiAgICAgICAgICAgICAgICAgIGhhdmUgPSBzdHJtLmF2YWlsX2luOwogICAgICAgICAgICAgICAgICBob2xkID0gc3RhdGUuaG9sZDsKICAgICAgICAgICAgICAgICAgYml0cyA9IHN0YXRlLmJpdHM7CiAgICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5tb2RlID09PSBUWVBFKSB7CiAgICAgICAgICAgICAgICAgICAgc3RhdGUuYmFjayA9IC0xOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUuYmFjayA9IDA7CiAgICAgICAgICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgICAgICAgICAgaGVyZSA9IHN0YXRlLmxlbmNvZGVbaG9sZCAmICgxIDw8IHN0YXRlLmxlbmJpdHMpIC0gMV07CiAgICAgICAgICAgICAgICAgIGhlcmVfYml0cyA9IGhlcmUgPj4+IDI0OwogICAgICAgICAgICAgICAgICBoZXJlX29wID0gaGVyZSA+Pj4gMTYgJiAyNTU7CiAgICAgICAgICAgICAgICAgIGhlcmVfdmFsID0gaGVyZSAmIDY1NTM1OwogICAgICAgICAgICAgICAgICBpZiAoaGVyZV9iaXRzIDw9IGJpdHMpIHsKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoaGVyZV9vcCAmJiAoaGVyZV9vcCAmIDI0MCkgPT09IDApIHsKICAgICAgICAgICAgICAgICAgbGFzdF9iaXRzID0gaGVyZV9iaXRzOwogICAgICAgICAgICAgICAgICBsYXN0X29wID0gaGVyZV9vcDsKICAgICAgICAgICAgICAgICAgbGFzdF92YWwgPSBoZXJlX3ZhbDsKICAgICAgICAgICAgICAgICAgZm9yICg7IDsgKSB7CiAgICAgICAgICAgICAgICAgICAgaGVyZSA9IHN0YXRlLmxlbmNvZGVbbGFzdF92YWwgKyAoKGhvbGQgJiAoMSA8PCBsYXN0X2JpdHMgKyBsYXN0X29wKSAtIDEpID4+IGxhc3RfYml0cyldOwogICAgICAgICAgICAgICAgICAgIGhlcmVfYml0cyA9IGhlcmUgPj4+IDI0OwogICAgICAgICAgICAgICAgICAgIGhlcmVfb3AgPSBoZXJlID4+PiAxNiAmIDI1NTsKICAgICAgICAgICAgICAgICAgICBoZXJlX3ZhbCA9IGhlcmUgJiA2NTUzNTsKICAgICAgICAgICAgICAgICAgICBpZiAobGFzdF9iaXRzICsgaGVyZV9iaXRzIDw9IGJpdHMpIHsKICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGhvbGQgPj4+PSBsYXN0X2JpdHM7CiAgICAgICAgICAgICAgICAgIGJpdHMgLT0gbGFzdF9iaXRzOwogICAgICAgICAgICAgICAgICBzdGF0ZS5iYWNrICs9IGxhc3RfYml0czsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGhvbGQgPj4+PSBoZXJlX2JpdHM7CiAgICAgICAgICAgICAgICBiaXRzIC09IGhlcmVfYml0czsKICAgICAgICAgICAgICAgIHN0YXRlLmJhY2sgKz0gaGVyZV9iaXRzOwogICAgICAgICAgICAgICAgc3RhdGUubGVuZ3RoID0gaGVyZV92YWw7CiAgICAgICAgICAgICAgICBpZiAoaGVyZV9vcCA9PT0gMCkgewogICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gTElUOwogICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmIChoZXJlX29wICYgMzIpIHsKICAgICAgICAgICAgICAgICAgc3RhdGUuYmFjayA9IC0xOwogICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gVFlQRTsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoaGVyZV9vcCAmIDY0KSB7CiAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImludmFsaWQgbGl0ZXJhbC9sZW5ndGggY29kZSI7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUuZXh0cmEgPSBoZXJlX29wICYgMTU7CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gTEVORVhUOwogICAgICAgICAgICAgIGNhc2UgTEVORVhUOgogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmV4dHJhKSB7CiAgICAgICAgICAgICAgICAgIG4gPSBzdGF0ZS5leHRyYTsKICAgICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCBuKSB7CiAgICAgICAgICAgICAgICAgICAgaWYgKGhhdmUgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgaGF2ZS0tOwogICAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBzdGF0ZS5sZW5ndGggKz0gaG9sZCAmICgxIDw8IHN0YXRlLmV4dHJhKSAtIDE7CiAgICAgICAgICAgICAgICAgIGhvbGQgPj4+PSBzdGF0ZS5leHRyYTsKICAgICAgICAgICAgICAgICAgYml0cyAtPSBzdGF0ZS5leHRyYTsKICAgICAgICAgICAgICAgICAgc3RhdGUuYmFjayArPSBzdGF0ZS5leHRyYTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0YXRlLndhcyA9IHN0YXRlLmxlbmd0aDsKICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBESVNUOwogICAgICAgICAgICAgIGNhc2UgRElTVDoKICAgICAgICAgICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgICAgICAgICBoZXJlID0gc3RhdGUuZGlzdGNvZGVbaG9sZCAmICgxIDw8IHN0YXRlLmRpc3RiaXRzKSAtIDFdOwogICAgICAgICAgICAgICAgICBoZXJlX2JpdHMgPSBoZXJlID4+PiAyNDsKICAgICAgICAgICAgICAgICAgaGVyZV9vcCA9IGhlcmUgPj4+IDE2ICYgMjU1OwogICAgICAgICAgICAgICAgICBoZXJlX3ZhbCA9IGhlcmUgJiA2NTUzNTsKICAgICAgICAgICAgICAgICAgaWYgKGhlcmVfYml0cyA8PSBiaXRzKSB7CiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaWYgKGhhdmUgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaGF2ZS0tOwogICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKChoZXJlX29wICYgMjQwKSA9PT0gMCkgewogICAgICAgICAgICAgICAgICBsYXN0X2JpdHMgPSBoZXJlX2JpdHM7CiAgICAgICAgICAgICAgICAgIGxhc3Rfb3AgPSBoZXJlX29wOwogICAgICAgICAgICAgICAgICBsYXN0X3ZhbCA9IGhlcmVfdmFsOwogICAgICAgICAgICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgICAgICAgICAgICBoZXJlID0gc3RhdGUuZGlzdGNvZGVbbGFzdF92YWwgKyAoKGhvbGQgJiAoMSA8PCBsYXN0X2JpdHMgKyBsYXN0X29wKSAtIDEpID4+IGxhc3RfYml0cyldOwogICAgICAgICAgICAgICAgICAgIGhlcmVfYml0cyA9IGhlcmUgPj4+IDI0OwogICAgICAgICAgICAgICAgICAgIGhlcmVfb3AgPSBoZXJlID4+PiAxNiAmIDI1NTsKICAgICAgICAgICAgICAgICAgICBoZXJlX3ZhbCA9IGhlcmUgJiA2NTUzNTsKICAgICAgICAgICAgICAgICAgICBpZiAobGFzdF9iaXRzICsgaGVyZV9iaXRzIDw9IGJpdHMpIHsKICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGhvbGQgPj4+PSBsYXN0X2JpdHM7CiAgICAgICAgICAgICAgICAgIGJpdHMgLT0gbGFzdF9iaXRzOwogICAgICAgICAgICAgICAgICBzdGF0ZS5iYWNrICs9IGxhc3RfYml0czsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGhvbGQgPj4+PSBoZXJlX2JpdHM7CiAgICAgICAgICAgICAgICBiaXRzIC09IGhlcmVfYml0czsKICAgICAgICAgICAgICAgIHN0YXRlLmJhY2sgKz0gaGVyZV9iaXRzOwogICAgICAgICAgICAgICAgaWYgKGhlcmVfb3AgJiA2NCkgewogICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbnZhbGlkIGRpc3RhbmNlIGNvZGUiOwogICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEOwogICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0YXRlLm9mZnNldCA9IGhlcmVfdmFsOwogICAgICAgICAgICAgICAgc3RhdGUuZXh0cmEgPSBoZXJlX29wICYgMTU7CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gRElTVEVYVDsKICAgICAgICAgICAgICBjYXNlIERJU1RFWFQ6CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuZXh0cmEpIHsKICAgICAgICAgICAgICAgICAgbiA9IHN0YXRlLmV4dHJhOwogICAgICAgICAgICAgICAgICB3aGlsZSAoYml0cyA8IG4pIHsKICAgICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIHN0YXRlLm9mZnNldCArPSBob2xkICYgKDEgPDwgc3RhdGUuZXh0cmEpIC0gMTsKICAgICAgICAgICAgICAgICAgaG9sZCA+Pj49IHN0YXRlLmV4dHJhOwogICAgICAgICAgICAgICAgICBiaXRzIC09IHN0YXRlLmV4dHJhOwogICAgICAgICAgICAgICAgICBzdGF0ZS5iYWNrICs9IHN0YXRlLmV4dHJhOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKHN0YXRlLm9mZnNldCA+IHN0YXRlLmRtYXgpIHsKICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW52YWxpZCBkaXN0YW5jZSB0b28gZmFyIGJhY2siOwogICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEOwogICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBNQVRDSDsKICAgICAgICAgICAgICBjYXNlIE1BVENIOgogICAgICAgICAgICAgICAgaWYgKGxlZnQgPT09IDApIHsKICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgY29weSA9IF9vdXQgLSBsZWZ0OwogICAgICAgICAgICAgICAgaWYgKHN0YXRlLm9mZnNldCA+IGNvcHkpIHsKICAgICAgICAgICAgICAgICAgY29weSA9IHN0YXRlLm9mZnNldCAtIGNvcHk7CiAgICAgICAgICAgICAgICAgIGlmIChjb3B5ID4gc3RhdGUud2hhdmUpIHsKICAgICAgICAgICAgICAgICAgICBpZiAoc3RhdGUuc2FuZSkgewogICAgICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW52YWxpZCBkaXN0YW5jZSB0b28gZmFyIGJhY2siOwogICAgICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBpZiAoY29weSA+IHN0YXRlLnduZXh0KSB7CiAgICAgICAgICAgICAgICAgICAgY29weSAtPSBzdGF0ZS53bmV4dDsKICAgICAgICAgICAgICAgICAgICBmcm9tID0gc3RhdGUud3NpemUgLSBjb3B5OwogICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgIGZyb20gPSBzdGF0ZS53bmV4dCAtIGNvcHk7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaWYgKGNvcHkgPiBzdGF0ZS5sZW5ndGgpIHsKICAgICAgICAgICAgICAgICAgICBjb3B5ID0gc3RhdGUubGVuZ3RoOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGZyb21fc291cmNlID0gc3RhdGUud2luZG93OwogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgZnJvbV9zb3VyY2UgPSBvdXRwdXQ7CiAgICAgICAgICAgICAgICAgIGZyb20gPSBwdXQgLSBzdGF0ZS5vZmZzZXQ7CiAgICAgICAgICAgICAgICAgIGNvcHkgPSBzdGF0ZS5sZW5ndGg7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoY29weSA+IGxlZnQpIHsKICAgICAgICAgICAgICAgICAgY29weSA9IGxlZnQ7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBsZWZ0IC09IGNvcHk7CiAgICAgICAgICAgICAgICBzdGF0ZS5sZW5ndGggLT0gY29weTsKICAgICAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICAgICAgb3V0cHV0W3B1dCsrXSA9IGZyb21fc291cmNlW2Zyb20rK107CiAgICAgICAgICAgICAgICB9IHdoaWxlICgtLWNvcHkpOwogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmxlbmd0aCA9PT0gMCkgewogICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gTEVOOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgY2FzZSBMSVQ6CiAgICAgICAgICAgICAgICBpZiAobGVmdCA9PT0gMCkgewogICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBvdXRwdXRbcHV0KytdID0gc3RhdGUubGVuZ3RoOwogICAgICAgICAgICAgICAgbGVmdC0tOwogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IExFTjsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgIGNhc2UgQ0hFQ0s6CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUud3JhcCkgewogICAgICAgICAgICAgICAgICB3aGlsZSAoYml0cyA8IDMyKSB7CiAgICAgICAgICAgICAgICAgICAgaWYgKGhhdmUgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgaGF2ZS0tOwogICAgICAgICAgICAgICAgICAgIGhvbGQgfD0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBfb3V0IC09IGxlZnQ7CiAgICAgICAgICAgICAgICAgIHN0cm0udG90YWxfb3V0ICs9IF9vdXQ7CiAgICAgICAgICAgICAgICAgIHN0YXRlLnRvdGFsICs9IF9vdXQ7CiAgICAgICAgICAgICAgICAgIGlmIChfb3V0KSB7CiAgICAgICAgICAgICAgICAgICAgc3RybS5hZGxlciA9IHN0YXRlLmNoZWNrID0gc3RhdGUuZmxhZ3MgPyBjcmMzMihzdGF0ZS5jaGVjaywgb3V0cHV0LCBfb3V0LCBwdXQgLSBfb3V0KSA6IGFkbGVyMzIoc3RhdGUuY2hlY2ssIG91dHB1dCwgX291dCwgcHV0IC0gX291dCk7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgX291dCA9IGxlZnQ7CiAgICAgICAgICAgICAgICAgIGlmICgoc3RhdGUuZmxhZ3MgPyBob2xkIDogenN3YXAzMihob2xkKSkgIT09IHN0YXRlLmNoZWNrKSB7CiAgICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW5jb3JyZWN0IGRhdGEgY2hlY2siOwogICAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaG9sZCA9IDA7CiAgICAgICAgICAgICAgICAgIGJpdHMgPSAwOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IExFTkdUSDsKICAgICAgICAgICAgICBjYXNlIExFTkdUSDoKICAgICAgICAgICAgICAgIGlmIChzdGF0ZS53cmFwICYmIHN0YXRlLmZsYWdzKSB7CiAgICAgICAgICAgICAgICAgIHdoaWxlIChiaXRzIDwgMzIpIHsKICAgICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChob2xkICE9PSAoc3RhdGUudG90YWwgJiA0Mjk0OTY3Mjk1KSkgewogICAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImluY29ycmVjdCBsZW5ndGggY2hlY2siOwogICAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaG9sZCA9IDA7CiAgICAgICAgICAgICAgICAgIGJpdHMgPSAwOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IERPTkU7CiAgICAgICAgICAgICAgY2FzZSBET05FOgogICAgICAgICAgICAgICAgcmV0ID0gWl9TVFJFQU1fRU5EOwogICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgIGNhc2UgQkFEOgogICAgICAgICAgICAgICAgcmV0ID0gWl9EQVRBX0VSUk9SOwogICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgIGNhc2UgTUVNOgogICAgICAgICAgICAgICAgcmV0dXJuIFpfTUVNX0VSUk9SOwogICAgICAgICAgICAgIGNhc2UgU1lOQzoKICAgICAgICAgICAgICBkZWZhdWx0OgogICAgICAgICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VSUk9SOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgc3RybS5uZXh0X291dCA9IHB1dDsKICAgICAgICBzdHJtLmF2YWlsX291dCA9IGxlZnQ7CiAgICAgICAgc3RybS5uZXh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DApICsgKHN0YXRlLm1vZGUgPT09IExFTl8gfHwgc3RhdGUubW9kZSA9PT0gQ09QWV8gPyAyNTYgOiAwKTsKICAgICAgICBpZiAoKF9pbiA9PT0gMCAmJiBfb3V0ID09PSAwIHx8IGZsdXNoID09PSBaX0ZJTklTSCkgJiYgcmV0ID09PSBaX09LKSB7CiAgICAgICAgICByZXQgPSBaX0JVRl9FUlJPUjsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHJldDsKICAgICAgfQogICAgICBmdW5jdGlvbiBpbmZsYXRlRW5kKHN0cm0pIHsKICAgICAgICBpZiAoIXN0cm0gfHwgIXN0cm0uc3RhdGUpIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgdmFyIHN0YXRlID0gc3RybS5zdGF0ZTsKICAgICAgICBpZiAoc3RhdGUud2luZG93KSB7CiAgICAgICAgICBzdGF0ZS53aW5kb3cgPSBudWxsOwogICAgICAgIH0KICAgICAgICBzdHJtLnN0YXRlID0gbnVsbDsKICAgICAgICByZXR1cm4gWl9PSzsKICAgICAgfQogICAgICBmdW5jdGlvbiBpbmZsYXRlR2V0SGVhZGVyKHN0cm0sIGhlYWQpIHsKICAgICAgICB2YXIgc3RhdGU7CiAgICAgICAgaWYgKCFzdHJtIHx8ICFzdHJtLnN0YXRlKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIHN0YXRlID0gc3RybS5zdGF0ZTsKICAgICAgICBpZiAoKHN0YXRlLndyYXAgJiAyKSA9PT0gMCkgewogICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VSUk9SOwogICAgICAgIH0KICAgICAgICBzdGF0ZS5oZWFkID0gaGVhZDsKICAgICAgICBoZWFkLmRvbmUgPSBmYWxzZTsKICAgICAgICByZXR1cm4gWl9PSzsKICAgICAgfQogICAgICBmdW5jdGlvbiBpbmZsYXRlU2V0RGljdGlvbmFyeShzdH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DSzogNSwKICAgICAgICBaX1RSRUVTOiA2LAogICAgICAgIFpfT0s6IDAsCiAgICAgICAgWl9TVFJFQU1fRU5EOiAxLAogICAgICAgIFpfTkVFRF9ESUNUOiAyLAogICAgICAgIFpfRVJSTk86IC0xLAogICAgICAgIFpfU1RSRUFNX0VSUk9SOiAtMiwKICAgICAgICBaX0RBVEFfRVJST1I6IC0zLAogICAgICAgIFpfQlVGX0VSUk9SOiAtNSwKICAgICAgICBaX05PX0NPTVBSRVNTSU9OOiAwLAogICAgICAgIFpfQkVTVF9TUEVFRDogMSwKICAgICAgICBaX0JFU1RfQ09NUFJFU1NJT046IDksCiAgICAgICAgWl9ERUZBVUxUX0NPTVBSRVNTSU9OOiAtMSwKICAgICAgICBaX0ZJTFRFUkVEOiAxLAogICAgICAgIFpfSFVGRk1BTl9PTkxZOiAyLAogICAgICAgIFpfUkxFOiAzLAogICAgICAgIFpfRklYRUQ6IDQsCiAgICAgICAgWl9ERUZBVUxUX1NUUkFURUdZOiAwLAogICAgICAgIFpfQklOQVJZOiAwLAogICAgICAgIFpfVEVYVDogMSwKICAgICAgICBaX1VOS05PV046IDIsCiAgICAgICAgWl9ERUZMQVRFRDogOAogICAgICB9OwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvZ3poZWFkZXIuanMKICB2YXIgcmVxdWlyZV9nemhlYWRlciA9IF9fY29tbW9uSlMoewogICAgIm5vZGVfbW9kdWxlcy8ucG5wbS9wYWtvQDEuMC4xMS9ub2RlX21vZHVsZXMvcGFrby9saWIvemxpYi9nemhlYWRlci5qcyIoZXhwb3J0czIsIG1vZHVsZTIpIHsKICAgICAgaW5pdF9idWZmZXJfc2hpbSgpOwogICAgICAidXNlIHN0cmljdCI7CiAgICAgIGZ1bmN0aW9uIEdaaGVhZGVyKCkgewogICAgICAgIHRoaXMudGV4dCA9IDA7CiAgICAgICAgdGh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SW5mbGF0ZTIob3B0aW9ucykgewogICAgICAgIGlmICghKHRoaXMgaW5zdGFuY2VvZiBJbmZsYXRlMikpCiAgICAgICAgICByZXR1cm4gbmV3IEluZmxhdGUyKG9wdGlvbnMpOwogICAgICAgIHRoaXMub3B0aW9ucyA9IHV0aWxzLmFzc2lnbih7CiAgICAgICAgICBjaHVua1NpemU6IDE2Mzg0LAogICAgICAgICAgd2luZG93Qml0czogMCwKICAgICAgICAgIHRvOiAiIgogICAgICAgIH0sIG9wdGlvbnMgfHwge30pOwogICAgICAgIHZhciBvcHQgPSB0aGlzLm9wdGlvbnM7CiAgICAgICAgaWYgKG9wdC5yYXcgJiYgb3B0LndpbmRvd0JpdHMgPj0gMCAmJiBvcHQud2luZG93Qml0cyA8IDE2KSB7CiAgICAgICAgICBvcHQud2luZG93Qml0cyA9IC1vcHQud2luZG93Qml0czsKICAgICAgICAgIGlmIChvcHQud2luZG93Qml0cyA9PT0gMCkgewogICAgICAgICAgICBvcHQud2luZG93Qml0cyA9IC0xNTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKG9wdC53aW5kb3dCaXRzID49IDAgJiYgb3B0LndpbmRvd0JpdHMgPCAxNiAmJiAhKG9wdGlvbnMgJiYgb3B0aW9ucy53aW5kb3dCaXRzKSkgewogICAgICAgICAgb3B0LndpbmRvd0JpdHMgKz0gMzI7CiAgICAgICAgfQogICAgICAgIGlmIChvcHQud2luZG93Qml0cyA+IDE1ICYmIG9wdC53aW5kb3dCaXRzIDwgNDgpIHsKICAgICAgICAgIGlmICgob3B0LndpbmRvd0JpdHMgJiAxNSkgPT09IDApIHsKICAgICAgICAgICAgb3B0LndpbmRvd0JpdHMgfD0gMTU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHRoaXMuZXJyID0gMDsKICAgICAgICB0aGlzLm1zZyA9ICIiOwogICAgICAgIHRoaXMuZW5kZWQgPSBmYWxzZTsKICAgICAgICB0aGlzLmNodW5rcyA9IFtdOwog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AgfQogICAgICAgIH0KICAgICAgfQogICAgICBJbmZsYXRlMi5wcm90b3R5cGUucHVzaCA9IGZ1bmN0aW9uKGRhdGEsIG1vZGUpIHsKICAgICAgICB2YXIgc3RybSA9IHRoaXMuc3RybTsKICAgICAgICB2YXIgY2h1bmtTaXplID0gdGhpcy5vcHRpb25zLmNodW5rU2l6ZTsKICAgICAgICB2YXIgZGljdGlvbmFyeSA9IHRoaXMub3B0aW9ucy5kaWN0aW9uYXJ5OwogICAgICAgIHZhciBzdGF0dXMsIF9tb2RlOwogICAgICAgIHZhciBuZXh0X291dF91dGY4LCB0YWlsLCB1dGY4c3RyOwogICAgICAgIHZhciBhbGxvd0J1ZkVycm9yID0gZmFsc2U7CiAgICAgICAgaWYgKHRoaXMuZW5kZWQpIHsKICAgICAgICAgIHJldHVybiBmYWxzZTsKICAgICAgICB9CiAgICAgICAgX21vZGUgPSBtb2RlID09PSB+fm1vZGUgPyBtb2RlIDogbW9kZSA9PT0gdHJ1ZSA/IGMuWl9GSU5JU0ggOiBjLlpfTk9fRkxVU0g7CiAgICAgICAgaWYgKHR5cGVvZiBkYXRhID09PSAic3RyaW5nIikgewogICAgICAgICAgc3RybS5pbnB1dCA9IHN0cmluZ3MuYmluc3RyaW5nMmJ1ZihkYXRhKTsKICAgICAgICB9IGVsc2UgaWYgKHRvU3RyaW5nLmNhbGwoZGF0YSkgPT09ICJbb2JqZWN0IEFycmF5QnVmZmVyXSIpIHsKICAgICAgICAgIHN0cm0uaW5wdXQgPSBuZXcgVWludDhBcnJheShkYXRhKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgc3RybS5pbnB1dCA9IGRhdGE7CiAgICAgICAgfQogICAgICAgIHN0cm0ubmV4dF9pbiA9IDA7CiAgICAgICAgc3RybS5hdmFpbF9pbiA9IHN0cm0uaW5wdXQubGVuZ3RoOwogICAgICAgIGRvIHsKICAgICAgICAgIGlmIChzdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICBzdHJtLm91dHB1dCA9IG5ldyB1dGlscy5CdWY4KGNodW5rU2l6ZSk7CiAgICAgICAgICAgIHN0cm0ubmV4dF9vdXQgPSAwOwogICAgICAgICAgICBzdHJtLmF2YWlsX291dCA9IGNodW5rU2l6ZTsKICAgICAgICAgIH0KICAgICAgICAgIHN0YXR1cyA9IHpsaWJfaW5mbGF0ZS5pbmZsYXRlKHN0cm0sIGMuWl9OT19GTFVTSCk7CiAgICAgICAgICBpZiAoc3RhdHVzID09PSBjLlpfTkVFRF9ESUNUICYmIGRpY3Rpb25hcnkpIHsKICAgICAgICAgICAgc3RhdHVzID0gemxpYl9pbmZsYXRlLmluZmxhdGVTZXREaWN0aW9uYXJ5KHRoaXMuc3RybSwgZGljdGlvbmFyeSk7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoc3RhdHVzID09PSBjLlpfQlVGX0VSUk9SICYmIGFsbG93QnVmRXJyb3IgPT09IHRydWUpIHsKICAgICAgICAgICAgc3RhdHVzID0gYy5aX09LOwogICAgICAgICAgICBhbGxvd0J1ZkVycm9yID0gZmFsc2U7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoc3RhdHVzICE9PSBjLlpfU1RSRUFNX0VORCAmJiBzdGF0dXMgIT09IGMuWl9PSykgewogICAgICAgICAgICB0aGlzLm9uRW5kKHN0YXR1cyk7CiAgICAgICAgICAgIHRoaXMuZW5kZWQgPSB0cnVlOwogICAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoc3RybS5uZXh0X291dCkgewogICAgICAgICAgICBpZiAoc3RybS5hdmFpbF9vdXQgPT09IDAgfHwgc3RhdHVzID09PSBjLlpfU1RSRUFNX0VORCB8fCBzdHJtLmF2YWlsX2luID09PSAwICYmIChfbW9kZSA9PT0gYy5aX0ZJTklTSCB8fCBfbW9kZSA9PT0gYy5aX1NZTkNfRkxVU0gpKSB7CiAgICAgICAgICAgICAgaWYgKHRoaXMub3B0aW9ucy50byA9PT0gInN0cmluZyIpIHsKICAgICAgICAgICAgICAgIG5leHRfb3V0X3V0ZjggPSBzdHJpbmdzLnV0Zjhib3JkZXIoc3RybS5vdXRwdXQsIHN0cm0ubmV4dF9vdXQpOwogICAgICAgICAgICAgICAgdGFpbCA9IHN0cm0ubmV4dF9vdXQgLSBuZXh0X291dF91dGY4OwogICAgICAgICAgICAgICAgdXRmOHN0ciA9IHN0cmluZ3MuYnVmMnN0cmluZyhzdHJtLm91dHB1dCwgbmV4dF9vdXRfdXRmOCk7CiAgICAgICAgICAgICAgICBzdHJtLm5leHRfb3V0ID0gdGFpbDsKICAgICAgICAgICAgICAgIHN0cm0uYXZhaWxfb3V0ID0gY2h1bmtTaXplIC0gdGFpbDsKICAgICAgICAgICAgICAgIGlmICh0YWlsKSB7CiAgICAgICAgICAgICAgICAgIHV0aWxzLmFycmF5U2V0KHN0cm0ub3V0cHV0LCBzdHJtLm91dHB1dCwgbmV4dF9vdXRfdXRmOCwgdGFpbCwgMCk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB0aGlzLm9uRGF0YSh1dGY4c3RyKTsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgdGhpcy5vbkRhdGEodXRpbHMuc2hyaW5rQnVmKHN0cm0ub3V0cHV0LCBzdHJtLm5leHRfb3V0KSk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoc3RybS5hdmFpbF9pbiA9PT0gMCAmJiBzdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICBhbGxvd0J1ZkVycm9yID0gdHJ1ZTsKICAgICAgICAgIH0KICAgICAgICB9IHdoaWxlICgoc3RybS5hdmFpbF9pbiA+IDAgfHwgc3RybS5hdmFpbF9vdXQgPT09IDApICYmIHN0YXR1cyAhPT0gYy5aX1NUUkVBTV9FTkQpOwogICAgICAgIGlmIChzdGF0dXMgPT09IGMuWl9TVFJFQU1fRU5EKSB7CiAgICAgICAgICBfbW9kZSA9IGMuWl9GSU5JU0g7CiAgICAgICAgfQogICAgICAgIGlmIChfbW9kZSA9PT0gYy5aX0ZJTklTSCkgewogICAgICAgICAgc3RhdHVzID0gemxpYl9pbmZsYXRlLmluZmxhdGVFbmQodGhpcy5zdHJtKTsKICAgICAgICAgIHRoaXMub25FbmQoc3RhdHVzKTsKICAgICAgICAgIHRoaXMuZW5kZWQgPSB0cnVlOwogICAgICAgICAgcmV0dXJuIHN0YXR1cyA9PT0gYy5aX09LOwogICAgICAgIH0KICAgICAgICBpZiAoX21vZGUgPT09IGMuWl9TWU5DX0ZMVVNIKSB7CiAgICAgICAgICB0aGlzLm9uRW5kKGMuWl9PSyk7CiAgICAgICAgICBzdHJtLmF2YWlsX291dCA9IDA7CiAgICAgICAgICByZXR1cm4gdHJ1ZTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHRydWU7CiAgICAgIH07CiAgICAgIEluZmxhdGUyLnByb3RvdHlwZS5vbkRhdGEgPSBmdW5jdGlvbihjaHVuaykgewogICAgICAgIHRoaXMuY2h1bmtzLnB1c2goY2h1bmspOwogICAgICB9OwogICAgICBJbmZsYXRlMi5wcm90b3R5cGUub25FbmQgPSBmdW5jdGlvbihzdGF0dXMpIHsKICAgICAgICBpZiAoc3RhdHVzID09PSBjLlpfT0spIHsKICAgICAgICAgIGlmICh0aGlzLm9wdGlvbnMudG8gPT09ICJzdHJpbmciKSB7CiAgICAgICAgICAgIHRoaXMucmVzdWx0ID0gdGhpcy5jaHVua3Muam9pbigiIik7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICB0aGlzLnJlc3VsdCA9IHV0aWxzLmZsYXR0ZW5DaHVua3ModGhpcy5jaHVua3MpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICB0aGlzLmNodW5rcyA9IFtdOwogICAgICAgIHRoaXMuZXJyID0gc3RhdHVzOwogICAgICAgIHRoaXMubXNnID0gdGhpcy5zdHJtLm1zZzsKICAgICAg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iAgICAgIHZhciBkZWZsYXRlID0gcmVxdWlyZV9kZWZsYXRlMigpOwogICAgICB2YXIgaW5mbGF0ZSA9IHJlcXVpcmVfaW5mbGF0ZTIoKTsKICAgICAgdmFyIGNvbnN0YW50cyA9IHJlcXVpcmVfY29uc3RhbnRzKCk7CiAgICAgIHZhciBwYWtvID0ge307CiAgICAgIGFzc2lnbihwYWtvLCBkZWZsYXRlLCBpbmZsYXRlLCBjb25zdGFudHMpOwogICAgICBtb2R1bGUyLmV4cG9ydHMgPSBwYWtvOwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vbG9uZ0A0LjAuMC9ub2RlX21vZHVsZXMvbG9uZy9zcmMvbG9uZy5qcwogIHZhciByZXF1aXJlX2xvbmcgPSBfX2NvbW1vbkpTKHsKICAgICJub2RlX21vZHVsZXMvLnBucG0vbG9uZ0A0LjAuMC9ub2RlX21vZHVsZXMvbG9uZy9zcmMvbG9uZy5qcyIoZXhwb3J0czIsIG1vZHVsZTIpIHsKICAgICAgaW5pdF9idWZmZXJfc2hpbSgpOwogICAgICBtb2R1bGUyLmV4cG9ydHMgPSBMb25nNDsKICAgICAgdmFyIHdhc20gPSBudWxsOwogICAgICB0cnkgewogICAgICAgIHdhc20gPSBuZXcgV2ViQXNzZW1ibHkuSW5zdGFuY2UobmV3IFdlYkFzc2VtYmx5Lk1vZHVsZShuZXcgVWludDhBcnJheShbCiAgICAgICAgICAwLAogICAgICAgICAgOTcsCiAgICAgICAgICAxMTUsCiAgICAgICAgICAxMDksCiAgICAgICAgICAxLAogICAgICAgICAgMCwKICAgICAgICAgIDAsCiAgICAgICAgICAwLAogICAgICAgICAgMSwKICAgICAgICAgIDEzLAogICAgICAgICAgMiwKICAgICAgICAgIDk2LAogICAgICAgICAgMCwKICAgICAgICAgIDEsCiAgICAgICAgICAxMjcsCiAgICAgICAgICA5NiwKICAgICAgICAgIDQsCiAgICAgICAgICAxMjcsCiAgICAgICAgICAxMjcsCiAgICAgICAgICAxMjcsCiAgICAgICAgICAxMjcsCiAgICAgICAgICAxLAogICAgICAgICAgMTI3LAogICAgICAgICAgMywKICAgICAgICAgIDcsCiAgICAgICAgICA2LAogICAgICAgICAgMCwKICAgICAgICAgIDEsCiAgICAgICAgICAxLAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICAxLAogICAgICAgICAgNiwKICAgICAgICAgIDYsCiAgICAgICAgICAxLAogICAgICAgICAgMTI3LAogICAgICAgICAgMSwKICAgICAgICAgIDY1LAogICAgICAgICAgMCwKICAgICAgICAgIDExLAogICAgICAgICAgNywKICAgICAgICAgIDUwLAogICAgICAgICAgNiwKICAgICAgICAgIDMsCiAgICAgICAgICAxMDksCiAgICAgICAgICAxMTcsCiAgICAgICAgICAxMDgsCiAgICAgICAgICAwLAogICAgICAgICAgMSwKICAgICAgICAgIDUsCiAgICAgICAgICAxMDAsCiAgICAgICAgICAxMDUsCiAgICAgICAgICAxMTgsCiAgICAgICAgICA5NSwKICAgICAgICAgIDExNSwKICAgICAgICAgIDAsCiAgICAgICAgICAyLAogICAgICAgICAgNSwKICAgICAgICAgIDEwMCwKICAgICAgICAgIDEwNSwKICAgICAgICAgIDExOCwKICAgICAgICAgIDk1LAogICAgICAgICAgMTE3LAogICAgICAgICAgMCwKICAgICAgICAgIDMsCiAgICAgICAgICA1LAogICAgICAgICAgMTE0LAogICAgICAgICAgMTAxLAogICAgICAgICAgMTA5LAogICAgICAgICAgOTUsCiAgICAgICAgICAxMTUsCiAgICAgICAgICAwLAogICAgICAgICAgNCwKICAgICAgICAgIDUsCiAgICAgICAgICAxMTQsCiAgICAgICAgICAxMDEsCiAgICAgICAgICAxMDksCiAgICAgICAgICA5NSwKICAgICAgICAgIDExNywKICAgICAgICAgIDAsCiAgICAgICAgICA1LAogICAgICAgICAgOCwKICAgICAgICAgIDEwMywKICAgICAgICAgIDEwMSwKICAgICAgICAgIDExNiwKICAgICAgICAgIDk1LAogICAgICAgICAgMTA0LAogICAgICAgICAgMTA1LAogICAgICAgICAgMTAzLAogICAgICAgICAgMTA0LAogICAgICAgICAgMCwKICAgICAgICAgIDAsCiAgICAgICAgICAxMCwKICAgICAgICAgIDE5MSwKICAgICAgICAgIDEsCiAgICAgICAgICA2LAogICAgICAgICAgNCwKICAgICAgICAgIDAsCiAgICAgICAgICAzNSwKICAgICAgICAgIDAsCiAgICAgICAgICAxMSwKICAgICAgICAgIDM2LAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICAxMjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDAsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMzIsCiAgICAgICAgICAyLAogICAgICAgICAgMTczLAogICAgICAgICAgMzIsCiAgICAgICAgICAzLAogICAgICAgICAgMTczLAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNCwKICAgICAgICAgIDEzMiwKICAgICAgICAgIDEyNiwKICAgICAgICAgIDM0LAogICAgICAgICAgNCwKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzUsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAzNiwKICAgICAgICAgIDAsCiAgICAgICAgICAzMiwKICAgICAgICAgIDQsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAxMSwKICAgICAgICAgIDM2LAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICAxMjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDAsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMzIsCiAgICAgICAgICAyLAogICAgICAgICAgMTczLAogICAgICAgICAgMzIsCiAgICAgICAgICAzLAogICAgICAgICAgMTczLAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNCwKICAgICAgICAgIDEzMiwKICAgICAgICAgIDEyNywKICAgICAgICAgIDM0LAogICAgICAgICAgNCwKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzUsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAzNiwKICAgICAgICAgIDAsCiAgICAgICAgICAzMiwKICAgICAgICAgIDQsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAxMSwKICAgICAgICAgIDM2LAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICAxMjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDAsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMzIsCiAgICAgICAgICAyLAogICAgICAgICAgMTczLAogICAgICAgICAgMzIsCiAgICAgICAgICAzLAogICAgICAgICAgMTczLAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNCwKICAgICAgICAgIDEzMiwKICAgICAgICAgIDEyOCwKICAgICAgICAgIDM0LAogICAgICAgICAgNCwKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzUsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAzNiwKICAgICAgICAgIDAsCiAgICAgICAgICAzMiwKICAgICAgICAgIDQsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAxMSwKICAgICAgICAgIDM2LAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICAxMjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDAsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMzIsCiAgICAgICAgICAyLAogICAgICAgICAgMTczLAogICAgICAgICAgMzIsCiAgICAgICAgICAzLAogICAgICAgICAgMTczLAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNCwKICAgICAgICAgIDEzMiwKICAgICAgICAgIDEyOSwKICAgICAgICAgIDM0LAogICAgICAgICAgNCwKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzUsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAzNiwKICAgICAgICAgIDAsCiAgICAgICAgICAzMiwKICAgICAgICAgIDQsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAxMSwKICAgICAgICAgIDM2LAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICAxMjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDAsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMzIsCiAgICAgICAgICAyLAogICAgICAgICAgMTczLAogICAgICAgICAgMzIsCiAgICAgICAgICAzLAogICAgICAgICAgMTczLAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNCwKICAgICAgICAgIDEzMiwKICAgICAgICAgIDEzMCwKICAgICAgICAgIDM0LAogICAgICAgICAgNCwKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzUsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAzNiwKICAgICAgICAgIDAsCiAgICAgICAgICAzMiwKICAgICAgICAgIDQsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAxMQogICAgICA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GNhY2hlKQogICAgICAgICAgICBVSU5UX0NBQ0hFW3ZhbHVlXSA9IG9iajsKICAgICAgICAgIHJldHVybiBvYmo7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIHZhbHVlIHw9IDA7CiAgICAgICAgICBpZiAoY2FjaGUgPSAtMTI4IDw9IHZhbHVlICYmIHZhbHVlIDwgMTI4KSB7CiAgICAgICAgICAgIGNhY2hlZE9iaiA9IElOVF9DQUNIRVt2YWx1ZV07CiAgICAgICAgICAgIGlmIChjYWNoZWRPYmopCiAgICAgICAgICAgICAgcmV0dXJuIGNhY2hlZE9iajsKICAgICAgICAgIH0KICAgICAgICAgIG9iaiA9IGZyb21CaXRzKHZhbHVlLCB2YWx1ZSA8IDAgPyAtMSA6IDAsIGZhbHNlKTsKICAgICAgICAgIGlmIChjYWNoZSkKICAgICAgICAgICAgSU5UX0NBQ0hFW3ZhbHVlXSA9IG9iajsKICAgICAgICAgIHJldHVybiBvYmo7CiAgICAgICAgfQogICAgICB9CiAgICAgIExvbmc0LmZyb21JbnQgPSBmcm9tSW50OwogICAgICBmdW5jdGlvbiBmcm9tTnVtYmVyKHZhbHVlLCB1bnNpZ25lZCkgewogICAgICAgIGlmIChpc05hTih2YWx1ZSkpCiAgICAgICAgICByZXR1cm4gdW5zaWduZWQgPyBVWkVSTyA6IFpFUk87CiAgICAgICAgaWYgKHVuc2lnbmVkKSB7CiAgICAgICAgICBpZiAodmFsdWUgPCAwKQogICAgICAgICAgICByZXR1cm4gVVpFUk87CiAgICAgICAgICBpZiAodmFsdWUgPj0gVFdPX1BXUl82NF9EQkwpCiAgICAgICAgICAgIHJldHVybiBNQVhfVU5TSUdORURfVkFMVUU7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIGlmICh2YWx1ZSA8PSAtVFdPX1BXUl82M19EQkwpCiAgICAgICAgICAgIHJldHVybiBNSU5fVkFMVUU7CiAgICAgICAgICBpZiAodmFsdWUgKyAxID49IFRXT19QV1JfNjNfREJMKQogICAgICAgICAgICByZXR1cm4gTUFYX1ZBTFVFOwogICAgICAgIH0KICAgICAgICBpZiAodmFsdWUgPCAwKQogICAgICAgICAgcmV0dXJuIGZyb21OdW1iZXIoLXZhbHVlLCB1bnNpZ25lZCkubmVnKCk7CiAgICAgICAgcmV0dXJuIGZyb21CaXRzKHZhbHVlICUgVFdPX1BXUl8zMl9EQkwgfCAwLCB2YWx1ZSAvIFRXT19QV1JfMzJfREJMIHwgMCwgdW5zaWduZWQpOwogICAgICB9CiAgICAgIExvbmc0LmZyb21OdW1iZXIgPSBmcm9tTnVtYmVyOwogICAgICBmdW5jdGlvbiBmcm9tQml0cyhsb3dCaXRzLCBoaWdoQml0cywgdW5zaWduZWQpIHsKICAgICAgICByZXR1cm4gbmV3IExvbmc0KGxvd0JpdHMsIGhpZ2hCaXRzLCB1bnNpZ25lZCk7CiAgICAgIH0KICAgICAgTG9uZzQuZnJvbUJpdHMgPSBmcm9tQml0czsKICAgICAgdmFyIHBvd19kYmwgPSBNYXRoLnBvdzsKICAgICAgZnVuY3Rpb24gZnJvbVN0cmluZyhzdHIsIHVuc2lnbmVkLCByYWRpeCkgewogICAgICAgIGlmIChzdHIubGVuZ3RoID09PSAwKQogICAgICAgICAgdGhyb3cgRXJyb3IoImVtcHR5IHN0cmluZyIpOwogICAgICAgIGlmIChzdHIgPT09ICJOYU4iIHx8IHN0ciA9PT0gIkluZmluaXR5IiB8fCBzdHIgPT09ICIrSW5maW5pdHkiIHx8IHN0ciA9PT0gIi1JbmZpbml0eSIpCiAgICAgICAgICByZXR1cm4gWkVSTzsKICAgICAgICBpZiAodHlwZW9mIHVuc2lnbmVkID09PSAibnVtYmVyIikgewogICAgICAgICAgcmFkaXggPSB1bnNpZ25lZCwgdW5zaWduZWQgPSBmYWxzZTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgdW5zaWduZWQgPSAhIXVuc2lnbmVkOwogICAgICAgIH0KICAgICAgICByYWRpeCA9IHJhZGl4IHx8IDEwOwogICAgICAgIGlmIChyYWRpeCA8IDIgfHwgMzYgPCByYWRpeCkKICAgICAgICAgIHRocm93IFJhbmdlRXJyb3IoInJhZGl4Iik7CiAgICAgICAgdmFyIHA7CiAgICAgICAgaWYgKChwID0gc3RyLmluZGV4T2YoIi0iKSkgPiAwKQogICAgICAgICAgdGhyb3cgRXJyb3IoImludGVyaW9yIGh5cGhlbiIpOwogICAgICAgIGVsc2UgaWYgKHAgPT09IDApIHsKICAgICAgICAgIHJldHVybiBmcm9tU3RyaW5nKHN0ci5zdWJzdHJpbmcoMSksIHVuc2lnbmVkLCByYWRpeCkubmVnKCk7CiAgICAgICAgfQogICAgICAgIHZhciByYWRpeFRvUG93ZXIgPSBmcm9tTnVtYmVyKHBvd19kYmwocmFkaXgsIDgpKTsKICAgICAgICB2YXIgcmVzdWx0ID0gWkVSTzsKICAgICAgICBmb3IgKHZhciBpID0gMDsgaSA8IHN0ci5sZW5ndGg7IGkgKz0gOCkgewogICAgICAgICAgdmFyIHNpemUgPSBNYXRoLm1pbig4LCBzdHIubGVuZ3RoIC0gaSksIHZhbHVlID0gcGFyc2VJbnQoc3RyLnN1YnN0cmluZyhpLCBpICsgc2l6ZSksIHJhZGl4KTsKICAgICAgICAgIGlmIChzaXplIDwgOCkgewogICAgICAgICAgICB2YXIgcG93ZXIgPSBmcm9tTnVtYmVyKHBvd19kYmwocmFkaXgsIHNpemUpKTsKICAgICAgICAgICAgcmVzdWx0ID0gcmVzdWx0Lm11bChwb3dlcikuYWRkKGZyb21OdW1iZXIodmFsdWUpKTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHJlc3VsdCA9IHJlc3VsdC5tdWwocmFkaXhUb1Bvd2VyKTsKICAgICAgICAgICAgcmVzdWx0ID0gcmVzdWx0LmFkZChmcm9tTnVtYmVyKHZhbHVlKSk7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJlc3VsdC51bnNpZ25lZCA9IHVuc2lnbmVkOwogICAgICAgIHJldHVybiByZ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TsKICAgICAgICAgIHJlbSA9IHJlbURpdjsKICAgICAgICAgIGlmIChyZW0uaXNaZXJvKCkpCiAgICAgICAgICAgIHJldHVybiBkaWdpdHMgKyByZXN1bHQ7CiAgICAgICAgICBlbHNlIHsKICAgICAgICAgICAgd2hpbGUgKGRpZ2l0cy5sZW5ndGggPCA2KQogICAgICAgICAgICAgIGRpZ2l0cyA9ICIwIiArIGRpZ2l0czsKICAgICAgICAgICAgcmVzdWx0ID0gIiIgKyBkaWdpdHMgKyByZXN1bHQ7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLmdldEhpZ2hCaXRzID0gZnVuY3Rpb24gZ2V0SGlnaEJpdHMoKSB7CiAgICAgICAgcmV0dXJuIHRoaXMuaGlnaDsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS5nZXRIaWdoQml0c1Vuc2lnbmVkID0gZnVuY3Rpb24gZ2V0SGlnaEJpdHNVbnNpZ25lZCgpIHsKICAgICAgICByZXR1cm4gdGhpcy5oaWdoID4+PiAwOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLmdldExvd0JpdHMgPSBmdW5jdGlvbiBnZXRMb3dCaXRzKCkgewogICAgICAgIHJldHVybiB0aGlzLmxvdzsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS5nZXRMb3dCaXRzVW5zaWduZWQgPSBmdW5jdGlvbiBnZXRMb3dCaXRzVW5zaWduZWQoKSB7CiAgICAgICAgcmV0dXJuIHRoaXMubG93ID4+PiAwOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLmdldE51bUJpdHNBYnMgPSBmdW5jdGlvbiBnZXROdW1CaXRzQWJzKCkgewogICAgICAgIGlmICh0aGlzLmlzTmVnYXRpdmUoKSkKICAgICAgICAgIHJldHVybiB0aGlzLmVxKE1JTl9WQUxVRSkgPyA2NCA6IHRoaXMubmVnKCkuZ2V0TnVtQml0c0FicygpOwogICAgICAgIHZhci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hlcikgewogICAgICAgIGlmICghaXNMb25nKG90aGVyKSkKICAgICAgICAgIG90aGVyID0gZnJvbVZhbHVlKG90aGVyKTsKICAgICAgICBpZiAodGhpcy51bnNpZ25lZCAhPT0gb3RoZXIudW5zaWduZWQgJiYgdGhpcy5oaWdoID4+PiAzMSA9PT0gMSAmJiBvdGhlci5oaWdoID4+PiAzMSA9PT0gMSkKICAgICAgICAgIHJldHVybiBmYWxzZTsKICAgICAgICByZXR1cm4gdGhpcy5oaWdoID09PSBvdGhlci5oaWdoICYmIHRoaXMubG93ID09PSBvdGhlci5sb3c7CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUuZXEgPSBMb25nUHJvdG90eXBlLmVxdWFsczsKICAgICAgTG9uZ1Byb3RvdHlwZS5ub3RFcXVhbHMgPSBmdW5jdGlvbiBub3RFcXVhbHMob3RoZXIpIHsKICAgICAgICByZXR1cm4gIXRoaXMuZXEob3RoZXIpOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLm5lcSA9IExvbmdQcm90b3R5cGUubm90RXF1YWxzOwogICAgICBMb25nUHJvdG90eXBlLm5lID0gTG9uZ1Byb3RvdHlwZS5ub3RFcXVhbHM7CiAgICAgIExvbmdQcm90b3R5cGUubGVzc1RoYW4gPSBmdW5jdGlvbiBsZXNzVGhhbihvdGhlcikgewogICAgICAgIHJldHVybiB0aGlzLmNvbXAob3RoZXIpIDwgMDsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS5sdCA9IExvbmdQcm90b3R5cGUubGVzc1RoYW47CiAgICAgIExvbmdQcm90b3R5cGUubGVzc1RoYW5PckVxdWFsID0gZnVuY3Rpb24gbGVzc1RoYW5PckVxdWFsKG90aGVyKSB7CiAgICAgICAgcmV0dXJuIHRoaXMuY29tcChvdGhlcikgPD0gMDsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS5sdGUgPSBMb25nUHJvdG90eXBlLmxlc3NUaGFuT3JFcXVhbDsKICAgICAgT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AgICAgdmFyIGIwMCA9IGFkZGVuZC5sb3cgJiA2NTUzNTsKICAgICAgICB2YXIgYzQ4ID0gMCwgYzMyID0gMCwgYzE2ID0gMCwgYzAwID0gMDsKICAgICAgICBjMDAgKz0gYTAwICsgYjAwOwogICAgICAgIGMxNiArPSBjMDAgPj4+IDE2OwogICAgICAgIGMwMCAmPSA2NTUzNTsKICAgICAgICBjMTYgKz0gYTE2ICsgYjE2OwogICAgICAgIGMzMiArPSBjMTYgPj4+IDE2OwogICAgICAgIGMxNiAmPSA2NTUzNTsKICAgICAgICBjMzIgKz0gYTMyICsgYjMyOwogICAgICAgIGM0OCArPSBjMzIgPj4+IDE2OwogICAgICAgIGMzMiAmPSA2NTUzNTsKICAgICAgICBjNDggKz0gYTQ4ICsgYjQ4OwogICAgICAgIGM0OCAmPSA2NTUzNTsKICAgICAgICByZXR1cm4gZnJvbUJpdHMoYzE2IDw8IDE2IHwgYzAwLCBjNDggPDwgMTYgfCBjMzIsIHRoaXMudW5zaWduZWQpOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLnN1YnRyYWN0ID0gZnVuY3Rpb24gc3VidHJhY3Qoc3VidHJhaGVuZCkgewogICAgICAgIGlmICghaXNMb25nKHN1YnRyYWhlbmQpKQogICAgICAgICAgc3VidHJhaGVuZCA9IGZyb21WYWx1ZShzdWJ0cmFoZW5kKTsKICAgICAgICByZXR1cm4gdGhpcy5hZGQoc3VidHJhaGVuZC5uZWcoKSk7CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUuc3ViID0gTG9uZ1Byb3RvdHlwZS5zdWJ0cmFjdDsKICAgICAgTG9uZ1Byb3RvdHlwZS5tdWx0aXBseSA9IGZ1bmN0aW9uIG11bHRpcGx5KG11bHRpcGxpZXIpIHsKICAgICAgICBpZiAodGhpcy5pc1plcm8oKSkKICAgICAgICAgIHJldHVybiBaRVJPOwogICAgICAgIGlmICghaXNMb25nKG11bHRpcGxpZXIpKQogICAgICAgICAgbXVsdGlwbGllciA9IGZyb21WYWx1ZShtdWx0aXBsaWVyKTsKICAgICAgICBpZiAod2FzbSkgewogICAgICAgICAgdmFyIGxvdyA9IHdhc20ubXVsKHRoaXMubG93LCB0aGlzLmhpZ2gsIG11bHRpcGxpZXIubG93LCBtdWx0aXBsaWVyLmhpZ2gpOwogICAgICAgICAgcmV0dXJuIGZyb21CaXRzKGxvdywgd2FzbS5nZXRfaGlnaCgpLCB0aGlzLnVuc2lnbmVkKTsKICAgICAgICB9CiAgICAgICAgaWYgKG11bHRpcGxpZXIuaXNaZXJvKCkpCiAgICAgICAgICByZXR1cm4gWkVSTzsKICAgICAgICBpZiAodGhpcy5lcShNSU5fVkFMVUUpKQogICAgICAgICAgcmV0dXJuIG11bHRpcGxpZXIuaXNPZGQoKSA/IE1JTl9WQUxVRSA6IFpFUk87CiAgICAgICAgaWYgKG11bHRpcGxpZXIuZXEoTUlOX1ZBTFVFKSkKICAgICAgICAgIHJldHVybiB0aGlzLmlzT2RkKCkgPyBNSU5fVkFMVUUgOiBaRVJPOwogICAgICAgIGlmICh0aGlzLmlzTmVnYXRpdmUoKSkgewogICAgICAgICAgaWYgKG11bHRpcGxpZXIuaXNOZWdhdGl2ZSgpKQogICAgICAgICAgICByZXR1cm4gdGhpcy5uZWcoKS5tdWwobXVsdGlwbGllci5uZWcoKSk7CiAgICAgICAgICBlbHNlCiAgICAgICAgICAgIHJldHVybiB0aGlzLm5lZygpLm11bChtdWx0aXBsaWVyKS5uZWcoKTsKICAgICAgICB9IGVsc2UgaWYgKG11bHRpcGxpZXIuaXNOZWdhdGl2ZSgpKQogICAgICAgICAgcmV0dXJuIHRoaXMubXVsKG11bHRpcGxpZXIubmVnKCkpLm5lZygpOwogICAgICAgIGlmICh0aGlzLmx0KFRXT19QV1JfMjQpICYmIG11bHRpcGxpZXIubHQoVFdPX1BXUl8yNCkpCiAgICAgICAgICByZXR1cm4gZnJvbU51bWJlcih0aGlzLnRvTnVtYmVyKCkgKiBtdWx0aXBsaWVyL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DogWkVSTzsKICAgICAgICB2YXIgYXBwcm94LCByZW0sIHJlczsKICAgICAgICBpZiAoIXRoaXMudW5zaWduZWQpIHsKICAgICAgICAgIGlmICh0aGlzLmVxKE1JTl9WQUxVRSkpIHsKICAgICAgICAgICAgaWYgKGRpdmlzb3IuZXEoT05FKSB8fCBkaXZpc29yLmVxKE5FR19PTkUpKQogICAgICAgICAgICAgIHJldHVybiBNSU5fVkFMVUU7CiAgICAgICAgICAgIGVsc2UgaWYgKGRpdmlzb3IuZXEoTUlOX1ZBTFVFKSkKICAgICAgICAgICAgICByZXR1cm4gT05FOwogICAgICAgICAgICBlbHNlIHsKICAgICAgICAgICAgICB2YXIgaGFsZlRoaXMgPSB0aGlzLnNocigxKTsKICAgICAgICAgICAgICBhcHByb3ggPSBoYWxmVGhpcy5kaXYoZGl2aXNvcikuc2hsKDEpOwogICAgICAgICAgICAgIGlmIChhcHByb3guZXEoWkVSTykpIHsKICAgICAgICAgICAgICAgIHJldHVybiBkaXZpc29yLmlzTmVnYXRpdmUoKSA/IE9ORSA6IE5FR19PTkU7CiAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIHJlbSA9IHRoaXMuc3ViKGRpdmlzb3IubXVsKGFwcHJveCkpOwogICAgICAgICAgICAgICAgcmVzID0gYXBwcm94LmFkZChyZW0uZGl2KGRpdmlzb3IpKTsKICAgICAgICAgICAgICAgIHJldHVybiByZXM7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgaWYgKGRpdmlzb3IuZXEoTUlOX1ZBTFVFKSkKICAgICAgICAgICAgcmV0dXJuIHRoaXMudW5zaWduZWQgPyBVWkVSTyA6IFpFUk87CiAgICAgICAgICBpZiAodGhpcy5pc05lZ2F0aXZlKCkpIHsKICAgICAgICAgICAgaWYgKGRpdmlzb3IuaXNOZWdhdGl2ZSgpKQogICAgICAgICAgICAgIHJldHVybiB0aGlzLm5lZygpLmRpdihkaXZpc29yLm5lZygpKTsKICAgICAgICAgICAgcmV0dXJuIHRoaXMubmVnKCkuZGl2KGRpdmlzb3IpLm5lZygpOwogICAgICAgICAgfSBlbHNlIGlmIChkaXZpc29yLmlzTmVnYXRpdmUoKSkKICAgICAgICAgICAgcmV0dXJuIHRoaXMuZGl2KGRpdmlzb3IubmVnKCkpLm5lZygpOwogICAgICAgICAgcmVzID0gWkVSTzsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgaWYgKCFkaXZpc29yLnVuc2lnbmVkKQogICAgICAgICAgICBkaXZpc29yID0gZGl2aXNvci50b1Vuc2lnbmVkKCk7CiAgICAgICAgICBpZiAoZGl2aXNvci5ndCh0aGlzKSkKICAgICAgICAgICAgcmV0dXJuIFVaRVJPOwogICAgICAgICAgaWYgKGRpdmlzb3IuZ3QodGhpcy5zaHJ1KDEpKSkKICAgICAgICAgICAgcmV0dXJuIFVPTkU7CiAgICAgICAgICByZXMgPSBVWkVSTzsKICAgICAgICB9CiAgICAgICAgcmVtID0gdGhpczsKICAgICAgICB3aGlsZSAocmVtLmd0ZShkaXZpc29yKSkgewogICAgICAgICAgYXBwcm94ID0gTWF0aC5tYXgoMSwgTWF0aC5mbG9vcihyZW0udG9OdW1iZXIoKSAvIGRpdmlzb3IudG9OdW1iZXIoKSkpOwogICAgICAgICAgdmFyIGxvZzIgPSBNYXRoLmNlaWwoTWF0aC5sb2coYXBwcm94KSAvIE1hdGguTE4yKSwgZGVsdGEgPSBsb2cyIDw9IDQ4ID8gMSA6IHBvd19kYmwoMiwgbG9nMiAtIDQ4KSwgYXBwcm94UmVzID0gZnJvbU51bWJlcihhcHByb3gpLCBhcHByb3hSZW0gPSBhcHByb3hSZXMubXVsKGRpdmlzb3IpOwogICAgICAgICAgd2hpbGUgKGFwcHJveFJlbS5pc05lZ2F0aXZlKCkgfHwgYXBwcm94UmVtLmd0KHJlbSkpIHsKICAgICAgICAgICAgYXBwcm94IC09IGRlbHRhOwogICAgICAgICAgICBhcHByb3hSZXMgPSBmcm9tTnVtYmVyKGFwcHJveCwgdGhpcy51bnNpZ25lZCk7CiAgICAgICAgICAgIGFwcHJveFJlbSA9IGFwcHJveFJlcy5tdWwoZGl2aXNvcik7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoYXBwcm94UmVzLmlzWmVybygpKQogICAgICAgICAgICBhcHByb3hSZXMgPSBPTkU7CiAgICAgICAgICByZXMgPSByZXMuYWRkKGFwcHJveFJlcyk7CiAgICAgICAgICByZW0gPSByZW0uc3ViKGFwcHJveFJlbSk7CiAgICAgICAgfQogICAgICAgIHJldHVybiByZXM7CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUuZGl2ID0gTG9uZ1Byb3RvdHlwZS5kaXZpZGU7CiAgICAgIExvbmdQcm90b3R5cGUubW9kdWxvID0gZnVuY3Rpb24gbW9kdWxvKGRpdmlzb3IpIHsKICAgICAgICBpZiAoIWlzTG9uZyhkaXZpc29yKSkKICAgICAgICAgIGRpdmlzb3IgPSBmcm9tVmFsdWUoZGl2aXNvcik7CiAgICAgICAgaWYgKHdhc20pIHsKICAgICAgICAgIHZhciBsb3cgPSAodGhpcy51bnNpZ25lZCA/IHdhc20ucmVtX3UgOiB3YXNtLnJlbV9zKSh0aGlzLmxvdywgdGhpcy5oaWdoLCBkaXZpc29yLmxvdywgZGl2aXNvci5oaWdoKTsKICAgICAgICAgIHJldHVybiBmcm9tQml0cyhsb3csIHdhc20uZ2V0X2hpZ2goKSwgdGhpcy51bnNpZ25lZCk7CiAgICAgICAgfQogICAgICAgIHJldHVybiB0aGlzLnN1Yih0aGlzLmRpdihkaXZpc29yKS5tdWwoZGl2aXNvcikpOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLm1vZCA9IExvbmdQcm90b3R5cGUubW9kdWxvOwogICAgICBMb25nUHJvdG90eXBlLnJlbSA9IExvbmdQcm90b3R5cGUubW9kdWxvOwogICAgICBMb25nUHJvdG90eXBlLm5vdCA9IGZ1bmN0aW9uIG5vdCgpIHsKICAgIC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2hpZnRSaWdodFVuc2lnbmVkID0gZnVuY3Rpb24gc2hpZnRSaWdodFVuc2lnbmVkKG51bUJpdHMpIHsKICAgICAgICBpZiAoaXNMb25nKG51bUJpdHMpKQogICAgICAgICAgbnVtQml0cyA9IG51bUJpdHMudG9JbnQoKTsKICAgICAgICBudW1CaXRzICY9IDYzOwogICAgICAgIGlmIChudW1CaXRzID09PSAwKQogICAgICAgICAgcmV0dXJuIHRoaXM7CiAgICAgICAgZWxzZSB7CiAgICAgICAgICB2YXIgaGlnaCA9IHRoaXMuaGlnaDsKICAgICAgICAgIGlmIChudW1CaXRzIDwgMzIpIHsKICAgICAgICAgICAgdmFyIGxvdyA9IHRoaXMubG93OwogICAgICAgICAgICByZXR1cm4gZnJvbUJpdHMobG93ID4+PiBudW1CaXRzIHwgaGlnaCA8PCAzMiAtIG51bUJpdHMsIGhpZ2ggPj4+IG51bUJpdHMsIHRoaXMudW5zaWduZWQpOwogICAgICAgICAgfSBlbHNlIGlmIChudW1CaXRzID09PSAzMikKICAgICAgICAgICAgcmV0dXJuIGZyb21CaXRzKGhpZ2gsIDAsIHRoaXMudW5zaWduZWQpOwogICAgICAgICAgZWxzZQogICAgICAgICAgICByZXR1cm4gZnJvbUJpdHMoaGlnaCA+Pj4gbnVtQml0cyAtIDMyLCAwLCB0aGlzLnVuc2lnbmVkKTsKICAgICAgICB9CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUuc2hydSA9IExvbmdQcm90b3R5cGUuc2hpZnRSaWdodFVuc2lnbmVkOwogICAgICBMb25nUHJvdG90eXBlLnNocl91ID0gTG9uZ1Byb3RvdHlwZS5zaGlmdFJpZ2h0VW5zaWduZWQ7CiAgICAgIExvbmdQcm90b3R5cGUudG9TaWduZWQgPSBmdW5jdGlvbiB0b1NpZ25lZCgpIHsKICAgICAgICBpZiAoIXRoaXMudW5zaWduZWQpCiAgICAgICAgICByZXR1cm4gdGhpczsKICAgICAgICByZXR1cm4gZnJvbUJpdHModGhpcy5sb3csIHRoaXMuaGlnaCwgZmFsc2UpOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLnRvVW5zaWduZWQgPSBmdW5jdGlvbiB0b1Vuc2lnbmVkKCkgewogICAgICAgIGlmICh0aGlzLnVuc2lnbmVkKQogICAgICAgICAgcmV0dXJuIHRoaXM7CiAgICAgICAgcmV0dXJuIGZyb21CaXRzKHRoaXMubG93LCB0aGlzLmhpZ2gsIHRydWUpOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLnRvQnl0ZXMgPSBmdW5jdGlvbiB0b0J5dGVzKGxlKSB7CiAgICAgICAgcmV0dXJuIGxlID8gdGhpcy50b0J5dGVzTEUoKSA6IHRoaXMudG9CeXRlc0JFKCk7CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUudG9CeXRlc0xFID0gZnVuY3Rpb24gdG9CeXRlc0xFKCkgewogICAgICAgIHZhciBoaSA9IHRoaXMuaGlnaCwgbG8gPSB0aGlzLmxvdzsKICAgICAgICByZXR1cm4gWwogICAgICAgICAgbG8gJiAyNTUsCiAgICAgICAgICBsbyA+Pj4gOCAmIDI1NSwKICAgICAgICAgIGxvID4+PiAxNiAmIDI1NSwKICAgICAgICAgIGxvID4+PiAyNCwKICAgICAgICAgIGhpICYgMjU1LAogICAgICAgICAgaGkgPj4+IDggJiAyNTUsCiAgICAgICAgICBoaSA+Pj4gMTYgJiAyNTUsCiAgICAgICAgICBoaSA+Pj4gMjQKICAgICAgICBdOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLnRvQnl0ZXNCRSA9IGZ1bmN0aW9uIHRvQnl0ZXNCRSgpIHsKICAgICAgICB2YXIgaGkgPSB0aGlzLmhpZ2gsIGxvID0gdGhpcy5sb3c7CiAgICAgICAgcmV0dXJuIFsKICAgICAgICAgIGhpID4+PiAyNCwKICAgICAgICAgIGhpID4+PiAxNiAmIDI1NSwKICAgICAgICAgIGhpID4+PiA4ICYgMjU1LAogICAgICAgICAgaGkgJiAyNTU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XJyb3IobWVzc2FnZS5tZXNzYWdlKSwgewogICAgICAgICAgICBuYW1lOiBtZXNzYWdlLm5hbWUsCiAgICAgICAgICAgIHN0YWNrOiBtZXNzYWdlLnN0YWNrCiAgICAgICAgICB9KTsKICAgICAgICB9LAogICAgICAgIHNlcmlhbGl6ZShlcnJvcikgewogICAgICAgICAgcmV0dXJuIHsKICAgICAgICAgICAgX19lcnJvcl9tYXJrZXI6ICIkJGVycm9yIiwKICAgICAgICAgICAgbWVzc2FnZTogZXJyb3IubWVzc2FnZSwKICAgICAgICAgICAgbmFtZTogZXJyb3IubmFtZSwKICAgICAgICAgICAgc3RhY2s6IGVycm9yLnN0YWNrCiAgICAgICAgICB9OwogICAgICAgIH0KICAgICAgfTsKICAgICAgdmFyIGlzU2VyaWFsaXplZEVycm9yID0gKHRoaW5nKSA9PiB0aGluZyAmJiB0eXBlb2YgdGhpbmcgPT09ICJvYmplY3QiICYmICJfX2Vycm9yX21hcmtlciIgaW4gdGhpbmcgJiYgdGhpbmcuX19lcnJvcl9tYXJrZXIgPT09ICIkJGVycm9yIjsKICAgICAgZXhwb3J0czIuRGVmYXVsdFNlcmlhbGl6ZXIgPSB7CiAgICAgICAgZGVzZXJpYWxpemUobWVzc2FnZSkgewogICAgICAgICAgaWYgKGlzU2VyaWFsaXplZEVycm9yKG1lc3NhZ2UpKSB7CiAgICAgICAgICAgIHJldHVybiBEZWZhdWx0RXJyb3JTZXJpYWxpemVyLmRlc2VyaWFsaXplKG1lc3NhZ2UpOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcmV0dXJuIG1lc3NhZ2U7CiAgICAgICAgICB9CiAgICAgICAgfSwKICAgICAgICBzZXJpYWxpemUoaW5wdXQpIHsKICAgICAgICAgIGlmIChpbnB1dCBpbnN0YW5jZW9mIEVycm9yKSB7CiAgICAgICAgICAgIHJldHVybiBEZWZhdWx0RXJyb3JTZXJpYWxpemVyLnNlcmlhbGl6ZShpbnB1dCk7CiAgICAgICAgICB9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IHsKICAgICAgICAgIHJldHVybiB2YWx1ZSBpbnN0YW5jZW9mIFAgPyB2YWx1ZSA6IG5ldyBQKGZ1bmN0aW9uKHJlc29sdmUpIHsKICAgICAgICAgICAgcmVzb2x2ZSh2YWx1ZSk7CiAgICAgICAgICB9KTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIG5ldyAoUCB8fCAoUCA9IFByb21pc2UpKShmdW5jdGlvbihyZXNvbHZlLCByZWplY3QpIHsKICAgICAgICAgIGZ1bmN0aW9uIGZ1bGZpbGxlZCh2YWx1ZSkgewogICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgIHN0ZXAoZ2VuZXJhdG9yLm5leHQodmFsdWUpKTsKICAgICAgICAgICAgfSBjYXRjaCAoZSkgewogICAgICAgICAgICAgIHJlamVjdChlKTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgZnVuY3Rpb24gcmVqZWN0ZWQodmFsdWUpIHsKICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICBzdGVwKGdlbmVyYXRvclsidGhyb3ciXSh2YWx1ZSkpOwogICAgICAgICAgICB9IGNhdGNoIChlKSB7CiAgICAgICAgICAgICAgcmVqZWN0KGUpOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBmdW5jdGlvbiBzdGVwKHJlc3VsdCkgewogICAgICAgICAgICByZXN1bHQuZG9uZSA/IHJlc29sdmUocmVzdWx0LnZhbHVlKSA6IGFkb3B0KHJlc3VsdC52YWx1ZSkudGhlbihmdWxmaWxsZWQsIHJlamVjdGVkKTsKICAgICAgICAgIH0KICAgICAgICAgIHN0ZXAoKGdlbmVyYXRvciA9IGdlbmVyYXRvci5hcHBseSh0aGlzQXJnLCBfYXJndW1lbnRzIHx8IFtdKSkubmV4dCgpKTsKICAgICAgICB9KTsKICAgICAgfTsKICAgICAgdmFyIF9faW1wb3J0RGVmYXVsdCA9IGV4cG9ydHMyICYmIGV4cG9ydHMyLl9faW1wb3J0RGVmY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GEpKSB7CiAgICAgICAgICAgIGNvbnN0IGpvYlVJRCA9IG1lc3NhZ2VEYXRhLnVpZDsKICAgICAgICAgICAgY29uc3Qgc3Vic2NyaXB0aW9uID0gYWN0aXZlU3Vic2NyaXB0aW9ucy5nZXQoam9iVUlEKTsKICAgICAgICAgICAgaWYgKHN1YnNjcmlwdGlvbikgewogICAgICAgICAgICAgIHN1YnNjcmlwdGlvbi51bnN1YnNjcmliZSgpOwogICAgICAgICAgICAgIGFjdGl2ZVN1YnNjcmlwdGlvbnMuZGVsZXRlKGpvYlVJRCk7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9KTsKICAgICAgfQogICAgICBleHBvcnRzMi5leHBvc2UgPSBleHBvc2UyOwogICAgICBpZiAodHlwZW9mIHNlbGYgIT09ICJ1bmRlZmluZWQiICYmIHR5cGVvZiBzZWxmLmFkZEV2ZW50TGlzdGVuZXIgPT09ICJmdW5jdGlvbiIgJiYgaW1wbGVtZW50YXRpb25fMS5kZWZhdWx0LmlzV29ya2VyUnVudGltZSgpKSB7CiAgICAgICAgc2VsZi5hZGRFdmVudExpc3RlbmVyKCJlcnJvciIsIChldmVudCkgPT4gewogICAgICAgICAgc2V0VGltZW91dCgoKSA9PiBwb3N0VW5jYXVnaHRFcnJvck1lc3NhZ2UoZXZlbnQuZXJyb3IgfHwgZXZlbnQpLCAyNTApOwogICAgICAgIH0pOwogICAgICAgIHNlbGYuYWRkRXZlbnRMaXN0ZW5lcigidW5oYW5kbGVkcmVqZWN0aW9uIiwgKGV2ZW50KSA9PiB7CiAgICAgICAgICBjb25zdCBlcnJvciA9IGV2ZW50LnJlYXNvbjsKICAgICAgICAgIGlmIChlcnJvciAmJiB0eXBlb2YgZXJyb3IubWVzc2FnZSA9PT0gInN0cmluZyIpIHsKICAgICAgICAgICAgc2V0VGltZW91dCgoKSA9PiBwb3N0VW5jYXVnaHRFcnJvck1lc3NhZ2UoZXJyb3IpLCAyNTApOwogICAgICAgICAgfQogICAg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0dGVtcHQgdG8gd29yayBhcm91bmQgY2hyb21lIENPUlMgaGVhZGVyIGNhY2hpbmcgYnVnYCk7CiAgICAgICAgICByZXNwb25zZSA9IGF3YWl0IHRoaXMuZmV0Y2hJbXBsZW1lbnRhdGlvbihpbnB1dCwgewogICAgICAgICAgICAuLi5pbml0MiwKICAgICAgICAgICAgY2FjaGU6ICJyZWxvYWQiCiAgICAgICAgICB9KTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgdGhyb3cgZTsKICAgICAgICB9CiAgICAgIH0KICAgICAgcmV0dXJuIHJlc3BvbnNlOwogICAgfQogICAgYXN5bmMgcmVhZChidWZmZXIsIG9mZnNldCA9IDAsIGxlbmd0aCwgcG9zaXRpb24gPSAwLCBvcHRzID0ge30pIHsKICAgICAgY29uc3QgeyBoZWFkZXJzID0ge30sIHNpZ25hbCwgb3ZlcnJpZGVzID0ge30gfSA9IG9wdHM7CiAgICAgIGlmIChsZW5ndGggPCBJbmZpbml0eSkgewogICAgICAgIGhlYWRlcnMucmFuZ2UgPSBgYnl0ZXM9JHtwb3NpdGlvbn0tJHtwb3NpdGlvbiArIGxlbmd0aH1gOwogICAgICB9IGVsc2UgaWYgKGxlbmd0aCA9PT0gSW5maW5pdHkgJiYgcG9zaXRpb24gIT09IDApIHsKICAgICAgICBoZWFkZXJzLnJhbmdlID0gYGJ5dGVzPSR7cG9zaXRpb259LWA7CiAgICAgIH0KICAgICAgY29uc3QgYXJncyA9IHsKICAgICAgICAuLi50aGlzLmJhc2VPdmVycmlkZXMsCiAgICAgICAgLi4ub3ZlcnJpZGVzLAogICAgICAgIGhlYWRlcnM6IHsKICAgICAgICAgIC4uLmhlYWRlcnMsCiAgICAgICAgICAuLi5vdmVycmlkZXMuaGVhZGVycywKICAgICAgICAgIC4uLnRoaXMuYmFzZU92ZXJyaWRlcy5oZWFkZXJzCiAgICAgICAgfSwKICAgICAgICBtZXRob2Q6ICJHRVQiLAogICAgICAgIHJlZGlyZWN0OiAiZm9sbG93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CIke3RoaXMudXJsfSBmZXRjaCByZXR1cm5lZCBzdGF0dXMgMjAwLCBleHBlY3RlZCAyMDYiKTsKICAgICAgfQogICAgICB0aHJvdyBuZXcgRXJyb3IoYEhUVFAgJHtyZXNwb25zZS5zdGF0dXN9IGZldGNoaW5nICR7dGhpcy51cmx9YCk7CiAgICB9CiAgICBhc3luYyByZWFkRmlsZShvcHRpb25zID0ge30pIHsKICAgICAgbGV0IGVuY29kaW5nOwogICAgICBsZXQgb3B0czsKICAgICAgaWYgKHR5cGVvZiBvcHRpb25zID09PSAic3RyaW5nIikgewogICAgICAgIGVuY29kaW5nID0gb3B0aW9uczsKICAgICAgICBvcHRzID0ge307CiAgICAgIH0gZWxzZSB7CiAgICAgICAgZW5jb2RpbmcgPSBvcHRpb25zLmVuY29kaW5nOwogICAgICAgIG9wdHMgPSBvcHRpb25zOwogICAgICAgIGRlbGV0ZSBvcHRzLmVuY29kaW5nOwogICAgICB9CiAgICAgIGNvbnN0IHsgaGVhZGVycyA9IHt9LCBzaWduYWwsIG92ZXJyaWRlcyA9IHt9IH0gPSBvcHRzOwogICAgICBjb25zdCBhcmdzID0gewogICAgICAgIGhlYWRlcnMsCiAgICAgICAgbWV0aG9kOiAiR0VUIiwKICAgICAgICByZWRpcmVjdDogImZvbGxvdyIsCiAgICAgICAgbW9kZTogImNvcnMiLAogICAgICAgIHNpZ25hbCwKICAgICAgICAuLi50aGlzLmJhc2VPdmVycmlkZXMsCiAgICAgICAgLi4ub3ZlcnJpZGVzCiAgICAgIH07CiAgICAgIGNvbnN0IHJlc3BvbnNlID0gYXdhaXQgdGhpcy5mZXRjaCh0aGlzLnVybCwgYXJncyk7CiAgICAgIGlmICghcmVzcG9uc2UpIHsKICAgICAgICB0aHJvdyBuZXcgRXJyb3IoImdlbmVyaWMtZmlsZWhhbmRsZSBmYWlsZWQgdG8gZmV0Y2giKTsKICAgICAgfQogICAgICBpZiAocmVzcG9uc2Uuc3RhdHVzICE9PSAyMDApIHsKICAgICA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IEVycm9yKCJwcm9ibGVtIGRlY29tcHJlc3NpbmcgYmxvY2s6IGluY29ycmVjdCBnemlwIGhlYWRlciBjaGVjayIpOwogICAgICB9CiAgICAgIHRocm93IGU7CiAgICB9CiAgfQogIGFzeW5jIGZ1bmN0aW9uIHVuemlwQ2h1bmtTbGljZShpbnB1dERhdGEsIGNodW5rKSB7CiAgICB0cnkgewogICAgICBsZXQgc3RybTsKICAgICAgY29uc3QgeyBtaW52LCBtYXh2IH0gPSBjaHVuazsKICAgICAgbGV0IGNwb3MgPSBtaW52LmJsb2NrUG9zaXRpb247CiAgICAgIGxldCBkcG9zID0gbWludi5kYXRhUG9zaXRpb247CiAgICAgIGNvbnN0IGNodW5rcyA9IFtdOwogICAgICBjb25zdCBjcG9zaXRpb25zID0gW107CiAgICAgIGNvbnN0IGRwb3NpdGlvbnMgPSBbXTsKICAgICAgbGV0IHRvdGFsU2l6ZSA9IDA7CiAgICAgIGxldCBpID0gMDsKICAgICAgZG8gewogICAgICAgIGNvbnN0IHJlbWFpbmluZ0lucHV0ID0gaW5wdXREYXRhLnN1YmFycmF5KGNwb3MgLSBtaW52LmJsb2NrUG9zaXRpb24pOwogICAgICAgIGNvbnN0IGluZmxhdG9yID0gbmV3IGltcG9ydF9wYWtvLkluZmxhdGUoKTsKICAgICAgICAoeyBzdHJtIH0gPSBpbmZsYXRvcik7CiAgICAgICAgaW5mbGF0b3IucHVzaChyZW1haW5pbmdJbnB1dCwgaW1wb3J0X3Bha28uWl9TWU5DX0ZMVVNIKTsKICAgICAgICBpZiAoaW5mbGF0b3IuZXJyKSB7CiAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IoaW5mbGF0b3IubXNnKTsKICAgICAgICB9CiAgICAgICAgY29uc3QgYnVmZmVyMiA9IGluZmxhdG9yLnJlc3VsdDsKICAgICAgICBjaHVua3MucHVzaChidWZmZXIyKTsKICAgICAgICBsZXQgbGVuID0gYnVmZmVyMi5sZW5ndGg7CiAgICAgICAgY3Bvc2l0a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sKICAgICAgY29uc3QgZGlmID0gYzAubWludi5ibG9ja1Bvc2l0aW9uIC0gYzEubWludi5ibG9ja1Bvc2l0aW9uOwogICAgICBpZiAoZGlmICE9PSAwKSB7CiAgICAgICAgcmV0dXJuIGRpZjsKICAgICAgfSBlbHNlIHsKICAgICAgICByZXR1cm4gYzAubWludi5kYXRhUG9zaXRpb24gLSBjMS5taW52LmRhdGFQb3NpdGlvbjsKICAgICAgfQogICAgfSk7CiAgICBjaHVua3MuZm9yRWFjaCgoY2h1bmspID0+IHsKICAgICAgaWYgKCFsb3dlc3QgfHwgY2h1bmsubWF4di5jb21wYXJlVG8obG93ZXN0KSA+IDApIHsKICAgICAgICBpZiAobGFzdENodW5rID09PSBudWxsKSB7CiAgICAgICAgICBtZXJnZWRDaHVua3MucHVzaChjaHVuayk7CiAgICAgICAgICBsYXN0Q2h1bmsgPSBjaHVuazsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgaWYgKGNhbk1lcmdlQmxvY2tzKGxhc3RDaHVuaywgY2h1bmspKSB7CiAgICAgICAgICAgIGlmIChjaHVuay5tYXh2LmNvbXBhcmVUbyhsYXN0Q2h1bmsubWF4dikgPiAwKSB7CiAgICAgICAgICAgICAgbGFzdENodW5rLm1heHYgPSBjaHVuay5tYXh2OwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBtZXJnZWRDaHVua3MucHVzaChjaHVuayk7CiAgICAgICAgICAgIGxhc3RDaHVuayA9IGNodW5rOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgfSk7CiAgICByZXR1cm4gbWVyZ2VkQ2h1bmtzOwogIH0KCiAgLy8gbm9kZV9tb2R1bGVzLy5wbnBtL0BnbW9kK3RhYml4QDEuNS4xMS9ub2RlX21vZHVsZXMvQGdtb2QvdGFiaXgvZXNtL3RiaS5qcwogIGluaXRfYnVmZmVyX3NoaW0oKTsKICB2YXIgaW1wb3J0X2xvbmcyID0gX190b01vZHVsZShyZXF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ogICAgICAgICAgICAgIHN0YXRzID0gdGhpcy5wYXJzZVBzZXVkb0JpbihieXRlcywgY3Vyck9mZnNldCk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgY3Vyck9mZnNldCArPSAxNiAqIGNodW5rQ291bnQ7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBjb25zdCBjaHVua0NvdW50ID0gYnl0ZXMucmVhZEludDMyTEUoY3Vyck9mZnNldCk7CiAgICAgICAgICAgIGN1cnJPZmZzZXQgKz0gNDsKICAgICAgICAgICAgY29uc3QgY2h1bmtzID0gbmV3IEFycmF5KGNodW5rQ291bnQpOwogICAgICAgICAgICBmb3IgKGxldCBrID0gMDsgayA8IGNodW5rQ291bnQ7IGsgKz0gMSkgewogICAgICAgICAgICAgIGNvbnN0IHUgPSBmcm9tQnl0ZXMoYnl0ZXMsIGN1cnJPZmZzZXQpOwogICAgICAgICAgICAgIGNvbnN0IHYgPSBmcm9tQnl0ZXMoYnl0ZXMsIGN1cnJPZmZzZXQgKyA4KTsKICAgICAgICAgICAgICBjdXJyT2Zmc2V0ICs9IDE2OwogICAgICAgICAgICAgIGZpcnN0RGF0YUxpbmUgPSB0aGlzLl9maW5kRmlyc3REYXRhKGZpcnN0RGF0YUxpbmUsIHUpOwogICAgICAgICAgICAgIGNodW5rc1trXSA9IG5ldyBDaHVuayh1LCB2LCBiaW4pOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGJpbkluZGV4W2Jpbl0gPSBjaHVua3M7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGNvbnN0IGxpbmVhckNvdW50ID0gYnl0ZXMucmVhZEludDMyTEUoY3Vyck9mZnNldCk7CiAgICAgICAgY3Vyck9mZnNldCArPSA0OwogICAgICAgIGNvbnN0IGxpbmVhckluZGV4ID0gbmV3IEFycmF5KGxpbmVhckNvdW50KTsKICAgICAgICBmb3IgKGxldCBrID0gMDsgayA8IGxpbmVhckNvdW50OyBrICs9IDEpIHsKICAgICAgICAgIG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TsKICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCBuYW1lc0J5dGVzLmxlbmd0aDsgaSArPSAxKSB7CiAgICAgICAgaWYgKCFuYW1lc0J5dGVzW2ldKSB7CiAgICAgICAgICBpZiAoY3Vyck5hbWVTdGFydCA8IGkpIHsKICAgICAgICAgICAgbGV0IHJlZk5hbWUgPSBuYW1lc0J5dGVzLnRvU3RyaW5nKCJ1dGY4IiwgY3Vyck5hbWVTdGFydCwgaSk7CiAgICAgICAgICAgIHJlZk5hbWUgPSB0aGlzLnJlbmFtZVJlZlNlcShyZWZOYW1lKTsKICAgICAgICAgICAgcmVmSWRUb05hbWVbY3VyclJlZklkXSA9IHJlZk5hbWU7CiAgICAgICAgICAgIHJlZk5hbWVUb0lkW3JlZk5hbWVdID0gY3VyclJlZklkOwogICAgICAgICAgfQogICAgICAgICAgY3Vyck5hbWVTdGFydCA9IGkgKyAxOwogICAgICAgICAgY3VyclJlZklkICs9IDE7CiAgICAgICAgfQogICAgICB9CiAgICAgIHJldHVybiB7IHJlZk5hbWVUb0lkLCByZWZJZFRvTmFtZSB9OwogICAgfQogICAgYXN5bmMgYmxvY2tzRm9yUmFuZ2UocmVmTmFtZSwgbWluLCBtYXgsIG9wdHMgPSB7fSkgewogICAgICBpZiAobWluIDwgMCkgewogICAgICAgIG1pbiA9IDA7CiAgICAgIH0KICAgICAgY29uc3QgaW5kZXhEYXRhID0gYXdhaXQgdGhpcy5wYXJzZShvcHRzKTsKICAgICAgaWYgKCFpbmRleERhdGEpIHsKICAgICAgICByZXR1cm4gW107CiAgICAgIH0KICAgICAgY29uc3QgcmVmSWQgPSBpbmRleERhdGEucmVmTmFtZVRvSWRbcmVmTmFtZV07CiAgICAgIGNvbnN0IGJhID0gaW5kZXhEYXRhLmluZGljZXNbcmVmSWRdOwogICAgICBpZiAoIWJhKSB7CiAgICAgICAgcmV0dXJuIFtdOwogICAgICB9CiAgICAgIGNvbnN0IG1pbk9mZnNldCA9IGJhLmxpbmVhckluZGV4Lmxlbmd0aCA/IGJhLmxpbmVhckluZGV4W21pbiA+PiBUQURfTElEWF9TSElGVCA+PSBiYS5saW5lYXJJbmRleC5sZW5ndGggPyBiYS5saW5lYXJJbmRleC5sZW5ndGggLSAxIDogbWluID4+IFRBRF9MSURYX1NISUZUXSA6IG5ldyBWaXJ0dWFsT2Zmc2V0KDAsIDApOwogICAgICBpZiAoIW1pbk9mZnNldCkgewogICAgICAgIGNvbnNvbGUud2FybigicXVlcnlpbmcgb3V0c2lkZSBvZiBwb3NzaWJsZSB0YWJpeCByYW5nZSIpOwogICAgICB9CiAgICAgIGNvbnN0IG92ZXJsYXBwaW5nQmlucyA9IHJlZzJiaW5zKG1pbiwgbWF4KTsKICAgICAgY29uc3QgY2h1bmtzID0gW107CiAgICAgIGZvciAoY29uc3QgW3N0YXJ0LCBlbmRdIG9mIG92ZXJsYXBwaW5nQmlucykgewogICAgICAgIGZvciAobGV0IGJpbiA9IHN0YXJ0OyBiaW4gPD0gZW5kOyBiaW4rKykgewogICAgICAgICAgaWYgKGJhLmJpbkluZGV4W2Jpbl0pIHsKICAgICAgICAgICAgY29uc3QgYmluQ2h1bmtzID0gYmEuYmluSW5kZXhbYmluXTsKICAgICAgICAgICAgZm9yIChsZXQgYyA9IDA7IGMgPCBiaW5DaHVua3MubGVuZ3RoOyArK2MpIHsKICAgICAgICAgICAgICBjaHVua3MucHVzaChuZXcgQ2h1bmsoYmluQ2h1bmtzW2NdLm1pbnYsIGJpbkNodW5rc1tjXS5tYXh2LCBiaW4pKTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgICBjb25zdCBuaW50diA9IGJhLmxpbmVhckluZGV4Lmxlbmd0aDsKICAgICAgbGV0IGxvd2VzdCA9IG51bGw7CiAgICAgIGNvbnN0IG1pbkxpbiA9IE1hdGgubWluKG1pbiA+PiAxNCwgbmludHYgLSAxKTsKICAgICAgY29uc3QgbWF4TGluID0gTWF0aC5taW4obWF4ID4+IDE0LCBuaW50diAtIDEpOwogICAgICBmb3IgKGxldCBpID0gbWluTGluOyBpIDw9IG1heExpbjsgKytpKSB7CiAgICAgICAgY29uc3QgdnAgPSBiYS5saW5lYXJJbmRleFtpXTsKICAgICAgICBpZiAodnApIHsKICAgICAgICAgIGlmICghbG93ZXN0IHx8IHZwLmNvbXBhcmVUbyhsb3dlc3QpIDwgMCkgewogICAgICAgICAgICBsb3dlc3QgPSB2cDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgICAgcmV0dXJuIG9wdGltaXplQ2h1bmtzKGNodW5rcywgbG93ZXN0KTsKICAgIH0KICB9OwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vQGdtb2QrdGFiaXhAMS41LjExL25vZGVfbW9kdWxlcy9AZ21vZC90YWJpeC9lc20vY3NpLmpzCiAgaW5pdF9idWZmZXJfc2hpbSgpOwogIHZhciBpbXBvcnRfbG9uZzMgPSBfX3RvTW9kdWxlKHJlcXVpcmVfbG9uZygpKTsKICB2YXIgQ1NJMV9NQUdJQyA9IDIxNTgyNjU5OwogIHZhciBDU0kyX01BR0lDID0gMzgzNTk4NzU7CiAgZnVuY3Rpb24gbHNoaWZ0KG51bSwgYml0cykgewogICAgcmV0dXJuIG51bSAqIDIgKiogYml0czsKICB9CiAgZnVuY3Rpb24gcnNoaWZ0KG51bSwgYml0cykgewogICAgcmV0dXJuIE1hdGguZmxvb3IobnVtIC8gMiAqKiBiaXRzKTsKICB9CiAgdmFyIENTSSA9IGNsYXNzIGV4dGVuZHMgSW5kZXhGaWxlIHsKICAgIGNvbnN0cnVjdG9yKGFyZ3MpIHsKICAgICAgc3VwZXIoYXJncyk7CiAgICAgIHRoaXMubWF4QmluTnVtYmVyID0gMDsKICAgICAgdGhpcy5kZXB0aCA9IDA7CiAgICAgIHRoaXMubWluU2hpZnQgPSAwOwogICAgfQogICAgYXN5bmMgbGluZUNvdW50KHJlZk5hbWUsIG9wdHMgPSB7fSkgewogICAgICBjb25zdC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ogICAgICAgIGxldCBzdGF0czsKICAgICAgICBmb3IgKGxldCBqID0gMDsgaiA8IGJpbkNvdW50OyBqICs9IDEpIHsKICAgICAgICAgIGNvbnN0IGJpbiA9IGJ5dGVzLnJlYWRVSW50MzJMRShjdXJyT2Zmc2V0KTsKICAgICAgICAgIGlmIChiaW4gPiB0aGlzLm1heEJpbk51bWJlcikgewogICAgICAgICAgICBzdGF0cyA9IHRoaXMucGFyc2VQc2V1ZG9CaW4oYnl0ZXMsIGN1cnJPZmZzZXQgKyA0KTsKICAgICAgICAgICAgY3Vyck9mZnNldCArPSA0ICsgOCArIDQgKyAxNiArIDE2OwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgY29uc3QgbG9mZnNldCA9IGZyb21CeXRlcyhieXRlcywgY3Vyck9mZnNldCArIDQpOwogICAgICAgICAgICBmaXJzdERhdGFMaW5lID0gdGhpcy5fZmluZEZpcnN0RGF0YShmaXJzdERhdGFMaW5lLCBsb2Zmc2V0KTsKICAgICAgICAgICAgY29uc3QgY2h1bmtDb3VudCA9IGJ5dGVzLnJlYWRJbnQzMkxFKGN1cnJPZmZzZXQgKyAxMik7CiAgICAgICAgICAgIGN1cnJPZmZzZXQgKz0gMTY7CiAgICAgICAgICAgIGNvbnN0IGNodW5rcyA9IG5ldyBBcnJheShjaHVua0NvdW50KTsKICAgICAgICAgICAgZm9yIChsZXQgayA9IDA7IGsgPCBjaHVua0NvdW50OyBrICs9IDEpIHsKICAgICAgICAgICAgICBjb25zdCB1ID0gZnJvbUJ5dGVzKGJ5dGVzLCBjdXJyT2Zmc2V0KTsKICAgICAgICAgICAgICBjb25zdCB2ID0gZnJvbUJ5dGVzKGJ5dGVzLCBjdXJyT2Zmc2V0ICsgOCk7CiAgICAgICAgICAgICAgY3Vyck9mZnNldCArPSAxNjsKICAgICAgICAgICAgICBjaHVua3Nba10gPSBuZXcgQ2h1bmsodSwgdiwgYmluKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBiaW5JbmRleFtiaW5dID0gY2h1bmtzOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4geyBiaW5JbmRleCwgc3RhdHMgfTsKICAgICAgfSk7CiAgICAgIHJldHVybiB7CiAgICAgICAgLi4uYXV4LAogICAgICAgIGNzaTogdHJ1ZSwKICAgICAgICByZWZDb3VudCwKICAgICAgICBtYXhCbG9ja1NpemU6IDEgPDwgMTYsCiAgICAgICAgZmlyc3REYXRhTGluZSwKICAgICAgICBjc2lWZXJzaW9uLAogICAgICAgIGluZGljZXMsCiAgICAgICAgZGVwdGg6IHRoaXMuZGVwdGgsCiAgICAgICAgbWF4QmluTnVtYmVyOiB0aGlzLm1heEJpbk51bWJlciwKICAgICAgICBtYXhSZWZMZW5ndGgKICAgICAgfTsKICAgIH0KICAgIHBhcnNlUHNldWRvQmluKGJ5dGVzLCBvZmZzZXQpIHsKICAgICAgY29uc3QgbGluZUNvdW50ID0gbG9uZ1RvTnVtYmVyKGltcG9ydF9sb25nMy5kZWZhdWx0LmZyb21CeXRlc0xFKGJ5dGVzLnNsaWNlKG9mZnNldCArIDI4LCBvZmZzZXQgKyAzNiksIHRydWUpKTsKICAgICAgcmV0dXJuIHsgbGluZUNvdW50IH07CiAgICB9CiAgICBhc3luYyBibG9ja3NGb3JSYW5nZShyZWZOYW1lLCBtaW4sIG1heCwgb3B0cyA9IHt9KSB7CiAgICAgIGlmIChtaW4gPCAwKSB7CiAgICAgICAgbWluID0gMDsKICAgICAgfQogICAgICBjb25zdCBpbmRleERhdGEgPSBhd2FpdCB0aGlzLnBhcnNlKG9wdHMpOwogICAgICBpZiAoIWluZGV4RGF0YSkgewogICAgICAgIHJldHVybiBbXTsKICAgICAgfQogICAgICBjb25zdCByZWZJZCA9IGluZGV4RGF0YS5yZWZOYW1lVG9JZFtyZWZOYW1lXTsKICAgICAgY29uc3QgYmEgPSBpbmRleERhdGEuaW5kaWNlc1tyZWZJZF07CiAgICAgIGlmICghYmEpIHsKICAgICAgICByZXR1cm4gW107CiAgICAgIH0KICAgICAgY29uc3Qgb3ZlcmxhcHBpbmdCaW5zID0gdGhpcy5yZWcyYmlucyhtaW4sIG1heCk7CiAgICAgIGNvbnN0IGNodW5rcyA9IFtdOwogICAgICBmb3IgKGNvbnN0IFtzdGFydCwgZW5kXSBvZiBvdmVybGFwcGluZ0JpbnMpIHsKICAgICAgICBmb3IgKGxldCBiaW4gPSBzdGFydDsgYmluIDw9IGVuZDsgYmluKyspIHsKICAgICAgICAgIGlmIChiYS5iaW5JbmRleFtiaW5dKSB7CiAgICAgICAgICAgIGNvbnN0IGJpbkNodW5rcyA9IGJhLmJpbkluZGV4W2Jpbl07CiAgICAgICAgICAgIGZvciAobGV0IGMgPSAwOyBjIDwgYmluQ2h1bmtzLmxlbmd0aDsgKytjKSB7CiAgICAgICAgICAgICAgY2h1bmtzLnB1c2gobmV3IENodW5rKGJpbkNodW5rc1tjXS5taW52LCBiaW5DaHVua3NbY10ubWF4diwgYmluKSk7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgICAgcmV0dXJuIG9wdGltaXplQ2h1bmtzKGNodW5rcywgbmV3IFZpcnR1YWxPZmZzZXQoMCwgMCkpOwogICAgfQogICAgcmVnMmJpbnMoYmVnLCBlbmQpIHsKICAgICAgYmVnIC09IDE7CiAgICAgIGlmIChiZWcgPCAxKSB7CiAgICAgICAgYmVnID0gMTsKICAgICAgfQogICAgICBpZiAoZW5kID4gMiAqKiA1MCkgewogICAgICAgIGVuZCA9IDIgKiogMzQ7CiAgICAgIH0KICAgICAgZW5kIC09IDE7CiAgICAgIGxldCBsID0gMDsKICAgICAgbGV0IHQgPSAwOwogICAgICBsZXQgcyA9IHRoaXMubWluU2hpZnQgKyB0aGlzLmRlcHRoICogMzsKICAgICAgY29uc3QgYmlucyA9IFtdOwogICAgICBmb3IgKDsgbCA8PSB0aGlzLmRlcHRoOyBzIC09IDMsIHQgKz0gbHNoaWZ0KDEsIGwgKiAzKSw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xpbWl0ID0gNWU3LCByZW5hbWVSZWZTZXFzID0gKG4pID0+IG4sIGNodW5rQ2FjaGVTaXplID0gNSAqIDIgKiogMjAgfSkgewogICAgICBpZiAoZmlsZWhhbmRsZSkgewogICAgICAgIHRoaXMuZmlsZWhhbmRsZSA9IGZpbGVoYW5kbGU7CiAgICAgIH0gZWxzZSBpZiAocGF0aCkgewogICAgICAgIHRoaXMuZmlsZWhhbmRsZSA9IG5ldyBpbXBvcnRfbG9jYWxGaWxlLmRlZmF1bHQocGF0aCk7CiAgICAgIH0gZWxzZSB7CiAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcigibXVzdCBwcm92aWRlIGVpdGhlciBmaWxlaGFuZGxlIG9yIHBhdGgiKTsKICAgICAgfQogICAgICBpZiAodGJpRmlsZWhhbmRsZSkgewogICAgICAgIHRoaXMuaW5kZXggPSBuZXcgVGFiaXhJbmRleCh7CiAgICAgICAgICBmaWxlaGFuZGxlOiB0YmlGaWxlaGFuZGxlLAogICAgICAgICAgcmVuYW1lUmVmU2VxcwogICAgICAgIH0pOwogICAgICB9IGVsc2UgaWYgKGNzaUZpbGVoYW5kbGUpIHsKICAgICAgICB0aGlzLmluZGV4ID0gbmV3IENTSSh7CiAgICAgICAgICBmaWxlaGFuZGxlOiBjc2lGaWxlaGFuZGxlLAogICAgICAgICAgcmVuYW1lUmVmU2VxcwogICAgICAgIH0pOwogICAgICB9IGVsc2UgaWYgKHRiaVBhdGgpIHsKICAgICAgICB0aGlzLmluZGV4ID0gbmV3IFRhYml4SW5kZXgoewogICAgICAgICAgZmlsZWhhbmRsZTogbmV3IGltcG9ydF9sb2NhbEZpbGUuZGVmYXVsdCh0YmlQYXRoKSwKICAgICAgICAgIHJlbmFtZVJlZlNlcXMKICAgICAgICB9KTsKICAgICAgfSBlbHNlIGlmIChjc2lQYXRoKSB7CiAgICAgICAgdGhpcy5pbmRleCA9IG5ldyBDU0koewogICAgICAgICAgZmlsZWhhbmRsZTogbmV3IGltcG9yd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mFjazsKICAgICAgaWYgKHR5cGVvZiBvcHRzID09PSAidW5kZWZpbmVkIikgewogICAgICAgIHRocm93IG5ldyBUeXBlRXJyb3IoImxpbmUgY2FsbGJhY2sgbXVzdCBiZSBwcm92aWRlZCIpOwogICAgICB9CiAgICAgIGlmICh0eXBlb2Ygb3B0cyA9PT0gImZ1bmN0aW9uIikgewogICAgICAgIGNhbGxiYWNrID0gb3B0czsKICAgICAgfSBlbHNlIHsKICAgICAgICBvcHRpb25zID0gb3B0czsKICAgICAgICBjYWxsYmFjayA9IG9wdHMubGluZUNhbGxiYWNrOwogICAgICB9CiAgICAgIGlmIChyZWZOYW1lID09PSB2b2lkIDApIHsKICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCJtdXN0IHByb3ZpZGUgYSByZWZlcmVuY2Ugc2VxdWVuY2UgbmFtZSIpOwogICAgICB9CiAgICAgIGlmICghY2FsbGJhY2spIHsKICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCJsaW5lIGNhbGxiYWNrIG11c3QgYmUgcHJvdmlkZWQiKTsKICAgICAgfQogICAgICBjb25zdCBtZXRhZGF0YSA9IGF3YWl0IHRoaXMuaW5kZXguZ2V0TWV0YWRhdGEob3B0aW9ucyk7CiAgICAgIGNoZWNrQWJvcnRTaWduYWwoc2lnbmFsKTsKICAgICAgaWYgKCFzdGFydCkgewogICAgICAgIHN0YXJ0ID0gMDsKICAgICAgfQogICAgICBpZiAoIWVuZCkgewogICAgICAgIGVuZCA9IG1ldGFkYXRhLm1heFJlZkxlbmd0aDsKICAgICAgfQogICAgICBpZiAoIShzdGFydCA8PSBlbmQpKSB7CiAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcigiaW52YWxpZCBzdGFydCBhbmQgZW5kIGNvb3JkaW5hdGVzLiBzdGFydCBtdXN0IGJlIGxlc3MgdGhhbiBvciBlcXVhbCB0byBlbmQiKTsKICAgICAgfQogICAgICBpZiAoc3RhcnQgPT09IGVuZCkgewogICAgICA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3RoKSB7CiAgICAgICAgICBjb25zdCBuID0gYnVmZmVyLmluZGV4T2YoIlxuIiwgYmxvY2tTdGFydCk7CiAgICAgICAgICBpZiAobiA9PT0gLTEpIHsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICB9CiAgICAgICAgICBjb25zdCBiID0gYnVmZmVyLnNsaWNlKGJsb2NrU3RhcnQsIG4pOwogICAgICAgICAgY29uc3QgbGluZSA9IChkZWNvZGVyID09PSBudWxsIHx8IGRlY29kZXIgPT09IHZvaWQgMCA/IHZvaWQgMCA6IGRlY29kZXIuZGVjb2RlKGIpKSB8fCBiLnRvU3RyaW5nKCk7CiAgICAgICAgICBpZiAoZHBvc2l0aW9ucykgewogICAgICAgICAgICB3aGlsZSAoYmxvY2tTdGFydCArIGMubWludi5kYXRhUG9zaXRpb24gPj0gZHBvc2l0aW9uc1twb3MrK10pIHsKICAgICAgICAgICAgfQogICAgICAgICAgICBwb3MtLTsKICAgICAgICAgIH0KICAgICAgICAgIGNvbnN0IHsgc3RhcnRDb29yZGluYXRlLCBvdmVybGFwcyB9ID0gdGhpcy5jaGVja0xpbmUobWV0YWRhdGEsIHJlZk5hbWUsIHN0YXJ0LCBlbmQsIGxpbmUpOwogICAgICAgICAgaWYgKHByZXZpb3VzU3RhcnRDb29yZGluYXRlICE9PSB2b2lkIDAgJiYgc3RhcnRDb29yZGluYXRlICE9PSB2b2lkIDAgJiYgcHJldmlvdXNTdGFydENvb3JkaW5hdGUgPiBzdGFydENvb3JkaW5hdGUpIHsKICAgICAgICAgICAgdGhyb3cgbmV3IEVycm9yKGBMaW5lcyBub3Qgc29ydGVkIGJ5IHN0YXJ0IGNvb3JkaW5hdGUgKCR7cHJldmlvdXNTdGFydENvb3JkaW5hdGV9ID4gJHtzdGFydENvb3JkaW5hdGV9KSwgdGhpcyBmaWxlIGlzIG5vdCB1c2FibGUgd2l0aCBUYWJpeC5gKTsKICAgICAgICAgIH0KICAgICAgICAgIHByZXZpb3VzU3RhcnRDb29yZGluYXRlID0gc3RhcnRDb29yZGluYXRlOwogICAgICAgICAgaWYgKG92ZXJsYXBzKSB7CiAgICAgICAgICAgIGNhbGxiYWNrKGxpbmUudHJpbSgpLCBjcG9zaXRpb25zW3Bvc10gKiAoMSA8PCA4KSArIChibG9ja1N0YXJ0IC0gZHBvc2l0aW9uc1twb3NdKSArIGMubWludi5kYXRhUG9zaXRpb24gKyAxKTsKICAgICAgICAgIH0gZWxzZSBpZiAoc3RhcnRDb29yZGluYXRlICE9PSB2b2lkIDAgJiYgc3RhcnRDb29yZGluYXRlID49IGVuZCkgewogICAgICAgICAgICByZXR1cm47CiAgICAgICAgICB9CiAgICAgICAgICBpZiAodGhpcy55aWVsZFRpbWUgJiYgbGFzdCAtIERhdGUubm93KCkgPiB0aGlzLnlpZWxkVGltZSkgewogICAgICAgICAgICBsYXN0ID0gRGF0ZS5ub3coKTsKICAgICAgICAgICAgY2hlY2tBYm9ydFNpZ25hbChzaWduYWwpOwogICAgICAgICAgICBhd2FpdCB0aW1lb3V0KDEpOwogICAgICAgICAgfQogICAgICAgICAgYmxvY2tTdGFydCA9IG4gKyAxOwogICAgICAgIH0KICAgICAgfQogICAgfQogICAgYXN5bmMgZ2V0TWV0YWRhdGEob3B0cyA9IHt9KSB7CiAgICAgIHJldHVybiB0aGlzLmluZGV4LmdldE1ldGFkYXRhKG9wdHMpOwogICAgfQogICAgYXN5bmMgZ2V0SGVhZGVyQnVmZmVyKG9wdHMgPSB7fSkgewogICAgICBjb25zdCB7IGZpcnN0RGF0YUxpbmUsIG1ldGFDaGFyLCBtYXhCbG9ja1NpemUgfSA9IGF3YWl0IHRoaXMuZ2V0TWV0YWRhdGEob3B0cyk7CiAgICAgIGNoZWNrQWJvcnRTaWduYWwob3B0cy5zaWduYWwpOwogICAgICBjb25zdCBtYXhGZXRjaCA9ICgoZmlyc3REYXRhTGluZSA9PT0gbnVsbCB8fCBmaXJzdERhdGFMaW5lID09PSB2b2lkIDAgPyB2b2lkIDAgOiBma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ICAgbGV0IHJlZlNlcSA9ICIiOwogICAgICBsZXQgc3RhcnRDb29yZGluYXRlID0gLUluZmluaXR5OwogICAgICBmb3IgKGxldCBpID0gMDsgaSA8IGxpbmUubGVuZ3RoICsgMTsgaSArPSAxKSB7CiAgICAgICAgaWYgKGxpbmVbaV0gPT09ICIJIiB8fCBpID09PSBsaW5lLmxlbmd0aCkgewogICAgICAgICAgaWYgKGN1cnJlbnRDb2x1bW5OdW1iZXIgPT09IHJlZikgewogICAgICAgICAgICBpZiAodGhpcy5yZW5hbWVSZWZTZXEobGluZS5zbGljZShjdXJyZW50Q29sdW1uU3RhcnQsIGkpKSAhPT0gcmVnaW9uUmVmTmFtZSkgewogICAgICAgICAgICAgIHJldHVybiB7IG92ZXJsYXBzOiBmYWxzZSB9OwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgaWYgKGN1cnJlbnRDb2x1bW5OdW1iZXIgPT09IHN0YXJ0KSB7CiAgICAgICAgICAgIHN0YXJ0Q29vcmRpbmF0ZSA9IHBhcnNlSW50KGxpbmUuc2xpY2UoY3VycmVudENvbHVtblN0YXJ0LCBpKSwgMTApOwogICAgICAgICAgICBpZiAoY29vcmRpbmF0ZVR5cGUgPT09ICIxLWJhc2VkLWNsb3NlZCIpIHsKICAgICAgICAgICAgICBzdGFydENvb3JkaW5hdGUgLT0gMTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoc3RhcnRDb29yZGluYXRlID49IHJlZ2lvbkVuZCkgewogICAgICAgICAgICAgIHJldHVybiB7IHN0YXJ0Q29vcmRpbmF0ZSwgb3ZlcmxhcHM6IGZhbHNlIH07CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKGVuZCA9PT0gMCB8fCBlbmQgPT09IHN0YXJ0KSB7CiAgICAgICAgICAgICAgaWYgKHN0YXJ0Q29vcmRpbmF0ZSArIDEgPD0gcmVnaW9uU3RhcnQpIHsKICAgICAgICAgICAgICAgIHJldHVybiB7IHN0YXJ0Q29vcmRpbmF0ZSwgb3ZlcmxhcHM6IGZhbHNlIH07CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgaWYgKGZvcm1hdCA9PT0gIlZDRiIgJiYgY3VycmVudENvbHVtbk51bWJlciA9PT0gNCkgewogICAgICAgICAgICByZWZTZXEgPSBsaW5lLnNsaWNlKGN1cnJlbnRDb2x1bW5TdGFydCwgaSk7CiAgICAgICAgICB9IGVsc2UgaWYgKGN1cnJlbnRDb2x1bW5OdW1iZXIgPT09IGVuZCkgewogICAgICAgICAgICBsZXQgZW5kQ29vcmRpbmF0ZTsKICAgICAgICAgICAgaWYgKGZvcm1hdCA9PT0gIlZDRiIpIHsKICAgICAgICAgICAgICBlbmRDb29yZGluYXRlID0gdGhpcy5fZ2V0VmNmRW5kKHN0YXJ0Q29vcmRpbmF0ZSwgcmVmU2VxLCBsaW5lLnNsaWNlKGN1cnJlbnRDb2x1bW5TdGFydCwgaSkpOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIGVuZENvb3JkaW5hdGUgPSBwYXJzZUludChsaW5lLnNsaWNlKGN1cnJlbnRDb2x1bW5TdGFydCwgaSksIDEwKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoZW5kQ29vcmRpbmF0ZSA8PSByZWdpb25TdGFydCkgewogICAgICAgICAgICAgIHJldHVybiB7IG92ZXJsYXBzOiBmYWxzZSB9OwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBjdXJyZW50Q29sdW1uU3RhcnQgPSBpICsgMTsKICAgICAgICAgIGN1cnJlbnRDb2x1bW5OdW1iZXIgKz0gMTsKICAgICAgICAgIGlmIChjdXJyZW50Q29sdW1uTnVtYmVyID4gbWF4Q29sdW1uKSB7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgICByZXR1cm4geyBzdGFydENvb3JkaW5hdGUsIG92ZXJsYXBzOiB0cnVlIH07CiAgICB9CiAgICBfZ2V0VmNmRW5kKHN0YXJ0Q29vcmRpbmF0ZSwgcmVmU2VxLCBpbmZvKSB7CiAgICAgIGxldCBlbmRDb29yZGluYXRlID0gc3RhcnRDb29yZGluYXRlICsgcmVmU2VxLmxlbmd0aDsKICAgICAgY29uc3QgaXNUUkEgPSBpbmZvLmluZGV4T2YoIlNWVFlQRT1UUkEiKSAhPT0gLTE7CiAgICAgIGlmIChpbmZvWzBdICE9PSAiLiIgJiYgIWlzVFJBKSB7CiAgICAgICAgbGV0IHByZXZDaGFyID0gIjsiOwogICAgICAgIGZvciAobGV0IGogPSAwOyBqIDwgaW5mby5sZW5ndGg7IGogKz0gMSkgewogICAgICAgICAgaWYgKHByZXZDaGFyID09PSAiOyIgJiYgaW5mby5zbGljZShqLCBqICsgNCkgPT09ICJFTkQ9IikgewogICAgICAgICAgICBsZXQgdmFsdWVFbmQgPSBpbmZvLmluZGV4T2YoIjsiLCBqKTsKICAgICAgICAgICAgaWYgKHZhbHVlRW5kID09PSAtMSkgewogICAgICAgICAgICAgIHZhbHVlRW5kID0gaW5mby5sZW5ndGg7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZW5kQ29vcmRpbmF0ZSA9IHBhcnNlSW50KGluZm8uc2xpY2UoaiArIDQsIHZhbHVlRW5kKSwgMTApOwogICAgICAgICAgICBicmVhazsKICAgICAgICAgIH0KICAgICAgICAgIHByZXZDaGFyID0gaW5mb1tqXTsKICAgICAgICB9CiAgICAgIH0gZWxzZSBpZiAoaXNUUkEpIHsKICAgICAgICByZXR1cm4gc3RhcnRDb29yZGluYXRlICsgMTsKICAgICAgfQogICAgICByZXR1cm4gZW5kQ29vcmRpbmF0ZTsKICAgIH0KICAgIGFzeW5jIGxpbmVDb3VudChyZWZOYW1lLCBvcHRzID0ge30pIHsKICAgICAgcmV0dXJuIHRoaXMuaW5kZXgubGluZUNvdW50KHJlZk5hbWUsIG9wdHMpOwogICAgfQogICAgYXN5bmMgX3JlYWRSZW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ZWQgZnJvbSBwcmltYXJ5IGRhdGEsIG5vdCBjYWxsZWQgZ2Vub3R5cGVzKSIKICAgICAgfSwKICAgICAgQU46IHsKICAgICAgICBOdW1iZXI6IDEsCiAgICAgICAgVHlwZTogIkludGVnZXIiLAogICAgICAgIERlc2NyaXB0aW9uOiAiVG90YWwgbnVtYmVyIG9mIGFsbGVsZXMgaW4gY2FsbGVkIGdlbm90eXBlcyIKICAgICAgfSwKICAgICAgQlE6IHsKICAgICAgICBOdW1iZXI6IDEsCiAgICAgICAgVHlwZTogIkZsb2F0IiwKICAgICAgICBEZXNjcmlwdGlvbjogIlJNUyBiYXNlIHF1YWxpdHkiCiAgICAgIH0sCiAgICAgIENJR0FSOiB7CiAgICAgICAgTnVtYmVyOiAxLAogICAgICAgIFR5cGU6ICJGbG9hdCIsCiAgICAgICAgRGVzY3JpcHRpb246ICJDaWdhciBzdHJpbmcgZGVzY3JpYmluZyBob3cgdG8gYWxpZ24gYW4gYWx0ZXJuYXRlIGFsbGVsZSB0byB0aGUgcmVmZXJlbmNlIGFsbGVsZSIKICAgICAgfSwKICAgICAgREI6IHsKICAgICAgICBOdW1iZXI6IDAsCiAgICAgICAgVHlwZTogIkZsYWciLAogICAgICAgIERlc2NyaXB0aW9uOiAiZGJTTlAgbWVtYmVyc2hpcCIKICAgICAgfSwKICAgICAgRFA6IHsKICAgICAgICBOdW1iZXI6IDEsCiAgICAgICAgVHlwZTogIkludGVnZXIiLAogICAgICAgIERlc2NyaXB0aW9uOiAiY29tYmluZWQgZGVwdGggYWNyb3NzIHNhbXBsZXMiCiAgICAgIH0sCiAgICAgIEVORDogewogICAgICAgIE51bWJlcjogMSwKICAgICAgICBUeXBlOiAiSW50ZWdlciIsCiAgICAgICAgRGVzY3JpcHRpb246ICJFbmQgcG9zaXRpb24gKGZvciB1c2Ugd2l0aCBzeW1ib2xpYyBhbGxlbGVzKSIKICAgICAgfSwKICAgICAgSDI6IHsKICAgICAgICBOdW1iZXI6IDAsCiAgICAgICAgVHlwZTogIkZsYWciLAogICAgICAgIERlc2NyaXB0aW9uOiAiSGFwTWFwMiBtZW1iZXJzaGlwIgogICAgICB9LAogICAgICBIMzogewogICAgICAgIE51bWJlcjogMCwKICAgICAgICBUeXBlOiAiRmxhZyIsCiAgICAgICAgRGVzY3JpcHRpb246ICJIYXBNYXAzIG1lbWJlcnNoaXAiCiAgICAgIH0sCiAgICAgIE1ROiB7CiAgICAgICAgTnVtYmVyOiAxLAogICAgICAgIFR5cGU6IG51bGwsCiAgICAgICAgRGVzY3JpcHRpb246ICJSTVMgbWFwcGluZyBxdWFsaXR5IgogICAgICB9LAogICAgICBNUTA6IHsKICAgICAgICBOdW1iZXI6IDEsCiAgICAgICAgVHlwZTogIkludGVnZXIiLAogICAgICAgIERlc2NyaXB0aW9uOiAiTnVtYmVyIG9mIE1BUFEgPT0gMCByZWFkcyIKICAgICAgfSwKICAgICAgTlM6IHsKICAgICAgICBOdW1iZXI6IDEsCiAgICAgICAgVHlwZTogIkludGVnZXIiLAogICAgICAgIERlc2NyaXB0aW9uOiAiTnVtYmVyIG9mIHNhbXBsZXMgd2l0aCBkYXRhIgogICAgICB9LAogICAgICBTQjogewogICAgICAgIE51bWJlcjogNCwKICAgICAgICBUeXBlOiAiSW50ZWdlciIsCiAgICAgICAgRGVzY3JpcHRpb246ICJTdHJhbmQgYmlhcyIKICAgICAgfSwKICAgICAgU09NQVRJQzogewogICAgICAgIE51bWJlcjogMCwKICAgICAgICBUeXBlOiAiRmxhZyIsCiAgICAgICAgRGVzY3JpcHRpb246ICJTb21hdGljIG11dGF0aW9uIChmb3IgY2FuY2VyIGdlbm9taWNzKSIKICAgICAgfSwKICAgICAgVkFMSURBVEVEOiB7CiAgICAgICAgTnVtYmVyOiAwLAogICAgICAgIFR5cGU6ICJGbGFnIiwKICAgICAgICBEZXNjcmlwdGlvbjogIlZhbGlkYXRlZCBieSBmb2xsb3ctdXAgZXhwZXJpbWVudCIKICAgICAgfSwKICAgICAgIjEwMDBHIjogewogICAgICAgIE51bWJlcjogMCwKICAgICAgICBUeXBlOiAiRmxhZyIsCiAgICAgICAgRGVzY3JpcHRpb246ICIxMDAwIEdlbm9tZXMgbWVtYmVyc2hpcCIKICAgICAgfSwKICAgICAgSU1QUkVDSVNFOiB7CiAgICAgICAgTnVtYmVyOiAwLAogICAgICAgIFR5cGU6ICJGbGFnIiwKICAgICAgICBEZXNjcmlwdGlvbjogIkltcHJlY2lzZSBzdHJ1Y3R1cmFsIHZhcmlhdGlvbiIKICAgICAgfSwKICAgICAgTk9WRUw6IHsKICAgICAgICBOdW1iZXI6IDAsCiAgICAgICAgVHlwZTogIkZsYWciLAogICAgICAgIERlc2NyaXB0aW9uOiAiSW5kaWNhdGVzIGEgbm92ZWwgc3RydWN0dXJhbCB2YXJpYXRpb24iCiAgICAgIH0sCiAgICAgIFNWVFlQRTogewogICAgICAgIE51bWJlcjogMSwKICAgICAgICBUeXBlOiAiU3RyaW5nIiwKICAgICAgICBEZXNjcmlwdGlvbjogIlR5cGUgb2Ygc3RydWN0dXJhbCB2YXJpYW50IgogICAgICB9LAogICAgICBTVkxFTjogewogICAgICAgIE51bWJlcjogbnVsbCwKICAgICAgICBUeXBlOiAiSW50ZWdlciIsCiAgICAgICAgRGVzY3JpcHRpb246ICJEaWZmZXJlbmNlIGluIGxlbmd0aCBiZXR3ZWVuIFJFRiBhbmQgQUxUIGFsbGVsZXMiCiAgICAgIH0sCiAgICAgIENJUE9TOiB7CiAgICAgICAgTnVtYmVyOiAyLAogICAgICAgIFR5cGU6ICJJbnRlZ2VyIiwKICAgICAgICBEZXNjcmlwdGlvbjogIkNvbmZpZGVuY2UgaW50ZXJ2YWwgYXJvdW5kIFBPUyBmb3IgaW1wcmVjaXNlIHZhcmlhbnRzIgogICAgICB9LAogICAgICBDSUVORDogewogICAgICAgIE51bWJlcjogMiwKICAgICAgICBUeXBlOiAiSW50ZWdlciIsCiAgICAgICAgRGVzY3JpcHRpb246ICJDb25maWRlbmNlIGludGVydmFsIGFyb3VuZCBFTkQgZm9yIGltcHJlY2lzZSB2YXJpYW50cyIKICAgICAgfSwKICAgICAgSE9NTEVOOiB7CiAgICAgICAgVHlwZTogIkludGVnZXIiLAogICAgICAgIERlc2NyaXB0aW9uOiAiTGVuZ3RoIG9mIGJhc2UgcGFpciBpZGVudGljYWwgbWljcm8taG9tb2xvZ3kgYXQgZXZlbnQgYnJlYWtwb2ludHMiCiAgICAgIH0sCiAgICAgIEhPTVNFUTogewogICAgICAgIFR5cGU6ICJTdHJpbmciLAogICAgICAgIERlc2NyaXB0aW9uOiAiU2VxdWVuY2Ugb2YgYmFzZSBwYWlyIGlkZW50aWNhbCBtaWNyby1ob21vbG9neSBhdCBldmVudCBicmVha3BvaW50cyIKICAgICAgfSwKICAgICAgQktQVElEOiB7CiAgICAgICAgVHlwZTogIlN0cmluZyIsCiAgICAgICAgRGVzY3JpcHRpb246ICJJRCBvZiB0aGUgYXNzZW1ibGVkIGFsdGVybmF0ZSBhbGxlbGUgaW4gdGhlIGFzc2VtYmx5IGZpbGUiCiAgICAgIH0sCiAgICAgIE1FSU5GTzogewogICAgICAgIE51bWJlcjogNCwKICAgICAgICBUeXBlOiAiU3RyaW5nIiwKICAgICAgICBEZXNjcmlwdGlvbjogIk1vYmlsZSBlbGVtZW50IGluZm8gb2YgdGhlIGZvcm0gTkFNRSxTVEFSVCxFTkQsUE9MQVJJVFkiCiAgICAgIH0sCiAgICAgIE1FVFJBTlM6IHsKICAgICAgICBOdW1iZXI6IDQsCiAgICAgICAgVHlwZTogIlN0cmluZyIsCiAgICAgICAgRGVzY3JpcHRpb246ICJNb2JpbGUgZWxlbWVudCB0cmFuc2R1Y3Rpb24gaW5mbyBvZiB0aGUgZm9ybSBDSFIsU1RBUlQsRU5ELFBPTEFSSVRZIgogICAgICB9LAogICAgICBER1ZJRDogewogICAgICAgIE51bWJlcjogMSwKICAgICAgICBUeXBlOiAiU3RyaW5nIiwKICAgICAgICBEZXNjcmlwdGlvbjogIklEIG9mIHRoaXMgZWxlbWVudCBpbiBEYXRhYmFzZSBvZiBHZW5vbWljIFZhcmlhdGlvbiIKICAgICAgfSwKICAgICAgREJWQVJJRDogewogICAgICAgIE51bWJlcjogMSwKICAgICAgICBUeXBlOiAiU3RyaW5nIiwKICAgICAgICBEZXNjcmlwdGlvbjogIklEIG9mIHRoaXMgZWxlbWVudCBpbiBEQlZBUiIKICAgICAgfSwKICAgICAgREJSSVBJRDogewogICAgICAgIE51bWJlcjogMSwKICAgICAgICBUeXBlOiAiU3RyaW5nIiwKICAgICAgICBEZXNjcmlwdGlvbjogIklEIG9mIHRoaXMgZWxlbWVudCBpbiBEQlJJUCIKICAgICAgfSwKICAgICAgTUFURUlEOiB7CiAgICAgICAgTnVtYmVyOiBudWxsLAogICAgICAgIFR5cGU6ICJTdHJpbmciLAogICAgICAgIERlc2NyaXB0aW9uOiAiSUQgb2YgbWF0ZSBicmVha2VuZHMiCiAgICAgIH0sCiAgICAgIFBBUklEOiB7CiAgICAgICAgTnVtYmVyOiAxLAogICAgICAgIFR5cGU6ICJTdHJpbmciLAogICAgICAgIERlc2NyaXB0aW9uOiAiSUQgb2YgcGFydG5lciBicmVha2VuZCIKICAgICAgfSwKICAgICAgRVZFTlQ6IHsKICAgICAgICBOdW1iZXI6IDEsCiAgICAgICAgVHlwZTogIlN0cmluZyIsCiAgICAgICAgRGVzY3JpcHRpb246ICJJRCBvZiBldmVudCBhc3NvY2lhdGVkIHRvIGJyZWFrZW5kIgogICAgICB9LAogICAgICBDSUxFTjogewogICAgICAgIE51bWJlcjogMiwKICAgICAgICBUeXBlOiAiSW50ZWdlciIsCiAgICAgICAgRGVzY3JpcHRpb246ICJDb25maWRlbmNlIGludGVydmFsIGFyb3VuZCB0aGUgaW5zZXJ0ZWQgbWF0ZXJpYWwgYmV0d2VlbiBicmVha2VuZCIKICAgICAgfSwKICAgICAgRFBBREo6IHsgVHlwZTogIkludGVnZXIiLCBEZXNjcmlwdGlvbjogIlJlYWQgRGVwdGggb2YgYWRqYWNlbmN5IiB9LAogICAgICBDTjogewogICAgICAgIE51bWJlcjogMSwKICAgICAgICBUeXBlOiAiSW50ZWdlciIsCiAgICAgICAgRGVzY3JpcHRpb246ICJDb3B5IG51bWJlciBvZiBzZWdtZW50IGNvbnRhaW5pbmcgYnJlYWtlbmQiCiAgICAgIH0sCiAgICAgIENOQURKOiB7CiAgICAgICAgTnVtYmVyOiBudWxsLAogICAgICAgIFR5cGU6ICJJbnRlZ2VyIiwKICAgICAgICBEZXNjcmlwdGlvbjogIkNvcHkgbnVtYmVyIG9mIGFkamFjZW5jeSIKICAgICAgfSwKICAgICAgQ0lDTjogewogICAgICAgIE51bWJlcjogMiwKICAgICAgICBUeXBlOiAiSW50ZWdlciIsCiAgICAgICAgRGVzY3JpcHRpb246ICJDb25maWRlbmNlIGludGVydmFsIGFyb3VuZCBjb3B5IG51bWJlciBmb3IgdGhlIHNlZ21lbnQiCiAgICAgIH0sCiAgICAgIENJQ05BREo6IHsKICAgICAgICBOdW1iZXI6IG51bGwsCiAgICAgICAgVHlwZTogIkludGVnZXIiLAogICAgICAgIERlc2NyaXB0aW9uOiAiQ29uZmlkZW5jZSBpbnRlcnZhbCBhcm91bmQgY29weSBudW1iZXIgZm9yIHRoZSBhZGphY2VuY3kiCiAgICAgIH0KICAgIH0sCiAgICBHZW5vdHlwZUZpZWxkczogewogICAgICBBRDogewogICAgICAgIE51bWJlcjogIlIiLAogICAgICAgIFR5cGU6ICJJbnRlZ2VyIiwKICAgICAgICBEZXNjcmlwdGlvbjogIlJlYWQgZGVwdGggZm9yIGVhY2ggYWxsZWxlIgogICAgICB9LAogICAgICBBREY6IHsKICAgICAgICBOdW1iZXI6ICJSIiwKICAgICAgICBUeXBlOiAiSW50ZWdlciIsCiAgICAgICAgRGVzY3JpcHRpb246ICJSZWFkIGRlcHRoIGZvciBlYWNoIGFsbGVsZSBvbiB0aGUgZm9yd2FyZCBzdHJhbmQiCiAgICAgIH0sCiAgICAgIEFEUjogewogICAgICAgIE51bWJlcjogIlIiLAogICAgICAgIFR5cGU6ICJJbnRlZ2VyIiwKICAgICAgICBEZXNjcmlwdGlvbjogIlJlYWQgZGVwdGggZm9yIGVhY2ggYWxsZWxlIG9uIHRoZSByZXZlcnNlIHN0cmFuZCIKICAgICAgfSwKICAgICAgRFA6IHsKICAgICAgICBOdW1iZXI6IDEsCiAgICAgICAgVHlwZTogIkludGVnZXIiLAogICAgICAgIERlc2NyaXB0aW9uOiAiUmVhZCBkZXB0aCIKICAgICAgfSwKICAgICAgRUM6IHsKICAgICAgICBOdW1iZXI6ICJBIiwKICAgICAgICBUeXBlOiAiSW50ZWdlciIsCiAgICAgICAgRGVzY3JpcHRpb246ICJFeHBlY3RlZCBhbHRlcm5hdGUgYWxsZWxlIGNvdW50cyIKICAgICAgfSwKICAgICAgRlQ6IHsKICAgICAgICBOdW1iZXI6IDEsCiAgICAgICAgVHlwZTogIlN0cmluZyIsCiAgICAgICAgRGVzY3JpcHRpb246ICdGaWx0ZXIgaW5kaWNhdGluZyBpZiB0aGlzIGdlbm90eXBlIHdhcyAiY2FsbGVkIicKICAgICAgfSwKICAgICAgR0w6IHsKICAgICAgICBOdW1iZXI6ICJHIiwKICAgICAgICBUeXBlOiAiRmxvYXQiLAogICAgICAgIERlc2NyaXB0aW9uOiAiR2Vub3R5cGUgbGlrZWxpaG9vZHMiCiAgICAgIH0sCiAgICAgIEdQOiB7CiAgICAgICAgTnVtYmVyOiAiRyIsCiAgICAgICAgVHlwZTogIkZsb2F0IiwKICAgICAgICBEZXNjcmlwdGlvbjogIkdlbm90eXBlIHBvc3RlcmlvciBwcm9iYWJpbGl0aWVzIgogICAgICB9LAogICAgICBHUTogewogICAgICAgIE51bWJlcjogMSwKICAgICAgICBUeXBlOiAiSW50ZWdlciIsCiAgICAgICAgRGVzY3JpcHRpb246ICJDb25kaXRpb25hbCBnZW5vdHlwZSBxdWFsaXR5IgogICAgICB9LAogICAgICBHVDogewogICAgICAgIE51bWJlcjogMSwKICAgICAgICBUeXBlOiAiU3RyaW5nIiwKICAgICAgICBEZXNjcmlwdGlvbjogIkdlbm90eXBlIgogICAgICB9LAogICAgICBIUTogewogICAgICAgIE51bWJlcjogMiwKICAgICAgICBUeXBlOiAiSW50ZWdlciIsCiAgICAgICAgRGVzY3JpcHRpb246ICJIYXBsb3R5cGUgcXVhbGl0eSIKICAgICAgfSwKICAgICAgTVE6IHsKICAgICAgICBOdW1iZXI6IDEsCiAgICAgICAgVHlwZTogIkludGVnZXIiLAogICAgICAgIERlc2NyaXB0aW9uOiAiUk1TIG1hcHBpbmcgcXVhbGl0eSIKICAgICAgfSwKICAgICAgUEw6IHsKICAgICAgICBOdW1iZXI6ICJHIiwKICAgICAgICBUeXBlOiAiSW50ZWdlciIsCiAgICAgICAgRGVzY3JpcHRpb246ICJQaHJlZC1zY2FsZWQgZ2Vub3R5cGUgbGlrZWxpaG9vZHMgcm91bmRlZCB0byB0aGUgY2xvc2VzdCBpbnRlZ2VyIgogICAgICB9LAogICAgICBQUTogewogICAgICAgIE51bWJlcjogMSwKICAgICAgICBUeXBlOiAiSW50ZWdlciIsCiAgICAgICAgRGVzY3JpcHRpb246ICJQaGFzaW5nIHF1YWxpdHkiCiAgICAgIH0sCiAgICAgIFBTOiB7CiAgICAgICAgTnVtYmVyOiAxLAogICAgICAgIFR5cGU6ICJJbnRlZ2VyIiwKICAgICAgICBEZXNjcmlwdGlvbjogIlBoYXNlIHNldCIKICAgICAgfQogICAgfSwKICAgIEFsdFR5cGVzOiB7CiAgICAgIERFTDogewogICAgICAgIERlc2NyaXB0aW9uOiAiRGVsZXRpb24gcmVsYXRpdmUgdG8gdGhlIHJlZmVyZW5jZSIKICAgICAgfSwKICAgICAgSU5TOiB7CiAgICAgICAgRGVzY3JpcHRpb246ICJJbnNlcnRpb24gb2Ygbm92ZWwgc2VxdWVuY2UgcmVsYXRpdmUgdG8gdGhlIHJlZmVyZW5jZSIKICAgICAgfSwKICAgICAgRFVQOiB7CiAgICAgICAg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ICAgICAgICBBTFQ6IHZjZlJlc2VydmVkX2RlZmF1bHQuQWx0VHlwZXMsCiAgICAgICAgRklMVEVSOiB2Y2ZSZXNlcnZlZF9kZWZhdWx0LkZpbHRlclR5cGVzCiAgICAgIH0pKTsKICAgICAgbGV0IGxhc3RMaW5lOwogICAgICBoZWFkZXJMaW5lcy5mb3JFYWNoKChsaW5lKSA9PiB7CiAgICAgICAgaWYgKCFsaW5lLnN0YXJ0c1dpdGgoIiMiKSkgewogICAgICAgICAgdGhyb3cgbmV3IEVycm9yKGBCYWQgbGluZSBpbiBoZWFkZXI6CiR7bGluZX1gKTsKICAgICAgICB9IGVsc2UgaWYgKGxpbmUuc3RhcnRzV2l0aCgiIyMiKSkgewogICAgICAgICAgdGhpcy5fcGFyc2VNZXRhZGF0YShsaW5lKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgbGFzdExpbmUgPSBsaW5lOwogICAgICAgIH0KICAgICAgfSk7CiAgICAgIGlmICghbGFzdExpbmUpIHsKICAgICAgICB0aHJvdyBuZXcgRXJyb3IoIk5vIGZvcm1hdCBsaW5lIGZvdW5kIGluIGhlYWRlciIpOwogICAgICB9CiAgICAgIGNvbnN0IGZpZWxkcyA9IGxhc3RMaW5lLnRyaW0oKS5zcGxpdCgiCSIpOwogICAgICBjb25zdCB0aGlzSGVhZGVyID0gZmllbGRzLnNsaWNlKDAsIDgpOwogICAgICBjb25zdCBjb3JyZWN0SGVhZGVyID0gWwogICAgICAgICIjQ0hST00iLAogICAgICAgICJQT1MiLAogICAgICAgICJJRCIsCiAgICAgICAgIlJFRiIsCiAgICAgICAgIkFMVCIsCiAgICAgICAgIlFVQUwiLAogICAgICAgICJGSUxURVIiLAogICAgICAgICJJTkZPIgogICAgICBdOwogICAgICBpZiAoZmllbGRzLmxlbmd0aCA8IDgpIHsKICAgICAgICB0aHJvdyBuZXcgRXJyb3IoYFZDRiBoZWFkZXIgbWlzc2luZyBjb2x1bW5zOgoke2xhc3RMaW5lfWApOwogICA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V07CiAgICAgICAgaWYgKCFmaWx0ZXJlZE1ldGFkYXRhKSB7CiAgICAgICAgICByZXR1cm4gZmlsdGVyZWRNZXRhZGF0YTsKICAgICAgICB9CiAgICAgIH0KICAgICAgcmV0dXJuIGZpbHRlcmVkTWV0YWRhdGE7CiAgICB9CiAgICBfcGFyc2VLZXlWYWx1ZShzdHIsIHBhaXJTZXBhcmF0b3IgPSAiOyIpIHsKICAgICAgY29uc3QgZGF0YSA9IHt9OwogICAgICBsZXQgY3VycktleSA9ICIiOwogICAgICBsZXQgY3VyclZhbHVlID0gIiI7CiAgICAgIGxldCBzdGF0ZSA9IDE7CiAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgc3RyLmxlbmd0aDsgaSArPSAxKSB7CiAgICAgICAgaWYgKHN0YXRlID09PSAxKSB7CiAgICAgICAgICBpZiAoc3RyW2ldID09PSAiPSIpIHsKICAgICAgICAgICAgc3RhdGUgPSAyOwogICAgICAgICAgfSBlbHNlIGlmIChzdHJbaV0gIT09IHBhaXJTZXBhcmF0b3IpIHsKICAgICAgICAgICAgY3VycktleSArPSBzdHJbaV07CiAgICAgICAgICB9IGVsc2UgaWYgKGN1cnJWYWx1ZSA9PT0gIiIpIHsKICAgICAgICAgICAgZGF0YVtjdXJyS2V5XSA9IG51bGw7CiAgICAgICAgICAgIGN1cnJLZXkgPSAiIjsKICAgICAgICAgIH0KICAgICAgICB9IGVsc2UgaWYgKHN0YXRlID09PSAyKSB7CiAgICAgICAgICBpZiAoc3RyW2ldID09PSBwYWlyU2VwYXJhdG9yKSB7CiAgICAgICAgICAgIGRhdGFbY3VycktleV0gPSBjdXJyVmFsdWU7CiAgICAgICAgICAgIGN1cnJLZXkgPSAiIjsKICAgICAgICAgICAgY3VyclZhbHVlID0gIiI7CiAgICAgICAgICAgIHN0YXRlID0gMTsKICAgICAgICAgIH0gZWxzZSBpZiAoc3RyW2ldID09PSAnIicpIHsKICAgICAgICAgICAgc3RhdGUgPSAzOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgY3VyclZhbHVlICs9IHN0cltpXTsKICAgICAgICAgIH0KICAgICAgICB9IGVsc2UgaWYgKHN0YXRlID09PSAzKSB7CiAgICAgICAgICBpZiAoc3RyW2ldICE9PSAnIicpIHsKICAgICAgICAgICAgY3VyclZhbHVlICs9IHN0cltpXTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHN0YXRlID0gMjsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgICAgaWYgKHN0YXRlID09PSAyIHx8IHN0YXRlID09PSAzKSB7CiAgICAgICAgZGF0YVtjdXJyS2V5XSA9IGN1cnJWYWx1ZTsKICAgICAgfSBlbHNlIGlmIChzdGF0ZSA9PT0gMSkgewogICAgICAgIGRhdGFbY3VycktleV0gPSBudWxsOwogICAgICB9CiAgICAgIHJldHVybiBkYXRhOwogICAgfQogICAgcGFyc2VMaW5lKGxpbmUpIHsKICAgICAgbGluZSA9IGxpbmUudHJpbSgpOwogICAgICBpZiAoIWxpbmUubGVuZ3RoKSB7CiAgICAgICAgcmV0dXJuIHZvaWQgMDsKICAgICAgfQogICAgICBjb25zdCBwYXJzZXIgPSB0aGlzOwogICAgICBsZXQgY3VyckNoYXIgPSAwOwogICAgICBmb3IgKGxldCBjdXJyRmllbGQgPSAwOyBjdXJyQ2hhciA8IGxpbmUubGVuZ3RoOyBjdXJyQ2hhciArPSAxKSB7CiAgICAgICAgaWYgKGxpbmVbY3VyckNoYXJdID09PSAiCSIpIHsKICAgICAgICAgIGN1cnJGaWVsZCArPSAxOwogICAgICAgIH0KICAgICAgICBpZiAoY3VyckZpZWxkID09PSA5KSB7CiAgICAgICAgICBicmVhazsKICAgICAgICB9CiAgICAgIH0KICAgICAgY29uc3QgZmllbGRzID0gbGluZS5zdWJzdHIoMCwgY3VyckNoYXIpLnNwbGl0KCIJIik7CiAgICAgIGNvbnN0IHJlc3QgPSBsaW5lLnN1YnN0cihjdXJyQ2hhciArIDEpOwogICAgICBjb25zdCBbQ0hST00sIFBPUywgSUQsIFJFRiwgQUxULCBRVUFMLCBGSUxURVJdID0gZmllbGRzOwogICAgICBjb25zdCBjaHJvbSA9IENIUk9NOwogICAgICBjb25zdCBwb3MgPSArUE9TOwogICAgICBjb25zdCBpZCA9IElEID09PSAiLiIgPyBudWxsIDogSUQuc3BsaXQoIjsiKTsKICAgICAgY29uc3QgcmVmID0gUkVGOwogICAgICBjb25zdCBhbHQgPSBBTFQgPT09ICIuIiA/IG51bGwgOiBBTFQuc3BsaXQoIiwiKTsKICAgICAgY29uc3QgcXVhbCA9IFFVQUwgPT09ICIuIiA/IG51bGwgOiArUVVBTDsKICAgICAgY29uc3QgZmlsdGVyID0gRklMVEVSID09PSAiLiIgPyBudWxsIDogRklMVEVSLnNwbGl0KCI7Iik7CiAgICAgIGlmICh0aGlzLnN0cmljdCAmJiBmaWVsZHNbN10gPT09IHZvaWQgMCkgewogICAgICAgIHRocm93IG5ldyBFcnJvcigibm8gSU5GTyBmaWVsZCBzcGVjaWZpZWQsIG11c3QgY29udGFpbiBhdCBsZWFzdCBhICcuJyAodHVybiBvZmYgc3RyaWN0IG1vZGUgdG8gYWxsb3cpIik7CiAgICAgIH0KICAgICAgY29uc3QgaW5mbyA9IGZpZWxkc1s3XSA9PT0gdm9pZCAwIHx8IGZpZWxkc1s3XSA9PT0gIi4iID8ge30gOiB0aGlzLl9wYXJzZUtleVZhbHVlKGZpZWxkc1s3XSk7CiAgICAgIE9iamVjdC5rZXlzKGluZm8pLmZvckVhY2goKGtleSkgPT4gewogICAgICAgIGxldCBpdGVtczsKICAgICAgICBpZiAoaW5mb1trZXldKSB7CiAgICAgICAgICBpdGVtcyA9IGluZm9ba2V5XS5zcGxpdCgiLCIpLm1hcCgodmFsKSA9PiB2YWwgPT09ICIuIiA/IG51bGwgOiB2YWwpLm1hcCgoZikgPT4gZiA/IGRlY29kZVVSSUNvbXBvbmVudE5vVGhyb3coZikgOiBmKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgaXRlbXMgPSBpbmZvW2tleV07CiAgICAgICAgfQogICAgICAgIGNvbnN0IGl0ZW1UeXBlID0gdGhpcy5nZXRNZXRhZGF0YSgiSU5GTyIsIGtleSwgIlR5cGUiKTsKICAgICAgICBpZiAoaXRlbVR5cGUpIHsKICAgICAgICAgIGlmIChpdGVtVHlwZSA9PT0gIkludGVnZXIiIHx8IGl0ZW1UeXBlID09PSAiRmxvYXQiKSB7CiAgICAgICAgICAgIGl0ZW1zID0gaXRlbXMubWFwKCh2YWwpID0+IHsKICAgICAgICAgICAgICBpZiAodmFsID09PSBudWxsKSB7CiAgICAgICAgICAgICAgICByZXR1cm4gbnVsbDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgcmV0dXJuIE51bWJlcih2YWwpOwogICAgICAgICAgICB9KTsKICAgICAgICAgIH0gZWxzZSBpZiAoaXRlbVR5cGUgPT09ICJGbGFnIikgewogICAgICAgICAgICBpZiAoaW5mb1trZXldKSB7CiAgICAgICAgICAgICAgY29uc29sZS53YXJuKGBJbmZvIGZpZWxkICR7a2V5fSBpcyBhIEZsYWcgYW5kIHNob3VsZCBub3QgaGF2ZSBhIHZhbHVlIChnb3QgdmFsdWUgJHtpbmZvW2tleV19KWApOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIGl0ZW1zID0gdHJ1ZTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpbmZvW2tleV0gPSBpdGVtczsKICAgICAgfSk7CiAgICAgIGNvbnN0IHZhcmlhbnQgPSBuZXcgVmFyaWFudCh7CiAgICAgICAgQ0hST006IGNocm9tLAogICAgICAgIFBPUzogcG9zLAogICAgICAgIEFMVDogYWx0LAogICAgICAgIElORk86IGluZm8sCiAgICAgICAgUkVGOiByZWYsCiAgICAgICAgRklMVEVSOiBmaWx0ZXIgJiYgZmlsdGVyLmxlbmd0aCA9PT0gMSAmJiBmaWx0ZXJbMF0gPT09ICJQQVNTIi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ChsbyA9PSBudWxsKQogICAgICAgIGxvID0gMDsKICAgICAgaWYgKGhpID09IG51bGwpCiAgICAgICAgaGkgPSBhLmxlbmd0aDsKICAgICAgd2hpbGUgKGxvIDwgaGkpIHsKICAgICAgICBjb25zdCBtaWQgPSBsbyArIGhpID4+PiAxOwogICAgICAgIGlmIChjb21wYXJlKGFbbWlkXSwgeCkgPCAwKQogICAgICAgICAgbG8gPSBtaWQgKyAxOwogICAgICAgIGVsc2UKICAgICAgICAgIGhpID0gbWlkOwogICAgICB9CiAgICAgIHJldHVybiBsbzsKICAgIH0KICAgIGZ1bmN0aW9uIHJpZ2h0KGEsIHgsIGxvLCBoaSkgewogICAgICBpZiAobG8gPT0gbnVsbCkKICAgICAgICBsbyA9IDA7CiAgICAgIGlmIChoaSA9PSBudWxsKQogICAgICAgIGhpID0gYS5sZW5ndGg7CiAgICAgIHdoaWxlIChsbyA8IGhpKSB7CiAgICAgICAgY29uc3QgbWlkID0gbG8gKyBoaSA+Pj4gMTsKICAgICAgICBpZiAoY29tcGFyZShhW21pZF0sIHgpID4gMCkKICAgICAgICAgIGhpID0gbWlkOwogICAgICAgIGVsc2UKICAgICAgICAgIGxvID0gbWlkICsgMTsKICAgICAgfQogICAgICByZXR1cm4gbG87CiAgICB9CiAgICBmdW5jdGlvbiBjZW50ZXIoYSwgeCwgbG8sIGhpKSB7CiAgICAgIGlmIChsbyA9PSBudWxsKQogICAgICAgIGxvID0gMDsKICAgICAgaWYgKGhpID09IG51bGwpCiAgICAgICAgaGkgPSBhLmxlbmd0aDsKICAgICAgY29uc3QgaSA9IGxlZnQoYSwgeCwgbG8sIGhpIC0gMSk7CiAgICAgIHJldHVybiBpID4gbG8gJiYgZGVsdGEoYVtpIC0gMV0sIHgpID4gLWRlbHRhKGFbaV0sIHgpID8gaSAtIDEgOiBpOwogICAgfQogICAgcmV0dXJuIHsgbGVmdCwgY2VudGVyLCByaWdodCB9OwogIH0KICBmdW5jdGlvbiBhc2NlbmRpbmdDb21wY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dXJuICJpbnNlcnRpb24iOwogICAgcmV0dXJuICJ1bmtub3duIjsKICB9OwogIHZhciBnZXRTdWJzdGl0dXRpb25UeXBlID0gKHJlZiwgYWx0KSA9PiB7CiAgICBzd2l0Y2ggKHJlZiArIGFsdCkgewogICAgICBjYXNlICJDQSI6CiAgICAgIGNhc2UgIkdUIjoKICAgICAgICByZXR1cm4gIkM+QSI7CiAgICAgIGNhc2UgIkNHIjoKICAgICAgY2FzZSAiR0MiOgogICAgICAgIHJldHVybiAiQz5HIjsKICAgICAgY2FzZSAiQ1QiOgogICAgICBjYXNlICJHQSI6CiAgICAgICAgcmV0dXJuICJDPlQiOwogICAgICBjYXNlICJUQSI6CiAgICAgIGNhc2UgIkFUIjoKICAgICAgICByZXR1cm4gIlQ+QSI7CiAgICAgIGNhc2UgIlRDIjoKICAgICAgY2FzZSAiQUciOgogICAgICAgIHJldHVybiAiVD5DIjsKICAgICAgY2FzZSAiVEciOgogICAgICBjYXNlICJBQyI6CiAgICAgICAgcmV0dXJuICJUPkciOwogICAgICBkZWZhdWx0OgogICAgICAgIHJldHVybiAidW5rbm93biI7CiAgICB9CiAgfTsKICBmdW5jdGlvbiByZWNvcmRUb1RpbGUodmNmUmVjb3JkLCBjaHJQb3MsIHByZXZBYnNQb3MpIHsKICAgIGNvbnN0IGFic1BvcyA9IGNoclBvcyArIHZjZlJlY29yZC5QT1MgKyAxOwogICAgbGV0IEFMVDsKICAgIGlmIChBcnJheS5pc0FycmF5KHZjZlJlY29yZC5BTFQpICYmIHZjZlJlY29yZC5BTFQubGVuZ3RoID4gMCkgewogICAgICBBTFQgPSB2Y2ZSZWNvcmQuQUxUWzBdOwogICAgfQogICAgY29uc3QgRElTVFBSRVYgPSAhcHJldkFic1BvcyA/IG51bGwgOiBhYnNQb3MgLSBwcmV2QWJzUG9zOwogICAgY29uc3QgRElTVFBSRVZMT0dFID0gIXByZXZBYnNQb3MgPyBudWxsIDogTWF0aC5sb2coYWJzUG9zIC0gcHJldkFic1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zIG9mIGN1bVBvc2l0aW9ucykgewogICAgICAgIGNvbnN0IGNocm9tTmFtZSA9IGN1bVBvcy5jaHI7CiAgICAgICAgY29uc3QgY2hyb21TdGFydCA9IGN1bVBvcy5wb3M7CiAgICAgICAgY29uc3QgY2hyb21FbmQgPSBjdW1Qb3MucG9zICsgY2hyb21MZW5ndGhzW2Nocm9tTmFtZV07CiAgICAgICAgbGV0IHN0YXJ0UG9zLCBlbmRQb3M7CiAgICAgICAgaWYgKGNocm9tU3RhcnQgPiBjdXJNaW5YIHx8IGN1ck1pblggPj0gY2hyb21FbmQpIHsKICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgIH0KICAgICAgICBsZXQgcHJldlBPUzsKICAgICAgICBjb25zdCB0aWxlc1Byb21pc2UgPSBuZXcgUHJvbWlzZSgocmVzb2x2ZSkgPT4gewogICAgICAgICAgY29uc3QgdGlsZXMgPSBbXTsKICAgICAgICAgIGNvbnN0IGxpbmVDYWxsYmFjayA9IChsaW5lKSA9PiB7CiAgICAgICAgICAgIGNvbnN0IHZjZlJlY29yZCA9IHBhcnNlci5wYXJzZUxpbmUobGluZSk7CiAgICAgICAgICAgIGNvbnN0IHZjZlRpbGUgPSByZWNvcmRUb1RpbGUodmNmUmVjb3JkLCBjaHJvbVN0YXJ0LCBwcmV2UE9TKTsKICAgICAgICAgICAgcHJldlBPUyA9IHZjZlRpbGUuUE9TOwogICAgICAgICAgICB0aWxlcy5wdXNoKHZjZlRpbGUpOwogICAgICAgICAgfTsKICAgICAgICAgIGlmIChtYXhYID4gY2hyb21FbmQpIHsKICAgICAgICAgICAgc3RhcnRQb3MgPSBjdXJNaW5YIC0gY2hyb21TdGFydDsKICAgICAgICAgICAgZW5kUG9zID0gY2hyb21FbmQgLSBjaHJvbVN0YXJ0OwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgc3RhcnRQb3MgPSBNYXRoLmZsb29yKGN1ck1pblggLSBjaHJvbVN0YXJ0KTsKICAgICAgICAgICAgZW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GZXJvc3MgQWJvdWtoYWRpamVoIDxodHRwczovL2Zlcm9zcy5vcmc+CiAqIEBsaWNlbnNlICBNSVQKICovCi8qISBpZWVlNzU0LiBCU0QtMy1DbGF1c2UgTGljZW5zZS4gRmVyb3NzIEFib3VraGFkaWplaCA8aHR0cHM6Ly9mZXJvc3Mub3JnL29wZW5zb3VyY2U+ICovCi8qKgogKiBAbGljZW5zZQogKiBMb2Rhc2ggKEN1c3RvbSBCdWlsZCkgPGh0dHBzOi8vbG9kYXNoLmNvbS8+CiAqIEJ1aWxkOiBgbG9kYXNoIG1vZHVsYXJpemUgZXhwb3J0cz0iZXMiIC1vIC4vYAogKiBDb3B5cmlnaHQgT3BlbkpTIEZvdW5kYXRpb24gYW5kIG90aGVyIGNvbnRyaWJ1dG9ycyA8aHR0cHM6Ly9vcGVuanNmLm9yZy8+CiAqIFJlbGVhc2VkIHVuZGVyIE1JVCBsaWNlbnNlIDxodHRwczovL2xvZGFzaC5jb20vbGljZW5zZT4KICogQmFzZWQgb24gVW5kZXJzY29yZS5qcyAxLjguMyA8aHR0cDovL3VuZGVyc2NvcmVqcy5vcmcvTElDRU5TRT4KICogQ29weXJpZ2h0IEplcmVteSBBc2hrZW5hcywgRG9jdW1lbnRDbG91ZCBhbmQgSW52ZXN0aWdhdGl2ZSBSZXBvcnRlcnMgJiBFZGl0b3JzCiAqLwo=",pse=typeof window<"u"&&window.Blob&&new Blob([atob(A9e)],{type:"text/javascript;charset=utf-8"});function stg(){const e=pse&&(window.URL||window.webkitURL).createObjectURL(pse);try{return e?new Worker(e):new Worker("data:application/javascript;base64,"+A9e,{type:"module"})}finally{e&&(window.URL||window.webkitURL).revokeObjectURL(e)}}const ltg=200;class a9e{constructor(g,I){Ct(this,"dataConfig",{}),Ct(this,"uid"),Ct(this,"prevRequestTime"),Ct(this,"track"),Ct(this,"toFetch"),Ct(this,"fetchTimeout"),Ct(this,"worker"),this.uid=g.libraries.slugid.nice(),this.prevRequestTime=0,this.toFetch=new Set;const{url:i,indexUrl:n,assembly:C,...r}=I;this.worker=GT(new stg).then(async o=>{const A=Object.entries(pI(C).size);return await o.init(this.uid,{url:i,indexUrl:n},A,r),o})}async tilesetInfo(g){(await this.worker).tilesetInfo(this.uid).then(g)}fetchTilesDebounced(g,I){this.track.drawLoadingCue(),I.forEach(i=>this.toFetch.add(i)),this.fetchTimeout&&clearTimeout(this.fetchTimeout),this.fetchTimeout=setTimeout(()=>{this.sendFetch(g,[...this.toFetch]),this.toFetch.clear()},ltg)}async sendFetch(g,I){(await this.worker).fetchTilesDebounced(this.uid,I).then(g)}async getTabularData(g){const I=await(await this.worker).getTabularData(this.uid,g);return JSON.parse(new TextDecoder().decode(I))}}Ct(a9e,"config",{type:"vcf"});const Vk=BigInt(32);function ctg(e,g,I){const i=+!!I,n=+!I;return BigInt(e.getInt32(g,I)*n+e.getInt32(g+4,I)*i)<>Vk),C=Number(I&BigInt(4294967295));i?(e.setInt32(g+4,n,i),e.setUint32(g,C,i)):(e.setInt32(g,n,i),e.setUint32(g+4,C,i))}function htg(e,g,I,i){const n=Number(I>>Vk),C=Number(I&BigInt(4294967295));i?(e.setUint32(g+4,n,i),e.setUint32(g,C,i)):(e.setUint32(g,n,i),e.setUint32(g+4,C,i))}"getBigInt64"in DataView||(DataView.prototype.getBigInt64=function(e,g){return ctg(this,e,g)});"getBigUint64"in DataView||(DataView.prototype.getBigUint64=function(e,g){return utg(this,e,g)});"setBigInt64"in DataView||(DataView.prototype.setBigInt64=function(e,g,I){dtg(this,e,g,I)});"setBigUint64"in DataView||(DataView.prototype.setBigUint64=function(e,g,I){htg(this,e,g,I)});class mtg{constructor(g,I){this.code="",this.scopes=[["vars"]],this.bitFields=[],this.tmpVariableCount=0,this.references=new Map,this.imports=[],this.reverseImports=new Map,this.useContextVariables=!1,this.importPath=g,this.useContextVariables=I}generateVariable(g){const I=[...this.scopes[this.scopes.length-1]];return g&&I.push(g),I.join(".")}generateOption(g){switch(typeof g){case"number":return g.toString();case"string":return this.generateVariable(g);case"function":return`${this.addImport(g)}.call(${this.generateVariable()}, vars)`}}generateError(g){this.pushCode(`throw new Error(${g});`)}generateTmpVariable(){return"$tmp"+this.tmpVariableCount++}pushCode(g){this.code+=g+` +`}pushPath(g){g&&this.scopes[this.scopes.length-1].push(g)}popPath(g){g&&this.scopes[this.scopes.length-1].pop()}pushScope(g){this.scopes.push([g])}popScope(){this.scopes.pop()}addImport(g){if(!this.importPath)return`(${g})`;let I=this.reverseImports.get(g);return I||(I=this.imports.push(g)-1,this.reverseImports.set(g,I)),`${this.importPath}[${I}]`}addReference(g){this.references.has(g)||this.references.set(g,{resolved:!1,requested:!1})}markResolved(g){const I=this.references.get(g);I&&(I.resolved=!0)}markRequested(g){g.forEach(I=>{const i=this.references.get(I);i&&(i.requested=!0)})}getUnresolvedReferences(){return Array.from(this.references).filter(([g,I])=>!I.resolved&&!I.requested).map(([g,I])=>g)}}const Ro=new Map,Ru="___parser_",Wo={uint8:1,uint16le:2,uint16be:2,uint32le:4,uint32be:4,int8:1,int16le:2,int16be:2,int32le:4,int32be:4,int64be:8,int64le:8,uint64be:8,uint64le:8,floatle:4,floatbe:4,doublele:8,doublebe:8},XR={uint8:"Uint8",uint16le:"Uint16",uint16be:"Uint16",uint32le:"Uint32",uint32be:"Uint32",int8:"Int8",int16le:"Int16",int16be:"Int16",int32le:"Int32",int32be:"Int32",int64be:"BigInt64",int64le:"BigInt64",uint64be:"BigUint64",uint64le:"BigUint64",floatle:"Float32",floatbe:"Float32",doublele:"Float64",doublebe:"Float64"},HR={uint8:!1,uint16le:!0,uint16be:!1,uint32le:!0,uint32be:!1,int8:!1,int16le:!0,int16be:!1,int32le:!0,int32be:!1,int64be:!1,int64le:!0,uint64be:!1,uint64le:!0,floatle:!0,floatbe:!1,doublele:!0,doublebe:!1};class Hg{constructor(){this.varName="",this.type="",this.options={},this.endian="be",this.useContextVariables=!1}static start(){return new Hg}primitiveGenerateN(g,I){const i=XR[g],n=HR[g];I.pushCode(`${I.generateVariable(this.varName)} = dataView.get${i}(offset, ${n});`),I.pushCode(`offset += ${Wo[g]};`)}primitiveN(g,I,i){return this.setNextParser(g,I,i)}useThisEndian(g){return g+this.endian.toLowerCase()}uint8(g,I={}){return this.primitiveN("uint8",g,I)}uint16(g,I={}){return this.primitiveN(this.useThisEndian("uint16"),g,I)}uint16le(g,I={}){return this.primitiveN("uint16le",g,I)}uint16be(g,I={}){return this.primitiveN("uint16be",g,I)}uint32(g,I={}){return this.primitiveN(this.useThisEndian("uint32"),g,I)}uint32le(g,I={}){return this.primitiveN("uint32le",g,I)}uint32be(g,I={}){return this.primitiveN("uint32be",g,I)}int8(g,I={}){return this.primitiveN("int8",g,I)}int16(g,I={}){return this.primitiveN(this.useThisEndian("int16"),g,I)}int16le(g,I={}){return this.primitiveN("int16le",g,I)}int16be(g,I={}){return this.primitiveN("int16be",g,I)}int32(g,I={}){return this.primitiveN(this.useThisEndian("int32"),g,I)}int32le(g,I={}){return this.primitiveN("int32le",g,I)}int32be(g,I={}){return this.primitiveN("int32be",g,I)}bigIntVersionCheck(){if(!DataView.prototype.getBigInt64)throw new Error("BigInt64 is unsupported on this runtime")}int64(g,I={}){return this.bigIntVersionCheck(),this.primitiveN(this.useThisEndian("int64"),g,I)}int64be(g,I={}){return this.bigIntVersionCheck(),this.primitiveN("int64be",g,I)}int64le(g,I={}){return this.bigIntVersionCheck(),this.primitiveN("int64le",g,I)}uint64(g,I={}){return this.bigIntVersionCheck(),this.primitiveN(this.useThisEndian("uint64"),g,I)}uint64be(g,I={}){return this.bigIntVersionCheck(),this.primitiveN("uint64be",g,I)}uint64le(g,I={}){return this.bigIntVersionCheck(),this.primitiveN("uint64le",g,I)}floatle(g,I={}){return this.primitiveN("floatle",g,I)}floatbe(g,I={}){return this.primitiveN("floatbe",g,I)}doublele(g,I={}){return this.primitiveN("doublele",g,I)}doublebe(g,I={}){return this.primitiveN("doublebe",g,I)}bitN(g,I,i){return i.length=g,this.setNextParser("bit",I,i)}bit1(g,I={}){return this.bitN(1,g,I)}bit2(g,I={}){return this.bitN(2,g,I)}bit3(g,I={}){return this.bitN(3,g,I)}bit4(g,I={}){return this.bitN(4,g,I)}bit5(g,I={}){return this.bitN(5,g,I)}bit6(g,I={}){return this.bitN(6,g,I)}bit7(g,I={}){return this.bitN(7,g,I)}bit8(g,I={}){return this.bitN(8,g,I)}bit9(g,I={}){return this.bitN(9,g,I)}bit10(g,I={}){return this.bitN(10,g,I)}bit11(g,I={}){return this.bitN(11,g,I)}bit12(g,I={}){return this.bitN(12,g,I)}bit13(g,I={}){return this.bitN(13,g,I)}bit14(g,I={}){return this.bitN(14,g,I)}bit15(g,I={}){return this.bitN(15,g,I)}bit16(g,I={}){return this.bitN(16,g,I)}bit17(g,I={}){return this.bitN(17,g,I)}bit18(g,I={}){return this.bitN(18,g,I)}bit19(g,I={}){return this.bitN(19,g,I)}bit20(g,I={}){return this.bitN(20,g,I)}bit21(g,I={}){return this.bitN(21,g,I)}bit22(g,I={}){return this.bitN(22,g,I)}bit23(g,I={}){return this.bitN(23,g,I)}bit24(g,I={}){return this.bitN(24,g,I)}bit25(g,I={}){return this.bitN(25,g,I)}bit26(g,I={}){return this.bitN(26,g,I)}bit27(g,I={}){return this.bitN(27,g,I)}bit28(g,I={}){return this.bitN(28,g,I)}bit29(g,I={}){return this.bitN(29,g,I)}bit30(g,I={}){return this.bitN(30,g,I)}bit31(g,I={}){return this.bitN(31,g,I)}bit32(g,I={}){return this.bitN(32,g,I)}namely(g){return Ro.set(g,this),this.alias=g,this}skip(g,I={}){return this.seek(g,I)}seek(g,I={}){if(I.assert)throw new Error("assert option on seek is not allowed.");return this.setNextParser("seek","",{length:g})}string(g,I){if(!I.zeroTerminated&&!I.length&&!I.greedy)throw new Error("One of length, zeroTerminated, or greedy must be defined for string.");if((I.zeroTerminated||I.length)&&I.greedy)throw new Error("greedy is mutually exclusive with length and zeroTerminated for string.");if(I.stripNull&&!(I.length||I.greedy))throw new Error("length or greedy must be defined if stripNull is enabled.");return I.encoding=I.encoding||"utf8",this.setNextParser("string",g,I)}buffer(g,I){if(!I.length&&!I.readUntil)throw new Error("length or readUntil must be defined for buffer.");return this.setNextParser("buffer",g,I)}wrapped(g,I){if(typeof I!="object"&&typeof g=="object"&&(I=g,g=""),!I||!I.wrapper||!I.type)throw new Error("Both wrapper and type must be defined for wrapped.");if(!I.length&&!I.readUntil)throw new Error("length or readUntil must be defined for wrapped.");return this.setNextParser("wrapper",g,I)}array(g,I){if(!I.readUntil&&!I.length&&!I.lengthInBytes)throw new Error("One of readUntil, length and lengthInBytes must be defined for array.");if(!I.type)throw new Error("type is required for array.");if(typeof I.type=="string"&&!Ro.has(I.type)&&!(I.type in Wo))throw new Error(`Array element type "${I.type}" is unkown.`);return this.setNextParser("array",g,I)}choice(g,I){if(typeof I!="object"&&typeof g=="object"&&(I=g,g=""),!I)throw new Error("tag and choices are are required for choice.");if(!I.tag)throw new Error("tag is requird for choice.");if(!I.choices)throw new Error("choices is required for choice.");for(const i in I.choices){const n=parseInt(i,10),C=I.choices[n];if(isNaN(n))throw new Error(`Choice key "${i}" is not a number.`);if(typeof C=="string"&&!Ro.has(C)&&!(C in Wo))throw new Error(`Choice type "${C}" is unkown.`)}return this.setNextParser("choice",g,I)}nest(g,I){if(typeof I!="object"&&typeof g=="object"&&(I=g,g=""),!I||!I.type)throw new Error("type is required for nest.");if(!(I.type instanceof Hg)&&!Ro.has(I.type))throw new Error("type must be a known parser name or a Parser object.");if(!(I.type instanceof Hg)&&!g)throw new Error("type must be a Parser object if the variable name is omitted.");return this.setNextParser("nest",g,I)}pointer(g,I){if(!I.offset)throw new Error("offset is required for pointer.");if(!I.type)throw new Error("type is required for pointer.");if(typeof I.type=="string"&&!(I.type in Wo)&&!Ro.has(I.type))throw new Error(`Pointer type "${I.type}" is unkown.`);return this.setNextParser("pointer",g,I)}saveOffset(g,I={}){return this.setNextParser("saveOffset",g,I)}endianness(g){switch(g.toLowerCase()){case"little":this.endian="le";break;case"big":this.endian="be";break;default:throw new Error('endianness must be one of "little" or "big"')}return this}endianess(g){return this.endianness(g)}useContextVars(g=!0){return this.useContextVariables=g,this}create(g){if(!(g instanceof Function))throw new Error("Constructor must be a Function object.");return this.constructorFn=g,this}getContext(g){const I=new mtg(g,this.useContextVariables);return I.pushCode("var dataView = new DataView(buffer.buffer, buffer.byteOffset, buffer.length);"),this.alias?(this.addAliasedCode(I),I.pushCode(`return ${Ru+this.alias}(0).result;`)):this.addRawCode(I),I}getCode(){const g="imports";return this.getContext(g).code}addRawCode(g){g.pushCode("var offset = 0;"),g.pushCode(`var vars = ${this.constructorFn?"new constructorFn()":"{}"};`),g.pushCode("vars.$parent = null;"),g.pushCode("vars.$root = vars;"),this.generate(g),this.resolveReferences(g),g.pushCode("delete vars.$parent;"),g.pushCode("delete vars.$root;"),g.pushCode("return vars;")}addAliasedCode(g){return g.pushCode(`function ${Ru+this.alias}(offset, context) {`),g.pushCode(`var vars = ${this.constructorFn?"new constructorFn()":"{}"};`),g.pushCode("var ctx = Object.assign({$parent: null, $root: vars}, context || {});"),g.pushCode("vars = Object.assign(vars, ctx);"),this.generate(g),g.markResolved(this.alias),this.resolveReferences(g),g.pushCode("Object.keys(ctx).forEach(function (item) { delete vars[item]; });"),g.pushCode("return { offset: offset, result: vars };"),g.pushCode("}"),g}resolveReferences(g){const I=g.getUnresolvedReferences();g.markRequested(I),I.forEach(i=>{var n;(n=Ro.get(i))===null||n===void 0||n.addAliasedCode(g)})}compile(){const g="imports",I=this.getContext(g);this.compiled=new Function(g,"TextDecoder",`return function (buffer, constructorFn) { ${I.code} };`)(I.imports,TextDecoder)}sizeOf(){let g=NaN;if(Object.keys(Wo).indexOf(this.type)>=0)g=Wo[this.type];else if(this.type==="string"&&typeof this.options.length=="number")g=this.options.length;else if(this.type==="buffer"&&typeof this.options.length=="number")g=this.options.length;else if(this.type==="array"&&typeof this.options.length=="number"){let I=NaN;typeof this.options.type=="string"?I=Wo[this.options.type]:this.options.type instanceof Hg&&(I=this.options.type.sizeOf()),g=this.options.length*I}else this.type==="seek"?g=this.options.length:this.type==="nest"?g=this.options.type.sizeOf():this.type||(g=0);return this.next&&(g+=this.next.sizeOf()),g}parse(g){return this.compiled||this.compile(),this.compiled(g,this.constructorFn)}setNextParser(g,I,i){const n=new Hg;return n.type=g,n.varName=I,n.options=i,n.endian=this.endian,this.head?this.head.next=n:this.next=n,this.head=n,this}generate(g){if(this.type){switch(this.type){case"uint8":case"uint16le":case"uint16be":case"uint32le":case"uint32be":case"int8":case"int16le":case"int16be":case"int32le":case"int32be":case"int64be":case"int64le":case"uint64be":case"uint64le":case"floatle":case"floatbe":case"doublele":case"doublebe":this.primitiveGenerateN(this.type,g);break;case"bit":this.generateBit(g);break;case"string":this.generateString(g);break;case"buffer":this.generateBuffer(g);break;case"seek":this.generateSeek(g);break;case"nest":this.generateNest(g);break;case"array":this.generateArray(g);break;case"choice":this.generateChoice(g);break;case"pointer":this.generatePointer(g);break;case"saveOffset":this.generateSaveOffset(g);break;case"wrapper":this.generateWrapper(g);break}this.type!=="bit"&&this.generateAssert(g)}const I=g.generateVariable(this.varName);return this.options.formatter&&this.type!=="bit"&&this.generateFormatter(g,I,this.options.formatter),this.generateNext(g)}generateAssert(g){if(!this.options.assert)return;const I=g.generateVariable(this.varName);switch(typeof this.options.assert){case"function":{const i=g.addImport(this.options.assert);g.pushCode(`if (!${i}.call(vars, ${I})) {`)}break;case"number":g.pushCode(`if (${this.options.assert} !== ${I}) {`);break;case"string":g.pushCode(`if (${JSON.stringify(this.options.assert)} !== ${I}) {`);break;default:throw new Error("assert option must be a string, number or a function.")}g.generateError(`"Assertion error: ${I} is " + ${JSON.stringify(this.options.assert.toString())}`),g.pushCode("}")}generateNext(g){return this.next&&(g=this.next.generate(g)),g}generateBit(g){const I=JSON.parse(JSON.stringify(this));if(I.options=this.options,I.generateAssert=this.generateAssert.bind(this),I.generateFormatter=this.generateFormatter.bind(this),I.varName=g.generateVariable(I.varName),g.bitFields.push(I),!this.next||this.next&&["bit","nest"].indexOf(this.next.type)<0){const i=g.generateTmpVariable();g.pushCode(`var ${i} = 0;`);const n=(a=0)=>{let l=0;for(let c=a;c32)break;l+=u}return l},C=a=>(a<=8?(g.pushCode(`${i} = dataView.getUint8(offset);`),a=8):a<=16?(g.pushCode(`${i} = dataView.getUint16(offset);`),a=16):a<=24?(g.pushCode(`${i} = (dataView.getUint16(offset) << 8) | dataView.getUint8(offset + 2);`),a=24):(g.pushCode(`${i} = dataView.getUint32(offset);`),a=32),g.pushCode(`offset += ${a/8};`),a);let r=0;const o=this.endian==="be";let A=0,s=0;g.bitFields.forEach((a,l)=>{let c=a.options.length;if(c>s){if(s){const h=-1>>>32-s;g.pushCode(`${a.varName} = (${i} & 0x${h.toString(16)}) << ${c-s};`),c-=s}r=0,s=A=C(n(l)-s)}const u=o?A-r-c:r,d=-1>>>32-c;g.pushCode(`${a.varName} ${c> ${u} & 0x${d.toString(16)};`),a.options.length===32&&g.pushCode(`${a.varName} >>>= 0`),a.options.assert&&a.generateAssert(g),a.options.formatter&&a.generateFormatter(g,a.varName,a.options.formatter),r+=c,s-=c}),g.bitFields=[]}}generateSeek(g){const I=g.generateOption(this.options.length);g.pushCode(`offset += ${I};`)}generateString(g){const I=g.generateVariable(this.varName),i=g.generateTmpVariable(),n=this.options.encoding,C=n.toLowerCase()==="hex",r='b => b.toString(16).padStart(2, "0")';if(this.options.length&&this.options.zeroTerminated){const o=this.options.length;g.pushCode(`var ${i} = offset;`),g.pushCode(`while(dataView.getUint8(offset++) !== 0 && offset - ${i} < ${o});`);const A=`offset - ${i} < ${o} ? offset - 1 : offset`;g.pushCode(C?`${I} = Array.from(buffer.subarray(${i}, ${A}), ${r}).join('');`:`${I} = new TextDecoder('${n}').decode(buffer.subarray(${i}, ${A}));`)}else if(this.options.length){const o=g.generateOption(this.options.length);g.pushCode(C?`${I} = Array.from(buffer.subarray(offset, offset + ${o}), ${r}).join('');`:`${I} = new TextDecoder('${n}').decode(buffer.subarray(offset, offset + ${o}));`),g.pushCode(`offset += ${o};`)}else this.options.zeroTerminated?(g.pushCode(`var ${i} = offset;`),g.pushCode("while(dataView.getUint8(offset++) !== 0);"),g.pushCode(C?`${I} = Array.from(buffer.subarray(${i}, offset - 1), ${r}).join('');`:`${I} = new TextDecoder('${n}').decode(buffer.subarray(${i}, offset - 1));`)):this.options.greedy&&(g.pushCode(`var ${i} = offset;`),g.pushCode("while(buffer.length > offset++);"),g.pushCode(C?`${I} = Array.from(buffer.subarray(${i}, offset), ${r}).join('');`:`${I} = new TextDecoder('${n}').decode(buffer.subarray(${i}, offset));`));this.options.stripNull&&g.pushCode(`${I} = ${I}.replace(/\\x00+$/g, '')`)}generateBuffer(g){const I=g.generateVariable(this.varName);if(typeof this.options.readUntil=="function"){const i=this.options.readUntil,n=g.generateTmpVariable(),C=g.generateTmpVariable();g.pushCode(`var ${n} = offset;`),g.pushCode(`var ${C} = 0;`),g.pushCode("while (offset < buffer.length) {"),g.pushCode(`${C} = dataView.getUint8(offset);`);const r=g.addImport(i);g.pushCode(`if (${r}.call(${g.generateVariable()}, ${C}, buffer.subarray(offset))) break;`),g.pushCode("offset += 1;"),g.pushCode("}"),g.pushCode(`${I} = buffer.subarray(${n}, offset);`)}else if(this.options.readUntil==="eof")g.pushCode(`${I} = buffer.subarray(offset);`);else{const i=g.generateOption(this.options.length);g.pushCode(`${I} = buffer.subarray(offset, offset + ${i});`),g.pushCode(`offset += ${i};`)}this.options.clone&&g.pushCode(`${I} = buffer.constructor.from(${I});`)}generateArray(g){const I=g.generateOption(this.options.length),i=g.generateOption(this.options.lengthInBytes),n=this.options.type,C=g.generateTmpVariable(),r=g.generateVariable(this.varName),o=g.generateTmpVariable(),A=this.options.key,s=typeof A=="string";if(s?g.pushCode(`${r} = {};`):g.pushCode(`${r} = [];`),typeof this.options.readUntil=="function"?g.pushCode("do {"):this.options.readUntil==="eof"?g.pushCode(`for (var ${C} = 0; offset < buffer.length; ${C}++) {`):i!==void 0?g.pushCode(`for (var ${C} = offset + ${i}; offset < ${C}; ) {`):g.pushCode(`for (var ${C} = ${I}; ${C} > 0; ${C}--) {`),typeof n=="string")if(Ro.get(n)){const a=g.generateTmpVariable();if(g.pushCode(`var ${a} = ${Ru+n}(offset, {`),g.useContextVariables){const l=g.generateVariable();g.pushCode(`$parent: ${l},`),g.pushCode(`$root: ${l}.$root,`),!this.options.readUntil&&i===void 0&&g.pushCode(`$index: ${I} - ${C},`)}g.pushCode("});"),g.pushCode(`var ${o} = ${a}.result; offset = ${a}.offset;`),n!==this.alias&&g.addReference(n)}else{const a=XR[n],l=HR[n];g.pushCode(`var ${o} = dataView.get${a}(offset, ${l});`),g.pushCode(`offset += ${Wo[n]};`)}else if(n instanceof Hg){g.pushCode(`var ${o} = {};`);const a=g.generateVariable();g.pushScope(o),g.useContextVariables&&(g.pushCode(`${o}.$parent = ${a};`),g.pushCode(`${o}.$root = ${a}.$root;`),!this.options.readUntil&&i===void 0&&g.pushCode(`${o}.$index = ${I} - ${C};`)),n.generate(g),g.useContextVariables&&(g.pushCode(`delete ${o}.$parent;`),g.pushCode(`delete ${o}.$root;`),g.pushCode(`delete ${o}.$index;`)),g.popScope()}if(s?g.pushCode(`${r}[${o}.${A}] = ${o};`):g.pushCode(`${r}.push(${o});`),g.pushCode("}"),typeof this.options.readUntil=="function"){const a=this.options.readUntil,l=g.addImport(a);g.pushCode(`while (!${l}.call(${g.generateVariable()}, ${o}, buffer.subarray(offset)));`)}}generateChoiceCase(g,I,i){if(typeof i=="string"){const n=g.generateVariable(this.varName);if(Ro.has(i)){const C=g.generateTmpVariable();g.pushCode(`var ${C} = ${Ru+i}(offset, {`),g.useContextVariables&&(g.pushCode(`$parent: ${n}.$parent,`),g.pushCode(`$root: ${n}.$root,`)),g.pushCode("});"),g.pushCode(`${n} = ${C}.result; offset = ${C}.offset;`),i!==this.alias&&g.addReference(i)}else{const C=XR[i],r=HR[i];g.pushCode(`${n} = dataView.get${C}(offset, ${r});`),g.pushCode(`offset += ${Wo[i]}`)}}else i instanceof Hg&&(g.pushPath(I),i.generate(g),g.popPath(I))}generateChoice(g){const I=g.generateOption(this.options.tag),i=g.generateVariable(this.varName);if(this.varName&&(g.pushCode(`${i} = {};`),g.useContextVariables)){const n=g.generateVariable();g.pushCode(`${i}.$parent = ${n};`),g.pushCode(`${i}.$root = ${n}.$root;`)}g.pushCode(`switch(${I}) {`);for(const n in this.options.choices){const C=parseInt(n,10),r=this.options.choices[C];g.pushCode(`case ${C}:`),this.generateChoiceCase(g,this.varName,r),g.pushCode("break;")}g.pushCode("default:"),this.options.defaultChoice?this.generateChoiceCase(g,this.varName,this.options.defaultChoice):g.generateError(`"Met undefined tag value " + ${I} + " at choice"`),g.pushCode("}"),this.varName&&g.useContextVariables&&(g.pushCode(`delete ${i}.$parent;`),g.pushCode(`delete ${i}.$root;`))}generateNest(g){const I=g.generateVariable(this.varName);if(this.options.type instanceof Hg){if(this.varName&&(g.pushCode(`${I} = {};`),g.useContextVariables)){const i=g.generateVariable();g.pushCode(`${I}.$parent = ${i};`),g.pushCode(`${I}.$root = ${i}.$root;`)}g.pushPath(this.varName),this.options.type.generate(g),g.popPath(this.varName),this.varName&&g.useContextVariables&&g.useContextVariables&&(g.pushCode(`delete ${I}.$parent;`),g.pushCode(`delete ${I}.$root;`))}else if(Ro.has(this.options.type)){const i=g.generateTmpVariable();if(g.pushCode(`var ${i} = ${Ru+this.options.type}(offset, {`),g.useContextVariables){const n=g.generateVariable();g.pushCode(`$parent: ${n},`),g.pushCode(`$root: ${n}.$root,`)}g.pushCode("});"),g.pushCode(`${I} = ${i}.result; offset = ${i}.offset;`),this.options.type!==this.alias&&g.addReference(this.options.type)}}generateWrapper(g){const I=g.generateVariable(this.varName),i=g.generateTmpVariable();if(typeof this.options.readUntil=="function"){const A=this.options.readUntil,s=g.generateTmpVariable(),a=g.generateTmpVariable();g.pushCode(`var ${s} = offset;`),g.pushCode(`var ${a} = 0;`),g.pushCode("while (offset < buffer.length) {"),g.pushCode(`${a} = dataView.getUint8(offset);`);const l=g.addImport(A);g.pushCode(`if (${l}.call(${g.generateVariable()}, ${a}, buffer.subarray(offset))) break;`),g.pushCode("offset += 1;"),g.pushCode("}"),g.pushCode(`${i} = buffer.subarray(${s}, offset);`)}else if(this.options.readUntil==="eof")g.pushCode(`${i} = buffer.subarray(offset);`);else{const A=g.generateOption(this.options.length);g.pushCode(`${i} = buffer.subarray(offset, offset + ${A});`),g.pushCode(`offset += ${A};`)}this.options.clone&&g.pushCode(`${i} = buffer.constructor.from(${i});`);const n=g.generateTmpVariable(),C=g.generateTmpVariable(),r=g.generateTmpVariable(),o=g.addImport(this.options.wrapper);if(g.pushCode(`${i} = ${o}.call(this, ${i}).subarray(0);`),g.pushCode(`var ${n} = buffer;`),g.pushCode(`var ${C} = offset;`),g.pushCode(`var ${r} = dataView;`),g.pushCode(`buffer = ${i};`),g.pushCode("offset = 0;"),g.pushCode("dataView = new DataView(buffer.buffer, buffer.byteOffset, buffer.length);"),this.options.type instanceof Hg)this.varName&&g.pushCode(`${I} = {};`),g.pushPath(this.varName),this.options.type.generate(g),g.popPath(this.varName);else if(Ro.has(this.options.type)){const A=g.generateTmpVariable();g.pushCode(`var ${A} = ${Ru+this.options.type}(0);`),g.pushCode(`${I} = ${A}.result;`),this.options.type!==this.alias&&g.addReference(this.options.type)}g.pushCode(`buffer = ${n};`),g.pushCode(`dataView = ${r};`),g.pushCode(`offset = ${C};`)}generateFormatter(g,I,i){if(typeof i=="function"){const n=g.addImport(i);g.pushCode(`${I} = ${n}.call(${g.generateVariable()}, ${I});`)}}generatePointer(g){const I=this.options.type,i=g.generateOption(this.options.offset),n=g.generateTmpVariable(),C=g.generateVariable(this.varName);if(g.pushCode(`var ${n} = offset;`),g.pushCode(`offset = ${i};`),this.options.type instanceof Hg){if(g.pushCode(`${C} = {};`),g.useContextVariables){const r=g.generateVariable();g.pushCode(`${C}.$parent = ${r};`),g.pushCode(`${C}.$root = ${r}.$root;`)}g.pushPath(this.varName),this.options.type.generate(g),g.popPath(this.varName),g.useContextVariables&&(g.pushCode(`delete ${C}.$parent;`),g.pushCode(`delete ${C}.$root;`))}else if(Ro.has(this.options.type)){const r=g.generateTmpVariable();if(g.pushCode(`var ${r} = ${Ru+this.options.type}(offset, {`),g.useContextVariables){const o=g.generateVariable();g.pushCode(`$parent: ${o},`),g.pushCode(`$root: ${o}.$root,`)}g.pushCode("});"),g.pushCode(`${C} = ${r}.result; offset = ${r}.offset;`),this.options.type!==this.alias&&g.addReference(this.options.type)}else if(Object.keys(Wo).indexOf(this.options.type)>=0){const r=XR[I],o=HR[I];g.pushCode(`${C} = dataView.get${r}(offset, ${o});`),g.pushCode(`offset += ${Wo[I]};`)}g.pushCode(`offset = ${n};`)}generateSaveOffset(g){const I=g.generateVariable(this.varName);g.pushCode(`${I} = offset`)}}var s9e={},U4={},wh={},dw={};Object.defineProperty(dw,"__esModule",{value:!0});function Q4(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function bse(e,g){for(var I=0;I"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function tG(e){if(e===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function btg(e,g){if(g&&(typeof g=="object"||typeof g=="function"))return g;if(g!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return tG(e)}function ytg(e){var g=ptg();return function(){var i=n0(e),n;if(g){var C=n0(this).constructor;n=Reflect.construct(i,arguments,C)}else n=i.apply(this,arguments);return btg(this,n)}}function Ztg(e,g){for(;!Object.prototype.hasOwnProperty.call(e,g)&&(e=n0(e),e!==null););return e}function uW(){return typeof Reflect<"u"&&Reflect.get?uW=Reflect.get.bind():uW=function(g,I,i){var n=Ztg(g,I);if(n){var C=Object.getOwnPropertyDescriptor(n,I);return C.get?C.get.call(arguments.length<3?g:i):C.value}},uW.apply(this,arguments)}var yse=function(){function e(){Q4(this,e),Object.defineProperty(this,"listeners",{value:{},writable:!0,configurable:!0})}return j4(e,[{key:"addEventListener",value:function(I,i,n){I in this.listeners||(this.listeners[I]=[]),this.listeners[I].push({callback:i,options:n})}},{key:"removeEventListener",value:function(I,i){if(I in this.listeners){for(var n=this.listeners[I],C=0,r=n.length;C"u")n=new Error("This operation was aborted"),n.name="AbortError";else try{n=new DOMException("signal is aborted without reason")}catch{n=new Error("This operation was aborted"),n.name="AbortError"}this.signal.reason=n,this.signal.dispatchEvent(i)}},{key:"toString",value:function(){return"[object AbortController]"}}]),e}();typeof Symbol<"u"&&Symbol.toStringTag&&(l9e.prototype[Symbol.toStringTag]="AbortController",$4.prototype[Symbol.toStringTag]="AbortSignal");function Gtg(e){return e.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL?(console.log("__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL=true is set, will force install polyfill"),!0):typeof e.Request=="function"&&!e.Request.prototype.hasOwnProperty("signal")||!e.AbortController}function vtg(e){typeof e=="function"&&(e={fetch:e});var g=e,I=g.fetch,i=g.Request,n=i===void 0?I.Request:i,C=g.AbortController,r=g.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL,o=r===void 0?!1:r;if(!Gtg({fetch:I,Request:n,AbortController:C,__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL:o}))return{fetch:I,Request:A};var A=n;(A&&!A.prototype.hasOwnProperty("signal")||o)&&(A=function(c,u){var d;u&&u.signal&&(d=u.signal,delete u.signal);var h=new n(c,u);return d&&Object.defineProperty(h,"signal",{writable:!1,enumerable:!1,configurable:!0,value:d}),h},A.prototype=n.prototype);var s=I,a=function(c,u){var d=A&&A.prototype.isPrototypeOf(c)?c.signal:u?u.signal:void 0;if(d){var h;try{h=new DOMException("Aborted","AbortError")}catch{h=new Error("Aborted"),h.name="AbortError"}if(d.aborted)return Promise.reject(h);var m=new Promise(function(f,b){d.addEventListener("abort",function(){return b(h)},{once:!0})});return u&&u.signal&&delete u.signal,Promise.race([m,s(c,u)])}return s(c,u)};return{fetch:a,Request:A}}dw.AbortController=l9e;dw.AbortSignal=$4;dw.abortableFetch=vtg;Object.defineProperty(wh,"__esModule",{value:!0});wh.AbortSignal=wh.AbortController=void 0;const c9e=dw;var CH=function(){if(typeof self<"u")return self;if(typeof window<"u")return window;if(typeof Od<"u")return Od;throw new Error("unable to locate global object")};let Btg=typeof CH().AbortController>"u"?c9e.AbortController:CH().AbortController;wh.AbortController=Btg;let Stg=typeof CH().AbortController>"u"?c9e.AbortSignal:CH().AbortSignal;wh.AbortSignal=Stg;var q4={};Object.defineProperty(q4,"__esModule",{value:!0});const wtg=wh;class Vtg{}class Rtg{constructor(){this.signals=new Set,this.abortController=new wtg.AbortController}addSignal(g=new Vtg){if(this.signal.aborted)throw new Error("cannot add a signal, already aborted!");this.signals.add(g),g.aborted?this.handleAborted(g):typeof g.addEventListener=="function"&&g.addEventListener("abort",()=>{this.handleAborted(g)})}handleAborted(g){this.signals.delete(g),this.signals.size===0&&this.abortController.abort()}get signal(){return this.abortController.signal}abort(){this.abortController.abort()}}q4.default=Rtg;var e$={};Object.defineProperty(e$,"__esModule",{value:!0});class Wtg{constructor(){this.callbacks=new Set}addCallback(g=()=>{}){this.callbacks.add(g),g(this.currentMessage)}callback(g){this.currentMessage=g,this.callbacks.forEach(I=>{I(g)})}}e$.default=Wtg;var u9e=Od&&Od.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(U4,"__esModule",{value:!0});const Xtg=wh,Htg=u9e(q4),Ttg=u9e(e$);class rH{constructor({fill:g,cache:I}){if(typeof g!="function")throw new TypeError("must pass a fill function");if(typeof I!="object")throw new TypeError("must pass a cache object");if(typeof I.get!="function"||typeof I.set!="function"||typeof I.delete!="function")throw new TypeError("cache must implement get(key), set(key, val), and and delete(key)");this.cache=I,this.fillCallback=g}static isAbortException(g){return g.name==="AbortError"||g.code==="ERR_ABORTED"||g.message==="AbortError: aborted"||g.message==="Error: aborted"}evict(g,I){this.cache.get(g)===I&&this.cache.delete(g)}fill(g,I,i,n){const C=new Htg.default,r=new Ttg.default;r.addCallback(n);const o={aborter:C,promise:this.fillCallback(I,C.signal,A=>{r.callback(A)}),settled:!1,statusReporter:r,get aborted(){return this.aborter.signal.aborted}};o.aborter.addSignal(i),o.aborter.signal.addEventListener("abort",()=>{o.settled||this.evict(g,o)}),o.promise.then(()=>{o.settled=!0},()=>{o.settled=!0,this.evict(g,o)}).catch(A=>{throw console.error(A),A}),this.cache.set(g,o)}static checkSinglePromise(g,I){function i(){if(I&&I.aborted)throw Object.assign(new Error("aborted"),{code:"ERR_ABORTED"})}return g.then(n=>(i(),n),n=>{throw i(),n})}has(g){return this.cache.has(g)}get(g,I,i,n){if(!i&&I instanceof Xtg.AbortSignal)throw new TypeError("second get argument appears to be an AbortSignal, perhaps you meant to pass `null` for the fill data?");const C=this.cache.get(g);return C?C.aborted&&!C.settled?(this.evict(g,C),this.get(g,I,i,n)):C.settled?C.promise:(C.aborter.addSignal(i),C.statusReporter.addCallback(n),rH.checkSinglePromise(C.promise,i)):(this.fill(g,I,i,n),rH.checkSinglePromise(this.cache.get(g).promise,i))}delete(g){const I=this.cache.get(g);I&&(I.settled||I.aborter.abort(),this.cache.delete(g))}clear(){const g=this.cache.keys();let I=0;for(let i=g.next();!i.done;i=g.next())this.delete(i.value),I+=1;return I}}U4.default=rH;var Ntg=Od&&Od.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(s9e,"__esModule",{value:!0});const ktg=Ntg(U4);var Ytg=s9e.default=ktg.default;class jl{constructor(g,I){this.ranges=arguments.length===2?[{min:g,max:I}]:0 in g?Object.assign({},g):[g]}min(){return this.ranges[0].min}max(){return this.ranges[this.ranges.length-1].max}contains(g){for(let I=0;I=g)return!0}return!1}isContiguous(){return this.ranges.length>1}getRanges(){return this.ranges.map(g=>new jl(g.min,g.max))}toString(){return this.ranges.map(g=>`[${g.min}-${g.max}]`).join(",")}union(g){const I=this.getRanges().concat(g.getRanges()).sort(this.rangeOrder),i=[];let n=I[0];for(let C=1;Cn.max()+1?(i.push(n),n=r):r.max()>n.max()&&(n=new jl(n.min(),r.max()))}return i.push(n),i.length===1?i[0]:new jl(i)}intersection(g){let I=this,i=g;const n=this.ranges(),C=i.ranges(),r=n.length,o=C.length;let A=0,s=0;const a=[];for(;A=l&&a.push(new jl(l,c)),I.max()>i.max()?s+=1:A+=1}if(a.length===0)throw new Error("found range of length 0");return a.length===1?a[0]:new jl(a)}coverage(){let g=0;const I=this.ranges();for(let i=0;in.min()?1:i.max()i.max()?1:0}}function Iy(e){let g=e.length;for(;--g>=0;)e[g]=0}const Ktg=3,Dtg=258,d9e=29,xtg=256,Ftg=xtg+1+d9e,h9e=30,Etg=512,Mtg=new Array((Ftg+2)*2);Iy(Mtg);const ztg=new Array(h9e*2);Iy(ztg);const Ptg=new Array(Etg);Iy(Ptg);const Jtg=new Array(Dtg-Ktg+1);Iy(Jtg);const Otg=new Array(d9e);Iy(Otg);const _tg=new Array(h9e);Iy(_tg);const Ltg=(e,g,I,i)=>{let n=e&65535|0,C=e>>>16&65535|0,r=0;for(;I!==0;){r=I>2e3?2e3:I,I-=r;do n=n+g[i++]|0,C=C+n|0;while(--r);n%=65521,C%=65521}return n|C<<16|0};var hO=Ltg;const Utg=()=>{let e,g=[];for(var I=0;I<256;I++){e=I;for(var i=0;i<8;i++)e=e&1?3988292384^e>>>1:e>>>1;g[I]=e}return g},Qtg=new Uint32Array(Utg()),jtg=(e,g,I,i)=>{const n=Qtg,C=i+I;e^=-1;for(let r=i;r>>8^n[(e^g[r])&255];return e^-1};var VA=jtg,mO={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"},t$={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8};const $tg=(e,g)=>Object.prototype.hasOwnProperty.call(e,g);var qtg=function(e){const g=Array.prototype.slice.call(arguments,1);for(;g.length;){const I=g.shift();if(I){if(typeof I!="object")throw new TypeError(I+"must be non-object");for(const i in I)$tg(I,i)&&(e[i]=I[i])}}return e},egg=e=>{let g=0;for(let i=0,n=e.length;i=252?6:e>=248?5:e>=240?4:e>=224?3:e>=192?2:1;zB[254]=zB[254]=1;var tgg=e=>{if(typeof TextEncoder=="function"&&TextEncoder.prototype.encode)return new TextEncoder().encode(e);let g,I,i,n,C,r=e.length,o=0;for(n=0;n>>6,g[C++]=128|I&63):I<65536?(g[C++]=224|I>>>12,g[C++]=128|I>>>6&63,g[C++]=128|I&63):(g[C++]=240|I>>>18,g[C++]=128|I>>>12&63,g[C++]=128|I>>>6&63,g[C++]=128|I&63);return g};const ggg=(e,g)=>{if(g<65534&&e.subarray&&f9e)return String.fromCharCode.apply(null,e.length===g?e:e.subarray(0,g));let I="";for(let i=0;i{const I=g||e.length;if(typeof TextDecoder=="function"&&TextDecoder.prototype.decode)return new TextDecoder().decode(e.subarray(0,g));let i,n;const C=new Array(I*2);for(n=0,i=0;i4){C[n++]=65533,i+=o-1;continue}for(r&=o===2?31:o===3?15:7;o>1&&i1){C[n++]=65533;continue}r<65536?C[n++]=r:(r-=65536,C[n++]=55296|r>>10&1023,C[n++]=56320|r&1023)}return ggg(C,n)},igg=(e,g)=>{g=g||e.length,g>e.length&&(g=e.length);let I=g-1;for(;I>=0&&(e[I]&192)===128;)I--;return I<0||I===0?g:I+zB[e[I]]>g?I:g},fO={string2buf:tgg,buf2string:Igg,utf8border:igg};function ngg(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0}var Cgg=ngg;const TR=16209,rgg=16191;var ogg=function(g,I){let i,n,C,r,o,A,s,a,l,c,u,d,h,m,f,b,p,y,Z,B,G,v,w,V;const S=g.state;i=g.next_in,w=g.input,n=i+(g.avail_in-5),C=g.next_out,V=g.output,r=C-(I-g.avail_out),o=C+(g.avail_out-257),A=S.dmax,s=S.wsize,a=S.whave,l=S.wnext,c=S.window,u=S.hold,d=S.bits,h=S.lencode,m=S.distcode,f=(1<>>24,u>>>=y,d-=y,y=p>>>16&255,y===0)V[C++]=p&65535;else if(y&16){Z=p&65535,y&=15,y&&(d>>=y,d-=y),d<15&&(u+=w[i++]<>>24,u>>>=y,d-=y,y=p>>>16&255,y&16){if(B=p&65535,y&=15,dA){g.msg="invalid distance too far back",S.mode=TR;break e}if(u>>>=y,d-=y,y=C-r,B>y){if(y=B-y,y>a&&S.sane){g.msg="invalid distance too far back",S.mode=TR;break e}if(G=0,v=c,l===0){if(G+=s-y,y2;)V[C++]=v[G++],V[C++]=v[G++],V[C++]=v[G++],Z-=3;Z&&(V[C++]=v[G++],Z>1&&(V[C++]=v[G++]))}else{G=C-B;do V[C++]=V[G++],V[C++]=V[G++],V[C++]=V[G++],Z-=3;while(Z>2);Z&&(V[C++]=V[G++],Z>1&&(V[C++]=V[G++]))}}else if(y&64){g.msg="invalid distance code",S.mode=TR;break e}else{p=m[(p&65535)+(u&(1<>3,i-=Z,d-=Z<<3,u&=(1<{const A=o.bits;let s=0,a=0,l=0,c=0,u=0,d=0,h=0,m=0,f=0,b=0,p,y,Z,B,G,v=null,w;const V=new Uint16Array(jm+1),S=new Uint16Array(jm+1);let X=null,W,R,H;for(s=0;s<=jm;s++)V[s]=0;for(a=0;a=1&&V[c]===0;c--);if(u>c&&(u=c),c===0)return n[C++]=1<<24|64<<16|0,n[C++]=1<<24|64<<16|0,o.bits=1,0;for(l=1;l0&&(e===vse||c!==1))return-1;for(S[1]=0,s=1;sZse||e===Bse&&f>Gse)return 1;for(;;){W=s-h,r[a]+1=w?(R=X[r[a]-w],H=v[r[a]-w]):(R=32+64,H=0),p=1<>h)+y]=W<<24|R<<16|H|0;while(y!==0);for(p=1<>=1;if(p!==0?(b&=p-1,b+=p):b=0,a++,--V[s]===0){if(s===c)break;s=g[I+r[a]]}if(s>u&&(b&B)!==Z){for(h===0&&(h=u),G+=l,d=s-h,m=1<Zse||e===Bse&&f>Gse)return 1;Z=b&B,n[Z]=u<<24|d<<16|G-C|0}}return b!==0&&(n[G+b]=s-h<<24|64<<16|0),o.bits=u,0};var fv=cgg;const ugg=0,p9e=1,b9e=2,{Z_FINISH:Sse,Z_BLOCK:dgg,Z_TREES:NR,Z_OK:Vh,Z_STREAM_END:hgg,Z_NEED_DICT:mgg,Z_STREAM_ERROR:io,Z_DATA_ERROR:y9e,Z_MEM_ERROR:Z9e,Z_BUF_ERROR:fgg,Z_DEFLATED:wse}=t$,Rk=16180,Vse=16181,Rse=16182,Wse=16183,Xse=16184,Hse=16185,Tse=16186,Nse=16187,kse=16188,Yse=16189,oH=16190,Fa=16191,Mx=16192,Kse=16193,zx=16194,Dse=16195,xse=16196,Fse=16197,Ese=16198,kR=16199,YR=16200,Mse=16201,zse=16202,Pse=16203,Jse=16204,Ose=16205,Px=16206,_se=16207,Lse=16208,GI=16209,G9e=16210,v9e=16211,pgg=852,bgg=592,ygg=15,Zgg=ygg,Use=e=>(e>>>24&255)+(e>>>8&65280)+((e&65280)<<8)+((e&255)<<24);function Ggg(){this.strm=null,this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Uint16Array(320),this.work=new Uint16Array(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}const cm=e=>{if(!e)return 1;const g=e.state;return!g||g.strm!==e||g.modev9e?1:0},B9e=e=>{if(cm(e))return io;const g=e.state;return e.total_in=e.total_out=g.total=0,e.msg="",g.wrap&&(e.adler=g.wrap&1),g.mode=Rk,g.last=0,g.havedict=0,g.flags=-1,g.dmax=32768,g.head=null,g.hold=0,g.bits=0,g.lencode=g.lendyn=new Int32Array(pgg),g.distcode=g.distdyn=new Int32Array(bgg),g.sane=1,g.back=-1,Vh},S9e=e=>{if(cm(e))return io;const g=e.state;return g.wsize=0,g.whave=0,g.wnext=0,B9e(e)},w9e=(e,g)=>{let I;if(cm(e))return io;const i=e.state;return g<0?(I=0,g=-g):(I=(g>>4)+5,g<48&&(g&=15)),g&&(g<8||g>15)?io:(i.window!==null&&i.wbits!==g&&(i.window=null),i.wrap=I,i.wbits=g,S9e(e))},V9e=(e,g)=>{if(!e)return io;const I=new Ggg;e.state=I,I.strm=e,I.window=null,I.mode=Rk;const i=w9e(e,g);return i!==Vh&&(e.state=null),i},vgg=e=>V9e(e,Zgg);let Qse=!0,Jx,Ox;const Bgg=e=>{if(Qse){Jx=new Int32Array(512),Ox=new Int32Array(32);let g=0;for(;g<144;)e.lens[g++]=8;for(;g<256;)e.lens[g++]=9;for(;g<280;)e.lens[g++]=7;for(;g<288;)e.lens[g++]=8;for(fv(p9e,e.lens,0,288,Jx,0,e.work,{bits:9}),g=0;g<32;)e.lens[g++]=5;fv(b9e,e.lens,0,32,Ox,0,e.work,{bits:5}),Qse=!1}e.lencode=Jx,e.lenbits=9,e.distcode=Ox,e.distbits=5},R9e=(e,g,I,i)=>{let n;const C=e.state;return C.window===null&&(C.wsize=1<=C.wsize?(C.window.set(g.subarray(I-C.wsize,I),0),C.wnext=0,C.whave=C.wsize):(n=C.wsize-C.wnext,n>i&&(n=i),C.window.set(g.subarray(I-i,I-i+n),C.wnext),i-=n,i?(C.window.set(g.subarray(I-i,I),0),C.wnext=i,C.whave=C.wsize):(C.wnext+=n,C.wnext===C.wsize&&(C.wnext=0),C.whave{let I,i,n,C,r,o,A,s,a,l,c,u,d,h,m=0,f,b,p,y,Z,B,G,v;const w=new Uint8Array(4);let V,S;const X=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);if(cm(e)||!e.output||!e.input&&e.avail_in!==0)return io;I=e.state,I.mode===Fa&&(I.mode=Mx),r=e.next_out,n=e.output,A=e.avail_out,C=e.next_in,i=e.input,o=e.avail_in,s=I.hold,a=I.bits,l=o,c=A,v=Vh;e:for(;;)switch(I.mode){case Rk:if(I.wrap===0){I.mode=Mx;break}for(;a<16;){if(o===0)break e;o--,s+=i[C++]<>>8&255,I.check=VA(I.check,w,2,0),s=0,a=0,I.mode=Vse;break}if(I.head&&(I.head.done=!1),!(I.wrap&1)||(((s&255)<<8)+(s>>8))%31){e.msg="incorrect header check",I.mode=GI;break}if((s&15)!==wse){e.msg="unknown compression method",I.mode=GI;break}if(s>>>=4,a-=4,G=(s&15)+8,I.wbits===0&&(I.wbits=G),G>15||G>I.wbits){e.msg="invalid window size",I.mode=GI;break}I.dmax=1<>8&1),I.flags&512&&I.wrap&4&&(w[0]=s&255,w[1]=s>>>8&255,I.check=VA(I.check,w,2,0)),s=0,a=0,I.mode=Rse;case Rse:for(;a<32;){if(o===0)break e;o--,s+=i[C++]<>>8&255,w[2]=s>>>16&255,w[3]=s>>>24&255,I.check=VA(I.check,w,4,0)),s=0,a=0,I.mode=Wse;case Wse:for(;a<16;){if(o===0)break e;o--,s+=i[C++]<>8),I.flags&512&&I.wrap&4&&(w[0]=s&255,w[1]=s>>>8&255,I.check=VA(I.check,w,2,0)),s=0,a=0,I.mode=Xse;case Xse:if(I.flags&1024){for(;a<16;){if(o===0)break e;o--,s+=i[C++]<>>8&255,I.check=VA(I.check,w,2,0)),s=0,a=0}else I.head&&(I.head.extra=null);I.mode=Hse;case Hse:if(I.flags&1024&&(u=I.length,u>o&&(u=o),u&&(I.head&&(G=I.head.extra_len-I.length,I.head.extra||(I.head.extra=new Uint8Array(I.head.extra_len)),I.head.extra.set(i.subarray(C,C+u),G)),I.flags&512&&I.wrap&4&&(I.check=VA(I.check,i,u,C)),o-=u,C+=u,I.length-=u),I.length))break e;I.length=0,I.mode=Tse;case Tse:if(I.flags&2048){if(o===0)break e;u=0;do G=i[C+u++],I.head&&G&&I.length<65536&&(I.head.name+=String.fromCharCode(G));while(G&&u>9&1,I.head.done=!0),e.adler=I.check=0,I.mode=Fa;break;case Yse:for(;a<32;){if(o===0)break e;o--,s+=i[C++]<>>=a&7,a-=a&7,I.mode=Px;break}for(;a<3;){if(o===0)break e;o--,s+=i[C++]<>>=1,a-=1,s&3){case 0:I.mode=Kse;break;case 1:if(Bgg(I),I.mode=kR,g===NR){s>>>=2,a-=2;break e}break;case 2:I.mode=xse;break;case 3:e.msg="invalid block type",I.mode=GI}s>>>=2,a-=2;break;case Kse:for(s>>>=a&7,a-=a&7;a<32;){if(o===0)break e;o--,s+=i[C++]<>>16^65535)){e.msg="invalid stored block lengths",I.mode=GI;break}if(I.length=s&65535,s=0,a=0,I.mode=zx,g===NR)break e;case zx:I.mode=Dse;case Dse:if(u=I.length,u){if(u>o&&(u=o),u>A&&(u=A),u===0)break e;n.set(i.subarray(C,C+u),r),o-=u,C+=u,A-=u,r+=u,I.length-=u;break}I.mode=Fa;break;case xse:for(;a<14;){if(o===0)break e;o--,s+=i[C++]<>>=5,a-=5,I.ndist=(s&31)+1,s>>>=5,a-=5,I.ncode=(s&15)+4,s>>>=4,a-=4,I.nlen>286||I.ndist>30){e.msg="too many length or distance symbols",I.mode=GI;break}I.have=0,I.mode=Fse;case Fse:for(;I.have>>=3,a-=3}for(;I.have<19;)I.lens[X[I.have++]]=0;if(I.lencode=I.lendyn,I.lenbits=7,V={bits:I.lenbits},v=fv(ugg,I.lens,0,19,I.lencode,0,I.work,V),I.lenbits=V.bits,v){e.msg="invalid code lengths set",I.mode=GI;break}I.have=0,I.mode=Ese;case Ese:for(;I.have>>24,b=m>>>16&255,p=m&65535,!(f<=a);){if(o===0)break e;o--,s+=i[C++]<>>=f,a-=f,I.lens[I.have++]=p;else{if(p===16){for(S=f+2;a>>=f,a-=f,I.have===0){e.msg="invalid bit length repeat",I.mode=GI;break}G=I.lens[I.have-1],u=3+(s&3),s>>>=2,a-=2}else if(p===17){for(S=f+3;a>>=f,a-=f,G=0,u=3+(s&7),s>>>=3,a-=3}else{for(S=f+7;a>>=f,a-=f,G=0,u=11+(s&127),s>>>=7,a-=7}if(I.have+u>I.nlen+I.ndist){e.msg="invalid bit length repeat",I.mode=GI;break}for(;u--;)I.lens[I.have++]=G}}if(I.mode===GI)break;if(I.lens[256]===0){e.msg="invalid code -- missing end-of-block",I.mode=GI;break}if(I.lenbits=9,V={bits:I.lenbits},v=fv(p9e,I.lens,0,I.nlen,I.lencode,0,I.work,V),I.lenbits=V.bits,v){e.msg="invalid literal/lengths set",I.mode=GI;break}if(I.distbits=6,I.distcode=I.distdyn,V={bits:I.distbits},v=fv(b9e,I.lens,I.nlen,I.ndist,I.distcode,0,I.work,V),I.distbits=V.bits,v){e.msg="invalid distances set",I.mode=GI;break}if(I.mode=kR,g===NR)break e;case kR:I.mode=YR;case YR:if(o>=6&&A>=258){e.next_out=r,e.avail_out=A,e.next_in=C,e.avail_in=o,I.hold=s,I.bits=a,ogg(e,c),r=e.next_out,n=e.output,A=e.avail_out,C=e.next_in,i=e.input,o=e.avail_in,s=I.hold,a=I.bits,I.mode===Fa&&(I.back=-1);break}for(I.back=0;m=I.lencode[s&(1<>>24,b=m>>>16&255,p=m&65535,!(f<=a);){if(o===0)break e;o--,s+=i[C++]<>y)],f=m>>>24,b=m>>>16&255,p=m&65535,!(y+f<=a);){if(o===0)break e;o--,s+=i[C++]<>>=y,a-=y,I.back+=y}if(s>>>=f,a-=f,I.back+=f,I.length=p,b===0){I.mode=Ose;break}if(b&32){I.back=-1,I.mode=Fa;break}if(b&64){e.msg="invalid literal/length code",I.mode=GI;break}I.extra=b&15,I.mode=Mse;case Mse:if(I.extra){for(S=I.extra;a>>=I.extra,a-=I.extra,I.back+=I.extra}I.was=I.length,I.mode=zse;case zse:for(;m=I.distcode[s&(1<>>24,b=m>>>16&255,p=m&65535,!(f<=a);){if(o===0)break e;o--,s+=i[C++]<>y)],f=m>>>24,b=m>>>16&255,p=m&65535,!(y+f<=a);){if(o===0)break e;o--,s+=i[C++]<>>=y,a-=y,I.back+=y}if(s>>>=f,a-=f,I.back+=f,b&64){e.msg="invalid distance code",I.mode=GI;break}I.offset=p,I.extra=b&15,I.mode=Pse;case Pse:if(I.extra){for(S=I.extra;a>>=I.extra,a-=I.extra,I.back+=I.extra}if(I.offset>I.dmax){e.msg="invalid distance too far back",I.mode=GI;break}I.mode=Jse;case Jse:if(A===0)break e;if(u=c-A,I.offset>u){if(u=I.offset-u,u>I.whave&&I.sane){e.msg="invalid distance too far back",I.mode=GI;break}u>I.wnext?(u-=I.wnext,d=I.wsize-u):d=I.wnext-u,u>I.length&&(u=I.length),h=I.window}else h=n,d=r-I.offset,u=I.length;u>A&&(u=A),A-=u,I.length-=u;do n[r++]=h[d++];while(--u);I.length===0&&(I.mode=YR);break;case Ose:if(A===0)break e;n[r++]=I.length,A--,I.mode=YR;break;case Px:if(I.wrap){for(;a<32;){if(o===0)break e;o--,s|=i[C++]<{if(cm(e))return io;let g=e.state;return g.window&&(g.window=null),e.state=null,Vh},Vgg=(e,g)=>{if(cm(e))return io;const I=e.state;return I.wrap&2?(I.head=g,g.done=!1,Vh):io},Rgg=(e,g)=>{const I=g.length;let i,n,C;return cm(e)||(i=e.state,i.wrap!==0&&i.mode!==oH)?io:i.mode===oH&&(n=1,n=hO(n,g,I,0),n!==i.check)?y9e:(C=R9e(e,g,I,I),C?(i.mode=G9e,Z9e):(i.havedict=1,Vh))};var Wgg=S9e,Xgg=w9e,Hgg=B9e,Tgg=vgg,Ngg=V9e,kgg=Sgg,Ygg=wgg,Kgg=Vgg,Dgg=Rgg,xgg="pako inflate (from Nodeca project)",ts={inflateReset:Wgg,inflateReset2:Xgg,inflateResetKeep:Hgg,inflateInit:Tgg,inflateInit2:Ngg,inflate:kgg,inflateEnd:Ygg,inflateGetHeader:Kgg,inflateSetDictionary:Dgg,inflateInfo:xgg};function Fgg(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1}var Egg=Fgg;const W9e=Object.prototype.toString,{Z_NO_FLUSH:Mgg,Z_FINISH:zgg,Z_OK:PB,Z_STREAM_END:_x,Z_NEED_DICT:Lx,Z_STREAM_ERROR:Pgg,Z_DATA_ERROR:jse,Z_MEM_ERROR:Jgg}=t$;function hw(e){this.options=m9e.assign({chunkSize:1024*64,windowBits:15,to:""},e||{});const g=this.options;g.raw&&g.windowBits>=0&&g.windowBits<16&&(g.windowBits=-g.windowBits,g.windowBits===0&&(g.windowBits=-15)),g.windowBits>=0&&g.windowBits<16&&!(e&&e.windowBits)&&(g.windowBits+=32),g.windowBits>15&&g.windowBits<48&&(g.windowBits&15||(g.windowBits|=15)),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new Cgg,this.strm.avail_out=0;let I=ts.inflateInit2(this.strm,g.windowBits);if(I!==PB)throw new Error(mO[I]);if(this.header=new Egg,ts.inflateGetHeader(this.strm,this.header),g.dictionary&&(typeof g.dictionary=="string"?g.dictionary=fO.string2buf(g.dictionary):W9e.call(g.dictionary)==="[object ArrayBuffer]"&&(g.dictionary=new Uint8Array(g.dictionary)),g.raw&&(I=ts.inflateSetDictionary(this.strm,g.dictionary),I!==PB)))throw new Error(mO[I])}hw.prototype.push=function(e,g){const I=this.strm,i=this.options.chunkSize,n=this.options.dictionary;let C,r,o;if(this.ended)return!1;for(g===~~g?r=g:r=g===!0?zgg:Mgg,W9e.call(e)==="[object ArrayBuffer]"?I.input=new Uint8Array(e):I.input=e,I.next_in=0,I.avail_in=I.input.length;;){for(I.avail_out===0&&(I.output=new Uint8Array(i),I.next_out=0,I.avail_out=i),C=ts.inflate(I,r),C===Lx&&n&&(C=ts.inflateSetDictionary(I,n),C===PB?C=ts.inflate(I,r):C===jse&&(C=Lx));I.avail_in>0&&C===_x&&I.state.wrap>0&&e[I.next_in]!==0;)ts.inflateReset(I),C=ts.inflate(I,r);switch(C){case Pgg:case jse:case Lx:case Jgg:return this.onEnd(C),this.ended=!0,!1}if(o=I.avail_out,I.next_out&&(I.avail_out===0||C===_x))if(this.options.to==="string"){let A=fO.utf8border(I.output,I.next_out),s=I.next_out-A,a=fO.buf2string(I.output,A);I.next_out=s,I.avail_out=i-s,s&&I.output.set(I.output.subarray(A,A+s),0),this.onData(a)}else this.onData(I.output.length===I.next_out?I.output:I.output.subarray(0,I.next_out));if(!(C===PB&&o===0)){if(C===_x)return C=ts.inflateEnd(this.strm),this.onEnd(C),this.ended=!0,!0;if(I.avail_in===0)break}}return!0};hw.prototype.onData=function(e){this.chunks.push(e)};hw.prototype.onEnd=function(e){e===PB&&(this.options.to==="string"?this.result=this.chunks.join(""):this.result=m9e.flattenChunks(this.chunks)),this.chunks=[],this.err=e,this.msg=this.strm.msg};function g$(e,g){const I=new hw(g);if(I.push(e),I.err)throw I.msg||mO[I.err];return I.result}function Ogg(e,g){return g=g||{},g.raw=!0,g$(e,g)}var _gg=hw,Lgg=g$,Ugg=Ogg,Qgg=g$,jgg=t$,$gg={Inflate:_gg,inflate:Lgg,inflateRaw:Ugg,ungzip:Qgg,constants:jgg};const{Inflate:Jdg,inflate:Odg,inflateRaw:qgg,ungzip:_dg}=$gg;var eIg=qgg;function tIg(e){return eIg(e.subarray(2))}class gIg extends Error{constructor(g){super(g),this.code="ERR_ABORTED"}}function IIg(e){e.sort((n,C)=>Number(n.offset)-Number(C.offset));const g=[];let I,i;for(let n=0;n=I}function rIg(e){const g=e?"big":"little",I=new Hg().endianess(g).uint32("chromId").uint32("start").uint32("end").uint32("validCnt").floatle("minScore").floatle("maxScore").floatle("sumData").floatle("sumSqData").saveOffset("offset"),i=new Hg().endianess(g).uint8("isLeaf").skip(1).uint16("cnt").choice({tag:"isLeaf",choices:{1:new Hg().endianess(g).array("blocksToFetch",{length:"cnt",type:new Hg().endianess(g).uint32("startChrom").uint32("startBase").uint32("endChrom").uint32("endBase").uint64("blockOffset").uint64("blockSize").saveOffset("offset")}),0:new Hg().array("recurOffsets",{length:"cnt",type:new Hg().endianess(g).uint32("startChrom").uint32("startBase").uint32("endChrom").uint32("endBase").uint64("blockOffset").saveOffset("offset")})}}),n=new Hg().endianess(g).uint32("chromId").int32("start").int32("end").string("rest",{zeroTerminated:!0}).saveOffset("offset");return{bigWigParser:new Hg().endianess(g).skip(4).int32("blockStart").skip(4).uint32("itemStep").uint32("itemSpan").uint8("blockType").skip(1).uint16("itemCount").choice({tag:"blockType",choices:{[CIg]:new Hg().array("items",{length:"itemCount",type:new Hg().floatle("score")}),[nIg]:new Hg().array("items",{length:"itemCount",type:new Hg().endianess(g).int32("start").floatle("score")}),[iIg]:new Hg().array("items",{length:"itemCount",type:new Hg().endianess(g).int32("start").int32("end").floatle("score")})}}),bigBedParser:n,summaryParser:I,leafParser:i}}class X9e{constructor(g,I,i,n,C,r){if(this.bbi=g,this.refsByName=I,this.cirTreeOffset=i,this.isBigEndian=n,this.isCompressed=C,this.blockType=r,this.featureCache=new Ytg({cache:new pqe({maxSize:1e3}),fill:async(A,s)=>{const a=Number(A.length),l=Number(A.offset),{buffer:c}=await this.bbi.read(Jd.Buffer.alloc(a),0,a,l,{signal:s});return c}}),!(i>=0))throw new Error("invalid cirTreeOffset!");const o=rIg(n);this.leafParser=o.leafParser,this.bigBedParser=o.bigBedParser}async readWigData(g,I,i,n,C){try{const{refsByName:r,bbi:o,cirTreeOffset:A,isBigEndian:s}=this,a=r[g];a===void 0&&n.complete();const l={chrId:a,start:I,end:i};this.cirTreePromise||(this.cirTreePromise=o.read(Jd.Buffer.alloc(48),0,48,Number(A),C));const{buffer:c}=await this.cirTreePromise,u=s?c.readUInt32BE(4):c.readUInt32LE(4);let d=[],h=0;const m=(y,Z,B)=>{try{const G=y.subarray(Z),v=this.leafParser.parse(G);if(v.blocksToFetch&&(d=d.concat(v.blocksToFetch.filter(f).map(w=>({offset:w.blockOffset,length:w.blockSize})))),v.recurOffsets){const w=v.recurOffsets.filter(f).map(V=>Number(V.blockOffset));w.length>0&&p(w,B+1)}}catch(G){n.error(G)}},f=y=>{const{startChrom:Z,startBase:B,endChrom:G,endBase:v}=y;return(Za||G===a&&v>=I)},b=async(y,Z,B)=>{try{const G=Z.max()-Z.min(),v=Z.min(),w=await this.featureCache.get(`${G}_${v}`,{length:G,offset:v},C.signal);for(let V=0;V{try{h+=y.length;const B=4+Number(u)*32;let G=new jl(y[0],y[0]+B);for(let v=1;vb(y,v,Z))}catch(B){n.error(B)}};return p([Number(A)+48],1)}catch(r){n.error(r)}}parseSummaryBlock(g,I,i){const n=[];let C=I;const r=new DataView(g.buffer,g.byteOffset,g.length);for(;CUx(o.start,o.end,n.start,n.end)):C}parseBigWigBlock(g,I,i){const n=g.subarray(I),C=new DataView(n.buffer,n.byteOffset,n.length);let r=0;r+=4;const o=C.getInt32(r,!0);r+=8;const A=C.getUint32(r,!0);r+=4;const s=C.getUint32(r,!0);r+=4;const a=C.getUint8(r);r+=2;const l=C.getUint16(r,!0);r+=2;const c=new Array(l);switch(a){case 1:for(let u=0;uUx(u.start,u.end,i.start,i.end)):c}async readFeatures(g,I,i={}){try{const{blockType:n,isCompressed:C}=this,{signal:r,request:o}=i,A=IIg(I);KR(r),await Promise.all(A.map(async s=>{KR(r);const{length:a,offset:l}=s,c=await this.featureCache.get(`${a}_${l}`,s,r);s.blocks.forEach(u=>{KR(r);let d=Number(u.offset)-Number(s.offset),h=c;switch(C&&(h=tIg(c.subarray(d)),d=0),KR(r),n){case"summary":g.next(this.parseSummaryBlock(h,d,o));break;case"bigwig":g.next(this.parseBigWigBlock(h,d,o));break;case"bigbed":g.next(this.parseBigBedBlock(h,d,Number(u.offset)*256,o));break;default:console.warn(`Don't know what to do with ${n}`)}})})),g.complete()}catch(n){g.error(n)}}}var pO=function(e,g){return pO=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(I,i){I.__proto__=i}||function(I,i){for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&(I[n]=i[n])},pO(e,g)};function I$(e,g){if(typeof g!="function"&&g!==null)throw new TypeError("Class extends value "+String(g)+" is not a constructor or null");pO(e,g);function I(){this.constructor=e}e.prototype=g===null?Object.create(g):(I.prototype=g.prototype,new I)}function $se(e){var g=typeof Symbol=="function"&&Symbol.iterator,I=g&&e[g],i=0;if(I)return I.call(e);if(e&&typeof e.length=="number")return{next:function(){return e&&i>=e.length&&(e=void 0),{value:e&&e[i++],done:!e}}};throw new TypeError(g?"Object is not iterable.":"Symbol.iterator is not defined.")}function bO(e,g){var I=typeof Symbol=="function"&&e[Symbol.iterator];if(!I)return e;var i=I.call(e),n,C=[],r;try{for(;(g===void 0||g-- >0)&&!(n=i.next()).done;)C.push(n.value)}catch(o){r={error:o}}finally{try{n&&!n.done&&(I=i.return)&&I.call(i)}finally{if(r)throw r.error}}return C}function yO(e,g,I){if(I||arguments.length===2)for(var i=0,n=g.length,C;i=2,!1,!0))}var Qtg=function(g,e){return g.push(e),g};function jtg(){return JHe(function(g,e){Utg(Qtg,[])(g).subscribe(e)})}const Mle=-2003829722,MF=-2021002517;function $tg(g){return new TextDecoder().decode(g)}function zle(g){const e=g?"big":"little",I=new Kg().endianess(e).int32("magic").uint16("version").uint16("numZoomLevels").uint64("chromTreeOffset").uint64("unzoomedDataOffset").uint64("unzoomedIndexOffset").uint16("fieldCount").uint16("definedFieldCount").uint64("asOffset").uint64("totalSummaryOffset").uint32("uncompressBufSize").uint64("extHeaderOffset").array("zoomLevels",{length:"numZoomLevels",type:new Kg().endianess(e).uint32("reductionLevel").uint32("reserved").uint64("dataOffset").uint64("indexOffset")}),i=new Kg().endianess(e).uint64("basesCovered").doublele("scoreMin").doublele("scoreMax").doublele("scoreSum").doublele("scoreSumSquares"),n=new Kg().endianess(e).uint32("magic").uint32("blockSize").uint32("keySize").uint32("valSize").uint64("itemCount"),C=new Kg().endianess(e).uint8("isLeafNode").skip(1).uint16("cnt").saveOffset("offset");return{chromTreeParser:n,totalSummaryParser:i,headerParser:I,isLeafNode:C}}class qtg{getHeader(e={}){const I="aborted"in e?{signal:e}:e;return this.headerP||(this.headerP=this._getHeader(I).catch(i=>{throw this.headerP=void 0,i})),this.headerP}constructor(e={}){const{filehandle:I,renameRefSeqs:i=r=>r,path:n,url:C}=e;if(this.renameRefSeqs=i,I)this.bbi=I;else if(C)this.bbi=new Zbe(C);else if(n)this.bbi=new qhe(n);else throw new Error("no file given")}async _getHeader(e){const I=await this._getMainHeader(e),i=await this._readChromTree(I,e);return{...I,...i}}async _getMainHeader(e,I=2e3){const{buffer:i}=await this.bbi.read(rh.Buffer.alloc(I),0,I,0,e),n=this._isBigEndian(i),C=zle(n),r=C.headerParser.parse(i),{magic:o,asOffset:A,totalSummaryOffset:s}=r;if(r.fileType=o===MF?"bigbed":"bigwig",A>I||s>I)return this._getMainHeader(e,I*2);if(A){const a=Number(r.asOffset);r.autoSql=$tg(i.subarray(a,i.indexOf(0,a)))}if(r.totalSummaryOffset>I)return this._getMainHeader(e,I*2);if(r.totalSummaryOffset){const a=i.subarray(Number(r.totalSummaryOffset)),l=C.totalSummaryParser.parse(a);r.totalSummary={...l,basesCovered:Number(l.basesCovered)}}return{...r,isBigEndian:n}}_isBigEndian(e){let I=e.readInt32LE(0);if(I===Mle||I===MF)return!1;if(I=e.readInt32BE(0),I===Mle||I===MF)return!0;throw new Error("not a BigWig/BigBed file")}async _readChromTree(e,I){const i=e.isBigEndian,n=i?"big":"little",C=[],r={};let o=Number(e.unzoomedDataOffset);const A=Number(e.chromTreeOffset);for(;o%4!==0;)o+=1;const s=o-A,{buffer:a}=await this.bbi.read(rh.Buffer.alloc(s),0,s,Number(A),I),l=zle(i),{keySize:c}=l.chromTreeParser.parse(a),u=new Kg().endianess(n).string("key",{stripNull:!0,length:c}).uint32("refId").uint32("refSize").saveOffset("offset"),d=new Kg().endianess(n).skip(c).uint64("childOffset").saveOffset("offset"),h=32,m=async f=>{let b=f;if(b>=a.length)throw new Error("reading beyond end of buffer");const p=l.isLeafNode.parse(a.subarray(b)),{isLeafNode:y,cnt:Z}=p;if(b+=p.offset,y)for(let v=0;v0,r)}async getFeatureStream(e,I,i,n={scale:1}){await this.getHeader(n);const C=this.renameRefSeqs(e);let r;if(n.basesPerSpan?r=await this.getView(1/n.basesPerSpan,n):n.scale?r=await this.getView(n.scale,n):r=await this.getView(1,n),!r)throw new Error("unable to get block view for data");return new Ftg(o=>{r.readWigData(C,I,i,o,n)})}async getFeatures(e,I,i,n={scale:1}){const C=await this.getFeatureStream(e,I,i,n);return(await Ltg(C.pipe(jtg()))).flat()}}class egg extends qtg{async getView(e,I){const{zoomLevels:i,refsByName:n,fileSize:C,isBigEndian:r,uncompressBufSize:o}=await this.getHeader(I),A=1/e;let s=i.length;C||(s-=1);for(let a=s;a>=0;a-=1){const l=i[a];if(l&&l.reductionLevel<=2*A){const c=Number(l.indexOffset);return new EHe(this.bbi,n,c,r,o>0,"summary")}}return this.getUnzoomedView(I)}}function OHe(g,e){if(!new.target)throw new Error('Uncaught TypeError: Class constructor cannot be invoked without "new"');const I=class{constructor(){nt(this,"dataConfig"),nt(this,"bwFileHeader"),nt(this,"bwFile"),nt(this,"TILE_SIZE"),nt(this,"errorTxt"),nt(this,"dataPromises"),nt(this,"chromSizes"),nt(this,"assembly"),nt(this,"tilesetInfoLoading"),this.dataConfig=e,this.assembly=this.dataConfig.assembly,this.bwFileHeader=null,this.bwFile=null,this.TILE_SIZE=1024,this.errorTxt="",this.dataPromises=[];const n=yI(this.assembly).size,C=[],r={};let o=0;Object.keys(yI(this.assembly).size).forEach((A,s)=>{const a={id:s,chr:A,pos:o};C.push(a),r[A]=a,o+=yI(this.assembly).size[A]}),this.chromSizes={chrToAbs:(A,s)=>this.chromSizes.chrPositions[A].pos+s,cumPositions:C,chrPositions:r,totalLength:o,chromLengths:n},this.dataPromises.push(this.loadBBI(e))}async loadBBI(n){return n.url?(this.bwFile=new egg({filehandle:new r0e(n.url,{overrides:n.urlFetchOptions})}),this.bwFile.getHeader().then(C=>{this.bwFileHeader=C})):(console.error('Please enter a "url" field to the data config'),null)}tilesetInfo(n){return this.tilesetInfoLoading=!0,Promise.all(this.dataPromises).then(()=>{this.tilesetInfoLoading=!1;const C=this.chromSizes.totalLength,r={tile_size:this.TILE_SIZE,max_zoom:Math.ceil(Math.log(C/this.TILE_SIZE)/Math.log(2)),max_width:2**Math.ceil(Math.log(C)/Math.log(2)),min_pos:[0],max_pos:[C]};return n&&n(r),r}).catch(C=>(this.tilesetInfoLoading=!1,console.error(C),n&&n({error:`Error parsing bigwig: ${C}`}),null))}fetchTilesDebounced(n,C){const r={},o=[],A=[];for(const s of C){const a=s.split("."),l=parseInt(a[0],10),c=parseInt(a[1],10);if(Number.isNaN(c)||Number.isNaN(l)){console.warn("Invalid tile zoom or position:",l,c);continue}o.push(s),A.push(this.tile(l,c))}return Promise.all(A).then(s=>{for(let a=0;a{const p=b.chr,y=b.pos,Z=b.pos+m[p];let v,G;if(y<=l&&lZ)v=l-y,G=Z-y,A.push(this.bwFile.getFeatures(p,v,G,{scale:1/u}).then(B=>(B.forEach(w=>{w.startAbs=g.utils.chrToAbs(p,w.start,this.chromSizes),w.endAbs=g.utils.chrToAbs(p,w.end,this.chromSizes)}),B))),l=Z;else{if(v=Math.floor(l-y),G=Math.ceil(c-y),!this.bwFile)return;A.push(this.bwFile.getFeatures(p,v,G,{scale:1/u}).then(B=>(B.forEach(w=>{w.startAbs=g.utils.chrToAbs(p,w.start,this.chromSizes),w.endAbs=g.utils.chrToAbs(p,w.end,this.chromSizes)}),B)));return}}),Promise.all(A).then(b=>{const p=b.flat(),y=[];for(let v=0;v{if(vc)return;const B=p.filter(w=>v>=w.startAbs&&vw.score);y[G]=B.length>0?B[0]:null});const Z=new g.utils.DenseDataExtrema1D(y);return s.min_value=Math.min(...y),s.max_value=Math.max(...y),s.dense=y,s.denseDataExtrema=Z,s.minNonZero=Z.minNonZeroInTile,s.maxNonZero=Z.maxNonZeroInTile,s})}determineScale(n,C){const r=[1],o=C-n;if(!this.bwFileHeader)throw Error("no bigwig header");this.bwFileHeader.zoomLevels.forEach(s=>{r.push(s.reductionLevel)});let A;return r.forEach(s=>{if(A)return;o/s<=this.TILE_SIZE*20&&(A=s)}),A||r.slice(-1)[0]}};return new I}OHe.config={type:"bigwig"};function LHe(g,e){const{field:I,not:i}=g;let n=Array.from(e);if(K7e(g)){const{oneOf:C}=g;n=n.filter(r=>i?C.indexOf(r[I])===-1:C.indexOf(r[I])!==-1)}else if(x7e(g)){const{inRange:C}=g;n=n.filter(r=>{const o=+r[I];return i?!(C[0]<=o&&o<=C[1]):C[0]<=o&&o<=C[1]})}else if(D7e(g)){const{include:C}=g;n=n.filter(r=>i?`${r[I]}`.includes(C):!`${r[I]}`.includes(C))}return n}function tgg(g,e){const{fields:I,separator:i,newField:n}=g;let C=Array.from(e);return C=C.map(r=>{const o=I.map(A=>r[A]);return r[n]=o.join(i),r}),C}function ggg(g,e){const{field:I,replace:i,newField:n}=g;let C=Array.from(e);return C=C.map(r=>(r[n]=r[I],i.forEach(o=>{const{from:A,to:s}=o;r[n]=r[n].toString().replaceAll(A,s)}),r)),C}function Igg(g,e){const{field:I,base:i,newField:n}=g;let C=Array.from(e);return C=C.map(r=>(+r[I]&&(i==="e"?r[n??I]=Math.log(+r[I]):r[n??I]=Math.log(+r[I])/Math.log(i??10)),r)),C}function igg(g,e){const{startField:I,endField:i,newField:n}=g,C=Array.from(e);return C.forEach(r=>{const o=r[I],A=r[i];!o||!A||(r[n]=Math.abs(+A-+o))}),C}function ngg(g,e){const{firstBp:I,secondBp:i,newField:n}=g,C=Array.from(e),[r,o,A,s,a]=["DUP","TRA","DEL","t2tINV","h2hINV"];return C.forEach(l=>{const c=l[I.chrField],u=l[i.chrField];if(c!==u){l[n]=o;return}let d=l[I.posField],h=l[i.posField],m=l[I.strandField],f=l[i.strandField];if(d>h){const b=d,p=m;d=h,m=f,h=b,f=p}switch(`${m}${f}`){case"+-":l[n]=A;break;case"--":l[n]=s;break;case"++":l[n]=a;break;case"-+":l[n]=r;break;default:l[n]="unknown"}}),C}function Cgg(g,e,I){const{startField:i,endField:n,newField:C,groupField:r}=g,o={},A=1;return e.forEach(a=>{const l=I(a[i]),c=I(a[n]),u=r?a[r]:"__NO_GROUP__",d=Math.floor(l);for(let h=d;h{const[l,c]=a;return Object.entries(c).map(u=>{const[d,h]=u;return{[i]:I.invert(+d),[n]:I.invert(+d+A),[C??"coverage"]:h,[r??"group"]:l}})})}function rgg(g,e,I){const{boundingBox:i,method:n,newField:C}=g,{startField:r,endField:o,groupField:A}=i;let s=0;i.padding&&I&&!i.isPaddingBP?s=Math.abs(I.invert(i.padding)-I.invert(0)):i.padding&&i.isPaddingBP&&(s=i.padding);const a=Array.from(e);if(a&&a.length>0&&(!Object.keys(a[0]).find(l=>l===r)||!Object.keys(a[0]).find(l=>l===o)))return a;if(n==="pile"){const{maxRows:l}=g,c={};a.sort((d,h)=>d[r]-h[r]).forEach(d=>{const h=+d[r]-s,m=+d[o]+s,f=A?d[A]:"__NO_GROUP__";c[f]||(c[f]=[]);let b=c[f].findIndex(p=>mc[r]-u[r]).forEach(c=>{let u=c[r]-s,d=c[o]+s,h=l.filter(m=>m.start===u&&d===m.end||m.start0){let m=0;do h=l.filter(f=>f.start===u&&d===f.end||f.start0&&(m%2===0?(u+=s*m,d+=s*m):(u-=s*m,d-=s*m)),m++;while(h.length>0&&m<1e3)}c[`${C}Start`]=`${u+s}`,c[`${C}Etart`]=`${d-s}`,l.push({start:u,end:d})})}return a}function ogg(g,e,I="hg38"){const{separator:i,fields:n,flag:C}=g;let r=Array.from(e);return r=r.map(o=>{const A=[];return n.forEach(s=>{const{field:a,type:l,newField:c,chrField:u}=s;o[a].toString().split(i).forEach((h,m)=>{let f=h;l==="genomic"&&(f=yI(I).interval[o[u]][0]+ +h),A[m]?A[m][c]=f:A[m]=Object.assign(JSON.parse(JSON.stringify(o)),{[c]:f,[C.field]:C.value})})}),[o,...A]}).reduce((o,A)=>o.concat(A),[]),r}function Agg(g,e){const{field:I,genomicField:i,baseGenomicField:n,genomicLengthField:C}=g;let r=Array.from(e);return r=r.map(o=>{let A=JSON.parse(o[I]);return A=A.map(s=>{var a,l;return s[i]&&o[n]&&(s[`${i}_start`]=+s[i]+ +o[n],s[`${i}_end`]=+s[i]+ +o[n]+ +s[C]),Object.assign(JSON.parse(JSON.stringify(o)),{...s,[`${i}_start`]:s[`${i}_start`],[`${i}_end`]:s[`${i}_end`],type:(l=(a=s.type)!=null?a:s.variant)!=null?l:null,isParsedRow:"yes"})}),[o,...A]}).reduce((o,A)=>o.concat(A),[]),r}function agg(g,e){if(M7e(g).length===0)return e;const I=f5(g,"nominal");if(I.length!==1)return console.warn("Currently, we only support aggregating datasets with single nominal field."),e;const i=g[I[0]];if(!lt(i))return e;const n=i.field;if(!n)return e;const C=[...f5(g,"quantitative"),...f5(g,"genomic")],r=[],o=Array.from(new Set(e.map(s=>s[n])));let A=!1;return o.forEach(s=>{const a={};a[n]=s,C.forEach(l=>{const c=g[l];if(!lt(c)){A=!0;return}const{field:u}=c;if(!u||!("aggregate"in c)){A=!0;return}a[u]=c.aggregate==="max"?Math.max(...e.filter(d=>d[n]===s).map(d=>+d[u])):Math.min(...e.filter(d=>d[n]===s).map(d=>+d[u]))}),r.push(a)}),A?e:r}class sgg{constructor(e){Zg(this,EO),Zg(this,v$),Zg(this,_2),Zg(this,zO),Zg(this,PO),Zg(this,JO),nt(this,"dataConfig"),nt(this,"tilesetInfoLoading"),Zg(this,vG,void 0),Zg(this,cS,void 0),Zg(this,uS,void 0),Zg(this,_d,void 0),Zg(this,O2,void 0),Zg(this,L2,void 0),this.dataConfig=e,this.tilesetInfoLoading=!1,wC(this,_d,this.dataConfig.assembly),wC(this,O2,this.dataConfig.filter),e.url||console.error("Please provide the `url` of the data");const{urlFetchOptions:I,url:i}=e;wC(this,L2,new r0e(i,{overrides:I})),wC(this,cS,wI(this,JO,cHe).call(this)),wC(this,vG,wI(this,EO,AHe).call(this))}tilesetInfo(e){if(Jt(this,vG))return this.tilesetInfoLoading=!0,Jt(this,vG).then(()=>wI(this,zO,sHe).call(this,e)).catch(I=>{this.tilesetInfoLoading=!1,console.error("[Gosling Data Fetcher] Error parsing data:",I)})}fetchTilesDebounced(e,I){const i={},n=[],C=[];for(const r of I){const o=r.split("."),A=parseInt(o[0],10),s=parseInt(o[1],10),a=parseInt(o[2],10);if(Number.isNaN(s)||Number.isNaN(A)){console.warn("[Gosling Data Fetcher] Invalid tile zoom or position:",A,s,a);continue}n.push(r),C.push(wI(this,PO,lHe).call(this,A,s,a))}Promise.all(C).then(r=>{r.forEach((o,A)=>{if(o){const s=n[A];i[s]=o,i[s].tilePositionId=s}}),e(i)})}}vG=new WeakMap;cS=new WeakMap;uS=new WeakMap;_d=new WeakMap;O2=new WeakMap;L2=new WeakMap;EO=new WeakSet;AHe=async function(){var g,e;const{chromosomeField:I,genomicFields:i,headerNames:n,longToWideId:C,genomicFieldsToConvert:r}=this.dataConfig,o=(g=this.dataConfig.separator)!=null?g:",";try{const s=(await Jt(this,L2).readFile()).toString(),a=n?`${n.join(o)} -${s}`:s,l=J8e(o).parse(a,c=>wI(this,v$,aHe).call(this,c,r,I,i));if(C&&((e=l[0])!=null&&e[C])){const c=Object.keys(l[0]),u={};l.forEach(d=>{u[d[C]]?c.forEach(h=>{u[d[C]][`${h}_2`]=d[h]}):u[d[C]]=JSON.parse(JSON.stringify(d))}),wC(this,uS,Object.keys(u).map(d=>u[d]))}else wC(this,uS,l)}catch(A){console.error("[Gosling Data Fetcher] Error fetching data",A)}};v$=new WeakSet;aHe=function(g,e,I,i){try{return e?e.forEach(n=>{const C=n.genomicFields,r=g[n.chromosomeField];C.forEach(o=>{const A=g[o];g[o]=String(wI(this,_2,MO).call(this,r,A))})}):I&&i&&i.forEach(n=>{const C=g[n],r=g[I];g[n]=String(wI(this,_2,MO).call(this,r,C))}),g}catch{return}};_2=new WeakSet;MO=function(g,e){if(Jt(this,_d)!=="unknown"){const I=s3(g,Jt(this,_d),this.dataConfig.chromosomePrefix);return yI(Jt(this,_d)).interval[I][0]+ +e}else return e};zO=new WeakSet;sHe=function(g){this.tilesetInfoLoading=!1;const e=1024,I=Jt(this,cS).totalLength,i={tile_size:e,max_zoom:Math.ceil(Math.log(I/e)/Math.log(2)),max_width:I,min_pos:[0,0],max_pos:[I,I]};return g&&g(i),i};PO=new WeakSet;lHe=async function(g,e,I){var i,n;const C=await this.tilesetInfo();if(!C)return;const r=+C.max_width/2**+g,o=C.min_pos[0]+e*r,A=C.min_pos[0]+(e+1)*r;let s=C0e(Jt(this,uS),[o,A],this.dataConfig);(i=Jt(this,O2))==null||i.forEach(l=>{s=LHe(l,s)});const a=(n=this.dataConfig.sampleLength)!=null?n:1e3;return{tabularData:s.length>a?EU(s,a):s,server:null,tilePos:[e,I],zoomLevel:g}};JO=new WeakSet;cHe=function(){const g=yI(Jt(this,_d)).size,e=[],I={};let i=0;return Object.keys(g).forEach((n,C)=>{const r={id:C,chr:n,pos:i};e.push(r),I[n]=r,i+=g[n]}),{chrToAbs:(n,C)=>Jt(this,cS).chrPositions[n].pos+C,cumPositions:e,chrPositions:I,totalLength:i,chromLengths:g}};function _He(g,e,I){if(!new.target)throw new Error('Uncaught TypeError: Class constructor cannot be invoked without "new"');return new sgg(e)}_He.config={type:"csv"};function UHe(g,...e){if(!new.target)throw new Error('Uncaught TypeError: Class constructor cannot be invoked without "new"');class I{constructor(n){nt(this,"dataConfig"),nt(this,"tilesetInfoLoading"),nt(this,"chromSizes"),nt(this,"values"),nt(this,"assembly");const[C]=n;if(this.dataConfig=C,this.tilesetInfoLoading=!1,this.assembly=this.dataConfig.assembly,!C.values){console.error("Please provide `values` of the JSON data");return}const r=yI(this.assembly).size,o=[],A={};let s=0;Object.keys(yI(this.assembly).size).forEach((u,d)=>{const h={id:d,chr:u,pos:s};o.push(h),A[u]=h,s+=yI(this.assembly).size[u]}),this.chromSizes={chrToAbs:(u,d)=>this.chromSizes.chrPositions[u].pos+d,cumPositions:o,chrPositions:A,totalLength:s,chromLengths:r};const{chromosomeField:a,genomicFields:l,genomicFieldsToConvert:c}=this.dataConfig;this.values=C.values.map(u=>{try{return c?c.forEach(d=>{const h=d.genomicFields,m=s3(u[d.chromosomeField],this.assembly);h.forEach(f=>{const b=u[f];u[f]=String(this.chromSizes.chrToAbs(m,b))})}):a&&l&&l.forEach(d=>{const h=u[d],m=s3(u[a],this.assembly);u[d]=String(this.chromSizes.chrToAbs(m,h))}),u}catch{return}})}tilesetInfo(n){this.tilesetInfoLoading=!1;const C=1024,r=this.chromSizes.totalLength,o={tile_size:C,max_zoom:Math.ceil(Math.log(r/C)/Math.log(2)),max_width:r,min_pos:[0,0],max_pos:[r,r]};return n&&n(o),o}fetchTilesDebounced(n,C){const r={},o=[],A=[];for(const s of C){const a=s.split("."),l=parseInt(a[0],10),c=parseInt(a[1],10),u=parseInt(a[2],10);if(Number.isNaN(c)||Number.isNaN(l)){console.warn("[Gosling Data Fetcher] Invalid tile zoom or position:",l,c,u);continue}o.push(s),A.push(this.tile(l,c,u))}return Promise.all(A).then(s=>{s.forEach((a,l)=>{const c=o[l];r[c]=a,r[c].tilePositionId=c}),n(r)}),r}tile(n,C,r){var o;const A=this.tilesetInfo(),s=+A.max_width/2**+n,a=A.min_pos[0]+C*s,l=A.min_pos[0]+(C+1)*s;let c=C0e(this.values,[a,l],this.dataConfig);const u=(o=this.dataConfig.sampleLength)!=null?o:1e3;return u{const A=Object.entries(yI(C).size);return await o.init(this.uid,{url:i,indexUrl:n},A,r),o})}async tilesetInfo(e){(await this.worker).tilesetInfo(this.uid).then(e)}fetchTilesDebounced(e,I){this.track.drawLoadingCue(),I.forEach(i=>this.toFetch.add(i)),this.fetchTimeout&&clearTimeout(this.fetchTimeout),this.fetchTimeout=setTimeout(()=>{this.sendFetch(e,[...this.toFetch]),this.toFetch.clear()},cgg)}async sendFetch(e,I){(await this.worker).fetchTilesDebounced(this.uid,I).then(e)}async getTabularData(e){const I=await(await this.worker).getTabularData(this.uid,e);return JSON.parse(new TextDecoder().decode(I))}}nt(jHe,"config",{type:"gff"});const $He="KCgpID0+IHsKICB2YXIgX19jcmVhdGUgPSBPYmplY3QuY3JlYXRlOwogIHZhciBfX2RlZlByb3AgPSBPYmplY3QuZGVmaW5lUHJvcGVydHk7CiAgdmFyIF9fZ2V0T3duUHJvcERlc2MgPSBPYmplY3QuZ2V0T3duUHJvcGVydHlEZXNjcmlwdG9yOwogIHZhciBfX2dldE93blByb3BOYW1lcyA9IE9iamVjdC5nZXRPd25Qcm9wZXJ0eU5hbWVzOwogIHZhciBfX2dldFByb3RvT2YgPSBPYmplY3QuZ2V0UHJvdG90eXBlT2Y7CiAgdmFyIF9faGFzT3duUHJvcCA9IE9iamVjdC5wcm90b3R5cGUuaGFzT3duUHJvcGVydHk7CiAgdmFyIF9fbWFya0FzTW9kdWxlID0gKHRhcmdldCkgPT4gX19kZWZQcm9wKHRhcmdldCwgIl9fZXNNb2R1bGUiLCB7IHZhbHVlOiB0cnVlIH0pOwogIHZhciBfX2VzbSA9IChmbiwgcmVzKSA9PiBmdW5jdGlvbiBfX2luaXQoKSB7CiAgICByZXR1cm4gZm4gJiYgKHJlcyA9ICgwLCBmbltPYmplY3Qua2V5cyhmbilbMF1dKShmbiA9IDApKSwgcmVzOwogIH07CiAgdmFyIF9fY29tbW9uSlMgPSAoY2IsIG1vZCkgPT4gZnVuY3Rpb24gX19yZXF1aXJlKCkgewogICAgcmV0dXJuIG1vZCB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m4gb3V0cHV0LmpvaW4oIiIpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGZyb21CeXRlQXJyYXkodWludDgpIHsKICAgICAgICB2YXIgdG1wOwogICAgICAgIHZhciBsZW4yID0gdWludDgubGVuZ3RoOwogICAgICAgIHZhciBleHRyYUJ5dGVzID0gbGVuMiAlIDM7CiAgICAgICAgdmFyIHBhcnRzID0gW107CiAgICAgICAgdmFyIG1heENodW5rTGVuZ3RoID0gMTYzODM7CiAgICAgICAgZm9yICh2YXIgaTIgPSAwLCBsZW4yMiA9IGxlbjIgLSBleHRyYUJ5dGVzOyBpMiA8IGxlbjIyOyBpMiArPSBtYXhDaHVua0xlbmd0aCkgewogICAgICAgICAgcGFydHMucHVzaChlbmNvZGVDaHVuayh1aW50OCwgaTIsIGkyICsgbWF4Q2h1bmtMZW5ndGggPiBsZW4yMiA/IGxlbjIyIDogaTIgKyBtYXhDaHVua0xlbmd0aCkpOwogICAgICAgIH0KICAgICAgICBpZiAoZXh0cmFCeXRlcyA9PT0gMSkgewogICAgICAgICAgdG1wID0gdWludDhbbGVuMiAtIDFdOwogICAgICAgICAgcGFydHMucHVzaChsb29rdXBbdG1wID4+IDJdICsgbG9va3VwW3RtcCA8PCA0ICYgNjNdICsgIj09Iik7CiAgICAgICAgfSBlbHNlIGlmIChleHRyYUJ5dGVzID09PSAyKSB7CiAgICAgICAgICB0bXAgPSAodWludDhbbGVuMiAtIDJdIDw8IDgpICsgdWludDhbbGVuMiAtIDFdOwogICAgICAgICAgcGFydHMucHVzaChsb29rdXBbdG1wID4+IDEwXSArIGxvb2t1cFt0bXAgPj4gNCAmIDYzXSArIGxvb2t1cFt0bXAgPDwgMiAmIDYzXSArICI9Iik7CiAgICAgICAgfQogICAgICAgIHJldHVybiBwYXJ0cy5qb2luKCIiKTsKICAgICAgfQogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vaWVlZTc1NEAxLjIuMS9ub2RlX21vZHVsZXMvaWVlZTc1NC9pbmRleC5qcwogIHZhciByZXF1aXJlX2llZWU3NTQgPSBfX2NvbW1vbkpTKHsKICAgICJub2RlX21vZHVsZXMvLnBucG0vaWVlZTc1NEAxLjIuMS9ub2RlX21vZHVsZXMvaWVlZTc1NC9pbmRleC5qcyIoZXhwb3J0czIpIHsKICAgICAgaW5pdF9idWZmZXJfc2hpbSgpOwogICAgICBleHBvcnRzMi5yZWFkID0gZnVuY3Rpb24oYnVmZmVyLCBvZmZzZXQsIGlzTEUsIG1MZW4sIG5CeXRlcykgewogICAgICAgIHZhciBlLCBtOwogICAgICAgIHZhciBlTGVuID0gbkJ5dGVzICogOCAtIG1MZW4gLSAxOwogICAgICAgIHZhciBlTWF4ID0gKDEgPDwgZUxlbikgLSAxOwogICAgICAgIHZhciBlQmlhcyA9IGVNYXggPj4gMTsKICAgICAgICB2YXIgbkJpdHMgPSAtNzsKICAgICAgICB2YXIgaSA9IGlzTEUgPyBuQnl0ZXMgLSAxIDogMDsKICAgICAgICB2YXIgZCA9IGlzTEUgPyAtMSA6IDE7CiAgICAgICAgdmFyIHMgPSBidWZmZXJbb2Zmc2V0ICsgaV07CiAgICAgICAgaSArPSBkOwogICAgICAgIGUgPSBzICYgKDEgPDwgLW5CaXRzKSAtIDE7CiAgICAgICAgcyA+Pj0gLW5CaXRzOwogICAgICAgIG5CaXRzICs9IGVMZW47CiAgICAgICAgZm9yICg7IG5CaXRzID4gMDsgZSA9IGUgKiAyNTYgKyBidWZmZXJbb2Zmc2V0ICsgaV0sIGkgKz0gZCwgbkJpdHMgLT0gOCkgewogICAgICAgIH0KICAgICAgICBtID0gZSAmICgxIDw8IC1uQml0cykgLSAxOwogICAgICAgIGUgPj49IC1uQml0czsKICAgICAgICBuQml0cyArPSBtTGVuOwogICAgICAgIGZvciAoOyBuQml0cyA+IDA7IG0gPSBtICogMjU2ICsgYnVmZmVyW29mZnNldCArIGldLCBpICs9IGQsIG5CaXRzIC09IDgpIHsKICAgICAgICB9CiAgICAgICAgaWY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gfSBlbHNlIHsKICAgICAgICAgIGUgPSBNYXRoLmZsb29yKE1hdGgubG9nKHZhbHVlKSAvIE1hdGguTE4yKTsKICAgICAgICAgIGlmICh2YWx1ZSAqIChjID0gTWF0aC5wb3coMiwgLWUpKSA8IDEpIHsKICAgICAgICAgICAgZS0tOwogICAgICAgICAgICBjICo9IDI7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoZSArIGVCaWFzID49IDEpIHsKICAgICAgICAgICAgdmFsdWUgKz0gcnQgLyBjOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgdmFsdWUgKz0gcnQgKiBNYXRoLnBvdygyLCAxIC0gZUJpYXMpOwogICAgICAgICAgfQogICAgICAgICAgaWYgKHZhbHVlICogYyA+PSAyKSB7CiAgICAgICAgICAgIGUrKzsKICAgICAgICAgICAgYyAvPSAyOwogICAgICAgICAgfQogICAgICAgICAgaWYgKGUgKyBlQmlhcyA+PSBlTWF4KSB7CiAgICAgICAgICAgIG0gPSAwOwogICAgICAgICAgICBlID0gZU1heDsKICAgICAgICAgIH0gZWxzZSBpZiAoZSArIGVCaWFzID49IDEpIHsKICAgICAgICAgICAgbSA9ICh2YWx1ZSAqIGMgLSAxKSAqIE1hdGgucG93KDIsIG1MZW4pOwogICAgICAgICAgICBlID0gZSArIGVCaWFzOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgbSA9IHZhbHVlICogTWF0aC5wb3coMiwgZUJpYXMgLSAxKSAqIE1hdGgucG93KDIsIG1MZW4pOwogICAgICAgICAgICBlID0gMDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZm9yICg7IG1MZW4gPj0gODsgYnVmZmVyW29mZnNldCArIGldID0gbSAmIDI1NSwgaSArPSBkLCBtIC89IDI1NiwgbUxlbiAtPSA4KSB7CiAgICAgICAgfQogICAgICAgIGUgPSBlIDw8IG1MZW4gfCBtOwogICAgICAgIGVMZW4gKz0gbUxlbjsKICAgICAgICBmb3IgKDsgZUxlbiA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1ZmZlcih0aGlzKSkKICAgICAgICAgICAgcmV0dXJuIHZvaWQgMDsKICAgICAgICAgIHJldHVybiB0aGlzLmJ1ZmZlcjsKICAgICAgICB9CiAgICAgIH0pOwogICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkoQnVmZmVyMTAucHJvdG90eXBlLCAib2Zmc2V0IiwgewogICAgICAgIGVudW1lcmFibGU6IHRydWUsCiAgICAgICAgZ2V0OiBmdW5jdGlvbigpIHsKICAgICAgICAgIGlmICghQnVmZmVyMTAuaXNCdWZmZXIodGhpcykpCiAgICAgICAgICAgIHJldHVybiB2b2lkIDA7CiAgICAgICAgICByZXR1cm4gdGhpcy5ieXRlT2Zmc2V0OwogICAgICAgIH0KICAgICAgfSk7CiAgICAgIGZ1bmN0aW9uIGNyZWF0ZUJ1ZmZlcihsZW5ndGgpIHsKICAgICAgICBpZiAobGVuZ3RoID4gS19NQVhfTEVOR1RIKSB7CiAgICAgICAgICB0aHJvdyBuZXcgUmFuZ2VFcnJvcignVGhlIHZhbHVlICInICsgbGVuZ3RoICsgJyIgaXMgaW52YWxpZCBmb3Igb3B0aW9uICJzaXplIicpOwogICAgICAgIH0KICAgICAgICBjb25zdCBidWYgPSBuZXcgVWludDhBcnJheShsZW5ndGgpOwogICAgICAgIE9iamVjdC5zZXRQcm90b3R5cGVPZihidWYsIEJ1ZmZlcjEwLnByb3RvdHlwZSk7CiAgICAgICAgcmV0dXJuIGJ1ZjsKICAgICAgfQogICAgICBmdW5jdGlvbiBCdWZmZXIxMChhcmcsIGVuY29kaW5nT3JPZmZzZXQsIGxlbmd0aCkgewogICAgICAgIGlmICh0eXBlb2YgYXJnID09PSAibnVtYmVyIikgewogICAgICAgICAgaWYgKHR5cGVvZiBlbmNvZGluZ09yT2Zmc2V0ID09PSAic3RyaW5nIikgewogICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCdUaGUgInN0cmluZyIgYXJndW1lbnQgbXVzdCBiZSBvZiB0eXBlIHN0cmluZ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2RpbmcoZW5jb2RpbmcpKSB7CiAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCJVbmtub3duIGVuY29kaW5nOiAiICsgZW5jb2RpbmcpOwogICAgICAgIH0KICAgICAgICBjb25zdCBsZW5ndGggPSBieXRlTGVuZ3RoKHN0cmluZywgZW5jb2RpbmcpIHwgMDsKICAgICAgICBsZXQgYnVmID0gY3JlYXRlQnVmZmVyKGxlbmd0aCk7CiAgICAgICAgY29uc3QgYWN0dWFsID0gYnVmLndyaXRlKHN0cmluZywgZW5jb2RpbmcpOwogICAgICAgIGlmIChhY3R1YWwgIT09IGxlbmd0aCkgewogICAgICAgICAgYnVmID0gYnVmLnNsaWNlKDAsIGFjdHVhbCk7CiAgICAgICAgfQogICAgICAgIHJldHVybiBidWY7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZnJvbUFycmF5TGlrZShhcnJheSkgewogICAgICAgIGNvbnN0IGxlbmd0aCA9IGFycmF5Lmxlbmd0aCA8IDAgPyAwIDogY2hlY2tlZChhcnJheS5sZW5ndGgpIHwgMDsKICAgICAgICBjb25zdCBidWYgPSBjcmVhdGVCdWZmZXIobGVuZ3RoKTsKICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IGxlbmd0aDsgaSArPSAxKSB7CiAgICAgICAgICBidWZbaV0gPSBhcnJheVtpXSAmIDI1NTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIGJ1ZjsKICAgICAgfQogICAgICBmdW5jdGlvbiBmcm9tQXJyYXlWaWV3KGFycmF5VmlldykgewogICAgICAgIGlmIChpc0luc3RhbmNlKGFycmF5VmlldywgVWludDhBcnJheSkpIHsKICAgICAgICAgIGNvbnN0IGNvcHkgPSBuZXcgVWludDhBcnJheShhcnJheVZpZXcpOwogICAgICAgICAgcmV0dXJuIGZyb21BcnJheUJ1ZmZlcihjb3B5LmJ1ZmZlciwgY29weS5ieXRlT2Zmc2V0LCBjb3B5LmJ5dGVMZW5ndGgpOwogICAgICAgIH0K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KG9iaikpIHsKICAgICAgICAgIGNvbnN0IGxlbiA9IGNoZWNrZWQob2JqLmxlbmd0aCkgfCAwOwogICAgICAgICAgY29uc3QgYnVmID0gY3JlYXRlQnVmZmVyKGxlbik7CiAgICAgICAgICBpZiAoYnVmLmxlbmd0aCA9PT0gMCkgewogICAgICAgICAgICByZXR1cm4gYnVmOwogICAgICAgICAgfQogICAgICAgICAgb2JqLmNvcHkoYnVmLCAwLCAwLCBsZW4pOwogICAgICAgICAgcmV0dXJuIGJ1ZjsKICAgICAgICB9CiAgICAgICAgaWYgKG9iai5sZW5ndGggIT09IHZvaWQgMCkgewogICAgICAgICAgaWYgKHR5cGVvZiBvYmoubGVuZ3RoICE9PSAibnVtYmVyIiB8fCBudW1iZXJJc05hTihvYmoubGVuZ3RoKSkgewogICAgICAgICAgICByZXR1cm4gY3JlYXRlQnVmZmVyKDApOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIGZyb21BcnJheUxpa2Uob2JqKTsKICAgICAgICB9CiAgICAgICAgaWYgKG9iai50eXBlID09PSAiQnVmZmVyIiAmJiBBcnJheS5pc0FycmF5KG9iai5kYXRhKSkgewogICAgICAgICAgcmV0dXJuIGZyb21BcnJheUxpa2Uob2JqLmRhdGEpOwogICAgICAgIH0KICAgICAgfQogICAgICBmdW5jdGlvbiBjaGVja2VkKGxlbmd0aCkgewogICAgICAgIGlmIChsZW5ndGggPj0gS19NQVhfTEVOR1RIKSB7CiAgICAgICAgICB0aHJvdyBuZXcgUmFuZ2VFcnJvcigiQXR0ZW1wdCB0byBhbGxvY2F0ZSBCdWZmZXIgbGFyZ2VyIHRoYW4gbWF4aW11bSBzaXplOiAweCIgKyBLX01BWF9MRU5HVEgudG9TdHJpbmcoMTYpICsgIiBieXRlcyIpOwogICAgICAgIH0KICAgICAgICByZXR1cm4gbGVuZ3RoIHwgMDsKICAgICAgfQogICAgICBmdW5jdGlvbiBTbG93QnVmZmVyKGxlbmd0aCkgewogICAgICAgIGlmICgrbGVu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YltpXSkgewogICAgICAgICAgICB4ID0gYVtpXTsKICAgICAgICAgICAgeSA9IGJbaV07CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAoeCA8IHkpCiAgICAgICAgICByZXR1cm4gLTE7CiAgICAgICAgaWYgKHkgPCB4KQogICAgICAgICAgcmV0dXJuIDE7CiAgICAgICAgcmV0dXJuIDA7CiAgICAgIH07CiAgICAgIEJ1ZmZlcjEwLmlzRW5jb2RpbmcgPSBmdW5jdGlvbiBpc0VuY29kaW5nKGVuY29kaW5nKSB7CiAgICAgICAgc3dpdGNoIChTdHJpbmcoZW5jb2RpbmcpLnRvTG93ZXJDYXNlKCkpIHsKICAgICAgICAgIGNhc2UgImhleCI6CiAgICAgICAgICBjYXNlICJ1dGY4IjoKICAgICAgICAgIGNhc2UgInV0Zi04IjoKICAgICAgICAgIGNhc2UgImFzY2lpIjoKICAgICAgICAgIGNhc2UgImxhdGluMSI6CiAgICAgICAgICBjYXNlICJiaW5hcnkiOgogICAgICAgICAgY2FzZSAiYmFzZTY0IjoKICAgICAgICAgIGNhc2UgInVjczIiOgogICAgICAgICAgY2FzZSAidWNzLTIiOgogICAgICAgICAgY2FzZSAidXRmMTZsZSI6CiAgICAgICAgICBjYXNlICJ1dGYtMTZsZSI6CiAgICAgICAgICAgIHJldHVybiB0cnVlOwogICAgICAgICAgZGVmYXVsdDoKICAgICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICAgIH0KICAgICAgfTsKICAgICAgQnVmZmVyMTAuY29uY2F0ID0gZnVuY3Rpb24gY29uY2F0KGxpc3QsIGxlbmd0aCkgewogICAgICAgIGlmICghQXJyYXkuaXNBcnJheShsaXN0KSkgewogICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcignImxpc3QiIGFyZ3VtZW50IG11c3QgYmUgYW4gQXJyYXkgb2YgQnVmZmVycycpOwogICAgICAgIH0KICAgICAgICBpZiAobGlzdC5sZW5ndGggPT09IDApIHsKICAgICAgICAgIHJldHVybiBCdWZmZXIxMC5hbGxvYygwKTsKICAgICAgICB9CiAgICAgICAgbGV0IGk7CiAgICAgICAgaWYgKGxlbmd0aCA9PT0gdm9pZCAwKSB7CiAgICAgICAgICBsZW5ndGggPSAwOwogICAgICAgICAgZm9yIChpID0gMDsgaSA8IGxpc3QubGVuZ3RoOyArK2kpIHsKICAgICAgICAgICAgbGVuZ3RoICs9IGxpc3RbaV0ubGVuZ3RoOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBjb25zdCBidWZmZXIgPSBCdWZmZXIxMC5hbGxvY1Vuc2FmZShsZW5ndGgpOwogICAgICAgIGxldCBwb3MgPSAwOwogICAgICAgIGZvciAoaSA9IDA7IGkgPCBsaXN0Lmxlbmd0aDsgKytpKSB7CiAgICAgICAgICBsZXQgYnVmID0gbGlzdFtpXTsKICAgICAgICAgIGlmIChpc0luc3RhbmNlKGJ1ZiwgVWludDhBcnJheSkpIHsKICAgICAgICAgICAgaWYgKHBvcyArIGJ1Zi5sZW5ndGggPiBidWZmZXIubGVuZ3RoKSB7CiAgICAgICAgICAgICAgaWYgKCFCdWZmZXIxMC5pc0J1ZmZlcihidWYpKQogICAgICAgICAgICAgICAgYnVmID0gQnVmZmVyMTAuZnJvbShidWYpOwogICAgICAgICAgICAgIGJ1Zi5jb3B5KGJ1ZmZlciwgcG9zKTsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICBVaW50OEFycmF5LnByb3RvdHlwZS5zZXQuY2FsbChidWZmZXIsIGJ1ZiwgcG9zKTsKICAgICAgICAgICAgfQogICAgICAgICAgfSBlbHNlIGlmICghQnVmZmVyMTAuaXNCdWZmZXIoYnVmKSkgewogICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCcibGlzdCIgYXJndW1lbnQgbXVzdCBiZSBhbiBBcnJheSBvZiBCdWZmZXJzJyk7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBidWYuY29weShidWZmZXIsIHBvcyk7CiAgICAgICAgICB9CiAgICAgICAgICBwb3MgKz0gYnVmLmxlbmd0aDsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIGJ1ZmZlcjsKICAgICAgfTsKICAgICAgZnVuY3Rpb24gYnl0ZUxlbmd0aChzdHJpbmcsIGVuY29kaW5nKSB7CiAgICAgICAgaWYgKEJ1ZmZlcjEwLmlzQnVmZmVyKHN0cmluZykpIHsKICAgICAgICAgIHJldHVybiBzdHJpbmcubGVuZ3RoOwogICAgICAgIH0KICAgICAgICBpZiAoQXJyYXlCdWZmZXIuaXNWaWV3KHN0cmluZykgfHwgaXNJbnN0YW5jZShzdHJpbmcsIEFycmF5QnVmZmVyKSkgewogICAgICAgICAgcmV0dXJuIHN0cmluZy5ieXRlTGVuZ3RoOwogICAgICAgIH0KICAgICAgICBpZiAodHlwZW9mIHN0cmluZyAhPT0gInN0cmluZyIpIHsKICAgICAgICAgIHRocm93IG5ldyBUeXBlRXJyb3IoJ1RoZSAic3RyaW5nIiBhcmd1bWVudCBtdXN0IGJlIG9uZSBvZiB0eXBlIHN0cmluZywgQnVmZmVyLCBvciBBcnJheUJ1ZmZlci4gUmVjZWl2ZWQgdHlwZSAnICsgdHlwZW9mIHN0cmluZyk7CiAgICAgICAgfQogICAgICAgIGNvbnN0IGxlbiA9IHN0cmluZy5sZW5ndGg7CiAgICAgICAgY29uc3QgbXVzdE1hdGNoID0gYXJndW1lbnRzLmxlbmd0aCA+IDIgJiYgYXJndW1lbnRzWzJdID09PSB0cnVlOwogICAgICAgIGlmICghbXVzdE1hdGNoICYmIGxlbiA9PT0gMCkKICAgICAgICAgIHJldHVybiAwOwogICAgICAgIGxldCBsb3dlcmVkQ2FzZSA9IGZhbHNlOwogICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgc3dpdGNoIChlbmNvZGluZykgewogICAgICAgICAgICBjYXNlICJhc2NpaSI6CiAgICAgICAgICAgIGNhc2UgImxhdGluMSI6CiAgICAgICAgICAgIGNhc2UgImJpbmFyeSI6CiAgICAgICAgICAgICAgcmV0dXJuIGxlbjsKICAgICAgICAgICAgY2FzZSAidXRmOCI6CiAgICAgICAgICAgIGNhc2UgInV0Zi04IjoKICAgICAgICAgICAgICByZXR1cm4gdXRmOFRvQnl0ZXMoc3RyaW5nKS5sZW5ndGg7CiAgICAgICAgICAgIGNhc2UgInVjczIiOgogICAgICAgICAgICBjYXNlICJ1Y3MtMiI6CiAgICAgICAgICAgIGNhc2UgInV0ZjE2bGUiOgogICAgICAgICAgICBjYXNlICJ1dGYtMTZsZSI6CiAgICAgICAgICAgICAgcmV0dXJuIGxlbiAqIDI7CiAgICAgICAgICAgIGNhc2UgImhleCI6CiAgICAgICAgICAgICAgcmV0dXJuIGxlbiA+Pj4gMTsKICAgICAgICAgICAgY2FzZSAiYmFzZTY0IjoKICAgICAgICAgICAgICByZXR1cm4gYmFzZTY0VG9CeXRlcyhzdHJpbmcpLmxlbmd0aDsKICAgICAgICAgICAgZGVmYXVsdDoKICAgICAgICAgICAgICBpZiAobG93ZXJlZENhc2UpIHsKICAgICAgICAgICAgICAgIHJldHVybiBtdXN0TWF0Y2ggPyAtMSA6IHV0ZjhUb0J5dGVzKHN0cmluZykubGVuZ3RoOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBlbmNvZGluZyA9ICgiIiArIGVuY29kaW5nKS50b0xvd2VyQ2FzZSgpOwogICAgICAgICAgICAgIGxvd2VyZWRDYXNlID0gdHJ1ZTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgICAgQnVmZmVyMTAuYnl0ZUxlbmd0aCA9IGJ5dGVMZW5ndGg7CiAgICAgIGZ1bmN0aW9uIHNsb3dUb1N0cmluZyhlbmNvZGluZywgc3RhcnQsIGVuZCkgewogICAgICAgIGxldCBsb3dlcmVkQ2FzZSA9IGZhbHNlOwogICAgICAgIGlmIChzdGFydCA9PT0gdm9pZCAwIHx8IHN0YXJ0IDwgMCkgewogICAgICAgICAgc3RhcnQgPSAwOwogICAgICAgIH0KICAgICAgICBpZiAoc3RhcnQgPiB0aGlzLmxlbmd0aCkgewogICAgICAgICAgcmV0dXJuICIiOwogICAgICAgIH0KICAgICAgICBpZiAoZW5kID09PSB2b2lkIDAgfHwgZW5kID4gdGhpcy5sZW5ndGgpIHsKICAgICAgICAgIGVuZCA9IHRoaXMubGVuZ3RoOwogICAgICAgIH0KICAgICAgICBpZiAoZW5kIDw9IDApIHsKICAgICAgICAgIHJldHVybiAiIjsKICAgICAgICB9CiAgICAgICAgZW5kID4+Pj0gMDsKICAgICAgICBzdGFydCA+Pj49IDA7CiAgICAgICAgaWYgKGVuZCA8PSBzdGFydCkgewogICAgICAgICAgcmV0dXJuICIiOwogICAgICAgIH0KICAgICAgICBpZiAoIWVuY29kaW5nKQogICAgICAgICAgZW5jb2RpbmcgPSAidXRmOCI7CiAgICAgICAgd2hpbGUgKHRydWUpIHsKICAgICAgICAgIHN3aXRjaCAoZW5jb2RpbmcpIHsKICAgICAgICAgICAgY2FzZSAiaGV4IjoKICAgICAgICAgICAgICByZXR1cm4gaGV4U2xpY2UodGhpcywgc3RhcnQsIGVuZCk7CiAgICAgICAgICAgIGNhc2UgInV0ZjgiOgogICAgICAgICAgICBjYXNlICJ1dGYtOCI6CiAgICAgICAgICAgICAgcmV0dXJuIHV0ZjhTbGljZSh0aGlzLCBzdGFydCwgZW5kKTsKICAgICAgICAgICAgY2FzZSAiYXNjaWkiOgogICAgICAgICAgICAgIHJldHVybiBhc2NpaVNsaWNlKHRoaXMsIHN0YXJ0LCBlbmQpOwogICAgICAgICAgICBjYXNlICJsYXRpbjEiOgogICAgICAgICAgICBjYXNlICJiaW5hcnkiOgogICAgICAgICAgICAgIHJldHVybiBsYXRpbjFTbGljZSh0aGlzLCBzdGFydCwgZW5kKTsKICAgICAgICAgICAgY2FzZSAiYmFzZTY0IjoKICAgICAgICAgICAgICByZXR1cm4gYmFzZTY0U2xpY2UodGhpcywgc3RhcnQsIGVuZCk7CiAgICAgICAgICAgIGNhc2UgInVjczIiOgogICAgICAgICAgICBjYXNlICJ1Y3MtMiI6CiAgICAgICAgICAgIGNhc2UgInV0ZjE2bGUiOgogICAgICAgICAgICBjYXNlICJ1dGYtMTZsZSI6CiAgICAgICAgICAgICAgcmV0dXJuIHV0ZjE2bGVTbGljZSh0aGlzLCBzdGFydCwgZW5kKTsKICAgICAgICAgICAgZGVmYXVsdDoKICAgICAgICAgICAgICBpZiAobG93ZXJlZENhc2UpCiAgICAgICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCJVbmtub3duIGVuY29kaW5nOiAiICsgZW5jb2RpbmcpOwogICAgICAgICAgICAgIGVuY29kaW5nID0gKGVuY29kaW5nICsgIiIpLnRvTG93ZXJDYXNlKCk7CiAgICAgICAgICAgICAgbG93ZXJlZENhc2UgPSB0cnVlOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgICBCdWZmZXIxMC5wcm90b3R5cGUuX2lzQnVmZmVyID0gdHJ1ZTsKICAgICAgZnVuY3Rpb24gc3dhcChiLCBuLCBtKSB7CiAgICAgICAgY29uc3QgaSA9IGJbbl07CiAgICAgICAgYltuXSA9IGJbbV07CiAgICAgICAgYlttXSA9IGk7CiAgICAgIH0KICAgICAgQnVmZmVyMTAucHJvdG90eXBlLnN3YXAxNiA9IGZ1bmN0aW9uIHN3YXAxNigpIHsKICAgICAgICBjb25zdCBsZW4gPSB0aGlzLmxlbmd0aDsKICAgICAgICBpZiAobGVuICUgMiAhPT0gMCkgewogICAgICAgICAgdGhyb3cgbmV3IFJhbmdlRXJyb3IoIkJ1ZmZlciBzaXplIG11c3QgYmUgYSBtdWx0aXBsZSBvZiAxNi1iaXRzIik7CiAgICAgICAgfQogICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgbGVuOyBpICs9IDIpIHsKICAgICAgICAgIHN3YXAodGhpcywgaSwgaSArIDEpOwogICAgICAgIH0KICAgICAgICByZXR1cm4gdGhpczsKICAgICAgfTsKICAgICAgQnVmZmVyMTAucHJvdG90eXBlLnN3YXAzMiA9IGZ1bmN0aW9uIHN3YXAzMigpIHsKICAgICAgICBjb25zdCBsZW4gPSB0aGlzLmxlbmd0aDsKICAgICAgICBpZiAobGVuICUgNCAhPT0gMCkgewogICAgICAgICAgdGhyb3cgbmV3IFJhbmdlRXJyb3IoIkJ1ZmZlciBzaXplIG11c3QgYmUgYSBtdWx0aXBsZSBvZiAzMi1iaXRzIik7CiAgICAgICAgfQogICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgbGVuOyBpICs9IDQpIHsKICAgICAgICAgIHN3YXAodGhpcywgaSwgaSArIDMpOwogICAgICAgICAgc3dhcCh0aGlzLCBpICsgMSwgaSArIDIpOwogICAgICAgIH0KICAgICAgICByZXR1cm4gdGhpczsKICAgICAgfTsKICAgICAgQnVmZmVyMTAucHJvdG90eXBlLnN3YXA2NCA9IGZ1bmN0aW9uIHN3YXA2NCgpIHsKICAgICAgICBjb25zdCBsZW4gPSB0aGlzLmxlbmd0aDsKICAgICAgICBpZiAobGVuICUgOCAhPT0gMCkgewogICAgICAgICAgdGhyb3cgbmV3IFJhbmdlRXJyb3IoIkJ1ZmZlciBzaXplIG11c3QgYmUgYSBtdWx0aXBsZSBvZiA2NC1iaXRzIik7CiAgICAgICAgfQogICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgbGVuOyBpICs9IDgpIHsKICAgICAgICAgIHN3YXAodGhpcywgaSwgaSArIDcpOwogICAgICAgICAgc3dhcCh0aGlzLCBpICsgMSwgaSArIDYpOwogICAgICAgICAgc3dhcCh0aGlzLCBpICsgMiwgaSArIDUpOwogICAgICAgICAgc3dhcCh0aGlzLCBpICsgMywgaSArIDQpOwogICAgICAgIH0KICAgICAgICByZXR1cm4gdGhpczsKICAgICAgfTsKICAgICAgQnVmZmVyMTAucHJvdG90eXBlLnRvU3RyaW5nID0gZnVuY3Rpb24gdG9TdHJpbmcoKSB7CiAgICAgICAgY29uc3QgbGVuZ3R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KICAgICAgICAgICAgcmV0dXJuIC0xOwogICAgICAgICAgZWxzZQogICAgICAgICAgICBieXRlT2Zmc2V0ID0gYnVmZmVyLmxlbmd0aCAtIDE7CiAgICAgICAgfSBlbHNlIGlmIChieXRlT2Zmc2V0IDwgMCkgewogICAgICAgICAgaWYgKGRpcikKICAgICAgICAgICAgYnl0ZU9mZnNldCA9IDA7CiAgICAgICAgICBlbHNlCiAgICAgICAgICAgIHJldHVybiAtMTsKICAgICAgICB9CiAgICAgICAgaWYgKHR5cGVvZiB2YWwgPT09ICJzdHJpbmciKSB7CiAgICAgICAgICB2YWwgPSBCdWZmZXIxMC5mcm9tKHZhbCwgZW5jb2RpbmcpOwogICAgICAgIH0KICAgICAgICBpZiAoQnVmZmVyMTAuaXNCdWZmZXIodmFsKSkgewogICAgICAgICAgaWYgKHZhbC5sZW5ndGggPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIC0xOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIGFycmF5SW5kZXhPZihidWZmZXIsIHZhbCwgYnl0ZU9mZnNldCwgZW5jb2RpbmcsIGRpcik7CiAgICAgICAgfSBlbHNlIGlmICh0eXBlb2YgdmFsID09PSAibnVtYmVyIikgewogICAgICAgICAgdmFsID0gdmFsICYgMjU1OwogICAgICAgICAgaWYgKHR5cGVvZiBVaW50OEFycmF5LnByb3RvdHlwZS5pbmRleE9mID09PSAiZnVuY3Rpb24iKSB7CiAgICAgICAgICAgIGlmIChkaXIpIHsKICAgICAgICAgICAgICByZXR1cm4gVWludDhBcnJheS5wcm90b3R5cGUuaW5kZXhPZi5jYWxsKGJ1ZmZlciwgdmFsLCBieXRlT2Zmc2V0KTsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICByZXR1cm4gVWludDhBcnJheS5wcm90b3R5cGUubGFzdEluZGV4T2YuY2FsbChidWZmZXIsIHZhbCwgYnl0ZU9mZnNldCk7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBhcnJheUluZGV4T2YoYnVmZmVyLCBbdmFsXSwgYnl0ZU9mZnNldCwgZW5jb2RpbmcsIGRpcik7CiAgICAgICAgfQogICAgICAgIHRocm93IG5ldyBUeXBlRXJyb3IoInZhbCBtdXN0IGJlIHN0cmluZywgbnVtYmVyIG9yIEJ1ZmZlciIpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGFycmF5SW5kZXhPZihhcnIsIHZhbCwgYnl0ZU9mZnNldCwgZW5jb2RpbmcsIGRpcikgewogICAgICAgIGxldCBpbmRleFNpemUgPSAxOwogICAgICAgIGxldCBhcnJMZW5ndGggPSBhcnIubGVuZ3RoOwogICAgICAgIGxldCB2YWxMZW5ndGggPSB2YWwubGVuZ3RoOwogICAgICAgIGlmIChlbmNvZGluZyAhPT0gdm9pZCAwKSB7CiAgICAgICAgICBlbmNvZGluZyA9IFN0cmluZyhlbmNvZGluZykudG9Mb3dlckNhc2UoKTsKICAgICAgICAgIGlmIChlbmNvZGluZyA9PT0gInVjczIiIHx8IGVuY29kaW5nID09PSAidWNzLTIiIHx8IGVuY29kaW5nID09PSAidXRmMTZsZSIgfHwgZW5jb2RpbmcgPT09ICJ1dGYtMTZsZSIpIHsKICAgICAgICAgICAgaWYgKGFyci5sZW5ndGggPCAyIHx8IHZhbC5sZW5ndGggPCAyKSB7CiAgICAgICAgICAgICAgcmV0dXJuIC0xOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGluZGV4U2l6ZSA9IDI7CiAgICAgICAgICAgIGFyckxlbmd0aCAvPSAyOwogICAgICAgICAgICB2YWxMZW5ndGggLz0gMjsKICAgICAgICAgICAgYnl0ZU9mZnNldCAvPSAyOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBmdW5jdGlvbiByZWFkKGJ1ZiwgaTIpIHsKICAgICAgICAgIGlmIChpbmRleFNpemUgPT09IDEpIHsKICAgICAgICAgICAgcmV0dXJuIGJ1ZltpMl07CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICByZXR1cm4gYnVmLnJlYWRVSW50MTZCRShpMiAqIGluZGV4U2l6ZSk7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGxldCBpOwogICAgICAgIGlmIChkaXIpIHsKICAgICAgICAgIGxldCBmb3VuZEluZGV4ID0gLTE7CiAgICAgICAgICBmb3IgKGkgPSBieXRlT2Zmc2V0OyBpIDwgYXJyTGVuZ3RoOyBpKyspIHsKICAgICAgICAgICAgaWYgKHJlYWQoYXJyLCBpKSA9PT0gcmVhZCh2YWwsIGZvdW5kSW5kZXggPT09IC0xID8gMCA6IGkgLSBmb3VuZEluZGV4KSkgewogICAgICAgICAgICAgIGlmIChmb3VuZEluZGV4ID09PSAtMSkKICAgICAgICAgICAgICAgIGZvdW5kSW5kZXggPSBpOwogICAgICAgICAgICAgIGlmIChpIC0gZm91bmRJbmRleCArIDEgPT09IHZhbExlbmd0aCkKICAgICAgICAgICAgICAgIHJldHVybiBmb3VuZEluZGV4ICogaW5kZXhTaXplOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIGlmIChmb3VuZEluZGV4ICE9PSAtMSkKICAgICAgICAgICAgICAgIGkgLT0gaSAtIGZvdW5kSW5kZXg7CiAgICAgICAgICAgICAgZm91bmRJbmRleCA9IC0xOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIGlmIChieXRlT2Zmc2V0ICsgdmFsTGVuZ3RoID4gYXJyTGVuZ3RoKQogICAgICAgICAgICBieXRlT2Zmc2V0ID0gYXJyTGVuZ3RoIC0gdmFsTGVuZ3RoOwogICAgICAgICAgZm9yIChpID0gYnl0ZU9mZnNldDsgaSA+PSAwOyBpLS0pIHsKICAgICAgICAgICAgbGV0IGZvdW5kID0gdHJ1ZTsKICAgICAgICAgICAgZm9yIChsZXQgaiA9IDA7IGogPCB2YWxMZW5ndGg7IGorKykgewogICAgICAgICAgICAgIGlmIChyZWFkKGFyciwgaSArIGopICE9PSByZWFkKHZhbCwgaikpIHsKICAgICAgICAgICAgICAgIGZvdW5kID0gZmFsc2U7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKGZvdW5kKQogICAgICAgICAgICAgIHJldHVybiBpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gLTE7CiAgICAgIH0KICAgICAgQnVmZmVyMTAucHJvdG90eXBlLmluY2x1ZGVzID0gZnVuY3Rpb24gaW5jbHVkZXModmFsLCBieXRlT2Zmc2V0LCBlbmNvZGluZykgewogICAgICAgIHJldHVybiB0aGlzLmluZGV4T2YodmFsLCBieXRlT2Zmc2V0LCBlbmNvZGluZykgIT09IC0xOwogICAgICB9OwogICAgICBCdWZmZXIxMC5wcm90b3R5cGUuaW5kZXhPZiA9IGZ1bmN0aW9uIGluZGV4T2YodmFsLCBieXRlT2Zmc2V0LCBlbmNvZGluZykgewogICAgICAgIHJldHVybiBiaWRpcmVjdGlvbmFsSW5kZXhPZih0aGlzLCB2YWwsIGJ5dGVPZmZzZXQsIGVuY29kaW5nLCB0cnVlKTsKICAgICAgfTsKICAgICAgQnVmZmVyMTAucHJvdG90eXBlLmxhc3RJbmRleE9mID0gZnVuY3Rpb24gbGFzdEluZGV4T2YodmFsLCBieXRlT2Zmc2V0LCBlbmNvZGluZykgewogICAgICAgIHJldHVybiBiaWRpcmVjdGlvbmFsSW5kZXhPZih0aGlzLCB2YWwsIGJ5dGVPZmZzZXQsIGVuY29kaW5nLCBmYWxzZSk7CiAgICAgIH07CiAgICAgIGZ1bmN0aW9uIGhleFdyaXRlKGJ1Ziwgc3RyaW5nLCBvZmZzZXQsIGxlbmd0aCkgewogICAgICAgIG9mZnNldCA9IE51bWJlcihvZmZzZXQpIHx8IDA7CiAgICAgICAgY29uc3QgcmVtYWluaW5nID0gYnVmLmxlbmd0aCAtIG9mZnNldDsKICAgICAgICBpZiAoIWxlbmd0aCkg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ogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgZW5jb2RpbmcgPSBsZW5ndGg7CiAgICAgICAgICAgIGxlbmd0aCA9IHZvaWQgMDsKICAgICAgICAgIH0KICAgICAgICB9IGVsc2UgewogICAgICAgICAgdGhyb3cgbmV3IEVycm9yKCJCdWZmZXIud3JpdGUoc3RyaW5nLCBlbmNvZGluZywgb2Zmc2V0WywgbGVuZ3RoXSkgaXMgbm8gbG9uZ2VyIHN1cHBvcnRlZCIpOwogICAgICAgIH0KICAgICAgICBjb25zdCByZW1haW5pbmcgPSB0aGlzLmxlbmd0aCAtIG9mZnNldDsKICAgICAgICBpZiAobGVuZ3RoID09PSB2b2lkIDAgfHwgbGVuZ3RoID4gcmVtYWluaW5nKQogICAgICAgICAgbGVuZ3RoID0gcmVtYWluaW5nOwogICAgICAgIGlmIChzdHJpbmcubGVuZ3RoID4gMCAmJiAobGVuZ3RoIDwgMCB8fCBvZmZzZXQgPCAwKSB8fCBvZmZzZXQgPiB0aGlzLmxlbmd0aCkgewogICAgICAgICAgdGhyb3cgbmV3IFJhbmdlRXJyb3IoIkF0dGVtcHQgdG8gd3JpdGUgb3V0c2lkZSBidWZmZXIgYm91bmRzIik7CiAgICAgICAgfQogICAgICAgIGlmICghZW5jb2RpbmcpCiAgICAgICAgICBlbmNvZGluZyA9ICJ1dGY4IjsKICAgICAgICBsZXQgbG93ZXJlZENhc2UgPSBmYWxzZTsKICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgIHN3aXRjaCAoZW5jb2RpbmcpIHsKICAgICAgICAgICAgY2FzZSAiaGV4IjoKICAgICAgICAgICAgICByZXR1cm4gaGV4V3JpdGUodGhpcywgc3RyaW5nLCBvZmZzZXQsIGxlbmd0aCk7CiAgICAgICAgICAgIGNhc2UgInV0ZjgiOgogICAgICAgICAgICBjYXNlICJ1dGYtOCI6CiAgICAgICAgICAgICAgcmV0dXJuIHV0ZjhXcml0ZSh0aGlzLCBzdHJpbmcsIG9mZnNldCwgbGVuZ3RoKTsKICAgICAgICAgICAgY2FzZSAiYXNjaWkiOgogICAgICAgICAgICBjYXNlICJsYXRpbjEiOgogICAgICAgICAgICBjYXNlICJiaW5hcnkiOgogICAgICAgICAgICAgIHJldHVybiBhc2NpaVdyaXRlKHRoaXMsIHN0cmluZywgb2Zmc2V0LCBsZW5ndGgpOwogICAgICAgICAgICBjYXNlICJiYXNlNjQiOgogICAgICAgICAgICAgIHJldHVybiBiYXNlNjRXcml0ZSh0aGlzLCBzdHJpbmcsIG9mZnNldCwgbGVuZ3RoKTsKICAgICAgICAgICAgY2FzZSAidWNzMiI6CiAgICAgICAgICAgIGNhc2UgInVjcy0yIjoKICAgICAgICAgICAgY2FzZSAidXRmMTZsZSI6CiAgICAgICAgICAgIGNhc2UgInV0Zi0xNmxlIjoKICAgICAgICAgICAgICByZXR1cm4gdWNzMldyaXRlKHRoaXMsIHN0cmluZywgb2Zmc2V0LCBsZW5ndGgpOwogICAgICAgICAgICBkZWZhdWx0OgogICAgICAgICAgICAgIGlmIChsb3dlcmVkQ2FzZSkKICAgICAgICAgICAgICAgIHRocm93IG5ldyBUeXBlRXJyb3IoIlVua25vd24gZW5jb2Rpbmc6ICIgKyBlbmNvZGluZyk7CiAgICAgICAgICAgICAgZW5jb2RpbmcgPSAoIiIgKyBlbmNvZGluZykudG9Mb3dlckNhc2UoKTsKICAgICAgICAgICAgICBsb3dlcmVkQ2FzZSA9IHRydWU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9OwogICAgICBCdWZmZXIxMC5wcm90b3R5cGUudG9KU09OID0gZnVuY3Rpb24gdG9KU09OKCkgewogICAgICAgIHJldHVybiB7CiAgICAgICAgICB0eXBlOiAiQnVmZmVyIiwKICAgICAgICAgIGRhdGE6IEFycmF5LnByb3RvdHlwZS5zbGljZS5jYWxsKHRoaXMuX2FyciB8fCB0aGlzLCAwKQogICAgICAgIH07CiAgICAgIH07CiAgICAgIGZ1bmN0aW9uIGJhc2U2NFNsaWNl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gICAgICAgICAgICAgY2FzZSAyOgogICAgICAgICAgICAgICAgc2Vjb25kQnl0ZSA9IGJ1ZltpICsgMV07CiAgICAgICAgICAgICAgICBpZiAoKHNlY29uZEJ5dGUgJiAxOTIpID09PSAxMjgpIHsKICAgICAgICAgICAgICAgICAgdGVtcENvZGVQb2ludCA9IChmaXJzdEJ5dGUgJiAzMSkgPDwgNiB8IHNlY29uZEJ5dGUgJiA2MzsKICAgICAgICAgICAgICAgICAgaWYgKHRlbXBDb2RlUG9pbnQgPiAxMjcpIHsKICAgICAgICAgICAgICAgICAgICBjb2RlUG9pbnQgPSB0ZW1wQ29kZVBvaW50OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICBjYXNlIDM6CiAgICAgICAgICAgICAgICBzZWNvbmRCeXRlID0gYnVmW2kgKyAxXTsKICAgICAgICAgICAgICAgIHRoaXJkQnl0ZSA9IGJ1ZltpICsgMl07CiAgICAgICAgICAgICAgICBpZiAoKHNlY29uZEJ5dGUgJiAxOTIpID09PSAxMjggJiYgKHRoaXJkQnl0ZSAmIDE5MikgPT09IDEyOCkgewogICAgICAgICAgICAgICAgICB0ZW1wQ29kZVBvaW50ID0gKGZpcnN0Qnl0ZSAmIDE1KSA8PCAxMiB8IChzZWNvbmRCeXRlICYgNjMpIDw8IDYgfCB0aGlyZEJ5dGUgJiA2MzsKICAgICAgICAgICAgICAgICAgaWYgKHRlbXBDb2RlUG9pbnQgPiAyMDQ3ICYmICh0ZW1wQ29kZVBvaW50IDwgNTUyOTYgfHwgdGVtcENvZGVQb2ludCA+IDU3MzQzKSkgewogICAgICAgICAgICAgICAgICAgIGNvZGVQb2ludCA9IHRlbXBDb2RlUG9pbnQ7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgIGNhc2UgNDoKICAgICAgICAgICAgICAgIHNlY29uZEJ5dGUgPSBidWZbaSArIDFdOwogICAgICAgICAgICAgICAgdGhpcmRCeXRlID0gYnVmW2kgKyAyXTsKICAgICAgICAgICAgICAgIGZvdXJ0aEJ5dGUgPSBidWZbaSArIDNdOwogICAgICAgICAgICAgICAgaWYgKChzZWNvbmRCeXRlICYgMTkyKSA9PT0gMTI4ICYmICh0aGlyZEJ5dGUgJiAxOTIpID09PSAxMjggJiYgKGZvdXJ0aEJ5dGUgJiAxOTIpID09PSAxMjgpIHsKICAgICAgICAgICAgICAgICAgdGVtcENvZGVQb2ludCA9IChmaXJzdEJ5dGUgJiAxNSkgPDwgMTggfCAoc2Vjb25kQnl0ZSAmIDYzKSA8PCAxMiB8ICh0aGlyZEJ5dGUgJiA2MykgPDwgNiB8IGZvdXJ0aEJ5dGUgJiA2MzsKICAgICAgICAgICAgICAgICAgaWYgKHRlbXBDb2RlUG9pbnQgPiA2NTUzNSAmJiB0ZW1wQ29kZVBvaW50IDwgMTExNDExMikgewogICAgICAgICAgICAgICAgICAgIGNvZGVQb2ludCA9IHRlbXBDb2RlUG9pbnQ7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgaWYgKGNvZGVQb2ludCA9PT0gbnVsbCkgewogICAgICAgICAgICBjb2RlUG9pbnQgPSA2NTUzMzsKICAgICAgICAgICAgYnl0ZXNQZXJTZXF1ZW5jZSA9IDE7CiAgICAgICAgICB9IGVsc2UgaWYgKGNvZGVQb2ludCA+IDY1NTM1KSB7CiAgICAgICAgICAgIGNvZGVQb2ludCAtPSA2NTUzNjsKICAgICAgICAgICAgcmVzLnB1c2goY29kZVBvaW50ID4+PiAxMCAmIDEwMjMgfCA1NTI5Nik7CiAgICAgICAgICAgIGNvZGVQb2ludCA9IDU2MzIwIHwgY29kZVBvaW50ICYgMTAyMzsKICAgICAgICAgIH0KICAgICAgICAgIHJlcy5wdXNoKGNvZGVQb2ludCk7CiAgICAgICAgICBpICs9IGJ5dGVzUGVyU2VxdWVuY2U7CiAgICAgICAgfQogICAgICAgIHJldHVybiBkZWNvZGVDb2RlUG9pbnRzQXJyYXkocmVzKTsKICAgICAgfQogICAgICB2YXIgTUFYX0FSR1VNRU5UU19MRU5HVEggPSA0MDk2OwogICAgICBmdW5jdGlvbiBkZWNvZGVDb2RlUG9pbnRzQXJyYXkoY29kZVBvaW50cykgewogICAgICAgIGNvbnN0IGxlbiA9IGNvZGVQb2ludHMubGVuZ3RoOwogICAgICAgIGlmIChsZW4gPD0gTUFYX0FSR1VNRU5UU19MRU5HVEgpIHsKICAgICAgICAgIHJldHVybiBTdHJpbmcuZnJvbUNoYXJDb2RlLmFwcGx5KFN0cmluZywgY29kZVBvaW50cyk7CiAgICAgICAgfQogICAgICAgIGxldCByZXMgPSAiIjsKICAgICAgICBsZXQgaSA9IDA7CiAgICAgICAgd2hpbGUgKGkgPCBsZW4pIHsKICAgICAgICAgIHJlcyArPSBTdHJpbmcuZnJvbUNoYXJDb2RlLmFwcGx5KFN0cmluZywgY29kZVBvaW50cy5zbGljZShpLCBpICs9IE1BWF9BUkdVTUVOVFNfTEVOR1RIKSk7CiAgICAgICAgfQogICAgICAgIHJldHVybiByZXM7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gYXNjaWlTbGljZShidWYsIHN0YXJ0LCBlbmQpIHsKICAgICAgICBsZXQgcmV0ID0gIiI7CiAgICAgICAgZW5kID0gTWF0aC5taW4oYnVmLmxlbmd0aCwgZW5kKTsKICAgICAgICBmb3IgKGxldCBpID0gc3RhcnQ7IGkgPCBlbmQ7ICsraSkgewogICAgICAgICAgcmV0ICs9IFN0cmluZy5mcm9tQ2hhckNvZGUoYnVmW2ldICYgMTI3KTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHJldDsKICAgICAgfQogICAgICBmdW5jdGlvbiBsYXRpbjFTbGljZShidWYsIHN0YXJ0LCBlbmQpIHsKICAgICAgICBsZXQgcmV0ID0gIiI7CiAgICAgICAgZW5kID0gTWF0aC5taW4oYnVmLmxlbmd0aCwgZW5kKTsKICAgICAgICBmb3IgKGxldCBpID0gc3RhcnQ7IGkgPCBlbmQ7ICsraSkgewogICAgICAgICAgcmV0ICs9IFN0cmluZy5mcm9tQ2hhckNvZGUoYnVmW2ldKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHJldDsKICAgICAgfQogICAgICBmdW5jdGlvbiBoZXhTbGljZShidWYsIHN0YXJ0LCBlbmQpIHsKICAgICAgICBjb25zdCBsZW4gPSBidWYubGVuZ3RoOwogICAgICAgIGlmICghc3RhcnQgfHwgc3RhcnQgPCAwKQogICAgICAgICAgc3RhcnQgPSAwOwogICAgICAgIGlmICghZW5kIHx8IGVuZCA8IDAgfHwgZW5kID4gbGVuKQogICAgICAgICAgZW5kID0gbGVuOwogICAgICAgIGxldCBvdXQgPSAiIjsKICAgICAgICBmb3IgKGxldCBpID0gc3RhcnQ7IGkgPCBlbmQ7ICsraSkgewogICAgICAgICAgb3V0ICs9IGhleFNsaWNlTG9va3VwVGFibGVbYnVmW2ldXTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIG91dDsKICAgICAgfQogICAgICBmdW5jdGlvbiB1dGYxNmxlU2xpY2UoYnVmLCBzdGFydCwgZW5kKSB7CiAgICAgICAgY29uc3QgYnl0ZXMgPSBidWYuc2xpY2Uoc3RhcnQsIGVuZCk7CiAgICAgICAgbGV0IHJlcyA9ICIiOwogICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgYnl0ZXMubGVuZ3RoIC0gMTsgaSArPSAyKSB7CiAgICAgICAgICByZXMgKz0gU3RyaW5nLmZyb21DaGFyQ29kZShieXRlc1tpXSArIGJ5dGVzW2kgKyAxXSAqIDI1Nik7CiAgICAgICAgfQogICAgICAgIHJldHVybiByZXM7CiAgICAgIH0KICAgICAgQnVmZmVyMTAucHJvdG90eXBlLnNsaWNlID0gZnVuY3Rpb24gc2xpY2Uoc3RhcnQsIGVuZCkgewogICAgICAgIGNvbnN0IGxlbiA9IHRoaXMubGVuZ3RoOwogICAgICAgIHN0YXJ0ID0gfn5zdGFydDsKICAgICAgICBlbmQgPSBlbmQgPT09IHZvaWQgMCA/IGxlbiA6IH5+ZW5kOwogICAgICAgIGlmIChzdGFydCA8IDApIHsKICAgICAgICAgIHN0YXJ0ICs9IGxlbjsKICAgICAgICAgIGlmIChzdGFydCA8IDApCiAgICAgICAgICAgIHN0YXJ0ID0gMDsKICAgICAgICB9IGVsc2UgaWYgKHN0YXJ0ID4gbGVuKSB7CiAgICAgICAgICBzdGFydCA9IGxlbjsKICAgICAgICB9CiAgICAgICAgaWYgKGVuZCA8IDApIHsKICAgICAgICAgIGVuZCArPSBsZW47CiAgICAgICAgICBpZiAoZW5kIDwgMCkKICAgICAgICAgICAgZW5kID0gMDsKICAgICAgICB9IGVsc2UgaWYgKGVuZCA+IGxlbikgewogICAgICAgICAgZW5kID0gbGVuOwogICAgICAgIH0KICAgICAgICBpZiAoZW5kIDwgc3RhcnQpCiAgICAgICAgICBlbmQgPSBzdGFydDsKICAgICAgICBjb25zdCBuZXdCdWYgPSB0aGlzLnN1YmFycmF5KHN0YXJ0LCBlbmQpOwogICAgICAgIE9iamVjdC5zZXRQcm90b3R5cGVPZihuZXdCdWYsIEJ1ZmZlcjEwLnByb3RvdHlwZSk7CiAgICAgICAgcmV0dXJuIG5ld0J1ZjsKICAgICAgfTsKICAgICAgZnVuY3Rpb24gY2hlY2tPZmZzZXQob2Zmc2V0LCBleHQsIGxlbmd0aCkgewogICAgICAgIGlmIChvZmZzZXQgJSAxICE9PSAwIHx8IG9mZnNldCA8IDApCiAgICAgICAgICB0aHJvdyBuZXcgUmFuZ2VFcnJvcigib2Zmc2V0IGlzIG5vdCB1aW50Iik7CiAgICAgICAgaWYgKG9mZnNldCArIGV4dCA+IGxlbmd0aCkKICAgICAgICAgIHRocm93IG5ldyBSYW5nZUVycm9yKCJUcnlpbmcgdG8gYWNjZXNzIGJleW9uZCB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AgICBtdWwgKj0gMTI4OwogICAgICAgIGlmICh2YWwgPj0gbXVsKQogICAgICAgICAgdmFsIC09IE1hdGgucG93KDIsIDggKiBieXRlTGVuZ3RoMik7CiAgICAgICAgcmV0dXJuIHZhbDsKICAgICAgfTsKICAgICAgQnVmZmVyMTAucHJvdG90eXBlLnJlYWRJbnRCRSA9IGZ1bmN0aW9uIHJlYWRJbnRCRShvZmZzZXQsIGJ5dGVMZW5ndGgyLCBub0Fzc2VydCkgewogICAgICAgIG9mZnNldCA9IG9mZnNldCA+Pj4gMDsKICAgICAgICBieXRlTGVuZ3RoMiA9IGJ5dGVMZW5ndGgyID4+PiAwOwogICAgICAgIGlmICghbm9Bc3NlcnQpCiAgICAgICAgICBjaGVja09mZnNldChvZmZzZXQsIGJ5dGVMZW5ndGgyLCB0aGlzLmxlbmd0aCk7CiAgICAgICAgbGV0IGkgPSBieXRlTGVuZ3RoMjsKICAgICAgICBsZXQgbXVsID0gMTsKICAgICAgICBsZXQgdmFsID0gdGhpc1tvZmZzZXQgKyAtLWldOwogICAgICAgIHdoaWxlIChpID4gMCAmJiAobXVsICo9IDI1NikpIHsKICAgICAgICAgIHZhbCArPSB0aGlzW29mZnNldCArIC0taV0gKiBtdWw7CiAgICAgICAgfQogICAgICAgIG11bCAqPSAxMjg7CiAgICAgICAgaWYgKHZhbCA+PSBtdWwpCiAgICAgICAgICB2YWwgLT0gTWF0aC5wb3coMiwgOCAqIGJ5dGVMZW5ndGgyKTsKICAgICAgICByZXR1cm4gdmFsOwogICAgICB9OwogICAgICBCdWZmZXIxMC5wcm90b3R5cGUucmVhZEludDggPSBmdW5jdGlvbiByZWFkSW50OChvZmZzZXQsIG5vQXNzZXJ0KSB7CiAgICAgICAgb2Zmc2V0ID0gb2Zmc2V0ID4+PiAwOwogICAgICAgIGlmICghbm9Bc3NlcnQpCiAgICAgICAgICBjaGVja09mZnNldChvZmZzZXQsIDEsIHRoaXMubGVuZ3RoKTsKICAgICAgICBpZiAoISh0aGlz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ICJzdHJpbmciKSB7CiAgICAgICAgICBpZiAodHlwZW9mIHN0YXJ0ID09PSAic3RyaW5nIikgewogICAgICAgICAgICBlbmNvZGluZyA9IHN0YXJ0OwogICAgICAgICAgICBzdGFydCA9IDA7CiAgICAgICAgICAgIGVuZCA9IHRoaXMubGVuZ3RoOwogICAgICAgICAgfSBlbHNlIGlmICh0eXBlb2YgZW5kID09PSAic3RyaW5nIikgewogICAgICAgICAgICBlbmNvZGluZyA9IGVuZDsKICAgICAgICAgICAgZW5kID0gdGhpcy5sZW5ndGg7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoZW5jb2RpbmcgIT09IHZvaWQgMCAmJiB0eXBlb2YgZW5jb2RpbmcgIT09ICJzdHJpbmciKSB7CiAgICAgICAgICAgIHRocm93IG5ldyBUeXBlRXJyb3IoImVuY29kaW5nIG11c3QgYmUgYSBzdHJpbmciKTsKICAgICAgICAgIH0KICAgICAgICAgIGlmICh0eXBlb2YgZW5jb2RpbmcgPT09ICJzdHJpbmciICYmICFCdWZmZXIxMC5pc0VuY29kaW5nKGVuY29kaW5nKSkgewogICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCJVbmtub3duIGVuY29kaW5nOiAiICsgZW5jb2RpbmcpOwogICAgICAgICAgfQogICAgICAgICAgaWYgKHZhbC5sZW5ndGggPT09IDEpIHsKICAgICAgICAgICAgY29uc3QgY29kZSA9IHZhbC5jaGFyQ29kZUF0KDApOwogICAgICAgICAgICBpZiAoZW5jb2RpbmcgPT09ICJ1dGY4IiAmJiBjb2RlIDwgMTI4IHx8IGVuY29kaW5nID09PSAibGF0aW4xIikgewogICAgICAgICAgICAgIHZhbCA9IGNvZGU7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9IGVsc2UgaWYgKHR5cGVvZiB2YWwgPT09ICJudW1iZXIiKSB7CiAgICAgICAgICB2YWwgPSB2YWwgJiAyNTU7CiAgICAgICAgfSBlbHNlIGlmICh0eXBlb2YgdmFs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IHN0YXJ0XSA9IGJ5dGVzW2kgJSBsZW5dOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gdGhpczsKICAgICAgfTsKICAgICAgdmFyIGVycm9ycyA9IHt9OwogICAgICBmdW5jdGlvbiBFKHN5bSwgZ2V0TWVzc2FnZSwgQmFzZSkgewogICAgICAgIGVycm9yc1tzeW1dID0gY2xhc3MgTm9kZUVycm9yIGV4dGVuZHMgQmFzZSB7CiAgICAgICAgICBjb25zdHJ1Y3RvcigpIHsKICAgICAgICAgICAgc3VwZXIoKTsKICAgICAgICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KHRoaXMsICJtZXNzYWdlIiwgewogICAgICAgICAgICAgIHZhbHVlOiBnZXRNZXNzYWdlLmFwcGx5KHRoaXMsIGFyZ3VtZW50cyksCiAgICAgICAgICAgICAgd3JpdGFibGU6IHRydWUsCiAgICAgICAgICAgICAgY29uZmlndXJhYmxlOiB0cnVlCiAgICAgICAgICAgIH0pOwogICAgICAgICAgICB0aGlzLm5hbWUgPSBgJHt0aGlzLm5hbWV9IFske3N5bX1dYDsKICAgICAgICAgICAgdGhpcy5zdGFjazsKICAgICAgICAgICAgZGVsZXRlIHRoaXMubmFtZTsKICAgICAgICAgIH0KICAgICAgICAgIGdldCBjb2RlKCkgewogICAgICAgICAgICByZXR1cm4gc3ltOwogICAgICAgICAgfQogICAgICAgICAgc2V0IGNvZGUodmFsdWUpIHsKICAgICAgICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KHRoaXMsICJjb2RlIiwgewogICAgICAgICAgICAgIGNvbmZpZ3VyYWJsZTogdHJ1ZSwKICAgICAgICAgICAgICBlbnVtZXJhYmxlOiB0cnVlLAogICAgICAgICAgICAgIHZhbHVlLAogICAgICAgICAgICAgIHdyaXRhYmxlOiB0cnVlCiAgICAgICAgICAgIH0pOwogICAgICAgICAgfQogICAgICAgICAgdG9TdHJpbmcoKSB7CiAgICAgICAgICAgIHJldHVybiBgJHt0aG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gICAgfQogICAgICBmdW5jdGlvbiBjaGVja0ludEJJKHZhbHVlLCBtaW4sIG1heCwgYnVmLCBvZmZzZXQsIGJ5dGVMZW5ndGgyKSB7CiAgICAgICAgaWYgKHZhbHVlID4gbWF4IHx8IHZhbHVlIDwgbWluKSB7CiAgICAgICAgICBjb25zdCBuID0gdHlwZW9mIG1pbiA9PT0gImJpZ2ludCIgPyAibiIgOiAiIjsKICAgICAgICAgIGxldCByYW5nZTsKICAgICAgICAgIGlmIChieXRlTGVuZ3RoMiA+IDMpIHsKICAgICAgICAgICAgaWYgKG1pbiA9PT0gMCB8fCBtaW4gPT09IEJpZ0ludCgwKSkgewogICAgICAgICAgICAgIHJhbmdlID0gYD49IDAke259IGFuZCA8IDIke259ICoqICR7KGJ5dGVMZW5ndGgyICsgMSkgKiA4fSR7bn1gOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHJhbmdlID0gYD49IC0oMiR7bn0gKiogJHsoYnl0ZUxlbmd0aDIgKyAxKSAqIDggLSAxfSR7bn0pIGFuZCA8IDIgKiogJHsoYnl0ZUxlbmd0aDIgKyAxKSAqIDggLSAxfSR7bn1gOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICByYW5nZSA9IGA+PSAke21pbn0ke259IGFuZCA8PSAke21heH0ke259YDsKICAgICAgICAgIH0KICAgICAgICAgIHRocm93IG5ldyBlcnJvcnMuRVJSX09VVF9PRl9SQU5HRSgidmFsdWUiLCByYW5nZSwgdmFsdWUpOwogICAgICAgIH0KICAgICAgICBjaGVja0JvdW5kcyhidWYsIG9mZnNldCwgYnl0ZUxlbmd0aDIpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIHZhbGlkYXRlTnVtYmVyKHZhbHVlLCBuYW1lKSB7CiAgICAgICAgaWYgKHR5cGVvZiB2YWx1ZSAhPT0gIm51bWJlciIpIHsKICAgICAgICAgIHRocm93IG5ldyBlcnJvcnMuRVJSX0lOVkFMSURfQVJ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ywgdW5pdHMpIHsKICAgICAgICB1bml0cyA9IHVuaXRzIHx8IEluZmluaXR5OwogICAgICAgIGxldCBjb2RlUG9pbnQ7CiAgICAgICAgY29uc3QgbGVuZ3RoID0gc3RyaW5nLmxlbmd0aDsKICAgICAgICBsZXQgbGVhZFN1cnJvZ2F0ZSA9IG51bGw7CiAgICAgICAgY29uc3QgYnl0ZXMgPSBbXTsKICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IGxlbmd0aDsgKytpKSB7CiAgICAgICAgICBjb2RlUG9pbnQgPSBzdHJpbmcuY2hhckNvZGVBdChpKTsKICAgICAgICAgIGlmIChjb2RlUG9pbnQgPiA1NTI5NSAmJiBjb2RlUG9pbnQgPCA1NzM0NCkgewogICAgICAgICAgICBpZiAoIWxlYWRTdXJyb2dhdGUpIHsKICAgICAgICAgICAgICBpZiAoY29kZVBvaW50ID4gNTYzMTkpIHsKICAgICAgICAgICAgICAgIGlmICgodW5pdHMgLT0gMykgPiAtMSkKICAgICAgICAgICAgICAgICAgYnl0ZXMucHVzaCgyMzksIDE5MSwgMTg5KTsKICAgICAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgICAgIH0gZWxzZSBpZiAoaSArIDEgPT09IGxlbmd0aCkgewogICAgICAgICAgICAgICAgaWYgKCh1bml0cyAtPSAzKSA+IC0xKQogICAgICAgICAgICAgICAgICBieXRlcy5wdXNoKDIzOSwgMTkxLCAxODkpOwogICAgICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGxlYWRTdXJyb2dhdGUgPSBjb2RlUG9pbnQ7CiAgICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKGNvZGVQb2ludCA8IDU2MzIwKSB7CiAgICAgICAgICAgICAgaWYgKCh1bml0cyAtPSAzKSA+IC0xKQogICAgICAgICAgICAgICAgYnl0ZXMucHVzaCgyMzksIDE5MSwgMTg5KTsKICAgICAgICAgICAgICBsZWFkU3Vycm9nYXRlID0gY29kZVBvaW50OwogICAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGNvZGVQb2ludCA9IChsZWFkU3Vycm9nYXRlIC0gNTUyOTYgPDwgMTAgfCBjb2RlUG9pbnQgLSA1NjMyMCkgKyA2NTUzNjsKICAgICAgICAgIH0gZWxzZSBpZiAobGVhZFN1cnJvZ2F0ZSkgewogICAgICAgICAgICBpZiAoKHVuaXRzIC09IDMpID4gLTEpCiAgICAgICAgICAgICAgYnl0ZXMucHVzaCgyMzksIDE5MSwgMTg5KTsKICAgICAgICAgIH0KICAgICAgICAgIGxlYWRTdXJyb2dhdGUgPSBudWxsOwogICAgICAgICAgaWYgKGNvZGVQb2ludCA8IDEyOCkgewogICAgICAgICAgICBpZiAoKHVuaXRzIC09IDEpIDwgMCkKICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgYnl0ZXMucHVzaChjb2RlUG9pbnQpOwogICAgICAgICAgfSBlbHNlIGlmIChjb2RlUG9pbnQgPCAyMDQ4KSB7CiAgICAgICAgICAgIGlmICgodW5pdHMgLT0gMikgPCAwKQogICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICBieXRlcy5wdXNoKGNvZGVQb2ludCA+PiA2IHwgMTkyLCBjb2RlUG9pbnQgJiA2MyB8IDEyOCk7CiAgICAgICAgICB9IGVsc2UgaWYgKGNvZGVQb2ludCA8IDY1NTM2KSB7CiAgICAgICAgICAgIGlmICgodW5pdHMgLT0gMykgPCAwKQogICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICBieXRlcy5wdXNoKGNvZGVQb2ludCA+PiAxMiB8IDIyNCwgY29kZVBvaW50ID4+IDYgJiA2MyB8IDEyOCwgY29kZVBvaW50ICYgNjMgfCAxMjgpOwogICAgICAgICAgfSBlbHNlIGlmIChjb2RlUG9pbnQgPCAxMTE0MTEyKSB7CiAgICAgICAgICAgIGlmICgodW5pdHMgLT0gNCkgPCAwKQogICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICBieXRlcy5wdXNoKGNvZGVQb2ludCA+PiAxOCB8IDI0MCwgY29kZVBvaW50ID4+IDEyICYgNjMgfCAxMjgsIGNvZGVQb2ludCA+PiA2ICYgNjMgfCAxMjgsIGNvZGVQb2ludCAmIDYzIHwgMTI4KTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHRocm93IG5ldyBFcnJvcigiSW52YWxpZCBjb2RlIHBvaW50Iik7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiBieXRlczsKICAgICAgfQogICAgICBmdW5jdGlvbiBhc2NpaVRvQnl0ZXMoc3RyKSB7CiAgICAgICAgY29uc3QgYnl0ZUFycmF5ID0gW107CiAgICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCBzdHIubGVuZ3RoOyArK2kpIHsKICAgICAgICAgIGJ5dGVBcnJheS5wdXNoKHN0ci5jaGFyQ29kZUF0KGkpICYgMjU1KTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIGJ5dGVBcnJheTsKICAgICAgfQogICAgICBmdW5jdGlvbiB1dGYxNmxlVG9CeXRlcyhzdHIsIHVuaXRzKSB7CiAgICAgICAgbGV0IGMsIGhpLCBsbzsKICAgICAgICBjb25zdCBieXRlQXJyYXkgPSBbXTsKICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IHN0ci5sZW5ndGg7ICsraSkgewogICAgICAgICAgaWYgKCh1bml0cyAtPSAyKSA8IDApCiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgYyA9IHN0ci5jaGFyQ29kZUF0KGkpOwogICAgICAgICAgaGkgPSBjID4+IDg7CiAgICAgICAgICBsbyA9IGMgJSAyNTY7CiAgICAgICAgICBieXRlQXJyYXkucHVzaChsbyk7CiAgICAgICAgICBieXRlQXJyYXkucHVzaChoaSk7CiAgICAgICAgfQogICAgICAgIHJldHVybiBieXRlQXJyYXk7CiAgICAgIH0KICA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HJvdG90eXBlLCBwcm90b1Byb3BzKTsKICAgICAgICBpZiAoc3RhdGljUHJvcHMpCiAgICAgICAgICBfZGVmaW5lUHJvcGVydGllcyhDb25zdHJ1Y3Rvciwgc3RhdGljUHJvcHMpOwogICAgICAgIE9iamVjdC5kZWZpbmVQcm9wZXJ0eShDb25zdHJ1Y3RvciwgInByb3RvdHlwZSIsIHsKICAgICAgICAgIHdyaXRhYmxlOiBmYWxzZQogICAgICAgIH0pOwogICAgICAgIHJldHVybiBDb25zdHJ1Y3RvcjsKICAgICAgfQogICAgICBmdW5jdGlvbiBfaW5oZXJpdHMoc3ViQ2xhc3MsIHN1cGVyQ2xhc3MpIHsKICAgICAgICBpZiAodHlwZW9mIHN1cGVyQ2xhc3MgIT09ICJmdW5jdGlvbiIgJiYgc3VwZXJDbGFzcyAhPT0gbnVsbCkgewogICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcigiU3VwZXIgZXhwcmVzc2lvbiBtdXN0IGVpdGhlciBiZSBudWxsIG9yIGEgZnVuY3Rpb24iKTsKICAgICAgICB9CiAgICAgICAgc3ViQ2xhc3MucHJvdG90eXBlID0gT2JqZWN0LmNyZWF0ZShzdXBlckNsYXNzICYmIHN1cGVyQ2xhc3MucHJvdG90eXBlLCB7CiAgICAgICAgICBjb25zdHJ1Y3RvcjogewogICAgICAgICAgICB2YWx1ZTogc3ViQ2xhc3MsCiAgICAgICAgICAgIHdyaXRhYmxlOiB0cnVlLAogICAgICAgICAgICBjb25maWd1cmFibGU6IHRydWUKICAgICAgICAgIH0KICAgICAgICB9KTsKICAgICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkoc3ViQ2xhc3MsICJwcm90b3R5cGUiLCB7CiAgICAgICAgICB3cml0YWJsZTogZmFsc2UKICAgICAgICB9KTsKICAgICAgICBpZiAoc3VwZXJDbGFzcykKICAgICAgICAgIF9zZXRQcm90b3R5cGVPZihzdWJDbGFzcywgc3VwZXJDbGFzcyk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gX2dldFByb3RvdHlwZU9mKG8pIHsKICAgICAgICBfZ2V0UHJvdG90eXBlT2YgPSBPYmplY3Quc2V0UHJvdG90eXBlT2YgPyBPYmplY3QuZ2V0UHJvdG90eXBlT2YuYmluZCgpIDogZnVuY3Rpb24gX2dldFByb3RvdHlwZU9mMihvMikgewogICAgICAgICAgcmV0dXJuIG8yLl9fcHJvdG9fXyB8fCBPYmplY3QuZ2V0UHJvdG90eXBlT2YobzIpOwogICAgICAgIH07CiAgICAgICAgcmV0dXJuIF9nZXRQcm90b3R5cGVPZihvKTsKICAgICAgfQogICAgICBmdW5jdGlvbiBfc2V0UHJvdG90eXBlT2YobywgcCkgewogICAgICAgIF9zZXRQcm90b3R5cGVPZiA9IE9iamVjdC5zZXRQcm90b3R5cGVPZiA/IE9iamVjdC5zZXRQcm90b3R5cGVPZi5iaW5kKCkgOiBmdW5jdGlvbiBfc2V0UHJvdG90eXBlT2YyKG8yLCBwMikgewogICAgICAgICAgbzIuX19wcm90b19fID0gcDI7CiAgICAgICAgICByZXR1cm4gbzI7CiAgICAgICAgfTsKICAgICAgICByZXR1cm4gX3NldFByb3RvdHlwZU9mKG8sIHApOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIF9pc05hdGl2ZVJlZmxlY3RDb25zdHJ1Y3QoKSB7CiAgICAgICAgaWYgKHR5cGVvZiBSZWZsZWN0ID09PSAidW5kZWZpbmVkIiB8fCAhUmVmbGVjdC5jb25zdHJ1Y3QpCiAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgaWYgKFJlZmxlY3QuY29uc3RydWN0LnNoYW0pCiAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgaWYgKHR5cGVvZiBQcm94eSA9PT0gImZ1bmN0aW9uIikKICAgICAgICAgIHJldHVybiB0cnVlOwogICAgICAgIHRyeSB7CiAgICAgICAgICBCb29sZWFuLnByb3RvdHlwZS52YWx1ZU9mLmNhbGwoUmVmbGVjdC5jb25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9jcmVhdGVTdXBlckludGVybmFsKCkgewogICAgICAgICAgdmFyIFN1cGVyID0gX2dldFByb3RvdHlwZU9mKERlcml2ZWQpLCByZXN1bHQ7CiAgICAgICAgICBpZiAoaGFzTmF0aXZlUmVmbGVjdENvbnN0cnVjdCkgewogICAgICAgICAgICB2YXIgTmV3VGFyZ2V0ID0gX2dldFByb3RvdHlwZU9mKHRoaXMpLmNvbnN0cnVjdG9yOwogICAgICAgICAgICByZXN1bHQgPSBSZWZsZWN0LmNvbnN0cnVjdChTdXBlciwgYXJndW1lbnRzLCBOZXdUYXJnZXQpOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcmVzdWx0ID0gU3VwZXIuYXBwbHkodGhpcywgYXJndW1lbnRzKTsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBfcG9zc2libGVDb25zdHJ1Y3RvclJldHVybih0aGlzLCByZXN1bHQpOwogICAgICAgIH07CiAgICAgIH0KICAgICAgZnVuY3Rpb24gX3N1cGVyUHJvcEJhc2Uob2JqZWN0LCBwcm9wZXJ0eSkgewogICAgICAgIHdoaWxlICghT2JqZWN0LnByb3RvdHlwZS5oYXNPd25Qcm9wZXJ0eS5jYWxsKG9iamVjdCwgcHJvcGVydHkpKSB7CiAgICAgICAgICBvYmplY3QgPSBfZ2V0UHJvdG90eXBlT2Yob2JqZWN0KTsKICAgICAgICAgIGlmIChvYmplY3QgPT09IG51bGwpCiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIH0KICAgICAgICByZXR1cm4gb2JqZWN0OwogICAgICB9CiAgICAgIGZ1bmN0aW9uIF9nZXQoKSB7CiAgICAgICAgaWYgKHR5cGVvZiBSZWZsZWN0ICE9PSAidW5kZWZpbmVkIiAmJiBSZWZsZWN0LmdldCkgewogICAgICAgICAgX2dldCA9IFJlZmxlY3QuZ2V0LmJpbmQoKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgX2dldCA9IGZ1bmN0aW9uIF9nZXQyKHRhcmdldCwgcHJvcGVydHksIHJlY2VpdmVyKSB7CiAgICAgICAgICAgIHZhciBiYXNlID0gX3N1cGVyUHJvcEJhc2UodGFyZ2V0LCBwcm9wZXJ0eSk7CiAgICAgICAgICAgIGlmICghYmFzZSkKICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgIHZhciBkZXNjID0gT2JqZWN0LmdldE93blByb3BlcnR5RGVzY3JpcHRvcihiYXNlLCBwcm9wZXJ0eSk7CiAgICAgICAgICAgIGlmIChkZXNjLmdldCkgewogICAgICAgICAgICAgIHJldHVybiBkZXNjLmdldC5jYWxsKGFyZ3VtZW50cy5sZW5ndGggPCAzID8gdGFyZ2V0IDogcmVjZWl2ZXIpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHJldHVybiBkZXNjLnZhbHVlOwogICAgICAgICAgfTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIF9nZXQuYXBwbHkodGhpcywgYXJndW1lbnRzKTsKICAgICAgfQogICAgICB2YXIgRW1pdHRlciA9IC8qIEBfX1BVUkVfXyAqLyBmdW5jdGlvbigpIHsKICAgICAgICBmdW5jdGlvbiBFbWl0dGVyMigpIHsKICAgICAgICAgIF9jbGFzc0NhbGxDaGVjayh0aGlzLCBFbWl0dGVyMik7CiAgICAgICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkodGhpcywgImxpc3RlbmVycyIsIHsKICAgICAgICAgICAgdmFsdWU6IHt9LAogICAgICAgICAgICB3cml0YWJsZTogdHJ1ZSwKICAgICAgICAgICAgY29uZmlndXJhYmxlOiB0cnVlCiAgICAgICAgICB9KTsKICAgICAgICB9CiAgICAgICAgX2NyZWF0ZUNsYXNzKEVtaXR0ZXIyLCBbewogICAgICAgICAga2V5OiAiYWRkRXZlbnRMaXN0ZW5lciIsCiAgICAgICAgICB2YWx1ZTogZnVuY3Rpb24gYWRkRXZlbnRMaXN0ZW5lcih0eXBlLCBjYWxsYmFjaywgb3B0aW9ucykgewogICAgICAgICAgICBpZiAoISh0eXBlIGluIHRoaXMubGlzdGVuZXJzKSkgewogICAgICAgICAgICAgIHRoaXMubGlzdGVuZXJzW3R5cGVdID0gW107CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdGhpcy5saXN0ZW5lcnNbdHlwZV0ucHVzaCh7CiAgICAgICAgICAgICAgY2FsbGJhY2ssCiAgICAgICAgICAgICAgb3B0aW9ucwogICAgICAgICAgICB9KTsKICAgICAgICAgIH0KICAgICAgICB9LCB7CiAgICAgICAgICBrZXk6ICJyZW1vdmVFdmVudExpc3RlbmVyIiwKICAgICAgICAgIHZhbHVlOiBmdW5jdGlvbiByZW1vdmVFdmVudExpc3RlbmVyKHR5cGUsIGNhbGxiYWNrKSB7CiAgICAgICAgICAgIGlmICghKHR5cGUgaW4gdGhpcy5saXN0ZW5lcnMpKSB7CiAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHZhciBzdGFjayA9IHRoaXMubGlzdGVuZXJzW3R5cGVdOwogICAgICAgICAgICBmb3IgKHZhciBpID0gMCwgbCA9IHN0YWNrLmxlbmd0aDsgaSA8IGw7IGkrKykgewogICAgICAgICAgICAgIGlmIChzdGFja1tpXS5jYWxsYmFjayA9PT0gY2FsbGJhY2spIHsKICAgICAgICAgICAgICAgIHN0YWNrLnNwbGljZShpLCAxKTsKICAgICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9LCB7CiAgICAgICAgICBrZXk6ICJkaXNwYXRjaEV2ZW50IiwKICAgICAgICAgIHZhbHVlOiBmdW5jdGlvbiBkaXNwYXRjaEV2ZW50KGV2ZW50KSB7CiAgICAgICAgICAgIGlmICghKGV2ZW50LnR5cGUgaW4gdGhpcy5saXN0ZW5lcnMpKSB7CiAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHZhciBzdGFjayA9IHRoaXMubGlzdGVuZXJzW2V2ZW50LnR5cGVdOwogICAgICAgICAgICB2YXIgc3RhY2tUb0NhbGwgPSBzdGFjay5zbGljZSgpOwogICAgICAgICAgICBmb3IgKHZhciBpID0gMCwgbCA9IHN0YWNrVG9DYWxsLmxlbmd0aDsgaSA8IGw7IGkrKykgewogICAgICAgICAgICAgIHZhciBsaXN0ZW5lciA9IHN0YWNrVG9DYWxsW2ldOwogICAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgICBsaXN0ZW5lci5jYWxsYmFjay5jYWxsKHRoaXMsIGV2ZW50KTsKICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7CiAgICAgICAgICAgICAgICBQcm9taXNlLnJlc29sdmUoKS50aGVuKGZ1bmN0aW9uKCkgewogICAgICAgICAgICAgICAgICB0aHJvdyBlOwogICAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGlmIChsaXN0ZW5lci5vcHRpb25zICYmIGxpc3RlbmVyLm9wdGlvbnMub25jZSkgewogICAgICAgICAgICAgICAgdGhpcy5yZW1vdmVFdmVudExpc3RlbmVyKGV2ZW50LnR5cGUsIGxpc3RlbmVyLmNhbGxiYWNrKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgcmV0dXJuICFldmVudC5kZWZhdWx0UHJldmVudGVkOwogICAgICAgICAgfQogICAgICAgIH1dKTsKICAgICAgICByZXR1cm4gRW1pdHRlcjI7CiAgICAgIH0oKTsKICAgICAgdmFyIEFib3J0U2lnbmFsID0gLyogQF9fUFVSRV9fICovIGZ1bmN0aW9uKF9FbWl0dGVyKSB7CiAgICAgICAgX2luaGVyaXRzKEFib3J0U2lnbmFsMiwgX0VtaXR0ZXIpOwogICAgICAgIHZhciBfc3VwZXIgPSBfY3JlYXRlU3VwZXIoQWJvcnRTaWduYWwyKTsKICAgICAgICBmdW5jdGlvbiBBYm9ydFNpZ25hbDIoKSB7CiAgICAgICAgICB2YXIgX3RoaXM7CiAgICAgICAgICBfY2xhc3NDYWxsQ2hlY2sodGhpcywgQWJvcnRTaWduYWwyKTsKICAgICAgICAgIF90aGlzID0gX3N1cGVyLmNhbGwodGhpcyk7CiAgICAgICAgICBpZiAoIV90aGlzLmxpc3RlbmVycykgewogICAgICAgICAgICBFbWl0dGVyLmNhbGwoX2Fzc2VydFRoaXNJbml0aWFsaXplZChfdGhpcykpOwogICAgICAgICAgfQogICAgICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KF9hc3NlcnRUaGlzSW5pdGlhbGl6ZWQoX3RoaXMpLCAiYWJvcnRlZCIsIHsKICAgICAgICAgICAgdmFsdWU6IGZhbHNlLAogICAgICAgICAgICB3cml0YWJsZTogdHJ1ZSwKICAgICAgICAgICAgY29uZmlndXJhYmxlOiB0cnVlCiAgICAgICAgICB9KTsKICAgICAgICAgIE9iamVjdC5kZWZpbmVQcm9wZXJ0eShfYXNzZXJ0VGhpc0luaXRpYWxpemVkKF90aGlzKSwgIm9uYWJvcnQiLCB7CiAgICAgICAgICAgIHZhbHVlOiBudWxsLAogICAgICAgICAgICB3cml0YWJsZTogdHJ1ZSwKICAgICAgICAgICAgY29uZmlndXJhYmxlOiB0cnVlCiAgICAgICAgICB9KTsKICAgICAgICAgIE9iamVjdC5kZWZpbmVQcm9wZXJ0eShfYXNzZXJ0VGhpc0luaXRpYWxpemVkKF90aGlzKSwgInJlYXNvbiIsIHsKICAgICAgICAgICAgdmFsdWU6IHZvaWQgMCwKICAgICAgICAgICAgd3JpdGFibGU6IHRydWUsCiAgICAgICAgICAgIGNvbmZpZ3VyYWJsZTogdHJ1ZQogICAgICAgICAgfSk7CiAgICAgICAgICByZXR1cm4gX3RoaXM7CiAgICAgICAgfQogICAgICAgIF9jcmVhdGVDbGFzcyhBYm9ydFNpZ25hbDIsIFt7CiAgICAgICAgICBrZXk6ICJ0b1N0cmluZyIsCiAgICAgICAgICB2YWx1ZTogZnVuY3Rpb24gdG9TdHJpbmcoKSB7CiAgICAgICAgICAgIHJldHVybiAiW29iamVjdCBBYm9ydFNpZ25hbF0iOwogICAgICAgICAgfQogICAgICAgIH0sIHsKICAgICAgICAgIGtleTogImRpc3BhdGNoRXZlbnQiLAogICAgICAgICAgdmFsdWU6IGZ1bmN0aW9uIGRpc3BhdGNoRXZlbnQoZXZlbnQpIHsKICAgICAgICAgICAgaWYgKGV2ZW50LnR5cGUgPT09ICJhYm9ydCIpIHsKICAgICAgICAgICAgICB0aGlzLmFib3J0ZWQgPSB0cnVlOwogICAgICAgICAgICAgIGlmICh0eXBlb2YgdGhpcy5vbmFib3J0ID09PSAiZnVuY3Rpb24iKSB7CiAgICAgICAgICAgICAgICB0aGlzLm9uYWJvcnQuY2FsbCh0aGlzLCBldmVudCk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIF9nZXQoX2dldFByb3RvdHlwZU9mKEFib3J0U2lnbmFsMi5wcm90b3R5cGUpLCAiZGlzcGF0Y2hFdmVudCIsIHRoaXMpLmNhbGwodGhpcywgZXZlbnQpOwogICAgICAgICAgfQogICAgICAgIH1dKTsKICAgICAgICByZXR1cm4gQWJvcnRTaWduYWwyOwogICAgICB9KEVtaXR0ZXIpOwogICAgICB2YXIgQWJvcnRDb250cm9sbGVyID0gLyogQF9fUFVSRV9fICovIGZ1bmN0aW9uKCkgewogICAgICAgIGZ1bmN0aW9uIEFib3J0Q29udHJvbGxlcjIoKSB7CiAgICAgICAgICBfY2xhc3NDYWxsQ2hlY2sodGhpcywgQWJvcnRDb250cm9sbGVyMik7CiAgICAgICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkodGhpcywgInNpZ25hbCIsIHsKICAgICAgICAgICAgdmFsdWU6IG5ldyBBYm9ydFNpZ25hbCgpLAogICAgICAgICAgICB3cml0YWJsZTogdHJ1ZSwKICAgICAgICAgICAgY29uZmlndXJhYmxlOiB0cnVlCiAgICAgICAgICB9KTsKICAgICAgICB9CiAgICAgICAgX2NyZWF0ZUNsYXNzKEFib3J0Q29udHJvbGxlcjIsIFt7CiAgICAgICAgICBrZXk6ICJhYm9ydCIsCiAgICAgICAgICB2YWx1ZTogZnVuY3Rpb24gYWJvcnQocmVhc29uKSB7CiAgICAgICAgICAgIHZhciBldmVudDsKICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICBldmVudCA9IG5ldyBFdmVudCgiYWJvcnQiKTsKICAgICAgICAgICAgfSBjYXRjaCAoZSkgewogICAgICAgICAgICAgIGlmICh0eXBlb2YgZG9jdW1lbnQgIT09ICJ1bmRlZmluZWQiKSB7CiAgICAgICAgICAgICAgICBpZiAoIWRvY3VtZW50LmNyZWF0ZUV2ZW50KSB7CiAgICAgICAgICAgICAgICAgIGV2ZW50ID0gZG9jdW1lbnQuY3JlYXRlRXZlbnRPYmplY3QoKTsKICAgICAgICAgICAgICAgICAgZXZlbnQudHlwZSA9ICJhYm9ydCI7CiAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICBldmVudCA9IGRvY3VtZW50LmNyZWF0ZUV2ZW50KCJFdmVudCIpOwogICAgICAgICAgICAgICAgICBldmVudC5pbml0RXZlbnQoImFib3J0IiwgZmFsc2UsIGZhbHNlKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgZXZlbnQgPSB7CiAgICAgICAgICAgICAgICAgIHR5cGU6ICJhYm9ydCIsCiAgICAgICAgICAgICAgICAgIGJ1YmJsZXM6IGZhbHNlLAogICAgICAgICAgICAgICAgICBjYW5jZWxhYmxlOiBmYWxzZQogICAgICAgICAgICAgICAgfTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdmFyIHNpZ25hbFJlYXNvbiA9IHJlYXNvbjsKICAgICAgICAgICAgaWYgKHNpZ25hbFJlYXNvbiA9PT0gdm9pZCAwKSB7CiAgICAgICAgICAgICAgaWYgKHR5cGVvZiBkb2N1bWVudCA9PT0gInVuZGVmaW5lZCIpIHsKICAgICAgICAgICAgICAgIHNpZ25hbFJlYXNvbiA9IG5ldyBFcnJvcigiVGhpcyBvcGVyYXRpb24gd2FzIGFib3J0ZWQiKTsKICAgICAgICAgICAgICAgIHNpZ25hbFJlYXNvbi5uYW1lID0gIkFib3J0RXJyb3IiOwogICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgICAgICBzaWduYWxSZWFzb24gPSBuZXcgRE9NRXhjZXB0aW9uKCJzaWduYWwgaXMgYWJvcnRlZCB3aXRob3V0IHJlYXNvbiIpOwogICAgICAgICAgICAgICAgfSBjYXRjaCAoZXJyKSB7CiAgICAgICAgICAgICAgICAgIHNpZ25hbFJlYXNvbiA9IG5ldyBFcnJvcigiVGhpcyBvcGVyYXRpb24gd2FzIGFib3J0ZWQiKTsKICAgICAgICAgICAgICAgICAgc2lnbmFsUmVhc29uLm5hbWUgPSAiQWJvcnRFcnJvciI7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIHRoaXMuc2lnbmFsLnJlYXNvbiA9IHNpZ25hbFJlYXNvbjsKICAgICAgICAgICAgdGhpcy5zaWduYWwuZGlzcGF0Y2hFdmVudChldmVudCk7CiAgICAgICAgICB9CiAgICAgICAgfSwgewogICAgICAgICAga2V5OiAidG9TdHJpbmciLAogICAgICAgICAgdmFsdWU6IGZ1bmN0aW9uIHRvU3RyaW5nKCkgewogICAgICAgICAgICByZXR1cm4gIltvYmplY3QgQWJvcnRDb250cm9sbGVyXSI7CiAgICAgICAgICB9CiAgICAgICAgfV0pOwogICAgICAgIHJldHVybiBBYm9ydENvbnRyb2xsZXIyOwogICAgICB9KCk7CiAgICAgIGlmICh0eXBlb2YgU3ltYm9sICE9PSAidW5kZWZpbmVkIiAmJiBTeW1ib2wudG9TdHJpbmdUYWcpIHsKICAgICAgICBBYm9ydENvbnRyb2xsZXIucHJvdG90eXBlW1N5bWJvbC50b1N0cmlu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AgICBpZiAoaW5pdDIgJiYgaW5pdDIuc2lnbmFsKSB7CiAgICAgICAgICAgICAgc2lnbmFsID0gaW5pdDIuc2lnbmFsOwogICAgICAgICAgICAgIGRlbGV0ZSBpbml0Mi5zaWduYWw7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdmFyIHJlcXVlc3QgPSBuZXcgTmF0aXZlUmVxdWVzdChpbnB1dCwgaW5pdDIpOwogICAgICAgICAgICBpZiAoc2lnbmFsKSB7CiAgICAgICAgICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KHJlcXVlc3QsICJzaWduYWwiLCB7CiAgICAgICAgICAgICAgICB3cml0YWJsZTogZmFsc2UsCiAgICAgICAgICAgICAgICBlbnVtZXJhYmxlOiBmYWxzZSwKICAgICAgICAgICAgICAgIGNvbmZpZ3VyYWJsZTogdHJ1ZSwKICAgICAgICAgICAgICAgIHZhbHVlOiBzaWduYWwKICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAgfQogICAgICAgICAgICByZXR1cm4gcmVxdWVzdDsKICAgICAgICAgIH07CiAgICAgICAgICBSZXF1ZXN0LnByb3RvdHlwZSA9IE5hdGl2ZVJlcXVlc3QucHJvdG90eXBlOwogICAgICAgIH0KICAgICAgICB2YXIgcmVhbEZldGNoID0gZmV0Y2g7CiAgICAgICAgdmFyIGFib3J0YWJsZUZldGNoID0gZnVuY3Rpb24gYWJvcnRhYmxlRmV0Y2gyKGlucHV0LCBpbml0MikgewogICAgICAgICAgdmFyIHNpZ25hbCA9IFJlcXVlc3QgJiYgUmVxdWVzdC5wcm90b3R5cGUuaXNQcm90b3R5cGVPZihpbnB1dCkgPyBpbnB1dC5zaWduYWwgOiBpbml0MiA/IGluaXQyLnNpZ25hbCA6IHZvaWQgMDsKICAgICAgICAgIGlmIChzaWduYWwpIHsKICAgICAgICAgICAgdmFyIGFib3J0RXJyb3I7CiAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgYWJvcnRFcnJvciA9IG5ldyBET01FeGNlcHRpb24oIkFib3J0ZWQiLCAiQWJvcnRFcnJvciIpOwogICAgICAgICAgICB9IGNhdGNoIChlcnIpIHsKICAgICAgICAgICAgICBhYm9ydEVycm9yID0gbmV3IEVycm9yKCJBYm9ydGVkIik7CiAgICAgICAgICAgICAgYWJvcnRFcnJvci5uYW1lID0gIkFib3J0RXJyb3IiOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzaWduYWwuYWJvcnRlZCkgewogICAgICAgICAgICAgIHJldHVybiBQcm9taXNlLnJlamVjdChhYm9ydEVycm9yKTsKICAgICAgICAgICAgfQogICAgICAgICAgICB2YXIgY2FuY2VsbGF0aW9uID0gbmV3IFByb21pc2UoZnVuY3Rpb24oXywgcmVqZWN0KSB7CiAgICAgICAgICAgICAgc2lnbmFsLmFkZEV2ZW50TGlzdGVuZXIoImFib3J0IiwgZnVuY3Rpb24oKSB7CiAgICAgICAgICAgICAgICByZXR1cm4gcmVqZWN0KGFib3J0RXJyb3IpOwogICAgICAgICAgICAgIH0sIHsKICAgICAgICAgICAgICAgIG9uY2U6IHRydWUKICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAgfSk7CiAgICAgICAgICAgIGlmIChpbml0MiAmJiBpbml0Mi5zaWduYWwpIHsKICAgICAgICAgICAgICBkZWxldGUgaW5pdDIuc2lnbmFsOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHJldHVybiBQcm9taXNlLnJhY2UoW2NhbmNlbGxhdGlvbiwgcmVhbEZldGNoKGlucHV0LCBpbml0MildKTsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiByZWFsRmV0Y2goaW5wdXQsIGluaXQyKTsKICAgICAgICB9OwogICAgICAgIHJldHVybiB7CiAgICAgICAgICBmZXRjaDogYWJvcnRhYmxlRmV0Y2gsCiAgICAgICAgICBSZXF1ZXN0CiAgICAgICAgfTsKICAgICAgfQogICAgICBleHBvcnRzMi5BYm9ydENvbnRyb2xsZXIgPSBBYm9ydENvbnRyb2xsZXI7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YXRlQWJvcnRDb250cm9sbGVyLmpzIihleHBvcnRzMikgewogICAgICBpbml0X2J1ZmZlcl9zaGltKCk7CiAgICAgICJ1c2Ugc3RyaWN0IjsKICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KGV4cG9ydHMyLCAiX19lc01vZHVsZSIsIHsgdmFsdWU6IHRydWUgfSk7CiAgICAgIHZhciBhYm9ydGNvbnRyb2xsZXJfcG9ueWZpbGxfMSA9IHJlcXVpcmVfYWJvcnRjb250cm9sbGVyX3BvbnlmaWxsKCk7CiAgICAgIHZhciBOdWxsU2lnbmFsID0gY2xhc3MgewogICAgICB9OwogICAgICB2YXIgQWdncmVnYXRlQWJvcnRDb250cm9sbGVyID0gY2xhc3MgewogICAgICAgIGNvbnN0cnVjdG9yKCkgewogICAgICAgICAgdGhpcy5zaWduYWxzID0gbmV3IFNldCgpOwogICAgICAgICAgdGhpcy5hYm9ydENvbnRyb2xsZXIgPSBuZXcgYWJvcnRjb250cm9sbGVyX3BvbnlmaWxsXzEuQWJvcnRDb250cm9sbGVyKCk7CiAgICAgICAgfQogICAgICAgIGFkZFNpZ25hbChzaWduYWwgPSBuZXcgTnVsbFNpZ25hbCgpKSB7CiAgICAgICAgICBpZiAodGhpcy5zaWduYWwuYWJvcnRlZCkgewogICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IoImNhbm5vdCBhZGQgYSBzaWduYWwsIGFscmVhZHkgYWJvcnRlZCEiKTsKICAgICAgICAgIH0KICAgICAgICAgIHRoaXMuc2lnbmFscy5hZGQoc2lnbmFsKTsKICAgICAgICAgIGlmIChzaWduYWwuYWJvcnRlZCkgewogICAgICAgICAgICB0aGlzLmhhbmRsZUFib3J0ZWQoc2lnbmFsKTsKICAgICAgICAgIH0gZWxzZSBpZiAodHlwZW9mIHNpZ25hbC5hZGRFdmVudExpc3RlbmVyID09PSAiZnVuY3Rpb24iKSB7CiAgICAgICAgICAgIHNpZ25hbC5hZGRFdmVudExpc3RlbmVyKCJhYm9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Ym9ydENvbnRyb2xsZXJfMS5kZWZhdWx0KCk7CiAgICAgICAgICBjb25zdCBzdGF0dXNSZXBvcnRlciA9IG5ldyBBZ2dyZWdhdGVTdGF0dXNSZXBvcnRlcl8xLmRlZmF1bHQoKTsKICAgICAgICAgIHN0YXR1c1JlcG9ydGVyLmFkZENhbGxiYWNrKHN0YXR1c0NhbGxiYWNrKTsKICAgICAgICAgIGNvbnN0IG5ld0VudHJ5ID0gewogICAgICAgICAgICBhYm9ydGVyLAogICAgICAgICAgICBwcm9taXNlOiB0aGlzLmZpbGxDYWxsYmFjayhkYXRhLCBhYm9ydGVyLnNpZ25hbCwgKG1lc3NhZ2UpID0+IHsKICAgICAgICAgICAgICBzdGF0dXNSZXBvcnRlci5jYWxsYmFjayhtZXNzYWdlKTsKICAgICAgICAgICAgfSksCiAgICAgICAgICAgIHNldHRsZWQ6IGZhbHNlLAogICAgICAgICAgICBzdGF0dXNSZXBvcnRlciwKICAgICAgICAgICAgZ2V0IGFib3J0ZWQoKSB7CiAgICAgICAgICAgICAgcmV0dXJuIHRoaXMuYWJvcnRlci5zaWduYWwuYWJvcnRlZDsKICAgICAgICAgICAgfQogICAgICAgICAgfTsKICAgICAgICAgIG5ld0VudHJ5LmFib3J0ZXIuYWRkU2lnbmFsKHNpZ25hbCk7CiAgICAgICAgICBuZXdFbnRyeS5hYm9ydGVyLnNpZ25hbC5hZGRFdmVudExpc3RlbmVyKCJhYm9ydCIsICgpID0+IHsKICAgICAgICAgICAgaWYgKCFuZXdFbnRyeS5zZXR0bGVkKSB7CiAgICAgICAgICAgICAgdGhpcy5ldmljdChrZXksIG5ld0VudHJ5KTsKICAgICAgICAgICAgfQogICAgICAgICAgfSk7CiAgICAgICAgICBuZXdFbnRyeS5wcm9taXNlLnRoZW4oKCkgPT4gewogICAgICAgICAgICBuZXdFbnRyeS5zZXR0bGVkID0gdHJ1ZTsKICAgICAgICAgIH0sICgpID0+IHsKICAgICAgICAgICAgbmV3RW50cnkuc2V0dGxlZCA9IHRydWU7CiAgICAgICAgICAgIHRoaXMuZXZpY3Qoa2V5LCBuZXdFbnRyeSk7CiAgICAgICAgICB9KS5jYXRjaCgoZSkgPT4gewogICAgICAgICAgICBjb25zb2xlLmVycm9yKGUpOwogICAgICAgICAgICB0aHJvdyBlOwogICAgICAgICAgfSk7CiAgICAgICAgICB0aGlzLmNhY2hlLnNldChrZXksIG5ld0VudHJ5KTsKICAgICAgICB9CiAgICAgICAgc3RhdGljIGNoZWNrU2luZ2xlUHJvbWlzZShwcm9taXNlLCBzaWduYWwpIHsKICAgICAgICAgIGZ1bmN0aW9uIGNoZWNrRm9yU2luZ2xlQWJvcnQoKSB7CiAgICAgICAgICAgIGlmIChzaWduYWwgJiYgc2lnbmFsLmFib3J0ZWQpIHsKICAgICAgICAgICAgICB0aHJvdyBPYmplY3QuYXNzaWduKG5ldyBFcnJvcigiYWJvcnRlZCIpLCB7IGNvZGU6ICJFUlJfQUJPUlRFRCIgfSk7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBwcm9taXNlLnRoZW4oKHJlc3VsdCkgPT4gewogICAgICAgICAgICBjaGVja0ZvclNpbmdsZUFib3J0KCk7CiAgICAgICAgICAgIHJldHVybiByZXN1bHQ7CiAgICAgICAgICB9LCAoZXJyb3IpID0+IHsKICAgICAgICAgICAgY2hlY2tGb3JTaW5nbGVBYm9ydCgpOwogICAgICAgICAgICB0aHJvdyBlcnJvcjsKICAgICAgICAgIH0pOwogICAgICAgIH0KICAgICAgICBoYXMoa2V5KSB7CiAgICAgICAgICByZXR1cm4gdGhpcy5jYWNoZS5oYXMoa2V5KTsKICAgICAgICB9CiAgICAgICAgZ2V0KGtleSwgZGF0YSwgc2lnbmFsLCBzdGF0dXNDYWxsYmFjaykgewogICAgICAgICAgaWYgKCFzaWduYWwgJiYgZGF0YSBpbnN0YW5jZW9mIGFib3J0Y29udHJvbGxlcl9wb255ZmlsbF8xLkFib3J0U2lnbmFsKSB7CiA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gICAgICAgIGlmICghKG9wdGlvbnMubWF4U2l6ZSAmJiBvcHRpb25zLm1heFNpemUgPiAwKSkgewogICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCJgbWF4U2l6ZWAgbXVzdCBiZSBhIG51bWJlciBncmVhdGVyIHRoYW4gMCIpOwogICAgICAgICAgfQogICAgICAgICAgdGhpcy5tYXhTaXplID0gb3B0aW9ucy5tYXhTaXplOwogICAgICAgICAgdGhpcy5jYWNoZSA9IG5ldyBNYXAoKTsKICAgICAgICAgIHRoaXMub2xkQ2FjaGUgPSBuZXcgTWFwKCk7CiAgICAgICAgICB0aGlzLl9zaXplID0gMDsKICAgICAgICB9CiAgICAgICAgX3NldChrZXksIHZhbHVlKSB7CiAgICAgICAgICB0aGlzLmNhY2hlLnNldChrZXksIHZhbHVlKTsKICAgICAgICAgIHRoaXMuX3NpemUrKzsKICAgICAgICAgIGlmICh0aGlzLl9zaXplID49IHRoaXMubWF4U2l6ZSkgewogICAgICAgICAgICB0aGlzLl9zaXplID0gMDsKICAgICAgICAgICAgdGhpcy5vbGRDYWNoZSA9IHRoaXMuY2FjaGU7CiAgICAgICAgICAgIHRoaXMuY2FjaGUgPSBuZXcgTWFwKCk7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGdldChrZXkpIHsKICAgICAgICAgIGlmICh0aGlzLmNhY2hlLmhhcyhrZXkpKSB7CiAgICAgICAgICAgIHJldHVybiB0aGlzLmNhY2hlLmdldChrZXkpOwogICAgICAgICAgfQogICAgICAgICAgaWYgKHRoaXMub2xkQ2FjaGUuaGFzKGtleSkpIHsKICAgICAgICAgICAgY29uc3QgdmFsdWUgPSB0aGlzLm9sZENhY2hlLmdldChrZXkpOwogICAgICAgICAgICB0aGlzLm9sZENhY2hlLmRlbGV0ZShrZXkpOwogICAgICAgICAgICB0aGlzLl9zZXQoa2V5LCB2YWx1ZSk7CiAgICAgICAgICAgIHJldHVybiB2YWx1ZTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgc2V0KGtleSwgdmFsdWUpIHsKICAgICAgICAgIGlmICh0aGlzLmNhY2hlLmhhcyhrZXkpKSB7CiAgICAgICAgICAgIHRoaXMuY2FjaGUuc2V0KGtleSwgdmFsdWUpOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgdGhpcy5fc2V0KGtleSwgdmFsdWUpOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIHRoaXM7CiAgICAgICAgfQogICAgICAgIGhhcyhrZXkpIHsKICAgICAgICAgIHJldHVybiB0aGlzLmNhY2hlLmhhcyhrZXkpIHx8IHRoaXMub2xkQ2FjaGUuaGFzKGtleSk7CiAgICAgICAgfQogICAgICAgIHBlZWsoa2V5KSB7CiAgICAgICAgICBpZiAodGhpcy5jYWNoZS5oYXMoa2V5KSkgewogICAgICAgICAgICByZXR1cm4gdGhpcy5jYWNoZS5nZXQoa2V5KTsKICAgICAgICAgIH0KICAgICAgICAgIGlmICh0aGlzLm9sZENhY2hlLmhhcyhrZXkpKSB7CiAgICAgICAgICAgIHJldHVybiB0aGlzLm9sZENhY2hlLmdldChrZXkpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBkZWxldGUoa2V5KSB7CiAgICAgICAgICBjb25zdCBkZWxldGVkID0gdGhpcy5jYWNoZS5kZWxldGUoa2V5KTsKICAgICAgICAgIGlmIChkZWxldGVkKSB7CiAgICAgICAgICAgIHRoaXMuX3NpemUtLTsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiB0aGlzLm9sZENhY2hlLmRlbGV0ZShrZXkpIHx8IGRlbGV0ZWQ7CiAgICAgICAgfQogICAgICAgIGNsZWFyKCkgewogICAgICAgICAgdGhpcy5jYWNoZS5jbGVhcigpOwogICAgICAgICAgdGhpcy5vbGRDYWNoZS5jbGVhcigpOwogICAgICAgICAgdGhpcy5fc2l6ZSA9IDA7CiAgICAgICAgfQogICAgICAgICprZXlzKCkgewogICAgICAgICAgZm9yIChjb25zdCBba2V5XSBvZiB0aGlzKSB7CiAgICAgICAgICAgIHlpZWxkIGtleTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgKnZhbHVlcygpIHsKICAgICAgICAgIGZvciAoY29uc3QgWywgdmFsdWVdIG9mIHRoaXMpIHsKICAgICAgICAgICAgeWllbGQgdmFsdWU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgICpbU3ltYm9sLml0ZXJhdG9yXSgpIHsKICAgICAgICAgIGZvciAoY29uc3QgaXRlbSBvZiB0aGlzLmNhY2hlKSB7CiAgICAgICAgICAgIHlpZWxkIGl0ZW07CiAgICAgICAgICB9CiAgICAgICAgICBmb3IgKGNvbnN0IGl0ZW0gb2YgdGhpcy5vbGRDYWNoZSkgewogICAgICAgICAgICBjb25zdCBba2V5XSA9IGl0ZW07CiAgICAgICAgICAgIGlmICghdGhpcy5jYWNoZS5oYXMoa2V5KSkgewogICAgICAgICAgICAgIHlpZWxkIGl0ZW07CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZ2V0IHNpemUoKSB7CiAgICAgICAgICBsZXQgb2xkQ2FjaGVTaXplID0gMDsKICAgICAgICAgIGZvciAoY29uc3Qga2V5IG9mIHRoaXMub2xkQ2FjaGUua2V5cygpKSB7CiAgICAgICAgICAgIGlmICghdGhpcy5jYWNoZS5oYXMoa2V5KSkgewogICAgICAgICAgICAgIG9sZENhY2hlU2l6ZSsrOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gdGhpcy5fc2l6ZSArIG9sZENhY2hlU2l6ZTsKICAgICAgICB9CiAgICAgIH07CiAgICAgIG1vZHVsZTIuZXhwb3J0cyA9IFF1aWNrTFJVOwogICAgfQogIH0pOwoKICAvLyAoZGlzYWJsZWQpOm5vZGVfbW9kdWxlcy8ucG5wbS9nZW5lcmljLWZpbGVoYW5kbGVAMy4xLjEvbm9kZV9tb2R1bGVzL2dlbmVyaWMtZmlsZWhhbmRs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UgPSBzb3VyY2VzLnNoaWZ0KCk7CiAgICAgICAgICBpZiAoIXNvdXJjZSkgewogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgIH0KICAgICAgICAgIGlmICh0eXBlb2Ygc291cmNlICE9PSAib2JqZWN0IikgewogICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKHNvdXJjZSArICJtdXN0IGJlIG5vbi1vYmplY3QiKTsKICAgICAgICAgIH0KICAgICAgICAgIGZvciAodmFyIHAgaW4gc291cmNlKSB7CiAgICAgICAgICAgIGlmIChfaGFzKHNvdXJjZSwgcCkpIHsKICAgICAgICAgICAgICBvYmpbcF0gPSBzb3VyY2VbcF07CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIG9iajsKICAgICAgfTsKICAgICAgZXhwb3J0czIuc2hyaW5rQnVmID0gZnVuY3Rpb24oYnVmLCBzaXplKSB7CiAgICAgICAgaWYgKGJ1Zi5sZW5ndGggPT09IHNpemUpIHsKICAgICAgICAgIHJldHVybiBidWY7CiAgICAgICAgfQogICAgICAgIGlmIChidWYuc3ViYXJyYXkpIHsKICAgICAgICAgIHJldHVybiBidWYuc3ViYXJyYXkoMCwgc2l6ZSk7CiAgICAgICAgfQogICAgICAgIGJ1Zi5sZW5ndGggPSBzaXplOwogICAgICAgIHJldHVybiBidWY7CiAgICAgIH07CiAgICAgIHZhciBmblR5cGVkID0gewogICAgICAgIGFycmF5U2V0OiBmdW5jdGlvbihkZXN0LCBzcmMsIHNyY19vZmZzLCBsZW4sIGRlc3Rfb2ZmcykgewogICAgICAgICAgaWYgKHNyYy5zdWJhcnJheSAmJiBkZXN0LnN1YmFycmF5KSB7CiAgICAgICAgICAgIGRlc3Quc2V0KHNyYy5zdWJhcnJheShzcmNfb2Zmcywgc3JjX29mZnMgKyBsZW4pLCBkZXN0X29mZnMpOwogICAgICAgICAgICByZXR1cm47CiAgICAgICAgICB9CiAgICAgICAgICBmb3IgKHZhciBpID0gMDsgaSA8IGxlbjsgaSsrKSB7CiAgICAgICAgICAgIGRlc3RbZGVzdF9vZmZzICsgaV0gPSBzcmNbc3JjX29mZnMgKyBpXTsKICAgICAgICAgIH0KICAgICAgICB9LAogICAgICAgIGZsYXR0ZW5DaHVua3M6IGZ1bmN0aW9uKGNodW5rcykgewogICAgICAgICAgdmFyIGksIGwsIGxlbiwgcG9zLCBjaHVuaywgcmVzdWx0OwogICAgICAgICAgbGVuID0gMDsKICAgICAgICAgIGZvciAoaSA9IDAsIGwgPSBjaHVua3MubGVuZ3RoOyBpIDwgbDsgaSsrKSB7CiAgICAgICAgICAgIGxlbiArPSBjaHVua3NbaV0ubGVuZ3RoOwogICAgICAgICAgfQogICAgICAgICAgcmVzdWx0ID0gbmV3IFVpbnQ4QXJyYXkobGVuKTsKICAgICAgICAgIHBvcyA9IDA7CiAgICAgICAgICBmb3IgKGkgPSAwLCBsID0gY2h1bmtzLmxlbmd0aDsgaSA8IGw7IGkrKykgewogICAgICAgICAgICBjaHVuayA9IGNodW5rc1tpXTsKICAgICAgICAgICAgcmVzdWx0LnNldChjaHVuaywgcG9zKTsKICAgICAgICAgICAgcG9zICs9IGNodW5rLmxlbmd0aDsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiByZXN1bHQ7CiAgICAgICAgfQogICAgICB9OwogICAgICB2YXIgZm5VbnR5cGVkID0gewogICAgICAgIGFycmF5U2V0OiBmdW5jdGlvbihkZXN0LCBzcmMsIHNyY19vZmZzLCBsZW4sIGRlc3Rfb2ZmcykgewogICAgICAgICAgZm9yICh2YXIgaSA9IDA7IGkgPCBsZW47IGkrKykgewogICAgICAgICAgICBkZXN0W2Rlc3Rfb2ZmcyArIGldID0gc3JjW3NyY19vZmZzICsgaV07CiAgICAgICAgICB9CiAgICAgICAgfSwKICAgICAgICBmbGF0dGVuQ2h1bmtzOiBmdW5jdGlvbihjaHVua3MpIHsKICAgICAgICAgIHJldHVybiBbXS5jb25jYXQuYXBwbHkoW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AgICAgICAgICBwdXRfc2hvcnQocywgcy5iaV9idWYpOwogICAgICAgICAgcy5iaV9idWYgPSB2YWx1ZSA+PiBCdWZfc2l6ZSAtIHMuYmlfdmFsaWQ7CiAgICAgICAgICBzLmJpX3ZhbGlkICs9IGxlbmd0aCAtIEJ1Zl9zaXplOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBzLmJpX2J1ZiB8PSB2YWx1ZSA8PCBzLmJpX3ZhbGlkICYgNjU1MzU7CiAgICAgICAgICBzLmJpX3ZhbGlkICs9IGxlbmd0aDsKICAgICAgICB9CiAgICAgIH0KICAgICAgZnVuY3Rpb24gc2VuZF9jb2RlKHMsIGMsIHRyZWUpIHsKICAgICAgICBzZW5kX2JpdHMocywgdHJlZVtjICogMl0sIHRyZWVbYyAqIDIgKyAxXSk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gYmlfcmV2ZXJzZShjb2RlLCBsZW4pIHsKICAgICAgICB2YXIgcmVzID0gMDsKICAgICAgICBkbyB7CiAgICAgICAgICByZXMgfD0gY29kZSAmIDE7CiAgICAgICAgICBjb2RlID4+Pj0gMTsKICAgICAgICAgIHJlcyA8PD0gMTsKICAgICAgICB9IHdoaWxlICgtLWxlbiA+IDApOwogICAgICAgIHJldHVybiByZXMgPj4+IDE7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gYmlfZmx1c2gocykgewogICAgICAgIGlmIChzLmJpX3ZhbGlkID09PSAxNikgewogICAgICAgICAgcHV0X3Nob3J0KHMsIHMuYmlfYnVmKTsKICAgICAgICAgIHMuYmlfYnVmID0gMDsKICAgICAgICAgIHMuYmlfdmFsaWQgPSAwOwogICAgICAgIH0gZWxzZSBpZiAocy5iaV92YWxpZCA+PSA4KSB7CiAgICAgICAgICBzLnBlbmRpbmdfYnVmW3MucGVuZGluZysrXSA9IHMuYmlfYnVmICYgMjU1OwogICAgICAgICAgcy5iaV9idWYgPj49IDg7CiAgICAgICAgICBzLmJpX3ZhbGlkIC09IDg7CiAgICAgICAgfQogICAgICB9CiAgICAgIGZ1bmN0aW9uIGdlbl9iaXRsZW4ocywgZGVzYykgewogICAgICAgIHZhciB0cmVlID0gZGVzYy5keW5fdHJlZTsKICAgICAgICB2YXIgbWF4X2NvZGUgPSBkZXNjLm1heF9jb2RlOwogICAgICAgIHZhciBzdHJlZSA9IGRlc2Muc3RhdF9kZXNjLnN0YXRpY190cmVlOwogICAgICAgIHZhciBoYXNfc3RyZWUgPSBkZXNjLnN0YXRfZGVzYy5oYXNfc3RyZWU7CiAgICAgICAgdmFyIGV4dHJhID0gZGVzYy5zdGF0X2Rlc2MuZXh0cmFfYml0czsKICAgICAgICB2YXIgYmFzZSA9IGRlc2Muc3RhdF9kZXNjLmV4dHJhX2Jhc2U7CiAgICAgICAgdmFyIG1heF9sZW5ndGggPSBkZXNjLnN0YXRfZGVzYy5tYXhfbGVuZ3RoOwogICAgICAgIHZhciBoOwogICAgICAgIHZhciBuLCBtOwogICAgICAgIHZhciBiaXRzOwogICAgICAgIHZhciB4Yml0czsKICAgICAgICB2YXIgZjsKICAgICAgICB2YXIgb3ZlcmZsb3cgPSAwOwogICAgICAgIGZvciAoYml0cyA9IDA7IGJpdHMgPD0gTUFYX0JJVFM7IGJpdHMrKykgewogICAgICAgICAgcy5ibF9jb3VudFtiaXRzXSA9IDA7CiAgICAgICAgfQogICAgICAgIHRyZWVbcy5oZWFwW3MuaGVhcF9tYXhdICogMiArIDFdID0gMDsKICAgICAgICBmb3IgKGggPSBzLmhlYXBfbWF4ICsgMTsgaCA8IEhFQVBfU0laRTsgaCsrKSB7CiAgICAgICAgICBuID0gcy5oZWFwW2hdOwogICAgICAgICAgYml0cyA9IHRyZWVbdHJlZVtuICogMiArIDFdICogMiArIDFdICsgMTsKICAgICAgICAgIGlmIChiaXRzID4gbWF4X2xlbmd0aCkgewogICAgICAgICAgICBiaXRzID0gbWF4X2xlbmd0aDsKICAgICAgICAgICAgb3ZlcmZsb3crKzsKICAgICAgICAgIH0KICAgICAgICAgIHRyZWVbbiAqIDIgKyAxXSA9IGJpdHM7CiAgICAgICAgICBpZiAobiA+IG1heF9jb2RlKSB7CiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgfQogICAgICAgICAgcy5ibF9jb3VudFtiaXRzXSsrOwogICAgICAgICAgeGJpdHMgPSAwOwogICAgICAgICAgaWYgKG4gPj0gYmFzZSkgewogICAgICAgICAgICB4Yml0cyA9IGV4dHJhW24gLSBiYXNlXTsKICAgICAgICAgIH0KICAgICAgICAgIGYgPSB0cmVlW24gKiAyXTsKICAgICAgICAgIHMub3B0X2xlbiArPSBmICogKGJpdHMgKyB4Yml0cyk7CiAgICAgICAgICBpZiAoaGFzX3N0cmVlKSB7CiAgICAgICAgICAgIHMuc3RhdGljX2xlbiArPSBmICogKHN0cmVlW24gKiAyICsgMV0gKyB4Yml0cyk7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChvdmVyZmxvdyA9PT0gMCkgewogICAgICAgICAgcmV0dXJuOwogICAgICAgIH0KICAgICAgICBkbyB7CiAgICAgICAgICBiaXRzID0gbWF4X2xlbmd0aCAtIDE7CiAgICAgICAgICB3aGlsZSAocy5ibF9jb3VudFtiaXRzXSA9PT0gMCkgewogICAgICAgICAgICBiaXRzLS07CiAgICAgICAgICB9CiAgICAgICAgICBzLmJsX2NvdW50W2JpdHNdLS07CiAgICAgICAgICBzLmJsX2NvdW50W2JpdHMgKyAxXSArPSAyOwogICAgICAgICAgcy5ibF9jb3VudFttYXhfbGVuZ3RoXS0tOwogICAgICAgICAgb3ZlcmZsb3cgLT0gMjsKICAgICAgICB9IHdoaWxlIChvdmVyZmxvdyA+IDApOwogICAgICAgIGZvciAoYml0cyA9IG1heF9sZW5ndGg7IGJpdHMgIT09IDA7IGJpdHMtLSkgewogICAgICAgICAgbiA9IHMuYmxfY291bnRbYml0c107CiAgICAgICAgICB3aGlsZSAobiAhPT0gMCkgewogICAgICAgICAgICBtID0gcy5oZWFwWy0taF07CiAgICAgICAgICAgIGlmIChtID4gbWF4X2NvZGUpIHsKICAgICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAodHJlZVttICogMiArIDFdICE9PSBiaXRzKSB7CiAgICAgICAgICAgICAgcy5vcHRfbGVuICs9IChiaXRzIC0gdHJlZVttICogMiArIDFdKSAqIHRyZWVbbSAqIDJdOwogICAgICAgICAgICAgIHRyZWVbbSAqIDIgKyAxXSA9IGJpdHM7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgbi0tOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgICBmdW5jdGlvbiBnZW5fY29kZXModHJlZSwgbWF4X2NvZGUsIGJsX2NvdW50KSB7CiAgICAgICAgdmFyIG5leHRfY29kZSA9IG5ldyBBcnJheShNQVhfQklUUyArIDEpOwogICAgICAgIHZhciBjb2RlID0gMDsKICAgICAgICB2YXIgYml0czsKICAgICAgICB2YXIgbjsKICAgICAgICBmb3IgKGJpdHMgPSAxOyBiaXRzIDw9IE1BWF9CSVRTOyBiaXRzKyspIHsKICAgICAgICAgIG5leHRfY29kZVtiaXRzXSA9IGNvZGUgPSBjb2RlICsgYmxfY291bnRbYml0cyAtIDFdIDw8IDE7CiAgICAgICAgfQogICAgICAgIGZvciAobiA9IDA7IG4gPD0gbWF4X2NvZGU7IG4rKykgewogICAgICAgICAgdmFyIGxlbiA9IHRyZWVbbiAqIDIgKyAxXTsKICAgICAgICAgIGlmIChsZW4gPT09IDApIHsKICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICB9CiAgICAgICAgICB0cmVlW24gKiAyXSA9IGJpX3JldmVyc2UobmV4dF9jb2RlW2xlbl0rKywgbGVuKTsKICAgICAgICB9CiAgICAgIH0KICAgICAgZnVuY3Rpb24gdHJfc3RhdGljX2luaXQoKSB7CiAgICAgICAgdmFyIG47CiAgICAgICAgdmFyIGJpdHM7CiAgICAgICAgdmFyIGxlbmd0aDsKICAgICAgICB2YXIgY29kZTsKICAgICAgICB2YXIgZGlzdDsKICAgICAgICB2YXIgYmxfY291bnQgPSBuZXcgQXJyYXkoTUFYX0JJVFMgKyAxKTsKICAgICAgICBsZW5ndGggPSAwOwogICAgICAgIGZvciAoY29kZSA9IDA7IGNvZGUgPCBMRU5HVEhfQ09ERVMgLSAxOyBjb2RlKyspIHsKICAgICAgICAgIGJhc2VfbGVuZ3RoW2NvZGVdID0gbGVuZ3RoOwogICAgICAgICAgZm9yIChuID0gMDsgbiA8IDEgPDwgZXh0cmFfbGJpdHNbY29kZV07IG4rKykgewogICAgICAgICAgICBfbGVuZ3RoX2NvZGVbbGVuZ3RoKytdID0gY29kZTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgX2xlbmd0aF9jb2RlW2xlbmd0aCAtIDFdID0gY29kZTsKICAgICAgICBkaXN0ID0gMDsKICAgICAgICBmb3IgKGNvZGUgPSAwOyBjb2RlIDwgMTY7IGNvZGUrKykgewogICAgICAgICAgYmFzZV9kaXN0W2NvZGVdID0gZGlzdDsKICAgICAgICAgIGZvciAobiA9IDA7IG4gPCAxIDw8IGV4dHJhX2RiaXRzW2NvZGVdOyBuKyspIHsKICAgICAgICAgICAgX2Rpc3RfY29kZVtkaXN0KytdID0gY29kZTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZGlzdCA+Pj0gNzsKICAgICAgICBmb3IgKDsgY29kZSA8IERfQ09ERVM7IGNvZGUrKykgewogICAgICAgICAgYmFzZV9kaXN0W2NvZGVdID0gZGlzdCA8PCA3OwogICAgICAgICAgZm9yIChuID0gMDsgbiA8IDEgPDwgZXh0cmFfZGJpdHNbY29kZV0gLSA3OyBuKyspIHsKICAgICAgICAgICAgX2Rpc3RfY29kZVsyNTYgKyBkaXN0KytdID0gY29kZTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZm9yIChiaXRzID0gMDsgYml0cyA8PSBNQVhfQklUUzsgYml0cysrKSB7CiAgICAgICAgICBibF9jb3VudFtiaXRzXSA9IDA7CiAgICAgICAgfQogICAgICAgIG4gPSAwOwogICAgICAgIHdoaWxlIChuIDw9IDE0MykgewogICAgICAgICAgc3RhdGljX2x0cmVlW24gKiAyICsgMV0gPSA4OwogICAgICAgICAgbisrOwogICAgICAgICAgYmxfY291bnRbOF0rKzsKICAgICAgICB9CiAgICAgICAgd2hpbGUgKG4gPD0gMjU1KSB7CiAgICAgICAgICBzdGF0aWNfbHRyZWVbbiAqIDIgKyAxXSA9IDk7CiAgICAgICAgICBuKys7CiAgICAgICAgICBibF9jb3VudFs5XSsrOwogICAgICAgIH0KICAgICAgICB3aGlsZSAobiA8PSAyNzkpIHsKICAgICAgICAgIHN0YXRpY19sdHJlZVtuICogMiArIDFdID0gNzsKICAgICAgICAgIG4rKzsKICAgICAgICAgIGJsX2NvdW50WzddKys7CiAgICAgICAgfQogICAgICAgIHdoaWxlIChuIDw9IDI4NykgewogICAgICAgICAgc3RhdGljX2x0cmVlW24gKiAyICsgMV0gPSA4OwogICAgICAgICAgbisrOwogICAgICAgICAgYmxfY291bnRbOF0rKzsKICAgICAgICB9CiAgICAgICAgZ2VuX2NvZGVzKHN0YXRpY19sdHJlZSwgTF9DT0RFUyArIDEsIGJsX2NvdW50KTsKICAgICAgICBmb3IgKG4gPSAwOyBuIDwgRF9DT0RFUzsgbisrKSB7CiAgICAgICAgICBzdGF0aWNfZHRyZWVbbiAqIDIgKyAxXSA9IDU7CiAgICAgICAgICBzdGF0aWNfZHRyZWVbbiAqIDJdID0gYmlfcmV2ZXJzZShuLCA1KTsKICAgICAgICB9CiAgICAgICAgc3RhdGljX2xfZGVzYyA9IG5ldyBTdGF0aWNUcmVlRGVzYyhzdGF0aWNfbHRyZWUsIGV4dHJhX2xiaXRzLCBMSVRFUkFMUyArIDEsIExfQ09ERVMsIE1BWF9CSVRTKTsKICAgICAgICBzdGF0aWNfZF9kZXNjID0gbmV3IFN0YXRpY1RyZWVEZXNjKHN0YXRpY19kdHJlZSwgZXh0cmFfZGJpdHMsIDAsIERfQ09ERVMsIE1BWF9CSVRTKTsKICAgICAgICBzdGF0aWNfYmxfZGVzYyA9IG5ldyBTdGF0aWNUcmVlRGVzYyhuZXcgQXJyYXkoMCksIGV4dHJhX2JsYml0cywgMCwgQkxfQ09ERVMsIE1BWF9CTF9CSVRTKTsKICAgICAgfQogICAgICBmdW5jdGlvbiBpbml0X2Jsb2NrKHMpIHsKICAgICAgICB2YXIgbjsKICAgICAgICBmb3IgKG4gPSAwOyBuIDwgTF9DT0RFUzsgbisrKSB7CiAgICAgICAgICBzLmR5bl9sdHJlZVtuICogMl0gPSAwOwogICAgICAgIH0KICAgICAgICBmb3IgKG4gPSAwOyBuIDwgRF9DT0RFUzsgbisrKSB7CiAgICAgICAgICBzLmR5bl9kdHJlZVtuICogMl0gPSAwOwogICAgICAgIH0KICAgICAgICBmb3IgKG4gPSAwOyBuIDwgQkxfQ09ERVM7IG4rKykgewogICAgICAgICAgcy5ibF90cmVlW24gKiAyXSA9IDA7CiAgICAgICAgfQogICAgICAgIHMuZHluX2x0cmVlW0VORF9CTE9DSyAqIDJdID0gMTsKICAgICAgICBzLm9wdF9sZW4gPSBzLnN0YXRpY19sZW4gPSAwOwogICAgICAgIHMubGFzdF9saXQgPSBzLm1hdGNoZXMgPSAwOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGJpX3dpbmR1cChzKSB7CiAgICAgICAgaWYgKHMuYmlfdmFsaWQgPiA4KSB7CiAgICAgICAgICBwdXRfc2hvcnQocywgcy5iaV9idWYpOwogICAgICAgIH0gZWxzZSBpZiAocy5iaV92YWxpZCA+IDApIHsKICAgICAgICAgIHMucGVuZGluZ19idWZbcy5wZW5kaW5nKytdID0gcy5iaV9idWY7CiAgICAgICAgfQogICAgICAgIHMuYmlfYnVmID0gMDsKICAgICAgICBzLmJpX3ZhbGlkID0gMDsKICAgICAgfQogICAgICBmdW5jdGlvbiBjb3B5X2Jsb2NrKHMsIGJ1ZiwgbGVuLCBoZWFkZXIpIHsKICAgICAgICBiaV93aW5kdXAocyk7CiAgICAgICAgaWYgKGhlYWRlcikgewogICAgICAgICAgcHV0X3Nob3J0KHMsIGxlbik7CiAgICAgICAgICBwdXRfc2hvcnQocywgfmxlbik7CiAgICAgICAgfQogICAgICAgIHV0aWxzLmFycmF5U2V0KHMucGVuZGluZ19idWYsIHMud2luZG93LCBidWYsIGxlbiwgcy5wZW5kaW5nKTsKICAgICAgICBzLnBlbmRpbmcgKz0gbGVuOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIHNtYWxsZXIodHJlZSwgbiwgbSwgZGVwdGgpIHsKICAgICAgICB2YXIgX24yID0gbiAqIDI7CiAgICAgICAgdmFyIF9tMiA9IG0gKiAyOwogICAgICAgIHJldHVybiB0cmVlW19uMl0gPCB0cmVlW19tMl0gfHwgdHJlZVtfbjJdID09PSB0cmVlW19tMl0gJiYgZGVwdGhbbl0gPD0gZGVwdGhbbV07CiAgICAgIH0KICAgICAgZnVuY3Rpb24gcHFkb3duaGVhcChzLCB0cmVlLCBrKSB7CiAgICAgICAgdmFyIHYgPSBzLmhlYXBba107CiAgICAgICAgdmFyIGogPSBrIDw8IDE7CiAgICAgICAgd2hpbGUgKGogPD0gcy5oZWFwX2xlbikgewogICAgICAgICAgaWYgKGogPCBzLmhlYXBfbGVuICYmIHNtYWxsZXIodHJlZSwgcy5oZWFwW2ogKyAxXSwgcy5oZWFwW2pdLCBzLmRlcHRoKSkgewogICAgICAgICAgICBqKys7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoc21hbGxlcih0cmVlLCB2LCBzLmhlYXBbal0sIHMuZGVwdGgpKSB7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgICAgcy5oZWFwW2tdID0gcy5oZWFwW2pdOwogICAgICAgICAgayA9IGo7CiAgICAgICAgICBqIDw8PSAxOwogICAgICAgIH0KICAgICAgICBzLmhlYXBba10gPSB2OwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGNvbXByZXNzX2Jsb2NrKHMsIGx0cmVlLCBkdHJlZSkgewogICAgICAgIHZhciBkaXN0OwogICAgICAgIHZhciBsYzsKICAgICAgICB2YXIgbHggPSAwOwogICAgICAgIHZhciBjb2RlOwogICAgICAgIHZhciBleHRyYTsKICAgICAgICBpZiAocy5sYXN0X2xpdCAhPT0gMCkgewogICAgICAgICAgZG8gewogICAgICAgICAgICBkaXN0ID0gcy5wZW5kaW5nX2J1ZltzLmRfYnVmICsgbHggKiAyXSA8PCA4IHwgcy5wZW5kaW5nX2J1ZltzLmRfYnVmICsgbHggKiAyICsgMV07CiAgICAgICAgICAgIGxjID0gcy5wZW5kaW5nX2J1ZltzLmxfYnVmICsgbHhdOwogICAgICAgICAgICBseCsrOwogICAgICAgICAgICBpZiAoZGlzdCA9PT0gMCkgewogICAgICAgICAgICAgIHNlbmRfY29kZShzLCBsYywgbHRyZWUpOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIGNvZGUgPSBfbGVuZ3RoX2NvZGVbbGNdOwogICAgICAgICAgICAgIHNlbmRfY29kZShzLCBjb2RlICsgTElURVJBTFMgKyAxLCBsdHJlZSk7CiAgICAgICAgICAgICAgZXh0cmEgPSBleHRyYV9sYml0c1tjb2RlXTsKICAgICAgICAgICAgICBpZiAoZXh0cmEgIT09IDApIHsKICAgICAgICAgICAgICAgIGxjIC09IGJhc2VfbGVuZ3RoW2NvZGVdOwogICAgICAgICAgICAgICAgc2VuZF9iaXRzKHMsIGxjLCBleHRyYSk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGRpc3QtLTsKICAgICAgICAgICAgICBjb2RlID0gZF9jb2RlKGRpc3QpOwogICAgICAgICAgICAgIHNlbmRfY29kZShzLCBjb2RlLCBkdHJlZSk7CiAgICAgICAgICAgICAgZXh0cmEgPSBleHRyYV9kYml0c1tjb2RlXTsKICAgICAgICAgICAgICBpZiAoZXh0cmEgIT09IDApIHsKICAgICAgICAgICAgICAgIGRpc3QgLT0gYmFzZV9kaXN0W2NvZGVdOwogICAgICAgICAgICAgICAgc2VuZF9iaXRzKHMsIGRpc3QsIGV4dHJhKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gd2hpbGUgKGx4IDwgcy5sYXN0X2xpdCk7CiAgICAgICAgfQogICAgICAgIHNlbmRfY29kZShzLCBFTkRfQkxPQ0ssIGx0cmVlKTsKICAgICAgfQogICAgICBmdW5jdGlvbiBidWlsZF90cmVlKHMsIGRlc2MpIHsKICAgICAgICB2YXIgdHJlZSA9IGRlc2MuZHluX3RyZWU7CiAgICAgICAgdmFyIHN0cmVlID0gZGVzYy5zdGF0X2Rlc2Muc3RhdGljX3RyZWU7CiAgICAgICAgdmFyIGhhc19zdHJlZSA9IGRlc2Muc3RhdF9kZXNjLmhhc19zdHJlZTsKICAgICAgICB2YXIgZWxlbXMgPSBkZXNjLnN0YXRfZGVzYy5lbGVtczsKICAgICAgICB2YXIgbiwgbTsKICAgICAgICB2YXIgbWF4X2NvZGUgPSAtMTsKICAgICAgICB2YXIgbm9kZTsKICAgICAgICBzLmhlYXBfbGVuID0gMDsKICAgICAgICBzLmhlYXBfbWF4ID0gSEVBUF9TSVpFOwogICAgICAgIGZvciAobiA9IDA7IG4gPCBlbGVtczsgbisrKSB7CiAgICAgICAgICBpZiAodHJlZVtuICogMl0gIT09IDApIHsKICAgICAgICAgICAgcy5oZWFwWysrcy5oZWFwX2xlbl0gPSBtYXhfY29kZSA9IG47CiAgICAgICAgICAgIHMuZGVwdGhbbl0gPSAwOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgdHJlZVtuICogMiArIDFdID0gMDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgd2hpbGUgKHMuaGVhcF9sZW4gPCAyKSB7CiAgICAgICAgICBub2RlID0gcy5oZWFwWysrcy5oZWFwX2xlbl0gPSBtYXhfY29kZSA8IDIgPyArK21heF9jb2RlIDogMDsKICAgICAgICAgIHRyZWVbbm9kZSAqIDJdID0gMTsKICAgICAgICAgIHMuZGVwdGhbbm9kZV0gPSAwOwogICAgICAgICAgcy5vcHRfbGVuLS07CiAgICAgICAgICBpZiAoaGFzX3N0cmVlKSB7CiAgICAgICAgICAgIHMuc3RhdGljX2xlbiAtPSBzdHJlZVtub2RlICogMiArIDFdOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBkZXNjLm1heF9jb2RlID0gbWF4X2NvZGU7CiAgICAgICAgZm9yIChuID0gcy5oZWFwX2xlbiA+PiAxOyBuID49IDE7IG4tLSkgewogICAgICAgICAgcHFkb3duaGVhcChzLCB0cmVlLCBuKTsKICAgICAgICB9CiAgICAgICAgbm9kZSA9IGVsZW1zOwogICAgICAgIGRvIHsKICAgICAgICAgIG4gPSBzLmhlYXBbMV07CiAgICAgICAgICBzLmhlYXBbMV0gPSBzLmhlYXBbcy5oZWFwX2xlbi0tXTsKICAgICAgICAgIHBxZG93bmhlYXAocywgdHJlZSwgMSk7CiAgICAgICAgICBtID0gcy5oZWFwWzFdOwogICAgICAgICAgcy5oZWFwWy0tcy5oZWFwX21heF0gPSBuOwogICAgICAgICAgcy5oZWFwWy0tcy5oZWFwX21heF0gPSBtOwogICAgICAgICAgdHJlZVtub2RlICogMl0gPSB0cmVlW24gKiAyXSArIHRyZWVbbSAqIDJdOwogICAgICAgICAgcy5kZXB0aFtub2RlXSA9IChzLmRlcHRoW25dID49IHMuZGVwdGhbbV0gPyBzLmRlcHRoW25dIDogcy5kZXB0aFttXSkgKyAxOwogICAgICAgICAgdHJlZVtuICogMiArIDFdID0gdHJlZVttICogMiArIDFdID0gbm9kZTsKICAgICAgICAgIHMuaGVhcFsxXSA9IG5vZGUrKzsKICAgICAgICAgIHBxZG93bmhlYXAocywgdHJlZSwgMSk7CiAgICAgICAgfSB3aGlsZSAocy5oZWFwX2xlbiA+PSAyKTsKICAgICAgICBzLmhlYXBbLS1zLmhlYXBfbWF4XSA9IHMuaGVhcFsxXTsKICAgICAgICBnZW5fYml0bGVuKHMsIGRlc2MpOwogICAgICAgIGdlbl9jb2Rlcyh0cmVlLCBtYXhfY29kZSwgcy5ibF9jb3VudCk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gc2Nhbl90cmVlKHMsIHRyZWUsIG1heF9jb2RlKSB7CiAgICAgICAgdmFyIG47CiAgICAgICAgdmFyIHByZXZsZW4gPSAtMTsKICAgICAgICB2YXIgY3VybGVuOwogICAgICAgIHZhciBuZXh0bGVuID0gdHJlZVswICogMiArIDFdOwogICAgICAgIHZhciBjb3VudCA9IDA7CiAgICAgICAgdmFyIG1heF9jb3VudCA9IDc7CiAgICAgICAgdmFyIG1pbl9jb3VudCA9IDQ7CiAgICAgICAgaWYgKG5leHRsZW4gPT09IDApIHsKICAgICAgICAgIG1heF9jb3VudCA9IDEzODsKICAgICAgICAgIG1pbl9jb3VudCA9IDM7CiAgICAgICAgfQogICAgICAgIHRyZWVbKG1heF9jb2RlICsgMSkgKiAyICsgMV0gPSA2NTUzNTsKICAgICAgICBmb3IgKG4gPSAwOyBuIDw9IG1heF9jb2RlOyBuKyspIHsKICAgICAgICAgIGN1cmxlbiA9IG5leHRsZW47CiAgICAgICAgICBuZXh0bGVuID0gdHJlZVsobiArIDEpICogMiArIDFdOwogICAgICAgICAgaWYgKCsrY291bnQgPCBtYXhfY291bnQgJiYgY3VybGVuID09PSBuZXh0bGVuKSB7CiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgfSBlbHNlIGlmIChjb3VudCA8IG1pbl9jb3VudCkgewogICAgICAgICAgICBzLmJsX3RyZWVbY3VybGVuICogMl0gKz0gY291bnQ7CiAgICAgICAgICB9IGVsc2UgaWYgKGN1cmxlbiAhPT0gMCkgewogICAgICAgICAgICBpZiAoY3VybGVuICE9PSBwcmV2bGVuKSB7CiAgICAgICAgICAgICAgcy5ibF90cmVlW2N1cmxlbiAqIDJdKys7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgcy5ibF90cmVlW1JFUF8zXzYgKiAyXSsrOwogICAgICAgICAgfSBlbHNlIGlmIChjb3VudCA8PSAxMCkgewogICAgICAgICAgICBzLmJsX3RyZWVbUkVQWl8zXzEwICogMl0rKzsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHMuYmxfdHJlZVtSRVBaXzExXzEzOCAqIDJdKys7CiAgICAgICAgICB9CiAgICAgICAgICBjb3VudCA9IDA7CiAgICAgICAgICBwcmV2bGVuID0gY3VybGVuOwogICAgICAgICAgaWYgKG5leHRsZW4gPT09IDApIHsKICAgICAgICAgICAgbWF4X2NvdW50ID0gMTM4OwogICAgICAgICAgICBtaW5fY291bnQgPSAzOwogICAgICAgICAgfSBlbHNlIGlmIChjdXJsZW4gPT09IG5leHRsZW4pIHsKICAgICAgICAgICAgbWF4X2NvdW50ID0gNjsKICAgICAgICAgICAgbWluX2NvdW50ID0gMzsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIG1heF9jb3VudCA9IDc7CiAgICAgICAgICAgIG1pbl9jb3VudCA9IDQ7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9CiAgICAgIGZ1bmN0aW9uIHNlbmRfdHJlZShzLCB0cmVlLCBtYXhfY29kZSkgewogICAgICAgIHZhciBuOwogICAgICAgIHZhciBwcmV2bGVuID0gLTE7CiAgICAgICAgdmFyIGN1cmxlbjsKICAgICAgICB2YXIgbmV4dGxlbiA9IHRyZWVbMCAqIDIgKyAxXTsKICAgICAgICB2YXIgY291bnQgPSAwOwogICAgICAgIHZhciBtYXhfY291bnQgPSA3OwogICAgICAgIHZhciBtaW5fY291bnQgPSA0OwogICAgICAgIGlmIChuZXh0bGVuID09PSAwKSB7CiAgICAgICAgICBtYXhfY291bnQgPSAxMzg7CiAgICAgICAgICBtaW5fY291bnQgPSAzOwogICAgICAgIH0KICAgICAgICBmb3IgKG4gPSAwOyBuIDw9IG1heF9jb2RlOyBuKyspIHsKICAgICAgICAgIGN1cmxlbiA9IG5leHRsZW47CiAgICAgICAgICBuZXh0bGVuID0gdHJlZVsobiArIDEpICogMiArIDFdOwogICAgICAgICAgaWYgKCsrY291bnQgPCBtYXhfY291bnQgJiYgY3VybGVuID09PSBuZXh0bGVuKSB7CiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgfSBlbHNlIGlmIChjb3VudCA8IG1pbl9jb3VudCkgewogICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgc2VuZF9jb2RlKHMsIGN1cmxlbiwgcy5ibF90cmVlKTsKICAgICAgICAgICAgfSB3aGlsZSAoLS1jb3VudCAhPT0gMCk7CiAgICAgICAgICB9IGVsc2UgaWYgKGN1cmxlbiAhPT0gMCkgewogICAgICAgICAgICBpZiAoY3VybGVuICE9PSBwcmV2bGVuKSB7CiAgICAgICAgICAgICAgc2VuZF9jb2RlKHMsIGN1cmxlbiwgcy5ibF90cmVlKTsKICAgICAgICAgICAgICBjb3VudC0tOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHNlbmRfY29kZShzLCBSRVBfM182LCBzLmJsX3RyZWUpOwogICAgICAgICAgICBzZW5kX2JpdHMocywgY291bnQgLSAzLCAyKTsKICAgICAgICAgIH0gZWxzZSBpZiAoY291bnQgPD0gMTApIHsKICAgICAgICAgICAgc2VuZF9jb2RlKHMsIFJFUFpfM18xMCwgcy5ibF90cmVlKTsKICAgICAgICAgICAgc2VuZF9iaXRzKHMsIGNvdW50IC0gMywgMyk7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBzZW5kX2NvZGUocywgUkVQWl8xMV8xMzgsIHMuYmxfdHJlZSk7CiAgICAgICAgICAgIHNlbmRfYml0cyhzLCBjb3VudCAtIDExLCA3KTsKICAgICAgICAgIH0KICAgICAgICAgIGNvdW50ID0gMDsKICAgICAgICAgIHByZXZsZW4gPSBjdXJsZW47CiAgICAgICAgICBpZiAobmV4dGxlbiA9PT0gMCkgewogICAgICAgICAgICBtYXhfY291bnQgPSAxMzg7CiAgICAgICAgICAgIG1pbl9jb3VudCA9IDM7CiAgICAgICAgICB9IGVsc2UgaWYgKGN1cmxlbiA9PT0gbmV4dGxlbikgewogICAgICAgICAgICBtYXhfY291bnQgPSA2OwogICAgICAgICAgICBtaW5fY291bnQgPSAzOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgbWF4X2NvdW50ID0gNzsKICAgICAgICAgICAgbWluX2NvdW50ID0gNDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgICAgZnVuY3Rpb24gYnVpbGRfYmxfdHJlZShzKSB7CiAgICAgICAgdmFyIG1heF9ibGluZGV4OwogICAgICAgIHNjYW5fdHJlZShzLCBzLmR5bl9sdHJlZSwgcy5sX2Rlc2MubWF4X2NvZGUpOwogICAgICAgIHNjYW5fdHJlZShzLCBzLmR5bl9kdHJlZSwgcy5kX2Rlc2MubWF4X2NvZGUpOwogICAgICAgIGJ1aWxkX3RyZWUocywgcy5ibF9kZXNjKTsKICAgICAgICBmb3IgKG1heF9ibGluZGV4ID0gQkxfQ09ERVMgLSAxOyBtYXhfYmxpbmRleCA+PSAzOyBtYXhfYmxpbmRleC0tKSB7CiAgICAgICAgICBpZiAocy5ibF90cmVlW2JsX29yZGVyW21heF9ibGluZGV4XSAqIDIgKyAxXSAhPT0gMCkgewogICAgICAgICAgICBicmVhazsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcy5vcHRfbGVuICs9IDMgKiAobWF4X2JsaW5kZXggKyAxKSArIDUgKyA1ICsgNDsKICAgICAgICByZXR1cm4gbWF4X2JsaW5kZXg7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gc2VuZF9hbGxfdHJlZXMocywgbGNvZGVzLCBkY29kZXMsIGJsY29kZXMpIHsKICAgICAgICB2YXIgcmFuazsKICAgICAgICBzZW5kX2JpdHMocywgbGNvZGVzIC0gMjU3LCA1KTsKICAgICAgICBzZW5kX2JpdHMocywgZGNvZGVzIC0gMSwgNSk7CiAgICAgICAgc2VuZF9iaXRzKHMsIGJsY29kZXMgLSA0LCA0KTsKICAgICAgICBmb3IgKHJhbmsgPSAwOyByYW5rIDwgYmxjb2RlczsgcmFuaysrKSB7CiAgICAgICAgICBzZW5kX2JpdHMocywgcy5ibF90cmVlW2JsX29yZGVyW3JhbmtdICogMiArIDFdLCAzKTsKICAgICAgICB9CiAgICAgICAgc2VuZF90cmVlKHMsIHMuZHluX2x0cmVlLCBsY29kZXMgLSAxKTsKICAgICAgICBzZW5kX3RyZWUocywgcy5keW5fZHRyZWUsIGRjb2RlcyAtIDEpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGRldGVjdF9kYXRhX3R5cGUocykgewogICAgICAgIHZhciBibGFja19tYXNrID0gNDA5MzYyNDQ0NzsKICAgICAgICB2YXIgbjsKICAgICAgICBmb3IgKG4gPSAwOyBuIDw9IDMxOyBuKyssIGJsYWNrX21hc2sgPj4+PSAxKSB7CiAgICAgICAgICBpZiAoYmxhY2tfbWFzayAmIDEgJiYgcy5keW5fbHRyZWVbbiAqIDJdICE9PSAwKSB7CiAgICAgICAgICAgIHJldHVybiBaX0JJTkFSWTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKHMuZHluX2x0cmVlWzkgKiAyXSAhPT0gMCB8fCBzLmR5bl9sdHJlZVsxMCAqIDJdICE9PSAwIHx8IHMuZHluX2x0cmVlWzEzICogMl0gIT09IDApIHsKICAgICAgICAgIHJldHVybiBaX1RFWFQ7CiAgICAgICAgfQogICAgICAgIGZvciAobiA9IDMyOyBuIDwgTElURVJBTFM7IG4rKykgewogICAgICAgICAgaWYgKHMuZHluX2x0cmVlW24gKiAyXSAhPT0gMCkgewogICAgICAgICAgICByZXR1cm4gWl9URVhUOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gWl9CSU5BUlk7CiAgICAgIH0KICAgICAgdmFyIHN0YXRpY19pbml0X2RvbmUgPSBmYWxzZTsKICAgICAgZnVuY3Rpb24gX3RyX2luaXQocykgewogICAgICAgIGlmICghc3RhdGljX2luaXRfZG9uZ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IDMpOwogICAgICAgICAgc2VuZF9hbGxfdHJlZXMocywgcy5sX2Rlc2MubWF4X2NvZGUgKyAxLCBzLmRfZGVzYy5tYXhfY29kZSArIDEsIG1heF9ibGluZGV4ICsgMSk7CiAgICAgICAgICBjb21wcmVzc19ibG9jayhzLCBzLmR5bl9sdHJlZSwgcy5keW5fZHRyZWUpOwogICAgICAgIH0KICAgICAgICBpbml0X2Jsb2NrKHMpOwogICAgICAgIGlmIChsYXN0KSB7CiAgICAgICAgICBiaV93aW5kdXAocyk7CiAgICAgICAgfQogICAgICB9CiAgICAgIGZ1bmN0aW9uIF90cl90YWxseShzLCBkaXN0LCBsYykgewogICAgICAgIHMucGVuZGluZ19idWZbcy5kX2J1ZiArIHMubGFzdF9saXQgKiAyXSA9IGRpc3QgPj4+IDggJiAyNTU7CiAgICAgICAgcy5wZW5kaW5nX2J1ZltzLmRfYnVmICsgcy5sYXN0X2xpdCAqIDIgKyAxXSA9IGRpc3QgJiAyNTU7CiAgICAgICAgcy5wZW5kaW5nX2J1ZltzLmxfYnVmICsgcy5sYXN0X2xpdF0gPSBsYyAmIDI1NTsKICAgICAgICBzLmxhc3RfbGl0Kys7CiAgICAgICAgaWYgKGRpc3QgPT09IDApIHsKICAgICAgICAgIHMuZHluX2x0cmVlW2xjICogMl0rKzsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgcy5tYXRjaGVzKys7CiAgICAgICAgICBkaXN0LS07CiAgICAgICAgICBzLmR5bl9sdHJlZVsoX2xlbmd0aF9jb2RlW2xjXSArIExJVEVSQUxTICsgMSkgKiAyXSsrOwogICAgICAgICAgcy5keW5fZHRyZWVbZF9jb2RlKGRpc3QpICogMl0rKzsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHMubGFzdF9saXQgPT09IHMubGl0X2J1ZnNpemUgLSAxOwogICAgICB9CiAgICAgIGV4cG9ydHMyLl90cl9pbml0ID0gX3RyX2luaXQ7CiAgICAgIGV4cG9ydHMyLl90cl9zdG9yZWRfYmxvY2sgPSBfdHJfc3RvcmVkX2Jsb2NrOwogICAgICBleHBvcnRzMi5fdHJfZmx1c2hfYmxvY2sgPSBfdHJfZmx1c2hfYmxvY2s7CiAgICAgIGV4cG9ydHMyLl90cl90YWxseSA9IF90cl90YWxseTsKICAgICAgZXhwb3J0czIuX3RyX2FsaWduID0gX3RyX2FsaWduOwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvYWRsZXIzMi5qcwogIHZhciByZXF1aXJlX2FkbGVyMzIgPSBfX2NvbW1vbkpTKHsKICAgICJub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvYWRsZXIzMi5qcyIoZXhwb3J0czIsIG1vZHVsZTIpIHsKICAgICAgaW5pdF9idWZmZXJfc2hpbSgpOwogICAgICAidXNlIHN0cmljdCI7CiAgICAgIGZ1bmN0aW9uIGFkbGVyMzIoYWRsZXIsIGJ1ZiwgbGVuLCBwb3MpIHsKICAgICAgICB2YXIgczEgPSBhZGxlciAmIDY1NTM1IHwgMCwgczIgPSBhZGxlciA+Pj4gMTYgJiA2NTUzNSB8IDAsIG4gPSAwOwogICAgICAgIHdoaWxlIChsZW4gIT09IDApIHsKICAgICAgICAgIG4gPSBsZW4gPiAyZTMgPyAyZTMgOiBsZW47CiAgICAgICAgICBsZW4gLT0gbjsKICAgICAgICAgIGRvIHsKICAgICAgICAgICAgczEgPSBzMSArIGJ1Zltwb3MrK10gfCAwOwogICAgICAgICAgICBzMiA9IHMyICsgczEgfCAwOwogICAgICAgICAgfSB3aGlsZSAoLS1uKTsKICAgICAgICAgIHMxICU9IDY1NTIxOwogICAgICAgICAgczIgJT0gNjU1MjE7CiAgICAgICAgfQogICAgICAgIHJldHVybiBzMSB8IHMyIDw8IDE2IHwgMDsKICAgICAgfQogICAgICBtb2R1bGUyLmV4cG9ydHMgPSBhZGxlcjMyOwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvY3JjMzIuanMKICB2YXIgcmVxdWlyZV9jcmMzMiA9IF9fY29tbW9uSlMoewogICAgIm5vZGVfbW9kdWxlcy8ucG5wbS9wYWtvQDEuMC4xMS9ub2RlX21vZHVsZXMvcGFrby9saWIvemxpYi9jcmMzMi5qcyIoZXhwb3J0czIsIG1vZHVsZTIpIHsKICAgICAgaW5pdF9idWZmZXJfc2hpbSgpOwogICAgICAidXNlIHN0cmljdCI7CiAgICAgIGZ1bmN0aW9uIG1ha2VUYWJsZSgpIHsKICAgICAgICB2YXIgYywgdGFibGUgPSBbXTsKICAgICAgICBmb3IgKHZhciBuID0gMDsgbiA8IDI1NjsgbisrKSB7CiAgICAgICAgICBjID0gbjsKICAgICAgICAgIGZvciAodmFyIGsgPSAwOyBrIDwgODsgaysrKSB7CiAgICAgICAgICAgIGMgPSBjICYgMSA/IDM5ODgyOTIzODQgXiBjID4+PiAxIDogYyA+Pj4gMTsKICAgICAgICAgIH0KICAgICAgICAgIHRhYmxlW25dID0gYzsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHRhYmxlOwogICAgICB9CiAgICAgIHZhciBjcmNUYWJsZSA9IG1ha2VUYWJsZSgpOwogICAgICBmdW5jdGlvbiBjcmMzMihjcmMsIGJ1ZiwgbGVuLCBwb3MpIHsKICAgICAgICB2YXIgdCA9IGNyY1RhYmxlLCBlbmQgPSBwb3MgKyBsZW47CiAgICAgICAgY3JjIF49IC0xOwogICAgICAgIGZvciAodmFyIGkgPSBwb3M7IGkgPCBlbmQ7IGkrKykgewogICAgICAgICAgY3JjID0gY3JjID4+PiA4IF4gdFsoY3JjIF4gYnVmW2ldKSAmIDI1NV07CiAgICAgICAgfQogICAgICAgIHJldHVybiBjcmMgXiAtMTsKICAgICAgfQogICAgICBtb2R1bGU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kFMUyArIDEgKyBMRU5HVEhfQ09ERVM7CiAgICAgIHZhciBEX0NPREVTID0gMzA7CiAgICAgIHZhciBCTF9DT0RFUyA9IDE5OwogICAgICB2YXIgSEVBUF9TSVpFID0gMiAqIExfQ09ERVMgKyAxOwogICAgICB2YXIgTUFYX0JJVFMgPSAxNTsKICAgICAgdmFyIE1JTl9NQVRDSCA9IDM7CiAgICAgIHZhciBNQVhfTUFUQ0ggPSAyNTg7CiAgICAgIHZhciBNSU5fTE9PS0FIRUFEID0gTUFYX01BVENIICsgTUlOX01BVENIICsgMTsKICAgICAgdmFyIFBSRVNFVF9ESUNUID0gMzI7CiAgICAgIHZhciBJTklUX1NUQVRFID0gNDI7CiAgICAgIHZhciBFWFRSQV9TVEFURSA9IDY5OwogICAgICB2YXIgTkFNRV9TVEFURSA9IDczOwogICAgICB2YXIgQ09NTUVOVF9TVEFURSA9IDkxOwogICAgICB2YXIgSENSQ19TVEFURSA9IDEwMzsKICAgICAgdmFyIEJVU1lfU1RBVEUgPSAxMTM7CiAgICAgIHZhciBGSU5JU0hfU1RBVEUgPSA2NjY7CiAgICAgIHZhciBCU19ORUVEX01PUkUgPSAxOwogICAgICB2YXIgQlNfQkxPQ0tfRE9ORSA9IDI7CiAgICAgIHZhciBCU19GSU5JU0hfU1RBUlRFRCA9IDM7CiAgICAgIHZhciBCU19GSU5JU0hfRE9ORSA9IDQ7CiAgICAgIHZhciBPU19DT0RFID0gMzsKICAgICAgZnVuY3Rpb24gZXJyKHN0cm0sIGVycm9yQ29kZSkgewogICAgICAgIHN0cm0ubXNnID0gbXNnW2Vycm9yQ29kZV07CiAgICAgICAgcmV0dXJuIGVycm9yQ29kZTsKICAgICAgfQogICAgICBmdW5jdGlvbiByYW5rKGYpIHsKICAgICAgICByZXR1cm4gKGYgPDwgMSkgLSAoZiA+IDQgPyA5IDogMCk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gemVybyhidWYpIHsKICAgICAgICB2YXIgbGVuID0gYnVmLmxlbmd0aDsKICAgICAgICB3aGlsZSAoLS1sZW4gPj0gMCkgewogICAgICAgICAgYnVmW2xlbl0gPSAwOwogICAgICAgIH0KICAgICAgfQogICAgICBmdW5jdGlvbiBmbHVzaF9wZW5kaW5nKHN0cm0pIHsKICAgICAgICB2YXIgcyA9IHN0cm0uc3RhdGU7CiAgICAgICAgdmFyIGxlbiA9IHMucGVuZGluZzsKICAgICAgICBpZiAobGVuID4gc3RybS5hdmFpbF9vdXQpIHsKICAgICAgICAgIGxlbiA9IHN0cm0uYXZhaWxfb3V0OwogICAgICAgIH0KICAgICAgICBpZiAobGVuID09PSAwKSB7CiAgICAgICAgICByZXR1cm47CiAgICAgICAgfQogICAgICAgIHV0aWxzLmFycmF5U2V0KHN0cm0ub3V0cHV0LCBzLnBlbmRpbmdfYnVmLCBzLnBlbmRpbmdfb3V0LCBsZW4sIHN0cm0ubmV4dF9vdXQpOwogICAgICAgIHN0cm0ubmV4dF9vdXQgKz0gbGVuOwogICAgICAgIHMucGVuZGluZ19vdXQgKz0gbGVuOwogICAgICAgIHN0cm0udG90YWxfb3V0ICs9IGxlbjsKICAgICAgICBzdHJtLmF2YWlsX291dCAtPSBsZW47CiAgICAgICAgcy5wZW5kaW5nIC09IGxlbjsKICAgICAgICBpZiAocy5wZW5kaW5nID09PSAwKSB7CiAgICAgICAgICBzLnBlbmRpbmdfb3V0ID0gMDsKICAgICAgICB9CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZmx1c2hfYmxvY2tfb25seShzLCBsYXN0KSB7CiAgICAgICAgdHJlZXMuX3RyX2ZsdXNoX2Jsb2NrKHMsIHMuYmxvY2tfc3RhcnQgPj0gMCA/IHMuYmxvY2tfc3RhcnQgOiAtMSwgcy5zdHJzdGFydCAtIHMuYmxvY2tfc3RhcnQsIGxhc3QpOwogICAgICAgIHMuYmxvY2tfc3RhcnQgPSBzLnN0cnN0YXJ0OwogICAgICAgIGZsdXNoX3BlbmRpbmcocy5zdHJtKTsKICAgICAgfQogICA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3VyX21hdGNoKSB7CiAgICAgICAgdmFyIGNoYWluX2xlbmd0aCA9IHMubWF4X2NoYWluX2xlbmd0aDsKICAgICAgICB2YXIgc2NhbiA9IHMuc3Ryc3RhcnQ7CiAgICAgICAgdmFyIG1hdGNoOwogICAgICAgIHZhciBsZW47CiAgICAgICAgdmFyIGJlc3RfbGVuID0gcy5wcmV2X2xlbmd0aDsKICAgICAgICB2YXIgbmljZV9tYXRjaCA9IHMubmljZV9tYXRjaDsKICAgICAgICB2YXIgbGltaXQgPSBzLnN0cnN0YXJ0ID4gcy53X3NpemUgLSBNSU5fTE9PS0FIRUFEID8gcy5zdHJzdGFydCAtIChzLndfc2l6ZSAtIE1JTl9MT09LQUhFQUQpIDogMDsKICAgICAgICB2YXIgX3dpbiA9IHMud2luZG93OwogICAgICAgIHZhciB3bWFzayA9IHMud19tYXNrOwogICAgICAgIHZhciBwcmV2ID0gcy5wcmV2OwogICAgICAgIHZhciBzdHJlbmQgPSBzLnN0cnN0YXJ0ICsgTUFYX01BVENIOwogICAgICAgIHZhciBzY2FuX2VuZDEgPSBfd2luW3NjYW4gKyBiZXN0X2xlbiAtIDFdOwogICAgICAgIHZhciBzY2FuX2VuZCA9IF93aW5bc2NhbiArIGJlc3RfbGVuXTsKICAgICAgICBpZiAocy5wcmV2X2xlbmd0aCA+PSBzLmdvb2RfbWF0Y2gpIHsKICAgICAgICAgIGNoYWluX2xlbmd0aCA+Pj0gMjsKICAgICAgICB9CiAgICAgICAgaWYgKG5pY2VfbWF0Y2ggPiBzLmxvb2thaGVhZCkgewogICAgICAgICAgbmljZV9tYXRjaCA9IHMubG9va2FoZWFkOwogICAgICAgIH0KICAgICAgICBkbyB7CiAgICAgICAgICBtYXRjaCA9IGN1cl9tYXRjaDsKICAgICAgICAgIGlmIChfd2luW21hdGNoICsgYmVzdF9sZW5dICE9PSBzY2FuX2VuZCB8fCBfd2luW21hdGNoICsgYmVzdF9sZW4gLSAxXSAhPT0gc2Nhbl9lbmQxIHx8IF93aW5bbWF0Y2hdICE9PSBfd2luW3NjYW5dIHx8IF93aW5bKyttYXRjaF0gIT09IF93aW5bc2NhbiArIDFdKSB7CiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgfQogICAgICAgICAgc2NhbiArPSAyOwogICAgICAgICAgbWF0Y2grKzsKICAgICAgICAgIGRvIHsKICAgICAgICAgIH0gd2hpbGUgKF93aW5bKytzY2FuXSA9PT0gX3dpblsrK21hdGNoXSAmJiBfd2luWysrc2Nhbl0gPT09IF93aW5bKyttYXRjaF0gJiYgX3dpblsrK3NjYW5dID09PSBfd2luWysrbWF0Y2hdICYmIF93aW5bKytzY2FuXSA9PT0gX3dpblsrK21hdGNoXSAmJiBfd2luWysrc2Nhbl0gPT09IF93aW5bKyttYXRjaF0gJiYgX3dpblsrK3NjYW5dID09PSBfd2luWysrbWF0Y2hdICYmIF93aW5bKytzY2FuXSA9PT0gX3dpblsrK21hdGNoXSAmJiBfd2luWysrc2Nhbl0gPT09IF93aW5bKyttYXRjaF0gJiYgc2NhbiA8IHN0cmVuZCk7CiAgICAgICAgICBsZW4gPSBNQVhfTUFUQ0ggLSAoc3RyZW5kIC0gc2Nhbik7CiAgICAgICAgICBzY2FuID0gc3RyZW5kIC0gTUFYX01BVENIOwogICAgICAgICAgaWYgKGxlbiA+IGJlc3RfbGVuKSB7CiAgICAgICAgICAgIHMubWF0Y2hfc3RhcnQgPSBjdXJfbWF0Y2g7CiAgICAgICAgICAgIGJlc3RfbGVuID0gbGVuOwogICAgICAgICAgICBpZiAobGVuID49IG5pY2VfbWF0Y2gpIHsKICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgICBzY2FuX2VuZDEgPSBfd2luW3NjYW4gKyBiZXN0X2xlbiAtIDFdOwogICAgICAgICAgICBzY2FuX2VuZCA9IF93aW5bc2NhbiArIGJlc3RfbGVuXTsKICAgICAgICAgIH0KICAgICAgICB9IHdoaWxlICgoY3VyX21hdGNoID0gcHJldltjdXJfbWF0Y2ggJiB3bWFza10pID4gbGltaXQgJiYgLS1jaGFpbl9sZW5ndGggIT09IDApOwogICAgICAgIGlmIChiZXN0X2xlbiA8PSBzLmxvb2thaGVhZCkgewogICAgICAgICAgcmV0dXJuIGJlc3RfbGVuOwogICAgICAgIH0KICAgICAgICByZXR1cm4gcy5sb29rYWhlYWQ7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZmlsbF93aW5kb3cocykgewogICAgICAgIHZhciBfd19zaXplID0gcy53X3NpemU7CiAgICAgICAgdmFyIHAsIG4sIG0sIG1vcmUsIHN0cjsKICAgICAgICBkbyB7CiAgICAgICAgICBtb3JlID0gcy53aW5kb3dfc2l6ZSAtIHMubG9va2FoZWFkIC0gcy5zdHJzdGFydDsKICAgICAgICAgIGlmIChzLnN0cnN0YXJ0ID49IF93X3NpemUgKyAoX3dfc2l6ZSAtIE1JTl9MT09LQUhFQUQpKSB7CiAgICAgICAgICAgIHV0aWxzLmFycmF5U2V0KHMud2luZG93LCBzLndpbmRvdywgX3dfc2l6ZSwgX3dfc2l6ZSwgMCk7CiAgICAgICAgICAgIHMubWF0Y2hfc3RhcnQgLT0gX3dfc2l6ZTsKICAgICAgICAgICAgcy5zdHJzdGFydCAtPSBfd19zaXplOwogICAgICAgICAgICBzLmJsb2NrX3N0YXJ0IC09IF93X3NpemU7CiAgICAgICAgICAgIG4gPSBzLmhhc2hfc2l6ZTsKICAgICAgICAgICAgcCA9IG47CiAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICBtID0gcy5oZWFkWy0tcF07CiAgICAgICAgICAgICAgcy5oZWFkW3BdID0gbSA+PSBfd19zaXplID8gbSAtIF93X3NpemUgOiAwOwogICAgICAgICAgICB9IHdoaWxlICgtLW4pOwogICAgICAgICAgICBuID0gX3dfc2l6ZTsKICAgICAgICAgICAgcCA9IG47CiAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICBtID0gcy5wcmV2Wy0tcF07CiAgICAgICAgICAgICAgcy5wcmV2W3BdID0gbSA+PSBfd19zaXplID8gbSAtIF93X3NpemUgOiAwOwogICAgICAgICAgICB9IHdoaWxlICgtLW4pOwogICAgICAgICAgICBtb3JlICs9IF93X3NpemU7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX2luID09PSAwKSB7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgICAgbiA9IHJlYWRfYnVmKHMuc3RybSwgcy53aW5kb3csIHMuc3Ryc3RhcnQgKyBzLmxvb2thaGVhZCwgbW9yZSk7CiAgICAgICAgICBzLmxvb2thaGVhZCArPSBuOwogICAgICAgICAgaWYgKHMubG9va2FoZWFkICsgcy5pbnNlcnQgPj0gTUlOX01BVENIKSB7CiAgICAgICAgICAgIHN0ciA9IHMuc3Ryc3RhcnQgLSBzLmluc2VydDsKICAgICAgICAgICAgcy5pbnNfaCA9IHMud2luZG93W3N0cl07CiAgICAgICAgICAgIHMuaW5zX2ggPSAocy5pbnNfaCA8PCBzLmhhc2hfc2hpZnQgXiBzLndpbmRvd1tzdHIgKyAxXSkgJiBzLmhhc2hfbWFzazsKICAgICAgICAgICAgd2hpbGUgKHMuaW5zZXJ0KSB7CiAgICAgICAgICAgICAgcy5pbnNfaCA9IChzLmluc19oIDw8IHMuaGFzaF9zaGlmdCBeIHMud2luZG93W3N0ciArIE1JTl9NQVRDSCAtIDFdKSAmIHMuaGFzaF9tYXNrOwogICAgICAgICAgICAgIHMucHJldltzdHIgJiBzLndfbWFza10gPSBzLmhlYWRbcy5pbnNfaF07CiAgICAgICAgICAgICAgcy5oZWFkW3MuaW5zX2hdID0gc3RyOwogICAgICAgICAgICAgIHN0cisrOwogICAgICAgICAgICAgIHMuaW5zZXJ0LS07CiAgICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkICsgcy5pbnNlcnQgPCBNSU5fTUFUQ0gpIHsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0gd2hpbGUgKHMubG9va2FoZWFkIDwgTUlOX0xPT0tBSEVBRCAmJiBzLnN0cm0uYXZhaWxfaW4gIT09IDApOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGRlZmxhdGVfc3RvcmVkKHMsIGZsdXNoKSB7CiAgICAgICAgdmFyIG1heF9ibG9ja19zaXplID0gNjU1MzU7CiAgICAgICAgaWYgKG1heF9ibG9ja19zaXplID4gcy5wZW5kaW5nX2J1Zl9zaXplIC0gNSkgewogICAgICAgICAgbWF4X2Jsb2NrX3NpemUgPSBzLnBlbmRpbmdfYnVmX3NpemUgLSA1OwogICAgICAgIH0KICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA8PSAxKSB7CiAgICAgICAgICAgIGZpbGxfd2luZG93KHMpOwogICAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPT09IDAgJiYgZmx1c2ggPT09IFpfTk9fRkxVU0gpIHsKICAgICAgICAgICAgICByZXR1cm4gQlNfTkVFRF9NT1JFOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA9PT0gMCkgewogICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBzLnN0cnN0YXJ0ICs9IHMubG9va2FoZWFkOwogICAgICAgICAgcy5sb29rYWhlYWQgPSAwOwogICAgICAgICAgdmFyIG1heF9zdGFydCA9IHMuYmxvY2tfc3RhcnQgKyBtYXhfYmxvY2tfc2l6ZTsKICAgICAgICAgIGlmIChzLnN0cnN0YXJ0ID09PSAwIHx8IHMuc3Ryc3RhcnQgPj0gbWF4X3N0YXJ0KSB7CiAgICAgICAgICAgIHMubG9va2FoZWFkID0gcy5zdHJzdGFydCAtIG1heF9zdGFydDsKICAgICAgICAgICAgcy5zdHJzdGFydCA9IG1heF9zdGFydDsKICAgICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCBmYWxzZSk7CiAgICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgaWYgKHMuc3Ryc3RhcnQgLSBzLmJsb2NrX3N0YXJ0ID49IHMud19zaXplIC0gTUlOX0xPT0tBSEVBRCkgewogICAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIGZhbHNlKTsKICAgICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgICByZXR1cm4gQlNfTkVFRF9NT1JFOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHMuaW5zZXJ0ID0gMDsKICAgICAgICBpZiAoZmx1c2ggPT09IFpfRklOSVNIKSB7CiAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIHRydWUpOwogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIEJTX0ZJTklTSF9TVEFSVEVEOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIEJTX0ZJTklTSF9ET05FOwogICAgICAgIH0KICAgICAgICBpZiAocy5zdHJzdGFydCA+IHMuYmxvY2tfc3RhcnQpIHsKICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgZmFsc2UpOwogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgfQogICAgICBmdW5jdGlvbiBkZWZsYXRlX2Zhc3QocywgZmx1c2gpIHsKICAgICAgICB2YXIgaGFzaF9oZWFkOwogICAgICAgIHZhciBiZmx1c2g7CiAgICAgICAgZm9yICg7IDsgKSB7CiAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPCBNSU5fTE9PS0FIRUFEKSB7CiAgICAgICAgICAgIGZpbGxfd2luZG93KHMpOwogICAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPCBNSU5fTE9PS0FIRUFEICYmIGZsdXNoID09PSBaX05PX0ZMVVNIKSB7CiAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPT09IDApIHsKICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgaGFzaF9oZWFkID0gMDsKICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA+PSBNSU5fTUFUQ0gpIHsKICAgICAgICAgICAgcy5pbnNfaCA9IChzLmluc19oIDw8IHMuaGFzaF9zaGlmdCBeIHMud2luZG93W3Muc3Ryc3RhcnQgKyBNSU5fTUFUQ0ggLSAxXSkgJiBzLmhhc2hfbWFzazsKICAgICAgICAgICAgaGFzaF9oZWFkID0gcy5wcmV2W3Muc3Ryc3RhcnQgJiBzLndfbWFza10gPSBzLmhlYWRbcy5pbnNfaF07CiAgICAgICAgICAgIHMuaGVhZFtzLmluc19oXSA9IHMuc3Ryc3RhcnQ7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoaGFzaF9oZWFkICE9PSAwICYmIHMuc3Ryc3RhcnQgLSBoYXNoX2hlYWQgPD0gcy53X3NpemUgLSBNSU5fTE9PS0FIRUFEKSB7CiAgICAgICAgICAgIHMubWF0Y2hfbGVuZ3RoID0gbG9uZ2VzdF9tYXRjaChzLCBoYXNoX2hlYWQpOwogICAgICAgICAgfQogICAgICAgICAgaWYgKHMubWF0Y2hfbGVuZ3RoID49IE1JTl9NQVRDSCkgewogICAgICAgICAgICBiZmx1c2ggPSB0cmVlcy5fdHJfdGFsbHkocywgcy5zdHJzdGFydCAtIHMubWF0Y2hfc3RhcnQsIHMubWF0Y2hfbGVuZ3RoIC0gTUlOX01BVENIKTsKICAgICAgICAgICAgcy5sb29rYWhlYWQgLT0gcy5tYXRjaF9sZW5ndGg7CiAgICAgICAgICAgIGlmIChzLm1hdGNoX2xlbmd0aCA8PSBzLm1heF9sYXp5X21hdGNoICYmIHMubG9va2FoZWFkID49IE1JTl9NQVRDSCkgewogICAgICAgICAgICAgIHMubWF0Y2hfbGVuZ3RoLS07CiAgICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgICAgcy5zdHJzdGFydCsrOwogICAgICAgICAgICAgICAgcy5pbnNfaCA9IChzLmluc19oIDw8IHMuaGFzaF9zaGlmdCBeIHMud2luZG93W3Muc3Ryc3RhcnQgKyBNSU5fTUFUQ0ggLSAxXSkgJiBzLmhhc2hfbWFzazsKICAgICAgICAgICAgICAgIGhhc2hfaGVhZCA9IHMucHJldltzLnN0cnN0YXJ0ICYgcy53X21hc2tdID0gcy5oZWFkW3MuaW5zX2hdOwogICAgICAgICAgICAgICAgcy5oZWFkW3MuaW5zX2hdID0gcy5zdHJzdGFydDsKICAgICAgICAgICAgICB9IHdoaWxlICgtLXMubWF0Y2hfbGVuZ3RoICE9PSAwKTsKICAgICAgICAgICAgICBzLnN0cnN0YXJ0Kys7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgcy5zdHJzdGFydCArPSBzLm1hdGNoX2xlbmd0aDsKICAgICAgICAgICAgICBzLm1hdGNoX2xlbmd0aCA9IDA7CiAgICAgICAgICAgICAgcy5pbnNfaCA9IHMud2luZG93W3Muc3Ryc3RhcnRdOwogICAgICAgICAgICAgIHMuaW5zX2ggPSAocy5pbnNfaCA8PCBzLmhhc2hfc2hpZnQgXiBzLndpbmRvd1tzLnN0cnN0YXJ0ICsgMV0pICYgcy5oYXNoX21hc2s7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGJmbHVzaCA9IHRyZWVzLl90cl90YWxseShzLCAwLCBzLndpbmRvd1tzLnN0cnN0YXJ0XSk7CiAgICAgICAgICAgIHMubG9va2FoZWFkLS07CiAgICAgICAgICAgIHMuc3Ryc3RhcnQrKzsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChiZmx1c2gpIHsKICAgICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCBmYWxzZSk7CiAgICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBzLmluc2VydCA9IHMuc3Ryc3RhcnQgPCBNSU5fTUFUQ0ggLSAxID8gcy5zdHJzdGFydCA6IE1JTl9NQVRDSCAtIDE7CiAgICAgICAgaWYgKGZsdXNoID09PSBaX0ZJTklTSCkgewogICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCB0cnVlKTsKICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgIHJldHVybiBCU19GSU5JU0hfU1RBUlRFRDsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBCU19GSU5JU0hfRE9ORTsKICAgICAgICB9CiAgICAgICAgaWYgKHMubGFzdF9saXQpIHsKICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgZmFsc2UpOwogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIEJTX0JMT0NLX0RPTkU7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZGVmbGF0ZV9zbG93KHMsIGZsdXNoKSB7CiAgICAgICAgdmFyIGhhc2hfaGVhZDsKICAgICAgICB2YXIgYmZsdXNoOwogICAgICAgIHZhciBtYXhfaW5zZXJ0OwogICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgaWYgKHMubG9va2FoZWFkIDwgTUlOX0xPT0tBSEVBRCkgewogICAgICAgICAgICBmaWxsX3dpbmRvdyhzKTsKICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkIDwgTUlOX0xPT0tBSEVBRCAmJiBmbHVzaCA9PT0gWl9OT19GTFVTSCkgewogICAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkID09PSAwKSB7CiAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGhhc2hfaGVhZCA9IDA7CiAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPj0gTUlOX01BVENIKSB7CiAgICAgICAgICAgIHMuaW5zX2ggPSAocy5pbnNfaCA8PCBzLmhhc2hfc2hpZnQgXiBzLndpbmRvd1tzLnN0cnN0YXJ0ICsgTUlOX01BVENIIC0gMV0pICYgcy5oYXNoX21hc2s7CiAgICAgICAgICAgIGhhc2hfaGVhZCA9IHMucHJldltzLnN0cnN0YXJ0ICYgcy53X21hc2tdID0gcy5oZWFkW3MuaW5zX2hdOwogICAgICAgICAgICBzLmhlYWRbcy5pbnNfaF0gPSBzLnN0cnN0YXJ0OwogICAgICAgICAgfQogICAgICAgICAgcy5wcmV2X2xlbmd0aCA9IHMubWF0Y2hfbGVuZ3RoOwogICAgICAgICAgcy5wcmV2X21hdGNoID0gcy5tYXRjaF9zdGFydDsKICAgICAgICAgIHMubWF0Y2hfbGVuZ3RoID0gTUlOX01BVENIIC0gMTsKICAgICAgICAgIGlmIChoYXNoX2hlYWQgIT09IDAgJiYgcy5wcmV2X2xlbmd0aCA8IHMubWF4X2xhenlfbWF0Y2ggJiYgcy5zdHJzdGFydCAtIGhhc2hfaGVhZCA8PSBzLndfc2l6ZSAtIE1JTl9MT09LQUhFQUQpIHsKICAgICAgICAgICAgcy5tYXRjaF9sZW5ndGggPSBsb25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HJzdGFydDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0gd2hpbGUgKC0tcy5wcmV2X2xlbmd0aCAhPT0gMCk7CiAgICAgICAgICAgIHMubWF0Y2hfYXZhaWxhYmxlID0gMDsKICAgICAgICAgICAgcy5tYXRjaF9sZW5ndGggPSBNSU5fTUFUQ0ggLSAxOwogICAgICAgICAgICBzLnN0cnN0YXJ0Kys7CiAgICAgICAgICAgIGlmIChiZmx1c2gpIHsKICAgICAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIGZhbHNlKTsKICAgICAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSBpZiAocy5tYXRjaF9hdmFpbGFibGUpIHsKICAgICAgICAgICAgYmZsdXNoID0gdHJlZXMuX3RyX3RhbGx5KHMsIDAsIHMud2luZG93W3Muc3Ryc3RhcnQgLSAxXSk7CiAgICAgICAgICAgIGlmIChiZmx1c2gpIHsKICAgICAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIGZhbHNlKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBzLnN0cnN0YXJ0Kys7CiAgICAgICAgICAgIHMubG9va2FoZWFkLS07CiAgICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgfQogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcy5tYXRjaF9hdmFpbGFibGUgPSAxOwogICAgICAgICAgICBzLnN0cnN0YXJ0Kys7CiAgICAgICAgICAgIHMubG9va2FoZWFkLS07CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChzLm1hdGNoX2F2YWlsYWJsZSkgewogICAgICAgICAgYmZsdXNoID0gdHJlZXMuX3RyX3RhbGx5KHMsIDAsIHMud2luZG93W3Muc3Ryc3RhcnQgLSAxXSk7CiAgICAgICAgICBzLm1hdGNoX2F2YWlsYWJsZSA9IDA7CiAgICAgICAgfQogICAgICAgIHMuaW5zZXJ0ID0gcy5zdHJzdGFydCA8IE1JTl9NQVRDSCAtIDEgPyBzLnN0cnN0YXJ0IDogTUlOX01BVENIIC0gMTsKICAgICAgICBpZiAoZmx1c2ggPT09IFpfRklOSVNIKSB7CiAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIHRydWUpOwogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIEJTX0ZJTklTSF9TVEFSVEVEOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIEJTX0ZJTklTSF9ET05FOwogICAgICAgIH0KICAgICAgICBpZiAocy5sYXN0X2xpdCkgewogICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCBmYWxzZSk7CiAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICByZXR1cm4gQlNfTkVFRF9NT1JFOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gQlNfQkxPQ0tfRE9ORTsKICAgICAgfQogICAgICBmdW5jdGlvbiBkZWZsYXRlX3JsZShzLCBmbHVzaCkgewogICAgICAgIHZhciBiZmx1c2g7CiAgICAgICAgdmFyIHByZXY7CiAgICAgICAgdmFyIHNjYW4sIHN0cmVuZDsKICAgICAgICB2YXIgX3dpbiA9IHMud2luZG93OwogICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgaWYgKHMubG9va2FoZWFkIDw9IE1BWF9NQVRDSCkgewogICAgICAgICAgICBmaWxsX3dpbmRvdyhzKTsKICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkIDw9IE1BWF9NQVRDSCAmJiBmbHVzaCA9PT0gWl9OT19GTFVTSCkgewogICAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkID09PSAwKSB7CiAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIHMubWF0Y2hfbGVuZ3RoID0gMDsKICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA+PSBNSU5fTUFUQ0ggJiYgcy5zdHJzdGFydCA+IDApIHsKICAgICAgICAgICAgc2NhbiA9IHMuc3Ryc3RhcnQgLSAxOwogICAgICAgICAgICBwcmV2ID0gX3dpbltzY2FuXTsKICAgICAgICAgICAgaWYgKHByZXYgPT09IF93aW5bKytzY2FuXSAmJiBwcmV2ID09PSBfd2luWysrc2Nhbl0gJiYgcHJldiA9PT0gX3dpblsrK3NjYW5dKSB7CiAgICAgICAgICAgICAgc3RyZW5kID0gcy5zdHJzdGFydCArIE1BWF9NQVRDSDsKICAgICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgfSB3aGlsZSAocHJldiA9PT0gX3dpblsrK3NjYW5dICYmIHByZXYgPT09IF93aW5bKytzY2FuXSAmJiBwcmV2ID09PSBfd2luWysrc2Nhbl0gJiYgcHJldiA9PT0gX3dpblsrK3NjYW5dICYmIHByZXYgPT09IF93aW5bKytzY2FuXSAmJiBwcmV2ID09PSBfd2luWysrc2Nhbl0gJiYgcHJldiA9PT0gX3dpblsrK3NjYW5dICYmIHByZXYgPT09IF93aW5bKytzY2FuXSAmJiBzY2FuIDwgc3RyZW5kKTsKICAgICAgICAgICAgICBzLm1hdGNoX2xlbmd0aCA9IE1BWF9NQVRDSCAtIChzdHJlbmQgLSBzY2FuKTsKICAgICAgICAgICAgICBpZiAocy5tYXRjaF9sZW5ndGggPiBzLmxvb2thaGVhZCkgewogICAgICAgICAgICAgICAgcy5tYXRjaF9sZW5ndGggPSBzLmxvb2thaGVhZDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGlmIChzLm1hdGNoX2xlbmd0aCA+PSBNSU5fTUFUQ0gpIHsKICAgICAgICAgICAgYmZsdXNoID0gdHJlZXMuX3RyX3RhbGx5KHMsIDEsIHMubWF0Y2hfbGVuZ3RoIC0gTUlOX01BVENIKTsKICAgICAgICAgICAgcy5sb29rYWhlYWQgLT0gcy5tYXRjaF9sZW5ndGg7CiAgICAgICAgICAgIHMuc3Ryc3RhcnQgKz0gcy5tYXRjaF9sZW5ndGg7CiAgICAgICAgICAgIHMubWF0Y2hfbGVuZ3RoID0gMDsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGJmbHVzaCA9IHRyZWVzLl90cl90YWxseShzLCAwLCBzLndpbmRvd1tzLnN0cnN0YXJ0XSk7CiAgICAgICAgICAgIHMubG9va2FoZWFkLS07CiAgICAgICAgICAgIHMuc3Ryc3RhcnQrKzsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChiZmx1c2gpIHsKICAgICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCBmYWxzZSk7CiAgICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBzLmluc2VydCA9IDA7CiAgICAgICAgaWYgKGZsdXNoID09PSBaX0ZJTklTSCkgewogICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCB0cnVlKTsKICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgIHJldHVybiBCU19GSU5JU0hfU1RBUlRFRDsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBCU19GSU5JU0hfRE9ORTsKICAgICAgICB9CiAgICAgICAgaWYgKHMubGFzdF9saXQpIHsKICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgZmFsc2UpOwogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIEJTX0JMT0NLX0RPTkU7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZGVmbGF0ZV9odWZmKHMsIGZsdXNoKSB7CiAgICAgICAgdmFyIGJmbHVzaDsKICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA9PT0gMCkgewogICAgICAgICAgICBmaWxsX3dpbmRvdyhzKTsKICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkID09PSAwKSB7CiAgICAgICAgICAgICAgaWYgKGZsdXNoID09PSBaX05PX0ZMVVNIKSB7CiAgICAgICAgICAgICAgICByZXR1cm4gQlNfTkVFRF9NT1JFOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgcy5tYXRjaF9sZW5ndGggPSAwOwogICAgICAgICAgYmZsdXNoID0gdHJlZXMuX3RyX3RhbGx5KHMsIDAsIHMud2luZG93W3Muc3Ryc3RhcnRdKTsKICAgICAgICAgIHMubG9va2FoZWFkLS07CiAgICAgICAgICBzLnN0cnN0YXJ0Kys7CiAgICAgICAgICBpZiAoYmZsdXNoKSB7CiAgICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgZmFsc2UpOwogICAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcy5pbnNlcnQgPSAwOwogICAgICAgIGlmIChmbHVzaCA9PT0gWl9GSU5JU0gpIHsKICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgdHJ1ZSk7CiAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICByZXR1cm4gQlNfRklOSVNIX1NUQVJURUQ7CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gQlNfRklOSVNIX0RPTkU7CiAgICAgICAgfQogICAgICAgIGlmIChzLmxhc3RfbGl0KSB7CiAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIGZhbHNlKTsKICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiBCU19CTE9DS19ET05FOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIENvbmZpZyhnb29kX2xlbmd0aCwgbWF4X2xhenksIG5pY2VfbGVuZ3RoLCBtYXhfY2hhaW4sIGZ1bmMpIHsKICAgICAgICB0aGlzLmdvb2RfbGVuZ3RoID0gZ29vZF9sZW5ndGg7CiAgICAgICAgdGhpcy5tYXhfbGF6eSA9IG1heF9sYXp5OwogICAgICAgIHRoaXMubmljZV9sZW5ndGggPSBuaWNlX2xlbmd0aDsKICAgICAgICB0aGlzLm1heF9jaGFpbiA9IG1heF9jaGFpbjsKICAgICAgICB0aGlzLmZ1bmMgPSBmdW5jOwogICAgICB9CiAgICAgIHZhciBjb25maWd1cmF0aW9uX3RhYmxlOwogICAgICBjb25maWd1cmF0aW9uX3RhYmxlID0gWwogICAgICAgIG5ldyBDb25maWcoMCwgMCwgMCwgMCwgZGVmbGF0ZV9zdG9yZWQpLAogICAgICAgIG5ldyBDb25maWcoNCwgNCwgOCwgNCwgZGVmbGF0ZV9mYXN0KSwKICAgICAgICBuZXcgQ29uZmlnKDQsIDUsIDE2LCA4LCBkZWZsYXRlX2Zhc3QpLAogICAgICAgIG5ldyBDb25maWcoNCwgNiwgMzIsIDMyLCBkZWZsYXRlX2Zhc3QpLAogICAgICAgIG5ldyBDb25maWcoN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sKICAgICAgICBzLmluc19oID0gMDsKICAgICAgfQogICAgICBmdW5jdGlvbiBEZWZsYXRlU3RhdGUoKSB7CiAgICAgICAgdGhpcy5zdHJtID0gbnVsbDsKICAgICAgICB0aGlzLnN0YXR1cyA9IDA7CiAgICAgICAgdGhpcy5wZW5kaW5nX2J1ZiA9IG51bGw7CiAgICAgICAgdGhpcy5wZW5kaW5nX2J1Zl9zaXplID0gMDsKICAgICAgICB0aGlzLnBlbmRpbmdfb3V0ID0gMDsKICAgICAgICB0aGlzLnBlbmRpbmcgPSAwOwogICAgICAgIHRoaXMud3JhcCA9IDA7CiAgICAgICAgdGhpcy5nemhlYWQgPSBudWxsOwogICAgICAgIHRoaXMuZ3ppbmRleCA9IDA7CiAgICAgICAgdGhpcy5tZXRob2QgPSBaX0RFRkxBVEVEOwogICAgICAgIHRoaXMubGFzdF9mbHVzaCA9IC0xOwogICAgICAgIHRoaXMud19zaXplID0gMDsKICAgICAgICB0aGlzLndfYml0cyA9IDA7CiAgICAgICAgdGhpcy53X21hc2sgPSAwOwogICAgICAgIHRoaXMud2luZG93ID0gbnVsbDsKICAgICAgICB0aGlzLndpbmRvd19zaXplID0gMDsKICAgICAgICB0aGlzLnByZXYgPSBudWxsOwogICAgICAgIHRoaXMuaGVhZCA9IG51bGw7CiAgICAgICAgdGhpcy5pbnNfaCA9IDA7CiAgICAgICAgdGhpcy5oYXNoX3NpemUgPSAwOwogICAgICAgIHRoaXMuaGFzaF9iaXRzID0gMDsKICAgICAgICB0aGlzLmhhc2hfbWFzayA9IDA7CiAgICAgICAgdGhpcy5oYXNoX3NoaWZ0ID0gMDsKICAgICAgICB0aGlzLmJsb2NrX3N0YXJ0ID0gMDsKICAgICAgICB0aGlzLm1hdGNoX2xlbmd0aCA9IDA7CiAgICAgICAgdGhpcy5wcmV2X21hdGNoID0gMDsKICAgICAgICB0aGlzLm1hdGNoX2F2YWlsYWJsZSA9IDA7CiAgICAgICAgdGhpcy5zdHJzdGFydCA9IDA7CiAgICAgICAgdGhpcy5tYXRjaF9zdGFydCA9IDA7CiAgICAgICAgdGhpcy5sb29rYWhlYWQgPSAwOwogICAgICAgIHRoaXMucHJldl9sZW5ndGggPSAwOwogICAgICAgIHRoaXMubWF4X2NoYWluX2xlbmd0aCA9IDA7CiAgICAgICAgdGhpcy5tYXhfbGF6eV9tYXRjaCA9IDA7CiAgICAgICAgdGhpcy5sZXZlbCA9IDA7CiAgICAgICAgdGhpcy5zdHJhdGVneSA9IDA7CiAgICAgICAgdGhpcy5nb29kX21hdGNoID0gMDsKICAgICAgICB0aGlzLm5pY2VfbWF0Y2ggPSAwOwogICAgICAgIHRoaXMuZHluX2x0cmVlID0gbmV3IHV0aWxzLkJ1ZjE2KEhFQVBfU0laRSAqIDIpOwogICAgICAgIHRoaXMuZHluX2R0cmVlID0gbmV3IHV0aWxzLkJ1ZjE2KCgyICogRF9DT0RFUyArIDEpICogMik7CiAgICAgICAgdGhpcy5ibF90cmVlID0gbmV3IHV0aWxzLkJ1ZjE2KCgyICogQkxfQ09ERVMgKyAxKSAqIDIpOwogICAgICAgIHplcm8odGhpcy5keW5fbHRyZWUpOwogICAgICAgIHplcm8odGhpcy5keW5fZHRyZWUpOwogICAgICAgIHplcm8odGhpcy5ibF90cmVlKTsKICAgICAgICB0aGlzLmxfZGVzYyA9IG51bGw7CiAgICAgICAgdGhpcy5kX2Rlc2MgPSBudWxsOwogICAgICAgIHRoaXMuYmxfZGVzYyA9IG51bGw7CiAgICAgICAgdGhpcy5ibF9jb3VudCA9IG5ldyB1dGlscy5CdWYxNihNQVhfQklUUyArIDEpOwogICAgICAgIHRoaXMuaGVhcCA9IG5ldyB1dGlscy5CdWYxNigyICogTF9DT0RFUyArIDEpOwogICAgICAgIHplcm8odGhpcy5oZWFwKTsKICAgICAgICB0aGlzLmhlYXBfbGVuID0gMDsKICAgICAgICB0aGlzLmhlYXBfbWF4ID0gMDsKICAgICAgICB0aGlzLmRlcHRoID0gbmV3IHV0aWxzLkJ1ZjE2KDIgKiBMX0NPREVTICsgMSk7CiAgICAgICAgemVybyh0aGlzLmRlcHRoKTsKICAgICAgICB0aGlzLmxfYnVmID0gMDsKICAgICAgICB0aGlzLmxpdF9idWZzaXplID0gMDsKICAgICAgICB0aGlzLmxhc3RfbGl0ID0gMDsKICAgICAgICB0aGlzLmRfYnVmID0gMDsKICAgICAgICB0aGlzLm9wdF9sZW4gPSAwOwogICAgICAgIHRoaXMuc3RhdGljX2xlbiA9IDA7CiAgICAgICAgdGhpcy5tYXRjaGVzID0gMDsKICAgICAgICB0aGlzLmluc2VydCA9IDA7CiAgICAgICAgdGhpcy5iaV9idWYgPSAwOwogICAgICAgIHRoaXMuYmlfdmFsaWQgPSAwOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGRlZmxhdGVSZXNldEtlZXAoc3RybSkgewogICAgICAgIHZhciBzOwogICAgICAgIGlmICghc3RybSB8fCAhc3RybS5zdGF0ZSkgewogICAgICAgICAgcmV0dXJuIGVycihzdHJtLCBaX1NUUkVBTV9FUlJPUik7CiAgICAgICAgfQogICAgICAgIHN0cm0udG90YWxfaW4gPSBzdHJtLnRvdGFsX291dCA9IDA7CiAgICAgICAgc3RybS5kYXRhX3R5cGUgPSBaX1VOS05PV047CiAgICAgICAgcyA9IHN0cm0uc3RhdGU7CiAgICAgICAgcy5wZW5kaW5nID0gMDsKICAgICAgICBzLnBlbmRpbmdfb3V0ID0gMDsKICAgICAgICBpZiAocy53cmFwIDwgMCkgewogICAgICAgICAgcy53cmFwID0gLXMud3JhcDsKICAgICAgICB9CiAgICAgICAgcy5zdGF0dXMgPSBzLndyYXAgPyBJTklUX1NUQVRFIDogQlVTWV9TVEFURTsKICAgICAgICBzdHJtLmFkbGVyID0gcy53cmFwID09PSAyID8gMCA6IDE7CiAgICAgICAgcy5sYXN0X2ZsdXNoID0gWl9OT19GTFVTSDsKICAgICAgICB0cmVlcy5fdHJfaW5pdChzKTsKICAgICAgICByZXR1cm4gWl9PSzsKICAgICAgfQogICAgICBmdW5jdGlvbiBkZWZsYXRlUmVzZXQoc3RybSkgewogICAgICAgIHZhciByZXQgPSBkZWZsYXRlUmVzZXRLZWVwKHN0cm0pOwogICAgICAgIGlmIChyZXQgPT09IFpfT0spIHsKICAgICAgICAgIGxtX2luaXQoc3RybS5zdGF0ZSk7CiAgICAgICAgfQogICAgICAgIHJldHVybiByZXQ7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZGVmbGF0ZVNldEhlYWRlcihzdHJtLCBoZWFkKSB7CiAgICAgICAgaWYgKCFzdHJtIHx8ICFzdHJtLnN0YXRlKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIGlmIChzdHJtLnN0YXRlLndyYXAgIT09IDIpIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgc3RybS5zdGF0ZS5nemhlYWQgPSBoZWFkOwogICAgICAgIHJldHVybiBaX09LOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGRlZmxhdGVJbml0MihzdHJtLCBsZXZlbCwgbWV0aG9kLCB3aW5kb3dCaXRzLCBtZW1MZXZlbCwgc3RyYXRlZ3kpIHsKICAgICAgICBpZiAoIXN0cm0pIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgdmFyIHdyYXAgPSAxOwogICAgICAgIGlmIChsZXZlbCA9PT0gWl9ERUZBVUxUX0NPTVBSRVNTSU9OKSB7CiAgICAgICAgICBsZXZlbCA9IDY7CiAgICAgICAgfQogICAgICAgIGlmICh3aW5kb3dCaXRzIDwgMCkgewogICAgICAgICAgd3JhcCA9IDA7CiAgICAgICAgICB3aW5kb3dCaXRzID0gLXdpbmRvd0JpdHM7CiAgICAgICAgfSBlbHNlIGlmICh3aW5kb3dCaXRzID4gMTUpIHsKICAgICAgICAgIHdyYXAgPSAyOwogICAgICAgICAgd2luZG93Qml0cyAtPSAxNjsKICAgICAgICB9CiAgICAgICAgaWYgKG1lbUxldmVsIDwgMSB8fCBtZW1MZXZlbCA+IE1BWF9NRU1fTEVWRUwgfHwgbWV0aG9kICE9PSBaX0RFRkxBVEVEIHx8IHdpbmRvd0JpdHMgPCA4IHx8IHdpbmRvd0JpdHMgPiAxNSB8fCBsZXZlbCA8IDAgfHwgbGV2ZWwgPiA5IHx8IHN0cmF0ZWd5IDwgMCB8fCBzdHJhdGVneSA+IFpfRklYRUQpIHsKICAgICAgICAgIHJldHVybiBlcnIoc3RybSwgWl9TVFJFQU1fRVJST1IpOwogICAgICAgIH0KICAgICAgICBpZiAod2luZG93Qml0cyA9PT0gOCkgewogICAgICAgICAgd2luZG93Qml0cyA9IDk7CiAgICAgICAgfQogICAgICAgIHZhciBzID0gbmV3IERlZmxhdGVTdGF0ZSgpOwogICAgICAgIHN0cm0uc3RhdGUgPSBzOwogICAgICAgIHMuc3RybSA9IHN0cm07CiAgICAgICAgcy53cmFwID0gd3JhcDsKICAgICAgICBzLmd6aGVhZCA9IG51bGw7CiAgICAgICAgcy53X2JpdHMgPSB3aW5kb3dCaXRzOwogICAgICAgIHMud19zaXplID0gMSA8PCBzLndfYml0czsKICAgICAgICBzLndfbWFzayA9IHMud19zaXplIC0gMTsKICAgICAgICBzLmhhc2hfYml0cyA9IG1lbUxldmVsICsgNzsKICAgICAgICBzLmhhc2hfc2l6ZSA9IDEgPDwgcy5oYXNoX2JpdHM7CiAgICAgICAgcy5oYXNoX21hc2sgPSBzLmhhc2hfc2l6ZSAtIDE7CiAgICAgICAgcy5oYXNoX3NoaWZ0ID0gfn4oKHMuaGFzaF9iaXRzICsgTUlOX01BVENIIC0gMSkgLyBNSU5fTUFUQ0gpOwogICAgICAgIHMud2luZG93ID0gbmV3IHV0aWxzLkJ1Zjgocy53X3NpemUgKiAyKTsKICAgICAgICBzLmhlYWQgPSBuZXcgdXRpbHMuQnVmMTYocy5oYXNoX3NpemUpOwogICAgICAgIHMucHJldiA9I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JiYgc3RybS5hdmFpbF9pbiAhPT0gMCB8fCBzLnN0YXR1cyA9PT0gRklOSVNIX1NUQVRFICYmIGZsdXNoICE9PSBaX0ZJTklTSCkgewogICAgICAgICAgcmV0dXJuIGVycihzdHJtLCBzdHJtLmF2YWlsX291dCA9PT0gMCA/IFpfQlVGX0VSUk9SIDogWl9TVFJFQU1fRVJST1IpOwogICAgICAgIH0KICAgICAgICBzLnN0cm0gPSBzdHJtOwogICAgICAgIG9sZF9mbHVzaCA9IHMubGFzdF9mbHVzaDsKICAgICAgICBzLmxhc3RfZmx1c2ggPSBmbHVzaDsKICAgICAgICBpZiAocy5zdGF0dXMgPT09IElOSVRfU1RBVEUpIHsKICAgICAgICAgIGlmIChzLndyYXAgPT09IDIpIHsKICAgICAgICAgICAgc3RybS5hZGxlciA9IDA7CiAgICAgICAgICAgIHB1dF9ieXRlKHMsIDMxKTsKICAgICAgICAgICAgcHV0X2J5dGUocywgMTM5KTsKICAgICAgICAgICAgcHV0X2J5dGUocywgOCk7CiAgICAgICAgICAgIGlmICghcy5nemhlYWQpIHsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCAwKTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCAwKTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCAwKTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCAwKTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCAwKTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCBzLmxldmVsID09PSA5ID8gMiA6IHMuc3RyYXRlZ3kgPj0gWl9IVUZGTUFOX09OTFkgfHwgcy5sZXZlbCA8IDIgPyA0IDogMCk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgT1NfQ09ERSk7CiAgICAgICAgICAgICAgcy5zdGF0dXMgPSBCVVNZX1NUQVRFOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHB1dF9ieXRlKHMsIChzLmd6aGVhZC50ZXh0ID8gMSA6IDApICsgKHMuZ3poZWFkLmhjcmMgPyAyIDogMCkgKyAoIXMuZ3poZWFkLmV4dHJhID8gMCA6IDQpICsgKCFzLmd6aGVhZC5uYW1lID8gMCA6IDgpICsgKCFzLmd6aGVhZC5jb21tZW50ID8gMCA6IDE2KSk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgcy5nemhlYWQudGltZSAmIDI1NSk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgcy5nemhlYWQudGltZSA+PiA4ICYgMjU1KTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCBzLmd6aGVhZC50aW1lID4+IDE2ICYgMjU1KTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCBzLmd6aGVhZC50aW1lID4+IDI0ICYgMjU1KTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCBzLmxldmVsID09PSA5ID8gMiA6IHMuc3RyYXRlZ3kgPj0gWl9IVUZGTUFOX09OTFkgfHwgcy5sZXZlbCA8IDIgPyA0IDogMCk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgcy5nemhlYWQub3MgJiAyNTUpOwogICAgICAgICAgICAgIGlmIChzLmd6aGVhZC5leHRyYSAmJiBzLmd6aGVhZC5leHRyYS5sZW5ndGgpIHsKICAgICAgICAgICAgICAgIHB1dF9ieXRlKHMsIHMuZ3poZWFkLmV4dHJhLmxlbmd0aCAmIDI1NSk7CiAgICAgICAgICAgICAgICBwdXRfYnl0ZShzLCBzLmd6aGVhZC5leHRyYS5sZW5ndGggPj4gOCAmIDI1NSk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGlmIChzLmd6aGVhZC5oY3JjKSB7CiAgICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gY3JjMzIoc3RybS5hZGxlciwgcy5wZW5kaW5nX2J1Ziwgcy5wZW5kaW5nLCAwKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgcy5nemluZGV4ID0gMDsKICAgICAgICAgICAgICBzLnN0YXR1cyA9IEVYVFJBX1NUQVRFOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICB2YXIgaGVhZGVyID0gWl9ERUZMQVRFRCArIChzLndfYml0cyAtIDggPDwgNCkgPDwgODsKICAgICAgICAgICAgdmFyIGxldmVsX2ZsYWdzID0gLTE7CiAgICAgICAgICAgIGlmIChzLnN0cmF0ZWd5ID49IFpfSFVGRk1BTl9PTkxZIHx8IHMubGV2ZWwgPCAyKSB7CiAgICAgICAgICAgICAgbGV2ZWxfZmxhZ3MgPSAwOwogICAgICAgICAgICB9IGVsc2UgaWYgKHMubGV2ZWwgPCA2KSB7CiAgICAgICAgICAgICAgbGV2ZWxfZmxhZ3MgPSAxOwogICAgICAgICAgICB9IGVsc2UgaWYgKHMubGV2ZWwgPT09IDYpIHsKICAgICAgICAgICAgICBsZXZlbF9mbGFncyA9IDI7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgbGV2ZWxfZmxhZ3MgPSAzOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGhlYWRlciB8PSBsZXZlbF9mbGFncyA8PCA2OwogICAgICAgICAgICBpZiAocy5zdHJzdGFydCAhPT0gMCkgewogICAgICAgICAgICAgIGhlYWRlciB8PSBQUkVTRVRfRElDVDsKICAgICAgICAgICAgfQogICAgICAgICAgICBoZWFkZXIgKz0gMzEgLSBoZWFkZXIgJSAzMTsKICAgICAgICAgICAgcy5zdGF0dXMgPSBCVVNZX1NUQVRFOwogICAgICAgICAgICBwdXRTaG9ydE1TQihzLCBoZWFkZXIpOwogICAgICAgICAgICBpZiAocy5zdHJzdGFydCAhPT0gMCkgewogICAgICAgICAgICAgIHB1dFNob3J0TVNCKHMsIHN0cm0uYWRsZXIgPj4+IDE2KTsKICAgICAgICAgICAgICBwdXRTaG9ydE1TQihzLCBzdHJtLmFkbGVyICYgNjU1MzUpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHN0cm0uYWRsZXIgPSAxOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAocy5zdGF0dXMgPT09IEVYVFJBX1NUQVRFKSB7CiAgICAgICAgICBpZiAocy5nemhlYWQuZXh0cmEpIHsKICAgICAgICAgICAgYmVnID0gcy5wZW5kaW5nOwogICAgICAgICAgICB3aGlsZSAocy5nemluZGV4IDwgKHMuZ3poZWFkLmV4dHJhLmxlbmd0aCAmIDY1NTM1KSkgewogICAgICAgICAgICAgIGlmIChzLnBlbmRpbmcgPT09IHMucGVuZGluZ19idWZfc2l6ZSkgewogICAgICAgICAgICAgICAgaWYgKHMuZ3poZWFkLmhjcmMgJiYgcy5wZW5kaW5nID4gYmVnKSB7CiAgICAgICAgICAgICAgICAgIHN0cm0uYWRsZXIgPSBjcmMzMihzdHJtLmFkbGVyLCBzLnBlbmRpbmdfYnVmLCBzLnBlbmRpbmcgLSBiZWcsIGJlZyk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBmbHVzaF9wZW5kaW5nKHN0cm0pOwogICAgICAgICAgICAgICAgYmVnID0gcy5wZW5kaW5nOwogICAgICAgICAgICAgICAgaWYgKHMucGVuZGluZyA9PT0gcy5wZW5kaW5nX2J1Zl9zaXplKSB7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBwdXRfYnl0ZShzLCBzLmd6aGVhZC5leHRyYVtzLmd6aW5kZXhdICYgMjU1KTsKICAgICAgICAgICAgICBzLmd6aW5kZXgrKzsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAocy5nemhlYWQuaGNyYyAmJiBzLnBlbmRpbmcgPiBiZWcpIHsKICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gY3JjMzIoc3RybS5hZGxlciwgcy5wZW5kaW5nX2J1Ziwgcy5wZW5kaW5nIC0gYmVnLCBiZWcpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzLmd6aW5kZXggPT09IHMuZ3poZWFkLmV4dHJhLmxlbmd0aCkgewogICAgICAgICAgICAgIHMuZ3ppbmRleCA9IDA7CiAgICAgICAgICAgICAgcy5zdGF0dXMgPSBOQU1FX1NUQVRFOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBzLnN0YXR1cyA9IE5BTUVfU1RBVEU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChzLnN0YXR1cyA9PT0gTkFNRV9TVEFURSkgewogICAgICAgICAgaWYgKHMuZ3poZWFkLm5hbWUpIHsKICAgICAgICAgICAgYmVnID0gcy5wZW5kaW5nOwogICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgaWYgKHMucGVuZGluZyA9PT0gcy5wZW5kaW5nX2J1Zl9zaXplKSB7CiAgICAgICAgICAgICAgICBpZiAocy5nemhlYWQuaGNyYyAmJiBzLnBlbmRpbmcgPiBiZWcpIHsKICAgICAgICAgICAgICAgICAgc3RybS5hZGxlciA9IGNyYzMyKHN0cm0uYWRsZXIsIHMucGVuZGluZ19idWYsIHMucGVuZGluZyAtIGJlZywgYmVnKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGZsdXNoX3BlbmRpbmcoc3RybSk7CiAgICAgICAgICAgICAgICBiZWcgPSBzLnBlbmRpbmc7CiAgICAgICAgICAgICAgICBpZiAocy5wZW5kaW5nID09PSBzLnBlbmRpbmdfYnVmX3NpemUpIHsKICAgICAgICAgICAgICAgICAgdmFsID0gMTsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGlmIChzLmd6aW5kZXggPCBzLmd6aGVhZC5uYW1lLmxlbmd0aCkgewogICAgICAgICAgICAgICAgdmFsID0gcy5nemhlYWQubmFtZS5jaGFyQ29kZUF0KHMuZ3ppbmRleCsrKSAmIDI1NTsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgdmFsID0gMDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgdmFsKTsKICAgICAgICAgICAgfSB3aGlsZSAodmFsICE9PSAwKTsKICAgICAgICAgICAgaWYgKHMuZ3poZWFkLmhjcmMgJiYgcy5wZW5kaW5nID4gYmVnKSB7CiAgICAgICAgICAgICAgc3RybS5hZGxlciA9IGNyYzMyKHN0cm0uYWRsZXIsIHMucGVuZGluZ19idWYsIHMucGVuZGluZyAtIGJlZywgYmVnKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAodmFsID09PSAwKSB7CiAgICAgICAgICAgICAgcy5nemluZGV4ID0gMDsKICAgICAgICAgICAgICBzLnN0YXR1cyA9IENPTU1FTlRfU1RBVEU7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHMuc3RhdHVzID0gQ09NTUVOVF9TVEFURTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKHMuc3RhdHVzID09PSBDT01NRU5UX1NUQVRFKSB7CiAgICAgICAgICBpZiAocy5nemhlYWQuY29tbWVudCkgewogICAgICAgICAgICBiZWcgPSBzLnBlbmRpbmc7CiAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICBpZiAocy5wZW5kaW5nID09PSBzLnBlbmRpbmdfYnVmX3NpemUpIHsKICAgICAgICAgICAgICAgIGlmIChzLmd6aGVhZC5oY3JjICYmIHMucGVuZGluZyA+IGJlZykgewogICAgICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gY3JjMzIoc3RybS5hZGxlciwgcy5wZW5kaW5nX2J1Ziwgcy5wZW5kaW5nIC0gYmVnLCBiZWcpOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgZmx1c2hfcGVuZGluZyhzdHJtKTsKICAgICAgICAgICAgICAgIGJlZyA9IHMucGVuZGluZzsKICAgICAgICAgICAgICAgIGlmIChzLnBlbmRpbmcgPT09IHMucGVuZGluZ19idWZfc2l6ZSkgewogICAgICAgICAgICAgICAgICB2YWwgPSAxOwogICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgaWYgKHMuZ3ppbmRleCA8IHMuZ3poZWFkLmNvbW1lbnQubGVuZ3RoKSB7CiAgICAgICAgICAgICAgICB2YWwgPSBzLmd6aGVhZC5jb21tZW50LmNoYXJDb2RlQXQocy5nemluZGV4KyspICYgMjU1OwogICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICB2YWwgPSAwOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBwdXRfYnl0ZShzLCB2YWwpOwogICAgICAgICAgICB9IHdoaWxlICh2YWwgIT09IDApOwogICAgICAgICAgICBpZiAocy5nemhlYWQuaGNyYyAmJiBzLnBlbmRpbmcgPiBiZWcpIHsKICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gY3JjMzIoc3RybS5hZGxlciwgcy5wZW5kaW5nX2J1Ziwgcy5wZW5kaW5nIC0gYmVnLCBiZWcpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmICh2YWwgPT09IDApIHsKICAgICAgICAgICAgICBzLnN0YXR1cyA9IEhDUkNfU1RBVEU7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHMuc3RhdHVzID0gSENSQ19TVEFURTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKHMuc3RhdHVzID09PSBIQ1JDX1NUQVRFKSB7CiAgICAgICAgICBpZiAocy5nemhlYWQuaGNyYykgewogICAgICAgICAgICBpZiAocy5wZW5kaW5nICsgMiA+IHMucGVuZGluZ19idWZfc2l6ZSkgewogICAgICAgICAgICAgIGZsdXNoX3BlbmRpbmcoc3RybSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHMucGVuZGluZyArIDIgPD0gcy5wZW5kaW5nX2J1Zl9zaXplKSB7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgc3RybS5hZGxlciAmIDI1NSk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgc3RybS5hZGxlciA+PiA4ICYgMjU1KTsKICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gMDsKICAgICAgICAgICAgICBzLnN0YXR1cyA9IEJVU1lfU1RBVEU7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHMuc3RhdHVzID0gQlVTWV9TVEFURTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKHMucGVuZGluZyAhPT0gMCkgewogICAgICAgICAgZmx1c2hfcGVuZGluZyhzdHJtKTsKICAgICAgICAgIGlmIChzdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICBzLmxhc3RfZmx1c2ggPSAtMTsKICAgICAgICAgICAgcmV0dXJuIFpfT0s7CiAgICAgICAgICB9CiAgICAgICAgfSBlbHNlIGlmIChzdHJtLmF2YWlsX2luID09PSAwICYmIHJhbmsoZmx1c2gpIDw9IHJhbmsob2xkX2ZsdXNoKSAmJiBmbHVzaCAhPT0gWl9GSU5JU0gpIHsKICAgICAgICAgIHJldHVybiBlcnIoc3RybSwgWl9CVUZfRVJST1IpOwogICAgICAgIH0KICAgICAgICBpZiAocy5zdGF0dXMgPT09IEZJTklTSF9TVEFURSAmJiBzdHJtLmF2YWlsX2luICE9PSAwKSB7CiAgICAgICAgICByZXR1cm4gZXJyKHN0cm0sIFpfQlVGX0VSUk9SKTsKICAgICAgICB9CiAgICAgICAgaWYgKHN0cm0uYXZhaWxfaW4gIT09IDAgfHwgcy5sb29rYWhlYWQgIT09IDAgfHwgZmx1c2ggIT09IFpfTk9fRkxVU0ggJiYgcy5zdGF0dXMgIT09IEZJTklTSF9TVEFURSkgewogICAgICAgICAgdmFyIGJzdGF0ZSA9IHMuc3RyYXRlZ3kgPT09IFpfSFVGRk1BTl9PTkxZID8gZGVmbGF0ZV9odWZmKHMsIGZsdXNoKSA6IHMuc3RyYXRlZ3kgPT09IFpfUkxFID8gZGVmbGF0ZV9ybGUocywgZmx1c2gpIDogY29uZmlndXJhdGlvbl90YWJsZVtzLmxldmVsXS5mdW5jKHMsIGZsdXNoKTsKICAgICAgICAgIGlmIChic3RhdGUgPT09IEJTX0ZJTklTSF9TVEFSVEVEIHx8IGJzdGF0ZSA9PT0gQlNfRklOSVNIX0RPTkUpIHsKICAgICAgICAgICAgcy5zdGF0dXMgPSBGSU5JU0hfU1RBVEU7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoYnN0YXRlID09PSBCU19ORUVEX01PUkUgfHwgYnN0YXRlID09PSBCU19GSU5JU0hfU1RBUlRFRCkgewogICAgICAgICAgICBpZiAoc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgICBzLmxhc3RfZmx1c2ggPSAtMTsKICAgICAgICAgICAgfQogICAgICAgICAgICByZXR1cm4gWl9PSzsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChic3RhdGUgPT09IEJTX0JMT0NLX0RPTkUpIHsKICAgICAgICAgICAgaWYgKGZsdXNoID09PSBaX1BBUlRJQUxfRkxVU0gpIHsKICAgICAgICAgICAgICB0cmVlcy5fdHJfYWxpZ24ocyk7CiAgICAgICAgICAgIH0gZWxzZSBpZiAoZmx1c2ggIT09IFpfQkxPQ0spIHsKICAgICAgICAgICAgICB0cmVlcy5fdHJfc3RvcmVkX2Jsb2NrKHMsIDAsIDAsIGZhbHNlKTsKICAgICAgICAgICAgICBpZiAoZmx1c2ggPT09IFpfRlVMTF9GTFVTSCkgewogICAgICAgICAgICAgICAgemVybyhzLmhlYWQpOwogICAgICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkID09PSAwKSB7CiAgICAgICAgICAgICAgICAgIHMuc3Ryc3RhcnQgPSAwOwogICAgICAgICAgICAgICAgICBzLmJsb2NrX3N0YXJ0ID0gMDsKICAgICAgICAgICAgICAgICAgcy5pbnNlcnQgPSAwOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBmbHVzaF9wZW5kaW5nKHN0cm0pOwogICAgICAgICAgICBpZiAoc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgICBzLmxhc3RfZmx1c2ggPSAtMTsKICAgICAgICAgICAgICByZXR1cm4gWl9PSzsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAoZmx1c2ggIT09IFpfRklOSVNIKSB7CiAgICAgICAgICByZXR1cm4gWl9PSzsKICAgICAgICB9CiAgICAgICAgaWYgKHMud3JhcCA8PSAwKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRU5EOwogICAgICAgIH0KICAgICAgICBpZiAocy53cmFwID09PSAyKSB7CiAgICAgICAgICBwdXRfYnl0ZShzLCBzdHJtLmFkbGVyICYgMjU1KTsKICAgICAgICAgIHB1dF9ieXRlKHMsIHN0cm0uYWRsZXIgPj4gOCAmIDI1NSk7CiAgICAgICAgICBwdXRfYnl0ZShzLCBzdHJtLmFkbGVyID4+IDE2ICYgMjU1KTsKICAgICAgICAgIHB1dF9ieXRlKHMsIHN0cm0uYWRsZXIgPj4gMjQgJiAyNTUpOwogICAgICAgICAgcHV0X2J5dGUocywgc3RybS50b3RhbF9pbiAmIDI1NSk7CiAgICAgICAgICBwdXRfYnl0ZShzLCBzdHJtLnRvdGFsX2luID4+IDggJiAyNTUpOwogICAgICAgICAgcHV0X2J5dGUocywgc3RybS50b3RhbF9pbiA+PiAxNiAmIDI1NSk7CiAgICAgICAgICBwdXRfYnl0ZShzLCBzdHJtLnRvdGFsX2luID4+IDI0ICYgMjU1KTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgcHV0U2hvcnRNU0Iocywgc3RybS5hZGxlciA+Pj4gMTYpOwogICAgICAgICAgcHV0U2hvcnRNU0Iocywgc3RybS5hZGxlciAmIDY1NTM1KTsKICAgICAgICB9CiAg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haWw7CiAgICAgICAgdmFyIG5leHQ7CiAgICAgICAgdmFyIGlucHV0OwogICAgICAgIHZhciB0bXBEaWN0OwogICAgICAgIGlmICghc3RybSB8fCAhc3RybS5zdGF0ZSkgewogICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VSUk9SOwogICAgICAgIH0KICAgICAgICBzID0gc3RybS5zdGF0ZTsKICAgICAgICB3cmFwID0gcy53cmFwOwogICAgICAgIGlmICh3cmFwID09PSAyIHx8IHdyYXAgPT09IDEgJiYgcy5zdGF0dXMgIT09IElOSVRfU1RBVEUgfHwgcy5sb29rYWhlYWQpIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgaWYgKHdyYXAgPT09IDEpIHsKICAgICAgICAgIHN0cm0uYWRsZXIgPSBhZGxlcjMyKHN0cm0uYWRsZXIsIGRpY3Rpb25hcnksIGRpY3RMZW5ndGgsIDApOwogICAgICAgIH0KICAgICAgICBzLndyYXAgPSAwOwogICAgICAgIGlmIChkaWN0TGVuZ3RoID49IHMud19zaXplKSB7CiAgICAgICAgICBpZiAod3JhcCA9PT0gMCkgewogICAgICAgICAgICB6ZXJvKHMuaGVhZCk7CiAgICAgICAgICAgIHMuc3Ryc3RhcnQgPSAwOwogICAgICAgICAgICBzLmJsb2NrX3N0YXJ0ID0gMDsKICAgICAgICAgICAgcy5pbnNlcnQgPSAwOwogICAgICAgICAgfQogICAgICAgICAgdG1wRGljdCA9IG5ldyB1dGlscy5CdWY4KHMud19zaXplKTsKICAgICAgICAgIHV0aWxzLmFycmF5U2V0KHRtcERpY3QsIGRpY3Rpb25hcnksIGRpY3RMZW5ndGggLSBzLndfc2l6ZSwgcy53X3NpemUsIDApOwogICAgICAgICAgZGljdGlvbmFyeSA9IHRtcERpY3Q7CiAgICAgICAgICBkaWN0TGVuZ3RoID0gcy53X3NpemU7CiAgICAgICAgfQogICAgICAgIGF2YWlsID0gc3RybS5hdmFpbF9pbjsKICAgICAgICBuZXh0ID0gc3RybS5uZXh0X2luOwogICAgICAgIGlucHV0ID0gc3RybS5pbnB1dDsKICAgICAgICBzdHJtLmF2YWlsX2luID0gZGljdExlbmd0aDsKICAgICAgICBzdHJtLm5leHRfaW4gPSAwOwogICAgICAgIHN0cm0uaW5wdXQgPSBkaWN0aW9uYXJ5OwogICAgICAgIGZpbGxfd2luZG93KHMpOwogICAgICAgIHdoaWxlIChzLmxvb2thaGVhZCA+PSBNSU5fTUFUQ0gpIHsKICAgICAgICAgIHN0ciA9IHMuc3Ryc3RhcnQ7CiAgICAgICAgICBuID0gcy5sb29rYWhlYWQgLSAoTUlOX01BVENIIC0gMSk7CiAgICAgICAgICBkbyB7CiAgICAgICAgICAgIHMuaW5zX2ggPSAocy5pbnNfaCA8PCBzLmhhc2hfc2hpZnQgXiBzLndpbmRvd1tzdHIgKyBNSU5fTUFUQ0ggLSAxXSkgJiBzLmhhc2hfbWFzazsKICAgICAgICAgICAgcy5wcmV2W3N0ciAmIHMud19tYXNrXSA9IHMuaGVhZFtzLmluc19oXTsKICAgICAgICAgICAgcy5oZWFkW3MuaW5zX2hdID0gc3RyOwogICAgICAgICAgICBzdHIrKzsKICAgICAgICAgIH0gd2hpbGUgKC0tbik7CiAgICAgICAgICBzLnN0cnN0YXJ0ID0gc3RyOwogICAgICAgICAgcy5sb29rYWhlYWQgPSBNSU5fTUFUQ0ggLSAxOwogICAgICAgICAgZmlsbF93aW5kb3cocyk7CiAgICAgICAgfQogICAgICAgIHMuc3Ryc3RhcnQgKz0gcy5sb29rYWhlYWQ7CiAgICAgICAgcy5ibG9ja19zdGFydCA9IHMuc3Ryc3RhcnQ7CiAgICAgICAgcy5pbnNlcnQgPSBzLmxvb2thaGVhZDsKICAgICAgICBzLmxvb2thaGVhZCA9IDA7CiAgICAgICAgcy5tYXRjaF9sZW5ndGggPSBzLnByZXZfbGVuZ3RoID0gTUlOX01BVENIIC0gMTsKICAgICAgICBzLm1hdGNoX2F2YWlsYWJsZSA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T0gNTUyOTYgJiYgbV9wb3MgKyAxIDwgc3RyX2xlbikgewogICAgICAgICAgICBjMiA9IHN0ci5jaGFyQ29kZUF0KG1fcG9zICsgMSk7CiAgICAgICAgICAgIGlmICgoYzIgJiA2NDUxMikgPT09IDU2MzIwKSB7CiAgICAgICAgICAgICAgYyA9IDY1NTM2ICsgKGMgLSA1NTI5NiA8PCAxMCkgKyAoYzIgLSA1NjMyMCk7CiAgICAgICAgICAgICAgbV9wb3MrKzsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgYnVmX2xlbiArPSBjIDwgMTI4ID8gMSA6IGMgPCAyMDQ4ID8gMiA6IGMgPCA2NTUzNiA/IDMgOiA0OwogICAgICAgIH0KICAgICAgICBidWYgPSBuZXcgdXRpbHMuQnVmOChidWZfbGVuKTsKICAgICAgICBmb3IgKGkgPSAwLCBtX3BvcyA9IDA7IGkgPCBidWZfbGVuOyBtX3BvcysrKSB7CiAgICAgICAgICBjID0gc3RyLmNoYXJDb2RlQXQobV9wb3MpOwogICAgICAgICAgaWYgKChjICYgNjQ1MTIpID09PSA1NTI5NiAmJiBtX3BvcyArIDEgPCBzdHJfbGVuKSB7CiAgICAgICAgICAgIGMyID0gc3RyLmNoYXJDb2RlQXQobV9wb3MgKyAxKTsKICAgICAgICAgICAgaWYgKChjMiAmIDY0NTEyKSA9PT0gNTYzMjApIHsKICAgICAgICAgICAgICBjID0gNjU1MzYgKyAoYyAtIDU1Mjk2IDw8IDEwKSArIChjMiAtIDU2MzIwKTsKICAgICAgICAgICAgICBtX3BvcysrOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoYyA8IDEyOCkgewogICAgICAgICAgICBidWZbaSsrXSA9IGM7CiAgICAgICAgICB9IGVsc2UgaWYgKGMgPCAyMDQ4KSB7CiAgICAgICAgICAgIGJ1ZltpKytdID0gMTkyIHwgYyA+Pj4gNjsKICAgICAgICAgICAgYnVmW2krK10gPSAxMjggfCBjICYgNjM7CiAgICAgICAgICB9IGVsc2UgaWYgKGMgPCA2NTUzNikgewogICAgICAgICAgICBidWZbaSsrXSA9IDIyNCB8IGMgPj4+IDEyOwogICAgICAgICAgICBidWZbaSsrXSA9IDEyOCB8IGMgPj4+IDYgJiA2MzsKICAgICAgICAgICAgYnVmW2krK10gPSAxMjggfCBjICYgNjM7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBidWZbaSsrXSA9IDI0MCB8IGMgPj4+IDE4OwogICAgICAgICAgICBidWZbaSsrXSA9IDEyOCB8IGMgPj4+IDEyICYgNjM7CiAgICAgICAgICAgIGJ1ZltpKytdID0gMTI4IHwgYyA+Pj4gNiAmIDYzOwogICAgICAgICAgICBidWZbaSsrXSA9IDEyOCB8IGMgJiA2MzsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIGJ1ZjsKICAgICAgfTsKICAgICAgZnVuY3Rpb24gYnVmMmJpbnN0cmluZyhidWYsIGxlbikgewogICAgICAgIGlmIChsZW4gPCA2NTUzNCkgewogICAgICAgICAgaWYgKGJ1Zi5zdWJhcnJheSAmJiBTVFJfQVBQTFlfVUlBX09LIHx8ICFidWYuc3ViYXJyYXkgJiYgU1RSX0FQUExZX09LKSB7CiAgICAgICAgICAgIHJldHVybiBTdHJpbmcuZnJvbUNoYXJDb2RlLmFwcGx5KG51bGwsIHV0aWxzLnNocmlua0J1ZihidWYsIGxlbikpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICB2YXIgcmVzdWx0ID0gIiI7CiAgICAgICAgZm9yICh2YXIgaSA9IDA7IGkgPCBsZW47IGkrKykgewogICAgICAgICAgcmVzdWx0ICs9IFN0cmluZy5mcm9tQ2hhckNvZGUoYnVmW2ldKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHJlc3VsdDsKICAgICAgfQogICAgICBleHBvcnRzMi5idWYyYmluc3RyaW5nID0gZnVuY3Rpb24oYnVmKSB7CiAgICAgICAgcmV0dXJuIGJ1ZjJiaW5zdHJpbmcoYnVmLCBidWYubGVuZ3RoKTsKICAgICAgfTsKICAgICAgZXhwb3J0czIuYmluc3RyaW5nMmJ1ZiA9IGZ1bmN0aW9uKHN0cikgewogICAgICAgIHZhciBidWYgPSBuZXcgdXRpbHMuQnVmOChzdHIubGVuZ3RoKTsKICAgICAgICBmb3IgKHZhciBpID0gMCwgbGVuID0gYnVmLmxlbmd0aDsgaSA8IGxlbjsgaSsrKSB7CiAgICAgICAgICBidWZbaV0gPSBzdHIuY2hhckNvZGVBdChpKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIGJ1ZjsKICAgICAgfTsKICAgICAgZXhwb3J0czIuYnVmMnN0cmluZyA9IGZ1bmN0aW9uKGJ1ZiwgbWF4KSB7CiAgICAgICAgdmFyIGksIG91dCwgYywgY19sZW47CiAgICAgICAgdmFyIGxlbiA9IG1heCB8fCBidWYubGVuZ3RoOwogICAgICAgIHZhciB1dGYxNmJ1ZiA9IG5ldyBBcnJheShsZW4gKiAyKTsKICAgICAgICBmb3IgKG91dCA9IDAsIGkgPSAwOyBpIDwgbGVuOyApIHsKICAgICAgICAgIGMgPSBidWZbaSsrXTsKICAgICAgICAgIGlmIChjIDwgMTI4KSB7CiAgICAgICAgICAgIHV0ZjE2YnVmW291dCsrXSA9IGM7CiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgfQogICAgICAgICAgY19sZW4gPSBfdXRmOGxlbltjXTsKICAgICAgICAgIGlmIChjX2xlbiA+IDQpIHsKICAgICAgICAgICAgdXRmMTZidWZbb3V0KytdID0gNjU1MzM7CiAgICAgICAgICAgIGkgKz0gY19sZW4gLSAxOwogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgIH0KICAgICAgICAgIGMgJj0gY19sZW4gPT09IDIgPyAzMSA6IGNfbGVuID09PSAzID8gMTUgOiA3OwogICAgICAgICAgd2hpbGUgKGNfbGVuID4gMSAmJiBpIDwgbGVuKSB7CiAgICAgICAgICAgIGMgPSBjIDw8IDYgfCBidWZbaSsrXSAmIDYzOwogICAgICAgICAgICBjX2xlbi0tOwogICAgICAgICAgfQogICAgICAgICAgaWYgKGNfbGVuID4gMSkgewogICAgICAgICAgICB1dGYxNmJ1ZltvdXQrK10gPSA2NTUzMzsKICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoYyA8IDY1NTM2KSB7CiAgICAgICAgICAgIHV0ZjE2YnVmW291dCsrXSA9IGM7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBjIC09IDY1NTM2OwogICAgICAgICAgICB1dGYxNmJ1ZltvdXQrK10gPSA1NTI5NiB8IGMgPj4gMTAgJiAxMDIzOwogICAgICAgICAgICB1dGYxNmJ1ZltvdXQrK10gPSA1NjMyMCB8IGMgJiAxMDIzOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gYnVmMmJpbnN0cmluZyh1dGYxNmJ1Ziwgb3V0KTsKICAgICAgfTsKICAgICAgZXhwb3J0czIudXRmOGJvcmRlciA9IGZ1bmN0aW9uKGJ1ZiwgbWF4KSB7CiAgICAgICAgdmFyIHBvczsKICAgICAgICBtYXggPSBtYXggfHwgYnVmLmxlbmd0aDsKICAgICAgICBpZiAobWF4ID4gYnVmLmxlbmd0aCkgewogICAgICAgICAgbWF4ID0gYnVmLmxlbmd0aDsKICAgICAgICB9CiAgICAgICAgcG9zID0gbWF4IC0gMTsKICAgICAgICB3aGlsZSAocG9zID49IDAgJiYgKGJ1Zltwb3NdICYgMTkyKSA9PT0gMTI4KSB7CiAgICAgICAgICBwb3MtLTsKICAgICAgICB9CiAgICAgICAgaWYgKHBvcyA8IDApIHsKICAgICAgICAgIHJldHVybiBtYXg7CiAgICAgICAgfQogICAgICAgIGlmIChwb3MgPT09IDApIHsKICAgICAgICAgIHJldHVybiBtYXg7CiAgICAgICAgfQogICAgICAgIHJldHVybiBwb3MgKyBfdXRmOGxlbltidWZbcG9zXV0gPiBtYXggPyBwb3MgOi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YWtvL2xpYi9kZWZsYXRlLmpzIihleHBvcnRzMikgewogICAgICBpbml0X2J1ZmZlcl9zaGltKCk7CiAgICAgICJ1c2Ugc3RyaWN0IjsKICAgICAgdmFyIHpsaWJfZGVmbGF0ZSA9IHJlcXVpcmVfZGVmbGF0ZSgpOwogICAgICB2YXIgdXRpbHMgPSByZXF1aXJlX2NvbW1vbigpOwogICAgICB2YXIgc3RyaW5ncyA9IHJlcXVpcmVfc3RyaW5ncygpOwogICAgICB2YXIgbXNnID0gcmVxdWlyZV9tZXNzYWdlcygpOwogICAgICB2YXIgWlN0cmVhbSA9IHJlcXVpcmVfenN0cmVhbSgpOwogICAgICB2YXIgdG9TdHJpbmcgPSBPYmplY3QucHJvdG90eXBlLnRvU3RyaW5nOwogICAgICB2YXIgWl9OT19GTFVTSCA9IDA7CiAgICAgIHZhciBaX0ZJTklTSCA9IDQ7CiAgICAgIHZhciBaX09LID0gMDsKICAgICAgdmFyIFpfU1RSRUFNX0VORCA9IDE7CiAgICAgIHZhciBaX1NZTkNfRkxVU0gyID0gMjsKICAgICAgdmFyIFpfREVGQVVMVF9DT01QUkVTU0lPTiA9IC0xOwogICAgICB2YXIgWl9ERUZBVUxUX1NUUkFURUdZID0gMDsKICAgICAgdmFyIFpfREVGTEFURUQgPSA4OwogICAgICBmdW5jdGlvbiBEZWZsYXRlKG9wdGlvbnMpIHsKICAgICAgICBpZiAoISh0aGlzIGluc3RhbmNlb2YgRGVmbGF0ZSkpCiAgICAgICAgICByZXR1cm4gbmV3IERlZmxhdGUob3B0aW9ucyk7CiAgICAgICAgdGhpcy5vcHRpb25zID0gdXRpbHMuYXNzaWduKHsKICAgICAgICAgIGxldmVsOiBaX0RFRkFVTFRfQ09NUFJFU1NJT04sCiAgICAgICAgICBtZXRob2Q6IFpfREVGTEFURUQsCiAgICAgICAgICBjaHVua1NpemU6IDE2Mzg0LAogICAgICAgICAgd2luZG93Qml0czogMTUsCiAgICAgICAgICBtZW1MZXZlbDogOCwKICAgIC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q7CiAgICAgICAgICBpZiAodHlwZW9mIG9wdC5kaWN0aW9uYXJ5ID09PSAic3RyaW5nIikgewogICAgICAgICAgICBkaWN0ID0gc3RyaW5ncy5zdHJpbmcyYnVmKG9wdC5kaWN0aW9uYXJ5KTsKICAgICAgICAgIH0gZWxzZSBpZiAodG9TdHJpbmcuY2FsbChvcHQuZGljdGlvbmFyeSkgPT09ICJbb2JqZWN0IEFycmF5QnVmZmVyXSIpIHsKICAgICAgICAgICAgZGljdCA9IG5ldyBVaW50OEFycmF5KG9wdC5kaWN0aW9uYXJ5KTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGRpY3QgPSBvcHQuZGljdGlvbmFyeTsKICAgICAgICAgIH0KICAgICAgICAgIHN0YXR1cyA9IHpsaWJfZGVmbGF0ZS5kZWZsYXRlU2V0RGljdGlvbmFyeSh0aGlzLnN0cm0sIGRpY3QpOwogICAgICAgICAgaWYgKHN0YXR1cyAhPT0gWl9PSykgewogICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IobXNnW3N0YXR1c10pOwogICAgICAgICAgfQogICAgICAgICAgdGhpcy5fZGljdF9zZXQgPSB0cnVlOwogICAgICAgIH0KICAgICAgfQogICAgICBEZWZsYXRlLnByb3RvdHlwZS5wdXNoID0gZnVuY3Rpb24oZGF0YSwgbW9kZSkgewogICAgICAgIHZhciBzdHJtID0gdGhpcy5zdHJtOwogICAgICAgIHZhciBjaHVua1NpemUgPSB0aGlzLm9wdGlvbnMuY2h1bmtTaXplOwogICAgICAgIHZhciBzdGF0dXMsIF9tb2RlOwogICAgICAgIGlmICh0aGlzLmVuZGVkKSB7CiAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgfQogICAgICAgIF9tb2RlID0gbW9kZSA9PT0gfn5tb2RlID8gbW9kZSA6IG1vZGUgPT09IHRydWUgPyBaX0ZJTklTSCA6IFpfTk9fRkxVU0g7CiAgICAgICAgaWYgKHR5cGVvZiBkYXRhID09PSAic3RyaW5nIikgewogICAgICAgICAgc3RybS5pbnB1dCA9IHN0cmluZ3Muc3RyaW5nMmJ1ZihkYXRhKTsKICAgICAgICB9IGVsc2UgaWYgKHRvU3RyaW5nLmNhbGwoZGF0YSkgPT09ICJbb2JqZWN0IEFycmF5QnVmZmVyXSIpIHsKICAgICAgICAgIHN0cm0uaW5wdXQgPSBuZXcgVWludDhBcnJheShkYXRhKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgc3RybS5pbnB1dCA9IGRhdGE7CiAgICAgICAgfQogICAgICAgIHN0cm0ubmV4dF9pbiA9IDA7CiAgICAgICAgc3RybS5hdmFpbF9pbiA9IHN0cm0uaW5wdXQubGVuZ3RoOwogICAgICAgIGRvIHsKICAgICAgICAgIGlmIChzdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICBzdHJtLm91dHB1dCA9IG5ldyB1dGlscy5CdWY4KGNodW5rU2l6ZSk7CiAgICAgICAgICAgIHN0cm0ubmV4dF9vdXQgPSAwOwogICAgICAgICAgICBzdHJtLmF2YWlsX291dCA9IGNodW5rU2l6ZTsKICAgICAgICAgIH0KICAgICAgICAgIHN0YXR1cyA9IHpsaWJfZGVmbGF0ZS5kZWZsYXRlKHN0cm0sIF9tb2RlKTsKICAgICAgICAgIGlmIChzdGF0dXMgIT09IFpfU1RSRUFNX0VORCAmJiBzdGF0dXMgIT09IFpfT0spIHsKICAgICAgICAgICAgdGhpcy5vbkVuZChzdGF0dXMpOwogICAgICAgICAgICB0aGlzLmVuZGVkID0gdHJ1ZTsKICAgICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICAgICAgfQogICAgICAgICAgaWYgKHN0cm0uYXZhaWxfb3V0ID09PSAwIHx8IHN0cm0uYXZhaWxfaW4gPT09IDAgJiYgKF9tb2RlID09PSBaX0ZJTklTSCB8fCBfbW9kZSA9PT0gWl9TWU5DX0ZMVVNIMikpIHsKICAgICAgICAgICAgaWYgKHRoaXMub3B0aW9ucy50byA9PT0gInN0cmluZyIpIHsKICAgICAgICAgICAgICB0aGlzLm9uRGF0YShzdHJpbmdzLmJ1ZjJiaW5zdHJpbmcodXRpbHMuc2hyaW5rQnVmKHN0cm0ub3V0cHV0LCBzdHJtLm5leHRfb3V0KSkpOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHRoaXMub25EYXRhKHV0aWxzLnNocmlua0J1ZihzdHJtLm91dHB1dCwgc3RybS5uZXh0X291dCkpOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfSB3aGlsZSAoKHN0cm0uYXZhaWxfaW4gPiAwIHx8IHN0cm0uYXZhaWxfb3V0ID09PSAwKSAmJiBzdGF0dXMgIT09IFpfU1RSRUFNX0VORCk7CiAgICAgICAgaWYgKF9tb2RlID09PSBaX0ZJTklTSCkgewogICAgICAgICAgc3RhdHVzID0gemxpYl9kZWZsYXRlLmRlZmxhdGVFbmQodGhpcy5zdHJtKTsKICAgICAgICAgIHRoaXMub25FbmQoc3RhdHVzKTsKICAgICAgICAgIHRoaXMuZW5kZWQgPSB0cnVlOwogICAgICAgICAgcmV0dXJuIHN0YXR1cyA9PT0gWl9PSzsKICAgICAgICB9CiAgICAgICAgaWYgKF9tb2RlID09PSBaX1NZTkNfRkxVU0gyKSB7CiAgICAgICAgICB0aGlzLm9uRW5kKFpfT0spOwogICAgICAgICAgc3RybS5hdmFpbF9vdXQgPSAwOwogICAgICAgICAgcmV0dXJuIHRydWU7CiAgICAgICAgfQogICAgICAgIHJldHVybiB0cnVlOwogICAgICB9OwogICAgICBEZWZsYXRlLnByb3RvdHlwZS5vbkRhdGEgPSBmdW5jdGlvbihjaHVuaykgewogICAgICAgIHRoaXMuY2h1bmtzLnB1c2goY2h1bmspOwogICAgICB9OwogICAgICBEZWZsYXRlLnByb3RvdHlwZS5vbkVuZCA9IGZ1bmN0aW9uKHN0YXR1cykgewogICAgICAgIGlmIChzdGF0dXMgPT09IFpfT0spIHsKICAgICAgICAgIGlmICh0aGlzLm9wdGlvbnMudG8gPT09ICJzdHJpbmciKSB7CiAgICAgICAgICAgIHRoaXMucmVzdWx0ID0gdGhpcy5jaHVua3Muam9pbigiIik7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICB0aGlzLnJlc3VsdCA9IHV0aWxzLmZsYXR0ZW5DaHVua3ModGhpcy5jaHVua3MpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICB0aGlzLmNodW5rcyA9IFtdOwogICAgICAgIHRoaXMuZXJyID0gc3RhdHVzOwogICAgICAgIHRoaXMubXNnID0gdGhpcy5zdHJtLm1zZzsKICAgICAgfTsKICAgICAgZnVuY3Rpb24gZGVmbGF0ZShpbnB1dCwgb3B0aW9ucykgewogICAgICAgIHZhciBkZWZsYXRvciA9IG5ldyBEZWZsYXRlKG9wdGlvbnMpOwogICAgICAgIGRlZmxhdG9yLnB1c2goaW5wdXQsIHRydWUpOwogICAgICAgIGlmIChkZWZsYXRvci5lcnIpIHsKICAgICAgICAgIHRocm93IGRlZmxhdG9yLm1zZyB8fCBtc2dbZGVmbGF0b3IuZXJyXTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIGRlZmxhdG9yLnJlc3VsdDsKICAgICAgfQogICAgICBmdW5jdGlvbiBkZWZsYXRlUmF3KGlucHV0LCBvcHRpb25zKSB7CiAgICAgICAgb3B0aW9ucyA9IG9wdGlvbnMgfHwge307CiAgICAgICAgb3B0aW9ucy5yYXcgPSB0cnVlOwogICAgICAgIHJldHVybiBkZWZsYXRlKGlucHV0LCBvcHRpb25zKTsKICAgICAgfQogICAgICBmdW5jdGlvbiBnemlwKGlucHV0LCBvcHRpb25zKSB7CiAgICAgICAgb3B0aW9ucyA9IG9wdGlvbnMgfHwge307CiAgICAgICAgb3B0aW9ucy5nemlwID0gdHJ1ZTsKICAgICAgICByZXR1cm4gZGVmbGF0ZShpbnB1dCwgb3B0aW9ucyk7CiAgICAgIH0KICAgICAgZXhwb3J0czIuRGVmbGF0ZSA9IERlZmxhdGU7CiAgICAgIGV4cG9ydHMyLmRlZmxhdGUgPSBkZWZsYXRlOwogICAgICBleHBvcnRzMi5kZWZsYXRlUmF3ID0gZGVmbGF0ZVJhdzsKICAgICAgZXhwb3J0czIuZ3ppcCA9IGd6aXA7CiAgICB9CiAgfSk7CgogIC8vIG5vZGVfbW9kdWxlcy8ucG5wbS9wYWtvQDEuMC4xMS9ub2RlX21vZHVsZXMvcGFrby9saWIvemxpYi9pbmZmYXN0LmpzCiAgdmFyIHJlcXVpcmVfaW5mZmFzdCA9IF9fY29tbW9uSlMoewogICAgIm5vZGVfbW9kdWxlcy8ucG5wbS9wYWtvQDEuMC4xMS9ub2RlX21vZHVsZXMvcGFrby9saWIvemxpYi9pbmZmYXN0LmpzIihleHBvcnRzMiwgbW9kdWxlMikgewogICAgICBpbml0X2J1ZmZlcl9zaGltKCk7CiAgICAgICJ1c2Ugc3RyaWN0IjsKICAgICAgdmFyIEJBRCA9IDMwOwogICAgICB2YXIgVFlQRSA9IDEyOwogICAgICBtb2R1bGUyLmV4cG9ydHMgPSBmdW5jdGlvbiBpbmZsYXRlX2Zhc3Qoc3RybSwgc3RhcnQpIHsKICAgICAgICB2YXIgc3RhdGU7CiAgICAgICAgdmFyIF9pbjsKICAgICAgICB2YXIgbGFzdDsKICAgICAgICB2YXIgX291dDsKICAgICAgICB2YXIgYmVnOwogICAgICAgIHZhciBlbmQ7CiAgICAgICAgdmFyIGRtYXg7CiAgICAgICAgdmFyIHdzaXplOwogICAgICAgIHZhciB3aGF2ZTsKICAgICAgICB2YXIgd25leHQ7CiAgICAgICAgdmFyIHNfd2luZG93OwogICAgICAgIHZhciBob2xkOwogICAgICAgIHZhciBiaXRzOwogICAgICAgIHZhciBsY29kZTsKICAgICAgICB2YXIgZGNvZGU7CiAgICAgICAgdmFyIGxtYXNrOwogICAgICAgIHZhciBkbWFzazsKICAgICAgICB2YXIgaGVyZTsKICAgICAgICB2YXIgb3A7CiAgICAgICAgdmFyIGxlbjsKICAgICAgICB2YXIgZGlzdDsKICAgICAgICB2YXIgZnJvbTsKICAgICAgICB2YXIgZnJvbV9zb3VyY2U7CiAgICAgICAgdmFyIGlucHV0LCBvdXRwdXQ7CiAgICAgICAgc3RhdGUgPSBzdHJtLnN0YXRlOwogICAgICAgIF9pbiA9IHN0cm0ubmV4dF9pbjsKICAgICAgICBpbnB1dCA9IHN0cm0uaW5wdXQ7CiAgICAgICAgbGFzdCA9IF9pbiArIChzdHJtLmF2YWlsX2luIC0gNSk7CiAgICAgICAgX291dCA9IHN0cm0ubmV4dF9vdXQ7CiAgICAgICAgb3V0cHV0ID0gc3RybS5vdXRwdXQ7CiAgICAgICAgYmVnID0gX291dCAtIChzdGFydCAtIHN0cm0uYXZhaWxfb3V0KTsKICAgICAgICBlbmQgPSBfb3V0ICsgKHN0cm0uYXZhaWxfb3V0IC0gMjU3KTsKICAgICAgICBkbWF4ID0gc3RhdGUuZG1heDsKICAgICAgICB3c2l6ZSA9IHN0YXRlLndzaXplOwogICAgICAgIHdoYXZlID0gc3RhdGUud2hhdmU7CiAgICAgICAgd25leHQgPSBzdGF0ZS53bmV4dDsKICAgICAgICBzX3dpbmRvdyA9IHN0YXRlLndpbmRvdzsKICAgICAgICBob2xkID0gc3RhdGUuaG9sZDsKICAgICAgICBiaXRzID0gc3RhdGUuYml0czsKICAgICAgICBsY29kZSA9IHN0YXRlLmxlbmNvZGU7CiAgICAgICAgZGNvZGUgPSBzdGF0ZS5kaXN0Y29kZTsKICAgICAgICBsbWFzayA9ICgxIDw8IHN0YXRlLmxlbmJpdHMpIC0gMTsKICAgICAgICBkbWFzayA9ICgxIDw8IHN0YXRlLmRpc3RiaXRzKSAtIDE7CiAgICAgICAgdG9wOgogICAgICAgICAgZG8gewogICAgICAgICAgICBpZiAoYml0cyA8IDE1KSB7CiAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtfaW4rK10gPDwgYml0czsKICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtfaW4rK10gPDwgYml0czsKICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaGVyZSA9IGxjb2RlW2hvbGQgJiBsbWFza107CiAgICAgICAgICAgIGRvbGVuOgogICAgICAgICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgICAgICAgb3AgPSBoZXJlID4+PiAyNDsKICAgICAgICAgICAgICAgIGhvbGQgPj4+PSBvcDsKICAgICAgICAgICAgICAgIGJpdHMgLT0gb3A7CiAgICAgICAgICAgICAgICBvcCA9IGhlcmUgPj4+IDE2ICYgMjU1OwogICAgICAgICAgICAgICAgaWYgKG9wID09PSAwKSB7CiAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gaGVyZSAmIDY1NTM1OwogICAgICAgICAgICAgICAgfSBlbHNlIGlmIChvcCAmIDE2KSB7CiAgICAgICAgICAgICAgICAgIGxlbiA9IGhlcmUgJiA2NTUzNTsKICAgICAgICAgICAgICAgICAgb3AgJj0gMTU7CiAgICAgICAgICAgICAgICAgIGlmIChvcCkgewogICAgICAgICAgICAgICAgICAgIGlmIChiaXRzIDwgb3ApIHsKICAgICAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbX2luKytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGxlbiArPSBob2xkICYgKDEgPDwgb3ApIC0gMTsKICAgICAgICAgICAgICAgICAgICBob2xkID4+Pj0gb3A7CiAgICAgICAgICAgICAgICAgICAgYml0cyAtPSBvcDsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBpZiAoYml0cyA8IDE1KSB7CiAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtfaW4rK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtfaW4rK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaGVyZSA9IGRjb2RlW2hvbGQgJiBkbWFza107CiAgICAgICAgICAgICAgICAgIGRvZGlzdDoKICAgICAgICAgICAgICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgICAgICAgICAgICAgIG9wID0gaGVyZSA+Pj4gMjQ7CiAgICAgICAgICAgICAgICAgICAgICBob2xkID4+Pj0gb3A7CiAgICAgICAgICAgICAgICAgICAgICBiaXRzIC09IG9wOwogICAgICAgICAgICAgICAgICAgICAgb3AgPSBoZXJlID4+PiAxNiAmIDI1NTsKICAgICAgICAgICAgICAgICAgICAgIGlmIChvcCAmIDE2KSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGRpc3QgPSBoZXJlICYgNjU1MzU7CiAgICAgICAgICAgICAgICAgICAgICAgIG9wICY9IDE1OwogICAgICAgICAgICAgICAgICAgICAgICBpZiAoYml0cyA8IG9wKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtfaW4rK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGJpdHMgPCBvcCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtfaW4rK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgZGlzdCArPSBob2xkICYgKDEgPDwgb3ApIC0gMTsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGRpc3QgPiBkbWF4KSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW52YWxpZCBkaXN0YW5jZSB0b28gZmFyIGJhY2siOwogICAgICAgICAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWsgdG9wOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIGhvbGQgPj4+PSBvcDsKICAgICAgICAgICAgICAgICAgICAgICAgYml0cyAtPSBvcDsKICAgICAgICAgICAgICAgICAgICAgICAgb3AgPSBfb3V0IC0gYmVnOwogICAgICAgICAgICAgICAgICAgICAgICBpZiAoZGlzdCA+IG9wKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgb3AgPSBkaXN0IC0gb3A7CiAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKG9wID4gd2hhdmUpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5zYW5lKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImludmFsaWQgZGlzdGFuY2UgdG9vIGZhciBiYWNrIjsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWsgdG9wOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tID0gMDsKICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tX3NvdXJjZSA9IHNfd2luZG93OwogICAgICAgICAgICAgICAgICAgICAgICAgIGlmICh3bmV4dCA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgZnJvbSArPSB3c2l6ZSAtIG9wOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKG9wIDwgbGVuKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxlbiAtPSBvcDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gc193aW5kb3dbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSB3aGlsZSAoLS1vcCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZyb20gPSBfb3V0IC0gZGlzdDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZnJvbV9zb3VyY2UgPSBvdXRwdXQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIGlmICh3bmV4dCA8IG9wKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tICs9IHdzaXplICsgd25leHQgLSBvcDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIG9wIC09IHduZXh0OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKG9wIDwgbGVuKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxlbiAtPSBvcDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gc193aW5kb3dbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSB3aGlsZSAoLS1vcCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZyb20gPSAwOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAod25leHQgPCBsZW4pIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBvcCA9IHduZXh0OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxlbiAtPSBvcDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IHNfd2luZG93W2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSB3aGlsZSAoLS1vcCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZnJvbSA9IF9vdXQgLSBkaXN0OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZyb21fc291cmNlID0gb3V0cHV0OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZyb20gKz0gd25leHQgLSBvcDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChvcCA8IGxlbikgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBsZW4gLT0gb3A7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IHNfd2luZG93W2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gd2hpbGUgKC0tb3ApOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tID0gX291dCAtIGRpc3Q7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZyb21fc291cmNlID0gb3V0cHV0OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICB3aGlsZSAobGVuID4gMikgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBmcm9tX3NvdXJjZVtmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBmcm9tX3NvdXJjZVtmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBmcm9tX3NvdXJjZVtmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgbGVuIC09IDM7CiAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChsZW4pIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gZnJvbV9zb3VyY2VbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChsZW4gPiAxKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gZnJvbV9zb3VyY2VbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgZnJvbSA9IF9vdXQgLSBkaXN0OwogICAgICAgICAgICAgICAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gb3V0cHV0W2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IG91dHB1dFtmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBvdXRwdXRbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxlbiAtPSAzOwogICAgICAgICAgICAgICAgICAgICAgICAgIH0gd2hpbGUgKGxlbiA+IDIpOwogICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChsZW4pIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gb3V0cHV0W2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAobGVuID4gMSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IG91dHB1dFtmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIGlmICgob3AgJiA2NCkgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgICAgaGVyZSA9IGRjb2RlWyhoZXJlICYgNjU1MzUpICsgKGhvbGQgJiAoMSA8PCBvcCkgLSAxKV07CiAgICAgICAgICAgICAgICAgICAgICAgIGNvbnRpbnVlIGRvZGlzdDsKICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImludmFsaWQgZGlzdGFuY2UgY29kZSI7CiAgICAgICAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrIHRvcDsKICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAoKG9wICYgNjQpID09PSAwKSB7CiAgICAgICAgICAgICAgICAgIGhlcmUgPSBsY29kZVsoaGVyZSAmIDY1NTM1KSArIChob2xkICYgKDEgPDwgb3ApIC0gMSldOwogICAgICAgICAgICAgICAgICBjb250aW51ZSBkb2xlbjsKICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAob3AgJiAzMikgewogICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gVFlQRTsKICAgICAgICAgICAgICAgICAgYnJlYWsgdG9wOwogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW52YWxpZCBsaXRlcmFsL2xlbmd0aCBjb2RlIjsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgYnJlYWsgdG9wOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgfQogICAgICAgICAgfSB3aGlsZSAoX2luIDwgbGFzdCAmJiBfb3V0IDwgZW5kKTsKICAgICAgICBsZW4gPSBiaXRzID4+IDM7CiAgICAgICAgX2luIC09IGxlbjsKICAgICAgICBiaXRzIC09IGxlbiA8PCAzOwogICAgICAgIGhvbGQgJj0gKDEgPDwgYml0cykgLSAxOwogICAgICAgIHN0cm0ubmV4dF9pbiA9IF9pbjsKICAgICAgICBzdHJtLm5leHRfb3V0ID0gX291dDsKICAgICAgICBzdHJtLmF2YWlsX2luID0gX2luIDwgbGFzdCA/IDUgKyAobGFzdCAtIF9pbikgOiA1IC0gKF9pbiAtIGxhc3QpOwogICAgICAgIHN0cm0uYXZhaWxfb3V0ID0gX291dCA8IGVuZCA/IDI1NyArIChlbmQgLSBfb3V0KSA6IDI1NyAtIChfb3V0IC0gZW5kKTsKICAgICAgICBzdGF0ZS5ob2xkID0gaG9sZDsKICAgICAgICBzdGF0ZS5iaXRzID0gYml0czsKICAgICAgICByZXR1cm47CiAgICAgIH07CiAgICB9CiAgfSk7CgogIC8vIG5vZGVfbW9kdWxlcy8ucG5wbS9wYWtvQDEuMC4xMS9ub2RlX21vZHVsZXMvcGFrby9saWIvemxpYi9pbmZ0cmVlcy5qcwogIHZhciByZXF1aXJlX2luZnRyZWVzID0gX19jb21tb25KUyh7CiAgICAibm9kZV9tb2R1bGVzLy5wbnBtL3Bha29AMS4wLjExL25vZGVfbW9kdWxlcy9wYWtvL2xpYi96bGliL2luZnRyZWVzLmpzIihleHBvcnRzMiwgbW9kdWxlMikgewogICAgICBpbml0X2J1ZmZlcl9zaGltKCk7CiAgICAgICJ1c2Ugc3RyaWN0IjsKICAgICAgdmFyIHV0aWxzID0gcmVxdWlyZV9jb21tb24oKTsKICAgICAgdmFyIE1BWEJJVFMgPSAxNTsKICAgICAgdmFyIEVOT1VHSF9MRU5TID0gODUyOwogICAgICB2YXIgRU5PVUdIX0RJU1RTID0gNTkyOwogICAgICB2YXIgQ09ERVMgPSAwOwogICAgICB2YXIgTEVOUyA9IDE7CiAgICAgIHZhciBESVNUUyA9IDI7CiAgICAgIHZhciBsYmFzZSA9IFsKICAgICAgICAzLAogICAgICAgIDQsCiAgICAgICAgNSwKICAgICAgICA2LAogICAgICAgIDcsCiAgICAgICAgOCwKICAgICAgICA5LAogICAgICAgIDEwLAogICAgICAgIDExLAogICAgICAgIDEzLAogICAgICAgIDE1LAogICAgICAgIDE3LAogICAgICAgIDE5LAogICAgICAgIDIzLAogICAgICAgIDI3LAogICAgICAgIDMxLAogICAgICAgIDM1LAogICAgICAgIDQzLAogICAgICAgIDUxLAogICAgICAgIDU5LAogICAgICAgIDY3LAogICAgICAgIDgzLAogICAgICAgIDk5LAogICAgICAgIDExNSwKICAgICAgICAxMzEsCiAgICAgICAgMTYzLAogICAgICAgIDE5NSwKICAgICAgICAyMjcsCiAgICAgICAgMjU4LAogICAgICAgIDAsCiAgICAgICAgMAogICAgICBdOwogICAgICB2YXIgbGV4dCA9IFsKICAgICAgICAxNiwKICAgICAgICAxNiwKICAgICAgICAxNiwKICAgICAgICAxNiwKICAgICAgICAxNiwKICAgICAgICAxNiwKICAgICAgICAxNiwKICAgICAgICAxNiwKICAgICAgICAxNywKICAgICAgICAxNywKICAgICAgICAxNywKICAgICAgICAxNywKICAgICAgICAxOCwKICAgICAgICAxOCwKICAgICAgICAxOCwKICAgICAgICAxOCwKICAgICAgICAxOSwKICAgICAgICAxOSwKICAgICAgICAxOSwKICAgICAgICAxOSwKICAgICAgICAyMCwKICAgICAgICAyMCwKICAgICAgICAyMCwKICAgICAgICAyMCwKICAgICAgICAyMSwKICAgICAgICAyMSwKICAgICAgICAyMSwKICAgICAgICAyMSwKICAgICAgICAxNiwKICAgICAgICA3MiwKICAgICAgICA3OAogICAgICBdOwogICAgICB2YXIgZGJhc2UgPSBbCiAgICAgICAgMSwKICAgICAgICAyLAogICAgICAgIDMsCiAgICAgICAgNCwKICAgICAgICA1LAogICAgICAgIDcsCiAgICAgICAgOSwKICAgICAgICAxMywKICAgICAgICAxNywKICAgICAgICAyNSwKICAgICAgICAzMywKICAgICAgICA0OSwKICAgICAgICA2NSwKICAgICAgICA5NywKICAgICAgICAxMjksCiAgICAgICAgMTkzLAogICAgICAgIDI1NywKICAgICAgICAzODUsCiAgICAgICAgNTEzLAogICAgICAgIDc2OSwKICAgICAgICAxMDI1LAogICAgICAgIDE1MzcsCiAgICAgICAgMjA0OSwKICAgICAgICAzMDczLAogICAgICAgIDQwOTcsCiAgICAgICAgNjE0NSwKICAgICAgICA4MTkzLAogICAgICAgIDEyMjg5LAogICAgICAgIDE2Mzg1LAogICAgICAgIDI0NTc3LAogICAgICAgIDAsCiAgICAgICAgMAogICAgICBdOwogICAgICB2YXIgZGV4dCA9IFsKICAgICAgICAxNiwKICAgICAgICAxNiwKICAgICAgICAxNiwKICAgICAgICAxNiwKICAgICAgICAxNywKICAgICAgICAxNywKICAgICAgICAxOCwKICAgICAgICAxOCwKICAgICAgICAxOSwKICAgICAgICAxOSwKICAgICAgICAyMCwKICAgICAgICAyMCwKICAgICAgICAyMSwKICAgICAgICAyMSwKICAgICAgICAyMiwKICAgICAgICAyMiwKICAgICAgICAyMywKICAgICAgICAyMywKICAgICAgICAyNCwKICAgICAgICAyNCwKICAgICAgICAyNSwKICAgICAgICAyNSwKICAgICAgICAyNiwKICAgICAgICAyNiwKICAgICAgICAyNywKICAgICAgICAyNywKICAgICAgICAyOCwKICAgICAgICAyOCwKICAgICAgICAyOSwKICAgICAgICAyOSwKICAgICAgICA2NCwKICAgICAgICA2NAogICAgICBdOwogICAgICBtb2R1bGUyLmV4cG9ydHMgPSBmdW5jdGlvbiBpbmZsYXRlX3RhYmxlKHR5cGUsIGxlbnMsIGxlbnNfaW5kZXgsIGNvZGVzLCB0YWJsZSwgdGFibGVfaW5kZXgsIHdvcmssIG9wdHMpIHsKICAgICAgICB2YXIgYml0cyA9IG9wdHMuYml0czsKICAgICAgICB2YXIgbGVuID0gMDsKICAgICAgICB2YXIgc3ltID0gMDsKICAgICAgICB2YXIgbWluID0gMCwgbWF4ID0gMDsKICAgICAgICB2YXIgcm9vdDIgPSAwOwogICAgICAgIHZhciBjdXJyID0gMDsKICAgICAgICB2YXIgZHJvcCA9IDA7CiAgICAgICAgdmFyIGxlZnQgPSAwOwogICAgICAgIHZhciB1c2VkID0gMDsKICAgICAgICB2YXIgaHVmZiA9IDA7CiAgICAgICAgdmFyIGluY3I7CiAgICAgICAgdmFyIGZpbGw7CiAgICAgICAgdmFyIGxvdzsKICAgICAgICB2YXIgbWFzazsKICAgICAgICB2YXIgbmV4dDsKICAgICAgICB2YXIgYmFzZSA9IG51bGw7CiAgICAgICAgdmFyIGJhc2VfaW5kZXggPSAwOwogICAgICAgIHZhciBlbmQ7CiAgICAgICAgdmFyIGNvdW50ID0gbmV3IHV0aWxzLkJ1ZjE2KE1BWEJJVFMgKyAxKTsKICAgICAgICB2YXIgb2ZmcyA9IG5ldyB1dGlscy5CdWYxNihNQVhCSVRTICsgMSk7CiAgICAgICAgdmFyIGV4dHJhID0gbnVsbDsKICAgICAgICB2YXIgZXh0cmFfaW5kZXggPSAwOwogICAgICAgIHZhciBoZXJlX2JpdHMsIGhlcmVfb3AsIGhlcmVfdmFsOwogICAgICAgIGZvciAobGVuID0gMDsgbGVuIDw9IE1BWEJJVFM7IGxlbisrKSB7CiAgICAgICAgICBjb3VudFtsZW5dID0gMDsKICAgICAgICB9CiAgICAgICAgZm9yIChzeW0gPSAwOyBzeW0gPCBjb2Rlczsgc3ltKyspIHsKICAgICAgICAgIGNvdW50W2xlbnNbbGVuc19pbmRleCArIHN5bV1dKys7CiAgICAgICAgfQogICAgICAgIHJvb3QyID0gYml0czsKICAgICAgICBmb3IgKG1heCA9IE1BWEJJVFM7IG1heCA+PSAxOyBtYXgtLSkgewogICAgICAgICAgaWYgKGNvdW50W21heF0gIT09IDApIHsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChyb290MiA+IG1heCkgewogICAgICAgICAgcm9vdDIgPSBtYXg7CiAgICAgICAgfQogICAgICAgIGlmIChtYXggPT09IDApIHsKICAgICAgICAgIHRhYmxlW3RhYmxlX2luZGV4KytdID0gMSA8PCAyNCB8IDY0IDw8IDE2IHwgMDsKICAgICAgICAgIHRhYmxlW3RhYmxlX2luZGV4KytdID0gMSA8PCAyNCB8IDY0IDw8IDE2IHwgMDsKICAgICAgICAgIG9wdHMuYml0cyA9IDE7CiAgICAgICAgICByZXR1cm4gMDsKICAgICAgICB9CiAgICAgICAgZm9yIChtaW4gPSAxOyBtaW4gPCBtYXg7IG1pbisrKSB7CiAgICAgICAgICBpZiAoY291bnRbbWluXSAhPT0gMCkgewogICAgICAgICAgICBicmVhazsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKHJvb3QyIDwgbWluKSB7CiAgICAgICAgICByb290MiA9IG1pbjsKICAgICAgICB9CiAgICAgICAgbGVmdCA9IDE7CiAgICAgICAgZm9yIChsZW4gPSAxOyBsZW4gPD0gTUFYQklUUzsgbGVuKyspIHsKICAgICAgICAgIGxlZnQgPDw9IDE7CiAgICAgICAgICBsZWZ0IC09IGNvdW50W2xlbl07CiAgICAgICAgICBpZiAobGVmdCA8IDApIHsKICAgICAgICAgICAgcmV0dXJuIC0xOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAobGVmdCA+IDAgJiYgKHR5cGUgPT09IENPREVTIHx8IG1heCAhPT0gMSkpIHsKICAgICAgICAgIHJldHVybiAtMTsKICAgICAgICB9CiAgICAgICAgb2Zmc1sxXSA9IDA7CiAgICAgICAgZm9yIChsZW4gPSAxOyBsZW4gPCBNQVhCSVRTOyBsZW4rKykgewogICAgICAgICAgb2Zmc1tsZW4gKyAxXSA9IG9mZnNbbGVuXSArIGNvdW50W2xlbl07CiAgICAgICAgfQogICAgICAgIGZvciAoc3ltID0gMDsgc3ltIDwgY29kZXM7IHN5bSsrKSB7CiAgICAgICAgICBpZiAobGVuc1tsZW5zX2luZGV4ICsgc3ltXSAhPT0gMCkgewogICAgICAgICAgICB3b3JrW29mZnNbbGVuc1tsZW5zX2luZGV4ICsgc3ltXV0rK10gPSBzeW07CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmICh0eXBlID09PSBDT0RFUykgewogICAgICAgICAgYmFzZSA9IGV4dHJhID0gd29yazsKICAgICAgICAgIGVuZCA9IDE5OwogICAgICAgIH0gZWxzZSBpZiAodHlwZSA9PT0gTEVOUykgewogICAgICAgICAgYmFzZSA9IGxiYXNlOwogICAgICAgICAgYmFzZV9pbmRleCAtPSAyNTc7CiAgICAgICAgICBleHRyYSA9IGxleHQ7CiAgICAgICAgICBleHRyYV9pbmRleCAtPSAyNTc7CiAgICAgICAgICBlbmQgPSAyNTY7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIGJhc2UgPSBkYmFzZTsKICAgICAgICAgIGV4dHJhID0gZGV4dDsKICAgICAgICAgIGVuZCA9IC0xOwogICAgICAgIH0KICAgICAgICBodWZmID0gMDsKICAgICAgICBzeW0gPSAwOwogICAgICAgIGxlbiA9IG1pbjsKICAgICAgICBuZXh0ID0gdGFibGVfaW5kZXg7CiAgICAgICAgY3VyciA9IHJvb3QyOwogICAgICAgIGRyb3AgPSAwOwogICAgICAgIGxvdyA9IC0xOwogICAgICAgIHVzZWQgPSAxIDw8IHJvb3QyOwogICAgICAgIG1hc2sgPSB1c2VkIC0gMTsKICAgICAgICBpZiAodHlwZSA9PT0gTEVOUyAmJiB1c2VkID4gRU5PVUdIX0xFTlMgfHwgdHlwZSA9PT0gRElTVFMgJiYgdXNlZCA+IEVOT1VHSF9ESVNUUykgewogICAgICAgICAgcmV0dXJuIDE7CiAgICAgICAgfQogICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgaGVyZV9iaXRzID0gbGVuIC0gZHJvcDsKICAgICAgICAgIGlmICh3b3JrW3N5bV0gPCBlbmQpIHsKICAgICAgICAgICAgaGVyZV9vcCA9IDA7CiAgICAgICAgICAgIGhlcmVfdmFsID0gd29ya1tzeW1dOwogICAgICAgICAgfSBlbHNlIGlmICh3b3JrW3N5bV0gPiBlbmQpIHsKICAgICAgICAgICAgaGVyZV9vcCA9IGV4dHJhW2V4dHJhX2luZGV4ICsgd29ya1tzeW1dXTsKICAgICAgICAgICAgaGVyZV92YWwgPSBiYXNlW2Jhc2VfaW5kZXggKyB3b3JrW3N5bV1dOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgaGVyZV9vcCA9IDMyICsgNjQ7CiAgICAgICAgICAgIGhlcmVfdmFsID0gMDsKICAgICAgICAgIH0KICAgICAgICAgIGluY3IgPSAxIDw8IGxlbiAtIGRyb3A7CiAgICAgICAgICBmaWxsID0gMSA8PCBjdXJyOwogICAgICAgICAgbWluID0gZmlsbDsKICAgICAgICAgIGRvIHsKICAgICAgICAgICAgZmlsbCAtPSBpbmNyOwogICAgICAgICAgICB0YWJsZVtuZXh0ICsgKGh1ZmYgPj4gZHJvcCkgKyBmaWxsXSA9IGhlcmVfYml0cyA8PCAyNCB8IGhlcmVfb3AgPDwgMTYgfCBoZXJlX3ZhbCB8IDA7CiAgICAgICAgICB9IHdoaWxlIChmaWxsICE9PSAwKTsKICAgICAgICAgIGluY3IgPSAxIDw8IGxlbiAtIDE7CiAgICAgICAgICB3aGlsZSAoaHVmZiAmIGluY3IpIHsKICAgICAgICAgICAgaW5jciA+Pj0gMTsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChpbmNyICE9PSAwKSB7CiAgICAgICAgICAgIGh1ZmYgJj0gaW5jciAtIDE7CiAgICAgICAgICAgIGh1ZmYgKz0gaW5jcjsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGh1ZmYgPSAwOwogICAgICAgICAgfQogICAgICAgICAgc3ltKys7CiAgICAgICAgICBpZiAoLS1jb3VudFtsZW5dID09PSAwKSB7CiAgICAgICAgICAgIGlmIChsZW4gPT09IG1heCkgewogICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGxlbiA9IGxlbnNbbGVuc19pbmRleCArIHdvcmtbc3ltXV07CiAgICAgICAgICB9CiAgICAgICAgICBpZiAobGVuID4gcm9vdDIgJiYgKGh1ZmYgJiBtYXNrKSAhPT0gbG93KSB7CiAgICAgICAgICAgIGlmIChkcm9wID09PSAwKSB7CiAgICAgICAgICAgICAgZHJvcCA9IHJvb3QyOwogICAgICAgICAgICB9CiAgICAgICAgICAgIG5leHQgKz0gbWluOwogICAgICAgICAgICBjdXJyID0gbGVuIC0gZHJvcDsKICAgICAgICAgICAgbGVmdCA9IDEgPDwgY3VycjsKICAgICAgICAgICAgd2hpbGUgKGN1cnIgKyBkcm9wIDwgbWF4KSB7CiAgICAgICAgICAgICAgbGVmdCAtPSBjb3VudFtjdXJyICsgZHJvcF07CiAgICAgICAgICAgICAgaWYgKGxlZnQgPD0gMCkgewogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGN1cnIrKzsKICAgICAgICAgICAgICBsZWZ0IDw8PSAxOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHVzZWQgKz0gMSA8PCBjdXJyOwogICAgICAgICAgICBpZiAodHlwZSA9PT0gTEVOUyAmJiB1c2VkID4gRU5PVUdIX0xFTlMgfHwgdHlwZSA9PT0gRElTVFMgJiYgdXNlZCA+IEVOT1VHSF9ESVNUUykgewogICAgICAgICAgICAgIHJldHVybiAxOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGxvdyA9IGh1ZmYgJiBtYXNrOwogICAgICAgICAgICB0YWJsZVtsb3ddID0gcm9vdDIgPDwgMjQgfCBjdXJyIDw8IDE2IHwgbmV4dCAtIHRhYmxlX2luZGV4IHwgMDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKGh1ZmYgIT09IDApIHsKICAgICAgICAgIHRhYmxlW25leHQgKyBodWZmXS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VSUk9SID0gLTQ7CiAgICAgIHZhciBaX0JVRl9FUlJPUiA9IC01OwogICAgICB2YXIgWl9ERUZMQVRFRCA9IDg7CiAgICAgIHZhciBIRUFEID0gMTsKICAgICAgdmFyIEZMQUdTID0gMjsKICAgICAgdmFyIFRJTUUgPSAzOwogICAgICB2YXIgT1MgPSA0OwogICAgICB2YXIgRVhMRU4gPSA1OwogICAgICB2YXIgRVhUUkEgPSA2OwogICAgICB2YXIgTkFNRSA9IDc7CiAgICAgIHZhciBDT01NRU5UID0gODsKICAgICAgdmFyIEhDUkMgPSA5OwogICAgICB2YXIgRElDVElEID0gMTA7CiAgICAgIHZhciBESUNUID0gMTE7CiAgICAgIHZhciBUWVBFID0gMTI7CiAgICAgIHZhciBUWVBFRE8gPSAxMzsKICAgICAgdmFyIFNUT1JFRCA9IDE0OwogICAgICB2YXIgQ09QWV8gPSAxNTsKICAgICAgdmFyIENPUFkgPSAxNjsKICAgICAgdmFyIFRBQkxFID0gMTc7CiAgICAgIHZhciBMRU5MRU5TID0gMTg7CiAgICAgIHZhciBDT0RFTEVOUyA9IDE5OwogICAgICB2YXIgTEVOXyA9IDIwOwogICAgICB2YXIgTEVOID0gMjE7CiAgICAgIHZhciBMRU5FWFQgPSAyMjsKICAgICAgdmFyIERJU1QgPSAyMzsKICAgICAgdmFyIERJU1RFWFQgPSAyNDsKICAgICAgdmFyIE1BVENIID0gMjU7CiAgICAgIHZhciBMSVQgPSAyNjsKICAgICAgdmFyIENIRUNLID0gMjc7CiAgICAgIHZhciBMRU5HVEggPSAyODsKICAgICAgdmFyIERPTkUgPSAyOTsKICAgICAgdmFyIEJBRCA9IDMwOwogICAgICB2YXIgTUVNID0gMzE7CiAgICAgIHZhciBTWU5DID0gMzI7CiAgICAgIHZhciBFTk9VR0hfTEVOUyA9IDg1MjsKICAgICAgdmFyIEVOT1VHSF9ESVNUUyA9IDU5MjsKICAgICAgdmFyIE1BWF9XQklUUyA9IDE1OwogICAgICB2YXIgREVGX1dCSVRTID0gTUFYX1dCSVRTOwogICAgICBmdW5jdGlvbiB6c3dhcDMyKHEpIHsKICAgICAgICByZXR1cm4gKHEgPj4+IDI0ICYgMjU1KSArIChxID4+PiA4ICYgNjUyODApICsgKChxICYgNjUyODApIDw8IDgpICsgKChxICYgMjU1KSA8PCAyNCk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gSW5mbGF0ZVN0YXRlKCkgewogICAgICAgIHRoaXMubW9kZSA9IDA7CiAgICAgICAgdGhpcy5sYXN0ID0gZmFsc2U7CiAgICAgICAgdGhpcy53cmFwID0gMDsKICAgICAgICB0aGlzLmhhdmVkaWN0ID0gZmFsc2U7CiAgICAgICAgdGhpcy5mbGFncyA9IDA7CiAgICAgICAgdGhpcy5kbWF4ID0gMDsKICAgICAgICB0aGlzLmNoZWNrID0gMDsKICAgICAgICB0aGlzLnRvdGFsID0gMDsKICAgICAgICB0aGlzLmhlYWQgPSBudWxsOwogICAgICAgIHRoaXMud2JpdHMgPSAwOwogICAgICAgIHRoaXMud3NpemUgPSAwOwogICAgICAgIHRoaXMud2hhdmUgPSAwOwogICAgICAgIHRoaXMud25leHQgPSAwOwogICAgICAgIHRoaXMud2luZG93ID0gbnVsbDsKICAgICAgICB0aGlzLmhvbGQgPSAwOwogICAgICAgIHRoaXMuYml0cyA9IDA7CiAgICAgICAgdGhpcy5sZW5ndGggPSAwOwogICAgICAgIHRoaXMub2Zmc2V0ID0gMDsKICAgICAgICB0aGlzLmV4dHJhID0gMDsKICAgICAgICB0aGlzLmxlbmNvZGUgPSBudWxsOwogICAgICAgIHRoaXMuZGlzdGNvZGUgPSBudWxsOwogICAgICAgIHRoaXMubGVuYml0cyA9IDA7CiAgICAgICAgdGhpcy5kaXN0Yml0cyA9IDA7CiAgICAgICAgdGhpcy5uY29kZSA9IDA7CiAgICAgICAgdGhpcy5ubGVuID0gMDsKICAgICAgICB0aGlzLm5kaXN0ID0gMDsKICAgICAgICB0aGlzLmhhdmUgPSAwOwogICAgICAgIHRo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R5biA9IG5ldyB1dGlscy5CdWYzMihFTk9VR0hfRElTVFMpOwogICAgICAgIHN0YXRlLnNhbmUgPSAxOwogICAgICAgIHN0YXRlLmJhY2sgPSAtMTsKICAgICAgICByZXR1cm4gWl9PSzsKICAgICAgfQogICAgICBmdW5jdGlvbiBpbmZsYXRlUmVzZXQoc3RybSkgewogICAgICAgIHZhciBzdGF0ZTsKICAgICAgICBpZiAoIXN0cm0gfHwgIXN0cm0uc3RhdGUpIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgc3RhdGUgPSBzdHJtLnN0YXRlOwogICAgICAgIHN0YXRlLndzaXplID0gMDsKICAgICAgICBzdGF0ZS53aGF2ZSA9IDA7CiAgICAgICAgc3RhdGUud25leHQgPSAwOwogICAgICAgIHJldHVybiBpbmZsYXRlUmVzZXRLZWVwKHN0cm0pOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGluZmxhdGVSZXNldDIoc3RybSwgd2luZG93Qml0cykgewogICAgICAgIHZhciB3cmFwOwogICAgICAgIHZhciBzdGF0ZTsKICAgICAgICBpZiAoIXN0cm0gfHwgIXN0cm0uc3RhdGUpIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgc3RhdGUgPSBzdHJtLnN0YXRlOwogICAgICAgIGlmICh3aW5kb3dCaXRzIDwgMCkgewogICAgICAgICAgd3JhcCA9IDA7CiAgICAgICAgICB3aW5kb3dCaXRzID0gLXdpbmRvd0JpdHM7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIHdyYXAgPSAod2luZG93Qml0cyA+PiA0KSArIDE7CiAgICAgICAgICBpZiAod2luZG93Qml0cyA8IDQ4KSB7CiAgICAgICAgICAgIHdpbmRvd0JpdHMgJj0gMTU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmICh3aW5kb3dCaXRzICYmICh3aW5kb3dCaXRzIDwgOCB8fCB3aW5kb3dCaXRzID4gMTUpKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIGlmIChzdGF0ZS53aW5kb3cgIT09IG51bGwgJiYgc3RhdGUud2JpdHMgIT09IHdpbmRvd0JpdHMpIHsKICAgICAgICAgIHN0YXRlLndpbmRvdyA9IG51bGw7CiAgICAgICAgfQogICAgICAgIHN0YXRlLndyYXAgPSB3cmFwOwogICAgICAgIHN0YXRlLndiaXRzID0gd2luZG93Qml0czsKICAgICAgICByZXR1cm4gaW5mbGF0ZVJlc2V0KHN0cm0pOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGluZmxhdGVJbml0MihzdHJtLCB3aW5kb3dCaXRzKSB7CiAgICAgICAgdmFyIHJldDsKICAgICAgICB2YXIgc3RhdGU7CiAgICAgICAgaWYgKCFzdHJtKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIHN0YXRlID0gbmV3IEluZmxhdGVTdGF0ZSgpOwogICAgICAgIHN0cm0uc3RhdGUgPSBzdGF0ZTsKICAgICAgICBzdGF0ZS53aW5kb3cgPSBudWxsOwogICAgICAgIHJldCA9IGluZmxhdGVSZXNldDIoc3RybSwgd2luZG93Qml0cyk7CiAgICAgICAgaWYgKHJldCAhPT0gWl9PSykgewogICAgICAgICAgc3RybS5zdGF0ZSA9IG51bGw7CiAgICAgICAgfQogICAgICAgIHJldHVybiByZXQ7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gaW5mbGF0ZUluaXQoc3RybSkgewogICAgICAgIHJldHVybiBpbmZsYXRlSW5pdDIoc3RybSwgREVGX1dCSVRTKTsKICAgICAgfQogICAgICB2YXIgdmlyZ2luID0gdHJ1ZTsKICAgICAgdmFyIGxlbmZpeDsKICAgICAgdmFyIGRpc3RmaXg7CiAgICAgIGZ1bmN0aW9uIGZpeGVkdGFibGVzKHN0YXRlKSB7CiAgICAgICAgaWYgKHZpcmdpbikgewogICAgICAgICAgdmFyIHN5bTsKICAgICAgICAgIGxlbmZpeCA9IG5ldyB1dGlscy5CdWYzMig1MTIpOwogICAgICAgICAgZGlzdGZpeCA9IG5ldyB1dGlscy5CdWYzMigzMik7CiAgICAgICAgICBzeW0gPSAwOwogICAgICAgICAgd2hpbGUgKHN5bSA8IDE0NCkgewogICAgICAgICAgICBzdGF0ZS5sZW5zW3N5bSsrXSA9IDg7CiAgICAgICAgICB9CiAgICAgICAgICB3aGlsZSAoc3ltIDwgMjU2KSB7CiAgICAgICAgICAgIHN0YXRlLmxlbnNbc3ltKytdID0gOTsKICAgICAgICAgIH0KICAgICAgICAgIHdoaWxlIChzeW0gPCAyODApIHsKICAgICAgICAgICAgc3RhdGUubGVuc1tzeW0rK10gPSA3OwogICAgICAgICAgfQogICAgICAgICAgd2hpbGUgKHN5bSA8IDI4OCkgewogICAgICAgICAgICBzdGF0ZS5sZW5zW3N5bSsrXSA9IDg7CiAgICAgICAgICB9CiAgICAgICAgICBpbmZsYXRlX3RhYmxlKExFTlMsIHN0YXRlLmxlbnMsIDAsIDI4OCwgbGVuZml4LCAwLCBzdGF0ZS53b3JrLCB7IGJpdHM6IDkgfSk7CiAgICAgICAgICBzeW0gPSAwOwogICAgICAgICAgd2hpbGUgKHN5bSA8IDMyKSB7CiAgICAgICAgICAgIHN0YXRlLmxlbnNbc3ltKytdID0gNTsKICAgICAgICAgIH0KICAgICAgICAgIGluZmxhdGVfdGFibGUoRElTVFMsIHN0YXRlLmxlbnMsIDAsIDMyLCBkaXN0Zml4LCAwLCBzdGF0ZS53b3JrLCB7IGJpdHM6IDUgfSk7CiAgICAgICAgICB2aXJnaW4gPSBmYWxzZTsKICAgICAgICB9CiAgICAgICAgc3RhdGUubGVuY29kZSA9IGxlbmZpeDsKICAgICAgICBzdGF0ZS5sZW5iaXRzID0gOTsKICAgICAgICBzdGF0ZS5kaXN0Y29kZSA9IGRpc3RmaXg7CiAgICAgICAgc3RhdGUuZGlzdGJpdHMgPSA1OwogICAgICB9CiAgICAgIGZ1bmN0aW9uIHVwZGF0ZXdpbmRvdyhzdHJtLCBzcmMsIGVuZCwgY29weSkgewogICAgICAgIHZhciBkaXN0OwogICAgICAgIHZhciBzdGF0ZSA9IHN0cm0uc3RhdGU7CiAgICAgICAgaWYgKHN0YXRlLndpbmRvdyA9PT0gbnVsbCkgewogICAgICAgICAgc3RhdGUud3NpemUgPSAxIDw8IHN0YXRlLndiaXRzOwogICAgICAgICAgc3RhdGUud25leHQgPSAwOwogICAgICAgICAgc3RhdGUud2hhdmUgPSAwOwogICAgICAgICAgc3RhdGUud2luZG93ID0gbmV3IHV0aWxzLkJ1Zjgoc3RhdGUud3NpemUpOwogICAgICAgIH0KICAgICAgICBpZiAoY29weSA+PSBzdGF0ZS53c2l6ZSkgewogICAgICAgICAgdXRpbHMuYXJyYXlTZXQoc3RhdGUud2luZG93LCBzcmMsIGVuZCAtIHN0YXRlLndzaXplLCBzdGF0ZS53c2l6ZSwgMCk7CiAgICAgICAgICBzdGF0ZS53bmV4dCA9IDA7CiAgICAgICAgICBzdGF0ZS53aGF2ZSA9IHN0YXRlLndzaXplOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBkaXN0ID0gc3RhdGUud3NpemUgLSBzdGF0ZS53bmV4dDsKICAgICAgICAgIGlmIChkaXN0ID4gY29weSkgewogICAgICAgICAgICBkaXN0ID0gY29weTsKICAgICAgICAgIH0KICAgICAgICAgIHV0aWxzLmFycmF5U2V0KHN0YXRlLndpbmRvdywgc3JjLCBlbmQgLSBjb3B5LCBkaXN0LCBzdGF0ZS53bmV4dCk7CiAgICAgICAgICBjb3B5IC09IGRpc3Q7CiAgICAgICAgICBpZiAoY29weSkgewogICAgICAgICAgICB1dGlscy5hcnJheVNldChzdGF0ZS53aW5kb3csIHNyYywgZW5kIC0gY29weSwgY29weSwgMCk7CiAgICAgICAgICAgIHN0YXRlLnduZXh0ID0gY29weTsKICAgICAgICAgICAgc3RhdGUud2hhdmUgPSBzdGF0ZS53c2l6ZTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHN0YXRlLnduZXh0ICs9IGRpc3Q7CiAgICAgICAgICAgIGlmIChzdGF0ZS53bmV4dCA9PT0gc3RhdGUud3NpemUpIHsKICAgICAgICAgICAgICBzdGF0ZS53bmV4dCA9IDA7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHN0YXRlLndoYXZlIDwgc3RhdGUud3NpemUpIHsKICAgICAgICAgICAgICBzdGF0ZS53aGF2ZSArPSBkaXN0OwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiAwOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGluZmxhdGUoc3RybSwgZmx1c2gpIHsKICAgICAgICB2YXIgc3RhdGU7CiAgICAgICAgdmFyIGlucHV0LCBvdXRwdXQ7CiAgICAgICAgdmFyIG5leHQ7CiAgICAgICAgdmFyIHB1dDsKICAgICAgICB2YXIgaGF2ZSwgbGVmdDsKICAgICAgICB2YXIgaG9sZDsKICAgICAgICB2YXIgYml0czsKICAgICAgICB2YXIgX2luLCBfb3V0OwogICAgICAgIHZhciBjb3B5OwogICAgICAgIHZhciBmcm9tOwogICAgICAgIHZhciBmcm9tX3NvdXJjZTsKICAgICAgICB2YXIgaGVyZSA9IDA7CiAgICAgICAgdmFyIGhlcmVfYml0cywgaGVyZV9vcCwgaGVyZV92YWw7CiAgICAgICAgdmFyIGxhc3RfYml0cywgbGFzdF9vcCwgbGFzdF92YWw7CiAgICAgICAgdmFyIGxlbjsKICAgICAgICB2YXIgcmV0OwogICAgICAgIHZhciBoYnVmID0gbmV3IHV0aWxzLkJ1ZjgoNCk7CiAgICAgICAgdmFyIG9wdHM7CiAgICAgICAgdmFyIG47CiAgICAgICAgdmFyIG9yZGVyID0gWzE2LCAxNywgMTgsIDAsIDgsIDcsIDksIDYsIDEwLCA1LCAxMSwgNCwgMTIsIDMsIDEzLCAyLCAxNCwgMSwgMTVdOwogICAgICAgIGlmICghc3RybSB8fCAhc3RybS5zdGF0ZSB8fCAhc3RybS5vdXRwdXQgfHwgIXN0cm0uaW5wdXQgJiYgc3RybS5hdmFpbF9pbiAhPT0gMCkgewogICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VSUk9SOwogICAgICAgIH0KICAgICAgICBzdGF0ZSA9IHN0cm0uc3RhdGU7CiAgICAgICAgaWYgKHN0YXRlLm1vZGUgPT09IFRZUEUpIHsKICAgICAgICAgIHN0YXRlLm1vZGUgPSBUWVBFRE87CiAgICAgICAgfQogICAgICAgIHB1dCA9IHN0cm0ubmV4dF9vdXQ7CiAgICAgICAgb3V0cHV0ID0gc3RybS5vdXRwdXQ7CiAgICAgICAgbGVmdCA9IHN0cm0uYXZhaWxfb3V0OwogICAgICAgIG5leHQgPSBzdHJtLm5leHRfaW47CiAgICAgICAgaW5wdXQgPSBzdHJtLmlucHV0OwogICAgICAgIGhhdmUgPSBzdHJtLmF2YWlsX2luOwogICAgICAgIGhvbGQgPSBzdGF0ZS5ob2xkOwogICAgICAgIGJpdHMgPSBzdGF0ZS5iaXRzOwogICAgICAgIF9pbiA9IGhhdmU7CiAgICAgICAgX291dCA9IGxlZnQ7CiAgICAgICAgcmV0ID0gWl9PSzsKICAgICAgICBpbmZfbGVhdmU6CiAgICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgICAgc3dpdGNoIChzdGF0ZS5tb2RlKSB7CiAgICAgICAgICAgICAgY2FzZSBIRUFEOgogICAgICAgICAgICAgICAgaWYgKHN0YXRlLndyYXAgPT09IDApIHsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IFRZUEVETzsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB3aGlsZSAoYml0cyA8IDE2KSB7CiAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmIChzdGF0ZS53cmFwICYgMiAmJiBob2xkID09PSAzNTYxNSkgewogICAgICAgICAgICAgICAgICBzdGF0ZS5jaGVjayA9IDA7CiAgICAgICAgICAgICAgICAgIGhidWZbMF0gPSBob2xkICYgMjU1OwogICAgICAgICAgICAgICAgICBoYnVmWzFdID0gaG9sZCA+Pj4gOCAmIDI1NTsKICAgICAgICAgICAgICAgICAgc3RhdGUuY2hlY2sgPSBjcmMzMihzdGF0ZS5jaGVjaywgaGJ1ZiwgMiwgMCk7CiAgICAgICAgICAgICAgICAgIGhvbGQgPSAwOwogICAgICAgICAgICAgICAgICBiaXRzID0gMDsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEZMQUdTOwogICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0YXRlLmZsYWdzID0gMDsKICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5oZWFkKSB7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmhlYWQuZG9uZSA9IGZhbHNlOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKCEoc3RhdGUud3JhcCAmIDEpIHx8ICgoKGhvbGQgJiAyNTUpIDw8IDgpICsgKGhvbGQgPj4gOCkpICUgMzEpIHsKICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW5jb3JyZWN0IGhlYWRlciBjaGVjayI7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKChob2xkICYgMTUpICE9PSBaX0RFRkxBVEVEKSB7CiAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gInVua25vd24gY29tcHJlc3Npb24gbWV0aG9kIjsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBob2xkID4+Pj0gNDsKICAgICAgICAgICAgICAgIGJpdHMgLT0gNDsKICAgICAgICAgICAgICAgIGxlbiA9IChob2xkICYgMTUpICsgODsKICAgICAgICAgICAgICAgIGlmIChzdGF0ZS53Yml0cyA9PT0gMCkgewogICAgICAgICAgICAgICAgICBzdGF0ZS53Yml0cyA9IGxlbjsKICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAobGVuID4gc3RhdGUud2JpdHMpIHsKICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW52YWxpZCB3aW5kb3cgc2l6ZSI7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUuZG1heCA9IDEgPDwgbGVuOwogICAgICAgICAgICAgICAgc3RybS5hZGxlciA9IHN0YXRlLmNoZWNrID0gMTsKICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBob2xkICYgNTEyID8gRElDVElEIDogVFlQRTsKICAgICAgICAgICAgICAgIGhvbGQgPSAwOwogICAgICAgICAgICAgICAgYml0cyA9IDA7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICBjYXNlIEZMQUdTOgogICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCAxNikgewogICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5mbGFncyA9IGhvbGQ7CiAgICAgICAgICAgICAgICBpZiAoKHN0YXRlLmZsYWdzICYgMjU1KSAhPT0gWl9ERUZMQVRFRCkgewogICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJ1bmtub3duIGNvbXByZXNzaW9uIG1ldGhvZCI7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmZsYWdzICYgNTczNDQpIHsKICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAidW5rbm93biBoZWFkZXIgZmxhZ3Mgc2V0IjsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuaGVhZCkgewogICAgICAgICAgICAgICAgICBzdGF0ZS5oZWFkLnRleHQgPSBob2xkID4+IDggJiAxOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmZsYWdzICYgNTEyKSB7CiAgICAgICAgICAgICAgICAgIGhidWZbMF0gPSBob2xkICYgMjU1OwogICAgICAgICAgICAgICAgICBoYnVmWzFdID0gaG9sZCA+Pj4gOCAmIDI1NTsKICAgICAgICAgICAgICAgICAgc3RhdGUuY2hlY2sgPSBjcmMzMihzdGF0ZS5jaGVjaywgaGJ1ZiwgMiwgMCk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBob2xkID0gMDsKICAgICAgICAgICAgICAgIGJpdHMgPSAwOwogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IFRJTUU7CiAgICAgICAgICAgICAgY2FzZSBUSU1FOgogICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCAzMikgewogICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuaGVhZCkgewogICAgICAgICAgICAgICAgICBzdGF0ZS5oZWFkLnRpbWUgPSBob2xkOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmZsYWdzICYgNTEyKSB7CiAgICAgICAgICAgICAgICAgIGhidWZbMF0gPSBob2xkICYgMjU1OwogICAgICAgICAgICAgICAgICBoYnVmWzFdID0gaG9sZCA+Pj4gOCAmIDI1NTsKICAgICAgICAgICAgICAgICAgaGJ1ZlsyXSA9IGhvbGQgPj4+IDE2ICYgMjU1OwogICAgICAgICAgICAgICAgICBoYnVmWzNdID0gaG9sZCA+Pj4gMjQgJiAyNTU7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmNoZWNrID0gY3JjMzIoc3RhdGUuY2hlY2ssIGhidWYsIDQsIDApOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaG9sZCA9IDA7CiAgICAgICAgICAgICAgICBiaXRzID0gMDsKICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBPUzsKICAgICAgICAgICAgICBjYXNlIE9TOgogICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCAxNikgewogICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuaGVhZCkgewogICAgICAgICAgICAgICAgICBzdGF0ZS5oZWFkLnhmbGFncyA9IGhvbGQgJiAyNTU7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmhlYWQub3MgPSBob2xkID4+IDg7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuZmxhZ3MgJiA1MTIpIHsKICAgICAgICAgICAgICAgICAgaGJ1ZlswXSA9IGhvbGQgJiAyNTU7CiAgICAgICAgICAgICAgICAgIGhidWZbMV0gPSBob2xkID4+PiA4ICYgMjU1OwogICAgICAgICAgICAgICAgICBzdGF0ZS5jaGVjayA9IGNyYzMyKHN0YXRlLmNoZWNrLCBoYnVmLCAyLCAwKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGhvbGQgPSAwOwogICAgICAgICAgICAgICAgYml0cyA9IDA7CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gRVhMRU47CiAgICAgICAgICAgICAgY2FzZSBFWExFTjoKICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5mbGFncyAmIDEwMjQpIHsKICAgICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCAxNikgewogICAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgc3RhdGUubGVuZ3RoID0gaG9sZDsKICAgICAgICAgICAgICAgICAgaWYgKHN0YXRlLmhlYWQpIHsKICAgICAgICAgICAgICAgICAgICBzdGF0ZS5oZWFkLmV4dHJhX2xlbiA9IGhvbGQ7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaWYgKHN0YXRlLmZsYWdzICYgNTEyKSB7CiAgICAgICAgICAgICAgICAgICAgaGJ1ZlswXSA9IGhvbGQgJiAyNTU7CiAgICAgICAgICAgICAgICAgICAgaGJ1ZlsxXSA9IGhvbGQgPj4+IDggJiAyNTU7CiAgICAgICAgICAgICAgICAgICAgc3RhdGUuY2hlY2sgPSBjcmMzMihzdGF0ZS5jaGVjaywgaGJ1ZiwgMiwgMCk7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaG9sZCA9IDA7CiAgICAgICAgICAgICAgICAgIGJpdHMgPSAwOwogICAgICAgICAgICAgICAgfSBlbHNlIGlmIChzdGF0ZS5oZWFkKSB7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmhlYWQuZXh0cmEgPSBudWxsOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEVYVFJBOwogICAgICAgICAgICAgIGNhc2UgRVhUUkE6CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuZmxhZ3MgJiAxMDI0KSB7CiAgICAgICAgICAgICAgICAgIGNvcHkgPSBzdGF0ZS5sZW5ndGg7CiAgICAgICAgICAgICAgICAgIGlmIChjb3B5ID4gaGF2ZSkgewogICAgICAgICAgICAgICAgICAgIGNvcHkgPSBoYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChjb3B5KSB7CiAgICAgICAgICAgICAgICAgICAgaWYgKHN0YXRlLmhlYWQpIHsKICAgICAgICAgICAgICAgICAgICAgIGxlbiA9IHN0YXRlLmhlYWQuZXh0cmFfbGVuIC0gc3RhdGUubGVuZ3RoOwogICAgICAgICAgICAgICAgICAgICAgaWYgKCFzdGF0ZS5oZWFkLmV4dHJhKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHN0YXRlLmhlYWQuZXh0cmEgPSBuZXcgQXJyYXkoc3RhdGUuaGVhZC5leHRyYV9sZW4pOwogICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgdXRpbHMuYXJyYXlTZXQoc3RhdGUuaGVhZC5leHRyYSwgaW5wdXQsIG5leHQsIGNvcHksIGxlbik7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5mbGFncyAmIDUxMikgewogICAgICAgICAgICAgICAgICAgICAgc3RhdGUuY2hlY2sgPSBjcmMzMihzdGF0ZS5jaGVjaywgaW5wdXQsIGNvcHksIG5leHQpOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBoYXZlIC09IGNvcHk7CiAgICAgICAgICAgICAgICAgICAgbmV4dCArPSBjb3B5OwogICAgICAgICAgICAgICAgICAgIHN0YXRlLmxlbmd0aCAtPSBjb3B5OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5sZW5ndGgpIHsKICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0YXRlLmxlbmd0aCA9IDA7CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gTkFNRTsKICAgICAgICAgICAgICBjYXNlIE5BTUU6CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuZmxhZ3MgJiAyMDQ4KSB7CiAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGNvcHkgPSAwOwogICAgICAgICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgICAgICAgbGVuID0gaW5wdXRbbmV4dCArIGNvcHkrK107CiAgICAgICAgICAgICAgICAgICAgaWYgKHN0YXRlLmhlYWQgJiYgbGVuICYmIHN0YXRlLmxlbmd0aCA8IDY1NTM2KSB7CiAgICAgICAgICAgICAgICAgICAgICBzdGF0ZS5oZWFkLm5hbWUgKz0gU3RyaW5nLmZyb21DaGFyQ29kZShsZW4pOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgfSB3aGlsZSAobGVuICYmIGNvcHkgPCBoYXZlKTsKICAgICAgICAgICAgICAgICAgaWYgKHN0YXRlLmZsYWdzICYgNTEyKSB7CiAgICAgICAgICAgICAgICAgICAgc3RhdGUuY2hlY2sgPSBjcmMzMihzdGF0ZS5jaGVjaywgaW5wdXQsIGNvcHksIG5leHQpOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGhhdmUgLT0gY29weTsKICAgICAgICAgICAgICAgICAgbmV4dCArPSBjb3B5OwogICAgICAgICAgICAgICAgICBpZiAobGVuKSB7CiAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKHN0YXRlLmhlYWQpIHsKICAgICAgICAgICAgICAgICAgc3RhdGUuaGVhZC5uYW1lID0gbnVsbDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0YXRlLmxlbmd0aCA9IDA7CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQ09NTUVOVDsKICAgICAgICAgICAgICBjYXNlIENPTU1FTlQ6CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuZmxhZ3MgJiA0MDk2KSB7CiAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGNvcHkgPSAwOwogICAgICAgICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgICAgICAgbGVuID0gaW5wdXRbbmV4dCArIGNvcHkrK107CiAgICAgICAgICAgICAgICAgICAgaWYgKHN0YXRlLmhlYWQgJiYgbGVuICYmIHN0YXRlLmxlbmd0aCA8IDY1NTM2KSB7CiAgICAgICAgICAgICAgICAgICAgICBzdGF0ZS5oZWFkLmNvbW1lbnQgKz0gU3RyaW5nLmZyb21DaGFyQ29kZShsZW4pOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgfSB3aGlsZSAobGVuICYmIGNvcHkgPCBoYXZlKTsKICAgICAgICAgICAgICAgICAgaWYgKHN0YXRlLmZsYWdzICYgNTEyKSB7CiAgICAgICAgICAgICAgICAgICAgc3RhdGUuY2hlY2sgPSBjcmMzMihzdGF0ZS5jaGVjaywgaW5wdXQsIGNvcHksIG5leHQpOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGhhdmUgLT0gY29weTsKICAgICAgICAgICAgICAgICAgbmV4dCArPSBjb3B5OwogICAgICAgICAgICAgICAgICBpZiAobGVuKSB7CiAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKHN0YXRlLmhlYWQpIHsKICAgICAgICAgICAgICAgICAgc3RhdGUuaGVhZC5jb21tZW50ID0gbnVsbDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBIQ1JDOwogICAgICAgICAgICAgIGNhc2UgSENSQzoKICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5mbGFncyAmIDUxMikgewogICAgICAgICAgICAgICAgICB3aGlsZSAoYml0cyA8IDE2KSB7CiAgICAgICAgICAgICAgICAgICAgaWYgKGhhdmUgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgaGF2ZS0tOwogICAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBpZiAoaG9sZCAhPT0gKHN0YXRlLmNoZWNrICYgNjU1MzUpKSB7CiAgICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaGVhZGVyIGNyYyBtaXNtYXRjaCI7CiAgICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBob2xkID0gMDsKICAgICAgICAgICAgICAgICAgYml0cyA9IDA7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuaGVhZCkgewogICAgICAgICAgICAgICAgICBzdGF0ZS5oZWFkLmhjcmMgPSBzdGF0ZS5mbGFncyA+PiA5ICYgMTsKICAgICAgICAgICAgICAgICAgc3RhdGUuaGVhZC5kb25lID0gdHJ1ZTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0cm0uYWRsZXIgPSBzdGF0ZS5jaGVjayA9IDA7CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gVFlQRTsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgIGNhc2UgRElDVElEOgogICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCAzMikgewogICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gc3RhdGUuY2hlY2sgPSB6c3dhcDMyKGhvbGQpOwogICAgICAgICAgICAgICAgaG9sZCA9IDA7CiAgICAgICAgICAgICAgICBiaXRzID0gMDsKICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBESUNUOwogICAgICAgICAgICAgIGNhc2UgRElDVDoKICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5oYXZlZGljdCA9PT0gMCkgewogICAgICAgICAgICAgICAgICBzdHJtLm5leHRfb3V0ID0gcHV0OwogICAgICAgICAgICAgICAgICBzdHJtLmF2YWlsX291dCA9IGxlZnQ7CiAgICAgICAgICAgICAgICAgIHN0cm0ubmV4dF9pbiA9IG5leHQ7CiAgICAgICAgICAgICAgICAgIHN0cm0uYXZhaWxfaW4gPSBoYXZlOwogICAgICAgICAgICAgICAgICBzdGF0ZS5ob2xkID0gaG9sZDsKICAgICAgICAgICAgICAgICAgc3RhdGUuYml0cyA9IGJpdHM7CiAgICAgICAgICAgICAgICAgIHJldHVybiBaX05FRURfRElDVDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0cm0uYWRsZXIgPSBzdGF0ZS5jaGVjayA9IDE7CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gVFlQRTsKICAgICAgICAgICAgICBjYXNlIFRZUEU6CiAgICAgICAgICAgICAgICBpZiAoZmx1c2ggPT09IFpfQkxPQ0sgfHwgZmx1c2ggPT09IFpfVFJFRVMpIHsKICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGNhc2UgVFlQRURPOgogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmxhc3QpIHsKICAgICAgICAgICAgICAgICAgaG9sZCA+Pj49IGJpdHMgJiA3OwogICAgICAgICAgICAgICAgICBiaXRzIC09IGJpdHMgJiA3OwogICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQ0hFQ0s7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCAzKSB7CiAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0YXRlLmxhc3QgPSBob2xkICYgMTsKICAgICAgICAgICAgICAgIGhvbGQgPj4+PSAxOwogICAgICAgICAgICAgICAgYml0cyAtPSAxOwogICAgICAgICAgICAgICAgc3dpdGNoIChob2xkICYgMykgewogICAgICAgICAgICAgICAgICBjYXNlIDA6CiAgICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IFNUT1JFRDsKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgY2FzZSAxOgogICAgICAgICAgICAgICAgICAgIGZpeGVkdGFibGVzKHN0YXRlKTsKICAgICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gTEVOXzsKICAgICAgICAgICAgICAgICAgICBpZiAoZmx1c2ggPT09IFpfVFJFRVMpIHsKICAgICAgICAgICAgICAgICAgICAgIGhvbGQgPj4+PSAyOwogICAgICAgICAgICAgICAgICAgICAgYml0cyAtPSAyOwogICAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgY2FzZSAyOgogICAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBUQUJMRTsKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgY2FzZSAzOgogICAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImludmFsaWQgYmxvY2sgdHlwZSI7CiAgICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGhvbGQgPj4+PSAyOwogICAgICAgICAgICAgICAgYml0cyAtPSAyOwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgY2FzZSBTVE9SRUQ6CiAgICAgICAgICAgICAgICBob2xkID4+Pj0gYml0cyAmIDc7CiAgICAgICAgICAgICAgICBiaXRzIC09IGJpdHMgJiA3OwogICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCAzMikgewogICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoKGhvbGQgJiA2NTUzNSkgIT09IChob2xkID4+PiAxNiBeIDY1NTM1KSkgewogICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbnZhbGlkIHN0b3JlZCBibG9jayBsZW5ndGhzIjsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5sZW5ndGggPSBob2xkICYgNjU1MzU7CiAgICAgICAgICAgICAgICBob2xkID0gMDsKICAgICAgICAgICAgICAgIGJpdHMgPSAwOwogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IENPUFlfOwogICAgICAgICAgICAgICAgaWYgKGZsdXNoID09PSBaX1RSRUVTKSB7CiAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBjYXNlIENPUFlfOgogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IENPUFk7CiAgICAgICAgICAgICAgY2FzZSBDT1BZOgogICAgICAgICAgICAgICAgY29weSA9IHN0YXRlLmxlbmd0aDsKICAgICAgICAgICAgICAgIGlmIChjb3B5KSB7CiAgICAgICAgICAgICAgICAgIGlmIChjb3B5ID4gaGF2ZSkgewogICAgICAgICAgICAgICAgICAgIGNvcHkgPSBoYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChjb3B5ID4gbGVmdCkgewogICAgICAgICAgICAgICAgICAgIGNvcHkgPSBsZWZ0OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChjb3B5ID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIHV0aWxzLmFycmF5U2V0KG91dHB1dCwgaW5wdXQsIG5leHQsIGNvcHksIHB1dCk7CiAgICAgICAgICAgICAgICAgIGhhdmUgLT0gY29weTsKICAgICAgICAgICAgICAgICAgbmV4dCArPSBjb3B5OwogICAgICAgICAgICAgICAgICBsZWZ0IC09IGNvcHk7CiAgICAgICAgICAgICAgICAgIHB1dCArPSBjb3B5OwogICAgICAgICAgICAgICAgICBzdGF0ZS5sZW5ndGggLT0gY29weTsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gVFlQRTsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgIGNhc2UgVEFCTEU6CiAgICAgICAgICAgICAgICB3aGlsZSAoYml0cyA8IDE0KSB7CiAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0YXRlLm5sZW4gPSAoaG9sZCAmIDMxKSArIDI1NzsKICAgICAgICAgICAgICAgIGhvbGQgPj4+PSA1OwogICAgICAgICAgICAgICAgYml0cyAtPSA1OwogICAgICAgICAgICAgICAgc3RhdGUubmRpc3QgPSAoaG9sZCAmIDMxKSArIDE7CiAgICAgICAgICAgICAgICBob2xkID4+Pj0gNTsKICAgICAgICAgICAgICAgIGJpdHMgLT0gNTsKICAgICAgICAgICAgICAgIHN0YXRlLm5jb2RlID0gKGhvbGQgJiAxNSkgKyA0OwogICAgICAgICAgICAgICAgaG9sZCA+Pj49IDQ7CiAgICAgICAgICAgICAgICBiaXRzIC09IDQ7CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUubmxlbiA+IDI4NiB8fCBzdGF0ZS5uZGlzdCA+IDMwKSB7CiAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gInRvbyBtYW55IGxlbmd0aCBvciBkaXN0YW5jZSBzeW1ib2xzIjsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5oYXZlID0gMDsKICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBMRU5MRU5TOwogICAgICAgICAgICAgIGNhc2UgTEVOTEVOUzoKICAgICAgICAgICAgICAgIHdoaWxlIChzdGF0ZS5oYXZlIDwgc3RhdGUubmNvZGUpIHsKICAgICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCAzKSB7CiAgICAgICAgICAgICAgICAgICAgaWYgKGhhdmUgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgaGF2ZS0tOwogICAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBzdGF0ZS5sZW5zW29yZGVyW3N0YXRlLmhhdmUrK11dID0gaG9sZCAmIDc7CiAgICAgICAgICAgICAgICAgIGhvbGQgPj4+PSAzOwogICAgICAgICAgICAgICAgICBiaXRzIC09IDM7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB3aGlsZSAoc3RhdGUuaGF2ZSA8IDE5KSB7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmxlbnNbb3JkZXJbc3RhdGUuaGF2ZSsrXV0gPSAwOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUubGVuY29kZSA9IHN0YXRlLmxlbmR5bjsKICAgICAgICAgICAgICAgIHN0YXRlLmxlbmJpdHMgPSA3OwogICAgICAgICAgICAgICAgb3B0cyA9IHsgYml0czogc3RhdGUubGVuYml0cyB9OwogICAgICAgICAgICAgICAgcmV0ID0gaW5mbGF0ZV90YWJsZShDT0RFUywgc3RhdGUubGVucywgMCwgMTksIHN0YXRlLmxlbmNvZGUsIDAsIHN0YXRlLndvcmssIG9wdHMpOwogICAgICAgICAgICAgICAgc3RhdGUubGVuYml0cyA9IG9wdHMuYml0czsKICAgICAgICAgICAgICAgIGlmIChyZXQpIHsKICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW52YWxpZCBjb2RlIGxlbmd0aHMgc2V0IjsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5oYXZlID0gMDsKICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBDT0RFTEVOUzsKICAgICAgICAgICAgICBjYXNlIENPREVMRU5TOgogICAgICAgICAgICAgICAgd2hpbGUgKHN0YXRlLmhhdmUgPCBzdGF0ZS5ubGVuICsgc3RhdGUubmRpc3QpIHsKICAgICAgICAgICAgICAgICAgZm9yICg7IDsgKSB7CiAgICAgICAgICAgICAgICAgICAgaGVyZSA9IHN0YXRlLmxlbmNvZGVbaG9sZCAmICgxIDw8IHN0YXRlLmxlbmJpdHMpIC0gMV07CiAgICAgICAgICAgICAgICAgICAgaGVyZV9iaXRzID0gaGVyZSA+Pj4gMjQ7CiAgICAgICAgICAgICAgICAgICAgaGVyZV9vcCA9IGhlcmUgPj4+IDE2ICYgMjU1OwogICAgICAgICAgICAgICAgICAgIGhlcmVfdmFsID0gaGVyZSAmIDY1NTM1OwogICAgICAgICAgICAgICAgICAgIGlmIChoZXJlX2JpdHMgPD0gYml0cykgewogICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaWYgKGhlcmVfdmFsIDwgMTYpIHsKICAgICAgICAgICAgICAgICAgICBob2xkID4+Pj0gaGVyZV9iaXRzOwogICAgICAgICAgICAgICAgICAgIGJpdHMgLT0gaGVyZV9iaXRzOwogICAgICAgICAgICAgICAgICAgIHN0YXRlLmxlbnNbc3RhdGUuaGF2ZSsrXSA9IGhlcmVfdmFsOwogICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgIGlmIChoZXJlX3ZhbCA9PT0gMTYpIHsKICAgICAgICAgICAgICAgICAgICAgIG4gPSBoZXJlX2JpdHMgKyAyOwogICAgICAgICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCBuKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgIGhvbGQgPj4+PSBoZXJlX2JpdHM7CiAgICAgICAgICAgICAgICAgICAgICBiaXRzIC09IGhlcmVfYml0czsKICAgICAgICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5oYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImludmFsaWQgYml0IGxlbmd0aCByZXBlYXQiOwogICAgICAgICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEOwogICAgICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgIGxlbiA9IHN0YXRlLmxlbnNbc3RhdGUuaGF2ZSAtIDFdOwogICAgICAgICAgICAgICAgICAgICAgY29weSA9IDMgKyAoaG9sZCAmIDMpOwogICAgICAgICAgICAgICAgICAgICAgaG9sZCA+Pj49IDI7CiAgICAgICAgICAgICAgICAgICAgICBiaXRzIC09IDI7CiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIGlmIChoZXJlX3ZhbCA9PT0gMTcpIHsKICAgICAgICAgICAgICAgICAgICAgIG4gPSBoZXJlX2JpdHMgKyAzOwogICAgICAgICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCBuKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgIGhvbGQgPj4+PSBoZXJlX2JpdHM7CiAgICAgICAgICAgICAgICAgICAgICBiaXRzIC09IGhlcmVfYml0czsKICAgICAgICAgICAgICAgICAgICAgIGxlbiA9IDA7CiAgICAgICAgICAgICAgICAgICAgICBjb3B5ID0gMyArIChob2xkICYgNyk7CiAgICAgICAgICAgICAgICAgICAgICBob2xkID4+Pj0gMzsKICAgICAgICAgICAgICAgICAgICAgIGJpdHMgLT0gMzsKICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgbiA9IGhlcmVfYml0cyArIDc7CiAgICAgICAgICAgICAgICAgICAgICB3aGlsZSAoYml0cyA8IG4pIHsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGhhdmUgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgaGF2ZS0tOwogICAgICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgaG9sZCA+Pj49IGhlcmVfYml0czsKICAgICAgICAgICAgICAgICAgICAgIGJpdHMgLT0gaGVyZV9iaXRzOwogICAgICAgICAgICAgICAgICAgICAgbGVuID0gMDsKICAgICAgICAgICAgICAgICAgICAgIGNvcHkgPSAxMSArIChob2xkICYgMTI3KTsKICAgICAgICAgICAgICAgICAgICAgIGhvbGQgPj4+PSA3OwogICAgICAgICAgICAgICAgICAgICAgYml0cyAtPSA3OwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBpZiAoc3RhdGUuaGF2ZSArIGNvcHkgPiBzdGF0ZS5ubGVuICsgc3RhdGUubmRpc3QpIHsKICAgICAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImludmFsaWQgYml0IGxlbmd0aCByZXBlYXQiOwogICAgICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICB3aGlsZSAoY29weS0tKSB7CiAgICAgICAgICAgICAgICAgICAgICBzdGF0ZS5sZW5zW3N0YXRlLmhhdmUrK10gPSBsZW47CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUubW9kZSA9PT0gQkFEKSB7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmxlbnNbMjU2XSA9PT0gMCkgewogICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbnZhbGlkIGNvZGUgLS0gbWlzc2luZyBlbmQtb2YtYmxvY2siOwogICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEOwogICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0YXRlLmxlbmJpdHMgPSA5OwogICAgICAgICAgICAgICAgb3B0cyA9IHsgYml0czogc3RhdGUubGVuYml0cyB9OwogICAgICAgICAgICAgICAgcmV0ID0gaW5mbGF0ZV90YWJsZShMRU5TLCBzdGF0ZS5sZW5zLCAwLCBzdGF0ZS5ubGVuLCBzdGF0ZS5sZW5jb2RlLCAwLCBzdGF0ZS53b3JrLCBvcHRzKTsKICAgICAgICAgICAgICAgIHN0YXRlLmxlbmJpdHMgPSBvcHRzLmJpdHM7CiAgICAgICAgICAgICAgICBpZiAocmV0KSB7CiAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImludmFsaWQgbGl0ZXJhbC9sZW5ndGhzIHNldCI7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUuZGlzdGJpdHMgPSA2OwogICAgICAgICAgICAgICAgc3RhdGUuZGlzdGNvZGUgPSBzdGF0ZS5kaXN0ZHluOwogICAgICAgICAgICAgICAgb3B0cyA9IHsgYml0czogc3RhdGUuZGlzdGJpdHMgfTsKICAgICAgICAgICAgICAgIHJldCA9IGluZmxhdGVfdGFibGUoRElTVFMsIHN0YXRlLmxlbnMsIHN0YXRlLm5sZW4sIHN0YXRlLm5kaXN0LCBzdGF0ZS5kaXN0Y29kZSwgMCwgc3RhdGUud29yaywgb3B0cyk7CiAgICAgICAgICAgICAgICBzdGF0ZS5kaXN0Yml0cyA9IG9wdHMuYml0czsKICAgICAgICAgICAgICAgIGlmIChyZXQpIHsKICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW52YWxpZCBkaXN0YW5jZXMgc2V0IjsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gTEVOXzsKICAgICAgICAgICAgICAgIGlmIChmbHVzaCA9PT0gWl9UUkVFUykgewogICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgY2FzZSBMRU5fOgogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IExFTjsKICAgICAgICAgICAgICBjYXNlIExFTjoKICAgICAgICAgICAgICAgIGlmIChoYXZlID49IDYgJiYgbGVmdCA+PSAyNTgpIHsKICAgICAgICAgICAgICAgICAgc3RybS5uZXh0X291dCA9IHB1dDsKICAgICAgICAgICAgICAgICAgc3RybS5hdmFpbF9vdXQgPSBsZWZ0OwogICAgICAgICAgICAgICAgICBzdHJtLm5leHRfaW4gPSBuZXh0OwogICAgICAgICAgICAgICAgICBzdHJtLmF2YWlsX2luID0gaGF2ZTsKICAgICAgICAgICAgICAgICAgc3RhdGUuaG9sZCA9IGhvbGQ7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmJpdHMgPSBiaXRzOwogICAgICAgICAgICAgICAgICBpbmZsYXRlX2Zhc3Qoc3RybSwgX291dCk7CiAgICAgICAgICAgICAgICAgIHB1dCA9IHN0cm0ubmV4dF9vdXQ7CiAgICAgICAgICAgICAgICAgIG91dHB1dCA9IHN0cm0ub3V0cHV0OwogICAgICAgICAgICAgICAgICBsZWZ0ID0gc3RybS5hdmFpbF9vdXQ7CiAgICAgICAgICAgICAgICAgIG5leHQgPSBzdHJtLm5leHRfaW47CiAgICAgICAgICAgICAgICAgIGlucHV0ID0gc3RybS5pbnB1dDsKICAgICAgICAgICAgICAgICAgaGF2ZSA9IHN0cm0uYXZhaWxfaW47CiAgICAgICAgICAgICAgICAgIGhvbGQgPSBzdGF0ZS5ob2xkOwogICAgICAgICAgICAgICAgICBiaXRzID0gc3RhdGUuYml0czsKICAgICAgICAgICAgICAgICAgaWYgKHN0YXRlLm1vZGUgPT09IFRZUEUpIHsKICAgICAgICAgICAgICAgICAgICBzdGF0ZS5iYWNrID0gLTE7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5iYWNrID0gMDsKICAgICAgICAgICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgICAgICAgICBoZXJlID0gc3RhdGUubGVuY29kZVtob2xkICYgKDEgPDwgc3RhdGUubGVuYml0cykgLSAxXTsKICAgICAgICAgICAgICAgICAgaGVyZV9iaXRzID0gaGVyZSA+Pj4gMjQ7CiAgICAgICAgICAgICAgICAgIGhlcmVfb3AgPSBoZXJlID4+PiAxNiAmIDI1NTsKICAgICAgICAgICAgICAgICAgaGVyZV92YWwgPSBoZXJlICYgNjU1MzU7CiAgICAgICAgICAgICAgICAgIGlmIChoZXJlX2JpdHMgPD0gYml0cykgewogICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmIChoZXJlX29wICYmIChoZXJlX29wICYgMjQwKSA9PT0gMCkgewogICAgICAgICAgICAgICAgICBsYXN0X2JpdHMgPSBoZXJlX2JpdHM7CiAgICAgICAgICAgICAgICAgIGxhc3Rfb3AgPSBoZXJlX29wOwogICAgICAgICAgICAgICAgICBsYXN0X3ZhbCA9IGhlcmVfdmFsOwogICAgICAgICAgICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgICAgICAgICAgICBoZXJlID0gc3RhdGUubGVuY29kZVtsYXN0X3ZhbCArICgoaG9sZCAmICgxIDw8IGxhc3RfYml0cyArIGxhc3Rfb3ApIC0gMSkgPj4gbGFzdF9iaXRzKV07CiAgICAgICAgICAgICAgICAgICAgaGVyZV9iaXRzID0gaGVyZSA+Pj4gMjQ7CiAgICAgICAgICAgICAgICAgICAgaGVyZV9vcCA9IGhlcmUgPj4+IDE2ICYgMjU1OwogICAgICAgICAgICAgICAgICAgIGhlcmVfdmFsID0gaGVyZSAmIDY1NTM1OwogICAgICAgICAgICAgICAgICAgIGlmIChsYXN0X2JpdHMgKyBoZXJlX2JpdHMgPD0gYml0cykgewogICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaG9sZCA+Pj49IGxhc3RfYml0czsKICAgICAgICAgICAgICAgICAgYml0cyAtPSBsYXN0X2JpdHM7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmJhY2sgKz0gbGFzdF9iaXRzOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaG9sZCA+Pj49IGhlcmVfYml0czsKICAgICAgICAgICAgICAgIGJpdHMgLT0gaGVyZV9iaXRzOwogICAgICAgICAgICAgICAgc3RhdGUuYmFjayArPSBoZXJlX2JpdHM7CiAgICAgICAgICAgICAgICBzdGF0ZS5sZW5ndGggPSBoZXJlX3ZhbDsKICAgICAgICAgICAgICAgIGlmIChoZXJlX29wID09PSAwKSB7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBMSVQ7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKGhlcmVfb3AgJiAzMikgewogICAgICAgICAgICAgICAgICBzdGF0ZS5iYWNrID0gLTE7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBUWVBFOwogICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmIChoZXJlX29wICYgNjQpIHsKICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW52YWxpZCBsaXRlcmFsL2xlbmd0aCBjb2RlIjsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5leHRyYSA9IGhlcmVfb3AgJiAxNTsKICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBMRU5FWFQ7CiAgICAgICAgICAgICAgY2FzZSBMRU5FWFQ6CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuZXh0cmEpIHsKICAgICAgICAgICAgICAgICAgbiA9IHN0YXRlLmV4dHJhOwogICAgICAgICAgICAgICAgICB3aGlsZSAoYml0cyA8IG4pIHsKICAgICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIHN0YXRlLmxlbmd0aCArPSBob2xkICYgKDEgPDwgc3RhdGUuZXh0cmEpIC0gMTsKICAgICAgICAgICAgICAgICAgaG9sZCA+Pj49IHN0YXRlLmV4dHJhOwogICAgICAgICAgICAgICAgICBiaXRzIC09IHN0YXRlLmV4dHJhOwogICAgICAgICAgICAgICAgICBzdGF0ZS5iYWNrICs9IHN0YXRlLmV4dHJhOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUud2FzID0gc3RhdGUubGVuZ3RoOwogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IERJU1Q7CiAgICAgICAgICAgICAgY2FzZSBESVNUOgogICAgICAgICAgICAgICAgZm9yICg7IDsgKSB7CiAgICAgICAgICAgICAgICAgIGhlcmUgPSBzdGF0ZS5kaXN0Y29kZVtob2xkICYgKDEgPDwgc3RhdGUuZGlzdGJpdHMpIC0gMV07CiAgICAgICAgICAgICAgICAgIGhlcmVfYml0cyA9IGhlcmUgPj4+IDI0OwogICAgICAgICAgICAgICAgICBoZXJlX29wID0gaGVyZSA+Pj4gMTYgJiAyNTU7CiAgICAgICAgICAgICAgICAgIGhlcmVfdmFsID0gaGVyZSAmIDY1NTM1OwogICAgICAgICAgICAgICAgICBpZiAoaGVyZV9iaXRzIDw9IGJpdHMpIHsKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoKGhlcmVfb3AgJiAyNDApID09PSAwKSB7CiAgICAgICAgICAgICAgICAgIGxhc3RfYml0cyA9IGhlcmVfYml0czsKICAgICAgICAgICAgICAgICAgbGFzdF9vcCA9IGhlcmVfb3A7CiAgICAgICAgICAgICAgICAgIGxhc3RfdmFsID0gaGVyZV92YWw7CiAgICAgICAgICAgICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgICAgICAgICAgIGhlcmUgPSBzdGF0ZS5kaXN0Y29kZVtsYXN0X3ZhbCArICgoaG9sZCAmICgxIDw8IGxhc3RfYml0cyArIGxhc3Rfb3ApIC0gMSkgPj4gbGFzdF9iaXRzKV07CiAgICAgICAgICAgICAgICAgICAgaGVyZV9iaXRzID0gaGVyZSA+Pj4gMjQ7CiAgICAgICAgICAgICAgICAgICAgaGVyZV9vcCA9IGhlcmUgPj4+IDE2ICYgMjU1OwogICAgICAgICAgICAgICAgICAgIGhlcmVfdmFsID0gaGVyZSAmIDY1NTM1OwogICAgICAgICAgICAgICAgICAgIGlmIChsYXN0X2JpdHMgKyBoZXJlX2JpdHMgPD0gYml0cykgewogICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaG9sZCA+Pj49IGxhc3RfYml0czsKICAgICAgICAgICAgICAgICAgYml0cyAtPSBsYXN0X2JpdHM7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmJhY2sgKz0gbGFzdF9iaXRzOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaG9sZCA+Pj49IGhlcmVfYml0czsKICAgICAgICAgICAgICAgIGJpdHMgLT0gaGVyZV9iaXRzOwogICAgICAgICAgICAgICAgc3RhdGUuYmFjayArPSBoZXJlX2JpdHM7CiAgICAgICAgICAgICAgICBpZiAoaGVyZV9vcCAmIDY0KSB7CiAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImludmFsaWQgZGlzdGFuY2UgY29kZSI7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUub2Zmc2V0ID0gaGVyZV92YWw7CiAgICAgICAgICAgICAgICBzdGF0ZS5leHRyYSA9IGhlcmVfb3AgJiAxNTsKICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBESVNURVhUOwogICAgICAgICAgICAgIGNhc2UgRElTVEVYVDoKICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5leHRyYSkgewogICAgICAgICAgICAgICAgICBuID0gc3RhdGUuZXh0cmE7CiAgICAgICAgICAgICAgICAgIHdoaWxlIChiaXRzIDwgbikgewogICAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgc3RhdGUub2Zmc2V0ICs9IGhvbGQgJiAoMSA8PCBzdGF0ZS5leHRyYSkgLSAxOwogICAgICAgICAgICAgICAgICBob2xkID4+Pj0gc3RhdGUuZXh0cmE7CiAgICAgICAgICAgICAgICAgIGJpdHMgLT0gc3RhdGUuZXh0cmE7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmJhY2sgKz0gc3RhdGUuZXh0cmE7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUub2Zmc2V0ID4gc3RhdGUuZG1heCkgewogICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbnZhbGlkIGRpc3RhbmNlIHRvbyBmYXIgYmFjayI7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IE1BVENIOwogICAgICAgICAgICAgIGNhc2UgTUFUQ0g6CiAgICAgICAgICAgICAgICBpZiAobGVmdCA9PT0gMCkgewogICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBjb3B5ID0gX291dCAtIGxlZnQ7CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUub2Zmc2V0ID4gY29weSkgewogICAgICAgICAgICAgICAgICBjb3B5ID0gc3RhdGUub2Zmc2V0IC0gY29weTsKICAgICAgICAgICAgICAgICAgaWYgKGNvcHkgPiBzdGF0ZS53aGF2ZSkgewogICAgICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5zYW5lKSB7CiAgICAgICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbnZhbGlkIGRpc3RhbmNlIHRvbyBmYXIgYmFjayI7CiAgICAgICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEOwogICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChjb3B5ID4gc3RhdGUud25leHQpIHsKICAgICAgICAgICAgICAgICAgICBjb3B5IC09IHN0YXRlLnduZXh0OwogICAgICAgICAgICAgICAgICAgIGZyb20gPSBzdGF0ZS53c2l6ZSAtIGNvcHk7CiAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgZnJvbSA9IHN0YXRlLnduZXh0IC0gY29weTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBpZiAoY29weSA+IHN0YXRlLmxlbmd0aCkgewogICAgICAgICAgICAgICAgICAgIGNvcHkgPSBzdGF0ZS5sZW5ndGg7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgZnJvbV9zb3VyY2UgPSBzdGF0ZS53aW5kb3c7CiAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICBmcm9tX3NvdXJjZSA9IG91dHB1dDsKICAgICAgICAgICAgICAgICAgZnJvbSA9IHB1dCAtIHN0YXRlLm9mZnNldDsKICAgICAgICAgICAgICAgICAgY29weSA9IHN0YXRlLmxlbmd0aDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmIChjb3B5ID4gbGVmdCkgewogICAgICAgICAgICAgICAgICBjb3B5ID0gbGVmdDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGxlZnQgLT0gY29weTsKICAgICAgICAgICAgICAgIHN0YXRlLmxlbmd0aCAtPSBjb3B5OwogICAgICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgICAgICBvdXRwdXRbcHV0KytdID0gZnJvbV9zb3VyY2VbZnJvbSsrXTsKICAgICAgICAgICAgICAgIH0gd2hpbGUgKC0tY29weSk7CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUubGVuZ3RoID09PSAwKSB7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBMRU47CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICBjYXNlIExJVDoKICAgICAgICAgICAgICAgIGlmIChsZWZ0ID09PSAwKSB7CiAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIG91dHB1dFtwdXQrK10gPSBzdGF0ZS5sZW5ndGg7CiAgICAgICAgICAgICAgICBsZWZ0LS07CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gTEVOOwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgY2FzZSBDSEVDSzoKICAgICAgICAgICAgICAgIGlmIChzdGF0ZS53cmFwKSB7CiAgICAgICAgICAgICAgICAgIHdoaWxlIChiaXRzIDwgMzIpIHsKICAgICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgICAgaG9sZCB8PSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIF9vdXQgLT0gbGVmdDsKICAgICAgICAgICAgICAgICAgc3RybS50b3RhbF9vdXQgKz0gX291dDsKICAgICAgICAgICAgICAgICAgc3RhdGUudG90YWwgKz0gX291dDsKICAgICAgICAgICAgICAgICAgaWYgKF9vdXQpIHsKICAgICAgICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gc3RhdGUuY2hlY2sgPSBzdGF0ZS5mbGFncyA/IGNyYzMyKHN0YXRlLmNoZWNrLCBvdXRwdXQsIF9vdXQsIHB1dCAtIF9vdXQpIDogYWRsZXIzMihzdGF0ZS5jaGVjaywgb3V0cHV0LCBfb3V0LCBwdXQgLSBfb3V0KTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBfb3V0ID0gbGVmdDsKICAgICAgICAgICAgICAgICAgaWYgKChzdGF0ZS5mbGFncyA/IGhvbGQgOiB6c3dhcDMyKGhvbGQpKSAhPT0gc3RhdGUuY2hlY2spIHsKICAgICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbmNvcnJlY3QgZGF0YSBjaGVjayI7CiAgICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBob2xkID0gMDsKICAgICAgICAgICAgICAgICAgYml0cyA9IDA7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gTEVOR1RIOwogICAgICAgICAgICAgIGNhc2UgTEVOR1RIOgogICAgICAgICAgICAgICAgaWYgKHN0YXRlLndyYXAgJiYgc3RhdGUuZmxhZ3MpIHsKICAgICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCAzMikgewogICAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaWYgKGhvbGQgIT09IChzdGF0ZS50b3RhbCAmIDQyOTQ5NjcyOTUpKSB7CiAgICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW5jb3JyZWN0IGxlbmd0aCBjaGVjayI7CiAgICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBob2xkID0gMDsKICAgICAgICAgICAgICAgICAgYml0cyA9IDA7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gRE9ORTsKICAgICAgICAgICAgICBjYXNlIERPTkU6CiAgICAgICAgICAgICAgICByZXQgPSBaX1NUUkVBTV9FTkQ7CiAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgY2FzZSBCQUQ6CiAgICAgICAgICAgICAgICByZXQgPSBaX0RBVEFfRVJST1I7CiAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgY2FzZSBNRU06CiAgICAgICAgICAgICAgICByZXR1cm4gWl9NRU1fRVJST1I7CiAgICAgICAgICAgICAgY2FzZSBTWU5DOgogICAgICAgICAgICAgIGRlZmF1bHQ6CiAgICAgICAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICBzdHJtLm5leHRfb3V0ID0gcHV0OwogICAgICAgIHN0cm0uYXZhaWxfb3V0ID0gbGVmdDsKICAgICAgICBzdHJtLm5leHRfaW4gPSBuZXh0OwogICAgICAgIHN0cm0uYXZhaWxfaW4gPSBoYXZlOwogICAgICAgIHN0YXRlLmhvbGQgPSBob2xkOwogICAgICAgIHN0YXRlLmJpdHMgPSBiaXRzOwogICAgICAgIGlmIChzdGF0ZS53c2l6ZSB8fCBfb3V0ICE9PSBzdHJtLmF2YWlsX291dCAmJiBzdGF0ZS5tb2RlIDwgQkFEICYmIChzdGF0ZS5tb2RlIDwgQ0hFQ0sgfHwgZmx1c2ggIT09IFpfRklOSVNIKSkgewogICAgICAgICAgaWYgKHVwZGF0ZXdpbmRvdyhzdHJtLCBzdHJtLm91dHB1dCwgc3RybS5uZXh0X291dCwgX291dCAtIHN0cm0uYXZhaWxfb3V0KSkgewogICAgICAgICAgICBzdGF0ZS5tb2RlID0gTUVNOwogICAgICAgICAgICByZXR1cm4gWl9NRU1fRVJST1I7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIF9pbiAtPSBzdHJtLmF2YWlsX2luOwogICAgICAgIF9vdXQgLT0gc3RybS5hdmFpbF9vdXQ7CiAgICAgICAgc3RybS50b3RhbF9pbiArPSBfaW47CiAgICAgICAgc3RybS50b3RhbF9vdXQgKz0gX291dDsKICAgICAgICBzdGF0ZS50b3RhbCArPSBfb3V0OwogICAgICAgIGlmIChzdGF0ZS53cmFwICYmIF9vdXQpIHsKICAgICAgICAgIHN0cm0uYWRsZXIgPSBzdGF0ZS5jaGVjayA9IHN0YXRlLmZsYWdzID8gY3JjMzIoc3RhdGUuY2hlY2ssIG91dHB1dCwgX291dCwgc3RybS5uZXh0X291dCAtIF9vdXQpIDogYWRsZXIzMihzdGF0ZS5jaGVjaywgb3V0cHV0LCBfb3V0LCBzdHJtLm5leHRfb3V0IC0gX291dCk7CiAgICAgICAgfQogICAgICAgIHN0cm0uZGF0YV90eXBlID0gc3RhdGUuYml0cyArIChzdGF0ZS5sYXN0ID8gNjQgOiAwKSArIChzdGF0ZS5tb2RlID09PSBUWVBFID8gMTI4IDogMCkgKyAoc3RhdGUubW9kZSA9PT0gTEVOXyB8fCBzdGF0ZS5tb2RlID09PSBDT1BZXyA/IDI1NiA6IDApOwogICAgICAgIGlmICgoX2luID09PSAwICYmIF9vdXQgPT09IDAgfHwgZmx1c2ggPT09IFpfRklOSVNIKSAmJiByZXQgPT09IFpfT0spIHsKICAgICAgICAgIHJldCA9IFpfQlVGX0VSUk9SOwogICAgICAgIH0KICAgICAgICByZXR1cm4gcmV0OwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGluZmxhdGVFbmQoc3RybSkgewogICAgICAgIGlmICghc3RybSB8fCAhc3RybS5zdGF0ZSkgewogICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VSUk9SOwogICAgICAgIH0KICAgICAgICB2YXIgc3RhdGUgPSBzdHJtLnN0YXRlOwogICAgICAgIGlmIChzdGF0ZS53aW5kb3cpIHsKICAgICAgICAgIHN0YXRlLndpbmRvdyA9IG51bGw7CiAgICAgICAgfQogICAgICAgIHN0cm0uc3RhdGUgPSBudWxsOwogICAgICAgIHJldHVybiBaX09LOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGluZmxhdGVHZXRIZWFkZXIoc3RybSwgaGVhZCkgewogICAgICAgIHZhciBzdGF0ZTsKICAgICAgICBpZiAoIXN0cm0gfHwgIXN0cm0uc3RhdGUpIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgc3RhdGUgPSBzdHJtLnN0YXRlOwogICAgICAgIGlmICgoc3RhdGUud3JhcCAmIDIpID09PSAwKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIHN0YXRlLmhlYWQgPSBoZWFkOwogICAgICAgIGhlYWQuZG9uZSA9IGZhbHNlOwogICAgICAgIHJldHVybiBaX09LOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGluZmxhdGVTZXREaWN0aW9uYXJ5KHN0cm0sIGRpY3Rpb25hcnkpIHsKICAgICAgICB2YXIgZGljdExlbmd0aCA9IGRpY3Rpb25hcnkubGVuZ3RoOwogICAgICAgIHZhciBzdGF0ZTsKICAgICAgICB2YXIgZGljdGlkOwogICAgICAgIHZhciByZXQ7CiAgICAgICAgaWYgKCFzdHJtIHx8ICFzdHJtLnN0YXRlKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIHN0YXRlID0gc3RybS5zdGF0ZTsKICAgICAgICBpZiAoc3RhdGUud3JhcCAhPT0gMCAmJiBzdG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KICAgICAgICBaX0RFRkFVTFRfQ09NUFJFU1NJT046IC0xLAogICAgICAgIFpfRklMVEVSRUQ6IDEsCiAgICAgICAgWl9IVUZGTUFOX09OTFk6IDIsCiAgICAgICAgWl9STEU6IDMsCiAgICAgICAgWl9GSVhFRDogNCwKICAgICAgICBaX0RFRkFVTFRfU1RSQVRFR1k6IDAsCiAgICAgICAgWl9CSU5BUlk6IDAsCiAgICAgICAgWl9URVhUOiAxLAogICAgICAgIFpfVU5LTk9XTjogMiwKICAgICAgICBaX0RFRkxBVEVEOiA4CiAgICAgIH07CiAgICB9CiAgfSk7CgogIC8vIG5vZGVfbW9kdWxlcy8ucG5wbS9wYWtvQDEuMC4xMS9ub2RlX21vZHVsZXMvcGFrby9saWIvemxpYi9nemhlYWRlci5qcwogIHZhciByZXF1aXJlX2d6aGVhZGVyID0gX19jb21tb25KUyh7CiAgICAibm9kZV9tb2R1bGVzLy5wbnBtL3Bha29AMS4wLjExL25vZGVfbW9kdWxlcy9wYWtvL2xpYi96bGliL2d6aGVhZGVyLmpzIihleHBvcnRzMiwgbW9kdWxlMikgewogICAgICBpbml0X2J1ZmZlcl9zaGltKCk7CiAgICAgICJ1c2Ugc3RyaWN0IjsKICAgICAgZnVuY3Rpb24gR1poZWFkZXIoKSB7CiAgICAgICAgdGhpcy50ZXh0ID0gMDsKICAgICAgICB0aGlzLnRpbWUgPSAwOwogICAgICAgIHRoaXMueGZsYWdzID0gMDsKICAgICAgICB0aGlzLm9zID0gMDsKICAgICAgICB0aGlzLmV4dHJhID0gbnVsbDsKICAgICAgICB0aGlzLmV4dHJhX2xlbiA9IDA7CiAgICAgICAgdGhpcy5uYW1lID0gIiI7CiAgICAgICAgdGhpcy5jb21tZW50ID0gIiI7CiAgICAgICAgdGhpcy5oY3JjID0gMDsKICAgICAgICB0aGlzLmRvbmUgPSBmYWxzZTsKICAgICAgfQogICAgICBtb2R1bGUyLmV4cG9ydHMgPSBHWmhlYWRlcjsKICAgIH0KICB9KTsKCiA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sKICAgICAgICBpZiAob3B0LnJhdyAmJiBvcHQud2luZG93Qml0cyA+PSAwICYmIG9wdC53aW5kb3dCaXRzIDwgMTYpIHsKICAgICAgICAgIG9wdC53aW5kb3dCaXRzID0gLW9wdC53aW5kb3dCaXRzOwogICAgICAgICAgaWYgKG9wdC53aW5kb3dCaXRzID09PSAwKSB7CiAgICAgICAgICAgIG9wdC53aW5kb3dCaXRzID0gLTE1OwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAob3B0LndpbmRvd0JpdHMgPj0gMCAmJiBvcHQud2luZG93Qml0cyA8IDE2ICYmICEob3B0aW9ucyAmJiBvcHRpb25zLndpbmRvd0JpdHMpKSB7CiAgICAgICAgICBvcHQud2luZG93Qml0cyArPSAzMjsKICAgICAgICB9CiAgICAgICAgaWYgKG9wdC53aW5kb3dCaXRzID4gMTUgJiYgb3B0LndpbmRvd0JpdHMgPCA0OCkgewogICAgICAgICAgaWYgKChvcHQud2luZG93Qml0cyAmIDE1KSA9PT0gMCkgewogICAgICAgICAgICBvcHQud2luZG93Qml0cyB8PSAxNTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgdGhpcy5lcnIgPSAwOwogICAgICAgIHRoaXMubXNnID0gIiI7CiAgICAgICAgdGhpcy5lbmRlZCA9IGZhbHNlOwogICAgICAgIHRoaXMuY2h1bmtzID0gW107CiAgICAgICAgdGhpcy5zdHJtID0gbmV3IFpTdHJlYW0oKTsKICAgICAgICB0aGlzLnN0cm0uYXZhaWxfb3V0ID0gMDsKICAgICAgICB2YXIgc3RhdHVzID0gemxpYl9pbmZsYXRlLmluZmxhdGVJbml0Mih0aGlzLnN0cm0sIG9wdC53aW5kb3dCaXRzKTsKICAgICAgICBpZiAoc3RhdHVzICE9PSBjLlpfT0spIHsKICAgICAgICAgIHRocm93IG5ldyBFcnJvcihtc2dbc3RhdHVzXSk7CiAgICAgICAgfQogICAgICAgIHRoaXMuaGVhZGVyID0gbmV3IEdaaGVhZGVyKCk7C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ZjhzdHI7CiAgICAgICAgdmFyIGFsbG93QnVmRXJyb3IgPSBmYWxzZTsKICAgICAgICBpZiAodGhpcy5lbmRlZCkgewogICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICAgIH0KICAgICAgICBfbW9kZSA9IG1vZGUgPT09IH5+bW9kZSA/IG1vZGUgOiBtb2RlID09PSB0cnVlID8gYy5aX0ZJTklTSCA6IGMuWl9OT19GTFVTSDsKICAgICAgICBpZiAodHlwZW9mIGRhdGEgPT09ICJzdHJpbmciKSB7CiAgICAgICAgICBzdHJtLmlucHV0ID0gc3RyaW5ncy5iaW5zdHJpbmcyYnVmKGRhdGEpOwogICAgICAgIH0gZWxzZSBpZiAodG9TdHJpbmcuY2FsbChkYXRhKSA9PT0gIltvYmplY3QgQXJyYXlCdWZmZXJdIikgewogICAgICAgICAgc3RybS5pbnB1dCA9IG5ldyBVaW50OEFycmF5KGRhdGEpOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBzdHJtLmlucHV0ID0gZGF0YTsKICAgICAgICB9CiAgICAgICAgc3RybS5uZXh0X2luID0gMDsKICAgICAgICBzdHJtLmF2YWlsX2luID0gc3RybS5pbnB1dC5sZW5ndGg7CiAgICAgICAgZG8gewogICAgICAgICAgaWYgKHN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgIHN0cm0ub3V0cHV0ID0gbmV3IHV0aWxzLkJ1ZjgoY2h1bmtTaXplKTsKICAgICAgICAgICAgc3RybS5uZXh0X291dCA9IDA7CiAgICAgICAgICAgIHN0cm0uYXZhaWxfb3V0ID0gY2h1bmtTaXplOwogICAgICAgICAgfQogICAgICAgICAgc3RhdHVzID0gemxpYl9pbmZsYXRlLmluZmxhdGUoc3RybSwgYy5aX05PX0ZMVVNIKTsKICAgICAgICAgIGlmIChzdGF0dXMgPT09IGMuWl9ORUVEX0RJQ1QgJiYgZGljdGlvbmFyeSkgewogICAgICAgICAgICBzdGF0dXMgPSB6bGliX2luZmxhdGUuaW5mbGF0ZVNldERpY3Rpb25hcnkodGhpcy5zdHJtLCBkaWN0aW9uYXJ5KTsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChzdGF0dXMgPT09IGMuWl9CVUZfRVJST1IgJiYgYWxsb3dCdWZFcnJvciA9PT0gdHJ1ZSkgewogICAgICAgICAgICBzdGF0dXMgPSBjLlpfT0s7CiAgICAgICAgICAgIGFsbG93QnVmRXJyb3IgPSBmYWxzZTsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChzdGF0dXMgIT09IGMuWl9TVFJFQU1fRU5EICYmIHN0YXR1cyAhPT0gYy5aX09LKSB7CiAgICAgICAgICAgIHRoaXMub25FbmQoc3RhdHVzKTsKICAgICAgICAgICAgdGhpcy5lbmRlZCA9IHRydWU7CiAgICAgICAgICAgIHJldHVybiBmYWxzZTsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChzdHJtLm5leHRfb3V0KSB7CiAgICAgICAgICAgIGlmIChzdHJtLmF2YWlsX291dCA9PT0gMCB8fCBzdGF0dXMgPT09IGMuWl9TVFJFQU1fRU5EIHx8IHN0cm0uYXZhaWxfaW4gPT09IDAgJiYgKF9tb2RlID09PSBjLlpfRklOSVNIIHx8IF9tb2RlID09PSBjLlpfU1lOQ19GTFVTSCkpIHsKICAgICAgICAgICAgICBpZiAodGhpcy5vcHRpb25zLnRvID09PSAic3RyaW5nIikgewogICAgICAgICAgICAgICAgbmV4dF9vdXRfdXRmOCA9IHN0cmluZ3MudXRmOGJvcmRlcihzdHJtLm91dHB1dCwgc3RybS5uZXh0X291dCk7CiAgICAgICAgICAgICAgICB0YWlsID0gc3RybS5uZXh0X291dCAtIG5leHRfb3V0X3V0Zjg7CiAgICAgICAgICAgICAgICB1dGY4c3RyID0gc3RyaW5ncy5idWYyc3RyaW5nKHN0cm0ub3V0cHV0LCBuZXh0X291dF91dGY4KTsKICAgICAgICAgICAgICAgIHN0cm0ubmV4dF9vdXQgPSB0YWlsOwogICAgICAgICAgICAgICAgc3RybS5hdmFpbF9vdXQgPSBjaHVua1NpemUgLSB0YWlsOwogICAgICAgICAgICAgICAgaWYgKHRhaWwpIHsKICAgICAgICAgICAgICAgICAgdXRpbHMuYXJyYXlTZXQoc3RybS5vdXRwdXQsIHN0cm0ub3V0cHV0LCBuZXh0X291dF91dGY4LCB0YWlsLCAwKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHRoaXMub25EYXRhKHV0ZjhzdHIpOwogICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICB0aGlzLm9uRGF0YSh1dGlscy5zaHJpbmtCdWYoc3RybS5vdXRwdXQsIHN0cm0ubmV4dF9vdXQpKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGlmIChzdHJtLmF2YWlsX2luID09PSAwICYmIHN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgIGFsbG93QnVmRXJyb3IgPSB0cnVlOwogICAgICAgICAgfQogICAgICAgIH0gd2hpbGUgKChzdHJtLmF2YWlsX2luID4gMCB8fCBzdHJtLmF2YWlsX291dCA9PT0gMCkgJiYgc3RhdHVzICE9PSBjLlpfU1RSRUFNX0VORCk7CiAgICAgICAgaWYgKHN0YXR1cyA9PT0gYy5aX1NUUkVBTV9FTkQpIHsKICAgICAgICAgIF9tb2RlID0gYy5aX0ZJTklTSDsKICAgICAgICB9CiAgICAgICAgaWYgKF9tb2RlID09PSBjLlpfRklOSVNIKSB7CiAgICAgICAgICBzdGF0dXMgPSB6bGliX2luZmxhdGUuaW5mbGF0ZUVuZCh0aGlzLnN0cm0pOwogICAgICAgICAgdGhpcy5vbkVuZChzdGF0dXMpOwogICAgICAgICAgdGhpcy5lbmRlZCA9IHRydWU7CiAgICAgICAgICByZXR1cm4gc3RhdHVzID09PSBjLlpfT0s7CiAgICAgICAgfQogICAgICAgIGlmIChfbW9kZSA9PT0gYy5aX1NZTkNfRkxVU0gpIHsKICAgICAgICAgIHRoaXMub25FbmQoYy5aX09LKTsKICAgICAgICAgIHN0cm0uYXZhaWxfb3V0ID0gMDsKICAgICAgICAgIHJldHVybiB0cnVlOwogICAgICAgIH0KICAgICAgICByZXR1cm4gdHJ1ZTsKICAgICAgfTsKICAgICAgSW5mbGF0ZTIucHJvdG90eXBlLm9uRGF0YSA9IGZ1bmN0aW9uKGNodW5rKSB7CiAgICAgICAgdGhpcy5jaHVua3MucHVzaChjaHVuayk7CiAgICAgIH07CiAgICAgIEluZmxhdGUyLnByb3RvdHlwZS5vbkVuZCA9IGZ1bmN0aW9uKHN0YXR1cykgewogICAgICAgIGlmIChzdGF0dXMgPT09IGMuWl9PSykgewogICAgICAgICAgaWYgKHRoaXMub3B0aW9ucy50byA9PT0gInN0cmluZyIpIHsKICAgICAgICAgICAgdGhpcy5yZXN1bHQgPSB0aGlzLmNodW5rcy5qb2luKCIiKTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHRoaXMucmVzdWx0ID0gdXRpbHMuZmxhdHRlbkNodW5rcyh0aGlzLmNodW5rcyk7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHRoaXMuY2h1bmtzID0gW107CiAgICAgICAgdGhpcy5lcnIgPSBzdGF0dXM7CiAgICAgICAgdGhpcy5tc2cgPSB0aGlzLnN0cm0ubXNnOwogICAgICB9OwogICAgICBmdW5jdGlvbiBpbmZsYXRlKGlucHV0LCBvcHRpb25zKSB7CiAgICAgICAgdmFyIGluZmxhdG9yID0gbmV3IEluZmxhdGUyKG9wdGlvbnMpOwogICAgICAgIGluZmxhdG9yLnB1c2goaW5wdXQsIHRydWUpOwogICAgICAgIGlmIChpbmZsYXRvci5lcnIpIHsKICAgICAgICAgIHRocm93IGluZmxhdG9yLm1zZyB8fCBtc2dbaW5mbGF0b3IuZXJyXTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIGluZmxhdG9yLnJlc3VsdDsKICAgICAgfQogICAgICBmdW5jdGlvbiBpb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ZGVfbW9kdWxlcy9sb25nL3NyYy9sb25nLmpzCiAgdmFyIHJlcXVpcmVfbG9uZyA9IF9fY29tbW9uSlMoewogICAgIm5vZGVfbW9kdWxlcy8ucG5wbS9sb25nQDQuMC4wL25vZGVfbW9kdWxlcy9sb25nL3NyYy9sb25nLmpzIihleHBvcnRzMiwgbW9kdWxlMikgewogICAgICBpbml0X2J1ZmZlcl9zaGltKCk7CiAgICAgIG1vZHVsZTIuZXhwb3J0cyA9IExvbmc0OwogICAgICB2YXIgd2FzbSA9IG51bGw7CiAgICAgIHRyeSB7CiAgICAgICAgd2FzbSA9IG5ldyBXZWJBc3NlbWJseS5JbnN0YW5jZShuZXcgV2ViQXNzZW1ibHkuTW9kdWxlKG5ldyBVaW50OEFycmF5KFsKICAgICAgICAgIDAsCiAgICAgICAgICA5NywKICAgICAgICAgIDExNSwKICAgICAgICAgIDEwOSwKICAgICAgICAgIDEsCiAgICAgICAgICAwLAogICAgICAgICAgMCwKICAgICAgICAgIDAsCiAgICAgICAgICAxLAogICAgICAgICAgMTMsCiAgICAgICAgICAyLAogICAgICAgICAgOTYsCiAgICAgICAgICAwLAogICAgICAgICAgMSwKICAgICAgICAgIDEyNywKICAgICAgICAgIDk2LAogICAgICAgICAgNCwKICAgICAgICAgIDEyNywKICAgICAgICAgIDEyNywKICAgICAgICAgIDEyNywKICAgICAgICAgIDEyNywKICAgICAgICAgIDEsCiAgICAgICAgICAxMjcsCiAgICAgICAgICAzLAogICAgICAgICAgNywKICAgICAgICAgIDYsCiAgICAgICAgICAwLAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICAxLAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICA2LAogICAgICAgICAgNiwKICAgICAgICAgIDEsCiAgICAgICAgICAxMjcsCiAgICAgICAgICAxLAogICAgICAgICAgNjUsCiAgICAgICAgICAwLAogICAgICAgICAgMTEsCiAgICAgICAgICA3LAogICAgICAgICAgNTAsCiAgICAgICAgICA2LAogICAgICAgICAgMywKICAgICAgICAgIDEwOSwKICAgICAgICAgIDExNywKICAgICAgICAgIDEwOCwKICAgICAgICAgIDAsCiAgICAgICAgICAxLAogICAgICAgICAgNSwKICAgICAgICAgIDEwMCwKICAgICAgICAgIDEwNSwKICAgICAgICAgIDExOCwKICAgICAgICAgIDk1LAogICAgICAgICAgMTE1LAogICAgICAgICAgMCwKICAgICAgICAgIDIsCiAgICAgICAgICA1LAogICAgICAgICAgMTAwLAogICAgICAgICAgMTA1LAogICAgICAgICAgMTE4LAogICAgICAgICAgOTUsCiAgICAgICAgICAxMTcsCiAgICAgICAgICAwLAogICAgICAgICAgMywKICAgICAgICAgIDUsCiAgICAgICAgICAxMTQsCiAgICAgICAgICAxMDEsCiAgICAgICAgICAxMDksCiAgICAgICAgICA5NSwKICAgICAgICAgIDExNSwKICAgICAgICAgIDAsCiAgICAgICAgICA0LAogICAgICAgICAgNSwKICAgICAgICAgIDExNCwKICAgICAgICAgIDEwMSwKICAgICAgICAgIDEwOSwKICAgICAgICAgIDk1LAogICAgICAgICAgMTE3LAogICAgICAgICAgMCwKICAgICAgICAgIDUsCiAgICAgICAgICA4LAogICAgICAgICAgMTAzLAogICAgICAgICAgMTAxLAogICAgICAgICAgMTE2LAogICAgICAgICAgOTUsCiAgICAgICAgICAxMDQsCiAgICAgICAgICAxMDUsCiAgICAgICAgICAxMDMsCiAgICAgICAgICAxMDQsCiAgICAgICAgICAwLAogICAgICAgICAgMCwKICAgICAgICAgIDEwLAogICAgICAgICAgMTkxLAogICAgICAgICAgMSwKICAgICAgICAgIDYsCiAgICAgICAgICA0LAogICAgICAgICAgMCwKICAgICAgICAgIDM1LAogICAgICAgICAgMCwKICAgICAgICAgIDExLAogICAgICAgICAgMzYsCiAgICAgICAgICAxLAogICAgICAgICAgMSwKICAgICAgICAgIDEyNiwKICAgICAgICAgIDMyLAogICAgICAgICAgMCwKICAgICAgICAgIDE3MywKICAgICAgICAgIDMyLAogICAgICAgICAgMSwKICAgICAgICAgIDE3MywKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzQsCiAgICAgICAgICAxMzIsCiAgICAgICAgICAzMiwKICAgICAgICAgIDIsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDMsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMTI2LAogICAgICAgICAgMzQsCiAgICAgICAgICA0LAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNSwKICAgICAgICAgIDE2NywKICAgICAgICAgIDM2LAogICAgICAgICAgMCwKICAgICAgICAgIDMyLAogICAgICAgICAgNCwKICAgICAgICAgIDE2NywKICAgICAgICAgIDExLAogICAgICAgICAgMzYsCiAgICAgICAgICAxLAogICAgICAgICAgMSwKICAgICAgICAgIDEyNiwKICAgICAgICAgIDMyLAogICAgICAgICAgMCwKICAgICAgICAgIDE3MywKICAgICAgICAgIDMyLAogICAgICAgICAgMSwKICAgICAgICAgIDE3MywKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzQsCiAgICAgICAgICAxMzIsCiAgICAgICAgICAzMiwKICAgICAgICAgIDIsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDMsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMTI3LAogICAgICAgICAgMzQsCiAgICAgICAgICA0LAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNSwKICAgICAgICAgIDE2NywKICAgICAgICAgIDM2LAogICAgICAgICAgMCwKICAgICAgICAgIDMyLAogICAgICAgICAgNCwKICAgICAgICAgIDE2NywKICAgICAgICAgIDExLAogICAgICAgICAgMzYsCiAgICAgICAgICAxLAogICAgICAgICAgMSwKICAgICAgICAgIDEyNiwKICAgICAgICAgIDMyLAogICAgICAgICAgMCwKICAgICAgICAgIDE3MywKICAgICAgICAgIDMyLAogICAgICAgICAgMSwKICAgICAgICAgIDE3MywKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzQsCiAgICAgICAgICAxMzIsCiAgICAgICAgICAzMiwKICAgICAgICAgIDIsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDMsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMTI4LAogICAgICAgICAgMzQsCiAgICAgICAgICA0LAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNSwKICAgICAgICAgIDE2NywKICAgICAgICAgIDM2LAogICAgICAgICAgMCwKICAgICAgICAgIDMyLAogICAgICAgICAgNCwKICAgICAgICAgIDE2NywKICAgICAgICAgIDExLAogICAgICAgICAgMzYsCiAgICAgICAgICAxLAogICAgICAgICAgMSwKICAgICAgICAgIDEyNiwKICAgICAgICAgIDMyLAogICAgICAgICAgMCwKICAgICAgICAgIDE3MywKICAgICAgICAgIDMyLAogICAgICAgICAgMSwKICAgICAgICAgIDE3MywKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzQsCiAgICAgICAgICAxMzIsCiAgICAgICAgICAzMiwKICAgICAgICAgIDIsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDMsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMTI5LAogICAgICAgICAgMzQsCiAgICAgICAgICA0LAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNSwKICAgICAgICAgIDE2NywKICAgICAgICAgIDM2LAogICAgICAgICAgMCwKICAgICAgICAgIDMyLAogICAgICAgICAgNCwKICAgICAgICAgIDE2NywKICAgICAgICAgIDExLAogICAgICAgICAgMzYsCiAgICAgICAgICAxLAogICAgICAgICAgMSwKICAgICAgICAgIDEyNiwKICAgICAgICAgIDMyLAogICAgICAgICAgMCwKICAgICAgICAgIDE3MywKICAgICAgICAgIDMyLAogICAgICAgICAgMSwKICAgICAgICAgIDE3MywKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzQsCiAgICAgICAgICAxMzIsCiAgICAgICAgICAzMiwKICAgICAgICAgIDIsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDMsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMTMwLAogICAgICAgICAgMzQsCiAgICAgICAgICA0LAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNSwKICAgICAgICAgIDE2NywKICAgICAgICAgIDM2LAogICAgICAgICAgMCwKICAgICAgICAgIDMyLAogICAgICAgICAgNCwKICAgICAgICAgIDE2NywKICAgICAgICAgIDExCiAgICAgICAgXSkpLCB7fSkuZXhwb3J0czsKICAgICAgfSBjYXRjaCAoZSkgewogICAgICB9CiAgICAgIGZ1bmN0aW9uIExvbmc0KGxvdywgaGlnaCwgdW5zaWduZWQpIHsKICAgICAgICB0aGlzLmxvdyA9IGxvdyB8IDA7CiAgICAgICAgdGhpcy5oaWdoID0gaGlnaCB8IDA7CiAgICAgICAgdGhpcy51bnNpZ25lZCA9ICEhdW5zaWduZWQ7CiAgICAgIH0KICAgICAgTG9uZzQucHJvdG90eXBlLl9faXNMb25nX187CiAgICAgIE9iamVjdC5kZWZpbmVQcm9wZXJ0eShMb25nNC5wcm90b3R5cGUsICJfX2lzTG9uZ19fIiwgeyB2YWx1ZTogdHJ1ZSB9KTsKICAgICAgZnVuY3Rpb24gaXNMb25nKG9iaikgewogICAgICAgIHJldHVybiAob2JqICYmIG9ialsiX19pc0xvbmdfXyJdKSA9PT0gdHJ1ZTsKICAgICAgfQogICAgICBMb25nNC5pc0xvbmcgPSBpc0xvbmc7CiAgICAgIHZhciBJTlRfQ0FDSEUgPSB7fTsKICAgICAgdmFyIFVJTlRfQ0FDSEUgPSB7fTsKICAgICAgZnVuY3Rpb24gZnJvbUludCh2YWx1ZSwgdW5zaWduZWQpIHsKICAgICAgICB2YXIgb2JqLCBjYWNoZWRPYmosIGNhY2hlOwogICAgICAgIGlmICh1bnNpZ25lZCkgewogICAgICAgICAgdmFsdWUgPj4+PSAwOwogICAgICAgICAgaWYgKGNhY2hlID0gMCA8PSB2YWx1ZSAmJiB2YWx1ZSA8IDI1NikgewogICAgICAgICAgICBjYWNoZWRPYmogPSBVSU5UX0NBQ0hFW3ZhbHVlXTsKICAgICAgICAgICAgaWYgKGNhY2hlZE9iaikKICAgICAgICAgICAgICByZXR1cm4gY2FjaGVkT2JqOwogICAgICAgICAgfQogICAgICAgICAgb2JqID0gZnJvbUJpdHModmFsdWUsICh2YWx1ZSB8IDApIDwgMCA/IC0xIDogMCwgdHJ1ZSk7CiAgICAgICAgICBpZiAoY2FjaGUpCiAgICAgICAgICAgIFVJTlRfQ0FDSEVbdmFsdWVdID0gb2JqOwogICAgICAgICAgcmV0dXJuIG9iajsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgdmFsdWUgfD0gMDsKICAgICAgICAgIGlmIChjYWNoZSA9IC0xMjggPD0gdmFsdWUgJiYgdmFsdWUgPCAxMjgpIHsKICAgICAgICAgICAgY2FjaGVkT2JqID0gSU5UX0NBQ0hFW3ZhbHVlXTsKICAgICAgICAgICAgaWYgKGNhY2hlZE9iaikKICAgICAgICAgICAgICByZXR1cm4gY2FjaGVkT2JqOwogICAgICAgICAgfQogICAgICAgICAgb2JqID0gZnJvbUJpdHModmFsdWUsIHZhbHVlIDwgMCA/IC0xIDogMCwgZmFsc2UpOwogICAgICAgICAgaWYgKGNhY2hlKQogICAgICAgICAgICBJTlRfQ0FDSEVbdmFsdWVdID0gb2JqOwogICAgICAgICAgcmV0dXJuIG9iajsKICAgICAgICB9CiAgICAgIH0KICAgICAgTG9uZzQuZnJvbUludCA9IGZyb21JbnQ7CiAgICAgIGZ1bmN0aW9uIGZyb21OdW1iZXIodmFsdWUsIHVuc2lnbmVkKSB7CiAgICAgICAgaWYgKGlzTmFOKHZhbHVlKSkKICAgICAgICAgIHJldHVybiB1bnNpZ25lZCA/IFVaRVJPIDogWkVSTzsKICAgICAgICBpZiAodW5zaWduZWQpIHsKICAgICAgICAgIGlmICh2YWx1ZSA8IDApCiAgICAgICAgICAgIHJldHVybiBVWkVSTzsKICAgICAgICAgIGlmICh2YWx1ZSA+PSBUV09fUFdSXzY0X0RCTCkKICAgICAgICAgICAgcmV0dXJuIE1BWF9VTlNJR05FRF9WQUxVRTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgaWYgKHZhbHVlIDw9IC1UV09fUFdSXzYzX0RCTCkKICAgICAgICAgICAgcmV0dXJuIE1JTl9WQUxVRTsKICAgICAgICAgIGlmICh2YWx1ZSArIDEgPj0gVFdPX1BXUl82M19EQkwpCiAgICAgICAgICAgIHJldHVybiBNQVhfVkFMVUU7CiAgICAgICAgfQogICAgICAgIGlmICh2YWx1ZSA8IDApCiAgICAgICAgICByZXR1cm4gZnJvbU51bWJlcigtdmFsdWUsIHVuc2lnbmVkKS5uZWcoKTsKICAgICAgICByZXR1cm4gZnJvbUJpdHModmFsdWUgJSBUV09fUFdSXzMyX0RCTCB8IDAsIHZhbHVlIC8gVFdPX1BXUl8zMl9EQkwgfCAwLCB1bnNpZ25lZCk7CiAgICAgIH0KICAgICAgTG9uZzQuZnJvbU51bWJlciA9IGZyb21OdW1iZXI7CiAgICAgIGZ1bmN0aW9uIGZyb21CaXRzKGxvd0JpdHMsIGhpZ2hCaXRzLCB1bnNpZ25lZCkgewogICAgICAgIHJldHVybiBuZXcgTG9uZzQobG93Qml0cywgaGlnaEJpdHMsIHVuc2lnbmVkKTsKICAgICAgfQogICAgICBMb25nNC5mcm9tQml0cyA9IGZyb21CaXRzOwogICAgICB2YXIgcG93X2RibCA9IE1hdGgucG93OwogICAgICBmdW5jdGlvbiBmcm9tU3RyaW5nKHN0ciwgdW5zaWduZWQsIHJhZGl4KSB7CiAgICAgICAgaWYgKHN0ci5sZW5ndGggPT09IDApCiAgICAgICAgICB0aHJvdyBFcnJvcigiZW1wdHkgc3RyaW5nIik7CiAgICAgICAgaWYgKHN0ciA9PT0gIk5hTiIgfHwgc3RyID09PSAiSW5maW5pdHkiIHx8IHN0ciA9PT0gIitJbmZpbml0eSIgfHwgc3RyID09PSAiLUluZmluaXR5IikKICAgICAgICAgIHJldHVybiBaRVJPOwogICAgICAgIGlmICh0eXBlb2YgdW5zaWduZWQgPT09ICJudW1iZXIiKSB7CiAgICAgICAgICByYWRpeCA9IHVuc2lnbmVkLCB1bnNpZ25lZCA9IGZhbHNlOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICB1bnNpZ25lZCA9ICEhdW5zaWduZWQ7CiAgICAgICAgfQogICAgICAgIHJhZGl4ID0gcmFkaXggfHwgMTA7CiAgICAgICAgaWYgKHJhZGl4IDwgMiB8fCAzNiA8IHJhZGl4KQogICAgICAgICAgdGhyb3cgUmFuZ2VFcnJvcigicmFkaXgiKTsKICAgICAgICB2YXIgcDsKICAgICAgICBpZiAoKHAgPSBzdHIuaW5kZXhPZigiLSIpKSA+IDApCiAgICAgICAgICB0aHJvdyBFcnJvcigiaW50ZXJpb3IgaHlwaGVuIik7CiAgICAgICAgZWxzZSBpZiAocCA9PT0gMCkgewogICAgICAgICAgcmV0dXJuIGZyb21TdHJpbmcoc3RyLnN1YnN0cmluZygxKSwgdW5zaWduZWQsIHJhZGl4KS5uZWcoKTsKICAgICAgICB9CiAgICAgICAgdmFyIHJhZGl4VG9Qb3dlciA9IGZyb21OdW1iZXIocG93X2RibChyYWRpeCwgOCkpOwogICAgICAgIHZhciByZXN1bHQgPSBaRVJPOwogICAgICAgIGZvciAodmFyIGkgPSAwOyBpIDwgc3RyLmxlbmd0aDsgaSArPSA4KSB7CiAgICAgICAgICB2YXIgc2l6ZSA9IE1hdGgubWluKDgsIHN0ci5sZW5ndGggLSBpKSwgdmFsdWUgPSBwYXJzZUludChzdHIuc3Vic3RyaW5nKGksIGkgKyBzaXplKSwgcmFkaXgpOwogICAgICAgICAgaWYgKHNpemUgPCA4KSB7CiAgICAgICAgICAgIHZhciBwb3dlciA9IGZyb21OdW1iZXIocG93X2RibChyYWRpeCwgc2l6ZSkpOwogICAgICAgICAgICByZXN1bHQgPSByZXN1bHQubXVsKHBvd2VyKS5hZGQoZnJvbU51bWJlcih2YWx1ZSkpOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcmVzdWx0ID0gcmVzdWx0Lm11bChyYWRpeFRvUG93ZXIpOwogICAgICAgICAgICByZXN1bHQgPSByZXN1bHQuYWRkKGZyb21OdW1iZXIodmFsdWUpKTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmVzdWx0LnVuc2lnbmVkID0gdW5zaWduZWQ7CiAgICAgICAgcmV0dXJuIHJlc3VsdDsKICAgICAgfQogICAgICBMb25nNC5mcm9tU3RyaW5nID0gZnJvbVN0cmluZzsKICAgICAgZnVuY3Rpb24gZnJvbVZhbHVlKHZhbCwgdW5zaWduZWQpIHsKICAgICAgICBpZiAodHlwZW9mIHZhbCA9PT0gIm51bWJlciIpCiAgICAgICAgICByZXR1cm4gZnJvbU51bWJlcih2YWwsIHVuc2lnbmVkKTsKICAgICAgICBpZiAodHlwZW9mIHZhbCA9PT0gInN0cmluZyIpCiAgICAgICAgICByZXR1cm4gZnJvbVN0cmluZyh2YWwsIHVuc2lnbmVkKTsKICAgICAgICByZXR1cm4gZnJvbUJpdHModmFsLmxvdywgdmFsLmhpZ2gsIHR5cGVv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ByYWRpeExvbmcgPSBmcm9tTnVtYmVyKHJhZGl4KSwgZGl2ID0gdGhpcy5kaXYocmFkaXhMb25nKSwgcmVtMSA9IGRpdi5tdWwocmFkaXhMb25nKS5zdWIodGhpcyk7CiAgICAgICAgICAgIHJldHVybiBkaXYudG9TdHJpbmcocmFkaXgpICsgcmVtMS50b0ludCgpLnRvU3RyaW5nKHJhZGl4KTsKICAgICAgICAgIH0gZWxzZQogICAgICAgICAgICByZXR1cm4gIi0iICsgdGhpcy5uZWcoKS50b1N0cmluZyhyYWRpeCk7CiAgICAgICAgfQogICAgICAgIHZhciByYWRpeFRvUG93ZXIgPSBmcm9tTnVtYmVyKHBvd19kYmwocmFkaXgsIDYpLCB0aGlzLnVuc2lnbmVkKSwgcmVtID0gdGhpczsKICAgICAgICB2YXIgcmVzdWx0ID0gIiI7CiAgICAgICAgd2hpbGUgKHRydWUpIHsKICAgICAgICAgIHZhciByZW1EaXYgPSByZW0uZGl2KHJhZGl4VG9Qb3dlciksIGludHZhbCA9IHJlbS5zdWIocmVtRGl2Lm11bChyYWRpeFRvUG93ZXIpKS50b0ludCgpID4+PiAwLCBkaWdpdHMgPSBpbnR2YWwudG9TdHJpbmcocmFkaXgpOwogICAgICAgICAgcmVtID0gcmVtRGl2OwogICAgICAgICAgaWYgKHJlbS5pc1plcm8oKSkKICAgICAgICAgICAgcmV0dXJuIGRpZ2l0cyArIHJlc3VsdDsKICAgICAgICAgIGVsc2UgewogICAgICAgICAgICB3aGlsZSAoZGlnaXRzLmxlbmd0aCA8IDYpCiAgICAgICAgICAgICAgZGlnaXRzID0gIjAiICsgZGlnaXRzOwogICAgICAgICAgICByZXN1bHQgPSAiIiArIGRpZ2l0cyArIHJlc3VsdDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUuZ2V0SGlnaEJpdHMgPSBmdW5jdGlvbiBnZXRIaWdoQml0cygpIHsKICAgICAgICByZXR1cm4gdGhpcy5oaWdo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4ICY9IDY1NTM1OwogICAgICAgIHJldHVybiBmcm9tQml0cyhjMTYgPDwgMTYgfCBjMDAsIGM0OCA8PCAxNiB8IGMzMiwgdGhpcy51bnNpZ25lZCk7CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUuc3VidHJhY3QgPSBmdW5jdGlvbiBzdWJ0cmFjdChzdWJ0cmFoZW5kKSB7CiAgICAgICAgaWYgKCFpc0xvbmcoc3VidHJhaGVuZCkpCiAgICAgICAgICBzdWJ0cmFoZW5kID0gZnJvbVZhbHVlKHN1YnRyYWhlbmQpOwogICAgICAgIHJldHVybiB0aGlzLmFkZChzdWJ0cmFoZW5kLm5lZygpKTsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS5zdWIgPSBMb25nUHJvdG90eXBlLnN1YnRyYWN0OwogICAgICBMb25nUHJvdG90eXBlLm11bHRpcGx5ID0gZnVuY3Rpb24gbXVsdGlwbHkobXVsdGlwbGllcikgewogICAgICAgIGlmICh0aGlzLmlzWmVybygpKQogICAgICAgICAgcmV0dXJuIFpFUk87CiAgICAgICAgaWYgKCFpc0xvbmcobXVsdGlwbGllcikpCiAgICAgICAgICBtdWx0aXBsaWVyID0gZnJvbVZhbHVlKG11bHRpcGxpZXIpOwogICAgICAgIGlmICh3YXNtKSB7CiAgICAgICAgICB2YXIgbG93ID0gd2FzbS5tdWwodGhpcy5sb3csIHRoaXMuaGlnaCwgbXVsdGlwbGllci5sb3csIG11bHRpcGxpZXIuaGlnaCk7CiAgICAgICAgICByZXR1cm4gZnJvbUJpdHMobG93LCB3YXNtLmdldF9oaWdoKCksIHRoaXMudW5zaWduZWQpOwogICAgICAgIH0KICAgICAgICBpZiAobXVsdGlwbGllci5pc1plcm8oKSkKICAgICAgICAgIHJldHVybiBaRVJPOwogICAgICAgIGlmICh0aGlzLmVxKE1JTl9WQUxVRSkpCiAgICAgICAgICByZXR1cm4gbXVsdGlwbGllci5pc09kZCgpID8gTUlOX1ZBTFVFIDogWkVSTz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OwogICAgICAgIGlmIChkaXZpc29yLmlzWmVybygpKQogICAgICAgICAgdGhyb3cgRXJyb3IoImRpdmlzaW9uIGJ5IHplcm8iKTsKICAgICAgICBpZiAod2FzbSkgewogICAgICAgICAgaWYgKCF0aGlzLnVuc2lnbmVkICYmIHRoaXMuaGlnaCA9PT0gLTIxNDc0ODM2NDggJiYgZGl2aXNvci5sb3cgPT09IC0xICYmIGRpdmlzb3IuaGlnaCA9PT0gLTEpIHsKICAgICAgICAgICAgcmV0dXJuIHRoaXM7CiAgICAgICAgICB9CiAgICAgICAgICB2YXIgbG93ID0gKHRoaXMudW5zaWduZWQgPyB3YXNtLmRpdl91IDogd2FzbS5kaXZfcykodGhpcy5sb3csIHRoaXMuaGlnaCwgZGl2aXNvci5sb3csIGRpdmlzb3IuaGlnaCk7CiAgICAgICAgICByZXR1cm4gZnJvbUJpdHMobG93LCB3YXNtLmdldF9oaWdoKCksIHRoaXMudW5zaWduZWQpOwogICAgICAgIH0KICAgICAgICBpZiAodGhpcy5pc1plcm8oKSkKICAgICAgICAgIHJldHVybiB0aGlzLnVuc2lnbmVkID8gVVpFUk8gOiBaRVJPOwogICAgICAgIHZhciBhcHByb3gsIHJlbSwgcmVzOwogICAgICAgIGlmICghdGhpcy51bnNpZ25lZCkgewogICAgICAgICAgaWYgKHRoaXMuZXEoTUlOX1ZBTFVFKSkgewogICAgICAgICAgICBpZiAoZGl2aXNvci5lcShPTkUpIHx8IGRpdmlzb3IuZXEoTkVHX09ORSkpCiAgICAgICAgICAgICAgcmV0dXJuIE1JTl9WQUxVRTsKICAgICAgICAgICAgZWxzZSBpZiAoZGl2aXNvci5lcShNSU5fVkFMVUUpKQogICAgICAgICAgICAgIHJldHVybiBPTkU7CiAgICAgICAgICAgIGVsc2UgewogICAgICAgICAgICAgIHZhciBoYWxmVGhpcyA9IHRoaXMuc2hyKDEpOwogICAgICAgICAgICAgIGFwcHJveCA9IGhhbGZUaGlzLmRpdihkaXZpc29yKS5zaGwoMSk7CiAgICAgICAgICAgICAgaWYgKGFwcHJveC5lcShaRVJPKSkgewogICAgICAgICAgICAgICAgcmV0dXJuIGRpdmlzb3IuaXNOZWdhdGl2ZSgpID8gT05FIDogTkVHX09ORTsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgcmVtID0gdGhpcy5zdWIoZGl2aXNvci5tdWwoYXBwcm94KSk7CiAgICAgICAgICAgICAgICByZXMgPSBhcHByb3guYWRkKHJlbS5kaXYoZGl2aXNvcikpOwogICAgICAgICAgICAgICAgcmV0dXJuIHJlczsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSBpZiAoZGl2aXNvci5lcShNSU5fVkFMVUUpKQogICAgICAgICAgICByZXR1cm4gdGhpcy51bnNpZ25lZCA/IFVaRVJPIDogWkVSTzsKICAgICAgICAgIGlmICh0aGlzLmlzTmVnYXRpdmUoKSkgewogICAgICAgICAgICBpZiAoZGl2aXNvci5pc05lZ2F0aXZlKCkpCiAgICAgICAgICAgICAgcmV0dXJuIHRoaXMubmVnKCkuZGl2KGRpdmlzb3IubmVnKCkpOwogICAgICAgICAgICByZXR1cm4gdGhpcy5uZWcoKS5kaXYoZGl2aXNvcikubmVnKCk7CiAgICAgICAgICB9IGVsc2UgaWYgKGRpdmlzb3IuaXNOZWdhdGl2ZSgpKQogICAgICAgICAgICByZXR1cm4gdGhpcy5kaXYoZGl2aXNvci5uZWcoKSkubmVnKCk7CiAgICAgICAgICByZXMgPSBaRVJPOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBpZiAoIWRpdmlzb3IudW5zaWduZWQpCiAgICAgICAgICAgIGRpdmlzb3IgPSBkaXZpc29yLnRvVW5zaWduZWQoKTsKICAgICAgICAgIGlmIChkaXZpc29yLmd0KHRoaXMpKQogICAgICAgICAgICByZXR1cm4gVVpFUk87CiAgICAgICAgICBpZiAoZGl2aXNvci5ndCh0aGlzLnNocnUoMSkpKQogICAgICAgICAgICByZXR1cm4gVU9ORTsKICAgICAgICAgIHJlcyA9IFVaRVJPOwogICAgICAgIH0KICAgICAgICByZW0gPSB0aGlzOwogICAgICAgIHdoaWxlIChyZW0uZ3RlKGRpdmlzb3IpKSB7CiAgICAgICAgICBhcHByb3ggPSBNYXRoLm1heCgxLCBNYXRoLmZsb29yKHJlbS50b051bWJlcigpIC8gZGl2aXNvci50b051bWJlcigpKSk7CiAgICAgICAgICB2YXIgbG9nMiA9IE1hdGguY2VpbChNYXRoLmxvZyhhcHByb3gpIC8gTWF0aC5MTjIpLCBkZWx0YSA9IGxvZzIgPD0gNDggPyAxIDogcG93X2RibCgyLCBsb2cyIC0gNDgpLCBhcHByb3hSZXMgPSBmcm9tTnVtYmVyKGFwcHJveCksIGFwcHJveFJlbSA9IGFwcHJveFJlcy5tdWwoZGl2aXNvcik7CiAgICAgICAgICB3aGlsZSAoYXBwcm94UmVtLmlzTmVnYXRpdmUoKSB8fCBhcHByb3hSZW0uZ3QocmVtKSkgewogICAgICAgICAgICBhcHByb3ggLT0gZGVsdGE7CiAgICAgICAgICAgIGFwcHJveFJlcyA9IGZyb21OdW1iZXIoYXBwcm94LCB0aGlzLnVuc2lnbmVkKTsKICAgICAgICAgICAgYXBwcm94UmVtID0gYXBwcm94UmVzLm11bChkaXZpc29yKTsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChhcHByb3hSZXMuaXNaZXJvKCkpCiAgICAgICAgICAgIGFwcHJveFJlcyA9IE9ORTsKICAgICAgICAgIHJlcyA9IHJlcy5hZGQoYXBwcm94UmVzKTsKICAgICAgICAgIHJlbSA9IHJlbS5zdWIoYXBwcm94UmVtKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHJlczsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS5kaXYgPSBMb25nUHJvdG90eXBlLmRpdmlkZTsKICAgICAgTG9uZ1Byb3RvdHlwZS5tb2R1bG8gPSBmdW5jdGlvbiBtb2R1bG8oZGl2aXNvcikgewogICAgICAgIGlmICghaXNMb25nKGRpdmlzb3IpKQogICAgICAgICAgZGl2aXNvciA9IGZyb21WYWx1ZShkaXZpc29yKTsKICAgICAgICBpZiAod2FzbSkgewogICAgICAgICAgdmFyIGxvdyA9ICh0aGlzLnVuc2lnbmVkID8gd2FzbS5yZW1fdSA6IHdhc20ucmVtX3MpKHRoaXMubG93LCB0aGlzLmhpZ2gsIGRpdmlzb3IubG93LCBkaXZpc29yLmhpZ2gpOwogICAgICAgICAgcmV0dXJuIGZyb21CaXRzKGxvdywgd2FzbS5nZXRfaGlnaCgpLCB0aGlzLnVuc2lnbmVkKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHRoaXMuc3ViKHRoaXMuZGl2KGRpdmlzb3IpLm11bChkaXZpc29yKSk7CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUubW9kID0gTG9uZ1Byb3RvdHlwZS5tb2R1bG87CiAgICAgIExvbmdQcm90b3R5cGUucmVtID0gTG9uZ1Byb3RvdHlwZS5tb2R1bG87CiAgICAgIExvbmdQcm90b3R5cGUubm90ID0gZnVuY3Rpb24gbm90KCkgewogICAgICAgIHJldHVybiBmcm9tQml0cyh+dGhpcy5sb3csIH50aGlzLmhpZ2gsIHRoaXMudW5zaWduZWQpOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLmFuZCA9IGZ1bmN0aW9uIGFuZChvdGhlcikgewogICAgICAgIGlmICghaXNMb25nKG90aGVyKSkKICAgICAgICAgIG90aGVyID0gZnJvbVZhbHVlKG90aGVyKTsKICAgICAgICByZXR1cm4gZnJvbUJpdHModGhpcy5sb3cgJiBvdGhlci5sb3csIHRoaXMuaGlnaCAmIG90aGVyLmhpZ2gsIHRoaXMudW5zaWduZWQpOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLm9yID0gZnVuY3Rpb24gb3Iob3RoZXIpIHsKICAgICAgICBpZiAoIWlzTG9uZyhvdGhlcikpCiAgICAgICAgICBvdGhlciA9IGZyb21WYWx1Z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1CaXRzKSB7CiAgICAgICAgaWYgKGlzTG9uZyhudW1CaXRzKSkKICAgICAgICAgIG51bUJpdHMgPSBudW1CaXRzLnRvSW50KCk7CiAgICAgICAgaWYgKChudW1CaXRzICY9IDYzKSA9PT0gMCkKICAgICAgICAgIHJldHVybiB0aGlzOwogICAgICAgIGVsc2UgaWYgKG51bUJpdHMgPCAzMikKICAgICAgICAgIHJldHVybiBmcm9tQml0cyh0aGlzLmxvdyA+Pj4gbnVtQml0cyB8IHRoaXMuaGlnaCA8PCAzMiAtIG51bUJpdHMsIHRoaXMuaGlnaCA+PiBudW1CaXRzLCB0aGlzLnVuc2lnbmVkKTsKICAgICAgICBlbHNlCiAgICAgICAgICByZXR1cm4gZnJvbUJpdHModGhpcy5oaWdoID4+IG51bUJpdHMgLSAzMiwgdGhpcy5oaWdoID49IDAgPyAwIDogLTEsIHRoaXMudW5zaWduZWQpOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLnNociA9IExvbmdQcm90b3R5cGUuc2hpZnRSaWdodDsKICAgICAgTG9uZ1Byb3RvdHlwZS5zaGlmdFJpZ2h0VW5zaWduZWQgPSBmdW5jdGlvbiBzaGlmdFJpZ2h0VW5zaWduZWQobnVtQml0cykgewogICAgICAgIGlmIChpc0xvbmcobnVtQml0cykpCiAgICAgICAgICBudW1CaXRzID0gbnVtQml0cy50b0ludCgpOwogICAgICAgIG51bUJpdHMgJj0gNjM7CiAgICAgICAgaWYgKG51bUJpdHMgPT09IDApCiAgICAgICAgICByZXR1cm4gdGhpczsKICAgICAgICBlbHNlIHsKICAgICAgICAgIHZhciBoaWdoID0gdGhpcy5oaWdoOwogICAgICAgICAgaWYgKG51bUJpdHMgPCAzMikgewogICAgICAgICAgICB2YXIgbG93ID0gdGhpcy5sb3c7CiAgICAgICAgICAgIHJldHVybiBmcm9tQml0cyhsb3cgPj4+IG51bUJpdHMgfCBoaWdoIDw8IDMyIC0gbnVtQml0cywgaGlnaCA+Pj4gbnVtQml0cywgdGhp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oKSB7CiAgICAgICAgdmFyIGhpID0gdGhpcy5oaWdoLCBsbyA9IHRoaXMubG93OwogICAgICAgIHJldHVybiBbCiAgICAgICAgICBsbyAmIDI1NSwKICAgICAgICAgIGxvID4+PiA4ICYgMjU1LAogICAgICAgICAgbG8gPj4+IDE2ICYgMjU1LAogICAgICAgICAgbG8gPj4+IDI0LAogICAgICAgICAgaGkgJiAyNTUsCiAgICAgICAgICBoaSA+Pj4gOCAmIDI1NSwKICAgICAgICAgIGhpID4+PiAxNiAmIDI1NSwKICAgICAgICAgIGhpID4+PiAyNAogICAgICAgIF07CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUudG9CeXRlc0JFID0gZnVuY3Rpb24gdG9CeXRlc0JFKCkgewogICAgICAgIHZhciBoaSA9IHRoaXMuaGlnaCwgbG8gPSB0aGlzLmxvdzsKICAgICAgICByZXR1cm4gWwogICAgICAgICAgaGkgPj4+IDI0LAogICAgICAgICAgaGkgPj4+IDE2ICYgMjU1LAogICAgICAgICAgaGkgPj4+IDggJiAyNTUsCiAgICAgICAgICBoaSAmIDI1NSwKICAgICAgICAgIGxvID4+PiAyNCwKICAgICAgICAgIGxvID4+PiAxNiAmIDI1NSwKICAgICAgICAgIGxvID4+PiA4ICYgMjU1LAogICAgICAgICAgbG8gJiAyNTUKICAgICAgICBdOwogICAgICB9OwogICAgICBMb25nNC5mcm9tQnl0ZXMgPSBmdW5jdGlvbiBmcm9tQnl0ZXMyKGJ5dGVzLCB1bnNpZ25lZCwgbGUpIHsKICAgICAgICByZXR1cm4gbGUgPyBMb25nNC5mcm9tQnl0ZXNMRShieXRlcywgdW5zaWduZWQpIDogTG9uZzQuZnJvbUJ5dGVzQkUoYnl0ZXMsIHVuc2lnbmVkKTsKICAgICAgfTsKICAgICAgTG9uZzQuZnJvbUJ5dGVzTEUgPSBmdW5jdGlvbiBmcm9tQnl0ZXNMRShieXRlcywgdW5zaWduZWQpIHsKICAgICAgICByZXR1cm4gbmV3IExvbmc0KGJ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WxpemVyID0gZXh0ZW5kLnNlcmlhbGl6ZS5iaW5kKGV4dGVuZCk7CiAgICAgICAgcmV0dXJuIHsKICAgICAgICAgIGRlc2VyaWFsaXplKG1lc3NhZ2UpIHsKICAgICAgICAgICAgcmV0dXJuIGltcGxlbWVudGF0aW9uLmRlc2VyaWFsaXplKG1lc3NhZ2UsIGZhbGxiYWNrRGVzZXJpYWxpemVyKTsKICAgICAgICAgIH0sCiAgICAgICAgICBzZXJpYWxpemUoaW5wdXQpIHsKICAgICAgICAgICAgcmV0dXJuIGltcGxlbWVudGF0aW9uLnNlcmlhbGl6ZShpbnB1dCwgZmFsbGJhY2tTZXJpYWxpemVyKTsKICAgICAgICAgIH0KICAgICAgICB9OwogICAgICB9CiAgICAgIGV4cG9ydHMyLmV4dGVuZFNlcmlhbGl6ZXIgPSBleHRlbmRTZXJpYWxpemVyOwogICAgICB2YXIgRGVmYXVsdEVycm9yU2VyaWFsaXplciA9IHsKICAgICAgICBkZXNlcmlhbGl6ZShtZXNzYWdlKSB7CiAgICAgICAgICByZXR1cm4gT2JqZWN0LmFzc2lnbihFcnJvcihtZXNzYWdlLm1lc3NhZ2UpLCB7CiAgICAgICAgICAgIG5hbWU6IG1lc3NhZ2UubmFtZSwKICAgICAgICAgICAgc3RhY2s6IG1lc3NhZ2Uuc3RhY2sKICAgICAgICAgIH0pOwogICAgICAgIH0sCiAgICAgICAgc2VyaWFsaXplKGVycm9yKSB7CiAgICAgICAgICByZXR1cm4gewogICAgICAgICAgICBfX2Vycm9yX21hcmtlcjogIiQkZXJyb3IiLAogICAgICAgICAgICBtZXNzYWdlOiBlcnJvci5tZXNzYWdlLAogICAgICAgICAgICBuYW1lOiBlcnJvci5uYW1lLAogICAgICAgICAgICBzdGFjazogZXJyb3Iuc3RhY2sKICAgICAgICAgIH07CiAgICAgICAgfQogICAgICB9OwogICAgICB2YXIgaXNTZXJpYWxpemVkRXJyb3IgPSAodGhpbmcpID0+IHRoaW5nICYmIHR5cGVvZiB0aGluZyA9PT0gIm9iamVjdCIgJiYgIl9fZXJyb3JfbWFya2VyIiBpbiB0aGluZyAmJiB0aGluZy5fX2Vycm9yX21hcmtlciA9PT0gIiQkZXJyb3IiOwogICAgICBleHBvcnRzMi5EZWZhdWx0U2VyaWFsaXplciA9IHsKICAgICAgICBkZXNlcmlhbGl6ZShtZXNzYWdlKSB7CiAgICAgICAgICBpZiAoaXNTZXJpYWxpemVkRXJyb3IobWVzc2FnZSkpIHsKICAgICAgICAgICAgcmV0dXJuIERlZmF1bHRFcnJvclNlcmlhbGl6ZXIuZGVzZXJpYWxpemUobWVzc2FnZSk7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICByZXR1cm4gbWVzc2FnZTsKICAgICAgICAgIH0KICAgICAgICB9LAogICAgICAgIHNlcmlhbGl6ZShpbnB1dCkgewogICAgICAgICAgaWYgKGlucHV0IGluc3RhbmNlb2YgRXJyb3IpIHsKICAgICAgICAgICAgcmV0dXJuIERlZmF1bHRFcnJvclNlcmlhbGl6ZXIuc2VyaWFsaXplKGlucHV0KTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHJldHVybiBpbnB1dDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH07CiAgICB9CiAgfSk7CgogIC8vIG5vZGVfbW9kdWxlcy8ucG5wbS90aHJlYWRzQDEuNy4wL25vZGVfbW9kdWxlcy90aHJlYWRzL2Rpc3QvY29tbW9uLmpzCiAgdmFyIHJlcXVpcmVfY29tbW9uMiA9IF9fY29tbW9uSlMoewogICAgIm5vZGVfbW9kdWxlcy8ucG5wbS90aHJlYWRzQDEuNy4wL25vZGVfbW9kdWxlcy90aHJlYWRzL2Rpc3QvY29tbW9uLmpzIihleHBvcnRzMikgewogICAgICBpbml0X2J1ZmZlcl9zaGltKCk7CiAgICAgICJ1c2Ugc3RyaWN0IjsKICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KGV4cG9ydHMyLCAiX19lc01vZHVsZSIsIHsgd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9uXzEuc2VyaWFsaXplKHZhbHVlKSksIChlcnJvcikgPT4gewogICAgICAgICAgICAgIHBvc3RKb2JFcnJvck1lc3NhZ2Uoam9iVUlELCBjb21tb25fMS5zZXJpYWxpemUoZXJyb3IpKTsKICAgICAgICAgICAgICBhY3RpdmVTdWJzY3JpcHRpb25zLmRlbGV0ZShqb2JVSUQpOwogICAgICAgICAgICB9LCAoKSA9PiB7CiAgICAgICAgICAgICAgcG9zdEpvYlJlc3VsdE1lc3NhZ2Uoam9iVUlELCB0cnVlKTsKICAgICAgICAgICAgICBhY3RpdmVTdWJzY3JpcHRpb25zLmRlbGV0ZShqb2JVSUQpOwogICAgICAgICAgICB9KTsKICAgICAgICAgICAgYWN0aXZlU3Vic2NyaXB0aW9ucy5zZXQoam9iVUlELCBzdWJzY3JpcHRpb24pOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICBjb25zdCByZXN1bHQgPSB5aWVsZCBzeW5jUmVzdWx0OwogICAgICAgICAgICAgIHBvc3RKb2JSZXN1bHRNZXNzYWdlKGpvYlVJRCwgdHJ1ZSwgY29tbW9uXzEuc2VyaWFsaXplKHJlc3VsdCkpOwogICAgICAgICAgICB9IGNhdGNoIChlcnJvcikgewogICAgICAgICAgICAgIHBvc3RKb2JFcnJvck1lc3NhZ2Uoam9iVUlELCBjb21tb25fMS5zZXJpYWxpemUoZXJyb3IpKTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0pOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGV4cG9zZTIoZXhwb3NlZCkgewogICAgICAgIGlmICghaW1wbGVtZW50YXRpb25fMS5kZWZhdWx0LmlzV29ya2VyUnVudGltZSgpKSB7CiAgICAgICAgICB0aHJvdyBFcnJvcigiZXhwb3NlKCkgY2FsbGVkIGluIHRoZSBtYXN0ZXIgdGhyZWFkLiIpOwogICAgICAgIH0KICAgICAgICBpZiAoZXhwb3NlQ2FsbGVkKSB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lZFttZXNzYWdlRGF0YS5tZXRob2RdLCBtZXNzYWdlRGF0YS5hcmdzLm1hcChjb21tb25fMS5kZXNlcmlhbGl6ZSkpOwogICAgICAgICAgICB9CiAgICAgICAgICB9KTsKICAgICAgICAgIGNvbnN0IG1ldGhvZE5hbWVzID0gT2JqZWN0LmtleXMoZXhwb3NlZCkuZmlsdGVyKChrZXkpID0+IHR5cGVvZiBleHBvc2VkW2tleV0gPT09ICJmdW5jdGlvbiIpOwogICAgICAgICAgcG9zdE1vZHVsZUluaXRNZXNzYWdlKG1ldGhvZE5hbWVzKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgdGhyb3cgRXJyb3IoYEludmFsaWQgYXJndW1lbnQgcGFzc2VkIHRvIGV4cG9zZSgpLiBFeHBlY3RlZCBhIGZ1bmN0aW9uIG9yIGFuIG9iamVjdCwgZ290OiAke2V4cG9zZWR9YCk7CiAgICAgICAgfQogICAgICAgIGltcGxlbWVudGF0aW9uXzEuZGVmYXVsdC5zdWJzY3JpYmVUb01hc3Rlck1lc3NhZ2VzKChtZXNzYWdlRGF0YSkgPT4gewogICAgICAgICAgaWYgKGlzTWFzdGVySm9iQ2FuY2VsTWVzc2FnZShtZXNzYWdlRGF0YSkpIHsKICAgICAgICAgICAgY29uc3Qgam9iVUlEID0gbWVzc2FnZURhdGEudWlkOwogICAgICAgICAgICBjb25zdCBzdWJzY3JpcHRpb24gPSBhY3RpdmVTdWJzY3JpcHRpb25zLmdldChqb2JVSUQpOwogICAgICAgICAgICBpZiAoc3Vic2NyaXB0aW9uKSB7CiAgICAgICAgICAgICAgc3Vic2NyaXB0aW9uLnVuc3Vic2NyaWJlKCk7CiAgICAgICAgICAgICAgYWN0aXZlU3Vic2NyaXB0aW9ucy5kZWxldGUoam9iVUlEKTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0pOwogICAgICB9CiAgICAgIGV4cG9ydHMyLmV4cG9zZSA9IGV4cG9zZTI7CiAgICAgIGlmICh0eXB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dGlvbi5pbnZlcnRlZCA/ICJeIiA6ICIiKSArIGVzY2FwZWRQYXJ0cyArICJdIjsKICAgICAgICAgIH0sCiAgICAgICAgICBhbnk6IGZ1bmN0aW9uKGV4cGVjdGF0aW9uKSB7CiAgICAgICAgICAgIHJldHVybiAiYW55IGNoYXJhY3RlciI7CiAgICAgICAgICB9LAogICAgICAgICAgZW5kOiBmdW5jdGlvbihleHBlY3RhdGlvbikgewogICAgICAgICAgICByZXR1cm4gImVuZCBvZiBpbnB1dCI7CiAgICAgICAgICB9LAogICAgICAgICAgb3RoZXI6IGZ1bmN0aW9uKGV4cGVjdGF0aW9uKSB7CiAgICAgICAgICAgIHJldHVybiBleHBlY3RhdGlvbi5kZXNjcmlwdGlvbjsKICAgICAgICAgIH0KICAgICAgICB9OwogICAgICAgIGZ1bmN0aW9uIGhleChjaCkgewogICAgICAgICAgcmV0dXJuIGNoLmNoYXJDb2RlQXQoMCkudG9TdHJpbmcoMTYpLnRvVXBwZXJDYXNlKCk7CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIGxpdGVyYWxFc2NhcGUocykgewogICAgICAgICAgcmV0dXJuIHMucmVwbGFjZSgvXFwvZywgIlxcXFwiKS5yZXBsYWNlKC8iL2csICdcXCInKS5yZXBsYWNlKC9cMC9nLCAiXFwwIikucmVwbGFjZSgvXHQvZywgIlxcdCIpLnJlcGxhY2UoL1xuL2csICJcXG4iKS5yZXBsYWNlKC9cci9nLCAiXFxyIikucmVwbGFjZSgvW1x4MDAtXHgwRl0vZywgZnVuY3Rpb24oY2gpIHsKICAgICAgICAgICAgcmV0dXJuICJcXHgwIiArIGhleChjaCk7CiAgICAgICAgICB9KS5yZXBsYWNlKC9bXHgxMC1ceDFGXHg3Ri1ceDlGXS9nLCBmdW5jdGlvbihjaCkgewogICAgICAgICAgICByZXR1cm4gIlxceCIgKyBoZXgoY2gpOwogICAgICAgICAgfSk7CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIGNsYXNzRXNjYXBlKHMpIHsKICAgICAgICAgIHJldHVybiBzLnJlcGxhY2UoL1xcL2csICJcXFxcIikucmVwbGFjZSgvXF0vZywgIlxcXSIpLnJlcGxhY2UoL1xeL2csICJcXF4iKS5yZXBsYWNlKC8tL2csICJcXC0iKS5yZXBsYWNlKC9cMC9nLCAiXFwwIikucmVwbGFjZSgvXHQvZywgIlxcdCIpLnJlcGxhY2UoL1xuL2csICJcXG4iKS5yZXBsYWNlKC9cci9nLCAiXFxyIikucmVwbGFjZSgvW1x4MDAtXHgwRl0vZywgZnVuY3Rpb24oY2gpIHsKICAgICAgICAgICAgcmV0dXJuICJcXHgwIiArIGhleChjaCk7CiAgICAgICAgICB9KS5yZXBsYWNlKC9bXHgxMC1ceDFGXHg3Ri1ceDlGXS9nLCBmdW5jdGlvbihjaCkgewogICAgICAgICAgICByZXR1cm4gIlxceCIgKyBoZXgoY2gpOwogICAgICAgICAgfSk7CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIGRlc2NyaWJlRXhwZWN0YXRpb24oZXhwZWN0YXRpb24pIHsKICAgICAgICAgIHJldHVybiBERVNDUklCRV9FWFBFQ1RBVElPTl9GTlNbZXhwZWN0YXRpb24udHlwZV0oZXhwZWN0YXRpb24pOwogICAgICAgIH0KICAgICAgICBmdW5jdGlvbiBkZXNjcmliZUV4cGVjdGVkKGV4cGVjdGVkMikgewogICAgICAgICAgdmFyIGRlc2NyaXB0aW9ucyA9IG5ldyBBcnJheShleHBlY3RlZDIubGVuZ3RoKSwgaSwgajsKICAgICAgICAgIGZvciAoaSA9IDA7IGkgPCBleHBlY3RlZDIubGVuZ3RoOyBpKyspIHsKICAgICAgICAgICAgZGVzY3JpcHRpb25zW2ldID0gZGVzY3JpYmVFeHBlY3RhdGlvbihleHBlY3RlZDJbaV0pOwogICAgICAgICAgfQogICAgICAgICAgZGVzY3JpcHRpb25zLnNvcnQoKTsKICAgICAgICAgIGlmIChkZXNjcmlwdGlvbnMubGVuZ3RoID4gMCkgewogICAgICAgICAgICBmb3IgKGkgPSAxLCBqID0gMTsgaSA8IGRlc2NyaXB0aW9ucy5sZW5ndGg7IGkrKykgewogICAgICAgICAgICAgIGlmIChkZXNjcmlwdGlvbnNbaSAtIDFdICE9PSBkZXNjcmlwdGlvbnNbaV0pIHsKICAgICAgICAgICAgICAgIGRlc2NyaXB0aW9uc1tqXSA9IGRlc2NyaXB0aW9uc1tpXTsKICAgICAgICAgICAgICAgIGorKzsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZGVzY3JpcHRpb25zLmxlbmd0aCA9IGo7CiAgICAgICAgICB9CiAgICAgICAgICBzd2l0Y2ggKGRlc2NyaXB0aW9ucy5sZW5ndGgpIHsKICAgICAgICAgICAgY2FzZSAxOgogICAgICAgICAgICAgIHJldHVybiBkZXNjcmlwdGlvbnNbMF07CiAgICAgICAgICAgIGNhc2UgMjoKICAgICAgICAgICAgICByZXR1cm4gZGVzY3JpcHRpb25zWzBdICsgIiBvciAiICsgZGVzY3JpcHRpb25zWzFdOwogICAgICAgICAgICBkZWZhdWx0OgogICAgICAgICAgICAgIHJldHVybiBkZXNjcmlwdGlvbnMuc2xpY2UoMCwgLTEpLmpvaW4oIiwgIikgKyAiLCBvciAiICsgZGVzY3JpcHRpb25zW2Rlc2NyaXB0aW9ucy5sZW5ndGggLSAxXTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZnVuY3Rpb24gZGVzY3JpYmVGb3VuZChmb3VuZDIpIHsKICAgICAgICAgIHJldHVybiBmb3VuZDIgPyAnIicgKyBsaXRlcmFsRXNjYXBlKGZvdW5kMikgKyAnIicgOiAiZW5kIG9mIGlucHV0IjsKICAgICAgICB9CiAgICAgICAgcmV0dXJuICJFeHBlY3RlZCAiICsgZGVzY3JpYmVFeHBlY3RlZChleHBlY3RlZCkgKyAiIGJ1dCAiICsgZGVzY3JpYmVGb3VuZChmb3VuZCkgKyAiIGZvdW5kLiI7CiAgICAgIH07CiAgICAgI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gIHJldHVybiBkZXRhaWxzOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcCA9IHBvcyAtIDE7CiAgICAgICAgICAgIHdoaWxlICghcGVnJHBvc0RldGFpbHNDYWNoZVtwXSkgewogICAgICAgICAgICAgIHAtLTsKICAgICAgICAgICAgfQogICAgICAgICAgICBkZXRhaWxzID0gcGVnJHBvc0RldGFpbHNDYWNoZVtwXTsKICAgICAgICAgICAgZGV0YWlscyA9IHsKICAgICAgICAgICAgICBsaW5lOiBkZXRhaWxzLmxpbmUsCiAgICAgICAgICAgICAgY29sdW1uOiBkZXRhaWxzLmNvbHVtbgogICAgICAgICAgICB9OwogICAgICAgICAgICB3aGlsZSAocCA8IHBvcykgewogICAgICAgICAgICAgIGlmIChpbnB1dC5jaGFyQ29kZUF0KHApID09PSAxMCkgewogICAgICAgICAgICAgICAgZGV0YWlscy5saW5lKys7CiAgICAgICAgICAgICAgICBkZXRhaWxzLmNvbHVtbiA9IDE7CiAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIGRldGFpbHMuY29sdW1uKys7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIHArKzsKICAgICAgICAgICAgfQogICAgICAgICAgICBwZWckcG9zRGV0YWlsc0NhY2hlW3Bvc10gPSBkZXRhaWxzOwogICAgICAgICAgICByZXR1cm4gZGV0YWlsczsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZnVuY3Rpb24gcGVnJGNvbXB1dGVMb2NhdGlvbihzdGFydFBvcywgZW5kUG9zKSB7CiAgICAgICAgICB2YXIgc3RhcnRQb3NEZXRhaWxzID0gcGVnJGNvbXB1dGVQb3NEZXRhaWxzKHN0YXJ0UG9zKSwgZW5kUG9zRGV0YWlscyA9IHBlZyRjb21wdXRlUG9zRGV0YWlscyhlbmRQb3MpOwogICAgICAgICAgcmV0dXJuIHsKICAgICAgICAgICAgc3RhcnQ6IHsKICAgICAgICAgICAgICBvZmZzZXQ6IHN0YXJ0UG9zLAogICAgICAgICAgICAgIGxpbmU6IHN0YXJ0UG9zRGV0YWlscy5saW5lLAogICAgICAgICAgICAgIGNvbHVtbjogc3RhcnRQb3NEZXRhaWxzLmNvbHVtbgogICAgICAgICAgICB9LAogICAgICAgICAgICBlbmQ6IHsKICAgICAgICAgICAgICBvZmZzZXQ6IGVuZFBvcywKICAgICAgICAgICAgICBsaW5lOiBlbmRQb3NEZXRhaWxzLmxpbmUsCiAgICAgICAgICAgICAgY29sdW1uOiBlbmRQb3NEZXRhaWxzLmNvbHVtbgogICAgICAgICAgICB9CiAgICAgICAgICB9OwogICAgICAgIH0KICAgICAgICBmdW5jdGlvbiBwZWckZmFpbChleHBlY3RlZDIpIHsKICAgICAgICAgIGlmIChwZWckY3VyclBvcyA8IHBlZyRtYXhGYWlsUG9zKSB7CiAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChwZWckY3VyclBvcyA+IHBlZyRtYXhGYWlsUG9zKSB7CiAgICAgICAgICAgIHBlZyRtYXhGYWlsUG9zID0gcGVnJGN1cnJQb3M7CiAgICAgICAgICAgIHBlZyRtYXhGYWlsRXhwZWN0ZWQgPSBbXTsKICAgICAgICAgIH0KICAgICAgICAgIHBlZyRtYXhGYWlsRXhwZWN0ZWQucHVzaChleHBlY3RlZDIpOwogICAgICAgIH0KICAgICAgICBmdW5jdGlvbiBwZWckYnVpbGRTaW1wbGVFcnJvcihtZXNzYWdlLCBsb2NhdGlvbjIpIHsKICAgICAgICAgIHJldHVybiBuZXcgcGVnJFN5bnRheEVycm9yKG1lc3NhZ2UsIG51bGwsIG51bGwsIGxvY2F0aW9uMik7CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIHBlZyRidWlsZFN0cnVjdHVyZWRFcnJvcihleHBlY3RlZDIsIGZvdW5kLCBsb2NhdGlvbjIpIHsKICAgICAgICAgIHJldHVybiBuZXcgcGVnJFN5bnRheEVycm9yKHBlZyRTeW50YXhFcnJvci5idWlsZE1lc3NhZ2UoZXhwZWN0ZWQyLCBmb3VuZCksIGV4cGVjdGVkMiwgZm91bmQsIGxvY2F0aW9uMik7CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIHBlZyRwYXJzZWRlY2xhcmF0aW9uKCkgewogICAgICAgICAgdmFyIHMwLCBzMSwgczIsIHMzLCBzNCwgczUsIHM2LCBzNywgczgsIHM5LCBzMTAsIHMxMSwgczEyLCBzMTM7CiAgICAgICAgICBzMCA9IHBlZyRjdXJyUG9zOwogICAgICAgICAgczEgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICBpZiAoczEgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgczIgPSBwZWckcGFyc2VkZWNsYXJlVHlwZSgpOwogICAgICAgICAgICBpZiAoczIgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICBzMyA9IHBlZyRwYXJzZV8oKTsKICAgICAgICAgICAgICBpZiAoczMgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgIHM0ID0gcGVnJHBhcnNlZGVjbGFyZU5hbWUoKTsKICAgICAgICAgICAgICAgIGlmIChzNCAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICBzNSA9IHBlZyRwYXJzZV8oKTsKICAgICAgICAgICAgICAgICAgaWYgKHM1ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgczYgPSBwZWckcGFyc2Vjb21tZW50KCk7CiAgICAgICAgICAgICAgICAgICAgaWYgKHM2ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgICBzNyA9IHBlZyRwYXJzZV8oKTsKICAgICAgICAgICAgICAgICAgICAgIGlmIChzNyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICBpZiAoaW5wdXQuY2hhckNvZGVBdChwZWckY3VyclBvcykgPT09IDQwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgczggPSBwZWckYzA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICBzOCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGMxKTsKICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHM4ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgczkgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHM5ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMTAgPSBwZWckcGFyc2VmaWVsZExpc3QoKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzMTAgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczExID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoczExICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGlucHV0LmNoYXJDb2RlQXQocGVnJGN1cnJQb3MpID09PSA0MSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczEyID0gcGVnJGMyOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczEyID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGMzKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHMxMiAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczEzID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHMxMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwZWckc2F2ZWRQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczEgPSBwZWckYzQoczIsIHM0LCBzNiwgczEwKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczAgPSBzMTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBzMDsKICAgICAgICB9CiAgICAgICAgZnVuY3Rpb24gcGVnJHBhcnNlZGVjbGFyZVR5cGUoKSB7CiAgICAgICAgICB2YXIgczA7CiAgICAgICAgICBpZiAoaW5wdXQuc3Vic3RyKHBlZyRjdXJyUG9zLCA2KSA9PT0gcGVnJGM1KSB7CiAgICAgICAgICAgIHMwID0gcGVnJGM1OwogICAgICAgICAgICBwZWckY3VyclBvcyArPSA2OwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGM2KTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgaWYgKHMwID09PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDYpID09PSBwZWckYzcpIHsKICAgICAgICAgICAgICBzMCA9IHBlZyRjNzsKICAgICAgICAgICAgICBwZWckY3VyclBvcyArPSA2OwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzgpOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICBpZiAoaW5wdXQuc3Vic3RyKHBlZyRjdXJyUG9zLCA1KSA9PT0gcGVnJGM5KSB7CiAgICAgICAgICAgICAgICBzMCA9IHBlZyRjOTsKICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zICs9IDU7CiAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGMxMCk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gczA7CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIHBlZyRwYXJzZWRlY2xhcmVOYW1lKCkgewogICAgICAgICAgdmFyIHMwLCBzMSwgczIsIHMzOwogICAgICAgICAgczAgPSBwZWckcGFyc2VuYW1lKCk7CiAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgczAgPSBwZWckY3VyclBvczsKICAgICAgICAgICAgczEgPSBwZWckcGFyc2VuYW1lKCk7CiAgICAgICAgICAgIGlmIChzMSAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgIHMyID0gcGVnJHBhcnNlaW5kZXhUeXBlKCk7CiAgICAgICAgICAgICAgaWYgKHMyICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICBzMSA9IFtzMSwgczJdOwogICAgICAgICAgICAgICAgczAgPSBzMTsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHMwID09PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgczAgPSBwZWckY3VyclBvczsKICAgICAgICAgICAgICBzMSA9IHBlZyRwYXJzZW5hbWUoKTsKICAgICAgICAgICAgICBpZiAoczEgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDQpID09PSBwZWckYzExKSB7CiAgICAgICAgICAgICAgICAgIHMyID0gcGVnJGMxMTsKICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gNDsKICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgIHMyID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjMTIpOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoczIgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgczEgPSBbczEsIHMyXTsKICAgICAgICAgICAgICAgICAgczAgPSBzMTsKICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgaWYgKHMwID09PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICBzMCA9IHBlZyRjdXJyUG9zOwogICAgICAgICAgICAgICAgczEgPSBwZWckcGFyc2VuYW1lKCk7CiAgICAgICAgICAgICAgICBpZiAoczEgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgczIgPSBwZWckcGFyc2VpbmRleFR5cGUoKTsKICAgICAgICAgICAgICAgICAgaWYgKHMyICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgaWYgKGlucHV0LnN1YnN0cihwZWckY3VyclBvcywgNCkgPT09IHBlZyRjMTEpIHsKICAgICAgICAgICAgICAgICAgICAgIHMzID0gcGVnJGMxMTsKICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zICs9IDQ7CiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgIHMzID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGMxMik7CiAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGlmIChzMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgczEgPSBbczEsIHMyLCBzM107CiAgICAgICAgICAgICAgICAgICAgICBzMCA9IHMxOwogICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMwOwogICAgICAgICAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMwOwogICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIHMwOwogICAgICAgIH0KICAgICAgICBmdW5jdGlvbiBwZWckcGFyc2VpbmRleFR5cGUoKSB7CiAgICAgICAgICB2YXIgczA7CiAgICAgICAgICBpZiAoaW5wdXQuc3Vic3RyKHBlZyRjdXJyUG9zLCA3KSA9PT0gcGVnJGMxMykgewogICAgICAgICAgICBzMCA9IHBlZyRjMTM7CiAgICAgICAgICAgIHBlZyRjdXJyUG9zICs9IDc7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzE0KTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgaWYgKHMwID09PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDUpID09PSBwZWckYzE1KSB7CiAgICAgICAgICAgICAgczAgPSBwZWckYzE1OwogICAgICAgICAgICAgIHBlZyRjdXJyUG9zICs9IDU7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjMTYpOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICBpZiAoaW5wdXQuc3Vic3RyKHBlZyRjdXJyUG9zLCA2KSA9PT0gcGVnJGMxNykgewogICAgICAgICAgICAgICAgczAgPSBwZWckYzE3OwogICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gNjsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzE4KTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBzMDsKICAgICAgICB9CiAgICAgICAgZnVuY3Rpb24gcGVnJHBhcnNlY29tbWVudCgpIHsKICAgICAgICAgIHZhciBzMDsKICAgICAgICAgIHMwID0gcGVnJHBhcnNlbm9uUXVvdGVkU3RyaW5nKCk7CiAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgczAgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gczA7CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIHBlZyRwYXJzZWZpZWxkTGlzdCgpIHsKICAgICAgICAgIHZhciBzMCwgczEsIHMyLCBzMywgczQsIHM1LCBzNjsKICAgICAgICAgIHMwID0gcGVnJGN1cnJQb3M7CiAgICAgICAgICBzMSA9IHBlZyRwYXJzZWZpZWxkKCk7CiAgICAgICAgICBpZiAoczEgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgczIgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICAgIGlmIChzMiAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgIHMzID0gW107CiAgICAgICAgICAgICAgczQgPSBwZWckY3VyclBvczsKICAgICAgICAgICAgICBzNSA9IHBlZyRwYXJzZV8oKTsKICAgICAgICAgICAgICBpZiAoczUgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgIHM2ID0gcGVnJHBhcnNlZmllbGQoKTsKICAgICAgICAgICAgICAgIGlmIChzNiAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICBwZWckc2F2ZWRQb3MgPSBzNDsKICAgICAgICAgICAgICAgICAgczUgPSBwZWckYzE5KHMxLCBzNik7CiAgICAgICAgICAgICAgICAgIHM0ID0gczU7CiAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHM0OwogICAgICAgICAgICAgICAgICBzNCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczQ7CiAgICAgICAgICAgICAgICBzNCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIHdoaWxlIChzNCAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgczMucHVzaChzNCk7CiAgICAgICAgICAgICAgICBzNCA9IHBlZyRjdXJyUG9zOwogICAgICAgICAgICAgICAgczUgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICAgICAgICBpZiAoczUgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgczYgPSBwZWckcGFyc2VmaWVsZCgpOwogICAgICAgICAgICAgICAgICBpZiAoczYgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICBwZWckc2F2ZWRQb3MgPSBzNDsKICAgICAgICAgICAgICAgICAgICBzNSA9IHBlZyRjMTkoczEsIHM2KTsKICAgICAgICAgICAgICAgICAgICBzNCA9IHM1OwogICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczQ7CiAgICAgICAgICAgICAgICAgICAgczQgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHM0OwogICAgICAgICAgICAgICAgICBzNCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGlmIChzMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgczQgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICAgICAgICBpZiAoczQgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgcGVnJHNhdmVkUG9zID0gczA7CiAgICAgICAgICAgICAgICAgIHMxID0gcGVnJGMyMChzMSwgczMpOwogICAgICAgICAgICAgICAgICBzMCA9IHMxOwogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMwOwogICAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMwOwogICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgfQogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIHMwOwogICAgICAgIH0KICAgICAgICBmdW5jdGlvbiBwZWckcGFyc2Vjb21tZW50U3RhcnQoKSB7CiAgICAgICAgICB2YXIgczA7CiAgICAgICAgICBpZiAoaW5wdXQuY2hhckNvZGVBdChwZWckY3VyclBvcykgPT09IDM1KSB7CiAgICAgICAgICAgIHMwID0gcGVnJGMyMTsKICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjMjIpOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gczA7CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIHBlZyRwYXJzZWludGVybmFsQ29tbWVudCgpIHsKICAgICAgICAgIHZhciBzMCwgczEsIHMyLCBzMywgczQ7CiAgICAgICAgICBzMCA9IHBlZyRjdXJyUG9zOwogICAgICAgICAgczEgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICBpZiAoczEgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgczIgPSBwZWckcGFyc2Vjb21tZW50U3RhcnQoKTsKICAgICAgICAgICAgaWYgKHMyICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgczMgPSBwZWckcGFyc2Vub25RdW90ZWRTdHJpbmcoKTsKICAgICAgICAgICAgICBpZiAoczMgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgIHM0ID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICAgICAgaWYgKHM0ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgIHMxID0gW3MxLCBzMiwgczMsIHM0XTsKICAgICAgICAgICAgICAgICAgczAgPSBzMTsKICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBzMDsKICAgICAgICB9CiAgICAgICAgZnVuY3Rpb24gcGVnJHBhcnNlZmllbGQoKSB7CiAgICAgICAgICB2YXIgczAsIHMxLCBzMiwgczMsIHM0LCBzNSwgczYsIHM3LCBzOCwgczksIHMxMCwgczExLCBzMTIsIHMxMzsKICAgICAgICAgIHMwID0gcGVnJGN1cnJQb3M7CiAgICAgICAgICBzMSA9IHBlZyRwYXJzZWZpZWxkVHlwZSgpOwogICAgICAgICAgaWYgKHMxICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgIHMyID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICBpZiAoczIgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICBzMyA9IHBlZyRwYXJzZW5hbWUoKTsKICAgICAgICAgICAgICBpZiAoczMgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgIHM0ID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICAgICAgaWYgKHM0ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgIGlmIChpbnB1dC5jaGFyQ29kZUF0KHBlZyRjdXJyUG9zKSA9PT0gNTkpIHsKICAgICAgICAgICAgICAgICAgICBzNSA9IHBlZyRjMjM7CiAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICBzNSA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGMyNCk7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChzNSAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgIHM2ID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICAgICAgICAgIGlmIChzNiAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgczcgPSBwZWckcGFyc2Vjb21tZW50KCk7CiAgICAgICAgICAgICAgICAgICAgICBpZiAoczcgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgcGVnJHNhdmVkUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgIHMxID0gcGVnJGMyNShzMSwgczMsIHM3KTsKICAgICAgICAgICAgICAgICAgICAgICAgczAgPSBzMTsKICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChzMCA9PT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICBzMCA9IHBlZyRjdXJyUG9zOwogICAgICAgICAgICBzMSA9IHBlZyRwYXJzZWZpZWxkVHlwZSgpOwogICAgICAgICAgICBpZiAoczEgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICBzMiA9IHBlZyRwYXJzZV8oKTsKICAgICAgICAgICAgICBpZiAoczIgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgIGlmIChpbnB1dC5jaGFyQ29kZUF0KHBlZyRjdXJyUG9zKSA9PT0gOTEpIHsKICAgICAgICAgICAgICAgICAgczMgPSBwZWckYzI2OwogICAgICAgICAgICAgICAgICBwZWckY3VyclBvcysrOwogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgczMgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGMyNyk7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmIChzMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICBzNCA9IHBlZyRwYXJzZV8oKTsKICAgICAgICAgICAgICAgICAgaWYgKHM0ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgczUgPSBwZWckcGFyc2VmaWVsZFNpemUoKTsKICAgICAgICAgICAgICAgICAgICBpZiAoczUgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgIHM2ID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICAgICAgICAgICAgaWYgKHM2ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChpbnB1dC5jaGFyQ29kZUF0KHBlZyRjdXJyUG9zKSA9PT0gOTMpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICBzNyA9IHBlZyRjMjg7CiAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICBzNyA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGMyOSk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzNyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgIHM4ID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzOCAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgczkgPSBwZWckcGFyc2VuYW1lKCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoczkgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczEwID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoczEwICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGlucHV0LmNoYXJDb2RlQXQocGVnJGN1cnJQb3MpID09PSA1OSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczExID0gcGVnJGMyMzsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zKys7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMxMSA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjMjQpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoczExICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMTIgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoczEyICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMxMyA9IHBlZyRwYXJzZWNvbW1lbnQoKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHMxMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRzYXZlZFBvcyA9IHMwOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMxID0gcGVnJGMzMChzMSwgczUsIHM5LCBzMTMpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gczE7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHMwID09PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgczAgPSBwZWckY3VyclBvczsKICAgICAgICAgICAgICBzMSA9IHBlZyRwYXJzZWZpZWxkVHlwZSgpOwogICAgICAgICAgICAgIGlmIChzMSAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgczIgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICAgICAgICBpZiAoczIgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgaWYgKGlucHV0LmNoYXJDb2RlQXQocGVnJGN1cnJQb3MpID09PSA0MCkgewogICAgICAgICAgICAgICAgICAgIHMzID0gcGVnJGMwOwogICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zKys7CiAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgczMgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjMSk7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChzMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgIHM0ID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICAgICAgICAgIGlmIChzNCAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgczUgPSBwZWckcGFyc2VmaWVsZFZhbHVlcygpOwogICAgICAgICAgICAgICAgICAgICAgaWYgKHM1ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHM2ID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICAgICAgICAgICAgICBpZiAoczYgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoaW5wdXQuY2hhckNvZGVBdChwZWckY3VyclBvcykgPT09IDQxKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzNyA9IHBlZyRjMjsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zKys7CiAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHM3ID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGMzKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHM3ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzOCA9IHBlZyRwYXJzZV8oKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzOCAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzOSA9IHBlZyRwYXJzZW5hbWUoKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHM5ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczEwID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzMTAgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChpbnB1dC5jaGFyQ29kZUF0KHBlZyRjdXJyUG9zKSA9PT0gNTkpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczExID0gcGVnJGMyMzsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMxMSA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzI0KTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHMxMSAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMTIgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzMTIgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMTMgPSBwZWckcGFyc2Vjb21tZW50KCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHMxMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJHNhdmVkUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMSA9IHBlZyRjMzEoczEsIHM1LCBzOSwgczEzKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gczE7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMwOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMwOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMwOwogICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMwOwogICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGlmIChzMCA9PT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgczAgPSBwZWckcGFyc2VpbnRlcm5hbENvbW1lbnQoKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBzMDsKICAgICAgICB9CiAgICAgICAgZnVuY3Rpb24gcGVnJHBhcnNlZmllbGRWYWx1ZXMoKSB7CiAgICAgICAgICB2YXIgczAsIHMxLCBzMiwgczMsIHM0LCBzNSwgczY7CiAgICAgICAgICBzMCA9IHBlZyRjdXJyUG9zOwogICAgICAgICAgczEgPSBwZWckcGFyc2VuYW1lKCk7CiAgICAgICAgICBpZiAoczEgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgczIgPSBbXTsKICAgICAgICAgICAgczMgPSBwZWckY3VyclBvczsKICAgICAgICAgICAgaWYgKGlucHV0LmNoYXJDb2RlQXQocGVnJGN1cnJQb3MpID09PSA0NCkgewogICAgICAgICAgICAgIHM0ID0gcGVnJGMzMjsKICAgICAgICAgICAgICBwZWckY3VyclBvcysrOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHM0ID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzMzKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHM0ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgczUgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICAgICAgaWYgKHM1ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICBzNiA9IHBlZyRwYXJzZW5hbWUoKTsKICAgICAgICAgICAgICAgIGlmIChzNiAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICBwZWckc2F2ZWRQb3MgPSBzMzsKICAgICAgICAgICAgICAgICAgczQgPSBwZWckYzE5KHMxLCBzNik7CiAgICAgICAgICAgICAgICAgIHMzID0gczQ7CiAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMzOwogICAgICAgICAgICAgICAgICBzMyA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczM7CiAgICAgICAgICAgICAgICBzMyA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczM7CiAgICAgICAgICAgICAgczMgPSBwZWckRkFJTEVEOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHdoaWxlIChzMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgIHMyLnB1c2goczMpOwogICAgICAgICAgICAgIHMzID0gcGVnJGN1cnJQb3M7CiAgICAgICAgICAgICAgaWYgKGlucHV0LmNoYXJDb2RlQXQocGVnJGN1cnJQb3MpID09PSA0NCkgewogICAgICAgICAgICAgICAgczQgPSBwZWckYzMyOwogICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgczQgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzMzKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgaWYgKHM0ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICBzNSA9IHBlZyRwYXJzZV8oKTsKICAgICAgICAgICAgICAgIGlmIChzNSAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICBzNiA9IHBlZyRwYXJzZW5hbWUoKTsKICAgICAgICAgICAgICAgICAgaWYgKHM2ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgcGVnJHNhdmVkUG9zID0gczM7CiAgICAgICAgICAgICAgICAgICAgczQgPSBwZWckYzE5KHMxLCBzNik7CiAgICAgICAgICAgICAgICAgICAgczMgPSBzNDsKICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMzOwogICAgICAgICAgICAgICAgICAgIHMzID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMzsKICAgICAgICAgICAgICAgICAgczMgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMzOwogICAgICAgICAgICAgICAgczMgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoczIgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICBwZWckc2F2ZWRQb3MgPSBzMDsKICAgICAgICAgICAgICBzMSA9IHBlZyRjMzQoczEsIHMyKTsKICAgICAgICAgICAgICBzMCA9IHMxOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBwZWckY3VyclBvcyA9IHMwOwogICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gczA7CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIHBlZyRwYXJzZWZpZWxkVHlwZSgpIHsKICAgICAgICAgIHZhciBzMCwgczEsIHMyLCBzMzsKICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDMpID09PSBwZWckYzM1KSB7CiAgICAgICAgICAgIHMwID0gcGVnJGMzNTsKICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gMzsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjMzYpOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgaWYgKGlucHV0LnN1YnN0cihwZWckY3VyclBvcywgNCkgPT09IHBlZyRjMzcpIHsKICAgICAgICAgICAgICBzMCA9IHBlZyRjMzc7CiAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gNDsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGMzOCk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzMCA9PT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDUpID09PSBwZWckYzM5KSB7CiAgICAgICAgICAgICAgICBzMCA9IHBlZyRjMzk7CiAgICAgICAgICAgICAgICBwZWckY3VyclBvcyArPSA1OwogICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjNDApOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDYpID09PSBwZWckYzQxKSB7CiAgICAgICAgICAgICAgICAgIHMwID0gcGVnJGM0MTsKICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gNjsKICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjNDIpOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgaWYgKGlucHV0LnN1YnN0cihwZWckY3VyclBvcywgNCkgPT09IHBlZyRjNDMpIHsKICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRjNDM7CiAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gNDsKICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGM0NCk7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChzMCA9PT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDUpID09PSBwZWckYzQ1KSB7CiAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRjNDU7CiAgICAgICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyArPSA1OwogICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjNDYpOwogICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDUpID09PSBwZWckYzQ3KSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJGM0NzsKICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gNTsKICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjNDgpOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGlucHV0LnN1YnN0cihwZWckY3VyclBvcywgNCkgPT09IHBlZyRjNDkpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRjNDk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gNDsKICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGM1MCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzMCA9PT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDYpID09PSBwZWckYzUxKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRjNTE7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyArPSA2OwogICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjNTIpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDcpID09PSBwZWckYzUzKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJGM1MzsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gNzsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjNTQpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGlucHV0LnN1YnN0cihwZWckY3VyclBvcywgNCkgPT09IHBlZyRjNTUpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRjNTU7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gNDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGM1Nik7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzMCA9PT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDYpID09PSBwZWckYzU3KSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRjNTc7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyArPSA2OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjNTgpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDYpID09PSBwZWckYzU5KSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJGM1OTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gNjsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjNjApOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGlucHV0LnN1YnN0cihwZWckY3VyclBvcywgMykgPT09IHBlZyRjNjEpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRjNjE7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gMzsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGM2Mik7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzMCA9PT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJGN1cnJQb3M7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczEgPSBwZWckcGFyc2VkZWNsYXJlVHlwZSgpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzMSAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczIgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoczIgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczMgPSBwZWckcGFyc2VkZWNsYXJlTmFtZSgpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoczMgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwZWckc2F2ZWRQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMSA9IHBlZyRjNjMoczEsIHMzKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHMxOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMwOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gczA7CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIHBlZyRwYXJzZWZpZWxkU2l6ZSgpIHsKICAgICAgICAgIHZhciBzMDsKICAgICAgICAgIHMwID0gcGVnJHBhcnNlbnVtYmVyKCk7CiAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgczAgPSBwZWckcGFyc2VuYW1lKCk7CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gczA7CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIHBlZyRwYXJzZW5hbWUoKSB7CiAgICAgICAgICB2YXIgczAsIHMxLCBzMiwgczMsIHM0OwogICAgICAgICAgczAgPSBwZWckY3VyclBvczsKICAgICAgICAgIHMxID0gcGVnJGN1cnJQb3M7CiAgICAgICAgICBpZiAocGVnJGM2NC50ZXN0KGlucHV0LmNoYXJBdChwZWckY3VyclBvcykpKSB7CiAgICAgICAgICAgIHMyID0gaW5wdXQuY2hhckF0KHBlZyRjdXJyUG9zKTsKICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHMyID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjNjUpOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoczIgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgczMgPSBbXTsKICAgICAgICAgICAgaWYgKHBlZyRjNjYudGVzdChpbnB1dC5jaGFyQXQocGVnJGN1cnJQb3MpKSkgewogICAgICAgICAgICAgIHM0ID0gaW5wdXQuY2hhckF0KHBlZyRjdXJyUG9zKTsKICAgICAgICAgICAgICBwZWckY3VyclBvcysrOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHM0ID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzY3KTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgd2hpbGUgKHM0ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgczMucHVzaChzNCk7CiAgICAgICAgICAgICAgaWYgKHBlZyRjNjYudGVzdChpbnB1dC5jaGFyQXQocGVnJGN1cnJQb3MpKSkgewogICAgICAgICAgICAgICAgczQgPSBpbnB1dC5jaGFyQXQocGVnJGN1cnJQb3MpOwogICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgczQgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzY3KTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHMzICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgczIgPSBbczIsIHMzXTsKICAgICAgICAgICAgICBzMSA9IHMyOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczE7CiAgICAgICAgICAgICAgczEgPSBwZWckRkFJTEVEOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBwZWckY3VyclBvcyA9IHMxOwogICAgICAgICAgICBzMSA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoczEgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgcGVnJHNhdmVkUG9zID0gczA7CiAgICAgICAgICAgIHMxID0gcGVnJGM2OChzMSk7CiAgICAgICAgICB9CiAgICAgICAgICBzMCA9IHMxOwogICAgICAgICAgcmV0dXJuIHMwOwogICAgICAgIH0KICAgICAgICBmdW5jdGlvbiBwZWckcGFyc2VxdW90ZWRTdHJpbmcoKSB7CiAgICAgICAgICB2YXIgczAsIHMxLCBzMiwgczM7CiAgICAgICAgICBzMCA9IHBlZyRjdXJyUG9zOwogICAgICAgICAgaWYgKGlucHV0LmNoYXJDb2RlQXQocGVnJGN1cnJQb3MpID09PSAzNCkgewogICAgICAgICAgICBzMSA9IHBlZyRjNjk7CiAgICAgICAgICAgIHBlZyRjdXJyUG9zKys7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBzMSA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzcwKTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgaWYgKHMxICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgIHMyID0gW107CiAgICAgICAgICAgIGlmIChwZWckYzcxLnRlc3QoaW5wdXQuY2hhckF0KHBlZyRjdXJyUG9zKSkpIHsKICAgICAgICAgICAgICBzMyA9IGlucHV0LmNoYXJBdChwZWckY3VyclBvcyk7CiAgICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICBzMyA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGM3Mik7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIHdoaWxlIChzMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgIHMyLnB1c2goczMpOwogICAgICAgICAgICAgIGlmIChwZWckYzcxLnRlc3QoaW5wdXQuY2hhckF0KHBlZyRjdXJyUG9zKSkpIHsKICAgICAgICAgICAgICAgIHMzID0gaW5wdXQuY2hhckF0KHBlZyRjdXJyUG9zKTsKICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zKys7CiAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIHMzID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGM3Mik7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzMiAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgIGlmIChpbnB1dC5jaGFyQ29kZUF0KHBlZyRjdXJyUG9zKSA9PT0gMzQpIHsKICAgICAgICAgICAgICAgIHMzID0gcGVnJGM2OTsKICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zKys7CiAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIHMzID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGM3MCk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGlmIChzMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgcGVnJHNhdmVkUG9zID0gczA7CiAgICAgICAgICAgICAgICBzMSA9IHBlZyRjNzMoczIpOwogICAgICAgICAgICAgICAgczAgPSBzMTsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBzMDsKICAgICAgICB9CiAgICAgICAgZnVuY3Rpb24gcGVnJHBhcnNlbm9uUXVvdGVkU3RyaW5nKCkgewogICAgICAgICAgdmFyIHMwLCBzMSwgczI7CiAgICAgICAgICBzMCA9IHBlZyRjdXJyUG9zOwogICAgICAgICAgczEgPSBbXTsKICAgICAgICAgIGlmIChwZWckYzc0LnRlc3QoaW5wdXQuY2hhckF0KHBlZyRjdXJyUG9zKSkpIHsKICAgICAgICAgICAgczIgPSBpbnB1dC5jaGFyQXQocGVnJGN1cnJQb3MpOwogICAgICAgICAgICBwZWckY3VyclBvcysrOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgczIgPSBwZWckRkFJTEVEOwogICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGM3NSk7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIHdoaWxlIChzMiAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICBzMS5wdXNoKHMyKTsKICAgICAgICAgICAgaWYgKHBlZyRjNzQudGVzdChpbnB1dC5jaGFyQXQocGVnJGN1cnJQb3MpKSkgewogICAgICAgICAgICAgIHMyID0gaW5wdXQuY2hhckF0KHBlZyRjdXJyUG9zKTsKICAgICAgICAgICAgICBwZWckY3VyclBvcysrOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHMyID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzc1KTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGlmIChzMSAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICBwZWckc2F2ZWRQb3MgPSBzMDsKICAgICAgICAgICAgczEgPSBwZWckYzc2KHMxKTsKICAgICAgICAgIH0KICAgICAgICAgIHMwID0gczE7CiAgICAgICAgICByZXR1cm4gczA7CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIHBlZyRwYXJzZW51bWJlcigpIHsKICAgICAgICAgIHZhciBzMCwgczEsIHMyLCBzMzsKICAgICAgICAgIHBlZyRzaWxlbnRGYWlscysrOwogICAgICAgICAgczAgPSBwZWckY3VyclBvczsKICAgICAgICAgIHMxID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgaWYgKHMxICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgIHMyID0gW107CiAgICAgICAgICAgIGlmIChwZWckYzc4LnRlc3QoaW5wdXQuY2hhckF0KHBlZyRjdXJyUG9zKSkpIHsKICAgICAgICAgICAgICBzMyA9IGlucHV0LmNoYXJBdChwZWckY3VyclBvcyk7CiAgICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICBzMyA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGM3OSk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgIHdoaWxlIChzMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgczIucHVzaChzMyk7CiAgICAgICAgICAgICAgICBpZiAocGVnJGM3OC50ZXN0KGlucHV0LmNoYXJBdChwZWckY3VyclBvcykpKSB7CiAgICAgICAgICAgICAgICAgIHMzID0gaW5wdXQuY2hhckF0KHBlZyRjdXJyUG9zKTsKICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgIHMzID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjNzkpOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHMyID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoczIgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICBwZWckc2F2ZWRQb3MgPSBzMDsKICAgICAgICAgICAgICBzMSA9IHBlZyRjODAoKTsKICAgICAgICAgICAgICBzMCA9IHMxOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBwZWckY3VyclBvcyA9IHMwOwogICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICB9CiAgICAgICAgICBwZWckc2lsZW50RmFpbHMtLTsKICAgICAgICAgIGlmIChzMCA9PT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICBzMSA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzc3KTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIHMwOwogICAgICAgIH0KICAgICAgICBmdW5jdGlvbiBwZWckcGFyc2VfKCkgewogICAgICAgICAgdmFyIHMwLCBzMTsKICAgICAgICAgIHBlZyRzaWxlbnRGYWlscysrOwogICAgICAgICAgczAgPSBbXTsKICAgICAgICAgIGlmIChwZWckYzgyLnRlc3QoaW5wdXQuY2hhckF0KHBlZyRjdXJyUG9zKSkpIHsKICAgICAgICAgICAgczEgPSBpbnB1dC5jaGFyQXQocGVnJGN1cnJQb3MpOwogICAgICAgICAgICBwZWckY3VyclBvcysrOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgczEgPSBwZWckRkFJTEVEOwogICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGM4Myk7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIHdoaWxlIChzMSAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICBzMC5wdXNoKHMxKTsKICAgICAgICAgICAgaWYgKHBlZyRjODIudGVzdChpbnB1dC5jaGFyQXQocGVnJGN1cnJQb3MpKSkgewogICAgICAgICAgICAgIHMxID0gaW5wdXQuY2hhckF0KHBlZyRjdXJyUG9zKTsKICAgICAgICAgICAgICBwZWckY3VyclBvcysrOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHMxID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzgzKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIHBlZyRzaWxlbnRGYWlscy0tOwogICAgICAgICAgaWYgKHMwID09PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgIHMxID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjODEpOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gczA7CiAgICAgICAgfQogICAgICAgIHBlZyRyZXN1bHQgPSBwZWckc3RhcnRSdWxlRnVuY3Rpb24oKTsKICAgICAgICBpZiAocGVnJHJlc3VsdCAhPT0gcGVnJEZBSUxFRCAmJiBwZWckY3VyclBvcyA9PT0gaW5wdXQubGVuZ3RoKSB7CiAgICAgICAgICByZXR1cm4gcGVnJHJlc3VsdDsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgaWYgKHBlZyRyZXN1bHQgIT09IHBlZyRGQUlMRUQgJiYgcGVnJGN1cnJQb3MgPCBpbnB1dC5sZW5ndGgpIHsKICAgICAgICAgICAgcGVnJGZhaWwocGVnJGVuZEV4cGVjdGF0aW9uKCkpOwogICAgICAgICAgfQogICAgICAgICAgdGhyb3cgcGVnJGJ1aWxkU3RydWN0dXJlZEVycm9yKHBlZyRtYXhGYWlsRXhwZWN0ZWQs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luaXQyLAogICAgICAgICAgICBjYWNoZTogInJlbG9hZCIKICAgICAgICAgIH0pOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICB0aHJvdyBlOwogICAgICAgIH0KICAgICAgfQogICAgICByZXR1cm4gcmVzcG9uc2U7CiAgICB9CiAgICBhc3luYyByZWFkKGJ1ZmZlciwgb2Zmc2V0ID0gMCwgbGVuZ3RoLCBwb3NpdGlvbiA9IDAsIG9wdHMgPSB7fSkgewogICAgICBjb25zdCB7IGhlYWRlcnMgPSB7fSwgc2lnbmFsLCBvdmVycmlkZXMgPSB7fSB9ID0gb3B0czsKICAgICAgaWYgKGxlbmd0aCA8IEluZmluaXR5KSB7CiAgICAgICAgaGVhZGVycy5yYW5nZSA9IGBieXRlcz0ke3Bvc2l0aW9ufS0ke3Bvc2l0aW9uICsgbGVuZ3RofWA7CiAgICAgIH0gZWxzZSBpZiAobGVuZ3RoID09PSBJbmZpbml0eSAmJiBwb3NpdGlvbiAhPT0gMCkgewogICAgICAgIGhlYWRlcnMucmFuZ2UgPSBgYnl0ZXM9JHtwb3NpdGlvbn0tYDsKICAgICAgfQogICAgICBjb25zdCBhcmdzID0gewogICAgICAgIC4uLnRoaXMuYmFzZU92ZXJyaWRlcywKICAgICAgICAuLi5vdmVycmlkZXMsCiAgICAgICAgaGVhZGVyczogewogICAgICAgICAgLi4uaGVhZGVycywKICAgICAgICAgIC4uLm92ZXJyaWRlcy5oZWFkZXJzLAogICAgICAgICAgLi4udGhpcy5iYXNlT3ZlcnJpZGVzLmhlYWRlcnMKICAgICAgICB9LAogICAgICAgIG1ldGhvZDogIkdFVCIsCiAgICAgICAgcmVkaXJlY3Q6ICJmb2xsb3ciLAogICAgICAgIG1vZGU6ICJjb3JzIiwKICAgICAgICBzaWduYWwKICAgICAgfTsKICAgICAgY29uc3QgcmVzcG9uc2UgPSBhd2FpdCB0aGlzLmZldGNoKHRoaXMudXJsLCBhcmdzKTsKICAgICAgaWYgKCFyZXNwb25zZS5vaykgewog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ICAgIH0KICAgIGFzeW5jIHJlYWRGaWxlKG9wdGlvbnMgPSB7fSkgewogICAgICBsZXQgZW5jb2Rpbmc7CiAgICAgIGxldCBvcHRzOwogICAgICBpZiAodHlwZW9mIG9wdGlvbnMgPT09ICJzdHJpbmciKSB7CiAgICAgICAgZW5jb2RpbmcgPSBvcHRpb25zOwogICAgICAgIG9wdHMgPSB7fTsKICAgICAgfSBlbHNlIHsKICAgICAgICBlbmNvZGluZyA9IG9wdGlvbnMuZW5jb2Rpbmc7CiAgICAgICAgb3B0cyA9IG9wdGlvbnM7CiAgICAgICAgZGVsZXRlIG9wdHMuZW5jb2Rpbmc7CiAgICAgIH0KICAgICAgY29uc3QgeyBoZWFkZXJzID0ge30sIHNpZ25hbCwgb3ZlcnJpZGVzID0ge30gfSA9IG9wdHM7CiAgICAgIGNvbnN0IGFyZ3MgPSB7CiAgICAgICAgaGVhZGVycywKICAgICAgICBtZXRob2Q6ICJHRVQiLAogICAgICAgIHJlZGlyZWN0OiAiZm9sbG93IiwKICAgICAgICBtb2RlOiAiY29ycyIsCiAgICAgICAgc2lnbmFsLAogICAgICAgIC4uLnRoaXMuYmFzZU92ZXJyaWRlcywKICAgICAgICAuLi5vdmVycmlkZXMKICAgICAgfTsKICAgICAgY29uc3QgcmVzcG9uc2UgPSBhd2FpdCB0aGlzLmZldGNoKHRoaXMudXJsLCBhcmdzKTsKICAgICAgaWYgKCFyZXNwb25zZSkgewogICAgICAgIHRocm93IG5ldyBFcnJvcigiZ2VuZXJpYy1maWxlaGFuZGxlIGZhaWxlZCB0byBmZXRjaCIpOwogICAgICB9CiAgICAgIGlmIChyZXNwb25zZS5zdGF0dXMgIT09IDIwMCkgewogICAgICAgIHRocm93IE9iamVjdC5hc3NpZ24obmV3IEVycm9yKGBIVFRQICR7cmVzcG9uc2Uuc3RhdHVzfSBmZXRjaGluZyAke3RoaXMudXJsfWApLCB7CiAgICAgICAgICBzdGF0dXM6IHJlc3BvbnNlLnN0YXR1cwogICAgICA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sKICAgIHRyeSB7CiAgICAgIGxldCBzdHJtOwogICAgICBjb25zdCB7IG1pbnYsIG1heHYgfSA9IGNodW5rOwogICAgICBsZXQgY3BvcyA9IG1pbnYuYmxvY2tQb3NpdGlvbjsKICAgICAgbGV0IGRwb3MgPSBtaW52LmRhdGFQb3NpdGlvbjsKICAgICAgY29uc3QgY2h1bmtzID0gW107CiAgICAgIGNvbnN0IGNwb3NpdGlvbnMgPSBbXTsKICAgICAgY29uc3QgZHBvc2l0aW9ucyA9IFtdOwogICAgICBsZXQgdG90YWxTaXplID0gMDsKICAgICAgbGV0IGkgPSAwOwogICAgICBkbyB7CiAgICAgICAgY29uc3QgcmVtYWluaW5nSW5wdXQgPSBpbnB1dERhdGEuc3ViYXJyYXkoY3BvcyAtIG1pbnYuYmxvY2tQb3NpdGlvbik7CiAgICAgICAgY29uc3QgaW5mbGF0b3IgPSBuZXcgaW1wb3J0X3Bha28uSW5mbGF0ZSgpOwogICAgICAgICh7IHN0cm0gfSA9IGluZmxhdG9yKTsKICAgICAgICBpbmZsYXRvci5wdXNoKHJlbWFpbmluZ0lucHV0LCBpbXBvcnRfcGFrby5aX1NZTkNfRkxVU0gpOwogICAgICAgIGlmIChpbmZsYXRvci5lcnIpIHsKICAgICAgICAgIHRocm93IG5ldyBFcnJvcihpbmZsYXRvci5tc2cpOwogICAgICAgIH0KICAgICAgICBjb25zdCBidWZmZXIyID0gaW5mbGF0b3IucmVzdWx0OwogICAgICAgIGNodW5rcy5wdXNoKGJ1ZmZlcjIpOwogICAgICAgIGxldCBsZW4gPSBidWZmZXIyLmxlbmd0aDsKICAgICAgICBjcG9zaXRpb25zLnB1c2goY3Bvcyk7CiAgICAgICAgZHBvc2l0aW9ucy5wdXNoKGRwb3MpOwogICAgICAgIGlmIChjaHVua3MubGVuZ3RoID09PSAxICYmIG1pbnYuZGF0YVBvc2l0aW9uKSB7CiAgICAgICAgICBjaHVua3NbMF0gPSBjaHVua3NbMF0uc3ViYXJyYXkobWludi5kY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bChzaWduYWwpIHsKICAgIGlmICghc2lnbmFsKSB7CiAgICAgIHJldHVybjsKICAgIH0KICAgIGlmIChzaWduYWwuYWJvcnRlZCkgewogICAgICBpZiAodHlwZW9mIERPTUV4Y2VwdGlvbiAhPT0gInVuZGVmaW5lZCIpIHsKICAgICAgICB0aHJvdyBuZXcgRE9NRXhjZXB0aW9uKCJhYm9ydGVkIiwgIkFib3J0RXJyb3IiKTsKICAgICAgfSBlbHNlIHsKICAgICAgICBjb25zdCBlID0gbmV3IEFib3J0RXJyb3IoImFib3J0ZWQiKTsKICAgICAgICBlLmNvZGUgPSAiRVJSX0FCT1JURUQiOwogICAgICAgIHRocm93IGU7CiAgICAgIH0KICAgIH0KICB9CiAgZnVuY3Rpb24gY2FuTWVyZ2VCbG9ja3MoY2h1bmsxLCBjaHVuazIpIHsKICAgIHJldHVybiBjaHVuazIubWludi5ibG9ja1Bvc2l0aW9uIC0gY2h1bmsxLm1heHYuYmxvY2tQb3NpdGlvbiA8IDY1ZTMgJiYgY2h1bmsyLm1heHYuYmxvY2tQb3NpdGlvbiAtIGNodW5rMS5taW52LmJsb2NrUG9zaXRpb24gPCA1ZTY7CiAgfQogIGZ1bmN0aW9uIG9wdGltaXplQ2h1bmtzKGNodW5rcywgbG93ZXN0KSB7CiAgICBjb25zdCBtZXJnZWRDaHVua3MgPSBbXTsKICAgIGxldCBsYXN0Q2h1bmsgPSBudWxsOwogICAgaWYgKGNodW5rcy5sZW5ndGggPT09IDApIHsKICAgICAgcmV0dXJuIGNodW5rczsKICAgIH0KICAgIGNodW5rcy5zb3J0KGZ1bmN0aW9uKGMwLCBjMSkgewogICAgICBjb25zdCBkaWYgPSBjMC5taW52LmJsb2NrUG9zaXRpb24gLSBjMS5taW52LmJsb2NrUG9zaXRpb247CiAgICAgIGlmIChkaWYgIT09IDApIHsKICAgICAgICByZXR1cm4gZGlmOwogICAgICB9IGVsc2UgewogICAgICAgIHJldHVybiBjMC5taW52LmRhdGFQb3NpdGlvbiAtIGMxLm1pbnYuZGF0YVBvc2l0aW9uOwogICAgICB9CiAgICB9KTsKICAgIGNodW5rcy5mb3JFYWNoKChjaHVuaykgPT4gewogICAgICBpZiAoIWxvd2VzdCB8fCBjaHVuay5tYXh2LmNvbXBhcmVUbyhsb3dlc3QpID4gMCkgewogICAgICAgIGlmIChsYXN0Q2h1bmsgPT09IG51bGwpIHsKICAgICAgICAgIG1lcmdlZENodW5rcy5wdXNoKGNodW5rKTsKICAgICAgICAgIGxhc3RDaHVuayA9IGNodW5rOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBpZiAoY2FuTWVyZ2VCbG9ja3MobGFzdENodW5rLCBjaHVuaykpIHsKICAgICAgICAgICAgaWYgKGNodW5rLm1heHYuY29tcGFyZVRvKGxhc3RDaHVuay5tYXh2KSA+IDApIHsKICAgICAgICAgICAgICBsYXN0Q2h1bmsubWF4diA9IGNodW5rLm1heHY7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIG1lcmdlZENodW5rcy5wdXNoKGNodW5rKTsKICAgICAgICAgICAgbGFzdENodW5rID0gY2h1bms7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9CiAgICB9KTsKICAgIHJldHVybiBtZXJnZWRDaHVua3M7CiAgfQoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vQGdtb2QrdGFiaXhAMS41LjExL25vZGVfbW9kdWxlcy9AZ21vZC90YWJpeC9lc20vdGJpLmpzCiAgaW5pdF9idWZmZXJfc2hpbSgpOwogIHZhciBpbXBvcnRfbG9uZzIgPSBfX3RvTW9kdWxlKHJlcXVpcmVfbG9uZygpKTsKCiAgLy8gbm9kZV9tb2R1bGVzLy5wbnBtL0BnbW9kK3RhYml4QDEuNS4xMS9ub2RlX21vZHVsZXMvQGdtb2QvdGFiaXgvZXNtL3ZpcnR1YWxPZmZzZXQuanMKICBpbml0X2J1ZmZlcl9zaGltKCk7CiAgdmFyIFZpcnR1YWxPZmZzZXQ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gewogICAgICAgIHRoaXMucGFyc2VQID0gdGhpcy5fcGFyc2Uob3B0cykuY2F0Y2goKGUpID0+IHsKICAgICAgICAgIHRoaXMucGFyc2VQID0gdm9pZCAwOwogICAgICAgICAgdGhyb3cgZTsKICAgICAgICB9KTsKICAgICAgfQogICAgICByZXR1cm4gdGhpcy5wYXJzZVA7CiAgICB9CiAgICBhc3luYyBoYXNSZWZTZXEoc2VxSWQsIG9wdHMgPSB7fSkgewogICAgICByZXR1cm4gISEoKGF3YWl0IHRoaXMucGFyc2Uob3B0cykpLmluZGljZXNbc2VxSWRdIHx8IHt9KS5iaW5JbmRleDsKICAgIH0KICB9OwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vQGdtb2QrdGFiaXhAMS41LjExL25vZGVfbW9kdWxlcy9AZ21vZC90YWJpeC9lc20vdGJpLmpzCiAgdmFyIFRCSV9NQUdJQyA9IDIxNTc4MzI0OwogIHZhciBUQURfTElEWF9TSElGVCA9IDE0OwogIGZ1bmN0aW9uIHJlZzJiaW5zKGJlZywgZW5kKSB7CiAgICBiZWcgKz0gMTsKICAgIGVuZCAtPSAxOwogICAgcmV0dXJuIFsKICAgICAgWzAsIDBdLAogICAgICBbMSArIChiZWcgPj4gMjYpLCAxICsgKGVuZCA+PiAyNildLAogICAgICBbOSArIChiZWcgPj4gMjMpLCA5ICsgKGVuZCA+PiAyMyldLAogICAgICBbNzMgKyAoYmVnID4+IDIwKSwgNzMgKyAoZW5kID4+IDIwKV0sCiAgICAgIFs1ODUgKyAoYmVnID4+IDE3KSwgNTg1ICsgKGVuZCA+PiAxNyldLAogICAgICBbNDY4MSArIChiZWcgPj4gMTQpLCA0NjgxICsgKGVuZCA+PiAxNCldCiAgICBdOwogIH0KICB2YXIgVGFiaXhJbmRleCA9IGNsYXNzIGV4dGVuZHMgSW5kZXhGaWxlIHsKICAgIGFzeW5jIGxpbmVDb3VudChyZWZOYW1lLCBvcHRzID0ge30pIHsKICAgICAgY29uc3QgaW5kZXhEYXR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Zmc2V0ID0gMzYgKyBuYW1lU2VjdGlvbkxlbmd0aDsKICAgICAgbGV0IGZpcnN0RGF0YUxpbmU7CiAgICAgIGNvbnN0IGluZGljZXMgPSBuZXcgQXJyYXkocmVmQ291bnQpLmZpbGwoMCkubWFwKCgpID0+IHsKICAgICAgICBjb25zdCBiaW5Db3VudCA9IGJ5dGVzLnJlYWRJbnQzMkxFKGN1cnJPZmZzZXQpOwogICAgICAgIGN1cnJPZmZzZXQgKz0gNDsKICAgICAgICBjb25zdCBiaW5JbmRleCA9IHt9OwogICAgICAgIGxldCBzdGF0czsKICAgICAgICBmb3IgKGxldCBqID0gMDsgaiA8IGJpbkNvdW50OyBqICs9IDEpIHsKICAgICAgICAgIGNvbnN0IGJpbiA9IGJ5dGVzLnJlYWRVSW50MzJMRShjdXJyT2Zmc2V0KTsKICAgICAgICAgIGN1cnJPZmZzZXQgKz0gNDsKICAgICAgICAgIGlmIChiaW4gPiBtYXhCaW5OdW1iZXIgKyAxKSB7CiAgICAgICAgICAgIHRocm93IG5ldyBFcnJvcigidGFiaXggaW5kZXggY29udGFpbnMgdG9vIG1hbnkgYmlucywgcGxlYXNlIHVzZSBhIENTSSBpbmRleCIpOwogICAgICAgICAgfSBlbHNlIGlmIChiaW4gPT09IG1heEJpbk51bWJlciArIDEpIHsKICAgICAgICAgICAgY29uc3QgY2h1bmtDb3VudCA9IGJ5dGVzLnJlYWRJbnQzMkxFKGN1cnJPZmZzZXQpOwogICAgICAgICAgICBjdXJyT2Zmc2V0ICs9IDQ7CiAgICAgICAgICAgIGlmIChjaHVua0NvdW50ID09PSAyKSB7CiAgICAgICAgICAgICAgc3RhdHMgPSB0aGlzLnBhcnNlUHNldWRvQmluKGJ5dGVzLCBjdXJyT2Zmc2V0KTsKICAgICAgICAgICAgfQogICAgICAgICAgICBjdXJyT2Zmc2V0ICs9IDE2ICogY2h1bmtDb3VudDsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGNvbnN0IGNodW5rQ291bnQgPSBieXRlcy5yZWFkSW50MzJMRShjdXJyT2Zmc2V0KTsKICAgICAgICAgICAgY3Vyck9mZnNldCArPSA0OwogICAgICAgICAgICBjb25zdCBjaHVua3MgPSBuZXcgQXJyYXkoY2h1bmtDb3VudCk7CiAgICAgICAgICAgIGZvciAobGV0IGsgPSAwOyBrIDwgY2h1bmtDb3VudDsgayArPSAxKSB7CiAgICAgICAgICAgICAgY29uc3QgdSA9IGZyb21CeXRlcyhieXRlcywgY3Vyck9mZnNldCk7CiAgICAgICAgICAgICAgY29uc3QgdiA9IGZyb21CeXRlcyhieXRlcywgY3Vyck9mZnNldCArIDgpOwogICAgICAgICAgICAgIGN1cnJPZmZzZXQgKz0gMTY7CiAgICAgICAgICAgICAgZmlyc3REYXRhTGluZSA9IHRoaXMuX2ZpbmRGaXJzdERhdGEoZmlyc3REYXRhTGluZSwgdSk7CiAgICAgICAgICAgICAgY2h1bmtzW2tdID0gbmV3IENodW5rKHUsIHYsIGJpbik7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgYmluSW5kZXhbYmluXSA9IGNodW5rczsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgY29uc3QgbGluZWFyQ291bnQgPSBieXRlcy5yZWFkSW50MzJMRShjdXJyT2Zmc2V0KTsKICAgICAgICBjdXJyT2Zmc2V0ICs9IDQ7CiAgICAgICAgY29uc3QgbGluZWFySW5kZXggPSBuZXcgQXJyYXkobGluZWFyQ291bnQpOwogICAgICAgIGZvciAobGV0IGsgPSAwOyBrIDwgbGluZWFyQ291bnQ7IGsgKz0gMSkgewogICAgICAgICAgbGluZWFySW5kZXhba10gPSBmcm9tQnl0ZXMoYnl0ZXMsIGN1cnJPZmZzZXQpOwogICAgICAgICAgY3Vyck9mZnNldCArPSA4OwogICAgICAgICAgZmlyc3REYXRhTGluZSA9IHRoaXMuX2ZpbmRGaXJzdERhdGEoZmlyc3REYXRhTGluZSwgbGluZWFySW5kZXhba10pOwogICAgICAgIH0KICAgICAgICByZXR1cm4geyBiaW5JbmRleCwgbGluZWFySW5kZXgsIHN0YXRzIH07CiAgICAgIH0pOwogICAgICByZXR1cm4gewogICAgICAgIGluZGljZXMsCiAgICAgICAgbWV0YUNoYXIsCiAgICAgICAgbWF4QmluTnVtYmVyLAogICAgICAgIG1heFJlZkxlbmd0aCwKICAgICAgICBza2lwTGluZXMsCiAgICAgICAgZmlyc3REYXRhTGluZSwKICAgICAgICBjb2x1bW5OdW1iZXJzLAogICAgICAgIGNvb3JkaW5hdGVUeXBlLAogICAgICAgIGZvcm1hdCwKICAgICAgICByZWZJZFRvTmFtZSwKICAgICAgICByZWZOYW1lVG9JZCwKICAgICAgICBtYXhCbG9ja1NpemU6IDEgPDwgMTYKICAgICAgfTsKICAgIH0KICAgIHBhcnNlUHNldWRvQmluKGJ5dGVzLCBvZmZzZXQpIHsKICAgICAgY29uc3QgbGluZUNvdW50ID0gbG9uZ1RvTnVtYmVyKGltcG9ydF9sb25nMi5kZWZhdWx0LmZyb21CeXRlc0xFKGJ5dGVzLnNsaWNlKG9mZnNldCArIDE2LCBvZmZzZXQgKyAyNCksIHRydWUpKTsKICAgICAgcmV0dXJuIHsgbGluZUNvdW50IH07CiAgICB9CiAgICBfcGFyc2VOYW1lQnl0ZXMobmFtZXNCeXRlcykgewogICAgICBsZXQgY3VyclJlZklkID0gMDsKICAgICAgbGV0IGN1cnJOYW1lU3RhcnQgPSAwOwogICAgICBjb25zdCByZWZJZFRvTmFtZSA9IFtdOwogICAgICBjb25zdCByZWZOYW1lVG9JZCA9IHt9OwogICAgICBmb3IgKGxldCBpID0gMDsgaSA8IG5hbWVzQnl0ZXMubGVuZ3RoOyBpICs9IDEpIHsKICAgICAgICBpZiAoIW5hbWVzQnl0ZXNbaV0pIHsKICAgICAgICAgIGlmIChjdXJyTmFtZVN0YXJ0IDwgaSkgewogICAgICAgICAgICBsZXQgcmVmTmFtZSA9IG5hbWVzQnl0ZXMudG9TdHJpbmcoInV0ZjgiLCBjdXJyTmFtZVN0YXJ0LCBpKTsKICAgICAgICAgICAgcmVmTmFtZSA9IHRoaXMucmVuYW1lUmVmU2VxKHJlZk5hbWUpOwogICAgICAgICAgICByZWZJZFRvTmFtZVtjdXJyUmVmSWRdID0gcmVmTmFtZTsKICAgICAgICAgICAgcmVmTmFtZVRvSWRbcmVmTmFtZV0gPSBjdXJyUmVmSWQ7CiAgICAgICAgICB9CiAgICAgICAgICBjdXJyTmFtZVN0YXJ0ID0gaSArIDE7CiAgICAgICAgICBjdXJyUmVmSWQgKz0gMTsKICAgICAgICB9CiAgICAgIH0KICAgICAgcmV0dXJuIHsgcmVmTmFtZVRvSWQsIHJlZklkVG9OYW1lIH07CiAgICB9CiAgICBhc3luYyBibG9ja3NGb3JSYW5nZShyZWZOYW1lLCBtaW4sIG1heCwgb3B0cyA9IHt9KSB7CiAgICAgIGlmIChtaW4gPCAwKSB7CiAgICAgICAgbWluID0gMDsKICAgICAgfQogICAgICBjb25zdCBpbmRleERhdGEgPSBhd2FpdCB0aGlzLnBhcnNlKG9wdHMpOwogICAgICBpZiAoIWluZGV4RGF0YSkgewogICAgICAgIHJldHVybiBbXTsKICAgICAgfQogICAgICBjb25zdCByZWZJZCA9IGluZGV4RGF0YS5yZWZOYW1lVG9JZFtyZWZOYW1lXTsKICAgICAgY29uc3QgYmEgPSBpbmRleERhdGEuaW5kaWNlc1tyZWZJZF07CiAgICAgIGlmICghYmEpIHsKICAgICAgICByZXR1cm4gW107CiAgICAgIH0KICAgICAgY29uc3QgbWluT2Zmc2V0ID0gYmEubGluZWFySW5kZXgubGVuZ3RoID8gYmEubGluZWFySW5kZXhbbWluID4+IFRBRF9MSURYX1NISUZUID49IGJhLmxpbmVhckluZGV4Lmxlbmd0aCA/IGJhLmxpbmVhckluZGV4Lmxlbmd0aCAtIDEgOiBtaW4gPj4gVEFEX0xJRFhfU0hJRlRdIDogbmV3IFZpcnR1YWxPZmZzZXQoMCwgMCk7CiAgICAgIGlmICghbWluT2Zmc2V0KSB7CiAgICAgICAgY29uc29sZS53YXJuKCJxdWVyeWluZyBvdXRzaWRlIG9mIHBvc3NpYmxlIHRhYml4IHJhbmdlIik7CiAgICAgIH0KICAgICAgY29uc3Qgb3ZlcmxhcHBpbmdCaW5zID0gcmVnMmJpbnMobWluLCBtYXgpOwogICAgICBjb25zdCBjaHVua3MgPSBbXTsKICAgICAgZm9yIChjb25zdCBbc3RhcnQsIGVuZF0gb2Ygb3ZlcmxhcHBpbmdCaW5zKSB7CiAgICAgICAgZm9yIChsZXQgYmluID0gc3RhcnQ7IGJpbiA8PSBlbmQ7IGJpbisrKSB7CiAgICAgICAgICBpZiAoYmEuYmluSW5kZXhbYmluXSkgewogICAgICAgICAgICBjb25zdCBiaW5DaHVua3MgPSBiYS5iaW5JbmRleFtiaW5dOwogICAgICAgICAgICBmb3IgKGxldCBjID0gMDsgYyA8IGJpbkNodW5rcy5sZW5ndGg7ICsrYykgewogICAgICAgICAgICAgIGNodW5rcy5wdXNoKG5ldyBDaHVuayhiaW5DaHVua3NbY10ubWludiwgYmluQ2h1bmtzW2NdLm1heHYsIGJpbikpOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9CiAgICAgIGNvbnN0IG5pbnR2ID0gYmEubGluZWFySW5kZXgubGVuZ3RoOwogICAgICBsZXQgbG93ZXN0ID0gbnVsbDsKICAgICAgY29uc3QgbWluTGluID0gTWF0aC5taW4obWluID4+IDE0LCBuaW50diAtIDEpOwogICAgICBjb25zdCBtYXhMaW4gPSBNYXRoLm1pbihtYXggPj4gMTQsIG5pbnR2IC0gMSk7CiAgICAgIGZvciAobGV0IGkgPSBtaW5MaW47IGkgPD0gbWF4TGluOyArK2kpIHsKICAgICAgICBjb25zdCB2cCA9IGJhLmxpbmVhckluZGV4W2ldOwogICAgICAgIGlmICh2cCkgewogICAgICAgICAgaWYgKCFsb3dlc3QgfHwgdnAuY29tcGFyZVRvKGxvd2VzdCkgPCAwKSB7CiAgICAgICAgICAgIGxvd2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taW5TaGlmdCArIHRoaXMuZGVwdGggKiAzKTsKICAgICAgY29uc3QgYXV4TGVuZ3RoID0gYnl0ZXMucmVhZEludDMyTEUoMTIpOwogICAgICBjb25zdCBhdXggPSBhdXhMZW5ndGggJiYgYXV4TGVuZ3RoID49IDMwID8gdGhpcy5wYXJzZUF1eERhdGEoYnl0ZXMsIDE2KSA6IHsKICAgICAgICByZWZJZFRvTmFtZTogW10sCiAgICAgICAgcmVmTmFtZVRvSWQ6IHt9LAogICAgICAgIG1ldGFDaGFyOiBudWxsLAogICAgICAgIGNvbHVtbk51bWJlcnM6IHsgcmVmOiAwLCBzdGFydDogMSwgZW5kOiAyIH0sCiAgICAgICAgY29vcmRpbmF0ZVR5cGU6ICJ6ZXJvLWJhc2VkLWhhbGYtb3BlbiIsCiAgICAgICAgZm9ybWF0OiAiZ2VuZXJpYyIKICAgICAgfTsKICAgICAgY29uc3QgcmVmQ291bnQgPSBieXRlcy5yZWFkSW50MzJMRSgxNiArIGF1eExlbmd0aCk7CiAgICAgIGxldCBmaXJzdERhdGFMaW5lOwogICAgICBsZXQgY3Vyck9mZnNldCA9IDE2ICsgYXV4TGVuZ3RoICsgNDsKICAgICAgY29uc3QgaW5kaWNlcyA9IG5ldyBBcnJheShyZWZDb3VudCkuZmlsbCgwKS5tYXAoKCkgPT4gewogICAgICAgIGNvbnN0IGJpbkNvdW50ID0gYnl0ZXMucmVhZEludDMyTEUoY3Vyck9mZnNldCk7CiAgICAgICAgY3Vyck9mZnNldCArPSA0OwogICAgICAgIGNvbnN0IGJpbkluZGV4ID0ge307CiAgICAgICAgbGV0IHN0YXRzOwogICAgICAgIGZvciAobGV0IGogPSAwOyBqIDwgYmluQ291bnQ7IGogKz0gMSkgewogICAgICAgICAgY29uc3QgYmluID0gYnl0ZXMucmVhZFVJbnQzMkxFKGN1cnJPZmZzZXQpOwogICAgICAgICAgaWYgKGJpbiA+IHRoaXMubWF4QmluTnVtYmVyKSB7CiAgICAgICAgICAgIHN0YXRzID0gdGhpcy5wYXJzZVBzZXVkb0JpbihieXRlcywgY3Vyck9mZnNldCArIDQpOwogICAgICAgICAgICBjdXJyT2Zmc2V0ICs9IDQgKyA4ICsgNCArIDE2ICsgMTY7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBjb25zdCBsb2Zmc2V0ID0gZnJvbUJ5dGVzKGJ5dGVzLCBjdXJyT2Zmc2V0ICsgNCk7CiAgICAgICAgICAgIGZpcnN0RGF0YUxpbmUgPSB0aGlzLl9maW5kRmlyc3REYXRhKGZpcnN0RGF0YUxpbmUsIGxvZmZzZXQpOwogICAgICAgICAgICBjb25zdCBjaHVua0NvdW50ID0gYnl0ZXMucmVhZEludDMyTEUoY3Vyck9mZnNldCArIDEyKTsKICAgICAgICAgICAgY3Vyck9mZnNldCArPSAxNjsKICAgICAgICAgICAgY29uc3QgY2h1bmtzID0gbmV3IEFycmF5KGNodW5rQ291bnQpOwogICAgICAgICAgICBmb3IgKGxldCBrID0gMDsgayA8IGNodW5rQ291bnQ7IGsgKz0gMSkgewogICAgICAgICAgICAgIGNvbnN0IHUgPSBmcm9tQnl0ZXMoYnl0ZXMsIGN1cnJPZmZzZXQpOwogICAgICAgICAgICAgIGNvbnN0IHYgPSBmcm9tQnl0ZXMoYnl0ZXMsIGN1cnJPZmZzZXQgKyA4KTsKICAgICAgICAgICAgICBjdXJyT2Zmc2V0ICs9IDE2OwogICAgICAgICAgICAgIGNodW5rc1trXSA9IG5ldyBDaHVuayh1LCB2LCBiaW4pOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGJpbkluZGV4W2Jpbl0gPSBjaHVua3M7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiB7IGJpbkluZGV4LCBzdGF0cyB9OwogICAgICB9KTsKICAgICAgcmV0dXJuIHsKICAgICAgICAuLi5hdXgsCiAgICAgICAgY3NpOiB0cnVlLAogICAgICAgIHJlZkNvdW50LAogICAgICAgIG1heEJsb2NrU2l6ZTogMSA8PCAxNiwKICAgICAgICBmaXJzdERhdGFMaW5lLAogICAgICAgIGNzaVZlcnNpb24sCiAgICAgICAgaW5kaWNlcywKICAgICAgICBkZXB0aDogdGhpcy5kZXB0aCwKICAgICAgICBtYXhCaW5OdW1iZXI6IHRoaXMubWF4QmluTnVtYmVyLAogICAgICAgIG1heFJlZkxlbmd0aAogICAgICB9OwogICAgfQogICAgcGFyc2VQc2V1ZG9CaW4oYnl0ZXMsIG9mZnNldCkgewogICAgICBjb25zdCBsaW5lQ291bnQgPSBsb25nVG9OdW1iZXIoaW1wb3J0X2xvbmczLmRlZmF1bHQuZnJvbUJ5dGVzTEUoYnl0ZXMuc2xpY2Uob2Zmc2V0ICsgMjgsIG9mZnNldCArIDM2KSwgdHJ1ZSkpOwogICAgICByZXR1cm4geyBsaW5lQ291bnQgfTsKICAgIH0KICAgIGFzeW5jIGJsb2Nrc0ZvclJhbmdlKHJlZk5hbWUsIG1pbiwgbWF4LCBvcHRzID0ge30pIHsKICAgICAgaWYgKG1pbiA8IDApIHsKICAgICAgICBtaW4gPSAwOwogICAgICB9CiAgICAgIGNvbnN0IGluZGV4RGF0YSA9IGF3YWl0IHRoaXMucGFyc2Uob3B0cyk7CiAgICAgIGlmICghaW5kZXhEYXRhKSB7CiAgICAgICAgcmV0dXJuIFtdOwogICAgICB9CiAgICAgIGNvbnN0IHJlZklkID0gaW5kZXhEYXRhLnJlZk5hbWVUb0lkW3JlZk5hbWVdOwogICAgICBjb25zdCBiYSA9IGluZGV4RGF0YS5pbmRpY2VzW3JlZklkXTsKICAgICAgaWYgKCFiYSkgewogICAgICAgIHJldHVybiBbXTsKICAgICAgfQogICAgICBjb25zdCBvdmVybGFwcGluZ0JpbnMgPSB0aGlzLnJlZzJiaW5zKG1pbiwgbWF4KTsKICAgICAgY29uc3QgY2h1bmtzID0gW107CiAgICAgIGZvciAoY29uc3QgW3N0YXJ0LCBlbmRdIG9mIG92ZXJsYXBwaW5nQmlucykgewogICAgICAgIGZvciAobGV0IGJpbiA9IHN0YXJ0OyBiaW4gPD0gZW5kOyBiaW4rKykgewogICAgICAgICAgaWYgKGJhLmJpbkluZGV4W2Jpbl0pIHsKICAgICAgICAgICAgY29uc3QgYmluQ2h1bmtzID0gYmEuYmluSW5kZXhbYmluXTsKICAgICAgICAgICAgZm9yIChsZXQgYyA9IDA7IGMgPCBiaW5DaHVua3MubGVuZ3RoOyArK2MpIHsKICAgICAgICAgICAgICBjaHVua3MucHVzaChuZXcgQ2h1bmsoYmluQ2h1bmtzW2NdLm1pbnYsIGJpbkNodW5rc1tjXS5tYXh2LCBiaW4pKTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgICByZXR1cm4gb3B0aW1pemVDaHVua3MoY2h1bmtzLCBuZXcgVmlydHVhbE9mZnNldCgwLCAwKSk7CiAgICB9CiAgICByZWcyYmlucyhiZWcsIGVuZCkgewogICAgICBiZWcgLT0gMTsKICAgICAgaWYgKGJlZyA8IDEpIHsKICAgICAgICBiZWcgPSAxOwogICAgICB9CiAgICAgIGlmIChlbmQgPiAyICoqIDUwKSB7CiAgICAgICAgZW5kID0gMiAqKiAzNDsKICAgICAgfQogICAgICBlbmQgLT0gMTsKICAgICAgbGV0IGwgPSAwOwogICAgICBsZXQgdCA9IDA7CiAgICAgIGxldCBzID0gdGhpcy5taW5TaGlmdCArIHRoaXMuZGVwdGggKiAzOwogICAgICBjb25zdCBiaW5zID0gW107CiAgICAgIGZvciAoOyBsIDw9IHRoaXMuZGVwdGg7IHMgLT0gMywgdCArPSBsc2hpZnQoMSwgbCAqIDMpLCBsICs9IDEpIHsKICAgICAgICBjb25zdCBiID0gdCArIHJzaGlmdChiZWcsIHMpOwogICAgICAgIGNvbnN0IGUgPSB0ICsgcnNoaWZ0KGVuZCwgcyk7CiAgICAgICAgaWYgKGUgLSBiICsgYmlucy5sZW5ndGggPiB0aGlzLm1heEJpbk51bWJlcikgewogICAgICAgICAgdGhyb3cgbmV3IEVycm9yKGBxdW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iik7CiAgICB9CiAgICBhc3luYyBnZXRSZWZlcmVuY2VTZXF1ZW5jZU5hbWVzKG9wdHMgPSB7fSkgewogICAgICBjb25zdCBtZXRhZGF0YSA9IGF3YWl0IHRoaXMuZ2V0TWV0YWRhdGEob3B0cyk7CiAgICAgIHJldHVybiBtZXRhZGF0YS5yZWZJZFRvTmFtZTsKICAgIH0KICAgIGNoZWNrTGluZShtZXRhZGF0YSwgcmVnaW9uUmVmTmFtZSwgcmVnaW9uU3RhcnQsIHJlZ2lvbkVuZCwgbGluZSkgewogICAgICBjb25zdCB7IGNvbHVtbk51bWJlcnMsIG1ldGFDaGFyLCBjb29yZGluYXRlVHlwZSwgZm9ybWF0IH0gPSBtZXRhZGF0YTsKICAgICAgaWYgKGxpbmUuY2hhckF0KDApID09PSBtZXRhQ2hhcikgewogICAgICAgIHJldHVybiB7IG92ZXJsYXBzOiBmYWxzZSB9OwogICAgICB9CiAgICAgIGxldCB7IHJlZiwgc3RhcnQsIGVuZCB9ID0gY29sdW1uTnVtYmVyczsKICAgICAgaWYgKCFyZWYpIHsKICAgICAgICByZWYgPSAwOwogICAgICB9CiAgICAgIGlmICghc3RhcnQpIHsKICAgICAgICBzdGFydCA9IDA7CiAgICAgIH0KICAgICAgaWYgKCFlbmQpIHsKICAgICAgICBlbmQgPSAwOwogICAgICB9CiAgICAgIGlmIChmb3JtYXQgPT09ICJWQ0YiKSB7CiAgICAgICAgZW5kID0gODsKICAgICAgfQogICAgICBjb25zdCBtYXhDb2x1bW4gPSBNYXRoLm1heChyZWYsIHN0YXJ0LCBlbmQpOwogICAgICBsZXQgY3VycmVudENvbHVtbk51bWJlciA9IDE7CiAgICAgIGxldCBjdXJyZW50Q29sdW1uU3RhcnQgPSAwOwogICAgICBsZXQgcmVmU2VxID0gIiI7CiAgICAgIGxldCBzdGFydENvb3JkaW5hdGUgPSAtSW5maW5pdHk7CiAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgbGluZS5sZW5ndGggKyAxOyBpICs9IDEpIHsKICAgICAgICBpZiAobGluZVtpXSA9PT0gIgkiIHx8IGkgPT09IGxpbmUubGVuZ3RoKSB7CiAgICAgICAgICBpZiAoY3VycmVudENvbHVtbk51bWJlciA9PT0gcmVmKSB7CiAgICAgICAgICAgIGlmICh0aGlzLnJlbmFtZVJlZlNlcShsaW5lLnNsaWNlKGN1cnJlbnRDb2x1bW5TdGFydCwgaSkpICE9PSByZWdpb25SZWZOYW1lKSB7CiAgICAgICAgICAgICAgcmV0dXJuIHsgb3ZlcmxhcHM6IGZhbHNlIH07CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSBpZiAoY3VycmVudENvbHVtbk51bWJlciA9PT0gc3RhcnQpIHsKICAgICAgICAgICAgc3RhcnRDb29yZGluYXRlID0gcGFyc2VJbnQobGluZS5zbGljZShjdXJyZW50Q29sdW1uU3RhcnQsIGkpLCAxMCk7CiAgICAgICAgICAgIGlmIChjb29yZGluYXRlVHlwZSA9PT0gIjEtYmFzZWQtY2xvc2VkIikgewogICAgICAgICAgICAgIHN0YXJ0Q29vcmRpbmF0ZSAtPSAxOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzdGFydENvb3JkaW5hdGUgPj0gcmVnaW9uRW5kKSB7CiAgICAgICAgICAgICAgcmV0dXJuIHsgc3RhcnRDb29yZGluYXRlLCBvdmVybGFwczogZmFsc2UgfTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoZW5kID09PSAwIHx8IGVuZCA9PT0gc3RhcnQpIHsKICAgICAgICAgICAgICBpZiAoc3RhcnRDb29yZGluYXRlICsgMSA8PSByZWdpb25TdGFydCkgewogICAgICAgICAgICAgICAgcmV0dXJuIHsgc3RhcnRDb29yZGluYXRlLCBvdmVybGFwczogZmFsc2UgfTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSBpZiAoZm9ybWF0ID09PSAiVkNGIiAmJiBjdXJyZW50Q29sdW1uTnVtYmVyID09PSA0KSB7CiAgICAgICAgICAgIHJlZlNlcSA9IGxpbmUuc2xpY2UoY3VycmVudENvbHVtblN0YXJ0LCBpKTsKICAgICAgICAgIH0gZWxzZSBpZiAoY3VycmVudENvbHVtbk51bWJlciA9PT0gZW5kKSB7CiAgICAgICAgICAgIGxldCBlbmRDb29yZGluYXRlOwogICAgICAgICAgICBpZiAoZm9ybWF0ID09PSAiVkNGIikgewogICAgICAgICAgICAgIGVuZENvb3JkaW5hdGUgPSB0aGlzLl9nZXRWY2ZFbmQoc3RhcnRDb29yZGluYXRlLCByZWZTZXEsIGxpbmUuc2xpY2UoY3VycmVudENvbHVtblN0YXJ0LCBpKSk7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgZW5kQ29vcmRpbmF0ZSA9IHBhcnNlSW50KGxpbmUuc2xpY2UoY3VycmVudENvbHVtblN0YXJ0LCBpKSwgMTApOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChlbmRDb29yZGluYXRlIDw9IHJlZ2lvblN0YXJ0KSB7CiAgICAgICAgICAgICAgcmV0dXJuIHsgb3ZlcmxhcHM6IGZhbHNlIH07CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGN1cnJlbnRDb2x1bW5TdGFydCA9IGkgKyAxOwogICAgICAgICAgY3VycmVudENvbHVtbk51bWJlciArPSAxOwogICAgICAgICAgaWYgKGN1cnJlbnRDb2x1bW5OdW1iZXIgPiBtYXhDb2x1bW4pIHsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9CiAgICAgIHJldHVybiB7IHN0YXJ0Q29vcmRpbmF0ZSwgb3ZlcmxhcHM6IHRydWUgfTsKICAgIH0KICAgIF9nZXRWY2ZFbmQoc3RhcnRDb29yZGluYXRlLCByZWZTZXEsIGluZm8pIHsKICAgICAgbGV0IGVuZENvb3JkaW5hdGUgPSBzdGFydENvb3JkaW5hdGUgKyByZWZTZXEubGVuZ3RoOwogICAgICBjb25zdCBpc1RSQSA9IGluZm8uaW5kZXhPZigiU1ZUWVBFPVRSQSIpICE9PSAtMTsKICAgICAgaWYgKGluZm9bMF0gIT09ICIuIiAmJiAhaXNUUkEpIHsKICAgICAgICBsZXQgcHJldkNoYXIgPSAiOyI7CiAgICAgICAgZm9yIChsZXQgaiA9IDA7IGogPCBpbmZvLmxlbmd0aDsgaiArPSAxKSB7CiAgICAgICAgICBpZiAocHJldkNoYXIgPT09ICI7IiAmJiBpbmZvLnNsaWNlKGosIGogKyA0KSA9PT0gIkVORD0iKSB7CiAgICAgICAgICAgIGxldCB2YWx1ZUVuZCA9IGluZm8uaW5kZXhPZigiOyIsIGopOwogICAgICAgICAgICBpZiAodmFsdWVFbmQgPT09IC0xKSB7CiAgICAgICAgICAgICAgdmFsdWVFbmQgPSBpbmZvLmxlbmd0aDsKICAgICAgICAgICAgfQogICAgICAgICAgICBlbmRDb29yZGluYXRlID0gcGFyc2VJbnQoaW5mby5zbGljZShqICsgNCwgdmFsdWVFbmQpLCAxMCk7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgICAgcHJldkNoYXIgPSBpbmZvW2pdOwogICAgICAgIH0KICAgICAgfSBlbHNlIGlmIChpc1RSQSkgewogICAgICAgIHJldHVybiBzdGFydENvb3JkaW5hdGUgKyAxOwogICAgICB9CiAgICAgIHJldHVybiBlbmRDb29yZGluYXRlOwogICAgfQogICAgYXN5bmMgbGluZUNvdW50KHJlZk5hbWUsIG9wdHMgPSB7fSkgewogICAgICByZXR1cm4gdGhpcy5pbmRleC5saW5lQ291bnQocmVmTmFtZSwgb3B0cyk7CiAgICB9CiAgICBhc3luYyBfcmVhZFJlZ2lvbihwb3MsIHNpemUsIG9wdHMgPSB7fSkgewogICAgICBjb25zdCBiID0gaW1wb3J0X2J1ZmZlcjcuQnVmZmVyLmFsbG9jKHNpemUpOwogICAgICBjb25zdCB7IGJ5dGVzUmVhZCwgYnVmZmVyIH0gPSBhd2F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xOwogICAgICAgIGVsc2UKICAgICAgICAgIGhpID0gbWlkOwogICAgICB9CiAgICAgIHJldHVybiBsbzsKICAgIH0KICAgIGZ1bmN0aW9uIHJpZ2h0KGEsIHgsIGxvLCBoaSkgewogICAgICBpZiAobG8gPT0gbnVsbCkKICAgICAgICBsbyA9IDA7CiAgICAgIGlmIChoaSA9PSBudWxsKQogICAgICAgIGhpID0gYS5sZW5ndGg7CiAgICAgIHdoaWxlIChsbyA8IGhpKSB7CiAgICAgICAgY29uc3QgbWlkID0gbG8gKyBoaSA+Pj4gMTsKICAgICAgICBpZiAoY29tcGFyZShhW21pZF0sIHgpID4gMCkKICAgICAgICAgIGhpID0gbWlkOwogICAgICAgIGVsc2UKICAgICAgICAgIGxvID0gbWlkICsgMTsKICAgICAgfQogICAgICByZXR1cm4gbG87CiAgICB9CiAgICBmdW5jdGlvbiBjZW50ZXIoYSwgeCwgbG8sIGhpKSB7CiAgICAgIGlmIChsbyA9PSBudWxsKQogICAgICAgIGxvID0gMDsKICAgICAgaWYgKGhpID09IG51bGwpCiAgICAgICAgaGkgPSBhLmxlbmd0aDsKICAgICAgY29uc3QgaSA9IGxlZnQoYSwgeCwgbG8sIGhpIC0gMSk7CiAgICAgIHJldHVybiBpID4gbG8gJiYgZGVsdGEoYVtpIC0gMV0sIHgpID4gLWRlbHRhKGFbaV0sIHgpID8gaSAtIDEgOiBpOwogICAgfQogICAgcmV0dXJuIHsgbGVmdCwgY2VudGVyLCByaWdodCB9OwogIH0KICBmdW5jdGlvbiBhc2NlbmRpbmdDb21wYXJhdG9yKGYpIHsKICAgIHJldHVybiAoZCwgeCkgPT4gYXNjZW5kaW5nX2RlZmF1bHQoZihkKSwgeCk7CiAgfQoKICAvLyBzcmMvZGF0YS1mZXRjaGVycy91dGlscy50cwogIHZhciBEYXRhU291cmNlID0gY2xhc3MgewogICAgY29uc3RydWN0b3IoZmlsZSwgY2hyb21TaXplcywgb3B0aW9ucykgewogICAgICB0aGlzLmZpbGUgPSBm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bCA9IGZpZWxkc1tpXTsKICAgICAgICAgIGNvbnN0IHsgaXNOdW1lcmljLCBpc0FycmF5OiBpc0FycmF5MiwgYXJyYXlJc051bWVyaWMsIG5hbWUgfSA9IGF1dG9GaWVsZDsKICAgICAgICAgIGlmIChjb2x1bW5WYWwgPT09IG51bGwgfHwgY29sdW1uVmFsID09PSB2b2lkIDApIHsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoY29sdW1uVmFsICE9PSAiLiIpIHsKICAgICAgICAgICAgaWYgKGlzTnVtZXJpYykgewogICAgICAgICAgICAgIGNvbnN0IG51bSA9IE51bWJlcihjb2x1bW5WYWwpOwogICAgICAgICAgICAgIGNvbHVtblZhbCA9IE51bWJlci5pc05hTihudW0pID8gY29sdW1uVmFsIDogbnVtOwogICAgICAgICAgICB9IGVsc2UgaWYgKGlzQXJyYXkyKSB7CiAgICAgICAgICAgICAgY29sdW1uVmFsID0gY29sdW1uVmFsLnNwbGl0KCIsIik7CiAgICAgICAgICAgICAgaWYgKGNvbHVtblZhbFtjb2x1bW5WYWwubGVuZ3RoIC0gMV0gPT09ICIiKSB7CiAgICAgICAgICAgICAgICBjb2x1bW5WYWwucG9wKCk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGlmIChhcnJheUlzTnVtZXJpYykgewogICAgICAgICAgICAgICAgY29sdW1uVmFsID0gY29sdW1uVmFsLm1hcCgoc3RyKSA9PiBOdW1iZXIoc3RyKSk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGZlYXR1cmVbbmFtZV0gPSBjb2x1bW5WYWw7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9IGVsc2UgewogICAgICAgIGNvbnN0IGZpZWxkTmFtZXMgPSBbImNocm9tIiwgImNocm9tU3RhcnQiLCAiY2hyb21FbmQiLCAibmFtZSJdOwogICAgICAgIGZlYXR1cmUgPSBPYmplY3QuZnJvbUVudHJpZXMoZmllb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lkKTsKICAgICAgY29uc3QgeyBjaHJvbUxlbmd0aHMsIGN1bVBvc2l0aW9ucyB9ID0gc291cmNlLmNocm9tSW5mbzsKICAgICAgbGV0IG5fY29scyA9IDA7CiAgICAgIGZvciAoY29uc3QgY3VtUG9zIG9mIGN1bVBvc2l0aW9ucykgewogICAgICAgIGNvbnN0IGNocm9tTmFtZSA9IGN1bVBvcy5jaHI7CiAgICAgICAgY29uc3QgY2hyb21TdGFydCA9IGN1bVBvcy5wb3M7CiAgICAgICAgY29uc3QgY2hyb21FbmQgPSBjdW1Qb3MucG9zICsgY2hyb21MZW5ndGhzW2Nocm9tTmFtZV07CiAgICAgICAgbl9jb2xzID0gYXdhaXQgbmV3IFByb21pc2UoKHJlc29sdmUpID0+IHsKICAgICAgICAgIHNvdXJjZS5maWxlLnRiaS5nZXRMaW5lcyhjaHJvbU5hbWUsIGNocm9tU3RhcnQsIGNocm9tRW5kLCAobGluZSkgPT4gewogICAgICAgICAgICByZXNvbHZlKGxpbmUuc3BsaXQoIgkiKS5sZW5ndGgpOwogICAgICAgICAgfSk7CiAgICAgICAgfSk7CiAgICAgICAgaWYgKG5fY29scyA+IDApCiAgICAgICAgICBicmVhazsKICAgICAgfQogICAgICByZXR1cm4gbl9jb2xzOwogICAgfQogICAgYXN5bmMgZ2V0VGlsZURhdGEobWluWCwgbWF4WCkgewogICAgICBjb25zdCBzb3VyY2UgPSBkYXRhU291cmNlcy5nZXQodGhpcy4jdWlkKTsKICAgICAgY29uc3QgcGFyc2VyMiA9IGF3YWl0IHRoaXMuZ2V0UGFyc2VyKCk7CiAgICAgIGxldCBjdXJNaW5YID0gbWluWDsKICAgICAgY29uc3QgeyBjaHJvbUxlbmd0aHMsIGN1bVBvc2l0aW9ucyB9ID0gc291cmNlLmNocm9tSW5mbzsKICAgICAgY29uc3QgYWxsVGlsZXMgPSBbXTsKICAgICAgZm9yIChjb25zdCBjdW1Qb3Mgb2YgY3VtUG9zaXRpb25zKSB7CiAgICAgICAgY29uc3QgY2hyb21OYW1lID0gY3VtUG9zLmNocjsKICAgICAgICBjb25zdCBjaHJvbVN0YXJ0ID0gY3VtUG9zLnBvczsKICAgICAgICBjb25zdCBjaHJvbUVuZCA9IGN1bVBvcy5wb3MgKyBjaHJvbUxlbmd0aHNbY2hyb21OYW1lXTsKICAgICAgICBsZXQgc3RhcnRQb3MsIGVuZFBvczsKICAgICAgICBpZiAoY2hyb21TdGFydCA+IGN1ck1pblggfHwgY3VyTWluWCA+PSBjaHJvbUVuZCkgewogICAgICAgICAgY29udGludWU7CiAgICAgICAgfQogICAgICAgIGNvbnN0IHRpbGVzUHJvbWlzZSA9IG5ldyBQcm9taXNlKChyZXNvbHZlKSA9PiB7CiAgICAgICAgICBjb25zdCB0aWxlcyA9IFtdOwogICAgICAgICAgY29uc3QgbGluZUNhbGxiYWNrID0gKGxpbmUpID0+IHsKICAgICAgICAgICAgY29uc3QgYmVkVGlsZSA9IHBhcnNlcjIucGFyc2VMaW5lKGxpbmUsIGNocm9tU3RhcnQpOwogICAgICAgICAgICB0aWxlcy5wdXNoKGJlZFRpbGUpOwogICAgICAgICAgfTsKICAgICAgICAgIGlmIChtYXhYID4gY2hyb21FbmQpIHsKICAgICAgICAgICAgc3RhcnRQb3MgPSBjdXJNaW5YIC0gY2hyb21TdGFydDsKICAgICAgICAgICAgZW5kUG9zID0gY2hyb21FbmQgLSBjaHJvbVN0YXJ0OwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgc3RhcnRQb3MgPSBNYXRoLmZsb29yKGN1ck1pblggLSBjaHJvbVN0YXJ0KTsKICAgICAgICAgICAgZW5kUG9zID0gTWF0aC5jZWlsKG1heFggLSBjaHJvbVN0YXJ0KTsKICAgICAgICAgIH0KICAgICAgICAgIHNvdXJjZS5maWxlLnRiaS5nZXRMaW5lcyhjaHJvbU5hbWUsIHN0YXJ0UG9zLCBlbmRQb3MsIGxpbmVDYWxsYmFjaykudGhlbigoKSA9PiB7CiAgICAgICAgICAgIHJlc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iZXIuaXNOYU4oeCkgfHwgTnVtYmVyLmlzTmFOKHopKSB7CiAgICAgICAgY29uc29sZS53YXJuKCJJbnZhbGlkIHRpbGUgem9vbSBvciBwb3NpdGlvbjoiLCB6LCB4KTsKICAgICAgICBjb250aW51ZTsKICAgICAgfQogICAgICB2YWxpZFRpbGVJZHMucHVzaCh0aWxlSWQpOwogICAgICB0aWxlUHJvbWlzZXMucHVzaCh0aWxlKHVpZCwgeiwgeCkpOwogICAgfQogICAgcmV0dXJuIFByb21pc2UuYWxsKHRpbGVQcm9taXNlcykudGhlbigodmFsdWVzMikgPT4gewogICAgICBmb3IgKGxldCBpID0gMDsgaSA8IHZhbHVlczIubGVuZ3RoOyBpKyspIHsKICAgICAgICBjb25zdCB2YWxpZFRpbGVJZCA9IHZhbGlkVGlsZUlkc1tpXTsKICAgICAgICB0aWxlc1t2YWxpZFRpbGVJZF0gPSB7IHRpbGVQb3NpdGlvbklkOiB2YWxpZFRpbGVJZCB9OwogICAgICB9CiAgICAgIHJldHVybiB0aWxlczsKICAgIH0pOwogIH07CiAgdmFyIGdldFRhYnVsYXJEYXRhID0gKHVpZCwgdGlsZUlkcykgPT4gewogICAgY29uc3QgZGF0YSA9IFtdOwogICAgdGlsZUlkcy5mb3JFYWNoKCh0aWxlSWQpID0+IHsKICAgICAgY29uc3QgcGFydHMgPSB0aWxlSWQuc3BsaXQoIi4iKTsKICAgICAgY29uc3QgeiA9IHBhcnNlSW50KHBhcnRzWzBdLCAxMCk7CiAgICAgIGNvbnN0IHggPSBwYXJzZUludChwYXJ0c1sxXSwgMTApOwogICAgICBjb25zdCB0aWxlVmFsdWUgPSB0aWxlVmFsdWVzW2Ake3VpZH0uJHt6fS4ke3h9YF07CiAgICAgIGlmICghdGlsZVZhbHVlKSB7CiAgICAgICAgY29uc29sZS53YXJuKGBObyB0aWxlIGRhdGEgY29uc3RydWN0ZWQgKCR7dGlsZUlkfSlgKTsKICAgICAgfQogICAgICBkYXRhLnB1c2godGlsZVZhb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9kdWxhcml6ZSBleHBvcnRzPSJlcyIgLW8gLi9gCiAqIENvcHlyaWdodCBPcGVuSlMgRm91bmRhdGlvbiBhbmQgb3RoZXIgY29udHJpYnV0b3JzIDxodHRwczovL29wZW5qc2Yub3JnLz4KICogUmVsZWFzZWQgdW5kZXIgTUlUIGxpY2Vuc2UgPGh0dHBzOi8vbG9kYXNoLmNvbS9saWNlbnNlPgogKiBCYXNlZCBvbiBVbmRlcnNjb3JlLmpzIDEuOC4zIDxodHRwOi8vdW5kZXJzY29yZWpzLm9yZy9MSUNFTlNFPgogKiBDb3B5cmlnaHQgSmVyZW15IEFzaGtlbmFzLCBEb2N1bWVudENsb3VkIGFuZCBJbnZlc3RpZ2F0aXZlIFJlcG9ydGVycyAmIEVkaXRvcnMKICovCg==",Jle=typeof window<"u"&&window.Blob&&new Blob([atob($He)],{type:"text/javascript;charset=utf-8"});function ugg(){const g=Jle&&(window.URL||window.webkitURL).createObjectURL(Jle);try{return g?new Worker(g):new Worker("data:application/javascript;base64,"+$He,{type:"module"})}finally{g&&(window.URL||window.webkitURL).revokeObjectURL(g)}}const dgg=200;class qHe{constructor(e,I){nt(this,"dataConfig",{}),nt(this,"uid"),nt(this,"prevRequestTime"),nt(this,"track"),nt(this,"toFetch"),nt(this,"fetchTimeout"),nt(this,"worker"),this.uid=e.libraries.slugid.nice(),this.prevRequestTime=0,this.toFetch=new Set;const{url:i,indexUrl:n,assembly:C,...r}=I;this.worker=dN(new ugg).then(async o=>{const A=Object.entries(yI(C).size);return await o.init(this.uid,{url:i,indexUrl:n},A,r),o})}async tilesetInfo(e){(await this.worker).tilesetInfo(this.uid).then(e)}fetchTilesDebounced(e,I){this.track.drawLoadingCue(),I.forEach(i=>this.toFetch.add(i)),this.fetchTimeout&&clearTimeout(this.fetchTimeout),this.fetchTimeout=setTimeout(()=>{this.sendFetch(e,[...this.toFetch]),this.toFetch.clear()},dgg)}async sendFetch(e,I){(await this.worker).fetchTilesDebounced(this.uid,I).then(e)}async getTabularData(e){const I=await(await this.worker).getTabularData(this.uid,e);return JSON.parse(new TextDecoder().decode(I))}}nt(qHe,"config",{type:"bed"});const hgg=Object.freeze(Object.defineProperty({__proto__:null,BamDataFetcher:U2,BedDataFetcher:qHe,BigWigDataFetcher:OHe,CsvDataFetcher:_He,GffDataFetcher:jHe,JsonDataFetcher:UHe,VcfDataFetcher:bHe},Symbol.toStringTag,{value:"Module"})),mgg="gosling-data-row-uid";function fgg(g,e){var I,i,n,C,r,o,A,s,a,l,c,u,d,h,m,f;const b=[];if(!JU(g.data)){console.warn("No data is specified");return}if(g.data.type==="vector"||g.data.type==="bigwig"){if(!("dense"in e))return;const p=(I=g.data.binSize)!=null?I:1,y=e.dense,Z=e.tileSize,v=e.tileWidth/e.tileSize,G=(i=g.data.value)!=null?i:"value",B=(n=g.data.column)!=null?n:"position",w=(C=g.data.start)!=null?C:"start",R=(r=g.data.end)!=null?r:"end",S=`${G}_min`,X=`${G}_max`,W=(o=g.data.aggregation)!=null?o:"mean";let V=0,H=Number.MAX_SAFE_INTEGER,D=Number.MIN_SAFE_INTEGER,Y=Number.MIN_SAFE_INTEGER,F=Number.MAX_SAFE_INTEGER;Array.from(Array(Z).keys()).forEach((_,J)=>{if(p===1){const te=y[J]/(W==="mean"?v:1);b.push({[G]:te,[B]:e.tileX+(J+.5)*v,[w]:e.tileX+J*v,[R]:e.tileX+(J+1)*v,[S]:te,[X]:te})}else if(J%p===0)V=H=D=y[J],Y=J,F=J+p;else if(J%p===p-1)b.push({[G]:V/p/(W==="mean"?v:1),[B]:e.tileX+(Y+p/2)*v,[w]:e.tileX+Y*v,[R]:e.tileX+F*v,[S]:H,[X]:D});else if(J===Z-1){const te=Z%p,q=Y+te;b.push({[G]:V/te/(W==="mean"?v:1),[B]:e.tileX+(Y+te/2)*v,[w]:e.tileX+Y*v,[R]:e.tileX+q*v,[S]:H,[X]:D})}else V+=y[J],H>y[J]&&(H=y[J]),D{let _=0,J=Number.MIN_SAFE_INTEGER,te=Number.MAX_SAFE_INTEGER,q=Number.MAX_SAFE_INTEGER,$=Number.MIN_SAFE_INTEGER;Array.from(Array(G).keys()).forEach((j,ee)=>{if(p===1){const Q=v[G*F+ee]/(D==="mean"?B:1);b.push({[w]:Y,[R]:Q,[S]:e.tileX+(ee+.5)*B,[X]:e.tileX+ee*B,[W]:e.tileX+(ee+1)*B,[V]:Q,[H]:Q})}else if(ee%p===0)_=q=$=v[G*F+ee],J=ee,te=ee+p;else if(ee%p===p-1)b.push({[w]:Y,[R]:D==="mean"?_/p/B:_,[S]:e.tileX+(J+p/2)*B,[X]:e.tileX+J*B,[W]:e.tileX+te*B,[V]:q,[H]:$});else if(ee===G-1){const Q=G%p,ne=J+Q;b.push({[w]:Y,[R]:D==="mean"?_/Q/B:_,[S]:e.tileX+(J+Q/2)*B,[X]:e.tileX+J*B,[W]:e.tileX+ne*B,[V]:q,[H]:$})}else{const Q=v[G*F+ee];_+=Q,q>Q&&(q=Q),$"u"||typeof e.tileHeight>"u")return;const p=Math.sqrt(e.dense.length),{tileX:y,tileY:Z,tileWidth:v,tileHeight:G}=e,B=e.dense,w=v/p,R=G/p,S=(m=g.data.column)!=null?m:"x",X=(f=g.data.row)!=null?f:"y",W=16;for(let V=0;V{const{chrOffset:B,fields:w}=v,R={};if(R[mgg]=`${G}`,p.forEach(S=>{R[S.name]=+w[S.index]+B}),Z==null||Z.forEach(S=>{R[S.name]=S.type==="quantitative"?+w[S.index]:w[S.index]}),b.push({...R,type:"gene"}),y){const[S,X]=y,W=w[S.index].split(","),V=w[X.index].split(",");W.forEach((H,D)=>{const Y=V[D];if(b.push({...R,[S.name]:+H+B,[X.name]:+Y+B,type:"exon"}),D+1n===g.chromosome))){if(X7e(g))return[I[g.chromosome][0]+1,I[g.chromosome][1]];if(H7e(g))return g.interval;if(T7e(g)){const i=I[g.chromosome][0],[n,C]=g.interval;return[i+n,i+C]}}}function Ggg(g,e){const I={},i=xd;g.forEach(n=>{i.forEach(C=>{const r=n.spec()[C];if(!lt(r)||r.domain===void 0)return;const{domain:o,type:A}=r;if(A==="quantitative"){const s=Array.from(o);if(!I[C])I[C]=s;else{const a=I[C];a[0]>s[0]&&(a[0]=s[0]),a[1]{i.forEach(C=>{const r=n.spec()[C];lt(r)&&r.type==="genomic"||(n.setChannelDomain(C,I[C],e),n.generateScales())}),n.updateChannelValue()})}const Bgg={compactLayout:!1,trackSourceServers:["https://server.gosling-lang.org/api/v1/"],views:[{genomePositionSearchBoxVisible:!1,genomePositionSearchBox:{autocompleteServer:"https://higlass.io/api/v1",autocompleteId:"P0PLbQMwTYGy-5uPIQid7A",chromInfoServer:"https://higlass.io/api/v1",chromInfoId:"hg38"},layout:{x:0,y:0,w:6.4,h:600},tracks:{top:[],left:[{type:"combined",width:130,height:600,contents:[{type:"gosling-track",server:"https://server.gosling-lang.org/api/v1/",tilesetUid:"cistrome-multivec",width:130,height:600,options:{showMousePosition:!0,mousePositionColor:"#000000",fontSize:24,labelPosition:"none",labelShowResolution:!1,labelColor:"black",labelBackgroundColor:"white",labelTextOpacity:1,labelLeftMargin:1,labelTopMargin:1,labelRightMargin:0,labelBottomMargin:0,backgroundColor:"transparent",spec:{spacing:10,orientation:"vertical",assembly:"hg38",layout:"linear",static:!1,xDomain:{interval:[0,1e9]},centerRadius:.3,xOffset:0,yOffset:0,style:{outlineWidth:.5},data:{url:"https://server.gosling-lang.org/api/v1/tileset_info/?d=cistrome-multivec",type:"multivec",row:"sample",column:"position",value:"peak",categories:["sample 1","sample 2","sample 3","sample 4"],binSize:4},mark:"rect",x:{field:"start",type:"genomic",axis:"left",domain:{interval:[0,1e9]},linkingId:"7f94b74e-25ec-4e67-8c75-3dc0f1b0d6bd"},xe:{field:"end",type:"genomic"},row:{field:"sample",type:"nominal",legend:!0},color:{field:"peak",type:"quantitative",legend:!0},tooltip:[{field:"start",type:"genomic",alt:"Start Position"},{field:"end",type:"genomic",alt:"End Position"},{field:"peak",type:"quantitative",alt:"Value",format:".2"},{field:"sample",type:"nominal",alt:"Sample"}],width:160,height:600,overlayOnPreviousTrack:!1},theme:{base:"light",root:{background:"white",titleColor:"black",titleBackgroundColor:"transparent",titleFontSize:18,titleFontFamily:"Arial",titleAlign:"left",titleFontWeight:"bold",subtitleColor:"gray",subtitleBackgroundColor:"transparent",subtitleFontSize:16,subtitleFontFamily:"Arial",subtitleFontWeight:"normal",subtitleAlign:"left",mousePositionColor:"#000000"},track:{background:"transparent",alternatingBackground:"transparent",titleColor:"black",titleBackground:"white",titleFontSize:24,titleAlign:"left",outline:"black",outlineWidth:1},legend:{position:"top",background:"white",backgroundOpacity:.7,labelColor:"black",labelFontSize:12,labelFontWeight:"normal",labelFontFamily:"Arial",backgroundStroke:"#DBDBDB",tickColor:"black"},axis:{tickColor:"black",labelColor:"black",labelFontSize:12,labelFontWeight:"normal",labelFontFamily:"Arial",baselineColor:"black",gridColor:"#E3E3E3",gridStrokeWidth:1,gridStrokeType:"solid",gridStrokeDash:[4,4]},markCommon:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},point:{color:"#E79F00",size:3,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},rect:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},triangle:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},area:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},line:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},bar:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},rule:{color:"#E79F00",size:1,stroke:"black",strokeWidth:1,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},link:{color:"#E79F00",size:1,stroke:"black",strokeWidth:1,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},text:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6],textAnchor:"middle",textFontWeight:"normal"},brush:{color:"gray",size:1,stroke:"black",strokeWidth:1,opacity:.3,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]}}}}]},{uid:"15483511-f6fb-11eb-914b-976b6ecda162",type:"axis-track",chromInfoPath:"https://s3.amazonaws.com/gosling-lang.org/data/hg38.chrom.sizes",options:{layout:"linear",outerRadius:null,width:160,height:600,theme:{base:"light",root:{background:"white",titleColor:"black",titleBackgroundColor:"transparent",titleFontSize:18,titleFontFamily:"Arial",titleAlign:"left",titleFontWeight:"bold",subtitleColor:"gray",subtitleBackgroundColor:"transparent",subtitleFontSize:16,subtitleFontFamily:"Arial",subtitleFontWeight:"normal",subtitleAlign:"left",mousePositionColor:"#000000"},track:{background:"transparent",alternatingBackground:"transparent",titleColor:"black",titleBackground:"white",titleFontSize:24,titleAlign:"left",outline:"black",outlineWidth:1},legend:{position:"top",background:"white",backgroundOpacity:.7,labelColor:"black",labelFontSize:12,labelFontWeight:"normal",labelFontFamily:"Arial",backgroundStroke:"#DBDBDB",tickColor:"black"},axis:{tickColor:"black",labelColor:"black",labelFontSize:12,labelFontWeight:"normal",labelFontFamily:"Arial",baselineColor:"black",gridColor:"#E3E3E3",gridStrokeWidth:1,gridStrokeType:"solid",gridStrokeDash:[4,4]},markCommon:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},point:{color:"#E79F00",size:3,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},rect:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},triangle:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},area:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},line:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},bar:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},rule:{color:"#E79F00",size:1,stroke:"black",strokeWidth:1,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},link:{color:"#E79F00",size:1,stroke:"black",strokeWidth:1,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},text:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6],textAnchor:"middle",textFontWeight:"normal"},brush:{color:"gray",size:1,stroke:"black",strokeWidth:1,opacity:.3,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]}},assembly:"hg38",stroke:"transparent",color:"black",fontSize:12,fontFamily:"Arial",fontWeight:"normal",tickColor:"black",tickFormat:"plain",tickPositions:"even",reverseOrientation:!1},width:30}],center:[],right:[],bottom:[],gallery:[],whole:[]},initialXDomain:[0,1e9],initialYDomain:[0,1e9],zoomFixed:!1,zoomLimits:[1,null],uid:"15483510-f6fb-11eb-914b-976b6ecda162",chromInfoPath:"https://s3.amazonaws.com/gosling-lang.org/data/hg38.chrom.sizes"},{genomePositionSearchBoxVisible:!1,genomePositionSearchBox:{autocompleteServer:"https://higlass.io/api/v1",autocompleteId:"P0PLbQMwTYGy-5uPIQid7A",chromInfoServer:"https://higlass.io/api/v1",chromInfoId:"hg38"},layout:{x:6.8,y:0,w:5.2,h:600},tracks:{top:[],left:[{type:"combined",width:130,height:600,contents:[{type:"gosling-track",server:"https://server.gosling-lang.org/api/v1/",tilesetUid:"cistrome-multivec",width:130,height:600,options:{showMousePosition:!0,mousePositionColor:"#000000",fontSize:24,labelPosition:"none",labelShowResolution:!1,labelColor:"black",labelBackgroundColor:"white",labelTextOpacity:1,labelLeftMargin:1,labelTopMargin:1,labelRightMargin:0,labelBottomMargin:0,backgroundColor:"transparent",spec:{spacing:10,orientation:"vertical",assembly:"hg38",layout:"linear",static:!1,xDomain:{interval:[0,1e9]},centerRadius:.3,xOffset:0,yOffset:0,style:{outlineWidth:.5},data:{url:"https://server.gosling-lang.org/api/v1/tileset_info/?d=cistrome-multivec",type:"multivec",row:"sample",column:"position",value:"peak",categories:["sample 1","sample 2","sample 3","sample 4"],binSize:4},mark:"rect",x:{field:"start",type:"genomic",domain:{interval:[0,1e9]},linkingId:"7f94b74e-25ec-4e67-8c75-3dc0f1b0d6bd"},xe:{field:"end",type:"genomic"},row:{field:"sample",type:"nominal",legend:!0},color:{field:"peak",type:"quantitative",legend:!0},tooltip:[{field:"start",type:"genomic",alt:"Start Position"},{field:"end",type:"genomic",alt:"End Position"},{field:"peak",type:"quantitative",alt:"Value",format:".2"},{field:"sample",type:"nominal",alt:"Sample"}],width:130,height:600},theme:{base:"light",root:{background:"white",titleColor:"black",titleBackgroundColor:"transparent",titleFontSize:18,titleFontFamily:"Arial",titleAlign:"left",titleFontWeight:"bold",subtitleColor:"gray",subtitleBackgroundColor:"transparent",subtitleFontSize:16,subtitleFontFamily:"Arial",subtitleFontWeight:"normal",subtitleAlign:"left",mousePositionColor:"#000000"},track:{background:"transparent",alternatingBackground:"transparent",titleColor:"black",titleBackground:"white",titleFontSize:24,titleAlign:"left",outline:"black",outlineWidth:1},legend:{position:"top",background:"white",backgroundOpacity:.7,labelColor:"black",labelFontSize:12,labelFontWeight:"normal",labelFontFamily:"Arial",backgroundStroke:"#DBDBDB",tickColor:"black"},axis:{tickColor:"black",labelColor:"black",labelFontSize:12,labelFontWeight:"normal",labelFontFamily:"Arial",baselineColor:"black",gridColor:"#E3E3E3",gridStrokeWidth:1,gridStrokeType:"solid",gridStrokeDash:[4,4]},markCommon:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},point:{color:"#E79F00",size:3,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},rect:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},triangle:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},area:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},line:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},bar:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},rule:{color:"#E79F00",size:1,stroke:"black",strokeWidth:1,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},link:{color:"#E79F00",size:1,stroke:"black",strokeWidth:1,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},text:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6],textAnchor:"middle",textFontWeight:"normal"},brush:{color:"gray",size:1,stroke:"black",strokeWidth:1,opacity:.3,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]}}}}]}],center:[],right:[],bottom:[],gallery:[],whole:[]},initialXDomain:[0,1e9],initialYDomain:[0,1e9],zoomFixed:!1,zoomLimits:[1,null],uid:"154b1b40-f6fb-11eb-914b-976b6ecda162"}],zoomLocks:{locksByViewUid:{},locksDict:{}},locationLocks:{locksByViewUid:{},locksDict:{}},editable:!1,chromInfoPath:"https://s3.amazonaws.com/gosling-lang.org/data/hg38.chrom.sizes"},qr=30,vgg=g=>({genomePositionSearchBoxVisible:!1,genomePositionSearchBox:{autocompleteServer:"https://higlass.io/api/v1",autocompleteId:b4e(g),chromInfoServer:"https://higlass.io/api/v1",chromInfoId:g??"hg38"},layout:{w:12,h:12,x:0,y:0},tracks:{top:[],left:[],center:[],right:[],bottom:[],gallery:[],whole:[]},initialXDomain:[0,yI(g).total],initialYDomain:[0,yI(g).total],zoomFixed:!1});class Sgg{constructor(){nt(this,"assembly"),nt(this,"orientation"),nt(this,"hg"),this.assembly="hg38",this.hg={compactLayout:!1,trackSourceServers:[],views:[],zoomLocks:{locksByViewUid:{},locksDict:{}},locationLocks:{locksByViewUid:{},locksDict:{}}},this.setEditable(!1)}spec(){return this.hg}setViewOrientation(e){return this.orientation=e,this}addDefaultView(e,I){return this.hg.views.push(JSON.parse(JSON.stringify({...vgg(I),uid:e}))),this}setAssembly(e){return this.assembly=e,this.setChromInfoPath(yI(this.assembly).path),this}getAssembly(){return this.assembly}setTextTrack(e,I,i,n="black",C=14,r="normal",o="left",A="transparent",s="Arial"){var a;return this.getLastView()&&((a=this.getLastView().tracks.top)==null||a.push({type:"text",width:e,height:I,options:{backgroundColor:A,textColor:n,fontSize:C,fontWeight:r,fontFamily:s,offsetY:0,align:o,text:i}})),this}setDummyTrack(e){var I;return this.getLastView()&&((I=this.getLastView().tracks.top)==null||I.push({type:"dummy-track",width:e.width,height:e.height,options:{width:e.width,height:e.height,title:e.title,...e.style}})),this}addBrush(e,I,i,n,C){var r,o,A,s,a,l;if(n)return(l=this.getView(I))==null||l.tracks.whole.push({type:e==="circular"?"brush-track":"viewport-projection-horizontal",uid:on(),fromViewUid:n,options:{projectionFillColor:(r=C==null?void 0:C.color)!=null?r:i.brush.color,projectionStrokeColor:(o=C==null?void 0:C.stroke)!=null?o:i.brush.stroke,projectionFillOpacity:(A=C==null?void 0:C.opacity)!=null?A:i.brush.opacity,projectionStrokeOpacity:(s=C==null?void 0:C.opacity)!=null?s:i.brush.opacity,strokeWidth:(a=C==null?void 0:C.strokeWidth)!=null?a:i.brush.strokeWidth,startAngle:C==null?void 0:C.startAngle,endAngle:C==null?void 0:C.endAngle,innerRadius:C==null?void 0:C.innerRadius,outerRadius:C==null?void 0:C.outerRadius}}),this}getLastView(){return this.hg.views[this.hg.views.length-1]}getMainTrackPosition(){return this.orientation==="vertical"?"left":"center"}getLastVisView(){const e=this.hg.views.filter(I=>{var i,n;return((n=(i=I.tracks[this.getMainTrackPosition()])==null?void 0:i[0])==null?void 0:n.type)==="combined"});return e[e.length-1]}getView(e){return this.hg.views.find(I=>I.uid===e)}validateSpec(e=!1){return uHe(Zgg,this.spec(),e).state==="success"}setDomain(e,I){return e&&(this.getLastView().initialXDomain=IL(e,this.getAssembly())),I&&(this.getLastView().initialYDomain=IL(I,this.getAssembly())),this}adjustDomain(e="horizontal",I,i){if(e!=="vertical")return this;const n=this.getLastView().initialXDomain;if(!n)return this;const[C,r]=n,o=r-C,A=(C+r)/2;return this.getLastView().initialXDomain=[A-o/I/2/i*I,A+o/I/2/i*I],this}setZoomFixed(e){return this.getLastView().zoomFixed=e,this}setZoomLimits(e){return this.getLastView().zoomLimits=e,this}setLayout(e){return this.getLastView().layout=e,this}setEditable(e){return this.hg.editable=e,this}setChromInfoPath(e){return this.getLastView()&&(this.getLastView().chromInfoPath=e),this.hg.chromInfoPath=e,this}addTrackSourceServers(e){var I,i;return e&&((I=this.hg.trackSourceServers)==null?void 0:I.indexOf(e))===-1&&((i=this.hg.trackSourceServers)==null||i.push(e)),this}setMainTrack(e){var I;return this.getLastView()?(this.getLastView().tracks[this.getMainTrackPosition()]=[{type:"combined",uid:`${(I=e.uid)!=null?I:on()}-${this.getMainTrackPosition()}-combined`,width:e.width-1,height:e.height,contents:[e]}],this):this}addTrackToCombined(e){var I;return this.getLastVisView()?((I=this.getLastVisView().tracks[this.getMainTrackPosition()][0])==null||I.contents.push(e),this):this}setAxisTrack(e,I="regular",i){if(!this.hg.views)return this;const n=e==="left"||e==="right"?"width":"height",C={type:"axis-track",chromInfoPath:this.hg.chromInfoPath,options:{...i,assembly:this.getAssembly(),stroke:"transparent",color:i.theme.axis.labelColor,labelMargin:i.theme.axis.labelMargin,excludeChrPrefix:i.theme.axis.labelExcludeChrPrefix,fontSize:i.theme.axis.labelFontSize,fontFamily:i.theme.axis.labelFontFamily,fontWeight:i.theme.axis.labelFontWeight,tickColor:i.theme.axis.tickColor,tickFormat:I==="narrower"?"si":"plain",tickPositions:I==="regular"?"even":"ends",reverseOrientation:e==="bottom"||e==="right"}};if(i.layout==="circular")this.addTrackToCombined({...C,options:{...C.options,layout:"circular"}});else{const r={...C,[n]:qr};if(e==="left"){if(this.getLastView().tracks.left.filter(o=>o.type==="axis-track").length!==0)return this;this.getLastView().tracks.left=o7e(this.getLastView().tracks.left,0,r)}else if(e==="right"){if(this.getLastView().tracks.right.filter(o=>o.type==="axis-track").length!==0)return this;this.getLastView().tracks.right.push(r)}else{if(this.getLastView().tracks[e].filter(o=>o.type==="axis-track").length!==0)return this;this.getLastView().tracks[e].push(r)}}return this}setExampleHiglassViewConfig(){this.hg=Bgg}}function VG(g,e,I,i){const n=i&&i!==0?i:void 0;let C=0;switch(e){case"less-than":case"LT":case"lt":C=I>g?n?(I-g)/n:1:0;break;case"less-than-or-equal-to":case"LTET":case"ltet":C=I>=g?n?(I-g)/n:1:0;break;case"greater-than":case"GT":case"gt":C=I{g[I]&&I!=="base"&&(e[I]=Object.assign(JSON.parse(JSON.stringify(e[I])),JSON.parse(JSON.stringify(g[I]))))}),e}}class Vgg{constructor(e,I,i){nt(this,"id"),nt(this,"theme"),nt(this,"specOriginal"),nt(this,"specComplete"),nt(this,"dataAggregated"),nt(this,"channelScales"),nt(this,"mouseEventModel"),this.id=on(),this.theme=i??e2e(),this.dataAggregated=I,this.specOriginal=e,this.specComplete=structuredClone(e),this.channelScales={},this.mouseEventModel=new Wqt;const n=this.validateSpec();if(!n.valid){console.warn("Gosling specification is not valid!",n.errorMessages);return}this.generateCompleteSpec(this.specComplete),this.flipRanges(this.specComplete),this.generateScales(),this.dataAggregated=agg(this.spec(),this.dataAggregated)}getId(){return this.id}originalSpec(){return this.specOriginal}spec(){return this.specComplete}data(){return this.dataAggregated}getMouseEventModel(){return this.mouseEventModel}generateCompleteSpec(e){if(!e.width||!e.height){console.warn("Size of track is not determined yet.");return}if(e.orientation==="vertical"){const n=e.width;e.width=e.height,e.height=n}const I=this.getGenomicChannelKey();let i=!1;I==="x"&&(i=lt(e.x)&&e.x.axis!==void 0&&e.x.axis!=="none"),I==="y"&&(i=lt(e.y)&&e.y.axis!==void 0&&e.y.axis!=="none"),e.layout!=="circular"?lt(e.x)&&e.x.axis!==void 0&&e.x.axis!=="none"&&(e.height-=qr):I==="x"&&i&<(e.x)&&e.x.axis==="top"?e.outerRadius=e.outerRadius-qr:I==="x"&&i&<(e.x)&&e.x.axis==="bottom"&&(e.innerRadius=e.innerRadius+qr),xd.forEach(n=>{const C=e[n];lt(C)&&!("zeroBaseline"in C)&&C.type==="quantitative"&&(C.zeroBaseline=!0)}),this.addScaleMaterials(e)}flipRanges(e){lt(e.y)&&e.y.flip&&Array.isArray(e.y.range)&&(e.y.range=e.y.range.reverse())}getGenomicChannelKey(){return hHe(this.spec())}getGenomicChannel(){return S$(this.spec())}setChannelDomain(e,I,i){const n=this.originalSpec()[e];if(!i&<(n)&&n.domain!==void 0)return;const C=this.specComplete[e];lt(C)&&(C.domain=I)}updateChannelValue(){if(this.originalSpec().y===void 0){const e=this.spec().y,I=this.getChannelDomainArray("row");e&&L1(e)&&I&&this.spec().mark!=="withinLink"&&(e.value=this.spec().height/I.length/2)}}encodedValue(e,I){var i;if(e==="text"&&I!==void 0)return`${+I?~~I:I}`;const n=this.spec()[e],C=lt(n)?n.type:L1(n)?"constant":void 0;if(C){if(C==="constant")return this.channelScales[e]();if(I!==void 0&&(I===null&&(C==="quantitative"?I=0:C==="nominal"&&(I="null")),typeof this.channelScales[e]=="function"))switch(e){case"x":case"y":case"x1":case"y1":case"xe":case"ye":case"x1e":if(C==="quantitative"||C==="genomic")return this.channelScales[e](I);if(C==="nominal")return this.channelScales[e](I);break;case"stroke":case"color":if(C==="quantitative"){const r=this.channelScales[e].copy(),o=r.domain(),A=o[1]-o[0],s=Array.from((i=n.scaleOffset)!=null?i:[0,1]);return r.domain([o[0]+A*s.sort()[0],o[0]+A*s.sort()[1]])(I)}if(C==="nominal")return this.channelScales[e](I);break;case"size":if(C==="quantitative")return this.channelScales[e](I);if(C==="nominal")return this.channelScales[e](I);break;case"row":if(C==="nominal")return this.channelScales[e](I);break;case"strokeWidth":case"opacity":if(C==="quantitative")return this.channelScales[e](I);break;default:console.warn(`${e} is not supported for encoding values, so returning a undefined value`);return}}}trackVisibility(e){const I=this.spec();if(!I.visibility||I.visibility.length===0||I.visibility.filter(n=>n.target==="track").length===0)return!0;let i=!0;return I.visibility.filter(n=>n.target==="track").forEach(n=>{const{operation:C,measure:r,threshold:o}=n;let A;r==="zoomLevel"?A=e[r]:A=I[r],A!==void 0&&(i=i&&VG(A,C,o)===1)}),i}markVisibility(e,I){const i=this.spec();if(!i.visibility||i.visibility.length===0||i.visibility.filter(C=>C.target==="mark").length===0)return 1;let n=1;return i.visibility.filter(C=>C.target==="mark").forEach(C=>{const{operation:r,threshold:o,conditionPadding:A,transitionPadding:s,measure:a}=C,l=A??0,c=i.mark;let u=1;if(c==="text"&&o==="|xe-x|"&&a==="width"){const d=this.encodedPIXIProperty("xe",e),h=this.encodedPIXIProperty("x",e);d!==void 0&&(I!=null&&I.width)&&(u=VG(I.width+l,r,Math.abs(d-h),s))}else a==="width"&&typeof o=="number"&&(I!=null&&I.width)?u=VG(I.width+l,r,o,s):a==="zoomLevel"&&typeof o=="number"&&(I!=null&&I.zoomLevel)&&(u=VG(I.zoomLevel,r,o,s));n>u&&(n=u)}),n}visualPropertyByChannel(e,I){const i=I!==void 0?bI(I,this.spec()[e]):void 0;return this.encodedValue(e,i)}encodedPIXIProperty(e,I,i){const n=this.spec().mark;if(["text","color","row","stroke","opacity","strokeWidth","x","y","xe","x1","x1e","ye","size"].includes(e))return this.visualPropertyByChannel(e,I);switch(n){case"bar":return e7e(this,e,I,i);case"point":case"text":return jUe(this,e,I);case"rect":return I7e(this,e,I,i);default:return}}addScaleMaterials(e){const I=this.data(),i=this.getGenomicChannel();if(!i||!i.field){console.warn("Genomic field is not provided in the specification");return}if(typeof e.width>"u"||typeof e.height>"u"){console.warn("Track size is not determined yet");return}xd.forEach(n=>{var C,r,o,A;const s=e[n];if(E7e(e,n)&<(s)){const a=JT(I,c=>c[i.field]),l=[...a.keys()];if(!s.domain){const c="zeroBaseline"in s&&s.zeroBaseline?0:P1(l.map(d=>xee(a.get(d).map(h=>s.field?h[s.field]:void 0)))),u=jG(l.map(d=>xee(a.get(d).map(h=>s.field?h[s.field]:void 0))));s.domain=[c,u]}if(!s.range){const c=e.row,u=lt(c)?c.field:void 0,d=(C=this.getChannelDomainArray("row"))!=null?C:u?Array.from(new Set(I.map(m=>m[u]))):[1],h=e.height/d.length;switch(n){case"x":s.range=[0,e.width];break;case"y":s.range=[0,h];break}}}else{const a=e.row,l=lt(a)?a.field:void 0,c=(r=this.getChannelDomainArray("row"))!=null?r:l?Array.from(new Set(I.map(d=>d[l]))):[1],u=e.height/c.length;if(s){if(lt(s)&&(s.type==="quantitative"||s.type==="genomic")){if(s.domain===void 0){const d="zeroBaseline"in s&&s.zeroBaseline?0:(o=P1(I.map(m=>+m[s.field])))!=null?o:0,h=(A=jG(I.map(m=>+m[s.field])))!=null?A:0;s.domain=[d,h]}else s.type==="genomic"&&!Rte(s.domain)&&(s.domain=IL(s.domain));if((n==="color"||n==="stroke")&&s.type==="quantitative"&&!s.scaleOffset&&(s.scaleOffset=[0,1]),!s.range){let d;switch(n){case"x":case"xe":case"x1":case"x1e":d=[0,e.width];break;case"y":case"ye":d=[0,u];break;case"color":case"stroke":d=wgg.QUANTITATIVE_COLOR;break;case"size":d=this.theme.markCommon.quantitativeSizeRange;break;case"strokeWidth":d=[1,3];break;case"opacity":d=[0,1];break}d&&(s.range=d)}}else if(lt(s)&&s.type==="nominal"&&(s.domain===void 0&&(s.domain=Array.from(new Set(I.map(d=>{var h;return(h=d[s.field])!=null?h:"null"})))),!s.range)){let d=2,h;switch(n){case"x":case"xe":h=[0,e.width];break;case"y":case"ye":h=[u,0];break;case"color":case"stroke":h=this.theme.markCommon.nominalColorRange;break;case"row":h=[0,e.height];break;case"size":h=s.domain.map(()=>d++);break}h&&(s.range=h)}}else{let d;switch(n){case"x":d=e.width/2;break;case"y":e.mark==="withinLink"?d=u:d=u/2;break;case"size":e.mark==="line"?d=this.theme.line.size:e.mark==="bar"||e.mark==="rect"||e.mark==="triangleRight"||e.mark==="triangleLeft"||e.mark==="triangleBottom"||e.stretch&&e.mark==="point"&<(e.x)&<(e.xe)?d=void 0:e.mark==="text"?d=12:d=this.theme.point.size;break;case"color":d=this.theme.markCommon.color;break;case"row":d=0;break;case"stroke":e.mark==="text"?d=this.theme.text.stroke:d=this.theme.markCommon.stroke;break;case"strokeWidth":e.mark==="rule"?d=this.theme.rule.strokeWidth:e.mark==="withinLink"||e.mark==="betweenLink"?d=this.theme.link.strokeWidth:e.mark==="text"?d=this.theme.text.strokeWidth:d=this.theme.markCommon.strokeWidth;break;case"opacity":d=this.theme.markCommon.opacity;break;case"text":d="";break}typeof d<"u"&&(e[n]={value:d})}}}),[["x","xe"],["y","ye"]].forEach(n=>{const[C,r]=n,o=e[C],A=e[r];if(lt(o)&<(A)&&o.type===A.type&&o.domain&&A.domain&&Array.isArray(o.domain)&&Array.isArray(A.domain)){if(o.type==="genomic"||o.type==="quantitative"){const s=P1([o.domain[0],A.domain[0]]),a=jG([o.domain[1],A.domain[1]]);o.domain=A.domain=[s,a]}else if(o.type==="nominal"){const s=Array.from(new Set([...o.domain,...A.domain]));o.range=A.range=s}}})}generateScales(){const e=this.spec();xd.forEach(I=>{const i=e[I];if(L1(i))this.channelScales[I]=()=>i.value;else if(lt(i)){if(I==="text")return;const n=i.domain,C=i.range;if(n===void 0||C===void 0)return;if(i.type==="quantitative"||i.type==="genomic")switch(I){case"x":case"x1":case"xe":case"x1e":case"y":case"ye":case"size":case"opacity":case"strokeWidth":this.channelScales[I]=nh().domain(n).range(C);break;case"color":case"stroke":let r=bbe;Object.keys(i9).includes(C)&&(r=i9[C]),this.channelScales[I]=Fpe(r).domain(n);break}else if(i.type==="nominal")switch(I){case"x":case"xe":case"y":case"ye":case"row":this.channelScales[I]=Xpe().domain(n).range(C);break;case"size":this.channelScales[I]=jX().domain(n).range(C);break;case"color":case"stroke":this.channelScales[I]=jX(C).domain(n);break}}})}getChannelScale(e){return this.channelScales[e]}setChannelScale(e,I){this.channelScales[e]=I}isShowYAxis(){const e=this.spec(),I=this.getChannelDomainArray("y"),i=this.getChannelRangeArray("y");return lt(e.y)&&e.y.axis!=="none"&&e.y.type==="quantitative"&&!!I&&!!i}getChannelDomainArray(e){const I=this.spec()[e];return lt(I)&&Rte(I.domain)?I.domain:void 0}getChannelRangeArray(e){const I=this.spec()[e];return lt(I)&&F7e(I.range)?I.range:void 0}validateSpec(){return dHe(this.originalSpec())}}function Kr(g,e){a7.publish(g,e)}function Rgg(g,e){a7.subscribe(g,e)}function Wgg(g){a7.unsubscribe(g)}const Ole={stroke:"black",strokeWidth:1,strokeOpacity:1,color:"none",opacity:1,arrange:"front"};function Xgg(){return{goslingModels:[],tabularData:[],skipRendering:!1}}const Hgg={type:"gosling-track",datatype:["multivec","epilogos"],orientation:"1d-horizontal",defaultOptions:{theme:SG("light")}},Tgg=(g,e,I)=>{var i,n,C,r,o,A,s,a,l,c,u,d,h,m,f,b,p,y,Z,v,G,B,w,R,S,X,W,V,H,D,Y,F,_;const{tileProxy:J}=g.services,{BarTrack:te}=g.tracks,q=Os({color:"black",size:12}),$=class iL extends te{constructor(){var Q,ne,fe,Ce,Ze,Ge;super(e,I),Zg(this,d),Zg(this,m),Zg(this,b),Zg(this,y),Zg(this,v),Zg(this,B),Zg(this,R),Zg(this,X),Zg(this,V),Zg(this,D),Zg(this,F),nt(this,"tileSize"),nt(this,"mRangeBrush"),Zg(this,i,void 0),Zg(this,n,void 0),nt(this,"firstDraw",!0),nt(this,"gLegend",g.libraries.d3Selection.select(e.svgElement).append("g")),nt(this,"displayedLegends",[]),nt(this,"textGraphics",[]),nt(this,"textsBeingUsed",0),nt(this,"pMouseHover",new g.libraries.PIXI.Graphics),nt(this,"pMouseSelection",new g.libraries.PIXI.Graphics),Zg(this,C,0),Zg(this,r,0),Zg(this,o,!1),Zg(this,A,g.libraries.d3Selection.select(e.svgElement).append("g")),Zg(this,s,new g.libraries.PIXI.TextStyle(q)),Zg(this,a,new g.libraries.PIXI.Graphics),Zg(this,l,new g.libraries.PIXI.Text("",q)),nt(this,"prevVisibleAndFetchedTiles"),nt(this,"resolvedTracks"),nt(this,"hideMousePosition"),e.dataFetcher.track=this,wC(this,n,{}),wC(this,i,this.options.spec.assembly),"overlay"in this.options.spec?this.options.spec.overlay=this.options.spec._overlay.map(Xe=>({...Xe,_renderingId:on()})):this.options.spec._renderingId=on(),this.fetchedTiles={},this.tileSize=(ne=(Q=this.tilesetInfo)==null?void 0:Q.tile_size)!=null?ne:1024;const{valid:ve,errorMessages:ke}=dHe(this.options.spec);ve||console.warn("The specification of the following track is invalid",ke,this.options.spec),this.pMain.addChild(this.pMouseHover),this.pMain.addChild(this.pMouseSelection),this.pMask.interactive=!0,this.mRangeBrush=new Gqt(Jt(this,A),g.libraries,(fe=this.options.spec.style)==null?void 0:fe.brush),this.mRangeBrush.on("brush",wI(this,V,H).bind(this)),this.pMask.on("mousedown",Xe=>{const{x:Oe,y:ze}=Xe.data.getLocalPosition(this.pMain);wI(this,b,p).call(this,Oe,ze,Xe.data.originalEvent.altKey)}),this.pMask.on("mouseup",Xe=>{const{x:Oe,y:ze}=Xe.data.getLocalPosition(this.pMain);wI(this,v,G).call(this,Oe,ze)}),this.pMask.on("mousemove",Xe=>{const{x:Oe}=Xe.data.getLocalPosition(this.pMain);wI(this,y,Z).call(this,Oe)}),this.pMask.on("mouseout",wI(this,B,w).bind(this)),this.flipText=this.options.spec.orientation==="vertical",this.hideMousePosition&&(this.hideMousePosition(),this.hideMousePosition=void 0),(Ce=this.options)!=null&&Ce.showMousePosition&&!this.hideMousePosition&&(this.hideMousePosition=g.utils.showMousePosition(this,IC(this.getResolvedTracks()[0]),this.isShowGlobalMousePosition())),this.pLabel.removeChild(this.trackNotFoundText),Jt(this,l).anchor.x=1,Jt(this,l).anchor.y=1,this.pLabel.addChild(Jt(this,a)),this.pLabel.addChild(Jt(this,l)),g.libraries.PIXI.GRAPHICS_CURVES.adaptive=(Ge=(Ze=this.options.spec.style)==null?void 0:Ze.enableSmoothPath)!=null?Ge:!1,g.libraries.PIXI.GRAPHICS_CURVES.adaptive&&(g.libraries.PIXI.GRAPHICS_CURVES.maxLength=1,g.libraries.PIXI.GRAPHICS_CURVES.maxSegments=2048*10)}draw(){var Q,ne;this.clearMouseEventData(),this.textsBeingUsed=0,(Q=this.pMouseHover)==null||Q.clear();const fe=()=>{const Ce=this.dataFetcher instanceof U2;this.processAllTiles(Ce),super.draw(),this.prevVisibleAndFetchedTiles=this.visibleAndFetchedTiles()};$V(this.dataFetcher)&&!fbe(this.visibleAndFetchedTiles(),this.prevVisibleAndFetchedTiles)?this.updateTileAsync(this.dataFetcher,fe):fe(),(ne=this.mRangeBrush)==null||ne.drawBrush(!0),this.firstDraw&&(wI(this,F,_).call(this),this.firstDraw=!1)}initTile(Q){this.drawTile(Q)}updateTile(){}renderTile(){}drawTile(Q){var ne,fe;Q.drawnAtScale=this._xScale.copy();const Ce=Jt(this,n)[Q.tileId];Ce&&((ne=Q.graphics)==null||ne.clear(),(fe=Q.graphics)==null||fe.removeChildren(),this.pBackground.clear(),this.pBackground.removeChildren(),this.pBorder.clear(),this.pBorder.removeChildren(),this.displayedLegends=[],Ce.goslingModels.forEach(Ze=>{const Ge=this.dimensions[0],ve=this._xScale.invert(Ge)-this._xScale.invert(0);Ze.trackVisibility({zoomLevel:ve})&&(B7e(g,this,Q,Ze,this.options.theme),G7e(g,this,Q,Ze),v7e(g,this,Q,Ze,this.options.theme))}),this.forceDraw())}rerender(Q){this.options=Q,this.options.spec.layout==="circular"&&this.mRangeBrush.remove(),this.getResolvedTracks(!0),this.clearMouseEventData(),this.textsBeingUsed=0,this.processAllTiles(!0),this.draw(),this.forceDraw()}clearMouseEventData(){this.visibleAndFetchedGoslingModels().forEach(Q=>Q.getMouseEventModel().clear())}visibleAndFetchedGoslingModels(){return this.visibleAndFetchedTiles().flatMap(Q=>{var ne,fe;return(fe=(ne=Jt(this,n)[Q.tileId])==null?void 0:ne.goslingModels)!=null?fe:[]})}remove(){super.remove(),this.gLegend&&(this.gLegend.remove(),this.gLegend=void 0),this.mRangeBrush.remove()}setDimensions(Q){super.setDimensions(Q),this.mRangeBrush.setSize(Q[1])}setPosition(Q){super.setPosition(Q),[this.pMain.position.x,this.pMain.position.y]=this.position,this.mRangeBrush.setOffset(...Q)}forceDraw(){this.animate()}zoomed(Q,ne){const fe=this.mRangeBrush.getRange();this.mRangeBrush.updateRange(fe?[Q(this._xScale.invert(fe[0])),Q(this._xScale.invert(fe[1]))]:null),this.xScale(Q),this.yScale(ne),this.refreshTiles(),this.draw(),this.forceDraw();const Ce=Q.domain().map(Ze=>gd(Ze,Jt(this,i),!0));Kr("location",{id:e.viewUid,genomicRange:Ce})}setMask(Q,ne){if(this.pMask.clear(),this.pMask.beginFill(),this.options.spec.layout==="circular"){const[fe,Ce]=this.position,[Ze,Ge]=this.dimensions,ve=fe+Ze/2,ke=Ce+Ge/2,Xe=this.options.spec.outerRadius;this.pMask.drawCircle(ve,ke,Xe)}else this.pMask.drawRect(Q[0],Q[1],ne[0],ne[1]);this.pMask.endFill()}processAllTiles(Q=!1){var ne,fe;this.tileSize=(fe=(ne=this.tilesetInfo)==null?void 0:ne.tile_size)!=null?fe:1024;const Ce=this.visibleAndFetchedTiles();Ce.forEach(ve=>wI(this,m,f).call(this,ve,Q)),this.combineAllTilesIfNeeded();const Ze=Ce.flatMap(ve=>this.transformDataAndCreateModels(ve));Ggg(Ze);const Ge=[].concat(...Ze.map(ve=>ve.data()));Ge.length!==0&&this.options.siblingIds.forEach(ve=>Kr("rawData",{id:ve,data:Ge}))}async updateTileAsync(Q,ne){if(!this.tilesetInfo)return;const fe=this.visibleAndFetchedTiles(),Ce=await Q.getTabularData(Object.values(fe).map(Ge=>Ge.remoteId)),Ze=this.tilesetInfo;fe.forEach((Ge,ve)=>{if(ve===0){const[ke]=g.utils.trackUtils.calculate1DVisibleTiles(Ze,this._xScale);Ge.tileData.zoomLevel=ke[0],Ge.tileData.tilePos=[ke[1],ke[1]],Ge.tileData.tabularData=Ce}else Ge.tileData.tabularData=[]}),ne()}calculateVisibleTiles(){var Q,ne,fe,Ce,Ze;if(this.tilesetInfo)if($V(this.dataFetcher)){const Ge=g.utils.trackUtils.calculate1DVisibleTiles(this.tilesetInfo,this._xScale),ve=(ne=(Q=this.tilesetInfo.max_tile_width)!=null?Q:this.dataFetcher.MAX_TILE_WIDTH)!=null?ne:Number.MAX_SAFE_INTEGER;for(const ke of Ge){const{tileWidth:Xe}=this.getTilePosAndDimensions(ke[0],[ke[1],ke[1]]);if(this.forceDraw(),Xe>ve)return}this.setVisibleTiles(Ge)}else{if(!this.tilesetInfo)return;const Ge=this.calculateZoomLevel();if("resolutions"in this.tilesetInfo){const ve=this.tilesetInfo.resolutions.map(ze=>+ze).sort((ze,Me)=>Me-ze),ke=J.calculateTilesFromResolution(ve[Ge],this._xScale,this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0]);let Xe;IC(this.getResolvedTracks()[0])&&(Xe=J.calculateTilesFromResolution(ve[Ge],this._yScale,this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0]));const Oe=wI(fe=iL,c,u).call(fe,ke,Xe,Ge);this.setVisibleTiles(Oe)}else{const ve=J.calculateTiles(Ge,this.relevantScale(),this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0],this.tilesetInfo.max_zoom,this.tilesetInfo.max_width);let ke;IC(this.getResolvedTracks()[0])&&(ke=J.calculateTiles(Ge,this._yScale,this.tilesetInfo.min_pos[1],this.tilesetInfo.max_pos[1],this.tilesetInfo.max_zoom,(Ce=this.tilesetInfo.max_width1)!=null?Ce:this.tilesetInfo.max_width));const Xe=wI(Ze=iL,c,u).call(Ze,ve,ke,Ge);this.setVisibleTiles(Xe)}}}getTilePosAndDimensions(Q,ne){if(!this.tilesetInfo)throw Error("tilesetInfo not parsed");if("resolutions"in this.tilesetInfo){const Ce=this.tilesetInfo.resolutions.map(ze=>+ze).sort((ze,Me)=>Me-ze)[Q],[Ze,Ge]=ne,ve=Ce*Jt(this,d,h),ke=ve,Xe=ve*Ze,Oe=ke*Ge;return{tileX:Xe,tileY:Oe,tileWidth:ve,tileHeight:ke}}else{const[fe,Ce]=ne,Ze=this.tilesetInfo.min_pos[0],Ge=this.tilesetInfo.min_pos[1],ve=this.tilesetInfo.max_width/2**Q,ke=this.tilesetInfo.max_width/2**Q,Xe=Ze+fe*ve,Oe=Ge+Ce*ke;return{tileX:Xe,tileY:Oe,tileWidth:ve,tileHeight:ke}}}getIndicesOfVisibleDataInTile(Q){const ne=this._xScale.range();if(!this.tilesetInfo||!Q.tileData.tilePos||!("dense"in Q.tileData))return[0,0];const{tileX:fe,tileWidth:Ce}=this.getTilePosAndDimensions(Q.tileData.zoomLevel,Q.tileData.tilePos),Ze=g.libraries.d3Scale.scaleLinear().domain([0,Jt(this,d,h)]).range([fe,fe+Ce]),Ge=Math.max(0,Math.round(Ze.invert(this._xScale.invert(ne[0])))),ve=Math.min(Q.tileData.dense.length,Math.round(Ze.invert(this._xScale.invert(ne[1]))));return[Ge,ve]}receivedTiles(Q){super.receivedTiles(Q),$V(this.dataFetcher)&&this.drawLoadingCue()}removeOldTiles(){super.removeOldTiles(),$V(this.dataFetcher)&&this.drawLoadingCue()}combineAllTilesIfNeeded(){var Q,ne,fe;if(!this.shouldCombineTiles())return;const Ce=this.visibleAndFetchedTiles();if(!Ce||Ce.length<=1)return;this.tileSize=((ne=(Q=this.tilesetInfo)==null?void 0:Q.tile_size)!=null?ne:1024)*Ce.length;let Ze=[];Ce.forEach((ve,ke)=>{const Xe=Jt(this,n)[ve.tileId];Xe&&(Ze=[...Ze,...Xe.tabularData],Xe.skipRendering=ke!==0)});const Ge=Jt(this,n)[Ce[0].tileId];Ge.tabularData=Ze,(fe=Ge.tabularData[0])!=null&&fe.uid&&(Ge.tabularData=pUe(Ge.tabularData,"uid"))}shouldCombineTiles(){const Q=S7e(this.options.spec,"displace"),ne=()=>{const Ce=this.visibleAndFetchedTiles();return Ce.length>=1&&"dense"in Ce[0].tileData},fe=this.dataFetcher instanceof U2;return Q&&!ne()&&!fe}getResolvedTracks(Q=!1){if(Q||!this.resolvedTracks){const ne=structuredClone(this.options.spec),fe=F0(ne).filter(Ce=>Ce.mark!=="brush");fe.forEach(Ce=>{"values"in Ce.data&&(Ce.data.values=[])}),this.resolvedTracks=fe}return this.resolvedTracks}transformDataAndCreateModels(Q){const ne=Jt(this,n)[Q.tileId];return!ne||ne.skipRendering?[]:(ne.goslingModels=[],this.getResolvedTracks().forEach(Ce=>{var Ze;let Ge=Array.from(ne.tabularData);(Ze=Ce.dataTransform)==null||Ze.forEach(_e=>{switch(_e.type){case"filter":Ge=LHe(_e,Ge);break;case"concat":Ge=tgg(_e,Ge);break;case"replace":Ge=ggg(_e,Ge);break;case"log":Ge=Igg(_e,Ge);break;case"exonSplit":Ge=ogg(_e,Ge,Ce.assembly);break;case"genomicLength":Ge=igg(_e,Ge);break;case"svType":Ge=ngg(_e,Ge);break;case"coverage":Ge=Cgg(_e,Ge,this._xScale.copy());break;case"subjson":Ge=Agg(_e,Ge);break;case"displace":Ge=rgg(_e,Ge,this._xScale.copy());break}});try{if(PubSub){const At=Ge.length;PubSub.publish("data-preview",{id:e.viewUid,dataConfig:JSON.stringify({data:Ce.data}),data:100>At?Ge:EU(Ge,100)})}}catch{}const[ve,ke]=this.dimensions,Xe=n9(Ce)?qr:0,[Oe,ze]=[ve,ke+Xe],Me=Math.min(Oe,ze)/Math.min(Ce.width,Ce.height);Ce.innerRadius&&(Ce.innerRadius=Ce.innerRadius*Me),Ce.outerRadius&&(Ce.outerRadius=Ce.outerRadius*Me),Ce.width=Oe,Ce.height=ze;const Ue=new Vgg(Ce,Ge,this.options.theme);ne.goslingModels.push(Ue)}),ne.goslingModels)}getMouseOverHtml(Q,ne){var fe,Ce,Ze,Ge,ve;if(wI(this,X,W).call(this,"trackMouseOver",Q,ne),Jt(this,o)||!this.tilesetInfo)return"";this.pMouseHover.clear();const ke=gd(Math.floor(this._xScale.invert(Q)),Jt(this,i)),Xe=wI(this,R,S).call(this,Q,ne);if(Xe.length!==0?document.body.style.cursor="pointer":document.body.style.cursor="default",Xe.length!==0){const Oe=(fe=this.options.spec.experimental)==null?void 0:fe.mouseEvents;if(!!Oe||zm(Oe)&&!!Oe.mouseOver){const _e=this.pMouseHover;((Ze=(Ce=this.options.spec.style)==null?void 0:Ce.mouseOver)==null?void 0:Ze.arrange)!=="behind"&&(this.pMain.removeChild(_e),this.pMain.addChild(_e)),wI(this,D,Y).call(this,_e,Xe,Object.assign({},Ole,(Ge=this.options.spec.style)==null?void 0:Ge.mouseOver)),Kr("mouseOver",{id:e.viewUid,genomicPosition:ke,data:Xe.map(At=>At.value)})}const Ue=(ve=this.visibleAndFetchedGoslingModels().find(_e=>{var At;return _e.spec().tooltip&&((At=_e.spec().tooltip)==null?void 0:At.length)!==0}))==null?void 0:ve.spec().tooltip;if(Ue){let _e=Ue.map(At=>{var wt;const rt=Xe[0].value[At.field];let Te=rt;if(At.type==="quantitative"&&At.format)Te=g.libraries.d3Format.format(At.format)(+rt);else if(At.type==="genomic"){const{chromosome:le,position:ye}=gd(+rt,Jt(this,i));Te=`${le}:${g.libraries.d3Format.format(",")(ye)}`}return`${(wt=At.alt)!=null?wt:At.field}${Te}`}).join("");return _e=`${_e}
`,Xe.length>1&&(_e+=`
${Xe.length-1} Additional Selections...
`),`
${_e}
`}}return""}minVisibleValue(){return 0}maxVisibleValue(){return 0}exportSVG(){throw new Error("exportSVG() not supported for gosling-track")}drawLoadingCue(){if(this.fetching.size){const ne=`Fetching... ${Array.from(this.fetching).join(" ")}`;Jt(this,l).text=ne,Jt(this,l).x=this.position[0]+this.dimensions[0]-6/2,Jt(this,l).y=this.position[1]+this.dimensions[1]-6/2;const fe=g.libraries.PIXI.TextMetrics.measureText(ne,Jt(this,s)),{width:Ce,height:Ze}=fe;Jt(this,a).clear(),Jt(this,a).lineStyle(1,ft("grey"),1,.5),Jt(this,a).beginFill(ft("white"),.8),Jt(this,a).drawRect(this.position[0]+this.dimensions[0]-Ce-6-1,this.position[1]+this.dimensions[1]-Ze-6-1,Ce+6,Ze+6),Jt(this,l).visible=!0,Jt(this,a).visible=!0}else Jt(this,l).visible=!1,Jt(this,a).visible=!1}updateScaleOffsetFromOriginalSpec(Q,ne,fe){this.getResolvedTracks().map(Ce=>{if(Ce._renderingId===Q){const Ze=Ce[fe];lt(Ze)&&(Ze.scaleOffset=ne)}})}shareScaleOffsetAcrossTracksAndTiles(Q,ne){this.visibleAndFetchedGoslingModels().forEach(Ce=>{const Ze=Ce.spec()[ne];lt(Ze)&&(Ze.scaleOffset=Q);const Ge=Ce.originalSpec()[ne];lt(Ge)&&(Ge.scaleOffset=Q)})}};i=new WeakMap,n=new WeakMap,C=new WeakMap,r=new WeakMap,o=new WeakMap,A=new WeakMap,s=new WeakMap,a=new WeakMap,l=new WeakMap,c=new WeakSet,u=function(ee,Q,ne){if(!Q)return ee.map(Ce=>[ne,Ce]);const fe=[];return ee.forEach(Ce=>Q.forEach(Ze=>fe.push([ne,Ce,Ze]))),fe},d=new WeakSet,h=function(){let ee;return this.tilesetInfo&&(ee="bins_per_dimension"in this.tilesetInfo?this.tilesetInfo.bins_per_dimension:this.tilesetInfo.tile_size),ee??256},m=new WeakSet,f=function(ee,Q=!1){if(Jt(this,n)[ee.tileId]&&!Q||!ee.tileData.tilePos)return;const ne=Xgg(),fe=this.getResolvedTracks();if(fe.length===0)return[];const Ce=fe[0];if("tabularData"in ee.tileData)ne.tabularData=ee.tileData.tabularData;else{const{tileX:Ze,tileY:Ge,tileWidth:ve,tileHeight:ke}=this.getTilePosAndDimensions(ee.tileData.zoomLevel,ee.tileData.tilePos),Xe="length"in ee.tileData?Array.from(ee.tileData):[],Oe=Object.assign({},ee.tileData,{sparse:Xe,tileX:Ze,tileY:Ge,tileWidth:ve,tileHeight:ke,tileSize:this.tileSize}),ze=fgg(Ce,Oe);ze&&(ne.tabularData=ze)}Jt(this,n)[ee.tileId]=ne},b=new WeakSet,p=function(ee,Q,ne){var fe;wC(this,C,ee),wC(this,r,Q);const Ce=(fe=this.options.spec.experimental)==null?void 0:fe.mouseEvents,Ze=!!Ce||zm(Ce)&&!!Ce.rangeSelect;wC(this,o,Ze&&ne),this.pMouseHover.clear()},y=new WeakSet,Z=function(ee){this.options.spec.layout!=="circular"&&Jt(this,o)&&this.mRangeBrush.updateRange([ee,Jt(this,C)]).drawBrush().visible().disable()},v=new WeakSet,G=function(ee,Q){var ne;wI(this,X,W).call(this,"trackClick",ee,Q);const fe=(ne=this.options.spec.experimental)==null?void 0:ne.mouseEvents,Ce=!!fe||zm(fe)&&!!fe.click,Ze=Math.sqrt((Jt(this,C)-ee)**2+(Jt(this,r)-Q)**2)>1;if(!Jt(this,o)&&!Ze?(this.mRangeBrush.clear(),this.pMouseSelection.clear()):this.mRangeBrush.enable(),wC(this,o,!1),!!this.tilesetInfo&&!Ze&&Ce){const Ge=gd(Math.floor(this._xScale.invert(ee)),Jt(this,i)),ve=wI(this,R,S).call(this,ee,Q);ve.length!==0&&this.options.siblingIds.forEach(ke=>Kr("click",{id:ke,genomicPosition:Ge,data:ve.map(Xe=>Xe.value)}))}},B=new WeakSet,w=function(){wC(this,o,!1),document.body.style.cursor="default",this.pMouseHover.clear()},R=new WeakSet,S=function(ee,Q){var ne;const fe=this.visibleAndFetchedGoslingModels(),Ce=(ne=this.options.spec.experimental)==null?void 0:ne.mouseEvents,Ze=zm(Ce)&&Ce.enableMouseOverOnMultipleMarks,Ge=zm(Ce)&&Ce.groupMarksByField,ve=fe.map(ke=>ke.getMouseEventModel().findAll(ee,Q,!0)).flat();if(Ze||ve.splice(1,ve.length-1),ve.length!==0&&Ge){const ke=Array.from(ve);fe.forEach(Xe=>{const Oe=Xe.getMouseEventModel().getSiblings(ke,Ge);ve.push(...Oe)})}return ve},X=new WeakSet,W=function(ee,Q,ne){const[fe,Ce]=this.position,[Ze,Ge]=this.dimensions;if(this.options.spec.layout==="circular"){const ve=fe+Ze/2,ke=Ce+Ge/2,Xe=this.options.spec.innerRadius,Oe=this.options.spec.outerRadius,ze=this.options.spec.startAngle,Me=this.options.spec.endAngle;Bqt([Q,ne],[Ze/2,Ge/2],[Xe,Oe],[ze,Me])&&Kr(ee,{id:e.viewUid,spec:structuredClone(this.options.spec),shape:{x:fe,y:Ce,width:Ze,height:Ge,cx:ve,cy:ke,innerRadius:Xe,outerRadius:Oe,startAngle:ze,endAngle:Me}})}else Kr(ee,{id:e.viewUid,spec:structuredClone(this.options.spec),shape:{x:fe,y:Ce,width:Ze,height:Ge}})},V=new WeakSet,H=function(ee,Q=!1){var ne,fe,Ce,Ze;if(this.pMouseSelection.clear(),ee===null){Q||Kr("rangeSelect",{id:e.viewUid,genomicRange:null,data:[]});return}const Ge=this.visibleAndFetchedGoslingModels(),[ve,ke]=ee;let Xe=Ge.map(Me=>Me.getMouseEventModel().findAllWithinRange(ve,ke,!0)).flat();const Oe=(ne=this.options.spec.experimental)==null?void 0:ne.mouseEvents,ze=zm(Oe)&&Oe.groupMarksByField;if(Xe.length!==0&&ze&&Ge.forEach(Me=>{const Ue=Me.getMouseEventModel().getSiblings(Xe,ze),_e=Array.from(new Set(Ue.map(At=>At.value[ze])));Xe=Xe.filter(At=>_e.indexOf(At.value[ze])===-1)}),Xe.length!==0){const Me=this.pMouseSelection;((Ce=(fe=this.options.spec.style)==null?void 0:fe.select)==null?void 0:Ce.arrange)!=="behind"&&(this.pMain.removeChild(Me),this.pMain.addChild(Me)),wI(this,D,Y).call(this,Me,Xe,Object.assign({},Ole,(Ze=this.options.spec.style)==null?void 0:Ze.select))}if(!Q){const Me=[gd(Math.floor(this._xScale.invert(ve)),Jt(this,i)),gd(Math.floor(this._xScale.invert(ke)),Jt(this,i))];Kr("rangeSelect",{id:e.viewUid,genomicRange:Me,data:Xe.map(Ue=>Ue.value)})}this.forceDraw()},D=new WeakSet,Y=function(ee,Q,ne){ee.lineStyle(ne.strokeWidth,ft(ne.stroke),ne.strokeOpacity,.5),ee.beginFill(ft(ne.color),ne.color==="none"?0:ne.opacity),Q.forEach(fe=>{if(fe.type==="point"){const[Ce,Ze,Ge=3]=fe.polygon;ee.drawCircle(Ce,Ze,Ge)}else fe.type==="line"?(ee.moveTo(fe.polygon[0],fe.polygon[1]),A7e(fe.polygon).map(Ce=>ee.lineTo(Ce[0],Ce[1]))):ee.drawPolygon(fe.polygon)})},F=new WeakSet,_=function(){Kr("onNewTrack",{id:e.viewUid})},Zg($,c);let j=$;return new j},u1=w$(Hgg,Tgg),Ngg={type:"dummy-track",defaultOptions:{height:0,width:0,title:"",background:"#fff",textFontSize:12,textFontWeight:"normal",textStroke:"#000",textStrokeWidth:.1,outline:"#fff"}},kgg=(g,e,I)=>{var i,n,C,r;const{SVGTrack:o}=g.tracks;class A extends o{constructor(){super(e,I),Zg(this,i),Zg(this,C),wI(this,i,n).call(this),wI(this,C,r).call(this),Kr("onNewTrack",{id:e.viewUid})}}return i=new WeakSet,n=function(){this.gMain.append("rect").attr("fill",I.background).attr("x",0).attr("y",0).attr("width",I.width).attr("height",I.height).style("stroke",I.outline)},C=new WeakSet,r=function(){this.gMain.append("text").attr("x",I.width/2).attr("y",(I.height+I.textFontSize)/2).style("text-anchor","middle").style("font-size",`${I.textFontSize}px`).style("font-weight",I.textFontWeight).style("stroke",I.textStroke).style("stroke-width",I.textStrokeWidth).text(I.title)},new A},Lle=w$(Ngg,kgg);let _le=!1;function Ygg(){if(!_le){Yu({name:"GoslingTrack",track:u1,config:u1.config}),Yu({name:"Gosling2DTrack",track:u1,config:{...u1.config,type:"gosling-2d-track",orientation:"2d"}}),Yu({name:"AxisTrack",track:tle,config:tle.config}),Yu({name:"TextTrack",track:u3,config:u3.config}),Yu({name:"BrushTrack",track:_O,config:_O.config}),Yu({name:"DummyTrack",track:Lle,config:Lle.config});for(const g of Object.values(hgg)){const{config:e}=g;Yu({dataFetcher:g,config:e},{pluginType:"dataFetcher"})}_le=!0}}function t2e(g){let e=0,I=0;return g.forEach(i=>{const n=i.boundingBox.x+i.boundingBox.width,C=i.boundingBox.y+i.boundingBox.height;I{s.boundingBox.y+=o+A}),n=[{track:xgg({width:C.width,height:o},g.title,g.subtitle),boundingBox:{x:0,y:0,width:C.width,height:o},layout:{x:0,y:0,w:12,h:o/C.height*12}},...n]}else C.height=C.height+(8-C.height%8);const r=!(typeof g.responsiveSize!="object"?g.responsiveSize:g.responsiveSize.height);return n.forEach(o=>{o.layout.x=o.boundingBox.x/C.width*12,o.layout.w=o.boundingBox.width/C.width*12,o.layout.y=r?o.boundingBox.y:o.boundingBox.y/C.height*12,o.layout.h=r?o.boundingBox.height:o.boundingBox.height/C.height*12}),{trackInfos:n,size:C}}function nL(g,e,I=0,i=0,n=!0){let C=0,r=0,o=!0,A=!1;Wb(g,c=>{A=!0,c.layout!=="circular"&&(o=!1)});let s=!0;i0e(g,c=>{(c.arrangement==="vertical"||c.arrangement==="horizontal")&&(s=!1)});const a=n&&o&&A&&s&&("views"in g&&(g.arrangement==="parallel"||g.arrangement==="serial")||"tracks"in g),l=e.length;if("tracks"in g){const c=g.tracks;g.orientation==="vertical"?(r=Math.max(...c.map(u=>u.height)),c.forEach((u,d,h)=>{Qle([u])===1&&(u.width+=qr),u.height=r,e.push({track:u,boundingBox:{x:I+C,y:i,width:u.width,height:r},layout:{x:0,y:0,w:0,h:0}}),h[d+1]&&h[d+1].overlayOnPreviousTrack||(C+=u.width,d!==h.length-1&&(C+=g.spacing!==void 0?g.spacing:0))})):(C=Math.max(...c.map(u=>u.width)),c.forEach((u,d,h)=>{Qle([u])===1&&(u.height+=qr);const m=F0(u);m.length>0&&IC(m[0])&&Kgg([u])===1&&(C+=qr),u.width=C,e.push({track:u,boundingBox:{x:I,y:i+r,width:C,height:u.height},layout:{x:0,y:0,w:0,h:0}}),h[d+1]&&h[d+1].overlayOnPreviousTrack||(r+=u.height,d!==h.length-1&&(r+=g.spacing!==void 0?g.spacing:0))}))}else if(g.arrangement==="parallel"||g.arrangement==="vertical"){const c=g.spacing!==void 0?g.spacing:O1;g.views.forEach((u,d,h)=>{var m,f,b,p,y;const Z=nL(u,e,I+((m=u.xOffset)!=null?m:0),i+((f=u.yOffset)!=null?f:0)+r,!a&&n);C<((b=u.xOffset)!=null?b:0)+Z.width&&(C=((p=u.xOffset)!=null?p:0)+Z.width),d!==h.length-1&&(r+=c),r+=((y=u.yOffset)!=null?y:0)+Z.height})}else(g.arrangement==="serial"||g.arrangement==="horizontal")&&g.views.forEach((c,u,d)=>{var h,m,f,b,p;const y=g.spacing!==void 0?g.spacing:O1,Z=nL(c,e,I+((h=c.xOffset)!=null?h:0)+C,i+((m=c.yOffset)!=null?m:0),!a&&n);r<((f=c.xOffset)!=null?f:0)+Z.height&&(r=((b=c.xOffset)!=null?b:0)+Z.height),u!==d.length-1&&(C+=y),C+=((p=c.xOffset)!=null?p:0)+Z.width});if(a){const c=e.slice(l),u="views"in g&&(g.arrangement==="parallel"||g.arrangement==="serial")&&g.views.length>1,d=g.spacing!==void 0?g.spacing:O1,h=LUe,m=g.centerRadius!==void 0?g.centerRadius:Gbe,f=C/2+h,b=f*(1-m);c.forEach((p,y)=>{var Z,v;if(zS(p.track))return;p.track.layout="circular",p.track.outerRadius=f-h-(p.boundingBox.y-i)/r*b,p.track.innerRadius=f-h-(p.boundingBox.y+p.boundingBox.height-i)/r*b;const G=d/C*360;p.track.startAngle=G+(p.boundingBox.x-I)/C*(C-d)/C*360,p.track.endAngle=(p.boundingBox.x+p.boundingBox.width-I)/C*(C-d)/C*360,p.boundingBox.x=I+((Z=p.track.xOffset)!=null?Z:0),p.boundingBox.y=i+((v=p.track.yOffset)!=null?v:0),p.boundingBox.height=p.track.height=p.boundingBox.width=p.track.width=f*2,y!==0&&(p.track.overlayOnPreviousTrack=!0),u&&si(p.track)&&(p.track._overlay=p.track._overlay.filter(B=>B.mark!=="brush"))}),r=f*2}return g._assignedWidth=C,g._assignedHeight=r,{x:I,y:i,width:C,height:r}}function Qle(g){return g.filter(e=>n9(e)).length}function Kgg(g){return g.filter(e=>z7e(e)).length}const xgg=(g,e,I)=>JSON.parse(JSON.stringify({mark:"header",width:g.width,height:g.height,title:e,subtitle:I}));function Dgg(g){if(!g.includes("tileset_info/?d=")||!g.includes("https:")&&!g.includes("http:"))return{server:void 0,tilesetUid:void 0};const e=g.split("tileset_info/?d=")[0],I=g.split("tileset_info/?d=")[1];return{server:e,tilesetUid:I}}function Fgg(g,e,I,i,n,C,r){var o,A,s,a,l,c,u,d,h,m,f,b,p,y,Z;if(zS(e))return g.addDefaultView(e.id).setDummyTrack(e).setLayout(i),g;const v=F0(e),G=v[0],B=(o=G.id)!=null?o:on();G.id||(G.id=B),v.forEach(R=>{R.id&&C.addMapping(R.id,B)});const w=G.assembly;if(Vte(G.data)){let R,S;if(JU(G.data)){const te=Dgg(G.data.url);R=te.server,S=te.tilesetUid}const X=S$(G),W=hHe(G),H=(W==="x"||W==="xe")&<(X)?X.domain:void 0,D=IC(G)&<(G.y)?G.y.domain:void 0,Y=I.width-(G.layout!=="circular"&&G.orientation==="vertical"&&n9(G)?qr:0),F=I.height-(G.layout!=="circular"&&G.orientation==="horizontal"&&n9(G)?qr:0),_={uid:`${B}-track`,type:IC(G)?"gosling-2d-track":"gosling-track",server:R,tilesetUid:S,width:Y,height:F,options:{id:B,siblingIds:C.getSiblingGoslingIds(B),showMousePosition:G.layout==="circular"?!1:n.root.showMousePosition,mousePositionColor:n.root.mousePositionColor,name:G.layout==="linear"?G.title:" ",labelPosition:G.title?n.track.titleAlign==="left"?"topLeft":"topRight":"none",labelShowResolution:!1,labelColor:n.track.titleColor,labelBackgroundColor:n.track.titleBackground,labelBackgroundOpacity:.5,labelTextOpacity:1,labelLeftMargin:1,labelTopMargin:1,labelRightMargin:0,labelBottomMargin:0,backgroundColor:"transparent",spec:{...e},theme:n}};if(G.data&&Vte(G.data)&&(G.data.type==="csv"||G.data.type==="json"||G.data.type==="bigwig"||G.data.type==="bam"||G.data.type==="vcf"||G.data.type==="gff"||G.data.type==="bed")){const te=ee=>{const Q=G[ee];return Q&<(Q)?Q.field:void 0},q={x:te("x"),xe:te("xe"),x1:te("x1"),x1e:te("x1e")},$="url"in G.data&&(r==null?void 0:r[G.data.url])||{},j="indexUrl"in G.data&&(r==null?void 0:r[G.data.indexUrl])||{};_.data={...G.data,...q,urlFetchOptions:$,indexUrlFetchOptions:j,assembly:w}}if(Y7e(G)){_.type="heatmap";const te=lt(G.color)&&typeof G.color.range=="string"?G.color.range:"viridis";_.options.colorRange=w7e(te),_.options.trackBorderWidth=(s=(A=G.style)==null?void 0:A.outlineWidth)!=null?s:n.track.outlineWidth,_.options.trackBorderColor=(l=(a=G.style)==null?void 0:a.outline)!=null?l:n.track.outline,_.options.extent=(u=(c=G.style)==null?void 0:c.matrixExtent)!=null?u:"full",_.options.colorbarPosition=(d=G.color)!=null&&d.legend?_.options.extent==="lower-left"?"bottomLeft":"topRight":"hidden"}G.overlayOnPreviousTrack?g.setViewOrientation(G.orientation).addTrackToCombined(_):g.setViewOrientation(G.orientation).setAssembly(w).addDefaultView(B,w).setDomain(H,D??H).adjustDomain(G.orientation,Y,F).setMainTrack(_).addTrackSourceServers(R).setZoomFixed(G.static===!0).setZoomLimits((h=G.zoomLimits)!=null?h:[1,null]).setLayout(i);const J=(te,q="horizontal",$,j)=>q==="horizontal"?te==="x"&&$<=200||te==="y"&&j<=200?"narrower":te==="x"&&$<=400||te==="y"&&j<=400?"narrow":"regular":te==="x"&&j<=200||te==="y"&&$<=200?"narrower":te==="x"&&j<=400||te==="y"&&$<=400?"narrow":"regular";["x","y"].forEach(te=>{const q=G[te];if(lt(q)&&"axis"in q&&q.axis&&q.axis!=="none"&&q.type==="genomic"){const $=J(te,e.orientation,I.width,I.height);g.setAxisTrack(q.axis,$,{id:`${B}-${q.axis}-axis`,layout:G.layout,innerRadius:q.axis==="top"?G.outerRadius-qr:G.innerRadius,outerRadius:q.axis==="top"?G.outerRadius:G.innerRadius+qr,width:G.width,height:G.height,startAngle:G.startAngle,endAngle:G.endAngle,theme:n})}}),g.validateSpec(!0)}else G.mark==="header"&&(g.addDefaultView(`${B}-title`).setLayout(i),typeof G.title=="string"&&g.setTextTrack(I.width,((m=n.root.titleFontSize)!=null?m:18)+I9,G.title,n.root.titleColor,(f=n.root.titleFontSize)!=null?f:18,n.root.titleFontWeight,n.root.titleAlign,n.root.titleBackgroundColor,(b=n.root.titleFontFamily)!=null?b:e3.fontFamily),typeof G.subtitle=="string"&&g.setTextTrack(I.width,((p=n.root.subtitleFontSize)!=null?p:14)+I9,G.subtitle,n.root.subtitleColor,(y=n.root.subtitleFontSize)!=null?y:14,n.root.subtitleFontWeight,n.root.subtitleAlign,n.root.subtitleBackgroundColor,(Z=n.root.subtitleFontFamily)!=null?Z:e3.fontFamily));return g}function Egg(g){const e=[];return g.spec().views.forEach(I=>{var i,n,C,r,o,A,s,a,l,c,u,d,h,m,f;const b=I.uid;let p=(o=(r=(C=(n=(i=I.tracks.center)==null?void 0:i[0])==null?void 0:n.contents)==null?void 0:C[0])==null?void 0:r.options)==null?void 0:o.spec;if(p||(p=(c=(l=(a=(s=(A=I.tracks.left)==null?void 0:A[0])==null?void 0:s.contents)==null?void 0:a[0])==null?void 0:l.options)==null?void 0:c.spec,p||(p=(f=(m=(h=(d=(u=I.tracks.left)==null?void 0:u[1])==null?void 0:d.contents)==null?void 0:h[0])==null?void 0:m.options)==null?void 0:f.spec)),!b||!p)return;F0(p).forEach(Z=>{xd.forEach(v=>{var G,B,w,R;const S=Z[v];if(lt(S)&&"linkingId"in S&&S.linkingId){e.push({layout:Z.layout==="circular"?"circular":"linear",hgViewId:b,linkId:S.linkingId,isBrush:Z.mark==="brush",style:{color:(G=Z.color)==null?void 0:G.value,stroke:(B=Z.stroke)==null?void 0:B.value,strokeWidth:(w=Z.strokeWidth)==null?void 0:w.value,opacity:(R=Z.opacity)==null?void 0:R.value,startAngle:Z.startAngle,endAngle:Z.endAngle,innerRadius:Z.innerRadius,outerRadius:Z.outerRadius}});return}})})}),e}class Mgg{constructor(){Zg(this,ts,{})}addMapping(e,I){Jt(this,ts)[e]&&Jt(this,ts)[e]!==I&&console.warn(`The track ID ${e} already exists but overwriting with a different ID.`),Jt(this,ts)[e]=I}getTable(){return Jt(this,ts)}getGoslingIds(){return Object.keys(Jt(this,ts))}getHiGlassId(e){return Jt(this,ts)[e]}getSiblingGoslingIds(e){return Object.entries(Jt(this,ts)).filter(([,I])=>I===e).map(([I])=>I)}}ts=new WeakMap;function zgg(g){const e=new Set;return g.id&&e.add(g.id),Wb(g,I=>{("views"in I||"tracks"in I)&&I.id&&e.add(I.id)}),Array.from(e)}function Pgg(g){const e=new Set;return Wb(g,I=>{!("views"in I)&&!("tracks"in I)&&I.id&&e.add(I.id)}),Array.from(e)}function Jgg(g,e){let I;return g.id===e&&(I=g),Wb(g,i=>{i.id===e&&(I=i)}),I}function Ogg(g,e){return zgg(g).map(I=>{const i=Jgg(g,I),n=Pgg(i),C={x:Number.MAX_SAFE_INTEGER,y:Number.MAX_SAFE_INTEGER,xe:-Number.MAX_SAFE_INTEGER,ye:-Number.MAX_SAFE_INTEGER};return n.map(r=>e.find(o=>o.id===r)).forEach(r=>{if(!r)return;const{shape:o}=r;C.x>o.x&&(C.x=o.x),C.y>o.y&&(C.y=o.y),C.xe{const{track:u,boundingBox:d,layout:h}=c;Fgg(C,u,d,h,i,r,n)});const o=Egg(C);o.filter(c=>c.isBrush).forEach(c=>{var u;C.addBrush(c.layout,c.hgViewId,i,(u=o.find(d=>!d.isBrush&&d.linkId===c.linkId))==null?void 0:u.hgViewId,c.style)}),o.filter(c=>!c.isBrush).forEach(c=>{C.spec().zoomLocks.locksByViewUid[c.hgViewId]=c.linkId,C.spec().locationLocks.locksByViewUid[c.hgViewId]=c.linkId}),Array.from(new Set(o.map(c=>c.linkId))).forEach(c=>{C.spec().zoomLocks.locksDict[c]={uid:c},C.spec().locationLocks.locksDict[c]={uid:c},o.filter(u=>!u.isBrush).filter(u=>u.linkId===c).forEach(u=>{C.spec().zoomLocks.locksDict[c][u.hgViewId]=[1246253105e-1,1246253105e-1,249250.621],C.spec().locationLocks.locksDict[c][u.hgViewId]=[1246253105e-1,1246253105e-1,249250.621]})});const s=e.map(c=>({id:c.track.id,spec:c.track,shape:c.track.layout==="linear"||zS(c.track)?c.boundingBox:{...c.boundingBox,cx:c.boundingBox.x+c.boundingBox.width/2,cy:c.boundingBox.y+c.boundingBox.height/2,innerRadius:c.track.innerRadius,outerRadius:c.track.outerRadius,startAngle:c.track.startAngle,endAngle:c.track.endAngle}})),a=Ogg(g,s),l=[...s.map(c=>({...c,type:"track"})),...a.map(c=>({...c,type:"view"}))];I(C.spec(),t2e(e),g,l,r.getTable())}function g2e(g,e,I,i,n){if(typeof g._assignedWidth>"u"||typeof g._assignedHeight>"u")return console.warn("Responsive spec cannot be used when width and height of a view is not determined yet."),!1;let C=!1;const{responsiveSpec:r}=g,o=g._assignedWidth*e,A=g._assignedHeight*I,s={width:o,height:A,aspectRatio:o/A},a={width:i,height:n,aspectRatio:i/n};return r&&r.forEach(l=>{const{spec:c,selectivity:u}=l;if(_gg(u,s,a)&&!C){Object.keys(c).forEach(d=>{g[d]=c[d]}),delete g.responsiveSpec,C=!0;return}}),"views"in g&&g.views.forEach(l=>{C=g2e(l,e,I,i,n)||C}),C}function _gg(g,e,I){if(g.length===0)return!1;let i=!0;return g.forEach(n=>{const{measure:C,operation:r,threshold:o,target:A}=n;i=i&&VG((A==="container"?I:e)[C],r,o)===1}),i}function Ugg(g,e,I,i,n,C){var r,o;const A=JSON.parse(JSON.stringify(g));f4e(A),gqt(A,I),a3(A);const s=Ule(A,i);let{trackInfos:a}=s;const{size:l}=s,c=typeof g.responsiveSize=="object"&&((r=g.responsiveSize)==null?void 0:r.width)||g.responsiveSize,u=typeof g.responsiveSize=="object"&&((o=g.responsiveSize)==null?void 0:o.height)||g.responsiveSize,d=c&&n.containerSize?n.containerSize.width/l.width:1,h=u&&n.containerSize?n.containerSize.height/l.height:1,m=n.containerParentSize?n.containerParentSize.width:Number.MAX_SAFE_INTEGER,f=n.containerParentSize?n.containerParentSize.height:Number.MAX_SAFE_INTEGER;g2e(A,d,h,m,f)&&(a3(A),a=Ule(A,i).trackInfos),Kr("specProcessed",{id:A.id,spec:A}),Lgg(A,a,e,i,C)}Ygg();const I2e=Ie.forwardRef((g,e)=>{var I;const[i,n]=Ie.useState((I=g.id)!=null?I:on());Ie.useEffect(()=>{var u;n((u=g.id)!=null?u:on())},[g.id]);const C=g.viewConfig||{},r=!1,o=Ie.useMemo(()=>N.createElement(yy,{ref:e,options:{pixelPreciseMarginPadding:r,containerPaddingX:0,containerPaddingY:0,viewMarginTop:0,viewMarginBottom:0,viewMarginLeft:0,viewMarginRight:0,viewPaddingTop:0,viewPaddingBottom:0,viewPaddingLeft:0,viewPaddingRight:0,sizeMode:"bounded",rangeSelectionOnAlt:!0},viewConfig:C}),[C,r]),{padding:A=60,margin:s=0,border:a="none",background:l,alt:c="Gosling visualization"}=g.options||{};return N.createElement(N.Fragment,null,N.createElement("div",{id:i,className:`gosling-component ${g.className||""}`,style:{position:"relative",padding:A,margin:s,border:a,background:l,width:g.options.responsiveWidth?`calc(100% - ${A*2}px)`:g.size.width,height:g.options.responsiveHeight?`calc(100% - ${A*2}px)`:g.size.height,textAlign:"left"},"aria-label":c,role:"graphics-document","aria-roledescription":"visualization"},N.createElement("div",{key:JSON.stringify(C),id:"higlass-wrapper",className:"higlass-wrapper",style:{position:"relative",display:"block",background:l,margin:0,padding:0,width:g.options.responsiveWidth?"100%":g.size.width,height:g.options.responsiveHeight?"100%":g.size.height}},o)))});I2e.displayName="HiGlassComponentWrapper";function Qgg(g,e,I,i,n){const C=structuredClone(n),r=d=>{const h=C[d];return h||console.warn(`Unable to find the track ID, named ${d}.`),h??d},o=()=>Object.keys(C),A=()=>[...I],s=()=>[...A().filter(d=>d.type==="track")],a=d=>{const h=s().find(m=>m.id===d);return h||console.warn(`[getTrack()] Unable to find a track using the ID (${d})`),h},l=()=>[...A().filter(d=>d.type==="view")],c=d=>{const h=l().find(m=>m.id===d);return h||console.warn(`Unable to find a view with the ID of ${d}`),h},u=d=>{var h,m;const f=(h=d==null?void 0:d.resolution)!=null?h:4,b=(m=d==null?void 0:d.transparentBackground)!=null?m:!1,p=g.pixiRenderer,y=il.create({width:p.width/2,height:p.height/2,resolution:f});p.render(g.pixiStage,y);const Z=p.plugins.extract.canvas(y),v=document.createElement("canvas");v.width=Z.width,v.height=Z.height;const G=v.getContext("2d");return b||(G.fillStyle=i.root.background,G.fillRect(0,0,v.width,v.height)),G.drawImage(Z,0,0),{canvas:v,resolution:f,canvasWidth:Z.width,canvasHeight:Z.height}};return{subscribe:Rgg,unsubscribe:Wgg,zoomTo:(d,h,m=0,f=1e3)=>{var b;const p=(b=a(d))==null?void 0:b.spec.assembly,Z=t7.fromString(h).toAbsoluteCoordinates(p,m),v=r(d);g.api.zoomTo(v,...Z,...Z,f)},zoomToExtent:(d,h=1e3)=>{var m;const f=(m=a(d))==null?void 0:m.spec.assembly,[b,p]=[0,yI(f).total],y=r(d);g.api.zoomTo(y,b,p,b,p,h)},zoomToGene:(d,h,m=0,f=1e3)=>{const b=r(d);g.api.zoomToGene(b,h,m,f)},suggestGene:(d,h,m)=>{const f=r(d);g.api.suggestGene(f,h,m)},getTrackIds:o,getTracksAndViews:A,getTracks:s,getTrack:a,getView:c,getViews:l,getCanvas:u,exportPng:d=>{const{canvas:h}=u({resolution:4,transparentBackground:d});h.toBlob(m=>{const f=document.createElement("a");document.body.append(f),f.download="gosling-visualization",f.href=URL.createObjectURL(m),f.click(),f.remove()},"image/png")},exportPdf:async d=>{const{jsPDF:h}=await c5e(()=>import("./jspdf.es.min-282c0c72.js").then(p=>p.j),[]),{canvas:m}=u({resolution:4,transparentBackground:d}),f=m.toDataURL("image/jpeg",1),b=new h({orientation:m.width{PU(I)&&e.forEach(i=>{delete I[i]})})}const jgg=(g,e)=>{g.views.forEach(I=>{var i,n,C;const r=I.uid;if(!e.views.find(A=>A.uid===r)){const{locksByViewUid:A}=g.zoomLocks,s=A[r],a=(i=Object.entries(A).find(([c,u])=>c&&u===s))==null?void 0:i[0],l=!!e.views.find(c=>c.uid===a);a&&l&&(I.initialXDomain=(n=e.views.find(c=>c.uid===a))==null?void 0:n.initialXDomain,I.initialYDomain=(C=e.views.find(c=>c.uid===a))==null?void 0:C.initialYDomain)}})},$gg=300,i2e=Ie.forwardRef((g,e)=>{var I,i,n;const[C,r]=Ie.useState(),[o,A]=Ie.useState({width:200,height:200}),s=Ie.useRef(),a=Ie.useRef(),l=Ie.useRef(),c=Ie.useRef([]),u=Ie.useRef({}),d=Ie.useRef(null),h=e2e(g.theme||"light"),m=(I=g.id)!=null?I:on(),f=Z=>{const v=c.current.filter(R=>R.type=="view"),G=Z.filter(R=>R.type=="view"),B=new Set(v.map(R=>R.id));G.filter(R=>!B.has(R.id)).forEach(R=>{Kr("onNewView",{id:R.id})})};Ie.useImperativeHandle(e,()=>{const Z=$le(d),v=$le(c);return{api:Qgg(Z,C,v,h,u.current),hgApi:Z}},[C,h]);const b=Ie.useCallback(()=>{if(g.spec){if(eqt(g.spec).state==="error"){console.warn("Gosling spec is not valid. Please refer to the console message.");return}Ugg(g.spec,(v,G,B,w,R)=>{var S,X;if(l.current&&fbe(jle(l.current,["linkingId"]),jle(B,["linkingId"])))return;(S=g.compiled)==null||S.call(g,g.spec,v,{_processedSpec:B}),A(G);const W=typeof C<"u";(X=g.experimental)!=null&&X.reactive&&W?setTimeout(()=>{var V,H;jgg(v,(V=d.current)==null?void 0:V.api.getViewConfig()),(H=d.current)==null||H.api.setViewConfig(v)},$gg):r(v),f(w),l.current=B,c.current=w,u.current=R},[...tqt],h,{containerSize:s.current,containerParentSize:a.current},g.urlToFetchOptions)}},[g.spec,h]);Ie.useEffect(()=>{var Z;if(!((Z=g.spec)!=null&&Z.responsiveSize))return;const v=document.getElementById(m);if(!v)return;const G=new zse.ResizeSensor(v,R=>{(!s.current||s.current.height!==R.height||s.current.width!==R.width)&&(s.current=R,b())}),B=v.parentElement;if(!B)return;const w=new zse.ResizeSensor(B,R=>{(!a.current||a.current.height!==R.height||a.current.width!==R.width)&&(a.current=R,b())});return()=>{G.detach(),w.detach()}}),Ie.useEffect(()=>{b()},[g.spec,h]);const p=typeof((i=g.spec)==null?void 0:i.responsiveSize)!="object"?(n=g.spec)==null?void 0:n.responsiveSize:g.spec.responsiveSize.height;return Ie.useMemo(()=>{var Z,v,G;return N.createElement(I2e,{ref:d,viewConfig:C,size:o,id:m,className:g.className,options:{padding:g.padding,border:g.border,margin:g.margin,responsiveWidth:typeof((Z=g.spec)==null?void 0:Z.responsiveSize)!="object"?(v=g.spec)==null?void 0:v.responsiveSize:g.spec.responsiveSize.width,responsiveHeight:p,background:h.root.background,alt:(G=g.spec)==null?void 0:G.description}})},[C,o,h,p])});i2e.displayName="GoslingComponent";function $le(g){return new Proxy({},{get(e,I,i){if(!g.current)throw Error("ref is not set!");return Reflect.get(g.current,I,i)}})}var qle=QI;qle.createRoot,qle.hydrateRoot;const qgg=["x","xe","x1","x1e","y","ye","y1","y1e","color","size","row","stroke","strokeWidth","opacity","text"];function eIg(g){return typeof g=="object"&&g!==null}function tIg(g){return"alignment"in g&&g.alignment==="overlay"}function gIg(g){return g!==null&&typeof g=="object"&&"value"in g}function IIg(g){return eIg(g)&&!("value"in g)}function ece(g,e){return e in g}function Ud(g){return g.length===1?g[0]:g.slice(0,-1).join(", ")+" and "+g.slice(-1)}function iIg(g){return g[0].toUpperCase()+g.slice(1)}const zn=new Map([["point","points"],["line","lines"],["bar","bars"],["rect","rectangles"],["area","area displayed"],["withinLink","connections"],["betweenLink","connections"],["triangleLeft","triangles"],["triangleRight","triangles"],["triangleBottom","triangles"]]),ja=new Map([["y","height"],["color","color"],["strokeWidth","stroke width"],["opacity","opacity"],["text","text"]]);function nIg(g){return g.includes("chr")&&(g=g.replace("chr","")),g}function D$(g,e){let I;Array.isArray(g.appearance.details.mark)?I=g.appearance.details.mark[e]:I=g.appearance.details.mark;const i=g.appearance.details.encodings.encodingDeepGenomic.map(r=>r.name),n=g.appearance.details.encodings.encodingDeepQuantitative.map(r=>r.name),C=g.appearance.details.encodings.encodingDeepNominal.map(r=>r.name);if(I==="point"&&n.includes("x")&&n.includes("y"))return"scatter plot";if(I==="line"&&i.includes("x")&&n.includes("y")||I==="line"&&n.includes("x")&&i.includes("y"))return"line chart";if(I==="bar"&&i.includes("x")&&n.includes("y"))return"bar chart";if(I==="rect"&&i.includes("x")&&i.includes("xe")&&n.includes("color"))return"heat map";if(I==="rect"&&i.includes("x")&&i.includes("xe")&&C.includes("color"))return"ideogram"}function CIg(g){const e={};e.tracks={},e.title=g.title,e.subtitle=g.subtitle;const I={nTracks:0,rowViews:0,colViews:0,allPositions:[[0,0]],totalRows:0,totalCols:0,matrix:{}},i={};i.arrangement="vertical",i.layout="linear",n2e(g,e,i,I),sIg(I);const n={description:"",nTracks:I.nTracks,parentValues:i,counter:I};return e.composition=n,e.alt="",e.longDescription="",e}function n2e(g,e,I,i){if("tracks"in g){const n=tce(g,I);if(g.tracks.length>1)if(tIg(g)){const C=g;e.tracks[i.nTracks]=rIg(C,n,i),i.nTracks>0&&(i.allPositions=[...i.allPositions,[i.rowViews,i.colViews]]),i.nTracks++}else for(const C in g.tracks){const r=g.tracks[C];e.tracks[i.nTracks]=gce(r,n,i),i.nTracks>0&&(i.allPositions=[...i.allPositions,[i.rowViews,i.colViews]]),i.nTracks++}else{const C=g.tracks[0];e.tracks[i.nTracks]=gce(C,I,i),i.nTracks>0&&(i.allPositions=[...i.allPositions,[i.rowViews,i.colViews]]),i.nTracks++}}else if("views"in g){const n=i.rowViews,C=i.colViews;g.views.forEach((r,o)=>{o!==0&&(I.arrangement==="vertical"||I.arrangement==="parallel"?i.rowViews++:i.colViews++);const A=tce(r,I);n2e(r,e,A,i)}),I.arrangement==="vertical"||I.arrangement==="parallel"?i.rowViews=n:i.colViews=C}}function tce(g,e){const I=JSON.parse(JSON.stringify(e));return ece(g,"arrangement")&&(I.arrangement=g.arrangement),ece(g,"layout")&&(I.layout=g.layout),I}function gce(g,e,I){const i={};i.alttype="single";let n;g.id!=="unknown"?n=g.id:n="";const C={trackNumber:I.nTracks,rowNumber:I.rowViews,colNumber:I.colViews},r={};r.assembly=g.assembly,r.layout=e.layout,r.overlaid=!1,r.mark=g.mark,r.encodings=eT(g);const o=F$(g.data,r.encodings),A={data:g.data,fields:o},s={description:"",details:C},a={description:"",details:r},l={description:"",details:A};return i.uid=n,i.position=s,i.appearance=a,i.title=g.title,i.data=l,i.charttype=D$(i),i.description="",i}function rIg(g,e,I){let i=n0e(g);return i=Sbe(i),i.length>1?AIg(g,i,e,I):oIg(g,e,I)}function oIg(g,e,I){const i={};i.alttype="ov-mark";let n;g.id!=="unknown"?n=g.id:n="";const C={trackNumber:I.nTracks,rowNumber:I.rowViews,colNumber:I.colViews},r={};r.assembly=g.assembly,r.layout=e.layout,r.overlaid=!0,r.encodings=eT(g);const o=[],A=[];g.mark&&o.push(g.mark);for(const c of g.tracks){const u=c;u.mark&&o.push(u.mark),A.push(eT(u))}if(r.mark=o,r.encodingsByMark=A,g.data){const c=F$(g.data,r.encodings),d={description:"",details:{data:g.data,fields:c}};i.data=d}const s={description:"",details:C},a={description:"",details:r};i.uid=n,i.position=s,i.appearance=a,i.title=g.title;const l=[];for(let c=0;c0&&(e.encodingDeepGenomic[0].details.field?I.genomicField=e.encodingDeepGenomic[0].details.field:I.genomicField),e.encodingDeepQuantitative.length>0&&(e.encodingDeepQuantitative[0].details.field?I.valueField=e.encodingDeepQuantitative[0].details.field:I.valueField),e.encodingDeepNominal.length>0&&(e.encodingDeepNominal[0].details.field?I.categoryField=e.encodingDeepNominal[0].details.field:I.categoryField),I}function eT(g){const e=[],I=[],i=[],n=[];return qgg.forEach(r=>{const o=g[r];IIg(o)?o.type==="genomic"?e.push({name:r,description:"",details:o}):o.type==="quantitative"?I.push({name:r,description:"",details:o}):i.push({name:r,description:"",details:o}):gIg(o)&&n.push({name:r,description:"",details:o})}),{encodingDeepGenomic:e,encodingDeepQuantitative:I,encodingDeepNominal:i,encodingValue:n}}function sIg(g){g.totalRows=Math.max(...g.allPositions.map(I=>I[0]))+1,g.totalCols=Math.max(...g.allPositions.map(I=>I[1]))+1;const e={};for(let I=0;IC[0]===I).map(C=>C[1]),n={};for(const C of i)n[C]?n[C]=n[C]+1:n[C]=1;e[I]=n}g.matrix=e}function lIg(g){cIg(g),hIg(g)}function cIg(g){g.composition.nTracks==1?(g.tracks[0].position.description="This is the only track.",g.tracks[0].alttype==="single"?g.composition.description="There is one ("+g.tracks[0].appearance.details.layout+") track.":g.composition.description="There is one (overlaid) track."):g.composition.nTracks==2?uIg(g):dIg(g)}function uIg(g){let e="",I="",i="";if(g.tracks[0].appearance.details.layout==="circular"&&g.tracks[1].appearance.details.layout==="circular")switch(g.composition.parentValues.arrangement){case"serial":e="left half of ring",I="right half of ring",i="Two circular tracks form one ring, with both the half of the ring.";break;case"parallel":e="outer ring",I="inner ring",i="Two circular tracks form two rings, one around the other.";break;case"horizontal":e="left",I="right",i="Two circular tracks are shown next to each other.";break;default:e="top",I="bottom",i="Two circular tracks are shown below each other."}else{const n=g.tracks[0].appearance.details.layout===g.tracks[1].appearance.details.layout;switch(g.composition.parentValues.arrangement){case"serial":e="left",I="right",i=" are shown next to each other.";break;default:e="top",I="bottom",i="are shown below each other."}n?i="".concat("Two linear tracks ",i):i="".concat("One linear and one circular track ",i)}g.tracks[0].position.description="This track is shown on the "+e+".",g.tracks[1].position.description="This track is shown on the "+I+".",g.composition.description=i}function dIg(g){const e=["first","second","third","fourth","fifth","sixth","seventh","eighth","ninth","tenth"];let I="";if(g.composition.counter.totalRows===1)I=I.concat("There are "+g.composition.counter.nTracks+" tracks, displayed next to each other.");else if(g.composition.counter.totalCols===1)I=I.concat("There are "+g.composition.counter.nTracks+" tracks, displayed below each other.");else{I=I.concat("There are "+g.composition.counter.nTracks+" tracks."),I=I.concat(" There are "+g.composition.counter.totalRows+" rows.");const i=Object.keys(g.composition.counter.matrix).map(C=>Object.keys(g.composition.counter.matrix[C]).length),n=[...new Set(i)];if(n.length==1)I=I.concat(" Each row has "+n[0]+" tracks next to each other");else if(n.length==2){const C=[],r=[];for(let o=0;oo+1))+" have "+n[0]+" column(s) each."),I=I.concat(" The other rows have "+n[1]+" column(s) each.")):(I=I.concat(" Row(s) "+Ud(r.map(o=>o+1))+" have "+n[1]+" column(s) each."),I=I.concat(" The other rows have "+n[0]+" column(s) each."))}else for(let C=0;C9?I=I.concat(" Row number "+C+" has "+g.composition.counter.matrix[C].length+" track(s) next to each other."):I=I.concat(" The "+e[C]+" row has "+g.composition.counter.matrix[C].length+" track(s) next to each other.")}g.composition.description=I;for(const i in g.tracks){let n="";const C=g.tracks[i].position.details,r=g.composition.counter;g.composition.counter.totalRows>1&&(C.rowNumber===0?n=n.concat("top row"):C.rowNumber===r.totalRows-1?n=n.concat("bottom row"):C.rowNumber<10?n=n.concat(e[C.rowNumber]+" row"):n=n.concat("row "+C.rowNumber+1)),g.composition.counter.totalCols>1&&(n.length>1&&(n=n.concat(", ")),r.matrix[C.rowNumber].length>1&&(C.colNumber===1?n=n.concat("left"):C.colNumber===r.matrix[C.rowNumber].length?n=n.concat("right"):C.colNumber===2&&r.matrix[C.rowNumber].length===3?n=n.concat("middle"):n=n.concat(e[C.colNumber]+" from left"))),g.tracks[i].position.description=n}}function hIg(g){for(const e in g.tracks){const I=g.tracks[e];if(I.alttype==="single"){let i="";I.charttype?i=i.concat(iIg(I.charttype)+"."):i=i.concat("Chart with "+zn.get(I.appearance.details.mark)+".");const n=mIg(I);i=i.concat(" "+n.desc),I.appearance.description=i,I.appearance.details.encodingsDescList=n.descList}else I.alttype==="ov-mark"&&(I.appearance.details.encodingsDescList=[[]])}}function mIg(g){const e=g.appearance.details.mark;let I="",i="",n="",C="";const r=[],o=g.appearance.details.encodings.encodingDeepGenomic.map(l=>l.name);if(o.includes("x")&&o.includes("y"))I=I.concat("The genome is shown on both the x- and y-axes."),o.includes("xe")&&o.includes("ye")?(I=I.concat(" Each displays genomic intervals."),r.push(["x","The x-axis show genomic intervals."]),r.push(["y","The y-axis show genomic intervals."])):o.includes("xe")?(I=I.concat(" The genome on the x-axis displays genomic intervals."),r.push(["x","The x-axis show genomic intervals."]),r.push(["y","The y-axis shows the genome."])):o.includes("ye")?(I=I.concat(" The genome on the y-axis displays genomic intervals."),r.push(["x","The x-axis shows the genome."]),r.push(["y","The y-axis show genomic intervals."])):(r.push(["x","The x-axis shows the genome."]),r.push(["y","The y-axis shows the genome."]));else{if(o.includes("x")){let l="";o.includes("xe")?(l="in intervals",r.push(["x","The x-axis show genomic intervals."])):r.push(["x","The x-axis shows the genome."]),I=I.concat("The genome is shown "+l+" on the x-axis.")}if(o.includes("y")){let l="";o.includes("ye")?(l="in intervals",r.push(["y","The y-axis show genomic intervals."])):r.push(["y","The y-axis shows the genome."]),I=I.concat("The genome is shown "+l+" on the y-axis.")}}const A=g.appearance.details.encodings.encodingDeepQuantitative.map(l=>l.name);if(A.length>1){i=i.concat("The expression values are shown with "+zn.get(e)+" on the "+Ud(A)+"-axes.");for(const l of A)r.push([l,"The "+l+" of the "+zn.get(e)+" shows the expression values."])}else A.length===1&&(A.includes("y")?(i=i.concat("The expression is shown on the y-axis with "+zn.get(e)+"."),r.push(["y","The y-axis shows the expression with"+zn.get(e)+"."])):A.includes("color")?(i=i.concat("The height of the expression values is shown with color."),r.push(["color","The color of the "+zn.get(e)+" shows the expression values."])):(i=i.concat("The height of the expression values is shown with the "+A[0]+"-axis."),r.push([ja.get(A[0]),"The "+ja.get(A[0])+" of the "+zn.get(e)+" shows the expression values."])));const s=g.appearance.details.encodings.encodingDeepNominal.map(l=>l.name);if(s.length>1)if(s.includes("row")){n=n.concat("The chart is stratified by rows for the categories.");const l=s.filter(c=>c!=="row").map(c=>ja.get(c));n=n.concat(" The categories are also shown with the "+Ud(l)+" of the "+zn.get(e)+"."),r.push(["row","The chart is stratified by rows for the categories."]);for(const c of l)r.push([ja.get(c),"The "+c+" of the "+zn.get(e)+" show the different categories."])}else{const l=s.map(c=>ja.get(c));n=n.concat("The categories are shown with the "+Ud(l)+" of the "+zn.get(e)+".");for(const c of s)r.push([ja.get(c),"The "+c+" of the "+zn.get(e)+" show the different categories."])}else s.length==1&&(s.includes("row")?(n=n.concat("The chart is stratified by rows for the categories."),r.push(["row","The chart is stratified by rows for the categories."])):(n=n.concat("The "+ja.get(s[0])+" of the "+zn.get(e)+" indicates the different categories."),r.push([ja.get(s[0]),"The "+ja.get(s[0])+" of the "+zn.get(e)+" show the different categories."])));for(let l=0;lr[n]).filter(r=>!isNaN(r));i.genomicMin=Math.min(...C),i.genomicMax=Math.max(...C)}catch(C){console.log(C)}}if(I.valueField!==void 0){const n=I.valueField;try{const C=e.map(r=>r[n]).filter(r=>!isNaN(r));i.valueMin=Math.min(...C),i.valueMax=Math.max(...C)}catch(C){console.log(C)}}if(I.genomicField!==void 0&&I.valueField!==void 0){const n=I.genomicField,C=I.valueField;try{i.valueMinGenomic=e.filter(r=>r[C]==i.valueMin).map(r=>r[n]),i.valueMaxGenomic=e.filter(r=>r[C]==i.valueMax).map(r=>r[n])}catch(r){console.log(r)}}if(I.categoryField!==void 0){const n=I.genomicField,C=I.valueField,r=I.categoryField;try{const o=e.map(l=>l[r]),A=[...new Set(o)],s={},a=[];for(const l of A){const c=e.filter(b=>b[r]===l),u=c.map(b=>b[C]).filter(b=>!isNaN(b)),d=Math.min(...u),h=Math.max(...u),m=c.filter(b=>b[C]==d).map(b=>b[n]),f=c.filter(b=>b[C]==h).map(b=>b[n]);s[l]=[d,m,h,f],h===i.valueMax&&a.push(l)}i.categories=A,i.categoryMinMaxWG=s,i.highestCategory=a}catch(o){console.log(o)}}return i}else return i}function GIg(g,e,I){const i=g.tracks.length>1;for(let n=0;n{let s=C.current;s!==r&&console.warn(`WARN: A component changed from ${s?"controlled":"uncontrolled"} to ${r?"controlled":"uncontrolled"}.`),C.current=r},[r]);let o=r?g:i,A=Ie.useCallback((s,...a)=>{let l=(c,...u)=>{I&&(Object.is(o,c)||I(c,...u)),r||(o=c)};typeof s=="function"?(console.warn("We can not support a function callback. See Github Issues for details https://github.com/adobe/react-spectrum/issues/2320"),n((u,...d)=>{let h=s(r?o:u,...d);return l(h,...a),r?u:h})):(r||n(s),l(s,...a))},[r,o,I]);return[o,A]}const tT={prefix:String(Math.round(Math.random()*1e10)),current:0},A2e=N.createContext(tT),wIg=N.createContext(!1);let VIg=!!(typeof window<"u"&&window.document&&window.document.createElement),zF=new WeakMap;function RIg(g=!1){let e=Ie.useContext(A2e),I=Ie.useRef(null);if(I.current===null&&!g){var i,n;let C=(n=N.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED)===null||n===void 0||(i=n.ReactCurrentOwner)===null||i===void 0?void 0:i.current;if(C){let r=zF.get(C);r==null?zF.set(C,{id:e.current,state:C.memoizedState}):C.memoizedState!==r.state&&(e.current=r.id,zF.delete(C))}I.current=++e.current}return I.current}function WIg(g){let e=Ie.useContext(A2e);e===tT&&!VIg&&console.warn("When server rendering, you must wrap your application in an to ensure consistent ids are generated between the client and server.");let I=RIg(!!g),i=`react-aria${e.prefix}`;return g||`${i}-${I}`}function XIg(g){let e=N.useId(),[I]=Ie.useState(Qw()),i=I?"react-aria":`react-aria${tT.prefix}`;return g||`${i}-${e}`}const HIg=typeof N.useId=="function"?XIg:WIg;function TIg(){return!1}function NIg(){return!0}function kIg(g){return()=>{}}function Qw(){return typeof N.useSyncExternalStore=="function"?N.useSyncExternalStore(kIg,TIg,NIg):Ie.useContext(wIg)}function a2e(g){var e,I,i="";if(typeof g=="string"||typeof g=="number")i+=g;else if(typeof g=="object")if(Array.isArray(g))for(e=0;e{};function or(g){const e=Ie.useRef(null);return mi(()=>{e.current=g},[g]),Ie.useCallback((...I)=>{const i=e.current;return i(...I)},[])}function KIg(g){let[e,I]=Ie.useState(g),i=Ie.useRef(null),n=or(()=>{let r=i.current.next();if(r.done){i.current=null;return}e===r.value?n():I(r.value)});mi(()=>{i.current&&n()});let C=or(r=>{i.current=r(e),n()});return[e,C]}let xIg=!!(typeof window<"u"&&window.document&&window.document.createElement),gT=new Map;function Jh(g){let[e,I]=Ie.useState(g),i=Ie.useRef(null),n=HIg(e),C=Ie.useCallback(r=>{i.current=r},[]);return xIg&&gT.set(n,C),mi(()=>{let r=n;return()=>{gT.delete(r)}},[n]),Ie.useEffect(()=>{let r=i.current;r&&(i.current=null,I(r))}),n}function DIg(g,e){if(g===e)return g;let I=gT.get(g);if(I)return I(e),e;let i=gT.get(e);return i?(i(g),g):e}function nce(g=[]){let e=Jh(),[I,i]=KIg(e),n=Ie.useCallback(()=>{i(function*(){yield e,yield document.getElementById(e)?e:void 0})},[e,i]);return mi(n,[e,n,...g]),I}function FIg(...g){return(...e)=>{for(let I of g)typeof I=="function"&&I(...e)}}const pc=g=>{var e;return(e=g==null?void 0:g.ownerDocument)!==null&&e!==void 0?e:document},IT=g=>g&&"window"in g&&g.window===g?g:pc(g).defaultView||window;function bi(...g){let e={...g[0]};for(let I=1;I=65&&n.charCodeAt(2)<=90?e[n]=FIg(C,r):(n==="className"||n==="UNSAFE_className")&&typeof C=="string"&&typeof r=="string"?e[n]=YIg(C,r):n==="id"&&C&&r?e.id=DIg(C,r):e[n]=r!==void 0?r:C}}return e}function EIg(...g){return g.length===1?g[0]:e=>{for(let I of g)typeof I=="function"?I(e):I!=null&&(I.current=e)}}const MIg=new Set(["id"]),zIg=new Set(["aria-label","aria-labelledby","aria-describedby","aria-details"]),PIg=new Set(["href","target","rel","download","ping","referrerPolicy"]),JIg=/^(data-.*)$/;function Da(g,e={}){let{labelable:I,isLink:i,propNames:n}=e,C={};for(const r in g)Object.prototype.hasOwnProperty.call(g,r)&&(MIg.has(r)||I&&zIg.has(r)||i&&PIg.has(r)||n!=null&&n.has(r)||JIg.test(r))&&(C[r]=g[r]);return C}function Rs(g){if(OIg())g.focus({preventScroll:!0});else{let e=LIg(g);g.focus(),_Ig(e)}}let d1=null;function OIg(){if(d1==null){d1=!1;try{var g=document.createElement("div");g.focus({get preventScroll(){return d1=!0,!0}})}catch{}}return d1}function LIg(g){for(var e=g.parentNode,I=[],i=document.scrollingElement||document.documentElement;e instanceof HTMLElement&&e!==i;)(e.offsetHeight"u"||window.navigator==null?!1:((e=window.navigator.userAgentData)===null||e===void 0?void 0:e.brands.some(I=>g.test(I.brand)))||g.test(window.navigator.userAgent)}function z$(g){var e;return typeof window<"u"&&window.navigator!=null?g.test(((e=window.navigator.userAgentData)===null||e===void 0?void 0:e.platform)||window.navigator.platform):!1}function Oh(){return z$(/^Mac/i)}function UIg(){return z$(/^iPhone/i)}function s2e(){return z$(/^iPad/i)||Oh()&&navigator.maxTouchPoints>1}function P$(){return UIg()||s2e()}function QIg(){return Oh()||P$()}function jIg(){return ZY(/AppleWebKit/i)&&!$Ig()}function $Ig(){return ZY(/Chrome/i)}function iT(){return ZY(/Android/i)}function qIg(){return ZY(/Firefox/i)}const eig=Ie.createContext({isNative:!0,open:gig});function l2e(){return Ie.useContext(eig)}function Lh(g,e,I=!0){var i,n;let{metaKey:C,ctrlKey:r,altKey:o,shiftKey:A}=e;qIg()&&(!((n=window.event)===null||n===void 0||(i=n.type)===null||i===void 0)&&i.startsWith("key"))&&g.target==="_blank"&&(Oh()?C=!0:r=!0);let s=jIg()&&Oh()&&!s2e()?new KeyboardEvent("keydown",{keyIdentifier:"Enter",metaKey:C,ctrlKey:r,altKey:o,shiftKey:A}):new MouseEvent("click",{metaKey:C,ctrlKey:r,altKey:o,shiftKey:A,bubbles:!0,cancelable:!0});Lh.isOpening=I,Rs(g),g.dispatchEvent(s),Lh.isOpening=!1}Lh.isOpening=!1;function tig(g,e){if(g instanceof HTMLAnchorElement)e(g);else if(g.hasAttribute("data-href")){let I=document.createElement("a");I.href=g.getAttribute("data-href"),g.hasAttribute("data-target")&&(I.target=g.getAttribute("data-target")),g.hasAttribute("data-rel")&&(I.rel=g.getAttribute("data-rel")),g.hasAttribute("data-download")&&(I.download=g.getAttribute("data-download")),g.hasAttribute("data-ping")&&(I.ping=g.getAttribute("data-ping")),g.hasAttribute("data-referrer-policy")&&(I.referrerPolicy=g.getAttribute("data-referrer-policy")),g.appendChild(I),e(I),g.removeChild(I)}}function gig(g,e){tig(g,I=>Lh(I,e))}function Iig(g){return{"data-href":g.href,"data-target":g.target,"data-rel":g.rel,"data-download":g.download,"data-ping":g.ping,"data-referrer-policy":g.referrerPolicy}}let qf=new Map,oL=new Set;function Cce(){if(typeof window>"u")return;let g=I=>{let i=qf.get(I.target);i||(i=new Set,qf.set(I.target,i),I.target.addEventListener("transitioncancel",e)),i.add(I.propertyName)},e=I=>{let i=qf.get(I.target);if(i&&(i.delete(I.propertyName),i.size===0&&(I.target.removeEventListener("transitioncancel",e),qf.delete(I.target)),qf.size===0)){for(let n of oL)n();oL.clear()}};document.body.addEventListener("transitionrun",g),document.body.addEventListener("transitionend",e)}typeof document<"u"&&(document.readyState!=="loading"?Cce():document.addEventListener("DOMContentLoaded",Cce));function c2e(g){requestAnimationFrame(()=>{qf.size===0?g():oL.add(g)})}function u2e(){let g=Ie.useRef(new Map),e=Ie.useCallback((n,C,r,o)=>{let A=o!=null&&o.once?(...s)=>{g.current.delete(r),r(...s)}:r;g.current.set(r,{type:C,eventTarget:n,fn:A,options:o}),n.addEventListener(C,r,o)},[]),I=Ie.useCallback((n,C,r,o)=>{var A;let s=((A=g.current.get(r))===null||A===void 0?void 0:A.fn)||r;n.removeEventListener(C,s,o),g.current.delete(r)},[]),i=Ie.useCallback(()=>{g.current.forEach((n,C)=>{I(n.eventTarget,n.type,C,n.options)})},[I]);return Ie.useEffect(()=>i,[i]),{addGlobalListener:e,removeGlobalListener:I,removeAllGlobalListeners:i}}function iig(g,e){let{id:I,"aria-label":i,"aria-labelledby":n}=g;return I=Jh(I),n&&i?n=[...new Set([I,...n.trim().split(/\s+/)])].join(" "):n&&(n=n.trim().split(/\s+/).join(" ")),!i&&!n&&e&&(i=e),{id:I,"aria-label":i,"aria-labelledby":n}}function jw(g){const e=Ie.useRef();return Ie.useMemo(()=>({get current(){return e.current},set current(I){e.current=I,typeof g=="function"?g(I):g&&(g.current=I)}}),[g])}function d2e(g,e){const I=Ie.useRef(!0),i=Ie.useRef(null);Ie.useEffect(()=>(I.current=!0,()=>{I.current=!1}),[]),Ie.useEffect(()=>{I.current?I.current=!1:(!i.current||e.some((n,C)=>!Object.is(n,i[C])))&&g(),i.current=e},e)}function h2e(g,e){mi(()=>{if(g&&g.ref&&e)return g.ref.current=e.current,()=>{g.ref.current=null}})}function ic(g){for(nT(g)&&(g=g.parentElement);g&&!nT(g);)g=g.parentElement;return g||document.scrollingElement||document.documentElement}function nT(g){let e=window.getComputedStyle(g);return/(auto|scroll)/.test(e.overflow+e.overflowX+e.overflowY)}let nig=0;const PF=new Map;function GY(g){let[e,I]=Ie.useState(void 0);return mi(()=>{if(!g)return;let i=PF.get(g);if(i)I(i.element.id);else{let n=`react-aria-description-${nig++}`;I(n);let C=document.createElement("div");C.id=n,C.style.display="none",C.textContent=g,document.body.appendChild(C),i={refCount:0,element:C},PF.set(g,i)}return i.refCount++,()=>{--i.refCount===0&&(i.element.remove(),PF.delete(g))}},[g]),{"aria-describedby":g?e:void 0}}function Cig(g,e,I,i){let n=or(I),C=I==null;Ie.useEffect(()=>{if(C)return;let r=g.current;return r.addEventListener(e,n,i),()=>{r.removeEventListener(e,n,i)}},[g,e,i,C,n])}function m2e(g,e){let I=rce(g,e,"left"),i=rce(g,e,"top"),n=e.offsetWidth,C=e.offsetHeight,r=g.scrollLeft,o=g.scrollTop,{borderTopWidth:A,borderLeftWidth:s}=getComputedStyle(g),a=g.scrollLeft+parseInt(s,10),l=g.scrollTop+parseInt(A,10),c=a+g.clientWidth,u=l+g.clientHeight;I<=r?r=I-parseInt(s,10):I+n>c&&(r+=I+n-c),i<=l?o=i-parseInt(A,10):i+C>u&&(o+=i+C-u),g.scrollLeft=r,g.scrollTop=o}function rce(g,e,I){const i=I==="left"?"offsetLeft":"offsetTop";let n=0;for(;e.offsetParent&&(n+=e[i],e.offsetParent!==g);){if(e.offsetParent.contains(g)){n-=g[i];break}e=e.offsetParent}return n}function nc(g,e){if(document.contains(g)){let r=document.scrollingElement||document.documentElement;if(window.getComputedStyle(r).overflow==="hidden"){let A=ic(g);for(;g&&A&&g!==r&&A!==r;)m2e(A,g),g=A,A=ic(g)}else{var I;let{left:A,top:s}=g.getBoundingClientRect();g==null||(I=g.scrollIntoView)===null||I===void 0||I.call(g,{block:"nearest"});let{left:a,top:l}=g.getBoundingClientRect();if(Math.abs(A-a)>1||Math.abs(s-l)>1){var i,n,C;e==null||(n=e.containingElement)===null||n===void 0||(i=n.scrollIntoView)===null||i===void 0||i.call(n,{block:"center",inline:"center"}),(C=g.scrollIntoView)===null||C===void 0||C.call(g,{block:"nearest"})}}}}function AL(g){return g.mozInputSource===0&&g.isTrusted?!0:iT()&&g.pointerType?g.type==="click"&&g.buttons===1:g.detail===0&&!g.pointerType}function rig(g){return!iT()&&g.width===0&&g.height===0||g.width===1&&g.height===1&&g.pressure===0&&g.detail===0&&g.pointerType==="mouse"}function oig(g,e,I){let i=Ie.useRef(e),n=or(()=>{I&&I(i.current)});Ie.useEffect(()=>{var C;let r=g==null||(C=g.current)===null||C===void 0?void 0:C.form;return r==null||r.addEventListener("reset",n),()=>{r==null||r.removeEventListener("reset",n)}},[g,n])}function Aig(g,e){return e.get?e.get.call(g):e.value}function f2e(g,e,I){if(!e.has(g))throw new TypeError("attempted to "+I+" private field on non-instance");return e.get(g)}function aig(g,e){var I=f2e(g,e,"get");return Aig(g,I)}function sig(g,e){if(e.has(g))throw new TypeError("Cannot initialize the same private elements twice on an object")}function lig(g,e,I){sig(g,e),e.set(g,I)}function cig(g,e,I){if(e.set)e.set.call(g,I);else{if(!e.writable)throw new TypeError("attempted to set read only private field");e.value=I}}function oce(g,e,I){var i=f2e(g,e,"set");return cig(g,i,I),I}let Sp="default",aL="",QW=new WeakMap;function Ace(g){if(P$()){if(Sp==="default"){const e=pc(g);aL=e.documentElement.style.webkitUserSelect,e.documentElement.style.webkitUserSelect="none"}Sp="disabled"}else(g instanceof HTMLElement||g instanceof SVGElement)&&(QW.set(g,g.style.userSelect),g.style.userSelect="none")}function h1(g){if(P$()){if(Sp!=="disabled")return;Sp="restoring",setTimeout(()=>{c2e(()=>{if(Sp==="restoring"){const e=pc(g);e.documentElement.style.webkitUserSelect==="none"&&(e.documentElement.style.webkitUserSelect=aL||""),aL="",Sp="default"}})},300)}else if((g instanceof HTMLElement||g instanceof SVGElement)&&g&&QW.has(g)){let e=QW.get(g);g.style.userSelect==="none"&&e&&(g.style.userSelect=e),g.getAttribute("style")===""&&g.removeAttribute("style"),QW.delete(g)}}const p2e=N.createContext({register:()=>{}});p2e.displayName="PressResponderContext";function uig(g){let e=Ie.useContext(p2e);if(e){let{register:I,...i}=e;g=bi(i,g),I()}return h2e(e,g.ref),g}var m1=new WeakMap;class f1{continuePropagation(){oce(this,m1,!1)}get shouldStopPropagation(){return aig(this,m1)}constructor(e,I,i){lig(this,m1,{writable:!0,value:void 0}),oce(this,m1,!0),this.type=e,this.pointerType=I,this.target=i.currentTarget,this.shiftKey=i.shiftKey,this.metaKey=i.metaKey,this.ctrlKey=i.ctrlKey,this.altKey=i.altKey}}const ace=Symbol("linkClicked");function J$(g){let{onPress:e,onPressChange:I,onPressStart:i,onPressEnd:n,onPressUp:C,isDisabled:r,isPressed:o,preventFocusOnPress:A,shouldCancelOnPointerExit:s,allowTextSelectionOnPress:a,ref:l,...c}=uig(g),[u,d]=Ie.useState(!1),h=Ie.useRef({isPressed:!1,ignoreEmulatedMouseEvents:!1,ignoreClickAfterPress:!1,didFirePressStart:!1,isTriggeringEvent:!1,activePointerId:null,target:null,isOverTarget:!1,pointerType:null}),{addGlobalListener:m,removeAllGlobalListeners:f}=u2e(),b=or((B,w)=>{let R=h.current;if(r||R.didFirePressStart)return!1;let S=!0;if(R.isTriggeringEvent=!0,i){let X=new f1("pressstart",w,B);i(X),S=X.shouldStopPropagation}return I&&I(!0),R.isTriggeringEvent=!1,R.didFirePressStart=!0,d(!0),S}),p=or((B,w,R=!0)=>{let S=h.current;if(!S.didFirePressStart)return!1;S.ignoreClickAfterPress=!0,S.didFirePressStart=!1,S.isTriggeringEvent=!0;let X=!0;if(n){let W=new f1("pressend",w,B);n(W),X=W.shouldStopPropagation}if(I&&I(!1),d(!1),e&&R&&!r){let W=new f1("press",w,B);e(W),X&&(X=W.shouldStopPropagation)}return S.isTriggeringEvent=!1,X}),y=or((B,w)=>{let R=h.current;if(r)return!1;if(C){R.isTriggeringEvent=!0;let S=new f1("pressup",w,B);return C(S),R.isTriggeringEvent=!1,S.shouldStopPropagation}return!0}),Z=or(B=>{let w=h.current;w.isPressed&&w.target&&(w.isOverTarget&&w.pointerType!=null&&p($a(w.target,B),w.pointerType,!1),w.isPressed=!1,w.isOverTarget=!1,w.activePointerId=null,w.pointerType=null,f(),a||h1(w.target))}),v=or(B=>{s&&Z(B)}),G=Ie.useMemo(()=>{let B=h.current,w={onKeyDown(S){if(JF(S.nativeEvent,S.currentTarget)&&S.currentTarget.contains(S.target)){var X;lce(S.target,S.key)&&S.preventDefault();let W=!0;!B.isPressed&&!S.repeat&&(B.target=S.currentTarget,B.isPressed=!0,W=b(S,"keyboard"),m(pc(S.currentTarget),"keyup",R,!1)),W&&S.stopPropagation(),S.metaKey&&Oh()&&((X=B.metaKeyEvents)===null||X===void 0||X.set(S.key,S.nativeEvent))}else S.key==="Meta"&&(B.metaKeyEvents=new Map)},onKeyUp(S){JF(S.nativeEvent,S.currentTarget)&&!S.repeat&&S.currentTarget.contains(S.target)&&B.target&&y($a(B.target,S),"keyboard")},onClick(S){if(!(S&&!S.currentTarget.contains(S.target))&&S&&S.button===0&&!B.isTriggeringEvent&&!Lh.isOpening){let X=!0;if(r&&S.preventDefault(),!B.ignoreClickAfterPress&&!B.ignoreEmulatedMouseEvents&&!B.isPressed&&(B.pointerType==="virtual"||AL(S.nativeEvent))){!r&&!A&&Rs(S.currentTarget);let W=b(S,"virtual"),V=y(S,"virtual"),H=p(S,"virtual");X=W&&V&&H}B.ignoreEmulatedMouseEvents=!1,B.ignoreClickAfterPress=!1,X&&S.stopPropagation()}}},R=S=>{var X;if(B.isPressed&&B.target&&JF(S,B.target)){var W;lce(S.target,S.key)&&S.preventDefault();let H=S.target,D=p($a(B.target,S),"keyboard",B.target.contains(H));f(),D&&S.stopPropagation(),S.key!=="Enter"&&O$(B.target)&&B.target.contains(H)&&!S[ace]&&(S[ace]=!0,Lh(B.target,S,!1)),B.isPressed=!1,(W=B.metaKeyEvents)===null||W===void 0||W.delete(S.key)}else if(S.key==="Meta"&&(!((X=B.metaKeyEvents)===null||X===void 0)&&X.size)){var V;let H=B.metaKeyEvents;B.metaKeyEvents=void 0;for(let D of H.values())(V=B.target)===null||V===void 0||V.dispatchEvent(new KeyboardEvent("keyup",D))}};if(typeof PointerEvent<"u"){w.onPointerDown=V=>{if(V.button!==0||!V.currentTarget.contains(V.target))return;if(rig(V.nativeEvent)){B.pointerType="virtual";return}OF(V.currentTarget)&&V.preventDefault(),B.pointerType=V.pointerType;let H=!0;B.isPressed||(B.isPressed=!0,B.isOverTarget=!0,B.activePointerId=V.pointerId,B.target=V.currentTarget,!r&&!A&&Rs(V.currentTarget),a||Ace(B.target),H=b(V,B.pointerType),m(pc(V.currentTarget),"pointermove",S,!1),m(pc(V.currentTarget),"pointerup",X,!1),m(pc(V.currentTarget),"pointercancel",W,!1)),H&&V.stopPropagation()},w.onMouseDown=V=>{V.currentTarget.contains(V.target)&&V.button===0&&(OF(V.currentTarget)&&V.preventDefault(),V.stopPropagation())},w.onPointerUp=V=>{!V.currentTarget.contains(V.target)||B.pointerType==="virtual"||V.button===0&&hf(V,V.currentTarget)&&y(V,B.pointerType||V.pointerType)};let S=V=>{V.pointerId===B.activePointerId&&(B.target&&hf(V,B.target)?!B.isOverTarget&&B.pointerType!=null&&(B.isOverTarget=!0,b($a(B.target,V),B.pointerType)):B.target&&B.isOverTarget&&B.pointerType!=null&&(B.isOverTarget=!1,p($a(B.target,V),B.pointerType,!1),v(V)))},X=V=>{V.pointerId===B.activePointerId&&B.isPressed&&V.button===0&&B.target&&(hf(V,B.target)&&B.pointerType!=null?p($a(B.target,V),B.pointerType):B.isOverTarget&&B.pointerType!=null&&p($a(B.target,V),B.pointerType,!1),B.isPressed=!1,B.isOverTarget=!1,B.activePointerId=null,B.pointerType=null,f(),a||h1(B.target))},W=V=>{Z(V)};w.onDragStart=V=>{V.currentTarget.contains(V.target)&&Z(V)}}else{w.onMouseDown=W=>{if(W.button!==0||!W.currentTarget.contains(W.target))return;if(OF(W.currentTarget)&&W.preventDefault(),B.ignoreEmulatedMouseEvents){W.stopPropagation();return}B.isPressed=!0,B.isOverTarget=!0,B.target=W.currentTarget,B.pointerType=AL(W.nativeEvent)?"virtual":"mouse",!r&&!A&&Rs(W.currentTarget),b(W,B.pointerType)&&W.stopPropagation(),m(pc(W.currentTarget),"mouseup",S,!1)},w.onMouseEnter=W=>{if(!W.currentTarget.contains(W.target))return;let V=!0;B.isPressed&&!B.ignoreEmulatedMouseEvents&&B.pointerType!=null&&(B.isOverTarget=!0,V=b(W,B.pointerType)),V&&W.stopPropagation()},w.onMouseLeave=W=>{if(!W.currentTarget.contains(W.target))return;let V=!0;B.isPressed&&!B.ignoreEmulatedMouseEvents&&B.pointerType!=null&&(B.isOverTarget=!1,V=p(W,B.pointerType,!1),v(W)),V&&W.stopPropagation()},w.onMouseUp=W=>{W.currentTarget.contains(W.target)&&!B.ignoreEmulatedMouseEvents&&W.button===0&&y(W,B.pointerType||"mouse")};let S=W=>{if(W.button===0){if(B.isPressed=!1,f(),B.ignoreEmulatedMouseEvents){B.ignoreEmulatedMouseEvents=!1;return}B.target&&hf(W,B.target)&&B.pointerType!=null?p($a(B.target,W),B.pointerType):B.target&&B.isOverTarget&&B.pointerType!=null&&p($a(B.target,W),B.pointerType,!1),B.isOverTarget=!1}};w.onTouchStart=W=>{if(!W.currentTarget.contains(W.target))return;let V=dig(W.nativeEvent);if(!V)return;B.activePointerId=V.identifier,B.ignoreEmulatedMouseEvents=!0,B.isOverTarget=!0,B.isPressed=!0,B.target=W.currentTarget,B.pointerType="touch",!r&&!A&&Rs(W.currentTarget),a||Ace(B.target),b(W,B.pointerType)&&W.stopPropagation(),m(IT(W.currentTarget),"scroll",X,!0)},w.onTouchMove=W=>{if(!W.currentTarget.contains(W.target))return;if(!B.isPressed){W.stopPropagation();return}let V=sce(W.nativeEvent,B.activePointerId),H=!0;V&&hf(V,W.currentTarget)?!B.isOverTarget&&B.pointerType!=null&&(B.isOverTarget=!0,H=b(W,B.pointerType)):B.isOverTarget&&B.pointerType!=null&&(B.isOverTarget=!1,H=p(W,B.pointerType,!1),v(W)),H&&W.stopPropagation()},w.onTouchEnd=W=>{if(!W.currentTarget.contains(W.target))return;if(!B.isPressed){W.stopPropagation();return}let V=sce(W.nativeEvent,B.activePointerId),H=!0;V&&hf(V,W.currentTarget)&&B.pointerType!=null?(y(W,B.pointerType),H=p(W,B.pointerType)):B.isOverTarget&&B.pointerType!=null&&(H=p(W,B.pointerType,!1)),H&&W.stopPropagation(),B.isPressed=!1,B.activePointerId=null,B.isOverTarget=!1,B.ignoreEmulatedMouseEvents=!0,B.target&&!a&&h1(B.target),f()},w.onTouchCancel=W=>{W.currentTarget.contains(W.target)&&(W.stopPropagation(),B.isPressed&&Z(W))};let X=W=>{B.isPressed&&W.target.contains(B.target)&&Z({currentTarget:B.target,shiftKey:!1,ctrlKey:!1,metaKey:!1,altKey:!1})};w.onDragStart=W=>{W.currentTarget.contains(W.target)&&Z(W)}}return w},[m,r,A,f,a,Z,v,p,b,y]);return Ie.useEffect(()=>()=>{var B;a||h1((B=h.current.target)!==null&&B!==void 0?B:void 0)},[a]),{isPressed:o||u,pressProps:bi(c,G)}}function O$(g){return g.tagName==="A"&&g.hasAttribute("href")}function JF(g,e){const{key:I,code:i}=g,n=e,C=n.getAttribute("role");return(I==="Enter"||I===" "||I==="Spacebar"||i==="Space")&&!(n instanceof IT(n).HTMLInputElement&&!b2e(n,I)||n instanceof IT(n).HTMLTextAreaElement||n.isContentEditable)&&!((C==="link"||!C&&O$(n))&&I!=="Enter")}function dig(g){const{targetTouches:e}=g;return e.length>0?e[0]:null}function sce(g,e){const I=g.changedTouches;for(let i=0;ie.right||e.left>g.right||g.top>e.bottom||e.top>g.bottom)}function hf(g,e){let I=e.getBoundingClientRect(),i=hig(g);return mig(I,i)}function OF(g){return!(g instanceof HTMLElement)||!g.hasAttribute("draggable")}function lce(g,e){return g instanceof HTMLInputElement?!b2e(g,e):g instanceof HTMLButtonElement?g.type!=="submit"&&g.type!=="reset":!O$(g)}const fig=new Set(["checkbox","radio","range","color","file","image","button","submit","reset"]);function b2e(g,e){return g.type==="checkbox"||g.type==="radio"?e===" ":fig.has(g.type)}class pig{isDefaultPrevented(){return this.nativeEvent.defaultPrevented}preventDefault(){this.defaultPrevented=!0,this.nativeEvent.preventDefault()}stopPropagation(){this.nativeEvent.stopPropagation(),this.isPropagationStopped=()=>!0}isPropagationStopped(){return!1}persist(){}constructor(e,I){this.nativeEvent=I,this.target=I.target,this.currentTarget=I.currentTarget,this.relatedTarget=I.relatedTarget,this.bubbles=I.bubbles,this.cancelable=I.cancelable,this.defaultPrevented=I.defaultPrevented,this.eventPhase=I.eventPhase,this.isTrusted=I.isTrusted,this.timeStamp=I.timeStamp,this.type=e}}function y2e(g){let e=Ie.useRef({isFocused:!1,observer:null});mi(()=>{const i=e.current;return()=>{i.observer&&(i.observer.disconnect(),i.observer=null)}},[]);let I=or(i=>{g==null||g(i)});return Ie.useCallback(i=>{if(i.target instanceof HTMLButtonElement||i.target instanceof HTMLInputElement||i.target instanceof HTMLTextAreaElement||i.target instanceof HTMLSelectElement){e.current.isFocused=!0;let n=i.target,C=r=>{e.current.isFocused=!1,n.disabled&&I(new pig("blur",r)),e.current.observer&&(e.current.observer.disconnect(),e.current.observer=null)};n.addEventListener("focusout",C,{once:!0}),e.current.observer=new MutationObserver(()=>{if(e.current.isFocused&&n.disabled){var r;(r=e.current.observer)===null||r===void 0||r.disconnect();let o=n===document.activeElement?null:document.activeElement;n.dispatchEvent(new FocusEvent("blur",{relatedTarget:o})),n.dispatchEvent(new FocusEvent("focusout",{bubbles:!0,relatedTarget:o}))}}),e.current.observer.observe(n,{attributes:!0,attributeFilter:["disabled"]})}},[I])}function Z2e(g){let{isDisabled:e,onFocus:I,onBlur:i,onFocusChange:n}=g;const C=Ie.useCallback(A=>{if(A.target===A.currentTarget)return i&&i(A),n&&n(!1),!0},[i,n]),r=y2e(C),o=Ie.useCallback(A=>{A.target===A.currentTarget&&document.activeElement===A.target&&(I&&I(A),n&&n(!0),r(A))},[n,I,r]);return{focusProps:{onFocus:!e&&(I||n||i)?o:void 0,onBlur:!e&&(i||n)?C:void 0}}}let tl=null,mS=new Set,cce=!1,_h=!1,sL=!1;const big={Tab:!0,Escape:!0};function BY(g,e){for(let I of mS)I(g,e)}function yig(g){return!(g.metaKey||!Oh()&&g.altKey||g.ctrlKey||g.key==="Control"||g.key==="Shift"||g.key==="Meta")}function uce(g){_h=!0,yig(g)&&(tl="keyboard",BY("keyboard",g))}function mf(g){tl="pointer",(g.type==="mousedown"||g.type==="pointerdown")&&(_h=!0,BY("pointer",g))}function Zig(g){AL(g)&&(_h=!0,tl="virtual")}function Gig(g){g.target===window||g.target===document||(!_h&&!sL&&(tl="virtual",BY("virtual",g)),_h=!1,sL=!1)}function Big(){_h=!1,sL=!0}function CT(){if(typeof window>"u"||cce)return;let g=HTMLElement.prototype.focus;HTMLElement.prototype.focus=function(){_h=!0,g.apply(this,arguments)},document.addEventListener("keydown",uce,!0),document.addEventListener("keyup",uce,!0),document.addEventListener("click",Zig,!0),window.addEventListener("focus",Gig,!0),window.addEventListener("blur",Big,!1),typeof PointerEvent<"u"?(document.addEventListener("pointerdown",mf,!0),document.addEventListener("pointermove",mf,!0),document.addEventListener("pointerup",mf,!0)):(document.addEventListener("mousedown",mf,!0),document.addEventListener("mousemove",mf,!0),document.addEventListener("mouseup",mf,!0)),cce=!0}typeof document<"u"&&(document.readyState!=="loading"?CT():document.addEventListener("DOMContentLoaded",CT));function L$(){return tl!=="pointer"}function lL(){return tl}function vig(g){tl=g,BY(g,null)}function Sig(){CT();let[g,e]=Ie.useState(tl);return Ie.useEffect(()=>{let I=()=>{e(tl)};return mS.add(I),()=>{mS.delete(I)}},[]),Qw()?null:g}const wig=new Set(["checkbox","radio","range","color","file","image","button","submit","reset"]);function Vig(g,e,I){var i;return g=g||(I==null?void 0:I.target)instanceof HTMLInputElement&&!wig.has(I==null||(i=I.target)===null||i===void 0?void 0:i.type)||(I==null?void 0:I.target)instanceof HTMLTextAreaElement||(I==null?void 0:I.target)instanceof HTMLElement&&(I==null?void 0:I.target.isContentEditable),!(g&&e==="keyboard"&&I instanceof KeyboardEvent&&!big[I.key])}function Rig(g,e,I){CT(),Ie.useEffect(()=>{let i=(n,C)=>{Vig(!!(I!=null&&I.isTextInput),n,C)&&g(L$())};return mS.add(i),()=>{mS.delete(i)}},e)}function G2e(g){let{isDisabled:e,onBlurWithin:I,onFocusWithin:i,onFocusWithinChange:n}=g,C=Ie.useRef({isFocusWithin:!1}),r=Ie.useCallback(s=>{C.current.isFocusWithin&&!s.currentTarget.contains(s.relatedTarget)&&(C.current.isFocusWithin=!1,I&&I(s),n&&n(!1))},[I,n,C]),o=y2e(r),A=Ie.useCallback(s=>{!C.current.isFocusWithin&&document.activeElement===s.target&&(i&&i(s),n&&n(!0),C.current.isFocusWithin=!0,o(s))},[i,n,o]);return e?{focusWithinProps:{onFocus:void 0,onBlur:void 0}}:{focusWithinProps:{onFocus:A,onBlur:r}}}let rT=!1,LF=0;function cL(){rT=!0,setTimeout(()=>{rT=!1},50)}function dce(g){g.pointerType==="touch"&&cL()}function Wig(){if(!(typeof document>"u"))return typeof PointerEvent<"u"?document.addEventListener("pointerup",dce):document.addEventListener("touchend",cL),LF++,()=>{LF--,!(LF>0)&&(typeof PointerEvent<"u"?document.removeEventListener("pointerup",dce):document.removeEventListener("touchend",cL))}}function _$(g){let{onHoverStart:e,onHoverChange:I,onHoverEnd:i,isDisabled:n}=g,[C,r]=Ie.useState(!1),o=Ie.useRef({isHovered:!1,ignoreEmulatedMouseEvents:!1,pointerType:"",target:null}).current;Ie.useEffect(Wig,[]);let{hoverProps:A,triggerHoverEnd:s}=Ie.useMemo(()=>{let a=(u,d)=>{if(o.pointerType=d,n||d==="touch"||o.isHovered||!u.currentTarget.contains(u.target))return;o.isHovered=!0;let h=u.currentTarget;o.target=h,e&&e({type:"hoverstart",target:h,pointerType:d}),I&&I(!0),r(!0)},l=(u,d)=>{if(o.pointerType="",o.target=null,d==="touch"||!o.isHovered)return;o.isHovered=!1;let h=u.currentTarget;i&&i({type:"hoverend",target:h,pointerType:d}),I&&I(!1),r(!1)},c={};return typeof PointerEvent<"u"?(c.onPointerEnter=u=>{rT&&u.pointerType==="mouse"||a(u,u.pointerType)},c.onPointerLeave=u=>{!n&&u.currentTarget.contains(u.target)&&l(u,u.pointerType)}):(c.onTouchStart=()=>{o.ignoreEmulatedMouseEvents=!0},c.onMouseEnter=u=>{!o.ignoreEmulatedMouseEvents&&!rT&&a(u,"mouse"),o.ignoreEmulatedMouseEvents=!1},c.onMouseLeave=u=>{!n&&u.currentTarget.contains(u.target)&&l(u,"mouse")}),{hoverProps:c,triggerHoverEnd:l}},[e,I,i,n,o]);return Ie.useEffect(()=>{n&&s({currentTarget:o.target},o.pointerType)},[n]),{hoverProps:A,isHovered:C}}function hce(g){if(!g)return;let e=!0;return I=>{let i={...I,preventDefault(){I.preventDefault()},isDefaultPrevented(){return I.isDefaultPrevented()},stopPropagation(){console.error("stopPropagation is now the default behavior for events in React Spectrum. You can use continuePropagation() to revert this behavior.")},continuePropagation(){e=!1}};g(i),e&&I.stopPropagation()}}function Xig(g){return{keyboardProps:g.isDisabled?{}:{onKeyDown:hce(g.onKeyDown),onKeyUp:hce(g.onKeyUp)}}}const Hig=500;function Tig(g){let{isDisabled:e,onLongPressStart:I,onLongPressEnd:i,onLongPress:n,threshold:C=Hig,accessibilityDescription:r}=g;const o=Ie.useRef();let{addGlobalListener:A,removeGlobalListener:s}=u2e(),{pressProps:a}=J$({isDisabled:e,onPressStart(c){if(c.continuePropagation(),(c.pointerType==="mouse"||c.pointerType==="touch")&&(I&&I({...c,type:"longpressstart"}),o.current=setTimeout(()=>{c.target.dispatchEvent(new PointerEvent("pointercancel",{bubbles:!0})),n&&n({...c,type:"longpress"}),o.current=void 0},C),c.pointerType==="touch")){let u=d=>{d.preventDefault()};A(c.target,"contextmenu",u,{once:!0}),A(window,"pointerup",()=>{setTimeout(()=>{s(c.target,"contextmenu",u)},30)},{once:!0})}},onPressEnd(c){o.current&&clearTimeout(o.current),i&&(c.pointerType==="mouse"||c.pointerType==="touch")&&i({...c,type:"longpressend"})}}),l=GY(n&&!e?r:void 0);return{longPressProps:bi(a,l)}}function tr(g){if(lL()==="virtual"){let e=document.activeElement;c2e(()=>{document.activeElement===e&&document.contains(g)&&Rs(g)})}else Rs(g)}function Nig(g){if(!(g instanceof HTMLElement)&&!(g instanceof SVGElement))return!1;let{display:e,visibility:I}=g.style,i=e!=="none"&&I!=="hidden"&&I!=="collapse";if(i){const{getComputedStyle:n}=g.ownerDocument.defaultView;let{display:C,visibility:r}=n(g);i=C!=="none"&&r!=="hidden"&&r!=="collapse"}return i}function kig(g,e){return!g.hasAttribute("hidden")&&(g.nodeName==="DETAILS"&&e&&e.nodeName!=="SUMMARY"?g.hasAttribute("open"):!0)}function B2e(g,e){return g.nodeName!=="#comment"&&Nig(g)&&kig(g,e)&&(!g.parentElement||B2e(g.parentElement,g))}const mce=N.createContext(null);let pI=null;function Yig(g){let{children:e,contain:I,restoreFocus:i,autoFocus:n}=g,C=Ie.useRef(null),r=Ie.useRef(null),o=Ie.useRef([]),{parentNode:A}=Ie.useContext(mce)||{},s=Ie.useMemo(()=>new dL({scopeRef:o}),[o]);mi(()=>{let c=A||li.root;if(li.getTreeNode(c.scopeRef)&&pI&&!oT(pI,c.scopeRef)){let u=li.getTreeNode(pI);u&&(c=u)}c.addChild(s),li.addNode(s)},[s,A]),mi(()=>{let c=li.getTreeNode(o);c&&(c.contain=!!I)},[I]),mi(()=>{var c;let u=(c=C.current)===null||c===void 0?void 0:c.nextSibling,d=[];for(;u&&u!==r.current;)d.push(u),u=u.nextSibling;o.current=d},[e]),Mig(o,i,I),Fig(o,I),Pig(o,i,I),Eig(o,n),Ie.useEffect(()=>{let c=document.activeElement,u=null;if(Xn(c,o.current)){for(let d of li.traverse())d.scopeRef&&Xn(c,d.scopeRef.current)&&(u=d);u===li.getTreeNode(o)&&(pI=u.scopeRef)}},[o]),mi(()=>()=>{var c,u,d;let h=(d=(u=li.getTreeNode(o))===null||u===void 0||(c=u.parent)===null||c===void 0?void 0:c.scopeRef)!==null&&d!==void 0?d:null;(o===pI||oT(o,pI))&&(!h||li.getTreeNode(h))&&(pI=h),li.removeTreeNode(o)},[o]);let a=Ie.useMemo(()=>Kig(o),[]),l=Ie.useMemo(()=>({focusManager:a,parentNode:s}),[s,a]);return N.createElement(mce.Provider,{value:l},N.createElement("span",{"data-focus-scope-start":!0,hidden:!0,ref:C}),e,N.createElement("span",{"data-focus-scope-end":!0,hidden:!0,ref:r}))}function Kig(g){return{focusNext(e={}){let I=g.current,{from:i,tabbable:n,wrap:C,accept:r}=e,o=i||document.activeElement,A=I[0].previousElementSibling,s=Sd(I),a=eo(s,{tabbable:n,accept:r},I);a.currentNode=Xn(o,I)?o:A;let l=a.nextNode();return!l&&C&&(a.currentNode=A,l=a.nextNode()),l&&Ws(l,!0),l},focusPrevious(e={}){let I=g.current,{from:i,tabbable:n,wrap:C,accept:r}=e,o=i||document.activeElement,A=I[I.length-1].nextElementSibling,s=Sd(I),a=eo(s,{tabbable:n,accept:r},I);a.currentNode=Xn(o,I)?o:A;let l=a.previousNode();return!l&&C&&(a.currentNode=A,l=a.previousNode()),l&&Ws(l,!0),l},focusFirst(e={}){let I=g.current,{tabbable:i,accept:n}=e,C=Sd(I),r=eo(C,{tabbable:i,accept:n},I);r.currentNode=I[0].previousElementSibling;let o=r.nextNode();return o&&Ws(o,!0),o},focusLast(e={}){let I=g.current,{tabbable:i,accept:n}=e,C=Sd(I),r=eo(C,{tabbable:i,accept:n},I);r.currentNode=I[I.length-1].nextElementSibling;let o=r.previousNode();return o&&Ws(o,!0),o}}}const U$=["input:not([disabled]):not([type=hidden])","select:not([disabled])","textarea:not([disabled])","button:not([disabled])","a[href]","area[href]","summary","iframe","object","embed","audio[controls]","video[controls]","[contenteditable]"],xig=U$.join(":not([hidden]),")+",[tabindex]:not([disabled]):not([hidden])";U$.push('[tabindex]:not([tabindex="-1"]):not([disabled])');const Dig=U$.join(':not([hidden]):not([tabindex="-1"]),');function Sd(g){return g[0].parentElement}function RG(g){let e=li.getTreeNode(pI);for(;e&&e.scopeRef!==g;){if(e.contain)return!1;e=e.parent}return!0}function Fig(g,e){let I=Ie.useRef(),i=Ie.useRef();mi(()=>{let n=g.current;if(!e){i.current&&(cancelAnimationFrame(i.current),i.current=void 0);return}let C=A=>{if(A.key!=="Tab"||A.altKey||A.ctrlKey||A.metaKey||!RG(g))return;let s=document.activeElement,a=g.current;if(!a||!Xn(s,a))return;let l=Sd(a),c=eo(l,{tabbable:!0},a);if(!s)return;c.currentNode=s;let u=A.shiftKey?c.previousNode():c.nextNode();u||(c.currentNode=A.shiftKey?a[a.length-1].nextElementSibling:a[0].previousElementSibling,u=A.shiftKey?c.previousNode():c.nextNode()),A.preventDefault(),u&&Ws(u,!0)},r=A=>{(!pI||oT(pI,g))&&Xn(A.target,g.current)?(pI=g,I.current=A.target):RG(g)&&!uL(A.target,g)?I.current?I.current.focus():pI&&pI.current&&AT(pI.current):RG(g)&&(I.current=A.target)},o=A=>{i.current&&cancelAnimationFrame(i.current),i.current=requestAnimationFrame(()=>{if(document.activeElement&&RG(g)&&!uL(document.activeElement,g))if(pI=g,document.body.contains(A.target)){var s;I.current=A.target,(s=I.current)===null||s===void 0||s.focus()}else pI.current&&AT(pI.current)})};return document.addEventListener("keydown",C,!1),document.addEventListener("focusin",r,!1),n==null||n.forEach(A=>A.addEventListener("focusin",r,!1)),n==null||n.forEach(A=>A.addEventListener("focusout",o,!1)),()=>{document.removeEventListener("keydown",C,!1),document.removeEventListener("focusin",r,!1),n==null||n.forEach(A=>A.removeEventListener("focusin",r,!1)),n==null||n.forEach(A=>A.removeEventListener("focusout",o,!1))}},[g,e]),mi(()=>()=>{i.current&&cancelAnimationFrame(i.current)},[i])}function v2e(g){return uL(g)}function Xn(g,e){return!g||!e?!1:e.some(I=>I.contains(g))}function uL(g,e=null){if(g instanceof Element&&g.closest("[data-react-aria-top-layer]"))return!0;for(let{scopeRef:I}of li.traverse(li.getTreeNode(e)))if(I&&Xn(g,I.current))return!0;return!1}function oT(g,e){var I;let i=(I=li.getTreeNode(e))===null||I===void 0?void 0:I.parent;for(;i;){if(i.scopeRef===g)return!0;i=i.parent}return!1}function Ws(g,e=!1){if(g!=null&&!e)try{tr(g)}catch{}else if(g!=null)try{g.focus()}catch{}}function AT(g,e=!0){let I=g[0].previousElementSibling,i=Sd(g),n=eo(i,{tabbable:e},g);n.currentNode=I;let C=n.nextNode();e&&!C&&(i=Sd(g),n=eo(i,{tabbable:!1},g),n.currentNode=I,C=n.nextNode()),Ws(C)}function Eig(g,e){const I=N.useRef(e);Ie.useEffect(()=>{I.current&&(pI=g,!Xn(document.activeElement,pI.current)&&g.current&&AT(g.current)),I.current=!1},[g])}function Mig(g,e,I){mi(()=>{if(e||I)return;let i=g.current,n=C=>{let r=C.target;Xn(r,g.current)?pI=g:v2e(r)||(pI=null)};return document.addEventListener("focusin",n,!1),i==null||i.forEach(C=>C.addEventListener("focusin",n,!1)),()=>{document.removeEventListener("focusin",n,!1),i==null||i.forEach(C=>C.removeEventListener("focusin",n,!1))}},[g,e,I])}function zig(g){let e=li.getTreeNode(pI);for(;e&&e.scopeRef!==g;){if(e.nodeToRestore)return!1;e=e.parent}return(e==null?void 0:e.scopeRef)===g}function Pig(g,e,I){const i=Ie.useRef(typeof document<"u"?document.activeElement:null);mi(()=>{let n=g.current;if(!e||I)return;let C=()=>{(!pI||oT(pI,g))&&Xn(document.activeElement,g.current)&&(pI=g)};return document.addEventListener("focusin",C,!1),n==null||n.forEach(r=>r.addEventListener("focusin",C,!1)),()=>{document.removeEventListener("focusin",C,!1),n==null||n.forEach(r=>r.removeEventListener("focusin",C,!1))}},[g,I]),mi(()=>{if(!e)return;let n=C=>{if(C.key!=="Tab"||C.altKey||C.ctrlKey||C.metaKey||!RG(g))return;let r=document.activeElement;if(!Xn(r,g.current))return;let o=li.getTreeNode(g);if(!o)return;let A=o.nodeToRestore,s=eo(document.body,{tabbable:!0});s.currentNode=r;let a=C.shiftKey?s.previousNode():s.nextNode();if((!A||!document.body.contains(A)||A===document.body)&&(A=void 0,o.nodeToRestore=void 0),(!a||!Xn(a,g.current))&&A){s.currentNode=A;do a=C.shiftKey?s.previousNode():s.nextNode();while(Xn(a,g.current));C.preventDefault(),C.stopPropagation(),a?Ws(a,!0):v2e(A)?Ws(A,!0):r.blur()}};return I||document.addEventListener("keydown",n,!0),()=>{I||document.removeEventListener("keydown",n,!0)}},[g,e,I]),mi(()=>{if(!e)return;let n=li.getTreeNode(g);if(n){var C;return n.nodeToRestore=(C=i.current)!==null&&C!==void 0?C:void 0,()=>{let r=li.getTreeNode(g);if(!r)return;let o=r.nodeToRestore;if(e&&o&&(Xn(document.activeElement,g.current)||document.activeElement===document.body&&zig(g))){let A=li.clone();requestAnimationFrame(()=>{if(document.activeElement===document.body){let s=A.getTreeNode(g);for(;s;){if(s.nodeToRestore&&document.body.contains(s.nodeToRestore)){Ws(s.nodeToRestore);return}s=s.parent}for(s=A.getTreeNode(g);s;){if(s.scopeRef&&s.scopeRef.current&&li.getTreeNode(s.scopeRef)){AT(s.scopeRef.current,!0);return}s=s.parent}}})}}}},[g,e])}function eo(g,e,I){let i=e!=null&&e.tabbable?Dig:xig,n=document.createTreeWalker(g,NodeFilter.SHOW_ELEMENT,{acceptNode(C){var r;return!(e==null||(r=e.from)===null||r===void 0)&&r.contains(C)?NodeFilter.FILTER_REJECT:C.matches(i)&&B2e(C)&&(!I||Xn(C,I))&&(!(e!=null&&e.accept)||e.accept(C))?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});return e!=null&&e.from&&(n.currentNode=e.from),n}class Q${get size(){return this.fastMap.size}getTreeNode(e){return this.fastMap.get(e)}addTreeNode(e,I,i){let n=this.fastMap.get(I??null);if(!n)return;let C=new dL({scopeRef:e});n.addChild(C),C.parent=n,this.fastMap.set(e,C),i&&(C.nodeToRestore=i)}addNode(e){this.fastMap.set(e.scopeRef,e)}removeTreeNode(e){if(e===null)return;let I=this.fastMap.get(e);if(!I)return;let i=I.parent;for(let C of this.traverse())C!==I&&I.nodeToRestore&&C.nodeToRestore&&I.scopeRef&&I.scopeRef.current&&Xn(C.nodeToRestore,I.scopeRef.current)&&(C.nodeToRestore=I.nodeToRestore);let n=I.children;i&&(i.removeChild(I),n.size>0&&n.forEach(C=>i&&i.addChild(C))),this.fastMap.delete(I.scopeRef)}*traverse(e=this.root){if(e.scopeRef!=null&&(yield e),e.children.size>0)for(let I of e.children)yield*this.traverse(I)}clone(){var e;let I=new Q$;var i;for(let n of this.traverse())I.addTreeNode(n.scopeRef,(i=(e=n.parent)===null||e===void 0?void 0:e.scopeRef)!==null&&i!==void 0?i:null,n.nodeToRestore);return I}constructor(){this.fastMap=new Map,this.root=new dL({scopeRef:null}),this.fastMap.set(null,this.root)}}class dL{addChild(e){this.children.add(e),e.parent=this}removeChild(e){this.children.delete(e),e.parent=void 0}constructor(e){this.children=new Set,this.contain=!1,this.scopeRef=e.scopeRef}}let li=new Q$;function vY(g={}){let{autoFocus:e=!1,isTextInput:I,within:i}=g,n=Ie.useRef({isFocused:!1,isFocusVisible:e||L$()}),[C,r]=Ie.useState(!1),[o,A]=Ie.useState(()=>n.current.isFocused&&n.current.isFocusVisible),s=Ie.useCallback(()=>A(n.current.isFocused&&n.current.isFocusVisible),[]),a=Ie.useCallback(u=>{n.current.isFocused=u,r(u),s()},[s]);Rig(u=>{n.current.isFocusVisible=u,s()},[],{isTextInput:I});let{focusProps:l}=Z2e({isDisabled:i,onFocusChange:a}),{focusWithinProps:c}=G2e({isDisabled:!i,onFocusWithinChange:a});return{isFocused:C,isFocusVisible:o,focusProps:i?c:l}}let Jig=N.createContext(null);function Oig(g){let e=Ie.useContext(Jig)||{};h2e(e,g);let{ref:I,...i}=e;return i}function S2e(g,e){let{focusProps:I}=Z2e(g),{keyboardProps:i}=Xig(g),n=bi(I,i),C=Oig(e),r=g.isDisabled?{}:C,o=Ie.useRef(g.autoFocus);return Ie.useEffect(()=>{o.current&&e.current&&tr(e.current),o.current=!1},[e]),{focusableProps:bi({...n,tabIndex:g.excludeFromTabOrder&&!g.isDisabled?-1:void 0},r)}}function Lig(g,e){let I=e==null?void 0:e.isDisabled,[i,n]=Ie.useState(!1);return mi(()=>{if(g!=null&&g.current&&!I){let C=()=>{if(g.current){let o=eo(g.current,{tabbable:!0});n(!!o.nextNode())}};C();let r=new MutationObserver(C);return r.observe(g.current,{subtree:!0,childList:!0,attributes:!0,attributeFilter:["tabIndex","disabled"]}),()=>{r.disconnect()}}}),I?!1:i}class _ig{getStringForLocale(e,I){let i=this.strings[I];i||(i=Uig(I,this.strings,this.defaultLocale),this.strings[I]=i);let n=i[e];if(!n)throw new Error(`Could not find intl message ${e} in ${I} locale`);return n}constructor(e,I="en-US"){this.strings={...e},this.defaultLocale=I}}function Uig(g,e,I="en-US"){if(e[g])return e[g];let i=Qig(g);if(e[i])return e[i];for(let n in e)if(n.startsWith(i+"-"))return e[n];return e[I]}function Qig(g){return Intl.Locale?new Intl.Locale(g).language:g.split("-")[0]}const fce=new Map,pce=new Map;class jig{format(e,I){let i=this.strings.getStringForLocale(e,this.locale);return typeof i=="function"?i(I,this):i}plural(e,I,i="cardinal"){let n=I["="+e];if(n)return typeof n=="function"?n():n;let C=this.locale+":"+i,r=fce.get(C);r||(r=new Intl.PluralRules(this.locale,{type:i}),fce.set(C,r));let o=r.select(e);return n=I[o]||I.other,typeof n=="function"?n():n}number(e){let I=pce.get(this.locale);return I||(I=new Intl.NumberFormat(this.locale),pce.set(this.locale,I)),I.format(e)}select(e,I){let i=e[I]||e.other;return typeof i=="function"?i():i}constructor(e,I){this.locale=e,this.strings=I}}const $ig=new Set(["Arab","Syrc","Samr","Mand","Thaa","Mend","Nkoo","Adlm","Rohg","Hebr"]),qig=new Set(["ae","ar","arc","bcc","bqi","ckb","dv","fa","glk","he","ku","mzn","nqo","pnb","ps","sd","ug","ur","yi"]);function eng(g){if(Intl.Locale){let I=new Intl.Locale(g).maximize().script;return I?$ig.has(I):!1}let e=g.split("-")[0];return qig.has(e)}function w2e(){let g=typeof navigator<"u"&&(navigator.language||navigator.userLanguage)||"en-US";try{Intl.DateTimeFormat.supportedLocalesOf([g])}catch{g="en-US"}return{locale:g,direction:eng(g)?"rtl":"ltr"}}let hL=w2e(),WG=new Set;function bce(){hL=w2e();for(let g of WG)g(hL)}function tng(){let g=Qw(),[e,I]=Ie.useState(hL);return Ie.useEffect(()=>(WG.size===0&&window.addEventListener("languagechange",bce),WG.add(I),()=>{WG.delete(I),WG.size===0&&window.removeEventListener("languagechange",bce)}),[]),g?{locale:"en-US",direction:"ltr"}:e}const gng=N.createContext(null);function Xm(){let g=tng();return Ie.useContext(gng)||g}const yce=new WeakMap;function Ing(g){let e=yce.get(g);return e||(e=new _ig(g),yce.set(g,e)),e}function Gy(g){let{locale:e}=Xm(),I=Ie.useMemo(()=>Ing(g),[g]);return Ie.useMemo(()=>new jig(e,I),[e,I])}let _F=new Map;function V2e(g){let{locale:e}=Xm(),I=e+(g?Object.entries(g).sort((n,C)=>n[0]{n.remove()},i)}clear(e){this.node&&((!e||e==="assertive")&&(this.assertiveLog.innerHTML=""),(!e||e==="polite")&&(this.politeLog.innerHTML=""))}constructor(){this.node=document.createElement("div"),this.node.dataset.liveAnnouncer="true",Object.assign(this.node.style,{border:0,clip:"rect(0 0 0 0)",clipPath:"inset(50%)",height:"1px",margin:"-1px",overflow:"hidden",padding:0,position:"absolute",width:"1px",whiteSpace:"nowrap"}),this.assertiveLog=this.createLog("assertive"),this.node.appendChild(this.assertiveLog),this.politeLog=this.createLog("polite"),this.node.appendChild(this.politeLog),document.body.prepend(this.node)}}function nng(g,e,I){let{validationBehavior:i,focus:n}=g;mi(()=>{if(i==="native"&&(I!=null&&I.current)){let A=e.realtimeValidation.isInvalid?e.realtimeValidation.validationErrors.join(" ")||"Invalid value.":"";I.current.setCustomValidity(A),I.current.hasAttribute("title")||(I.current.title=""),e.realtimeValidation.isInvalid||e.updateValidation(rng(I.current))}});let C=or(()=>{e.resetValidation()}),r=or(A=>{var s;e.displayValidation.isInvalid||e.commitValidation();let a=I==null||(s=I.current)===null||s===void 0?void 0:s.form;if(!A.defaultPrevented&&I&&a&&ong(a)===I.current){var l;n?n():(l=I.current)===null||l===void 0||l.focus(),vig("keyboard")}A.preventDefault()}),o=or(()=>{e.commitValidation()});Ie.useEffect(()=>{let A=I==null?void 0:I.current;if(!A)return;let s=A.form;return A.addEventListener("invalid",r),A.addEventListener("change",o),s==null||s.addEventListener("reset",C),()=>{A.removeEventListener("invalid",r),A.removeEventListener("change",o),s==null||s.removeEventListener("reset",C)}},[I,r,o,C,i])}function Cng(g){let e=g.validity;return{badInput:e.badInput,customError:e.customError,patternMismatch:e.patternMismatch,rangeOverflow:e.rangeOverflow,rangeUnderflow:e.rangeUnderflow,stepMismatch:e.stepMismatch,tooLong:e.tooLong,tooShort:e.tooShort,typeMismatch:e.typeMismatch,valueMissing:e.valueMissing,valid:e.valid}}function rng(g){return{isInvalid:!g.validity.valid,validationDetails:Cng(g),validationErrors:g.validationMessage?[g.validationMessage]:[]}}function ong(g){for(let e=0;eGce(lng(r,n)),[r,n]);C!=null&&C.validationDetails.valid&&(C=null);let a=Ie.useContext(Ang),l=Ie.useMemo(()=>i?Array.isArray(i)?i.flatMap(R=>mL(a[R])):mL(a[i]):[],[a,i]),[c,u]=Ie.useState(a),[d,h]=Ie.useState(!1);a!==c&&(u(a),h(!1));let m=Ie.useMemo(()=>Gce(d?[]:l),[d,l]),f=Ie.useRef(wZ),[b,p]=Ie.useState(wZ),y=Ie.useRef(wZ),Z=()=>{if(!v)return;G(!1);let R=s||C||f.current;QF(R,y.current)||(y.current=R,p(R))},[v,G]=Ie.useState(!1);return Ie.useEffect(Z),{realtimeValidation:A||m||s||C||wZ,displayValidation:o==="native"?A||m||b:A||m||s||C||b,updateValidation(R){o==="aria"&&!QF(b,R)?p(R):f.current=R},resetValidation(){let R=wZ;QF(R,y.current)||(y.current=R,p(R)),o==="native"&&G(!1),h(!0)},commitValidation(){o==="native"&&G(!0),h(!0)}}}function mL(g){return g?Array.isArray(g)?g:[g]:[]}function lng(g,e){if(typeof g=="function"){let I=g(e);if(I&&typeof I!="boolean")return mL(I)}return[]}function Gce(g){return g.length?{isInvalid:!0,validationErrors:g,validationDetails:H2e}:null}function QF(g,e){return g===e?!0:g&&e&&g.isInvalid===e.isInvalid&&g.validationErrors.length===e.validationErrors.length&&g.validationErrors.every((I,i)=>I===e.validationErrors[i])&&Object.entries(g.validationDetails).every(([I,i])=>e.validationDetails[I]===i)}function cng(g){let{id:e,label:I,"aria-labelledby":i,"aria-label":n,labelElementType:C="label"}=g;e=Jh(e);let r=Jh(),o={};I?(i=i?`${r} ${i}`:r,o={id:r,htmlFor:C==="label"?e:void 0}):!i&&!n&&console.warn("If you do not provide a visible label, you must specify an aria-label or aria-labelledby attribute for accessibility");let A=iig({id:e,"aria-label":n,"aria-labelledby":i});return{labelProps:o,fieldProps:A}}function ung(g){let{description:e,errorMessage:I,isInvalid:i,validationState:n}=g,{labelProps:C,fieldProps:r}=cng(g),o=nce([!!e,!!I,i,n]),A=nce([!!e,!!I,i,n]);return r=bi(r,{"aria-describedby":[o,A,g["aria-describedby"]].filter(Boolean).join(" ")||void 0}),{labelProps:C,fieldProps:r,descriptionProps:{id:o},errorMessageProps:{id:A}}}const Bce={border:0,clip:"rect(0 0 0 0)",clipPath:"inset(50%)",height:"1px",margin:"-1px",overflow:"hidden",padding:0,position:"absolute",width:"1px",whiteSpace:"nowrap"};function j$(g={}){let{style:e,isFocusable:I}=g,[i,n]=Ie.useState(!1),{focusWithinProps:C}=G2e({isDisabled:!I,onFocusWithinChange:o=>n(o)}),r=Ie.useMemo(()=>i?e:e?{...Bce,...e}:Bce,[i]);return{visuallyHiddenProps:{...C,style:r}}}function fL(g){return QIg()?g.altKey:g.ctrlKey}function ep(g){return Oh()?g.metaKey:g.ctrlKey}const dng=1e3;function hng(g){let{keyboardDelegate:e,selectionManager:I,onTypeSelect:i}=g,n=Ie.useRef({search:"",timeout:null}).current,C=r=>{let o=mng(r.key);if(!o||r.ctrlKey||r.metaKey||!r.currentTarget.contains(r.target))return;o===" "&&n.search.trim().length>0&&(r.preventDefault(),"continuePropagation"in r||r.stopPropagation()),n.search+=o;let A=e.getKeyForSearch(n.search,I.focusedKey);A==null&&(A=e.getKeyForSearch(n.search)),A!=null&&(I.setFocusedKey(A),i&&i(A)),clearTimeout(n.timeout),n.timeout=setTimeout(()=>{n.search=""},dng)};return{typeSelectProps:{onKeyDownCapture:e.getKeyForSearch?C:null}}}function mng(g){return g.length===1||!/^[A-Z]/i.test(g)?g:""}function fng(g){let{selectionManager:e,keyboardDelegate:I,ref:i,autoFocus:n=!1,shouldFocusWrap:C=!1,disallowEmptySelection:r=!1,disallowSelectAll:o=!1,selectOnFocus:A=e.selectionBehavior==="replace",disallowTypeAhead:s=!1,shouldUseVirtualFocus:a,allowsTabNavigation:l=!1,isVirtualized:c,scrollRef:u=i,linkBehavior:d="action"}=g,{direction:h}=Xm(),m=l2e(),f=R=>{if(R.altKey&&R.key==="Tab"&&R.preventDefault(),!i.current.contains(R.target))return;const S=(J,te)=>{if(J!=null){if(e.isLink(J)&&d==="selection"&&A&&!fL(R)){Fs.flushSync(()=>{e.setFocusedKey(J,te)});let q=u.current.querySelector(`[data-key="${J}"]`);m.open(q,R);return}if(e.setFocusedKey(J,te),e.isLink(J)&&d==="override")return;R.shiftKey&&e.selectionMode==="multiple"?e.extendSelection(J):A&&!fL(R)&&e.replaceSelection(J)}};switch(R.key){case"ArrowDown":if(I.getKeyBelow){var X,W;R.preventDefault();let J=e.focusedKey!=null?I.getKeyBelow(e.focusedKey):(X=I.getFirstKey)===null||X===void 0?void 0:X.call(I);J==null&&C&&(J=(W=I.getFirstKey)===null||W===void 0?void 0:W.call(I,e.focusedKey)),S(J)}break;case"ArrowUp":if(I.getKeyAbove){var V,H;R.preventDefault();let J=e.focusedKey!=null?I.getKeyAbove(e.focusedKey):(V=I.getLastKey)===null||V===void 0?void 0:V.call(I);J==null&&C&&(J=(H=I.getLastKey)===null||H===void 0?void 0:H.call(I,e.focusedKey)),S(J)}break;case"ArrowLeft":if(I.getKeyLeftOf){var D,Y;R.preventDefault();let J=I.getKeyLeftOf(e.focusedKey);J==null&&C&&(J=h==="rtl"?(D=I.getFirstKey)===null||D===void 0?void 0:D.call(I,e.focusedKey):(Y=I.getLastKey)===null||Y===void 0?void 0:Y.call(I,e.focusedKey)),S(J,h==="rtl"?"first":"last")}break;case"ArrowRight":if(I.getKeyRightOf){var F,_;R.preventDefault();let J=I.getKeyRightOf(e.focusedKey);J==null&&C&&(J=h==="rtl"?(F=I.getLastKey)===null||F===void 0?void 0:F.call(I,e.focusedKey):(_=I.getFirstKey)===null||_===void 0?void 0:_.call(I,e.focusedKey)),S(J,h==="rtl"?"last":"first")}break;case"Home":if(I.getFirstKey){R.preventDefault();let J=I.getFirstKey(e.focusedKey,ep(R));e.setFocusedKey(J),ep(R)&&R.shiftKey&&e.selectionMode==="multiple"?e.extendSelection(J):A&&e.replaceSelection(J)}break;case"End":if(I.getLastKey){R.preventDefault();let J=I.getLastKey(e.focusedKey,ep(R));e.setFocusedKey(J),ep(R)&&R.shiftKey&&e.selectionMode==="multiple"?e.extendSelection(J):A&&e.replaceSelection(J)}break;case"PageDown":if(I.getKeyPageBelow){R.preventDefault();let J=I.getKeyPageBelow(e.focusedKey);S(J)}break;case"PageUp":if(I.getKeyPageAbove){R.preventDefault();let J=I.getKeyPageAbove(e.focusedKey);S(J)}break;case"a":ep(R)&&e.selectionMode==="multiple"&&o!==!0&&(R.preventDefault(),e.selectAll());break;case"Escape":R.preventDefault(),r||e.clearSelection();break;case"Tab":if(!l){if(R.shiftKey)i.current.focus();else{let J=eo(i.current,{tabbable:!0}),te,q;do q=J.lastChild(),q&&(te=q);while(q);te&&!te.contains(document.activeElement)&&Rs(te)}break}}},b=Ie.useRef({top:0,left:0});Cig(u,"scroll",c?null:()=>{b.current={top:u.current.scrollTop,left:u.current.scrollLeft}});let p=R=>{if(e.isFocused){R.currentTarget.contains(R.target)||e.setFocused(!1);return}if(R.currentTarget.contains(R.target)){if(e.setFocused(!0),e.focusedKey==null){let W=H=>{H!=null&&(e.setFocusedKey(H),A&&e.replaceSelection(H))},V=R.relatedTarget;var S,X;V&&R.currentTarget.compareDocumentPosition(V)&Node.DOCUMENT_POSITION_FOLLOWING?W((S=e.lastSelectedKey)!==null&&S!==void 0?S:I.getLastKey()):W((X=e.firstSelectedKey)!==null&&X!==void 0?X:I.getFirstKey())}else c||(u.current.scrollTop=b.current.top,u.current.scrollLeft=b.current.left);if(!c&&e.focusedKey!=null){let W=u.current.querySelector(`[data-key="${e.focusedKey}"]`);W&&(W.contains(document.activeElement)||Rs(W),lL()==="keyboard"&&nc(W,{containingElement:i.current}))}}},y=R=>{R.currentTarget.contains(R.relatedTarget)||e.setFocused(!1)};const Z=Ie.useRef(n);Ie.useEffect(()=>{if(Z.current){let R=null;n==="first"&&(R=I.getFirstKey()),n==="last"&&(R=I.getLastKey());let S=e.selectedKeys;S.size&&(R=S.values().next().value),e.setFocused(!0),e.setFocusedKey(R),R==null&&!a&&tr(i.current)}Z.current=!1},[]);let v=Ie.useRef(e.focusedKey);Ie.useEffect(()=>{let R=lL();if(e.isFocused&&e.focusedKey!=null&&(u!=null&&u.current)){let S=u.current.querySelector(`[data-key="${e.focusedKey}"]`);S&&R==="keyboard"&&(c||m2e(u.current,S),nc(S,{containingElement:i.current}))}e.isFocused&&e.focusedKey==null&&v.current!=null&&tr(i.current),v.current=e.focusedKey},[c,u,e.focusedKey,e.isFocused,i]);let G={onKeyDown:f,onFocus:p,onBlur:y,onMouseDown(R){u.current===R.target&&R.preventDefault()}},{typeSelectProps:B}=hng({keyboardDelegate:I,selectionManager:e});s||(G=bi(B,G));let w;return a||(w=e.focusedKey==null?0:-1),{collectionProps:{...G,tabIndex:w}}}function T2e(g){let{selectionManager:e,key:I,ref:i,shouldSelectOnPressUp:n,shouldUseVirtualFocus:C,focus:r,isDisabled:o,onAction:A,allowsDifferentPressOrigin:s,linkBehavior:a="action"}=g,l=l2e(),c=Y=>{if(Y.pointerType==="keyboard"&&fL(Y))e.toggleSelection(I);else{if(e.selectionMode==="none")return;if(e.isLink(I)){if(a==="selection"){l.open(i.current,Y),e.setSelectedKeys(e.selectedKeys);return}else if(a==="override"||a==="none")return}e.selectionMode==="single"?e.isSelected(I)&&!e.disallowEmptySelection?e.toggleSelection(I):e.replaceSelection(I):Y&&Y.shiftKey?e.extendSelection(I):e.selectionBehavior==="toggle"||Y&&(ep(Y)||Y.pointerType==="touch"||Y.pointerType==="virtual")?e.toggleSelection(I):e.replaceSelection(I)}};Ie.useEffect(()=>{I===e.focusedKey&&e.isFocused&&!C&&(r?r():document.activeElement!==i.current&&tr(i.current))},[i,I,e.focusedKey,e.childFocusStrategy,e.isFocused,C]),o=o||e.isDisabled(I);let u={};!C&&!o?u={tabIndex:I===e.focusedKey?0:-1,onFocus(Y){Y.target===i.current&&e.setFocusedKey(I)}}:o&&(u.onMouseDown=Y=>{Y.preventDefault()});let d=e.isLink(I)&&a==="override",h=e.isLink(I)&&a!=="selection"&&a!=="none",m=!o&&e.canSelectItem(I)&&!d,f=(A||h)&&!o,b=f&&(e.selectionBehavior==="replace"?!m:!m||e.isEmpty),p=f&&m&&e.selectionBehavior==="replace",y=b||p,Z=Ie.useRef(null),v=y&&m,G=Ie.useRef(!1),B=Ie.useRef(!1),w=Y=>{A&&A(),h&&l.open(i.current,Y)},R={};n?(R.onPressStart=Y=>{Z.current=Y.pointerType,G.current=v,Y.pointerType==="keyboard"&&(!y||Sce())&&c(Y)},s?(R.onPressUp=b?null:Y=>{Y.pointerType!=="keyboard"&&m&&c(Y)},R.onPress=b?w:null):R.onPress=Y=>{if(b||p&&Y.pointerType!=="mouse"){if(Y.pointerType==="keyboard"&&!vce())return;w(Y)}else Y.pointerType!=="keyboard"&&m&&c(Y)}):(R.onPressStart=Y=>{Z.current=Y.pointerType,G.current=v,B.current=b,m&&(Y.pointerType==="mouse"&&!b||Y.pointerType==="keyboard"&&(!f||Sce()))&&c(Y)},R.onPress=Y=>{(Y.pointerType==="touch"||Y.pointerType==="pen"||Y.pointerType==="virtual"||Y.pointerType==="keyboard"&&y&&vce()||Y.pointerType==="mouse"&&B.current)&&(y?w(Y):m&&c(Y))}),u["data-key"]=I,R.preventFocusOnPress=C;let{pressProps:S,isPressed:X}=J$(R),W=p?Y=>{Z.current==="mouse"&&(Y.stopPropagation(),Y.preventDefault(),w(Y))}:void 0,{longPressProps:V}=Tig({isDisabled:!v,onLongPress(Y){Y.pointerType==="touch"&&(c(Y),e.setSelectionBehavior("toggle"))}}),H=Y=>{Z.current==="touch"&&G.current&&Y.preventDefault()},D=e.isLink(I)?Y=>{Lh.isOpening||Y.preventDefault()}:void 0;return{itemProps:bi(u,m||b?S:{},v?V:{},{onDoubleClick:W,onDragStartCapture:H,onClick:D}),isPressed:X,isSelected:e.isSelected(I),isFocused:e.isFocused&&e.focusedKey===I,isDisabled:o,allowsSelection:m,hasAction:y}}function vce(){let g=window.event;return(g==null?void 0:g.key)==="Enter"}function Sce(){let g=window.event;return(g==null?void 0:g.key)===" "||(g==null?void 0:g.code)==="Space"}class png{getNextKey(e){for(e=this.collection.getKeyAfter(e);e!=null;){if(this.collection.getItem(e).type==="item"&&!this.disabledKeys.has(e))return e;e=this.collection.getKeyAfter(e)}return null}getPreviousKey(e){for(e=this.collection.getKeyBefore(e);e!=null;){if(this.collection.getItem(e).type==="item"&&!this.disabledKeys.has(e))return e;e=this.collection.getKeyBefore(e)}return null}findKey(e,I,i){let n=this.getItem(e);if(!n)return null;let C=n.getBoundingClientRect();do e=I(e),n=this.getItem(e);while(n&&i(C,n.getBoundingClientRect()));return e}isSameRow(e,I){return e.top===I.top||e.left!==I.left}isSameColumn(e,I){return e.left===I.left||e.top!==I.top}getKeyBelow(e){return this.layout==="grid"&&this.orientation==="vertical"?this.findKey(e,I=>this.getNextKey(I),this.isSameRow):this.getNextKey(e)}getKeyAbove(e){return this.layout==="grid"&&this.orientation==="vertical"?this.findKey(e,I=>this.getPreviousKey(I),this.isSameRow):this.getPreviousKey(e)}getNextColumn(e,I){return I?this.getPreviousKey(e):this.getNextKey(e)}getKeyRightOf(e){return this.layout==="grid"?this.orientation==="vertical"?this.getNextColumn(e,this.direction==="rtl"):this.findKey(e,I=>this.getNextColumn(I,this.direction==="rtl"),this.isSameColumn):this.orientation==="horizontal"?this.getNextColumn(e,this.direction==="rtl"):null}getKeyLeftOf(e){return this.layout==="grid"?this.orientation==="vertical"?this.getNextColumn(e,this.direction==="ltr"):this.findKey(e,I=>this.getNextColumn(I,this.direction==="ltr"),this.isSameColumn):this.orientation==="horizontal"?this.getNextColumn(e,this.direction==="ltr"):null}getFirstKey(){let e=this.collection.getFirstKey();for(;e!=null;){if(this.collection.getItem(e).type==="item"&&!this.disabledKeys.has(e))return e;e=this.collection.getKeyAfter(e)}return null}getLastKey(){let e=this.collection.getLastKey();for(;e!=null;){if(this.collection.getItem(e).type==="item"&&!this.disabledKeys.has(e))return e;e=this.collection.getKeyBefore(e)}return null}getItem(e){return this.ref.current.querySelector(`[data-key="${e}"]`)}getKeyPageAbove(e){let I=this.ref.current,i=this.getItem(e);if(!i)return null;if(!nT(I))return this.getFirstKey();let n=I.getBoundingClientRect(),C=i.getBoundingClientRect();if(this.orientation==="horizontal"){let r=n.x-I.scrollLeft,o=Math.max(0,C.x-r+C.width-n.width);for(;i&&C.x-r>o;)e=this.getKeyAbove(e),i=e==null?null:this.getItem(e),C=i==null?void 0:i.getBoundingClientRect()}else{let r=n.y-I.scrollTop,o=Math.max(0,C.y-r+C.height-n.height);for(;i&&C.y-r>o;)e=this.getKeyAbove(e),i=e==null?null:this.getItem(e),C=i==null?void 0:i.getBoundingClientRect()}return e??this.getFirstKey()}getKeyPageBelow(e){let I=this.ref.current,i=this.getItem(e);if(!i)return null;if(!nT(I))return this.getLastKey();let n=I.getBoundingClientRect(),C=i.getBoundingClientRect();if(this.orientation==="horizontal"){let r=n.x-I.scrollLeft,o=Math.min(I.scrollWidth,C.x-r-C.width+n.width);for(;i&&C.x-rthis.iterateCollection(e))}*iterateCollection(e){let{children:I,items:i}=e;if(typeof I=="function"){if(!i)throw new Error("props.children was a function but props.items is missing");for(let n of e.items)yield*this.getFullNode({value:n},{renderer:I})}else{let n=[];N.Children.forEach(I,r=>{n.push(r)});let C=0;for(let r of n){let o=this.getFullNode({element:r,index:C},{});for(let A of o)C++,yield A}}}getKey(e,I,i,n){if(e.key!=null)return e.key;if(I.type==="cell"&&I.key!=null)return`${n}${I.key}`;let C=I.value;if(C!=null){var r;let o=(r=C.key)!==null&&r!==void 0?r:C.id;if(o==null)throw new Error("No key found for item");return o}return n?`${n}.${I.index}`:`$.${I.index}`}getChildState(e,I){return{renderer:I.renderer||e.renderer}}*getFullNode(e,I,i,n){let C=e.element;if(!C&&e.value&&I&&I.renderer){let A=this.cache.get(e.value);if(A&&(!A.shouldInvalidate||!A.shouldInvalidate(this.context))){A.index=e.index,A.parentKey=n?n.key:null,yield A;return}C=I.renderer(e.value)}if(N.isValidElement(C)){let A=C.type;if(typeof A!="function"&&typeof A.getCollectionNode!="function"){let c=typeof C.type=="function"?C.type.name:C.type;throw new Error(`Unknown element <${c}> in collection.`)}let s=A.getCollectionNode(C.props,this.context),a=e.index,l=s.next();for(;!l.done&&l.value;){let c=l.value;e.index=a;let u=c.key;u||(u=c.element?null:this.getKey(C,e,I,i));let h=[...this.getFullNode({...c,key:u,index:a,wrapper:yng(e.wrapper,c.wrapper)},this.getChildState(I,c),i?`${i}${C.key}`:C.key,n)];for(let m of h){if(m.value=c.value||e.value,m.value&&this.cache.set(m.value,m),e.type&&m.type!==e.type)throw new Error(`Unsupported type <${jF(m.type)}> in <${jF(n.type)}>. Only <${jF(e.type)}> is supported.`);a++,yield m}l=s.next(h)}return}if(e.key==null)return;let r=this,o={type:e.type,props:e.props,key:e.key,parentKey:n?n.key:null,value:e.value,level:n?n.level+1:0,index:e.index,rendered:e.rendered,textValue:e.textValue,"aria-label":e["aria-label"],wrapper:e.wrapper,shouldInvalidate:e.shouldInvalidate,hasChildNodes:e.hasChildNodes,childNodes:wce(function*(){if(!e.hasChildNodes)return;let A=0;for(let s of e.childNodes()){s.key!=null&&(s.key=`${o.key}${s.key}`),s.index=A;let a=r.getFullNode(s,r.getChildState(I,s),o.key,o);for(let l of a)A++,yield l}})};yield o}constructor(){this.cache=new WeakMap}}function wce(g){let e=[],I=null;return{*[Symbol.iterator](){for(let i of e)yield i;I||(I=g());for(let i of I)e.push(i),yield i}}}function yng(g,e){if(g&&e)return I=>g(e(I));if(g)return g;if(e)return e}function jF(g){return g[0].toUpperCase()+g.slice(1)}function Zng(g,e,I){let i=Ie.useMemo(()=>new bng,[]),{children:n,items:C,collection:r}=g;return Ie.useMemo(()=>{if(r)return r;let A=i.build({children:n,items:C},I);return e(A)},[i,n,C,r,I,e])}function Gi(g,e){return typeof e.getChildren=="function"?e.getChildren(g.key):g.childNodes}function us(g){return Cc(g,0)}function Cc(g,e){if(e<0)return;let I=0;for(let i of g){if(I===e)return i;I++}}function Nc(g){let e;for(let I of g)e=I;return e}function $F(g,e,I){if(e.parentKey===I.parentKey)return e.index-I.index;let i=[...Vce(g,e),e],n=[...Vce(g,I),I],C=i.slice(0,n.length).findIndex((r,o)=>r!==n[o]);return C!==-1?(e=i[C],I=n[C],e.index-I.index):i.findIndex(r=>r===I)>=0?1:(n.findIndex(r=>r===e)>=0,-1)}function Vce(g,e){let I=[];for(;(e==null?void 0:e.parentKey)!=null;)e=g.getItem(e.parentKey),I.unshift(e);return I}function Gng(g,e){let{inputElementType:I="input",isDisabled:i=!1,isRequired:n=!1,isReadOnly:C=!1,type:r="text",validationBehavior:o="aria"}=g,[A,s]=o2e(g.value,g.defaultValue||"",g.onChange),{focusableProps:a}=S2e(g,e),l=ang({...g,value:A}),{isInvalid:c,validationErrors:u,validationDetails:d}=l.displayValidation,{labelProps:h,fieldProps:m,descriptionProps:f,errorMessageProps:b}=ung({...g,isInvalid:c,errorMessage:g.errorMessage||u}),p=Da(g,{labelable:!0});const y={type:r,pattern:g.pattern};return oig(e,A,s),nng(g,l,e),Ie.useEffect(()=>{if(e.current instanceof IT(e.current).HTMLTextAreaElement){let Z=e.current;Object.defineProperty(Z,"defaultValue",{get:()=>Z.value,set:()=>{},configurable:!0})}},[e]),{labelProps:h,inputProps:bi(p,I==="input"&&y,{disabled:i,readOnly:C,required:n&&o==="native","aria-required":n&&o==="aria"||void 0,"aria-invalid":c||void 0,"aria-errormessage":g["aria-errormessage"],"aria-activedescendant":g["aria-activedescendant"],"aria-autocomplete":g["aria-autocomplete"],"aria-haspopup":g["aria-haspopup"],value:A,onChange:Z=>s(Z.target.value),autoComplete:g.autoComplete,maxLength:g.maxLength,minLength:g.minLength,name:g.name,placeholder:g.placeholder,inputMode:g.inputMode,onCopy:g.onCopy,onCut:g.onCut,onPaste:g.onPaste,onCompositionEnd:g.onCompositionEnd,onCompositionStart:g.onCompositionStart,onCompositionUpdate:g.onCompositionUpdate,onSelect:g.onSelect,onBeforeInput:g.onBeforeInput,onInput:g.onInput,...a,...m}),descriptionProps:f,errorMessageProps:b,isInvalid:c,validationErrors:u,validationDetails:d}}class wp{copy(){return new wp(this.x,this.y)}equals(e){return this.x===e.x&&this.y===e.y}isOrigin(){return this.x===0&&this.y===0}constructor(e=0,I=0){this.x=e,this.y=I}}class Vp{get maxX(){return this.x+this.width}get maxY(){return this.y+this.height}get area(){return this.width*this.height}get topLeft(){return new wp(this.x,this.y)}get topRight(){return new wp(this.maxX,this.y)}get bottomLeft(){return new wp(this.x,this.maxY)}get bottomRight(){return new wp(this.maxX,this.maxY)}intersects(e){return this.x<=e.x+e.width&&e.x<=this.x+this.width&&this.y<=e.y+e.height&&e.y<=this.y+this.height}containsRect(e){return this.x<=e.x&&this.y<=e.y&&this.maxX>=e.maxX&&this.maxY>=e.maxY}containsPoint(e){return this.x<=e.x&&this.y<=e.y&&this.maxX>=e.x&&this.maxY>=e.y}getCornerInRect(e){for(let I of["topLeft","topRight","bottomLeft","bottomRight"])if(e.containsPoint(this[I]))return I;return null}equals(e){return e.x===this.x&&e.y===this.y&&e.width===this.width&&e.height===this.height}pointEquals(e){return this.x===e.x&&this.y===e.y}sizeEquals(e){return this.width===e.width&&this.height===e.height}union(e){let I=Math.min(this.x,e.x),i=Math.min(this.y,e.y),n=Math.max(this.maxX,e.maxX)-I,C=Math.max(this.maxY,e.maxY)-i;return new Vp(I,i,n,C)}intersection(e){if(!this.intersects(e))return new Vp(0,0,0,0);let I=Math.max(this.x,e.x),i=Math.max(this.y,e.y);return new Vp(I,i,Math.min(this.maxX,e.maxX)-I,Math.min(this.maxY,e.maxY)-i)}copy(){return new Vp(this.x,this.y,this.width,this.height)}constructor(e=0,I=0,i=0,n=0){this.x=e,this.y=I,this.width=i,this.height=n}}let tp=typeof window<"u"?window.performance:null,Rce=tp&&(tp.now||tp.webkitNow||tp.msNow||tp.mozNow);Rce&&Rce.bind(tp);function q$(g){return g&&g.__esModule?g.default:g}class N2e{isCell(e){return e.type==="cell"}isRow(e){return e.type==="row"||e.type==="item"}findPreviousKey(e,I){let i=e!=null?this.collection.getKeyBefore(e):this.collection.getLastKey();for(;i!=null;){let n=this.collection.getItem(i);if(!this.disabledKeys.has(i)&&(!I||I(n)))return i;i=this.collection.getKeyBefore(i)}}findNextKey(e,I){let i=e!=null?this.collection.getKeyAfter(e):this.collection.getFirstKey();for(;i!=null;){let n=this.collection.getItem(i);if(!this.disabledKeys.has(i)&&(!I||I(n)))return i;i=this.collection.getKeyAfter(i)}}getKeyBelow(e){let I=this.collection.getItem(e);if(I&&(this.isCell(I)&&(e=I.parentKey),e=this.findNextKey(e),e!=null)){if(this.isCell(I)){let i=this.collection.getItem(e);return Cc(Gi(i,this.collection),I.index).key}if(this.focusMode==="row")return e}}getKeyAbove(e){let I=this.collection.getItem(e);if(I&&(this.isCell(I)&&(e=I.parentKey),e=this.findPreviousKey(e),e!=null)){if(this.isCell(I)){let i=this.collection.getItem(e);return Cc(Gi(i,this.collection),I.index).key}if(this.focusMode==="row")return e}}getKeyRightOf(e){let I=this.collection.getItem(e);if(I){if(this.isRow(I)){let i=Gi(I,this.collection);return this.direction==="rtl"?Nc(i).key:us(i).key}if(this.isCell(I)){let i=this.collection.getItem(I.parentKey),n=Gi(i,this.collection),C=this.direction==="rtl"?Cc(n,I.index-1):Cc(n,I.index+1);return C?C.key:this.focusMode==="row"?I.parentKey:this.direction==="rtl"?this.getFirstKey(e):this.getLastKey(e)}}}getKeyLeftOf(e){let I=this.collection.getItem(e);if(I){if(this.isRow(I)){let i=Gi(I,this.collection);return this.direction==="rtl"?us(i).key:Nc(i).key}if(this.isCell(I)){let i=this.collection.getItem(I.parentKey),n=Gi(i,this.collection),C=this.direction==="rtl"?Cc(n,I.index+1):Cc(n,I.index-1);return C?C.key:this.focusMode==="row"?I.parentKey:this.direction==="rtl"?this.getLastKey(e):this.getFirstKey(e)}}}getFirstKey(e,I){let i;if(e!=null){if(i=this.collection.getItem(e),!i)return;if(this.isCell(i)&&!I){let n=this.collection.getItem(i.parentKey);return us(Gi(n,this.collection)).key}}if(e=this.findNextKey(),e!=null&&i&&this.isCell(i)&&I||this.focusMode==="cell"){let n=this.collection.getItem(e);e=us(Gi(n,this.collection)).key}return e}getLastKey(e,I){let i;if(e!=null){if(i=this.collection.getItem(e),!i)return;if(this.isCell(i)&&!I){let n=this.collection.getItem(i.parentKey),C=Gi(n,this.collection);return Nc(C).key}}if(e=this.findPreviousKey(),e!=null&&i&&this.isCell(i)&&I||this.focusMode==="cell"){let n=this.collection.getItem(e),C=Gi(n,this.collection);e=Nc(C).key}return e}getItem(e){return this.ref.current.querySelector(`[data-key="${e}"]`)}getItemRect(e){var I;if(this.layout)return(I=this.layout.getLayoutInfo(e))===null||I===void 0?void 0:I.rect;let i=this.getItem(e);if(i)return new Vp(i.offsetLeft,i.offsetTop,i.offsetWidth,i.offsetHeight)}getPageHeight(){var e,I,i;return this.layout?(e=this.layout.virtualizer)===null||e===void 0?void 0:e.visibleRect.height:(i=this.ref)===null||i===void 0||(I=i.current)===null||I===void 0?void 0:I.offsetHeight}getContentHeight(){var e,I;return this.layout?this.layout.getContentSize().height:(I=this.ref)===null||I===void 0||(e=I.current)===null||e===void 0?void 0:e.scrollHeight}getKeyPageAbove(e){let I=this.getItemRect(e);if(!I)return null;let i=Math.max(0,I.maxY-this.getPageHeight());for(;I&&I.y>i;)e=this.getKeyAbove(e),I=this.getItemRect(e);return e}getKeyPageBelow(e){let I=this.getItemRect(e);if(!I)return null;let i=this.getPageHeight(),n=Math.min(this.getContentHeight(),I.y+i);for(;I&&I.maxY`${g.item} غير المحدد`,longPressToSelect:"اضغط مطولًا للدخول إلى وضع التحديد.",select:"تحديد",selectedAll:"جميع العناصر المحددة.",selectedCount:(g,e)=>`${e.plural(g.count,{"=0":"لم يتم تحديد عناصر",one:()=>`${e.number(g.count)} عنصر محدد`,other:()=>`${e.number(g.count)} عنصر محدد`})}.`,selectedItem:g=>`${g.item} المحدد`};var Y2e={};Y2e={deselectedItem:g=>`${g.item} не е избран.`,longPressToSelect:"Натиснете и задръжте за да влезете в избирателен режим.",select:"Изберете",selectedAll:"Всички елементи са избрани.",selectedCount:(g,e)=>`${e.plural(g.count,{"=0":"Няма избрани елементи",one:()=>`${e.number(g.count)} избран елемент`,other:()=>`${e.number(g.count)} избрани елементи`})}.`,selectedItem:g=>`${g.item} избран.`};var K2e={};K2e={deselectedItem:g=>`Položka ${g.item} není vybrána.`,longPressToSelect:"Dlouhým stisknutím přejdete do režimu výběru.",select:"Vybrat",selectedAll:"Vybrány všechny položky.",selectedCount:(g,e)=>`${e.plural(g.count,{"=0":"Nevybrány žádné položky",one:()=>`Vybrána ${e.number(g.count)} položka`,other:()=>`Vybráno ${e.number(g.count)} položek`})}.`,selectedItem:g=>`Vybrána položka ${g.item}.`};var x2e={};x2e={deselectedItem:g=>`${g.item} ikke valgt.`,longPressToSelect:"Lav et langt tryk for at aktivere valgtilstand.",select:"Vælg",selectedAll:"Alle elementer valgt.",selectedCount:(g,e)=>`${e.plural(g.count,{"=0":"Ingen elementer valgt",one:()=>`${e.number(g.count)} element valgt`,other:()=>`${e.number(g.count)} elementer valgt`})}.`,selectedItem:g=>`${g.item} valgt.`};var D2e={};D2e={deselectedItem:g=>`${g.item} nicht ausgewählt.`,longPressToSelect:"Gedrückt halten, um Auswahlmodus zu öffnen.",select:"Auswählen",selectedAll:"Alle Elemente ausgewählt.",selectedCount:(g,e)=>`${e.plural(g.count,{"=0":"Keine Elemente ausgewählt",one:()=>`${e.number(g.count)} Element ausgewählt`,other:()=>`${e.number(g.count)} Elemente ausgewählt`})}.`,selectedItem:g=>`${g.item} ausgewählt.`};var F2e={};F2e={deselectedItem:g=>`Δεν επιλέχθηκε το στοιχείο ${g.item}.`,longPressToSelect:"Πατήστε παρατεταμένα για να μπείτε σε λειτουργία επιλογής.",select:"Επιλογή",selectedAll:"Επιλέχθηκαν όλα τα στοιχεία.",selectedCount:(g,e)=>`${e.plural(g.count,{"=0":"Δεν επιλέχθηκαν στοιχεία",one:()=>`Επιλέχθηκε ${e.number(g.count)} στοιχείο`,other:()=>`Επιλέχθηκαν ${e.number(g.count)} στοιχεία`})}.`,selectedItem:g=>`Επιλέχθηκε το στοιχείο ${g.item}.`};var E2e={};E2e={deselectedItem:g=>`${g.item} not selected.`,select:"Select",selectedCount:(g,e)=>`${e.plural(g.count,{"=0":"No items selected",one:()=>`${e.number(g.count)} item selected`,other:()=>`${e.number(g.count)} items selected`})}.`,selectedAll:"All items selected.",selectedItem:g=>`${g.item} selected.`,longPressToSelect:"Long press to enter selection mode."};var M2e={};M2e={deselectedItem:g=>`${g.item} no seleccionado.`,longPressToSelect:"Mantenga pulsado para abrir el modo de selección.",select:"Seleccionar",selectedAll:"Todos los elementos seleccionados.",selectedCount:(g,e)=>`${e.plural(g.count,{"=0":"Ningún elemento seleccionado",one:()=>`${e.number(g.count)} elemento seleccionado`,other:()=>`${e.number(g.count)} elementos seleccionados`})}.`,selectedItem:g=>`${g.item} seleccionado.`};var z2e={};z2e={deselectedItem:g=>`${g.item} pole valitud.`,longPressToSelect:"Valikurežiimi sisenemiseks vajutage pikalt.",select:"Vali",selectedAll:"Kõik üksused valitud.",selectedCount:(g,e)=>`${e.plural(g.count,{"=0":"Üksusi pole valitud",one:()=>`${e.number(g.count)} üksus valitud`,other:()=>`${e.number(g.count)} üksust valitud`})}.`,selectedItem:g=>`${g.item} valitud.`};var P2e={};P2e={deselectedItem:g=>`Kohdetta ${g.item} ei valittu.`,longPressToSelect:"Siirry valintatilaan painamalla pitkään.",select:"Valitse",selectedAll:"Kaikki kohteet valittu.",selectedCount:(g,e)=>`${e.plural(g.count,{"=0":"Ei yhtään kohdetta valittu",one:()=>`${e.number(g.count)} kohde valittu`,other:()=>`${e.number(g.count)} kohdetta valittu`})}.`,selectedItem:g=>`${g.item} valittu.`};var J2e={};J2e={deselectedItem:g=>`${g.item} non sélectionné.`,longPressToSelect:"Appuyez de manière prolongée pour passer en mode de sélection.",select:"Sélectionner",selectedAll:"Tous les éléments sélectionnés.",selectedCount:(g,e)=>`${e.plural(g.count,{"=0":"Aucun élément sélectionné",one:()=>`${e.number(g.count)} élément sélectionné`,other:()=>`${e.number(g.count)} éléments sélectionnés`})}.`,selectedItem:g=>`${g.item} sélectionné.`};var O2e={};O2e={deselectedItem:g=>`${g.item} לא נבחר.`,longPressToSelect:"הקשה ארוכה לכניסה למצב בחירה.",select:"בחר",selectedAll:"כל הפריטים נבחרו.",selectedCount:(g,e)=>`${e.plural(g.count,{"=0":"לא נבחרו פריטים",one:()=>`פריט ${e.number(g.count)} נבחר`,other:()=>`${e.number(g.count)} פריטים נבחרו`})}.`,selectedItem:g=>`${g.item} נבחר.`};var L2e={};L2e={deselectedItem:g=>`Stavka ${g.item} nije odabrana.`,longPressToSelect:"Dugo pritisnite za ulazak u način odabira.",select:"Odaberite",selectedAll:"Odabrane su sve stavke.",selectedCount:(g,e)=>`${e.plural(g.count,{"=0":"Nije odabrana nijedna stavka",one:()=>`Odabrana je ${e.number(g.count)} stavka`,other:()=>`Odabrano je ${e.number(g.count)} stavki`})}.`,selectedItem:g=>`Stavka ${g.item} je odabrana.`};var _2e={};_2e={deselectedItem:g=>`${g.item} nincs kijelölve.`,longPressToSelect:"Nyomja hosszan a kijelöléshez.",select:"Kijelölés",selectedAll:"Az összes elem kijelölve.",selectedCount:(g,e)=>`${e.plural(g.count,{"=0":"Egy elem sincs kijelölve",one:()=>`${e.number(g.count)} elem kijelölve`,other:()=>`${e.number(g.count)} elem kijelölve`})}.`,selectedItem:g=>`${g.item} kijelölve.`};var U2e={};U2e={deselectedItem:g=>`${g.item} non selezionato.`,longPressToSelect:"Premi a lungo per passare alla modalità di selezione.",select:"Seleziona",selectedAll:"Tutti gli elementi selezionati.",selectedCount:(g,e)=>`${e.plural(g.count,{"=0":"Nessun elemento selezionato",one:()=>`${e.number(g.count)} elemento selezionato`,other:()=>`${e.number(g.count)} elementi selezionati`})}.`,selectedItem:g=>`${g.item} selezionato.`};var Q2e={};Q2e={deselectedItem:g=>`${g.item} が選択されていません。`,longPressToSelect:"長押しして選択モードを開きます。",select:"選択",selectedAll:"すべての項目を選択しました。",selectedCount:(g,e)=>`${e.plural(g.count,{"=0":"項目が選択されていません",one:()=>`${e.number(g.count)} 項目を選択しました`,other:()=>`${e.number(g.count)} 項目を選択しました`})}。`,selectedItem:g=>`${g.item} を選択しました。`};var j2e={};j2e={deselectedItem:g=>`${g.item}이(가) 선택되지 않았습니다.`,longPressToSelect:"선택 모드로 들어가려면 길게 누르십시오.",select:"선택",selectedAll:"모든 항목이 선택되었습니다.",selectedCount:(g,e)=>`${e.plural(g.count,{"=0":"선택된 항목이 없습니다",one:()=>`${e.number(g.count)}개 항목이 선택되었습니다`,other:()=>`${e.number(g.count)}개 항목이 선택되었습니다`})}.`,selectedItem:g=>`${g.item}이(가) 선택되었습니다.`};var $2e={};$2e={deselectedItem:g=>`${g.item} nepasirinkta.`,longPressToSelect:"Norėdami įjungti pasirinkimo režimą, paspauskite ir palaikykite.",select:"Pasirinkti",selectedAll:"Pasirinkti visi elementai.",selectedCount:(g,e)=>`${e.plural(g.count,{"=0":"Nepasirinktas nė vienas elementas",one:()=>`Pasirinktas ${e.number(g.count)} elementas`,other:()=>`Pasirinkta elementų: ${e.number(g.count)}`})}.`,selectedItem:g=>`Pasirinkta: ${g.item}.`};var q2e={};q2e={deselectedItem:g=>`Vienums ${g.item} nav atlasīts.`,longPressToSelect:"Ilgi turiet nospiestu. lai ieslēgtu atlases režīmu.",select:"Atlasīt",selectedAll:"Atlasīti visi vienumi.",selectedCount:(g,e)=>`${e.plural(g.count,{"=0":"Nav atlasīts neviens vienums",one:()=>`Atlasīto vienumu skaits: ${e.number(g.count)}`,other:()=>`Atlasīto vienumu skaits: ${e.number(g.count)}`})}.`,selectedItem:g=>`Atlasīts vienums ${g.item}.`};var eTe={};eTe={deselectedItem:g=>`${g.item} er ikke valgt.`,longPressToSelect:"Bruk et langt trykk for å gå inn i valgmodus.",select:"Velg",selectedAll:"Alle elementer er valgt.",selectedCount:(g,e)=>`${e.plural(g.count,{"=0":"Ingen elementer er valgt",one:()=>`${e.number(g.count)} element er valgt`,other:()=>`${e.number(g.count)} elementer er valgt`})}.`,selectedItem:g=>`${g.item} er valgt.`};var tTe={};tTe={deselectedItem:g=>`${g.item} niet geselecteerd.`,longPressToSelect:"Druk lang om de selectiemodus te openen.",select:"Selecteren",selectedAll:"Alle items geselecteerd.",selectedCount:(g,e)=>`${e.plural(g.count,{"=0":"Geen items geselecteerd",one:()=>`${e.number(g.count)} item geselecteerd`,other:()=>`${e.number(g.count)} items geselecteerd`})}.`,selectedItem:g=>`${g.item} geselecteerd.`};var gTe={};gTe={deselectedItem:g=>`Nie zaznaczono ${g.item}.`,longPressToSelect:"Naciśnij i przytrzymaj, aby wejść do trybu wyboru.",select:"Zaznacz",selectedAll:"Wszystkie zaznaczone elementy.",selectedCount:(g,e)=>`${e.plural(g.count,{"=0":"Nie zaznaczono żadnych elementów",one:()=>`${e.number(g.count)} zaznaczony element`,other:()=>`${e.number(g.count)} zaznaczonych elementów`})}.`,selectedItem:g=>`Zaznaczono ${g.item}.`};var ITe={};ITe={deselectedItem:g=>`${g.item} não selecionado.`,longPressToSelect:"Mantenha pressionado para entrar no modo de seleção.",select:"Selecionar",selectedAll:"Todos os itens selecionados.",selectedCount:(g,e)=>`${e.plural(g.count,{"=0":"Nenhum item selecionado",one:()=>`${e.number(g.count)} item selecionado`,other:()=>`${e.number(g.count)} itens selecionados`})}.`,selectedItem:g=>`${g.item} selecionado.`};var iTe={};iTe={deselectedItem:g=>`${g.item} não selecionado.`,longPressToSelect:"Prima continuamente para entrar no modo de seleção.",select:"Selecionar",selectedAll:"Todos os itens selecionados.",selectedCount:(g,e)=>`${e.plural(g.count,{"=0":"Nenhum item selecionado",one:()=>`${e.number(g.count)} item selecionado`,other:()=>`${e.number(g.count)} itens selecionados`})}.`,selectedItem:g=>`${g.item} selecionado.`};var nTe={};nTe={deselectedItem:g=>`${g.item} neselectat.`,longPressToSelect:"Apăsați lung pentru a intra în modul de selectare.",select:"Selectare",selectedAll:"Toate elementele selectate.",selectedCount:(g,e)=>`${e.plural(g.count,{"=0":"Niciun element selectat",one:()=>`${e.number(g.count)} element selectat`,other:()=>`${e.number(g.count)} elemente selectate`})}.`,selectedItem:g=>`${g.item} selectat.`};var CTe={};CTe={deselectedItem:g=>`${g.item} не выбрано.`,longPressToSelect:"Нажмите и удерживайте для входа в режим выбора.",select:"Выбрать",selectedAll:"Выбраны все элементы.",selectedCount:(g,e)=>`${e.plural(g.count,{"=0":"Нет выбранных элементов",one:()=>`${e.number(g.count)} элемент выбран`,other:()=>`${e.number(g.count)} элементов выбрано`})}.`,selectedItem:g=>`${g.item} выбрано.`};var rTe={};rTe={deselectedItem:g=>`Nevybraté položky: ${g.item}.`,longPressToSelect:"Dlhším stlačením prejdite do režimu výberu.",select:"Vybrať",selectedAll:"Všetky vybraté položky.",selectedCount:(g,e)=>`${e.plural(g.count,{"=0":"Žiadne vybraté položky",one:()=>`${e.number(g.count)} vybratá položka`,other:()=>`Počet vybratých položiek:${e.number(g.count)}`})}.`,selectedItem:g=>`Vybraté položky: ${g.item}.`};var oTe={};oTe={deselectedItem:g=>`Element ${g.item} ni izbran.`,longPressToSelect:"Za izbirni način pritisnite in dlje časa držite.",select:"Izberite",selectedAll:"Vsi elementi so izbrani.",selectedCount:(g,e)=>`${e.plural(g.count,{"=0":"Noben element ni izbran",one:()=>`${e.number(g.count)} element je izbran`,other:()=>`${e.number(g.count)} elementov je izbranih`})}.`,selectedItem:g=>`Element ${g.item} je izbran.`};var ATe={};ATe={deselectedItem:g=>`${g.item} nije izabrano.`,longPressToSelect:"Dugo pritisnite za ulazak u režim biranja.",select:"Izaberite",selectedAll:"Izabrane su sve stavke.",selectedCount:(g,e)=>`${e.plural(g.count,{"=0":"Nije izabrana nijedna stavka",one:()=>`Izabrana je ${e.number(g.count)} stavka`,other:()=>`Izabrano je ${e.number(g.count)} stavki`})}.`,selectedItem:g=>`${g.item} je izabrano.`};var aTe={};aTe={deselectedItem:g=>`${g.item} ej markerat.`,longPressToSelect:"Tryck länge när du vill öppna väljarläge.",select:"Markera",selectedAll:"Alla markerade objekt.",selectedCount:(g,e)=>`${e.plural(g.count,{"=0":"Inga markerade objekt",one:()=>`${e.number(g.count)} markerat objekt`,other:()=>`${e.number(g.count)} markerade objekt`})}.`,selectedItem:g=>`${g.item} markerat.`};var sTe={};sTe={deselectedItem:g=>`${g.item} seçilmedi.`,longPressToSelect:"Seçim moduna girmek için uzun basın.",select:"Seç",selectedAll:"Tüm ögeler seçildi.",selectedCount:(g,e)=>`${e.plural(g.count,{"=0":"Hiçbir öge seçilmedi",one:()=>`${e.number(g.count)} öge seçildi`,other:()=>`${e.number(g.count)} öge seçildi`})}.`,selectedItem:g=>`${g.item} seçildi.`};var lTe={};lTe={deselectedItem:g=>`${g.item} не вибрано.`,longPressToSelect:"Виконайте довге натиснення, щоб перейти в режим вибору.",select:"Вибрати",selectedAll:"Усі елементи вибрано.",selectedCount:(g,e)=>`${e.plural(g.count,{"=0":"Жодних елементів не вибрано",one:()=>`${e.number(g.count)} елемент вибрано`,other:()=>`Вибрано елементів: ${e.number(g.count)}`})}.`,selectedItem:g=>`${g.item} вибрано.`};var cTe={};cTe={deselectedItem:g=>`未选择 ${g.item}。`,longPressToSelect:"长按以进入选择模式。",select:"选择",selectedAll:"已选择所有项目。",selectedCount:(g,e)=>`${e.plural(g.count,{"=0":"未选择项目",one:()=>`已选择 ${e.number(g.count)} 个项目`,other:()=>`已选择 ${e.number(g.count)} 个项目`})}。`,selectedItem:g=>`已选择 ${g.item}。`};var uTe={};uTe={deselectedItem:g=>`未選取「${g.item}」。`,longPressToSelect:"長按以進入選擇模式。",select:"選取",selectedAll:"已選取所有項目。",selectedCount:(g,e)=>`${e.plural(g.count,{"=0":"未選取任何項目",one:()=>`已選取 ${e.number(g.count)} 個項目`,other:()=>`已選取 ${e.number(g.count)} 個項目`})}。`,selectedItem:g=>`已選取「${g.item}」。`};SY={"ar-AE":k2e,"bg-BG":Y2e,"cs-CZ":K2e,"da-DK":x2e,"de-DE":D2e,"el-GR":F2e,"en-US":E2e,"es-ES":M2e,"et-EE":z2e,"fi-FI":P2e,"fr-FR":J2e,"he-IL":O2e,"hr-HR":L2e,"hu-HU":_2e,"it-IT":U2e,"ja-JP":Q2e,"ko-KR":j2e,"lt-LT":$2e,"lv-LV":q2e,"nb-NO":eTe,"nl-NL":tTe,"pl-PL":gTe,"pt-BR":ITe,"pt-PT":iTe,"ro-RO":nTe,"ru-RU":CTe,"sk-SK":rTe,"sl-SI":oTe,"sr-SP":ATe,"sv-SE":aTe,"tr-TR":sTe,"uk-UA":lTe,"zh-CN":cTe,"zh-TW":uTe};function Bng(g,e){let{getRowText:I=r=>{var o,A,s,a;return(a=(o=(A=e.collection).getTextValue)===null||o===void 0?void 0:o.call(A,r))!==null&&a!==void 0?a:(s=e.collection.getItem(r))===null||s===void 0?void 0:s.textValue}}=g,i=Gy(q$(SY)),n=e.selectionManager.rawSelection,C=Ie.useRef(n);d2e(()=>{var r;if(!e.selectionManager.isFocused){C.current=n;return}let o=Wce(n,C.current),A=Wce(C.current,n),s=e.selectionManager.selectionBehavior==="replace",a=[];if(e.selectionManager.selectedKeys.size===1&&s){if(e.collection.getItem(e.selectionManager.selectedKeys.keys().next().value)){let l=I(e.selectionManager.selectedKeys.keys().next().value);l&&a.push(i.format("selectedItem",{item:l}))}}else if(o.size===1&&A.size===0){let l=I(o.keys().next().value);l&&a.push(i.format("selectedItem",{item:l}))}else if(A.size===1&&o.size===0&&e.collection.getItem(A.keys().next().value)){let l=I(A.keys().next().value);l&&a.push(i.format("deselectedItem",{item:l}))}e.selectionManager.selectionMode==="multiple"&&(a.length===0||n==="all"||n.size>1||C.current==="all"||((r=C.current)===null||r===void 0?void 0:r.size)>1)&&a.push(n==="all"?i.format("selectedAll"):i.format("selectedCount",{count:n.size})),a.length>0&&W2e(a.join(" ")),C.current=n},[n])}function Wce(g,e){let I=new Set;if(g==="all"||e==="all")return I;for(let i of g.keys())e.has(i)||I.add(i);return I}function vng(g){let e=Gy(q$(SY)),I=Sig(),i=(I==="pointer"||I==="virtual"||I==null)&&typeof window<"u"&&"ontouchstart"in window,n=Ie.useMemo(()=>{let r=g.selectionManager.selectionMode,o=g.selectionManager.selectionBehavior,A;return i&&(A=e.format("longPressToSelect")),o==="replace"&&r!=="none"&&g.hasItemActions?A:void 0},[g.selectionManager.selectionMode,g.selectionManager.selectionBehavior,g.hasItemActions,e,i]);return GY(n)}function Sng(g,e,I){let{isVirtualized:i,keyboardDelegate:n,focusMode:C,scrollRef:r,getRowText:o,onRowAction:A,onCellAction:s}=g,{selectionManager:a}=e;!g["aria-label"]&&!g["aria-labelledby"]&&console.warn("An aria-label or aria-labelledby prop is required for accessibility.");let l=V2e({usage:"search",sensitivity:"base"}),{direction:c}=Xm(),u=e.selectionManager.disabledBehavior,d=Ie.useMemo(()=>n||new N2e({collection:e.collection,disabledKeys:u==="selection"?new Set:e.disabledKeys,ref:I,direction:c,collator:l,focusMode:C}),[n,e.collection,e.disabledKeys,u,I,c,l,C]),{collectionProps:h}=fng({ref:I,selectionManager:a,keyboardDelegate:d,isVirtualized:i,scrollRef:r}),m=Jh(g.id);e8.set(e,{keyboardDelegate:d,actions:{onRowAction:A,onCellAction:s}});let f=vng({selectionManager:a,hasItemActions:!!(A||s)}),b=Da(g,{labelable:!0}),p=Ie.useCallback(G=>{if(a.isFocused){G.currentTarget.contains(G.target)||a.setFocused(!1);return}G.currentTarget.contains(G.target)&&a.setFocused(!0)},[a]),y=Ie.useMemo(()=>({onBlur:h.onBlur,onFocus:p}),[p,h.onBlur]),Z=Lig(I,{isDisabled:e.collection.size!==0}),v=bi(b,{role:"grid",id:m,"aria-multiselectable":a.selectionMode==="multiple"?"true":void 0},e.isKeyboardNavigationDisabled?y:h,e.collection.size===0&&{tabIndex:Z?-1:0},f);return i&&(v["aria-rowcount"]=e.collection.size,v["aria-colcount"]=e.collection.columnCount),Bng({getRowText:o},e),{gridProps:v}}function wng(){return{rowGroupProps:{role:"rowgroup"}}}function Vng(g,e,I){let{node:i,isVirtualized:n,shouldSelectOnPressUp:C,onAction:r}=g,{actions:{onRowAction:o}}=e8.get(e),{itemProps:A,...s}=T2e({selectionManager:e.selectionManager,key:i.key,ref:I,isVirtualized:n,shouldSelectOnPressUp:C,onAction:o?()=>o(i.key):r,isDisabled:e.collection.size===0}),a=e.selectionManager.isSelected(i.key),l={role:"row","aria-selected":e.selectionManager.selectionMode!=="none"?a:void 0,"aria-disabled":s.isDisabled||void 0,...A};return n&&(l["aria-rowindex"]=i.index+1),{rowProps:l,...s}}function dTe(g,e,I){let{node:i,isVirtualized:n,focusMode:C="child",shouldSelectOnPressUp:r,onAction:o}=g,{direction:A}=Xm(),{keyboardDelegate:s,actions:{onCellAction:a}}=e8.get(e),l=Ie.useRef(null),c=()=>{let p=eo(I.current);if(C==="child"){if(I.current.contains(document.activeElement)&&I.current!==document.activeElement)return;let y=e.selectionManager.childFocusStrategy==="last"?qF(p):p.firstChild();if(y){tr(y);return}}(l.current!=null&&i.key!==l.current||!I.current.contains(document.activeElement))&&tr(I.current)},{itemProps:u,isPressed:d}=T2e({selectionManager:e.selectionManager,key:i.key,ref:I,isVirtualized:n,focus:c,shouldSelectOnPressUp:r,onAction:a?()=>a(i.key):o,isDisabled:e.collection.size===0}),f=bi(u,{role:"gridcell",onKeyDownCapture:p=>{if(!p.currentTarget.contains(p.target)||e.isKeyboardNavigationDisabled)return;let y=eo(I.current);switch(y.currentNode=document.activeElement,p.key){case"ArrowLeft":{let Z=A==="rtl"?y.nextNode():y.previousNode();if(C==="child"&&Z===I.current&&(Z=null),Z)p.preventDefault(),p.stopPropagation(),tr(Z),nc(Z,{containingElement:ic(I.current)});else{if(s.getKeyLeftOf(i.key)!==i.key)break;p.preventDefault(),p.stopPropagation(),C==="cell"&&A==="rtl"?(tr(I.current),nc(I.current,{containingElement:ic(I.current)})):(y.currentNode=I.current,Z=A==="rtl"?y.firstChild():qF(y),Z&&(tr(Z),nc(Z,{containingElement:ic(I.current)})))}break}case"ArrowRight":{let Z=A==="rtl"?y.previousNode():y.nextNode();if(C==="child"&&Z===I.current&&(Z=null),Z)p.preventDefault(),p.stopPropagation(),tr(Z),nc(Z,{containingElement:ic(I.current)});else{if(s.getKeyRightOf(i.key)!==i.key)break;p.preventDefault(),p.stopPropagation(),C==="cell"&&A==="ltr"?(tr(I.current),nc(I.current,{containingElement:ic(I.current)})):(y.currentNode=I.current,Z=A==="rtl"?qF(y):y.firstChild(),Z&&(tr(Z),nc(Z,{containingElement:ic(I.current)})))}break}case"ArrowUp":case"ArrowDown":!p.altKey&&I.current.contains(p.target)&&(p.stopPropagation(),p.preventDefault(),I.current.parentElement.dispatchEvent(new KeyboardEvent(p.nativeEvent.type,p.nativeEvent)));break}},onFocus:p=>{if(l.current=i.key,p.target!==I.current){L$()||e.selectionManager.setFocusedKey(i.key);return}requestAnimationFrame(()=>{C==="child"&&document.activeElement===I.current&&c()})}});var b;return n&&(f["aria-colindex"]=((b=i.colIndex)!==null&&b!==void 0?b:i.index)+1),r&&f.tabIndex!=null&&f.onPointerDown==null&&(f.onPointerDown=p=>{let y=p.currentTarget,Z=y.getAttribute("tabindex");y.removeAttribute("tabindex"),requestAnimationFrame(()=>{y.setAttribute("tabindex",Z)})}),{gridCellProps:f,isPressed:d}}function qF(g){let e,I;do I=g.lastChild(),I&&(e=I);while(I);return e}function Rng(g,e){let{key:I}=g,i=e.selectionManager,n=Jh(),C=!e.selectionManager.canSelectItem(I),r=e.selectionManager.isSelected(I),o=()=>i.select(I);const A=Gy(q$(SY));return{checkboxProps:{id:n,"aria-label":A.format("select"),isSelected:r,isDisabled:C,onChange:o}}}let Wng=!1;function aT(){return Wng}function t8(g){return g&&g.__esModule?g.default:g}const g8=new WeakMap;function pL(g){return typeof g=="string"?g.replace(/\s*/g,""):""+g}function Xng(g,e){let I=g8.get(g);if(!I)throw new Error("Unknown grid");return`${I}-${pL(e)}`}function hTe(g,e,I){let i=g8.get(g);if(!i)throw new Error("Unknown grid");return`${i}-${pL(e)}-${pL(I)}`}function mTe(g,e){return[...g.collection.rowHeaderColumnKeys].map(I=>hTe(g,e,I)).join(" ")}var wY={},fTe={};fTe={ascending:"تصاعدي",ascendingSort:g=>`ترتيب حسب العمود ${g.columnName} بترتيب تصاعدي`,columnSize:g=>`${g.value} بالبكسل`,descending:"تنازلي",descendingSort:g=>`ترتيب حسب العمود ${g.columnName} بترتيب تنازلي`,resizerDescription:"اضغط على مفتاح Enter لبدء تغيير الحجم",select:"تحديد",selectAll:"تحديد الكل",sortable:"عمود قابل للترتيب"};var pTe={};pTe={ascending:"възходящ",ascendingSort:g=>`сортирано по колона ${g.columnName} във възходящ ред`,columnSize:g=>`${g.value} пиксела`,descending:"низходящ",descendingSort:g=>`сортирано по колона ${g.columnName} в низходящ ред`,resizerDescription:"Натиснете „Enter“, за да започнете да преоразмерявате",select:"Изберете",selectAll:"Изберете всичко",sortable:"сортираща колона"};var bTe={};bTe={ascending:"vzestupně",ascendingSort:g=>`řazeno vzestupně podle sloupce ${g.columnName}`,columnSize:g=>`${g.value} pixelů`,descending:"sestupně",descendingSort:g=>`řazeno sestupně podle sloupce ${g.columnName}`,resizerDescription:"Stisknutím klávesy Enter začnete měnit velikost",select:"Vybrat",selectAll:"Vybrat vše",sortable:"sloupec s možností řazení"};var yTe={};yTe={ascending:"stigende",ascendingSort:g=>`sorteret efter kolonne ${g.columnName} i stigende rækkefølge`,columnSize:g=>`${g.value} pixels`,descending:"faldende",descendingSort:g=>`sorteret efter kolonne ${g.columnName} i faldende rækkefølge`,resizerDescription:"Tryk på Enter for at ændre størrelse",select:"Vælg",selectAll:"Vælg alle",sortable:"sorterbar kolonne"};var ZTe={};ZTe={ascending:"aufsteigend",ascendingSort:g=>`sortiert nach Spalte ${g.columnName} in aufsteigender Reihenfolge`,columnSize:g=>`${g.value} Pixel`,descending:"absteigend",descendingSort:g=>`sortiert nach Spalte ${g.columnName} in absteigender Reihenfolge`,resizerDescription:"Eingabetaste zum Starten der Größenänderung drücken",select:"Auswählen",selectAll:"Alles auswählen",sortable:"sortierbare Spalte"};var GTe={};GTe={ascending:"αύξουσα",ascendingSort:g=>`διαλογή ανά στήλη ${g.columnName} σε αύξουσα σειρά`,columnSize:g=>`${g.value} pixel`,descending:"φθίνουσα",descendingSort:g=>`διαλογή ανά στήλη ${g.columnName} σε φθίνουσα σειρά`,resizerDescription:"Πατήστε Enter για έναρξη της αλλαγής μεγέθους",select:"Επιλογή",selectAll:"Επιλογή όλων",sortable:"Στήλη διαλογής"};var BTe={};BTe={select:"Select",selectAll:"Select All",sortable:"sortable column",ascending:"ascending",descending:"descending",ascendingSort:g=>`sorted by column ${g.columnName} in ascending order`,descendingSort:g=>`sorted by column ${g.columnName} in descending order`,columnSize:g=>`${g.value} pixels`,resizerDescription:"Press Enter to start resizing"};var vTe={};vTe={ascending:"de subida",ascendingSort:g=>`ordenado por columna ${g.columnName} en orden de subida`,columnSize:g=>`${g.value} píxeles`,descending:"de bajada",descendingSort:g=>`ordenado por columna ${g.columnName} en orden de bajada`,resizerDescription:"Pulse Intro para empezar a redimensionar",select:"Seleccionar",selectAll:"Seleccionar todos",sortable:"columna ordenable"};var STe={};STe={ascending:"tõusev järjestus",ascendingSort:g=>`sorditud veeru järgi ${g.columnName} tõusvas järjestuses`,columnSize:g=>`${g.value} pikslit`,descending:"laskuv järjestus",descendingSort:g=>`sorditud veeru järgi ${g.columnName} laskuvas järjestuses`,resizerDescription:"Suuruse muutmise alustamiseks vajutage klahvi Enter",select:"Vali",selectAll:"Vali kõik",sortable:"sorditav veerg"};var wTe={};wTe={ascending:"nouseva",ascendingSort:g=>`lajiteltu sarakkeen ${g.columnName} mukaan nousevassa järjestyksessä`,columnSize:g=>`${g.value} pikseliä`,descending:"laskeva",descendingSort:g=>`lajiteltu sarakkeen ${g.columnName} mukaan laskevassa järjestyksessä`,resizerDescription:"Aloita koon muutos painamalla Enter-näppäintä",select:"Valitse",selectAll:"Valitse kaikki",sortable:"lajiteltava sarake"};var VTe={};VTe={ascending:"croissant",ascendingSort:g=>`trié en fonction de la colonne ${g.columnName} par ordre croissant`,columnSize:g=>`${g.value} pixels`,descending:"décroissant",descendingSort:g=>`trié en fonction de la colonne ${g.columnName} par ordre décroissant`,resizerDescription:"Appuyez sur Entrée pour commencer le redimensionnement.",select:"Sélectionner",selectAll:"Sélectionner tout",sortable:"colonne triable"};var RTe={};RTe={ascending:"עולה",ascendingSort:g=>`מוין לפי עמודה ${g.columnName} בסדר עולה`,columnSize:g=>`${g.value} פיקסלים`,descending:"יורד",descendingSort:g=>`מוין לפי עמודה ${g.columnName} בסדר יורד`,resizerDescription:"הקש Enter כדי לשנות את הגודל",select:"בחר",selectAll:"בחר הכול",sortable:"עמודה שניתן למיין"};var WTe={};WTe={ascending:"rastući",ascendingSort:g=>`razvrstano po stupcima ${g.columnName} rastućem redoslijedom`,columnSize:g=>`${g.value} piksela`,descending:"padajući",descendingSort:g=>`razvrstano po stupcima ${g.columnName} padajućim redoslijedom`,resizerDescription:"Pritisnite Enter da biste započeli promenu veličine",select:"Odaberite",selectAll:"Odaberite sve",sortable:"stupac koji se može razvrstati"};var XTe={};XTe={ascending:"növekvő",ascendingSort:g=>`rendezve a(z) ${g.columnName} oszlop szerint, növekvő sorrendben`,columnSize:g=>`${g.value} képpont`,descending:"csökkenő",descendingSort:g=>`rendezve a(z) ${g.columnName} oszlop szerint, csökkenő sorrendben`,resizerDescription:"Nyomja le az Enter billentyűt az átméretezés megkezdéséhez",select:"Kijelölés",selectAll:"Összes kijelölése",sortable:"rendezendő oszlop"};var HTe={};HTe={ascending:"crescente",ascendingSort:g=>`in ordine crescente in base alla colonna ${g.columnName}`,columnSize:g=>`${g.value} pixel`,descending:"decrescente",descendingSort:g=>`in ordine decrescente in base alla colonna ${g.columnName}`,resizerDescription:"Premi Invio per iniziare a ridimensionare",select:"Seleziona",selectAll:"Seleziona tutto",sortable:"colonna ordinabile"};var TTe={};TTe={ascending:"昇順",ascendingSort:g=>`列 ${g.columnName} を昇順で並べ替え`,columnSize:g=>`${g.value} ピクセル`,descending:"降順",descendingSort:g=>`列 ${g.columnName} を降順で並べ替え`,resizerDescription:"Enter キーを押してサイズ変更を開始",select:"選択",selectAll:"すべて選択",sortable:"並べ替え可能な列"};var NTe={};NTe={ascending:"오름차순",ascendingSort:g=>`${g.columnName} 열을 기준으로 오름차순으로 정렬됨`,columnSize:g=>`${g.value} 픽셀`,descending:"내림차순",descendingSort:g=>`${g.columnName} 열을 기준으로 내림차순으로 정렬됨`,resizerDescription:"크기 조정을 시작하려면 Enter를 누르세요.",select:"선택",selectAll:"모두 선택",sortable:"정렬 가능한 열"};var kTe={};kTe={ascending:"didėjančia tvarka",ascendingSort:g=>`surikiuota pagal stulpelį ${g.columnName} didėjančia tvarka`,columnSize:g=>`${g.value} piks.`,descending:"mažėjančia tvarka",descendingSort:g=>`surikiuota pagal stulpelį ${g.columnName} mažėjančia tvarka`,resizerDescription:"Paspauskite „Enter“, kad pradėtumėte keisti dydį",select:"Pasirinkti",selectAll:"Pasirinkti viską",sortable:"rikiuojamas stulpelis"};var YTe={};YTe={ascending:"augošā secībā",ascendingSort:g=>`kārtots pēc kolonnas ${g.columnName} augošā secībā`,columnSize:g=>`${g.value} pikseļi`,descending:"dilstošā secībā",descendingSort:g=>`kārtots pēc kolonnas ${g.columnName} dilstošā secībā`,resizerDescription:"Nospiediet Enter, lai sāktu izmēru mainīšanu",select:"Atlasīt",selectAll:"Atlasīt visu",sortable:"kārtojamā kolonna"};var KTe={};KTe={ascending:"stigende",ascendingSort:g=>`sortert etter kolonne ${g.columnName} i stigende rekkefølge`,columnSize:g=>`${g.value} piksler`,descending:"synkende",descendingSort:g=>`sortert etter kolonne ${g.columnName} i synkende rekkefølge`,resizerDescription:"Trykk på Enter for å starte størrelsesendring",select:"Velg",selectAll:"Velg alle",sortable:"kolonne som kan sorteres"};var xTe={};xTe={ascending:"oplopend",ascendingSort:g=>`gesorteerd in oplopende volgorde in kolom ${g.columnName}`,columnSize:g=>`${g.value} pixels`,descending:"aflopend",descendingSort:g=>`gesorteerd in aflopende volgorde in kolom ${g.columnName}`,resizerDescription:"Druk op Enter om het formaat te wijzigen",select:"Selecteren",selectAll:"Alles selecteren",sortable:"sorteerbare kolom"};var DTe={};DTe={ascending:"rosnąco",ascendingSort:g=>`posortowano według kolumny ${g.columnName} w porządku rosnącym`,columnSize:g=>`Liczba pikseli: ${g.value}`,descending:"malejąco",descendingSort:g=>`posortowano według kolumny ${g.columnName} w porządku malejącym`,resizerDescription:"Naciśnij Enter, aby rozpocząć zmienianie rozmiaru",select:"Zaznacz",selectAll:"Zaznacz wszystko",sortable:"kolumna z możliwością sortowania"};var FTe={};FTe={ascending:"crescente",ascendingSort:g=>`classificado pela coluna ${g.columnName} em ordem crescente`,columnSize:g=>`${g.value} pixels`,descending:"decrescente",descendingSort:g=>`classificado pela coluna ${g.columnName} em ordem decrescente`,resizerDescription:"Pressione Enter para começar a redimensionar",select:"Selecionar",selectAll:"Selecionar tudo",sortable:"coluna classificável"};var ETe={};ETe={ascending:"ascendente",ascendingSort:g=>`Ordenar por coluna ${g.columnName} em ordem ascendente`,columnSize:g=>`${g.value} pixels`,descending:"descendente",descendingSort:g=>`Ordenar por coluna ${g.columnName} em ordem descendente`,resizerDescription:"Prima Enter para iniciar o redimensionamento",select:"Selecionar",selectAll:"Selecionar tudo",sortable:"Coluna ordenável"};var MTe={};MTe={ascending:"crescătoare",ascendingSort:g=>`sortate după coloana ${g.columnName} în ordine crescătoare`,columnSize:g=>`${g.value} pixeli`,descending:"descrescătoare",descendingSort:g=>`sortate după coloana ${g.columnName} în ordine descrescătoare`,resizerDescription:"Apăsați pe Enter pentru a începe redimensionarea",select:"Selectare",selectAll:"Selectare totală",sortable:"coloană sortabilă"};var zTe={};zTe={ascending:"возрастание",ascendingSort:g=>`сортировать столбец ${g.columnName} в порядке возрастания`,columnSize:g=>`${g.value} пикс.`,descending:"убывание",descendingSort:g=>`сортировать столбец ${g.columnName} в порядке убывания`,resizerDescription:"Нажмите клавишу Enter для начала изменения размеров",select:"Выбрать",selectAll:"Выбрать все",sortable:"сортируемый столбец"};var PTe={};PTe={ascending:"vzostupne",ascendingSort:g=>`zoradené zostupne podľa stĺpca ${g.columnName}`,columnSize:g=>`Počet pixelov: ${g.value}`,descending:"zostupne",descendingSort:g=>`zoradené zostupne podľa stĺpca ${g.columnName}`,resizerDescription:"Stlačením klávesu Enter začnete zmenu veľkosti",select:"Vybrať",selectAll:"Vybrať všetko",sortable:"zoraditeľný stĺpec"};var JTe={};JTe={ascending:"naraščajoče",ascendingSort:g=>`razvrščeno po stolpcu ${g.columnName} v naraščajočem vrstnem redu`,columnSize:g=>`${g.value} slikovnih pik`,descending:"padajoče",descendingSort:g=>`razvrščeno po stolpcu ${g.columnName} v padajočem vrstnem redu`,resizerDescription:"Pritisnite tipko Enter da začnete spreminjati velikost",select:"Izberite",selectAll:"Izberite vse",sortable:"razvrstljivi stolpec"};var OTe={};OTe={ascending:"rastući",ascendingSort:g=>`sortirano po kolonama ${g.columnName} rastućim redosledom`,columnSize:g=>`${g.value} piksela`,descending:"padajući",descendingSort:g=>`sortirano po kolonama ${g.columnName} padajućim redosledom`,resizerDescription:"Pritisnite Enter da biste započeli promenu veličine",select:"Izaberite",selectAll:"Izaberite sve",sortable:"kolona koja se može sortirati"};var LTe={};LTe={ascending:"stigande",ascendingSort:g=>`sorterat på kolumn ${g.columnName} i stigande ordning`,columnSize:g=>`${g.value} pixlar`,descending:"fallande",descendingSort:g=>`sorterat på kolumn ${g.columnName} i fallande ordning`,resizerDescription:"Tryck på Retur för att börja ändra storlek",select:"Markera",selectAll:"Markera allt",sortable:"sorterbar kolumn"};var _Te={};_Te={ascending:"artan sırada",ascendingSort:g=>`${g.columnName} sütuna göre artan düzende sırala`,columnSize:g=>`${g.value} piksel`,descending:"azalan sırada",descendingSort:g=>`${g.columnName} sütuna göre azalan düzende sırala`,resizerDescription:"Yeniden boyutlandırmak için Enter'a basın",select:"Seç",selectAll:"Tümünü Seç",sortable:"Sıralanabilir sütun"};var UTe={};UTe={ascending:"висхідний",ascendingSort:g=>`відсортовано за стовпцем ${g.columnName} у висхідному порядку`,columnSize:g=>`${g.value} пікс.`,descending:"низхідний",descendingSort:g=>`відсортовано за стовпцем ${g.columnName} у низхідному порядку`,resizerDescription:"Натисніть Enter, щоб почати зміну розміру",select:"Вибрати",selectAll:"Вибрати все",sortable:"сортувальний стовпець"};var QTe={};QTe={ascending:"升序",ascendingSort:g=>`按列 ${g.columnName} 升序排序`,columnSize:g=>`${g.value} 像素`,descending:"降序",descendingSort:g=>`按列 ${g.columnName} 降序排序`,resizerDescription:"按“输入”键开始调整大小。",select:"选择",selectAll:"全选",sortable:"可排序的列"};var jTe={};jTe={ascending:"遞增",ascendingSort:g=>`已依據「${g.columnName}」欄遞增排序`,columnSize:g=>`${g.value} 像素`,descending:"遞減",descendingSort:g=>`已依據「${g.columnName}」欄遞減排序`,resizerDescription:"按 Enter 鍵以開始調整大小",select:"選取",selectAll:"全選",sortable:"可排序的欄"};wY={"ar-AE":fTe,"bg-BG":pTe,"cs-CZ":bTe,"da-DK":yTe,"de-DE":ZTe,"el-GR":GTe,"en-US":BTe,"es-ES":vTe,"et-EE":STe,"fi-FI":wTe,"fr-FR":VTe,"he-IL":RTe,"hr-HR":WTe,"hu-HU":XTe,"it-IT":HTe,"ja-JP":TTe,"ko-KR":NTe,"lt-LT":kTe,"lv-LV":YTe,"nb-NO":KTe,"nl-NL":xTe,"pl-PL":DTe,"pt-BR":FTe,"pt-PT":ETe,"ro-RO":MTe,"ru-RU":zTe,"sk-SK":PTe,"sl-SI":JTe,"sr-SP":OTe,"sv-SE":LTe,"tr-TR":_Te,"uk-UA":UTe,"zh-CN":QTe,"zh-TW":jTe};class Hng extends N2e{isCell(e){return e.type==="cell"||e.type==="rowheader"||e.type==="column"}getKeyBelow(e){let I=this.collection.getItem(e);if(I){if(I.type==="column"){let i=us(Gi(I,this.collection));if(i)return i.key;let n=this.getFirstKey();if(n==null)return;let C=this.collection.getItem(n);return Cc(Gi(C,this.collection),I.index).key}return super.getKeyBelow(e)}}getKeyAbove(e){let I=this.collection.getItem(e);if(!I)return;if(I.type==="column"){let n=this.collection.getItem(I.parentKey);return n&&n.type==="column"?n.key:void 0}let i=super.getKeyAbove(e);return i!=null&&this.collection.getItem(i).type!=="headerrow"?i:this.isCell(I)?this.collection.columns[I.index].key:this.collection.columns[0].key}findNextColumnKey(e){let I=this.findNextKey(e.key,n=>n.type==="column");if(I!=null)return I;let i=this.collection.headerRows[e.level];for(let n of Gi(i,this.collection))if(n.type==="column")return n.key}findPreviousColumnKey(e){let I=this.findPreviousKey(e.key,C=>C.type==="column");if(I!=null)return I;let i=this.collection.headerRows[e.level],n=[...Gi(i,this.collection)];for(let C=n.length-1;C>=0;C--){let r=n[C];if(r.type==="column")return r.key}}getKeyRightOf(e){let I=this.collection.getItem(e);if(I)return I.type==="column"?this.direction==="rtl"?this.findPreviousColumnKey(I):this.findNextColumnKey(I):super.getKeyRightOf(e)}getKeyLeftOf(e){let I=this.collection.getItem(e);if(I)return I.type==="column"?this.direction==="rtl"?this.findNextColumnKey(I):this.findPreviousColumnKey(I):super.getKeyLeftOf(e)}getKeyForSearch(e,I){if(!this.collator)return null;let i=this.collection,n=I??this.getFirstKey();if(n==null)return null;let C=i.getItem(n);C.type==="cell"&&(n=C.parentKey);let r=!1;for(;n!=null;){let o=i.getItem(n);for(let A of Gi(o,this.collection)){let s=i.columns[A.index];if(i.rowHeaderColumnKeys.has(s.key)&&A.textValue){let a=A.textValue.slice(0,e.length);if(this.collator.compare(a,e)===0)return(I!=null?i.getItem(I):C).type==="cell"?A.key:o.key}}n=this.getKeyBelow(n),n==null&&!r&&(n=this.getFirstKey(),r=!0)}return null}}function Tng(g,e,I){let{keyboardDelegate:i,isVirtualized:n,layout:C}=g,r=V2e({usage:"search",sensitivity:"base"}),{direction:o}=Xm(),A=e.selectionManager.disabledBehavior,s=Ie.useMemo(()=>i||new Hng({collection:e.collection,disabledKeys:A==="selection"?new Set:e.disabledKeys,ref:I,direction:o,collator:r,layout:C}),[i,e.collection,e.disabledKeys,A,I,o,r,C]),a=Jh(g.id);g8.set(e,a);let{gridProps:l}=Sng({...g,id:a,keyboardDelegate:s},e,I);n&&(l["aria-rowcount"]=e.collection.size+e.collection.headerRows.length),aT()&&"expandedKeys"in e&&(l.role="treegrid");let{column:c,direction:u}=e.sortDescriptor||{},d=Gy(t8(wY)),h=Ie.useMemo(()=>{var f;let b=(f=e.collection.columns.find(p=>p.key===c))===null||f===void 0?void 0:f.textValue;return u&&c?d.format(`${u}Sort`,{columnName:b}):void 0},[u,c,e.collection.columns]),m=GY(h);return d2e(()=>{W2e(h,"assertive",500)},[h]),{gridProps:bi(l,m,{"aria-describedby":[m["aria-describedby"],l["aria-describedby"]].filter(Boolean).join(" ")})}}function Nng(g,e,I){var i,n;let{node:C}=g,r=C.props.allowsSorting,{gridCellProps:o}=dTe({...g,focusMode:"child"},e,I),A=C.props.isSelectionCell&&e.selectionManager.selectionMode==="single",{pressProps:s}=J$({isDisabled:!r||A,onPress(){e.sort(C.key)},ref:I}),{focusableProps:a}=S2e({},I),l=null,c=((i=e.sortDescriptor)===null||i===void 0?void 0:i.column)===C.key,u=(n=e.sortDescriptor)===null||n===void 0?void 0:n.direction;C.props.allowsSorting&&!iT()&&(l=c?u:"none");let d=Gy(t8(wY)),h;r&&(h=`${d.format("sortable")}`,c&&u&&iT()&&(h=`${h}, ${d.format(u)}`));let m=GY(h),f=e.collection.size===0;return Ie.useEffect(()=>{f&&e.selectionManager.focusedKey===C.key&&e.selectionManager.setFocusedKey(null)},[f,e.selectionManager,C.key]),{columnHeaderProps:{...bi(o,s,a,m,f&&{tabIndex:-1}),role:"columnheader",id:Xng(e,C.key),"aria-colspan":C.colspan&&C.colspan>1?C.colspan:null,"aria-sort":l}}}const Xce={expand:{ltr:"ArrowRight",rtl:"ArrowLeft"},collapse:{ltr:"ArrowLeft",rtl:"ArrowRight"}};function kng(g,e,I){let{node:i,isVirtualized:n}=g,{rowProps:C,...r}=Vng(g,e,I),{direction:o}=Xm();n&&!(aT()&&"expandedKeys"in e)?C["aria-rowindex"]=i.index+1+e.collection.headerRows.length:delete C["aria-rowindex"];let A={};if(aT()&&"expandedKeys"in e){let u=e.keyMap.get(i.key);if(u!=null){var s,a,l;let d=((s=u.props)===null||s===void 0?void 0:s.UNSTABLE_childItems)||((l=u.props)===null||l===void 0||(a=l.children)===null||a===void 0?void 0:a.length)>e.userColumnCount;A={onKeyDown:h=>{(h.key===Xce.expand[o]&&e.selectionManager.focusedKey===u.key&&d&&e.expandedKeys!=="all"&&!e.expandedKeys.has(u.key)||h.key===Xce.collapse[o]&&e.selectionManager.focusedKey===u.key&&d&&(e.expandedKeys==="all"||e.expandedKeys.has(u.key)))&&(e.toggleKey(u.key),h.stopPropagation())},"aria-expanded":d?e.expandedKeys==="all"||e.expandedKeys.has(i.key):void 0,"aria-level":u.level,"aria-posinset":u.indexOfType+1,"aria-setsize":u.level>1?Nc(e.keyMap.get(u==null?void 0:u.parentKey).childNodes).indexOfType+1:Nc(e.keyMap.get(e.collection.body.key).childNodes).indexOfType+1}}}let c=r.hasAction?Iig(i.props):{};return{rowProps:{...bi(C,A,c),"aria-labelledby":mTe(e,i.key)},...r}}function Yng(g,e,I){let{node:i,isVirtualized:n}=g,C={role:"row"};return n&&!(aT()&&"expandedKeys"in e)&&(C["aria-rowindex"]=i.index+1),{rowProps:C}}function Kng(g,e,I){let{gridCellProps:i,isPressed:n}=dTe(g,e,I),C=g.node.column.key;return e.collection.rowHeaderColumnKeys.has(C)&&(i.role="rowheader",i.id=hTe(e,g.node.parentKey,C)),{gridCellProps:i,isPressed:n}}function xng(g,e){let{key:I}=g;const{checkboxProps:i}=Rng(g,e);return{checkboxProps:{...i,"aria-labelledby":`${i.id} ${mTe(e,I)}`}}}function Dng(g){let{isEmpty:e,isSelectAll:I,selectionMode:i}=g.selectionManager;return{checkboxProps:{"aria-label":Gy(t8(wY)).format(i==="single"?"select":"selectAll"),isSelected:I,isDisabled:i!=="multiple"||g.collection.size===0,isIndeterminate:!e&&!I,onChange:()=>g.selectionManager.toggleSelectAll()}}}function $Te(){return wng()}var qTe={exports:{}},eNe={};/** + `):"",this.name="UnsubscriptionError",this.errors=I}});function qse(e,g){if(e){var I=e.indexOf(g);0<=I&&e.splice(I,1)}}var i$=function(){function e(g){this.initialTeardown=g,this.closed=!1,this._parentage=null,this._finalizers=null}return e.prototype.unsubscribe=function(){var g,I,i,n,C;if(!this.closed){this.closed=!0;var r=this._parentage;if(r)if(this._parentage=null,Array.isArray(r))try{for(var o=$se(r),A=o.next();!A.done;A=o.next()){var s=A.value;s.remove(this)}}catch(h){g={error:h}}finally{try{A&&!A.done&&(I=o.return)&&I.call(o)}finally{if(g)throw g.error}}else r.remove(this);var a=this.initialTeardown;if(oa(a))try{a()}catch(h){C=h instanceof Qx?h.errors:[h]}var l=this._finalizers;if(l){this._finalizers=null;try{for(var c=$se(l),u=c.next();!u.done;u=c.next()){var d=u.value;try{ele(d)}catch(h){C=C??[],h instanceof Qx?C=yO(yO([],bO(C)),bO(h.errors)):C.push(h)}}}catch(h){i={error:h}}finally{try{u&&!u.done&&(n=c.return)&&n.call(c)}finally{if(i)throw i.error}}}if(C)throw new Qx(C)}},e.prototype.add=function(g){var I;if(g&&g!==this)if(this.closed)ele(g);else{if(g instanceof e){if(g.closed||g._hasParent(this))return;g._addParent(this)}(this._finalizers=(I=this._finalizers)!==null&&I!==void 0?I:[]).push(g)}},e.prototype._hasParent=function(g){var I=this._parentage;return I===g||Array.isArray(I)&&I.includes(g)},e.prototype._addParent=function(g){var I=this._parentage;this._parentage=Array.isArray(I)?(I.push(g),I):I?[I,g]:g},e.prototype._removeParent=function(g){var I=this._parentage;I===g?this._parentage=null:Array.isArray(I)&&qse(I,g)},e.prototype.remove=function(g){var I=this._finalizers;I&&qse(I,g),g instanceof e&&g._removeParent(this)},e.EMPTY=function(){var g=new e;return g.closed=!0,g}(),e}();i$.EMPTY;function T9e(e){return e instanceof i$||e&&"closed"in e&&oa(e.remove)&&oa(e.add)&&oa(e.unsubscribe)}function ele(e){oa(e)?e():e.unsubscribe()}var N9e={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1},oIg={setTimeout:function(e,g){for(var I=[],i=2;i=2,!1,!0))}var VIg=function(e,g){return e.push(g),e};function RIg(){return k9e(function(e,g){wIg(VIg,[])(e).subscribe(g)})}const Ile=-2003829722,$x=-2021002517;function WIg(e){return new TextDecoder().decode(e)}function ile(e){const g=e?"big":"little",I=new Hg().endianess(g).int32("magic").uint16("version").uint16("numZoomLevels").uint64("chromTreeOffset").uint64("unzoomedDataOffset").uint64("unzoomedIndexOffset").uint16("fieldCount").uint16("definedFieldCount").uint64("asOffset").uint64("totalSummaryOffset").uint32("uncompressBufSize").uint64("extHeaderOffset").array("zoomLevels",{length:"numZoomLevels",type:new Hg().endianess(g).uint32("reductionLevel").uint32("reserved").uint64("dataOffset").uint64("indexOffset")}),i=new Hg().endianess(g).uint64("basesCovered").doublele("scoreMin").doublele("scoreMax").doublele("scoreSum").doublele("scoreSumSquares"),n=new Hg().endianess(g).uint32("magic").uint32("blockSize").uint32("keySize").uint32("valSize").uint64("itemCount"),C=new Hg().endianess(g).uint8("isLeafNode").skip(1).uint16("cnt").saveOffset("offset");return{chromTreeParser:n,totalSummaryParser:i,headerParser:I,isLeafNode:C}}class XIg{getHeader(g={}){const I="aborted"in g?{signal:g}:g;return this.headerP||(this.headerP=this._getHeader(I).catch(i=>{throw this.headerP=void 0,i})),this.headerP}constructor(g={}){const{filehandle:I,renameRefSeqs:i=r=>r,path:n,url:C}=g;if(this.renameRefSeqs=i,I)this.bbi=I;else if(C)this.bbi=new lpe(C);else if(n)this.bbi=new hhe(n);else throw new Error("no file given")}async _getHeader(g){const I=await this._getMainHeader(g),i=await this._readChromTree(I,g);return{...I,...i}}async _getMainHeader(g,I=2e3){const{buffer:i}=await this.bbi.read(Jd.Buffer.alloc(I),0,I,0,g),n=this._isBigEndian(i),C=ile(n),r=C.headerParser.parse(i),{magic:o,asOffset:A,totalSummaryOffset:s}=r;if(r.fileType=o===$x?"bigbed":"bigwig",A>I||s>I)return this._getMainHeader(g,I*2);if(A){const a=Number(r.asOffset);r.autoSql=WIg(i.subarray(a,i.indexOf(0,a)))}if(r.totalSummaryOffset>I)return this._getMainHeader(g,I*2);if(r.totalSummaryOffset){const a=i.subarray(Number(r.totalSummaryOffset)),l=C.totalSummaryParser.parse(a);r.totalSummary={...l,basesCovered:Number(l.basesCovered)}}return{...r,isBigEndian:n}}_isBigEndian(g){let I=g.readInt32LE(0);if(I===Ile||I===$x)return!1;if(I=g.readInt32BE(0),I===Ile||I===$x)return!0;throw new Error("not a BigWig/BigBed file")}async _readChromTree(g,I){const i=g.isBigEndian,n=i?"big":"little",C=[],r={};let o=Number(g.unzoomedDataOffset);const A=Number(g.chromTreeOffset);for(;o%4!==0;)o+=1;const s=o-A,{buffer:a}=await this.bbi.read(Jd.Buffer.alloc(s),0,s,Number(A),I),l=ile(i),{keySize:c}=l.chromTreeParser.parse(a),u=new Hg().endianess(n).string("key",{stripNull:!0,length:c}).uint32("refId").uint32("refSize").saveOffset("offset"),d=new Hg().endianess(n).skip(c).uint64("childOffset").saveOffset("offset"),h=32,m=async f=>{let b=f;if(b>=a.length)throw new Error("reading beyond end of buffer");const p=l.isLeafNode.parse(a.subarray(b)),{isLeafNode:y,cnt:Z}=p;if(b+=p.offset,y)for(let B=0;B0,r)}async getFeatureStream(g,I,i,n={scale:1}){await this.getHeader(n);const C=this.renameRefSeqs(g);let r;if(n.basesPerSpan?r=await this.getView(1/n.basesPerSpan,n):n.scale?r=await this.getView(n.scale,n):r=await this.getView(1,n),!r)throw new Error("unable to get block view for data");return new fIg(o=>{r.readWigData(C,I,i,o,n)})}async getFeatures(g,I,i,n={scale:1}){const C=await this.getFeatureStream(g,I,i,n);return(await BIg(C.pipe(RIg()))).flat()}}class HIg extends XIg{async getView(g,I){const{zoomLevels:i,refsByName:n,fileSize:C,isBigEndian:r,uncompressBufSize:o}=await this.getHeader(I),A=1/g;let s=i.length;C||(s-=1);for(let a=s;a>=0;a-=1){const l=i[a];if(l&&l.reductionLevel<=2*A){const c=Number(l.indexOffset);return new X9e(this.bbi,n,c,r,o>0,"summary")}}return this.getUnzoomedView(I)}}function Y9e(e,g){if(!new.target)throw new Error('Uncaught TypeError: Class constructor cannot be invoked without "new"');const I=class{constructor(){Ct(this,"dataConfig"),Ct(this,"bwFileHeader"),Ct(this,"bwFile"),Ct(this,"TILE_SIZE"),Ct(this,"errorTxt"),Ct(this,"dataPromises"),Ct(this,"chromSizes"),Ct(this,"assembly"),Ct(this,"tilesetInfoLoading"),this.dataConfig=g,this.assembly=this.dataConfig.assembly,this.bwFileHeader=null,this.bwFile=null,this.TILE_SIZE=1024,this.errorTxt="",this.dataPromises=[];const n=pI(this.assembly).size,C=[],r={};let o=0;Object.keys(pI(this.assembly).size).forEach((A,s)=>{const a={id:s,chr:A,pos:o};C.push(a),r[A]=a,o+=pI(this.assembly).size[A]}),this.chromSizes={chrToAbs:(A,s)=>this.chromSizes.chrPositions[A].pos+s,cumPositions:C,chrPositions:r,totalLength:o,chromLengths:n},this.dataPromises.push(this.loadBBI(g))}async loadBBI(n){return n.url?(this.bwFile=new HIg({filehandle:new jpe(n.url,{overrides:n.urlFetchOptions})}),this.bwFile.getHeader().then(C=>{this.bwFileHeader=C})):(console.error('Please enter a "url" field to the data config'),null)}tilesetInfo(n){return this.tilesetInfoLoading=!0,Promise.all(this.dataPromises).then(()=>{this.tilesetInfoLoading=!1;const C=this.chromSizes.totalLength,r={tile_size:this.TILE_SIZE,max_zoom:Math.ceil(Math.log(C/this.TILE_SIZE)/Math.log(2)),max_width:2**Math.ceil(Math.log(C)/Math.log(2)),min_pos:[0],max_pos:[C]};return n&&n(r),r}).catch(C=>(this.tilesetInfoLoading=!1,console.error(C),n&&n({error:`Error parsing bigwig: ${C}`}),null))}fetchTilesDebounced(n,C){const r={},o=[],A=[];for(const s of C){const a=s.split("."),l=parseInt(a[0],10),c=parseInt(a[1],10);if(Number.isNaN(c)||Number.isNaN(l)){console.warn("Invalid tile zoom or position:",l,c);continue}o.push(s),A.push(this.tile(l,c))}return Promise.all(A).then(s=>{for(let a=0;a{const p=b.chr,y=b.pos,Z=b.pos+m[p];let B,G;if(y<=l&&lZ)B=l-y,G=Z-y,A.push(this.bwFile.getFeatures(p,B,G,{scale:1/u}).then(v=>(v.forEach(w=>{w.startAbs=e.utils.chrToAbs(p,w.start,this.chromSizes),w.endAbs=e.utils.chrToAbs(p,w.end,this.chromSizes)}),v))),l=Z;else{if(B=Math.floor(l-y),G=Math.ceil(c-y),!this.bwFile)return;A.push(this.bwFile.getFeatures(p,B,G,{scale:1/u}).then(v=>(v.forEach(w=>{w.startAbs=e.utils.chrToAbs(p,w.start,this.chromSizes),w.endAbs=e.utils.chrToAbs(p,w.end,this.chromSizes)}),v)));return}}),Promise.all(A).then(b=>{const p=b.flat(),y=[];for(let B=0;B{if(Bc)return;const v=p.filter(w=>B>=w.startAbs&&Bw.score);y[G]=v.length>0?v[0]:null});const Z=new e.utils.DenseDataExtrema1D(y);return s.min_value=Math.min(...y),s.max_value=Math.max(...y),s.dense=y,s.denseDataExtrema=Z,s.minNonZero=Z.minNonZeroInTile,s.maxNonZero=Z.maxNonZeroInTile,s})}determineScale(n,C){const r=[1],o=C-n;if(!this.bwFileHeader)throw Error("no bigwig header");this.bwFileHeader.zoomLevels.forEach(s=>{r.push(s.reductionLevel)});let A;return r.forEach(s=>{if(A)return;o/s<=this.TILE_SIZE*20&&(A=s)}),A||r.slice(-1)[0]}};return new I}Y9e.config={type:"bigwig"};function K9e(e,g){const{field:I,not:i}=e;let n=Array.from(g);if(dje(e)){const{oneOf:C}=e;n=n.filter(r=>i?C.indexOf(r[I])===-1:C.indexOf(r[I])!==-1)}else if(hje(e)){const{inRange:C}=e;n=n.filter(r=>{const o=+r[I];return i?!(C[0]<=o&&o<=C[1]):C[0]<=o&&o<=C[1]})}else if(mje(e)){const{include:C}=e;n=n.filter(r=>i?`${r[I]}`.includes(C):!`${r[I]}`.includes(C))}return n}function TIg(e,g){const{fields:I,separator:i,newField:n}=e;let C=Array.from(g);return C=C.map(r=>{const o=I.map(A=>r[A]);return r[n]=o.join(i),r}),C}function NIg(e,g){const{field:I,replace:i,newField:n}=e;let C=Array.from(g);return C=C.map(r=>(r[n]=r[I],i.forEach(o=>{const{from:A,to:s}=o;r[n]=r[n].toString().replaceAll(A,s)}),r)),C}function kIg(e,g){const{field:I,base:i,newField:n}=e;let C=Array.from(g);return C=C.map(r=>(+r[I]&&(i==="e"?r[n??I]=Math.log(+r[I]):r[n??I]=Math.log(+r[I])/Math.log(i??10)),r)),C}function YIg(e,g){const{startField:I,endField:i,newField:n}=e,C=Array.from(g);return C.forEach(r=>{const o=r[I],A=r[i];!o||!A||(r[n]=Math.abs(+A-+o))}),C}function KIg(e,g){const{firstBp:I,secondBp:i,newField:n}=e,C=Array.from(g),[r,o,A,s,a]=["DUP","TRA","DEL","t2tINV","h2hINV"];return C.forEach(l=>{const c=l[I.chrField],u=l[i.chrField];if(c!==u){l[n]=o;return}let d=l[I.posField],h=l[i.posField],m=l[I.strandField],f=l[i.strandField];if(d>h){const b=d,p=m;d=h,m=f,h=b,f=p}switch(`${m}${f}`){case"+-":l[n]=A;break;case"--":l[n]=s;break;case"++":l[n]=a;break;case"-+":l[n]=r;break;default:l[n]="unknown"}}),C}function DIg(e,g,I){const{startField:i,endField:n,newField:C,groupField:r}=e,o={},A=1;return g.forEach(a=>{const l=I(a[i]),c=I(a[n]),u=r?a[r]:"__NO_GROUP__",d=Math.floor(l);for(let h=d;h{const[l,c]=a;return Object.entries(c).map(u=>{const[d,h]=u;return{[i]:I.invert(+d),[n]:I.invert(+d+A),[C??"coverage"]:h,[r??"group"]:l}})})}function xIg(e,g,I){const{boundingBox:i,method:n,newField:C}=e,{startField:r,endField:o,groupField:A}=i;let s=0;i.padding&&I&&!i.isPaddingBP?s=Math.abs(I.invert(i.padding)-I.invert(0)):i.padding&&i.isPaddingBP&&(s=i.padding);const a=Array.from(g);if(a&&a.length>0&&(!Object.keys(a[0]).find(l=>l===r)||!Object.keys(a[0]).find(l=>l===o)))return a;if(n==="pile"){const{maxRows:l}=e,c={};a.sort((d,h)=>d[r]-h[r]).forEach(d=>{const h=+d[r]-s,m=+d[o]+s,f=A?d[A]:"__NO_GROUP__";c[f]||(c[f]=[]);let b=c[f].findIndex(p=>mc[r]-u[r]).forEach(c=>{let u=c[r]-s,d=c[o]+s,h=l.filter(m=>m.start===u&&d===m.end||m.start0){let m=0;do h=l.filter(f=>f.start===u&&d===f.end||f.start0&&(m%2===0?(u+=s*m,d+=s*m):(u-=s*m,d-=s*m)),m++;while(h.length>0&&m<1e3)}c[`${C}Start`]=`${u+s}`,c[`${C}Etart`]=`${d-s}`,l.push({start:u,end:d})})}return a}function FIg(e,g,I="hg38"){const{separator:i,fields:n,flag:C}=e;let r=Array.from(g);return r=r.map(o=>{const A=[];return n.forEach(s=>{const{field:a,type:l,newField:c,chrField:u}=s;o[a].toString().split(i).forEach((h,m)=>{let f=h;l==="genomic"&&(f=pI(I).interval[o[u]][0]+ +h),A[m]?A[m][c]=f:A[m]=Object.assign(JSON.parse(JSON.stringify(o)),{[c]:f,[C.field]:C.value})})}),[o,...A]}).reduce((o,A)=>o.concat(A),[]),r}function EIg(e,g){const{field:I,genomicField:i,baseGenomicField:n,genomicLengthField:C}=e;let r=Array.from(g);return r=r.map(o=>{let A=JSON.parse(o[I]);return A=A.map(s=>{var a,l;return s[i]&&o[n]&&(s[`${i}_start`]=+s[i]+ +o[n],s[`${i}_end`]=+s[i]+ +o[n]+ +s[C]),Object.assign(JSON.parse(JSON.stringify(o)),{...s,[`${i}_start`]:s[`${i}_start`],[`${i}_end`]:s[`${i}_end`],type:(l=(a=s.type)!=null?a:s.variant)!=null?l:null,isParsedRow:"yes"})}),[o,...A]}).reduce((o,A)=>o.concat(A),[]),r}function MIg(e,g){if(bje(e).length===0)return g;const I=VK(e,"nominal");if(I.length!==1)return console.warn("Currently, we only support aggregating datasets with single nominal field."),g;const i=e[I[0]];if(!st(i))return g;const n=i.field;if(!n)return g;const C=[...VK(e,"quantitative"),...VK(e,"genomic")],r=[],o=Array.from(new Set(g.map(s=>s[n])));let A=!1;return o.forEach(s=>{const a={};a[n]=s,C.forEach(l=>{const c=e[l];if(!st(c)){A=!0;return}const{field:u}=c;if(!u||!("aggregate"in c)){A=!0;return}a[u]=c.aggregate==="max"?Math.max(...g.filter(d=>d[n]===s).map(d=>+d[u])):Math.min(...g.filter(d=>d[n]===s).map(d=>+d[u]))}),r.push(a)}),A?g:r}class zIg{constructor(g){hg(this,CO),hg(this,O4),hg(this,iH),hg(this,oO),hg(this,AO),hg(this,aO),Ct(this,"dataConfig"),Ct(this,"tilesetInfoLoading"),hg(this,qZ,void 0),hg(this,EB,void 0),hg(this,MB,void 0),hg(this,Rd,void 0),hg(this,gH,void 0),hg(this,IH,void 0),this.dataConfig=g,this.tilesetInfoLoading=!1,vC(this,Rd,this.dataConfig.assembly),vC(this,gH,this.dataConfig.filter),g.url||console.error("Please provide the `url` of the data");const{urlFetchOptions:I,url:i}=g;vC(this,IH,new jpe(i,{overrides:I})),vC(this,EB,BI(this,aO,I9e).call(this)),vC(this,qZ,BI(this,CO,qXe).call(this))}tilesetInfo(g){if(xt(this,qZ))return this.tilesetInfoLoading=!0,xt(this,qZ).then(()=>BI(this,oO,t9e).call(this,g)).catch(I=>{this.tilesetInfoLoading=!1,console.error("[Gosling Data Fetcher] Error parsing data:",I)})}fetchTilesDebounced(g,I){const i={},n=[],C=[];for(const r of I){const o=r.split("."),A=parseInt(o[0],10),s=parseInt(o[1],10),a=parseInt(o[2],10);if(Number.isNaN(s)||Number.isNaN(A)){console.warn("[Gosling Data Fetcher] Invalid tile zoom or position:",A,s,a);continue}n.push(r),C.push(BI(this,AO,g9e).call(this,A,s,a))}Promise.all(C).then(r=>{r.forEach((o,A)=>{if(o){const s=n[A];i[s]=o,i[s].tilePositionId=s}}),g(i)})}}qZ=new WeakMap;EB=new WeakMap;MB=new WeakMap;Rd=new WeakMap;gH=new WeakMap;IH=new WeakMap;CO=new WeakSet;qXe=async function(){var e,g;const{chromosomeField:I,genomicFields:i,headerNames:n,longToWideId:C,genomicFieldsToConvert:r}=this.dataConfig,o=(e=this.dataConfig.separator)!=null?e:",";try{const s=(await xt(this,IH).readFile()).toString(),a=n?`${n.join(o)} +${s}`:s,l=Gqe(o).parse(a,c=>BI(this,O4,e9e).call(this,c,r,I,i));if(C&&((g=l[0])!=null&&g[C])){const c=Object.keys(l[0]),u={};l.forEach(d=>{u[d[C]]?c.forEach(h=>{u[d[C]][`${h}_2`]=d[h]}):u[d[C]]=JSON.parse(JSON.stringify(d))}),vC(this,MB,Object.keys(u).map(d=>u[d]))}else vC(this,MB,l)}catch(A){console.error("[Gosling Data Fetcher] Error fetching data",A)}};O4=new WeakSet;e9e=function(e,g,I,i){try{return g?g.forEach(n=>{const C=n.genomicFields,r=e[n.chromosomeField];C.forEach(o=>{const A=e[o];e[o]=String(BI(this,iH,rO).call(this,r,A))})}):I&&i&&i.forEach(n=>{const C=e[n],r=e[I];e[n]=String(BI(this,iH,rO).call(this,r,C))}),e}catch{return}};iH=new WeakSet;rO=function(e,g){if(xt(this,Rd)!=="unknown"){const I=WM(e,xt(this,Rd),this.dataConfig.chromosomePrefix);return pI(xt(this,Rd)).interval[I][0]+ +g}else return g};oO=new WeakSet;t9e=function(e){this.tilesetInfoLoading=!1;const g=1024,I=xt(this,EB).totalLength,i={tile_size:g,max_zoom:Math.ceil(Math.log(I/g)/Math.log(2)),max_width:I,min_pos:[0,0],max_pos:[I,I]};return e&&e(i),i};AO=new WeakSet;g9e=async function(e,g,I){var i,n;const C=await this.tilesetInfo();if(!C)return;const r=+C.max_width/2**+e,o=C.min_pos[0]+g*r,A=C.min_pos[0]+(g+1)*r;let s=Qpe(xt(this,MB),[o,A],this.dataConfig);(i=xt(this,gH))==null||i.forEach(l=>{s=K9e(l,s)});const a=(n=this.dataConfig.sampleLength)!=null?n:1e3;return{tabularData:s.length>a?oU(s,a):s,server:null,tilePos:[g,I],zoomLevel:e}};aO=new WeakSet;I9e=function(){const e=pI(xt(this,Rd)).size,g=[],I={};let i=0;return Object.keys(e).forEach((n,C)=>{const r={id:C,chr:n,pos:i};g.push(r),I[n]=r,i+=e[n]}),{chrToAbs:(n,C)=>xt(this,EB).chrPositions[n].pos+C,cumPositions:g,chrPositions:I,totalLength:i,chromLengths:e}};function D9e(e,g,I){if(!new.target)throw new Error('Uncaught TypeError: Class constructor cannot be invoked without "new"');return new zIg(g)}D9e.config={type:"csv"};function x9e(e,...g){if(!new.target)throw new Error('Uncaught TypeError: Class constructor cannot be invoked without "new"');class I{constructor(n){Ct(this,"dataConfig"),Ct(this,"tilesetInfoLoading"),Ct(this,"chromSizes"),Ct(this,"values"),Ct(this,"assembly");const[C]=n;if(this.dataConfig=C,this.tilesetInfoLoading=!1,this.assembly=this.dataConfig.assembly,!C.values){console.error("Please provide `values` of the JSON data");return}const r=pI(this.assembly).size,o=[],A={};let s=0;Object.keys(pI(this.assembly).size).forEach((u,d)=>{const h={id:d,chr:u,pos:s};o.push(h),A[u]=h,s+=pI(this.assembly).size[u]}),this.chromSizes={chrToAbs:(u,d)=>this.chromSizes.chrPositions[u].pos+d,cumPositions:o,chrPositions:A,totalLength:s,chromLengths:r};const{chromosomeField:a,genomicFields:l,genomicFieldsToConvert:c}=this.dataConfig;this.values=C.values.map(u=>{try{return c?c.forEach(d=>{const h=d.genomicFields,m=WM(u[d.chromosomeField],this.assembly);h.forEach(f=>{const b=u[f];u[f]=String(this.chromSizes.chrToAbs(m,b))})}):a&&l&&l.forEach(d=>{const h=u[d],m=WM(u[a],this.assembly);u[d]=String(this.chromSizes.chrToAbs(m,h))}),u}catch{return}})}tilesetInfo(n){this.tilesetInfoLoading=!1;const C=1024,r=this.chromSizes.totalLength,o={tile_size:C,max_zoom:Math.ceil(Math.log(r/C)/Math.log(2)),max_width:r,min_pos:[0,0],max_pos:[r,r]};return n&&n(o),o}fetchTilesDebounced(n,C){const r={},o=[],A=[];for(const s of C){const a=s.split("."),l=parseInt(a[0],10),c=parseInt(a[1],10),u=parseInt(a[2],10);if(Number.isNaN(c)||Number.isNaN(l)){console.warn("[Gosling Data Fetcher] Invalid tile zoom or position:",l,c,u);continue}o.push(s),A.push(this.tile(l,c,u))}return Promise.all(A).then(s=>{s.forEach((a,l)=>{const c=o[l];r[c]=a,r[c].tilePositionId=c}),n(r)}),r}tile(n,C,r){var o;const A=this.tilesetInfo(),s=+A.max_width/2**+n,a=A.min_pos[0]+C*s,l=A.min_pos[0]+(C+1)*s;let c=Qpe(this.values,[a,l],this.dataConfig);const u=(o=this.dataConfig.sampleLength)!=null?o:1e3;return u{const A=Object.entries(pI(C).size);return await o.init(this.uid,{url:i,indexUrl:n},A,r),o})}async tilesetInfo(g){(await this.worker).tilesetInfo(this.uid).then(g)}fetchTilesDebounced(g,I){this.track.drawLoadingCue(),I.forEach(i=>this.toFetch.add(i)),this.fetchTimeout&&clearTimeout(this.fetchTimeout),this.fetchTimeout=setTimeout(()=>{this.sendFetch(g,[...this.toFetch]),this.toFetch.clear()},JIg)}async sendFetch(g,I){(await this.worker).fetchTilesDebounced(this.uid,I).then(g)}async getTabularData(g){const I=await(await this.worker).getTabularData(this.uid,g);return JSON.parse(new TextDecoder().decode(I))}}Ct(E9e,"config",{type:"gff"});const M9e="KCgpID0+IHsKICB2YXIgX19jcmVhdGUgPSBPYmplY3QuY3JlYXRlOwogIHZhciBfX2RlZlByb3AgPSBPYmplY3QuZGVmaW5lUHJvcGVydHk7CiAgdmFyIF9fZ2V0T3duUHJvcERlc2MgPSBPYmplY3QuZ2V0T3duUHJvcGVydHlEZXNjcmlwdG9yOwogIHZhciBfX2dldE93blByb3BOYW1lcyA9IE9iamVjdC5nZXRPd25Qcm9wZXJ0eU5hbWVzOwogIHZhciBfX2dldFByb3RvT2YgPSBPYmplY3QuZ2V0UHJvdG90eXBlT2Y7CiAgdmFyIF9faGFzT3duUHJvcCA9IE9iamVjdC5wcm90b3R5cGUuaGFzT3duUHJvcGVydHk7CiAgdmFyIF9fbWFya0FzTW9kdWxlID0gKHRhcmdldCkgPT4gX19kZWZQcm9wKHRhcmdldCwgIl9fZXNNb2R1bGUiLCB7IHZhbHVlOiB0cnVlIH0pOwogIHZhciBfX2VzbSA9IChmbiwgcmVzKSA9PiBmdW5jdGlvbiBfX2luaXQoKSB7CiAgICByZXR1cm4gZm4gJiYgKHJlcyA9ICgwLCBmbltPYmplY3Qua2V5cyhmbilbMF1dKShmbiA9IDApKSwgcmVzOwogIH07CiAgdmFyIF9fY29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ICAgICAgICAgb3V0cHV0LnB1c2godHJpcGxldFRvQmFzZTY0KHRtcCkpOwogICAgICAgIH0KICAgICAgICByZXR1cm4gb3V0cHV0LmpvaW4oIiIpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGZyb21CeXRlQXJyYXkodWludDgpIHsKICAgICAgICB2YXIgdG1wOwogICAgICAgIHZhciBsZW4yID0gdWludDgubGVuZ3RoOwogICAgICAgIHZhciBleHRyYUJ5dGVzID0gbGVuMiAlIDM7CiAgICAgICAgdmFyIHBhcnRzID0gW107CiAgICAgICAgdmFyIG1heENodW5rTGVuZ3RoID0gMTYzODM7CiAgICAgICAgZm9yICh2YXIgaTIgPSAwLCBsZW4yMiA9IGxlbjIgLSBleHRyYUJ5dGVzOyBpMiA8IGxlbjIyOyBpMiArPSBtYXhDaHVua0xlbmd0aCkgewogICAgICAgICAgcGFydHMucHVzaChlbmNvZGVDaHVuayh1aW50OCwgaTIsIGkyICsgbWF4Q2h1bmtMZW5ndGggPiBsZW4yMiA/IGxlbjIyIDogaTIgKyBtYXhDaHVua0xlbmd0aCkpOwogICAgICAgIH0KICAgICAgICBpZiAoZXh0cmFCeXRlcyA9PT0gMSkgewogICAgICAgICAgdG1wID0gdWludDhbbGVuMiAtIDFdOwogICAgICAgICAgcGFydHMucHVzaChsb29rdXBbdG1wID4+IDJdICsgbG9va3VwW3RtcCA8PCA0ICYgNjNdICsgIj09Iik7CiAgICAgICAgfSBlbHNlIGlmIChleHRyYUJ5dGVzID09PSAyKSB7CiAgICAgICAgICB0bXAgPSAodWludDhbbGVuMiAtIDJdIDw8IDgpICsgdWludDhbbGVuMiAtIDFdOwogICAgICAgICAgcGFydHMucHVzaChsb29rdXBbdG1wID4+IDEwXSArIGxvb2t1cFt0bXAgPj4gNCAmIDYzXSArIGxvb2t1cFt0bXAgPDwgMiAmIDYzXSArICI9Iik7CiAgICAgICAgfQogICAgICAgIHJldHVybiBwYXJ0cy5qb2luKCIiKTsKICAgICAgfQogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vaWVlZTc1NEAxLjIuMS9ub2RlX21vZHVsZXMvaWVlZTc1NC9pbmRleC5qcwogIHZhciByZXF1aXJlX2llZWU3NTQgPSBfX2NvbW1vbkpTKHsKICAgICJub2RlX21vZHVsZXMvLnBucG0vaWVlZTc1NEAxLjIuMS9ub2RlX21vZHVsZXMvaWVlZTc1NC9pbmRleC5qcyIoZXhwb3J0czIpIHsKICAgICAgaW5pdF9idWZmZXJfc2hpbSgpOwogICAgICBleHBvcnRzMi5yZWFkID0gZnVuY3Rpb24oYnVmZmVyLCBvZmZzZXQsIGlzTEUsIG1MZW4sIG5CeXRlcykgewogICAgICAgIHZhciBlLCBtOwogICAgICAgIHZhciBlTGVuID0gbkJ5dGVzICogOCAtIG1MZW4gLSAxOwogICAgICAgIHZhciBlTWF4ID0gKDEgPDwgZUxlbikgLSAxOwogICAgICAgIHZhciBlQmlhcyA9IGVNYXggPj4gMTsKICAgICAgICB2YXIgbkJpdHMgPSAtNzsKICAgICAgICB2YXIgaSA9IGlzTEUgPyBuQnl0ZXMgLSAxIDogMDsKICAgICAgICB2YXIgZCA9IGlzTEUgPyAtMSA6IDE7CiAgICAgICAgdmFyIHMgPSBidWZmZXJbb2Zmc2V0ICsgaV07CiAgICAgICAgaSArPSBkOwogICAgICAgIGUgPSBzICYgKDEgPDwgLW5CaXRzKSAtIDE7CiAgICAgICAgcyA+Pj0gLW5CaXRzOwogICAgICAgIG5CaXRzICs9IGVMZW47CiAgICAgICAgZm9yICg7IG5CaXRzID4gMDsgZSA9IGUgKiAyNTYgKyBidWZmZXJbb2Zmc2V0ICsgaV0sIGkgKz0gZCwgbkJpdHMgLT0gOCkgewogICAgICAgIH0KICAgICAgICBtID0gZSAmICgxIDw8IC1uQml0cykgLSAxOwogICAgICAgIGUgPj49IC1uQml0czsKICAgICAgICBuQml0cyArPSBtTGVuOwogICAgICAgIGZvciAoOyBuQml0cyA+IDA7IG0gPSBtICogMjU2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ewogICAgICAgICAgbSA9IGlzTmFOKHZhbHVlKSA/IDEgOiAwOwogICAgICAgICAgZSA9IGVNYXg7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIGUgPSBNYXRoLmZsb29yKE1hdGgubG9nKHZhbHVlKSAvIE1hdGguTE4yKTsKICAgICAgICAgIGlmICh2YWx1ZSAqIChjID0gTWF0aC5wb3coMiwgLWUpKSA8IDEpIHsKICAgICAgICAgICAgZS0tOwogICAgICAgICAgICBjICo9IDI7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoZSArIGVCaWFzID49IDEpIHsKICAgICAgICAgICAgdmFsdWUgKz0gcnQgLyBjOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgdmFsdWUgKz0gcnQgKiBNYXRoLnBvdygyLCAxIC0gZUJpYXMpOwogICAgICAgICAgfQogICAgICAgICAgaWYgKHZhbHVlICogYyA+PSAyKSB7CiAgICAgICAgICAgIGUrKzsKICAgICAgICAgICAgYyAvPSAyOwogICAgICAgICAgfQogICAgICAgICAgaWYgKGUgKyBlQmlhcyA+PSBlTWF4KSB7CiAgICAgICAgICAgIG0gPSAwOwogICAgICAgICAgICBlID0gZU1heDsKICAgICAgICAgIH0gZWxzZSBpZiAoZSArIGVCaWFzID49IDEpIHsKICAgICAgICAgICAgbSA9ICh2YWx1ZSAqIGMgLSAxKSAqIE1hdGgucG93KDIsIG1MZW4pOwogICAgICAgICAgICBlID0gZSArIGVCaWFzOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgbSA9IHZhbHVlICogTWF0aC5wb3coMiwgZUJpYXMgLSAxKSAqIE1hdGgucG93KDIsIG1MZW4pOwogICAgICAgICAgICBlID0gMDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZm9yICg7IG1MZW4gPj0gODsgYnVmZmVyW29mZnNldCArIGldID0gbSAmIDI1NSwgaSArPSBkLCBtIC89IDI1NiwgbUxlbiAtPSA4KSB7CiAgICAgICAgfQogICAgICAgI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ogdHJ1ZSwKICAgICAgICBnZXQ6IGZ1bmN0aW9uKCkgewogICAgICAgICAgaWYgKCFCdWZmZXIxMC5pc0J1ZmZlcih0aGlzKSkKICAgICAgICAgICAgcmV0dXJuIHZvaWQgMDsKICAgICAgICAgIHJldHVybiB0aGlzLmJ1ZmZlcjsKICAgICAgICB9CiAgICAgIH0pOwogICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkoQnVmZmVyMTAucHJvdG90eXBlLCAib2Zmc2V0IiwgewogICAgICAgIGVudW1lcmFibGU6IHRydWUsCiAgICAgICAgZ2V0OiBmdW5jdGlvbigpIHsKICAgICAgICAgIGlmICghQnVmZmVyMTAuaXNCdWZmZXIodGhpcykpCiAgICAgICAgICAgIHJldHVybiB2b2lkIDA7CiAgICAgICAgICByZXR1cm4gdGhpcy5ieXRlT2Zmc2V0OwogICAgICAgIH0KICAgICAgfSk7CiAgICAgIGZ1bmN0aW9uIGNyZWF0ZUJ1ZmZlcihsZW5ndGgpIHsKICAgICAgICBpZiAobGVuZ3RoID4gS19NQVhfTEVOR1RIKSB7CiAgICAgICAgICB0aHJvdyBuZXcgUmFuZ2VFcnJvcignVGhlIHZhbHVlICInICsgbGVuZ3RoICsgJyIgaXMgaW52YWxpZCBmb3Igb3B0aW9uICJzaXplIicpOwogICAgICAgIH0KICAgICAgICBjb25zdCBidWYgPSBuZXcgVWludDhBcnJheShsZW5ndGgpOwogICAgICAgIE9iamVjdC5zZXRQcm90b3R5cGVPZihidWYsIEJ1ZmZlcjEwLnByb3RvdHlwZSk7CiAgICAgICAgcmV0dXJuIGJ1ZjsKICAgICAgfQogICAgICBmdW5jdGlvbiBCdWZmZXIxMChhcmcsIGVuY29kaW5nT3JPZmZzZXQsIGxlbmd0aCkgewogICAgICAgIGlmICh0eXBlb2YgYXJnID09PSAibnVtYmVyIikgewogICAgICAgICAgaWYgKHR5cGVvZiBlbmNvZGluZ09yT2Zmc2V0ID09PSAic3RyaW5nIikgewogICAgICAgICAgICB0aHJv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AgICAgIGVuY29kaW5nID0gInV0ZjgiOwogICAgICAgIH0KICAgICAgICBpZiAoIUJ1ZmZlcjEwLmlzRW5jb2RpbmcoZW5jb2RpbmcpKSB7CiAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCJVbmtub3duIGVuY29kaW5nOiAiICsgZW5jb2RpbmcpOwogICAgICAgIH0KICAgICAgICBjb25zdCBsZW5ndGggPSBieXRlTGVuZ3RoKHN0cmluZywgZW5jb2RpbmcpIHwgMDsKICAgICAgICBsZXQgYnVmID0gY3JlYXRlQnVmZmVyKGxlbmd0aCk7CiAgICAgICAgY29uc3QgYWN0dWFsID0gYnVmLndyaXRlKHN0cmluZywgZW5jb2RpbmcpOwogICAgICAgIGlmIChhY3R1YWwgIT09IGxlbmd0aCkgewogICAgICAgICAgYnVmID0gYnVmLnNsaWNlKDAsIGFjdHVhbCk7CiAgICAgICAgfQogICAgICAgIHJldHVybiBidWY7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZnJvbUFycmF5TGlrZShhcnJheSkgewogICAgICAgIGNvbnN0IGxlbmd0aCA9IGFycmF5Lmxlbmd0aCA8IDAgPyAwIDogY2hlY2tlZChhcnJheS5sZW5ndGgpIHwgMDsKICAgICAgICBjb25zdCBidWYgPSBjcmVhdGVCdWZmZXIobGVuZ3RoKTsKICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IGxlbmd0aDsgaSArPSAxKSB7CiAgICAgICAgICBidWZbaV0gPSBhcnJheVtpXSAmIDI1NTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIGJ1ZjsKICAgICAgfQogICAgICBmdW5jdGlvbiBmcm9tQXJyYXlWaWV3KGFycmF5VmlldykgewogICAgICAgIGlmIChpc0luc3RhbmNlKGFycmF5VmlldywgVWludDhBcnJheSkpIHsKICAgICAgICAgIGNvbnN0IGNvcHkgPSBuZXcgVWludDhBcnJheShhcnJheVZpZXcpOwogICAgICAgICAgcmV0dXJuIGZyb21BcnJheUJ1ZmZlc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gIGZ1bmN0aW9uIGZyb21PYmplY3Qob2JqKSB7CiAgICAgICAgaWYgKEJ1ZmZlcjEwLmlzQnVmZmVyKG9iaikpIHsKICAgICAgICAgIGNvbnN0IGxlbiA9IGNoZWNrZWQob2JqLmxlbmd0aCkgfCAwOwogICAgICAgICAgY29uc3QgYnVmID0gY3JlYXRlQnVmZmVyKGxlbik7CiAgICAgICAgICBpZiAoYnVmLmxlbmd0aCA9PT0gMCkgewogICAgICAgICAgICByZXR1cm4gYnVmOwogICAgICAgICAgfQogICAgICAgICAgb2JqLmNvcHkoYnVmLCAwLCAwLCBsZW4pOwogICAgICAgICAgcmV0dXJuIGJ1ZjsKICAgICAgICB9CiAgICAgICAgaWYgKG9iai5sZW5ndGggIT09IHZvaWQgMCkgewogICAgICAgICAgaWYgKHR5cGVvZiBvYmoubGVuZ3RoICE9PSAibnVtYmVyIiB8fCBudW1iZXJJc05hTihvYmoubGVuZ3RoKSkgewogICAgICAgICAgICByZXR1cm4gY3JlYXRlQnVmZmVyKDApOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIGZyb21BcnJheUxpa2Uob2JqKTsKICAgICAgICB9CiAgICAgICAgaWYgKG9iai50eXBlID09PSAiQnVmZmVyIiAmJiBBcnJheS5pc0FycmF5KG9iai5kYXRhKSkgewogICAgICAgICAgcmV0dXJuIGZyb21BcnJheUxpa2Uob2JqLmRhdGEpOwogICAgICAgIH0KICAgICAgfQogICAgICBmdW5jdGlvbiBjaGVja2VkKGxlbmd0aCkgewogICAgICAgIGlmIChsZW5ndGggPj0gS19NQVhfTEVOR1RIKSB7CiAgICAgICAgICB0aHJvdyBuZXcgUmFuZ2VFcnJvcigiQXR0ZW1wdCB0byBhbGxvY2F0ZSBCdWZmZXIgbGFyZ2VyIHRoYW4gbWF4aW11bSBzaXplOiAweCIgKyBLX01BWF9MRU5HVEgudG9TdHJpbmcoMTYpICsgIiBieXRlcyIpOwogICAgICAgIH0KICAgICAgICByZXR1cm4gbGVuZ3RoI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sZW4gPSBNYXRoLm1pbih4LCB5KTsgaSA8IGxlbjsgKytpKSB7CiAgICAgICAgICBpZiAoYVtpXSAhPT0gYltpXSkgewogICAgICAgICAgICB4ID0gYVtpXTsKICAgICAgICAgICAgeSA9IGJbaV07CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAoeCA8IHkpCiAgICAgICAgICByZXR1cm4gLTE7CiAgICAgICAgaWYgKHkgPCB4KQogICAgICAgICAgcmV0dXJuIDE7CiAgICAgICAgcmV0dXJuIDA7CiAgICAgIH07CiAgICAgIEJ1ZmZlcjEwLmlzRW5jb2RpbmcgPSBmdW5jdGlvbiBpc0VuY29kaW5nKGVuY29kaW5nKSB7CiAgICAgICAgc3dpdGNoIChTdHJpbmcoZW5jb2RpbmcpLnRvTG93ZXJDYXNlKCkpIHsKICAgICAgICAgIGNhc2UgImhleCI6CiAgICAgICAgICBjYXNlICJ1dGY4IjoKICAgICAgICAgIGNhc2UgInV0Zi04IjoKICAgICAgICAgIGNhc2UgImFzY2lpIjoKICAgICAgICAgIGNhc2UgImxhdGluMSI6CiAgICAgICAgICBjYXNlICJiaW5hcnkiOgogICAgICAgICAgY2FzZSAiYmFzZTY0IjoKICAgICAgICAgIGNhc2UgInVjczIiOgogICAgICAgICAgY2FzZSAidWNzLTIiOgogICAgICAgICAgY2FzZSAidXRmMTZsZSI6CiAgICAgICAgICBjYXNlICJ1dGYtMTZsZSI6CiAgICAgICAgICAgIHJldHVybiB0cnVlOwogICAgICAgICAgZGVmYXVsdDoKICAgICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICAgIH0KICAgICAgfTsKICAgICAgQnVmZmVyMTAuY29uY2F0ID0gZnVuY3Rpb24gY29uY2F0KGxpc3QsIGxlbmd0aCkgewogICAgICAgIGlmICghQXJyYXkuaXNBcnJheShsaXN0KSkgewogICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcignImxpc3QiIGFyZ3VtZW50IG11c3QgYmUgYW4gQXJyYXkgb2YgQnVmZmVycycpOwogICAgICAgIH0KICAgICAgICBpZiAobGlzdC5sZW5ndGggPT09IDApIHsKICAgICAgICAgIHJldHVybiBCdWZmZXIxMC5hbGxvYygwKTsKICAgICAgICB9CiAgICAgICAgbGV0IGk7CiAgICAgICAgaWYgKGxlbmd0aCA9PT0gdm9pZCAwKSB7CiAgICAgICAgICBsZW5ndGggPSAwOwogICAgICAgICAgZm9yIChpID0gMDsgaSA8IGxpc3QubGVuZ3RoOyArK2kpIHsKICAgICAgICAgICAgbGVuZ3RoICs9IGxpc3RbaV0ubGVuZ3RoOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBjb25zdCBidWZmZXIgPSBCdWZmZXIxMC5hbGxvY1Vuc2FmZShsZW5ndGgpOwogICAgICAgIGxldCBwb3MgPSAwOwogICAgICAgIGZvciAoaSA9IDA7IGkgPCBsaXN0Lmxlbmd0aDsgKytpKSB7CiAgICAgICAgICBsZXQgYnVmID0gbGlzdFtpXTsKICAgICAgICAgIGlmIChpc0luc3RhbmNlKGJ1ZiwgVWludDhBcnJheSkpIHsKICAgICAgICAgICAgaWYgKHBvcyArIGJ1Zi5sZW5ndGggPiBidWZmZXIubGVuZ3RoKSB7CiAgICAgICAgICAgICAgaWYgKCFCdWZmZXIxMC5pc0J1ZmZlcihidWYpKQogICAgICAgICAgICAgICAgYnVmID0gQnVmZmVyMTAuZnJvbShidWYpOwogICAgICAgICAgICAgIGJ1Zi5jb3B5KGJ1ZmZlciwgcG9zKTsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICBVaW50OEFycmF5LnByb3RvdHlwZS5zZXQuY2FsbChidWZmZXIsIGJ1ZiwgcG9zKTsKICAgICAgICAgICAgfQogICAgICAgICAgfSBlbHNlIGlmICghQnVmZmVyMTAuaXNCdWZmZXIoYnVmKSkgewogICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCcibGlzdCIgYXJndW1lbnQgbXVzdCBiZSBhbiBBcnJheSBvZiBCdWZmZXJzJyk7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBidWYuY29weShidWZmZXIsIHBvcyk7CiAgICAgICAgICB9CiAgICAgICAgICBwb3MgKz0gYnVmLmxlbmd0aDsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIGJ1ZmZlcjsKICAgICAgfTsKICAgICAgZnVuY3Rpb24gYnl0ZUxlbmd0aChzdHJpbmcsIGVuY29kaW5nKSB7CiAgICAgICAgaWYgKEJ1ZmZlcjEwLmlzQnVmZmVyKHN0cmluZykpIHsKICAgICAgICAgIHJldHVybiBzdHJpbmcubGVuZ3RoOwogICAgICAgIH0KICAgICAgICBpZiAoQXJyYXlCdWZmZXIuaXNWaWV3KHN0cmluZykgfHwgaXNJbnN0YW5jZShzdHJpbmcsIEFycmF5QnVmZmVyKSkgewogICAgICAgICAgcmV0dXJuIHN0cmluZy5ieXRlTGVuZ3RoOwogICAgICAgIH0KICAgICAgICBpZiAodHlwZW9mIHN0cmluZyAhPT0gInN0cmluZyIpIHsKICAgICAgICAgIHRocm93IG5ldyBUeXBlRXJyb3IoJ1RoZSAic3RyaW5nIiBhcmd1bWVudCBtdXN0IGJlIG9uZSBvZiB0eXBlIHN0cmluZywgQnVmZmVyLCBvciBBcnJheUJ1ZmZlci4gUmVjZWl2ZWQgdHlwZSAnICsgdHlwZW9mIHN0cmluZyk7CiAgICAgICAgfQogICAgICAgIGNvbnN0IGxlbiA9IHN0cmluZy5sZW5ndGg7CiAgICAgICAgY29uc3QgbXVzdE1hdGNoID0gYXJndW1lbnRzLmxlbmd0aCA+IDIgJiYgYXJndW1lbnRzWzJdID09PSB0cnVlOwogICAgICAgIGlmICghbXVzdE1hdGNoICYmIGxlbiA9PT0gMCkKICAgICAgICAgIHJldHVybiAwOwogICAgICAgIGxldCBsb3dlcmVkQ2FzZSA9IGZhbHNlOwogICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgc3dpdGNoIChlbmNvZGluZykgewogICAgICAgICAgICBjYXNlICJhc2NpaSI6CiAgICAgICAgICAgIGNhc2UgImxhdGluMSI6CiAgICAgICAgICAgIGNhc2UgImJpbmFyeSI6CiAgICAgICAgICAgICAgcmV0dXJuIGxlbjsKICAgICAgICAgICAgY2FzZSAidXRmOCI6CiAgICAgICAgICAgIGNhc2UgInV0Zi04IjoKICAgICAgICAgICAgICByZXR1cm4gdXRmOFRvQnl0ZXMoc3RyaW5nKS5sZW5ndGg7CiAgICAgICAgICAgIGNhc2UgInVjczIiOgogICAgICAgICAgICBjYXNlICJ1Y3MtMiI6CiAgICAgICAgICAgIGNhc2UgInV0ZjE2bGUiOgogICAgICAgICAgICBjYXNlICJ1dGYtMTZsZSI6CiAgICAgICAgICAgICAgcmV0dXJuIGxlbiAqIDI7CiAgICAgICAgICAgIGNhc2UgImhleCI6CiAgICAgICAgICAgICAgcmV0dXJuIGxlbiA+Pj4gMTsKICAgICAgICAgICAgY2FzZSAiYmFzZTY0IjoKICAgICAgICAgICAgICByZXR1cm4gYmFzZTY0VG9CeXRlcyhzdHJpbmcpLmxlbmd0aDsKICAgICAgICAgICAgZGVmYXVsdDoKICAgICAgICAgICAgICBpZiAobG93ZXJlZENhc2UpIHsKICAgICAgICAgICAgICAgIHJldHVybiBtdXN0TWF0Y2ggPyAtMSA6IHV0ZjhUb0J5dGVzKHN0cmluZykubGVuZ3RoOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBlbmNvZGluZyA9ICgiIiArIGVuY29kaW5nKS50b0xvd2VyQ2FzZSgpOwogICAgICAgICAgICAgIGxvd2VyZWRDYXNlID0gdHJ1ZTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgICAgQnVmZmVyMTAuYnl0ZUxlbmd0aCA9IGJ5dGVMZW5ndGg7CiAgICAgIGZ1bmN0aW9uIHNsb3dUb1N0cmluZyhlbmNvZGluZywgc3RhcnQsIGVuZCkgewogICAgICAgIGxldCBsb3dlcmVkQ2FzZSA9IGZhbHNlOwogICAgICAgIGlmIChzdGFydCA9PT0gdm9pZCAwIHx8IHN0YXJ0IDwgMCkgewogICAgICAgICAgc3RhcnQgPSAwOwogICAgICAgIH0KICAgICAgICBpZiAoc3RhcnQgPiB0aGlzLmxlbmd0aCkgewogICAgICAgICAgcmV0dXJuICIiOwogICAgICAgIH0KICAgICAgICBpZiAoZW5kID09PSB2b2lkIDAgfHwgZW5kID4gdGhpcy5sZW5ndGgpIHsKICAgICAgICAgIGVuZCA9IHRoaXMubGVuZ3RoOwogICAgICAgIH0KICAgICAgICBpZiAoZW5kIDw9IDApIHsKICAgICAgICAgIHJldHVybiAiIjsKICAgICAgICB9CiAgICAgICAgZW5kID4+Pj0gMDsKICAgICAgICBzdGFydCA+Pj49IDA7CiAgICAgICAgaWYgKGVuZCA8PSBzdGFydCkgewogICAgICAgICAgcmV0dXJuICIiOwogICAgICAgIH0KICAgICAgICBpZiAoIWVuY29kaW5nKQogICAgICAgICAgZW5jb2RpbmcgPSAidXRmOCI7CiAgICAgICAgd2hpbGUgKHRydWUpIHsKICAgICAgICAgIHN3aXRjaCAoZW5jb2RpbmcpIHsKICAgICAgICAgICAgY2FzZSAiaGV4IjoKICAgICAgICAgICAgICByZXR1cm4gaGV4U2xpY2UodGhpcywgc3RhcnQsIGVuZCk7CiAgICAgICAgICAgIGNhc2UgInV0ZjgiOgogICAgICAgICAgICBjYXNlICJ1dGYtOCI6CiAgICAgICAgICAgICAgcmV0dXJuIHV0ZjhTbGljZSh0aGlzLCBzdGFydCwgZW5kKTsKICAgICAgICAgICAgY2FzZSAiYXNjaWkiOgogICAgICAgICAgICAgIHJldHVybiBhc2NpaVNsaWNlKHRoaXMsIHN0YXJ0LCBlbmQpOwogICAgICAgICAgICBjYXNlICJsYXRpbjEiOgogICAgICAgICAgICBjYXNlICJiaW5hcnkiOgogICAgICAgICAgICAgIHJldHVybiBsYXRpbjFTbGljZSh0aGlzLCBzdGFydCwgZW5kKTsKICAgICAgICAgICAgY2FzZSAiYmFzZTY0IjoKICAgICAgICAgICAgICByZXR1cm4gYmFzZTY0U2xpY2UodGhpcywgc3RhcnQsIGVuZCk7CiAgICAgICAgICAgIGNhc2UgInVjczIiOgogICAgICAgICAgICBjYXNlICJ1Y3MtMiI6CiAgICAgICAgICAgIGNhc2UgInV0ZjE2bGUiOgogICAgICAgICAgICBjYXNlICJ1dGYtMTZsZSI6CiAgICAgICAgICAgICAgcmV0dXJuIHV0ZjE2bGVTbGljZSh0aGlzLCBzdGFydCwgZW5kKTsKICAgICAgICAgICAgZGVmYXVsdDoKICAgICAgICAgICAgICBpZiAobG93ZXJlZENhc2UpCiAgICAgICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCJVbmtub3duIGVuY29kaW5nOiAiICsgZW5jb2RpbmcpOwogICAgICAgICAgICAgIGVuY29kaW5nID0gKGVuY29kaW5nICsgIiIpLnRvTG93ZXJDYXNlKCk7CiAgICAgICAgICAgICAgbG93ZXJlZENhc2UgPSB0cnVlOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgICBCdWZmZXIxMC5wcm90b3R5cGUuX2lzQnVmZmVyID0gdHJ1ZTsKICAgICAgZnVuY3Rpb24gc3dhcChiLCBuLCBtKSB7CiAgICAgICAgY29uc3QgaSA9IGJbbl07CiAgICAgICAgYltuXSA9IGJbbV07CiAgICAgICAgYlttXSA9IGk7CiAgICAgIH0KICAgICAgQnVmZmVyMTAucHJvdG90eXBlLnN3YXAxNiA9IGZ1bmN0aW9uIHN3YXAxNigpIHsKICAgICAgICBjb25zdCBsZW4gPSB0aGlzLmxlbmd0aDsKICAgICAgICBpZiAobGVuICUgMiAhPT0gMCkgewogICAgICAgICAgdGhyb3cgbmV3IFJhbmdlRXJyb3IoIkJ1ZmZlciBzaXplIG11c3QgYmUgYSBtdWx0aXBsZSBvZiAxNi1iaXRzIik7CiAgICAgICAgfQogICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgbGVuOyBpICs9IDIpIHsKICAgICAgICAgIHN3YXAodGhpcywgaSwgaSArIDEpOwogICAgICAgIH0KICAgICAgICByZXR1cm4gdGhpczsKICAgICAgfTsKICAgICAgQnVmZmVyMTAucHJvdG90eXBlLnN3YXAzMiA9IGZ1bmN0aW9uIHN3YXAzMigpIHsKICAgICAgICBjb25zdCBsZW4gPSB0aGlzLmxlbmd0aDsKICAgICAgICBpZiAobGVuICUgNCAhPT0gMCkgewogICAgICAgICAgdGhyb3cgbmV3IFJhbmdlRXJyb3IoIkJ1ZmZlciBzaXplIG11c3QgYmUgYSBtdWx0aXBsZSBvZiAzMi1iaXRzIik7CiAgICAgICAgfQogICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgbGVuOyBpICs9IDQpIHsKICAgICAgICAgIHN3YXAodGhpcywgaSwgaSArIDMpOwogICAgICAgICAgc3dhcCh0aGlzLCBpICsgMSwgaSArIDIpOwogICAgICAgIH0KICAgICAgICByZXR1cm4gdGhpczsKICAgICAgfTsKICAgICAgQnVmZmVyMTAucHJvdG90eXBlLnN3YXA2NCA9IGZ1bmN0aW9uIHN3YXA2NCgpIHsKICAgICAgICBjb25zdCBsZW4gPSB0aGlzLmxlbmd0aDsKICAgICAgICBpZiAobGVuICUgOCAhPT0gMCkgewogICAgICAgICAgdGhyb3cgbmV3IFJhbmdlRXJyb3IoIkJ1ZmZlciBzaXplIG11c3QgYmUgYSBtdWx0aXBsZSBvZiA2NC1iaXRzIik7CiAgICAgICAgfQogICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgbGVuOyBpICs9IDgpIHsKICAgICAgICAgIHN3YXAodGhpcywgaSwgaSArIDcpOwogICAgICAgICAgc3dhcCh0aGlzLCBpICsgMSwgaSArIDYpOwogICAgICAgICAgc3dhcCh0aGlzLCBpICsgMiwgaSArIDUpOwogICAgICAgICAgc3dhcCh0aGlzLCBpICsgMywgaSArIDQpOwogICAgICAgIH0KICAgICAgICByZXR1cm4gdGhpczsKICAgICAgfTsKICAgICAgQnVmZmVyMTAucHJ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CkgewogICAgICAgICAgdGhpc0VuZCA9IHRoaXMubGVuZ3RoOwogICAgICAgIH0KICAgICAgICBpZiAoc3RhcnQgPCAwIHx8IGVuZCA+IHRhcmdldC5sZW5ndGggfHwgdGhpc1N0YXJ0IDwgMCB8fCB0aGlzRW5kID4gdGhpcy5sZW5ndGgpIHsKICAgICAgICAgIHRocm93IG5ldyBSYW5nZUVycm9yKCJvdXQgb2YgcmFuZ2UgaW5kZXgiKTsKICAgICAgICB9CiAgICAgICAgaWYgKHRoaXNTdGFydCA+PSB0aGlzRW5kICYmIHN0YXJ0ID49IGVuZCkgewogICAgICAgICAgcmV0dXJuIDA7CiAgICAgICAgfQogICAgICAgIGlmICh0aGlzU3RhcnQgPj0gdGhpc0VuZCkgewogICAgICAgICAgcmV0dXJuIC0xOwogICAgICAgIH0KICAgICAgICBpZiAoc3RhcnQgPj0gZW5kKSB7CiAgICAgICAgICByZXR1cm4gMTsKICAgICAgICB9CiAgICAgICAgc3RhcnQgPj4+PSAwOwogICAgICAgIGVuZCA+Pj49IDA7CiAgICAgICAgdGhpc1N0YXJ0ID4+Pj0gMDsKICAgICAgICB0aGlzRW5kID4+Pj0gMDsKICAgICAgICBpZiAodGhpcyA9PT0gdGFyZ2V0KQogICAgICAgICAgcmV0dXJuIDA7CiAgICAgICAgbGV0IHggPSB0aGlzRW5kIC0gdGhpc1N0YXJ0OwogICAgICAgIGxldCB5ID0gZW5kIC0gc3RhcnQ7CiAgICAgICAgY29uc3QgbGVuID0gTWF0aC5taW4oeCwgeSk7CiAgICAgICAgY29uc3QgdGhpc0NvcHkgPSB0aGlzLnNsaWNlKHRoaXNTdGFydCwgdGhpc0VuZCk7CiAgICAgICAgY29uc3QgdGFyZ2V0Q29weSA9IHRhcmdldC5zbGljZShzdGFydCwgZW5kKTsKICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IGxlbjsgKytpKSB7CiAgICAgICAgICBpZiAodGhpc0NvcHlbaV0gIT09IHRhcmdldENvcHlbaV0p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CiAgICAgICAgaWYgKGJ5dGVPZmZzZXQgPj0gYnVmZmVyLmxlbmd0aCkgewogICAgICAgICAgaWYgKGRpcikKICAgICAgICAgICAgcmV0dXJuIC0xOwogICAgICAgICAgZWxzZQogICAgICAgICAgICBieXRlT2Zmc2V0ID0gYnVmZmVyLmxlbmd0aCAtIDE7CiAgICAgICAgfSBlbHNlIGlmIChieXRlT2Zmc2V0IDwgMCkgewogICAgICAgICAgaWYgKGRpcikKICAgICAgICAgICAgYnl0ZU9mZnNldCA9IDA7CiAgICAgICAgICBlbHNlCiAgICAgICAgICAgIHJldHVybiAtMTsKICAgICAgICB9CiAgICAgICAgaWYgKHR5cGVvZiB2YWwgPT09ICJzdHJpbmciKSB7CiAgICAgICAgICB2YWwgPSBCdWZmZXIxMC5mcm9tKHZhbCwgZW5jb2RpbmcpOwogICAgICAgIH0KICAgICAgICBpZiAoQnVmZmVyMTAuaXNCdWZmZXIodmFsKSkgewogICAgICAgICAgaWYgKHZhbC5sZW5ndGggPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIC0xOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIGFycmF5SW5kZXhPZihidWZmZXIsIHZhbCwgYnl0ZU9mZnNldCwgZW5jb2RpbmcsIGRpcik7CiAgICAgICAgfSBlbHNlIGlmICh0eXBlb2YgdmFsID09PSAibnVtYmVyIikgewogICAgICAgICAgdmFsID0gdmFsICYgMjU1OwogICAgICAgICAgaWYgKHR5cGVvZiBVaW50OEFycmF5LnByb3RvdHlwZS5pbmRleE9mID09PSAiZnVuY3Rpb24iKSB7CiAgICAgICAgICAgIGlmIChkaXIpIHsKICAgICAgICAgICAgICByZXR1cm4gVWludDhBcnJheS5wcm90b3R5cGUuaW5kZXhPZi5jYWxsKGJ1ZmZlciwgdmFsLCBieXRlT2Zmc2V0KTsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICByZXR1cm4gVWludDhBcnJheS5wcm90b3R5cGUubGFzdEluZGV4T2YuY2FsbChidWZmZXIsIHZhbCwgYnl0ZU9mZnNldCk7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBhcnJheUluZGV4T2YoYnVmZmVyLCBbdmFsXSwgYnl0ZU9mZnNldCwgZW5jb2RpbmcsIGRpcik7CiAgICAgICAgfQogICAgICAgIHRocm93IG5ldyBUeXBlRXJyb3IoInZhbCBtdXN0IGJlIHN0cmluZywgbnVtYmVyIG9yIEJ1ZmZlciIpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGFycmF5SW5kZXhPZihhcnIsIHZhbCwgYnl0ZU9mZnNldCwgZW5jb2RpbmcsIGRpcikgewogICAgICAgIGxldCBpbmRleFNpemUgPSAxOwogICAgICAgIGxldCBhcnJMZW5ndGggPSBhcnIubGVuZ3RoOwogICAgICAgIGxldCB2YWxMZW5ndGggPSB2YWwubGVuZ3RoOwogICAgICAgIGlmIChlbmNvZGluZyAhPT0gdm9pZCAwKSB7CiAgICAgICAgICBlbmNvZGluZyA9IFN0cmluZyhlbmNvZGluZykudG9Mb3dlckNhc2UoKTsKICAgICAgICAgIGlmIChlbmNvZGluZyA9PT0gInVjczIiIHx8IGVuY29kaW5nID09PSAidWNzLTIiIHx8IGVuY29kaW5nID09PSAidXRmMTZsZSIgfHwgZW5jb2RpbmcgPT09ICJ1dGYtMTZsZSIpIHsKICAgICAgICAgICAgaWYgKGFyci5sZW5ndGggPCAyIHx8IHZhbC5sZW5ndGggPCAyKSB7CiAgICAgICAgICAgICAgcmV0dXJuIC0xOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGluZGV4U2l6ZSA9IDI7CiAgICAgICAgICAgIGFyckxlbmd0aCAvPSAyOwogICAgICAgICAgICB2YWxMZW5ndGggLz0gMjsKICAgICAgICAgICAgYnl0ZU9mZnNldCAvPSAyOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBmdW5jdGlvbiByZWFkKGJ1ZiwgaTIpIHsKICAgICAgICAgIGlmIChpbmRleFNpemUgPT09IDEpIHsKICAgICAgICAgICAgcmV0dXJuIGJ1ZltpMl07CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICByZXR1cm4gYnVmLnJlYWRVSW50MTZCRShpMiAqIGluZGV4U2l6ZSk7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGxldCBpOwogICAgICAgIGlmIChkaXIpIHsKICAgICAgICAgIGxldCBmb3VuZEluZGV4ID0gLTE7CiAgICAgICAgICBmb3IgKGkgPSBieXRlT2Zmc2V0OyBpIDwgYXJyTGVuZ3RoOyBpKyspIHsKICAgICAgICAgICAgaWYgKHJlYWQoYXJyLCBpKSA9PT0gcmVhZCh2YWwsIGZvdW5kSW5kZXggPT09IC0xID8gMCA6IGkgLSBmb3VuZEluZGV4KSkgewogICAgICAgICAgICAgIGlmIChmb3VuZEluZGV4ID09PSAtMSkKICAgICAgICAgICAgICAgIGZvdW5kSW5kZXggPSBpOwogICAgICAgICAgICAgIGlmIChpIC0gZm91bmRJbmRleCArIDEgPT09IHZhbExlbmd0aCkKICAgICAgICAgICAgICAgIHJldHVybiBmb3VuZEluZGV4ICogaW5kZXhTaXplOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIGlmIChmb3VuZEluZGV4ICE9PSAtMSkKICAgICAgICAgICAgICAgIGkgLT0gaSAtIGZvdW5kSW5kZXg7CiAgICAgICAgICAgICAgZm91bmRJbmRleCA9IC0xOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIGlmIChieXRlT2Zmc2V0ICsgdmFsTGVuZ3RoID4gYXJyTGVuZ3RoKQogICAgICAgICAgICBieXRlT2Zmc2V0ID0gYXJyTGVuZ3RoIC0gdmFsTGVuZ3RoOwogICAgICAgICAgZm9yIChpID0gYnl0ZU9mZnNldDsgaSA+PSAwOyBpLS0pIHsKICAgICAgICAgICAgbGV0IGZvdW5kID0gdHJ1ZTsKICAgICAgICAgICAgZm9yIChsZXQgaiA9IDA7IGogPCB2YWxMZW5ndGg7IGorKykgewogICAgICAgICAgICAgIGlmIChyZWFkKGFyciwgaSArIGopICE9PSByZWFkKHZhbCwgaikpIHsKICAgICAgICAgICAgICAgIGZvdW5kID0gZmFsc2U7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKGZvdW5kKQogICAgICAgICAgICAgIHJldHVybiBpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gLTE7CiAgICAgIH0KICAgICAgQnVmZmVyMTAucHJvdG90eXBlLmluY2x1ZGVzID0gZnVuY3Rpb24gaW5jbHVkZXModmFsLCBieXRlT2Zmc2V0LCBlbmNvZGluZykgewogICAgICAgIHJldHVybiB0aGlzLmluZGV4T2YodmFsLCBieXRlT2Zmc2V0LCBlbmNvZGluZykgIT09IC0xOwogICAgICB9OwogICAgICBCdWZmZXIxMC5wcm90b3R5cGUuaW5kZXhPZiA9IGZ1bmN0aW9uIGluZGV4T2YodmFsLCBieXRlT2Zmc2V0LCBlbmNvZGluZykgewogICAgICAgIHJldHVybiBiaWRpcmVjdGlvbmFsSW5kZXhPZih0aGlzLCB2YWwsIGJ5dGVPZmZzZXQsIGVuY29kaW5nLCB0cnVlKTsKICAgICAgfTsKICAgICAgQnVmZmVyMTAucHJvdG90eXBlLmxhc3RJbmRleE9mID0gZnVuY3Rpb24gbGFzdEluZGV4T2YodmFsLCBieXRlT2Zmc2V0LCBlbmNvZGluZykgewogICAgICAgIHJldHVybiBiaWRpcmVjdGlvbmFsSW5kZXhPZih0aGlzLCB2YWwsIGJ5dGVPZmZzZXQsIGVuY29kaW5nLCBmYWxzZSk7CiAgICAgIH07CiAgICAgIGZ1bmN0aW9uIGhleFdyaXRlKGJ1Ziwgc3RyaW5nLCBvZmZzZXQsIGxlbmd0aCkgewogICAgICAgIG9mZnNldCA9IE51bWJlcihvZmZzZXQpIHx8IDA7CiAgICAgICAgY29uc3QgcmVtYWluaW5nID0gYnVmLmxlbmd0aCAtIG9mZnNldDsKICAgICAgICBpZiAoIWxlbmd0aCkgewogICAgICAgICAgbGVuZ3RoID0gcmVtYWluaW5nOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBsZW5ndGggPSBOdW1iZXIobGVuZ3RoKTsKICAgICAgICAgIGlmIChsZW5ndGggPiByZW1haW5pbmcpIHsKICAgICAgICAgICAgbGVuZ3RoID0gcmVtYWluaW5nOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBjb25zdCBzdHJMZW4gPSBzdHJpbmcubGVuZ3RoOwogICAgICAgIGlmIChsZW5ndGggPiBzdHJMZW4gLyAyKSB7CiAgICAgICAgICBsZW5ndGggPSBzdHJMZW4gLyAyOwogICAgICAgIH0KICAgICAgICBsZXQgaTsKICAgICAgICBmb3IgKGkgPSAwOyBpIDwgbGVuZ3RoOyArK2kpIHsKICAgICAgICAgIGNvbnN0IHBhcnNlZCA9IHBhcnNlSW50KHN0cmluZy5zdWJzdHIoaSAqIDIsIDIpLCAxNik7CiAgICAgICAgICBpZiAobnVtYmVySXNOYU4ocGFyc2VkKSkKICAgICAgICAgICAgcmV0dXJuIGk7CiAgICAgICAgICBidWZbb2Zmc2V0ICsgaV0gPSBwYXJzZWQ7CiAgICAgICAgfQogICAgICAgIHJldHVybiBpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIHV0ZjhXcml0ZShidWYsIHN0cmluZywgb2Zmc2V0LCBsZW5ndGgpIHsKICAgICAgICByZXR1cm4gYmxpdEJ1ZmZlcih1dGY4VG9CeXRlcyhzdHJpbmcsIGJ1Zi5sZW5ndGggLSBvZmZzZXQpLCBidWYsIG9mZnNldCwgbGVuZ3RoKTsKICAgICAgfQogICAgICBmdW5jdGlvbiBhc2NpaVdyaXRlKGJ1Ziwgc3RyaW5nLCBvZmZzZXQsIGxlbmd0aCkgewogICAgICAgIHJldHVybiBibGl0QnVmZmVyKGFzY2lpVG9CeXRl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gICAgICAgIGlmIChlbmNvZGluZyA9PT0gdm9pZCAwKQogICAgICAgICAgICAgIGVuY29kaW5nID0gInV0ZjgiOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgZW5jb2RpbmcgPSBsZW5ndGg7CiAgICAgICAgICAgIGxlbmd0aCA9IHZvaWQgMDsKICAgICAgICAgIH0KICAgICAgICB9IGVsc2UgewogICAgICAgICAgdGhyb3cgbmV3IEVycm9yKCJCdWZmZXIud3JpdGUoc3RyaW5nLCBlbmNvZGluZywgb2Zmc2V0WywgbGVuZ3RoXSkgaXMgbm8gbG9uZ2VyIHN1cHBvcnRlZCIpOwogICAgICAgIH0KICAgICAgICBjb25zdCByZW1haW5pbmcgPSB0aGlzLmxlbmd0aCAtIG9mZnNldDsKICAgICAgICBpZiAobGVuZ3RoID09PSB2b2lkIDAgfHwgbGVuZ3RoID4gcmVtYWluaW5nKQogICAgICAgICAgbGVuZ3RoID0gcmVtYWluaW5nOwogICAgICAgIGlmIChzdHJpbmcubGVuZ3RoID4gMCAmJiAobGVuZ3RoIDwgMCB8fCBvZmZzZXQgPCAwKSB8fCBvZmZzZXQgPiB0aGlzLmxlbmd0aCkgewogICAgICAgICAgdGhyb3cgbmV3IFJhbmdlRXJyb3IoIkF0dGVtcHQgdG8gd3JpdGUgb3V0c2lkZSBidWZmZXIgYm91bmRzIik7CiAgICAgICAgfQogICAgICAgIGlmICghZW5jb2RpbmcpCiAgICAgICAgICBlbmNvZGluZyA9ICJ1dGY4IjsKICAgICAgICBsZXQgbG93ZXJlZENhc2UgPSBmYWxzZTsKICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgIHN3aXRjaCAoZW5jb2RpbmcpIHsKICAgICAgICAgICAgY2FzZSAiaGV4IjoKICAgICAgICAgICAgICByZXR1cm4gaGV4V3JpdGUodGhpcywgc3RyaW5nLCBvZmZzZXQsIGxlbmd0aCk7CiAgICAgICAgICAgIGNhc2UgInV0ZjgiOgogICAgICAgICAgICBjYXNlICJ1dGYtOCI6CiAgICAgICAgICAgICAgcmV0dXJuIHV0ZjhXcml0ZSh0aGlzLCBzdHJpbmcsIG9mZnNldCwgbGVuZ3RoKTsKICAgICAgICAgICAgY2FzZSAiYXNjaWkiOgogICAgICAgICAgICBjYXNlICJsYXRpbjEiOgogICAgICAgICAgICBjYXNlICJiaW5hcnkiOgogICAgICAgICAgICAgIHJldHVybiBhc2NpaVdyaXRlKHRoaXMsIHN0cmluZywgb2Zmc2V0LCBsZW5ndGgpOwogICAgICAgICAgICBjYXNlICJiYXNlNjQiOgogICAgICAgICAgICAgIHJldHVybiBiYXNlNjRXcml0ZSh0aGlzLCBzdHJpbmcsIG9mZnNldCwgbGVuZ3RoKTsKICAgICAgICAgICAgY2FzZSAidWNzMiI6CiAgICAgICAgICAgIGNhc2UgInVjcy0yIjoKICAgICAgICAgICAgY2FzZSAidXRmMTZsZSI6CiAgICAgICAgICAgIGNhc2UgInV0Zi0xNmxlIjoKICAgICAgICAgICAgICByZXR1cm4gdWNzMldyaXRlKHRoaXMsIHN0cmluZywgb2Zmc2V0LCBsZW5ndGgpOwogICAgICAgICAgICBkZWZhdWx0OgogICAgICAgICAgICAgIGlmIChsb3dlcmVkQ2FzZSkKICAgICAgICAgICAgICAgIHRocm93IG5ldyBUeXBlRXJyb3IoIlVua25vd24gZW5jb2Rpbmc6ICIgKyBlbmNvZGluZyk7CiAgICAgICAgICAgICAgZW5jb2RpbmcgPSAoIiIgKyBlbmNvZGluZykudG9Mb3dlckNhc2UoKTsKICAgICAgICAgICAgICBsb3dlcmVkQ2FzZSA9IHRydWU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9OwogICAgICBCdWZmZXIxMC5wcm90b3R5cGUudG9KU09OID0gZnVuY3Rpb24gdG9KU09OKCkgewogICAgICAgIHJldHVybiB7CiAgICAgICAgICB0eXBlOiAiQnVmZmVyIiwKICAgICAgICAgIGRhdGE6IEFycmF5LnByb3RvdHlwZS5zbGljZS5jYWxsKHRoaXMuX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ICAgY29kZVBvaW50ID0gZmlyc3RCeXRlOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgY2FzZSAyOgogICAgICAgICAgICAgICAgc2Vjb25kQnl0ZSA9IGJ1ZltpICsgMV07CiAgICAgICAgICAgICAgICBpZiAoKHNlY29uZEJ5dGUgJiAxOTIpID09PSAxMjgpIHsKICAgICAgICAgICAgICAgICAgdGVtcENvZGVQb2ludCA9IChmaXJzdEJ5dGUgJiAzMSkgPDwgNiB8IHNlY29uZEJ5dGUgJiA2MzsKICAgICAgICAgICAgICAgICAgaWYgKHRlbXBDb2RlUG9pbnQgPiAxMjcpIHsKICAgICAgICAgICAgICAgICAgICBjb2RlUG9pbnQgPSB0ZW1wQ29kZVBvaW50OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICBjYXNlIDM6CiAgICAgICAgICAgICAgICBzZWNvbmRCeXRlID0gYnVmW2kgKyAxXTsKICAgICAgICAgICAgICAgIHRoaXJkQnl0ZSA9IGJ1ZltpICsgMl07CiAgICAgICAgICAgICAgICBpZiAoKHNlY29uZEJ5dGUgJiAxOTIpID09PSAxMjggJiYgKHRoaXJkQnl0ZSAmIDE5MikgPT09IDEyOCkgewogICAgICAgICAgICAgICAgICB0ZW1wQ29kZVBvaW50ID0gKGZpcnN0Qnl0ZSAmIDE1KSA8PCAxMiB8IChzZWNvbmRCeXRlICYgNjMpIDw8IDYgfCB0aGlyZEJ5dGUgJiA2MzsKICAgICAgICAgICAgICAgICAgaWYgKHRlbXBDb2RlUG9pbnQgPiAyMDQ3ICYmICh0ZW1wQ29kZVBvaW50IDwgNTUyOTYgfHwgdGVtcENvZGVQb2ludCA+IDU3MzQzKSkgewogICAgICAgICAgICAgICAgICAgIGNvZGVQb2ludCA9IHRlbXBDb2RlUG9pbnQ7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgIGNhc2UgNDoKICAgICAgICAgICAgICAgIHNlY29uZEJ5dGUgPSBidWZbaSArIDFdOwogICAgICAgICAgICAgICAgdGhpcmRCeXRlID0gYnVmW2kgKyAyXTsKICAgICAgICAgICAgICAgIGZvdXJ0aEJ5dGUgPSBidWZbaSArIDNdOwogICAgICAgICAgICAgICAgaWYgKChzZWNvbmRCeXRlICYgMTkyKSA9PT0gMTI4ICYmICh0aGlyZEJ5dGUgJiAxOTIpID09PSAxMjggJiYgKGZvdXJ0aEJ5dGUgJiAxOTIpID09PSAxMjgpIHsKICAgICAgICAgICAgICAgICAgdGVtcENvZGVQb2ludCA9IChmaXJzdEJ5dGUgJiAxNSkgPDwgMTggfCAoc2Vjb25kQnl0ZSAmIDYzKSA8PCAxMiB8ICh0aGlyZEJ5dGUgJiA2MykgPDwgNiB8IGZvdXJ0aEJ5dGUgJiA2MzsKICAgICAgICAgICAgICAgICAgaWYgKHRlbXBDb2RlUG9pbnQgPiA2NTUzNSAmJiB0ZW1wQ29kZVBvaW50IDwgMTExNDExMikgewogICAgICAgICAgICAgICAgICAgIGNvZGVQb2ludCA9IHRlbXBDb2RlUG9pbnQ7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgaWYgKGNvZGVQb2ludCA9PT0gbnVsbCkgewogICAgICAgICAgICBjb2RlUG9pbnQgPSA2NTUzMzsKICAgICAgICAgICAgYnl0ZXNQZXJTZXF1ZW5jZSA9IDE7CiAgICAgICAgICB9IGVsc2UgaWYgKGNvZGVQb2ludCA+IDY1NTM1KSB7CiAgICAgICAgICAgIGNvZGVQb2ludCAtPSA2NTUzNjsKICAgICAgICAgICAgcmVzLnB1c2goY29kZVBvaW50ID4+PiAxMCAmIDEwMjMgfCA1NTI5Nik7CiAgICAgICAgICAgIGNvZGVQb2ludCA9IDU2MzIwIHwgY29kZVBvaW50ICYgMTAyMzsKICAgICAgICAgIH0KICAgICAgICAgIHJlcy5wdXNoKGNvZGVQb2ludCk7CiAgICAgICAgICBpICs9IGJ5dGVzUGVyU2VxdWVuY2U7CiAgICAgICAgfQogICAgICAgIHJldHVybiBkZWNvZGVDb2RlUG9pbnRzQXJyYXkocmVzKTsKICAgICAgfQogICAgICB2YXIgTUFYX0FSR1VNRU5UU19MRU5HVEggPSA0MDk2OwogICAgICBmdW5jdGlvbiBkZWNvZGVDb2RlUG9pbnRzQXJyYXkoY29kZVBvaW50cykgewogICAgICAgIGNvbnN0IGxlbiA9IGNvZGVQb2ludHMubGVuZ3RoOwogICAgICAgIGlmIChsZW4gPD0gTUFYX0FSR1VNRU5UU19MRU5HVEgpIHsKICAgICAgICAgIHJldHVybiBTdHJpbmcuZnJvbUNoYXJDb2RlLmFwcGx5KFN0cmluZywgY29kZVBvaW50cyk7CiAgICAgICAgfQogICAgICAgIGxldCByZXMgPSAiIjsKICAgICAgICBsZXQgaSA9IDA7CiAgICAgICAgd2hpbGUgKGkgPCBsZW4pIHsKICAgICAgICAgIHJlcyArPSBTdHJpbmcuZnJvbUNoYXJDb2RlLmFwcGx5KFN0cmluZywgY29kZVBvaW50cy5zbGljZShpLCBpICs9IE1BWF9BUkdVTUVOVFNfTEVOR1RIKSk7CiAgICAgICAgfQogICAgICAgIHJldHVybiByZXM7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gYXNjaWlTbGljZShidWYsIHN0YXJ0LCBlbmQpIHsKICAgICAgICBsZXQgcmV0ID0gIiI7CiAgICAgICAgZW5kID0gTWF0aC5taW4oYnVmLmxlbmd0aCwgZW5kKTsKICAgICAgICBmb3IgKGxldCBpID0gc3RhcnQ7IGkgPCBlbmQ7ICsraSkgewogICAgICAgICAgcmV0ICs9IFN0cmluZy5mcm9tQ2hhckNvZGUoYnVmW2ldICYgMTI3KTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHJldDsKICAgICAgfQogICAgICBmdW5jdGlvbiBsYXRpbjFTbGljZShidWYsIHN0YXJ0LCBlbmQpIHsKICAgICAgICBsZXQgcmV0ID0gIiI7CiAgICAgICAgZW5kID0gTWF0aC5taW4oYnVmLmxlbmd0aCwgZW5kKTsKICAgICAgICBmb3IgKGxldCBpID0gc3RhcnQ7IGkgPCBlbmQ7ICsraSkgewogICAgICAgICAgcmV0ICs9IFN0cmluZy5mcm9tQ2hhckNvZGUoYnVmW2ldKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHJldDsKICAgICAgfQogICAgICBmdW5jdGlvbiBoZXhTbGljZShidWYsIHN0YXJ0LCBlbmQpIHsKICAgICAgICBjb25zdCBsZW4gPSBidWYubGVuZ3RoOwogICAgICAgIGlmICghc3RhcnQgfHwgc3RhcnQgPCAwKQogICAgICAgICAgc3RhcnQgPSAwOwogICAgICAgIGlmICghZW5kIHx8IGVuZCA8IDAgfHwgZW5kID4gbGVuKQogICAgICAgICAgZW5kID0gbGVuOwogICAgICAgIGxldCBvdXQgPSAiIjsKICAgICAgICBmb3IgKGxldCBpID0gc3RhcnQ7IGkgPCBlbmQ7ICsraSkgewogICAgICAgICAgb3V0ICs9IGhleFNsaWNlTG9va3VwVGFibGVbYnVmW2ldXTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIG91dDsKICAgICAgfQogICAgICBmdW5jdGlvbiB1dGYxNmxlU2xpY2UoYnVmLCBzdGFydCwgZW5kKSB7CiAgICAgICAgY29uc3QgYnl0ZXMgPSBidWYuc2xpY2Uoc3RhcnQsIGVuZCk7CiAgICAgICAgbGV0IHJlcyA9ICIiOwogICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgYnl0ZXMubGVuZ3RoIC0gMTsgaSArPSAyKSB7CiAgICAgICAgICByZXMgKz0gU3RyaW5nLmZyb21DaGFyQ29kZShieXRlc1tpXSArIGJ5dGVzW2kgKyAxXSAqIDI1Nik7CiAgICAgICAgfQogICAgICAgIHJldHVybiByZXM7CiAgICAgIH0KICAgICAgQnVmZmVyMTAucHJvdG90eXBlLnNsaWNlID0gZnVuY3Rpb24gc2xpY2Uoc3RhcnQsIGVuZCkgewogICAgICAgIGNvbnN0IGxlbiA9IHRoaXMubGVuZ3RoOwogICAgICAgIHN0YXJ0ID0gfn5zdGFydDsKICAgICAgICBlbmQgPSBlbmQgPT09IHZvaWQgMCA/IGxlbiA6IH5+ZW5kOwogICAgICAgIGlmIChzdGFydCA8IDApIHsKICAgICAgICAgIHN0YXJ0ICs9IGxlbjsKICAgICAgICAgIGlmIChzdGFydCA8IDApCiAgICAgICAgICAgIHN0YXJ0ID0gMDsKICAgICAgICB9IGVsc2UgaWYgKHN0YXJ0ID4gbGVuKSB7CiAgICAgICAgICBzdGFydCA9IGxlbjsKICAgICAgICB9CiAgICAgICAgaWYgKGVuZCA8IDApIHsKICAgICAgICAgIGVuZCArPSBsZW47CiAgICAgICAgICBpZiAoZW5kIDwgMCkKICAgICAgICAgICAgZW5kID0gMDsKICAgICAgICB9IGVsc2UgaWYgKGVuZCA+IGxlbikgewogICAgICAgICAgZW5kID0gbGVuOwogICAgICAgIH0KICAgICAgICBpZiAoZW5kIDwgc3RhcnQpCiAgICAgICAgICBlbmQgPSBzdGFydDsKICAgICAgICBjb25zdCBuZXdCdWYgPSB0aGlzLnN1YmFycmF5KHN0YXJ0LCBlbmQpOwogICAgICAgIE9iamVjdC5zZXRQcm90b3R5cGVPZihuZXdCdWYsIEJ1ZmZlcjEwLnByb3RvdHlwZSk7CiAgICAgICAgcmV0dXJuIG5ld0J1ZjsKICAgICAgfTsKICAgICAgZnVuY3Rpb24gY2hlY2tPZmZzZXQob2Zmc2V0LCBleHQsIGxlbmd0aCkgewogICAgICAgIGlmIChvZmZzZXQgJSAxICE9PSAwIHx8IG9mZnNldCA8IDApCiAgICAgICAgICB0aHJvdyBuZXcgUmFuZ2VFcnJvcigib2Zmc2V0IGlzIG5vdCB1aW50Iik7CiAgICAgICAgaWYgKG9mZnNldCArIGV4dCA+IGxl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XVsICo9IDI1NikpIHsKICAgICAgICAgIHZhbCArPSB0aGlzW29mZnNldCArIGldICogbXVsOwogICAgICAgIH0KICAgICAgICBtdWwgKj0gMTI4OwogICAgICAgIGlmICh2YWwgPj0gbXVsKQogICAgICAgICAgdmFsIC09IE1hdGgucG93KDIsIDggKiBieXRlTGVuZ3RoMik7CiAgICAgICAgcmV0dXJuIHZhbDsKICAgICAgfTsKICAgICAgQnVmZmVyMTAucHJvdG90eXBlLnJlYWRJbnRCRSA9IGZ1bmN0aW9uIHJlYWRJbnRCRShvZmZzZXQsIGJ5dGVMZW5ndGgyLCBub0Fzc2VydCkgewogICAgICAgIG9mZnNldCA9IG9mZnNldCA+Pj4gMDsKICAgICAgICBieXRlTGVuZ3RoMiA9IGJ5dGVMZW5ndGgyID4+PiAwOwogICAgICAgIGlmICghbm9Bc3NlcnQpCiAgICAgICAgICBjaGVja09mZnNldChvZmZzZXQsIGJ5dGVMZW5ndGgyLCB0aGlzLmxlbmd0aCk7CiAgICAgICAgbGV0IGkgPSBieXRlTGVuZ3RoMjsKICAgICAgICBsZXQgbXVsID0gMTsKICAgICAgICBsZXQgdmFsID0gdGhpc1tvZmZzZXQgKyAtLWldOwogICAgICAgIHdoaWxlIChpID4gMCAmJiAobXVsICo9IDI1NikpIHsKICAgICAgICAgIHZhbCArPSB0aGlzW29mZnNldCArIC0taV0gKiBtdWw7CiAgICAgICAgfQogICAgICAgIG11bCAqPSAxMjg7CiAgICAgICAgaWYgKHZhbCA+PSBtdWwpCiAgICAgICAgICB2YWwgLT0gTWF0aC5wb3coMiwgOCAqIGJ5dGVMZW5ndGgyKTsKICAgICAgICByZXR1cm4gdmFsOwogICAgICB9OwogICAgICBCdWZmZXIxMC5wcm90b3R5cGUucmVhZEludDggPSBmdW5jdGlvbiByZWFkSW50OChvZmZzZXQsIG5vQXNzZXJ0KSB7CiAgICAgICAgb2Zmc2V0ID0gb2Zmc2V0ID4+PiAwOwogICAgICAgIGlmICghbm9Bc3NlcnQpC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GxvID0gbG8gPj4gODsKICAgICAgICBidWZbb2Zmc2V0KytdID0gbG87CiAgICAgICAgbG8gPSBsbyA+PiA4OwogICAgICAgIGJ1ZltvZmZzZXQrK10gPSBsbzsKICAgICAgICBsZXQgaGkgPSBOdW1iZXIodmFsdWUgPj4gQmlnSW50KDMyKSAmIEJpZ0ludCg0Mjk0OTY3Mjk1KSk7CiAgICAgICAgYnVmW29mZnNldCsrXSA9IGhpOwogICAgICAgIGhpID0gaGkgPj4gODsKICAgICAgICBidWZbb2Zmc2V0KytdID0gaGk7CiAgICAgICAgaGkgPSBoaSA+PiA4OwogICAgICAgIGJ1ZltvZmZzZXQrK10gPSBoaTsKICAgICAgICBoaSA9IGhpID4+IDg7CiAgICAgICAgYnVmW29mZnNldCsrXSA9IGhpOwogICAgICAgIHJldHVybiBvZmZzZXQ7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gd3J0QmlnVUludDY0QkUoYnVmLCB2YWx1ZSwgb2Zmc2V0LCBtaW4sIG1heCkgewogICAgICAgIGNoZWNrSW50QkkodmFsdWUsIG1pbiwgbWF4LCBidWYsIG9mZnNldCwgNyk7CiAgICAgICAgbGV0IGxvID0gTnVtYmVyKHZhbHVlICYgQmlnSW50KDQyOTQ5NjcyOTUpKTsKICAgICAgICBidWZbb2Zmc2V0ICsgN10gPSBsbzsKICAgICAgICBsbyA9IGxvID4+IDg7CiAgICAgICAgYnVmW29mZnNldCArIDZdID0gbG87CiAgICAgICAgbG8gPSBsbyA+PiA4OwogICAgICAgIGJ1ZltvZmZzZXQgKyA1XSA9IGxvOwogICAgICAgIGxvID0gbG8gPj4gODsKICAgICAgICBidWZbb2Zmc2V0ICsgNF0gPSBsbzsKICAgICAgICBsZXQgaGkgPSBOdW1iZXIodmFsdWUgPj4gQmlnSW50KDMyKSAmIEJpZ0ludCg0Mjk0OTY3Mjk1KSk7CiAgICAgICAgYnVmW29mZnNldCArIDNdID0gaGk7CiAgICAgICAgaGkgPSBoaSA+PiA4OwogICAg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lsbCh2YWwsIHN0YXJ0LCBlbmQsIGVuY29kaW5nKSB7CiAgICAgICAgaWYgKHR5cGVvZiB2YWwgPT09ICJzdHJpbmciKSB7CiAgICAgICAgICBpZiAodHlwZW9mIHN0YXJ0ID09PSAic3RyaW5nIikgewogICAgICAgICAgICBlbmNvZGluZyA9IHN0YXJ0OwogICAgICAgICAgICBzdGFydCA9IDA7CiAgICAgICAgICAgIGVuZCA9IHRoaXMubGVuZ3RoOwogICAgICAgICAgfSBlbHNlIGlmICh0eXBlb2YgZW5kID09PSAic3RyaW5nIikgewogICAgICAgICAgICBlbmNvZGluZyA9IGVuZDsKICAgICAgICAgICAgZW5kID0gdGhpcy5sZW5ndGg7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoZW5jb2RpbmcgIT09IHZvaWQgMCAmJiB0eXBlb2YgZW5jb2RpbmcgIT09ICJzdHJpbmciKSB7CiAgICAgICAgICAgIHRocm93IG5ldyBUeXBlRXJyb3IoImVuY29kaW5nIG11c3QgYmUgYSBzdHJpbmciKTsKICAgICAgICAgIH0KICAgICAgICAgIGlmICh0eXBlb2YgZW5jb2RpbmcgPT09ICJzdHJpbmciICYmICFCdWZmZXIxMC5pc0VuY29kaW5nKGVuY29kaW5nKSkgewogICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCJVbmtub3duIGVuY29kaW5nOiAiICsgZW5jb2RpbmcpOwogICAgICAgICAgfQogICAgICAgICAgaWYgKHZhbC5sZW5ndGggPT09IDEpIHsKICAgICAgICAgICAgY29uc3QgY29kZSA9IHZhbC5jaGFyQ29kZUF0KDApOwogICAgICAgICAgICBpZiAoZW5jb2RpbmcgPT09ICJ1dGY4IiAmJiBjb2RlIDwgMTI4IHx8IGVuY29kaW5nID09PSAibGF0aW4xIikgewogICAgICAgICAgICAgIHZhbCA9IGNvZGU7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9IGVsc2UgaWYgKHR5cGVvZiB2YWwgPT09ICJudW1iZX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gICAgICAgIGZvciAoaSA9IDA7IGkgPCBlbmQgLSBzdGFydDsgKytpKSB7CiAgICAgICAgICAgIHRoaXNbaSArIHN0YXJ0XSA9IGJ5dGVzW2kgJSBsZW5dOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gdGhpczsKICAgICAgfTsKICAgICAgdmFyIGVycm9ycyA9IHt9OwogICAgICBmdW5jdGlvbiBFKHN5bSwgZ2V0TWVzc2FnZSwgQmFzZSkgewogICAgICAgIGVycm9yc1tzeW1dID0gY2xhc3MgTm9kZUVycm9yIGV4dGVuZHMgQmFzZSB7CiAgICAgICAgICBjb25zdHJ1Y3RvcigpIHsKICAgICAgICAgICAgc3VwZXIoKTsKICAgICAgICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KHRoaXMsICJtZXNzYWdlIiwgewogICAgICAgICAgICAgIHZhbHVlOiBnZXRNZXNzYWdlLmFwcGx5KHRoaXMsIGFyZ3VtZW50cyksCiAgICAgICAgICAgICAgd3JpdGFibGU6IHRydWUsCiAgICAgICAgICAgICAgY29uZmlndXJhYmxlOiB0cnVlCiAgICAgICAgICAgIH0pOwogICAgICAgICAgICB0aGlzLm5hbWUgPSBgJHt0aGlzLm5hbWV9IFske3N5bX1dYDsKICAgICAgICAgICAgdGhpcy5zdGFjazsKICAgICAgICAgICAgZGVsZXRlIHRoaXMubmFtZTsKICAgICAgICAgIH0KICAgICAgICAgIGdldCBjb2RlKCkgewogICAgICAgICAgICByZXR1cm4gc3ltOwogICAgICAgICAgfQogICAgICAgICAgc2V0IGNvZGUodmFsdWUpIHsKICAgICAgICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KHRoaXMsICJjb2RlIiwgewogICAgICAgICAgICAgIGNvbmZpZ3VyYWJsZTogdHJ1ZSwKICAgICAgICAgICAgICBlbnVtZXJhYmxlOiB0cnVlLAogICAgICAgICAgICAgIHZhbHVlLAogICAgICAgICAgICAgIHdyaXRhYmxlOiB0cnVlCiAgICAgICAg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zRXJyb3Iob2Zmc2V0LCBidWYubGVuZ3RoIC0gKGJ5dGVMZW5ndGgyICsgMSkpOwogICAgICAgIH0KICAgICAgfQogICAgICBmdW5jdGlvbiBjaGVja0ludEJJKHZhbHVlLCBtaW4sIG1heCwgYnVmLCBvZmZzZXQsIGJ5dGVMZW5ndGgyKSB7CiAgICAgICAgaWYgKHZhbHVlID4gbWF4IHx8IHZhbHVlIDwgbWluKSB7CiAgICAgICAgICBjb25zdCBuID0gdHlwZW9mIG1pbiA9PT0gImJpZ2ludCIgPyAibiIgOiAiIjsKICAgICAgICAgIGxldCByYW5nZTsKICAgICAgICAgIGlmIChieXRlTGVuZ3RoMiA+IDMpIHsKICAgICAgICAgICAgaWYgKG1pbiA9PT0gMCB8fCBtaW4gPT09IEJpZ0ludCgwKSkgewogICAgICAgICAgICAgIHJhbmdlID0gYD49IDAke259IGFuZCA8IDIke259ICoqICR7KGJ5dGVMZW5ndGgyICsgMSkgKiA4fSR7bn1gOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHJhbmdlID0gYD49IC0oMiR7bn0gKiogJHsoYnl0ZUxlbmd0aDIgKyAxKSAqIDggLSAxfSR7bn0pIGFuZCA8IDIgKiogJHsoYnl0ZUxlbmd0aDIgKyAxKSAqIDggLSAxfSR7bn1gOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICByYW5nZSA9IGA+PSAke21pbn0ke259IGFuZCA8PSAke21heH0ke259YDsKICAgICAgICAgIH0KICAgICAgICAgIHRocm93IG5ldyBlcnJvcnMuRVJSX09VVF9PRl9SQU5HRSgidmFsdWUiLCByYW5nZSwgdmFsdWUpOwogICAgICAgIH0KICAgICAgICBjaGVja0JvdW5kcyhidWYsIG9mZnNldCwgYnl0ZUxlbmd0aDIpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIHZhbGlkYXRlTnVtYmVyKHZhbHVlLCBuYW1lKSB7CiAgICAgICAgaWYgKHR5cGVvZiB2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0KICAgICAgICByZXR1cm4gc3RyOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIHV0ZjhUb0J5dGVzKHN0cmluZywgdW5pdHMpIHsKICAgICAgICB1bml0cyA9IHVuaXRzIHx8IEluZmluaXR5OwogICAgICAgIGxldCBjb2RlUG9pbnQ7CiAgICAgICAgY29uc3QgbGVuZ3RoID0gc3RyaW5nLmxlbmd0aDsKICAgICAgICBsZXQgbGVhZFN1cnJvZ2F0ZSA9IG51bGw7CiAgICAgICAgY29uc3QgYnl0ZXMgPSBbXTsKICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IGxlbmd0aDsgKytpKSB7CiAgICAgICAgICBjb2RlUG9pbnQgPSBzdHJpbmcuY2hhckNvZGVBdChpKTsKICAgICAgICAgIGlmIChjb2RlUG9pbnQgPiA1NTI5NSAmJiBjb2RlUG9pbnQgPCA1NzM0NCkgewogICAgICAgICAgICBpZiAoIWxlYWRTdXJyb2dhdGUpIHsKICAgICAgICAgICAgICBpZiAoY29kZVBvaW50ID4gNTYzMTkpIHsKICAgICAgICAgICAgICAgIGlmICgodW5pdHMgLT0gMykgPiAtMSkKICAgICAgICAgICAgICAgICAgYnl0ZXMucHVzaCgyMzksIDE5MSwgMTg5KTsKICAgICAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgICAgIH0gZWxzZSBpZiAoaSArIDEgPT09IGxlbmd0aCkgewogICAgICAgICAgICAgICAgaWYgKCh1bml0cyAtPSAzKSA+IC0xKQogICAgICAgICAgICAgICAgICBieXRlcy5wdXNoKDIzOSwgMTkxLCAxODkpOwogICAgICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGxlYWRTdXJyb2dhdGUgPSBjb2RlUG9pbnQ7CiAgICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKGNvZGVQb2ludCA8IDU2MzIwKSB7CiAgICAgICAgICAgICAgaWYgKCh1bml0cyAtPSAzKSA+IC0xKQogICAgICAgICAgICAgICAgYnl0ZXMucHVzaCgyMzksIDE5MSwgMTg5KTsKICAgICAgICAgICAgICBsZWFkU3Vycm9nYXRlID0gY29kZVBvaW50OwogICAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGNvZGVQb2ludCA9IChsZWFkU3Vycm9nYXRlIC0gNTUyOTYgPDwgMTAgfCBjb2RlUG9pbnQgLSA1NjMyMCkgKyA2NTUzNjsKICAgICAgICAgIH0gZWxzZSBpZiAobGVhZFN1cnJvZ2F0ZSkgewogICAgICAgICAgICBpZiAoKHVuaXRzIC09IDMpID4gLTEpCiAgICAgICAgICAgICAgYnl0ZXMucHVzaCgyMzksIDE5MSwgMTg5KTsKICAgICAgICAgIH0KICAgICAgICAgIGxlYWRTdXJyb2dhdGUgPSBudWxsOwogICAgICAgICAgaWYgKGNvZGVQb2ludCA8IDEyOCkgewogICAgICAgICAgICBpZiAoKHVuaXRzIC09IDEpIDwgMCkKICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgYnl0ZXMucHVzaChjb2RlUG9pbnQpOwogICAgICAgICAgfSBlbHNlIGlmIChjb2RlUG9pbnQgPCAyMDQ4KSB7CiAgICAgICAgICAgIGlmICgodW5pdHMgLT0gMikgPCAwKQogICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICBieXRlcy5wdXNoKGNvZGVQb2ludCA+PiA2IHwgMTkyLCBjb2RlUG9pbnQgJiA2MyB8IDEyOCk7CiAgICAgICAgICB9IGVsc2UgaWYgKGNvZGVQb2ludCA8IDY1NTM2KSB7CiAgICAgICAgICAgIGlmICgodW5pdHMgLT0gMykgPCAwKQogICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICBieXRlcy5wdXNoKGNvZGVQb2ludCA+PiAxMiB8IDIyNCwgY29kZVBvaW50ID4+IDYgJiA2MyB8IDEyOCwgY29kZVBvaW50ICYgNjMgfCAxMjgpOwogICAgICAgICAgfSBlbHNlIGlmIChjb2RlUG9pbnQgPCAxMTE0MTEyKSB7CiAgICAgICAgICAgIGlmICgodW5pdHMgLT0gNCkgPCAwKQogICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICBieXRlcy5wdXNoKGNvZGVQb2ludCA+PiAxOCB8IDI0MCwgY29kZVBvaW50ID4+IDEyICYgNjMgfCAxMjgsIGNvZGVQb2ludCA+PiA2ICYgNjMgfCAxMjgsIGNvZGVQb2ludCAmIDYzIHwgMTI4KTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHRocm93IG5ldyBFcnJvcigiSW52YWxpZCBjb2RlIHBvaW50Iik7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiBieXRlczsKICAgICAgfQogICAgICBmdW5jdGlvbiBhc2NpaVRvQnl0ZXMoc3RyKSB7CiAgICAgICAgY29uc3QgYnl0ZUFycmF5ID0gW107CiAgICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCBzdHIubGVuZ3RoOyArK2kpIHsKICAgICAgICAgIGJ5dGVBcnJheS5wdXNoKHN0ci5jaGFyQ29kZUF0KGkpICYgMjU1KTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIGJ5dGVBcnJheTsKICAgICAgfQogICAgICBmdW5jdGlvbiB1dGYxNmxlVG9CeXRlcyhzdHIsIHVuaXRzKSB7CiAgICAgICAgbGV0IGMsIGhpLCBsbzsKICAgICAgICBjb25zdCBieXRlQXJyYXkgPSBbXTsKICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IHN0ci5sZW5ndGg7ICsraSkgewogICAgICAgICAgaWYgKCh1bml0cyAtPSAyKSA8IDApCiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgYyA9IHN0ci5jaGFyQ29kZUF0KGkpOwogICAgICAgICAgaGkgPSBjID4+IDg7CiAgICAgICAgICBsbyA9IGMgJSAyNTY7CiAgICAgICAgICBieXRlQXJyYXkucHVzaChsbyk7CiAgICAgICAgIC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xNjsgKytpKSB7CiAgICAgICAgICBjb25zdCBpMTYgPSBpICogMTY7CiAgICAgICAgICBmb3IgKGxldCBqID0gMDsgaiA8IDE2OyArK2opIHsKICAgICAgICAgICAgdGFibGVbaTE2ICsgal0gPSBhbHBoYWJldFtpXSArIGFscGhhYmV0W2pdOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gdGFibGU7CiAgICAgIH0oKTsKICAgICAgZnVuY3Rpb24gZGVmaW5lQmlnSW50TWV0aG9kKGZuKSB7CiAgICAgICAgcmV0dXJuIHR5cGVvZiBCaWdJbnQgPT09ICJ1bmRlZmluZWQiID8gQnVmZmVyQmlnSW50Tm90RGVmaW5lZCA6IGZuOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIEJ1ZmZlckJpZ0ludE5vdERlZmluZWQoKSB7CiAgICAgICAgdGhyb3cgbmV3IEVycm9yKCJCaWdJbnQgbm90IHN1cHBvcnRlZCIpOwogICAgICB9CiAgICB9CiAgfSk7CgogIC8vIHNyYy9hbGlhcy9idWZmZXItc2hpbS5qcwogIHZhciBpbXBvcnRfYnVmZmVyOwogIHZhciBpbml0X2J1ZmZlcl9zaGltID0gX19lc20oewogICAgInNyYy9hbGlhcy9idWZmZXItc2hpbS5qcyIoKSB7CiAgICAgIGltcG9ydF9idWZmZXIgPSBfX3RvTW9kdWxlKHJlcXVpcmVfYnVmZmVyKCkpOwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vYWJvcnRjb250cm9sbGVyLXBvbHlmaWxsQDEuNy41L25vZGVfbW9kdWxlcy9hYm9ydGNvbnRyb2xsZXItcG9seWZpbGwvZGlzdC9janMtcG9ueWZpbGwuanMKICB2YXIgcmVxdWlyZV9janNfcG9ueWZpbGwgPSBfX2NvbW1vbkpTKHsKICAgICJub2RlX21vZHVsZXMvLnBucG0vYWJvcnRjb250cm9sbGVyLXBvbHlmaWxsQDEuNy41L25vZGVfbW9kdWxlcy9hYm9ydGNvbnR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gewogICAgICAgIGlmIChwcm90b1Byb3BzKQogICAgICAgICAgX2RlZmluZVByb3BlcnRpZXMoQ29uc3RydWN0b3IucHJvdG90eXBlLCBwcm90b1Byb3BzKTsKICAgICAgICBpZiAoc3RhdGljUHJvcHMpCiAgICAgICAgICBfZGVmaW5lUHJvcGVydGllcyhDb25zdHJ1Y3Rvciwgc3RhdGljUHJvcHMpOwogICAgICAgIE9iamVjdC5kZWZpbmVQcm9wZXJ0eShDb25zdHJ1Y3RvciwgInByb3RvdHlwZSIsIHsKICAgICAgICAgIHdyaXRhYmxlOiBmYWxzZQogICAgICAgIH0pOwogICAgICAgIHJldHVybiBDb25zdHJ1Y3RvcjsKICAgICAgfQogICAgICBmdW5jdGlvbiBfaW5oZXJpdHMoc3ViQ2xhc3MsIHN1cGVyQ2xhc3MpIHsKICAgICAgICBpZiAodHlwZW9mIHN1cGVyQ2xhc3MgIT09ICJmdW5jdGlvbiIgJiYgc3VwZXJDbGFzcyAhPT0gbnVsbCkgewogICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcigiU3VwZXIgZXhwcmVzc2lvbiBtdXN0IGVpdGhlciBiZSBudWxsIG9yIGEgZnVuY3Rpb24iKTsKICAgICAgICB9CiAgICAgICAgc3ViQ2xhc3MucHJvdG90eXBlID0gT2JqZWN0LmNyZWF0ZShzdXBlckNsYXNzICYmIHN1cGVyQ2xhc3MucHJvdG90eXBlLCB7CiAgICAgICAgICBjb25zdHJ1Y3RvcjogewogICAgICAgICAgICB2YWx1ZTogc3ViQ2xhc3MsCiAgICAgICAgICAgIHdyaXRhYmxlOiB0cnVlLAogICAgICAgICAgICBjb25maWd1cmFibGU6IHRydWUKICAgICAgICAgIH0KICAgICAgICB9KTsKICAgICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkoc3ViQ2xhc3MsICJwcm90b3R5cGUiLCB7CiAgICAgICAgICB3cml0YWJsZTogZmFsc2UKICAgICAgICB9KTsKICAgICAgICBpZiAoc3VwZXJDbGFzcykKICAgICAgICAgIF9zZXRQcm90b3R5cGVPZihzdWJDbGFzcywgc3VwZXJDbGFzcyk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gX2dldFByb3RvdHlwZU9mKG8pIHsKICAgICAgICBfZ2V0UHJvdG90eXBlT2YgPSBPYmplY3Quc2V0UHJvdG90eXBlT2YgPyBPYmplY3QuZ2V0UHJvdG90eXBlT2YuYmluZCgpIDogZnVuY3Rpb24gX2dldFByb3RvdHlwZU9mMihvMikgewogICAgICAgICAgcmV0dXJuIG8yLl9fcHJvdG9fXyB8fCBPYmplY3QuZ2V0UHJvdG90eXBlT2YobzIpOwogICAgICAgIH07CiAgICAgICAgcmV0dXJuIF9nZXRQcm90b3R5cGVPZihvKTsKICAgICAgfQogICAgICBmdW5jdGlvbiBfc2V0UHJvdG90eXBlT2YobywgcCkgewogICAgICAgIF9zZXRQcm90b3R5cGVPZiA9IE9iamVjdC5zZXRQcm90b3R5cGVPZiA/IE9iamVjdC5zZXRQcm90b3R5cGVPZi5iaW5kKCkgOiBmdW5jdGlvbiBfc2V0UHJvdG90eXBlT2YyKG8yLCBwMikgewogICAgICAgICAgbzIuX19wcm90b19fID0gcDI7CiAgICAgICAgICByZXR1cm4gbzI7CiAgICAgICAgfTsKICAgICAgICByZXR1cm4gX3NldFByb3RvdHlwZU9mKG8sIHApOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIF9pc05hdGl2ZVJlZmxlY3RDb25zdHJ1Y3QoKSB7CiAgICAgICAgaWYgKHR5cGVvZiBSZWZsZWN0ID09PSAidW5kZWZpbmVkIiB8fCAhUmVmbGVjdC5jb25zdHJ1Y3QpCiAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgaWYgKFJlZmxlY3QuY29uc3RydWN0LnNoYW0pCiAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgaWYgKHR5cGVvZiBQcm94eSA9PT0gImZ1bmN0aW9uIikKICAgICAgICAgIHJldHVybiB0cnVlOwogICAg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y3QgPSBfaXNOYXRpdmVSZWZsZWN0Q29uc3RydWN0KCk7CiAgICAgICAgcmV0dXJuIGZ1bmN0aW9uIF9jcmVhdGVTdXBlckludGVybmFsKCkgewogICAgICAgICAgdmFyIFN1cGVyID0gX2dldFByb3RvdHlwZU9mKERlcml2ZWQpLCByZXN1bHQ7CiAgICAgICAgICBpZiAoaGFzTmF0aXZlUmVmbGVjdENvbnN0cnVjdCkgewogICAgICAgICAgICB2YXIgTmV3VGFyZ2V0ID0gX2dldFByb3RvdHlwZU9mKHRoaXMpLmNvbnN0cnVjdG9yOwogICAgICAgICAgICByZXN1bHQgPSBSZWZsZWN0LmNvbnN0cnVjdChTdXBlciwgYXJndW1lbnRzLCBOZXdUYXJnZXQpOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcmVzdWx0ID0gU3VwZXIuYXBwbHkodGhpcywgYXJndW1lbnRzKTsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBfcG9zc2libGVDb25zdHJ1Y3RvclJldHVybih0aGlzLCByZXN1bHQpOwogICAgICAgIH07CiAgICAgIH0KICAgICAgZnVuY3Rpb24gX3N1cGVyUHJvcEJhc2Uob2JqZWN0LCBwcm9wZXJ0eSkgewogICAgICAgIHdoaWxlICghT2JqZWN0LnByb3RvdHlwZS5oYXNPd25Qcm9wZXJ0eS5jYWxsKG9iamVjdCwgcHJvcGVydHkpKSB7CiAgICAgICAgICBvYmplY3QgPSBfZ2V0UHJvdG90eXBlT2Yob2JqZWN0KTsKICAgICAgICAgIGlmIChvYmplY3QgPT09IG51bGwpCiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIH0KICAgICAgICByZXR1cm4gb2JqZWN0OwogICAgICB9CiAgICAgIGZ1bmN0aW9uIF9nZXQoKSB7CiAgICAgICAgaWYgKHR5cGVvZiBSZWZsZWN0ICE9PSAidW5kZWZpbmVkIiAmJiBSZWZsZWN0LmdldCkgewogICAgICAgICAgX2dldCA9IFJlZmxlY3QuZ2V0LmJpbmQoKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgX2dldCA9IGZ1bmN0aW9uIF9nZXQyKHRhcmdldCwgcHJvcGVydHksIHJlY2VpdmVyKSB7CiAgICAgICAgICAgIHZhciBiYXNlID0gX3N1cGVyUHJvcEJhc2UodGFyZ2V0LCBwcm9wZXJ0eSk7CiAgICAgICAgICAgIGlmICghYmFzZSkKICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgIHZhciBkZXNjID0gT2JqZWN0LmdldE93blByb3BlcnR5RGVzY3JpcHRvcihiYXNlLCBwcm9wZXJ0eSk7CiAgICAgICAgICAgIGlmIChkZXNjLmdldCkgewogICAgICAgICAgICAgIHJldHVybiBkZXNjLmdldC5jYWxsKGFyZ3VtZW50cy5sZW5ndGggPCAzID8gdGFyZ2V0IDogcmVjZWl2ZXIpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHJldHVybiBkZXNjLnZhbHVlOwogICAgICAgICAgfTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIF9nZXQuYXBwbHkodGhpcywgYXJndW1lbnRzKTsKICAgICAgfQogICAgICB2YXIgRW1pdHRlciA9IC8qIEBfX1BVUkVfXyAqLyBmdW5jdGlvbigpIHsKICAgICAgICBmdW5jdGlvbiBFbWl0dGVyMigpIHsKICAgICAgICAgIF9jbGFzc0NhbGxDaGVjayh0aGlzLCBFbWl0dGVyMik7CiAgICAgICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkodGhpcywgImxpc3RlbmVycyIsIHsKICAgICAgICAgICAgdmFsdWU6IHt9LAogICAgICAgICAgICB3cml0YWJsZTogdHJ1ZSwKICAgICAgICAgICAgY29uZmlndXJhYmxlOiB0cnVlCiAgICAgICAgICB9KTsKICAgICAgICB9CiAgICAgICAgX2NyZWF0ZUNsYXNzKEVtaXR0ZXIyLCBbewogICAgICAgICAga2V5OiAiYWRkRXZlbnRMaXN0ZW5lciIsCiAgICAgICAgICB2YWx1ZTogZnVuY3Rpb24gYWRkRXZlbnRMaXN0ZW5lcih0eXBlLCBjYWxsYmFjaywgb3B0aW9ucykgewogICAgICAgICAgICBpZiAoISh0eXBlIGluIHRoaXMubGlzdGVuZXJzKSkgewogICAgICAgICAgICAgIHRoaXMubGlzdGVuZXJzW3R5cGVdID0gW107CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdGhpcy5saXN0ZW5lcnNbdHlwZV0ucHVzaCh7CiAgICAgICAgICAgICAgY2FsbGJhY2ssCiAgICAgICAgICAgICAgb3B0aW9ucwogICAgICAgICAgICB9KTsKICAgICAgICAgIH0KICAgICAgICB9LCB7CiAgICAgICAgICBrZXk6ICJyZW1vdmVFdmVudExpc3RlbmVyIiwKICAgICAgICAgIHZhbHVlOiBmdW5jdGlvbiByZW1vdmVFdmVudExpc3RlbmVyKHR5cGUsIGNhbGxiYWNrKSB7CiAgICAgICAgICAgIGlmICghKHR5cGUgaW4gdGhpcy5saXN0ZW5lcnMpKSB7CiAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHZhciBzdGFjayA9IHRoaXMubGlzdGVuZXJzW3R5cGVdOwogICAgICAgICAgICBmb3IgKHZhciBpID0gMCwgbCA9IHN0YWNrLmxlbmd0aDsgaSA8IGw7IGkrKykgewogICAgICAgICAgICAgIGlmIChzdGFja1tpXS5jYWxsYmFjayA9PT0gY2FsbGJhY2spIHsKICAgICAgICAgICAgICAgIHN0YWNrLnNwbGljZShpLCAxKTsKICAgICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9LCB7CiAgICAgICAgICBrZXk6ICJkaXNwYXRjaEV2ZW50IiwKICAgICAgICAgIHZhbHVlOiBmdW5jdGlvbiBkaXNwYXRjaEV2ZW50KGV2ZW50KSB7CiAgICAgICAgICAgIGlmICghKGV2ZW50LnR5cGUgaW4gdGhpcy5saXN0ZW5lcnMpKSB7CiAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHZhciBzdGFjayA9IHRoaXMubGlzdGVuZXJzW2V2ZW50LnR5cGVdOwogICAgICAgICAgICB2YXIgc3RhY2tUb0NhbGwgPSBzdGFjay5zbGljZSgpOwogICAgICAgICAgICBmb3IgKHZhciBpID0gMCwgbCA9IHN0YWNrVG9DYWxsLmxlbmd0aDsgaSA8IGw7IGkrKykgewogICAgICAgICAgICAgIHZhciBsaXN0ZW5lciA9IHN0YWNrVG9DYWxsW2ldOwogICAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgICBsaXN0ZW5lci5jYWxsYmFjay5jYWxsKHRoaXMsIGV2ZW50KTsKICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7CiAgICAgICAgICAgICAgICBQcm9taXNlLnJlc29sdmUoKS50aGVuKGZ1bmN0aW9uKCkgewogICAgICAgICAgICAgICAgICB0aHJvdyBlOwogICAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGlmIChsaXN0ZW5lci5vcHRpb25zICYmIGxpc3RlbmVyLm9wdGlvbnMub25jZSkgewogICAgICAgICAgICAgICAgdGhpcy5yZW1vdmVFdmVudExpc3RlbmVyKGV2ZW50LnR5cGUsIGxpc3RlbmVyLmNhbGxiYWNrKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgcmV0dXJuICFldmVudC5kZWZhdWx0UHJldmVudGVkOwogICAgICAgICAgfQogICAgICAgIH1dKTsKICAgICAgICByZXR1cm4gRW1pdHRlcjI7CiAgICAgIH0oKTsKICAgICAgdmFyIEFib3J0U2lnbmFsID0gLyogQF9fUFVSRV9fICovIGZ1bmN0aW9uKF9FbWl0dGVyKSB7CiAgICAgICAgX2luaGVyaXRzKEFib3J0U2lnbmFsMiwgX0VtaXR0ZXIpOwogICAgICAgIHZhciBfc3VwZXIgPSBfY3JlYXRlU3VwZXIoQWJvcnRTaWduYWwyKTsKICAgICAgICBmdW5jdGlvbiBBYm9ydFNpZ25hbDIoKSB7CiAgICAgICAgICB2YXIgX3RoaXM7CiAgICAgICAgICBfY2xhc3NDYWxsQ2hlY2sodGhpcywgQWJvcnRTaWduYWwyKTsKICAgICAgICAgIF90aGlzID0gX3N1cGVyLmNhbGwodGhpcyk7CiAgICAgICAgICBpZiAoIV90aGlzLmxpc3RlbmVycykgewogICAgICAgICAgICBFbWl0dGVyLmNhbGwoX2Fzc2VydFRoaXNJbml0aWFsaXplZChfdGhpcykpOwogICAgICAgICAgfQogICAgICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KF9hc3NlcnRUaGlzSW5pdGlhbGl6ZWQoX3RoaXMpLCAiYWJvcnRlZCIsIHsKICAgICAgICAgICAgdmFsdWU6IGZhbHNlLAogICAgICAgICAgICB3cml0YWJsZTogdHJ1ZSwKICAgICAgICAgICAgY29uZmlndXJhYmxlOiB0cnVlCiAgICAgICAgICB9KTsKICAgICAgICAgIE9iamVjdC5kZWZpbmVQcm9wZXJ0eShfYXNzZXJ0VGhpc0luaXRpYWxpemVkKF90aGlzKSwgIm9uYWJvcnQiLCB7CiAgICAgICAgICAgIHZhbHVlOiBudWxsLAogICAgICAgICAgICB3cml0YWJsZTogdHJ1ZSwKICAgICAgICAgICAgY29uZmlndXJhYmxlOiB0cnVlCiAgICAgICAgICB9KTsKICAgICAgICAgIE9iamVjdC5kZWZpbmVQcm9wZXJ0eShfYXNzZXJ0VGhpc0luaXRpYWxpemVkKF90aGlzKSwgInJlYXNvbiIsIHsKICAgICAgICAgICAgdmFsdWU6IHZvaWQgMCwKICAgICAgICAgICAgd3JpdGFibGU6IHRydWUsCiAgICAgICAgICAgIGNvbmZpZ3VyYWJsZTogdHJ1ZQogICAgICAgICAgfSk7CiAgICAgICAgICByZXR1cm4gX3RoaXM7CiAgICAgICAgfQogICAgICAgIF9jcmVhdGVDbGFzcyhBYm9ydFNpZ25hbDIsIFt7CiAgICAgICAgICBrZXk6ICJ0b1N0cmluZyIsCiAgICAgICAgICB2YWx1ZTogZnVuY3Rpb24gdG9TdHJpbmcoKSB7CiAgICAgICAgICAgIHJldHVybiAiW29iamVjdCBBYm9ydFNpZ25hbF0iOwogICAgICAgICAgfQogICAgICAgIH0sIHsKICAgICAgICAgIGtleTogImRpc3BhdGNoRXZlbnQiLAogICAgICAgICAgdmFsdWU6IGZ1bmN0aW9uIGRpc3BhdGNoRXZlbnQoZXZlbnQpIHsKICAgICAgICAgICAgaWYgKGV2ZW50LnR5cGUgPT09ICJhYm9ydCIpIHsKICAgICAgICAgICAgICB0aGlzLmFib3J0ZWQgPSB0cnVlOwogICAgICAgICAgICAgIGlmICh0eXBlb2YgdGhpcy5vbmFib3J0ID09PSAiZnVuY3Rpb24iKSB7CiAgICAgICAgICAgICAgICB0aGlzLm9uYWJvcnQuY2FsbCh0aGlzLCBldmVudCk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIF9nZXQoX2dldFByb3RvdHlwZU9mKEFib3J0U2lnbmFsMi5wcm90b3R5cGUpLCAiZGlzcGF0Y2hFdmVudCIsIHRoaXMpLmNhbGwodGhpcywgZXZlbnQpOwogICAgICAgICAgfQogICAgICAgIH1dKTsKICAgICAgICByZXR1cm4gQWJvcnRTaWduYWwyOwogICAgICB9KEVtaXR0ZXIpOwogICAgICB2YXIgQWJvcnRDb250cm9sbGVyID0gLyogQF9fUFVSRV9fICovIGZ1bmN0aW9uKCkgewogICAgICAgIGZ1bmN0aW9uIEFib3J0Q29udHJvbGxlcjIoKSB7CiAgICAgICAgICBfY2xhc3NDYWxsQ2hlY2sodGhpcywgQWJvcnRDb250cm9sbGVyMik7CiAgICAgICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkodGhpcywgInNpZ25hbCIsIHsKICAgICAgICAgICAgdmFsdWU6IG5ldyBBYm9ydFNpZ25hbCgpLAogICAgICAgICAgICB3cml0YWJsZTogdHJ1ZSwKICAgICAgICAgICAgY29uZmlndXJhYmxlOiB0cnVlCiAgICAgICAgICB9KTsKICAgICAgICB9CiAgICAgICAgX2NyZWF0ZUNsYXNzKEFib3J0Q29udHJvbGxlcjIsIFt7CiAgICAgICAgICBrZXk6ICJhYm9ydCIsCiAgICAgICAgICB2YWx1ZTogZnVuY3Rpb24gYWJvcnQocmVhc29uKSB7CiAgICAgICAgICAgIHZhciBldmVudDsKICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICBldmVudCA9IG5ldyBFdmVudCgiYWJvcnQiKTsKICAgICAgICAgICAgfSBjYXRjaCAoZSkgewogICAgICAgICAgICAgIGlmICh0eXBlb2YgZG9jdW1lbnQgIT09ICJ1bmRlZmluZWQiKSB7CiAgICAgICAgICAgICAgICBpZiAoIWRvY3VtZW50LmNyZWF0ZUV2ZW50KSB7CiAgICAgICAgICAgICAgICAgIGV2ZW50ID0gZG9jdW1lbnQuY3JlYXRlRXZlbnRPYmplY3QoKTsKICAgICAgICAgICAgICAgICAgZXZlbnQudHlwZSA9ICJhYm9ydCI7CiAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICBldmVudCA9IGRvY3VtZW50LmNyZWF0ZUV2ZW50KCJFdmVudCIpOwogICAgICAgICAgICAgICAgICBldmVudC5pbml0RXZlbnQoImFib3J0IiwgZmFsc2UsIGZhbHNlKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgZXZlbnQgPSB7CiAgICAgICAgICAgICAgICAgIHR5cGU6ICJhYm9ydCIsCiAgICAgICAgICAgICAgICAgIGJ1YmJsZXM6IGZhbHNlLAogICAgICAgICAgICAgICAgICBjYW5jZWxhYmxlOiBmYWxzZQogICAgICAgICAgICAgICAgfTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdmFyIHNpZ25hbFJlYXNvbiA9IHJlYXNvbjsKICAgICAgICAgICAgaWYgKHNpZ25hbFJlYXNvbiA9PT0gdm9pZCAwKSB7CiAgICAgICAgICAgICAgaWYgKHR5cGVvZiBkb2N1bWVudCA9PT0gInVuZGVmaW5lZCIpIHsKICAgICAgICAgICAgICAgIHNpZ25hbFJlYXNvbiA9IG5ldyBFcnJvcigiVGhpcyBvcGVyYXRpb24gd2FzIGFib3J0ZWQiKTsKICAgICAgICAgICAgICAgIHNpZ25hbFJlYXNvbi5uYW1lID0gIkFib3J0RXJyb3IiOwogICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgICAgICBzaWduYWxSZWFzb24gPSBuZXcgRE9NRXhjZXB0aW9uKCJzaWduYWwgaXMgYWJvcnRlZCB3aXRob3V0IHJlYXNvbiIpOwogICAgICAgICAgICAgICAgfSBjYXRjaCAoZXJyKSB7CiAgICAgICAgICAgICAgICAgIHNpZ25hbFJlYXNvbiA9IG5ldyBFcnJvcigiVGhpcyBvcGVyYXRpb24gd2FzIGFib3J0ZWQiKTsKICAgICAgICAgICAgICAgICAgc2lnbmFsUmVhc29uLm5hbWUgPSAiQWJvcnRFcnJvciI7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIHRoaXMuc2lnbmFsLnJlYXNvbiA9IHNpZ25hbFJlYXNvbjsKICAgICAgICAgICAgdGhpcy5zaWduYWwuZGlzcGF0Y2hFdmVudChldmVudCk7CiAgICAgICAgICB9CiAgICAgICAgfSwgewogICAgICAgICAga2V5OiAidG9TdHJpbmciLAogICAgICAgICAgdmFsdWU6IGZ1bmN0aW9uIHRvU3RyaW5nKCkgewogICAgICAgICAgICByZXR1cm4gIltvYmplY3QgQWJvcnRDb250cm9sbGVyXSI7CiAgICAgICAgICB9CiAgICAgICAgfV0pOwogICAgICAgIHJldHVybiBBYm9ydENvbnRyb2xsZXIyOwogICAgICB9KCk7CiAgICAgIGlmICh0eXBlb2YgU3ltYm9sICE9PSAidW5kZWZpbmVkIiAmJiBTeW1ib2w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Z1bmN0aW9uIFJlcXVlc3QyKGlucHV0LCBpbml0MikgewogICAgICAgICAgICB2YXIgc2lnbmFsOwogICAgICAgICAgICBpZiAoaW5pdDIgJiYgaW5pdDIuc2lnbmFsKSB7CiAgICAgICAgICAgICAgc2lnbmFsID0gaW5pdDIuc2lnbmFsOwogICAgICAgICAgICAgIGRlbGV0ZSBpbml0Mi5zaWduYWw7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdmFyIHJlcXVlc3QgPSBuZXcgTmF0aXZlUmVxdWVzdChpbnB1dCwgaW5pdDIpOwogICAgICAgICAgICBpZiAoc2lnbmFsKSB7CiAgICAgICAgICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KHJlcXVlc3QsICJzaWduYWwiLCB7CiAgICAgICAgICAgICAgICB3cml0YWJsZTogZmFsc2UsCiAgICAgICAgICAgICAgICBlbnVtZXJhYmxlOiBmYWxzZSwKICAgICAgICAgICAgICAgIGNvbmZpZ3VyYWJsZTogdHJ1ZSwKICAgICAgICAgICAgICAgIHZhbHVlOiBzaWduYWwKICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAgfQogICAgICAgICAgICByZXR1cm4gcmVxdWVzdDsKICAgICAgICAgIH07CiAgICAgICAgICBSZXF1ZXN0LnByb3RvdHlwZSA9IE5hdGl2ZVJlcXVlc3QucHJvdG90eXBlOwogICAgICAgIH0KICAgICAgICB2YXIgcmVhbEZldGNoID0gZmV0Y2g7CiAgICAgICAgdmFyIGFib3J0YWJsZUZldGNoID0gZnVuY3Rpb24gYWJvcnRhYmxlRmV0Y2gyKGlucHV0LCBpbml0MikgewogICAgICAgICAgdmFyIHNpZ25hbCA9IFJlcXVlc3QgJiYgUmVxdWVzdC5wcm90b3R5cGUuaXNQcm90b3R5cGVPZihpbnB1dCkgPyBpbnB1dC5zaWduYWwgOiBpbml0MiA/IGluaXQyLnNpZ25hbCA6IHZvaWQgMDsKICAgICAgICAgIGlmIChzaWduYWwpIHsKICAgICAgICAgICAgdmFyIGFib3J0RXJyb3I7CiAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgYWJvcnRFcnJvciA9IG5ldyBET01FeGNlcHRpb24oIkFib3J0ZWQiLCAiQWJvcnRFcnJvciIpOwogICAgICAgICAgICB9IGNhdGNoIChlcnIpIHsKICAgICAgICAgICAgICBhYm9ydEVycm9yID0gbmV3IEVycm9yKCJBYm9ydGVkIik7CiAgICAgICAgICAgICAgYWJvcnRFcnJvci5uYW1lID0gIkFib3J0RXJyb3IiOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzaWduYWwuYWJvcnRlZCkgewogICAgICAgICAgICAgIHJldHVybiBQcm9taXNlLnJlamVjdChhYm9ydEVycm9yKTsKICAgICAgICAgICAgfQogICAgICAgICAgICB2YXIgY2FuY2VsbGF0aW9uID0gbmV3IFByb21pc2UoZnVuY3Rpb24oXywgcmVqZWN0KSB7CiAgICAgICAgICAgICAgc2lnbmFsLmFkZEV2ZW50TGlzdGVuZXIoImFib3J0IiwgZnVuY3Rpb24oKSB7CiAgICAgICAgICAgICAgICByZXR1cm4gcmVqZWN0KGFib3J0RXJyb3IpOwogICAgICAgICAgICAgIH0sIHsKICAgICAgICAgICAgICAgIG9uY2U6IHRydWUKICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAgfSk7CiAgICAgICAgICAgIGlmIChpbml0MiAmJiBpbml0Mi5zaWduYWwpIHsKICAgICAgICAgICAgICBkZWxldGUgaW5pdDIuc2lnbmFsOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHJldHVybiBQcm9taXNlLnJhY2UoW2NhbmNlbGxhdGlvbiwgcmVhbEZldGNoKGlucHV0LCBpbml0MildKTsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiByZWFsRmV0Y2goaW5wdXQsIGluaXQyKTsKICAgICAgICB9OwogICAgICAgIHJldHVybiB7CiAgICAgICAgICBmZXRjaDogYWJvcnRhYmxlRmV0Y2gsCiAgICAgICAgICBSZXF1ZXN0CiAgICA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LWNhY2hlQDEuNS4wL25vZGVfbW9kdWxlcy9hYm9ydGFibGUtcHJvbWlzZS1jYWNoZS9lc20vQWdncmVnYXRlQWJvcnRDb250cm9sbGVyLmpzIihleHBvcnRzMikgewogICAgICBpbml0X2J1ZmZlcl9zaGltKCk7CiAgICAgICJ1c2Ugc3RyaWN0IjsKICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KGV4cG9ydHMyLCAiX19lc01vZHVsZSIsIHsgdmFsdWU6IHRydWUgfSk7CiAgICAgIHZhciBhYm9ydGNvbnRyb2xsZXJfcG9ueWZpbGxfMSA9IHJlcXVpcmVfYWJvcnRjb250cm9sbGVyX3BvbnlmaWxsKCk7CiAgICAgIHZhciBOdWxsU2lnbmFsID0gY2xhc3MgewogICAgICB9OwogICAgICB2YXIgQWdncmVnYXRlQWJvcnRDb250cm9sbGVyID0gY2xhc3MgewogICAgICAgIGNvbnN0cnVjdG9yKCkgewogICAgICAgICAgdGhpcy5zaWduYWxzID0gbmV3IFNldCgpOwogICAgICAgICAgdGhpcy5hYm9ydENvbnRyb2xsZXIgPSBuZXcgYWJvcnRjb250cm9sbGVyX3BvbnlmaWxsXzEuQWJvcnRDb250cm9sbGVyKCk7CiAgICAgICAgfQogICAgICAgIGFkZFNpZ25hbChzaWduYWwgPSBuZXcgTnVsbFNpZ25hbCgpKSB7CiAgICAgICAgICBpZiAodGhpcy5zaWduYWwuYWJvcnRlZCkgewogICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IoImNhbm5vdCBhZGQgYSBzaWduYWwsIGFscmVhZHkgYWJvcnRlZCEiKTsKICAgICAgICAgIH0KICAgICAgICAgIHRoaXMuc2lnbmFscy5hZGQoc2lnbmFsKTsKICAgICAgICAgIGlmIChzaWduYWwuYWJvcnRlZCkgewogICAgICAgICAgICB0aGlzLmhhbmRsZUFib3J0ZWQoc2lnbmFsKTsKICAgICAgICAgIH0gZWxzZSBpZiAodHlwZW9mIHNpZ25hbC5hZGRFdmVudExpc3Rlb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mFsLCBzdGF0dXNDYWxsYmFjaykgewogICAgICAgICAgY29uc3QgYWJvcnRlciA9IG5ldyBBZ2dyZWdhdGVBYm9ydENvbnRyb2xsZXJfMS5kZWZhdWx0KCk7CiAgICAgICAgICBjb25zdCBzdGF0dXNSZXBvcnRlciA9IG5ldyBBZ2dyZWdhdGVTdGF0dXNSZXBvcnRlcl8xLmRlZmF1bHQoKTsKICAgICAgICAgIHN0YXR1c1JlcG9ydGVyLmFkZENhbGxiYWNrKHN0YXR1c0NhbGxiYWNrKTsKICAgICAgICAgIGNvbnN0IG5ld0VudHJ5ID0gewogICAgICAgICAgICBhYm9ydGVyLAogICAgICAgICAgICBwcm9taXNlOiB0aGlzLmZpbGxDYWxsYmFjayhkYXRhLCBhYm9ydGVyLnNpZ25hbCwgKG1lc3NhZ2UpID0+IHsKICAgICAgICAgICAgICBzdGF0dXNSZXBvcnRlci5jYWxsYmFjayhtZXNzYWdlKTsKICAgICAgICAgICAgfSksCiAgICAgICAgICAgIHNldHRsZWQ6IGZhbHNlLAogICAgICAgICAgICBzdGF0dXNSZXBvcnRlciwKICAgICAgICAgICAgZ2V0IGFib3J0ZWQoKSB7CiAgICAgICAgICAgICAgcmV0dXJuIHRoaXMuYWJvcnRlci5zaWduYWwuYWJvcnRlZDsKICAgICAgICAgICAgfQogICAgICAgICAgfTsKICAgICAgICAgIG5ld0VudHJ5LmFib3J0ZXIuYWRkU2lnbmFsKHNpZ25hbCk7CiAgICAgICAgICBuZXdFbnRyeS5hYm9ydGVyLnNpZ25hbC5hZGRFdmVudExpc3RlbmVyKCJhYm9ydCIsICgpID0+IHsKICAgICAgICAgICAgaWYgKCFuZXdFbnRyeS5zZXR0bGVkKSB7CiAgICAgICAgICAgICAgdGhpcy5ldmljdChrZXksIG5ld0VudHJ5KTsKICAgICAgICAgICAgfQogICAgICAgICAgfSk7CiAgICAgICAgICBuZXdFbnRyeS5wcm9taXNlLnRoZW4oKCkgPT4gewogICAgICAgICAgICBuZXdFbnRyeS5zZXR0bGVkID0gdHJ1ZTsKICAgICAgICAgIH0sICgpID0+IHsKICAgICAgICAgICAgbmV3RW50cnkuc2V0dGxlZCA9IHRydWU7CiAgICAgICAgICAgIHRoaXMuZXZpY3Qoa2V5LCBuZXdFbnRyeSk7CiAgICAgICAgICB9KS5jYXRjaCgoZSkgPT4gewogICAgICAgICAgICBjb25zb2xlLmVycm9yKGUpOwogICAgICAgICAgICB0aHJvdyBlOwogICAgICAgICAgfSk7CiAgICAgICAgICB0aGlzLmNhY2hlLnNldChrZXksIG5ld0VudHJ5KTsKICAgICAgICB9CiAgICAgICAgc3RhdGljIGNoZWNrU2luZ2xlUHJvbWlzZShwcm9taXNlLCBzaWduYWwpIHsKICAgICAgICAgIGZ1bmN0aW9uIGNoZWNrRm9yU2luZ2xlQWJvcnQoKSB7CiAgICAgICAgICAgIGlmIChzaWduYWwgJiYgc2lnbmFsLmFib3J0ZWQpIHsKICAgICAgICAgICAgICB0aHJvdyBPYmplY3QuYXNzaWduKG5ldyBFcnJvcigiYWJvcnRlZCIpLCB7IGNvZGU6ICJFUlJfQUJPUlRFRCIgfSk7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBwcm9taXNlLnRoZW4oKHJlc3VsdCkgPT4gewogICAgICAgICAgICBjaGVja0ZvclNpbmdsZUFib3J0KCk7CiAgICAgICAgICAgIHJldHVybiByZXN1bHQ7CiAgICAgICAgICB9LCAoZXJyb3IpID0+IHsKICAgICAgICAgICAgY2hlY2tGb3JTaW5nbGVBYm9ydCgpOwogICAgICAgICAgICB0aHJvdyBlcnJvcjsKICAgICAgICAgIH0pOwogICAgICAgIH0KICAgICAgICBoYXMoa2V5KSB7CiAgICAgICAgICByZXR1cm4gdGhpcy5jYWNoZS5oYXMoa2V5KTsKICAgICAgICB9CiAgICAgICAgZ2V0KGtleSwgZGF0YSwgc2lnbmFsLCBzdGF0dXNDYWxsYmFjaykgewogICAgICAgICAgaWYgKCFzaWduYWwgJiY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k7CiAgICAgICAgICByZXR1cm4gQWJvcnRhYmxlUHJvbWlzZUNhY2hlMi5jaGVja1NpbmdsZVByb21pc2UodGhpcy5jYWNoZS5nZXQoa2V5KS5wcm9taXNlLCBzaWduYWwpOwogICAgICAgIH0KICAgICAgICBkZWxldGUoa2V5KSB7CiAgICAgICAgICBjb25zdCBjYWNoZWRFbnRyeSA9IHRoaXMuY2FjaGUuZ2V0KGtleSk7CiAgICAgICAgICBpZiAoY2FjaGVkRW50cnkpIHsKICAgICAgICAgICAgaWYgKCFjYWNoZWRFbnRyeS5zZXR0bGVkKSB7CiAgICAgICAgICAgICAgY2FjaGVkRW50cnkuYWJvcnRlci5hYm9ydCgpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHRoaXMuY2FjaGUuZGVsZXRlKGtleSk7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGNsZWFyKCkgewogICAgICAgICAgY29uc3Qga2V5SXRlciA9IHRoaXMuY2FjaGUua2V5cygpOwogICAgICAgICAgbGV0IGRlbGV0ZUNvdW50ID0gMDsKICAgICAgICAgIGZvciAobGV0IHJlc3VsdCA9IGtleUl0ZXIubmV4dCgpOyAhcmVzdWx0LmRvbmU7IHJlc3VsdCA9IGtleUl0ZXIubmV4dCgpKSB7CiAgICAgICAgICAgIHRoaXMuZGVsZXRlKHJlc3VsdC52YWx1ZSk7CiAgICAgICAgICAgIGRlbGV0ZUNvdW50ICs9IDE7CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gZGVsZXRlQ291bnQ7CiAgICAgICAgfQogICAgICB9OwogICAgICBleHBvcnRzMi5kZWZhdWx0ID0gQWJvcnRhYmxlUHJvbWlzZUNhY2hlMjsKICAgIH0KICB9KTsKCiAgLy8gbm9kZV9tb2R1bGVzLy5wbnBtL2Fib3J0YWJsZS1wcm9taXNlLWNhY2hlQDEuNS4wL25vZGVfbW9kdWxlcy9hYm9ydGFibGUtcHJvbWlzZS1jYWNoZS9lc20vaW5kZXguanMKICB2Y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AgIHZhciBRdWlja0xSVSA9IGNsYXNzIHsKICAgICAgICBjb25zdHJ1Y3RvcihvcHRpb25zID0ge30pIHsKICAgICAgICAgIGlmICghKG9wdGlvbnMubWF4U2l6ZSAmJiBvcHRpb25zLm1heFNpemUgPiAwKSkgewogICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCJgbWF4U2l6ZWAgbXVzdCBiZSBhIG51bWJlciBncmVhdGVyIHRoYW4gMCIpOwogICAgICAgICAgfQogICAgICAgICAgdGhpcy5tYXhTaXplID0gb3B0aW9ucy5tYXhTaXplOwogICAgICAgICAgdGhpcy5jYWNoZSA9IG5ldyBNYXAoKTsKICAgICAgICAgIHRoaXMub2xkQ2FjaGUgPSBuZXcgTWFwKCk7CiAgICAgICAgICB0aGlzLl9zaXplID0gMDsKICAgICAgICB9CiAgICAgICAgX3NldChrZXksIHZhbHVlKSB7CiAgICAgICAgICB0aGlzLmNhY2hlLnNldChrZXksIHZhbHVlKTsKICAgICAgICAgIHRoaXMuX3NpemUrKzsKICAgICAgICAgIGlmICh0aGlzLl9zaXplID49IHRoaXMubWF4U2l6ZSkgewogICAgICAgICAgICB0aGlzLl9zaXplID0gMDsKICAgICAgICAgICAgdGhpcy5vbGRDYWNoZSA9IHRoaXMuY2FjaGU7CiAgICAgICAgICAgIHRoaXMuY2FjaGUgPSBuZXcgTWFwKCk7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGdldChrZXkpIHsKICAgICAgICAgIGlmICh0aGlzLmNhY2hlLmhhcyhrZXkpKSB7CiAgICAgICAgICAgIHJldHVybiB0aGlzLmNhY2hlLmdldChrZXkpOwogICAgICAgICAgfQogICAgICAgICAgaWYgKHRoaXMub2xkQ2FjaGUuaGFzKGtleSkpIHsKICAgICAgICAgICAgY29uc3QgdmFsdWUgPSB0aGlzLm9sZENhY2hlLmdldChrZXkpOwogICAgICAgICAgICB0aGlzLm9sZENhY2hlLmRlbGV0ZShrZXkpOwogICAgICAgICAgICB0aGlzLl9zZXQoa2V5LCB2YWx1ZSk7CiAgICAgICAgICAgIHJldHVybiB2YWx1ZTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgc2V0KGtleSwgdmFsdWUpIHsKICAgICAgICAgIGlmICh0aGlzLmNhY2hlLmhhcyhrZXkpKSB7CiAgICAgICAgICAgIHRoaXMuY2FjaGUuc2V0KGtleSwgdmFsdWUpOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgdGhpcy5fc2V0KGtleSwgdmFsdWUpOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIHRoaXM7CiAgICAgICAgfQogICAgICAgIGhhcyhrZXkpIHsKICAgICAgICAgIHJldHVybiB0aGlzLmNhY2hlLmhhcyhrZXkpIHx8IHRoaXMub2xkQ2FjaGUuaGFzKGtleSk7CiAgICAgICAgfQogICAgICAgIHBlZWsoa2V5KSB7CiAgICAgICAgICBpZiAodGhpcy5jYWNoZS5oYXMoa2V5KSkgewogICAgICAgICAgICByZXR1cm4gdGhpcy5jYWNoZS5nZXQoa2V5KTsKICAgICAgICAgIH0KICAgICAgICAgIGlmICh0aGlzLm9sZENhY2hlLmhhcyhrZXkpKSB7CiAgICAgICAgICAgIHJldHVybiB0aGlzLm9sZENhY2hlLmdldChrZXkpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBkZWxldGUoa2V5KSB7CiAgICAgICAgICBjb25zdCBkZWxldGVkID0gdGhpcy5jYWNoZS5kZWxldGUoa2V5KTsKICAgICAgICAgIGlmIChkZWxldGVkKSB7CiAgICAgICAgICAgIHRoaXMuX3NpemUtLTsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiB0aGlzLm9sZENhY2hlLmRlbGV0ZShrZXkpIHx8IGRlbGV0ZWQ7CiAgICAgICAgfQogICAgICAgIGNsZWFyKCkgewogICAgICAgICAgdGhpcy5jYWNoZS5jbGVhcigpOwogICAgICAgICAgdGhpcy5vbGRDYWNoZS5jbGVhcigpOwogICAgICAgICAgdGhpcy5fc2l6ZSA9IDA7CiAgICAgICAgfQogICAgICAgICprZXlzKCkgewogICAgICAgICAgZm9yIChjb25zdCBba2V5XSBvZiB0aGlzKSB7CiAgICAgICAgICAgIHlpZWxkIGtleTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgKnZhbHVlcygpIHsKICAgICAgICAgIGZvciAoY29uc3QgWywgdmFsdWVdIG9mIHRoaXMpIHsKICAgICAgICAgICAgeWllbGQgdmFsdWU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgICpbU3ltYm9sLml0ZXJhdG9yXSgpIHsKICAgICAgICAgIGZvciAoY29uc3QgaXRlbSBvZiB0aGlzLmNhY2hlKSB7CiAgICAgICAgICAgIHlpZWxkIGl0ZW07CiAgICAgICAgICB9CiAgICAgICAgICBmb3IgKGNvbnN0IGl0ZW0gb2YgdGhpcy5vbGRDYWNoZSkgewogICAgICAgICAgICBjb25zdCBba2V5XSA9IGl0ZW07CiAgICAgICAgICAgIGlmICghdGhpcy5jYWNoZS5oYXMoa2V5KSkgewogICAgICAgICAgICAgIHlpZWxkIGl0ZW07CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZ2V0IHNpemUoKSB7CiAgICAgICAgICBsZXQgb2xkQ2FjaGVTaXplID0gMDsKICAgICAgICAgIGZvciAoY29uc3Qga2V5IG9mIHRoaXMub2xkQ2FjaGUua2V5cygpKSB7CiAgICAgICAgICAgIGlmICghdGhpcy5jYWNoZS5oYXMoa2V5KSkgewogICAgICAgICAgICAgIG9sZENhY2hlU2l6ZSsrOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gdGhpcy5fc2l6ZSArIG9sZENhY2hlU2l6ZTsKICAgICAgICB9CiAgICAgIH07CiAgICAgIG1vZHVsZTIuZXhwb3J0cyA9IFF1aWNrTFJVOwogICAgfQogIH0pOwoKICAvLyAoZGlzYWJsZWQpOm5vZGVfbW9kdWxlcy8ucG5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W1lbnRzLCAxKTsKICAgICAgICB3aGlsZSAoc291cmNlcy5sZW5ndGgpIHsKICAgICAgICAgIHZhciBzb3VyY2UgPSBzb3VyY2VzLnNoaWZ0KCk7CiAgICAgICAgICBpZiAoIXNvdXJjZSkgewogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgIH0KICAgICAgICAgIGlmICh0eXBlb2Ygc291cmNlICE9PSAib2JqZWN0IikgewogICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKHNvdXJjZSArICJtdXN0IGJlIG5vbi1vYmplY3QiKTsKICAgICAgICAgIH0KICAgICAgICAgIGZvciAodmFyIHAgaW4gc291cmNlKSB7CiAgICAgICAgICAgIGlmIChfaGFzKHNvdXJjZSwgcCkpIHsKICAgICAgICAgICAgICBvYmpbcF0gPSBzb3VyY2VbcF07CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIG9iajsKICAgICAgfTsKICAgICAgZXhwb3J0czIuc2hyaW5rQnVmID0gZnVuY3Rpb24oYnVmLCBzaXplKSB7CiAgICAgICAgaWYgKGJ1Zi5sZW5ndGggPT09IHNpemUpIHsKICAgICAgICAgIHJldHVybiBidWY7CiAgICAgICAgfQogICAgICAgIGlmIChidWYuc3ViYXJyYXkpIHsKICAgICAgICAgIHJldHVybiBidWYuc3ViYXJyYXkoMCwgc2l6ZSk7CiAgICAgICAgfQogICAgICAgIGJ1Zi5sZW5ndGggPSBzaXplOwogICAgICAgIHJldHVybiBidWY7CiAgICAgIH07CiAgICAgIHZhciBmblR5cGVkID0gewogICAgICAgIGFycmF5U2V0OiBmdW5jdGlvbihkZXN0LCBzcmMsIHNyY19vZmZzLCBsZW4sIGRlc3Rfb2ZmcykgewogICAgICAgICAgaWYgKHNyYy5zdWJhcnJheSAmJiBkZXN0LnN1YmFycmF5KSB7CiAgICAgICAgICAgIGRlc3Quc2V0KHNyYy5zdWJhcnJheShzcmNfb2Zmcywgc3JjX29mZnMgKyBsZW4pLCBkZXN0X29mZnMpOwogICAgICAgICAgICByZXR1cm47CiAgICAgICAgICB9CiAgICAgICAgICBmb3IgKHZhciBpID0gMDsgaSA8IGxlbjsgaSsrKSB7CiAgICAgICAgICAgIGRlc3RbZGVzdF9vZmZzICsgaV0gPSBzcmNbc3JjX29mZnMgKyBpXTsKICAgICAgICAgIH0KICAgICAgICB9LAogICAgICAgIGZsYXR0ZW5DaHVua3M6IGZ1bmN0aW9uKGNodW5rcykgewogICAgICAgICAgdmFyIGksIGwsIGxlbiwgcG9zLCBjaHVuaywgcmVzdWx0OwogICAgICAgICAgbGVuID0gMDsKICAgICAgICAgIGZvciAoaSA9IDAsIGwgPSBjaHVua3MubGVuZ3RoOyBpIDwgbDsgaSsrKSB7CiAgICAgICAgICAgIGxlbiArPSBjaHVua3NbaV0ubGVuZ3RoOwogICAgICAgICAgfQogICAgICAgICAgcmVzdWx0ID0gbmV3IFVpbnQ4QXJyYXkobGVuKTsKICAgICAgICAgIHBvcyA9IDA7CiAgICAgICAgICBmb3IgKGkgPSAwLCBsID0gY2h1bmtzLmxlbmd0aDsgaSA8IGw7IGkrKykgewogICAgICAgICAgICBjaHVuayA9IGNodW5rc1tpXTsKICAgICAgICAgICAgcmVzdWx0LnNldChjaHVuaywgcG9zKTsKICAgICAgICAgICAgcG9zICs9IGNodW5rLmxlbmd0aDsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiByZXN1bHQ7CiAgICAgICAgfQogICAgICB9OwogICAgICB2YXIgZm5VbnR5cGVkID0gewogICAgICAgIGFycmF5U2V0OiBmdW5jdGlvbihkZXN0LCBzcmMsIHNyY19vZmZzLCBsZW4sIGRlc3Rfb2ZmcykgewogICAgICAgICAgZm9yICh2YXIgaSA9IDA7IGkgPCBsZW47IGkrKykgewogICAgICAgICAgICBkZXN0W2Rlc3Rfb2ZmcyArIGldID0gc3JjW3NyY19vZmZzICsgaV07CiAgICAgICAgICB9CiAgICAgICAgfSwKICAgICAgICBmbGF0dG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Q7CiAgICAgIHZhciBaX0JJTkFSWSA9IDA7CiAgICAgIHZhciBaX1RFWFQgPSAxOwogICAgICB2YXIgWl9VTktOT1dOID0gMjsKICAgICAgZnVuY3Rpb24gemVybyhidWYpIHsKICAgICAgICB2YXIgbGVuID0gYnVmLmxlbmd0aDsKICAgICAgICB3aGlsZSAoLS1sZW4gPj0gMCkgewogICAgICAgICAgYnVmW2xlbl0gPSAwOwogICAgICAgIH0KICAgICAgfQogICAgICB2YXIgU1RPUkVEX0JMT0NLID0gMDsKICAgICAgdmFyIFNUQVRJQ19UUkVFUyA9IDE7CiAgICAgIHZhciBEWU5fVFJFRVMgPSAyOwogICAgICB2YXIgTUlOX01BVENIID0gMzsKICAgICAgdmFyIE1BWF9NQVRDSCA9IDI1ODsKICAgICAgdmFyIExFTkdUSF9DT0RFUyA9IDI5OwogICAgICB2YXIgTElURVJBTFMgPSAyNTY7CiAgICAgIHZhciBMX0NPREVTID0gTElURVJBTFMgKyAxICsgTEVOR1RIX0NPREVTOwogICAgICB2YXIgRF9DT0RFUyA9IDMwOwogICAgICB2YXIgQkxfQ09ERVMgPSAxOTsKICAgICAgdmFyIEhFQVBfU0laRSA9IDIgKiBMX0NPREVTICsgMTsKICAgICAgdmFyIE1BWF9CSVRTID0gMTU7CiAgICAgIHZhciBCdWZfc2l6ZSA9IDE2OwogICAgICB2YXIgTUFYX0JMX0JJVFMgPSA3OwogICAgICB2YXIgRU5EX0JMT0NLID0gMjU2OwogICAgICB2YXIgUkVQXzNfNiA9IDE2OwogICAgICB2YXIgUkVQWl8zXzEwID0gMTc7CiAgICAgIHZhciBSRVBaXzExXzEzOCA9IDE4OwogICAgICB2YXIgZXh0cmFfbGJpdHMgPSBbMCwgMCwgMCwgMCwgMCwgMCwgMCwgMCwgMSwgMSwgMSwgMSwgMiwgMiwgMiwgMiwgMywgMywgMywgMywgNCwgNCwgNCwgNCwgNSwgNSwgNSwgNSwgMF07CiAgICAgIHZhciBleHRyYV9kYml0cyA9IFswL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mICYgMjU1OwogICAgICAgICAgcy5iaV9idWYgPj49IDg7CiAgICAgICAgICBzLmJpX3ZhbGlkIC09IDg7CiAgICAgICAgfQogICAgICB9CiAgICAgIGZ1bmN0aW9uIGdlbl9iaXRsZW4ocywgZGVzYykgewogICAgICAgIHZhciB0cmVlID0gZGVzYy5keW5fdHJlZTsKICAgICAgICB2YXIgbWF4X2NvZGUgPSBkZXNjLm1heF9jb2RlOwogICAgICAgIHZhciBzdHJlZSA9IGRlc2Muc3RhdF9kZXNjLnN0YXRpY190cmVlOwogICAgICAgIHZhciBoYXNfc3RyZWUgPSBkZXNjLnN0YXRfZGVzYy5oYXNfc3RyZWU7CiAgICAgICAgdmFyIGV4dHJhID0gZGVzYy5zdGF0X2Rlc2MuZXh0cmFfYml0czsKICAgICAgICB2YXIgYmFzZSA9IGRlc2Muc3RhdF9kZXNjLmV4dHJhX2Jhc2U7CiAgICAgICAgdmFyIG1heF9sZW5ndGggPSBkZXNjLnN0YXRfZGVzYy5tYXhfbGVuZ3RoOwogICAgICAgIHZhciBoOwogICAgICAgIHZhciBuLCBtOwogICAgICAgIHZhciBiaXRzOwogICAgICAgIHZhciB4Yml0czsKICAgICAgICB2YXIgZjsKICAgICAgICB2YXIgb3ZlcmZsb3cgPSAwOwogICAgICAgIGZvciAoYml0cyA9IDA7IGJpdHMgPD0gTUFYX0JJVFM7IGJpdHMrKykgewogICAgICAgICAgcy5ibF9jb3VudFtiaXRzXSA9IDA7CiAgICAgICAgfQogICAgICAgIHRyZWVbcy5oZWFwW3MuaGVhcF9tYXhdICogMiArIDFdID0gMDsKICAgICAgICBmb3IgKGggPSBzLmhlYXBfbWF4ICsgMTsgaCA8IEhFQVBfU0laRTsgaCsrKSB7CiAgICAgICAgICBuID0gcy5oZWFwW2hdOwogICAgICAgICAgYml0cyA9IHRyZWVbdHJlZVtuICogMiArIDFdICogMiArIDFdICsgMTsKICAgICAgICAgIGlmIChiaXRzID4gbWF4X2xlbmd0aCkgewogICAgICAgICAgICBiaXRzID0gbWF4X2xlbmd0aDsKICAgICAgICAgICAgb3ZlcmZsb3crKzsKICAgICAgICAgIH0KICAgICAgICAgIHRyZWVbbiAqIDIgKyAxXSA9IGJpdHM7CiAgICAgICAgICBpZiAobiA+IG1heF9jb2RlKSB7CiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgfQogICAgICAgICAgcy5ibF9jb3VudFtiaXRzXSsrOwogICAgICAgICAgeGJpdHMgPSAwOwogICAgICAgICAgaWYgKG4gPj0gYmFzZSkgewogICAgICAgICAgICB4Yml0cyA9IGV4dHJhW24gLSBiYXNlXTsKICAgICAgICAgIH0KICAgICAgICAgIGYgPSB0cmVlW24gKiAyXTsKICAgICAgICAgIHMub3B0X2xlbiArPSBmICogKGJpdHMgKyB4Yml0cyk7CiAgICAgICAgICBpZiAoaGFzX3N0cmVlKSB7CiAgICAgICAgICAgIHMuc3RhdGljX2xlbiArPSBmICogKHN0cmVlW24gKiAyICsgMV0gKyB4Yml0cyk7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChvdmVyZmxvdyA9PT0gMCkgewogICAgICAgICAgcmV0dXJuOwogICAgICAgIH0KICAgICAgICBkbyB7CiAgICAgICAgICBiaXRzID0gbWF4X2xlbmd0aCAtIDE7CiAgICAgICAgICB3aGlsZSAocy5ibF9jb3VudFtiaXRzXSA9PT0gMCkgewogICAgICAgICAgICBiaXRzLS07CiAgICAgICAgICB9CiAgICAgICAgICBzLmJsX2NvdW50W2JpdHNdLS07CiAgICAgICAgICBzLmJsX2NvdW50W2JpdHMgKyAxXSArPSAyOwogICAgICAgICAgcy5ibF9jb3VudFttYXhfbGVuZ3RoXS0tOwogICAgICAgICAgb3ZlcmZsb3cgLT0gMjsKICAgICAgICB9IHdoaWxlIChvdmVyZmxvdyA+IDApOwogICAgICAgIGZvciAoYml0cyA9IG1heF9sZW5ndGg7IGJpdHMgIT09IDA7IGJpdHMtLSkgewogICAgICAgICAgbiA9IHMuYmxfY291bnRbYml0c107CiAgICAgICAgICB3aGlsZSAobiAhPT0gMCkgewogICAgICAgICAgICBtID0gcy5oZWFwWy0taF07CiAgICAgICAgICAgIGlmIChtID4gbWF4X2NvZGUpIHsKICAgICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAodHJlZVttICogMiArIDFdICE9PSBiaXRzKSB7CiAgICAgICAgICAgICAgcy5vcHRfbGVuICs9IChiaXRzIC0gdHJlZVttICogMiArIDFdKSAqIHRyZWVbbSAqIDJdOwogICAgICAgICAgICAgIHRyZWVbbSAqIDIgKyAxXSA9IGJpdHM7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgbi0tOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgICBmdW5jdGlvbiBnZW5fY29kZXModHJlZSwgbWF4X2NvZGUsIGJsX2NvdW50KSB7CiAgICAgICAgdmFyIG5leHRfY29kZSA9IG5ldyBBcnJheShNQVhfQklUUyArIDEpOwogICAgICAgIHZhciBjb2RlID0gMDsKICAgICAgICB2YXIgYml0czsKICAgICAgICB2YXIgbjsKICAgICAgICBmb3IgKGJpdHMgPSAxOyBiaXRzIDw9IE1BWF9CSVRTOyBiaXRzKyspIHsKICAgICAgICAgIG5leHRfY29kZVtiaXRzXSA9IGNvZGUgPSBjb2RlICsgYmxfY291bnRbYml0cyAtIDFdIDw8IDE7CiAgICAgICAgfQogICAgICAgIGZvciAobiA9IDA7IG4gPD0gbWF4X2NvZGU7IG4rKykgewogICAgICAgICAgdmFyIGxlbiA9IHRyZWVbbiAqIDIgKyAxXTsKICAgICAgICAgIGlmIChsZW4gPT09IDApIHsKICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICB9CiAgICAgICAgICB0cmVlW24gKiAyXSA9IGJpX3JldmVyc2UobmV4dF9jb2RlW2xlbl0rKywgbGVuKTsKICAgICAgICB9CiAgICAgIH0KICAgICAgZnVuY3Rpb24gdHJfc3RhdGljX2luaXQoKSB7CiAgICAgICAgdmFyIG47CiAgICAgICAgdmFyIGJpdHM7CiAgICAgICAgdmFyIGxlbmd0aDsKICAgICAgICB2YXIgY29kZTsKICAgICAgICB2YXIgZGlzdDsKICAgICAgICB2YXIgYmxfY291bnQgPSBuZXcgQXJyYXkoTUFYX0JJVFMgKyAxKTsKICAgICAgICBsZW5ndGggPSAwOwogICAgICAgIGZvciAoY29kZSA9IDA7IGNvZGUgPCBMRU5HVEhfQ09ERVMgLSAxOyBjb2RlKyspIHsKICAgICAgICAgIGJhc2VfbGVuZ3RoW2NvZGVdID0gbGVuZ3RoOwogICAgICAgICAgZm9yIChuID0gMDsgbiA8IDEgPDwgZXh0cmFfbGJpdHNbY29kZV07IG4rKykgewogICAgICAgICAgICBfbGVuZ3RoX2NvZGVbbGVuZ3RoKytdID0gY29kZTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgX2xlbmd0aF9jb2RlW2xlbmd0aCAtIDFdID0gY29kZTsKICAgICAgICBkaXN0ID0gMDsKICAgICAgICBmb3IgKGNvZGUgPSAwOyBjb2RlIDwgMTY7IGNvZGUrKykgewogICAgICAgICAgYmFzZV9kaXN0W2NvZGVdID0gZGlzdDsKICAgICAgICAgIGZvciAobiA9IDA7IG4gPCAxIDw8IGV4dHJhX2RiaXRzW2NvZGVdOyBuKyspIHsKICAgICAgICAgICAgX2Rpc3RfY29kZVtkaXN0KytdID0gY29kZTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZGlzdCA+Pj0gNzsKICAgICAgICBmb3IgKDsgY29kZSA8IERfQ09ERVM7IGNvZGUrKykgewogICAgICAgICAgYmFzZV9kaXN0W2NvZGVdID0gZGlzdCA8PCA3OwogICAgICAgICAgZm9yIChuID0gMDsgbiA8IDEgPDwgZXh0cmFfZGJpdHNbY29kZV0gLSA3OyBuKyspIHsKICAgICAgICAgICAgX2Rpc3RfY29kZVsyNTYgKyBkaXN0KytdID0gY29kZTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZm9yIChiaXRzID0gMDsgYml0cyA8PSBNQVhfQklUUzsgYml0cysrKSB7CiAgICAgICAgICBibF9jb3VudFtiaXRzXSA9IDA7CiAgICAgICAgfQogICAgICAgIG4gPSAwOwogICAgICAgIHdoaWxlIChuIDw9IDE0MykgewogICAgICAgICAgc3RhdGljX2x0cmVlW24gKiAyICsgMV0gPSA4OwogICAgICAgICAgbisrOwogICAgICAgICAgYmxfY291bnRbOF0rKzsKICAgICAgICB9CiAgICAgICAgd2hpbGUgKG4gPD0gMjU1KSB7CiAgICAgICAgICBzdGF0aWNfbHRyZWVbbiAqIDIgKyAxXSA9IDk7CiAgICAgICAgICBuKys7CiAgICAgICAgICBibF9jb3VudFs5XSsrOwogICAgICAgIH0KICAgICAgICB3aGlsZSAobiA8PSAyNzkpIHsKICAgICAgICAgIHN0YXRpY19sdHJlZVtuICogMiArIDFdID0gNzsKICAgICAgICAgIG4rKzsKICAgICAgICAgIGJsX2NvdW50WzddKys7CiAgICAgICAgfQogICAgICAgIHdoaWxlIChuIDw9IDI4NykgewogICAgICAgICAgc3RhdGljX2x0cmVlW24gKiAyICsgMV0gPSA4OwogICAgICAgICAgbisrOwogICAgICAgICAgYmxfY291bnRbOF0rKzsKICAgICAgICB9CiAgICAgICAgZ2VuX2NvZGVzKHN0YXRpY19sdHJlZSwgTF9DT0RFUyArIDEsIGJsX2NvdW50KTsKICAgICAgICBmb3IgKG4gPSAwOyBuIDwgRF9DT0RFUzsgbisrKSB7CiAgICAgICAgICBzdGF0aWNfZHRyZWVbbiAqIDIgKyAxXSA9IDU7CiAgICAgICAgICBzdGF0aWNfZHRyZWVbbiAqIDJdID0gYmlfcmV2ZXJzZShuLCA1KTsKICAgICAgICB9CiAgICAgICAgc3RhdGljX2xfZGVzYyA9IG5ldyBTdGF0aWNUcmVlRGVzYyhzdGF0aWNfbHRyZWUsIGV4dHJhX2xiaXRzLCBMSVRFUkFMUyArIDEsIExfQ09ERVMsIE1BWF9CSVRTKTsKICAgICAgICBzdGF0aWNfZF9kZXNjID0gbmV3IFN0YXRpY1RyZWVEZXNjKHN0YXRpY19kdHJlZSwgZXh0cmFfZGJpdHMsIDAsIERfQ09ERVMsIE1BWF9CSVRTKTsKICAgICAgICBzdGF0aWNfYmxfZGVzYyA9IG5ldyBTdGF0aWNUcmVlRGVzYyhuZXcgQXJyYXkoMCksIGV4dHJhX2JsYml0cywgMCwgQkxfQ09ERVMsIE1BWF9CTF9CSVRTKTsKICAgICAgfQogICAgICBmdW5jdGlvbiBpbml0X2Jsb2NrKHMpIHsKICAgICAgICB2YXIgbjsKICAgICAgICBmb3IgKG4gPSAwOyBuIDwgTF9DT0RFUzsgbisrKSB7CiAgICAgICAgICBzLmR5bl9sdHJlZVtuICogMl0gPSAwOwogICAgICAgIH0KICAgICAgICBmb3IgKG4gPSAwOyBuIDwgRF9DT0RFUzsgbisrKSB7CiAgICAgICAgICBzLmR5bl9kdHJlZVtuICogMl0gPSAwOwogICAgICAgIH0KICAgICAgICBmb3IgKG4gPSAwOyBuIDwgQkxfQ09ERVM7IG4rKykgewogICAgICAgICAgcy5ibF90cmVlW24gKiAyXSA9IDA7CiAgICAgICAgfQogICAgICAgIHMuZHluX2x0cmVlW0VORF9CTE9DSyAqIDJdID0gMTsKICAgICAgICBzLm9wdF9sZW4gPSBzLnN0YXRpY19sZW4gPSAwOwogICAgICAgIHMubGFzdF9saXQgPSBzLm1hdGNoZXMgPSAwOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGJpX3dpbmR1cChzKSB7CiAgICAgICAgaWYgKHMuYmlfdmFsaWQgPiA4KSB7CiAgICAgICAgICBwdXRfc2hvcnQocywgcy5iaV9idWYpOwogICAgICAgIH0gZWxzZSBpZiAocy5iaV92YWxpZCA+IDApIHsKICAgICAgICAgIHMucGVuZGluZ19idWZbcy5wZW5kaW5nKytdID0gcy5iaV9idWY7CiAgICAgICAgfQogICAgICAgIHMuYmlfYnVmID0gMDsKICAgICAgICBzLmJpX3ZhbGlkID0gMDsKICAgICAgfQogICAgICBmdW5jdGlvbiBjb3B5X2Jsb2NrKHMsIGJ1ZiwgbGVuLCBoZWFkZXIpIHsKICAgICAgICBiaV93aW5kdXAocyk7CiAgICAgICAgaWYgKGhlYWRlcikgewogICAgICAgICAgcHV0X3Nob3J0KHMsIGxlbik7CiAgICAgICAgICBwdXRfc2hvcnQocywgfmxlbik7CiAgICAgICAgfQogICAgICAgIHV0aWxzLmFycmF5U2V0KHMucGVuZGluZ19idWYsIHMud2luZG93LCBidWYsIGxlbiwgcy5wZW5kaW5nKTsKICAgICAgICBzLnBlbmRpbmcgKz0gbGVuOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIHNtYWxsZXIodHJlZSwgbiwgbSwgZGVwdGgpIHsKICAgICAgICB2YXIgX24yID0gbiAqIDI7CiAgICAgICAgdmFyIF9tMiA9IG0gKiAyOwogICAgICAgIHJldHVybiB0cmVlW19uMl0gPCB0cmVlW19tMl0gfHwgdHJlZVtfbjJdID09PSB0cmVlW19tMl0gJiYgZGVwdGhbbl0gPD0gZGVwdGhbbV07CiAgICAgIH0KICAgICAgZnVuY3Rpb24gcHFkb3duaGVhcChzLCB0cmVlLCBrKSB7CiAgICAgICAgdmFyIHYgPSBzLmhlYXBba107CiAgICAgICAgdmFyIGogPSBrIDw8IDE7CiAgICAgICAgd2hpbGUgKGogPD0gcy5oZWFwX2xlbikgewogICAgICAgICAgaWYgKGogPCBzLmhlYXBfbGVuICYmIHNtYWxsZXIodHJlZSwgcy5oZWFwW2ogKyAxXSwgcy5oZWFwW2pdLCBzLmRlcHRoKSkgewogICAgICAgICAgICBqKys7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoc21hbGxlcih0cmVlLCB2LCBzLmhlYXBbal0sIHMuZGVwdGgpKSB7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgICAgcy5oZWFwW2tdID0gcy5oZWFwW2pdOwogICAgICAgICAgayA9IGo7CiAgICAgICAgICBqIDw8PSAxOwogICAgICAgIH0KICAgICAgICBzLmhlYXBba10gPSB2OwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGNvbXByZXNzX2Jsb2NrKHMsIGx0cmVlLCBkdHJlZSkgewogICAgICAgIHZhciBkaXN0OwogICAgICAgIHZhciBsYzsKICAgICAgICB2YXIgbHggPSAwOwogICAgICAgIHZhciBjb2RlOwogICAgICAgIHZhciBleHRyYTsKICAgICAgICBpZiAocy5sYXN0X2xpdCAhPT0gMCkgewogICAgICAgICAgZG8gewogICAgICAgICAgICBkaXN0ID0gcy5wZW5kaW5nX2J1ZltzLmRfYnVmICsgbHggKiAyXSA8PCA4IHwgcy5wZW5kaW5nX2J1ZltzLmRfYnVmICsgbHggKiAyICsgMV07CiAgICAgICAgICAgIGxjID0gcy5wZW5kaW5nX2J1ZltzLmxfYnVmICsgbHhdOwogICAgICAgICAgICBseCsrOwogICAgICAgICAgICBpZiAoZGlzdCA9PT0gMCkgewogICAgICAgICAgICAgIHNlbmRfY29kZShzLCBsYywgbHRyZWUpOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIGNvZGUgPSBfbGVuZ3RoX2NvZGVbbGNdOwogICAgICAgICAgICAgIHNlbmRfY29kZShzLCBjb2RlICsgTElURVJBTFMgKyAxLCBsdHJlZSk7CiAgICAgICAgICAgICAgZXh0cmEgPSBleHRyYV9sYml0c1tjb2RlXTsKICAgICAgICAgICAgICBpZiAoZXh0cmEgIT09IDApIHsKICAgICAgICAgICAgICAgIGxjIC09IGJhc2VfbGVuZ3RoW2NvZGVdOwogICAgICAgICAgICAgICAgc2VuZF9iaXRzKHMsIGxjLCBleHRyYSk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGRpc3QtLTsKICAgICAgICAgICAgICBjb2RlID0gZF9jb2RlKGRpc3QpOwogICAgICAgICAgICAgIHNlbmRfY29kZShzLCBjb2RlLCBkdHJlZSk7CiAgICAgICAgICAgICAgZXh0cmEgPSBleHRyYV9kYml0c1tjb2RlXTsKICAgICAgICAgICAgICBpZiAoZXh0cmEgIT09IDApIHsKICAgICAgICAgICAgICAgIGRpc3QgLT0gYmFzZV9kaXN0W2NvZGVdOwogICAgICAgICAgICAgICAgc2VuZF9iaXRzKHMsIGRpc3QsIGV4dHJhKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gd2hpbGUgKGx4IDwgcy5sYXN0X2xpdCk7CiAgICAgICAgfQogICAgICAgIHNlbmRfY29kZShzLCBFTkRfQkxPQ0ssIGx0cmVlKTsKICAgICAgfQogICAgICBmdW5jdGlvbiBidWlsZF90cmVlKHMsIGRlc2MpIHsKICAgICAgICB2YXIgdHJlZSA9IGRlc2MuZHluX3RyZWU7CiAgICAgICAgdmFyIHN0cmVlID0gZGVzYy5zdGF0X2Rlc2Muc3RhdGljX3RyZWU7CiAgICAgICAgdmFyIGhhc19zdHJlZSA9IGRlc2Muc3RhdF9kZXNjLmhhc19zdHJlZTsKICAgICAgICB2YXIgZWxlbXMgPSBkZXNjLnN0YXRfZGVzYy5lbGVtczsKICAgICAgICB2YXIgbiwgbTsKICAgICAgICB2YXIgbWF4X2NvZGUgPSAtMTsKICAgICAgICB2YXIgbm9kZTsKICAgICAgICBzLmhlYXBfbGVuID0gMDsKICAgICAgICBzLmhlYXBfbWF4ID0gSEVBUF9TSVpFOwogICAgICAgIGZvciAobiA9IDA7IG4gPCBlbGVtczsgbisrKSB7CiAgICAgICAgICBpZiAodHJlZVtuICogMl0gIT09IDApIHsKICAgICAgICAgICAgcy5oZWFwWysrcy5oZWFwX2xlbl0gPSBtYXhfY29kZSA9IG47CiAgICAgICAgICAgIHMuZGVwdGhbbl0gPSAwOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgdHJlZVtuICogMiArIDFdID0gMDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgd2hpbGUgKHMuaGVhcF9sZW4gPCAyKSB7CiAgICAgICAgICBub2RlID0gcy5oZWFwWysrcy5oZWFwX2xlbl0gPSBtYXhfY29kZSA8IDIgPyArK21heF9jb2RlIDogMDsKICAgICAgICAgIHRyZWVbbm9kZSAqIDJdID0gMTsKICAgICAgICAgIHMuZGVwdGhbbm9kZV0gPSAwOwogICAgICAgICAgcy5vcHRfbGVuLS07CiAgICAgICAgICBpZiAoaGFzX3N0cmVlKSB7CiAgICAgICAgICAgIHMuc3RhdGljX2xlbiAtPSBzdHJlZVtub2RlICogMiArIDFdOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBkZXNjLm1heF9jb2RlID0gbWF4X2NvZGU7CiAgICAgICAgZm9yIChuID0gcy5oZWFwX2xlbiA+PiAxOyBuID49IDE7IG4tLSkgewogICAgICAgICAgcHFkb3duaGVhcChzLCB0cmVlLCBuKTsKICAgICAgICB9CiAgICAgICAgbm9kZSA9IGVsZW1zOwogICAgICAgIGRvIHsKICAgICAgICAgIG4gPSBzLmhlYXBbMV07CiAgICAgICAgICBzLmhlYXBbMV0gPSBzLmhlYXBbcy5oZWFwX2xlbi0tXTsKICAgICAgICAgIHBxZG93bmhlYXAocywgdHJlZSwgMSk7CiAgICAgICAgICBtID0gcy5oZWFwWzFdOwogICAgICAgICAgcy5oZWFwWy0tcy5oZWFwX21heF0gPSBuOwogICAgICAgICAgcy5oZWFwWy0tcy5oZWFwX21heF0gPSBtOwogICAgICAgICAgdHJlZVtub2RlICogMl0gPSB0cmVlW24gKiAyXSArIHRyZWVbbSAqIDJdOwogICAgICAgICAgcy5kZXB0aFtub2RlXSA9IChzLmRlcHRoW25dID49IHMuZGVwdGhbbV0gPyBzLmRlcHRoW25dIDogcy5kZXB0aFttXSkgKyAxOwogICAgICAgICAgdHJlZVtuICogMiArIDFdID0gdHJlZVttICogMiArIDFdID0gbm9kZTsKICAgICAgICAgIHMuaGVhcFsxXSA9IG5vZGUrKzsKICAgICAgICAgIHBxZG93bmhlYXAocywgdHJlZSwgMSk7CiAgICAgICAgfSB3aGlsZSAocy5oZWFwX2xlbiA+PSAyKTsKICAgICAgICBzLmhlYXBbLS1zLmhlYXBfbWF4XSA9IHMuaGVhcFsxXTsKICAgICAgICBnZW5fYml0bGVuKHMsIGRlc2MpOwogICAgICAgIGdlbl9jb2Rlcyh0cmVlLCBtYXhfY29kZSwgcy5ibF9jb3VudCk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gc2Nhbl90cmVlKHMsIHRyZWUsIG1heF9jb2RlKSB7CiAgICAgICAgdmFyIG47CiAgICAgICAgdmFyIHByZXZsZW4gPSAtMTsKICAgICAgICB2YXIgY3VybGVuOwogICAgICAgIHZhciBuZXh0bGVuID0gdHJlZVswICogMiArIDFdOwogICAgICAgIHZhciBjb3VudCA9IDA7CiAgICAgICAgdmFyIG1heF9jb3VudCA9IDc7CiAgICAgICAgdmFyIG1pbl9jb3VudCA9IDQ7CiAgICAgICAgaWYgKG5leHRsZW4gPT09IDApIHsKICAgICAgICAgIG1heF9jb3VudCA9IDEzODsKICAgICAgICAgIG1pbl9jb3VudCA9IDM7CiAgICAgICAgfQogICAgICAgIHRyZWVbKG1heF9jb2RlICsgMSkgKiAyICsgMV0gPSA2NTUzNTsKICAgICAgICBmb3IgKG4gPSAwOyBuIDw9IG1heF9jb2RlOyBuKyspIHsKICAgICAgICAgIGN1cmxlbiA9IG5leHRsZW47CiAgICAgICAgICBuZXh0bGVuID0gdHJlZVsobiArIDEpICogMiArIDFdOwogICAgICAgICAgaWYgKCsrY291bnQgPCBtYXhfY291bnQgJiYgY3VybGVuID09PSBuZXh0bGVuKSB7CiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgfSBlbHNlIGlmIChjb3VudCA8IG1pbl9jb3VudCkgewogICAgICAgICAgICBzLmJsX3RyZWVbY3VybGVuICogMl0gKz0gY291bnQ7CiAgICAgICAgICB9IGVsc2UgaWYgKGN1cmxlbiAhPT0gMCkgewogICAgICAgICAgICBpZiAoY3VybGVuICE9PSBwcmV2bGVuKSB7CiAgICAgICAgICAgICAgcy5ibF90cmVlW2N1cmxlbiAqIDJdKys7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgcy5ibF90cmVlW1JFUF8zXzYgKiAyXSsrOwogICAgICAgICAgfSBlbHNlIGlmIChjb3VudCA8PSAxMCkgewogICAgICAgICAgICBzLmJsX3RyZWVbUkVQWl8zXzEwICogMl0rKzsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHMuYmxfdHJlZVtSRVBaXzExXzEzOCAqIDJdKys7CiAgICAgICAgICB9CiAgICAgICAgICBjb3VudCA9IDA7CiAgICAgICAgICBwcmV2bGVuID0gY3VybGVuOwogICAgICAgICAgaWYgKG5leHRsZW4gPT09IDApIHsKICAgICAgICAgICAgbWF4X2NvdW50ID0gMTM4OwogICAgICAgICAgICBtaW5fY291bnQgPSAzOwogICAgICAgICAgfSBlbHNlIGlmIChjdXJsZW4gPT09IG5leHRsZW4pIHsKICAgICAgICAgICAgbWF4X2NvdW50ID0gNjsKICAgICAgICAgICAgbWluX2NvdW50ID0gMzsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIG1heF9jb3VudCA9IDc7CiAgICAgICAgICAgIG1pbl9jb3VudCA9IDQ7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9CiAgICAgIGZ1bmN0aW9uIHNlbmRfdHJlZShzLCB0cmVlLCBtYXhfY29kZSkgewogICAgICAgIHZhciBuOwogICAgICAgIHZhciBwcmV2bGVuID0gLTE7CiAgICAgICAgdmFyIGN1cmxlbjsKICAgICAgICB2YXIgbmV4dGxlbiA9IHRyZWVbMCAqIDIgKyAxXTsKICAgICAgICB2YXIgY291bnQgPSAwOwogICAgICAgIHZhciBtYXhfY291bnQgPSA3OwogICAgICAgIHZhciBtaW5fY291bnQgPSA0OwogICAgICAgIGlmIChuZXh0bGVuID09PSAwKSB7CiAgICAgICAgICBtYXhfY291bnQgPSAxMzg7CiAgICAgICAgICBtaW5fY291bnQgPSAzOwogICAgICAgIH0KICAgICAgICBmb3IgKG4gPSAwOyBuIDw9IG1heF9jb2RlOyBuKyspIHsKICAgICAgICAgIGN1cmxlbiA9IG5leHRsZW47CiAgICAgICAgICBuZXh0bGVuID0gdHJlZVsobiArIDEpICogMiArIDFdOwogICAgICAgICAgaWYgKCsrY291bnQgPCBtYXhfY291bnQgJiYgY3VybGVuID09PSBuZXh0bGVuKSB7CiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgfSBlbHNlIGlmIChjb3VudCA8IG1pbl9jb3VudCkgewogICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgc2VuZF9jb2RlKHMsIGN1cmxlbiwgcy5ibF90cmVlKTsKICAgICAgICAgICAgfSB3aGlsZSAoLS1jb3VudCAhPT0gMCk7CiAgICAgICAgICB9IGVsc2UgaWYgKGN1cmxlbiAhPT0gMCkgewogICAgICAgICAgICBpZiAoY3VybGVuICE9PSBwcmV2bGVuKSB7CiAgICAgICAgICAgICAgc2VuZF9jb2RlKHMsIGN1cmxlbiwgcy5ibF90cmVlKTsKICAgICAgICAgICAgICBjb3VudC0tOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHNlbmRfY29kZShzLCBSRVBfM182LCBzLmJsX3RyZWUpOwogICAgICAgICAgICBzZW5kX2JpdHMocywgY291bnQgLSAzLCAyKTsKICAgICAgICAgIH0gZWxzZSBpZiAoY291bnQgPD0gMTApIHsKICAgICAgICAgICAgc2VuZF9jb2RlKHMsIFJFUFpfM18xMCwgcy5ibF90cmVlKTsKICAgICAgICAgICAgc2VuZF9iaXRzKHMsIGNvdW50IC0gMywgMyk7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBzZW5kX2NvZGUocywgUkVQWl8xMV8xMzgsIHMuYmxfdHJlZSk7CiAgICAgICAgICAgIHNlbmRfYml0cyhzLCBjb3VudCAtIDExLCA3KTsKICAgICAgICAgIH0KICAgICAgICAgIGNvdW50ID0gMDsKICAgICAgICAgIHByZXZsZW4gPSBjdXJsZW47CiAgICAgICAgICBpZiAobmV4dGxlbiA9PT0gMCkgewogICAgICAgICAgICBtYXhfY291bnQgPSAxMzg7CiAgICAgICAgICAgIG1pbl9jb3VudCA9IDM7CiAgICAgICAgICB9IGVsc2UgaWYgKGN1cmxlbiA9PT0gbmV4dGxlbikgewogICAgICAgICAgICBtYXhfY291bnQgPSA2OwogICAgICAgICAgICBtaW5fY291bnQgPSAzOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgbWF4X2NvdW50ID0gNzsKICAgICAgICAgICAgbWluX2NvdW50ID0gNDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgICAgZnVuY3Rpb24gYnVpbGRfYmxfdHJlZShzKSB7CiAgICAgICAgdmFyIG1heF9ibGluZGV4OwogICAgICAgIHNjYW5fdHJlZShzLCBzLmR5bl9sdHJlZSwgcy5sX2Rlc2MubWF4X2NvZGUpOwogICAgICAgIHNjYW5fdHJlZShzLCBzLmR5bl9kdHJlZSwgcy5kX2Rlc2MubWF4X2NvZGUpOwogICAgICAgIGJ1aWxkX3RyZWUocywgcy5ibF9kZXNjKTsKICAgICAgICBmb3IgKG1heF9ibGluZGV4ID0gQkxfQ09ERVMgLSAxOyBtYXhfYmxpbmRleCA+PSAzOyBtYXhfYmxpbmRleC0tKSB7CiAgICAgICAgICBpZiAocy5ibF90cmVlW2JsX29yZGVyW21heF9ibGluZGV4XSAqIDIgKyAxXSAhPT0gMCkgewogICAgICAgICAgICBicmVhazsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcy5vcHRfbGVuICs9IDMgKiAobWF4X2JsaW5kZXggKyAxKSArIDUgKyA1ICsgNDsKICAgICAgICByZXR1cm4gbWF4X2JsaW5kZXg7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gc2VuZF9hbGxfdHJlZXMocywgbGNvZGVzLCBkY29kZXMsIGJsY29kZXMpIHsKICAgICAgICB2YXIgcmFuazsKICAgICAgICBzZW5kX2JpdHMocywgbGNvZGVzIC0gMjU3LCA1KTsKICAgICAgICBzZW5kX2JpdHMocywgZGNvZGVzIC0gMSwgNSk7CiAgICAgICAgc2VuZF9iaXRzKHMsIGJsY29kZXMgLSA0LCA0KTsKICAgICAgICBmb3IgKHJhbmsgPSAwOyByYW5rIDwgYmxjb2RlczsgcmFuaysrKSB7CiAgICAgICAgICBzZW5kX2JpdHMocywgcy5ibF90cmVlW2JsX29yZGVyW3JhbmtdICogMiArIDFdLCAzKTsKICAgICAgICB9CiAgICAgICAgc2VuZF90cmVlKHMsIHMuZHluX2x0cmVlLCBsY29kZXMgLSAxKTsKICAgICAgICBzZW5kX3RyZWUocywgcy5keW5fZHRyZWUsIGRjb2RlcyAtIDEpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGRldGVjdF9kYXRhX3R5cGUocykgewogICAgICAgIHZhciBibGFja19tYXNrID0gNDA5MzYyNDQ0NzsKICAgICAgICB2YXIgbjsKICAgICAgICBmb3IgKG4gPSAwOyBuIDw9IDMxOyBuKyssIGJsYWNrX21hc2sgPj4+PSAxKSB7CiAgICAgICAgICBpZiAoYmxhY2tfbWFzayAmIDEgJiYgcy5keW5fbHRyZWVbbiAqIDJdICE9PSAwKSB7CiAgICAgICAgICAgIHJldHVybiBaX0JJTkFSWTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKHMuZHluX2x0cmVlWzkgKiAyXSAhPT0gMCB8fCBzLmR5bl9sdHJlZVsxMCAqIDJdICE9PSAwIHx8IHMuZHluX2x0cmVlWzEzICogMl0gIT09IDApIHsKICAgICAgICAgIHJldHVybiBaX1RFWFQ7CiAgICAgICAgfQogICAgICAgIGZvciAobiA9IDMyOyBuIDwgTElURVJBTFM7IG4rKykgewogICAgICAgICAgaWYgKHMuZHluX2x0cmVlW24gKiAyXSAhPT0gMCkgewogICAgICAgICAgICByZXR1cm4gWl9URVhUOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gWl9CSU5BUlk7CiAgICAgIH0KICAgICAgdmFyIHN0YXRpY19pbml0X2RvbmUg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X2JsaW5kZXggPSAwOwogICAgICAgIGlmIChzLmxldmVsID4gMCkgewogICAgICAgICAgaWYgKHMuc3RybS5kYXRhX3R5cGUgPT09IFpfVU5LTk9XTikgewogICAgICAgICAgICBzLnN0cm0uZGF0YV90eXBlID0gZGV0ZWN0X2RhdGFfdHlwZShzKTsKICAgICAgICAgIH0KICAgICAgICAgIGJ1aWxkX3RyZWUocywgcy5sX2Rlc2MpOwogICAgICAgICAgYnVpbGRfdHJlZShzLCBzLmRfZGVzYyk7CiAgICAgICAgICBtYXhfYmxpbmRleCA9IGJ1aWxkX2JsX3RyZWUocyk7CiAgICAgICAgICBvcHRfbGVuYiA9IHMub3B0X2xlbiArIDMgKyA3ID4+PiAzOwogICAgICAgICAgc3RhdGljX2xlbmIgPSBzLnN0YXRpY19sZW4gKyAzICsgNyA+Pj4gMzsKICAgICAgICAgIGlmIChzdGF0aWNfbGVuYiA8PSBvcHRfbGVuYikgewogICAgICAgICAgICBvcHRfbGVuYiA9IHN0YXRpY19sZW5iOwogICAgICAgICAgfQogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBvcHRfbGVuYiA9IHN0YXRpY19sZW5iID0gc3RvcmVkX2xlbiArIDU7CiAgICAgICAgfQogICAgICAgIGlmIChzdG9yZWRfbGVuICsgNCA8PSBvcHRfbGVuYiAmJiBidWYgIT09IC0xKSB7CiAgICAgICAgICBfdHJfc3RvcmVkX2Jsb2NrKHMsIGJ1Ziwgc3RvcmVkX2xlbiwgbGFzdCk7CiAgICAgICAgfSBlbHNlIGlmIChzLnN0cmF0ZWd5ID09PSBaX0ZJWEVEIHx8IHN0YXRpY19sZW5iID09PSBvcHRfbGVuYikgewogICAgICAgICAgc2VuZF9iaXRzKHMsIChTVEFUSUNfVFJFRVMgPDwgMSkgKyAobGFzdCA/IDEgOiAwKSwgMyk7CiAgICAgICAgICBjb21wcmVzc19ibG9jayhzLCBzdGF0aWNfbHRyZWUsIHN0YXRpY19kdHJlZSk7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIHNlbmRfYml0cyhzLCAoRFlOX1RSRUVTIDw8IDEpICsgKGxhc3QgPyAxIDogMCksIDMpOwogICAgICAgICAgc2VuZF9hbGxfdHJlZXMocywgcy5sX2Rlc2MubWF4X2NvZGUgKyAxLCBzLmRfZGVzYy5tYXhfY29kZSArIDEsIG1heF9ibGluZGV4ICsgMSk7CiAgICAgICAgICBjb21wcmVzc19ibG9jayhzLCBzLmR5bl9sdHJlZSwgcy5keW5fZHRyZWUpOwogICAgICAgIH0KICAgICAgICBpbml0X2Jsb2NrKHMpOwogICAgICAgIGlmIChsYXN0KSB7CiAgICAgICAgICBiaV93aW5kdXAocyk7CiAgICAgICAgfQogICAgICB9CiAgICAgIGZ1bmN0aW9uIF90cl90YWxseShzLCBkaXN0LCBsYykgewogICAgICAgIHMucGVuZGluZ19idWZbcy5kX2J1ZiArIHMubGFzdF9saXQgKiAyXSA9IGRpc3QgPj4+IDggJiAyNTU7CiAgICAgICAgcy5wZW5kaW5nX2J1ZltzLmRfYnVmICsgcy5sYXN0X2xpdCAqIDIgKyAxXSA9IGRpc3QgJiAyNTU7CiAgICAgICAgcy5wZW5kaW5nX2J1ZltzLmxfYnVmICsgcy5sYXN0X2xpdF0gPSBsYyAmIDI1NTsKICAgICAgICBzLmxhc3RfbGl0Kys7CiAgICAgICAgaWYgKGRpc3QgPT09IDApIHsKICAgICAgICAgIHMuZHluX2x0cmVlW2xjICogMl0rKzsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgcy5tYXRjaGVzKys7CiAgICAgICAgICBkaXN0LS07CiAgICAgICAgICBzLmR5bl9sdHJlZVsoX2xlbmd0aF9jb2RlW2xjXSArIExJVEVSQUxTICsgMSkgKiAyXSsrOwogICAgICAgICAgcy5keW5fZHRyZWVbZF9jb2RlKGRpc3QpICogMl0rKzsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHMubGFzdF9saXQgPT09IHMubGl0X2J1ZnNpemUgLSAxOwogICAgICB9CiAgIC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gICAgfQogICAgICAgIHJldHVybiBzMSB8IHMyIDw8IDE2IHwgMDsKICAgICAgfQogICAgICBtb2R1bGUyLmV4cG9ydHMgPSBhZGxlcjMyOwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvY3JjMzIuanMKICB2YXIgcmVxdWlyZV9jcmMzMiA9IF9fY29tbW9uSlMoewogICAgIm5vZGVfbW9kdWxlcy8ucG5wbS9wYWtvQDEuMC4xMS9ub2RlX21vZHVsZXMvcGFrby9saWIvemxpYi9jcmMzMi5qcyIoZXhwb3J0czIsIG1vZHVsZTIpIHsKICAgICAgaW5pdF9idWZmZXJfc2hpbSgpOwogICAgICAidXNlIHN0cmljdCI7CiAgICAgIGZ1bmN0aW9uIG1ha2VUYWJsZSgpIHsKICAgICAgICB2YXIgYywgdGFibGUgPSBbXTsKICAgICAgICBmb3IgKHZhciBuID0gMDsgbiA8IDI1NjsgbisrKSB7CiAgICAgICAgICBjID0gbjsKICAgICAgICAgIGZvciAodmFyIGsgPSAwOyBrIDwgODsgaysrKSB7CiAgICAgICAgICAgIGMgPSBjICYgMSA/IDM5ODgyOTIzODQgXiBjID4+PiAxIDogYyA+Pj4gMTsKICAgICAgICAgIH0KICAgICAgICAgIHRhYmxlW25dID0gYzsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHRhYmxlOwogICAgICB9CiAgICAgIHZhciBjcmNUYWJsZSA9IG1ha2VUYWJsZSgpOwogICAgICBmdW5jdGlvbiBjcmMzMihjcmMsIGJ1ZiwgbGVuLCBwb3MpIHsKICAgICAgICB2YXIgdCA9IGNyY1RhYmxlLCBlbmQgPSBwb3MgKyBsZW47CiAgICAgICAgY3JjIF49IC0xOwogICAgICAgIGZvciAodmFyIGkgPSBwb3M7IGkgPCBlbmQ7IGkrKykgewogICAgICAgICAgY3JjID0gY3JjID4+PiA4IF4gdFsoY3JjIF4gYnVmW2ldKSAmIDI1NV07CiAgICAgICAgfQogICAgICAgIHJldHVybiBjcmMgXiAtMTsKICAgICAgfQogICAgICBtb2R1bGUyLmV4cG9ydHMgPSBjcmMzMjsKICAgIH0KICB9KTsKCiAgLy8gbm9kZV9tb2R1bGVzLy5wbnBtL3Bha29AMS4wLjExL25vZGVfbW9kdWxlcy9wYWtvL2xpYi96bGliL21lc3NhZ2VzLmpzCiAgdmFyIHJlcXVpcmVfbWVzc2FnZXMgPSBfX2NvbW1vbkpTKHsKICAgICJub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvbWVzc2FnZXMuanMiKGV4cG9ydHMyLCBtb2R1bGUyKSB7CiAgICAgIGluaXRfYnVmZmVyX3NoaW0oKTsKICAgICAgInVzZSBzdHJpY3QiOwogICAgICBtb2R1bGUyLmV4cG9ydHMgPSB7CiAgICAgICAgMjogIm5lZWQgZGljdGlvbmFyeSIsCiAgICAgICAgMTogInN0cmVhbSBlbmQiLAogICAgICAgIDA6ICIiLAogICAgICAgICItMSI6ICJmaWxlIGVycm9yIiwKICAgICAgICAiLTIiOiAic3RyZWFtIGVycm9yIiwKICAgICAgICAiLTMiOiAiZGF0YSBlcnJvciIsCiAgICAgICAgIi00IjogImluc3VmZmljaWVudCBtZW1vcnkiLAogICAgICAgICItNSI6ICJidWZmZXIgZXJyb3IiLAogICAgICAgICItNiI6ICJpbmNvbXBhdGlibGUgdmVyc2lvbiIKICAgICAgfTsKICAgIH0KICB9KTsKCiAgLy8gbm9kZV9tb2R1bGVzLy5wbnBtL3Bha29AMS4wLjExL25vZGVfbW9kdWxlcy9wYWtvL2xpYi96bGliL2RlZmxhdGUuanMKICB2YXIgcmVxdWlyZV9kZWZsYXRlID0gX19jb21tb25KUyh7CiAgICAibm9kZV9tb2R1bGVzLy5wbnBtL3Bha29AMS4wLjExL25vZGVfbW9kdWxlcy9wYWtvL2xpYi96bGliL2RlZmxhdGUuanMi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DogMCk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gemVybyhidWYpIHsKICAgICAgICB2YXIgbGVuID0gYnVmLmxlbmd0aDsKICAgICAgICB3aGlsZSAoLS1sZW4gPj0gMCkgewogICAgICAgICAgYnVmW2xlbl0gPSAwOwogICAgICAgIH0KICAgICAgfQogICAgICBmdW5jdGlvbiBmbHVzaF9wZW5kaW5nKHN0cm0pIHsKICAgICAgICB2YXIgcyA9IHN0cm0uc3RhdGU7CiAgICAgICAgdmFyIGxlbiA9IHMucGVuZGluZzsKICAgICAgICBpZiAobGVuID4gc3RybS5hdmFpbF9vdXQpIHsKICAgICAgICAgIGxlbiA9IHN0cm0uYXZhaWxfb3V0OwogICAgICAgIH0KICAgICAgICBpZiAobGVuID09PSAwKSB7CiAgICAgICAgICByZXR1cm47CiAgICAgICAgfQogICAgICAgIHV0aWxzLmFycmF5U2V0KHN0cm0ub3V0cHV0LCBzLnBlbmRpbmdfYnVmLCBzLnBlbmRpbmdfb3V0LCBsZW4sIHN0cm0ubmV4dF9vdXQpOwogICAgICAgIHN0cm0ubmV4dF9vdXQgKz0gbGVuOwogICAgICAgIHMucGVuZGluZ19vdXQgKz0gbGVuOwogICAgICAgIHN0cm0udG90YWxfb3V0ICs9IGxlbjsKICAgICAgICBzdHJtLmF2YWlsX291dCAtPSBsZW47CiAgICAgICAgcy5wZW5kaW5nIC09IGxlbjsKICAgICAgICBpZiAocy5wZW5kaW5nID09PSAwKSB7CiAgICAgICAgICBzLnBlbmRpbmdfb3V0ID0gMDsKICAgICAgICB9CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZmx1c2hfYmxvY2tfb25seShzLCBsYXN0KSB7CiAgICAgICAgdHJlZXMuX3RyX2ZsdXNoX2Jsb2NrKHMsIHMuYmxvY2tfc3RhcnQgPj0gMCA/IHMuYmxvY2tfc3RhcnQgOiAtMSwgcy5zdHJzdGFydCAtIHMuYmxvY2tfc3RhcnQsIGxhc3QpOwogICAgICAgIHMuYmxvY2tf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jsKICAgICAgICByZXR1cm4gbGVuOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGxvbmdlc3RfbWF0Y2gocywgY3VyX21hdGNoKSB7CiAgICAgICAgdmFyIGNoYWluX2xlbmd0aCA9IHMubWF4X2NoYWluX2xlbmd0aDsKICAgICAgICB2YXIgc2NhbiA9IHMuc3Ryc3RhcnQ7CiAgICAgICAgdmFyIG1hdGNoOwogICAgICAgIHZhciBsZW47CiAgICAgICAgdmFyIGJlc3RfbGVuID0gcy5wcmV2X2xlbmd0aDsKICAgICAgICB2YXIgbmljZV9tYXRjaCA9IHMubmljZV9tYXRjaDsKICAgICAgICB2YXIgbGltaXQgPSBzLnN0cnN0YXJ0ID4gcy53X3NpemUgLSBNSU5fTE9PS0FIRUFEID8gcy5zdHJzdGFydCAtIChzLndfc2l6ZSAtIE1JTl9MT09LQUhFQUQpIDogMDsKICAgICAgICB2YXIgX3dpbiA9IHMud2luZG93OwogICAgICAgIHZhciB3bWFzayA9IHMud19tYXNrOwogICAgICAgIHZhciBwcmV2ID0gcy5wcmV2OwogICAgICAgIHZhciBzdHJlbmQgPSBzLnN0cnN0YXJ0ICsgTUFYX01BVENIOwogICAgICAgIHZhciBzY2FuX2VuZDEgPSBfd2luW3NjYW4gKyBiZXN0X2xlbiAtIDFdOwogICAgICAgIHZhciBzY2FuX2VuZCA9IF93aW5bc2NhbiArIGJlc3RfbGVuXTsKICAgICAgICBpZiAocy5wcmV2X2xlbmd0aCA+PSBzLmdvb2RfbWF0Y2gpIHsKICAgICAgICAgIGNoYWluX2xlbmd0aCA+Pj0gMjsKICAgICAgICB9CiAgICAgICAgaWYgKG5pY2VfbWF0Y2ggPiBzLmxvb2thaGVhZCkgewogICAgICAgICAgbmljZV9tYXRjaCA9IHMubG9va2FoZWFkOwogICAgICAgIH0KICAgICAgICBkbyB7CiAgICAgICAgICBtYXRjaCA9IGN1cl9tYXRjaDsKICAgICAgICAgIGlmIChfd2luW21hdGNoICsgYmVzdF9sZW5dICE9PSBzY2FuX2VuZCB8fCBfd2luW21hdGNoICsgYmVzdF9sZW4gLSAxXSAhPT0gc2Nhbl9lbmQxIHx8IF93aW5bbWF0Y2hdICE9PSBfd2luW3NjYW5dIHx8IF93aW5bKyttYXRjaF0gIT09IF93aW5bc2NhbiArIDFdKSB7CiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgfQogICAgICAgICAgc2NhbiArPSAyOwogICAgICAgICAgbWF0Y2grKzsKICAgICAgICAgIGRvIHsKICAgICAgICAgIH0gd2hpbGUgKF93aW5bKytzY2FuXSA9PT0gX3dpblsrK21hdGNoXSAmJiBfd2luWysrc2Nhbl0gPT09IF93aW5bKyttYXRjaF0gJiYgX3dpblsrK3NjYW5dID09PSBfd2luWysrbWF0Y2hdICYmIF93aW5bKytzY2FuXSA9PT0gX3dpblsrK21hdGNoXSAmJiBfd2luWysrc2Nhbl0gPT09IF93aW5bKyttYXRjaF0gJiYgX3dpblsrK3NjYW5dID09PSBfd2luWysrbWF0Y2hdICYmIF93aW5bKytzY2FuXSA9PT0gX3dpblsrK21hdGNoXSAmJiBfd2luWysrc2Nhbl0gPT09IF93aW5bKyttYXRjaF0gJiYgc2NhbiA8IHN0cmVuZCk7CiAgICAgICAgICBsZW4gPSBNQVhfTUFUQ0ggLSAoc3RyZW5kIC0gc2Nhbik7CiAgICAgICAgICBzY2FuID0gc3RyZW5kIC0gTUFYX01BVENIOwogICAgICAgICAgaWYgKGxlbiA+IGJlc3RfbGVuKSB7CiAgICAgICAgICAgIHMubWF0Y2hfc3RhcnQgPSBjdXJfbWF0Y2g7CiAgICAgICAgICAgIGJlc3RfbGVuID0gbGVuOwogICAgICAgICAgICBpZiAobGVuID49IG5pY2VfbWF0Y2gpIHsKICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgICBzY2FuX2VuZDEgPSBfd2luW3NjYW4gKyBiZXN0X2xlbiAtIDFdOwogICAgICAgICAgICBzY2FuX2VuZCA9IF93aW5bc2NhbiArIGJlc3RfbGVuXTsKICAgICAgICAgIH0KICAgICAgICB9IHdoaWxlICgoY3VyX21hdGNoID0gcHJldltjdXJfbWF0Y2ggJiB3bWFza10pID4gbGltaXQgJiYgLS1jaGFpbl9sZW5ndGggIT09IDApOwogICAgICAgIGlmIChiZXN0X2xlbiA8PSBzLmxvb2thaGVhZCkgewogICAgICAgICAgcmV0dXJuIGJlc3RfbGVuOwogICAgICAgIH0KICAgICAgICByZXR1cm4gcy5sb29rYWhlYWQ7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZmlsbF93aW5kb3cocykgewogICAgICAgIHZhciBfd19zaXplID0gcy53X3NpemU7CiAgICAgICAgdmFyIHAsIG4sIG0sIG1vcmUsIHN0cjsKICAgICAgICBkbyB7CiAgICAgICAgICBtb3JlID0gcy53aW5kb3dfc2l6ZSAtIHMubG9va2FoZWFkIC0gcy5zdHJzdGFydDsKICAgICAgICAgIGlmIChzLnN0cnN0YXJ0ID49IF93X3NpemUgKyAoX3dfc2l6ZSAtIE1JTl9MT09LQUhFQUQpKSB7CiAgICAgICAgICAgIHV0aWxzLmFycmF5U2V0KHMud2luZG93LCBzLndpbmRvdywgX3dfc2l6ZSwgX3dfc2l6ZSwgMCk7CiAgICAgICAgICAgIHMubWF0Y2hfc3RhcnQgLT0gX3dfc2l6ZTsKICAgICAgICAgICAgcy5zdHJzdGFydCAtPSBfd19zaXplOwogICAgICAgICAgICBzLmJsb2NrX3N0YXJ0IC09IF93X3NpemU7CiAgICAgICAgICAgIG4gPSBzLmhhc2hfc2l6ZTsKICAgICAgICAgICAgcCA9IG47CiAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICBtID0gcy5oZWFkWy0tcF07CiAgICAgICAgICAgICAgcy5oZWFkW3BdID0gbSA+PSBfd19zaXplID8gbSAtIF93X3NpemUgOiAwOwogICAgICAgICAgICB9IHdoaWxlICgtLW4pOwogICAgICAgICAgICBuID0gX3dfc2l6ZTsKICAgICAgICAgICAgcCA9IG47CiAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICBtID0gcy5wcmV2Wy0tcF07CiAgICAgICAgICAgICAgcy5wcmV2W3BdID0gbSA+PSBfd19zaXplID8gbSAtIF93X3NpemUgOiAwOwogICAgICAgICAgICB9IHdoaWxlICgtLW4pOwogICAgICAgICAgICBtb3JlICs9IF93X3NpemU7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX2luID09PSAwKSB7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgICAgbiA9IHJlYWRfYnVmKHMuc3RybSwgcy53aW5kb3csIHMuc3Ryc3RhcnQgKyBzLmxvb2thaGVhZCwgbW9yZSk7CiAgICAgICAgICBzLmxvb2thaGVhZCArPSBuOwogICAgICAgICAgaWYgKHMubG9va2FoZWFkICsgcy5pbnNlcnQgPj0gTUlOX01BVENIKSB7CiAgICAgICAgICAgIHN0ciA9IHMuc3Ryc3RhcnQgLSBzLmluc2VydDsKICAgICAgICAgICAgcy5pbnNfaCA9IHMud2luZG93W3N0cl07CiAgICAgICAgICAgIHMuaW5zX2ggPSAocy5pbnNfaCA8PCBzLmhhc2hfc2hpZnQgXiBzLndpbmRvd1tzdHIgKyAxXSkgJiBzLmhhc2hfbWFzazsKICAgICAgICAgICAgd2hpbGUgKHMuaW5zZXJ0KSB7CiAgICAgICAgICAgICAgcy5pbnNfaCA9IChzLmluc19oIDw8IHMuaGFzaF9zaGlmdCBeIHMud2luZG93W3N0ciArIE1JTl9NQVRDSCAtIDFdKSAmIHMuaGFzaF9tYXNrOwogICAgICAgICAgICAgIHMucHJldltzdHIgJiBzLndfbWFza10gPSBzLmhlYWRbcy5pbnNfaF07CiAgICAgICAgICAgICAgcy5oZWFkW3MuaW5zX2hdID0gc3RyOwogICAgICAgICAgICAgIHN0cisrOwogICAgICAgICAgICAgIHMuaW5zZXJ0LS07CiAgICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkICsgcy5pbnNlcnQgPCBNSU5fTUFUQ0gpIHsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0gd2hpbGUgKHMubG9va2FoZWFkIDwgTUlOX0xPT0tBSEVBRCAmJiBzLnN0cm0uYXZhaWxfaW4gIT09IDApOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGRlZmxhdGVfc3RvcmVkKHMsIGZsdXNoKSB7CiAgICAgICAgdmFyIG1heF9ibG9ja19zaXplID0gNjU1MzU7CiAgICAgICAgaWYgKG1heF9ibG9ja19zaXplID4gcy5wZW5kaW5nX2J1Zl9zaXplIC0gNSkgewogICAgICAgICAgbWF4X2Jsb2NrX3NpemUgPSBzLnBlbmRpbmdfYnVmX3NpemUgLSA1OwogICAgICAgIH0KICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA8PSAxKSB7CiAgICAgICAgICAgIGZpbGxfd2luZG93KHMpOwogICAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPT09IDAgJiYgZmx1c2ggPT09IFpfTk9fRkxVU0gpIHsKICAgICAgICAgICAgICByZXR1cm4gQlNfTkVFRF9NT1JFOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA9PT0gMCkgewogICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBzLnN0cnN0YXJ0ICs9IHMubG9va2FoZWFkOwogICAgICAgICAgcy5sb29rYWhlYWQgPSAwOwogICAgICAgICAgdmFyIG1heF9zdGFydCA9IHMuYmxvY2tfc3RhcnQgKyBtYXhfYmxvY2tfc2l6ZTsKICAgICAgICAgIGlmIChzLnN0cnN0YXJ0ID09PSAwIHx8IHMuc3Ryc3RhcnQgPj0gbWF4X3N0YXJ0KSB7CiAgICAgICAgICAgIHMubG9va2FoZWFkID0gcy5zdHJzdGFydCAtIG1heF9zdGFydDsKICAgICAgICAgICAgcy5zdHJzdGFydCA9IG1heF9zdGFydDsKICAgICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCBmYWxzZSk7CiAgICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgaWYgKHMuc3Ryc3RhcnQgLSBzLmJsb2NrX3N0YXJ0ID49IHMud19zaXplIC0gTUlOX0xPT0tBSEVBRCkgewogICAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIGZhbHNlKTsKICAgICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgICByZXR1cm4gQlNfTkVFRF9NT1JFOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHMuaW5zZXJ0ID0gMDsKICAgICAgICBpZiAoZmx1c2ggPT09IFpfRklOSVNIKSB7CiAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIHRydWUpOwogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIEJTX0ZJTklTSF9TVEFSVEVEOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIEJTX0ZJTklTSF9ET05FOwogICAgICAgIH0KICAgICAgICBpZiAocy5zdHJzdGFydCA+IHMuYmxvY2tfc3RhcnQpIHsKICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgZmFsc2UpOwogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgfQogICAgICBmdW5jdGlvbiBkZWZsYXRlX2Zhc3QocywgZmx1c2gpIHsKICAgICAgICB2YXIgaGFzaF9oZWFkOwogICAgICAgIHZhciBiZmx1c2g7CiAgICAgICAgZm9yICg7IDsgKSB7CiAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPCBNSU5fTE9PS0FIRUFEKSB7CiAgICAgICAgICAgIGZpbGxfd2luZG93KHMpOwogICAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPCBNSU5fTE9PS0FIRUFEICYmIGZsdXNoID09PSBaX05PX0ZMVVNIKSB7CiAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPT09IDApIHsKICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgaGFzaF9oZWFkID0gMDsKICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA+PSBNSU5fTUFUQ0gpIHsKICAgICAgICAgICAgcy5pbnNfaCA9IChzLmluc19oIDw8IHMuaGFzaF9zaGlmdCBeIHMud2luZG93W3Muc3Ryc3RhcnQgKyBNSU5fTUFUQ0ggLSAxXSkgJiBzLmhhc2hfbWFzazsKICAgICAgICAgICAgaGFzaF9oZWFkID0gcy5wcmV2W3Muc3Ryc3RhcnQgJiBzLndfbWFza10gPSBzLmhlYWRbcy5pbnNfaF07CiAgICAgICAgICAgIHMuaGVhZFtzLmluc19oXSA9IHMuc3Ryc3RhcnQ7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoaGFzaF9oZWFkICE9PSAwICYmIHMuc3Ryc3RhcnQgLSBoYXNoX2hlYWQgPD0gcy53X3NpemUgLSBNSU5fTE9PS0FIRUFEKSB7CiAgICAgICAgICAgIHMubWF0Y2hfbGVuZ3RoID0gbG9uZ2VzdF9tYXRjaChzLCBoYXNoX2hlYWQpOwogICAgICAgICAgfQogICAgICAgICAgaWYgKHMubWF0Y2hfbGVuZ3RoID49IE1JTl9NQVRDSCkgewogICAgICAgICAgICBiZmx1c2ggPSB0cmVlcy5fdHJfdGFsbHkocywgcy5zdHJzdGFydCAtIHMubWF0Y2hfc3RhcnQsIHMubWF0Y2hfbGVuZ3RoIC0gTUlOX01BVENIKTsKICAgICAgICAgICAgcy5sb29rYWhlYWQgLT0gcy5tYXRjaF9sZW5ndGg7CiAgICAgICAgICAgIGlmIChzLm1hdGNoX2xlbmd0aCA8PSBzLm1heF9sYXp5X21hdGNoICYmIHMubG9va2FoZWFkID49IE1JTl9NQVRDSCkgewogICAgICAgICAgICAgIHMubWF0Y2hfbGVuZ3RoLS07CiAgICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgICAgcy5zdHJzdGFydCsrOwogICAgICAgICAgICAgICAgcy5pbnNfaCA9IChzLmluc19oIDw8IHMuaGFzaF9zaGlmdCBeIHMud2luZG93W3Muc3Ryc3RhcnQgKyBNSU5fTUFUQ0ggLSAxXSkgJiBzLmhhc2hfbWFzazsKICAgICAgICAgICAgICAgIGhhc2hfaGVhZCA9IHMucHJldltzLnN0cnN0YXJ0ICYgcy53X21hc2tdID0gcy5oZWFkW3MuaW5zX2hdOwogICAgICAgICAgICAgICAgcy5oZWFkW3MuaW5zX2hdID0gcy5zdHJzdGFydDsKICAgICAgICAgICAgICB9IHdoaWxlICgtLXMubWF0Y2hfbGVuZ3RoICE9PSAwKTsKICAgICAgICAgICAgICBzLnN0cnN0YXJ0Kys7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgcy5zdHJzdGFydCArPSBzLm1hdGNoX2xlbmd0aDsKICAgICAgICAgICAgICBzLm1hdGNoX2xlbmd0aCA9IDA7CiAgICAgICAgICAgICAgcy5pbnNfaCA9IHMud2luZG93W3Muc3Ryc3RhcnRdOwogICAgICAgICAgICAgIHMuaW5zX2ggPSAocy5pbnNfaCA8PCBzLmhhc2hfc2hpZnQgXiBzLndpbmRvd1tzLnN0cnN0YXJ0ICsgMV0pICYgcy5oYXNoX21hc2s7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGJmbHVzaCA9IHRyZWVzLl90cl90YWxseShzLCAwLCBzLndpbmRvd1tzLnN0cnN0YXJ0XSk7CiAgICAgICAgICAgIHMubG9va2FoZWFkLS07CiAgICAgICAgICAgIHMuc3Ryc3RhcnQrKzsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChiZmx1c2gpIHsKICAgICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCBmYWxzZSk7CiAgICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBzLmluc2VydCA9IHMuc3Ryc3RhcnQgPCBNSU5fTUFUQ0ggLSAxID8gcy5zdHJzdGFydCA6IE1JTl9NQVRDSCAtIDE7CiAgICAgICAgaWYgKGZsdXNoID09PSBaX0ZJTklTSCkgewogICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCB0cnVlKTsKICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgIHJldHVybiBCU19GSU5JU0hfU1RBUlRFRDsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBCU19GSU5JU0hfRE9ORTsKICAgICAgICB9CiAgICAgICAgaWYgKHMubGFzdF9saXQpIHsKICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgZmFsc2UpOwogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIEJTX0JMT0NLX0RPTkU7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZGVmbGF0ZV9zbG93KHMsIGZsdXNoKSB7CiAgICAgICAgdmFyIGhhc2hfaGVhZDsKICAgICAgICB2YXIgYmZsdXNoOwogICAgICAgIHZhciBtYXhfaW5zZXJ0OwogICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgaWYgKHMubG9va2FoZWFkIDwgTUlOX0xPT0tBSEVBRCkgewogICAgICAgICAgICBmaWxsX3dpbmRvdyhzKTsKICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkIDwgTUlOX0xPT0tBSEVBRCAmJiBmbHVzaCA9PT0gWl9OT19GTFVTSCkgewogICAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkID09PSAwKSB7CiAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGhhc2hfaGVhZCA9IDA7CiAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPj0gTUlOX01BVENIKSB7CiAgICAgICAgICAgIHMuaW5zX2ggPSAocy5pbnNfaCA8PCBzLmhhc2hfc2hpZnQgXiBzLndpbmRvd1tzLnN0cnN0YXJ0ICsgTUlOX01BVENIIC0gMV0pICYgcy5oYXNoX21hc2s7CiAgICAgICAgICAgIGhhc2hfaGVhZCA9IHMucHJldltzLnN0cnN0YXJ0ICYgcy53X21hc2tdID0gcy5oZWFkW3MuaW5zX2hdOwogICAgICAgICAgICBzLmhlYWRbcy5pbnNfaF0gPSBzLnN0cnN0YXJ0OwogICAgICAgICAgfQogICAgICAgICAgcy5wcmV2X2xlbmd0aCA9IHMubWF0Y2hfbGVuZ3RoOwogICAgICAgICAgcy5wcmV2X21hdGNoID0gcy5tYXRjaF9zdGFydDsKICAgICAgICAgIHMubWF0Y2hfbGVuZ3RoID0gTUlOX01BVENIIC0gMTsKICAgICAgICAgIGlmIChoYXNoX2hlYWQgIT09IDAgJiYgcy5wcmV2X2xlbmd0aCA8IHMubWF4X2xhenlfbWF0Y2ggJiYgcy5zdHJzdGFydCAtIGhhc2hfaGVhZCA8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X21hc2tdID0gcy5oZWFkW3MuaW5zX2hdOwogICAgICAgICAgICAgICAgcy5oZWFkW3MuaW5zX2hdID0gcy5zdHJzdGFydDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0gd2hpbGUgKC0tcy5wcmV2X2xlbmd0aCAhPT0gMCk7CiAgICAgICAgICAgIHMubWF0Y2hfYXZhaWxhYmxlID0gMDsKICAgICAgICAgICAgcy5tYXRjaF9sZW5ndGggPSBNSU5fTUFUQ0ggLSAxOwogICAgICAgICAgICBzLnN0cnN0YXJ0Kys7CiAgICAgICAgICAgIGlmIChiZmx1c2gpIHsKICAgICAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIGZhbHNlKTsKICAgICAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSBpZiAocy5tYXRjaF9hdmFpbGFibGUpIHsKICAgICAgICAgICAgYmZsdXNoID0gdHJlZXMuX3RyX3RhbGx5KHMsIDAsIHMud2luZG93W3Muc3Ryc3RhcnQgLSAxXSk7CiAgICAgICAgICAgIGlmIChiZmx1c2gpIHsKICAgICAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIGZhbHNlKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBzLnN0cnN0YXJ0Kys7CiAgICAgICAgICAgIHMubG9va2FoZWFkLS07CiAgICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgfQogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcy5tYXRjaF9hdmFpbGFibGUgPSAxOwogICAgICAgICAgICBzLnN0cnN0YXJ0Kys7CiAgICAgICAgICAgIHMubG9va2FoZWFkLS07CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChzLm1hdGNoX2F2YWlsYWJsZSkgewogICAgICAgICAgYmZsdXNoID0gdHJlZXMuX3RyX3RhbGx5KHMsIDAsIHMud2luZG93W3Muc3Ryc3RhcnQgLSAxXSk7CiAgICAgICAgICBzLm1hdGNoX2F2YWlsYWJsZSA9IDA7CiAgICAgICAgfQogICAgICAgIHMuaW5zZXJ0ID0gcy5zdHJzdGFydCA8IE1JTl9NQVRDSCAtIDEgPyBzLnN0cnN0YXJ0IDogTUlOX01BVENIIC0gMTsKICAgICAgICBpZiAoZmx1c2ggPT09IFpfRklOSVNIKSB7CiAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIHRydWUpOwogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIEJTX0ZJTklTSF9TVEFSVEVEOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIEJTX0ZJTklTSF9ET05FOwogICAgICAgIH0KICAgICAgICBpZiAocy5sYXN0X2xpdCkgewogICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCBmYWxzZSk7CiAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICByZXR1cm4gQlNfTkVFRF9NT1JFOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gQlNfQkxPQ0tfRE9ORTsKICAgICAgfQogICAgICBmdW5jdGlvbiBkZWZsYXRlX3JsZShzLCBmbHVzaCkgewogICAgICAgIHZhciBiZmx1c2g7CiAgICAgICAgdmFyIHByZXY7CiAgICAgICAgdmFyIHNjYW4sIHN0cmVuZDsKICAgICAgICB2YXIgX3dpbiA9IHMud2luZG93OwogICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgaWYgKHMubG9va2FoZWFkIDw9IE1BWF9NQVRDSCkgewogICAgICAgICAgICBmaWxsX3dpbmRvdyhzKTsKICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkIDw9IE1BWF9NQVRDSCAmJiBmbHVzaCA9PT0gWl9OT19GTFVTSCkgewogICAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkID09PSAwKSB7CiAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIHMubWF0Y2hfbGVuZ3RoID0gMDsKICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA+PSBNSU5fTUFUQ0ggJiYgcy5zdHJzdGFydCA+IDApIHsKICAgICAgICAgICAgc2NhbiA9IHMuc3Ryc3RhcnQgLSAxOwogICAgICAgICAgICBwcmV2ID0gX3dpbltzY2FuXTsKICAgICAgICAgICAgaWYgKHByZXYgPT09IF93aW5bKytzY2FuXSAmJiBwcmV2ID09PSBfd2luWysrc2Nhbl0gJiYgcHJldiA9PT0gX3dpblsrK3NjYW5dKSB7CiAgICAgICAgICAgICAgc3RyZW5kID0gcy5zdHJzdGFydCArIE1BWF9NQVRDSDsKICAgICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgfSB3aGlsZSAocHJldiA9PT0gX3dpblsrK3NjYW5dICYmIHByZXYgPT09IF93aW5bKytzY2FuXSAmJiBwcmV2ID09PSBfd2luWysrc2Nhbl0gJiYgcHJldiA9PT0gX3dpblsrK3NjYW5dICYmIHByZXYgPT09IF93aW5bKytzY2FuXSAmJiBwcmV2ID09PSBfd2luWysrc2Nhbl0gJiYgcHJldiA9PT0gX3dpblsrK3NjYW5dICYmIHByZXYgPT09IF93aW5bKytzY2FuXSAmJiBzY2FuIDwgc3RyZW5kKTsKICAgICAgICAgICAgICBzLm1hdGNoX2xlbmd0aCA9IE1BWF9NQVRDSCAtIChzdHJlbmQgLSBzY2FuKTsKICAgICAgICAgICAgICBpZiAocy5tYXRjaF9sZW5ndGggPiBzLmxvb2thaGVhZCkgewogICAgICAgICAgICAgICAgcy5tYXRjaF9sZW5ndGggPSBzLmxvb2thaGVhZDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGlmIChzLm1hdGNoX2xlbmd0aCA+PSBNSU5fTUFUQ0gpIHsKICAgICAgICAgICAgYmZsdXNoID0gdHJlZXMuX3RyX3RhbGx5KHMsIDEsIHMubWF0Y2hfbGVuZ3RoIC0gTUlOX01BVENIKTsKICAgICAgICAgICAgcy5sb29rYWhlYWQgLT0gcy5tYXRjaF9sZW5ndGg7CiAgICAgICAgICAgIHMuc3Ryc3RhcnQgKz0gcy5tYXRjaF9sZW5ndGg7CiAgICAgICAgICAgIHMubWF0Y2hfbGVuZ3RoID0gMDsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGJmbHVzaCA9IHRyZWVzLl90cl90YWxseShzLCAwLCBzLndpbmRvd1tzLnN0cnN0YXJ0XSk7CiAgICAgICAgICAgIHMubG9va2FoZWFkLS07CiAgICAgICAgICAgIHMuc3Ryc3RhcnQrKzsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChiZmx1c2gpIHsKICAgICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCBmYWxzZSk7CiAgICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBzLmluc2VydCA9IDA7CiAgICAgICAgaWYgKGZsdXNoID09PSBaX0ZJTklTSCkgewogICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCB0cnVlKTsKICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgIHJldHVybiBCU19GSU5JU0hfU1RBUlRFRDsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBCU19GSU5JU0hfRE9ORTsKICAgICAgICB9CiAgICAgICAgaWYgKHMubGFzdF9saXQpIHsKICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgZmFsc2UpOwogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIEJTX0JMT0NLX0RPTkU7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZGVmbGF0ZV9odWZmKHMsIGZsdXNoKSB7CiAgICAgICAgdmFyIGJmbHVzaDsKICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA9PT0gMCkgewogICAgICAgICAgICBmaWxsX3dpbmRvdyhzKTsKICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkID09PSAwKSB7CiAgICAgICAgICAgICAgaWYgKGZsdXNoID09PSBaX05PX0ZMVVNIKSB7CiAgICAgICAgICAgICAgICByZXR1cm4gQlNfTkVFRF9NT1JFOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgcy5tYXRjaF9sZW5ndGggPSAwOwogICAgICAgICAgYmZsdXNoID0gdHJlZXMuX3RyX3RhbGx5KHMsIDAsIHMud2luZG93W3Muc3Ryc3RhcnRdKTsKICAgICAgICAgIHMubG9va2FoZWFkLS07CiAgICAgICAgICBzLnN0cnN0YXJ0Kys7CiAgICAgICAgICBpZiAoYmZsdXNoKSB7CiAgICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgZmFsc2UpOwogICAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcy5pbnNlcnQgPSAwOwogICAgICAgIGlmIChmbHVzaCA9PT0gWl9GSU5JU0gpIHsKICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgdHJ1ZSk7CiAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICByZXR1cm4gQlNfRklOSVNIX1NUQVJURUQ7CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gQlNfRklOSVNIX0RPTkU7CiAgICAgICAgfQogICAgICAgIGlmIChzLmxhc3RfbGl0KSB7CiAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIGZhbHNlKTsKICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiBCU19CTE9DS19ET05FOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIENvbmZpZyhnb29kX2xlbmd0aCwgbWF4X2xhenksIG5pY2VfbGVuZ3RoLCBtYXhfY2hhaW4sIGZ1bmMpIHsKICAgICAgICB0aGlzLmdvb2RfbGVuZ3RoID0gZ29vZF9sZW5ndGg7CiAgICAgICAgdGhpcy5tYXhfbGF6eSA9IG1heF9sYXp5OwogICAgICAgIHRoaXMubmljZV9sZW5ndGggPSBuaWNlX2xlbmd0aDsKICAgICAgICB0aGlzLm1heF9jaGFpbiA9IG1heF9jaGFpbjsKICAgICAgICB0aGlzLmZ1bmMgPSBmdW5jOwogICAgICB9CiAgICAgIHZhciBjb25maWd1cmF0aW9uX3RhYmxlOwogICAgICBjb25maWd1cmF0aW9uX3RhYmxlID0gWwogICAgICAgIG5ldyBDb25maWcoMCwgMCwgMCwgMCwgZGVmbGF0ZV9zdG9yZWQpLAogICAgICAgIG5ldyBDb25maWcoNCwgNCwgOCwgNCwgZGVmbGF0ZV9mYXN0KSwKICAgICAgICBuZXcgQ29uZmlnKDQsIDUsIDE2LCA4LCBkZWZsYXRlX2Zhc3QpLAogICAgICA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IHMucHJldl9sZW5ndGggPSBNSU5fTUFUQ0ggLSAxOwogICAgICAgIHMubWF0Y2hfYXZhaWxhYmxlID0gMDsKICAgICAgICBzLmluc19oID0gMDsKICAgICAgfQogICAgICBmdW5jdGlvbiBEZWZsYXRlU3RhdGUoKSB7CiAgICAgICAgdGhpcy5zdHJtID0gbnVsbDsKICAgICAgICB0aGlzLnN0YXR1cyA9IDA7CiAgICAgICAgdGhpcy5wZW5kaW5nX2J1ZiA9IG51bGw7CiAgICAgICAgdGhpcy5wZW5kaW5nX2J1Zl9zaXplID0gMDsKICAgICAgICB0aGlzLnBlbmRpbmdfb3V0ID0gMDsKICAgICAgICB0aGlzLnBlbmRpbmcgPSAwOwogICAgICAgIHRoaXMud3JhcCA9IDA7CiAgICAgICAgdGhpcy5nemhlYWQgPSBudWxsOwogICAgICAgIHRoaXMuZ3ppbmRleCA9IDA7CiAgICAgICAgdGhpcy5tZXRob2QgPSBaX0RFRkxBVEVEOwogICAgICAgIHRoaXMubGFzdF9mbHVzaCA9IC0xOwogICAgICAgIHRoaXMud19zaXplID0gMDsKICAgICAgICB0aGlzLndfYml0cyA9IDA7CiAgICAgICAgdGhpcy53X21hc2sgPSAwOwogICAgICAgIHRoaXMud2luZG93ID0gbnVsbDsKICAgICAgICB0aGlzLndpbmRvd19zaXplID0gMDsKICAgICAgICB0aGlzLnByZXYgPSBudWxsOwogICAgICAgIHRoaXMuaGVhZCA9IG51bGw7CiAgICAgICAgdGhpcy5pbnNfaCA9IDA7CiAgICAgICAgdGhpcy5oYXNoX3NpemUgPSAwOwogICAgICAgIHRoaXMuaGFzaF9iaXRzID0gMDsKICAgICAgICB0aGlzLmhhc2hfbWFzayA9IDA7CiAgICAgICAgdGhpcy5oYXNoX3NoaWZ0ID0gMDsKICAgICAgICB0aGlzLmJsb2NrX3N0YXJ0ID0gMDsKICAgICAgICB0aGlzLm1hdGNoX2xlbmd0aCA9IDA7CiAgICAgICAgdGhpcy5wcmV2X21hdGNoID0gMDsKICAgICAgICB0aGlzLm1hdGNoX2F2YWlsYWJsZSA9IDA7CiAgICAgICAgdGhpcy5zdHJzdGFydCA9IDA7CiAgICAgICAgdGhpcy5tYXRjaF9zdGFydCA9IDA7CiAgICAgICAgdGhpcy5sb29rYWhlYWQgPSAwOwogICAgICAgIHRoaXMucHJldl9sZW5ndGggPSAwOwogICAgICAgIHRoaXMubWF4X2NoYWluX2xlbmd0aCA9IDA7CiAgICAgICAgdGhpcy5tYXhfbGF6eV9tYXRjaCA9IDA7CiAgICAgICAgdGhpcy5sZXZlbCA9IDA7CiAgICAgICAgdGhpcy5zdHJhdGVneSA9IDA7CiAgICAgICAgdGhpcy5nb29kX21hdGNoID0gMDsKICAgICAgICB0aGlzLm5pY2VfbWF0Y2ggPSAwOwogICAgICAgIHRoaXMuZHluX2x0cmVlID0gbmV3IHV0aWxzLkJ1ZjE2KEhFQVBfU0laRSAqIDIpOwogICAgICAgIHRoaXMuZHluX2R0cmVlID0gbmV3IHV0aWxzLkJ1ZjE2KCgyICogRF9DT0RFUyArIDEpICogMik7CiAgICAgICAgdGhpcy5ibF90cmVlID0gbmV3IHV0aWxzLkJ1ZjE2KCgyICogQkxfQ09ERVMgKyAxKSAqIDIpOwogICAgICAgIHplcm8odGhpcy5keW5fbHRyZWUpOwogICAgICAgIHplcm8odGhpcy5keW5fZHRyZWUpOwogICAgICAgIHplcm8odGhpcy5ibF90cmVlKTsKICAgICAgICB0aGlzLmxfZGVzYyA9IG51bGw7CiAgICAgICAgdGhpcy5kX2Rlc2MgPSBudWxsOwogICAgICAgIHRoaXMuYmxfZGVzYyA9IG51bGw7CiAgICAgICAgdGhpcy5ibF9jb3VudCA9IG5ldyB1dGlscy5CdWYxNihNQVhfQklUUyArIDEpOwogICAgICAgIHRoaXMuaGVhcCA9IG5ldyB1dGlscy5CdWYxNigyICogTF9DT0RFUyArIDEpOwogICAgICAgIHplcm8odGhpcy5oZWFwKTsKICAgICAgICB0aGlzLmhlYXBfbGVuID0gMDsKICAgICAgICB0aGlzLmhlYXBfbWF4ID0gMDsKICAgICAgICB0aGlzLmRlcHRoID0gbmV3IHV0aWxzLkJ1ZjE2KDIgKiBMX0NPREVTICsgMSk7CiAgICAgICAgemVybyh0aGlzLmRlcHRoKTsKICAgICAgICB0aGlzLmxfYnVmID0gMDsKICAgICAgICB0aGlzLmxpdF9idWZzaXplID0gMDsKICAgICAgICB0aGlzLmxhc3RfbGl0ID0gMDsKICAgICAgICB0aGlzLmRfYnVmID0gMDsKICAgICAgICB0aGlzLm9wdF9sZW4gPSAwOwogICAgICAgIHRoaXMuc3RhdGljX2xlbiA9IDA7CiAgICAgICAgdGhpcy5tYXRjaGVzID0gMDsKICAgICAgICB0aGlzLmluc2VydCA9IDA7CiAgICAgICAgdGhpcy5iaV9idWYgPSAwOwogICAgICAgIHRoaXMuYmlfdmFsaWQgPSAwOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGRlZmxhdGVSZXNldEtlZXAoc3RybSkgewogICAgICAgIHZhciBzOwogICAgICAgIGlmICghc3RybSB8fCAhc3RybS5zdGF0ZSkgewogICAgICAgICAgcmV0dXJuIGVycihzdHJtLCBaX1NUUkVBTV9FUlJPUik7CiAgICAgICAgfQogICAgICAgIHN0cm0udG90YWxfaW4gPSBzdHJtLnRvdGFsX291dCA9IDA7CiAgICAgICAgc3RybS5kYXRhX3R5cGUgPSBaX1VOS05PV047CiAgICAgICAgcyA9IHN0cm0uc3RhdGU7CiAgICAgICAgcy5wZW5kaW5nID0gMDsKICAgICAgICBzLnBlbmRpbmdfb3V0ID0gMDsKICAgICAgICBpZiAocy53cmFwIDwgMCkgewogICAgICAgICAgcy53cmFwID0gLXMud3JhcDsKICAgICAgICB9CiAgICAgICAgcy5zdGF0dXMgPSBzLndyYXAgPyBJTklUX1NUQVRFIDogQlVTWV9TVEFURTsKICAgICAgICBzdHJtLmFkbGVyID0gcy53cmFwID09PSAyID8gMCA6IDE7CiAgICAgICAgcy5sYXN0X2ZsdXNoID0gWl9OT19GTFVTSDsKICAgICAgICB0cmVlcy5fdHJfaW5pdChzKTsKICAgICAgICByZXR1cm4gWl9PSzsKICAgICAgfQogICAgICBmdW5jdGlvbiBkZWZsYXRlUmVzZXQoc3RybSkgewogICAgICAgIHZhciByZXQgPSBkZWZsYXRlUmVzZXRLZWVwKHN0cm0pOwogICAgICAgIGlmIChyZXQgPT09IFpfT0spIHsKICAgICAgICAgIGxtX2luaXQoc3RybS5zdGF0ZSk7CiAgICAgICAgfQogICAgICAgIHJldHVybiByZXQ7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZGVmbGF0ZVNldEhlYWRlcihzdHJtLCBoZWFkKSB7CiAgICAgICAgaWYgKCFzdHJtIHx8ICFzdHJtLnN0YXRlKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIGlmIChzdHJtLnN0YXRlLndyYXAgIT09IDIpIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgc3RybS5zdGF0ZS5nemhlYWQgPSBoZWFkOwogICAgICAgIHJldHVybiBaX09LOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGRlZmxhdGVJbml0MihzdHJtLCBsZXZlbCwgbWV0aG9kLCB3aW5kb3dCaXRzLCBtZW1MZXZlbCwgc3RyYXRlZ3kpIHsKICAgICAgICBpZiAoIXN0cm0pIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgdmFyIHdyYXAgPSAxOwogICAgICAgIGlmIChsZXZlbCA9PT0gWl9ERUZBVUxUX0NPTVBSRVNTSU9OKSB7CiAgICAgICAgICBsZXZlbCA9IDY7CiAgICAgICAgfQogICAgICAgIGlmICh3aW5kb3dCaXRzIDwgMCkgewogICAgICAgICAgd3JhcCA9IDA7CiAgICAgICAgICB3aW5kb3dCaXRzID0gLXdpbmRvd0JpdHM7CiAgICAgICAgfSBlbHNlIGlmICh3aW5kb3dCaXRzID4gMTUpIHsKICAgICAgICAgIHdyYXAgPSAyOwogICAgICAgICAgd2luZG93Qml0cyAtPSAxNjsKICAgICAgICB9CiAgICAgICAgaWYgKG1lbUxldmVsIDwgMSB8fCBtZW1MZXZlbCA+IE1BWF9NRU1fTEVWRUwgfHwgbWV0aG9kICE9PSBaX0RFRkxBVEVEIHx8IHdpbmRvd0JpdHMgPCA4IHx8IHdpbmRvd0JpdHMgPiAxNSB8fCBsZXZlbCA8IDAgfHwgbGV2ZWwgPiA5IHx8IHN0cmF0ZWd5IDwgMCB8fCBzdHJhdGVneSA+IFpfRklYRUQpIHsKICAgICAgICAgIHJldHVybiBlcnIoc3RybSwgWl9TVFJFQU1fRVJST1IpOwogICAgICAgIH0KICAgICAgICBpZiAod2luZG93Qml0cyA9PT0gOCkgewogICAgICAgICAgd2luZG93Qml0cyA9IDk7CiAgICAgICAgfQogICAgICAgIHZhciBzID0gbmV3IERlZmxhdGVTdGF0ZSgpOwogICAgICAgIHN0cm0uc3RhdGUgPSBzOwogICAgICAgIHMuc3RybSA9IHN0cm07CiAgICAgICAgcy53cmFwID0gd3JhcDsKICAgICAgICBzLmd6aGVhZCA9IG51bGw7CiAgICAgICAgcy53X2JpdHMgPSB3aW5kb3dCaXRzOwogICAgICAgIHMud19zaXplID0gMSA8PCBzLndfYml0czsKICAgICAgICBzLndfbWFzayA9IHMud19zaXplIC0gMTsKICAgICAgICBzLmhhc2hfYml0cyA9IG1lbUxldmVsICsgNzsKICAgICAgICBzLmhhc2hfc2l6ZSA9IDEgPDwgcy5oYXNoX2JpdHM7CiAgICAgICAgcy5oYXNoX21hc2sgPSBzLmhhc2hfc2l6ZSAtIDE7CiAgICAgICAgcy5oYXNoX3NoaWZ0ID0gfn4oKHMuaGFzaF9iaXRzICsgTUlOX01BVENIIC0gMSkgLyBNSU5fTUFUQ0gpOwogICAgICAgIHMud2luZG93ID0gbmV3IHV0aWxzLkJ1Zjgocy53X3NpemUgKiAyKTs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ICAgICAgIHMgPSBzdHJtLnN0YXRlOwogICAgICAgIGlmICghc3RybS5vdXRwdXQgfHwgIXN0cm0uaW5wdXQgJiYgc3RybS5hdmFpbF9pbiAhPT0gMCB8fCBzLnN0YXR1cyA9PT0gRklOSVNIX1NUQVRFICYmIGZsdXNoICE9PSBaX0ZJTklTSCkgewogICAgICAgICAgcmV0dXJuIGVycihzdHJtLCBzdHJtLmF2YWlsX291dCA9PT0gMCA/IFpfQlVGX0VSUk9SIDogWl9TVFJFQU1fRVJST1IpOwogICAgICAgIH0KICAgICAgICBzLnN0cm0gPSBzdHJtOwogICAgICAgIG9sZF9mbHVzaCA9IHMubGFzdF9mbHVzaDsKICAgICAgICBzLmxhc3RfZmx1c2ggPSBmbHVzaDsKICAgICAgICBpZiAocy5zdGF0dXMgPT09IElOSVRfU1RBVEUpIHsKICAgICAgICAgIGlmIChzLndyYXAgPT09IDIpIHsKICAgICAgICAgICAgc3RybS5hZGxlciA9IDA7CiAgICAgICAgICAgIHB1dF9ieXRlKHMsIDMxKTsKICAgICAgICAgICAgcHV0X2J5dGUocywgMTM5KTsKICAgICAgICAgICAgcHV0X2J5dGUocywgOCk7CiAgICAgICAgICAgIGlmICghcy5nemhlYWQpIHsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCAwKTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCAwKTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCAwKTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCAwKTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCAwKTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCBzLmxldmVsID09PSA5ID8gMiA6IHMuc3RyYXRlZ3kgPj0gWl9IVUZGTUFOX09OTFkgfHwgcy5sZXZlbCA8IDIgPyA0IDogMCk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgT1NfQ09ERSk7CiAgICAgICAgICAgICAgcy5zdGF0dXMgPSBCVVNZX1NUQVRFOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHB1dF9ieXRlKHMsIChzLmd6aGVhZC50ZXh0ID8gMSA6IDApICsgKHMuZ3poZWFkLmhjcmMgPyAyIDogMCkgKyAoIXMuZ3poZWFkLmV4dHJhID8gMCA6IDQpICsgKCFzLmd6aGVhZC5uYW1lID8gMCA6IDgpICsgKCFzLmd6aGVhZC5jb21tZW50ID8gMCA6IDE2KSk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgcy5nemhlYWQudGltZSAmIDI1NSk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgcy5nemhlYWQudGltZSA+PiA4ICYgMjU1KTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCBzLmd6aGVhZC50aW1lID4+IDE2ICYgMjU1KTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCBzLmd6aGVhZC50aW1lID4+IDI0ICYgMjU1KTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCBzLmxldmVsID09PSA5ID8gMiA6IHMuc3RyYXRlZ3kgPj0gWl9IVUZGTUFOX09OTFkgfHwgcy5sZXZlbCA8IDIgPyA0IDogMCk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgcy5nemhlYWQub3MgJiAyNTUpOwogICAgICAgICAgICAgIGlmIChzLmd6aGVhZC5leHRyYSAmJiBzLmd6aGVhZC5leHRyYS5sZW5ndGgpIHsKICAgICAgICAgICAgICAgIHB1dF9ieXRlKHMsIHMuZ3poZWFkLmV4dHJhLmxlbmd0aCAmIDI1NSk7CiAgICAgICAgICAgICAgICBwdXRfYnl0ZShzLCBzLmd6aGVhZC5leHRyYS5sZW5ndGggPj4gOCAmIDI1NSk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGlmIChzLmd6aGVhZC5oY3JjKSB7CiAgICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gY3JjMzIoc3RybS5hZGxlciwgcy5wZW5kaW5nX2J1Ziwgcy5wZW5kaW5nLCAwKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgcy5nemluZGV4ID0gMDsKICAgICAgICAgICAgICBzLnN0YXR1cyA9IEVYVFJBX1NUQVRFOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICB2YXIgaGVhZGVyID0gWl9ERUZMQVRFRCArIChzLndfYml0cyAtIDggPDwgNCkgPDwgODsKICAgICAgICAgICAgdmFyIGxldmVsX2ZsYWdzID0gLTE7CiAgICAgICAgICAgIGlmIChzLnN0cmF0ZWd5ID49IFpfSFVGRk1BTl9PTkxZIHx8IHMubGV2ZWwgPCAyKSB7CiAgICAgICAgICAgICAgbGV2ZWxfZmxhZ3MgPSAwOwogICAgICAgICAgICB9IGVsc2UgaWYgKHMubGV2ZWwgPCA2KSB7CiAgICAgICAgICAgICAgbGV2ZWxfZmxhZ3MgPSAxOwogICAgICAgICAgICB9IGVsc2UgaWYgKHMubGV2ZWwgPT09IDYpIHsKICAgICAgICAgICAgICBsZXZlbF9mbGFncyA9IDI7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgbGV2ZWxfZmxhZ3MgPSAzOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGhlYWRlciB8PSBsZXZlbF9mbGFncyA8PCA2OwogICAgICAgICAgICBpZiAocy5zdHJzdGFydCAhPT0gMCkgewogICAgICAgICAgICAgIGhlYWRlciB8PSBQUkVTRVRfRElDVDsKICAgICAgICAgICAgfQogICAgICAgICAgICBoZWFkZXIgKz0gMzEgLSBoZWFkZXIgJSAzMTsKICAgICAgICAgICAgcy5zdGF0dXMgPSBCVVNZX1NUQVRFOwogICAgICAgICAgICBwdXRTaG9ydE1TQihzLCBoZWFkZXIpOwogICAgICAgICAgICBpZiAocy5zdHJzdGFydCAhPT0gMCkgewogICAgICAgICAgICAgIHB1dFNob3J0TVNCKHMsIHN0cm0uYWRsZXIgPj4+IDE2KTsKICAgICAgICAgICAgICBwdXRTaG9ydE1TQihzLCBzdHJtLmFkbGVyICYgNjU1MzUpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHN0cm0uYWRsZXIgPSAxOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAocy5zdGF0dXMgPT09IEVYVFJBX1NUQVRFKSB7CiAgICAgICAgICBpZiAocy5nemhlYWQuZXh0cmEpIHsKICAgICAgICAgICAgYmVnID0gcy5wZW5kaW5nOwogICAgICAgICAgICB3aGlsZSAocy5nemluZGV4IDwgKHMuZ3poZWFkLmV4dHJhLmxlbmd0aCAmIDY1NTM1KSkgewogICAgICAgICAgICAgIGlmIChzLnBlbmRpbmcgPT09IHMucGVuZGluZ19idWZfc2l6ZSkgewogICAgICAgICAgICAgICAgaWYgKHMuZ3poZWFkLmhjcmMgJiYgcy5wZW5kaW5nID4gYmVnKSB7CiAgICAgICAgICAgICAgICAgIHN0cm0uYWRsZXIgPSBjcmMzMihzdHJtLmFkbGVyLCBzLnBlbmRpbmdfYnVmLCBzLnBlbmRpbmcgLSBiZWcsIGJlZyk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBmbHVzaF9wZW5kaW5nKHN0cm0pOwogICAgICAgICAgICAgICAgYmVnID0gcy5wZW5kaW5nOwogICAgICAgICAgICAgICAgaWYgKHMucGVuZGluZyA9PT0gcy5wZW5kaW5nX2J1Zl9zaXplKSB7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBwdXRfYnl0ZShzLCBzLmd6aGVhZC5leHRyYVtzLmd6aW5kZXhdICYgMjU1KTsKICAgICAgICAgICAgICBzLmd6aW5kZXgrKzsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAocy5nemhlYWQuaGNyYyAmJiBzLnBlbmRpbmcgPiBiZWcpIHsKICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gY3JjMzIoc3RybS5hZGxlciwgcy5wZW5kaW5nX2J1Ziwgcy5wZW5kaW5nIC0gYmVnLCBiZWcpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzLmd6aW5kZXggPT09IHMuZ3poZWFkLmV4dHJhLmxlbmd0aCkgewogICAgICAgICAgICAgIHMuZ3ppbmRleCA9IDA7CiAgICAgICAgICAgICAgcy5zdGF0dXMgPSBOQU1FX1NUQVRFOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBzLnN0YXR1cyA9IE5BTUVfU1RBVEU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChzLnN0YXR1cyA9PT0gTkFNRV9TVEFURSkgewogICAgICAgICAgaWYgKHMuZ3poZWFkLm5hbWUpIHsKICAgICAgICAgICAgYmVnID0gcy5wZW5kaW5nOwogICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgaWYgKHMucGVuZGluZyA9PT0gcy5wZW5kaW5nX2J1Zl9zaXplKSB7CiAgICAgICAgICAgICAgICBpZiAocy5nemhlYWQuaGNyYyAmJiBzLnBlbmRpbmcgPiBiZWcpIHsKICAgICAgICAgICAgICAgICAgc3RybS5hZGxlciA9IGNyYzMyKHN0cm0uYWRsZXIsIHMucGVuZGluZ19idWYsIHMucGVuZGluZyAtIGJlZywgYmVnKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGZsdXNoX3BlbmRpbmcoc3RybSk7CiAgICAgICAgICAgICAgICBiZWcgPSBzLnBlbmRpbmc7CiAgICAgICAgICAgICAgICBpZiAocy5wZW5kaW5nID09PSBzLnBlbmRpbmdfYnVmX3NpemUpIHsKICAgICAgICAgICAgICAgICAgdmFsID0gMTsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGlmIChzLmd6aW5kZXggPCBzLmd6aGVhZC5uYW1lLmxlbmd0aCkgewogICAgICAgICAgICAgICAgdmFsID0gcy5nemhlYWQubmFtZS5jaGFyQ29kZUF0KHMuZ3ppbmRleCsrKSAmIDI1NTsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgdmFsID0gMDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgdmFsKTsKICAgICAgICAgICAgfSB3aGlsZSAodmFsICE9PSAwKTsKICAgICAgICAgICAgaWYgKHMuZ3poZWFkLmhjcmMgJiYgcy5wZW5kaW5nID4gYmVnKSB7CiAgICAgICAgICAgICAgc3RybS5hZGxlciA9IGNyYzMyKHN0cm0uYWRsZXIsIHMucGVuZGluZ19idWYsIHMucGVuZGluZyAtIGJlZywgYmVnKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAodmFsID09PSAwKSB7CiAgICAgICAgICAgICAgcy5nemluZGV4ID0gMDsKICAgICAgICAgICAgICBzLnN0YXR1cyA9IENPTU1FTlRfU1RBVEU7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHMuc3RhdHVzID0gQ09NTUVOVF9TVEFURTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKHMuc3RhdHVzID09PSBDT01NRU5UX1NUQVRFKSB7CiAgICAgICAgICBpZiAocy5nemhlYWQuY29tbWVudCkgewogICAgICAgICAgICBiZWcgPSBzLnBlbmRpbmc7CiAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICBpZiAocy5wZW5kaW5nID09PSBzLnBlbmRpbmdfYnVmX3NpemUpIHsKICAgICAgICAgICAgICAgIGlmIChzLmd6aGVhZC5oY3JjICYmIHMucGVuZGluZyA+IGJlZykgewogICAgICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gY3JjMzIoc3RybS5hZGxlciwgcy5wZW5kaW5nX2J1Ziwgcy5wZW5kaW5nIC0gYmVnLCBiZWcpOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgZmx1c2hfcGVuZGluZyhzdHJtKTsKICAgICAgICAgICAgICAgIGJlZyA9IHMucGVuZGluZzsKICAgICAgICAgICAgICAgIGlmIChzLnBlbmRpbmcgPT09IHMucGVuZGluZ19idWZfc2l6ZSkgewogICAgICAgICAgICAgICAgICB2YWwgPSAxOwogICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgaWYgKHMuZ3ppbmRleCA8IHMuZ3poZWFkLmNvbW1lbnQubGVuZ3RoKSB7CiAgICAgICAgICAgICAgICB2YWwgPSBzLmd6aGVhZC5jb21tZW50LmNoYXJDb2RlQXQocy5nemluZGV4KyspICYgMjU1OwogICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICB2YWwgPSAwOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBwdXRfYnl0ZShzLCB2YWwpOwogICAgICAgICAgICB9IHdoaWxlICh2YWwgIT09IDApOwogICAgICAgICAgICBpZiAocy5nemhlYWQuaGNyYyAmJiBzLnBlbmRpbmcgPiBiZWcpIHsKICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gY3JjMzIoc3RybS5hZGxlciwgcy5wZW5kaW5nX2J1Ziwgcy5wZW5kaW5nIC0gYmVnLCBiZWcpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmICh2YWwgPT09IDApIHsKICAgICAgICAgICAgICBzLnN0YXR1cyA9IEhDUkNfU1RBVEU7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHMuc3RhdHVzID0gSENSQ19TVEFURTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKHMuc3RhdHVzID09PSBIQ1JDX1NUQVRFKSB7CiAgICAgICAgICBpZiAocy5nemhlYWQuaGNyYykgewogICAgICAgICAgICBpZiAocy5wZW5kaW5nICsgMiA+IHMucGVuZGluZ19idWZfc2l6ZSkgewogICAgICAgICAgICAgIGZsdXNoX3BlbmRpbmcoc3RybSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHMucGVuZGluZyArIDIgPD0gcy5wZW5kaW5nX2J1Zl9zaXplKSB7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgc3RybS5hZGxlciAmIDI1NSk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgc3RybS5hZGxlciA+PiA4ICYgMjU1KTsKICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gMDsKICAgICAgICAgICAgICBzLnN0YXR1cyA9IEJVU1lfU1RBVEU7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHMuc3RhdHVzID0gQlVTWV9TVEFURTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKHMucGVuZGluZyAhPT0gMCkgewogICAgICAgICAgZmx1c2hfcGVuZGluZyhzdHJtKTsKICAgICAgICAgIGlmIChzdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICBzLmxhc3RfZmx1c2ggPSAtMTsKICAgICAgICAgICAgcmV0dXJuIFpfT0s7CiAgICAgICAgICB9CiAgICAgICAgfSBlbHNlIGlmIChzdHJtLmF2YWlsX2luID09PSAwICYmIHJhbmsoZmx1c2gpIDw9IHJhbmsob2xkX2ZsdXNoKSAmJiBmbHVzaCAhPT0gWl9GSU5JU0gpIHsKICAgICAgICAgIHJldHVybiBlcnIoc3RybSwgWl9CVUZfRVJST1IpOwogICAgICAgIH0KICAgICAgICBpZiAocy5zdGF0dXMgPT09IEZJTklTSF9TVEFURSAmJiBzdHJtLmF2YWlsX2luICE9PSAwKSB7CiAgICAgICAgICByZXR1cm4gZXJyKHN0cm0sIFpfQlVGX0VSUk9SKTsKICAgICAgICB9CiAgICAgICAgaWYgKHN0cm0uYXZhaWxfaW4gIT09IDAgfHwgcy5sb29rYWhlYWQgIT09IDAgfHwgZmx1c2ggIT09IFpfTk9fRkxVU0ggJiYgcy5zdGF0dXMgIT09IEZJTklTSF9TVEFURSkgewogICAgICAgICAgdmFyIGJzdGF0ZSA9IHMuc3RyYXRlZ3kgPT09IFpfSFVGRk1BTl9PTkxZID8gZGVmbGF0ZV9odWZmKHMsIGZsdXNoKSA6IHMuc3RyYXRlZ3kgPT09IFpfUkxFID8gZGVmbGF0ZV9ybGUocywgZmx1c2gpIDogY29uZmlndXJhdGlvbl90YWJsZVtzLmxldmVsXS5mdW5jKHMsIGZsdXNoKTsKICAgICAgICAgIGlmIChic3RhdGUgPT09IEJTX0ZJTklTSF9TVEFSVEVEIHx8IGJzdGF0ZSA9PT0gQlNfRklOSVNIX0RPTkUpIHsKICAgICAgICAgICAgcy5zdGF0dXMgPSBGSU5JU0hfU1RBVEU7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoYnN0YXRlID09PSBCU19ORUVEX01PUkUgfHwgYnN0YXRlID09PSBCU19GSU5JU0hfU1RBUlRFRCkgewogICAgICAgICAgICBpZiAoc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgICBzLmxhc3RfZmx1c2ggPSAtMTsKICAgICAgICAgICAgfQogICAgICAgICAgICByZXR1cm4gWl9PSzsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChic3RhdGUgPT09IEJTX0JMT0NLX0RPTkUpIHsKICAgICAgICAgICAgaWYgKGZsdXNoID09PSBaX1BBUlRJQUxfRkxVU0gpIHsKICAgICAgICAgICAgICB0cmVlcy5fdHJfYWxpZ24ocyk7CiAgICAgICAgICAgIH0gZWxzZSBpZiAoZmx1c2ggIT09IFpfQkxPQ0spIHsKICAgICAgICAgICAgICB0cmVlcy5fdHJfc3RvcmVkX2Jsb2NrKHMsIDAsIDAsIGZhbHNlKTsKICAgICAgICAgICAgICBpZiAoZmx1c2ggPT09IFpfRlVMTF9GTFVTSCkgewogICAgICAgICAgICAgICAgemVybyhzLmhlYWQpOwogICAgICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkID09PSAwKSB7CiAgICAgICAgICAgICAgICAgIHMuc3Ryc3RhcnQgPSAwOwogICAgICAgICAgICAgICAgICBzLmJsb2NrX3N0YXJ0ID0gMDsKICAgICAgICAgICAgICAgICAgcy5pbnNlcnQgPSAwOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBmbHVzaF9wZW5kaW5nKHN0cm0pOwogICAgICAgICAgICBpZiAoc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgICBzLmxhc3RfZmx1c2ggPSAtMTsKICAgICAgICAgICAgICByZXR1cm4gWl9PSzsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAoZmx1c2ggIT09IFpfRklOSVNIKSB7CiAgICAgICAgICByZXR1cm4gWl9PSzsKICAgICAgICB9CiAgICAgICAgaWYgKHMud3JhcCA8PSAwKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRU5EOwogICAgICAgIH0KICAgICAgICBpZiAocy53cmFwID09PSAyKSB7CiAgICAgICAgICBwdXRfYnl0ZShzLCBzdHJtLmFkbGVyICYgMjU1KTsKICAgICAgICAgIHB1dF9ieXRlKHMsIHN0cm0uYWRsZXIgPj4gOCAmIDI1NSk7CiAgICAgICAgICBwdXRfYnl0ZShzLCBzdHJtLmFkbGVyID4+IDE2ICYgMjU1KTsKICAgICAgICAgIHB1dF9ieXRlKHMsIHN0cm0uYWRsZXIgPj4gMjQgJiAyNTUpOwogICAgICAgICAgcHV0X2J5dGUocywgc3RybS50b3RhbF9pbiAmIDI1NSk7CiAgICAgICAgICBwdXRfYnl0ZShzLCBzdHJtLnRvdGFsX2luID4+IDggJiAyNTUpOwogICAgICAgICAgcHV0X2J5dGUocywgc3RybS50b3RhbF9pbiA+PiAxNiAmIDI1NSk7CiAgICAgICAgICBwdXRfYnl0ZShzLCBzdHJtLnRvdGFsX2luID4+IDI0ICYgMjU1KTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgcHV0U2hvcnRNU0Iocywgc3RybS5hZGxlciA+Pj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AgICAgdmFyIHM7CiAgICAgICAgdmFyIHN0ciwgbjsKICAgICAgICB2YXIgd3JhcDsKICAgICAgICB2YXIgYXZhaWw7CiAgICAgICAgdmFyIG5leHQ7CiAgICAgICAgdmFyIGlucHV0OwogICAgICAgIHZhciB0bXBEaWN0OwogICAgICAgIGlmICghc3RybSB8fCAhc3RybS5zdGF0ZSkgewogICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VSUk9SOwogICAgICAgIH0KICAgICAgICBzID0gc3RybS5zdGF0ZTsKICAgICAgICB3cmFwID0gcy53cmFwOwogICAgICAgIGlmICh3cmFwID09PSAyIHx8IHdyYXAgPT09IDEgJiYgcy5zdGF0dXMgIT09IElOSVRfU1RBVEUgfHwgcy5sb29rYWhlYWQpIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgaWYgKHdyYXAgPT09IDEpIHsKICAgICAgICAgIHN0cm0uYWRsZXIgPSBhZGxlcjMyKHN0cm0uYWRsZXIsIGRpY3Rpb25hcnksIGRpY3RMZW5ndGgsIDApOwogICAgICAgIH0KICAgICAgICBzLndyYXAgPSAwOwogICAgICAgIGlmIChkaWN0TGVuZ3RoID49IHMud19zaXplKSB7CiAgICAgICAgICBpZiAod3JhcCA9PT0gMCkgewogICAgICAgICAgICB6ZXJvKHMuaGVhZCk7CiAgICAgICAgICAgIHMuc3Ryc3RhcnQgPSAwOwogICAgICAgICAgICBzLmJsb2NrX3N0YXJ0ID0gMDsKICAgICAgICAgICAgcy5pbnNlcnQgPSAwOwogICAgICAgICAgfQogICAgICAgICAgdG1wRGljdCA9IG5ldyB1dGlscy5CdWY4KHMud19zaXplKTsKICAgICAgICAgIHV0aWxzLmFycmF5U2V0KHRtcERpY3QsIGRpY3Rpb25hcnksIGRpY3RMZW5ndGggLSBzLndfc2l6ZSwgcy53X3NpemUsIDApOwogICAgICAgICAgZGljdGlvbmFyeSA9IHRtcERpY3Q7CiAgICAgICAgICBkaWN0TGVuZ3RoID0gcy53X3NpemU7CiAgICAgICAgfQogICAgICAgIGF2YWlsID0gc3RybS5hdmFpbF9pbjsKICAgICAgICBuZXh0ID0gc3RybS5uZXh0X2luOwogICAgICAgIGlucHV0ID0gc3RybS5pbnB1dDsKICAgICAgICBzdHJtLmF2YWlsX2luID0gZGljdExlbmd0aDsKICAgICAgICBzdHJtLm5leHRfaW4gPSAwOwogICAgICAgIHN0cm0uaW5wdXQgPSBkaWN0aW9uYXJ5OwogICAgICAgIGZpbGxfd2luZG93KHMpOwogICAgICAgIHdoaWxlIChzLmxvb2thaGVhZCA+PSBNSU5fTUFUQ0gpIHsKICAgICAgICAgIHN0ciA9IHMuc3Ryc3RhcnQ7CiAgICAgICAgICBuID0gcy5sb29rYWhlYWQgLSAoTUlOX01BVENIIC0gMSk7CiAgICAgICAgICBkbyB7CiAgICAgICAgICAgIHMuaW5zX2ggPSAocy5pbnNfaCA8PCBzLmhhc2hfc2hpZnQgXiBzLndpbmRvd1tzdHIgKyBNSU5fTUFUQ0ggLSAxXSkgJiBzLmhhc2hfbWFzazsKICAgICAgICAgICAgcy5wcmV2W3N0ciAmIHMud19tYXNrXSA9IHMuaGVhZFtzLmluc19oXTsKICAgICAgICAgICAgcy5oZWFkW3MuaW5zX2hdID0gc3RyOwogICAgICAgICAgICBzdHIrKzsKICAgICAgICAgIH0gd2hpbGUgKC0tbik7CiAgICAgICAgICBzLnN0cnN0YXJ0ID0gc3RyOwogICAgICAgICAgcy5sb29rYWhlYWQgPSBNSU5fTUFUQ0ggLSAxOwogICAgICAgICAgZmlsbF93aW5kb3cocyk7CiAgICAgICAgfQogICAgICAgIHMuc3Ryc3RhcnQgKz0gcy5sb29rYWhlYWQ7CiAgICAgICAgcy5ibG9ja19zdGFydCA9IHMuc3Ryc3RhcnQ7CiAgICAgICAgcy5pbnNlcnQgPSBzLmxvb2thaGVhZDsKICAgICAgICBzLmxvb2thaGVhZCA9IDA7CiAgICAgICAgcy5tYXRjaF9sZW5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gICAgICAgYyA9IHN0ci5jaGFyQ29kZUF0KG1fcG9zKTsKICAgICAgICAgIGlmICgoYyAmIDY0NTEyKSA9PT0gNTUyOTYgJiYgbV9wb3MgKyAxIDwgc3RyX2xlbikgewogICAgICAgICAgICBjMiA9IHN0ci5jaGFyQ29kZUF0KG1fcG9zICsgMSk7CiAgICAgICAgICAgIGlmICgoYzIgJiA2NDUxMikgPT09IDU2MzIwKSB7CiAgICAgICAgICAgICAgYyA9IDY1NTM2ICsgKGMgLSA1NTI5NiA8PCAxMCkgKyAoYzIgLSA1NjMyMCk7CiAgICAgICAgICAgICAgbV9wb3MrKzsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgYnVmX2xlbiArPSBjIDwgMTI4ID8gMSA6IGMgPCAyMDQ4ID8gMiA6IGMgPCA2NTUzNiA/IDMgOiA0OwogICAgICAgIH0KICAgICAgICBidWYgPSBuZXcgdXRpbHMuQnVmOChidWZfbGVuKTsKICAgICAgICBmb3IgKGkgPSAwLCBtX3BvcyA9IDA7IGkgPCBidWZfbGVuOyBtX3BvcysrKSB7CiAgICAgICAgICBjID0gc3RyLmNoYXJDb2RlQXQobV9wb3MpOwogICAgICAgICAgaWYgKChjICYgNjQ1MTIpID09PSA1NTI5NiAmJiBtX3BvcyArIDEgPCBzdHJfbGVuKSB7CiAgICAgICAgICAgIGMyID0gc3RyLmNoYXJDb2RlQXQobV9wb3MgKyAxKTsKICAgICAgICAgICAgaWYgKChjMiAmIDY0NTEyKSA9PT0gNTYzMjApIHsKICAgICAgICAgICAgICBjID0gNjU1MzYgKyAoYyAtIDU1Mjk2IDw8IDEwKSArIChjMiAtIDU2MzIwKTsKICAgICAgICAgICAgICBtX3BvcysrOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoYyA8IDEyOCkgewogICAgICAgICAgICBidWZbaSsrXSA9IGM7CiAgICAgICAgICB9IGVsc2UgaWYgKGMgPCAyMDQ4KSB7CiAgICAgICAgICAgIGJ1ZltpKytdID0gMTkyIHwgYyA+Pj4gNjsKICAgICAgICAgICAgYnVmW2krK10gPSAxMjggfCBjICYgNjM7CiAgICAgICAgICB9IGVsc2UgaWYgKGMgPCA2NTUzNikgewogICAgICAgICAgICBidWZbaSsrXSA9IDIyNCB8IGMgPj4+IDEyOwogICAgICAgICAgICBidWZbaSsrXSA9IDEyOCB8IGMgPj4+IDYgJiA2MzsKICAgICAgICAgICAgYnVmW2krK10gPSAxMjggfCBjICYgNjM7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBidWZbaSsrXSA9IDI0MCB8IGMgPj4+IDE4OwogICAgICAgICAgICBidWZbaSsrXSA9IDEyOCB8IGMgPj4+IDEyICYgNjM7CiAgICAgICAgICAgIGJ1ZltpKytdID0gMTI4IHwgYyA+Pj4gNiAmIDYzOwogICAgICAgICAgICBidWZbaSsrXSA9IDEyOCB8IGMgJiA2MzsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIGJ1ZjsKICAgICAgfTsKICAgICAgZnVuY3Rpb24gYnVmMmJpbnN0cmluZyhidWYsIGxlbikgewogICAgICAgIGlmIChsZW4gPCA2NTUzNCkgewogICAgICAgICAgaWYgKGJ1Zi5zdWJhcnJheSAmJiBTVFJfQVBQTFlfVUlBX09LIHx8ICFidWYuc3ViYXJyYXkgJiYgU1RSX0FQUExZX09LKSB7CiAgICAgICAgICAgIHJldHVybiBTdHJpbmcuZnJvbUNoYXJDb2RlLmFwcGx5KG51bGwsIHV0aWxzLnNocmlua0J1ZihidWYsIGxlbikpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICB2YXIgcmVzdWx0ID0gIiI7CiAgICAgICAgZm9yICh2YXIgaSA9IDA7IGkgPCBsZW47IGkrKykgewogICAgICAgICAgcmVzdWx0ICs9IFN0cmluZy5mcm9tQ2hhckNvZGUoYnVmW2ldKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHJlc3VsdDsKICAgICAgfQogICAgICBleHBvcnRzMi5idWYyYmluc3RyaW5nID0gZnVuY3Rpb24oYnVmKSB7CiAgICAgICAgcmV0dXJuIGJ1ZjJiaW5zdHJpbmcoYnVmLCBidWYubGVuZ3RoKTsKICAgICAgfTsKICAgICAgZXhwb3J0czIuYmluc3RyaW5nMmJ1ZiA9IGZ1bmN0aW9uKHN0cikgewogICAgICAgIHZhciBidWYgPSBuZXcgdXRpbHMuQnVmOChzdHIubGVuZ3RoKTsKICAgICAgICBmb3IgKHZhciBpID0gMCwgbGVuID0gYnVmLmxlbmd0aDsgaSA8IGxlbjsgaSsrKSB7CiAgICAgICAgICBidWZbaV0gPSBzdHIuY2hhckNvZGVBdChpKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIGJ1ZjsKICAgICAgfTsKICAgICAgZXhwb3J0czIuYnVmMnN0cmluZyA9IGZ1bmN0aW9uKGJ1ZiwgbWF4KSB7CiAgICAgICAgdmFyIGksIG91dCwgYywgY19sZW47CiAgICAgICAgdmFyIGxlbiA9IG1heCB8fCBidWYubGVuZ3RoOwogICAgICAgIHZhciB1dGYxNmJ1ZiA9IG5ldyBBcnJheShsZW4gKiAyKTsKICAgICAgICBmb3IgKG91dCA9IDAsIGkgPSAwOyBpIDwgbGVuOyApIHsKICAgICAgICAgIGMgPSBidWZbaSsrXTsKICAgICAgICAgIGlmIChjIDwgMTI4KSB7CiAgICAgICAgICAgIHV0ZjE2YnVmW291dCsrXSA9IGM7CiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgfQogICAgICAgICAgY19sZW4gPSBfdXRmOGxlbltjXTsKICAgICAgICAgIGlmIChjX2xlbiA+IDQpIHsKICAgICAgICAgICAgdXRmMTZidWZbb3V0KytdID0gNjU1MzM7CiAgICAgICAgICAgIGkgKz0gY19sZW4gLSAxOwogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgIH0KICAgICAgICAgIGMgJj0gY19sZW4gPT09IDIgPyAzMSA6IGNfbGVuID09PSAzID8gMTUgOiA3OwogICAgICAgICAgd2hpbGUgKGNfbGVuID4gMSAmJiBpIDwgbGVuKSB7CiAgICAgICAgICAgIGMgPSBjIDw8IDYgfCBidWZbaSsrXSAmIDYzOwogICAgICAgICAgICBjX2xlbi0tOwogICAgICAgICAgfQogICAgICAgICAgaWYgKGNfbGVuID4gMSkgewogICAgICAgICAgICB1dGYxNmJ1ZltvdXQrK10gPSA2NTUzMzsKICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoYyA8IDY1NTM2KSB7CiAgICAgICAgICAgIHV0ZjE2YnVmW291dCsrXSA9IGM7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBjIC09IDY1NTM2OwogICAgICAgICAgICB1dGYxNmJ1ZltvdXQrK10gPSA1NTI5NiB8IGMgPj4gMTAgJiAxMDIzOwogICAgICAgICAgICB1dGYxNmJ1ZltvdXQrK10gPSA1NjMyMCB8IGMgJiAxMDIzOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gYnVmMmJpbnN0cmluZyh1dGYxNmJ1Ziwgb3V0KTsKICAgICAgfTsKICAgICAgZXhwb3J0czIudXRmOGJvcmRlciA9IGZ1bmN0aW9uKGJ1ZiwgbWF4KSB7CiAgICAgICAgdmFyIHBvczsKICAgICAgICBtYXggPSBtYXggfHwgYnVmLmxlbmd0aDsKICAgICAgICBpZiAobWF4ID4gYnVmLmxlbmd0aCkgewogICAgICAgICAgbWF4ID0gYnVmLmxlbmd0aDsKICAgICAgICB9CiAgICAgICAgcG9zID0gbWF4IC0gMTsKICAgICAgICB3aGlsZSAocG9zID49IDAgJiYgKGJ1Zltwb3NdICYgMTkyKSA9PT0gMTI4KSB7CiAgICAgICAgICBwb3MtLTsKICAgICAgICB9CiAgICAgICAgaWYgKHBvcyA8IDApIHsKICAgICAgICAgIHJldHVybiBtYXg7CiAgICAgICAgfQogICAgICAgIGlmIChwb3MgPT09IDApIHsKICAgICAgICAgIHJldHVybiBtYXg7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hlYWRlcik7CiAgICAgICAgfQogICAgICAgIGlmIChvcHQuZGljdGlvbmFyeSkgewogICAgICAgICAgdmFyIGRpY3Q7CiAgICAgICAgICBpZiAodHlwZW9mIG9wdC5kaWN0aW9uYXJ5ID09PSAic3RyaW5nIikgewogICAgICAgICAgICBkaWN0ID0gc3RyaW5ncy5zdHJpbmcyYnVmKG9wdC5kaWN0aW9uYXJ5KTsKICAgICAgICAgIH0gZWxzZSBpZiAodG9TdHJpbmcuY2FsbChvcHQuZGljdGlvbmFyeSkgPT09ICJbb2JqZWN0IEFycmF5QnVmZmVyXSIpIHsKICAgICAgICAgICAgZGljdCA9IG5ldyBVaW50OEFycmF5KG9wdC5kaWN0aW9uYXJ5KTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGRpY3QgPSBvcHQuZGljdGlvbmFyeTsKICAgICAgICAgIH0KICAgICAgICAgIHN0YXR1cyA9IHpsaWJfZGVmbGF0ZS5kZWZsYXRlU2V0RGljdGlvbmFyeSh0aGlzLnN0cm0sIGRpY3QpOwogICAgICAgICAgaWYgKHN0YXR1cyAhPT0gWl9PSykgewogICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IobXNnW3N0YXR1c10pOwogICAgICAgICAgfQogICAgICAgICAgdGhpcy5fZGljdF9zZXQgPSB0cnVlOwogICAgICAgIH0KICAgICAgfQogICAgICBEZWZsYXRlLnByb3RvdHlwZS5wdXNoID0gZnVuY3Rpb24oZGF0YSwgbW9kZSkgewogICAgICAgIHZhciBzdHJtID0gdGhpcy5zdHJtOwogICAgICAgIHZhciBjaHVua1NpemUgPSB0aGlzLm9wdGlvbnMuY2h1bmtTaXplOwogICAgICAgIHZhciBzdGF0dXMsIF9tb2RlOwogICAgICAgIGlmICh0aGlzLmVuZGVkKSB7CiAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgfQogICAgICAgIF9tb2RlID0gbW9kZSA9PT0gfn5tb2RlID8gbW9kZSA6IG1vZGUgPT09IHRydWUgPyBaX0ZJTklTSCA6IFpfTk9fRkxVU0g7CiAgICAgICAgaWYgKHR5cGVvZiBkYXRhID09PSAic3RyaW5nIikgewogICAgICAgICAgc3RybS5pbnB1dCA9IHN0cmluZ3Muc3RyaW5nMmJ1ZihkYXRhKTsKICAgICAgICB9IGVsc2UgaWYgKHRvU3RyaW5nLmNhbGwoZGF0YSkgPT09ICJbb2JqZWN0IEFycmF5QnVmZmVyXSIpIHsKICAgICAgICAgIHN0cm0uaW5wdXQgPSBuZXcgVWludDhBcnJheShkYXRhKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgc3RybS5pbnB1dCA9IGRhdGE7CiAgICAgICAgfQogICAgICAgIHN0cm0ubmV4dF9pbiA9IDA7CiAgICAgICAgc3RybS5hdmFpbF9pbiA9IHN0cm0uaW5wdXQubGVuZ3RoOwogICAgICAgIGRvIHsKICAgICAgICAgIGlmIChzdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICBzdHJtLm91dHB1dCA9IG5ldyB1dGlscy5CdWY4KGNodW5rU2l6ZSk7CiAgICAgICAgICAgIHN0cm0ubmV4dF9vdXQgPSAwOwogICAgICAgICAgICBzdHJtLmF2YWlsX291dCA9IGNodW5rU2l6ZTsKICAgICAgICAgIH0KICAgICAgICAgIHN0YXR1cyA9IHpsaWJfZGVmbGF0ZS5kZWZsYXRlKHN0cm0sIF9tb2RlKTsKICAgICAgICAgIGlmIChzdGF0dXMgIT09IFpfU1RSRUFNX0VORCAmJiBzdGF0dXMgIT09IFpfT0spIHsKICAgICAgICAgICAgdGhpcy5vbkVuZChzdGF0dXMpOwogICAgICAgICAgICB0aGlzLmVuZGVkID0gdHJ1ZTsKICAgICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICAgICAgfQogICAgICAgICAgaWYgKHN0cm0uYXZhaWxfb3V0ID09PSAwIHx8IHN0cm0uYXZhaWxfaW4gPT09IDAgJiYgKF9tb2RlID09PSBaX0ZJTklTSCB8fCBfbW9kZSA9PT0gWl9TWU5DX0ZMVVNIMikpIHsKICAgICAgICAgICAgaWYgKHRoaXMub3B0aW9ucy50byA9PT0gInN0cmluZyIpIHsKICAgICAgICAgICAgICB0aGlzLm9uRGF0YShzdHJpbmdzLmJ1ZjJiaW5zdHJpbmcodXRpbHMuc2hyaW5rQnVmKHN0cm0ub3V0cHV0LCBzdHJtLm5leHRfb3V0KSkpOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHRoaXMub25EYXRhKHV0aWxzLnNocmlua0J1ZihzdHJtLm91dHB1dCwgc3RybS5uZXh0X291dCkpOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfSB3aGlsZSAoKHN0cm0uYXZhaWxfaW4gPiAwIHx8IHN0cm0uYXZhaWxfb3V0ID09PSAwKSAmJiBzdGF0dXMgIT09IFpfU1RSRUFNX0VORCk7CiAgICAgICAgaWYgKF9tb2RlID09PSBaX0ZJTklTSCkgewogICAgICAgICAgc3RhdHVzID0gemxpYl9kZWZsYXRlLmRlZmxhdGVFbmQodGhpcy5zdHJtKTsKICAgICAgICAgIHRoaXMub25FbmQoc3RhdHVzKTsKICAgICAgICAgIHRoaXMuZW5kZWQgPSB0cnVlOwogICAgICAgICAgcmV0dXJuIHN0YXR1cyA9PT0gWl9PSzsKICAgICAgICB9CiAgICAgICAgaWYgKF9tb2RlID09PSBaX1NZTkNfRkxVU0gyKSB7CiAgICAgICAgICB0aGlzLm9uRW5kKFpfT0spOwogICAgICAgICAgc3RybS5hdmFpbF9vdXQgPSAwOwogICAgICAgICAgcmV0dXJuIHRydWU7CiAgICAgICAgfQogICAgICAgIHJldHVybiB0cnVlOwogICAgICB9OwogICAgICBEZWZsYXRlLnByb3RvdHlwZS5vbkRhdGEgPSBmdW5jdGlvbihjaHVuaykgewogICAgICAgIHRoaXMuY2h1bmtzLnB1c2goY2h1bmspOwogICAgICB9OwogICAgICBEZWZsYXRlLnByb3RvdHlwZS5vbkVuZCA9IGZ1bmN0aW9uKHN0YXR1cykgewogICAgICAgIGlmIChzdGF0dXMgPT09IFpfT0spIHsKICAgICAgICAgIGlmICh0aGlzLm9wdGlvbnMudG8gPT09ICJzdHJpbmciKSB7CiAgICAgICAgICAgIHRoaXMucmVzdWx0ID0gdGhpcy5jaHVua3Muam9pbigiIik7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICB0aGlzLnJlc3VsdCA9IHV0aWxzLmZsYXR0ZW5DaHVua3ModGhpcy5jaHVua3MpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICB0aGlzLmNodW5rcyA9IFtdOwogICAgICAgIHRoaXMuZXJyID0gc3RhdHVzOwogICAgICAgIHRoaXMubXNnID0gdGhpcy5zdHJtLm1zZzsKICAgICAgfTsKICAgICAgZnVuY3Rpb24gZGVmbGF0ZShpbnB1dCwgb3B0aW9ucykgewogICAgICAgIHZhciBkZWZsYXRvciA9IG5ldyBEZWZsYXRlKG9wdGlvbnMpOwogICAgICAgIGRlZmxhdG9yLnB1c2goaW5wdXQsIHRydWUpOwogICAgICAgIGlmIChkZWZsYXRvci5lcnIpIHsKICAgICAgICAgIHRocm93IGRlZmxhdG9yLm1zZyB8fCBtc2dbZGVmbGF0b3IuZXJyXTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIGRlZmxhdG9yLnJlc3VsdDsKICAgICAgfQogICAgICBmdW5jdGlvbiBkZWZsYXRlUmF3KGlucHV0LCBvcHRpb25zKSB7CiAgICAgICAgb3B0aW9ucyA9IG9wdGlvbnMgfHwge307CiAgICAgICAgb3B0aW9ucy5yYXcgPSB0cnVlOwogICAgICAgIHJldHVybiBkZWZsYXRlKGlucHV0LCBvcHRpb25zKTsKICAgICAgfQogICAgICBmdW5jdGlvbiBnemlwKGlucHV0LCBvcHRpb25zKSB7CiAgICAgICAgb3B0aW9ucyA9IG9wdGlvbnMgfHwge307CiAgICAgICAgb3B0aW9ucy5nemlwID0gdHJ1ZTsKICAgICAgICByZXR1cm4gZGVmbGF0ZShp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sKICAgICAgICB2YXIgaGVyZTsKICAgICAgICB2YXIgb3A7CiAgICAgICAgdmFyIGxlbjsKICAgICAgICB2YXIgZGlzdDsKICAgICAgICB2YXIgZnJvbTsKICAgICAgICB2YXIgZnJvbV9zb3VyY2U7CiAgICAgICAgdmFyIGlucHV0LCBvdXRwdXQ7CiAgICAgICAgc3RhdGUgPSBzdHJtLnN0YXRlOwogICAgICAgIF9pbiA9IHN0cm0ubmV4dF9pbjsKICAgICAgICBpbnB1dCA9IHN0cm0uaW5wdXQ7CiAgICAgICAgbGFzdCA9IF9pbiArIChzdHJtLmF2YWlsX2luIC0gNSk7CiAgICAgICAgX291dCA9IHN0cm0ubmV4dF9vdXQ7CiAgICAgICAgb3V0cHV0ID0gc3RybS5vdXRwdXQ7CiAgICAgICAgYmVnID0gX291dCAtIChzdGFydCAtIHN0cm0uYXZhaWxfb3V0KTsKICAgICAgICBlbmQgPSBfb3V0ICsgKHN0cm0uYXZhaWxfb3V0IC0gMjU3KTsKICAgICAgICBkbWF4ID0gc3RhdGUuZG1heDsKICAgICAgICB3c2l6ZSA9IHN0YXRlLndzaXplOwogICAgICAgIHdoYXZlID0gc3RhdGUud2hhdmU7CiAgICAgICAgd25leHQgPSBzdGF0ZS53bmV4dDsKICAgICAgICBzX3dpbmRvdyA9IHN0YXRlLndpbmRvdzsKICAgICAgICBob2xkID0gc3RhdGUuaG9sZDsKICAgICAgICBiaXRzID0gc3RhdGUuYml0czsKICAgICAgICBsY29kZSA9IHN0YXRlLmxlbmNvZGU7CiAgICAgICAgZGNvZGUgPSBzdGF0ZS5kaXN0Y29kZTsKICAgICAgICBsbWFzayA9ICgxIDw8IHN0YXRlLmxlbmJpdHMpIC0gMTsKICAgICAgICBkbWFzayA9ICgxIDw8IHN0YXRlLmRpc3RiaXRzKSAtIDE7CiAgICAgICAgdG9wOgogICAgICAgICAgZG8gewogICAgICAgICAgICBpZiAoYml0cyA8IDE1KSB7CiAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtfaW4rK10gPDwgYml0czsKICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtfaW4rK10gPDwgYml0czsKICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaGVyZSA9IGxjb2RlW2hvbGQgJiBsbWFza107CiAgICAgICAgICAgIGRvbGVuOgogICAgICAgICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgICAgICAgb3AgPSBoZXJlID4+PiAyNDsKICAgICAgICAgICAgICAgIGhvbGQgPj4+PSBvcDsKICAgICAgICAgICAgICAgIGJpdHMgLT0gb3A7CiAgICAgICAgICAgICAgICBvcCA9IGhlcmUgPj4+IDE2ICYgMjU1OwogICAgICAgICAgICAgICAgaWYgKG9wID09PSAwKSB7CiAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gaGVyZSAmIDY1NTM1OwogICAgICAgICAgICAgICAgfSBlbHNlIGlmIChvcCAmIDE2KSB7CiAgICAgICAgICAgICAgICAgIGxlbiA9IGhlcmUgJiA2NTUzNTsKICAgICAgICAgICAgICAgICAgb3AgJj0gMTU7CiAgICAgICAgICAgICAgICAgIGlmIChvcCkgewogICAgICAgICAgICAgICAgICAgIGlmIChiaXRzIDwgb3ApIHsKICAgICAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbX2luKytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGxlbiArPSBob2xkICYgKDEgPDwgb3ApIC0gMTsKICAgICAgICAgICAgICAgICAgICBob2xkID4+Pj0gb3A7CiAgICAgICAgICAgICAgICAgICAgYml0cyAtPSBvcDsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBpZiAoYml0cyA8IDE1KSB7CiAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtfaW4rK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtfaW4rK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaGVyZSA9IGRjb2RlW2hvbGQgJiBkbWFza107CiAgICAgICAgICAgICAgICAgIGRvZGlzdDoKICAgICAgICAgICAgICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgICAgICAgICAgICAgIG9wID0gaGVyZSA+Pj4gMjQ7CiAgICAgICAgICAgICAgICAgICAgICBob2xkID4+Pj0gb3A7CiAgICAgICAgICAgICAgICAgICAgICBiaXRzIC09IG9wOwogICAgICAgICAgICAgICAgICAgICAgb3AgPSBoZXJlID4+PiAxNiAmIDI1NTsKICAgICAgICAgICAgICAgICAgICAgIGlmIChvcCAmIDE2KSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGRpc3QgPSBoZXJlICYgNjU1MzU7CiAgICAgICAgICAgICAgICAgICAgICAgIG9wICY9IDE1OwogICAgICAgICAgICAgICAgICAgICAgICBpZiAoYml0cyA8IG9wKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtfaW4rK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGJpdHMgPCBvcCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtfaW4rK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgZGlzdCArPSBob2xkICYgKDEgPDwgb3ApIC0gMTsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGRpc3QgPiBkbWF4KSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW52YWxpZCBkaXN0YW5jZSB0b28gZmFyIGJhY2siOwogICAgICAgICAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWsgdG9wOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIGhvbGQgPj4+PSBvcDsKICAgICAgICAgICAgICAgICAgICAgICAgYml0cyAtPSBvcDsKICAgICAgICAgICAgICAgICAgICAgICAgb3AgPSBfb3V0IC0gYmVnOwogICAgICAgICAgICAgICAgICAgICAgICBpZiAoZGlzdCA+IG9wKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgb3AgPSBkaXN0IC0gb3A7CiAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKG9wID4gd2hhdmUpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5zYW5lKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImludmFsaWQgZGlzdGFuY2UgdG9vIGZhciBiYWNrIjsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWsgdG9wOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tID0gMDsKICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tX3NvdXJjZSA9IHNfd2luZG93OwogICAgICAgICAgICAgICAgICAgICAgICAgIGlmICh3bmV4dCA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgZnJvbSArPSB3c2l6ZSAtIG9wOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKG9wIDwgbGVuKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxlbiAtPSBvcDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gc193aW5kb3dbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSB3aGlsZSAoLS1vcCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZyb20gPSBfb3V0IC0gZGlzdDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZnJvbV9zb3VyY2UgPSBvdXRwdXQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIGlmICh3bmV4dCA8IG9wKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tICs9IHdzaXplICsgd25leHQgLSBvcDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIG9wIC09IHduZXh0OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKG9wIDwgbGVuKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxlbiAtPSBvcDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gc193aW5kb3dbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSB3aGlsZSAoLS1vcCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZyb20gPSAwOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAod25leHQgPCBsZW4pIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBvcCA9IHduZXh0OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxlbiAtPSBvcDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IHNfd2luZG93W2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSB3aGlsZSAoLS1vcCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZnJvbSA9IF9vdXQgLSBkaXN0OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZyb21fc291cmNlID0gb3V0cHV0OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZyb20gKz0gd25leHQgLSBvcDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChvcCA8IGxlbikgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBsZW4gLT0gb3A7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IHNfd2luZG93W2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gd2hpbGUgKC0tb3ApOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tID0gX291dCAtIGRpc3Q7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZyb21fc291cmNlID0gb3V0cHV0OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICB3aGlsZSAobGVuID4gMikgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBmcm9tX3NvdXJjZVtmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBmcm9tX3NvdXJjZVtmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBmcm9tX3NvdXJjZVtmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgbGVuIC09IDM7CiAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChsZW4pIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gZnJvbV9zb3VyY2VbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChsZW4gPiAxKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gZnJvbV9zb3VyY2VbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgZnJvbSA9IF9vdXQgLSBkaXN0OwogICAgICAgICAgICAgICAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gb3V0cHV0W2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IG91dHB1dFtmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBvdXRwdXRbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxlbiAtPSAzOwogICAgICAgICAgICAgICAgICAgICAgICAgIH0gd2hpbGUgKGxlbiA+IDIpOwogICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChsZW4pIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gb3V0cHV0W2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAobGVuID4gMSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IG91dHB1dFtmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIGlmICgob3AgJiA2NCkgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgICAgaGVyZSA9IGRjb2RlWyhoZXJlICYgNjU1MzUpICsgKGhvbGQgJiAoMSA8PCBvcCkgLSAxKV07CiAgICAgICAgICAgICAgICAgICAgICAgIGNvbnRpbnVlIGRvZGlzdDsKICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImludmFsaWQgZGlzdGFuY2UgY29kZSI7CiAgICAgICAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrIHRvcDsKICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAoKG9wICYgNjQpID09PSAwKSB7CiAgICAgICAgICAgICAgICAgIGhlcmUgPSBsY29kZVsoaGVyZSAmIDY1NTM1KSArIChob2xkICYgKDEgPDwgb3ApIC0gMSldOwogICAgICAgICAgICAgICAgICBjb250aW51ZSBkb2xlbjsKICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAob3AgJiAzMikgewogICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gVFlQRTsKICAgICAgICAgICAgICAgICAgYnJlYWsgdG9wOwogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW52YWxpZCBsaXRlcmFsL2xlbmd0aCBjb2RlIjsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgYnJlYWsgdG9wOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgfQogICAgICAgICAgfSB3aGlsZSAoX2luIDwgbGFzdCAmJiBfb3V0IDwgZW5kKTsKICAgICAgICBsZW4gPSBiaXRzID4+IDM7CiAgICAgICAgX2luIC09IGxlbjsKICAgICAgICBiaXRzIC09IGxlbiA8PCAzOwogICAgICAgIGhvbGQgJj0gKDEgPDwgYml0cykgLSAxOwogICAgICAgIHN0cm0ubmV4dF9pbiA9IF9pbjsKICAgICAgICBzdHJtLm5leHRfb3V0ID0gX291dDsKICAgICAgICBzdHJtLmF2YWlsX2luID0gX2luIDwgbGFzdCA/IDUgKyAobGFzdCAtIF9pbikgOiA1IC0gKF9pbiAtIGxhc3QpOwogICAgICAgIHN0cm0uYXZhaWxfb3V0ID0gX291dCA8IGVuZCA/IDI1NyArIChlbmQgLSBfb3V0KSA6IDI1NyAtIChfb3V0IC0gZW5kKTsKICAgICAgICBzdGF0ZS5ob2xkID0gaG9sZDsKICAgICAgICBzdGF0ZS5iaXRzID0gYml0czsKICAgICAgICByZXR1cm47CiAgICAgIH07CiAgICB9CiAgfSk7CgogIC8vIG5vZGVfbW9kdWxlcy8ucG5wbS9wYWtvQDEuMC4xMS9ub2RlX21vZHVsZXMvcGFrby9saWIvemxpYi9pbmZ0cmVlcy5qcwogIHZhciByZXF1aXJlX2luZnRyZWVzID0gX19jb21tb25KUyh7CiAgICAibm9kZV9tb2R1bGVzLy5wbnBtL3Bha29AMS4wLjExL25vZGVfbW9kdWxlcy9wYWtvL2xpYi96bGliL2luZnRyZWVzLmpzIihleHBvcnRzMiwgbW9kdWxlMikgewogICAgICBpbml0X2J1ZmZlcl9zaGltKCk7CiAgICAgICJ1c2Ugc3RyaWN0IjsKICAgICAgdmFyIHV0aWxzID0gcmVxdWlyZV9jb21tb24oKTsKICAgICAgdmFyIE1BWEJJVFMgPSAxNTsKICAgICAgdmFyIEVOT1VHSF9MRU5TID0gODUyOwogICAgICB2YXIgRU5PVUdIX0RJU1RTID0gNTkyOwogICAgICB2YXIgQ09ERVMgPSAwOwogICAgICB2YXIgTEVOUyA9IDE7CiAgICAgIHZhciBESVNUUyA9IDI7CiAgICAgIHZhciBsYmFzZSA9IFsKICAgICAgICAzLAogICAgICAgIDQsCiAgICAgICAgNSwKICAgICAgICA2LAogICAgICAgIDcsCiAgICAgICAgOCwKICAgICAgICA5LAogICAgICAgIDEwLAogICAgICAgIDExLAogICAgICAgIDEzLAogICAgICAgIDE1LAogICAgICAgIDE3LAogICAgICAgIDE5LAogICAgICAgIDIzLAogICAgICAgIDI3LAogICAgICAgIDMxLAogICAgICAgIDM1LAogICAgICAgIDQzLAogICAgICAgIDUxLAogICAgICAgIDU5LAogICAgICAgIDY3LAogICAgICAgIDgzLAogICAgICAgIDk5LAogICAgICAgIDExNSwKICAgICAgICAxMzEsCiAgICAgICAgMTYzLAogICAgICAgIDE5NSwKICAgICAgICAyMjcsCiAgICAgICAgMjU4LAogICAgICAgIDAsCiAgICAgICAgMAogICAgICBdOwogICAgICB2YXIgbGV4dCA9IFsKICAgICAgICAxNiwKICAgICAgICAxNiwKICAgICAgICAxNiwKICAgICAgICAxNiwKICAgICAgICAxNiwKICAgICAgICAxNiwKICAgICAgICAxNiwKICAgICAgICAxNiwKICAgICAgICAxNywKICAgICAgICAxNywKICAgICAgICAxNywKICAgICAgICAxNywKICAgICAgICAxOCwKICAgICAgICAxOCwKICAgICAgICAxOCwKICAgICAgICAxOCwKICAgICAgICAxOSwKICAgICAgICAxOSwKICAgICAgICAxOSwKICAgICAgICAxOSwKICAgICAgICAyMCwKICAgICAgICAyMCwKICAgICAgICAyMCwKICAgICAgICAyMCwKICAgICAgICAyMSwKICAgICAgICAyMSwKICAgICAgICAyMSwKICAgICAgICAyMSwKICAgICAgICAxNiwKICAgICAgICA3MiwKICAgICAgICA3OAogICAgICBdOwogICAgICB2YXIgZGJhc2UgPSBbCiAgICAgICAgMSwKICAgICAgICAyLAogICAgICAgIDMsCiAgICAgICAgNCwKICAgICAgICA1LAogICAgICAgIDcsCiAgICAgICAgOSwKICAgICAgICAxMywKICAgICAgICAxNywKICAgICAgICAyNSwKICAgICAgICAzMywKICAgICAgICA0OSwKICAgICAgICA2NSwKICAgICAgICA5NywKICAgICAgICAxMjksCiAgICAgICAgMTkzLAogICAgICAgIDI1NywKICAgICAgICAzODUsCiAgICAgICAgNTEzLAogICAgICAgIDc2OSwKICAgICAgICAxMDI1LAogICAgICAgIDE1MzcsCiAgICAgICAgMjA0OSwKICAgICAgICAzMDczLAogICAgICAgIDQwOTcsCiAgICAgICAgNjE0NSwKICAgICAgICA4MTkzLAogICAgICAgIDEyMjg5LAogICAgICAgIDE2Mzg1LAogICAgICAgIDI0NTc3LAogICAgICAgIDAsCiAgICAgICAgMAogICAgICBdOwogICAgICB2YXIgZGV4dCA9IFsKICAgICAgICAxNiwKICAgICAgICAxNiwKICAgICAgICAxNiwKICAgICAgICAxNiwKICAgICAgICAxNywKICAgICAgICAxNywKICAgICAgICAxOCwKICAgICAgICAxOCwKICAgICAgICAxOSwKICAgICAgICAxOSwKICAgICAgICAyMCwKICAgICAgICAyMCwKICAgICAgICAyMSwKICAgICAgICAyMSwKICAgICAgICAyMiwKICAgICAgICAyMiwKICAgICAgICAyMywKICAgICAgICAyMywKICAgICAgICAyNCwKICAgICAgICAyNCwKICAgICAgICAyNSwKICAgICAgICAyNSwKICAgICAgICAyNiwKICAgICAgICAyNiwKICAgICAgICAyNywKICAgICAgICAyNywKICAgICAgICAyOCwKICAgICAgICAyOCwKICAgICAgICAyOSwKICAgICAgICAyOSwKICAgICAgICA2NCwKICAgICAgICA2NAogICAgICBdOwogICAgICBtb2R1bGUyLmV4cG9ydHMgPSBmdW5jdGlvbiBpbmZsYXRlX3RhYmxlKHR5cGUsIGxlbnMsIGxlbnNfaW5kZXgsIGNvZGVzLCB0YWJsZSwgdGFibGVfaW5kZXgsIHdvcmssIG9wdHMpIHsKICAgICAgICB2YXIgYml0cyA9IG9wdHMuYml0czsKICAgICAgICB2YXIgbGVuID0gMDsKICAgICAgICB2YXIgc3ltID0gMDsKICAgICAgICB2YXIgbWluID0gMCwgbWF4ID0gMDsKICAgICAgICB2YXIgcm9vdDIgPSAwOwogICAgICAgIHZhciBjdXJyID0gMDsKICAgICAgICB2YXIgZHJvcCA9IDA7CiAgICAgICAgdmFyIGxlZnQgPSAwOwogICAgICAgIHZhciB1c2VkID0gMDsKICAgICAgICB2YXIgaHVmZiA9IDA7CiAgICAgICAgdmFyIGluY3I7CiAgICAgICAgdmFyIGZpbGw7CiAgICAgICAgdmFyIGxvdzsKICAgICAgICB2YXIgbWFzazsKICAgICAgICB2YXIgbmV4dDsKICAgICAgICB2YXIgYmFzZSA9IG51bGw7CiAgICAgICAgdmFyIGJhc2VfaW5kZXggPSAwOwogICAgICAgIHZhciBlbmQ7CiAgICAgICAgdmFyIGNvdW50ID0gbmV3IHV0aWxzLkJ1ZjE2KE1BWEJJVFMgKyAxKTsKICAgICAgICB2YXIgb2ZmcyA9IG5ldyB1dGlscy5CdWYxNihNQVhCSVRTICsgMSk7CiAgICAgICAgdmFyIGV4dHJhID0gbnVsbDsKICAgICAgICB2YXIgZXh0cmFfaW5kZXggPSAwOwogICAgICAgIHZhciBoZXJlX2JpdHMsIGhlcmVfb3AsIGhlcmVfdmFsOwogICAgICAgIGZvciAobGVuID0gMDsgbGVuIDw9IE1BWEJJVFM7IGxlbisrKSB7CiAgICAgICAgICBjb3VudFtsZW5dID0gMDsKICAgICAgICB9CiAgICAgICAgZm9yIChzeW0gPSAwOyBzeW0gPCBjb2Rlczsgc3ltKyspIHsKICAgICAgICAgIGNvdW50W2xlbnNbbGVuc19pbmRleCArIHN5bV1dKys7CiAgICAgICAgfQogICAgICAgIHJvb3QyID0gYml0czsKICAgICAgICBmb3IgKG1heCA9IE1BWEJJVFM7IG1heCA+PSAxOyBtYXgtLSkgewogICAgICAgICAgaWYgKGNvdW50W21heF0gIT09IDApIHsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChyb290MiA+IG1heCkgewogICAgICAgICAgcm9vdDIgPSBtYXg7CiAgICAgICAgfQogICAgICAgIGlmIChtYXggPT09IDApIHsKICAgICAgICAgIHRhYmxlW3RhYmxlX2luZGV4KytdID0gMSA8PCAyNCB8IDY0IDw8IDE2IHwgMDsKICAgICAgICAgIHRhYmxlW3RhYmxlX2luZGV4KytdID0gMSA8PCAyNCB8IDY0IDw8IDE2IHwgMDsKICAgICAgICAgIG9wdHMuYml0cyA9IDE7CiAgICAgICAgICByZXR1cm4gMDsKICAgICAgICB9CiAgICAgICAgZm9yIChtaW4gPSAxOyBtaW4gPCBtYXg7IG1pbisrKSB7CiAgICAgICAgICBpZiAoY291bnRbbWluXSAhPT0gMCkgewogICAgICAgICAgICBicmVhazsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKHJvb3QyIDwgbWluKSB7CiAgICAgICAgICByb290MiA9IG1pbjsKICAgICAgICB9CiAgICAgICAgbGVmdCA9IDE7CiAgICAgICAgZm9yIChsZW4gPSAxOyBsZW4gPD0gTUFYQklUUzsgbGVuKyspIHsKICAgICAgICAgIGxlZnQgPDw9IDE7CiAgICAgICAgICBsZWZ0IC09IGNvdW50W2xlbl07CiAgICAgICAgICBpZiAobGVmdCA8IDApIHsKICAgICAgICAgICAgcmV0dXJuIC0xOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAobGVmdCA+IDAgJiYgKHR5cGUgPT09IENPREVTIHx8IG1heCAhPT0gMSkpIHsKICAgICAgICAgIHJldHVybiAtMTsKICAgICAgICB9CiAgICAgICAgb2Zmc1sxXSA9IDA7CiAgICAgICAgZm9yIChsZW4gPSAxOyBsZW4gPCBNQVhCSVRTOyBsZW4rKykgewogICAgICAgICAgb2Zmc1tsZW4gKyAxXSA9IG9mZnNbbGVuXSArIGNvdW50W2xlbl07CiAgICAgICAgfQogICAgICAgIGZvciAoc3ltID0gMDsgc3ltIDwgY29kZXM7IHN5bSsrKSB7CiAgICAgICAgICBpZiAobGVuc1tsZW5zX2luZGV4ICsgc3ltXSAhPT0gMCkgewogICAgICAgICAgICB3b3JrW29mZnNbbGVuc1tsZW5zX2luZGV4ICsgc3ltXV0rK10gPSBzeW07CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmICh0eXBlID09PSBDT0RFUykgewogICAgICAgICAgYmFzZSA9IGV4dHJhID0gd29yazsKICAgICAgICAgIGVuZCA9IDE5OwogICAgICAgIH0gZWxzZSBpZiAodHlwZSA9PT0gTEVOUykgewogICAgICAgICAgYmFzZSA9IGxiYXNlOwogICAgICAgICAgYmFzZV9pbmRleCAtPSAyNTc7CiAgICAgICAgICBleHRyYSA9IGxleHQ7CiAgICAgICAgICBleHRyYV9pbmRleCAtPSAyNTc7CiAgICAgICAgICBlbmQgPSAyNTY7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIGJhc2UgPSBkYmFzZTsKICAgICAgICAgIGV4dHJhID0gZGV4dDsKICAgICAgICAgIGVuZCA9IC0xOwogICAgICAgIH0KICAgICAgICBodWZmID0gMDsKICAgICAgICBzeW0gPSAwOwogICAgICAgIGxlbiA9IG1pbjsKICAgICAgICBuZXh0ID0gdGFibGVfaW5kZXg7CiAgICAgICAgY3VyciA9IHJvb3QyOwogICAgICAgIGRyb3AgPSAwOwogICAgICAgIGxvdyA9IC0xOwogICAgICAgIHVzZWQgPSAxIDw8IHJvb3QyOwogICAgICAgIG1hc2sgPSB1c2VkIC0gMTsKICAgICAgICBpZiAodHlwZSA9PT0gTEVOUyAmJiB1c2VkID4gRU5PVUdIX0xFTlMgfHwgdHlwZSA9PT0gRElTVFMgJiYgdXNlZCA+IEVOT1VHSF9ESVNUUykgewogICAgICAgICAgcmV0dXJuIDE7CiAgICAgICAgfQogICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgaGVyZV9iaXRzID0gbGVuIC0gZHJvcDsKICAgICAgICAgIGlmICh3b3JrW3N5bV0gPCBlbmQpIHsKICAgICAgICAgICAgaGVyZV9vcCA9IDA7CiAgICAgICAgICAgIGhlcmVfdmFsID0gd29ya1tzeW1dOwogICAgICAgICAgfSBlbHNlIGlmICh3b3JrW3N5bV0gPiBlbmQpIHsKICAgICAgICAgICAgaGVyZV9vcCA9IGV4dHJhW2V4dHJhX2luZGV4ICsgd29ya1tzeW1dXTsKICAgICAgICAgICAgaGVyZV92YWwgPSBiYXNlW2Jhc2VfaW5kZXggKyB3b3JrW3N5bV1dOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgaGVyZV9vcCA9IDMyICsgNjQ7CiAgICAgICAgICAgIGhlcmVfdmFsID0gMDsKICAgICAgICAgIH0KICAgICAgICAgIGluY3IgPSAxIDw8IGxlbiAtIGRyb3A7CiAgICAgICAgICBmaWxsID0gMSA8PCBjdXJyOwogICAgICAgICAgbWluID0gZmlsbDsKICAgICAgICAgIGRvIHsKICAgICAgICAgICAgZmlsbCAtPSBpbmNyOwogICAgICAgICAgICB0YWJsZVtuZXh0ICsgKGh1ZmYgPj4gZHJvcCkgKyBmaWxsXSA9IGhlcmVfYml0cyA8PCAyNCB8IGhlcmVfb3AgPDwgMTYgfCBoZXJlX3ZhbCB8IDA7CiAgICAgICAgICB9IHdoaWxlIChmaWxsICE9PSAwKTsKICAgICAgICAgIGluY3IgPSAxIDw8IGxlbiAtIDE7CiAgICAgICAgICB3aGlsZSAoaHVmZiAmIGluY3IpIHsKICAgICAgICAgICAgaW5jciA+Pj0gMTsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChpbmNyICE9PSAwKSB7CiAgICAgICAgICAgIGh1ZmYgJj0gaW5jciAtIDE7CiAgICAgICAgICAgIGh1ZmYgKz0gaW5jcjsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGh1ZmYgPSAwOwogICAgICAgICAgfQogICAgICAgICAgc3ltKys7CiAgICAgICAgICBpZiAoLS1jb3VudFtsZW5dID09PSAwKSB7CiAgICAgICAgICAgIGlmIChsZW4gPT09IG1heCkgewogICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGxlbiA9IGxlbnNbbGVuc19pbmRleCArIHdvcmtbc3ltXV07CiAgICAgICAgICB9CiAgICAgICAgICBpZiAobGVuID4gcm9vdDIgJiYgKGh1ZmYgJiBtYXNrKSAhPT0gbG93KSB7CiAgICAgICAgICAgIGlmIChkcm9wID09PSAwKSB7CiAgICAgICAgICAgICAgZHJvcCA9IHJvb3QyOwogICAgICAgICAgICB9CiAgICAgICAgICAgIG5leHQgKz0gbWluOwogICAgICAgICAgICBjdXJyID0gbGVuIC0gZHJvcDsKICAgICAgICAgICAgbGVmdCA9IDEgPDwgY3VycjsKICAgICAgICAgICAgd2hpbGUgKGN1cnIgKyBkcm9wIDwgbWF4KSB7CiAgICAgICAgICAgICAgbGVmdCAtPSBjb3VudFtjdXJyICsgZHJvcF07CiAgICAgICAgICAgICAgaWYgKGxlZnQgPD0gMCkgewogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGN1cnIrKzsKICAgICAgICAgICAgICBsZWZ0IDw8PSAxOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHVzZWQgKz0gMSA8PCBjdXJyOwogICAgICAgICAgICBpZiAodHlwZSA9PT0gTEVOUyAmJiB1c2VkID4gRU5PVUdIX0xFTlMgfHwgdHlwZSA9PT0gRElTVFMgJiYgdXNlZCA+IEVOT1VHSF9ESVNUUykgewogICAgICAgICAgICAgIHJldHVybiAxOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGxvdyA9IGh1ZmYgJiBtYXNrOwogICAgICAgICAgICB0YWJsZVtsb3ddID0gcm9vdDIgPDwgMjQgfCBjdXJyIDw8IDE2IHwgbmV4dCAtIHRhYmxlX2luZGV4IHwgMDsKICAgICAgICAgIH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RUFNX0VSUk9SID0gLTI7CiAgICAgIHZhciBaX0RBVEFfRVJST1IgPSAtMzsKICAgICAgdmFyIFpfTUVNX0VSUk9SID0gLTQ7CiAgICAgIHZhciBaX0JVRl9FUlJPUiA9IC01OwogICAgICB2YXIgWl9ERUZMQVRFRCA9IDg7CiAgICAgIHZhciBIRUFEID0gMTsKICAgICAgdmFyIEZMQUdTID0gMjsKICAgICAgdmFyIFRJTUUgPSAzOwogICAgICB2YXIgT1MgPSA0OwogICAgICB2YXIgRVhMRU4gPSA1OwogICAgICB2YXIgRVhUUkEgPSA2OwogICAgICB2YXIgTkFNRSA9IDc7CiAgICAgIHZhciBDT01NRU5UID0gODsKICAgICAgdmFyIEhDUkMgPSA5OwogICAgICB2YXIgRElDVElEID0gMTA7CiAgICAgIHZhciBESUNUID0gMTE7CiAgICAgIHZhciBUWVBFID0gMTI7CiAgICAgIHZhciBUWVBFRE8gPSAxMzsKICAgICAgdmFyIFNUT1JFRCA9IDE0OwogICAgICB2YXIgQ09QWV8gPSAxNTsKICAgICAgdmFyIENPUFkgPSAxNjsKICAgICAgdmFyIFRBQkxFID0gMTc7CiAgICAgIHZhciBMRU5MRU5TID0gMTg7CiAgICAgIHZhciBDT0RFTEVOUyA9IDE5OwogICAgICB2YXIgTEVOXyA9IDIwOwogICAgICB2YXIgTEVOID0gMjE7CiAgICAgIHZhciBMRU5FWFQgPSAyMjsKICAgICAgdmFyIERJU1QgPSAyMzsKICAgICAgdmFyIERJU1RFWFQgPSAyNDsKICAgICAgdmFyIE1BVENIID0gMjU7CiAgICAgIHZhciBMSVQgPSAyNjsKICAgICAgdmFyIENIRUNLID0gMjc7CiAgICAgIHZhciBMRU5HVEggPSAyODsKICAgICAgdmFyIERPTkUgPSAyOTsKICAgICAgdmFyIEJBRCA9IDMwOwogICAgICB2YXIgTUVNID0gMzE7CiAgICAgIHZhciBTWU5DID0gMzI7CiAgICAgIHZhciBFTk9VR0hfTEVOUyA9IDg1MjsKICAgICAgdmFyIEVOT1VHSF9ESVNUUyA9IDU5MjsKICAgICAgdmFyIE1BWF9XQklUUyA9IDE1OwogICAgICB2YXIgREVGX1dCSVRTID0gTUFYX1dCSVRTOwogICAgICBmdW5jdGlvbiB6c3dhcDMyKHEpIHsKICAgICAgICByZXR1cm4gKHEgPj4+IDI0ICYgMjU1KSArIChxID4+PiA4ICYgNjUyODApICsgKChxICYgNjUyODApIDw8IDgpICsgKChxICYgMjU1KSA8PCAyNCk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gSW5mbGF0ZVN0YXRlKCkgewogICAgICAgIHRoaXMubW9kZSA9IDA7CiAgICAgICAgdGhpcy5sYXN0ID0gZmFsc2U7CiAgICAgICAgdGhpcy53cmFwID0gMDsKICAgICAgICB0aGlzLmhhdmVkaWN0ID0gZmFsc2U7CiAgICAgICAgdGhpcy5mbGFncyA9IDA7CiAgICAgICAgdGhpcy5kbWF4ID0gMDsKICAgICAgICB0aGlzLmNoZWNrID0gMDsKICAgICAgICB0aGlzLnRvdGFsID0gMDsKICAgICAgICB0aGlzLmhlYWQgPSBudWxsOwogICAgICAgIHRoaXMud2JpdHMgPSAwOwogICAgICAgIHRoaXMud3NpemUgPSAwOwogICAgICAgIHRoaXMud2hhdmUgPSAwOwogICAgICAgIHRoaXMud25leHQgPSAwOwogICAgICAgIHRoaXMud2luZG93ID0gbnVsbDsKICAgICAgICB0aGlzLmhvbGQgPSAwOwogICAgICAgIHRoaXMuYml0cyA9IDA7CiAgICAgICAgdGhpcy5sZW5ndGggPSAwOwogICAgICAgIHRoaXMub2Zmc2V0ID0gMDsKICAgICAgICB0aGlzLmV4dHJhID0gMDsKICAgICAgICB0aGlzLmxlbmNvZGUgPSBudWxsOwogICAgICAgIHRoaXMuZGlzdGNvZGUgPSBudWxsOwogICAgICAgIHRoaXMubGVuYml0cyA9IDA7CiAgICAgICAgdGhpcy5kaXN0Yml0cyA9IDA7CiAgICAgICAgdGhpcy5uY29kZSA9IDA7CiAgICAgICAgdGhpcy5ubGVuID0gMDsKICAgICAgICB0aGlzLm5kaXN0ID0gMDsKICAgICAgICB0aGlzLmhhdmUgPSAwOwogICAgICAgIHRoaXMubmV4dCA9IG51bGw7CiAgICAgICAgdGhpcy5sZW5zID0gbmV3IHV0aWxzLkJ1ZjE2KDMyMCk7CiAgICAgICAgdGhpcy53b3JrID0gbmV3IHV0aWxzLkJ1ZjE2KDI4OCk7CiAgICAgICAgdGhpcy5sZW5keW4gPSBudWxsOwogICAgICAgIHRoaXMuZGlzdGR5biA9IG51bGw7CiAgICAgICAgdGhpcy5zYW5lID0gMDsKICAgICAgICB0aGlzLmJhY2sgPSAwOwogICAgICAgIHRoaXMud2FzID0gMDsKICAgICAgfQogICAgICBmdW5jdGlvbiBpbmZsYXRlUmVzZXRLZWVwKHN0cm0pIHsKICAgICAgICB2YXIgc3RhdGU7CiAgICAgICAgaWYgKCFzdHJtIHx8ICFzdHJtLnN0YXRlKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIHN0YXRlID0gc3RybS5zdGF0ZTsKICAgICAgICBzdHJtLnRvdGFsX2luID0gc3RybS50b3RhbF9vdXQgPSBzdGF0ZS50b3RhbCA9IDA7CiAgICAgICAgc3RybS5tc2cgPSAiIjsKICAgICAgICBpZiAoc3RhdGUud3JhcCkgewogICAgICAgICAgc3RybS5hZGxlciA9IHN0YXRlLndyYXAgJiAxOwogICAgICAgIH0KICAgICAgICBzdGF0ZS5tb2RlID0gSEVBRDsKICAgICAgICBzdGF0ZS5sYXN0ID0gMDsKICAgICAgICBzdGF0ZS5oYXZlZGljdCA9IDA7CiAgICAgICAgc3RhdGUuZG1heCA9IDMyNzY4OwogICAgICAgIHN0YXRlLmhlYWQgPSBudWxsOwogICAgICAgIHN0YXRlLmhvbGQgPSAwOwogICAgICAgIHN0YXRlLmJpdHMgPSAwOwogICAgICAgIHN0YXRlLmxlbmNvZGUgPSBzdGF0ZS5sZW5keW4gPSBuZXcgdXRpbHMuQnVmMzIoRU5PVUdIX0xFTlMpOwogICAgICAgIHN0YXRlLmRpc3Rjb2RlID0gc3RhdGUuZGlzdGR5biA9IG5ldyB1dGlscy5CdWYzMihFTk9VR0hfRElTVFMpOwogICAgICAgIHN0YXRlLnNhbmUgPSAxOwogICAgICAgIHN0YXRlLmJhY2sgPSAtMTsKICAgICAgICByZXR1cm4gWl9PSzsKICAgICAgfQogICAgICBmdW5jdGlvbiBpbmZsYXRlUmVzZXQoc3RybSkgewogICAgICAgIHZhciBzdGF0ZTsKICAgICAgICBpZiAoIXN0cm0gfHwgIXN0cm0uc3RhdGUpIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgc3RhdGUgPSBzdHJtLnN0YXRlOwogICAgICAgIHN0YXRlLndzaXplID0gMDsKICAgICAgICBzdGF0ZS53aGF2ZSA9IDA7CiAgICAgICAgc3RhdGUud25leHQgPSAwOwogICAgICAgIHJldHVybiBpbmZsYXRlUmVzZXRLZWVwKHN0cm0pOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGluZmxhdGVSZXNldDIoc3RybSwgd2luZG93Qml0cykgewogICAgICAgIHZhciB3cmFwOwogICAgICAgIHZhciBzdGF0ZTsKICAgICAgICBpZiAoIXN0cm0gfHwgIXN0cm0uc3RhdGUpIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgc3RhdGUgPSBzdHJtLnN0YXRlOwogICAgICAgIGlmICh3aW5kb3dCaXRzIDwgMCkgewogICAgICAgICAgd3JhcCA9IDA7CiAgICAgICAgICB3aW5kb3dCaXRzID0gLXdpbmRvd0JpdHM7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIHdyYXAgPSAod2luZG93Qml0cyA+PiA0KSArIDE7CiAgICAgICAgICBpZiAod2luZG93Qml0cyA8IDQ4KSB7CiAgICAgICAgICAgIHdpbmRvd0JpdHMgJj0gMTU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmICh3aW5kb3dCaXRzICYmICh3aW5kb3dCaXRzIDwgOCB8fCB3aW5kb3dCaXRzID4gMTUpKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIGlmIChzdGF0ZS53aW5kb3cgIT09IG51bGwgJiYgc3RhdGUud2JpdHMgIT09IHdpbmRvd0JpdHMpIHsKICAgICAgICAgIHN0YXRlLndpbmRvdyA9IG51bGw7CiAgICAgICAgfQogICAgICAgIHN0YXRlLndyYXAgPSB3cmFwOwogICAgICAgIHN0YXRlLndiaXRzID0gd2luZG93Qml0czsKICAgICAgICByZXR1cm4gaW5mbGF0ZVJlc2V0KHN0cm0pOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGluZmxhdGVJbml0MihzdHJtLCB3aW5kb3dCaXRzKSB7CiAgICAgICAgdmFyIHJldDsKICAgICAgICB2YXIgc3RhdGU7CiAgICAgICAgaWYgKCFzdHJtKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIHN0YXRlID0gbmV3IEluZmxhdGVTdGF0ZSgpOwogICAgICAgIHN0cm0uc3RhdGUgPSBzdGF0ZTsKICAgICAgICBzdGF0ZS53aW5kb3cgPSBudWxsOwogICAgICAgIHJldCA9IGluZmxhdGVSZXNldDIoc3RybSwgd2luZG93Qml0cyk7CiAgICAgICAgaWYgKHJldCAhPT0gWl9PSykgewogICAgICAgICAgc3RybS5zdGF0ZSA9IG51bGw7CiAgICAgICAgfQogICAgICAgIHJldHVybiByZXQ7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gaW5mbGF0ZUluaXQoc3RybSkgewogICAgICAgIHJldHVybiBpbmZsYXRlSW5pdDIoc3RybSwgREVGX1dCSVRTKTsKICAgICAgfQogICAgICB2YXIgdmlyZ2luID0gdHJ1ZTsKICAgICAgdmFyIGxlbmZpeDsKICAgICAgdmFyIGRpc3RmaXg7CiAgICAgIGZ1bmN0aW9uIGZpeGVkdGFibGVzKHN0YXRlKSB7CiAgICAgICAgaWYgKHZpcmdpbikgewogICAgICAgICAgdmFyIHN5bTsKICAgICAgICAgIGxlbmZpeCA9IG5ldyB1dGlscy5CdWYzMig1MTIpOwogICAgICAgICAgZGlzdGZpeCA9IG5ldyB1dGlscy5CdWYzMigzMik7CiAgICAgICAgICBzeW0gPSAwOwogICAgICAgICAgd2hpbGUgKHN5bSA8IDE0NCkgewogICAgICAgICAgICBzdGF0ZS5sZW5zW3N5bSsrXSA9IDg7CiAgICAgICAgICB9CiAgICAgICAgICB3aGlsZSAoc3ltIDwgMjU2KSB7CiAgICAgICAgICAgIHN0YXRlLmxlbnNbc3ltKytdID0gOTsKICAgICAgICAgIH0KICAgICAgICAgIHdoaWxlIChzeW0gPCAyODApIHsKICAgICAgICAgICAgc3RhdGUubGVuc1tzeW0rK10gPSA3OwogICAgICAgICAgfQogICAgICAgICAgd2hpbGUgKHN5bSA8IDI4OCkgewogICAgICAgICAgICBzdGF0ZS5sZW5zW3N5bSsrXSA9IDg7CiAgICAgICAgICB9CiAgICAgICAgICBpbmZsYXRlX3RhYmxlKExFTlMsIHN0YXRlLmxlbnMsIDAsIDI4OCwgbGVuZml4LCAwLCBzdGF0ZS53b3JrLCB7IGJpdHM6IDkgfSk7CiAgICAgICAgICBzeW0gPSAwOwogICAgICAgICAgd2hpbGUgKHN5bSA8IDMyKSB7CiAgICAgICAgICAgIHN0YXRlLmxlbnNbc3ltKytdID0gNTsKICAgICAgICAgIH0KICAgICAgICAgIGluZmxhdGVfdGFibGUoRElTVFMsIHN0YXRlLmxlbnMsIDAsIDMyLCBkaXN0Zml4LCAwLCBzdGF0ZS53b3JrLCB7IGJpdHM6IDUgfSk7CiAgICAgICAgICB2aXJnaW4gPSBmYWxzZTsKICAgICAgICB9CiAgICAgICAgc3RhdGUubGVuY29kZSA9IGxlbmZpeDsKICAgICAgICBzdGF0ZS5sZW5iaXRzID0gOTsKICAgICAgICBzdGF0ZS5kaXN0Y29kZSA9IGRpc3RmaXg7CiAgICAgICAgc3RhdGUuZGlzdGJpdHMgPSA1OwogICAgICB9CiAgICAgIGZ1bmN0aW9uIHVwZGF0ZXdpbmRvdyhzdHJtLCBzcmMsIGVuZCwgY29weSkgewogICAgICAgIHZhciBkaXN0OwogICAgICAgIHZhciBzdGF0ZSA9IHN0cm0uc3RhdGU7CiAgICAgICAgaWYgKHN0YXRlLndpbmRvdyA9PT0gbnVsbCkgewogICAgICAgICAgc3RhdGUud3NpemUgPSAxIDw8IHN0YXRlLndiaXRzOwogICAgICAgICAgc3RhdGUud25leHQgPSAwOwogICAgICAgICAgc3RhdGUud2hhdmUgPSAwOwogICAgICAgICAgc3RhdGUud2luZG93ID0gbmV3IHV0aWxzLkJ1Zjgoc3RhdGUud3NpemUpOwogICAgICAgIH0KICAgICAgICBpZiAoY29weSA+PSBzdGF0ZS53c2l6ZSkgewogICAgICAgICAgdXRpbHMuYXJyYXlTZXQoc3RhdGUud2luZG93LCBzcmMsIGVuZCAtIHN0YXRlLndzaXplLCBzdGF0ZS53c2l6ZSwgMCk7CiAgICAgICAgICBzdGF0ZS53bmV4dCA9IDA7CiAgICAgICAgICBzdGF0ZS53aGF2ZSA9IHN0YXRlLndzaXplOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBkaXN0ID0gc3RhdGUud3NpemUgLSBzdGF0ZS53bmV4dDsKICAgICAgICAgIGlmIChkaXN0ID4gY29weSkgewogICAgICAgICAgICBkaXN0ID0gY29weTsKICAgICAgICAgIH0KICAgICAgICAgIHV0aWxzLmFycmF5U2V0KHN0YXRlLndpbmRvdywgc3JjLCBlbmQgLSBjb3B5LCBkaXN0LCBzdGF0ZS53bmV4dCk7CiAgICAgICAgICBjb3B5IC09IGRpc3Q7CiAgICAgICAgICBpZiAoY29weSkgewogICAgICAgICAgICB1dGlscy5hcnJheVNldChzdGF0ZS53aW5kb3csIHNyYywgZW5kIC0gY29weSwgY29weSwgMCk7CiAgICAgICAgICAgIHN0YXRlLnduZXh0ID0gY29weTsKICAgICAgICAgICAgc3RhdGUud2hhdmUgPSBzdGF0ZS53c2l6ZTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHN0YXRlLnduZXh0ICs9IGRpc3Q7CiAgICAgICAgICAgIGlmIChzdGF0ZS53bmV4dCA9PT0gc3RhdGUud3NpemUpIHsKICAgICAgICAgICAgICBzdGF0ZS53bmV4dCA9IDA7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHN0YXRlLndoYXZlIDwgc3RhdGUud3NpemUpIHsKICAgICAgICAgICAgICBzdGF0ZS53aGF2ZSArPSBkaXN0OwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiAwOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGluZmxhdGUoc3RybSwgZmx1c2gpIHsKICAgICAgICB2YXIgc3RhdGU7CiAgICAgICAgdmFyIGlucHV0LCBvdXRwdXQ7CiAgICAgICAgdmFyIG5leHQ7CiAgICAgICAgdmFyIHB1dDsKICAgICAgICB2YXIgaGF2ZSwgbGVmdDsKICAgICAgICB2YXIgaG9sZDsKICAgICAgICB2YXIgYml0czsKICAgICAgICB2YXIgX2luLCBfb3V0OwogICAgICAgIHZhciBjb3B5OwogICAgICAgIHZhciBmcm9tOwogICAgICAgIHZhciBmcm9tX3NvdXJjZTsKICAgICAgICB2YXIgaGVyZSA9IDA7CiAgICAgICAgdmFyIGhlcmVfYml0cywgaGVyZV9vcCwgaGVyZV92YWw7CiAgICAgICAgdmFyIGxhc3RfYml0cywgbGFzdF9vcCwgbGFzdF92YWw7CiAgICAgICAgdmFyIGxlbjsKICAgICAgICB2YXIgcmV0OwogICAgICAgIHZhciBoYnVmID0gbmV3IHV0aWxzLkJ1ZjgoNCk7CiAgICAgICAgdmFyIG9wdHM7CiAgICAgICAgdmFyIG47CiAgICAgICAgdmFyIG9yZGVyID0gWzE2LCAxNywgMTgsIDAsIDgsIDcsIDksIDYsIDEwLCA1LCAxMSwgNCwgMTIsIDMsIDEzLCAyLCAxNCwgMSwgMTVdOwogICAgICAgIGlmICghc3RybSB8fCAhc3RybS5zdGF0ZSB8fCAhc3RybS5vdXRwdXQgfHwgIXN0cm0uaW5wdXQgJiYgc3RybS5hdmFpbF9pbiAhPT0gMCkgewogICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VSUk9SOwogICAgICAgIH0KICAgICAgICBzdGF0ZSA9IHN0cm0uc3RhdGU7CiAgICAgICAgaWYgKHN0YXRlLm1vZGUgPT09IFRZUEUpIHsKICAgICAgICAgIHN0YXRlLm1vZGUgPSBUWVBFRE87CiAgICAgICAgfQogICAgICAgIHB1dCA9IHN0cm0ubmV4dF9vdXQ7CiAgICAgICAgb3V0cHV0ID0gc3RybS5vdXRwdXQ7CiAgICAgICAgbGVmdCA9IHN0cm0uYXZhaWxfb3V0OwogICAgICAgIG5leHQgPSBzdHJtLm5leHRfaW47CiAgICAgICAgaW5wdXQgPSBzdHJtLmlucHV0OwogICAgICAgIGhhdmUgPSBzdHJtLmF2YWlsX2luOwogICAgICAgIGhvbGQgPSBzdGF0ZS5ob2xkOwogICAgICAgIGJpdHMgPSBzdGF0ZS5iaXRzOwogICAgICAgIF9pbiA9IGhhdmU7CiAgICAgICAgX291dCA9IGxlZnQ7CiAgICAgICAgcmV0ID0gWl9PSzsKICAgICAgICBpbmZfbGVhdmU6CiAgICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgICAgc3dpdGNoIChzdGF0ZS5tb2RlKSB7CiAgICAgICAgICAgICAgY2FzZSBIRUFEOgogICAgICAgICAgICAgICAgaWYgKHN0YXRlLndyYXAgPT09IDApIHsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IFRZUEVETzsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB3aGlsZSAoYml0cyA8IDE2KSB7CiAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmIChzdGF0ZS53cmFwICYgMiAmJiBob2xkID09PSAzNTYxNSkgewogICAgICAgICAgICAgICAgICBzdGF0ZS5jaGVjayA9IDA7CiAgICAgICAgICAgICAgICAgIGhidWZbMF0gPSBob2xkICYgMjU1OwogICAgICAgICAgICAgICAgICBoYnVmWzFdID0gaG9sZCA+Pj4gOCAmIDI1NTsKICAgICAgICAgICAgICAgICAgc3RhdGUuY2hlY2sgPSBjcmMzMihzdGF0ZS5jaGVjaywgaGJ1ZiwgMiwgMCk7CiAgICAgICAgICAgICAgICAgIGhvbGQgPSAwOwogICAgICAgICAgICAgICAgICBiaXRzID0gMDsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEZMQUdTOwogICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0YXRlLmZsYWdzID0gMDsKICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5oZWFkKSB7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmhlYWQuZG9uZSA9IGZhbHNlOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKCEoc3RhdGUud3JhcCAmIDEpIHx8ICgoKGhvbGQgJiAyNTUpIDw8IDgpICsgKGhvbGQgPj4gOCkpICUgMzEpIHsKICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW5jb3JyZWN0IGhlYWRlciBjaGVjayI7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKChob2xkICYgMTUpICE9PSBaX0RFRkxBVEVEKSB7CiAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gInVua25vd24gY29tcHJlc3Npb24gbWV0aG9kIjsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBob2xkID4+Pj0gNDsKICAgICAgICAgICAgICAgIGJpdHMgLT0gNDsKICAgICAgICAgICAgICAgIGxlbiA9IChob2xkICYgMTUpICsgODsKICAgICAgICAgICAgICAgIGlmIChzdGF0ZS53Yml0cyA9PT0gMCkgewogICAgICAgICAgICAgICAgICBzdGF0ZS53Yml0cyA9IGxlbjsKICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAobGVuID4gc3RhdGUud2JpdHMpIHsKICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW52YWxpZCB3aW5kb3cgc2l6ZSI7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUuZG1heCA9IDEgPDwgbGVuOwogICAgICAgICAgICAgICAgc3RybS5hZGxlciA9IHN0YXRlLmNoZWNrID0gMTsKICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBob2xkICYgNTEyID8gRElDVElEIDogVFlQRTsKICAgICAgICAgICAgICAgIGhvbGQgPSAwOwogICAgICAgICAgICAgICAgYml0cyA9IDA7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICBjYXNlIEZMQUdTOgogICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCAxNikgewogICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5mbGFncyA9IGhvbGQ7CiAgICAgICAgICAgICAgICBpZiAoKHN0YXRlLmZsYWdzICYgMjU1KSAhPT0gWl9ERUZMQVRFRCkgewogICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJ1bmtub3duIGNvbXByZXNzaW9uIG1ldGhvZCI7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmZsYWdzICYgNTczNDQpIHsKICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAidW5rbm93biBoZWFkZXIgZmxhZ3Mgc2V0IjsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuaGVhZCkgewogICAgICAgICAgICAgICAgICBzdGF0ZS5oZWFkLnRleHQgPSBob2xkID4+IDggJiAxOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmZsYWdzICYgNTEyKSB7CiAgICAgICAgICAgICAgICAgIGhidWZbMF0gPSBob2xkICYgMjU1OwogICAgICAgICAgICAgICAgICBoYnVmWzFdID0gaG9sZCA+Pj4gOCAmIDI1NTsKICAgICAgICAgICAgICAgICAgc3RhdGUuY2hlY2sgPSBjcmMzMihzdGF0ZS5jaGVjaywgaGJ1ZiwgMiwgMCk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBob2xkID0gMDsKICAgICAgICAgICAgICAgIGJpdHMgPSAwOwogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IFRJTUU7CiAgICAgICAgICAgICAgY2FzZSBUSU1FOgogICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCAzMikgewogICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuaGVhZCkgewogICAgICAgICAgICAgICAgICBzdGF0ZS5oZWFkLnRpbWUgPSBob2xkOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmZsYWdzICYgNTEyKSB7CiAgICAgICAgICAgICAgICAgIGhidWZbMF0gPSBob2xkICYgMjU1OwogICAgICAgICAgICAgICAgICBoYnVmWzFdID0gaG9sZCA+Pj4gOCAmIDI1NTsKICAgICAgICAgICAgICAgICAgaGJ1ZlsyXSA9IGhvbGQgPj4+IDE2ICYgMjU1OwogICAgICAgICAgICAgICAgICBoYnVmWzNdID0gaG9sZCA+Pj4gMjQgJiAyNTU7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmNoZWNrID0gY3JjMzIoc3RhdGUuY2hlY2ssIGhidWYsIDQsIDApOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaG9sZCA9IDA7CiAgICAgICAgICAgICAgICBiaXRzID0gMDsKICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBPUzsKICAgICAgICAgICAgICBjYXNlIE9TOgogICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCAxNikgewogICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuaGVhZCkgewogICAgICAgICAgICAgICAgICBzdGF0ZS5oZWFkLnhmbGFncyA9IGhvbGQgJiAyNTU7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmhlYWQub3MgPSBob2xkID4+IDg7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuZmxhZ3MgJiA1MTIpIHsKICAgICAgICAgICAgICAgICAgaGJ1ZlswXSA9IGhvbGQgJiAyNTU7CiAgICAgICAgICAgICAgICAgIGhidWZbMV0gPSBob2xkID4+PiA4ICYgMjU1OwogICAgICAgICAgICAgICAgICBzdGF0ZS5jaGVjayA9IGNyYzMyKHN0YXRlLmNoZWNrLCBoYnVmLCAyLCAwKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGhvbGQgPSAwOwogICAgICAgICAgICAgICAgYml0cyA9IDA7CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gRVhMRU47CiAgICAgICAgICAgICAgY2FzZSBFWExFTjoKICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5mbGFncyAmIDEwMjQpIHsKICAgICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCAxNikgewogICAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgc3RhdGUubGVuZ3RoID0gaG9sZDsKICAgICAgICAgICAgICAgICAgaWYgKHN0YXRlLmhlYWQpIHsKICAgICAgICAgICAgICAgICAgICBzdGF0ZS5oZWFkLmV4dHJhX2xlbiA9IGhvbGQ7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaWYgKHN0YXRlLmZsYWdzICYgNTEyKSB7CiAgICAgICAgICAgICAgICAgICAgaGJ1ZlswXSA9IGhvbGQgJiAyNTU7CiAgICAgICAgICAgICAgICAgICAgaGJ1ZlsxXSA9IGhvbGQgPj4+IDggJiAyNTU7CiAgICAgICAgICAgICAgICAgICAgc3RhdGUuY2hlY2sgPSBjcmMzMihzdGF0ZS5jaGVjaywgaGJ1ZiwgMiwgMCk7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaG9sZCA9IDA7CiAgICAgICAgICAgICAgICAgIGJpdHMgPSAwOwogICAgICAgICAgICAgICAgfSBlbHNlIGlmIChzdGF0ZS5oZWFkKSB7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmhlYWQuZXh0cmEgPSBudWxsOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEVYVFJBOwogICAgICAgICAgICAgIGNhc2UgRVhUUkE6CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuZmxhZ3MgJiAxMDI0KSB7CiAgICAgICAgICAgICAgICAgIGNvcHkgPSBzdGF0ZS5sZW5ndGg7CiAgICAgICAgICAgICAgICAgIGlmIChjb3B5ID4gaGF2ZSkgewogICAgICAgICAgICAgICAgICAgIGNvcHkgPSBoYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChjb3B5KSB7CiAgICAgICAgICAgICAgICAgICAgaWYgKHN0YXRlLmhlYWQpIHsKICAgICAgICAgICAgICAgICAgICAgIGxlbiA9IHN0YXRlLmhlYWQuZXh0cmFfbGVuIC0gc3RhdGUubGVuZ3RoOwogICAgICAgICAgICAgICAgICAgICAgaWYgKCFzdGF0ZS5oZWFkLmV4dHJhKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHN0YXRlLmhlYWQuZXh0cmEgPSBuZXcgQXJyYXkoc3RhdGUuaGVhZC5leHRyYV9sZW4pOwogICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgdXRpbHMuYXJyYXlTZXQoc3RhdGUuaGVhZC5leHRyYSwgaW5wdXQsIG5leHQsIGNvcHksIGxlbik7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5mbGFncyAmIDUxMikgewogICAgICAgICAgICAgICAgICAgICAgc3RhdGUuY2hlY2sgPSBjcmMzMihzdGF0ZS5jaGVjaywgaW5wdXQsIGNvcHksIG5leHQpOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBoYXZlIC09IGNvcHk7CiAgICAgICAgICAgICAgICAgICAgbmV4dCArPSBjb3B5OwogICAgICAgICAgICAgICAgICAgIHN0YXRlLmxlbmd0aCAtPSBjb3B5OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5sZW5ndGgpIHsKICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0YXRlLmxlbmd0aCA9IDA7CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gTkFNRTsKICAgICAgICAgICAgICBjYXNlIE5BTUU6CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuZmxhZ3MgJiAyMDQ4KSB7CiAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGNvcHkgPSAwOwogICAgICAgICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgICAgICAgbGVuID0gaW5wdXRbbmV4dCArIGNvcHkrK107CiAgICAgICAgICAgICAgICAgICAgaWYgKHN0YXRlLmhlYWQgJiYgbGVuICYmIHN0YXRlLmxlbmd0aCA8IDY1NTM2KSB7CiAgICAgICAgICAgICAgICAgICAgICBzdGF0ZS5oZWFkLm5hbWUgKz0gU3RyaW5nLmZyb21DaGFyQ29kZShsZW4pOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgfSB3aGlsZSAobGVuICYmIGNvcHkgPCBoYXZlKTsKICAgICAgICAgICAgICAgICAgaWYgKHN0YXRlLmZsYWdzICYgNTEyKSB7CiAgICAgICAgICAgICAgICAgICAgc3RhdGUuY2hlY2sgPSBjcmMzMihzdGF0ZS5jaGVjaywgaW5wdXQsIGNvcHksIG5leHQpOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGhhdmUgLT0gY29weTsKICAgICAgICAgICAgICAgICAgbmV4dCArPSBjb3B5OwogICAgICAgICAgICAgICAgICBpZiAobGVuKSB7CiAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKHN0YXRlLmhlYWQpIHsKICAgICAgICAgICAgICAgICAgc3RhdGUuaGVhZC5uYW1lID0gbnVsbDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0YXRlLmxlbmd0aCA9IDA7CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQ09NTUVOVDsKICAgICAgICAgICAgICBjYXNlIENPTU1FTlQ6CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuZmxhZ3MgJiA0MDk2KSB7CiAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGNvcHkgPSAwOwogICAgICAgICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgICAgICAgbGVuID0gaW5wdXRbbmV4dCArIGNvcHkrK107CiAgICAgICAgICAgICAgICAgICAgaWYgKHN0YXRlLmhlYWQgJiYgbGVuICYmIHN0YXRlLmxlbmd0aCA8IDY1NTM2KSB7CiAgICAgICAgICAgICAgICAgICAgICBzdGF0ZS5oZWFkLmNvbW1lbnQgKz0gU3RyaW5nLmZyb21DaGFyQ29kZShsZW4pOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgfSB3aGlsZSAobGVuICYmIGNvcHkgPCBoYXZlKTsKICAgICAgICAgICAgICAgICAgaWYgKHN0YXRlLmZsYWdzICYgNTEyKSB7CiAgICAgICAgICAgICAgICAgICAgc3RhdGUuY2hlY2sgPSBjcmMzMihzdGF0ZS5jaGVjaywgaW5wdXQsIGNvcHksIG5leHQpOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGhhdmUgLT0gY29weTsKICAgICAgICAgICAgICAgICAgbmV4dCArPSBjb3B5OwogICAgICAgICAgICAgICAgICBpZiAobGVuKSB7CiAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKHN0YXRlLmhlYWQpIHsKICAgICAgICAgICAgICAgICAgc3RhdGUuaGVhZC5jb21tZW50ID0gbnVsbDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBIQ1JDOwogICAgICAgICAgICAgIGNhc2UgSENSQzoKICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5mbGFncyAmIDUxMikgewogICAgICAgICAgICAgICAgICB3aGlsZSAoYml0cyA8IDE2KSB7CiAgICAgICAgICAgICAgICAgICAgaWYgKGhhdmUgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgaGF2ZS0tOwogICAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBpZiAoaG9sZCAhPT0gKHN0YXRlLmNoZWNrICYgNjU1MzUpKSB7CiAgICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaGVhZGVyIGNyYyBtaXNtYXRjaCI7CiAgICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBob2xkID0gMDsKICAgICAgICAgICAgICAgICAgYml0cyA9IDA7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuaGVhZCkgewogICAgICAgICAgICAgICAgICBzdGF0ZS5oZWFkLmhjcmMgPSBzdGF0ZS5mbGFncyA+PiA5ICYgMTsKICAgICAgICAgICAgICAgICAgc3RhdGUuaGVhZC5kb25lID0gdHJ1ZTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0cm0uYWRsZXIgPSBzdGF0ZS5jaGVjayA9IDA7CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gVFlQRTsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgIGNhc2UgRElDVElEOgogICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCAzMikgewogICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gc3RhdGUuY2hlY2sgPSB6c3dhcDMyKGhvbGQpOwogICAgICAgICAgICAgICAgaG9sZCA9IDA7CiAgICAgICAgICAgICAgICBiaXRzID0gMDsKICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBESUNUOwogICAgICAgICAgICAgIGNhc2UgRElDVDoKICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5oYXZlZGljdCA9PT0gMCkgewogICAgICAgICAgICAgICAgICBzdHJtLm5leHRfb3V0ID0gcHV0OwogICAgICAgICAgICAgICAgICBzdHJtLmF2YWlsX291dCA9IGxlZnQ7CiAgICAgICAgICAgICAgICAgIHN0cm0ubmV4dF9pbiA9IG5leHQ7CiAgICAgICAgICAgICAgICAgIHN0cm0uYXZhaWxfaW4gPSBoYXZlOwogICAgICAgICAgICAgICAgICBzdGF0ZS5ob2xkID0gaG9sZDsKICAgICAgICAgICAgICAgICAgc3RhdGUuYml0cyA9IGJpdHM7CiAgICAgICAgICAgICAgICAgIHJldHVybiBaX05FRURfRElDVDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0cm0uYWRsZXIgPSBzdGF0ZS5jaGVjayA9IDE7CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gVFlQRTsKICAgICAgICAgICAgICBjYXNlIFRZUEU6CiAgICAgICAgICAgICAgICBpZiAoZmx1c2ggPT09IFpfQkxPQ0sgfHwgZmx1c2ggPT09IFpfVFJFRVMpIHsKICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGNhc2UgVFlQRURPOgogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmxhc3QpIHsKICAgICAgICAgICAgICAgICAgaG9sZCA+Pj49IGJpdHMgJiA3OwogICAgICAgICAgICAgICAgICBiaXRzIC09IGJpdHMgJiA3OwogICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQ0hFQ0s7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCAzKSB7CiAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0YXRlLmxhc3QgPSBob2xkICYgMTsKICAgICAgICAgICAgICAgIGhvbGQgPj4+PSAxOwogICAgICAgICAgICAgICAgYml0cyAtPSAxOwogICAgICAgICAgICAgICAgc3dpdGNoIChob2xkICYgMykgewogICAgICAgICAgICAgICAgICBjYXNlIDA6CiAgICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IFNUT1JFRDsKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgY2FzZSAxOgogICAgICAgICAgICAgICAgICAgIGZpeGVkdGFibGVzKHN0YXRlKTsKICAgICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gTEVOXzsKICAgICAgICAgICAgICAgICAgICBpZiAoZmx1c2ggPT09IFpfVFJFRVMpIHsKICAgICAgICAgICAgICAgICAgICAgIGhvbGQgPj4+PSAyOwogICAgICAgICAgICAgICAgICAgICAgYml0cyAtPSAyOwogICAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgY2FzZSAyOgogICAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBUQUJMRTsKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgY2FzZSAzOgogICAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImludmFsaWQgYmxvY2sgdHlwZSI7CiAgICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGhvbGQgPj4+PSAyOwogICAgICAgICAgICAgICAgYml0cyAtPSAyOwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgY2FzZSBTVE9SRUQ6CiAgICAgICAgICAgICAgICBob2xkID4+Pj0gYml0cyAmIDc7CiAgICAgICAgICAgICAgICBiaXRzIC09IGJpdHMgJiA3OwogICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCAzMikgewogICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoKGhvbGQgJiA2NTUzNSkgIT09IChob2xkID4+PiAxNiBeIDY1NTM1KSkgewogICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbnZhbGlkIHN0b3JlZCBibG9jayBsZW5ndGhzIjsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5sZW5ndGggPSBob2xkICYgNjU1MzU7CiAgICAgICAgICAgICAgICBob2xkID0gMDsKICAgICAgICAgICAgICAgIGJpdHMgPSAwOwogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IENPUFlfOwogICAgICAgICAgICAgICAgaWYgKGZsdXNoID09PSBaX1RSRUVTKSB7CiAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBjYXNlIENPUFlfOgogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IENPUFk7CiAgICAgICAgICAgICAgY2FzZSBDT1BZOgogICAgICAgICAgICAgICAgY29weSA9IHN0YXRlLmxlbmd0aDsKICAgICAgICAgICAgICAgIGlmIChjb3B5KSB7CiAgICAgICAgICAgICAgICAgIGlmIChjb3B5ID4gaGF2ZSkgewogICAgICAgICAgICAgICAgICAgIGNvcHkgPSBoYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChjb3B5ID4gbGVmdCkgewogICAgICAgICAgICAgICAgICAgIGNvcHkgPSBsZWZ0OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChjb3B5ID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIHV0aWxzLmFycmF5U2V0KG91dHB1dCwgaW5wdXQsIG5leHQsIGNvcHksIHB1dCk7CiAgICAgICAgICAgICAgICAgIGhhdmUgLT0gY29weTsKICAgICAgICAgICAgICAgICAgbmV4dCArPSBjb3B5OwogICAgICAgICAgICAgICAgICBsZWZ0IC09IGNvcHk7CiAgICAgICAgICAgICAgICAgIHB1dCArPSBjb3B5OwogICAgICAgICAgICAgICAgICBzdGF0ZS5sZW5ndGggLT0gY29weTsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gVFlQRTsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgIGNhc2UgVEFCTEU6CiAgICAgICAgICAgICAgICB3aGlsZSAoYml0cyA8IDE0KSB7CiAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0YXRlLm5sZW4gPSAoaG9sZCAmIDMxKSArIDI1NzsKICAgICAgICAgICAgICAgIGhvbGQgPj4+PSA1OwogICAgICAgICAgICAgICAgYml0cyAtPSA1OwogICAgICAgICAgICAgICAgc3RhdGUubmRpc3QgPSAoaG9sZCAmIDMxKSArIDE7CiAgICAgICAgICAgICAgICBob2xkID4+Pj0gNTsKICAgICAgICAgICAgICAgIGJpdHMgLT0gNTsKICAgICAgICAgICAgICAgIHN0YXRlLm5jb2RlID0gKGhvbGQgJiAxNSkgKyA0OwogICAgICAgICAgICAgICAgaG9sZCA+Pj49IDQ7CiAgICAgICAgICAgICAgICBiaXRzIC09IDQ7CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUubmxlbiA+IDI4NiB8fCBzdGF0ZS5uZGlzdCA+IDMwKSB7CiAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gInRvbyBtYW55IGxlbmd0aCBvciBkaXN0YW5jZSBzeW1ib2xzIjsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5oYXZlID0gMDsKICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBMRU5MRU5TOwogICAgICAgICAgICAgIGNhc2UgTEVOTEVOUzoKICAgICAgICAgICAgICAgIHdoaWxlIChzdGF0ZS5oYXZlIDwgc3RhdGUubmNvZGUpIHsKICAgICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCAzKSB7CiAgICAgICAgICAgICAgICAgICAgaWYgKGhhdmUgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgaGF2ZS0tOwogICAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBzdGF0ZS5sZW5zW29yZGVyW3N0YXRlLmhhdmUrK11dID0gaG9sZCAmIDc7CiAgICAgICAgICAgICAgICAgIGhvbGQgPj4+PSAzOwogICAgICAgICAgICAgICAgICBiaXRzIC09IDM7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB3aGlsZSAoc3RhdGUuaGF2ZSA8IDE5KSB7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmxlbnNbb3JkZXJbc3RhdGUuaGF2ZSsrXV0gPSAwOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUubGVuY29kZSA9IHN0YXRlLmxlbmR5bjsKICAgICAgICAgICAgICAgIHN0YXRlLmxlbmJpdHMgPSA3OwogICAgICAgICAgICAgICAgb3B0cyA9IHsgYml0czogc3RhdGUubGVuYml0cyB9OwogICAgICAgICAgICAgICAgcmV0ID0gaW5mbGF0ZV90YWJsZShDT0RFUywgc3RhdGUubGVucywgMCwgMTksIHN0YXRlLmxlbmNvZGUsIDAsIHN0YXRlLndvcmssIG9wdHMpOwogICAgICAgICAgICAgICAgc3RhdGUubGVuYml0cyA9IG9wdHMuYml0czsKICAgICAgICAgICAgICAgIGlmIChyZXQpIHsKICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW52YWxpZCBjb2RlIGxlbmd0aHMgc2V0IjsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5oYXZlID0gMDsKICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBDT0RFTEVOUzsKICAgICAgICAgICAgICBjYXNlIENPREVMRU5TOgogICAgICAgICAgICAgICAgd2hpbGUgKHN0YXRlLmhhdmUgPCBzdGF0ZS5ubGVuICsgc3RhdGUubmRpc3QpIHsKICAgICAgICAgICAgICAgICAgZm9yICg7IDsgKSB7CiAgICAgICAgICAgICAgICAgICAgaGVyZSA9IHN0YXRlLmxlbmNvZGVbaG9sZCAmICgxIDw8IHN0YXRlLmxlbmJpdHMpIC0gMV07CiAgICAgICAgICAgICAgICAgICAgaGVyZV9iaXRzID0gaGVyZSA+Pj4gMjQ7CiAgICAgICAgICAgICAgICAgICAgaGVyZV9vcCA9IGhlcmUgPj4+IDE2ICYgMjU1OwogICAgICAgICAgICAgICAgICAgIGhlcmVfdmFsID0gaGVyZSAmIDY1NTM1OwogICAgICAgICAgICAgICAgICAgIGlmIChoZXJlX2JpdHMgPD0gYml0cykgewogICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaWYgKGhlcmVfdmFsIDwgMTYpIHsKICAgICAgICAgICAgICAgICAgICBob2xkID4+Pj0gaGVyZV9iaXRzOwogICAgICAgICAgICAgICAgICAgIGJpdHMgLT0gaGVyZV9iaXRzOwogICAgICAgICAgICAgICAgICAgIHN0YXRlLmxlbnNbc3RhdGUuaGF2ZSsrXSA9IGhlcmVfdmFsOwogICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgIGlmIChoZXJlX3ZhbCA9PT0gMTYpIHsKICAgICAgICAgICAgICAgICAgICAgIG4gPSBoZXJlX2JpdHMgKyAyOwogICAgICAgICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCBuKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgIGhvbGQgPj4+PSBoZXJlX2JpdHM7CiAgICAgICAgICAgICAgICAgICAgICBiaXRzIC09IGhlcmVfYml0czsKICAgICAgICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5oYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImludmFsaWQgYml0IGxlbmd0aCByZXBlYXQiOwogICAgICAgICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEOwogICAgICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgIGxlbiA9IHN0YXRlLmxlbnNbc3RhdGUuaGF2ZSAtIDFdOwogICAgICAgICAgICAgICAgICAgICAgY29weSA9IDMgKyAoaG9sZCAmIDMpOwogICAgICAgICAgICAgICAgICAgICAgaG9sZCA+Pj49IDI7CiAgICAgICAgICAgICAgICAgICAgICBiaXRzIC09IDI7CiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIGlmIChoZXJlX3ZhbCA9PT0gMTcpIHsKICAgICAgICAgICAgICAgICAgICAgIG4gPSBoZXJlX2JpdHMgKyAzOwogICAgICAgICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCBuKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgIGhvbGQgPj4+PSBoZXJlX2JpdHM7CiAgICAgICAgICAgICAgICAgICAgICBiaXRzIC09IGhlcmVfYml0czsKICAgICAgICAgICAgICAgICAgICAgIGxlbiA9IDA7CiAgICAgICAgICAgICAgICAgICAgICBjb3B5ID0gMyArIChob2xkICYgNyk7CiAgICAgICAgICAgICAgICAgICAgICBob2xkID4+Pj0gMzsKICAgICAgICAgICAgICAgICAgICAgIGJpdHMgLT0gMzsKICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgbiA9IGhlcmVfYml0cyArIDc7CiAgICAgICAgICAgICAgICAgICAgICB3aGlsZSAoYml0cyA8IG4pIHsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGhhdmUgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgaGF2ZS0tOwogICAgICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgaG9sZCA+Pj49IGhlcmVfYml0czsKICAgICAgICAgICAgICAgICAgICAgIGJpdHMgLT0gaGVyZV9iaXRzOwogICAgICAgICAgICAgICAgICAgICAgbGVuID0gMDsKICAgICAgICAgICAgICAgICAgICAgIGNvcHkgPSAxMSArIChob2xkICYgMTI3KTsKICAgICAgICAgICAgICAgICAgICAgIGhvbGQgPj4+PSA3OwogICAgICAgICAgICAgICAgICAgICAgYml0cyAtPSA3OwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBpZiAoc3RhdGUuaGF2ZSArIGNvcHkgPiBzdGF0ZS5ubGVuICsgc3RhdGUubmRpc3QpIHsKICAgICAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImludmFsaWQgYml0IGxlbmd0aCByZXBlYXQiOwogICAgICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICB3aGlsZSAoY29weS0tKSB7CiAgICAgICAgICAgICAgICAgICAgICBzdGF0ZS5sZW5zW3N0YXRlLmhhdmUrK10gPSBsZW47CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUubW9kZSA9PT0gQkFEKSB7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmxlbnNbMjU2XSA9PT0gMCkgewogICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbnZhbGlkIGNvZGUgLS0gbWlzc2luZyBlbmQtb2YtYmxvY2siOwogICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEOwogICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHN0YXRlLmxlbmJpdHMgPSA5OwogICAgICAgICAgICAgICAgb3B0cyA9IHsgYml0czogc3RhdGUubGVuYml0cyB9OwogICAgICAgICAgICAgICAgcmV0ID0gaW5mbGF0ZV90YWJsZShMRU5TLCBzdGF0ZS5sZW5zLCAwLCBzdGF0ZS5ubGVuLCBzdGF0ZS5sZW5jb2RlLCAwLCBzdGF0ZS53b3JrLCBvcHRzKTsKICAgICAgICAgICAgICAgIHN0YXRlLmxlbmJpdHMgPSBvcHRzLmJpdHM7CiAgICAgICAgICAgICAgICBpZiAocmV0KSB7CiAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImludmFsaWQgbGl0ZXJhbC9sZW5ndGhzIHNldCI7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUuZGlzdGJpdHMgPSA2OwogICAgICAgICAgICAgICAgc3RhdGUuZGlzdGNvZGUgPSBzdGF0ZS5kaXN0ZHluOwogICAgICAgICAgICAgICAgb3B0cyA9IHsgYml0czogc3RhdGUuZGlzdGJpdHMgfTsKICAgICAgICAgICAgICAgIHJldCA9IGluZmxhdGVfdGFibGUoRElTVFMsIHN0YXRlLmxlbnMsIHN0YXRlLm5sZW4sIHN0YXRlLm5kaXN0LCBzdGF0ZS5kaXN0Y29kZSwgMCwgc3RhdGUud29yaywgb3B0cyk7CiAgICAgICAgICAgICAgICBzdGF0ZS5kaXN0Yml0cyA9IG9wdHMuYml0czsKICAgICAgICAgICAgICAgIGlmIChyZXQpIHsKICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW52YWxpZCBkaXN0YW5jZXMgc2V0IjsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gTEVOXzsKICAgICAgICAgICAgICAgIGlmIChmbHVzaCA9PT0gWl9UUkVFUykgewogICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgY2FzZSBMRU5fOgogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IExFTjsKICAgICAgICAgICAgICBjYXNlIExFTjoKICAgICAgICAgICAgICAgIGlmIChoYXZlID49IDYgJiYgbGVmdCA+PSAyNTgpIHsKICAgICAgICAgICAgICAgICAgc3RybS5uZXh0X291dCA9IHB1dDsKICAgICAgICAgICAgICAgICAgc3RybS5hdmFpbF9vdXQgPSBsZWZ0OwogICAgICAgICAgICAgICAgICBzdHJtLm5leHRfaW4gPSBuZXh0OwogICAgICAgICAgICAgICAgICBzdHJtLmF2YWlsX2luID0gaGF2ZTsKICAgICAgICAgICAgICAgICAgc3RhdGUuaG9sZCA9IGhvbGQ7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmJpdHMgPSBiaXRzOwogICAgICAgICAgICAgICAgICBpbmZsYXRlX2Zhc3Qoc3RybSwgX291dCk7CiAgICAgICAgICAgICAgICAgIHB1dCA9IHN0cm0ubmV4dF9vdXQ7CiAgICAgICAgICAgICAgICAgIG91dHB1dCA9IHN0cm0ub3V0cHV0OwogICAgICAgICAgICAgICAgICBsZWZ0ID0gc3RybS5hdmFpbF9vdXQ7CiAgICAgICAgICAgICAgICAgIG5leHQgPSBzdHJtLm5leHRfaW47CiAgICAgICAgICAgICAgICAgIGlucHV0ID0gc3RybS5pbnB1dDsKICAgICAgICAgICAgICAgICAgaGF2ZSA9IHN0cm0uYXZhaWxfaW47CiAgICAgICAgICAgICAgICAgIGhvbGQgPSBzdGF0ZS5ob2xkOwogICAgICAgICAgICAgICAgICBiaXRzID0gc3RhdGUuYml0czsKICAgICAgICAgICAgICAgICAgaWYgKHN0YXRlLm1vZGUgPT09IFRZUEUpIHsKICAgICAgICAgICAgICAgICAgICBzdGF0ZS5iYWNrID0gLTE7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5iYWNrID0gMDsKICAgICAgICAgICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgICAgICAgICBoZXJlID0gc3RhdGUubGVuY29kZVtob2xkICYgKDEgPDwgc3RhdGUubGVuYml0cykgLSAxXTsKICAgICAgICAgICAgICAgICAgaGVyZV9iaXRzID0gaGVyZSA+Pj4gMjQ7CiAgICAgICAgICAgICAgICAgIGhlcmVfb3AgPSBoZXJlID4+PiAxNiAmIDI1NTsKICAgICAgICAgICAgICAgICAgaGVyZV92YWwgPSBoZXJlICYgNjU1MzU7CiAgICAgICAgICAgICAgICAgIGlmIChoZXJlX2JpdHMgPD0gYml0cykgewogICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmIChoZXJlX29wICYmIChoZXJlX29wICYgMjQwKSA9PT0gMCkgewogICAgICAgICAgICAgICAgICBsYXN0X2JpdHMgPSBoZXJlX2JpdHM7CiAgICAgICAgICAgICAgICAgIGxhc3Rfb3AgPSBoZXJlX29wOwogICAgICAgICAgICAgICAgICBsYXN0X3ZhbCA9IGhlcmVfdmFsOwogICAgICAgICAgICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgICAgICAgICAgICBoZXJlID0gc3RhdGUubGVuY29kZVtsYXN0X3ZhbCArICgoaG9sZCAmICgxIDw8IGxhc3RfYml0cyArIGxhc3Rfb3ApIC0gMSkgPj4gbGFzdF9iaXRzKV07CiAgICAgICAgICAgICAgICAgICAgaGVyZV9iaXRzID0gaGVyZSA+Pj4gMjQ7CiAgICAgICAgICAgICAgICAgICAgaGVyZV9vcCA9IGhlcmUgPj4+IDE2ICYgMjU1OwogICAgICAgICAgICAgICAgICAgIGhlcmVfdmFsID0gaGVyZSAmIDY1NTM1OwogICAgICAgICAgICAgICAgICAgIGlmIChsYXN0X2JpdHMgKyBoZXJlX2JpdHMgPD0gYml0cykgewogICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaG9sZCA+Pj49IGxhc3RfYml0czsKICAgICAgICAgICAgICAgICAgYml0cyAtPSBsYXN0X2JpdHM7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmJhY2sgKz0gbGFzdF9iaXRzOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaG9sZCA+Pj49IGhlcmVfYml0czsKICAgICAgICAgICAgICAgIGJpdHMgLT0gaGVyZV9iaXRzOwogICAgICAgICAgICAgICAgc3RhdGUuYmFjayArPSBoZXJlX2JpdHM7CiAgICAgICAgICAgICAgICBzdGF0ZS5sZW5ndGggPSBoZXJlX3ZhbDsKICAgICAgICAgICAgICAgIGlmIChoZXJlX29wID09PSAwKSB7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBMSVQ7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYgKGhlcmVfb3AgJiAzMikgewogICAgICAgICAgICAgICAgICBzdGF0ZS5iYWNrID0gLTE7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBUWVBFOwogICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmIChoZXJlX29wICYgNjQpIHsKICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW52YWxpZCBsaXRlcmFsL2xlbmd0aCBjb2RlIjsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5leHRyYSA9IGhlcmVfb3AgJiAxNTsKICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBMRU5FWFQ7CiAgICAgICAgICAgICAgY2FzZSBMRU5FWFQ6CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUuZXh0cmEpIHsKICAgICAgICAgICAgICAgICAgbiA9IHN0YXRlLmV4dHJhOwogICAgICAgICAgICAgICAgICB3aGlsZSAoYml0cyA8IG4pIHsKICAgICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIHN0YXRlLmxlbmd0aCArPSBob2xkICYgKDEgPDwgc3RhdGUuZXh0cmEpIC0gMTsKICAgICAgICAgICAgICAgICAgaG9sZCA+Pj49IHN0YXRlLmV4dHJhOwogICAgICAgICAgICAgICAgICBiaXRzIC09IHN0YXRlLmV4dHJhOwogICAgICAgICAgICAgICAgICBzdGF0ZS5iYWNrICs9IHN0YXRlLmV4dHJhOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUud2FzID0gc3RhdGUubGVuZ3RoOwogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IERJU1Q7CiAgICAgICAgICAgICAgY2FzZSBESVNUOgogICAgICAgICAgICAgICAgZm9yICg7IDsgKSB7CiAgICAgICAgICAgICAgICAgIGhlcmUgPSBzdGF0ZS5kaXN0Y29kZVtob2xkICYgKDEgPDwgc3RhdGUuZGlzdGJpdHMpIC0gMV07CiAgICAgICAgICAgICAgICAgIGhlcmVfYml0cyA9IGhlcmUgPj4+IDI0OwogICAgICAgICAgICAgICAgICBoZXJlX29wID0gaGVyZSA+Pj4gMTYgJiAyNTU7CiAgICAgICAgICAgICAgICAgIGhlcmVfdmFsID0gaGVyZSAmIDY1NTM1OwogICAgICAgICAgICAgICAgICBpZiAoaGVyZV9iaXRzIDw9IGJpdHMpIHsKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoKGhlcmVfb3AgJiAyNDApID09PSAwKSB7CiAgICAgICAgICAgICAgICAgIGxhc3RfYml0cyA9IGhlcmVfYml0czsKICAgICAgICAgICAgICAgICAgbGFzdF9vcCA9IGhlcmVfb3A7CiAgICAgICAgICAgICAgICAgIGxhc3RfdmFsID0gaGVyZV92YWw7CiAgICAgICAgICAgICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgICAgICAgICAgIGhlcmUgPSBzdGF0ZS5kaXN0Y29kZVtsYXN0X3ZhbCArICgoaG9sZCAmICgxIDw8IGxhc3RfYml0cyArIGxhc3Rfb3ApIC0gMSkgPj4gbGFzdF9iaXRzKV07CiAgICAgICAgICAgICAgICAgICAgaGVyZV9iaXRzID0gaGVyZSA+Pj4gMjQ7CiAgICAgICAgICAgICAgICAgICAgaGVyZV9vcCA9IGhlcmUgPj4+IDE2ICYgMjU1OwogICAgICAgICAgICAgICAgICAgIGhlcmVfdmFsID0gaGVyZSAmIDY1NTM1OwogICAgICAgICAgICAgICAgICAgIGlmIChsYXN0X2JpdHMgKyBoZXJlX2JpdHMgPD0gYml0cykgewogICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaG9sZCA+Pj49IGxhc3RfYml0czsKICAgICAgICAgICAgICAgICAgYml0cyAtPSBsYXN0X2JpdHM7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmJhY2sgKz0gbGFzdF9iaXRzOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaG9sZCA+Pj49IGhlcmVfYml0czsKICAgICAgICAgICAgICAgIGJpdHMgLT0gaGVyZV9iaXRzOwogICAgICAgICAgICAgICAgc3RhdGUuYmFjayArPSBoZXJlX2JpdHM7CiAgICAgICAgICAgICAgICBpZiAoaGVyZV9vcCAmIDY0KSB7CiAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImludmFsaWQgZGlzdGFuY2UgY29kZSI7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUub2Zmc2V0ID0gaGVyZV92YWw7CiAgICAgICAgICAgICAgICBzdGF0ZS5leHRyYSA9IGhlcmVfb3AgJiAxNTsKICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBESVNURVhUOwogICAgICAgICAgICAgIGNhc2UgRElTVEVYVDoKICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5leHRyYSkgewogICAgICAgICAgICAgICAgICBuID0gc3RhdGUuZXh0cmE7CiAgICAgICAgICAgICAgICAgIHdoaWxlIChiaXRzIDwgbikgewogICAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgc3RhdGUub2Zmc2V0ICs9IGhvbGQgJiAoMSA8PCBzdGF0ZS5leHRyYSkgLSAxOwogICAgICAgICAgICAgICAgICBob2xkID4+Pj0gc3RhdGUuZXh0cmE7CiAgICAgICAgICAgICAgICAgIGJpdHMgLT0gc3RhdGUuZXh0cmE7CiAgICAgICAgICAgICAgICAgIHN0YXRlLmJhY2sgKz0gc3RhdGUuZXh0cmE7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUub2Zmc2V0ID4gc3RhdGUuZG1heCkgewogICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbnZhbGlkIGRpc3RhbmNlIHRvbyBmYXIgYmFjayI7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IE1BVENIOwogICAgICAgICAgICAgIGNhc2UgTUFUQ0g6CiAgICAgICAgICAgICAgICBpZiAobGVmdCA9PT0gMCkgewogICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBjb3B5ID0gX291dCAtIGxlZnQ7CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUub2Zmc2V0ID4gY29weSkgewogICAgICAgICAgICAgICAgICBjb3B5ID0gc3RhdGUub2Zmc2V0IC0gY29weTsKICAgICAgICAgICAgICAgICAgaWYgKGNvcHkgPiBzdGF0ZS53aGF2ZSkgewogICAgICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5zYW5lKSB7CiAgICAgICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbnZhbGlkIGRpc3RhbmNlIHRvbyBmYXIgYmFjayI7CiAgICAgICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEOwogICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChjb3B5ID4gc3RhdGUud25leHQpIHsKICAgICAgICAgICAgICAgICAgICBjb3B5IC09IHN0YXRlLnduZXh0OwogICAgICAgICAgICAgICAgICAgIGZyb20gPSBzdGF0ZS53c2l6ZSAtIGNvcHk7CiAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgZnJvbSA9IHN0YXRlLnduZXh0IC0gY29weTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBpZiAoY29weSA+IHN0YXRlLmxlbmd0aCkgewogICAgICAgICAgICAgICAgICAgIGNvcHkgPSBzdGF0ZS5sZW5ndGg7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgZnJvbV9zb3VyY2UgPSBzdGF0ZS53aW5kb3c7CiAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICBmcm9tX3NvdXJjZSA9IG91dHB1dDsKICAgICAgICAgICAgICAgICAgZnJvbSA9IHB1dCAtIHN0YXRlLm9mZnNldDsKICAgICAgICAgICAgICAgICAgY29weSA9IHN0YXRlLmxlbmd0aDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmIChjb3B5ID4gbGVmdCkgewogICAgICAgICAgICAgICAgICBjb3B5ID0gbGVmdDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGxlZnQgLT0gY29weTsKICAgICAgICAgICAgICAgIHN0YXRlLmxlbmd0aCAtPSBjb3B5OwogICAgICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgICAgICBvdXRwdXRbcHV0KytdID0gZnJvbV9zb3VyY2VbZnJvbSsrXTsKICAgICAgICAgICAgICAgIH0gd2hpbGUgKC0tY29weSk7CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUubGVuZ3RoID09PSAwKSB7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBMRU47CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICBjYXNlIExJVDoKICAgICAgICAgICAgICAgIGlmIChsZWZ0ID09PSAwKSB7CiAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIG91dHB1dFtwdXQrK10gPSBzdGF0ZS5sZW5ndGg7CiAgICAgICAgICAgICAgICBsZWZ0LS07CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gTEVOOwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgY2FzZSBDSEVDSzoKICAgICAgICAgICAgICAgIGlmIChzdGF0ZS53cmFwKSB7CiAgICAgICAgICAgICAgICAgIHdoaWxlIChiaXRzIDwgMzIpIHsKICAgICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgICAgaG9sZCB8PSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIF9vdXQgLT0gbGVmdDsKICAgICAgICAgICAgICAgICAgc3RybS50b3RhbF9vdXQgKz0gX291dDsKICAgICAgICAgICAgICAgICAgc3RhdGUudG90YWwgKz0gX291dDsKICAgICAgICAgICAgICAgICAgaWYgKF9vdXQpIHsKICAgICAgICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gc3RhdGUuY2hlY2sgPSBzdGF0ZS5mbGFncyA/IGNyYzMyKHN0YXRlLmNoZWNrLCBvdXRwdXQsIF9vdXQsIHB1dCAtIF9vdXQpIDogYWRsZXIzMihzdGF0ZS5jaGVjaywgb3V0cHV0LCBfb3V0LCBwdXQgLSBfb3V0KTsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBfb3V0ID0gbGVmdDsKICAgICAgICAgICAgICAgICAgaWYgKChzdGF0ZS5mbGFncyA/IGhvbGQgOiB6c3dhcDMyKGhvbGQpKSAhPT0gc3RhdGUuY2hlY2spIHsKICAgICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbmNvcnJlY3QgZGF0YSBjaGVjayI7CiAgICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBob2xkID0gMDsKICAgICAgICAgICAgICAgICAgYml0cyA9IDA7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gTEVOR1RIOwogICAgICAgICAgICAgIGNhc2UgTEVOR1RIOgogICAgICAgICAgICAgICAgaWYgKHN0YXRlLndyYXAgJiYgc3RhdGUuZmxhZ3MpIHsKICAgICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCAzMikgewogICAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaWYgKGhvbGQgIT09IChzdGF0ZS50b3RhbCAmIDQyOTQ5NjcyOTUpKSB7CiAgICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW5jb3JyZWN0IGxlbmd0aCBjaGVjayI7CiAgICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBob2xkID0gMDsKICAgICAgICAgICAgICAgICAgYml0cyA9IDA7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gRE9ORTsKICAgICAgICAgICAgICBjYXNlIERPTkU6CiAgICAgICAgICAgICAgICByZXQgPSBaX1NUUkVBTV9FTkQ7CiAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgY2FzZSBCQUQ6CiAgICAgICAgICAgICAgICByZXQgPSBaX0RBVEFfRVJST1I7CiAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgY2FzZSBNRU06CiAgICAgICAgICAgICAgICByZXR1cm4gWl9NRU1fRVJST1I7CiAgICAgICAgICAgICAgY2FzZSBTWU5DOgogICAgICAgICAgICAgIGRlZmF1bHQ6CiAgICAgICAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICBzdHJtLm5leHRfb3V0ID0gcHV0OwogICAgICAgIHN0cm0uYXZhaWxfb3V0ID0gbGVmdDsKICAgICAgICBzdHJtLm5leHRfaW4gPSBuZXh0OwogICAgICAgIHN0cm0uYXZhaWxfaW4gPSBoYXZlOwogICAgICAgIHN0YXRlLmhvbGQgPSBob2xkOwogICAgICAgIHN0YXRlLmJpdHMgPSBiaXRzOwogICAgICAgIGlmIChzdGF0ZS53c2l6ZSB8fCBfb3V0ICE9PSBzdHJtLmF2YWlsX291dCAmJiBzdGF0ZS5tb2RlIDwgQkFEICYmIChzdGF0ZS5tb2RlIDwgQ0hFQ0sgfHwgZmx1c2ggIT09IFpfRklOSVNIKSkgewogICAgICAgICAgaWYgKHVwZGF0ZXdpbmRvdyhzdHJtLCBzdHJtLm91dHB1dCwgc3RybS5uZXh0X291dCwgX291dCAtIHN0cm0uYXZhaWxfb3V0KSkgewogICAgICAgICAgICBzdGF0ZS5tb2RlID0gTUVNOwogICAgICAgICAgICByZXR1cm4gWl9NRU1fRVJST1I7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIF9pbiAtPSBzdHJtLmF2YWlsX2luOwogICAgICAgIF9vdXQgLT0gc3RybS5hdmFpbF9vdXQ7CiAgICAgICAgc3RybS50b3RhbF9pbiArPSBfaW47CiAgICAgICAgc3RybS50b3RhbF9vdXQgKz0gX291dDsKICAgICAgICBzdGF0ZS50b3RhbCArPSBfb3V0OwogICAgICAgIGlmIChzdGF0ZS53cmFwICYmIF9vdXQpIHsKICAgICAgICAgIHN0cm0uYWRsZXIgPSBzdGF0ZS5jaGVjayA9IHN0YXRlLmZsYWdzID8gY3JjMzIoc3RhdGUuY2hlY2ssIG91dHB1dCwgX291dCwgc3RybS5uZXh0X291dCAtIF9vdXQpIDogYWRsZXIzMihzdGF0ZS5jaGVjaywgb3V0cHV0LCBfb3V0LCBzdHJtLm5leHRfb3V0IC0gX291dCk7CiAgICAgICAgfQogICAgICAgIHN0cm0uZGF0YV90eXBlID0gc3RhdGUuYml0cyArIChzdGF0ZS5sYXN0ID8gNjQgOiAwKSArIChzdGF0ZS5tb2RlID09PSBUWVBFID8gMTI4IDogMCkgKyAoc3RhdGUubW9kZSA9PT0gTEVOXyB8fCBzdGF0ZS5tb2RlID09PSBDT1BZXyA/IDI1NiA6IDApOwogICAgICAgIGlmICgoX2luID09PSAwICYmIF9vdXQgPT09IDAgfHwgZmx1c2ggPT09IFpfRklOSVNIKSAmJiByZXQgPT09IFpfT0spIHsKICAgICAgICAgIHJldCA9IFpfQlVGX0VSUk9SOwogICAgICAgIH0KICAgICAgICByZXR1cm4gcmV0OwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGluZmxhdGVFbmQoc3RybSkgewogICAgICAgIGlmICghc3RybSB8fCAhc3RybS5zdGF0ZSkgewogICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VSUk9SOwogICAgICAgIH0KICAgICAgICB2YXIgc3RhdGUgPSBzdHJtLnN0YXRlOwogICAgICAgIGlmIChzdGF0ZS53aW5kb3cpIHsKICAgICAgICAgIHN0YXRlLndpbmRvdyA9IG51bGw7CiAgICAgICAgfQogICAgICAgIHN0cm0uc3RhdGUgPSBudWxsOwogICAgICAgIHJldHVybiBaX09LOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGluZmxhdGVHZXRIZWFkZXIoc3RybSwgaGVhZCkgewogICAgICAgIHZhciBzdGF0ZTsKICAgICAgICBpZiAoIXN0cm0gfHwgIXN0cm0uc3RhdGUpIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgc3RhdGUgPSBzdHJtLnN0YXRlOwogICAgICAgIGlmICgoc3RhdGUud3JhcCAmIDIpID09PSAwKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIHN0YXRlLmhlYWQgPSBoZWFkOwogICAgICAgIGhlYWQuZG9uZSA9IGZhbHNlOwogICAgICAgIHJldHVybiBaX09LOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGluZmxhdGVTZXREaWN0aW9uYXJ5KHN0cm0sIGRpY3Rpb25hcnkpIHsKICAgICAgICB2YXIgZGljdExlbmd0aCA9IGRpY3Rpb25hcnkubGVuZ3RoOwogICAgICAgIHZhciBzdGF0ZTsKICAgICAgICB2YXIgZGljdGlkOwogICAgICAgIHZhciByZXQ7CiAgICAgICAgaWYgKCFzdHJtIHx8ICFzdHJtLnN0YXRlKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIHN0YXRlID0gc3RybS5zdGF0ZTsKICAgICAgICBpZiAoc3RhdGUud3JhcCAhPT0gMCAmJiBzdGF0ZS5tb2RlICE9PSBESUNUKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIGlmIChzdGF0ZS5tb2RlID09PSBESUNUKSB7CiAgICAgICAgICBkaWN0aWQgPSAxOwogICAgICAgICAgZGljdGlkID0gYWRsZXIzMihkaWN0aWQsIGRpY3Rpb25hcnksIGRpY3RMZW5ndGgsIDApOwogICAgICAgICAgaWYgKGRpY3RpZCAhPT0gc3RhdGUuY2hlY2spIHsKICAgICAgICAgICAgcmV0dXJuIFpfREFUQV9FUlJPUjsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0ID0gdXBkYXRld2luZG93KHN0cm0sIGRpY3Rpb25hcnksIGRpY3RMZW5ndGgsIGRpY3RMZW5ndGgpOwogICAgICAgIGlmIChyZXQpIHsKICAgICAgICAgIHN0YXRlLm1vZGUgPSBNRU07CiAgICAgICAgICByZXR1cm4gWl9NRU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIHN0YXRlLmhhdmVkaWN0ID0gMTsKICAgICAgICByZXR1cm4gWl9PSzsKICAgICAgfQogICAgICBleHBvcnRzMi5pbmZsYXRlUmVzZXQgPSBpbmZsYXRlUmVzZXQ7CiAgICAgIGV4cG9ydHMyLmluZmxhdGVSZXNldDIgPSBpbmZsYXRlUmVzZXQyOwogICAgICBleHBvcnRzMi5pbmZsYXRlUmVzZXRLZWVwID0gaW5mbGF0ZVJlc2V0S2VlcDsKICAgICAgZXhwb3J0czIuaW5mbGF0ZUluaXQgPSBpbmZsYXRlSW5pdDsKICAgICAgZXhwb3J0czIuaW5mbGF0ZUluaXQyID0gaW5mbGF0ZUluaXQyOwogICAgICBleHBvcnRzMi5pbmZsYXRlID0gaW5mbGF0ZTsKICAgICAgZXhwb3J0czIuaW5mbGF0ZUVuZCA9I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NJT046IDAsCiAgICAgICAgWl9CRVNUX1NQRUVEOiAxLAogICAgICAgIFpfQkVTVF9DT01QUkVTU0lPTjogOSwKICAgICAgICBaX0RFRkFVTFRfQ09NUFJFU1NJT046IC0xLAogICAgICAgIFpfRklMVEVSRUQ6IDEsCiAgICAgICAgWl9IVUZGTUFOX09OTFk6IDIsCiAgICAgICAgWl9STEU6IDMsCiAgICAgICAgWl9GSVhFRDogNCwKICAgICAgICBaX0RFRkFVTFRfU1RSQVRFR1k6IDAsCiAgICAgICAgWl9CSU5BUlk6IDAsCiAgICAgICAgWl9URVhUOiAxLAogICAgICAgIFpfVU5LTk9XTjogMiwKICAgICAgICBaX0RFRkxBVEVEOiA4CiAgICAgIH07CiAgICB9CiAgfSk7CgogIC8vIG5vZGVfbW9kdWxlcy8ucG5wbS9wYWtvQDEuMC4xMS9ub2RlX21vZHVsZXMvcGFrby9saWIvemxpYi9nemhlYWRlci5qcwogIHZhciByZXF1aXJlX2d6aGVhZGVyID0gX19jb21tb25KUyh7CiAgICAibm9kZV9tb2R1bGVzLy5wbnBtL3Bha29AMS4wLjExL25vZGVfbW9kdWxlcy9wYWtvL2xpYi96bGliL2d6aGVhZGVyLmpzIihleHBvcnRzMiwgbW9kdWxlMikgewogICAgICBpbml0X2J1ZmZlcl9zaGltKCk7CiAgICAgICJ1c2Ugc3RyaWN0IjsKICAgICAgZnVuY3Rpb24gR1poZWFkZXIoKSB7CiAgICAgICAgdGhpcy50ZXh0ID0gMDsKICAgICAgICB0aGlzLnRpbWUgPSAwOwogICAgICAgIHRoaXMueGZsYWdzID0gMDsKICAgICAgICB0aGlzLm9zID0gMDsKICAgICAgICB0aGlzLmV4dHJhID0gbnVsbDsKICAgICAgICB0aGlzLmV4dHJhX2xlbiA9IDA7CiAgICAgICAgdGhpcy5uYW1lID0gIiI7CiAgICAgICAgdGhpcy5jb21tZW50ID0gIiI7CiAgICAgICAgdGhpcy5oY3JjID0gMDsKICAgICAgICB0aGlzLmRvbmUgPSBm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ICIiCiAgICAgICAgfSwgb3B0aW9ucyB8fCB7fSk7CiAgICAgICAgdmFyIG9wdCA9IHRoaXMub3B0aW9uczsKICAgICAgICBpZiAob3B0LnJhdyAmJiBvcHQud2luZG93Qml0cyA+PSAwICYmIG9wdC53aW5kb3dCaXRzIDwgMTYpIHsKICAgICAgICAgIG9wdC53aW5kb3dCaXRzID0gLW9wdC53aW5kb3dCaXRzOwogICAgICAgICAgaWYgKG9wdC53aW5kb3dCaXRzID09PSAwKSB7CiAgICAgICAgICAgIG9wdC53aW5kb3dCaXRzID0gLTE1OwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAob3B0LndpbmRvd0JpdHMgPj0gMCAmJiBvcHQud2luZG93Qml0cyA8IDE2ICYmICEob3B0aW9ucyAmJiBvcHRpb25zLndpbmRvd0JpdHMpKSB7CiAgICAgICAgICBvcHQud2luZG93Qml0cyArPSAzMjsKICAgICAgICB9CiAgICAgICAgaWYgKG9wdC53aW5kb3dCaXRzID4gMTUgJiYgb3B0LndpbmRvd0JpdHMgPCA0OCkgewogICAgICAgICAgaWYgKChvcHQud2luZG93Qml0cyAmIDE1KSA9PT0gMCkgewogICAgICAgICAgICBvcHQud2luZG93Qml0cyB8PSAxNTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgdGhpcy5lcnIgPSAwOwogICAgICAgIHRoaXMubXNnID0gIiI7CiAgICAgICAgdGhpcy5lbmRlZCA9IGZhbHNlOwogICAgICAgIHRoaXMuY2h1bmtzID0gW107CiAgICAgICAgdGhpcy5zdHJtID0gbmV3IFpTdHJlYW0oKTsKICAgICAgICB0aGlzLnN0cm0uYXZhaWxfb3V0ID0gMDsKICAgICAgICB2YXIgc3RhdHVzID0gemxpYl9pbmZsYXRlLmluZmxhdGVJbml0Mih0aGlzLnN0cm0sIG9wdC53aW5kb3dCaXRzKTsKICAgICAgICBpZiAoc3RhdHVzICE9PSBjLlpfT0spIHsKICAgICAgICAgIHRocm93IG5ldyBFcnJvcih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AgICAgICAgdmFyIHN0YXR1cywgX21vZGU7CiAgICAgICAgdmFyIG5leHRfb3V0X3V0ZjgsIHRhaWwsIHV0ZjhzdHI7CiAgICAgICAgdmFyIGFsbG93QnVmRXJyb3IgPSBmYWxzZTsKICAgICAgICBpZiAodGhpcy5lbmRlZCkgewogICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICAgIH0KICAgICAgICBfbW9kZSA9IG1vZGUgPT09IH5+bW9kZSA/IG1vZGUgOiBtb2RlID09PSB0cnVlID8gYy5aX0ZJTklTSCA6IGMuWl9OT19GTFVTSDsKICAgICAgICBpZiAodHlwZW9mIGRhdGEgPT09ICJzdHJpbmciKSB7CiAgICAgICAgICBzdHJtLmlucHV0ID0gc3RyaW5ncy5iaW5zdHJpbmcyYnVmKGRhdGEpOwogICAgICAgIH0gZWxzZSBpZiAodG9TdHJpbmcuY2FsbChkYXRhKSA9PT0gIltvYmplY3QgQXJyYXlCdWZmZXJdIikgewogICAgICAgICAgc3RybS5pbnB1dCA9IG5ldyBVaW50OEFycmF5KGRhdGEpOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBzdHJtLmlucHV0ID0gZGF0YTsKICAgICAgICB9CiAgICAgICAgc3RybS5uZXh0X2luID0gMDsKICAgICAgICBzdHJtLmF2YWlsX2luID0gc3RybS5pbnB1dC5sZW5ndGg7CiAgICAgICAgZG8gewogICAgICAgICAgaWYgKHN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgIHN0cm0ub3V0cHV0ID0gbmV3IHV0aWxzLkJ1ZjgoY2h1bmtTaXplKTsKICAgICAgICAgICAgc3RybS5uZXh0X291dCA9IDA7CiAgICAgICAgICAgIHN0cm0uYXZhaWxfb3V0ID0gY2h1bmtTaXplOwogICAgICAgICAgfQogICAgICAgICAgc3RhdHVzID0gemxpYl9pbmZsYXRlLmluZmxhdGUoc3RybSwgYy5aX05PX0ZMVVNIKTsKICAgICAgICAgIGlmIChzdGF0dXMgPT09IGMuWl9ORUVEX0RJQ1QgJiYgZGljdGlvbmFyeSkgewogICAgICAgICAgICBzdGF0dXMgPSB6bGliX2luZmxhdGUuaW5mbGF0ZVNldERpY3Rpb25hcnkodGhpcy5zdHJtLCBkaWN0aW9uYXJ5KTsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChzdGF0dXMgPT09IGMuWl9CVUZfRVJST1IgJiYgYWxsb3dCdWZFcnJvciA9PT0gdHJ1ZSkgewogICAgICAgICAgICBzdGF0dXMgPSBjLlpfT0s7CiAgICAgICAgICAgIGFsbG93QnVmRXJyb3IgPSBmYWxzZTsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChzdGF0dXMgIT09IGMuWl9TVFJFQU1fRU5EICYmIHN0YXR1cyAhPT0gYy5aX09LKSB7CiAgICAgICAgICAgIHRoaXMub25FbmQoc3RhdHVzKTsKICAgICAgICAgICAgdGhpcy5lbmRlZCA9IHRydWU7CiAgICAgICAgICAgIHJldHVybiBmYWxzZTsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChzdHJtLm5leHRfb3V0KSB7CiAgICAgICAgICAgIGlmIChzdHJtLmF2YWlsX291dCA9PT0gMCB8fCBzdGF0dXMgPT09IGMuWl9TVFJFQU1fRU5EIHx8IHN0cm0uYXZhaWxfaW4gPT09IDAgJiYgKF9tb2RlID09PSBjLlpfRklOSVNIIHx8IF9tb2RlID09PSBjLlpfU1lOQ19GTFVTSCkpIHsKICAgICAgICAgICAgICBpZiAodGhpcy5vcHRpb25zLnRvID09PSAic3RyaW5nIikgewogICAgICAgICAgICAgICAgbmV4dF9vdXRfdXRmOCA9IHN0cmluZ3MudXRmOGJvcmRlcihzdHJtLm91dHB1dCwgc3RybS5uZXh0X291dCk7CiAgICAgICAgICAgICAgICB0YWlsID0gc3RybS5uZXh0X291dCAtIG5leHRfb3V0X3V0Zjg7CiAgICAgICAgICAgICAgICB1dGY4c3RyID0gc3RyaW5ncy5idWYyc3RyaW5nKHN0cm0ub3V0cHV0LCBuZXh0X291dF91dGY4KTsKICAgICAgICAgICAgICAgIHN0cm0ubmV4dF9vdXQgPSB0YWlsOwogICAgICAgICAgICAgICAgc3RybS5hdmFpbF9vdXQgPSBjaHVua1NpemUgLSB0YWlsOwogICAgICAgICAgICAgICAgaWYgKHRhaWwpIHsKICAgICAgICAgICAgICAgICAgdXRpbHMuYXJyYXlTZXQoc3RybS5vdXRwdXQsIHN0cm0ub3V0cHV0LCBuZXh0X291dF91dGY4LCB0YWlsLCAwKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHRoaXMub25EYXRhKHV0ZjhzdHIpOwogICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICB0aGlzLm9uRGF0YSh1dGlscy5zaHJpbmtCdWYoc3RybS5vdXRwdXQsIHN0cm0ubmV4dF9vdXQpKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGlmIChzdHJtLmF2YWlsX2luID09PSAwICYmIHN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgIGFsbG93QnVmRXJyb3IgPSB0cnVlOwogICAgICAgICAgfQogICAgICAgIH0gd2hpbGUgKChzdHJtLmF2YWlsX2luID4gMCB8fCBzdHJtLmF2YWlsX291dCA9PT0gMCkgJiYgc3RhdHVzICE9PSBjLlpfU1RSRUFNX0VORCk7CiAgICAgICAgaWYgKHN0YXR1cyA9PT0gYy5aX1NUUkVBTV9FTkQpIHsKICAgICAgICAgIF9tb2RlID0gYy5aX0ZJTklTSDsKICAgICAgICB9CiAgICAgICAgaWYgKF9tb2RlID09PSBjLlpfRklOSVNIKSB7CiAgICAgICAgICBzdGF0dXMgPSB6bGliX2luZmxhdGUuaW5mbGF0ZUVuZCh0aGlzLnN0cm0pOwogICAgICAgICAgdGhpcy5vbkVuZChzdGF0dXMpOwogICAgICAgICAgdGhpcy5lbmRlZCA9IHRydWU7CiAgICAgICAgICByZXR1cm4gc3RhdHVzID09PSBjLlpfT0s7CiAgICAgICAgfQogICAgICAgIGlmIChfbW9kZSA9PT0gYy5aX1NZTkNfRkxVU0gpIHsKICAgICAgICAgIHRoaXMub25FbmQoYy5aX09LKTsKICAgICAgICAgIHN0cm0uYXZhaWxfb3V0ID0gMDsKICAgICAgICAgIHJldHVybiB0cnVlOwogICAgICAgIH0KICAgICAgICByZXR1cm4gdHJ1ZTsKICAgICAgfTsKICAgICAgSW5mbGF0ZTIucHJvdG90eXBlLm9uRGF0YSA9IGZ1bmN0aW9uKGNodW5rKSB7CiAgICAgICAgdGhpcy5jaHVua3MucHVzaChjaHVuayk7CiAgICAgIH07CiAgICAgIEluZmxhdGUyLnByb3RvdHlwZS5vbkVuZCA9IGZ1bmN0aW9uKHN0YXR1cykgewogICAgICAgIGlmIChzdGF0dXMgPT09IGMuWl9PSykgewogICAgICAgICAgaWYgKHRoaXMub3B0aW9ucy50byA9PT0gInN0cmluZyIpIHsKICAgICAgICAgICAgdGhpcy5yZXN1bHQgPSB0aGlzLmNodW5rcy5qb2luKCIiKTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHRoaXMucmVzdWx0ID0gdXRpbHMuZmxhdHRlbkNodW5rcyh0aGlzLmNodW5rcyk7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHRoaXMuY2h1bmtzID0gW107CiAgICAgICAgdGhpcy5lcnIgPSBzdGF0dXM7CiAgICAgICAgdGhpcy5tc2cgPSB0aGlzLnN0cm0ubXNnOwogICAgICB9OwogICAgICBmdW5jdGlvbiBpbmZsYXRlKGlucHV0LCBvcHRpb25zKSB7CiAgICAgICAgdmFyIGluZmxhdG9yID0gbmV3IEluZmxhdGUyKG9wdGlvbnMpOwogICAgICAgIGluZmxhdG9yLnB1c2goaW5wdXQsIHRydWUpOwogICAgICAgIGlmIChpbmZsYXRvci5lcnIpIHsKICAgICAgICAgIHRocm93IGluZmxhdG9yLm1zZyB8fCBtc2dbaW5mbGF0b3IuZXJyXTsKICA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3J0cyA9IHBha287CiAgICB9CiAgfSk7CgogIC8vIG5vZGVfbW9kdWxlcy8ucG5wbS9sb25nQDQuMC4wL25vZGVfbW9kdWxlcy9sb25nL3NyYy9sb25nLmpzCiAgdmFyIHJlcXVpcmVfbG9uZyA9IF9fY29tbW9uSlMoewogICAgIm5vZGVfbW9kdWxlcy8ucG5wbS9sb25nQDQuMC4wL25vZGVfbW9kdWxlcy9sb25nL3NyYy9sb25nLmpzIihleHBvcnRzMiwgbW9kdWxlMikgewogICAgICBpbml0X2J1ZmZlcl9zaGltKCk7CiAgICAgIG1vZHVsZTIuZXhwb3J0cyA9IExvbmc0OwogICAgICB2YXIgd2FzbSA9IG51bGw7CiAgICAgIHRyeSB7CiAgICAgICAgd2FzbSA9IG5ldyBXZWJBc3NlbWJseS5JbnN0YW5jZShuZXcgV2ViQXNzZW1ibHkuTW9kdWxlKG5ldyBVaW50OEFycmF5KFsKICAgICAgICAgIDAsCiAgICAgICAgICA5NywKICAgICAgICAgIDExNSwKICAgICAgICAgIDEwOSwKICAgICAgICAgIDEsCiAgICAgICAgICAwLAogICAgICAgICAgMCwKICAgICAgICAgIDAsCiAgICAgICAgICAxLAogICAgICAgICAgMTMsCiAgICAgICAgICAyLAogICAgICAgICAgOTYsCiAgICAgICAgICAwLAogICAgICAgICAgMSwKICAgICAgICAgIDEyNywKICAgICAgICAgIDk2LAogICAgICAgICAgNCwKICAgICAgICAgIDEyNywKICAgICAgICAgIDEyNywKICAgICAgICAgIDEyNywKICAgICAgICAgIDEyNywKICAgICAgICAgIDEsCiAgICAgICAgICAxMjcsCiAgICAgICAgICAzLAogICAgICAgICAgNywKICAgICAgICAgIDYsCiAgICAgICAgICAwLAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICAxLAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICA2LAogICAgICAgICAgNiwKICAgICAgICAgIDEsCiAgICAgICAgICAxMjcsCiAgICAgICAgICAxLAogICAgICAgICAgNjUsCiAgICAgICAgICAwLAogICAgICAgICAgMTEsCiAgICAgICAgICA3LAogICAgICAgICAgNTAsCiAgICAgICAgICA2LAogICAgICAgICAgMywKICAgICAgICAgIDEwOSwKICAgICAgICAgIDExNywKICAgICAgICAgIDEwOCwKICAgICAgICAgIDAsCiAgICAgICAgICAxLAogICAgICAgICAgNSwKICAgICAgICAgIDEwMCwKICAgICAgICAgIDEwNSwKICAgICAgICAgIDExOCwKICAgICAgICAgIDk1LAogICAgICAgICAgMTE1LAogICAgICAgICAgMCwKICAgICAgICAgIDIsCiAgICAgICAgICA1LAogICAgICAgICAgMTAwLAogICAgICAgICAgMTA1LAogICAgICAgICAgMTE4LAogICAgICAgICAgOTUsCiAgICAgICAgICAxMTcsCiAgICAgICAgICAwLAogICAgICAgICAgMywKICAgICAgICAgIDUsCiAgICAgICAgICAxMTQsCiAgICAgICAgICAxMDEsCiAgICAgICAgICAxMDksCiAgICAgICAgICA5NSwKICAgICAgICAgIDExNSwKICAgICAgICAgIDAsCiAgICAgICAgICA0LAogICAgICAgICAgNSwKICAgICAgICAgIDExNCwKICAgICAgICAgIDEwMSwKICAgICAgICAgIDEwOSwKICAgICAgICAgIDk1LAogICAgICAgICAgMTE3LAogICAgICAgICAgMCwKICAgICAgICAgIDUsCiAgICAgICAgICA4LAogICAgICAgICAgMTAzLAogICAgICAgICAgMTAxLAogICAgICAgICAgMTE2LAogICAgICAgICAgOTUsCiAgICAgICAgICAxMDQsCiAgICAgICAgICAxMDUsCiAgICAgICAgICAxMDMsCiAgICAgICAgICAxMDQsCiAgICAgICAgICAwLAogICAgICAgICAgMCwKICAgICAgICAgIDEwLAogICAgICAgICAgMTkxLAogICAgICAgICAgMSwKICAgICAgICAgIDYsCiAgICAgICAgICA0LAogICAgICAgICAgMCwKICAgICAgICAgIDM1LAogICAgICAgICAgMCwKICAgICAgICAgIDExLAogICAgICAgICAgMzYsCiAgICAgICAgICAxLAogICAgICAgICAgMSwKICAgICAgICAgIDEyNiwKICAgICAgICAgIDMyLAogICAgICAgICAgMCwKICAgICAgICAgIDE3MywKICAgICAgICAgIDMyLAogICAgICAgICAgMSwKICAgICAgICAgIDE3MywKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzQsCiAgICAgICAgICAxMzIsCiAgICAgICAgICAzMiwKICAgICAgICAgIDIsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDMsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMTI2LAogICAgICAgICAgMzQsCiAgICAgICAgICA0LAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNSwKICAgICAgICAgIDE2NywKICAgICAgICAgIDM2LAogICAgICAgICAgMCwKICAgICAgICAgIDMyLAogICAgICAgICAgNCwKICAgICAgICAgIDE2NywKICAgICAgICAgIDExLAogICAgICAgICAgMzYsCiAgICAgICAgICAxLAogICAgICAgICAgMSwKICAgICAgICAgIDEyNiwKICAgICAgICAgIDMyLAogICAgICAgICAgMCwKICAgICAgICAgIDE3MywKICAgICAgICAgIDMyLAogICAgICAgICAgMSwKICAgICAgICAgIDE3MywKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzQsCiAgICAgICAgICAxMzIsCiAgICAgICAgICAzMiwKICAgICAgICAgIDIsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDMsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMTI3LAogICAgICAgICAgMzQsCiAgICAgICAgICA0LAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNSwKICAgICAgICAgIDE2NywKICAgICAgICAgIDM2LAogICAgICAgICAgMCwKICAgICAgICAgIDMyLAogICAgICAgICAgNCwKICAgICAgICAgIDE2NywKICAgICAgICAgIDExLAogICAgICAgICAgMzYsCiAgICAgICAgICAxLAogICAgICAgICAgMSwKICAgICAgICAgIDEyNiwKICAgICAgICAgIDMyLAogICAgICAgICAgMCwKICAgICAgICAgIDE3MywKICAgICAgICAgIDMyLAogICAgICAgICAgMSwKICAgICAgICAgIDE3MywKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzQsCiAgICAgICAgICAxMzIsCiAgICAgICAgICAzMiwKICAgICAgICAgIDIsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDMsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMTI4LAogICAgICAgICAgMzQsCiAgICAgICAgICA0LAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNSwKICAgICAgICAgIDE2NywKICAgICAgICAgIDM2LAogICAgICAgICAgMCwKICAgICAgICAgIDMyLAogICAgICAgICAgNCwKICAgICAgICAgIDE2NywKICAgICAgICAgIDExLAogICAgICAgICAgMzYsCiAgICAgICAgICAxLAogICAgICAgICAgMSwKICAgICAgICAgIDEyNiwKICAgICAgICAgIDMyLAogICAgICAgICAgMCwKICAgICAgICAgIDE3MywKICAgICAgICAgIDMyLAogICAgICAgICAgMSwKICAgICAgICAgIDE3MywKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzQsCiAgICAgICAgICAxMzIsCiAgICAgICAgICAzMiwKICAgICAgICAgIDIsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDMsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMTI5LAogICAgICAgICAgMzQsCiAgICAgICAgICA0LAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNSwKICAgICAgICAgIDE2NywKICAgICAgICAgIDM2LAogICAgICAgICAgMCwKICAgICAgICAgIDMyLAogICAgICAgICAgNCwKICAgICAgICAgIDE2NywKICAgICAgICAgIDExLAogICAgICAgICAgMzYsCiAgICAgICAgICAxLAogICAgICAgICAgMSwKICAgICAgICAgIDEyNiwKICAgICAgICAgIDMyLAogICAgICAgICAgMCwKICAgICAgICAgIDE3MywKICAgICAgICAgIDMyLAogICAgICAgICAgMSwKICAgICAgICAgIDE3MywKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzQsCiAgICAgICAgICAxMzIsCiAgICAgICAgICAzMiwKICAgICAgICAgIDIsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDMsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMTMwLAogICAgICAgICAgMzQsCiAgICAgICAgICA0LAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNSwKICAgICAgICAgIDE2NywKICAgICAgICAgIDM2LAogICAgICAgICAgMCwKICAgICAgICAgIDMyLAogICAgICAgICAgNCwKICAgICAgICAgIDE2NywKICAgICAgICAgIDExCiAgICAgICAgXSkpLCB7fSkuZXhwb3J0czsKICAgICAgfSBjYXRjaCAoZSkgewogICAgICB9CiAgICAgIGZ1bmN0aW9uIExvbmc0KGxvdywgaGlnaCwgdW5zaWduZWQpIHsKICAgICAgICB0aGlzLmxvdyA9IGxvdyB8IDA7CiAgICAgICAgdGhpcy5oaWdoID0gaGlnaCB8IDA7CiAgICAgICAgdGhpcy51bnNpZ25lZCA9ICEhdW5zaWduZWQ7CiAgICAgIH0KICAgICAgTG9uZzQucHJvdG90eXBlLl9faXNMb25nX187CiAgICAgIE9iamVjdC5kZWZpbmVQcm9wZXJ0eShMb25nNC5wcm90b3R5cGUsICJfX2lzTG9uZ19fIiwgeyB2YWx1ZTogdHJ1ZSB9KTsKICAgICAgZnVuY3Rpb24gaXNMb25nKG9iaikgewogICAgICAgIHJldHVybiAob2JqICYmIG9ialsiX19pc0xvbmdfXyJdKSA9PT0gdHJ1ZTsKICAgICAgfQogICAgICBMb25nNC5pc0xvbmcgPSBpc0xvbmc7CiAgICAgIHZhciBJTlRfQ0FDSEUgPSB7fTsKICAgICAgdmFyIFVJTlRfQ0FDSEUgPSB7fTsKICAgICAgZnVuY3Rpb24gZnJvbUludCh2YWx1ZSwgdW5zaWduZWQpIHsKICAgICAgICB2YXIgb2JqLCBjYWNoZWRPYmosIGNhY2hlOwogICAgICAgIGlmICh1bnNpZ25lZCkgewogICAgICAgICAgdmFsdWUgPj4+PSAwOwogICAgICAgICAgaWYgKGNhY2hlID0gMCA8PSB2YWx1ZSAmJiB2YWx1ZSA8IDI1NikgewogICAgICAgICAgICBjYWNoZWRPYmogPSBVSU5UX0NBQ0hFW3ZhbHVlXTsKICAgICAgICAgICAgaWYgKGNhY2hlZE9iaikKICAgICAgICAgICAgICByZXR1cm4gY2FjaGVkT2JqOwogICAgICAgICAgfQogICAgICAgICAgb2JqID0gZnJvbUJpdHModmFsdWUsICh2YWx1ZSB8IDApIDwgMCA/IC0xIDogMCwgdHJ1ZSk7CiAgICAgICAgICBpZiAoY2FjaGUpCiAgICAgICAgICAgIFVJTlRfQ0FDSEVbdmFsdWVdID0gb2JqOwogICAgICAgICAgcmV0dXJuIG9iajsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgdmFsdWUgfD0gMDsKICAgICAgICAgIGlmIChjYWNoZSA9IC0xMjggPD0gdmFsdWUgJiYgdmFsdWUgPCAxMjgpIHsKICAgICAgICAgICAgY2FjaGVkT2JqID0gSU5UX0NBQ0hFW3ZhbHVlXTsKICAgICAgICAgICAgaWYgKGNhY2hlZE9iaikKICAgICAgICAgICAgICByZXR1cm4gY2FjaGVkT2JqOwogICAgICAgICAgfQogICAgICAgICAgb2JqID0gZnJvbUJpdHModmFsdWUsIHZhbHVlIDwgMCA/IC0xIDogMCwgZmFsc2UpOwogICAgICAgICAgaWYgKGNhY2hlKQogICAgICAgICAgICBJTlRfQ0FDSEVbdmFsdWVdID0gb2JqOwogICAgICAgICAgcmV0dXJuIG9iajsKICAgICAgICB9CiAgICAgIH0KICAgICAgTG9uZzQuZnJvbUludCA9IGZyb21JbnQ7CiAgICAgIGZ1bmN0aW9uIGZyb21OdW1iZXIodmFsdWUsIHVuc2lnbmVkKSB7CiAgICAgICAgaWYgKGlzTmFOKHZhbHVlKSkKICAgICAgICAgIHJldHVybiB1bnNpZ25lZCA/IFVaRVJPIDogWkVSTzsKICAgICAgICBpZiAodW5zaWduZWQpIHsKICAgICAgICAgIGlmICh2YWx1ZSA8IDApCiAgICAgICAgICAgIHJldHVybiBVWkVSTzsKICAgICAgICAgIGlmICh2YWx1ZSA+PSBUV09fUFdSXzY0X0RCTCkKICAgICAgICAgICAgcmV0dXJuIE1BWF9VTlNJR05FRF9WQUxVRTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgaWYgKHZhbHVlIDw9IC1UV09fUFdSXzYzX0RCTCkKICAgICAgICAgICAgcmV0dXJuIE1JTl9WQUxVRTsKICAgICAgICAgIGlmICh2YWx1ZSArIDEgPj0gVFdPX1BXUl82M19EQkwpCiAgICAgICAgICAgIHJldHVybiBNQVhfVkFMVUU7CiAgICAgICAgfQogICAgICAgIGlmICh2YWx1ZSA8IDApCiAgICAgICAgICByZXR1cm4gZnJvbU51bWJlcigtdmFsdWUsIHVuc2lnbmVkKS5uZWcoKTsKICAgICAgICByZXR1cm4gZnJvbUJpdHModmFsdWUgJSBUV09fUFdSXzMyX0RCTCB8IDAsIHZhbHVlIC8gVFdPX1BXUl8zMl9EQkwgfCAwLCB1bnNpZ25lZCk7CiAgICAgIH0KICAgICAgTG9uZzQuZnJvbU51bWJlciA9IGZyb21OdW1iZXI7CiAgICAgIGZ1bmN0aW9uIGZyb21CaXRzKGxvd0JpdHMsIGhpZ2hCaXRzLCB1bnNpZ25lZCkgewogICAgICAgIHJldHVybiBuZXcgTG9uZzQobG93Qml0cywgaGlnaEJpdHMsIHVuc2lnbmVkKTsKICAgICAgfQogICAgICBMb25nNC5mcm9tQml0cyA9IGZyb21CaXRzOwogICAgICB2YXIgcG93X2RibCA9IE1hdGgucG93OwogICAgICBmdW5jdGlvbiBmcm9tU3RyaW5nKHN0ciwgdW5zaWduZWQsIHJhZGl4KSB7CiAgICAgICAgaWYgKHN0ci5sZW5ndGggPT09IDApCiAgICAgICAgICB0aHJvdyBFcnJvcigiZW1wdHkgc3RyaW5nIik7CiAgICAgICAgaWYgKHN0ciA9PT0gIk5hTiIgfHwgc3RyID09PSAiSW5maW5pdHkiIHx8IHN0ciA9PT0gIitJbmZpbml0eSIgfHwgc3RyID09PSAiLUluZmluaXR5IikKICAgICAgICAgIHJldHVybiBaRVJPOwogICAgICAgIGlmICh0eXBlb2YgdW5zaWduZWQgPT09ICJudW1iZXIiKSB7CiAgICAgICAgICByYWRpeCA9IHVuc2lnbmVkLCB1bnNpZ25lZCA9IGZhbHNlOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICB1bnNpZ25lZCA9ICEhdW5zaWduZWQ7CiAgICAgICAgfQogICAgICAgIHJhZGl4ID0gcmFkaXggfHwgMTA7CiAgICAgICAgaWYgKHJhZGl4IDwgMiB8fCAzNiA8IHJhZGl4KQogICAgICAgICAgdGhyb3cgUmFuZ2VFcnJvcigicmFkaXgiKTsKICAgICAgICB2YXIgcDsKICAgICAgICBpZiAoKHAgPSBzdHIuaW5kZXhPZigiLSIpKSA+IDApCiAgICAgICAgICB0aHJvdyBFcnJvcigiaW50ZXJpb3IgaHlwaGVuIik7CiAgICAgICAgZWxzZSBpZiAocCA9PT0gMCkgewogICAgICAgICAgcmV0dXJuIGZyb21TdHJpbmcoc3RyLnN1YnN0cmluZygxKSwgdW5zaWduZWQsIHJhZGl4KS5uZWcoKTsKICAgICAgICB9CiAgICAgICAgdmFyIHJhZGl4VG9Qb3dlciA9IGZyb21OdW1iZXIocG93X2RibChyYWRpeCwgOCkpOwogICAgICAgIHZhciByZXN1bHQgPSBaRVJPOwogICAgICAgIGZvciAodmFyIGkgPSAwOyBpIDwgc3RyLmxlbmd0aDsgaSArPSA4KSB7CiAgICAgICAgICB2YXIgc2l6ZSA9IE1hdGgubWluKDgsIHN0ci5sZW5ndGggLSBpKSwgdmFsdWUgPSBwYXJzZUludChzdHIuc3Vic3RyaW5nKGksIGkgKyBzaXplKSwgcmFkaXgpOwogICAgICAgICAgaWYgKHNpemUgPCA4KSB7CiAgICAgICAgICAgIHZhciBwb3dlciA9IGZyb21OdW1iZXIocG93X2RibChyYWRpeCwgc2l6ZSkpOwogICAgICAgICAgICByZXN1bHQgPSByZXN1bHQubXVsKHBvd2VyKS5hZGQoZnJvbU51bWJlcih2YWx1ZSkpOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcmVzdWx0ID0gcmVzdWx0Lm11bChyYWRpeFRvUG93ZXIpOwogICAgICAgICAgICByZXN1bHQgPSByZXN1bHQuYWRkKGZyb21OdW1iZXIodmFsdWUpKTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmVzdWx0LnVuc2lnbmVkID0gdW5zaWduZWQ7CiAgICAgICAgcmV0dXJuIHJlc3VsdDsKICAgICAgfQogICAgICBMb25nNC5mcm9tU3RyaW5nID0gZnJvbVN0cmluZzsKICAgICAgZnVuY3Rpb24gZnJvbVZhbHVlKHZhbCwgdW5zaWduZWQpIHsKICAgICAgICBpZiAodHlwZW9mIHZhbCA9PT0gIm51bWJlciIpCiAgICAgICAgICByZXR1cm4gZnJvbU51bWJlcih2YWwsIHVuc2lnbmVkKTsKICAgICAgICBpZiAodHlwZW9mIHZhbCA9PT0gInN0cmluZyIpCiAgICAgICAgICByZXR1cm4gZnJvbVN0cmluZyh2YW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dhdGl2ZSgpKSB7CiAgICAgICAgICBpZiAodGhpcy5lcShNSU5fVkFMVUUpKSB7CiAgICAgICAgICAgIHZhciByYWRpeExvbmcgPSBmcm9tTnVtYmVyKHJhZGl4KSwgZGl2ID0gdGhpcy5kaXYocmFkaXhMb25nKSwgcmVtMSA9IGRpdi5tdWwocmFkaXhMb25nKS5zdWIodGhpcyk7CiAgICAgICAgICAgIHJldHVybiBkaXYudG9TdHJpbmcocmFkaXgpICsgcmVtMS50b0ludCgpLnRvU3RyaW5nKHJhZGl4KTsKICAgICAgICAgIH0gZWxzZQogICAgICAgICAgICByZXR1cm4gIi0iICsgdGhpcy5uZWcoKS50b1N0cmluZyhyYWRpeCk7CiAgICAgICAgfQogICAgICAgIHZhciByYWRpeFRvUG93ZXIgPSBmcm9tTnVtYmVyKHBvd19kYmwocmFkaXgsIDYpLCB0aGlzLnVuc2lnbmVkKSwgcmVtID0gdGhpczsKICAgICAgICB2YXIgcmVzdWx0ID0gIiI7CiAgICAgICAgd2hpbGUgKHRydWUpIHsKICAgICAgICAgIHZhciByZW1EaXYgPSByZW0uZGl2KHJhZGl4VG9Qb3dlciksIGludHZhbCA9IHJlbS5zdWIocmVtRGl2Lm11bChyYWRpeFRvUG93ZXIpKS50b0ludCgpID4+PiAwLCBkaWdpdHMgPSBpbnR2YWwudG9TdHJpbmcocmFkaXgpOwogICAgICAgICAgcmVtID0gcmVtRGl2OwogICAgICAgICAgaWYgKHJlbS5pc1plcm8oKSkKICAgICAgICAgICAgcmV0dXJuIGRpZ2l0cyArIHJlc3VsdDsKICAgICAgICAgIGVsc2UgewogICAgICAgICAgICB3aGlsZSAoZGlnaXRzLmxlbmd0aCA8IDYpCiAgICAgICAgICAgICAgZGlnaXRzID0gIjAiICsgZGlnaXRzOwogICAgICAgICAgICByZXN1bHQgPSAiIiArIGRpZ2l0cyArIHJlc3VsdDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUuZ2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4gdGhpcy5oaWdoID09PSAwICYmIHRoaXMubG93ID09PSAwOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLmVxeiA9IExvbmdQcm90b3R5cGUuaXNaZXJvOwogICAgICBMb25nUHJvdG90eXBlLmlzTmVnYXRpdmUgPSBmdW5jdGlvbiBpc05lZ2F0aXZlKCkgewogICAgICAgIHJldHVybiAhdGhpcy51bnNpZ25lZCAmJiB0aGlzLmhpZ2ggPCAwOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLmlzUG9zaXRpdmUgPSBmdW5jdGlvbiBpc1Bvc2l0aXZlKCkgewogICAgICAgIHJldHVybiB0aGlzLnVuc2lnbmVkIHx8IHRoaXMuaGlnaCA+PSAwOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLmlzT2RkID0gZnVuY3Rpb24gaXNPZGQoKSB7CiAgICAgICAgcmV0dXJuICh0aGlzLmxvdyAmIDEpID09PSAxOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLmlzRXZlbiA9IGZ1bmN0aW9uIGlzRXZlbigpIHsKICAgICAgICByZXR1cm4gKHRoaXMubG93ICYgMSkgPT09IDA7CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUuZXF1YWxzID0gZnVuY3Rpb24gZXF1YWxzKG90aGVyKSB7CiAgICAgICAgaWYgKCFpc0xvbmcob3RoZXIpKQogICAgICAgICAgb3RoZXIgPSBmcm9tVmFsdWUob3RoZXIpOwogICAgICAgIGlmICh0aGlzLnVuc2lnbmVkICE9PSBvdGhlci51bnNpZ25lZCAmJiB0aGlzLmhpZ2ggPj4+IDMxID09PSAxICYmIG90aGVyLmhpZ2ggPj4+IDMxID09PSAxKQogICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICAgIHJldHVybiB0aGlzLmhpZ2ggPT09IG90aGVyLmhpZ2ggJiYgdGhpcy5sb3cgPT09IG90aGVyLmxvdzsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS5lcSA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4gMTY7CiAgICAgICAgYzMyICY9IDY1NTM1OwogICAgICAgIGM0OCArPSBhNDggKyBiNDg7CiAgICAgICAgYzQ4ICY9IDY1NTM1OwogICAgICAgIHJldHVybiBmcm9tQml0cyhjMTYgPDwgMTYgfCBjMDAsIGM0OCA8PCAxNiB8IGMzMiwgdGhpcy51bnNpZ25lZCk7CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUuc3VidHJhY3QgPSBmdW5jdGlvbiBzdWJ0cmFjdChzdWJ0cmFoZW5kKSB7CiAgICAgICAgaWYgKCFpc0xvbmcoc3VidHJhaGVuZCkpCiAgICAgICAgICBzdWJ0cmFoZW5kID0gZnJvbVZhbHVlKHN1YnRyYWhlbmQpOwogICAgICAgIHJldHVybiB0aGlzLmFkZChzdWJ0cmFoZW5kLm5lZygpKTsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS5zdWIgPSBMb25nUHJvdG90eXBlLnN1YnRyYWN0OwogICAgICBMb25nUHJvdG90eXBlLm11bHRpcGx5ID0gZnVuY3Rpb24gbXVsdGlwbHkobXVsdGlwbGllcikgewogICAgICAgIGlmICh0aGlzLmlzWmVybygpKQogICAgICAgICAgcmV0dXJuIFpFUk87CiAgICAgICAgaWYgKCFpc0xvbmcobXVsdGlwbGllcikpCiAgICAgICAgICBtdWx0aXBsaWVyID0gZnJvbVZhbHVlKG11bHRpcGxpZXIpOwogICAgICAgIGlmICh3YXNtKSB7CiAgICAgICAgICB2YXIgbG93ID0gd2FzbS5tdWwodGhpcy5sb3csIHRoaXMuaGlnaCwgbXVsdGlwbGllci5sb3csIG11bHRpcGxpZXIuaGlnaCk7CiAgICAgICAgICByZXR1cm4gZnJvbUJpdHMobG93LCB3YXNtLmdldF9oaWdoKCksIHRoaXMudW5zaWduZWQpOwogICAgICAgIH0KICAgICAgICBpZiAobXVsdGlwbGllci5pc1plcm8oKSkKICAgICAgICAgIHJldHVybiBaRVJPOwogICAgICAgIGlmICh0aGlzLmVxKE1JTl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AgaWYgKCFpc0xvbmcoZGl2aXNvcikpCiAgICAgICAgICBkaXZpc29yID0gZnJvbVZhbHVlKGRpdmlzb3IpOwogICAgICAgIGlmIChkaXZpc29yLmlzWmVybygpKQogICAgICAgICAgdGhyb3cgRXJyb3IoImRpdmlzaW9uIGJ5IHplcm8iKTsKICAgICAgICBpZiAod2FzbSkgewogICAgICAgICAgaWYgKCF0aGlzLnVuc2lnbmVkICYmIHRoaXMuaGlnaCA9PT0gLTIxNDc0ODM2NDggJiYgZGl2aXNvci5sb3cgPT09IC0xICYmIGRpdmlzb3IuaGlnaCA9PT0gLTEpIHsKICAgICAgICAgICAgcmV0dXJuIHRoaXM7CiAgICAgICAgICB9CiAgICAgICAgICB2YXIgbG93ID0gKHRoaXMudW5zaWduZWQgPyB3YXNtLmRpdl91IDogd2FzbS5kaXZfcykodGhpcy5sb3csIHRoaXMuaGlnaCwgZGl2aXNvci5sb3csIGRpdmlzb3IuaGlnaCk7CiAgICAgICAgICByZXR1cm4gZnJvbUJpdHMobG93LCB3YXNtLmdldF9oaWdoKCksIHRoaXMudW5zaWduZWQpOwogICAgICAgIH0KICAgICAgICBpZiAodGhpcy5pc1plcm8oKSkKICAgICAgICAgIHJldHVybiB0aGlzLnVuc2lnbmVkID8gVVpFUk8gOiBaRVJPOwogICAgICAgIHZhciBhcHByb3gsIHJlbSwgcmVzOwogICAgICAgIGlmICghdGhpcy51bnNpZ25lZCkgewogICAgICAgICAgaWYgKHRoaXMuZXEoTUlOX1ZBTFVFKSkgewogICAgICAgICAgICBpZiAoZGl2aXNvci5lcShPTkUpIHx8IGRpdmlzb3IuZXEoTkVHX09ORSkpCiAgICAgICAgICAgICAgcmV0dXJuIE1JTl9WQUxVRTsKICAgICAgICAgICAgZWxzZSBpZiAoZGl2aXNvci5lcShNSU5fVkFMVUUpKQogICAgICAgICAgICAgIHJldHVybiBPTkU7CiAgICAgICAgICAgIGVsc2UgewogICAgICAgICAgICAgIHZhciBoYWxmVGhpcyA9IHRoaXMuc2hyKDEpOwogICAgICAgICAgICAgIGFwcHJveCA9IGhhbGZUaGlzLmRpdihkaXZpc29yKS5zaGwoMSk7CiAgICAgICAgICAgICAgaWYgKGFwcHJveC5lcShaRVJPKSkgewogICAgICAgICAgICAgICAgcmV0dXJuIGRpdmlzb3IuaXNOZWdhdGl2ZSgpID8gT05FIDogTkVHX09ORTsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgcmVtID0gdGhpcy5zdWIoZGl2aXNvci5tdWwoYXBwcm94KSk7CiAgICAgICAgICAgICAgICByZXMgPSBhcHByb3guYWRkKHJlbS5kaXYoZGl2aXNvcikpOwogICAgICAgICAgICAgICAgcmV0dXJuIHJlczsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSBpZiAoZGl2aXNvci5lcShNSU5fVkFMVUUpKQogICAgICAgICAgICByZXR1cm4gdGhpcy51bnNpZ25lZCA/IFVaRVJPIDogWkVSTzsKICAgICAgICAgIGlmICh0aGlzLmlzTmVnYXRpdmUoKSkgewogICAgICAgICAgICBpZiAoZGl2aXNvci5pc05lZ2F0aXZlKCkpCiAgICAgICAgICAgICAgcmV0dXJuIHRoaXMubmVnKCkuZGl2KGRpdmlzb3IubmVnKCkpOwogICAgICAgICAgICByZXR1cm4gdGhpcy5uZWcoKS5kaXYoZGl2aXNvcikubmVnKCk7CiAgICAgICAgICB9IGVsc2UgaWYgKGRpdmlzb3IuaXNOZWdhdGl2ZSgpKQogICAgICAgICAgICByZXR1cm4gdGhpcy5kaXYoZGl2aXNvci5uZWcoKSkubmVnKCk7CiAgICAgICAgICByZXMgPSBaRVJPOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBpZiAoIWRpdmlzb3IudW5zaWduZWQpCiAgICAgICAgICAgIGRpdmlzb3IgPSBkaXZpc29yLnRvVW5zaWduZWQoKTsKICAgICAgICAgIGlmIChkaXZpc29yLmd0KHRoaXMpKQogICAgICAgICAgICByZXR1cm4gVVpFUk87CiAgICAgICAgICBpZiAoZGl2aXNvci5ndCh0aGlzLnNocnUoMSkpKQogICAgICAgICAgICByZXR1cm4gVU9ORTsKICAgICAgICAgIHJlcyA9IFVaRVJPOwogICAgICAgIH0KICAgICAgICByZW0gPSB0aGlzOwogICAgICAgIHdoaWxlIChyZW0uZ3RlKGRpdmlzb3IpKSB7CiAgICAgICAgICBhcHByb3ggPSBNYXRoLm1heCgxLCBNYXRoLmZsb29yKHJlbS50b051bWJlcigpIC8gZGl2aXNvci50b051bWJlcigpKSk7CiAgICAgICAgICB2YXIgbG9nMiA9IE1hdGguY2VpbChNYXRoLmxvZyhhcHByb3gpIC8gTWF0aC5MTjIpLCBkZWx0YSA9IGxvZzIgPD0gNDggPyAxIDogcG93X2RibCgyLCBsb2cyIC0gNDgpLCBhcHByb3hSZXMgPSBmcm9tTnVtYmVyKGFwcHJveCksIGFwcHJveFJlbSA9IGFwcHJveFJlcy5tdWwoZGl2aXNvcik7CiAgICAgICAgICB3aGlsZSAoYXBwcm94UmVtLmlzTmVnYXRpdmUoKSB8fCBhcHByb3hSZW0uZ3QocmVtKSkgewogICAgICAgICAgICBhcHByb3ggLT0gZGVsdGE7CiAgICAgICAgICAgIGFwcHJveFJlcyA9IGZyb21OdW1iZXIoYXBwcm94LCB0aGlzLnVuc2lnbmVkKTsKICAgICAgICAgICAgYXBwcm94UmVtID0gYXBwcm94UmVzLm11bChkaXZpc29yKTsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChhcHByb3hSZXMuaXNaZXJvKCkpCiAgICAgICAgICAgIGFwcHJveFJlcyA9IE9ORTsKICAgICAgICAgIHJlcyA9IHJlcy5hZGQoYXBwcm94UmVzKTsKICAgICAgICAgIHJlbSA9IHJlbS5zdWIoYXBwcm94UmVtKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHJlczsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS5kaXYgPSBMb25nUHJvdG90eXBlLmRpdmlkZTsKICAgICAgTG9uZ1Byb3RvdHlwZS5tb2R1bG8gPSBmdW5jdGlvbiBtb2R1bG8oZGl2aXNvcikgewogICAgICAgIGlmICghaXNMb25nKGRpdmlzb3IpKQogICAgICAgICAgZGl2aXNvciA9IGZyb21WYWx1ZShkaXZpc29yKTsKICAgICAgICBpZiAod2FzbSkgewogICAgICAgICAgdmFyIGxvdyA9ICh0aGlzLnVuc2lnbmVkID8gd2FzbS5yZW1fdSA6IHdhc20ucmVtX3MpKHRoaXMubG93LCB0aGlzLmhpZ2gsIGRpdmlzb3IubG93LCBkaXZpc29yLmhpZ2gpOwogICAgICAgICAgcmV0dXJuIGZyb21CaXRzKGxvdywgd2FzbS5nZXRfaGlnaCgpLCB0aGlzLnVuc2lnbmVkKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHRoaXMuc3ViKHRoaXMuZGl2KGRpdmlzb3IpLm11bChkaXZpc29yKSk7CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUubW9kID0gTG9uZ1Byb3RvdHlwZS5tb2R1bG87CiAgICAgIExvbmdQcm90b3R5cGUucmVtID0gTG9uZ1Byb3RvdHlwZS5tb2R1bG87CiAgICAgIExvbmdQcm90b3R5cGUubm90ID0gZnVuY3Rpb24gbm90KCkgewogICAgICAgIHJldHVybiBmcm9tQml0cyh+dGhpcy5sb3csIH50aGlzLmhpZ2gsIHRoaXMudW5zaWduZWQpOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLmFuZCA9IGZ1bmN0aW9uIGFuZChvdGhlcikgewogICAgICAgIGlmICghaXNMb25nKG90aGVyKSkKICAgICAgICAgIG90aGVyID0gZnJvbVZhbHVlKG90aGVyKTsKICAgICAgICByZXR1cm4gZnJvbUJpdHModGhpcy5sb3cgJiBvdGhlci5sb3csIHRoaXMuaGlnaCAmIG90aGVyLmhpZ2gsIHRoaXMudW5zaWduZWQpOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLm9yID0gZnVuY3Rpb24gb3Iob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mdDsKICAgICAgTG9uZ1Byb3RvdHlwZS5zaGlmdFJpZ2h0ID0gZnVuY3Rpb24gc2hpZnRSaWdodChudW1CaXRzKSB7CiAgICAgICAgaWYgKGlzTG9uZyhudW1CaXRzKSkKICAgICAgICAgIG51bUJpdHMgPSBudW1CaXRzLnRvSW50KCk7CiAgICAgICAgaWYgKChudW1CaXRzICY9IDYzKSA9PT0gMCkKICAgICAgICAgIHJldHVybiB0aGlzOwogICAgICAgIGVsc2UgaWYgKG51bUJpdHMgPCAzMikKICAgICAgICAgIHJldHVybiBmcm9tQml0cyh0aGlzLmxvdyA+Pj4gbnVtQml0cyB8IHRoaXMuaGlnaCA8PCAzMiAtIG51bUJpdHMsIHRoaXMuaGlnaCA+PiBudW1CaXRzLCB0aGlzLnVuc2lnbmVkKTsKICAgICAgICBlbHNlCiAgICAgICAgICByZXR1cm4gZnJvbUJpdHModGhpcy5oaWdoID4+IG51bUJpdHMgLSAzMiwgdGhpcy5oaWdoID49IDAgPyAwIDogLTEsIHRoaXMudW5zaWduZWQpOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLnNociA9IExvbmdQcm90b3R5cGUuc2hpZnRSaWdodDsKICAgICAgTG9uZ1Byb3RvdHlwZS5zaGlmdFJpZ2h0VW5zaWduZWQgPSBmdW5jdGlvbiBzaGlmdFJpZ2h0VW5zaWduZWQobnVtQml0cykgewogICAgICAgIGlmIChpc0xvbmcobnVtQml0cykpCiAgICAgICAgICBudW1CaXRzID0gbnVtQml0cy50b0ludCgpOwogICAgICAgIG51bUJpdHMgJj0gNjM7CiAgICAgICAgaWYgKG51bUJpdHMgPT09IDApCiAgICAgICAgICByZXR1cm4gdGhpczsKICAgICAgICBlbHNlIHsKICAgICAgICAgIHZhciBoaWdoID0gdGhpcy5oaWdoOwogICAgICAgICAgaWYgKG51bUJpdHMgPCAzMikgewogICAgICAgICAgICB2YXIgbG93ID0gdGhpcy5sb3c7CiAgICAgICAgICAgIHJldHVybiBmcm9tQml0cyhs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KICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS50b0J5dGVzTEUgPSBmdW5jdGlvbiB0b0J5dGVzTEUoKSB7CiAgICAgICAgdmFyIGhpID0gdGhpcy5oaWdoLCBsbyA9IHRoaXMubG93OwogICAgICAgIHJldHVybiBbCiAgICAgICAgICBsbyAmIDI1NSwKICAgICAgICAgIGxvID4+PiA4ICYgMjU1LAogICAgICAgICAgbG8gPj4+IDE2ICYgMjU1LAogICAgICAgICAgbG8gPj4+IDI0LAogICAgICAgICAgaGkgJiAyNTUsCiAgICAgICAgICBoaSA+Pj4gOCAmIDI1NSwKICAgICAgICAgIGhpID4+PiAxNiAmIDI1NSwKICAgICAgICAgIGhpID4+PiAyNAogICAgICAgIF07CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUudG9CeXRlc0JFID0gZnVuY3Rpb24gdG9CeXRlc0JFKCkgewogICAgICAgIHZhciBoaSA9IHRoaXMuaGlnaCwgbG8gPSB0aGlzLmxvdzsKICAgICAgICByZXR1cm4gWwogICAgICAgICAgaGkgPj4+IDI0LAogICAgICAgICAgaGkgPj4+IDE2ICYgMjU1LAogICAgICAgICAgaGkgPj4+IDggJiAyNTUsCiAgICAgICAgICBoaSAmIDI1NSwKICAgICAgICAgIGxvID4+PiAyNCwKICAgICAgICAgIGxvID4+PiAxNiAmIDI1NSwKICAgICAgICAgIGxvID4+PiA4ICYgMjU1LAogICAgICAgICAgbG8gJiAyNTUKICAgICAgICBdOwogICAgICB9OwogICAgICBMb25nNC5mcm9tQnl0ZXMgPSBmdW5jdGlvbiBmcm9tQnl0ZXMyKGJ5dGVzLCB1bnNpZ25lZCwgbGUpIHsKICAgICAgICByZXR1cm4gbGUgPyBMb25nNC5mcm9tQnl0ZXNMRShieXRlcywgdW5zaWduZWQpIDogTG9uZzQuZnJvbUJ5dGVzQkUoYnl0ZXMsIHVuc2lnbmVkKTsKICAgICAgfTsKICAgICAgTG9uZzQuZnJvbUJ5dGVzTEUgPSBmdW5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4dGVuZC5kZXNlcmlhbGl6ZS5iaW5kKGV4dGVuZCk7CiAgICAgICAgY29uc3QgZmFsbGJhY2tTZXJpYWxpemVyID0gZXh0ZW5kLnNlcmlhbGl6ZS5iaW5kKGV4dGVuZCk7CiAgICAgICAgcmV0dXJuIHsKICAgICAgICAgIGRlc2VyaWFsaXplKG1lc3NhZ2UpIHsKICAgICAgICAgICAgcmV0dXJuIGltcGxlbWVudGF0aW9uLmRlc2VyaWFsaXplKG1lc3NhZ2UsIGZhbGxiYWNrRGVzZXJpYWxpemVyKTsKICAgICAgICAgIH0sCiAgICAgICAgICBzZXJpYWxpemUoaW5wdXQpIHsKICAgICAgICAgICAgcmV0dXJuIGltcGxlbWVudGF0aW9uLnNlcmlhbGl6ZShpbnB1dCwgZmFsbGJhY2tTZXJpYWxpemVyKTsKICAgICAgICAgIH0KICAgICAgICB9OwogICAgICB9CiAgICAgIGV4cG9ydHMyLmV4dGVuZFNlcmlhbGl6ZXIgPSBleHRlbmRTZXJpYWxpemVyOwogICAgICB2YXIgRGVmYXVsdEVycm9yU2VyaWFsaXplciA9IHsKICAgICAgICBkZXNlcmlhbGl6ZShtZXNzYWdlKSB7CiAgICAgICAgICByZXR1cm4gT2JqZWN0LmFzc2lnbihFcnJvcihtZXNzYWdlLm1lc3NhZ2UpLCB7CiAgICAgICAgICAgIG5hbWU6IG1lc3NhZ2UubmFtZSwKICAgICAgICAgICAgc3RhY2s6IG1lc3NhZ2Uuc3RhY2sKICAgICAgICAgIH0pOwogICAgICAgIH0sCiAgICAgICAgc2VyaWFsaXplKGVycm9yKSB7CiAgICAgICAgICByZXR1cm4gewogICAgICAgICAgICBfX2Vycm9yX21hcmtlcjogIiQkZXJyb3IiLAogICAgICAgICAgICBtZXNzYWdlOiBlcnJvci5tZXNzYWdlLAogICAgICAgICAgICBuYW1lOiBlcnJvci5uYW1lLAogICAgICAgICAgICBzdGFjazogZXJyb3Iuc3RhY2sKICAgICAgICAgIH07CiAgICAgICAgfQogICAgICB9OwogICAgICB2YXIgaXNTZXJpYWxpemVkRXJyb3IgPSAodGhpbmcpID0+IHRoaW5nICYmIHR5cGVvZiB0aGluZyA9PT0gIm9iamVjdCIgJiYgIl9fZXJyb3JfbWFya2VyIiBpbiB0aGluZyAmJiB0aGluZy5fX2Vycm9yX21hcmtlciA9PT0gIiQkZXJyb3IiOwogICAgICBleHBvcnRzMi5EZWZhdWx0U2VyaWFsaXplciA9IHsKICAgICAgICBkZXNlcmlhbGl6ZShtZXNzYWdlKSB7CiAgICAgICAgICBpZiAoaXNTZXJpYWxpemVkRXJyb3IobWVzc2FnZSkpIHsKICAgICAgICAgICAgcmV0dXJuIERlZmF1bHRFcnJvclNlcmlhbGl6ZXIuZGVzZXJpYWxpemUobWVzc2FnZSk7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICByZXR1cm4gbWVzc2FnZTsKICAgICAgICAgIH0KICAgICAgICB9LAogICAgICAgIHNlcmlhbGl6ZShpbnB1dCkgewogICAgICAgICAgaWYgKGlucHV0IGluc3RhbmNlb2YgRXJyb3IpIHsKICAgICAgICAgICAgcmV0dXJuIERlZmF1bHRFcnJvclNlcmlhbGl6ZXIuc2VyaWFsaXplKGlucHV0KTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHJldHVybiBpbnB1dDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH07CiAgICB9CiAgfSk7CgogIC8vIG5vZGVfbW9kdWxlcy8ucG5wbS90aHJlYWRzQDEuNy4wL25vZGVfbW9kdWxlcy90aHJlYWRzL2Rpc3QvY29tbW9uLmpzCiAgdmFyIHJlcXVpcmVfY29tbW9uMiA9IF9fY29tbW9uSlMoewogICAgIm5vZGVfbW9kdWxlcy8ucG5wbS90aHJlYWRzQDEuNy4wL25vZGVfbW9kdWxlcy90aHJlYWRzL2Rpc3QvY29tbW9uLmpzIihleHBvcnRzMikgewogICAgICBpbml0X2J1ZmZlcl9zaGltKCk7CiAgICAgICJ1c2Ugc3R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NyaWJlKCh2YWx1ZSkgPT4gcG9zdEpvYlJlc3VsdE1lc3NhZ2Uoam9iVUlELCBmYWxzZSwgY29tbW9uXzEuc2VyaWFsaXplKHZhbHVlKSksIChlcnJvcikgPT4gewogICAgICAgICAgICAgIHBvc3RKb2JFcnJvck1lc3NhZ2Uoam9iVUlELCBjb21tb25fMS5zZXJpYWxpemUoZXJyb3IpKTsKICAgICAgICAgICAgICBhY3RpdmVTdWJzY3JpcHRpb25zLmRlbGV0ZShqb2JVSUQpOwogICAgICAgICAgICB9LCAoKSA9PiB7CiAgICAgICAgICAgICAgcG9zdEpvYlJlc3VsdE1lc3NhZ2Uoam9iVUlELCB0cnVlKTsKICAgICAgICAgICAgICBhY3RpdmVTdWJzY3JpcHRpb25zLmRlbGV0ZShqb2JVSUQpOwogICAgICAgICAgICB9KTsKICAgICAgICAgICAgYWN0aXZlU3Vic2NyaXB0aW9ucy5zZXQoam9iVUlELCBzdWJzY3JpcHRpb24pOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICBjb25zdCByZXN1bHQgPSB5aWVsZCBzeW5jUmVzdWx0OwogICAgICAgICAgICAgIHBvc3RKb2JSZXN1bHRNZXNzYWdlKGpvYlVJRCwgdHJ1ZSwgY29tbW9uXzEuc2VyaWFsaXplKHJlc3VsdCkpOwogICAgICAgICAgICB9IGNhdGNoIChlcnJvcikgewogICAgICAgICAgICAgIHBvc3RKb2JFcnJvck1lc3NhZ2Uoam9iVUlELCBjb21tb25fMS5zZXJpYWxpemUoZXJyb3IpKTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0pOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGV4cG9zZTIoZXhwb3NlZCkgewogICAgICAgIGlmICghaW1wbGVtZW50YXRpb25fMS5kZWZhdWx0LmlzV29ya2VyUnVudGltZSgpKSB7CiAgICAgICAgICB0aHJvdyBFcnJvcigiZXhwb3NlKCkgY2FsbGVkIG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RhdGlvbi5wYXJ0c1tpXSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgcmV0dXJuICJbIiArIChleHBlY3RhdGlvbi5pbnZlcnRlZCA/ICJeIiA6ICIiKSArIGVzY2FwZWRQYXJ0cyArICJdIjsKICAgICAgICAgIH0sCiAgICAgICAgICBhbnk6IGZ1bmN0aW9uKGV4cGVjdGF0aW9uKSB7CiAgICAgICAgICAgIHJldHVybiAiYW55IGNoYXJhY3RlciI7CiAgICAgICAgICB9LAogICAgICAgICAgZW5kOiBmdW5jdGlvbihleHBlY3RhdGlvbikgewogICAgICAgICAgICByZXR1cm4gImVuZCBvZiBpbnB1dCI7CiAgICAgICAgICB9LAogICAgICAgICAgb3RoZXI6IGZ1bmN0aW9uKGV4cGVjdGF0aW9uKSB7CiAgICAgICAgICAgIHJldHVybiBleHBlY3RhdGlvbi5kZXNjcmlwdGlvbjsKICAgICAgICAgIH0KICAgICAgICB9OwogICAgICAgIGZ1bmN0aW9uIGhleChjaCkgewogICAgICAgICAgcmV0dXJuIGNoLmNoYXJDb2RlQXQoMCkudG9TdHJpbmcoMTYpLnRvVXBwZXJDYXNlKCk7CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIGxpdGVyYWxFc2NhcGUocykgewogICAgICAgICAgcmV0dXJuIHMucmVwbGFjZSgvXFwvZywgIlxcXFwiKS5yZXBsYWNlKC8iL2csICdcXCInKS5yZXBsYWNlKC9cMC9nLCAiXFwwIikucmVwbGFjZSgvXHQvZywgIlxcdCIpLnJlcGxhY2UoL1xuL2csICJcXG4iKS5yZXBsYWNlKC9cci9nLCAiXFxyIikucmVwbGFjZSgvW1x4MDAtXHgwRl0vZywgZnVuY3Rpb24oY2gpIHsKICAgICAgICAgICAgcmV0dXJuICJcXHgwIiArIGhleChjaCk7CiAgICAgICAgICB9KS5yZXBsYWNlKC9bXHgxMC1ceDFGXHg3Ri1ceDlGXS9nLCBmdW5jdGlvbihjaCkgewogICAgICAgICAgICByZXR1cm4gIlxceCIgKyBoZXgoY2gpOwogICAgICAgICAgfSk7CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIGNsYXNzRXNjYXBlKHMpIHsKICAgICAgICAgIHJldHVybiBzLnJlcGxhY2UoL1xcL2csICJcXFxcIikucmVwbGFjZSgvXF0vZywgIlxcXSIpLnJlcGxhY2UoL1xeL2csICJcXF4iKS5yZXBsYWNlKC8tL2csICJcXC0iKS5yZXBsYWNlKC9cMC9nLCAiXFwwIikucmVwbGFjZSgvXHQvZywgIlxcdCIpLnJlcGxhY2UoL1xuL2csICJcXG4iKS5yZXBsYWNlKC9cci9nLCAiXFxyIikucmVwbGFjZSgvW1x4MDAtXHgwRl0vZywgZnVuY3Rpb24oY2gpIHsKICAgICAgICAgICAgcmV0dXJuICJcXHgwIiArIGhleChjaCk7CiAgICAgICAgICB9KS5yZXBsYWNlKC9bXHgxMC1ceDFGXHg3Ri1ceDlGXS9nLCBmdW5jdGlvbihjaCkgewogICAgICAgICAgICByZXR1cm4gIlxceCIgKyBoZXgoY2gpOwogICAgICAgICAgfSk7CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIGRlc2NyaWJlRXhwZWN0YXRpb24oZXhwZWN0YXRpb24pIHsKICAgICAgICAgIHJldHVybiBERVNDUklCRV9FWFBFQ1RBVElPTl9GTlNbZXhwZWN0YXRpb24udHlwZV0oZXhwZWN0YXRpb24pOwogICAgICAgIH0KICAgICAgICBmdW5jdGlvbiBkZXNjcmliZUV4cGVjdGVkKGV4cGVjdGVkMikgewogICAgICAgICAgdmFyIGRlc2NyaXB0aW9ucyA9IG5ldyBBcnJheShleHBlY3RlZDIubGVuZ3RoKSwgaSwgajsKICAgICAgICAgIGZvciAoaSA9IDA7IGkgPCBleHBlY3RlZDIubGVuZ3RoOyBpKyspIHsKICAgICAgICAgICAgZGVzY3JpcHRpb25zW2ldID0gZGVzY3JpYmVFeHBlY3RhdGlvbihleHBlY3RlZDJbaV0pOwogICAgICAgICAgfQogICAgICAgICAgZGVzY3JpcHRpb25zLnNvcnQoKTsKICAgICAgICAgIGlmIChkZXNjcmlwdGlvbnMubGVuZ3RoID4gMCkgewogICAgICAgICAgICBmb3IgKGkgPSAxLCBqID0gMTsgaSA8IGRlc2NyaXB0aW9ucy5sZW5ndGg7IGkrKykgewogICAgICAgICAgICAgIGlmIChkZXNjcmlwdGlvbnNbaSAtIDFdICE9PSBkZXNjcmlwdGlvbnNbaV0pIHsKICAgICAgICAgICAgICAgIGRlc2NyaXB0aW9uc1tqXSA9IGRlc2NyaXB0aW9uc1tpXTsKICAgICAgICAgICAgICAgIGorKzsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZGVzY3JpcHRpb25zLmxlbmd0aCA9IGo7CiAgICAgICAgICB9CiAgICAgICAgICBzd2l0Y2ggKGRlc2NyaXB0aW9ucy5sZW5ndGgpIHsKICAgICAgICAgICAgY2FzZSAxOgogICAgICAgICAgICAgIHJldHVybiBkZXNjcmlwdGlvbnNbMF07CiAgICAgICAgICAgIGNhc2UgMjoKICAgICAgICAgICAgICByZXR1cm4gZGVzY3JpcHRpb25zWzBdICsgIiBvciAiICsgZGVzY3JpcHRpb25zWzFdOwogICAgICAgICAgICBkZWZhdWx0OgogICAgICAgICAgICAgIHJldHVybiBkZXNjcmlwdGlvbnMuc2xpY2UoMCwgLTEpLmpvaW4oIiwgIikgKyAiLCBvciAiICsgZGVzY3JpcHRpb25zW2Rlc2NyaXB0aW9ucy5sZW5ndGggLSAxXTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZnVuY3Rpb24gZGVzY3JpYmVGb3VuZChmb3VuZDIpIHsKICAgICAgICAgIHJldHVybiBmb3VuZDIgPyAnIicgKyBsaXRlcmFsRXNjYXBlKGZvdW5kMikgKyAnIicgOiAiZW5kIG9mIGlucHV0IjsKICAgICAgICB9CiAgICAgICAgcmV0dXJuICJFeHBlY3RlZCAiICsgZGVzY3JpYmVFeHBlY3RlZChleHBlY3RlZCkgK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yRwb3NEZXRhaWxzQ2FjaGVbcG9zXSwgcDsKICAgICAgICAgIGlmIChkZXRhaWxzKSB7CiAgICAgICAgICAgIHJldHVybiBkZXRhaWxzOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcCA9IHBvcyAtIDE7CiAgICAgICAgICAgIHdoaWxlICghcGVnJHBvc0RldGFpbHNDYWNoZVtwXSkgewogICAgICAgICAgICAgIHAtLTsKICAgICAgICAgICAgfQogICAgICAgICAgICBkZXRhaWxzID0gcGVnJHBvc0RldGFpbHNDYWNoZVtwXTsKICAgICAgICAgICAgZGV0YWlscyA9IHsKICAgICAgICAgICAgICBsaW5lOiBkZXRhaWxzLmxpbmUsCiAgICAgICAgICAgICAgY29sdW1uOiBkZXRhaWxzLmNvbHVtbgogICAgICAgICAgICB9OwogICAgICAgICAgICB3aGlsZSAocCA8IHBvcykgewogICAgICAgICAgICAgIGlmIChpbnB1dC5jaGFyQ29kZUF0KHApID09PSAxMCkgewogICAgICAgICAgICAgICAgZGV0YWlscy5saW5lKys7CiAgICAgICAgICAgICAgICBkZXRhaWxzLmNvbHVtbiA9IDE7CiAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIGRldGFpbHMuY29sdW1uKys7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIHArKzsKICAgICAgICAgICAgfQogICAgICAgICAgICBwZWckcG9zRGV0YWlsc0NhY2hlW3Bvc10gPSBkZXRhaWxzOwogICAgICAgICAgICByZXR1cm4gZGV0YWlsczsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZnVuY3Rpb24gcGVnJGNvbXB1dGVMb2NhdGlvbihzdGFydFBvcywgZW5kUG9zKSB7CiAgICAgICAgICB2YXIgc3RhcnRQb3NEZXRhaWxzID0gcGVnJGNvbXB1dGVQb3NEZXRhaWxzKHN0YXJ0UG9zKSwgZW5kUG9zRGV0YWlscyA9IHBlZyRjb21wdXRlUG9zRGV0YWlscyhlbmRQb3MpOwogICAgICAgICAgcmV0dXJuIHsKICAgICAgICAgICAgc3RhcnQ6IHsKICAgICAgICAgICAgICBvZmZzZXQ6IHN0YXJ0UG9zLAogICAgICAgICAgICAgIGxpbmU6IHN0YXJ0UG9zRGV0YWlscy5saW5lLAogICAgICAgICAgICAgIGNvbHVtbjogc3RhcnRQb3NEZXRhaWxzLmNvbHVtbgogICAgICAgICAgICB9LAogICAgICAgICAgICBlbmQ6IHsKICAgICAgICAgICAgICBvZmZzZXQ6IGVuZFBvcywKICAgICAgICAgICAgICBsaW5lOiBlbmRQb3NEZXRhaWxzLmxpbmUsCiAgICAgICAgICAgICAgY29sdW1uOiBlbmRQb3NEZXRhaWxzLmNvbHVtbgogICAgICAgICAgICB9CiAgICAgICAgICB9OwogICAgICAgIH0KICAgICAgICBmdW5jdGlvbiBwZWckZmFpbChleHBlY3RlZDIpIHsKICAgICAgICAgIGlmIChwZWckY3VyclBvcyA8IHBlZyRtYXhGYWlsUG9zKSB7CiAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChwZWckY3VyclBvcyA+IHBlZyRtYXhGYWlsUG9zKSB7CiAgICAgICAgICAgIHBlZyRtYXhGYWlsUG9zID0gcGVnJGN1cnJQb3M7CiAgICAgICAgICAgIHBlZyRtYXhGYWlsRXhwZWN0ZWQgPSBbXTsKICAgICAgICAgIH0KICAgICAgICAgIHBlZyRtYXhGYWlsRXhwZWN0ZWQucHVzaChleHBlY3RlZDIpOwogICAgICAgIH0KICAgICAgICBmdW5jdGlvbiBwZWckYnVpbGRTaW1wbGVFcnJvcihtZXNzYWdlLCBsb2NhdGlvbjIpIHsKICAgICAgICAgIHJldHVybiBuZXcgcGVnJFN5bnRheEVycm9yKG1lc3NhZ2UsIG51bGwsIG51bGwsIGxvY2F0aW9uMik7CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIHBlZyRidWlsZFN0cnVjdHVyZWRFcnJvcihleHBlY3RlZDIsIGZvdW5kLCBsb2NhdGlvbjIpIHsKICAgICAgICAgIHJldHVybiBuZXcgcGVnJFN5bnRheEVycm9yKHBlZyRTeW50YXhFcnJvci5idWlsZE1lc3NhZ2UoZXhwZWN0ZWQyLCBmb3VuZCksIGV4cGVjdGVkMiwgZm91bmQsIGxvY2F0aW9uMik7CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIHBlZyRwYXJzZWRlY2xhcmF0aW9uKCkgewogICAgICAgICAgdmFyIHMwLCBzMSwgczIsIHMzLCBzNCwgczUsIHM2LCBzNywgczgsIHM5LCBzMTAsIHMxMSwgczEyLCBzMTM7CiAgICAgICAgICBzMCA9IHBlZyRjdXJyUG9zOwogICAgICAgICAgczEgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICBpZiAoczEgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgczIgPSBwZWckcGFyc2VkZWNsYXJlVHlwZSgpOwogICAgICAgICAgICBpZiAoczIgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICBzMyA9IHBlZyRwYXJzZV8oKTsKICAgICAgICAgICAgICBpZiAoczMgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgIHM0ID0gcGVnJHBhcnNlZGVjbGFyZU5hbWUoKTsKICAgICAgICAgICAgICAgIGlmIChzNCAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICBzNSA9IHBlZyRwYXJzZV8oKTsKICAgICAgICAgICAgICAgICAgaWYgKHM1ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgczYgPSBwZWckcGFyc2Vjb21tZW50KCk7CiAgICAgICAgICAgICAgICAgICAgaWYgKHM2ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgICBzNyA9IHBlZyRwYXJzZV8oKTsKICAgICAgICAgICAgICAgICAgICAgIGlmIChzNyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICBpZiAoaW5wdXQuY2hhckNvZGVBdChwZWckY3VyclBvcykgPT09IDQwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgczggPSBwZWckYzA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICBzOCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGMxKTsKICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHM4ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgczkgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHM5ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMTAgPSBwZWckcGFyc2VmaWVsZExpc3QoKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzMTAgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczExID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoczExICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGlucHV0LmNoYXJDb2RlQXQocGVnJGN1cnJQb3MpID09PSA0MSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczEyID0gcGVnJGMyOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczEyID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGMzKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHMxMiAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczEzID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHMxMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwZWckc2F2ZWRQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczEgPSBwZWckYzQoczIsIHM0LCBzNiwgczEwKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczAgPSBzMTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBzMDsKICAgICAgICB9CiAgICAgICAgZnVuY3Rpb24gcGVnJHBhcnNlZGVjbGFyZVR5cGUoKSB7CiAgICAgICAgICB2YXIgczA7CiAgICAgICAgICBpZiAoaW5wdXQuc3Vic3RyKHBlZyRjdXJyUG9zLCA2KSA9PT0gcGVnJGM1KSB7CiAgICAgICAgICAgIHMwID0gcGVnJGM1OwogICAgICAgICAgICBwZWckY3VyclBvcyArPSA2OwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGM2KTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgaWYgKHMwID09PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDYpID09PSBwZWckYzcpIHsKICAgICAgICAgICAgICBzMCA9IHBlZyRjNzsKICAgICAgICAgICAgICBwZWckY3VyclBvcyArPSA2OwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzgpOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICBpZiAoaW5wdXQuc3Vic3RyKHBlZyRjdXJyUG9zLCA1KSA9PT0gcGVnJGM5KSB7CiAgICAgICAgICAgICAgICBzMCA9IHBlZyRjOTsKICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zICs9IDU7CiAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGMxMCk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gczA7CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIHBlZyRwYXJzZWRlY2xhcmVOYW1lKCkgewogICAgICAgICAgdmFyIHMwLCBzMSwgczIsIHMzOwogICAgICAgICAgczAgPSBwZWckcGFyc2VuYW1lKCk7CiAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgczAgPSBwZWckY3VyclBvczsKICAgICAgICAgICAgczEgPSBwZWckcGFyc2VuYW1lKCk7CiAgICAgICAgICAgIGlmIChzMSAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgIHMyID0gcGVnJHBhcnNlaW5kZXhUeXBlKCk7CiAgICAgICAgICAgICAgaWYgKHMyICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICBzMSA9IFtzMSwgczJdOwogICAgICAgICAgICAgICAgczAgPSBzMTsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHMwID09PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgczAgPSBwZWckY3VyclBvczsKICAgICAgICAgICAgICBzMSA9IHBlZyRwYXJzZW5hbWUoKTsKICAgICAgICAgICAgICBpZiAoczEgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDQpID09PSBwZWckYzExKSB7CiAgICAgICAgICAgICAgICAgIHMyID0gcGVnJGMxMTsKICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gNDsKICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgIHMyID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjMTIpOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoczIgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgczEgPSBbczEsIHMyXTsKICAgICAgICAgICAgICAgICAgczAgPSBzMTsKICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgaWYgKHMwID09PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICBzMCA9IHBlZyRjdXJyUG9zOwogICAgICAgICAgICAgICAgczEgPSBwZWckcGFyc2VuYW1lKCk7CiAgICAgICAgICAgICAgICBpZiAoczEgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgczIgPSBwZWckcGFyc2VpbmRleFR5cGUoKTsKICAgICAgICAgICAgICAgICAgaWYgKHMyICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgaWYgKGlucHV0LnN1YnN0cihwZWckY3VyclBvcywgNCkgPT09IHBlZyRjMTEpIHsKICAgICAgICAgICAgICAgICAgICAgIHMzID0gcGVnJGMxMTsKICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zICs9IDQ7CiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgIHMzID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGMxMik7CiAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGlmIChzMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgczEgPSBbczEsIHMyLCBzM107CiAgICAgICAgICAgICAgICAgICAgICBzMCA9IHMxOwogICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMwOwogICAgICAgICAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMwOwogICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIHMwOwogICAgICAgIH0KICAgICAgICBmdW5jdGlvbiBwZWckcGFyc2VpbmRleFR5cGUoKSB7CiAgICAgICAgICB2YXIgczA7CiAgICAgICAgICBpZiAoaW5wdXQuc3Vic3RyKHBlZyRjdXJyUG9zLCA3KSA9PT0gcGVnJGMxMykgewogICAgICAgICAgICBzMCA9IHBlZyRjMTM7CiAgICAgICAgICAgIHBlZyRjdXJyUG9zICs9IDc7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzE0KTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgaWYgKHMwID09PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDUpID09PSBwZWckYzE1KSB7CiAgICAgICAgICAgICAgczAgPSBwZWckYzE1OwogICAgICAgICAgICAgIHBlZyRjdXJyUG9zICs9IDU7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjMTYpOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICBpZiAoaW5wdXQuc3Vic3RyKHBlZyRjdXJyUG9zLCA2KSA9PT0gcGVnJGMxNykgewogICAgICAgICAgICAgICAgczAgPSBwZWckYzE3OwogICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gNjsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzE4KTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBzMDsKICAgICAgICB9CiAgICAgICAgZnVuY3Rpb24gcGVnJHBhcnNlY29tbWVudCgpIHsKICAgICAgICAgIHZhciBzMDsKICAgICAgICAgIHMwID0gcGVnJHBhcnNlbm9uUXVvdGVkU3RyaW5nKCk7CiAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgczAgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gczA7CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIHBlZyRwYXJzZWZpZWxkTGlzdCgpIHsKICAgICAgICAgIHZhciBzMCwgczEsIHMyLCBzMywgczQsIHM1LCBzNjsKICAgICAgICAgIHMwID0gcGVnJGN1cnJQb3M7CiAgICAgICAgICBzMSA9IHBlZyRwYXJzZWZpZWxkKCk7CiAgICAgICAgICBpZiAoczEgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgczIgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICAgIGlmIChzMiAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgIHMzID0gW107CiAgICAgICAgICAgICAgczQgPSBwZWckY3VyclBvczsKICAgICAgICAgICAgICBzNSA9IHBlZyRwYXJzZV8oKTsKICAgICAgICAgICAgICBpZiAoczUgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgIHM2ID0gcGVnJHBhcnNlZmllbGQoKTsKICAgICAgICAgICAgICAgIGlmIChzNiAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICBwZWckc2F2ZWRQb3MgPSBzNDsKICAgICAgICAgICAgICAgICAgczUgPSBwZWckYzE5KHMxLCBzNik7CiAgICAgICAgICAgICAgICAgIHM0ID0gczU7CiAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHM0OwogICAgICAgICAgICAgICAgICBzNCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczQ7CiAgICAgICAgICAgICAgICBzNCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIHdoaWxlIChzNCAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgczMucHVzaChzNCk7CiAgICAgICAgICAgICAgICBzNCA9IHBlZyRjdXJyUG9zOwogICAgICAgICAgICAgICAgczUgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICAgICAgICBpZiAoczUgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgczYgPSBwZWckcGFyc2VmaWVsZCgpOwogICAgICAgICAgICAgICAgICBpZiAoczYgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICBwZWckc2F2ZWRQb3MgPSBzNDsKICAgICAgICAgICAgICAgICAgICBzNSA9IHBlZyRjMTkoczEsIHM2KTsKICAgICAgICAgICAgICAgICAgICBzNCA9IHM1OwogICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczQ7CiAgICAgICAgICAgICAgICAgICAgczQgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHM0OwogICAgICAgICAgICAgICAgICBzNCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGlmIChzMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgczQgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICAgICAgICBpZiAoczQgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgcGVnJHNhdmVkUG9zID0gczA7CiAgICAgICAgICAgICAgICAgIHMxID0gcGVnJGMyMChzMSwgczMpOwogICAgICAgICAgICAgICAgICBzMCA9IHMxOwogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMwOwogICAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMwOwogICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgfQogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIHMwOwogICAgICAgIH0KICAgICAgICBmdW5jdGlvbiBwZWckcGFyc2Vjb21tZW50U3RhcnQoKSB7CiAgICAgICAgICB2YXIgczA7CiAgICAgICAgICBpZiAoaW5wdXQuY2hhckNvZGVBdChwZWckY3VyclBvcykgPT09IDM1KSB7CiAgICAgICAgICAgIHMwID0gcGVnJGMyMTsKICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjMjIpOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gczA7CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIHBlZyRwYXJzZWludGVybmFsQ29tbWVudCgpIHsKICAgICAgICAgIHZhciBzMCwgczEsIHMyLCBzMywgczQ7CiAgICAgICAgICBzMCA9IHBlZyRjdXJyUG9zOwogICAgICAgICAgczEgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICBpZiAoczEgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgczIgPSBwZWckcGFyc2Vjb21tZW50U3RhcnQoKTsKICAgICAgICAgICAgaWYgKHMyICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgczMgPSBwZWckcGFyc2Vub25RdW90ZWRTdHJpbmcoKTsKICAgICAgICAgICAgICBpZiAoczMgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgIHM0ID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICAgICAgaWYgKHM0ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgIHMxID0gW3MxLCBzMiwgczMsIHM0XTsKICAgICAgICAgICAgICAgICAgczAgPSBzMTsKICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBzMDsKICAgICAgICB9CiAgICAgICAgZnVuY3Rpb24gcGVnJHBhcnNlZmllbGQoKSB7CiAgICAgICAgICB2YXIgczAsIHMxLCBzMiwgczMsIHM0LCBzNSwgczYsIHM3LCBzOCwgczksIHMxMCwgczExLCBzMTIsIHMxMzsKICAgICAgICAgIHMwID0gcGVnJGN1cnJQb3M7CiAgICAgICAgICBzMSA9IHBlZyRwYXJzZWZpZWxkVHlwZSgpOwogICAgICAgICAgaWYgKHMxICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgIHMyID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICBpZiAoczIgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICBzMyA9IHBlZyRwYXJzZW5hbWUoKTsKICAgICAgICAgICAgICBpZiAoczMgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgIHM0ID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICAgICAgaWYgKHM0ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgIGlmIChpbnB1dC5jaGFyQ29kZUF0KHBlZyRjdXJyUG9zKSA9PT0gNTkpIHsKICAgICAgICAgICAgICAgICAgICBzNSA9IHBlZyRjMjM7CiAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICBzNSA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGMyNCk7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChzNSAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgIHM2ID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICAgICAgICAgIGlmIChzNiAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgczcgPSBwZWckcGFyc2Vjb21tZW50KCk7CiAgICAgICAgICAgICAgICAgICAgICBpZiAoczcgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgcGVnJHNhdmVkUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgIHMxID0gcGVnJGMyNShzMSwgczMsIHM3KTsKICAgICAgICAgICAgICAgICAgICAgICAgczAgPSBzMTsKICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChzMCA9PT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICBzMCA9IHBlZyRjdXJyUG9zOwogICAgICAgICAgICBzMSA9IHBlZyRwYXJzZWZpZWxkVHlwZSgpOwogICAgICAgICAgICBpZiAoczEgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICBzMiA9IHBlZyRwYXJzZV8oKTsKICAgICAgICAgICAgICBpZiAoczIgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgIGlmIChpbnB1dC5jaGFyQ29kZUF0KHBlZyRjdXJyUG9zKSA9PT0gOTEpIHsKICAgICAgICAgICAgICAgICAgczMgPSBwZWckYzI2OwogICAgICAgICAgICAgICAgICBwZWckY3VyclBvcysrOwogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgczMgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGMyNyk7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmIChzMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICBzNCA9IHBlZyRwYXJzZV8oKTsKICAgICAgICAgICAgICAgICAgaWYgKHM0ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgczUgPSBwZWckcGFyc2VmaWVsZFNpemUoKTsKICAgICAgICAgICAgICAgICAgICBpZiAoczUgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgIHM2ID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICAgICAgICAgICAgaWYgKHM2ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChpbnB1dC5jaGFyQ29kZUF0KHBlZyRjdXJyUG9zKSA9PT0gOTMpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICBzNyA9IHBlZyRjMjg7CiAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICBzNyA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGMyOSk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzNyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgIHM4ID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzOCAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgczkgPSBwZWckcGFyc2VuYW1lKCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoczkgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczEwID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoczEwICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGlucHV0LmNoYXJDb2RlQXQocGVnJGN1cnJQb3MpID09PSA1OSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczExID0gcGVnJGMyMzsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zKys7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMxMSA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjMjQpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoczExICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMTIgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoczEyICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMxMyA9IHBlZyRwYXJzZWNvbW1lbnQoKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHMxMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRzYXZlZFBvcyA9IHMwOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMxID0gcGVnJGMzMChzMSwgczUsIHM5LCBzMTMpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gczE7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHMwID09PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgczAgPSBwZWckY3VyclBvczsKICAgICAgICAgICAgICBzMSA9IHBlZyRwYXJzZWZpZWxkVHlwZSgpOwogICAgICAgICAgICAgIGlmIChzMSAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgczIgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICAgICAgICBpZiAoczIgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgaWYgKGlucHV0LmNoYXJDb2RlQXQocGVnJGN1cnJQb3MpID09PSA0MCkgewogICAgICAgICAgICAgICAgICAgIHMzID0gcGVnJGMwOwogICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zKys7CiAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgczMgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjMSk7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChzMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgIHM0ID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICAgICAgICAgIGlmIChzNCAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgczUgPSBwZWckcGFyc2VmaWVsZFZhbHVlcygpOwogICAgICAgICAgICAgICAgICAgICAgaWYgKHM1ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHM2ID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICAgICAgICAgICAgICBpZiAoczYgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoaW5wdXQuY2hhckNvZGVBdChwZWckY3VyclBvcykgPT09IDQxKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzNyA9IHBlZyRjMjsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zKys7CiAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHM3ID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGMzKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHM3ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzOCA9IHBlZyRwYXJzZV8oKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzOCAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzOSA9IHBlZyRwYXJzZW5hbWUoKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHM5ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczEwID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzMTAgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChpbnB1dC5jaGFyQ29kZUF0KHBlZyRjdXJyUG9zKSA9PT0gNTkpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczExID0gcGVnJGMyMzsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMxMSA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzI0KTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHMxMSAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMTIgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzMTIgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMTMgPSBwZWckcGFyc2Vjb21tZW50KCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHMxMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJHNhdmVkUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMSA9IHBlZyRjMzEoczEsIHM1LCBzOSwgczEzKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gczE7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMwOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMwOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMwOwogICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMwOwogICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGlmIChzMCA9PT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgczAgPSBwZWckcGFyc2VpbnRlcm5hbENvbW1lbnQoKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBzMDsKICAgICAgICB9CiAgICAgICAgZnVuY3Rpb24gcGVnJHBhcnNlZmllbGRWYWx1ZXMoKSB7CiAgICAgICAgICB2YXIgczAsIHMxLCBzMiwgczMsIHM0LCBzNSwgczY7CiAgICAgICAgICBzMCA9IHBlZyRjdXJyUG9zOwogICAgICAgICAgczEgPSBwZWckcGFyc2VuYW1lKCk7CiAgICAgICAgICBpZiAoczEgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgczIgPSBbXTsKICAgICAgICAgICAgczMgPSBwZWckY3VyclBvczsKICAgICAgICAgICAgaWYgKGlucHV0LmNoYXJDb2RlQXQocGVnJGN1cnJQb3MpID09PSA0NCkgewogICAgICAgICAgICAgIHM0ID0gcGVnJGMzMjsKICAgICAgICAgICAgICBwZWckY3VyclBvcysrOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHM0ID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzMzKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHM0ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgczUgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICAgICAgaWYgKHM1ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICBzNiA9IHBlZyRwYXJzZW5hbWUoKTsKICAgICAgICAgICAgICAgIGlmIChzNiAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICBwZWckc2F2ZWRQb3MgPSBzMzsKICAgICAgICAgICAgICAgICAgczQgPSBwZWckYzE5KHMxLCBzNik7CiAgICAgICAgICAgICAgICAgIHMzID0gczQ7CiAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMzOwogICAgICAgICAgICAgICAgICBzMyA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczM7CiAgICAgICAgICAgICAgICBzMyA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczM7CiAgICAgICAgICAgICAgczMgPSBwZWckRkFJTEVEOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHdoaWxlIChzMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgIHMyLnB1c2goczMpOwogICAgICAgICAgICAgIHMzID0gcGVnJGN1cnJQb3M7CiAgICAgICAgICAgICAgaWYgKGlucHV0LmNoYXJDb2RlQXQocGVnJGN1cnJQb3MpID09PSA0NCkgewogICAgICAgICAgICAgICAgczQgPSBwZWckYzMyOwogICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgczQgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzMzKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgaWYgKHM0ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICBzNSA9IHBlZyRwYXJzZV8oKTsKICAgICAgICAgICAgICAgIGlmIChzNSAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICBzNiA9IHBlZyRwYXJzZW5hbWUoKTsKICAgICAgICAgICAgICAgICAgaWYgKHM2ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgcGVnJHNhdmVkUG9zID0gczM7CiAgICAgICAgICAgICAgICAgICAgczQgPSBwZWckYzE5KHMxLCBzNik7CiAgICAgICAgICAgICAgICAgICAgczMgPSBzNDsKICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMzOwogICAgICAgICAgICAgICAgICAgIHMzID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMzsKICAgICAgICAgICAgICAgICAgczMgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMzOwogICAgICAgICAgICAgICAgczMgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoczIgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICBwZWckc2F2ZWRQb3MgPSBzMDsKICAgICAgICAgICAgICBzMSA9IHBlZyRjMzQoczEsIHMyKTsKICAgICAgICAgICAgICBzMCA9IHMxOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBwZWckY3VyclBvcyA9IHMwOwogICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gczA7CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIHBlZyRwYXJzZWZpZWxkVHlwZSgpIHsKICAgICAgICAgIHZhciBzMCwgczEsIHMyLCBzMzsKICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDMpID09PSBwZWckYzM1KSB7CiAgICAgICAgICAgIHMwID0gcGVnJGMzNTsKICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gMzsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjMzYpOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgaWYgKGlucHV0LnN1YnN0cihwZWckY3VyclBvcywgNCkgPT09IHBlZyRjMzcpIHsKICAgICAgICAgICAgICBzMCA9IHBlZyRjMzc7CiAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gNDsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGMzOCk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzMCA9PT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDUpID09PSBwZWckYzM5KSB7CiAgICAgICAgICAgICAgICBzMCA9IHBlZyRjMzk7CiAgICAgICAgICAgICAgICBwZWckY3VyclBvcyArPSA1OwogICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjNDApOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDYpID09PSBwZWckYzQxKSB7CiAgICAgICAgICAgICAgICAgIHMwID0gcGVnJGM0MTsKICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gNjsKICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjNDIpOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgaWYgKGlucHV0LnN1YnN0cihwZWckY3VyclBvcywgNCkgPT09IHBlZyRjNDMpIHsKICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRjNDM7CiAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gNDsKICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGM0NCk7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChzMCA9PT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDUpID09PSBwZWckYzQ1KSB7CiAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRjNDU7CiAgICAgICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyArPSA1OwogICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjNDYpOwogICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDUpID09PSBwZWckYzQ3KSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJGM0NzsKICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gNTsKICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjNDgpOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGlucHV0LnN1YnN0cihwZWckY3VyclBvcywgNCkgPT09IHBlZyRjNDkpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRjNDk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gNDsKICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGM1MCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzMCA9PT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDYpID09PSBwZWckYzUxKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRjNTE7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyArPSA2OwogICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjNTIpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDcpID09PSBwZWckYzUzKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJGM1MzsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gNzsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjNTQpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGlucHV0LnN1YnN0cihwZWckY3VyclBvcywgNCkgPT09IHBlZyRjNTUpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRjNTU7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gNDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGM1Nik7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzMCA9PT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDYpID09PSBwZWckYzU3KSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRjNTc7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyArPSA2OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjNTgpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDYpID09PSBwZWckYzU5KSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJGM1OTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gNjsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjNjApOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGlucHV0LnN1YnN0cihwZWckY3VyclBvcywgMykgPT09IHBlZyRjNjEpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRjNjE7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gMzsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGM2Mik7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzMCA9PT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJGN1cnJQb3M7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczEgPSBwZWckcGFyc2VkZWNsYXJlVHlwZSgpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzMSAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczIgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoczIgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczMgPSBwZWckcGFyc2VkZWNsYXJlTmFtZSgpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoczMgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwZWckc2F2ZWRQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMSA9IHBlZyRjNjMoczEsIHMzKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHMxOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMwOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gczA7CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIHBlZyRwYXJzZWZpZWxkU2l6ZSgpIHsKICAgICAgICAgIHZhciBzMDsKICAgICAgICAgIHMwID0gcGVnJHBhcnNlbnVtYmVyKCk7CiAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgczAgPSBwZWckcGFyc2VuYW1lKCk7CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gczA7CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIHBlZyRwYXJzZW5hbWUoKSB7CiAgICAgICAgICB2YXIgczAsIHMxLCBzMiwgczMsIHM0OwogICAgICAgICAgczAgPSBwZWckY3VyclBvczsKICAgICAgICAgIHMxID0gcGVnJGN1cnJQb3M7CiAgICAgICAgICBpZiAocGVnJGM2NC50ZXN0KGlucHV0LmNoYXJBdChwZWckY3VyclBvcykpKSB7CiAgICAgICAgICAgIHMyID0gaW5wdXQuY2hhckF0KHBlZyRjdXJyUG9zKTsKICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHMyID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjNjUpOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoczIgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgczMgPSBbXTsKICAgICAgICAgICAgaWYgKHBlZyRjNjYudGVzdChpbnB1dC5jaGFyQXQocGVnJGN1cnJQb3MpKSkgewogICAgICAgICAgICAgIHM0ID0gaW5wdXQuY2hhckF0KHBlZyRjdXJyUG9zKTsKICAgICAgICAgICAgICBwZWckY3VyclBvcysrOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHM0ID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzY3KTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgd2hpbGUgKHM0ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgczMucHVzaChzNCk7CiAgICAgICAgICAgICAgaWYgKHBlZyRjNjYudGVzdChpbnB1dC5jaGFyQXQocGVnJGN1cnJQb3MpKSkgewogICAgICAgICAgICAgICAgczQgPSBpbnB1dC5jaGFyQXQocGVnJGN1cnJQb3MpOwogICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgczQgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzY3KTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHMzICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgczIgPSBbczIsIHMzXTsKICAgICAgICAgICAgICBzMSA9IHMyOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczE7CiAgICAgICAgICAgICAgczEgPSBwZWckRkFJTEVEOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBwZWckY3VyclBvcyA9IHMxOwogICAgICAgICAgICBzMSA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoczEgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgcGVnJHNhdmVkUG9zID0gczA7CiAgICAgICAgICAgIHMxID0gcGVnJGM2OChzMSk7CiAgICAgICAgICB9CiAgICAgICAgICBzMCA9IHMxOwogICAgICAgICAgcmV0dXJuIHMwOwogICAgICAgIH0KICAgICAgICBmdW5jdGlvbiBwZWckcGFyc2VxdW90ZWRTdHJpbmcoKSB7CiAgICAgICAgICB2YXIgczAsIHMxLCBzMiwgczM7CiAgICAgICAgICBzMCA9IHBlZyRjdXJyUG9zOwogICAgICAgICAgaWYgKGlucHV0LmNoYXJDb2RlQXQocGVnJGN1cnJQb3MpID09PSAzNCkgewogICAgICAgICAgICBzMSA9IHBlZyRjNjk7CiAgICAgICAgICAgIHBlZyRjdXJyUG9zKys7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBzMSA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzcwKTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgaWYgKHMxICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgIHMyID0gW107CiAgICAgICAgICAgIGlmIChwZWckYzcxLnRlc3QoaW5wdXQuY2hhckF0KHBlZyRjdXJyUG9zKSkpIHsKICAgICAgICAgICAgICBzMyA9IGlucHV0LmNoYXJBdChwZWckY3VyclBvcyk7CiAgICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICBzMyA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGM3Mik7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIHdoaWxlIChzMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgIHMyLnB1c2goczMpOwogICAgICAgICAgICAgIGlmIChwZWckYzcxLnRlc3QoaW5wdXQuY2hhckF0KHBlZyRjdXJyUG9zKSkpIHsKICAgICAgICAgICAgICAgIHMzID0gaW5wdXQuY2hhckF0KHBlZyRjdXJyUG9zKTsKICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zKys7CiAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIHMzID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGM3Mik7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzMiAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgIGlmIChpbnB1dC5jaGFyQ29kZUF0KHBlZyRjdXJyUG9zKSA9PT0gMzQpIHsKICAgICAgICAgICAgICAgIHMzID0gcGVnJGM2OTsKICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zKys7CiAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIHMzID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGM3MCk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGlmIChzMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgcGVnJHNhdmVkUG9zID0gczA7CiAgICAgICAgICAgICAgICBzMSA9IHBlZyRjNzMoczIpOwogICAgICAgICAgICAgICAgczAgPSBzMTsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBzMDsKICAgICAgICB9CiAgICAgICAgZnVuY3Rpb24gcGVnJHBhcnNlbm9uUXVvdGVkU3RyaW5nKCkgewogICAgICAgICAgdmFyIHMwLCBzMSwgczI7CiAgICAgICAgICBzMCA9IHBlZyRjdXJyUG9zOwogICAgICAgICAgczEgPSBbXTsKICAgICAgICAgIGlmIChwZWckYzc0LnRlc3QoaW5wdXQuY2hhckF0KHBlZyRjdXJyUG9zKSkpIHsKICAgICAgICAgICAgczIgPSBpbnB1dC5jaGFyQXQocGVnJGN1cnJQb3MpOwogICAgICAgICAgICBwZWckY3VyclBvcysrOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgczIgPSBwZWckRkFJTEVEOwogICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGM3NSk7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIHdoaWxlIChzMiAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICBzMS5wdXNoKHMyKTsKICAgICAgICAgICAgaWYgKHBlZyRjNzQudGVzdChpbnB1dC5jaGFyQXQocGVnJGN1cnJQb3MpKSkgewogICAgICAgICAgICAgIHMyID0gaW5wdXQuY2hhckF0KHBlZyRjdXJyUG9zKTsKICAgICAgICAgICAgICBwZWckY3VyclBvcysrOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHMyID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzc1KTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGlmIChzMSAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICBwZWckc2F2ZWRQb3MgPSBzMDsKICAgICAgICAgICAgczEgPSBwZWckYzc2KHMxKTsKICAgICAgICAgIH0KICAgICAgICAgIHMwID0gczE7CiAgICAgICAgICByZXR1cm4gczA7CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIHBlZyRwYXJzZW51bWJlcigpIHsKICAgICAgICAgIHZhciBzMCwgczEsIHMyLCBzMzsKICAgICAgICAgIHBlZyRzaWxlbnRGYWlscysrOwogICAgICAgICAgczAgPSBwZWckY3VyclBvczsKICAgICAgICAgIHMxID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgaWYgKHMxICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgIHMyID0gW107CiAgICAgICAgICAgIGlmIChwZWckYzc4LnRlc3QoaW5wdXQuY2hhckF0KHBlZyRjdXJyUG9zKSkpIHsKICAgICAgICAgICAgICBzMyA9IGlucHV0LmNoYXJBdChwZWckY3VyclBvcyk7CiAgICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICBzMyA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGM3OSk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgIHdoaWxlIChzMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgczIucHVzaChzMyk7CiAgICAgICAgICAgICAgICBpZiAocGVnJGM3OC50ZXN0KGlucHV0LmNoYXJBdChwZWckY3VyclBvcykpKSB7CiAgICAgICAgICAgICAgICAgIHMzID0gaW5wdXQuY2hhckF0KHBlZyRjdXJyUG9zKTsKICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgIHMzID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjNzkpOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHMyID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoczIgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICBwZWckc2F2ZWRQb3MgPSBzMDsKICAgICAgICAgICAgICBzMSA9IHBlZyRjODAoKTsKICAgICAgICAgICAgICBzMCA9IHMxOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBwZWckY3VyclBvcyA9IHMwOwogICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICB9CiAgICAgICAgICBwZWckc2lsZW50RmFpbHMtLTsKICAgICAgICAgIGlmIChzMCA9PT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICBzMSA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzc3KTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIHMwOwogICAgICAgIH0KICAgICAgICBmdW5jdGlvbiBwZWckcGFyc2VfKCkgewogICAgICAgICAgdmFyIHMwLCBzMTsKICAgICAgICAgIHBlZyRzaWxlbnRGYWlscysrOwogICAgICAgICAgczAgPSBbXTsKICAgICAgICAgIGlmIChwZWckYzgyLnRlc3QoaW5wdXQuY2hhckF0KHBlZyRjdXJyUG9zKSkpIHsKICAgICAgICAgICAgczEgPSBpbnB1dC5jaGFyQXQocGVnJGN1cnJQb3MpOwogICAgICAgICAgICBwZWckY3VyclBvcysrOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgczEgPSBwZWckRkFJTEVEOwogICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGM4Myk7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIHdoaWxlIChzMSAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICBzMC5wdXNoKHMxKTsKICAgICAgICAgICAgaWYgKHBlZyRjODIudGVzdChpbnB1dC5jaGFyQXQocGVnJGN1cnJQb3MpKSkgewogICAgICAgICAgICAgIHMxID0gaW5wdXQuY2hhckF0KHBlZyRjdXJyUG9zKTsKICAgICAgICAgICAgICBwZWckY3VyclBvcysrOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHMxID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzgzKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIHBlZyRzaWxlbnRGYWlscy0tOwogICAgICAgICAgaWYgKHMwID09PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgIHMxID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjODEpOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gczA7CiAgICAgICAgfQogICAgICAgIHBlZyRyZXN1bHQgPSBwZWckc3RhcnRSdWxlRnVuY3Rpb24oKTsKICAgICAgICBpZiAocGVnJHJlc3VsdCAhPT0gcGVnJEZBSUxFRCAmJiBwZWckY3VyclBvcyA9PT0gaW5wdXQubGVuZ3RoKSB7CiAgICAgICAgICByZXR1cm4gcGVnJHJlc3VsdDsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgaWYgKHBlZyRyZXN1bHQgIT09IHBlZyRGQUlMRUQgJiYgcGVnJGN1cnJQb3MgPCBpbnB1dC5sZW5ndGgpIHsKICAgICAgICAgICAgcGVnJGZhaWwocGVnJGVuZEV4cGVjdGF0aW9uKCkpOwogICAgICAgICAgfQogIC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vbnNlID0gYXdhaXQgdGhpcy5mZXRjaEltcGxlbWVudGF0aW9uKGlucHV0LCB7CiAgICAgICAgICAgIC4uLmluaXQyLAogICAgICAgICAgICBjYWNoZTogInJlbG9hZCIKICAgICAgICAgIH0pOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICB0aHJvdyBlOwogICAgICAgIH0KICAgICAgfQogICAgICByZXR1cm4gcmVzcG9uc2U7CiAgICB9CiAgICBhc3luYyByZWFkKGJ1ZmZlciwgb2Zmc2V0ID0gMCwgbGVuZ3RoLCBwb3NpdGlvbiA9IDAsIG9wdHMgPSB7fSkgewogICAgICBjb25zdCB7IGhlYWRlcnMgPSB7fSwgc2lnbmFsLCBvdmVycmlkZXMgPSB7fSB9ID0gb3B0czsKICAgICAgaWYgKGxlbmd0aCA8IEluZmluaXR5KSB7CiAgICAgICAgaGVhZGVycy5yYW5nZSA9IGBieXRlcz0ke3Bvc2l0aW9ufS0ke3Bvc2l0aW9uICsgbGVuZ3RofWA7CiAgICAgIH0gZWxzZSBpZiAobGVuZ3RoID09PSBJbmZpbml0eSAmJiBwb3NpdGlvbiAhPT0gMCkgewogICAgICAgIGhlYWRlcnMucmFuZ2UgPSBgYnl0ZXM9JHtwb3NpdGlvbn0tYDsKICAgICAgfQogICAgICBjb25zdCBhcmdzID0gewogICAgICAgIC4uLnRoaXMuYmFzZU92ZXJyaWRlcywKICAgICAgICAuLi5vdmVycmlkZXMsCiAgICAgICAgaGVhZGVyczogewogICAgICAgICAgLi4uaGVhZGVycywKICAgICAgICAgIC4uLm92ZXJyaWRlcy5oZWFkZXJzLAogICAgICAgICAgLi4udGhpcy5iYXNlT3ZlcnJpZGVzLmhlYWRlcnMKICAgICAgICB9LAogICAgICAgIG1ldGhvZDogIkdFVCIsCiAgICAgICAgcmVkaXJlY3Q6ICJmb2xsb3ciLAogICAgICAgIG1vZGU6ICJjb3JzIiwKICAgICAgICBzaWduYWwKICAgICAgfTsKICAgICAgY29uc3QgcmVzcG9uc2Ug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ICAgIH0KICB9CiAgYXN5bmMgZnVuY3Rpb24gdW56aXBDaHVua1NsaWNlKGlucHV0RGF0YSwgY2h1bmspIHsKICAgIHRyeSB7CiAgICAgIGxldCBzdHJtOwogICAgICBjb25zdCB7IG1pbnYsIG1heHYgfSA9IGNodW5rOwogICAgICBsZXQgY3BvcyA9IG1pbnYuYmxvY2tQb3NpdGlvbjsKICAgICAgbGV0IGRwb3MgPSBtaW52LmRhdGFQb3NpdGlvbjsKICAgICAgY29uc3QgY2h1bmtzID0gW107CiAgICAgIGNvbnN0IGNwb3NpdGlvbnMgPSBbXTsKICAgICAgY29uc3QgZHBvc2l0aW9ucyA9IFtdOwogICAgICBsZXQgdG90YWxTaXplID0gMDsKICAgICAgbGV0IGkgPSAwOwogICAgICBkbyB7CiAgICAgICAgY29uc3QgcmVtYWluaW5nSW5wdXQgPSBpbnB1dERhdGEuc3ViYXJyYXkoY3BvcyAtIG1pbnYuYmxvY2tQb3NpdGlvbik7CiAgICAgICAgY29uc3QgaW5mbGF0b3IgPSBuZXcgaW1wb3J0X3Bha28uSW5mbGF0ZSgpOwogICAgICAgICh7IHN0cm0gfSA9IGluZmxhdG9yKTsKICAgICAgICBpbmZsYXRvci5wdXNoKHJlbWFpbmluZ0lucHV0LCBpbXBvcnRfcGFrby5aX1NZTkNfRkxVU0gpOwogICAgICAgIGlmIChpbmZsYXRvci5lcnIpIHsKICAgICAgICAgIHRocm93IG5ldyBFcnJvcihpbmZsYXRvci5tc2cpOwogICAgICAgIH0KICAgICAgICBjb25zdCBidWZmZXIyID0gaW5mbGF0b3IucmVzdWx0OwogICAgICAgIGNodW5rcy5wdXNoKGJ1ZmZlcjIpOwogICAgICAgIGxldCBsZW4gPSBidWZmZXIyLmxlbmd0aDsKICAgICAgICBjcG9zaXRpb25zLnB1c2goY3Bvcyk7CiAgICAgICAgZHBvc2l0aW9ucy5wdXNoKGRwb3MpOwogICAgICAgIGlmIChjaHVua3MubGVuZ3RoID09PSAxICYmIG1pbnYuZ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gICByZXR1cm4gZGlmOwogICAgICB9IGVsc2UgewogICAgICAgIHJldHVybiBjMC5taW52LmRhdGFQb3NpdGlvbiAtIGMxLm1pbnYuZGF0YVBvc2l0aW9uOwogICAgICB9CiAgICB9KTsKICAgIGNodW5rcy5mb3JFYWNoKChjaHVuaykgPT4gewogICAgICBpZiAoIWxvd2VzdCB8fCBjaHVuay5tYXh2LmNvbXBhcmVUbyhsb3dlc3QpID4gMCkgewogICAgICAgIGlmIChsYXN0Q2h1bmsgPT09IG51bGwpIHsKICAgICAgICAgIG1lcmdlZENodW5rcy5wdXNoKGNodW5rKTsKICAgICAgICAgIGxhc3RDaHVuayA9IGNodW5rOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBpZiAoY2FuTWVyZ2VCbG9ja3MobGFzdENodW5rLCBjaHVuaykpIHsKICAgICAgICAgICAgaWYgKGNodW5rLm1heHYuY29tcGFyZVRvKGxhc3RDaHVuay5tYXh2KSA+IDApIHsKICAgICAgICAgICAgICBsYXN0Q2h1bmsubWF4diA9IGNodW5rLm1heHY7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIG1lcmdlZENodW5rcy5wdXNoKGNodW5rKTsKICAgICAgICAgICAgbGFzdENodW5rID0gY2h1bms7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9CiAgICB9KTsKICAgIHJldHVybiBtZXJnZWRDaHVua3M7CiAgfQoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vQGdtb2QrdGFiaXhAMS41LjExL25vZGVfbW9kdWxlcy9AZ21vZC90YWJpeC9lc20vdGJpLmpzCiAgaW5pdF9idWZmZXJfc2hpbSgpOwogIHZhciBpbXBvcnRfbG9uZzIgPSBfX3RvTW9kdWxlKHJlcXVpcmVfbG9uZygpKTsKCiAgLy8gbm9kZV9tb2R1bGVzLy5wbnBtL0BnbW9kK3RhYml4QDEuNS4xMS9ub2RlX21vZHVsZXMvQGdtb2QvdGFiaXgvZXNtL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AgICB9CiAgICB9CiAgICBhc3luYyBwYXJzZShvcHRzID0ge30pIHsKICAgICAgaWYgKCF0aGlzLnBhcnNlUCkgewogICAgICAgIHRoaXMucGFyc2VQID0gdGhpcy5fcGFyc2Uob3B0cykuY2F0Y2goKGUpID0+IHsKICAgICAgICAgIHRoaXMucGFyc2VQID0gdm9pZCAwOwogICAgICAgICAgdGhyb3cgZTsKICAgICAgICB9KTsKICAgICAgfQogICAgICByZXR1cm4gdGhpcy5wYXJzZVA7CiAgICB9CiAgICBhc3luYyBoYXNSZWZTZXEoc2VxSWQsIG9wdHMgPSB7fSkgewogICAgICByZXR1cm4gISEoKGF3YWl0IHRoaXMucGFyc2Uob3B0cykpLmluZGljZXNbc2VxSWRdIHx8IHt9KS5iaW5JbmRleDsKICAgIH0KICB9OwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vQGdtb2QrdGFiaXhAMS41LjExL25vZGVfbW9kdWxlcy9AZ21vZC90YWJpeC9lc20vdGJpLmpzCiAgdmFyIFRCSV9NQUdJQyA9IDIxNTc4MzI0OwogIHZhciBUQURfTElEWF9TSElGVCA9IDE0OwogIGZ1bmN0aW9uIHJlZzJiaW5zKGJlZywgZW5kKSB7CiAgICBiZWcgKz0gMTsKICAgIGVuZCAtPSAxOwogICAgcmV0dXJuIFsKICAgICAgWzAsIDBdLAogICAgICBbMSArIChiZWcgPj4gMjYpLCAxICsgKGVuZCA+PiAyNildLAogICAgICBbOSArIChiZWcgPj4gMjMpLCA5ICsgKGVuZCA+PiAyMyldLAogICAgICBbNzMgKyAoYmVnID4+IDIwKSwgNzMgKyAoZW5kID4+IDIwKV0sCiAgICAgIFs1ODUgKyAoYmVnID4+IDE3KSwgNTg1ICsgKGVuZCA+PiAxNyldLAogICAgICBbNDY4MSArIChiZWcgPj4gMTQpLCA0NjgxICsgKGVuZCA+PiAxNCldCiAgICBdOwogIH0KICB2YXIgVGFiaXhJbmRleCA9IGNsYXNzIGV4dGVuZHMgSW5kZXhGaWxlIHsKICAgIGFzeW5jIGxpbmVDb3VudChyZWZOYW1lLCBvcHRzID0ge30pIHsKICAgICAgY29uc3QgaW5kZXhEYXRhID0gYXdhaXQgdGhpcy5wYXJzZShvcHRzKTsKICAgICAgaWYgKCFpbmRleERhdGEpIHsKICAgICAgICByZXR1cm4gLTE7CiAgICAgIH0KICAgICAgY29uc3QgcmVmSWQgPSBpbmRleERhdGEucmVmTmFtZVRvSWRbcmVmTmFtZV07CiAgICAgIGNvbnN0IGlkeCA9IGluZGV4RGF0YS5pbmRpY2VzW3JlZklkXTsKICAgICAgaWYgKCFpZHgpIHsKICAgICAgICByZXR1cm4gLTE7CiAgICAgIH0KICAgICAgY29uc3QgeyBzdGF0cyB9ID0gaW5kZXhEYXRhLmluZGljZXNbcmVmSWRdOwogICAgICBpZiAoc3RhdHMpIHsKICAgICAgICByZXR1cm4gc3RhdHMubGluZUNvdW50OwogICAgICB9CiAgICAgIHJldHVybiAtMTsKICAgIH0KICAgIGFzeW5jIF9wYXJzZShvcHRzID0ge30pIHsKICAgICAgY29uc3QgYnVmID0gYXdhaXQgdGhpcy5maWxlaGFuZGxlLnJlYWRGaWxlKG9wdHMpOwogICAgICBjb25zdCBieXRlcyA9IGF3YWl0IHVuemlwKGJ1Zik7CiAgICAgIGNoZWNrQWJvcnRTaWduYWwob3B0cy5zaWduYWwpOwogICAgICBpZiAoYnl0ZXMucmVhZFVJbnQzMkxFKDApICE9PSBUQklfTUFHSUMpIHsKICAgICAgICB0aHJvdyBuZXcgRXJyb3IoIk5vdCBhIFRCSSBmaWxlIik7CiAgICAgIH0KICAgICAgY29uc3QgcmVmQ291bnQgPSBieXRlcy5yZWFkSW50MzJMRSg0KTsKICAgICAgY29uc3QgZm9ybWF0RmxhZ3MgPSBieXRlcy5yZWFkSW50MzJMRSg4KTsKICAgICAgY29uc3QgY29vcmRpbmF0ZVR5cGUgPSBmb3JtYXRGbGFncyAmIDY1NTM2ID8gInplcm8tYmFzZWQtaGFsZi1vcGVuIiA6IC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ICs9IDE2ICogY2h1bmtDb3VudDsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGNvbnN0IGNodW5rQ291bnQgPSBieXRlcy5yZWFkSW50MzJMRShjdXJyT2Zmc2V0KTsKICAgICAgICAgICAgY3Vyck9mZnNldCArPSA0OwogICAgICAgICAgICBjb25zdCBjaHVua3MgPSBuZXcgQXJyYXkoY2h1bmtDb3VudCk7CiAgICAgICAgICAgIGZvciAobGV0IGsgPSAwOyBrIDwgY2h1bmtDb3VudDsgayArPSAxKSB7CiAgICAgICAgICAgICAgY29uc3QgdSA9IGZyb21CeXRlcyhieXRlcywgY3Vyck9mZnNldCk7CiAgICAgICAgICAgICAgY29uc3QgdiA9IGZyb21CeXRlcyhieXRlcywgY3Vyck9mZnNldCArIDgpOwogICAgICAgICAgICAgIGN1cnJPZmZzZXQgKz0gMTY7CiAgICAgICAgICAgICAgZmlyc3REYXRhTGluZSA9IHRoaXMuX2ZpbmRGaXJzdERhdGEoZmlyc3REYXRhTGluZSwgdSk7CiAgICAgICAgICAgICAgY2h1bmtzW2tdID0gbmV3IENodW5rKHUsIHYsIGJpbik7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgYmluSW5kZXhbYmluXSA9IGNodW5rczsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgY29uc3QgbGluZWFyQ291bnQgPSBieXRlcy5yZWFkSW50MzJMRShjdXJyT2Zmc2V0KTsKICAgICAgICBjdXJyT2Zmc2V0ICs9IDQ7CiAgICAgICAgY29uc3QgbGluZWFySW5kZXggPSBuZXcgQXJyYXkobGluZWFyQ291bnQpOwogICAgICAgIGZvciAobGV0IGsgPSAwOyBrIDwgbGluZWFyQ291bnQ7IGsgKz0gMSkgewogICAgICAgICAgbGluZWFySW5kZXhba10gPSBmcm9tQnl0ZXMoYnl0ZXMsIGN1cnJPZmZzZXQpOwogICAgICAgICAgY3Vyck9mZnNldCArPSA4OwogICAgICAgICAgZmlyc3REYXRhTGluZSA9IHRoaXMuX2ZpbmRGaXJzdERhdGEoZmlyc3REYXRhTGluZSwgbGluZWFySW5kZXhba10pOwogICAgICAgIH0KICAgICAgICByZXR1cm4geyBiaW5JbmRleCwgbGluZWFySW5kZXgsIHN0YXRzIH07CiAgICAgIH0pOwogICAgICByZXR1cm4gewogICAgICAgIGluZGljZXMsCiAgICAgICAgbWV0YUNoYXIsCiAgICAgICAgbWF4QmluTnVtYmVyLAogICAgICAgIG1heFJlZkxlbmd0aCwKICAgICAgICBza2lwTGluZXMsCiAgICAgICAgZmlyc3REYXRhTGluZSwKICAgICAgICBjb2x1bW5OdW1iZXJzLAogICAgICAgIGNvb3JkaW5hdGVUeXBlLAogICAgICAgIGZvcm1hdCwKICAgICAgICByZWZJZFRvTmFtZSwKICAgICAgICByZWZOYW1lVG9JZCwKICAgICAgICBtYXhCbG9ja1NpemU6IDEgPDwgMTYKICAgICAgfTsKICAgIH0KICAgIHBhcnNlUHNldWRvQmluKGJ5dGVzLCBvZmZzZXQpIHsKICAgICAgY29uc3QgbGluZUNvdW50ID0gbG9uZ1RvTnVtYmVyKGltcG9ydF9sb25nMi5kZWZhdWx0LmZyb21CeXRlc0xFKGJ5dGVzLnNsaWNlKG9mZnNldCArIDE2LCBvZmZzZXQgKyAyNCksIHRydWUpKTsKICAgICAgcmV0dXJuIHsgbGluZUNvdW50IH07CiAgICB9CiAgICBfcGFyc2VOYW1lQnl0ZXMobmFtZXNCeXRlcykgewogICAgICBsZXQgY3VyclJlZklkID0gMDsKICAgICAgbGV0IGN1cnJOYW1lU3RhcnQgPSAwOwogICAgICBjb25zdCByZWZJZFRvTmFtZSA9IFtdOwogICAgICBjb25zdCByZWZOYW1lVG9JZCA9IHt9OwogICAgICBmb3IgKGxldCBpID0gMDsgaSA8IG5hbWVzQnl0ZXMubGVuZ3RoOyBpICs9IDEpIHsKICAgICAgICBpZiAoIW5hbWVzQnl0ZXNbaV0pIHsKICAgICAgICAgIGlmIChjdXJyTmFtZVN0YXJ0IDwgaSkgewogICAgICAgICAgICBsZXQgcmVmTmFtZSA9IG5hbWVzQnl0ZXMudG9TdHJpbmcoInV0ZjgiLCBjdXJyTmFtZVN0YXJ0LCBpKTsKICAgICAgICAgICAgcmVmTmFtZSA9IHRoaXMucmVuYW1lUmVmU2VxKHJlZk5hbWUpOwogICAgICAgICAgICByZWZJZFRvTmFtZVtjdXJyUmVmSWRdID0gcmVmTmFtZTsKICAgICAgICAgICAgcmVmTmFtZVRvSWRbcmVmTmFtZV0gPSBjdXJyUmVmSWQ7CiAgICAgICAgICB9CiAgICAgICAgICBjdXJyTmFtZVN0YXJ0ID0gaSArIDE7CiAgICAgICAgICBjdXJyUmVmSWQgKz0gMTsKICAgICAgICB9CiAgICAgIH0KICAgICAgcmV0dXJuIHsgcmVmTmFtZVRvSWQsIHJlZklkVG9OYW1lIH07CiAgICB9CiAgICBhc3luYyBibG9ja3NGb3JSYW5nZShyZWZOYW1lLCBtaW4sIG1heCwgb3B0cyA9IHt9KSB7CiAgICAgIGlmIChtaW4gPCAwKSB7CiAgICAgICAgbWluID0gMDsKICAgICAgfQogICAgICBjb25zdCBpbmRleERhdGEgPSBhd2FpdCB0aGlzLnBhcnNlKG9wdHMpOwogICAgICBpZiAoIWluZGV4RGF0YSkgewogICAgICAgIHJldHVybiBbXTsKICAgICAgfQogICAgICBjb25zdCByZWZJZCA9IGluZGV4RGF0YS5yZWZOYW1lVG9JZFtyZWZOYW1lXTsKICAgICAgY29uc3QgYmEgPSBpbmRleERhdGEuaW5kaWNlc1tyZWZJZF07CiAgICAgIGlmICghYmEpIHsKICAgICAgICByZXR1cm4gW107CiAgICAgIH0KICAgICAgY29uc3QgbWluT2Zmc2V0ID0gYmEubGluZWFySW5kZXgubGVuZ3RoID8gYmEubGluZWFySW5kZXhbbWluID4+IFRBRF9MSURYX1NISUZUID49IGJhLmxpbmVhckluZGV4Lmxlbmd0aCA/IGJhLmxpbmVhckluZGV4Lmxlbmd0aCAtIDEgOiBtaW4gPj4gVEFEX0xJRFhfU0hJRlRdIDogbmV3IFZpcnR1YWxPZmZzZXQoMCwgMCk7CiAgICAgIGlmICghbWluT2Zmc2V0KSB7CiAgICAgICAgY29uc29sZS53YXJuKCJxdWVyeWluZyBvdXRzaWRlIG9mIHBvc3NpYmxlIHRhYml4IHJhbmdlIik7CiAgICAgIH0KICAgICAgY29uc3Qgb3ZlcmxhcHBpbmdCaW5zID0gcmVnMmJpbnMobWluLCBtYXgpOwogICAgICBjb25zdCBjaHVua3MgPSBbXTsKICAgICAgZm9yIChjb25zdCBbc3RhcnQsIGVuZF0gb2Ygb3ZlcmxhcHBpbmdCaW5zKSB7CiAgICAgICAgZm9yIChsZXQgYmluID0gc3RhcnQ7IGJpbiA8PSBlbmQ7IGJpbisrKSB7CiAgICAgICAgICBpZiAoYmEuYmluSW5kZXhbYmluXSkgewogICAgICAgICAgICBjb25zdCBiaW5DaHVua3MgPSBiYS5iaW5JbmRleFtiaW5dOwogICAgICAgICAgICBmb3IgKGxldCBjID0gMDsgYyA8IGJpbkNodW5rcy5sZW5ndGg7ICsrYykgewogICAgICAgICAgICAgIGNodW5rcy5wdXNoKG5ldyBDaHVuayhiaW5DaHVua3NbY10ubWludiwgYmluQ2h1bmtzW2NdLm1heHYsIGJpbikpOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9CiAgICAgIGNvbnN0IG5pbnR2ID0gYmEubGluZWFySW5kZXgubGVuZ3RoOwogICAgICBsZXQgbG93ZXN0ID0gbnVsbDsKICAgICAgY29uc3QgbWluTGluID0gTWF0aC5taW4obWluID4+IDE0LCBuaW50diAtIDEpOwogICAgICBjb25zdCBtYXhMaW4gPSBNYXRoLm1pbihtYXggPj4gMTQsIG5pbnR2IC0gMSk7CiAgICAgIGZvciAobGV0IGkgPSBtaW5MaW47IGkgPD0gbWF4TGluOyArK2kpIHsKICAgICAgICBjb25zdCB2cCA9IGJhLmxpbmVhckluZGV4W2ldOwogICAgICAgIGlmICh2cCkgewogICAgICAgIC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ZXQpOwogICAgICAgICAgaWYgKGJpbiA+IHRoaXMubWF4QmluTnVtYmVyKSB7CiAgICAgICAgICAgIHN0YXRzID0gdGhpcy5wYXJzZVBzZXVkb0JpbihieXRlcywgY3Vyck9mZnNldCArIDQpOwogICAgICAgICAgICBjdXJyT2Zmc2V0ICs9IDQgKyA4ICsgNCArIDE2ICsgMTY7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBjb25zdCBsb2Zmc2V0ID0gZnJvbUJ5dGVzKGJ5dGVzLCBjdXJyT2Zmc2V0ICsgNCk7CiAgICAgICAgICAgIGZpcnN0RGF0YUxpbmUgPSB0aGlzLl9maW5kRmlyc3REYXRhKGZpcnN0RGF0YUxpbmUsIGxvZmZzZXQpOwogICAgICAgICAgICBjb25zdCBjaHVua0NvdW50ID0gYnl0ZXMucmVhZEludDMyTEUoY3Vyck9mZnNldCArIDEyKTsKICAgICAgICAgICAgY3Vyck9mZnNldCArPSAxNjsKICAgICAgICAgICAgY29uc3QgY2h1bmtzID0gbmV3IEFycmF5KGNodW5rQ291bnQpOwogICAgICAgICAgICBmb3IgKGxldCBrID0gMDsgayA8IGNodW5rQ291bnQ7IGsgKz0gMSkgewogICAgICAgICAgICAgIGNvbnN0IHUgPSBmcm9tQnl0ZXMoYnl0ZXMsIGN1cnJPZmZzZXQpOwogICAgICAgICAgICAgIGNvbnN0IHYgPSBmcm9tQnl0ZXMoYnl0ZXMsIGN1cnJPZmZzZXQgKyA4KTsKICAgICAgICAgICAgICBjdXJyT2Zmc2V0ICs9IDE2OwogICAgICAgICAgICAgIGNodW5rc1trXSA9IG5ldyBDaHVuayh1LCB2LCBiaW4pOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGJpbkluZGV4W2Jpbl0gPSBjaHVua3M7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiB7IGJpbkluZGV4LCBzdGF0cyB9OwogICAgICB9KTsKICAgICAgcmV0dXJuIHsKICAgICAgICAuLi5hdXgsCiAgICAgICAgY3NpOiB0cnVlLAogICAgICAgIHJlZkNvdW50LAogICAgICAgIG1heEJsb2NrU2l6ZTogMSA8PCAxNiwKICAgICAgICBmaXJzdERhdGFMaW5lLAogICAgICAgIGNzaVZlcnNpb24sCiAgICAgICAgaW5kaWNlcywKICAgICAgICBkZXB0aDogdGhpcy5kZXB0aCwKICAgICAgICBtYXhCaW5OdW1iZXI6IHRoaXMubWF4QmluTnVtYmVyLAogICAgICAgIG1heFJlZkxlbmd0aAogICAgICB9OwogICAgfQogICAgcGFyc2VQc2V1ZG9CaW4oYnl0ZXMsIG9mZnNldCkgewogICAgICBjb25zdCBsaW5lQ291bnQgPSBsb25nVG9OdW1iZXIoaW1wb3J0X2xvbmczLmRlZmF1bHQuZnJvbUJ5dGVzTEUoYnl0ZXMuc2xpY2Uob2Zmc2V0ICsgMjgsIG9mZnNldCArIDM2KSwgdHJ1ZSkpOwogICAgICByZXR1cm4geyBsaW5lQ291bnQgfTsKICAgIH0KICAgIGFzeW5jIGJsb2Nrc0ZvclJhbmdlKHJlZk5hbWUsIG1pbiwgbWF4LCBvcHRzID0ge30pIHsKICAgICAgaWYgKG1pbiA8IDApIHsKICAgICAgICBtaW4gPSAwOwogICAgICB9CiAgICAgIGNvbnN0IGluZGV4RGF0YSA9IGF3YWl0IHRoaXMucGFyc2Uob3B0cyk7CiAgICAgIGlmICghaW5kZXhEYXRhKSB7CiAgICAgICAgcmV0dXJuIFtdOwogICAgICB9CiAgICAgIGNvbnN0IHJlZklkID0gaW5kZXhEYXRhLnJlZk5hbWVUb0lkW3JlZk5hbWVdOwogICAgICBjb25zdCBiYSA9IGluZGV4RGF0YS5pbmRpY2VzW3JlZklkXTsKICAgICAgaWYgKCFiYSkgewogICAgICAgIHJldHVybiBbXTsKICAgICAgfQogICAgICBjb25zdCBvdmVybGFwcGluZ0JpbnMgPSB0aGlzLnJlZzJiaW5zKG1pbiwgbWF4KTsKICAgICAgY29uc3QgY2h1bmtzID0gW107CiAgICAgIGZvciAoY29uc3QgW3N0YXJ0LCBlbmRdIG9mIG92ZXJsYXBwaW5nQmlucykgewogICAgICAgIGZvciAobGV0IGJpbiA9IHN0YXJ0OyBiaW4gPD0gZW5kOyBiaW4rKykgewogICAgICAgICAgaWYgKGJhLmJpbkluZGV4W2Jpbl0pIHsKICAgICAgICAgICAgY29uc3QgYmluQ2h1bmtzID0gYmEuYmluSW5kZXhbYmluXTsKICAgICAgICAgICAgZm9yIChsZXQgYyA9IDA7IGMgPCBiaW5DaHVua3MubGVuZ3RoOyArK2MpIHsKICAgICAgICAgICAgICBjaHVua3MucHVzaChuZXcgQ2h1bmsoYmluQ2h1bmtzW2NdLm1pbnYsIGJpbkNodW5rc1tjXS5tYXh2LCBiaW4pKTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgICByZXR1cm4gb3B0aW1pemVDaHVua3MoY2h1bmtzLCBuZXcgVmlydHVhbE9mZnNldCgwLCAwKSk7CiAgICB9CiAgICByZWcyYmlucyhiZWcsIGVuZCkgewogICAgICBiZWcgLT0gMTsKICAgICAgaWYgKGJlZyA8IDEpIHsKICAgICAgICBiZWcgPSAxOwogICAgICB9CiAgICAgIGlmIChlbmQgPiAyICoqIDUwKSB7CiAgICAgICAgZW5kID0gMiAqKiAzNDsKICAgICAgfQogICAgICBlbmQgLT0gMTsKICAgICAgbGV0IGwgPSAwOwogICAgICBsZXQgdCA9IDA7CiAgICAgIGxldCBzID0gdGhpcy5taW5TaGlmdCArIHRoaXMuZGVwdGggKiAzOwogICAgICBjb25zdCBiaW5zID0gW107CiAgICAgIGZvciAoOyBsIDw9IHRoaXMuZGVwdGg7IHMgLT0gMywgdCArPSBsc2hpZnQoMSwgbCAqIDMpLCBsICs9IDEpIHsKICAgICAgICBjb25zdCBiID0gdCArIHJzaGlmdChiZWcsIHMpOwogICAgICAgIGNvbnN0IGUgPSB0ICsgcnNoaWZ0KGVuZCwgcyk7CiAgICAgICAgaWYgKGUgLSBiICs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hdGUgPSAtSW5maW5pdHk7CiAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgbGluZS5sZW5ndGggKyAxOyBpICs9IDEpIHsKICAgICAgICBpZiAobGluZVtpXSA9PT0gIgkiIHx8IGkgPT09IGxpbmUubGVuZ3RoKSB7CiAgICAgICAgICBpZiAoY3VycmVudENvbHVtbk51bWJlciA9PT0gcmVmKSB7CiAgICAgICAgICAgIGlmICh0aGlzLnJlbmFtZVJlZlNlcShsaW5lLnNsaWNlKGN1cnJlbnRDb2x1bW5TdGFydCwgaSkpICE9PSByZWdpb25SZWZOYW1lKSB7CiAgICAgICAgICAgICAgcmV0dXJuIHsgb3ZlcmxhcHM6IGZhbHNlIH07CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSBpZiAoY3VycmVudENvbHVtbk51bWJlciA9PT0gc3RhcnQpIHsKICAgICAgICAgICAgc3RhcnRDb29yZGluYXRlID0gcGFyc2VJbnQobGluZS5zbGljZShjdXJyZW50Q29sdW1uU3RhcnQsIGkpLCAxMCk7CiAgICAgICAgICAgIGlmIChjb29yZGluYXRlVHlwZSA9PT0gIjEtYmFzZWQtY2xvc2VkIikgewogICAgICAgICAgICAgIHN0YXJ0Q29vcmRpbmF0ZSAtPSAxOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzdGFydENvb3JkaW5hdGUgPj0gcmVnaW9uRW5kKSB7CiAgICAgICAgICAgICAgcmV0dXJuIHsgc3RhcnRDb29yZGluYXRlLCBvdmVybGFwczogZmFsc2UgfTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoZW5kID09PSAwIHx8IGVuZCA9PT0gc3RhcnQpIHsKICAgICAgICAgICAgICBpZiAoc3RhcnRDb29yZGluYXRlICsgMSA8PSByZWdpb25TdGFydCkgewogICAgICAgICAgICAgICAgcmV0dXJuIHsgc3RhcnRDb29yZGluYXRlLCBvdmVybGFwczogZmFsc2UgfTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSBpZiAoZm9ybWF0ID09PSAiVkNGIiAmJiBjdXJyZW50Q29sdW1uTnVtYmVyID09PSA0KSB7CiAgICAgICAgICAgIHJlZlNlcSA9IGxpbmUuc2xpY2UoY3VycmVudENvbHVtblN0YXJ0LCBpKTsKICAgICAgICAgIH0gZWxzZSBpZiAoY3VycmVudENvbHVtbk51bWJlciA9PT0gZW5kKSB7CiAgICAgICAgICAgIGxldCBlbmRDb29yZGluYXRlOwogICAgICAgICAgICBpZiAoZm9ybWF0ID09PSAiVkNGIikgewogICAgICAgICAgICAgIGVuZENvb3JkaW5hdGUgPSB0aGlzLl9nZXRWY2ZFbmQoc3RhcnRDb29yZGluYXRlLCByZWZTZXEsIGxpbmUuc2xpY2UoY3VycmVudENvbHVtblN0YXJ0LCBpKSk7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgZW5kQ29vcmRpbmF0ZSA9IHBhcnNlSW50KGxpbmUuc2xpY2UoY3VycmVudENvbHVtblN0YXJ0LCBpKSwgMTApOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChlbmRDb29yZGluYXRlIDw9IHJlZ2lvblN0YXJ0KSB7CiAgICAgICAgICAgICAgcmV0dXJuIHsgb3ZlcmxhcHM6IGZhbHNlIH07CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGN1cnJlbnRDb2x1bW5TdGFydCA9IGkgKyAxOwogICAgICAgICAgY3VycmVudENvbHVtbk51bWJlciArPSAxOwogICAgICAgICAgaWYgKGN1cnJlbnRDb2x1bW5OdW1iZXIgPiBtYXhDb2x1bW4pIHsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9CiAgICAgIHJldHVybiB7IHN0YXJ0Q29vcmRpbmF0ZSwgb3ZlcmxhcHM6IHRydWUgfTsKICAgIH0KICAgIF9nZXRWY2ZFbmQoc3RhcnRDb29yZGluYXRlLCByZWZTZXEsIGluZm8pIHsKICAgICAgbGV0IGVuZENvb3JkaW5hdGUgPSBzdGFydENvb3JkaW5hdGUgKyByZWZTZXEubGVuZ3RoOwogICAgICBjb25zdCBpc1RSQSA9IGluZm8uaW5kZXhPZigiU1ZUWVBFPVRSQSIpICE9PSAtMTsKICAgICAgaWYgKGluZm9bMF0gIT09ICIuIiAmJiAhaXNUUkEpIHsKICAgICAgICBsZXQgcHJldkNoYXIgPSAiOyI7CiAgICAgICAgZm9yIChsZXQgaiA9IDA7IGogPCBpbmZvLmxlbmd0aDsgaiArPSAxKSB7CiAgICAgICAgICBpZiAocHJldkNoYXIgPT09ICI7IiAmJiBpbmZvLnNsaWNlKGosIGogKyA0KSA9PT0gIkVORD0iKSB7CiAgICAgICAgICAgIGxldCB2YWx1ZUVuZCA9IGluZm8uaW5kZXhPZigiOyIsIGopOwogICAgICAgICAgICBpZiAodmFsdWVFbmQgPT09IC0xKSB7CiAgICAgICAgICAgICAgdmFsdWVFbmQgPSBpbmZvLmxlbmd0aDsKICAgICAgICAgICAgfQogICAgICAgICAgICBlbmRDb29yZGluYXRlID0gcGFyc2VJbnQoaW5mby5zbGljZShqICsgNCwgdmFsdWVFbmQpLCAxMCk7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgICAgcHJldkNoYXIgPSBpbmZvW2pdOwogICAgICAgIH0KICAgICAgfSBlbHNlIGlmIChpc1RSQSkgewogICAgICAgIHJldHVybiBzdGFydENvb3JkaW5hdGUgKyAxOwogICAgICB9CiAgICAgIHJldHVybiBlbmRDb29yZGluYXRlOwogICAgfQogICAgYXN5bmMgbGluZUNvdW50KHJlZk5hbWUsIG9wdHMgPSB7fSkgewogICAgICByZXR1cm4gdGhpcy5pbmRleC5saW5lQ291bnQocmVmTmFtZSwgb3B0cyk7CiAgICB9CiAgICBhc3luYyBfcmVhZFJlZ2lvbihwb3MsIHNpemUsIG9wdHMgPSB7fSkgewogICAgICBjb25zdCBiID0gaW1wb3J0X2J1ZmZlcjc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4+PiAxOwogICAgICAgIGlmIChjb21wYXJlKGFbbWlkXSwgeCkgPCAwKQogICAgICAgICAgbG8gPSBtaWQgKyAxOwogICAgICAgIGVsc2UKICAgICAgICAgIGhpID0gbWlkOwogICAgICB9CiAgICAgIHJldHVybiBsbzsKICAgIH0KICAgIGZ1bmN0aW9uIHJpZ2h0KGEsIHgsIGxvLCBoaSkgewogICAgICBpZiAobG8gPT0gbnVsbCkKICAgICAgICBsbyA9IDA7CiAgICAgIGlmIChoaSA9PSBudWxsKQogICAgICAgIGhpID0gYS5sZW5ndGg7CiAgICAgIHdoaWxlIChsbyA8IGhpKSB7CiAgICAgICAgY29uc3QgbWlkID0gbG8gKyBoaSA+Pj4gMTsKICAgICAgICBpZiAoY29tcGFyZShhW21pZF0sIHgpID4gMCkKICAgICAgICAgIGhpID0gbWlkOwogICAgICAgIGVsc2UKICAgICAgICAgIGxvID0gbWlkICsgMTsKICAgICAgfQogICAgICByZXR1cm4gbG87CiAgICB9CiAgICBmdW5jdGlvbiBjZW50ZXIoYSwgeCwgbG8sIGhpKSB7CiAgICAgIGlmIChsbyA9PSBudWxsKQogICAgICAgIGxvID0gMDsKICAgICAgaWYgKGhpID09IG51bGwpCiAgICAgICAgaGkgPSBhLmxlbmd0aDsKICAgICAgY29uc3QgaSA9IGxlZnQoYSwgeCwgbG8sIGhpIC0gMSk7CiAgICAgIHJldHVybiBpID4gbG8gJiYgZGVsdGEoYVtpIC0gMV0sIHgpID4gLWRlbHRhKGFbaV0sIHgpID8gaSAtIDEgOiBpOwogICAgfQogICAgcmV0dXJuIHsgbGVmdCwgY2VudGVyLCByaWdodCB9OwogIH0KICBmdW5jdGlvbiBhc2NlbmRpbmdDb21wYXJhdG9yKGYpIHsKICAgIHJldHVybiAoZCwgeCkgPT4gYXNjZW5kaW5nX2RlZmF1bHQoZihkKSwgeCk7CiAgfQoKICAvLyBzcmMvZGF0YS1mZXRjaGVycy91dGlscy50cwogIHZhciBEYXRhU291cmNlID0gY2xhc3M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AgIGNvbnN0IGF1dG9GaWVsZCA9IGF1dG9TcWwuZmllbGRzW2ldOwogICAgICAgICAgbGV0IGNvbHVtblZhbCA9IGZpZWxkc1tpXTsKICAgICAgICAgIGNvbnN0IHsgaXNOdW1lcmljLCBpc0FycmF5OiBpc0FycmF5MiwgYXJyYXlJc051bWVyaWMsIG5hbWUgfSA9IGF1dG9GaWVsZDsKICAgICAgICAgIGlmIChjb2x1bW5WYWwgPT09IG51bGwgfHwgY29sdW1uVmFsID09PSB2b2lkIDApIHsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoY29sdW1uVmFsICE9PSAiLiIpIHsKICAgICAgICAgICAgaWYgKGlzTnVtZXJpYykgewogICAgICAgICAgICAgIGNvbnN0IG51bSA9IE51bWJlcihjb2x1bW5WYWwpOwogICAgICAgICAgICAgIGNvbHVtblZhbCA9IE51bWJlci5pc05hTihudW0pID8gY29sdW1uVmFsIDogbnVtOwogICAgICAgICAgICB9IGVsc2UgaWYgKGlzQXJyYXkyKSB7CiAgICAgICAgICAgICAgY29sdW1uVmFsID0gY29sdW1uVmFsLnNwbGl0KCIsIik7CiAgICAgICAgICAgICAgaWYgKGNvbHVtblZhbFtjb2x1bW5WYWwubGVuZ3RoIC0gMV0gPT09ICIiKSB7CiAgICAgICAgICAgICAgICBjb2x1bW5WYWwucG9wKCk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGlmIChhcnJheUlzTnVtZXJpYykgewogICAgICAgICAgICAgICAgY29sdW1uVmFsID0gY29sdW1uVmFsLm1hcCgoc3RyKSA9PiBOdW1iZXIoc3RyKSk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGZlYXR1cmVbbmFtZV0gPSBjb2x1bW5WYWw7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9IGVsc2UgewogICAgICAgIGNvbnN0IGZpZWxkTmFtZXMgPSBbImNocm9tIiwgImNocm9tU3RhcnQiL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yAjY2FsY05Db2x1bW5zKCkgewogICAgICBjb25zdCBzb3VyY2UgPSBkYXRhU291cmNlcy5nZXQodGhpcy4jdWlkKTsKICAgICAgY29uc3QgeyBjaHJvbUxlbmd0aHMsIGN1bVBvc2l0aW9ucyB9ID0gc291cmNlLmNocm9tSW5mbzsKICAgICAgbGV0IG5fY29scyA9IDA7CiAgICAgIGZvciAoY29uc3QgY3VtUG9zIG9mIGN1bVBvc2l0aW9ucykgewogICAgICAgIGNvbnN0IGNocm9tTmFtZSA9IGN1bVBvcy5jaHI7CiAgICAgICAgY29uc3QgY2hyb21TdGFydCA9IGN1bVBvcy5wb3M7CiAgICAgICAgY29uc3QgY2hyb21FbmQgPSBjdW1Qb3MucG9zICsgY2hyb21MZW5ndGhzW2Nocm9tTmFtZV07CiAgICAgICAgbl9jb2xzID0gYXdhaXQgbmV3IFByb21pc2UoKHJlc29sdmUpID0+IHsKICAgICAgICAgIHNvdXJjZS5maWxlLnRiaS5nZXRMaW5lcyhjaHJvbU5hbWUsIGNocm9tU3RhcnQsIGNocm9tRW5kLCAobGluZSkgPT4gewogICAgICAgICAgICByZXNvbHZlKGxpbmUuc3BsaXQoIgkiKS5sZW5ndGgpOwogICAgICAgICAgfSk7CiAgICAgICAgfSk7CiAgICAgICAgaWYgKG5fY29scyA+IDApCiAgICAgICAgICBicmVhazsKICAgICAgfQogICAgICByZXR1cm4gbl9jb2xzOwogICAgfQogICAgYXN5bmMgZ2V0VGlsZURhdGEobWluWCwgbWF4WCkgewogICAgICBjb25zdCBzb3VyY2UgPSBkYXRhU291cmNlcy5nZXQodGhpcy4jdWlkKTsKICAgICAgY29uc3QgcGFyc2VyMiA9IGF3YWl0IHRoaXMuZ2V0UGFyc2VyKCk7CiAgICAgIGxldCBjdXJNaW5YID0gbWluWDsKICAgICAgY29uc3QgeyBjaHJvbUxlbmd0aHMsIGN1bVBvc2l0aW9ucyB9ID0gc291cmNlLmNocm9tSW5mbzsKICAgICAgY29uc3QgYWxsVGlsZXMgPSBbXTsKICAgICAgZm9yIChjb25zdCBjdW1Qb3Mgb2YgY3VtUG9zaXRpb25zKSB7CiAgICAgICAgY29uc3QgY2hyb21OYW1lID0gY3VtUG9zLmNocjsKICAgICAgICBjb25zdCBjaHJvbVN0YXJ0ID0gY3VtUG9zLnBvczsKICAgICAgICBjb25zdCBjaHJvbUVuZCA9IGN1bVBvcy5wb3MgKyBjaHJvbUxlbmd0aHNbY2hyb21OYW1lXTsKICAgICAgICBsZXQgc3RhcnRQb3MsIGVuZFBvczsKICAgICAgICBpZiAoY2hyb21TdGFydCA+IGN1ck1pblggfHwgY3VyTWluWCA+PSBjaHJvbUVuZCkgewogICAgICAgICAgY29udGludWU7CiAgICAgICAgfQogICAgICAgIGNvbnN0IHRpbGVzUHJvbWlzZSA9IG5ldyBQcm9taXNlKChyZXNvbHZlKSA9PiB7CiAgICAgICAgICBjb25zdCB0aWxlcyA9IFtdOwogICAgICAgICAgY29uc3QgbGluZUNhbGxiYWNrID0gKGxpbmUpID0+IHsKICAgICAgICAgICAgY29uc3QgYmVkVGlsZSA9IHBhcnNlcjIucGFyc2VMaW5lKGxpbmUsIGNocm9tU3RhcnQpOwogICAgICAgICAgICB0aWxlcy5wdXNoKGJlZFRpbGUpOwogICAgICAgICAgfTsKICAgICAgICAgIGlmIChtYXhYID4gY2hyb21FbmQpIHsKICAgICAgICAgICAgc3RhcnRQb3MgPSBjdXJNaW5YIC0gY2hyb21TdGFydDsKICAgICAgICAgICAgZW5kUG9zID0gY2hyb21FbmQgLSBjaHJvbVN0YXJ0OwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgc3RhcnRQb3MgPSBNYXRoLmZsb29yKGN1ck1pblggLSBjaHJvbVN0YXJ0KTsKICAgICAgICAgICAgZW5kUG9zID0gTWF0aC5jZWlsKG1heFggLSBjaHJvbVN0YXJ0KTsKICAgICAgICAgIH0KICAgICAgICAgIHNvdXJjZS5maWxlLnRiaS5nZXRMaW5lcyhjaHJvbU5hbWUs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F0sIDEwKTsKICAgICAgY29uc3QgeCA9IHBhcnNlSW50KHBhcnRzWzFdLCAxMCk7CiAgICAgIGlmIChOdW1iZXIuaXNOYU4oeCkgfHwgTnVtYmVyLmlzTmFOKHopKSB7CiAgICAgICAgY29uc29sZS53YXJuKCJJbnZhbGlkIHRpbGUgem9vbSBvciBwb3NpdGlvbjoiLCB6LCB4KTsKICAgICAgICBjb250aW51ZTsKICAgICAgfQogICAgICB2YWxpZFRpbGVJZHMucHVzaCh0aWxlSWQpOwogICAgICB0aWxlUHJvbWlzZXMucHVzaCh0aWxlKHVpZCwgeiwgeCkpOwogICAgfQogICAgcmV0dXJuIFByb21pc2UuYWxsKHRpbGVQcm9taXNlcykudGhlbigodmFsdWVzMikgPT4gewogICAgICBmb3IgKGxldCBpID0gMDsgaSA8IHZhbHVlczIubGVuZ3RoOyBpKyspIHsKICAgICAgICBjb25zdCB2YWxpZFRpbGVJZCA9IHZhbGlkVGlsZUlkc1tpXTsKICAgICAgICB0aWxlc1t2YWxpZFRpbGVJZF0gPSB7IHRpbGVQb3NpdGlvbklkOiB2YWxpZFRpbGVJZCB9OwogICAgICB9CiAgICAgIHJldHVybiB0aWxlczsKICAgIH0pOwogIH07CiAgdmFyIGdldFRhYnVsYXJEYXRhID0gKHVpZCwgdGlsZUlkcykgPT4gewogICAgY29uc3QgZGF0YSA9IFtdOwogICAgdGlsZUlkcy5mb3JFYWNoKCh0aWxlSWQpID0+IHsKICAgICAgY29uc3QgcGFydHMgPSB0aWxlSWQuc3BsaXQoIi4iKTsKICAgICAgY29uc3QgeiA9IHBhcnNlSW50KHBhcnRzWzBdLCAxMCk7CiAgICAgIGNvbnN0IHggPSBwYXJzZUludChwYXJ0c1sxXSwgMTApOwogICAgICBjb25zdCB0aWxlVmFsdWUgPSB0aWxlVmFsdWVzW2Ake3VpZH0uJHt6fS4ke3h9YF07CiAgICAgIGlmICghdGlsZVZhbHVlKSB7CiAgICAgICAgY29uc29sZS53YXJuKGBObyB0aWxlI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Q3VzdG9tIEJ1aWxkKSA8aHR0cHM6Ly9sb2Rhc2guY29tLz4KICogQnVpbGQ6IGBsb2Rhc2ggbW9kdWxhcml6ZSBleHBvcnRzPSJlcyIgLW8gLi9gCiAqIENvcHlyaWdodCBPcGVuSlMgRm91bmRhdGlvbiBhbmQgb3RoZXIgY29udHJpYnV0b3JzIDxodHRwczovL29wZW5qc2Yub3JnLz4KICogUmVsZWFzZWQgdW5kZXIgTUlUIGxpY2Vuc2UgPGh0dHBzOi8vbG9kYXNoLmNvbS9saWNlbnNlPgogKiBCYXNlZCBvbiBVbmRlcnNjb3JlLmpzIDEuOC4zIDxodHRwOi8vdW5kZXJzY29yZWpzLm9yZy9MSUNFTlNFPgogKiBDb3B5cmlnaHQgSmVyZW15IEFzaGtlbmFzLCBEb2N1bWVudENsb3VkIGFuZCBJbnZlc3RpZ2F0aXZlIFJlcG9ydGVycyAmIEVkaXRvcnMKICovCg==",Cle=typeof window<"u"&&window.Blob&&new Blob([atob(M9e)],{type:"text/javascript;charset=utf-8"});function OIg(){const e=Cle&&(window.URL||window.webkitURL).createObjectURL(Cle);try{return e?new Worker(e):new Worker("data:application/javascript;base64,"+M9e,{type:"module"})}finally{e&&(window.URL||window.webkitURL).revokeObjectURL(e)}}const _Ig=200;class z9e{constructor(g,I){Ct(this,"dataConfig",{}),Ct(this,"uid"),Ct(this,"prevRequestTime"),Ct(this,"track"),Ct(this,"toFetch"),Ct(this,"fetchTimeout"),Ct(this,"worker"),this.uid=g.libraries.slugid.nice(),this.prevRequestTime=0,this.toFetch=new Set;const{url:i,indexUrl:n,assembly:C,...r}=I;this.worker=GT(new OIg).then(async o=>{const A=Object.entries(pI(C).size);return await o.init(this.uid,{url:i,indexUrl:n},A,r),o})}async tilesetInfo(g){(await this.worker).tilesetInfo(this.uid).then(g)}fetchTilesDebounced(g,I){this.track.drawLoadingCue(),I.forEach(i=>this.toFetch.add(i)),this.fetchTimeout&&clearTimeout(this.fetchTimeout),this.fetchTimeout=setTimeout(()=>{this.sendFetch(g,[...this.toFetch]),this.toFetch.clear()},_Ig)}async sendFetch(g,I){(await this.worker).fetchTilesDebounced(this.uid,I).then(g)}async getTabularData(g){const I=await(await this.worker).getTabularData(this.uid,g);return JSON.parse(new TextDecoder().decode(I))}}Ct(z9e,"config",{type:"bed"});const LIg=Object.freeze(Object.defineProperty({__proto__:null,BamDataFetcher:nH,BedDataFetcher:z9e,BigWigDataFetcher:Y9e,CsvDataFetcher:D9e,GffDataFetcher:E9e,JsonDataFetcher:x9e,VcfDataFetcher:a9e},Symbol.toStringTag,{value:"Module"})),UIg="gosling-data-row-uid";function QIg(e,g){var I,i,n,C,r,o,A,s,a,l,c,u,d,h,m,f;const b=[];if(!lU(e.data)){console.warn("No data is specified");return}if(e.data.type==="vector"||e.data.type==="bigwig"){if(!("dense"in g))return;const p=(I=e.data.binSize)!=null?I:1,y=g.dense,Z=g.tileSize,B=g.tileWidth/g.tileSize,G=(i=e.data.value)!=null?i:"value",v=(n=e.data.column)!=null?n:"position",w=(C=e.data.start)!=null?C:"start",V=(r=e.data.end)!=null?r:"end",S=`${G}_min`,X=`${G}_max`,W=(o=e.data.aggregation)!=null?o:"mean";let R=0,H=Number.MAX_SAFE_INTEGER,Y=Number.MIN_SAFE_INTEGER,D=Number.MIN_SAFE_INTEGER,E=Number.MAX_SAFE_INTEGER;Array.from(Array(Z).keys()).forEach((O,J)=>{if(p===1){const ee=y[J]/(W==="mean"?B:1);b.push({[G]:ee,[v]:g.tileX+(J+.5)*B,[w]:g.tileX+J*B,[V]:g.tileX+(J+1)*B,[S]:ee,[X]:ee})}else if(J%p===0)R=H=Y=y[J],D=J,E=J+p;else if(J%p===p-1)b.push({[G]:R/p/(W==="mean"?B:1),[v]:g.tileX+(D+p/2)*B,[w]:g.tileX+D*B,[V]:g.tileX+E*B,[S]:H,[X]:Y});else if(J===Z-1){const ee=Z%p,q=D+ee;b.push({[G]:R/ee/(W==="mean"?B:1),[v]:g.tileX+(D+ee/2)*B,[w]:g.tileX+D*B,[V]:g.tileX+q*B,[S]:H,[X]:Y})}else R+=y[J],H>y[J]&&(H=y[J]),Y{let O=0,J=Number.MIN_SAFE_INTEGER,ee=Number.MAX_SAFE_INTEGER,q=Number.MAX_SAFE_INTEGER,$=Number.MIN_SAFE_INTEGER;Array.from(Array(G).keys()).forEach((j,te)=>{if(p===1){const U=B[G*E+te]/(Y==="mean"?v:1);b.push({[w]:D,[V]:U,[S]:g.tileX+(te+.5)*v,[X]:g.tileX+te*v,[W]:g.tileX+(te+1)*v,[R]:U,[H]:U})}else if(te%p===0)O=q=$=B[G*E+te],J=te,ee=te+p;else if(te%p===p-1)b.push({[w]:D,[V]:Y==="mean"?O/p/v:O,[S]:g.tileX+(J+p/2)*v,[X]:g.tileX+J*v,[W]:g.tileX+ee*v,[R]:q,[H]:$});else if(te===G-1){const U=G%p,ie=J+U;b.push({[w]:D,[V]:Y==="mean"?O/U/v:O,[S]:g.tileX+(J+U/2)*v,[X]:g.tileX+J*v,[W]:g.tileX+ie*v,[R]:q,[H]:$})}else{const U=B[G*E+te];O+=U,q>U&&(q=U),$"u"||typeof g.tileHeight>"u")return;const p=Math.sqrt(g.dense.length),{tileX:y,tileY:Z,tileWidth:B,tileHeight:G}=g,v=g.dense,w=B/p,V=G/p,S=(m=e.data.column)!=null?m:"x",X=(f=e.data.row)!=null?f:"y",W=16;for(let R=0;R{const{chrOffset:v,fields:w}=B,V={};if(V[UIg]=`${G}`,p.forEach(S=>{V[S.name]=+w[S.index]+v}),Z==null||Z.forEach(S=>{V[S.name]=S.type==="quantitative"?+w[S.index]:w[S.index]}),b.push({...V,type:"gene"}),y){const[S,X]=y,W=w[S.index].split(","),R=w[X.index].split(",");W.forEach((H,Y)=>{const D=R[Y];if(b.push({...V,[S.name]:+H+v,[X.name]:+D+v,type:"exon"}),Y+1n===e.chromosome))){if(Aje(e))return[I[e.chromosome][0]+1,I[e.chromosome][1]];if(aje(e))return e.interval;if(sje(e)){const i=I[e.chromosome][0],[n,C]=e.interval;return[i+n,i+C]}}}function tig(e,g){const I={},i=pd;e.forEach(n=>{i.forEach(C=>{const r=n.spec()[C];if(!st(r)||r.domain===void 0)return;const{domain:o,type:A}=r;if(A==="quantitative"){const s=Array.from(o);if(!I[C])I[C]=s;else{const a=I[C];a[0]>s[0]&&(a[0]=s[0]),a[1]{i.forEach(C=>{const r=n.spec()[C];st(r)&&r.type==="genomic"||(n.setChannelDomain(C,I[C],g),n.generateScales())}),n.updateChannelValue()})}const gig={compactLayout:!1,trackSourceServers:["https://server.gosling-lang.org/api/v1/"],views:[{genomePositionSearchBoxVisible:!1,genomePositionSearchBox:{autocompleteServer:"https://higlass.io/api/v1",autocompleteId:"P0PLbQMwTYGy-5uPIQid7A",chromInfoServer:"https://higlass.io/api/v1",chromInfoId:"hg38"},layout:{x:0,y:0,w:6.4,h:600},tracks:{top:[],left:[{type:"combined",width:130,height:600,contents:[{type:"gosling-track",server:"https://server.gosling-lang.org/api/v1/",tilesetUid:"cistrome-multivec",width:130,height:600,options:{showMousePosition:!0,mousePositionColor:"#000000",fontSize:24,labelPosition:"none",labelShowResolution:!1,labelColor:"black",labelBackgroundColor:"white",labelTextOpacity:1,labelLeftMargin:1,labelTopMargin:1,labelRightMargin:0,labelBottomMargin:0,backgroundColor:"transparent",spec:{spacing:10,orientation:"vertical",assembly:"hg38",layout:"linear",static:!1,xDomain:{interval:[0,1e9]},centerRadius:.3,xOffset:0,yOffset:0,style:{outlineWidth:.5},data:{url:"https://server.gosling-lang.org/api/v1/tileset_info/?d=cistrome-multivec",type:"multivec",row:"sample",column:"position",value:"peak",categories:["sample 1","sample 2","sample 3","sample 4"],binSize:4},mark:"rect",x:{field:"start",type:"genomic",axis:"left",domain:{interval:[0,1e9]},linkingId:"7f94b74e-25ec-4e67-8c75-3dc0f1b0d6bd"},xe:{field:"end",type:"genomic"},row:{field:"sample",type:"nominal",legend:!0},color:{field:"peak",type:"quantitative",legend:!0},tooltip:[{field:"start",type:"genomic",alt:"Start Position"},{field:"end",type:"genomic",alt:"End Position"},{field:"peak",type:"quantitative",alt:"Value",format:".2"},{field:"sample",type:"nominal",alt:"Sample"}],width:160,height:600,overlayOnPreviousTrack:!1},theme:{base:"light",root:{background:"white",titleColor:"black",titleBackgroundColor:"transparent",titleFontSize:18,titleFontFamily:"Arial",titleAlign:"left",titleFontWeight:"bold",subtitleColor:"gray",subtitleBackgroundColor:"transparent",subtitleFontSize:16,subtitleFontFamily:"Arial",subtitleFontWeight:"normal",subtitleAlign:"left",mousePositionColor:"#000000"},track:{background:"transparent",alternatingBackground:"transparent",titleColor:"black",titleBackground:"white",titleFontSize:24,titleAlign:"left",outline:"black",outlineWidth:1},legend:{position:"top",background:"white",backgroundOpacity:.7,labelColor:"black",labelFontSize:12,labelFontWeight:"normal",labelFontFamily:"Arial",backgroundStroke:"#DBDBDB",tickColor:"black"},axis:{tickColor:"black",labelColor:"black",labelFontSize:12,labelFontWeight:"normal",labelFontFamily:"Arial",baselineColor:"black",gridColor:"#E3E3E3",gridStrokeWidth:1,gridStrokeType:"solid",gridStrokeDash:[4,4]},markCommon:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},point:{color:"#E79F00",size:3,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},rect:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},triangle:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},area:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},line:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},bar:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},rule:{color:"#E79F00",size:1,stroke:"black",strokeWidth:1,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},link:{color:"#E79F00",size:1,stroke:"black",strokeWidth:1,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},text:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6],textAnchor:"middle",textFontWeight:"normal"},brush:{color:"gray",size:1,stroke:"black",strokeWidth:1,opacity:.3,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]}}}}]},{uid:"15483511-f6fb-11eb-914b-976b6ecda162",type:"axis-track",chromInfoPath:"https://s3.amazonaws.com/gosling-lang.org/data/hg38.chrom.sizes",options:{layout:"linear",outerRadius:null,width:160,height:600,theme:{base:"light",root:{background:"white",titleColor:"black",titleBackgroundColor:"transparent",titleFontSize:18,titleFontFamily:"Arial",titleAlign:"left",titleFontWeight:"bold",subtitleColor:"gray",subtitleBackgroundColor:"transparent",subtitleFontSize:16,subtitleFontFamily:"Arial",subtitleFontWeight:"normal",subtitleAlign:"left",mousePositionColor:"#000000"},track:{background:"transparent",alternatingBackground:"transparent",titleColor:"black",titleBackground:"white",titleFontSize:24,titleAlign:"left",outline:"black",outlineWidth:1},legend:{position:"top",background:"white",backgroundOpacity:.7,labelColor:"black",labelFontSize:12,labelFontWeight:"normal",labelFontFamily:"Arial",backgroundStroke:"#DBDBDB",tickColor:"black"},axis:{tickColor:"black",labelColor:"black",labelFontSize:12,labelFontWeight:"normal",labelFontFamily:"Arial",baselineColor:"black",gridColor:"#E3E3E3",gridStrokeWidth:1,gridStrokeType:"solid",gridStrokeDash:[4,4]},markCommon:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},point:{color:"#E79F00",size:3,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},rect:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},triangle:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},area:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},line:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},bar:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},rule:{color:"#E79F00",size:1,stroke:"black",strokeWidth:1,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},link:{color:"#E79F00",size:1,stroke:"black",strokeWidth:1,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},text:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6],textAnchor:"middle",textFontWeight:"normal"},brush:{color:"gray",size:1,stroke:"black",strokeWidth:1,opacity:.3,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]}},assembly:"hg38",stroke:"transparent",color:"black",fontSize:12,fontFamily:"Arial",fontWeight:"normal",tickColor:"black",tickFormat:"plain",tickPositions:"even",reverseOrientation:!1},width:30}],center:[],right:[],bottom:[],gallery:[],whole:[]},initialXDomain:[0,1e9],initialYDomain:[0,1e9],zoomFixed:!1,zoomLimits:[1,null],uid:"15483510-f6fb-11eb-914b-976b6ecda162",chromInfoPath:"https://s3.amazonaws.com/gosling-lang.org/data/hg38.chrom.sizes"},{genomePositionSearchBoxVisible:!1,genomePositionSearchBox:{autocompleteServer:"https://higlass.io/api/v1",autocompleteId:"P0PLbQMwTYGy-5uPIQid7A",chromInfoServer:"https://higlass.io/api/v1",chromInfoId:"hg38"},layout:{x:6.8,y:0,w:5.2,h:600},tracks:{top:[],left:[{type:"combined",width:130,height:600,contents:[{type:"gosling-track",server:"https://server.gosling-lang.org/api/v1/",tilesetUid:"cistrome-multivec",width:130,height:600,options:{showMousePosition:!0,mousePositionColor:"#000000",fontSize:24,labelPosition:"none",labelShowResolution:!1,labelColor:"black",labelBackgroundColor:"white",labelTextOpacity:1,labelLeftMargin:1,labelTopMargin:1,labelRightMargin:0,labelBottomMargin:0,backgroundColor:"transparent",spec:{spacing:10,orientation:"vertical",assembly:"hg38",layout:"linear",static:!1,xDomain:{interval:[0,1e9]},centerRadius:.3,xOffset:0,yOffset:0,style:{outlineWidth:.5},data:{url:"https://server.gosling-lang.org/api/v1/tileset_info/?d=cistrome-multivec",type:"multivec",row:"sample",column:"position",value:"peak",categories:["sample 1","sample 2","sample 3","sample 4"],binSize:4},mark:"rect",x:{field:"start",type:"genomic",domain:{interval:[0,1e9]},linkingId:"7f94b74e-25ec-4e67-8c75-3dc0f1b0d6bd"},xe:{field:"end",type:"genomic"},row:{field:"sample",type:"nominal",legend:!0},color:{field:"peak",type:"quantitative",legend:!0},tooltip:[{field:"start",type:"genomic",alt:"Start Position"},{field:"end",type:"genomic",alt:"End Position"},{field:"peak",type:"quantitative",alt:"Value",format:".2"},{field:"sample",type:"nominal",alt:"Sample"}],width:130,height:600},theme:{base:"light",root:{background:"white",titleColor:"black",titleBackgroundColor:"transparent",titleFontSize:18,titleFontFamily:"Arial",titleAlign:"left",titleFontWeight:"bold",subtitleColor:"gray",subtitleBackgroundColor:"transparent",subtitleFontSize:16,subtitleFontFamily:"Arial",subtitleFontWeight:"normal",subtitleAlign:"left",mousePositionColor:"#000000"},track:{background:"transparent",alternatingBackground:"transparent",titleColor:"black",titleBackground:"white",titleFontSize:24,titleAlign:"left",outline:"black",outlineWidth:1},legend:{position:"top",background:"white",backgroundOpacity:.7,labelColor:"black",labelFontSize:12,labelFontWeight:"normal",labelFontFamily:"Arial",backgroundStroke:"#DBDBDB",tickColor:"black"},axis:{tickColor:"black",labelColor:"black",labelFontSize:12,labelFontWeight:"normal",labelFontFamily:"Arial",baselineColor:"black",gridColor:"#E3E3E3",gridStrokeWidth:1,gridStrokeType:"solid",gridStrokeDash:[4,4]},markCommon:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},point:{color:"#E79F00",size:3,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},rect:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},triangle:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},area:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},line:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},bar:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},rule:{color:"#E79F00",size:1,stroke:"black",strokeWidth:1,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},link:{color:"#E79F00",size:1,stroke:"black",strokeWidth:1,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]},text:{color:"#E79F00",size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6],textAnchor:"middle",textFontWeight:"normal"},brush:{color:"gray",size:1,stroke:"black",strokeWidth:1,opacity:.3,nominalColorRange:["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],quantitativeSizeRange:[2,6]}}}}]}],center:[],right:[],bottom:[],gallery:[],whole:[]},initialXDomain:[0,1e9],initialYDomain:[0,1e9],zoomFixed:!1,zoomLimits:[1,null],uid:"154b1b40-f6fb-11eb-914b-976b6ecda162"}],zoomLocks:{locksByViewUid:{},locksDict:{}},locationLocks:{locksByViewUid:{},locksDict:{}},editable:!1,chromInfoPath:"https://s3.amazonaws.com/gosling-lang.org/data/hg38.chrom.sizes"},Or=30,Iig=e=>({genomePositionSearchBoxVisible:!1,genomePositionSearchBox:{autocompleteServer:"https://higlass.io/api/v1",autocompleteId:$$e(e),chromInfoServer:"https://higlass.io/api/v1",chromInfoId:e??"hg38"},layout:{w:12,h:12,x:0,y:0},tracks:{top:[],left:[],center:[],right:[],bottom:[],gallery:[],whole:[]},initialXDomain:[0,pI(e).total],initialYDomain:[0,pI(e).total],zoomFixed:!1});class iig{constructor(){Ct(this,"assembly"),Ct(this,"orientation"),Ct(this,"hg"),this.assembly="hg38",this.hg={compactLayout:!1,trackSourceServers:[],views:[],zoomLocks:{locksByViewUid:{},locksDict:{}},locationLocks:{locksByViewUid:{},locksDict:{}}},this.setEditable(!1)}spec(){return this.hg}setViewOrientation(g){return this.orientation=g,this}addDefaultView(g,I){return this.hg.views.push(JSON.parse(JSON.stringify({...Iig(I),uid:g}))),this}setAssembly(g){return this.assembly=g,this.setChromInfoPath(pI(this.assembly).path),this}getAssembly(){return this.assembly}setTextTrack(g,I,i,n="black",C=14,r="normal",o="left",A="transparent",s="Arial"){var a;return this.getLastView()&&((a=this.getLastView().tracks.top)==null||a.push({type:"text",width:g,height:I,options:{backgroundColor:A,textColor:n,fontSize:C,fontWeight:r,fontFamily:s,offsetY:0,align:o,text:i}})),this}setDummyTrack(g){var I;return this.getLastView()&&((I=this.getLastView().tracks.top)==null||I.push({type:"dummy-track",width:g.width,height:g.height,options:{width:g.width,height:g.height,title:g.title,...g.style}})),this}addBrush(g,I,i,n,C){var r,o,A,s,a,l;if(n)return(l=this.getView(I))==null||l.tracks.whole.push({type:g==="circular"?"brush-track":"viewport-projection-horizontal",uid:rn(),fromViewUid:n,options:{projectionFillColor:(r=C==null?void 0:C.color)!=null?r:i.brush.color,projectionStrokeColor:(o=C==null?void 0:C.stroke)!=null?o:i.brush.stroke,projectionFillOpacity:(A=C==null?void 0:C.opacity)!=null?A:i.brush.opacity,projectionStrokeOpacity:(s=C==null?void 0:C.opacity)!=null?s:i.brush.opacity,strokeWidth:(a=C==null?void 0:C.strokeWidth)!=null?a:i.brush.strokeWidth,startAngle:C==null?void 0:C.startAngle,endAngle:C==null?void 0:C.endAngle,innerRadius:C==null?void 0:C.innerRadius,outerRadius:C==null?void 0:C.outerRadius}}),this}getLastView(){return this.hg.views[this.hg.views.length-1]}getMainTrackPosition(){return this.orientation==="vertical"?"left":"center"}getLastVisView(){const g=this.hg.views.filter(I=>{var i,n;return((n=(i=I.tracks[this.getMainTrackPosition()])==null?void 0:i[0])==null?void 0:n.type)==="combined"});return g[g.length-1]}getView(g){return this.hg.views.find(I=>I.uid===g)}validateSpec(g=!1){return i9e(eig,this.spec(),g).state==="success"}setDomain(g,I){return g&&(this.getLastView().initialXDomain=ZO(g,this.getAssembly())),I&&(this.getLastView().initialYDomain=ZO(I,this.getAssembly())),this}adjustDomain(g="horizontal",I,i){if(g!=="vertical")return this;const n=this.getLastView().initialXDomain;if(!n)return this;const[C,r]=n,o=r-C,A=(C+r)/2;return this.getLastView().initialXDomain=[A-o/I/2/i*I,A+o/I/2/i*I],this}setZoomFixed(g){return this.getLastView().zoomFixed=g,this}setZoomLimits(g){return this.getLastView().zoomLimits=g,this}setLayout(g){return this.getLastView().layout=g,this}setEditable(g){return this.hg.editable=g,this}setChromInfoPath(g){return this.getLastView()&&(this.getLastView().chromInfoPath=g),this.hg.chromInfoPath=g,this}addTrackSourceServers(g){var I,i;return g&&((I=this.hg.trackSourceServers)==null?void 0:I.indexOf(g))===-1&&((i=this.hg.trackSourceServers)==null||i.push(g)),this}setMainTrack(g){var I;return this.getLastView()?(this.getLastView().tracks[this.getMainTrackPosition()]=[{type:"combined",uid:`${(I=g.uid)!=null?I:rn()}-${this.getMainTrackPosition()}-combined`,width:g.width-1,height:g.height,contents:[g]}],this):this}addTrackToCombined(g){var I;return this.getLastVisView()?((I=this.getLastVisView().tracks[this.getMainTrackPosition()][0])==null||I.contents.push(g),this):this}setAxisTrack(g,I="regular",i){if(!this.hg.views)return this;const n=g==="left"||g==="right"?"width":"height",C={type:"axis-track",chromInfoPath:this.hg.chromInfoPath,options:{...i,assembly:this.getAssembly(),stroke:"transparent",color:i.theme.axis.labelColor,labelMargin:i.theme.axis.labelMargin,excludeChrPrefix:i.theme.axis.labelExcludeChrPrefix,fontSize:i.theme.axis.labelFontSize,fontFamily:i.theme.axis.labelFontFamily,fontWeight:i.theme.axis.labelFontWeight,tickColor:i.theme.axis.tickColor,tickFormat:I==="narrower"?"si":"plain",tickPositions:I==="regular"?"even":"ends",reverseOrientation:g==="bottom"||g==="right"}};if(i.layout==="circular")this.addTrackToCombined({...C,options:{...C.options,layout:"circular"}});else{const r={...C,[n]:Or};if(g==="left"){if(this.getLastView().tracks.left.filter(o=>o.type==="axis-track").length!==0)return this;this.getLastView().tracks.left=FQe(this.getLastView().tracks.left,0,r)}else if(g==="right"){if(this.getLastView().tracks.right.filter(o=>o.type==="axis-track").length!==0)return this;this.getLastView().tracks.right.push(r)}else{if(this.getLastView().tracks[g].filter(o=>o.type==="axis-track").length!==0)return this;this.getLastView().tracks[g].push(r)}}return this}setExampleHiglassViewConfig(){this.hg=gig}}function gG(e,g,I,i){const n=i&&i!==0?i:void 0;let C=0;switch(g){case"less-than":case"LT":case"lt":C=I>e?n?(I-e)/n:1:0;break;case"less-than-or-equal-to":case"LTET":case"ltet":C=I>=e?n?(I-e)/n:1:0;break;case"greater-than":case"GT":case"gt":C=I{e[I]&&I!=="base"&&(g[I]=Object.assign(JSON.parse(JSON.stringify(g[I])),JSON.parse(JSON.stringify(e[I]))))}),g}}class Cig{constructor(g,I,i){Ct(this,"id"),Ct(this,"theme"),Ct(this,"specOriginal"),Ct(this,"specComplete"),Ct(this,"dataAggregated"),Ct(this,"channelScales"),Ct(this,"mouseEventModel"),this.id=rn(),this.theme=i??P9e(),this.dataAggregated=I,this.specOriginal=g,this.specComplete=structuredClone(g),this.channelScales={},this.mouseEventModel=new otg;const n=this.validateSpec();if(!n.valid){console.warn("Gosling specification is not valid!",n.errorMessages);return}this.generateCompleteSpec(this.specComplete),this.flipRanges(this.specComplete),this.generateScales(),this.dataAggregated=MIg(this.spec(),this.dataAggregated)}getId(){return this.id}originalSpec(){return this.specOriginal}spec(){return this.specComplete}data(){return this.dataAggregated}getMouseEventModel(){return this.mouseEventModel}generateCompleteSpec(g){if(!g.width||!g.height){console.warn("Size of track is not determined yet.");return}if(g.orientation==="vertical"){const n=g.width;g.width=g.height,g.height=n}const I=this.getGenomicChannelKey();let i=!1;I==="x"&&(i=st(g.x)&&g.x.axis!==void 0&&g.x.axis!=="none"),I==="y"&&(i=st(g.y)&&g.y.axis!==void 0&&g.y.axis!=="none"),g.layout!=="circular"?st(g.x)&&g.x.axis!==void 0&&g.x.axis!=="none"&&(g.height-=Or):I==="x"&&i&&st(g.x)&&g.x.axis==="top"?g.outerRadius=g.outerRadius-Or:I==="x"&&i&&st(g.x)&&g.x.axis==="bottom"&&(g.innerRadius=g.innerRadius+Or),pd.forEach(n=>{const C=g[n];st(C)&&!("zeroBaseline"in C)&&C.type==="quantitative"&&(C.zeroBaseline=!0)}),this.addScaleMaterials(g)}flipRanges(g){st(g.y)&&g.y.flip&&Array.isArray(g.y.range)&&(g.y.range=g.y.range.reverse())}getGenomicChannelKey(){return C9e(this.spec())}getGenomicChannel(){return _4(this.spec())}setChannelDomain(g,I,i){const n=this.originalSpec()[g];if(!i&&st(n)&&n.domain!==void 0)return;const C=this.specComplete[g];st(C)&&(C.domain=I)}updateChannelValue(){if(this.originalSpec().y===void 0){const g=this.spec().y,I=this.getChannelDomainArray("row");g&&l1(g)&&I&&this.spec().mark!=="withinLink"&&(g.value=this.spec().height/I.length/2)}}encodedValue(g,I){var i;if(g==="text"&&I!==void 0)return`${+I?~~I:I}`;const n=this.spec()[g],C=st(n)?n.type:l1(n)?"constant":void 0;if(C){if(C==="constant")return this.channelScales[g]();if(I!==void 0&&(I===null&&(C==="quantitative"?I=0:C==="nominal"&&(I="null")),typeof this.channelScales[g]=="function"))switch(g){case"x":case"y":case"x1":case"y1":case"xe":case"ye":case"x1e":if(C==="quantitative"||C==="genomic")return this.channelScales[g](I);if(C==="nominal")return this.channelScales[g](I);break;case"stroke":case"color":if(C==="quantitative"){const r=this.channelScales[g].copy(),o=r.domain(),A=o[1]-o[0],s=Array.from((i=n.scaleOffset)!=null?i:[0,1]);return r.domain([o[0]+A*s.sort()[0],o[0]+A*s.sort()[1]])(I)}if(C==="nominal")return this.channelScales[g](I);break;case"size":if(C==="quantitative")return this.channelScales[g](I);if(C==="nominal")return this.channelScales[g](I);break;case"row":if(C==="nominal")return this.channelScales[g](I);break;case"strokeWidth":case"opacity":if(C==="quantitative")return this.channelScales[g](I);break;default:console.warn(`${g} is not supported for encoding values, so returning a undefined value`);return}}}trackVisibility(g){const I=this.spec();if(!I.visibility||I.visibility.length===0||I.visibility.filter(n=>n.target==="track").length===0)return!0;let i=!0;return I.visibility.filter(n=>n.target==="track").forEach(n=>{const{operation:C,measure:r,threshold:o}=n;let A;r==="zoomLevel"?A=g[r]:A=I[r],A!==void 0&&(i=i&&gG(A,C,o)===1)}),i}markVisibility(g,I){const i=this.spec();if(!i.visibility||i.visibility.length===0||i.visibility.filter(C=>C.target==="mark").length===0)return 1;let n=1;return i.visibility.filter(C=>C.target==="mark").forEach(C=>{const{operation:r,threshold:o,conditionPadding:A,transitionPadding:s,measure:a}=C,l=A??0,c=i.mark;let u=1;if(c==="text"&&o==="|xe-x|"&&a==="width"){const d=this.encodedPIXIProperty("xe",g),h=this.encodedPIXIProperty("x",g);d!==void 0&&(I!=null&&I.width)&&(u=gG(I.width+l,r,Math.abs(d-h),s))}else a==="width"&&typeof o=="number"&&(I!=null&&I.width)?u=gG(I.width+l,r,o,s):a==="zoomLevel"&&typeof o=="number"&&(I!=null&&I.zoomLevel)&&(u=gG(I.zoomLevel,r,o,s));n>u&&(n=u)}),n}visualPropertyByChannel(g,I){const i=I!==void 0?fI(I,this.spec()[g]):void 0;return this.encodedValue(g,i)}encodedPIXIProperty(g,I,i){const n=this.spec().mark;if(["text","color","row","stroke","opacity","strokeWidth","x","y","xe","x1","x1e","ye","size"].includes(g))return this.visualPropertyByChannel(g,I);switch(n){case"bar":return HQe(this,g,I,i);case"point":case"text":return RQe(this,g,I);case"rect":return kQe(this,g,I,i);default:return}}addScaleMaterials(g){const I=this.data(),i=this.getGenomicChannel();if(!i||!i.field){console.warn("Genomic field is not provided in the specification");return}if(typeof g.width>"u"||typeof g.height>"u"){console.warn("Track size is not determined yet");return}pd.forEach(n=>{var C,r,o,A;const s=g[n];if(pje(g,n)&&st(s)){const a=qH(I,c=>c[i.field]),l=[...a.keys()];if(!s.domain){const c="zeroBaseline"in s&&s.zeroBaseline?0:A1(l.map(d=>qq(a.get(d).map(h=>s.field?h[s.field]:void 0)))),u=BG(l.map(d=>qq(a.get(d).map(h=>s.field?h[s.field]:void 0))));s.domain=[c,u]}if(!s.range){const c=g.row,u=st(c)?c.field:void 0,d=(C=this.getChannelDomainArray("row"))!=null?C:u?Array.from(new Set(I.map(m=>m[u]))):[1],h=g.height/d.length;switch(n){case"x":s.range=[0,g.width];break;case"y":s.range=[0,h];break}}}else{const a=g.row,l=st(a)?a.field:void 0,c=(r=this.getChannelDomainArray("row"))!=null?r:l?Array.from(new Set(I.map(d=>d[l]))):[1],u=g.height/c.length;if(s){if(st(s)&&(s.type==="quantitative"||s.type==="genomic")){if(s.domain===void 0){const d="zeroBaseline"in s&&s.zeroBaseline?0:(o=A1(I.map(m=>+m[s.field])))!=null?o:0,h=(A=BG(I.map(m=>+m[s.field])))!=null?A:0;s.domain=[d,h]}else s.type==="genomic"&&!Pee(s.domain)&&(s.domain=ZO(s.domain));if((n==="color"||n==="stroke")&&s.type==="quantitative"&&!s.scaleOffset&&(s.scaleOffset=[0,1]),!s.range){let d;switch(n){case"x":case"xe":case"x1":case"x1e":d=[0,g.width];break;case"y":case"ye":d=[0,u];break;case"color":case"stroke":d=nig.QUANTITATIVE_COLOR;break;case"size":d=this.theme.markCommon.quantitativeSizeRange;break;case"strokeWidth":d=[1,3];break;case"opacity":d=[0,1];break}d&&(s.range=d)}}else if(st(s)&&s.type==="nominal"&&(s.domain===void 0&&(s.domain=Array.from(new Set(I.map(d=>{var h;return(h=d[s.field])!=null?h:"null"})))),!s.range)){let d=2,h;switch(n){case"x":case"xe":h=[0,g.width];break;case"y":case"ye":h=[u,0];break;case"color":case"stroke":h=this.theme.markCommon.nominalColorRange;break;case"row":h=[0,g.height];break;case"size":h=s.domain.map(()=>d++);break}h&&(s.range=h)}}else{let d;switch(n){case"x":d=g.width/2;break;case"y":g.mark==="withinLink"?d=u:d=u/2;break;case"size":g.mark==="line"?d=this.theme.line.size:g.mark==="bar"||g.mark==="rect"||g.mark==="triangleRight"||g.mark==="triangleLeft"||g.mark==="triangleBottom"||g.stretch&&g.mark==="point"&&st(g.x)&&st(g.xe)?d=void 0:g.mark==="text"?d=12:d=this.theme.point.size;break;case"color":d=this.theme.markCommon.color;break;case"row":d=0;break;case"stroke":g.mark==="text"?d=this.theme.text.stroke:d=this.theme.markCommon.stroke;break;case"strokeWidth":g.mark==="rule"?d=this.theme.rule.strokeWidth:g.mark==="withinLink"||g.mark==="betweenLink"?d=this.theme.link.strokeWidth:g.mark==="text"?d=this.theme.text.strokeWidth:d=this.theme.markCommon.strokeWidth;break;case"opacity":d=this.theme.markCommon.opacity;break;case"text":d="";break}typeof d<"u"&&(g[n]={value:d})}}}),[["x","xe"],["y","ye"]].forEach(n=>{const[C,r]=n,o=g[C],A=g[r];if(st(o)&&st(A)&&o.type===A.type&&o.domain&&A.domain&&Array.isArray(o.domain)&&Array.isArray(A.domain)){if(o.type==="genomic"||o.type==="quantitative"){const s=A1([o.domain[0],A.domain[0]]),a=BG([o.domain[1],A.domain[1]]);o.domain=A.domain=[s,a]}else if(o.type==="nominal"){const s=Array.from(new Set([...o.domain,...A.domain]));o.range=A.range=s}}})}generateScales(){const g=this.spec();pd.forEach(I=>{const i=g[I];if(l1(i))this.channelScales[I]=()=>i.value;else if(st(i)){if(I==="text")return;const n=i.domain,C=i.range;if(n===void 0||C===void 0)return;if(i.type==="quantitative"||i.type==="genomic")switch(I){case"x":case"x1":case"xe":case"x1e":case"y":case"ye":case"size":case"opacity":case"strokeWidth":this.channelScales[I]=zd().domain(n).range(C);break;case"color":case"stroke":let r=ape;Object.keys(uX).includes(C)&&(r=uX[C]),this.channelScales[I]=Wfe(r).domain(n);break}else if(i.type==="nominal")switch(I){case"x":case"xe":case"y":case"ye":case"row":this.channelScales[I]=yfe().domain(n).range(C);break;case"size":this.channelScales[I]=rX().domain(n).range(C);break;case"color":case"stroke":this.channelScales[I]=rX(C).domain(n);break}}})}getChannelScale(g){return this.channelScales[g]}setChannelScale(g,I){this.channelScales[g]=I}isShowYAxis(){const g=this.spec(),I=this.getChannelDomainArray("y"),i=this.getChannelRangeArray("y");return st(g.y)&&g.y.axis!=="none"&&g.y.type==="quantitative"&&!!I&&!!i}getChannelDomainArray(g){const I=this.spec()[g];return st(I)&&Pee(I.domain)?I.domain:void 0}getChannelRangeArray(g){const I=this.spec()[g];return st(I)&&fje(I.range)?I.range:void 0}validateSpec(){return n9e(this.originalSpec())}}function Vr(e,g){XU.publish(e,g)}function rig(e,g){XU.subscribe(e,g)}function oig(e){XU.unsubscribe(e)}const rle={stroke:"black",strokeWidth:1,strokeOpacity:1,color:"none",opacity:1,arrange:"front"};function Aig(){return{goslingModels:[],tabularData:[],skipRendering:!1}}const aig={type:"gosling-track",datatype:["multivec","epilogos"],orientation:"1d-horizontal",defaultOptions:{theme:eG("light")}},sig=(e,g,I)=>{var i,n,C,r,o,A,s,a,l,c,u,d,h,m,f,b,p,y,Z,B,G,v,w,V,S,X,W,R,H,Y,D,E,O;const{tileProxy:J}=e.services,{BarTrack:ee}=e.tracks,q=Hs({color:"black",size:12}),$=class GO extends ee{constructor(){var U,ie,me,Ce,Ze,Ge;super(g,I),hg(this,d),hg(this,m),hg(this,b),hg(this,y),hg(this,B),hg(this,v),hg(this,V),hg(this,X),hg(this,R),hg(this,Y),hg(this,E),Ct(this,"tileSize"),Ct(this,"mRangeBrush"),hg(this,i,void 0),hg(this,n,void 0),Ct(this,"firstDraw",!0),Ct(this,"gLegend",e.libraries.d3Selection.select(g.svgElement).append("g")),Ct(this,"displayedLegends",[]),Ct(this,"textGraphics",[]),Ct(this,"textsBeingUsed",0),Ct(this,"pMouseHover",new e.libraries.PIXI.Graphics),Ct(this,"pMouseSelection",new e.libraries.PIXI.Graphics),hg(this,C,0),hg(this,r,0),hg(this,o,!1),hg(this,A,e.libraries.d3Selection.select(g.svgElement).append("g")),hg(this,s,new e.libraries.PIXI.TextStyle(q)),hg(this,a,new e.libraries.PIXI.Graphics),hg(this,l,new e.libraries.PIXI.Text("",q)),Ct(this,"prevVisibleAndFetchedTiles"),Ct(this,"resolvedTracks"),Ct(this,"hideMousePosition"),g.dataFetcher.track=this,vC(this,n,{}),vC(this,i,this.options.spec.assembly),"overlay"in this.options.spec?this.options.spec.overlay=this.options.spec._overlay.map(Se=>({...Se,_renderingId:rn()})):this.options.spec._renderingId=rn(),this.fetchedTiles={},this.tileSize=(ie=(U=this.tilesetInfo)==null?void 0:U.tile_size)!=null?ie:1024;const{valid:Be,errorMessages:Ne}=n9e(this.options.spec);Be||console.warn("The specification of the following track is invalid",Ne,this.options.spec),this.pMain.addChild(this.pMouseHover),this.pMain.addChild(this.pMouseSelection),this.pMask.interactive=!0,this.mRangeBrush=new ttg(xt(this,A),e.libraries,(me=this.options.spec.style)==null?void 0:me.brush),this.mRangeBrush.on("brush",BI(this,R,H).bind(this)),this.pMask.on("mousedown",Se=>{const{x:Pe,y:ze}=Se.data.getLocalPosition(this.pMain);BI(this,b,p).call(this,Pe,ze,Se.data.originalEvent.altKey)}),this.pMask.on("mouseup",Se=>{const{x:Pe,y:ze}=Se.data.getLocalPosition(this.pMain);BI(this,B,G).call(this,Pe,ze)}),this.pMask.on("mousemove",Se=>{const{x:Pe}=Se.data.getLocalPosition(this.pMain);BI(this,y,Z).call(this,Pe)}),this.pMask.on("mouseout",BI(this,v,w).bind(this)),this.flipText=this.options.spec.orientation==="vertical",this.hideMousePosition&&(this.hideMousePosition(),this.hideMousePosition=void 0),(Ce=this.options)!=null&&Ce.showMousePosition&&!this.hideMousePosition&&(this.hideMousePosition=e.utils.showMousePosition(this,qn(this.getResolvedTracks()[0]),this.isShowGlobalMousePosition())),this.pLabel.removeChild(this.trackNotFoundText),xt(this,l).anchor.x=1,xt(this,l).anchor.y=1,this.pLabel.addChild(xt(this,a)),this.pLabel.addChild(xt(this,l)),e.libraries.PIXI.GRAPHICS_CURVES.adaptive=(Ge=(Ze=this.options.spec.style)==null?void 0:Ze.enableSmoothPath)!=null?Ge:!1,e.libraries.PIXI.GRAPHICS_CURVES.adaptive&&(e.libraries.PIXI.GRAPHICS_CURVES.maxLength=1,e.libraries.PIXI.GRAPHICS_CURVES.maxSegments=2048*10)}draw(){var U,ie;this.clearMouseEventData(),this.textsBeingUsed=0,(U=this.pMouseHover)==null||U.clear();const me=()=>{const Ce=this.dataFetcher instanceof nH;this.processAllTiles(Ce),super.draw(),this.prevVisibleAndFetchedTiles=this.visibleAndFetchedTiles()};GV(this.dataFetcher)&&!ope(this.visibleAndFetchedTiles(),this.prevVisibleAndFetchedTiles)?this.updateTileAsync(this.dataFetcher,me):me(),(ie=this.mRangeBrush)==null||ie.drawBrush(!0),this.firstDraw&&(BI(this,E,O).call(this),this.firstDraw=!1)}initTile(U){this.drawTile(U)}updateTile(){}renderTile(){}drawTile(U){var ie,me;U.drawnAtScale=this._xScale.copy();const Ce=xt(this,n)[U.tileId];Ce&&((ie=U.graphics)==null||ie.clear(),(me=U.graphics)==null||me.removeChildren(),this.pBackground.clear(),this.pBackground.removeChildren(),this.pBorder.clear(),this.pBorder.removeChildren(),this.displayedLegends=[],Ce.goslingModels.forEach(Ze=>{const Ge=this.dimensions[0],Be=this._xScale.invert(Ge)-this._xScale.invert(0);Ze.trackVisibility({zoomLevel:Be})&&(gje(e,this,U,Ze,this.options.theme),tje(e,this,U,Ze),Ije(e,this,U,Ze,this.options.theme))}),this.forceDraw())}rerender(U){this.options=U,this.options.spec.layout==="circular"&&this.mRangeBrush.remove(),this.getResolvedTracks(!0),this.clearMouseEventData(),this.textsBeingUsed=0,this.processAllTiles(!0),this.draw(),this.forceDraw()}clearMouseEventData(){this.visibleAndFetchedGoslingModels().forEach(U=>U.getMouseEventModel().clear())}visibleAndFetchedGoslingModels(){return this.visibleAndFetchedTiles().flatMap(U=>{var ie,me;return(me=(ie=xt(this,n)[U.tileId])==null?void 0:ie.goslingModels)!=null?me:[]})}remove(){super.remove(),this.gLegend&&(this.gLegend.remove(),this.gLegend=void 0),this.mRangeBrush.remove()}setDimensions(U){super.setDimensions(U),this.mRangeBrush.setSize(U[1])}setPosition(U){super.setPosition(U),[this.pMain.position.x,this.pMain.position.y]=this.position,this.mRangeBrush.setOffset(...U)}forceDraw(){this.animate()}zoomed(U,ie){const me=this.mRangeBrush.getRange();this.mRangeBrush.updateRange(me?[U(this._xScale.invert(me[0])),U(this._xScale.invert(me[1]))]:null),this.xScale(U),this.yScale(ie),this.refreshTiles(),this.draw(),this.forceDraw();const Ce=U.domain().map(Ze=>Ku(Ze,xt(this,i),!0));Vr("location",{id:g.viewUid,genomicRange:Ce})}setMask(U,ie){if(this.pMask.clear(),this.pMask.beginFill(),this.options.spec.layout==="circular"){const[me,Ce]=this.position,[Ze,Ge]=this.dimensions,Be=me+Ze/2,Ne=Ce+Ge/2,Se=this.options.spec.outerRadius;this.pMask.drawCircle(Be,Ne,Se)}else this.pMask.drawRect(U[0],U[1],ie[0],ie[1]);this.pMask.endFill()}processAllTiles(U=!1){var ie,me;this.tileSize=(me=(ie=this.tilesetInfo)==null?void 0:ie.tile_size)!=null?me:1024;const Ce=this.visibleAndFetchedTiles();Ce.forEach(Be=>BI(this,m,f).call(this,Be,U)),this.combineAllTilesIfNeeded();const Ze=Ce.flatMap(Be=>this.transformDataAndCreateModels(Be));tig(Ze);const Ge=[].concat(...Ze.map(Be=>Be.data()));Ge.length!==0&&this.options.siblingIds.forEach(Be=>Vr("rawData",{id:Be,data:Ge}))}async updateTileAsync(U,ie){if(!this.tilesetInfo)return;const me=this.visibleAndFetchedTiles(),Ce=await U.getTabularData(Object.values(me).map(Ge=>Ge.remoteId)),Ze=this.tilesetInfo;me.forEach((Ge,Be)=>{if(Be===0){const[Ne]=e.utils.trackUtils.calculate1DVisibleTiles(Ze,this._xScale);Ge.tileData.zoomLevel=Ne[0],Ge.tileData.tilePos=[Ne[1],Ne[1]],Ge.tileData.tabularData=Ce}else Ge.tileData.tabularData=[]}),ie()}calculateVisibleTiles(){var U,ie,me,Ce,Ze;if(this.tilesetInfo)if(GV(this.dataFetcher)){const Ge=e.utils.trackUtils.calculate1DVisibleTiles(this.tilesetInfo,this._xScale),Be=(ie=(U=this.tilesetInfo.max_tile_width)!=null?U:this.dataFetcher.MAX_TILE_WIDTH)!=null?ie:Number.MAX_SAFE_INTEGER;for(const Ne of Ge){const{tileWidth:Se}=this.getTilePosAndDimensions(Ne[0],[Ne[1],Ne[1]]);if(this.forceDraw(),Se>Be)return}this.setVisibleTiles(Ge)}else{if(!this.tilesetInfo)return;const Ge=this.calculateZoomLevel();if("resolutions"in this.tilesetInfo){const Be=this.tilesetInfo.resolutions.map(ze=>+ze).sort((ze,Fe)=>Fe-ze),Ne=J.calculateTilesFromResolution(Be[Ge],this._xScale,this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0]);let Se;qn(this.getResolvedTracks()[0])&&(Se=J.calculateTilesFromResolution(Be[Ge],this._yScale,this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0]));const Pe=BI(me=GO,c,u).call(me,Ne,Se,Ge);this.setVisibleTiles(Pe)}else{const Be=J.calculateTiles(Ge,this.relevantScale(),this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0],this.tilesetInfo.max_zoom,this.tilesetInfo.max_width);let Ne;qn(this.getResolvedTracks()[0])&&(Ne=J.calculateTiles(Ge,this._yScale,this.tilesetInfo.min_pos[1],this.tilesetInfo.max_pos[1],this.tilesetInfo.max_zoom,(Ce=this.tilesetInfo.max_width1)!=null?Ce:this.tilesetInfo.max_width));const Se=BI(Ze=GO,c,u).call(Ze,Be,Ne,Ge);this.setVisibleTiles(Se)}}}getTilePosAndDimensions(U,ie){if(!this.tilesetInfo)throw Error("tilesetInfo not parsed");if("resolutions"in this.tilesetInfo){const Ce=this.tilesetInfo.resolutions.map(ze=>+ze).sort((ze,Fe)=>Fe-ze)[U],[Ze,Ge]=ie,Be=Ce*xt(this,d,h),Ne=Be,Se=Be*Ze,Pe=Ne*Ge;return{tileX:Se,tileY:Pe,tileWidth:Be,tileHeight:Ne}}else{const[me,Ce]=ie,Ze=this.tilesetInfo.min_pos[0],Ge=this.tilesetInfo.min_pos[1],Be=this.tilesetInfo.max_width/2**U,Ne=this.tilesetInfo.max_width/2**U,Se=Ze+me*Be,Pe=Ge+Ce*Ne;return{tileX:Se,tileY:Pe,tileWidth:Be,tileHeight:Ne}}}getIndicesOfVisibleDataInTile(U){const ie=this._xScale.range();if(!this.tilesetInfo||!U.tileData.tilePos||!("dense"in U.tileData))return[0,0];const{tileX:me,tileWidth:Ce}=this.getTilePosAndDimensions(U.tileData.zoomLevel,U.tileData.tilePos),Ze=e.libraries.d3Scale.scaleLinear().domain([0,xt(this,d,h)]).range([me,me+Ce]),Ge=Math.max(0,Math.round(Ze.invert(this._xScale.invert(ie[0])))),Be=Math.min(U.tileData.dense.length,Math.round(Ze.invert(this._xScale.invert(ie[1]))));return[Ge,Be]}receivedTiles(U){super.receivedTiles(U),GV(this.dataFetcher)&&this.drawLoadingCue()}removeOldTiles(){super.removeOldTiles(),GV(this.dataFetcher)&&this.drawLoadingCue()}combineAllTilesIfNeeded(){var U,ie,me;if(!this.shouldCombineTiles())return;const Ce=this.visibleAndFetchedTiles();if(!Ce||Ce.length<=1)return;this.tileSize=((ie=(U=this.tilesetInfo)==null?void 0:U.tile_size)!=null?ie:1024)*Ce.length;let Ze=[];Ce.forEach((Be,Ne)=>{const Se=xt(this,n)[Be.tileId];Se&&(Ze=[...Ze,...Se.tabularData],Se.skipRendering=Ne!==0)});const Ge=xt(this,n)[Ce[0].tileId];Ge.tabularData=Ze,(me=Ge.tabularData[0])!=null&&me.uid&&(Ge.tabularData=j7e(Ge.tabularData,"uid"))}shouldCombineTiles(){const U=ije(this.options.spec,"displace"),ie=()=>{const Ce=this.visibleAndFetchedTiles();return Ce.length>=1&&"dense"in Ce[0].tileData},me=this.dataFetcher instanceof nH;return U&&!ie()&&!me}getResolvedTracks(U=!1){if(U||!this.resolvedTracks){const ie=structuredClone(this.options.spec),me=y0(ie).filter(Ce=>Ce.mark!=="brush");me.forEach(Ce=>{"values"in Ce.data&&(Ce.data.values=[])}),this.resolvedTracks=me}return this.resolvedTracks}transformDataAndCreateModels(U){const ie=xt(this,n)[U.tileId];return!ie||ie.skipRendering?[]:(ie.goslingModels=[],this.getResolvedTracks().forEach(Ce=>{var Ze;let Ge=Array.from(ie.tabularData);(Ze=Ce.dataTransform)==null||Ze.forEach(_e=>{switch(_e.type){case"filter":Ge=K9e(_e,Ge);break;case"concat":Ge=TIg(_e,Ge);break;case"replace":Ge=NIg(_e,Ge);break;case"log":Ge=kIg(_e,Ge);break;case"exonSplit":Ge=FIg(_e,Ge,Ce.assembly);break;case"genomicLength":Ge=YIg(_e,Ge);break;case"svType":Ge=KIg(_e,Ge);break;case"coverage":Ge=DIg(_e,Ge,this._xScale.copy());break;case"subjson":Ge=EIg(_e,Ge);break;case"displace":Ge=xIg(_e,Ge,this._xScale.copy());break}});try{if(PubSub){const ot=Ge.length;PubSub.publish("data-preview",{id:g.viewUid,dataConfig:JSON.stringify({data:Ce.data}),data:100>ot?Ge:oU(Ge,100)})}}catch{}const[Be,Ne]=this.dimensions,Se=dX(Ce)?Or:0,[Pe,ze]=[Be,Ne+Se],Fe=Math.min(Pe,ze)/Math.min(Ce.width,Ce.height);Ce.innerRadius&&(Ce.innerRadius=Ce.innerRadius*Fe),Ce.outerRadius&&(Ce.outerRadius=Ce.outerRadius*Fe),Ce.width=Pe,Ce.height=ze;const Ue=new Cig(Ce,Ge,this.options.theme);ie.goslingModels.push(Ue)}),ie.goslingModels)}getMouseOverHtml(U,ie){var me,Ce,Ze,Ge,Be;if(BI(this,X,W).call(this,"trackMouseOver",U,ie),xt(this,o)||!this.tilesetInfo)return"";this.pMouseHover.clear();const Ne=Ku(Math.floor(this._xScale.invert(U)),xt(this,i)),Se=BI(this,V,S).call(this,U,ie);if(Se.length!==0?document.body.style.cursor="pointer":document.body.style.cursor="default",Se.length!==0){const Pe=(me=this.options.spec.experimental)==null?void 0:me.mouseEvents;if(!!Pe||Sm(Pe)&&!!Pe.mouseOver){const _e=this.pMouseHover;((Ze=(Ce=this.options.spec.style)==null?void 0:Ce.mouseOver)==null?void 0:Ze.arrange)!=="behind"&&(this.pMain.removeChild(_e),this.pMain.addChild(_e)),BI(this,Y,D).call(this,_e,Se,Object.assign({},rle,(Ge=this.options.spec.style)==null?void 0:Ge.mouseOver)),Vr("mouseOver",{id:g.viewUid,genomicPosition:Ne,data:Se.map(ot=>ot.value)})}const Ue=(Be=this.visibleAndFetchedGoslingModels().find(_e=>{var ot;return _e.spec().tooltip&&((ot=_e.spec().tooltip)==null?void 0:ot.length)!==0}))==null?void 0:Be.spec().tooltip;if(Ue){let _e=Ue.map(ot=>{var Zt;const nt=Se[0].value[ot.field];let Te=nt;if(ot.type==="quantitative"&&ot.format)Te=e.libraries.d3Format.format(ot.format)(+nt);else if(ot.type==="genomic"){const{chromosome:se,position:ye}=Ku(+nt,xt(this,i));Te=`${se}:${e.libraries.d3Format.format(",")(ye)}`}return`${(Zt=ot.alt)!=null?Zt:ot.field}${Te}`}).join("");return _e=`${_e}
`,Se.length>1&&(_e+=`
${Se.length-1} Additional Selections...
`),`
${_e}
`}}return""}minVisibleValue(){return 0}maxVisibleValue(){return 0}exportSVG(){throw new Error("exportSVG() not supported for gosling-track")}drawLoadingCue(){if(this.fetching.size){const ie=`Fetching... ${Array.from(this.fetching).join(" ")}`;xt(this,l).text=ie,xt(this,l).x=this.position[0]+this.dimensions[0]-6/2,xt(this,l).y=this.position[1]+this.dimensions[1]-6/2;const me=e.libraries.PIXI.TextMetrics.measureText(ie,xt(this,s)),{width:Ce,height:Ze}=me;xt(this,a).clear(),xt(this,a).lineStyle(1,ft("grey"),1,.5),xt(this,a).beginFill(ft("white"),.8),xt(this,a).drawRect(this.position[0]+this.dimensions[0]-Ce-6-1,this.position[1]+this.dimensions[1]-Ze-6-1,Ce+6,Ze+6),xt(this,l).visible=!0,xt(this,a).visible=!0}else xt(this,l).visible=!1,xt(this,a).visible=!1}updateScaleOffsetFromOriginalSpec(U,ie,me){this.getResolvedTracks().map(Ce=>{if(Ce._renderingId===U){const Ze=Ce[me];st(Ze)&&(Ze.scaleOffset=ie)}})}shareScaleOffsetAcrossTracksAndTiles(U,ie){this.visibleAndFetchedGoslingModels().forEach(Ce=>{const Ze=Ce.spec()[ie];st(Ze)&&(Ze.scaleOffset=U);const Ge=Ce.originalSpec()[ie];st(Ge)&&(Ge.scaleOffset=U)})}};i=new WeakMap,n=new WeakMap,C=new WeakMap,r=new WeakMap,o=new WeakMap,A=new WeakMap,s=new WeakMap,a=new WeakMap,l=new WeakMap,c=new WeakSet,u=function(te,U,ie){if(!U)return te.map(Ce=>[ie,Ce]);const me=[];return te.forEach(Ce=>U.forEach(Ze=>me.push([ie,Ce,Ze]))),me},d=new WeakSet,h=function(){let te;return this.tilesetInfo&&(te="bins_per_dimension"in this.tilesetInfo?this.tilesetInfo.bins_per_dimension:this.tilesetInfo.tile_size),te??256},m=new WeakSet,f=function(te,U=!1){if(xt(this,n)[te.tileId]&&!U||!te.tileData.tilePos)return;const ie=Aig(),me=this.getResolvedTracks();if(me.length===0)return[];const Ce=me[0];if("tabularData"in te.tileData)ie.tabularData=te.tileData.tabularData;else{const{tileX:Ze,tileY:Ge,tileWidth:Be,tileHeight:Ne}=this.getTilePosAndDimensions(te.tileData.zoomLevel,te.tileData.tilePos),Se="length"in te.tileData?Array.from(te.tileData):[],Pe=Object.assign({},te.tileData,{sparse:Se,tileX:Ze,tileY:Ge,tileWidth:Be,tileHeight:Ne,tileSize:this.tileSize}),ze=QIg(Ce,Pe);ze&&(ie.tabularData=ze)}xt(this,n)[te.tileId]=ie},b=new WeakSet,p=function(te,U,ie){var me;vC(this,C,te),vC(this,r,U);const Ce=(me=this.options.spec.experimental)==null?void 0:me.mouseEvents,Ze=!!Ce||Sm(Ce)&&!!Ce.rangeSelect;vC(this,o,Ze&&ie),this.pMouseHover.clear()},y=new WeakSet,Z=function(te){this.options.spec.layout!=="circular"&&xt(this,o)&&this.mRangeBrush.updateRange([te,xt(this,C)]).drawBrush().visible().disable()},B=new WeakSet,G=function(te,U){var ie;BI(this,X,W).call(this,"trackClick",te,U);const me=(ie=this.options.spec.experimental)==null?void 0:ie.mouseEvents,Ce=!!me||Sm(me)&&!!me.click,Ze=Math.sqrt((xt(this,C)-te)**2+(xt(this,r)-U)**2)>1;if(!xt(this,o)&&!Ze?(this.mRangeBrush.clear(),this.pMouseSelection.clear()):this.mRangeBrush.enable(),vC(this,o,!1),!!this.tilesetInfo&&!Ze&&Ce){const Ge=Ku(Math.floor(this._xScale.invert(te)),xt(this,i)),Be=BI(this,V,S).call(this,te,U);Be.length!==0&&this.options.siblingIds.forEach(Ne=>Vr("click",{id:Ne,genomicPosition:Ge,data:Be.map(Se=>Se.value)}))}},v=new WeakSet,w=function(){vC(this,o,!1),document.body.style.cursor="default",this.pMouseHover.clear()},V=new WeakSet,S=function(te,U){var ie;const me=this.visibleAndFetchedGoslingModels(),Ce=(ie=this.options.spec.experimental)==null?void 0:ie.mouseEvents,Ze=Sm(Ce)&&Ce.enableMouseOverOnMultipleMarks,Ge=Sm(Ce)&&Ce.groupMarksByField,Be=me.map(Ne=>Ne.getMouseEventModel().findAll(te,U,!0)).flat();if(Ze||Be.splice(1,Be.length-1),Be.length!==0&&Ge){const Ne=Array.from(Be);me.forEach(Se=>{const Pe=Se.getMouseEventModel().getSiblings(Ne,Ge);Be.push(...Pe)})}return Be},X=new WeakSet,W=function(te,U,ie){const[me,Ce]=this.position,[Ze,Ge]=this.dimensions;if(this.options.spec.layout==="circular"){const Be=me+Ze/2,Ne=Ce+Ge/2,Se=this.options.spec.innerRadius,Pe=this.options.spec.outerRadius,ze=this.options.spec.startAngle,Fe=this.options.spec.endAngle;gtg([U,ie],[Ze/2,Ge/2],[Se,Pe],[ze,Fe])&&Vr(te,{id:g.viewUid,spec:structuredClone(this.options.spec),shape:{x:me,y:Ce,width:Ze,height:Ge,cx:Be,cy:Ne,innerRadius:Se,outerRadius:Pe,startAngle:ze,endAngle:Fe}})}else Vr(te,{id:g.viewUid,spec:structuredClone(this.options.spec),shape:{x:me,y:Ce,width:Ze,height:Ge}})},R=new WeakSet,H=function(te,U=!1){var ie,me,Ce,Ze;if(this.pMouseSelection.clear(),te===null){U||Vr("rangeSelect",{id:g.viewUid,genomicRange:null,data:[]});return}const Ge=this.visibleAndFetchedGoslingModels(),[Be,Ne]=te;let Se=Ge.map(Fe=>Fe.getMouseEventModel().findAllWithinRange(Be,Ne,!0)).flat();const Pe=(ie=this.options.spec.experimental)==null?void 0:ie.mouseEvents,ze=Sm(Pe)&&Pe.groupMarksByField;if(Se.length!==0&&ze&&Ge.forEach(Fe=>{const Ue=Fe.getMouseEventModel().getSiblings(Se,ze),_e=Array.from(new Set(Ue.map(ot=>ot.value[ze])));Se=Se.filter(ot=>_e.indexOf(ot.value[ze])===-1)}),Se.length!==0){const Fe=this.pMouseSelection;((Ce=(me=this.options.spec.style)==null?void 0:me.select)==null?void 0:Ce.arrange)!=="behind"&&(this.pMain.removeChild(Fe),this.pMain.addChild(Fe)),BI(this,Y,D).call(this,Fe,Se,Object.assign({},rle,(Ze=this.options.spec.style)==null?void 0:Ze.select))}if(!U){const Fe=[Ku(Math.floor(this._xScale.invert(Be)),xt(this,i)),Ku(Math.floor(this._xScale.invert(Ne)),xt(this,i))];Vr("rangeSelect",{id:g.viewUid,genomicRange:Fe,data:Se.map(Ue=>Ue.value)})}this.forceDraw()},Y=new WeakSet,D=function(te,U,ie){te.lineStyle(ie.strokeWidth,ft(ie.stroke),ie.strokeOpacity,.5),te.beginFill(ft(ie.color),ie.color==="none"?0:ie.opacity),U.forEach(me=>{if(me.type==="point"){const[Ce,Ze,Ge=3]=me.polygon;te.drawCircle(Ce,Ze,Ge)}else me.type==="line"?(te.moveTo(me.polygon[0],me.polygon[1]),EQe(me.polygon).map(Ce=>te.lineTo(Ce[0],Ce[1]))):te.drawPolygon(me.polygon)})},E=new WeakSet,O=function(){Vr("onNewTrack",{id:g.viewUid})},hg($,c);let j=$;return new j},xR=L4(aig,sig),lig={type:"dummy-track",defaultOptions:{height:0,width:0,title:"",background:"#fff",textFontSize:12,textFontWeight:"normal",textStroke:"#000",textStrokeWidth:.1,outline:"#fff"}},cig=(e,g,I)=>{var i,n,C,r;const{SVGTrack:o}=e.tracks;class A extends o{constructor(){super(g,I),hg(this,i),hg(this,C),BI(this,i,n).call(this),BI(this,C,r).call(this),Vr("onNewTrack",{id:g.viewUid})}}return i=new WeakSet,n=function(){this.gMain.append("rect").attr("fill",I.background).attr("x",0).attr("y",0).attr("width",I.width).attr("height",I.height).style("stroke",I.outline)},C=new WeakSet,r=function(){this.gMain.append("text").attr("x",I.width/2).attr("y",(I.height+I.textFontSize)/2).style("text-anchor","middle").style("font-size",`${I.textFontSize}px`).style("font-weight",I.textFontWeight).style("stroke",I.textStroke).style("stroke-width",I.textStrokeWidth).text(I.title)},new A},ole=L4(lig,cig);let Ale=!1;function uig(){if(!Ale){mu({name:"GoslingTrack",track:xR,config:xR.config}),mu({name:"Gosling2DTrack",track:xR,config:{...xR.config,type:"gosling-2d-track",orientation:"2d"}}),mu({name:"AxisTrack",track:hse,config:hse.config}),mu({name:"TextTrack",track:TM,config:TM.config}),mu({name:"BrushTrack",track:cO,config:cO.config}),mu({name:"DummyTrack",track:ole,config:ole.config});for(const e of Object.values(LIg)){const{config:g}=e;mu({dataFetcher:e,config:g},{pluginType:"dataFetcher"})}Ale=!0}}function J9e(e){let g=0,I=0;return e.forEach(i=>{const n=i.boundingBox.x+i.boundingBox.width,C=i.boundingBox.y+i.boundingBox.height;I{s.boundingBox.y+=o+A}),n=[{track:hig({width:C.width,height:o},e.title,e.subtitle),boundingBox:{x:0,y:0,width:C.width,height:o},layout:{x:0,y:0,w:12,h:o/C.height*12}},...n]}else C.height=C.height+(8-C.height%8);const r=!(typeof e.responsiveSize!="object"?e.responsiveSize:e.responsiveSize.height);return n.forEach(o=>{o.layout.x=o.boundingBox.x/C.width*12,o.layout.w=o.boundingBox.width/C.width*12,o.layout.y=r?o.boundingBox.y:o.boundingBox.y/C.height*12,o.layout.h=r?o.boundingBox.height:o.boundingBox.height/C.height*12}),{trackInfos:n,size:C}}function vO(e,g,I=0,i=0,n=!0){let C=0,r=0,o=!0,A=!1;Ab(e,c=>{A=!0,c.layout!=="circular"&&(o=!1)});let s=!0;Lpe(e,c=>{(c.arrangement==="vertical"||c.arrangement==="horizontal")&&(s=!1)});const a=n&&o&&A&&s&&("views"in e&&(e.arrangement==="parallel"||e.arrangement==="serial")||"tracks"in e),l=g.length;if("tracks"in e){const c=e.tracks;e.orientation==="vertical"?(r=Math.max(...c.map(u=>u.height)),c.forEach((u,d,h)=>{sle([u])===1&&(u.width+=Or),u.height=r,g.push({track:u,boundingBox:{x:I+C,y:i,width:u.width,height:r},layout:{x:0,y:0,w:0,h:0}}),h[d+1]&&h[d+1].overlayOnPreviousTrack||(C+=u.width,d!==h.length-1&&(C+=e.spacing!==void 0?e.spacing:0))})):(C=Math.max(...c.map(u=>u.width)),c.forEach((u,d,h)=>{sle([u])===1&&(u.height+=Or);const m=y0(u);m.length>0&&qn(m[0])&&dig([u])===1&&(C+=Or),u.width=C,g.push({track:u,boundingBox:{x:I,y:i+r,width:C,height:u.height},layout:{x:0,y:0,w:0,h:0}}),h[d+1]&&h[d+1].overlayOnPreviousTrack||(r+=u.height,d!==h.length-1&&(r+=e.spacing!==void 0?e.spacing:0))}))}else if(e.arrangement==="parallel"||e.arrangement==="vertical"){const c=e.spacing!==void 0?e.spacing:s1;e.views.forEach((u,d,h)=>{var m,f,b,p,y;const Z=vO(u,g,I+((m=u.xOffset)!=null?m:0),i+((f=u.yOffset)!=null?f:0)+r,!a&&n);C<((b=u.xOffset)!=null?b:0)+Z.width&&(C=((p=u.xOffset)!=null?p:0)+Z.width),d!==h.length-1&&(r+=c),r+=((y=u.yOffset)!=null?y:0)+Z.height})}else(e.arrangement==="serial"||e.arrangement==="horizontal")&&e.views.forEach((c,u,d)=>{var h,m,f,b,p;const y=e.spacing!==void 0?e.spacing:s1,Z=vO(c,g,I+((h=c.xOffset)!=null?h:0)+C,i+((m=c.yOffset)!=null?m:0),!a&&n);r<((f=c.xOffset)!=null?f:0)+Z.height&&(r=((b=c.xOffset)!=null?b:0)+Z.height),u!==d.length-1&&(C+=y),C+=((p=c.xOffset)!=null?p:0)+Z.width});if(a){const c=g.slice(l),u="views"in e&&(e.arrangement==="parallel"||e.arrangement==="serial")&&e.views.length>1,d=e.spacing!==void 0?e.spacing:s1,h=BQe,m=e.centerRadius!==void 0?e.centerRadius:cpe,f=C/2+h,b=f*(1-m);c.forEach((p,y)=>{var Z,B;if(aS(p.track))return;p.track.layout="circular",p.track.outerRadius=f-h-(p.boundingBox.y-i)/r*b,p.track.innerRadius=f-h-(p.boundingBox.y+p.boundingBox.height-i)/r*b;const G=d/C*360;p.track.startAngle=G+(p.boundingBox.x-I)/C*(C-d)/C*360,p.track.endAngle=(p.boundingBox.x+p.boundingBox.width-I)/C*(C-d)/C*360,p.boundingBox.x=I+((Z=p.track.xOffset)!=null?Z:0),p.boundingBox.y=i+((B=p.track.yOffset)!=null?B:0),p.boundingBox.height=p.track.height=p.boundingBox.width=p.track.width=f*2,y!==0&&(p.track.overlayOnPreviousTrack=!0),u&&ai(p.track)&&(p.track._overlay=p.track._overlay.filter(v=>v.mark!=="brush"))}),r=f*2}return e._assignedWidth=C,e._assignedHeight=r,{x:I,y:i,width:C,height:r}}function sle(e){return e.filter(g=>dX(g)).length}function dig(e){return e.filter(g=>yje(g)).length}const hig=(e,g,I)=>JSON.parse(JSON.stringify({mark:"header",width:e.width,height:e.height,title:g,subtitle:I}));function mig(e){if(!e.includes("tileset_info/?d=")||!e.includes("https:")&&!e.includes("http:"))return{server:void 0,tilesetUid:void 0};const g=e.split("tileset_info/?d=")[0],I=e.split("tileset_info/?d=")[1];return{server:g,tilesetUid:I}}function fig(e,g,I,i,n,C,r){var o,A,s,a,l,c,u,d,h,m,f,b,p,y,Z;if(aS(g))return e.addDefaultView(g.id).setDummyTrack(g).setLayout(i),e;const B=y0(g),G=B[0],v=(o=G.id)!=null?o:rn();G.id||(G.id=v),B.forEach(V=>{V.id&&C.addMapping(V.id,v)});const w=G.assembly;if(zee(G.data)){let V,S;if(lU(G.data)){const ee=mig(G.data.url);V=ee.server,S=ee.tilesetUid}const X=_4(G),W=C9e(G),H=(W==="x"||W==="xe")&&st(X)?X.domain:void 0,Y=qn(G)&&st(G.y)?G.y.domain:void 0,D=I.width-(G.layout!=="circular"&&G.orientation==="vertical"&&dX(G)?Or:0),E=I.height-(G.layout!=="circular"&&G.orientation==="horizontal"&&dX(G)?Or:0),O={uid:`${v}-track`,type:qn(G)?"gosling-2d-track":"gosling-track",server:V,tilesetUid:S,width:D,height:E,options:{id:v,siblingIds:C.getSiblingGoslingIds(v),showMousePosition:G.layout==="circular"?!1:n.root.showMousePosition,mousePositionColor:n.root.mousePositionColor,name:G.layout==="linear"?G.title:" ",labelPosition:G.title?n.track.titleAlign==="left"?"topLeft":"topRight":"none",labelShowResolution:!1,labelColor:n.track.titleColor,labelBackgroundColor:n.track.titleBackground,labelBackgroundOpacity:.5,labelTextOpacity:1,labelLeftMargin:1,labelTopMargin:1,labelRightMargin:0,labelBottomMargin:0,backgroundColor:"transparent",spec:{...g},theme:n}};if(G.data&&zee(G.data)&&(G.data.type==="csv"||G.data.type==="json"||G.data.type==="bigwig"||G.data.type==="bam"||G.data.type==="vcf"||G.data.type==="gff"||G.data.type==="bed")){const ee=te=>{const U=G[te];return U&&st(U)?U.field:void 0},q={x:ee("x"),xe:ee("xe"),x1:ee("x1"),x1e:ee("x1e")},$="url"in G.data&&(r==null?void 0:r[G.data.url])||{},j="indexUrl"in G.data&&(r==null?void 0:r[G.data.indexUrl])||{};O.data={...G.data,...q,urlFetchOptions:$,indexUrlFetchOptions:j,assembly:w}}if(uje(G)){O.type="heatmap";const ee=st(G.color)&&typeof G.color.range=="string"?G.color.range:"viridis";O.options.colorRange=nje(ee),O.options.trackBorderWidth=(s=(A=G.style)==null?void 0:A.outlineWidth)!=null?s:n.track.outlineWidth,O.options.trackBorderColor=(l=(a=G.style)==null?void 0:a.outline)!=null?l:n.track.outline,O.options.extent=(u=(c=G.style)==null?void 0:c.matrixExtent)!=null?u:"full",O.options.colorbarPosition=(d=G.color)!=null&&d.legend?O.options.extent==="lower-left"?"bottomLeft":"topRight":"hidden"}G.overlayOnPreviousTrack?e.setViewOrientation(G.orientation).addTrackToCombined(O):e.setViewOrientation(G.orientation).setAssembly(w).addDefaultView(v,w).setDomain(H,Y??H).adjustDomain(G.orientation,D,E).setMainTrack(O).addTrackSourceServers(V).setZoomFixed(G.static===!0).setZoomLimits((h=G.zoomLimits)!=null?h:[1,null]).setLayout(i);const J=(ee,q="horizontal",$,j)=>q==="horizontal"?ee==="x"&&$<=200||ee==="y"&&j<=200?"narrower":ee==="x"&&$<=400||ee==="y"&&j<=400?"narrow":"regular":ee==="x"&&j<=200||ee==="y"&&$<=200?"narrower":ee==="x"&&j<=400||ee==="y"&&$<=400?"narrow":"regular";["x","y"].forEach(ee=>{const q=G[ee];if(st(q)&&"axis"in q&&q.axis&&q.axis!=="none"&&q.type==="genomic"){const $=J(ee,g.orientation,I.width,I.height);e.setAxisTrack(q.axis,$,{id:`${v}-${q.axis}-axis`,layout:G.layout,innerRadius:q.axis==="top"?G.outerRadius-Or:G.innerRadius,outerRadius:q.axis==="top"?G.outerRadius:G.innerRadius+Or,width:G.width,height:G.height,startAngle:G.startAngle,endAngle:G.endAngle,theme:n})}}),e.validateSpec(!0)}else G.mark==="header"&&(e.addDefaultView(`${v}-title`).setLayout(i),typeof G.title=="string"&&e.setTextTrack(I.width,((m=n.root.titleFontSize)!=null?m:18)+cX,G.title,n.root.titleColor,(f=n.root.titleFontSize)!=null?f:18,n.root.titleFontWeight,n.root.titleAlign,n.root.titleBackgroundColor,(b=n.root.titleFontFamily)!=null?b:pM.fontFamily),typeof G.subtitle=="string"&&e.setTextTrack(I.width,((p=n.root.subtitleFontSize)!=null?p:14)+cX,G.subtitle,n.root.subtitleColor,(y=n.root.subtitleFontSize)!=null?y:14,n.root.subtitleFontWeight,n.root.subtitleAlign,n.root.subtitleBackgroundColor,(Z=n.root.subtitleFontFamily)!=null?Z:pM.fontFamily));return e}function pig(e){const g=[];return e.spec().views.forEach(I=>{var i,n,C,r,o,A,s,a,l,c,u,d,h,m,f;const b=I.uid;let p=(o=(r=(C=(n=(i=I.tracks.center)==null?void 0:i[0])==null?void 0:n.contents)==null?void 0:C[0])==null?void 0:r.options)==null?void 0:o.spec;if(p||(p=(c=(l=(a=(s=(A=I.tracks.left)==null?void 0:A[0])==null?void 0:s.contents)==null?void 0:a[0])==null?void 0:l.options)==null?void 0:c.spec,p||(p=(f=(m=(h=(d=(u=I.tracks.left)==null?void 0:u[1])==null?void 0:d.contents)==null?void 0:h[0])==null?void 0:m.options)==null?void 0:f.spec)),!b||!p)return;y0(p).forEach(Z=>{pd.forEach(B=>{var G,v,w,V;const S=Z[B];if(st(S)&&"linkingId"in S&&S.linkingId){g.push({layout:Z.layout==="circular"?"circular":"linear",hgViewId:b,linkId:S.linkingId,isBrush:Z.mark==="brush",style:{color:(G=Z.color)==null?void 0:G.value,stroke:(v=Z.stroke)==null?void 0:v.value,strokeWidth:(w=Z.strokeWidth)==null?void 0:w.value,opacity:(V=Z.opacity)==null?void 0:V.value,startAngle:Z.startAngle,endAngle:Z.endAngle,innerRadius:Z.innerRadius,outerRadius:Z.outerRadius}});return}})})}),g}class big{constructor(){hg(this,Pa,{})}addMapping(g,I){xt(this,Pa)[g]&&xt(this,Pa)[g]!==I&&console.warn(`The track ID ${g} already exists but overwriting with a different ID.`),xt(this,Pa)[g]=I}getTable(){return xt(this,Pa)}getGoslingIds(){return Object.keys(xt(this,Pa))}getHiGlassId(g){return xt(this,Pa)[g]}getSiblingGoslingIds(g){return Object.entries(xt(this,Pa)).filter(([,I])=>I===g).map(([I])=>I)}}Pa=new WeakMap;function yig(e){const g=new Set;return e.id&&g.add(e.id),Ab(e,I=>{("views"in I||"tracks"in I)&&I.id&&g.add(I.id)}),Array.from(g)}function Zig(e){const g=new Set;return Ab(e,I=>{!("views"in I)&&!("tracks"in I)&&I.id&&g.add(I.id)}),Array.from(g)}function Gig(e,g){let I;return e.id===g&&(I=e),Ab(e,i=>{i.id===g&&(I=i)}),I}function vig(e,g){return yig(e).map(I=>{const i=Gig(e,I),n=Zig(i),C={x:Number.MAX_SAFE_INTEGER,y:Number.MAX_SAFE_INTEGER,xe:-Number.MAX_SAFE_INTEGER,ye:-Number.MAX_SAFE_INTEGER};return n.map(r=>g.find(o=>o.id===r)).forEach(r=>{if(!r)return;const{shape:o}=r;C.x>o.x&&(C.x=o.x),C.y>o.y&&(C.y=o.y),C.xe{const{track:u,boundingBox:d,layout:h}=c;fig(C,u,d,h,i,r,n)});const o=pig(C);o.filter(c=>c.isBrush).forEach(c=>{var u;C.addBrush(c.layout,c.hgViewId,i,(u=o.find(d=>!d.isBrush&&d.linkId===c.linkId))==null?void 0:u.hgViewId,c.style)}),o.filter(c=>!c.isBrush).forEach(c=>{C.spec().zoomLocks.locksByViewUid[c.hgViewId]=c.linkId,C.spec().locationLocks.locksByViewUid[c.hgViewId]=c.linkId}),Array.from(new Set(o.map(c=>c.linkId))).forEach(c=>{C.spec().zoomLocks.locksDict[c]={uid:c},C.spec().locationLocks.locksDict[c]={uid:c},o.filter(u=>!u.isBrush).filter(u=>u.linkId===c).forEach(u=>{C.spec().zoomLocks.locksDict[c][u.hgViewId]=[1246253105e-1,1246253105e-1,249250.621],C.spec().locationLocks.locksDict[c][u.hgViewId]=[1246253105e-1,1246253105e-1,249250.621]})});const s=g.map(c=>({id:c.track.id,spec:c.track,shape:c.track.layout==="linear"||aS(c.track)?c.boundingBox:{...c.boundingBox,cx:c.boundingBox.x+c.boundingBox.width/2,cy:c.boundingBox.y+c.boundingBox.height/2,innerRadius:c.track.innerRadius,outerRadius:c.track.outerRadius,startAngle:c.track.startAngle,endAngle:c.track.endAngle}})),a=vig(e,s),l=[...s.map(c=>({...c,type:"track"})),...a.map(c=>({...c,type:"view"}))];I(C.spec(),J9e(g),e,l,r.getTable())}function O9e(e,g,I,i,n){if(typeof e._assignedWidth>"u"||typeof e._assignedHeight>"u")return console.warn("Responsive spec cannot be used when width and height of a view is not determined yet."),!1;let C=!1;const{responsiveSpec:r}=e,o=e._assignedWidth*g,A=e._assignedHeight*I,s={width:o,height:A,aspectRatio:o/A},a={width:i,height:n,aspectRatio:i/n};return r&&r.forEach(l=>{const{spec:c,selectivity:u}=l;if(Sig(u,s,a)&&!C){Object.keys(c).forEach(d=>{e[d]=c[d]}),delete e.responsiveSpec,C=!0;return}}),"views"in e&&e.views.forEach(l=>{C=O9e(l,g,I,i,n)||C}),C}function Sig(e,g,I){if(e.length===0)return!1;let i=!0;return e.forEach(n=>{const{measure:C,operation:r,threshold:o,target:A}=n;i=i&&gG((A==="container"?I:g)[C],r,o)===1}),i}function wig(e,g,I,i,n,C){var r,o;const A=JSON.parse(JSON.stringify(e));Q$e(A),Neg(A,I),RM(A);const s=ale(A,i);let{trackInfos:a}=s;const{size:l}=s,c=typeof e.responsiveSize=="object"&&((r=e.responsiveSize)==null?void 0:r.width)||e.responsiveSize,u=typeof e.responsiveSize=="object"&&((o=e.responsiveSize)==null?void 0:o.height)||e.responsiveSize,d=c&&n.containerSize?n.containerSize.width/l.width:1,h=u&&n.containerSize?n.containerSize.height/l.height:1,m=n.containerParentSize?n.containerParentSize.width:Number.MAX_SAFE_INTEGER,f=n.containerParentSize?n.containerParentSize.height:Number.MAX_SAFE_INTEGER;O9e(A,d,h,m,f)&&(RM(A),a=ale(A,i).trackInfos),Vr("specProcessed",{id:A.id,spec:A}),Big(A,a,g,i,C)}uig();const _9e=Ie.forwardRef((e,g)=>{var I;const[i,n]=Ie.useState((I=e.id)!=null?I:rn());Ie.useEffect(()=>{var u;n((u=e.id)!=null?u:rn())},[e.id]);const C=e.viewConfig||{},r=!1,o=Ie.useMemo(()=>N.createElement(gy,{ref:g,options:{pixelPreciseMarginPadding:r,containerPaddingX:0,containerPaddingY:0,viewMarginTop:0,viewMarginBottom:0,viewMarginLeft:0,viewMarginRight:0,viewPaddingTop:0,viewPaddingBottom:0,viewPaddingLeft:0,viewPaddingRight:0,sizeMode:"bounded",rangeSelectionOnAlt:!0},viewConfig:C}),[C,r]),{padding:A=60,margin:s=0,border:a="none",background:l,alt:c="Gosling visualization"}=e.options||{};return N.createElement(N.Fragment,null,N.createElement("div",{id:i,className:`gosling-component ${e.className||""}`,style:{position:"relative",padding:A,margin:s,border:a,background:l,width:e.options.responsiveWidth?`calc(100% - ${A*2}px)`:e.size.width,height:e.options.responsiveHeight?`calc(100% - ${A*2}px)`:e.size.height,textAlign:"left"},"aria-label":c,role:"graphics-document","aria-roledescription":"visualization"},N.createElement("div",{key:JSON.stringify(C),id:"higlass-wrapper",className:"higlass-wrapper",style:{position:"relative",display:"block",background:l,margin:0,padding:0,width:e.options.responsiveWidth?"100%":e.size.width,height:e.options.responsiveHeight?"100%":e.size.height}},o)))});_9e.displayName="HiGlassComponentWrapper";function Vig(e,g,I,i,n){const C=structuredClone(n),r=d=>{const h=C[d];return h||console.warn(`Unable to find the track ID, named ${d}.`),h??d},o=()=>Object.keys(C),A=()=>[...I],s=()=>[...A().filter(d=>d.type==="track")],a=d=>{const h=s().find(m=>m.id===d);return h||console.warn(`[getTrack()] Unable to find a track using the ID (${d})`),h},l=()=>[...A().filter(d=>d.type==="view")],c=d=>{const h=l().find(m=>m.id===d);return h||console.warn(`Unable to find a view with the ID of ${d}`),h},u=d=>{var h,m;const f=(h=d==null?void 0:d.resolution)!=null?h:4,b=(m=d==null?void 0:d.transparentBackground)!=null?m:!1,p=e.pixiRenderer,y=Ws.create({width:p.width/2,height:p.height/2,resolution:f});p.render(e.pixiStage,y);const Z=p.plugins.extract.canvas(y),B=document.createElement("canvas");B.width=Z.width,B.height=Z.height;const G=B.getContext("2d");return b||(G.fillStyle=i.root.background,G.fillRect(0,0,B.width,B.height)),G.drawImage(Z,0,0),{canvas:B,resolution:f,canvasWidth:Z.width,canvasHeight:Z.height}};return{subscribe:rig,unsubscribe:oig,zoomTo:(d,h,m=0,f=1e3)=>{var b;const p=(b=a(d))==null?void 0:b.spec.assembly,Z=ZU.fromString(h).toAbsoluteCoordinates(p,m),B=r(d);e.api.zoomTo(B,...Z,...Z,f)},zoomToExtent:(d,h=1e3)=>{var m;const f=(m=a(d))==null?void 0:m.spec.assembly,[b,p]=[0,pI(f).total],y=r(d);e.api.zoomTo(y,b,p,b,p,h)},zoomToGene:(d,h,m=0,f=1e3)=>{const b=r(d);e.api.zoomToGene(b,h,m,f)},suggestGene:(d,h,m)=>{const f=r(d);e.api.suggestGene(f,h,m)},getTrackIds:o,getTracksAndViews:A,getTracks:s,getTrack:a,getView:c,getViews:l,getCanvas:u,exportPng:d=>{const{canvas:h}=u({resolution:4,transparentBackground:d});h.toBlob(m=>{const f=document.createElement("a");document.body.append(f),f.download="gosling-visualization",f.href=URL.createObjectURL(m),f.click(),f.remove()},"image/png")},exportPdf:async d=>{const{jsPDF:h}=await IKe(()=>import("./jspdf.es.min-9eaca9d8.js").then(p=>p.j),[]),{canvas:m}=u({resolution:4,transparentBackground:d}),f=m.toDataURL("image/jpeg",1),b=new h({orientation:m.width{sU(I)&&g.forEach(i=>{delete I[i]})})}const Rig=(e,g)=>{e.views.forEach(I=>{var i,n,C;const r=I.uid;if(!g.views.find(A=>A.uid===r)){const{locksByViewUid:A}=e.zoomLocks,s=A[r],a=(i=Object.entries(A).find(([c,u])=>c&&u===s))==null?void 0:i[0],l=!!g.views.find(c=>c.uid===a);a&&l&&(I.initialXDomain=(n=g.views.find(c=>c.uid===a))==null?void 0:n.initialXDomain,I.initialYDomain=(C=g.views.find(c=>c.uid===a))==null?void 0:C.initialYDomain)}})},Wig=300,L9e=Ie.forwardRef((e,g)=>{var I,i,n;const[C,r]=Ie.useState(),[o,A]=Ie.useState({width:200,height:200}),s=Ie.useRef(),a=Ie.useRef(),l=Ie.useRef(),c=Ie.useRef([]),u=Ie.useRef({}),d=Ie.useRef(null),h=P9e(e.theme||"light"),m=(I=e.id)!=null?I:rn(),f=Z=>{const B=c.current.filter(V=>V.type=="view"),G=Z.filter(V=>V.type=="view"),v=new Set(B.map(V=>V.id));G.filter(V=>!v.has(V.id)).forEach(V=>{Vr("onNewView",{id:V.id})})};Ie.useImperativeHandle(g,()=>{const Z=cle(d),B=cle(c);return{api:Vig(Z,C,B,h,u.current),hgApi:Z}},[C,h]);const b=Ie.useCallback(()=>{if(e.spec){if(Heg(e.spec).state==="error"){console.warn("Gosling spec is not valid. Please refer to the console message.");return}wig(e.spec,(B,G,v,w,V)=>{var S,X;if(l.current&&ope(lle(l.current,["linkingId"]),lle(v,["linkingId"])))return;(S=e.compiled)==null||S.call(e,e.spec,B,{_processedSpec:v}),A(G);const W=typeof C<"u";(X=e.experimental)!=null&&X.reactive&&W?setTimeout(()=>{var R,H;Rig(B,(R=d.current)==null?void 0:R.api.getViewConfig()),(H=d.current)==null||H.api.setViewConfig(B)},Wig):r(B),f(w),l.current=v,c.current=w,u.current=V},[...Teg],h,{containerSize:s.current,containerParentSize:a.current},e.urlToFetchOptions)}},[e.spec,h]);Ie.useEffect(()=>{var Z;if(!((Z=e.spec)!=null&&Z.responsiveSize))return;const B=document.getElementById(m);if(!B)return;const G=new ise.ResizeSensor(B,V=>{(!s.current||s.current.height!==V.height||s.current.width!==V.width)&&(s.current=V,b())}),v=B.parentElement;if(!v)return;const w=new ise.ResizeSensor(v,V=>{(!a.current||a.current.height!==V.height||a.current.width!==V.width)&&(a.current=V,b())});return()=>{G.detach(),w.detach()}}),Ie.useEffect(()=>{b()},[e.spec,h]);const p=typeof((i=e.spec)==null?void 0:i.responsiveSize)!="object"?(n=e.spec)==null?void 0:n.responsiveSize:e.spec.responsiveSize.height;return Ie.useMemo(()=>{var Z,B,G;return N.createElement(_9e,{ref:d,viewConfig:C,size:o,id:m,className:e.className,options:{padding:e.padding,border:e.border,margin:e.margin,responsiveWidth:typeof((Z=e.spec)==null?void 0:Z.responsiveSize)!="object"?(B=e.spec)==null?void 0:B.responsiveSize:e.spec.responsiveSize.width,responsiveHeight:p,background:h.root.background,alt:(G=e.spec)==null?void 0:G.description}})},[C,o,h,p])});L9e.displayName="GoslingComponent";function cle(e){return new Proxy({},{get(g,I,i){if(!e.current)throw Error("ref is not set!");return Reflect.get(e.current,I,i)}})}var ule=UI;ule.createRoot,ule.hydrateRoot;const Xig=["x","xe","x1","x1e","y","ye","y1","y1e","color","size","row","stroke","strokeWidth","opacity","text"];function Hig(e){return typeof e=="object"&&e!==null}function Tig(e){return"alignment"in e&&e.alignment==="overlay"}function Nig(e){return e!==null&&typeof e=="object"&&"value"in e}function kig(e){return Hig(e)&&!("value"in e)}function dle(e,g){return g in e}function Wd(e){return e.length===1?e[0]:e.slice(0,-1).join(", ")+" and "+e.slice(-1)}function Yig(e){return e[0].toUpperCase()+e.slice(1)}const En=new Map([["point","points"],["line","lines"],["bar","bars"],["rect","rectangles"],["area","area displayed"],["withinLink","connections"],["betweenLink","connections"],["triangleLeft","triangles"],["triangleRight","triangles"],["triangleBottom","triangles"]]),Ea=new Map([["y","height"],["color","color"],["strokeWidth","stroke width"],["opacity","opacity"],["text","text"]]);function Kig(e){return e.includes("chr")&&(e=e.replace("chr","")),e}function C$(e,g){let I;Array.isArray(e.appearance.details.mark)?I=e.appearance.details.mark[g]:I=e.appearance.details.mark;const i=e.appearance.details.encodings.encodingDeepGenomic.map(r=>r.name),n=e.appearance.details.encodings.encodingDeepQuantitative.map(r=>r.name),C=e.appearance.details.encodings.encodingDeepNominal.map(r=>r.name);if(I==="point"&&n.includes("x")&&n.includes("y"))return"scatter plot";if(I==="line"&&i.includes("x")&&n.includes("y")||I==="line"&&n.includes("x")&&i.includes("y"))return"line chart";if(I==="bar"&&i.includes("x")&&n.includes("y"))return"bar chart";if(I==="rect"&&i.includes("x")&&i.includes("xe")&&n.includes("color"))return"heat map";if(I==="rect"&&i.includes("x")&&i.includes("xe")&&C.includes("color"))return"ideogram"}function Dig(e){const g={};g.tracks={},g.title=e.title,g.subtitle=e.subtitle;const I={nTracks:0,rowViews:0,colViews:0,allPositions:[[0,0]],totalRows:0,totalCols:0,matrix:{}},i={};i.arrangement="vertical",i.layout="linear",U9e(e,g,i,I),zig(I);const n={description:"",nTracks:I.nTracks,parentValues:i,counter:I};return g.composition=n,g.alt="",g.longDescription="",g}function U9e(e,g,I,i){if("tracks"in e){const n=hle(e,I);if(e.tracks.length>1)if(Tig(e)){const C=e;g.tracks[i.nTracks]=xig(C,n,i),i.nTracks>0&&(i.allPositions=[...i.allPositions,[i.rowViews,i.colViews]]),i.nTracks++}else for(const C in e.tracks){const r=e.tracks[C];g.tracks[i.nTracks]=mle(r,n,i),i.nTracks>0&&(i.allPositions=[...i.allPositions,[i.rowViews,i.colViews]]),i.nTracks++}else{const C=e.tracks[0];g.tracks[i.nTracks]=mle(C,I,i),i.nTracks>0&&(i.allPositions=[...i.allPositions,[i.rowViews,i.colViews]]),i.nTracks++}}else if("views"in e){const n=i.rowViews,C=i.colViews;e.views.forEach((r,o)=>{o!==0&&(I.arrangement==="vertical"||I.arrangement==="parallel"?i.rowViews++:i.colViews++);const A=hle(r,I);U9e(r,g,A,i)}),I.arrangement==="vertical"||I.arrangement==="parallel"?i.rowViews=n:i.colViews=C}}function hle(e,g){const I=JSON.parse(JSON.stringify(g));return dle(e,"arrangement")&&(I.arrangement=e.arrangement),dle(e,"layout")&&(I.layout=e.layout),I}function mle(e,g,I){const i={};i.alttype="single";let n;e.id!=="unknown"?n=e.id:n="";const C={trackNumber:I.nTracks,rowNumber:I.rowViews,colNumber:I.colViews},r={};r.assembly=e.assembly,r.layout=g.layout,r.overlaid=!1,r.mark=e.mark,r.encodings=aH(e);const o=r$(e.data,r.encodings),A={data:e.data,fields:o},s={description:"",details:C},a={description:"",details:r},l={description:"",details:A};return i.uid=n,i.position=s,i.appearance=a,i.title=e.title,i.data=l,i.charttype=C$(i),i.description="",i}function xig(e,g,I){let i=Upe(e);return i=hpe(i),i.length>1?Eig(e,i,g,I):Fig(e,g,I)}function Fig(e,g,I){const i={};i.alttype="ov-mark";let n;e.id!=="unknown"?n=e.id:n="";const C={trackNumber:I.nTracks,rowNumber:I.rowViews,colNumber:I.colViews},r={};r.assembly=e.assembly,r.layout=g.layout,r.overlaid=!0,r.encodings=aH(e);const o=[],A=[];e.mark&&o.push(e.mark);for(const c of e.tracks){const u=c;u.mark&&o.push(u.mark),A.push(aH(u))}if(r.mark=o,r.encodingsByMark=A,e.data){const c=r$(e.data,r.encodings),d={description:"",details:{data:e.data,fields:c}};i.data=d}const s={description:"",details:C},a={description:"",details:r};i.uid=n,i.position=s,i.appearance=a,i.title=e.title;const l=[];for(let c=0;c0&&(g.encodingDeepGenomic[0].details.field?I.genomicField=g.encodingDeepGenomic[0].details.field:I.genomicField),g.encodingDeepQuantitative.length>0&&(g.encodingDeepQuantitative[0].details.field?I.valueField=g.encodingDeepQuantitative[0].details.field:I.valueField),g.encodingDeepNominal.length>0&&(g.encodingDeepNominal[0].details.field?I.categoryField=g.encodingDeepNominal[0].details.field:I.categoryField),I}function aH(e){const g=[],I=[],i=[],n=[];return Xig.forEach(r=>{const o=e[r];kig(o)?o.type==="genomic"?g.push({name:r,description:"",details:o}):o.type==="quantitative"?I.push({name:r,description:"",details:o}):i.push({name:r,description:"",details:o}):Nig(o)&&n.push({name:r,description:"",details:o})}),{encodingDeepGenomic:g,encodingDeepQuantitative:I,encodingDeepNominal:i,encodingValue:n}}function zig(e){e.totalRows=Math.max(...e.allPositions.map(I=>I[0]))+1,e.totalCols=Math.max(...e.allPositions.map(I=>I[1]))+1;const g={};for(let I=0;IC[0]===I).map(C=>C[1]),n={};for(const C of i)n[C]?n[C]=n[C]+1:n[C]=1;g[I]=n}e.matrix=g}function Pig(e){Jig(e),Lig(e)}function Jig(e){e.composition.nTracks==1?(e.tracks[0].position.description="This is the only track.",e.tracks[0].alttype==="single"?e.composition.description="There is one ("+e.tracks[0].appearance.details.layout+") track.":e.composition.description="There is one (overlaid) track."):e.composition.nTracks==2?Oig(e):_ig(e)}function Oig(e){let g="",I="",i="";if(e.tracks[0].appearance.details.layout==="circular"&&e.tracks[1].appearance.details.layout==="circular")switch(e.composition.parentValues.arrangement){case"serial":g="left half of ring",I="right half of ring",i="Two circular tracks form one ring, with both the half of the ring.";break;case"parallel":g="outer ring",I="inner ring",i="Two circular tracks form two rings, one around the other.";break;case"horizontal":g="left",I="right",i="Two circular tracks are shown next to each other.";break;default:g="top",I="bottom",i="Two circular tracks are shown below each other."}else{const n=e.tracks[0].appearance.details.layout===e.tracks[1].appearance.details.layout;switch(e.composition.parentValues.arrangement){case"serial":g="left",I="right",i=" are shown next to each other.";break;default:g="top",I="bottom",i="are shown below each other."}n?i="".concat("Two linear tracks ",i):i="".concat("One linear and one circular track ",i)}e.tracks[0].position.description="This track is shown on the "+g+".",e.tracks[1].position.description="This track is shown on the "+I+".",e.composition.description=i}function _ig(e){const g=["first","second","third","fourth","fifth","sixth","seventh","eighth","ninth","tenth"];let I="";if(e.composition.counter.totalRows===1)I=I.concat("There are "+e.composition.counter.nTracks+" tracks, displayed next to each other.");else if(e.composition.counter.totalCols===1)I=I.concat("There are "+e.composition.counter.nTracks+" tracks, displayed below each other.");else{I=I.concat("There are "+e.composition.counter.nTracks+" tracks."),I=I.concat(" There are "+e.composition.counter.totalRows+" rows.");const i=Object.keys(e.composition.counter.matrix).map(C=>Object.keys(e.composition.counter.matrix[C]).length),n=[...new Set(i)];if(n.length==1)I=I.concat(" Each row has "+n[0]+" tracks next to each other");else if(n.length==2){const C=[],r=[];for(let o=0;oo+1))+" have "+n[0]+" column(s) each."),I=I.concat(" The other rows have "+n[1]+" column(s) each.")):(I=I.concat(" Row(s) "+Wd(r.map(o=>o+1))+" have "+n[1]+" column(s) each."),I=I.concat(" The other rows have "+n[0]+" column(s) each."))}else for(let C=0;C9?I=I.concat(" Row number "+C+" has "+e.composition.counter.matrix[C].length+" track(s) next to each other."):I=I.concat(" The "+g[C]+" row has "+e.composition.counter.matrix[C].length+" track(s) next to each other.")}e.composition.description=I;for(const i in e.tracks){let n="";const C=e.tracks[i].position.details,r=e.composition.counter;e.composition.counter.totalRows>1&&(C.rowNumber===0?n=n.concat("top row"):C.rowNumber===r.totalRows-1?n=n.concat("bottom row"):C.rowNumber<10?n=n.concat(g[C.rowNumber]+" row"):n=n.concat("row "+C.rowNumber+1)),e.composition.counter.totalCols>1&&(n.length>1&&(n=n.concat(", ")),r.matrix[C.rowNumber].length>1&&(C.colNumber===1?n=n.concat("left"):C.colNumber===r.matrix[C.rowNumber].length?n=n.concat("right"):C.colNumber===2&&r.matrix[C.rowNumber].length===3?n=n.concat("middle"):n=n.concat(g[C.colNumber]+" from left"))),e.tracks[i].position.description=n}}function Lig(e){for(const g in e.tracks){const I=e.tracks[g];if(I.alttype==="single"){let i="";I.charttype?i=i.concat(Yig(I.charttype)+"."):i=i.concat("Chart with "+En.get(I.appearance.details.mark)+".");const n=Uig(I);i=i.concat(" "+n.desc),I.appearance.description=i,I.appearance.details.encodingsDescList=n.descList}else I.alttype==="ov-mark"&&(I.appearance.details.encodingsDescList=[[]])}}function Uig(e){const g=e.appearance.details.mark;let I="",i="",n="",C="";const r=[],o=e.appearance.details.encodings.encodingDeepGenomic.map(l=>l.name);if(o.includes("x")&&o.includes("y"))I=I.concat("The genome is shown on both the x- and y-axes."),o.includes("xe")&&o.includes("ye")?(I=I.concat(" Each displays genomic intervals."),r.push(["x","The x-axis show genomic intervals."]),r.push(["y","The y-axis show genomic intervals."])):o.includes("xe")?(I=I.concat(" The genome on the x-axis displays genomic intervals."),r.push(["x","The x-axis show genomic intervals."]),r.push(["y","The y-axis shows the genome."])):o.includes("ye")?(I=I.concat(" The genome on the y-axis displays genomic intervals."),r.push(["x","The x-axis shows the genome."]),r.push(["y","The y-axis show genomic intervals."])):(r.push(["x","The x-axis shows the genome."]),r.push(["y","The y-axis shows the genome."]));else{if(o.includes("x")){let l="";o.includes("xe")?(l="in intervals",r.push(["x","The x-axis show genomic intervals."])):r.push(["x","The x-axis shows the genome."]),I=I.concat("The genome is shown "+l+" on the x-axis.")}if(o.includes("y")){let l="";o.includes("ye")?(l="in intervals",r.push(["y","The y-axis show genomic intervals."])):r.push(["y","The y-axis shows the genome."]),I=I.concat("The genome is shown "+l+" on the y-axis.")}}const A=e.appearance.details.encodings.encodingDeepQuantitative.map(l=>l.name);if(A.length>1){i=i.concat("The expression values are shown with "+En.get(g)+" on the "+Wd(A)+"-axes.");for(const l of A)r.push([l,"The "+l+" of the "+En.get(g)+" shows the expression values."])}else A.length===1&&(A.includes("y")?(i=i.concat("The expression is shown on the y-axis with "+En.get(g)+"."),r.push(["y","The y-axis shows the expression with"+En.get(g)+"."])):A.includes("color")?(i=i.concat("The height of the expression values is shown with color."),r.push(["color","The color of the "+En.get(g)+" shows the expression values."])):(i=i.concat("The height of the expression values is shown with the "+A[0]+"-axis."),r.push([Ea.get(A[0]),"The "+Ea.get(A[0])+" of the "+En.get(g)+" shows the expression values."])));const s=e.appearance.details.encodings.encodingDeepNominal.map(l=>l.name);if(s.length>1)if(s.includes("row")){n=n.concat("The chart is stratified by rows for the categories.");const l=s.filter(c=>c!=="row").map(c=>Ea.get(c));n=n.concat(" The categories are also shown with the "+Wd(l)+" of the "+En.get(g)+"."),r.push(["row","The chart is stratified by rows for the categories."]);for(const c of l)r.push([Ea.get(c),"The "+c+" of the "+En.get(g)+" show the different categories."])}else{const l=s.map(c=>Ea.get(c));n=n.concat("The categories are shown with the "+Wd(l)+" of the "+En.get(g)+".");for(const c of s)r.push([Ea.get(c),"The "+c+" of the "+En.get(g)+" show the different categories."])}else s.length==1&&(s.includes("row")?(n=n.concat("The chart is stratified by rows for the categories."),r.push(["row","The chart is stratified by rows for the categories."])):(n=n.concat("The "+Ea.get(s[0])+" of the "+En.get(g)+" indicates the different categories."),r.push([Ea.get(s[0]),"The "+Ea.get(s[0])+" of the "+En.get(g)+" show the different categories."])));for(let l=0;lr[n]).filter(r=>!isNaN(r));i.genomicMin=Math.min(...C),i.genomicMax=Math.max(...C)}catch(C){console.log(C)}}if(I.valueField!==void 0){const n=I.valueField;try{const C=g.map(r=>r[n]).filter(r=>!isNaN(r));i.valueMin=Math.min(...C),i.valueMax=Math.max(...C)}catch(C){console.log(C)}}if(I.genomicField!==void 0&&I.valueField!==void 0){const n=I.genomicField,C=I.valueField;try{i.valueMinGenomic=g.filter(r=>r[C]==i.valueMin).map(r=>r[n]),i.valueMaxGenomic=g.filter(r=>r[C]==i.valueMax).map(r=>r[n])}catch(r){console.log(r)}}if(I.categoryField!==void 0){const n=I.genomicField,C=I.valueField,r=I.categoryField;try{const o=g.map(l=>l[r]),A=[...new Set(o)],s={},a=[];for(const l of A){const c=g.filter(b=>b[r]===l),u=c.map(b=>b[C]).filter(b=>!isNaN(b)),d=Math.min(...u),h=Math.max(...u),m=c.filter(b=>b[C]==d).map(b=>b[n]),f=c.filter(b=>b[C]==h).map(b=>b[n]);s[l]=[d,m,h,f],h===i.valueMax&&a.push(l)}i.categories=A,i.categoryMinMaxWG=s,i.highestCategory=a}catch(o){console.log(o)}}return i}else return i}function tng(e,g,I){const i=e.tracks.length>1;for(let n=0;n{let s=C.current;s!==r&&console.warn(`WARN: A component changed from ${s?"controlled":"uncontrolled"} to ${r?"controlled":"uncontrolled"}.`),C.current=r},[r]);let o=r?e:i,A=Ie.useCallback((s,...a)=>{let l=(c,...u)=>{I&&(Object.is(o,c)||I(c,...u)),r||(o=c)};typeof s=="function"?(console.warn("We can not support a function callback. See Github Issues for details https://github.com/adobe/react-spectrum/issues/2320"),n((u,...d)=>{let h=s(r?o:u,...d);return l(h,...a),r?u:h})):(r||n(s),l(s,...a))},[r,o,I]);return[o,A]}const sH={prefix:String(Math.round(Math.random()*1e10)),current:0},q9e=N.createContext(sH),nng=N.createContext(!1);let Cng=!!(typeof window<"u"&&window.document&&window.document.createElement),qx=new WeakMap;function rng(e=!1){let g=Ie.useContext(q9e),I=Ie.useRef(null);if(I.current===null&&!e){var i,n;let C=(n=N.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED)===null||n===void 0||(i=n.ReactCurrentOwner)===null||i===void 0?void 0:i.current;if(C){let r=qx.get(C);r==null?qx.set(C,{id:g.current,state:C.memoizedState}):C.memoizedState!==r.state&&(g.current=r.id,qx.delete(C))}I.current=++g.current}return I.current}function ong(e){let g=Ie.useContext(q9e);g===sH&&!Cng&&console.warn("When server rendering, you must wrap your application in an to ensure consistent ids are generated between the client and server.");let I=rng(!!e),i=`react-aria${g.prefix}`;return e||`${i}-${I}`}function Ang(e){let g=N.useId(),[I]=Ie.useState(mw()),i=I?"react-aria":`react-aria${sH.prefix}`;return e||`${i}-${g}`}const ang=typeof N.useId=="function"?Ang:ong;function sng(){return!1}function lng(){return!0}function cng(e){return()=>{}}function mw(){return typeof N.useSyncExternalStore=="function"?N.useSyncExternalStore(cng,sng,lng):Ie.useContext(nng)}function e2e(e){var g,I,i="";if(typeof e=="string"||typeof e=="number")i+=e;else if(typeof e=="object")if(Array.isArray(e))for(g=0;g{};function Ir(e){const g=Ie.useRef(null);return hi(()=>{g.current=e},[e]),Ie.useCallback((...I)=>{const i=g.current;return i(...I)},[])}function dng(e){let[g,I]=Ie.useState(e),i=Ie.useRef(null),n=Ir(()=>{let r=i.current.next();if(r.done){i.current=null;return}g===r.value?n():I(r.value)});hi(()=>{i.current&&n()});let C=Ir(r=>{i.current=r(g),n()});return[g,C]}let hng=!!(typeof window<"u"&&window.document&&window.document.createElement),lH=new Map;function Rh(e){let[g,I]=Ie.useState(e),i=Ie.useRef(null),n=ang(g),C=Ie.useCallback(r=>{i.current=r},[]);return hng&&lH.set(n,C),hi(()=>{let r=n;return()=>{lH.delete(r)}},[n]),Ie.useEffect(()=>{let r=i.current;r&&(i.current=null,I(r))}),n}function mng(e,g){if(e===g)return e;let I=lH.get(e);if(I)return I(g),g;let i=lH.get(g);return i?(i(e),e):g}function ble(e=[]){let g=Rh(),[I,i]=dng(g),n=Ie.useCallback(()=>{i(function*(){yield g,yield document.getElementById(g)?g:void 0})},[g,i]);return hi(n,[g,n,...e]),I}function fng(...e){return(...g)=>{for(let I of e)typeof I=="function"&&I(...g)}}const $l=e=>{var g;return(g=e==null?void 0:e.ownerDocument)!==null&&g!==void 0?g:document},cH=e=>e&&"window"in e&&e.window===e?e:$l(e).defaultView||window;function pi(...e){let g={...e[0]};for(let I=1;I=65&&n.charCodeAt(2)<=90?g[n]=fng(C,r):(n==="className"||n==="UNSAFE_className")&&typeof C=="string"&&typeof r=="string"?g[n]=ung(C,r):n==="id"&&C&&r?g.id=mng(C,r):g[n]=r!==void 0?r:C}}return g}function png(...e){return e.length===1?e[0]:g=>{for(let I of e)typeof I=="function"?I(g):I!=null&&(I.current=g)}}const bng=new Set(["id"]),yng=new Set(["aria-label","aria-labelledby","aria-describedby","aria-details"]),Zng=new Set(["href","target","rel","download","ping","referrerPolicy"]),Gng=/^(data-.*)$/;function Ra(e,g={}){let{labelable:I,isLink:i,propNames:n}=g,C={};for(const r in e)Object.prototype.hasOwnProperty.call(e,r)&&(bng.has(r)||I&&yng.has(r)||i&&Zng.has(r)||n!=null&&n.has(r)||Gng.test(r))&&(C[r]=e[r]);return C}function ms(e){if(vng())e.focus({preventScroll:!0});else{let g=Bng(e);e.focus(),Sng(g)}}let FR=null;function vng(){if(FR==null){FR=!1;try{var e=document.createElement("div");e.focus({get preventScroll(){return FR=!0,!0}})}catch{}}return FR}function Bng(e){for(var g=e.parentNode,I=[],i=document.scrollingElement||document.documentElement;g instanceof HTMLElement&&g!==i;)(g.offsetHeight"u"||window.navigator==null?!1:((g=window.navigator.userAgentData)===null||g===void 0?void 0:g.brands.some(I=>e.test(I.brand)))||e.test(window.navigator.userAgent)}function a$(e){var g;return typeof window<"u"&&window.navigator!=null?e.test(((g=window.navigator.userAgentData)===null||g===void 0?void 0:g.platform)||window.navigator.platform):!1}function Wh(){return a$(/^Mac/i)}function wng(){return a$(/^iPhone/i)}function t2e(){return a$(/^iPad/i)||Wh()&&navigator.maxTouchPoints>1}function s$(){return wng()||t2e()}function Vng(){return Wh()||s$()}function Rng(){return Wk(/AppleWebKit/i)&&!Wng()}function Wng(){return Wk(/Chrome/i)}function uH(){return Wk(/Android/i)}function Xng(){return Wk(/Firefox/i)}const Hng=Ie.createContext({isNative:!0,open:Nng});function g2e(){return Ie.useContext(Hng)}function Xh(e,g,I=!0){var i,n;let{metaKey:C,ctrlKey:r,altKey:o,shiftKey:A}=g;Xng()&&(!((n=window.event)===null||n===void 0||(i=n.type)===null||i===void 0)&&i.startsWith("key"))&&e.target==="_blank"&&(Wh()?C=!0:r=!0);let s=Rng()&&Wh()&&!t2e()?new KeyboardEvent("keydown",{keyIdentifier:"Enter",metaKey:C,ctrlKey:r,altKey:o,shiftKey:A}):new MouseEvent("click",{metaKey:C,ctrlKey:r,altKey:o,shiftKey:A,bubbles:!0,cancelable:!0});Xh.isOpening=I,ms(e),e.dispatchEvent(s),Xh.isOpening=!1}Xh.isOpening=!1;function Tng(e,g){if(e instanceof HTMLAnchorElement)g(e);else if(e.hasAttribute("data-href")){let I=document.createElement("a");I.href=e.getAttribute("data-href"),e.hasAttribute("data-target")&&(I.target=e.getAttribute("data-target")),e.hasAttribute("data-rel")&&(I.rel=e.getAttribute("data-rel")),e.hasAttribute("data-download")&&(I.download=e.getAttribute("data-download")),e.hasAttribute("data-ping")&&(I.ping=e.getAttribute("data-ping")),e.hasAttribute("data-referrer-policy")&&(I.referrerPolicy=e.getAttribute("data-referrer-policy")),e.appendChild(I),g(I),e.removeChild(I)}}function Nng(e,g){Tng(e,I=>Xh(I,g))}function kng(e){return{"data-href":e.href,"data-target":e.target,"data-rel":e.rel,"data-download":e.download,"data-ping":e.ping,"data-referrer-policy":e.referrerPolicy}}let Wf=new Map,wO=new Set;function yle(){if(typeof window>"u")return;let e=I=>{let i=Wf.get(I.target);i||(i=new Set,Wf.set(I.target,i),I.target.addEventListener("transitioncancel",g)),i.add(I.propertyName)},g=I=>{let i=Wf.get(I.target);if(i&&(i.delete(I.propertyName),i.size===0&&(I.target.removeEventListener("transitioncancel",g),Wf.delete(I.target)),Wf.size===0)){for(let n of wO)n();wO.clear()}};document.body.addEventListener("transitionrun",e),document.body.addEventListener("transitionend",g)}typeof document<"u"&&(document.readyState!=="loading"?yle():document.addEventListener("DOMContentLoaded",yle));function I2e(e){requestAnimationFrame(()=>{Wf.size===0?e():wO.add(e)})}function i2e(){let e=Ie.useRef(new Map),g=Ie.useCallback((n,C,r,o)=>{let A=o!=null&&o.once?(...s)=>{e.current.delete(r),r(...s)}:r;e.current.set(r,{type:C,eventTarget:n,fn:A,options:o}),n.addEventListener(C,r,o)},[]),I=Ie.useCallback((n,C,r,o)=>{var A;let s=((A=e.current.get(r))===null||A===void 0?void 0:A.fn)||r;n.removeEventListener(C,s,o),e.current.delete(r)},[]),i=Ie.useCallback(()=>{e.current.forEach((n,C)=>{I(n.eventTarget,n.type,C,n.options)})},[I]);return Ie.useEffect(()=>i,[i]),{addGlobalListener:g,removeGlobalListener:I,removeAllGlobalListeners:i}}function Yng(e,g){let{id:I,"aria-label":i,"aria-labelledby":n}=e;return I=Rh(I),n&&i?n=[...new Set([I,...n.trim().split(/\s+/)])].join(" "):n&&(n=n.trim().split(/\s+/).join(" ")),!i&&!n&&g&&(i=g),{id:I,"aria-label":i,"aria-labelledby":n}}function fw(e){const g=Ie.useRef();return Ie.useMemo(()=>({get current(){return g.current},set current(I){g.current=I,typeof e=="function"?e(I):e&&(e.current=I)}}),[e])}function n2e(e,g){const I=Ie.useRef(!0),i=Ie.useRef(null);Ie.useEffect(()=>(I.current=!0,()=>{I.current=!1}),[]),Ie.useEffect(()=>{I.current?I.current=!1:(!i.current||g.some((n,C)=>!Object.is(n,i[C])))&&e(),i.current=g},g)}function C2e(e,g){hi(()=>{if(e&&e.ref&&g)return e.ref.current=g.current,()=>{e.ref.current=null}})}function xl(e){for(dH(e)&&(e=e.parentElement);e&&!dH(e);)e=e.parentElement;return e||document.scrollingElement||document.documentElement}function dH(e){let g=window.getComputedStyle(e);return/(auto|scroll)/.test(g.overflow+g.overflowX+g.overflowY)}let Kng=0;const eF=new Map;function Xk(e){let[g,I]=Ie.useState(void 0);return hi(()=>{if(!e)return;let i=eF.get(e);if(i)I(i.element.id);else{let n=`react-aria-description-${Kng++}`;I(n);let C=document.createElement("div");C.id=n,C.style.display="none",C.textContent=e,document.body.appendChild(C),i={refCount:0,element:C},eF.set(e,i)}return i.refCount++,()=>{--i.refCount===0&&(i.element.remove(),eF.delete(e))}},[e]),{"aria-describedby":e?g:void 0}}function Dng(e,g,I,i){let n=Ir(I),C=I==null;Ie.useEffect(()=>{if(C)return;let r=e.current;return r.addEventListener(g,n,i),()=>{r.removeEventListener(g,n,i)}},[e,g,i,C,n])}function r2e(e,g){let I=Zle(e,g,"left"),i=Zle(e,g,"top"),n=g.offsetWidth,C=g.offsetHeight,r=e.scrollLeft,o=e.scrollTop,{borderTopWidth:A,borderLeftWidth:s}=getComputedStyle(e),a=e.scrollLeft+parseInt(s,10),l=e.scrollTop+parseInt(A,10),c=a+e.clientWidth,u=l+e.clientHeight;I<=r?r=I-parseInt(s,10):I+n>c&&(r+=I+n-c),i<=l?o=i-parseInt(A,10):i+C>u&&(o+=i+C-u),e.scrollLeft=r,e.scrollTop=o}function Zle(e,g,I){const i=I==="left"?"offsetLeft":"offsetTop";let n=0;for(;g.offsetParent&&(n+=g[i],g.offsetParent!==e);){if(g.offsetParent.contains(e)){n-=e[i];break}g=g.offsetParent}return n}function Fl(e,g){if(document.contains(e)){let r=document.scrollingElement||document.documentElement;if(window.getComputedStyle(r).overflow==="hidden"){let A=xl(e);for(;e&&A&&e!==r&&A!==r;)r2e(A,e),e=A,A=xl(e)}else{var I;let{left:A,top:s}=e.getBoundingClientRect();e==null||(I=e.scrollIntoView)===null||I===void 0||I.call(e,{block:"nearest"});let{left:a,top:l}=e.getBoundingClientRect();if(Math.abs(A-a)>1||Math.abs(s-l)>1){var i,n,C;g==null||(n=g.containingElement)===null||n===void 0||(i=n.scrollIntoView)===null||i===void 0||i.call(n,{block:"center",inline:"center"}),(C=e.scrollIntoView)===null||C===void 0||C.call(e,{block:"nearest"})}}}}function VO(e){return e.mozInputSource===0&&e.isTrusted?!0:uH()&&e.pointerType?e.type==="click"&&e.buttons===1:e.detail===0&&!e.pointerType}function xng(e){return!uH()&&e.width===0&&e.height===0||e.width===1&&e.height===1&&e.pressure===0&&e.detail===0&&e.pointerType==="mouse"}function Fng(e,g,I){let i=Ie.useRef(g),n=Ir(()=>{I&&I(i.current)});Ie.useEffect(()=>{var C;let r=e==null||(C=e.current)===null||C===void 0?void 0:C.form;return r==null||r.addEventListener("reset",n),()=>{r==null||r.removeEventListener("reset",n)}},[e,n])}function Eng(e,g){return g.get?g.get.call(e):g.value}function o2e(e,g,I){if(!g.has(e))throw new TypeError("attempted to "+I+" private field on non-instance");return g.get(e)}function Mng(e,g){var I=o2e(e,g,"get");return Eng(e,I)}function zng(e,g){if(g.has(e))throw new TypeError("Cannot initialize the same private elements twice on an object")}function Png(e,g,I){zng(e,g),g.set(e,I)}function Jng(e,g,I){if(g.set)g.set.call(e,I);else{if(!g.writable)throw new TypeError("attempted to set read only private field");g.value=I}}function Gle(e,g,I){var i=o2e(e,g,"set");return Jng(e,i,I),I}let Ip="default",RO="",dW=new WeakMap;function vle(e){if(s$()){if(Ip==="default"){const g=$l(e);RO=g.documentElement.style.webkitUserSelect,g.documentElement.style.webkitUserSelect="none"}Ip="disabled"}else(e instanceof HTMLElement||e instanceof SVGElement)&&(dW.set(e,e.style.userSelect),e.style.userSelect="none")}function ER(e){if(s$()){if(Ip!=="disabled")return;Ip="restoring",setTimeout(()=>{I2e(()=>{if(Ip==="restoring"){const g=$l(e);g.documentElement.style.webkitUserSelect==="none"&&(g.documentElement.style.webkitUserSelect=RO||""),RO="",Ip="default"}})},300)}else if((e instanceof HTMLElement||e instanceof SVGElement)&&e&&dW.has(e)){let g=dW.get(e);e.style.userSelect==="none"&&g&&(e.style.userSelect=g),e.getAttribute("style")===""&&e.removeAttribute("style"),dW.delete(e)}}const A2e=N.createContext({register:()=>{}});A2e.displayName="PressResponderContext";function Ong(e){let g=Ie.useContext(A2e);if(g){let{register:I,...i}=g;e=pi(i,e),I()}return C2e(g,e.ref),e}var MR=new WeakMap;class zR{continuePropagation(){Gle(this,MR,!1)}get shouldStopPropagation(){return Mng(this,MR)}constructor(g,I,i){Png(this,MR,{writable:!0,value:void 0}),Gle(this,MR,!0),this.type=g,this.pointerType=I,this.target=i.currentTarget,this.shiftKey=i.shiftKey,this.metaKey=i.metaKey,this.ctrlKey=i.ctrlKey,this.altKey=i.altKey}}const Ble=Symbol("linkClicked");function l$(e){let{onPress:g,onPressChange:I,onPressStart:i,onPressEnd:n,onPressUp:C,isDisabled:r,isPressed:o,preventFocusOnPress:A,shouldCancelOnPointerExit:s,allowTextSelectionOnPress:a,ref:l,...c}=Ong(e),[u,d]=Ie.useState(!1),h=Ie.useRef({isPressed:!1,ignoreEmulatedMouseEvents:!1,ignoreClickAfterPress:!1,didFirePressStart:!1,isTriggeringEvent:!1,activePointerId:null,target:null,isOverTarget:!1,pointerType:null}),{addGlobalListener:m,removeAllGlobalListeners:f}=i2e(),b=Ir((v,w)=>{let V=h.current;if(r||V.didFirePressStart)return!1;let S=!0;if(V.isTriggeringEvent=!0,i){let X=new zR("pressstart",w,v);i(X),S=X.shouldStopPropagation}return I&&I(!0),V.isTriggeringEvent=!1,V.didFirePressStart=!0,d(!0),S}),p=Ir((v,w,V=!0)=>{let S=h.current;if(!S.didFirePressStart)return!1;S.ignoreClickAfterPress=!0,S.didFirePressStart=!1,S.isTriggeringEvent=!0;let X=!0;if(n){let W=new zR("pressend",w,v);n(W),X=W.shouldStopPropagation}if(I&&I(!1),d(!1),g&&V&&!r){let W=new zR("press",w,v);g(W),X&&(X=W.shouldStopPropagation)}return S.isTriggeringEvent=!1,X}),y=Ir((v,w)=>{let V=h.current;if(r)return!1;if(C){V.isTriggeringEvent=!0;let S=new zR("pressup",w,v);return C(S),V.isTriggeringEvent=!1,S.shouldStopPropagation}return!0}),Z=Ir(v=>{let w=h.current;w.isPressed&&w.target&&(w.isOverTarget&&w.pointerType!=null&&p(Ma(w.target,v),w.pointerType,!1),w.isPressed=!1,w.isOverTarget=!1,w.activePointerId=null,w.pointerType=null,f(),a||ER(w.target))}),B=Ir(v=>{s&&Z(v)}),G=Ie.useMemo(()=>{let v=h.current,w={onKeyDown(S){if(tF(S.nativeEvent,S.currentTarget)&&S.currentTarget.contains(S.target)){var X;wle(S.target,S.key)&&S.preventDefault();let W=!0;!v.isPressed&&!S.repeat&&(v.target=S.currentTarget,v.isPressed=!0,W=b(S,"keyboard"),m($l(S.currentTarget),"keyup",V,!1)),W&&S.stopPropagation(),S.metaKey&&Wh()&&((X=v.metaKeyEvents)===null||X===void 0||X.set(S.key,S.nativeEvent))}else S.key==="Meta"&&(v.metaKeyEvents=new Map)},onKeyUp(S){tF(S.nativeEvent,S.currentTarget)&&!S.repeat&&S.currentTarget.contains(S.target)&&v.target&&y(Ma(v.target,S),"keyboard")},onClick(S){if(!(S&&!S.currentTarget.contains(S.target))&&S&&S.button===0&&!v.isTriggeringEvent&&!Xh.isOpening){let X=!0;if(r&&S.preventDefault(),!v.ignoreClickAfterPress&&!v.ignoreEmulatedMouseEvents&&!v.isPressed&&(v.pointerType==="virtual"||VO(S.nativeEvent))){!r&&!A&&ms(S.currentTarget);let W=b(S,"virtual"),R=y(S,"virtual"),H=p(S,"virtual");X=W&&R&&H}v.ignoreEmulatedMouseEvents=!1,v.ignoreClickAfterPress=!1,X&&S.stopPropagation()}}},V=S=>{var X;if(v.isPressed&&v.target&&tF(S,v.target)){var W;wle(S.target,S.key)&&S.preventDefault();let H=S.target,Y=p(Ma(v.target,S),"keyboard",v.target.contains(H));f(),Y&&S.stopPropagation(),S.key!=="Enter"&&c$(v.target)&&v.target.contains(H)&&!S[Ble]&&(S[Ble]=!0,Xh(v.target,S,!1)),v.isPressed=!1,(W=v.metaKeyEvents)===null||W===void 0||W.delete(S.key)}else if(S.key==="Meta"&&(!((X=v.metaKeyEvents)===null||X===void 0)&&X.size)){var R;let H=v.metaKeyEvents;v.metaKeyEvents=void 0;for(let Y of H.values())(R=v.target)===null||R===void 0||R.dispatchEvent(new KeyboardEvent("keyup",Y))}};if(typeof PointerEvent<"u"){w.onPointerDown=R=>{if(R.button!==0||!R.currentTarget.contains(R.target))return;if(xng(R.nativeEvent)){v.pointerType="virtual";return}gF(R.currentTarget)&&R.preventDefault(),v.pointerType=R.pointerType;let H=!0;v.isPressed||(v.isPressed=!0,v.isOverTarget=!0,v.activePointerId=R.pointerId,v.target=R.currentTarget,!r&&!A&&ms(R.currentTarget),a||vle(v.target),H=b(R,v.pointerType),m($l(R.currentTarget),"pointermove",S,!1),m($l(R.currentTarget),"pointerup",X,!1),m($l(R.currentTarget),"pointercancel",W,!1)),H&&R.stopPropagation()},w.onMouseDown=R=>{R.currentTarget.contains(R.target)&&R.button===0&&(gF(R.currentTarget)&&R.preventDefault(),R.stopPropagation())},w.onPointerUp=R=>{!R.currentTarget.contains(R.target)||v.pointerType==="virtual"||R.button===0&&$m(R,R.currentTarget)&&y(R,v.pointerType||R.pointerType)};let S=R=>{R.pointerId===v.activePointerId&&(v.target&&$m(R,v.target)?!v.isOverTarget&&v.pointerType!=null&&(v.isOverTarget=!0,b(Ma(v.target,R),v.pointerType)):v.target&&v.isOverTarget&&v.pointerType!=null&&(v.isOverTarget=!1,p(Ma(v.target,R),v.pointerType,!1),B(R)))},X=R=>{R.pointerId===v.activePointerId&&v.isPressed&&R.button===0&&v.target&&($m(R,v.target)&&v.pointerType!=null?p(Ma(v.target,R),v.pointerType):v.isOverTarget&&v.pointerType!=null&&p(Ma(v.target,R),v.pointerType,!1),v.isPressed=!1,v.isOverTarget=!1,v.activePointerId=null,v.pointerType=null,f(),a||ER(v.target))},W=R=>{Z(R)};w.onDragStart=R=>{R.currentTarget.contains(R.target)&&Z(R)}}else{w.onMouseDown=W=>{if(W.button!==0||!W.currentTarget.contains(W.target))return;if(gF(W.currentTarget)&&W.preventDefault(),v.ignoreEmulatedMouseEvents){W.stopPropagation();return}v.isPressed=!0,v.isOverTarget=!0,v.target=W.currentTarget,v.pointerType=VO(W.nativeEvent)?"virtual":"mouse",!r&&!A&&ms(W.currentTarget),b(W,v.pointerType)&&W.stopPropagation(),m($l(W.currentTarget),"mouseup",S,!1)},w.onMouseEnter=W=>{if(!W.currentTarget.contains(W.target))return;let R=!0;v.isPressed&&!v.ignoreEmulatedMouseEvents&&v.pointerType!=null&&(v.isOverTarget=!0,R=b(W,v.pointerType)),R&&W.stopPropagation()},w.onMouseLeave=W=>{if(!W.currentTarget.contains(W.target))return;let R=!0;v.isPressed&&!v.ignoreEmulatedMouseEvents&&v.pointerType!=null&&(v.isOverTarget=!1,R=p(W,v.pointerType,!1),B(W)),R&&W.stopPropagation()},w.onMouseUp=W=>{W.currentTarget.contains(W.target)&&!v.ignoreEmulatedMouseEvents&&W.button===0&&y(W,v.pointerType||"mouse")};let S=W=>{if(W.button===0){if(v.isPressed=!1,f(),v.ignoreEmulatedMouseEvents){v.ignoreEmulatedMouseEvents=!1;return}v.target&&$m(W,v.target)&&v.pointerType!=null?p(Ma(v.target,W),v.pointerType):v.target&&v.isOverTarget&&v.pointerType!=null&&p(Ma(v.target,W),v.pointerType,!1),v.isOverTarget=!1}};w.onTouchStart=W=>{if(!W.currentTarget.contains(W.target))return;let R=_ng(W.nativeEvent);if(!R)return;v.activePointerId=R.identifier,v.ignoreEmulatedMouseEvents=!0,v.isOverTarget=!0,v.isPressed=!0,v.target=W.currentTarget,v.pointerType="touch",!r&&!A&&ms(W.currentTarget),a||vle(v.target),b(W,v.pointerType)&&W.stopPropagation(),m(cH(W.currentTarget),"scroll",X,!0)},w.onTouchMove=W=>{if(!W.currentTarget.contains(W.target))return;if(!v.isPressed){W.stopPropagation();return}let R=Sle(W.nativeEvent,v.activePointerId),H=!0;R&&$m(R,W.currentTarget)?!v.isOverTarget&&v.pointerType!=null&&(v.isOverTarget=!0,H=b(W,v.pointerType)):v.isOverTarget&&v.pointerType!=null&&(v.isOverTarget=!1,H=p(W,v.pointerType,!1),B(W)),H&&W.stopPropagation()},w.onTouchEnd=W=>{if(!W.currentTarget.contains(W.target))return;if(!v.isPressed){W.stopPropagation();return}let R=Sle(W.nativeEvent,v.activePointerId),H=!0;R&&$m(R,W.currentTarget)&&v.pointerType!=null?(y(W,v.pointerType),H=p(W,v.pointerType)):v.isOverTarget&&v.pointerType!=null&&(H=p(W,v.pointerType,!1)),H&&W.stopPropagation(),v.isPressed=!1,v.activePointerId=null,v.isOverTarget=!1,v.ignoreEmulatedMouseEvents=!0,v.target&&!a&&ER(v.target),f()},w.onTouchCancel=W=>{W.currentTarget.contains(W.target)&&(W.stopPropagation(),v.isPressed&&Z(W))};let X=W=>{v.isPressed&&W.target.contains(v.target)&&Z({currentTarget:v.target,shiftKey:!1,ctrlKey:!1,metaKey:!1,altKey:!1})};w.onDragStart=W=>{W.currentTarget.contains(W.target)&&Z(W)}}return w},[m,r,A,f,a,Z,B,p,b,y]);return Ie.useEffect(()=>()=>{var v;a||ER((v=h.current.target)!==null&&v!==void 0?v:void 0)},[a]),{isPressed:o||u,pressProps:pi(c,G)}}function c$(e){return e.tagName==="A"&&e.hasAttribute("href")}function tF(e,g){const{key:I,code:i}=e,n=g,C=n.getAttribute("role");return(I==="Enter"||I===" "||I==="Spacebar"||i==="Space")&&!(n instanceof cH(n).HTMLInputElement&&!a2e(n,I)||n instanceof cH(n).HTMLTextAreaElement||n.isContentEditable)&&!((C==="link"||!C&&c$(n))&&I!=="Enter")}function _ng(e){const{targetTouches:g}=e;return g.length>0?g[0]:null}function Sle(e,g){const I=e.changedTouches;for(let i=0;ig.right||g.left>e.right||e.top>g.bottom||g.top>e.bottom)}function $m(e,g){let I=g.getBoundingClientRect(),i=Lng(e);return Ung(I,i)}function gF(e){return!(e instanceof HTMLElement)||!e.hasAttribute("draggable")}function wle(e,g){return e instanceof HTMLInputElement?!a2e(e,g):e instanceof HTMLButtonElement?e.type!=="submit"&&e.type!=="reset":!c$(e)}const Qng=new Set(["checkbox","radio","range","color","file","image","button","submit","reset"]);function a2e(e,g){return e.type==="checkbox"||e.type==="radio"?g===" ":Qng.has(e.type)}class jng{isDefaultPrevented(){return this.nativeEvent.defaultPrevented}preventDefault(){this.defaultPrevented=!0,this.nativeEvent.preventDefault()}stopPropagation(){this.nativeEvent.stopPropagation(),this.isPropagationStopped=()=>!0}isPropagationStopped(){return!1}persist(){}constructor(g,I){this.nativeEvent=I,this.target=I.target,this.currentTarget=I.currentTarget,this.relatedTarget=I.relatedTarget,this.bubbles=I.bubbles,this.cancelable=I.cancelable,this.defaultPrevented=I.defaultPrevented,this.eventPhase=I.eventPhase,this.isTrusted=I.isTrusted,this.timeStamp=I.timeStamp,this.type=g}}function s2e(e){let g=Ie.useRef({isFocused:!1,observer:null});hi(()=>{const i=g.current;return()=>{i.observer&&(i.observer.disconnect(),i.observer=null)}},[]);let I=Ir(i=>{e==null||e(i)});return Ie.useCallback(i=>{if(i.target instanceof HTMLButtonElement||i.target instanceof HTMLInputElement||i.target instanceof HTMLTextAreaElement||i.target instanceof HTMLSelectElement){g.current.isFocused=!0;let n=i.target,C=r=>{g.current.isFocused=!1,n.disabled&&I(new jng("blur",r)),g.current.observer&&(g.current.observer.disconnect(),g.current.observer=null)};n.addEventListener("focusout",C,{once:!0}),g.current.observer=new MutationObserver(()=>{if(g.current.isFocused&&n.disabled){var r;(r=g.current.observer)===null||r===void 0||r.disconnect();let o=n===document.activeElement?null:document.activeElement;n.dispatchEvent(new FocusEvent("blur",{relatedTarget:o})),n.dispatchEvent(new FocusEvent("focusout",{bubbles:!0,relatedTarget:o}))}}),g.current.observer.observe(n,{attributes:!0,attributeFilter:["disabled"]})}},[I])}function l2e(e){let{isDisabled:g,onFocus:I,onBlur:i,onFocusChange:n}=e;const C=Ie.useCallback(A=>{if(A.target===A.currentTarget)return i&&i(A),n&&n(!1),!0},[i,n]),r=s2e(C),o=Ie.useCallback(A=>{A.target===A.currentTarget&&document.activeElement===A.target&&(I&&I(A),n&&n(!0),r(A))},[n,I,r]);return{focusProps:{onFocus:!g&&(I||n||i)?o:void 0,onBlur:!g&&(i||n)?C:void 0}}}let Es=null,JB=new Set,Vle=!1,Hh=!1,WO=!1;const $ng={Tab:!0,Escape:!0};function Hk(e,g){for(let I of JB)I(e,g)}function qng(e){return!(e.metaKey||!Wh()&&e.altKey||e.ctrlKey||e.key==="Control"||e.key==="Shift"||e.key==="Meta")}function Rle(e){Hh=!0,qng(e)&&(Es="keyboard",Hk("keyboard",e))}function qm(e){Es="pointer",(e.type==="mousedown"||e.type==="pointerdown")&&(Hh=!0,Hk("pointer",e))}function eCg(e){VO(e)&&(Hh=!0,Es="virtual")}function tCg(e){e.target===window||e.target===document||(!Hh&&!WO&&(Es="virtual",Hk("virtual",e)),Hh=!1,WO=!1)}function gCg(){Hh=!1,WO=!0}function hH(){if(typeof window>"u"||Vle)return;let e=HTMLElement.prototype.focus;HTMLElement.prototype.focus=function(){Hh=!0,e.apply(this,arguments)},document.addEventListener("keydown",Rle,!0),document.addEventListener("keyup",Rle,!0),document.addEventListener("click",eCg,!0),window.addEventListener("focus",tCg,!0),window.addEventListener("blur",gCg,!1),typeof PointerEvent<"u"?(document.addEventListener("pointerdown",qm,!0),document.addEventListener("pointermove",qm,!0),document.addEventListener("pointerup",qm,!0)):(document.addEventListener("mousedown",qm,!0),document.addEventListener("mousemove",qm,!0),document.addEventListener("mouseup",qm,!0)),Vle=!0}typeof document<"u"&&(document.readyState!=="loading"?hH():document.addEventListener("DOMContentLoaded",hH));function u$(){return Es!=="pointer"}function XO(){return Es}function ICg(e){Es=e,Hk(e,null)}function iCg(){hH();let[e,g]=Ie.useState(Es);return Ie.useEffect(()=>{let I=()=>{g(Es)};return JB.add(I),()=>{JB.delete(I)}},[]),mw()?null:e}const nCg=new Set(["checkbox","radio","range","color","file","image","button","submit","reset"]);function CCg(e,g,I){var i;return e=e||(I==null?void 0:I.target)instanceof HTMLInputElement&&!nCg.has(I==null||(i=I.target)===null||i===void 0?void 0:i.type)||(I==null?void 0:I.target)instanceof HTMLTextAreaElement||(I==null?void 0:I.target)instanceof HTMLElement&&(I==null?void 0:I.target.isContentEditable),!(e&&g==="keyboard"&&I instanceof KeyboardEvent&&!$ng[I.key])}function rCg(e,g,I){hH(),Ie.useEffect(()=>{let i=(n,C)=>{CCg(!!(I!=null&&I.isTextInput),n,C)&&e(u$())};return JB.add(i),()=>{JB.delete(i)}},g)}function c2e(e){let{isDisabled:g,onBlurWithin:I,onFocusWithin:i,onFocusWithinChange:n}=e,C=Ie.useRef({isFocusWithin:!1}),r=Ie.useCallback(s=>{C.current.isFocusWithin&&!s.currentTarget.contains(s.relatedTarget)&&(C.current.isFocusWithin=!1,I&&I(s),n&&n(!1))},[I,n,C]),o=s2e(r),A=Ie.useCallback(s=>{!C.current.isFocusWithin&&document.activeElement===s.target&&(i&&i(s),n&&n(!0),C.current.isFocusWithin=!0,o(s))},[i,n,o]);return g?{focusWithinProps:{onFocus:void 0,onBlur:void 0}}:{focusWithinProps:{onFocus:A,onBlur:r}}}let mH=!1,IF=0;function HO(){mH=!0,setTimeout(()=>{mH=!1},50)}function Wle(e){e.pointerType==="touch"&&HO()}function oCg(){if(!(typeof document>"u"))return typeof PointerEvent<"u"?document.addEventListener("pointerup",Wle):document.addEventListener("touchend",HO),IF++,()=>{IF--,!(IF>0)&&(typeof PointerEvent<"u"?document.removeEventListener("pointerup",Wle):document.removeEventListener("touchend",HO))}}function d$(e){let{onHoverStart:g,onHoverChange:I,onHoverEnd:i,isDisabled:n}=e,[C,r]=Ie.useState(!1),o=Ie.useRef({isHovered:!1,ignoreEmulatedMouseEvents:!1,pointerType:"",target:null}).current;Ie.useEffect(oCg,[]);let{hoverProps:A,triggerHoverEnd:s}=Ie.useMemo(()=>{let a=(u,d)=>{if(o.pointerType=d,n||d==="touch"||o.isHovered||!u.currentTarget.contains(u.target))return;o.isHovered=!0;let h=u.currentTarget;o.target=h,g&&g({type:"hoverstart",target:h,pointerType:d}),I&&I(!0),r(!0)},l=(u,d)=>{if(o.pointerType="",o.target=null,d==="touch"||!o.isHovered)return;o.isHovered=!1;let h=u.currentTarget;i&&i({type:"hoverend",target:h,pointerType:d}),I&&I(!1),r(!1)},c={};return typeof PointerEvent<"u"?(c.onPointerEnter=u=>{mH&&u.pointerType==="mouse"||a(u,u.pointerType)},c.onPointerLeave=u=>{!n&&u.currentTarget.contains(u.target)&&l(u,u.pointerType)}):(c.onTouchStart=()=>{o.ignoreEmulatedMouseEvents=!0},c.onMouseEnter=u=>{!o.ignoreEmulatedMouseEvents&&!mH&&a(u,"mouse"),o.ignoreEmulatedMouseEvents=!1},c.onMouseLeave=u=>{!n&&u.currentTarget.contains(u.target)&&l(u,"mouse")}),{hoverProps:c,triggerHoverEnd:l}},[g,I,i,n,o]);return Ie.useEffect(()=>{n&&s({currentTarget:o.target},o.pointerType)},[n]),{hoverProps:A,isHovered:C}}function Xle(e){if(!e)return;let g=!0;return I=>{let i={...I,preventDefault(){I.preventDefault()},isDefaultPrevented(){return I.isDefaultPrevented()},stopPropagation(){console.error("stopPropagation is now the default behavior for events in React Spectrum. You can use continuePropagation() to revert this behavior.")},continuePropagation(){g=!1}};e(i),g&&I.stopPropagation()}}function ACg(e){return{keyboardProps:e.isDisabled?{}:{onKeyDown:Xle(e.onKeyDown),onKeyUp:Xle(e.onKeyUp)}}}const aCg=500;function sCg(e){let{isDisabled:g,onLongPressStart:I,onLongPressEnd:i,onLongPress:n,threshold:C=aCg,accessibilityDescription:r}=e;const o=Ie.useRef();let{addGlobalListener:A,removeGlobalListener:s}=i2e(),{pressProps:a}=l$({isDisabled:g,onPressStart(c){if(c.continuePropagation(),(c.pointerType==="mouse"||c.pointerType==="touch")&&(I&&I({...c,type:"longpressstart"}),o.current=setTimeout(()=>{c.target.dispatchEvent(new PointerEvent("pointercancel",{bubbles:!0})),n&&n({...c,type:"longpress"}),o.current=void 0},C),c.pointerType==="touch")){let u=d=>{d.preventDefault()};A(c.target,"contextmenu",u,{once:!0}),A(window,"pointerup",()=>{setTimeout(()=>{s(c.target,"contextmenu",u)},30)},{once:!0})}},onPressEnd(c){o.current&&clearTimeout(o.current),i&&(c.pointerType==="mouse"||c.pointerType==="touch")&&i({...c,type:"longpressend"})}}),l=Xk(n&&!g?r:void 0);return{longPressProps:pi(a,l)}}function QC(e){if(XO()==="virtual"){let g=document.activeElement;I2e(()=>{document.activeElement===g&&document.contains(e)&&ms(e)})}else ms(e)}function lCg(e){if(!(e instanceof HTMLElement)&&!(e instanceof SVGElement))return!1;let{display:g,visibility:I}=e.style,i=g!=="none"&&I!=="hidden"&&I!=="collapse";if(i){const{getComputedStyle:n}=e.ownerDocument.defaultView;let{display:C,visibility:r}=n(e);i=C!=="none"&&r!=="hidden"&&r!=="collapse"}return i}function cCg(e,g){return!e.hasAttribute("hidden")&&(e.nodeName==="DETAILS"&&g&&g.nodeName!=="SUMMARY"?e.hasAttribute("open"):!0)}function u2e(e,g){return e.nodeName!=="#comment"&&lCg(e)&&cCg(e,g)&&(!e.parentElement||u2e(e.parentElement,e))}const Hle=N.createContext(null);let hI=null;function uCg(e){let{children:g,contain:I,restoreFocus:i,autoFocus:n}=e,C=Ie.useRef(null),r=Ie.useRef(null),o=Ie.useRef([]),{parentNode:A}=Ie.useContext(Hle)||{},s=Ie.useMemo(()=>new NO({scopeRef:o}),[o]);hi(()=>{let c=A||si.root;if(si.getTreeNode(c.scopeRef)&&hI&&!fH(hI,c.scopeRef)){let u=si.getTreeNode(hI);u&&(c=u)}c.addChild(s),si.addNode(s)},[s,A]),hi(()=>{let c=si.getTreeNode(o);c&&(c.contain=!!I)},[I]),hi(()=>{var c;let u=(c=C.current)===null||c===void 0?void 0:c.nextSibling,d=[];for(;u&&u!==r.current;)d.push(u),u=u.nextSibling;o.current=d},[g]),bCg(o,i,I),fCg(o,I),ZCg(o,i,I),pCg(o,n),Ie.useEffect(()=>{let c=document.activeElement,u=null;if(Wn(c,o.current)){for(let d of si.traverse())d.scopeRef&&Wn(c,d.scopeRef.current)&&(u=d);u===si.getTreeNode(o)&&(hI=u.scopeRef)}},[o]),hi(()=>()=>{var c,u,d;let h=(d=(u=si.getTreeNode(o))===null||u===void 0||(c=u.parent)===null||c===void 0?void 0:c.scopeRef)!==null&&d!==void 0?d:null;(o===hI||fH(o,hI))&&(!h||si.getTreeNode(h))&&(hI=h),si.removeTreeNode(o)},[o]);let a=Ie.useMemo(()=>dCg(o),[]),l=Ie.useMemo(()=>({focusManager:a,parentNode:s}),[s,a]);return N.createElement(Hle.Provider,{value:l},N.createElement("span",{"data-focus-scope-start":!0,hidden:!0,ref:C}),g,N.createElement("span",{"data-focus-scope-end":!0,hidden:!0,ref:r}))}function dCg(e){return{focusNext(g={}){let I=e.current,{from:i,tabbable:n,wrap:C,accept:r}=g,o=i||document.activeElement,A=I[0].previousElementSibling,s=Ad(I),a=_r(s,{tabbable:n,accept:r},I);a.currentNode=Wn(o,I)?o:A;let l=a.nextNode();return!l&&C&&(a.currentNode=A,l=a.nextNode()),l&&fs(l,!0),l},focusPrevious(g={}){let I=e.current,{from:i,tabbable:n,wrap:C,accept:r}=g,o=i||document.activeElement,A=I[I.length-1].nextElementSibling,s=Ad(I),a=_r(s,{tabbable:n,accept:r},I);a.currentNode=Wn(o,I)?o:A;let l=a.previousNode();return!l&&C&&(a.currentNode=A,l=a.previousNode()),l&&fs(l,!0),l},focusFirst(g={}){let I=e.current,{tabbable:i,accept:n}=g,C=Ad(I),r=_r(C,{tabbable:i,accept:n},I);r.currentNode=I[0].previousElementSibling;let o=r.nextNode();return o&&fs(o,!0),o},focusLast(g={}){let I=e.current,{tabbable:i,accept:n}=g,C=Ad(I),r=_r(C,{tabbable:i,accept:n},I);r.currentNode=I[I.length-1].nextElementSibling;let o=r.previousNode();return o&&fs(o,!0),o}}}const h$=["input:not([disabled]):not([type=hidden])","select:not([disabled])","textarea:not([disabled])","button:not([disabled])","a[href]","area[href]","summary","iframe","object","embed","audio[controls]","video[controls]","[contenteditable]"],hCg=h$.join(":not([hidden]),")+",[tabindex]:not([disabled]):not([hidden])";h$.push('[tabindex]:not([tabindex="-1"]):not([disabled])');const mCg=h$.join(':not([hidden]):not([tabindex="-1"]),');function Ad(e){return e[0].parentElement}function IG(e){let g=si.getTreeNode(hI);for(;g&&g.scopeRef!==e;){if(g.contain)return!1;g=g.parent}return!0}function fCg(e,g){let I=Ie.useRef(),i=Ie.useRef();hi(()=>{let n=e.current;if(!g){i.current&&(cancelAnimationFrame(i.current),i.current=void 0);return}let C=A=>{if(A.key!=="Tab"||A.altKey||A.ctrlKey||A.metaKey||!IG(e))return;let s=document.activeElement,a=e.current;if(!a||!Wn(s,a))return;let l=Ad(a),c=_r(l,{tabbable:!0},a);if(!s)return;c.currentNode=s;let u=A.shiftKey?c.previousNode():c.nextNode();u||(c.currentNode=A.shiftKey?a[a.length-1].nextElementSibling:a[0].previousElementSibling,u=A.shiftKey?c.previousNode():c.nextNode()),A.preventDefault(),u&&fs(u,!0)},r=A=>{(!hI||fH(hI,e))&&Wn(A.target,e.current)?(hI=e,I.current=A.target):IG(e)&&!TO(A.target,e)?I.current?I.current.focus():hI&&hI.current&&pH(hI.current):IG(e)&&(I.current=A.target)},o=A=>{i.current&&cancelAnimationFrame(i.current),i.current=requestAnimationFrame(()=>{if(document.activeElement&&IG(e)&&!TO(document.activeElement,e))if(hI=e,document.body.contains(A.target)){var s;I.current=A.target,(s=I.current)===null||s===void 0||s.focus()}else hI.current&&pH(hI.current)})};return document.addEventListener("keydown",C,!1),document.addEventListener("focusin",r,!1),n==null||n.forEach(A=>A.addEventListener("focusin",r,!1)),n==null||n.forEach(A=>A.addEventListener("focusout",o,!1)),()=>{document.removeEventListener("keydown",C,!1),document.removeEventListener("focusin",r,!1),n==null||n.forEach(A=>A.removeEventListener("focusin",r,!1)),n==null||n.forEach(A=>A.removeEventListener("focusout",o,!1))}},[e,g]),hi(()=>()=>{i.current&&cancelAnimationFrame(i.current)},[i])}function d2e(e){return TO(e)}function Wn(e,g){return!e||!g?!1:g.some(I=>I.contains(e))}function TO(e,g=null){if(e instanceof Element&&e.closest("[data-react-aria-top-layer]"))return!0;for(let{scopeRef:I}of si.traverse(si.getTreeNode(g)))if(I&&Wn(e,I.current))return!0;return!1}function fH(e,g){var I;let i=(I=si.getTreeNode(g))===null||I===void 0?void 0:I.parent;for(;i;){if(i.scopeRef===e)return!0;i=i.parent}return!1}function fs(e,g=!1){if(e!=null&&!g)try{QC(e)}catch{}else if(e!=null)try{e.focus()}catch{}}function pH(e,g=!0){let I=e[0].previousElementSibling,i=Ad(e),n=_r(i,{tabbable:g},e);n.currentNode=I;let C=n.nextNode();g&&!C&&(i=Ad(e),n=_r(i,{tabbable:!1},e),n.currentNode=I,C=n.nextNode()),fs(C)}function pCg(e,g){const I=N.useRef(g);Ie.useEffect(()=>{I.current&&(hI=e,!Wn(document.activeElement,hI.current)&&e.current&&pH(e.current)),I.current=!1},[e])}function bCg(e,g,I){hi(()=>{if(g||I)return;let i=e.current,n=C=>{let r=C.target;Wn(r,e.current)?hI=e:d2e(r)||(hI=null)};return document.addEventListener("focusin",n,!1),i==null||i.forEach(C=>C.addEventListener("focusin",n,!1)),()=>{document.removeEventListener("focusin",n,!1),i==null||i.forEach(C=>C.removeEventListener("focusin",n,!1))}},[e,g,I])}function yCg(e){let g=si.getTreeNode(hI);for(;g&&g.scopeRef!==e;){if(g.nodeToRestore)return!1;g=g.parent}return(g==null?void 0:g.scopeRef)===e}function ZCg(e,g,I){const i=Ie.useRef(typeof document<"u"?document.activeElement:null);hi(()=>{let n=e.current;if(!g||I)return;let C=()=>{(!hI||fH(hI,e))&&Wn(document.activeElement,e.current)&&(hI=e)};return document.addEventListener("focusin",C,!1),n==null||n.forEach(r=>r.addEventListener("focusin",C,!1)),()=>{document.removeEventListener("focusin",C,!1),n==null||n.forEach(r=>r.removeEventListener("focusin",C,!1))}},[e,I]),hi(()=>{if(!g)return;let n=C=>{if(C.key!=="Tab"||C.altKey||C.ctrlKey||C.metaKey||!IG(e))return;let r=document.activeElement;if(!Wn(r,e.current))return;let o=si.getTreeNode(e);if(!o)return;let A=o.nodeToRestore,s=_r(document.body,{tabbable:!0});s.currentNode=r;let a=C.shiftKey?s.previousNode():s.nextNode();if((!A||!document.body.contains(A)||A===document.body)&&(A=void 0,o.nodeToRestore=void 0),(!a||!Wn(a,e.current))&&A){s.currentNode=A;do a=C.shiftKey?s.previousNode():s.nextNode();while(Wn(a,e.current));C.preventDefault(),C.stopPropagation(),a?fs(a,!0):d2e(A)?fs(A,!0):r.blur()}};return I||document.addEventListener("keydown",n,!0),()=>{I||document.removeEventListener("keydown",n,!0)}},[e,g,I]),hi(()=>{if(!g)return;let n=si.getTreeNode(e);if(n){var C;return n.nodeToRestore=(C=i.current)!==null&&C!==void 0?C:void 0,()=>{let r=si.getTreeNode(e);if(!r)return;let o=r.nodeToRestore;if(g&&o&&(Wn(document.activeElement,e.current)||document.activeElement===document.body&&yCg(e))){let A=si.clone();requestAnimationFrame(()=>{if(document.activeElement===document.body){let s=A.getTreeNode(e);for(;s;){if(s.nodeToRestore&&document.body.contains(s.nodeToRestore)){fs(s.nodeToRestore);return}s=s.parent}for(s=A.getTreeNode(e);s;){if(s.scopeRef&&s.scopeRef.current&&si.getTreeNode(s.scopeRef)){pH(s.scopeRef.current,!0);return}s=s.parent}}})}}}},[e,g])}function _r(e,g,I){let i=g!=null&&g.tabbable?mCg:hCg,n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode(C){var r;return!(g==null||(r=g.from)===null||r===void 0)&&r.contains(C)?NodeFilter.FILTER_REJECT:C.matches(i)&&u2e(C)&&(!I||Wn(C,I))&&(!(g!=null&&g.accept)||g.accept(C))?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});return g!=null&&g.from&&(n.currentNode=g.from),n}class m${get size(){return this.fastMap.size}getTreeNode(g){return this.fastMap.get(g)}addTreeNode(g,I,i){let n=this.fastMap.get(I??null);if(!n)return;let C=new NO({scopeRef:g});n.addChild(C),C.parent=n,this.fastMap.set(g,C),i&&(C.nodeToRestore=i)}addNode(g){this.fastMap.set(g.scopeRef,g)}removeTreeNode(g){if(g===null)return;let I=this.fastMap.get(g);if(!I)return;let i=I.parent;for(let C of this.traverse())C!==I&&I.nodeToRestore&&C.nodeToRestore&&I.scopeRef&&I.scopeRef.current&&Wn(C.nodeToRestore,I.scopeRef.current)&&(C.nodeToRestore=I.nodeToRestore);let n=I.children;i&&(i.removeChild(I),n.size>0&&n.forEach(C=>i&&i.addChild(C))),this.fastMap.delete(I.scopeRef)}*traverse(g=this.root){if(g.scopeRef!=null&&(yield g),g.children.size>0)for(let I of g.children)yield*this.traverse(I)}clone(){var g;let I=new m$;var i;for(let n of this.traverse())I.addTreeNode(n.scopeRef,(i=(g=n.parent)===null||g===void 0?void 0:g.scopeRef)!==null&&i!==void 0?i:null,n.nodeToRestore);return I}constructor(){this.fastMap=new Map,this.root=new NO({scopeRef:null}),this.fastMap.set(null,this.root)}}class NO{addChild(g){this.children.add(g),g.parent=this}removeChild(g){this.children.delete(g),g.parent=void 0}constructor(g){this.children=new Set,this.contain=!1,this.scopeRef=g.scopeRef}}let si=new m$;function Tk(e={}){let{autoFocus:g=!1,isTextInput:I,within:i}=e,n=Ie.useRef({isFocused:!1,isFocusVisible:g||u$()}),[C,r]=Ie.useState(!1),[o,A]=Ie.useState(()=>n.current.isFocused&&n.current.isFocusVisible),s=Ie.useCallback(()=>A(n.current.isFocused&&n.current.isFocusVisible),[]),a=Ie.useCallback(u=>{n.current.isFocused=u,r(u),s()},[s]);rCg(u=>{n.current.isFocusVisible=u,s()},[],{isTextInput:I});let{focusProps:l}=l2e({isDisabled:i,onFocusChange:a}),{focusWithinProps:c}=c2e({isDisabled:!i,onFocusWithinChange:a});return{isFocused:C,isFocusVisible:o,focusProps:i?c:l}}let GCg=N.createContext(null);function vCg(e){let g=Ie.useContext(GCg)||{};C2e(g,e);let{ref:I,...i}=g;return i}function h2e(e,g){let{focusProps:I}=l2e(e),{keyboardProps:i}=ACg(e),n=pi(I,i),C=vCg(g),r=e.isDisabled?{}:C,o=Ie.useRef(e.autoFocus);return Ie.useEffect(()=>{o.current&&g.current&&QC(g.current),o.current=!1},[g]),{focusableProps:pi({...n,tabIndex:e.excludeFromTabOrder&&!e.isDisabled?-1:void 0},r)}}function BCg(e,g){let I=g==null?void 0:g.isDisabled,[i,n]=Ie.useState(!1);return hi(()=>{if(e!=null&&e.current&&!I){let C=()=>{if(e.current){let o=_r(e.current,{tabbable:!0});n(!!o.nextNode())}};C();let r=new MutationObserver(C);return r.observe(e.current,{subtree:!0,childList:!0,attributes:!0,attributeFilter:["tabIndex","disabled"]}),()=>{r.disconnect()}}}),I?!1:i}class SCg{getStringForLocale(g,I){let i=this.strings[I];i||(i=wCg(I,this.strings,this.defaultLocale),this.strings[I]=i);let n=i[g];if(!n)throw new Error(`Could not find intl message ${g} in ${I} locale`);return n}constructor(g,I="en-US"){this.strings={...g},this.defaultLocale=I}}function wCg(e,g,I="en-US"){if(g[e])return g[e];let i=VCg(e);if(g[i])return g[i];for(let n in g)if(n.startsWith(i+"-"))return g[n];return g[I]}function VCg(e){return Intl.Locale?new Intl.Locale(e).language:e.split("-")[0]}const Tle=new Map,Nle=new Map;class RCg{format(g,I){let i=this.strings.getStringForLocale(g,this.locale);return typeof i=="function"?i(I,this):i}plural(g,I,i="cardinal"){let n=I["="+g];if(n)return typeof n=="function"?n():n;let C=this.locale+":"+i,r=Tle.get(C);r||(r=new Intl.PluralRules(this.locale,{type:i}),Tle.set(C,r));let o=r.select(g);return n=I[o]||I.other,typeof n=="function"?n():n}number(g){let I=Nle.get(this.locale);return I||(I=new Intl.NumberFormat(this.locale),Nle.set(this.locale,I)),I.format(g)}select(g,I){let i=g[I]||g.other;return typeof i=="function"?i():i}constructor(g,I){this.locale=g,this.strings=I}}const WCg=new Set(["Arab","Syrc","Samr","Mand","Thaa","Mend","Nkoo","Adlm","Rohg","Hebr"]),XCg=new Set(["ae","ar","arc","bcc","bqi","ckb","dv","fa","glk","he","ku","mzn","nqo","pnb","ps","sd","ug","ur","yi"]);function HCg(e){if(Intl.Locale){let I=new Intl.Locale(e).maximize().script;return I?WCg.has(I):!1}let g=e.split("-")[0];return XCg.has(g)}function m2e(){let e=typeof navigator<"u"&&(navigator.language||navigator.userLanguage)||"en-US";try{Intl.DateTimeFormat.supportedLocalesOf([e])}catch{e="en-US"}return{locale:e,direction:HCg(e)?"rtl":"ltr"}}let kO=m2e(),iG=new Set;function kle(){kO=m2e();for(let e of iG)e(kO)}function TCg(){let e=mw(),[g,I]=Ie.useState(kO);return Ie.useEffect(()=>(iG.size===0&&window.addEventListener("languagechange",kle),iG.add(I),()=>{iG.delete(I),iG.size===0&&window.removeEventListener("languagechange",kle)}),[]),e?{locale:"en-US",direction:"ltr"}:g}const NCg=N.createContext(null);function um(){let e=TCg();return Ie.useContext(NCg)||e}const Yle=new WeakMap;function kCg(e){let g=Yle.get(e);return g||(g=new SCg(e),Yle.set(e,g)),g}function iy(e){let{locale:g}=um(),I=Ie.useMemo(()=>kCg(e),[e]);return Ie.useMemo(()=>new RCg(g,I),[g,I])}let iF=new Map;function f2e(e){let{locale:g}=um(),I=g+(e?Object.entries(e).sort((n,C)=>n[0]{n.remove()},i)}clear(g){this.node&&((!g||g==="assertive")&&(this.assertiveLog.innerHTML=""),(!g||g==="polite")&&(this.politeLog.innerHTML=""))}constructor(){this.node=document.createElement("div"),this.node.dataset.liveAnnouncer="true",Object.assign(this.node.style,{border:0,clip:"rect(0 0 0 0)",clipPath:"inset(50%)",height:"1px",margin:"-1px",overflow:"hidden",padding:0,position:"absolute",width:"1px",whiteSpace:"nowrap"}),this.assertiveLog=this.createLog("assertive"),this.node.appendChild(this.assertiveLog),this.politeLog=this.createLog("polite"),this.node.appendChild(this.politeLog),document.body.prepend(this.node)}}function KCg(e,g,I){let{validationBehavior:i,focus:n}=e;hi(()=>{if(i==="native"&&(I!=null&&I.current)){let A=g.realtimeValidation.isInvalid?g.realtimeValidation.validationErrors.join(" ")||"Invalid value.":"";I.current.setCustomValidity(A),I.current.hasAttribute("title")||(I.current.title=""),g.realtimeValidation.isInvalid||g.updateValidation(xCg(I.current))}});let C=Ir(()=>{g.resetValidation()}),r=Ir(A=>{var s;g.displayValidation.isInvalid||g.commitValidation();let a=I==null||(s=I.current)===null||s===void 0?void 0:s.form;if(!A.defaultPrevented&&I&&a&&FCg(a)===I.current){var l;n?n():(l=I.current)===null||l===void 0||l.focus(),ICg("keyboard")}A.preventDefault()}),o=Ir(()=>{g.commitValidation()});Ie.useEffect(()=>{let A=I==null?void 0:I.current;if(!A)return;let s=A.form;return A.addEventListener("invalid",r),A.addEventListener("change",o),s==null||s.addEventListener("reset",C),()=>{A.removeEventListener("invalid",r),A.removeEventListener("change",o),s==null||s.removeEventListener("reset",C)}},[I,r,o,C,i])}function DCg(e){let g=e.validity;return{badInput:g.badInput,customError:g.customError,patternMismatch:g.patternMismatch,rangeOverflow:g.rangeOverflow,rangeUnderflow:g.rangeUnderflow,stepMismatch:g.stepMismatch,tooLong:g.tooLong,tooShort:g.tooShort,typeMismatch:g.typeMismatch,valueMissing:g.valueMissing,valid:g.valid}}function xCg(e){return{isInvalid:!e.validity.valid,validationDetails:DCg(e),validationErrors:e.validationMessage?[e.validationMessage]:[]}}function FCg(e){for(let g=0;gDle(PCg(r,n)),[r,n]);C!=null&&C.validationDetails.valid&&(C=null);let a=Ie.useContext(ECg),l=Ie.useMemo(()=>i?Array.isArray(i)?i.flatMap(V=>YO(a[V])):YO(a[i]):[],[a,i]),[c,u]=Ie.useState(a),[d,h]=Ie.useState(!1);a!==c&&(u(a),h(!1));let m=Ie.useMemo(()=>Dle(d?[]:l),[d,l]),f=Ie.useRef(aZ),[b,p]=Ie.useState(aZ),y=Ie.useRef(aZ),Z=()=>{if(!B)return;G(!1);let V=s||C||f.current;CF(V,y.current)||(y.current=V,p(V))},[B,G]=Ie.useState(!1);return Ie.useEffect(Z),{realtimeValidation:A||m||s||C||aZ,displayValidation:o==="native"?A||m||b:A||m||s||C||b,updateValidation(V){o==="aria"&&!CF(b,V)?p(V):f.current=V},resetValidation(){let V=aZ;CF(V,y.current)||(y.current=V,p(V)),o==="native"&&G(!1),h(!0)},commitValidation(){o==="native"&&G(!0),h(!0)}}}function YO(e){return e?Array.isArray(e)?e:[e]:[]}function PCg(e,g){if(typeof e=="function"){let I=e(g);if(I&&typeof I!="boolean")return YO(I)}return[]}function Dle(e){return e.length?{isInvalid:!0,validationErrors:e,validationDetails:Z2e}:null}function CF(e,g){return e===g?!0:e&&g&&e.isInvalid===g.isInvalid&&e.validationErrors.length===g.validationErrors.length&&e.validationErrors.every((I,i)=>I===g.validationErrors[i])&&Object.entries(e.validationDetails).every(([I,i])=>g.validationDetails[I]===i)}function JCg(e){let{id:g,label:I,"aria-labelledby":i,"aria-label":n,labelElementType:C="label"}=e;g=Rh(g);let r=Rh(),o={};I?(i=i?`${r} ${i}`:r,o={id:r,htmlFor:C==="label"?g:void 0}):!i&&!n&&console.warn("If you do not provide a visible label, you must specify an aria-label or aria-labelledby attribute for accessibility");let A=Yng({id:g,"aria-label":n,"aria-labelledby":i});return{labelProps:o,fieldProps:A}}function OCg(e){let{description:g,errorMessage:I,isInvalid:i,validationState:n}=e,{labelProps:C,fieldProps:r}=JCg(e),o=ble([!!g,!!I,i,n]),A=ble([!!g,!!I,i,n]);return r=pi(r,{"aria-describedby":[o,A,e["aria-describedby"]].filter(Boolean).join(" ")||void 0}),{labelProps:C,fieldProps:r,descriptionProps:{id:o},errorMessageProps:{id:A}}}const xle={border:0,clip:"rect(0 0 0 0)",clipPath:"inset(50%)",height:"1px",margin:"-1px",overflow:"hidden",padding:0,position:"absolute",width:"1px",whiteSpace:"nowrap"};function f$(e={}){let{style:g,isFocusable:I}=e,[i,n]=Ie.useState(!1),{focusWithinProps:C}=c2e({isDisabled:!I,onFocusWithinChange:o=>n(o)}),r=Ie.useMemo(()=>i?g:g?{...xle,...g}:xle,[i]);return{visuallyHiddenProps:{...C,style:r}}}function KO(e){return Vng()?e.altKey:e.ctrlKey}function Xf(e){return Wh()?e.metaKey:e.ctrlKey}const _Cg=1e3;function LCg(e){let{keyboardDelegate:g,selectionManager:I,onTypeSelect:i}=e,n=Ie.useRef({search:"",timeout:null}).current,C=r=>{let o=UCg(r.key);if(!o||r.ctrlKey||r.metaKey||!r.currentTarget.contains(r.target))return;o===" "&&n.search.trim().length>0&&(r.preventDefault(),"continuePropagation"in r||r.stopPropagation()),n.search+=o;let A=g.getKeyForSearch(n.search,I.focusedKey);A==null&&(A=g.getKeyForSearch(n.search)),A!=null&&(I.setFocusedKey(A),i&&i(A)),clearTimeout(n.timeout),n.timeout=setTimeout(()=>{n.search=""},_Cg)};return{typeSelectProps:{onKeyDownCapture:g.getKeyForSearch?C:null}}}function UCg(e){return e.length===1||!/^[A-Z]/i.test(e)?e:""}function QCg(e){let{selectionManager:g,keyboardDelegate:I,ref:i,autoFocus:n=!1,shouldFocusWrap:C=!1,disallowEmptySelection:r=!1,disallowSelectAll:o=!1,selectOnFocus:A=g.selectionBehavior==="replace",disallowTypeAhead:s=!1,shouldUseVirtualFocus:a,allowsTabNavigation:l=!1,isVirtualized:c,scrollRef:u=i,linkBehavior:d="action"}=e,{direction:h}=um(),m=g2e(),f=V=>{if(V.altKey&&V.key==="Tab"&&V.preventDefault(),!i.current.contains(V.target))return;const S=(J,ee)=>{if(J!=null){if(g.isLink(J)&&d==="selection"&&A&&!KO(V)){Rs.flushSync(()=>{g.setFocusedKey(J,ee)});let q=u.current.querySelector(`[data-key="${J}"]`);m.open(q,V);return}if(g.setFocusedKey(J,ee),g.isLink(J)&&d==="override")return;V.shiftKey&&g.selectionMode==="multiple"?g.extendSelection(J):A&&!KO(V)&&g.replaceSelection(J)}};switch(V.key){case"ArrowDown":if(I.getKeyBelow){var X,W;V.preventDefault();let J=g.focusedKey!=null?I.getKeyBelow(g.focusedKey):(X=I.getFirstKey)===null||X===void 0?void 0:X.call(I);J==null&&C&&(J=(W=I.getFirstKey)===null||W===void 0?void 0:W.call(I,g.focusedKey)),S(J)}break;case"ArrowUp":if(I.getKeyAbove){var R,H;V.preventDefault();let J=g.focusedKey!=null?I.getKeyAbove(g.focusedKey):(R=I.getLastKey)===null||R===void 0?void 0:R.call(I);J==null&&C&&(J=(H=I.getLastKey)===null||H===void 0?void 0:H.call(I,g.focusedKey)),S(J)}break;case"ArrowLeft":if(I.getKeyLeftOf){var Y,D;V.preventDefault();let J=I.getKeyLeftOf(g.focusedKey);J==null&&C&&(J=h==="rtl"?(Y=I.getFirstKey)===null||Y===void 0?void 0:Y.call(I,g.focusedKey):(D=I.getLastKey)===null||D===void 0?void 0:D.call(I,g.focusedKey)),S(J,h==="rtl"?"first":"last")}break;case"ArrowRight":if(I.getKeyRightOf){var E,O;V.preventDefault();let J=I.getKeyRightOf(g.focusedKey);J==null&&C&&(J=h==="rtl"?(E=I.getLastKey)===null||E===void 0?void 0:E.call(I,g.focusedKey):(O=I.getFirstKey)===null||O===void 0?void 0:O.call(I,g.focusedKey)),S(J,h==="rtl"?"last":"first")}break;case"Home":if(I.getFirstKey){V.preventDefault();let J=I.getFirstKey(g.focusedKey,Xf(V));g.setFocusedKey(J),Xf(V)&&V.shiftKey&&g.selectionMode==="multiple"?g.extendSelection(J):A&&g.replaceSelection(J)}break;case"End":if(I.getLastKey){V.preventDefault();let J=I.getLastKey(g.focusedKey,Xf(V));g.setFocusedKey(J),Xf(V)&&V.shiftKey&&g.selectionMode==="multiple"?g.extendSelection(J):A&&g.replaceSelection(J)}break;case"PageDown":if(I.getKeyPageBelow){V.preventDefault();let J=I.getKeyPageBelow(g.focusedKey);S(J)}break;case"PageUp":if(I.getKeyPageAbove){V.preventDefault();let J=I.getKeyPageAbove(g.focusedKey);S(J)}break;case"a":Xf(V)&&g.selectionMode==="multiple"&&o!==!0&&(V.preventDefault(),g.selectAll());break;case"Escape":V.preventDefault(),r||g.clearSelection();break;case"Tab":if(!l){if(V.shiftKey)i.current.focus();else{let J=_r(i.current,{tabbable:!0}),ee,q;do q=J.lastChild(),q&&(ee=q);while(q);ee&&!ee.contains(document.activeElement)&&ms(ee)}break}}},b=Ie.useRef({top:0,left:0});Dng(u,"scroll",c?null:()=>{b.current={top:u.current.scrollTop,left:u.current.scrollLeft}});let p=V=>{if(g.isFocused){V.currentTarget.contains(V.target)||g.setFocused(!1);return}if(V.currentTarget.contains(V.target)){if(g.setFocused(!0),g.focusedKey==null){let W=H=>{H!=null&&(g.setFocusedKey(H),A&&g.replaceSelection(H))},R=V.relatedTarget;var S,X;R&&V.currentTarget.compareDocumentPosition(R)&Node.DOCUMENT_POSITION_FOLLOWING?W((S=g.lastSelectedKey)!==null&&S!==void 0?S:I.getLastKey()):W((X=g.firstSelectedKey)!==null&&X!==void 0?X:I.getFirstKey())}else c||(u.current.scrollTop=b.current.top,u.current.scrollLeft=b.current.left);if(!c&&g.focusedKey!=null){let W=u.current.querySelector(`[data-key="${g.focusedKey}"]`);W&&(W.contains(document.activeElement)||ms(W),XO()==="keyboard"&&Fl(W,{containingElement:i.current}))}}},y=V=>{V.currentTarget.contains(V.relatedTarget)||g.setFocused(!1)};const Z=Ie.useRef(n);Ie.useEffect(()=>{if(Z.current){let V=null;n==="first"&&(V=I.getFirstKey()),n==="last"&&(V=I.getLastKey());let S=g.selectedKeys;S.size&&(V=S.values().next().value),g.setFocused(!0),g.setFocusedKey(V),V==null&&!a&&QC(i.current)}Z.current=!1},[]);let B=Ie.useRef(g.focusedKey);Ie.useEffect(()=>{let V=XO();if(g.isFocused&&g.focusedKey!=null&&(u!=null&&u.current)){let S=u.current.querySelector(`[data-key="${g.focusedKey}"]`);S&&V==="keyboard"&&(c||r2e(u.current,S),Fl(S,{containingElement:i.current}))}g.isFocused&&g.focusedKey==null&&B.current!=null&&QC(i.current),B.current=g.focusedKey},[c,u,g.focusedKey,g.isFocused,i]);let G={onKeyDown:f,onFocus:p,onBlur:y,onMouseDown(V){u.current===V.target&&V.preventDefault()}},{typeSelectProps:v}=LCg({keyboardDelegate:I,selectionManager:g});s||(G=pi(v,G));let w;return a||(w=g.focusedKey==null?0:-1),{collectionProps:{...G,tabIndex:w}}}function G2e(e){let{selectionManager:g,key:I,ref:i,shouldSelectOnPressUp:n,shouldUseVirtualFocus:C,focus:r,isDisabled:o,onAction:A,allowsDifferentPressOrigin:s,linkBehavior:a="action"}=e,l=g2e(),c=D=>{if(D.pointerType==="keyboard"&&KO(D))g.toggleSelection(I);else{if(g.selectionMode==="none")return;if(g.isLink(I)){if(a==="selection"){l.open(i.current,D),g.setSelectedKeys(g.selectedKeys);return}else if(a==="override"||a==="none")return}g.selectionMode==="single"?g.isSelected(I)&&!g.disallowEmptySelection?g.toggleSelection(I):g.replaceSelection(I):D&&D.shiftKey?g.extendSelection(I):g.selectionBehavior==="toggle"||D&&(Xf(D)||D.pointerType==="touch"||D.pointerType==="virtual")?g.toggleSelection(I):g.replaceSelection(I)}};Ie.useEffect(()=>{I===g.focusedKey&&g.isFocused&&!C&&(r?r():document.activeElement!==i.current&&QC(i.current))},[i,I,g.focusedKey,g.childFocusStrategy,g.isFocused,C]),o=o||g.isDisabled(I);let u={};!C&&!o?u={tabIndex:I===g.focusedKey?0:-1,onFocus(D){D.target===i.current&&g.setFocusedKey(I)}}:o&&(u.onMouseDown=D=>{D.preventDefault()});let d=g.isLink(I)&&a==="override",h=g.isLink(I)&&a!=="selection"&&a!=="none",m=!o&&g.canSelectItem(I)&&!d,f=(A||h)&&!o,b=f&&(g.selectionBehavior==="replace"?!m:!m||g.isEmpty),p=f&&m&&g.selectionBehavior==="replace",y=b||p,Z=Ie.useRef(null),B=y&&m,G=Ie.useRef(!1),v=Ie.useRef(!1),w=D=>{A&&A(),h&&l.open(i.current,D)},V={};n?(V.onPressStart=D=>{Z.current=D.pointerType,G.current=B,D.pointerType==="keyboard"&&(!y||Ele())&&c(D)},s?(V.onPressUp=b?null:D=>{D.pointerType!=="keyboard"&&m&&c(D)},V.onPress=b?w:null):V.onPress=D=>{if(b||p&&D.pointerType!=="mouse"){if(D.pointerType==="keyboard"&&!Fle())return;w(D)}else D.pointerType!=="keyboard"&&m&&c(D)}):(V.onPressStart=D=>{Z.current=D.pointerType,G.current=B,v.current=b,m&&(D.pointerType==="mouse"&&!b||D.pointerType==="keyboard"&&(!f||Ele()))&&c(D)},V.onPress=D=>{(D.pointerType==="touch"||D.pointerType==="pen"||D.pointerType==="virtual"||D.pointerType==="keyboard"&&y&&Fle()||D.pointerType==="mouse"&&v.current)&&(y?w(D):m&&c(D))}),u["data-key"]=I,V.preventFocusOnPress=C;let{pressProps:S,isPressed:X}=l$(V),W=p?D=>{Z.current==="mouse"&&(D.stopPropagation(),D.preventDefault(),w(D))}:void 0,{longPressProps:R}=sCg({isDisabled:!B,onLongPress(D){D.pointerType==="touch"&&(c(D),g.setSelectionBehavior("toggle"))}}),H=D=>{Z.current==="touch"&&G.current&&D.preventDefault()},Y=g.isLink(I)?D=>{Xh.isOpening||D.preventDefault()}:void 0;return{itemProps:pi(u,m||b?S:{},B?R:{},{onDoubleClick:W,onDragStartCapture:H,onClick:Y}),isPressed:X,isSelected:g.isSelected(I),isFocused:g.isFocused&&g.focusedKey===I,isDisabled:o,allowsSelection:m,hasAction:y}}function Fle(){let e=window.event;return(e==null?void 0:e.key)==="Enter"}function Ele(){let e=window.event;return(e==null?void 0:e.key)===" "||(e==null?void 0:e.code)==="Space"}class jCg{getNextKey(g){for(g=this.collection.getKeyAfter(g);g!=null;){if(this.collection.getItem(g).type==="item"&&!this.disabledKeys.has(g))return g;g=this.collection.getKeyAfter(g)}return null}getPreviousKey(g){for(g=this.collection.getKeyBefore(g);g!=null;){if(this.collection.getItem(g).type==="item"&&!this.disabledKeys.has(g))return g;g=this.collection.getKeyBefore(g)}return null}findKey(g,I,i){let n=this.getItem(g);if(!n)return null;let C=n.getBoundingClientRect();do g=I(g),n=this.getItem(g);while(n&&i(C,n.getBoundingClientRect()));return g}isSameRow(g,I){return g.top===I.top||g.left!==I.left}isSameColumn(g,I){return g.left===I.left||g.top!==I.top}getKeyBelow(g){return this.layout==="grid"&&this.orientation==="vertical"?this.findKey(g,I=>this.getNextKey(I),this.isSameRow):this.getNextKey(g)}getKeyAbove(g){return this.layout==="grid"&&this.orientation==="vertical"?this.findKey(g,I=>this.getPreviousKey(I),this.isSameRow):this.getPreviousKey(g)}getNextColumn(g,I){return I?this.getPreviousKey(g):this.getNextKey(g)}getKeyRightOf(g){return this.layout==="grid"?this.orientation==="vertical"?this.getNextColumn(g,this.direction==="rtl"):this.findKey(g,I=>this.getNextColumn(I,this.direction==="rtl"),this.isSameColumn):this.orientation==="horizontal"?this.getNextColumn(g,this.direction==="rtl"):null}getKeyLeftOf(g){return this.layout==="grid"?this.orientation==="vertical"?this.getNextColumn(g,this.direction==="ltr"):this.findKey(g,I=>this.getNextColumn(I,this.direction==="ltr"),this.isSameColumn):this.orientation==="horizontal"?this.getNextColumn(g,this.direction==="ltr"):null}getFirstKey(){let g=this.collection.getFirstKey();for(;g!=null;){if(this.collection.getItem(g).type==="item"&&!this.disabledKeys.has(g))return g;g=this.collection.getKeyAfter(g)}return null}getLastKey(){let g=this.collection.getLastKey();for(;g!=null;){if(this.collection.getItem(g).type==="item"&&!this.disabledKeys.has(g))return g;g=this.collection.getKeyBefore(g)}return null}getItem(g){return this.ref.current.querySelector(`[data-key="${g}"]`)}getKeyPageAbove(g){let I=this.ref.current,i=this.getItem(g);if(!i)return null;if(!dH(I))return this.getFirstKey();let n=I.getBoundingClientRect(),C=i.getBoundingClientRect();if(this.orientation==="horizontal"){let r=n.x-I.scrollLeft,o=Math.max(0,C.x-r+C.width-n.width);for(;i&&C.x-r>o;)g=this.getKeyAbove(g),i=g==null?null:this.getItem(g),C=i==null?void 0:i.getBoundingClientRect()}else{let r=n.y-I.scrollTop,o=Math.max(0,C.y-r+C.height-n.height);for(;i&&C.y-r>o;)g=this.getKeyAbove(g),i=g==null?null:this.getItem(g),C=i==null?void 0:i.getBoundingClientRect()}return g??this.getFirstKey()}getKeyPageBelow(g){let I=this.ref.current,i=this.getItem(g);if(!i)return null;if(!dH(I))return this.getLastKey();let n=I.getBoundingClientRect(),C=i.getBoundingClientRect();if(this.orientation==="horizontal"){let r=n.x-I.scrollLeft,o=Math.min(I.scrollWidth,C.x-r-C.width+n.width);for(;i&&C.x-rthis.iterateCollection(g))}*iterateCollection(g){let{children:I,items:i}=g;if(typeof I=="function"){if(!i)throw new Error("props.children was a function but props.items is missing");for(let n of g.items)yield*this.getFullNode({value:n},{renderer:I})}else{let n=[];N.Children.forEach(I,r=>{n.push(r)});let C=0;for(let r of n){let o=this.getFullNode({element:r,index:C},{});for(let A of o)C++,yield A}}}getKey(g,I,i,n){if(g.key!=null)return g.key;if(I.type==="cell"&&I.key!=null)return`${n}${I.key}`;let C=I.value;if(C!=null){var r;let o=(r=C.key)!==null&&r!==void 0?r:C.id;if(o==null)throw new Error("No key found for item");return o}return n?`${n}.${I.index}`:`$.${I.index}`}getChildState(g,I){return{renderer:I.renderer||g.renderer}}*getFullNode(g,I,i,n){let C=g.element;if(!C&&g.value&&I&&I.renderer){let A=this.cache.get(g.value);if(A&&(!A.shouldInvalidate||!A.shouldInvalidate(this.context))){A.index=g.index,A.parentKey=n?n.key:null,yield A;return}C=I.renderer(g.value)}if(N.isValidElement(C)){let A=C.type;if(typeof A!="function"&&typeof A.getCollectionNode!="function"){let c=typeof C.type=="function"?C.type.name:C.type;throw new Error(`Unknown element <${c}> in collection.`)}let s=A.getCollectionNode(C.props,this.context),a=g.index,l=s.next();for(;!l.done&&l.value;){let c=l.value;g.index=a;let u=c.key;u||(u=c.element?null:this.getKey(C,g,I,i));let h=[...this.getFullNode({...c,key:u,index:a,wrapper:qCg(g.wrapper,c.wrapper)},this.getChildState(I,c),i?`${i}${C.key}`:C.key,n)];for(let m of h){if(m.value=c.value||g.value,m.value&&this.cache.set(m.value,m),g.type&&m.type!==g.type)throw new Error(`Unsupported type <${rF(m.type)}> in <${rF(n.type)}>. Only <${rF(g.type)}> is supported.`);a++,yield m}l=s.next(h)}return}if(g.key==null)return;let r=this,o={type:g.type,props:g.props,key:g.key,parentKey:n?n.key:null,value:g.value,level:n?n.level+1:0,index:g.index,rendered:g.rendered,textValue:g.textValue,"aria-label":g["aria-label"],wrapper:g.wrapper,shouldInvalidate:g.shouldInvalidate,hasChildNodes:g.hasChildNodes,childNodes:Mle(function*(){if(!g.hasChildNodes)return;let A=0;for(let s of g.childNodes()){s.key!=null&&(s.key=`${o.key}${s.key}`),s.index=A;let a=r.getFullNode(s,r.getChildState(I,s),o.key,o);for(let l of a)A++,yield l}})};yield o}constructor(){this.cache=new WeakMap}}function Mle(e){let g=[],I=null;return{*[Symbol.iterator](){for(let i of g)yield i;I||(I=e());for(let i of I)g.push(i),yield i}}}function qCg(e,g){if(e&&g)return I=>e(g(I));if(e)return e;if(g)return g}function rF(e){return e[0].toUpperCase()+e.slice(1)}function erg(e,g,I){let i=Ie.useMemo(()=>new $Cg,[]),{children:n,items:C,collection:r}=e;return Ie.useMemo(()=>{if(r)return r;let A=i.build({children:n,items:C},I);return g(A)},[i,n,C,r,I,g])}function Zi(e,g){return typeof g.getChildren=="function"?g.getChildren(e.key):e.childNodes}function Is(e){return El(e,0)}function El(e,g){if(g<0)return;let I=0;for(let i of e){if(I===g)return i;I++}}function cc(e){let g;for(let I of e)g=I;return g}function oF(e,g,I){if(g.parentKey===I.parentKey)return g.index-I.index;let i=[...zle(e,g),g],n=[...zle(e,I),I],C=i.slice(0,n.length).findIndex((r,o)=>r!==n[o]);return C!==-1?(g=i[C],I=n[C],g.index-I.index):i.findIndex(r=>r===I)>=0?1:(n.findIndex(r=>r===g)>=0,-1)}function zle(e,g){let I=[];for(;(g==null?void 0:g.parentKey)!=null;)g=e.getItem(g.parentKey),I.unshift(g);return I}function trg(e,g){let{inputElementType:I="input",isDisabled:i=!1,isRequired:n=!1,isReadOnly:C=!1,type:r="text",validationBehavior:o="aria"}=e,[A,s]=$9e(e.value,e.defaultValue||"",e.onChange),{focusableProps:a}=h2e(e,g),l=MCg({...e,value:A}),{isInvalid:c,validationErrors:u,validationDetails:d}=l.displayValidation,{labelProps:h,fieldProps:m,descriptionProps:f,errorMessageProps:b}=OCg({...e,isInvalid:c,errorMessage:e.errorMessage||u}),p=Ra(e,{labelable:!0});const y={type:r,pattern:e.pattern};return Fng(g,A,s),KCg(e,l,g),Ie.useEffect(()=>{if(g.current instanceof cH(g.current).HTMLTextAreaElement){let Z=g.current;Object.defineProperty(Z,"defaultValue",{get:()=>Z.value,set:()=>{},configurable:!0})}},[g]),{labelProps:h,inputProps:pi(p,I==="input"&&y,{disabled:i,readOnly:C,required:n&&o==="native","aria-required":n&&o==="aria"||void 0,"aria-invalid":c||void 0,"aria-errormessage":e["aria-errormessage"],"aria-activedescendant":e["aria-activedescendant"],"aria-autocomplete":e["aria-autocomplete"],"aria-haspopup":e["aria-haspopup"],value:A,onChange:Z=>s(Z.target.value),autoComplete:e.autoComplete,maxLength:e.maxLength,minLength:e.minLength,name:e.name,placeholder:e.placeholder,inputMode:e.inputMode,onCopy:e.onCopy,onCut:e.onCut,onPaste:e.onPaste,onCompositionEnd:e.onCompositionEnd,onCompositionStart:e.onCompositionStart,onCompositionUpdate:e.onCompositionUpdate,onSelect:e.onSelect,onBeforeInput:e.onBeforeInput,onInput:e.onInput,...a,...m}),descriptionProps:f,errorMessageProps:b,isInvalid:c,validationErrors:u,validationDetails:d}}class ip{copy(){return new ip(this.x,this.y)}equals(g){return this.x===g.x&&this.y===g.y}isOrigin(){return this.x===0&&this.y===0}constructor(g=0,I=0){this.x=g,this.y=I}}class np{get maxX(){return this.x+this.width}get maxY(){return this.y+this.height}get area(){return this.width*this.height}get topLeft(){return new ip(this.x,this.y)}get topRight(){return new ip(this.maxX,this.y)}get bottomLeft(){return new ip(this.x,this.maxY)}get bottomRight(){return new ip(this.maxX,this.maxY)}intersects(g){return this.x<=g.x+g.width&&g.x<=this.x+this.width&&this.y<=g.y+g.height&&g.y<=this.y+this.height}containsRect(g){return this.x<=g.x&&this.y<=g.y&&this.maxX>=g.maxX&&this.maxY>=g.maxY}containsPoint(g){return this.x<=g.x&&this.y<=g.y&&this.maxX>=g.x&&this.maxY>=g.y}getCornerInRect(g){for(let I of["topLeft","topRight","bottomLeft","bottomRight"])if(g.containsPoint(this[I]))return I;return null}equals(g){return g.x===this.x&&g.y===this.y&&g.width===this.width&&g.height===this.height}pointEquals(g){return this.x===g.x&&this.y===g.y}sizeEquals(g){return this.width===g.width&&this.height===g.height}union(g){let I=Math.min(this.x,g.x),i=Math.min(this.y,g.y),n=Math.max(this.maxX,g.maxX)-I,C=Math.max(this.maxY,g.maxY)-i;return new np(I,i,n,C)}intersection(g){if(!this.intersects(g))return new np(0,0,0,0);let I=Math.max(this.x,g.x),i=Math.max(this.y,g.y);return new np(I,i,Math.min(this.maxX,g.maxX)-I,Math.min(this.maxY,g.maxY)-i)}copy(){return new np(this.x,this.y,this.width,this.height)}constructor(g=0,I=0,i=0,n=0){this.x=g,this.y=I,this.width=i,this.height=n}}let Hf=typeof window<"u"?window.performance:null,Ple=Hf&&(Hf.now||Hf.webkitNow||Hf.msNow||Hf.mozNow);Ple&&Ple.bind(Hf);function p$(e){return e&&e.__esModule?e.default:e}class v2e{isCell(g){return g.type==="cell"}isRow(g){return g.type==="row"||g.type==="item"}findPreviousKey(g,I){let i=g!=null?this.collection.getKeyBefore(g):this.collection.getLastKey();for(;i!=null;){let n=this.collection.getItem(i);if(!this.disabledKeys.has(i)&&(!I||I(n)))return i;i=this.collection.getKeyBefore(i)}}findNextKey(g,I){let i=g!=null?this.collection.getKeyAfter(g):this.collection.getFirstKey();for(;i!=null;){let n=this.collection.getItem(i);if(!this.disabledKeys.has(i)&&(!I||I(n)))return i;i=this.collection.getKeyAfter(i)}}getKeyBelow(g){let I=this.collection.getItem(g);if(I&&(this.isCell(I)&&(g=I.parentKey),g=this.findNextKey(g),g!=null)){if(this.isCell(I)){let i=this.collection.getItem(g);return El(Zi(i,this.collection),I.index).key}if(this.focusMode==="row")return g}}getKeyAbove(g){let I=this.collection.getItem(g);if(I&&(this.isCell(I)&&(g=I.parentKey),g=this.findPreviousKey(g),g!=null)){if(this.isCell(I)){let i=this.collection.getItem(g);return El(Zi(i,this.collection),I.index).key}if(this.focusMode==="row")return g}}getKeyRightOf(g){let I=this.collection.getItem(g);if(I){if(this.isRow(I)){let i=Zi(I,this.collection);return this.direction==="rtl"?cc(i).key:Is(i).key}if(this.isCell(I)){let i=this.collection.getItem(I.parentKey),n=Zi(i,this.collection),C=this.direction==="rtl"?El(n,I.index-1):El(n,I.index+1);return C?C.key:this.focusMode==="row"?I.parentKey:this.direction==="rtl"?this.getFirstKey(g):this.getLastKey(g)}}}getKeyLeftOf(g){let I=this.collection.getItem(g);if(I){if(this.isRow(I)){let i=Zi(I,this.collection);return this.direction==="rtl"?Is(i).key:cc(i).key}if(this.isCell(I)){let i=this.collection.getItem(I.parentKey),n=Zi(i,this.collection),C=this.direction==="rtl"?El(n,I.index+1):El(n,I.index-1);return C?C.key:this.focusMode==="row"?I.parentKey:this.direction==="rtl"?this.getLastKey(g):this.getFirstKey(g)}}}getFirstKey(g,I){let i;if(g!=null){if(i=this.collection.getItem(g),!i)return;if(this.isCell(i)&&!I){let n=this.collection.getItem(i.parentKey);return Is(Zi(n,this.collection)).key}}if(g=this.findNextKey(),g!=null&&i&&this.isCell(i)&&I||this.focusMode==="cell"){let n=this.collection.getItem(g);g=Is(Zi(n,this.collection)).key}return g}getLastKey(g,I){let i;if(g!=null){if(i=this.collection.getItem(g),!i)return;if(this.isCell(i)&&!I){let n=this.collection.getItem(i.parentKey),C=Zi(n,this.collection);return cc(C).key}}if(g=this.findPreviousKey(),g!=null&&i&&this.isCell(i)&&I||this.focusMode==="cell"){let n=this.collection.getItem(g),C=Zi(n,this.collection);g=cc(C).key}return g}getItem(g){return this.ref.current.querySelector(`[data-key="${g}"]`)}getItemRect(g){var I;if(this.layout)return(I=this.layout.getLayoutInfo(g))===null||I===void 0?void 0:I.rect;let i=this.getItem(g);if(i)return new np(i.offsetLeft,i.offsetTop,i.offsetWidth,i.offsetHeight)}getPageHeight(){var g,I,i;return this.layout?(g=this.layout.virtualizer)===null||g===void 0?void 0:g.visibleRect.height:(i=this.ref)===null||i===void 0||(I=i.current)===null||I===void 0?void 0:I.offsetHeight}getContentHeight(){var g,I;return this.layout?this.layout.getContentSize().height:(I=this.ref)===null||I===void 0||(g=I.current)===null||g===void 0?void 0:g.scrollHeight}getKeyPageAbove(g){let I=this.getItemRect(g);if(!I)return null;let i=Math.max(0,I.maxY-this.getPageHeight());for(;I&&I.y>i;)g=this.getKeyAbove(g),I=this.getItemRect(g);return g}getKeyPageBelow(g){let I=this.getItemRect(g);if(!I)return null;let i=this.getPageHeight(),n=Math.min(this.getContentHeight(),I.y+i);for(;I&&I.maxY`${e.item} غير المحدد`,longPressToSelect:"اضغط مطولًا للدخول إلى وضع التحديد.",select:"تحديد",selectedAll:"جميع العناصر المحددة.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"لم يتم تحديد عناصر",one:()=>`${g.number(e.count)} عنصر محدد`,other:()=>`${g.number(e.count)} عنصر محدد`})}.`,selectedItem:e=>`${e.item} المحدد`};var S2e={};S2e={deselectedItem:e=>`${e.item} не е избран.`,longPressToSelect:"Натиснете и задръжте за да влезете в избирателен режим.",select:"Изберете",selectedAll:"Всички елементи са избрани.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Няма избрани елементи",one:()=>`${g.number(e.count)} избран елемент`,other:()=>`${g.number(e.count)} избрани елементи`})}.`,selectedItem:e=>`${e.item} избран.`};var w2e={};w2e={deselectedItem:e=>`Položka ${e.item} není vybrána.`,longPressToSelect:"Dlouhým stisknutím přejdete do režimu výběru.",select:"Vybrat",selectedAll:"Vybrány všechny položky.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Nevybrány žádné položky",one:()=>`Vybrána ${g.number(e.count)} položka`,other:()=>`Vybráno ${g.number(e.count)} položek`})}.`,selectedItem:e=>`Vybrána položka ${e.item}.`};var V2e={};V2e={deselectedItem:e=>`${e.item} ikke valgt.`,longPressToSelect:"Lav et langt tryk for at aktivere valgtilstand.",select:"Vælg",selectedAll:"Alle elementer valgt.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Ingen elementer valgt",one:()=>`${g.number(e.count)} element valgt`,other:()=>`${g.number(e.count)} elementer valgt`})}.`,selectedItem:e=>`${e.item} valgt.`};var R2e={};R2e={deselectedItem:e=>`${e.item} nicht ausgewählt.`,longPressToSelect:"Gedrückt halten, um Auswahlmodus zu öffnen.",select:"Auswählen",selectedAll:"Alle Elemente ausgewählt.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Keine Elemente ausgewählt",one:()=>`${g.number(e.count)} Element ausgewählt`,other:()=>`${g.number(e.count)} Elemente ausgewählt`})}.`,selectedItem:e=>`${e.item} ausgewählt.`};var W2e={};W2e={deselectedItem:e=>`Δεν επιλέχθηκε το στοιχείο ${e.item}.`,longPressToSelect:"Πατήστε παρατεταμένα για να μπείτε σε λειτουργία επιλογής.",select:"Επιλογή",selectedAll:"Επιλέχθηκαν όλα τα στοιχεία.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Δεν επιλέχθηκαν στοιχεία",one:()=>`Επιλέχθηκε ${g.number(e.count)} στοιχείο`,other:()=>`Επιλέχθηκαν ${g.number(e.count)} στοιχεία`})}.`,selectedItem:e=>`Επιλέχθηκε το στοιχείο ${e.item}.`};var X2e={};X2e={deselectedItem:e=>`${e.item} not selected.`,select:"Select",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"No items selected",one:()=>`${g.number(e.count)} item selected`,other:()=>`${g.number(e.count)} items selected`})}.`,selectedAll:"All items selected.",selectedItem:e=>`${e.item} selected.`,longPressToSelect:"Long press to enter selection mode."};var H2e={};H2e={deselectedItem:e=>`${e.item} no seleccionado.`,longPressToSelect:"Mantenga pulsado para abrir el modo de selección.",select:"Seleccionar",selectedAll:"Todos los elementos seleccionados.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Ningún elemento seleccionado",one:()=>`${g.number(e.count)} elemento seleccionado`,other:()=>`${g.number(e.count)} elementos seleccionados`})}.`,selectedItem:e=>`${e.item} seleccionado.`};var T2e={};T2e={deselectedItem:e=>`${e.item} pole valitud.`,longPressToSelect:"Valikurežiimi sisenemiseks vajutage pikalt.",select:"Vali",selectedAll:"Kõik üksused valitud.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Üksusi pole valitud",one:()=>`${g.number(e.count)} üksus valitud`,other:()=>`${g.number(e.count)} üksust valitud`})}.`,selectedItem:e=>`${e.item} valitud.`};var N2e={};N2e={deselectedItem:e=>`Kohdetta ${e.item} ei valittu.`,longPressToSelect:"Siirry valintatilaan painamalla pitkään.",select:"Valitse",selectedAll:"Kaikki kohteet valittu.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Ei yhtään kohdetta valittu",one:()=>`${g.number(e.count)} kohde valittu`,other:()=>`${g.number(e.count)} kohdetta valittu`})}.`,selectedItem:e=>`${e.item} valittu.`};var k2e={};k2e={deselectedItem:e=>`${e.item} non sélectionné.`,longPressToSelect:"Appuyez de manière prolongée pour passer en mode de sélection.",select:"Sélectionner",selectedAll:"Tous les éléments sélectionnés.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Aucun élément sélectionné",one:()=>`${g.number(e.count)} élément sélectionné`,other:()=>`${g.number(e.count)} éléments sélectionnés`})}.`,selectedItem:e=>`${e.item} sélectionné.`};var Y2e={};Y2e={deselectedItem:e=>`${e.item} לא נבחר.`,longPressToSelect:"הקשה ארוכה לכניסה למצב בחירה.",select:"בחר",selectedAll:"כל הפריטים נבחרו.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"לא נבחרו פריטים",one:()=>`פריט ${g.number(e.count)} נבחר`,other:()=>`${g.number(e.count)} פריטים נבחרו`})}.`,selectedItem:e=>`${e.item} נבחר.`};var K2e={};K2e={deselectedItem:e=>`Stavka ${e.item} nije odabrana.`,longPressToSelect:"Dugo pritisnite za ulazak u način odabira.",select:"Odaberite",selectedAll:"Odabrane su sve stavke.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Nije odabrana nijedna stavka",one:()=>`Odabrana je ${g.number(e.count)} stavka`,other:()=>`Odabrano je ${g.number(e.count)} stavki`})}.`,selectedItem:e=>`Stavka ${e.item} je odabrana.`};var D2e={};D2e={deselectedItem:e=>`${e.item} nincs kijelölve.`,longPressToSelect:"Nyomja hosszan a kijelöléshez.",select:"Kijelölés",selectedAll:"Az összes elem kijelölve.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Egy elem sincs kijelölve",one:()=>`${g.number(e.count)} elem kijelölve`,other:()=>`${g.number(e.count)} elem kijelölve`})}.`,selectedItem:e=>`${e.item} kijelölve.`};var x2e={};x2e={deselectedItem:e=>`${e.item} non selezionato.`,longPressToSelect:"Premi a lungo per passare alla modalità di selezione.",select:"Seleziona",selectedAll:"Tutti gli elementi selezionati.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Nessun elemento selezionato",one:()=>`${g.number(e.count)} elemento selezionato`,other:()=>`${g.number(e.count)} elementi selezionati`})}.`,selectedItem:e=>`${e.item} selezionato.`};var F2e={};F2e={deselectedItem:e=>`${e.item} が選択されていません。`,longPressToSelect:"長押しして選択モードを開きます。",select:"選択",selectedAll:"すべての項目を選択しました。",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"項目が選択されていません",one:()=>`${g.number(e.count)} 項目を選択しました`,other:()=>`${g.number(e.count)} 項目を選択しました`})}。`,selectedItem:e=>`${e.item} を選択しました。`};var E2e={};E2e={deselectedItem:e=>`${e.item}이(가) 선택되지 않았습니다.`,longPressToSelect:"선택 모드로 들어가려면 길게 누르십시오.",select:"선택",selectedAll:"모든 항목이 선택되었습니다.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"선택된 항목이 없습니다",one:()=>`${g.number(e.count)}개 항목이 선택되었습니다`,other:()=>`${g.number(e.count)}개 항목이 선택되었습니다`})}.`,selectedItem:e=>`${e.item}이(가) 선택되었습니다.`};var M2e={};M2e={deselectedItem:e=>`${e.item} nepasirinkta.`,longPressToSelect:"Norėdami įjungti pasirinkimo režimą, paspauskite ir palaikykite.",select:"Pasirinkti",selectedAll:"Pasirinkti visi elementai.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Nepasirinktas nė vienas elementas",one:()=>`Pasirinktas ${g.number(e.count)} elementas`,other:()=>`Pasirinkta elementų: ${g.number(e.count)}`})}.`,selectedItem:e=>`Pasirinkta: ${e.item}.`};var z2e={};z2e={deselectedItem:e=>`Vienums ${e.item} nav atlasīts.`,longPressToSelect:"Ilgi turiet nospiestu. lai ieslēgtu atlases režīmu.",select:"Atlasīt",selectedAll:"Atlasīti visi vienumi.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Nav atlasīts neviens vienums",one:()=>`Atlasīto vienumu skaits: ${g.number(e.count)}`,other:()=>`Atlasīto vienumu skaits: ${g.number(e.count)}`})}.`,selectedItem:e=>`Atlasīts vienums ${e.item}.`};var P2e={};P2e={deselectedItem:e=>`${e.item} er ikke valgt.`,longPressToSelect:"Bruk et langt trykk for å gå inn i valgmodus.",select:"Velg",selectedAll:"Alle elementer er valgt.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Ingen elementer er valgt",one:()=>`${g.number(e.count)} element er valgt`,other:()=>`${g.number(e.count)} elementer er valgt`})}.`,selectedItem:e=>`${e.item} er valgt.`};var J2e={};J2e={deselectedItem:e=>`${e.item} niet geselecteerd.`,longPressToSelect:"Druk lang om de selectiemodus te openen.",select:"Selecteren",selectedAll:"Alle items geselecteerd.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Geen items geselecteerd",one:()=>`${g.number(e.count)} item geselecteerd`,other:()=>`${g.number(e.count)} items geselecteerd`})}.`,selectedItem:e=>`${e.item} geselecteerd.`};var O2e={};O2e={deselectedItem:e=>`Nie zaznaczono ${e.item}.`,longPressToSelect:"Naciśnij i przytrzymaj, aby wejść do trybu wyboru.",select:"Zaznacz",selectedAll:"Wszystkie zaznaczone elementy.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Nie zaznaczono żadnych elementów",one:()=>`${g.number(e.count)} zaznaczony element`,other:()=>`${g.number(e.count)} zaznaczonych elementów`})}.`,selectedItem:e=>`Zaznaczono ${e.item}.`};var _2e={};_2e={deselectedItem:e=>`${e.item} não selecionado.`,longPressToSelect:"Mantenha pressionado para entrar no modo de seleção.",select:"Selecionar",selectedAll:"Todos os itens selecionados.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Nenhum item selecionado",one:()=>`${g.number(e.count)} item selecionado`,other:()=>`${g.number(e.count)} itens selecionados`})}.`,selectedItem:e=>`${e.item} selecionado.`};var L2e={};L2e={deselectedItem:e=>`${e.item} não selecionado.`,longPressToSelect:"Prima continuamente para entrar no modo de seleção.",select:"Selecionar",selectedAll:"Todos os itens selecionados.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Nenhum item selecionado",one:()=>`${g.number(e.count)} item selecionado`,other:()=>`${g.number(e.count)} itens selecionados`})}.`,selectedItem:e=>`${e.item} selecionado.`};var U2e={};U2e={deselectedItem:e=>`${e.item} neselectat.`,longPressToSelect:"Apăsați lung pentru a intra în modul de selectare.",select:"Selectare",selectedAll:"Toate elementele selectate.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Niciun element selectat",one:()=>`${g.number(e.count)} element selectat`,other:()=>`${g.number(e.count)} elemente selectate`})}.`,selectedItem:e=>`${e.item} selectat.`};var Q2e={};Q2e={deselectedItem:e=>`${e.item} не выбрано.`,longPressToSelect:"Нажмите и удерживайте для входа в режим выбора.",select:"Выбрать",selectedAll:"Выбраны все элементы.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Нет выбранных элементов",one:()=>`${g.number(e.count)} элемент выбран`,other:()=>`${g.number(e.count)} элементов выбрано`})}.`,selectedItem:e=>`${e.item} выбрано.`};var j2e={};j2e={deselectedItem:e=>`Nevybraté položky: ${e.item}.`,longPressToSelect:"Dlhším stlačením prejdite do režimu výberu.",select:"Vybrať",selectedAll:"Všetky vybraté položky.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Žiadne vybraté položky",one:()=>`${g.number(e.count)} vybratá položka`,other:()=>`Počet vybratých položiek:${g.number(e.count)}`})}.`,selectedItem:e=>`Vybraté položky: ${e.item}.`};var $2e={};$2e={deselectedItem:e=>`Element ${e.item} ni izbran.`,longPressToSelect:"Za izbirni način pritisnite in dlje časa držite.",select:"Izberite",selectedAll:"Vsi elementi so izbrani.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Noben element ni izbran",one:()=>`${g.number(e.count)} element je izbran`,other:()=>`${g.number(e.count)} elementov je izbranih`})}.`,selectedItem:e=>`Element ${e.item} je izbran.`};var q2e={};q2e={deselectedItem:e=>`${e.item} nije izabrano.`,longPressToSelect:"Dugo pritisnite za ulazak u režim biranja.",select:"Izaberite",selectedAll:"Izabrane su sve stavke.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Nije izabrana nijedna stavka",one:()=>`Izabrana je ${g.number(e.count)} stavka`,other:()=>`Izabrano je ${g.number(e.count)} stavki`})}.`,selectedItem:e=>`${e.item} je izabrano.`};var eHe={};eHe={deselectedItem:e=>`${e.item} ej markerat.`,longPressToSelect:"Tryck länge när du vill öppna väljarläge.",select:"Markera",selectedAll:"Alla markerade objekt.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Inga markerade objekt",one:()=>`${g.number(e.count)} markerat objekt`,other:()=>`${g.number(e.count)} markerade objekt`})}.`,selectedItem:e=>`${e.item} markerat.`};var tHe={};tHe={deselectedItem:e=>`${e.item} seçilmedi.`,longPressToSelect:"Seçim moduna girmek için uzun basın.",select:"Seç",selectedAll:"Tüm ögeler seçildi.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Hiçbir öge seçilmedi",one:()=>`${g.number(e.count)} öge seçildi`,other:()=>`${g.number(e.count)} öge seçildi`})}.`,selectedItem:e=>`${e.item} seçildi.`};var gHe={};gHe={deselectedItem:e=>`${e.item} не вибрано.`,longPressToSelect:"Виконайте довге натиснення, щоб перейти в режим вибору.",select:"Вибрати",selectedAll:"Усі елементи вибрано.",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"Жодних елементів не вибрано",one:()=>`${g.number(e.count)} елемент вибрано`,other:()=>`Вибрано елементів: ${g.number(e.count)}`})}.`,selectedItem:e=>`${e.item} вибрано.`};var IHe={};IHe={deselectedItem:e=>`未选择 ${e.item}。`,longPressToSelect:"长按以进入选择模式。",select:"选择",selectedAll:"已选择所有项目。",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"未选择项目",one:()=>`已选择 ${g.number(e.count)} 个项目`,other:()=>`已选择 ${g.number(e.count)} 个项目`})}。`,selectedItem:e=>`已选择 ${e.item}。`};var iHe={};iHe={deselectedItem:e=>`未選取「${e.item}」。`,longPressToSelect:"長按以進入選擇模式。",select:"選取",selectedAll:"已選取所有項目。",selectedCount:(e,g)=>`${g.plural(e.count,{"=0":"未選取任何項目",one:()=>`已選取 ${g.number(e.count)} 個項目`,other:()=>`已選取 ${g.number(e.count)} 個項目`})}。`,selectedItem:e=>`已選取「${e.item}」。`};Nk={"ar-AE":B2e,"bg-BG":S2e,"cs-CZ":w2e,"da-DK":V2e,"de-DE":R2e,"el-GR":W2e,"en-US":X2e,"es-ES":H2e,"et-EE":T2e,"fi-FI":N2e,"fr-FR":k2e,"he-IL":Y2e,"hr-HR":K2e,"hu-HU":D2e,"it-IT":x2e,"ja-JP":F2e,"ko-KR":E2e,"lt-LT":M2e,"lv-LV":z2e,"nb-NO":P2e,"nl-NL":J2e,"pl-PL":O2e,"pt-BR":_2e,"pt-PT":L2e,"ro-RO":U2e,"ru-RU":Q2e,"sk-SK":j2e,"sl-SI":$2e,"sr-SP":q2e,"sv-SE":eHe,"tr-TR":tHe,"uk-UA":gHe,"zh-CN":IHe,"zh-TW":iHe};function grg(e,g){let{getRowText:I=r=>{var o,A,s,a;return(a=(o=(A=g.collection).getTextValue)===null||o===void 0?void 0:o.call(A,r))!==null&&a!==void 0?a:(s=g.collection.getItem(r))===null||s===void 0?void 0:s.textValue}}=e,i=iy(p$(Nk)),n=g.selectionManager.rawSelection,C=Ie.useRef(n);n2e(()=>{var r;if(!g.selectionManager.isFocused){C.current=n;return}let o=Jle(n,C.current),A=Jle(C.current,n),s=g.selectionManager.selectionBehavior==="replace",a=[];if(g.selectionManager.selectedKeys.size===1&&s){if(g.collection.getItem(g.selectionManager.selectedKeys.keys().next().value)){let l=I(g.selectionManager.selectedKeys.keys().next().value);l&&a.push(i.format("selectedItem",{item:l}))}}else if(o.size===1&&A.size===0){let l=I(o.keys().next().value);l&&a.push(i.format("selectedItem",{item:l}))}else if(A.size===1&&o.size===0&&g.collection.getItem(A.keys().next().value)){let l=I(A.keys().next().value);l&&a.push(i.format("deselectedItem",{item:l}))}g.selectionManager.selectionMode==="multiple"&&(a.length===0||n==="all"||n.size>1||C.current==="all"||((r=C.current)===null||r===void 0?void 0:r.size)>1)&&a.push(n==="all"?i.format("selectedAll"):i.format("selectedCount",{count:n.size})),a.length>0&&b2e(a.join(" ")),C.current=n},[n])}function Jle(e,g){let I=new Set;if(e==="all"||g==="all")return I;for(let i of e.keys())g.has(i)||I.add(i);return I}function Irg(e){let g=iy(p$(Nk)),I=iCg(),i=(I==="pointer"||I==="virtual"||I==null)&&typeof window<"u"&&"ontouchstart"in window,n=Ie.useMemo(()=>{let r=e.selectionManager.selectionMode,o=e.selectionManager.selectionBehavior,A;return i&&(A=g.format("longPressToSelect")),o==="replace"&&r!=="none"&&e.hasItemActions?A:void 0},[e.selectionManager.selectionMode,e.selectionManager.selectionBehavior,e.hasItemActions,g,i]);return Xk(n)}function irg(e,g,I){let{isVirtualized:i,keyboardDelegate:n,focusMode:C,scrollRef:r,getRowText:o,onRowAction:A,onCellAction:s}=e,{selectionManager:a}=g;!e["aria-label"]&&!e["aria-labelledby"]&&console.warn("An aria-label or aria-labelledby prop is required for accessibility.");let l=f2e({usage:"search",sensitivity:"base"}),{direction:c}=um(),u=g.selectionManager.disabledBehavior,d=Ie.useMemo(()=>n||new v2e({collection:g.collection,disabledKeys:u==="selection"?new Set:g.disabledKeys,ref:I,direction:c,collator:l,focusMode:C}),[n,g.collection,g.disabledKeys,u,I,c,l,C]),{collectionProps:h}=QCg({ref:I,selectionManager:a,keyboardDelegate:d,isVirtualized:i,scrollRef:r}),m=Rh(e.id);b$.set(g,{keyboardDelegate:d,actions:{onRowAction:A,onCellAction:s}});let f=Irg({selectionManager:a,hasItemActions:!!(A||s)}),b=Ra(e,{labelable:!0}),p=Ie.useCallback(G=>{if(a.isFocused){G.currentTarget.contains(G.target)||a.setFocused(!1);return}G.currentTarget.contains(G.target)&&a.setFocused(!0)},[a]),y=Ie.useMemo(()=>({onBlur:h.onBlur,onFocus:p}),[p,h.onBlur]),Z=BCg(I,{isDisabled:g.collection.size!==0}),B=pi(b,{role:"grid",id:m,"aria-multiselectable":a.selectionMode==="multiple"?"true":void 0},g.isKeyboardNavigationDisabled?y:h,g.collection.size===0&&{tabIndex:Z?-1:0},f);return i&&(B["aria-rowcount"]=g.collection.size,B["aria-colcount"]=g.collection.columnCount),grg({getRowText:o},g),{gridProps:B}}function nrg(){return{rowGroupProps:{role:"rowgroup"}}}function Crg(e,g,I){let{node:i,isVirtualized:n,shouldSelectOnPressUp:C,onAction:r}=e,{actions:{onRowAction:o}}=b$.get(g),{itemProps:A,...s}=G2e({selectionManager:g.selectionManager,key:i.key,ref:I,isVirtualized:n,shouldSelectOnPressUp:C,onAction:o?()=>o(i.key):r,isDisabled:g.collection.size===0}),a=g.selectionManager.isSelected(i.key),l={role:"row","aria-selected":g.selectionManager.selectionMode!=="none"?a:void 0,"aria-disabled":s.isDisabled||void 0,...A};return n&&(l["aria-rowindex"]=i.index+1),{rowProps:l,...s}}function nHe(e,g,I){let{node:i,isVirtualized:n,focusMode:C="child",shouldSelectOnPressUp:r,onAction:o}=e,{direction:A}=um(),{keyboardDelegate:s,actions:{onCellAction:a}}=b$.get(g),l=Ie.useRef(null),c=()=>{let p=_r(I.current);if(C==="child"){if(I.current.contains(document.activeElement)&&I.current!==document.activeElement)return;let y=g.selectionManager.childFocusStrategy==="last"?AF(p):p.firstChild();if(y){QC(y);return}}(l.current!=null&&i.key!==l.current||!I.current.contains(document.activeElement))&&QC(I.current)},{itemProps:u,isPressed:d}=G2e({selectionManager:g.selectionManager,key:i.key,ref:I,isVirtualized:n,focus:c,shouldSelectOnPressUp:r,onAction:a?()=>a(i.key):o,isDisabled:g.collection.size===0}),f=pi(u,{role:"gridcell",onKeyDownCapture:p=>{if(!p.currentTarget.contains(p.target)||g.isKeyboardNavigationDisabled)return;let y=_r(I.current);switch(y.currentNode=document.activeElement,p.key){case"ArrowLeft":{let Z=A==="rtl"?y.nextNode():y.previousNode();if(C==="child"&&Z===I.current&&(Z=null),Z)p.preventDefault(),p.stopPropagation(),QC(Z),Fl(Z,{containingElement:xl(I.current)});else{if(s.getKeyLeftOf(i.key)!==i.key)break;p.preventDefault(),p.stopPropagation(),C==="cell"&&A==="rtl"?(QC(I.current),Fl(I.current,{containingElement:xl(I.current)})):(y.currentNode=I.current,Z=A==="rtl"?y.firstChild():AF(y),Z&&(QC(Z),Fl(Z,{containingElement:xl(I.current)})))}break}case"ArrowRight":{let Z=A==="rtl"?y.previousNode():y.nextNode();if(C==="child"&&Z===I.current&&(Z=null),Z)p.preventDefault(),p.stopPropagation(),QC(Z),Fl(Z,{containingElement:xl(I.current)});else{if(s.getKeyRightOf(i.key)!==i.key)break;p.preventDefault(),p.stopPropagation(),C==="cell"&&A==="ltr"?(QC(I.current),Fl(I.current,{containingElement:xl(I.current)})):(y.currentNode=I.current,Z=A==="rtl"?AF(y):y.firstChild(),Z&&(QC(Z),Fl(Z,{containingElement:xl(I.current)})))}break}case"ArrowUp":case"ArrowDown":!p.altKey&&I.current.contains(p.target)&&(p.stopPropagation(),p.preventDefault(),I.current.parentElement.dispatchEvent(new KeyboardEvent(p.nativeEvent.type,p.nativeEvent)));break}},onFocus:p=>{if(l.current=i.key,p.target!==I.current){u$()||g.selectionManager.setFocusedKey(i.key);return}requestAnimationFrame(()=>{C==="child"&&document.activeElement===I.current&&c()})}});var b;return n&&(f["aria-colindex"]=((b=i.colIndex)!==null&&b!==void 0?b:i.index)+1),r&&f.tabIndex!=null&&f.onPointerDown==null&&(f.onPointerDown=p=>{let y=p.currentTarget,Z=y.getAttribute("tabindex");y.removeAttribute("tabindex"),requestAnimationFrame(()=>{y.setAttribute("tabindex",Z)})}),{gridCellProps:f,isPressed:d}}function AF(e){let g,I;do I=e.lastChild(),I&&(g=I);while(I);return g}function rrg(e,g){let{key:I}=e,i=g.selectionManager,n=Rh(),C=!g.selectionManager.canSelectItem(I),r=g.selectionManager.isSelected(I),o=()=>i.select(I);const A=iy(p$(Nk));return{checkboxProps:{id:n,"aria-label":A.format("select"),isSelected:r,isDisabled:C,onChange:o}}}let org=!1;function bH(){return org}function y$(e){return e&&e.__esModule?e.default:e}const Z$=new WeakMap;function DO(e){return typeof e=="string"?e.replace(/\s*/g,""):""+e}function Arg(e,g){let I=Z$.get(e);if(!I)throw new Error("Unknown grid");return`${I}-${DO(g)}`}function CHe(e,g,I){let i=Z$.get(e);if(!i)throw new Error("Unknown grid");return`${i}-${DO(g)}-${DO(I)}`}function rHe(e,g){return[...e.collection.rowHeaderColumnKeys].map(I=>CHe(e,g,I)).join(" ")}var kk={},oHe={};oHe={ascending:"تصاعدي",ascendingSort:e=>`ترتيب حسب العمود ${e.columnName} بترتيب تصاعدي`,columnSize:e=>`${e.value} بالبكسل`,descending:"تنازلي",descendingSort:e=>`ترتيب حسب العمود ${e.columnName} بترتيب تنازلي`,resizerDescription:"اضغط على مفتاح Enter لبدء تغيير الحجم",select:"تحديد",selectAll:"تحديد الكل",sortable:"عمود قابل للترتيب"};var AHe={};AHe={ascending:"възходящ",ascendingSort:e=>`сортирано по колона ${e.columnName} във възходящ ред`,columnSize:e=>`${e.value} пиксела`,descending:"низходящ",descendingSort:e=>`сортирано по колона ${e.columnName} в низходящ ред`,resizerDescription:"Натиснете „Enter“, за да започнете да преоразмерявате",select:"Изберете",selectAll:"Изберете всичко",sortable:"сортираща колона"};var aHe={};aHe={ascending:"vzestupně",ascendingSort:e=>`řazeno vzestupně podle sloupce ${e.columnName}`,columnSize:e=>`${e.value} pixelů`,descending:"sestupně",descendingSort:e=>`řazeno sestupně podle sloupce ${e.columnName}`,resizerDescription:"Stisknutím klávesy Enter začnete měnit velikost",select:"Vybrat",selectAll:"Vybrat vše",sortable:"sloupec s možností řazení"};var sHe={};sHe={ascending:"stigende",ascendingSort:e=>`sorteret efter kolonne ${e.columnName} i stigende rækkefølge`,columnSize:e=>`${e.value} pixels`,descending:"faldende",descendingSort:e=>`sorteret efter kolonne ${e.columnName} i faldende rækkefølge`,resizerDescription:"Tryk på Enter for at ændre størrelse",select:"Vælg",selectAll:"Vælg alle",sortable:"sorterbar kolonne"};var lHe={};lHe={ascending:"aufsteigend",ascendingSort:e=>`sortiert nach Spalte ${e.columnName} in aufsteigender Reihenfolge`,columnSize:e=>`${e.value} Pixel`,descending:"absteigend",descendingSort:e=>`sortiert nach Spalte ${e.columnName} in absteigender Reihenfolge`,resizerDescription:"Eingabetaste zum Starten der Größenänderung drücken",select:"Auswählen",selectAll:"Alles auswählen",sortable:"sortierbare Spalte"};var cHe={};cHe={ascending:"αύξουσα",ascendingSort:e=>`διαλογή ανά στήλη ${e.columnName} σε αύξουσα σειρά`,columnSize:e=>`${e.value} pixel`,descending:"φθίνουσα",descendingSort:e=>`διαλογή ανά στήλη ${e.columnName} σε φθίνουσα σειρά`,resizerDescription:"Πατήστε Enter για έναρξη της αλλαγής μεγέθους",select:"Επιλογή",selectAll:"Επιλογή όλων",sortable:"Στήλη διαλογής"};var uHe={};uHe={select:"Select",selectAll:"Select All",sortable:"sortable column",ascending:"ascending",descending:"descending",ascendingSort:e=>`sorted by column ${e.columnName} in ascending order`,descendingSort:e=>`sorted by column ${e.columnName} in descending order`,columnSize:e=>`${e.value} pixels`,resizerDescription:"Press Enter to start resizing"};var dHe={};dHe={ascending:"de subida",ascendingSort:e=>`ordenado por columna ${e.columnName} en orden de subida`,columnSize:e=>`${e.value} píxeles`,descending:"de bajada",descendingSort:e=>`ordenado por columna ${e.columnName} en orden de bajada`,resizerDescription:"Pulse Intro para empezar a redimensionar",select:"Seleccionar",selectAll:"Seleccionar todos",sortable:"columna ordenable"};var hHe={};hHe={ascending:"tõusev järjestus",ascendingSort:e=>`sorditud veeru järgi ${e.columnName} tõusvas järjestuses`,columnSize:e=>`${e.value} pikslit`,descending:"laskuv järjestus",descendingSort:e=>`sorditud veeru järgi ${e.columnName} laskuvas järjestuses`,resizerDescription:"Suuruse muutmise alustamiseks vajutage klahvi Enter",select:"Vali",selectAll:"Vali kõik",sortable:"sorditav veerg"};var mHe={};mHe={ascending:"nouseva",ascendingSort:e=>`lajiteltu sarakkeen ${e.columnName} mukaan nousevassa järjestyksessä`,columnSize:e=>`${e.value} pikseliä`,descending:"laskeva",descendingSort:e=>`lajiteltu sarakkeen ${e.columnName} mukaan laskevassa järjestyksessä`,resizerDescription:"Aloita koon muutos painamalla Enter-näppäintä",select:"Valitse",selectAll:"Valitse kaikki",sortable:"lajiteltava sarake"};var fHe={};fHe={ascending:"croissant",ascendingSort:e=>`trié en fonction de la colonne ${e.columnName} par ordre croissant`,columnSize:e=>`${e.value} pixels`,descending:"décroissant",descendingSort:e=>`trié en fonction de la colonne ${e.columnName} par ordre décroissant`,resizerDescription:"Appuyez sur Entrée pour commencer le redimensionnement.",select:"Sélectionner",selectAll:"Sélectionner tout",sortable:"colonne triable"};var pHe={};pHe={ascending:"עולה",ascendingSort:e=>`מוין לפי עמודה ${e.columnName} בסדר עולה`,columnSize:e=>`${e.value} פיקסלים`,descending:"יורד",descendingSort:e=>`מוין לפי עמודה ${e.columnName} בסדר יורד`,resizerDescription:"הקש Enter כדי לשנות את הגודל",select:"בחר",selectAll:"בחר הכול",sortable:"עמודה שניתן למיין"};var bHe={};bHe={ascending:"rastući",ascendingSort:e=>`razvrstano po stupcima ${e.columnName} rastućem redoslijedom`,columnSize:e=>`${e.value} piksela`,descending:"padajući",descendingSort:e=>`razvrstano po stupcima ${e.columnName} padajućim redoslijedom`,resizerDescription:"Pritisnite Enter da biste započeli promenu veličine",select:"Odaberite",selectAll:"Odaberite sve",sortable:"stupac koji se može razvrstati"};var yHe={};yHe={ascending:"növekvő",ascendingSort:e=>`rendezve a(z) ${e.columnName} oszlop szerint, növekvő sorrendben`,columnSize:e=>`${e.value} képpont`,descending:"csökkenő",descendingSort:e=>`rendezve a(z) ${e.columnName} oszlop szerint, csökkenő sorrendben`,resizerDescription:"Nyomja le az Enter billentyűt az átméretezés megkezdéséhez",select:"Kijelölés",selectAll:"Összes kijelölése",sortable:"rendezendő oszlop"};var ZHe={};ZHe={ascending:"crescente",ascendingSort:e=>`in ordine crescente in base alla colonna ${e.columnName}`,columnSize:e=>`${e.value} pixel`,descending:"decrescente",descendingSort:e=>`in ordine decrescente in base alla colonna ${e.columnName}`,resizerDescription:"Premi Invio per iniziare a ridimensionare",select:"Seleziona",selectAll:"Seleziona tutto",sortable:"colonna ordinabile"};var GHe={};GHe={ascending:"昇順",ascendingSort:e=>`列 ${e.columnName} を昇順で並べ替え`,columnSize:e=>`${e.value} ピクセル`,descending:"降順",descendingSort:e=>`列 ${e.columnName} を降順で並べ替え`,resizerDescription:"Enter キーを押してサイズ変更を開始",select:"選択",selectAll:"すべて選択",sortable:"並べ替え可能な列"};var vHe={};vHe={ascending:"오름차순",ascendingSort:e=>`${e.columnName} 열을 기준으로 오름차순으로 정렬됨`,columnSize:e=>`${e.value} 픽셀`,descending:"내림차순",descendingSort:e=>`${e.columnName} 열을 기준으로 내림차순으로 정렬됨`,resizerDescription:"크기 조정을 시작하려면 Enter를 누르세요.",select:"선택",selectAll:"모두 선택",sortable:"정렬 가능한 열"};var BHe={};BHe={ascending:"didėjančia tvarka",ascendingSort:e=>`surikiuota pagal stulpelį ${e.columnName} didėjančia tvarka`,columnSize:e=>`${e.value} piks.`,descending:"mažėjančia tvarka",descendingSort:e=>`surikiuota pagal stulpelį ${e.columnName} mažėjančia tvarka`,resizerDescription:"Paspauskite „Enter“, kad pradėtumėte keisti dydį",select:"Pasirinkti",selectAll:"Pasirinkti viską",sortable:"rikiuojamas stulpelis"};var SHe={};SHe={ascending:"augošā secībā",ascendingSort:e=>`kārtots pēc kolonnas ${e.columnName} augošā secībā`,columnSize:e=>`${e.value} pikseļi`,descending:"dilstošā secībā",descendingSort:e=>`kārtots pēc kolonnas ${e.columnName} dilstošā secībā`,resizerDescription:"Nospiediet Enter, lai sāktu izmēru mainīšanu",select:"Atlasīt",selectAll:"Atlasīt visu",sortable:"kārtojamā kolonna"};var wHe={};wHe={ascending:"stigende",ascendingSort:e=>`sortert etter kolonne ${e.columnName} i stigende rekkefølge`,columnSize:e=>`${e.value} piksler`,descending:"synkende",descendingSort:e=>`sortert etter kolonne ${e.columnName} i synkende rekkefølge`,resizerDescription:"Trykk på Enter for å starte størrelsesendring",select:"Velg",selectAll:"Velg alle",sortable:"kolonne som kan sorteres"};var VHe={};VHe={ascending:"oplopend",ascendingSort:e=>`gesorteerd in oplopende volgorde in kolom ${e.columnName}`,columnSize:e=>`${e.value} pixels`,descending:"aflopend",descendingSort:e=>`gesorteerd in aflopende volgorde in kolom ${e.columnName}`,resizerDescription:"Druk op Enter om het formaat te wijzigen",select:"Selecteren",selectAll:"Alles selecteren",sortable:"sorteerbare kolom"};var RHe={};RHe={ascending:"rosnąco",ascendingSort:e=>`posortowano według kolumny ${e.columnName} w porządku rosnącym`,columnSize:e=>`Liczba pikseli: ${e.value}`,descending:"malejąco",descendingSort:e=>`posortowano według kolumny ${e.columnName} w porządku malejącym`,resizerDescription:"Naciśnij Enter, aby rozpocząć zmienianie rozmiaru",select:"Zaznacz",selectAll:"Zaznacz wszystko",sortable:"kolumna z możliwością sortowania"};var WHe={};WHe={ascending:"crescente",ascendingSort:e=>`classificado pela coluna ${e.columnName} em ordem crescente`,columnSize:e=>`${e.value} pixels`,descending:"decrescente",descendingSort:e=>`classificado pela coluna ${e.columnName} em ordem decrescente`,resizerDescription:"Pressione Enter para começar a redimensionar",select:"Selecionar",selectAll:"Selecionar tudo",sortable:"coluna classificável"};var XHe={};XHe={ascending:"ascendente",ascendingSort:e=>`Ordenar por coluna ${e.columnName} em ordem ascendente`,columnSize:e=>`${e.value} pixels`,descending:"descendente",descendingSort:e=>`Ordenar por coluna ${e.columnName} em ordem descendente`,resizerDescription:"Prima Enter para iniciar o redimensionamento",select:"Selecionar",selectAll:"Selecionar tudo",sortable:"Coluna ordenável"};var HHe={};HHe={ascending:"crescătoare",ascendingSort:e=>`sortate după coloana ${e.columnName} în ordine crescătoare`,columnSize:e=>`${e.value} pixeli`,descending:"descrescătoare",descendingSort:e=>`sortate după coloana ${e.columnName} în ordine descrescătoare`,resizerDescription:"Apăsați pe Enter pentru a începe redimensionarea",select:"Selectare",selectAll:"Selectare totală",sortable:"coloană sortabilă"};var THe={};THe={ascending:"возрастание",ascendingSort:e=>`сортировать столбец ${e.columnName} в порядке возрастания`,columnSize:e=>`${e.value} пикс.`,descending:"убывание",descendingSort:e=>`сортировать столбец ${e.columnName} в порядке убывания`,resizerDescription:"Нажмите клавишу Enter для начала изменения размеров",select:"Выбрать",selectAll:"Выбрать все",sortable:"сортируемый столбец"};var NHe={};NHe={ascending:"vzostupne",ascendingSort:e=>`zoradené zostupne podľa stĺpca ${e.columnName}`,columnSize:e=>`Počet pixelov: ${e.value}`,descending:"zostupne",descendingSort:e=>`zoradené zostupne podľa stĺpca ${e.columnName}`,resizerDescription:"Stlačením klávesu Enter začnete zmenu veľkosti",select:"Vybrať",selectAll:"Vybrať všetko",sortable:"zoraditeľný stĺpec"};var kHe={};kHe={ascending:"naraščajoče",ascendingSort:e=>`razvrščeno po stolpcu ${e.columnName} v naraščajočem vrstnem redu`,columnSize:e=>`${e.value} slikovnih pik`,descending:"padajoče",descendingSort:e=>`razvrščeno po stolpcu ${e.columnName} v padajočem vrstnem redu`,resizerDescription:"Pritisnite tipko Enter da začnete spreminjati velikost",select:"Izberite",selectAll:"Izberite vse",sortable:"razvrstljivi stolpec"};var YHe={};YHe={ascending:"rastući",ascendingSort:e=>`sortirano po kolonama ${e.columnName} rastućim redosledom`,columnSize:e=>`${e.value} piksela`,descending:"padajući",descendingSort:e=>`sortirano po kolonama ${e.columnName} padajućim redosledom`,resizerDescription:"Pritisnite Enter da biste započeli promenu veličine",select:"Izaberite",selectAll:"Izaberite sve",sortable:"kolona koja se može sortirati"};var KHe={};KHe={ascending:"stigande",ascendingSort:e=>`sorterat på kolumn ${e.columnName} i stigande ordning`,columnSize:e=>`${e.value} pixlar`,descending:"fallande",descendingSort:e=>`sorterat på kolumn ${e.columnName} i fallande ordning`,resizerDescription:"Tryck på Retur för att börja ändra storlek",select:"Markera",selectAll:"Markera allt",sortable:"sorterbar kolumn"};var DHe={};DHe={ascending:"artan sırada",ascendingSort:e=>`${e.columnName} sütuna göre artan düzende sırala`,columnSize:e=>`${e.value} piksel`,descending:"azalan sırada",descendingSort:e=>`${e.columnName} sütuna göre azalan düzende sırala`,resizerDescription:"Yeniden boyutlandırmak için Enter'a basın",select:"Seç",selectAll:"Tümünü Seç",sortable:"Sıralanabilir sütun"};var xHe={};xHe={ascending:"висхідний",ascendingSort:e=>`відсортовано за стовпцем ${e.columnName} у висхідному порядку`,columnSize:e=>`${e.value} пікс.`,descending:"низхідний",descendingSort:e=>`відсортовано за стовпцем ${e.columnName} у низхідному порядку`,resizerDescription:"Натисніть Enter, щоб почати зміну розміру",select:"Вибрати",selectAll:"Вибрати все",sortable:"сортувальний стовпець"};var FHe={};FHe={ascending:"升序",ascendingSort:e=>`按列 ${e.columnName} 升序排序`,columnSize:e=>`${e.value} 像素`,descending:"降序",descendingSort:e=>`按列 ${e.columnName} 降序排序`,resizerDescription:"按“输入”键开始调整大小。",select:"选择",selectAll:"全选",sortable:"可排序的列"};var EHe={};EHe={ascending:"遞增",ascendingSort:e=>`已依據「${e.columnName}」欄遞增排序`,columnSize:e=>`${e.value} 像素`,descending:"遞減",descendingSort:e=>`已依據「${e.columnName}」欄遞減排序`,resizerDescription:"按 Enter 鍵以開始調整大小",select:"選取",selectAll:"全選",sortable:"可排序的欄"};kk={"ar-AE":oHe,"bg-BG":AHe,"cs-CZ":aHe,"da-DK":sHe,"de-DE":lHe,"el-GR":cHe,"en-US":uHe,"es-ES":dHe,"et-EE":hHe,"fi-FI":mHe,"fr-FR":fHe,"he-IL":pHe,"hr-HR":bHe,"hu-HU":yHe,"it-IT":ZHe,"ja-JP":GHe,"ko-KR":vHe,"lt-LT":BHe,"lv-LV":SHe,"nb-NO":wHe,"nl-NL":VHe,"pl-PL":RHe,"pt-BR":WHe,"pt-PT":XHe,"ro-RO":HHe,"ru-RU":THe,"sk-SK":NHe,"sl-SI":kHe,"sr-SP":YHe,"sv-SE":KHe,"tr-TR":DHe,"uk-UA":xHe,"zh-CN":FHe,"zh-TW":EHe};class arg extends v2e{isCell(g){return g.type==="cell"||g.type==="rowheader"||g.type==="column"}getKeyBelow(g){let I=this.collection.getItem(g);if(I){if(I.type==="column"){let i=Is(Zi(I,this.collection));if(i)return i.key;let n=this.getFirstKey();if(n==null)return;let C=this.collection.getItem(n);return El(Zi(C,this.collection),I.index).key}return super.getKeyBelow(g)}}getKeyAbove(g){let I=this.collection.getItem(g);if(!I)return;if(I.type==="column"){let n=this.collection.getItem(I.parentKey);return n&&n.type==="column"?n.key:void 0}let i=super.getKeyAbove(g);return i!=null&&this.collection.getItem(i).type!=="headerrow"?i:this.isCell(I)?this.collection.columns[I.index].key:this.collection.columns[0].key}findNextColumnKey(g){let I=this.findNextKey(g.key,n=>n.type==="column");if(I!=null)return I;let i=this.collection.headerRows[g.level];for(let n of Zi(i,this.collection))if(n.type==="column")return n.key}findPreviousColumnKey(g){let I=this.findPreviousKey(g.key,C=>C.type==="column");if(I!=null)return I;let i=this.collection.headerRows[g.level],n=[...Zi(i,this.collection)];for(let C=n.length-1;C>=0;C--){let r=n[C];if(r.type==="column")return r.key}}getKeyRightOf(g){let I=this.collection.getItem(g);if(I)return I.type==="column"?this.direction==="rtl"?this.findPreviousColumnKey(I):this.findNextColumnKey(I):super.getKeyRightOf(g)}getKeyLeftOf(g){let I=this.collection.getItem(g);if(I)return I.type==="column"?this.direction==="rtl"?this.findNextColumnKey(I):this.findPreviousColumnKey(I):super.getKeyLeftOf(g)}getKeyForSearch(g,I){if(!this.collator)return null;let i=this.collection,n=I??this.getFirstKey();if(n==null)return null;let C=i.getItem(n);C.type==="cell"&&(n=C.parentKey);let r=!1;for(;n!=null;){let o=i.getItem(n);for(let A of Zi(o,this.collection)){let s=i.columns[A.index];if(i.rowHeaderColumnKeys.has(s.key)&&A.textValue){let a=A.textValue.slice(0,g.length);if(this.collator.compare(a,g)===0)return(I!=null?i.getItem(I):C).type==="cell"?A.key:o.key}}n=this.getKeyBelow(n),n==null&&!r&&(n=this.getFirstKey(),r=!0)}return null}}function srg(e,g,I){let{keyboardDelegate:i,isVirtualized:n,layout:C}=e,r=f2e({usage:"search",sensitivity:"base"}),{direction:o}=um(),A=g.selectionManager.disabledBehavior,s=Ie.useMemo(()=>i||new arg({collection:g.collection,disabledKeys:A==="selection"?new Set:g.disabledKeys,ref:I,direction:o,collator:r,layout:C}),[i,g.collection,g.disabledKeys,A,I,o,r,C]),a=Rh(e.id);Z$.set(g,a);let{gridProps:l}=irg({...e,id:a,keyboardDelegate:s},g,I);n&&(l["aria-rowcount"]=g.collection.size+g.collection.headerRows.length),bH()&&"expandedKeys"in g&&(l.role="treegrid");let{column:c,direction:u}=g.sortDescriptor||{},d=iy(y$(kk)),h=Ie.useMemo(()=>{var f;let b=(f=g.collection.columns.find(p=>p.key===c))===null||f===void 0?void 0:f.textValue;return u&&c?d.format(`${u}Sort`,{columnName:b}):void 0},[u,c,g.collection.columns]),m=Xk(h);return n2e(()=>{b2e(h,"assertive",500)},[h]),{gridProps:pi(l,m,{"aria-describedby":[m["aria-describedby"],l["aria-describedby"]].filter(Boolean).join(" ")})}}function lrg(e,g,I){var i,n;let{node:C}=e,r=C.props.allowsSorting,{gridCellProps:o}=nHe({...e,focusMode:"child"},g,I),A=C.props.isSelectionCell&&g.selectionManager.selectionMode==="single",{pressProps:s}=l$({isDisabled:!r||A,onPress(){g.sort(C.key)},ref:I}),{focusableProps:a}=h2e({},I),l=null,c=((i=g.sortDescriptor)===null||i===void 0?void 0:i.column)===C.key,u=(n=g.sortDescriptor)===null||n===void 0?void 0:n.direction;C.props.allowsSorting&&!uH()&&(l=c?u:"none");let d=iy(y$(kk)),h;r&&(h=`${d.format("sortable")}`,c&&u&&uH()&&(h=`${h}, ${d.format(u)}`));let m=Xk(h),f=g.collection.size===0;return Ie.useEffect(()=>{f&&g.selectionManager.focusedKey===C.key&&g.selectionManager.setFocusedKey(null)},[f,g.selectionManager,C.key]),{columnHeaderProps:{...pi(o,s,a,m,f&&{tabIndex:-1}),role:"columnheader",id:Arg(g,C.key),"aria-colspan":C.colspan&&C.colspan>1?C.colspan:null,"aria-sort":l}}}const Ole={expand:{ltr:"ArrowRight",rtl:"ArrowLeft"},collapse:{ltr:"ArrowLeft",rtl:"ArrowRight"}};function crg(e,g,I){let{node:i,isVirtualized:n}=e,{rowProps:C,...r}=Crg(e,g,I),{direction:o}=um();n&&!(bH()&&"expandedKeys"in g)?C["aria-rowindex"]=i.index+1+g.collection.headerRows.length:delete C["aria-rowindex"];let A={};if(bH()&&"expandedKeys"in g){let u=g.keyMap.get(i.key);if(u!=null){var s,a,l;let d=((s=u.props)===null||s===void 0?void 0:s.UNSTABLE_childItems)||((l=u.props)===null||l===void 0||(a=l.children)===null||a===void 0?void 0:a.length)>g.userColumnCount;A={onKeyDown:h=>{(h.key===Ole.expand[o]&&g.selectionManager.focusedKey===u.key&&d&&g.expandedKeys!=="all"&&!g.expandedKeys.has(u.key)||h.key===Ole.collapse[o]&&g.selectionManager.focusedKey===u.key&&d&&(g.expandedKeys==="all"||g.expandedKeys.has(u.key)))&&(g.toggleKey(u.key),h.stopPropagation())},"aria-expanded":d?g.expandedKeys==="all"||g.expandedKeys.has(i.key):void 0,"aria-level":u.level,"aria-posinset":u.indexOfType+1,"aria-setsize":u.level>1?cc(g.keyMap.get(u==null?void 0:u.parentKey).childNodes).indexOfType+1:cc(g.keyMap.get(g.collection.body.key).childNodes).indexOfType+1}}}let c=r.hasAction?kng(i.props):{};return{rowProps:{...pi(C,A,c),"aria-labelledby":rHe(g,i.key)},...r}}function urg(e,g,I){let{node:i,isVirtualized:n}=e,C={role:"row"};return n&&!(bH()&&"expandedKeys"in g)&&(C["aria-rowindex"]=i.index+1),{rowProps:C}}function drg(e,g,I){let{gridCellProps:i,isPressed:n}=nHe(e,g,I),C=e.node.column.key;return g.collection.rowHeaderColumnKeys.has(C)&&(i.role="rowheader",i.id=CHe(g,e.node.parentKey,C)),{gridCellProps:i,isPressed:n}}function hrg(e,g){let{key:I}=e;const{checkboxProps:i}=rrg(e,g);return{checkboxProps:{...i,"aria-labelledby":`${i.id} ${rHe(g,I)}`}}}function mrg(e){let{isEmpty:g,isSelectAll:I,selectionMode:i}=e.selectionManager;return{checkboxProps:{"aria-label":iy(y$(kk)).format(i==="single"?"select":"selectAll"),isSelected:I,isDisabled:i!=="multiple"||e.collection.size===0,isIndeterminate:!g&&!I,onChange:()=>e.selectionManager.toggleSelectAll()}}}function MHe(){return nrg()}var zHe={exports:{}},PHe={};/** * @license React * use-sync-external-store-shim.production.min.js * @@ -1598,20 +1997,20 @@ ${s}`:s,l=J8e(o).parse(a,c=>wI(this,v$,aHe).call(this,c,r,I,i));if(C&&((e=l[0])! * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - */var w0=Ie;function Fng(g,e){return g===e&&(g!==0||1/g===1/e)||g!==g&&e!==e}var Eng=typeof Object.is=="function"?Object.is:Fng,Mng=w0.useState,zng=w0.useEffect,Png=w0.useLayoutEffect,Jng=w0.useDebugValue;function Ong(g,e){var I=e(),i=Mng({inst:{value:I,getSnapshot:e}}),n=i[0].inst,C=i[1];return Png(function(){n.value=I,n.getSnapshot=e,eE(n)&&C({inst:n})},[g,I,e]),zng(function(){return eE(n)&&C({inst:n}),g(function(){eE(n)&&C({inst:n})})},[g]),Jng(I),I}function eE(g){var e=g.getSnapshot;g=g.value;try{var I=e();return!Eng(g,I)}catch{return!0}}function Lng(g,e){return e()}var _ng=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?Lng:Ong;eNe.useSyncExternalStore=w0.useSyncExternalStore!==void 0?w0.useSyncExternalStore:_ng;qTe.exports=eNe;var Ung=qTe.exports;class Po extends Set{constructor(e,I,i){super(e),e instanceof Po?(this.anchorKey=I||e.anchorKey,this.currentKey=i||e.currentKey):(this.anchorKey=I,this.currentKey=i)}}function Qng(g,e){if(g.size!==e.size)return!1;for(let I of g)if(!e.has(I))return!1;return!0}function jng(g){let{selectionMode:e="none",disallowEmptySelection:I,allowDuplicateSelectionEvents:i,selectionBehavior:n="toggle",disabledBehavior:C="all"}=g,r=Ie.useRef(!1),[,o]=Ie.useState(!1),A=Ie.useRef(null),s=Ie.useRef(null),[,a]=Ie.useState(null),l=Ie.useMemo(()=>Hce(g.selectedKeys),[g.selectedKeys]),c=Ie.useMemo(()=>Hce(g.defaultSelectedKeys,new Po),[g.defaultSelectedKeys]),[u,d]=o2e(l,c,g.onSelectionChange),h=Ie.useMemo(()=>g.disabledKeys?new Set(g.disabledKeys):new Set,[g.disabledKeys]),[m,f]=Ie.useState(n);n==="replace"&&m==="toggle"&&typeof u=="object"&&u.size===0&&f("replace");let b=Ie.useRef(n);return Ie.useEffect(()=>{n!==b.current&&(f(n),b.current=n)},[n]),{selectionMode:e,disallowEmptySelection:I,selectionBehavior:m,setSelectionBehavior:f,get isFocused(){return r.current},setFocused(p){r.current=p,o(p)},get focusedKey(){return A.current},get childFocusStrategy(){return s.current},setFocusedKey(p,y="first"){A.current=p,s.current=y,a(p)},selectedKeys:u,setSelectedKeys(p){(i||!Qng(p,u))&&d(p)},disabledKeys:h,disabledBehavior:C}}function Hce(g,e){return g?g==="all"?"all":new Po(g):e}class $ng{get selectionMode(){return this.state.selectionMode}get disallowEmptySelection(){return this.state.disallowEmptySelection}get selectionBehavior(){return this.state.selectionBehavior}setSelectionBehavior(e){this.state.setSelectionBehavior(e)}get isFocused(){return this.state.isFocused}setFocused(e){this.state.setFocused(e)}get focusedKey(){return this.state.focusedKey}get childFocusStrategy(){return this.state.childFocusStrategy}setFocusedKey(e,I){(e==null||this.collection.getItem(e))&&this.state.setFocusedKey(e,I)}get selectedKeys(){return this.state.selectedKeys==="all"?new Set(this.getSelectAllKeys()):this.state.selectedKeys}get rawSelection(){return this.state.selectedKeys}isSelected(e){return this.state.selectionMode==="none"?!1:(e=this.getKey(e),this.state.selectedKeys==="all"?this.canSelectItem(e):this.state.selectedKeys.has(e))}get isEmpty(){return this.state.selectedKeys!=="all"&&this.state.selectedKeys.size===0}get isSelectAll(){if(this.isEmpty)return!1;if(this.state.selectedKeys==="all")return!0;if(this._isSelectAll!=null)return this._isSelectAll;let e=this.getSelectAllKeys(),I=this.state.selectedKeys;return this._isSelectAll=e.every(i=>I.has(i)),this._isSelectAll}get firstSelectedKey(){let e=null;for(let I of this.state.selectedKeys){let i=this.collection.getItem(I);(!e||i&&$F(this.collection,i,e)<0)&&(e=i)}return e==null?void 0:e.key}get lastSelectedKey(){let e=null;for(let I of this.state.selectedKeys){let i=this.collection.getItem(I);(!e||i&&$F(this.collection,i,e)>0)&&(e=i)}return e==null?void 0:e.key}get disabledKeys(){return this.state.disabledKeys}get disabledBehavior(){return this.state.disabledBehavior}extendSelection(e){if(this.selectionMode==="none")return;if(this.selectionMode==="single"){this.replaceSelection(e);return}e=this.getKey(e);let I;if(this.state.selectedKeys==="all")I=new Po([e],e,e);else{let i=this.state.selectedKeys,n=i.anchorKey||e;I=new Po(i,n,e);for(let C of this.getKeyRange(n,i.currentKey||e))I.delete(C);for(let C of this.getKeyRange(e,n))this.canSelectItem(C)&&I.add(C)}this.state.setSelectedKeys(I)}getKeyRange(e,I){let i=this.collection.getItem(e),n=this.collection.getItem(I);return i&&n?$F(this.collection,i,n)<=0?this.getKeyRangeInternal(e,I):this.getKeyRangeInternal(I,e):[]}getKeyRangeInternal(e,I){let i=[],n=e;for(;n;){let C=this.collection.getItem(n);if((C&&C.type==="item"||C.type==="cell"&&this.allowsCellSelection)&&i.push(n),n===I)return i;n=this.collection.getKeyAfter(n)}return[]}getKey(e){let I=this.collection.getItem(e);if(!I||I.type==="cell"&&this.allowsCellSelection)return e;for(;I.type!=="item"&&I.parentKey!=null;)I=this.collection.getItem(I.parentKey);return!I||I.type!=="item"?null:I.key}toggleSelection(e){if(this.selectionMode==="none")return;if(this.selectionMode==="single"&&!this.isSelected(e)){this.replaceSelection(e);return}if(e=this.getKey(e),e==null)return;let I=new Po(this.state.selectedKeys==="all"?this.getSelectAllKeys():this.state.selectedKeys);I.has(e)?I.delete(e):this.canSelectItem(e)&&(I.add(e),I.anchorKey=e,I.currentKey=e),!(this.disallowEmptySelection&&I.size===0)&&this.state.setSelectedKeys(I)}replaceSelection(e){if(this.selectionMode==="none"||(e=this.getKey(e),e==null))return;let I=this.canSelectItem(e)?new Po([e],e,e):new Po;this.state.setSelectedKeys(I)}setSelectedKeys(e){if(this.selectionMode==="none")return;let I=new Po;for(let i of e)if(i=this.getKey(i),i!=null&&(I.add(i),this.selectionMode==="single"))break;this.state.setSelectedKeys(I)}getSelectAllKeys(){let e=[],I=i=>{for(;i;){if(this.canSelectItem(i)){let n=this.collection.getItem(i);n.type==="item"&&e.push(i),n.hasChildNodes&&(this.allowsCellSelection||n.type!=="item")&&I(us(Gi(n,this.collection)).key)}i=this.collection.getKeyAfter(i)}};return I(this.collection.getFirstKey()),e}selectAll(){!this.isSelectAll&&this.selectionMode==="multiple"&&this.state.setSelectedKeys("all")}clearSelection(){!this.disallowEmptySelection&&(this.state.selectedKeys==="all"||this.state.selectedKeys.size>0)&&this.state.setSelectedKeys(new Po)}toggleSelectAll(){this.isSelectAll?this.clearSelection():this.selectAll()}select(e,I){this.selectionMode!=="none"&&(this.selectionMode==="single"?this.isSelected(e)&&!this.disallowEmptySelection?this.toggleSelection(e):this.replaceSelection(e):this.selectionBehavior==="toggle"||I&&(I.pointerType==="touch"||I.pointerType==="virtual")?this.toggleSelection(e):this.replaceSelection(e))}isSelectionEqual(e){if(e===this.state.selectedKeys)return!0;let I=this.selectedKeys;if(e.size!==I.size)return!1;for(let i of e)if(!I.has(i))return!1;for(let i of I)if(!e.has(i))return!1;return!0}canSelectItem(e){if(this.state.selectionMode==="none"||this.state.disabledKeys.has(e))return!1;let I=this.collection.getItem(e);return!(!I||I.type==="cell"&&!this.allowsCellSelection)}isDisabled(e){return this.state.disabledKeys.has(e)&&this.state.disabledBehavior==="all"}isLink(e){var I,i;return!!(!((i=this.collection.getItem(e))===null||i===void 0||(I=i.props)===null||I===void 0)&&I.href)}constructor(e,I,i){this.collection=e,this.state=I;var n;this.allowsCellSelection=(n=i==null?void 0:i.allowsCellSelection)!==null&&n!==void 0?n:!1,this._isSelectAll=null}}function qng(g){let{collection:e,focusMode:I}=g,i=jng(g),n=Ie.useMemo(()=>g.disabledKeys?new Set(g.disabledKeys):new Set,[g.disabledKeys]),C=i.setFocusedKey;i.setFocusedKey=(A,s)=>{if(I==="cell"&&A!=null){let c=e.getItem(A);if((c==null?void 0:c.type)==="item"){var a,l;let u=Gi(c,e);s==="last"?A=(a=Nc(u))===null||a===void 0?void 0:a.key:A=(l=us(u))===null||l===void 0?void 0:l.key}}C(A,s)};let r=Ie.useMemo(()=>new $ng(e,i),[e,i]);const o=Ie.useRef(null);return Ie.useEffect(()=>{if(i.focusedKey!=null&&!e.getItem(i.focusedKey)){const A=o.current.getItem(i.focusedKey),s=A.parentKey!=null&&(A.type==="cell"||A.type==="rowheader"||A.type==="column")?o.current.getItem(A.parentKey):A,a=o.current.rows,l=e.rows,c=a.length-l.length;let u=Math.min(c>1?Math.max(s.index-c+1,0):s.index,l.length-1),d;for(;u>=0;){if(!r.isDisabled(l[u].key)&&l[u].type!=="headerrow"){d=l[u];break}us.index&&(u=s.index),u--)}if(d){const h=d.hasChildNodes?[...Gi(d,e)]:[],m=d.hasChildNodes&&s!==A&&A.index{let r=this.keyMap.get(C.key);e.visitNode&&(C=e.visitNode(C)),this.keyMap.set(C.key,C);let o=new Set,A;for(let s of C.childNodes)s.type==="cell"&&s.parentKey==null&&(s.parentKey=C.key),o.add(s.key),A?(A.nextKey=s.key,s.prevKey=A.key):s.prevKey=null,I(s),A=s;if(A&&(A.nextKey=null),r)for(let s of r.childNodes)o.has(s.key)||i(s)},i=C=>{this.keyMap.delete(C.key);for(let r of C.childNodes)this.keyMap.get(r.key)===r&&i(r)},n;e.items.forEach((C,r)=>{let o={level:0,key:"row-"+r,type:"row",value:void 0,hasChildNodes:!0,childNodes:[...C.childNodes],rendered:void 0,textValue:void 0,...C};n?(n.nextKey=o.key,o.prevKey=n.key):o.prevKey=null,this.rows.push(o),I(o),n=o}),n&&(n.nextKey=null)}}const tNe="row-header-column-"+Math.random().toString(36).slice(2);let bL="row-header-column-"+Math.random().toString(36).slice(2);for(;tNe===bL;)bL="row-header-column-"+Math.random().toString(36).slice(2);function gNe(g,e){if(e.length===0)return[];let I=[],i=new Map;for(let A of e){let s=A.parentKey,a=[A];for(;s;){let l=g.get(s);if(!l)break;if(i.has(l)){l.colspan++;let{column:c,index:u}=i.get(l);if(u>a.length)break;for(let d=u;dA.length)),C=Array(n).fill(0).map(()=>[]),r=0;for(let A of I){let s=n-1;for(let a of A){if(a){let l=C[s],c=l.reduce((u,d)=>u+d.colspan,0);if(c0&&(l[l.length-1].nextKey=u.key,u.prevKey=l[l.length-1].key),l.push(u)}l.length>0&&(l[l.length-1].nextKey=a.key,a.prevKey=l[l.length-1].key),a.level=s,a.colIndex=r,l.push(a)}s--}r++}let o=0;for(let A of C){let s=A.reduce((a,l)=>a+l.colspan,0);if(s({type:"headerrow",key:"headerrow-"+s,index:s,value:null,rendered:null,level:0,hasChildNodes:!0,childNodes:A,textValue:null}))}class tCg extends eCg{*[Symbol.iterator](){yield*this.body.childNodes}get size(){return this._size}getKeys(){return this.keyMap.keys()}getKeyBefore(e){let I=this.keyMap.get(e);return I?I.prevKey:null}getKeyAfter(e){let I=this.keyMap.get(e);return I?I.nextKey:null}getFirstKey(){var e;return(e=us(this.body.childNodes))===null||e===void 0?void 0:e.key}getLastKey(){var e;return(e=Nc(this.body.childNodes))===null||e===void 0?void 0:e.key}getItem(e){return this.keyMap.get(e)}at(e){const I=[...this.getKeys()];return this.getItem(I[e])}getTextValue(e){let I=this.getItem(e);if(!I)return"";if(I.textValue)return I.textValue;let i=this.rowHeaderColumnKeys;if(i){let n=[];for(let C of I.childNodes){let r=this.columns[C.index];if(i.has(r.key)&&C.textValue&&n.push(C.textValue),n.length===i.size)break}return n.join(" ")}return""}constructor(e,I,i){let n=new Set,C,r=[];if(i!=null&&i.showSelectionCheckboxes){let l={type:"column",key:tNe,value:null,textValue:"",level:0,index:i!=null&&i.showDragButtons?1:0,hasChildNodes:!1,rendered:null,childNodes:[],props:{isSelectionCell:!0}};r.unshift(l)}if(i!=null&&i.showDragButtons){let l={type:"column",key:bL,value:null,textValue:"",level:0,index:0,hasChildNodes:!1,rendered:null,childNodes:[],props:{isDragButtonCell:!0}};r.unshift(l)}let o=[],A=new Map,s=l=>{switch(l.type){case"body":C=l;break;case"column":A.set(l.key,l),l.hasChildNodes||(r.push(l),l.props.isRowHeader&&n.add(l.key));break;case"item":o.push(l);return}for(let c of l.childNodes)s(c)};for(let l of e)s(l);let a=gNe(A,r);a.forEach((l,c)=>o.splice(c,0,l)),super({columnCount:r.length,items:o,visitNode:l=>(l.column=r[l.index],l)}),this._size=0,this.columns=r,this.rowHeaderColumnKeys=n,this.body=C,this.headerRows=a,this._size=[...C.childNodes].length,this.rowHeaderColumnKeys.size===0&&(i!=null&&i.showSelectionCheckboxes?i!=null&&i.showDragButtons?this.rowHeaderColumnKeys.add(this.columns[2].key):this.rowHeaderColumnKeys.add(this.columns[1].key):this.rowHeaderColumnKeys.add(this.columns[0].key))}}const gCg={ascending:"descending",descending:"ascending"};function ICg(g){let[e,I]=Ie.useState(!1),{selectionMode:i="none",showSelectionCheckboxes:n,showDragButtons:C}=g,r=Ie.useMemo(()=>({showSelectionCheckboxes:n&&i!=="none",showDragButtons:C,selectionMode:i,columns:[]}),[g.children,n,i,C]),o=Zng(g,Ie.useCallback(a=>new tCg(a,null,r),[r]),r),{disabledKeys:A,selectionManager:s}=qng({...g,collection:o,disabledBehavior:g.disabledBehavior||"selection"});return{collection:o,disabledKeys:A,selectionManager:s,showSelectionCheckboxes:g.showSelectionCheckboxes||!1,sortDescriptor:g.sortDescriptor,isKeyboardNavigationDisabled:o.size===0||e,setKeyboardNavigationDisabled:I,sort(a,l){var c;g.onSortChange({column:a,direction:l??(((c=g.sortDescriptor)===null||c===void 0?void 0:c.column)===a?gCg[g.sortDescriptor.direction]:"ascending")})}}}class fS{get childNodes(){throw new Error("childNodes is not supported")}clone(){let e=new fS(this.type,this.key);return e.value=this.value,e.level=this.level,e.hasChildNodes=this.hasChildNodes,e.rendered=this.rendered,e.textValue=this.textValue,e["aria-label"]=this["aria-label"],e.index=this.index,e.parentKey=this.parentKey,e.prevKey=this.prevKey,e.nextKey=this.nextKey,e.firstChildKey=this.firstChildKey,e.lastChildKey=this.lastChildKey,e.props=this.props,e}constructor(e,I){this.value=null,this.level=0,this.hasChildNodes=!1,this.rendered=null,this.textValue="",this["aria-label"]=void 0,this.index=0,this.parentKey=null,this.prevKey=null,this.nextKey=null,this.firstChildKey=null,this.lastChildKey=null,this.props={},this.type=e,this.key=I}}class INe{*[Symbol.iterator](){let e=this.firstChild;for(;e;)yield e,e=e.nextSibling}get firstChild(){return this._firstChild}set firstChild(e){this._firstChild=e,this.ownerDocument.markDirty(this)}get lastChild(){return this._lastChild}set lastChild(e){this._lastChild=e,this.ownerDocument.markDirty(this)}get previousSibling(){return this._previousSibling}set previousSibling(e){this._previousSibling=e,this.ownerDocument.markDirty(this)}get nextSibling(){return this._nextSibling}set nextSibling(e){this._nextSibling=e,this.ownerDocument.markDirty(this)}get parentNode(){return this._parentNode}set parentNode(e){this._parentNode=e,this.ownerDocument.markDirty(this)}appendChild(e){this.ownerDocument.startTransaction(),e.parentNode&&e.parentNode.removeChild(e),this.firstChild==null&&(this.firstChild=e),this.lastChild?(this.lastChild.nextSibling=e,e.index=this.lastChild.index+1,e.previousSibling=this.lastChild):(e.previousSibling=null,e.index=0),e.parentNode=this,e.nextSibling=null,this.lastChild=e,this.ownerDocument.markDirty(this),e.hasSetProps&&this.ownerDocument.addNode(e),this.ownerDocument.endTransaction(),this.ownerDocument.queueUpdate()}insertBefore(e,I){if(I==null)return this.appendChild(e);this.ownerDocument.startTransaction(),e.parentNode&&e.parentNode.removeChild(e),e.nextSibling=I,e.previousSibling=I.previousSibling,e.index=I.index,this.firstChild===I?this.firstChild=e:I.previousSibling&&(I.previousSibling.nextSibling=e),I.previousSibling=e,e.parentNode=I.parentNode;let i=I;for(;i;)i.index++,i=i.nextSibling;e.hasSetProps&&this.ownerDocument.addNode(e),this.ownerDocument.endTransaction(),this.ownerDocument.queueUpdate()}removeChild(e){if(e.parentNode!==this)return;this.ownerDocument.startTransaction();let I=e.nextSibling;for(;I;)I.index--,I=I.nextSibling;e.nextSibling&&(e.nextSibling.previousSibling=e.previousSibling),e.previousSibling&&(e.previousSibling.nextSibling=e.nextSibling),this.firstChild===e&&(this.firstChild=e.nextSibling),this.lastChild===e&&(this.lastChild=e.previousSibling),e.parentNode=null,e.nextSibling=null,e.previousSibling=null,e.index=0,this.ownerDocument.removeNode(e),this.ownerDocument.endTransaction(),this.ownerDocument.queueUpdate()}addEventListener(){}removeEventListener(){}constructor(e){this._firstChild=null,this._lastChild=null,this._previousSibling=null,this._nextSibling=null,this._parentNode=null,this.ownerDocument=e}}class pS extends INe{get index(){return this._index}set index(e){this._index=e,this.ownerDocument.markDirty(this)}get level(){return this.parentNode instanceof pS?this.parentNode.level+(this.node.type==="item"?1:0):0}updateNode(){var e,I,i,n;let C=this.ownerDocument.getMutableNode(this);C.index=this.index,C.level=this.level,C.parentKey=this.parentNode instanceof pS?this.parentNode.node.key:null;var r;C.prevKey=(r=(e=this.previousSibling)===null||e===void 0?void 0:e.node.key)!==null&&r!==void 0?r:null;var o;C.nextKey=(o=(I=this.nextSibling)===null||I===void 0?void 0:I.node.key)!==null&&o!==void 0?o:null,C.hasChildNodes=!!this.firstChild;var A;C.firstChildKey=(A=(i=this.firstChild)===null||i===void 0?void 0:i.node.key)!==null&&A!==void 0?A:null;var s;C.lastChildKey=(s=(n=this.lastChild)===null||n===void 0?void 0:n.node.key)!==null&&s!==void 0?s:null}setProps(e,I,i){let n=this.ownerDocument.getMutableNode(this),{value:C,textValue:r,id:o,...A}=e;if(A.ref=I,n.props=A,n.rendered=i,n.value=C,n.textValue=r||(typeof i=="string"?i:"")||e["aria-label"]||"",o!=null&&o!==n.key){if(this.hasSetProps)throw new Error("Cannot change the id of an item");n.key=o}this.hasSetProps||(this.ownerDocument.addNode(this),this.ownerDocument.endTransaction(),this.hasSetProps=!0),this.ownerDocument.queueUpdate()}get style(){return{}}hasAttribute(){}setAttribute(){}setAttributeNS(){}removeAttribute(){}constructor(e,I){super(I),this.nodeType=8,this._index=0,this.hasSetProps=!1,this.node=new fS(e,`react-aria-${++I.nodeId}`),this.ownerDocument.startTransaction()}}class iNe{get size(){return this.keyMap.size}getKeys(){return this.keyMap.keys()}*[Symbol.iterator](){let e=this.firstKey!=null?this.keyMap.get(this.firstKey):void 0;for(;e;)yield e,e=e.nextKey!=null?this.keyMap.get(e.nextKey):void 0}getChildren(e){let I=this.keyMap;return{*[Symbol.iterator](){let i=I.get(e),n=(i==null?void 0:i.firstChildKey)!=null?I.get(i.firstChildKey):null;for(;n;)yield n,n=n.nextKey!=null?I.get(n.nextKey):void 0}}}getKeyBefore(e){let I=this.keyMap.get(e);if(!I)return null;if(I.prevKey!=null){for(I=this.keyMap.get(I.prevKey);I&&I.type!=="item"&&I.lastChildKey!=null;)I=this.keyMap.get(I.lastChildKey);var i;return(i=I==null?void 0:I.key)!==null&&i!==void 0?i:null}return I.parentKey}getKeyAfter(e){let I=this.keyMap.get(e);if(!I)return null;if(I.type!=="item"&&I.firstChildKey!=null)return I.firstChildKey;for(;I;){if(I.nextKey!=null)return I.nextKey;if(I.parentKey!=null)I=this.keyMap.get(I.parentKey);else return null}return null}getFirstKey(){return this.firstKey}getLastKey(){let e=this.lastKey!=null?this.keyMap.get(this.lastKey):null;for(;(e==null?void 0:e.lastChildKey)!=null;)e=this.keyMap.get(e.lastChildKey);var I;return(I=e==null?void 0:e.key)!==null&&I!==void 0?I:null}getItem(e){var I;return(I=this.keyMap.get(e))!==null&&I!==void 0?I:null}at(){throw new Error("Not implemented")}clone(){let e=this.constructor,I=new e;return I.keyMap=new Map(this.keyMap),I.firstKey=this.firstKey,I.lastKey=this.lastKey,I}addNode(e){if(this.frozen)throw new Error("Cannot add a node to a frozen collection");this.keyMap.set(e.key,e)}removeNode(e){if(this.frozen)throw new Error("Cannot remove a node to a frozen collection");this.keyMap.delete(e)}commit(e,I,i=!1){if(this.frozen)throw new Error("Cannot commit a frozen collection");this.firstKey=e,this.lastKey=I,this.frozen=!i}constructor(){this.keyMap=new Map,this.firstKey=null,this.lastKey=null,this.frozen=!1}}class iCg extends INe{createElement(e){return new pS(e,this)}getMutableNode(e){let I=e.node;return this.mutatedNodes.has(e)||(I=e.node.clone(),this.mutatedNodes.add(e),e.node=I),this.markDirty(e),I}getMutableCollection(){return!this.isSSR&&!this.collectionMutated&&(this.collection=this.collection.clone(),this.collectionMutated=!0),this.collection}markDirty(e){this.dirtyNodes.add(e)}startTransaction(){this.transactionCount++}endTransaction(){this.transactionCount--}addNode(e){let I=this.getMutableCollection();if(!I.getItem(e.node.key)){I.addNode(e.node);for(let i of e)this.addNode(i)}this.markDirty(e)}removeNode(e){for(let i of e)i.parentNode=null,this.removeNode(i);this.getMutableCollection().removeNode(e.node.key),this.markDirty(e)}getCollection(){return this.transactionCount>0?this.collection:(this.updateCollection(),this.collection)}updateCollection(){for(let C of this.dirtyNodes)C instanceof pS&&C.parentNode&&C.updateNode();if(this.dirtyNodes.clear(),this.mutatedNodes.size){var e,I;let C=this.getMutableCollection();for(let r of this.mutatedNodes)r.parentNode&&C.addNode(r.node);var i,n;C.commit((i=(e=this.firstChild)===null||e===void 0?void 0:e.node.key)!==null&&i!==void 0?i:null,(n=(I=this.lastChild)===null||I===void 0?void 0:I.node.key)!==null&&n!==void 0?n:null,this.isSSR),this.mutatedNodes.clear()}this.collectionMutated=!1}queueUpdate(){if(!(this.dirtyNodes.size===0||this.transactionCount>0))for(let e of this.subscriptions)e()}subscribe(e){return this.subscriptions.add(e),()=>this.subscriptions.delete(e)}resetAfterSSR(){this.isSSR&&(this.isSSR=!1,this.firstChild=null,this.lastChild=null,this.nodeId=0)}constructor(e){super(null),this.nodeType=11,this.ownerDocument=this,this.dirtyNodes=new Set,this.isSSR=!1,this.nodeId=0,this.nodesByProps=new WeakMap,this.mutatedNodes=new Set,this.subscriptions=new Set,this.transactionCount=0,this.collection=e,this.collectionMutated=!0}}function $w(g){let{children:e,items:I,idScope:i,addIdAndValue:n}=g,C=Ie.useMemo(()=>new WeakMap,[]);return Ie.useMemo(()=>{if(I&&typeof e=="function"){let A=[];for(let s of I){let a=C.get(s);if(!a){if(a=e(s),a.key==null){var r,o;let l=(o=(r=a.props.id)!==null&&r!==void 0?r:s.key)!==null&&o!==void 0?o:s.id;if(l==null)throw new Error("Could not determine key for item");i&&(l=i+":"+l),a=Ie.cloneElement(a,n?{key:l,id:l,value:s}:{key:l})}C.set(s,a)}A.push(a)}return A}else if(typeof e!="function")return e},[e,I,C,i,n])}function qw(g){return $w({...g,addIdAndValue:!0})}const nCg=Ie.createContext(!1);function CCg(g,e){let{collection:I,document:i}=ACg(e);return{portal:sCg(g,i),collection:I}}function rCg(g,e,I){let i=Qw(),n=Ie.useRef(i);n.current=i;let C=Ie.useCallback(()=>n.current?I():e(),[e,I]);return Ung.useSyncExternalStore(g,C)}const oCg=typeof N.useSyncExternalStore=="function"?N.useSyncExternalStore:rCg;function ACg(g){let e=Ie.useMemo(()=>new iCg(g||new iNe),[g]),I=Ie.useCallback(r=>e.subscribe(r),[e]),i=Ie.useCallback(()=>{let r=e.getCollection();return e.isSSR&&e.resetAfterSSR(),r},[e]),n=Ie.useCallback(()=>(e.isSSR=!0,e.getCollection()),[e]);return{collection:oCg(I,i,n),document:e}}const yL=Ie.createContext(null),aCg=Ie.createContext(null);function sCg(g,e){let I=Ie.useContext(aCg),i=e??I,n=qw(g),C=Ie.useMemo(()=>N.createElement(nCg.Provider,{value:!0},n),[n]);return Qw()?N.createElement(yL.Provider,{value:i},C):Fs.createPortal(C,i)}function lCg(g,e,I){return Ie.useCallback(i=>{i==null||i.setProps(g,e,I)},[g,e,I])}function eV(g,e,I,i,n){let C=lCg(e,I,i),r=Ie.useContext(yL);if(r){let o=r.ownerDocument.nodesByProps.get(e);return o||(o=r.ownerDocument.createElement(g),o.setProps(e,I,i),r.appendChild(o),r.ownerDocument.updateCollection(),r.ownerDocument.nodesByProps.set(e,o)),n?N.createElement(yL.Provider,{value:o},n):null}return N.createElement(g,{ref:C},n)}const cCg=Ie.createContext(null),nNe=Ie.createContext(null),uCg=Symbol("callback"),ZL=Symbol("default");function VY({values:g,children:e}){for(let[I,i]of g)e=N.createElement(I.Provider,{value:i},e);return e}function Hm(g){let{className:e,style:I,children:i,defaultClassName:n,defaultChildren:C,values:r}=g;return Ie.useMemo(()=>{let o,A,s;return typeof e=="function"?o=e(r):o=e,typeof I=="function"?A=I(r):A=I,typeof i=="function"?s=i(r):i==null?s=C:s=i,{className:o??n,style:A,children:s,"data-rac":""}},[e,I,i,n,C,r])}function dCg(g,e){let I=Ie.useContext(g);if(e===null)return null;if(I&&typeof I=="object"&&"slots"in I&&I.slots){if(!e&&!I.slots[ZL])throw new Error("A slot prop is required");let i=e||ZL;if(!I.slots[i])throw new Error(`Invalid slot "${e}". Valid slot names are `+new Intl.ListFormat().format(Object.keys(I.slots).map(n=>`"${n}"`))+".");return I.slots[i]}return I}function CNe(g,e,I){let i=dCg(I,g.slot)||{},{ref:n,[uCg]:C,...r}=i,o=jw(Ie.useMemo(()=>EIg(e,n),[e,n])),A=bi(r,g);return Ie.useEffect(()=>{C&&C(g)},[C,g]),[A,o]}function hCg(){let[g,e]=Ie.useState(!0),I=Ie.useRef(!1),i=Ie.useCallback(n=>{I.current=!0,e(!!n)},[]);return mi(()=>{I.current||e(!1)},[]),[i,g]}if(typeof HTMLTemplateElement<"u"){const g=Object.getOwnPropertyDescriptor(Node.prototype,"firstChild").get;Object.defineProperty(HTMLTemplateElement.prototype,"firstChild",{configurable:!0,enumerable:!0,get:function(){return this.dataset.reactAriaHidden?this.content.firstChild:g.call(this)}})}typeof DocumentFragment<"u"&&new DocumentFragment;function mCg(g){const e=/^(data-.*)$/;let I={};for(const i in g)e.test(i)||(I[i]=g[i]);return I}const fCg=Ie.createContext({}),pCg=Ie.createContext({}),bCg=Ie.createContext({}),rNe=Ie.createContext(null),yCg=Ie.createContext({}),oNe=Ie.createContext(null);function ZCg(g,e){let{render:I}=Ie.useContext(oNe);return N.createElement(N.Fragment,null,I(g,e))}const GCg=Ie.forwardRef(ZCg),tV=Ie.createContext({});JSON.parse('{"dropzoneLabel":"DropZone","selectPlaceholder":"حدد عنصرًا","tableResizer":"أداة تغيير الحجم"}');JSON.parse('{"dropzoneLabel":"DropZone","selectPlaceholder":"Изберете предмет","tableResizer":"Преоразмерител"}');JSON.parse('{"dropzoneLabel":"Místo pro přetažení","selectPlaceholder":"Vyberte položku","tableResizer":"Změna velikosti"}');JSON.parse('{"dropzoneLabel":"DropZone","selectPlaceholder":"Vælg et element","tableResizer":"Størrelsesændring"}');JSON.parse('{"dropzoneLabel":"Ablegebereich","selectPlaceholder":"Element wählen","tableResizer":"Größenanpassung"}');JSON.parse('{"dropzoneLabel":"DropZone","selectPlaceholder":"Επιλέξτε ένα αντικείμενο","tableResizer":"Αλλαγή μεγέθους"}');JSON.parse('{"selectPlaceholder":"Select an item","tableResizer":"Resizer","dropzoneLabel":"DropZone"}');JSON.parse('{"dropzoneLabel":"DropZone","selectPlaceholder":"Seleccionar un artículo","tableResizer":"Cambiador de tamaño"}');JSON.parse('{"dropzoneLabel":"DropZone","selectPlaceholder":"Valige üksus","tableResizer":"Suuruse muutja"}');JSON.parse('{"dropzoneLabel":"DropZone","selectPlaceholder":"Valitse kohde","tableResizer":"Koon muuttaja"}');JSON.parse('{"dropzoneLabel":"DropZone","selectPlaceholder":"Sélectionner un élément","tableResizer":"Redimensionneur"}');JSON.parse('{"dropzoneLabel":"DropZone","selectPlaceholder":"בחר פריט","tableResizer":"שינוי גודל"}');JSON.parse('{"dropzoneLabel":"Zona spuštanja","selectPlaceholder":"Odaberite stavku","tableResizer":"Promjena veličine"}');JSON.parse('{"dropzoneLabel":"DropZone","selectPlaceholder":"Válasszon ki egy elemet","tableResizer":"Átméretező"}');JSON.parse('{"dropzoneLabel":"Zona di rilascio","selectPlaceholder":"Seleziona un elemento","tableResizer":"Ridimensionamento"}');JSON.parse('{"dropzoneLabel":"ドロップゾーン","selectPlaceholder":"項目を選択","tableResizer":"サイズ変更ツール"}');JSON.parse('{"dropzoneLabel":"드롭 영역","selectPlaceholder":"항목 선택","tableResizer":"크기 조정기"}');JSON.parse('{"dropzoneLabel":"„DropZone“","selectPlaceholder":"Pasirinkite elementą","tableResizer":"Dydžio keitiklis"}');JSON.parse('{"dropzoneLabel":"DropZone","selectPlaceholder":"Izvēlēties vienumu","tableResizer":"Izmēra mainītājs"}');JSON.parse('{"dropzoneLabel":"Droppsone","selectPlaceholder":"Velg et element","tableResizer":"Størrelsesendrer"}');JSON.parse('{"dropzoneLabel":"DropZone","selectPlaceholder":"Selecteer een item","tableResizer":"Resizer"}');JSON.parse('{"dropzoneLabel":"Strefa upuszczania","selectPlaceholder":"Wybierz element","tableResizer":"Zmiana rozmiaru"}');JSON.parse('{"dropzoneLabel":"DropZone","selectPlaceholder":"Selecione um item","tableResizer":"Redimensionador"}');JSON.parse('{"dropzoneLabel":"DropZone","selectPlaceholder":"Selecione um item","tableResizer":"Redimensionador"}');JSON.parse('{"dropzoneLabel":"Zonă de plasare","selectPlaceholder":"Selectați un element","tableResizer":"Instrument de redimensionare"}');JSON.parse('{"dropzoneLabel":"DropZone","selectPlaceholder":"Выберите элемент","tableResizer":"Средство изменения размера"}');JSON.parse('{"dropzoneLabel":"DropZone","selectPlaceholder":"Vyberte položku","tableResizer":"Nástroj na zmenu veľkosti"}');JSON.parse('{"dropzoneLabel":"DropZone","selectPlaceholder":"Izberite element","tableResizer":"Spreminjanje velikosti"}');JSON.parse('{"dropzoneLabel":"DropZone","selectPlaceholder":"Izaberite stavku","tableResizer":"Promena veličine"}');JSON.parse('{"dropzoneLabel":"DropZone","selectPlaceholder":"Välj en artikel","tableResizer":"Storleksändrare"}');JSON.parse('{"dropzoneLabel":"Bırakma Bölgesi","selectPlaceholder":"Bir öğe seçin","tableResizer":"Yeniden boyutlandırıcı"}');JSON.parse('{"dropzoneLabel":"DropZone","selectPlaceholder":"Виберіть елемент","tableResizer":"Засіб змінення розміру"}');JSON.parse('{"dropzoneLabel":"放置区域","selectPlaceholder":"选择一个项目","tableResizer":"尺寸调整器"}');JSON.parse('{"dropzoneLabel":"放置區","selectPlaceholder":"選取項目","tableResizer":"大小調整器"}');class BCg extends iNe{addNode(e){super.addNode(e),this.columnsDirty||(this.columnsDirty=e.type==="column"),e.type==="tableheader"&&(this.head=e),e.type==="tablebody"&&(this.body=e)}commit(e,I,i=!1){this.updateColumns(i),super.commit(e,I,i)}updateColumns(e){if(!this.columnsDirty)return;this.rowHeaderColumnKeys=new Set,this.columns=[];let I=new Map,i=n=>{switch(n.type){case"column":I.set(n.key,n),n.hasChildNodes||(n.index=this.columns.length,this.columns.push(n),n.props.isRowHeader&&this.rowHeaderColumnKeys.add(n.key));break}for(let C of this.getChildren(n.key))i(C)};for(let n of this.getChildren(this.head.key))i(n);if(this.headerRows=gNe(I,this.columns),this.columnsDirty=!1,this.rowHeaderColumnKeys.size===0&&this.columns.length>0&&!e)throw new Error("A table must have at least one Column with the isRowHeader prop set to true")}get columnCount(){return this.columns.length}get rows(){return[...this.getChildren(this.body.key)]}*[Symbol.iterator](){yield*this.getChildren(this.body.key)}get size(){return[...this.getChildren(this.body.key)].length}getFirstKey(){var e;return(e=[...this.getChildren(this.body.key)][0])===null||e===void 0?void 0:e.key}getLastKey(){var e;let I=[...this.getChildren(this.body.key)];return(e=I[I.length-1])===null||e===void 0?void 0:e.key}getKeyAfter(e){let I=this.getItem(e);var i;return(I==null?void 0:I.type)==="column"?(i=I.nextKey)!==null&&i!==void 0?i:null:super.getKeyAfter(e)}getKeyBefore(e){var I;let i=this.getItem(e);var n;if((i==null?void 0:i.type)==="column")return(n=i.prevKey)!==null&&n!==void 0?n:null;let C=super.getKeyBefore(e);return C!=null&&((I=this.getItem(C))===null||I===void 0?void 0:I.type)==="tablebody"?null:C}getChildren(e){if(!this.getItem(e)){for(let I of this.headerRows)if(I.key===e)return I.childNodes}return super.getChildren(e)}clone(){let e=super.clone();return e.headerRows=this.headerRows,e.columns=this.columns,e.rowHeaderColumnKeys=this.rowHeaderColumnKeys,e.head=this.head,e.body=this.body,e}getTextValue(e){let I=this.getItem(e);if(!I)return"";if(I.textValue)return I.textValue;let i=this.rowHeaderColumnKeys,n=[];for(let C of this.getChildren(e)){let r=this.columns[C.index];if(i.has(r.key)&&C.textValue&&n.push(C.textValue),n.length===i.size)break}return n.join(" ")}constructor(...e){super(...e),this.headerRows=[],this.columns=[],this.rowHeaderColumnKeys=new Set,this.head=new fS("tableheader",-1),this.body=new fS("tablebody",-2),this.columnsDirty=!0}}const vCg=Ie.createContext(null),SCg=Ie.createContext(null),Tm=Ie.createContext(null),ANe=Ie.createContext(null);function wCg(g,e){[g,e]=CNe(g,e,SCg);let I=Ie.useMemo(()=>new BCg,[]),{portal:i,collection:n}=CCg(g,I),C=ICg({...g,collection:n,children:void 0}),{gridProps:r}=Tng(g,C,e),{dragAndDropHooks:o}=g,A=C.selectionManager,s=!!(o!=null&&o.useDraggableCollectionState),a=!!(o!=null&&o.useDroppableCollectionState),l=Ie.useRef(s),c=Ie.useRef(a);Ie.useEffect(()=>{l.current!==s&&console.warn("Drag hooks were provided during one render, but not another. This should be avoided as it may produce unexpected behavior."),c.current!==a&&console.warn("Drop hooks were provided during one render, but not another. This should be avoided as it may produce unexpected behavior.")},[s,a]);let u,d,h,m=!1,f=null,b=Ie.useRef(null);if(s&&o){u=o.useDraggableCollectionState({collection:n,selectionManager:A,preview:o.renderDragPreview?b:void 0}),o.useDraggableCollection({},u,e);let V=o.DragPreview;f=o.renderDragPreview?N.createElement(V,{ref:b},o.renderDragPreview):null}if(a&&o){d=o.useDroppableCollectionState({collection:n,selectionManager:A});let V=new png(n,A.disabledBehavior==="selection"?new Set:A.disabledKeys,e),H=o.dropTargetDelegate||new o.ListDropTargetDelegate(n,e);h=o.useDroppableCollection({keyboardDelegate:V,dropTargetDelegate:H},d,e),m=d.isDropTarget({type:"root"})}let{focusProps:p,isFocused:y,isFocusVisible:Z}=vY(),v=Hm({className:g.className,style:g.style,defaultClassName:"react-aria-Table",values:{isDropTarget:m,isFocused:y,isFocusVisible:Z,state:C}}),{selectionBehavior:G,selectionMode:B,disallowEmptySelection:w}=C.selectionManager,R=Ie.useMemo(()=>({selectionBehavior:B==="none"?null:G,selectionMode:B,disallowEmptySelection:w,allowsDragging:s}),[G,B,w,s]),S=v.style,X=Ie.useContext(vCg),W=null;return X&&(W=X.useTableColumnResizeState({tableWidth:X.tableWidth},C),S={...S,tableLayout:"fixed",width:"fit-content"}),N.createElement(N.Fragment,null,N.createElement(RCg.Provider,{value:R},i),N.createElement(VY,{values:[[Tm,C],[ANe,W],[tV,{dragAndDropHooks:o,dragState:u,dropState:d}],[oNe,{render:LCg}]]},N.createElement(Yig,null,N.createElement("table",{...Da(g),...v,...bi(r,p,h==null?void 0:h.collectionProps),style:S,ref:e,slot:g.slot||void 0,"data-allows-dragging":s||void 0,"data-drop-target":m||void 0,"data-focused":y||void 0,"data-focus-visible":Z||void 0},N.createElement(FCg,{collection:n}),N.createElement(ECg,{collection:n,isDroppable:a}))),f))}const VCg=Ie.forwardRef(wCg),RCg=Ie.createContext(null);function WCg(g,e){let I=qw({children:g.children,items:g.columns}),i=typeof g.children=="function"?g.children:null;return N.createElement(nNe.Provider,{value:i},eV("tableheader",g,e,null,I))}const XCg=Ie.forwardRef(WCg);function HCg(g,e){let I=Ie.useContext(nNe),i;typeof I=="function"?i=I:typeof g.children!="function"&&(i=g.children);let n=qw({children:g.title||g.childColumns?i:null,items:g.childColumns});var C;return eV("column",g,e,(C=g.title)!==null&&C!==void 0?C:g.children,n)}const TCg=Ie.forwardRef(HCg);function NCg(g,e){let I=qw(g);return eV("tablebody",g,e,null,I)}const kCg=Ie.forwardRef(NCg);function YCg(g,e){let I=qw({children:g.children,items:g.columns,idScope:g.id}),i=Ie.useMemo(()=>({idScope:g.id}),[g.id]);return eV("item",g,e,null,N.createElement(cCg.Provider,{value:i},I))}const KCg=Ie.forwardRef(YCg);function xCg(g,e){return eV("cell",g,e,g.children)}const DCg=Ie.forwardRef(xCg);function FCg({collection:g}){let e=$w({items:g.headerRows,children:Ie.useCallback(n=>{switch(n.type){case"headerrow":return N.createElement(MCg,{item:n});default:throw new Error("Unsupported node type in TableHeader: "+n.type)}},[])}),{rowGroupProps:I}=$Te();var i;return N.createElement("thead",{...Da(g.head.props),...I,ref:g.head.props.ref,className:(i=g.head.props.className)!==null&&i!==void 0?i:"react-aria-TableHeader",style:g.head.props.style},e)}function ECg({collection:g,isDroppable:e}){let I=$w({items:g.rows,children:Ie.useCallback(o=>{switch(o.type){case"item":return N.createElement(JCg,{item:o});default:throw new Error("Unsupported node type in TableBody: "+o.type)}},[])}),i=g.body.props,n=Hm({...i,id:void 0,children:void 0,defaultClassName:"react-aria-TableBody",values:{isEmpty:g.size===0}}),C;g.size===0&&i.renderEmptyState&&(C=N.createElement("tr",{role:"row"},N.createElement("td",{role:"gridcell",colSpan:g.columnCount},i.renderEmptyState())));let{rowGroupProps:r}=$Te();return N.createElement("tbody",{...bi(Da(i),r),...n,ref:g.body.props.ref,"data-empty":g.size===0||void 0},e&&N.createElement(QCg,null),I,C)}function MCg({item:g}){let e=Ie.useRef(null),I=Ie.useContext(Tm),{rowProps:i}=Yng({node:g},I,e),{checkboxProps:n}=Dng(I),C=$w({items:I.collection.getChildren(g.key),children:r=>{switch(r.type){case"column":return N.createElement(PCg,{column:r});default:throw new Error("Unsupported node type in Row: "+r.type)}}});return N.createElement("tr",{...i,ref:e},N.createElement(VY,{values:[[rNe,{slots:{selection:n}}]]},C))}const zCg=Ie.createContext(null);function PCg({column:g}){var e,I;let i=jw(g.props.ref),n=Ie.useContext(Tm),{columnHeaderProps:C}=Nng({node:g},n,i),{isFocused:r,isFocusVisible:o,focusProps:A}=vY(),{hoverProps:s,isHovered:a}=_$({}),l=Ie.useContext(ANe),c=!1;if(l)c=l.resizingColumn===g.key;else for(let m in["width","defaultWidth","minWidth","maxWidth"])m in g.props&&console.warn(`The ${m} prop on a only applies when a is wrapped in a . If you aren't using column resizing, you can set the width of a column with CSS.`);let u=g.props,d=Hm({...u,id:void 0,children:g.rendered,defaultClassName:"react-aria-Column",values:{isHovered:a,isFocused:r,isFocusVisible:o,allowsSorting:g.props.allowsSorting,sortDirection:((e=n.sortDescriptor)===null||e===void 0?void 0:e.column)===g.key?n.sortDescriptor.direction:void 0,isResizing:c,startResize:()=>{if(l)l.startResize(g.key),n.setKeyboardNavigationDisabled(!0);else throw new Error("Wrap your
in a to enable column resizing")},sort:m=>{n.sort(g.key,m)}}}),h=d.style;return l&&(h={...h,width:l.getColumnWidth(g.key)}),N.createElement("th",{...bi(Da(u),C,A,s),...d,style:h,colSpan:g.colspan,ref:i,"data-focused":r||void 0,"data-focus-visible":o||void 0,"data-resizing":c||void 0,"data-allows-sorting":g.props.allowsSorting||void 0,"data-sort-direction":((I=n.sortDescriptor)===null||I===void 0?void 0:I.column)===g.key?n.sortDescriptor.direction:void 0},N.createElement(zCg.Provider,{value:{column:g,triggerRef:i}},d.children))}function JCg({item:g}){let e=jw(g.props.ref),I=Ie.useContext(Tm),{dragAndDropHooks:i,dragState:n,dropState:C}=Ie.useContext(tV),{rowProps:r,...o}=kng({node:g,shouldSelectOnPressUp:!!n},I,e),{isFocused:A,isFocusVisible:s,focusProps:a}=vY(),{hoverProps:l,isHovered:c}=_$({isDisabled:!o.allowsSelection&&!o.hasAction}),{checkboxProps:u}=xng({key:g.key},I),d;n&&i&&(d=i.useDraggableItem({key:g.key,hasDragButton:!0},n));let h,m=Ie.useRef(null),{visuallyHiddenProps:f}=j$();C&&i&&(h=i.useDropIndicator({target:{type:"item",key:g.key,dropPosition:"on"}},C,m));let b=(i==null?void 0:i.renderDropIndicator)||(B=>N.createElement(GCg,{target:B})),p=Ie.useRef(null);Ie.useEffect(()=>{n&&!p.current&&console.warn('Draggable items in a Table must contain a
is wrapped in a . If you aren't using column resizing, you can set the width of a column with CSS.`);let u=e.props,d=dm({...u,id:void 0,children:e.rendered,defaultClassName:"react-aria-Column",values:{isHovered:a,isFocused:r,isFocusVisible:o,allowsSorting:e.props.allowsSorting,sortDirection:((g=n.sortDescriptor)===null||g===void 0?void 0:g.column)===e.key?n.sortDescriptor.direction:void 0,isResizing:c,startResize:()=>{if(l)l.startResize(e.key),n.setKeyboardNavigationDisabled(!0);else throw new Error("Wrap your
in a to enable column resizing")},sort:m=>{n.sort(e.key,m)}}}),h=d.style;return l&&(h={...h,width:l.getColumnWidth(e.key)}),N.createElement("th",{...pi(Ra(u),C,A,s),...d,style:h,colSpan:e.colspan,ref:i,"data-focused":r||void 0,"data-focus-visible":o||void 0,"data-resizing":c||void 0,"data-allows-sorting":e.props.allowsSorting||void 0,"data-sort-direction":((I=n.sortDescriptor)===null||I===void 0?void 0:I.column)===e.key?n.sortDescriptor.direction:void 0},N.createElement(yog.Provider,{value:{column:e,triggerRef:i}},d.children))}function Gog({item:e}){let g=fw(e.props.ref),I=Ie.useContext(hm),{dragAndDropHooks:i,dragState:n,dropState:C}=Ie.useContext(Zw),{rowProps:r,...o}=crg({node:e,shouldSelectOnPressUp:!!n},I,g),{isFocused:A,isFocusVisible:s,focusProps:a}=Tk(),{hoverProps:l,isHovered:c}=d$({isDisabled:!o.allowsSelection&&!o.hasAction}),{checkboxProps:u}=hrg({key:e.key},I),d;n&&i&&(d=i.useDraggableItem({key:e.key,hasDragButton:!0},n));let h,m=Ie.useRef(null),{visuallyHiddenProps:f}=f$();C&&i&&(h=i.useDropIndicator({target:{type:"item",key:e.key,dropPosition:"on"}},C,m));let b=(i==null?void 0:i.renderDropIndicator)||(v=>N.createElement(tog,{target:v})),p=Ie.useRef(null);Ie.useEffect(()=>{n&&!p.current&&console.warn('Draggable items in a Table must contain a